1: /******************************************************************************
2: ezht - Copyright (C) 2004 Tradcrafts
3: This file is part of the ezht.
4:
5: ezht is free software; you can redistribute it and/or modify
6: it under the terms of the GNU General Public License as published by the
7: Free Software Foundation; either version 2 of the License, or (at your
8: option) any later version.
9:
10: ezht is distributed in the hope that it will be useful, but
11: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13: more details.
14:
15: You should have received a copy of the GNU General Public License along with
16: this program; see the file COPYING. If not, write to the Free Software
17: Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18: ******************************************************************************/
19:
20: #include <stdio.h>
21: #include <stdlib.h>
22: #include <ctype.h>
23: #include <errno.h>
24:
25:
26: #include <string>
27: #include <vector>
28: #include <list>
29:
30: #ifndef unix
31: #include <windows.h>
32: #endif
33:
34: #include "version.h"
35: #include "reader.h"
36: #include "error.h"
37: #include "stack.h"
38: #include "gen.h"
39: #include "vfile.h"
40:
41:
42: static void usage(const char *prognam)
43: {
44: fprintf(stderr,"Error - Incorrect argument(s).\n");
45: fprintf(stderr,"usage:\n");
46: fprintf(stderr,"%s srcfile\n",prognam);
47: fprintf(stderr,"%s srcfile [outfile]\n",prognam);
48:
49: #ifndef unix
50: MessageBox(NULL,"Incorrect argument(s)\nSee document for details.","Error",MB_OK);
51: #endif
52: }
53:
54: int main(int argc,char **argv)
55: {
56:
57: fprintf(stderr,"ezht version %s - Copyright (C) 2004 Tradcrafts.\n",VERSION);
58:
59: if( argc < 2 || argc > 3){
60: usage("ezht");
61: exit(-1);
62: }
63:
64: stack_init();
65:
66: const char *infile = argv[1];
67: const char *outfile = NULL;
68: if( argc > 2 )
69: outfile = argv[2];
70:
71: if( ! reader.open( infile ) ){
72: fprintf(stderr,"unable to read `%s': %s\n",infile,strerror(errno));
73: exit(-1);
74: }
75:
76: generate();
77: reader_tempfile_delete();
78:
79: if( argc == 2 )
80: vf_flushall();
81: else if( argv[2] == (std::string)"STDOUT" )
82: vf_flushall_to(stdout);
83: else{
84: FILE *out = fopen(argv[2],"w");
85: if( ! out ){
86: fprintf(stderr,"unable to write `%s': %s\n",argv[2],strerror(errno));
87: }else{
88: vf_flushall_to(out);
89: fclose(out);
90: }
91: }
92:
93: return 0; // Exit normally
94: }