Add multi-user support
[apps/core/preloaded/print-service.git] / TC / ppd_compare.c
1 /*
2 *       Printservice
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://floralicense.org/license/
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stddef.h>
23 #include <string.h>
24 #include <cups/ppd.h>
25
26 typedef struct _cups_array_s cups_array_t;
27
28 static void print_ppd_stucture(ppd_file_t *ppdfile)
29 {
30         int index =0;
31
32         fprintf(stderr,"[%20s] %d\n","language_level", ppdfile->language_level);
33         fprintf(stderr,"[%20s] %d\n","color_device", ppdfile->color_device);
34         fprintf(stderr,"[%20s] %d\n","variable_sizes", ppdfile->variable_sizes);
35         fprintf(stderr,"[%20s] %d\n","accurate_screens", ppdfile->accurate_screens);
36         fprintf(stderr,"[%20s] %d\n","contone_only", ppdfile->contone_only);
37         fprintf(stderr,"[%20s] %d\n","landscape", ppdfile->landscape);
38         fprintf(stderr,"[%20s] %d\n","model_number", ppdfile->model_number);
39         fprintf(stderr,"[%20s] %d\n","manual_copies", ppdfile->manual_copies);
40         fprintf(stderr,"[%20s] %d\n","throughput", ppdfile->throughput);
41         fprintf(stderr,"[%20s] %d\n","colorspace", ppdfile->colorspace);
42
43         if (ppdfile->patches != NULL) {
44                 fprintf(stderr,"[%20s] %s\n","patches", ppdfile->patches);
45         }
46
47         fprintf(stderr,"[%20s] %d\n","num_emulations", ppdfile->num_emulations);
48
49         if (ppdfile->emulations != NULL) {
50                 fprintf(stderr,"[%20s] %s\n","emulations", ppdfile->emulations->name);
51         }
52
53         if (ppdfile->jcl_begin != NULL) {
54                 fprintf(stderr,"[%20s] %s\n","jcl_begin", ppdfile->jcl_begin);
55         }
56
57         if (ppdfile->jcl_ps != NULL) {
58                 fprintf(stderr,"[%20s] %s\n","jcl_ps", ppdfile->jcl_ps);
59         }
60
61         if (ppdfile->jcl_end != NULL) {
62                 fprintf(stderr,"[%20s] %s\n","jcl_end", ppdfile->jcl_end);
63         }
64
65         if (ppdfile->lang_encoding != NULL) {
66                 fprintf(stderr,"[%20s] %s\n","lang_encoding", ppdfile->lang_encoding);
67         }
68
69         if (ppdfile->lang_version != NULL) {
70                 fprintf(stderr,"[%20s] %s\n","lang_version", ppdfile->lang_version);
71         }
72
73         if (ppdfile->modelname != NULL) {
74                 fprintf(stderr,"[%20s] %s\n","modelname", ppdfile->modelname);
75         }
76
77         if (ppdfile->ttrasterizer != NULL) {
78                 fprintf(stderr,"[%20s] %s\n","ttrasterizer", ppdfile->ttrasterizer);
79         }
80
81         if (ppdfile->manufacturer != NULL) {
82                 fprintf(stderr,"[%20s] %s\n","manufacturer", ppdfile->manufacturer);
83         }
84
85         if (ppdfile->product != NULL) {
86                 fprintf(stderr,"[%20s] %s\n","product", ppdfile->product);
87         }
88
89         if (ppdfile->nickname != NULL) {
90                 fprintf(stderr,"[%20s] %s\n","nickname", ppdfile->nickname);
91         }
92
93         if (ppdfile->shortnickname != NULL) {
94                 fprintf(stderr,"[%20s] %s\n","shortnickname", ppdfile->shortnickname);
95         }
96
97         fprintf(stderr,"[%20s] %d\n","num_groups", ppdfile->num_groups);
98
99         if (ppdfile->groups != NULL) {
100                 fprintf(stderr,"[%20s] %s\n","groups", ppdfile->groups->text);
101                 fprintf(stderr,"[%20s] %s\n","groups", ppdfile->groups->name);
102         }
103
104         fprintf(stderr,"[%20s] %d\n","num_sizes", ppdfile->num_sizes);
105
106         if (ppdfile->sizes != NULL) {
107                 fprintf(stderr,"[%20s] %s\n","sizes", ppdfile->sizes->name);
108         }
109
110         fprintf(stderr,"[%20s] %f %f\n","custom_min", ppdfile->custom_min[0], ppdfile->custom_min[0]);
111         fprintf(stderr,"[%20s] %f %f\n","custom_max", ppdfile->custom_max[0], ppdfile->custom_max[1]);
112         fprintf(stderr,"[%20s] %f %f %f %f\n","custom_margins" \
113                         , ppdfile->custom_margins[0], ppdfile->custom_margins[1] \
114                         , ppdfile->custom_margins[2], ppdfile->custom_margins[3]);
115         fprintf(stderr,"[%20s] %d\n","num_consts", ppdfile->num_consts);
116
117         if (ppdfile->consts != NULL) {
118                 fprintf(stderr,"[%20s] %s\n","consts", ppdfile->consts->choice1);
119                 fprintf(stderr,"[%20s] %s\n","consts", ppdfile->consts->choice2);
120                 fprintf(stderr,"[%20s] %s\n","consts", ppdfile->consts->option1);
121                 fprintf(stderr,"[%20s] %s\n","consts", ppdfile->consts->option2);
122         }
123
124         fprintf(stderr,"[%20s] %d\n","num_fonts", ppdfile->num_fonts);
125
126         for (index = 0; index < ppdfile->num_fonts; index++) {
127                 if (ppdfile->fonts[index] != NULL) {
128                         fprintf(stderr,"[%20s] %s\n","fonts", ppdfile->fonts[index]);
129                 }
130         }
131
132         fprintf(stderr,"[%20s] %d\n","num_profiles", ppdfile->num_profiles);
133
134         if (ppdfile->profiles != NULL) {
135                 fprintf(stderr,"[%20s] %s\n","profiles", ppdfile->profiles->media_type);
136         }
137
138         fprintf(stderr,"[%20s] %d\n","num_filters", ppdfile->num_filters);
139
140         for (index = 0; index < ppdfile->num_filters; index++) {
141                 if (ppdfile->filters[index] != NULL) {
142                         fprintf(stderr,"[%20s] %s\n","filters", ppdfile->filters[index]);
143                 }
144         }
145
146         fprintf(stderr,"[%20s] %d\n","flip_duplex", ppdfile->flip_duplex);
147
148         if (ppdfile->protocols != NULL) {
149                 fprintf(stderr,"[%20s] %s\n","protocols", ppdfile->protocols);
150         }
151
152         if (ppdfile->pcfilename != NULL) {
153                 fprintf(stderr,"[%20s] %s\n","pcfilename", ppdfile->pcfilename);
154         }
155
156         fprintf(stderr,"[%20s] %d\n","num_attrs", ppdfile->num_attrs);
157         fprintf(stderr,"[%20s] %d\n","cur_attr", ppdfile->cur_attr);
158
159         if (ppdfile->attrs != NULL) {
160                 for (index = 0; index < ppdfile->num_attrs; index++) {
161                         fprintf(stderr,"[%20s] %s\n","attrs_name", ppdfile->attrs[index]->name);
162                         fprintf(stderr,"[%20s] %s\n","attrs_spec", ppdfile->attrs[index]->spec);
163                         fprintf(stderr,"[%20s] %s\n","attrs_text", ppdfile->attrs[index]->text);
164                         fprintf(stderr,"[%20s] %s\n","attrs_value", ppdfile->attrs[index]->value);
165                 }
166         }
167
168         if (ppdfile->sorted_attrs != NULL) {
169                 fprintf(stderr,"[%20s] %d\n","sortedattrs_num", cupsArrayCount(ppdfile->sorted_attrs));
170                 for (index = 0; index < cupsArrayCount(ppdfile->sorted_attrs); index++) {
171                         if (cupsArrayIndex(ppdfile->sorted_attrs, index) != NULL) {
172                                 fprintf(stderr,"[%20s] %s\n","sortedattrs_name",        ((ppd_attr_t *)(cupsArrayIndex(ppdfile->sorted_attrs, index)))->name);
173                         }
174                 }
175         }
176
177         if (ppdfile->options != NULL) {
178                 fprintf(stderr,"[%20s] %d\n","options_num", cupsArrayCount(ppdfile->options));
179                 for (index = 0; index < cupsArrayCount(ppdfile->options); index++) {
180                         fprintf(stderr,"[%20s] %s\n","options_keyword", ((ppd_option_t *)(cupsArrayIndex(ppdfile->options, index)))->keyword);
181                 }
182         }
183
184         if (ppdfile->coptions != NULL) {
185                 fprintf(stderr,"[%20s] %d\n","coptions_num", cupsArrayCount(ppdfile->coptions));
186                 for (index = 0; index < cupsArrayCount(ppdfile->coptions); index++) {
187                         fprintf(stderr,"[%20s] %s\n","coptions_keyword", ((ppd_option_t *)(cupsArrayIndex(ppdfile->coptions, index)))->keyword);
188                 }
189         }
190
191         if (ppdfile->marked != NULL) {
192                 fprintf(stderr,"[%20s] %d\n","marked_num", cupsArrayCount(ppdfile->marked));
193                 for (index = 0; index < cupsArrayCount(ppdfile->marked); index++) {
194                         fprintf(stderr,"[%20s] %s\n","marked_keyword", ((ppd_choice_t *)(cupsArrayIndex(ppdfile->marked, index)))->choice);
195                 }
196         }
197
198         if (ppdfile->cups_uiconstraints != NULL) {
199                 fprintf(stderr,"[%20s] %d\n","cups_uiconstraints_num", cupsArrayCount(ppdfile->cups_uiconstraints));
200                 for (index = 0; index < cupsArrayCount(ppdfile->cups_uiconstraints); index++) {
201                         fprintf(stderr,"[%20s] %s\n","cups_uiconstraints_choice", ((ppd_choice_t *)(cupsArrayIndex(ppdfile->cups_uiconstraints, index)))->choice);
202                 }
203         }
204
205 }
206
207 /*
208 "*Keyword: Value" Type(single)
209 */
210 static void print_attribute_kvs(ppd_file_t *ppdfile, const char *option)
211 {
212         ppd_attr_t *attr = NULL;
213
214         for (attr = ppdFindAttr(ppdfile, option, NULL); attr != NULL;
215                         attr = ppdFindNextAttr(ppdfile, option, NULL)) {
216
217                 if (attr != NULL) {
218                         printf("%s\n",attr->value);
219                 }
220         }
221 }
222
223 /*
224 "*Keyword: Value" Type(multiple)
225 */
226 static void print_attribute_kvm(ppd_file_t *ppdfile, const char *option)
227 {
228         ppd_attr_t *attr = NULL;
229
230         for (attr = ppdFindAttr(ppdfile, option, NULL); attr != NULL;
231                         attr = ppdFindNextAttr(ppdfile, option, NULL)) {
232
233                 if (attr != NULL) {
234                         printf("[Name]%s [Spec]%s [Text]%s [Value]%s\n"
235                                    ,attr->name
236                                    ,attr->spec
237                                    ,attr->text
238                                    ,attr->value);
239                 }
240         }
241 }
242
243 /*
244 "*Keyword Value/Value: Value" Type
245 */
246 static void print_attribute_kvvm(ppd_file_t *ppdfile, const char *option)
247 {
248         ppd_option_t *attr = NULL;
249         int index = 0;
250
251         attr = ppdFindOption(ppdfile, option);
252
253         if (attr != NULL) {
254                 for (index = 0 ; index < attr->num_choices ; index++) {
255                         printf("[Keyword]%s",attr->keyword);
256                         printf(" [Choice]%s",attr->choices->choice);
257                         printf(" [Code]%s",attr->choices->code);
258                         printf(" [Text]%s\n",attr->choices->text);
259                 }
260         }
261
262 }
263
264 static void print_options(ppd_file_t *ppdfile)
265 {
266         int index = 0;
267
268         if (ppdfile->options != NULL) {
269                 for (index = 0; index < cupsArrayCount(ppdfile->options); index++) {
270                         printf("%s\n", ((ppd_option_t *)(cupsArrayIndex(ppdfile->options, index)))->keyword);
271                 }
272         }
273
274         if (ppdfile->coptions != NULL) {
275                 for (index = 0; index < cupsArrayCount(ppdfile->coptions); index++) {
276                         printf("%s\n", ((ppd_option_t *)(cupsArrayIndex(ppdfile->coptions, index)))->keyword);
277                 }
278         }
279
280 }
281
282 static void print_option_choices(ppd_file_t *ppdfile, const char *keyword, const char *ch)
283 {
284         ppd_option_t *opt = NULL;
285         ppd_choice_t *choice = NULL;
286
287         opt = ppdFindOption(ppdfile, keyword);
288         if (opt == NULL) {
289                 return;
290         }
291
292         choice = ppdFindChoice(opt, ch);
293         if (choice == NULL) {
294                 return;
295         }
296
297         printf("[Choice]%s",choice->choice);
298         printf(" [Code]%s",choice->code);
299         printf(" [Text]%s\n",choice->text);
300
301 }
302
303 int main(int argc, char *argv[])
304 {
305         ppd_file_t *ppd_source = NULL;
306
307         if (argc == 5) {
308                 ppd_source = ppdOpenFile(argv[4]);
309         } else if (argc ==4) {
310                 ppd_source = ppdOpenFile(argv[3]);
311         } else if (argc == 3) {
312                 ppd_source = ppdOpenFile(argv[2]);
313         } else {
314                 fprintf(stderr, "Usage : %s [Type] [Option] [original_ppd_file]\n", argv[0]);
315                 fprintf(stderr, "Usage : %s CHOICE [Option] [Choice] [original_ppd_file]\n", argv[0]);
316                 fprintf(stderr, "Usage : %s PPD [original_ppd_file]\n", argv[0]);
317                 fprintf(stderr, "Usage : %s OPT [original_ppd_file]\n", argv[0]);
318                 fprintf(stderr, "Type(KVS) : *Keyword: Value(Single)\n");
319                 fprintf(stderr, "Type(KVM) : *Keyword: Value(Multiple)\n");
320                 fprintf(stderr, "Type(KVVM) : *Keyword Value/Value: Value(Multiple)\n");
321                 return (1);
322         }
323
324         if (ppd_source == NULL) {
325                 fprintf(stderr, "Failed to open ppd(%s)\n",argv[3]);
326                 return (1);
327         }
328
329         if (!strcasecmp(argv[1], "KVS")) {
330                 print_attribute_kvs(ppd_source, argv[2]);
331         } else if (!strcasecmp(argv[1], "KVM")) {
332                 print_attribute_kvm(ppd_source, argv[2]);
333         } else if (!strcasecmp(argv[1], "KVVM")) {
334                 print_attribute_kvvm(ppd_source, argv[2]);
335         } else if (!strcasecmp(argv[1], "PPD")) {
336                 print_ppd_stucture(ppd_source);
337         } else if (!strcasecmp(argv[1], "OPT")) {
338                 print_options(ppd_source);
339         } else if (!strcasecmp(argv[1], "CHOICE")) {
340                 print_option_choices(ppd_source, argv[2], argv[3]);
341         } else {
342                 return (1);
343         }
344
345         ppdClose(ppd_source);
346         return (0);
347 }
348