| 58 | */ |
| 59 | |
| 60 | int /* O - Number of options */ |
| 61 | cupsAddOption(const char *name, /* I - Name of option */ |
| 62 | const char *value, /* I - Value of option */ |
| 63 | int num_options,/* I - Number of options */ |
| 64 | cups_option_t **options) /* IO - Pointer to options */ |
| 65 | { |
| 66 | cups_option_t *temp; /* Pointer to new option */ |
| 67 | int insert, /* Insertion point */ |
| 68 | diff; /* Result of search */ |
| 69 | |
| 70 | |
| 71 | DEBUG_printf(("2cupsAddOption(name=\"%s\", value=\"%s\", num_options=%d, options=%p)", name, value, num_options, (void *)options)); |
| 72 | |
| 73 | if (!name || !name[0] || !value || !options || num_options < 0) |
| 74 | { |
| 75 | DEBUG_printf(("3cupsAddOption: Returning %d", num_options)); |
| 76 | return (num_options); |
| 77 | } |
| 78 | |
| 79 | if (!_cups_strcasecmp(name, "cupsPrintQuality")) |
| 80 | num_options = cupsRemoveOption("print-quality", num_options, options); |
| 81 | else if (!_cups_strcasecmp(name, "print-quality")) |
| 82 | num_options = cupsRemoveOption("cupsPrintQuality", num_options, options); |
| 83 | |
| 84 | /* |
| 85 | * Look for an existing option with the same name... |
| 86 | */ |
| 87 | |
| 88 | if (num_options == 0) |
| 89 | { |
| 90 | insert = 0; |
| 91 | diff = 1; |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | insert = cups_find_option(name, num_options, *options, num_options - 1, |
| 96 | &diff); |
| 97 | |
| 98 | if (diff > 0) |
| 99 | insert ++; |
| 100 | } |
| 101 | |
| 102 | if (diff) |
| 103 | { |
| 104 | /* |
| 105 | * No matching option name... |
| 106 | */ |
| 107 | |
| 108 | DEBUG_printf(("4cupsAddOption: New option inserted at index %d...", |
| 109 | insert)); |
| 110 | |
| 111 | if (num_options == 0) |
| 112 | temp = (cups_option_t *)malloc(sizeof(cups_option_t)); |
| 113 | else |
| 114 | temp = (cups_option_t *)realloc(*options, sizeof(cups_option_t) * (size_t)(num_options + 1)); |
| 115 | |
| 116 | if (!temp) |
| 117 | { |