Classes | Functions
doxyapp.cpp File Reference

Example of how to use doxygen as part of another GPL applications. More...

#include <stdlib.h>
#include <qfile.h>
#include <qdir.h>
#include "doxygen.h"
#include "outputgen.h"
#include "parserintf.h"
#include "classdef.h"
#include "namespacedef.h"
#include "filedef.h"
#include "util.h"
#include "classlist.h"
#include "config.h"
#include "filename.h"

Go to the source code of this file.

Classes

class  XRefDummyCodeGenerator
 

Functions

static void findXRefSymbols (FileDef *fd)
 
static void listSymbol (Definition *d)
 
static void listSymbols ()
 
static void lookupSymbol (Definition *d)
 
static void lookupSymbols (const QCString &sym)
 
int main (int argc, char **argv)
 

Detailed Description

Example of how to use doxygen as part of another GPL applications.

This example shows how to configure and run doxygen programmatically from within an application without generating the usual output. The example should work on any Unix like OS (including Linux and Mac OS X).

This example shows how to use to code parser to get cross-references information and it also shows how to look up symbols in a program parsed by doxygen and show some information about them.

Definition in file doxyapp.cpp.

Function Documentation

static void findXRefSymbols ( FileDef fd)
static

Definition at line 109 of file doxyapp.cpp.

110 {
111  // get the interface to a parser that matches the file extension
113 
114  // get the programming language from the file name
116 
117  // reset the parsers state
118  pIntf->resetCodeParserState();
119 
120  // create a new backend object
122 
123  // parse the source code
124  pIntf->parseCode(*xrefGen,
125  0,
126  fileToString(fd->absFilePath()),
127  lang,
128  FALSE,
129  0,
130  fd);
131 
132  // dismiss the object.
133  delete xrefGen;
134 }
ParserInterface * getParser(const char *extension)
Definition: parserintf.h:191
QCString fileToString(const char *name, bool filter, bool isSourceCode)
Definition: util.cpp:2418
Abstract interface for programming language parsers.
Definition: parserintf.h:38
const bool FALSE
Definition: qglobal.h:370
SrcLangExt
Definition: types.h:41
QCString getDefFileExtension() const
static ParserManager * parserManager
Definition: doxygen.h:141
QCString name() const
Definition: filedef.cpp:1193
QCString absFilePath() const
Definition: filedef.h:96
SrcLangExt getLanguageFromFileName(const QCString fileName)
Definition: util.cpp:7061
virtual void parseCode(CodeOutputInterface &codeOutIntf, const char *scopeName, const QCString &input, SrcLangExt lang, bool isExampleBlock, const char *exampleName=0, FileDef *fileDef=0, int startLine=-1, int endLine=-1, bool inlineFragment=FALSE, MemberDef *memberDef=0, bool showLineNumbers=TRUE, Definition *searchCtx=0, bool collectXRefs=TRUE)=0
virtual void resetCodeParserState()=0
static void listSymbol ( Definition d)
static

Definition at line 136 of file doxyapp.cpp.

137 {
138  if (d!=Doxygen::globalScope && // skip the global namespace symbol
139  d->name().at(0)!='@' // skip anonymous stuff
140  )
141  {
142  printf("%s\n",
143  d->name().data());
144  }
145 }
char & at(uint i) const
Definition: qcstring.h:326
static NamespaceDef * globalScope
Definition: doxygen.h:128
const QCString & name() const
Definition: definition.h:114
const char * data() const
Definition: qcstring.h:207
static void listSymbols ( )
static

Definition at line 147 of file doxyapp.cpp.

