/******************************************************************************* Description : Get the next element to write to Result : Returns the element to write to, or NULL in case of error Arguments : *pFifo - Pointer to the Fifo structure Remarks : Error occurs if the write pointer reaches the read pointer, meaning the fifo if full and would otherwise overwrite the next element. *******************************************************************************/ void* Fifo_writeElement (FIFO *pFifo) { void* ret = NULL; if (Fifo_isFull(pFifo)) return NULL; else { /* get the next entry of the Fifo */ ret = pFifo->pWrite; INCREMENT_INDEX(pFifo->pWrite); pFifo->count++; return ret; } }
/******************************************************************************* Description : Get the next element to read from Result : Returns the element to read from, or NULL if no element available or an error occured Arguments : *pFifo - Pointer to the Fifo structure Remarks : Error occurs if fifo is empty *******************************************************************************/ void* Fifo_readElement (FIFO *pFifo) { void *ret = NULL; if (pFifo->count == 0) { return NULL; } ret = pFifo->pRead; INCREMENT_INDEX(pFifo->pRead); pFifo->count--; return ret; }
/** Get the next element to read from \param *pFifo - Pointer to the Fifo structure \return Returns the element to read from, or IFX_NULL if no element available or an error occured \remark Error occurs if fifo is empty */ IFX_void_t* Fifo_readElement (FIFO *pFifo) { IFX_void_t *ret = IFX_NULL; if (pFifo->count == 0) { return IFX_NULL; } ret = pFifo->pRead; INCREMENT_INDEX(pFifo->pRead); pFifo->count--; return ret; }
/* * 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; }