Macros | Functions
rtfgen.cpp File Reference
#include <stdlib.h>
#include <qdir.h>
#include <qregexp.h>
#include <qtextstream.h>
#include "rtfgen.h"
#include "config.h"
#include "message.h"
#include "doxygen.h"
#include "util.h"
#include "diagram.h"
#include "language.h"
#include "dot.h"
#include "version.h"
#include "pagedef.h"
#include "rtfstyle.h"
#include "rtfdocvisitor.h"
#include "docparser.h"
#include "dirdef.h"
#include "vhdldocgen.h"
#include "portable.h"
#include "groupdef.h"
#include "classlist.h"
#include "filename.h"
#include "namespacedef.h"

Go to the source code of this file.

Macros

#define DBG_RTF(x)
 

Functions

static QCString dateToRTFDateString ()
 
static QCString makeIndexName (const char *s, int i)
 
bool isLeadBytes (int c)
 
static void encodeForOutput (FTextStream &t, const char *s)
 
static bool preProcessFile (QDir &d, QCString &infName, FTextStream &t, bool bIncludeHeader=TRUE)
 
void testRTFOutput (const char *name)
 

Macro Definition Documentation

#define DBG_RTF (   x)

Definition at line 48 of file rtfgen.cpp.

Function Documentation

static QCString dateToRTFDateString ( )
static

Definition at line 50 of file rtfgen.cpp.

51 {
54  result.sprintf("\\yr%d\\mo%d\\dy%d\\hr%d\\min%d\\sec%d",
55  d.date().year(), d.date().month(), d.date().day(),
56  d.time().hour(),d.time().minute(),d.time().second());
57  return result;
58 }
static QCString result
QTime time() const
Definition: qdatetime.h:172
int hour() const
Definition: qdatetime.cpp:648
int minute() const
Definition: qdatetime.cpp:657
The QDateTime class provides date and time functions.
Definition: qdatetime.h:161
QCString & sprintf(const char *format,...)
Definition: qcstring.cpp:27
QDate date() const
Definition: qdatetime.h:171
static QDateTime currentDateTime()
Definition: qdatetime.cpp:1340
int month() const
Definition: qdatetime.cpp:202
int year() const
Definition: qdatetime.cpp:189
int second() const
Definition: qdatetime.cpp:666
int day() const
Definition: qdatetime.cpp:215
static void encodeForOutput ( FTextStream t,
const char *  s 
)
static

Definition at line 2299 of file rtfgen.cpp.

