BSD 4_4_Lite2 release
[unix-history] / usr / src / bin / sh / show.c
index 0f6b555..4319809 100644 (file)
@@ -1,6 +1,6 @@
 /*-
 /*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Kenneth Almquist.
  *
  * This code is derived from software contributed to Berkeley by
  * Kenneth Almquist.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)show.c     5.2 (Berkeley) 4/12/91";
+static char sccsid[] = "@(#)show.c     8.3 (Berkeley) 5/4/95";
 #endif /* not lint */
 
 #include <stdio.h>
 #endif /* not lint */
 
 #include <stdio.h>
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
 #include "shell.h"
 #include "parser.h"
 #include "nodes.h"
 #include "mystring.h"
 #include "shell.h"
 #include "parser.h"
 #include "nodes.h"
 #include "mystring.h"
+#include "show.h"
 
 
 #ifdef DEBUG
 
 
 #ifdef DEBUG
-static shtree(), shcmd(), sharg(), indent();
+static void shtree __P((union node *, int, char *, FILE*));
+static void shcmd __P((union node *, FILE *));
+static void sharg __P((union node *, FILE *));
+static void indent __P((int, char *, FILE *));
+static void trstring __P((char *));
 
 
 
 
+void
 showtree(n)
        union node *n;
 showtree(n)
        union node *n;
-       {
+{
        trputs("showtree called\n");
        shtree(n, 1, NULL, stdout);
 }
 
 
        trputs("showtree called\n");
        shtree(n, 1, NULL, stdout);
 }
 
 
-static
+static void
 shtree(n, ind, pfx, fp)
        union node *n;
 shtree(n, ind, pfx, fp)
        union node *n;
+       int ind;
        char *pfx;
        FILE *fp;
        char *pfx;
        FILE *fp;
