/* Delete any files that are named as -replace "resources". */ int process_replaces(config_t * pconf) { char bufname[MAX_STR]; int i; for (i = 0; i < pconf->replaces.count; ++i) { int j; strcpy(bufname, pconf->replaces.items[i].str); /* See if the file being replaced was included. */ dev_file_name(bufname); for (j = 0; j < pconf->file_names.count; ++j) { const char *fname = pconf->file_names.items[j].str; if (!strcmp(fname, bufname)) { if (pconf->debug) printf("Replacing file %s.\n", fname); /* Delete all resources associated with this file. */ { int rn; for (rn = 0; rn < NUM_RESOURCE_LISTS; ++rn) { string_item_t *items = pconf->lists.indexed[rn].items; int count = pconf->lists.indexed[rn].count; int tn; for (tn = 0; tn < count; ++tn) { if (items[tn].file_index == j) { /* * Delete the item. Since we haven't sorted * the items yet, just replace this item * with the last one, but make sure we don't * miss scanning it. */ if (pconf->debug) printf("Replacing %s %s.\n", pconf->lists.indexed[rn].list_name, items[tn].str); items[tn--] = items[--count]; } } pconf->lists.indexed[rn].count = count; } } pconf->file_names.items[j].str = ""; break; } } } /* Don't process the replaces again. */ pconf->replaces.count = 0; return 0; }
/* Add an entry to a configuration. Return its uniq_mode_t. */ int add_entry(config_t * pconf, char *category, const char *item, int file_index) { if (item[0] == '-' && islower(item[1])) { /* set category */ strcpy(category, item + 1); return 0; } else { /* add to current category */ char str[MAX_STR]; char templat[MAX_TEMPLAT + 1]; const char *pat = 0; string_list_t *list = &pconf->lists.named.resources; if (pconf->debug) printf("Adding %s %s;\n", category, item); /* Handle a few resources specially; just queue the rest. */ switch (category[0]) { #define IS_CAT(str) !strcmp(category, str) case 'c': if (!IS_CAT("comp")) goto err; pat = "compositor_(%scomposite_%%s_type)"; list = &pconf->lists.named.compositors; goto pre; case 'd': if (IS_CAT("dev")) pat = "device_(%s%%s_device)"; else if (IS_CAT("dev2")) pat = "device2_(%s%%s_device)"; else goto err; list = &pconf->lists.named.devs; pre: sprintf(templat, pat, pconf->name_prefix); pat = templat; break; case 'e': if (IS_CAT("emulator")) { sprintf(str, "emulator_(\"%s\",%u)", item, (uint)strlen(item)); item = str; break; } goto err; case 'f': if (IS_CAT("font")) { list = &pconf->lists.named.fonts; break; } else if (IS_CAT("functiontype")) { pat = "function_type_(%%s,%sbuild_function_%%s)"; } else if (IS_CAT("fapi")) { pat = "fapi_(%s%%s_init)"; } else goto err; goto pre; case 'h': if (IS_CAT("halftone")) { pat = "halftone_(%sdht_%%s)"; } else goto err; goto pre; case 'i': if (IS_CAT("imageclass")) { list = &pconf->lists.named.sorted_resources; pat = "image_class_(%simage_class_%%s)"; } else if (IS_CAT("imagetype")) { pat = "image_type_(%%s,%simage_type_%%s)"; } else if (IS_CAT("include")) { strcpy(str, item); dev_file_name(str); return read_dev(pconf, str); } else if (IS_CAT("init")) { pat = "init_(%s%%s_init)"; } else if (IS_CAT("iodev")) { pat = "io_device_(%siodev_%%s)"; } else goto err; goto pre; case 'l': if (IS_CAT("lib")) { list = &pconf->lists.named.libs; break; } else if (IS_CAT("libpath")) { list = &pconf->lists.named.libpaths; break; } else if (IS_CAT("link")) { list = &pconf->lists.named.links; break; } goto err; case 'o': if (IS_CAT("obj")) { list = &pconf->lists.named.objs; strncpy(templat, pconf->file_prefix, MAX_TEMPLAT); strcat(templat, "%s"); pat = templat; break; } if (IS_CAT("oper")) { pat = "oper_(%s_op_defs)"; break; } goto err; case 'p': if (IS_CAT("ps")) { sprintf(str, "psfile_(\"%s.ps\",%u)", item, (uint)(strlen(item) + 3)); item = str; break; } else if (IS_CAT("plugin")) { pat = "plugin_(%s%%s_instantiate)"; goto pre; } goto err; case 'r': if (IS_CAT("replace")) { list = &pconf->replaces; break; } goto err; #undef IS_CAT default: err: fprintf(stderr, "Definition not recognized: %s %s.\n", category, item); exit(1); } if (pat) { sprintf(str, pat, item, item); assert(strlen(str) < MAX_STR); add_item(list, str, file_index); } else add_item(list, item, file_index); return list->mode; } }