My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Functions
definition.cpp File Reference
#include <ctype.h>
#include <qregexp.h>
#include "md5.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "config.h"
#include "definition.h"
#include "doxygen.h"
#include "language.h"
#include "message.h"
#include "outputlist.h"
#include "code.h"
#include "util.h"
#include "groupdef.h"
#include "pagedef.h"
#include "section.h"
#include "htags.h"
#include "parserintf.h"
#include "marshal.h"
#include "debug.h"
#include "vhdldocgen.h"
#include "memberlist.h"
#include "namespacedef.h"
#include "filedef.h"
#include "dirdef.h"

Go to the source code of this file.

Classes

class  DefinitionImpl
 

Macros

#define START_MARKER   0x4445465B
 
#define END_MARKER   0x4445465D
 
#define uni_isupper(c)   (QChar(c).category()==QChar::Letter_Uppercase)
 

Functions

static bool matchExcludedSymbols (const char *name)
 
static bool lastCharIsMultibyte (const QCString &s)
 
bool readCodeFragment (const char *fileName, int &startLine, int &endLine, QCString &result)
 
static bool stripWord (QCString &s, QCString w)
 
QCString abbreviate (const char *s, const char *name)
 

Macro Definition Documentation

#define END_MARKER   0x4445465D

Definition at line 46 of file definition.cpp.

#define START_MARKER   0x4445465B

Definition at line 45 of file definition.cpp.

#define uni_isupper (   c)    (QChar(c).category()==QChar::Letter_Uppercase)

Definition at line 618 of file definition.cpp.

Referenced by Definition::_setBriefDescription().

Function Documentation

QCString abbreviate ( const char *  s,
const char *  name 
)

Definition at line 1720 of file definition.cpp.

References Config_getList, and stripWord().

Referenced by Definition::briefDescription().

{
QCString scopelessName=name;
int i=scopelessName.findRev("::");
if (i!=-1) scopelessName=scopelessName.mid(i+2);
QCString result=s;
result=result.stripWhiteSpace();
// strip trailing .
if (!result.isEmpty() && result.at(result.length()-1)=='.')
result=result.left(result.length()-1);
// strip any predefined prefix
QStrList &briefDescAbbrev = Config_getList(ABBREVIATE_BRIEF);
const char *p = briefDescAbbrev.first();
while (p)
{
QCString s = p;
s.replace(QRegExp("\\$name"), scopelessName); // replace $name with entity name
s += " ";
stripWord(result,s);
p = briefDescAbbrev.next();
}
// capitalize first word
if (!result.isEmpty())
{
int c=result[0];
if (c>='a' && c<='z') c+='A'-'a';
result[0]=c;
}
return result;
}
static bool lastCharIsMultibyte ( const QCString &  s)
static

Definition at line 622 of file definition.cpp.

References nextUtf8CharPosition().

Referenced by Definition::_setBriefDescription().

{
int l = s.length();
int p = 0;
int pp = -1;
while ((p=nextUtf8CharPosition(s,l,p))<l) pp=p;
if (pp==-1 || ((uchar)s[pp])<0x80) return FALSE;
return TRUE;
}
static bool matchExcludedSymbols ( const char *  name)
static

Definition at line 150 of file definition.cpp.

References Config_getList, isId(), and substitute().

Referenced by Definition::Definition().

{
static QStrList &exclSyms = Config_getList(EXCLUDE_SYMBOLS);
if (exclSyms.count()==0) return FALSE; // nothing specified
const char *pat = exclSyms.first();
QCString symName = name;
while (pat)
{
QCString pattern = pat;
bool forceStart=FALSE;
bool forceEnd=FALSE;
if (pattern.at(0)=='^')
pattern=pattern.mid(1),forceStart=TRUE;
if (pattern.at(pattern.length()-1)=='$')
pattern=pattern.left(pattern.length()-1),forceEnd=TRUE;
if (pattern.find('*')!=-1) // wildcard mode
{
QRegExp re(substitute(pattern,"*",".*"),TRUE);
int i,pl;
i = re.match(symName,0,&pl);
//printf(" %d = re.match(%s) pattern=%s\n",i,symName.data(),pattern.data());
if (i!=-1) // wildcard match
{
int sl=symName.length();
// check if it is a whole word match
if ((i==0 || pattern.at(0)=='*' || (!isId(symName.at(i-1)) && !forceStart)) &&
(i+pl==sl || pattern.at(i+pl)=='*' || (!isId(symName.at(i+pl)) && !forceEnd))
)
{
//printf("--> name=%s pattern=%s match at %d\n",symName.data(),pattern.data(),i);
return TRUE;
}
}
}
else if (!pattern.isEmpty()) // match words
{
int i = symName.find(pattern);
if (i!=-1) // we have a match!
{
int pl=pattern.length();
int sl=symName.length();
// check if it is a whole word match
if ((i==0 || (!isId(symName.at(i-1)) && !forceStart)) &&
(i+pl==sl || (!isId(symName.at(i+pl)) && !forceEnd))
)
{
//printf("--> name=%s pattern=%s match at %d\n",symName.data(),pattern.data(),i);
return TRUE;
}
}
}
pat = exclSyms.next();
}
//printf("--> name=%s: no match\n",name);
return FALSE;
}
bool readCodeFragment ( const char *  fileName,
int &  startLine,
int &  endLine,
QCString &  result 
)

