/******************************************************************************
*
*
*
*
* Copyright (C) 1997-2003 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qcstring.h>
#include <qstack.h>
#include <qdict.h>
#include <qregexp.h>
#include <ctype.h>
#include "doxygen.h"
#include "debug.h"
#include "util.h"
#include "page.h"
#include "docparser.h"
#include "doctokenizer.h"
#include "cmdmapper.h"
#include "printdocvisitor.h"
#include "message.h"
#define DBG(x) do {} while(0)
//#define DBG(x) printf x
#define INTERNAL_ASSERT(x) do {} while(0)
//#define INTERNAL_ASSERT(x) if (!(x)) DBG(("INTERNAL_ASSERT(%s) failed retval=0x%x: file=%s line=%d\n",#x,retval,__FILE__,__LINE__));
//---------------------------------------------------------------------------
static const char *sectionLevelToName[] =
{
"page",
"section",
"subsection",
"subsubsection",
"paragraph"
};
//---------------------------------------------------------------------------
// global variables during a call to validatingParseDoc
static bool g_hasParamCommand;
static MemberDef * g_memberDef;
static QDict<void> g_paramsFound;
static bool g_isExample;
// include file state
static QString g_includeFileText;
static uint g_includeFileOffset;
static uint g_includeFileLength;
// parser state
static QString g_context;
static bool g_inSeeBlock;
static bool g_insideHtmlLink;
static QStack<DocNode> g_nodeStack;
static QStack<DocStyleChange> g_styleStack;
static QStack<DocStyleChange> g_initialStyleStack;
static QList<Definition> g_copyStack;
static QString g_fileName;
struct DocParserContext
{
QString context;
bool inSeeBlock;
bool insideHtmlLink;
QStack<DocNode> nodeStack;
QStack<DocStyleChange> styleStack;
QStack<DocStyleChange> initialStyleStack;
QList<Definition> copyStack;
MemberDef *memberDef;
QString fileName;
};
static QStack<DocParserContext> g_parserStack;
//---------------------------------------------------------------------------
static void docParserPushContext()
{
doctokenizerYYpushContext();
DocParserContext *ctx = new DocParserContext;
ctx->context = g_context;
ctx->inSeeBlock = g_inSeeBlock;
ctx->insideHtmlLink = g_insideHtmlLink;
ctx->nodeStack = g_nodeStack;
ctx->styleStack = g_styleStack;
ctx->initialStyleStack = g_initialStyleStack;
ctx->copyStack = g_copyStack;
ctx->fileName = g_fileName;
g_parserStack.push(ctx);
}
static void docParserPopContext()
{
DocParserContext *ctx = g_parserStack.pop();
g_context = ctx->context;
g_inSeeBlock = ctx->inSeeBlock;
g_insideHtmlLink = ctx->insideHtmlLink;
g_nodeStack = ctx->nodeStack;
g_styleStack = ctx->styleStack;
g_initialStyleStack = ctx->initialStyleStack;
g_copyStack = ctx->copyStack;
g_fileName = ctx->fileName;
delete ctx;
doctokenizerYYpopContext();
}
//---------------------------------------------------------------------------
/*! search for an image in the imageNameDict and if found
* copies the image to the output directory (which depends on the \a type
* parameter).
*/
static QCString findAndCopyImage(const char *fileName,DocImage::Type type)
{
QCString result;
bool ambig;
FileDef *fd;
//printf("Search for %s\n",fileName);
if ((fd=findFileDef(Doxygen::imageNameDict,fileName,ambig)))
{
QFile inImage(QString(fd->absFilePath().data()));
if (inImage.open(IO_ReadOnly))
{
result = fileName;
int i;
if ((i=result.findRev('/'))!=-1 || (i=result.findRev('\\'))!=-1)
{
result.right(result.length()-i-1);
}
QCString outputDir;
switch(type)
{
case DocImage::Html:
if (!Config_getBool("GENERATE_HTML")) return result;
outputDir = Config_getString("HTML_OUTPUT");
break;
case DocImage::Latex:
if (!Config_getBool("GENERATE_LATEX")) return result;
outputDir = Config_getString("LATEX_OUTPUT");
break;
case DocImage::Rtf:
if (!Config_getBool("GENERATE_RTF")) return result;
outputDir = Config_getString("RTF_OUTPUT");
break;
}
QCString outputFile = outputDir+"/"+result;
QFile outImage(QString(outputFile.data()));
if (outImage.open(IO_WriteOnly)) // copy the image
{
char *buffer = new char[inImage.size()];
inImage.readBlock(buffer,inImage.size());
outImage.writeBlock(buffer,inImage.size());
outImage.flush();
delete buffer;
}
else
{
warn_doc_error(g_fileName,doctokenizerYYlineno,
"Warning: could not write output image %s",outputFile.data());
}
}
else
{
warn_doc_error(g_fileName,doctokenizerYYlineno,
"Warning: could not open image %s",fileName);
}
if (type==DocImage::Latex && Config_getBool("USE_PDFLATEX") &&
fd->name().right(4)==".eps"
)
{ // we have an .eps image in pdflatex mode => convert it to a pdf.
QCString outputDir = Config_getString("LATEX_OUTPUT");
QCString baseName = fd->name().left(fd->name().length()-4);
QCString epstopdfArgs(4096);
epstopdfArgs.sprintf("\"%s/%s.eps\" --outfile=\"%s/%s.pdf\"",
outputDir.data(), baseName.data(),
outputDir.data(), baseName.data());
if (iSystem("epstopdf",epstopdfArgs,TRUE)!=0)
{
err("Error: Problems running epstopdf. Check your TeX installation!\n");
}
|