Better ANSI C compatibility and portability - part 1:
authorcarl <cecodere@yahoo.ca>
Mon, 18 Feb 2019 16:32:48 +0000 (00:32 +0800)
committercarl <cecodere@yahoo.ca>
Mon, 18 Feb 2019 16:54:23 +0000 (00:54 +0800)
+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
+ Convert to sed scripts some shell scripts for better portability.
+ Reduce usage of em_path.h

54 files changed:
modules/src/em_code/CMakeLists.txt [new file with mode: 0644]
modules/src/em_code/C_out.c
modules/src/em_code/bhcst.c
modules/src/em_code/bhdlb.c
modules/src/em_code/bhdnam.c
modules/src/em_code/bhfcon.c
modules/src/em_code/bhicon.c
modules/src/em_code/bhilb.c
modules/src/em_code/bhpnam.c
modules/src/em_code/bhucon.c
modules/src/em_code/build.lua
modules/src/em_code/crcst.c
modules/src/em_code/crdlb.c
modules/src/em_code/crdnam.c
modules/src/em_code/crilb.c
modules/src/em_code/crpnam.c
modules/src/em_code/crscon.c
modules/src/em_code/crxcon.c
modules/src/em_code/cst.c
modules/src/em_code/dfdlb.c
modules/src/em_code/dfdnam.c
modules/src/em_code/dfilb.c
modules/src/em_code/dlb.c
modules/src/em_code/dnam.c
modules/src/em_code/em.c
modules/src/em_code/em_code.h
modules/src/em_code/em_private.h
modules/src/em_code/end.c
modules/src/em_code/endarg.c
modules/src/em_code/exc.c
modules/src/em_code/fcon.c
modules/src/em_code/getid.c
modules/src/em_code/icon.c
modules/src/em_code/ilb.c
modules/src/em_code/insert.c
modules/src/em_code/internerr.c
modules/src/em_code/makeem.sed [new file with mode: 0644]
modules/src/em_code/msend.c
modules/src/em_code/msstart.c
modules/src/em_code/op.c
modules/src/em_code/opcst.c
modules/src/em_code/opdlb.c
modules/src/em_code/opdnam.c
modules/src/em_code/opilb.c
modules/src/em_code/opnarg.c
modules/src/em_code/oppnam.c
modules/src/em_code/pnam.c
modules/src/em_code/pro.c
modules/src/em_code/pronarg.c
modules/src/em_code/psdlb.c
modules/src/em_code/psdnam.c
modules/src/em_code/pspnam.c
modules/src/em_code/scon.c
modules/src/em_code/ucon.c

diff --git a/modules/src/em_code/CMakeLists.txt b/modules/src/em_code/CMakeLists.txt
new file mode 100644 (file)
index 0000000..91761f9
--- /dev/null
@@ -0,0 +1,99 @@
+cmake_minimum_required (VERSION 2.9)
+project(em_code)
+
+set(SRC
+ bhcst.c
+ bhdlb.c
+ bhdnam.c
+ bhfcon.c
+ bhicon.c
+ bhilb.c
+ bhpnam.c
+ bhucon.c
+ crcst.c
+ crdlb.c
+ crdnam.c
+ crxcon.c
+ crilb.c
+ crpnam.c
+ crscon.c 
+ cst.c
+ dfdlb.c
+ dfdnam.c
+ dfilb.c
+ dlb.c
+ dnam.c
+ end.c
+ endarg.c 
+ exc.c
+ fcon.c
+ getid.c
+ icon.c
+ ilb.c
+ insert.c
+ internerr.c 
+ msend.c
+ op.c
+ opcst.c
+ opdlb.c
+ opdnam.c
+ opilb.c
+ opnarg.c
+ oppnam.c
+ pnam.c 
+ pro.c
+ pronarg.c
+ msstart.c
+ psdlb.c
+ psdnam.c
+ pspnam.c
+ scon.c
+ ucon.c 
+ C_out.c
+ failed.c
+ em.c
+ em_codeEK.h
+ em_code.h
+ em_codeCE.h
+ em_codeO.h
+ em_private.h
+)
+
+set(INCLUDE_DIRS 
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+
+
+add_library(eme ${SRC})
+target_include_directories(eme PUBLIC ${INCLUDE_DIRS})
+target_compile_definitions(eme PRIVATE READABLE_EM)
+target_link_libraries(eme em_data alloc print system)
+
+add_library(emk ${SRC})
+target_include_directories(emk PUBLIC ${INCLUDE_DIRS})
+target_link_libraries(emk em_data alloc print system)
+
+set_target_properties(eme PROPERTIES PUBLIC_HEADER "em_codeEK.h")
+set_target_properties(emk PROPERTIES PUBLIC_HEADER "em_codeEK.h")
+
+add_custom_command(
+  OUTPUT em_codeEK.h file1.tmp
+  COMMAND ${CMAKE_COMMAND} -E copy
+    ${CMAKE_CURRENT_SOURCE_DIR}/makeem.sed
+    ${CMAKE_CURRENT_BINARY_DIR}/makeem.sed
+  COMMAND sed -f makeem.sed ${CMAKE_CURRENT_SOURCE_DIR}/../../../h/em_table>file1.tmp
+  COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/em.nogen file1.tmp>em_codeEK.h
+  COMMENT "Regenerate em_codeEK.h from em_table"
+)
+
+install(TARGETS eme emk 
+        RUNTIME DESTINATION bin
+        LIBRARY DESTINATION lib
+        ARCHIVE DESTINATION lib
+        PUBLIC_HEADER DESTINATION include
+)
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/em_code.3X DESTINATION man OPTIONAL)
+
+
index 1359340..f03c10c 100644 (file)
@@ -9,25 +9,22 @@
 
 /* $Id$ */
 
