Fix for UBSan build
[platform/upstream/doxygen.git] / src / outputgen.cpp
1 /******************************************************************************
2  *
3  * $Id: outputgen.cpp,v 1.15 2001/03/19 19:27:41 root Exp $
4  *
5  * Copyright (C) 1997-2012 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   active=TRUE;
30   genStack = new QStack<bool>;
31   genStack->setAutoDelete(TRUE);
32 }
33
34 OutputGenerator::~OutputGenerator()
35 {
36   //printf("OutputGenerator::~OutputGenerator()\n");
37   delete file;
38   delete genStack;
39 }
40
41 void OutputGenerator::startPlainFile(const char *name)
42 {
43   //printf("startPlainFile(%s)\n",name);
44   fileName=dir+"/"+name;
45   file = new QFile(fileName);
46   if (!file)
47   {
48     err("Could not create file object for %s\n",fileName.data());
49     exit(1);
50   }
51   if (!file->open(IO_WriteOnly))
52   {
53     err("Could not open file %s for writing\n",fileName.data());
54     exit(1);
55   }
56   t.setDevice(file);
57 }
58
59 void OutputGenerator::endPlainFile()
60 {
61   t.unsetDevice();
62   delete file;
63   file=0;
64   fileName.resize(0);
65 }
66
67 void OutputGenerator::pushGeneratorState()
68 {
69   genStack->push(new bool(isEnabled()));
70   //printf("%p:pushGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
71 }
72
73 void OutputGenerator::popGeneratorState()
74 {
75   //printf("%p:popGeneratorState(%d) enabled=%d\n",this,genStack->count(),isEnabled());
76   bool *lb = genStack->pop();
77   ASSERT(lb!=0);
78   if (lb==0) return; // for some robustness against superfluous \endhtmlonly commands.
79   if (*lb) enable(); else disable();
80   delete lb;
81 }
82