4646 * Identified this need when working with in-house code,
4747 * which uses some custom functions. This solution
4848 * is (hoped to be) general enough to cover all cases.
49+ * Mon, 16 Oct 2006 by David L. Paktor
50+ * Add "special function" words. So far, only one added:
51+ * double-literal Infrastructure will support
52+ * adding others as needed.
4953 *
5054 **************************************************************************** */
5155
5862 *
5963 **************************************************************************** */
6064
65+
66+ /* **************************************************************************
67+ *
68+ * Global Variables Exported :
69+ *
70+ * For "special function" identification, we will need to
71+ * export Global Variables, each of which is a pointer
72+ * to the address of the FCode field of the entry in
73+ * the Special Functions List for that function.
74+ *
75+ * Variable Associated Name
76+ * double_lit_code double-literal
77+ *
78+ **************************************************************************** */
79+
6180#include <stdio.h>
6281#include <stdlib.h>
6382#include <string.h>
7392 * vfc_remainder Remainder of Vendor-FCodes buffer to be scanned
7493 * vfc_line_no Number of current line in Vendor-FCodes buffer
7594 * vfc_buf_end Pointer to end of Vendor-FCodes buffer
95+ * spcl_func_list List of reserved Special Function names
96+ * spcl_func_count Number of reserved Special Function names
7697 *
7798 **************************************************************************** */
7899
@@ -81,6 +102,22 @@ static char *vfc_remainder;
81102static int vfc_line_no = 0 ;
82103static char * vfc_buf_end ;
83104
105+ /* Special Functions List */
106+ /* Initial fcode-field value of -1 guarantees they won't be used */
107+ token_t spcl_func_list [] = {
108+ TOKEN_ENTRY ( -1 , "double(lit)" ), /* Entry [0] */
109+ };
110+
111+ static const int spcl_func_count = (sizeof (spcl_func_list )/sizeof (token_t )) ;
112+
113+ /* Global Variables for "special function" identification */
114+ /* Each is a pointer to the FCode field of the entry in
115+ * the Special Functions List for that function.
116+ */
117+
118+ u16 * double_lit_code = & spcl_func_list [0 ].fcode ;
119+
120+
84121/* **************************************************************************
85122 *
86123 * Function name: skip_whitespace
@@ -231,11 +268,19 @@ static void vfc_splash(char *vf_file_name)
231268 * after the name will be ignored, so an extra "comment"
232269 * is permitted. The FCode number must be in hex, with
233270 * an optional leading 0x or 0X For example: 0X407
234- * The valid range is 0x010 to 0x7ff. Numbers above 0x800
235- * infringe upon the are reserved for FCodes generated
236- * by the tokenization process.
271+ * The valid range for the FCode numbers is 0x010 to 0x7ff.
272+ * Numbers above 0x800 infringe upon the area reserved
273+ * for FCodes generated by the tokenization process.
237274 * Numbers already in use will be ignored. A Message will be
238275 * printed even if the name matches the one on the line.
276+ * Names may not be longer than 31 characters.
277+ * Certain names will be reserved for special functions.
278+ * Those names will be entered in the detok_table
279+ * with a value of -1 and again in the static
280+ * table associated with this function, below, to
281+ * supply the variable that will be used to match
282+ * the name with the special function.
283+ *
239284 *
240285 **************************************************************************** */
241286
@@ -267,6 +312,13 @@ bool add_fcodes_from_list(char *vf_file_name)
267312 char * lookup_result ;
268313 char * fc_name_cpy ;
269314
315+ /* For each line of input, we need to check that we have
316+ * two strings, one of which is the number and the
317+ * second of which is the name. We will check for
318+ * the various formats allowed for the number
319+ */
320+
321+ /* Start with a lower-case 0x */
270322 scan_result = sscanf (current_vfc_line , "0x%x %32s" ,
271323 & vs_fc_number , vs_fc_name );
272324
@@ -315,6 +367,28 @@ bool add_fcodes_from_list(char *vf_file_name)
315367 continue ;
316368 }
317369
370+ /* Check if the name is on the "Special Functions List" */
371+ {
372+ bool found_spf = FALSE;
373+ int indx ;
374+ for (indx = 0 ; indx < spcl_func_count ; indx ++ ) {
375+ if ( strcmp ( vs_fc_name , spcl_func_list [indx ].name ) == 0 ) {
376+ char strbuf [64 ];
377+ found_spf = TRUE;
378+ spcl_func_list [indx ].fcode = vs_fc_number ;
379+ link_token ( & spcl_func_list [indx ]);
380+ added_fc_count ++ ;
381+ sprintf ( strbuf , "Added Special Function FCode "
382+ "number 0x%03x, name %s\n" , vs_fc_number , vs_fc_name );
383+ printremark ( strbuf );
384+ break ;
385+ }
386+ }
387+
388+ if (found_spf )
389+ continue ;
390+ }
391+
318392 /* We've passed all the tests! */
319393 fc_name_cpy = strdup (vs_fc_name );
320394 add_token ((u16 ) vs_fc_number , fc_name_cpy );
@@ -323,11 +397,10 @@ bool add_fcodes_from_list(char *vf_file_name)
323397 }
324398
325399 if (verbose ) {
326- char * strbfr = malloc ( 85 );
400+ char strbfr [ 32 ];
327401 sprintf (strbfr ,
328402 "Added %d FCode numbers\n" , added_fc_count );
329403 printremark (strbfr );
330- free (strbfr );
331404 }
332405
333406 close_stream ();
0 commit comments