Reads a fragment of code from file fileName starting at line startLine and ending at line endLine (inclusive). The fragment is stored in result. If FALSE is returned the code fragment could not be found.

The file is scanned for a opening bracket ('{') from startLine onward The line actually containing the bracket is returned via startLine. The file is scanned for a closing bracket ('}') from endLine backward. The line actually containing the bracket is returned via endLine. Note that for VHDL code the bracket search is not done.

Definition at line 728 of file definition.cpp.

References Config_getBool, Config_getInt, Debug::ExtCmd, filter(), Debug::FilterOutput, getFileFilter(), getLanguageFromFileName(), portable_fopen(), portable_pclose(), portable_popen(), Debug::print(), SrcLangExt_Fortran, SrcLangExt_Python, SrcLangExt_Tcl, SrcLangExt_VHDL, and transcodeCharacterStringToUTF8().

Referenced by VhdlDocGen::createFlowChart(), MemberContext::Private::sourceCode(), and Definition::writeInlineCode().

{
static bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
static int tabSize = Config_getInt(TAB_SIZE);
//printf("readCodeFragment(%s,%d,%d)\n",fileName,startLine,endLine);
if (fileName==0 || fileName[0]==0) return FALSE; // not a valid file name
QCString filter = getFileFilter(fileName,TRUE);
FILE *f=0;
bool usePipe = !filter.isEmpty() && filterSourceFiles;
if (!usePipe) // no filter given or wanted
{
f = portable_fopen(fileName,"r");
}
else // use filter
{
QCString cmd=filter+" \""+fileName+"\"";
Debug::print(Debug::ExtCmd,0,"Executing popen(`%s`)\n",qPrint(cmd));
f = portable_popen(cmd,"r");
}
bool found = lang==SrcLangExt_VHDL ||
lang==SrcLangExt_Tcl ||
// for VHDL, TCL, Python, and Fortran no bracket search is possible
if (f)
{
int c=0;
int col=0;
int lineNr=1;
// skip until the startLine has reached
while (lineNr<startLine && !feof(f))
{
while ((c=fgetc(f))!='\n' && c!=EOF) /* skip */;
lineNr++;
if (found && c == '\n') c = '\0';
}
if (!feof(f))
{
// skip until the opening bracket or lonely : is found
char cn=0;
while (lineNr<=endLine && !feof(f) && !found)
{
int pc=0;
while ((c=fgetc(f))!='{' && c!=':' && c!=EOF) // } so vi matching brackets has no problem
{
//printf("parsing char `%c'\n",c);
if (c=='\n')
{
lineNr++,col=0;
}
else if (c=='\t')
{
col+=tabSize - (col%tabSize);
}
else if (pc=='/' && c=='/') // skip single line comment
{
while ((c=fgetc(f))!='\n' && c!=EOF) pc=c;
if (c=='\n') lineNr++,col=0;
}
else if (pc=='/' && c=='*') // skip C style comment
{
while (((c=fgetc(f))!='/' || pc!='*') && c!=EOF)
{
if (c=='\n') lineNr++,col=0;
pc=c;
}
}
else
{
col++;
}
pc = c;
}
if (c==':')
{
cn=fgetc(f);
if (cn!=':') found=TRUE;
}
else if (c=='{') // } so vi matching brackets has no problem
{
found=TRUE;
}
}
//printf(" -> readCodeFragment(%s,%d,%d) lineNr=%d\n",fileName,startLine,endLine,lineNr);
if (found)
{
// For code with more than one line,
// fill the line with spaces until we are at the right column
// so that the opening brace lines up with the closing brace
if (endLine!=startLine)
{
QCString spaces;
spaces.fill(' ',col);
result+=spaces;
}
// copy until end of line
if (c) result+=c;
startLine=lineNr;
if (c==':')
{
result+=cn;
if (cn=='\n') lineNr++;
}
const int maxLineLength=4096;
char lineStr[maxLineLength];
do
{
//printf("reading line %d in range %d-%d\n",lineNr,startLine,endLine);
int size_read;
do
{
// read up to maxLineLength-1 bytes, the last byte being zero
char *p = fgets(lineStr, maxLineLength,f);
//printf(" read %s",p);
if (p)
{
size_read=qstrlen(p);
}
else // nothing read
{
size_read=-1;
lineStr[0]='\0';
}
result+=lineStr;
} while (size_read == (maxLineLength-1));
lineNr++;
} while (lineNr<=endLine && !feof(f));
// strip stuff after closing bracket
int newLineIndex = result.findRev('\n');
int braceIndex = result.findRev('}');
if (braceIndex > newLineIndex)
{
result.truncate(braceIndex+1);
}
endLine=lineNr-1;
}
}
if (usePipe)
{
Debug::print(Debug::FilterOutput, 0, "Filter output\n");
Debug::print(Debug::FilterOutput,0,"-------------\n%s\n-------------\n",qPrint(result));
}
else
{
fclose(f);
}
}
if (!result.isEmpty() && result.at(result.length()-1)!='\n') result += "\n";
//fprintf(stderr,"readCodeFragement(%d-%d)=%s\n",startLine,endLine,result.data());
return found;
}
static bool stripWord ( QCString &  s,
QCString  w 
)
static

Definition at line 1707 of file definition.cpp.

Referenced by abbreviate().

{
bool success=FALSE;
if (s.left(w.length())==w)
{
success=TRUE;
s=s.right(s.length()-w.length());
}
return success;
}