-static arg();
-static pseudo();
+static void arg(struct e_instr *p, int comma);
+static void pseudo(struct e_instr *p);
 
 extern char em_flag[];
 char *C_error;
 
 #define flags(pp)      (em_flag[(pp)->em_opcode - sp_fmnem] & EM_PAR)
 
-struct e_instr *
-C_alloc()
+struct e_instr *C_alloc(void)
 {
        static struct e_instr b;
 
        return &b;
 }
 
-int
-C_out(p)
-       register struct e_instr *p;
+int C_out(register struct e_instr *p)
 {
        /*      Generate EM-code from the e_instr structure "p"
        */
@@ -82,9 +79,7 @@ C_out(p)
        return 1;
 }
 
-static
-arg(p, comma)
-       register struct e_instr *p;
+static void arg(register struct e_instr *p, int comma)
 {
        /*      Output the argument of "p".
        */
@@ -145,9 +140,7 @@ arg(p, comma)
        }
 }
 
-static
-pseudo(p)
-       register struct e_instr *p;
+static void pseudo(register struct e_instr *p)
 {
 
        PS(p->em_opcode);
index a49ab59..63edd1b 100644 (file)
@@ -2,11 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_bhcst(op, n, w, i)
-       arith n;
-       arith w;
-       int i;
+void CC_bhcst(int op, arith n, arith w, int i)
 {
        /*      BSS or HOL with size n, initial value a cst w, and flag i
        */
index 702960a..8813319 100644 (file)
@@ -2,12 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_bhdlb(op, n, s, off, i)
-       arith n;
-       label s;
-       arith off;
-       int i;
+void CC_bhdlb(int op, arith n, label s, arith off, int i)
 {
        /*      BSS or HOL with size n, initial value a dlb(s, off),
                and flag i
index d47465c..f73f85f 100644 (file)
@@ -2,12 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_bhdnam(op, n, s, off, i)
-       arith n;
-       char *s;
-       arith off;
-       int i;
+void CC_bhdnam(int op, arith n, char *s, arith off, int i)
 {
        /*      BSS or HOL with size n, initial value a dnam(s, off),
                and flag i
index 9c92845..3d31be7 100644 (file)
@@ -2,12 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_bhfcon(op, n, s, sz, i)
-       arith n;
-       char *s;
-       arith sz;
-       int i;
+void CC_bhfcon(int op, arith n, char *s, arith sz, int i)
 {
        /*      BSS or HOL with size n, initial value an FCON (s, sz),
                and flag i
index b6bf6ac..21dda2a 100644 (file)
@@ -2,12 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_bhicon(op, n, s, sz, i)
-       arith n;
-       char *s;
-       arith sz;
-       int i;
+void CC_bhicon(int op, arith n, char *s, arith sz, int i)
 {
        /*      BSS or HOL with size n, initial value an ICON (s, sz),
                and flag i
index eba7457..df03fdb 100644 (file)
@@ -2,11 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_bhilb(op, n, l, i)
-       arith n;
-       label l;
-       int i;
+void CC_bhilb(int op, arith n, label l, int i)
 {
        /*      BSS or HOL with size n, initial value a ILB(l),
                and flag i
index 3f9a8d6..e3f80e3 100644 (file)
@@ -2,11 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_bhpnam(op, n, p, i)
-       arith n;
-       char *p;
-       int i;
+void CC_bhpnam(int op, arith n, char *p, int i)
 {
        /*      BSS or HOL with size n, initial value a PNAM(p),
                and flag i
index de18fe9..6671691 100644 (file)
@@ -2,12 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_bhucon(op, n, s, sz, i)
-       arith n;
-       char *s;
-       arith sz;
-       int i;
+void CC_bhucon(int op, arith n, char *s, arith sz, int i)
 {
        /*      BSS or HOL with size n, initial value an UCON (s, sz),
                and flag i
index 3a82234..b65ce83 100644 (file)
@@ -89,6 +89,7 @@ local function build_variant(code, cflags)
                        "modules+headers",
                        "modules/src/alloc+lib",
                        "modules/src/em_data+lib",
+                       "modules/src/print+lib",
                        "modules/src/system+lib",
                },
                vars = {
index 6bacdb3..8e3f594 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_crcst(op, v)
-       arith v;
+void CC_crcst(int op, arith v)
 {
        /*      CON or ROM with argument CST(v)
        */
index 0cafe9f..032bdd0 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_crdlb(op, v, off)
-       label v;
-       arith off;
+void CC_crdlb(int op, label v, arith off)
 {
        /*      CON or ROM with argument DLB(v, off)
        */
index c8ec92d..d7be550 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_crdnam(op, s, off)
-       char *s;
-       arith off;
+void CC_crdnam(int op, char* s, arith off)
 {
        /*      CON or ROM with argument DNAM(s, off)
        */
index d0db218..cae0774 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_crilb(op, l)
-       label l;
+void CC_crilb(int op, label l)
 {
        /*      CON or ROM with argument ILB(l)
        */
index 24c4c49..1fdc41d 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_crpnam(op, p)
-       char *p;
+void CC_crpnam(int op, char* p)
 {
        /*      CON or ROM with argument PNAM(p)
        */
index eab953e..22c0fd8 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_crscon(op, v, s)
-       char *v;
-       arith s;
+void CC_crscon(int op, char* v, arith s)
 {
        /*      CON or ROM with argument SCON(v,z)
        */
index 5fc7063..57b579f 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_crxcon(op, spec, v, s)
-       char *v;
-       arith s;
+void CC_crxcon(int op, int spec, char* v, arith s)
 {
        /*      CON or ROM with argument ICON(v,z)
        */
index 17cfdbc..7b81dcc 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_cst(l)
-       arith l;
+void CC_cst(arith l)
 {
        COMMA();
        CST(l);
index eb9fbab..90452f1 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_dfdlb(l)
-       label l;
+void CC_dfdlb(label l)
 {
        /*      Define numeric data label
        */
index 1f1478b..bfcfbed 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_dfdnam(s)
-       char *s;
+void CC_dfdnam(char* s)
 {
        /*      Define data label
        */
index 4dd88a1..e0f0cb4 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_dfilb(l)
-       label l;
+void CC_dfilb(label l)
 {
        /*      Define instruction label
        */
index 8f711eb..5f0cd28 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_dlb(l, val)
-       label l;
-       arith val;
+void CC_dlb(label l, arith val)
 {
        COMMA();
        DOFF(l, val);
index 5c05321..85ebfa6 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_dnam(str, val)
-       char *str;
-       arith val;
+void CC_dnam(char* str, arith val)
 {
        COMMA();
        NOFF(str, val);
index cf6948b..61d4c70 100644 (file)
@@ -12,7 +12,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include "system.h"
 #include "alloc.h"
+#include "print.h"
 #include "em_arith.h"
 #include "insert.h"
 #include "em_private.h"
@@ -49,8 +51,9 @@ char          *C_current_out = obuf;
 char           *C_opp = obuf;
 #endif
 
-void
-C_flush() {
+void C_flush(void)
+{
+       int count;
 #ifdef INCORE
        static unsigned int bufsiz;
 
@@ -69,6 +72,7 @@ C_flush() {
                return;
        }
 #endif
+       count = (int)(C_opp - obuf);
        if (C_opp != obuf && sys_write(C_ofp, obuf, (int)(C_opp - obuf)) == 0) {
                C_ofp = 0;
                C_failed();
@@ -82,9 +86,7 @@ C_flush() {
 #define Xputbyte(c) put(c)
 #endif
 
-void
-C_putbyte(c)
-       int c;
+void C_putbyte(int c)
 {
        Xputbyte(c);
 }
@@ -94,15 +96,11 @@ C_putbyte(c)
 #endif
 
 /*ARGSUSED*/
-void
-C_init(w, p)
-       arith w, p;
+void C_init(arith w, arith p)
 {
 }
 
-int
-C_open(nm)
-       char *nm;
+int C_open(char* nm)
 {
        /*      Open file "nm" for output
        */
@@ -110,13 +108,15 @@ C_open(nm)
        if (nm == 0)
                C_ofp = STDOUT; /* standard output      */
        else
-       if (sys_open(nm, OP_WRITE, &C_ofp) == 0)
+       {
+
+         if (sys_open(nm, OP_WRITE, &C_ofp) == 0)
                return 0;
+       }
        return 1;
 }
 
-void
-C_close()
+void C_close(void)
 {
        /*      Finish the code-generation.
        */
@@ -150,8 +150,7 @@ C_close()
        C_ofp = 0;
 }
 
-int
-C_busy()
+int C_busy(void)
 {
        return C_ofp != 0; /* true if code is being generated */
 }
@@ -165,32 +164,27 @@ C_busy()
        names.
 */
 
-void
-C_magic()
+void C_magic(void)
 {
 }
 
 /***    the readable code generating routines  ***/
 
-static
-wrs(s)
-       register char *s;
+static int wrs(register char *s)
 {
-       while (*s) {
+       while (*s)
+       {
                C_putbyte(*s++);
        }
+       return 0;
 }
 
-void
-C_pt_dnam(s)
-       char *s;
+void C_pt_dnam(char* s)
 {
        wrs(s);
 }
 
-void
-C_pt_ilb(l)
-       label l;
+void C_pt_ilb(label l)
 {
        char buf[16];
 
@@ -201,17 +195,14 @@ C_pt_ilb(l)
 extern char em_mnem[][4];
 extern char em_pseu[][4];
 
-void
-C_pt_op(x)
+void C_pt_op(int x)
 {
        C_putbyte(' ');
        wrs(em_mnem[x - sp_fmnem]);
        C_putbyte(' ');
 }
 
-void
-C_pt_cst(l)
-       arith l;
+void C_pt_cst(arith l)
 {
        char buf[16];
 
@@ -219,10 +210,7 @@ C_pt_cst(l)
        wrs(buf);
 }
 
-void
-C_pt_scon(x, y)
-       char *x;
-       arith y;
+void C_pt_scon(char *x, arith y)
 {
        char xbuf[1024];
        register char *p;
@@ -239,17 +227,14 @@ C_pt_scon(x, y)
        C_putbyte('\'');
 }
 
-void
-C_pt_ps(x)
+void C_pt_ps(int x)
 {
        C_putbyte(' ');
        wrs(em_pseu[x - sp_fpseu]);
        C_putbyte(' ');
 }
 
-void
-C_pt_dlb(l)
-       label l;
+void C_pt_dlb(label l)
 {
        char buf[16];
 
@@ -257,10 +242,7 @@ C_pt_dlb(l)
        wrs(buf);
 }
 
-void
-C_pt_doff(l, v)
-       label l;
-       arith v;
+void C_pt_doff(label l, arith v)
 {
        char buf[16];
 
@@ -271,10 +253,7 @@ C_pt_doff(l, v)
        }
 }
 
-void
-C_pt_noff(s, v)
-       char *s;
-       arith v;
+void C_pt_noff(char *s, arith v)
 {
        char buf[16];
 
@@ -285,17 +264,13 @@ C_pt_noff(s, v)
        }
 }
 
-void
-C_pt_pnam(s)
-       char *s;
+void C_pt_pnam(char *s)
 {
        C_putbyte('$');
        wrs(s);
 }
 
-void
-C_pt_dfilb(l)
-       label l;
+void C_pt_dfilb(label l)
 {
        char buf[16];
 
@@ -303,11 +278,7 @@ C_pt_dfilb(l)
        wrs(buf);
 }
 
-void
-C_pt_wcon(sp, v, sz)   /* sp_icon, sp_ucon or sp_fcon with int repr    */
-       int sp;
-       char *v;
-       arith sz;
+void C_pt_wcon(int sp, char *v, arith sz)      /* sp_icon, sp_ucon or sp_fcon with int repr    */
 {
        int ch = sp == sp_icon ? 'I' : sp == sp_ucon ? 'U' : 'F';
 
@@ -316,18 +287,18 @@ C_pt_wcon(sp, v, sz)      /* sp_icon, sp_ucon or sp_fcon with int repr    */
        C_pt_cst(sz);
 }
 
-void
-C_pt_nl() {
+void C_pt_nl(void)
+{
        C_putbyte('\n');
 }
 
-void
-C_pt_comma() {
+void C_pt_comma(void)
+{
        C_putbyte(',');
 }
 
-void
-C_pt_ccend() { 
+void C_pt_ccend(void)
+{
        C_putbyte('?');
 }
 
@@ -345,8 +316,7 @@ C_pt_ccend() {
        names.
 */
 
-void
-C_magic()
+void C_magic(void)
 {
        put16(sp_magic);
 }
@@ -355,9 +325,7 @@ C_magic()
 #define        fit16i(x)       ((x) >= (long)(-0x8000) && (x) <= (long)0x7FFF)
 #define        fit8u(x)        ((x) <= 0xFF)           /* x is already unsigned */
 
-void
-C_pt_ilb(l)
-       register label l;
+void C_pt_ilb(register label l)
 {
        if (fit8u(l))   {
                put8(sp_ilb1);
@@ -369,9 +337,7 @@ C_pt_ilb(l)
        }
 }
 
-void
-C_pt_dlb(l)
-       register label l;
+void C_pt_dlb(register label l)
 {
        if (fit8u(l))   {
                put8(sp_dlb1);
@@ -383,9 +349,7 @@ C_pt_dlb(l)
        }
 }
 
-void
-C_pt_cst(l)
-       register arith l;
+void C_pt_cst(register arith l)
 {
        if (l >= (arith) -sp_zcst0 && l < (arith) (sp_ncst0 - sp_zcst0)) {
                /*      we can convert 'l' to an int because its value
@@ -404,10 +368,7 @@ C_pt_cst(l)
        }
 }
 
-void
-C_pt_doff(l, v)
-       label l;
-       arith v;
+void C_pt_doff(label l, arith v)
 {
        if (v == 0) {
                C_pt_dlb(l);
@@ -419,9 +380,7 @@ C_pt_doff(l, v)
        }
 }
 
-void
-C_pt_str(s)
-       register char *s;
+void C_pt_str(register char *s)
 {
        register int len;
 
@@ -431,18 +390,13 @@ C_pt_str(s)
        }
 }
 
-void
-C_pt_dnam(s)
-       char *s;
+void C_pt_dnam(char* s)
 {
        put8(sp_dnam);
        C_pt_str(s);
 }
 
-void
-C_pt_noff(s, v)
-       char *s;
-       arith v;
+void C_pt_noff(char* s, arith v)
 {
        if (v == 0) {
                C_pt_dnam(s);
@@ -454,19 +408,13 @@ C_pt_noff(s, v)
        }
 }
 
-void
-C_pt_pnam(s)
-       char *s;
+void C_pt_pnam(char* s)
 {
        put8(sp_pnam);
        C_pt_str(s);
 }
 
-void
-C_pt_wcon(sp, v, sz)   /* sp_icon, sp_ucon or sp_fcon with int repr    */
-       int sp;
-       char *v;
-       arith sz;
+void C_pt_wcon(int sp, char* v, arith sz)      /* sp_icon, sp_ucon or sp_fcon with int repr    */
 {
        /* how 'bout signextension int --> long ???     */
        put8(sp);
@@ -474,10 +422,7 @@ C_pt_wcon(sp, v, sz)       /* sp_icon, sp_ucon or sp_fcon with int repr    */
        C_pt_str(v);
 }
 
-void
-C_pt_scon(b, n)
-       register char *b;
-       register arith n;
+void C_pt_scon(register char *b, register arith n)
 {
        put8(sp_scon);
        C_pt_cst(n);
index 26a3251..028e5ba 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "em_mesX.h"
+#include "em_arith.h"
 #include "ansi.h"
 
 _PROTOTYPE(void C_ms_com, (char *));
@@ -24,6 +25,8 @@ _PROTOTYPE(void C_ms_stb_ilb, (char *, int, int, label));
 _PROTOTYPE(void C_ms_stb_pnam, (char *, int, int, char *));
 _PROTOTYPE(void C_ms_std, (char *, int, int));
 
+
+
 #ifdef PEEPHOLE
 #include "em_codeO.h"
 #include "emO_code.h"
index 45b80f5..b706d9b 100644 (file)
@@ -5,16 +5,16 @@
  */
 /* private inclusion file */
 
-#include <em_arith.h>
-#include <em_label.h>
+#include "em_arith.h"
+#include  "em_label.h"
 
 /* include the EM description files */
-#include       <em_spec.h>
-#include       <em_pseu.h>
-#include       <em_mnem.h>
-#include       <em_reg.h>
+#include       "em_spec.h"
+#include       "em_pseu.h"
+#include       "em_mnem.h"
+#include       "em_reg.h"
 
-#include       <ansi.h>
+#include       "ansi.h"
 
 #include       "em_codeEK.h"
 
@@ -79,6 +79,10 @@ _PROTOTYPE(void C_pt_noff, (char *, arith));
 _PROTOTYPE(void C_pt_pnam, (char *));
 _PROTOTYPE(void C_pt_dfilb, (label));
 _PROTOTYPE(void C_pt_wcon, (int, char *, arith));
+_PROTOTYPE(void C_failed, (void));
+_PROTOTYPE(void C_flush, (void));
+_PROTOTYPE(void C_internal_error, (void));
+_PROTOTYPE(void C_putbyte, (int));
 #ifdef READABLE_EM
 _PROTOTYPE(void C_pt_ps, (int));
 _PROTOTYPE(void C_pt_op, (int));
index b5ac649..580751a 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_end(l)
-       arith l;
+void CC_end(arith l)
 {
        /*      END pseudo of procedure with l locals
        */
index 510fc48..f2b6320 100644 (file)
@@ -2,8 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_endnarg()
+void CC_endnarg()
 {
        /*      END pseudo of procedure with unknown # of locals
        */
index 3fe2b25..905a902 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_exc(c1,c2)
-       arith c1,c2;
+void CC_exc(arith c1,arith c2)
 {
        PS(ps_exc);
        CST(c1);
index c33731f..bdd9f9e 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_fcon(val, siz)
-       char *val;
-       arith siz;
+void CC_fcon(char* val, arith siz)
 {
        COMMA();
        WCON(sp_fcon, val, siz);
index 157b7e8..f8fb1f5 100644 (file)
@@ -3,8 +3,7 @@
 /*     Get a unique id for C_insertpart, etc.
 */
 
-int
-C_getid()
+int C_getid(void)
 {
        static int id = 0;
 
index bed0886..4883829 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_icon(val, siz)
-       char *val;
-       arith siz;
+void CC_icon(char* val, arith siz)
 {
        COMMA();
        WCON(sp_icon, val, siz);
index 6c41680..b54c4bd 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_ilb(l)
-       label l;
+void CC_ilb(label l)
 {
        COMMA();
        ILB(l);
index 00c628d..2048d04 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-#include <em_path.h>
-#include <alloc.h>
+#include <stdio.h>
+#include <assert.h>
+#include "em_private.h"
+#include "system.h"
+/*#include "em_path.h"*/
+#include "alloc.h"
 #include "insert.h"
 
-char           *C_tmpdir = TMP_DIR;
+/* To make this portable, the initial value here is NULL
+ * and system is used to retrieve the correct directory
+ */
+char           *C_tmpdir = NULL;
 static Part    *C_stable[TABSIZ];
 
 static char    *C_old_top;
@@ -58,12 +65,10 @@ getbyte(b)
 }
 #endif
 
-static C_out_parts();
-static Part *C_findpart();
+static void C_out_parts(register PartOfPart *pp);
+static Part *C_findpart(int part);
 
-static
-outpart(id)
-       int id;
+static int outpart(int id)
 {
        /*      Output part "id", if present.
        */
@@ -73,11 +78,10 @@ outpart(id)
                C_out_parts(p->p_parts);
                p->p_parts = 0;
        }
+       return 0;
 }
 
-static
-C_out_parts(pp)
-       register PartOfPart *pp;
+static void C_out_parts(register PartOfPart *pp)
 {
        /*      Output the list of chunks started by "pp".
                The list is build in reverse order, so this routine is
@@ -119,9 +123,7 @@ C_out_parts(pp)
        }
 }
 
-static Part *
-C_findpart(part)
-       int part;
+static Part *C_findpart(int part)
 {
        /*      Look for part "part" in the table.
                Return 0 if not present,
@@ -134,14 +136,22 @@ C_findpart(part)
        return p;
 }
 
-static
-swttmp()
+
+
+
+static int swttmp(void)
 {
 #ifndef INCORE
-       if (C_tmpfile == 0) {
-               static char tmpbuf[64];
+       if (C_tmpfile == NULL) {
+
+               static char tmpbuf[FILENAME_MAX];
                register char *p = tmpbuf;
 
+               if (C_tmpdir == NULL)
+               {
+                       C_tmpdir = sys_gettmpdir();
+                       assert(C_tmpdir != NULL);
+               }
                strcpy(p, C_tmpdir);
                strcat(p, "/CodeXXXXXX");
                close(mkstemp(p));
@@ -175,10 +185,10 @@ swttmp()
                C_ontmpfile = 1;
        }
 #endif
+       return 0;
 }
 
-static
-swtout()
+static int swtout(void)
 {
 #ifndef INCORE
        if (C_ontmpfile) {
@@ -203,11 +213,10 @@ swtout()
                C_ontmpfile = 0;
        }
 #endif
+       return 0;
 }
 
-static int
-available(part)
-       int part;
+static int available(int part)
 {
        /*      See if part "part", and all the parts it consists of,
                are available. Return 1 if they are, 0 otherwize
@@ -240,9 +249,7 @@ available(part)
        return retval;
 }
 
-static Part *
-mkpart(part)
-       int part;
+static Part *mkpart(int part)
 {
        /*      Create a Part structure with id "part", and return a
                pointer to it, after checking that is does not exist
@@ -266,9 +273,7 @@ mkpart(part)
        return p;
 }
 
-static
-end_partofpart(p)
-       register Part *p;
+static void end_partofpart(register Part *p)
 {
        /*      End the current chunk of part *p.
        */
@@ -285,9 +290,7 @@ end_partofpart(p)
        }
 }
 
-static
-resume(p)
-       register Part *p;
+static void resume(register Part *p)
 {
        /*      Resume part "p", by creating a new PartOfPart structure
                for it.
@@ -302,9 +305,7 @@ resume(p)
        pp->pp_begin = C_current_out - C_BASE;
 }
 
-void
-C_insertpart(part)
-       int part;
+void C_insertpart(int part)
 {
        /*      Insert part "part" in the current part. If C_sequential is
                still set and the part to be inserted is available now,
@@ -341,9 +342,7 @@ C_insertpart(part)
        resume(p);
 }
 
-void
-C_beginpart(part)
-       int part;
+void C_beginpart(int part)
 {
        /*      Now follows the definition for part "part".
                Suspend the current part, and add part "part" to the
@@ -361,9 +360,7 @@ C_beginpart(part)
        resume(p);
 }
 
-void
-C_endpart(part)
-       int part;
+void C_endpart(int part)
 {
        /*      End the current part. The parameter "part" is just there
                for the checking. Do we really need it ???
index 19bd653..f77aadf 100644 (file)
@@ -3,10 +3,11 @@
  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  * See the copyright notice in the ACK home directory, in the file "Copyright".
  */
-#include <system.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "system.h"
 
-void
-C_internal_error()
+void C_internal_error(void)
 {
        sys_write(STDERR,"internal error\n",15);
        sys_stop(S_EXIT);
diff --git a/modules/src/em_code/makeem.sed b/modules/src/em_code/makeem.sed
new file mode 100644 (file)
index 0000000..8db5d8c
--- /dev/null
@@ -0,0 +1,18 @@
+1i\
+/* this part is generated from em_table */
+# Remove pseudo instructions
+/^\(...\)      \([0-9]\).*/d
+# Remove opcode constant categories/count
+/^\(....\)     \([0-9]\).*/d
+/^\(.....\)    \([0-9]\).*/d
+# Below are the actual replacement of opcodes.
+s/^\(...\)     \(d\).*/#define C_\1(c) CC_opcst(op_\1, c)/
+s/^\(...\)     \([cslnfzor]\).*/#define C_\1(c) CC_opcst(op_\1, c)/
+s/^\(...\)     \(w\).*/#define C_\1(w) CC_opcst(op_\1, w)\
+#define C_\1_narg() CC_opnarg(op_\1)/
+s/^\(...\)     \(g\).*/#define C_\1(g) CC_opcst(op_\1, g)\
+#define C_\1_dnam(g, o) CC_opdnam(op_\1, g, o)\
+#define C_\1_dlb(g, o) CC_opdlb(op_\1, g, o)/
+s/^\(...\)     \(p\).*/#define C_\1(p) CC_oppnam(op_\1, p)/
+s/^\(...\)     \(b\).*/#define C_\1(b) CC_opilb(op_\1, b)/
+s/^\(...\)     \(-\).*/#define C_\1() CC_op(op_\1)/
index f78dcae..0174594 100644 (file)
@@ -2,8 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_msend()
+void CC_msend(void)
 {
        CEND();
        NL();
index 82bc136..edc5027 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_msstart(cst)
-       int cst;
+void CC_msstart(int cst)
 {
        /*      start of message
        */
index ac03706..df98c8f 100644 (file)
@@ -2,8 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_op(opcode)
+void CC_op(int opcode)
 {
        /*      Instruction that never has an argument
                Argument types: -
index 782f15c..8f6dab3 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_opcst(opcode, cst)
-       arith cst;
+void CC_opcst(int opcode, arith cst)
 {
        /*      Instruction with a constant argument
                Argument types: c, d, l, g, f, n, s, z, o, w, r
index 59c8ed5..7df0096 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_opdlb(opcode, dlb, offset)
-       label dlb;
-       arith offset;
+void CC_opdlb(int opcode, label dlb, arith offset)
 {
        /*      Instruction that as a numeric datalabel + offset as argument
                Argument types: g
index 84fd207..640a529 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_opdnam(opcode, dnam, offset)
-       char *dnam;
-       arith offset;
+void CC_opdnam(int opcode, char* dnam, arith offset)
 {
        /*      Instruction that has a datalabel + offset as argument
                Argument types: g
index 8cecaec..637811d 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_opilb(opcode, ilb)
-       label ilb;
+void CC_opilb(int opcode, label ilb)
 {
        /*      Instruction with instruction label argument
                Argument types: b
index 241cc00..e6fada6 100644 (file)
@@ -2,8 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_opnarg(opcode)
+void CC_opnarg(int opcode)
 {
        /*      Instruction with optional argument, but now without one
                Argument types: w
index d799772..20e2038 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_oppnam(opcode, pnam)
-       char *pnam;
+void CC_oppnam(int opcode, char* pnam)
 {
        /*      Instruction that has a procedure name as argument
                Argument types: p
index 5e21a2a..e5efbfa 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_pnam(str)
-       char *str;
+void CC_pnam(char* str)
 {
        COMMA();
        PNAM(str);
index 5829a4b..20c9e25 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_pro(pnam, l)
-       char *pnam;
-       arith l;
+void CC_pro(char* pnam, arith l)
 {
        /*      PRO pseudo with procedure name pnam and # of locals l
        */
index 2204f04..9f714a4 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_pronarg(pnam)
-       char *pnam;
+void CC_pronarg(char* pnam)
 {
        /*      PRO pseudo with procedure name pnam and unknown # of locals
        */
index 73d674d..a006ab9 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_psdlb(op, dlb)
-       label dlb;
+void CC_psdlb(int op, label dlb)
 {
        /*      Pseudo with numeric datalabel
        */
index 5acf697..0581592 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_psdnam(op, dnam)
-       char *dnam;
+void CC_psdnam(int op, char* dnam)
 {
        /*      Pseudo with data label
        */
index 283fce4..cf364ff 100644 (file)
@@ -2,9 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_pspnam(op, pnam)
-       char *pnam;
+void CC_pspnam(int op, char* pnam)
 {
        /*      Pseudo with procedure name
        */
index 5c204db..b421b47 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_scon(str, siz)
-       char *str;
-       arith siz;
+void CC_scon(char* str, arith siz)
 {
        COMMA();
        SCON(str, siz);
index 4520c80..71ed045 100644 (file)
@@ -2,10 +2,7 @@
 
 /* $Id$ */
 
-void
-CC_ucon(val,siz)
-       char *val;
-       arith siz;
+void CC_ucon(char* val,arith siz)
 {
        COMMA();
        WCON(sp_ucon, val, siz);