1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
|
/*
* "$Id: mark.c 10996 2013-05-29 11:51:34Z msweet $"
*
* Option marking routines for CUPS.
*
* Copyright 2007-2012 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
* property of Apple Inc. and are protected by Federal copyright
* law. Distribution and use rights are outlined in the file "LICENSE.txt"
* which should have been included with this file. If this file is
* file is missing or damaged, see the license at "http://www.cups.org/".
*
* PostScript is a trademark of Adobe Systems, Inc.
*
* This file is subject to the Apple OS-Developed Software exception.
*
* Contents:
*
* cupsMarkOptions() - Mark command-line options in a PPD file.
* ppdFindChoice() - Return a pointer to an option choice.
* ppdFindMarkedChoice() - Return the marked choice for the specified option.
* ppdFindOption() - Return a pointer to the specified option.
* ppdIsMarked() - Check to see if an option is marked.
* ppdMarkDefaults() - Mark all default options in the PPD file.
* ppdMarkOption() - Mark an option in a PPD file and return the number
* of conflicts.
* ppdFirstOption() - Return the first option in the PPD file.
* ppdNextOption() - Return the next option in the PPD file.
* _ppdParseOptions() - Parse options from a PPD file.
* ppd_debug_marked() - Output the marked array to stdout...
* ppd_defaults() - Set the defaults for this group and all sub-groups.
* ppd_mark_choices() - Mark one or more option choices from a string.
* ppd_mark_option() - Quickly mark an option without checking for
* conflicts.
*/
/*
* Include necessary headers...
*/
#include "cups-private.h"
/*
* Local functions...
*/
#ifdef DEBUG
static void ppd_debug_marked(ppd_file_t *ppd, const char *title);
#else
# define ppd_debug_marked(ppd,title)
#endif /* DEBUG */
static void ppd_defaults(ppd_file_t *ppd, ppd_group_t *g);
static void ppd_mark_choices(ppd_file_t *ppd, const char *s);
static void ppd_mark_option(ppd_file_t *ppd, const char *option,
const char *choice);
/*
* 'cupsMarkOptions()' - Mark command-line options in a PPD file.
*
* This function maps the IPP "finishings", "media", "mirror",
* "multiple-document-handling", "output-bin", "print-color-mode",
* "print-quality", "printer-resolution", and "sides" attributes to their
* corresponding PPD options and choices.
*/
int /* O - 1 if conflicts exist, 0 otherwise */
cupsMarkOptions(
ppd_file_t *ppd, /* I - PPD file */
int num_options, /* I - Number of options */
cups_option_t *options) /* I - Options */
{
int i, j; /* Looping vars */
char *ptr, /* Pointer into string */
s[255]; /* Temporary string */
const char *val, /* Pointer into value */
*media, /* media option */
*output_bin, /* output-bin option */
*page_size, /* PageSize option */
*ppd_keyword, /* PPD keyword */
*print_color_mode, /* print-color-mode option */
*print_quality, /* print-quality option */
*sides; /* sides option */
cups_option_t *optptr; /* Current option */
ppd_attr_t *attr; /* PPD attribute */
_ppd_cache_t *cache; /* PPD cache and mapping data */
/*
* Check arguments...
*/
if (!ppd || num_options <= 0 || !options)
return (0);
ppd_debug_marked(ppd, "Before...");
/*
* Do special handling for finishings, media, output-bin, output-mode,
* print-color-mode, print-quality, and PageSize...
*/
media = cupsGetOption("media", num_options, options);
output_bin = cupsGetOption("output-bin", num_options, options);
page_size = cupsGetOption("PageSize", num_options, options);
print_quality = cupsGetOption("print-quality", num_options, options);
sides = cupsGetOption("sides", num_options, options);
if ((print_color_mode = cupsGetOption("print-color-mode", num_options,
options)) == NULL)
print_color_mode = cupsGetOption("output-mode", num_options, options);
if ((media || output_bin || print_color_mode || print_quality || sides) &&
!ppd->cache)
{
/*
* Load PPD cache and mapping data as needed...
*/
ppd->cache = _ppdCacheCreateWithPPD(ppd);
}
cache = ppd->cache;
if (media)
{
/*
* Loop through the option string, separating it at commas and marking each
* individual option as long as the corresponding PPD option (PageSize,
* InputSlot, etc.) is not also set.
*
* For PageSize, we also check for an empty option value since some versions
* of MacOS X use it to specify auto-selection of the media based solely on
* the size.
*/
for (val = media; *val;)
{
/*
* Extract the sub-option from the string...
*/
for (ptr = s; *val && *val != ',' && (ptr - s) < (sizeof(s) - 1);)
*ptr++ = *val++;
*ptr++ = '\0';
if (*val == ',')
val ++;
/*
* Mark it...
*/
if (!page_size || !page_size[0])
{
if (!_cups_strncasecmp(s, "Custom.", 7) || ppdPageSize(ppd, s))
ppd_mark_option(ppd, "PageSize", s);
else if ((ppd_keyword = _ppdCacheGetPageSize(cache, NULL, s, NULL)) != NULL)
ppd_mark_option(ppd, "PageSize", ppd_keyword);
}
if (cache && cache->source_option &&
!cupsGetOption(cache->source_option, num_options, options) &&
(ppd_keyword = _ppdCacheGetInputSlot(cache, NULL, s)) != NULL)
ppd_mark_option(ppd, cache->source_option, ppd_keyword);
if (!cupsGetOption("MediaType", num_options, options) &&
(ppd_keyword = _ppdCacheGetMediaType(cache, NULL, s)) != NULL)
ppd_mark_option(ppd, "MediaType", ppd_keyword);
}
}
if (cache)
{
if (!cupsGetOption("com.apple.print.DocumentTicket.PMSpoolFormat",
num_options, options) &&
!cupsGetOption("APPrinterPreset", num_options, options) &&
(print_color_mode || print_quality))
{
/*
* Map output-mode and print-quality to a preset...
*/
_pwg_print_color_mode_t pwg_pcm;/* print-color-mode index */
_pwg_print_quality_t pwg_pq; /* print-quality index */
cups_option_t *preset;/* Current preset option */
if (print_color_mode && !strcmp(print_color_mode, "monochrome"))
pwg_pcm = _PWG_PRINT_COLOR_MODE_MONOCHROME;
else
pwg_pcm = _PWG_PRINT_COLOR_MODE_COLOR;
if (print_quality)
{
pwg_pq = atoi(print_quality) - IPP_QUALITY_DRAFT;
if (pwg_pq < _PWG_PRINT_QUALITY_DRAFT)
pwg_pq = _PWG_PRINT_QUALITY_DRAFT;
else if (pwg_pq > _PWG_PRINT_QUALITY_HIGH)
pwg_pq = _PWG_PRINT_QUALITY_HIGH;
}
else
pwg_pq = _PWG_PRINT_QUALITY_NORMAL;
if (cache->num_presets[pwg_pcm][pwg_pq] == 0)
{
/*
* Try to find a preset that works so that we maximize the chances of us
* getting a good print using IPP attributes.
*/
if (cache->num_presets[pwg_pcm][_PWG_PRINT_QUALITY_NORMAL] > 0)
pwg_pq = _PWG_PRINT_QUALITY_NORMAL;
else if (cache->num_presets[_PWG_PRINT_COLOR_MODE_COLOR][pwg_pq] > 0)
pwg_pcm = _PWG_PRINT_COLOR_MODE_COLOR;
else
{
pwg_pq = _PWG_PRINT_QUALITY_NORMAL;
pwg_pcm = _PWG_PRINT_COLOR_MODE_COLOR;
}
}
if (cache->num_presets[pwg_pcm][pwg_pq] > 0)
{
/*
* Copy the preset options as long as the corresponding names are not
* already defined in the IPP request...
*/
for (i = cache->num_presets[pwg_pcm][pwg_pq],
preset = cache->presets[pwg_pcm][pwg_pq];
i > 0;
i --, preset ++)
{
if (!cupsGetOption(preset->name, num_options, options))
ppd_mark_option(ppd, preset->name, preset->value);
}
}
}
if (output_bin && !cupsGetOption("OutputBin", num_options, options) &&
(ppd_keyword = _ppdCacheGetOutputBin(cache, output_bin)) != NULL)
{
/*
* Map output-bin to OutputBin...
*/
ppd_mark_option(ppd, "OutputBin", ppd_keyword);
}
if (sides && cache->sides_option &&
!cupsGetOption(cache->sides_option, num_options, options))
{
/*
* Map sides to duplex option...
*/
if (!strcmp(sides, "one-sided") && cache->sides_1sided)
ppd_mark_option(ppd, cache->sides_option, cache->sides_1sided);
else if (!strcmp(sides, "two-sided-long-edge") &&
cache->sides_2sided_long)
ppd_mark_option(ppd, cache->sides_option, cache->sides_2sided_long);
else if (!strcmp(sides, "two-sided-short-edge") &&
cache->sides_2sided_short)
ppd_mark_option(ppd, cache->sides_option, cache->sides_2sided_short);
}
}
/*
* Mark other options...
*/
for (i = num_options, optptr = options; i > 0; i --, optptr ++)
if (!_cups_strcasecmp(optptr->name, "media") ||
!_cups_strcasecmp(optptr->name, "output-bin") ||
!_cups_strcasecmp(optptr->name, "output-mode") ||
!_cups_strcasecmp(optptr->name, "print-quality") ||
!_cups_strcasecmp(optptr->name, "sides"))
continue;
else if (!_cups_strcasecmp(optptr->name, "resolution") ||
!_cups_strcasecmp(optptr->name, "printer-resolution"))
{
ppd_mark_option(ppd, "Resolution", optptr->value);
ppd_mark_option(ppd, "SetResolution", optptr->value);
/* Calcomp, Linotype, QMS, Summagraphics, Tektronix, Varityper */
ppd_mark_option(ppd, "JCLResolution", optptr->value);
/* HP */
ppd_mark_option(ppd, "CNRes_PGP", optptr->value);
/* Canon */
}
else if (!_cups_strcasecmp(optptr->name, "multiple-document-handling"))
{
if (!cupsGetOption("Collate", num_options, options) &&
ppdFindOption(ppd, "Collate"))
{
if (_cups_strcasecmp(optptr->value, "separate-documents-uncollated-copies"))
ppd_mark_option(ppd, "Collate", "True");
else
ppd_mark_option(ppd, "Collate", "False");
}
}
else if (!_cups_strcasecmp(optptr->name, "finishings"))
{
/*
* Lookup cupsIPPFinishings attributes for each value...
*/
for (ptr = optptr->value; *ptr;)
{
/*
* Get the next finishings number...
*/
if (!isdigit(*ptr & 255))
break;
if ((j = strtol(ptr, &ptr, 10)) < 3)
break;
/*
* Skip separator as needed...
*/
if (*ptr == ',')
ptr ++;
/*
* Look it up in the PPD file...
*/
sprintf(s, "%d", j);
if ((attr = ppdFindAttr(ppd, "cupsIPPFinishings", s)) == NULL)
continue;
/*
* Apply "*Option Choice" settings from the attribute value...
*/
ppd_mark_choices(ppd, attr->value);
}
}
else if (!_cups_strcasecmp(optptr->name, "APPrinterPreset"))
{
/*
* Lookup APPrinterPreset value...
*/
if ((attr = ppdFindAttr(ppd, "APPrinterPreset", optptr->value)) != NULL)
{
/*
* Apply "*Option Choice" settings from the attribute value...
*/
ppd_mark_choices(ppd, attr->value);
}
}
else if (!_cups_strcasecmp(optptr->name, "mirror"))
ppd_mark_option(ppd, "MirrorPrint", optptr->value);
else
ppd_mark_option(ppd, optptr->name, optptr->value);
ppd_debug_marked(ppd, "After...");
return (ppdConflicts(ppd) > 0);
}
/*
* 'ppdFindChoice()' - Return a pointer to an option choice.
*/
ppd_choice_t * /* O - Choice pointer or @code NULL@ */
ppdFindChoice(ppd_option_t *o, /* I - Pointer to option */
const char *choice) /* I - Name of choice */
{
int i; /* Looping var */
ppd_choice_t *c; /* Current choice */
if (!o || !choice)
return (NULL);
if (choice[0] == '{' || !_cups_strncasecmp(choice, "Custom.", 7))
choice = "Custom";
for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
if (!_cups_strcasecmp(c->choice, choice))
return (c);
return (NULL);
}
/*
* 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
*/
ppd_choice_t * /* O - Pointer to choice or @code NULL@ */
ppdFindMarkedChoice(ppd_file_t *ppd, /* I - PPD file */
const char *option) /* I - Keyword/option name */
{
ppd_choice_t key, /* Search key for choice */
*marked; /* Marked choice */
DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd, option));
if ((key.option = ppdFindOption(ppd, option)) == NULL)
{
DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL");
return (NULL);
}
marked = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key);
DEBUG_printf(("3ppdFindMarkedChoice: Returning %p(%s)...", marked,
marked ? marked->choice : "NULL"));
return (marked);
}
/*
* 'ppdFindOption()' - Return a pointer to the specified option.
*/
ppd_option_t * /* O - Pointer to option or @code NULL@ */
ppdFindOption(ppd_file_t *ppd, /* I - PPD file data */
const char *option) /* I - Option/Keyword name */
{
/*
* Range check input...
*/
if (!ppd || !option)
return (NULL);
if (ppd->options)
{
/*
* Search in the array...
*/
ppd_option_t key; /* Option search key */
strlcpy(key.keyword, option, sizeof(key.keyword));
return ((ppd_option_t *)cupsArrayFind(ppd->options, &key));
}
else
{
/*
* Search in each group...
*/
int i, j; /* Looping vars */
ppd_group_t *group; /* Current group */
ppd_option_t *optptr; /* Current option */
for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
for (j = group->num_options, optptr = group->options;
j > 0;
j --, optptr ++)
if (!_cups_strcasecmp(optptr->keyword, option))
return (optptr);
return (NULL);
}
}
/*
* 'ppdIsMarked()' - Check to see if an option is marked.
*/
int /* O - Non-zero if option is marked */
ppdIsMarked(ppd_file_t *ppd, /* I - PPD file data */
const char *option, /* I - Option/Keyword name */
const char *choice) /* I - Choice name */
{
ppd_choice_t key, /* Search key */
*c; /* Choice pointer */
if (!ppd)
return (0);
if ((key.option = ppdFindOption(ppd, option)) == NULL)
return (0);
if ((c = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) == NULL)
return (0);
return (!strcmp(c->choice, choice));
}
/*
* 'ppdMarkDefaults()' - Mark all default options in the PPD file.
*/
void
ppdMarkDefaults(ppd_file_t *ppd) /* I - PPD file record */
{
int i; /* Looping variables */
ppd_group_t *g; /* Current group */
ppd_choice_t *c; /* Current choice */
if (!ppd)
return;
/*
* Clean out the marked array...
*/
for (c = (ppd_choice_t *)cupsArrayFirst(ppd->marked);
c;
c = (ppd_choice_t *)cupsArrayNext(ppd->marked))
{
cupsArrayRemove(ppd->marked, c);
c->marked = 0;
}
/*
* Then repopulate it with the defaults...
*/
for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
ppd_defaults(ppd, g);
}
/*
* 'ppdMarkOption()' - Mark an option in a PPD file and return the number of
* conflicts.
*/
int /* O - Number of conflicts */
ppdMarkOption(ppd_file_t *ppd, /* I - PPD file record */
const char *option, /* I - Keyword */
const char *choice) /* I - Option name */
{
DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")",
ppd, option, choice));
/*
* Range check input...
*/
if (!ppd || !option || !choice)
return (0);
/*
* Mark the option...
*/
ppd_mark_option(ppd, option, choice);
/*
* Return the number of conflicts...
*/
return (ppdConflicts(ppd));
}
/*
* 'ppdFirstOption()' - Return the first option in the PPD file.
*
* Options are returned from all groups in ascending alphanumeric order.
*
* @since CUPS 1.2/OS X 10.5@
*/
ppd_option_t * /* O - First option or @code NULL@ */
ppdFirstOption(ppd_file_t *ppd) /* I - PPD file */
{
if (!ppd)
return (NULL);
else
return ((ppd_option_t *)cupsArrayFirst(ppd->options));
}
/*
* 'ppdNextOption()' - Return the next option in the PPD file.
*
* Options are returned from all groups in ascending alphanumeric order.
*
* @since CUPS 1.2/OS X 10.5@
*/
ppd_option_t * /* O - Next option or @code NULL@ */
ppdNextOption(ppd_file_t *ppd) /* I - PPD file */
{
if (!ppd)
return (NULL);
else
return ((ppd_option_t *)cupsArrayNext(ppd->options));
}
/*
* '_ppdParseOptions()' - Parse options from a PPD file.
*
* This function looks for strings of the form:
*
* *option choice ... *optionN choiceN
* property value ... propertyN valueN
*
* It stops when it finds a string that doesn't match this format.
*/
int /* O - Number of options */
_ppdParseOptions(
const char *s, /* I - String to parse */
int num_options, /* I - Number of options */
cups_option_t **options, /* IO - Options */
_ppd_parse_t which) /* I - What to parse */
{
char option[PPD_MAX_NAME * 2 + 1], /* Current option/property */
choice[PPD_MAX_NAME], /* Current choice/value */
*ptr; /* Pointer into option or choice */
if (!s)
return (num_options);
/*
* Read all of the "*Option Choice" and "property value" pairs from the
* string, add them to an options array as we go...
*/
while (*s)
{
/*
* Skip leading whitespace...
*/
while (_cups_isspace(*s))
s ++;
/*
* Get the option/property name...
*/
ptr = option;
while (*s && !_cups_isspace(*s) && ptr < (option + sizeof(option) - 1))
*ptr++ = *s++;
if (ptr == s || !_cups_isspace(*s))
break;
*ptr = '\0';
/*
* Get the choice...
*/
while (_cups_isspace(*s))
s ++;
if (!*s)
break;
ptr = choice;
while (*s && !_cups_isspace(*s) && ptr < (choice + sizeof(choice) - 1))
*ptr++ = *s++;
if (*s && !_cups_isspace(*s))
break;
*ptr = '\0';
/*
* Add it to the options array...
*/
if (option[0] == '*' && which != _PPD_PARSE_PROPERTIES)
num_options = cupsAddOption(option + 1, choice, num_options, options);
else if (option[0] != '*' && which != _PPD_PARSE_OPTIONS)
num_options = cupsAddOption(option, choice, num_options, options);
}
return (num_options);
}
#ifdef DEBUG
/*
* 'ppd_debug_marked()' - Output the marked array to stdout...
*/
static void
ppd_debug_marked(ppd_file_t *ppd, /* I - PPD file data */
const char *title) /* I - Title for list */
{
ppd_choice_t *c; /* Current choice */
DEBUG_printf(("2cupsMarkOptions: %s", title));
for (c = (ppd_choice_t *)cupsArrayFirst(ppd->marked);
c;
c = (ppd_choice_t *)cupsArrayNext(ppd->marked))
DEBUG_printf(("2cupsMarkOptions: %s=%s", c->option->keyword, c->choice));
}
#endif /* DEBUG */
/*
* 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
*/
static void
ppd_defaults(ppd_file_t *ppd, /* I - PPD file */
ppd_group_t *g) /* I - Group to default */
{
int i; /* Looping var */
ppd_option_t *o; /* Current option */
ppd_group_t *sg; /* Current sub-group */
for (i = g->num_options, o = g->options; i > 0; i --, o ++)
if (_cups_strcasecmp(o->keyword, "PageRegion") != 0)
ppdMarkOption(ppd, o->keyword, o->defchoice);
for (i = g->num_subgroups, sg = g->subgroups; i > 0; i --, sg ++)
ppd_defaults(ppd, sg);
}
/*
* 'ppd_mark_choices()' - Mark one or more option choices from a string.
*/
static void
ppd_mark_choices(ppd_file_t *ppd, /* I - PPD file */
const char *s) /* I - "*Option Choice ..." string */
{
int i, /* Looping var */
num_options; /* Number of options */
cups_option_t *options, /* Options */
*option; /* Current option */
if (!s)
return;
options = NULL;
num_options = _ppdParseOptions(s, 0, &options, 0);
for (i = num_options, option = options; i > 0; i --, option ++)
ppd_mark_option(ppd, option->name, option->value);
cupsFreeOptions(num_options, options);
}
/*
* 'ppd_mark_option()' - Quick mark an option without checking for conflicts.
*/
static void
ppd_mark_option(ppd_file_t *ppd, /* I - PPD file */
const char *option, /* I - Option name */
const char *choice) /* I - Choice name */
{
int i, j; /* Looping vars */
ppd_option_t *o; /* Option pointer */
ppd_choice_t *c, /* Choice pointer */
*oldc, /* Old choice pointer */
key; /* Search key for choice */
struct lconv *loc; /* Locale data */
DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")",
ppd, option, choice));
/*
* AP_D_InputSlot is the "default input slot" on MacOS X, and setting
* it clears the regular InputSlot choices...
*/
if (!_cups_strcasecmp(option, "AP_D_InputSlot"))
{
cupsArraySave(ppd->options);
if ((o = ppdFindOption(ppd, "InputSlot")) != NULL)
{
key.option = o;
if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL)
{
oldc->marked = 0;
cupsArrayRemove(ppd->marked, oldc);
}
}
cupsArrayRestore(ppd->options);
}
/*
* Check for custom options...
*/
cupsArraySave(ppd->options);
o = ppdFindOption(ppd, option);
cupsArrayRestore(ppd->options);
if (!o)
return;
loc = localeconv();
if (!_cups_strncasecmp(choice, "Custom.", 7))
{
/*
* Handle a custom option...
*/
if ((c = ppdFindChoice(o, "Custom")) == NULL)
return;
if (!_cups_strcasecmp(option, "PageSize"))
{
/*
* Handle custom page sizes...
*/
ppdPageSize(ppd, choice);
}
else
{
/*
* Handle other custom options...
*/
ppd_coption_t *coption; /* Custom option */
ppd_cparam_t *cparam; /* Custom parameter */
char *units; /* Custom points units */
if ((coption = ppdFindCustomOption(ppd, option)) != NULL)
{
if ((cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params)) == NULL)
return;
switch (cparam->type)
{
case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_REAL :
cparam->current.custom_real = (float)_cupsStrScand(choice + 7,
NULL, loc);
break;
case PPD_CUSTOM_POINTS :
cparam->current.custom_points = (float)_cupsStrScand(choice + 7,
&units,
loc);
if (units)
{
if (!_cups_strcasecmp(units, "cm"))
cparam->current.custom_points *= 72.0f / 2.54f;
else if (!_cups_strcasecmp(units, "mm"))
cparam->current.custom_points *= 72.0f / 25.4f;
else if (!_cups_strcasecmp(units, "m"))
cparam->current.custom_points *= 72.0f / 0.0254f;
else if (!_cups_strcasecmp(units, "in"))
cparam->current.custom_points *= 72.0f;
else if (!_cups_strcasecmp(units, "ft"))
cparam->current.custom_points *= 12.0f * 72.0f;
}
break;
case PPD_CUSTOM_INT :
cparam->current.custom_int = atoi(choice + 7);
break;
case PPD_CUSTOM_PASSCODE :
case PPD_CUSTOM_PASSWORD :
case PPD_CUSTOM_STRING :
if (cparam->current.custom_string)
_cupsStrFree(cparam->current.custom_string);
cparam->current.custom_string = _cupsStrAlloc(choice + 7);
break;
}
}
}
/*
* Make sure that we keep the option marked below...
*/
choice = "Custom";
}
else if (choice[0] == '{')
{
/*
* Handle multi-value custom options...
*/
ppd_coption_t *coption; /* Custom option */
ppd_cparam_t *cparam; /* Custom parameter */
char *units; /* Custom points units */
int num_vals; /* Number of values */
cups_option_t *vals, /* Values */
*val; /* Value */
if ((c = ppdFindChoice(o, "Custom")) == NULL)
return;
if ((coption = ppdFindCustomOption(ppd, option)) != NULL)
{
num_vals = cupsParseOptions(choice, 0, &vals);
for (i = 0, val = vals; i < num_vals; i ++, val ++)
{
if ((cparam = ppdFindCustomParam(coption, val->name)) == NULL)
continue;
switch (cparam->type)
{
case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_REAL :
cparam->current.custom_real = (float)_cupsStrScand(val->value,
NULL, loc);
break;
case PPD_CUSTOM_POINTS :
cparam->current.custom_points = (float)_cupsStrScand(val->value,
&units,
loc);
if (units)
{
if (!_cups_strcasecmp(units, "cm"))
cparam->current.custom_points *= 72.0f / 2.54f;
else if (!_cups_strcasecmp(units, "mm"))
cparam->current.custom_points *= 72.0f / 25.4f;
else if (!_cups_strcasecmp(units, "m"))
cparam->current.custom_points *= 72.0f / 0.0254f;
else if (!_cups_strcasecmp(units, "in"))
cparam->current.custom_points *= 72.0f;
else if (!_cups_strcasecmp(units, "ft"))
cparam->current.custom_points *= 12.0f * 72.0f;
}
break;
case PPD_CUSTOM_INT :
cparam->current.custom_int = atoi(val->value);
break;
case PPD_CUSTOM_PASSCODE :
case PPD_CUSTOM_PASSWORD :
case PPD_CUSTOM_STRING :
if (cparam->current.custom_string)
_cupsStrFree(cparam->current.custom_string);
cparam->current.custom_string = _cupsStrRetain(val->value);
break;
}
}
cupsFreeOptions(num_vals, vals);
}
}
else
{
for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
if (!_cups_strcasecmp(c->choice, choice))
break;
if (!i)
return;
}
/*
* Option found; mark it and then handle unmarking any other options.
*/
if (o->ui != PPD_UI_PICKMANY)
{
/*
* Unmark all other choices...
*/
if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, c)) != NULL)
{
oldc->marked = 0;
cupsArrayRemove(ppd->marked, oldc);
}
if (!_cups_strcasecmp(option, "PageSize") || !_cups_strcasecmp(option, "PageRegion"))
{
/*
* Mark current page size...
*/
for (j = 0; j < ppd->num_sizes; j ++)
ppd->sizes[j].marked = !_cups_strcasecmp(ppd->sizes[j].name,
choice);
/*
* Unmark the current PageSize or PageRegion setting, as
* appropriate...
*/
cupsArraySave(ppd->options);
if (!_cups_strcasecmp(option, "PageSize"))
{
if ((o = ppdFindOption(ppd, "PageRegion")) != NULL)
{
key.option = o;
if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL)
{
oldc->marked = 0;
cupsArrayRemove(ppd->marked, oldc);
}
}
}
else
{
if ((o = ppdFindOption(ppd, "PageSize")) != NULL)
{
key.option = o;
if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL)
{
oldc->marked = 0;
cupsArrayRemove(ppd->marked, oldc);
}
}
}
cupsArrayRestore(ppd->options);
}
else if (!_cups_strcasecmp(option, "InputSlot"))
{
/*
* Unmark ManualFeed option...
*/
cupsArraySave(ppd->options);
if ((o = ppdFindOption(ppd, "ManualFeed")) != NULL)
{
key.option = o;
if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL)
{
oldc->marked = 0;
cupsArrayRemove(ppd->marked, oldc);
}
}
cupsArrayRestore(ppd->options);
}
else if (!_cups_strcasecmp(option, "ManualFeed") &&
!_cups_strcasecmp(choice, "True"))
{
/*
* Unmark InputSlot option...
*/
cupsArraySave(ppd->options);
if ((o = ppdFindOption(ppd, "InputSlot")) != NULL)
{
key.option = o;
if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL)
{
oldc->marked = 0;
cupsArrayRemove(ppd->marked, oldc);
}
}
cupsArrayRestore(ppd->options);
}
}
c->marked = 1;
cupsArrayAdd(ppd->marked, c);
}
/*
* End of "$Id: mark.c 10996 2013-05-29 11:51:34Z msweet $".
*/
|