outputgen.cpp 2.04 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2
/******************************************************************************
 *
3
 * 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5
 * Copyright (C) 1997-2013 by Dimitri van Heesch.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6 7 8 9 10 11 12
 *
 * 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.
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
13 14
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
15 16 17 18
 *
 */

#include <stdlib.h>
19

20 21
#include <qfile.h>

Dimitri van Heesch's avatar
Dimitri van Heesch committed
22 23
#include "outputgen.h"
#include "message.h"
24
#include "portable.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
25 26 27 28 29 30

OutputGenerator::OutputGenerator()
{
  //printf("OutputGenerator::OutputGenerator()\n");
  file=0;
  active=TRUE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
31 32
  genStack = new QStack<bool>;
  genStack->setAutoDelete(TRUE);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
33 34 35 36 37 38
}

OutputGenerator::~OutputGenerator()
{
  //printf("OutputGenerator::~OutputGenerator()\n");
  delete file;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
39
  delete genStack;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
40 41 42 43 44
}

void OutputGenerator::startPlainFile(const char *name)
{
  //printf("startPlainFile(%s)\n",name);
45
  fileName=dir+"/"+name;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
46 47 48 49 50 51 52 53 54 55 56
  file = new QFile(fileName);
  if (!file)
  {
    err("Could not create file object for %s\n",fileName.data());
    exit(1);
  }
  if (!file->open(IO_WriteOnly))
  {
    err("Could not open file %s for writing\n",fileName.data());
    exit(1);
  }
57
  t.setDevice(file);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
58 59 60 61
}

void OutputGenerator::endPlainFile()
{
62
  t.unsetDevice();
63
  delete file;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
64
  file=0;
65
  fileName.resize(0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
66 67
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
68 69 70
void OutputGenerator::pushGeneratorState()
{
  genStack->push(new bool(isEnabled()));
71
  //printf("%p:pushGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
72 73 74 75
}

void OutputGenerator::popGeneratorState()
{
76
  //printf("%p:popGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
77 78 79 80
  bool *lb = genStack->pop();
  ASSERT(lb!=0);
  if (lb==0) return; // for some robustness against superfluous \endhtmlonly commands.
  if (*lb) enable(); else disable();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
81
  delete lb;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
82
}
83