Pre-ansification changes for bin/csh
authorNick Downing <downing.nick@gmail.com>
Sat, 28 Jan 2017 11:40:32 +0000 (22:40 +1100)
committerNick Downing <downing.nick@gmail.com>
Sun, 29 Jan 2017 05:30:34 +0000 (16:30 +1100)
28 files changed:
bin/csh/Makefile
bin/csh/conflicts.txt [new file with mode: 0644]
bin/csh/doprnt.c
bin/csh/doprnt.c.vax [new file with mode: 0644]
bin/csh/groups.txt [new file with mode: 0644]
bin/csh/malloc.c [moved from bin/csh/alloc.c with 97% similarity]
bin/csh/printf.c
bin/csh/printf.c.vax [new file with mode: 0644]
bin/csh/sh.c
bin/csh/sh.data.c [new file with mode: 0644]
bin/csh/sh.end.c [new file with mode: 0644]
bin/csh/sh.err.c
bin/csh/sh.exec.c
bin/csh/sh.exp.c
bin/csh/sh.file.c
bin/csh/sh.func.c
bin/csh/sh.glob.c
bin/csh/sh.h
bin/csh/sh.init.c
bin/csh/sh.lex.c
bin/csh/sh.local.h
bin/csh/sh.misc.c
bin/csh/sh.proc.h
bin/csh/sh.sem.c
bin/csh/sh.set.c
lib/libc/gen/malloc.c
scripts/ansify.sh
xify/xify.c

index ac1cc5d..0ff7f3c 100644 (file)
@@ -21,45 +21,48 @@ CTAGS=      /usr/ucb/ctags
 LIBES=
 SCCS=  sccs
 
-OBJS=  alloc.o doprnt.o printf.o sh.o sh.char.o sh.dir.o sh.dol.o sh.err.o \
-       sh.exec.o sh.exp.o sh.file.o sh.func.o sh.glob.o sh.hist.o sh.init.o \
-       sh.lex.o sh.misc.o sh.parse.o sh.print.o sh.proc.o sh.sem.o sh.set.o \
-       sh.time.o
+OBJS=  malloc.o doprnt.o printf.o sh.o sh.char.o sh.data.o sh.dir.o sh.dol.o \
+       sh.err.o sh.exec.o sh.exp.o sh.file.o sh.func.o sh.glob.o sh.hist.o \
+       sh.init.o sh.lex.o sh.misc.o sh.parse.o sh.print.o sh.proc.o sh.sem.o \
+       sh.set.o sh.time.o sh.end.o
 