2300 {
2301  if (s==0) return;
2303  bool converted=FALSE;
2304  int l = qstrlen(s);
2305  static QByteArray enc;
2306  if (l*4>(int)enc.size()) enc.resize(l*4); // worst case
2307  encoding.sprintf("CP%s",theTranslator->trRTFansicp().data());
2308  if (!encoding.isEmpty())
2309  {
2310  // convert from UTF-8 back to the output encoding
2311  void *cd = portable_iconv_open(encoding,"UTF-8");
2312  if (cd!=(void *)(-1))
2313  {
2314  size_t iLeft=l;
2315  size_t oLeft=enc.size();
2316  char *inputPtr = (char*)s;
2317  char *outputPtr = enc.data();
2318  if (!portable_iconv(cd, &inputPtr, &iLeft, &outputPtr, &oLeft))
2319  {
2320  enc.resize(enc.size()-(unsigned int)oLeft);
2321  converted=TRUE;
2322  }
2324  }
2325  }
2326  if (!converted) // if we did not convert anything, copy as is.
2327  {
2328  memcpy(enc.data(),s,l);
2329  enc.resize(l);
2330  }
2331  uint i;
2332  bool multiByte = FALSE;
2333 
2334  for (i=0;i<enc.size();i++)
2335  {
2336  uchar c = (uchar)enc.at(i);
2337 
2338  if (c>=0x80 || multiByte)
2339  {
2340  char esc[10];
2341  sprintf(esc,"\\'%X",c); // escape sequence for SBCS and DBCS(1st&2nd bytes).
2342  t << esc;
2343 
2344  if (!multiByte)
2345  {
2346  multiByte = isLeadBytes(c); // It may be DBCS Codepages.
2347  }
2348  else
2349  {
2350  multiByte = FALSE; // end of Double Bytes Character.
2351  }
2352  }
2353  else
2354  {
2355  t << (char)c;
2356  }
2357  }
2358 }
bool isLeadBytes(int c)
Definition: rtfgen.cpp:2267
bool isEmpty() const
Definition: qcstring.h:189
bool resize(uint size)
Definition: qarray.h:69
size_t portable_iconv(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition: portable_c.c:24
const bool FALSE
Definition: qglobal.h:370
static QStrList * l
Definition: config.cpp:1044
unsigned char uchar
Definition: nybbler.cc:11
int portable_iconv_close(void *cd)
Definition: portable_c.c:30
type * data() const
Definition: qarray.h:63
Q_EXPORT uint qstrlen(const char *str)
Definition: qcstring.h:81
const char * data() const
Definition: qcstring.h:207
void * portable_iconv_open(const char *tocode, const char *fromcode)
Definition: portable_c.c:19
virtual QCString trRTFansicp()=0
QCString & sprintf(const char *format,...)
Definition: qcstring.cpp:27
static QCString encoding
Definition: config.cpp:1052
Translator * theTranslator
Definition: language.cpp:157
type & at(uint i) const
Definition: qarray.h:98
uint size() const
Definition: qarray.h:65
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
const bool TRUE
Definition: qglobal.h:371
bool isLeadBytes ( int  c)

Definition at line 2267 of file rtfgen.cpp.

2268 {
2269  bool result;
2270 
2271  QCString codePage = theTranslator->trRTFansicp();
2272 
2273  if (codePage == "932") // cp932 (Japanese Shift-JIS)
2274  {
2275  result = (0x81<=c && c<=0x9f) || (0xe0<=c && c<=0xfc);
2276  }
2277  else if (codePage == "936") // cp936 (Simplified Chinese GBK)
2278  {
2279  result = 0x81<=c && c<=0xFE;
2280  }
2281  else if (codePage == "949") // cp949 (Korean)
2282  {
2283  result = 0x81<=c && c<=0xFE;
2284  }
2285  else if (codePage == "950") // cp950 (Traditional Chinese Big5)
2286  {
2287  result = 0x81<=c && c<=0xFE;
2288  }
2289  else // for SBCS Codepages (cp1252,1251 etc...)
2290  {
2291  result = false;
2292  }
2293 
2294  return result;
2295 }
static QCString result
virtual QCString trRTFansicp()=0
Translator * theTranslator
Definition: language.cpp:157
static QCString makeIndexName ( const char *  s,
int  i 
)
static

Definition at line 205 of file rtfgen.cpp.

206 {
207  QCString result=s;
208  result+=(char)(i+'0');
209  return result;
210 }
static QCString result
static QCString * s
Definition: config.cpp:1042
static bool preProcessFile ( QDir d,
QCString infName,
FTextStream t,
bool  bIncludeHeader = TRUE 
)
static

VERY brittle routine inline RTF's included by other RTF's. it is recursive and ugly.

Definition at line 2364 of file rtfgen.cpp.

2365 {
2366  QFile f(infName);
2367  if (!f.open(IO_ReadOnly))
2368  {
2369  err("problems opening rtf file %s for reading\n",infName.data());
2370  return FALSE;
2371  }
2372 
2373  const int maxLineLength = 10240;
2374  static QCString lineBuf(maxLineLength);
2375 
2376  // scan until find end of header
2377  // this is EXTREEEEEEEMLY brittle. It works on OUR rtf
2378  // files because the first line before the body
2379  // ALWAYS contains "{\comment begin body}"
2380  int len;
2381  for(;;)
2382  {
2383  lineBuf.resize(maxLineLength);
2384  if ((len=f.readLine(lineBuf.rawData(),maxLineLength))==-1)
2385  {
2386  err("read error in %s before end of RTF header!\n",infName.data());
2387  return FALSE;
2388  }
2389  lineBuf.resize(len+1);
2390  if (lineBuf.find("\\comment begin body")!=-1) break;
2391  if (bIncludeHeader) encodeForOutput(t,lineBuf.data());
2392  }
2393 
2394 
2395  lineBuf.resize(maxLineLength);
2396  while ((len=f.readLine(lineBuf.rawData(),maxLineLength))!=-1)
2397  {
2398  lineBuf.resize(len+1);
2399  int pos;
2400  if ((pos=lineBuf.find("INCLUDETEXT"))!=-1)
2401  {
2402  int startNamePos = lineBuf.find('"',pos)+1;
2403  int endNamePos = lineBuf.find('"',startNamePos);
2404  QCString fileName = lineBuf.mid(startNamePos,endNamePos-startNamePos);
2405  DBG_RTF(t << "{\\comment begin include " << fileName << "}" << endl)
2406  if (!preProcessFile(d,fileName,t,FALSE)) return FALSE;
2407  DBG_RTF(t << "{\\comment end include " << fileName << "}" << endl)
2408  }
2409  else // no INCLUDETEXT on this line
2410  {
2411  // elaborate hoopla to skip the final "}" if we didn't include the
2412  // headers
2413  if (!f.atEnd() || bIncludeHeader)
2414  {
2415  encodeForOutput(t,lineBuf);
2416  }
2417  else // last line of included file
2418  {
2419  // null terminate at the last '}'
2420  //char *str = strrchr(buffer,'}');
2421  int pos = lineBuf.findRev('}');
2422 
2423  if (pos != -1)
2424  lineBuf.at(pos) = '\0';
2425  else
2426  err("Strange, the last char was not a '}'\n");
2427  encodeForOutput(t,lineBuf);
2428  }
2429  }
2430  lineBuf.resize(maxLineLength);
2431  }
2432  f.close();
2433  // remove temporary file
2434  d.remove(infName);
2435  return TRUE;
2436 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
#define DBG_RTF(x)
Definition: rtfgen.cpp:48
const bool FALSE
Definition: qglobal.h:370
int comment
#define IO_ReadOnly
Definition: qiodevice.h:61
static void encodeForOutput(FTextStream &t, const char *s)
Definition: rtfgen.cpp:2299
fileName
Definition: dumpTree.py:9
std::void_t< T > n
const double a
const char * data() const
Definition: qcstring.h:207
void include(std::istream &in, std::string &result)
Definition: include.cc:63
void err(const char *fmt,...)
Definition: message.cpp:226
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
static bool preProcessFile(QDir &d, QCString &infName, FTextStream &t, bool bIncludeHeader=TRUE)
Definition: rtfgen.cpp:2364
if(!yymsg) yymsg
QTextStream & endl(QTextStream &s)
void testRTFOutput ( const char *  name)

Tests the integrity of the result by counting brackets.

Definition at line 2542 of file rtfgen.cpp.

2543 {
2544  int bcount=0;
2545  int line=1;
2546  int c;
2547  QFile f(name);
2548  if (f.open(IO_ReadOnly))
2549  {
2550  while ((c=f.getch())!=-1)
2551  {
2552  if (c=='\\') // escape char
2553  {
2554  c=f.getch();
2555  if (c==-1) break;
2556  }
2557  else if (c=='{') // open bracket
2558  {
2559  bcount++;
2560  }
2561  else if (c=='}') // close bracket
2562  {
2563  bcount--;
2564  if (bcount<0)
2565  {
2566  goto err;
2567  break;
2568  }
2569  }
2570  else if (c=='\n') // newline
2571  {
2572  line++;
2573  }
2574  }
2575  }
2576  if (bcount==0) return; // file is OK.
2577 err:
2578  err("RTF integrity test failed at line %d of %s due to a bracket mismatch.\n"
2579  " Please try to create a small code example that produces this error \n"
2580  " and send that to dimitri@stack.nl.\n",line,name);
2581 }
static QCString name
Definition: declinfo.cpp:673
#define IO_ReadOnly
Definition: qiodevice.h:61
void err(const char *fmt,...)
Definition: message.cpp:226
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
void line(double t, double *p, double &x, double &y, double &z)