Thread: [Doxygen-develop] RE: Patch: Preprocessing DOT input files
Brought to you by:
dimitri
From: Michael M. <Mic...@tt...> - 2005-07-04 17:23:37
|
Hi there, I've made a few improvements to this such that it creates a separate ".i" file containing the preprocesed input. Aside, I've also been building using Cygwin and -mno-cygwin to make native Win32 binaries, which works rather nicely (although needs a hack in qtools.pro.in to use the win32 files). Anyone interested in these patches, or a binary with preprocessing functionality? Regards, Mike > -----Original Message----- > From: Michael McTernan [mailto:Mic...@tt...] > Sent: 25 May 2005 00:03 > To: 'dox...@li...'; 'di...@st...' > Subject: Patch: Preprocessing DOT input files > > Hi there, > > There was a post on the doxygen-users list a few days ago asking if it is > possible to do something like the following: > > /** blah blah > \dot > graph G { > a -- b > #if defined(ENABLE_C) > b -- c > c -- a > #endif > } > \enddot > > */ > > Basically this allows showing or hiding of nodes based on the pre- > processor defines. As far as I've been able to workout, this cannot be > done without invoking an external pre-processor as part of a build step or > script. > > This feature is something I very much want, as I have a large diagram with > a few small parts which are optional depending on compile switches. DOT > itself seems to like the idea of pre-processing as it ignores any lines > that start with a # character, so is safe to ignore and '#line' output, > were the pre-processor to make any. > > There follows a patch that adds an option "PREPROCESS_DOT_FILES" to allow > DOT input files to be preprocessed. I would be very grateful to know if > this patch can be included in a future version or Doxygen, or whether it > needs any changes to be acceptable. > > The patch can be applied in the following way: > > $ tar -xzf doxygen-1.4.3.src.tar.gz > $ cd doxygen-1.4.3 > $ patch -p1 < patchfile > > Here is the patch: > > diff -Naurw doxygen-1.4.3.orig/addon/doxywizard/config.l doxygen- > 1.4.3/addon/doxywizard/config.l > --- doxygen-1.4.3.orig/addon/doxywizard/config.l 2005-05-16 > 20:38:16.000000000 +0100 > +++ doxygen-1.4.3/addon/doxywizard/config.l 2005-05-24 > 22:57:11.358347200 +0100 > @@ -2491,6 +2491,16 @@ > TRUE > ); > cb->addDependency("ENABLE_PREPROCESSING"); > + cb = addBool( > + "PREPROCESS_DOT_FILES", > + "If the PREPROCESS_DOT_FILES tag is set to YES then > doxygen's preprocessor \n" > + "will be called on all files that are about to be > passed to DOT. This \n" > + "allows pre-processor protections to be added around > nodes such that build \n" > + "defines can add or hide graph nodes. The default > option is NO such that \n" > + "compatibility with older versions of Doxygen is > maintained. \n", > + FALSE > + ); > + cb->addDependency("ENABLE_PREPROCESSING"); > //--------------------------------------------------------------------- > -------------------------- > addInfo( "External","Configuration::additions related to external > references "); > //--------------------------------------------------------------------- > -------------------------- > diff -Naurw doxygen-1.4.3.orig/src/config.l doxygen-1.4.3/src/config.l > --- doxygen-1.4.3.orig/src/config.l 2005-05-12 20:19:42.000000000 +0100 > +++ doxygen-1.4.3/src/config.l 2005-05-24 22:56:52.050584000 +0100 > @@ -2491,6 +2491,16 @@ > TRUE > ); > cb->addDependency("ENABLE_PREPROCESSING"); > + cb = addBool( > + "PREPROCESS_DOT_FILES", > + "If the PREPROCESS_DOT_FILES tag is set to YES then > doxygen's preprocessor \n" > + "will be called on all files that are about to be > passed to DOT. This \n" > + "allows pre-processor protections to be added around > nodes such that build \n" > + "defines can add or hide graph nodes. The default > option is NO such that \n" > + "compatibility with older versions of Doxygen is > maintained. \n", > + FALSE > + ); > + cb->addDependency("ENABLE_PREPROCESSING"); > //--------------------------------------------------------------------- > -------------------------- > addInfo( "External","Configuration::additions related to external > references "); > //--------------------------------------------------------------------- > -------------------------- > diff -Naurw doxygen-1.4.3.orig/src/dot.cpp doxygen-1.4.3/src/dot.cpp > --- doxygen-1.4.3.orig/src/dot.cpp 2005-04-17 17:55:56.000000000 +0100 > +++ doxygen-1.4.3/src/dot.cpp 2005-05-24 23:44:22.929947200 +0100 > @@ -29,6 +29,8 @@ > #include "docparser.h" > #include "debug.h" > #include "pagedef.h" > +#include "pre.h" > +#include "bufstr.h" > > #include <qdir.h> > #include <qfile.h> > @@ -2714,6 +2716,24 @@ > #endif > absOutFile+=outFile; > > + // Preprocess the file if needed */ > + if(Config_getBool("PREPROCESS_DOT_FILES")) > + { > + BufStr ppBuf(512); > + > + preprocessFile(inFile, ppBuf); > + > + // Rewrite the buffer to the input file > + QFile file(inFile); > + if (!file.open(IO_WriteOnly)) > + { > + err("Could not open file %s for writing\n",inFile); > + } > + file.writeBlock( ppBuf.data(), ppBuf.curPos() ); > + file.close(); > + } > + > + > // chdir to the output dir, so dot can find the font file. > QCString oldDir = convertToQCString(QDir::currentDirPath()); > // go to the html output directory (i.e. path) > > > > Cheers, > > Mike |
From: Michael M. <Mic...@tt...> - 2005-07-04 22:35:51
|
Hi, I've improved the patch for preprocessing dot input files. It now generates an intermediate file (inputname.i), which is deleted/preserved based on the setting of DOT_CLEANUP. Apply in the following manner: $ tar -xzf doxygen-1.4.3.src.tar.gz $ cd doxygen-1.4.3 $ patch -p1 < patchfile The patch is available here: http://www.mcternan.co.uk/Doxygen/pre-proc-dot-1.4.3.patch Also listed directly: diff -Naurw doxygen-1.4.3.orig/addon/doxywizard/config.l doxygen-1.4.3/addon/doxywizard/config.l --- doxygen-1.4.3.orig/addon/doxywizard/config.l 2005-05-16 20:38:16.000000000 +0100 +++ doxygen-1.4.3/addon/doxywizard/config.l 2005-05-24 22:57:11.358347200 +0100 @@ -2491,6 +2491,16 @@ TRUE ); cb->addDependency("ENABLE_PREPROCESSING"); + cb = addBool( + "PREPROCESS_DOT_FILES", + "If the PREPROCESS_DOT_FILES tag is set to YES then doxygen's preprocessor \n" + "will be called on all files that are about to be passed to DOT. This \n" + "allows pre-processor protections to be added around nodes such that build \n" + "defines can add or hide graph nodes. The default option is NO such that \n" + "compatibility with older versions of Doxygen is maintained. \n", + FALSE + ); + cb->addDependency("ENABLE_PREPROCESSING"); //-------------------------------------------------------------------------- --------------------- addInfo( "External","Configuration::additions related to external references "); //-------------------------------------------------------------------------- --------------------- diff -Naurw doxygen-1.4.3.orig/src/config.l doxygen-1.4.3/src/config.l --- doxygen-1.4.3.orig/src/config.l 2005-05-12 20:19:42.000000000 +0100 +++ doxygen-1.4.3/src/config.l 2005-05-24 22:56:52.050584000 +0100 @@ -2491,6 +2491,16 @@ TRUE ); cb->addDependency("ENABLE_PREPROCESSING"); + cb = addBool( + "PREPROCESS_DOT_FILES", + "If the PREPROCESS_DOT_FILES tag is set to YES then doxygen's preprocessor \n" + "will be called on all files that are about to be passed to DOT. This \n" + "allows pre-processor protections to be added around nodes such that build \n" + "defines can add or hide graph nodes. The default option is NO such that \n" + "compatibility with older versions of Doxygen is maintained. \n", + FALSE + ); + cb->addDependency("ENABLE_PREPROCESSING"); //-------------------------------------------------------------------------- --------------------- addInfo( "External","Configuration::additions related to external references "); //-------------------------------------------------------------------------- --------------------- diff -Naurw doxygen-1.4.3.orig/src/dot.cpp doxygen-1.4.3/src/dot.cpp --- doxygen-1.4.3.orig/src/dot.cpp 2005-04-17 17:55:56.000000000 +0100 +++ doxygen-1.4.3/src/dot.cpp 2005-07-04 23:18:42.981606400 +0100 @@ -29,6 +29,8 @@ #include "docparser.h" #include "debug.h" #include "pagedef.h" +#include "pre.h" +#include "bufstr.h" #include <qdir.h> #include <qfile.h> @@ -2707,6 +2709,7 @@ const char *outFile,GraphOutputFormat format) { QCString absOutFile = outDir; + QCString *tempFile = NULL; #ifdef _WIN32 absOutFile+='\\'; #else @@ -2733,6 +2736,34 @@ QCString imgExt = Config_getEnum("DOT_IMAGE_FORMAT"); QCString imgName = (QCString)outFile+"."+imgExt; + // Preprocess the file if needed */ + if(Config_getBool("PREPROCESS_DOT_FILES")) + { + BufStr ppBuf(512); + + // Preprocess the input to the buffer + preprocessFile(inFile, ppBuf); + + // Duplicate outFile and append ".i" + tempFile = new SCString(outFile); + tempFile->append(".i"); + + // Rewrite the buffer to the input file + QFile file(*tempFile); + if (!file.open(IO_WriteOnly)) + { + err("Could not open file %s for writing\n", (const char *)tempFile); + } + else + { + file.writeBlock( ppBuf.data(), ppBuf.curPos() ); + file.close(); + + // Switch inFile to the preprocessed tempFile + inFile = tempFile->data(); + } + } + DotRunner dotRun(inFile); if (format==BITMAP) dotRun.addJob(imgExt,imgName); @@ -2775,9 +2806,22 @@ if (format==BITMAP) checkDotResult(imgName); - QDir::setCurrent(oldDir); + // Check if a temp file was created + if (tempFile) + { + // Delete the intermediate file if needed + if(Config_getBool("DOT_CLEANUP")) + { + QFile file(*tempFile); + + file.remove(); } + delete tempFile; + } + + QDir::setCurrent(oldDir);} + /*! Marco Dalla Gasperina [ma...@at...] added this to allow * dotfiles to generate image maps. Regards, Mike > -----Original Message----- > From: dox...@li... [mailto:doxygen-develop- > ad...@li...] On Behalf Of Michael McTernan > Sent: 04 July 2005 18:08 > To: dox...@li... > Subject: [Doxygen-develop] RE: Patch: Preprocessing DOT input files > > Hi there, > > I've made a few improvements to this such that it creates a separate ".i" > file containing the preprocesed input. > > Aside, I've also been building using Cygwin and -mno-cygwin to make native > Win32 binaries, which works rather nicely (although needs a hack in > qtools.pro.in to use the win32 files). > > Anyone interested in these patches, or a binary with preprocessing > functionality? > > Regards, > > Mike > > > -----Original Message----- > > From: Michael McTernan [mailto:Mic...@tt...] > > Sent: 25 May 2005 00:03 > > To: 'dox...@li...'; 'di...@st...' > > Subject: Patch: Preprocessing DOT input files > > > > Hi there, > > > > There was a post on the doxygen-users list a few days ago asking if it > is > > possible to do something like the following: > > > > /** blah blah > > \dot > > graph G { > > a -- b > > #if defined(ENABLE_C) > > b -- c > > c -- a > > #endif > > } > > \enddot > > > > */ > > > > Basically this allows showing or hiding of nodes based on the pre- > > processor defines. As far as I've been able to workout, this cannot be > > done without invoking an external pre-processor as part of a build step > or > > script. > > > > This feature is something I very much want, as I have a large diagram > with > > a few small parts which are optional depending on compile switches. DOT > > itself seems to like the idea of pre-processing as it ignores any lines > > that start with a # character, so is safe to ignore and '#line' output, > > were the pre-processor to make any. > > > > There follows a patch that adds an option "PREPROCESS_DOT_FILES" to > allow > > DOT input files to be preprocessed. I would be very grateful to know if > > this patch can be included in a future version or Doxygen, or whether it > > needs any changes to be acceptable. > > > > The patch can be applied in the following way: > > > > $ tar -xzf doxygen-1.4.3.src.tar.gz > > $ cd doxygen-1.4.3 > > $ patch -p1 < patchfile > > > > Here is the patch: > > > > diff -Naurw doxygen-1.4.3.orig/addon/doxywizard/config.l doxygen- > > 1.4.3/addon/doxywizard/config.l > > --- doxygen-1.4.3.orig/addon/doxywizard/config.l 2005-05-16 > > 20:38:16.000000000 +0100 > > +++ doxygen-1.4.3/addon/doxywizard/config.l 2005-05-24 > > 22:57:11.358347200 +0100 > > @@ -2491,6 +2491,16 @@ > > TRUE > > ); > > cb->addDependency("ENABLE_PREPROCESSING"); > > + cb = addBool( > > + "PREPROCESS_DOT_FILES", > > + "If the PREPROCESS_DOT_FILES tag is set to YES then > > doxygen's preprocessor \n" > > + "will be called on all files that are about to be > > passed to DOT. This \n" > > + "allows pre-processor protections to be added > around > > nodes such that build \n" > > + "defines can add or hide graph nodes. The default > > option is NO such that \n" > > + "compatibility with older versions of Doxygen is > > maintained. \n", > > + FALSE > > + ); > > + cb->addDependency("ENABLE_PREPROCESSING"); > > //------------------------------------------------------------------- > -- > > -------------------------- > > addInfo( "External","Configuration::additions related to external > > references "); > > //------------------------------------------------------------------- > -- > > -------------------------- > > diff -Naurw doxygen-1.4.3.orig/src/config.l doxygen-1.4.3/src/config.l > > --- doxygen-1.4.3.orig/src/config.l 2005-05-12 20:19:42.000000000 > +0100 > > +++ doxygen-1.4.3/src/config.l 2005-05-24 22:56:52.050584000 +0100 > > @@ -2491,6 +2491,16 @@ > > TRUE > > ); > > cb->addDependency("ENABLE_PREPROCESSING"); > > + cb = addBool( > > + "PREPROCESS_DOT_FILES", > > + "If the PREPROCESS_DOT_FILES tag is set to YES then > > doxygen's preprocessor \n" > > + "will be called on all files that are about to be > > passed to DOT. This \n" > > + "allows pre-processor protections to be added > around > > nodes such that build \n" > > + "defines can add or hide graph nodes. The default > > option is NO such that \n" > > + "compatibility with older versions of Doxygen is > > maintained. \n", > > + FALSE > > + ); > > + cb->addDependency("ENABLE_PREPROCESSING"); > > //------------------------------------------------------------------- > -- > > -------------------------- > > addInfo( "External","Configuration::additions related to external > > references "); > > //------------------------------------------------------------------- > -- > > -------------------------- > > diff -Naurw doxygen-1.4.3.orig/src/dot.cpp doxygen-1.4.3/src/dot.cpp > > --- doxygen-1.4.3.orig/src/dot.cpp 2005-04-17 17:55:56.000000000 > +0100 > > +++ doxygen-1.4.3/src/dot.cpp 2005-05-24 23:44:22.929947200 +0100 > > @@ -29,6 +29,8 @@ > > #include "docparser.h" > > #include "debug.h" > > #include "pagedef.h" > > +#include "pre.h" > > +#include "bufstr.h" > > > > #include <qdir.h> > > #include <qfile.h> > > @@ -2714,6 +2716,24 @@ > > #endif > > absOutFile+=outFile; > > > > + // Preprocess the file if needed */ > > + if(Config_getBool("PREPROCESS_DOT_FILES")) > > + { > > + BufStr ppBuf(512); > > + > > + preprocessFile(inFile, ppBuf); > > + > > + // Rewrite the buffer to the input file > > + QFile file(inFile); > > + if (!file.open(IO_WriteOnly)) > > + { > > + err("Could not open file %s for writing\n",inFile); > > + } > > + file.writeBlock( ppBuf.data(), ppBuf.curPos() ); > > + file.close(); > > + } > > + > > + > > // chdir to the output dir, so dot can find the font file. > > QCString oldDir = convertToQCString(QDir::currentDirPath()); > > // go to the html output directory (i.e. path) > > > > > > > > Cheers, > > > > Mike > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Doxygen-develop mailing list > Dox...@li... > https://lists.sourceforge.net/lists/listinfo/doxygen-develop |