introduced the string(3L) module
authorerikb <none@none>
Wed, 26 Mar 1986 16:58:43 +0000 (16:58 +0000)
committererikb <none@none>
Wed, 26 Mar 1986 16:58:43 +0000 (16:58 +0000)
lang/cem/cemcom/Files
lang/cem/cemcom/Makefile.erik
lang/cem/cemcom/Parameters
lang/cem/cemcom/cem.c
lang/cem/cemcom/doprnt.c [new file with mode: 0644]
lang/cem/cemcom/error.c
lang/cem/cemcom/eval.c
lang/cem/cemcom/init.c
lang/cem/cemcom/input.c
lang/cem/cemcom/ival.c
lang/cem/cemcom/replace.c

index 80cfbae..125c0c2 100644 (file)
@@ -33,6 +33,7 @@ decspecs.c
 decspecs.str
 def.str
 domacro.c
+doprnt.c
 dumpidf.c
 error.c
 eval.c
@@ -75,8 +76,6 @@ statement.g
 stb.c
 storage.c
 storage.h
-string.c
-string.h
 struct.c
 struct.str
 switch.c
index f2348fa..3fe9018 100644 (file)
@@ -10,8 +10,9 @@ EM_INCLUDES =$(EM)/h#         # directory containing EM interface definition
 # Libraries
 SYSLIB = /user1/erikb/em/lib/libsystem.a
 EMLIB = /user1/erikb/em/lib/libemk.a
+STRLIB = /user1/erikb/em/lib/libstr.a
 EMMESLIB = /user1/erikb/em/lib/libem_mes.a
-LIBS = $(EMMESLIB) $(EMLIB) $(SYSLIB)
+LIBS = $(EMMESLIB) $(EMLIB) $(STRLIB) $(SYSLIB)
 LIB_INCLUDES = /user1/erikb/em/h
 
 # Where to install the compiler and its driver
@@ -44,7 +45,7 @@ COBJ =        main.o idf.o declarator.o decspecs.o struct.o \
        input.o domacro.o replace.o init.o options.o \
        scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \
        switch.o storage.o ival.o conversion.o \
-       blocks.o dataflow.o string.o
+       blocks.o dataflow.o doprnt.o
 
 # Objects of other generated C files
 GOBJ = char.o symbol2str.o next.o
@@ -60,7 +61,7 @@ GHSRC =       botch_free.h dataflow.h debug.h density.h errout.h \
        maxincl.h myalloc.h nobitfield.h nopp.h \
        nparams.h numsize.h parbufsize.h pathlength.h predefine.h \
        strsize.h target_sizes.h textsize.h use_tmp.h \
-       str_params.h spec_arith.h
+       ssize.h spec_arith.h
 
 # Other generated files, for 'make clean' only
 GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \
@@ -81,10 +82,10 @@ cc:
        make LLfiles
        make main
 
-cem:   cem.c string.o
-       $(CC) -O cem.c string.o $(SYSLIB) -o cem
+cem:   cem.c
+       $(CC) -O cem.c $(SYSLIB) -o cem
 
-lint.cem: cem.c string.c
+lint.cem: cem.c
        lint -abx cem.c
 
 hfiles: Parameters
@@ -197,15 +198,15 @@ arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h
 alloc.o: alloc.h assert.h debug.h myalloc.h
 code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h
 dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h
-error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nopp.h spec_arith.h string.h tokenname.h use_tmp.h
+error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nopp.h spec_arith.h tokenname.h use_tmp.h
 field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h type.h
 tokenname.o: LLlex.h Lpars.h arith.h idf.h nopp.h spec_arith.h tokenname.h
 LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nopp.h numsize.h sizes.h spec_arith.h strsize.h
 LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nopp.h spec_arith.h
 input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h
 domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h
-replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h string.h strsize.h
-init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h
+replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h strsize.h
+init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h
 options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h
 scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h
 skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h
@@ -213,14 +214,14 @@ stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h
 type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h type.h
 ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h type.h
 label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nopp.h spec_arith.h type.h
-eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h string.h type.h
+eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h type.h
 switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h switch.h type.h
 storage.o: alloc.h assert.h botch_free.h debug.h storage.h
-ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h string.h struct.h type.h
+ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h
 conversion.o: Lpars.h arith.h nobitfield.h sizes.h spec_arith.h type.h
 blocks.o: arith.h atw.h sizes.h spec_arith.h
 dataflow.o: dataflow.h
-string.o: arith.h nopp.h spec_arith.h str_params.h string.h
+doprnt.o: ssize.h
 tokenfile.o: Lpars.h
 declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h
 statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h storage.h type.h
index 1ae2b45..00cae78 100644 (file)
 #undef NOBITFIELD      1       /* implement bitfields  */
 
 
