14b88c807SRodney W. Grimes /*- 24b88c807SRodney W. Grimes * Copyright (c) 1991, 1993 34b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 44b88c807SRodney W. Grimes * 54b88c807SRodney W. Grimes * This code is derived from software contributed to Berkeley by 64b88c807SRodney W. Grimes * Kenneth Almquist. 74b88c807SRodney W. Grimes * 84b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 94b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 104b88c807SRodney W. Grimes * are met: 114b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 124b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 134b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 144b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 154b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 164b88c807SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 174b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 184b88c807SRodney W. Grimes * without specific prior written permission. 194b88c807SRodney W. Grimes * 204b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 214b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 244b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304b88c807SRodney W. Grimes * SUCH DAMAGE. 314b88c807SRodney W. Grimes */ 324b88c807SRodney W. Grimes 334b88c807SRodney W. Grimes #ifndef lint 343d7b5b93SPhilippe Charnier #if 0 353d7b5b93SPhilippe Charnier static char sccsid[] = "@(#)show.c 8.3 (Berkeley) 5/4/95"; 363d7b5b93SPhilippe Charnier #endif 374b88c807SRodney W. Grimes #endif /* not lint */ 382749b141SDavid E. O'Brien #include <sys/cdefs.h> 392749b141SDavid E. O'Brien __FBSDID("$FreeBSD$"); 404b88c807SRodney W. Grimes 416da31df8STim J. Robbins #include <fcntl.h> 424b88c807SRodney W. Grimes #include <stdio.h> 436da31df8STim J. Robbins #include <stdlib.h> 44aa9caaf6SPeter Wemm #include <stdarg.h> 45d62ec71cSMartin Cracauer #include <errno.h> 46aa9caaf6SPeter Wemm 474b88c807SRodney W. Grimes #include "shell.h" 484b88c807SRodney W. Grimes #include "parser.h" 494b88c807SRodney W. Grimes #include "nodes.h" 504b88c807SRodney W. Grimes #include "mystring.h" 51aa9caaf6SPeter Wemm #include "show.h" 524b88c807SRodney W. Grimes 534b88c807SRodney W. Grimes 544b88c807SRodney W. Grimes #ifdef DEBUG 5588328642SDavid E. O'Brien static void shtree(union node *, int, char *, FILE*); 5688328642SDavid E. O'Brien static void shcmd(union node *, FILE *); 5788328642SDavid E. O'Brien static void sharg(union node *, FILE *); 5888328642SDavid E. O'Brien static void indent(int, char *, FILE *); 5988328642SDavid E. O'Brien static void trstring(char *); 604b88c807SRodney W. Grimes 614b88c807SRodney W. Grimes 62aa9caaf6SPeter Wemm void 635134c3f7SWarner Losh showtree(union node *n) 644b88c807SRodney W. Grimes { 654b88c807SRodney W. Grimes trputs("showtree called\n"); 664b88c807SRodney W. Grimes shtree(n, 1, NULL, stdout); 674b88c807SRodney W. Grimes } 684b88c807SRodney W. Grimes 694b88c807SRodney W. Grimes 7088328642SDavid E. O'Brien static void 715134c3f7SWarner Losh shtree(union node *n, int ind, char *pfx, FILE *fp) 724b88c807SRodney W. Grimes { 734b88c807SRodney W. Grimes struct nodelist *lp; 744b88c807SRodney W. Grimes char *s; 754b88c807SRodney W. Grimes 76aa9caaf6SPeter Wemm if (n == NULL) 77aa9caaf6SPeter Wemm return; 78aa9caaf6SPeter Wemm 794b88c807SRodney W. Grimes indent(ind, pfx, fp); 804b88c807SRodney W. Grimes switch(n->type) { 814b88c807SRodney W. Grimes case NSEMI: 824b88c807SRodney W. Grimes s = "; "; 834b88c807SRodney W. Grimes goto binop; 844b88c807SRodney W. Grimes case NAND: 854b88c807SRodney W. Grimes s = " && "; 864b88c807SRodney W. Grimes goto binop; 874b88c807SRodney W. Grimes case NOR: 884b88c807SRodney W. Grimes s = " || "; 894b88c807SRodney W. Grimes binop: 904b88c807SRodney W. Grimes shtree(n->nbinary.ch1, ind, NULL, fp); 914b88c807SRodney W. Grimes /* if (ind < 0) */ 924b88c807SRodney W. Grimes fputs(s, fp); 934b88c807SRodney W. Grimes shtree(n->nbinary.ch2, ind, NULL, fp); 944b88c807SRodney W. Grimes break; 954b88c807SRodney W. Grimes case NCMD: 964b88c807SRodney W. Grimes shcmd(n, fp); 974b88c807SRodney W. Grimes if (ind >= 0) 984b88c807SRodney W. Grimes putc('\n', fp); 994b88c807SRodney W. Grimes break; 1004b88c807SRodney W. Grimes case NPIPE: 1014b88c807SRodney W. Grimes for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) { 1024b88c807SRodney W. Grimes shcmd(lp->n, fp); 1034b88c807SRodney W. Grimes if (lp->next) 1044b88c807SRodney W. Grimes fputs(" | ", fp); 1054b88c807SRodney W. Grimes } 1064b88c807SRodney W. Grimes if (n->npipe.backgnd) 1074b88c807SRodney W. Grimes fputs(" &", fp); 1084b88c807SRodney W. Grimes if (ind >= 0) 1094b88c807SRodney W. Grimes putc('\n', fp); 1104b88c807SRodney W. Grimes break; 1114b88c807SRodney W. Grimes default: 1124b88c807SRodney W. Grimes fprintf(fp, "<node type %d>", n->type); 1134b88c807SRodney W. Grimes if (ind >= 0) 1144b88c807SRodney W. Grimes putc('\n', fp); 1154b88c807SRodney W. Grimes break; 1164b88c807SRodney W. Grimes } 1174b88c807SRodney W. Grimes } 1184b88c807SRodney W. Grimes 1194b88c807SRodney W. Grimes 1204b88c807SRodney W. Grimes 12188328642SDavid E. O'Brien static void 1225134c3f7SWarner Losh shcmd(union node *cmd, FILE *fp) 1234b88c807SRodney W. Grimes { 1244b88c807SRodney W. Grimes union node *np; 1254b88c807SRodney W. Grimes int first; 1264b88c807SRodney W. Grimes char *s; 1274b88c807SRodney W. Grimes int dftfd; 1284b88c807SRodney W. Grimes 1294b88c807SRodney W. Grimes first = 1; 1304b88c807SRodney W. Grimes for (np = cmd->ncmd.args ; np ; np = np->narg.next) { 1314b88c807SRodney W. Grimes if (! first) 1324b88c807SRodney W. Grimes putchar(' '); 1334b88c807SRodney W. Grimes sharg(np, fp); 1344b88c807SRodney W. Grimes first = 0; 1354b88c807SRodney W. Grimes } 1364b88c807SRodney W. Grimes for (np = cmd->ncmd.redirect ; np ; np = np->nfile.next) { 1374b88c807SRodney W. Grimes if (! first) 1384b88c807SRodney W. Grimes putchar(' '); 1394b88c807SRodney W. Grimes switch (np->nfile.type) { 1404b88c807SRodney W. Grimes case NTO: s = ">"; dftfd = 1; break; 1414b88c807SRodney W. Grimes case NAPPEND: s = ">>"; dftfd = 1; break; 1424b88c807SRodney W. Grimes case NTOFD: s = ">&"; dftfd = 1; break; 1431a958c66STim J. Robbins case NCLOBBER: s = ">|"; dftfd = 1; break; 1444b88c807SRodney W. Grimes case NFROM: s = "<"; dftfd = 0; break; 1454682f420SBrian Somers case NFROMTO: s = "<>"; dftfd = 0; break; 1464b88c807SRodney W. Grimes case NFROMFD: s = "<&"; dftfd = 0; break; 14762463f67SJens Schweikhardt case NHERE: s = "<<"; dftfd = 0; break; 14862463f67SJens Schweikhardt case NXHERE: s = "<<"; dftfd = 0; break; 149aa9caaf6SPeter Wemm default: s = "*error*"; dftfd = 0; break; 1504b88c807SRodney W. Grimes } 1514b88c807SRodney W. Grimes if (np->nfile.fd != dftfd) 1524b88c807SRodney W. Grimes fprintf(fp, "%d", np->nfile.fd); 1534b88c807SRodney W. Grimes fputs(s, fp); 1544b88c807SRodney W. Grimes if (np->nfile.type == NTOFD || np->nfile.type == NFROMFD) { 15590735447STim J. Robbins if (np->ndup.dupfd >= 0) 1564b88c807SRodney W. Grimes fprintf(fp, "%d", np->ndup.dupfd); 15790735447STim J. Robbins else 15890735447STim J. Robbins fprintf(fp, "-"); 15962463f67SJens Schweikhardt } else if (np->nfile.type == NHERE) { 16062463f67SJens Schweikhardt fprintf(fp, "HERE"); 16162463f67SJens Schweikhardt } else if (np->nfile.type == NXHERE) { 16262463f67SJens Schweikhardt fprintf(fp, "XHERE"); 1634b88c807SRodney W. Grimes } else { 1644b88c807SRodney W. Grimes sharg(np->nfile.fname, fp); 1654b88c807SRodney W. Grimes } 1664b88c807SRodney W. Grimes first = 0; 1674b88c807SRodney W. Grimes } 1684b88c807SRodney W. Grimes } 1694b88c807SRodney W. Grimes 1704b88c807SRodney W. Grimes 1714b88c807SRodney W. Grimes 17288328642SDavid E. O'Brien static void 1735134c3f7SWarner Losh sharg(union node *arg, FILE *fp) 1744b88c807SRodney W. Grimes { 1754b88c807SRodney W. Grimes char *p; 1764b88c807SRodney W. Grimes struct nodelist *bqlist; 1774b88c807SRodney W. Grimes int subtype; 1784b88c807SRodney W. Grimes 1794b88c807SRodney W. Grimes if (arg->type != NARG) { 1804b88c807SRodney W. Grimes printf("<node type %d>\n", arg->type); 1814b88c807SRodney W. Grimes fflush(stdout); 1824b88c807SRodney W. Grimes abort(); 1834b88c807SRodney W. Grimes } 1844b88c807SRodney W. Grimes bqlist = arg->narg.backquote; 1854b88c807SRodney W. Grimes for (p = arg->narg.text ; *p ; p++) { 1864b88c807SRodney W. Grimes switch (*p) { 1874b88c807SRodney W. Grimes case CTLESC: 1884b88c807SRodney W. Grimes putc(*++p, fp); 1894b88c807SRodney W. Grimes break; 1904b88c807SRodney W. Grimes case CTLVAR: 1914b88c807SRodney W. Grimes putc('$', fp); 1924b88c807SRodney W. Grimes putc('{', fp); 1934b88c807SRodney W. Grimes subtype = *++p; 194aa9caaf6SPeter Wemm if (subtype == VSLENGTH) 195aa9caaf6SPeter Wemm putc('#', fp); 196aa9caaf6SPeter Wemm 1974b88c807SRodney W. Grimes while (*p != '=') 1984b88c807SRodney W. Grimes putc(*p++, fp); 199aa9caaf6SPeter Wemm 2004b88c807SRodney W. Grimes if (subtype & VSNUL) 2014b88c807SRodney W. Grimes putc(':', fp); 202aa9caaf6SPeter Wemm 2034b88c807SRodney W. Grimes switch (subtype & VSTYPE) { 2044b88c807SRodney W. Grimes case VSNORMAL: 2054b88c807SRodney W. Grimes putc('}', fp); 2064b88c807SRodney W. Grimes break; 2074b88c807SRodney W. Grimes case VSMINUS: 2084b88c807SRodney W. Grimes putc('-', fp); 2094b88c807SRodney W. Grimes break; 2104b88c807SRodney W. Grimes case VSPLUS: 2114b88c807SRodney W. Grimes putc('+', fp); 2124b88c807SRodney W. Grimes break; 2134b88c807SRodney W. Grimes case VSQUESTION: 2144b88c807SRodney W. Grimes putc('?', fp); 2154b88c807SRodney W. Grimes break; 2164b88c807SRodney W. Grimes case VSASSIGN: 2174b88c807SRodney W. Grimes putc('=', fp); 2184b88c807SRodney W. Grimes break; 219aa9caaf6SPeter Wemm case VSTRIMLEFT: 220aa9caaf6SPeter Wemm putc('#', fp); 221aa9caaf6SPeter Wemm break; 222aa9caaf6SPeter Wemm case VSTRIMLEFTMAX: 223aa9caaf6SPeter Wemm putc('#', fp); 224aa9caaf6SPeter Wemm putc('#', fp); 225aa9caaf6SPeter Wemm break; 226aa9caaf6SPeter Wemm case VSTRIMRIGHT: 227aa9caaf6SPeter Wemm putc('%', fp); 228aa9caaf6SPeter Wemm break; 229aa9caaf6SPeter Wemm case VSTRIMRIGHTMAX: 230aa9caaf6SPeter Wemm putc('%', fp); 231aa9caaf6SPeter Wemm putc('%', fp); 232aa9caaf6SPeter Wemm break; 233aa9caaf6SPeter Wemm case VSLENGTH: 234aa9caaf6SPeter Wemm break; 2354b88c807SRodney W. Grimes default: 2364b88c807SRodney W. Grimes printf("<subtype %d>", subtype); 2374b88c807SRodney W. Grimes } 2384b88c807SRodney W. Grimes break; 2394b88c807SRodney W. Grimes case CTLENDVAR: 2404b88c807SRodney W. Grimes putc('}', fp); 2414b88c807SRodney W. Grimes break; 2424b88c807SRodney W. Grimes case CTLBACKQ: 2434b88c807SRodney W. Grimes case CTLBACKQ|CTLQUOTE: 2444b88c807SRodney W. Grimes putc('$', fp); 2454b88c807SRodney W. Grimes putc('(', fp); 2464b88c807SRodney W. Grimes shtree(bqlist->n, -1, NULL, fp); 2474b88c807SRodney W. Grimes putc(')', fp); 2484b88c807SRodney W. Grimes break; 2494b88c807SRodney W. Grimes default: 2504b88c807SRodney W. Grimes putc(*p, fp); 2514b88c807SRodney W. Grimes break; 2524b88c807SRodney W. Grimes } 2534b88c807SRodney W. Grimes } 2544b88c807SRodney W. Grimes } 2554b88c807SRodney W. Grimes 2564b88c807SRodney W. Grimes 25788328642SDavid E. O'Brien static void 2585134c3f7SWarner Losh indent(int amount, char *pfx, FILE *fp) 2594b88c807SRodney W. Grimes { 2604b88c807SRodney W. Grimes int i; 2614b88c807SRodney W. Grimes 2624b88c807SRodney W. Grimes for (i = 0 ; i < amount ; i++) { 2634b88c807SRodney W. Grimes if (pfx && i == amount - 1) 2644b88c807SRodney W. Grimes fputs(pfx, fp); 2654b88c807SRodney W. Grimes putc('\t', fp); 2664b88c807SRodney W. Grimes } 2674b88c807SRodney W. Grimes } 2684b88c807SRodney W. Grimes 2694b88c807SRodney W. Grimes 2704b88c807SRodney W. Grimes /* 2714b88c807SRodney W. Grimes * Debugging stuff. 2724b88c807SRodney W. Grimes */ 2734b88c807SRodney W. Grimes 2744b88c807SRodney W. Grimes 2754b88c807SRodney W. Grimes FILE *tracefile; 2764b88c807SRodney W. Grimes 2779d22cd9bSDavid E. O'Brien #if DEBUG >= 2 2784b88c807SRodney W. Grimes int debug = 1; 2794b88c807SRodney W. Grimes #else 2804b88c807SRodney W. Grimes int debug = 0; 2814b88c807SRodney W. Grimes #endif 2824b88c807SRodney W. Grimes 2834b88c807SRodney W. Grimes 284aa9caaf6SPeter Wemm void 2855134c3f7SWarner Losh trputc(int c) 286aa9caaf6SPeter Wemm { 2874b88c807SRodney W. Grimes if (tracefile == NULL) 2884b88c807SRodney W. Grimes return; 2894b88c807SRodney W. Grimes putc(c, tracefile); 2904b88c807SRodney W. Grimes if (c == '\n') 2914b88c807SRodney W. Grimes fflush(tracefile); 2924b88c807SRodney W. Grimes } 2934b88c807SRodney W. Grimes 294ab0a2172SSteve Price 295aa9caaf6SPeter Wemm void 296d62ec71cSMartin Cracauer sh_trace(const char *fmt, ...) 2974b88c807SRodney W. Grimes { 298aa9caaf6SPeter Wemm va_list va; 299aa9caaf6SPeter Wemm va_start(va, fmt); 300aa9caaf6SPeter Wemm if (tracefile != NULL) { 301aa9caaf6SPeter Wemm (void) vfprintf(tracefile, fmt, va); 3024b88c807SRodney W. Grimes if (strchr(fmt, '\n')) 303aa9caaf6SPeter Wemm (void) fflush(tracefile); 304aa9caaf6SPeter Wemm } 305aa9caaf6SPeter Wemm va_end(va); 3064b88c807SRodney W. Grimes } 3074b88c807SRodney W. Grimes 3084b88c807SRodney W. Grimes 309aa9caaf6SPeter Wemm void 3102cac6e36SJilles Tjoelker trputs(const char *s) 3114b88c807SRodney W. Grimes { 3124b88c807SRodney W. Grimes if (tracefile == NULL) 3134b88c807SRodney W. Grimes return; 3144b88c807SRodney W. Grimes fputs(s, tracefile); 3154b88c807SRodney W. Grimes if (strchr(s, '\n')) 3164b88c807SRodney W. Grimes fflush(tracefile); 3174b88c807SRodney W. Grimes } 3184b88c807SRodney W. Grimes 3194b88c807SRodney W. Grimes 32088328642SDavid E. O'Brien static void 3215134c3f7SWarner Losh trstring(char *s) 3224b88c807SRodney W. Grimes { 323afb033d5SSteve Price char *p; 3244b88c807SRodney W. Grimes char c; 3254b88c807SRodney W. Grimes 3264b88c807SRodney W. Grimes if (tracefile == NULL) 3274b88c807SRodney W. Grimes return; 3284b88c807SRodney W. Grimes putc('"', tracefile); 3294b88c807SRodney W. Grimes for (p = s ; *p ; p++) { 3304b88c807SRodney W. Grimes switch (*p) { 3314b88c807SRodney W. Grimes case '\n': c = 'n'; goto backslash; 3324b88c807SRodney W. Grimes case '\t': c = 't'; goto backslash; 3334b88c807SRodney W. Grimes case '\r': c = 'r'; goto backslash; 3344b88c807SRodney W. Grimes case '"': c = '"'; goto backslash; 3354b88c807SRodney W. Grimes case '\\': c = '\\'; goto backslash; 3364b88c807SRodney W. Grimes case CTLESC: c = 'e'; goto backslash; 3374b88c807SRodney W. Grimes case CTLVAR: c = 'v'; goto backslash; 3384b88c807SRodney W. Grimes case CTLVAR+CTLQUOTE: c = 'V'; goto backslash; 3394b88c807SRodney W. Grimes case CTLBACKQ: c = 'q'; goto backslash; 3404b88c807SRodney W. Grimes case CTLBACKQ+CTLQUOTE: c = 'Q'; goto backslash; 3414b88c807SRodney W. Grimes backslash: putc('\\', tracefile); 3424b88c807SRodney W. Grimes putc(c, tracefile); 3434b88c807SRodney W. Grimes break; 3444b88c807SRodney W. Grimes default: 3454b88c807SRodney W. Grimes if (*p >= ' ' && *p <= '~') 3464b88c807SRodney W. Grimes putc(*p, tracefile); 3474b88c807SRodney W. Grimes else { 3484b88c807SRodney W. Grimes putc('\\', tracefile); 3494b88c807SRodney W. Grimes putc(*p >> 6 & 03, tracefile); 3504b88c807SRodney W. Grimes putc(*p >> 3 & 07, tracefile); 3514b88c807SRodney W. Grimes putc(*p & 07, tracefile); 3524b88c807SRodney W. Grimes } 3534b88c807SRodney W. Grimes break; 3544b88c807SRodney W. Grimes } 3554b88c807SRodney W. Grimes } 3564b88c807SRodney W. Grimes putc('"', tracefile); 3574b88c807SRodney W. Grimes } 3584b88c807SRodney W. Grimes 3594b88c807SRodney W. Grimes 360aa9caaf6SPeter Wemm void 3615134c3f7SWarner Losh trargs(char **ap) 3624b88c807SRodney W. Grimes { 3634b88c807SRodney W. Grimes if (tracefile == NULL) 3644b88c807SRodney W. Grimes return; 3654b88c807SRodney W. Grimes while (*ap) { 3664b88c807SRodney W. Grimes trstring(*ap++); 3674b88c807SRodney W. Grimes if (*ap) 3684b88c807SRodney W. Grimes putc(' ', tracefile); 3694b88c807SRodney W. Grimes else 3704b88c807SRodney W. Grimes putc('\n', tracefile); 3714b88c807SRodney W. Grimes } 3724b88c807SRodney W. Grimes fflush(tracefile); 3734b88c807SRodney W. Grimes } 3744b88c807SRodney W. Grimes 3754b88c807SRodney W. Grimes 376aa9caaf6SPeter Wemm void 3775134c3f7SWarner Losh opentrace(void) 3785134c3f7SWarner Losh { 3794b88c807SRodney W. Grimes char s[100]; 3804b88c807SRodney W. Grimes int flags; 3814b88c807SRodney W. Grimes 3824b88c807SRodney W. Grimes if (!debug) 3834b88c807SRodney W. Grimes return; 3844b88c807SRodney W. Grimes #ifdef not_this_way 385aa9caaf6SPeter Wemm { 386aa9caaf6SPeter Wemm char *p; 3874b88c807SRodney W. Grimes if ((p = getenv("HOME")) == NULL) { 3884b88c807SRodney W. Grimes if (geteuid() == 0) 3894b88c807SRodney W. Grimes p = "/"; 3904b88c807SRodney W. Grimes else 3914b88c807SRodney W. Grimes p = "/tmp"; 3924b88c807SRodney W. Grimes } 393*670dd3f0SJilles Tjoelker strcpy(s, p); 3944b88c807SRodney W. Grimes strcat(s, "/trace"); 395aa9caaf6SPeter Wemm } 3964b88c807SRodney W. Grimes #else 397*670dd3f0SJilles Tjoelker strcpy(s, "./trace"); 3984b88c807SRodney W. Grimes #endif /* not_this_way */ 3994b88c807SRodney W. Grimes if ((tracefile = fopen(s, "a")) == NULL) { 4006c48b6cfSMartin Cracauer fprintf(stderr, "Can't open %s: %s\n", s, strerror(errno)); 4014b88c807SRodney W. Grimes return; 4024b88c807SRodney W. Grimes } 4034b88c807SRodney W. Grimes if ((flags = fcntl(fileno(tracefile), F_GETFL, 0)) >= 0) 4044b88c807SRodney W. Grimes fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND); 4054b88c807SRodney W. Grimes fputs("\nTracing started.\n", tracefile); 4064b88c807SRodney W. Grimes fflush(tracefile); 4074b88c807SRodney W. Grimes } 408ab0a2172SSteve Price #endif /* DEBUG */ 409