• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * CGI template test program for CUPS.
3  *
4  * Copyright © 2020-2024 by OpenPrinting.
5  * Copyright © 2007-2011 by Apple Inc.
6  * Copyright © 2006 by Easy Software Products.
7  *
8  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
9  * information.
10  */
11 
12 /*
13  * Include necessary headers...
14  */
15 
16 #include "cgi.h"
17 
18 
19 /*
20  * 'main()' - Test the template code.
21  */
22 
23 int					/* O - Exit status */
main(int argc,char * argv[])24 main(int  argc,				/* I - Number of command-line arguments */
25      char *argv[])			/* I - Command-line arguments */
26 {
27   int	i;				/* Looping var */
28   char	*value;				/* Value in name=value */
29   FILE	*out;				/* Where to send output */
30 
31 
32  /*
33   * Don't buffer stdout or stderr so that the mixed output is sane...
34   */
35 
36   setbuf(stdout, NULL);
37   setbuf(stderr, NULL);
38 
39  /*
40   * Loop through the command-line, assigning variables for any args with
41   * "name=value"...
42   */
43 
44   out = stdout;
45 
46   for (i = 1; i < argc; i ++)
47   {
48     if (!strcmp(argv[i], "-o"))
49     {
50       i ++;
51       if (i < argc)
52       {
53         out = fopen(argv[i], "w");
54 	if (!out)
55 	{
56 	  perror(argv[i]);
57 	  return (1);
58 	}
59       }
60     }
61     else if (!strcmp(argv[i], "-e"))
62     {
63       i ++;
64 
65       if (i < argc)
66       {
67         if (!freopen(argv[i], "w", stderr))
68 	{
69 	  perror(argv[i]);
70 	  return (1);
71 	}
72       }
73     }
74     else if (!strcmp(argv[i], "-q"))
75       freopen("/dev/null", "w", stderr);
76     else if ((value = strchr(argv[i], '=')) != NULL)
77     {
78       *value++ = '\0';
79       cgiSetVariable(argv[i], value);
80     }
81     else
82       cgiCopyTemplateFile(out, argv[i]);
83   }
84 
85  /*
86   * Return with no errors...
87   */
88 
89   return (0);
90 }
91