-# Special massaging of C files for sharing of strings
-.c.o:
-       ${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -
-       ${CC} -c ${CFLAGS} x.c 
-       mv -f x.o $*.o
-       rm -f x.c
-
-# strings.o must be last since it can change when previous files compile
-csh: ${OBJS} strings.o
-       rm -f csh
-       ${CC} ${CFLAGS} ${OBJS} strings.o -o csh ${LIBES}
-
-.DEFAULT:
-       ${SCCS} get $<
-
-# need an old doprnt, whose output we can trap
-doprnt.o: doprnt.c
-       ${CC} -E doprnt.c | ${AS} -o doprnt.o
-
-# strings.o, sh.init.o, and sh.char.o are specially processed to be shared
-strings.o: strings
-       ${XSTR}
-       ${CC} -c -R xs.c
-       mv -f xs.o strings.o
-       rm -f xs.c
-
-sh.char.o sh.init.o:
-       ${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -
-       ${CC} ${CFLAGS} -c -R x.c
-       mv -f x.o $*.o
-       rm -f x.c
+# do things the standard way for Linux hosted version, fix this properly later
+csh: ${OBJS}
+       ${CC} ${CFLAGS} ${OBJS} -o csh ${LIBES}
+## Special massaging of C files for sharing of strings
+#.c.o:
+#      ${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -
+#      ${CC} -c ${CFLAGS} x.c 
+#      mv -f x.o $*.o
+#      rm -f x.c
+#
+## strings.o must be last since it can change when previous files compile
+#csh: ${OBJS} strings.o
+#      rm -f csh
+#      ${CC} ${CFLAGS} ${OBJS} strings.o -o csh ${LIBES}
+#
+#.DEFAULT:
+#      ${SCCS} get $<
+#
+## need an old doprnt, whose output we can trap
+#doprnt.o: doprnt.c
+#      ${CC} -E doprnt.c | ${AS} -o doprnt.o
+#
+## strings.o, sh.init.o, and sh.char.o are specially processed to be shared
+#strings.o: strings
+#      ${XSTR}
+#      ${CC} -c -R xs.c
+#      mv -f xs.o strings.o
+#      rm -f xs.c
+#
+#sh.char.o sh.init.o:
+#      ${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -
+#      ${CC} ${CFLAGS} -c -R x.c
+#      mv -f x.o $*.o
+#      rm -f x.c
        
 lint:
-       lint -z ${DEFS} sh*.c alloc.c
+       lint -z ${DEFS} sh*.c malloc.c
 
 print:
        @pr READ_ME
@@ -67,7 +70,7 @@ print:
        @(size -l a.out; size *.o) | pr -h SIZES
        @${CXREF} sh*.c | pr -h XREF
        @ls -l | pr 
-       @pr sh*.h [a-rt-z]*.h sh*.c alloc.c
+       @pr sh*.h [a-rt-z]*.h sh*.c malloc.c
 
 vprint:
        @pr -l84 READ_ME TODO
@@ -76,7 +79,7 @@ vprint:
        @${CXREF} sh*.c | pr -l84 -h XREF
        @ls -l | pr -l84
        @${CXREF} sh*.c | pr -l84 -h XREF
-       @pr -l84 sh*.h [a-rt-z]*.h sh*.c alloc.c
+       @pr -l84 sh*.h [a-rt-z]*.h sh*.c malloc.c
 
 vgrind:
        @cp /dev/null index
diff --git a/bin/csh/conflicts.txt b/bin/csh/conflicts.txt
new file mode 100644 (file)
index 0000000..c59ac33
--- /dev/null
@@ -0,0 +1,22 @@
+doprnt.c stdio.h
+malloc.c stdio.h
+printf.c stdio.h
+sh.c stdio.h
+sh.data.c stdio.h
+sh.dir.c stdio.h
+sh.dol.c stdio.h
+sh.err.c stdio.h
+sh.exec.c stdio.h
+sh.exp.c stdio.h
+sh.file.c stdio.h
+sh.func.c stdio.h
+sh.glob.c stdio.h
+sh.h stdio.h
+sh.hist.c stdio.h
+sh.lex.c stdio.h
+sh.local.h stdio.h
+sh.misc.c stdio.h
+sh.print.c stdio.h
+sh.proc.c stdio.h
+sh.set.c stdio.h
+sh.time.c stdio.h
index 0144f14..3f86842 100644 (file)
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley Software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#ifndef lint
-       .ascii  "@(#)doprnt.c   5.2 (Berkeley) 6/6/85"
-#endif
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)doprnt.c   5.35 (Berkeley) 6/27/88";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <varargs.h>
+#include <stdio.h>
+#include <ctype.h>
 
-       # C library -- conversions
+/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
+#define        MAXEXP          308
+/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
+#define        MAXFRACT        39
 
-.globl __doprnt
-.globl __strout
+#define        DEFPREC         6
 
-#define flags r10
-#define literb 0
-#define liter 1
-#define ndfndb 0
-#define ndfnd 1
-#define ljustb 1
-#define ljust 2
-#define zfillb 2
-#define zfill 4
-#define precb 3
-#define prec 8
-#define psignb 4
-#define psign 16
-#define gflagb 5
-#define gflag 32
-#define width r9
-#define ndigit r8
-#define fdesc -4(fp)
-#define exp -8(fp)
-#define sign -9(fp)
-       .set one,010                    # 1.0 in floating immediate
-       .set ch.zer,'0                  # cpp doesn't like single appostrophes
+#define        BUF             (MAXEXP+MAXFRACT+1)     /* + decimal point */
+
+#if 1 /* for csh */
+#define PUTC(ch)       (void) putchar(ch);
+#else
+#define        PUTC(ch)        (void) putc(ch, fp)
+#endif
 
-       .align  1
-__doprnt:
-       .word   0xfc0                   # uses r11-r6
-       subl2 $128,sp
-       movl 4(ap),r11                  # addr of format string
-       movl 12(ap),fdesc               # output FILE ptr
-       movl 8(ap),ap                   # addr of first arg
-loop:
-       movl r11,r0                     # current point in format
-       bicl2 $liter,flags              # no literal characters yet
-L1:    movb (r11)+,width               # next character of format
-       beql L2                         # end of format string
-       cmpb width,$'%
-       beql L2                         # warning character
-       bisl2 $liter,flags              # literal character
-       jbr L1
-L2:    blbc flags,L3                   # bbc $literb,flags,L3 # no literals in format
-       pushl fdesc                     # file pointer
-       pushl $0                        # no left/right adjust
-       pushl r0                        # addr
-       subl3 r0,r11,r1                 # length
-       subl3 $1,r1,-(sp)               # % or null not part of literal
-       calls $4,__strout               # dump the literal
-L3:
-       blbs width,L4                   # % is odd; end of format?
-       ret                             # yes
+#define        ARG() \
+       _ulong = flags&LONGINT ? va_arg(argp, long) : \
+           flags&SHORTINT ? va_arg(argp, short) : va_arg(argp, int);
 
-       # htab overlaps last 16 characters of ftab
-ftab:  .byte    0, 0, 0,'c,'d,'e,'f,'g, 0, 0, 0,'+,'l,'-,'.,'o
-htab:  .byte   '0,'1,'2,'3,'4,'5,'6,'7,'8,'9,'a,'b,'c,'d,'e,'f
+#define        todigit(c)      ((c) - '0')
+#define        tochar(n)       ((n) + '0')
 
-L4:    movl sp,r5                      # reset output buffer pointer
-       clrq r9                         # width; flags ljustb,ndfndb,zfillb
-L4a:   movzbl (r11)+,r0                # supposed format
-       extzv $0,$5,r0,r1                # bottom 5 bits
-L4b:   cmpb r0,ftab[r1]                # good enough?
-       jneq L6                         # no
-L4c:   casel r1,$3,$22                 # yes
-L5:    .word charac-L5                 # c
-       .word decimal-L5                # d
-       .word scien-L5                  # e
-       .word float-L5                  # f
-       .word general-L5                # g
-       .word L6-L5                     # h
-       .word L6-L5                     # i
-       .word L6-L5                     # j
-       .word plus-L5                   # +
-       .word longorunsg-L5             # l
-       .word minus-L5                  # -
-       .word dot-L5                    # .
-       .word octal-L5                  # o
-       .word gnum0-L5                  # 0
-       .word gnum-L5                   # 1
-       .word gnum-L5                   # 2
-       .word gnum-L5                   # 3
-       .word gnum-L5                   # 4
-       .word gnum-L5                   # 5
-       .word gnum-L5                   # 6
-       .word gnum-L5                   # 7
-       .word gnum-L5                   # 8
-       .word gnum-L5                   # 9
+/* have to deal with the negative buffer count kludge */
+#define        NEGATIVE_COUNT_KLUDGE
 
-L6:    jbcs $5,r0,L4b                  # capitals same as small
-       cmpb r0,$'s
-       jeql string
-       cmpb r0,$'x
-       jeql hex
-       cmpb r0,$'u
-       jeql unsigned
-       cmpb r0,$'r
-       jeql remote
-       movzbl -1(r11),r0               # orginal "format" character
-       cmpb r0,$'*
-       jeql indir
-L9:    movb r0,(r5)+                   # print the unfound character
-       jbr prbuf
+#define        LONGINT         0x01            /* long integer */
+#define        LONGDBL         0x02            /* long double; unimplemented */
+#define        SHORTINT        0x04            /* short integer */
+#define        ALT             0x08            /* alternate form */
+#define        LADJUST         0x10            /* left adjustment */
+#define        ZEROPAD         0x20            /* zero (as opposed to blank) pad */
+#define        HEXPREFIX       0x40            /* add 0x or 0X prefix */
 
-nulstr:
-       .byte '(,'n,'u,'l,'l,'),0
+_doprnt(fmt0, argp/*, fp*/)
+       u_char *fmt0;
+       va_list argp;
+       /*register FILE *fp;*/
+{
+       register u_char *fmt;   /* format string */
+       register int ch;        /* character from fmt */
+       register int cnt;       /* return value accumulator */
+       register int n;         /* random handy integer */
+       register char *t;       /* buffer pointer */
+       double _double;         /* double precision arguments %[eEfgG] */
+       u_long _ulong;          /* integer arguments %[diouxX] */
+       int base;               /* base for [diouxX] conversion */
+       int dprec;              /* decimal precision in [diouxX] */
+       int fieldsz;            /* field size expanded by sign, etc */
+       int flags;              /* flags as above */
+       int fpprec;             /* `extra' floating precision in [eEfgG] */
+       int prec;               /* precision from format (%.3d), or -1 */
+       int realsz;             /* field size expanded by decimal precision */
+       int size;               /* size of converted field or string */
+       int width;              /* width from format (%8d), or 0 */
+       char sign;              /* sign prefix (' ', '+', '-', or \0) */
+       char softsign;          /* temporary negative sign for floats */
+       char *digs;             /* digits for [diouxX] conversion */
+       char buf[BUF];          /* space for %c, %[diouxX], %[eEfgG] */
 
-string:
-       movl ndigit,r0
-       jbs $precb,flags,L20            # max length was specified
-       mnegl $1,r0                     # default max length
-L20:   movl (ap)+,r2                   # addr first byte
-       bneq L21
-       movab nulstr,r2
-L21:   locc $0,r0,(r2)                 # find the zero at the end
-       movl r1,r5                      # addr last byte +1
-       movl r2,r1                      # addr first byte
-       jbr prstr
+#if 0 /* for csh */
+       if (fp->_flag & _IORW) {
+               fp->_flag |= _IOWRT;
+               fp->_flag &= ~(_IOEOF|_IOREAD);
+       }
+       if ((fp->_flag & _IOWRT) == 0)
+               return (EOF);
+#endif
 
+       fmt = fmt0;
+       digs = "0123456789abcdef";
+       for (cnt = 0;; ++fmt) {
+#if 1 /* for csh */
+               for (; (ch = *fmt) && ch != '%'; ++fmt)
+                       PUTC(ch);
+#else
+               n = fp->_cnt;
+               for (t = (char *)fp->_ptr; (ch = *fmt) && ch != '%';
+                    ++cnt, ++fmt)
+                       if (--n < 0
+#ifdef NEGATIVE_COUNT_KLUDGE
+                           && (!(fp->_flag & _IOLBF) || -n >= fp->_bufsiz)
+#endif
+                           || ch == '\n' && fp->_flag & _IOLBF) {
+                               fp->_cnt = n;
+                               fp->_ptr = t;
+                               (void) _flsbuf((u_char)ch, fp);
+                               n = fp->_cnt;
+                               t = (char *)fp->_ptr;
+                       } else
+                               *t++ = ch;
+               fp->_cnt = n;
+               fp->_ptr = t;
+#endif
+               if (!ch)
+                       return (cnt);
 
-longorunsg:
-       movb (r11)+,r0
-       cmpb r0,$'o
-       jeql loct
-       cmpb r0,$'x
-       jeql lhex
-       cmpb r0,$'d
-       jeql long
-       cmpb r0,$'u
-       jeql lunsigned
-       decl r11
-       jbr unsigned
+               flags = 0; dprec = 0; fpprec = 0; width = 0;
+               prec = -1;
+               sign = '\0';
 
-loct:
-octal:
-       movl $30,r2                     # init position
-       movl $3,r3                      # field width
-       movl $10,r4                     # result length -1
-       jbr L10
+rflag:         switch (*++fmt) {
+               case ' ':
+                       /*
+                        * ``If the space and + flags both appear, the space
+                        * flag will be ignored.''
+                        *      -- ANSI X3J11
+                        */
+                       if (!sign)
+                               sign = ' ';
+                       goto rflag;
+               case '#':
+                       flags |= ALT;
+                       goto rflag;
+               case '*':
+                       /*
+                        * ``A negative field width argument is taken as a
+                        * - flag followed by a  positive field width.''
+                        *      -- ANSI X3J11
+                        * They don't exclude field widths read from args.
+                        */
+                       if ((width = va_arg(argp, int)) >= 0)
+                               goto rflag;
+                       width = -width;
+                       /* FALLTHROUGH */
+               case '-':
+                       flags |= LADJUST;
+                       goto rflag;
+               case '+':
+                       sign = '+';
+                       goto rflag;
+               case '.':
+                       if (*++fmt == '*')
+                               n = va_arg(argp, int);
+                       else {
+                               n = 0;
+                               while (isascii(*fmt) && isdigit(*fmt))
+                                       n = 10 * n + todigit(*fmt++);
+                               --fmt;
+                       }
+                       prec = n < 0 ? -1 : n;
+                       goto rflag;
+               case '0':
+                       /*
+                        * ``Note that 0 is taken as a flag, not as the
+                        * beginning of a field width.''
+                        *      -- ANSI X3J11
+                        */
+                       flags |= ZEROPAD;
+                       goto rflag;
+               case '1': case '2': case '3': case '4':
+               case '5': case '6': case '7': case '8': case '9':
+                       n = 0;
+                       do {
+                               n = 10 * n + todigit(*fmt);
+                       } while (isascii(*++fmt) && isdigit(*fmt));
+                       width = n;
+                       --fmt;
+                       goto rflag;
+               case 'L':
+                       flags |= LONGDBL;
+                       goto rflag;
+               case 'h':
+                       flags |= SHORTINT;
+                       goto rflag;
+               case 'l':
+                       flags |= LONGINT;
+                       goto rflag;
+               case 'c':
+                       *(t = buf) = va_arg(argp, int);
+                       size = 1;
+                       sign = '\0';
+                       goto pforw;
+               case 'D':
+                       flags |= LONGINT;
+                       /*FALLTHROUGH*/
+               case 'd':
+               case 'i':
+                       ARG();
+                       if ((long)_ulong < 0) {
+                               _ulong = -_ulong;
+                               sign = '-';
+                       }
+                       base = 10;
+                       goto number;
+               case 'e':
+               case 'E':
+               case 'f':
+               case 'g':
+               case 'G':
+                       _double = va_arg(argp, double);
+                       /*
+                        * don't do unrealistic precision; just pad it with
+                        * zeroes later, so buffer size stays rational.
+                        */
+                       if (prec > MAXFRACT) {
+                               if (*fmt != 'g' && *fmt != 'G' || (flags&ALT))
+                                       fpprec = prec - MAXFRACT;
+                               prec = MAXFRACT;
+                       }
+                       else if (prec == -1)
+                               prec = DEFPREC;
+                       /*
+                        * softsign avoids negative 0 if _double is < 0 and
+                        * no significant digits will be shown
+                        */
+                       if (_double < 0) {
+                               softsign = '-';
+                               _double = -_double;
+                       }
+                       else
+                               softsign = 0;
+                       /*
+                        * cvt may have to round up past the "start" of the
+                        * buffer, i.e. ``intf("%.2f", (double)9.999);'';
+                        * if the first char isn't NULL, it did.
+                        */
+                       *buf = NULL;
+                       size = cvt(_double, prec, flags, &softsign, *fmt, buf,
+                           buf + sizeof(buf));
+                       if (softsign)
+                               sign = '-';
+                       t = *buf ? buf : buf + 1;
+                       goto pforw;
+               case 'n':
+                       if (flags & LONGINT)
+                               *va_arg(argp, long *) = cnt;
+                       else if (flags & SHORTINT)
+                               *va_arg(argp, short *) = cnt;
+                       else
+                               *va_arg(argp, int *) = cnt;
+                       break;
+               case 'O':
+                       flags |= LONGINT;
+                       /*FALLTHROUGH*/
+               case 'o':
+                       ARG();
+                       base = 8;
+                       goto nosign;
+               case 'p':
+                       /*
+                        * ``The argument shall be a pointer to void.  The
+                        * value of the pointer is converted to a sequence
+                        * of printable characters, in an implementation-
+                        * defined manner.''
+                        *      -- ANSI X3J11
+                        */
+                       /* NOSTRICT */
+                       _ulong = (u_long)va_arg(argp, void *);
+                       base = 16;
+                       goto nosign;
+               case 's':
+                       if (!(t = va_arg(argp, char *)))
+                               t = "(null)";
+                       if (prec >= 0) {
+                               /*
+                                * can't use strlen; can only look for the
+                                * NUL in the first `prec' characters, and
+                                * strlen() will go further.
+                                */
+                               char *p;
+                               void *memchr();
 
-lhex:
-hex:
-       movl $28,r2                     # init position
-       movl $4,r3                      # field width
-       movl $7,r4                      # result length -1
-L10:   mnegl r3,r6                     # increment
-       clrl r1
-       movl (ap)+,r0                   # fetch arg
-L11:   extzv r2,r3,r0,r1               # pull out a digit
-       movb htab[r1],(r5)+             # convert to character
-L12:   acbl $0,r6,r2,L11               # continue until done
-       clrb (r5)                       # flag end
-       skpc $'0,r4,(sp)                # skip over leading zeroes
-       jbr prstr
+                               if (p = (char *)memchr(t, 0, prec)) {
+                                       size = p - t;
+                                       if (size > prec)
+                                               size = prec;
+                               } else
+                                       size = prec;
+                       } else
+                               size = strlen(t);
+                       sign = '\0';
+                       goto pforw;
+               case 'U':
+                       flags |= LONGINT;
+                       /*FALLTHROUGH*/
+               case 'u':
+                       ARG();
+                       base = 10;
+                       goto nosign;
+               case 'X':
+                       digs = "0123456789ABCDEF";
+                       /* FALLTHROUGH */
+               case 'x':
+                       ARG();
+                       base = 16;
+                       /* leading 0x/X only if non-zero */
+                       if (flags & ALT && _ulong != 0)
+                               flags |= HEXPREFIX;
 
-patdec:                                        # editpc pattern for decimal printing
-       .byte 0xA9                      # eo$float 9
-       .byte 0x01                      # eo$end_float
-       .byte 0x91                      # eo$move 1
-       .byte 0                         # eo$end
+                       /* unsigned conversions */
+nosign:                        sign = '\0';
+                       /*
+                        * ``... diouXx conversions ... if a precision is
+                        * specified, the 0 flag will be ignored.''
+                        *      -- ANSI X3J11
+                        */
+number:                        if ((dprec = prec) >= 0)
+                               flags &= ~ZEROPAD;
 
-long:
-decimal:
-       cvtlp (ap)+,$10,(sp)            # 10 digits max
-L14:   editpc $10,(sp),patdec,8(sp)    # ascii at 8(sp); r5=end+1
-       skpc $' ,$10,8(sp)              # skip leading blanks; r1=first
+                       /*
+                        * ``The result of converting a zero value with an
+                        * explicit precision of zero is no characters.''
+                        *      -- ANSI X3J11
+                        */
+                       t = buf + BUF;
+                       if (_ulong != 0 || prec != 0) {
+                               do {
+                                       *--t = digs[_ulong % base];
+                                       _ulong /= base;
+                               } while (_ulong);
+                               digs = "0123456789abcdef";
+                               if (flags & ALT && base == 8 && *t != '0')
+                                       *--t = '0'; /* octal leading 0 */
+                       }
+                       size = buf + BUF - t;
 
-prstr:                 # r1=addr first byte; r5=addr last byte +1
-       cvtbl $' ,-(sp)                 # blank fill
-       jbc $zfillb,flags,L15
-       cvtbl $'0,(sp)                  # zero fill
-L15:   pushl fdesc                     # FILE
-       subl2 r1,r5                     # r5=actual length=end+1-first
-       subl3 r5,width,r0               # if >0, how much to fill
-       bgeq L24
-       clrl r0                         # no fill
-L24:   jbs $ljustb,flags,L25
-       mnegl r0,r0
-L25:   pushl r0                        # fill count
-       pushl r1                        # addr first byte
-       pushl r5                        # length
-       calls $5,__strout
-       jbr     loop
+pforw:
+                       /*
+                        * All reasonable formats wind up here.  At this point,
+                        * `t' points to a string which (if not flags&LADJUST)
+                        * should be padded out to `width' places.  If
+                        * flags&ZEROPAD, it should first be prefixed by any
+                        * sign or other prefix; otherwise, it should be blank
+                        * padded before the prefix is emitted.  After any
+                        * left-hand padding and prefixing, emit zeroes
+                        * required by a decimal [diouxX] precision, then print
+                        * the string proper, then emit zeroes required by any
+                        * leftover floating precision; finally, if LADJUST,
+                        * pad with blanks.
+                        */
 
-pone:  .byte   0x1C                    # packed 1
-       
-unsigned:
-lunsigned:
-       extzv $1,$31,(ap),r0            # right shift logical 1 bit
-       cvtlp r0,$10,(sp)               # convert [n/2] to packed
-       movp $10,(sp),8(sp)             # copy packed
-       addp4 $10,8(sp),$10,(sp)        # 2*[n/2] in packed, at (sp)
-       blbc (ap)+,L14                  # n was even
-       addp4 $1,pone,$10,(sp)          # n was odd
-       jbr L14
+                       /*
+                        * compute actual size, so we know how much to pad
+                        * fieldsz excludes decimal prec; realsz includes it
+                        */
+                       fieldsz = size + fpprec;
+                       if (sign)
+                               fieldsz++;
+                       if (flags & HEXPREFIX)
+                               fieldsz += 2;
+                       realsz = dprec > fieldsz ? dprec : fieldsz;
 
-charac:
-       movl $4,r0                      # chars per word
-L18:   movb (ap)+,(r5)+                # transfer char
-       bneq L19
-       decl r5                         # omit null characters
-L19:   sobgtr r0,L18
+                       /* right-adjusting blank padding */
+                       if ((flags & (LADJUST|ZEROPAD)) == 0 && width)
+                               for (n = realsz; n < width; n++)
+                                       PUTC(' ');
+                       /* prefix */
+                       if (sign)
+                               PUTC(sign);
+                       if (flags & HEXPREFIX) {
+                               PUTC('0');
+                               PUTC((char)*fmt);
+                       }
+                       /* right-adjusting zero padding */
+                       if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
+                               for (n = realsz; n < width; n++)
+                                       PUTC('0');
+                       /* leading zeroes from decimal precision */
+                       for (n = fieldsz; n < dprec; n++)
+                               PUTC('0');
 
-prbuf:
-       movl sp,r1                      # addr first byte
-       jbr prstr
+                       /* the string or number proper */
+#if 0 /* for csh */
+                       if (fp->_cnt - (n = size) >= 0 &&
+                           (fp->_flag & _IOLBF) == 0) {
+                               fp->_cnt -= n;
+                               bcopy(t, (char *)fp->_ptr, n);
+                               fp->_ptr += n;
+                       } else
+#endif
+                               while (--n >= 0)
+                                       PUTC(*t++);
+                       /* trailing f.p. zeroes */
+                       while (--fpprec >= 0)
+                               PUTC('0');
+                       /* left-adjusting padding (always blank) */
+                       if (flags & LADJUST)
+                               for (n = realsz; n < width; n++)
+                                       PUTC(' ');
+                       /* finally, adjust cnt */
+                       cnt += width > realsz ? width : realsz;
+                       break;
+               case '\0':      /* "%?" prints ?, unless ? is NULL */
+                       return (cnt);
+               default:
+                       PUTC((char)*fmt);
+                       cnt++;
+               }
+       }
+       /* NOTREACHED */
+}
 