-!File: str_params.h
-/* maximum number of characters in string representation of (unsigned) long
-*/
-#define MAXWIDTH 32            
-
+!File: ssize.h
 #define SSIZE  1024    /* string-buffer size for print routines        */
 
 
index f2d832f..7f8a349 100644 (file)
@@ -6,7 +6,7 @@
        Author: Erik Baalbergen
 */
        
-#include "string.h"
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
diff --git a/lang/cem/cemcom/doprnt.c b/lang/cem/cemcom/doprnt.c
new file mode 100644 (file)
index 0000000..9cdc126
--- /dev/null
@@ -0,0 +1,144 @@
+/* $Header$ */
+/* STRING MANIPULATION AND PRINT ROUTINES */
+
+#include       <system.h>
+#include       "ssize.h"
+
+char *long2str();
+
+static
+integral(c)
+{
+       switch (c) {
+       case 'b':
+               return -2;
+       case 'd':
+               return 10;
+       case 'o':
+               return -8;
+       case 'u':
+               return -10;
+       case 'x':
+               return -16;
+       }
+       return 0;
+}
+
+static int
+format(buf, fmt, argp)
+       char *buf, *fmt;
+       char *argp;
+{
+       register char *pf = fmt, *pa = argp;
+       register char *pb = buf;
+
+       while (*pf) {
+               if (*pf == '%') {
+                       register width, base, pad, npad;
+                       char *arg;
+                       char cbuf[2];
+                       char *badformat = "<bad format>";
+                       
+                       /* get padder */
+                       if (*++pf == '0') {
+                               pad = '0';
+                               ++pf;
+                       }
+                       else
+                               pad = ' ';
+                       
+                       /* get width */
+                       width = 0;
+                       while (*pf >= '0' && *pf <= '9')
+                               width = 10 * width + *pf++ - '0';
+                       
+                       /* get text and move pa */
+                       if (*pf == 's') {
+                               arg = *(char **)pa;
+                               pa += sizeof(char *);
+                       }
+                       else
+                       if (*pf == 'c') {
+                               cbuf[0] = * (char *) pa;
+                               cbuf[1] = '\0';
+                               pa += sizeof(int);
+                               arg = &cbuf[0];
+                       }
+                       else
+                       if (*pf == 'l') {
+                               /* alignment ??? */
+                               if (base = integral(*++pf)) {
+                                       arg = long2str(*(long *)pa, base);
+                                       pa += sizeof(long);
+                               }
+                               else {
+                                       pf--;
+                                       arg = badformat;
+                               }
+                       }
+                       else
+                       if (base = integral(*pf)) {
+                               arg = long2str((long)*(int *)pa, base);
+                               pa += sizeof(int);
+                       }
+                       else
+                       if (*pf == '%')
+                               arg = "%";
+                       else
+                               arg = badformat;
+
+                       npad = width - strlen(arg);
+
+                       while (npad-- > 0)
+                               *pb++ = pad;
+                       
+                       while (*pb++ = *arg++);
+                       pb--;
+                       pf++;
+               }
+               else
+                       *pb++ = *pf++;
+       }
+       return pb - buf;
+}
+
+doprnt(fp, fmt, argp)
+       File *fp;
+       char *fmt;
+       int argp[];
+{
+       char buf[SSIZE];
+
+       sys_write(fp, buf, format(buf, fmt, (char *)argp));
+}
+
+/*VARARGS1*/
+printf(fmt, args)
+       char *fmt;
+       char args;
+{
+       char buf[SSIZE];
+
+       sys_write(STDOUT, buf, format(buf, fmt, &args));
+}
+
+/*VARARGS1*/
+fprintf(fp, fmt, args)
+       File *fp;
+       char *fmt;
+       char args;
+{
+       char buf[SSIZE];
+
+       sys_write(fp, buf, format(buf, fmt, &args));
+}
+
+/*VARARGS1*/
+char *
+sprintf(buf, fmt, args)
+       char *buf, *fmt;
+       char args;
+{
+       buf[format(buf, fmt, &args)] = '\0';
+       return buf;
+}
index bbfe23d..7b1629e 100644 (file)
@@ -8,7 +8,6 @@
 #include       "use_tmp.h"
 #include       "errout.h"
 #include       "debug.h"
-#include       "string.h"
 
 #include       "tokenname.h"
 #include       "arith.h"
index ab3af1c..636e428 100644 (file)
@@ -17,7 +17,6 @@
 #include       "debug.h"
 #include       "nobitfield.h"
 
-#include       "string.h"
 #include       "dataflow.h"
 #include       "arith.h"
 #include       "type.h"
@@ -39,6 +38,7 @@
 #define        roundup(n)      ((n) < word_size ? word_size : (n))
 
 char *symbol2str();
