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