Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Have "make clean" remove sh.html1 and adapt it to cle...
details: https://anonhg.NetBSD.org/src/rev/f187c42e0efd
branches: trunk
changeset: 352110:f187c42e0efd
user: kre <kre%NetBSD.org@localhost>
date: Thu Mar 16 13:09:06 2017 +0000
description:
Have "make clean" remove sh.html1 and adapt it to clean trace files
the way they have been generated the past 20 years or so...
diffstat:
bin/sh/Makefile | 6 +-
bin/sh/show.c | 1285 +++++++++++++++++++++++++++++++++++++-----------------
bin/sh/show.h | 4 +-
3 files changed, 880 insertions(+), 415 deletions(-)
diffs (truncated from 1431 to 300 lines):
diff -r 3d0aa5a42c23 -r f187c42e0efd bin/sh/Makefile
--- a/bin/sh/Makefile Thu Mar 16 09:43:56 2017 +0000
+++ b/bin/sh/Makefile Thu Mar 16 13:09:06 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.102 2016/02/27 18:34:12 christos Exp $
+# $NetBSD: Makefile,v 1.103 2017/03/16 13:09:06 kre Exp $
# @(#)Makefile 8.4 (Berkeley) 5/5/95
.include <bsd.own.mk>
@@ -53,8 +53,8 @@
${NETBSDSRCDIR}/usr.bin/printf \
${NETBSDSRCDIR}/bin/kill
-CLEANFILES+= ${GENSRCS} ${GENHDRS} y.tab.h
-CLEANFILES+= trace
+CLEANFILES+= ${GENSRCS} ${GENHDRS} y.tab.h sh.html1
+CLEANFILES+= trace.*
token.h: mktokens
${_MKTARGET_CREATE}
diff -r 3d0aa5a42c23 -r f187c42e0efd bin/sh/show.c
--- a/bin/sh/show.c Thu Mar 16 09:43:56 2017 +0000
+++ b/bin/sh/show.c Thu Mar 16 13:09:06 2017 +0000
@@ -1,9 +1,11 @@
-/* $NetBSD: show.c,v 1.34 2016/10/23 08:24:27 abhinav Exp $ */
+/* $NetBSD: show.c,v 1.35 2017/03/16 13:09:06 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.
*
@@ -15,14 +17,16 @@
* 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 nor the names of its 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, 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.
*
- * 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
+ * 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
* 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)
@@ -37,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)show.c 8.3 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: show.c,v 1.34 2016/10/23 08:24:27 abhinav Exp $");
+__RCSID("$NetBSD: show.c,v 1.35 2017/03/16 13:09:06 kre Exp $");
#endif
#endif /* not lint */
@@ -45,6 +49,10 @@
#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"
@@ -52,390 +60,903 @@
#include "mystring.h"
#include "show.h"
#include "options.h"
-#ifndef SMALL
+#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
+
#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)
Home |
Main Index |
Thread Index |
Old Index