148 {
149  QDictIterator<DefinitionIntf> sli(*Doxygen::symbolMap);
150  DefinitionIntf *di;
151  for (sli.toFirst();(di=sli.current());++sli)
152  {
153  if (di->definitionType()==DefinitionIntf::TypeSymbolList) // list of symbols
154  // with same name
155  {
157  Definition *d;
158  // for each symbol
159  for (dli.toFirst();(d=dli.current());++dli)
160  {
161  listSymbol(d);
162  }
163  }
164  else // single symbol
165  {
166  listSymbol((Definition*)di);
167  }
168  }
169 }
virtual DefType definitionType() const =0
static QDict< DefinitionIntf > * symbolMap
Definition: doxygen.h:134
static void listSymbol(Definition *d)
Definition: doxyapp.cpp:136
static void lookupSymbol ( Definition d)
static

Definition at line 171 of file doxyapp.cpp.

172 {
173  if (d!=Doxygen::globalScope && // skip the global namespace symbol
174  d->name().at(0)!='@' // skip anonymous stuff
175  )
176  {
177  printf("Symbol info\n");
178  printf("-----------\n");
179  printf("Name: %s\n",d->name().data());
180  printf("File: %s\n",d->getDefFileName().data());
181  printf("Line: %d\n",d->getDefLine());
182  // depending on the definition type we can case to the appropriate
183  // derived to get additional information
184  switch (d->definitionType())
185  {
187  {
188  ClassDef *cd = (ClassDef *)d;
189  printf("Kind: %s\n",cd->compoundTypeString().data());
190  }
191  break;
193  {
194  FileDef *fd = (FileDef *)d;
195  printf("Kind: File: #includes %d other files\n",
196  fd->includeFileList() ? fd->includeFileList()->count() : 0);
197  }
198  break;
200  {
201  NamespaceDef *nd = (NamespaceDef *)d;
202  printf("Kind: Namespace: contains %d classes and %d namespaces\n",
203  nd->getClassSDict() ? nd->getClassSDict()->count() : 0,
204  nd->getNamespaceSDict() ? nd->getNamespaceSDict()->count() : 0);
205  }
206  break;
208  {
209  MemberDef *md = (MemberDef *)d;
210  printf("Kind: %s\n",md->memberTypeName().data());
211  }
212  break;
213  default:
214  // ignore groups/pages/packages/dirs for now
215  break;
216  }
217  }
218 }
char & at(uint i) const
Definition: qcstring.h:326
QCString compoundTypeString() const
Definition: classdef.cpp:3499
int count() const
Definition: sortdict.h:284
QCString getDefFileName() const
static NamespaceDef * globalScope
Definition: doxygen.h:128
virtual DefType definitionType() const =0
uint count() const
Definition: qlist.h:66
const QCString & name() const
Definition: definition.h:114
int getDefLine() const
Definition: definition.h:188
QList< IncludeInfo > * includeFileList() const
Definition: filedef.h:124
const char * data() const
Definition: qcstring.h:207
NamespaceSDict * getNamespaceSDict() const
Definition: namespacedef.h:101
QCString memberTypeName() const
Definition: memberdef.cpp:3188
ClassSDict * getClassSDict() const
Definition: namespacedef.h:98
static void lookupSymbols ( const QCString sym)
static

Definition at line 220 of file doxyapp.cpp.

221 {
222  if (!sym.isEmpty())
223  {
224  DefinitionIntf *di = Doxygen::symbolMap->find(sym);
225  if (di)
226  {
228  {
230  Definition *d;
231  // for each symbol with the given name
232  for (dli.toFirst();(d=dli.current());++dli)
233  {
234  lookupSymbol(d);
235  }
236  }
237  else
238  {
239  lookupSymbol((Definition*)di);
240  }
241  }
242  else
243  {
244  printf("Unknown symbol\n");
245  }
246  }
247 }
bool isEmpty() const
Definition: qcstring.h:189
static void lookupSymbol(Definition *d)
Definition: doxyapp.cpp:171
virtual DefType definitionType() const =0
static QDict< DefinitionIntf > * symbolMap
Definition: doxygen.h:134
int main ( int  argc,
char **  argv 
)

Definition at line 249 of file doxyapp.cpp.

