Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / infolib / etc / NodeParser.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: NodeParser.C /main/6 1996/08/21 15:47:06 drk $ */
24
25 #include <stdio.h>
26
27 #include "dti_cc/CC_Stack.h"
28 #include "Exceptions.hh"
29 #include "DataBase.h"
30
31 #include "Dispatch.h"
32 #include "SearchPath.h"
33
34 #include "Task.h"
35 #include "BookTasks.h"
36 #include "OLAF.h"
37
38 #ifdef FISH_DEBUG
39 #include "dbug.h" /* Fred Fish's dbug.h */
40 #endif
41 #include "Handler.h"
42
43 //---------------------------------------------------------------------
44 int main(int argc, char **argv)
45 {
46   INIT_EXCEPTIONS();
47
48   /* can't seem to get C++ initialization stuff to do this... */
49   OLAF::init();
50
51   set_new_handler( FreeStoreException );
52
53   int ret = 1;
54   
55 #ifdef FISH_DEBUG
56   DBUG_PROCESS(argv[0]);
57   if(getenv("FISH_DBUG")) DBUG_PUSH(getenv("FISH_DBUG"));
58 #endif
59
60   if(argc == 4){
61
62     const char *toc_option = argv[1];
63     const char *infolib = argv[2];
64     const char *srcdir  = argv[3];
65     
66
67     Dispatch::tmpdir = infolib;
68     Dispatch::srcdir = srcdir;
69
70     if ( !strcmp(toc_option, "toc") ) {
71       Dispatch::tocgen_only = 1;
72     }
73     else if ( !strcmp(toc_option, "all") ) {
74       Dispatch::tocgen_only = 0;
75     }
76     else { 
77       fprintf(stderr, "usage: NodeParse [ tocgen_only | all ] <database-dir> <source-dir>\n");
78
79       exit(1);
80     }
81
82       
83     
84     /*
85      * Add the . directory as a default if the file is not found in scrdir
86      */
87
88     SearchPath *sptable = new SearchPath( srcdir, ".", 0 );
89     Dispatch::search_path_table = sptable;
90
91     Task *t = new BookCaseTask( infolib );
92     Stack<int> *istack = new Stack<int>;
93
94     Dispatch::setRoot(t, istack);
95
96     try{
97       extern int yylex();
98       
99       yylex();
100
101       ret = 0;
102     }
103     catch(Unexpected&, u)
104       {
105         try {
106           Dispatch::tok->reportError(Token::User, Token::Fatal,
107                                      "markup error: %s", u.msg());
108         }
109         catch(ErrorReported&, e)
110           {
111             if ( e.f_severity == Token::Fatal ) {
112               exit(1);
113             }
114           }end_try;
115       }
116     catch(PosixError&, pe)
117       {
118         fprintf(stderr, "(ERROR) %s\n", pe.msg() );
119         exit(1);
120       }
121     catch(ErrorReported&, e)
122       {
123         if ( e.f_severity == Token::Fatal ) {
124           exit(1);
125         }
126       }end_try;
127
128   }else{
129     fprintf(stderr, "usage: NodeParse [ tocgen_only | all ] <database-dir> <source-dir>\n");
130   }
131
132   return ret;
133 }