Blame addon/doxyapp/doxyapp.cpp

Packit Service 50c9f2
/******************************************************************************
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Copyright (C) 1997-2015 by Dimitri van Heesch.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Permission to use, copy, modify, and distribute this software and its
Packit Service 50c9f2
 * documentation under the terms of the GNU General Public License is hereby 
Packit Service 50c9f2
 * granted. No representations are made about the suitability of this software 
Packit Service 50c9f2
 * for any purpose. It is provided "as is" without express or implied warranty.
Packit Service 50c9f2
 * See the GNU General Public License for more details.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Documents produced by Doxygen are derivative works derived from the
Packit Service 50c9f2
 * input used in their production; they are not affected by this license.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 */
Packit Service 50c9f2
Packit Service 50c9f2
/** @file
Packit Service 50c9f2
 *  @brief Example of how to use doxygen as part of another GPL applications
Packit Service 50c9f2
 *
Packit Service 50c9f2
 *  This example shows how to configure and run doxygen programmatically from
Packit Service 50c9f2
 *  within an application without generating the usual output.
Packit Service 50c9f2
 *  The example should work on any Unix like OS (including Linux and Mac OS X).
Packit Service 50c9f2
 *  
Packit Service 50c9f2
 *  This example shows how to use to code parser to get cross-references information
Packit Service 50c9f2
 *  and it also shows how to look up symbols in a program parsed by doxygen and
Packit Service 50c9f2
 *  show some information about them.
Packit Service 50c9f2
 */
