| 1 | /* |
| 2 | * PPD file generation program for the CUPS drivers. |
| 3 | * |
| 4 | * Copyright 1993-2008 by Mike Sweet and Robert Krawitz. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the Free |
| 8 | * Software Foundation; either version 2 of the License, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * Contents: |
| 20 | * |
| 21 | * main() - Process files on the command-line... |
| 22 | * cat_ppd() - Copy the named PPD to stdout. |
| 23 | * generate_ppd() - Generate a PPD file. |
| 24 | * getlangs() - Get a list of available translations. |
| 25 | * help() - Show detailed help. |
| 26 | * is_special_option() - Determine if an option should be grouped. |
| 27 | * list_ppds() - List the available drivers. |
| 28 | * print_group_close() - Close a UI group. |
| 29 | * print_group_open() - Open a new UI group. |
| 30 | * printlangs() - Print list of available translations. |
| 31 | * printmodels() - Print a list of available models. |
| 32 | * usage() - Show program usage. |
| 33 | * write_ppd() - Write a PPD file. |
| 34 | */ |
| 35 | |
| 36 | /* |
| 37 | * 'main()' - Process files on the command-line... |
| 38 | */ |
| 39 | |
| 40 | #include "genppd.h"cxx . . $ `<file>/src/cups/genppd.h`/ |
| 41 | |
| 42 | static int cat_ppdcxx . . $ cat_ppd(5c4306d8553b3696).(const char *uri); |
| 43 | static int list_ppdscxx . . $ list_ppds(5c4306d8553b3696).(const char *argv0); |
| 44 | |
| 45 | |
| 46 | int /* O - Exit status */ |
| 47 | maincxx . . $ main(afcd3168fc1188a4).(int argc, /* I - Number of command-line arguments */ |
| 48 | char *argv[]) /* I - Command-line arguments */ |
| 49 | { |
| 50 | /* |
| 51 | * Force POSIX locale, since stp_init incorrectly calls setlocale... |
| 52 | */ |
| 53 | |
| 54 | #if defined(HAVE_SETENVcxx . . $ `config.h:115:9`!) |
| 55 | (void) setenvcxx . . $ setenv(f0be30763a490cce).("LANG", "C", 1); |
| 56 | (void) setenvcxx . . $ setenv(f0be30763a490cce).("LC_ALL", "C", 1); |
| 57 | (void) setenvcxx . . $ setenv(f0be30763a490cce).("LC_NUMERIC", "C", 1); |
| 58 | #else |
| 59 | putenv("LANG=C"); |
| 60 | putenv("LC_ALL=C"); |
| 61 | putenv("LC_NUMERIC=C"); |
| 62 | #endif |
| 63 | |
| 64 | /* |
| 65 | * Initialise libgutenprint |
| 66 | */ |
| 67 | |
| 68 | stp_initcxx . . $ stp_init(b126dc7c1de90089).(); |
| 69 | |
| 70 | /* |
| 71 | * Process command-line... |
| 72 | */ |
| 73 | |
| 74 | if (argc == 2 && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "list")) |
| 75 | return (list_ppdscxx . . $ list_ppds(5c4306d8553b3696).(argv[0])); |
| 76 | else if (argc == 3 && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "cat")) |
| 77 | return (cat_ppdcxx . . $ cat_ppd(5c4306d8553b3696).(argv[2])); |
| 78 | else if (argc == 2 && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "org.gutenprint.multicat")) |
| 79 | { |
| 80 | char buf[1024]; |
| 81 | int status = 0; |
| 82 | while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(buf, sizeof(buf) - 1, stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!)) |
| 83 | { |
| 84 | size_t len = strlencxx . . $ strlen(751346f8406fd082).(buf); |
| 85 | if (len == 0) |
| 86 | continue; |
| 87 | if (buf[len - 1] == '\n') |
| 88 | buf[len - 1] = '\0'; |
| 89 | status |= cat_ppdcxx . . $ cat_ppd(5c4306d8553b3696).(buf); |
| 90 | fputscxx . . $ fputs(874fa6a5e59ab9bd).("*%*%EOFEOF\n", stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 91 | (void) fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 92 | } |
| 93 | } |
| 94 | else if (argc == 2 && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "VERSION")) |
| 95 | { |
| 96 | printfcxx . . $ printf(581fddd72a8db8fc).("%s\n", VERSIONcxx . . $ `config.h:204:9`!); |
| 97 | return (0); |
| 98 | } |
| 99 | else if (argc == 2 && !strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(argv[1], "org.gutenprint.extensions")) |
| 100 | { |
| 101 | printfcxx . . $ printf(581fddd72a8db8fc).("org.gutenprint.multicat"); |
| 102 | return (0); |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Usage: %s list\n", argv[0]); |
| 107 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " %s cat URI\n", argv[0]); |
| 108 | return (1); |
| 109 | } |
| 110 | return (0); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /* |
| 115 | * 'cat_ppd()' - Copy the named PPD to stdout. |
| 116 | */ |
| 117 | |
| 118 | static int /* O - Exit status */ |
| 119 | cat_ppdcxx . . $ cat_ppd(5c4306d8553b3696).(const char *uri) /* I - Driver URI */ |
| 120 | { |
| 121 | char scheme[64], /* URI scheme */ |
| 122 | userpass[32], /* URI user/pass (unused) */ |
| 123 | hostname[32], /* URI hostname */ |
| 124 | resource[1024]; /* URI resource */ |
| 125 | int port; /* URI port (unused) */ |
| 126 | http_uri_status_tcxx . . $ http_uri_status_t# status; /* URI decode status */ |
| 127 | const stp_printer_tcxx . . $ stp_printer_t# *p; /* Printer driver */ |
| 128 | const char *lang = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 129 | char *s; |
| 130 | char filename[1024], /* Filename */ |
| 131 | ppd_location[2048]; /* Installed location */ |
| 132 | const char *infix = ""; |
| 133 | ppd_type_tcxx . . $ ppd_type_t# ppd_type = PPD_STANDARDcxx . . $ PPD_STANDARD.; |
| 134 | gpfilecxx . . $ gpfile# outFD; |
| 135 | |
| 136 | if ((status = httpSeparateURIcxx . . $ httpSeparateURI(302238e9f89c53aa).(HTTP_URI_CODING_ALLcxx . . $ HTTP_URI_CODING_ALL., uri, |
| 137 | scheme, sizeof(scheme), |
| 138 | userpass, sizeof(userpass), |
| 139 | hostname, sizeof(hostname), |
| 140 | &port, resource, sizeof(resource))) |
| 141 | < HTTP_URI_OKcxx . . $ `<external>/16516257576518300729/http.h:396:13`!) |
| 142 | { |
| 143 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Bad ppd-name \"%s\" (%d)!\n", uri, status); |
| 144 | return (1); |
| 145 | } |
| 146 | |
| 147 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(scheme, "gutenprint." GUTENPRINT_RELEASE_VERSIONcxx . . $ `config.h:30:9`!) != 0) |
| 148 | { |
| 149 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Gutenprint version mismatch!\n"); |
| 150 | return(1); |
| 151 | } |
| 152 | |
| 153 | s = strchrcxx . . $ strchr(2050848944e00d54).(resource + 1, '/'); |
| 154 | if (s) |
| 155 | { |
| 156 | lang = s + 1; |
| 157 | *s = '\0'; |
| 158 | } |
| 159 | |
| 160 | if ((p = stp_get_printer_by_drivercxx . . $ stp_get_printer_by_driver(5594043bc706389b).(hostname)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 161 | { |
| 162 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Unable to find driver \"%s\"!\n", hostname); |
| 163 | return (1); |
| 164 | } |
| 165 | |
| 166 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(resource + 1, "simple") == 0) |
| 167 | { |
| 168 | infix = ".sim"; |
| 169 | ppd_type = PPD_SIMPLIFIEDcxx . . $ PPD_SIMPLIFIED.; |
| 170 | } |
| 171 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(resource + 1, "nocolor") == 0) |
| 172 | { |
| 173 | infix = ".nc"; |
| 174 | ppd_type = PPD_NO_COLOR_OPTScxx . . $ PPD_NO_COLOR_OPTS.; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * This isn't really the right thing to do. We really shouldn't |
| 179 | * be embedding filenames in automatically generated PPD files, but |
| 180 | * if the user ever decides to go back from generated PPD files to |
| 181 | * static PPD files we'll need to have this for genppdupdate to work. |
| 182 | */ |
| 183 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(filename, sizeof(filename) - 1, "stp-%s.%s%s%s", |
| 184 | hostname, GUTENPRINT_RELEASE_VERSIONcxx . . $ `config.h:30:9`!, infix, ppdextcxx . . $ ppdext.); |
| 185 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(ppd_location, sizeof(ppd_location) - 1, "%s%s%s/ppd/%s%s", |
| 186 | cups_modeldircxx . . $ cups_modeldir., |
| 187 | cups_modeldircxx . . $ cups_modeldir.[strlencxx . . $ strlen(751346f8406fd082).(cups_modeldircxx . . $ cups_modeldir.) - 1] == '/' ? "" : "/", |
| 188 | lang ? lang : "C", |
| 189 | filename, gpextcxx . . $ gpext.); |
| 190 | |
| 191 | outFD.fcxx . . $ $anonymous_type_b1f2d71ee109eb2b_1#f. = stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!; |
| 192 | return (write_ppdcxx . . $ write_ppd(b5c2acede45c40d2).(&outFD, p, lang, ppd_location, ppd_type, filename, 0)); |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * 'list_ppds()' - List the available drivers. |
| 197 | */ |
| 198 | |
| 199 | static int /* O - Exit status */ |
| 200 | list_ppdscxx . . $ list_ppds(5c4306d8553b3696).(const char *argv0) /* I - Name of program */ |
| 201 | { |
| 202 | const char *scheme; /* URI scheme */ |
| 203 | int i; /* Looping var */ |
| 204 | const stp_printer_tcxx . . $ stp_printer_t# *printer; /* Pointer to printer driver */ |
| 205 | |
| 206 | if ((scheme = strrchrcxx . . $ strrchr(2050848944e00d54).(argv0, '/')) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 207 | scheme ++; |
| 208 | else |
| 209 | scheme = argv0; |
| 210 | |
| 211 | for (i = 0; i < stp_printer_model_countcxx . . $ stp_printer_model_count(b126dc7c1de90089).(); i++) |
| 212 | if ((printer = stp_get_printer_by_indexcxx . . $ stp_get_printer_by_index(2036101347f379c).(i)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 213 | { |
| 214 | const char *device_id; |
| 215 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(stp_printer_get_familycxx . . $ stp_printer_get_family(b5d6ef9de7e317aa).(printer), "ps") || |
| 216 | !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(stp_printer_get_familycxx . . $ stp_printer_get_family(b5d6ef9de7e317aa).(printer), "raw")) |
| 217 | continue; |
| 218 | |
| 219 | device_id = stp_printer_get_device_idcxx . . $ stp_printer_get_device_id(b5d6ef9de7e317aa).(printer); |
| 220 | printfcxx . . $ printf(581fddd72a8db8fc).("\"%s://%s/expert\" " |
| 221 | "%s " |
| 222 | "\"%s\" " |
| 223 | "\"%s" CUPS_PPD_NICKNAME_STRINGcxx . . $ `config.h:11:9`! VERSIONcxx . . $ `config.h:204:9`! "\" " |
| 224 | "\"%s\"\n", |
| 225 | scheme, stp_printer_get_drivercxx . . $ stp_printer_get_driver(b5d6ef9de7e317aa).(printer), |
| 226 | "en", |
| 227 | stp_printer_get_manufacturercxx . . $ stp_printer_get_manufacturer(b5d6ef9de7e317aa).(printer), |
| 228 | stp_printer_get_long_namecxx . . $ stp_printer_get_long_name(b5d6ef9de7e317aa).(printer), |
| 229 | device_id ? device_id : ""); |
| 230 | |
| 231 | #ifdef GENERATE_SIMPLIFIED_PPDS |
| 232 | printf("\"%s://%s/simple\" " |
| 233 | "%s " |
| 234 | "\"%s\" " |
| 235 | "\"%s" CUPS_PPD_NICKNAME_STRING VERSION " Simplified\" " |
| 236 | "\"%s\"\n", |
| 237 | scheme, stp_printer_get_driver(printer), |
| 238 | "en", |
| 239 | stp_printer_get_manufacturer(printer), |
| 240 | stp_printer_get_long_name(printer), |
| 241 | device_id ? device_id : ""); |
| 242 | #endif |
| 243 | |
| 244 | #ifdef GENERATE_NOCOLOR_PPDS |
| 245 | printf("\"%s://%s/nocolor\" " |
| 246 | "%s " |
| 247 | "\"%s\" " |
| 248 | "\"%s" CUPS_PPD_NICKNAME_STRING VERSION " No color options\" " |
| 249 | "\"%s\"\n", |
| 250 | scheme, stp_printer_get_driver(printer), |
| 251 | "en", |
| 252 | stp_printer_get_manufacturer(printer), |
| 253 | stp_printer_get_long_name(printer), |
| 254 | device_id ? device_id : ""); |
| 255 | #endif |
| 256 | } |
| 257 | |
| 258 | return (0); |
| 259 | } |