plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

cb.h (3404B)


      1 #define	IF	1
      2 #define	ELSE	2
      3 #define	CASE	3
      4 #define TYPE	4
      5 #define DO	5
      6 #define STRUCT	6
      7 #define OTHER	7
      8 
      9 #define ALWAYS	01
     10 #define	NEVER	02
     11 #define	SOMETIMES	04
     12 
     13 #define YES	1
     14 #define NO	0
     15 
     16 #define	KEYWORD	1
     17 #define	DATADEF	2
     18 #define	SINIT	3
     19 
     20 #define CLEVEL	200
     21 #define IFLEVEL	100
     22 #define DOLEVEL	100
     23 #define OPLENGTH	100
     24 #define LINE	2048
     25 #define LINELENG	2048
     26 #define MAXTABS	8
     27 #define TABLENG	8
     28 #define TEMP	20480
     29 
     30 #define OUT	outs(clev->tabs); Bputc(output, '\n');opflag = lbegin = 1; count = 0
     31 #define OUTK	OUT; keyflag = 0;
     32 #define BUMP	clev->tabs++; clev->pdepth++
     33 #define UNBUMP	clev->tabs -= clev->pdepth; clev->pdepth = 0
     34 #define eatspace()	while((cc=getch()) == ' ' || cc == '\t'); unget(cc)
     35 #define eatallsp()	while((cc=getch()) == ' ' || cc == '\t' || cc == '\n'); unget(cc)
     36 
     37 struct indent {		/* one for each level of { } */
     38 	int tabs;
     39 	int pdepth;
     40 	int iflev;
     41 	int ifc[IFLEVEL];
     42 	int spdepth[IFLEVEL];
     43 } ind[CLEVEL];
     44 struct indent *clev = ind;
     45 struct keyw {
     46 	char	*name;
     47 	char	punc;
     48 	char	type;
     49 } key[] = {
     50 	"switch", ' ', OTHER,
     51 	"do", ' ', DO,
     52 	"while", ' ', OTHER,
     53 	"if", ' ', IF,
     54 	"for", ' ', OTHER,
     55 	"else", ' ', ELSE,
     56 	"case", ' ', CASE,
     57 	"default", ' ', CASE,
     58 	"char", '\t', TYPE,
     59 	"int", '\t', TYPE,
     60 	"short", '\t', TYPE,
     61 	"long", '\t', TYPE,
     62 	"unsigned", '\t', TYPE,
     63 	"float", '\t', TYPE,
     64 	"double", '\t', TYPE,
     65 	"struct", ' ', STRUCT,
     66 	"union", ' ', STRUCT,
     67 	"enum", ' ', STRUCT,
     68 	"extern", ' ', TYPE,
     69 	"register", ' ', TYPE,
     70 	"static", ' ', TYPE,
     71 	"typedef", ' ', TYPE,
     72 	0, 0, 0
     73 };
     74 struct op {
     75 	char	*name;
     76 	char	blanks;
     77 	char	setop;
     78 } op[] = {
     79 	"+=", 	ALWAYS,  YES,
     80 	"-=", 	ALWAYS,  YES,
     81 	"*=", 	ALWAYS,  YES,
     82 	"/=", 	ALWAYS,  YES,
     83 	"%=", 	ALWAYS,  YES,
     84 	">>=", 	ALWAYS,  YES,
     85 	"<<=", 	ALWAYS,  YES,
     86 	"&=", 	ALWAYS,  YES,
     87 	"^=", 	ALWAYS,  YES,
     88 	"|=", 	ALWAYS,  YES,
     89 	">>", 	ALWAYS,  YES,
     90 	"<<", 	ALWAYS,  YES,
     91 	"<=", 	ALWAYS,  YES,
     92 	">=", 	ALWAYS,  YES,
     93 	"==", 	ALWAYS,  YES,
     94 	"!=", 	ALWAYS,  YES,
     95 	"=", 	ALWAYS,  YES,
     96 	"&&", 	ALWAYS, YES,
     97 	"||", 	ALWAYS, YES,
     98 	"++", 	NEVER, NO,
     99 	"--", 	NEVER, NO,
    100 	"->", 	NEVER, NO,
    101 	"<", 	ALWAYS, YES,
    102 	">", 	ALWAYS, YES,
    103 	"+", 	ALWAYS, YES,
    104 	"/", 	ALWAYS, YES,
    105 	"%", 	ALWAYS, YES,
    106 	"^", 	ALWAYS, YES,
    107 	"|", 	ALWAYS, YES,
    108 	"!", 	NEVER, YES,
    109 	"~", 	NEVER, YES,
    110 	"*", 	SOMETIMES, YES,
    111 	"&", 	SOMETIMES, YES,
    112 	"-", 	SOMETIMES, YES,
    113 	"?",	ALWAYS,YES,
    114 	":",	ALWAYS,YES,
    115 	0, 	0,0
    116 };
    117 Biobuf *input;
    118 Biobuf *output;
    119 int	strict = 0;
    120 int	join	= 0;
    121 int	opflag = 1;
    122 int	keyflag = 0;
    123 int	paren	 = 0;
    124 int	split	 = 0;
    125 int	folded	= 0;
    126 int	dolevel	=0;
    127 int	dotabs[DOLEVEL];
    128 int	docurly[DOLEVEL];
    129 int	dopdepth[DOLEVEL];
    130 int	structlev = 0;
    131 int	question	 = 0;
    132 char	string[LINE];
    133 char	*lastlook;
    134 char	*p = string;
    135 char temp[TEMP];
    136 char *tp;
    137 int err = 0;
    138 char *lastplace = temp;
    139 char *tptr = temp;
    140 int maxleng	= LINELENG;
    141 int maxtabs	= MAXTABS;
    142 int count	= 0;
    143 char next = '\0';
    144 int	inswitch	=0;
    145 int	lbegin	 = 1;
    146 int lineno	= 0;
    147 
    148 void work(void);
    149 void gotif(void);
    150 void gotelse(void);
    151 int checkif(char *);
    152 void gotdo(void);
    153 void resetdo(void);
    154 void gottype(struct keyw *lptr);
    155 void gotstruct(void);
    156 void gotop(int);
    157 void keep(struct op *);
    158 int getnl(void);
    159 void ptabs(int);
    160 void outs(int);
    161 void putch(char, int);
    162 struct keyw *lookup(char *, char *);
    163 int comment(int);
    164 void putspace(char, int);
    165 int getch(void);
    166 void unget(char);
    167 char *getnext(int);
    168 void copy(char *);
    169 void clearif(struct indent *);
    170 char puttmp(char, int);
    171 void error(char *);
    172 int cpp_comment(int);