1 // Copyright (C) 2000-2007, Luca Padovani <padovani@sti.uniurb.it>.
2 //
3 // This file is part of GtkMathView, a flexible, high-quality rendering
4 // engine for MathML documents.
5 //
6 // GtkMathView is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GtkMathView is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 
19 #include <config.h>
20 
21 // needed for old versions of GCC, must come before String.hh!
22 #include "CharTraits.icc"
23 
24 #include <cassert>
25 #include <stdlib.h>
26 
27 #include <popt.h>
28 
29 #include "defs.h"
30 #include "guiGTK.h"
31 #include "String.hh"
32 #include "MathMLTokenElement.hh"
33 #ifdef DEBUG
34 #include "Gtk_GraphicsContext.hh"
35 #endif // DEBUG
36 #ifdef ENABLE_PROFILE
37 #endif // ENABLE_PROFILE
38 
39 enum CommandLineOptionId {
40   OPTION_VERSION = 256,
41   OPTION_VERBOSE
42 };
43 
44 // global options
45 bool entityWarning = false;
46 
47 static char appName[64];
48 
49 extern void *parseMathMLFile(char *);
50 
printVersion()51 static void printVersion()
52 {
53   printf("%s - written by Luca Padovani (C) 2000-2005.\n", appName);
54   exit(0);
55 }
56 
57 static gint logLevel = -1;
58 static struct poptOption optionsTable[] = {
59   { "version", 'V', POPT_ARG_NONE, 0, OPTION_VERSION, "Output version information", 0 },
60   { "verbose", 'v', POPT_ARG_INT, &logLevel, OPTION_VERBOSE, "Display messages", "[0-3]" },
61   POPT_AUTOHELP
62   { 0, 0, 0, 0, 0, 0, 0 }
63 };
64 
65 static void
usage(poptContext optCon,int exitcode,const char * msg)66 usage(poptContext optCon, int exitcode, const char* msg)
67 {
68   poptPrintUsage(optCon, stderr, 0);
69   if (msg) fprintf(stderr, "%s\n", msg);
70   exit(exitcode);
71 }
72 
73 int
main(int argc,const char * argv[])74 main(int argc, const char *argv[])
75 {
76   poptContext ctxt = poptGetContext(NULL, argc, argv, optionsTable, 0);
77   sprintf(appName, "mathmlviewer v%s", VERSION);
78 
79   gint c;
80   while ((c = poptGetNextOpt(ctxt)) >= 0)
81     {
82       switch (c) {
83       case OPTION_VERSION:
84 	printVersion();
85 	break;
86       case OPTION_VERBOSE:
87 	break;
88       default:
89 	assert(false);
90       }
91     }
92 
93   if (c < -1)
94     {
95       /* an error occurred during option processing */
96       fprintf(stderr, "%s: %s\n",
97 	      poptBadOption(ctxt, POPT_BADOPTION_NOALIAS),
98 	      poptStrerror(c));
99       return 1;
100     }
101 
102   const gchar* file = poptGetArg(ctxt);
103   if (file == 0 || !(poptPeekArg(ctxt) == 0))
104     usage(ctxt, 1, "fatal error: no input document");
105 
106   poptFreeContext(ctxt);
107 
108   GUI_init(&argc, &argv, appName, 500, 600, logLevel);
109   if (GUI_load_document(file) < 0)
110     printf("fatal error: cannot load document `%s'\n", file);
111   GUI_run();
112   GUI_uninit();
113   exit(0);
114 }
115