1: #include <stdio.h>
2: int slevel[10];
3: int clevel = 0;
4: int spflg[20][10];
5: int sind[20][10];
6: int siflev[10];
7: int sifflg[10];
8: int iflev = 0;
9: int ifflg = -1;
10: int level = 0;
11: int ind[10] = {
12: 0,0,0,0,0,0,0,0,0,0 };
13: int eflg = 0;
14: int paren = 0;
15: int pflg[10] = {
16: 0,0,0,0,0,0,0,0,0,0 };
17: char lchar;
18: char pchar;
19: int aflg = 0;
20: int ct;
21: int stabs[20][10];
22: int qflg = 0;
23: char *wif[] = {
24: "if",0};
25: char *welse[] = {
26: "else",0};
27: char *wfor[] = {
28: "for",0};
29: char *wds[] = {
30: "case","default",0};
31: int j = 0;
32: char string[200];
33: char cc;
34: int sflg = 1;
35: int peek = -1;
36: int tabs = 0;
37: int lastchar;
38: int c;
39: main(argc,argv) int argc;
40: char argv[];
41: {
42: while((c = getch()) != EOF){
43: switch(c){
44: case ' ':
45: case '\t':
46: if(lookup(welse) == 1){
47: gotelse();
48: if(sflg == 0 || j > 0)string[j++] = c;
49: puts();
50: sflg = 0;
51: if(getnl() == 1){
52: puts();
53: printf("\n");
54: sflg = 1;
55: pflg[level]++;
56: tabs++;
57: }
58: continue;
59: }
60: if(sflg == 0 || j > 0)string[j++] = c;
61: continue;
62: case '\n':
63: if((eflg = lookup(welse)) == 1)gotelse();
64: puts();
65: printf("\n");
66: sflg = 1;
67: if(eflg == 1){
68: pflg[level]++;
69: tabs++;
70: }
71: else
72: if(pchar == lchar)
73: aflg = 1;
74: continue;
75: case '{':
76: if(lookup(welse) == 1)gotelse();
77: siflev[clevel] = iflev;
78: sifflg[clevel] = ifflg;
79: iflev = ifflg = 0;
80: clevel++;
81: if(sflg == 1 && pflg[level] != 0){
82: pflg[level]--;
83: tabs--;
84: }
85: string[j++] = c;
86: puts();
87: getnl();
88: puts();
89: printf("\n");
90: tabs++;
91: sflg = 1;
92: if(pflg[level] > 0){
93: ind[level] = 1;
94: level++;
95: slevel[level] = clevel;
96: }
97: continue;
98: case '}':
99: clevel--;
100: if((iflev = siflev[clevel]-1) < 0)iflev = 0;
101: ifflg = sifflg[clevel];
102: if(pflg[level] >0 && ind[level] == 0){
103: tabs -= pflg[level];
104: pflg[level] = 0;
105: }
106: puts();
107: tabs--;
108: ptabs();
109: if((peek = getch()) == ';'){
110: printf("%c;",c);
111: peek = -1;
112: }
113: else printf("%c",c);
114: getnl();
115: puts();
116: printf("\n");
117: sflg = 1;
118: if(clevel < slevel[level])if(level > 0)level--;
119: if(ind[level] != 0){
120: tabs -= pflg[level];
121: pflg[level] = 0;
122: ind[level] = 0;
123: }
124: continue;
125: case '"':
126: case '\'':
127: string[j++] = c;
128: while((cc = getch()) != c){
129: string[j++] = cc;
130: if(cc == '\\'){
131: string[j++] = getch();
132: }
133: if(cc == '\n'){
134: puts();
135: sflg = 1;
136: }
137: }
138: string[j++] = cc;
139: if(getnl() == 1){
140: lchar = cc;
141: peek = '\n';
142: }
143: continue;
144: case ';':
145: string[j++] = c;
146: puts();
147: if(pflg[level] > 0 && ind[level] == 0){
148: tabs -= pflg[level];
149: pflg[level] = 0;
150: }
151: getnl();
152: puts();
153: printf("\n");
154: sflg = 1;
155: if(iflev > 0)
156: if(ifflg == 1){iflev--;
157: ifflg = 0;
158: }
159: else iflev = 0;
160: continue;
161: case '\\':
162: string[j++] = c;
163: string[j++] = getch();
164: continue;
165: case '?':
166: qflg = 1;
167: string[j++] = c;
168: continue;
169: case ':':
170: string[j++] = c;
171: if(qflg == 1){
172: qflg = 0;
173: continue;
174: }
175: if(lookup(wds) == 0){
176: sflg = 0;
177: puts();
178: }
179: else{
180: tabs--;
181: puts();
182: tabs++;
183: }
184: if((peek = getch()) == ';'){
185: printf(";");
186: peek = -1;
187: }
188: getnl();
189: puts();
190: printf("\n");
191: sflg = 1;
192: continue;
193: case '/':
194: string[j++] = c;
195: if((peek = getch()) != '*')continue;
196: string[j++] = peek;
197: peek = -1;
198: comment();
199: continue;
200: case ')':
201: paren--;
202: string[j++] = c;
203: puts();
204: if(getnl() == 1){
205: peek = '\n';
206: if(paren != 0)aflg = 1;
207: else if(tabs > 0){
208: pflg[level]++;
209: tabs++;
210: ind[level] = 0;
211: }
212: }
213: continue;
214: case '#':
215: string[j++] = c;
216: while((cc = getch()) != '\n')string[j++] = cc;
217: string[j++] = cc;
218: sflg = 0;
219: puts();
220: sflg = 1;
221: continue;
222: case '(':
223: string[j++] = c;
224: paren++;
225: if(lookup(wfor) == 1){
226: while((c = gets()) != ';');
227: ct=0;
228: cont:
229: while((c = gets()) != ')'){
230: if(c == '(') ct++;
231: }
232: if(ct != 0){
233: ct--;
234: goto cont;
235: }
236: paren--;
237: puts();
238: if(getnl() == 1){
239: peek = '\n';
240: pflg[level]++;
241: tabs++;
242: ind[level] = 0;
243: }
244: continue;
245: }
246: if(lookup(wif) == 1){
247: puts();
248: stabs[clevel][iflev] = tabs;
249: spflg[clevel][iflev] = pflg[level];
250: sind[clevel][iflev] = ind[level];
251: iflev++;
252: ifflg = 1;
253: }
254: continue;
255: default:
256: string[j++] = c;
257: if(c != ',')lchar = c;
258: }
259: }
260: }
261: ptabs(){
262: int i;
263: for(i=0; i < tabs; i++)printf("\t");
264: }
265: getch(){
266: if(peek < 0 && lastchar != ' ' && lastchar != '\t')pchar = lastchar;
267: lastchar = (peek<0) ? getc(stdin):peek;
268: peek = -1;
269: return(lastchar);
270: }
271: puts(){
272: if(j > 0){
273: if(sflg != 0){
274: ptabs();
275: sflg = 0;
276: if(aflg == 1){
277: aflg = 0;
278: if(tabs > 0)printf(" ");
279: }
280: }
281: string[j] = '\0';
282: printf("%s",string);
283: j = 0;
284: }
285: else{
286: if(sflg != 0){
287: sflg = 0;
288: aflg = 0;
289: }
290: }
291: }
292: lookup(tab)
293: char *tab[];
294: {
295: char r;
296: int l,kk,k,i;
297: if(j < 1)return(0);
298: kk=0;
299: while(string[kk] == ' ')kk++;
300: for(i=0; tab[i] != 0; i++){
301: l=0;
302: for(k=kk;(r = tab[i][l++]) == string[k] && r != '\0';k++);
303: if(r == '\0' && (string[k] < 'a' || string[k] > 'z' || k >= j))return(1);
304: }
305: return(0);
306: }
307: gets(){
308: char ch;
309: beg:
310: if((ch = string[j++] = getch()) == '\\'){
311: string[j++] = getch();
312: goto beg;
313: }
314: if(ch == '\'' || ch == '"'){
315: while((cc = string[j++] = getch()) != ch)if(cc == '\\')string[j++] = getch();
316: goto beg;
317: }
318: if(ch == '\n'){
319: puts();
320: aflg = 1;
321: goto beg;
322: }
323: else return(ch);
324: }
325: gotelse(){
326: tabs = stabs[clevel][iflev];
327: pflg[level] = spflg[clevel][iflev];
328: ind[level] = sind[clevel][iflev];
329: ifflg = 1;
330: }
331: getnl(){
332: while((peek = getch()) == '\t' || peek == ' '){
333: string[j++] = peek;
334: peek = -1;
335: }
336: if((peek = getch()) == '/'){
337: peek = -1;
338: if((peek = getch()) == '*'){
339: string[j++] = '/';
340: string[j++] = '*';
341: peek = -1;
342: comment();
343: }
344: else string[j++] = '/';
345: }
346: if((peek = getch()) == '\n'){
347: peek = -1;
348: return(1);
349: }
350: return(0);
351: }
352: (){
353: :
354: while((c = string[j++] = getch()) != '*')
355: if(c == '\n'){
356: puts();
357: sflg = 1;
358: }
359: :
360: if((c = string[j++] = getch()) != '/'){
361: if(c == '*')goto gotstar;
362: goto rep;
363: }
364: }
Defined functions
defined in line
352; used 2 times
getch
defined in line
265; used 18 times
- in line 42,
109,
128-131(2),
163,
184,
195,
216,
310-315(4),
332-338(3),
346,
354,
360
gets
defined in line
307; used 2 times
main
defined in line
39;
never used
puts
defined in line
271; used 19 times
- in line 49-52(2),
64,
86-88(2),
106,
115,
134,
146,
152,
177-181(2),
189,
203,
219,
237,
247,
319,
356
Defined variables
aflg
defined in line
19; used 6 times
c
defined in line
38; used 27 times
- in line 42-48(3),
60,
85,
110-113(2),
127-128(2),
145,
162-170(3),
194,
202,
215,
223-230(4),
256-257(3),
354-361(4)
cc
defined in line
33; used 11 times
clevel
defined in line
3; used 14 times
ct
defined in line
20; used 4 times
eflg
defined in line
13; used 2 times
ifflg
defined in line
9; used 7 times
iflev
defined in line
8; used 14 times
ind
defined in line
11; used 9 times
j
defined in line
31; used 37 times
- in line 48(2),
60(2),
85,
127-131(3),
138,
145,
162-170(4),
194-196(2),
202,
215-217(3),
223,
256,
272,
281-283(2),
297,
303,
310-315(4),
333,
339-344(3),
354,
360
lchar
defined in line
17; used 3 times
level
defined in line
10; used 31 times
- in line 55,
68,
81-82(2),
92-95(4),
102-104(4),
118-122(7),
147-149(4),
208-210(2),
240-242(2),
249-250(2),
327-328(2)
paren
defined in line
14; used 4 times
pchar
defined in line
18; used 2 times
peek
defined in line
35; used 24 times
pflg
defined in line
15; used 17 times
- in line 55,
68,
81-82(2),
92,
102-104(3),
120-121(2),
147-149(3),
208,
240,
249,
327
qflg
defined in line
22; used 3 times
sflg
defined in line
34; used 19 times
- in line 48-54(3),
60,
66,
81,
91,
117,
135,
154,
176,
191,
218-220(2),
273-275(2),
286-287(2),
357
sifflg
defined in line
7; used 2 times
siflev
defined in line
6; used 2 times
sind
defined in line
5; used 2 times
slevel
defined in line
2; used 2 times
spflg
defined in line
4; used 2 times
stabs
defined in line
21; used 2 times
string
defined in line
32; used 36 times
- in line 48,
60,
85,
127-131(3),
138,
145,
162-170(4),
194-196(2),
202,
215-217(3),
223,
256,
281-282(2),
299-303(4),
310-315(4),
333,
339-344(3),
354,
360
tabs
defined in line
36; used 17 times
- in line 56,
69,
83,
90,
103-107(2),
120,
148,
180-182(2),
207-209(2),
241,
248,
263,
278,
326
wds
defined in line
29; used 1 times
welse
defined in line
25; used 3 times
wfor
defined in line
27; used 1 times
wif
defined in line
23; used 1 times