• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Sample/test driver interface program for CUPS.
3  *
4  *   This program handles listing and installing both static PPD files
5  *   in CUPS_DATADIR/model and dynamically generated PPD files using
6  *   the driver helper programs in CUPS_SERVERBIN/driver.
7  *
8  *   Copyright 2007-2010 by Apple Inc.
9  *   Copyright 1997-2006 by Easy Software Products.
10  *
11  *   These coded instructions, statements, and computer programs are the
12  *   property of Apple Inc. and are protected by Federal copyright
13  *   law.  Distribution and use rights are outlined in the file "COPYING"
14  *   which should have been included with this file.
15  *
16  * Contents:
17  *
18  *   main()      - Enumerate or display PPD files.
19  *   cat_ppd()   - Display a PPD file.
20  *   list_ppds() - List PPDs.
21  */
22 
23 /*
24  * Include necessary headers...
25  */
26 
27 #include <cups/string-private.h>
28 #include <cups/cups.h>
29 
30 
31 /*
32  * Local functions...
33  */
34 
35 static int	cat_ppd(const char *uri);
36 static int	list_ppds(const char *name);
37 
38 
39 /*
40  * Sample data...
41  */
42 
43 static const char *models[][2] =
44 		{
45 		  { "foojet.ppd", "Foo Printer" },
46 		  { "barjet.ppd", "Bar Printer" },
47 		  { "foobar.ppd", "Foo/Bar Multifunction Printer" }
48 		};
49 
50 
51 /*
52  * 'main()' - Enumerate or display PPD files.
53  */
54 
55 int					/* O - Exit status */
main(int argc,char * argv[])56 main(int  argc,				/* I - Number of command-line args */
57      char *argv[])			/* I - Command-line arguments */
58 {
59   if (argc == 2 && !strcmp(argv[1], "list"))
60     return (list_ppds(argv[0]));
61   else if (argc == 3 && !strcmp(argv[1], "cat"))
62     return (cat_ppd(argv[2]));
63 
64   fprintf(stderr, "ERROR: Usage: %s cat URI\n", argv[0]);
65   fprintf(stderr, "ERROR: Usage: %s list\n", argv[0]);
66   return (1);
67 }
68 
69 
70 /*
71  * 'cat_ppd()' - Display a PPD file.
72  */
73 
74 static int				/* O - Exit status */
cat_ppd(const char * uri)75 cat_ppd(const char *uri)		/* I - PPD URI */
76 {
77   int		i;			/* Looping var */
78   char		scheme[255],		/* URI scheme */
79 		userpass[255],		/* Username/password (unused) */
80 		hostname[255],		/* Hostname (unused) */
81 		resource[1024];		/* Resource name */
82   int		port;			/* Port (unused) */
83   const char	*name;			/* Pointer to name in URI */
84 
85 
86   if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
87                       userpass, sizeof(userpass), hostname, sizeof(hostname),
88 		      &port, resource, sizeof(resource)) < HTTP_URI_OK)
89   {
90     fprintf(stderr, "ERROR: Bad URI \"%s\"!\n", uri);
91     return (1);
92   }
93 
94   name = resource + 1;
95 
96   for (i = 0 ; i < (int)(sizeof(models) / sizeof(models[0])); i ++)
97     if (!strcmp(name, models[i][0]))
98     {
99      /*
100       * Actually display the PPD file...
101       */
102       puts("*PPD-Adobe: \"4.3\"");
103 
104       puts("*LanguageEncoding: ISOLatin1");
105       puts("*LanguageVersion: English");
106       puts("*Manufacturer: \"Test\"");
107       puts("*FileVersion: \"1.0\"");
108       puts("*FormatVersion: \"4.3\"");
109       puts("*PSVersion: \"(3010) 1\"");
110       printf("*PCFileName: \"%s\"\n", models[i][0]);
111 
112       printf("*Product: \"(%s)\"\n", models[i][1]);
113       printf("*ModelName: \"Test %s\"\n", models[i][1]);
114       printf("*NickName: \"Test %s\"\n", models[i][1]);
115       printf("*ShortNickName: \"Test %s\"\n", models[i][1]);
116 
117       puts("*OpenUI PageSize: PickOne");
118       puts("*OrderDependency: 10 AnySetup *PageSetup");
119       puts("*DefaultPageSize: Letter");
120       puts("*PageSize Letter: \"<</PageSize[612 792]>>setpagedevice\"");
121       puts("*PageSize A4: \"<</PageSize[585 842]>>setpagedevice\"");
122       puts("*CloseUI: *PageSize");
123 
124       puts("*OpenUI PageRegion: PickOne");
125       puts("*OrderDependency: 10 AnySetup *PageRegion");
126       puts("*DefaultPageRegion: Letter");
127       puts("*PageRegion Letter: \"<</PageRegion[612 792]>>setpagedevice\"");
128       puts("*PageRegion A4: \"<</PageRegion[585 842]>>setpagedevice\"");
129       puts("*CloseUI: *PageRegion");
130 
131       puts("*DefaultImageableArea: Letter");
132       puts("*ImageableArea Letter: \"0 0 612 792\"");
133       puts("*ImageableArea A4: \"0 0 595 842\"");
134 
135       puts("*DefaultPaperDimension: Letter");
136       puts("*PaperDimension Letter: \"612 792\"");
137       puts("*PaperDimension A4: \"595 842\"");
138 
139       return (0);
140     }
141 
142   fprintf(stderr, "ERROR: Unknown URI \"%s\"!\n", uri);
143   return (1);
144 }
145 
146 
147 /*
148  * 'list_ppds()' - List PPDs.
149  */
150 
151 static int				/* O - Exit status */
list_ppds(const char * name)152 list_ppds(const char *name)		/* I - Program name */
153 {
154   int		i;			/* Looping var */
155   const char	*base;			/* Base name of program */
156 
157 
158   if ((base = strrchr(name, '/')) != NULL)
159     base ++;
160   else
161     base = name;
162 
163   for (i = 0; i < (int)(sizeof(models) / sizeof(models[0])); i ++)
164     printf("\"%s:///%s\" en \"Test\" \"Test %s\" \"1284 device id\"\n",
165            base, models[i][0], models[i][1]);
166 
167   return (0);
168 }
169 
170