File: cs.c

package info (click to toggle)
clearsilver 0.10.5-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,304 kB
  • sloc: ansic: 24,586; python: 4,233; sh: 2,502; cs: 1,429; ruby: 819; java: 735; makefile: 589; perl: 120; lisp: 34; sql: 21
file content (106 lines) | stat: -rw-r--r-- 2,096 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright 2001-2004 Brandon Long
 * All Rights Reserved.
 *
 * ClearSilver Templating System
 *
 * This code is made available under the terms of the ClearSilver License.
 * http://www.clearsilver.net/license.hdf
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "cs.h"
#include "util/neo_misc.h"
#include "util/neo_hdf.h"

static NEOERR *output (void *ctx, char *s)
{
  printf ("%s", s);
  return STATUS_OK;
}

int main (int argc, char *argv[])
{
  NEOERR *err;
  CSPARSE *parse;
  HDF *hdf;
  int verbose = 0;
  char *hdf_file, *cs_file;
  char c;

  extern char *optarg;

  err = hdf_init(&hdf);
  if (err != STATUS_OK)
  {
    nerr_log_error(err);
    return -1;
  }

  err = cs_init (&parse, hdf);
  if (err != STATUS_OK) {
    nerr_log_error(err);
    return -1;
  }

  while ((c = getopt(argc, argv, "Hvh:c:")) != EOF )

    switch (c) {
    case 'h':
      hdf_file=optarg;
      err = hdf_read_file(hdf, hdf_file);
      if (err != STATUS_OK) {
	nerr_log_error(err);
	return -1;
      }
      break;
    case 'c':
      cs_file=optarg;
      if ( verbose )
	printf ("Parsing %s\n", cs_file);

      err = cs_parse_file (parse, cs_file);
      if (err != STATUS_OK) {
	err = nerr_pass(err);
	nerr_log_error(err);
	return -1;
      }
      break;
    case 'v':
      verbose=1;
      break;
    case 'H':
      fprintf(stderr, "Usage: %s [-v] [-h <file.hdf>] [-c <file.cs>]\n", argv[0]);
      fprintf(stderr, "     -h <file.hdf> load hdf file file.hdf (multiple allowed)\n");
      fprintf(stderr, "     -c <file.cs>  load cs file file.cs (multiple allowed)\n");
      fprintf(stderr, "     -v            verbose output\n");
      return -1;
      break;
    }


  err = cs_render(parse, NULL, output);
  if (err != STATUS_OK) {
    err = nerr_pass(err);
    nerr_log_error(err);
    return -1;
  }

  if (verbose) {
    printf ("\n-----------------------\nCS DUMP\n");
    err = cs_dump(parse, NULL, output);
  }

  cs_destroy (&parse);

  if (verbose) {
    printf ("\n-----------------------\nHDF DUMP\n");
    hdf_dump (hdf, NULL);
  }

  return 0;
}