From 498c79a61f667a0dc42a8e0c6a8b9e7aaa6ffc6c Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Tue, 26 Nov 2019 22:32:00 -0800 Subject: [PATCH 1/4] Convert fcode-utils to Linux kernel indentation Signed-off-by Stefan Reinauer --- detok/addfcodes.c | 39 +- detok/addfcodes.h | 3 +- detok/decode.c | 39 +- detok/detok.c | 19 +- detok/detok.h | 6 +- detok/dictionary.c | 21 +- detok/pcihdr.c | 22 +- detok/printformats.c | 6 +- detok/stream.c | 11 +- detok/stream.h | 3 +- romheaders/romheaders.c | 153 +- shared/classcodes.c | 456 +++-- shared/pcihdr.h | 42 +- shared/types.h | 11 +- toke/clflags.c | 569 +++--- toke/clflags.h | 16 +- toke/conditl.c | 386 ++-- toke/conditl.h | 10 +- toke/devnode.c | 308 ++- toke/devnode.h | 23 +- toke/dictionary.c | 1643 ++++++++-------- toke/dictionary.h | 266 +-- toke/emit.c | 353 ++-- toke/emit.h | 33 +- toke/errhandler.c | 548 +++--- toke/errhandler.h | 37 +- toke/flowcontrol.c | 782 ++++---- toke/flowcontrol.h | 43 +- toke/macros.c | 245 ++- toke/macros.h | 17 +- toke/nextfcode.c | 423 ++--- toke/nextfcode.h | 16 +- toke/parselocals.c | 492 +++-- toke/parselocals.h | 14 +- toke/scanner.c | 3926 ++++++++++++++++++--------------------- toke/scanner.h | 98 +- toke/stack.c | 175 +- toke/stack.h | 4 +- toke/stream.c | 1004 +++++----- toke/stream.h | 24 +- toke/strsubvocab.c | 60 +- toke/strsubvocab.h | 19 +- toke/ticvocab.c | 263 ++- toke/ticvocab.h | 202 +- toke/toke.c | 183 +- toke/toke.h | 4 +- toke/tokzesc.c | 345 ++-- toke/tokzesc.h | 10 +- toke/tracesyms.c | 458 +++-- toke/tracesyms.h | 24 +- toke/usersymbols.c | 182 +- toke/usersymbols.h | 7 +- toke/vocabfuncts.h | 49 +- 53 files changed, 6683 insertions(+), 7409 deletions(-) diff --git a/detok/addfcodes.c b/detok/addfcodes.c index 35f1656..1d884e6 100644 --- a/detok/addfcodes.c +++ b/detok/addfcodes.c @@ -53,7 +53,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Global Variables Imported @@ -62,7 +61,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Global Variables Exported : @@ -104,11 +102,11 @@ static u8 *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] */ +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)) ; +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 @@ -117,7 +115,6 @@ static const int spcl_func_count = (sizeof(spcl_func_list)/sizeof(token_t)) ; u16 *double_lit_code = &spcl_func_list[0].fcode; - /* ************************************************************************** * * Function name: skip_whitespace @@ -174,7 +171,8 @@ static bool get_next_vfc_line(void) bool retval = FALSE; /* TRUE = not at end yet */ while (vfc_remainder < vfc_buf_end) { current_vfc_line = (char *)vfc_remainder; - vfc_remainder = (u8 *)strchr((const char *)current_vfc_line, '\n'); + vfc_remainder = + (u8 *) strchr((const char *)current_vfc_line, '\n'); *vfc_remainder = 0; vfc_remainder++; vfc_line_no++; @@ -332,8 +330,7 @@ bool add_fcodes_from_list(char *vf_file_name) } if (scan_result != 2) { /* That's it... */ - char *strbfr = - malloc(strlen(current_vfc_line) + 65); + char *strbfr = malloc(strlen(current_vfc_line) + 65); vfc_splash(vf_file_name); sprintf(strbfr, "Line #%d, invalid format. Ignoring: %s\n", @@ -372,20 +369,25 @@ bool add_fcodes_from_list(char *vf_file_name) 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 ) { + 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]); + 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); + sprintf(strbuf, + "Added Special Function FCode " + "number 0x%03x, name %s\n", + vs_fc_number, vs_fc_name); + printremark(strbuf); break; } } - if (found_spf) + if (found_spf) continue; } @@ -397,9 +399,8 @@ bool add_fcodes_from_list(char *vf_file_name) } if (verbose) { - char strbfr[32]; - sprintf(strbfr, - "Added %d FCode numbers\n", added_fc_count); + char strbfr[32]; + sprintf(strbfr, "Added %d FCode numbers\n", added_fc_count); printremark(strbfr); } diff --git a/detok/addfcodes.h b/detok/addfcodes.h index 27b136d..bb6f38c 100644 --- a/detok/addfcodes.h +++ b/detok/addfcodes.h @@ -46,7 +46,6 @@ /* For "special function" identification */ extern u16 *double_lit_code; - /* ************************************************************************** * * * Function Prototypes / Functions Exported: @@ -55,4 +54,4 @@ extern u16 *double_lit_code; bool add_fcodes_from_list(char *vf_file_name); -#endif /* _DETOK_VSFCODES_H */ +#endif /* _DETOK_VSFCODES_H */ diff --git a/detok/decode.c b/detok/decode.c index 39a52de..615afd3 100644 --- a/detok/decode.c +++ b/detok/decode.c @@ -126,7 +126,7 @@ static void pretty_print_string(void) static void decode_lines(void) { if (show_linenumbers) { - printf("%6d: ",show_offsets ? token_streampos : linenum++); + printf("%6d: ", show_offsets ? token_streampos : linenum++); } } @@ -195,7 +195,6 @@ static void output_token_name(void) return; } - tname = lookup_token(fcode); printf("%s ", tname); @@ -239,7 +238,6 @@ static void output_token(void) output_token_name(); } - /* ************************************************************************** * * Function name: decode_offset @@ -330,8 +328,7 @@ static s16 decode_offset(void) if (offs == 0) { printremark("Error: Unresolved offset."); } else { - printremark - ("Error: Invalid offset. Ignoring..."); + printremark("Error: Invalid offset. Ignoring..."); set_streampos(streampos); } } @@ -446,7 +443,6 @@ static void decode_start(void) fcformat = get_num8(); printf(" format: 0x%02x\n", fcformat); - /* Check for checksum correctness. */ token_streampos = get_streampos(); @@ -467,7 +463,6 @@ static void decode_start(void) printf(" len: 0x%04x ( %d bytes)\n", fclen, fclen); } - /* ************************************************************************** * * Function name: decode_token @@ -549,28 +544,26 @@ static void decode_token(u16 token) decode_default(); break; -#if 0 /* Fooey on C's petty limitations! */ - /* I'd like to be able to do this: */ - /* Special Functions */ +#if 0 /* Fooey on C's petty limitations! */ + /* I'd like to be able to do this: */ + /* Special Functions */ case *double_lit_code: double_length_literal(); break; -#endif /* Fooey on C's petty limitations! */ +#endif /* Fooey on C's petty limitations! */ default: - { - /* Have to do this clumsy thing instead */ - if ( token == *double_lit_code ) - { - double_length_literal(); - break; - } + { + /* Have to do this clumsy thing instead */ + if (token == *double_lit_code) { + double_length_literal(); + break; + } - decode_default(); + decode_default(); + } } } -} - /* ************************************************************************** * @@ -763,8 +756,7 @@ static bool another_fcode_block(void) case 0x0f2: /* start2 */ case 0x0f3: /* start4 */ retval = TRUE; - printremark - ("Subsequent FCode Block detected. Detokenizing."); + printremark("Subsequent FCode Block detected. Detokenizing."); break; case 0: /* Start of a zero-fill field */ /* retval already = FALSE . Nothing else to be done. */ @@ -816,5 +808,4 @@ void detokenize(void) } } - } diff --git a/detok/detok.c b/detok/detok.c index a3d39f1..08d6db4 100644 --- a/detok/detok.c +++ b/detok/detok.c @@ -60,12 +60,12 @@ bool show_offsets = FALSE; * TRUE preceding error-exit */ static void print_copyright(bool is_error) { - typedef void (*vfunct) (); /* Pointer to function returning void */ + typedef void (*vfunct)(); /* Pointer to function returning void */ vfunct pfunct; char buffr[512]; sprintf(buffr, - "Welcome to detok - FCode detokenizer v" DETOK_VERSION "\n" + "Welcome to detok - FCode detokenizer v" DETOK_VERSION "\n" CORE_COPYR "\n" IBM_COPYR "\n" "Written by Stefan Reinauer\n" "This program is free software; you may redistribute it " @@ -100,13 +100,13 @@ int main(int argc, char **argv) #ifdef __GLIBC__ int option_index = 0; static struct option long_options[] = { - {"verbose", 0, 0, 'v'}, - {"help", 0, 0, 'h'}, - {"all", 0, 0, 'a'}, - {"linenumbers", 0, 0, 'n'}, - {"offsets", 0, 0, 'o'}, - {"fcodes", 1, 0, 'f'}, - {0, 0, 0, 0} + { "verbose", 0, 0, 'v' }, + { "help", 0, 0, 'h' }, + { "all", 0, 0, 'a' }, + { "linenumbers", 0, 0, 'n' }, + { "offsets", 0, 0, 'o' }, + { "fcodes", 1, 0, 'f' }, + { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, optstring, @@ -190,4 +190,3 @@ int main(int argc, char **argv) return 0; } - diff --git a/detok/detok.h b/detok/detok.h index 8ebf719..a9b3d24 100644 --- a/detok/detok.h +++ b/detok/detok.h @@ -51,12 +51,11 @@ typedef struct token { /* Macro for creating an entry in a token-table data-array */ #define TOKEN_ENTRY(num, name) { name, (u16)num, (token_t *)NULL } - /* Prototypes for functions exported from * detok.c decode.c printformats.c pcihdr.c and dictionary.c */ -void link_token(token_t *curr_token); +void link_token(token_t * curr_token); void add_token(u16 number, char *name); void init_dictionary(void); void reset_dictionary(void); @@ -70,7 +69,6 @@ void printremark(char *str); int handle_pci_header(u8 * data_ptr); void handle_pci_filler(u8 * filler_ptr); - /* External declarations for variables defined in or used by * detok.c decode.c printformats.c pcihdr.c and dictionary.c */ @@ -90,4 +88,4 @@ extern u8 *pci_image_end; extern unsigned int token_streampos; extern u16 last_defined_token; -#endif /* _UTILS_DETOK_DETOK_H */ +#endif /* _UTILS_DETOK_DETOK_H */ diff --git a/detok/dictionary.c b/detok/dictionary.c index a753130..80494ee 100644 --- a/detok/dictionary.c +++ b/detok/dictionary.c @@ -75,9 +75,9 @@ char *lookup_token(u16 number) * **************************************************************************** */ -void link_token( token_t *curr_token) +void link_token(token_t * curr_token) { - curr_token->prev = dictionary; + curr_token->prev = dictionary; dictionary = curr_token; } @@ -134,9 +134,9 @@ void add_token(u16 number, char *name) } curr->name = name; - curr->fcode=number; + curr->fcode = number; - link_token( curr); + link_token(curr); if (check_tok_seq) { /* Error-check, but not for first time. */ @@ -145,11 +145,13 @@ void add_token(u16 number, char *name) last_defined_token = number; } else { if (number <= last_defined_token) { - printremark("Warning: New token # might overlap " - "previously assigned token #(s)."); + printremark + ("Warning: New token # might overlap " + "previously assigned token #(s)."); } else { - printremark("Warning: New token # out of sequence with " - "previously assigned token #(s)."); + printremark + ("Warning: New token # out of sequence with " + "previously assigned token #(s)."); /* It's increasing; update it. */ last_defined_token = number; } @@ -546,8 +548,7 @@ token_t detok_table[] = { TOKEN_ENTRY(0x254, "xwsplit"), }; -static const int dictionary_indx_max = - (sizeof(detok_table) / sizeof(token_t)); +static const int dictionary_indx_max = (sizeof(detok_table) / sizeof(token_t)); static token_t *dictionary_reset_position; diff --git a/detok/pcihdr.c b/detok/pcihdr.c index 5cfa94b..62c51cb 100644 --- a/detok/pcihdr.c +++ b/detok/pcihdr.c @@ -62,7 +62,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Still to be done: @@ -78,7 +77,6 @@ #include "detok.h" - /* ************************************************************************** * * Global Variables Exported @@ -97,7 +95,6 @@ u8 *pci_image_end = NULL; static int pci_image_len = 0; - /* ************************************************************************** * * Function name: is_pci_header ( rom_header_t *pci_rom_hdr ) @@ -143,7 +140,8 @@ static int is_pci_header(rom_header_t * pci_rom_hdr) retval = 0; - if (BIG_ENDIAN_WORD_FETCH(pci_rom_hdr->signature) == pci_header_signature) { + if (BIG_ENDIAN_WORD_FETCH(pci_rom_hdr->signature) == + pci_header_signature) { retval = LITTLE_ENDIAN_WORD_FETCH(pci_rom_hdr->data_ptr); } return (retval); @@ -207,7 +205,6 @@ static int is_pci_data_struct(pci_data_t * pci_data_ptr) return (retval); } - /* ************************************************************************** * * Function name: announce_pci_hdr ( rom_header_t *pci_rom_hdr ) @@ -272,7 +269,8 @@ static void announce_pci_data_struct(pci_data_t * pci_data_ptr) printremark("PCI Data Structure identified"); temp = (u32) LITTLE_ENDIAN_WORD_FETCH(pci_data_ptr->dlen); - sprintf(temp_buf, " Data Structure Length = 0x%04x (%d)\n", temp, temp); + sprintf(temp_buf, " Data Structure Length = 0x%04x (%d)\n", temp, + temp); printremark(temp_buf); sprintf(temp_buf, " Vendor ID: 0x%04x\n", @@ -317,7 +315,6 @@ static void announce_pci_data_struct(pci_data_t * pci_data_ptr) } - /* ************************************************************************** * * Function name: handle_pci_header @@ -384,7 +381,9 @@ int handle_pci_header(u8 * data_ptr) /* if hdrlen == 0 then we don't need to check a Data Structure */ if (hdrlen > 0) { announce_pci_hdr((rom_header_t *) data_ptr); - data_struc_len = is_pci_data_struct((pci_data_t *) & data_ptr[hdrlen]); + data_struc_len = + is_pci_data_struct((pci_data_t *) & + data_ptr[hdrlen]); /* * A Data Structure Length of Zero would be an error * that could be detected by is_pci_data_struct() @@ -395,7 +394,8 @@ int handle_pci_header(u8 * data_ptr) /* It might need to do a premature EXIT here... */ /* retval = -1; *//* Not needed yet... */ } else { - announce_pci_data_struct((pci_data_t *) & data_ptr[hdrlen]); + announce_pci_data_struct((pci_data_t *) & + data_ptr[hdrlen]); pci_image_end = data_ptr + pci_image_len; /* retval = hdrlen+data_struc_len; *//* Not needed yet... */ } @@ -404,7 +404,6 @@ int handle_pci_header(u8 * data_ptr) return (hdrlen + data_struc_len); } - /* ************************************************************************** * * Function name: handle_pci_filler @@ -457,7 +456,8 @@ void handle_pci_filler(u8 * filler_ptr) } if (all_zero) { - sprintf(temp_buf, "PCI Image padded with %d bytes of zero", filler_len); + sprintf(temp_buf, "PCI Image padded with %d bytes of zero", + filler_len); } else { sprintf(temp_buf, "PCI Image padding-field of %d bytes " "had first non-zero byte at offset %ld", diff --git a/detok/printformats.c b/detok/printformats.c index 62ca5b7..864c0ba 100644 --- a/detok/printformats.c +++ b/detok/printformats.c @@ -46,7 +46,6 @@ #include "detok.h" - /* ************************************************************************** * * Function name: printremark ( string ) @@ -94,13 +93,12 @@ void printremark(char *str) char *strbfr; /* Temporary substring buffer */ /* Guarantee that the malloc will be big enough. */ - strbfr = (char *) malloc(strlen((char *) str) + 1); + strbfr = (char *)malloc(strlen((char *)str) + 1); if (!strbfr) { printf("No memory.\n"); exit(-1); } - strtmp = str; strend = &str[strlen(str)]; @@ -125,7 +123,7 @@ void printremark(char *str) * so we have to. * ************************************************************ */ - strbfr[substrlen] = (char) 0; + strbfr[substrlen] = (char)0; printf("\\ %s\n", strbfr); diff --git a/detok/stream.c b/detok/stream.c index 22466b0..da685b9 100644 --- a/detok/stream.c +++ b/detok/stream.c @@ -77,7 +77,6 @@ u8 *indata; static u8 *fc_start; static bool pci_image_found = FALSE; - int init_stream(char *name) { FILE *infile; @@ -124,7 +123,6 @@ void init_fcode_block(void) linenum = 1; } - void close_stream(void) { free(indata); @@ -133,7 +131,7 @@ void close_stream(void) int get_streampos(void) { - return (int) (pc - fc_start); + return (int)(pc - fc_start); } void set_streampos(int pos) @@ -141,7 +139,6 @@ void set_streampos(int pos) pc = fc_start + pos; } - /* ************************************************************************** * * Function name: throw_eof @@ -239,7 +236,6 @@ static u8 *get_bytes(int nbytes) return retval; } - /* ************************************************************************** * * Function name: more_to_go @@ -255,7 +251,6 @@ bool more_to_go(void) return retval; } - /* ************************************************************************** * * Function name: next_token @@ -359,12 +354,11 @@ u8 *get_string(u8 * len) u8 *retval; *len = get_num8(); - retval = get_bytes((int) *len); + retval = get_bytes((int)*len); return retval; } - /* ************************************************************************** * * Function name: get_name @@ -465,7 +459,6 @@ u16 calc_checksum(void) return retval; } - /* ************************************************************************** * * Function name: adjust_for_pci_header diff --git a/detok/stream.h b/detok/stream.h index 34252c3..6c062eb 100644 --- a/detok/stream.h +++ b/detok/stream.h @@ -37,7 +37,6 @@ /* Prototypes for functions exported from stream.c */ - int init_stream(char *name); void close_stream(void); bool more_to_go(void); @@ -65,4 +64,4 @@ extern u8 *indata; extern u8 *pc; extern u8 *max; -#endif /* _UTILS_DETOK_STREAM_H */ +#endif /* _UTILS_DETOK_STREAM_H */ diff --git a/romheaders/romheaders.c b/romheaders/romheaders.c index ebabdcd..41ce30f 100644 --- a/romheaders/romheaders.c +++ b/romheaders/romheaders.c @@ -42,10 +42,8 @@ #include "types.h" #include "pcihdr.h" - -char *rom=NULL; -size_t romlen=0; - +char *rom = NULL; +size_t romlen = 0; /* Prototypes for functions exported from devsupp/pci/classcodes.c */ @@ -58,73 +56,75 @@ char *pci_code_type_name(unsigned char code); void dump_platform_extensions(u8 type, rom_header_t *data); */ -static bool dump_rom_header(rom_header_t *data) -{ /* Return TRUE for "no problem" */ +static bool dump_rom_header(rom_header_t * data) +{ /* Return TRUE for "no problem" */ const u16 pci_header_signature = 0x55aa; - u16 sig=BIG_ENDIAN_WORD_FETCH(data->signature); + u16 sig = BIG_ENDIAN_WORD_FETCH(data->signature); int i; - printf ("PCI Expansion ROM Header:\n"); + printf("PCI Expansion ROM Header:\n"); - printf (" Signature: 0x%04x (%s)\n", - sig, sig == pci_header_signature ? "Ok":"Not Ok"); + printf(" Signature: 0x%04x (%s)\n", + sig, sig == pci_header_signature ? "Ok" : "Not Ok"); - printf (" CPU unique data:"); - for (i=0;i<16;i++) { - printf(" 0x%02x",data->reserved[i]); - if (i==7) printf("\n "); + printf(" CPU unique data:"); + for (i = 0; i < 16; i++) { + printf(" 0x%02x", data->reserved[i]); + if (i == 7) + printf("\n "); } - printf ("\n Pointer to PCI Data Structure: 0x%04x\n\n", - LITTLE_ENDIAN_WORD_FETCH(data->data_ptr)); + printf("\n Pointer to PCI Data Structure: 0x%04x\n\n", + LITTLE_ENDIAN_WORD_FETCH(data->data_ptr)); - return (BOOLVAL(sig == pci_header_signature) ); + return (BOOLVAL(sig == pci_header_signature)); } -static bool dump_pci_data(pci_data_t *data) -{ /* Return TRUE for "no problem" */ - const u32 pci_data_hdr = PCI_DATA_HDR ; +static bool dump_pci_data(pci_data_t * data) +{ /* Return TRUE for "no problem" */ + const u32 pci_data_hdr = PCI_DATA_HDR; - u32 sig = BIG_ENDIAN_LONG_FETCH(data->signature); - u32 classcode= CLASS_CODE_FETCH(data->class_code); - u32 dlen = (u32)LITTLE_ENDIAN_WORD_FETCH(data->dlen); - u32 ilen = (u32)LITTLE_ENDIAN_WORD_FETCH(data->ilen); + u32 sig = BIG_ENDIAN_LONG_FETCH(data->signature); + u32 classcode = CLASS_CODE_FETCH(data->class_code); + u32 dlen = (u32) LITTLE_ENDIAN_WORD_FETCH(data->dlen); + u32 ilen = (u32) LITTLE_ENDIAN_WORD_FETCH(data->ilen); printf("PCI Data Structure:\n"); printf(" Signature: 0x%04x '%c%c%c%c' ", sig, - sig>>24,(sig>>16)&0xff, (sig>>8)&0xff, sig&0xff); - printf("(%s)\n", sig == pci_data_hdr ?"Ok":"Not Ok"); + sig >> 24, (sig >> 16) & 0xff, (sig >> 8) & 0xff, sig & 0xff); + printf("(%s)\n", sig == pci_data_hdr ? "Ok" : "Not Ok"); printf(" Vendor ID: 0x%04x\n", LITTLE_ENDIAN_WORD_FETCH(data->vendor)); printf(" Device ID: 0x%04x\n", LITTLE_ENDIAN_WORD_FETCH(data->device)); printf(" Vital Product Data: 0x%04x\n", - LITTLE_ENDIAN_WORD_FETCH(data->vpd)); + LITTLE_ENDIAN_WORD_FETCH(data->vpd)); printf(" PCI Data Structure Length: 0x%04x (%d bytes)\n", dlen, dlen); printf(" PCI Data Structure Revision: 0x%02x\n", data->drevision); - printf(" Class Code: 0x%06x (%s)\n",classcode, - pci_device_class_name(classcode)); - printf(" Image Length: 0x%04x blocks (%d bytes)\n", ilen, ilen*512); + printf(" Class Code: 0x%06x (%s)\n", classcode, + pci_device_class_name(classcode)); + printf(" Image Length: 0x%04x blocks (%d bytes)\n", ilen, ilen * 512); printf(" Revision Level of Code/Data: 0x%04x\n", - (u32)LITTLE_ENDIAN_WORD_FETCH(data->irevision)); + (u32) LITTLE_ENDIAN_WORD_FETCH(data->irevision)); printf(" Code Type: 0x%02x (%s)\n", data->code_type, - pci_code_type_name(data->code_type) ); + pci_code_type_name(data->code_type)); printf(" Last-Image Flag: 0x%02x (%slast image in rom)\n", - data->last_image_flag, - data->last_image_flag&0x80?"":"not "); + data->last_image_flag, + data->last_image_flag & 0x80 ? "" : "not "); printf(" Reserved: 0x%04x\n\n", little_word(data->reserved_2)); - return (BOOLVAL(sig==PCI_DATA_HDR) ); + return (BOOLVAL(sig == PCI_DATA_HDR)); } -static void dump_platform_extensions(u8 type, rom_header_t *data) +static void dump_platform_extensions(u8 type, rom_header_t * data) { u32 entry; switch (type) { case 0x00: - printf("Platform specific data for x86 compliant option rom:\n"); + printf + ("Platform specific data for x86 compliant option rom:\n"); printf(" Initialization Size: 0x%02x (%d bytes)\n", - data->reserved[0], data->reserved[0]*512); + data->reserved[0], data->reserved[0] * 512); /* We do a hack here - implement a jump disasm to be able * to output correct offset for init code. Once again x86 @@ -132,80 +132,83 @@ static void dump_platform_extensions(u8 type, rom_header_t *data) */ switch (data->reserved[1]) { - case 0xeb: /* short jump */ + case 0xeb: /* short jump */ entry = data->reserved[2] + 2; /* a short jump instruction is 2 bytes, * we have to add those to the offset */ break; - case 0xe9: /* jump */ - entry = ((data->reserved[3]<<8)|data->reserved[2]) + 3; + case 0xe9: /* jump */ + entry = + ((data->reserved[3] << 8) | data->reserved[2]) + 3; /* jump is 3 bytes, so add them */ break; default: - entry=0; + entry = 0; break; } if (entry) { /* 0x55aa rom signature plus 1 byte len */ entry += 3; - printf( " Entry point for INIT function:" - " 0x%x\n\n",entry); + printf(" Entry point for INIT function:" + " 0x%x\n\n", entry); } else - printf( " Unable to determine entry point for INIT" - " function. Please report.\n\n"); + printf(" Unable to determine entry point for INIT" + " function. Please report.\n\n"); break; case 0x01: - printf("Platform specific data for Open Firmware compliant rom:\n"); + printf + ("Platform specific data for Open Firmware compliant rom:\n"); printf(" Pointer to FCode program: 0x%04x\n\n", - data->reserved[1]<<8|data->reserved[0]); + data->reserved[1] << 8 | data->reserved[0]); break; default: - printf("Parsing of platform specific data not available for this image\n\n"); + printf + ("Parsing of platform specific data not available for this image\n\n"); } } int main(int argc, char **argv) { - char *name=argv[1]; - FILE *romfile; - struct stat finfo; + char *name = argv[1]; + FILE *romfile; + struct stat finfo; - rom_header_t *rom_header; - pci_data_t *pci_data; + rom_header_t *rom_header; + pci_data_t *pci_data; - int i=1; + int i = 1; - if (argc!=2) { - printf ("\nUsage: %s \n",argv[0]); - printf ("\n romheaders dumps pci option rom headers " - "according to PCI \n" - " specs 2.2 in human readable form\n\n"); + if (argc != 2) { + printf("\nUsage: %s \n", argv[0]); + printf("\n romheaders dumps pci option rom headers " + "according to PCI \n" + " specs 2.2 in human readable form\n\n"); return -1; } - if (stat(name,&finfo)) { + if (stat(name, &finfo)) { printf("Error while reading file information.\n"); return -1; } - romlen=finfo.st_size; + romlen = finfo.st_size; - rom=malloc(romlen); + rom = malloc(romlen); if (!rom) { printf("Out of memory.\n"); return -1; } - romfile=fopen(name,"r"); - if (!romfile) { + romfile = fopen(name, "r"); + if (!romfile) { printf("Error while opening file\n"); return -1; } - if (fread(rom, romlen, 1, romfile)!=1) { + if (fread(rom, romlen, 1, romfile) != 1) { printf("Error while reading file\n"); free(rom); return -1; @@ -213,17 +216,18 @@ int main(int argc, char **argv) fclose(romfile); - rom_header=(rom_header_t *)rom; + rom_header = (rom_header_t *) rom; do { - printf("\nImage %d:\n",i); + printf("\nImage %d:\n", i); if (!dump_rom_header(rom_header)) { printf("Rom Header error occured. Bailing out.\n"); break; } - pci_data = (pci_data_t *)((char *)rom_header + - LITTLE_ENDIAN_WORD_FETCH(rom_header->data_ptr)); + pci_data = (pci_data_t *) ((char *)rom_header + + LITTLE_ENDIAN_WORD_FETCH(rom_header-> + data_ptr)); if (!dump_pci_data(pci_data)) { printf("PCI Data error occured. Bailing out.\n"); @@ -232,11 +236,12 @@ int main(int argc, char **argv) dump_platform_extensions(pci_data->code_type, rom_header); - rom_header = (rom_header_t *)((char *)rom_header + - LITTLE_ENDIAN_WORD_FETCH(pci_data->ilen)*512); + rom_header = (rom_header_t *) ((char *)rom_header + + LITTLE_ENDIAN_WORD_FETCH + (pci_data->ilen) * 512); i++; - } while ((pci_data->last_image_flag&0x80)!=0x80 && - (char *)rom_header < rom+(int)romlen ); + } while ((pci_data->last_image_flag & 0x80) != 0x80 && + (char *)rom_header < rom + (int)romlen); return 0; } diff --git a/shared/classcodes.c b/shared/classcodes.c index 6919cc3..54a96b8 100644 --- a/shared/classcodes.c +++ b/shared/classcodes.c @@ -46,15 +46,13 @@ * **************************************************************************** */ -const char *pci_device_class_name( u32 code); +const char *pci_device_class_name(u32 code); const char *pci_code_type_name(u8 code); - typedef struct { - const u32 classcode; - const char *classname; -} num_to_name_table ; - + const u32 classcode; + const char *classname; +} num_to_name_table; /* ************************************************************************** * @@ -88,27 +86,23 @@ typedef struct { **************************************************************************** */ static const char *convert_num_to_name(u32 num, - num_to_name_table *table, - int max, - const char *not_found) + num_to_name_table * table, + int max, const char *not_found) { - int indx; - const char *retval; - - retval = not_found; - - for (indx = 0; indx < max ; indx++) - { - if ( num == table[indx].classcode ) - { - retval = table[indx].classname ; - break ; - } - } - return ( retval ); + int indx; + const char *retval; + + retval = not_found; + + for (indx = 0; indx < max; indx++) { + if (num == table[indx].classcode) { + retval = table[indx].classname; + break; + } + } + return (retval); } - /* ************************************************************************** * * @@ -124,182 +118,181 @@ static const char *convert_num_to_name(u32 num, * **************************************************************************** */ - static const num_to_name_table pci_code_type_name_table[] = { - { 0 , "Intel x86" }, - { 1 , "Open Firmware" }, - { 2 , "HP PA Risc" }, - { 3 , "Intel EFI (unofficial)" } + { 0, "Intel x86" }, + { 1, "Open Firmware" }, + { 2, "HP PA Risc" }, + { 3, "Intel EFI (unofficial)" } }; - static const num_to_name_table pci_dev_class_name_table[] = { - { 0x000000 , "Legacy Device" }, - { 0x000100 , "VGA-Compatible Device" }, - - { 0x010000 , "SCSI bus controller" }, - /* { 0x0101xx , "IDE controller" }, */ - { 0x010200 , "Floppy disk controller" }, - { 0x010300 , "IPI bus controller" }, - { 0x010400 , "RAID controller" }, - { 0x010520 , "ATA controller, single stepping" }, - { 0x010530 , "ATA controller, continuous" }, - { 0x010600 , "Serial ATA controller - vendor specific interface" }, - { 0x010601 , "Serial ATA controller - AHCI 1.0 interface" }, - { 0x010700 , "Serial Attached SCSI controller" }, - { 0x018000 , "Mass Storage controller" }, - - { 0x020000 , "Ethernet controller" }, - { 0x020100 , "Token Ring controller" }, - { 0x020200 , "FDDI controller" }, - { 0x020300 , "ATM controller" }, - { 0x020400 , "ISDN controller" }, - { 0x020500 , "WorldFip controller" }, - /* { 0x0206xx , "PICMG 2.14 Multi Computing" }, */ - { 0x028000 , "Network controller" }, - - { 0x030000 , "VGA Display controller" }, - { 0x030001 , "8514-compatible Display controller" }, - { 0x030100 , "XGA Display controller" }, - { 0x030200 , "3D Display controller" }, - { 0x038000 , "Display controller" }, - - { 0x040000 , "Video device" }, - { 0x040100 , "Audio device" }, - { 0x040200 , "Computer Telephony device" }, - { 0x048000 , "Multimedia device" }, - - { 0x050000 , "RAM memory controller" }, - { 0x050100 , "Flash memory controller" }, - { 0x058000 , "Memory controller" }, - - { 0x060000 , "Host bridge" }, - { 0x060100 , "ISA bridge" }, - { 0x060200 , "EISA bridge" }, - { 0x060300 , "MCA bridge" }, - { 0x060400 , "PCI-to-PCI bridge" }, - { 0x060401 , "PCI-to-PCI bridge (subtractive decoding)" }, - { 0x060500 , "PCMCIA bridge" }, - { 0x060600 , "NuBus bridge" }, - { 0x060700 , "CardBus bridge" }, - /* { 0x0608xx , "RACEway bridge" }, */ - { 0x060940 , "PCI-to-PCI bridge, Semi-transparent, primary facing Host" }, - { 0x060980 , "PCI-to-PCI bridge, Semi-transparent, secondary facing Host" }, - { 0x060A00 , "InfiniBand-to-PCI host bridge" }, - { 0x068000 , "Bridge device" }, - - { 0x070000 , "Generic XT-compatible serial controller" }, - { 0x070001 , "16450-compatible serial controller" }, - { 0x070002 , "16550-compatible serial controller" }, - { 0x070003 , "16650-compatible serial controller" }, - { 0x070004 , "16750-compatible serial controller" }, - { 0x070005 , "16850-compatible serial controller" }, - { 0x070006 , "16950-compatible serial controller" }, - - { 0x070100 , "Parallel port" }, - { 0x070101 , "Bi-directional parallel port" }, - { 0x070102 , "ECP 1.X compliant parallel port" }, - { 0x070103 , "IEEE1284 controller" }, - { 0x0701FE , "IEEE1284 target device" }, - { 0x070200 , "Multiport serial controller" }, - - { 0x070300 , "Generic modem" }, - { 0x070301 , "Hayes 16450-compatible modem" }, - { 0x070302 , "Hayes 16550-compatible modem" }, - { 0x070303 , "Hayes 16650-compatible modem" }, - { 0x070304 , "Hayes 16750-compatible modem" }, - { 0x070400 , "GPIB (IEEE 488.1/2) controller" }, - { 0x070500 , "Smart Card" }, - { 0x078000 , "Communications device" }, - - { 0x080000 , "Generic 8259 PIC" }, - { 0x080001 , "ISA PIC" }, - { 0x080002 , "EISA PIC" }, - { 0x080010 , "I/O APIC interrupt controller" }, - { 0x080020 , "I/O(x) APIC interrupt controller" }, - - { 0x080100 , "Generic 8237 DMA controller" }, - { 0x080101 , "ISA DMA controller" }, - { 0x080102 , "EISA DMA controller" }, - - { 0x080200 , "Generic 8254 system timer" }, - { 0x080201 , "ISA system timer" }, - { 0x080202 , "EISA system timer-pair" }, - - { 0x080300 , "Generic RTC controller" }, - { 0x080301 , "ISA RTC controller" }, - - { 0x080400 , "Generic PCI Hot-Plug controller" }, - { 0x080500 , "SD Host controller" }, - { 0x088000 , "System peripheral" }, - - { 0x090000 , "Keyboard controller" }, - { 0x090100 , "Digitizer (pen)" }, - { 0x090200 , "Mouse controller" }, - { 0x090300 , "Scanner controller" }, - { 0x090400 , "Generic Gameport controller" }, - { 0x090410 , "Legacy Gameport controller" }, - { 0x098000 , "Input controller" }, - - { 0x0a0000 , "Generic docking station" }, - { 0x0a8000 , "Docking station" }, - - { 0x0b0000 , "386 Processor" }, - { 0x0b0100 , "486 Processor" }, - { 0x0b0200 , "Pentium Processor" }, - { 0x0b1000 , "Alpha Processor" }, - { 0x0b2000 , "PowerPC Processor" }, - { 0x0b3000 , "MIPS Processor" }, - { 0x0b4000 , "Co-processor" }, - - { 0x0c0000 , "IEEE 1394 (FireWire)" }, - { 0x0c0010 , "IEEE 1394 -- OpenHCI spec" }, - { 0x0c0100 , "ACCESS.bus" }, - { 0x0c0200 , "SSA" }, - { 0x0c0300 , "Universal Serial Bus (UHC spec)" }, - { 0x0c0310 , "Universal Serial Bus (Open Host spec)" }, - { 0x0c0320 , "USB2 Host controller (Intel Enhanced HCI spec)" }, - { 0x0c0380 , "Universal Serial Bus (no PI spec)" }, - { 0x0c03FE , "USB Target Device" }, - { 0x0c0400 , "Fibre Channel" }, - { 0x0c0500 , "System Management Bus" }, - { 0x0c0600 , "InfiniBand" }, - { 0x0c0700 , "IPMI SMIC Interface" }, - { 0x0c0701 , "IPMI Kybd Controller Style Interface" }, - { 0x0c0702 , "IPMI Block Transfer Interface" }, - /* { 0x0c08xx , "SERCOS Interface" }, */ - { 0x0c0900 , "CANbus" }, - - { 0x0d100 , "iRDA compatible controller" }, - { 0x0d100 , "Consumer IR controller" }, - { 0x0d100 , "RF controller" }, - { 0x0d100 , "Bluetooth controller" }, - { 0x0d100 , "Broadband controller" }, - { 0x0d100 , "Ethernet (802.11a 5 GHz) controller" }, - { 0x0d100 , "Ethernet (802.11b 2.4 GHz) controller" }, - { 0x0d100 , "Wireless controller" }, - - /* { 0x0e00xx , "I2O Intelligent I/O, spec 1.0" }, */ - { 0x0e0000 , "Message FIFO at offset 040h" }, - - { 0x0f0100 , "TV satellite comm. controller" }, - { 0x0f0200 , "Audio satellite comm. controller" }, - { 0x0f0300 , "Voice satellite comm. controller" }, - { 0x0f0400 , "Data satellite comm. controller" }, - - { 0x100000 , "Network and computing en/decryption" }, - { 0x101000 , "Entertainment en/decryption" }, - { 0x108000 , "En/Decryption" }, - - { 0x110000 , "DPIO modules" }, - { 0x110100 , "Perf. counters" }, - { 0x111000 , "Comm. synch., time and freq. test" }, - { 0x112000 , "Management card" }, - { 0x118000 , "Data acq./Signal proc." }, + { 0x000000, "Legacy Device" }, + { 0x000100, "VGA-Compatible Device" }, + + { 0x010000, "SCSI bus controller" }, + /* { 0x0101xx , "IDE controller" }, */ + { 0x010200, "Floppy disk controller" }, + { 0x010300, "IPI bus controller" }, + { 0x010400, "RAID controller" }, + { 0x010520, "ATA controller, single stepping" }, + { 0x010530, "ATA controller, continuous" }, + { 0x010600, "Serial ATA controller - vendor specific interface" }, + { 0x010601, "Serial ATA controller - AHCI 1.0 interface" }, + { 0x010700, "Serial Attached SCSI controller" }, + { 0x018000, "Mass Storage controller" }, + + { 0x020000, "Ethernet controller" }, + { 0x020100, "Token Ring controller" }, + { 0x020200, "FDDI controller" }, + { 0x020300, "ATM controller" }, + { 0x020400, "ISDN controller" }, + { 0x020500, "WorldFip controller" }, + /* { 0x0206xx , "PICMG 2.14 Multi Computing" }, */ + { 0x028000, "Network controller" }, + + { 0x030000, "VGA Display controller" }, + { 0x030001, "8514-compatible Display controller" }, + { 0x030100, "XGA Display controller" }, + { 0x030200, "3D Display controller" }, + { 0x038000, "Display controller" }, + + { 0x040000, "Video device" }, + { 0x040100, "Audio device" }, + { 0x040200, "Computer Telephony device" }, + { 0x048000, "Multimedia device" }, + + { 0x050000, "RAM memory controller" }, + { 0x050100, "Flash memory controller" }, + { 0x058000, "Memory controller" }, + + { 0x060000, "Host bridge" }, + { 0x060100, "ISA bridge" }, + { 0x060200, "EISA bridge" }, + { 0x060300, "MCA bridge" }, + { 0x060400, "PCI-to-PCI bridge" }, + { 0x060401, "PCI-to-PCI bridge (subtractive decoding)" }, + { 0x060500, "PCMCIA bridge" }, + { 0x060600, "NuBus bridge" }, + { 0x060700, "CardBus bridge" }, + /* { 0x0608xx , "RACEway bridge" }, */ + { 0x060940, + "PCI-to-PCI bridge, Semi-transparent, primary facing Host" }, + { 0x060980, + "PCI-to-PCI bridge, Semi-transparent, secondary facing Host" }, + { 0x060A00, "InfiniBand-to-PCI host bridge" }, + { 0x068000, "Bridge device" }, + + { 0x070000, "Generic XT-compatible serial controller" }, + { 0x070001, "16450-compatible serial controller" }, + { 0x070002, "16550-compatible serial controller" }, + { 0x070003, "16650-compatible serial controller" }, + { 0x070004, "16750-compatible serial controller" }, + { 0x070005, "16850-compatible serial controller" }, + { 0x070006, "16950-compatible serial controller" }, + + { 0x070100, "Parallel port" }, + { 0x070101, "Bi-directional parallel port" }, + { 0x070102, "ECP 1.X compliant parallel port" }, + { 0x070103, "IEEE1284 controller" }, + { 0x0701FE, "IEEE1284 target device" }, + { 0x070200, "Multiport serial controller" }, + + { 0x070300, "Generic modem" }, + { 0x070301, "Hayes 16450-compatible modem" }, + { 0x070302, "Hayes 16550-compatible modem" }, + { 0x070303, "Hayes 16650-compatible modem" }, + { 0x070304, "Hayes 16750-compatible modem" }, + { 0x070400, "GPIB (IEEE 488.1/2) controller" }, + { 0x070500, "Smart Card" }, + { 0x078000, "Communications device" }, + + { 0x080000, "Generic 8259 PIC" }, + { 0x080001, "ISA PIC" }, + { 0x080002, "EISA PIC" }, + { 0x080010, "I/O APIC interrupt controller" }, + { 0x080020, "I/O(x) APIC interrupt controller" }, + + { 0x080100, "Generic 8237 DMA controller" }, + { 0x080101, "ISA DMA controller" }, + { 0x080102, "EISA DMA controller" }, + + { 0x080200, "Generic 8254 system timer" }, + { 0x080201, "ISA system timer" }, + { 0x080202, "EISA system timer-pair" }, + + { 0x080300, "Generic RTC controller" }, + { 0x080301, "ISA RTC controller" }, + + { 0x080400, "Generic PCI Hot-Plug controller" }, + { 0x080500, "SD Host controller" }, + { 0x088000, "System peripheral" }, + + { 0x090000, "Keyboard controller" }, + { 0x090100, "Digitizer (pen)" }, + { 0x090200, "Mouse controller" }, + { 0x090300, "Scanner controller" }, + { 0x090400, "Generic Gameport controller" }, + { 0x090410, "Legacy Gameport controller" }, + { 0x098000, "Input controller" }, + + { 0x0a0000, "Generic docking station" }, + { 0x0a8000, "Docking station" }, + + { 0x0b0000, "386 Processor" }, + { 0x0b0100, "486 Processor" }, + { 0x0b0200, "Pentium Processor" }, + { 0x0b1000, "Alpha Processor" }, + { 0x0b2000, "PowerPC Processor" }, + { 0x0b3000, "MIPS Processor" }, + { 0x0b4000, "Co-processor" }, + + { 0x0c0000, "IEEE 1394 (FireWire)" }, + { 0x0c0010, "IEEE 1394 -- OpenHCI spec" }, + { 0x0c0100, "ACCESS.bus" }, + { 0x0c0200, "SSA" }, + { 0x0c0300, "Universal Serial Bus (UHC spec)" }, + { 0x0c0310, "Universal Serial Bus (Open Host spec)" }, + { 0x0c0320, "USB2 Host controller (Intel Enhanced HCI spec)" }, + { 0x0c0380, "Universal Serial Bus (no PI spec)" }, + { 0x0c03FE, "USB Target Device" }, + { 0x0c0400, "Fibre Channel" }, + { 0x0c0500, "System Management Bus" }, + { 0x0c0600, "InfiniBand" }, + { 0x0c0700, "IPMI SMIC Interface" }, + { 0x0c0701, "IPMI Kybd Controller Style Interface" }, + { 0x0c0702, "IPMI Block Transfer Interface" }, + /* { 0x0c08xx , "SERCOS Interface" }, */ + { 0x0c0900, "CANbus" }, + + { 0x0d100, "iRDA compatible controller" }, + { 0x0d100, "Consumer IR controller" }, + { 0x0d100, "RF controller" }, + { 0x0d100, "Bluetooth controller" }, + { 0x0d100, "Broadband controller" }, + { 0x0d100, "Ethernet (802.11a 5 GHz) controller" }, + { 0x0d100, "Ethernet (802.11b 2.4 GHz) controller" }, + { 0x0d100, "Wireless controller" }, + + /* { 0x0e00xx , "I2O Intelligent I/O, spec 1.0" }, */ + { 0x0e0000, "Message FIFO at offset 040h" }, + + { 0x0f0100, "TV satellite comm. controller" }, + { 0x0f0200, "Audio satellite comm. controller" }, + { 0x0f0300, "Voice satellite comm. controller" }, + { 0x0f0400, "Data satellite comm. controller" }, + + { 0x100000, "Network and computing en/decryption" }, + { 0x101000, "Entertainment en/decryption" }, + { 0x108000, "En/Decryption" }, + + { 0x110000, "DPIO modules" }, + { 0x110100, "Perf. counters" }, + { 0x111000, "Comm. synch., time and freq. test" }, + { 0x112000, "Management card" }, + { 0x118000, "Data acq./Signal proc." }, }; - /* ************************************************************************** * * PCI Class Code name calculations are further complicated by the @@ -315,16 +308,14 @@ static const num_to_name_table pci_dev_class_name_table[] = { * **************************************************************************** */ - static const num_to_name_table pci_all_prg_intfcs_table[] = { - { 0x0101 , "IDE controller" }, - { 0x0206 , "PICMG 2.14 Multi Computing" }, - { 0x0608 , "RACEway bridge" }, - { 0x0c08 , "SERCOS Interface" }, - { 0x0e00 , "I2O Intelligent I/O, spec 1.0" }, + { 0x0101, "IDE controller" }, + { 0x0206, "PICMG 2.14 Multi Computing" }, + { 0x0608, "RACEway bridge" }, + { 0x0c08, "SERCOS Interface" }, + { 0x0e00, "I2O Intelligent I/O, spec 1.0" }, }; - /* ************************************************************************** * * Function name: pci_device_class_name @@ -350,33 +341,30 @@ static const num_to_name_table pci_all_prg_intfcs_table[] = { * **************************************************************************** */ -const char *pci_device_class_name( u32 code) +const char *pci_device_class_name(u32 code) { - const int pdc_max_indx = - sizeof(pci_dev_class_name_table)/sizeof(num_to_name_table) ; - const char *result ; - - result = convert_num_to_name( - code, - (num_to_name_table *)pci_dev_class_name_table, - pdc_max_indx, - NULL); - - if ( result == NULL) - { - const int pallpi_max_indx = - sizeof(pci_all_prg_intfcs_table)/sizeof(num_to_name_table) ; - - result = convert_num_to_name( - code>>8, - (num_to_name_table *)pci_all_prg_intfcs_table, - pallpi_max_indx, - "unknown"); - } - return ( result ); + const int pdc_max_indx = + sizeof(pci_dev_class_name_table) / sizeof(num_to_name_table); + const char *result; + + result = convert_num_to_name(code, + (num_to_name_table *) + pci_dev_class_name_table, pdc_max_indx, + NULL); + + if (result == NULL) { + const int pallpi_max_indx = + sizeof(pci_all_prg_intfcs_table) / + sizeof(num_to_name_table); + + result = convert_num_to_name(code >> 8, + (num_to_name_table *) + pci_all_prg_intfcs_table, + pallpi_max_indx, "unknown"); + } + return (result); } - /* ************************************************************************** * * Function name: pci_code_type_name @@ -401,15 +389,13 @@ const char *pci_device_class_name( u32 code) const char *pci_code_type_name(u8 code) { - const int pct_max_indx = - sizeof(pci_code_type_name_table)/sizeof(num_to_name_table) ; - const char *result ; - - result = convert_num_to_name( - (u32)code, - (num_to_name_table *)pci_code_type_name_table, - pct_max_indx, - "unknown as of PCI specs 2.2"); - return ( result ); + const int pct_max_indx = + sizeof(pci_code_type_name_table) / sizeof(num_to_name_table); + const char *result; + + result = convert_num_to_name((u32) code, + (num_to_name_table *) + pci_code_type_name_table, pct_max_indx, + "unknown as of PCI specs 2.2"); + return (result); } - diff --git a/shared/pcihdr.h b/shared/pcihdr.h index 824652c..5ab075b 100644 --- a/shared/pcihdr.h +++ b/shared/pcihdr.h @@ -37,7 +37,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Structures: @@ -110,7 +109,6 @@ /* Fetch a little-endian triplet from 3 unsigned chars in sequence */ #define LITTLE_ENDIAN_TRIPLET_FETCH(x) (u32)( (x[2] << 16) | (x[1] << 8) | x[0] ) - /* Special case for Class-Code triplet: lo, mid, hi */ #define class_code_u24(x) u8 x[3] /* Special fetch for Class-Code triplet */ @@ -140,37 +138,33 @@ /* Store an integer into 3 unsigned chars in little-endian triplet sequence */ #define LITTLE_ENDIAN_TRIPLET_STORE(dest,x) \ dest[2] = (u8)( x >> 16); dest[1] = (u8)(x >> 8); dest[0] = (u8)x; - typedef struct { - be_u16(signature); - u8 reserved[0x16]; - le_u16(data_ptr); - le_u16(padd); + be_u16(signature); + u8 reserved[0x16]; + le_u16(data_ptr); + le_u16(padd); } rom_header_t; - typedef struct { - be_u32 (signature); - le_u16 (vendor); - le_u16 (device); - le_u16 (vpd); - le_u16 (dlen); - u8 drevision; - class_code_u24 (class_code); - le_u16 (ilen); - le_u16 (irevision); - u8 code_type; - u8 last_image_flag; - u16 reserved_2; + be_u32(signature); + le_u16(vendor); + le_u16(device); + le_u16(vpd); + le_u16(dlen); + u8 drevision; + class_code_u24(class_code); + le_u16(ilen); + le_u16(irevision); + u8 code_type; + u8 last_image_flag; + u16 reserved_2; } pci_data_t; #define PCI_DATA_STRUCT_REV 0 /* Prototypes for functions exported from devsupp/pci/classcodes.c */ -char *pci_device_class_name( u32 code); +char *pci_device_class_name(u32 code); char *pci_code_type_name(u8 code); - - -#endif /* _PCIHDR_H */ +#endif /* _PCIHDR_H */ diff --git a/shared/types.h b/shared/types.h index 0ff64bc..11205ed 100644 --- a/shared/types.h +++ b/shared/types.h @@ -41,7 +41,6 @@ #include - typedef int8_t s8; typedef uint8_t u8; @@ -54,14 +53,12 @@ typedef uint32_t u32; typedef int64_t s64; typedef uint64_t u64; - -#ifdef FALSE /* Hack for AIX. */ +#ifdef FALSE /* Hack for AIX. */ #undef FALSE #undef TRUE -#endif /* Hack for AIX. */ - -typedef enum boolean { FALSE = 0 , TRUE = -1 } bool ; +#endif /* Hack for AIX. */ +typedef enum boolean { FALSE = 0, TRUE = -1 } bool; /* ************************************************************************** * Macro Name: BOOLVAL @@ -74,7 +71,6 @@ typedef enum boolean { FALSE = 0 , TRUE = -1 } bool ; #define BOOLVAL(x) (x ? TRUE : FALSE) - /* ************************************************************************** * Macro Name: INVERSE * Return the logical inversion of the @@ -86,7 +82,6 @@ typedef enum boolean { FALSE = 0 , TRUE = -1 } bool ; #define INVERSE(x) (x ? FALSE : TRUE) - /* ************************************************************************** * * Some hacks stuck in for systems w/ incomplete includes diff --git a/toke/clflags.c b/toke/clflags.c index 0fd6d15..43efdf0 100644 --- a/toke/clflags.c +++ b/toke/clflags.c @@ -81,7 +81,6 @@ #include "clflags.h" #include "errhandler.h" - /* ************************************************************************** * * Global Variables Exported @@ -89,23 +88,23 @@ * **************************************************************************** */ -bool ibm_locals = FALSE ; -bool ibm_locals_legacy_separator = TRUE ; -bool ibm_legacy_separator_message = TRUE ; -bool enable_abort_quote = TRUE ; -bool sun_style_abort_quote = TRUE ; -bool sun_style_checksum = FALSE ; -bool abort_quote_throw = TRUE ; -bool string_remark_escape = TRUE ; -bool hex_remark_escape = TRUE ; -bool c_style_string_escape = TRUE ; -bool always_headers = FALSE ; -bool always_external = FALSE ; -bool verbose_dup_warning = TRUE ; -bool obso_fcode_warning = TRUE ; -bool trace_conditionals = FALSE ; -bool big_end_pci_image_rev = FALSE ; -bool allow_ret_stk_interp = TRUE ; +bool ibm_locals = FALSE; +bool ibm_locals_legacy_separator = TRUE; +bool ibm_legacy_separator_message = TRUE; +bool enable_abort_quote = TRUE; +bool sun_style_abort_quote = TRUE; +bool sun_style_checksum = FALSE; +bool abort_quote_throw = TRUE; +bool string_remark_escape = TRUE; +bool hex_remark_escape = TRUE; +bool c_style_string_escape = TRUE; +bool always_headers = FALSE; +bool always_external = FALSE; +bool verbose_dup_warning = TRUE; +bool obso_fcode_warning = TRUE; +bool trace_conditionals = FALSE; +bool big_end_pci_image_rev = FALSE; +bool allow_ret_stk_interp = TRUE; /* And one to trigger a "help" message */ bool clflag_help = FALSE; @@ -118,8 +117,8 @@ bool clflag_help = FALSE; * **************************************************************************** */ -bool force_tokens_case = FALSE ; -bool force_lower_case_tokens = FALSE ; +bool force_tokens_case = FALSE; +bool force_lower_case_tokens = FALSE; /* ************************************************************************** * @@ -127,10 +126,10 @@ bool force_lower_case_tokens = FALSE ; * and keep two more to detect when a change is made... * **************************************************************************** */ -static bool upper_case_tokens = FALSE ; -static bool lower_case_tokens = FALSE ; -static bool was_upper_case_tk = FALSE ; -static bool was_lower_case_tk = FALSE ; +static bool upper_case_tokens = FALSE; +static bool lower_case_tokens = FALSE; +static bool was_upper_case_tk = FALSE; +static bool was_lower_case_tk = FALSE; /* ************************************************************************** * @@ -144,129 +143,125 @@ static bool was_lower_case_tk = FALSE ; static bool cl_flag_change = FALSE; static const cl_flag_t cl_flags_list[] = { - /* The clflag_tabs field takes at least one tab. - * If the name has fewer than 16 characters, - * stick in an extra tab, and yet another tab - * if the name is shorter than 8 characters - * to make the formatting of the "explanation" - * come out prettier. - */ - { "Local-Values", - &ibm_locals, - "\t\t", - "Support IBM-style Local Values (\"LV\"s)" } , - - { "LV-Legacy-Separator", - &ibm_locals_legacy_separator, - "\t", - "Allow Semicolon for Local Values Separator (\"Legacy\")" } , - - { "LV-Legacy-Message", - &ibm_legacy_separator_message, - "\t", - "Display a Message when Semicolon is used as the " - "Local Values Separator" } , - - { "ABORT-Quote", - &enable_abort_quote, - "\t\t", - "Allow ABORT\" macro" } , - - { "Sun-ABORT-Quote", - &sun_style_abort_quote, - "\t\t", - "ABORT\" with implicit IF ... THEN" } , - - { "ABORT-Quote-Throw", - &abort_quote_throw, - "\t", - "Use -2 THROW in an Abort\" phrase, rather than ABORT" } , - - { "Sun-Style-Checksum", - &sun_style_checksum, - "\t\t", - "Use this for SPARC (Enterprise) platforms (especially): M3000, M4000, M9000" } , - - { "String-remark-escape", - &string_remark_escape, - "\t", - "Allow \"\\ (Quote-Backslash) to interrupt string parsing" } , - - { "Hex-remark-escape", - &hex_remark_escape, - "\t", - "Allow \\ (Backslash) to interrupt " - "hex-sequence parsing within a string" } , - - { "C-Style-string-escape", - &c_style_string_escape , - "\t", - "Allow \\n \\t and \\xx\\ for special chars in string parsing" } , - - { "Always-Headers", - &always_headers , - "\t\t", - "Override \"headerless\" and force to \"headers\"" } , - - { "Always-External", - &always_external , - "\t\t", - "Override \"headerless\" and \"headers\" and " - "force to \"external\"" } , - - { "Warn-if-Duplicate", - &verbose_dup_warning , - "\t", - "Display a WARNING message when a duplicate definition is made" } , - - { "Obsolete-FCode-Warning", - &obso_fcode_warning , - "\t", - "Display a WARNING message when an \"obsolete\" " - "(per the Standard) FCode is used" } , - - { "Trace-Conditionals", - &trace_conditionals, - "\t", - "Display ADVISORY messages about the state of " - "Conditional Tokenization" } , - - { "Upper-Case-Token-Names", - &upper_case_tokens, - "\t", - "Convert Token-Names to UPPER-Case" } , - - - { "Lower-Case-Token-Names", - &lower_case_tokens, - "\t", - "Convert Token-Names to lower-Case" } , - - - { "Big-End-PCI-Rev-Level", - &big_end_pci_image_rev, - "\t", - "Save the Vendor's Rev Level field of the PCI Header" - " in Big-Endian format" } , - - { "Ret-Stk-Interp", - &allow_ret_stk_interp, - "\t\t", - "Allow Return-Stack Operations during Interpretation" } , - - - /* Keep the "help" pseudo-flag last in the list */ - { "help", - &clflag_help, - /* Two extra tabs if the name is shorter than 8 chars */ - "\t\t\t", - "Print this \"Help\" message for the Special-Feature Flags" } + /* The clflag_tabs field takes at least one tab. + * If the name has fewer than 16 characters, + * stick in an extra tab, and yet another tab + * if the name is shorter than 8 characters + * to make the formatting of the "explanation" + * come out prettier. + */ + { "Local-Values", + &ibm_locals, + "\t\t", + "Support IBM-style Local Values (\"LV\"s)" }, + + { "LV-Legacy-Separator", + &ibm_locals_legacy_separator, + "\t", + "Allow Semicolon for Local Values Separator (\"Legacy\")" }, + + { "LV-Legacy-Message", + &ibm_legacy_separator_message, + "\t", + "Display a Message when Semicolon is used as the " + "Local Values Separator" }, + + { "ABORT-Quote", + &enable_abort_quote, + "\t\t", + "Allow ABORT\" macro" }, + + { "Sun-ABORT-Quote", + &sun_style_abort_quote, + "\t\t", + "ABORT\" with implicit IF ... THEN" }, + + { "ABORT-Quote-Throw", + &abort_quote_throw, + "\t", + "Use -2 THROW in an Abort\" phrase, rather than ABORT" }, + + { "Sun-Style-Checksum", + &sun_style_checksum, + "\t\t", + "Use this for SPARC (Enterprise) platforms (especially): M3000, M4000, M9000" + }, + + { "String-remark-escape", + &string_remark_escape, + "\t", + "Allow \"\\ (Quote-Backslash) to interrupt string parsing" }, + + { "Hex-remark-escape", + &hex_remark_escape, + "\t", + "Allow \\ (Backslash) to interrupt " + "hex-sequence parsing within a string" }, + + { "C-Style-string-escape", + &c_style_string_escape, + "\t", + "Allow \\n \\t and \\xx\\ for special chars in string parsing" }, + + { "Always-Headers", + &always_headers, + "\t\t", + "Override \"headerless\" and force to \"headers\"" }, + + { "Always-External", + &always_external, + "\t\t", + "Override \"headerless\" and \"headers\" and " + "force to \"external\"" }, + + { "Warn-if-Duplicate", + &verbose_dup_warning, + "\t", + "Display a WARNING message when a duplicate definition is made" }, + + { "Obsolete-FCode-Warning", + &obso_fcode_warning, + "\t", + "Display a WARNING message when an \"obsolete\" " + "(per the Standard) FCode is used" }, + + { "Trace-Conditionals", + &trace_conditionals, + "\t", + "Display ADVISORY messages about the state of " + "Conditional Tokenization" }, + + { "Upper-Case-Token-Names", + &upper_case_tokens, + "\t", + "Convert Token-Names to UPPER-Case" }, + + { "Lower-Case-Token-Names", + &lower_case_tokens, + "\t", + "Convert Token-Names to lower-Case" }, + + { "Big-End-PCI-Rev-Level", + &big_end_pci_image_rev, + "\t", + "Save the Vendor's Rev Level field of the PCI Header" + " in Big-Endian format" }, + + { "Ret-Stk-Interp", + &allow_ret_stk_interp, + "\t\t", + "Allow Return-Stack Operations during Interpretation" }, + + /* Keep the "help" pseudo-flag last in the list */ + { "help", + &clflag_help, + /* Two extra tabs if the name is shorter than 8 chars */ + "\t\t\t", + "Print this \"Help\" message for the Special-Feature Flags" } }; -static const int number_of_cl_flags = - sizeof(cl_flags_list)/sizeof(cl_flag_t); - +static const int number_of_cl_flags = sizeof(cl_flags_list) / sizeof(cl_flag_t); /* ************************************************************************** * @@ -327,40 +322,35 @@ static long int cl_flags_bit_map; * **************************************************************************** */ -static void adjust_case_flags( void) +static void adjust_case_flags(void) { - static bool *case_tokens[2] = { &upper_case_tokens, &lower_case_tokens }; - static bool *was_case_tk[2] = { &was_upper_case_tk, &was_lower_case_tk }; - int the_one = 0; - int the_other = 1; - - for ( ; the_one < 2 ; the_one++ , the_other-- ) - { - /* If one has changed state */ - if ( *(case_tokens[the_one]) != *(was_case_tk[the_one]) ) - { - if ( *(case_tokens[the_one]) ) - { - /* If it has gone to TRUE, force the other to FALSE. */ - *(case_tokens[the_other]) = FALSE; - /* and set force_tokens_case to TRUE */ - force_tokens_case = TRUE; - }else{ - /* If it has gone to FALSE turn force_tokens_case FALSE */ - force_tokens_case = FALSE; - } - if ( force_tokens_case ) - { - force_lower_case_tokens = lower_case_tokens; - } - break; /* Only one can have changed state. */ + static bool *case_tokens[2] = + { &upper_case_tokens, &lower_case_tokens }; + static bool *was_case_tk[2] = + { &was_upper_case_tk, &was_lower_case_tk }; + int the_one = 0; + int the_other = 1; + + for (; the_one < 2; the_one++, the_other--) { + /* If one has changed state */ + if (*(case_tokens[the_one]) != *(was_case_tk[the_one])) { + if (*(case_tokens[the_one])) { + /* If it has gone to TRUE, force the other to FALSE. */ + *(case_tokens[the_other]) = FALSE; + /* and set force_tokens_case to TRUE */ + force_tokens_case = TRUE; + } else { + /* If it has gone to FALSE turn force_tokens_case FALSE */ + force_tokens_case = FALSE; + } + if (force_tokens_case) { + force_lower_case_tokens = lower_case_tokens; + } + break; /* Only one can have changed state. */ + } } - } } - - - /* ************************************************************************** * * Function name: set_cl_flag @@ -408,67 +398,62 @@ static void adjust_case_flags( void) * Adjust the "upper/lower-case-tokens" flags if one has changed. * **************************************************************************** */ -static bool first_err_msg = TRUE; /* Need extra carr-ret for first err msg */ +static bool first_err_msg = TRUE; /* Need extra carr-ret for first err msg */ bool set_cl_flag(char *flag_name, bool from_src) { - bool retval = TRUE; + bool retval = TRUE; - was_upper_case_tk = upper_case_tokens; - was_lower_case_tk = lower_case_tokens; + was_upper_case_tk = upper_case_tokens; + was_lower_case_tk = lower_case_tokens; - if ( strlen(flag_name) > 3 ) - { - int indx; - bool flagval = TRUE; - char *compar = flag_name; + if (strlen(flag_name) > 3) { + int indx; + bool flagval = TRUE; + char *compar = flag_name; - if ( strncasecmp( flag_name, "no", 2) == 0 ) - { - flagval = FALSE; - compar += 2; - } - for ( indx = 0 ; indx < number_of_cl_flags ; indx++ ) - { - if ( strcasecmp( compar, cl_flags_list[indx].clflag_name ) == 0 ) - { - retval = FALSE; - *(cl_flags_list[indx].flag_var) = flagval; - - /* The "help" flag is the last one in the list */ - if ( indx != number_of_cl_flags - 1 ) - { - cl_flag_change = TRUE; + if (strncasecmp(flag_name, "no", 2) == 0) { + flagval = FALSE; + compar += 2; } - if ( from_src ) - { - tokenization_error(INFO, - "%sabling: %s\n", - flagval ? "En" : "Dis", cl_flags_list[indx].clflag_expln); + for (indx = 0; indx < number_of_cl_flags; indx++) { + if (strcasecmp(compar, cl_flags_list[indx].clflag_name) + == 0) { + retval = FALSE; + *(cl_flags_list[indx].flag_var) = flagval; + + /* The "help" flag is the last one in the list */ + if (indx != number_of_cl_flags - 1) { + cl_flag_change = TRUE; + } + if (from_src) { + tokenization_error(INFO, + "%sabling: %s\n", + flagval ? "En" : + "Dis", + cl_flags_list[indx]. + clflag_expln); + } + break; + } } - break; - } } - } - - if ( retval ) - { - const char* msg_txt = "Unknown Special-Feature Flag: %s\n" ; - if ( from_src ) - { - tokenization_error( TKERROR, (char *)msg_txt, flag_name); - }else{ - if ( first_err_msg ) - { - printf( "\n"); - first_err_msg = FALSE; - } - printf( msg_txt, flag_name); - } - } - - adjust_case_flags(); - - return ( retval ); + + if (retval) { + const char *msg_txt = "Unknown Special-Feature Flag: %s\n"; + if (from_src) { + tokenization_error(TKERROR, (char *)msg_txt, flag_name); + } else { + if (first_err_msg) { + printf("\n"); + first_err_msg = FALSE; + } + printf(msg_txt, flag_name); + } + } + + adjust_case_flags(); + + return (retval); } /* ************************************************************************** @@ -510,24 +495,23 @@ bool set_cl_flag(char *flag_name, bool from_src) void show_all_cl_flag_settings(bool from_src) { - const char* hdr_txt = "Special-Feature Flag settings:" ; - int indx; - - if ( from_src ) - { - tokenization_error(MESSAGE, (char *)hdr_txt); - }else{ - printf("\n%s\n", hdr_txt); - } - - for ( indx = 0 ; indx < (number_of_cl_flags - 1) ; indx++ ) - { - fprintf( from_src ? ERRMSG_DESTINATION : stdout , - "\t%s%s\n", - *(cl_flags_list[indx].flag_var) ? " " : "No" , - cl_flags_list[indx].clflag_name ); - } - if ( from_src ) fprintf( ERRMSG_DESTINATION, "\n"); + const char *hdr_txt = "Special-Feature Flag settings:"; + int indx; + + if (from_src) { + tokenization_error(MESSAGE, (char *)hdr_txt); + } else { + printf("\n%s\n", hdr_txt); + } + + for (indx = 0; indx < (number_of_cl_flags - 1); indx++) { + fprintf(from_src ? ERRMSG_DESTINATION : stdout, + "\t%s%s\n", + *(cl_flags_list[indx].flag_var) ? " " : "No", + cl_flags_list[indx].clflag_name); + } + if (from_src) + fprintf(ERRMSG_DESTINATION, "\n"); } /* ************************************************************************** @@ -554,13 +538,11 @@ void show_all_cl_flag_settings(bool from_src) void list_cl_flag_settings(void) { - if ( cl_flag_change ) - { - show_all_cl_flag_settings( FALSE); - } + if (cl_flag_change) { + show_all_cl_flag_settings(FALSE); + } } - /* ************************************************************************** * * Function name: list_cl_flag_names @@ -582,13 +564,12 @@ void list_cl_flag_settings(void) void list_cl_flag_names(void) { - int indx; + int indx; - printf("Valid Special-Feature Flags are:\n"); - for ( indx = 0 ; indx < number_of_cl_flags ; indx++ ) - { - printf("\t%s\n", cl_flags_list[indx].clflag_name ); - } + printf("Valid Special-Feature Flags are:\n"); + for (indx = 0; indx < number_of_cl_flags; indx++) { + printf("\t%s\n", cl_flags_list[indx].clflag_name); + } } /* ************************************************************************** @@ -632,30 +613,27 @@ void list_cl_flag_names(void) * **************************************************************************** */ -void cl_flags_help(void ) +void cl_flags_help(void) { - int indx; - - printf("\n" - "Special-Feature Flags usage:\n" - " -f FlagName to enable the feature associated with FlagName,\n" - "or\n" - " -f noFlagName to disable the feature.\n\n" - "%s Flag-Name\t\t Feature:\n\n", - cl_flag_change ? "Setting" : "Default" ); - - for ( indx = 0 ; indx < number_of_cl_flags ; indx++ ) - { - printf(" %s %s%s%s\n", - *(cl_flags_list[indx].flag_var) ? " " : "no" , - cl_flags_list[indx].clflag_name, - cl_flags_list[indx].clflag_tabs, - cl_flags_list[indx].clflag_expln); - } - -} + int indx; + printf("\n" + "Special-Feature Flags usage:\n" + " -f FlagName to enable the feature associated with FlagName,\n" + "or\n" + " -f noFlagName to disable the feature.\n\n" + "%s Flag-Name\t\t Feature:\n\n", + cl_flag_change ? "Setting" : "Default"); + + for (indx = 0; indx < number_of_cl_flags; indx++) { + printf(" %s %s%s%s\n", + *(cl_flags_list[indx].flag_var) ? " " : "no", + cl_flags_list[indx].clflag_name, + cl_flags_list[indx].clflag_tabs, + cl_flags_list[indx].clflag_expln); + } +} /* ************************************************************************** * @@ -686,18 +664,16 @@ void cl_flags_help(void ) void save_cl_flags(void) { - int indx; - long int moving_bit = 1; - - cl_flags_bit_map = 0; - for ( indx = 0 ; indx < (number_of_cl_flags - 1) ; indx++ ) - { - if ( *(cl_flags_list[indx].flag_var) ) - { - cl_flags_bit_map |= moving_bit; /* The moving finger writes, */ + int indx; + long int moving_bit = 1; + + cl_flags_bit_map = 0; + for (indx = 0; indx < (number_of_cl_flags - 1); indx++) { + if (*(cl_flags_list[indx].flag_var)) { + cl_flags_bit_map |= moving_bit; /* The moving finger writes, */ + } + moving_bit <<= 1; /* and having writ, moves on. */ } - moving_bit <<= 1; /* and having writ, moves on. */ - } } /* ************************************************************************** @@ -729,13 +705,12 @@ void save_cl_flags(void) void reset_cl_flags(void) { - int indx; - long int moving_bit = 1; - - for ( indx = 0 ; indx < (number_of_cl_flags - 1) ; indx++ ) - { - *(cl_flags_list[indx].flag_var) = - BOOLVAL( cl_flags_bit_map & moving_bit) ; - moving_bit <<= 1; - } + int indx; + long int moving_bit = 1; + + for (indx = 0; indx < (number_of_cl_flags - 1); indx++) { + *(cl_flags_list[indx].flag_var) = + BOOLVAL(cl_flags_bit_map & moving_bit); + moving_bit <<= 1; + } } diff --git a/toke/clflags.h b/toke/clflags.h index d9eac86..6afe528 100644 --- a/toke/clflags.h +++ b/toke/clflags.h @@ -92,14 +92,12 @@ #include "types.h" -typedef struct cl_flag - { - char *clflag_name; - bool *flag_var; - char *clflag_tabs; - char *clflag_expln; - } cl_flag_t ; - +typedef struct cl_flag { + char *clflag_name; + bool *flag_var; + char *clflag_tabs; + char *clflag_expln; +} cl_flag_t; /* ************************************************************************** * @@ -144,4 +142,4 @@ void list_cl_flag_settings(void); void save_cl_flags(void); void reset_cl_flags(void); -#endif /* _TOKE_CLFLAGS_H */ +#endif /* _TOKE_CLFLAGS_H */ diff --git a/toke/conditl.c b/toke/conditl.c index 062291b..d30f135 100644 --- a/toke/conditl.c +++ b/toke/conditl.c @@ -111,7 +111,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Support function: is_a_type @@ -128,28 +127,28 @@ * **************************************************************************** */ - -static bool is_a_type( char *tname, fwtoken fw_type) +static bool is_a_type(char *tname, fwtoken fw_type) { - bool retval = FALSE; - tic_fwt_hdr_t *found = (tic_fwt_hdr_t *)lookup_shared_f_exec_word( tname ); - if ( found != NULL ) - { - if ( found->pfield.fw_token == fw_type ) retval = TRUE; - } - return ( retval ); + bool retval = FALSE; + tic_fwt_hdr_t *found = + (tic_fwt_hdr_t *) lookup_shared_f_exec_word(tname); + if (found != NULL) { + if (found->pfield.fw_token == fw_type) + retval = TRUE; + } + return (retval); } -static bool is_a_then( char *a_word) +static bool is_a_then(char *a_word) { - bool retval = is_a_type( a_word, CONDL_ENDER); - return ( retval ); + bool retval = is_a_type(a_word, CONDL_ENDER); + return (retval); } -static bool is_an_else( char *a_word) +static bool is_an_else(char *a_word) { - bool retval = is_a_type( a_word, CONDL_ELSE); - return ( retval ); + bool retval = is_a_type(a_word, CONDL_ELSE); + return (retval); } /* ************************************************************************** @@ -176,7 +175,6 @@ static bool already_ignoring = FALSE; * **************************************************************************** */ - /* ************************************************************************** * * We also need a few common routines to pass as "Ignoring" functions @@ -193,7 +191,7 @@ static bool already_ignoring = FALSE; * the "word" is strictly an input token, delimited by whitespace. * **************************************************************************** */ - + /* ************************************************************************** * * Function name: skip_a_word @@ -210,9 +208,9 @@ static bool already_ignoring = FALSE; * **************************************************************************** */ -void skip_a_word( tic_bool_param_t pfield ) +void skip_a_word(tic_bool_param_t pfield) { - /* signed long wlen = */ get_word(); + /* signed long wlen = */ get_word(); } /* ************************************************************************** @@ -238,9 +236,9 @@ void skip_a_word( tic_bool_param_t pfield ) * get_word_in_line() will check and report if no word on same line. * **************************************************************************** */ -void skip_a_word_in_line( tic_bool_param_t pfield ) +void skip_a_word_in_line(tic_bool_param_t pfield) { - /* bool isokay = */ get_word_in_line( statbuf); + /* bool isokay = */ get_word_in_line(statbuf); } /* ************************************************************************** @@ -271,17 +269,15 @@ void skip_a_word_in_line( tic_bool_param_t pfield ) * **************************************************************************** */ -void skip_two_words_in_line( tic_bool_param_t pfield ) +void skip_two_words_in_line(tic_bool_param_t pfield) { - char *func_cpy = strupr( strdup( statbuf)); - if ( get_word_in_line( func_cpy) ) - { - /* bool isokay = */ get_word_in_line( func_cpy); - } - free( func_cpy); + char *func_cpy = strupr(strdup(statbuf)); + if (get_word_in_line(func_cpy)) { + /* bool isokay = */ get_word_in_line(func_cpy); + } + free(func_cpy); } - /* ************************************************************************** * * Function name: ignore_one_word @@ -319,22 +315,21 @@ void skip_two_words_in_line( tic_bool_param_t pfield ) * **************************************************************************** */ -static void ignore_one_word( char *tname) +static void ignore_one_word(char *tname) { - tic_bool_hdr_t *found = (tic_bool_hdr_t *)lookup_word( tname, NULL, NULL); - if ( found != NULL ) - { - if ( found->ign_func != NULL ) - { - bool save_already_ignoring = already_ignoring; - already_ignoring = TRUE ; - tic_found = (tic_hdr_t *)found; - - found->ign_func( found->pfield); - - already_ignoring = save_already_ignoring; + tic_bool_hdr_t *found = + (tic_bool_hdr_t *) lookup_word(tname, NULL, NULL); + if (found != NULL) { + if (found->ign_func != NULL) { + bool save_already_ignoring = already_ignoring; + already_ignoring = TRUE; + tic_found = (tic_hdr_t *) found; + + found->ign_func(found->pfield); + + already_ignoring = save_already_ignoring; + } } - } } /* ************************************************************************** @@ -422,112 +417,109 @@ static void ignore_one_word( char *tname) * **************************************************************************** */ -static void conditionally_tokenize( bool cond, bool alr_ign ) +static void conditionally_tokenize(bool cond, bool alr_ign) { - - signed long wlen; - - /* Note: The following variables *must* remain within - * the scope of this routine; a distinct instance - * is needed each time this routine is re-entered - * (aka "a nested call"). - */ - bool ignoring; - bool first_else = TRUE; /* The "else" we see is the first. */ - bool not_done = TRUE; - unsigned int cond_strt_lineno = lineno; - char *cond_strt_ifile_nam = strdup( iname); - - ignoring = BOOLVAL( ( cond == FALSE ) || ( alr_ign != FALSE ) ); - - if ( trace_conditionals ) - { - char *cond_val = cond ? "True" : "False" ; - char *cond_junct = alr_ign ? ", but Already " : "; "; - char *processg = ignoring ? "Ignoring" : "Processing" ; - tokenization_error( INFO, - "Tokenization-Condition is %s%s%s.\n", - cond_val, cond_junct, processg); - } - - while ( not_done ) - { - wlen = get_word(); - if ( wlen == 0 ) - { - continue; - } - if ( wlen < 0 ) - { - tokenization_error( TKERROR, - "Conditional without conclusion; started"); - just_where_started( cond_strt_ifile_nam, cond_strt_lineno); - not_done = FALSE ; - continue; - } + signed long wlen; - if ( is_a_then ( statbuf ) ) - { - if ( trace_conditionals ) - { - tokenization_error( INFO, - "Concluding Conditional"); - just_started_at( cond_strt_ifile_nam, cond_strt_lineno); - } - not_done = FALSE ; - continue; + /* Note: The following variables *must* remain within + * the scope of this routine; a distinct instance + * is needed each time this routine is re-entered + * (aka "a nested call"). + */ + bool ignoring; + bool first_else = TRUE; /* The "else" we see is the first. */ + bool not_done = TRUE; + unsigned int cond_strt_lineno = lineno; + char *cond_strt_ifile_nam = strdup(iname); + + ignoring = BOOLVAL((cond == FALSE) || (alr_ign != FALSE)); + + if (trace_conditionals) { + char *cond_val = cond ? "True" : "False"; + char *cond_junct = alr_ign ? ", but Already " : "; "; + char *processg = ignoring ? "Ignoring" : "Processing"; + tokenization_error(INFO, + "Tokenization-Condition is %s%s%s.\n", + cond_val, cond_junct, processg); } - if ( is_an_else( statbuf ) ) - { - if ( ! alr_ign ) - { - if ( first_else ) - { - ignoring = INVERSE( ignoring); + while (not_done) { + wlen = get_word(); + if (wlen == 0) { + continue; } - } - - if ( ! first_else ) - { - int severity = ignoring ? WARNING : TKERROR ; - char *the_scop = ignoring ? "(ignored)" : "the" ; - tokenization_error( severity, "Multiple %s directives " - "within %s scope of the Conditional", - strupr(statbuf), the_scop); - just_started_at( cond_strt_ifile_nam, cond_strt_lineno); - }else{ - first_else = FALSE; - if ( trace_conditionals ) - { - char *when_enc = alr_ign ? "While already" : "Now" ; - char *processg = alr_ign ? "ignoring" : - ignoring ? "Ignoring" : "Processing" ; - char *enc = alr_ign ? ", e" : ". E" ; - - tokenization_error( INFO, - "%s %s%sncountered %s belonging to Conditional", - when_enc, processg, enc, strupr(statbuf) ); - just_started_at( cond_strt_ifile_nam, cond_strt_lineno); + + if (wlen < 0) { + tokenization_error(TKERROR, + "Conditional without conclusion; started"); + just_where_started(cond_strt_ifile_nam, + cond_strt_lineno); + not_done = FALSE; + continue; } - } - continue; - } + if (is_a_then(statbuf)) { + if (trace_conditionals) { + tokenization_error(INFO, + "Concluding Conditional"); + just_started_at(cond_strt_ifile_nam, + cond_strt_lineno); + } + not_done = FALSE; + continue; + } - /* If we are ignoring source input, for whatever reason, we still - * need to be sensitive to the nesting of Conditional Operators - * and some other commands and directives, as indicated... - */ - if ( ignoring ) - { - ignore_one_word( statbuf ); - }else{ - /* And if we're not ignoring source input, process it! */ - tokenize_one_word ( wlen ); + if (is_an_else(statbuf)) { + if (!alr_ign) { + if (first_else) { + ignoring = INVERSE(ignoring); + } + } + + if (!first_else) { + int severity = ignoring ? WARNING : TKERROR; + char *the_scop = ignoring ? "(ignored)" : "the"; + tokenization_error(severity, + "Multiple %s directives " + "within %s scope of the Conditional", + strupr(statbuf), the_scop); + just_started_at(cond_strt_ifile_nam, + cond_strt_lineno); + } else { + first_else = FALSE; + if (trace_conditionals) { + char *when_enc = + alr_ign ? "While already" : "Now"; + char *processg = + alr_ign ? "ignoring" : ignoring ? + "Ignoring" : "Processing"; + char *enc = alr_ign ? ", e" : ". E"; + + tokenization_error(INFO, + "%s %s%sncountered %s belonging to Conditional", + when_enc, processg, + enc, + strupr(statbuf)); + just_started_at(cond_strt_ifile_nam, + cond_strt_lineno); + } + } + + continue; + } + + /* If we are ignoring source input, for whatever reason, we still + * need to be sensitive to the nesting of Conditional Operators + * and some other commands and directives, as indicated... + */ + if (ignoring) { + ignore_one_word(statbuf); + } else { + /* And if we're not ignoring source input, process it! */ + tokenize_one_word(wlen); + } } - } } /* ************************************************************************** @@ -592,23 +584,19 @@ static void conditionally_tokenize( bool cond, bool alr_ign ) * **************************************************************************** */ -static void conditional_word_in_line( bool alr_ign, - bool exist_test, - bool (*exist_funct)() ) +static void conditional_word_in_line(bool alr_ign, + bool exist_test, bool (*exist_funct)()) { - if ( get_word_in_line( statbuf) ) - { - bool cond = FALSE; - if ( INVERSE( alr_ign) ) - { - bool exists = exist_funct( statbuf); - cond = BOOLVAL( exists == exist_test); + if(get_word_in_line(statbuf)) { + bool cond = FALSE; + if (INVERSE(alr_ign)) { + bool exists = exist_funct(statbuf); + cond = BOOLVAL(exists == exist_test); + } + conditionally_tokenize(cond, alr_ign); } - conditionally_tokenize( cond, alr_ign ); - } } - /* ************************************************************************** * * Function name: if_exists @@ -624,10 +612,10 @@ static void conditional_word_in_line( bool alr_ign, * **************************************************************************** */ -static void if_exists( tic_param_t pfield ) +static void if_exists(tic_param_t pfield) { - bool alr_ign = *pfield.bool_ptr; - conditional_word_in_line( alr_ign, TRUE, exists_in_current ); + bool alr_ign = *pfield.bool_ptr; + conditional_word_in_line(alr_ign, TRUE, exists_in_current); } /* ************************************************************************** @@ -646,10 +634,10 @@ static void if_exists( tic_param_t pfield ) * **************************************************************************** */ -static void if_not_exist( tic_bool_param_t pfield ) +static void if_not_exist(tic_bool_param_t pfield) { - bool alr_ign = *pfield.bool_ptr; - conditional_word_in_line( alr_ign, FALSE, exists_in_current ); + bool alr_ign = *pfield.bool_ptr; + conditional_word_in_line(alr_ign, FALSE, exists_in_current); } /* ************************************************************************** @@ -663,10 +651,10 @@ static void if_not_exist( tic_bool_param_t pfield ) * **************************************************************************** */ -static void if_defined( tic_bool_param_t pfield ) +static void if_defined(tic_bool_param_t pfield) { - bool alr_ign = *pfield.bool_ptr; - conditional_word_in_line( alr_ign, TRUE, exists_as_user_symbol ); + bool alr_ign = *pfield.bool_ptr; + conditional_word_in_line(alr_ign, TRUE, exists_as_user_symbol); } /* ************************************************************************** @@ -680,13 +668,12 @@ static void if_defined( tic_bool_param_t pfield ) * **************************************************************************** */ -static void if_not_defined( tic_bool_param_t pfield ) +static void if_not_defined(tic_bool_param_t pfield) { - bool alr_ign = *pfield.bool_ptr; - conditional_word_in_line( alr_ign, FALSE, exists_as_user_symbol ); + bool alr_ign = *pfield.bool_ptr; + conditional_word_in_line(alr_ign, FALSE, exists_as_user_symbol); } - /* ************************************************************************** * * Function name: if_from_stack @@ -704,20 +691,18 @@ static void if_not_defined( tic_bool_param_t pfield ) * **************************************************************************** */ -static void if_from_stack( tic_bool_param_t pfield ) +static void if_from_stack(tic_bool_param_t pfield) { - bool alr_ign = *pfield.bool_ptr; - bool cond = FALSE; - - if ( ! alr_ign ) - { - long num = dpop(); - if (num != 0) - { - cond = TRUE; + bool alr_ign = *pfield.bool_ptr; + bool cond = FALSE; + + if (!alr_ign) { + long num = dpop(); + if (num != 0) { + cond = TRUE; + } } - } - conditionally_tokenize( cond, alr_ign ); + conditionally_tokenize(cond, alr_ign); } /* For future functions, use conditl.BlankTemplate.c */ @@ -732,25 +717,24 @@ static void if_from_stack( tic_bool_param_t pfield ) #define ADD_CONDL(str, func ) BUILTIN_BOOL_TIC(str, func, already_ignoring ) static tic_bool_hdr_t conditionals_vocab_tbl[] = { - ADD_CONDL ("[ifexist]" , if_exists ) , - ADD_CONDL ("[ifexists]" , if_exists ) , - ADD_CONDL ("#ifexist" , if_exists ) , - ADD_CONDL ("#ifexists" , if_exists ) , - ADD_CONDL ("[#ifexist]" , if_exists ) , - ADD_CONDL ("[#ifexists]" , if_exists ) , - ADD_CONDL ("[ifnexist]" , if_not_exist ) , - ADD_CONDL ("#ifnexist" , if_not_exist ) , - ADD_CONDL ("[#ifnexist]" , if_not_exist ) , - ADD_CONDL ("[ifdef]" , if_defined ) , - ADD_CONDL ("#ifdef" , if_defined ) , - ADD_CONDL ("[#ifdef]" , if_defined ) , - ADD_CONDL ("[ifndef]" , if_not_defined ) , - ADD_CONDL ("#ifndef" , if_not_defined ) , - ADD_CONDL ("[#ifndef]" , if_not_defined ) , - ADD_CONDL ("[if]" , if_from_stack ) + ADD_CONDL("[ifexist]", if_exists), + ADD_CONDL("[ifexists]", if_exists), + ADD_CONDL("#ifexist", if_exists), + ADD_CONDL("#ifexists", if_exists), + ADD_CONDL("[#ifexist]", if_exists), + ADD_CONDL("[#ifexists]", if_exists), + ADD_CONDL("[ifnexist]", if_not_exist), + ADD_CONDL("#ifnexist", if_not_exist), + ADD_CONDL("[#ifnexist]", if_not_exist), + ADD_CONDL("[ifdef]", if_defined), + ADD_CONDL("#ifdef", if_defined), + ADD_CONDL("[#ifdef]", if_defined), + ADD_CONDL("[ifndef]", if_not_defined), + ADD_CONDL("#ifndef", if_not_defined), + ADD_CONDL("[#ifndef]", if_not_defined), + ADD_CONDL("[if]", if_from_stack) }; - /* ************************************************************************** * * Function name: init_conditionals_vocab @@ -760,13 +744,11 @@ static tic_bool_hdr_t conditionals_vocab_tbl[] = { * **************************************************************************** */ -void init_conditionals_vocab( tic_hdr_t **tic_vocab_ptr ) +void init_conditionals_vocab(tic_hdr_t ** tic_vocab_ptr) { - static const int conditionals_vocab_max_indx = - sizeof(conditionals_vocab_tbl)/sizeof(tic_bool_hdr_t); + static const int conditionals_vocab_max_indx = + sizeof(conditionals_vocab_tbl) / sizeof(tic_bool_hdr_t); - init_tic_vocab( (tic_hdr_t *)conditionals_vocab_tbl, - conditionals_vocab_max_indx, - tic_vocab_ptr ); + init_tic_vocab((tic_hdr_t *) conditionals_vocab_tbl, + conditionals_vocab_max_indx, tic_vocab_ptr); } - diff --git a/toke/conditl.h b/toke/conditl.h index b6cb7e3..bbcae51 100644 --- a/toke/conditl.h +++ b/toke/conditl.h @@ -37,10 +37,10 @@ #include "types.h" #include "ticvocab.h" -void init_conditionals_vocab( tic_hdr_t **tic_vocab_ptr ); +void init_conditionals_vocab(tic_hdr_t ** tic_vocab_ptr); -void skip_a_word( tic_bool_param_t pfield ); -void skip_a_word_in_line( tic_bool_param_t pfield ); -void skip_two_words_in_line( tic_bool_param_t pfield ); +void skip_a_word(tic_bool_param_t pfield); +void skip_a_word_in_line(tic_bool_param_t pfield); +void skip_two_words_in_line(tic_bool_param_t pfield); -#endif /* _TOKE_CONDITL_H */ +#endif /* _TOKE_CONDITL_H */ diff --git a/toke/devnode.c b/toke/devnode.c index 835574f..51929ff 100644 --- a/toke/devnode.c +++ b/toke/devnode.c @@ -50,7 +50,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Functions Exported: @@ -76,8 +75,6 @@ * **************************************************************************** */ - - #include #include #include @@ -91,7 +88,6 @@ #include "stream.h" #include "ticvocab.h" - /* ************************************************************************** * * Tokenization starts with an implicit "new-device" in effect. @@ -103,12 +99,12 @@ char default_top_dev_ifile_name[] = "Start of tokenization"; static device_node_t top_level_dev_node = { - NULL , /* parent_node */ - default_top_dev_ifile_name , /* ifile_name. + NULL, /* parent_node */ + default_top_dev_ifile_name, /* ifile_name. * Something to show, Just In Case */ - 0 , /* line_no */ - NULL , /* tokens_vocab */ + 0, /* line_no */ + NULL, /* tokens_vocab */ }; /* ************************************************************************** @@ -123,7 +119,6 @@ static device_node_t top_level_dev_node = { device_node_t *current_device_node = &top_level_dev_node; tic_hdr_t **current_definitions = &(top_level_dev_node.tokens_vocab); - /* ************************************************************************** * * Internal Static Variables @@ -140,13 +135,12 @@ tic_hdr_t **current_definitions = &(top_level_dev_node.tokens_vocab); * **************************************************************************** */ -static char in_what_buffr[50]; /* Ought to be more than enough. */ +static char in_what_buffr[50]; /* Ought to be more than enough. */ static bool show_where = FALSE; static bool show_which; static int in_what_line; static char *in_what_file; - /* ************************************************************************** * * Function name: dev_vocab_control_struct_check @@ -173,21 +167,19 @@ static char *in_what_file; * **************************************************************************** */ -static void dev_vocab_control_struct_check( void) +static void dev_vocab_control_struct_check(void) { - char *ccs_messg; - - ccs_messg = safe_malloc(strlen(statbuf) + 32, - "Device-Node control-structure check"); - - strcpy( ccs_messg, statbuf ); - strupr( ccs_messg); - strcat( ccs_messg, " encountered"); - announce_control_structs( WARNING, ccs_messg, 0 ); - free( ccs_messg); -} + char *ccs_messg; + ccs_messg = safe_malloc(strlen(statbuf) + 32, + "Device-Node control-structure check"); + strcpy(ccs_messg, statbuf); + strupr(ccs_messg); + strcat(ccs_messg, " encountered"); + announce_control_structs(WARNING, ccs_messg, 0); + free(ccs_messg); +} /* ************************************************************************** * @@ -229,40 +221,39 @@ static void dev_vocab_control_struct_check( void) * **************************************************************************** */ -void new_device_vocab( void ) +void new_device_vocab(void) { - device_node_t *new_node_data; + device_node_t *new_node_data; - dev_vocab_control_struct_check(); + dev_vocab_control_struct_check(); - /* Advisory message will mention previous device-node - * if there was one. Either way starts out the same: - */ + /* Advisory message will mention previous device-node + * if there was one. Either way starts out the same: + */ #define NEW_DEV_MSG_START "Encountered %s. Starting new device-node." - if ( current_device_node == &top_level_dev_node ) - { - tokenization_error(INFO, NEW_DEV_MSG_START "\n", statbuf ); - }else{ - tokenization_error(INFO, NEW_DEV_MSG_START - " Suspending definitions of parent-device node", statbuf ); - started_at( current_device_node->ifile_name, - current_device_node->line_no ); - } - - /* Now to business... */ - new_node_data = safe_malloc( sizeof(device_node_t), - "creating new-device vocab data" ); - new_node_data->parent_node = current_device_node; - new_node_data->ifile_name = strdup(iname); - new_node_data->line_no = lineno; - new_node_data->tokens_vocab = NULL; - - current_device_node = new_node_data; - - current_definitions = &(current_device_node->tokens_vocab); -} + if (current_device_node == &top_level_dev_node) { + tokenization_error(INFO, NEW_DEV_MSG_START "\n", statbuf); + } else { + tokenization_error(INFO, NEW_DEV_MSG_START + " Suspending definitions of parent-device node", + statbuf); + started_at(current_device_node->ifile_name, + current_device_node->line_no); + } + + /* Now to business... */ + new_node_data = safe_malloc(sizeof(device_node_t), + "creating new-device vocab data"); + new_node_data->parent_node = current_device_node; + new_node_data->ifile_name = strdup(iname); + new_node_data->line_no = lineno; + new_node_data->tokens_vocab = NULL; + current_device_node = new_node_data; + + current_definitions = &(current_device_node->tokens_vocab); +} /* ************************************************************************** * @@ -295,19 +286,18 @@ void new_device_vocab( void ) * **************************************************************************** */ -void delete_device_vocab( void ) +void delete_device_vocab(void) { - reset_tic_vocab( current_definitions, NULL ); + reset_tic_vocab(current_definitions, NULL); - if ( current_device_node != &top_level_dev_node ) - { - device_node_t *temp_node = current_device_node; - current_device_node = current_device_node->parent_node; - free( temp_node->ifile_name ); - free(temp_node); - } + if (current_device_node != &top_level_dev_node) { + device_node_t *temp_node = current_device_node; + current_device_node = current_device_node->parent_node; + free(temp_node->ifile_name); + free(temp_node); + } - current_definitions = &(current_device_node->tokens_vocab); + current_definitions = &(current_device_node->tokens_vocab); } /* ************************************************************************** @@ -346,52 +336,48 @@ void delete_device_vocab( void ) * **************************************************************************** */ -void finish_device_vocab( void ) +void finish_device_vocab(void) { - bool at_top_level; - - dev_vocab_control_struct_check(); - - /* We never remove the top-level device-node vocabulary, - * so we need to test whether we're about to. - */ - - at_top_level = BOOLVAL( current_device_node == &top_level_dev_node ); - if ( at_top_level ) - { - tokenization_error( TKERROR, - "Encountered %s without corresponding NEW-DEVICE. " - "Resetting definitions since start of tokenization.\n", - statbuf ); - }else{ - tokenization_error(INFO, - "Encountered %s. Resetting definitions of device node", - statbuf ); - started_at( current_device_node->ifile_name, - current_device_node->line_no ); - } - - /* Now to business... */ - delete_device_vocab(); - - /* Did we just get to the top-level device-node vocabulary - * when we weren't before? - */ - if ( INVERSE(at_top_level) ) - { - if ( current_device_node == &top_level_dev_node ) - { - tokenization_error(INFO, - "Resuming definitions since start of tokenization.\n" ); - }else{ - tokenization_error(INFO, - "Resuming definitions of parent device-node" ); - started_at( current_device_node->ifile_name, - current_device_node->line_no ); + bool at_top_level; + + dev_vocab_control_struct_check(); + + /* We never remove the top-level device-node vocabulary, + * so we need to test whether we're about to. + */ + + at_top_level = BOOLVAL(current_device_node == &top_level_dev_node); + if (at_top_level) { + tokenization_error(TKERROR, + "Encountered %s without corresponding NEW-DEVICE. " + "Resetting definitions since start of tokenization.\n", + statbuf); + } else { + tokenization_error(INFO, + "Encountered %s. Resetting definitions of device node", + statbuf); + started_at(current_device_node->ifile_name, + current_device_node->line_no); } - } -} + /* Now to business... */ + delete_device_vocab(); + + /* Did we just get to the top-level device-node vocabulary + * when we weren't before? + */ + if (INVERSE(at_top_level)) { + if (current_device_node == &top_level_dev_node) { + tokenization_error(INFO, + "Resuming definitions since start of tokenization.\n"); + } else { + tokenization_error(INFO, + "Resuming definitions of parent device-node"); + started_at(current_device_node->ifile_name, + current_device_node->line_no); + } + } +} /* ************************************************************************** * @@ -454,30 +440,26 @@ void finish_device_vocab( void ) * **************************************************************************** */ -char *in_what_node(device_node_t *the_node) +char *in_what_node(device_node_t * the_node) { - bool top_node = BOOLVAL( the_node == &top_level_dev_node); - bool curr_node = BOOLVAL( the_node == current_device_node); - bool known_node = BOOLVAL( top_node || curr_node ); - bool no_line = BOOLVAL( the_node->line_no == 0); - - show_where = INVERSE( no_line ); - show_which = known_node; - in_what_line = the_node->line_no; - in_what_file = the_node->ifile_name; - - sprintf( in_what_buffr, "in the%s device-node%s", - INVERSE( known_node ) ? "" - : top_node ? " top-level" : " current" , - - no_line ? ".\n" - : known_node ? ", which began" : "" ); - - - return( in_what_buffr); + bool top_node = BOOLVAL(the_node == &top_level_dev_node); + bool curr_node = BOOLVAL(the_node == current_device_node); + bool known_node = BOOLVAL(top_node || curr_node); + bool no_line = BOOLVAL(the_node->line_no == 0); + + show_where = INVERSE(no_line); + show_which = known_node; + in_what_line = the_node->line_no; + in_what_file = the_node->ifile_name; + + sprintf(in_what_buffr, "in the%s device-node%s", + INVERSE(known_node) ? "" + : top_node ? " top-level" : " current", + no_line ? ".\n" : known_node ? ", which began" : ""); + + return (in_what_buffr); } - /* ************************************************************************** * * Function name: show_node_start @@ -510,22 +492,18 @@ char *in_what_node(device_node_t *the_node) * **************************************************************************** */ -void show_node_start( void) +void show_node_start(void) { - if ( show_where) - { - if ( show_which ) - { - just_where_started( in_what_file, in_what_line); - }else{ - just_started_at( in_what_file, in_what_line); + if (show_where) { + if (show_which) { + just_where_started(in_what_file, in_what_line); + } else { + just_started_at(in_what_file, in_what_line); + } + show_where = FALSE; } - show_where = FALSE; - } } - - /* ************************************************************************** * * Function name: exists_in_ancestor @@ -559,37 +537,33 @@ void show_node_start( void) * **************************************************************************** */ -bool exists_in_ancestor( char *m_name) +bool exists_in_ancestor(char *m_name) { - tic_hdr_t *found; - bool retval = FALSE; - if ( current_device_node != NULL ) - { - device_node_t *grandpa = current_device_node->parent_node; - - if ( scope_is_global ) grandpa = current_device_node; - - for ( ; grandpa != NULL; grandpa = grandpa->parent_node ) - { - found = lookup_tic_entry( m_name, grandpa->tokens_vocab); - if ( found != NULL ) - { - retval = TRUE; - break; - } - } - if ( grandpa != NULL ) - { - char as_what_buf[AS_WHAT_BUF_SIZE] = ""; - if ( as_a_what( found->fword_defr, as_what_buf) ) - { - strcat( as_what_buf, " "); - } - tokenization_error(INFO, "%s is defined %s%s", m_name, - as_what_buf, in_what_node( grandpa) ); - show_node_start(); + tic_hdr_t *found; + bool retval = FALSE; + if (current_device_node != NULL) { + device_node_t *grandpa = current_device_node->parent_node; + + if (scope_is_global) + grandpa = current_device_node; + + for (; grandpa != NULL; grandpa = grandpa->parent_node) { + found = lookup_tic_entry(m_name, grandpa->tokens_vocab); + if (found != NULL) { + retval = TRUE; + break; + } + } + if (grandpa != NULL) { + char as_what_buf[AS_WHAT_BUF_SIZE] = ""; + if (as_a_what(found->fword_defr, as_what_buf)) { + strcat(as_what_buf, " "); + } + tokenization_error(INFO, "%s is defined %s%s", m_name, + as_what_buf, in_what_node(grandpa)); + show_node_start(); + } } - } - return(retval ); + return (retval); } diff --git a/toke/devnode.h b/toke/devnode.h index 26bc768..e98e9d5 100644 --- a/toke/devnode.h +++ b/toke/devnode.h @@ -54,13 +54,12 @@ **************************************************************************** */ typedef struct device_node { - struct device_node *parent_node ; - char *ifile_name ; - unsigned int line_no ; - tic_hdr_t *tokens_vocab ; + struct device_node *parent_node; + char *ifile_name; + unsigned int line_no; + tic_hdr_t *tokens_vocab; } device_node_t; - /* ************************************************************************** * * * Global Variables Exported @@ -76,11 +75,11 @@ extern tic_hdr_t **current_definitions; * Function Prototypes / Functions Exported: * **************************************************************************** */ -void new_device_vocab( void ); -void delete_device_vocab( void ); -void finish_device_vocab( void ); -char *in_what_node(device_node_t *the_node); -void show_node_start( void); -bool exists_in_ancestor( char *m_name); +void new_device_vocab(void); +void delete_device_vocab(void); +void finish_device_vocab(void); +char *in_what_node(device_node_t * the_node); +void show_node_start(void); +bool exists_in_ancestor(char *m_name); -#endif /* _TOKE_DEVNODE_H */ +#endif /* _TOKE_DEVNODE_H */ diff --git a/toke/dictionary.c b/toke/dictionary.c index eed5389..05d1e41 100644 --- a/toke/dictionary.c +++ b/toke/dictionary.c @@ -98,7 +98,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Global Variables Exported @@ -118,17 +117,17 @@ **************************************************************************** */ bool scope_is_global = FALSE; -bool define_token = TRUE; /* TRUE = Normal definition process; - * FALSE when definition is an Error. - * We enter definition state anyway, - * but must still suppress: - * (1) adding an entry for the token - * to the vocab, - * (2) "hiding" it at first, and - * (3) "revealing" it later. - * - * Makes for more "normal" error- detection... - */ +bool define_token = TRUE; /* TRUE = Normal definition process; + * FALSE when definition is an Error. + * We enter definition state anyway, + * but must still suppress: + * (1) adding an entry for the token + * to the vocab, + * (2) "hiding" it at first, and + * (3) "revealing" it later. + * + * Makes for more "normal" error- detection... + */ /* ************************************************************************** * @@ -218,12 +217,11 @@ bool define_token = TRUE; /* TRUE = Normal definition process; * **************************************************************************** */ -static tic_hdr_t *global_voc_dict_ptr = NULL; /* The Global Vocabulary */ -static tic_hdr_t *fc_tokens_list_ender = NULL; /* Tokens search ends here */ -static tic_hdr_t *fc_tokens_list_start = NULL; /* Start the search here */ -static tic_hdr_t *shared_fwords_ender = NULL; /* Shared FWords search end */ -static tic_hdr_t *global_voc_reset_ptr = NULL; /* Reset-point for G.V. */ - +static tic_hdr_t *global_voc_dict_ptr = NULL; /* The Global Vocabulary */ +static tic_hdr_t *fc_tokens_list_ender = NULL; /* Tokens search ends here */ +static tic_hdr_t *fc_tokens_list_start = NULL; /* Start the search here */ +static tic_hdr_t *shared_fwords_ender = NULL; /* Shared FWords search end */ +static tic_hdr_t *global_voc_reset_ptr = NULL; /* Reset-point for G.V. */ /* ************************************************************************** * @@ -243,12 +241,12 @@ static tic_hdr_t *global_voc_reset_ptr = NULL; /* Reset-point for G.V. */ * **************************************************************************** */ -tic_hdr_t *lookup_core_word( char *tname) +tic_hdr_t *lookup_core_word(char *tname) { - tic_hdr_t *found ; + tic_hdr_t *found; - found = lookup_tic_entry( tname, global_voc_dict_ptr); - return ( found ) ; + found = lookup_tic_entry(tname, global_voc_dict_ptr); + return (found); } /* ************************************************************************** @@ -280,10 +278,11 @@ tic_hdr_t *lookup_core_word( char *tname) * **************************************************************************** */ -bool create_core_alias( char *new_name, char *old_name) +bool create_core_alias(char *new_name, char *old_name) { - bool retval = create_tic_alias( new_name, old_name, &global_voc_dict_ptr); - return ( retval ); + bool retval = + create_tic_alias(new_name, old_name, &global_voc_dict_ptr); + return (retval); } /* ************************************************************************** @@ -310,10 +309,10 @@ bool create_core_alias( char *new_name, char *old_name) * **************************************************************************** */ -static void emit_fc_token( tic_param_t pfield) +static void emit_fc_token(tic_param_t pfield) { - u16 fc_tok = (u16)pfield.deflt_elem; - emit_fcode( fc_tok); + u16 fc_tok = (u16) pfield.deflt_elem; + emit_fcode(fc_tok); } #define FC_TOKEN_FUNC emit_fc_token @@ -345,19 +344,18 @@ static void emit_fc_token( tic_param_t pfield) * **************************************************************************** */ -static void obsolete_warning( void) +static void obsolete_warning(void) { - if ( obso_fcode_warning ) - { - tokenization_error( WARNING, "%s is an Obsolete FCode.\n", - strupr(statbuf) ); - } + if (obso_fcode_warning) { + tokenization_error(WARNING, "%s is an Obsolete FCode.\n", + strupr(statbuf)); + } } -static void obsolete_fc_token( tic_param_t pfield) +static void obsolete_fc_token(tic_param_t pfield) { - obsolete_warning(); - emit_fc_token( pfield); + obsolete_warning(); + emit_fc_token(pfield); } #define OBSO_FC_FUNC obsolete_fc_token @@ -368,7 +366,6 @@ static void obsolete_fc_token( tic_param_t pfield) #define OBSOLETE_VALUE( tok, nam) \ VALPARAM_TIC(nam, OBSO_FC_FUNC, tok , VALUE, TRUE ) - /* ************************************************************************** * * The function for most of the "FWords" list, handle_internal() , @@ -385,9 +382,9 @@ static void obsolete_fc_token( tic_param_t pfield) * **************************************************************************** */ -void handle_internal( tic_param_t pfield); +void handle_internal(tic_param_t pfield); /* "Skip-a-string when Ignoring" function. Same args and limited-proto ... */ -void skip_string( tic_param_t pfield); +void skip_string(tic_param_t pfield); #define FWORD_EXEC_FUNC handle_internal @@ -499,36 +496,34 @@ void skip_string( tic_param_t pfield); static tic_hdr_t **save_device_definitions; -void enter_global_scope( void ) -{ - if ( scope_is_global ) +void enter_global_scope(void) { - tokenization_error( WARNING, - "%s -- Global Scope already in effect; ignoring.\n", - strupr(statbuf) ); - }else{ - tokenization_error( INFO, - "Initiating Global Scope definitions.\n" ); - scope_is_global = TRUE; - save_device_definitions = current_definitions; - current_definitions = &global_voc_dict_ptr; - } + if (scope_is_global) { + tokenization_error(WARNING, + "%s -- Global Scope already in effect; ignoring.\n", + strupr(statbuf)); + } else { + tokenization_error(INFO, + "Initiating Global Scope definitions.\n"); + scope_is_global = TRUE; + save_device_definitions = current_definitions; + current_definitions = &global_voc_dict_ptr; + } } -void resume_device_scope( void ) +void resume_device_scope(void) { - if ( scope_is_global ) - { - tokenization_error( INFO, - "Terminating Global Scope definitions; " - "resuming Device-node definitions.\n" ); - current_definitions = save_device_definitions; - scope_is_global = FALSE; - }else{ - tokenization_error( WARNING, - "%s -- Device-node Scope already in effect; ignoring.\n", - strupr(statbuf) ); - } + if (scope_is_global) { + tokenization_error(INFO, + "Terminating Global Scope definitions; " + "resuming Device-node definitions.\n"); + current_definitions = save_device_definitions; + scope_is_global = FALSE; + } else { + tokenization_error(WARNING, + "%s -- Device-node Scope already in effect; ignoring.\n", + strupr(statbuf)); + } } @@ -565,16 +560,15 @@ void resume_device_scope( void ) * **************************************************************************** */ -tic_hdr_t *lookup_current( char *tname) -{ - /* Search Current Device Vocabulary ahead of global (core) vocabulary */ - tic_hdr_t *retval; - retval = lookup_tic_entry( tname, *current_definitions); - if ( (retval == NULL) && INVERSE(scope_is_global) ) +tic_hdr_t *lookup_current(char *tname) { - retval = lookup_core_word( tname); - } - return ( retval ); + /* Search Current Device Vocabulary ahead of global (core) vocabulary */ + tic_hdr_t *retval; + retval = lookup_tic_entry(tname, *current_definitions); + if ((retval == NULL) && INVERSE(scope_is_global)) { + retval = lookup_core_word(tname); + } + return (retval); } /* ************************************************************************** @@ -594,12 +588,12 @@ tic_hdr_t *lookup_current( char *tname) * **************************************************************************** */ -bool exists_in_current( char *tname) +bool exists_in_current(char *tname) { - tic_hdr_t *found = lookup_word( tname, NULL, NULL); - bool retval = BOOLVAL ( found != NULL); - return( retval); - } + tic_hdr_t *found = lookup_word(tname, NULL, NULL); + bool retval = BOOLVAL(found != NULL); + return (retval); +} /* ************************************************************************** * @@ -622,18 +616,16 @@ bool exists_in_current( char *tname) * **************************************************************************** */ -tic_hdr_t *lookup_in_dev_node( char *tname) +tic_hdr_t *lookup_in_dev_node(char *tname) { - tic_hdr_t *retval = NULL; + tic_hdr_t *retval = NULL; - if ( INVERSE(scope_is_global) ) -{ - retval = lookup_tic_entry( tname, *current_definitions); -} - return ( retval ); + if (INVERSE(scope_is_global)) { + retval = lookup_tic_entry(tname, *current_definitions); + } + return (retval); } - /* ************************************************************************** * * In order to avoid unintentional "recursive"-ness, we need a way @@ -705,55 +697,48 @@ static tic_hdr_t *save_current = NULL; * **************************************************************************** */ -void add_to_current( char *name, - TIC_P_DEFLT_TYPE fc_token, - fwtoken definer) +void add_to_current(char *name, TIC_P_DEFLT_TYPE fc_token, fwtoken definer) { - if ( define_token ) -{ - char *nu_name = strdup( name); - - save_current = *current_definitions; - add_tic_entry( nu_name, FC_TOKEN_FUNC, fc_token, - definer, 0 , TRUE , NULL, current_definitions ); - }else{ - trace_create_failure( name, NULL, fc_token); - warn_if_duplicate( name); - } + if (define_token) { + char *nu_name = strdup(name); + + save_current = *current_definitions; + add_tic_entry(nu_name, FC_TOKEN_FUNC, fc_token, + definer, 0, TRUE, NULL, current_definitions); + } else { + trace_create_failure(name, NULL, fc_token); + warn_if_duplicate(name); + } } - -void hide_last_colon ( void ) +void hide_last_colon(void) { - if ( define_token ) - { - tic_hdr_t *temp_vocab; - - /* The add_to_current() function will have been called before this - * one when a new colon-definition is created, so save_current - * will have been set to point to the entry that had been made - * just before the newest one, which we are hiding here. - */ - - temp_vocab = save_current ; - save_current = *current_definitions; - *current_definitions = temp_vocab; - } + if (define_token) { + tic_hdr_t *temp_vocab; + + /* The add_to_current() function will have been called before this + * one when a new colon-definition is created, so save_current + * will have been set to point to the entry that had been made + * just before the newest one, which we are hiding here. + */ + + temp_vocab = save_current; + save_current = *current_definitions; + *current_definitions = temp_vocab; + } } -void reveal_last_colon ( void ) +void reveal_last_colon(void) { - if ( define_token ) - { - /* We call this function either when the colon-definition is - * completed, or when "recursive"-ness is intentional. - */ - *current_definitions = save_current ; -} + if (define_token) { + /* We call this function either when the colon-definition is + * completed, or when "recursive"-ness is intentional. + */ + *current_definitions = save_current; + } } - /* ************************************************************************** * * Function name: create_current_alias @@ -833,53 +818,48 @@ void reveal_last_colon ( void ) * **************************************************************************** */ -bool create_current_alias( char *new_name, char *old_name ) +bool create_current_alias(char *new_name, char *old_name) { - bool retval = FALSE; - bool split_alias = FALSE; - - /* Rules 1 & 2 are implemented in the same code. */ - if ( create_tic_alias( new_name, old_name, current_definitions) ) - { - retval = TRUE; - }else{ - if ( INVERSE(scope_is_global) ) - { - /* Rule 3. - * Because the vocab into which the new definition will go is - * not the same as the one in which the old name was found, - * we cannot call create_tic_alias but must replicate it. - */ - /* Hmmmmmm..... - * We could get around that by refactoring: add a parameter, - * make the vocab to search separate from the one in which to - * create. Also, by making it a separate routine, we won't - * have to disturb the other callers of create_tic_alias() - * Yes! Excellent! Make it so! - */ - split_alias = TRUE; - split_alias_message = INFO; - retval = create_split_alias( - new_name, old_name, - &global_voc_dict_ptr, - current_definitions ); + bool retval = FALSE; + bool split_alias = FALSE; + + /* Rules 1 & 2 are implemented in the same code. */ + if (create_tic_alias(new_name, old_name, current_definitions)) { + retval = TRUE; + } else { + if (INVERSE(scope_is_global)) { + /* Rule 3. + * Because the vocab into which the new definition will go is + * not the same as the one in which the old name was found, + * we cannot call create_tic_alias but must replicate it. + */ + /* Hmmmmmm..... + * We could get around that by refactoring: add a parameter, + * make the vocab to search separate from the one in which to + * create. Also, by making it a separate routine, we won't + * have to disturb the other callers of create_tic_alias() + * Yes! Excellent! Make it so! + */ + split_alias = TRUE; + split_alias_message = INFO; + retval = create_split_alias(new_name, old_name, + &global_voc_dict_ptr, + current_definitions); + } } - } - - if ( retval ) - { - if ( split_alias ) - { - tokenization_error( split_alias_message, - "%s is a Global definition, but its alias, %s, " - "will only be defined %s", - strupr( old_name), new_name, - in_what_node( current_device_node) ); - show_node_start(); - } + + if (retval) { + if (split_alias) { + tokenization_error(split_alias_message, + "%s is a Global definition, but its alias, %s, " + "will only be defined %s", + strupr(old_name), new_name, + in_what_node(current_device_node)); + show_node_start(); + } } - return ( retval ); + return (retval); } /* ************************************************************************** @@ -899,430 +879,429 @@ bool create_current_alias( char *new_name, char *old_name ) * **************************************************************************** */ -static tic_hdr_t tokens_table[] = -{ - BUILTIN_FCODE( 0x000, "end0" ) , - BUILTIN_FCODE( 0x010, "b(lit)" ) , - BUILTIN_FCODE( 0x011, "b(')" ) , - BUILTIN_FCODE( 0x012, "b(\")" ) , - BUILTIN_FCODE( 0x013, "bbranch" ) , - BUILTIN_FCODE( 0x014, "b?branch" ) , - BUILTIN_FCODE( 0x015, "b(loop)" ) , - BUILTIN_FCODE( 0x016, "b(+loop)" ) , - BUILTIN_FCODE( 0x017, "b(do)" ) , - BUILTIN_FCODE( 0x018, "b(?do)" ) , - BUILTIN_FCODE( 0x019, "i" ) , - BUILTIN_FCODE( 0x01a, "j" ) , - BUILTIN_FCODE( 0x01b, "b(leave)" ) , - BUILTIN_FCODE( 0x01c, "b(of)" ) , - BUILTIN_FCODE( 0x01d, "execute" ) , - BUILTIN_FCODE( 0x01e, "+" ) , - BUILTIN_FCODE( 0x01f, "-" ) , - BUILTIN_FCODE( 0x020, "*" ) , - BUILTIN_FCODE( 0x021, "/" ) , - BUILTIN_FCODE( 0x022, "mod" ) , - BUILTIN_FCODE( 0x023, "and" ) , - BUILTIN_FCODE( 0x024, "or" ) , - BUILTIN_FCODE( 0x025, "xor" ) , - BUILTIN_FCODE( 0x026, "invert" ) , - BUILTIN_FCODE( 0x026, "not" ) , /* Synonym for "invert" */ - BUILTIN_FCODE( 0x027, "lshift" ) , - BUILTIN_FCODE( 0x027, "<<" ) , /* Synonym for "lshift" */ - BUILTIN_FCODE( 0x028, "rshift" ) , - BUILTIN_FCODE( 0x028, ">>" ) , /* Synonym for "rshift" */ - BUILTIN_FCODE( 0x029, ">>a" ) , - BUILTIN_FCODE( 0x02a, "/mod" ) , - BUILTIN_FCODE( 0x02b, "u/mod" ) , - BUILTIN_FCODE( 0x02c, "negate" ) , - BUILTIN_FCODE( 0x02d, "abs" ) , - BUILTIN_FCODE( 0x02e, "min" ) , - BUILTIN_FCODE( 0x02f, "max" ) , - BUILTIN_FCODE( 0x030, ">r" ) , - BUILTIN_FCODE( 0x031, "r>" ) , - BUILTIN_FCODE( 0x032, "r@" ) , - BUILTIN_FCODE( 0x033, "exit" ) , - BUILTIN_FCODE( 0x034, "0=" ) , - BUILTIN_FCODE( 0x035, "0<>" ) , - BUILTIN_FCODE( 0x036, "0<" ) , - BUILTIN_FCODE( 0x037, "0<=" ) , - BUILTIN_FCODE( 0x038, "0>" ) , - BUILTIN_FCODE( 0x039, "0>=" ) , - BUILTIN_FCODE( 0x03a, "<" ) , - BUILTIN_FCODE( 0x03b, ">" ) , - BUILTIN_FCODE( 0x03c, "=" ) , - BUILTIN_FCODE( 0x03d, "<>" ) , - BUILTIN_FCODE( 0x03e, "u>" ) , - BUILTIN_FCODE( 0x03f, "u<=" ) , - BUILTIN_FCODE( 0x040, "u<" ) , - BUILTIN_FCODE( 0x041, "u>=" ) , - BUILTIN_FCODE( 0x042, ">=" ) , - BUILTIN_FCODE( 0x043, "<=" ) , - BUILTIN_FCODE( 0x044, "between" ) , - BUILTIN_FCODE( 0x045, "within" ) , - BUILTIN_FCODE( 0x046, "drop" ) , - BUILTIN_FCODE( 0x047, "dup" ) , - BUILTIN_FCODE( 0x048, "over" ) , - BUILTIN_FCODE( 0x049, "swap" ) , - BUILTIN_FCODE( 0x04A, "rot" ) , - BUILTIN_FCODE( 0x04b, "-rot" ) , - BUILTIN_FCODE( 0x04c, "tuck" ) , - BUILTIN_FCODE( 0x04d, "nip" ) , - BUILTIN_FCODE( 0x04e, "pick" ) , - BUILTIN_FCODE( 0x04f, "roll" ) , - BUILTIN_FCODE( 0x050, "?dup" ) , - BUILTIN_FCODE( 0x051, "depth" ) , - BUILTIN_FCODE( 0x052, "2drop" ) , - BUILTIN_FCODE( 0x053, "2dup" ) , - BUILTIN_FCODE( 0x054, "2over" ) , - BUILTIN_FCODE( 0x055, "2swap" ) , - BUILTIN_FCODE( 0x056, "2rot" ) , - BUILTIN_FCODE( 0x057, "2/" ) , - BUILTIN_FCODE( 0x058, "u2/" ) , - BUILTIN_FCODE( 0x059, "2*" ) , - BUILTIN_FCODE( 0x05a, "/c" ) , - BUILTIN_FCODE( 0x05b, "/w" ) , - BUILTIN_FCODE( 0x05c, "/l" ) , - BUILTIN_FCODE( 0x05d, "/n" ) , - BUILTIN_FCODE( 0x05e, "ca+" ) , - BUILTIN_FCODE( 0x05f, "wa+" ) , - BUILTIN_FCODE( 0x060, "la+" ) , - BUILTIN_FCODE( 0x061, "na+" ) , - BUILTIN_FCODE( 0x062, "char+" ) , - BUILTIN_FCODE( 0x062, "ca1+" ) , /* Synonym for char+" */ - BUILTIN_FCODE( 0x063, "wa1+" ) , - BUILTIN_FCODE( 0x064, "la1+" ) , - BUILTIN_FCODE( 0x065, "cell+" ) , - BUILTIN_FCODE( 0x065, "na1+" ) , /* Synonym for "cell+" */ - BUILTIN_FCODE( 0x066, "chars" ) , - BUILTIN_FCODE( 0x066, "/c*" ) , /* Synonym for "chars" */ - BUILTIN_FCODE( 0x067, "/w*" ) , - BUILTIN_FCODE( 0x068, "/l*" ) , - BUILTIN_FCODE( 0x069, "cells" ) , - BUILTIN_FCODE( 0x069, "/n*" ) , /* Synonym for "cells" */ - BUILTIN_FCODE( 0x06a, "on" ) , - BUILTIN_FCODE( 0x06b, "off" ) , - BUILTIN_FCODE( 0x06c, "+!" ) , - BUILTIN_FCODE( 0x06d, "@" ) , - BUILTIN_FCODE( 0x06e, "l@" ) , - BUILTIN_FCODE( 0x06f, "w@" ) , - BUILTIN_FCODE( 0x070, "" ) , - BUILTIN_FCODE( 0x086, ">body" ) , - BUILTIN_FCODE( 0x087, "fcode-revision" ) , - BUILTIN_FCODE( 0x087, "version" ) , /* Synonym for "fcode-revision" */ - BI_FCODE_VRBLE( 0x088, "span" ) , - BUILTIN_FCODE( 0x089, "unloop" ) , - BUILTIN_FCODE( 0x08a, "expect" ) , - BUILTIN_FCODE( 0x08b, "alloc-mem" ) , - BUILTIN_FCODE( 0x08c, "free-mem" ) , - BUILTIN_FCODE( 0x08d, "key?" ) , - BUILTIN_FCODE( 0x08e, "key" ) , - BUILTIN_FCODE( 0x08f, "emit" ) , - BUILTIN_FCODE( 0x090, "type" ) , - BUILTIN_FCODE( 0x091, "(cr" ) , - BUILTIN_FCODE( 0x092, "cr" ) , - BI_FCODE_VRBLE( 0x093, "#out" ) , - BI_FCODE_VRBLE( 0x094, "#line" ) , - BUILTIN_FCODE( 0x095, "hold" ) , - BUILTIN_FCODE( 0x096, "<#" ) , - BUILTIN_FCODE( 0x097, "u#>" ) , - BUILTIN_FCODE( 0x098, "sign" ) , - BUILTIN_FCODE( 0x099, "u#" ) , - BUILTIN_FCODE( 0x09a, "u#s" ) , - BUILTIN_FCODE( 0x09b, "u." ) , - BUILTIN_FCODE( 0x09c, "u.r" ) , - BUILTIN_FCODE( 0x09d, "." ) , - BUILTIN_FCODE( 0x09e, ".r" ) , - BUILTIN_FCODE( 0x09f, ".s" ) , - BI_FCODE_VRBLE( 0x0a0, "base" ) , - OBSOLETE_FCODE( 0x0a1, "convert" ) , - BUILTIN_FCODE( 0x0a2, "$number" ) , - BUILTIN_FCODE( 0x0a3, "digit" ) , - BI_FCODE_CONST( 0x0a4, "-1" ) , - BI_FCODE_CONST( 0x0a4, "true" ) , /* Synonym for "-1" */ - BI_FCODE_CONST( 0x0a5, "0" ) , - BI_FCODE_CONST( 0x0a5, "false" ) , /* Synonym for "0" */ - BI_FCODE_CONST( 0x0a5, "struct" ) , /* Synonym for "0" */ - BI_FCODE_CONST( 0x0a6, "1" ) , - BI_FCODE_CONST( 0x0a7, "2" ) , - BI_FCODE_CONST( 0x0a8, "3" ) , - BI_FCODE_CONST( 0x0a9, "bl" ) , - BI_FCODE_CONST( 0x0aa, "bs" ) , - BI_FCODE_CONST( 0x0ab, "bell" ) , - BUILTIN_FCODE( 0x0ac, "bounds" ) , - BUILTIN_FCODE( 0x0ad, "here" ) , - BUILTIN_FCODE( 0x0ae, "aligned" ) , - BUILTIN_FCODE( 0x0af, "wbsplit" ) , - BUILTIN_FCODE( 0x0b0, "bwjoin" ) , - BUILTIN_FCODE( 0x0b1, "b(resolve)" ) , - OBSOLETE_FCODE( 0x0b3, "set-token-table" ) , - OBSOLETE_FCODE( 0x0b4, "set-table" ) , - BUILTIN_FCODE( 0x0b5, "new-token" ) , - BUILTIN_FCODE( 0x0b6, "named-token" ) , - BUILTIN_FCODE( 0x0b7, "b(:)" ) , - BUILTIN_FCODE( 0x0b8, "b(value)" ) , - BUILTIN_FCODE( 0x0b9, "b(variable)" ) , - BUILTIN_FCODE( 0x0ba, "b(constant)" ) , - BUILTIN_FCODE( 0x0bb, "b(create)" ) , - BUILTIN_FCODE( 0x0bc, "b(defer)" ) , - BUILTIN_FCODE( 0x0bd, "b(buffer:)" ) , - BUILTIN_FCODE( 0x0be, "b(field)" ) , - OBSOLETE_FCODE( 0x0bf, "b(code)" ) , - BUILTIN_FCODE( 0x0c0, "instance" ) , - BUILTIN_FCODE( 0x0c2, "b(;)" ) , - BUILTIN_FCODE( 0x0c3, "b(to)" ) , - BUILTIN_FCODE( 0x0c4, "b(case)" ) , - BUILTIN_FCODE( 0x0c5, "b(endcase)" ) , - BUILTIN_FCODE( 0x0c6, "b(endof)" ) , - BUILTIN_FCODE( 0x0c7, "#" ) , - BUILTIN_FCODE( 0x0c8, "#s" ) , - BUILTIN_FCODE( 0x0c9, "#>" ) , - BUILTIN_FCODE( 0x0ca, "external-token" ) , - BUILTIN_FCODE( 0x0cb, "$find" ) , - BUILTIN_FCODE( 0x0cc, "offset16" ) , - BUILTIN_FCODE( 0x0cd, "evaluate" ) , - BUILTIN_FCODE( 0x0cd, "eval" ) , /* Synonym for "evaluate" */ - BUILTIN_FCODE( 0x0d0, "c," ) , - BUILTIN_FCODE( 0x0d1, "w," ) , - BUILTIN_FCODE( 0x0d2, "l," ) , - BUILTIN_FCODE( 0x0d3, "," ) , - BUILTIN_FCODE( 0x0d4, "um*" ) , - BUILTIN_FCODE( 0x0d4, "u*x" ) , /* Synonym for "um*" */ - BUILTIN_FCODE( 0x0d5, "um/mod" ) , - BUILTIN_FCODE( 0x0d5, "xu/mod" ) , /* Synonym for "um/mod" */ - BUILTIN_FCODE( 0x0d8, "d+" ) , - BUILTIN_FCODE( 0x0d8, "x+" ) , /* Synonym for "d+" */ - BUILTIN_FCODE( 0x0d9, "d-" ) , - BUILTIN_FCODE( 0x0d9, "x-" ) , /* Synonym for "d-" */ - BUILTIN_FCODE( 0x0da, "get-token" ) , - BUILTIN_FCODE( 0x0db, "set-token" ) , - BI_FCODE_VRBLE( 0x0dc, "state" ) , - BUILTIN_FCODE( 0x0dd, "compile," ) , - BUILTIN_FCODE( 0x0de, "behavior" ) , - BUILTIN_FCODE( 0x0f0, "start0" ) , - BUILTIN_FCODE( 0x0f1, "start1" ) , - BUILTIN_FCODE( 0x0f2, "start2" ) , - BUILTIN_FCODE( 0x0f3, "start4" ) , - BUILTIN_FCODE( 0x0fc, "ferror" ) , - BUILTIN_FCODE( 0x0fd, "version1" ) , - OBSOLETE_FCODE( 0x0fe, "4-byte-id" ) , - BUILTIN_FCODE( 0x0ff, "end1" ) , - OBSOLETE_FCODE( 0x101, "dma-alloc" ) , - BUILTIN_FCODE( 0x102, "my-address" ) , - BUILTIN_FCODE( 0x103, "my-space" ) , - OBSOLETE_FCODE( 0x104, "memmap" ) , - BUILTIN_FCODE( 0x105, "free-virtual" ) , - OBSOLETE_FCODE( 0x106, ">physical" ) , - OBSOLETE_FCODE( 0x10f, "my-params" ) , - BUILTIN_FCODE( 0x110, "property" ) , - BUILTIN_FCODE( 0x110, "attribute" ) , /* Synonym for "property" */ - BUILTIN_FCODE( 0x111, "encode-int" ) , - BUILTIN_FCODE( 0x111, "xdrint" ) , /* Synonym for "encode-int" */ - BUILTIN_FCODE( 0x112, "encode+" ) , - BUILTIN_FCODE( 0x112, "xdr+" ) , /* Synonym for "encode+" */ - BUILTIN_FCODE( 0x113, "encode-phys" ) , - BUILTIN_FCODE( 0x113, "xdrphys" ) , /* Synonym for "encode-phys" */ - BUILTIN_FCODE( 0x114, "encode-string" ) , - BUILTIN_FCODE( 0x114, "xdrstring" ) , /* Synonym for "encode-string" */ - BUILTIN_FCODE( 0x115, "encode-bytes" ) , - BUILTIN_FCODE( 0x115, "xdrbytes" ) , /* Synonym for "encode-bytes" */ - BUILTIN_FCODE( 0x116, "reg" ) , - OBSOLETE_FCODE( 0x117, "intr" ) , - OBSOLETE_FCODE( 0x118, "driver" ) , - BUILTIN_FCODE( 0x119, "model" ) , - BUILTIN_FCODE( 0x11a, "device-type" ) , - BUILTIN_FCODE( 0x11b, "parse-2int" ) , - BUILTIN_FCODE( 0x11b, "decode-2int" ) , /* Synonym for "parse-2int" */ - BUILTIN_FCODE( 0x11c, "is-install" ) , - BUILTIN_FCODE( 0x11d, "is-remove" ) , - BUILTIN_FCODE( 0x11e, "is-selftest" ) , - BUILTIN_FCODE( 0x11f, "new-device" ) , - BUILTIN_FCODE( 0x120, "diagnostic-mode?" ) , - OBSOLETE_FCODE( 0x121, "display-status" ) , - BUILTIN_FCODE( 0x122, "memory-test-issue" ) , - OBSOLETE_FCODE( 0x123, "group-code" ) , - BI_FCODE_VRBLE( 0x124, "mask" ) , - BUILTIN_FCODE( 0x125, "get-msecs" ) , - BUILTIN_FCODE( 0x126, "ms" ) , - BUILTIN_FCODE( 0x127, "finish-device" ) , - BUILTIN_FCODE( 0x128, "decode-phys" ) , - BUILTIN_FCODE( 0x12b, "interpose" ) , - BUILTIN_FCODE( 0x130, "map-low" ) , - BUILTIN_FCODE( 0x130, "map-sbus" ) , /* Synonym for "map-low" */ - BUILTIN_FCODE( 0x131, "sbus-intr>cpu" ) , - BI_FCODE_VALUE( 0x150, "#lines" ) , - BI_FCODE_VALUE( 0x151, "#columns" ) , - BI_FCODE_VALUE( 0x152, "line#" ) , - BI_FCODE_VALUE( 0x153, "column#" ) , - BI_FCODE_VALUE( 0x154, "inverse?" ) , - BI_FCODE_VALUE( 0x155, "inverse-screen?" ) , - OBSOLETE_VALUE( 0x156, "frame-buffer-busy?" ) , - BI_FCODE_DEFER( 0x157, "draw-character" ) , - BI_FCODE_DEFER( 0x158, "reset-screen" ) , - BI_FCODE_DEFER( 0x159, "toggle-cursor" ) , - BI_FCODE_DEFER( 0x15a, "erase-screen" ) , - BI_FCODE_DEFER( 0x15b, "blink-screen" ) , - BI_FCODE_DEFER( 0x15c, "invert-screen" ) , - BI_FCODE_DEFER( 0x15d, "insert-characters" ) , - BI_FCODE_DEFER( 0x15e, "delete-characters" ) , - BI_FCODE_DEFER( 0x15f, "insert-lines" ) , - BI_FCODE_DEFER( 0x160, "delete-lines" ) , - BI_FCODE_DEFER( 0x161, "draw-logo" ) , - BI_FCODE_VALUE( 0x162, "frame-buffer-adr" ) , - BI_FCODE_VALUE( 0x163, "screen-height" ) , - BI_FCODE_VALUE( 0x164, "screen-width" ) , - BI_FCODE_VALUE( 0x165, "window-top" ) , - BI_FCODE_VALUE( 0x166, "window-left" ) , - BUILTIN_FCODE( 0x16a, "default-font" ) , - BUILTIN_FCODE( 0x16b, "set-font" ) , - BI_FCODE_VALUE( 0x16c, "char-height" ) , - BI_FCODE_VALUE( 0x16d, "char-width" ) , - BUILTIN_FCODE( 0x16e, ">font" ) , - BI_FCODE_VALUE( 0x16f, "fontbytes" ) , - OBSOLETE_FCODE( 0x170, "fb1-draw-character" ) , - OBSOLETE_FCODE( 0x171, "fb1-reset-screen" ) , - OBSOLETE_FCODE( 0x172, "fb1-toggle-cursor" ) , - OBSOLETE_FCODE( 0x173, "fb1-erase-screen" ) , - OBSOLETE_FCODE( 0x174, "fb1-blink-screen" ) , - OBSOLETE_FCODE( 0x175, "fb1-invert-screen" ) , - OBSOLETE_FCODE( 0x176, "fb1-insert-characters" ) , - OBSOLETE_FCODE( 0x177, "fb1-delete-characters" ) , - OBSOLETE_FCODE( 0x178, "fb1-insert-lines" ) , - OBSOLETE_FCODE( 0x179, "fb1-delete-lines" ) , - OBSOLETE_FCODE( 0x17a, "fb1-draw-logo" ) , - OBSOLETE_FCODE( 0x17b, "fb1-install" ) , - OBSOLETE_FCODE( 0x17c, "fb1-slide-up" ) , - BUILTIN_FCODE( 0x180, "fb8-draw-character" ) , - BUILTIN_FCODE( 0x181, "fb8-reset-screen" ) , - BUILTIN_FCODE( 0x182, "fb8-toggle-cursor" ) , - BUILTIN_FCODE( 0x183, "fb8-erase-screen" ) , - BUILTIN_FCODE( 0x184, "fb8-blink-screen" ) , - BUILTIN_FCODE( 0x185, "fb8-invert-screen" ) , - BUILTIN_FCODE( 0x186, "fb8-insert-characters" ) , - BUILTIN_FCODE( 0x187, "fb8-delete-characters" ) , - BUILTIN_FCODE( 0x188, "fb8-insert-lines" ) , - BUILTIN_FCODE( 0x189, "fb8-delete-lines" ) , - BUILTIN_FCODE( 0x18a, "fb8-draw-logo" ) , - BUILTIN_FCODE( 0x18b, "fb8-install" ) , - OBSOLETE_FCODE( 0x1a0, "return-buffer" ) , - OBSOLETE_FCODE( 0x1a1, "xmit-packet" ) , - OBSOLETE_FCODE( 0x1a2, "poll-packet" ) , - BUILTIN_FCODE( 0x1a4, "mac-address" ) , - BUILTIN_FCODE( 0x201, "device-name" ) , - BUILTIN_FCODE( 0x201, "name" ) , /* Synonym for "device-name" */ - BUILTIN_FCODE( 0x202, "my-args" ) , - BI_FCODE_VALUE( 0x203, "my-self" ) , - BUILTIN_FCODE( 0x204, "find-package" ) , - BUILTIN_FCODE( 0x205, "open-package" ) , - BUILTIN_FCODE( 0x206, "close-package" ) , - BUILTIN_FCODE( 0x207, "find-method" ) , - BUILTIN_FCODE( 0x208, "call-package" ) , - BUILTIN_FCODE( 0x209, "$call-parent" ) , - BUILTIN_FCODE( 0x20a, "my-parent" ) , - BUILTIN_FCODE( 0x20b, "ihandle>phandle" ) , - BUILTIN_FCODE( 0x20d, "my-unit" ) , - BUILTIN_FCODE( 0x20e, "$call-method" ) , - BUILTIN_FCODE( 0x20f, "$open-package" ) , - OBSOLETE_FCODE( 0x210, "processor-type" ) , - OBSOLETE_FCODE( 0x211, "firmware-version" ) , - OBSOLETE_FCODE( 0x212, "fcode-version" ) , - BUILTIN_FCODE( 0x213, "alarm" ) , - BUILTIN_FCODE( 0x214, "(is-user-word)" ) , - BUILTIN_FCODE( 0x215, "suspend-fcode" ) , - BUILTIN_FCODE( 0x216, "abort" ) , - BUILTIN_FCODE( 0x217, "catch" ) , - BUILTIN_FCODE( 0x218, "throw" ) , - BUILTIN_FCODE( 0x219, "user-abort" ) , - BUILTIN_FCODE( 0x21a, "get-my-property" ) , - BUILTIN_FCODE( 0x21a, "get-my-attribute" ) , /* Synonym for "get-my-property" */ - BUILTIN_FCODE( 0x21b, "decode-int" ) , - BUILTIN_FCODE( 0x21b, "xdrtoint" ) , /* Synonym for "decode-int" */ - BUILTIN_FCODE( 0x21c, "decode-string" ) , - BUILTIN_FCODE( 0x21c, "xdrtostring" ), /* Synonym for "decode-string" */ - BUILTIN_FCODE( 0x21d, "get-inherited-property" ) , - BUILTIN_FCODE( 0x21d, "get-inherited-attribute" ) , /* Synonym for "get-inherited-property" */ - BUILTIN_FCODE( 0x21e, "delete-property" ) , - BUILTIN_FCODE( 0x21e, "delete-attribute" ) , /* Synonym for "delete-property" */ - BUILTIN_FCODE( 0x21f, "get-package-property" ) , - BUILTIN_FCODE( 0x21f, "get-package-attribute" ) , /* Synonym for "get-package-property" */ - BUILTIN_FCODE( 0x220, "cpeek" ) , - BUILTIN_FCODE( 0x221, "wpeek" ) , - BUILTIN_FCODE( 0x222, "lpeek" ) , - BUILTIN_FCODE( 0x223, "cpoke" ) , - BUILTIN_FCODE( 0x224, "wpoke" ) , - BUILTIN_FCODE( 0x225, "lpoke" ) , - BUILTIN_FCODE( 0x226, "lwflip" ) , - BUILTIN_FCODE( 0x227, "lbflip" ) , - BUILTIN_FCODE( 0x228, "lbflips" ) , - OBSOLETE_FCODE( 0x229, "adr-mask" ) , - BUILTIN_FCODE( 0x230, "rb@" ) , - BUILTIN_FCODE( 0x231, "rb!" ) , - BUILTIN_FCODE( 0x232, "rw@" ) , - BUILTIN_FCODE( 0x233, "rw!" ) , - BUILTIN_FCODE( 0x234, "rl@" ) , - BUILTIN_FCODE( 0x235, "rl!" ) , - BUILTIN_FCODE( 0x236, "wbflips" ) , - BUILTIN_FCODE( 0x236, "wflips" ) , /* Synonym for "wbflips" */ - BUILTIN_FCODE( 0x237, "lwflips" ) , - BUILTIN_FCODE( 0x237, "lflips" ) , /* Synonym for "lwflips" */ - OBSOLETE_FCODE( 0x238, "probe" ) , - OBSOLETE_FCODE( 0x239, "probe-virtual" ) , - BUILTIN_FCODE( 0x23b, "child" ) , - BUILTIN_FCODE( 0x23c, "peer" ) , - BUILTIN_FCODE( 0x23d, "next-property" ) , - BUILTIN_FCODE( 0x23e, "byte-load" ) , - BUILTIN_FCODE( 0x23f, "set-args" ) , - BUILTIN_FCODE( 0x240, "left-parse-string" ) , +static tic_hdr_t tokens_table[] = { + BUILTIN_FCODE(0x000, "end0"), + BUILTIN_FCODE(0x010, "b(lit)"), + BUILTIN_FCODE(0x011, "b(')"), + BUILTIN_FCODE(0x012, "b(\")"), + BUILTIN_FCODE(0x013, "bbranch"), + BUILTIN_FCODE(0x014, "b?branch"), + BUILTIN_FCODE(0x015, "b(loop)"), + BUILTIN_FCODE(0x016, "b(+loop)"), + BUILTIN_FCODE(0x017, "b(do)"), + BUILTIN_FCODE(0x018, "b(?do)"), + BUILTIN_FCODE(0x019, "i"), + BUILTIN_FCODE(0x01a, "j"), + BUILTIN_FCODE(0x01b, "b(leave)"), + BUILTIN_FCODE(0x01c, "b(of)"), + BUILTIN_FCODE(0x01d, "execute"), + BUILTIN_FCODE(0x01e, "+"), + BUILTIN_FCODE(0x01f, "-"), + BUILTIN_FCODE(0x020, "*"), + BUILTIN_FCODE(0x021, "/"), + BUILTIN_FCODE(0x022, "mod"), + BUILTIN_FCODE(0x023, "and"), + BUILTIN_FCODE(0x024, "or"), + BUILTIN_FCODE(0x025, "xor"), + BUILTIN_FCODE(0x026, "invert"), + BUILTIN_FCODE(0x026, "not"), /* Synonym for "invert" */ + BUILTIN_FCODE(0x027, "lshift"), + BUILTIN_FCODE(0x027, "<<"), /* Synonym for "lshift" */ + BUILTIN_FCODE(0x028, "rshift"), + BUILTIN_FCODE(0x028, ">>"), /* Synonym for "rshift" */ + BUILTIN_FCODE(0x029, ">>a"), + BUILTIN_FCODE(0x02a, "/mod"), + BUILTIN_FCODE(0x02b, "u/mod"), + BUILTIN_FCODE(0x02c, "negate"), + BUILTIN_FCODE(0x02d, "abs"), + BUILTIN_FCODE(0x02e, "min"), + BUILTIN_FCODE(0x02f, "max"), + BUILTIN_FCODE(0x030, ">r"), + BUILTIN_FCODE(0x031, "r>"), + BUILTIN_FCODE(0x032, "r@"), + BUILTIN_FCODE(0x033, "exit"), + BUILTIN_FCODE(0x034, "0="), + BUILTIN_FCODE(0x035, "0<>"), + BUILTIN_FCODE(0x036, "0<"), + BUILTIN_FCODE(0x037, "0<="), + BUILTIN_FCODE(0x038, "0>"), + BUILTIN_FCODE(0x039, "0>="), + BUILTIN_FCODE(0x03a, "<"), + BUILTIN_FCODE(0x03b, ">"), + BUILTIN_FCODE(0x03c, "="), + BUILTIN_FCODE(0x03d, "<>"), + BUILTIN_FCODE(0x03e, "u>"), + BUILTIN_FCODE(0x03f, "u<="), + BUILTIN_FCODE(0x040, "u<"), + BUILTIN_FCODE(0x041, "u>="), + BUILTIN_FCODE(0x042, ">="), + BUILTIN_FCODE(0x043, "<="), + BUILTIN_FCODE(0x044, "between"), + BUILTIN_FCODE(0x045, "within"), + BUILTIN_FCODE(0x046, "drop"), + BUILTIN_FCODE(0x047, "dup"), + BUILTIN_FCODE(0x048, "over"), + BUILTIN_FCODE(0x049, "swap"), + BUILTIN_FCODE(0x04A, "rot"), + BUILTIN_FCODE(0x04b, "-rot"), + BUILTIN_FCODE(0x04c, "tuck"), + BUILTIN_FCODE(0x04d, "nip"), + BUILTIN_FCODE(0x04e, "pick"), + BUILTIN_FCODE(0x04f, "roll"), + BUILTIN_FCODE(0x050, "?dup"), + BUILTIN_FCODE(0x051, "depth"), + BUILTIN_FCODE(0x052, "2drop"), + BUILTIN_FCODE(0x053, "2dup"), + BUILTIN_FCODE(0x054, "2over"), + BUILTIN_FCODE(0x055, "2swap"), + BUILTIN_FCODE(0x056, "2rot"), + BUILTIN_FCODE(0x057, "2/"), + BUILTIN_FCODE(0x058, "u2/"), + BUILTIN_FCODE(0x059, "2*"), + BUILTIN_FCODE(0x05a, "/c"), + BUILTIN_FCODE(0x05b, "/w"), + BUILTIN_FCODE(0x05c, "/l"), + BUILTIN_FCODE(0x05d, "/n"), + BUILTIN_FCODE(0x05e, "ca+"), + BUILTIN_FCODE(0x05f, "wa+"), + BUILTIN_FCODE(0x060, "la+"), + BUILTIN_FCODE(0x061, "na+"), + BUILTIN_FCODE(0x062, "char+"), + BUILTIN_FCODE(0x062, "ca1+"), /* Synonym for char+" */ + BUILTIN_FCODE(0x063, "wa1+"), + BUILTIN_FCODE(0x064, "la1+"), + BUILTIN_FCODE(0x065, "cell+"), + BUILTIN_FCODE(0x065, "na1+"), /* Synonym for "cell+" */ + BUILTIN_FCODE(0x066, "chars"), + BUILTIN_FCODE(0x066, "/c*"), /* Synonym for "chars" */ + BUILTIN_FCODE(0x067, "/w*"), + BUILTIN_FCODE(0x068, "/l*"), + BUILTIN_FCODE(0x069, "cells"), + BUILTIN_FCODE(0x069, "/n*"), /* Synonym for "cells" */ + BUILTIN_FCODE(0x06a, "on"), + BUILTIN_FCODE(0x06b, "off"), + BUILTIN_FCODE(0x06c, "+!"), + BUILTIN_FCODE(0x06d, "@"), + BUILTIN_FCODE(0x06e, "l@"), + BUILTIN_FCODE(0x06f, "w@"), + BUILTIN_FCODE(0x070, ""), + BUILTIN_FCODE(0x086, ">body"), + BUILTIN_FCODE(0x087, "fcode-revision"), + BUILTIN_FCODE(0x087, "version"), /* Synonym for "fcode-revision" */ + BI_FCODE_VRBLE(0x088, "span"), + BUILTIN_FCODE(0x089, "unloop"), + BUILTIN_FCODE(0x08a, "expect"), + BUILTIN_FCODE(0x08b, "alloc-mem"), + BUILTIN_FCODE(0x08c, "free-mem"), + BUILTIN_FCODE(0x08d, "key?"), + BUILTIN_FCODE(0x08e, "key"), + BUILTIN_FCODE(0x08f, "emit"), + BUILTIN_FCODE(0x090, "type"), + BUILTIN_FCODE(0x091, "(cr"), + BUILTIN_FCODE(0x092, "cr"), + BI_FCODE_VRBLE(0x093, "#out"), + BI_FCODE_VRBLE(0x094, "#line"), + BUILTIN_FCODE(0x095, "hold"), + BUILTIN_FCODE(0x096, "<#"), + BUILTIN_FCODE(0x097, "u#>"), + BUILTIN_FCODE(0x098, "sign"), + BUILTIN_FCODE(0x099, "u#"), + BUILTIN_FCODE(0x09a, "u#s"), + BUILTIN_FCODE(0x09b, "u."), + BUILTIN_FCODE(0x09c, "u.r"), + BUILTIN_FCODE(0x09d, "."), + BUILTIN_FCODE(0x09e, ".r"), + BUILTIN_FCODE(0x09f, ".s"), + BI_FCODE_VRBLE(0x0a0, "base"), + OBSOLETE_FCODE(0x0a1, "convert"), + BUILTIN_FCODE(0x0a2, "$number"), + BUILTIN_FCODE(0x0a3, "digit"), + BI_FCODE_CONST(0x0a4, "-1"), + BI_FCODE_CONST(0x0a4, "true"), /* Synonym for "-1" */ + BI_FCODE_CONST(0x0a5, "0"), + BI_FCODE_CONST(0x0a5, "false"), /* Synonym for "0" */ + BI_FCODE_CONST(0x0a5, "struct"), /* Synonym for "0" */ + BI_FCODE_CONST(0x0a6, "1"), + BI_FCODE_CONST(0x0a7, "2"), + BI_FCODE_CONST(0x0a8, "3"), + BI_FCODE_CONST(0x0a9, "bl"), + BI_FCODE_CONST(0x0aa, "bs"), + BI_FCODE_CONST(0x0ab, "bell"), + BUILTIN_FCODE(0x0ac, "bounds"), + BUILTIN_FCODE(0x0ad, "here"), + BUILTIN_FCODE(0x0ae, "aligned"), + BUILTIN_FCODE(0x0af, "wbsplit"), + BUILTIN_FCODE(0x0b0, "bwjoin"), + BUILTIN_FCODE(0x0b1, "b(resolve)"), + OBSOLETE_FCODE(0x0b3, "set-token-table"), + OBSOLETE_FCODE(0x0b4, "set-table"), + BUILTIN_FCODE(0x0b5, "new-token"), + BUILTIN_FCODE(0x0b6, "named-token"), + BUILTIN_FCODE(0x0b7, "b(:)"), + BUILTIN_FCODE(0x0b8, "b(value)"), + BUILTIN_FCODE(0x0b9, "b(variable)"), + BUILTIN_FCODE(0x0ba, "b(constant)"), + BUILTIN_FCODE(0x0bb, "b(create)"), + BUILTIN_FCODE(0x0bc, "b(defer)"), + BUILTIN_FCODE(0x0bd, "b(buffer:)"), + BUILTIN_FCODE(0x0be, "b(field)"), + OBSOLETE_FCODE(0x0bf, "b(code)"), + BUILTIN_FCODE(0x0c0, "instance"), + BUILTIN_FCODE(0x0c2, "b(;)"), + BUILTIN_FCODE(0x0c3, "b(to)"), + BUILTIN_FCODE(0x0c4, "b(case)"), + BUILTIN_FCODE(0x0c5, "b(endcase)"), + BUILTIN_FCODE(0x0c6, "b(endof)"), + BUILTIN_FCODE(0x0c7, "#"), + BUILTIN_FCODE(0x0c8, "#s"), + BUILTIN_FCODE(0x0c9, "#>"), + BUILTIN_FCODE(0x0ca, "external-token"), + BUILTIN_FCODE(0x0cb, "$find"), + BUILTIN_FCODE(0x0cc, "offset16"), + BUILTIN_FCODE(0x0cd, "evaluate"), + BUILTIN_FCODE(0x0cd, "eval"), /* Synonym for "evaluate" */ + BUILTIN_FCODE(0x0d0, "c,"), + BUILTIN_FCODE(0x0d1, "w,"), + BUILTIN_FCODE(0x0d2, "l,"), + BUILTIN_FCODE(0x0d3, ","), + BUILTIN_FCODE(0x0d4, "um*"), + BUILTIN_FCODE(0x0d4, "u*x"), /* Synonym for "um*" */ + BUILTIN_FCODE(0x0d5, "um/mod"), + BUILTIN_FCODE(0x0d5, "xu/mod"), /* Synonym for "um/mod" */ + BUILTIN_FCODE(0x0d8, "d+"), + BUILTIN_FCODE(0x0d8, "x+"), /* Synonym for "d+" */ + BUILTIN_FCODE(0x0d9, "d-"), + BUILTIN_FCODE(0x0d9, "x-"), /* Synonym for "d-" */ + BUILTIN_FCODE(0x0da, "get-token"), + BUILTIN_FCODE(0x0db, "set-token"), + BI_FCODE_VRBLE(0x0dc, "state"), + BUILTIN_FCODE(0x0dd, "compile,"), + BUILTIN_FCODE(0x0de, "behavior"), + BUILTIN_FCODE(0x0f0, "start0"), + BUILTIN_FCODE(0x0f1, "start1"), + BUILTIN_FCODE(0x0f2, "start2"), + BUILTIN_FCODE(0x0f3, "start4"), + BUILTIN_FCODE(0x0fc, "ferror"), + BUILTIN_FCODE(0x0fd, "version1"), + OBSOLETE_FCODE(0x0fe, "4-byte-id"), + BUILTIN_FCODE(0x0ff, "end1"), + OBSOLETE_FCODE(0x101, "dma-alloc"), + BUILTIN_FCODE(0x102, "my-address"), + BUILTIN_FCODE(0x103, "my-space"), + OBSOLETE_FCODE(0x104, "memmap"), + BUILTIN_FCODE(0x105, "free-virtual"), + OBSOLETE_FCODE(0x106, ">physical"), + OBSOLETE_FCODE(0x10f, "my-params"), + BUILTIN_FCODE(0x110, "property"), + BUILTIN_FCODE(0x110, "attribute"), /* Synonym for "property" */ + BUILTIN_FCODE(0x111, "encode-int"), + BUILTIN_FCODE(0x111, "xdrint"), /* Synonym for "encode-int" */ + BUILTIN_FCODE(0x112, "encode+"), + BUILTIN_FCODE(0x112, "xdr+"), /* Synonym for "encode+" */ + BUILTIN_FCODE(0x113, "encode-phys"), + BUILTIN_FCODE(0x113, "xdrphys"), /* Synonym for "encode-phys" */ + BUILTIN_FCODE(0x114, "encode-string"), + BUILTIN_FCODE(0x114, "xdrstring"), /* Synonym for "encode-string" */ + BUILTIN_FCODE(0x115, "encode-bytes"), + BUILTIN_FCODE(0x115, "xdrbytes"), /* Synonym for "encode-bytes" */ + BUILTIN_FCODE(0x116, "reg"), + OBSOLETE_FCODE(0x117, "intr"), + OBSOLETE_FCODE(0x118, "driver"), + BUILTIN_FCODE(0x119, "model"), + BUILTIN_FCODE(0x11a, "device-type"), + BUILTIN_FCODE(0x11b, "parse-2int"), + BUILTIN_FCODE(0x11b, "decode-2int"), /* Synonym for "parse-2int" */ + BUILTIN_FCODE(0x11c, "is-install"), + BUILTIN_FCODE(0x11d, "is-remove"), + BUILTIN_FCODE(0x11e, "is-selftest"), + BUILTIN_FCODE(0x11f, "new-device"), + BUILTIN_FCODE(0x120, "diagnostic-mode?"), + OBSOLETE_FCODE(0x121, "display-status"), + BUILTIN_FCODE(0x122, "memory-test-issue"), + OBSOLETE_FCODE(0x123, "group-code"), + BI_FCODE_VRBLE(0x124, "mask"), + BUILTIN_FCODE(0x125, "get-msecs"), + BUILTIN_FCODE(0x126, "ms"), + BUILTIN_FCODE(0x127, "finish-device"), + BUILTIN_FCODE(0x128, "decode-phys"), + BUILTIN_FCODE(0x12b, "interpose"), + BUILTIN_FCODE(0x130, "map-low"), + BUILTIN_FCODE(0x130, "map-sbus"), /* Synonym for "map-low" */ + BUILTIN_FCODE(0x131, "sbus-intr>cpu"), + BI_FCODE_VALUE(0x150, "#lines"), + BI_FCODE_VALUE(0x151, "#columns"), + BI_FCODE_VALUE(0x152, "line#"), + BI_FCODE_VALUE(0x153, "column#"), + BI_FCODE_VALUE(0x154, "inverse?"), + BI_FCODE_VALUE(0x155, "inverse-screen?"), + OBSOLETE_VALUE(0x156, "frame-buffer-busy?"), + BI_FCODE_DEFER(0x157, "draw-character"), + BI_FCODE_DEFER(0x158, "reset-screen"), + BI_FCODE_DEFER(0x159, "toggle-cursor"), + BI_FCODE_DEFER(0x15a, "erase-screen"), + BI_FCODE_DEFER(0x15b, "blink-screen"), + BI_FCODE_DEFER(0x15c, "invert-screen"), + BI_FCODE_DEFER(0x15d, "insert-characters"), + BI_FCODE_DEFER(0x15e, "delete-characters"), + BI_FCODE_DEFER(0x15f, "insert-lines"), + BI_FCODE_DEFER(0x160, "delete-lines"), + BI_FCODE_DEFER(0x161, "draw-logo"), + BI_FCODE_VALUE(0x162, "frame-buffer-adr"), + BI_FCODE_VALUE(0x163, "screen-height"), + BI_FCODE_VALUE(0x164, "screen-width"), + BI_FCODE_VALUE(0x165, "window-top"), + BI_FCODE_VALUE(0x166, "window-left"), + BUILTIN_FCODE(0x16a, "default-font"), + BUILTIN_FCODE(0x16b, "set-font"), + BI_FCODE_VALUE(0x16c, "char-height"), + BI_FCODE_VALUE(0x16d, "char-width"), + BUILTIN_FCODE(0x16e, ">font"), + BI_FCODE_VALUE(0x16f, "fontbytes"), + OBSOLETE_FCODE(0x170, "fb1-draw-character"), + OBSOLETE_FCODE(0x171, "fb1-reset-screen"), + OBSOLETE_FCODE(0x172, "fb1-toggle-cursor"), + OBSOLETE_FCODE(0x173, "fb1-erase-screen"), + OBSOLETE_FCODE(0x174, "fb1-blink-screen"), + OBSOLETE_FCODE(0x175, "fb1-invert-screen"), + OBSOLETE_FCODE(0x176, "fb1-insert-characters"), + OBSOLETE_FCODE(0x177, "fb1-delete-characters"), + OBSOLETE_FCODE(0x178, "fb1-insert-lines"), + OBSOLETE_FCODE(0x179, "fb1-delete-lines"), + OBSOLETE_FCODE(0x17a, "fb1-draw-logo"), + OBSOLETE_FCODE(0x17b, "fb1-install"), + OBSOLETE_FCODE(0x17c, "fb1-slide-up"), + BUILTIN_FCODE(0x180, "fb8-draw-character"), + BUILTIN_FCODE(0x181, "fb8-reset-screen"), + BUILTIN_FCODE(0x182, "fb8-toggle-cursor"), + BUILTIN_FCODE(0x183, "fb8-erase-screen"), + BUILTIN_FCODE(0x184, "fb8-blink-screen"), + BUILTIN_FCODE(0x185, "fb8-invert-screen"), + BUILTIN_FCODE(0x186, "fb8-insert-characters"), + BUILTIN_FCODE(0x187, "fb8-delete-characters"), + BUILTIN_FCODE(0x188, "fb8-insert-lines"), + BUILTIN_FCODE(0x189, "fb8-delete-lines"), + BUILTIN_FCODE(0x18a, "fb8-draw-logo"), + BUILTIN_FCODE(0x18b, "fb8-install"), + OBSOLETE_FCODE(0x1a0, "return-buffer"), + OBSOLETE_FCODE(0x1a1, "xmit-packet"), + OBSOLETE_FCODE(0x1a2, "poll-packet"), + BUILTIN_FCODE(0x1a4, "mac-address"), + BUILTIN_FCODE(0x201, "device-name"), + BUILTIN_FCODE(0x201, "name"), /* Synonym for "device-name" */ + BUILTIN_FCODE(0x202, "my-args"), + BI_FCODE_VALUE(0x203, "my-self"), + BUILTIN_FCODE(0x204, "find-package"), + BUILTIN_FCODE(0x205, "open-package"), + BUILTIN_FCODE(0x206, "close-package"), + BUILTIN_FCODE(0x207, "find-method"), + BUILTIN_FCODE(0x208, "call-package"), + BUILTIN_FCODE(0x209, "$call-parent"), + BUILTIN_FCODE(0x20a, "my-parent"), + BUILTIN_FCODE(0x20b, "ihandle>phandle"), + BUILTIN_FCODE(0x20d, "my-unit"), + BUILTIN_FCODE(0x20e, "$call-method"), + BUILTIN_FCODE(0x20f, "$open-package"), + OBSOLETE_FCODE(0x210, "processor-type"), + OBSOLETE_FCODE(0x211, "firmware-version"), + OBSOLETE_FCODE(0x212, "fcode-version"), + BUILTIN_FCODE(0x213, "alarm"), + BUILTIN_FCODE(0x214, "(is-user-word)"), + BUILTIN_FCODE(0x215, "suspend-fcode"), + BUILTIN_FCODE(0x216, "abort"), + BUILTIN_FCODE(0x217, "catch"), + BUILTIN_FCODE(0x218, "throw"), + BUILTIN_FCODE(0x219, "user-abort"), + BUILTIN_FCODE(0x21a, "get-my-property"), + BUILTIN_FCODE(0x21a, "get-my-attribute"), /* Synonym for "get-my-property" */ + BUILTIN_FCODE(0x21b, "decode-int"), + BUILTIN_FCODE(0x21b, "xdrtoint"), /* Synonym for "decode-int" */ + BUILTIN_FCODE(0x21c, "decode-string"), + BUILTIN_FCODE(0x21c, "xdrtostring"), /* Synonym for "decode-string" */ + BUILTIN_FCODE(0x21d, "get-inherited-property"), + BUILTIN_FCODE(0x21d, "get-inherited-attribute"), /* Synonym for "get-inherited-property" */ + BUILTIN_FCODE(0x21e, "delete-property"), + BUILTIN_FCODE(0x21e, "delete-attribute"), /* Synonym for "delete-property" */ + BUILTIN_FCODE(0x21f, "get-package-property"), + BUILTIN_FCODE(0x21f, "get-package-attribute"), /* Synonym for "get-package-property" */ + BUILTIN_FCODE(0x220, "cpeek"), + BUILTIN_FCODE(0x221, "wpeek"), + BUILTIN_FCODE(0x222, "lpeek"), + BUILTIN_FCODE(0x223, "cpoke"), + BUILTIN_FCODE(0x224, "wpoke"), + BUILTIN_FCODE(0x225, "lpoke"), + BUILTIN_FCODE(0x226, "lwflip"), + BUILTIN_FCODE(0x227, "lbflip"), + BUILTIN_FCODE(0x228, "lbflips"), + OBSOLETE_FCODE(0x229, "adr-mask"), + BUILTIN_FCODE(0x230, "rb@"), + BUILTIN_FCODE(0x231, "rb!"), + BUILTIN_FCODE(0x232, "rw@"), + BUILTIN_FCODE(0x233, "rw!"), + BUILTIN_FCODE(0x234, "rl@"), + BUILTIN_FCODE(0x235, "rl!"), + BUILTIN_FCODE(0x236, "wbflips"), + BUILTIN_FCODE(0x236, "wflips"), /* Synonym for "wbflips" */ + BUILTIN_FCODE(0x237, "lwflips"), + BUILTIN_FCODE(0x237, "lflips"), /* Synonym for "lwflips" */ + OBSOLETE_FCODE(0x238, "probe"), + OBSOLETE_FCODE(0x239, "probe-virtual"), + BUILTIN_FCODE(0x23b, "child"), + BUILTIN_FCODE(0x23c, "peer"), + BUILTIN_FCODE(0x23d, "next-property"), + BUILTIN_FCODE(0x23e, "byte-load"), + BUILTIN_FCODE(0x23f, "set-args"), + BUILTIN_FCODE(0x240, "left-parse-string"), /* FCodes from 64bit extension addendum */ - BUILTIN_FCODE( 0x22e, "rx@" ) , - BUILTIN_FCODE( 0x22f, "rx!" ) , - BUILTIN_FCODE( 0x241, "bxjoin" ) , - BUILTIN_FCODE( 0x242, "is_token; - } - return ( retval ); + bool retval = FALSE; + if (test_entry != NULL) { + retval = test_entry->is_token; + } + return (retval); } /* ************************************************************************** @@ -1482,15 +1457,13 @@ bool entry_is_token( tic_hdr_t *test_entry ) * **************************************************************************** */ -void token_entry_warning( tic_hdr_t *t_entry) +void token_entry_warning(tic_hdr_t * t_entry) { - if ( t_entry->funct == OBSO_FC_FUNC ) - { - obsolete_warning(); - } + if (t_entry->funct == OBSO_FC_FUNC) { + obsolete_warning(); + } } - /* ************************************************************************** * * Create the initial "FWords" list. @@ -1499,97 +1472,96 @@ void token_entry_warning( tic_hdr_t *t_entry) static tic_fwt_hdr_t fwords_list[] = { - BI_FWD_SKP_OW(COLON, ":") , - BUILTIN_FWORD(SEMICOLON, ";") , - BI_FWD_SKP_OW(TICK, "'") , - BUILTIN_FWORD(AGAIN, "again") , - BI_FWD_SKP_OW(BRACK_TICK, "[']") , - BI_FWD_SKP_OW(ASCII, "ascii") , - BUILTIN_FWORD(BEGIN, "begin") , - BI_FWD_SKP_OW(BUFFER, "buffer:") , - BUILTIN_FWORD(CASE, "case") , - BI_FWD_SKP_OW(CONST, "constant") , - BI_FWD_SKP_OW(CONTROL, "control") , - BI_FWD_SKP_OW(CREATE, "create") , - - BI_FWD_SKP_OW(DEFER, "defer") , - BUILTIN_FWORD(CDO, "?do") , - BUILTIN_FWORD(DO, "do") , - BUILTIN_FWORD(ELSE, "else") , - BUILTIN_FWORD(ENDCASE, "endcase") , - BUILTIN_FWORD(ENDOF, "endof") , - BUILTIN_FWORD(EXTERNAL, "external") , - BI_FWD_SKP_OW(FIELD, "field") , - BUILTIN_FWORD(FINISH_DEVICE, "finish-device" ) , - BUILTIN_FWORD(HEADERLESS, "headerless") , - BUILTIN_FWORD(HEADERS, "headers") , - - BUILTIN_FWORD(INSTANCE , "instance") , - - BUILTIN_FWORD(IF, "if") , - BUILTIN_FWORD(UNLOOP, "unloop") , - BUILTIN_FWORD(LEAVE, "leave") , - BUILTIN_FWORD(PLUS_LOOP, "+loop") , - BUILTIN_FWORD(LOOP, "loop") , - - BUILTIN_FWORD(OF, "of") , - BUILTIN_FWORD(REPEAT, "repeat") , - BUILTIN_FWORD(THEN, "then") , - BI_FWD_SKP_OW(TO, "to") , - BI_FWD_SKP_OW(IS, "is") , /* Deprecated synonym to TO */ - BUILTIN_FWORD(UNTIL, "until") , - BI_FWD_SKP_OW(VALUE, "value") , - BI_FWD_SKP_OW(VARIABLE, "variable") , - BUILTIN_FWORD(WHILE, "while") , - BUILTIN_FWORD(OFFSET16, "offset16") , - - BI_FWD_STRING(STRING, "\"") , /* XXXXX */ - BI_FWD_STRING(PSTRING, ".\"") , /* XXXXX */ - BI_FWD_STRING(PBSTRING, ".(") , /* XXXXX */ - BI_FWD_STRING(SSTRING, "s\"") , /* XXXXX */ - BUILTIN_FWORD(IFILE_NAME, "[input-file-name]"), - BUILTIN_FWORD(ILINE_NUM, "[line-number]"), - BUILTIN_FWORD(RECURSE, "recurse") , - BUILTIN_FWORD(RECURSIVE, "recursive") , - BUILTIN_FWORD(RET_STK_FETCH, "r@") , - BUILTIN_FWORD(RET_STK_FROM, "r>") , - BUILTIN_FWORD(RET_STK_TO, ">r") , - BUILTIN_FWORD(THEN, "endif" ) , /* Synonym for "then" */ - BUILTIN_FWORD(NEW_DEVICE, "new-device" ) , - BUILTIN_FWORD(LOOP_I, "i") , - BUILTIN_FWORD(LOOP_J, "j") , + BI_FWD_SKP_OW(COLON, ":"), + BUILTIN_FWORD(SEMICOLON, ";"), + BI_FWD_SKP_OW(TICK, "'"), + BUILTIN_FWORD(AGAIN, "again"), + BI_FWD_SKP_OW(BRACK_TICK, "[']"), + BI_FWD_SKP_OW(ASCII, "ascii"), + BUILTIN_FWORD(BEGIN, "begin"), + BI_FWD_SKP_OW(BUFFER, "buffer:"), + BUILTIN_FWORD(CASE, "case"), + BI_FWD_SKP_OW(CONST, "constant"), + BI_FWD_SKP_OW(CONTROL, "control"), + BI_FWD_SKP_OW(CREATE, "create"), + + BI_FWD_SKP_OW(DEFER, "defer"), + BUILTIN_FWORD(CDO, "?do"), + BUILTIN_FWORD(DO, "do"), + BUILTIN_FWORD(ELSE, "else"), + BUILTIN_FWORD(ENDCASE, "endcase"), + BUILTIN_FWORD(ENDOF, "endof"), + BUILTIN_FWORD(EXTERNAL, "external"), + BI_FWD_SKP_OW(FIELD, "field"), + BUILTIN_FWORD(FINISH_DEVICE, "finish-device"), + BUILTIN_FWORD(HEADERLESS, "headerless"), + BUILTIN_FWORD(HEADERS, "headers"), + + BUILTIN_FWORD(INSTANCE, "instance"), + + BUILTIN_FWORD(IF, "if"), + BUILTIN_FWORD(UNLOOP, "unloop"), + BUILTIN_FWORD(LEAVE, "leave"), + BUILTIN_FWORD(PLUS_LOOP, "+loop"), + BUILTIN_FWORD(LOOP, "loop"), + + BUILTIN_FWORD(OF, "of"), + BUILTIN_FWORD(REPEAT, "repeat"), + BUILTIN_FWORD(THEN, "then"), + BI_FWD_SKP_OW(TO, "to"), + BI_FWD_SKP_OW(IS, "is"), /* Deprecated synonym to TO */ + BUILTIN_FWORD(UNTIL, "until"), + BI_FWD_SKP_OW(VALUE, "value"), + BI_FWD_SKP_OW(VARIABLE, "variable"), + BUILTIN_FWORD(WHILE, "while"), + BUILTIN_FWORD(OFFSET16, "offset16"), + + BI_FWD_STRING(STRING, "\""), /* XXXXX */ + BI_FWD_STRING(PSTRING, ".\""), /* XXXXX */ + BI_FWD_STRING(PBSTRING, ".("), /* XXXXX */ + BI_FWD_STRING(SSTRING, "s\""), /* XXXXX */ + BUILTIN_FWORD(IFILE_NAME, "[input-file-name]"), + BUILTIN_FWORD(ILINE_NUM, "[line-number]"), + BUILTIN_FWORD(RECURSE, "recurse"), + BUILTIN_FWORD(RECURSIVE, "recursive"), + BUILTIN_FWORD(RET_STK_FETCH, "r@"), + BUILTIN_FWORD(RET_STK_FROM, "r>"), + BUILTIN_FWORD(RET_STK_TO, ">r"), + BUILTIN_FWORD(THEN, "endif"), /* Synonym for "then" */ + BUILTIN_FWORD(NEW_DEVICE, "new-device"), + BUILTIN_FWORD(LOOP_I, "i"), + BUILTIN_FWORD(LOOP_J, "j"), /* version1 is also an fcode word, but it * needs to trigger some tokenizer internals */ - BUILTIN_FWORD(VERSION1, "version1") , - BUILTIN_FWORD(START0, "start0") , - BUILTIN_FWORD(START1, "start1") , - BUILTIN_FWORD(START2, "start2") , - BUILTIN_FWORD(START4, "start4") , - BUILTIN_FWORD(END0, "end0") , - BUILTIN_FWORD(END1, "end1") , - BUILTIN_FWORD(FCODE_V1, "fcode-version1") , - BUILTIN_FWORD(FCODE_V2, "fcode-version2") , - BUILTIN_FWORD(FCODE_V3, "fcode-version3") , - BUILTIN_FWORD(FCODE_END, "fcode-end") , - - /* Support for IBM-style Locals */ - BI_FWD_STRING(CURLY_BRACE, "{") , - BI_FWD_STRING(DASH_ARROW, "->") , - BUILTIN_FWORD(EXIT, "exit") , - - - BUILTIN_FWORD(CHAR, "char") , - BUILTIN_FWORD(CCHAR, "[char]") , - BI_FWD_STRING(ABORTTXT, "abort\"") , - - BUILTIN_FWORD(ENCODEFILE, "encode-file") , - - BI_IG_FW_HDLR(ESCAPETOK, "tokenizer[") , - BI_IG_FW_HDLR(ESCAPETOK, "f[") , /* An IBM-ish synonym */ + BUILTIN_FWORD(VERSION1, "version1"), + BUILTIN_FWORD(START0, "start0"), + BUILTIN_FWORD(START1, "start1"), + BUILTIN_FWORD(START2, "start2"), + BUILTIN_FWORD(START4, "start4"), + BUILTIN_FWORD(END0, "end0"), + BUILTIN_FWORD(END1, "end1"), + BUILTIN_FWORD(FCODE_V1, "fcode-version1"), + BUILTIN_FWORD(FCODE_V2, "fcode-version2"), + BUILTIN_FWORD(FCODE_V3, "fcode-version3"), + BUILTIN_FWORD(FCODE_END, "fcode-end"), + + /* Support for IBM-style Locals */ + BI_FWD_STRING(CURLY_BRACE, "{"), + BI_FWD_STRING(DASH_ARROW, "->"), + BUILTIN_FWORD(EXIT, "exit"), + + BUILTIN_FWORD(CHAR, "char"), + BUILTIN_FWORD(CCHAR, "[char]"), + BI_FWD_STRING(ABORTTXT, "abort\""), + + BUILTIN_FWORD(ENCODEFILE, "encode-file"), + + BI_IG_FW_HDLR(ESCAPETOK, "tokenizer["), + BI_IG_FW_HDLR(ESCAPETOK, "f["), /* An IBM-ish synonym */ }; static const int number_of_builtin_fwords = - sizeof(fwords_list)/sizeof(tic_hdr_t); + sizeof(fwords_list) / sizeof(tic_hdr_t); /* ************************************************************************** * @@ -1600,38 +1572,38 @@ static const int number_of_builtin_fwords = **************************************************************************** */ static tic_fwt_hdr_t shared_words_list[] = { - SHARED_FWORD(FLOAD, "fload") , + SHARED_FWORD(FLOAD, "fload"), /* As does the "Allow Multi-Line" directive */ - SHR_SAMIG_FWRD(ALLOW_MULTI_LINE, "multi-line") , + SHR_SAMIG_FWRD(ALLOW_MULTI_LINE, "multi-line"), - SHR_FWD_SKOW( F_BRACK_TICK, "f[']") , + SHR_FWD_SKOW(F_BRACK_TICK, "f[']"), - SH_FW_SK2WIL(ALIAS, "alias") , - SHARED_FWORD(DECIMAL, "decimal") , - SHARED_FWORD(HEX, "hex") , - SHARED_FWORD(OCTAL, "octal") , - SH_FW_SK_WIL(HEXVAL, "h#") , - SH_FW_SK_WIL(DECVAL, "d#") , - SH_FW_SK_WIL(OCTVAL, "o#") , + SH_FW_SK2WIL(ALIAS, "alias"), + SHARED_FWORD(DECIMAL, "decimal"), + SHARED_FWORD(HEX, "hex"), + SHARED_FWORD(OCTAL, "octal"), + SH_FW_SK_WIL(HEXVAL, "h#"), + SH_FW_SK_WIL(DECVAL, "d#"), + SH_FW_SK_WIL(OCTVAL, "o#"), - SH_FW_SK_WIL(ASC_NUM, "a#") , - SH_FW_SK_WIL(ASC_LEFT_NUM, "al#") , + SH_FW_SK_WIL(ASC_NUM, "a#"), + SH_FW_SK_WIL(ASC_LEFT_NUM, "al#"), /* IBM-style extension. Might be generalizable... */ - SHARED_FWORD(FLITERAL, "fliteral") , + SHARED_FWORD(FLITERAL, "fliteral"), /* Directives to extract the value of a Command-Line symbol */ - SH_FW_SK_WIL(DEFINED, "[defined]") , - SH_FW_SK_WIL(DEFINED, "#defined") , - SH_FW_SK_WIL(DEFINED, "[#defined]") , + SH_FW_SK_WIL(DEFINED, "[defined]"), + SH_FW_SK_WIL(DEFINED, "#defined"), + SH_FW_SK_WIL(DEFINED, "[#defined]"), /* Present the current date or time, either as an */ /* in-line string or as a user-generated message. */ - SHARED_FWORD(FCODE_DATE, "[fcode-date]") , - SHARED_FWORD(FCODE_TIME, "[fcode-time]") , + SHARED_FWORD(FCODE_DATE, "[fcode-date]"), + SHARED_FWORD(FCODE_TIME, "[fcode-time]"), /* Current definition under construction, similarly */ - SHARED_FWORD(FUNC_NAME, "[function-name]"), + SHARED_FWORD(FUNC_NAME, "[function-name]"), /* Synonymous forms of the #ELSE and #THEN operators, * associated with Conditional-Compilation, @@ -1640,83 +1612,82 @@ static tic_fwt_hdr_t shared_words_list[] = { */ /* #ELSE operators */ - SHARED_FWORD(CONDL_ELSE, "#else") , - SHARED_FWORD(CONDL_ELSE, "[else]") , - SHARED_FWORD(CONDL_ELSE, "[#else]") , + SHARED_FWORD(CONDL_ELSE, "#else"), + SHARED_FWORD(CONDL_ELSE, "[else]"), + SHARED_FWORD(CONDL_ELSE, "[#else]"), /* #THEN operators */ - SHARED_FWORD(CONDL_ENDER, "#then") , - SHARED_FWORD(CONDL_ENDER, "[then]") , - SHARED_FWORD(CONDL_ENDER, "[#then]") , + SHARED_FWORD(CONDL_ENDER, "#then"), + SHARED_FWORD(CONDL_ENDER, "[then]"), + SHARED_FWORD(CONDL_ENDER, "[#then]"), /* #ENDIF variants for users who favor C-style notation */ - SHARED_FWORD(CONDL_ENDER, "#endif") , - SHARED_FWORD(CONDL_ENDER, "[endif]") , - SHARED_FWORD(CONDL_ENDER, "[#endif]") , + SHARED_FWORD(CONDL_ENDER, "#endif"), + SHARED_FWORD(CONDL_ENDER, "[endif]"), + SHARED_FWORD(CONDL_ENDER, "[#endif]"), + SHARED_FWORD(OVERLOAD, "overload"), - SHARED_FWORD(OVERLOAD, "overload" ) , - - SHARED_FWORD(GLOB_SCOPE , "global-definitions" ) , - SHARED_FWORD(DEV_SCOPE , "device-definitions" ) , + SHARED_FWORD(GLOB_SCOPE, "global-definitions"), + SHARED_FWORD(DEV_SCOPE, "device-definitions"), /* Directives to change a command-line flag value from source */ - SH_FW_SK_WIL(CL_FLAG, "[FLAG]") , - SH_FW_SK_WIL(CL_FLAG, "#FLAG") , - SH_FW_SK_WIL(CL_FLAG, "[#FLAG]") , + SH_FW_SK_WIL(CL_FLAG, "[FLAG]"), + SH_FW_SK_WIL(CL_FLAG, "#FLAG"), + SH_FW_SK_WIL(CL_FLAG, "[#FLAG]"), /* Directives to force display of a command-line flags' values */ - SHARED_FWORD(SHOW_CL_FLAGS, "[FLAGS]") , - SHARED_FWORD(SHOW_CL_FLAGS, "#FLAGS") , - SHARED_FWORD(SHOW_CL_FLAGS, "[#FLAGS]") , - SHARED_FWORD(SHOW_CL_FLAGS, "SHOW-FLAGS") , + SHARED_FWORD(SHOW_CL_FLAGS, "[FLAGS]"), + SHARED_FWORD(SHOW_CL_FLAGS, "#FLAGS"), + SHARED_FWORD(SHOW_CL_FLAGS, "[#FLAGS]"), + SHARED_FWORD(SHOW_CL_FLAGS, "SHOW-FLAGS"), /* Directives to save and retrieve the FCode Assignment number */ - SHARED_FWORD(PUSH_FCODE, "FCODE-PUSH") , - SHARED_FWORD(POP_FCODE, "FCODE-POP") , + SHARED_FWORD(PUSH_FCODE, "FCODE-PUSH"), + SHARED_FWORD(POP_FCODE, "FCODE-POP"), /* Directive to reset the FCode Assignment number and * re-initialize FCode Range overlap checking. */ - SHARED_FWORD(RESET_FCODE, "FCODE-RESET") , + SHARED_FWORD(RESET_FCODE, "FCODE-RESET"), /* pci header generation is done differently * across the available tokenizers. We try to * be compatible to all of them */ - SHARED_FWORD(PCIHDR, "pci-header") , - SHARED_FWORD(PCIEND, "pci-end") , /* SUN syntax */ - SHARED_FWORD(PCIEND, "pci-header-end") , /* Firmworks syntax */ - SHARED_FWORD(PCIREV, "pci-revision") , /* SUN syntax */ - SHARED_FWORD(PCIREV, "pci-code-revision") , /* SUN syntax */ - SHARED_FWORD(PCIREV, "set-rev-level") , /* Firmworks syntax */ - SHARED_FWORD(NOTLAST, "not-last-image") , - SHARED_FWORD(NOTLAST, "not-last-img") , /* Shorthand form */ - SHARED_FWORD(ISLAST, "last-image") , - SHARED_FWORD(ISLAST, "last-img") , /* Shorthand form */ - SHARED_FWORD(SETLAST, "set-last-image") , - SHARED_FWORD(SETLAST, "set-last-img") , /* Shorthand form */ - - SH_FW_SK_WIL(SAVEIMG, "save-image") , - SH_FW_SK_WIL(SAVEIMG, "save-img") , /* Shorthand form */ - - SHARED_FWORD(RESETSYMBS, "reset-symbols") , + SHARED_FWORD(PCIHDR, "pci-header"), + SHARED_FWORD(PCIEND, "pci-end"), /* SUN syntax */ + SHARED_FWORD(PCIEND, "pci-header-end"), /* Firmworks syntax */ + SHARED_FWORD(PCIREV, "pci-revision"), /* SUN syntax */ + SHARED_FWORD(PCIREV, "pci-code-revision"), /* SUN syntax */ + SHARED_FWORD(PCIREV, "set-rev-level"), /* Firmworks syntax */ + SHARED_FWORD(NOTLAST, "not-last-image"), + SHARED_FWORD(NOTLAST, "not-last-img"), /* Shorthand form */ + SHARED_FWORD(ISLAST, "last-image"), + SHARED_FWORD(ISLAST, "last-img"), /* Shorthand form */ + SHARED_FWORD(SETLAST, "set-last-image"), + SHARED_FWORD(SETLAST, "set-last-img"), /* Shorthand form */ + + SH_FW_SK_WIL(SAVEIMG, "save-image"), + SH_FW_SK_WIL(SAVEIMG, "save-img"), /* Shorthand form */ + + SHARED_FWORD(RESETSYMBS, "reset-symbols"), /* User-Macro definers */ - SHARED_IG_HDLR("[MACRO]", add_user_macro, 0 , skip_user_macro) , + SHARED_IG_HDLR("[MACRO]", add_user_macro, 0, skip_user_macro), /* Comments and Remarks */ - SHARED_IG_HDLR("\\", process_remark, '\n', process_remark) , - SHARED_IG_HDLR("(", process_remark, ')', process_remark) , + SHARED_IG_HDLR("\\", process_remark, '\n', process_remark), + SHARED_IG_HDLR("(", process_remark, ')', process_remark), /* Directives to print or discard a user-generated message */ - SHARED_IG_HDLR("[MESSAGE]", user_message, '\n', skip_user_message) , - SHARED_IG_HDLR("#MESSAGE", user_message, '\n', skip_user_message) , - SHARED_IG_HDLR("[#MESSAGE]", user_message, '\n', skip_user_message) , - SHARED_IG_HDLR("#MESSAGE\"", user_message, '"' , skip_user_message) , + SHARED_IG_HDLR("[MESSAGE]", user_message, '\n', skip_user_message), + SHARED_IG_HDLR("#MESSAGE", user_message, '\n', skip_user_message), + SHARED_IG_HDLR("[#MESSAGE]", user_message, '\n', skip_user_message), + SHARED_IG_HDLR("#MESSAGE\"", user_message, '"', skip_user_message), }; static const int number_of_shared_words = - sizeof(shared_words_list)/sizeof(tic_hdr_t); + sizeof(shared_words_list) / sizeof(tic_hdr_t); /* ************************************************************************** * @@ -1749,22 +1720,20 @@ static const int number_of_shared_words = * applying it here and in the other place(s). * **************************************************************************** */ - -tic_hdr_t *lookup_shared_word( char *tname) + +tic_hdr_t *lookup_shared_word(char *tname) { - tic_hdr_t *found ; - tic_hdr_t *retval = NULL ; - - found = lookup_current( tname ); - if ( found != NULL ) - { - if ( found->fword_defr == COMMON_FWORD ) - { - retval = found ; + tic_hdr_t *found; + tic_hdr_t *retval = NULL; + + found = lookup_current(tname); + if (found != NULL) { + if (found->fword_defr == COMMON_FWORD) { + retval = found; + } } - } - return ( retval ); + return (retval); } @@ -1799,22 +1768,20 @@ tic_hdr_t *lookup_shared_word( char *tname) * the core of this routine... * **************************************************************************** */ - -tic_hdr_t *lookup_shared_f_exec_word( char *tname) + +tic_hdr_t *lookup_shared_f_exec_word(char *tname) { - tic_hdr_t *found ; - tic_hdr_t *retval = NULL ; - - found = lookup_shared_word( tname ); - if ( found != NULL ) - { - if ( found->funct == FWORD_EXEC_FUNC ) - { - retval = found ; + tic_hdr_t *found; + tic_hdr_t *retval = NULL; + + found = lookup_shared_word(tname); + if (found != NULL) { + if (found->funct == FWORD_EXEC_FUNC) { + retval = found; + } } - } - return ( retval ); + return (retval); } @@ -1865,42 +1832,39 @@ tic_hdr_t *lookup_shared_f_exec_word( char *tname) * **************************************************************************** */ -void init_dictionary( void ) +void init_dictionary(void) { - global_voc_dict_ptr = NULL; /* Belt-and-suspenders... */ + global_voc_dict_ptr = NULL; /* Belt-and-suspenders... */ - /* The "FC-Tokens" list must be linked first. */ - fc_tokens_list_ender = global_voc_dict_ptr; - init_tic_vocab( tokens_table, - number_of_builtin_tokens, - &global_voc_dict_ptr ) ; - fc_tokens_list_start = global_voc_dict_ptr; + /* The "FC-Tokens" list must be linked first. */ + fc_tokens_list_ender = global_voc_dict_ptr; + init_tic_vocab(tokens_table, + number_of_builtin_tokens, &global_voc_dict_ptr); + fc_tokens_list_start = global_voc_dict_ptr; - /* Link the "FWords" next */ - init_tic_vocab( (tic_hdr_t *)fwords_list, - number_of_builtin_fwords, - &global_voc_dict_ptr ) ; + /* Link the "FWords" next */ + init_tic_vocab((tic_hdr_t *) fwords_list, + number_of_builtin_fwords, &global_voc_dict_ptr); - /* Mark the end-limit of the "Shared Words", and link them. */ - shared_fwords_ender = global_voc_dict_ptr; - init_tic_vocab( (tic_hdr_t *)shared_words_list, - number_of_shared_words, - &global_voc_dict_ptr ) ; + /* Mark the end-limit of the "Shared Words", and link them. */ + shared_fwords_ender = global_voc_dict_ptr; + init_tic_vocab((tic_hdr_t *) shared_words_list, + number_of_shared_words, &global_voc_dict_ptr); - /* Link the "Conditionals" to the Global Vocabulary. */ - init_conditionals_vocab( &global_voc_dict_ptr ) ; + /* Link the "Conditionals" to the Global Vocabulary. */ + init_conditionals_vocab(&global_voc_dict_ptr); - /* Link the Built-In Macros */ - init_macros( &global_voc_dict_ptr ) ; + /* Link the Built-In Macros */ + init_macros(&global_voc_dict_ptr); - /* Mark the reset-point for the Global Vocabulary. */ - global_voc_reset_ptr = global_voc_dict_ptr; + /* Mark the reset-point for the Global Vocabulary. */ + global_voc_reset_ptr = global_voc_dict_ptr; - /* Initialize the "Tokenizer Escape" mode vocabulary */ - init_tokz_esc_vocab(); + /* Initialize the "Tokenizer Escape" mode vocabulary */ + init_tokz_esc_vocab(); - /* Locals and Device-Node vocabularies are initially empty */ + /* Locals and Device-Node vocabularies are initially empty */ } @@ -1949,28 +1913,25 @@ void init_dictionary( void ) * **************************************************************************** */ -void reset_normal_vocabs( void ) +void reset_normal_vocabs(void) { - reset_tic_vocab( &global_voc_dict_ptr, global_voc_reset_ptr ); - - /* Delete the top-level device-node vocab. - * If there are extra device-nodes, - * delete their data structures and show errors - */ - do - { - if ( current_device_node->parent_node != NULL ) - { - tokenization_error( TKERROR, - "Missing FINISH-DEVICE for new device"); - started_at( current_device_node->ifile_name, - current_device_node->line_no ); - } - delete_device_vocab(); - } while ( current_device_node->parent_node != NULL ); + reset_tic_vocab(&global_voc_dict_ptr, global_voc_reset_ptr); -} + /* Delete the top-level device-node vocab. + * If there are extra device-nodes, + * delete their data structures and show errors + */ + do { + if (current_device_node->parent_node != NULL) { + tokenization_error(TKERROR, + "Missing FINISH-DEVICE for new device"); + started_at(current_device_node->ifile_name, + current_device_node->line_no); + } + delete_device_vocab(); + } while (current_device_node->parent_node != NULL); +} /* ************************************************************************** * @@ -1996,8 +1957,8 @@ void reset_normal_vocabs( void ) * **************************************************************************** */ -void reset_vocabs( void ) +void reset_vocabs(void) { - reset_normal_vocabs(); - reset_tokz_esc(); + reset_normal_vocabs(); + reset_tokz_esc(); } diff --git a/toke/dictionary.h b/toke/dictionary.h index 92f4695..6c05d39 100644 --- a/toke/dictionary.h +++ b/toke/dictionary.h @@ -43,136 +43,136 @@ **************************************************************************** */ typedef enum fword_token { - UNSPECIFIED = 0xBAADD00D , /* Default (absence-of) "definer" */ - COMMON_FWORD = 0xC0EDC0DE , /* Definer indicating a "shared" FWord */ - BI_FWRD_DEFN = 0xB1F4409D , /* Definer indicating a "built-in FWord" */ - COLON = 1 , - SEMICOLON , - TICK , - AGAIN , - ALIAS , - BRACK_TICK , - F_BRACK_TICK , - ASCII , - BEGIN , - BUFFER , - CASE , - CONST , - CONTROL , - CREATE , - DECIMAL , - DEFER , - DEFINED , - CDO , - DO , - ELSE , - ENDCASE , - ENDOF , - EXTERNAL , - INSTANCE , - FIELD , - NEW_DEVICE , - FINISH_DEVICE , - FLITERAL , - HEADERLESS , - HEADERS , - HEX , - IF , - UNLOOP , - LEAVE , - LOOP_I , - LOOP_J , - LOOP , - PLUS_LOOP , - OCTAL , - OF , - REPEAT , - THEN , - TO , - IS , - UNTIL , - VALUE , - VARIABLE , - WHILE , - OFFSET16 , - ESCAPETOK , - EMITBYTE , - FLOAD , - STRING , - PSTRING , - PBSTRING , - SSTRING , - RECURSIVE , - RECURSE , - RET_STK_FETCH , - RET_STK_FROM , - RET_STK_TO , - HEXVAL , - DECVAL , - OCTVAL , - - ret_stk_from , - ASC_NUM , /* Convert char seq to number */ - ASC_LEFT_NUM , /* same, only left-justified. */ - - CONDL_ENDER , /* Conditional "[THEN] / [ENDIF]" variants */ - CONDL_ELSE , /* Conditional "[ELSE]" directive variants */ - - PUSH_FCODE , /* Save the FCode Assignment number */ - POP_FCODE , /* Retrieve the FCode Assignment number */ - RESET_FCODE , /* Reset FCode Ass't nr and overlap checking */ - - CURLY_BRACE , /* Support for IBM-style Locals */ - DASH_ARROW , - LOCAL_VAL , - EXIT , - - FUNC_NAME , - IFILE_NAME , - ILINE_NUM , - - CL_FLAG , - SHOW_CL_FLAGS , - - OVERLOAD , - ALLOW_MULTI_LINE , - MACRO_DEF , - GLOB_SCOPE , - DEV_SCOPE , - - /* This value has to be adjusted - * so that FCODE_END comes - * out to be 0xff - */ - END0 = 0xd7 , /* 0xd7 */ - END1 , /* 0xd8 */ - CHAR , /* 0xd9 */ - CCHAR , /* 0xda */ - ABORTTXT , /* 0xdb */ - - NEXTFCODE , /* 0xdc */ - - ENCODEFILE , /* 0xdd */ - - FCODE_V1 , /* 0xde */ - FCODE_V3 , /* 0xdf */ - NOTLAST , /* 0xef */ - ISLAST , /* 0xf0 */ - SETLAST , /* 0xf1 */ - PCIREV , /* 0xf2 */ - PCIHDR , /* 0xf3 */ - PCIEND , /* 0xf4 */ - RESETSYMBS , /* 0xf5 */ - SAVEIMG , /* 0xf6 */ - START0 , /* 0xf7 */ - START1 , /* 0xf8 */ - START2 , /* 0xf9 */ - START4 , /* 0xfa */ - VERSION1 , /* 0xfb */ - FCODE_TIME , /* 0xfc */ - FCODE_DATE , /* 0xfd */ - FCODE_V2 , /* 0xfe */ - FCODE_END = 0xff /* 0xff */ -} fwtoken ; - -#endif /* _TOKE_DICTIONARY_H */ + UNSPECIFIED = 0xBAADD00D, /* Default (absence-of) "definer" */ + COMMON_FWORD = 0xC0EDC0DE, /* Definer indicating a "shared" FWord */ + BI_FWRD_DEFN = 0xB1F4409D, /* Definer indicating a "built-in FWord" */ + COLON = 1, + SEMICOLON, + TICK, + AGAIN, + ALIAS, + BRACK_TICK, + F_BRACK_TICK, + ASCII, + BEGIN, + BUFFER, + CASE, + CONST, + CONTROL, + CREATE, + DECIMAL, + DEFER, + DEFINED, + CDO, + DO, + ELSE, + ENDCASE, + ENDOF, + EXTERNAL, + INSTANCE, + FIELD, + NEW_DEVICE, + FINISH_DEVICE, + FLITERAL, + HEADERLESS, + HEADERS, + HEX, + IF, + UNLOOP, + LEAVE, + LOOP_I, + LOOP_J, + LOOP, + PLUS_LOOP, + OCTAL, + OF, + REPEAT, + THEN, + TO, + IS, + UNTIL, + VALUE, + VARIABLE, + WHILE, + OFFSET16, + ESCAPETOK, + EMITBYTE, + FLOAD, + STRING, + PSTRING, + PBSTRING, + SSTRING, + RECURSIVE, + RECURSE, + RET_STK_FETCH, + RET_STK_FROM, + RET_STK_TO, + HEXVAL, + DECVAL, + OCTVAL, + + ret_stk_from, + ASC_NUM, /* Convert char seq to number */ + ASC_LEFT_NUM, /* same, only left-justified. */ + + CONDL_ENDER, /* Conditional "[THEN] / [ENDIF]" variants */ + CONDL_ELSE, /* Conditional "[ELSE]" directive variants */ + + PUSH_FCODE, /* Save the FCode Assignment number */ + POP_FCODE, /* Retrieve the FCode Assignment number */ + RESET_FCODE, /* Reset FCode Ass't nr and overlap checking */ + + CURLY_BRACE, /* Support for IBM-style Locals */ + DASH_ARROW, + LOCAL_VAL, + EXIT, + + FUNC_NAME, + IFILE_NAME, + ILINE_NUM, + + CL_FLAG, + SHOW_CL_FLAGS, + + OVERLOAD, + ALLOW_MULTI_LINE, + MACRO_DEF, + GLOB_SCOPE, + DEV_SCOPE, + + /* This value has to be adjusted + * so that FCODE_END comes + * out to be 0xff + */ + END0 = 0xd7, /* 0xd7 */ + END1, /* 0xd8 */ + CHAR, /* 0xd9 */ + CCHAR, /* 0xda */ + ABORTTXT, /* 0xdb */ + + NEXTFCODE, /* 0xdc */ + + ENCODEFILE, /* 0xdd */ + + FCODE_V1, /* 0xde */ + FCODE_V3, /* 0xdf */ + NOTLAST, /* 0xef */ + ISLAST, /* 0xf0 */ + SETLAST, /* 0xf1 */ + PCIREV, /* 0xf2 */ + PCIHDR, /* 0xf3 */ + PCIEND, /* 0xf4 */ + RESETSYMBS, /* 0xf5 */ + SAVEIMG, /* 0xf6 */ + START0, /* 0xf7 */ + START1, /* 0xf8 */ + START2, /* 0xf9 */ + START4, /* 0xfa */ + VERSION1, /* 0xfb */ + FCODE_TIME, /* 0xfc */ + FCODE_DATE, /* 0xfd */ + FCODE_V2, /* 0xfe */ + FCODE_END = 0xff /* 0xff */ +} fwtoken; + +#endif /* _TOKE_DICTIONARY_H */ diff --git a/toke/emit.c b/toke/emit.c index 010868e..c69b109 100644 --- a/toke/emit.c +++ b/toke/emit.c @@ -68,7 +68,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Global Variables Exported: @@ -80,8 +79,8 @@ * **************************************************************************** */ -unsigned int opc = 0; -unsigned int pci_hdr_end_ob_off = 0; /* 0 means "Not initialized" */ +unsigned int opc = 0; +unsigned int pci_hdr_end_ob_off = 0; /* 0 means "Not initialized" */ /* ************************************************************************** * @@ -92,7 +91,6 @@ unsigned int pci_hdr_end_ob_off = 0; /* 0 means "Not initialized" */ #define EMIT_STRUCT(x) {int j; for (j=0; j < sizeof(x) ; j++ ) emit_byte(0); } - /* ************************************************************************** * * Local Static Variables, offsets into Output Buffer of ...: @@ -106,11 +104,11 @@ unsigned int pci_hdr_end_ob_off = 0; /* 0 means "Not initialized" */ * *************************************************************************** */ -static int fcode_start_ob_off = -1; -static int fcode_hdr_ob_off = -1; -static int fcode_body_ob_off = -1; -static int pci_hdr_ob_off = -1; -static int pci_data_blk_ob_off = -1; +static int fcode_start_ob_off = -1; +static int fcode_hdr_ob_off = -1; +static int fcode_body_ob_off = -1; +static int pci_hdr_ob_off = -1; +static int pci_data_blk_ob_off = -1; /* ************************************************************************** * @@ -134,8 +132,7 @@ static bool fcode_written = FALSE; extern u8 *ostart; extern int olen; -extern void increase_output_buffer( void); - +extern void increase_output_buffer(void); /* ************************************************************************** * @@ -145,21 +142,20 @@ extern void increase_output_buffer( void); * Exposure as Limited as possible. * **************************************************************************** */ -void init_emit( void); /* Prototype. Limit Exposure. */ -void init_emit( void) +void init_emit(void); /* Prototype. Limit Exposure. */ +void init_emit(void) { - fcode_start_ob_off = -1; - fcode_hdr_ob_off = -1; - fcode_body_ob_off = -1; - pci_hdr_ob_off = -1; - pci_data_blk_ob_off = -1; - opc = 0; - pci_hdr_end_ob_off = 0; - fcode_written = FALSE; - haveend = FALSE; /* Get this one too... */ + fcode_start_ob_off = -1; + fcode_hdr_ob_off = -1; + fcode_body_ob_off = -1; + pci_hdr_ob_off = -1; + pci_data_blk_ob_off = -1; + opc = 0; + pci_hdr_end_ob_off = 0; + fcode_written = FALSE; + haveend = FALSE; /* Get this one too... */ } - /* ************************************************************************** * * Function name: emit_byte @@ -172,31 +168,29 @@ void init_emit( void) static void emit_byte(u8 data) { - if ( opc == olen) - { - increase_output_buffer(); + if (opc == olen) { + increase_output_buffer(); } - - *(ostart+opc) = data ; + *(ostart + opc) = data; opc++; } void emit_fcode(u16 tok) { - if ((tok>>8)) - emit_byte(tok>>8); + if ((tok >> 8)) + emit_byte(tok >> 8); - emit_byte(tok&0xff); + emit_byte(tok & 0xff); fcode_written = TRUE; } static void emit_num32(u32 num) { - emit_byte(num>>24); - emit_byte((num>>16)&0xff); - emit_byte((num>>8)&0xff); - emit_byte(num&0xff); + emit_byte(num >> 24); + emit_byte((num >> 16) & 0xff); + emit_byte((num >> 8) & 0xff); + emit_byte(num & 0xff); } @@ -211,58 +205,58 @@ static void emit_num32(u32 num) void user_emit_byte(u8 data) { - emit_byte( data); + emit_byte(data); fcode_written = TRUE; } void emit_offset(s16 offs) { - /* Calling routine will test for out-of-range FCode-Offset */ + /* Calling routine will test for out-of-range FCode-Offset */ if (offs16) - emit_byte(offs>>8); - emit_byte(offs&0xff); + emit_byte(offs >> 8); + emit_byte(offs & 0xff); } void emit_literal(u32 num) { - emit_token("b(lit)"); - emit_num32(num); + emit_token("b(lit)"); + emit_num32(num); } -void emit_string(u8 *string, signed int cnt) +void emit_string(u8 * string, signed int cnt) { - signed int i=0; + signed int i = 0; signed int cnt_cpy = cnt; - - if ( cnt_cpy > STRING_LEN_MAX ) - { - tokenization_error( TKERROR, - "String too long: %d characters. Truncating.\n",cnt); - cnt_cpy = STRING_LEN_MAX ; + + if (cnt_cpy > STRING_LEN_MAX) { + tokenization_error(TKERROR, + "String too long: %d characters. Truncating.\n", + cnt); + cnt_cpy = STRING_LEN_MAX; } emit_byte(cnt_cpy); - for (i=0; i> 16); - checksum = (checksum & 0xffff) + (checksum >> 16); - } - - BIG_ENDIAN_WORD_STORE(fcode_hdr->checksum, - (u16)(checksum & 0xffff)); - BIG_ENDIAN_LONG_STORE(fcode_hdr->length , length); - - if (verbose) - { - printf( "toke: checksum is 0x%04x (%d bytes). ", - (u16)checksum, length); - list_fcode_ranges( TRUE); - } + if (fcode_start_ob_off != -1) { + u32 checksum; + int length; + + u8 *fcode_body = ostart + fcode_body_ob_off; + u8 *ob_end = ostart + opc; + fcode_header_t *fcode_hdr = + (fcode_header_t *) (ostart + fcode_hdr_ob_off); + + length = opc - fcode_start_ob_off; + + for (checksum = 0; + fcode_body < ob_end; checksum += *(fcode_body++)) ; + + if (sun_style_checksum) { + /* SUN OPB on the SPARC (Enterprise) platforms (especially): + * M3000, M4000, M9000 expects a checksum algorithm that is + * not compliant with IEEE 1275-1994 section 5.2.2.5. + */ + checksum = (checksum & 0xffff) + (checksum >> 16); + checksum = (checksum & 0xffff) + (checksum >> 16); + } + + BIG_ENDIAN_WORD_STORE(fcode_hdr->checksum, + (u16) (checksum & 0xffff)); + BIG_ENDIAN_LONG_STORE(fcode_hdr->length, length); + + if (verbose) { + printf("toke: checksum is 0x%04x (%d bytes). ", + (u16) checksum, length); + list_fcode_ranges(TRUE); + } } /* Reset things for the next image... */ fcode_start_ob_off = -1; - fcode_hdr_ob_off = -1; - fcode_body_ob_off = -1; - fcode_written = FALSE; - haveend=FALSE; + fcode_hdr_ob_off = -1; + fcode_body_ob_off = -1; + fcode_written = FALSE; + haveend = FALSE; } /* ************************************************************************** @@ -390,15 +378,15 @@ void finish_fcodehdr(void) static void emit_pci_rom_hdr(void) { - rom_header_t *pci_hdr; - pci_hdr_ob_off = opc; - pci_hdr = (rom_header_t *)(ostart + pci_hdr_ob_off); + rom_header_t *pci_hdr; + pci_hdr_ob_off = opc; + pci_hdr = (rom_header_t *) (ostart + pci_hdr_ob_off); + + EMIT_STRUCT(rom_header_t); - EMIT_STRUCT(rom_header_t); - /* PCI start signature */ - LITTLE_ENDIAN_WORD_STORE(pci_hdr->signature,0xaa55); - + LITTLE_ENDIAN_WORD_STORE(pci_hdr->signature, 0xaa55); + /* Processor architecture */ /* Note: * The legacy code used to read: @@ -414,16 +402,16 @@ static void emit_pci_rom_hdr(void) * and that the following would be preferable: */ - LITTLE_ENDIAN_WORD_STORE( pci_hdr->reserved , - (sizeof(rom_header_t) + sizeof(pci_data_t)) ) ; + LITTLE_ENDIAN_WORD_STORE(pci_hdr->reserved, + (sizeof(rom_header_t) + sizeof(pci_data_t))); /* already handled padding */ /* pointer to start of PCI data structure */ - LITTLE_ENDIAN_WORD_STORE(pci_hdr->data_ptr, sizeof(rom_header_t) ); + LITTLE_ENDIAN_WORD_STORE(pci_hdr->data_ptr, sizeof(rom_header_t)); } - + /* ************************************************************************** * * Function name: emit_pci_data_block @@ -458,36 +446,36 @@ static void emit_pci_rom_hdr(void) static void emit_pci_data_block(void) { - pci_data_t *pci_data_blk; - u32 class_id = dpop(); - u16 dev_id = dpop(); - u16 vend_id = dpop(); + pci_data_t *pci_data_blk; + u32 class_id = dpop(); + u16 dev_id = dpop(); + u16 vend_id = dpop(); - pci_data_blk_ob_off = opc; - pci_data_blk = (pci_data_t *)(ostart + pci_data_blk_ob_off); + pci_data_blk_ob_off = opc; + pci_data_blk = (pci_data_t *) (ostart + pci_data_blk_ob_off); - EMIT_STRUCT(pci_data_t); + EMIT_STRUCT(pci_data_t); - BIG_ENDIAN_LONG_STORE(pci_data_blk->signature , PCI_DATA_HDR ); + BIG_ENDIAN_LONG_STORE(pci_data_blk->signature, PCI_DATA_HDR); - LITTLE_ENDIAN_WORD_STORE(pci_data_blk->vendor , vend_id ); - LITTLE_ENDIAN_WORD_STORE(pci_data_blk->device , dev_id ); - LITTLE_ENDIAN_TRIPLET_STORE(pci_data_blk->class_code , class_id ); + LITTLE_ENDIAN_WORD_STORE(pci_data_blk->vendor, vend_id); + LITTLE_ENDIAN_WORD_STORE(pci_data_blk->device, dev_id); + LITTLE_ENDIAN_TRIPLET_STORE(pci_data_blk->class_code, class_id); - LITTLE_ENDIAN_WORD_STORE(pci_data_blk->dlen , sizeof(pci_data_t) ); + LITTLE_ENDIAN_WORD_STORE(pci_data_blk->dlen, sizeof(pci_data_t)); - pci_data_blk->drevision = PCI_DATA_STRUCT_REV ; + pci_data_blk->drevision = PCI_DATA_STRUCT_REV; /* code type = open firmware = 1 */ - pci_data_blk->code_type = 1; + pci_data_blk->code_type = 1; /* last image flag */ - pci_data_blk->last_image_flag = pci_is_last_image ? 0x80 : 0 ; + pci_data_blk->last_image_flag = pci_is_last_image ? 0x80 : 0; - tokenization_error(INFO , - "PCI header vendor id=0x%04x, " - "device id=0x%04x, class=%06x\n", - vend_id, dev_id, class_id ); + tokenization_error(INFO, + "PCI header vendor id=0x%04x, " + "device id=0x%04x, class=%06x\n", + vend_id, dev_id, class_id); } @@ -525,17 +513,16 @@ static void emit_pci_data_block(void) void emit_pcihdr(void) { - /* Check for error conditions */ - if ( - /* FCODE-START has already been issued */ - ( fcode_start_ob_off != -1 ) - /* Other FCode has been written */ - || fcode_written - ) - { - tokenization_error( TKERROR , - "Cannot create PCI header after FCode output has begun.\n"); - if ( ! noerrors ) return ; + /* Check for error conditions */ + if ( + /* FCODE-START has already been issued */ + (fcode_start_ob_off != -1) + /* Other FCode has been written */ + || fcode_written) { + tokenization_error(TKERROR, + "Cannot create PCI header after FCode output has begun.\n"); + if (!noerrors) + return; } emit_pci_rom_hdr(); @@ -556,62 +543,59 @@ void emit_pcihdr(void) void finish_pcihdr(void) { - u32 imagesize ; + u32 imagesize; u32 imageblocks; int padding; - + rom_header_t *pci_hdr; - pci_data_t *pci_data_blk; + pci_data_t *pci_data_blk; - if( pci_data_blk_ob_off == -1 ) - { - tokenization_error( TKERROR, - "%s without PCI-HEADER\n", strupr(statbuf) ); - return ; + if (pci_data_blk_ob_off == -1) { + tokenization_error(TKERROR, + "%s without PCI-HEADER\n", strupr(statbuf)); + return; } - pci_hdr = (rom_header_t *)(ostart + pci_hdr_ob_off); - pci_data_blk = (pci_data_t *)(ostart + pci_data_blk_ob_off); + pci_hdr = (rom_header_t *) (ostart + pci_hdr_ob_off); + pci_data_blk = (pci_data_t *) (ostart + pci_data_blk_ob_off); /* fix up vpd */ LITTLE_ENDIAN_WORD_STORE(pci_data_blk->vpd, pci_vpd); /* Calculate image size and padding */ - imagesize = opc - pci_hdr_ob_off; /* Padding includes PCI hdr */ - imageblocks = (imagesize + 511) >> 9; /* Size in 512-byte blocks */ + imagesize = opc - pci_hdr_ob_off; /* Padding includes PCI hdr */ + imageblocks = (imagesize + 511) >> 9; /* Size in 512-byte blocks */ padding = (imageblocks << 9) - imagesize; /* fix up image size. */ LITTLE_ENDIAN_WORD_STORE(pci_data_blk->ilen, imageblocks); - + /* fix up revision */ - if ( big_end_pci_image_rev ) - { - BIG_ENDIAN_WORD_STORE(pci_data_blk->irevision, pci_image_rev); - }else{ - LITTLE_ENDIAN_WORD_STORE(pci_data_blk->irevision, pci_image_rev); + if (big_end_pci_image_rev) { + BIG_ENDIAN_WORD_STORE(pci_data_blk->irevision, pci_image_rev); + } else { + LITTLE_ENDIAN_WORD_STORE(pci_data_blk->irevision, + pci_image_rev); } - + /* fix up last image flag */ - pci_data_blk->last_image_flag = pci_is_last_image ? 0x80 : 0 ; - + pci_data_blk->last_image_flag = pci_is_last_image ? 0x80 : 0; + /* align to 512bytes */ - - printf("Adding %d bytes of zero padding to PCI image.\n",padding); + + printf("Adding %d bytes of zero padding to PCI image.\n", padding); while (padding--) emit_byte(0); - if ( ! pci_is_last_image ) - { - printf("Note: PCI header is not last image.\n"); + if (!pci_is_last_image) { + printf("Note: PCI header is not last image.\n"); } printf("\n"); - - pci_hdr_ob_off = -1; + + pci_hdr_ob_off = -1; pci_data_blk_ob_off = -1; - pci_hdr_end_ob_off = 0; + pci_hdr_end_ob_off = 0; } - /* ************************************************************************** * * Function name: finish_headers @@ -622,7 +606,8 @@ void finish_pcihdr(void) void finish_headers(void) { - if (fcode_hdr_ob_off != -1) finish_fcodehdr(); - if (pci_hdr_ob_off != -1) finish_pcihdr(); + if (fcode_hdr_ob_off != -1) + finish_fcodehdr(); + if (pci_hdr_ob_off != -1) + finish_pcihdr(); } - diff --git a/toke/emit.h b/toke/emit.h index f058d6e..7a02766 100644 --- a/toke/emit.h +++ b/toke/emit.h @@ -32,7 +32,7 @@ * (C) Copyright 2005 IBM Corporation. All Rights Reserved. * Modifications Author: David L. Paktor dlpaktor@us.ibm.com **************************************************************************** */ - + #include "types.h" /* ************************************************************************** @@ -51,12 +51,11 @@ **************************************************************************** */ typedef struct { - u8 format; - u8 checksum[2]; /* [0] = Hi byte, [1] = Lo */ - u8 length[4]; /* [0] = Hi, [1] = Hi-mid, [2] = Lo-mid, [3] = Lo */ + u8 format; + u8 checksum[2]; /* [0] = Hi byte, [1] = Lo */ + u8 length[4]; /* [0] = Hi, [1] = Hi-mid, [2] = Lo-mid, [3] = Lo */ } fcode_header_t; - /* ************************************************************************** * Macro Name: STRING_LEN_MAX * Max number of bytes allowable in an output string @@ -74,7 +73,6 @@ typedef struct { #define STRING_LEN_MAX 255 - /* ************************************************************************** * Macro Name: GET_BUF_MAX * Size alloted to input-string buffer @@ -93,7 +91,6 @@ typedef struct { #define GET_BUF_MAX 1024 - /* ************************************************************************** * * * Global Variables Exported @@ -109,17 +106,17 @@ extern unsigned int pci_hdr_end_ob_off; * **************************************************************************** */ -void emit_fcode(u16 tok); -void user_emit_byte(u8 data); +void emit_fcode(u16 tok); +void user_emit_byte(u8 data); -void emit_offset(s16 offs); -void emit_string(u8 *string, signed int cnt); -void emit_fcodehdr(const char *starter_name); -void finish_fcodehdr(void); -void emit_pcihdr(void); -void finish_pcihdr(void); +void emit_offset(s16 offs); +void emit_string(u8 * string, signed int cnt); +void emit_fcodehdr(const char *starter_name); +void finish_fcodehdr(void); +void emit_pcihdr(void); +void finish_pcihdr(void); void finish_headers(void); -void emit_end0(void); -void emit_literal(u32 num); +void emit_end0(void); +void emit_literal(u32 num); -#endif /* _TOKE_EMIT_H */ +#endif /* _TOKE_EMIT_H */ diff --git a/toke/errhandler.c b/toke/errhandler.c index 0ca9667..1a30f04 100644 --- a/toke/errhandler.c +++ b/toke/errhandler.c @@ -67,7 +67,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * We will define a set of bit-valued error-types and a @@ -163,19 +162,19 @@ * **************************************************************************** */ -static bool print_msg ; -static int errs_to_print = ( FATAL | TKERROR | WARNING | - MESSAGE | P_MESSAGE | TRACER | FORCE_MSG ) ; -static int err_types_found = 0 ; -static int err_count = 0 ; -static int warn_count = 0 ; -static int info_count = 0 ; -static int user_msg_count = 0 ; -static int trace_msg_count = 0 ; -static int fatal_err_exit = -1 ; -static FILE *message_dest; /* Would like to init to ERRMSG_DESTINATION - * here, but the compiler complains... - */ +static bool print_msg; +static int errs_to_print = (FATAL | TKERROR | WARNING | + MESSAGE | P_MESSAGE | TRACER | FORCE_MSG); +static int err_types_found = 0; +static int err_count = 0; +static int warn_count = 0; +static int info_count = 0; +static int user_msg_count = 0; +static int trace_msg_count = 0; +static int fatal_err_exit = -1; +static FILE *message_dest; /* Would like to init to ERRMSG_DESTINATION + * here, but the compiler complains... + */ /* ************************************************************************** * @@ -188,30 +187,29 @@ static FILE *message_dest; /* Would like to init to ERRMSG_DESTINATION **************************************************************************** */ typedef struct { - int type_bit ; /* Error-type single-bit code */ - char *category_name ; /* Printable-name base */ - char *single ; /* Suffix to print singular of name */ - char *plural ; /* Suffix to print plural of name */ - int *counter ; /* Associated Counter-variable */ - bool new_line ; /* Whether to print new-line at end */ -} err_category ; - -static const err_category error_categories[] = { - /* FATAL must be the first entry in the table. */ - /* No plural is needed; only one is allowed.... */ - { FATAL, "Fatal Error", "", "", &err_count , TRUE }, - - { TKERROR, "Error" , "", "s", &err_count , FALSE }, - { WARNING, "Warning" , "", "s", &warn_count , FALSE }, - { INFO, "Advisor" , "y", "ies", &info_count , FALSE }, - { MESSAGE , "Message" , "", "s", &user_msg_count , TRUE }, - { P_MESSAGE , "Message" , "", "s", &user_msg_count , FALSE }, - { TRACER , "Trace-Note" , "", "s", &trace_msg_count , FALSE } + int type_bit; /* Error-type single-bit code */ + char *category_name; /* Printable-name base */ + char *single; /* Suffix to print singular of name */ + char *plural; /* Suffix to print plural of name */ + int *counter; /* Associated Counter-variable */ + bool new_line; /* Whether to print new-line at end */ +} err_category; + +static const err_category error_categories[] = { + /* FATAL must be the first entry in the table. */ + /* No plural is needed; only one is allowed.... */ + { FATAL, "Fatal Error", "", "", &err_count, TRUE }, + + { TKERROR, "Error", "", "s", &err_count, FALSE }, + { WARNING, "Warning", "", "s", &warn_count, FALSE }, + { INFO, "Advisor", "y", "ies", &info_count, FALSE }, + { MESSAGE, "Message", "", "s", &user_msg_count, TRUE }, + { P_MESSAGE, "Message", "", "s", &user_msg_count, FALSE }, + { TRACER, "Trace-Note", "", "s", &trace_msg_count, FALSE } }; static const int num_categories = - ( sizeof(error_categories) / sizeof(err_category) ); - + (sizeof(error_categories) / sizeof(err_category)); /* ************************************************************************** * @@ -235,13 +233,12 @@ static const int num_categories = * **************************************************************************** */ -static void toup( char *chr_ptr) +static void toup(char *chr_ptr) { - const unsigned char upcas_diff = ( 'a' - 'A' ); - if ( ( *chr_ptr >= 'a' ) && ( *chr_ptr <= 'z' ) ) - { - *chr_ptr -= upcas_diff ; - } + const unsigned char upcas_diff = ('a' - 'A'); + if ((*chr_ptr >= 'a') && (*chr_ptr <= 'z')) { + *chr_ptr -= upcas_diff; + } } /* ************************************************************************** @@ -266,14 +263,13 @@ static void toup( char *chr_ptr) * **************************************************************************** */ -char *strupper( char *strung) +char *strupper(char *strung) { - char *strindx; - for (strindx = strung; *strindx != 0; strindx++) - { - toup( strindx); - } - return strung; + char *strindx; + for (strindx = strung; *strindx != 0; strindx++) { + toup(strindx); + } + return strung; } /* ************************************************************************** @@ -304,13 +300,12 @@ char *strupper( char *strung) * **************************************************************************** */ -static void tolow( char *chr_ptr) +static void tolow(char *chr_ptr) { - const unsigned char lowcas_diff = ( 'A' - 'a' ); - if ( ( *chr_ptr >= 'A' ) && ( *chr_ptr <= 'Z' ) ) - { - *chr_ptr -= lowcas_diff ; - } + const unsigned char lowcas_diff = ('A' - 'a'); + if ((*chr_ptr >= 'A') && (*chr_ptr <= 'Z')) { + *chr_ptr -= lowcas_diff; + } } /* ************************************************************************** @@ -335,17 +330,15 @@ static void tolow( char *chr_ptr) * **************************************************************************** */ -char *strlower( char *strung) +char *strlower(char *strung) { - char *strindx; - for (strindx = strung; *strindx != 0; strindx++) - { - tolow( strindx); - } - return strung; + char *strindx; + for (strindx = strung; *strindx != 0; strindx++) { + tolow(strindx); + } + return strung; } - /* ************************************************************************** * * Function name: init_error_handler @@ -386,22 +379,21 @@ char *strlower( char *strung) * **************************************************************************** */ -void init_error_handler( void) +void init_error_handler(void) { - int indx ; + int indx; - message_dest = ERRMSG_DESTINATION; - if ( verbose ) errs_to_print |= INFO ; - err_types_found = 0 ; + message_dest = ERRMSG_DESTINATION; + if (verbose) + errs_to_print |= INFO; + err_types_found = 0; - /* Start at indx = 1 to skip resetting FATALs */ - for ( indx = 1; indx < num_categories ; indx ++ ) - { - *(error_categories[indx].counter) = 0 ; - } + /* Start at indx = 1 to skip resetting FATALs */ + for (indx = 1; indx < num_categories; indx++) { + *(error_categories[indx].counter) = 0; + } - FFLUSH_STDOUT -} +FFLUSH_STDOUT} /* ************************************************************************** * @@ -479,83 +471,77 @@ void init_error_handler( void) * **************************************************************************** */ -void tokenization_error( int err_type, char* msg, ... ) +void tokenization_error(int err_type, char *msg, ...) { - int indx ; - - /* Initial settings: treat as an Error. */ - char *catgy_name = "Error"; - char *catgy_suffx = ""; - int *catgy_counter = &err_count; - bool print_new_line = FALSE; - - /* Accumulated the Error-type into err_types_found */ - err_types_found |= err_type; - - /* Identify the Error-Category. */ - for ( indx = 0 ; indx < num_categories ; indx ++ ) - { - if ( ( error_categories[indx].type_bit & err_type ) != 0 ) - { - catgy_name = error_categories[indx].category_name; - catgy_suffx = error_categories[indx].single; - catgy_counter = error_categories[indx].counter; - print_new_line = error_categories[indx].new_line; - break; - } - } - - /* Special message if err_type not in list; treat as an Error. */ - if ( catgy_name == NULL ) - { - fprintf(ERRMSG_DESTINATION, - "Program error: Unknown Error-Type, 0x%08x. " - " Will treat as Error.\n", err_type) ; - err_types_found |= TKERROR; - print_msg = TRUE ; - } else { - /* Check the Error-Type against the Error Verbosity Mask */ - print_msg = BOOLVAL( ( errs_to_print & err_type ) != 0 ); - } - - if ( print_msg ) - { - va_list argp; - - fprintf(ERRMSG_DESTINATION, "%s%s: ", - catgy_name, catgy_suffx); - if ( iname != NULL ) - { - /* Don't print iname or lineno if no file opened. */ - fprintf(ERRMSG_DESTINATION, "File %s, Line %d. ", - iname, lineno); - } - if ( opc > 0 ) - { - /* Don't print Output Position if no output started. */ - fprintf(ERRMSG_DESTINATION, "(Output Position = %d). ", opc); + int indx; + + /* Initial settings: treat as an Error. */ + char *catgy_name = "Error"; + char *catgy_suffx = ""; + int *catgy_counter = &err_count; + bool print_new_line = FALSE; + + /* Accumulated the Error-type into err_types_found */ + err_types_found |= err_type; + + /* Identify the Error-Category. */ + for (indx = 0; indx < num_categories; indx++) { + if ((error_categories[indx].type_bit & err_type) != 0) { + catgy_name = error_categories[indx].category_name; + catgy_suffx = error_categories[indx].single; + catgy_counter = error_categories[indx].counter; + print_new_line = error_categories[indx].new_line; + break; + } } - if ( pci_hdr_end_ob_off > 0 ) - { - /* Don't print PCI-Block Position if no PCI-Block in effect. */ - fprintf(ERRMSG_DESTINATION, "(PCI-Block Position = %d). ", - opc - pci_hdr_end_ob_off ); + + /* Special message if err_type not in list; treat as an Error. */ + if (catgy_name == NULL) { + fprintf(ERRMSG_DESTINATION, + "Program error: Unknown Error-Type, 0x%08x. " + " Will treat as Error.\n", err_type); + err_types_found |= TKERROR; + print_msg = TRUE; + } else { + /* Check the Error-Type against the Error Verbosity Mask */ + print_msg = BOOLVAL((errs_to_print & err_type) != 0); } - va_start(argp, msg); - vfprintf(ERRMSG_DESTINATION, msg, argp); - va_end(argp); - if ( print_new_line ) fprintf(ERRMSG_DESTINATION, "\n"); - - /* Increment the category-counter. */ - *catgy_counter += 1; - } - if ( err_type == FATAL ) - { - fprintf(ERRMSG_DESTINATION, "Tokenization terminating.\n"); - error_summary(); - exit ( fatal_err_exit ); - } + if (print_msg) { + va_list argp; + + fprintf(ERRMSG_DESTINATION, "%s%s: ", catgy_name, catgy_suffx); + if (iname != NULL) { + /* Don't print iname or lineno if no file opened. */ + fprintf(ERRMSG_DESTINATION, "File %s, Line %d. ", + iname, lineno); + } + if (opc > 0) { + /* Don't print Output Position if no output started. */ + fprintf(ERRMSG_DESTINATION, "(Output Position = %d). ", + opc); + } + if (pci_hdr_end_ob_off > 0) { + /* Don't print PCI-Block Position if no PCI-Block in effect. */ + fprintf(ERRMSG_DESTINATION, + "(PCI-Block Position = %d). ", + opc - pci_hdr_end_ob_off); + } + + va_start(argp, msg); + vfprintf(ERRMSG_DESTINATION, msg, argp); + va_end(argp); + if (print_new_line) + fprintf(ERRMSG_DESTINATION, "\n"); + + /* Increment the category-counter. */ + *catgy_counter += 1; + } + if (err_type == FATAL) { + fprintf(ERRMSG_DESTINATION, "Tokenization terminating.\n"); + error_summary(); + exit(fatal_err_exit); + } } /* ************************************************************************** @@ -625,46 +611,41 @@ void tokenization_error( int err_type, char* msg, ... ) * **************************************************************************** */ -static void print_where_started( bool show_started, - bool show_that_st, - char * saved_ifile, - unsigned int saved_lineno, - bool may_show_incolon) +static void print_where_started(bool show_started, + bool show_that_st, + char *saved_ifile, + unsigned int saved_lineno, + bool may_show_incolon) { - if ( print_msg ) - { - bool fil_is_diff; - bool lin_is_diff; - - /* File names are case-sensitive */ - fil_is_diff = BOOLVAL(strcmp(saved_ifile, iname) != 0 ); - lin_is_diff = BOOLVAL(saved_lineno != lineno ); - if ( fil_is_diff || lin_is_diff ) - { - if ( show_started ) - { - if ( show_that_st ) - { - fprintf(message_dest, " that"); - }else{ - fprintf(message_dest, " , which"); + if (print_msg) { + bool fil_is_diff; + bool lin_is_diff; + + /* File names are case-sensitive */ + fil_is_diff = BOOLVAL(strcmp(saved_ifile, iname) != 0); + lin_is_diff = BOOLVAL(saved_lineno != lineno); + if (fil_is_diff || lin_is_diff) { + if (show_started) { + if (show_that_st) { + fprintf(message_dest, " that"); + } else { + fprintf(message_dest, " , which"); + } + fprintf(message_dest, " started"); + } + fprintf(message_dest, " on line %d", saved_lineno); + if (fil_is_diff) { + fprintf(message_dest, " of file %s", + saved_ifile); + } } - fprintf(message_dest, " started"); - } - fprintf(message_dest, " on line %d", saved_lineno); - if ( fil_is_diff ) - { - fprintf(message_dest, " of file %s", saved_ifile); - } - } - if ( may_show_incolon ) - { - in_last_colon( TRUE ); - }else{ - fprintf(message_dest, "\n"); + if (may_show_incolon) { + in_last_colon(TRUE); + } else { + fprintf(message_dest, "\n"); + } } - } } /* ************************************************************************** @@ -691,12 +672,11 @@ static void print_where_started( bool show_started, * **************************************************************************** */ -void started_at( char * saved_ifile, unsigned int saved_lineno) +void started_at(char *saved_ifile, unsigned int saved_lineno) { - print_where_started( TRUE, TRUE, saved_ifile, saved_lineno, TRUE); + print_where_started(TRUE, TRUE, saved_ifile, saved_lineno, TRUE); } - /* ************************************************************************** * * Function name: print_started_at @@ -707,15 +687,14 @@ void started_at( char * saved_ifile, unsigned int saved_lineno) * A retrofit. Can you tell? * **************************************************************************** */ - -void print_started_at( char * saved_ifile, unsigned int saved_lineno) + +void print_started_at(char *saved_ifile, unsigned int saved_lineno) { - message_dest = stdout; - started_at( saved_ifile, saved_lineno); - message_dest = ERRMSG_DESTINATION; + message_dest = stdout; + started_at(saved_ifile, saved_lineno); + message_dest = ERRMSG_DESTINATION; } - /* ************************************************************************** * * Function name: just_started_at @@ -739,9 +718,9 @@ void print_started_at( char * saved_ifile, unsigned int saved_lineno) * **************************************************************************** */ -void just_started_at( char * saved_ifile, unsigned int saved_lineno) +void just_started_at(char *saved_ifile, unsigned int saved_lineno) { - print_where_started( TRUE, TRUE, saved_ifile, saved_lineno, FALSE); + print_where_started(TRUE, TRUE, saved_ifile, saved_lineno, FALSE); } /* ************************************************************************** @@ -767,9 +746,9 @@ void just_started_at( char * saved_ifile, unsigned int saved_lineno) * **************************************************************************** */ -void where_started( char * saved_ifile, unsigned int saved_lineno) +void where_started(char *saved_ifile, unsigned int saved_lineno) { - print_where_started( FALSE, FALSE, saved_ifile, saved_lineno, TRUE); + print_where_started(FALSE, FALSE, saved_ifile, saved_lineno, TRUE); } /* ************************************************************************** @@ -794,9 +773,9 @@ void where_started( char * saved_ifile, unsigned int saved_lineno) * **************************************************************************** */ -void just_where_started( char * saved_ifile, unsigned int saved_lineno) +void just_where_started(char *saved_ifile, unsigned int saved_lineno) { - print_where_started( FALSE, FALSE, saved_ifile, saved_lineno, FALSE); + print_where_started(FALSE, FALSE, saved_ifile, saved_lineno, FALSE); } /* ************************************************************************** @@ -836,23 +815,21 @@ void just_where_started( char * saved_ifile, unsigned int saved_lineno) * **************************************************************************** */ -void in_last_colon( bool say_in ) +void in_last_colon(bool say_in) { - if ( print_msg ) - { - if ( incolon || ( ! say_in ) ) - { - fprintf( message_dest, "%s definition of %s ", say_in ? " in" : "", - strupr( last_colon_defname) ); - print_where_started( TRUE, FALSE, - last_colon_filename, last_colon_lineno, FALSE); - }else{ - fprintf(message_dest, "\n"); + if (print_msg) { + if (incolon || (!say_in)) { + fprintf(message_dest, "%s definition of %s ", + say_in ? " in" : "", + strupr(last_colon_defname)); + print_where_started(TRUE, FALSE, last_colon_filename, + last_colon_lineno, FALSE); + } else { + fprintf(message_dest, "\n"); + } } - } } - /* ************************************************************************** * * Function name: safe_malloc @@ -882,16 +859,15 @@ void in_last_colon( bool say_in ) * **************************************************************************** */ -_PTR safe_malloc( size_t size, char *phrase) +_PTR safe_malloc(size_t size, char *phrase) { - _PTR retval ; - retval = malloc (size); - if ( !retval ) - { - fatal_err_exit = -ENOMEM ; - tokenization_error( FATAL, "Out of memory while %s.", phrase); - } - return ( retval ); + _PTR retval; + retval = malloc(size); + if (!retval) { + fatal_err_exit = -ENOMEM; + tokenization_error(FATAL, "Out of memory while %s.", phrase); + } + return (retval); } /* ************************************************************************** @@ -923,79 +899,73 @@ _PTR safe_malloc( size_t size, char *phrase) * **************************************************************************** */ -bool error_summary( void ) +bool error_summary(void) { - /* Bit-mask of error-types that require suppressing output */ - static const int suppress_mask = ( FATAL | TKERROR ); - bool retval = TRUE; - bool suppressing = FALSE; - - /* There's no escaping a FATAL error */ - if ( ( err_types_found & FATAL ) != 0 ) - { - /* FATAL error. Don't even bother with the tally. */ - suppressing = TRUE; - } else { - - if ( opc == 0 ) - { - printf ( "Nothing Tokenized"); - }else{ - printf ( "Tokenization Completed"); - } + /* Bit-mask of error-types that require suppressing output */ + static const int suppress_mask = (FATAL | TKERROR); + bool retval = TRUE; + bool suppressing = FALSE; + + /* There's no escaping a FATAL error */ + if ((err_types_found & FATAL) != 0) { + /* FATAL error. Don't even bother with the tally. */ + suppressing = TRUE; + } else { - if ( err_types_found != 0 ) - { - int indx; - bool tally_started = FALSE ; - printf (". "); - /* - * Print a tally of the error-types; - * handle plurals and punctuation appropriately. - */ - /* Start at indx = 1 to skip examining FATALs */ - for ( indx = 1; indx < num_categories ; indx ++ ) - { - if ( *(error_categories[indx].counter) > 0 ) - { - printf ("%s %d %s%s", - tally_started ? "," : "" , - *(error_categories[indx].counter), - error_categories[indx].category_name, - *(error_categories[indx].counter) > 1 ? - error_categories[indx].plural : - error_categories[indx].single ); - /* Zero out the counter, to prevent displaying the - * number of Messages twice, since it's shared - * by the "Messages" and "P_Messages" categories. - */ - *(error_categories[indx].counter) = 0; - tally_started = TRUE; + if (opc == 0) { + printf("Nothing Tokenized"); + } else { + printf("Tokenization Completed"); } - } - } - printf (".\n"); - if ( ( err_types_found & suppress_mask ) != 0 ) - { /* Errors found. Not OK to produce output */ - /* Unless "Ignore Errors" flag set... */ - if ( INVERSE(noerrors) ) - { - suppressing = TRUE; - }else{ - if ( opc > 0 ) - { - printf ("Error-detection over-ridden; " - "producing binary output.\n"); + if (err_types_found != 0) { + int indx; + bool tally_started = FALSE; + printf(". "); + /* + * Print a tally of the error-types; + * handle plurals and punctuation appropriately. + */ + /* Start at indx = 1 to skip examining FATALs */ + for (indx = 1; indx < num_categories; indx++) { + if (*(error_categories[indx].counter) > 0) { + printf("%s %d %s%s", + tally_started ? "," : "", + *(error_categories[indx]. + counter), + error_categories[indx]. + category_name, + *(error_categories[indx]. + counter) > + 1 ? error_categories[indx]. + plural : error_categories[indx]. + single); + /* Zero out the counter, to prevent displaying the + * number of Messages twice, since it's shared + * by the "Messages" and "P_Messages" categories. + */ + *(error_categories[indx].counter) = 0; + tally_started = TRUE; + } + } + } + printf(".\n"); + + if ((err_types_found & suppress_mask) != 0) { /* Errors found. Not OK to produce output */ + /* Unless "Ignore Errors" flag set... */ + if (INVERSE(noerrors)) { + suppressing = TRUE; + } else { + if (opc > 0) { + printf("Error-detection over-ridden; " + "producing binary output.\n"); + } + } } - } } - } - if ( suppressing ) - { - retval = FALSE ; - printf ("Suppressing binary output.\n"); - } - return ( retval ); + if (suppressing) { + retval = FALSE; + printf("Suppressing binary output.\n"); + } + return (retval); } - diff --git a/toke/errhandler.h b/toke/errhandler.h index c204510..5c3253f 100644 --- a/toke/errhandler.h +++ b/toke/errhandler.h @@ -49,17 +49,16 @@ #define P_MESSAGE 0x00000040 #define FORCE_MSG 0x00000001 -void init_error_handler( void); -void tokenization_error( int err_type, char* msg, ... ); -void started_at( char * saved_ifile, unsigned int saved_lineno); -void print_started_at( char * saved_ifile, unsigned int saved_lineno); -void just_started_at( char * saved_ifile, unsigned int saved_lineno); -void where_started( char * saved_ifile, unsigned int saved_lineno); -void just_where_started( char * saved_ifile, unsigned int saved_lineno); -void in_last_colon( bool say_in ); -_PTR safe_malloc( size_t size, char *phrase); -bool error_summary( void ); /* Return TRUE if OK to produce output. */ - +void init_error_handler(void); +void tokenization_error(int err_type, char *msg, ...); +void started_at(char *saved_ifile, unsigned int saved_lineno); +void print_started_at(char *saved_ifile, unsigned int saved_lineno); +void just_started_at(char *saved_ifile, unsigned int saved_lineno); +void where_started(char *saved_ifile, unsigned int saved_lineno); +void just_where_started(char *saved_ifile, unsigned int saved_lineno); +void in_last_colon(bool say_in); +_PTR safe_malloc(size_t size, char *phrase); +bool error_summary(void); /* Return TRUE if OK to produce output. */ /* ************************************************************************** * @@ -83,12 +82,11 @@ bool error_summary( void ); /* Return TRUE if OK to produce output. */ /* We're no longer switching the above. * The below is left here to show what had been done formerly. */ -#if -1 /* Switchable error-message destination */ -#else /* Switchable error-message destination */ +#if -1 /* Switchable error-message destination */ +#else /* Switchable error-message destination */ #define ERRMSG_DESTINATION stdout -#define FFLUSH_STDOUT /* Don't need to do anything here */ -#endif /* Switchable error-message destination */ - +#define FFLUSH_STDOUT /* Don't need to do anything here */ +#endif /* Switchable error-message destination */ /* ************************************************************************** * @@ -98,11 +96,10 @@ bool error_summary( void ); /* Return TRUE if OK to produce output. */ * **************************************************************************** */ -extern char *strupper( char *strung); +extern char *strupper(char *strung); #define strupr strupper -extern char *strlower( char *strung); +extern char *strlower(char *strung); #define strlwr strlower - -#endif /* _TOKE_ERRHANDLER_H */ +#endif /* _TOKE_ERRHANDLER_H */ diff --git a/toke/flowcontrol.c b/toke/flowcontrol.c index 42fdc28..838c06b 100644 --- a/toke/flowcontrol.c +++ b/toke/flowcontrol.c @@ -132,7 +132,6 @@ int control_stack_depth = 0; - /* ************************************************************************** * * Internal Static Functions: @@ -175,15 +174,14 @@ int control_stack_depth = 0; * and constructed with a hint of mnemonic value in mind. * **************************************************************************** */ - /* Mnemonic: */ -#define BEGIN_CSTAG 0xC57be916 /* CST BEGIN */ -#define IF_CSTAG 0xC57A901f /* CSTAG (0) IF */ -#define WHILE_CSTAG 0xC573412e /* CST WHILE */ -#define DO_CSTAG 0xC57A90d0 /* CSTAG (0) DO */ -#define CASE_CSTAG 0xC57Aca5e /* CSTA CASE */ -#define OF_CSTAG 0xC57A90f0 /* CSTAG OF (0) */ -#define ENDOF_CSTAG 0xC57e6d0f /* CST ENDOF */ - + /* Mnemonic: */ +#define BEGIN_CSTAG 0xC57be916 /* CST BEGIN */ +#define IF_CSTAG 0xC57A901f /* CSTAG (0) IF */ +#define WHILE_CSTAG 0xC573412e /* CST WHILE */ +#define DO_CSTAG 0xC57A90d0 /* CSTAG (0) DO */ +#define CASE_CSTAG 0xC57Aca5e /* CSTA CASE */ +#define OF_CSTAG 0xC57A90f0 /* CSTAG OF (0) */ +#define ENDOF_CSTAG 0xC57e6d0f /* CST ENDOF */ /* ************************************************************************** * @@ -284,14 +282,14 @@ int control_stack_depth = 0; **************************************************************************** */ typedef struct cstag_group { - unsigned long cs_tag; - char *cs_inp_fil; - unsigned int cs_line_num; - unsigned int cs_abs_token_num; - char *cs_word; - bool cs_not_dup; - unsigned long cs_datum; - struct cstag_group *prev; + unsigned long cs_tag; + char *cs_inp_fil; + unsigned int cs_line_num; + unsigned int cs_abs_token_num; + char *cs_word; + bool cs_not_dup; + unsigned long cs_datum; + struct cstag_group *prev; } cstag_group_t; /* ************************************************************************** @@ -305,7 +303,7 @@ typedef struct cstag_group { * **************************************************************************** */ -static cstag_group_t *control_stack = NULL; /* "Top" of the "Stack" */ +static cstag_group_t *control_stack = NULL; /* "Top" of the "Stack" */ /* ************************************************************************** * @@ -318,7 +316,7 @@ static cstag_group_t *control_stack = NULL; /* "Top" of the "Stack" */ * **************************************************************************** */ -static bool not_cs_underflow; /* No need to initialize. */ +static bool not_cs_underflow; /* No need to initialize. */ /* ************************************************************************** * @@ -340,7 +338,6 @@ static bool not_cs_underflow; /* No need to initialize. */ static bool not_consuming_two = TRUE; static bool didnt_print_otl = TRUE; - /* ************************************************************************** * * Function name: push_cstag @@ -376,24 +373,24 @@ static bool didnt_print_otl = TRUE; * **************************************************************************** */ -static void push_cstag( unsigned long cstag, unsigned long datum) +static void push_cstag(unsigned long cstag, unsigned long datum) { - cstag_group_t *cs_temp; - - cs_temp = control_stack; - control_stack = safe_malloc( sizeof(cstag_group_t), "pushing CSTag"); - - control_stack->cs_tag = cstag; - control_stack->cs_inp_fil = strdup(iname); - control_stack->cs_line_num = lineno; - control_stack->cs_abs_token_num = abs_token_no; - control_stack->cs_word = strdup(statbuf); - control_stack->cs_not_dup = TRUE; - control_stack->cs_datum = datum; - control_stack->prev = cs_temp; - - control_stack_depth++; - + cstag_group_t *cs_temp; + + cs_temp = control_stack; + control_stack = safe_malloc(sizeof(cstag_group_t), "pushing CSTag"); + + control_stack->cs_tag = cstag; + control_stack->cs_inp_fil = strdup(iname); + control_stack->cs_line_num = lineno; + control_stack->cs_abs_token_num = abs_token_no; + control_stack->cs_word = strdup(statbuf); + control_stack->cs_not_dup = TRUE; + control_stack->cs_datum = datum; + control_stack->prev = cs_temp; + + control_stack_depth++; + } /* ************************************************************************** @@ -426,21 +423,20 @@ static void push_cstag( unsigned long cstag, unsigned long datum) * **************************************************************************** */ -static void pop_cstag( void) +static void pop_cstag(void) { - if ( control_stack != NULL ) - { - cstag_group_t *cs_temp; + if (control_stack != NULL) { + cstag_group_t *cs_temp; - cs_temp = control_stack->prev; - free( control_stack->cs_word ); - free( control_stack->cs_inp_fil ); - free( control_stack ); - control_stack = cs_temp; + cs_temp = control_stack->prev; + free(control_stack->cs_word); + free(control_stack->cs_inp_fil); + free(control_stack); + control_stack = cs_temp; - control_stack_depth--; - } + control_stack_depth--; + } } /* ************************************************************************** @@ -470,21 +466,21 @@ static void pop_cstag( void) * **************************************************************************** */ -static bool control_stack_size_test( int min_depth ) +static bool control_stack_size_test(int min_depth) { - bool retval = TRUE; + bool retval = TRUE; - if ( control_stack_depth < min_depth ) - { - retval = FALSE; - tokenization_error ( TKERROR, - "Control-Stack underflow at %s", strupr(statbuf) ); - in_last_colon( TRUE); + if (control_stack_depth < min_depth) { + retval = FALSE; + tokenization_error(TKERROR, + "Control-Stack underflow at %s", + strupr(statbuf)); + in_last_colon(TRUE); - not_cs_underflow = FALSE; /* See expl'n early on in this file */ - } + not_cs_underflow = FALSE; /* See expl'n early on in this file */ + } - return( retval ); + return (retval); } /* ************************************************************************** @@ -521,18 +517,18 @@ static bool control_stack_size_test( int min_depth ) * **************************************************************************** */ -static void control_structure_mismatch( void ) +static void control_structure_mismatch(void) { - if ( control_stack->cs_not_dup || not_consuming_two ) - { - tokenization_error ( TKERROR, - "The %s is mismatched with the %s" , - strupr(statbuf), strupr(control_stack->cs_word)); - where_started( control_stack->cs_inp_fil, control_stack->cs_line_num ); - } + if (control_stack->cs_not_dup || not_consuming_two) { + tokenization_error(TKERROR, + "The %s is mismatched with the %s", + strupr(statbuf), + strupr(control_stack->cs_word)); + where_started(control_stack->cs_inp_fil, + control_stack->cs_line_num); + } } - /* ************************************************************************** * * Function name: offset_too_large @@ -579,29 +575,28 @@ static void control_structure_mismatch( void ) * **************************************************************************** */ -static void offset_too_large( bool too_large_for_16 ) +static void offset_too_large(bool too_large_for_16) { - if ( control_stack->cs_not_dup || didnt_print_otl ) - { - tokenization_error( TKERROR, - "Branch offset is too large between %s and the %s" , - strupr(statbuf), strupr(control_stack->cs_word)); - where_started( control_stack->cs_inp_fil, control_stack->cs_line_num ); - if ( INVERSE( offs16 ) ) - { - if ( too_large_for_16 ) - { - tokenization_error ( INFO, - "Offset would be too large even if 16-bit offsets " - "were in effect.\n"); - }else{ - tokenization_error ( INFO, - "Offset might fit if 16-bit offsets " - "(e.g., fcode-version2) were used.\n" ); - } + if (control_stack->cs_not_dup || didnt_print_otl) { + tokenization_error(TKERROR, + "Branch offset is too large between %s and the %s", + strupr(statbuf), + strupr(control_stack->cs_word)); + where_started(control_stack->cs_inp_fil, + control_stack->cs_line_num); + if (INVERSE(offs16)) { + if (too_large_for_16) { + tokenization_error(INFO, + "Offset would be too large even if 16-bit offsets " + "were in effect.\n"); + } else { + tokenization_error(INFO, + "Offset might fit if 16-bit offsets " + "(e.g., fcode-version2) were used.\n"); + } + } } - } - didnt_print_otl = FALSE; + didnt_print_otl = FALSE; } /* ************************************************************************** @@ -638,30 +633,29 @@ static void offset_too_large( bool too_large_for_16 ) * **************************************************************************** */ -static void emit_fc_offset( int fc_offset) +static void emit_fc_offset(int fc_offset) { - int fc_offs_s16 = (s16)fc_offset; - int fc_offs_s8 = (s8)fc_offset; - bool too_large_for_8 = BOOLVAL( fc_offset != fc_offs_s8 ); - bool too_large_for_16 = BOOLVAL( fc_offset != fc_offs_s16); - - if ( too_large_for_16 || ( INVERSE(offs16) && too_large_for_8 ) ) - { - offset_too_large( too_large_for_16 ); - if ( noerrors ) - { - int coded_as = offs16 ? (int)fc_offs_s16 : (int)fc_offs_s8 ; - tokenization_error( WARNING, - "Actual offset is 0x%x (=dec %d), " - "but it will be coded as 0x%x (=dec %d).\n", - fc_offset, fc_offset, coded_as, coded_as ); + int fc_offs_s16 = (s16) fc_offset; + int fc_offs_s8 = (s8) fc_offset; + bool too_large_for_8 = BOOLVAL(fc_offset != fc_offs_s8); + bool too_large_for_16 = BOOLVAL(fc_offset != fc_offs_s16); + + if (too_large_for_16 || (INVERSE(offs16) && too_large_for_8)) { + offset_too_large(too_large_for_16); + if (noerrors) { + int coded_as = + offs16 ? (int)fc_offs_s16 : (int)fc_offs_s8; + tokenization_error(WARNING, + "Actual offset is 0x%x (=dec %d), " + "but it will be coded as 0x%x (=dec %d).\n", + fc_offset, fc_offset, coded_as, + coded_as); + } } - } - emit_offset( fc_offs_s16 ); + emit_offset(fc_offs_s16); } - /* ************************************************************************** * * Function name: matchup_control_structure @@ -723,29 +717,26 @@ static void emit_fc_offset( int fc_offset) * **************************************************************************** */ -static bool matchup_control_structure( unsigned long cstag ) +static bool matchup_control_structure(unsigned long cstag) { - bool retval = FALSE; + bool retval = FALSE; - if ( control_stack_size_test( 1) ) - { - retval = TRUE; + if (control_stack_size_test(1)) { + retval = TRUE; - if ( control_stack->cs_tag != cstag ) - { - control_structure_mismatch(); + if (control_stack->cs_tag != cstag) { + control_structure_mismatch(); - if ( ( INVERSE(noerrors) ) - || ( cstag == CASE_CSTAG ) - || ( control_stack->cs_tag == CASE_CSTAG ) - ) - { - retval = FALSE; - } - } + if ((INVERSE(noerrors)) + || (cstag == CASE_CSTAG) + || (control_stack->cs_tag == CASE_CSTAG) + ) { + retval = FALSE; + } + } - } - return ( retval ); + } + return (retval); } /* ************************************************************************** @@ -793,18 +784,17 @@ static bool matchup_control_structure( unsigned long cstag ) * **************************************************************************** */ -static void control_structure_swap( void ) +static void control_structure_swap(void) { - if ( control_stack_size_test( 2) ) - { - cstag_group_t *cs_temp; + if (control_stack_size_test(2)) { + cstag_group_t *cs_temp; - cs_temp = control_stack->prev; + cs_temp = control_stack->prev; - control_stack->prev = cs_temp->prev; - cs_temp->prev = control_stack; - control_stack = cs_temp; - } + control_stack->prev = cs_temp->prev; + cs_temp->prev = control_stack; + control_stack = cs_temp; + } } /* ************************************************************************** @@ -851,39 +841,36 @@ static void control_structure_swap( void ) * **************************************************************************** */ -static bool matchup_two_control_structures( unsigned long top_cstag, - unsigned long next_cstag) +static bool matchup_two_control_structures(unsigned long top_cstag, + unsigned long next_cstag) { - bool retval; - bool topmatch; - bool nextmatch = FALSE; - bool sav_noerrors = noerrors; - noerrors = FALSE; - not_consuming_two = FALSE; - - not_cs_underflow = TRUE; - topmatch = matchup_control_structure( top_cstag); - if ( not_cs_underflow ) - { - control_structure_swap(); - if ( not_cs_underflow ) - { - nextmatch = matchup_control_structure( next_cstag); - control_structure_swap(); + bool retval; + bool topmatch; + bool nextmatch = FALSE; + bool sav_noerrors = noerrors; + noerrors = FALSE; + not_consuming_two = FALSE; + + not_cs_underflow = TRUE; + topmatch = matchup_control_structure(top_cstag); + if (not_cs_underflow) { + control_structure_swap(); + if (not_cs_underflow) { + nextmatch = matchup_control_structure(next_cstag); + control_structure_swap(); + } } - } - retval = BOOLVAL( topmatch && nextmatch); + retval = BOOLVAL(topmatch && nextmatch); - if ( INVERSE( retval) ) - { - pop_cstag(); - pop_cstag(); - } + if (INVERSE(retval)) { + pop_cstag(); + pop_cstag(); + } - not_consuming_two = TRUE; - noerrors = sav_noerrors; - return ( retval ); + not_consuming_two = TRUE; + noerrors = sav_noerrors; + return (retval); } /* ************************************************************************** @@ -917,9 +904,9 @@ static bool matchup_two_control_structures( unsigned long top_cstag, * **************************************************************************** */ -static void mark_backward_target(unsigned long cstag ) +static void mark_backward_target(unsigned long cstag) { - push_cstag( cstag, (unsigned long)opc); + push_cstag(cstag, (unsigned long)opc); } /* ************************************************************************** @@ -961,10 +948,10 @@ static void mark_backward_target(unsigned long cstag ) * **************************************************************************** */ -static void mark_forward_branch(unsigned long cstag ) +static void mark_forward_branch(unsigned long cstag) { - mark_backward_target(cstag ); - emit_offset(0); + mark_backward_target(cstag); + emit_offset(0); } /* ************************************************************************** @@ -1015,19 +1002,18 @@ static void mark_forward_branch(unsigned long cstag ) * **************************************************************************** */ -static void resolve_backward( unsigned long cstag) +static void resolve_backward(unsigned long cstag) { - unsigned long targ_opc; - int fc_offset = 0; + unsigned long targ_opc; + int fc_offset = 0; - if ( matchup_control_structure( cstag) ) - { - targ_opc = control_stack->cs_datum; - fc_offset = targ_opc - opc; - } + if (matchup_control_structure(cstag)) { + targ_opc = control_stack->cs_datum; + fc_offset = targ_opc - opc; + } - emit_fc_offset( fc_offset ); - pop_cstag(); + emit_fc_offset(fc_offset); + pop_cstag(); } /* ************************************************************************** @@ -1086,36 +1072,33 @@ static void resolve_backward( unsigned long cstag) * **************************************************************************** */ -static void resolve_forward( unsigned long cstag) +static void resolve_forward(unsigned long cstag) { - unsigned long resvd_opc; - bool sav_noerrors = noerrors; - bool cs_match_result; - noerrors = FALSE; - /* Restore the "ignore-errors" flag before we act on our match result - * because we want it to remain in effect for emit_fc_offset() - */ - cs_match_result = matchup_control_structure( cstag); - noerrors = sav_noerrors; - - if ( cs_match_result ) - { - int saved_opc; - int fc_offset; - - resvd_opc = control_stack->cs_datum; - fc_offset = opc - resvd_opc; - - saved_opc = opc; - opc = resvd_opc; - - - emit_fc_offset( fc_offset ); - opc = saved_opc; - } - pop_cstag(); + unsigned long resvd_opc; + bool sav_noerrors = noerrors; + bool cs_match_result; + noerrors = FALSE; + /* Restore the "ignore-errors" flag before we act on our match result + * because we want it to remain in effect for emit_fc_offset() + */ + cs_match_result = matchup_control_structure(cstag); + noerrors = sav_noerrors; + + if (cs_match_result) { + int saved_opc; + int fc_offset; + + resvd_opc = control_stack->cs_datum; + fc_offset = opc - resvd_opc; + + saved_opc = opc; + opc = resvd_opc; + + emit_fc_offset(fc_offset); + opc = saved_opc; + } + pop_cstag(); } - /* ************************************************************************** * @@ -1130,7 +1113,6 @@ static void resolve_forward( unsigned long cstag) * **************************************************************************** */ - /* ************************************************************************** * * Function name: emit_if @@ -1152,10 +1134,10 @@ static void resolve_forward( unsigned long cstag) * **************************************************************************** */ -void emit_if( void ) +void emit_if(void) { - emit_token("b?branch"); - mark_forward_branch( IF_CSTAG ); + emit_token("b?branch"); + mark_forward_branch(IF_CSTAG); } /* ************************************************************************** @@ -1193,20 +1175,17 @@ void emit_if( void ) * **************************************************************************** */ -void emit_then( void ) +void emit_then(void) { - emit_token("b(>resolve)"); - if ( control_stack != NULL ) - { - if ( control_stack->cs_tag == WHILE_CSTAG ) - { - control_stack->cs_tag = IF_CSTAG; + emit_token("b(>resolve)"); + if (control_stack != NULL) { + if (control_stack->cs_tag == WHILE_CSTAG) { + control_stack->cs_tag = IF_CSTAG; + } } - } - resolve_forward( IF_CSTAG ); + resolve_forward(IF_CSTAG); } - /* ************************************************************************** * * Function name: emit_else @@ -1255,22 +1234,19 @@ void emit_then( void ) * **************************************************************************** */ -void emit_else( void ) +void emit_else(void) { - if ( control_stack_depth > 0 ) - { - emit_token("bbranch"); - mark_forward_branch( IF_CSTAG ); - } - not_cs_underflow = TRUE; - control_structure_swap(); - if ( not_cs_underflow ) - { - emit_then(); - } + if (control_stack_depth > 0) { + emit_token("bbranch"); + mark_forward_branch(IF_CSTAG); + } + not_cs_underflow = TRUE; + control_structure_swap(); + if (not_cs_underflow) { + emit_then(); + } } - /* ************************************************************************** * * Function name: emit_begin @@ -1291,13 +1267,12 @@ void emit_else( void ) * **************************************************************************** */ -void emit_begin( void ) +void emit_begin(void) { - emit_token("b( 0 ) - { - emit_token("b?branch"); - mark_forward_branch( WHILE_CSTAG ); - } - control_structure_swap(); + if (control_stack_depth > 0) { + emit_token("b?branch"); + mark_forward_branch(WHILE_CSTAG); + } + control_structure_swap(); } /* ************************************************************************** @@ -1449,20 +1423,18 @@ void emit_while( void ) * **************************************************************************** */ -void emit_repeat( void ) +void emit_repeat(void) { - if ( matchup_two_control_structures( BEGIN_CSTAG, WHILE_CSTAG ) ) - { - not_cs_underflow = TRUE; - not_consuming_two = FALSE; - emit_again(); - if ( not_cs_underflow ) - { - emit_token("b(>resolve)"); - resolve_forward( WHILE_CSTAG ); + if (matchup_two_control_structures(BEGIN_CSTAG, WHILE_CSTAG)) { + not_cs_underflow = TRUE; + not_consuming_two = FALSE; + emit_again(); + if (not_cs_underflow) { + emit_token("b(>resolve)"); + resolve_forward(WHILE_CSTAG); + } + not_consuming_two = TRUE; } - not_consuming_two = TRUE; - } } /* ************************************************************************** @@ -1515,15 +1487,14 @@ void emit_repeat( void ) * **************************************************************************** */ -void mark_do( void ) +void mark_do(void) { - mark_forward_branch( DO_CSTAG); - control_stack->cs_not_dup = FALSE; - mark_backward_target( DO_CSTAG); - do_loop_depth++; + mark_forward_branch(DO_CSTAG); + control_stack->cs_not_dup = FALSE; + mark_backward_target(DO_CSTAG); + do_loop_depth++; } - /* ************************************************************************** * * Function name: resolve_loop @@ -1596,24 +1567,23 @@ void mark_do( void ) * **************************************************************************** */ -void resolve_loop( void ) +void resolve_loop(void) { - if ( INVERSE( matchup_two_control_structures( DO_CSTAG, DO_CSTAG) ) ) - { - emit_offset( 0 ); - }else{ - not_cs_underflow = TRUE; - didnt_print_otl = TRUE; - not_consuming_two = FALSE; - resolve_backward( DO_CSTAG); - if ( not_cs_underflow ) - { - resolve_forward( DO_CSTAG); + if (INVERSE(matchup_two_control_structures(DO_CSTAG, DO_CSTAG))) { + emit_offset(0); + } else { + not_cs_underflow = TRUE; + didnt_print_otl = TRUE; + not_consuming_two = FALSE; + resolve_backward(DO_CSTAG); + if (not_cs_underflow) { + resolve_forward(DO_CSTAG); + } + if (do_loop_depth > 0) + do_loop_depth--; + not_consuming_two = TRUE; + didnt_print_otl = TRUE; /* Might have gotten cleared */ } - if ( do_loop_depth > 0 ) do_loop_depth--; - not_consuming_two = TRUE; - didnt_print_otl = TRUE; /* Might have gotten cleared */ - } } /* ************************************************************************** @@ -1637,13 +1607,12 @@ void resolve_loop( void ) * **************************************************************************** */ -void emit_case( void ) +void emit_case(void) { - push_cstag( CASE_CSTAG, 0); - emit_token("b(case)"); + push_cstag(CASE_CSTAG, 0); + emit_token("b(case)"); } - /* ************************************************************************** * * Function name: emit_of @@ -1689,34 +1658,32 @@ void emit_case( void ) * **************************************************************************** */ -void emit_of( void ) +void emit_of(void) { - if ( matchup_control_structure( CASE_CSTAG ) ) - { - emit_token("b(of)"); + if (matchup_control_structure(CASE_CSTAG)) { + emit_token("b(of)"); - /* - * See comment-block about "Control-Stack" Diagram Notation - * early on in this file. - * - */ + /* + * See comment-block about "Control-Stack" Diagram Notation + * early on in this file. + * + */ - /* ( {Endof_FORw_ENDOF}1..n_ofs N_OFs...CASE_CSTAG -- ) */ + /* ( {Endof_FORw_ENDOF}1..n_ofs N_OFs...CASE_CSTAG -- ) */ - /* Increment the OF-count . */ - (control_stack->cs_datum)++; + /* Increment the OF-count . */ + (control_stack->cs_datum)++; - /* ( {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG -- ) */ + /* ( {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG -- ) */ - mark_forward_branch( OF_CSTAG ); - /* ( -- {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG Of_FORw_OF ) - */ - } - /* Leave the CSTAG-Group on the "Control-Stack" . */ + mark_forward_branch(OF_CSTAG); + /* ( -- {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG Of_FORw_OF ) + */ + } + /* Leave the CSTAG-Group on the "Control-Stack" . */ } - /* ************************************************************************** * * Function name: emit_endof @@ -1757,50 +1724,49 @@ void emit_of( void ) * **************************************************************************** */ -void emit_endof( void ) +void emit_endof(void) { - if ( control_stack_size_test( 2) ) - { - emit_token("b(endof)"); - - /* See "Control-Stack" Diagram Notation comment-block */ - - /* Stack-diagrams might need to be split across lines. */ - - /* ( {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG ... - * ... Of_FORw_OF -- ) - */ - mark_forward_branch(ENDOF_CSTAG); - /* ( -- {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG ... - * ... Of_FORw_OF {Endof_FORw_ENDOF}n_ofs+1 ) - */ - - control_structure_swap(); - /* ( -- {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG ... - * ... {Endof_FORw_ENDOF}n_ofs+1 Of_FORw_OF ) - */ - - resolve_forward( OF_CSTAG ); - /* ( -- {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG ... - * ... {Endof_FORw_ENDOF}n_ofs+1 ) - */ - - control_structure_swap(); - /* ( -- {Endof_FORw_ENDOF}1..n_ofs ... - * ... {Endof_FORw_ENDOF}n_ofs+1 ... - * ... N_OFs+1...CASE_CSTAG ) - */ - - /* The number of ENDOF-tagged Forward-Marker pairs has now - * caught up with the incremented OF-count; therefore, - * we can notate the above as: - * - * ( {Endof_FORw_ENDOF}1..n_ofs N_OFs CASE_CSTAG ) - * - * and we are ready for another OF ... ENDOF pair, - * or for the ENDCASE statement. - */ - } + if (control_stack_size_test(2)) { + emit_token("b(endof)"); + + /* See "Control-Stack" Diagram Notation comment-block */ + + /* Stack-diagrams might need to be split across lines. */ + + /* ( {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG ... + * ... Of_FORw_OF -- ) + */ + mark_forward_branch(ENDOF_CSTAG); + /* ( -- {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG ... + * ... Of_FORw_OF {Endof_FORw_ENDOF}n_ofs+1 ) + */ + + control_structure_swap(); + /* ( -- {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG ... + * ... {Endof_FORw_ENDOF}n_ofs+1 Of_FORw_OF ) + */ + + resolve_forward(OF_CSTAG); + /* ( -- {Endof_FORw_ENDOF}1..n_ofs N_OFs+1...CASE_CSTAG ... + * ... {Endof_FORw_ENDOF}n_ofs+1 ) + */ + + control_structure_swap(); + /* ( -- {Endof_FORw_ENDOF}1..n_ofs ... + * ... {Endof_FORw_ENDOF}n_ofs+1 ... + * ... N_OFs+1...CASE_CSTAG ) + */ + + /* The number of ENDOF-tagged Forward-Marker pairs has now + * caught up with the incremented OF-count; therefore, + * we can notate the above as: + * + * ( {Endof_FORw_ENDOF}1..n_ofs N_OFs CASE_CSTAG ) + * + * and we are ready for another OF ... ENDOF pair, + * or for the ENDCASE statement. + */ + } } @@ -1842,33 +1808,30 @@ void emit_endof( void ) * **************************************************************************** */ -void emit_endcase( void ) +void emit_endcase(void) { - unsigned long n_endofs ; - if ( matchup_control_structure( CASE_CSTAG) ) - { - int indx; - - emit_token("b(endcase)"); - n_endofs = control_stack->cs_datum; - for ( indx = 0 ; indx < n_endofs ; indx++ ) - { - /* Because matchup_control_structure doesn't pop the - * control-stack, we have the N_OFs...CASE_CSTAG - * item on top of the Endof_FORw_ENDOF item we - * want to resolve. We need to keep it there so - * the POP is valid for the other path as well - * as at the end of this one. - * So we SWAP to get at the Endof_FORw_ENDOF item. - */ - control_structure_swap(); - resolve_forward( ENDOF_CSTAG); + unsigned long n_endofs; + if (matchup_control_structure(CASE_CSTAG)) { + int indx; + + emit_token("b(endcase)"); + n_endofs = control_stack->cs_datum; + for (indx = 0; indx < n_endofs; indx++) { + /* Because matchup_control_structure doesn't pop the + * control-stack, we have the N_OFs...CASE_CSTAG + * item on top of the Endof_FORw_ENDOF item we + * want to resolve. We need to keep it there so + * the POP is valid for the other path as well + * as at the end of this one. + * So we SWAP to get at the Endof_FORw_ENDOF item. + */ + control_structure_swap(); + resolve_forward(ENDOF_CSTAG); + } } - } - pop_cstag(); + pop_cstag(); } - /* ************************************************************************** * * Function name: control_struct_incomplete @@ -1895,15 +1858,14 @@ void emit_endcase( void ) * **************************************************************************** */ -static void control_struct_incomplete( - int severity, - char *call_cond, - cstag_group_t *c_s_entry) +static void control_struct_incomplete(int severity, + char *call_cond, + cstag_group_t * c_s_entry) { - tokenization_error ( severity, - "%s before completion of %s" , - call_cond, strupr(c_s_entry->cs_word)); - where_started( c_s_entry->cs_inp_fil, c_s_entry->cs_line_num ); + tokenization_error(severity, + "%s before completion of %s", + call_cond, strupr(c_s_entry->cs_word)); + where_started(c_s_entry->cs_inp_fil, c_s_entry->cs_line_num); } /* ************************************************************************** @@ -1931,22 +1893,19 @@ static void control_struct_incomplete( * **************************************************************************** */ -void announce_control_structs( int severity, char *call_cond, - unsigned int abs_token_limit) +void announce_control_structs(int severity, char *call_cond, + unsigned int abs_token_limit) { - cstag_group_t *cs_temp = control_stack; - while ( cs_temp != NULL ) - { - if ( cs_temp->cs_abs_token_num < abs_token_limit ) - { - break; - } - if ( cs_temp->cs_not_dup ) - { - control_struct_incomplete( severity, call_cond, cs_temp ); + cstag_group_t *cs_temp = control_stack; + while (cs_temp != NULL) { + if (cs_temp->cs_abs_token_num < abs_token_limit) { + break; + } + if (cs_temp->cs_not_dup) { + control_struct_incomplete(severity, call_cond, cs_temp); + } + cs_temp = cs_temp->prev; } - cs_temp = cs_temp->prev; - } } /* ************************************************************************** @@ -2009,22 +1968,21 @@ void announce_control_structs( int severity, char *call_cond, * **************************************************************************** */ -void clear_control_structs_to_limit( char *call_cond, - unsigned int abs_token_limit) +void clear_control_structs_to_limit(char *call_cond, + unsigned int abs_token_limit) { - while ( control_stack_depth > 0 ) - { - if ( control_stack->cs_abs_token_num < abs_token_limit ) - { - break; + while (control_stack_depth > 0) { + if (control_stack->cs_abs_token_num < abs_token_limit) { + break; + } + if (control_stack->cs_not_dup) { + control_struct_incomplete(TKERROR, call_cond, + control_stack); + if (control_stack->cs_tag == DO_CSTAG) + do_loop_depth--; + } + pop_cstag(); } - if ( control_stack->cs_not_dup ) - { - control_struct_incomplete( TKERROR, call_cond, control_stack ); - if ( control_stack->cs_tag == DO_CSTAG) do_loop_depth--; - } - pop_cstag(); - } } /* ************************************************************************** @@ -2074,7 +2032,7 @@ void clear_control_structs_to_limit( char *call_cond, * **************************************************************************** */ -void clear_control_structs( char *call_cond) +void clear_control_structs(char *call_cond) { - clear_control_structs_to_limit( call_cond, 0); + clear_control_structs_to_limit(call_cond, 0); } diff --git a/toke/flowcontrol.h b/toke/flowcontrol.h index 5ca9195..a2dad53 100644 --- a/toke/flowcontrol.h +++ b/toke/flowcontrol.h @@ -35,7 +35,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * * Global Variables Exported @@ -43,32 +42,32 @@ **************************************************************************** */ extern int control_stack_depth; - + /* ************************************************************************** * * * Function Prototypes / Functions Exported: * **************************************************************************** */ -void emit_if( void ); -void emit_then( void ); -void emit_else( void ); -void emit_begin( void ); -void emit_again( void ); -void emit_until( void ); -void emit_while( void ); -void emit_repeat( void ); -void mark_do( void ); -void resolve_loop( void ); -void emit_case( void ); -void emit_of( void ); -void emit_endof( void ); -void emit_endcase( void ); +void emit_if(void); +void emit_then(void); +void emit_else(void); +void emit_begin(void); +void emit_again(void); +void emit_until(void); +void emit_while(void); +void emit_repeat(void); +void mark_do(void); +void resolve_loop(void); +void emit_case(void); +void emit_of(void); +void emit_endof(void); +void emit_endcase(void); -void announce_control_structs( int severity, char *call_cond, - unsigned int abs_token_limit); -void clear_control_structs_to_limit( char *call_cond, - unsigned int abs_token_limit); -void clear_control_structs( char *call_cond); +void announce_control_structs(int severity, char *call_cond, + unsigned int abs_token_limit); +void clear_control_structs_to_limit(char *call_cond, + unsigned int abs_token_limit); +void clear_control_structs(char *call_cond); -#endif /* _TOKE_FLOWCONTROL_H */ +#endif /* _TOKE_FLOWCONTROL_H */ diff --git a/toke/macros.c b/toke/macros.c index 92bc0ca..0288e8c 100644 --- a/toke/macros.c +++ b/toke/macros.c @@ -88,8 +88,6 @@ * **************************************************************************** */ - - /* ************************************************************************** * * Function name: macro_recursion_error @@ -120,13 +118,12 @@ * **************************************************************************** */ -static void macro_recursion_error( tic_param_t pfield) +static void macro_recursion_error(tic_param_t pfield) { - tokenization_error( TKERROR, - "Recursive invocation of macro named %s\n", statbuf); + tokenization_error(TKERROR, + "Recursive invocation of macro named %s\n", statbuf); } - /* ************************************************************************** * * Function name: eval_mac_string @@ -210,9 +207,8 @@ static void macro_recursion_error( tic_param_t pfield) * **************************************************************************** */ -typedef void (*vfunct)(); /* Pointer to function returning void */ -static vfunct sav_mac_funct ; - +typedef void (*vfunct)(); /* Pointer to function returning void */ +static vfunct sav_mac_funct; /* ************************************************************************** * @@ -222,10 +218,10 @@ static vfunct sav_mac_funct ; * **************************************************************************** */ -static void mac_string_recovery( tic_hdr_t *macro_entry) +static void mac_string_recovery(tic_hdr_t * macro_entry) { - (*macro_entry).funct = sav_mac_funct; - (*macro_entry).ign_func = sav_mac_funct; + (*macro_entry).funct = sav_mac_funct; + (*macro_entry).ign_func = sav_mac_funct; } /* ************************************************************************** @@ -233,27 +229,27 @@ static void mac_string_recovery( tic_hdr_t *macro_entry) * The normal Macro-invocation routine, at last... * **************************************************************************** */ -static void eval_mac_string( tic_param_t pfield) +static void eval_mac_string(tic_param_t pfield) { - int mac_str_len = strlen(pfield.chr_ptr); - /* We can't use (*tic_found).pfld_size for the string length - * because, if this is an alias for a macro, it will be zero... - */ - /* We can change that by de-coupling the decision to free the - * param-field from whether pfld_size is non-zero (by intro- - * ducing yet another field into the tic_param_t struct), - * but we're not doing that today... - */ - - sav_mac_funct = *tic_found->funct; - (*tic_found).funct = macro_recursion_error; - (*tic_found).ign_func = macro_recursion_error; - push_source( mac_string_recovery, tic_found, FALSE); - report_multiline = FALSE; /* Must be done AFTER call to push_source() - * because report_multiline is part of - * the state that push_source() saves. - */ - init_inbuf( pfield.chr_ptr, mac_str_len); + int mac_str_len = strlen(pfield.chr_ptr); + /* We can't use (*tic_found).pfld_size for the string length + * because, if this is an alias for a macro, it will be zero... + */ + /* We can change that by de-coupling the decision to free the + * param-field from whether pfld_size is non-zero (by intro- + * ducing yet another field into the tic_param_t struct), + * but we're not doing that today... + */ + + sav_mac_funct = *tic_found->funct; + (*tic_found).funct = macro_recursion_error; + (*tic_found).ign_func = macro_recursion_error; + push_source(mac_string_recovery, tic_found, FALSE); + report_multiline = FALSE; /* Must be done AFTER call to push_source() + * because report_multiline is part of + * the state that push_source() saves. + */ + init_inbuf(pfield.chr_ptr, mac_str_len); } /* ************************************************************************** @@ -262,10 +258,11 @@ static void eval_mac_string( tic_param_t pfield) * Intermediate routine to convert parameter type. * **************************************************************************** */ -static void eval_builtin_mac( tic_param_t pfield) +static void eval_builtin_mac(tic_param_t pfield) { - eval_string( pfield.chr_ptr); + eval_string(pfield.chr_ptr); } + /* ************************************************************************** * * Make a macro, because we might eliminate this layer later on. @@ -283,20 +280,19 @@ static void eval_builtin_mac( tic_param_t pfield) #define BUILTIN_MACRO(nam, alias) BUILTIN_MAC_TIC(nam, BUILTIN_MAC_FUNC, alias ) static tic_mac_hdr_t macros_tbl[] = { - BUILTIN_MACRO( "(.)", "dup abs <# u#s swap sign u#>") , - + BUILTIN_MACRO("(.)", "dup abs <# u#s swap sign u#>"), - BUILTIN_MACRO( "?", "@ .") , - BUILTIN_MACRO( "1+", "1 +") , - BUILTIN_MACRO( "1-", "1 -") , - BUILTIN_MACRO( "2+", "2 +") , - BUILTIN_MACRO( "2-", "2 -") , + BUILTIN_MACRO("?", "@ ."), + BUILTIN_MACRO("1+", "1 +"), + BUILTIN_MACRO("1-", "1 -"), + BUILTIN_MACRO("2+", "2 +"), + BUILTIN_MACRO("2-", "2 -"), - BUILTIN_MACRO( "accept", "span @ -rot expect span @ swap span !") , - BUILTIN_MACRO( "allot", "0 max 0 ?do 0 c, loop") , - BUILTIN_MACRO( "blank", "bl fill") , - BUILTIN_MACRO( "carret", "h# d") , - BUILTIN_MACRO( ".d", "base @ swap h# a base ! . base !") , + BUILTIN_MACRO("accept", "span @ -rot expect span @ swap span !"), + BUILTIN_MACRO("allot", "0 max 0 ?do 0 c, loop"), + BUILTIN_MACRO("blank", "bl fill"), + BUILTIN_MACRO("carret", "h# d"), + BUILTIN_MACRO(".d", "base @ swap h# a base ! . base !"), /* Note: The Standard gives: ">r over r@ + swap r@ - rot r>" * as its example of the macro for decode-bytes @@ -304,23 +300,23 @@ static tic_mac_hdr_t macros_tbl[] = { * using return-stack operations. And it's one step * shorter, into the bargain! */ - BUILTIN_MACRO( "decode-bytes", "tuck - -rot 2dup + swap 2swap rot") , - - BUILTIN_MACRO( "3drop", "drop 2drop") , - BUILTIN_MACRO( "3dup", "2 pick 2 pick 2 pick") , - BUILTIN_MACRO( "erase", "0 fill") , - BUILTIN_MACRO( ".h", "base @ swap h# 10 base ! . base !") , - BUILTIN_MACRO( "linefeed", "h# a") , - - BUILTIN_MACRO( "s.", "(.) type space") , - BUILTIN_MACRO( "space", "bl emit") , - BUILTIN_MACRO( "spaces", "0 max 0 ?do space loop") , - BUILTIN_MACRO( "(u.)", "<# u#s u#>") , - BUILTIN_MACRO( "?leave", "if leave then"), + BUILTIN_MACRO("decode-bytes", "tuck - -rot 2dup + swap 2swap rot"), + + BUILTIN_MACRO("3drop", "drop 2drop"), + BUILTIN_MACRO("3dup", "2 pick 2 pick 2 pick"), + BUILTIN_MACRO("erase", "0 fill"), + BUILTIN_MACRO(".h", "base @ swap h# 10 base ! . base !"), + BUILTIN_MACRO("linefeed", "h# a"), + + BUILTIN_MACRO("s.", "(.) type space"), + BUILTIN_MACRO("space", "bl emit"), + BUILTIN_MACRO("spaces", "0 max 0 ?do space loop"), + BUILTIN_MACRO("(u.)", "<# u#s u#>"), + BUILTIN_MACRO("?leave", "if leave then"), }; static const int number_of_builtin_macros = - sizeof(macros_tbl)/sizeof(tic_mac_hdr_t); + sizeof(macros_tbl) / sizeof(tic_mac_hdr_t); /* ************************************************************************** * @@ -345,14 +341,12 @@ static const int number_of_builtin_macros = * **************************************************************************** */ -void init_macros( tic_hdr_t **tic_vocab_ptr ) +void init_macros(tic_hdr_t ** tic_vocab_ptr) { - init_tic_vocab( (tic_hdr_t *)macros_tbl, - number_of_builtin_macros, - tic_vocab_ptr ); + init_tic_vocab((tic_hdr_t *) macros_tbl, + number_of_builtin_macros, tic_vocab_ptr); } - /* ************************************************************************** * * Function name: print_if_mac_err @@ -371,18 +365,16 @@ void init_macros( tic_hdr_t **tic_vocab_ptr ) * Error message, if failure is TRUE. * **************************************************************************** */ -static void print_if_mac_err( bool failure, char *func_cpy) +static void print_if_mac_err(bool failure, char *func_cpy) { - if ( failure ) - { - tokenization_error( TKERROR, - "%s directive expects name and definition on the same line\n", - strupr(func_cpy)); - } - free( func_cpy); + if (failure) { + tokenization_error(TKERROR, + "%s directive expects name and definition on the same line\n", + strupr(func_cpy)); + } + free(func_cpy); } - /* ************************************************************************** * * Function name: add_user_macro @@ -453,54 +445,53 @@ static void print_if_mac_err( bool failure, char *func_cpy) **************************************************************************** */ /* This pointer is exported to this file only */ -extern tic_hdr_t *tokz_esc_vocab ; +extern tic_hdr_t *tokz_esc_vocab; -void add_user_macro( void) +void add_user_macro(void) { - char *macroname; - char *macrobody; - bool failure = TRUE; - - /* Copy of function name, for error message */ - char *func_cpy = strdup( statbuf); - - if ( get_word_in_line( NULL ) ) - { - /* This is the Macro name */ - macroname = strdup( statbuf); - - if ( INVERSE(get_rest_of_line() ) ) - { - /* No body on line */ - free( macroname); - - }else{ - /* We have valid Macro body on line */ - int mac_body_len = 0; - - tic_hdr_t **target_vocab = current_definitions; - if ( in_tokz_esc ) target_vocab = &tokz_esc_vocab ; - - /* Tack on a new-line, so that a remark will appear - * to be properly terminated. This might trigger - * an undeserved multi-line warning if the Macro - * is an improperly terminated quote; we will work - * around that problem by temporarily suspending - * multi-line warnings during macro processing. - */ - strcat( statbuf, "\n"); - macrobody = strdup( statbuf); - mac_body_len = strlen(macrobody); - - add_tic_entry( macroname, EVAL_MAC_FUNC, - (TIC_P_DEFLT_TYPE)macrobody, - MACRO_DEF, mac_body_len, FALSE, - EVAL_MAC_FUNC, target_vocab ); - failure = FALSE; + char *macroname; + char *macrobody; + bool failure = TRUE; + + /* Copy of function name, for error message */ + char *func_cpy = strdup(statbuf); + + if (get_word_in_line(NULL)) { + /* This is the Macro name */ + macroname = strdup(statbuf); + + if (INVERSE(get_rest_of_line())) { + /* No body on line */ + free(macroname); + + } else { + /* We have valid Macro body on line */ + int mac_body_len = 0; + + tic_hdr_t **target_vocab = current_definitions; + if (in_tokz_esc) + target_vocab = &tokz_esc_vocab; + + /* Tack on a new-line, so that a remark will appear + * to be properly terminated. This might trigger + * an undeserved multi-line warning if the Macro + * is an improperly terminated quote; we will work + * around that problem by temporarily suspending + * multi-line warnings during macro processing. + */ + strcat(statbuf, "\n"); + macrobody = strdup(statbuf); + mac_body_len = strlen(macrobody); + + add_tic_entry(macroname, EVAL_MAC_FUNC, + (TIC_P_DEFLT_TYPE) macrobody, + MACRO_DEF, mac_body_len, FALSE, + EVAL_MAC_FUNC, target_vocab); + failure = FALSE; + } } - } - print_if_mac_err( failure, func_cpy); + print_if_mac_err(failure, func_cpy); } /* ************************************************************************** @@ -533,18 +524,16 @@ void add_user_macro( void) * invokes a directive that alters Conditional processing... * **************************************************************************** */ -void skip_user_macro( tic_bool_param_t pfield ) +void skip_user_macro(tic_bool_param_t pfield) { - bool failure = TRUE; - char *func_cpy = strdup( statbuf); - if ( get_word_in_line( NULL ) ) - { - if ( get_rest_of_line() ) - { - failure = FALSE; + bool failure = TRUE; + char *func_cpy = strdup(statbuf); + if (get_word_in_line(NULL)) { + if (get_rest_of_line()) { + failure = FALSE; + } } - } - print_if_mac_err( failure, func_cpy); + print_if_mac_err(failure, func_cpy); } diff --git a/toke/macros.h b/toke/macros.h index 6b42894..b3704cb 100644 --- a/toke/macros.h +++ b/toke/macros.h @@ -35,7 +35,6 @@ * **************************************************************************** */ - #include "types.h" #include "ticvocab.h" @@ -45,14 +44,14 @@ * **************************************************************************** */ -void init_macros( tic_hdr_t **tic_vocab_ptr ); -void add_user_macro( void); -void skip_user_macro( tic_bool_param_t pfield ); -#if 0 /* What's this doing here? */ +void init_macros(tic_hdr_t ** tic_vocab_ptr); +void add_user_macro(void); +void skip_user_macro(tic_bool_param_t pfield); +#if 0 /* What's this doing here? */ char *lookup_macro(char *name); bool exists_as_macro(char *name); -bool create_macro_alias( char *new_name, char *old_name ); -void reset_macros_vocab( void ); -#endif /* What's this doing here? */ +bool create_macro_alias(char *new_name, char *old_name); +void reset_macros_vocab(void); +#endif /* What's this doing here? */ -#endif /* _TOKE_MACROS_H */ +#endif /* _TOKE_MACROS_H */ diff --git a/toke/nextfcode.c b/toke/nextfcode.c index ab78ea6..ffee702 100644 --- a/toke/nextfcode.c +++ b/toke/nextfcode.c @@ -56,7 +56,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Functions Exported: @@ -85,7 +84,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Still to be done: @@ -99,8 +97,6 @@ * **************************************************************************** */ - - /* ************************************************************************** * * Global Variables Imported @@ -119,7 +115,6 @@ #include "stream.h" #include "scanner.h" - /* ************************************************************************** * * Global Variables Exported @@ -127,7 +122,7 @@ * **************************************************************************** */ -u16 nextfcode; /* The next FCode-number to be assigned */ +u16 nextfcode; /* The next FCode-number to be assigned */ /* ************************************************************************** * @@ -153,16 +148,14 @@ u16 nextfcode; /* The next FCode-number to be assigned */ * **************************************************************************** */ -typedef struct fcode_range - { - u16 fcr_start; - u16 fcr_end ; - char *fcr_infile; - int fcr_linenum; - bool fcr_not_lapped; +typedef struct fcode_range { + u16 fcr_start; + u16 fcr_end; + char *fcr_infile; + int fcr_linenum; + bool fcr_not_lapped; struct fcode_range *fcr_next; - } fcode_range_t ; - +} fcode_range_t; /* ************************************************************************** * @@ -194,16 +187,16 @@ typedef struct fcode_range * **************************************************************************** */ -static bool ranges_exist = FALSE; -static bool changes_listed = FALSE; +static bool ranges_exist = FALSE; +static bool changes_listed = FALSE; -static u16 range_start = FCODE_START; -static u16 range_end = 0; -static char *first_fcr_infile = NULL; -static int first_fcr_linenum = 0; +static u16 range_start = FCODE_START; +static u16 range_end = 0; +static char *first_fcr_infile = NULL; +static int first_fcr_linenum = 0; -static fcode_range_t *first_fc_range = NULL; -static fcode_range_t *current_fc_range = NULL; +static fcode_range_t *first_fc_range = NULL; +static fcode_range_t *current_fc_range = NULL; /* ************************************************************************** * @@ -258,39 +251,34 @@ static fcode_range_t *current_fc_range = NULL; * **************************************************************************** */ -void reset_fcode_ranges( void) +void reset_fcode_ranges(void) { - if ( ranges_exist ) - { - while ( current_fc_range != NULL ) - { - current_fc_range = first_fc_range->fcr_next; - free( first_fc_range->fcr_infile); - free( first_fc_range); - first_fc_range = current_fc_range; + if (ranges_exist) { + while (current_fc_range != NULL) { + current_fc_range = first_fc_range->fcr_next; + free(first_fc_range->fcr_infile); + free(first_fc_range); + first_fc_range = current_fc_range; + } + ranges_exist = FALSE; + } else { + if (first_fcr_infile != NULL) { + if (strcmp(first_fcr_infile, iname) != 0) { + free(first_fcr_infile); + first_fcr_infile = NULL; + } + } } - ranges_exist = FALSE; - }else{ - if ( first_fcr_infile != NULL ) - { - if ( strcmp( first_fcr_infile, iname) != 0 ) - { - free( first_fcr_infile); - first_fcr_infile = NULL; - } + + changes_listed = FALSE; + range_start = FCODE_START; + range_end = 0; + + if (first_fcr_infile == NULL) { + first_fcr_infile = strdup(iname); } - } - - changes_listed = FALSE; - range_start = FCODE_START; - range_end = 0; - - if ( first_fcr_infile == NULL ) - { - first_fcr_infile = strdup( iname); - } - first_fcr_linenum = lineno; - nextfcode = FCODE_START; + first_fcr_linenum = lineno; + nextfcode = FCODE_START; } /* ************************************************************************** @@ -338,73 +326,75 @@ void reset_fcode_ranges( void) * **************************************************************************** */ -void list_fcode_ranges( bool final_tally) +void list_fcode_ranges(bool final_tally) { - if ( verbose ) - { - FILE *message_dest = ( final_tally ? stdout : ERRMSG_DESTINATION ); - if ( changes_listed ) - { - fprintf(message_dest, "\n"); - }else{ - changes_listed = TRUE; - - if ( INVERSE(ranges_exist) ) - { /* List the first and only range */ - if ( range_end == 0 ) - { - fprintf(message_dest, "No FCodes assigned.\n"); - }else{ - if ( range_start == FCODE_START ) - { - fprintf(message_dest, - "Last assigned FCode = 0x%x\n", range_end); - }else{ - fprintf(message_dest, - "FCodes assigned: 0x%x to 0x%x\n", - range_start, range_end); - } - } - /* We are done listing the first and only range */ - }else{ /* List the collection of Ranges */ - - /* Pionter to function returning void */ - typedef void (*vfunct)(); - - /* Function for the started_at() part of the message */ - vfunct start_at_funct = - ( final_tally ? print_started_at : started_at ); - - - fcode_range_t *next_range = first_fc_range; - - fprintf(message_dest, "FCodes assigned:\n"); - - while ( next_range != NULL ) - { - if ( next_range->fcr_end == 0 ) - { - fprintf(message_dest, " None assigned"); - }else{ - fprintf(message_dest, " From 0x%x to 0x%x", - next_range->fcr_start, next_range->fcr_end ); - if ( INVERSE( next_range->fcr_not_lapped) ) - { - fprintf(message_dest, " ***Overlap***" ); + if (verbose) { + FILE *message_dest = + (final_tally ? stdout : ERRMSG_DESTINATION); + if (changes_listed) { + fprintf(message_dest, "\n"); + } else { + changes_listed = TRUE; + + if (INVERSE(ranges_exist)) { /* List the first and only range */ + if (range_end == 0) { + fprintf(message_dest, + "No FCodes assigned.\n"); + } else { + if (range_start == FCODE_START) { + fprintf(message_dest, + "Last assigned FCode = 0x%x\n", + range_end); + } else { + fprintf(message_dest, + "FCodes assigned: 0x%x to 0x%x\n", + range_start, range_end); + } + } + /* We are done listing the first and only range */ + } else { /* List the collection of Ranges */ + + /* Pionter to function returning void */ + typedef void (*vfunct)(); + + /* Function for the started_at() part of the message */ + vfunct start_at_funct = + (final_tally ? print_started_at : + started_at); + + fcode_range_t *next_range = first_fc_range; + + fprintf(message_dest, "FCodes assigned:\n"); + + while (next_range != NULL) { + if (next_range->fcr_end == 0) { + fprintf(message_dest, + " None assigned"); + } else { + fprintf(message_dest, + " From 0x%x to 0x%x", + next_range->fcr_start, + next_range->fcr_end); + if (INVERSE + (next_range-> + fcr_not_lapped)) { + fprintf(message_dest, + " ***Overlap***"); + } + } + fprintf(message_dest, " in the range"); + (*start_at_funct) (next_range-> + fcr_infile, + next_range-> + fcr_linenum); + + next_range = next_range->fcr_next; + } } - } - fprintf(message_dest, " in the range"); - (*start_at_funct)( - next_range->fcr_infile, next_range->fcr_linenum ); - - next_range = next_range->fcr_next; } - } } - } } - /* ************************************************************************** * * Function name: set_next_fcode @@ -485,66 +475,62 @@ void list_fcode_ranges( bool final_tally) * **************************************************************************** */ -void set_next_fcode( u16 new_fcode) +void set_next_fcode(u16 new_fcode) { - if ( INVERSE( ranges_exist) ) - { /* The current range is the first and only. */ + if (INVERSE(ranges_exist)) { /* The current range is the first and only. */ - if ( new_fcode == nextfcode ) - { - /* Do nothing here */ - return; - } + if (new_fcode == nextfcode) { + /* Do nothing here */ + return; + } - if ( range_end == 0 ) - { /* No FCode assignments have been made in the current range */ - /* This is still the first and only range. */ + if (range_end == 0) { /* No FCode assignments have been made in the current range */ + /* This is still the first and only range. */ - reset_fcode_ranges(); /* Update file name and line number */ - range_start = new_fcode; - nextfcode = new_fcode; + reset_fcode_ranges(); /* Update file name and line number */ + range_start = new_fcode; + nextfcode = new_fcode; - /* We are done here */ - return; + /* We are done here */ + return; - }else{ /* Create the data structure for the first Range */ - first_fc_range = safe_malloc( sizeof( fcode_range_t), - "creating first FCode Range" ); - first_fc_range->fcr_start = range_start; - first_fc_range->fcr_end = range_end; - first_fc_range->fcr_infile = first_fcr_infile; - first_fc_range->fcr_linenum = first_fcr_linenum; - first_fc_range->fcr_not_lapped = TRUE; - first_fc_range->fcr_next = NULL; + } else { /* Create the data structure for the first Range */ + first_fc_range = safe_malloc(sizeof(fcode_range_t), + "creating first FCode Range"); + first_fc_range->fcr_start = range_start; + first_fc_range->fcr_end = range_end; + first_fc_range->fcr_infile = first_fcr_infile; + first_fc_range->fcr_linenum = first_fcr_linenum; + first_fc_range->fcr_not_lapped = TRUE; + first_fc_range->fcr_next = NULL; - first_fcr_infile = NULL; - first_fcr_linenum = 0; - range_start = FCODE_START; - range_end = 0; + first_fcr_infile = NULL; + first_fcr_linenum = 0; + range_start = FCODE_START; + range_end = 0; - current_fc_range = first_fc_range; + current_fc_range = first_fc_range; - ranges_exist = TRUE; + ranges_exist = TRUE; + } } - } - - /* Previous Ranges exist now for sure! */ - current_fc_range->fcr_next = safe_malloc( sizeof( fcode_range_t), - "creating new FCode Range" ); - current_fc_range = current_fc_range->fcr_next; - - nextfcode = new_fcode; - current_fc_range->fcr_start = nextfcode; - current_fc_range->fcr_end = 0; - /* Will be filled in by first assignment */ - current_fc_range->fcr_infile = strdup( iname); - current_fc_range->fcr_linenum = lineno; - current_fc_range->fcr_not_lapped = TRUE; - current_fc_range->fcr_next = NULL; - - changes_listed = FALSE; -} + /* Previous Ranges exist now for sure! */ + current_fc_range->fcr_next = safe_malloc(sizeof(fcode_range_t), + "creating new FCode Range"); + current_fc_range = current_fc_range->fcr_next; + + nextfcode = new_fcode; + current_fc_range->fcr_start = nextfcode; + current_fc_range->fcr_end = 0; + /* Will be filled in by first assignment */ + current_fc_range->fcr_infile = strdup(iname); + current_fc_range->fcr_linenum = lineno; + current_fc_range->fcr_not_lapped = TRUE; + current_fc_range->fcr_next = NULL; + + changes_listed = FALSE; +} /* ************************************************************************** * @@ -576,28 +562,24 @@ void set_next_fcode( u16 new_fcode) * **************************************************************************** */ -static fcode_range_t *find_overlap( u16 test_fcode) +static fcode_range_t *find_overlap(u16 test_fcode) { - fcode_range_t *retval = NULL; - if ( ranges_exist ) - { - fcode_range_t *test_range = first_fc_range; - while ( test_range != current_fc_range ) - { - if ( ( test_fcode <= test_range->fcr_end ) && - ( test_fcode >= test_range->fcr_start ) ) - { - retval = test_range; - break; - } - test_range = test_range->fcr_next; + fcode_range_t *retval = NULL; + if (ranges_exist) { + fcode_range_t *test_range = first_fc_range; + while (test_range != current_fc_range) { + if ((test_fcode <= test_range->fcr_end) && + (test_fcode >= test_range->fcr_start)) { + retval = test_range; + break; + } + test_range = test_range->fcr_next; + } } - } - return( retval); + return (retval); } - /* ************************************************************************** * * Function name: assigning_fcode @@ -630,50 +612,47 @@ static fcode_range_t *find_overlap( u16 test_fcode) * **************************************************************************** */ -void assigning_fcode( void) +void assigning_fcode(void) { - if ( nextfcode > FCODE_LIMIT ) - { - /* Let's give a last summarization before we crap out */ - tokenization_error( INFO, ""); - list_fcode_ranges( FALSE); - - tokenization_error( FATAL, - "Too many definitions. " - "Assigned FCode exceeds limit " - "specified by IEEE-1275."); - /* - * No need to return() from here. - * FATAL error exits program. - */ - } - - changes_listed = FALSE; - - if ( INVERSE(ranges_exist) ) - { /* No Overlap Error checking needed here. */ - range_end = nextfcode; - }else{ - current_fc_range->fcr_end = nextfcode; - - /* Detect and report Overlap Error only once per Range */ - if ( current_fc_range->fcr_not_lapped ) - { - fcode_range_t *found_lap = find_overlap( nextfcode); - if ( found_lap != NULL ) - { - tokenization_error( TKERROR, - "Assigning FCode of 0x%x, " - "which overlaps the range", nextfcode); - started_at( found_lap->fcr_infile, found_lap->fcr_linenum); - - current_fc_range->fcr_not_lapped = FALSE; - } + if (nextfcode > FCODE_LIMIT) { + /* Let's give a last summarization before we crap out */ + tokenization_error(INFO, ""); + list_fcode_ranges(FALSE); + + tokenization_error(FATAL, + "Too many definitions. " + "Assigned FCode exceeds limit " + "specified by IEEE-1275."); + /* + * No need to return() from here. + * FATAL error exits program. + */ } - } -} + changes_listed = FALSE; + + if (INVERSE(ranges_exist)) { /* No Overlap Error checking needed here. */ + range_end = nextfcode; + } else { + current_fc_range->fcr_end = nextfcode; + + /* Detect and report Overlap Error only once per Range */ + if (current_fc_range->fcr_not_lapped) { + fcode_range_t *found_lap = find_overlap(nextfcode); + if (found_lap != NULL) { + tokenization_error(TKERROR, + "Assigning FCode of 0x%x, " + "which overlaps the range", + nextfcode); + started_at(found_lap->fcr_infile, + found_lap->fcr_linenum); + + current_fc_range->fcr_not_lapped = FALSE; + } + } + } +} /* ************************************************************************** * @@ -699,7 +678,7 @@ void assigning_fcode( void) * **************************************************************************** */ -void bump_fcode( void) +void bump_fcode(void) { - nextfcode++; + nextfcode++; } diff --git a/toke/nextfcode.h b/toke/nextfcode.h index 3620adb..f5e2784 100644 --- a/toke/nextfcode.h +++ b/toke/nextfcode.h @@ -37,15 +37,13 @@ #include "types.h" - /* ************************************************************************** * * * Global Variables Exported * **************************************************************************** */ -extern u16 nextfcode; /* The next FCode-number to be assigned */ - +extern u16 nextfcode; /* The next FCode-number to be assigned */ /* ************************************************************************** * * @@ -53,11 +51,11 @@ extern u16 nextfcode; /* The next FCode-number to be assigned */ * **************************************************************************** */ -void reset_fcode_ranges( void); -void list_fcode_ranges( bool final_tally); -void set_next_fcode( u16 new_fcode); -void assigning_fcode( void); -void bump_fcode( void); +void reset_fcode_ranges(void); +void list_fcode_ranges(bool final_tally); +void set_next_fcode(u16 new_fcode); +void assigning_fcode(void); +void bump_fcode(void); /* ************************************************************************** * @@ -77,4 +75,4 @@ void bump_fcode( void); #define FCODE_START 0x0800 #define FCODE_LIMIT 0x0fff -#endif /* _TOKE_NEXTFCODE_H */ +#endif /* _TOKE_NEXTFCODE_H */ diff --git a/toke/parselocals.c b/toke/parselocals.c index 084e8c3..754a607 100644 --- a/toke/parselocals.c +++ b/toke/parselocals.c @@ -54,13 +54,12 @@ **************************************************************************** */ /* Note that the enclosing curly-braces are part of the name */ -static const char* push_locals = "{push-locals}"; /* ( #ilocals #ulocals -- ) */ -static const char* pop_locals = "{pop-locals}"; /* ( #locals -- ) */ -static const char* local_addr = "_{local}"; /* ( local# -- addr ) */ +static const char *push_locals = "{push-locals}"; /* ( #ilocals #ulocals -- ) */ +static const char *pop_locals = "{pop-locals}"; /* ( #locals -- ) */ +static const char *local_addr = "_{local}"; /* ( local# -- addr ) */ /* Switchable Fetch or Store operator to apply to local_addr. */ -static const char* local_op = "@"; /* Initially Fetch */ - +static const char *local_op = "@"; /* Initially Fetch */ /* ************************************************************************** * @@ -121,7 +120,7 @@ static int num_ilocals = 0; static int num_ulocals = 0; static int localno = 0; static char eval_buf[64]; -static unsigned int l_d_lineno; /* For Error Messages */ +static unsigned int l_d_lineno; /* For Error Messages */ /* ************************************************************************** * @@ -169,16 +168,15 @@ static unsigned int l_d_lineno; /* For Error Messages */ * **************************************************************************** */ -static char *int_to_str( int num, char *bufr) +static char *int_to_str(int num, char *bufr) { - char* prefix = "d# "; - if ( num < 8 ) prefix = ""; - sprintf(bufr,"%s%d",prefix, num); - return (bufr); + char *prefix = "d# "; + if (num < 8) + prefix = ""; + sprintf(bufr, "%s%d", prefix, num); + return (bufr); } - - /* ************************************************************************** * * Function name: invoke_local @@ -226,18 +224,17 @@ static char *int_to_str( int num, char *bufr) * **************************************************************************** */ -static void invoke_local( tic_param_t pfield ) +static void invoke_local(tic_param_t pfield) { - char local_num_buf[10]; - int loc_num = (int)pfield.deflt_elem; + char local_num_buf[10]; + int loc_num = (int)pfield.deflt_elem; - int_to_str(loc_num, local_num_buf); - sprintf( eval_buf, "%s %s %s", local_num_buf, local_addr, local_op ); - eval_string( eval_buf); + int_to_str(loc_num, local_num_buf); + sprintf(eval_buf, "%s %s %s", local_num_buf, local_addr, local_op); + eval_string(eval_buf); } - /* ************************************************************************** * * Function name: locals_separator @@ -277,29 +274,26 @@ static void invoke_local( tic_param_t pfield ) * **************************************************************************** */ -static bool locals_separator( char subj ) +static bool locals_separator(char subj) { - bool retval = FALSE; - /* Is it the preferred (i.e., non-legacy) separator? */ - if ( subj == '|' ) - { - retval = TRUE; - return ( retval ); - } - - if ( ibm_locals_legacy_separator ) - { - if ( subj == ';' ) - { - retval = TRUE; - if ( ibm_legacy_separator_message ) - { - tokenization_error ( WARNING , "Semicolon as separator in " - "Locals declaration is deprecated in favor of '|'\n"); - } + bool retval = FALSE; + /* Is it the preferred (i.e., non-legacy) separator? */ + if (subj == '|') { + retval = TRUE; + return (retval); } - } - return ( retval ); + + if (ibm_locals_legacy_separator) { + if (subj == ';') { + retval = TRUE; + if (ibm_legacy_separator_message) { + tokenization_error(WARNING, + "Semicolon as separator in " + "Locals declaration is deprecated in favor of '|'\n"); + } + } + } + return (retval); } /* ************************************************************************** @@ -332,17 +326,15 @@ static bool locals_separator( char subj ) * **************************************************************************** */ -static void add_local( TIC_P_DEFLT_TYPE lnum, char *lname) +static void add_local(TIC_P_DEFLT_TYPE lnum, char *lname) { - char *lnamecopy ; + char *lnamecopy; - lnamecopy = strdup( lname); - add_tic_entry( lnamecopy, invoke_local, lnum, - LOCAL_VAL, 0, FALSE, NULL, - &local_names ); + lnamecopy = strdup(lname); + add_tic_entry(lnamecopy, invoke_local, lnum, + LOCAL_VAL, 0, FALSE, NULL, &local_names); } - /* ************************************************************************** * * Function name: gather_locals @@ -390,91 +382,86 @@ static void add_local( TIC_P_DEFLT_TYPE lnum, char *lname) * **************************************************************************** */ -static bool gather_locals( bool initted, int *counter ) +static bool gather_locals(bool initted, int *counter) { - signed long wlen; - bool retval = FALSE; + signed long wlen; + bool retval = FALSE; - while ( TRUE ) - { - wlen = get_word(); + while (TRUE) { + wlen = get_word(); - if ( wlen <= 0 ) - { - warn_unterm( TKERROR, "Local-Values Declaration", l_d_lineno); - break; - } + if (wlen <= 0) { + warn_unterm(TKERROR, "Local-Values Declaration", + l_d_lineno); + break; + } - /* Allow comments to be interspersed among the declarations. */ - if ( filter_comments( statbuf) ) - { - /* Unterminated and Multi-line checking already handled */ - continue; - } - /* Is this the terminator or the separator? */ - if ( wlen == 1 ) /* Maybe */ - { - /* Check for separator */ - if (locals_separator( statbuf[0] ) ) - { - /* If gathering initted Local names, separator is legit */ - if ( initted ) - { - retval = TRUE; - break; - }else{ - tokenization_error ( TKERROR, - "Excess separator -- %s -- found " - "in Local-Values declaration", statbuf); - in_last_colon( TRUE); - continue; + /* Allow comments to be interspersed among the declarations. */ + if (filter_comments(statbuf)) { + /* Unterminated and Multi-line checking already handled */ + continue; } - } - /* Haven't found the separator. Check for the terminator */ - if ( statbuf[0] == '}' ) - { - break; - } - } - /* It was not the terminator or the separator */ - { - long tmp; - char *where_pt1; char *where_pt2; - /* Error-check for duplicated names */ - if ( word_exists ( statbuf, &where_pt1, &where_pt2 ) ) - { - tokenization_error ( TKERROR, "Cannot declare %s " - "as a Local-Name; it's already defined %s%s", - statbuf, where_pt1, where_pt2 ); - show_node_start(); - continue; - } - /* Error-check for numbers. */ - if ( get_number(&tmp) ) - { - tokenization_error ( TKERROR, "Cannot declare %s " - "as a Local-Name; it's a number.\n", statbuf ); - continue; - } - - /* We've got a valid new local-name */ - /* Don't need to check name length; it won't go into the FCode */ - - /* Increment our counting-v'ble */ - *counter += 1; - - /* Define our new local-name in the Locals' vocabulary */ - add_local( localno, statbuf ); - - /* Bump the running Local-Number */ - localno++; + /* Is this the terminator or the separator? */ + if (wlen == 1) { /* Maybe */ + /* Check for separator */ + if (locals_separator(statbuf[0])) { + /* If gathering initted Local names, separator is legit */ + if (initted) { + retval = TRUE; + break; + } else { + tokenization_error(TKERROR, + "Excess separator -- %s -- found " + "in Local-Values declaration", + statbuf); + in_last_colon(TRUE); + continue; + } + } + /* Haven't found the separator. Check for the terminator */ + if (statbuf[0] == '}') { + break; + } + } + /* It was not the terminator or the separator */ + { + long tmp; + char *where_pt1; + char *where_pt2; + /* Error-check for duplicated names */ + if (word_exists(statbuf, &where_pt1, &where_pt2)) { + tokenization_error(TKERROR, "Cannot declare %s " + "as a Local-Name; it's already defined %s%s", + statbuf, where_pt1, + where_pt2); + show_node_start(); + continue; + } + /* Error-check for numbers. */ + if (get_number(&tmp)) { + tokenization_error(TKERROR, "Cannot declare %s " + "as a Local-Name; it's a number.\n", + statbuf); + continue; + } + + /* We've got a valid new local-name */ + /* Don't need to check name length; it won't go into the FCode */ + + /* Increment our counting-v'ble */ + *counter += 1; + + /* Define our new local-name in the Locals' vocabulary */ + add_local(localno, statbuf); + + /* Bump the running Local-Number */ + localno++; + } } - } - return ( retval ); + return (retval); } - /* ************************************************************************** * * Function name: activate_locals @@ -513,15 +500,15 @@ static bool gather_locals( bool initted, int *counter ) * **************************************************************************** */ -static void activate_locals( void ) +static void activate_locals(void) { - char ilocals_buf[10]; - char ulocals_buf[10]; - - int_to_str(num_ilocals, ilocals_buf ); - int_to_str(num_ulocals, ulocals_buf ); - sprintf( eval_buf,"%s %s %s",ilocals_buf, ulocals_buf, push_locals); - eval_string( eval_buf); + char ilocals_buf[10]; + char ulocals_buf[10]; + + int_to_str(num_ilocals, ilocals_buf); + int_to_str(num_ulocals, ulocals_buf); + sprintf(eval_buf, "%s %s %s", ilocals_buf, ulocals_buf, push_locals); + eval_string(eval_buf); } /* ************************************************************************** @@ -560,35 +547,33 @@ static void activate_locals( void ) */ static int last_local_colon = 0; -static bool error_check_locals ( void ) +static bool error_check_locals(void) { - bool retval = FALSE; - - if ( ! incolon ) - { - tokenization_error ( TKERROR, - "Can only declare Locals inside of a Colon-definition.\n"); - retval = TRUE; - } else { - if ( last_local_colon == lastcolon ) - { - tokenization_error ( TKERROR, "Excess Locals Declaration"); - in_last_colon( TRUE); - retval = TRUE; - }else{ - last_local_colon = lastcolon; - if ( opc > lastcolon ) - { - tokenization_error ( WARNING, - "Declaring Locals after the body of a Colon-definition " - "has begun is not recommended.\n"); - } - announce_control_structs( TKERROR, - "Local-Values Declaration encountered", - last_colon_abs_token_no); + bool retval = FALSE; + + if (!incolon) { + tokenization_error(TKERROR, + "Can only declare Locals inside of a Colon-definition.\n"); + retval = TRUE; + } else { + if (last_local_colon == lastcolon) { + tokenization_error(TKERROR, + "Excess Locals Declaration"); + in_last_colon(TRUE); + retval = TRUE; + } else { + last_local_colon = lastcolon; + if (opc > lastcolon) { + tokenization_error(WARNING, + "Declaring Locals after the body of a Colon-definition " + "has begun is not recommended.\n"); + } + announce_control_structs(TKERROR, + "Local-Values Declaration encountered", + last_colon_abs_token_no); + } } - } - return ( retval ); + return (retval); } /* ************************************************************************** @@ -629,50 +614,46 @@ static bool error_check_locals ( void ) * **************************************************************************** */ -void declare_locals ( bool ignoring) +void declare_locals(bool ignoring) { - num_ilocals = 0; - num_ulocals = 0; - localno = 0; - - l_d_lineno = lineno; - bool sav_rep_mul_lin = report_multiline; - report_multiline = TRUE; - - if ( ignoring || error_check_locals() ) - { - if ( skip_until ( '}' ) ) - { - warn_unterm(TKERROR, - "misplaced Local-Values Declaration", l_d_lineno); - }else{ - pc++ ; /* Get past the close-curly-brace */ - } - }else{ - if (gather_locals( TRUE, &num_ilocals ) ) - { - gather_locals( FALSE, &num_ulocals ); - } - } - - /* If PC has reached the END, gather_locals() will - * have already issued an "unterminated" Error; - * a "multiline" warning would be redundant - * repetitive, unnecessary, excessive, unaesthetic - * and -- did I already mention? -- redundant. - */ - if ( pc < end ) - { - report_multiline = sav_rep_mul_lin; - warn_if_multiline( "Local-Values declaration", l_d_lineno); - } - - /* Don't do anything if no Locals were declared */ - /* This could happen if the { } field is empty */ - if ( localno != 0 ) - { - activate_locals(); - } + num_ilocals = 0; + num_ulocals = 0; + localno = 0; + + l_d_lineno = lineno; + bool sav_rep_mul_lin = report_multiline; + report_multiline = TRUE; + + if (ignoring || error_check_locals()) { + if (skip_until('}')) { + warn_unterm(TKERROR, + "misplaced Local-Values Declaration", + l_d_lineno); + } else { + pc++; /* Get past the close-curly-brace */ + } + } else { + if (gather_locals(TRUE, &num_ilocals)) { + gather_locals(FALSE, &num_ulocals); + } + } + + /* If PC has reached the END, gather_locals() will + * have already issued an "unterminated" Error; + * a "multiline" warning would be redundant + * repetitive, unnecessary, excessive, unaesthetic + * and -- did I already mention? -- redundant. + */ + if (pc < end) { + report_multiline = sav_rep_mul_lin; + warn_if_multiline("Local-Values declaration", l_d_lineno); + } + + /* Don't do anything if no Locals were declared */ + /* This could happen if the { } field is empty */ + if (localno != 0) { + activate_locals(); + } } /* ************************************************************************** @@ -692,10 +673,10 @@ void declare_locals ( bool ignoring) * **************************************************************************** */ -static bool handle_local( char *lname) +static bool handle_local(char *lname) { - bool retval = handle_tic_vocab( lname, local_names ); - return ( retval ) ; + bool retval = handle_tic_vocab(lname, local_names); + return (retval); } /* ************************************************************************** @@ -716,13 +697,12 @@ static bool handle_local( char *lname) * **************************************************************************** */ -tic_hdr_t *lookup_local( char *lname) +tic_hdr_t *lookup_local(char *lname) { - tic_hdr_t *retval = lookup_tic_entry( lname, local_names ); - return ( retval ) ; + tic_hdr_t *retval = lookup_tic_entry(lname, local_names); + return (retval); } - /* ************************************************************************** * * Function name: create_local_alias @@ -749,8 +729,8 @@ tic_hdr_t *lookup_local( char *lname) bool create_local_alias(char *new_name, char *old_name) { - bool retval = create_tic_alias( new_name, old_name, &local_names ); - return ( retval ); + bool retval = create_tic_alias(new_name, old_name, &local_names); + return (retval); } /* ************************************************************************** @@ -768,13 +748,12 @@ bool create_local_alias(char *new_name, char *old_name) * **************************************************************************** */ -bool exists_as_local( char *stat_name ) +bool exists_as_local(char *stat_name) { - bool retval = exists_in_tic_vocab(stat_name, local_names ); - return ( retval ); + bool retval = exists_in_tic_vocab(stat_name, local_names); + return (retval); } - /* ************************************************************************** * * Function name: assign_local @@ -816,32 +795,31 @@ bool exists_as_local( char *stat_name ) * **************************************************************************** */ -void assign_local ( void ) +void assign_local(void) { - signed long wlen; - bool is_okay; - u8 *savd_pc = pc; - unsigned int savd_lineno = lineno; + signed long wlen; + bool is_okay; + u8 *savd_pc = pc; + unsigned int savd_lineno = lineno; - wlen = get_word(); + wlen = get_word(); - if ( wlen <= 0 ) - { - warn_unterm(TKERROR, "Locals Assignment", lineno); - return; + if (wlen <= 0) { + warn_unterm(TKERROR, "Locals Assignment", lineno); + return; } - local_op = "!"; /* Set to Store */ - - is_okay = handle_local( statbuf); - if( INVERSE(is_okay) ) - { - tokenization_error ( TKERROR, - "Cannot apply -> to %s, only to a declared Local.\n", statbuf ); - pc = savd_pc; - lineno = savd_lineno; - } - local_op = "@"; /* Reset to Fetch */ + local_op = "!"; /* Set to Store */ + + is_okay = handle_local(statbuf); + if (INVERSE(is_okay)) { + tokenization_error(TKERROR, + "Cannot apply -> to %s, only to a declared Local.\n", + statbuf); + pc = savd_pc; + lineno = savd_lineno; + } + local_op = "@"; /* Reset to Fetch */ } /* ************************************************************************** @@ -891,19 +869,18 @@ void assign_local ( void ) * **************************************************************************** */ -void finish_locals ( void ) +void finish_locals(void) { - /* Don't do anything if Locals are not in use */ - if ( localno > 0 ) - { - char nlocals_buf[10]; - - int_to_str(localno, nlocals_buf ); - sprintf( eval_buf,"%s %s",nlocals_buf, pop_locals); - eval_string( eval_buf); - tokenize_one_word( get_word() ); - tokenize_one_word( get_word() ); - } + /* Don't do anything if Locals are not in use */ + if (localno > 0) { + char nlocals_buf[10]; + + int_to_str(localno, nlocals_buf); + sprintf(eval_buf, "%s %s", nlocals_buf, pop_locals); + eval_string(eval_buf); + tokenize_one_word(get_word()); + tokenize_one_word(get_word()); + } } /* ************************************************************************** @@ -933,15 +910,14 @@ void finish_locals ( void ) * **************************************************************************** */ -void forget_locals ( void ) +void forget_locals(void) { - /* Don't do anything if Locals are not in use */ - if ( localno != 0 ) - { - reset_tic_vocab( &local_names, NULL ) ; - - num_ilocals = 0; - num_ulocals = 0; - localno = 0; - } + /* Don't do anything if Locals are not in use */ + if (localno != 0) { + reset_tic_vocab(&local_names, NULL); + + num_ilocals = 0; + num_ulocals = 0; + localno = 0; + } } diff --git a/toke/parselocals.h b/toke/parselocals.h index ddf4248..65d0547 100644 --- a/toke/parselocals.h +++ b/toke/parselocals.h @@ -37,12 +37,12 @@ #include "ticvocab.h" -void declare_locals ( bool ignoring); -tic_hdr_t *lookup_local( char *lname); -bool exists_as_local( char *stat_name ); +void declare_locals(bool ignoring); +tic_hdr_t *lookup_local(char *lname); +bool exists_as_local(char *stat_name); bool create_local_alias(char *new_name, char *old_name); -void assign_local ( void ); -void finish_locals ( void ); -void forget_locals ( void ); +void assign_local(void); +void finish_locals(void); +void forget_locals(void); -#endif /* _TOKE_LOCALX_H */ +#endif /* _TOKE_LOCALX_H */ diff --git a/toke/scanner.c b/toke/scanner.c index 6a3ae0b..7422fa1 100644 --- a/toke/scanner.c +++ b/toke/scanner.c @@ -66,74 +66,72 @@ * **************************************************************************** */ -u8 *statbuf=NULL; /* The word just read from the input stream */ -u8 base=0x0a; /* The numeric-interpretation base */ +u8 *statbuf = NULL; /* The word just read from the input stream */ +u8 base = 0x0a; /* The numeric-interpretation base */ /* pci data */ -bool pci_is_last_image=TRUE; -u16 pci_image_rev=0x0001; /* Vendor's Image, NOT PCI Data Structure Rev */ -u16 pci_vpd=0x0000; - +bool pci_is_last_image = TRUE; +u16 pci_image_rev = 0x0001; /* Vendor's Image, NOT PCI Data Structure Rev */ +u16 pci_vpd = 0x0000; /* Having to do with the state of the tokenization */ -bool offs16 = TRUE; /* We are using 16-bit branch- (etc) -offsets */ -bool in_tokz_esc = FALSE; /* TRUE if in "Tokenizer Escape" mode */ -bool incolon = FALSE; /* TRUE if inside a colon definition */ -bool haveend = FALSE; /* TRUE if the "end" code was read. */ -int do_loop_depth = 0; /* How deep we are inside DO ... LOOP variants */ +bool offs16 = TRUE; /* We are using 16-bit branch- (etc) -offsets */ +bool in_tokz_esc = FALSE; /* TRUE if in "Tokenizer Escape" mode */ +bool incolon = FALSE; /* TRUE if inside a colon definition */ +bool haveend = FALSE; /* TRUE if the "end" code was read. */ +int do_loop_depth = 0; /* How deep we are inside DO ... LOOP variants */ /* State of headered-ness for name-creation */ -headeredness hdr_flag = FLAG_HEADERLESS ; /* Init'l default state */ +headeredness hdr_flag = FLAG_HEADERLESS; /* Init'l default state */ /* Used for error-checking of IBM-style Locals */ -int lastcolon; /* Location in output stream of latest colon-definition. */ +int lastcolon; /* Location in output stream of latest colon-definition. */ /* Used for error reporting */ -char *last_colon_defname = NULL; /* Name of last colon-definition */ -char *last_colon_filename = NULL; /* File where last colon-def'n made */ -unsigned int last_colon_lineno; /* Line number of last colon-def'n */ -bool report_multiline = TRUE; /* False to suspend multiline warning */ +char *last_colon_defname = NULL; /* Name of last colon-definition */ +char *last_colon_filename = NULL; /* File where last colon-def'n made */ +unsigned int last_colon_lineno; /* Line number of last colon-def'n */ +bool report_multiline = TRUE; /* False to suspend multiline warning */ unsigned int last_colon_abs_token_no; - /* Shared phrases */ + /* Shared phrases */ char *in_tkz_esc_mode = "in Tokenizer-Escape mode.\n"; -char *wh_defined = ", which is defined as a "; +char *wh_defined = ", which is defined as a "; /* ************************************************************************** * Local variables **************************************************************************** */ -static u16 last_colon_fcode; /* FCode-number assigned to last colon-def'n */ - /* Used for RECURSE */ +static u16 last_colon_fcode; /* FCode-number assigned to last colon-def'n */ + /* Used for RECURSE */ -static bool do_not_overload = TRUE ; /* False to suspend dup-name-test */ -static bool got_until_eof = FALSE ; /* TRUE to signal "unterminated" */ +static bool do_not_overload = TRUE; /* False to suspend dup-name-test */ +static bool got_until_eof = FALSE; /* TRUE to signal "unterminated" */ static unsigned int last_colon_do_depth = 0; /* Local variables having to do with: */ /* ... the state of the tokenization */ -static bool is_instance = FALSE; /* Is "instance" is in effect? */ -static char *instance_filename = NULL; /* File where "instance" invoked */ -static unsigned int instance_lineno; /* Line number of "instance" */ -static bool fcode_started = FALSE ; /* Only 1 fcode_starter per block. */ -static bool first_fc_starter = TRUE; /* Only once per tokenization... */ +static bool is_instance = FALSE; /* Is "instance" is in effect? */ +static char *instance_filename = NULL; /* File where "instance" invoked */ +static unsigned int instance_lineno; /* Line number of "instance" */ +static bool fcode_started = FALSE; /* Only 1 fcode_starter per block. */ +static bool first_fc_starter = TRUE; /* Only once per tokenization... */ /* ... with the state of the input stream, */ static bool need_to_pop_source; /* ... with the use of the return stack, */ -static int ret_stk_depth = 0; /* Return-Stack-Usage-Depth counter */ +static int ret_stk_depth = 0; /* Return-Stack-Usage-Depth counter */ /* ... and with control of error-messaging. */ - /* Should a warning about a dangling "instance" + /* Should a warning about a dangling "instance" * be issued at the next device-node change? */ static bool dev_change_instance_warning = TRUE; - /* Has a gap developed between "instance" and its application? */ + /* Has a gap developed between "instance" and its application? */ static bool instance_definer_gap = FALSE; - /* ************************************************************************** * * Function name: skip_ws @@ -161,20 +159,19 @@ static bool instance_definer_gap = FALSE; static bool skip_ws(void) { - bool retval = TRUE; - char ch_tmp; + bool retval = TRUE; + char ch_tmp; - for ( ; pc < end; pc++ ) -{ - ch_tmp = *pc; - if ( (ch_tmp != '\t') && (ch_tmp != ' ') && (ch_tmp != '\n' ) ) - { - retval = FALSE; - break; + for (; pc < end; pc++) { + ch_tmp = *pc; + if ((ch_tmp != '\t') && (ch_tmp != ' ') && (ch_tmp != '\n')) { + retval = FALSE; + break; + } + if (ch_tmp == '\n') + lineno++; } - if ( ch_tmp == '\n') lineno++; - } - return ( retval ); + return (retval); } /* ************************************************************************** @@ -204,25 +201,23 @@ static bool skip_ws(void) * **************************************************************************** */ -bool skip_until( char lim_ch) +bool skip_until(char lim_ch) { - bool retval = TRUE; - char ch_tmp; - - for ( ; pc < end; pc++ ) - { - ch_tmp = *pc; - if ( ch_tmp == lim_ch ) - { - retval = FALSE; - break; - } - if ( ch_tmp == '\n') lineno++; + bool retval = TRUE; + char ch_tmp; + + for (; pc < end; pc++) { + ch_tmp = *pc; + if (ch_tmp == lim_ch) { + retval = FALSE; + break; + } + if (ch_tmp == '\n') + lineno++; } - return ( retval ); + return (retval); } - /* ************************************************************************** * * Function name: get_until @@ -270,35 +265,34 @@ bool skip_until( char lim_ch) * Involved replacing firstchar() * **************************************************************************** */ - + static signed long get_until(char needle) -{ - u8 *safe; +{ + u8 *safe; unsigned long len = 0; - safe=pc; + safe = pc; got_until_eof = skip_until(needle); len = pc - safe; - if (len >= GET_BUF_MAX ) - { - tokenization_error( TKERROR, - "get_until buffer overflow. Max is %d.\n", GET_BUF_MAX-1 ); - len = GET_BUF_MAX-1; -} + if (len >= GET_BUF_MAX) { + tokenization_error(TKERROR, + "get_until buffer overflow. Max is %d.\n", + GET_BUF_MAX - 1); + len = GET_BUF_MAX - 1; + } memcpy(statbuf, safe, len); - statbuf[len]=0; + statbuf[len] = 0; - if ( INVERSE(got_until_eof) ) -{ - if ( needle != '\n' ) pc++; + if (INVERSE(got_until_eof)) { + if (needle != '\n') + pc++; } return len; } - /* ************************************************************************** * * We are going to use a fairly sophisticated mechanism to @@ -333,22 +327,20 @@ static signed long get_until(char needle) * **************************************************************************** */ -typedef struct source_state - { - struct source_state *next; - u8 *old_start; - u8 *old_pc; - u8 *old_end; - char *old_iname; - unsigned int old_lineno; - bool pause_before_pop; - bool sav_rep_multlin; - void (*resump_func)(); - _PTR resump_param; - } source_state_t ; - -static source_state_t *saved_source = NULL; - +typedef struct source_state { + struct source_state *next; + u8 *old_start; + u8 *old_pc; + u8 *old_end; + char *old_iname; + unsigned int old_lineno; + bool pause_before_pop; + bool sav_rep_multlin; + void (*resump_func)(); + _PTR resump_param; +} source_state_t; + +static source_state_t *saved_source = NULL; /* ************************************************************************** * @@ -388,24 +380,25 @@ static source_state_t *saved_source = NULL; * **************************************************************************** */ -void push_source( void (*res_func)(), _PTR res_parm, bool file_chg ) +void push_source(void (*res_func)(), _PTR res_parm, bool file_chg) { - source_state_t *new_sav_src; - - new_sav_src = safe_malloc( sizeof(source_state_t), "pushing Source state"); - - new_sav_src->next = saved_source; - new_sav_src->old_start = start; - new_sav_src->old_pc = pc; - new_sav_src->old_end = end; - new_sav_src->old_iname = iname; - new_sav_src->old_lineno = lineno; - new_sav_src->pause_before_pop = file_chg; - new_sav_src->sav_rep_multlin = report_multiline; - new_sav_src->resump_func = res_func; - new_sav_src->resump_param = res_parm; - - saved_source = new_sav_src; + source_state_t *new_sav_src; + + new_sav_src = + safe_malloc(sizeof(source_state_t), "pushing Source state"); + + new_sav_src->next = saved_source; + new_sav_src->old_start = start; + new_sav_src->old_pc = pc; + new_sav_src->old_end = end; + new_sav_src->old_iname = iname; + new_sav_src->old_lineno = lineno; + new_sav_src->pause_before_pop = file_chg; + new_sav_src->sav_rep_multlin = report_multiline; + new_sav_src->resump_func = res_func; + new_sav_src->resump_param = res_parm; + + saved_source = new_sav_src; } /* ************************************************************************** @@ -432,12 +425,12 @@ void push_source( void (*res_func)(), _PTR res_parm, bool file_chg ) * **************************************************************************** */ -static void drop_source( void) +static void drop_source(void) { - source_state_t *former_sav_src = saved_source; + source_state_t *former_sav_src = saved_source; - saved_source = saved_source->next ; - free( former_sav_src); + saved_source = saved_source->next; + free(former_sav_src); } /* ************************************************************************** @@ -481,41 +474,36 @@ static void drop_source( void) * **************************************************************************** */ -static bool pop_source( void ) +static bool pop_source(void) { - bool retval = TRUE; - - if ( saved_source != NULL ) - { - retval = FALSE; - if ( need_to_pop_source ) - { - need_to_pop_source = FALSE; - }else{ - if ( saved_source->pause_before_pop ) - { - need_to_pop_source = TRUE; - return( retval); - } - } + bool retval = TRUE; + + if (saved_source != NULL) { + retval = FALSE; + if (need_to_pop_source) { + need_to_pop_source = FALSE; + } else { + if (saved_source->pause_before_pop) { + need_to_pop_source = TRUE; + return (retval); + } + } - if ( saved_source->resump_func != NULL ) - { - saved_source->resump_func( saved_source->resump_param); + if (saved_source->resump_func != NULL) { + saved_source->resump_func(saved_source->resump_param); + } + report_multiline = saved_source->sav_rep_multlin; + lineno = saved_source->old_lineno; + iname = saved_source->old_iname; + end = saved_source->old_end; + pc = saved_source->old_pc; + start = saved_source->old_start; + + drop_source(); } - report_multiline = saved_source->sav_rep_multlin; - lineno = saved_source->old_lineno ; - iname = saved_source->old_iname ; - end = saved_source->old_end ; - pc = saved_source->old_pc ; - start = saved_source->old_start ; - - drop_source(); - } - return( retval); + return (retval); } - /* ************************************************************************** * * Function name: get_word @@ -589,59 +577,55 @@ static bool pop_source( void ) * **************************************************************************** */ -signed long get_word( void) +signed long get_word(void) { size_t len; u8 *str; bool keep_skipping; bool pop_result; - if ( need_to_pop_source ) - { - pop_result = pop_source(); + if (need_to_pop_source) { + pop_result = pop_source(); } do { - keep_skipping = skip_ws(); - if ( keep_skipping ) - { - pop_result = pop_source(); - if ( pop_result || need_to_pop_source ) - { - statbuf[0] = 0; - if ( pop_result ) - { - return -1; - } - return 0; + keep_skipping = skip_ws(); + if (keep_skipping) { + pop_result = pop_source(); + if (pop_result || need_to_pop_source) { + statbuf[0] = 0; + if (pop_result) { + return -1; + } + return 0; + } } - } - } while ( keep_skipping ); + } while (keep_skipping); - str=pc; - while ( (str < end) && *str && *str!='\n' && *str!='\t' && *str!=' ') + str = pc; + while ((str < end) && *str && *str != '\n' && *str != '\t' + && *str != ' ') str++; - len=(size_t)(str-pc); - if (len >= GET_BUF_MAX ) - { - tokenization_error ( FATAL, - "get_word buffer overflow. Max is %d.", GET_BUF_MAX-1 ); + len = (size_t)(str - pc); + if (len >= GET_BUF_MAX) { + tokenization_error(FATAL, + "get_word buffer overflow. Max is %d.", + GET_BUF_MAX - 1); } - memcpy(statbuf, pc, len); - statbuf[len]=0; + memcpy(statbuf, pc, len); + statbuf[len] = 0; #ifdef DEBUG_SCANNER printf("%s:%d: debug: read token '%s', length=%ld\n", - iname, lineno, statbuf, len); + iname, lineno, statbuf, len); #endif - pc+=len; + pc += len; abs_token_no++; return len; } - /* ************************************************************************** * * Function name: get_word_in_line @@ -675,41 +659,37 @@ signed long get_word( void) * **************************************************************************** */ -bool get_word_in_line( char *func_nam) -{ - signed long wlen; - bool retval = TRUE; - u8 *save_pc = pc; - unsigned int save_lineno = lineno; - unsigned int save_abs_token_no = abs_token_no; - - /* Copy of function name, for error message */ - char func_cpy[FUNC_CPY_BUF_SIZE+1]; - - /* Do this first, in the likely event that func_nam was statbuf */ - if ( func_nam != NULL ) - { - strncpy( func_cpy, func_nam, FUNC_CPY_BUF_SIZE); - func_cpy[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee a null terminator */ - } - - wlen = get_word(); - if ( ( lineno != save_lineno ) || ( wlen <= 0 ) ) - { - abs_token_no = save_abs_token_no; - lineno = save_lineno; - pc = save_pc; - retval = FALSE; - if ( func_nam != NULL ) - { - tokenization_error ( TKERROR, - "Operator %s expects its target on the same line\n", - strupr(func_cpy)); +bool get_word_in_line(char *func_nam) +{ + signed long wlen; + bool retval = TRUE; + u8 *save_pc = pc; + unsigned int save_lineno = lineno; + unsigned int save_abs_token_no = abs_token_no; + + /* Copy of function name, for error message */ + char func_cpy[FUNC_CPY_BUF_SIZE + 1]; + + /* Do this first, in the likely event that func_nam was statbuf */ + if (func_nam != NULL) { + strncpy(func_cpy, func_nam, FUNC_CPY_BUF_SIZE); + func_cpy[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee a null terminator */ } - } - return ( retval ); -} + wlen = get_word(); + if ((lineno != save_lineno) || (wlen <= 0)) { + abs_token_no = save_abs_token_no; + lineno = save_lineno; + pc = save_pc; + retval = FALSE; + if (func_nam != NULL) { + tokenization_error(TKERROR, + "Operator %s expects its target on the same line\n", + strupr(func_cpy)); + } + } + return (retval); +} /* ************************************************************************** * @@ -739,29 +719,27 @@ bool get_word_in_line( char *func_nam) * **************************************************************************** */ -bool get_rest_of_line( void) +bool get_rest_of_line(void) { - bool retval = FALSE; - u8 *save_pc = pc; - unsigned int save_lineno = lineno; - unsigned int save_abs_token_no = abs_token_no; - - if ( INVERSE( skip_ws() ) ) - { - if ( lineno == save_lineno ) - { - signed long wlen = get_until('\n'); - if ( wlen > 0 ) retval = TRUE; - }else{ - abs_token_no = save_abs_token_no; - lineno = save_lineno; - pc = save_pc; + bool retval = FALSE; + u8 *save_pc = pc; + unsigned int save_lineno = lineno; + unsigned int save_abs_token_no = abs_token_no; + + if (INVERSE(skip_ws())) { + if (lineno == save_lineno) { + signed long wlen = get_until('\n'); + if (wlen > 0) + retval = TRUE; + } else { + abs_token_no = save_abs_token_no; + lineno = save_lineno; + pc = save_pc; + } } - } - return( retval); + return (retval); } - /* ************************************************************************** * * Function name: warn_unterm @@ -807,20 +785,19 @@ bool get_rest_of_line( void) **************************************************************************** */ static bool unterm_is_colon = FALSE; -void warn_unterm( int severity, char *something, unsigned int saved_lineno) +void warn_unterm(int severity, char *something, unsigned int saved_lineno) { - unsigned int tmp = lineno; - lineno = saved_lineno; - if ( unterm_is_colon ) - { - tokenization_error( severity, "Unterminated %s of %s\n", - something, strupr( last_colon_defname) ); - unterm_is_colon = FALSE; - }else{ - tokenization_error( severity, "Unterminated %s", something); - in_last_colon( TRUE); - } - lineno = tmp; + unsigned int tmp = lineno; + lineno = saved_lineno; + if (unterm_is_colon) { + tokenization_error(severity, "Unterminated %s of %s\n", + something, strupr(last_colon_defname)); + unterm_is_colon = FALSE; + } else { + tokenization_error(severity, "Unterminated %s", something); + in_last_colon(TRUE); + } + lineno = tmp; } /* ************************************************************************** @@ -856,17 +833,16 @@ void warn_unterm( int severity, char *something, unsigned int saved_lineno) * **************************************************************************** */ -void warn_if_multiline( char *something, unsigned int start_lineno ) +void warn_if_multiline(char *something, unsigned int start_lineno) { - if ( report_multiline && ( start_lineno != lineno ) ) - { - tokenization_error( WARNING, "Multi-line %s, started", something); - where_started( iname, start_lineno); - } - report_multiline = TRUE; + if (report_multiline && (start_lineno != lineno)) { + tokenization_error(WARNING, "Multi-line %s, started", + something); + where_started(iname, start_lineno); + } + report_multiline = TRUE; } - /* ************************************************************************** * * Function name: string_remark @@ -893,19 +869,16 @@ void warn_if_multiline( char *something, unsigned int start_lineno ) static void string_remark(char *errmsg_txt) { - unsigned int sav_lineno = lineno; - bool eof = skip_until('\n'); - if ( ! eof ) - { - eof = skip_ws(); - } - if ( eof ) - { - warn_unterm(WARNING, errmsg_txt, sav_lineno); + unsigned int sav_lineno = lineno; + bool eof = skip_until('\n'); + if (!eof) { + eof = skip_ws(); + } + if (eof) { + warn_unterm(WARNING, errmsg_txt, sav_lineno); } - -} +} /* Convert the given string to a number in the supplied base */ /* Allow -- and ignore -- embedded periods. */ @@ -917,24 +890,23 @@ static void string_remark(char *errmsg_txt) * the calling routine is responsible for ascertaining * the validity of the string being passed. */ -static long parse_number(u8 *start, u8 **endptr, int lbase) +static long parse_number(u8 * start, u8 ** endptr, int lbase) { long val = 0; - bool negative = FALSE ; - int curr; - u8 *nptr=start; + bool negative = FALSE; + int curr; + u8 *nptr = start; curr = *nptr; - if (curr == '-') - { - negative = TRUE ; + if (curr == '-') { + negative = TRUE; nptr++; } - + for (curr = *nptr; (curr = *nptr); nptr++) { - if ( curr == '.' ) + if (curr == '.') continue; - if ( curr >= '0' && curr <= '9') + if (curr >= '0' && curr <= '9') curr -= '0'; else if (curr >= 'a' && curr <= 'f') curr += 10 - 'a'; @@ -942,25 +914,24 @@ static long parse_number(u8 *start, u8 **endptr, int lbase) curr += 10 - 'A'; else break; - + if (curr >= lbase) break; - + val *= lbase; val += curr; } #ifdef DEBUG_SCANNER if (curr) - printf( "%s:%d: warning: couldn't parse number '%s' (%d/%d)\n", - iname, lineno, start,curr,lbase); + printf("%s:%d: warning: couldn't parse number '%s' (%d/%d)\n", + iname, lineno, start, curr, lbase); #endif if (endptr) - *endptr=nptr; + *endptr = nptr; - if (negative) - { + if (negative) { val = -val; } return val; @@ -996,14 +967,13 @@ static long parse_number(u8 *start, u8 **endptr, int lbase) * Calling routine will detect overflow. * **************************************************************************** */ - -static void add_byte_to_string( u8 nu_byte, u8 **walk ) + +static void add_byte_to_string(u8 nu_byte, u8 ** walk) { - if ( *walk - statbuf < GET_BUF_MAX ) - { - **walk = nu_byte; + if (*walk - statbuf < GET_BUF_MAX) { + **walk = nu_byte; } - (*walk)++; + (*walk)++; } /* ************************************************************************** @@ -1054,102 +1024,99 @@ static void add_byte_to_string( u8 nu_byte, u8 **walk ) * **************************************************************************** */ -static void c_string_escape( u8 **walk) +static void c_string_escape(u8 ** walk) { - char c = *pc; - u8 val; - /* We will come out of this "switch" statement - * with a value for val and a decision - * as to whether to write it. - */ - bool write_val = TRUE; - - switch (c) - { - case 'n': - /* newline */ - val = '\n'; - break; - case 't': - /* tab */ - val = '\t'; - break; - default: + char c = *pc; + u8 val; + /* We will come out of this "switch" statement + * with a value for val and a decision + * as to whether to write it. + */ + bool write_val = TRUE; + + switch (c) { + case 'n': + /* newline */ + val = '\n'; + break; + case 't': + /* tab */ + val = '\t'; + break; + default: - /* Digit-string? Convert it to a number, using the current base. - * The first non-numeric character ends the numeric sequence - * and gets swallowed up. - * If the number exceeds the size of a byte, use the truncated - * value and issue a WARNING. - * If the first character in the "digit"-string was non-numeric, - * use the character literally and issue a WARNING. - */ - - /* - * If the sequence ender is a quote, it might be the end of - * the string, or the start of a special-character or even - * of an "( ... ) hex-sequence, so don't swallow it up. - */ - { - long lval; - u8 *sav_pc = pc; - lval=parse_number(pc, &pc, base); - val = (u8)lval; + /* Digit-string? Convert it to a number, using the current base. + * The first non-numeric character ends the numeric sequence + * and gets swallowed up. + * If the number exceeds the size of a byte, use the truncated + * value and issue a WARNING. + * If the first character in the "digit"-string was non-numeric, + * use the character literally and issue a WARNING. + */ + + /* + * If the sequence ender is a quote, it might be the end of + * the string, or the start of a special-character or even + * of an "( ... ) hex-sequence, so don't swallow it up. + */ + { + long lval; + u8 *sav_pc = pc; + lval = parse_number(pc, &pc, base); + val = (u8) lval; #ifdef DEBUG_SCANNER - if (verbose) - printf( "%s:%d: debug: escape code " - "0x%x\n",iname, lineno, val); + if (verbose) + printf("%s:%d: debug: escape code " + "0x%x\n", iname, lineno, val); #endif - if ( lval > 0x0ff ) - { - tokenization_error ( WARNING, - "Numeric String after \\ overflows byte. " - "Using 0x%02x.\n", val); + if (lval > 0x0ff) { + tokenization_error(WARNING, + "Numeric String after \\ overflows byte. " + "Using 0x%02x.\n", val); } - if ( pc == sav_pc ) - { - /* NOTE: Here, PC hasn't been advanced past its - * saved value, so we can count on C remaining - * unchanged since the start of the routine. - */ - /* Don't use the null-byte at the end of the buffer */ - if ( ( pc >= end ) - /* or a sequence-ending quote. */ - || ( c == '"' ) ) - { - write_val = FALSE; - }else{ - /* In the WARNING message, print the character - * if it's printable or show it in hex - * if it's not. - */ - if ( (c > 0x20 ) && ( c <= 0x7e) ) - { - tokenization_error ( WARNING, - "Unrecognized character, %c, " - "after \\ in string. " - "Using it literally.\n", c); - }else{ - tokenization_error ( WARNING, - "Unrecognized character, 0x%02x, " - "after \\ in string. " - "Using it literally.\n", c); + if (pc == sav_pc) { + /* NOTE: Here, PC hasn't been advanced past its + * saved value, so we can count on C remaining + * unchanged since the start of the routine. + */ + /* Don't use the null-byte at the end of the buffer */ + if ((pc >= end) + /* or a sequence-ending quote. */ + || (c == '"')) { + write_val = FALSE; + } else { + /* In the WARNING message, print the character + * if it's printable or show it in hex + * if it's not. + */ + if ((c > 0x20) && (c <= 0x7e)) { + tokenization_error(WARNING, + "Unrecognized character, %c, " + "after \\ in string. " + "Using it literally.\n", + c); + } else { + tokenization_error(WARNING, + "Unrecognized character, 0x%02x, " + "after \\ in string. " + "Using it literally.\n", + c); + } + val = c; + } + } + /* NOTE: Here, however, PC may have been advanced... */ + /* Don't swallow the sequence-ender if it's a quote. */ + if (*pc == '"') { + pc--; } - val = c; - } - } - /* NOTE: Here, however, PC may have been advanced... */ - /* Don't swallow the sequence-ender if it's a quote. */ - if ( *pc == '"' ) - { - pc--; - } - } /* End of the "default" clause */ - } /* End of the "switch" statement */ + } /* End of the "default" clause */ + } /* End of the "switch" statement */ - if ( write_val ) add_byte_to_string( val, walk ); + if (write_val) + add_byte_to_string(val, walk); } @@ -1238,68 +1205,61 @@ static void c_string_escape( u8 **walk) * **************************************************************************** */ -static bool get_sequence(u8 **walk) +static bool get_sequence(u8 ** walk) { - int pv_indx = 0; - bool retval = FALSE; /* "Abnormal Completion" indicator */ - bool ready_to_parse = FALSE; - char next_ch; - char pval[3]; + int pv_indx = 0; + bool retval = FALSE; /* "Abnormal Completion" indicator */ + bool ready_to_parse = FALSE; + char next_ch; + char pval[3]; #ifdef DEBUG_SCANNER printf("%s:%d: debug: hex field:", iname, lineno); #endif - pval[2]=0; - - while ( pc < end ) - { - next_ch = *pc; - if ( next_ch == ')' ) - { - retval = TRUE; - break; - } - if ( hex_remark_escape ) - { - if ( next_ch == '\\' ) - { - string_remark("string hex-sequence remark"); - continue; - } - } - if ( isxdigit(next_ch) ) - { - pval[pv_indx] = next_ch; - if ( pv_indx == 0 ) - { - pv_indx++; - }else{ - ready_to_parse = TRUE; - } - }else{ - if ( next_ch == '\n' ) lineno++ ; - if ( pv_indx != 0 ) - { - pval[1] = 0; - ready_to_parse = TRUE; - } - } - if ( ready_to_parse ) - { - u8 val = parse_number(pval, NULL, 16); - *((*walk)++)=val; + pval[2] = 0; + + while (pc < end) { + next_ch = *pc; + if (next_ch == ')') { + retval = TRUE; + break; + } + if (hex_remark_escape) { + if (next_ch == '\\') { + string_remark("string hex-sequence remark"); + continue; + } + } + if (isxdigit(next_ch)) { + pval[pv_indx] = next_ch; + if (pv_indx == 0) { + pv_indx++; + } else { + ready_to_parse = TRUE; + } + } else { + if (next_ch == '\n') + lineno++; + if (pv_indx != 0) { + pval[1] = 0; + ready_to_parse = TRUE; + } + } + if (ready_to_parse) { + u8 val = parse_number(pval, NULL, 16); + *((*walk)++) = val; #ifdef DEBUG_SCANNER - printf(" %02x",val); + printf(" %02x", val); #endif - pv_indx = 0; - ready_to_parse = FALSE; + pv_indx = 0; + ready_to_parse = FALSE; + } + pc++; } - pc++; - } #ifdef DEBUG_SCANNER printf("\n"); #endif - return ( retval ); + return (retval); } /* ************************************************************************** @@ -1331,14 +1291,14 @@ static bool get_sequence(u8 **walk) * ************************************************************************** */ -static signed long get_string( bool pack_str) +static signed long get_string(bool pack_str) { u8 *walk; unsigned long len; char c; bool run = TRUE; - unsigned long start_lineno = lineno; /* For warning message */ - + unsigned long start_lineno = lineno; /* For warning message */ + /* * Bump past the single whitespace character that delimits * the command -- e.g., ." or " or suchlike -- that @@ -1346,63 +1306,61 @@ static signed long get_string( bool pack_str) * -delimiting whitespace character. Regard any sub- * sequent whitespace characters as part of the string */ - if ( *pc == '\n' ) lineno++; + if (*pc == '\n') + lineno++; pc++; - got_until_eof = TRUE ; + got_until_eof = TRUE; - walk=statbuf; + walk = statbuf; while (run) { - switch ((c=*pc)) - { - /* Standard use of '"' (Quote) for special-char escape */ - case '\"': + switch ((c = *pc)) { + /* Standard use of '"' (Quote) for special-char escape */ + case '\"': /* Skip the '"' (Quote) */ - pc++; + pc++; /* End of the buffer also ends the string cleanly */ - if ( pc >= end ) - { - run = FALSE; - got_until_eof = FALSE ; + if (pc >= end) { + run = FALSE; + got_until_eof = FALSE; break; } /* Pick up the next char after the '"' (Quote) */ - c=*pc; - switch (c) - { - case '(': - pc++; /* skip the '(' */ + c = *pc; + switch (c) { + case '(': + pc++; /* skip the '(' */ run = get_sequence(&walk); break; case 'n': - add_byte_to_string( '\n', &walk); + add_byte_to_string('\n', &walk); break; case 'r': - add_byte_to_string( '\r', &walk); + add_byte_to_string('\r', &walk); break; case 't': - add_byte_to_string( '\t', &walk); + add_byte_to_string('\t', &walk); break; case 'f': - add_byte_to_string( '\f', &walk); + add_byte_to_string('\f', &walk); break; case 'l': - add_byte_to_string( '\n', &walk); + add_byte_to_string('\n', &walk); break; case 'b': - add_byte_to_string( 0x08, &walk); + add_byte_to_string(0x08, &walk); break; case '!': - add_byte_to_string( 0x07, &walk); + add_byte_to_string(0x07, &walk); break; case '^': - pc++; /* Skip the up-arrow (Caret) */ - add_byte_to_string( *pc & 0x1f , &walk); + pc++; /* Skip the up-arrow (Caret) */ + add_byte_to_string(*pc & 0x1f, &walk); break; - /* We're done after any of the whitespace - * characters follows a quote. - */ + /* We're done after any of the whitespace + * characters follows a quote. + */ case ' ': case '\t': /* Advance past the terminating whitespace @@ -1410,32 +1368,31 @@ static signed long get_string( bool pack_str) * Let get_word() handle that. */ pc++; - case '\n': - run=FALSE; - got_until_eof = FALSE ; + case '\n': + run = FALSE; + got_until_eof = FALSE; break; default: /* Control allowability of Quote-Backslash * as a String-Remark by means of a * command-line switch. */ - if ( string_remark_escape ) - { - if ( c == '\\' ) - { - string_remark("string-escape remark"); - /* The first non-blank in the new line - * has not been processed yet. - * Back up to allow it to be. - */ - pc--; - break; - } + if (string_remark_escape) { + if (c == '\\') { + string_remark + ("string-escape remark"); + /* The first non-blank in the new line + * has not been processed yet. + * Back up to allow it to be. + */ + pc--; + break; + } } - add_byte_to_string( c, &walk); + add_byte_to_string(c, &walk); } break; - case '\n': + case '\n': /* Allow strings to cross lines. Include the * newline in the string. Account for it. */ @@ -1444,58 +1401,54 @@ static signed long get_string( bool pack_str) /* Control allowability of C-style escape-character * syntax by means of a command-line switch. */ - if ( c_style_string_escape ) - { - if ( c == '\\' ) - { - pc++; - c_string_escape(&walk ); - break; - } + if (c_style_string_escape) { + if (c == '\\') { + pc++; + c_string_escape(&walk); + break; + } } - add_byte_to_string( c, &walk); + add_byte_to_string(c, &walk); } /* Advance past the char processed, unless we're done. */ - if ( run ) pc++; + if (run) + pc++; /* Done if we hit end of file before string was concluded */ - if ( pc >= end ) - { - run = FALSE; - if ( got_until_eof ) - { - warn_unterm( WARNING, "string", start_lineno); - /* Prevent multiple messages for one error */ - got_until_eof = FALSE; - } + if (pc >= end) { + run = FALSE; + if (got_until_eof) { + warn_unterm(WARNING, "string", start_lineno); + /* Prevent multiple messages for one error */ + got_until_eof = FALSE; + } } } - - warn_if_multiline( "string", start_lineno); + + warn_if_multiline("string", start_lineno); len = walk - statbuf; - if (len >= GET_BUF_MAX ) - { - tokenization_error ( TKERROR, - "get_string buffer overflow. Max is %d\n.", GET_BUF_MAX-1 ); - len = GET_BUF_MAX-1; + if (len >= GET_BUF_MAX) { + tokenization_error(TKERROR, + "get_string buffer overflow. Max is %d\n.", + GET_BUF_MAX - 1); + len = GET_BUF_MAX - 1; } #ifdef DEBUG_SCANNER if (verbose) - printf("%s:%d: debug: scanned string: '%s'\n", - iname, lineno, statbuf); + printf("%s:%d: debug: scanned string: '%s'\n", + iname, lineno, statbuf); #endif - if ( pack_str && (len > STRING_LEN_MAX) ) - { - tokenization_error ( WARNING, - "String length being truncated to %d.\n", STRING_LEN_MAX ); - len = STRING_LEN_MAX; + if (pack_str && (len > STRING_LEN_MAX)) { + tokenization_error(WARNING, + "String length being truncated to %d.\n", + STRING_LEN_MAX); + len = STRING_LEN_MAX; } statbuf[len] = 0; - return len ; + return len; } - /* ************************************************************************** * * Function name: handle_user_message @@ -1537,60 +1490,57 @@ static signed long get_string( bool pack_str) * **************************************************************************** */ -static void handle_user_message( char delim, bool print_it ) +static void handle_user_message(char delim, bool print_it) { - signed long wlen; - unsigned int start_lineno = lineno; - unsigned int multiline_start = lineno; /* For warning message */ - bool check_multiline = FALSE; - const char *ug_msg = "user-generated message"; - - if ( delim == '"' ) - { - wlen = get_string( FALSE); - }else{ - /* - * When the message-delimiter is a new-line, and the - * command-delimiter was a new-line, it means the - * string length is zero; we won't bump the PC. - * Otherwise, we will honor the convention we extend - * to .( whereby, if the command is delimited - * by a new-line, we allow the string to begin - * on the next line. - */ - if ( delim == '\n' ) - { - if ( *pc != '\n') pc++; - }else{ - if ( *pc == '\n' ) lineno++; - pc++; - multiline_start = lineno; - check_multiline = TRUE; + signed long wlen; + unsigned int start_lineno = lineno; + unsigned int multiline_start = lineno; /* For warning message */ + bool check_multiline = FALSE; + const char *ug_msg = "user-generated message"; + + if (delim == '"') { + wlen = get_string(FALSE); + } else { + /* + * When the message-delimiter is a new-line, and the + * command-delimiter was a new-line, it means the + * string length is zero; we won't bump the PC. + * Otherwise, we will honor the convention we extend + * to .( whereby, if the command is delimited + * by a new-line, we allow the string to begin + * on the next line. + */ + if (delim == '\n') { + if (*pc != '\n') + pc++; + } else { + if (*pc == '\n') + lineno++; + pc++; + multiline_start = lineno; + check_multiline = TRUE; + } + wlen = get_until(delim); } - wlen = get_until( delim ); - } - - if ( print_it ) - { - unsigned int tmp_lineno = lineno; - lineno = start_lineno; - /* Don't add a new-line to body of the message. - * Routine already takes care of that. - * Besides, buffer might be full... - */ - tokenization_error( MESSAGE, statbuf); - lineno = tmp_lineno; - } - - if ( got_until_eof ) /* Crude but effective retrofit... */ - { - warn_unterm(WARNING, (char *)ug_msg, start_lineno); - }else{ - if ( check_multiline ) - { - warn_if_multiline( (char *)ug_msg, multiline_start); + + if (print_it) { + unsigned int tmp_lineno = lineno; + lineno = start_lineno; + /* Don't add a new-line to body of the message. + * Routine already takes care of that. + * Besides, buffer might be full... + */ + tokenization_error(MESSAGE, statbuf); + lineno = tmp_lineno; + } + + if (got_until_eof) { /* Crude but effective retrofit... */ + warn_unterm(WARNING, (char *)ug_msg, start_lineno); + } else { + if (check_multiline) { + warn_if_multiline((char *)ug_msg, multiline_start); + } } - } } /* ************************************************************************** @@ -1623,10 +1573,10 @@ static void handle_user_message( char delim, bool print_it ) * **************************************************************************** */ -void user_message( tic_param_t pfield ) +void user_message(tic_param_t pfield) { - char delim = (char)pfield.fw_token ; - handle_user_message( delim, TRUE); + char delim = (char)pfield.fw_token; + handle_user_message(delim, TRUE); } /* ************************************************************************** @@ -1654,14 +1604,12 @@ void user_message( tic_param_t pfield ) * **************************************************************************** */ -void skip_user_message( tic_param_t pfield ) +void skip_user_message(tic_param_t pfield) { - char delim = (char)pfield.deflt_elem ; - handle_user_message( delim, FALSE); + char delim = (char)pfield.deflt_elem; + handle_user_message(delim, FALSE); } - - /* ************************************************************************** * * Function name: get_number @@ -1689,30 +1637,29 @@ void skip_user_message( tic_param_t pfield ) * **************************************************************************** */ -bool get_number( long *result) +bool get_number(long *result) { - u8 *until; - long val; - bool retval = FALSE ; + u8 *until; + long val; + bool retval = FALSE; + + val = parse_number(statbuf, &until, base); - val = parse_number(statbuf, &until, base); - #ifdef DEBUG_SCANNER - printf("%s:%d: debug: parsing number: base 0x%x, val 0x%lx, " - "processed %ld of %ld bytes\n", iname, lineno, - base, val,(size_t)(until-statbuf), strlen((char *)statbuf)); + printf("%s:%d: debug: parsing number: base 0x%x, val 0x%lx, " + "processed %ld of %ld bytes\n", iname, lineno, + base, val, (size_t)(until - statbuf), strlen((char *)statbuf)); #endif - /* If number-parsing ended before the end of the input word, - * then the input word was not a valid number. - */ - if (until==(statbuf+strlen((char *)statbuf))) - { - *result=val; - retval = TRUE; - } + /* If number-parsing ended before the end of the input word, + * then the input word was not a valid number. + */ + if (until == (statbuf + strlen((char *)statbuf))) { + *result = val; + retval = TRUE; + } - return ( retval ); + return (retval); } /* ************************************************************************** @@ -1741,15 +1688,15 @@ bool get_number( long *result) * **************************************************************************** */ -static void deliver_number( long numval) +static void deliver_number(long numval) { - if ( in_tokz_esc ) - { - dpush( numval ); - } else { - emit_literal(numval); - } + if (in_tokz_esc) { + dpush(numval); + } else { + emit_literal(numval); + } } + /* ************************************************************************** * * Function name: handle_number @@ -1770,18 +1717,17 @@ static void deliver_number( long numval) * **************************************************************************** */ -static bool handle_number( void ) +static bool handle_number(void) { - bool retval ; - long numval; + bool retval; + long numval; - retval = get_number( &numval ); - if ( retval ) - { - deliver_number( numval ); - } + retval = get_number(&numval); + if (retval) { + deliver_number(numval); + } - return ( retval ); + return (retval); } /* ************************************************************************** @@ -1811,21 +1757,17 @@ static bool handle_number( void ) * **************************************************************************** */ -static void ascii_right_number( char *in_str) +static void ascii_right_number(char *in_str) { - u8 nxt_ch; - char *str_ptr = in_str; - long numval = 0; - - for ( nxt_ch = (u8)*str_ptr ; - ( nxt_ch = (u8)*str_ptr ) != 0 ; - str_ptr++ ) - { - numval = ( numval << 8 ) + nxt_ch ; - } - deliver_number( numval ); -} + u8 nxt_ch; + char *str_ptr = in_str; + long numval = 0; + for (nxt_ch = (u8) * str_ptr; (nxt_ch = (u8) * str_ptr) != 0; str_ptr++) { + numval = (numval << 8) + nxt_ch; + } + deliver_number(numval); +} /* ************************************************************************** * @@ -1850,24 +1792,24 @@ static void ascii_right_number( char *in_str) * **************************************************************************** */ -static void ascii_left_number( char *in_str) +static void ascii_left_number(char *in_str) { - u8 nxt_ch; - char *str_ptr = in_str; - long numval = 0; - int shift_amt = 24; - bool shift_over = FALSE ; - - for ( nxt_ch = (u8)*str_ptr ; - ( nxt_ch = (u8)*str_ptr ) != 0 ; - str_ptr++ ) - { - if ( shift_over ) numval <<= 8; - if ( shift_amt == 0 ) shift_over = TRUE ; - numval += ( nxt_ch << shift_amt ); - if ( shift_amt > 0 ) shift_amt -= 8; - } - deliver_number( numval ); + u8 nxt_ch; + char *str_ptr = in_str; + long numval = 0; + int shift_amt = 24; + bool shift_over = FALSE; + + for (nxt_ch = (u8) * str_ptr; (nxt_ch = (u8) * str_ptr) != 0; str_ptr++) { + if (shift_over) + numval <<= 8; + if (shift_amt == 0) + shift_over = TRUE; + numval += (nxt_ch << shift_amt); + if (shift_amt > 0) + shift_amt -= 8; + } + deliver_number(numval); } @@ -1881,7 +1823,7 @@ static void ascii_left_number( char *in_str) void init_scanner(void) { - statbuf=safe_malloc(GET_BUF_MAX, "initting scanner"); + statbuf = safe_malloc(GET_BUF_MAX, "initting scanner"); } /* ************************************************************************** @@ -1925,35 +1867,33 @@ void exit_scanner(void) * **************************************************************************** */ -static void set_hdr_flag( headeredness new_flag) +static void set_hdr_flag(headeredness new_flag) { - headeredness new_state = new_flag; - switch ( new_flag) - { + headeredness new_state = new_flag; + switch (new_flag) { case FLAG_HEADERLESS: - { - if ( always_headers ) - { new_state = FLAG_HEADERS; + { + if (always_headers) { + new_state = FLAG_HEADERS; + } + /* No break. Intentional... */ } - /* No break. Intentional... */ - } case FLAG_HEADERS: - { - if ( always_external ) - { new_state = FLAG_EXTERNAL; + { + if (always_external) { + new_state = FLAG_EXTERNAL; + } + /* No break. Intentional... */ } - /* No break. Intentional... */ - } case FLAG_EXTERNAL: - break; /* Satisfy compiler's error-checking... */ - /* No default needed here... */ - } + break; /* Satisfy compiler's error-checking... */ + /* No default needed here... */ + } - hdr_flag = new_state; + hdr_flag = new_state; } - /* ************************************************************************** * * Function name: init_scan_state @@ -1986,26 +1926,27 @@ static void set_hdr_flag( headeredness new_flag) * **************************************************************************** */ -void init_scan_state( void) +void init_scan_state(void) { - base = 0x0a; - pci_is_last_image = TRUE; - incolon = FALSE; - is_instance = FALSE; - set_hdr_flag( FLAG_HEADERLESS); - reset_fcode_ranges(); - first_fc_starter = TRUE; - if ( last_colon_filename != NULL ) free( last_colon_filename); - if ( instance_filename != NULL ) free( instance_filename); - last_colon_filename = NULL; - instance_filename = NULL; - dev_change_instance_warning = TRUE; - instance_definer_gap = FALSE; - need_to_pop_source = FALSE; - ret_stk_depth = 0; + base = 0x0a; + pci_is_last_image = TRUE; + incolon = FALSE; + is_instance = FALSE; + set_hdr_flag(FLAG_HEADERLESS); + reset_fcode_ranges(); + first_fc_starter = TRUE; + if (last_colon_filename != NULL) + free(last_colon_filename); + if (instance_filename != NULL) + free(instance_filename); + last_colon_filename = NULL; + instance_filename = NULL; + dev_change_instance_warning = TRUE; + instance_definer_gap = FALSE; + need_to_pop_source = FALSE; + ret_stk_depth = 0; } - /* ************************************************************************** * * Function name: collect_input_filename @@ -2038,24 +1979,21 @@ void init_scan_state( void) * **************************************************************************** */ -static void collect_input_filename( char **saved_nam) +static void collect_input_filename(char **saved_nam) { - bool update_lcfn = TRUE; /* Need to re-allocate? */ - if ( *saved_nam != NULL ) - { - if ( strcmp( *saved_nam, iname) == 0 ) - { - /* Last collected filename unchanged from iname */ - update_lcfn = FALSE; - }else{ - free( *saved_nam); + bool update_lcfn = TRUE; /* Need to re-allocate? */ + if (*saved_nam != NULL) { + if (strcmp(*saved_nam, iname) == 0) { + /* Last collected filename unchanged from iname */ + update_lcfn = FALSE; + } else { + free(*saved_nam); + } + } + if (update_lcfn) { + *saved_nam = strdup(iname); } - } - if ( update_lcfn ) - { - *saved_nam = strdup(iname); - } -} +} /* ************************************************************************** * @@ -2092,32 +2030,29 @@ static void collect_input_filename( char **saved_nam) * **************************************************************************** */ -static bool test_in_colon ( char *wname, - bool sb_in_colon, /* "Should Be IN colon" */ - int severity, - char *use_instead) +static bool test_in_colon(char *wname, bool sb_in_colon, /* "Should Be IN colon" */ + int severity, char *use_instead) { - bool is_wrong; - bool retval = TRUE ; - - is_wrong = BOOLVAL(( sb_in_colon != FALSE ) != ( incolon != FALSE )) ; - if ( is_wrong ) - { - char *ui_pt1 = ""; - char *ui_pt2 = ""; - char *ui_pt3 = ""; - retval = FALSE; - if ( use_instead != NULL ) - { - ui_pt1 = " Use "; - ui_pt2 = use_instead; - ui_pt3 = " instead."; + bool is_wrong; + bool retval = TRUE; + + is_wrong = BOOLVAL((sb_in_colon != FALSE) != (incolon != FALSE)); + if (is_wrong) { + char *ui_pt1 = ""; + char *ui_pt2 = ""; + char *ui_pt3 = ""; + retval = FALSE; + if (use_instead != NULL) { + ui_pt1 = " Use "; + ui_pt2 = use_instead; + ui_pt3 = " instead."; + } + tokenization_error(severity, "The word %s should not be used " + "%sside of a colon definition.%s%s%s\n", + strupr(wname), sb_in_colon ? "out" : "in", + ui_pt1, ui_pt2, ui_pt3); } - tokenization_error ( severity, "The word %s should not be used " - "%sside of a colon definition.%s%s%s\n", strupr(wname), - sb_in_colon ? "out" : "in", ui_pt1, ui_pt2, ui_pt3 ); - } - return ( retval ); + return (retval); } /* ************************************************************************** @@ -2131,37 +2066,33 @@ static bool test_in_colon ( char *wname, * **************************************************************************** */ -static void must_be_deep_in_do( int how_deep ) +static void must_be_deep_in_do(int how_deep) { - int functional_depth = do_loop_depth; - if ( incolon ) - { - functional_depth -= last_colon_do_depth; - } - if ( functional_depth < how_deep ) - { - char deep_do[64] = ""; - int indx; - bool prefix = FALSE; - - for ( indx = 0; indx < how_deep ; indx ++ ) - { - strcat( deep_do, "DO ... "); - } - for ( indx = 0; indx < how_deep ; indx ++ ) - { - if ( prefix ) - { - strcat( deep_do, " ... "); - } - strcat( deep_do, "LOOP"); - prefix = TRUE; + int functional_depth = do_loop_depth; + if (incolon) { + functional_depth -= last_colon_do_depth; } + if (functional_depth < how_deep) { + char deep_do[64] = ""; + int indx; + bool prefix = FALSE; + + for (indx = 0; indx < how_deep; indx++) { + strcat(deep_do, "DO ... "); + } + for (indx = 0; indx < how_deep; indx++) { + if (prefix) { + strcat(deep_do, " ... "); + } + strcat(deep_do, "LOOP"); + prefix = TRUE; + } - tokenization_error( TKERROR, - "%s outside of %s structure", strupr(statbuf), deep_do); - in_last_colon( TRUE); - } + tokenization_error(TKERROR, + "%s outside of %s structure", + strupr(statbuf), deep_do); + in_last_colon(TRUE); + } } @@ -2219,12 +2150,11 @@ static void must_be_deep_in_do( int how_deep ) * **************************************************************************** */ -static void bump_ret_stk_depth( int bump) +static void bump_ret_stk_depth(int bump) { - ret_stk_depth += bump; + ret_stk_depth += bump; } - /* ************************************************************************** * * Function name: ret_stk_balance_rpt @@ -2278,25 +2208,24 @@ static void bump_ret_stk_depth( int bump) * **************************************************************************** */ -static void ret_stk_balance_rpt( char *before_what, bool clear_it) +static void ret_stk_balance_rpt(char *before_what, bool clear_it) { - if ( ret_stk_depth != 0 ) - { - char *what_flow = ret_stk_depth < 0 ? "deficit" : "excess" ; - char *what_phr = before_what != NULL ? before_what : strupr(statbuf); - - tokenization_error( WARNING, - "Possible Return-Stack %s before %s", what_flow, what_phr); - in_last_colon( TRUE); - - if ( clear_it ) - { - ret_stk_depth = 0; + if (ret_stk_depth != 0) { + char *what_flow = ret_stk_depth < 0 ? "deficit" : "excess"; + char *what_phr = + before_what != NULL ? before_what : strupr(statbuf); + + tokenization_error(WARNING, + "Possible Return-Stack %s before %s", + what_flow, what_phr); + in_last_colon(TRUE); + + if (clear_it) { + ret_stk_depth = 0; + } } - } } - /* ************************************************************************** * * Function name: ret_stk_access_rpt @@ -2326,20 +2255,17 @@ static void ret_stk_balance_rpt( char *before_what, bool clear_it) * **************************************************************************** */ -static void ret_stk_access_rpt( void) +static void ret_stk_access_rpt(void) { - if ( ret_stk_depth <= 0 ) - { - tokenization_error( WARNING, - "Possible Return-Stack access attempt by %s " - "without value having been placed there", - strupr(statbuf) ); - in_last_colon( TRUE); - } + if (ret_stk_depth <= 0) { + tokenization_error(WARNING, + "Possible Return-Stack access attempt by %s " + "without value having been placed there", + strupr(statbuf)); + in_last_colon(TRUE); + } } - - /* ************************************************************************** * * Function name: encode_file @@ -2354,28 +2280,26 @@ static void ret_stk_access_rpt( void) * **************************************************************************** */ -static void encode_file( const char *filename ) +static void encode_file(const char *filename) { FILE *f; size_t s; - int num_encoded=0; - - tokenization_error( INFO, "ENCODing File %s\n", filename ); - - f = open_expanded_file( filename, "rb", "encoding"); - if( f != NULL ) - { - while( (s=fread(statbuf, 1, STRING_LEN_MAX, f)) ) - { - emit_token("b(\")"); - emit_string(statbuf, s); - emit_token("encode-bytes"); - if( num_encoded ) - emit_token("encode+"); - num_encoded += s; - } - fclose( f ); - tokenization_error ( INFO, "ENCODed %d bytes.\n", num_encoded); + int num_encoded = 0; + + tokenization_error(INFO, "ENCODing File %s\n", filename); + + f = open_expanded_file(filename, "rb", "encoding"); + if (f != NULL) { + while ((s = fread(statbuf, 1, STRING_LEN_MAX, f))) { + emit_token("b(\")"); + emit_string(statbuf, s); + emit_token("encode-bytes"); + if (num_encoded) + emit_token("encode+"); + num_encoded += s; + } + fclose(f); + tokenization_error(INFO, "ENCODed %d bytes.\n", num_encoded); } } @@ -2419,26 +2343,24 @@ static void encode_file( const char *filename ) * **************************************************************************** */ -void check_name_length( signed long wlen ) +void check_name_length(signed long wlen) { - if ( wlen > 31 ) - { - int severity = TKERROR; - if ( in_tokz_esc ) - { severity = INFO; - }else{ - if (hdr_flag == FLAG_HEADERLESS) - { severity = WARNING; - } + if (wlen > 31) { + int severity = TKERROR; + if (in_tokz_esc) { + severity = INFO; + } else { + if (hdr_flag == FLAG_HEADERLESS) { + severity = WARNING; + } + } + tokenization_error(severity, + "ANSI Forth does not permit definition of names " + "longer than 31 characters.\n"); } - tokenization_error( severity, - "ANSI Forth does not permit definition of names " - "longer than 31 characters.\n" ); - } } - /* ************************************************************************** * * Function name: definer_name @@ -2463,50 +2385,48 @@ void check_name_length( signed long wlen ) bool definer_name(fwtoken definer, char **reslt_ptr) { - bool retval = TRUE; - switch (definer) - { + bool retval = TRUE; + switch (definer) { case VARIABLE: - *reslt_ptr = "VARIABLE"; - break; + *reslt_ptr = "VARIABLE"; + break; case DEFER: - *reslt_ptr = "DEFER"; - break; + *reslt_ptr = "DEFER"; + break; case VALUE: - *reslt_ptr = "VALUE"; - break; + *reslt_ptr = "VALUE"; + break; case BUFFER: - *reslt_ptr = "BUFFER"; - break; + *reslt_ptr = "BUFFER"; + break; case CONST: - *reslt_ptr = "CONSTANT"; - break; + *reslt_ptr = "CONSTANT"; + break; case COLON: - *reslt_ptr = "COLON"; - break; + *reslt_ptr = "COLON"; + break; case CREATE: - *reslt_ptr = "CREATE"; - break; + *reslt_ptr = "CREATE"; + break; case FIELD: - *reslt_ptr = "FIELD"; - break; + *reslt_ptr = "FIELD"; + break; case MACRO_DEF: - *reslt_ptr = "MACRO"; - break; + *reslt_ptr = "MACRO"; + break; case ALIAS: - *reslt_ptr = "ALIAS"; - break; + *reslt_ptr = "ALIAS"; + break; case LOCAL_VAL: - *reslt_ptr = "Local Value name"; - break; + *reslt_ptr = "Local Value name"; + break; default: - retval = FALSE; - } + retval = FALSE; + } - return ( retval); + return (retval); } - /* ************************************************************************** * * Function name: as_a_what @@ -2539,31 +2459,30 @@ bool definer_name(fwtoken definer, char **reslt_ptr) * **************************************************************************** */ -bool as_a_what( fwtoken definer, char *as_what) +bool as_a_what(fwtoken definer, char *as_what) { - char *defn_type_name; - bool retval = definer_name(definer, &defn_type_name); - if ( retval ) - { - strcat( as_what, "as a"); - /* Handle article preceding definer name - * that starts with a vowel. - */ - /* HACK: Only one definer name -- ALIAS -- - * begins with a vowel. Take advantage - * of that... - * Otherwise, we'd need to do something involving - * strchr( "AEIOU", defn_type_name[0] ) - */ - if ( definer == ALIAS ) strcat( as_what, "n" ); + char *defn_type_name; + bool retval = definer_name(definer, &defn_type_name); + if (retval) { + strcat(as_what, "as a"); + /* Handle article preceding definer name + * that starts with a vowel. + */ + /* HACK: Only one definer name -- ALIAS -- + * begins with a vowel. Take advantage + * of that... + * Otherwise, we'd need to do something involving + * strchr( "AEIOU", defn_type_name[0] ) + */ + if (definer == ALIAS) + strcat(as_what, "n"); - strcat( as_what, " "); - strcat( as_what, defn_type_name); - } - return( retval); + strcat(as_what, " "); + strcat(as_what, defn_type_name); + } + return (retval); } - /* ************************************************************************** * * Function name: lookup_word @@ -2645,70 +2564,61 @@ bool as_a_what( fwtoken definer, char *as_what) static char lookup_where_pt1_buf[AS_WHAT_BUF_SIZE]; -tic_hdr_t *lookup_word( char *stat_name, char **where_pt1, char **where_pt2 ) +tic_hdr_t *lookup_word(char *stat_name, char **where_pt1, char **where_pt2) { - tic_hdr_t *found = NULL; - bool trail_space = TRUE; - bool doing_lookup = BOOLVAL( ( where_pt1 != NULL ) - && ( where_pt2 != NULL ) ); - char *temp_where_pt2 = "in the core vocabulary.\n"; - - lookup_where_pt1_buf[0] = 0; /* Init'lz part-1 buffer */ - - /* "Core vocab" refers both to shared fwords and built-in tokens. */ - - /* Distinguish between "Normal" and "Tokenizer Escape" mode */ - if ( in_tokz_esc ) - { /* "Tokenizer Escape" mode. */ - found = lookup_tokz_esc( stat_name); - if ( found != NULL ) - { - temp_where_pt2 = in_tkz_esc_mode; - }else{ - /* "Core vocabulary". */ - found = lookup_shared_word( stat_name); - } - }else{ - /* "Normal" tokenization mode */ - if ( ibm_locals ) - { - found = lookup_local( stat_name); - if ( doing_lookup && ( found != NULL ) ) - { - trail_space = FALSE; - temp_where_pt2 = ".\n"; - } - } + tic_hdr_t *found = NULL; + bool trail_space = TRUE; + bool doing_lookup = BOOLVAL((where_pt1 != NULL) + && (where_pt2 != NULL)); + char *temp_where_pt2 = "in the core vocabulary.\n"; + + lookup_where_pt1_buf[0] = 0; /* Init'lz part-1 buffer */ + + /* "Core vocab" refers both to shared fwords and built-in tokens. */ + + /* Distinguish between "Normal" and "Tokenizer Escape" mode */ + if (in_tokz_esc) { /* "Tokenizer Escape" mode. */ + found = lookup_tokz_esc(stat_name); + if (found != NULL) { + temp_where_pt2 = in_tkz_esc_mode; + } else { + /* "Core vocabulary". */ + found = lookup_shared_word(stat_name); + } + } else { + /* "Normal" tokenization mode */ + if (ibm_locals) { + found = lookup_local(stat_name); + if (doing_lookup && (found != NULL)) { + trail_space = FALSE; + temp_where_pt2 = ".\n"; + } + } - if ( found == NULL ) - { - found = lookup_in_dev_node( stat_name); - if ( found != NULL ) - { - if ( doing_lookup ) - { - temp_where_pt2 = in_what_node( current_device_node); + if (found == NULL) { + found = lookup_in_dev_node(stat_name); + if (found != NULL) { + if (doing_lookup) { + temp_where_pt2 = + in_what_node(current_device_node); + } + } else { + /* "Core vocabulary". */ + found = lookup_core_word(stat_name); + } } - }else{ - /* "Core vocabulary". */ - found = lookup_core_word( stat_name); - } } - } - - if ( ( doing_lookup ) && ( found != NULL ) ) - { - if ( as_a_what( found->fword_defr, lookup_where_pt1_buf) ) - { - if ( trail_space ) - { - strcat(lookup_where_pt1_buf, " "); - } + + if ((doing_lookup) && (found != NULL)) { + if (as_a_what(found->fword_defr, lookup_where_pt1_buf)) { + if (trail_space) { + strcat(lookup_where_pt1_buf, " "); + } + } + *where_pt1 = lookup_where_pt1_buf; + *where_pt2 = temp_where_pt2; } - *where_pt1 = lookup_where_pt1_buf; - *where_pt2 = temp_where_pt2; - } - return( found); + return (found); } /* ************************************************************************** @@ -2743,17 +2653,16 @@ tic_hdr_t *lookup_word( char *stat_name, char **where_pt1, char **where_pt2 ) * **************************************************************************** */ -bool word_exists( char *stat_name, char **where_pt1, char **where_pt2 ) +bool word_exists(char *stat_name, char **where_pt1, char **where_pt2) { - bool retval = FALSE; - tic_hdr_t *found = lookup_word( stat_name, where_pt1, where_pt2 ); + bool retval = FALSE; + tic_hdr_t *found = lookup_word(stat_name, where_pt1, where_pt2); - if ( found != NULL ) - { - retval = TRUE; - } + if (found != NULL) { + retval = TRUE; + } - return( retval); + return (retval); } /* ************************************************************************** @@ -2801,24 +2710,21 @@ bool word_exists( char *stat_name, char **where_pt1, char **where_pt2 ) * **************************************************************************** */ -void warn_if_duplicate( char *stat_name) +void warn_if_duplicate(char *stat_name) { - if ( verbose_dup_warning && do_not_overload ) - { - char *where_pt1; - char *where_pt2; - if ( word_exists( stat_name, &where_pt1, &where_pt2) ) - { - tokenization_error( WARNING, - "Duplicate definition: %s already exists %s%s", - stat_name, where_pt1, where_pt2 ); - show_node_start(); + if (verbose_dup_warning && do_not_overload) { + char *where_pt1; + char *where_pt2; + if (word_exists(stat_name, &where_pt1, &where_pt2)) { + tokenization_error(WARNING, + "Duplicate definition: %s already exists %s%s", + stat_name, where_pt1, where_pt2); + show_node_start(); + } } - } - do_not_overload = TRUE; + do_not_overload = TRUE; } - /* ************************************************************************** * * Function name: glob_not_allowed @@ -2840,17 +2746,15 @@ void warn_if_duplicate( char *stat_name) * **************************************************************************** */ -static void glob_not_allowed( int severity, bool not_ignoring) +static void glob_not_allowed(int severity, bool not_ignoring) { - tokenization_error( severity, "Global Scope is in effect; " - "%s not allowed. %s.\n", - strupr(statbuf), - not_ignoring ? - "Attempting to compensate.." : - "Ignoring" ); + tokenization_error(severity, "Global Scope is in effect; " + "%s not allowed. %s.\n", + strupr(statbuf), + not_ignoring ? + "Attempting to compensate.." : "Ignoring"); } - /* ************************************************************************** * * Function name: not_in_dict @@ -2867,10 +2771,10 @@ static void glob_not_allowed( int severity, bool not_ignoring) * **************************************************************************** */ -static void not_in_dict( char *stat_name) +static void not_in_dict(char *stat_name) { - tokenization_error ( TKERROR, - "Word %s is not in dictionary.\n", stat_name); + tokenization_error(TKERROR, + "Word %s is not in dictionary.\n", stat_name); } /* ************************************************************************** @@ -2909,40 +2813,37 @@ static void not_in_dict( char *stat_name) * **************************************************************************** */ -static void tokenized_word_error( char *stat_name) +static void tokenized_word_error(char *stat_name) { - char *where_pt1; - char *where_pt2; - bool found_somewhere; - - bool sav_in_tokz_esc = in_tokz_esc; - in_tokz_esc = INVERSE(sav_in_tokz_esc); - - traced_name_error( stat_name); - - found_somewhere = word_exists( stat_name, &where_pt1, &where_pt2); - if ( found_somewhere ) - { - tokenization_error ( TKERROR, "The word %s is %s recognized " - "in tokenizer-escape mode.\n", - stat_name, sav_in_tokz_esc ? "not" : "only" ); - } else { - not_in_dict( stat_name); - } - - if ( INVERSE(exists_in_ancestor( stat_name)) ) - { - if ( found_somewhere && sav_in_tokz_esc ) - { - tokenization_error(INFO, - "%s is defined %s%s", stat_name, where_pt1, where_pt2 ); - show_node_start(); + char *where_pt1; + char *where_pt2; + bool found_somewhere; + + bool sav_in_tokz_esc = in_tokz_esc; + in_tokz_esc = INVERSE(sav_in_tokz_esc); + + traced_name_error(stat_name); + + found_somewhere = word_exists(stat_name, &where_pt1, &where_pt2); + if (found_somewhere) { + tokenization_error(TKERROR, "The word %s is %s recognized " + "in tokenizer-escape mode.\n", + stat_name, sav_in_tokz_esc ? "not" : "only"); + } else { + not_in_dict(stat_name); } - } - in_tokz_esc = sav_in_tokz_esc; -} + if (INVERSE(exists_in_ancestor(stat_name))) { + if (found_somewhere && sav_in_tokz_esc) { + tokenization_error(INFO, + "%s is defined %s%s", stat_name, + where_pt1, where_pt2); + show_node_start(); + } + } + in_tokz_esc = sav_in_tokz_esc; +} /* ************************************************************************** * @@ -2965,13 +2866,12 @@ static void tokenized_word_error( char *stat_name) * **************************************************************************** */ -static void unresolved_instance( int severity) +static void unresolved_instance(int severity) { - tokenization_error( severity, "Unresolved \"INSTANCE\"" ); - just_where_started( instance_filename, instance_lineno ); + tokenization_error(severity, "Unresolved \"INSTANCE\""); + just_where_started(instance_filename, instance_lineno); } - /* ************************************************************************** * * Function name: modified_by_instance @@ -2994,19 +2894,19 @@ static void unresolved_instance( int severity) * **************************************************************************** */ -static void modified_by_instance( fwtoken definer, bool was_modded) +static void modified_by_instance(fwtoken definer, bool was_modded) { - char *was_not = was_modded ? "was" : "not" ; - char *defn_type_name; + char *was_not = was_modded ? "was" : "not"; + char *defn_type_name; - /* No need to check the return value */ - definer_name(definer, &defn_type_name); + /* No need to check the return value */ + definer_name(definer, &defn_type_name); - tokenization_error ( WARNING, - "%s definition %s modified by \"INSTANCE\"", - defn_type_name, was_not ); - just_where_started( instance_filename, instance_lineno ); - } + tokenization_error(WARNING, + "%s definition %s modified by \"INSTANCE\"", + defn_type_name, was_not); + just_where_started(instance_filename, instance_lineno); +} /* ************************************************************************** * @@ -3047,38 +2947,33 @@ static void modified_by_instance( fwtoken definer, bool was_modded) static void validate_instance(fwtoken definer) { - if ( is_instance ) - { - bool is_error = TRUE ; - - switch ( definer) - { - case VALUE: - case VARIABLE: - case DEFER: - case BUFFER: - is_error = FALSE; - /* No default needed, likewise, no breaks; */ - /* but some compilers get upset without 'em... */ - default: - break; - } + if (is_instance) { + bool is_error = TRUE; + + switch (definer) { + case VALUE: + case VARIABLE: + case DEFER: + case BUFFER: + is_error = FALSE; + /* No default needed, likewise, no breaks; */ + /* but some compilers get upset without 'em... */ + default: + break; + } - if( is_error ) - { - modified_by_instance(definer, FALSE ); - instance_definer_gap = TRUE; - }else{ - if ( instance_definer_gap ) - { - modified_by_instance(definer, TRUE ); - } - is_instance = FALSE; - instance_definer_gap = FALSE; + if (is_error) { + modified_by_instance(definer, FALSE); + instance_definer_gap = TRUE; + } else { + if (instance_definer_gap) { + modified_by_instance(definer, TRUE); + } + is_instance = FALSE; + instance_definer_gap = FALSE; + } } - } } - /* ************************************************************************** * @@ -3175,104 +3070,96 @@ static void validate_instance(fwtoken definer) static bool create_word(fwtoken definer) { - signed long wlen; - bool retval = FALSE; - char *defn_type_name; + signed long wlen; + bool retval = FALSE; + char *defn_type_name; - /* If already inside a colon, ERROR and discontinue processing */ - /* If an alias to a definer is used, show the name of the alias */ - if ( test_in_colon(statbuf, FALSE, TKERROR, NULL) ) - { - char defn_type_buffr[32] = ""; - unsigned int old_lineno = lineno; /* For error message */ + /* If already inside a colon, ERROR and discontinue processing */ + /* If an alias to a definer is used, show the name of the alias */ + if (test_in_colon(statbuf, FALSE, TKERROR, NULL)) { + char defn_type_buffr[32] = ""; + unsigned int old_lineno = lineno; /* For error message */ - define_token = TRUE; + define_token = TRUE; - { /* Set up definition-type text for error-message */ + { /* Set up definition-type text for error-message */ - /* No need to check the return value */ - definer_name(definer, &defn_type_name); + /* No need to check the return value */ + definer_name(definer, &defn_type_name); - strcat( defn_type_buffr, defn_type_name); - strcat( defn_type_buffr, " definition"); - } - /* If in a control-structure, ERROR but continue processing */ - if ( control_stack_depth != 0 ) - { - announce_control_structs( TKERROR, defn_type_buffr, 0); - /* Leave the new token undefined. */ - define_token = FALSE; - } + strcat(defn_type_buffr, defn_type_name); + strcat(defn_type_buffr, " definition"); + } + /* If in a control-structure, ERROR but continue processing */ + if (control_stack_depth != 0) { + announce_control_structs(TKERROR, defn_type_buffr, 0); + /* Leave the new token undefined. */ + define_token = FALSE; + } - /* Get the name of the new token */ - wlen = get_word(); + /* Get the name of the new token */ + wlen = get_word(); #ifdef DEBUG_SCANNER - printf("%s:%d: debug: defined new word %s, fcode no 0x%x\n", - iname, lineno, name, nextfcode); + printf("%s:%d: debug: defined new word %s, fcode no 0x%x\n", + iname, lineno, name, nextfcode); #endif - if ( wlen <= 0 ) - { - warn_unterm( TKERROR, defn_type_buffr, old_lineno); - }else{ - bool emit_token_name = TRUE; - - /* Other Error or Warnings as applicable */ - validate_instance( definer); - - /* Bump FCode; error-check as applicable */ - assigning_fcode(); - - /* Define the new token, unless disallowed */ - add_to_current( statbuf, nextfcode, definer); - - check_name_length( wlen); - - /* Emit appropriate FCodes: Type of def'n, */ - switch ( hdr_flag ) - { - case FLAG_HEADERS: - emit_token("named-token"); - break; - - case FLAG_EXTERNAL: - emit_token("external-token"); - break; - - default: /* FLAG_HEADERLESS */ - emit_token("new-token"); - emit_token_name = FALSE; - } - - /* Emit name of token, if applicable */ - if ( emit_token_name ) - { - if ( force_tokens_case ) - { - if ( force_lower_case_tokens ) - { - strlwr( statbuf); - }else{ - strupr( statbuf); - } - } - emit_string((u8 *)statbuf, wlen); - } + if (wlen <= 0) { + warn_unterm(TKERROR, defn_type_buffr, old_lineno); + } else { + bool emit_token_name = TRUE; + + /* Other Error or Warnings as applicable */ + validate_instance(definer); + + /* Bump FCode; error-check as applicable */ + assigning_fcode(); - /* Emit the new token's FCode */ - emit_fcode(nextfcode); + /* Define the new token, unless disallowed */ + add_to_current(statbuf, nextfcode, definer); - /* Prepare FCode Assignment Counter for next definition */ - bump_fcode(); + check_name_length(wlen); - /* Declare victory */ - retval = TRUE; + /* Emit appropriate FCodes: Type of def'n, */ + switch (hdr_flag) { + case FLAG_HEADERS: + emit_token("named-token"); + break; + + case FLAG_EXTERNAL: + emit_token("external-token"); + break; + + default: /* FLAG_HEADERLESS */ + emit_token("new-token"); + emit_token_name = FALSE; + } + + /* Emit name of token, if applicable */ + if (emit_token_name) { + if (force_tokens_case) { + if (force_lower_case_tokens) { + strlwr(statbuf); + } else { + strupr(statbuf); + } + } + emit_string((u8 *) statbuf, wlen); + } + + /* Emit the new token's FCode */ + emit_fcode(nextfcode); + + /* Prepare FCode Assignment Counter for next definition */ + bump_fcode(); + + /* Declare victory */ + retval = TRUE; + } } - } - return( retval); + return (retval); } - /* ************************************************************************** * * Function name: cannot_apply @@ -3306,23 +3193,21 @@ static bool create_word(fwtoken definer) * **************************************************************************** */ -static void cannot_apply( char *func_nam, char *targ_nam, fwtoken defr) +static void cannot_apply(char *func_nam, char *targ_nam, fwtoken defr) { - char *defr_name = "" ; - char *defr_phrase = wh_defined ; + char *defr_name = ""; + char *defr_phrase = wh_defined; - if ( ! definer_name(defr, &defr_name) ) - { - defr_phrase = ""; - } + if (!definer_name(defr, &defr_name)) { + defr_phrase = ""; + } - tokenization_error ( TKERROR , - "Cannot apply %s to %s %s%s.\n", - func_nam, targ_nam, defr_phrase, defr_name ); + tokenization_error(TKERROR, + "Cannot apply %s to %s %s%s.\n", + func_nam, targ_nam, defr_phrase, defr_name); } - /* ************************************************************************** * * Function name: lookup_with_definer @@ -3355,16 +3240,16 @@ static void cannot_apply( char *func_nam, char *targ_nam, fwtoken defr) * **************************************************************************** */ -static tic_hdr_t *lookup_with_definer( char *stat_name, fwtoken *definr ) +static tic_hdr_t *lookup_with_definer(char *stat_name, fwtoken * definr) { - tic_hdr_t *retval = lookup_current( stat_name); - if ( retval != NULL ) - { - *definr = retval->fword_defr; - }else{ - if ( exists_as_local( stat_name) ) *definr = LOCAL_VAL; - } - return ( retval ); + tic_hdr_t *retval = lookup_current(stat_name); + if (retval != NULL) { + *definr = retval->fword_defr; + } else { + if (exists_as_local(stat_name)) + *definr = LOCAL_VAL; + } + return (retval); } /* ************************************************************************** @@ -3411,59 +3296,54 @@ static tic_hdr_t *lookup_with_definer( char *stat_name, fwtoken *definr ) * **************************************************************************** */ -static bool validate_to_target( void ) +static bool validate_to_target(void) { - signed long wlen; - tic_hdr_t *test_entry; - u8 *saved_pc = pc; - char *cmd_cpy = strupr( strdup( statbuf)); /* For error message */ - unsigned int saved_lineno = lineno; - unsigned int saved_abs_token_no = abs_token_no; - fwtoken defr = UNSPECIFIED ; - bool targ_err = TRUE ; - bool retval = FALSE ; - - wlen = get_word(); - if ( wlen <= 0 ) - { - warn_unterm( TKERROR, cmd_cpy, saved_lineno); - }else{ - - test_entry = lookup_with_definer( statbuf, &defr); - if ( test_entry != NULL ) - { - switch (defr) - { - case VARIABLE: - tokenization_error( WARNING, - "Applying %s to a VARIABLE (%s) is " - "not recommended; use ! instead.\n", - cmd_cpy, statbuf); - case DEFER: - case VALUE: - targ_err = FALSE ; - case CONST: - retval = TRUE ; - /* No default needed, likewise, no breaks; */ - /* but some compilers get upset without 'em... */ - default: - break; - } - } + signed long wlen; + tic_hdr_t *test_entry; + u8 *saved_pc = pc; + char *cmd_cpy = strupr(strdup(statbuf)); /* For error message */ + unsigned int saved_lineno = lineno; + unsigned int saved_abs_token_no = abs_token_no; + fwtoken defr = UNSPECIFIED; + bool targ_err = TRUE; + bool retval = FALSE; - if ( targ_err ) - { - cannot_apply(cmd_cpy, strupr(statbuf), defr ); - } + wlen = get_word(); + if (wlen <= 0) { + warn_unterm(TKERROR, cmd_cpy, saved_lineno); + } else { + + test_entry = lookup_with_definer(statbuf, &defr); + if (test_entry != NULL) { + switch (defr) { + case VARIABLE: + tokenization_error(WARNING, + "Applying %s to a VARIABLE (%s) is " + "not recommended; use ! instead.\n", + cmd_cpy, statbuf); + case DEFER: + case VALUE: + targ_err = FALSE; + case CONST: + retval = TRUE; + /* No default needed, likewise, no breaks; */ + /* but some compilers get upset without 'em... */ + default: + break; + } + } - pc = saved_pc; - lineno = saved_lineno; - abs_token_no = saved_abs_token_no; - } - free( cmd_cpy); - return( retval); -} + if (targ_err) { + cannot_apply(cmd_cpy, strupr(statbuf), defr); + } + pc = saved_pc; + lineno = saved_lineno; + abs_token_no = saved_abs_token_no; + } + free(cmd_cpy); + return (retval); +} /* ************************************************************************** * @@ -3483,14 +3363,12 @@ static bool validate_to_target( void ) * **************************************************************************** */ -static void you_are_here( void) +static void you_are_here(void) { - tokenization_error( INFO, - "%s encountered; processing...\n", - strupr(statbuf) ); + tokenization_error(INFO, + "%s encountered; processing...\n", strupr(statbuf)); } - /* ************************************************************************** * * Function name: fcode_starter @@ -3550,35 +3428,33 @@ static void you_are_here( void) * **************************************************************************** */ -static void fcode_starter( const char *token_name, int spread, bool is_offs16) +static void fcode_starter(const char *token_name, int spread, bool is_offs16) { - you_are_here(); - if ( spread != 1 ) - { - tokenization_error( WARNING, "spread of %d not supported.\n", spread); - } - if ( fcode_started ) - { - tokenization_error( WARNING, - "Only one \"FCode Starter\" permitted per tokenization. " - "Ignoring...\n"); - } else { - - emit_fcodehdr(token_name); - offs16 = is_offs16; - fcode_started = TRUE; - - current_device_node->ifile_name = strdup(iname); - current_device_node->line_no = lineno; - - if ( first_fc_starter ) - { - reset_fcode_ranges(); - first_fc_starter = FALSE; - }else{ - set_next_fcode( nextfcode); + you_are_here(); + if (spread != 1) { + tokenization_error(WARNING, "spread of %d not supported.\n", + spread); + } + if (fcode_started) { + tokenization_error(WARNING, + "Only one \"FCode Starter\" permitted per tokenization. " + "Ignoring...\n"); + } else { + + emit_fcodehdr(token_name); + offs16 = is_offs16; + fcode_started = TRUE; + + current_device_node->ifile_name = strdup(iname); + current_device_node->line_no = lineno; + + if (first_fc_starter) { + reset_fcode_ranges(); + first_fc_starter = FALSE; + } else { + set_next_fcode(nextfcode); + } } - } } /* ************************************************************************** @@ -3605,17 +3481,16 @@ static void fcode_starter( const char *token_name, int spread, bool is_offs16) * **************************************************************************** */ -static void fcode_end_err_check( void) +static void fcode_end_err_check(void) { - bool stack_imbal = BOOLVAL( stackdepth() != 0 ); + bool stack_imbal = BOOLVAL(stackdepth() != 0); - if ( stack_imbal ) - { - tokenization_error( WARNING, - "Stack imbalance before end of tokenization.\n"); + if (stack_imbal) { + tokenization_error(WARNING, + "Stack imbalance before end of tokenization.\n"); } - clear_stack(); - clear_control_structs("End of tokenization"); + clear_stack(); + clear_control_structs("End of tokenization"); } /* ************************************************************************** @@ -3674,40 +3549,36 @@ static void fcode_end_err_check( void) void fcode_ender(void) { - if ( incolon ) - { - char *tmp_iname = iname; - iname = last_colon_filename; - unterm_is_colon = TRUE; - warn_unterm( TKERROR, "Colon Definition", last_colon_lineno); - iname = tmp_iname; - } - - haveend = TRUE; - - if ( is_instance ) - { - unresolved_instance( TKERROR); - } - - if ( scope_is_global ) - { - tokenization_error( WARNING , - "No DEVICE-DEFINITIONS directive encountered before end. " - "Compensating...\n"); - resume_device_scope(); - } - fcode_end_err_check(); - reset_normal_vocabs(); - finish_fcodehdr(); - fcode_started = FALSE; - - if ( current_device_node->ifile_name != default_top_dev_ifile_name ) - { - free( current_device_node->ifile_name ); - current_device_node->ifile_name = default_top_dev_ifile_name; - current_device_node->line_no = 0; - } + if (incolon) { + char *tmp_iname = iname; + iname = last_colon_filename; + unterm_is_colon = TRUE; + warn_unterm(TKERROR, "Colon Definition", last_colon_lineno); + iname = tmp_iname; + } + + haveend = TRUE; + + if (is_instance) { + unresolved_instance(TKERROR); + } + + if (scope_is_global) { + tokenization_error(WARNING, + "No DEVICE-DEFINITIONS directive encountered before end. " + "Compensating...\n"); + resume_device_scope(); + } + fcode_end_err_check(); + reset_normal_vocabs(); + finish_fcodehdr(); + fcode_started = FALSE; + + if (current_device_node->ifile_name != default_top_dev_ifile_name) { + free(current_device_node->ifile_name); + current_device_node->ifile_name = default_top_dev_ifile_name; + current_device_node->line_no = 0; + } } /* ************************************************************************** @@ -3750,104 +3621,95 @@ void fcode_ender(void) * **************************************************************************** */ -static bool get_token(tic_hdr_t **tok_entry) +static bool get_token(tic_hdr_t ** tok_entry) { - bool retval = FALSE; - tic_hdr_t *found; - u8 *save_pc; - - /* Copy of command being processed, for error message */ - char cmnd_cpy[FUNC_CPY_BUF_SIZE+1]; - strncpy( cmnd_cpy, statbuf, FUNC_CPY_BUF_SIZE); - cmnd_cpy[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee null terminator. */ - - save_pc = pc; - - if ( get_word_in_line( statbuf) ) - { - fwtoken defr = UNSPECIFIED; - - /* We need to scan the newest definitions first; they - * might supercede standard ones. We need, though, - * to bypass built-in FWords that need to trigger - * some tokenizer internals before emitting their - * synonymous FCode Tokens, (e.g., version1 , end0 , - * and start{0-4}); if we find one of those, we will - * need to search again, specifically within the list - * of FCode Tokens. - */ - found = lookup_with_definer( statbuf, &defr); - if ( found != NULL ) - { - /* Built-in FWords can be uniquely identified by their - * definer, BI_FWRD_DEFN . The definer for "shared" - * FWords is COMMON_FWORD but there are none of - * those that might be synonymous with legitimate - * FCode Tokens, nor are any likely ever to be... - */ - if ( defr == BI_FWRD_DEFN ) - { - found = lookup_token( statbuf); - retval = BOOLVAL( found != NULL ); - }else{ - retval = entry_is_token( found); - } - } + bool retval = FALSE; + tic_hdr_t *found; + u8 *save_pc; + + /* Copy of command being processed, for error message */ + char cmnd_cpy[FUNC_CPY_BUF_SIZE + 1]; + strncpy(cmnd_cpy, statbuf, FUNC_CPY_BUF_SIZE); + cmnd_cpy[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee null terminator. */ + + save_pc = pc; + + if (get_word_in_line(statbuf)) { + fwtoken defr = UNSPECIFIED; + + /* We need to scan the newest definitions first; they + * might supercede standard ones. We need, though, + * to bypass built-in FWords that need to trigger + * some tokenizer internals before emitting their + * synonymous FCode Tokens, (e.g., version1 , end0 , + * and start{0-4}); if we find one of those, we will + * need to search again, specifically within the list + * of FCode Tokens. + */ + found = lookup_with_definer(statbuf, &defr); + if (found != NULL) { + /* Built-in FWords can be uniquely identified by their + * definer, BI_FWRD_DEFN . The definer for "shared" + * FWords is COMMON_FWORD but there are none of + * those that might be synonymous with legitimate + * FCode Tokens, nor are any likely ever to be... + */ + if (defr == BI_FWRD_DEFN) { + found = lookup_token(statbuf); + retval = BOOLVAL(found != NULL); + } else { + retval = entry_is_token(found); + } + } - handle_invocation( found); + handle_invocation(found); - if ( retval) - { - *tok_entry = found; - }else{ - cannot_apply( cmnd_cpy, strupr(statbuf), defr ); - pc = save_pc; + if (retval) { + *tok_entry = found; + } else { + cannot_apply(cmnd_cpy, strupr(statbuf), defr); + pc = save_pc; + } } - } - return ( retval ); + return (retval); } - -static void base_change ( int new_base ) +static void base_change(int new_base) { - if ( incolon && ( INVERSE( in_tokz_esc) ) ) - { - emit_literal(new_base ); - emit_token("base"); - emit_token("!"); - } else { - base = new_base; - } + if (incolon && (INVERSE(in_tokz_esc))) { + emit_literal(new_base); + emit_token("base"); + emit_token("!"); + } else { + base = new_base; + } } -static void base_val (int new_base) +static void base_val(int new_base) { - u8 *old_pc; - - char base_cmnd[FUNC_CPY_BUF_SIZE+1]; - strncpy( base_cmnd, statbuf, FUNC_CPY_BUF_SIZE); - base_cmnd[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee NULL terminator */ - - old_pc=pc; - if ( get_word_in_line( statbuf) ) - { - u8 basecpy=base; - - base = new_base; - if ( ! handle_number() ) - { - /* We did get a word on the line, but it's not a valid number */ - tokenization_error( WARNING , - "Applying %s to non-numeric value. Ignoring.\n", - strupr(base_cmnd) ); - pc = old_pc; + u8 *old_pc; + + char base_cmnd[FUNC_CPY_BUF_SIZE + 1]; + strncpy(base_cmnd, statbuf, FUNC_CPY_BUF_SIZE); + base_cmnd[FUNC_CPY_BUF_SIZE] = 0; /* Guarantee NULL terminator */ + + old_pc = pc; + if (get_word_in_line(statbuf)) { + u8 basecpy = base; + + base = new_base; + if (!handle_number()) { + /* We did get a word on the line, but it's not a valid number */ + tokenization_error(WARNING, + "Applying %s to non-numeric value. Ignoring.\n", + strupr(base_cmnd)); + pc = old_pc; + } + base = basecpy; } - base=basecpy; - } } - /* ************************************************************************** * * Function name: eval_string @@ -3883,13 +3745,12 @@ static void base_val (int new_base) * **************************************************************************** */ -void eval_string( char *inp_bufr) +void eval_string(char *inp_bufr) { - push_source( NULL, NULL, FALSE); - init_inbuf( inp_bufr, strlen(inp_bufr)); + push_source(NULL, NULL, FALSE); + init_inbuf(inp_bufr, strlen(inp_bufr)); } - /* ************************************************************************** * * Function name: finish_or_new_device @@ -3945,48 +3806,41 @@ void eval_string( char *inp_bufr) * **************************************************************************** */ -static void finish_or_new_device( bool finishing_device ) +static void finish_or_new_device(bool finishing_device) { - if ( INVERSE( incolon ) ) - { - if ( INVERSE( is_instance) ) - { - /* Arm warning for next time: */ - dev_change_instance_warning = TRUE; - }else{ - /* Dangling "instance" */ - instance_definer_gap = TRUE; - /* Warn only once. */ - if ( dev_change_instance_warning ) - { - unresolved_instance( WARNING); - dev_change_instance_warning = FALSE; - } - } + if (INVERSE(incolon)) { + if (INVERSE(is_instance)) { + /* Arm warning for next time: */ + dev_change_instance_warning = TRUE; + } else { + /* Dangling "instance" */ + instance_definer_gap = TRUE; + /* Warn only once. */ + if (dev_change_instance_warning) { + unresolved_instance(WARNING); + dev_change_instance_warning = FALSE; + } + } - /* Note: "Instance" cannot be in effect during "global" scope */ - if ( scope_is_global ) - { - glob_not_allowed( TKERROR, noerrors ); - if ( noerrors ) - { - resume_device_scope(); - }else{ - return; - } - } + /* Note: "Instance" cannot be in effect during "global" scope */ + if (scope_is_global) { + glob_not_allowed(TKERROR, noerrors); + if (noerrors) { + resume_device_scope(); + } else { + return; + } + } - if ( finishing_device ) - { - finish_device_vocab(); - }else{ - new_device_vocab(); - } - } - emit_token( finishing_device ? "finish-device" : "new-device" ); + if (finishing_device) { + finish_device_vocab(); + } else { + new_device_vocab(); + } } - - + emit_token(finishing_device ? "finish-device" : "new-device"); +} + /* ************************************************************************** * * Function name: abort_quote @@ -4050,63 +3904,62 @@ static void finish_or_new_device( bool finishing_device ) * buffer-interpretation scheme somewhat too messy for my tastes. * **************************************************************************** */ - -static bool abort_quote( fwtoken tok) + +static bool abort_quote(fwtoken tok) { - bool retval = FALSE; - if ( tok == ABORTTXT ) - { - if ( ! enable_abort_quote ) - { - /* ABORT" is not enabled; we'd better consume the string */ - char *save_statbuf; - signed long wlen; - save_statbuf = strdup( (char *)statbuf); - wlen = get_string( FALSE); - strcpy( statbuf, save_statbuf); - free( save_statbuf); - }else{ - /* ABORT" is not to be used in FCODE drivers - * but Apple drivers do use it. Therefore we - * allow it. We push the specified string to - * the stack, do -2 THROW and hope that THROW - * will correctly unwind the stack. - * Presumably, Apple Source supplies its own - * IF ... THEN - */ - char *abort_string; - signed long wlen; - - retval = TRUE; - tokenization_error (INFO, "ABORT\" in fcode not " - "defined by IEEE 1275-1994\n"); - test_in_colon("ABORT\"", TRUE, TKERROR, NULL); - wlen=get_string( TRUE); - - if ( sun_style_abort_quote ) emit_if(); - - emit_token("b(\")"); - emit_string(statbuf, wlen); - - if ( sun_style_abort_quote ) emit_token("type"); - - if ( abort_quote_throw ) - { - emit_literal( -2); - emit_token("throw"); - }else{ - emit_token("abort"); - } - - if ( sun_style_abort_quote ) emit_then(); - /* Sun Style */ - abort_string = " type -2 THROW THEN:" ; -} + bool retval = FALSE; + if (tok == ABORTTXT) { + if (!enable_abort_quote) { + /* ABORT" is not enabled; we'd better consume the string */ + char *save_statbuf; + signed long wlen; + save_statbuf = strdup((char *)statbuf); + wlen = get_string(FALSE); + strcpy(statbuf, save_statbuf); + free(save_statbuf); + } else { + /* ABORT" is not to be used in FCODE drivers + * but Apple drivers do use it. Therefore we + * allow it. We push the specified string to + * the stack, do -2 THROW and hope that THROW + * will correctly unwind the stack. + * Presumably, Apple Source supplies its own + * IF ... THEN + */ + char *abort_string; + signed long wlen; + + retval = TRUE; + tokenization_error(INFO, "ABORT\" in fcode not " + "defined by IEEE 1275-1994\n"); + test_in_colon("ABORT\"", TRUE, TKERROR, NULL); + wlen = get_string(TRUE); + + if (sun_style_abort_quote) + emit_if(); + + emit_token("b(\")"); + emit_string(statbuf, wlen); + + if (sun_style_abort_quote) + emit_token("type"); + + if (abort_quote_throw) { + emit_literal(-2); + emit_token("throw"); + } else { + emit_token("abort"); + } + + if (sun_style_abort_quote) + emit_then(); + /* Sun Style */ + abort_string = " type -2 THROW THEN:"; + } } - return( retval ); + return (retval); } - /* ************************************************************************** * * Function name: create_alias @@ -4182,86 +4035,82 @@ static bool abort_quote( fwtoken tok) * **************************************************************************** */ -static void create_alias( void ) +static void create_alias(void) { - char *new_alias ; - - validate_instance(ALIAS); - if ( incolon ) - { - tokenization_error ( WARNING, - "ALIAS during colon-definition " - "is not supported by IEEE 1275-1994\n"); -} - if ( get_word_in_line( "ALIAS") ) - { - - new_alias = strdup((char *)statbuf); + char *new_alias; - if (get_word_in_line( "ALIAS") ) -{ - char *old_name = strdup((char *)statbuf) ; - - /* - * Here is where we begin trying the create_..._alias() - * routines for the vocabularies. - */ - - /* - * Distinguish between "Normal" tokenization mode - * and "Tokenizer Escape" mode - */ - if ( in_tokz_esc ) - { - if ( create_tokz_esc_alias( new_alias, old_name) ) - return; - - /* - * Handle the classes of operatives that are common between - * "Tokenizer Escape" mode and "Normal" tokenization mode. - * Those classes include selected non-fcode forth constructs - * and Conditional-Compilation Operators. - */ - { - tic_hdr_t *found = lookup_shared_word( old_name); - if ( found != NULL ) - { - if ( create_core_alias( new_alias, old_name) ) - return; - } + validate_instance(ALIAS); + if (incolon) { + tokenization_error(WARNING, + "ALIAS during colon-definition " + "is not supported by IEEE 1275-1994\n"); } - }else{ - /* "Normal" tokenization mode */ - - /* Can create aliases for "Locals", why not? */ - if ( create_local_alias( new_alias, old_name) ) - return; + if (get_word_in_line("ALIAS")) { - /* - * All other classes of operatives -- non-fcode forth - * constructs, Standard and user-defined fcode - * tokens, Macros, and Conditional-Compilation - * Operators, -- are included in the "currently - * active" vocabulary. - */ + new_alias = strdup((char *)statbuf); + + if (get_word_in_line("ALIAS")) { + char *old_name = strdup((char *)statbuf); + + /* + * Here is where we begin trying the create_..._alias() + * routines for the vocabularies. + */ + + /* + * Distinguish between "Normal" tokenization mode + * and "Tokenizer Escape" mode + */ + if (in_tokz_esc) { + if (create_tokz_esc_alias(new_alias, old_name)) + return; + + /* + * Handle the classes of operatives that are common between + * "Tokenizer Escape" mode and "Normal" tokenization mode. + * Those classes include selected non-fcode forth constructs + * and Conditional-Compilation Operators. + */ + { + tic_hdr_t *found = + lookup_shared_word(old_name); + if (found != NULL) { + if (create_core_alias + (new_alias, old_name)) + return; + } + } + } else { + /* "Normal" tokenization mode */ + + /* Can create aliases for "Locals", why not? */ + if (create_local_alias(new_alias, old_name)) + return; + + /* + * All other classes of operatives -- non-fcode forth + * constructs, Standard and user-defined fcode + * tokens, Macros, and Conditional-Compilation + * Operators, -- are included in the "currently + * active" vocabulary. + */ - if ( create_current_alias( new_alias, old_name) ) - return; - - } /* End of separate handling for normal-tokenization mode - * versus "Tokenizer-Escape" mode - */ - - /* It's not a word, a macro or any of that other stuff. */ - trace_create_failure( new_alias, old_name, 0); - tokenized_word_error(old_name); - free(old_name); + if (create_current_alias(new_alias, old_name)) + return; + + } /* End of separate handling for normal-tokenization mode + * versus "Tokenizer-Escape" mode + */ + + /* It's not a word, a macro or any of that other stuff. */ + trace_create_failure(new_alias, old_name, 0); + tokenized_word_error(old_name); + free(old_name); + } + free(new_alias); } - free (new_alias); - } } - /* ************************************************************************** * * Function name: string_err_check @@ -4288,24 +4137,20 @@ static void create_alias( void ) * **************************************************************************** */ -static bool string_err_check( bool is_paren, - unsigned int sav_lineno, - unsigned int strt_lineno ) +static bool string_err_check(bool is_paren, + unsigned int sav_lineno, unsigned int strt_lineno) { - bool retval = noerrors ; - char *item_typ = is_paren ? - "Dot-Paren" : "Ess-Quote" ; - if ( got_until_eof ) /* Crude retrofit... */ - { - warn_unterm( TKERROR, item_typ, sav_lineno ); - }else{ - retval = TRUE; - warn_if_multiline( item_typ, strt_lineno ); + bool retval = noerrors; + char *item_typ = is_paren ? "Dot-Paren" : "Ess-Quote"; + if (got_until_eof) { /* Crude retrofit... */ + warn_unterm(TKERROR, item_typ, sav_lineno); + } else { + retval = TRUE; + warn_if_multiline(item_typ, strt_lineno); } - return( retval); + return (retval); } - /* ************************************************************************** * * Function name: handle_internal @@ -4355,22 +4200,22 @@ static bool string_err_check( bool is_paren, * **************************************************************************** */ -void handle_internal( tic_param_t pfield); -void handle_internal( tic_param_t pfield) +void handle_internal(tic_param_t pfield); +void handle_internal(tic_param_t pfield) { fwtoken tok = pfield.fw_token; signed long wlen; - unsigned int sav_lineno = lineno; /* For error message */ + unsigned int sav_lineno = lineno; /* For error message */ - bool handy_toggle = TRUE ; /* Various uses... */ - bool handy_toggle_too = TRUE ; /* Various other uses... */ + bool handy_toggle = TRUE; /* Various uses... */ + bool handy_toggle_too = TRUE; /* Various other uses... */ char *handy_string = ""; int handy_int = 0; - + #ifdef DEBUG_SCANNER printf("%s:%d: debug: tokenizing control word '%s'\n", - iname, lineno, statbuf); + iname, lineno, statbuf); #endif switch (tok) { case BEGIN: @@ -4378,88 +4223,83 @@ void handle_internal( tic_param_t pfield) break; case BUFFER: - if ( create_word(tok) ) - { - emit_token("b(buffer:)"); + if (create_word(tok)) { + emit_token("b(buffer:)"); } break; case CONST: - if ( create_word(tok) ) - { - emit_token("b(constant)"); + if (create_word(tok)) { + emit_token("b(constant)"); } break; case COLON: { - /* Collect error- -detection or -reporting items, - * but don't commit until we're sure the - * creation was a success. - */ - u16 maybe_last_colon_fcode = nextfcode ; - unsigned int maybe_last_colon_lineno = lineno; - unsigned int maybe_last_colon_abs_token_no = abs_token_no; - unsigned int maybe_last_colon_do_depth = do_loop_depth; - /* last_colon_defname - * has to wait until after call to create_word() - */ - - if ( create_word(tok) ) - { - last_colon_fcode = maybe_last_colon_fcode; - last_colon_lineno = maybe_last_colon_lineno; - last_colon_abs_token_no = maybe_last_colon_abs_token_no; - last_colon_do_depth = maybe_last_colon_do_depth; - collect_input_filename( &last_colon_filename); - /* Now we can get last_colon_defname */ - if ( last_colon_defname != NULL ) - { - free( last_colon_defname); - } - last_colon_defname = strdup(statbuf); + /* Collect error- -detection or -reporting items, + * but don't commit until we're sure the + * creation was a success. + */ + u16 maybe_last_colon_fcode = nextfcode; + unsigned int maybe_last_colon_lineno = lineno; + unsigned int maybe_last_colon_abs_token_no = + abs_token_no; + unsigned int maybe_last_colon_do_depth = do_loop_depth; + /* last_colon_defname + * has to wait until after call to create_word() + */ - emit_token("b(:)"); - incolon=TRUE; - hide_last_colon(); - lastcolon = opc; - } + if (create_word(tok)) { + last_colon_fcode = maybe_last_colon_fcode; + last_colon_lineno = maybe_last_colon_lineno; + last_colon_abs_token_no = + maybe_last_colon_abs_token_no; + last_colon_do_depth = maybe_last_colon_do_depth; + collect_input_filename(&last_colon_filename); + /* Now we can get last_colon_defname */ + if (last_colon_defname != NULL) { + free(last_colon_defname); + } + last_colon_defname = strdup(statbuf); + + emit_token("b(:)"); + incolon = TRUE; + hide_last_colon(); + lastcolon = opc; + } } break; - + case SEMICOLON: - if ( test_in_colon("SEMICOLON", TRUE, TKERROR, NULL) ) - { - ret_stk_balance_rpt( "termination,", TRUE); - /* Clear Control Structures just back to where - * the current Colon-definition began. - */ - clear_control_structs_to_limit( - "End of colon-definition", last_colon_abs_token_no); - - if ( ibm_locals ) - { - finish_locals(); - forget_locals(); - } - - emit_token("b(;)"); - incolon=FALSE; - reveal_last_colon(); + if (test_in_colon("SEMICOLON", TRUE, TKERROR, NULL)) { + ret_stk_balance_rpt("termination,", TRUE); + /* Clear Control Structures just back to where + * the current Colon-definition began. + */ + clear_control_structs_to_limit + ("End of colon-definition", + last_colon_abs_token_no); + + if (ibm_locals) { + finish_locals(); + forget_locals(); + } + + emit_token("b(;)"); + incolon = FALSE; + reveal_last_colon(); } break; case CREATE: - if ( create_word(tok) ) - { - emit_token("b(create)"); + if (create_word(tok)) { + emit_token("b(create)"); } break; case DEFER: - if ( create_word(tok) ) - { - emit_token("b(defer)"); + if (create_word(tok)) { + emit_token("b(defer)"); } break; @@ -4468,48 +4308,42 @@ void handle_internal( tic_param_t pfield) break; case OVERLOAD: - if ( test_in_colon(statbuf, FALSE, WARNING, NULL) ) - { - do_not_overload = FALSE; + if (test_in_colon(statbuf, FALSE, WARNING, NULL)) { + do_not_overload = FALSE; } break; case DEFINED: - if (get_word_in_line( statbuf) ) - { - eval_user_symbol(statbuf); + if (get_word_in_line(statbuf)) { + eval_user_symbol(statbuf); } break; case CL_FLAG: - if (get_word_in_line( statbuf) ) - { - set_cl_flag( statbuf, TRUE); + if (get_word_in_line(statbuf)) { + set_cl_flag(statbuf, TRUE); } break; case SHOW_CL_FLAGS: - show_all_cl_flag_settings( TRUE); + show_all_cl_flag_settings(TRUE); break; case FIELD: - if ( create_word(tok) ) - { - emit_token("b(field)"); + if (create_word(tok)) { + emit_token("b(field)"); } break; case VALUE: - if ( create_word(tok) ) - { - emit_token("b(value)"); + if (create_word(tok)) { + emit_token("b(value)"); } break; - + case VARIABLE: - if ( create_word(tok) ) - { - emit_token("b(variable)"); + if (create_word(tok)) { + emit_token("b(variable)"); } break; @@ -4522,9 +4356,8 @@ void handle_internal( tic_param_t pfield) break; case CONTROL: - if ( get_word_in_line( statbuf) ) - { - emit_literal(statbuf[0]&0x1f); + if (get_word_in_line(statbuf)) { + emit_literal(statbuf[0] & 0x1f); } break; @@ -4553,14 +4386,14 @@ void handle_internal( tic_param_t pfield) case NEW_DEVICE: handy_toggle = FALSE; case FINISH_DEVICE: - finish_or_new_device( handy_toggle ); + finish_or_new_device(handy_toggle); break; case FLITERAL: { - u32 val; - val = dpop(); - emit_literal(val); + u32 val; + val = dpop(); + emit_literal(val); } break; @@ -4571,42 +4404,42 @@ void handle_internal( tic_param_t pfield) case ENDOF: emit_endof(); break; - + case EXTERNAL: - set_hdr_flag( FLAG_EXTERNAL ); + set_hdr_flag(FLAG_EXTERNAL); break; - + case HEADERLESS: - set_hdr_flag( FLAG_HEADERLESS ); + set_hdr_flag(FLAG_HEADERLESS); break; - + case HEADERS: - set_hdr_flag( FLAG_HEADERS ); + set_hdr_flag(FLAG_HEADERS); break; case DECIMAL: /* in a definition this is expanded as macro "10 base !" */ - base_change ( 0x0a ); + base_change(0x0a); break; - + case HEX: - base_change ( 0x10 ); + base_change(0x10); break; case OCTAL: - base_change ( 0x08 ); + base_change(0x08); break; case OFFSET16: - if (!offs16) - { - tokenization_error(INFO, "Switching to 16-bit offsets.\n"); - }else{ - tokenization_error(WARNING, - "Call of OFFSET16 is redundant.\n"); + if (!offs16) { + tokenization_error(INFO, + "Switching to 16-bit offsets.\n"); + } else { + tokenization_error(WARNING, + "Call of OFFSET16 is redundant.\n"); } emit_token("offset16"); - offs16=TRUE; + offs16 = TRUE; break; case IF: @@ -4639,113 +4472,103 @@ void handle_internal( tic_param_t pfield) emit_token("j"); must_be_deep_in_do(2); break; - + case LOOP: emit_token("b(loop)"); resolve_loop(); break; - + case PLUS_LOOP: emit_token("b(+loop)"); resolve_loop(); break; - case INSTANCE: { - bool set_instance_state = FALSE; - bool emit_instance = TRUE; - /* We will treat "instance" in a colon-definition as - * an error, but allow it to be emitted if we're - * ignoring errors; if we're not ignoring errors, - * there's no output anyway... - */ - if ( test_in_colon(statbuf, FALSE, TKERROR, NULL) ) - { /* We are in interpretation (not colon) state. */ - /* "Instance" not allowed during "global" scope */ - if ( scope_is_global ) - { - glob_not_allowed( WARNING, FALSE ); - emit_instance = FALSE; - }else{ - set_instance_state = TRUE; + bool set_instance_state = FALSE; + bool emit_instance = TRUE; + /* We will treat "instance" in a colon-definition as + * an error, but allow it to be emitted if we're + * ignoring errors; if we're not ignoring errors, + * there's no output anyway... + */ + if (test_in_colon(statbuf, FALSE, TKERROR, NULL)) { /* We are in interpretation (not colon) state. */ + /* "Instance" not allowed during "global" scope */ + if (scope_is_global) { + glob_not_allowed(WARNING, FALSE); + emit_instance = FALSE; + } else { + set_instance_state = TRUE; + } } - } - if ( emit_instance ) - { - if ( set_instance_state ) - { - /* "Instance" isn't cumulative.... */ - if ( is_instance ) - { - unresolved_instance( WARNING); - } - collect_input_filename( &instance_filename); - instance_lineno = lineno; - is_instance = TRUE; - dev_change_instance_warning = TRUE; + if (emit_instance) { + if (set_instance_state) { + /* "Instance" isn't cumulative.... */ + if (is_instance) { + unresolved_instance(WARNING); + } + collect_input_filename + (&instance_filename); + instance_lineno = lineno; + is_instance = TRUE; + dev_change_instance_warning = TRUE; + } + emit_token("instance"); } - emit_token("instance"); - } } break; - + case GLOB_SCOPE: - if ( test_in_colon(statbuf, FALSE, TKERROR, NULL) ) - { - if ( INVERSE( is_instance) ) - { - enter_global_scope(); - }else{ - tokenization_error( TKERROR, - "Global Scope not allowed. " - "\"Instance\" is in effect; issued" ); - just_where_started( instance_filename, - instance_lineno ); - } + if (test_in_colon(statbuf, FALSE, TKERROR, NULL)) { + if (INVERSE(is_instance)) { + enter_global_scope(); + } else { + tokenization_error(TKERROR, + "Global Scope not allowed. " + "\"Instance\" is in effect; issued"); + just_where_started(instance_filename, + instance_lineno); + } } break; case DEV_SCOPE: - if ( test_in_colon(statbuf, FALSE, TKERROR, NULL) ) - { - resume_device_scope(); + if (test_in_colon(statbuf, FALSE, TKERROR, NULL)) { + resume_device_scope(); } break; - case TICK: /* ' */ + case TICK: /* ' */ test_in_colon(statbuf, FALSE, WARNING, "[']"); - case BRACK_TICK: /* ['] */ + case BRACK_TICK: /* ['] */ { - tic_hdr_t *token_entry; - if ( get_token( &token_entry) ) - { - emit_token("b(')"); - /* Emit the token; warning or whatever comes gratis */ - token_entry->funct( token_entry->pfield); - } + tic_hdr_t *token_entry; + if (get_token(&token_entry)) { + emit_token("b(')"); + /* Emit the token; warning or whatever comes gratis */ + token_entry->funct(token_entry->pfield); + } } break; - case F_BRACK_TICK: /* F['] - * emits the token-number for - * Mainly useful to compute the argument - * to get-token or set-token - */ + case F_BRACK_TICK: /* F['] + * emits the token-number for + * Mainly useful to compute the argument + * to get-token or set-token + */ { - tic_hdr_t *token_entry; - if ( get_token( &token_entry) ) - { - /* "Obsolete" warning doesn't come gratis here... */ - token_entry_warning( token_entry); - /* In Tokenizer-Escape mode, push the token */ - if ( in_tokz_esc ) - { - dpush( token_entry->pfield.deflt_elem); - }else{ - emit_literal( token_entry->pfield.deflt_elem); + tic_hdr_t *token_entry; + if (get_token(&token_entry)) { + /* "Obsolete" warning doesn't come gratis here... */ + token_entry_warning(token_entry); + /* In Tokenizer-Escape mode, push the token */ + if (in_tokz_esc) { + dpush(token_entry->pfield.deflt_elem); + } else { + emit_literal(token_entry->pfield. + deflt_elem); + } } - } } break; @@ -4753,14 +4576,13 @@ void handle_internal( tic_param_t pfield) handy_toggle = FALSE; case CCHAR: test_in_colon(statbuf, handy_toggle, WARNING, - handy_toggle ? "CHAR" : "[CHAR]" ); + handy_toggle ? "CHAR" : "[CHAR]"); case ASCII: - if ( get_word_in_line( statbuf) ) - { - emit_literal(statbuf[0]); + if (get_word_in_line(statbuf)) { + emit_literal(statbuf[0]); } break; - + case UNTIL: emit_until(); break; @@ -4768,139 +4590,130 @@ void handle_internal( tic_param_t pfield) case WHILE: emit_while(); break; - + case REPEAT: emit_repeat(); break; - + case THEN: emit_then(); break; case IS: - tokenization_error ( INFO, - "Substituting TO for deprecated IS\n"); + tokenization_error(INFO, + "Substituting TO for deprecated IS\n"); case TO: - if ( validate_to_target() ) - { - emit_token("b(to)"); + if (validate_to_target()) { + emit_token("b(to)"); } break; case FLOAD: - if ( get_word_in_line( statbuf) ) - { - bool stream_ok ; - - push_source( close_stream, NULL, TRUE) ; - - tokenization_error( INFO, "FLOADing %s\n", statbuf ); - - stream_ok = init_stream( statbuf ); - if ( INVERSE( stream_ok) ) - { - drop_source(); - } + if (get_word_in_line(statbuf)) { + bool stream_ok; + + push_source(close_stream, NULL, TRUE); + + tokenization_error(INFO, "FLOADing %s\n", statbuf); + + stream_ok = init_stream(statbuf); + if (INVERSE(stream_ok)) { + drop_source(); + } } break; - case STRING: /* Double-Quote ( " ) string */ + case STRING: /* Double-Quote ( " ) string */ handy_toggle = FALSE; - case PSTRING: /* Dot-Quote ( ." ) string */ - wlen=get_string( TRUE); + case PSTRING: /* Dot-Quote ( ." ) string */ + wlen = get_string(TRUE); emit_token("b(\")"); emit_string(statbuf, wlen); - if ( handy_toggle ) - { - emit_token("type"); + if (handy_toggle) { + emit_token("type"); } break; - case SSTRING: /* Ess-Quote ( s" ) string */ + case SSTRING: /* Ess-Quote ( s" ) string */ handy_toggle = FALSE; - case PBSTRING: /* Dot-Paren .( string */ - if (*pc++=='\n') lineno++; + case PBSTRING: /* Dot-Paren .( string */ + if (*pc++ == '\n') + lineno++; { - unsigned int strt_lineno = lineno; - wlen = get_until( handy_toggle ? ')' : '"' ); - if ( string_err_check( handy_toggle, - sav_lineno, strt_lineno) ) - { - emit_token("b(\")"); - emit_string(statbuf, wlen); - if ( handy_toggle ) - { - emit_token("type"); + unsigned int strt_lineno = lineno; + wlen = get_until(handy_toggle ? ')' : '"'); + if (string_err_check(handy_toggle, + sav_lineno, strt_lineno)) { + emit_token("b(\")"); + emit_string(statbuf, wlen); + if (handy_toggle) { + emit_token("type"); + } } - } } break; case FUNC_NAME: - if ( in_tokz_esc ) - { - if ( incolon ) - { - tokenization_error( P_MESSAGE, "Currently" ); - }else{ - tokenization_error( P_MESSAGE, "After" ); - } - in_last_colon( incolon); - }else{ - emit_token("b(\")"); - emit_string( last_colon_defname, - strlen( last_colon_defname) ); + if (in_tokz_esc) { + if (incolon) { + tokenization_error(P_MESSAGE, "Currently"); + } else { + tokenization_error(P_MESSAGE, "After"); + } + in_last_colon(incolon); + } else { + emit_token("b(\")"); + emit_string(last_colon_defname, + strlen(last_colon_defname)); /* if ( hdr_flag == FLAG_HEADERLESS ) { WARNING } */ - } + } break; case IFILE_NAME: emit_token("b(\")"); - emit_string( iname, strlen( iname) ); + emit_string(iname, strlen(iname)); break; case ILINE_NUM: - emit_literal( lineno); + emit_literal(lineno); break; - + case HEXVAL: - base_val (0x10); + base_val(0x10); break; - + case DECVAL: - base_val (0x0a); + base_val(0x0a); break; - + case OCTVAL: - base_val (8); + base_val(8); break; case ASC_LEFT_NUM: handy_toggle = FALSE; case ASC_NUM: - if (get_word_in_line( statbuf) ) - { - if ( handy_toggle ) - { - ascii_right_number( statbuf); + if (get_word_in_line(statbuf)) { + if (handy_toggle) { + ascii_right_number(statbuf); } else { - ascii_left_number( statbuf); + ascii_left_number(statbuf); } } break; - case CONDL_ENDER: /* Conditional directives out of context */ + case CONDL_ENDER: /* Conditional directives out of context */ case CONDL_ELSE: - tokenization_error ( TKERROR, - "No conditional preceding %s directive\n", - strupr(statbuf) ); + tokenization_error(TKERROR, + "No conditional preceding %s directive\n", + strupr(statbuf)); break; case PUSH_FCODE: - tokenization_error( INFO, - "FCode-token Assignment Counter of 0x%x " - "has been saved on stack.\n", nextfcode ); - dpush( (long)nextfcode ); + tokenization_error(INFO, + "FCode-token Assignment Counter of 0x%x " + "has been saved on stack.\n", nextfcode); + dpush((long)nextfcode); break; case POP_FCODE: @@ -4908,83 +4721,76 @@ void handle_internal( tic_param_t pfield) break; case RESET_FCODE: - tokenization_error( INFO, - "Encountered %s. Resetting FCode-token " - "Assignment Counter. ", strupr(statbuf) ); - list_fcode_ranges( FALSE); + tokenization_error(INFO, + "Encountered %s. Resetting FCode-token " + "Assignment Counter. ", strupr(statbuf)); + list_fcode_ranges(FALSE); reset_fcode_ranges(); break; - + case EXIT: - if ( test_in_colon( statbuf, TRUE, TKERROR, NULL) - || noerrors ) - { - ret_stk_balance_rpt( NULL, FALSE); - if ( ibm_locals ) - { - finish_locals (); - } - emit_token("exit"); + if (test_in_colon(statbuf, TRUE, TKERROR, NULL) + || noerrors) { + ret_stk_balance_rpt(NULL, FALSE); + if (ibm_locals) { + finish_locals(); + } + emit_token("exit"); } break; case ESCAPETOK: enter_tokz_esc(); break; - + case VERSION1: case FCODE_V1: - fcode_starter( "version1", 1, FALSE) ; - tokenization_error( INFO, "Using version1 header " - "(8-bit offsets).\n"); + fcode_starter("version1", 1, FALSE); + tokenization_error(INFO, "Using version1 header " + "(8-bit offsets).\n"); break; - + case START1: case FCODE_V2: - case FCODE_V3: /* Full IEEE 1275 */ - fcode_starter( "start1", 1, TRUE); + case FCODE_V3: /* Full IEEE 1275 */ + fcode_starter("start1", 1, TRUE); break; - + case START0: - fcode_starter( "start0", 0, TRUE); + fcode_starter("start0", 0, TRUE); break; - + case START2: - fcode_starter( "start2", 2, TRUE); + fcode_starter("start2", 2, TRUE); break; - + case START4: - fcode_starter( "start4", 4, TRUE); + fcode_starter("start4", 4, TRUE); break; - + case END1: - tokenization_error( WARNING, - "Appearance of END1 in FCode source code " - "is not intended by IEEE 1275-1994\n"); + tokenization_error(WARNING, + "Appearance of END1 in FCode source code " + "is not intended by IEEE 1275-1994\n"); handy_toggle = FALSE; case END0: case FCODE_END: - if ( handy_toggle ) - { - you_are_here(); + if (handy_toggle) { + you_are_here(); } - emit_token( handy_toggle ? "end0" : "end1" ); + emit_token(handy_toggle ? "end0" : "end1"); fcode_ender(); - FFLUSH_STDOUT - break; + FFLUSH_STDOUT break; case RECURSE: - if ( test_in_colon(statbuf, TRUE, TKERROR, NULL ) ) - { - emit_fcode(last_colon_fcode); + if (test_in_colon(statbuf, TRUE, TKERROR, NULL)) { + emit_fcode(last_colon_fcode); } break; - case RECURSIVE: - if ( test_in_colon(statbuf, TRUE, TKERROR, NULL ) ) - { - reveal_last_colon(); + if (test_in_colon(statbuf, TRUE, TKERROR, NULL)) { + reveal_last_colon(); } break; @@ -4995,69 +4801,64 @@ void handle_internal( tic_param_t pfield) */ /* First in series doesn't need to check handy_toggle */ handy_string = "r@"; - /* Will call ret_stk_access_rpt() */ - /* handy_toggle_too is already TRUE */ - /* Will not call bump_ret_stk_depth() */ - /* handy_int is already zero */ + /* Will call ret_stk_access_rpt() */ + /* handy_toggle_too is already TRUE */ + /* Will not call bump_ret_stk_depth() */ + /* handy_int is already zero */ handy_toggle = FALSE; case RET_STK_FROM: - if ( handy_toggle ) - { - handy_string = "r>"; - /* Will call ret_stk_access_rpt() */ - /* handy_toggle_too is already TRUE */ - /* Will call bump_ret_stk_depth( -1) */ - handy_int = -1; - handy_toggle = FALSE; + if (handy_toggle) { + handy_string = "r>"; + /* Will call ret_stk_access_rpt() */ + /* handy_toggle_too is already TRUE */ + /* Will call bump_ret_stk_depth( -1) */ + handy_int = -1; + handy_toggle = FALSE; } case RET_STK_TO: - if ( handy_toggle ) - { - handy_string = ">r"; - /* Will not call ret_stk_access_rpt() */ - handy_toggle_too = FALSE; - /* Will call bump_ret_stk_depth( 1) */ - handy_int = 1; - /* Last in series doesn't need to reset handy_toggle */ + if (handy_toggle) { + handy_string = ">r"; + /* Will not call ret_stk_access_rpt() */ + handy_toggle_too = FALSE; + /* Will call bump_ret_stk_depth( 1) */ + handy_int = 1; + /* Last in series doesn't need to reset handy_toggle */ } /* handy_toggle is now free for other use */ handy_toggle = allow_ret_stk_interp; - if ( ! handy_toggle ) - { - handy_toggle = test_in_colon(statbuf, TRUE, TKERROR, NULL ); + if (!handy_toggle) { + handy_toggle = + test_in_colon(statbuf, TRUE, TKERROR, NULL); } - if ( handy_toggle || noerrors ) - { - if ( handy_toggle_too ) - { - ret_stk_access_rpt(); - } - if ( handy_int != 0 ) - { - bump_ret_stk_depth( handy_int); - } - emit_token( handy_string); + if (handy_toggle || noerrors) { + if (handy_toggle_too) { + ret_stk_access_rpt(); + } + if (handy_int != 0) { + bump_ret_stk_depth(handy_int); + } + emit_token(handy_string); } break; case PCIHDR: emit_pcihdr(); break; - + case PCIEND: finish_pcihdr(); reset_fcode_ranges(); - FFLUSH_STDOUT - break; + FFLUSH_STDOUT break; case PCIREV: pci_image_rev = dpop(); - tokenization_error( INFO, - "PCI header revision=0x%04x%s\n", pci_image_rev, - big_end_pci_image_rev ? - ". Will be saved in Big-Endian format." - : "" ); + tokenization_error(INFO, + "PCI header revision=0x%04x%s\n", + pci_image_rev, + big_end_pci_image_rev ? + ". Will be saved in Big-Endian format." : + ""); break; case NOTLAST: @@ -5066,39 +4867,39 @@ void handle_internal( tic_param_t pfield) dpush(handy_toggle); case SETLAST: { - u32 val = dpop(); - bool new_pili = BOOLVAL( (val != 0) ); - if ( pci_is_last_image != new_pili ) - { - tokenization_error( INFO, - new_pili ? - "Last image for PCI header.\n" : - "PCI header not last image.\n" ); - pci_is_last_image = new_pili; - } + u32 val = dpop(); + bool new_pili = BOOLVAL((val != 0)); + if (pci_is_last_image != new_pili) { + tokenization_error(INFO, + new_pili ? + "Last image for PCI header.\n" + : + "PCI header not last image.\n"); + pci_is_last_image = new_pili; + } } break; - + case SAVEIMG: - if (get_word_in_line( statbuf) ) - { - free(oname); - oname = strdup( statbuf ); - tokenization_error( INFO, - "Output is redirected to file: %s\n", oname); + if (get_word_in_line(statbuf)) { + free(oname); + oname = strdup(statbuf); + tokenization_error(INFO, + "Output is redirected to file: %s\n", + oname); } break; case RESETSYMBS: - tokenization_error( INFO, - "Resetting symbols defined in %s mode.\n", - in_tokz_esc ? "tokenizer-escape" : "\"normal\""); - if ( in_tokz_esc ) - { - reset_tokz_esc(); - }else{ - reset_normal_vocabs(); - } + tokenization_error(INFO, + "Resetting symbols defined in %s mode.\n", + in_tokz_esc ? "tokenizer-escape" : + "\"normal\""); + if (in_tokz_esc) { + reset_tokz_esc(); + } else { + reset_normal_vocabs(); + } break; case FCODE_DATE: @@ -5106,78 +4907,82 @@ void handle_internal( tic_param_t pfield) case FCODE_TIME: { time_t tt; - char temp_buffr[32]; - - tt=time(NULL); - if ( handy_toggle ) - { - strftime(temp_buffr, 32, "%T %Z", localtime(&tt)); - }else{ - strftime(temp_buffr, 32, "%m/%d/%Y", localtime(&tt)); - } - if ( in_tokz_esc ) - { - tokenization_error( MESSAGE, temp_buffr); - }else{ - emit_token("b(\")"); - emit_string((u8 *)temp_buffr, strlen(temp_buffr) ); - } + char temp_buffr[32]; + + tt = time(NULL); + if (handy_toggle) { + strftime(temp_buffr, 32, "%T %Z", + localtime(&tt)); + } else { + strftime(temp_buffr, 32, "%m/%d/%Y", + localtime(&tt)); + } + if (in_tokz_esc) { + tokenization_error(MESSAGE, temp_buffr); + } else { + emit_token("b(\")"); + emit_string((u8 *) temp_buffr, + strlen(temp_buffr)); + } } break; case ENCODEFILE: - if (get_word_in_line( statbuf) ) - { - encode_file( (char*)statbuf ); + if (get_word_in_line(statbuf)) { + encode_file((char *)statbuf); } break; default: - /* IBM-style Locals, under control of a switch */ - if ( ibm_locals ) - { - bool found_it = TRUE; - switch (tok) { - case CURLY_BRACE: - declare_locals( FALSE); - break; - case DASH_ARROW: - assign_local(); - break; - default: - found_it = FALSE; - } - if ( found_it ) break; -} - - /* Down here, we have our last chance to recognize a token. - * If abort_quote is disallowed, we will still consume - * the string. In case the string spans more than one - * line, we want to make sure the line number displayed - * in the error-message is the one on which the disallowed - * abort_quote token appeared, not the one where the - * string ended; therefore, we might need to be able to - * "fake-out" the line number... - */ -{ - bool fake_out_lineno = FALSE; - unsigned int save_lineno = lineno; - unsigned int true_lineno; - if ( abort_quote( tok) ) - { break; - }else{ - if ( tok == ABORTTXT ) fake_out_lineno = TRUE; + /* IBM-style Locals, under control of a switch */ + if (ibm_locals) { + bool found_it = TRUE; + switch (tok) { + case CURLY_BRACE: + declare_locals(FALSE); + break; + case DASH_ARROW: + assign_local(); + break; + default: + found_it = FALSE; + } + if (found_it) + break; } - true_lineno = lineno; - if ( fake_out_lineno ) lineno = save_lineno; - tokenization_error ( TKERROR, - "Unimplemented control word '%s'\n", strupr(statbuf) ); - if ( fake_out_lineno ) lineno = true_lineno; - } + /* Down here, we have our last chance to recognize a token. + * If abort_quote is disallowed, we will still consume + * the string. In case the string spans more than one + * line, we want to make sure the line number displayed + * in the error-message is the one on which the disallowed + * abort_quote token appeared, not the one where the + * string ended; therefore, we might need to be able to + * "fake-out" the line number... + */ + { + bool fake_out_lineno = FALSE; + unsigned int save_lineno = lineno; + unsigned int true_lineno; + if (abort_quote(tok)) { + break; + } else { + if (tok == ABORTTXT) + fake_out_lineno = TRUE; + } + true_lineno = lineno; + + if (fake_out_lineno) + lineno = save_lineno; + tokenization_error(TKERROR, + "Unimplemented control word '%s'\n", + strupr(statbuf)); + if (fake_out_lineno) + lineno = true_lineno; + } } } - + /* ************************************************************************** * * Function name: skip_string @@ -5217,53 +5022,55 @@ void handle_internal( tic_param_t pfield) * **************************************************************************** */ -void skip_string( tic_param_t pfield); -void skip_string( tic_param_t pfield) +void skip_string(tic_param_t pfield); +void skip_string(tic_param_t pfield) { - fwtoken tok = pfield.fw_token; - unsigned int sav_lineno = lineno; - bool handy_toggle = TRUE ; /* Various uses... */ - - switch (tok) { - case STRING: /* Double-Quote ( " ) string */ - case PSTRING: /* Dot-Quote ( ." ) string */ - case ABORTTXT: /* ABORT", even if not enabled */ - get_string( FALSE); /* Don't truncate; ignoring anyway */ - /* Will handle multi-line warnings, etc. */ + fwtoken tok = pfield.fw_token; + unsigned int sav_lineno = lineno; + bool handy_toggle = TRUE; /* Various uses... */ + + switch (tok) { + case STRING: /* Double-Quote ( " ) string */ + case PSTRING: /* Dot-Quote ( ." ) string */ + case ABORTTXT: /* ABORT", even if not enabled */ + get_string(FALSE); /* Don't truncate; ignoring anyway */ + /* Will handle multi-line warnings, etc. */ + break; + + case SSTRING: /* Ess-Quote ( s" ) string */ + handy_toggle = FALSE; + case PBSTRING: /* Dot-Paren .( string */ + if (*pc++ == '\n') + lineno++; + { + unsigned int strt_lineno = lineno; + get_until(handy_toggle ? ')' : '"'); + string_err_check(handy_toggle, sav_lineno, strt_lineno); + } + break; + + default: + /* IBM-style Locals, under control of a switch */ + if (ibm_locals) { + bool found_it = TRUE; + switch (tok) { + case CURLY_BRACE: + declare_locals(TRUE); break; - - case SSTRING: /* Ess-Quote ( s" ) string */ - handy_toggle = FALSE; - case PBSTRING: /* Dot-Paren .( string */ - if (*pc++=='\n') lineno++; - { - unsigned int strt_lineno = lineno; - get_until( handy_toggle ? ')' : '"' ); - string_err_check( handy_toggle, sav_lineno, strt_lineno ); - } - break; - - default: - /* IBM-style Locals, under control of a switch */ - if ( ibm_locals ) - { - bool found_it = TRUE; - switch (tok) { - case CURLY_BRACE: - declare_locals( TRUE); - break; - case DASH_ARROW: - get_word(); - break; - default: - found_it = FALSE; - } - if ( found_it ) break; - } + case DASH_ARROW: + get_word(); + break; + default: + found_it = FALSE; + } + if (found_it) + break; + } - tokenization_error ( FATAL, "Program Error. " - "Unimplemented skip-string word '%s'\n", strupr(statbuf) ); - } + tokenization_error(FATAL, "Program Error. " + "Unimplemented skip-string word '%s'\n", + strupr(statbuf)); + } } /* ************************************************************************** @@ -5293,39 +5100,33 @@ void skip_string( tic_param_t pfield) * **************************************************************************** */ -void process_remark( tic_param_t pfield ) +void process_remark(tic_param_t pfield) { - char until_char = (char)pfield.fw_token ; - unsigned int start_lineno = lineno; + char until_char = (char)pfield.fw_token; + unsigned int start_lineno = lineno; #ifdef DEBUG_SCANNER - get_until(until_char); - printf ("%s:%d: debug: stack diagram: %s)\n", - iname, lineno, statbuf); + get_until(until_char); + printf("%s:%d: debug: stack diagram: %s)\n", iname, lineno, statbuf); #else - if ( skip_until( until_char) ) - { - if ( until_char == '\n' ) - { - /* Don't need any saved line number here ... */ - tokenization_error ( WARNING, - "Unterminated remark.\n"); - }else{ - warn_unterm( WARNING, "comment", start_lineno); - } - }else{ - if ( until_char != '\n' ) - { - pc++; - warn_if_multiline( "comment", start_lineno); + if (skip_until(until_char)) { + if (until_char == '\n') { + /* Don't need any saved line number here ... */ + tokenization_error(WARNING, "Unterminated remark.\n"); + } else { + warn_unterm(WARNING, "comment", start_lineno); + } + } else { + if (until_char != '\n') { + pc++; + warn_if_multiline("comment", start_lineno); + } } - } -#endif /* DEBUG_SCANNER */ +#endif /* DEBUG_SCANNER */ } - - + /* ************************************************************************** * * Function name: filter_comments @@ -5354,34 +5155,29 @@ void process_remark( tic_param_t pfield ) * **************************************************************************** */ -bool filter_comments( u8 *inword) +bool filter_comments(u8 * inword) { - bool retval = FALSE; - tic_hdr_t *found = lookup_word( inword, NULL, NULL ); - - if ( found != NULL ) - { - if ( found->funct == process_remark ) - { - found->funct( found->pfield); - retval = TRUE; - }else{ - /* Permit the "allow-multiline-comments" directive */ - if ( found->funct == handle_internal ) - { - if ( found->pfield.fw_token == ALLOW_MULTI_LINE ) - { - /* Make sure any intended side-effects occur... */ - found->funct( found->pfield); - retval = TRUE; + bool retval = FALSE; + tic_hdr_t *found = lookup_word(inword, NULL, NULL); + + if (found != NULL) { + if (found->funct == process_remark) { + found->funct(found->pfield); + retval = TRUE; + } else { + /* Permit the "allow-multiline-comments" directive */ + if (found->funct == handle_internal) { + if (found->pfield.fw_token == ALLOW_MULTI_LINE) { + /* Make sure any intended side-effects occur... */ + found->funct(found->pfield); + retval = TRUE; + } + } } - } } - } - return ( retval ); - } + return (retval); +} - /* ************************************************************************** * * Function name: tokenize_one_word @@ -5440,35 +5236,32 @@ bool filter_comments( u8 *inword) * of coding. * **************************************************************************** */ - -void tokenize_one_word( signed long wlen ) + +void tokenize_one_word(signed long wlen) { - - /* The shared lookup routine now handles everything. */ - tic_hdr_t *found = lookup_word( statbuf, NULL, NULL ); - - if ( found != NULL ) - { - tic_found = found; - if ( found->tracing) - { - invoking_traced_name( found); - } - found->funct( found->pfield); - return ; - } - - /* It's not a word in any of our current contexts. - * Is it a number? - */ - if ( handle_number() ) - { - return ; - } - /* Could not identify - give a shout. */ - tokenized_word_error( statbuf ); + /* The shared lookup routine now handles everything. */ + tic_hdr_t *found = lookup_word(statbuf, NULL, NULL); + + if (found != NULL) { + tic_found = found; + if (found->tracing) { + invoking_traced_name(found); } + found->funct(found->pfield); + return; + } + + /* It's not a word in any of our current contexts. + * Is it a number? + */ + if (handle_number()) { + return; + } + + /* Could not identify - give a shout. */ + tokenized_word_error(statbuf); +} /* ************************************************************************** * @@ -5486,15 +5279,12 @@ void tokenize_one_word( signed long wlen ) void tokenize(void) { - signed long wlen = 0; - - while ( wlen >= 0 ) - { - wlen = get_word(); - if ( wlen > 0 ) - { - tokenize_one_word( wlen ); - } + signed long wlen = 0; + + while (wlen >= 0) { + wlen = get_word(); + if (wlen > 0) { + tokenize_one_word(wlen); + } } } - diff --git a/toke/scanner.h b/toke/scanner.h index 722ad78..ebb3f1e 100644 --- a/toke/scanner.h +++ b/toke/scanner.h @@ -34,7 +34,6 @@ * **************************************************************************** */ - #include "types.h" #include "ticvocab.h" @@ -44,42 +43,41 @@ * **************************************************************************** */ -extern u8 *statbuf; /* The word just read from the input stream */ -extern u8 base; /* The numeric-interpretation base */ - +extern u8 *statbuf; /* The word just read from the input stream */ +extern u8 base; /* The numeric-interpretation base */ /* pci data */ extern bool pci_is_last_image; -extern u16 pci_image_rev; /* Vendor's Image, NOT PCI Data Struct Rev */ -extern u16 pci_vpd; - +extern u16 pci_image_rev; /* Vendor's Image, NOT PCI Data Struct Rev */ +extern u16 pci_vpd; /* Having to do with the state of the tokenization */ -extern bool offs16; /* Using 16-bit branch- (etc) -offsets */ -extern bool in_tokz_esc; /* TRUE if in "Tokenizer Escape" mode */ -extern bool incolon; /* TRUE if inside a colon definition */ -extern bool haveend; /* TRUE if the "end" code was read. */ -extern int do_loop_depth; /* How deep we are inside DO ... LOOP variants */ +extern bool offs16; /* Using 16-bit branch- (etc) -offsets */ +extern bool in_tokz_esc; /* TRUE if in "Tokenizer Escape" mode */ +extern bool incolon; /* TRUE if inside a colon definition */ +extern bool haveend; /* TRUE if the "end" code was read. */ +extern int do_loop_depth; /* How deep we are inside DO ... LOOP variants */ /* State of headered-ness for name-creation */ typedef enum headeredness_t { - FLAG_HEADERLESS , - FLAG_EXTERNAL , - FLAG_HEADERS } headeredness ; + FLAG_HEADERLESS, + FLAG_EXTERNAL, + FLAG_HEADERS +} headeredness; extern headeredness hdr_flag; /* For special-case error detection or reporting */ -extern int lastcolon; /* Loc'n in output stream of latest colon-def'n. */ +extern int lastcolon; /* Loc'n in output stream of latest colon-def'n. */ /* Used for error-checking of IBM-style Locals */ -extern char *last_colon_defname; /* Name of last colon-definition */ -extern char *last_colon_filename; /* File where last colon-def'n made */ -extern unsigned int last_colon_lineno; /* Line number of last colon-def'n */ -extern bool report_multiline; /* False to suspend multiline warning */ +extern char *last_colon_defname; /* Name of last colon-definition */ +extern char *last_colon_filename; /* File where last colon-def'n made */ +extern unsigned int last_colon_lineno; /* Line number of last colon-def'n */ +extern bool report_multiline; /* False to suspend multiline warning */ extern unsigned int last_colon_abs_token_no; - /* Shared phrases */ + /* Shared phrases */ extern char *in_tkz_esc_mode; -extern char *wh_defined; +extern char *wh_defined; /* ************************************************************************** * * @@ -87,36 +85,34 @@ extern char *wh_defined; * **************************************************************************** */ -void init_scanner( void ); -void exit_scanner( void ); -void init_scan_state( void ); -void fcode_ender( void ); - -bool skip_until( char lim_ch); -void push_source( void (*res_func)(), _PTR res_parm, bool is_f_chg ); -signed long get_word( void); -bool get_word_in_line( char *func_nam); -bool get_rest_of_line( void); -void warn_unterm( int severity, - char *something, - unsigned int saved_lineno); -void warn_if_multiline( char *something, unsigned int start_lineno ); -void user_message( tic_param_t pfield ); -void skip_user_message( tic_param_t pfield ); -bool get_number( long *result); -void eval_string( char *inp_bufr); - -void process_remark( tic_param_t pfield ); -bool filter_comments( u8 *inword); -bool as_a_what( fwtoken definer, char *as_what); -tic_hdr_t *lookup_word( char *stat_name, char **where_pt1, char **where_pt2 ); -bool word_exists( char *stat_name, char **where_pt1, char **where_pt2 ); -void warn_if_duplicate ( char *stat_name); -void tokenize_one_word( signed long wlen ); -void check_name_length( signed long wlen ); +void init_scanner(void); +void exit_scanner(void); +void init_scan_state(void); +void fcode_ender(void); + +bool skip_until(char lim_ch); +void push_source(void (*res_func)(), _PTR res_parm, bool is_f_chg); +signed long get_word(void); +bool get_word_in_line(char *func_nam); +bool get_rest_of_line(void); +void warn_unterm(int severity, char *something, unsigned int saved_lineno); +void warn_if_multiline(char *something, unsigned int start_lineno); +void user_message(tic_param_t pfield); +void skip_user_message(tic_param_t pfield); +bool get_number(long *result); +void eval_string(char *inp_bufr); + +void process_remark(tic_param_t pfield); +bool filter_comments(u8 * inword); +bool as_a_what(fwtoken definer, char *as_what); +tic_hdr_t *lookup_word(char *stat_name, char **where_pt1, char **where_pt2); +bool word_exists(char *stat_name, char **where_pt1, char **where_pt2); +void warn_if_duplicate(char *stat_name); +void tokenize_one_word(signed long wlen); +void check_name_length(signed long wlen); bool definer_name(fwtoken definer, char **reslt_ptr); -void tokenize( void ); +void tokenize(void); /* ************************************************************************** * @@ -135,4 +131,4 @@ void tokenize( void ); #define AS_WHAT_BUF_SIZE 32 -#endif /* _TOKE_SCANNER_H */ +#endif /* _TOKE_SCANNER_H */ diff --git a/toke/stack.c b/toke/stack.c index 2d4614a..60adc04 100644 --- a/toke/stack.c +++ b/toke/stack.c @@ -45,7 +45,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Global Variables Exported @@ -68,28 +67,29 @@ static long *enddstack; void clear_stack(void) { - dstack = enddstack; + dstack = enddstack; } /* internal stack functions */ void init_stack(void) { - startdstack = safe_malloc(MAX_ELEMENTS*sizeof(long), "initting stack"); + startdstack = + safe_malloc(MAX_ELEMENTS * sizeof(long), "initting stack"); enddstack = startdstack + MAX_ELEMENTS; - dstack=enddstack; + dstack = enddstack; } /* Input Param: stat TRUE = Underflow, FALSE = Overflow */ static void stackerror(bool stat) { - /* - * Because all of our stack operations are protected and - * we have no risk of the dstack pointer going into - * invalid territory, this error needs not be FATAL. - */ - tokenization_error ( TKERROR , "stack %sflow at or near %s \n", - (stat)?"under":"over" , statbuf ); + /* + * Because all of our stack operations are protected and + * we have no risk of the dstack pointer going into + * invalid territory, this error needs not be FATAL. + */ + tokenization_error(TKERROR, "stack %sflow at or near %s \n", + (stat) ? "under" : "over", statbuf); } /* @@ -98,29 +98,28 @@ static void stackerror(bool stat) */ bool min_stack_depth(int mindep) { - bool retval = TRUE ; - long *stack_result; - - stack_result = dstack + mindep; - /* - * The above appears counter-intuitive. However, C compensates - * for the size of the object of a pointer when it handles - * address arithmetic. A more explicit expression that would - * yield the same result, might look something like this: - * - * (long *)((int)dstack + (mindep * sizeof(long))) - * - * I doubt that that form would yield tighter code, or otherwise - * represent any material advantage... - */ - - if ( stack_result > enddstack ) - { - retval = FALSE; - stackerror(TRUE); - } - - return ( retval ); + bool retval = TRUE; + long *stack_result; + + stack_result = dstack + mindep; + /* + * The above appears counter-intuitive. However, C compensates + * for the size of the object of a pointer when it handles + * address arithmetic. A more explicit expression that would + * yield the same result, might look something like this: + * + * (long *)((int)dstack + (mindep * sizeof(long))) + * + * I doubt that that form would yield tighter code, or otherwise + * represent any material advantage... + */ + + if (stack_result > enddstack) { + retval = FALSE; + stackerror(TRUE); + } + + return (retval); } /* @@ -128,19 +127,18 @@ bool min_stack_depth(int mindep) */ static bool room_on_stack_for(int newdep) { - bool retval = TRUE ; - long *stack_result; + bool retval = TRUE; + long *stack_result; - stack_result = dstack - newdep; - /* See above note about "counter-intuitive" pointer address arithmetic */ + stack_result = dstack - newdep; + /* See above note about "counter-intuitive" pointer address arithmetic */ - if ( stack_result < startdstack ) - { - retval = FALSE; - stackerror(FALSE); - } + if (stack_result < startdstack) { + retval = FALSE; + stackerror(FALSE); + } - return ( retval ); + return (retval); } void dpush(long data) @@ -148,79 +146,72 @@ void dpush(long data) #ifdef DEBUG_DSTACK printf("dpush: sp=%p, data=0x%lx, ", dstack, data); #endif - if ( room_on_stack_for(1) ) - { - --dstack; - *(dstack)=data; + if (room_on_stack_for(1)) { + --dstack; + *(dstack) = data; } } long dpop(void) { - long val = 0; + long val = 0; #ifdef DEBUG_DSTACK - printf("dpop: sp=%p, data=0x%lx, ",dstack, *dstack); + printf("dpop: sp=%p, data=0x%lx, ", dstack, *dstack); #endif - if ( min_stack_depth(1) ) - { - val=*(dstack); - dstack++; + if (min_stack_depth(1)) { + val = *(dstack); + dstack++; } return val; } long dget(void) { - long val = 0; - if ( min_stack_depth(1) ) - { - val = *(dstack); + long val = 0; + if (min_stack_depth(1)) { + val = *(dstack); } return val; } long stackdepth(void) { - long depth; - - depth = enddstack - dstack; - /* - * Again, C's address arithmetic compensation comes into play. - * See the note at min_stack_depth() - * - * A more explicit equivalent expression might look like this: - * - * (((long int)enddstack - (long int)dstack) / sizeof(long)) - * - * I doubt any material advantage with that one either... - */ - - return (depth); + long depth; + + depth = enddstack - dstack; + /* + * Again, C's address arithmetic compensation comes into play. + * See the note at min_stack_depth() + * + * A more explicit equivalent expression might look like this: + * + * (((long int)enddstack - (long int)dstack) / sizeof(long)) + * + * I doubt any material advantage with that one either... + */ + + return (depth); } void swap(void) { - long nos_temp; /* Next-On-Stack temp */ - if ( min_stack_depth(2) ) - { - nos_temp = dstack[1]; - dstack[1]= dstack[0]; - dstack[0]= nos_temp; - } + long nos_temp; /* Next-On-Stack temp */ + if (min_stack_depth(2)) { + nos_temp = dstack[1]; + dstack[1] = dstack[0]; + dstack[0] = nos_temp; + } } void two_swap(void) { - long two_deep, three_deep; - if ( min_stack_depth(4) ) - { - two_deep = dstack[2]; - three_deep = dstack[3]; - dstack[2] = dstack[0]; - dstack[3] = dstack[1]; - dstack[1] = three_deep; - dstack[0] = two_deep; - } + long two_deep, three_deep; + if (min_stack_depth(4)) { + two_deep = dstack[2]; + three_deep = dstack[3]; + dstack[2] = dstack[0]; + dstack[3] = dstack[1]; + dstack[1] = three_deep; + dstack[0] = two_deep; + } } - - diff --git a/toke/stack.h b/toke/stack.h index eedad0f..c3727cc 100644 --- a/toke/stack.h +++ b/toke/stack.h @@ -65,9 +65,9 @@ long dget(void); void clear_stack(void); void init_stack(void); -bool min_stack_depth(int mindep); /* TRUE if no error */ +bool min_stack_depth(int mindep); /* TRUE if no error */ long stackdepth(void); void swap(void); void two_swap(void); -#endif /* _TOKE_STACK_H */ +#endif /* _TOKE_STACK_H */ diff --git a/toke/stream.c b/toke/stream.c index 6e6a5a7..633fd6a 100644 --- a/toke/stream.c +++ b/toke/stream.c @@ -55,7 +55,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Still to be done: @@ -69,7 +68,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Global Variables Exported @@ -83,29 +81,27 @@ * **************************************************************************** */ - /* Input pointers, Position Counters and Length counters */ u8 *start = NULL; u8 *pc; u8 *end; char *iname = NULL; unsigned int lineno = 0; -unsigned int abs_token_no = 0; /* Absolute Token Number in all Source Input - * Will be used to identify position - * where colon-definition begins and - * to limit clearing of control-structs. - */ -static unsigned int ilen; /* Length of Input Buffer */ +unsigned int abs_token_no = 0; /* Absolute Token Number in all Source Input + * Will be used to identify position + * where colon-definition begins and + * to limit clearing of control-structs. + */ +static unsigned int ilen; /* Length of Input Buffer */ /* output pointers */ u8 *ostart; char *oname = NULL; - /* We want to limit exposure of this v'ble, so don't put it in .h file */ -unsigned int olen; /* Length of Output Buffer */ +unsigned int olen; /* Length of Output Buffer */ /* We want to limit exposure of this Imported Function, likewise. */ -void init_emit( void); +void init_emit(void); /* ************************************************************************** * @@ -136,11 +132,10 @@ static bool no_files_missing = TRUE; * **************************************************************************** */ -typedef struct incl_list -{ - char *dir_path; +typedef struct incl_list { + char *dir_path; struct incl_list *next; - } incl_list_t; +} incl_list_t; /* ************************************************************************** * @@ -157,7 +152,6 @@ static incl_list_t *include_list_next = NULL; static unsigned int max_dir_path_len = 0; static char *include_list_full_path = NULL; - /* ************************************************************************** * * Function name: add_to_include_list @@ -196,24 +190,24 @@ static char *include_list_full_path = NULL; * **************************************************************************** */ -void add_to_include_list( char *dir_compt) +void add_to_include_list(char *dir_compt) { - unsigned int new_path_len = strlen( dir_compt); - incl_list_t *new_i_l_e = safe_malloc( sizeof( incl_list_t), - "adding to include-list" ); - - new_i_l_e->dir_path = strdup( dir_compt); - new_i_l_e->next = NULL; - - if ( include_list_start == NULL ) - { - include_list_start = new_i_l_e; - }else{ - include_list_next->next = new_i_l_e; - } - - include_list_next = new_i_l_e; - if ( new_path_len > max_dir_path_len ) max_dir_path_len = new_path_len; + unsigned int new_path_len = strlen(dir_compt); + incl_list_t *new_i_l_e = safe_malloc(sizeof(incl_list_t), + "adding to include-list"); + + new_i_l_e->dir_path = strdup(dir_compt); + new_i_l_e->next = NULL; + + if (include_list_start == NULL) { + include_list_start = new_i_l_e; + } else { + include_list_next->next = new_i_l_e; + } + + include_list_next = new_i_l_e; + if (new_path_len > max_dir_path_len) + max_dir_path_len = new_path_len; } #define DISPLAY_WIDTH 80 @@ -247,32 +241,27 @@ void add_to_include_list( char *dir_compt) * **************************************************************************** */ -void display_include_list( void) +void display_include_list(void) { - if ( include_list_start != NULL ) - { - int curr_wid = DISPLAY_WIDTH; /* Current width; force new line */ - printf("\nInclude-List:"); - include_list_next = include_list_start ; - while ( include_list_next != NULL ) - { - int this_wid = strlen( include_list_next->dir_path) + 1; - char *separator = " "; - if ( curr_wid + this_wid > DISPLAY_WIDTH ) - { - separator = "\n\t"; - curr_wid = 7; /* Allow 1 for the theoretical space */ - } - printf("%s%s", separator, include_list_next->dir_path); - curr_wid += this_wid; - include_list_next = include_list_next->next ; + if (include_list_start != NULL) { + int curr_wid = DISPLAY_WIDTH; /* Current width; force new line */ + printf("\nInclude-List:"); + include_list_next = include_list_start; + while (include_list_next != NULL) { + int this_wid = strlen(include_list_next->dir_path) + 1; + char *separator = " "; + if (curr_wid + this_wid > DISPLAY_WIDTH) { + separator = "\n\t"; + curr_wid = 7; /* Allow 1 for the theoretical space */ + } + printf("%s%s", separator, include_list_next->dir_path); + curr_wid += this_wid; + include_list_next = include_list_next->next; + } + printf("\n"); } - printf("\n"); - } } - - /* ************************************************************************** * * We cannot accommodate the structures of the different @@ -324,19 +313,19 @@ void display_include_list( void) * **************************************************************************** */ -static void init_incl_list_scan( char *base_name) +static void init_incl_list_scan(char *base_name) { - if ( include_list_start != NULL ) - { - /* Allocate memory for the file-name buffer. - * maximum path-element length plus base-name length - * plus one for the slash plus one for the ending NULL - */ - unsigned int new_path_len = max_dir_path_len + strlen( base_name) + 2; - include_list_full_path = safe_malloc( new_path_len, - "scanning include-list" ); - include_list_next = include_list_start; - } + if (include_list_start != NULL) { + /* Allocate memory for the file-name buffer. + * maximum path-element length plus base-name length + * plus one for the slash plus one for the ending NULL + */ + unsigned int new_path_len = + max_dir_path_len + strlen(base_name) + 2; + include_list_full_path = + safe_malloc(new_path_len, "scanning include-list"); + include_list_next = include_list_start; + } } /* ************************************************************************** @@ -397,39 +386,37 @@ static void init_incl_list_scan( char *base_name) * **************************************************************************** */ -static bool scan_incl_list( char *base_name) +static bool scan_incl_list(char *base_name) { - bool retval = FALSE; /* default to "Done" */ - - if ( include_list_full_path == NULL ) - { - include_list_full_path = base_name; - retval = TRUE; - }else{ - if ( include_list_next != NULL ) - { - - /* Special case: If the next Directory Component is - * an empty string, do not prepend a slash; that - * would either become a root-based absolute path, - * or, if the base-name is itself an absolute path, - * it would be a path that begins with two slashes, - * and *some* Host Operating Systems ***REALLY*** - * DO NOT LIKE that! - */ - if ( strlen( include_list_next->dir_path) == 0 ) - { - sprintf( include_list_full_path, "%s", base_name); - }else{ - sprintf( include_list_full_path, "%s/%s", - include_list_next->dir_path, base_name); - } - include_list_next = include_list_next->next; - retval = TRUE; + bool retval = FALSE; /* default to "Done" */ + + if (include_list_full_path == NULL) { + include_list_full_path = base_name; + retval = TRUE; + } else { + if (include_list_next != NULL) { + + /* Special case: If the next Directory Component is + * an empty string, do not prepend a slash; that + * would either become a root-based absolute path, + * or, if the base-name is itself an absolute path, + * it would be a path that begins with two slashes, + * and *some* Host Operating Systems ***REALLY*** + * DO NOT LIKE that! + */ + if (strlen(include_list_next->dir_path) == 0) { + sprintf(include_list_full_path, "%s", + base_name); + } else { + sprintf(include_list_full_path, "%s/%s", + include_list_next->dir_path, base_name); + } + include_list_next = include_list_next->next; + retval = TRUE; + } } - } - return( retval); + return (retval); } /* ************************************************************************** @@ -457,19 +444,18 @@ static bool scan_incl_list( char *base_name) * **************************************************************************** */ -static void finish_incl_list_scan( bool op_succeeded) +static void finish_incl_list_scan(bool op_succeeded) { - if ( include_list_start != NULL ) - { - if ( op_succeeded ) - { - tokenization_error( INFO, - "File was found in %s\n" ,include_list_full_path ); + if (include_list_start != NULL) { + if (op_succeeded) { + tokenization_error(INFO, + "File was found in %s\n", + include_list_full_path); + } + free(include_list_full_path); } - free( include_list_full_path); - } - include_list_full_path = NULL; - include_list_next = NULL; + include_list_full_path = NULL; + include_list_next = NULL; } /* ************************************************************************** @@ -500,21 +486,19 @@ static void finish_incl_list_scan( bool op_succeeded) * **************************************************************************** */ -static FILE *open_incl_list_file( char *base_name, char *mode) +static FILE *open_incl_list_file(char *base_name, char *mode) { - FILE *retval = NULL; + FILE *retval = NULL; - init_incl_list_scan( base_name); - while ( scan_incl_list( base_name) ) - { - retval = fopen( include_list_full_path, mode); - if ( retval != NULL ) - { - break; + init_incl_list_scan(base_name); + while (scan_incl_list(base_name)) { + retval = fopen(include_list_full_path, mode); + if (retval != NULL) { + break; + } } - } - return (retval); + return (retval); } /* ************************************************************************** @@ -548,23 +532,21 @@ static FILE *open_incl_list_file( char *base_name, char *mode) * **************************************************************************** */ -static bool stat_incl_list_file( char *base_name, struct stat *file_info) +static bool stat_incl_list_file(char *base_name, struct stat *file_info) { - bool retval = FALSE; - int stat_reslt = -1; /* Success = 0 */ - - init_incl_list_scan( base_name); - while ( scan_incl_list( base_name) ) - { - stat_reslt = stat( include_list_full_path, file_info); - if ( stat_reslt == 0 ) - { - retval = TRUE; - break; + bool retval = FALSE; + int stat_reslt = -1; /* Success = 0 */ + + init_incl_list_scan(base_name); + while (scan_incl_list(base_name)) { + stat_reslt = stat(include_list_full_path, file_info); + if (stat_reslt == 0) { + retval = TRUE; + break; + } } - } - return (retval); + return (retval); } /* ************************************************************************** @@ -588,9 +570,9 @@ static bool stat_incl_list_file( char *base_name, struct stat *file_info) void init_inbuf(char *inbuf, unsigned int buflen) { - start = inbuf; - pc = start; - end = pc + buflen; + start = inbuf; + pc = start; + end = pc + buflen; } /* ************************************************************************** @@ -616,8 +598,8 @@ void init_inbuf(char *inbuf, unsigned int buflen) static void could_not_open(int severity, char *fle_nam, char *for_what) { - tokenization_error( severity, "Could not open file %s for %s.\n", - fle_nam, for_what); + tokenization_error(severity, "Could not open file %s for %s.\n", + fle_nam, for_what); } @@ -645,13 +627,12 @@ static void could_not_open(int severity, char *fle_nam, char *for_what) * **************************************************************************** */ -static void file_is_missing( char *fle_nam) +static void file_is_missing(char *fle_nam) { - if ( missing_list_file != NULL ) - { - fprintf( missing_list_file, "%s\n", fle_nam); - no_files_missing = FALSE; - } + if (missing_list_file != NULL) { + fprintf(missing_list_file, "%s\n", fle_nam); + no_files_missing = FALSE; + } } /* ************************************************************************** @@ -683,19 +664,16 @@ static void file_is_missing( char *fle_nam) * **************************************************************************** */ -static void add_to_load_lists( const char *in_name) +static void add_to_load_lists(const char *in_name) { - if ( load_list_file != NULL ) - { - fprintf( load_list_file, "%s\n", in_name); - } - if ( depncy_file != NULL ) - { - fprintf( depncy_file, "%s\n", include_list_full_path); - } + if (load_list_file != NULL) { + fprintf(load_list_file, "%s\n", in_name); + } + if (depncy_file != NULL) { + fprintf(depncy_file, "%s\n", include_list_full_path); + } } - /* ************************************************************************** * * In the functions that support accessing files whose path-names @@ -708,7 +686,7 @@ static void add_to_load_lists( const char *in_name) * **************************************************************************** */ -static char expansion_buffer[ 2*GET_BUF_MAX]; +static char expansion_buffer[2 * GET_BUF_MAX]; static bool was_expanded; static int expansion_msg_severity = INFO; @@ -734,16 +712,15 @@ static int expansion_msg_severity = INFO; * **************************************************************************** */ -static void expanded_name( void ) +static void expanded_name(void) { - if ( was_expanded ) - { - tokenization_error( expansion_msg_severity, - "File name expanded to: %s\n", expansion_buffer); - } + if (was_expanded) { + tokenization_error(expansion_msg_severity, + "File name expanded to: %s\n", + expansion_buffer); + } } - /* ************************************************************************** * * Function name: expansion_error @@ -783,17 +760,15 @@ static void expanded_name( void ) * **************************************************************************** */ -static void expansion_error( void ) +static void expansion_error(void) { - if ( INVERSE( verbose) ) - { - expansion_msg_severity |= FORCE_MSG; - expanded_name(); - expansion_msg_severity ^= FORCE_MSG; - } + if (INVERSE(verbose)) { + expansion_msg_severity |= FORCE_MSG; + expanded_name(); + expansion_msg_severity ^= FORCE_MSG; + } } - /* ************************************************************************** * * Function name: expand_pathname @@ -897,56 +872,52 @@ static void expansion_error( void ) * **************************************************************************** */ -static char *expand_pathname( const char *input_pathname) +static char *expand_pathname(const char *input_pathname) { - static const int buffer_max = GET_BUF_MAX * 2; - - char *retval = (char *)input_pathname; - was_expanded = FALSE; - - /* If no '$' is found, expansion is unnecessary. */ - if ( strchr( input_pathname, '$') != NULL ) - { - FILE *temp_file; - int syst_stat; - const char *temp_file_name = tmpnam( NULL); - - /* Use the expansion buffer for our temporary command string */ - sprintf( expansion_buffer, - "echo %s>%s\n", input_pathname, temp_file_name); - syst_stat = system( expansion_buffer); - if ( syst_stat != 0 ) - { - tokenization_error( TKERROR, - "Expansion Syntax.\n"); - /* The "File-Opening" error message will show the input string */ - return( NULL); - } + static const int buffer_max = GET_BUF_MAX * 2; + + char *retval = (char *)input_pathname; + was_expanded = FALSE; + + /* If no '$' is found, expansion is unnecessary. */ + if (strchr(input_pathname, '$') != NULL) { + FILE *temp_file; + int syst_stat; + const char *temp_file_name = tmpnam(NULL); + + /* Use the expansion buffer for our temporary command string */ + sprintf(expansion_buffer, + "echo %s>%s\n", input_pathname, temp_file_name); + syst_stat = system(expansion_buffer); + if (syst_stat != 0) { + tokenization_error(TKERROR, "Expansion Syntax.\n"); + /* The "File-Opening" error message will show the input string */ + return (NULL); + } - temp_file = fopen( temp_file_name, "r"); /* Cannot fail. */ - syst_stat = fread( expansion_buffer, 1, buffer_max, temp_file); - /* Error test. Length of what we read is not a good indicator; - * it's limited anyway by buffer_max. - * Valid test is if last character read was the new-line. - */ - if ( expansion_buffer[syst_stat-1] != '\n' ) - { - tokenization_error( TKERROR, - "Expansion buffer overflow. Max length is %d.\n", - buffer_max); - retval = NULL; - }else{ - expansion_buffer[syst_stat-1] =0; - was_expanded = TRUE; - retval = expansion_buffer; - expanded_name(); - } + temp_file = fopen(temp_file_name, "r"); /* Cannot fail. */ + syst_stat = fread(expansion_buffer, 1, buffer_max, temp_file); + /* Error test. Length of what we read is not a good indicator; + * it's limited anyway by buffer_max. + * Valid test is if last character read was the new-line. + */ + if (expansion_buffer[syst_stat - 1] != '\n') { + tokenization_error(TKERROR, + "Expansion buffer overflow. Max length is %d.\n", + buffer_max); + retval = NULL; + } else { + expansion_buffer[syst_stat - 1] = 0; + was_expanded = TRUE; + retval = expansion_buffer; + expanded_name(); + } - fclose( temp_file); - remove( temp_file_name); - } + fclose(temp_file); + remove(temp_file_name); + } - return( retval); + return (retval); } /* ************************************************************************** @@ -975,27 +946,26 @@ static char *expand_pathname( const char *input_pathname) * **************************************************************************** */ -FILE *open_expanded_file( const char *path_name, char *mode, char *for_what) +FILE *open_expanded_file(const char *path_name, char *mode, char *for_what) { - FILE *retval = NULL; + FILE *retval = NULL; - char *infile_name = expand_pathname( path_name); - if ( infile_name != NULL ) - { - retval = open_incl_list_file( infile_name, mode); - } + char *infile_name = expand_pathname(path_name); + if (infile_name != NULL) { + retval = open_incl_list_file(infile_name, mode); + } - if ( retval == NULL ) - { - expansion_error(); - tokenization_error ( TKERROR, - "Failed to open file %s for %s\n", path_name, for_what ); - } + if (retval == NULL) { + expansion_error(); + tokenization_error(TKERROR, + "Failed to open file %s for %s\n", path_name, + for_what); + } - finish_incl_list_scan( BOOLVAL( retval != NULL) ); + finish_incl_list_scan(BOOLVAL(retval != NULL)); - return( retval); + return (retval); } /* ************************************************************************** @@ -1075,144 +1045,136 @@ FILE *open_expanded_file( const char *path_name, char *mode, char *for_what) * **************************************************************************** */ -bool init_stream( const char *name) +bool init_stream(const char *name) { - FILE *infile; - u8 *newbuf; + FILE *infile; + u8 *newbuf; struct stat finfo; - bool stat_succ = FALSE; - bool tried_stat = FALSE; - bool retval = FALSE; - bool inp_fil_acc_err = FALSE; - bool inp_fil_open_err = FALSE; - bool inp_fil_read_err = FALSE; - - char *infile_name = expand_pathname( name); - - if ( (infile_name != NULL) ) - { - tried_stat = TRUE; - stat_succ = stat_incl_list_file( infile_name, &finfo); - } - - if ( INVERSE( stat_succ) ) - { - inp_fil_acc_err = TRUE; - }else{ - - infile = fopen( include_list_full_path, "r"); - if ( infile == NULL ) - { - inp_fil_open_err = TRUE; - }else{ - - ilen=finfo.st_size; - newbuf = safe_malloc(ilen+1, "initting stream"); - - if ( fread( newbuf, ilen, 1, infile) != 1 ) - { - inp_fil_read_err = TRUE; - free( newbuf ); - } else { - unsigned int i; - - retval = TRUE ; - /* Replace zeroes in the file with LineFeeds. */ - /* Replace carr-rets with spaces. */ - for (i=0; iname = ename; - new_entry->alias = subst_str; - new_entry->next = *str_sub_vocab; + new_entry = + safe_malloc(sizeof(str_sub_vocab_t), "adding str_sub_entry"); + new_entry->name = ename; + new_entry->alias = subst_str; + new_entry->next = *str_sub_vocab; - *str_sub_vocab = new_entry; + *str_sub_vocab = new_entry; } - /* ************************************************************************** * * Function name: lookup_str_sub @@ -138,20 +136,18 @@ void add_str_sub_entry( char *ename, * **************************************************************************** */ -str_sub_vocab_t *lookup_str_sub( char *tname, str_sub_vocab_t *str_sub_vocab ) +str_sub_vocab_t *lookup_str_sub(char *tname, str_sub_vocab_t * str_sub_vocab) { - str_sub_vocab_t *curr; - str_sub_vocab_t *retval = NULL; - - for (curr = str_sub_vocab ; curr != NULL ; curr=curr->next) - { - if ( strcasecmp(tname, curr->name) == 0 ) - { - retval = curr; - break; + str_sub_vocab_t *curr; + str_sub_vocab_t *retval = NULL; + + for (curr = str_sub_vocab; curr != NULL; curr = curr->next) { + if (strcasecmp(tname, curr->name) == 0) { + retval = curr; + break; + } } - } - return ( retval ) ; + return (retval); } /* ************************************************************************** @@ -170,17 +166,15 @@ str_sub_vocab_t *lookup_str_sub( char *tname, str_sub_vocab_t *str_sub_vocab ) * **************************************************************************** */ -bool exists_in_str_sub( char *tname, str_sub_vocab_t *str_sub_vocab ) +bool exists_in_str_sub(char *tname, str_sub_vocab_t * str_sub_vocab) { - bool retval = FALSE; - str_sub_vocab_t *found = NULL; + bool retval = FALSE; + str_sub_vocab_t *found = NULL; - found = lookup_str_sub( tname, str_sub_vocab ); - if ( found != NULL ) - { - retval = TRUE; - } - return ( retval ); + found = lookup_str_sub(tname, str_sub_vocab); + if (found != NULL) { + retval = TRUE; + } + return (retval); } - diff --git a/toke/strsubvocab.h b/toke/strsubvocab.h index cc5ff81..334bb60 100644 --- a/toke/strsubvocab.h +++ b/toke/strsubvocab.h @@ -1,7 +1,6 @@ #ifndef _TOKE_STRSUBVOCAB_H #define _TOKE_STRSUBVOCAB_H - /* * OpenBIOS - free your system! * ( FCode tokenizer ) @@ -48,19 +47,15 @@ #include "types.h" - typedef struct str_sub_vocab { - u8 *name; - u8 *alias; + u8 *name; + u8 *alias; struct str_sub_vocab *next; } str_sub_vocab_t; +void add_str_sub_entry(char *ename, + char *subst_str, str_sub_vocab_t ** str_sub_vocab); +str_sub_vocab_t *lookup_str_sub(char *tname, str_sub_vocab_t * str_sub_vocab); +bool exists_in_str_sub(char *tname, str_sub_vocab_t * str_sub_vocab); -void add_str_sub_entry( char *ename, - char *subst_str, - str_sub_vocab_t **str_sub_vocab ); -str_sub_vocab_t *lookup_str_sub( char *tname, str_sub_vocab_t *str_sub_vocab ); -bool exists_in_str_sub( char *tname, str_sub_vocab_t *str_sub_vocab ); - - -#endif /* _TOKE_STRSUBVOCAB_H */ +#endif /* _TOKE_STRSUBVOCAB_H */ diff --git a/toke/ticvocab.c b/toke/ticvocab.c index 3e96716..feb7584 100644 --- a/toke/ticvocab.c +++ b/toke/ticvocab.c @@ -70,7 +70,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Functions Exported: @@ -87,7 +86,6 @@ * **************************************************************************** */ - /* ************************************************************************** * * Global Variables Exported @@ -99,7 +97,6 @@ * **************************************************************************** */ - #include #include @@ -145,20 +142,17 @@ tic_hdr_t *tic_found; * **************************************************************************** */ -void init_tic_vocab( tic_hdr_t *tic_vocab_tbl, - int max_indx, - tic_hdr_t **tic_vocab_ptr) +void init_tic_vocab(tic_hdr_t * tic_vocab_tbl, + int max_indx, tic_hdr_t ** tic_vocab_ptr) { - int indx; - for ( indx = 0 ; indx < max_indx ; indx++ ) - { - tic_vocab_tbl[indx].next = *tic_vocab_ptr; - *tic_vocab_ptr = &tic_vocab_tbl[indx]; - trace_builtin( &tic_vocab_tbl[indx]); - } + int indx; + for (indx = 0; indx < max_indx; indx++) { + tic_vocab_tbl[indx].next = *tic_vocab_ptr; + *tic_vocab_ptr = &tic_vocab_tbl[indx]; + trace_builtin(&tic_vocab_tbl[indx]); + } } - /* ************************************************************************** * * Function name: make_tic_entry @@ -207,33 +201,31 @@ void init_tic_vocab( tic_hdr_t *tic_vocab_tbl, * **************************************************************************** */ -static tic_hdr_t *make_tic_entry( char *tname, - void (*tfunct)(), - TIC_P_DEFLT_TYPE tparam, - fwtoken fw_defr, - int pfldsiz, - bool is_single, - void (*ign_fnc)(), - bool trace_this, - tic_hdr_t **tic_vocab ) +static tic_hdr_t *make_tic_entry(char *tname, + void (*tfunct)(), + TIC_P_DEFLT_TYPE tparam, + fwtoken fw_defr, + int pfldsiz, + bool is_single, + void(*ign_fnc)(), + bool trace_this, tic_hdr_t ** tic_vocab) { - tic_hdr_t *new_entry; - - new_entry = safe_malloc(sizeof(tic_hdr_t), "adding tic_entry"); - new_entry->name = tname; - new_entry->next = *tic_vocab; - new_entry->funct = tfunct; - new_entry->pfield.deflt_elem = tparam; - new_entry->fword_defr = fw_defr; - new_entry->is_token = is_single; - new_entry->ign_func = ign_fnc; - new_entry->pfld_size = pfldsiz; - new_entry->tracing = trace_this; - - return( new_entry); + tic_hdr_t *new_entry; + + new_entry = safe_malloc(sizeof(tic_hdr_t), "adding tic_entry"); + new_entry->name = tname; + new_entry->next = *tic_vocab; + new_entry->funct = tfunct; + new_entry->pfield.deflt_elem = tparam; + new_entry->fword_defr = fw_defr; + new_entry->is_token = is_single; + new_entry->ign_func = ign_fnc; + new_entry->pfld_size = pfldsiz; + new_entry->tracing = trace_this; + + return (new_entry); } - /* ************************************************************************** * * Function name: add_tic_entry @@ -284,31 +276,28 @@ static tic_hdr_t *make_tic_entry( char *tname, * **************************************************************************** */ -void add_tic_entry( char *tname, - void (*tfunct)(), - TIC_P_DEFLT_TYPE tparam, - fwtoken fw_defr, - int pfldsiz, - bool is_single, - void (*ign_fnc)(), - tic_hdr_t **tic_vocab ) +void add_tic_entry(char *tname, + void (*tfunct)(), + TIC_P_DEFLT_TYPE tparam, + fwtoken fw_defr, + int pfldsiz, + bool is_single, void(*ign_fnc)(), tic_hdr_t ** tic_vocab) { - bool trace_this = is_on_trace_list( tname); - tic_hdr_t *new_entry = make_tic_entry( tname, - tfunct, - tparam, - fw_defr, pfldsiz, - is_single, - ign_fnc, - trace_this, - tic_vocab ); - - if ( trace_this ) - { - trace_creation( new_entry, NULL, scope_is_global); - } - warn_if_duplicate( tname); - *tic_vocab = new_entry; + bool trace_this = is_on_trace_list(tname); + tic_hdr_t *new_entry = make_tic_entry(tname, + tfunct, + tparam, + fw_defr, pfldsiz, + is_single, + ign_fnc, + trace_this, + tic_vocab); + + if (trace_this) { + trace_creation(new_entry, NULL, scope_is_global); + } + warn_if_duplicate(tname); + *tic_vocab = new_entry; } @@ -334,20 +323,18 @@ void add_tic_entry( char *tname, * for instance, duplicate-name checking... * **************************************************************************** */ - -tic_hdr_t *lookup_tic_entry( char *tname, tic_hdr_t *tic_vocab ) + +tic_hdr_t *lookup_tic_entry(char *tname, tic_hdr_t * tic_vocab) { - tic_hdr_t *curr ; + tic_hdr_t *curr; - for (curr = tic_vocab ; curr != NULL ; curr=curr->next) - { - if ( strcasecmp(tname, curr->name) == 0 ) - { - break; + for (curr = tic_vocab; curr != NULL; curr = curr->next) { + if (strcasecmp(tname, curr->name) == 0) { + break; + } } - } - return ( curr ) ; + return (curr); } /* ************************************************************************** @@ -366,21 +353,19 @@ tic_hdr_t *lookup_tic_entry( char *tname, tic_hdr_t *tic_vocab ) * **************************************************************************** */ -bool exists_in_tic_vocab( char *tname, tic_hdr_t *tic_vocab ) +bool exists_in_tic_vocab(char *tname, tic_hdr_t * tic_vocab) { - tic_hdr_t *found ; - bool retval = FALSE; + tic_hdr_t *found; + bool retval = FALSE; - found = lookup_tic_entry( tname, tic_vocab ); - if ( found != NULL ) - { - retval = TRUE; - } + found = lookup_tic_entry(tname, tic_vocab); + if (found != NULL) { + retval = TRUE; + } - return ( retval ); + return (retval); } - /* ************************************************************************** * * Function name: create_split_alias @@ -439,39 +424,35 @@ bool exists_in_tic_vocab( char *tname, tic_hdr_t *tic_vocab ) * **************************************************************************** */ -bool create_split_alias( char *new_name, char *old_name, - tic_hdr_t **src_vocab, tic_hdr_t **dest_vocab ) +bool create_split_alias(char *new_name, char *old_name, + tic_hdr_t ** src_vocab, tic_hdr_t ** dest_vocab) { - tic_hdr_t *found ; - bool retval = FALSE; - - found = lookup_tic_entry( old_name, *src_vocab ); - if ( found != NULL ) - { - bool trace_it = found->tracing; - if ( ! trace_it ) - { - trace_it = is_on_trace_list( new_name); + tic_hdr_t *found; + bool retval = FALSE; + + found = lookup_tic_entry(old_name, *src_vocab); + if (found != NULL) { + bool trace_it = found->tracing; + if (!trace_it) { + trace_it = is_on_trace_list(new_name); + } + if (trace_it) { + bool old_is_global = BOOLVAL(src_vocab != dest_vocab); + trace_creation(found, new_name, old_is_global); + } + warn_if_duplicate(new_name); + + *dest_vocab = make_tic_entry(new_name, + found->funct, + found->pfield.deflt_elem, + found->fword_defr, 0, + found->is_token, + found->ign_func, + trace_it, dest_vocab); + retval = TRUE; } - if ( trace_it ) - { - bool old_is_global = BOOLVAL( src_vocab != dest_vocab ); - trace_creation( found, new_name, old_is_global); - } - warn_if_duplicate( new_name); - - *dest_vocab = make_tic_entry( new_name, - found->funct, - found->pfield.deflt_elem, - found->fword_defr, 0, - found->is_token, - found->ign_func, - trace_it, - dest_vocab ); - retval = TRUE; - } - - return ( retval ); + + return (retval); } /* ************************************************************************** @@ -504,12 +485,11 @@ bool create_split_alias( char *new_name, char *old_name, **************************************************************************** */ -bool create_tic_alias( char *new_name, char *old_name, tic_hdr_t **tic_vocab ) +bool create_tic_alias(char *new_name, char *old_name, tic_hdr_t ** tic_vocab) { - return ( create_split_alias( new_name, old_name, tic_vocab, tic_vocab ) ); + return (create_split_alias(new_name, old_name, tic_vocab, tic_vocab)); } - /* ************************************************************************** * * Function name: handle_tic_vocab @@ -536,19 +516,18 @@ bool create_tic_alias( char *new_name, char *old_name, tic_hdr_t **tic_vocab ) * to decide how to proceed. * **************************************************************************** */ - -bool handle_tic_vocab( char *tname, tic_hdr_t *tic_vocab ) + +bool handle_tic_vocab(char *tname, tic_hdr_t * tic_vocab) { - bool retval = FALSE; - - tic_found = lookup_tic_entry( tname, tic_vocab ); - if ( tic_found != NULL ) - { - tic_found->funct( tic_found->pfield); - retval = TRUE; - } - - return ( retval ) ; + bool retval = FALSE; + + tic_found = lookup_tic_entry(tname, tic_vocab); + if (tic_found != NULL) { + tic_found->funct(tic_found->pfield); + retval = TRUE; + } + + return (retval); } /* ************************************************************************** @@ -580,21 +559,19 @@ bool handle_tic_vocab( char *tname, tic_hdr_t *tic_vocab ) * **************************************************************************** */ -void reset_tic_vocab( tic_hdr_t **tic_vocab, tic_hdr_t *reset_position ) +void reset_tic_vocab(tic_hdr_t ** tic_vocab, tic_hdr_t * reset_position) { - tic_hdr_t *next_t; - - next_t = *tic_vocab; - while ( next_t != reset_position ) - { - next_t = (*tic_vocab)->next ; - - free( (*tic_vocab)->name ); - if ( (*tic_vocab)->pfld_size != 0 ) - { - free( (*tic_vocab)->pfield.chr_ptr ); + tic_hdr_t *next_t; + + next_t = *tic_vocab; + while (next_t != reset_position) { + next_t = (*tic_vocab)->next; + + free((*tic_vocab)->name); + if ((*tic_vocab)->pfld_size != 0) { + free((*tic_vocab)->pfield.chr_ptr); + } + free(*tic_vocab); + *tic_vocab = next_t; } - free( *tic_vocab ); - *tic_vocab = next_t ; - } } diff --git a/toke/ticvocab.h b/toke/ticvocab.h index 8dc9301..ef8a4fe 100644 --- a/toke/ticvocab.h +++ b/toke/ticvocab.h @@ -157,36 +157,34 @@ **************************************************************************** */ #define TIC_P_DEFLT_TYPE long -typedef union tic_param - { - TIC_P_DEFLT_TYPE deflt_elem ; /* The "default element" aspect. */ - long long_val ; /* Explicitly specifying "long" */ - fwtoken fw_token ; /* FWord Token */ - bool *bool_ptr ; /* Pointer to a boolean variable */ - char *chr_ptr ; /* Pointer to a character string */ +typedef union tic_param { + TIC_P_DEFLT_TYPE deflt_elem; /* The "default element" aspect. */ + long long_val; /* Explicitly specifying "long" */ + fwtoken fw_token; /* FWord Token */ + bool *bool_ptr; /* Pointer to a boolean variable */ + char *chr_ptr; /* Pointer to a character string */ /* The "character value" aspect behaves differently on big- * versus little- -endian platforms (for initialization, * anyway), so we cannot actually use it. * Keep this commented-out, as a reminder. */ - /* char char_val ; */ + /* char char_val ; */ /* We will recast "character value" as an integer. */ - } tic_param_t ; - -typedef struct tic_hdr - { - char *name; - struct tic_hdr *next; - void (*funct)(); /* Function for active processing */ - tic_param_t pfield; - fwtoken fword_defr; /* FWord Token of entry's Definer */ - bool is_token; /* Is entry a single-token FCode? */ - void (*ign_func)(); /* Function in "Ignored" segment */ - int pfld_size; - bool tracing; /* TRUE if Invoc'n Msg required */ - } tic_hdr_t ; +} tic_param_t; + +typedef struct tic_hdr { + char *name; + struct tic_hdr *next; + void (*funct)(); /* Function for active processing */ + tic_param_t pfield; + fwtoken fword_defr; /* FWord Token of entry's Definer */ + bool is_token; /* Is entry a single-token FCode? */ + void (*ign_func)(); /* Function in "Ignored" segment */ + int pfld_size; + bool tracing; /* TRUE if Invoc'n Msg required */ +} tic_hdr_t; /* ************************************************************************** * @@ -195,28 +193,25 @@ typedef struct tic_hdr **************************************************************************** */ #define TIC_FWT_P_DEFLT_TYPE fwtoken -typedef union tic_fwt_param - { - TIC_FWT_P_DEFLT_TYPE deflt_elem ; /* "Default element" aspect. */ - long long_val ; /* Long integer */ - fwtoken fw_token ; /* Explicit FWord Token */ - bool *bool_ptr ; /* Pointer to a boolean variable */ - char *chr_ptr ; /* Pointer to a character string */ - } tic_fwt_param_t ; - -typedef struct tic_fwt_hdr - { - char *name; +typedef union tic_fwt_param { + TIC_FWT_P_DEFLT_TYPE deflt_elem; /* "Default element" aspect. */ + long long_val; /* Long integer */ + fwtoken fw_token; /* Explicit FWord Token */ + bool *bool_ptr; /* Pointer to a boolean variable */ + char *chr_ptr; /* Pointer to a character string */ +} tic_fwt_param_t; + +typedef struct tic_fwt_hdr { + char *name; struct tic_fwt_hdr *next; - void (*funct)(); /* Function for active processing */ - tic_fwt_param_t pfield; - fwtoken fword_defr; /* FWord Token of entry's Definer */ - bool is_token; /* Is entry a single-token FCode? */ - void (*ign_func)(); /* Function in "Ignored" segment */ - int pfld_size; - bool tracing; /* TRUE if Invoc'n Msg required */ - } tic_fwt_hdr_t ; - + void (*funct)(); /* Function for active processing */ + tic_fwt_param_t pfield; + fwtoken fword_defr; /* FWord Token of entry's Definer */ + bool is_token; /* Is entry a single-token FCode? */ + void (*ign_func)(); /* Function in "Ignored" segment */ + int pfld_size; + bool tracing; /* TRUE if Invoc'n Msg required */ +} tic_fwt_hdr_t; /* ************************************************************************** * @@ -231,27 +226,25 @@ typedef struct tic_fwt_hdr **************************************************************************** */ #define TIC_MAC_P_DEFLT_TYPE char * -typedef union tic_mac_param - { - TIC_MAC_P_DEFLT_TYPE deflt_elem ; /* "Default element" aspect. */ - long long_val ; /* Long integer */ - fwtoken fw_token ; /* FWord Token */ - bool *bool_ptr ; /* Pointer to a boolean variable */ - char *chr_ptr ; /* Explicit Pointer to char str. */ - } tic_mac_param_t ; - -typedef struct tic_mac_hdr - { - char *name; +typedef union tic_mac_param { + TIC_MAC_P_DEFLT_TYPE deflt_elem; /* "Default element" aspect. */ + long long_val; /* Long integer */ + fwtoken fw_token; /* FWord Token */ + bool *bool_ptr; /* Pointer to a boolean variable */ + char *chr_ptr; /* Explicit Pointer to char str. */ +} tic_mac_param_t; + +typedef struct tic_mac_hdr { + char *name; struct tic_mac_hdr *next; - void (*funct)(); - tic_mac_param_t pfield; - fwtoken fword_defr; - bool is_token; /* Is entry a single-token FCode? */ - void (*ign_func)(); - int pfld_size; - bool tracing; /* TRUE if Invoc'n Msg required */ - } tic_mac_hdr_t ; + void (*funct)(); + tic_mac_param_t pfield; + fwtoken fword_defr; + bool is_token; /* Is entry a single-token FCode? */ + void (*ign_func)(); + int pfld_size; + bool tracing; /* TRUE if Invoc'n Msg required */ +} tic_mac_hdr_t; /* ************************************************************************** * @@ -261,29 +254,25 @@ typedef struct tic_mac_hdr **************************************************************************** */ #define TIC_BOOL_P_DEFLT_TYPE bool * -typedef union tic_bool_param - { - TIC_BOOL_P_DEFLT_TYPE deflt_elem ; /* "Default element" aspect. */ - long long_val ; /* Long integer */ - fwtoken fw_token ; /* FWord Token */ - bool *bool_ptr ; /* Explicit Ptr to boolean v'ble */ - char *chr_ptr ; /* Pointer to a character string */ - } tic_bool_param_t ; - -typedef struct tic_bool_hdr - { - char *name; +typedef union tic_bool_param { + TIC_BOOL_P_DEFLT_TYPE deflt_elem; /* "Default element" aspect. */ + long long_val; /* Long integer */ + fwtoken fw_token; /* FWord Token */ + bool *bool_ptr; /* Explicit Ptr to boolean v'ble */ + char *chr_ptr; /* Pointer to a character string */ +} tic_bool_param_t; + +typedef struct tic_bool_hdr { + char *name; struct tic_bool_hdr *next; - void (*funct)(); - tic_bool_param_t pfield; - fwtoken fword_defr; - bool is_token; /* Is entry a single-token FCode? */ - void (*ign_func)(); - int pfld_size; - bool tracing; /* TRUE if Invoc'n Msg required */ - } tic_bool_hdr_t ; - - + void (*funct)(); + tic_bool_param_t pfield; + fwtoken fword_defr; + bool is_token; /* Is entry a single-token FCode? */ + void (*ign_func)(); + int pfld_size; + bool tracing; /* TRUE if Invoc'n Msg required */ +} tic_bool_hdr_t; /* ************************************************************************** * @@ -313,7 +302,6 @@ typedef struct tic_bool_hdr { nam , (tic_hdr_t *)NULL , func , \ { 0 }, UNSPECIFIED , FALSE , NULL , 0 , FALSE } - /* ************************************************************************** * Macro Name: NO_PARAM_IGN * Create an entry with an empty "param field" @@ -330,7 +318,6 @@ typedef struct tic_bool_hdr { nam , (tic_hdr_t *)NULL , func , \ { 0 }, UNSPECIFIED , FALSE , func , 0 , FALSE } - /* ************************************************************************** * * Variations on the above, to compensate for Type-Casting complications @@ -358,7 +345,6 @@ typedef struct tic_bool_hdr { nam , (tic_hdr_t *)NULL , func , \ { (TIC_P_DEFLT_TYPE)(pval) }, definr , is_tok , NULL , 0 , FALSE } - /* ************************************************************************** * Macro Name: DUALFUNC_TIC * Create an entry in the initial "Built-In" portion @@ -387,7 +373,6 @@ typedef struct tic_bool_hdr { nam , (tic_fwt_hdr_t *)NULL , afunc , \ { (TIC_FWT_P_DEFLT_TYPE)(pval) }, definr , FALSE , ifunc , 0 , FALSE } - /* ************************************************************************** * Macro Name: FWORD_TKN_TIC * Create an entry in the initial "Built-In" portion @@ -451,7 +436,6 @@ typedef struct tic_bool_hdr { nam , (tic_mac_hdr_t *)NULL , func , { alias }, \ MACRO_DEF , FALSE , NULL , 0 , FALSE } - /* ************************************************************************** * Macro Name: BUILTIN_BOOL_TIC * Create an entry in the initial "Built-In" portion @@ -474,7 +458,6 @@ typedef struct tic_bool_hdr { nam , (tic_bool_hdr_t *)NULL , func , { &bool_vbl }, \ COMMON_FWORD , FALSE , func , 0 , FALSE } - /* ************************************************************************** * * Exported Variables and Function Prototypes the rest of the way... @@ -483,23 +466,20 @@ typedef struct tic_bool_hdr extern tic_hdr_t *tic_found; -void init_tic_vocab( tic_hdr_t *tic_vocab_tbl, - int max_indx, - tic_hdr_t **tic_vocab_ptr); -void add_tic_entry( char *tname, - void (*tfunct)(), - TIC_P_DEFLT_TYPE tparam, - fwtoken fw_defr, - int pfldsiz, - bool is_single, - void (*ign_fnc)(), - tic_hdr_t **tic_vocab ); -tic_hdr_t *lookup_tic_entry( char *tname, tic_hdr_t *tic_vocab ); -bool exists_in_tic_vocab( char *tname, tic_hdr_t *tic_vocab ); -bool handle_tic_vocab( char *tname, tic_hdr_t *tic_vocab ); -bool create_split_alias( char *new_name, char *old_name, - tic_hdr_t **src_vocab, tic_hdr_t **dest_vocab ); -bool create_tic_alias( char *new_name, char *old_name, tic_hdr_t **tic_vocab ); -void reset_tic_vocab( tic_hdr_t **tic_vocab, tic_hdr_t *reset_position ); - -#endif /* _TOKE_TICVOCAB_H */ +void init_tic_vocab(tic_hdr_t * tic_vocab_tbl, + int max_indx, tic_hdr_t ** tic_vocab_ptr); +void add_tic_entry(char *tname, + void (*tfunct)(), + TIC_P_DEFLT_TYPE tparam, + fwtoken fw_defr, + int pfldsiz, + bool is_single, void(*ign_fnc)(), tic_hdr_t ** tic_vocab); +tic_hdr_t *lookup_tic_entry(char *tname, tic_hdr_t * tic_vocab); +bool exists_in_tic_vocab(char *tname, tic_hdr_t * tic_vocab); +bool handle_tic_vocab(char *tname, tic_hdr_t * tic_vocab); +bool create_split_alias(char *new_name, char *old_name, + tic_hdr_t ** src_vocab, tic_hdr_t ** dest_vocab); +bool create_tic_alias(char *new_name, char *old_name, tic_hdr_t ** tic_vocab); +void reset_tic_vocab(tic_hdr_t ** tic_vocab, tic_hdr_t * reset_position); + +#endif /* _TOKE_TICVOCAB_H */ diff --git a/toke/toke.c b/toke/toke.c index e933cec..92a1bba 100644 --- a/toke/toke.c +++ b/toke/toke.c @@ -74,9 +74,9 @@ * **************************************************************************** */ -bool verbose = FALSE; -bool noerrors = FALSE; -bool fload_list = FALSE; +bool verbose = FALSE; +bool noerrors = FALSE; +bool fload_list = FALSE; bool dependency_list = FALSE; /* ************************************************************************** @@ -99,14 +99,14 @@ static char *outputname = NULL; **************************************************************************** */ static void print_copyright(void) { - printf( "Welcome to toke - FCode tokenizer v" TOKE_VERSION "\n" - CORE_COPYR "\n" IBM_COPYR "\n" - "This program is free software; you may redistribute it " - "under the terms of\nthe GNU General Public License v2. " - "This program has absolutely no warranty.\n\n"); + printf("Welcome to toke - FCode tokenizer v" TOKE_VERSION "\n" + CORE_COPYR "\n" IBM_COPYR "\n" + "This program is free software; you may redistribute it " + "under the terms of\nthe GNU General Public License v2. " + "This program has absolutely no warranty.\n\n"); #ifdef DEVEL - /* Temporary hack during development... */ - printf( "\tTokenizer Compiled " DATE_STAMP "\n" ); + /* Temporary hack during development... */ + printf("\tTokenizer Compiled " DATE_STAMP "\n"); #endif /* DEVEL */ } @@ -121,8 +121,8 @@ static void print_copyright(void) static void usage(char *name) { printf("usage: %s [-v] [-i] [-l] [-P] [-o target] <[-d name[=value]]> " - "<[-f [no]flagname]> <[-I dir-path]> " - "<[-T symbol]> \n\n",name); + "<[-f [no]flagname]> <[-I dir-path]> " + "<[-T symbol]> \n\n", name); printf(" -v|--verbose print Advisory messages\n"); printf(" -i|--ignore-errors don't suppress output after errors\n"); printf(" -l|--load-list create list of FLoaded file names\n"); @@ -225,9 +225,9 @@ static void usage(char *name) * **************************************************************************** */ -static void get_args( int argc, char **argv ) +static void get_args(int argc, char **argv) { - const char *optstring="vhilPo:d:f:I:T:?"; + const char *optstring = "vhilPo:d:f:I:T:?"; int c; int argindx = 0; bool inval_opt = FALSE; @@ -241,20 +241,20 @@ static void get_args( int argc, char **argv ) { "verbose", 0, 0, 'v' }, { "help", 0, 0, 'h' }, { "ignore-errors", 0, 0, 'i' }, - { "load-list", 0, 0, 'l' }, - { "dependencies", 0, 0, 'P' }, - { "output-name", 1, 0, 'o' }, - { "define", 1, 0, 'd' }, - { "flag", 1, 0, 'f' }, - { "Include", 1, 0, 'I' }, - { "Trace", 1, 0, 'T' }, + { "load-list", 0, 0, 'l' }, + { "dependencies", 0, 0, 'P' }, + { "output-name", 1, 0, 'o' }, + { "define", 1, 0, 'd' }, + { "flag", 1, 0, 'f' }, + { "Include", 1, 0, 'I' }, + { "Trace", 1, 0, 'T' }, { 0, 0, 0, 0 } }; - c = getopt_long (argc, argv, optstring, - long_options, &option_index); + c = getopt_long(argc, argv, optstring, + long_options, &option_index); #else - c = getopt (argc, argv, optstring); + c = getopt(argc, argv, optstring); #endif if (c == -1) break; @@ -262,7 +262,7 @@ static void get_args( int argc, char **argv ) argindx++; switch (c) { case 'v': - verbose=TRUE; + verbose = TRUE; break; case 'o': outputname = optarg; @@ -278,17 +278,17 @@ static void get_args( int argc, char **argv ) break; case 'd': { - char *user_symb = optarg; - add_user_symbol(user_symb); + char *user_symb = optarg; + add_user_symbol(user_symb); } break; case 'f': - cl_flag_error = set_cl_flag(optarg, FALSE) ; + cl_flag_error = set_cl_flag(optarg, FALSE); break; case 'I': { - char *incl_list_elem = optarg; - add_to_include_list(incl_list_elem); + char *incl_list_elem = optarg; + add_to_include_list(incl_list_elem); } break; case 'T': @@ -298,14 +298,13 @@ static void get_args( int argc, char **argv ) /* Distinguish between a '?' from the user * and one getopt() returned */ - if ( argv[argindx][1] != '?' ) - { - inval_opt = TRUE; - break; + if (argv[argindx][1] != '?') { + inval_opt = TRUE; + break; } case 'h': case 'H': - help_mssg = TRUE; + help_mssg = TRUE; break; default: /* This is never executed @@ -313,44 +312,42 @@ static void get_args( int argc, char **argv ) * "unknown option -- X" * message and returns a '?' */ - printf ("%s: unknown options.\n",argv[0]); + printf("%s: unknown options.\n", argv[0]); usage(argv[0]); - exit( 1 ); + exit(1); } } - if ( help_mssg ) - { - usage(argv[0]); - if ( ! clflag_help ) - { - list_cl_flag_names(); - } + if (help_mssg) { + usage(argv[0]); + if (!clflag_help) { + list_cl_flag_names(); + } } - if ( clflag_help ) cl_flags_help(); - if ( help_mssg || clflag_help ) - { - exit( 0 ); + if (clflag_help) + cl_flags_help(); + if (help_mssg || clflag_help) { + exit(0); } - if ( inval_opt ) printf ("unknown options.\n"); - if (optind >= argc) printf ("Input file name missing.\n"); - if ( inval_opt || (optind >= argc) ) - { + if (inval_opt) + printf("unknown options.\n"); + if (optind >= argc) + printf("Input file name missing.\n"); + if (inval_opt || (optind >= argc)) { usage(argv[0]); } - if ( cl_flag_error ) list_cl_flag_names(); + if (cl_flag_error) + list_cl_flag_names(); - if ( inval_opt || (optind >= argc) || cl_flag_error ) - { - exit( 1); + if (inval_opt || (optind >= argc) || cl_flag_error) { + exit(1); } - if (verbose) - { - list_user_symbols(); - list_cl_flag_settings(); - display_include_list(); + if (verbose) { + list_user_symbols(); + list_cl_flag_settings(); + display_include_list(); } show_trace_list(); save_cl_flags(); @@ -377,7 +374,7 @@ int main(int argc, char **argv) int retval = 0; print_copyright(); - get_args( argc, argv ); + get_args(argc, argv); init_error_handler(); @@ -385,46 +382,42 @@ int main(int argc, char **argv) init_dictionary(); init_scanner(); - - if ( outputname != NULL ) - { - if ( argc > optind + 1 ) - { - /* Multiple input file names w/ single output file name */ - /* Work-around */ - printf( "Cannot specify single output file name " - "with multiple input file names.\n" - "Please either remove output-file-name specification,\n" - "or use multiple commands.\n"); - exit ( -2 ); - } + + if (outputname != NULL) { + if (argc > optind + 1) { + /* Multiple input file names w/ single output file name */ + /* Work-around */ + printf("Cannot specify single output file name " + "with multiple input file names.\n" + "Please either remove output-file-name specification,\n" + "or use multiple commands.\n"); + exit(-2); } + } - for ( ; optind < argc ; optind++ ) - { - bool stream_ok ; + for (; optind < argc; optind++) { + bool stream_ok; - printf("\nTokenizing %s ", argv[optind]); - init_error_handler(); - stream_ok = init_stream( argv[optind]); - if ( stream_ok ) - { - init_output(argv[optind], outputname); + printf("\nTokenizing %s ", argv[optind]); + init_error_handler(); + stream_ok = init_stream(argv[optind]); + if (stream_ok) { + init_output(argv[optind], outputname); - init_scan_state(); + init_scan_state(); - reset_vocabs(); - reset_cl_flags(); + reset_vocabs(); + reset_cl_flags(); - tokenize(); - finish_headers(); - - close_stream( NULL); - if ( close_output() ) retval = 1; - } + tokenize(); + finish_headers(); + + close_stream(NULL); + if (close_output()) + retval = 1; + } } - + exit_scanner(); return retval; } - diff --git a/toke/toke.h b/toke/toke.h index e0532bc..b1c27d9 100644 --- a/toke/toke.h +++ b/toke/toke.h @@ -33,10 +33,8 @@ * Modifications Author: David L. Paktor dlpaktor@us.ibm.com **************************************************************************** */ - #include "types.h" - /* ************************************************************************** * * * Global Variables Exported @@ -48,4 +46,4 @@ extern bool noerrors; extern bool fload_list; extern bool dependency_list; -#endif /* _TOKE_TOKE_H */ +#endif /* _TOKE_TOKE_H */ diff --git a/toke/tokzesc.c b/toke/tokzesc.c index 32f9941..e2a6eec 100644 --- a/toke/tokzesc.c +++ b/toke/tokzesc.c @@ -57,11 +57,11 @@ #include "nextfcode.h" #include "tracesyms.h" -#undef TOKZTEST /* Define for testing only; else undef */ -#ifdef TOKZTEST /* For testing only */ - #include "vocabfuncts.h" - #include "date_stamp.h" -#endif /* For testing only */ +#undef TOKZTEST /* Define for testing only; else undef */ +#ifdef TOKZTEST /* For testing only */ +#include "vocabfuncts.h" +#include "date_stamp.h" +#endif /* For testing only */ /* ************************************************************************** * @@ -123,7 +123,7 @@ * **************************************************************************** */ -tic_hdr_t *tokz_esc_vocab = NULL ; +tic_hdr_t *tokz_esc_vocab = NULL; /* ************************************************************************** * @@ -153,13 +153,13 @@ tic_hdr_t *tokz_esc_vocab = NULL ; * **************************************************************************** */ -static int saved_base ; /* Place to save the numeric conversion radix */ +static int saved_base; /* Place to save the numeric conversion radix */ -void enter_tokz_esc( void ) +void enter_tokz_esc(void) { - saved_base = base ; - base = 16; - in_tokz_esc = TRUE; + saved_base = base; + base = 16; + in_tokz_esc = TRUE; } /* ************************************************************************** @@ -176,10 +176,10 @@ void enter_tokz_esc( void ) * **************************************************************************** */ -static void end_tokz_esc( tic_param_t pfield ) +static void end_tokz_esc(tic_param_t pfield) { - in_tokz_esc = FALSE; - base = saved_base ; + in_tokz_esc = FALSE; + base = saved_base; } /* ************************************************************************** @@ -194,18 +194,17 @@ static void end_tokz_esc( tic_param_t pfield ) * **************************************************************************** */ -static void tokz_esc_emit_byte ( tic_param_t pfield ) +static void tokz_esc_emit_byte(tic_param_t pfield) { - long num_on_stk = dpop(); - u8 byt_to_emit = (u8)num_on_stk; - if ( byt_to_emit != num_on_stk ) - { - tokenization_error( WARNING, - "Value on stack for %s command is 0x%0x. " - "Truncating to 0x%02x.\n", - strupr(statbuf), num_on_stk, byt_to_emit); - } - user_emit_byte(byt_to_emit); + long num_on_stk = dpop(); + u8 byt_to_emit = (u8) num_on_stk; + if (byt_to_emit != num_on_stk) { + tokenization_error(WARNING, + "Value on stack for %s command is 0x%0x. " + "Truncating to 0x%02x.\n", + strupr(statbuf), num_on_stk, byt_to_emit); + } + user_emit_byte(byt_to_emit); } /* ************************************************************************** @@ -252,38 +251,35 @@ static void tokz_esc_emit_byte ( tic_param_t pfield ) * **************************************************************************** */ -static bool get_fcode_from_stack( u16 *the_num, bool setting_fc) +static bool get_fcode_from_stack(u16 * the_num, bool setting_fc) { - bool retval = FALSE; - char *the_action = "emit FCode value of"; - u16 legal_minimum = 0x10; - long num_on_stk = dpop(); - u16 test_fcode = (u16)num_on_stk; - - if ( setting_fc ) - { - the_action = "set next fcode to"; - legal_minimum = 0x800; - } - if ( test_fcode != num_on_stk ) - { - tokenization_error( WARNING, - "Value on stack for %s command is 0x%0x. " - "Truncating to 0x%03x.\n", - strupr(statbuf), num_on_stk, test_fcode); - } - if ( ( test_fcode >= legal_minimum ) && ( test_fcode <= 0xfff ) ) - { - retval = TRUE; - *the_num = test_fcode; - }else{ tokenization_error( TKERROR, "Attempt to %s " - "0x%x, which violates limit specified by IEEE-1275. " - "Disallowing.\n", the_action, test_fcode ); - } - return( retval ); + bool retval = FALSE; + char *the_action = "emit FCode value of"; + u16 legal_minimum = 0x10; + long num_on_stk = dpop(); + u16 test_fcode = (u16) num_on_stk; + + if (setting_fc) { + the_action = "set next fcode to"; + legal_minimum = 0x800; + } + if (test_fcode != num_on_stk) { + tokenization_error(WARNING, + "Value on stack for %s command is 0x%0x. " + "Truncating to 0x%03x.\n", + strupr(statbuf), num_on_stk, test_fcode); + } + if ((test_fcode >= legal_minimum) && (test_fcode <= 0xfff)) { + retval = TRUE; + *the_num = test_fcode; + } else { + tokenization_error(TKERROR, "Attempt to %s " + "0x%x, which violates limit specified by IEEE-1275. " + "Disallowing.\n", the_action, test_fcode); + } + return (retval); } - /* ************************************************************************** * * Function name: tokz_esc_next_fcode @@ -301,26 +297,27 @@ static bool get_fcode_from_stack( u16 *the_num, bool setting_fc) * **************************************************************************** */ -static void tokz_esc_next_fcode( tic_param_t pfield ) +static void tokz_esc_next_fcode(tic_param_t pfield) { - u16 test_fcode; - - if ( get_fcode_from_stack( &test_fcode, TRUE) ) - { - if ( test_fcode == nextfcode ) - { - tokenization_error( INFO, "FCode-token Assignment Counter " - "is unchanged from 0x%x.\n", - nextfcode); - }else{ - tokenization_error( INFO, "FCode-token Assignment Counter " - "was 0x%x; has been %s to 0x%x.\n", - nextfcode, - test_fcode > nextfcode ? "advanced" : "reset", - test_fcode ); - set_next_fcode( test_fcode); + u16 test_fcode; + + if (get_fcode_from_stack(&test_fcode, TRUE)) { + if (test_fcode == nextfcode) { + tokenization_error(INFO, + "FCode-token Assignment Counter " + "is unchanged from 0x%x.\n", + nextfcode); + } else { + tokenization_error(INFO, + "FCode-token Assignment Counter " + "was 0x%x; has been %s to 0x%x.\n", + nextfcode, + test_fcode > + nextfcode ? "advanced" : "reset", + test_fcode); + set_next_fcode(test_fcode); + } } - } } /* ************************************************************************** @@ -340,18 +337,17 @@ static void tokz_esc_next_fcode( tic_param_t pfield ) * **************************************************************************** */ -static void tokz_emit_fcode( tic_param_t pfield ) +static void tokz_emit_fcode(tic_param_t pfield) { - u16 test_fcode; - - if ( get_fcode_from_stack( &test_fcode, FALSE) ) - { - tokenization_error( INFO, - "Emitting FCode value of 0x%x\n", test_fcode); - emit_fcode( test_fcode); - } -} + u16 test_fcode; + if (get_fcode_from_stack(&test_fcode, FALSE)) { + tokenization_error(INFO, + "Emitting FCode value of 0x%x\n", + test_fcode); + emit_fcode(test_fcode); + } +} /* ************************************************************************** * @@ -363,9 +359,9 @@ static void tokz_emit_fcode( tic_param_t pfield ) * **************************************************************************** */ -static void zero_equals ( tic_param_t pfield ) +static void zero_equals(tic_param_t pfield) { - *dstack = (*dstack == 0) ? -1 : 0 ; + *dstack = (*dstack == 0) ? -1 : 0; } /* ************************************************************************** @@ -377,9 +373,9 @@ static void zero_equals ( tic_param_t pfield ) * **************************************************************************** */ -static void tokz_esc_swap ( tic_param_t pfield ) +static void tokz_esc_swap(tic_param_t pfield) { - swap(); + swap(); } /* ************************************************************************** @@ -391,9 +387,9 @@ static void tokz_esc_swap ( tic_param_t pfield ) * **************************************************************************** */ -static void tokz_esc_two_swap ( tic_param_t pfield ) +static void tokz_esc_two_swap(tic_param_t pfield) { - two_swap(); + two_swap(); } /* ************************************************************************** @@ -405,22 +401,22 @@ static void tokz_esc_two_swap ( tic_param_t pfield ) * **************************************************************************** */ -static void tokz_esc_noop ( tic_param_t pfield ) +static void tokz_esc_noop(tic_param_t pfield) { - return; + return; } -#ifdef TOKZTEST /* For testing only */ +#ifdef TOKZTEST /* For testing only */ - static void tokz_esc_emit_string( tic_param_t pfield ) - { - int lenny ; - lenny = strlen ( pfield.chr_ptr ); - emit_token("b(\")"); - emit_string(pfield.chr_ptr, lenny); - } +static void tokz_esc_emit_string(tic_param_t pfield) +{ + int lenny; + lenny = strlen(pfield.chr_ptr); + emit_token("b(\")"); + emit_string(pfield.chr_ptr, lenny); +} -#endif /* For testing only */ +#endif /* For testing only */ /* ************************************************************************** * @@ -449,9 +445,9 @@ static void tokz_esc_noop ( tic_param_t pfield ) * **************************************************************************** */ -static void do_constant ( tic_param_t pfield ) +static void do_constant(tic_param_t pfield) { - dpush( pfield.long_val ); + dpush(pfield.long_val); } /* ************************************************************************** @@ -498,38 +494,34 @@ static void do_constant ( tic_param_t pfield ) * **************************************************************************** */ -static void create_constant( tic_param_t pfield ) +static void create_constant(tic_param_t pfield) { - char *c_name_space ; /* Space for copy of the name */ - long valu ; /* Value, popped off the stack */ - signed long wlen; - - /* Get the name that is to be defined */ - wlen = get_word(); - if ( wlen <= 0 ) - { - warn_unterm( TKERROR, "Constant definition", lineno); - return; - } + char *c_name_space; /* Space for copy of the name */ + long valu; /* Value, popped off the stack */ + signed long wlen; + + /* Get the name that is to be defined */ + wlen = get_word(); + if (wlen <= 0) { + warn_unterm(TKERROR, "Constant definition", lineno); + return; + } - valu = dpop(); + valu = dpop(); - /* If ever we implement more than just this one - * defining-word in "Tokenizer Escape" mode, - * the lines from here to the end of the - * routine should be re-factored... - */ - c_name_space = strdup( statbuf ); + /* If ever we implement more than just this one + * defining-word in "Tokenizer Escape" mode, + * the lines from here to the end of the + * routine should be re-factored... + */ + c_name_space = strdup(statbuf); - add_tic_entry( - c_name_space, - do_constant, - (TIC_P_DEFLT_TYPE)valu, - CONST , - 0 , FALSE , NULL, - &tokz_esc_vocab ); + add_tic_entry(c_name_space, + do_constant, + (TIC_P_DEFLT_TYPE) valu, + CONST, 0, FALSE, NULL, &tokz_esc_vocab); - check_name_length( wlen ); + check_name_length(wlen); } @@ -545,9 +537,9 @@ static const int minus_one = -1 ; static const char double_quote = '"' ; static const char close_paren = ')' ; * Except for this next one, of course... */ -#ifdef TOKZTEST /* For testing only */ - static const char date_me[] = DATE_STAMP; -#endif /* For testing only */ +#ifdef TOKZTEST /* For testing only */ +static const char date_me[] = DATE_STAMP; +#endif /* For testing only */ /* ************************************************************************** * @@ -566,31 +558,31 @@ static const char close_paren = ')' ; DUALFUNC_TIC(nam, afunc, pval, ifunc, UNSPECIFIED) static tic_hdr_t tokz_esc_vocab_tbl[] = { - NO_PARAM_IGN( "]tokenizer" , end_tokz_esc ) , - - /* An IBM-ish synonym. */ - NO_PARAM_IGN( "f]" , end_tokz_esc ) , - /* An alternate synonym. */ - NO_PARAM_IGN( "]f" , end_tokz_esc ) , - - NO_PARAM_TIC( "emit-byte" , tokz_esc_emit_byte ) , - NO_PARAM_TIC( "next-fcode" , tokz_esc_next_fcode ) , - NO_PARAM_TIC( "emit-fcode" , tokz_emit_fcode ) , - NO_PARAM_TIC( "constant" , create_constant ) , - NO_PARAM_TIC( "0=" , zero_equals ) , - NO_PARAM_TIC( "swap" , tokz_esc_swap ) , - NO_PARAM_TIC( "2swap" , tokz_esc_two_swap ) , - NO_PARAM_TIC( "noop" , tokz_esc_noop ) , - TKZESC_CONST( "false" , 0 ) , - TKZESC_CONST( "true" , -1 ) , - TKZ_ESC_FUNC( ".(" , user_message, ')', skip_user_message ) , - TKZ_ESC_FUNC( ".\"" , user_message, '"', skip_user_message ) , -#ifdef TOKZTEST /* For testing only */ - /* Data is a pointer to a constant string in the compiler; */ - /* no need to copy, hence data_size can remain zero. */ - /* We could almost use the Macro macro, except for the type. */ - TKZ_ESC_FUNC( "emit-date" , tokz_esc_emit_string, date_me , NULL ) , -#endif /* For testing only */ + NO_PARAM_IGN("]tokenizer", end_tokz_esc), + + /* An IBM-ish synonym. */ + NO_PARAM_IGN("f]", end_tokz_esc), + /* An alternate synonym. */ + NO_PARAM_IGN("]f", end_tokz_esc), + + NO_PARAM_TIC("emit-byte", tokz_esc_emit_byte), + NO_PARAM_TIC("next-fcode", tokz_esc_next_fcode), + NO_PARAM_TIC("emit-fcode", tokz_emit_fcode), + NO_PARAM_TIC("constant", create_constant), + NO_PARAM_TIC("0=", zero_equals), + NO_PARAM_TIC("swap", tokz_esc_swap), + NO_PARAM_TIC("2swap", tokz_esc_two_swap), + NO_PARAM_TIC("noop", tokz_esc_noop), + TKZESC_CONST("false", 0), + TKZESC_CONST("true", -1), + TKZ_ESC_FUNC(".(", user_message, ')', skip_user_message), + TKZ_ESC_FUNC(".\"", user_message, '"', skip_user_message), +#ifdef TOKZTEST /* For testing only */ + /* Data is a pointer to a constant string in the compiler; */ + /* no need to copy, hence data_size can remain zero. */ + /* We could almost use the Macro macro, except for the type. */ + TKZ_ESC_FUNC("emit-date", tokz_esc_emit_string, date_me, NULL), +#endif /* For testing only */ }; /* ************************************************************************** @@ -601,7 +593,7 @@ static tic_hdr_t tokz_esc_vocab_tbl[] = { **************************************************************************** */ static const tic_hdr_t *built_in_tokz_esc = - &tokz_esc_vocab_tbl[(sizeof(tokz_esc_vocab_tbl)/sizeof(tic_hdr_t))-1]; + &tokz_esc_vocab_tbl[(sizeof(tokz_esc_vocab_tbl) / sizeof(tic_hdr_t)) - 1]; /* ************************************************************************** * @@ -616,17 +608,16 @@ static const tic_hdr_t *built_in_tokz_esc = * **************************************************************************** */ -void init_tokz_esc_vocab ( void ) +void init_tokz_esc_vocab(void) { - static const int tokz_esc_vocab_max_indx = - sizeof(tokz_esc_vocab_tbl)/sizeof(tic_hdr_t) ; - - in_tokz_esc = TRUE; - tokz_esc_vocab = NULL ; /* Belt-and-suspenders... */ - init_tic_vocab(tokz_esc_vocab_tbl, - tokz_esc_vocab_max_indx, - &tokz_esc_vocab ); - in_tokz_esc = FALSE; + static const int tokz_esc_vocab_max_indx = + sizeof(tokz_esc_vocab_tbl) / sizeof(tic_hdr_t); + + in_tokz_esc = TRUE; + tokz_esc_vocab = NULL; /* Belt-and-suspenders... */ + init_tic_vocab(tokz_esc_vocab_tbl, + tokz_esc_vocab_max_indx, &tokz_esc_vocab); + in_tokz_esc = FALSE; } /* ************************************************************************** @@ -648,11 +639,10 @@ void init_tokz_esc_vocab ( void ) tic_hdr_t *lookup_tokz_esc(char *name) { - tic_hdr_t *retval = lookup_tic_entry( name, tokz_esc_vocab ); - return ( retval ); + tic_hdr_t *retval = lookup_tic_entry(name, tokz_esc_vocab); + return (retval); } - /* ************************************************************************** * * Function name: create_tokz_esc_alias @@ -680,11 +670,10 @@ tic_hdr_t *lookup_tokz_esc(char *name) bool create_tokz_esc_alias(char *new_name, char *old_name) { - bool retval = create_tic_alias( new_name, old_name, &tokz_esc_vocab ); - return ( retval ); + bool retval = create_tic_alias(new_name, old_name, &tokz_esc_vocab); + return (retval); } - /* ************************************************************************** * * Function name: reset_tokz_esc @@ -709,9 +698,9 @@ bool create_tokz_esc_alias(char *new_name, char *old_name) * **************************************************************************** */ -void reset_tokz_esc( void ) +void reset_tokz_esc(void) { - reset_tic_vocab( &tokz_esc_vocab, (tic_hdr_t *)built_in_tokz_esc); + reset_tic_vocab(&tokz_esc_vocab, (tic_hdr_t *) built_in_tokz_esc); } /* ************************************************************************** @@ -735,8 +724,8 @@ void reset_tokz_esc( void ) * **************************************************************************** */ -void pop_next_fcode( void) +void pop_next_fcode(void) { - tic_param_t dummy_param; - tokz_esc_next_fcode( dummy_param); + tic_param_t dummy_param; + tokz_esc_next_fcode(dummy_param); } diff --git a/toke/tokzesc.h b/toke/tokzesc.h index 55d87c2..7634ffa 100644 --- a/toke/tokzesc.h +++ b/toke/tokzesc.h @@ -38,11 +38,11 @@ #include "types.h" #include "ticvocab.h" -void init_tokz_esc_vocab( void ); +void init_tokz_esc_vocab(void); bool create_tokz_esc_alias(char *new_name, char *old_name); -void enter_tokz_esc( void ); +void enter_tokz_esc(void); tic_hdr_t *lookup_tokz_esc(char *name); -void reset_tokz_esc( void ); -void pop_next_fcode( void); +void reset_tokz_esc(void); +void pop_next_fcode(void); -#endif /* _TOKE_TOKZESC_H */ +#endif /* _TOKE_TOKZESC_H */ diff --git a/toke/tracesyms.c b/toke/tracesyms.c index 4de93f6..2019ce3 100644 --- a/toke/tracesyms.c +++ b/toke/tracesyms.c @@ -97,7 +97,6 @@ * **************************************************************************** */ - #include #include #include @@ -122,7 +121,6 @@ int split_alias_message = INFO; * **************************************************************************** */ - /* ************************************************************************** * * Internal (Static) Structures: @@ -135,8 +133,8 @@ int split_alias_message = INFO; **************************************************************************** */ typedef struct trace_entry { - char *tracee; - struct trace_entry *next; + char *tracee; + struct trace_entry *next; } trace_entry_t; static trace_entry_t *trace_list = NULL; @@ -180,24 +178,22 @@ static bool tracing_symbols = FALSE; * **************************************************************************** */ -void add_to_trace_list( char *trace_symb) +void add_to_trace_list(char *trace_symb) { - trace_entry_t *new_t_l_entry = safe_malloc( sizeof( trace_entry_t), - "adding to trace-list"); - new_t_l_entry->tracee = strdup( trace_symb); - new_t_l_entry->next = NULL; - - if ( trace_list != NULL ) - { - trace_list_last->next = new_t_l_entry; - }else{ - trace_list = new_t_l_entry; - tracing_symbols = TRUE; - } - trace_list_last = new_t_l_entry; + trace_entry_t *new_t_l_entry = safe_malloc(sizeof(trace_entry_t), + "adding to trace-list"); + new_t_l_entry->tracee = strdup(trace_symb); + new_t_l_entry->next = NULL; + + if (trace_list != NULL) { + trace_list_last->next = new_t_l_entry; + } else { + trace_list = new_t_l_entry; + tracing_symbols = TRUE; + } + trace_list_last = new_t_l_entry; } - /* ************************************************************************** * * Function name: is_on_trace_list @@ -215,26 +211,22 @@ void add_to_trace_list( char *trace_symb) * **************************************************************************** */ -bool is_on_trace_list( char *symb_name) +bool is_on_trace_list(char *symb_name) { - bool retval = FALSE; - if ( tracing_symbols ) - { - trace_entry_t *test_entry = trace_list; - while ( test_entry != NULL ) - { - if ( strcasecmp( symb_name, test_entry->tracee) == 0 ) - { - retval = TRUE; - break; - } - test_entry = test_entry->next; + bool retval = FALSE; + if (tracing_symbols) { + trace_entry_t *test_entry = trace_list; + while (test_entry != NULL) { + if (strcasecmp(symb_name, test_entry->tracee) == 0) { + retval = TRUE; + break; + } + test_entry = test_entry->next; + } } - } - return ( retval ); + return (retval); } - /* ************************************************************************** * * Function name: tracing_fcode @@ -267,13 +259,12 @@ bool is_on_trace_list( char *symb_name) * **************************************************************************** */ -void tracing_fcode( char *fc_phrase_buff, u16 fc_token_num) +void tracing_fcode(char *fc_phrase_buff, u16 fc_token_num) { - if ( fc_token_num > 0 ) - { - sprintf( fc_phrase_buff, - " (FCode token = 0x%03x)", fc_token_num); - } + if (fc_token_num > 0) { + sprintf(fc_phrase_buff, + " (FCode token = 0x%03x)", fc_token_num); + } } /* ************************************************************************** @@ -333,109 +324,96 @@ void tracing_fcode( char *fc_phrase_buff, u16 fc_token_num) * **************************************************************************** */ -void trace_creation( tic_hdr_t *trace_entry, - char *nu_name, - bool is_global) +void trace_creation(tic_hdr_t * trace_entry, char *nu_name, bool is_global) { - char fc_token_display[TRACING_FCODE_LENGTH] = ""; - char *head_ness = ""; - char *defr_name = "" ; - char *defr_phrase = "" ; - char *with_scope = "" ; - bool def_is_local = BOOLVAL( trace_entry->fword_defr == LOCAL_VAL); - bool creating_alias = BOOLVAL( nu_name != NULL ); - - if ( creating_alias ) - { - head_ness = "n"; - split_alias_message = TRACER; - } - - if ( in_tokz_esc ) - { - with_scope = in_tkz_esc_mode; - }else{ - if ( ! def_is_local ) - { - if ( is_global ) - { - with_scope = "with Global scope.\n"; - }else{ - with_scope = in_what_node( current_device_node); - } + char fc_token_display[TRACING_FCODE_LENGTH] = ""; + char *head_ness = ""; + char *defr_name = ""; + char *defr_phrase = ""; + char *with_scope = ""; + bool def_is_local = BOOLVAL(trace_entry->fword_defr == LOCAL_VAL); + bool creating_alias = BOOLVAL(nu_name != NULL); + + if (creating_alias) { + head_ness = "n"; + split_alias_message = TRACER; } - if ( trace_entry->is_token ) - { - tracing_fcode( fc_token_display, - (u16)trace_entry->pfield.deflt_elem ); - /* Headered-ness only applies to FCode definitions */ - /* But not to aliases to FCode definitions */ - if ( ! creating_alias ) - { - switch ( hdr_flag ) - { - case FLAG_HEADERS: - head_ness = " Headered"; - break; - - case FLAG_EXTERNAL: - head_ness = "n External"; - break; - - default: /* FLAG_HEADERLESS */ - head_ness = " Headerless"; + if (in_tokz_esc) { + with_scope = in_tkz_esc_mode; + } else { + if (!def_is_local) { + if (is_global) { + with_scope = "with Global scope.\n"; + } else { + with_scope = in_what_node(current_device_node); + } } - } - } - } + if (trace_entry->is_token) { + tracing_fcode(fc_token_display, + (u16) trace_entry->pfield.deflt_elem); + /* Headered-ness only applies to FCode definitions */ + /* But not to aliases to FCode definitions */ + if (!creating_alias) { + switch (hdr_flag) { + case FLAG_HEADERS: + head_ness = " Headered"; + break; + + case FLAG_EXTERNAL: + head_ness = "n External"; + break; + + default: /* FLAG_HEADERLESS */ + head_ness = " Headerless"; + } + } + } + } - if ( definer_name(trace_entry->fword_defr, &defr_name) ) - { - defr_phrase = wh_defined; - }else{ - /* Even if we don't have a Type for the "old" word - * we still have its scope. If the "new" word's - * scope is different, the "split-alias message" - * will take care of it. - */ - if ( creating_alias ) - { - defr_phrase = ", which is defined" ; + if (definer_name(trace_entry->fword_defr, &defr_name)) { + defr_phrase = wh_defined; + } else { + /* Even if we don't have a Type for the "old" word + * we still have its scope. If the "new" word's + * scope is different, the "split-alias message" + * will take care of it. + */ + if (creating_alias) { + defr_phrase = ", which is defined"; + } } - } - if ( creating_alias ) - { - /* - * Creating as a{n External,Headered,Headerless} - * ALIAS to <(if is_single:FCode Token = xxx)>, - * [which is defined as a ] - */ - tokenization_error(TRACER, - "Creating %s" /* nu_name */ - " as a%s ALIAS to %s" /* head_ness trace_entry->name */ - "%s" /* fc_token_display */ - "%s%s " /* defr_phrase defr_name */ - "%s", /* with_scope */ - nu_name, head_ness, trace_entry->name, - fc_token_display, defr_phrase, defr_name, with_scope ); - }else{ - /* - * Creating <(if is_single:FCode Token = xxx)> - * as a{n External,Headered,Headerless} - * [ ] - */ - tokenization_error(TRACER, - "Creating %s" /* trace_entry->name */ - "%s" /* fc_token_display */ - " as a%s %s " /* head_ness defr_name */ - "%s", /* with_scope */ - trace_entry->name, - fc_token_display, head_ness, defr_name, with_scope ); - } + if (creating_alias) { + /* + * Creating as a{n External,Headered,Headerless} + * ALIAS to <(if is_single:FCode Token = xxx)>, + * [which is defined as a ] + */ + tokenization_error(TRACER, "Creating %s" /* nu_name */ + " as a%s ALIAS to %s" /* head_ness trace_entry->name */ + "%s" /* fc_token_display */ + "%s%s " /* defr_phrase defr_name */ + "%s", /* with_scope */ + nu_name, head_ness, trace_entry->name, + fc_token_display, defr_phrase, defr_name, + with_scope); + } else { + /* + * Creating <(if is_single:FCode Token = xxx)> + * as a{n External,Headered,Headerless} + * [ ] + */ + tokenization_error(TRACER, "Creating %s" /* trace_entry->name */ + "%s" /* fc_token_display */ + " as a%s %s " /* head_ness defr_name */ + "%s", /* with_scope */ + trace_entry->name, + fc_token_display, head_ness, defr_name, + with_scope); + } /* * The phrase is: * If we are in Tokz-Esc mode, "in Tokenizer-Escape mode". @@ -446,20 +424,16 @@ void trace_creation( tic_hdr_t *trace_entry, * Otherwise, the identification of the current device-node. */ - - if ( ! in_tokz_esc ) - { - if ( def_is_local ) - { - in_last_colon( TRUE); - }else{ - show_node_start(); + if (!in_tokz_esc) { + if (def_is_local) { + in_last_colon(TRUE); + } else { + show_node_start(); + } } - } } - /* ************************************************************************** * * Function name: trace_create_failure @@ -482,36 +456,31 @@ void trace_creation( tic_hdr_t *trace_entry, * **************************************************************************** */ -void trace_create_failure( char *new_name, char *old_name, u16 fc_tokn) +void trace_create_failure(char *new_name, char *old_name, u16 fc_tokn) { - bool not_alias = BOOLVAL( old_name == NULL ); - bool do_it = is_on_trace_list( new_name); - - if ( ( ! do_it ) && ( ! not_alias ) ) - { - do_it = is_on_trace_list( old_name); - } - - if ( do_it ) - { - char fc_token_display[TRACING_FCODE_LENGTH] = ""; - char *as_alias = not_alias ? "" : " as an ALIAS to "; - char *alias_name = not_alias ? "" : old_name; - - if ( fc_tokn > 0 ) - { - tracing_fcode( fc_token_display, fc_tokn); + bool not_alias = BOOLVAL(old_name == NULL); + bool do_it = is_on_trace_list(new_name); + + if ((!do_it) && (!not_alias)) { + do_it = is_on_trace_list(old_name); } - tokenization_error(TRACER, - "Failed to create %s" /* new_name */ - "%s" /* fc_token_display */ - "%s" /* as_alias */ - "%s\n", /* alias_name */ - new_name, fc_token_display, - as_alias, alias_name); - } -} + if (do_it) { + char fc_token_display[TRACING_FCODE_LENGTH] = ""; + char *as_alias = not_alias ? "" : " as an ALIAS to "; + char *alias_name = not_alias ? "" : old_name; + + if (fc_tokn > 0) { + tracing_fcode(fc_token_display, fc_tokn); + } + tokenization_error(TRACER, "Failed to create %s" /* new_name */ + "%s" /* fc_token_display */ + "%s" /* as_alias */ + "%s\n", /* alias_name */ + new_name, fc_token_display, + as_alias, alias_name); + } +} /* ************************************************************************** * @@ -537,13 +506,13 @@ void trace_create_failure( char *new_name, char *old_name, u16 fc_tokn) * **************************************************************************** */ -void traced_name_error( char *trace_name) +void traced_name_error(char *trace_name) { - if ( is_on_trace_list( trace_name ) ) - { - tokenization_error(TRACER, "Attempt to invoke (undefined) %s.\n", - trace_name); - } + if (is_on_trace_list(trace_name)) { + tokenization_error(TRACER, + "Attempt to invoke (undefined) %s.\n", + trace_name); + } } /* ************************************************************************** @@ -576,36 +545,32 @@ void traced_name_error( char *trace_name) * **************************************************************************** */ -void invoking_traced_name( tic_hdr_t *trace_entry) +void invoking_traced_name(tic_hdr_t * trace_entry) { - char fc_token_display[TRACING_FCODE_LENGTH] = ""; - char *defr_name = "" ; - char *defr_phrase = "" ; - char *defr_space = "" ; - - if ( trace_entry->is_token ) - { - tracing_fcode( fc_token_display, - (u16)trace_entry->pfield.deflt_elem ); - } - - if ( definer_name(trace_entry->fword_defr, &defr_name) ) - { - defr_phrase = " defined as a"; - defr_space = " " ; - - } - - tokenization_error(TRACER, - "Invoking %s" /* */ - "%s" /* fc_token_display */ - "%s%s" /* defr_phrase defr_space */ - "%s.\n", /* defr_name */ - trace_entry->name, - fc_token_display, - defr_phrase, defr_space, - defr_name); + char fc_token_display[TRACING_FCODE_LENGTH] = ""; + char *defr_name = ""; + char *defr_phrase = ""; + char *defr_space = ""; + + if (trace_entry->is_token) { + tracing_fcode(fc_token_display, + (u16) trace_entry->pfield.deflt_elem); + } + + if (definer_name(trace_entry->fword_defr, &defr_name)) { + defr_phrase = " defined as a"; + defr_space = " "; + + } + + tokenization_error(TRACER, "Invoking %s" /* */ + "%s" /* fc_token_display */ + "%s%s" /* defr_phrase defr_space */ + "%s.\n", /* defr_name */ + trace_entry->name, + fc_token_display, + defr_phrase, defr_space, defr_name); } @@ -633,18 +598,15 @@ void invoking_traced_name( tic_hdr_t *trace_entry) * **************************************************************************** */ -void handle_invocation( tic_hdr_t *trace_entry) +void handle_invocation(tic_hdr_t * trace_entry) { - if ( trace_entry != NULL ) - { - if ( trace_entry->tracing) - { - invoking_traced_name( trace_entry); + if (trace_entry != NULL) { + if (trace_entry->tracing) { + invoking_traced_name(trace_entry); + } } - } } - /* ************************************************************************** * * Function name: show_trace_list @@ -666,21 +628,18 @@ void handle_invocation( tic_hdr_t *trace_entry) * **************************************************************************** */ -void show_trace_list( void) +void show_trace_list(void) { - if ( tracing_symbols ) - { - trace_entry_t *test_entry; - printf("\nTracing these symbols:"); - for ( test_entry = trace_list; - test_entry != NULL; - test_entry = test_entry->next ) - { - printf(" %s", test_entry->tracee); - - } - printf("\n"); - } + if (tracing_symbols) { + trace_entry_t *test_entry; + printf("\nTracing these symbols:"); + for (test_entry = trace_list; + test_entry != NULL; test_entry = test_entry->next) { + printf(" %s", test_entry->tracee); + + } + printf("\n"); + } } @@ -712,29 +671,26 @@ void show_trace_list( void) * is a built-in {word|} [in Tokz-Esc mode] * **************************************************************************** */ - -void trace_builtin( tic_hdr_t *trace_entry) + +void trace_builtin(tic_hdr_t * trace_entry) { - if (is_on_trace_list( trace_entry->name ) ) - { - char fc_token_display[TRACING_FCODE_LENGTH] = ""; - char *defr_name = "word"; - char *ws_space = in_tokz_esc ? " " : ""; - char *with_scope = in_tokz_esc ? in_tkz_esc_mode : ".\n"; - if ( trace_entry->is_token ) - { - tracing_fcode( fc_token_display, - (u16)trace_entry->pfield.deflt_elem ); + if (is_on_trace_list(trace_entry->name)) { + char fc_token_display[TRACING_FCODE_LENGTH] = ""; + char *defr_name = "word"; + char *ws_space = in_tokz_esc ? " " : ""; + char *with_scope = in_tokz_esc ? in_tkz_esc_mode : ".\n"; + if (trace_entry->is_token) { + tracing_fcode(fc_token_display, + (u16) trace_entry->pfield.deflt_elem); + } + definer_name(trace_entry->fword_defr, &defr_name); + trace_entry->tracing = TRUE; + tokenization_error(TRACER, "%s" /* */ + "%s " /* fc_token_display */ + "is a built-in %s" /* defr_name */ + "%s%s", /* ws_space with_scope */ + trace_entry->name, + fc_token_display, defr_name, ws_space, + with_scope); } - definer_name(trace_entry->fword_defr, &defr_name); - trace_entry->tracing = TRUE; - tokenization_error(TRACER, - "%s" /* */ - "%s " /* fc_token_display */ - "is a built-in %s" /* defr_name */ - "%s%s", /* ws_space with_scope */ - trace_entry->name, - fc_token_display, defr_name, ws_space, with_scope ); - } } - diff --git a/toke/tracesyms.h b/toke/tracesyms.h index 9409563..8dafd98 100644 --- a/toke/tracesyms.h +++ b/toke/tracesyms.h @@ -52,18 +52,16 @@ extern int split_alias_message; * **************************************************************************** */ -void add_to_trace_list( char *trace_symb); -bool is_on_trace_list( char *symb_name); -void tracing_fcode( char *fc_phrase_buff, u16 fc_token_num); -void trace_creation( tic_hdr_t *trace_entry, - char *nu_name, - bool is_global); -void trace_create_failure( char *new_name, char *old_name, u16 fc_tokn); -void traced_name_error( char *trace_name); -void invoking_traced_name( tic_hdr_t *trace_entry); -void handle_invocation( tic_hdr_t *trace_entry); -void show_trace_list( void); -void trace_builtin( tic_hdr_t *trace_entry); +void add_to_trace_list(char *trace_symb); +bool is_on_trace_list(char *symb_name); +void tracing_fcode(char *fc_phrase_buff, u16 fc_token_num); +void trace_creation(tic_hdr_t * trace_entry, char *nu_name, bool is_global); +void trace_create_failure(char *new_name, char *old_name, u16 fc_tokn); +void traced_name_error(char *trace_name); +void invoking_traced_name(tic_hdr_t * trace_entry); +void handle_invocation(tic_hdr_t * trace_entry); +void show_trace_list(void); +void trace_builtin(tic_hdr_t * trace_entry); /* ************************************************************************** * * @@ -75,4 +73,4 @@ void trace_builtin( tic_hdr_t *trace_entry); #define TRACING_FCODE_LENGTH 32 -#endif /* _TOKE_TRACESYMS_H */ +#endif /* _TOKE_TRACESYMS_H */ diff --git a/toke/usersymbols.c b/toke/usersymbols.c index 32860c0..bc2d797 100644 --- a/toke/usersymbols.c +++ b/toke/usersymbols.c @@ -102,8 +102,6 @@ * **************************************************************************** */ - - #include #include #if defined(__linux__) && ! defined(__USE_BSD) @@ -116,7 +114,6 @@ #include "usersymbols.h" #include "scanner.h" - /* ************************************************************************** * * Internal Static Variables @@ -164,21 +161,19 @@ static int user_symbol_count = 0; void add_user_symbol(char *raw_symb) { - char *symb_nam; - char *symb_valu; + char *symb_nam; + char *symb_valu; - symb_nam = strdup(raw_symb); - symb_valu = strchr(symb_nam,'='); - if ( symb_valu != NULL ) - { - *symb_valu = 0; - symb_valu++; - } - add_str_sub_entry(symb_nam, symb_valu, &user_symbol_list ); - user_symbol_count++; + symb_nam = strdup(raw_symb); + symb_valu = strchr(symb_nam, '='); + if (symb_valu != NULL) { + *symb_valu = 0; + symb_valu++; + } + add_str_sub_entry(symb_nam, symb_valu, &user_symbol_list); + user_symbol_count++; } - /* ************************************************************************** * * Function name: exists_as_user_symbol @@ -198,10 +193,10 @@ void add_user_symbol(char *raw_symb) bool exists_as_user_symbol(char *symb_nam) { - bool retval; + bool retval; - retval = exists_in_str_sub(symb_nam, user_symbol_list ); - return (retval); + retval = exists_in_str_sub(symb_nam, user_symbol_list); + return (retval); } /* ************************************************************************** @@ -250,29 +245,29 @@ bool exists_as_user_symbol(char *symb_nam) * **************************************************************************** */ -void eval_user_symbol( char *symb_nam) +void eval_user_symbol(char *symb_nam) { - str_sub_vocab_t *found = NULL; - + str_sub_vocab_t *found = NULL; - found = lookup_str_sub( symb_nam, user_symbol_list ); - if ( found == NULL ) - { - tokenization_error ( TKERROR, - "Command-line symbol %s is not defined.\n", symb_nam); - }else{ - char *symb_valu = found->alias; + found = lookup_str_sub(symb_nam, user_symbol_list); + if (found == NULL) { + tokenization_error(TKERROR, + "Command-line symbol %s is not defined.\n", + symb_nam); + } else { + char *symb_valu = found->alias; - if ( symb_valu == NULL ) - { - tokenization_error ( WARNING, - "No value assigned to command-line symbol %s\n", symb_nam ); - }else{ - eval_string( symb_valu ); + if (symb_valu == NULL) { + tokenization_error(WARNING, + "No value assigned to command-line symbol %s\n", + symb_nam); + } else { + eval_string(symb_valu); + } } - } } + /* ************************************************************************** * * Function name: list_user_symbols @@ -320,74 +315,67 @@ void eval_user_symbol( char *symb_nam) * **************************************************************************** */ -void list_user_symbols(void ) +void list_user_symbols(void) { - str_sub_vocab_t *curr; + str_sub_vocab_t *curr; - if ( user_symbol_list != NULL ) - { - /* Collect the pointers and max length */ - str_sub_vocab_t **symb_ptr; - int indx = 0; - int maxlen = 0; - - symb_ptr = (str_sub_vocab_t **)safe_malloc( - (sizeof(str_sub_vocab_t *) * user_symbol_count), - "collecting user-symbol pointers" ); - - for (curr = user_symbol_list ; curr != NULL ; curr=curr->next) - { - symb_ptr[indx] = curr; - indx++; - if ( strlen(curr->name) > maxlen ) maxlen = strlen(curr->name); - } - - /* Now print 'em out */ - printf("\nUser-Defined Symbols:\n"); - while ( indx > 0 ) - { - bool is_dup; - int dup_srch_indx; - indx--; - curr = symb_ptr[indx]; + if (user_symbol_list != NULL) { + /* Collect the pointers and max length */ + str_sub_vocab_t **symb_ptr; + int indx = 0; + int maxlen = 0; - /* Detect duplicate names. */ - dup_srch_indx = indx; - is_dup = FALSE; - while ( dup_srch_indx > 0 ) - { - str_sub_vocab_t *dup_cand; - dup_srch_indx--; - dup_cand = symb_ptr[dup_srch_indx]; - if ( strcmp( curr->name, dup_cand->name) == 0 ) - { - is_dup = TRUE; - break; + symb_ptr = (str_sub_vocab_t **) safe_malloc((sizeof + (str_sub_vocab_t *) + * + user_symbol_count), + "collecting user-symbol pointers"); + + for (curr = user_symbol_list; curr != NULL; curr = curr->next) { + symb_ptr[indx] = curr; + indx++; + if (strlen(curr->name) > maxlen) + maxlen = strlen(curr->name); } - } - printf("\t%s",curr->name); + /* Now print 'em out */ + printf("\nUser-Defined Symbols:\n"); + while (indx > 0) { + bool is_dup; + int dup_srch_indx; + indx--; + curr = symb_ptr[indx]; + + /* Detect duplicate names. */ + dup_srch_indx = indx; + is_dup = FALSE; + while (dup_srch_indx > 0) { + str_sub_vocab_t *dup_cand; + dup_srch_indx--; + dup_cand = symb_ptr[dup_srch_indx]; + if (strcmp(curr->name, dup_cand->name) == 0) { + is_dup = TRUE; + break; + } + } + + printf("\t%s", curr->name); - if ( ( curr->alias != NULL ) || is_dup ) - { - int strindx; - for ( strindx = strlen(curr->name) ; - strindx < maxlen ; - strindx++ ) - { - printf(" "); + if ((curr->alias != NULL) || is_dup) { + int strindx; + for (strindx = strlen(curr->name); + strindx < maxlen; strindx++) { + printf(" "); + } + } + if (curr->alias != NULL) { + printf(" = %s", curr->alias); + } + if (is_dup) { + printf(" *** Over-ridden"); + } + printf("\n"); } - } - if ( curr->alias != NULL ) - { - printf(" = %s",curr->alias); - } - if ( is_dup ) - { - printf(" *** Over-ridden" ); - } - printf("\n"); + free(symb_ptr); } - free(symb_ptr); - } } diff --git a/toke/usersymbols.h b/toke/usersymbols.h index 0a4857f..3ab46c8 100644 --- a/toke/usersymbols.h +++ b/toke/usersymbols.h @@ -1,7 +1,6 @@ #ifndef _TOKE_USERSYMBOLS_H #define _TOKE_USERSYMBOLS_H - /* * OpenBIOS - free your system! * ( FCode tokenizer ) @@ -39,7 +38,7 @@ void add_user_symbol(char *raw_symb); bool exists_as_user_symbol(char *symb_nam); -void eval_user_symbol(char *symbol ); -void list_user_symbols(void ); +void eval_user_symbol(char *symbol); +void list_user_symbols(void); -#endif /* _TOKE_USERSYMBOLS_H */ +#endif /* _TOKE_USERSYMBOLS_H */ diff --git a/toke/vocabfuncts.h b/toke/vocabfuncts.h index c4787d8..6cd711a 100644 --- a/toke/vocabfuncts.h +++ b/toke/vocabfuncts.h @@ -35,11 +35,9 @@ * **************************************************************************** */ - #include "types.h" #include "ticvocab.h" - /* ************************************************************************** * * * Global Variables Exported @@ -49,41 +47,36 @@ extern bool scope_is_global; extern bool define_token; - /* ************************************************************************** * * * Function Prototypes / Functions Exported: * **************************************************************************** */ +tic_hdr_t *lookup_core_word(char *tname); +bool create_core_alias(char *new_name, char *old_name); -tic_hdr_t *lookup_core_word( char *tname); -bool create_core_alias( char *new_name, char *old_name); - -void enter_global_scope( void ); -void resume_device_scope( void ); - -tic_hdr_t *lookup_current( char *name); -bool exists_in_current( char *tname); -tic_hdr_t *lookup_in_dev_node( char *tname); -void add_to_current( char *name, - TIC_P_DEFLT_TYPE fc_token, - fwtoken definer); -void hide_last_colon ( void ); -void reveal_last_colon ( void ); -bool create_current_alias( char *new_name, char *old_name ); +void enter_global_scope(void); +void resume_device_scope(void); -void emit_token( const char *fc_name); -tic_hdr_t *lookup_token( char *tname); -bool entry_is_token( tic_hdr_t *test_entry ); -void token_entry_warning( tic_hdr_t *t_entry); +tic_hdr_t *lookup_current(char *name); +bool exists_in_current(char *tname); +tic_hdr_t *lookup_in_dev_node(char *tname); +void add_to_current(char *name, TIC_P_DEFLT_TYPE fc_token, fwtoken definer); +void hide_last_colon(void); +void reveal_last_colon(void); +bool create_current_alias(char *new_name, char *old_name); -tic_hdr_t *lookup_shared_word( char *tname); -tic_hdr_t *lookup_shared_f_exec_word( char *tname); +void emit_token(const char *fc_name); +tic_hdr_t *lookup_token(char *tname); +bool entry_is_token(tic_hdr_t * test_entry); +void token_entry_warning(tic_hdr_t * t_entry); -void init_dictionary( void ); -void reset_normal_vocabs( void ); -void reset_vocabs( void ); +tic_hdr_t *lookup_shared_word(char *tname); +tic_hdr_t *lookup_shared_f_exec_word(char *tname); +void init_dictionary(void); +void reset_normal_vocabs(void); +void reset_vocabs(void); -#endif /* _TOKE_VOCABFUNCTS_H */ +#endif /* _TOKE_VOCABFUNCTS_H */ From 8d7070baf56a6bd71d4216c8d0d879f2bfc8ad43 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Thu, 28 Nov 2019 13:57:16 -0800 Subject: [PATCH 2/4] Simplify Makefiles to one central Makefile Drop separate Makefiles and license files. Signed-off-by: Stefan Reinauer --- Makefile | 79 ++++++++-- detok/COPYING | 341 -------------------------------------------- detok/Makefile | 69 --------- romheaders/COPYING | 341 -------------------------------------------- romheaders/Makefile | 49 ------- toke/COPYING | 341 -------------------------------------------- toke/Makefile | 79 ---------- 7 files changed, 65 insertions(+), 1234 deletions(-) delete mode 100644 detok/COPYING delete mode 100644 detok/Makefile delete mode 100644 romheaders/COPYING delete mode 100644 romheaders/Makefile delete mode 100644 toke/COPYING delete mode 100644 toke/Makefile diff --git a/Makefile b/Makefile index 624059e..bdded63 100644 --- a/Makefile +++ b/Makefile @@ -23,22 +23,73 @@ VERSION:=$(shell grep "^\#.*TOKE_VERSION" < toke/toke.c |cut -f2 -d\" ) -all: - $(MAKE) -C toke - $(MAKE) -C detok - $(MAKE) -C romheaders +DESTDIR = /usr/local +CC ?= gcc +STRIP = strip +INCLUDES=-I shared -I. -install: - $(MAKE) -C toke install - $(MAKE) -C detok install - $(MAKE) -C romheaders install - -clean: - $(MAKE) -C toke clean - $(MAKE) -C detok clean - $(MAKE) -C romheaders clean +# Normal Flags: +CFLAGS = -O2 -Wall #-Wextra +LDFLAGS = + +# Coverage: +#CFLAGS := $(CFLAGS) -fprofile-arcs -ftest-coverage +#LDFLAGS := $(LDFLAGS) -lgcov + +# Debugging: +#CFLAGS := $(CFLAGS) -g + +PROGRAMS = toke/toke detok/detok romheaders/romheaders + +TOKE_SOURCE = toke/clflags.c toke/conditl.c toke/devnode.c toke/dictionary.c +TOKE_SOURCE += toke/emit.c toke/errhandler.c toke/flowcontrol.c toke/macros.c +TOKE_SOURCE += toke/nextfcode.c toke/parselocals.c toke/scanner.c toke/stack.c +TOKE_SOURCE += toke/stream.c toke/strsubvocab.c toke/ticvocab.c toke/toke.c +TOKE_SOURCE += toke/tokzesc.c toke/tracesyms.c toke/usersymbols.c shared/classcodes.c +TOKE_OBJECTS := $(TOKE_SOURCE:.c=.o) + +DETOK_SOURCE = detok/addfcodes.c detok/decode.c detok/detok.c detok/dictionary.c +DETOK_SOURCE += detok/pcihdr.c detok/printformats.c detok/stream.c shared/classcodes.c +DETOK_OBJECTS := $(DETOK_SOURCE:.c=.o) + +ROMHEADERS_SOURCE = romheaders/romheaders.c shared/classcodes.c +ROMHEADERS_OBJECTS := $(ROMHEADERS_SOURCE:.c=.o) + +all: .dependencies $(PROGRAMS) + +toke/toke: $(TOKE_OBJECTS) + @echo " LD $@" + @$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ + @$(STRIP) -s $@ + +detok/detok: $(DETOK_OBJECTS) + @echo " LD $@" + @$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ + @$(STRIP) -s $@ + +romheaders/romheaders: $(ROMHEADERS_OBJECTS) + @echo " LD $@" + @$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ + @$(STRIP) -s $@ + +%.o: %.c + @echo " CC $@" + @$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $^ + +.dependencies: $(TOKE_SOURCE) $(DETOK_SOURCE) $(ROMHEADERS_SOURCE) + @$(CC) $(CFLAGS) $(INCLUDES) -MM $^ > .dependencies + +clean: + rm -rf $(PROGRAMS) $(TOKE_OBJECTS) $(DETOK_OBJECTS) $(ROMHEADERS_OBJECTS) + rm -f .dependencies $(MAKE) -C testsuite clean +-include .dependencies + +install: + mkdir -p $(DESTDIR)/bin + cp -a $(PROGRAMS) $(DESTDIR)/bin + distclean: clean $(MAKE) -C testsuite distclean find . -name "*.gcda" -exec rm -f \{\} \; @@ -56,5 +107,5 @@ coverage: @testsuite/GenCoverage . fcode-suite-$(VERSION) "FCode suite $(VERSION)" @testsuite/GenCoverage toke toke-$(VERSION) "Toke $(VERSION)" -.PHONY: all clean distclean toke detok romheaders tests +.PHONY: all clean distclean tests diff --git a/detok/COPYING b/detok/COPYING deleted file mode 100644 index 8a6932a..0000000 --- a/detok/COPYING +++ /dev/null @@ -1,341 +0,0 @@ - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/detok/Makefile b/detok/Makefile deleted file mode 100644 index 235966a..0000000 --- a/detok/Makefile +++ /dev/null @@ -1,69 +0,0 @@ -# -# OpenBIOS - free your system! -# ( FCode detokenizer ) -# -# This program is part of a free implementation of the IEEE 1275-1994 -# Standard for Boot (Initialization Configuration) Firmware. -# -# Copyright (C) 2001-2010 Stefan Reinauer -# Copyright (C) 2006-2009 coresystems GmbH -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA -# - -PROGRAM = detok - -DESTDIR = /usr/local -CC ?= gcc -STRIP = strip -INCLUDES = -I../shared - -# Normal Flags: -CFLAGS = -O2 -Wall #-Wextra -LDFLAGS = - -# Coverage: -#CFLAGS := $(CFLAGS) -fprofile-arcs -ftest-coverage -#LDFLAGS := $(LDFLAGS) -lgcov - -# Debugging: -#CFLAGS := $(CFLAGS) -g - - -OBJS = addfcodes.o decode.o detok.o dictionary.o pcihdr.o printformats.o \ - stream.o ../shared/classcodes.o - -all: .dependencies $(PROGRAM) - -$(PROGRAM): $(OBJS) - $(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS) - $(STRIP) $(PROGRAM) - -clean: - rm -f $(OBJS) *~ - rm -f $(PROGRAM) .dependencies - -.dependencies: *.c - @$(CC) $(CFLAGS) $(INCLUDES) -MM *.c > .dependencies - -.PHONY: all clean - --include .dependencies - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@ - -install: - mkdir -p $(DESTDIR)/bin - cp $(PROGRAM) $(DESTDIR)/bin/$(PROGRAM) diff --git a/romheaders/COPYING b/romheaders/COPYING deleted file mode 100644 index 8a6932a..0000000 --- a/romheaders/COPYING +++ /dev/null @@ -1,341 +0,0 @@ - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/romheaders/Makefile b/romheaders/Makefile deleted file mode 100644 index cdb3d51..0000000 --- a/romheaders/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -# OpenBIOS - free your system! -# ( Utilities ) -# -# This program is part of a free implementation of the IEEE 1275-1994 -# Standard for Boot (Initialization Configuration) Firmware. -# -# Copyright (C) 2002-2010 Stefan Reinauer -# Copyright (C) 2009 coresystems GmbH -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA -# - -PROGRAM = romheaders - -DESTDIR = /usr/local -CC ?= gcc -STRIP = strip -CFLAGS = -O2 -Wall -Wextra -INCLUDES = -I../shared - -SOURCES = romheaders.c ../shared/classcodes.c - -.SUFFIXES: .c - -all: romheaders - -romheaders: $(SOURCES) - $(CC) $(CFLAGS) $(INCLUDES) $(SOURCES) -o $@ - $(STRIP) romheaders - -clean: - rm -f *~ - rm -f $(PROGRAM) - -install: - mkdir -p $(DESTDIR)/bin - cp $(PROGRAM) $(DESTDIR)/bin/$(PROGRAM) diff --git a/toke/COPYING b/toke/COPYING deleted file mode 100644 index 8a6932a..0000000 --- a/toke/COPYING +++ /dev/null @@ -1,341 +0,0 @@ - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/toke/Makefile b/toke/Makefile deleted file mode 100644 index 0b9c928..0000000 --- a/toke/Makefile +++ /dev/null @@ -1,79 +0,0 @@ -# -# OpenBIOS - free your system! -# ( Utilities ) -# -# This program is part of a free implementation of the IEEE 1275-1994 -# Standard for Boot (Initialization Configuration) Firmware. -# -# Copyright (C) 2001-2006 Stefan Reinauer -# Copyright (C) 2006-2009 coresystems GmbH -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA -# - -PROGRAM = toke - -DESTDIR = /usr/local -CC ?= gcc -STRIP = strip -INCLUDES = -I../shared - -# Normal flags -CFLAGS = -O2 -Wall #-Wextra -LDFLAGS = - -# Coverage: -#CFLAGS := $(CFLAGS) -fprofile-arcs -ftest-coverage -#LDFLAGS := $(LDFLAGS) -lgcov - -# Debugging: -# CFLAGS := $(CFLAGS) -g - -# for gcc 4. remove if you fixed the code. -_GCC4_CFLAGS=$(shell echo 'main(int argc, char **argv){return 0;}' > .test.c; \ - $(CC) -Wno-pointer-sign -c .test.c -o .test.o > /dev/null 2>&1 \ - && echo -Wno-pointer-sign; rm .test.c .test.o ) -CFLAGS := $(CFLAGS) $(_GCC4_CFLAGS) - -OBJS = clflags.o conditl.o devnode.o dictionary.o emit.o errhandler.o \ - flowcontrol.o macros.o nextfcode.o parselocals.o scanner.o stack.o \ - stream.o strsubvocab.o ticvocab.o toke.o tokzesc.o tracesyms.o \ - usersymbols.o ../shared/classcodes.o - -all: .dependencies $(PROGRAM) - -$(PROGRAM): $(OBJS) - $(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS) - $(STRIP) $(PROGRAM) - -clean: - rm -f $(OBJS) *~ - rm -f $(PROGRAM) .dependencies - -.dependencies: *.c - @$(CC) $(CFLAGS) $(INCLUDES) -MM *.c > .dependencies - -documentation:: *.c *.h toke.doxygen - @doxygen toke.doxygen - -.PHONY: all clean - --include .dependencies - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@ - -install: - mkdir -p $(DESTDIR)/bin - cp $(PROGRAM) $(DESTDIR)/bin/$(PROGRAM) From c236a0745b74550bb64f693a30ef4d8a8a79d9cb Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Thu, 28 Nov 2019 14:09:43 -0800 Subject: [PATCH 3/4] Use char instead of u8 in most places it helps get rid of unneeded casting Signed-of-by: Stefan Reinauer --- detok/addfcodes.c | 6 ++--- detok/decode.c | 4 +--- toke/emit.c | 12 ++++------ toke/emit.h | 2 +- toke/parselocals.c | 10 ++++---- toke/scanner.c | 58 +++++++++++++++++++++------------------------- toke/scanner.h | 4 ++-- toke/stream.c | 8 +++---- toke/stream.h | 6 ++--- toke/strsubvocab.h | 4 ++-- toke/toke.c | 2 +- 11 files changed, 52 insertions(+), 64 deletions(-) diff --git a/detok/addfcodes.c b/detok/addfcodes.c index 1d884e6..b07e99e 100644 --- a/detok/addfcodes.c +++ b/detok/addfcodes.c @@ -369,10 +369,8 @@ bool add_fcodes_from_list(char *vf_file_name) 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]; + if (strcmp(vs_fc_name, spcl_func_list[indx].name) == 0) { + char strbuf[85]; found_spf = TRUE; spcl_func_list[indx].fcode = vs_fc_number; diff --git a/detok/decode.c b/detok/decode.c index 615afd3..a58df6f 100644 --- a/detok/decode.c +++ b/detok/decode.c @@ -411,10 +411,8 @@ static void decode_branch(void) static void decode_two(void) { - u16 token; - output_token(); - token = next_token(); + next_token(); output_token_name(); printf("\n"); } diff --git a/toke/emit.c b/toke/emit.c index c69b109..8317299 100644 --- a/toke/emit.c +++ b/toke/emit.c @@ -130,7 +130,7 @@ static bool fcode_written = FALSE; * **************************************************************************** */ -extern u8 *ostart; +extern char *ostart; extern int olen; extern void increase_output_buffer(void); @@ -172,7 +172,7 @@ static void emit_byte(u8 data) increase_output_buffer(); } - *(ostart + opc) = data; + *(ostart + opc) = (char)data; opc++; } @@ -223,7 +223,7 @@ void emit_literal(u32 num) emit_num32(num); } -void emit_string(u8 * string, signed int cnt) +void emit_string(const char *string, signed int cnt) { signed int i = 0; signed int cnt_cpy = cnt; @@ -310,8 +310,8 @@ void finish_fcodehdr(void) u32 checksum; int length; - u8 *fcode_body = ostart + fcode_body_ob_off; - u8 *ob_end = ostart + opc; + char *fcode_body = ostart + fcode_body_ob_off; + char *ob_end = ostart + opc; fcode_header_t *fcode_hdr = (fcode_header_t *) (ostart + fcode_hdr_ob_off); @@ -547,7 +547,6 @@ void finish_pcihdr(void) u32 imageblocks; int padding; - rom_header_t *pci_hdr; pci_data_t *pci_data_blk; if (pci_data_blk_ob_off == -1) { @@ -556,7 +555,6 @@ void finish_pcihdr(void) return; } - pci_hdr = (rom_header_t *) (ostart + pci_hdr_ob_off); pci_data_blk = (pci_data_t *) (ostart + pci_data_blk_ob_off); /* fix up vpd */ diff --git a/toke/emit.h b/toke/emit.h index 7a02766..23eb01e 100644 --- a/toke/emit.h +++ b/toke/emit.h @@ -110,7 +110,7 @@ void emit_fcode(u16 tok); void user_emit_byte(u8 data); void emit_offset(s16 offs); -void emit_string(u8 * string, signed int cnt); +void emit_string(const char *string, signed int cnt); void emit_fcodehdr(const char *starter_name); void finish_fcodehdr(void); void emit_pcihdr(void); diff --git a/toke/parselocals.c b/toke/parselocals.c index 754a607..bec525f 100644 --- a/toke/parselocals.c +++ b/toke/parselocals.c @@ -226,7 +226,7 @@ static char *int_to_str(int num, char *bufr) static void invoke_local(tic_param_t pfield) { - char local_num_buf[10]; + char local_num_buf[14]; int loc_num = (int)pfield.deflt_elem; int_to_str(loc_num, local_num_buf); @@ -502,8 +502,8 @@ static bool gather_locals(bool initted, int *counter) static void activate_locals(void) { - char ilocals_buf[10]; - char ulocals_buf[10]; + char ilocals_buf[14]; + char ulocals_buf[14]; int_to_str(num_ilocals, ilocals_buf); int_to_str(num_ulocals, ulocals_buf); @@ -799,7 +799,7 @@ void assign_local(void) { signed long wlen; bool is_okay; - u8 *savd_pc = pc; + char *savd_pc = pc; unsigned int savd_lineno = lineno; wlen = get_word(); @@ -873,7 +873,7 @@ void finish_locals(void) { /* Don't do anything if Locals are not in use */ if (localno > 0) { - char nlocals_buf[10]; + char nlocals_buf[14]; int_to_str(localno, nlocals_buf); sprintf(eval_buf, "%s %s", nlocals_buf, pop_locals); diff --git a/toke/scanner.c b/toke/scanner.c index 7422fa1..3422c22 100644 --- a/toke/scanner.c +++ b/toke/scanner.c @@ -66,7 +66,7 @@ * **************************************************************************** */ -u8 *statbuf = NULL; /* The word just read from the input stream */ +char *statbuf = NULL; /* The word just read from the input stream */ u8 base = 0x0a; /* The numeric-interpretation base */ /* pci data */ @@ -268,7 +268,7 @@ bool skip_until(char lim_ch) static signed long get_until(char needle) { - u8 *safe; + char *safe; unsigned long len = 0; safe = pc; @@ -329,9 +329,9 @@ static signed long get_until(char needle) typedef struct source_state { struct source_state *next; - u8 *old_start; - u8 *old_pc; - u8 *old_end; + char *old_start; + char *old_pc; + char *old_end; char *old_iname; unsigned int old_lineno; bool pause_before_pop; @@ -580,7 +580,7 @@ static bool pop_source(void) signed long get_word(void) { size_t len; - u8 *str; + char *str; bool keep_skipping; bool pop_result; @@ -663,7 +663,7 @@ bool get_word_in_line(char *func_nam) { signed long wlen; bool retval = TRUE; - u8 *save_pc = pc; + char *save_pc = pc; unsigned int save_lineno = lineno; unsigned int save_abs_token_no = abs_token_no; @@ -722,7 +722,7 @@ bool get_word_in_line(char *func_nam) bool get_rest_of_line(void) { bool retval = FALSE; - u8 *save_pc = pc; + char *save_pc = pc; unsigned int save_lineno = lineno; unsigned int save_abs_token_no = abs_token_no; @@ -890,12 +890,12 @@ static void string_remark(char *errmsg_txt) * the calling routine is responsible for ascertaining * the validity of the string being passed. */ -static long parse_number(u8 * start, u8 ** endptr, int lbase) +static long parse_number(char *start, char **endptr, int lbase) { long val = 0; bool negative = FALSE; int curr; - u8 *nptr = start; + char *nptr = start; curr = *nptr; if (curr == '-') { @@ -968,7 +968,7 @@ static long parse_number(u8 * start, u8 ** endptr, int lbase) * **************************************************************************** */ -static void add_byte_to_string(u8 nu_byte, u8 ** walk) +static void add_byte_to_string(char nu_byte, char **walk) { if (*walk - statbuf < GET_BUF_MAX) { **walk = nu_byte; @@ -1024,10 +1024,10 @@ static void add_byte_to_string(u8 nu_byte, u8 ** walk) * **************************************************************************** */ -static void c_string_escape(u8 ** walk) +static void c_string_escape(char **walk) { char c = *pc; - u8 val; + char val; /* We will come out of this "switch" statement * with a value for val and a decision * as to whether to write it. @@ -1061,7 +1061,7 @@ static void c_string_escape(u8 ** walk) */ { long lval; - u8 *sav_pc = pc; + char *sav_pc = pc; lval = parse_number(pc, &pc, base); val = (u8) lval; #ifdef DEBUG_SCANNER @@ -1205,7 +1205,7 @@ static void c_string_escape(u8 ** walk) * **************************************************************************** */ -static bool get_sequence(u8 ** walk) +static bool get_sequence(char **walk) { int pv_indx = 0; bool retval = FALSE; /* "Abnormal Completion" indicator */ @@ -1293,7 +1293,7 @@ static bool get_sequence(u8 ** walk) static signed long get_string(bool pack_str) { - u8 *walk; + char *walk; unsigned long len; char c; bool run = TRUE; @@ -1492,14 +1492,13 @@ static signed long get_string(bool pack_str) static void handle_user_message(char delim, bool print_it) { - signed long wlen; unsigned int start_lineno = lineno; unsigned int multiline_start = lineno; /* For warning message */ bool check_multiline = FALSE; const char *ug_msg = "user-generated message"; if (delim == '"') { - wlen = get_string(FALSE); + get_string(FALSE); } else { /* * When the message-delimiter is a new-line, and the @@ -1520,7 +1519,7 @@ static void handle_user_message(char delim, bool print_it) multiline_start = lineno; check_multiline = TRUE; } - wlen = get_until(delim); + get_until(delim); } if (print_it) { @@ -1639,7 +1638,7 @@ void skip_user_message(tic_param_t pfield) bool get_number(long *result) { - u8 *until; + char *until; long val; bool retval = FALSE; @@ -3144,7 +3143,7 @@ static bool create_word(fwtoken definer) strupr(statbuf); } } - emit_string((u8 *) statbuf, wlen); + emit_string(statbuf, wlen); } /* Emit the new token's FCode */ @@ -3300,7 +3299,7 @@ static bool validate_to_target(void) { signed long wlen; tic_hdr_t *test_entry; - u8 *saved_pc = pc; + char *saved_pc = pc; char *cmd_cpy = strupr(strdup(statbuf)); /* For error message */ unsigned int saved_lineno = lineno; unsigned int saved_abs_token_no = abs_token_no; @@ -3625,7 +3624,7 @@ static bool get_token(tic_hdr_t ** tok_entry) { bool retval = FALSE; tic_hdr_t *found; - u8 *save_pc; + char *save_pc; /* Copy of command being processed, for error message */ char cmnd_cpy[FUNC_CPY_BUF_SIZE + 1]; @@ -3688,7 +3687,7 @@ static void base_change(int new_base) static void base_val(int new_base) { - u8 *old_pc; + char *old_pc; char base_cmnd[FUNC_CPY_BUF_SIZE + 1]; strncpy(base_cmnd, statbuf, FUNC_CPY_BUF_SIZE); @@ -3912,9 +3911,8 @@ static bool abort_quote(fwtoken tok) if (!enable_abort_quote) { /* ABORT" is not enabled; we'd better consume the string */ char *save_statbuf; - signed long wlen; save_statbuf = strdup((char *)statbuf); - wlen = get_string(FALSE); + get_string(FALSE); strcpy(statbuf, save_statbuf); free(save_statbuf); } else { @@ -3926,7 +3924,6 @@ static bool abort_quote(fwtoken tok) * Presumably, Apple Source supplies its own * IF ... THEN */ - char *abort_string; signed long wlen; retval = TRUE; @@ -3953,8 +3950,6 @@ static bool abort_quote(fwtoken tok) if (sun_style_abort_quote) emit_then(); - /* Sun Style */ - abort_string = " type -2 THROW THEN:"; } } return (retval); @@ -4921,8 +4916,7 @@ void handle_internal(tic_param_t pfield) tokenization_error(MESSAGE, temp_buffr); } else { emit_token("b(\")"); - emit_string((u8 *) temp_buffr, - strlen(temp_buffr)); + emit_string(temp_buffr, strlen(temp_buffr)); } } break; @@ -5155,7 +5149,7 @@ void process_remark(tic_param_t pfield) * **************************************************************************** */ -bool filter_comments(u8 * inword) +bool filter_comments(char *inword) { bool retval = FALSE; tic_hdr_t *found = lookup_word(inword, NULL, NULL); diff --git a/toke/scanner.h b/toke/scanner.h index ebb3f1e..d48948c 100644 --- a/toke/scanner.h +++ b/toke/scanner.h @@ -43,7 +43,7 @@ * **************************************************************************** */ -extern u8 *statbuf; /* The word just read from the input stream */ +extern char *statbuf; /* The word just read from the input stream */ extern u8 base; /* The numeric-interpretation base */ /* pci data */ @@ -103,7 +103,7 @@ bool get_number(long *result); void eval_string(char *inp_bufr); void process_remark(tic_param_t pfield); -bool filter_comments(u8 * inword); +bool filter_comments(char *inword); bool as_a_what(fwtoken definer, char *as_what); tic_hdr_t *lookup_word(char *stat_name, char **where_pt1, char **where_pt2); bool word_exists(char *stat_name, char **where_pt1, char **where_pt2); diff --git a/toke/stream.c b/toke/stream.c index 633fd6a..9a4c8fe 100644 --- a/toke/stream.c +++ b/toke/stream.c @@ -82,9 +82,9 @@ **************************************************************************** */ /* Input pointers, Position Counters and Length counters */ -u8 *start = NULL; -u8 *pc; -u8 *end; +char *start = NULL; +char *pc; +char *end; char *iname = NULL; unsigned int lineno = 0; unsigned int abs_token_no = 0; /* Absolute Token Number in all Source Input @@ -1048,7 +1048,7 @@ FILE *open_expanded_file(const char *path_name, char *mode, char *for_what) bool init_stream(const char *name) { FILE *infile; - u8 *newbuf; + char *newbuf; struct stat finfo; bool stat_succ = FALSE; bool tried_stat = FALSE; diff --git a/toke/stream.h b/toke/stream.h index d227faf..294ef12 100644 --- a/toke/stream.h +++ b/toke/stream.h @@ -42,9 +42,9 @@ **************************************************************************** */ /* input pointers */ -extern u8 *start; -extern u8 *pc; -extern u8 *end; +extern char *start; +extern char *pc; +extern char *end; extern char *iname; extern unsigned int lineno; /* Line Number within current input file */ extern unsigned int abs_token_no; /* Absolute Token Number in Source Input */ diff --git a/toke/strsubvocab.h b/toke/strsubvocab.h index 334bb60..483876d 100644 --- a/toke/strsubvocab.h +++ b/toke/strsubvocab.h @@ -48,8 +48,8 @@ #include "types.h" typedef struct str_sub_vocab { - u8 *name; - u8 *alias; + char *name; + char *alias; struct str_sub_vocab *next; } str_sub_vocab_t; diff --git a/toke/toke.c b/toke/toke.c index 92a1bba..84439f2 100644 --- a/toke/toke.c +++ b/toke/toke.c @@ -106,7 +106,7 @@ static void print_copyright(void) "This program has absolutely no warranty.\n\n"); #ifdef DEVEL /* Temporary hack during development... */ - printf("\tTokenizer Compiled " DATE_STAMP "\n"); + printf("\tTokenizer compiled " DATE_STAMP "\n"); #endif /* DEVEL */ } From d48d8151d154c5af958a92969acb69a6800f2656 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Thu, 28 Nov 2019 14:13:41 -0800 Subject: [PATCH 4/4] Drop ChangeLog We have version control. Signed-off-by: Stefan Reinauer --- ChangeLog | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index c51cdb3..0000000 --- a/ChangeLog +++ /dev/null @@ -1,37 +0,0 @@ - -1.0.2 ------ - -David Paktor: -The most prominent change is that the Tokenizer's Message -format has been expanded to show the current Output Position -and, if applicable, the position relative to the end of the -most recent PCI Header (to keep in sync with Offset numbers -displayed by the DeTokenizer.) - -The Symbol-Tracing feature has been changed and expanded: -Its Messages are no longer Advisories, but a class of their -own called Trace-Notes. When a Traced Symbol is created, the -Trace-Note Message gives the new Symbol's assigned FCode Token -(when applicable) in addition to the Data-Type and Scope of -the definition. - -A Trace-Note Message is now also issued when a Traced Symbol -is invoked. Symbol-Tracing is not fooled by aliases, and a -failed attempt to create or invoke a Traced Symbol will also -cause a Trace-Note Message to be displayed. - -These expansions are based on some questions asked by one of -my colleagues while maintaining a very large and convoluted -body of Legacy code -- questions like: "Where is such-and-so -definition coming from?" "Which version of it is being used -here?" "How can I find where exactly that is in the Binary?" - -Another change is based on the recent exchange of letters with -Rolf Schroedter concerning the use of the emit-fcode command. -In the previous version, arguments to the emit-fcode command -were limited to the range of user-defined FCodes, i.e., 0x800 -to 0xFFF. The new version permits numbers in the entire range -of valid FCodes, 0x010 to 0xFFF, which includes the sub-ranges -that are reserved for Vendor-Specific FCodes. -