250 {
251  char cmd[256];
252 
253  if (argc<2)
254  {
255  printf("Usage: %s [source_file | source_dir]\n",argv[0]);
256  exit(1);
257  }
258 
259  // initialize data structures
260  initDoxygen();
261 
262  // setup the non-default configuration options
263 
264  // we need a place to put intermediate files
265  Config_getString("OUTPUT_DIRECTORY")="/tmp/doxygen";
266  // disable html output
267  Config_getBool("GENERATE_HTML")=FALSE;
268  // disable latex output
269  Config_getBool("GENERATE_LATEX")=FALSE;
270  // be quiet
271  Config_getBool("QUIET")=TRUE;
272  // turn off warnings
273  Config_getBool("WARNINGS")=FALSE;
274  Config_getBool("WARN_IF_UNDOCUMENTED")=FALSE;
275  Config_getBool("WARN_IF_DOC_ERROR")=FALSE;
276  // Extract as much as possible
277  Config_getBool("EXTRACT_ALL")=TRUE;
278  Config_getBool("EXTRACT_STATIC")=TRUE;
279  Config_getBool("EXTRACT_PRIVATE")=TRUE;
280  Config_getBool("EXTRACT_LOCAL_METHODS")=TRUE;
281  // Extract source browse information, needed
282  // to make doxygen gather the cross reference info
283  Config_getBool("SOURCE_BROWSER")=TRUE;
284 
285  // set the input
286  Config_getList("INPUT").append(argv[1]);
287 
288  // check and finialize the configuration
291 
292  // parse the files
293  parseInput();
294 
295  // iterate over the input files
297  FileName *fn;
298  // foreach file with a certain name
299  for (fnli.toFirst();(fn=fnli.current());++fnli)
300  {
301  FileNameIterator fni(*fn);
302  FileDef *fd;
303  // for each file definition
304  for (;(fd=fni.current());++fni)
305  {
306  // get the references (linked and unlinked) found in this file
307  findXRefSymbols(fd);
308  }
309  }
310 
311  // remove temporary files
314  // clean up after us
315  QDir().rmdir("/tmp/doxygen");
316 
317  while (1)
318  {
319  printf("> Type a symbol name or\n> .list for a list of symbols or\n> .quit to exit\n> ");
320  fgets(cmd,256,stdin);
321  QCString s(cmd);
322  if (s.at(s.length()-1)=='\n') s=s.left(s.length()-1); // strip trailing \n
323  if (s==".list")
324  listSymbols();
325  else if (s==".quit")
326  exit(0);
327  else
328  lookupSymbols(s);
329  }
330 }
Traverses directory structures and contents in a platform-independent way.
Definition: qdir.h:52
uint length() const
Definition: qcstring.h:195
void initDoxygen()
Definition: doxygen.cpp:9979
char & at(uint i) const
Definition: qcstring.h:326
const bool FALSE
Definition: qglobal.h:370
static FileNameList * inputNameList
Definition: doxygen.h:109
void checkConfiguration()
Definition: doxygen.cpp:10493
#define Config_getList(val)
Definition: config.cpp:662
QCString left(uint len) const
Definition: qcstring.cpp:213
static void findXRefSymbols(FileDef *fd)
Definition: doxyapp.cpp:109
void adjustConfiguration()
Definition: doxygen.cpp:10504
QAsciiDict< Entry > fn
static QCString objDBFileName
Definition: doxygen.h:144
#define Config_getString(val)
Definition: config.cpp:660
#define Config_getBool(val)
Definition: config.cpp:664
static void lookupSymbols(const QCString &sym)
Definition: doxyapp.cpp:220
static QCString entryDBFileName
Definition: doxygen.h:145
virtual bool rmdir(const QString &dirName, bool acceptAbsPath=TRUE) const
Definition: qdir_unix.cpp:104
bool remove()
Definition: qfile.cpp:205
void parseInput()
Definition: doxygen.cpp:10880
list cmd
Definition: getreco.py:22
static void listSymbols()
Definition: doxyapp.cpp:147
static QCString * s
Definition: config.cpp:1042
const bool TRUE
Definition: qglobal.h:371