-       {
+{
        struct nodelist *lp;
        char *s;
 
        struct nodelist *lp;
        char *s;
 
+       if (n == NULL)
+               return;
+
        indent(ind, pfx, fp);
        switch(n->type) {
        case NSEMI:
        indent(ind, pfx, fp);
        switch(n->type) {
        case NSEMI:
@@ -108,11 +124,11 @@ binop:
 
 
 
 
 
 
-static
+static void
 shcmd(cmd, fp)
        union node *cmd;
        FILE *fp;
 shcmd(cmd, fp)
        union node *cmd;
        FILE *fp;
-       {
+{
        union node *np;
        int first;
        char *s;
        union node *np;
        int first;
        char *s;
@@ -134,6 +150,7 @@ shcmd(cmd, fp)
                        case NTOFD:     s = ">&"; dftfd = 1; break;
                        case NFROM:     s = "<";  dftfd = 0; break;
                        case NFROMFD:   s = "<&"; dftfd = 0; break;
                        case NTOFD:     s = ">&"; dftfd = 1; break;
                        case NFROM:     s = "<";  dftfd = 0; break;
                        case NFROMFD:   s = "<&"; dftfd = 0; break;
+                       default:        s = "*error*"; dftfd = 0; break;
                }
                if (np->nfile.fd != dftfd)
                        fprintf(fp, "%d", np->nfile.fd);
                }
                if (np->nfile.fd != dftfd)
                        fprintf(fp, "%d", np->nfile.fd);
@@ -149,7 +166,7 @@ shcmd(cmd, fp)
 
 
 
 
 
 
-static
+static void
 sharg(arg, fp)
        union node *arg;
        FILE *fp;
 sharg(arg, fp)
        union node *arg;
        FILE *fp;
@@ -173,10 +190,15 @@ sharg(arg, fp)
                        putc('$', fp);
                        putc('{', fp);
                        subtype = *++p;
                        putc('$', fp);
                        putc('{', fp);
                        subtype = *++p;
+                       if (subtype == VSLENGTH)
+                               putc('#', fp);
+
                        while (*p != '=')
                                putc(*p++, fp);
                        while (*p != '=')
                                putc(*p++, fp);
+
                        if (subtype & VSNUL)
                                putc(':', fp);
                        if (subtype & VSNUL)
                                putc(':', fp);
+
                        switch (subtype & VSTYPE) {
                        case VSNORMAL:
                                putc('}', fp);
                        switch (subtype & VSTYPE) {
                        case VSNORMAL:
                                putc('}', fp);
@@ -193,6 +215,22 @@ sharg(arg, fp)
                        case VSASSIGN:
                                putc('=', fp);
                                break;
                        case VSASSIGN:
                                putc('=', fp);
                                break;
+                       case VSTRIMLEFT:
+                               putc('#', fp);
+                               break;
+                       case VSTRIMLEFTMAX:
+                               putc('#', fp);
+                               putc('#', fp);
+                               break;
+                       case VSTRIMRIGHT:
+                               putc('%', fp);
+                               break;
+                       case VSTRIMRIGHTMAX:
+                               putc('%', fp);
+                               putc('%', fp);
+                               break;
+                       case VSLENGTH:
+                               break;
                        default:
                                printf("<subtype %d>", subtype);
                        }
                        default:
                                printf("<subtype %d>", subtype);
                        }
@@ -215,11 +253,12 @@ sharg(arg, fp)
 }
 
 
 }
 
 
-static
+static void
 indent(amount, pfx, fp)
 indent(amount, pfx, fp)
+       int amount;
        char *pfx;
        FILE *fp;
        char *pfx;
        FILE *fp;
-       {
+{
        int i;
 
        for (i = 0 ; i < amount ; i++) {
        int i;
 
        for (i = 0 ; i < amount ; i++) {
@@ -246,7 +285,10 @@ int debug = 0;
 #endif
 
 
 #endif
 
 
-trputc(c) {
+void
+trputc(c) 
+       int c;
+{
 #ifdef DEBUG
        if (tracefile == NULL)
                return;
 #ifdef DEBUG
        if (tracefile == NULL)
                return;
@@ -256,23 +298,37 @@ trputc(c) {
 #endif
 }
 
 #endif
 }
 
-
-trace(fmt, a1, a2, a3, a4, a5, a6, a7, a8)
-       char *fmt;
-       {
+void
+#if __STDC__
+trace(const char *fmt, ...)
+#else
+trace(va_alist)
+       va_dcl
+#endif
+{
 #ifdef DEBUG
 #ifdef DEBUG
-       if (tracefile == NULL)
-               return;
-       fprintf(tracefile, fmt, a1, a2, a3, a4, a5, a6, a7, a8);
-       if (strchr(fmt, '\n'))
-               fflush(tracefile);
+       va_list va;
+#if __STDC__
+       va_start(va, fmt);
+#else
+       char *fmt;
+       va_start(va);
+       fmt = va_arg(va, char *);
+#endif
+       if (tracefile != NULL) {
+               (void) vfprintf(tracefile, fmt, va);
+               if (strchr(fmt, '\n'))
+                       (void) fflush(tracefile);
+       }
+       va_end(va);
 #endif
 }
 
 
 #endif
 }
 
 
+void
 trputs(s)
        char *s;
 trputs(s)
        char *s;
-       {
+{
 #ifdef DEBUG
        if (tracefile == NULL)
                return;
 #ifdef DEBUG
        if (tracefile == NULL)
                return;
@@ -283,9 +339,10 @@ trputs(s)
 }
 
 
 }
 
 
+static void
 trstring(s)
        char *s;
 trstring(s)
        char *s;
-       {
+{
        register char *p;
        char c;
 
        register char *p;
        char c;
 
@@ -325,9 +382,10 @@ backslash:   putc('\\', tracefile);
 }
 
 
 }
 
 
+void
 trargs(ap)
        char **ap;
 trargs(ap)
        char **ap;
-       {
+{
 #ifdef DEBUG
        if (tracefile == NULL)
                return;
 #ifdef DEBUG
        if (tracefile == NULL)
                return;
@@ -343,24 +401,29 @@ trargs(ap)
 }
 
 
 }
 
 
+void
 opentrace() {
        char s[100];
 opentrace() {
        char s[100];
-       char *p;
        char *getenv();
        char *getenv();
+#ifdef O_APPEND
        int flags;
        int flags;
+#endif
 
 #ifdef DEBUG
        if (!debug)
                return;
 #ifdef not_this_way
 
 #ifdef DEBUG
        if (!debug)
                return;
 #ifdef not_this_way
-       if ((p = getenv("HOME")) == NULL) {
-               if (geteuid() == 0)
-                       p = "/";
-               else
-                       p = "/tmp";
+       {
+               char *p;
+               if ((p = getenv("HOME")) == NULL) {
+                       if (geteuid() == 0)
+                               p = "/";
+                       else
+                               p = "/tmp";
+               }
+               scopy(p, s);
+               strcat(s, "/trace");
        }
        }
-       scopy(p, s);
-       strcat(s, "/trace");
 #else
        scopy("./trace", s);
 #endif /* not_this_way */
 #else
        scopy("./trace", s);
 #endif /* not_this_way */