-plus:  bisl2 $psign,flags              # always print sign for floats
-       jbr L4a
-minus: bisl2 $ljust,flags              # left justification, please
-       jbr L4a
-gnum0: jbs $ndfndb,flags,gnum
-       jbs $precb,flags,gnump          # ignore when reading precision
-       bisl2 $zfill,flags              # leading zero fill, please
-gnum:  jbs $precb,flags,gnump
-       moval (width)[width],width      # width *= 5;
-       movaw -ch.zer(r0)[width],width  # width = 2*witdh + r0 - '0';
-       jbr gnumd
-gnump: moval (ndigit)[ndigit],ndigit   # ndigit *= 5;
-       movaw -ch.zer(r0)[ndigit],ndigit # ndigit = 2*ndigit + r0 - '0';
-gnumd: bisl2 $ndfnd,flags              # digit seen
-       jbr L4a
-dot:   clrl ndigit                     # start on the precision
-       bisl2 $prec,flags
-       bicl2 $ndfnd,flags
-       jbr L4a
-indir: movl (ap)+,ndigit               # width specified by parameter
-       jbr gnumd
-remote:        movl (ap)+,ap
-       movl (ap)+,r11
-       jbr loop
+static
+cvt(number, prec, flags, signp, fmtch, startp, endp)
+       double number;
+       register int prec;
+       int flags;
+       u_char fmtch;
+       char *signp, *startp, *endp;
+{
+       register char *p, *t;
+       register double fract;
+       int dotrim, expcnt, gformat;
+       double integer, tmp, modf();
+       char *exponent(), *round();
 
-float:
-       bsbw fltcvt
-fltg:  jbs $ndfndb,flags,float1
-       movl $6,ndigit                  # default # digits to right of decpt.
-float1:        addl3 exp,ndigit,r7
-       movl r7,r6                      # for later "underflow" checking
-       bgeq fxplrd
-       clrl r7                         # poor programmer planning
-fxplrd:        cmpl r7,$31                     # expressible in packed decimal?
-       bleq fnarro                     # yes
-       movl $31,r7
-fnarro:        subl3 $17,r7,r0                 # where to round
-       ashp r0,$17,(sp),$5,r7,16(sp)   # do it
-       bvc fnovfl
-       # band-aid for microcode error (spurious overflow)
-       clrl r0                         # assume even length result
-       jlbc r7,fleven                  # right
-       movl $4,r0                      # odd length result
-fleven:        cmpv r0,$4,16(sp),$0            # top digit zero iff true overflow
-       bneq fnovfl
-       # end band-aid
-       aobleq $0,r6,fnovfl             # if "underflow" then jump
-       movl r7,r0
-       incl exp
-       incl r7
-       ashp r0,$1,pone,$0,r7,16(sp)
-       ashl $-1,r7,r0                  # displ to last byte
-       bisb2 sign,16(sp)[r0]           # insert sign
-fnovfl:
-       movc3 $4,patsci,(sp)
-       clrl r6                         # # digits moved so far
-       movl exp,r0
-       bleq fexpng
-       bsbb patmov                     # digits to left of decpt.
-fexpng:        tstl ndigit
-       jeql fnodp
-       movc3 $2,fpatdp,(r3)
-       tstl exp
-       bgeq fxppos
-       addl3 exp,ndigit,r6
-       bgeq  flfakl
-       clrl r6                         # it's all fill
-flfakl:        subl3 r6,$31,r6                 # fake length for patmov
-flfill:        movc3 $2,fpatzf,(r3)            # zero fill to right of dec.pt
-fxppos:        movl ndigit,r0
-       bsbb patmov
-fnodp: sobgeq r6,fledit                # must move at least 1 digit
-       movl $31,r6                     # none moved; fake it
-       aobleq $1,ndigit,flfill         # with a one-character zero fill
-fledit:        editpc r7,16(sp),(sp),32(sp)
-       jbr prflt
+       dotrim = expcnt = gformat = 0;
+       fract = modf(number, &integer);
 
-patexp:        .byte   0x03                    # eo$set_signif
-       .byte   0x44,'e                 # eo$insert 'e
-       .byte   0x42,'+                 # eo$load_plus '+
-       .byte   0x04                    # eo$store_sign
-       .byte   0x92                    # eo$move 2
-       .byte   0                       # eo$end
-patsci:        .byte   0x42,'+                 # eo$load_plus '+
-       .byte   0x03                    # eo$set_signif
-       .byte   0x04                    # eo$store_sign
-       .byte   0x91                    # eo$move 1
-fpatdp:        .byte   0x44,'.                 # eo$insert '.
-fpatzf:        .byte   0x40,'0                 # eo$load_fill '0
+       /* get an extra slot for rounding. */
+       t = ++startp;
 
-       # construct pattern at (r3) to move  r0  digits in  editpc;
-       #  r6  digits already moved for this number
-patmov:
-       movb $0x90,r2                   # eo$move
-       subl3 r6,$31,r1                 # # digits remaining in packed
-       addl2 r0,r6
-       cmpl r0,r1                      # enough digits remaining?
-       bleq patsml                     # yes
-       tstl exp                        # zero 'fill'; before or after rest?
-       bgeq pataft                     # after
-       pushl r1                        # # digits remaining
-       movb $0x80,r2                   # eo$fill
-       subl3 $31,r6,r0                 # number of fill bytes
-       bsbb patsml                     # recursion!
-       movl (sp)+,r0
-       movb $0x90,r2                   # eo$move
-       jbr patsml
-pataft:        movl r1,r0                      # last of the 31
-       bsbb patsml                     # recursion!
-       subl3 $31,r6,r0                 # number of fill bytes
-       movb $0x80,r2                   # eo$fill
-patsml:        tstl r0
-       bleq patzer                     # DEC doesn't like repetition counts of 0
-       mnegl $15,r1                    # 15 digits at a time
-       subl2 r1,r0                     # counteract acbl
-       jbr pattst
-patmlp:        bisb3 r2,$15,(r3)+              # 15
-pattst:        acbl $16,r1,r0,patmlp           # until <= 15 left
-       bisb3 r2,r0,(r3)+               # rest
-patzer:        clrb (r3)                       # eo$end
-       rsb
+       /*
+        * get integer portion of number; put into the end of the buffer; the
+        * .01 is added for modf(356.0 / 10, &integer) returning .59999999...
+        */
+       for (p = endp - 1; integer; ++expcnt) {
+               tmp = modf(integer / 10, &integer);
+               *p-- = tochar((int)((tmp + .01) * 10));
+       }
+       switch(fmtch) {
+       case 'f':
+               /* reverse integer into beginning of buffer */
+               if (expcnt)
+                       for (; ++p < endp; *t++ = *p);
+               else
+                       *t++ = '0';
+               /*
+                * if precision required or alternate flag set, add in a
+                * decimal point.
+                */
+               if (prec || flags&ALT)
+                       *t++ = '.';
+               /* if requires more precision and some fraction left */
+               if (fract) {
+                       if (prec)
+                               do {
+                                       fract = modf(fract * 10, &tmp);
+                                       *t++ = tochar((int)tmp);
+                               } while (--prec && fract);
+                       if (fract)
+                               startp = round(fract, (int *)NULL, startp,
+                                   t - 1, (char)0, signp);
+               }
+               for (; prec--; *t++ = '0');
+               break;
+       case 'e':
+       case 'E':
+eformat:       if (expcnt) {
+                       *t++ = *++p;
+                       if (prec || flags&ALT)
+                               *t++ = '.';
+                       /* if requires more precision and some integer left */
+                       for (; prec && ++p < endp; --prec)
+                               *t++ = *p;
+                       /*
+                        * if done precision and more of the integer component,
+                        * round using it; adjust fract so we don't re-round
+                        * later.
+                        */
+                       if (!prec && ++p < endp) {
+                               fract = 0;
+                               startp = round((double)0, &expcnt, startp,
+                                   t - 1, *p, signp);
+                       }
+                       /* adjust expcnt for digit in front of decimal */
+                       --expcnt;
+               }
+               /* until first fractional digit, decrement exponent */
+               else if (fract) {
+                       /* adjust expcnt for digit in front of decimal */
+                       for (expcnt = -1;; --expcnt) {
+                               fract = modf(fract * 10, &tmp);
+                               if (tmp)
+                                       break;
+                       }
+                       *t++ = tochar((int)tmp);
+                       if (prec || flags&ALT)
+                               *t++ = '.';
+               }
+               else {
+                       *t++ = '0';
+                       if (prec || flags&ALT)
+                               *t++ = '.';
+               }
+               /* if requires more precision and some fraction left */
+               if (fract) {
+                       if (prec)
+                               do {
+                                       fract = modf(fract * 10, &tmp);
+                                       *t++ = tochar((int)tmp);
+                               } while (--prec && fract);
+                       if (fract)
+                               startp = round(fract, &expcnt, startp,
+                                   t - 1, (char)0, signp);
+               }
+               /* if requires more precision */
+               for (; prec--; *t++ = '0');
 
-scien:
-       bsbw fltcvt                     # get packed digits
-scig:  incl ndigit
-       jbs $ndfndb,flags,L23
-       movl $7,ndigit
-L23:   subl3 $17,ndigit,r0             # rounding position
-       ashp r0,$17,(sp),$5,ndigit,16(sp) # shift and round
-       bvc snovfl
-       # band-aid for microcode error (spurious overflow)
-       clrl r0                         # assume even length result
-       jlbc ndigit,sceven              # right
-       movl $4,r0                      # odd length result
-sceven:        cmpv r0,$4,16(sp),$0            # top digit zero iff true overflow
-       bneq snovfl
-       # end band-aid
-       incl exp                        # rounding overflowed to 100...
-       subl3 $1,ndigit,r0
-       ashp r0,$1,pone,$0,ndigit,16(sp)
-       ashl $-1,ndigit,r0              # displ to last byte
-       bisb2 sign,16(sp)[r0]           # insert sign
-snovfl:
-       jbc $gflagb,flags,enotg         # not %g format
- # find trailing zeroes in packed number
-       ashl $-1,ndigit,r0
-       addl2 r3,r0                     # addr of l.s.digit and sign
-       movl $4,r1                      # bit position of digit
-       movl ndigit,r7                  # current length of packed
-       jbr gtz
-gtz1:  xorl2 $4,r1                     # position of next digit
-       bneq gtz                        # same byte
-       decl r0                         # different byte
-gtz:   cmpv r1,$4,(r0),$0              # a trailing zero?
-       jneq gntz
-       sobgtr r7,gtz1
-       incl r7
-gntz:                                  # r7: minimum width of fraction
-       cmpl exp,$-4
-       jleq eg                         # small exponents use %e
-       subl3 r7,exp,r0
-       cmpl $5,r0
-       jleq eg                         # so do (w+5) <= exp
-       tstl r0                         # rest use %f
-       jleq fg                         # did we trim too many trailing zeroes?
-       movl exp,r7                     # yes
-fg:    subl3 ndigit,r7,r0
-       ashp r0,ndigit,16(sp),$0,r7,(sp)
-       movp r7,(sp),16(sp)
-       subl3 exp,r7,ndigit             # correct ndigit for %f
-       jbr fnovfl
-eg:    subl3 ndigit,r7,r0
-       ashp r0,ndigit,16(sp),$0,r7,(sp)
-       movp r7,(sp),16(sp)
-       movl r7,ndigit                  # packed number has been trimmed
-enotg:
-       movc3 $7,patsci,(sp)
-       movl $1,r6                      # 1P
-       subl3 $1,ndigit,r0              # digits after dec.pt
-       bsbw patmov
-       editpc ndigit,16(sp),(sp),32(sp)        # 32(sp)->result, r5->(end+1)
-       decl exp                        # compensate: 1 digit left of dec.pt
-       cvtlp exp,$2,(sp)               # exponent
-       editpc $2,(sp),patexp,(r5)
-prflt: movab 32(sp),r1
-       jbs $psignb,flags,prflt1
-       cmpb (r1)+,$'+
-       beql prflt1
-       decl r1
-prflt1:        skpc $' ,$63,(r1)
-       jbr prstr
+               /* unless alternate flag, trim any g/G format trailing 0's */
+               if (gformat && !(flags&ALT)) {
+                       while (t > startp && *--t == '0');
+                       if (*t == '.')
+                               --t;
+                       ++t;
+               }
+               t = exponent(t, expcnt, fmtch);
+               break;
+       case 'g':
+       case 'G':
+               /* a precision of 0 is treated as a precision of 1. */
+               if (!prec)
+                       ++prec;
+               /*
+                * ``The style used depends on the value converted; style e
+                * will be used only if the exponent resulting from the
+                * conversion is less than -4 or greater than the precision.''
+                *      -- ANSI X3J11
+                */
+               if (expcnt > prec || !expcnt && fract && fract < .0001) {
+                       /*
+                        * g/G format counts "significant digits, not digits of
+                        * precision; for the e/E format, this just causes an
+                        * off-by-one problem, i.e. g/G considers the digit
+                        * before the decimal point significant and e/E doesn't
+                        * count it as precision.
+                        */
+                       --prec;
+                       fmtch -= 2;             /* G->E, g->e */
+                       gformat = 1;
+                       goto eformat;
+               }
+               /*
+                * reverse integer into beginning of buffer,
+                * note, decrement precision
+                */
+               if (expcnt)
+                       for (; ++p < endp; *t++ = *p, --prec);
+               else
+                       *t++ = '0';
+               /*
+                * if precision required or alternate flag set, add in a
+                * decimal point.  If no digits yet, add in leading 0.
+                */
+               if (prec || flags&ALT) {
+                       dotrim = 1;
+                       *t++ = '.';
+               }
+               else
+                       dotrim = 0;
+               /* if requires more precision and some fraction left */
+               if (fract) {
+                       if (prec) {
+                               do {
+                                       fract = modf(fract * 10, &tmp);
+                                       *t++ = tochar((int)tmp);
+                               } while(!tmp);
+                               while (--prec && fract) {
+                                       fract = modf(fract * 10, &tmp);
+                                       *t++ = tochar((int)tmp);
+                               }
+                       }
+                       if (fract)
+                               startp = round(fract, (int *)NULL, startp,
+                                   t - 1, (char)0, signp);
+               }
+               /* alternate format, adds 0's for precision, else trim 0's */
+               if (flags&ALT)
+                       for (; prec--; *t++ = '0');
+               else if (dotrim) {
+                       while (t > startp && *--t == '0');
+                       if (*t != '.')
+                               ++t;
+               }
+       }
+       return(t - startp);
+}
 
