9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

rc.h (3495B)


      1 /*
      2  * Plan9 is defined for plan 9
      3  * V9 is defined for 9th edition
      4  * Sun is defined for sun-os
      5  * Please don't litter the code with ifdefs.  The three below (and one in
      6  * getflags) should be enough.
      7  */
      8 #define	Plan9
      9 #ifdef	Plan9
     10 #include <u.h>
     11 #include <libc.h>
     12 #undef NSIG
     13 #undef SIGINT
     14 #undef SIGQUIT
     15 #define	NSIG	32
     16 #define	SIGINT	2
     17 #define	SIGQUIT	3
     18 #endif
     19 #ifdef	V9
     20 #include <signal.h>
     21 #include <libc.h>
     22 #endif
     23 #ifdef Sun
     24 #include <signal.h>
     25 #endif
     26 #define	YYMAXDEPTH	500
     27 #ifndef PAREN
     28 #ifndef YYMAJOR
     29 #include "x.tab.h"
     30 #endif
     31 #endif
     32 
     33 #undef pipe	/* so that /dev/fd works */
     34 #define searchpath rcsearchpath	/* avoid new libc function */
     35 
     36 typedef struct tree tree;
     37 typedef struct word word;
     38 typedef struct io io;
     39 typedef union code code;
     40 typedef struct var var;
     41 typedef struct list list;
     42 typedef struct redir redir;
     43 typedef struct thread thread;
     44 typedef struct builtin builtin;
     45 
     46 struct tree{
     47 	int type;
     48 	int rtype, fd0, fd1;		/* details of REDIR PIPE DUP tokens */
     49 	char *str;
     50 	int quoted;
     51 	int iskw;
     52 	tree *child[3];
     53 	tree *next;
     54 };
     55 tree *newtree(void);
     56 tree *token(char*, int), *klook(char*), *tree1(int, tree*);
     57 tree *tree2(int, tree*, tree*), *tree3(int, tree*, tree*, tree*);
     58 tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*);
     59 tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*);
     60 tree *simplemung(tree*), *heredoc(tree*);
     61 void freetree(tree*);
     62 tree *cmdtree;
     63 /*
     64  * The first word of any code vector is a reference count.
     65  * Always create a new reference to a code vector by calling codecopy(.).
     66  * Always call codefree(.) when deleting a reference.
     67  */
     68 union code{
     69 	void (*f)(void);
     70 	int i;
     71 	char *s;
     72 };
     73 char *promptstr;
     74 int doprompt;
     75 #define	NTOK	8192
     76 char tok[NTOK];
     77 #define	APPEND	1
     78 #define	WRITE	2
     79 #define	READ	3
     80 #define	HERE	4
     81 #define	DUPFD	5
     82 #define	CLOSE	6
     83 #define	RDWR	7
     84 struct var{
     85 	char *name;		/* ascii name */
     86 	word *val;	/* value */
     87 	int changed;
     88 	code *fn;		/* pointer to function's code vector */
     89 	int fnchanged;
     90 	int pc;			/* pc of start of function */
     91 	var *next;	/* next on hash or local list */
     92 	void	(*changefn)(var*);
     93 };
     94 var *vlook(char*), *gvlook(char*), *newvar(char*, var*);
     95 #define	NVAR	521
     96 var *gvar[NVAR];				/* hash for globals */
     97 #define	new(type)	((type *)emalloc(sizeof(type)))
     98 char *emalloc(long);
     99 void *Malloc(ulong);
    100 void efree(char*);
    101 #define	NOFILE	128		/* should come from <param.h> */
    102 struct here{
    103 	tree *tag;
    104 	char *name;
    105 	struct here *next;
    106 };
    107 int mypid;
    108 /*
    109  * Glob character escape in strings:
    110  *	In a string, GLOB must be followed by *?[ or GLOB.
    111  *	GLOB* matches any string
    112  *	GLOB? matches any single character
    113  *	GLOB[...] matches anything in the brackets
    114  *	GLOBGLOB matches GLOB
    115  */
    116 #define	GLOB	((char)0x01)
    117 /*
    118  * onebyte(c), twobyte(c), threebyte(c)
    119  * Is c the first character of a one- two- or three-byte utf sequence?
    120  */
    121 #define	onebyte(c)	((c&0x80)==0x00)
    122 #define	twobyte(c)	((c&0xe0)==0xc0)
    123 #define	threebyte(c)	((c&0xf0)==0xe0)
    124 char **argp;
    125 char **args;
    126 int nerror;		/* number of errors encountered during compilation */
    127 int doprompt;		/* is it time for a prompt? */
    128 /*
    129  * Which fds are the reading/writing end of a pipe?
    130  * Unfortunately, this can vary from system to system.
    131  * 9th edition Unix doesn't care, the following defines
    132  * work on plan 9.
    133  */
    134 #define	PRD	0
    135 #define	PWR	1
    136 extern char *Rcmain(), Fdprefix[];
    137 #define	register
    138 /*
    139  * How many dot commands have we executed?
    140  * Used to ensure that -v flag doesn't print rcmain.
    141  */
    142 int ndot;
    143 char *getstatus(void);
    144 int lastc;
    145 int lastword;
    146 int kidpid;