Packit Service 50c9f2
Packit Service 50c9f2
#include <stdlib.h>
Packit Service 50c9f2
#include <qfile.h>
Packit Service 50c9f2
#include <qdir.h>
Packit Service 50c9f2
#include "doxygen.h"
Packit Service 50c9f2
#include "outputgen.h"
Packit Service 50c9f2
#include "parserintf.h"
Packit Service 50c9f2
#include "classdef.h"
Packit Service 50c9f2
#include "namespacedef.h"
Packit Service 50c9f2
#include "filedef.h"
Packit Service 50c9f2
#include "util.h"
Packit Service 50c9f2
#include "classlist.h"
Packit Service 50c9f2
#include "config.h"
Packit Service 50c9f2
#include "filename.h"
Packit Service 50c9f2
Packit Service 50c9f2
class XRefDummyCodeGenerator : public CodeOutputInterface
Packit Service 50c9f2
{
Packit Service 50c9f2
  public:
Packit Service 50c9f2
    XRefDummyCodeGenerator(FileDef *fd) : m_fd(fd) {}
Packit Service 50c9f2
   ~XRefDummyCodeGenerator() {}
Packit Service 50c9f2
Packit Service 50c9f2
    // these are just null functions, they can be used to produce a syntax highlighted
Packit Service 50c9f2
    // and cross-linked version of the source code, but who needs that anyway ;-)
Packit Service 50c9f2
    void codify(const char *) {}
Packit Service 50c9f2
    void writeCodeLink(const char *,const char *,const char *,const char *,const char *)  {}
Packit Service 50c9f2
    void writeLineNumber(const char *,const char *,const char *,int) {}
Packit Service 50c9f2
    virtual void writeTooltip(const char *,const DocLinkInfo &,
Packit Service 50c9f2
                              const char *,const char *,const SourceLinkInfo &, 
Packit Service 50c9f2
                              const SourceLinkInfo &) {}
Packit Service 50c9f2
    void startCodeLine(bool) {}
Packit Service 50c9f2
    void endCodeLine() {}
Packit Service 50c9f2
    void startCodeAnchor(const char *) {}
Packit Service 50c9f2
    void endCodeAnchor() {}
Packit Service 50c9f2
    void startFontClass(const char *) {}
Packit Service 50c9f2
    void endFontClass() {}
Packit Service 50c9f2
    void writeCodeAnchor(const char *) {}
Packit Service 50c9f2
    void setCurrentDoc(Definition *,const char *,bool) {}
Packit Service 50c9f2
    void addWord(const char *,bool) {}
Packit Service 50c9f2
Packit Service 50c9f2
    // here we are presented with the symbols found by the code parser
Packit Service 50c9f2
    void linkableSymbol(int l, const char *sym,Definition *symDef,Definition *context) 
Packit Service 50c9f2
    {
Packit Service 50c9f2
      QCString ctx;
Packit Service 50c9f2
      if (context) // the context of the symbol is known
Packit Service 50c9f2
      {
Packit Service 50c9f2
        if (context->definitionType()==Definition::TypeMember) // it is inside a member
Packit Service 50c9f2
        {
Packit Service 50c9f2
          Definition *parentContext = context->getOuterScope();
Packit Service 50c9f2
          if (parentContext && parentContext->definitionType()==Definition::TypeClass)
Packit Service 50c9f2
             // it is inside a member of a class
Packit Service 50c9f2
          {
Packit Service 50c9f2
            ctx.sprintf("inside %s %s of %s %s",
Packit Service 50c9f2
              ((MemberDef *)context)->memberTypeName().data(),
Packit Service 50c9f2
              context->name().data(),
Packit Service 50c9f2
              ((ClassDef*)parentContext)->compoundTypeString().data(),
Packit Service 50c9f2
              parentContext->name().data());
Packit Service 50c9f2
          }
Packit Service 50c9f2
          else if (parentContext==Doxygen::globalScope) // it is inside a global member
Packit Service 50c9f2
          {
Packit Service 50c9f2
            ctx.sprintf("inside %s %s",
Packit Service 50c9f2
              ((MemberDef *)context)->memberTypeName().data(),
Packit Service 50c9f2
              context->name().data());
Packit Service 50c9f2
          }
Packit Service 50c9f2
        }
Packit Service 50c9f2
        if (ctx.isEmpty()) // it is something else (class, or namespace member, ...)
Packit Service 50c9f2
        {
Packit Service 50c9f2
          ctx.sprintf("in %s",context->name().data());
Packit Service 50c9f2
        }
Packit Service 50c9f2
      }
Packit Service 50c9f2
      printf("Found symbol %s at line %d of %s %s\n",
Packit Service 50c9f2
          sym,l,m_fd->getDefFileName().data(),ctx.data());
Packit Service 50c9f2
      if (symDef && context) // in this case the definition of the symbol is
Packit Service 50c9f2
        // known to doxygen.
Packit Service 50c9f2
      {
Packit Service 50c9f2
        printf("-> defined at line %d of %s\n",
Packit Service 50c9f2
            symDef->getDefLine(),symDef->getDefFileName().data());
Packit Service 50c9f2
      }
Packit Service 50c9f2
    }
Packit Service 50c9f2
  private:
Packit Service 50c9f2
    FileDef *m_fd;
Packit Service 50c9f2
};
Packit Service 50c9f2
Packit Service 50c9f2
static void findXRefSymbols(FileDef *fd)
Packit Service 50c9f2
{
Packit Service 50c9f2
  // get the interface to a parser that matches the file extension
Packit Service 50c9f2
  ParserInterface *pIntf=Doxygen::parserManager->getParser(fd->getDefFileExtension());
Packit Service 50c9f2
Packit Service 50c9f2
  // get the programming language from the file name
Packit Service 50c9f2
  SrcLangExt lang = getLanguageFromFileName(fd->name());
Packit Service 50c9f2
Packit Service 50c9f2
  // reset the parsers state
Packit Service 50c9f2
  pIntf->resetCodeParserState();
Packit Service 50c9f2
Packit Service 50c9f2
  // create a new backend object 
Packit Service 50c9f2
  XRefDummyCodeGenerator *xrefGen = new XRefDummyCodeGenerator(fd);
Packit Service 50c9f2
Packit Service 50c9f2
  // parse the source code
Packit Service 50c9f2
  pIntf->parseCode(*xrefGen,
Packit Service 50c9f2
                0,
Packit Service 50c9f2
                fileToString(fd->absFilePath()),
Packit Service 50c9f2
                lang,
Packit Service 50c9f2
                FALSE,
Packit Service 50c9f2
                0,
Packit Service 50c9f2
                fd);
Packit Service 50c9f2
Packit Service 50c9f2
  // dismiss the object.
Packit Service 50c9f2
  delete xrefGen;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
static void listSymbol(Definition *d)
Packit Service 50c9f2
{
Packit Service 50c9f2
  if (d!=Doxygen::globalScope && // skip the global namespace symbol
Packit Service 50c9f2
      d->name().at(0)!='@'       // skip anonymous stuff
Packit Service 50c9f2
     )      
Packit Service 50c9f2
  {
Packit Service 50c9f2
    printf("%s\n",
Packit Service 50c9f2
        d->name().data());
Packit Service 50c9f2
  }
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
static void listSymbols()
Packit Service 50c9f2
{
Packit Service 50c9f2
  QDictIterator<DefinitionIntf> sli(*Doxygen::symbolMap);
Packit Service 50c9f2
  DefinitionIntf *di;
Packit Service 50c9f2
  for (sli.toFirst();(di=sli.current());++sli)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    if (di->definitionType()==DefinitionIntf::TypeSymbolList) // list of symbols
Packit Service 50c9f2
      // with same name
Packit Service 50c9f2
    {
Packit Service 50c9f2
      DefinitionListIterator dli(*(DefinitionList*)di);
Packit Service 50c9f2
      Definition *d;
Packit Service 50c9f2
      // for each symbol
Packit Service 50c9f2
      for (dli.toFirst();(d=dli.current());++dli)
Packit Service 50c9f2
      {
Packit Service 50c9f2
        listSymbol(d);
Packit Service 50c9f2
      }
Packit Service 50c9f2
    }
Packit Service 50c9f2
    else // single symbol
Packit Service 50c9f2
    {
Packit Service 50c9f2
      listSymbol((Definition*)di);
Packit Service 50c9f2
    }
Packit Service 50c9f2
  }
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
static void lookupSymbol(Definition *d)
Packit Service 50c9f2
{
Packit Service 50c9f2
  if (d!=Doxygen::globalScope && // skip the global namespace symbol
Packit Service 50c9f2
      d->name().at(0)!='@'       // skip anonymous stuff
Packit Service 50c9f2
     )      
Packit Service 50c9f2
  {
Packit Service 50c9f2
    printf("Symbol info\n");
Packit Service 50c9f2
    printf("-----------\n");
Packit Service 50c9f2
    printf("Name: %s\n",d->name().data());
Packit Service 50c9f2
    printf("File: %s\n",d->getDefFileName().data());
Packit Service 50c9f2
    printf("Line: %d\n",d->getDefLine());
Packit Service 50c9f2
    // depending on the definition type we can case to the appropriate
Packit Service 50c9f2
    // derived to get additional information
Packit Service 50c9f2
    switch (d->definitionType())
Packit Service 50c9f2
    {
Packit Service 50c9f2
      case Definition::TypeClass:
Packit Service 50c9f2
        {
Packit Service 50c9f2
          ClassDef *cd = (ClassDef *)d;
Packit Service 50c9f2
          printf("Kind: %s\n",cd->compoundTypeString().data());
Packit Service 50c9f2
        }
Packit Service 50c9f2
        break;
Packit Service 50c9f2
      case Definition::TypeFile:
Packit Service 50c9f2
        {
Packit Service 50c9f2
          FileDef *fd = (FileDef *)d;
Packit Service 50c9f2
          printf("Kind: File: #includes %d other files\n",
Packit Service 50c9f2
              fd->includeFileList() ? fd->includeFileList()->count() : 0);
Packit Service 50c9f2
        }
Packit Service 50c9f2
        break;
Packit Service 50c9f2
      case Definition::TypeNamespace:
Packit Service 50c9f2
        {
Packit Service 50c9f2
          NamespaceDef *nd = (NamespaceDef *)d;
Packit Service 50c9f2
          printf("Kind: Namespace: contains %d classes and %d namespaces\n",
Packit Service 50c9f2
              nd->getClassSDict() ? nd->getClassSDict()->count() : 0,
Packit Service 50c9f2
              nd->getNamespaceSDict() ? nd->getNamespaceSDict()->count() : 0);
Packit Service 50c9f2
        }
Packit Service 50c9f2
        break;
Packit Service 50c9f2
      case Definition::TypeMember:
Packit Service 50c9f2
        {
Packit Service 50c9f2
          MemberDef *md = (MemberDef *)d;
Packit Service 50c9f2
          printf("Kind: %s\n",md->memberTypeName().data());
Packit Service 50c9f2
        }
Packit Service 50c9f2
        break;
Packit Service 50c9f2
      default:
Packit Service 50c9f2
        // ignore groups/pages/packages/dirs for now
Packit Service 50c9f2
        break;
Packit Service 50c9f2
    }
Packit Service 50c9f2
  }
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
static void lookupSymbols(const QCString &sym)
Packit Service 50c9f2
{
Packit Service 50c9f2
  if (!sym.isEmpty())
Packit Service 50c9f2
  {
Packit Service 50c9f2
    DefinitionIntf *di = Doxygen::symbolMap->find(sym);
Packit Service 50c9f2
    if (di)
Packit Service 50c9f2
    {
Packit Service 50c9f2
      if (di->definitionType()==DefinitionIntf::TypeSymbolList)
Packit Service 50c9f2
      {
Packit Service 50c9f2
        DefinitionListIterator dli(*(DefinitionList*)di);
Packit Service 50c9f2
        Definition *d;
Packit Service 50c9f2
        // for each symbol with the given name
Packit Service 50c9f2
        for (dli.toFirst();(d=dli.current());++dli)
Packit Service 50c9f2
        {
Packit Service 50c9f2
          lookupSymbol(d);
Packit Service 50c9f2
        }
Packit Service 50c9f2
      }
Packit Service 50c9f2
      else
Packit Service 50c9f2
      {
Packit Service 50c9f2
        lookupSymbol((Definition*)di);
Packit Service 50c9f2
      }
Packit Service 50c9f2
    }
Packit Service 50c9f2
    else
Packit Service 50c9f2
    {
Packit Service 50c9f2
      printf("Unknown symbol\n");
Packit Service 50c9f2
    }
Packit Service 50c9f2
  }
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
int main(int argc,char **argv)
Packit Service 50c9f2
{
Packit Service 50c9f2
  char cmd[256];
Packit Service 50c9f2
Packit Service 50c9f2
  if (argc<2)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    printf("Usage: %s [source_file | source_dir]\n",argv[0]);
Packit Service 50c9f2
    exit(1);
Packit Service 50c9f2
  }
Packit Service 50c9f2
Packit Service 50c9f2
  // initialize data structures 
Packit Service 50c9f2
  initDoxygen();
Packit Service 50c9f2
Packit Service 50c9f2
  // setup the non-default configuration options
Packit Service 50c9f2
Packit Service 50c9f2
  // we need a place to put intermediate files
Packit Service 50c9f2
  Config_getString(OUTPUT_DIRECTORY)="/tmp/doxygen"; 
Packit Service 50c9f2
  // disable html output
Packit Service 50c9f2
  Config_getBool(GENERATE_HTML)=FALSE;
Packit Service 50c9f2
  // disable latex output
Packit Service 50c9f2
  Config_getBool(GENERATE_LATEX)=FALSE;
Packit Service 50c9f2
  // be quiet
Packit Service 50c9f2
  Config_getBool(QUIET)=TRUE;
Packit Service 50c9f2
  // turn off warnings
Packit Service 50c9f2
  Config_getBool(WARNINGS)=FALSE;
Packit Service 50c9f2
  Config_getBool(WARN_IF_UNDOCUMENTED)=FALSE;
Packit Service 50c9f2
  Config_getBool(WARN_IF_DOC_ERROR)=FALSE;
Packit Service 50c9f2
  // Extract as much as possible
Packit Service 50c9f2
  Config_getBool(EXTRACT_ALL)=TRUE;
Packit Service 50c9f2
  Config_getBool(EXTRACT_STATIC)=TRUE;
Packit Service 50c9f2
  Config_getBool(EXTRACT_PRIVATE)=TRUE;
Packit Service 50c9f2
  Config_getBool(EXTRACT_LOCAL_METHODS)=TRUE;
Packit Service 50c9f2
  // Extract source browse information, needed 
Packit Service 50c9f2
  // to make doxygen gather the cross reference info
Packit Service 50c9f2
  Config_getBool(SOURCE_BROWSER)=TRUE;
Packit Service 50c9f2
Packit Service 50c9f2
  // set the input
Packit Service 50c9f2
  Config_getList(INPUT).append(argv[1]);
Packit Service 50c9f2
Packit Service 50c9f2
  // check and finialize the configuration
Packit Service 50c9f2
  checkConfiguration();
Packit Service 50c9f2
  adjustConfiguration();
Packit Service 50c9f2
Packit Service 50c9f2
  // parse the files
Packit Service 50c9f2
  parseInput();
Packit Service 50c9f2
Packit Service 50c9f2
  // iterate over the input files
Packit Service 50c9f2
  FileNameListIterator fnli(*Doxygen::inputNameList); 
Packit Service 50c9f2
  FileName *fn;
Packit Service 50c9f2
  // foreach file with a certain name
Packit Service 50c9f2
  for (fnli.toFirst();(fn=fnli.current());++fnli)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    FileNameIterator fni(*fn);
Packit Service 50c9f2
    FileDef *fd;
Packit Service 50c9f2
    // for each file definition
Packit Service 50c9f2
    for (;(fd=fni.current());++fni)
Packit Service 50c9f2
    {
Packit Service 50c9f2
      // get the references (linked and unlinked) found in this file
Packit Service 50c9f2
      findXRefSymbols(fd);
Packit Service 50c9f2
    }
Packit Service 50c9f2
  }
Packit Service 50c9f2
Packit Service 50c9f2
  // remove temporary files
Packit Service 50c9f2
  if (!Doxygen::objDBFileName.isEmpty()) QFile::remove(Doxygen::objDBFileName);
Packit Service 50c9f2
  if (!Doxygen::entryDBFileName.isEmpty()) QFile::remove(Doxygen::entryDBFileName);
Packit Service 50c9f2
  // clean up after us
Packit Service 50c9f2
  QDir().rmdir("/tmp/doxygen");
Packit Service 50c9f2
Packit Service 50c9f2
  while (1)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    printf("> Type a symbol name or\n> .list for a list of symbols or\n> .quit to exit\n> ");
Packit Service 50c9f2
    fgets(cmd,256,stdin);
Packit Service 50c9f2
    QCString s(cmd);
Packit Service 50c9f2
    if (s.at(s.length()-1)=='\n') s=s.left(s.length()-1); // strip trailing \n
Packit Service 50c9f2
    if (s==".list") 
Packit Service 50c9f2
      listSymbols();
Packit Service 50c9f2
    else if (s==".quit") 
Packit Service 50c9f2
      exit(0);
Packit Service 50c9f2
    else 
Packit Service 50c9f2
      lookupSymbols(s);
Packit Service 50c9f2
  }
Packit Service 50c9f2
}
Packit Service 50c9f2