]>
Commit | Line | Data |
---|---|---|
bd7854cb | 1 | /* |
503b54c9 | 2 | * CGI template test program for CUPS. |
bd7854cb | 3 | * |
503b54c9 MS |
4 | * Copyright 2007-2011 by Apple Inc. |
5 | * Copyright 2006 by Easy Software Products. | |
bd7854cb | 6 | * |
503b54c9 MS |
7 | * These coded instructions, statements, and computer programs are the |
8 | * property of Apple Inc. and are protected by Federal copyright | |
9 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
10 | * which should have been included with this file. If this file is | |
57b7b66b | 11 | * missing or damaged, see the license at "http://www.cups.org/". |
bd7854cb | 12 | */ |
13 | ||
14 | /* | |
15 | * Include necessary headers... | |
16 | */ | |
17 | ||
18 | #include "cgi.h" | |
19 | ||
20 | ||
21 | /* | |
22 | * 'main()' - Test the template code. | |
23 | */ | |
24 | ||
25 | int /* O - Exit status */ | |
26 | main(int argc, /* I - Number of command-line arguments */ | |
27 | char *argv[]) /* I - Command-line arguments */ | |
28 | { | |
29 | int i; /* Looping var */ | |
30 | char *value; /* Value in name=value */ | |
31 | FILE *out; /* Where to send output */ | |
32 | ||
33 | ||
34 | /* | |
35 | * Don't buffer stdout or stderr so that the mixed output is sane... | |
36 | */ | |
37 | ||
38 | setbuf(stdout, NULL); | |
39 | setbuf(stderr, NULL); | |
40 | ||
41 | /* | |
42 | * Loop through the command-line, assigning variables for any args with | |
43 | * "name=value"... | |
44 | */ | |
45 | ||
46 | out = stdout; | |
47 | ||
48 | for (i = 1; i < argc; i ++) | |
49 | { | |
50 | if (!strcmp(argv[i], "-o")) | |
51 | { | |
52 | i ++; | |
53 | if (i < argc) | |
54 | { | |
55 | out = fopen(argv[i], "w"); | |
56 | if (!out) | |
57 | { | |
58 | perror(argv[i]); | |
59 | return (1); | |
60 | } | |
61 | } | |
62 | } | |
63 | else if (!strcmp(argv[i], "-e")) | |
64 | { | |
65 | i ++; | |
66 | ||
67 | if (i < argc) | |
68 | { | |
69 | if (!freopen(argv[i], "w", stderr)) | |
70 | { | |
71 | perror(argv[i]); | |
72 | return (1); | |
73 | } | |
74 | } | |
75 | } | |
76 | else if (!strcmp(argv[i], "-q")) | |
77 | freopen("/dev/null", "w", stderr); | |
78 | else if ((value = strchr(argv[i], '=')) != NULL) | |
79 | { | |
80 | *value++ = '\0'; | |
81 | cgiSetVariable(argv[i], value); | |
82 | } | |
83 | else | |
84 | cgiCopyTemplateFile(out, argv[i]); | |
85 | } | |
86 | ||
87 | /* | |
88 | * Return with no errors... | |
89 | */ | |
90 | ||
91 | return (0); | |
92 | } |