summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>2002-08-02 21:34:40 +0200
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:48:47 +0200
commit660429af0232d4afcb3e03fb0437053dd6e16286 (patch)
treeab173f1b824dda797d7633c4c57cde91941c908c
parente6248da18100235ae33468d058e5b71fcefeff3b (diff)
downloaddev86-660429af0232d4afcb3e03fb0437053dd6e16286.tar.gz
Import Dev86src-0.16.7.tar.gzv0.16.7
-rw-r--r--Makefile2
-rw-r--r--bcc/bcc.c16
-rw-r--r--bcc/declare.c9
-rw-r--r--bcc/output.c2
-rw-r--r--bcc/patch.file157
-rw-r--r--bcc/q112
-rw-r--r--cpp/c.c78
-rw-r--r--cpp/cc.h142
-rwxr-xr-xcpp/cgbin27808 -> 0 bytes
-rw-r--r--cpp/cpp.c609
-rw-r--r--cpp/log77
-rw-r--r--cpp/main.c217
-rw-r--r--cpp/q.c25
-rw-r--r--cpp/token1.tok1
-rw-r--r--cpp/torture.c18
-rw-r--r--ld/writex86.c6
-rw-r--r--libc/i386fp/Makefile9
-rw-r--r--libc/include/features.h4
-rw-r--r--libc/include/sys/cdefs.h2
19 files changed, 702 insertions, 784 deletions
diff --git a/Makefile b/Makefile
index 095b6c8..92fb9ae 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
# This file is part of the Linux-8086 Development environment and is
# distributed under the GNU General Public License.
-VERSION=0.16.6
+VERSION=0.16.7
TARGETS= \
clean bcc unproto copt as86 ld86 elksemu \
diff --git a/bcc/bcc.c b/bcc/bcc.c
index f7e7eb6..289767e 100644
--- a/bcc/bcc.c
+++ b/bcc/bcc.c
@@ -220,6 +220,7 @@ char ** argv;
fprintf(stderr, "%s:\n", next_file->file);
/* Assembler that's not to be optimised. */
+ if (do_preproc && next_file->filetype == 'x') run_aspreproc(next_file);
if (do_preproc && next_file->filetype == 'S') run_aspreproc(next_file);
if (do_as && next_file->filetype == 's') run_as(next_file);
@@ -727,8 +728,7 @@ char ** argv;
case 'a':
if(strcmp(argv[ar], "-ansi") == 0) {
do_unproto = 1;
- opt_e = 1;
-#if 1
+#if 0
/* NOTE I'm setting this to zero, this isn't a _real_ Ansi cpp. */
prepend_option("-D__STDC__=0", 'p');
#else
@@ -815,7 +815,6 @@ char ** argv;
case 'E':
control_count++;
do_compile = do_link = do_as = 0;
- opt_e = 1;
break;
case 'S':
control_count++;
@@ -874,6 +873,9 @@ char ** argv;
if (exe_count && file_count != 1 && !do_link)
fatal("only one input file for each non-linked output");
+ opt_e = !opt_e;
+ if (do_unproto || !do_compile) opt_e = 1;
+
add_prefix(getenv("BCC_EXEC_PREFIX"));
#ifdef MC6809
@@ -898,12 +900,18 @@ char ** argv;
prepend_option("-D__ELKS__", 'p');
append_option("-c", 'p');
append_option("-f", 'p');
+ if (opt_e) {
+ append_option("-c", 'c');
+ append_option("-f", 'c');
+ }
libc="-lc_f";
break;
case 'c': /* Caller saves Elks */
prepend_option("-D__unix__", 'p');
prepend_option("-D__ELKS__", 'p');
append_option("-c", 'p');
+ if (opt_e)
+ append_option("-c", 'c');
libc="-lc";
break;
case 's': /* Standalone 8086 */
@@ -947,7 +955,7 @@ char ** argv;
append_option("/lib/crt0.o", 'l');
break;
default:
- fatal("Unknown model specifier for -M");
+ fatal("Unknown model specifier for -M valid are: n,f,c,s,d,l,g,8,9,0");
}
if (do_optim)
diff --git a/bcc/declare.c b/bcc/declare.c
index f61887f..3dfb26b 100644
--- a/bcc/declare.c
+++ b/bcc/declare.c
@@ -461,6 +461,15 @@ PRIVATE bool_pt declspec()
&& (gsymptr->type == stype || gsymptr->type == ltype))
ntype = 0;
+ /* Allow long double and long float */
+ if (gvartype == ltype
+ && (gsymptr->type == fltype || gsymptr->type == dtype))
+ {
+ gvartype = dtype;
+ nextsym();
+ break;
+ }
+
/* allow int short and int long, blech */
if (gsymptr->type == itype
&& (gvartype == stype || gvartype == ltype))
diff --git a/bcc/output.c b/bcc/output.c
index e5db292..b82f968 100644
--- a/bcc/output.c
+++ b/bcc/output.c
@@ -40,7 +40,7 @@ FORWARD void outvaldigs P((uvalue_t num));
PUBLIC void bugerror(message)
char *message;
{
- error2error("compiler bug - ", message);
+ error2error("compiler bug? - ", message);
}
PUBLIC void closeout()
diff --git a/bcc/patch.file b/bcc/patch.file
deleted file mode 100644
index 20a3174..0000000
--- a/bcc/patch.file
+++ /dev/null
@@ -1,157 +0,0 @@
-diff -u5 -r bcc~/declare.c bcc/declare.c
---- bcc~/declare.c Fri Dec 17 17:51:13 1999
-+++ bcc/declare.c Thu Jun 6 13:27:00 2002
-@@ -410,16 +410,17 @@
- }
-
- PRIVATE bool_pt declspec()
- {
- unsigned nsc;
-+ unsigned nsigned;
- unsigned ntype;
- unsigned nunsigned;
-
- gvarsc = NULLDECL;
- gvartype = itype;
-- nunsigned = ntype = nsc = 0;
-+ nsigned = nunsigned = ntype = nsc = 0;
- while (TRUE)
- {
- switch (sym)
- {
- case AUTODECL:
-@@ -482,29 +483,37 @@
- goto break2;
- ++ntype;
- gvartype = gsymptr->type;
- nextsym();
- break;
-+ case SIGNDECL:
-+ ++nsigned;
-+ nextsym();
-+ break;
- case UNSIGNDECL:
- ++nunsigned;
- nextsym();
- break;
- default:
- goto break2;
- }
- }
-+
- break2:
-+ if (nsigned > 0)
-+ {
-+ if (ntype++ == 0)
-+ gvartype = itype;
-+ else
-+ gvartype = tosigned(gvartype);
-+ }
- if (nunsigned > 0)
- {
-- if (ntype == 0)
-- {
-+ if (ntype++ == 0)
- gvartype = uitype;
-- ntype = 1;
-- }
-- gvartype = tounsigned(gvartype);
-- if (nunsigned > 1)
-- ntype = 2;
-+ else
-+ gvartype = tounsigned(gvartype);
- }
- if (nsc > 0)
- {
- if (ntype == 0)
- ntype = 1;
-diff -u5 -r bcc~/proto.h bcc/proto.h
---- bcc~/proto.h Sun Jan 11 12:18:36 1998
-+++ bcc/proto.h Thu Jun 6 00:46:24 2002
-@@ -360,8 +360,8 @@
- void outntypechar P((struct typestruct *type));
- struct typestruct *pointype P((struct typestruct *type));
- struct typestruct *prefix P((constr_pt constructor, uoffset_T size,
- struct typestruct *type));
- struct typestruct *promote P((struct typestruct *type));
-+struct typestruct *tosigned P((struct typestruct *type));
- struct typestruct *tounsigned P((struct typestruct *type));
- void typeinit P((void));
--
-diff -u5 -r bcc~/scan.h bcc/scan.h
---- bcc~/scan.h Sat Jul 24 14:27:42 1999
-+++ bcc/scan.h Thu Jun 6 00:32:20 2002
-@@ -134,10 +134,11 @@
-
- #define LASTOP PTRSUBOP
-
- ENUMDECL,
- NULLDECL,
-+ SIGNDECL,
- STRUCTDECL,
- TYPEDECL,
- TYPEDEFNAME,
- UNIONDECL,
- UNSIGNDECL,
-diff -u5 -r bcc~/table.c bcc/table.c
---- bcc~/table.c Sun Sep 28 09:57:30 1997
-+++ bcc/table.c Thu Jun 6 00:29:36 2002
-@@ -28,11 +28,11 @@
- #define MAXEXPR 125
- #else
- #define MAXEXPR 500
- #endif
- #define MAXLOCAL 100
--#define NKEYWORDS 35
-+#define NKEYWORDS 36
- #ifdef NOFLOAT
- #define NSCALTYPES 10
- #else
- #define NSCALTYPES 12
- #endif
-@@ -88,11 +88,12 @@
- PRIVATE struct keywordstruct keywords[NKEYWORDS] =
- {
- { "enum", ENUMDECL, },
- { "struct", STRUCTDECL, },
- { "union", UNIONDECL, },
- { "unsigned", UNSIGNDECL, },
-+ { "signed", SIGNDECL, },
-
- { "auto", AUTODECL, },
- { "extern", EXTERNDECL, },
- { "register", REGDECL, },
- { "static", STATICDECL, },
-diff -u5 -r bcc~/type.c bcc/type.c
---- bcc~/type.c Sun Jan 11 12:18:37 1998
-+++ bcc/type.c Thu Jun 6 00:49:06 2002
-@@ -155,10 +155,29 @@
- if (type->constructor & FUNCTION)
- return pointype(type);
- return type;
- }
-
-+PUBLIC struct typestruct *tosigned(type)
-+struct typestruct *type;
-+{
-+ switch (type->scalar & ~(UNSIGNED | DLONG))
-+ {
-+ case CHAR:
-+ return sctype;
-+ case SHORT:
-+ return stype;
-+ case INT:
-+ return itype;
-+ case LONG:
-+ return ltype;
-+ default:
-+ error("signed only applies to integral types");
-+ return type;
-+ }
-+}
-+
- PUBLIC struct typestruct *tounsigned(type)
- struct typestruct *type;
- {
- switch (type->scalar & ~(UNSIGNED | DLONG))
- {
diff --git a/bcc/q b/bcc/q
deleted file mode 100644
index e124394..0000000
--- a/bcc/q
+++ /dev/null
@@ -1,112 +0,0 @@
-diff -u5 -r bcc~/declare.c bcc/declare.c
---- bcc~/declare.c Fri Dec 17 17:51:13 1999
-+++ bcc/declare.c Thu Jun 6 13:27:00 2002
-@@ -410,16 +410,17 @@
- }
-
- PRIVATE bool_pt declspec()
- {
- unsigned nsc;
-+ unsigned nsigned;
- unsigned ntype;
- unsigned nunsigned;
-
- gvarsc = NULLDECL;
- gvartype = itype;
-- nunsigned = ntype = nsc = 0;
-+ nsigned = nunsigned = ntype = nsc = 0;
- while (TRUE)
- {
- switch (sym)
- {
- case AUTODECL:
-diff -u5 -r bcc~/proto.h bcc/proto.h
---- bcc~/proto.h Sun Jan 11 12:18:36 1998
-+++ bcc/proto.h Thu Jun 6 00:46:24 2002
-@@ -360,8 +360,8 @@
- void outntypechar P((struct typestruct *type));
- struct typestruct *pointype P((struct typestruct *type));
- struct typestruct *prefix P((constr_pt constructor, uoffset_T size,
- struct typestruct *type));
- struct typestruct *promote P((struct typestruct *type));
-+struct typestruct *tosigned P((struct typestruct *type));
- struct typestruct *tounsigned P((struct typestruct *type));
- void typeinit P((void));
--
-diff -u5 -r bcc~/scan.h bcc/scan.h
---- bcc~/scan.h Sat Jul 24 14:27:42 1999
-+++ bcc/scan.h Thu Jun 6 00:32:20 2002
-@@ -134,10 +134,11 @@
-
- #define LASTOP PTRSUBOP
-
- ENUMDECL,
- NULLDECL,
-+ SIGNDECL,
- STRUCTDECL,
- TYPEDECL,
- TYPEDEFNAME,
- UNIONDECL,
- UNSIGNDECL,
-diff -u5 -r bcc~/table.c bcc/table.c
---- bcc~/table.c Sun Sep 28 09:57:30 1997
-+++ bcc/table.c Thu Jun 6 00:29:36 2002
-@@ -28,11 +28,11 @@
- #define MAXEXPR 125
- #else
- #define MAXEXPR 500
- #endif
- #define MAXLOCAL 100
--#define NKEYWORDS 35
-+#define NKEYWORDS 36
- #ifdef NOFLOAT
- #define NSCALTYPES 10
- #else
- #define NSCALTYPES 12
- #endif
-@@ -88,11 +88,12 @@
- PRIVATE struct keywordstruct keywords[NKEYWORDS] =
- {
- { "enum", ENUMDECL, },
- { "struct", STRUCTDECL, },
- { "union", UNIONDECL, },
- { "unsigned", UNSIGNDECL, },
-+ { "signed", SIGNDECL, },
-
- { "auto", AUTODECL, },
- { "extern", EXTERNDECL, },
- { "register", REGDECL, },
- { "static", STATICDECL, },
-diff -u5 -r bcc~/type.c bcc/type.c
---- bcc~/type.c Sun Jan 11 12:18:37 1998
-+++ bcc/type.c Thu Jun 6 00:49:06 2002
-@@ -155,10 +155,29 @@
- if (type->constructor & FUNCTION)
- return pointype(type);
- return type;
- }
-
-+PUBLIC struct typestruct *tosigned(type)
-+struct typestruct *type;
-+{
-+ switch (type->scalar & ~(UNSIGNED | DLONG))
-+ {
-+ case CHAR:
-+ return sctype;
-+ case SHORT:
-+ return stype;
-+ case INT:
-+ return itype;
-+ case LONG:
-+ return ltype;
-+ default:
-+ error("signed only applies to integral types");
-+ return type;
-+ }
-+}
-+
- PUBLIC struct typestruct *tounsigned(type)
- struct typestruct *type;
- {
- switch (type->scalar & ~(UNSIGNED | DLONG))
- {
diff --git a/cpp/c.c b/cpp/c.c
new file mode 100644
index 0000000..5e1ef4e
--- /dev/null
+++ b/cpp/c.c
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <errno.h>
+
+#if __STDC__
+#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
+#warning Using Ansi combine
+#elif __BCC__
+#define comb(x,y) x/**/y
+#warning Using bcc combine
+#else
+#define comb(x,y) x/**/y
+#warning Using K&R combine
+#endif
+
+#define signed unsigned
+#define unsigned signed
+
+#ifdef signed
+typedef signed char t_sc;
+typedef comb(un,signed) char t_uc;
+#endif
+
+char c;
+t_sc sc;
+t_uc uc;
+
+strong_alias(main,zulu);
+main()
+{
+ int i1, i2, i3;
+
+ printf("sizeof(long double) = %d\n", sizeof(long double));
+ printf("sizeof(long float) = %d\n", sizeof(long float));
+ printf("sizeof(double) = %d\n", sizeof(double));
+ printf("sizeof(float) = %d\n", sizeof(float));
+
+ c = -6;
+ uc = -6;
+ sc = -6;
+
+ printf("%ld, ", (long)c);
+ printf("%ld, ", (long)uc);
+ printf("%ld\n", (long)sc);
+
+ printf("%d, ", c);
+ printf("%d, ", uc);
+ printf("%d\n", sc);
+
+ i1 = c; i2 = uc; i3 = sc;
+
+ printf("%d, ", i1);
+ printf("%d, ", i2);
+ printf("%d\n", i3);
+
+ i1 = (char) 200 + (char) 50;
+ i2 = (t_uc) 200 + (t_uc) 50;
+ i3 = (t_sc) 200 + (t_sc) 50;
+
+ printf("%d, ", i1);
+ printf("%d, ", i2);
+ printf("%d\n", i3);
+
+ c = 200; uc = 200; sc = 200;
+
+ i1 = c + (long) 50;
+ i2 = uc + (long) 50;
+ i3 = sc + (long) 50;
+
+ printf("%d, ", i1);
+ printf("%d, ", i2);
+ printf("%d\n", i3);
+}
diff --git a/cpp/cc.h b/cpp/cc.h
index 57dab6c..5781f05 100644
--- a/cpp/cc.h
+++ b/cpp/cc.h
@@ -16,8 +16,11 @@ extern FILE * curfile;
extern char curword[];
extern char * c_fname;
extern int c_lineno;
-extern int in_asm;
-extern int ansi_c;
+extern int alltok;
+extern int dialect;
+
+#define DI_KNR 1
+#define DI_ANSI 2
extern int gettok _P((void));
@@ -25,77 +28,78 @@ struct token_trans { char * name; int token; };
struct token_trans * is_ctok _P((const char *str, unsigned int len));
struct token_trans * is_ckey _P((const char *str, unsigned int len));
-#define WORDSIZE 128
-#define TK_WORD 256
-#define TK_NUM 257
-#define TK_FLT 258
-#define TK_QUOT 259
-#define TK_STR 260
-#define TK_FILE 261
-#define TK_LINE 262
-#define TK_COPY 263
+#define WORDSIZE 128
+#define TK_WSPACE 256
+#define TK_WORD 257
+#define TK_NUM 258
+#define TK_FLT 259
+#define TK_QUOT 260
+#define TK_STR 261
+#define TK_FILE 262
+#define TK_LINE 263
+#define TK_COPY 264
-#define TK_CTOK 0x200
-#define TK_CKEY 0x300
+#define TKS_CTOK 0x200
+#define TKS_CKEY 0x300
-#define TK_NE_OP (TK_CTOK+ 0)
-#define TK_MOD_ASSIGN (TK_CTOK+ 1)
-#define TK_AND_OP (TK_CTOK+ 2)
-#define TK_AND_ASSIGN (TK_CTOK+ 3)
-#define TK_MUL_ASSIGN (TK_CTOK+ 4)
-#define TK_INC_OP (TK_CTOK+ 5)
-#define TK_ADD_ASSIGN (TK_CTOK+ 6)
-#define TK_DEC_OP (TK_CTOK+ 7)
-#define TK_SUB_ASSIGN (TK_CTOK+ 8)
-#define TK_PTR_OP (TK_CTOK+ 9)
-#define TK_ELLIPSIS (TK_CTOK+10)
-#define TK_DIV_ASSIGN (TK_CTOK+11)
-#define TK_LEFT_OP (TK_CTOK+12)
-#define TK_LEFT_ASSIGN (TK_CTOK+13)
-#define TK_LE_OP (TK_CTOK+14)
-#define TK_EQ_OP (TK_CTOK+15)
-#define TK_GE_OP (TK_CTOK+16)
-#define TK_RIGHT_OP (TK_CTOK+17)
-#define TK_RIGHT_ASSIGN (TK_CTOK+18)
-#define TK_XOR_ASSIGN (TK_CTOK+19)
-#define TK_OR_ASSIGN (TK_CTOK+20)
-#define TK_OR_OP (TK_CTOK+21)
+#define TK_NE_OP (TKS_CTOK+ 0)
+#define TK_MOD_ASSIGN (TKS_CTOK+ 1)
+#define TK_AND_OP (TKS_CTOK+ 2)
+#define TK_AND_ASSIGN (TKS_CTOK+ 3)
+#define TK_MUL_ASSIGN (TKS_CTOK+ 4)
+#define TK_INC_OP (TKS_CTOK+ 5)
+#define TK_ADD_ASSIGN (TKS_CTOK+ 6)
+#define TK_DEC_OP (TKS_CTOK+ 7)
+#define TK_SUB_ASSIGN (TKS_CTOK+ 8)
+#define TK_PTR_OP (TKS_CTOK+ 9)
+#define TK_ELLIPSIS (TKS_CTOK+10)
+#define TK_DIV_ASSIGN (TKS_CTOK+11)
+#define TK_LEFT_OP (TKS_CTOK+12)
+#define TK_LEFT_ASSIGN (TKS_CTOK+13)
+#define TK_LE_OP (TKS_CTOK+14)
+#define TK_EQ_OP (TKS_CTOK+15)
+#define TK_GE_OP (TKS_CTOK+16)
+#define TK_RIGHT_OP (TKS_CTOK+17)
+#define TK_RIGHT_ASSIGN (TKS_CTOK+18)
+#define TK_XOR_ASSIGN (TKS_CTOK+19)
+#define TK_OR_ASSIGN (TKS_CTOK+20)
+#define TK_OR_OP (TKS_CTOK+21)
-#define TK_AUTO (TK_CKEY+ 0)
-#define TK_BREAK (TK_CKEY+ 1)
-#define TK_CASE (TK_CKEY+ 2)
-#define TK_CHAR (TK_CKEY+ 3)
-#define TK_CONST (TK_CKEY+ 4)
-#define TK_CONTINUE (TK_CKEY+ 5)
-#define TK_DEFAULT (TK_CKEY+ 6)
-#define TK_DO (TK_CKEY+ 7)
-#define TK_DOUBLE (TK_CKEY+ 8)
-#define TK_ELSE (TK_CKEY+ 9)
-#define TK_ENUM (TK_CKEY+10)
-#define TK_EXTERN (TK_CKEY+11)
-#define TK_FLOAT (TK_CKEY+12)
-#define TK_FOR (TK_CKEY+13)
-#define TK_GOTO (TK_CKEY+14)
-#define TK_IF (TK_CKEY+15)
-#define TK_INT (TK_CKEY+16)
-#define TK_LONG (TK_CKEY+17)
-#define TK_REGISTER (TK_CKEY+18)
-#define TK_RETURN (TK_CKEY+19)
-#define TK_SHORT (TK_CKEY+20)
-#define TK_SIGNED (TK_CKEY+21)
-#define TK_SIZEOF (TK_CKEY+22)
-#define TK_STATIC (TK_CKEY+23)
-#define TK_STRUCT (TK_CKEY+24)
-#define TK_SWITCH (TK_CKEY+25)
-#define TK_TYPEDEF (TK_CKEY+26)
-#define TK_UNION (TK_CKEY+27)
-#define TK_UNSIGNED (TK_CKEY+28)
-#define TK_VOID (TK_CKEY+29)
-#define TK_VOLATILE (TK_CKEY+30)
-#define TK_WHILE (TK_CKEY+31)
+#define TK_AUTO (TKS_CKEY+ 0)
+#define TK_BREAK (TKS_CKEY+ 1)
+#define TK_CASE (TKS_CKEY+ 2)
+#define TK_CHAR (TKS_CKEY+ 3)
+#define TK_CONST (TKS_CKEY+ 4)
+#define TK_CONTINUE (TKS_CKEY+ 5)
+#define TK_DEFAULT (TKS_CKEY+ 6)
+#define TK_DO (TKS_CKEY+ 7)
+#define TK_DOUBLE (TKS_CKEY+ 8)
+#define TK_ELSE (TKS_CKEY+ 9)
+#define TK_ENUM (TKS_CKEY+10)
+#define TK_EXTERN (TKS_CKEY+11)
+#define TK_FLOAT (TKS_CKEY+12)
+#define TK_FOR (TKS_CKEY+13)
+#define TK_GOTO (TKS_CKEY+14)
+#define TK_IF (TKS_CKEY+15)
+#define TK_INT (TKS_CKEY+16)
+#define TK_LONG (TKS_CKEY+17)
+#define TK_REGISTER (TKS_CKEY+18)
+#define TK_RETURN (TKS_CKEY+19)
+#define TK_SHORT (TKS_CKEY+20)
+#define TK_SIGNED (TKS_CKEY+21)
+#define TK_SIZEOF (TKS_CKEY+22)
+#define TK_STATIC (TKS_CKEY+23)
+#define TK_STRUCT (TKS_CKEY+24)
+#define TK_SWITCH (TKS_CKEY+25)
+#define TK_TYPEDEF (TKS_CKEY+26)
+#define TK_UNION (TKS_CKEY+27)
+#define TK_UNSIGNED (TKS_CKEY+28)
+#define TK_VOID (TKS_CKEY+29)
+#define TK_VOLATILE (TKS_CKEY+30)
+#define TK_WHILE (TKS_CKEY+31)
-#define MAX_INCLUDE 16 /* Nested includes */
-#define MAX_DEFINE 32 /* Nested defines */
+#define MAX_INCLUDE 64 /* Nested includes */
+#define MAX_DEFINE 64 /* Nested defines */
extern char * set_entry _P((int,char*,void*));
extern void * read_entry _P((int,char*));
diff --git a/cpp/cg b/cpp/cg
deleted file mode 100755
index 9fbf146..0000000
--- a/cpp/cg
+++ /dev/null
Binary files differ
diff --git a/cpp/cpp.c b/cpp/cpp.c
index 542a709..57cbda0 100644
--- a/cpp/cpp.c
+++ b/cpp/cpp.c
@@ -7,7 +7,7 @@
#endif
#include "cc.h"
-#define CPP_DEBUG 0 /* LOTS of junk to stdout. */
+#define CPP_DEBUG 0 /* LOTS of junk to stderr. */
/*
* This file comprises the 'guts' of a C preprocessor.
@@ -22,14 +22,23 @@
* c_fname Name of file being parsed
* c_lineno Current line number in file being parsed.
*
- * in_asm Control flag for the kind of tokens you want (C or assembler)
- * ansi_c Control flag to change the preprocessor for Ansi C.
+ * alltok Control flag for the kind of tokens you want (C or generic)
+ * dislect Control flag to change the preprocessor for Ansi C.
*
+ * TODO:
+ * #asm -> asm("...") translation.
+ * ?: in #if expressions
*/
+#define KEEP_SPACE 0
+#define SKIP_SPACE 1
+
+#define EOT 4
+#define SYN 22
+
char curword[WORDSIZE];
-int in_asm = 0;
-int ansi_c = 0;
+int alltok = 0;
+int dialect = 0;
FILE * curfile;
char * c_fname;
@@ -73,9 +82,10 @@ struct arg_store {
};
static int chget _P((void));
+static int chget_raw _P((void));
static void unchget _P((int));
static int gettok_nosub _P((void));
-static int get_onetok _P((void));
+static int get_onetok _P((int));
static int pgetc _P((void));
static int do_preproc _P((void));
static int do_proc_copy_hashline _P((void));
@@ -89,7 +99,7 @@ static void do_proc_tail _P((void));
static int get_if_expression _P((void));
static int_type get_expression _P((int));
static int_type get_exp_value _P((void));
-static int gen_substrings _P((char *, char *, int));
+static void gen_substrings _P((char *, char *, int));
static char * insert_substrings _P((char *, struct arg_store *, int));
int
@@ -99,58 +109,25 @@ gettok()
for(;;)
{
- /* Normal C Preprocessor decoding */
- if (in_asm) {
- *curword = 0;
- if (quoted_str) ch = chget();
- else ch = pgetc();
- if (ch > 0xFF || ch == EOF) return ch;
-
- if(!quoted_str &&
- ( (ch >= 'A' && ch <= 'Z')
- || (ch >= 'a' && ch <= 'z')
- || ch == '_' || ch == '$' ) ) {
- unchget(ch);
- }
- else
- {
- curword[0] = ch;
- curword[1] = 0;
- if (quoted_str==2)
- quoted_str=1;
- else {
- if (ch == '"') {
- quoted_str = !quoted_str;
- return '"';
- }
- if (quoted_str == 1 && ch == '\\')
- quoted_str = 2;
- else if (quoted_str && ch == '\n') {
- quoted_str = 0;
- unchget(ch);
- return '\n';
- }
- }
-
- if (ch == '\n') continue;
- return TK_STR;
- }
- }
-
/* Tokenised C-Preprocessing */
if (!quoted_str)
{
- ch = get_onetok();
+ if (alltok)
+ ch = get_onetok(KEEP_SPACE);
+ else
+ ch = get_onetok(SKIP_SPACE);
- /* Erase meaningless backslashes */
- if( ch == '\\' ) {
- int ch1 = chget();
- if (ch1 == '\n') continue;
- unchget(ch1);
+ if( ch == '"' || ch == '\'' )
+ quoted_str = ch;
+
+ if( ch == TK_WORD )
+ {
+ struct token_trans *p;
+ if( p=is_ckey(curword, strlen(curword)) )
+ return p->token;
}
- if( ch == '"' )
- quoted_str = 1;
+ if (ch == '\n') continue;
return ch;
}
@@ -162,43 +139,46 @@ gettok()
*curword = ch;
curword[1] = '\0';
- if( quoted_str == 2 ) {
- quoted_str = 1;
- return TK_STR;
- }
-
- if( ch == '"' )
- {
- /* Found a terminator '"' check for ansi continuation */
- while( (ch = pgetc()) <= ' ' && ch != EOF) ;
- if( ch == '"' ) continue;
- quoted_str = 0;
- unchget(ch);
+ if( ch == quoted_str ) {
+ if( ch == '"' )
+ {
+ if (dialect == DI_ANSI) {
+ /* Found a terminator '"' check for ansi continuation */
+ while( (ch = pgetc()) <= ' ' && ch != EOF) ;
+ if( ch == '"' ) continue;
+ unchget(ch);
+ *curword = '"';
+ curword[1] = '\0';
+ }
- *curword = '"';
- curword[1] = '\0';
- return '"';
+ quoted_str = 0;
+ return '"';
+ } else {
+ quoted_str = 0;
+ return ch;
+ }
}
if( ch == '\n' ) {
quoted_str = 0;
+ unchget(ch); /* Make sure error line is right */
+ return ch;
+ }
+ if( ch == '\\' ) {
unchget(ch);
+ ch = get_onetok(KEEP_SPACE);
return ch;
}
- if( ch != '\\' ) return TK_STR;
-
- /* Deal with backslash; NB this could interpret all the \X codes */
- ch = chget();
-
- if( ch != '\n' ) { quoted_str++; unchget(ch); return TK_STR; }
+ return TK_STR;
}
}
static int
gettok_nosub()
-{ int rv; dont_subst++; rv=get_onetok(); dont_subst--; return rv; }
+{ int rv; dont_subst++; rv=get_onetok(SKIP_SPACE); dont_subst--; return rv; }
static int
-get_onetok()
+get_onetok(keep)
+int keep;
{
char * p;
int state;
@@ -208,13 +188,23 @@ Try_again:
*(p=curword) = '\0';
state=cc=ch=0;
- while( (ch = pgetc()) != EOF)
+ /* First skip whitespace, if the arg says so then we need to keep it */
+ while( (ch = pgetc()) == ' ' || ch == '\t' )
{
- if( ch > ' ' ) break;
- if( in_preproc && ch == '\n') break;
- if( (!in_preproc) && in_asm && (ch == ' ' || ch == '\t') ) break;
+ if (keep == KEEP_SPACE) {
+ if( p < curword + WORDSIZE-1 ) {
+ *p++ = ch; /* Clip to WORDSIZE */
+ *p = '\0';
+ }
+ }
}
+
if( ch > 0xFF ) return ch;
+ if( p != curword ) { unchget(ch); return TK_WSPACE; }
+ if( ch == '\n') return ch;
+ if( ch == EOF ) return ch;
+ if( ch >= 0 && ch < ' ' ) goto Try_again;
+
for(;;)
{
switch(state)
@@ -275,9 +265,28 @@ Try_again:
}
if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */
*p = '\0'; cc++;
- ch = pgetc();
+ ch = chget();
+ if (ch == 1) ch = chget();
}
break_break:
+ /* Numbers */
+ if( state >= 2 )
+ {
+ if( state < 6 )
+ {
+ if( ch == 'l' || ch == 'L' )
+ {
+ if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */
+ *p = '\0'; cc++;
+ }
+ else unchget(ch);
+ return TK_NUM;
+ }
+ unchget(ch);
+ return TK_FLT;
+ }
+
+ /* Words */
if( state == 1 )
{
struct define_item * ptr;
@@ -288,20 +297,36 @@ break_break:
)
{
if ( def_count >= MAX_DEFINE ) {
- cerror("Preprocessor recursion overflow");
- goto oops_keep_going;
- } else
- /* Add in the arguments if they're there */
- if( ptr->arg_count >= 0 )
+ cwarn("Preprocessor recursion overflow");
+ return TK_WORD;
+ } else if( ptr->arg_count >= 0 )
{
+ /* An open bracket must follow the word */
+ int ch1 = 0;
+ while ((ch = chget()) == ' ' || ch == '\t' ) ch1 = ch;
+ if (ch != '(') {
+ unchget(ch);
+ if (ch1) unchget(ch1);
+ return TK_WORD;
+ }
+
/* We have arguments to process so lets do so. */
- if( !gen_substrings(ptr->name, ptr->value, ptr->arg_count) )
- goto oops_keep_going;
+ gen_substrings(ptr->name, ptr->value, ptr->arg_count);
+
+ /* Don't mark macros with arguments as in use, it's very
+ * difficult to say what the correct result would be so
+ * I'm letting the error happen. Also if I do block
+ * recursion then it'll also block 'pseudo' recursion
+ * where the arguments have a call to this macro.
+ *
def_ref = ptr;
ptr->in_use = 1;
+ */
}
else if (ptr->value[0])
{
+ /* Simple direct substitution; note the shortcut (above) for
+ * macros that are defined as null */
saved_ref[def_count] = def_ref;
saved_def[def_count] = def_ptr;
saved_start[def_count] = def_start;
@@ -315,75 +340,93 @@ break_break:
}
goto Try_again;
}
-oops_keep_going:
- if( !in_preproc )
- {
- struct token_trans *p;
- if( p=is_ckey(curword, cc) )
- return p->token;
- }
return TK_WORD;
}
- if( state >= 2 )
- {
- if( state < 6 )
- {
- if( ch == 'l' || ch == 'L' )
- {
- if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */
- *p = '\0'; cc++;
- }
- else unchget(ch);
- return TK_NUM;
- }
- unchget(ch);
- return TK_FLT;
- }
- /* More tokeniser for C like stuff */
- if(!in_asm || in_preproc)
+ /* Quoted char for preprocessor expressions */
+ if(in_preproc && ch == '\'' )
{
- /* Quoted char (NOT strings!) */
- if (ch == '\'' )
+ *p++ = ch; ch = chget();
+ for(;;)
{
- *p++ = ch; ch = chget();
- for(;;)
+ if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */
+ *p = '\0'; cc++;
+ if( ch == '\'' || ch == '\n' ) break;
+
+ if( ch == '\\' )
{
+ ch = chget();
if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */
*p = '\0'; cc++;
- if( ch == '\'' || ch == '\n' ) break;
+ }
+ ch = chget();
+ }
+ ch = TK_QUOT;
+ }
- if( ch == '\\' )
- {
- ch = chget();
- if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */
- *p = '\0'; cc++;
+ /* Collect and translate \xyx strings, (should probably translate these
+ * all to some standard form (eg \ooo plus \N )
+ *
+ * ___________________________________________________________________
+ * | new-line NL (LF) \n| audible alert BEL \a |
+ * | horizontal tab HT \t| question mark ? \? |
+ * | vertical tab VT \v| double quote " \" |
+ * | backspace BS \b| octal escape ooo \ooo|
+ * | carriage return CR \r| hexadecimal escape hh \xhh|
+ * | formfeed FF \f| backslash \ \\ |
+ * | single quote ' \'| |
+ * |_______________________________|_________________________________|
+ */
+
+ if( ch == '\\' )
+ {
+ int i;
+
+ *p++ = ch; ch = chget();
+ if (ch >= '0' && ch <= '7' ) {
+ for(i=0; i<3; i++) {
+ if (ch >= '0' && ch <= '7' ) {
+ *p++ = ch; ch = chget();
}
- ch = chget();
}
- ch = TK_QUOT;
- }
- /* Composite tokens */
- if( ch > ' ' && ch <= '~' )
- {
- struct token_trans *p;
- *curword = cc = ch;
+ unchget(ch);
+ } else if (ch == 'x' || ch == 'X') {
+ *p++ = ch; ch = chget();
+ for(i=0; i<2; i++) {
+ if ( (ch >= '0' && ch <= '9' ) ||
+ (ch >= 'A' && ch <= 'F' ) ||
+ (ch >= 'a' && ch <= 'f' ) ) {
+ *p++ = ch; ch = chget();
+ }
+ }
+ unchget(ch);
+ } else if (ch == '?') {
+ p[-1] = '?';
+ } else if (ch != '\n' && ch != EOF) {
+ *p++ = ch;
+ } else
+ unchget(ch);
+ *p = 0;
+ return TK_STR;
+ }
+
+ /* Possible composite tokens */
+ if( ch > ' ' && ch <= '~' )
+ {
+ struct token_trans *p;
+ *curword = cc = ch;
- for(state=1; ; state++)
+ for(state=1; ; state++)
+ {
+ curword[state] = ch = chget();
+ if( !(p=is_ctok(curword, state+1)) )
{
- curword[state] = ch = chget();
- if( !(p=is_ctok(curword, state+1)) )
- {
- unchget(ch);
- curword[state] = '\0';
- return cc;
- }
- cc=p->token;
+ unchget(ch);
+ curword[state] = '\0';
+ return cc;
}
+ cc=p->token;
}
- } else {
- *curword = ch;
- curword[1] = 0;
}
return ch;
}
@@ -395,47 +438,16 @@ pgetc()
for(;;)
{
- /* This loop is repeated if the current char is not suitable
- either because of a comment or a false #if condition
- */
-
- ch = chget();
-
- if( ch == EOF ) return ch;
- if( in_preproc && ch == '\\' )
- {
- ch1 = chget();
- if( ch1 == '\n' ) ch = chget();
- else unchget(ch1);
- }
-
- /* Ansi trigraphs -- Ewww, anyway this doesn't work, it needs lots
- * of 'unchget' space too. */
- if (ansi_c && ch == '?') {
- ch1 = chget();
- if (ch1 != '?')
- unchget(ch1);
- else {
- static char trig1[] = "()<>/!'-=";
- static char trig2[] = "[]{}\\|^~#";
- char * s;
- ch1 = chget();
- s = strchr(trig1, ch1);
- if (s) ch = trig2[s-trig1];
- else {
- unchget(ch1);
- unchget('?');
- }
- }
- }
+ if ((ch = chget()) == EOF) return ch;
if( !in_preproc && last_char == '\n' && ch == '#' )
{
in_preproc = 1;
ch = do_preproc();
in_preproc = 0;
+ if(if_false || ch == 0) continue;
+
last_char = '\n';
- if(if_false) continue;
return ch;
}
if( last_char != '\n' || (ch != ' ' && ch != '\t') )
@@ -444,21 +456,12 @@ pgetc()
/* Remove comments ... */
if( ch != '/' )
{ if(if_false && !in_preproc) continue; return ch; }
- ch1 = chget();
+ ch1 = chget(); /* Allow "/\\\n*" as comment start too!? */
if( ch1 == '/' ) /* Double slash style comments */
{
- do
- {
- ch = chget();
- if( ch == EOF ) return EOF;
- if( ch == '\\' ) {
- ch1 = chget();
- if( ch1 == EOF ) return EOF;
- }
- }
- while(ch != '\n');
- continue;
+ do { ch = chget(); } while(ch != '\n' && ch != EOF);
+ return ch; /* Keep the return. */
}
if( ch1 != '*' )
@@ -478,10 +481,48 @@ pgetc()
}
else ch = chget();
}
- if (ansi_c)
- return ' '; /* If comments become " " */
+ if (dialect == DI_ANSI)
+ return ' '; /* If comments become " " */
+ else return SYN; /* Comments become nulls, but we need a
+ * marker so I can do token concat properly. */
+ }
+}
+
+/* This function handles the first and second translation phases of Ansi-C */
+static int
+chget()
+{
+ int ch, ch1;
+ for(;;) {
+ ch = chget_raw();
+ if (ch == '\\') {
+ ch1 = chget_raw();
+ if (ch1 == '\n') continue;
+ unchget(ch1);
+ }
- /* Comments become nulls */
+ /* Ansi trigraphs -- Ewww, it needs lots of 'unchget' space too. */
+ if (dialect == DI_ANSI && ch == '?') {
+ ch1 = chget_raw();
+ if (ch1 != '?')
+ unchget(ch1);
+ else {
+ static char trig1[] = "()<>/!'-=";
+ static char trig2[] = "[]{}\\|^~#";
+ char * s;
+ ch1 = chget_raw();
+ s = strchr(trig1, ch1);
+ if (s) {
+ unchget(trig2[s-trig1]); /* Unchget so that ??/ can be used as */
+ continue; /* a real backslash at EOL. */
+ } else {
+ unchget(ch1);
+ unchget('?');
+ }
+ }
+ }
+
+ return ch;
}
}
@@ -491,7 +532,8 @@ unchget(ch)
#if CPP_DEBUG
fprintf(stderr, "\b", ch);
#endif
- if(ch == EOF) ch=26; /* EOF is pushed back as ^Z */
+ if(ch == 0) return; /* Hummm */
+ if(ch == EOF) ch=EOT; /* EOF is pushed back as ^Z */
ch &= 0xFF;
if(unputc&0xFF000000)
@@ -501,7 +543,7 @@ unchget(ch)
}
static int
-chget()
+chget_raw()
#if CPP_DEBUG
{
int ch;
@@ -530,9 +572,9 @@ realchget()
{
if( unputc )
{
- if((unputc&0xFF)==26 && in_preproc) return '\n';
+ if((unputc&0xFF)==EOT && in_preproc) return '\n';
ch=(unputc&0xFF); unputc>>=8;
- if( ch == 26 ) ch = EOF;
+ if( ch == EOT ) ch = EOF;
if( ch == '\n' ) c_lineno++;
return ch;
}
@@ -579,7 +621,7 @@ do_preproc()
{
int val, no_match=0;
- if( (val=get_onetok()) == TK_WORD )
+ if( (val=get_onetok(SKIP_SPACE)) == TK_WORD )
{
if( strcmp(curword, "ifdef") == 0 )
do_proc_if(0);
@@ -603,25 +645,27 @@ do_preproc()
do_proc_define();
else if( strcmp(curword, "undef") == 0 )
do_proc_undef();
- else if( strcmp(curword, "error") == 0 )
- return do_proc_copy_hashline();
- else if( strcmp(curword, "warning") == 0 )
- return do_proc_copy_hashline();
- else if( strcmp(curword, "asm") == 0 ) {
- in_asm |= 1;
+ else if( strcmp(curword, "error") == 0 ) {
+ strcpy(curword, "#error");
+ do_proc_copy_hashline(); pgetc();
+ cerror(curword);
+ } else if( strcmp(curword, "warning") == 0 ) {
+ strcpy(curword, "#warning");
+ do_proc_copy_hashline(); pgetc();
+ cwarn(curword);
+ } else if( strcmp(curword, "pragma") == 0 ) {
+ do_proc_copy_hashline(); pgetc();
+ /* Ignore #pragma */
+ } else if( strcmp(curword, "asm") == 0 ) {
+ alltok |= 0x100;
return do_proc_copy_hashline();
} else if( strcmp(curword, "endasm") == 0 ) {
- in_asm &= ~1;
+ alltok &= ~0x100;
return do_proc_copy_hashline();
} else
no_match=1;
}
}
- else if( val == '#' ) /* This is a comment, it's used as a marker */
- /* for compiler specific header files */
- {
- while((val = pgetc()) != '\n');
- }
else no_match=1;
if( no_match )
@@ -630,8 +674,8 @@ do_preproc()
while( val != '\n' ) val = pgetc();
}
- strcpy(curword, "\n");
- return '\n';
+ *curword = 0; /* Just in case */
+ return 0;
}
static int
@@ -657,18 +701,19 @@ do_proc_copy_hashline()
return TK_COPY;
}
-static void do_proc_include()
+static void
+do_proc_include()
{
int ch, ch1;
char * p;
FILE * fd;
- ch = get_onetok();
+ ch = get_onetok(SKIP_SPACE);
if( ch == '<' || ch == '"' )
{
if( ch == '"' ) ch1 = ch; else ch1 = '>';
p = curword;
- while(p< curword+sizeof(curword)-1)
+ while(p< curword+WORDSIZE-1)
{
ch = pgetc();
if( ch == '\n' ) break;
@@ -705,12 +750,13 @@ static void do_proc_include()
return;
}
-static void do_proc_define()
+static void
+do_proc_define()
{
int ch, ch1;
struct define_item * ptr, * old_value = 0;
int cc, len;
- char name[sizeof(curword)];
+ char name[WORDSIZE];
if( (ch=gettok_nosub()) == TK_WORD )
{
@@ -720,32 +766,15 @@ static void do_proc_define()
{
set_entry(0, name, (void*)0); /* Unset var */
if (ptr->in_use)
- ; /* Eeeek! This shouldn't happen; so just let it leak. */
+ /* Eeeek! This shouldn't happen; so just let it leak. */
+ cwarn("macro redefined while it was in use!?");
else
old_value = ptr;
}
+
+ /* Skip blanks */
for(ch=ch1=pgetc(); ch == ' ' || ch == '\t' ; ch=pgetc()) ;
- /* If #define with no substitute */
- if( ch == '\n' )
- {
-#if CPP_DEBUG
- fprintf(stderr, "\n### Define '%s' as null\n", name);
-#endif
- ptr = malloc(sizeof(struct define_item));
- if(ptr==0) cfatal("Preprocessor out of memory");
- ptr->name = set_entry(0, name, ptr);
- ptr->value[0] = '\0';
- ptr->arg_count = -1;
- ptr->in_use = 0;
- ptr->next = 0;
- if (old_value) {
- if (strcmp(old_value->value, ptr->value) != 0)
- cwarn("#define redefined macro");
- free(old_value);
- }
- return;
- }
len = WORDSIZE;
ptr = malloc(sizeof(struct define_item) + WORDSIZE);
if(ptr==0) cfatal("Preprocessor out of memory");
@@ -801,11 +830,14 @@ static void do_proc_define()
ptr->value[cc++] = ch;
ch = pgetc();
}
- ptr->value[cc++] = ' '; /* Byte of lookahead for recursive macros */
+ if (cc)
+ ptr->value[cc++] = ' ';/* Byte of lookahead for recursive macros */
ptr->value[cc++] = 0;
#if CPP_DEBUG
- if (ptr->arg_count<0)
+ if (cc == 1)
+ fprintf(stderr, "\n### Define '%s' as null\n", name);
+ else if (ptr->arg_count<0)
fprintf(stderr, "\n### Define '%s' as '%s'\n",
name, ptr->value);
else
@@ -829,7 +861,8 @@ static void do_proc_define()
while(ch != '\n') ch = pgetc();
}
-static void do_proc_undef()
+static void
+do_proc_undef()
{
int ch;
struct define_item * ptr;
@@ -840,7 +873,8 @@ static void do_proc_undef()
{
set_entry(0, curword, (void*)0); /* Unset var */
if (ptr->in_use)
- ; /* Eeeek! This shouldn't happen; so just let it leak. */
+ /* Eeeek! This shouldn't happen; so just let it leak. */
+ cwarn("macro undefined while it was in use!?");
else
free(ptr);
}
@@ -853,7 +887,8 @@ static void do_proc_undef()
}
}
-static int do_proc_if(type)
+static int
+do_proc_if(type)
int type;
{
int ch = 0;
@@ -914,7 +949,8 @@ int type;
return 0;
}
-static void do_proc_else()
+static void
+do_proc_else()
{
if( if_hidden == 0 )
{
@@ -929,7 +965,8 @@ static void do_proc_else()
do_proc_tail();
}
-static void do_proc_endif()
+static void
+do_proc_endif()
{
if( if_hidden )
if_hidden--;
@@ -979,7 +1016,7 @@ int prio;
int_type rvalue;
int no_op = 0;
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
lvalue = get_exp_value();
do
@@ -1112,22 +1149,22 @@ get_exp_value()
int sign = 1;
if (curtok == '!') {
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
return !get_exp_value();
}
if (curtok == '~') {
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
return ~get_exp_value();
}
while (curtok == '+' || curtok == '-') {
if (curtok == '-') sign = -sign;
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
}
if (curtok == TK_NUM) {
value = strtoul(curword, (void*)0, 0);
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
} else if (curtok == TK_QUOT) {
value = curword[1];
if (value == '\\') {
@@ -1153,7 +1190,7 @@ get_exp_value()
#else
value = (unsigned char) value;
#endif
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
} else if (curtok == TK_WORD) {
value = 0;
if (strcmp("defined", curword) == 0) {
@@ -1165,16 +1202,16 @@ get_exp_value()
if (curtok == '(' && gettok_nosub() != ')')
cerror("'defined' keyword requires closing ')'");
else
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
}
}
else
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
} else if (curtok == '(') {
value = get_expression(0);
if (curtok == ')')
- curtok = get_onetok();
+ curtok = get_onetok(SKIP_SPACE);
else
curtok = '$';
}
@@ -1182,7 +1219,7 @@ get_exp_value()
return sign<0 ? -value: value;
}
-static int
+void
gen_substrings(macname, data_str, arg_count)
char * macname;
char * data_str;
@@ -1191,10 +1228,12 @@ int arg_count;
char * mac_text = 0;
struct arg_store *arg_list;
int ac, ch, cc, len;
- int args_found = 1; /* An empty arg still counts as one. */
int paren_count = 0;
int in_quote = 0;
+ int quote_char = 0;
+ int commas_found = 0;
+ int args_found = 0;
arg_list = malloc(sizeof(struct arg_store) * arg_count);
memset(arg_list, 0, sizeof(struct arg_store) * arg_count);
@@ -1212,38 +1251,28 @@ int arg_count;
arg_list[ac].name[cc] = 0;
}
- while((ch = chget()) <= ' ' && ch != EOF ) ;
-
- if( ch != '(' )
- {
- /* Macro name used without arguments, ignore substitution */
- unchget(ch);
- /* unchget(' '); .* This is needed incase the next thing is a word */
- /* to stop these two words being stuck together. */
- return 0;
- }
-
for(;;) {
if ((ch = chget()) == EOF) break;
if(in_quote == 2) {
in_quote = 1;
} else if (in_quote) {
- if ( ch == '"' ) in_quote = 0;
+ if ( ch == quote_char ) in_quote = 0;
if ( ch == '\\') in_quote = 2;
} else {
if ( ch == '(' ) paren_count++;
- if ( ch == '"' ) in_quote = 1;
+ if ( ch == '"' || ch == '\'' ) { in_quote = 1; quote_char = ch; }
if (paren_count == 0 && ch == ',' ) {
- args_found++; continue;
+ commas_found++; continue;
}
if ( ch == ')' ) {
if (paren_count == 0) break;
paren_count--;
}
}
+ args_found = 1;
/* Too many args; ignore rest */
- if (args_found > arg_count ) continue;
- ac = args_found-1;
+ if (commas_found >= arg_count ) continue;
+ ac = commas_found;
if (arg_list[ac].value == 0) {
cc = len = 0;
arg_list[ac].in_define = def_count;
@@ -1253,27 +1282,38 @@ int arg_count;
len += 20;
arg_list[ac].value = realloc(arg_list[ac].value, len);
}
- if (ch == '\n' && cc>0 && arg_list[ac].value[cc-1] == '\\' ) {
- /* Humm, ok */
- arg_list[ac].value[--cc] = 0;
- ch = ' ';
- if (!ansi_c) continue;
- }
+#if 0
if (ch == '\n' && cc>0 && arg_list[ac].value[cc-1] == '\n' ) {
- cerror("Unquoted newline in macro arguments");
- break;
+ ... ?
}
+#endif
arg_list[ac].value[cc++] = ch;
arg_list[ac].value[cc] = 0;
}
+ if (commas_found || args_found) args_found = commas_found+1;
+
if( arg_count != args_found )
cerror("Incorrect number of macro arguments");
mac_text = insert_substrings(data_str, arg_list, arg_count);
+ /*
+ * At this point 'mac_text' contains the full expansion of the macro.
+ *
+ * So we could scan this for calls to this macro and if we find one
+ * that _exactly_ matches this call (including arguments) then we mark
+ * this call's in_use flag.
+ *
+ * OTOH, it would probably be best to throw away this expansion and
+ * pretend we never noticed this macro expansion in the first place.
+ *
+ * Still this is mostly academic as the error trapping works and
+ * recursive macros _with_arguments_ are both rare and unpredictable.
+ */
+
if (arg_list) {
for (ac=0; ac<arg_count; ac++) {
if (arg_list[ac].name) free(arg_list[ac].name);
@@ -1290,10 +1330,10 @@ int arg_count;
unputc = 0;
def_ptr = mac_text;
def_start = mac_text;
+ def_ref = 0;
#if CPP_DEBUG
fprintf(stderr, "\n### <DEF%d='%s'>\n", def_count, mac_text);
#endif
- return 1;
}
static char *
@@ -1308,6 +1348,7 @@ int arg_count;
int len = 0;
int cc = 0;
int in_quote = 0;
+ int quote_char = 0;
int ansi_stringize = 0;
#if CPP_DEBUG
@@ -1323,14 +1364,15 @@ int arg_count;
while(*data_str) {
p = curword;
- if (ansi_c) {
+ if (dialect != DI_KNR) {
if (in_quote == 2)
in_quote = 1;
else if (in_quote) {
- if (*data_str == '"') in_quote = 0;
+ if (*data_str == quote_char) in_quote = 0;
if (*data_str == '\\') in_quote = 2;
} else {
- if (*data_str == '"') in_quote = 1;
+ if (*data_str == '"' || *data_str == '\'')
+ { in_quote = 1; quote_char = *data_str; }
}
}
@@ -1347,7 +1389,7 @@ int arg_count;
if (p == curword) {
/* Ansi Stringize and concat */
- if (*data_str == '#' && ansi_c) {
+ if (*data_str == '#' && dialect != DI_KNR) {
if (data_str[1] == '#') {
while(cc>0 && (rv[cc-1] == ' ' || rv[cc-1] == '\t'))
cc--;
@@ -1381,6 +1423,7 @@ int arg_count;
strcmp(curword, arg_list[ac].name) == 0)
{
s = arg_list[ac].value;
+ if (!s) s = ""; else
/* Ansi stringize operation, this is very messy! */
if (ansi_stringize) {
diff --git a/cpp/log b/cpp/log
deleted file mode 100644
index 1117b3d..0000000
--- a/cpp/log
+++ /dev/null
@@ -1,77 +0,0 @@
-
-#define  m_size((p))  ((p) [0].size) /* For malloc */
-
-### Define 'm_size' as 1 args 'p,((p) [0].size) '
-#define  m_next((p))  ((p) [1].next) /* For malloc and alloca */
-
-### Define 'm_next' as 1 args 'p,((p) [1].next) '
-#define  m_deep((p))  ((p) [0].depth) /* For alloca */
-
-### Define 'm_deep' as 1 args 'p,((p) [0].depth) '
-
- mm_size((p1)
-### Macro substitution in '((p) [0].size) '
-### Argument 1 (p) = 'p1'
-
-### <DEF1='((p1) [0].size) '>
-<DEF1>((pp1)) [0].ssize)) <DEF0>+= mm_size((m_next(p1))
-### Macro substitution in '((p) [0].size) '
-### Argument 1 (p) = 'm_next(p1)'
-
-### <DEF1='((m_next(p1)) [0].size) '>
-<DEF1>((mm_next((p1)
-### Macro substitution in '((p) [1].next) '
-### Argument 1 (p) = 'p1'
-
-### <DEF2='((p1) [1].next) '>
-<DEF2>((pp1)) [1].nnext)) )<DEF1> [0].ssize)) ;<DEF0>
- mm_next((p1)
-### Macro substitution in '((p) [1].next) '
-### Argument 1 (p) = 'p1'
-
-### <DEF1='((p1) [1].next) '>
-<DEF1>((pp1)) [1].nnext)) <DEF0>= mm_next((m_next(p1))
-### Macro substitution in '((p) [1].next) '
-### Argument 1 (p) = 'm_next(p1)'
-
-### <DEF1='((m_next(p1)) [1].next) '>
-<DEF1>((mm_next((pp1))) [1].nnext)) ;<DEF0>
- nnoise(("JOIN 2", pp1));
-
- hhello/?/??? ? 
-??=warning  oooer
-
-#define  LOCK_NB  4 /* or'd with one of the above to prevent
- blocking */
-
-### Define 'LOCK_NB' as '4 '
-#define  LOCK_UN  8 /* remove lock */
-
-### Define 'LOCK_UN' as '8 '
-
-
-#define  comba((x,,yy))  x/**/y
-
-### Define 'comba' as 2 args 'x,y,x y '
-#define  combb((x,,yy))  x ## y
-
-### Define 'combb' as 2 args 'x,y,x ## y '
-
-
- ccomba((un,signed)
-### Macro substitution in 'x y '
-### Argument 1 (x) = 'un'
-### Argument 2 (y) = 'signed'
-
-### <DEF1='un signed '>
-<DEF1>un  ssigned  ;<DEF0>
- ccombb((un,signed)
-### Macro substitution in 'x ## y '
-### Argument 1 (x) = 'un'
-### Argument 2 (y) = 'signed'
-
-### <DEF1='unsigned '>
-<DEF1>unsigned  ;<DEF0>
-.
-
-<EOF> \ No newline at end of file
diff --git a/cpp/main.c b/cpp/main.c
index 0ef2cf2..b2935dd 100644
--- a/cpp/main.c
+++ b/cpp/main.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#if __STDC__
#include <stdlib.h>
+#include <locale.h>
#endif
#include <ctype.h>
#include <string.h>
@@ -11,16 +12,22 @@
#define MAXINCPATH 5
+int main _P((int argc, char ** argv));
+void undefine_macro _P((char * name));
+void define_macro _P((char * name));
void print_toks_cpp _P((void));
void print_toks_raw _P((void));
void define_macro _P((char *));
void undefine_macro _P((char *));
+void cmsg _P((char * mtype, char * str));
+char * token_txn _P((int));
char * include_paths[MAXINCPATH];
char last_name[512] = "";
int last_line = -1;
int debug_mode = 0;
+int p_flag = 0;
char * outfile = 0;
FILE * ofd = 0;
@@ -34,16 +41,21 @@ char ** argv;
char * p;
static char Usage[] = "Usage: cpp -E -0 -Dxxx -Uxxx -Ixxx infile -o outfile";
- in_asm = 2; /* Always in assembler mode */
+#ifdef LC_CTYPE
+ setlocale(LC_CTYPE, "");
+#endif
+
+ alltok = 1; /* Get all tokens from the cpp. */
for(ar=1; ar<argc; ar++) if( argv[ar][0] == '-') switch(argv[ar][1])
{
- case 'd': debug_mode = 1; break;
- case 'T': in_asm = 0; break;
- case 'E': /* in_asm = 0; */ break;
- case 'A': ansi_c = 1; break;
+ case 'd': debug_mode++; break;
+ case 'T': alltok = 0; break;
+ case 'A': dialect = DI_ANSI; break;
+ case 'K': dialect = DI_KNR; break;
- /* Some options for the code generator. */
+ /* Some options for describing the code generator. */
+ case 'E': break;
case '0': define_macro("__BCC__");
define_macro("__AS386_16__");
define_macro("__8086__");
@@ -60,10 +72,9 @@ static char Usage[] = "Usage: cpp -E -0 -Dxxx -Uxxx -Ixxx infile -o outfile";
break;
case 'C': /* Keep comments. */
- cfatal("-C not implemented");
+ cwarn("-C not implemented");
break;
- case 'P': /* Supress #line lines. */
- cfatal("-P not implemented");
+ case 'P': p_flag++;
break;
case 'I':
@@ -116,9 +127,14 @@ static char Usage[] = "Usage: cpp -E -0 -Dxxx -Uxxx -Ixxx infile -o outfile";
/* Input file */
curfile = fopen(argv[ar], "r");
c_fname = argv[ar]; c_lineno = 1;
+ if (!curfile)
+ cfatal("Cannot open input file");
} else
cfatal(Usage);
+ if (!curfile)
+ cfatal(Usage);
+
if (outfile) ofd = fopen(outfile, "w");
else ofd = stdout;
if (!ofd)
@@ -205,12 +221,12 @@ cmsg(mtype, str)
char * mtype;
char * str;
{
- if (mtype) {
- if (c_fname && (*c_fname || c_lineno))
- fprintf(stderr, "%s %s(%d): %s\n", mtype, c_fname, c_lineno, str);
- else
- fprintf(stderr, "%s %s\n", mtype, str);
- } else
+ if (c_fname && (*c_fname || c_lineno))
+ fprintf(stderr, "%s:%d: ", c_fname, c_lineno);
+
+ if (mtype && *mtype)
+ fprintf(stderr, "%s: %s\n", mtype, str);
+ else
fprintf(stderr, "%s\n", str);
}
@@ -226,14 +242,14 @@ void
cerror(str)
char * str;
{
- cmsg("CPP error", str);
+ cmsg("error", str);
}
void
cwarn(str)
char * str;
{
- cmsg("CPP warning", str);
+ cmsg("warning", str);
}
void
@@ -255,22 +271,22 @@ hash_line()
if (last_line > 0) last_line++;
}
while( c_lineno > last_line &&
- c_lineno < last_line+2 && /* XXX: Change to 10 */
+ (p_flag || c_lineno < last_line+4) &&
last_line > 0 &&
!debug_mode )
{
fputc('\n', ofd); last_line++;
}
- if( c_lineno != last_line || last_line <= 0 )
+ if( !p_flag && (c_lineno != last_line || last_line <= 0 ))
{
fprintf(ofd, "# %d", c_lineno);
if( last_line <= 0 ) fprintf(ofd, " \"%s\"", c_fname);
- /* if( last_line > 0 ) fprintf(ofd, " // From line %d", last_line); */
fprintf(ofd, "\n");
- strcpy(last_name, c_fname);
- last_line = c_lineno;
}
+
+ strcpy(last_name, c_fname);
+ last_line = c_lineno;
}
}
@@ -288,12 +304,11 @@ print_toks_cpp()
switch(i)
{
case '\n':
- cwarn("Newline!?");
+ cwarn("newline received from tokeniser!");
break;
case TK_STR:
- outpos += strlen(curword);
- fprintf(ofd, "%s", curword);
+ outpos += fprintf(ofd, "%s", curword);
break;
case TK_COPY:
@@ -304,9 +319,10 @@ print_toks_cpp()
case TK_FILE: sprintf(curword, "\"%s\"", c_fname); if(0) {
case TK_LINE: sprintf(curword, "%d", c_lineno);
- default: ; }
-
- if (!in_asm) {
+ }
+ /*FALLTHROUGH*/
+ default:
+ if (!alltok) {
if(i == '}' || i == TK_CASE || i == TK_DEFAULT ) indent--;
if(i ==')') paren--;
@@ -318,23 +334,15 @@ print_toks_cpp()
if(i =='(') paren++;
}
- fprintf(ofd, "%s", curword);
- outpos += strlen(curword);
+ outpos += fprintf(ofd, "%s", curword);
- if ( i == '"' )
+ if ( i == '"' || i == '\'' )
{
while((i=gettok()) == TK_STR) {
- outpos += strlen(curword);
- fprintf(ofd, "%s", curword);
- }
- if (i != '\n') {
- outpos += strlen(curword);
- fprintf(ofd, "%s", curword);
- } else {
- outpos++;
- fputc('"', ofd);
- cerror("Unterminated string");
+ outpos += fprintf(ofd, "%s", curword);
}
+ if (i != '\n')
+ outpos += fprintf(ofd, "%s", curword);
}
break;
}
@@ -355,36 +363,133 @@ print_toks_raw()
hash_line();
switch(i)
{
- default: fprintf(ofd, "%04x: '", i);
+ case '"': case '\'':
+ if (debug_mode < 2) {
+ fprintf(ofd, "%-16s: %s", "Quoted string", curword);
+ while((i=gettok()) == TK_STR)
+ outpos+= fprintf(ofd, "%s", curword);
+ if ( i == '\n' ) fprintf(ofd, " --> EOL!!\n");
+ else outpos+= fprintf(ofd, "%s\n", curword);
+ break;
+ }
+ /*FALLTHROUGH*/
+ default: fprintf(ofd, "%-16s: '", token_txn(i));
{
char *p;
for(p=curword; *p; p++)
- if(isprint(*p) && *p != '\'')
+ if(isprint(*p) && *p != '\'' && *p != '\\')
fputc(*p, ofd);
+ else if (*p == '\n') fprintf(ofd, "\\n");
+ else if (*p == '\t') fprintf(ofd, "\\t");
+ else if (*p == '\v') fprintf(ofd, "\\v");
+ else if (*p == '\b') fprintf(ofd, "\\b");
+ else if (*p == '\r') fprintf(ofd, "\\r");
+ else if (*p == '\f') fprintf(ofd, "\\f");
+ else if (*p == '\a') fprintf(ofd, "\\a");
else
fprintf(ofd, "\\x%02x", (unsigned char)*p);
}
fprintf(ofd, "'\n");
break;
- case '"':
- fprintf(ofd, "QSTR: \"");
- while((i=gettok()) == TK_STR) {
- if (i == '\n')
- fprintf(ofd, "\\N");
- else
- fputc(*curword, ofd), outpos++;
- }
- if ( i == '\n' ) fprintf(ofd, "\" --> No terminator\n");
- else fprintf(ofd, "\"\n");
- break;
case TK_NUM:
val = strtoul(curword, (void*)0, 0);
- fprintf(ofd, "NUMB: %s => %ld\n", curword, val);
+ fprintf(ofd, "%-16s: ", token_txn(i));
+ fprintf(ofd, "%s => %ld\n", curword, val);
break;
case TK_COPY:
- fprintf(ofd, "AMSG: #%s\n", curword);
+ fprintf(ofd, "%-16s: ", token_txn(i));
+ fprintf(ofd, "#%s\n", curword);
+ break;
+ case '\n':
+ fprintf(ofd, "%-16s:\n", "Newline char");
break;
}
}
}
+char *
+token_txn(token)
+int token;
+{
+ char * s = "UNKNOWN";
+ static char buf[17];
+
+ if (token> ' ' && token <= '~')
+ {
+ sprintf(buf, "TK_CHAR('%c')", token);
+ return buf;
+ }
+ if (token >= 0 && token < 0x100)
+ {
+ sprintf(buf, "TK_CHAR(%d)", token);
+ return buf;
+ }
+
+ switch(token)
+ {
+ case TK_WSPACE : s="TK_WSPACE"; break;
+ case TK_WORD : s="TK_WORD"; break;
+ case TK_NUM : s="TK_NUM"; break;
+ case TK_FLT : s="TK_FLT"; break;
+ case TK_QUOT : s="TK_QUOT"; break;
+ case TK_STR : s="TK_STR"; break;
+ case TK_FILE : s="TK_FILE"; break;
+ case TK_LINE : s="TK_LINE"; break;
+ case TK_COPY : s="TK_COPY"; break;
+ case TK_NE_OP : s="TK_NE_OP"; break;
+ case TK_MOD_ASSIGN : s="TK_MOD_ASSIGN"; break;
+ case TK_AND_OP : s="TK_AND_OP"; break;
+ case TK_AND_ASSIGN : s="TK_AND_ASSIGN"; break;
+ case TK_MUL_ASSIGN : s="TK_MUL_ASSIGN"; break;
+ case TK_INC_OP : s="TK_INC_OP"; break;
+ case TK_ADD_ASSIGN : s="TK_ADD_ASSIGN"; break;
+ case TK_DEC_OP : s="TK_DEC_OP"; break;
+ case TK_SUB_ASSIGN : s="TK_SUB_ASSIGN"; break;
+ case TK_PTR_OP : s="TK_PTR_OP"; break;
+ case TK_ELLIPSIS : s="TK_ELLIPSIS"; break;
+ case TK_DIV_ASSIGN : s="TK_DIV_ASSIGN"; break;
+ case TK_LEFT_OP : s="TK_LEFT_OP"; break;
+ case TK_LEFT_ASSIGN : s="TK_LEFT_ASSIGN"; break;
+ case TK_LE_OP : s="TK_LE_OP"; break;
+ case TK_EQ_OP : s="TK_EQ_OP"; break;
+ case TK_GE_OP : s="TK_GE_OP"; break;
+ case TK_RIGHT_OP : s="TK_RIGHT_OP"; break;
+ case TK_RIGHT_ASSIGN : s="TK_RIGHT_ASSIGN"; break;
+ case TK_XOR_ASSIGN : s="TK_XOR_ASSIGN"; break;
+ case TK_OR_ASSIGN : s="TK_OR_ASSIGN"; break;
+ case TK_OR_OP : s="TK_OR_OP"; break;
+ case TK_AUTO : s="TK_AUTO"; break;
+ case TK_BREAK : s="TK_BREAK"; break;
+ case TK_CASE : s="TK_CASE"; break;
+ case TK_CHAR : s="TK_CHAR"; break;
+ case TK_CONST : s="TK_CONST"; break;
+ case TK_CONTINUE : s="TK_CONTINUE"; break;
+ case TK_DEFAULT : s="TK_DEFAULT"; break;
+ case TK_DO : s="TK_DO"; break;
+ case TK_DOUBLE : s="TK_DOUBLE"; break;
+ case TK_ELSE : s="TK_ELSE"; break;
+ case TK_ENUM : s="TK_ENUM"; break;
+ case TK_EXTERN : s="TK_EXTERN"; break;
+ case TK_FLOAT : s="TK_FLOAT"; break;
+ case TK_FOR : s="TK_FOR"; break;
+ case TK_GOTO : s="TK_GOTO"; break;
+ case TK_IF : s="TK_IF"; break;
+ case TK_INT : s="TK_INT"; break;
+ case TK_LONG : s="TK_LONG"; break;
+ case TK_REGISTER : s="TK_REGISTER"; break;
+ case TK_RETURN : s="TK_RETURN"; break;
+ case TK_SHORT : s="TK_SHORT"; break;
+ case TK_SIGNED : s="TK_SIGNED"; break;
+ case TK_SIZEOF : s="TK_SIZEOF"; break;
+ case TK_STATIC : s="TK_STATIC"; break;
+ case TK_STRUCT : s="TK_STRUCT"; break;
+ case TK_SWITCH : s="TK_SWITCH"; break;
+ case TK_TYPEDEF : s="TK_TYPEDEF"; break;
+ case TK_UNION : s="TK_UNION"; break;
+ case TK_UNSIGNED : s="TK_UNSIGNED"; break;
+ case TK_VOID : s="TK_VOID"; break;
+ case TK_VOLATILE : s="TK_VOLATILE"; break;
+ case TK_WHILE : s="TK_WHILE"; break;
+ }
+ return s;
+}
diff --git a/cpp/q.c b/cpp/q.c
index e24592a..8ca4402 100644
--- a/cpp/q.c
+++ b/cpp/q.c
@@ -1,23 +1,26 @@
-
#define m_size(p) ((p) [0].size) /* For malloc */
#define m_next(p) ((p) [1].next) /* For malloc and alloca */
#define m_deep(p) ((p) [0].depth) /* For alloca */
-
m_size(p1) += m_size(m_next(p1));
m_next(p1) = m_next(m_next(p1));
- noise("JOIN 2", p1);
-
- hello/??
+ noise("JÖIN \"2\" EOF?->˙", p1);
+#asm
+ hello??
??=warning oooer
+/\
+* wtf! */
#define LOCK_NB 4 /* or'd with one of the above to prevent
blocking */
#define LOCK_UN 8 /* remove lock */
-
-
+#define bb 11
+#define cc 22
+#define bbcc 4455
#define comba(x,y) x/**/y
#define combb(x,y) x ## y
+#define empty
-
- comba(un,signed);
- combb(un,signed);
-.
+ \0 \00 \000 \0000 \200 \x34f \xff
+bb\
+cc
+ comba(un,signed); ++ -- >> << {} combb(un,signed);
+#endasm
diff --git a/cpp/token1.tok b/cpp/token1.tok
index 92e6d83..cd668ce 100644
--- a/cpp/token1.tok
+++ b/cpp/token1.tok
@@ -23,4 +23,3 @@ struct token_trans { char * name; int token; };
==, TK_EQ_OP
!=, TK_NE_OP
.., TK_WORD
-//, TK_WORD
diff --git a/cpp/torture.c b/cpp/torture.c
new file mode 100644
index 0000000..5bd13ce
--- /dev/null
+++ b/cpp/torture.c
@@ -0,0 +1,18 @@
+/\
+* \ This _evil_ little file is compilable Ansi C.
+* / There are NO extensions ... Waddya think ?
+\/
+
+// ***/ func() { printf("Hello /* world */ %d ???/?=\n" ??/
+, 1?
+'\\
+007':
+'??/"'/*"*/
+ );}
+
+
+main()
+{
+ func();
+
+}
diff --git a/ld/writex86.c b/ld/writex86.c
index 95ff040..d877edc 100644
--- a/ld/writex86.c
+++ b/ld/writex86.c
@@ -357,9 +357,9 @@ bool_pt argxsym;
sizeof extsym.n_name);
else
{
- memcpy((char *) extsym.n_name, "__", 2);
- strncpy((char *) extsym.n_name+2, symptr->name,
- sizeof(extsym.n_name)-2);
+ memcpy((char *) extsym.n_name, "$", 1);
+ strncpy((char *) extsym.n_name+1, symptr->name,
+ sizeof(extsym.n_name)-1);
}
#else
strncpy((char *) extsym.n_name, symptr->name,
diff --git a/libc/i386fp/Makefile b/libc/i386fp/Makefile
index 46c28a9..298ca18 100644
--- a/libc/i386fp/Makefile
+++ b/libc/i386fp/Makefile
@@ -2,9 +2,7 @@
.SUFFIXES: .x # .x files are .s files that need C-preprocessing
.x.o:
- cp $< tmp.c
- $(CC) $(CFLAGS) -E tmp.c >tmp.s
- $(CC) $(CFLAGS) -c tmp.s -A-n -A$* -o $@
+ $(CC) $(CFLAGS) -c $< -o $@
FPDIST =Makefile $(FPSRC) test.c bccfp.tex
FPSRC =fadd.x fcomp.x fdiv.x fmul.x fbsr.x \
@@ -17,14 +15,13 @@ FPOBJ =fadd.o fcomp.o fdiv.o fmul.o fpbsr.o \
fperr.o fperror.o fptoi.o fpushd.o fpulld.o \
fpushi.o fpushf.o fpullf.o frexp.o ftst.o \
fabs.o ldexp.o modf.o
-JUNK =tmp tmp.c tmp.s tmp.lst
LIB =.
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
ifeq ($(LIB_CPU),i386)
all: $(LIBC)($(FPOBJ))
- rm -f $(JUNK) $(FPOBJ)
+ rm -f $(FPOBJ)
else
all:
@:
@@ -34,5 +31,5 @@ $(LIBC)($(FPOBJ)): fplib.h
$(LIBC)(fperr.o fperror.o): fperr.h
clean:
- rm -f $(FPOBJ) $(JUNK) test
+ rm -f $(FPOBJ) test
rm -f $(LIB)/libfp.a bccfp.tar.Z bccfp.uue
diff --git a/libc/include/features.h b/libc/include/features.h
index 1c7da63..cc002f6 100644
--- a/libc/include/features.h
+++ b/libc/include/features.h
@@ -7,8 +7,8 @@
#define __P(x) x
#define __const const
-/* Almost ansi */
-#if __STDC__ != 1
+/* Not really ansi */
+#ifdef __BCC__
#define const
#define volatile
#endif
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 0afc883..ce975f0 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -3,7 +3,7 @@
#define __SYS_CDEFS_H
#include <features.h>
-#if defined (__STDC__) && __STDC__
+#if __STDC__
#define __CONCAT(x,y) x ## y
#define __STRING(x) #x