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 "ClearSilver.h"
13
14 #include <stdio.h>
15 #include <string.h>
16
output(void * ctx,char * s)17 static NEOERR *output (void *ctx, char *s)
18 {
19 printf ("%s", s);
20 return STATUS_OK;
21 }
22
main(int argc,char * argv[])23 int main (int argc, char *argv[])
24 {
25 NEOERR *err;
26 CSPARSE *parse;
27 HDF *hdf;
28 int verbose = 0;
29 char *hdf_file, *cs_file;
30
31 if (argc < 3)
32 {
33 ne_warn ("Usage: cstest [-v] <file.hdf> <file.cs>");
34 return -1;
35 }
36
37 if (!strcmp(argv[1], "-v"))
38 {
39 verbose = 1;
40 if (argc < 4)
41 {
42 ne_warn ("Usage: cstest [-v] <file.hdf> <file.cs>");
43 return -1;
44 }
45 hdf_file = argv[2];
46 cs_file = argv[3];
47 }
48 else
49 {
50 hdf_file = argv[1];
51 cs_file = argv[2];
52 }
53
54 err = hdf_init(&hdf);
55 if (err != STATUS_OK)
56 {
57 nerr_log_error(err);
58 return -1;
59 }
60 err = hdf_read_file(hdf, hdf_file);
61 if (err != STATUS_OK)
62 {
63 nerr_log_error(err);
64 return -1;
65 }
66
67 printf ("Parsing %s\n", cs_file);
68 err = cs_init (&parse, hdf);
69 if (err != STATUS_OK)
70 {
71 nerr_log_error(err);
72 return -1;
73 }
74 err = cgi_register_strfuncs(parse);
75 if (err != STATUS_OK)
76 {
77 nerr_log_error(err);
78 return -1;
79 }
80
81 err = cs_parse_file (parse, cs_file);
82 if (err != STATUS_OK)
83 {
84 err = nerr_pass(err);
85 nerr_log_error(err);
86 return -1;
87 }
88
89 err = cs_render(parse, NULL, output);
90 if (err != STATUS_OK)
91 {
92 err = nerr_pass(err);
93 nerr_log_error(err);
94 return -1;
95 }
96
97 if (verbose)
98 {
99 printf ("\n-----------------------\nCS DUMP\n");
100 err = cs_dump(parse, NULL, output);
101 }
102
103 cs_destroy (&parse);
104
105 if (verbose)
106 {
107 printf ("\n-----------------------\nHDF DUMP\n");
108 hdf_dump (hdf, NULL);
109 }
110 hdf_destroy(&hdf);
111
112
113 return 0;
114 }
115