1 /*  $Id$
2 
3     Part of SWI-Prolog
4 
5     Author:        Jan Wielemaker
6     E-mail:        jan@swi.psy.uva.nl
7     WWW:           http://www.swi-prolog.org
8     Copyright (C): 1985-2002, University of Amsterdam
9 
10     This library is free software; you can redistribute it and/or
11     modify it under the terms of the GNU Lesser General Public
12     License as published by the Free Software Foundation; either
13     version 2.1 of the License, or (at your option) any later version.
14 
15     This library is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18     Lesser General Public License for more details.
19 
20     You should have received a copy of the GNU Lesser General Public
21     License along with this library; if not, write to the Free Software
22     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <wchar.h>
29 #include "dtd.h"
30 #include "util.h"
31 #include "prolog.h"
32 
33 #define streq(s,q) strcmp((s), (q)) == 0
34 
35 char *program;
36 
37 static void
usage()38 usage()
39 { fprintf(stderr, "Usage: %s [-xml|sgml] file.dtd\n", program);
40 }
41 
42 int
main(int argc,char ** argv)43 main(int argc, char **argv)
44 { dtd_dialect dialect = DL_SGML;
45 
46   init_ring();
47 
48   program = argv[0];
49   argv++;
50   argc--;
51 
52   while(argc > 0 && argv[0][0] == '-')
53   { if ( streq(argv[0], "-xml") )
54     { dialect = DL_XML;
55       argc--;
56       argv++;
57     } else if ( streq(argv[0], "-sgml") )
58     { dialect = DL_SGML;
59       argc--;
60       argv++;
61     } else
62     { usage();
63       exit(1);
64     }
65   }
66 
67   if ( argc == 1 )
68   { int wl = mbstowcs(NULL, argv[0], 0);
69 
70     if ( wl > 0 )
71     { wchar_t *ws = malloc((wl+1)*sizeof(wchar_t));
72       dtd *dtd;
73 
74       mbstowcs(ws, argv[0], wl+1);
75       dtd = file_to_dtd(ws, L"test", dialect);
76 
77       if ( dtd )
78       { prolog_print_dtd(dtd, PL_PRINT_ALL & ~PL_PRINT_PENTITIES);
79 	return 0;
80       }
81     } else
82     { perror("mbstowcs");
83       exit(1);
84     }
85   }
86 
87   usage();
88   return 1;
89 }
90 
91 
92 
93 
94 
95