4 * Copyright 2013 Samsung Electronics Co., Ltd
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
10 * http://floralicense.org/license/
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.
25 static pt_db *database;
29 fprintf(stderr, "Extract ppd file by model name:\n");
30 fprintf(stderr, "Usage: %s -m <model> -i <database>\n\n", gargv[0]);
31 fprintf(stderr, "Extract ppd file by product name:\n");
32 fprintf(stderr, "Usage: %s -p <product> -i <database>\n\n", gargv[0]);
33 fprintf(stderr, "Extract ppd file either by model name or product name:\n");
34 fprintf(stderr, "Usage: %s -a <key> -i <database>\n", gargv[0]);
37 void clean_all_resources(void)
42 config *initialization(int argc, char **argv)
49 int res = atexit(clean_all_resources);
51 perror("atexit() failed");
54 config *cfg = malloc(sizeof(config));
56 fprintf(stderr, "Can't allocate memory\n");
59 bzero(cfg, sizeof(config));
61 while ((opt = getopt(argc, argv, "i:m:p:a:r:")) != -1) {
65 cfg->drvstr = strdup(optarg);
67 fprintf(stderr, "Can't duplicate string with strdup()\n");
72 fprintf(stderr, "Don't support extraction from multiple databases\n");
73 fprintf(stderr, "Do not provide some \'-i\'' options\n");
79 cfg->product = strdup(optarg);
82 fprintf(stderr, "Can't duplicate string with strdup()\n");
87 fprintf(stderr, "Supported extraction only of one ppd file by product\n");
88 fprintf(stderr, "Do not provide some \'-p\'' options\n");
94 cfg->model = strdup(optarg);
97 fprintf(stderr, "Can't duplicate string with strdup()\n");
102 fprintf(stderr, "Supported extraction only of one ppd file by modelname\n");
103 fprintf(stderr, "Do not provide some \'-m\'' options\n");
110 cfg->model = strdup(optarg);
112 fprintf(stderr, "Can't allocate memory\n");
117 fprintf(stderr, "Supported extraction only of one ppd file by modelname\n");
118 fprintf(stderr, "Do not provide some \'-m\'' options\n");
123 cfg->product = strdup(optarg);
125 fprintf(stderr, "Can't duplicate string with strdup()\n");
130 fprintf(stderr, "Supported extraction only of one ppd file by product\n");
131 fprintf(stderr, "Do not provide some \'-p\'' options\n");
141 cfg->find_product = product;
142 cfg->find_model = model;
145 fprintf(stderr, "drv file is not provided\n");
152 int main(int argc, char **argv)
155 config *cfg = initialization(argc, argv);
157 fprintf(stderr, "Unexpected error\n");
162 fprintf(stderr, "drvstr is NULL\n");
166 database = pt_create_db(cfg->drvstr);
168 fprintf(stderr, "database is NULL\n");
174 if (cfg->find_model && !cfg->find_product) {
175 output = pt_extract_ppd(database, cfg->model, PT_SEARCH_MODEL);
177 fprintf(stderr, "Can't find suitable ppd file by model\n");
180 } else if (cfg->find_product && !cfg->find_model) {
181 output = pt_extract_ppd(database, cfg->product, PT_SEARCH_PROD);
183 fprintf(stderr, "Can't find suitable ppd file by product\n");
186 } else if (cfg->find_model && cfg->find_product) {
187 if (strcmp(cfg->product, cfg->model)) {
188 fprintf(stderr, "Supported extraction only of one ppd file\n");
189 fprintf(stderr, "Do not provide mixed \'-m\',\'-p\',\'-a\' with different names\n");
193 output = pt_extract_ppd(database, cfg->model, PT_SEARCH_MODEL);
195 output = pt_extract_ppd(database, cfg->product, PT_SEARCH_PROD);
197 fprintf(stderr, "Can't find suitable ppd file\n");
206 printf("%s", output);