Author: stepan Date: 2006-10-30 12:59:18 +0100 (Mon, 30 Oct 2006) New Revision: 105
Modified: fcode-utils/detok/addfcodes.c fcode-utils/detok/dictionary.c Log: detok 1.0.2 merge part 3
Modified: fcode-utils/detok/addfcodes.c =================================================================== --- fcode-utils/detok/addfcodes.c 2006-10-30 11:31:16 UTC (rev 104) +++ fcode-utils/detok/addfcodes.c 2006-10-30 11:59:18 UTC (rev 105) @@ -46,6 +46,10 @@ * Identified this need when working with in-house code, * which uses some custom functions. This solution * is (hoped to be) general enough to cover all cases. + * Mon, 16 Oct 2006 by David L. Paktor + * Add "special function" words. So far, only one added: + * double-literal Infrastructure will support + * adding others as needed. * **************************************************************************** */
@@ -58,6 +62,21 @@ * **************************************************************************** */
+ +/* ************************************************************************** + * + * Global Variables Exported : + * + * For "special function" identification, we will need to + * export Global Variables, each of which is a pointer + * to the address of the FCode field of the entry in + * the Special Functions List for that function. + * + * Variable Associated Name + * double_lit_code double-literal + * + **************************************************************************** */ + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -73,6 +92,8 @@ * vfc_remainder Remainder of Vendor-FCodes buffer to be scanned * vfc_line_no Number of current line in Vendor-FCodes buffer * vfc_buf_end Pointer to end of Vendor-FCodes buffer + * spcl_func_list List of reserved Special Function names + * spcl_func_count Number of reserved Special Function names * **************************************************************************** */
@@ -81,6 +102,22 @@ static int vfc_line_no = 0; static char *vfc_buf_end;
+/* Special Functions List */ +/* Initial fcode-field value of -1 guarantees they won't be used */ +token_t spcl_func_list[] = { + TOKEN_ENTRY( -1, "double(lit)" ), /* Entry [0] */ +}; + +static const int spcl_func_count = (sizeof(spcl_func_list)/sizeof(token_t)) ; + +/* Global Variables for "special function" identification */ +/* Each is a pointer to the FCode field of the entry in + * the Special Functions List for that function. + */ + +u16 *double_lit_code = &spcl_func_list[0].fcode; + + /* ************************************************************************** * * Function name: skip_whitespace @@ -231,11 +268,19 @@ * after the name will be ignored, so an extra "comment" * is permitted. The FCode number must be in hex, with * an optional leading 0x or 0X For example: 0X407 - * The valid range is 0x010 to 0x7ff. Numbers above 0x800 - * infringe upon the are reserved for FCodes generated - * by the tokenization process. + * The valid range for the FCode numbers is 0x010 to 0x7ff. + * Numbers above 0x800 infringe upon the area reserved + * for FCodes generated by the tokenization process. * Numbers already in use will be ignored. A Message will be * printed even if the name matches the one on the line. + * Names may not be longer than 31 characters. + * Certain names will be reserved for special functions. + * Those names will be entered in the detok_table + * with a value of -1 and again in the static + * table associated with this function, below, to + * supply the variable that will be used to match + * the name with the special function. + * * **************************************************************************** */
@@ -267,6 +312,13 @@ char *lookup_result; char *fc_name_cpy;
+ /* For each line of input, we need to check that we have + * two strings, one of which is the number and the + * second of which is the name. We will check for + * the various formats allowed for the number + */ + + /* Start with a lower-case 0x */ scan_result = sscanf(current_vfc_line, "0x%x %32s", &vs_fc_number, vs_fc_name);
@@ -315,6 +367,28 @@ continue; }
+ /* Check if the name is on the "Special Functions List" */ + { + bool found_spf = FALSE; + int indx; + for (indx = 0; indx < spcl_func_count; indx++) { + if ( strcmp( vs_fc_name, spcl_func_list[indx].name) == 0 ) { + char strbuf[64]; + found_spf = TRUE; + spcl_func_list[indx].fcode = vs_fc_number; + link_token( &spcl_func_list[indx]); + added_fc_count++; + sprintf( strbuf, "Added Special Function FCode " + "number 0x%03x, name %s\n", vs_fc_number, vs_fc_name); + printremark( strbuf); + break; + } + } + + if (found_spf) + continue; + } + /* We've passed all the tests! */ fc_name_cpy = strdup(vs_fc_name); add_token((u16) vs_fc_number, fc_name_cpy); @@ -323,11 +397,10 @@ }
if (verbose) { - char *strbfr = malloc(85); + char strbfr[32]; sprintf(strbfr, "Added %d FCode numbers\n", added_fc_count); printremark(strbfr); - free(strbfr); }
close_stream();
Modified: fcode-utils/detok/dictionary.c =================================================================== --- fcode-utils/detok/dictionary.c 2006-10-30 11:31:16 UTC (rev 104) +++ fcode-utils/detok/dictionary.c 2006-10-30 11:59:18 UTC (rev 105) @@ -37,13 +37,6 @@ #include "detok.h"
bool check_tok_seq = TRUE; - -typedef struct token { - char *name; - u16 fcode; - struct token *next; -} token_t; -#define TOKEN_ENTRY(num, name) { name, (u16)num, (token_t *)NULL } static token_t *dictionary; /* Initialize dynamically to accommodate AIX */
static char *fcerror = "ferror"; @@ -52,7 +45,7 @@ { token_t *curr;
- for (curr = dictionary; curr != NULL; curr = curr->next) + for (curr = dictionary; curr != NULL; curr = curr->prev) if (curr->fcode == number) break;
@@ -64,6 +57,33 @@
/* ************************************************************************** * + * Function name: link_token + * Synopsis: Simply link a ready-made token-table entry to + * the dictionary, without side-effects. + * + * Inputs: + * Parameters: + * curr_token The token-table entry to link + * Local Static Variables: + * dictionary Pointer to the "tail" of the + * FCode-Tokens vocabulary. + * + * Outputs: + * Returned Value: NONE + * Local Static Variables: + * dictionary Updated to point to the new entry. + * + **************************************************************************** */ + +void link_token( token_t *curr_token) +{ + curr_token->prev = dictionary; + + dictionary = curr_token; +} + +/* ************************************************************************** + * * Function name: add_token * Synopsis: Add an entry to the FCode-Tokens vocabulary. * @@ -72,8 +92,6 @@ * number Numeric value of the FCode token * name Name of the function to display * Global/Static Variables: - * dictionary Pointer to the "tail" of the - * FCode-Tokens vocabulary. * check_tok_seq TRUE = "Check Token Sequence" * A retro-fit to accommodate * adding Vendor FCodes @@ -81,7 +99,6 @@ * Outputs: * Returned Value: NONE * Global/Static Variables: - * dictionary Updated to point to the new entry. * last_defined_token Updated to the given FCode token * Memory Allocated * For the new entry. @@ -116,11 +133,10 @@ exit(-ENOMEM); }
- curr->next = dictionary; - curr->fcode = number; curr->name = name; + curr->fcode=number;
- dictionary = curr; + link_token( curr);
if (check_tok_seq) { /* Error-check, but not for first time. */ @@ -543,7 +559,7 @@ dictionary_reset_position = dictionary;
for (indx = 1; indx < dictionary_indx_max; indx++) { - detok_table[indx].next = &detok_table[indx - 1]; + detok_table[indx].prev = &detok_table[indx - 1]; } }
@@ -553,7 +569,7 @@
next_t = dictionary; while (next_t != dictionary_reset_position) { - next_t = dictionary->next; + next_t = dictionary->prev; free(dictionary->name); free(dictionary); dictionary = next_t;