4 * Copyright (c) 2012-2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 typedef struct _cups_array_s cups_array_t;
28 static void print_ppd_stucture(ppd_file_t *ppdfile)
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);
43 if (ppdfile->patches != NULL) {
44 fprintf(stderr,"[%20s] %s\n","patches", ppdfile->patches);
47 fprintf(stderr,"[%20s] %d\n","num_emulations", ppdfile->num_emulations);
49 if (ppdfile->emulations != NULL) {
50 fprintf(stderr,"[%20s] %s\n","emulations", ppdfile->emulations->name);
53 if (ppdfile->jcl_begin != NULL) {
54 fprintf(stderr,"[%20s] %s\n","jcl_begin", ppdfile->jcl_begin);
57 if (ppdfile->jcl_ps != NULL) {
58 fprintf(stderr,"[%20s] %s\n","jcl_ps", ppdfile->jcl_ps);
61 if (ppdfile->jcl_end != NULL) {
62 fprintf(stderr,"[%20s] %s\n","jcl_end", ppdfile->jcl_end);
65 if (ppdfile->lang_encoding != NULL) {
66 fprintf(stderr,"[%20s] %s\n","lang_encoding", ppdfile->lang_encoding);
69 if (ppdfile->lang_version != NULL) {
70 fprintf(stderr,"[%20s] %s\n","lang_version", ppdfile->lang_version);
73 if (ppdfile->modelname != NULL) {
74 fprintf(stderr,"[%20s] %s\n","modelname", ppdfile->modelname);
77 if (ppdfile->ttrasterizer != NULL) {
78 fprintf(stderr,"[%20s] %s\n","ttrasterizer", ppdfile->ttrasterizer);
81 if (ppdfile->manufacturer != NULL) {
82 fprintf(stderr,"[%20s] %s\n","manufacturer", ppdfile->manufacturer);
85 if (ppdfile->product != NULL) {
86 fprintf(stderr,"[%20s] %s\n","product", ppdfile->product);
89 if (ppdfile->nickname != NULL) {
90 fprintf(stderr,"[%20s] %s\n","nickname", ppdfile->nickname);
93 if (ppdfile->shortnickname != NULL) {
94 fprintf(stderr,"[%20s] %s\n","shortnickname", ppdfile->shortnickname);
97 fprintf(stderr,"[%20s] %d\n","num_groups", ppdfile->num_groups);
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);
104 fprintf(stderr,"[%20s] %d\n","num_sizes", ppdfile->num_sizes);
106 if (ppdfile->sizes != NULL) {
107 fprintf(stderr,"[%20s] %s\n","sizes", ppdfile->sizes->name);
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);
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);
124 fprintf(stderr,"[%20s] %d\n","num_fonts", ppdfile->num_fonts);
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]);
132 fprintf(stderr,"[%20s] %d\n","num_profiles", ppdfile->num_profiles);
134 if (ppdfile->profiles != NULL) {
135 fprintf(stderr,"[%20s] %s\n","profiles", ppdfile->profiles->media_type);
138 fprintf(stderr,"[%20s] %d\n","num_filters", ppdfile->num_filters);
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]);
146 fprintf(stderr,"[%20s] %d\n","flip_duplex", ppdfile->flip_duplex);
148 if (ppdfile->protocols != NULL) {
149 fprintf(stderr,"[%20s] %s\n","protocols", ppdfile->protocols);
152 if (ppdfile->pcfilename != NULL) {
153 fprintf(stderr,"[%20s] %s\n","pcfilename", ppdfile->pcfilename);
156 fprintf(stderr,"[%20s] %d\n","num_attrs", ppdfile->num_attrs);
157 fprintf(stderr,"[%20s] %d\n","cur_attr", ppdfile->cur_attr);
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);
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);
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);
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);
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);
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);
208 "*Keyword: Value" Type(single)
210 static void print_attribute_kvs(ppd_file_t *ppdfile, const char *option)
212 ppd_attr_t *attr = NULL;
214 for (attr = ppdFindAttr(ppdfile, option, NULL); attr != NULL;
215 attr = ppdFindNextAttr(ppdfile, option, NULL)) {
218 printf("%s\n",attr->value);
224 "*Keyword: Value" Type(multiple)
226 static void print_attribute_kvm(ppd_file_t *ppdfile, const char *option)
228 ppd_attr_t *attr = NULL;
230 for (attr = ppdFindAttr(ppdfile, option, NULL); attr != NULL;
231 attr = ppdFindNextAttr(ppdfile, option, NULL)) {
234 printf("[Name]%s [Spec]%s [Text]%s [Value]%s\n"
244 "*Keyword Value/Value: Value" Type
246 static void print_attribute_kvvm(ppd_file_t *ppdfile, const char *option)
248 ppd_option_t *attr = NULL;
251 attr = ppdFindOption(ppdfile, option);
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);
264 static void print_options(ppd_file_t *ppdfile)
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);
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);
282 static void print_option_choices(ppd_file_t *ppdfile, const char *keyword, const char *ch)
284 ppd_option_t *opt = NULL;
285 ppd_choice_t *choice = NULL;
287 opt = ppdFindOption(ppdfile, keyword);
292 choice = ppdFindChoice(opt, ch);
293 if (choice == NULL) {
297 printf("[Choice]%s",choice->choice);
298 printf(" [Code]%s",choice->code);
299 printf(" [Text]%s\n",choice->text);
303 int main(int argc, char *argv[])
305 ppd_file_t *ppd_source = NULL;
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]);
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");
324 if (ppd_source == NULL) {
325 fprintf(stderr, "Failed to open ppd(%s)\n",argv[3]);
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]);
345 ppdClose(ppd_source);