-general:
-       jbcs $gflagb,flags,scien
-       jbr scien                       # safety net
+static char *
+round(fract, exp, start, end, ch, signp)
+       double fract;
+       int *exp;
+       register char *start, *end;
+       char ch, *signp;
+{
+       double tmp;
 
-       # convert double-floating at (ap) to 17-digit packed at (sp),
-       # set 'sign' and 'exp', advance ap.
-fltcvt:
-       clrb sign
-       movd (ap)+,r5
-       jeql fzero
-       bgtr fpos
-       mnegd r5,r5
-       incb sign
-fpos:
-       extzv $7,$8,r5,r2               # exponent of 2
-       movaw -0600(r2)[r2],r2          # unbias and mult by 3
-       bgeq epos
-       subl2 $9,r2
-epos:  divl2 $10,r2
-       bsbb expten
-       cmpd r0,r5
-       bgtr ceil
-       incl r2
-ceil:  movl r2,exp
-       mnegl r2,r2
-       cmpl r2,$29                     # 10^(29+9) is all we can handle
-       bleq getman
-       muld2 ten16,r5
-       subl2 $16,r2
-getman:        addl2 $9,r2                     # -ceil(log10(x)) + 9
-       bsbb expten
-       emodd r0,r4,r5,r0,r5            # (r0+r4)*r5; r0=int, r5=frac
-fz1:   cvtlp r0,$9,16(sp)              # leading 9 digits
-       ashp $8,$9,16(sp),$0,$17,4(sp)  # as top 9 of 17
-       emodd ten8,$0,r5,r0,r5
-       cvtlp r0,$8,16(sp)              # trailing 8 digits
-       addp4 $8,16(sp),$17,4(sp)       # combine leading and trailing
-       bisb2 sign,12(sp)               # and insert sign
-       rsb
-fzero: clrl r0
-       movl $1,exp             # 0.000e+00 and 0.000 rather than 0.000e-01 and .000
-       jbr fz1
+       if (fract)
+               (void)modf(fract * 10, &tmp);
+       else
+               tmp = todigit(ch);
+       if (tmp > 4)
+               for (;; --end) {
+                       if (*end == '.')
+                               --end;
+                       if (++*end <= '9')
+                               break;
+                       *end = '0';
+                       if (end == start) {
+                               if (exp) {      /* e/E; increment exponent */
+                                       *end = '1';
+                                       ++*exp;
+                               }
+                               else {          /* f; add extra digit */
+                                       *--end = '1';
+                                       --start;
+                               }
+                               break;
+                       }
+               }
+       /* ``"%.3f", (double)-0.0004'' gives you a negative 0. */
+       else if (*signp == '-')
+               for (;; --end) {
+                       if (*end == '.')
+                               --end;
+                       if (*end != '0')
+                               break;
+                       if (end == start)
+                               *signp = 0;
+               }
+       return(start);
+}
 
-       # return 10^r2 as a double float in r0||r1 and 8 extra bits of precision in r4
-       # preserve r2, r5||r6
-expten:
-       movd $one,r0                    # begin computing 10^exp10
-       clrl r4                         # bit counter
-       movad ten1,r3                   # table address
-       tstl r2
-       bgeq e10lp
-       mnegl r2,r2                     # get absolute value
-       jbss $6,r2,e10lp                # flag as negative
-e10lp: jbc r4,r2,el1                   # want this power?
-       muld2 (r3),r0                   # yes
-el1:   addl2 $8,r3                     # advance to next power
-       aobleq $5,r4,e10lp              # through 10^32
-       jbcc $6,r2,el2                  # correct for negative exponent
-       divd3 r0,$one,r0                # by taking reciprocal
-       mnegl r2,r2
-el2:   clrl r4                         # 8 extra bits of precision
-       rsb
+static char *
+exponent(p, exp, fmtch)
+       register char *p;
+       register int exp;
+       u_char fmtch;
+{
+       register char *t;
+       char expbuf[MAXEXP];
 
-       # powers of ten
-       .align  2
-ten1:  .word   0x4220,0,0,0
-ten2:  .word   0x43c8,0,0,0
-ten4:  .word   0x471c,0x4000,0,0
-ten8:  .word   0x4dbe,0xbc20,0,0
-ten16: .word   0x5b0e,0x1bc9,0xbf04,0
-ten32: .word   0x759d,0xc5ad,0xa82b,0x70b6
+       *p++ = fmtch;
+       if (exp < 0) {
+               exp = -exp;
+               *p++ = '-';
+       }
+       else
+               *p++ = '+';
+       t = expbuf + MAXEXP;
+       if (exp > 9) {
+               do {
+                       *--t = tochar(exp % 10);
+               } while ((exp /= 10) > 9);
+               *--t = tochar(exp);
+               for (; t < expbuf + MAXEXP; *p++ = *t++);
+       }
+       else {
+               *p++ = '0';
+               *p++ = tochar(exp);
+       }
+       return(p);
+}
diff --git a/bin/csh/doprnt.c.vax b/bin/csh/doprnt.c.vax
new file mode 100644 (file)
index 0000000..0144f14
--- /dev/null
@@ -0,0 +1,481 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley Software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+       .ascii  "@(#)doprnt.c   5.2 (Berkeley) 6/6/85"
+#endif
+
+       # C library -- conversions
+
+.globl __doprnt
+.globl __strout
+
+#define flags r10
+#define literb 0
+#define liter 1
+#define ndfndb 0
+#define ndfnd 1
+#define ljustb 1
+#define ljust 2
+#define zfillb 2
+#define zfill 4
+#define precb 3
+#define prec 8
+#define psignb 4
+#define psign 16
+#define gflagb 5
+#define gflag 32
+#define width r9
+#define ndigit r8
+#define fdesc -4(fp)
+#define exp -8(fp)
+#define sign -9(fp)
+       .set one,010                    # 1.0 in floating immediate
+       .set ch.zer,'0                  # cpp doesn't like single appostrophes
+
+       .align  1
+__doprnt:
+       .word   0xfc0                   # uses r11-r6
+       subl2 $128,sp
+       movl 4(ap),r11                  # addr of format string
+       movl 12(ap),fdesc               # output FILE ptr
+       movl 8(ap),ap                   # addr of first arg
+loop:
+       movl r11,r0                     # current point in format
+       bicl2 $liter,flags              # no literal characters yet
+L1:    movb (r11)+,width               # next character of format
+       beql L2                         # end of format string
+       cmpb width,$'%
+       beql L2                         # warning character
+       bisl2 $liter,flags              # literal character
+       jbr L1
+L2:    blbc flags,L3                   # bbc $literb,flags,L3 # no literals in format
+       pushl fdesc                     # file pointer
+       pushl $0                        # no left/right adjust
+       pushl r0                        # addr
+       subl3 r0,r11,r1                 # length
+       subl3 $1,r1,-(sp)               # % or null not part of literal
+       calls $4,__strout               # dump the literal
+L3:
+       blbs width,L4                   # % is odd; end of format?
+       ret                             # yes
+
+       # htab overlaps last 16 characters of ftab
+ftab:  .byte    0, 0, 0,'c,'d,'e,'f,'g, 0, 0, 0,'+,'l,'-,'.,'o
+htab:  .byte   '0,'1,'2,'3,'4,'5,'6,'7,'8,'9,'a,'b,'c,'d,'e,'f
+
+L4:    movl sp,r5                      # reset output buffer pointer
+       clrq r9                         # width; flags ljustb,ndfndb,zfillb
+L4a:   movzbl (r11)+,r0                # supposed format
+       extzv $0,$5,r0,r1                # bottom 5 bits
+L4b:   cmpb r0,ftab[r1]                # good enough?
+       jneq L6                         # no
+L4c:   casel r1,$3,$22                 # yes
+L5:    .word charac-L5                 # c
+       .word decimal-L5                # d
+       .word scien-L5                  # e
+       .word float-L5                  # f
+       .word general-L5                # g
+       .word L6-L5                     # h
+       .word L6-L5                     # i
+       .word L6-L5                     # j
+       .word plus-L5                   # +
+       .word longorunsg-L5             # l
+       .word minus-L5                  # -
+       .word dot-L5                    # .
+       .word octal-L5                  # o
+       .word gnum0-L5                  # 0
+       .word gnum-L5                   # 1
+       .word gnum-L5                   # 2
+       .word gnum-L5                   # 3
+       .word gnum-L5                   # 4
+       .word gnum-L5                   # 5
+       .word gnum-L5                   # 6
+       .word gnum-L5                   # 7
+       .word gnum-L5                   # 8
+       .word gnum-L5                   # 9
+
+L6:    jbcs $5,r0,L4b                  # capitals same as small
+       cmpb r0,$'s
+       jeql string
+       cmpb r0,$'x
+       jeql hex
+       cmpb r0,$'u
+       jeql unsigned
+       cmpb r0,$'r
+       jeql remote
+       movzbl -1(r11),r0               # orginal "format" character
+       cmpb r0,$'*
+       jeql indir
+L9:    movb r0,(r5)+                   # print the unfound character
+       jbr prbuf
+
+nulstr:
+       .byte '(,'n,'u,'l,'l,'),0
+
+string:
+       movl ndigit,r0
+       jbs $precb,flags,L20            # max length was specified
+       mnegl $1,r0                     # default max length
+L20:   movl (ap)+,r2                   # addr first byte
+       bneq L21
+       movab nulstr,r2
+L21:   locc $0,r0,(r2)                 # find the zero at the end
+       movl r1,r5                      # addr last byte +1
+       movl r2,r1                      # addr first byte
+       jbr prstr
+
+
+longorunsg:
+       movb (r11)+,r0
+       cmpb r0,$'o
+       jeql loct
+       cmpb r0,$'x
+       jeql lhex
+       cmpb r0,$'d
+       jeql long
+       cmpb r0,$'u
+       jeql lunsigned
+       decl r11
+       jbr unsigned
+
+loct:
+octal:
+       movl $30,r2                     # init position
+       movl $3,r3                      # field width
+       movl $10,r4                     # result length -1
+       jbr L10
+
+lhex:
+hex:
+       movl $28,r2                     # init position
+       movl $4,r3                      # field width
+       movl $7,r4                      # result length -1
+L10:   mnegl r3,r6                     # increment
+       clrl r1
+       movl (ap)+,r0                   # fetch arg
+L11:   extzv r2,r3,r0,r1               # pull out a digit
+       movb htab[r1],(r5)+             # convert to character
+L12:   acbl $0,r6,r2,L11               # continue until done
+       clrb (r5)                       # flag end
+       skpc $'0,r4,(sp)                # skip over leading zeroes
+       jbr prstr
+
+patdec:                                        # editpc pattern for decimal printing
+       .byte 0xA9                      # eo$float 9
+       .byte 0x01                      # eo$end_float
+       .byte 0x91                      # eo$move 1
+       .byte 0                         # eo$end
+
+long:
+decimal:
+       cvtlp (ap)+,$10,(sp)            # 10 digits max
+L14:   editpc $10,(sp),patdec,8(sp)    # ascii at 8(sp); r5=end+1
+       skpc $' ,$10,8(sp)              # skip leading blanks; r1=first
+
+prstr:                 # r1=addr first byte; r5=addr last byte +1
+       cvtbl $' ,-(sp)                 # blank fill
+       jbc $zfillb,flags,L15
+       cvtbl $'0,(sp)                  # zero fill
+L15:   pushl fdesc                     # FILE
+       subl2 r1,r5                     # r5=actual length=end+1-first
+       subl3 r5,width,r0               # if >0, how much to fill
+       bgeq L24
+       clrl r0                         # no fill
+L24:   jbs $ljustb,flags,L25
+       mnegl r0,r0
+L25:   pushl r0                        # fill count
+       pushl r1                        # addr first byte
+       pushl r5                        # length
+       calls $5,__strout
+       jbr     loop
+
+pone:  .byte   0x1C                    # packed 1
+       
+unsigned:
+lunsigned:
+       extzv $1,$31,(ap),r0            # right shift logical 1 bit
+       cvtlp r0,$10,(sp)               # convert [n/2] to packed
+       movp $10,(sp),8(sp)             # copy packed
+       addp4 $10,8(sp),$10,(sp)        # 2*[n/2] in packed, at (sp)
+       blbc (ap)+,L14                  # n was even
+       addp4 $1,pone,$10,(sp)          # n was odd
+       jbr L14
+
+charac:
+       movl $4,r0                      # chars per word
+L18:   movb (ap)+,(r5)+                # transfer char
+       bneq L19
+       decl r5                         # omit null characters
+L19:   sobgtr r0,L18
+
+prbuf:
+       movl sp,r1                      # addr first byte
+       jbr prstr
+
+plus:  bisl2 $psign,flags              # always print sign for floats
+       jbr L4a
+minus: bisl2 $ljust,flags              # left justification, please
+       jbr L4a
+gnum0: jbs $ndfndb,flags,gnum
+       jbs $precb,flags,gnump          # ignore when reading precision
+       bisl2 $zfill,flags              # leading zero fill, please
+gnum:  jbs $precb,flags,gnump
+       moval (width)[width],width      # width *= 5;
+       movaw -ch.zer(r0)[width],width  # width = 2*witdh + r0 - '0';
+       jbr gnumd
+gnump: moval (ndigit)[ndigit],ndigit   # ndigit *= 5;
+       movaw -ch.zer(r0)[ndigit],ndigit # ndigit = 2*ndigit + r0 - '0';
+gnumd: bisl2 $ndfnd,flags              # digit seen
+       jbr L4a
+dot:   clrl ndigit                     # start on the precision
+       bisl2 $prec,flags
+       bicl2 $ndfnd,flags
+       jbr L4a
+indir: movl (ap)+,ndigit               # width specified by parameter
+       jbr gnumd
+remote:        movl (ap)+,ap
+       movl (ap)+,r11
+       jbr loop
+
+float:
+       bsbw fltcvt
+fltg:  jbs $ndfndb,flags,float1
+       movl $6,ndigit                  # default # digits to right of decpt.
+float1:        addl3 exp,ndigit,r7
+       movl r7,r6                      # for later "underflow" checking
+       bgeq fxplrd
+       clrl r7                         # poor programmer planning
+fxplrd:        cmpl r7,$31                     # expressible in packed decimal?
+       bleq fnarro                     # yes
+       movl $31,r7
+fnarro:        subl3 $17,r7,r0                 # where to round
+       ashp r0,$17,(sp),$5,r7,16(sp)   # do it
+       bvc fnovfl
+       # band-aid for microcode error (spurious overflow)
+       clrl r0                         # assume even length result
+       jlbc r7,fleven                  # right
+       movl $4,r0                      # odd length result
+fleven:        cmpv r0,$4,16(sp),$0            # top digit zero iff true overflow
+       bneq fnovfl
+       # end band-aid
+       aobleq $0,r6,fnovfl             # if "underflow" then jump
+       movl r7,r0
+       incl exp
+       incl r7
+       ashp r0,$1,pone,$0,r7,16(sp)
+       ashl $-1,r7,r0                  # displ to last byte
+       bisb2 sign,16(sp)[r0]           # insert sign
+fnovfl:
+       movc3 $4,patsci,(sp)
+       clrl r6                         # # digits moved so far
+       movl exp,r0
+       bleq fexpng
+       bsbb patmov                     # digits to left of decpt.
+fexpng:        tstl ndigit
+       jeql fnodp
+       movc3 $2,fpatdp,(r3)
+       tstl exp
+       bgeq fxppos
+       addl3 exp,ndigit,r6
+       bgeq  flfakl
+       clrl r6                         # it's all fill
+flfakl:        subl3 r6,$31,r6                 # fake length for patmov
+flfill:        movc3 $2,fpatzf,(r3)            # zero fill to right of dec.pt
+fxppos:        movl ndigit,r0
+       bsbb patmov
+fnodp: sobgeq r6,fledit                # must move at least 1 digit
+       movl $31,r6                     # none moved; fake it
+       aobleq $1,ndigit,flfill         # with a one-character zero fill
+fledit:        editpc r7,16(sp),(sp),32(sp)
+       jbr prflt
+
+patexp:        .byte   0x03                    # eo$set_signif
+       .byte   0x44,'e                 # eo$insert 'e
+       .byte   0x42,'+                 # eo$load_plus '+
+       .byte   0x04                    # eo$store_sign
+       .byte   0x92                    # eo$move 2
+       .byte   0                       # eo$end
+patsci:        .byte   0x42,'+                 # eo$load_plus '+
+       .byte   0x03                    # eo$set_signif
+       .byte   0x04                    # eo$store_sign
+       .byte   0x91                    # eo$move 1
+fpatdp:        .byte   0x44,'.                 # eo$insert '.
+fpatzf:        .byte   0x40,'0                 # eo$load_fill '0
+
+       # construct pattern at (r3) to move  r0  digits in  editpc;
+       #  r6  digits already moved for this number
+patmov:
+       movb $0x90,r2                   # eo$move
+       subl3 r6,$31,r1                 # # digits remaining in packed
+       addl2 r0,r6
+       cmpl r0,r1                      # enough digits remaining?
+       bleq patsml                     # yes
+       tstl exp                        # zero 'fill'; before or after rest?
+       bgeq pataft                     # after
+       pushl r1                        # # digits remaining
+       movb $0x80,r2                   # eo$fill
+       subl3 $31,r6,r0                 # number of fill bytes
+       bsbb patsml                     # recursion!
+       movl (sp)+,r0
+       movb $0x90,r2                   # eo$move
+       jbr patsml
+pataft:        movl r1,r0                      # last of the 31
+       bsbb patsml                     # recursion!
+       subl3 $31,r6,r0                 # number of fill bytes
+       movb $0x80,r2                   # eo$fill
+patsml:        tstl r0
+       bleq patzer                     # DEC doesn't like repetition counts of 0
+       mnegl $15,r1                    # 15 digits at a time
+       subl2 r1,r0                     # counteract acbl
+       jbr pattst
+patmlp:        bisb3 r2,$15,(r3)+              # 15
+pattst:        acbl $16,r1,r0,patmlp           # until <= 15 left
+       bisb3 r2,r0,(r3)+               # rest
+patzer:        clrb (r3)                       # eo$end
+       rsb
+
+scien:
+       bsbw fltcvt                     # get packed digits
+scig:  incl ndigit
+       jbs $ndfndb,flags,L23
+       movl $7,ndigit
+L23:   subl3 $17,ndigit,r0             # rounding position
+       ashp r0,$17,(sp),$5,ndigit,16(sp) # shift and round
+       bvc snovfl
+       # band-aid for microcode error (spurious overflow)
+       clrl r0                         # assume even length result
+       jlbc ndigit,sceven              # right
+       movl $4,r0                      # odd length result
+sceven:        cmpv r0,$4,16(sp),$0            # top digit zero iff true overflow
+       bneq snovfl
+       # end band-aid
+       incl exp                        # rounding overflowed to 100...
+       subl3 $1,ndigit,r0
+       ashp r0,$1,pone,$0,ndigit,16(sp)
+       ashl $-1,ndigit,r0              # displ to last byte
+       bisb2 sign,16(sp)[r0]           # insert sign
+snovfl:
+       jbc $gflagb,flags,enotg         # not %g format
+ # find trailing zeroes in packed number
+       ashl $-1,ndigit,r0
+       addl2 r3,r0                     # addr of l.s.digit and sign
+       movl $4,r1                      # bit position of digit
+       movl ndigit,r7                  # current length of packed
+       jbr gtz
+gtz1:  xorl2 $4,r1                     # position of next digit
+       bneq gtz                        # same byte
+       decl r0                         # different byte
+gtz:   cmpv r1,$4,(r0),$0              # a trailing zero?
+       jneq gntz
+       sobgtr r7,gtz1
+       incl r7
+gntz:                                  # r7: minimum width of fraction
+       cmpl exp,$-4
+       jleq eg                         # small exponents use %e
+       subl3 r7,exp,r0
+       cmpl $5,r0
+       jleq eg                         # so do (w+5) <= exp
+       tstl r0                         # rest use %f
+       jleq fg                         # did we trim too many trailing zeroes?
+       movl exp,r7                     # yes
+fg:    subl3 ndigit,r7,r0
+       ashp r0,ndigit,16(sp),$0,r7,(sp)
+       movp r7,(sp),16(sp)
+       subl3 exp,r7,ndigit             # correct ndigit for %f
+       jbr fnovfl
+eg:    subl3 ndigit,r7,r0
+       ashp r0,ndigit,16(sp),$0,r7,(sp)
+       movp r7,(sp),16(sp)
+       movl r7,ndigit                  # packed number has been trimmed
+enotg:
+       movc3 $7,patsci,(sp)
+       movl $1,r6                      # 1P
+       subl3 $1,ndigit,r0              # digits after dec.pt
+       bsbw patmov
+       editpc ndigit,16(sp),(sp),32(sp)        # 32(sp)->result, r5->(end+1)
+       decl exp                        # compensate: 1 digit left of dec.pt
+       cvtlp exp,$2,(sp)               # exponent
+       editpc $2,(sp),patexp,(r5)
+prflt: movab 32(sp),r1
+       jbs $psignb,flags,prflt1
+       cmpb (r1)+,$'+
+       beql prflt1
+       decl r1
+prflt1:        skpc $' ,$63,(r1)
+       jbr prstr
+
+general:
+       jbcs $gflagb,flags,scien
+       jbr scien                       # safety net
+
+       # convert double-floating at (ap) to 17-digit packed at (sp),
+       # set 'sign' and 'exp', advance ap.
+fltcvt:
+       clrb sign
+       movd (ap)+,r5
+       jeql fzero
+       bgtr fpos
+       mnegd r5,r5
+       incb sign
+fpos:
+       extzv $7,$8,r5,r2               # exponent of 2
+       movaw -0600(r2)[r2],r2          # unbias and mult by 3
+       bgeq epos
+       subl2 $9,r2
+epos:  divl2 $10,r2
+       bsbb expten
+       cmpd r0,r5
+       bgtr ceil
+       incl r2
+ceil:  movl r2,exp
+       mnegl r2,r2
+       cmpl r2,$29                     # 10^(29+9) is all we can handle
+       bleq getman
+       muld2 ten16,r5
+       subl2 $16,r2
+getman:        addl2 $9,r2                     # -ceil(log10(x)) + 9
+       bsbb expten
+       emodd r0,r4,r5,r0,r5            # (r0+r4)*r5; r0=int, r5=frac
+fz1:   cvtlp r0,$9,16(sp)              # leading 9 digits
+       ashp $8,$9,16(sp),$0,$17,4(sp)  # as top 9 of 17
+       emodd ten8,$0,r5,r0,r5
+       cvtlp r0,$8,16(sp)              # trailing 8 digits
+       addp4 $8,16(sp),$17,4(sp)       # combine leading and trailing
+       bisb2 sign,12(sp)               # and insert sign
+       rsb
+fzero: clrl r0
+       movl $1,exp             # 0.000e+00 and 0.000 rather than 0.000e-01 and .000
+       jbr fz1
+
+       # return 10^r2 as a double float in r0||r1 and 8 extra bits of precision in r4
+       # preserve r2, r5||r6
+expten:
+       movd $one,r0                    # begin computing 10^exp10
+       clrl r4                         # bit counter
+       movad ten1,r3                   # table address
+       tstl r2
+       bgeq e10lp
+       mnegl r2,r2                     # get absolute value
+       jbss $6,r2,e10lp                # flag as negative
+e10lp: jbc r4,r2,el1                   # want this power?
+       muld2 (r3),r0                   # yes
+el1:   addl2 $8,r3                     # advance to next power
+       aobleq $5,r4,e10lp              # through 10^32
+       jbcc $6,r2,el2                  # correct for negative exponent
+       divd3 r0,$one,r0                # by taking reciprocal
+       mnegl r2,r2
+el2:   clrl r4                         # 8 extra bits of precision
+       rsb
+
+       # powers of ten
+       .align  2
+ten1:  .word   0x4220,0,0,0
+ten2:  .word   0x43c8,0,0,0
+ten4:  .word   0x471c,0x4000,0,0
+ten8:  .word   0x4dbe,0xbc20,0,0
+ten16: .word   0x5b0e,0x1bc9,0xbf04,0
+ten32: .word   0x759d,0xc5ad,0xa82b,0x70b6
diff --git a/bin/csh/groups.txt b/bin/csh/groups.txt
new file mode 100644 (file)
index 0000000..bd281d0
--- /dev/null
@@ -0,0 +1,23 @@
+malloc.c sh.h
+doprnt.c sh.h
+printf.c sh.h
+sh.c sh.h
+sh.char.c sh.char.h
+sh.dir.c sh.dir.h
+sh.dol.c sh.h
+sh.err.c sh.h
+sh.exec.c sh.h
+sh.exp.c sh.h
+sh.file.c sh.h
+sh.func.c sh.h
+sh.glob.c sh.h
+sh.hist.c sh.h
+sh.init.c sh.local.h
+sh.lex.c sh.h
+sh.misc.c sh.h
+sh.parse.c sh.h
+sh.print.c sh.h
+sh.proc.c sh.proc.h
+sh.sem.c sh.proc.h
+sh.set.c sh.h
+sh.time.c sh.h
similarity index 97%
rename from bin/csh/alloc.c
rename to bin/csh/malloc.c
index 933a015..ea0be7d 100644 (file)
@@ -6,7 +6,7 @@
 
 #ifndef lint
 /* From "@(#)malloc.c  5.5 (Berkeley) 2/25/86"; */
