Orb/Doxygen/src/outputgen.cpp
changeset 0 42188c7ea2d9
child 4 468f4c8d3d5b
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /******************************************************************************
       
     2  *
       
     3  * 
       
     4  *
       
     5  * Copyright (C) 1997-2008 by Dimitri van Heesch.
       
     6  *
       
     7  * Permission to use, copy, modify, and distribute this software and its
       
     8  * documentation under the terms of the GNU General Public License is hereby 
       
     9  * granted. No representations are made about the suitability of this software 
       
    10  * for any purpose. It is provided "as is" without express or implied warranty.
       
    11  * See the GNU General Public License for more details.
       
    12  *
       
    13  * Documents produced by Doxygen are derivative works derived from the
       
    14  * input used in their production; they are not affected by this license.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <stdlib.h>
       
    19 
       
    20 #include "qtbc.h"
       
    21 #include "outputgen.h"
       
    22 #include "message.h"
       
    23 #include "portable.h"
       
    24 
       
    25 OutputGenerator::OutputGenerator()
       
    26 {
       
    27   //printf("OutputGenerator::OutputGenerator()\n");
       
    28   file=0;
       
    29   b.setBuffer(a);
       
    30   b.open( IO_WriteOnly );
       
    31   t.setDevice(&b);
       
    32   t.setEncoding(QTextStream::UnicodeUTF8);
       
    33   active=TRUE;
       
    34   genStack = new QStack<bool>;
       
    35   genStack->setAutoDelete(TRUE);
       
    36 }
       
    37 
       
    38 OutputGenerator::~OutputGenerator()
       
    39 {
       
    40   //printf("OutputGenerator::~OutputGenerator()\n");
       
    41   delete file;
       
    42   delete genStack;
       
    43 }
       
    44 
       
    45 void OutputGenerator::startPlainFile(const char *name)
       
    46 {
       
    47   //printf("startPlainFile(%s)\n",name);
       
    48   QCString fileName=dir+"/"+name;
       
    49   file = new QFile(fileName);
       
    50   if (!file)
       
    51   {
       
    52     err("Could not create file object for %s\n",fileName.data());
       
    53     exit(1);
       
    54   }
       
    55   if (!file->open(IO_WriteOnly))
       
    56   {
       
    57     err("Could not open file %s for writing\n",fileName.data());
       
    58     exit(1);
       
    59   }
       
    60   fs.setDevice(file);
       
    61 }
       
    62 
       
    63 void OutputGenerator::endPlainFile()
       
    64 {
       
    65   bool converted=false;
       
    66   if (!encoding.isEmpty())
       
    67   {
       
    68     QByteArray enc(a.size()*4);
       
    69     void *cd = portable_iconv_open(encoding,"UTF-8");
       
    70     if (cd!=(void *)(-1))
       
    71     {
       
    72       size_t iLeft=a.size();
       
    73       size_t oLeft=enc.size();
       
    74       const char *inputPtr = a.data();
       
    75       char *outputPtr = enc.data();
       
    76       if (!portable_iconv(cd, &inputPtr, &iLeft, &outputPtr, &oLeft))
       
    77       {
       
    78         enc.resize(enc.size()-oLeft);
       
    79         postProcess(enc);
       
    80         //printf("a.size()=%d enc.size()=%d iLeft=%d oLeft=%d enc2.size()=%d\n",
       
    81         //    a.size(),enc.size(),iLeft,oLeft,enc2.size());
       
    82         fs.writeRawBytes(enc.data(),enc.size()) ;  // write string buffer to file
       
    83         converted=TRUE;
       
    84       }
       
    85       portable_iconv_close(cd);
       
    86     }
       
    87   }
       
    88   if (!converted)
       
    89   {
       
    90     //printf("endPlainFile(%s)\n",file->name());
       
    91     fs.writeRawBytes(a.data(),a.size()) ;  // write string buffer to file
       
    92   }
       
    93   b.close();
       
    94   delete file; 
       
    95   file=0;
       
    96   a.resize(0);
       
    97   b.setBuffer(a);
       
    98   b.open(IO_WriteOnly);
       
    99   t.setDevice(&b);
       
   100 }
       
   101 
       
   102 QCString OutputGenerator::getContents() const
       
   103 {
       
   104   QCString s;
       
   105   s.resize(a.size()+1);
       
   106   memcpy(s.data(),a.data(),a.size());
       
   107   s.at(a.size())='\0';
       
   108   return s;
       
   109 }
       
   110 
       
   111 void OutputGenerator::pushGeneratorState()
       
   112 {
       
   113   genStack->push(new bool(isEnabled()));
       
   114 }
       
   115 
       
   116 void OutputGenerator::popGeneratorState()
       
   117 {
       
   118   bool *lb = genStack->pop();
       
   119   ASSERT(lb!=0);
       
   120   if (lb==0) return; // for some robustness against superfluous \endhtmlonly commands.
       
   121   if (*lb) enable(); else disable();
       
   122   delete lb;
       
   123 }
       
   124