1 /*
2 * Copyright 2001-2004 Brandon Long
3 * All Rights Reserved.
4 *
5 * ClearSilver Templating System
6 *
7 * This code is made available under the terms of the ClearSilver License.
8 * http://www.clearsilver.net/license.hdf
9 *
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15
16 #include "cs.h"
17 #include "util/neo_misc.h"
18 #include "util/neo_hdf.h"
19
output(void * ctx,char * s)20 static NEOERR *output (void *ctx, char *s)
21 {
22 printf ("%s", s);
23 return STATUS_OK;
24 }
25
main(int argc,char * argv[])26 int main (int argc, char *argv[])
27 {
28 NEOERR *err;
29 CSPARSE *parse;
30 HDF *hdf;
31 int verbose = 0;
32 char *hdf_file, *cs_file;
33 char c;
34
35 extern char *optarg;
36
37 err = hdf_init(&hdf);
38 if (err != STATUS_OK)
39 {
40 nerr_log_error(err);
41 return -1;
42 }
43
44 err = cs_init (&parse, hdf);
45 if (err != STATUS_OK) {
46 nerr_log_error(err);
47 return -1;
48 }
49
50 while ((c = getopt(argc, argv, "Hvh:c:")) != EOF )
51
52 switch (c) {
53 case 'h':
54 hdf_file=optarg;
55 err = hdf_read_file(hdf, hdf_file);
56 if (err != STATUS_OK) {
57 nerr_log_error(err);
58 return -1;
59 }
60 break;
61 case 'c':
62 cs_file=optarg;
63 if ( verbose )
64 printf ("Parsing %s\n", cs_file);
65
66 err = cs_parse_file (parse, cs_file);
67 if (err != STATUS_OK) {
68 err = nerr_pass(err);
69 nerr_log_error(err);
70 return -1;
71 }
72 break;
73 case 'v':
74 verbose=1;
75 break;
76 case 'H':
77 fprintf(stderr, "Usage: %s [-v] [-h <file.hdf>] [-c <file.cs>]\n", argv[0]);
78 fprintf(stderr, " -h <file.hdf> load hdf file file.hdf (multiple allowed)\n");
79 fprintf(stderr, " -c <file.cs> load cs file file.cs (multiple allowed)\n");
80 fprintf(stderr, " -v verbose output\n");
81 return -1;
82 break;
83 }
84
85
86 err = cs_render(parse, NULL, output);
87 if (err != STATUS_OK) {
88 err = nerr_pass(err);
89 nerr_log_error(err);
90 return -1;
91 }
92
93 if (verbose) {
94 printf ("\n-----------------------\nCS DUMP\n");
95 err = cs_dump(parse, NULL, output);
96 }
97
98 cs_destroy (&parse);
99
100 if (verbose) {
101 printf ("\n-----------------------\nHDF DUMP\n");
102 hdf_dump (hdf, NULL);
103 }
104
105 return 0;
106 }
107