-static char *sccsid = "@(#)alloc.c     5.3 (Berkeley) 3/29/86";
+static char *sccsid = "@(#)malloc.c    5.3 (Berkeley) 3/29/86";
 #endif not lint
 
 /*
@@ -79,7 +79,7 @@ static        u_int nmalloc[NBUCKETS];
 
 #if defined(DEBUG) || defined(RCHECK)
 #define        ASSERT(p)   if (!(p)) botch("p")
-static
+static void
 botch(s)
        char *s;
 {
@@ -90,13 +90,14 @@ botch(s)
 #define        ASSERT(p)
 #endif
 
-char *
+void *
 malloc(nbytes)
        unsigned nbytes;
 {
        register union overhead *op;
        register int bucket;
-       register unsigned amt, n;
+       register unsigned amt;
+       register int n;
 
        /*
         * First time malloc is called, setup page size and
@@ -105,7 +106,7 @@ malloc(nbytes)
        if (pagesz == 0) {
                pagesz = n = getpagesize();
                op = (union overhead *)sbrk(0);
-               n = n - sizeof (*op) - ((int)op & (n - 1));
+               n = n - sizeof (*op) - ((intptr_t)op & (n - 1));
                if (n < 0)
                        n += pagesz;
                if (n) {
@@ -173,6 +174,7 @@ malloc(nbytes)
 /*
  * Allocate more memory to the indicated bucket.
  */
+void
 morecore(bucket)
        int bucket;
 {
@@ -214,9 +216,10 @@ morecore(bucket)
        }
 }
 
+void
 free(cp)
