Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Undo local changes not intended to be committed (and ...



details:   https://anonhg.NetBSD.org/src/rev/11436274ecb8
branches:  trunk
changeset: 822362:11436274ecb8
user:      kre <kre%NetBSD.org@localhost>
date:      Thu Mar 16 13:21:59 2017 +0000

description:
Undo local changes not intended to be committed (and certainly not
with that commit message) in the previous update.   This stuff works,
and will probably appear sometime, but not right now.

diffstat:

 bin/sh/show.c |  1287 ++++++++++++++++++--------------------------------------
 bin/sh/show.h |     4 +-
 2 files changed, 413 insertions(+), 878 deletions(-)

diffs (truncated from 1412 to 300 lines):

diff -r ff1d433c04ab -r 11436274ecb8 bin/sh/show.c
--- a/bin/sh/show.c     Thu Mar 16 13:09:06 2017 +0000
+++ b/bin/sh/show.c     Thu Mar 16 13:21:59 2017 +0000
@@ -1,11 +1,9 @@
-/*     $NetBSD: show.c,v 1.35 2017/03/16 13:09:06 kre Exp $    */
+/*     $NetBSD: show.c,v 1.36 2017/03/16 13:21:59 kre Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
- * Copyright (c) 2016,2017 The NetBSD Foundation, Inc.  All rights reserved.
- *
  * This code is derived from software contributed to Berkeley by
  * Kenneth Almquist.
  *
@@ -17,16 +15,14 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University, the NetBSD Foundation, nor the
- *    names of their contributors may be used to endorse or promote products
- *    derived from this software without specific prior written permission.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS, FOUNDATION, AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED.
- *
- * IN NO EVENT SHALL THE REGENTS, FOUNDATION OR CONTRIBUTORS BE LIABLE
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -41,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)show.c     8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: show.c,v 1.35 2017/03/16 13:09:06 kre Exp $");
+__RCSID("$NetBSD: show.c,v 1.36 2017/03/16 13:21:59 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -49,10 +45,6 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <sys/uio.h>
 
 #include "shell.h"
 #include "parser.h"
@@ -60,903 +52,390 @@
 #include "mystring.h"
 #include "show.h"
 #include "options.h"
-#include "redir.h"
-#include "error.h"
-
-#if defined(DEBUG) && !defined(DBG_PID)
-/*
- * If this is compiled, it means this is being compiled in a shell that still
- * has an older shell.h (a simpler TRACE() mechanism than is coming soon.)
- *
- * Compensate for as much of that as is missing and is needed here
- * to compile and operate at all.   After the other changes have appeared,
- * this little block can (and should be) deleted (sometime).
- *
- * Try to avoid waiting 22 years...
- */
-#define        DBG_PID         1
-#define        DBG_NEST        2
-
-/* decide at compile time for now (DBG_NEST won't work) */
-static int DFlags = DBG_PID;
-static int ShNest = 0;
-#endif
-
+#ifndef SMALL
 #define DEFINE_NODENAMES
 #include "nodenames.h"
-
-#define        TR_STD_WIDTH    60      /* tend to fold lines wider than this */
-#define        TR_IOVECS       10      /* number of lines or trace (max) / write */
-
-typedef struct traceinfo {
-       int     tfd;    /* file descriptor for open trace file */
-       int     nxtiov; /* the buffer we should be writing to */
-       char    lastc;  /* the last non-white character output */
-       uint8_t supr;   /* char classes to supress after \n */
-       pid_t   pid;    /* process id of process that opened that file */
-       size_t  llen;   /* number of chars in current output line */
-       size_t  blen;   /* chars used in current buffer being filled */
-       char *  tracefile;              /* name of the tracefile */
-       struct iovec lines[TR_IOVECS];  /* filled, flling, pending buffers */
-} TFILE;
-
-/* These are auto turned off when non white space is printed */
-#define        SUP_NL  0x01    /* don't print \n */
-#define        SUP_SP  0x03    /* supress spaces */
-#define        SUP_WSP 0x04    /* supress all white space */
-
-#ifdef DEBUG
-TFILE tracedata, *tracetfile;
-FILE *tracefile;               /* just for histedit */
-#endif
-
-#ifdef DEBUG
-static void shtree(union node *, int, int, int, TFILE *);
-static void shcmd(union node *, TFILE *);
-static void shsubsh(union node *, TFILE *);
-static void shredir(union node *, TFILE *, int);
-static void sharg(union node *, TFILE *);
-static void indent(int, TFILE *);
-static void trstring(const char *);
-static void trace_putc(char, TFILE *);
-static void trace_puts(const char *, TFILE *);
-static void trace_flush(TFILE *, int);
-static char *trace_id(TFILE *);
-
-inline static int trlinelen(TFILE *);
 #endif
 
 
+FILE *tracefile;
+
+#ifdef DEBUG
+static int shtree(union node *, int, int, char *, FILE*);
+static int shcmd(union node *, FILE *);
+static int shsubsh(union node *, FILE *);
+static int shredir(union node *, FILE *, int);
+static int sharg(union node *, FILE *);
+static int indent(int, char *, FILE *);
+static void trstring(char *);
+
+void
+showtree(union node *n)
+{
+       FILE *fp;
+
+       fp = tracefile ? tracefile : stdout;
+
+       trputs("showtree(");
+               if (n == NULL)
+                       trputs("NULL");
+               else if (n == NEOF)
+                       trputs("NEOF");
+       trputs(") called\n");
+       if (n != NULL && n != NEOF)
+               shtree(n, 1, 1, NULL, fp);
+}
+
+
+static int
+shtree(union node *n, int ind, int nl, char *pfx, FILE *fp)
+{
+       struct nodelist *lp;
+       const char *s;
+       int len;
+
+       if (n == NULL) {
+               if (nl)
+                       fputc('\n', fp);
+               return 0;
+       }
+
+       len = indent(ind, pfx, fp);
+       switch (n->type) {
+       case NSEMI:
+               s = "; ";
+               len += 2;
+               goto binop;
+       case NAND:
+               s = " && ";
+               len += 4;
+               goto binop;
+       case NOR:
+               s = " || ";
+               len += 4;
+binop:
+               len += shtree(n->nbinary.ch1, 0, 0, NULL, fp);
+               fputs(s, fp);
+               if (len >= 60) {
+                       putc('\n', fp);
+                       len = indent(ind < 0 ? 2 : ind + 1, pfx, fp);
+               }
+               len += shtree(n->nbinary.ch2, 0, nl, NULL, fp);
+               break;
+       case NCMD:
+               len += shcmd(n, fp);
+               if (nl && len > 0)
+                       len = 0, putc('\n', fp);
+               break;
+       case NPIPE:
+               for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
+                       len += shcmd(lp->n, fp);
+                       if (lp->next) {
+                               len += 3, fputs(" | ", fp);
+                               if (len >= 60)  {
+                                       fputc('\n', fp);
+                                       len = indent(ind < 0 ? 2 : ind + 1,
+                                           pfx, fp);
+                               }
+                       }
+               }
+               if (n->npipe.backgnd)
+                       len += 2, fputs(" &", fp);
+               if (nl || len >= 60)
+                       len = 0, fputc('\n', fp);
+               break;
+       case NSUBSHELL:
+               len += shsubsh(n, fp);
+               if (nl && len > 0)
+                       len = 0, putc('\n', fp);
+               break;
+       default:
+#ifdef NODETYPENAME
+               len += fprintf(fp, "<node type %d [%s]>", n->type,
+                   NODETYPENAME(n->type));
+#else
+               len += fprintf(fp, "<node type %d>", n->type);
+#endif
+               if (nl)
+                       len = 0, putc('\n', fp);
+               break;
+       }
+       return len;
+}
+
+
+
+static int
+shcmd(union node *cmd, FILE *fp)
+{
+       union node *np;
+       int first;
+       int len = 0;
+
+       first = 1;
+       for (np = cmd->ncmd.args ; np ; np = np->narg.next) {
+               if (! first)
+                       len++, fputc(' ', fp);
+               len += sharg(np, fp);
+               first = 0;
+       }
+       return len + shredir(cmd, fp, first);
+}
+
+static int
+shsubsh(union node *cmd, FILE *fp)
+{
+       int len = 6;
+
+       fputs(" ( ", fp);
+       len += shtree(cmd->nredir.n, -1, 0, NULL, fp);
+       fputs(" ) ", fp);
+       len += shredir(cmd, fp, 1);
+
+       return len;
+}
+
+static int
+shredir(union node *cmd, FILE *fp, int first)
+{
+       union node *np;
+       const char *s;
+       int dftfd;
+       int len = 0;
+       char buf[106];
+
+       for (np = cmd->ncmd.redirect ; np ; np = np->nfile.next) {
+               if (! first)
+                       len++, fputc(' ', fp);
+               switch (np->nfile.type) {
+                       case NTO:       s = ">";  dftfd = 1; len += 1; break;
+                       case NCLOBBER:  s = ">|"; dftfd = 1; len += 2; break;
+                       case NAPPEND:   s = ">>"; dftfd = 1; len += 2; break;
+                       case NTOFD:     s = ">&"; dftfd = 1; len += 2; break;
+                       case NFROM:     s = "<";  dftfd = 0; len += 1; break;
+                       case NFROMFD:   s = "<&"; dftfd = 0; len += 2; break;
+                       case NFROMTO:   s = "<>"; dftfd = 0; len += 2; break;
+                       case NXHERE:    /* FALLTHROUGH */ 
+                       case NHERE:     s = "<<"; dftfd = 0; len += 2; break;
+                       default:   s = "*error*"; dftfd = 0; len += 7; break;
+               }
+               if (np->nfile.fd != dftfd)
+                       len += fprintf(fp, "%d", np->nfile.fd);
+               fputs(s, fp);
+               if (np->nfile.type == NTOFD || np->nfile.type == NFROMFD) {
+                       len += fprintf(fp, "%d", np->ndup.dupfd);
+               } else
+                   if (np->nfile.type == NHERE || np->nfile.type == NXHERE) {



Home | Main Index | Thread Index | Old Index