+char *long2str();
 arith tmp_pointer_var();
 
 /*     EVAL() serves as the main expression tree evaluator, which turns
@@ -1024,7 +1024,7 @@ load_cst(val, siz)
                label datlab;
 
                C_df_dlb(datlab = data_label());
-               C_rom_icon(itos(val), siz);
+               C_rom_icon(long2str((long)val, 10), siz);
                C_lae_dlb(datlab, (arith)0);
                C_loi(siz);
        }
index bd14564..fcfe547 100644 (file)
@@ -11,7 +11,6 @@
 #include       "macro.h"
 #include       "idf.h"
 #include       "interface.h"
-#include       "string.h"
 
 PRIVATE struct mkey    {
        char *mk_reserved;
@@ -30,6 +29,8 @@ PRIVATE struct mkey   {
        {0,             K_UNKNOWN}
 };
 
+char *strcpy();
+
 EXPORT
 init_pp()
 {
index 45db437..850f7f0 100644 (file)
@@ -427,12 +427,12 @@ setwdir(wdir, fn)
        char *fn, **wdir;
 {
        register char *p;
-       char *rindex();
+       char *strrindex();
 
-       p = rindex(fn, '/');
+       p = strrindex(fn, '/');
        while (p && *(p + 1) == '\0') { /* remove trailing /'s */
                *p = '\0';
-               p = rindex(fn, '/');
+               p = strrindex(fn, '/');
        }
 
        if (fn[0] == '\0' || (fn[0] == '/' && p == &fn[0])) /* absolute path */
index d843546..cbc7fb0 100644 (file)
@@ -6,7 +6,6 @@
 #include       "debug.h"
 #include       "nobitfield.h"
 
-#include       "string.h"
 #include       "arith.h"
 #include       "align.h"
 #include       "label.h"
 #include       "level.h"
 #include       "def.h"
 
-extern char *symbol2str();
+#define con_nullbyte() C_con_ucon("0", (arith)1)
 
-#define con_byte(c)    C_con_ucon(itos((long)(c) & 0xFF), (arith)1)
+char *symbol2str();
+char *long2str();
 
 struct expr *do_array(), *do_struct(), *IVAL();
 struct expr *strings = 0; /* list of string constants within initialiser */
@@ -313,7 +313,7 @@ do_struct(expr, tp)
        }
        /* keep on aligning...  */
        while (bytes_upto_here++ < tp->tp_size)
-               con_byte(0);
+               con_nullbyte();
        return expr;
 }
 
@@ -479,7 +479,10 @@ check_ival(expr, type)
                                illegal_init_cst(expr);
                                break;
                        }
-                       C_con_fcon(itos(expr->VL_VALUE), type->tp_size);
+                       C_con_fcon(
+                               long2str((long)expr->VL_VALUE, 10),
+                               type->tp_size
+                       );
                }
                else
                        illegal_init_cst(expr);
@@ -578,11 +581,11 @@ init_string(tpp, expr)
        }
        /* throw out the characters of the already prepared string      */
        do
-               con_byte(*s++);
+               C_con_ucon(long2str((long)*s++ & 0xFF, 10), (arith)1);
        while (--length > 0);
        /* pad the allocated memory (the alignment has been calculated) */
        while (ntopad-- > 0)
-               con_byte(0);
+               con_nullbyte();
 }
 
 #ifndef NOBITFIELD
@@ -635,7 +638,7 @@ zero_bytes(sd)
        register count = n;
 
        while (n-- > 0)
-               con_byte((arith)0);
+               con_nullbyte();
        return count;
 }
 
@@ -657,9 +660,9 @@ con_int(expr)
        register struct type *tp = expr->ex_type;
 
        if (tp->tp_unsigned)
-               C_con_ucon(itos(expr->VL_VALUE), tp->tp_size);
+               C_con_ucon(long2str((long)expr->VL_VALUE, -10), tp->tp_size);
        else
-               C_con_icon(itos(expr->VL_VALUE), tp->tp_size);
+               C_con_icon(long2str((long)expr->VL_VALUE, 10), tp->tp_size);
 }
 
 illegal_init_cst(expr)
index c76b5d7..0b0f730 100644 (file)
@@ -8,7 +8,6 @@
 #include       "pathlength.h"  /* UF */
 #include       "strsize.h"     /* UF */
 
-#include       "string.h"
 #include       "alloc.h"
 #include       "idf.h"
 #include       "input.h"
@@ -19,6 +18,9 @@
 #include       "assert.h"
 #include       "interface.h"
 
+char *strcpy(), *strcat();
+char *long2str();
+
 EXPORT int
 replace(idef)
        struct idf *idef;
@@ -90,7 +92,7 @@ macro_func(idef)
                break;
 
        case 'L' :                      /* __LINE__     */
-               idef->id_macro->mc_text = itos(LineNumber);
+               idef->id_macro->mc_text = long2str((long)LineNumber, 10);
                idef->id_macro->mc_length = 1;
                break;