-       char *cp;
-{   
+       void *cp;
+{
        register int size;
        register union overhead *op;
 
@@ -257,11 +260,11 @@ free(cp)
  */
 int realloc_srchlen = 4;       /* 4 should be plenty, -1 =>'s whole list */
 
-char *
+void *
 realloc(cp, nbytes)
-       char *cp; 
+       void *cp; 
        unsigned nbytes;
-{   
+{
        register u_int onb, i;
        union overhead *op;
        char *res;
@@ -353,6 +356,7 @@ findbucket(freep, srchlen)
  * for each size category, the second showing the number of mallocs -
  * frees for each size category.
  */
+void
 showall(s)
 char **s;
 {
index d872ae3..7944b8a 100644 (file)
@@ -1,44 +1,36 @@
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley Software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#ifndef lint
-static char *sccsid = "@(#)printf.c    5.2 (Berkeley) 6/6/85";
-#endif
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)printf.c   5.4 (Berkeley) 6/27/88";
+#endif LIBC_SCCS and not lint
 
-/*
- * Hacked "printf" which prints through putchar.
- * DONT USE WITH STDIO!
- */
-printf(fmt, args)
-char *fmt;
-{
-       _doprnt(fmt, &args, 0);
-}
+/*#include <stdio.h>*/
+#include <varargs.h>
 
-_strout(count, string, adjust, foo, fillch)
-register char *string;
-register int count;
-int adjust;
-register struct { int a[6]; } *foo;
+printf(fmt, va_alist)
+       char *fmt;
+       va_dcl
 {
+       va_list argp;
+       int len;
 
-       if (foo != 0)
-               abort();
-       while (adjust < 0) {
-               if (*string=='-' && fillch=='0') {
-                       putchar(*string++);
-                       count--;
-               }
-               putchar(fillch);
-               adjust++;
-       }
-       while (--count>=0)
-               putchar(*string++);
-       while (adjust) {
-               putchar(fillch);
-               adjust--;
-       }
+       va_start(argp);
+       len = _doprnt(fmt, argp/*, stdout*/);
+       va_end(argp);
+       return(/*ferror(stdout) ? EOF :*/ len);
 }
diff --git a/bin/csh/printf.c.vax b/bin/csh/printf.c.vax
new file mode 100644 (file)
index 0000000..d872ae3
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley Software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)printf.c    5.2 (Berkeley) 6/6/85";
+#endif
+
+/*
+ * Hacked "printf" which prints through putchar.
+ * DONT USE WITH STDIO!
+ */
+printf(fmt, args)
+char *fmt;
+{
+       _doprnt(fmt, &args, 0);
+}
+
+_strout(count, string, adjust, foo, fillch)
+register char *string;
+register int count;
+int adjust;
+register struct { int a[6]; } *foo;
+{
+
+       if (foo != 0)
+               abort();
+       while (adjust < 0) {
+               if (*string=='-' && fillch=='0') {
+                       putchar(*string++);
+                       count--;
+               }
+               putchar(fillch);
+               adjust++;
+       }
+       while (--count>=0)
+               putchar(*string++);
+       while (adjust) {
+               putchar(fillch);
+               adjust--;
+       }
+}
index 8935c28..c7ed09e 100644 (file)
@@ -490,7 +490,7 @@ srcunit(unit, onlyown, hflg)
        reenter++;
        if (reenter == 1) {
                /* Setup the new values of the state stuff saved above */
-               copy((char *)&saveB, (char *)&B, sizeof saveB);
+               bcopy((char *)&B, (char *)&saveB, sizeof saveB);
                fbuf = (char **) 0;
                fseekp = feobp = fblocks = 0;
                oSHIN = SHIN, SHIN = unit, arginp = 0, onelflg = 0;
@@ -522,7 +522,7 @@ srcunit(unit, onlyown, hflg)
                xfree((char *)fbuf);
 
                /* Reset input arena */
-               copy((char *)&B, (char *)&saveB, sizeof B);
+               bcopy((char *)&saveB, (char *)&B, sizeof B);
 
                (void) close(SHIN), SHIN = oSHIN;
                arginp = oarginp, onelflg = oonelflg;
@@ -792,7 +792,11 @@ process(catch)
                /*
                 * Execute the parse tree
                 */
+#if defined(__STDC__) || defined(lint)
+               execute(t, tpgrp, 0, 0);
+#else
                execute(t, tpgrp);
+#endif
 
                /*
                 * Made it!
@@ -903,11 +907,11 @@ initdesc()
        closem();
 }
 
-#ifdef PROF
-done(i)
-#else
+/*#ifdef PROF*/
+/*done(i)*/
+/*#else*/
 exit(i)
-#endif
+/*#endif*/
        int i;
 {
 
diff --git a/bin/csh/sh.data.c b/bin/csh/sh.data.c
new file mode 100644 (file)
index 0000000..38e989c
--- /dev/null
@@ -0,0 +1,189 @@
+#include "sh.h"
+
+/* moved all this here from sh.h which now only declares them extern */
+
+/*
+ * Global flags
+ */
+bool   chkstop;                /* Warned of stopped jobs... allow exit */
+bool   didfds;                 /* Have setup i/o fd's for child */
+bool   doneinp;                /* EOF indicator after reset from readc */
+bool   exiterr;                /* Exit if error or non-zero exit status */
+bool   child;                  /* Child shell ... errors cause exit */
+bool   haderr;                 /* Reset was because of an error */
+bool   intty;                  /* Input is a tty */
+bool   intact;                 /* We are interactive... therefore prompt */
+bool   justpr;                 /* Just print because of :p hist mod */
+bool   loginsh;                /* We are a loginsh -> .login/.logout */
+bool   neednote;               /* Need to pnotify() */
+bool   noexec;                 /* Don't execute, just syntax check */
+bool   pjobs;                  /* want to print jobs if interrupted */
+bool   setintr;                /* Set interrupts on/off -> Wait intr... */
+bool   timflg;                 /* Time the next waited for command */
+bool   havhash;                /* path hashing is available */
+#ifdef FILEC
+bool   filec;                  /* doing filename expansion */
+#endif
+
+/*
+ * Global i/o info
+ */
+char   *arginp;                /* Argument input for sh -c and internal `xx` */
+int    onelflg;                /* 2 -> need line for -t, 1 -> exit on read */
+char   *file;                  /* Name of shell file for $0 */
+
+char   *err;                   /* Error message from scanner/parser */
+int    errno;                  /* Error from C library routines */
+char   *shtemp;                /* Temp name for << shell files in /tmp */
+struct timeval time0;          /* Time at which the shell started */
+struct rusage ru0;
+
+/*
+ * Miscellany
+ */
+char   *doldol;                /* Character pid for $$ */
+int    uid;                    /* Invokers uid */
+time_t chktim;                 /* Time mail last checked */
+int    shpgrp;                 /* Pgrp of shell */
+int    tpgrp;                  /* Terminal process group */
+/* If tpgrp is -1, leave tty alone! */
+int    opgrp;                  /* Initial pgrp and tty pgrp */
+int    oldisc;                 /* Initial line discipline or -1 */
+
+/*
+ * To be able to redirect i/o for builtins easily, the shell moves the i/o
+ * descriptors it uses away from 0,1,2.
+ * Ideally these should be in units which are closed across exec's
+ * (this saves work) but for version 6, this is not usually possible.
+ * The desired initial values for these descriptors are defined in
+ * sh.local.h.
+ */
+short  SHIN;                   /* Current shell input (script) */
+short  SHOUT;                  /* Shell output */
+short  SHDIAG;                 /* Diagnostic output... shell errs go here */
+short  OLDSTD;                 /* Old standard input (def for cmds) */
+
+/*
+ * Error control
+ *
+ * Errors in scanning and parsing set up an error message to be printed
+ * at the end and complete.  Other errors always cause a reset.
+ * Because of source commands and .cshrc we need nested error catches.
+ */
+
+jmp_buf        reslab;
+
+char   *gointr;                /* Label for an onintr transfer */
+
+/*
+ * Each level of input has a buffered input structure.
+ * There are one or more blocks of buffered input for each level,
+ * exactly one if the input is seekable and tell is available.
+ * In other cases, the shell buffers enough blocks to keep all loops
+ * in the buffer.
+ */
+struct Bin B;
+
+/*
+ * The shell finds commands in loops by reseeking the input
+ * For whiles, in particular, it reseeks to the beginning of the
+ * line the while was on; hence the while placement restrictions.
+ */
+off_t  lineloc;
+
+#ifdef TELL
+bool   cantell;                        /* Is current source tellable ? */
+#endif
+
+/*
+ * Labuf implements a general buffer for lookahead during lexical operations.
+ * Text which is to be placed in the input stream can be stuck here.
+ * We stick parsed ahead $ constructs during initial input,
+ * process id's from `$$', and modified variable values (from qualifiers
+ * during expansion in sh.dol.c) here.
+ */
+char   labuf[BUFSIZ];
+
+char   *lap;
+
+/*
+ * Structure defining the existing while/foreach loops at this
+ * source level.  Loops are implemented by seeking back in the
+ * input.  For foreach (fe), the word list is attached here.
+ */
+struct whyle *whyles;
+
+/*
+ * Variable structure
+ *
+ * Aliases and variables are stored in AVL balanced binary trees.
+ */
+struct varent shvhed, aliases;
+
+/*
+ * The following are for interfacing redo substitution in
+ * aliases to the lexical routines.
+ */
+struct wordent *alhistp;               /* Argument list (first) */
+struct wordent *alhistt;               /* Node after last in arg list */
+char   **alvec;                        /* The (remnants of) alias vector */
+
+/*
+ * Filename/command name expansion variables
+ */
+short  gflag;                          /* After tglob -> is globbing needed? */
+
+/*
+ * Variables for filename expansion
+ */
+char   **gargv;                        /* Pointer to the (stack) arglist */
+short  gargc;                          /* Number args in gargv */
+short  gnleft;
+
+/*
+ * Variables for command expansion.
+ */
+char   **pargv;                        /* Pointer to the argv list space */
+char   *pargs;                         /* Pointer to start current word */
+short  pargc;                          /* Count of arguments in pargv */
+short  pnleft;                         /* Number of chars left in pargs */
+char   *pargcp;                        /* Current index into pargs */
+
+/*
+ * History list
+ *
+ * Each history list entry contains an embedded wordlist
+ * from the scanner, a number for the event, and a reference count
+ * to aid in discarding old entries.
+ *
+ * Essentially "invisible" entries are put on the history list
+ * when history substitution includes modifiers, and thrown away
+ * at the next discarding since their event numbers are very negative.
+ */
+struct Hist Histlist;
+
+struct wordent paraml;                 /* Current lexical word list */
+int    eventno;                        /* Next events number */
+int    lastev;                         /* Last event reference (default) */
+
+char   HIST;                           /* history invocation character */
+char   HISTSUB;                        /* auto-substitute character */
+
+/*
+ * In lines for frequently called functions
+ */
+char   *alloctmp;
+
+/*
+ * setname is a macro to save space (see sh.err.c)
+ */
+char   *bname;
+
+#ifdef VFORK
+char   *Vsav;
+char   **Vav;
+char   *Vdp;
+#endif
+
+char   **evalvec;
+char   *evalp;
diff --git a/bin/csh/sh.end.c b/bin/csh/sh.end.c
new file mode 100644 (file)
index 0000000..0ddd16d
--- /dev/null
@@ -0,0 +1 @@
+char end[0];
index e72d3aa..239ed23 100644 (file)
@@ -28,12 +28,13 @@ char        *onev[2] = { one, NOSTR };
  * be closed in the routine process in sh.c which is the only
  * place error unwinds are ever caught.
  */
-/*VARARGS1*/
-error(s, arg)
+error(s, va_alist)
        char *s;
+       va_dcl
 {
        register char **v;
        register char *ep;
+       va_list argp;
 
        /*
         * Must flush before we print as we wish output before the error
@@ -54,8 +55,11 @@ error(s, arg)
         * A zero arguments causes no printing, else print
         * an error diagnostic here.
         */
-       if (s)
-               printf(s, arg), printf(".\n");
+       if (s) {
+               va_start(argp);
+               vprintf(s, argp), printf(".\n");
+               va_end(argp);
+       }
 
        didfds = 0;             /* Forget about 0,1,2 */
        if ((ep = err) && errspl) {
index 9ea5fa9..b51e9dc 100644 (file)
@@ -274,9 +274,7 @@ xechoit(t)
        }
 }
 
-/*VARARGS0*//*ARGSUSED*/
-dohash(v)
-       char **v;
+dohash()
 {
        struct stat stb;
        DIR *dirp;
index 3bcdf1c..2739938 100644 (file)
@@ -510,7 +510,11 @@ evalav(v)
        t = syntax(paraml.next, &paraml, 0);
        if (err)
                error(err);
+#if defined(__STDC__) || defined(lint)
+       execute(t, -1, 0, 0);
+#else
        execute(t, -1);
+#endif
        freelex(&paraml), freesyn(t);
 }
 
index f06ba94..eca7181 100644 (file)
@@ -352,7 +352,7 @@ free_items(items)
  * Perform a RECOGNIZE or LIST command on string "word".
  */
 static
-search(word, command, max_word_length)
+_search(word, command, max_word_length)
        char *word;
        COMMAND command;
 {
@@ -381,7 +381,7 @@ search(word, command, max_word_length)
                        return (0);
        }
 
-again: /* search for matches */
+again: /* _search for matches */
        name_length = strlen(name);
        for (numitems = 0; entry = getentry(dir_fd, looking_for_lognames); ) {
                if (!is_prefix(name, entry))
@@ -453,7 +453,7 @@ again:      /* search for matches */
  * On first match, copy full entry (assume it'll be the only match) 
  * On subsequent matches, shorten extended_name to the first
  * character mismatch between extended_name and entry.
- * If we shorten it back to the prefix length, stop searching.
+ * If we shorten it back to the prefix length, stop _searching.
  */
 static
 recognize(extended_name, entry, name_length, numitems)
@@ -547,7 +547,7 @@ tenex(inputline, inputline_size)
                        if (index(delims, word_start[-1]))
                                break;
                space_left = inputline_size - (word_start - inputline) - 1;
-               numitems = search(word_start, command, space_left);
+               numitems = _search(word_start, command, space_left);
 
                if (command == RECOGNIZE) {
                        /* print from str_end on */
index d94e5bc..8838e64 100644 (file)
@@ -226,7 +226,11 @@ doif(v, kp)
                 * otherwise just fall into following code.
                 */
                if (!i)
+#if defined(__STDC__) || defined(lint)
+                       search(ZIF, 0, 0);
+#else
                        search(ZIF, 0);
+#endif
                return;
        }
        /*
@@ -245,9 +249,7 @@ doif(v, kp)
  * Reexecute a command, being careful not
  * to redo i/o redirection, which is already set up.
  */
-reexecute(kp)
-       register struct command *kp;
-{
+int reexecute(kp) register struct command *kp; {
 
        kp->t_dflg &= FSAVE;
        kp->t_dflg |= FREDO;
@@ -257,13 +259,20 @@ reexecute(kp)
         * then have no way to get the tty (we can't give it
         * to them, and our parent wouldn't know their pgrp, etc.
         */
+#if defined(__STDC__) || defined(lint)
+       execute(kp, tpgrp > 0 ? tpgrp : -1, 0, 0);
+#else
        execute(kp, tpgrp > 0 ? tpgrp : -1);
+#endif
 }
 
 doelse()
 {
-
+#if defined(__STDC__) || defined(lint)
+       search(ZELSE, 0, 0);
+#else
        search(ZELSE, 0);
+#endif
 }
 
 dogoto(v)
@@ -279,7 +288,11 @@ dogoto(v)
         */
        for (wp = whyles; wp; wp = wp->w_next)
                if (wp->w_end == 0) {
+#if defined(__STDC__) || defined(lint)
+                       search(ZBREAK, 0, 0);
+#else
                        search(ZBREAK, 0);
+#endif
                        wp->w_end = btell();
                } else
                        bseek(wp->w_end);
@@ -419,7 +432,11 @@ preread()
        whyles->w_end = -1;
        if (setintr)
                (void) sigsetmask(sigblock(0) & ~sigmask(SIGINT));
+#if defined(__STDC__) || defined(lint)
+       search(ZBREAK, 0, 0);
+#else
        search(ZBREAK, 0);
+#endif
        if (setintr)
                (void) sigblock(sigmask(SIGINT));
        whyles->w_end = btell();
@@ -486,8 +503,11 @@ dorepeat(v, kp)
 
 doswbrk()
 {
-
+#if defined(__STDC__) || defined(lint)
+       search(ZBRKSW, 0, 0);
+#else
        search(ZBRKSW, 0);
+#endif
 }
 
 srchx(cp)
@@ -682,7 +702,11 @@ toend()
 {
 
        if (whyles->w_end == 0) {
+#if defined(__STDC__) || defined(lint)
+               search(ZBREAK, 0, 0);
+#else
                search(ZBREAK, 0);
+#endif
                whyles->w_end = btell() - 1;
        } else
                bseek(whyles->w_end);
index 2f41daf..b81ee84 100644 (file)
@@ -668,7 +668,11 @@ backeval(cp, literal)
                (void) signal(SIGTSTP, SIG_IGN);
                (void) signal(SIGTTIN, SIG_IGN);
                (void) signal(SIGTTOU, SIG_IGN);
+#if defined(__STDC__) || defined(lint)
+               execute(t, -1, 0, 0);
+#else
                execute(t, -1);
+#endif
                exitstat();
        }
        xfree(cp);
index 765df59..113dea5 100644 (file)
@@ -35,64 +35,64 @@ typedef     char    bool;
 /*
  * Global flags
  */
-bool   chkstop;                /* Warned of stopped jobs... allow exit */
-bool   didfds;                 /* Have setup i/o fd's for child */
-bool   doneinp;                /* EOF indicator after reset from readc */
-bool   exiterr;                /* Exit if error or non-zero exit status */
-bool   child;                  /* Child shell ... errors cause exit */
-bool   haderr;                 /* Reset was because of an error */
-bool   intty;                  /* Input is a tty */
-bool   intact;                 /* We are interactive... therefore prompt */
-bool   justpr;                 /* Just print because of :p hist mod */
-bool   loginsh;                /* We are a loginsh -> .login/.logout */
-bool   neednote;               /* Need to pnotify() */
-bool   noexec;                 /* Don't execute, just syntax check */
-bool   pjobs;                  /* want to print jobs if interrupted */
-bool   setintr;                /* Set interrupts on/off -> Wait intr... */
-bool   timflg;                 /* Time the next waited for command */
-bool   havhash;                /* path hashing is available */
+extern bool    chkstop;                /* Warned of stopped jobs... allow exit */
+extern bool    didfds;                 /* Have setup i/o fd's for child */
+extern bool    doneinp;                /* EOF indicator after reset from readc */
+extern bool    exiterr;                /* Exit if error or non-zero exit status */
+extern bool    child;                  /* Child shell ... errors cause exit */
+extern bool    haderr;                 /* Reset was because of an error */
+extern bool    intty;                  /* Input is a tty */
+extern bool    intact;                 /* We are interactive... therefore prompt */
+extern bool    justpr;                 /* Just print because of :p hist mod */
+extern bool    loginsh;                /* We are a loginsh -> .login/.logout */
+extern bool    neednote;               /* Need to pnotify() */
+extern bool    noexec;                 /* Don't execute, just syntax check */
+extern bool    pjobs;                  /* want to print jobs if interrupted */
+extern bool    setintr;                /* Set interrupts on/off -> Wait intr... */
+extern bool    timflg;                 /* Time the next waited for command */
+extern bool    havhash;                /* path hashing is available */
 #ifdef FILEC
-bool   filec;                  /* doing filename expansion */
+extern bool    filec;                  /* doing filename expansion */
 #endif
 
 /*
  * Global i/o info
  */
-char   *arginp;                /* Argument input for sh -c and internal `xx` */
-int    onelflg;                /* 2 -> need line for -t, 1 -> exit on read */
-char   *file;                  /* Name of shell file for $0 */
+extern char    *arginp;                /* Argument input for sh -c and internal `xx` */
+extern int     onelflg;                /* 2 -> need line for -t, 1 -> exit on read */
+extern char    *file;                  /* Name of shell file for $0 */
 
-char   *err;                   /* Error message from scanner/parser */
-int    errno;                  /* Error from C library routines */
-char   *shtemp;                /* Temp name for << shell files in /tmp */
-struct timeval time0;          /* Time at which the shell started */
-struct rusage ru0;
+extern char    *err;                   /* Error message from scanner/parser */
+extern int     errno;                  /* Error from C library routines */
+extern char    *shtemp;                /* Temp name for << shell files in /tmp */
+extern struct  timeval time0;          /* Time at which the shell started */
+extern struct  rusage ru0;
 
 /*
  * Miscellany
  */
-char   *doldol;                /* Character pid for $$ */
-int    uid;                    /* Invokers uid */
-time_t chktim;                 /* Time mail last checked */
-int    shpgrp;                 /* Pgrp of shell */
-int    tpgrp;                  /* Terminal process group */
+extern char    *doldol;                /* Character pid for $$ */
+extern int     uid;                    /* Invokers uid */
+extern time_t  chktim;                 /* Time mail last checked */
+extern int     shpgrp;                 /* Pgrp of shell */
+extern int     tpgrp;                  /* Terminal process group */
 /* If tpgrp is -1, leave tty alone! */
-int    opgrp;                  /* Initial pgrp and tty pgrp */
-int    oldisc;                 /* Initial line discipline or -1 */
+extern int     opgrp;                  /* Initial pgrp and tty pgrp */
+extern int     oldisc;                 /* Initial line discipline or -1 */
 
 /*
  * These are declared here because they want to be
  * initialized in sh.init.c (to allow them to be made readonly)
  */
 
-struct biltins {
+extern struct  biltins {
        char    *bname;
        int     (*bfunct)();
        short   minargs, maxargs;
 } bfunc[];
 extern int nbfunc;
 
-struct srch {
+extern struct srch {
        char    *s_name;
        short   s_value;
 } srchn[];
@@ -106,10 +106,10 @@ extern int nsrchn;
  * The desired initial values for these descriptors are defined in
  * sh.local.h.
  */
-short  SHIN;                   /* Current shell input (script) */
-short  SHOUT;                  /* Shell output */
-short  SHDIAG;                 /* Diagnostic output... shell errs go here */
-short  OLDSTD;                 /* Old standard input (def for cmds) */
+extern short   SHIN;                   /* Current shell input (script) */
+extern short   SHOUT;                  /* Shell output */
+extern short   SHDIAG;                 /* Diagnostic output... shell errs go here */
+extern short   OLDSTD;                 /* Old standard input (def for cmds) */
 
 /*
  * Error control
@@ -119,15 +119,15 @@ short     OLDSTD;                 /* Old standard input (def for cmds) */
  * Because of source commands and .cshrc we need nested error catches.
  */
 
-jmp_buf        reslab;
+extern jmp_buf reslab;
 
 #define        setexit()       ((void) setjmp(reslab))
 #define        reset()         longjmp(reslab, 0)
        /* Should use structure assignment here */
-#define        getexit(a)      copy((char *)(a), (char *)reslab, sizeof reslab)
-#define        resexit(a)      copy((char *)reslab, ((char *)(a)), sizeof reslab)
+#define        getexit(a)      bcopy((char *)reslab, (char *)(a), sizeof reslab)
+#define        resexit(a)      bcopy((char *)(a), (char *)reslab, sizeof reslab)
 
-char   *gointr;                /* Label for an onintr transfer */
+extern char    *gointr;                /* Label for an onintr transfer */
 int    (*parintr)();           /* Parents interrupt catch */
 int    (*parterm)();           /* Parents terminate catch */
 
@@ -148,7 +148,7 @@ int (*parterm)();           /* Parents terminate catch */
  * In other cases, the shell buffers enough blocks to keep all loops
  * in the buffer.
  */
-struct Bin {
+extern struct  Bin {
        off_t   Bfseekp;                /* Seek pointer */
        off_t   Bfbobp;                 /* Seekp of beginning of buffers */
        off_t   Bfeobp;                 /* Seekp of end of buffers */
@@ -164,19 +164,15 @@ struct    Bin {
 
 #define btell()        fseekp
 
-#ifndef btell
-off_t  btell();
-#endif
-
 /*
  * The shell finds commands in loops by reseeking the input
  * For whiles, in particular, it reseeks to the beginning of the
  * line the while was on; hence the while placement restrictions.
  */
-off_t  lineloc;
+extern off_t   lineloc;
 
 #ifdef TELL
-bool   cantell;                        /* Is current source tellable ? */
+extern bool    cantell;                        /* Is current source tellable ? */
 #endif
 
 /*
@@ -209,9 +205,9 @@ struct      wordent {
  * process id's from `$$', and modified variable values (from qualifiers
  * during expansion in sh.dol.c) here.
  */
-char   labuf[BUFSIZ];
+extern char    labuf[BUFSIZ];
 
-char   *lap;
+extern char    *lap;
 
 /*
  * Parser structure
@@ -292,7 +288,7 @@ struct      command {
  * source level.  Loops are implemented by seeking back in the
  * input.  For foreach (fe), the word list is attached here.
  */
-struct whyle {
+extern struct  whyle {
        off_t   w_start;                /* Point to restart loop */
        off_t   w_end;                  /* End of loop (0 if unknown) */
        char    **w_fe, **w_fe0;        /* Current/initial wordlist for fe */
@@ -305,7 +301,7 @@ struct      whyle {
  *
  * Aliases and variables are stored in AVL balanced binary trees.
  */
-struct varent {
+extern struct  varent {
        char    **vec;          /* Array of words which is the value */
        char    *v_name;        /* Name of variable/alias */
        struct  varent *v_link[3];      /* The links, see below */
@@ -315,7 +311,7 @@ struct      varent {
 #define v_right                v_link[1]
 #define v_parent       v_link[2]
 
-struct varent *adrof1();
+/*struct varent *adrof1();*/
 #define adrof(v)       adrof1(v, &shvhed)
 #define value(v)       value1(v, &shvhed)
 
@@ -323,14 +319,14 @@ struct varent *adrof1();
  * The following are for interfacing redo substitution in
  * aliases to the lexical routines.
  */
-struct wordent *alhistp;               /* Argument list (first) */
-struct wordent *alhistt;               /* Node after last in arg list */
-char   **alvec;                        /* The (remnants of) alias vector */
+extern struct  wordent *alhistp;               /* Argument list (first) */
+extern struct  wordent *alhistt;               /* Node after last in arg list */
+extern char    **alvec;                        /* The (remnants of) alias vector */
 
 /*
  * Filename/command name expansion variables
  */
-short  gflag;                          /* After tglob -> is globbing needed? */
+extern short   gflag;                          /* After tglob -> is globbing needed? */
 
 /*
  * A reasonable limit on number of arguments would seem to be
@@ -341,18 +337,18 @@ short     gflag;                          /* After tglob -> is globbing needed? */
 /*
  * Variables for filename expansion
  */
-char   **gargv;                        /* Pointer to the (stack) arglist */
-short  gargc;                          /* Number args in gargv */
-short  gnleft;
+extern char    **gargv;                        /* Pointer to the (stack) arglist */
+extern short   gargc;                          /* Number args in gargv */
+extern short   gnleft;
 
 /*
  * Variables for command expansion.
  */
-char   **pargv;                        /* Pointer to the argv list space */
-char   *pargs;                         /* Pointer to start current word */
-short  pargc;                          /* Count of arguments in pargv */
-short  pnleft;                         /* Number of chars left in pargs */
-char   *pargcp;                        /* Current index into pargs */
+extern char    **pargv;                        /* Pointer to the argv list space */
+extern char    *pargs;                         /* Pointer to start current word */
+extern short   pargc;                          /* Count of arguments in pargv */
+extern short   pnleft;                         /* Number of chars left in pargs */
+extern char    *pargcp;                        /* Current index into pargs */
 
 /*
  * History list
@@ -365,19 +361,19 @@ char      *pargcp;                        /* Current index into pargs */
  * when history substitution includes modifiers, and thrown away
  * at the next discarding since their event numbers are very negative.
  */
-struct Hist {
+extern struct  Hist {
        struct  wordent Hlex;
        int     Hnum;
        int     Href;
        struct  Hist *Hnext;
 } Histlist;
 
-struct wordent paraml;                 /* Current lexical word list */
-int    eventno;                        /* Next events number */
-int    lastev;                         /* Last event reference (default) */
+extern struct  wordent paraml;                 /* Current lexical word list */
+extern int     eventno;                        /* Next events number */
+extern int     lastev;                         /* Last event reference (default) */
 
-char   HIST;                           /* history invocation character */
-char   HISTSUB;                        /* auto-substitute character */
+extern char    HIST;                           /* history invocation character */
+extern char    HISTSUB;                        /* auto-substitute character */
 
 /*
  * In lines for frequently called functions
@@ -388,7 +384,7 @@ char        HISTSUB;                        /* auto-substitute character */
        if ((cp) >= end && (cp) < &stack) \
                free(cp); \
 }
-char   *alloctmp;
+extern char    *alloctmp;
 #define xalloc(i) ((alloctmp = malloc(i)) ? alloctmp : (char *)nomem(i))
 
 char   *Dfix1();
@@ -455,19 +451,19 @@ char      *xset();
 /*
  * setname is a macro to save space (see sh.err.c)
  */
-char   *bname;
+extern char    *bname;
 #define        setname(a)      (bname = (a))
 
 #ifdef VFORK
-char   *Vsav;
-char   **Vav;
-char   *Vdp;
+extern char    *Vsav;
+extern char    **Vav;
+extern char    *Vdp;
 #endif
 
-char   **evalvec;
-char   *evalp;
+extern char    **evalvec;
+extern char    *evalp;
 
-struct mesg {
+extern struct  mesg {
        char    *iname;         /* name from /usr/include */
        char    *pname;         /* print name */
 } mesg[];
index 26daf5a..99116b7 100644 (file)
@@ -77,11 +77,7 @@ extern       int dounsetenv();
 
 #define        INF     1000
 
-struct biltins {
-       char    *bname;
-       int     (*bfunct)();
-       short   minargs, maxargs;
-} bfunc[] = {
+struct biltins bfunc[] = {
        "@",            dolet,          0,      INF,
        "alias",        doalias,        0,      INF,
        "alloc",        showall,        0,      1,
@@ -175,10 +171,7 @@ int nbfunc = sizeof bfunc / sizeof *bfunc;
 #define        ZTHEN           17
 #define        ZWHILE          18
 
-struct srch {
-       char    *s_name;
-       short   s_value;
-} srchn[] = {
+struct srch srchn[] = {
        "@",            ZLET,
        "break",        ZBREAK,
        "breaksw",      ZBRKSW,
@@ -199,10 +192,7 @@ struct srch {
 };
 int nsrchn = sizeof srchn / sizeof *srchn;
 
-struct mesg {
-       char    *iname;
-       char    *pname;
-} mesg[] = {
+struct mesg mesg[] = {
        0,      0,
        "HUP",  "Hangup",
        "INT",  "Interrupt",    
index f5da907..3a1d19d 100644 (file)
@@ -1215,12 +1215,11 @@ again:
        if (fseekp >= feobp) {
                buf = (int) feobp / BUFSIZ;
                off = (int) feobp % BUFSIZ;
-#ifndef FILEC
-               for (;;) {
-                       c = read(SHIN, fbuf[buf] + off, BUFSIZ - off);
-#else
+#ifdef FILEC
                roomleft = BUFSIZ - off;
+#endif
                for (;;) {
+#ifdef FILEC
                        if (filec && intty) {
                                c = numleft ? numleft : tenex(ttyline, BUFSIZ);
                                if (c > roomleft) {
@@ -1230,10 +1229,12 @@ again:
                                        goto again;
                                }
                                if (c > 0)
-                                       copy(fbuf[buf] + off, ttyline, c);
+                                       bcopy(ttyline, fbuf[buf] + off, c);
                                numleft = 0;
                        } else
                                c = read(SHIN, fbuf[buf] + off, roomleft);
+#else
+                       c = read(SHIN, fbuf[buf] + off, BUFSIZ - off);
 #endif
                        if (c >= 0)
                                break;
@@ -1247,12 +1248,10 @@ again:
                if (c <= 0)
                        return (-1);
                feobp += c;
-#ifndef FILEC
-               goto again;
-#else
+#ifdef FILEC
                if (filec && !intty)
-                       goto again;
 #endif
+                       goto again;
        }
        c = fbuf[buf][(int) fseekp % BUFSIZ];
        fseekp++;
@@ -1300,16 +1299,6 @@ bseek(l)
 #endif
 }
 
-/* any similarity to bell telephone is purely accidental */
-#ifndef btell
-off_t
-btell()
-{
-
-       return (fseekp);
-}
-#endif
-
 btoeof()
 {
 
index aca92a2..3bec204 100644 (file)
 #undef OTHERSH
 #endif
 
-#ifdef vax
-#define        copy(to, from, size)    bcopy(from, to, size)
-#endif
-
-#ifdef PROF
-#define        exit(n) done(n)
-#endif
+/*#ifdef PROF*/
+/*#define      exit(n) done(n)*/
+/*#endif*/
index fd345b7..2ae46cd 100644 (file)
@@ -59,7 +59,7 @@ savestr(s)
        return (n);
 }
 
-char *
+void *
 calloc(i, j)
        register unsigned i;
        unsigned j;
@@ -286,19 +286,6 @@ renum(i, j)
        return (k);
 }
 
-#ifndef copy
-copy(to, from, size)
-       register char *to, *from;
-       register int size;
-{
-
-       if (size)
-               do
-                       *to++ = *from++;
-               while (--size != 0);
-}
-#endif
-
 /*
  * Left shift a command argument list, discarding
  * the first c arguments.  Used in "shift" commands
index 48dc60c..b71455e 100644 (file)
@@ -22,7 +22,7 @@ struct process        {
        struct  process *p_next;        /* next in global "proclist" */
        struct  process *p_friends;     /* next in job list (or self) */
        struct  directory *p_cwd;       /* cwd of the job (only in head) */
-       short   unsigned p_flags;       /* various job status flags */
+       unsigned short p_flags;         /* various job status flags */
        char    p_reason;               /* reason for entering this state */
        char    p_index;                /* shorthand job index */
        int     p_pid;
index 94c2613..0e30189 100644 (file)
@@ -16,7 +16,6 @@ static char *sccsid = "@(#)sh.sem.c   5.4 (Berkeley) 5/13/86";
  * C shell
  */
 
-/*VARARGS 1*/
 execute(t, wanttty, pipein, pipeout)
        register struct command *t;
        int wanttty, *pipein, *pipeout;
@@ -250,7 +249,11 @@ execute(t, wanttty, pipein, pipeout)
                didfds = 0;
                wanttty = -1;
                t->t_dspr->t_dflg |= t->t_dflg & FINT;
+#if defined(__STDC__) || defined(lint)
+               execute(t->t_dspr, wanttty, 0, 0);
+#else
                execute(t->t_dspr, wanttty);
+#endif
                exitstat();
 
        case TFIL:
@@ -267,7 +270,11 @@ execute(t, wanttty, pipein, pipeout)
        case TLST:
                if (t->t_dcar) {
                        t->t_dcar->t_dflg |= t->t_dflg & FINT;
+#if defined(__STDC__) || defined(lint)
+                       execute(t->t_dcar, wanttty, 0, 0);
+#else
                        execute(t->t_dcar, wanttty);
+#endif
                        /*
                         * In strange case of A&B make a new job after A
                         */
@@ -277,7 +284,11 @@ execute(t, wanttty, pipein, pipeout)
                }
                if (t->t_dcdr) {
                        t->t_dcdr->t_dflg |= t->t_dflg & (FPAR|FINT);
+#if defined(__STDC__) || defined(lint)
+                       execute(t->t_dcdr, wanttty, 0, 0);
+#else
                        execute(t->t_dcdr, wanttty);
+#endif
                }
                break;
 
@@ -285,13 +296,21 @@ execute(t, wanttty, pipein, pipeout)
        case TAND:
                if (t->t_dcar) {
                        t->t_dcar->t_dflg |= t->t_dflg & FINT;
+#if defined(__STDC__) || defined(lint)
+                       execute(t->t_dcar, wanttty, 0, 0);
+#else
                        execute(t->t_dcar, wanttty);
+#endif
                        if ((getn(value("status")) == 0) != (t->t_dtyp == TAND))
                                return;
                }
                if (t->t_dcdr) {
                        t->t_dcdr->t_dflg |= t->t_dflg & (FPAR|FINT);
+#if defined(__STDC__) || defined(lint)
+                       execute(t->t_dcdr, wanttty, 0, 0);
+#else
                        execute(t->t_dcdr, wanttty);
+#endif
                }
                break;
        }
index d8682d9..30ffd3e 100644 (file)
@@ -275,10 +275,9 @@ putn(n)
        if (sizeof (int) == 2 && n == -32768) {
                *putp++ = '3';
                n = 2768;
-#ifdef pdp11
        }
-#else
-       else if (sizeof (int) == 4 && n == -2147483648) {
+#ifndef pdp11
+       else if (sizeof (int) == 4 && n == -2147483648) {
                *putp++ = '2';
                n = 147483648;
        }
index 5731d0c..f49d116 100644 (file)
@@ -109,7 +109,8 @@ static findbucket __P((union overhead *freep, int srchlen));
 void *malloc(nbytes) unsigned nbytes; {
        register union overhead *op;
        register int bucket;
-       register unsigned amt, n;
+       register unsigned amt;
+       register int n;
 
        /*
         * First time malloc is called, setup page size and
index a51a3b8..4610076 100755 (executable)
@@ -27,6 +27,7 @@ then
   echo "===stage 0==="
 
   rm -f *.[ch].allprotos
+  rm -f *.[ch].cproto
   rm -f *.[ch].nocomm
   rm -f *.[ch].oldprotos
   rm -f *.[ch].protos
@@ -35,6 +36,7 @@ then
   rm -f *.[ch].uses
   rm -rf .xify
   #rm -f `find . -name '*.[ch].allprotos' -print`
+  #rm -f `find . -name '*.[ch].cproto' -print`
   #rm -f `find . -name '*.[ch].nocomm' -print`
   #rm -f `find . -name '*.[ch].oldprotos' -print`
   #rm -f `find . -name '*.[ch].protos' -print`
@@ -103,16 +105,16 @@ then
     sed -e 's/^\(#[     ]*\(else\|endif\)\)\([^0-9A-Za-z_].*\)\?/\1/' -i $i
 
     rm -f xx*
-    csplit -b '%05d' -q $i '/^#[        ]*ifndef[       ]*lint$/' '{*}'
+    csplit -b '%05d' -q $i '/^#[        ]*if.*\(SCCS\|lint\)/' '{*}'
     for j in xx*
     do
       if test $j != xx00000 && sed -ne '2p' $j |grep -q 'char[  ]*\(copyright[  ]*\[[   ]*\]\|\*[       ]*copyright\)[  ]*='
       then
-        sed -e 's/^\(#[         ]*if\)ndef\([   ]*\)lint$/\1\2defined(DOCOPYRIGHT) \&\& !defined(lint)/' -i $j
+        sed -e 's/^\(#[         ]*if\).*\(SCCS\|lint\).*$/\1 defined(DOCOPYRIGHT) \&\& !defined(lint)/' -i $j
       fi
       if test $j != xx00000 && sed -ne '2p' $j |grep -q 'char[  ]*\(sccsid[     ]*\[[   ]*\]\|\*[       ]*sccsid\)[     ]*='
       then
-        sed -e 's/^\(#[         ]*if\)ndef\([   ]*\)lint$/\1\2defined(DOSCCS) \&\& !defined(lint)/' -i $j
+        sed -e 's/^\(#[         ]*if\).*\(SCCS\|lint\).*$/\1 defined(DOSCCS) \&\& !defined(lint)/' -i $j
       else
         sed -e 's/^.*char[      ]*\(sccsid[     ]*\[[   ]*\]\|\*[       ]*sccsid\)[     ]*=.*$/#if defined(DOSCCS) \&\& !defined(lint)\n&\n#endif/' -i $j
       fi
@@ -161,6 +163,7 @@ then
     fi
     echo "group=$group"
 
+    cp $i $i.cproto
     $ROOT/cproto-4.6/cproto -i$INCLUDE -Dvax -t -H -s $i |sed -ne '2,$p' >$i.allprotos
     if ! grep -qv '^int main __P((' $i.allprotos
     then
@@ -483,7 +486,7 @@ then
     for j in xx*
     do
       sed -e 's/^#[     ]*include[      ]*\(<[^>]*>\|"[^"]*"\)/\/\*&\*\//' -i $j
-      if grep -v "^#[   ]*include[^0-9A-Za-z_]" $j |sed -e '/^#[        ]*if.*SCCS\|lint/,/^#[  ]*endif/s/.*//' |$SCRIPTS/nocomment |grep -q '[^        ]'
+      if grep -v "^#[   ]*include[^0-9A-Za-z_]" $j |sed -e '/^#[        ]*if.*\(SCCS\|lint\)/,/^#[      ]*endif/s/.*//' |$SCRIPTS/nocomment |grep -q '[^        ]'
       then
         break
       fi
index 947028a..ee40136 100644 (file)
@@ -49,6 +49,7 @@ int main() {
               l = m - 4;
             }
             else if (
+              (l != 0 || m != 8 || memcmp(p, "setjmp.h", 8) != 0) &&
               (l != 0 || m != 8 || memcmp(p, "stdarg.h", 8) != 0) &&
               (l != 0 || m != 8 || memcmp(p, "stdint.h", 8) != 0) &&
               (l != 0 || m != 9 || memcmp(p, "varargs.h", 9) != 0)
@@ -106,8 +107,11 @@ int main() {
               (m != 7 || memcmp(q, "int32_t", 7) != 0) &&
               (m != 7 || memcmp(q, "int64_t", 7) != 0) &&
               (m != 8 || memcmp(q, "intptr_t", 8) != 0) &&
+              (m != 7 || memcmp(q, "jmp_buf", 7) != 0) &&
               (m != 4 || memcmp(q, "long", 4) != 0) &&
               (m != 5 || memcmp(q, "short", 5) != 0) &&
+              (m != 6 || memcmp(q, "size_t", 6) != 0) &&
+              (m != 7 || memcmp(q, "ssize_t", 7) != 0) &&
               (m != 6 || memcmp(q, "struct", 6) != 0) &&
               (m != 7 || memcmp(q, "uint8_t", 7) != 0) &&
               (m != 8 || memcmp(q, "uint16_t", 8) != 0) &&
@@ -226,9 +230,14 @@ int main() {
           (l != 8 || memcmp(p, "intptr_t", 8) != 0) &&
           (l != 3 || memcmp(p, "for", 3) != 0) &&
           (l != 4 || memcmp(p, "goto", 4) != 0) &&
+          (l != 7 || memcmp(p, "jmp_buf", 7) != 0) &&
+          (l != 7 || memcmp(p, "longjmp", 7) != 0) &&
           (l != 6 || memcmp(p, "return", 6) != 0) &&
           (l != 8 || memcmp(p, "register", 8) != 0) &&
+          (l != 6 || memcmp(p, "setjmp", 6) != 0) &&
           (l != 6 || memcmp(p, "sizeof", 6) != 0) &&
+          /*(l != 6 || memcmp(p, "size_t", 6) != 0) &&
+          (l != 7 || memcmp(p, "ssize_t", 7) != 0) &&*/
           (l != 6 || memcmp(p, "static", 6) != 0) &&
           (l != 6 || memcmp(p, "struct", 6) != 0) &&
           (l != 6 || memcmp(p, "switch", 6) != 0) &&