[9089] | 1 | /* |
---|
| 2 | * Copyright (C) 1992 Adobe Systems Incorporated. All rights reserved. |
---|
| 3 | * |
---|
| 4 | * RCSID: $Header: /afs/dev.mit.edu/source/repository/third/transcript/src/printpanel/readppd.c,v 1.1.1.1 1996-10-07 20:25:55 ghudson Exp $ |
---|
| 5 | * |
---|
| 6 | * RCSLog: |
---|
| 7 | * $Log: not supported by cvs2svn $ |
---|
| 8 | * Revision 4.4 1993/08/23 22:58:34 snichols |
---|
| 9 | * Ignore constraints that aren't UI features. |
---|
| 10 | * |
---|
| 11 | * Revision 4.3 1993/08/19 17:26:20 snichols |
---|
| 12 | * updated for Motif 1.2, and added missing check for NULL. |
---|
| 13 | * |
---|
| 14 | * Revision 4.2 1993/06/18 16:48:15 snichols |
---|
| 15 | * Check before dereferencing. |
---|
| 16 | * |
---|
| 17 | * Revision 4.1 1992/12/15 17:36:24 snichols |
---|
| 18 | * handle constraints where all options are constrained. |
---|
| 19 | * |
---|
| 20 | * Revision 4.0 1992/08/21 16:24:13 snichols |
---|
| 21 | * Release 4.0 |
---|
| 22 | * |
---|
| 23 | * Revision 1.6 1992/07/14 23:08:22 snichols |
---|
| 24 | * Added copyright. |
---|
| 25 | * |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | #include <stdio.h> |
---|
| 31 | #include <string.h> |
---|
| 32 | #include <X11/StringDefs.h> |
---|
| 33 | #include <X11/IntrinsicP.h> |
---|
| 34 | #include <Xm/Xm.h> |
---|
| 35 | #if XmVersion > 1001 |
---|
| 36 | #include <Xm/ManagerP.h> |
---|
| 37 | #else |
---|
| 38 | #include <Xm/XmP.h> |
---|
| 39 | #endif |
---|
| 40 | #include <Xm/XmP.h> |
---|
| 41 | #include "PrintPaneP.h" |
---|
| 42 | |
---|
| 43 | #define FALSE 0 |
---|
| 44 | #define TRUE 1 |
---|
| 45 | |
---|
| 46 | extern char *PPDDir; |
---|
| 47 | /* temporary storage for constrainst */ |
---|
| 48 | static char constraints[100][125]; |
---|
| 49 | static int nCons = 0; |
---|
| 50 | |
---|
| 51 | void InitPPD(p) |
---|
| 52 | PrintPanelWidget p; |
---|
| 53 | { |
---|
| 54 | int i; |
---|
| 55 | int j; |
---|
| 56 | |
---|
| 57 | nCons = 0; |
---|
| 58 | /* |
---|
| 59 | memset(&p->printpanel.features, 0, sizeof(p->printpanel.features)); |
---|
| 60 | */ |
---|
| 61 | p->printpanel.features.num_uis = 0; |
---|
| 62 | p->printpanel.features.supports_fax = FALSE; |
---|
| 63 | for (i = 0; i < 20; i++) { |
---|
| 64 | p->printpanel.features.uis[i].num_options = 0; |
---|
| 65 | p->printpanel.features.uis[i].default_option = -1; |
---|
| 66 | p->printpanel.features.uis[i].key_tran[0] = '\0'; |
---|
| 67 | p->printpanel.features.uis[i].display = TRUE; |
---|
| 68 | for (j = 0; j < 50; j++) { |
---|
| 69 | p->printpanel.features.uis[i].options[j].num_constraints = 0; |
---|
| 70 | p->printpanel.features.uis[i].options[j].gray = FALSE; |
---|
| 71 | p->printpanel.features.uis[i].options[j].name_tran[0] = '\0'; |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | static void ParseConstraintLine(line, keyword, option, nokeyword, nooption) |
---|
| 77 | char *line; |
---|
| 78 | char **keyword, **option, **nokeyword, **nooption; |
---|
| 79 | { |
---|
| 80 | char *p, *q; |
---|
| 81 | |
---|
| 82 | p = line; |
---|
| 83 | while (*p != '*') p++; |
---|
| 84 | *keyword = p; |
---|
| 85 | p = strchr(*keyword, ' '); |
---|
| 86 | *p = '\0'; |
---|
| 87 | p++; |
---|
| 88 | while (*p == ' ') p++; |
---|
| 89 | if (*p != '*') { |
---|
| 90 | /* we have a constraining option */ |
---|
| 91 | *option = p; |
---|
| 92 | p = strchr(*option, ' '); |
---|
| 93 | *p = '\0'; |
---|
| 94 | p++; |
---|
| 95 | while (*p == ' ') p++; |
---|
| 96 | } |
---|
| 97 | else *option = NULL; |
---|
| 98 | /* constrained keyword */ |
---|
| 99 | *nokeyword = p; |
---|
| 100 | p = strchr(*nokeyword, ' '); |
---|
| 101 | if (p) { |
---|
| 102 | /* possibly a constrained option */ |
---|
| 103 | *p = '\0'; |
---|
| 104 | p++; |
---|
| 105 | while (*p == ' ') p++; |
---|
| 106 | if (*p != '\0' && *p != '\n') { |
---|
| 107 | *nooption = p; |
---|
| 108 | p = strchr(*nooption, ' '); |
---|
| 109 | if (p) *p = '\0'; |
---|
| 110 | } |
---|
| 111 | else |
---|
| 112 | *nooption = NULL; |
---|
| 113 | } |
---|
| 114 | else *nooption = NULL; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | static UIData *FindKeyword(p, key) |
---|
| 118 | PrintPanelWidget p; |
---|
| 119 | char *key; |
---|
| 120 | { |
---|
| 121 | int i; |
---|
| 122 | UIData *uiptr; |
---|
| 123 | |
---|
| 124 | if (key == NULL) |
---|
| 125 | return NULL; |
---|
| 126 | |
---|
| 127 | for (i = 0; i < p->printpanel.features.num_uis; i++) { |
---|
| 128 | uiptr = &p->printpanel.features.uis[i]; |
---|
| 129 | if (strcmp(uiptr->keyword, key) != 0) { |
---|
| 130 | continue; |
---|
| 131 | } |
---|
| 132 | /* found the keyword */ |
---|
| 133 | return uiptr; |
---|
| 134 | } |
---|
| 135 | return NULL; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | static OptionData *FindOption(uiptr, opt) |
---|
| 139 | UIData *uiptr; |
---|
| 140 | char *opt; |
---|
| 141 | { |
---|
| 142 | int i; |
---|
| 143 | OptionData *optptr; |
---|
| 144 | |
---|
| 145 | if (opt == NULL) |
---|
| 146 | return NULL; |
---|
| 147 | if (uiptr == NULL) |
---|
| 148 | return NULL; |
---|
| 149 | for (i = 0; i < uiptr->num_options; i++) { |
---|
| 150 | optptr = &(uiptr->options[i]); |
---|
| 151 | if (strcmp(optptr->name, opt) != 0) |
---|
| 152 | continue; |
---|
| 153 | /* found the option */ |
---|
| 154 | return optptr; |
---|
| 155 | } |
---|
| 156 | return NULL; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | static void AddConstraint(p, optptr, key, opt) |
---|
| 160 | PrintPanelWidget p; |
---|
| 161 | OptionData *optptr; |
---|
| 162 | char *key; |
---|
| 163 | char *opt; |
---|
| 164 | { |
---|
| 165 | UIData *up; |
---|
| 166 | OptionData *op; |
---|
| 167 | /* if the constraint isn't a UI feature, ignore it */ |
---|
| 168 | if ((up = FindKeyword(p, key)) != NULL) |
---|
| 169 | optptr->constraints[optptr->num_constraints].no_key = up; |
---|
| 170 | if ((op = FindOption(up, opt)) != NULL) |
---|
| 171 | optptr->constraints[optptr->num_constraints].no_option = op; |
---|
| 172 | if (up && op) |
---|
| 173 | optptr->num_constraints++; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | static void HandleConstraints(p) |
---|
| 178 | PrintPanelWidget p; |
---|
| 179 | { |
---|
| 180 | int i, j, k; |
---|
| 181 | char *key, *opt, *nokey, *noopt; |
---|
| 182 | UIData *uiptr; |
---|
| 183 | UIData *noptr; |
---|
| 184 | OptionData *optptr; |
---|
| 185 | |
---|
| 186 | for (i = 0; i < nCons; i++) { |
---|
| 187 | ParseConstraintLine(constraints[i], &key, &opt, &nokey, &noopt); |
---|
| 188 | uiptr = FindKeyword(p, key); |
---|
| 189 | if (uiptr) { |
---|
| 190 | if (opt) { |
---|
| 191 | optptr = FindOption(uiptr, opt); |
---|
| 192 | if (optptr) { |
---|
| 193 | if (noopt) { |
---|
| 194 | AddConstraint(p, optptr, nokey, noopt); |
---|
| 195 | } |
---|
| 196 | else { |
---|
| 197 | /* all options are constrained */ |
---|
| 198 | noptr = FindKeyword(p, nokey); |
---|
| 199 | if (noptr) { |
---|
| 200 | for (j = 0; j < noptr->num_options; j++) { |
---|
| 201 | AddConstraint(p, optptr, nokey, |
---|
| 202 | noptr->options[j].name); |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | else { |
---|
| 209 | /* all options are constraining */ |
---|
| 210 | for (j = 0; j < uiptr->num_options; j++) { |
---|
| 211 | optptr = &(uiptr->options[j]); |
---|
| 212 | if ((strcmp(optptr->name, "None") == 0) || |
---|
| 213 | (strcmp(optptr->name, "False") == 0)) |
---|
| 214 | continue; |
---|
| 215 | AddConstraint(p, optptr, nokey, noopt); |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | /* now, go ahead and mark as gray those options constrained by a |
---|
| 221 | installable option that isn't installed */ |
---|
| 222 | |
---|
| 223 | for (i = 0; i < p->printpanel.features.num_uis; i++) { |
---|
| 224 | uiptr = &p->printpanel.features.uis[i]; |
---|
| 225 | if (uiptr->display) { |
---|
| 226 | /* regular one, not installable */ |
---|
| 227 | continue; |
---|
| 228 | } |
---|
| 229 | if (strcmp(uiptr->options[uiptr->default_option].name, "True") == |
---|
| 230 | 0) { |
---|
| 231 | /* it's installed */ |
---|
| 232 | continue; |
---|
| 233 | } |
---|
| 234 | for (j = 0; j < uiptr->num_options; j++) { |
---|
| 235 | if (j != uiptr->default_option) |
---|
| 236 | continue; |
---|
| 237 | for (k = 0; k < uiptr->options[j].num_constraints; k++) { |
---|
| 238 | uiptr->options[j].constraints[k].no_option->gray = |
---|
| 239 | TRUE; |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | int HandleContents(p, fp) |
---|
| 246 | PrintPanelWidget p; |
---|
| 247 | FILE *fp; |
---|
| 248 | { |
---|
| 249 | char *s, *q; |
---|
| 250 | int ret; |
---|
| 251 | char *key, *option, *value, *otran, *vtran; |
---|
| 252 | int midUI = FALSE; |
---|
| 253 | int midinstall = FALSE; |
---|
| 254 | char buf[1024]; |
---|
| 255 | char *pbuf; |
---|
| 256 | char defname[255]; |
---|
| 257 | char tmpname[255]; |
---|
| 258 | int i, j, k; |
---|
| 259 | UIData *uiptr; |
---|
| 260 | OptionData *popt; |
---|
| 261 | char *beg, *end; |
---|
| 262 | char incname[1024]; |
---|
| 263 | FILE *incfile; |
---|
| 264 | int tmp; |
---|
| 265 | int multiline = FALSE; |
---|
| 266 | int quotestring = FALSE; |
---|
| 267 | |
---|
| 268 | pbuf = buf; |
---|
| 269 | while (fgets(pbuf, 1024, fp)) { |
---|
| 270 | if (buf[0] == '*') { |
---|
| 271 | if (buf[1] == '%') { |
---|
| 272 | /* comment */ |
---|
| 273 | continue; |
---|
| 274 | } |
---|
| 275 | s = strchr(buf, '\n'); |
---|
| 276 | if (s) *s = '\0'; |
---|
| 277 | ret = ParseLine(buf, &key, &option, &otran, &value, &vtran); |
---|
| 278 | if (ret > 0) { |
---|
| 279 | if (strncmp(key, "*Include", 8) == 0) { |
---|
| 280 | /* strip off delimiters */ |
---|
| 281 | beg = value; |
---|
| 282 | beg++; |
---|
| 283 | end = strrchr(beg, *value); |
---|
| 284 | if (end) *end = '\0'; |
---|
| 285 | if (*beg != '/') { |
---|
| 286 | /* tack on ppddir */ |
---|
| 287 | strcpy(incname, PPDDir); |
---|
| 288 | strcat(incname, beg); |
---|
| 289 | } |
---|
| 290 | else |
---|
| 291 | strcpy(incname, beg); |
---|
| 292 | if ((incfile = fopen(incname, "r")) == NULL) { |
---|
| 293 | fprintf(stderr, "couldn't open include file %s\n", |
---|
| 294 | incname); |
---|
| 295 | continue; |
---|
| 296 | } |
---|
| 297 | tmp = HandleContents(p, incfile); |
---|
| 298 | if (tmp == FALSE) |
---|
| 299 | return tmp; |
---|
| 300 | } |
---|
| 301 | if (*value == '"') { |
---|
| 302 | s = value; |
---|
| 303 | value++; |
---|
| 304 | q = strrchr(value, '"'); |
---|
| 305 | if (q) |
---|
| 306 | *q = '\0'; |
---|
| 307 | *s = '\0'; |
---|
| 308 | } |
---|
| 309 | if (strncmp(key, "*FormatVersion", 14) == 0) { |
---|
| 310 | strcpy(p->printpanel.features.format_version, value); |
---|
| 311 | } |
---|
| 312 | if (strncmp(key, "*Product", 8) == 0) { |
---|
| 313 | strcpy(p->printpanel.features.product, value); |
---|
| 314 | } |
---|
| 315 | if (strncmp(key, "*PSVersion", 10) == 0) { |
---|
| 316 | strcpy(p->printpanel.features.ps_version, value); |
---|
| 317 | } |
---|
| 318 | if (strncmp(key, "*ModelName", 10) == 0) { |
---|
| 319 | strcpy(p->printpanel.features.model, value); |
---|
| 320 | } |
---|
| 321 | if (strncmp(key, "*Nickname", 9) == 0) { |
---|
| 322 | strcpy(p->printpanel.features.nickname, value); |
---|
| 323 | } |
---|
| 324 | if (strncmp(key, "*FreeVM", 7) == 0) { |
---|
| 325 | p->printpanel.features.free_vm = atoi(value); |
---|
| 326 | } |
---|
| 327 | if (strncmp(key, "*LanguageLevel", 15) == 0) { |
---|
| 328 | p->printpanel.features.language_level = atoi(value); |
---|
| 329 | } |
---|
| 330 | if (strncmp(key, "*ColorDevice", 12) == 0) { |
---|
| 331 | if (strcmp(value, "True") == 0) |
---|
| 332 | p->printpanel.features.color_device = TRUE; |
---|
| 333 | } |
---|
| 334 | if (strncmp(key, "*FaxSupport", 11) == 0) { |
---|
| 335 | p->printpanel.features.supports_fax = TRUE; |
---|
| 336 | } |
---|
| 337 | if (strncmp(key, "*DefaultResolution", 18) == 0) { |
---|
| 338 | strcpy(p->printpanel.features.default_resolution, value); |
---|
| 339 | } |
---|
| 340 | if (strncmp(key, "*UIConstraints", 14) == 0) { |
---|
| 341 | strcpy(constraints[nCons++], value); |
---|
| 342 | } |
---|
| 343 | if (strcmp(key, "*OpenGroup") == 0 && |
---|
| 344 | strcmp(value,"InstallableOptions") == 0 ) { |
---|
| 345 | /* special case of group */ |
---|
| 346 | midinstall = TRUE; |
---|
| 347 | } |
---|
| 348 | if (strncmp(key, "*OpenUI", 7) == 0) { |
---|
| 349 | uiptr = FindKeyword(p, option); |
---|
| 350 | if (uiptr == NULL) { |
---|
| 351 | uiptr = |
---|
| 352 | &p->printpanel.features.uis[p->printpanel.features.num_uis]; |
---|
| 353 | /* we've already seen this one, so we've already |
---|
| 354 | gotten these values */ |
---|
| 355 | if (strncmp(value, "PickOne", 7) == 0) |
---|
| 356 | uiptr->type = PICKONE; |
---|
| 357 | if (strncmp(value, "PickMany", 8) == 0) |
---|
| 358 | uiptr->type = PICKMANY; |
---|
| 359 | if (strncmp(value, "Boolean", 7) == 0) |
---|
| 360 | uiptr->type = BOOL; |
---|
| 361 | if (otran) { |
---|
| 362 | strcpy(uiptr->key_tran, otran); |
---|
| 363 | } |
---|
| 364 | else { |
---|
| 365 | uiptr->key_tran[0] = '\0'; |
---|
| 366 | } |
---|
| 367 | strcpy(uiptr->keyword, option); |
---|
| 368 | } |
---|
| 369 | strcpy(defname, "*Default"); |
---|
| 370 | s = uiptr->keyword + 1; |
---|
| 371 | strcat(defname, s); |
---|
| 372 | midUI = TRUE; |
---|
| 373 | if (midinstall) { |
---|
| 374 | uiptr->display = FALSE; |
---|
| 375 | } |
---|
| 376 | else { |
---|
| 377 | uiptr->display = TRUE; |
---|
| 378 | } |
---|
| 379 | } |
---|
| 380 | if (midUI) { |
---|
| 381 | if (strncmp(key, defname, strlen(defname)) == 0) { |
---|
| 382 | if (FindOption(uiptr, tmpname) == NULL) { |
---|
| 383 | strcpy(tmpname, value); |
---|
| 384 | } |
---|
| 385 | else tmpname[0] = '\0'; |
---|
| 386 | continue; |
---|
| 387 | } |
---|
| 388 | if (strncmp(key, uiptr->keyword, |
---|
| 389 | strlen(uiptr->keyword)) == 0) { |
---|
| 390 | /* option! */ |
---|
| 391 | if (FindOption(uiptr, option) == NULL) { |
---|
| 392 | if (otran) { |
---|
| 393 | strcpy(uiptr->options[uiptr->num_options].name_tran, |
---|
| 394 | otran); |
---|
| 395 | } |
---|
| 396 | else { |
---|
| 397 | uiptr->options[uiptr->num_options].name_tran[0] |
---|
| 398 | = '\0'; |
---|
| 399 | } |
---|
| 400 | strcpy(uiptr->options[uiptr->num_options].name, |
---|
| 401 | option); |
---|
| 402 | if (strcmp(option, tmpname) == 0) { |
---|
| 403 | uiptr->default_option = uiptr->num_options; |
---|
| 404 | } |
---|
| 405 | uiptr->num_options++; |
---|
| 406 | } |
---|
| 407 | } |
---|
| 408 | if (strncmp(key, "*CloseUI", 8) == 0) { |
---|
| 409 | if (strncmp(value, uiptr->keyword, |
---|
| 410 | strlen(uiptr->keyword)) == 0) { |
---|
| 411 | midUI = FALSE; |
---|
| 412 | defname[0] = '\0'; |
---|
| 413 | tmpname[0] = '\0'; |
---|
| 414 | p->printpanel.features.num_uis++; |
---|
| 415 | uiptr = |
---|
| 416 | &p->printpanel.features.uis[p->printpanel.features.num_uis]; |
---|
| 417 | } |
---|
| 418 | else { |
---|
| 419 | fprintf(stderr, |
---|
| 420 | "CloseUI doesn't match OpenUI\n"); |
---|
| 421 | return FALSE; |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | } |
---|
| 425 | if (strcmp(key, "*CloseGroup") == 0 && |
---|
| 426 | strcmp(value,"InstallableOptions") == 0 ) { |
---|
| 427 | midinstall = FALSE; |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | |
---|
| 435 | |
---|
| 436 | int ReadPPD(p, fp) |
---|
| 437 | PrintPanelWidget p; |
---|
| 438 | FILE *fp; |
---|
| 439 | { |
---|
| 440 | if (fp == NULL) return FALSE; |
---|
| 441 | InitPPD(p); |
---|
| 442 | HandleContents(p, fp); |
---|
| 443 | HandleConstraints(p); |
---|
| 444 | return TRUE; |
---|
| 445 | } |
---|
| 446 | |
---|