summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>2002-08-11 08:50:48 +0200
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:48:48 +0200
commit26ade8d624457b7164502ed9c190ca3f146bda0c (patch)
tree75a70b6a562bc595c971e170994a8e302a8c7b3b /cpp
parent660429af0232d4afcb3e03fb0437053dd6e16286 (diff)
downloaddev86-26ade8d624457b7164502ed9c190ca3f146bda0c.tar.gz
Import Dev86src-0.16.8.tar.gzv0.16.8
Diffstat (limited to 'cpp')
-rw-r--r--cpp/Makefile14
-rw-r--r--cpp/c.c10
-rw-r--r--cpp/cpp.c75
-rw-r--r--cpp/hash.c2
-rw-r--r--cpp/main.c42
-rw-r--r--cpp/token1.c5
-rw-r--r--cpp/token1.h117
-rw-r--r--cpp/token2.c5
-rw-r--r--cpp/token2.h139
9 files changed, 356 insertions, 53 deletions
diff --git a/cpp/Makefile b/cpp/Makefile
index b5d5322..0ea43cc 100644
--- a/cpp/Makefile
+++ b/cpp/Makefile
@@ -5,11 +5,11 @@ all: bcc-cpp
bcc-cpp: main.o cpp.o hash.o token1.o token2.o
$(CC) $(CFLAGS) -o bcc-cpp main.o cpp.o hash.o token1.o token2.o
-realclean: clean
- rm -f bcc-cpp token1.h token2.h
+clean realclean:
+ rm -f bcc-cpp main.o cpp.o hash.o token1.o token2.o tmp.h
-clean:
- rm -f main.o cpp.o hash.o token1.o token2.o
+maintclean: realclean
+ rm -f token1.h token2.h
main.o: cc.h
cpp.o: cc.h
@@ -20,7 +20,9 @@ token1.o: token1.h
token2.o: token2.h
token1.h: token1.tok
- gperf -aptTc -N is_ctok -H hash1 token1.tok > token1.h
+ gperf -aptTc -N is_ctok -H hash1 token1.tok > tmp.h
+ mv tmp.h token1.h
token2.h: token2.tok
- gperf -aptTc -k1,3 -N is_ckey -H hash2 token2.tok > token2.h
+ gperf -aptTc -k1,3 -N is_ckey -H hash2 token2.tok > tmp.h
+ mv tmp.h token2.h
diff --git a/cpp/c.c b/cpp/c.c
index 5e1ef4e..89f3120 100644
--- a/cpp/c.c
+++ b/cpp/c.c
@@ -1,14 +1,14 @@
#include <stdio.h>
#include <errno.h>
-#if __STDC__
+#if __STDC__ == (1UL)
#define strong_alias(Y,X) asm("export _" #X, "_" #X " = _" #Y )
#else
#define strong_alias(Y,X) asm("export _" "X", "_" "X" " = _" "Y" )
#endif
#if __STDC__
-#define comb(x,y) x##y
+#define comb(x,y) x ## y
#warning Using Ansi combine
#elif __BCC__
#define comb(x,y) x/**/y
@@ -36,7 +36,13 @@ main()
int i1, i2, i3;
printf("sizeof(long double) = %d\n", sizeof(long double));
+#ifdef __GNUC__
+ printf("sizeof(long float) = ERROR!\n");
+ printf("sizeof(long long) = %d\n", sizeof(long long));
+#else
printf("sizeof(long float) = %d\n", sizeof(long float));
+ printf("sizeof(long long) = ERROR!\n");
+#endif
printf("sizeof(double) = %d\n", sizeof(double));
printf("sizeof(float) = %d\n", sizeof(float));
diff --git a/cpp/cpp.c b/cpp/cpp.c
index 57cbda0..030535e 100644
--- a/cpp/cpp.c
+++ b/cpp/cpp.c
@@ -28,6 +28,12 @@
* TODO:
* #asm -> asm("...") translation.
* ?: in #if expressions
+ * __DATE__ and __TIME__ macros.
+ * Add #line directive.
+ * Poss: Seperate current directory for #include from errors (#line).
+ * Poss: C99 Variable macro args.
+ * \n in "\n" in a stringized argument.
+ * Comments in stringized arguments should be deleted.
*/
#define KEEP_SPACE 0
@@ -44,7 +50,11 @@ FILE * curfile;
char * c_fname;
int c_lineno = 0;
+#ifdef __BCC__
+typedef long int_type; /* Used for preprocessor expressions */
+#else
typedef int int_type; /* Used for preprocessor expressions */
+#endif
static int curtok = 0; /* Used for preprocessor expressions */
static int fi_count = 0;
@@ -132,7 +142,7 @@ gettok()
}
/* Special for quoted strings */
- *curword = 0;
+ *curword = '\0';
ch = chget();
if( ch == EOF ) return ch;
@@ -274,6 +284,12 @@ break_break:
{
if( state < 6 )
{
+ if( ch == 'u' || ch == 'U' )
+ {
+ if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */
+ *p = '\0'; cc++;
+ ch = chget();
+ }
if( ch == 'l' || ch == 'L' )
{
if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */
@@ -406,7 +422,7 @@ break_break:
*p++ = ch;
} else
unchget(ch);
- *p = 0;
+ *p = '\0';
return TK_STR;
}
@@ -720,26 +736,23 @@ do_proc_include()
if( ch == ch1 )
{
*p = '\0';
+ p = strdup(curword);
- fd = open_include(curword, "r", (ch=='"'));
- if( fd == 0 )
- cerror("Cannot open include file");
- do { ch = pgetc(); } while(ch == ' ' || ch == '\t'); unchget(ch);
+ do { ch1 = pgetc(); } while(ch1 == ' ' || ch1 == '\t');
+ unchget(ch1);
do_proc_tail();
- if( fd )
- {
- saved_files[fi_count] = curfile;
- saved_fname[fi_count] = c_fname;
- saved_lines[fi_count] = c_lineno;
- fi_count++;
-
- curfile = fd;
- c_fname = malloc(strlen(curword)+1);
- if( c_fname == 0 ) cfatal("Preprocessor out of memory");
- strcpy(c_fname, curword);
- c_lineno = 1;
- }
+ saved_files[fi_count] = curfile;
+ saved_fname[fi_count] = c_fname;
+ saved_lines[fi_count] = c_lineno;
+
+ fd = open_include(p, "r", (ch=='"'));
+ if( fd ) {
+ fi_count++;
+ curfile = fd;
+ } else
+ cerror("Cannot open include file");
+
return;
}
*p++ = ch;
@@ -778,7 +791,7 @@ do_proc_define()
len = WORDSIZE;
ptr = malloc(sizeof(struct define_item) + WORDSIZE);
if(ptr==0) cfatal("Preprocessor out of memory");
- ptr->value[cc=0] = 0;
+ ptr->value[cc=0] = '\0';
/* Add in arguments */
if( ch1 == '(' )
@@ -832,7 +845,7 @@ do_proc_define()
}
if (cc)
ptr->value[cc++] = ' ';/* Byte of lookahead for recursive macros */
- ptr->value[cc++] = 0;
+ ptr->value[cc++] = '\0';
#if CPP_DEBUG
if (cc == 1)
@@ -1212,8 +1225,10 @@ get_exp_value()
value = get_expression(0);
if (curtok == ')')
curtok = get_onetok(SKIP_SPACE);
- else
+ else {
curtok = '$';
+ cerror("Expected ')'");
+ }
}
return sign<0 ? -value: value;
@@ -1248,7 +1263,7 @@ int arg_count;
arg_list[ac].name = realloc(arg_list[ac].name, len);
}
arg_list[ac].name[cc++] = *data_str;
- arg_list[ac].name[cc] = 0;
+ arg_list[ac].name[cc] = '\0';
}
for(;;) {
@@ -1290,7 +1305,7 @@ int arg_count;
#endif
arg_list[ac].value[cc++] = ch;
- arg_list[ac].value[cc] = 0;
+ arg_list[ac].value[cc] = '\0';
}
if (commas_found || args_found) args_found = commas_found+1;
@@ -1359,12 +1374,12 @@ int arg_count;
}
#endif
- rv = malloc(4); *rv = 0; len = 4;
+ rv = malloc(4); *rv = '\0'; len = 4;
while(*data_str) {
p = curword;
- if (dialect != DI_KNR) {
+ if (dialect == DI_ANSI) {
if (in_quote == 2)
in_quote = 1;
else if (in_quote) {
@@ -1396,7 +1411,7 @@ int arg_count;
data_str+=2;
while(*data_str == ' ' || *data_str == '\t')
data_str++;
- if (*data_str == 0) { /* Hummm */
+ if (*data_str == '\0') { /* Hummm */
data_str--;
cerror("'##' operator at end of macro");
}
@@ -1417,7 +1432,7 @@ int arg_count;
rv[cc++] = *data_str++;
continue;
}
- *p = 0; s = curword;
+ *p = '\0'; s = curword;
for (ac=0; ac<arg_count; ac++) {
if (*curword == arg_list[ac].name[0] &&
strcmp(curword, arg_list[ac].name) == 0)
@@ -1445,7 +1460,7 @@ int arg_count;
while(cc>0 && (rv[cc-1] == ' ' || rv[cc-1] == '\t'))
cc--;
rv[cc++] = '"';
- rv[cc++] = 0;
+ rv[cc++] = '\0';
ansi_stringize = 0;
s = "";
break;
@@ -1465,6 +1480,6 @@ int arg_count;
cc = strlen(rv);
}
- rv[cc] = 0;
+ rv[cc] = '\0';
return rv;
}
diff --git a/cpp/hash.c b/cpp/hash.c
index 3d340e8..11c32da 100644
--- a/cpp/hash.c
+++ b/cpp/hash.c
@@ -23,7 +23,7 @@ struct hashentry
struct hashentry ** hashtable;
int hashsize = 0xFF; /* 2^X -1 */
int hashcount = 0;
-static int hashvalue();
+static int hashvalue _P((int namespace, char * word));
void *
read_entry(namespace, word)
diff --git a/cpp/main.c b/cpp/main.c
index b2935dd..0cbdaa3 100644
--- a/cpp/main.c
+++ b/cpp/main.c
@@ -21,6 +21,8 @@ void define_macro _P((char *));
void undefine_macro _P((char *));
void cmsg _P((char * mtype, char * str));
char * token_txn _P((int));
+void pr_indent _P((int));
+void hash_line _P((void));
char * include_paths[MAXINCPATH];
@@ -28,6 +30,7 @@ char last_name[512] = "";
int last_line = -1;
int debug_mode = 0;
int p_flag = 0;
+int exit_code = 0;
char * outfile = 0;
FILE * ofd = 0;
@@ -146,7 +149,7 @@ static char Usage[] = "Usage: cpp -E -0 -Dxxx -Uxxx -Ixxx infile -o outfile";
print_toks_cpp();
if (outfile) fclose(ofd);
- exit(0);
+ exit(exit_code);
}
void
@@ -192,24 +195,34 @@ char * fname;
char * mode;
int checkrel;
{
- FILE * fd;
+ FILE * fd = 0;
int i;
- char buf[256];
+ char buf[256], *p;
if( checkrel )
{
- fd=fopen(fname, mode);
- if( fd ) return fd;
+ strcpy(buf, c_fname);
+ p = strrchr(buf, '/');
+ if (p) *++p = 0; else *(p=buf) = 0;
+ strcpy(p, fname);
+
+ fd=fopen(buf, mode);
+ }
+ if (!fd) {
+ for(i=0; i<MAXINCPATH; i++)
+ if (include_paths[i]) {
+ strcpy(buf, include_paths[i]);
+ if (buf[strlen(buf)-1] != '/') strcat(buf, "/");
+ strcat(buf, fname);
+ fd=fopen(buf, mode);
+ if( fd ) break;
+ }
}
- for(i=0; i<MAXINCPATH; i++)
- if (include_paths[i]) {
- strcpy(buf, include_paths[i]);
- if (buf[strlen(buf)-1] != '/') strcat(buf, "/");
- strcat(buf, fname);
- fd=fopen(buf, mode);
- if( fd ) return fd;
- }
- return 0;
+ if (!fd) return fd;
+ c_fname = strdup(buf);
+ c_lineno = 1;
+
+ return fd;
}
/*----------------------------------------------------------------------*/
@@ -242,6 +255,7 @@ void
cerror(str)
char * str;
{
+ exit_code = 1;
cmsg("error", str);
}
diff --git a/cpp/token1.c b/cpp/token1.c
index e53f563..4b966f7 100644
--- a/cpp/token1.c
+++ b/cpp/token1.c
@@ -3,4 +3,9 @@
#include <string.h>
#include "cc.h"
+#ifdef __GNUC__
+__inline
+#endif
+static unsigned int hash1 _P((register const char *, register unsigned int));
+
#include "token1.h"
diff --git a/cpp/token1.h b/cpp/token1.h
new file mode 100644
index 0000000..2e2b9eb
--- /dev/null
+++ b/cpp/token1.h
@@ -0,0 +1,117 @@
+/* C code produced by gperf version 2.7.1 (19981006 egcs) */
+/* Command-line: gperf -aptTc -N is_ctok -H hash1 token1.tok */
+
+#define TOTAL_KEYWORDS 23
+#define MIN_WORD_LENGTH 2
+#define MAX_WORD_LENGTH 3
+#define MIN_HASH_VALUE 2
+#define MAX_HASH_VALUE 63
+/* maximum key range = 62, duplicates = 0 */
+
+#ifdef __GNUC__
+__inline
+#endif
+static unsigned int
+hash1 (str, len)
+ register const char *str;
+ register unsigned int len;
+{
+ static unsigned char asso_values[] =
+ {
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 1, 64, 64, 64, 3, 25, 64,
+ 64, 64, 13, 18, 64, 8, 30, 15, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 5, 0, 20, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 30, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 23, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64
+ };
+ return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]];
+}
+
+#ifdef __GNUC__
+__inline
+#endif
+struct token_trans *
+is_ctok (str, len)
+ register const char *str;
+ register unsigned int len;
+{
+ static struct token_trans wordlist[] =
+ {
+ {""}, {""},
+ {"==", TK_EQ_OP},
+ {"!=", TK_NE_OP},
+ {""},
+ {"%=", TK_MOD_ASSIGN},
+ {""},
+ {"<=", TK_LE_OP},
+ {"<<=", TK_LEFT_ASSIGN},
+ {""},
+ {"-=", TK_SUB_ASSIGN},
+ {""},
+ {"<<", TK_LEFT_OP},
+ {""}, {""},
+ {"*=", TK_MUL_ASSIGN},
+ {""},
+ {"/=", TK_DIV_ASSIGN},
+ {"--", TK_DEC_OP},
+ {""},
+ {"+=", TK_ADD_ASSIGN},
+ {""},
+ {">=", TK_GE_OP},
+ {">>=", TK_RIGHT_ASSIGN},
+ {""},
+ {"|=", TK_OR_ASSIGN},
+ {""},
+ {"&=", TK_AND_ASSIGN},
+ {""}, {""},
+ {"->", TK_PTR_OP},
+ {""},
+ {"^=", TK_XOR_ASSIGN},
+ {""}, {""}, {""}, {""}, {""},
+ {"++", TK_INC_OP},
+ {""}, {""}, {""},
+ {">>", TK_RIGHT_OP},
+ {""}, {""}, {""}, {""}, {""},
+ {"||", TK_OR_OP},
+ {""}, {""}, {""},
+ {"&&", TK_AND_OP},
+ {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
+ {"..", TK_WORD},
+ {"...", TK_ELLIPSIS}
+ };
+
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+ {
+ register int key = hash1 (str, len);
+
+ if (key <= MAX_HASH_VALUE && key >= 0)
+ {
+ register const char *s = wordlist[key].name;
+
+ if (*str == *s && !strncmp (str + 1, s + 1, len - 1))
+ return &wordlist[key];
+ }
+ }
+ return 0;
+}
diff --git a/cpp/token2.c b/cpp/token2.c
index e113fdd..c535746 100644
--- a/cpp/token2.c
+++ b/cpp/token2.c
@@ -3,4 +3,9 @@
#include <string.h>
#include "cc.h"
+#ifdef __GNUC__
+__inline
+#endif
+static unsigned int hash2 _P((register const char *, register unsigned int));
+
#include "token2.h"
diff --git a/cpp/token2.h b/cpp/token2.h
new file mode 100644
index 0000000..62e69b1
--- /dev/null
+++ b/cpp/token2.h
@@ -0,0 +1,139 @@
+/* C code produced by gperf version 2.7.1 (19981006 egcs) */
+/* Command-line: gperf -aptTc -k1,3 -N is_ckey -H hash2 token2.tok */
+
+#define TOTAL_KEYWORDS 34
+#define MIN_WORD_LENGTH 2
+#define MAX_WORD_LENGTH 8
+#define MIN_HASH_VALUE 2
+#define MAX_HASH_VALUE 69
+/* maximum key range = 68, duplicates = 0 */
+
+#ifdef __GNUC__
+__inline
+#endif
+static unsigned int
+hash2 (str, len)
+ register const char *str;
+ register unsigned int len;
+{
+ static unsigned char asso_values[] =
+ {
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 5, 70, 70, 70, 70, 70, 0, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 0, 70, 5, 5, 10,
+ 10, 20, 20, 25, 70, 0, 70, 70, 50, 70,
+ 0, 15, 0, 70, 15, 0, 40, 20, 0, 0,
+ 70, 70, 10, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70
+ };
+ register int hval = len;
+
+ switch (hval)
+ {
+ default:
+ case 3:
+ hval += asso_values[(unsigned char)str[2]];
+ case 2:
+ case 1:
+ hval += asso_values[(unsigned char)str[0]];
+ break;
+ }
+ return hval;
+}
+
+#ifdef __GNUC__
+__inline
+#endif
+struct token_trans *
+is_ckey (str, len)
+ register const char *str;
+ register unsigned int len;
+{
+ static struct token_trans wordlist[] =
+ {
+ {""}, {""},
+ {"if", TK_IF},
+ {""},
+ {"void", TK_VOID},
+ {"while", TK_WHILE},
+ {"switch", TK_SWITCH},
+ {""},
+ {"__LINE__", TK_LINE},
+ {""}, {""},
+ {"static", TK_STATIC},
+ {"do", TK_DO},
+ {"__FILE__", TK_FILE},
+ {"case", TK_CASE},
+ {"const", TK_CONST},
+ {"sizeof", TK_SIZEOF},
+ {""},
+ {"continue", TK_CONTINUE},
+ {"char", TK_CHAR},
+ {"short", TK_SHORT},
+ {"struct", TK_STRUCT},
+ {""}, {""},
+ {"else", TK_ELSE},
+ {"union", TK_UNION},
+ {""}, {""},
+ {"unsigned", TK_UNSIGNED},
+ {""},
+ {"break", TK_BREAK},
+ {"signed", TK_SIGNED},
+ {""}, {""}, {""}, {""},
+ {"double", TK_DOUBLE},
+ {"default", TK_DEFAULT},
+ {"for", TK_FOR},
+ {""},
+ {"float", TK_FLOAT},
+ {""}, {""},
+ {"int", TK_INT},
+ {"enum", TK_ENUM},
+ {""}, {""},
+ {"typedef", TK_TYPEDEF},
+ {"register", TK_REGISTER},
+ {"auto", TK_AUTO},
+ {""}, {""}, {""}, {""},
+ {"long", TK_LONG},
+ {""}, {""}, {""},
+ {"volatile", TK_VOLATILE},
+ {""}, {""},
+ {"return", TK_RETURN},
+ {""}, {""}, {""}, {""},
+ {"extern", TK_EXTERN},
+ {""}, {""},
+ {"goto", TK_GOTO}
+ };
+
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+ {
+ register int key = hash2 (str, len);
+
+ if (key <= MAX_HASH_VALUE && key >= 0)
+ {
+ register const char *s = wordlist[key].name;
+
+ if (*str == *s && !strncmp (str + 1, s + 1, len - 1))
+ return &wordlist[key];
+ }
+ }
+ return 0;
+}