home *** CD-ROM | disk | FTP | other *** search
- /*
-
-
- Copyright (C) 1990 Texas Instruments Incorporated.
-
- Permission is granted to any individual or institution to use, copy, modify,
- and distribute this software, provided that this complete copyright and
- permission notice is maintained, intact, in all copies and supporting
- documentation.
-
- Texas Instruments Incorporated provides this software "as is" without
- express or implied warranty.
-
-
- *
- * I/O support for internal defmacros
- * Defmacros which execute in their own process use stdin and stdout.
- * Defmacros which execute as cpp functions use these routines instead.
- *
- * Edit history
- * Created: LGO 30-Mar-89 -- Initial design and implementation.
- *
- */
-
- #include <ctype.h>
- #include <stdio.h>
-
- #define EOS 0
- #ifndef TRUE
- #define TRUE 1
- #define FALSE 0
- #endif
-
- typedef int Boolean;
-
- /************************************************************/
-
- /* I moved these definitions in here from hash.c because the SAS C
- * compiler (MVS) complains about not knowing about type Hash_Table
- * in declaration extern struct Hash_Table* init_Hash_Table();
- * This looks like a bug their compiler ... DKM
- */
-
- #define BUCKET_SIZE 8
-
- static int hash_primes[] = {3, 7, 13, 19, 29, 41, 53, 67, 83, 97, 113, 137,
- 163, 191, 223, 263, 307, 349, 401, 461, 521, 587,
- 653, 719, 773, 839, 911, 983, 1049, 1123, 1201,
- 1279, 1367, 1459, 1549, 1657, 1759, 1861, 1973,
- 2081, 2179, 2281, 2383, 2503, 2617, 2729, 2843,
- 2963, 3089, 3203, 3323, 3449, 3571, 3697, 3833,
- 3967, 4099, 4241, 4391, 4549, 4703, 4861, 5011,
- 5171, 5333, 5483, 5669, 5839, 6029, 6197, 6361,
- 6547, 6761, 6961, 7177, 7393, 7517, 7727, 7951,
- 8101, 8209, 16411, 32771, 65537, 131301, 262147,
- 524287};
-
- struct hash_pair {
- char* key;
- void* value;
- };
-
- struct bucket {
- struct hash_pair data[BUCKET_SIZE];
- };
-
- struct Hash_Table {
- struct bucket* table;
- unsigned char* items_in_buckets;
- int entry_count;
- int bucket_index;
- int current_bucket;
- int current_index;
- };
-
- /**************************************************************/
-
- #if defined (DOS) || defined (MSDOS)
- extern void free (void *);
- #endif
-
- extern char* strcpy(/* char*, char* */);
- extern char* strcat(/* char*, char* */);
- extern char* getmem(/* int byte_count */);
- extern char* savestring(/* char* */);
- extern cerror(/* char* format_string, char* string_arg */);
-
- extern struct Hash_Table* init_Hash_Table();
- extern void* get_hash(/* Hash_Table, key */);
- extern Boolean put_hash(/* Hash_Table, key, value */);
- extern void* next_hash(/* Hash_Table, firstp */);
-
- extern char* lookup_symbol(/* char* pkgname, char* symname */);
-
- extern void new_defmacro(); /* Define a new defmacro */
-
- /*
- * The FILEINFO structure stores information about open files
- * and macros being expanded.
- */
- /* WARNING: This structure is duplicated in cpp.h */
- typedef struct fileinfo {
- char *bptr; /* Buffer pointer */
- int line; /* for include or macro */
- FILE *fp; /* File if non-null */
- struct fileinfo *parent; /* Link to includer */
- char *filename; /* File/macro name */
- char *progname; /* From #line statement */
- unsigned int unrecur; /* For macro recursion */
- char* buffer; /* current input line */
- } FILEINFO;
-
- extern FILEINFO *MacInFile, *MacOutFile;
- extern char* MacOutEnd;
- extern void NextMacOutString(); /* takes 1 char* parameter */
- extern char NextMacInChar();
- extern void NextMacOutBuffer();
- extern void set_inbuffer(/* char* instring */);
-
- /* get the next input character */
- #undef getchar
- #define getchar() (*MacInFile->bptr ? *MacInFile->bptr++ : NextMacInChar())
-
- /* unget the last character */
- #undef unget
- #define unget() (MacInFile->bptr--)
-
- /* put the next character to output */
- #undef putchar
- #define putchar(c) \
- {if (MacOutFile->bptr > MacOutEnd) NextMacOutBuffer(); \
- *MacOutFile->bptr++ = c;}
-
- #define puts(s) NextMacOutString(s)
-
- extern char skip_blanks();
- extern char skip_line();
- extern char* copytoken(/* char* */);
- extern void scan_start();
- extern char* scan_next(/* char delim */);
- extern char* scan_list(/* char delim */);
- extern char* scan_token(/* char* delims */);
-
- extern void put_string(/* char* */);
-
- extern char* c_upcase(/* char* */);
- extern char* c_downcase(/* char* */);
- extern char* c_capitalize(/* char* */);
- extern char* c_trim_all (/* char*, char* */);
-
- typedef struct String {
- char* buff;
- char* buffp;
- char* buffend;
- }* STRING;
-
- STRING make_STRING(/* int size */);
- void destroy_STRING(/* STRING string */);
- void grow_STRING(/* STRING string, unsigned int len */);
- void append_STRING(/* STRING string, char* chars */);
- char append_blanks(/* STRING string */);
-
- #define append_char(string, c) \
- { if(string->buffp>=string->buffend) grow_STRING(string,(unsigned int)0); \
- *string->buffp++ = (c); }
-
- extern STRING work_string; /* string buffer for utilities */
- extern int current_line; /* line at start of defmacro */
- extern char current_file[]; /* file at start of defmacro */
-