📄 csh.h
字号:
/*- * Copyright (c) 1980, 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 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. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. 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 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) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)csh.h 8.1 (Berkeley) 5/31/93 *//* * Fundamental definitions which may vary from system to system. * * BUFSIZ The i/o buffering size; also limits word size * MAILINTVL How often to mailcheck; more often is more expensive */#ifndef BUFSIZ#define BUFSIZ 1024 /* default buffer size */#endif /* BUFSIZ */#define FORKSLEEP 10 /* delay loop on non-interactive fork failure */#define MAILINTVL 600 /* 10 minutes *//* * The shell moves std in/out/diag and the old std input away from units * 0, 1, and 2 so that it is easy to set up these standards for invoked * commands. */#define FSHTTY 15 /* /dev/tty when manip pgrps */#define FSHIN 16 /* Preferred desc for shell input */#define FSHOUT 17 /* ... shell output */#define FSHERR 18 /* ... shell diagnostics */#define FOLDSTD 19 /* ... old std input */#ifdef PROF#define xexit(n) done(n)#endif#ifdef SHORT_STRINGStypedef short Char;#define SAVE(a) (Strsave(str2short(a)))#elsetypedef char Char;#define SAVE(a) (strsave(a))#endif/* * Make sure a variable is not stored in a register by taking its address * This is used where variables might be clobbered by longjmp. */#define UNREGISTER(a) (void) &atypedef void *ioctl_t; /* Third arg of ioctl */typedef void *ptr_t;#include "const.h"#include "char.h"#include "err.h"#define xmalloc(i) Malloc(i)#define xrealloc(p, i) Realloc(p, i)#define xcalloc(n, s) Calloc(n, s)#define xfree(p) Free(p)#include <stdio.h>FILE *cshin, *cshout, *csherr;#define isdir(d) ((d.st_mode & S_IFMT) == S_IFDIR)typedef int bool;#define eq(a, b) (Strcmp(a, b) == 0)/* globone() flags */#define G_ERROR 0 /* default action: error if multiple words */#define G_IGNORE 1 /* ignore the rest of the words */#define G_APPEND 2 /* make a sentence by cat'ing the words *//* * 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 FILECbool 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 *ffile; /* Name of shell file for $0 */char *seterr; /* Error message from scanner/parser */Char *shtemp; /* Temp name for << shell files in /tmp */#include <sys/types.h>#include <sys/time.h>#include <sys/resource.h>struct timeval time0; /* Time at which the shell started */struct rusage ru0;/* * Miscellany */Char *doldol; /* Character pid for $$ */int backpid; /* Pid of the last background process */int uid, euid; /* Invokers uid */int gid, egid; /* Invokers gid */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 *//* * 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 F{SHIN,...}. */int SHIN; /* Current shell input (script) */int SHOUT; /* Shell output */int SHERR; /* Diagnostic output... shell errs go here */int 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. */#include <setjmp.h>jmp_buf reslab;#define setexit() (setjmp(reslab))#define reset() longjmp(reslab, 1) /* Should use structure assignment here */#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 */#include <signal.h>sig_t parintr; /* Parents interrupt catch */sig_t parterm; /* Parents terminate catch *//* * Lexical definitions. * * All lexical space is allocated dynamically. * The eighth/sixteenth bit of characters is used to prevent recognition, * and eventually stripped. */#define META 0200#define ASCII 0177#ifdef SHORT_STRINGS#define CHAR 0377#define QUOTE 0100000 /* 16nth char bit used for 'ing */#define TRIM 0077777 /* Mask to strip quote bit */#else#define CHAR 0177#define QUOTE 0200 /* Eighth char bit used for 'ing */#define TRIM 0177 /* Mask to strip quote bit */#endifint AsciiOnly; /* If set only 7 bits is expected in characters *//* * 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 { off_t Bfseekp; /* Seek pointer */ off_t Bfbobp; /* Seekp of beginning of buffers */ off_t Bfeobp; /* Seekp of end of buffers */ int Bfblocks; /* Number of buffer blocks */ Char **Bfbuf; /* The array of buffer blocks */} B;/* * This structure allows us to seek inside aliases */struct Ain { int type;#define I_SEEK -1 /* Invalid seek */#define A_SEEK 0 /* Alias seek */#define F_SEEK 1 /* File seek */#define E_SEEK 2 /* Eval seek */ union { off_t _f_seek; Char* _c_seek; } fc;#define f_seek fc._f_seek#define c_seek fc._c_seek Char **a_seek;} ;extern int aret; /* What was the last character returned */#define SEEKEQ(a, b) ((a)->type == (b)->type && \ (a)->f_seek == (b)->f_seek && \ (a)->a_seek == (b)->a_seek)#define fseekp B.Bfseekp#define fbobp B.Bfbobp#define feobp B.Bfeobp#define fblocks B.Bfblocks#define fbuf B.Bfbuf/* * 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. */struct Ain lineloc;bool cantell; /* Is current source tellable ? *//* * Input lines are parsed into doubly linked circular * lists of words of the following form. */struct wordent { Char *word; struct wordent *prev;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -