/* * Read table from stdin, without assuming options section is sorted. */ static void read_table(void) { char line[512]; char *option_lines[MAX_OPTIONS]; int option_line_count = 0; char *p; int section = 0; int i = num_options; int j; strcpy(options[i].flag, "O_Unrecognized"); options[i].internal = TRUE; strcpy(options[i].name, ""); options[i].implies = NULL; i++; /* Find beginning of OPTIONS section. */ while (get_line(line) != EOF) { if (EMPTY(line)) continue; else if (line[0] == '%' && line[1] != '%') continue; else if (strcmp(line, "%%% OPTIONS") == 0) { section = OPTIONS; break; } else { internal_error("Unexpected line: %s", line); } } /* Read and sort the OPTIONS section. */ if (section != OPTIONS) { internal_error("OPTIONS section not found"); } option_line_count = 0; while (get_line(line) != EOF) { char* s; if (EMPTY(line)) continue; else if (line[0] == '%' && line[1] != '%') continue; else if (strncmp(line, "%%% ", 4) == 0) { if (strcmp(line, "%%% OPTIONS") == 0) internal_error("OPTIONS section seen twice"); else if (strcmp(line, "%%% COMBINATIONS") == 0) { section = COMBINATIONS; break; } else { internal_error("UNKNOWN SECTION: %s", line); } } s = malloc(strlen(line) + 1); if (s == NULL) internal_error("memory allocation failed"); strcpy(s, line); option_lines[option_line_count] = s; INCREMENT_INDEX(option_line_count, MAX_OPTIONS); } qsort(option_lines, option_line_count, sizeof(char*), reverse_strcmp); /* Process the option lines */ for (j = 0; j < option_line_count; ++j) { /* <name> <action> <langs> <phases> <implies> */ p = strtok(option_lines[j], SPACE); if (*p == 'I') { options[i].internal = TRUE; p++; } else options[i].internal = FALSE; if (*p != '-') internal_error("MISSING - : %s", p); options[i].syntax = set_option_name(options[i].name, p, &options[i].num_letters); if (options[i].syntax == normal && strlen(options[i].name) == 2) options[i].syntax = oneletter; set_flag_name(&options[i]); p = strtok(NULL, SPACE); store_string(options[i].action, p, ";"); if (strncmp(p, "toggle", 6) == 0) options[i].toggle = TRUE; else options[i].toggle = FALSE; if (!table_for_phase) { p = strtok(NULL, SPACE); options[i].languages = create_lang_field(p); if ( options[i].internal ) { options[i].languages |= get_language_mask ( L_internal ); } p = strtok(NULL, SPACE); options[i].phases = create_phase_field(p); } options[i].implies = create_option_list(&p,i); options[i].help = create_help_msg(p); INCREMENT_INDEX(i, MAX_OPTIONS); } check_dups(); /* Read and process the COMBINATIONS section */ if (section != COMBINATIONS) { internal_error("COMBINATIONS section not found"); } while (get_line(line) != EOF) { if (EMPTY(line)) continue; else if (line[0] == '%' && line[1] != '%') continue; else if (strncmp(line, "%%% ", 4) == 0) { internal_error("Unexpected sections line: %s", line); } else { /* <name> <action> <implies> */ if (line[0] != '\"') internal_error("MISSING \" : %s", line); p = strtok(line+1, DQUOTE); set_option_name(options[i].name, p, &options[i].num_letters); options[i].syntax = combo; set_flag_name(&options[i]); p = strtok(NULL, SPACE); store_string(options[i].action, p, "OKAY"); options[i].implies = create_option_list(&p,i); options[i].languages = ALL_LANGS; options[i].phases = ALL_PHASES; options[i].help = NULL; INCREMENT_INDEX(i, MAX_OPTIONS); } } num_options = i; }
/* * Read table from stdin, without assuming options section is sorted. */ static void read_table(void) { char line[512]; char line2[512]; char *option_lines[MAX_OPTIONS]; int option_line_count = 0; char *p; int section = 0; int i = num_options; int j; strcpy(options[i].flag, "O_Unrecognized"); options[i].internal = TRUE; strcpy(options[i].name, ""); options[i].implies = NULL; i++; option_line_count = 0; while (get_line(line) != EOF) { char* s; if (EMPTY(line)) continue; else if (line[0] == '%') continue; else if (line[0] == ' ' && line[1] == NIL) continue; else if (line[0] == '\t') internal_error("unexpected line (help msg?): %s", line); else if (line[0] != '-' && line[0] != 'I') internal_error("unexpected line: [%s]", line); if (get_line(line2) == EOF) internal_error("unexpected EOF for line2"); s = malloc(strlen(line) + strlen(line2) + 4); if (s == NULL) internal_error("memory allocation failed"); sprintf(s, "%s %c %s", line, FIELD_DIVIDER, line2); option_lines[option_line_count] = s; INCREMENT_INDEX(option_line_count, MAX_OPTIONS); } qsort(option_lines, option_line_count, sizeof(char*), reverse_strcmp); /* Process the option lines */ for (j = 0; j < option_line_count; ++j) { /* <name> <action> <langs> <phases> <implies> */ p = strtok(option_lines[j], SPACE); if (*p == 'I') { options[i].internal = TRUE; p++; } else options[i].internal = FALSE; if (*p != '-') internal_error("MISSING - : %s", p); options[i].syntax = set_option_name(options[i].name, p, &options[i].num_letters); if (options[i].syntax == normal && strlen(options[i].name) == 2) options[i].syntax = oneletter; set_flag_name(&options[i]); p = strtok(NULL, SPACE); store_string(options[i].action, p, ";"); if (strncmp(p, "toggle", 6) == 0) options[i].toggle = TRUE; else options[i].toggle = FALSE; if (!table_for_phase) { p = strtok(NULL, SPACE); options[i].languages = create_lang_field(p); if ( options[i].internal ) { options[i].languages |= get_language_mask ( L_internal ); } p = strtok(NULL, SPACE); options[i].phases = create_phase_field(p); } options[i].implies = create_option_list(&p,i); options[i].help = create_help_msg(p); INCREMENT_INDEX(i, MAX_OPTIONS); } check_dups(); num_options = i; }