home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD2.mdf
/
c
/
clint
/
syntax
/
syntax.lst
< prev
next >
Wrap
File List
|
1987-09-11
|
5KB
|
154 lines
PAGE 1
09-11-87
11:38:02
Line# Source Line Microsoft C Compiler Version 4.00
1 /* syntax.c Program running a quick syntax check on C source
2 code Version 1.11 J. Tomasik; created 05/23/87
3
4 From BYTE magazine - September 1987
5
6 */
7
8 #include <stdio.h>
9
10 main(argc, argv)
11 int argc;
12 char *argv[];
13 {
14 FILE *fopen(), *infile;
15 char c;
16 int lbrace = 0, rbrace = 0;
17 int squote = 0, dquote = 0;
18 int lpar = 0, rpar = 0;
19 int lbrkt = 0, rbrkt = 0;
20 int bytecount = 0, errorcount = 0;
21
22 if (argc != 2) {
23 printf("SYNTAX checker for C source code, version 1.11\n");
24 printf("Copyright (C) J. Tomadik 1987, 1988\n\n");
25 printf("Usage: syntax fname.ext \n");
26 exit(1);
27 }
28 infile = fopen(argv[1],"r");
29 if (infile == NULL) {
30 printf("Cannot open %s \n", argv[1]);
31 exit(2);
32 }
33
34 while ((c = fgetc(infile)) != EOF) {
35 ++bytecount;
36 if (c == '{') ++lbrace;
37 else
38 if (c == '}') ++rbrace;
39 else
40 if (c == '\'') ++squote;
41 else
42 if (c == '\"') ++dquote;
43 else
44 if (c == '(') ++lpar;
45 else
46 if (c == ')') ++rpar;
47 else
48 if (c == '[') ++lbrkt;
49 else
50 if (c == ']') ++rbrkt;
51 }
52
53 fclose(infile);
54 printf("The file length is %d \n", bytecount);
PAGE 2
09-11-87
11:38:02
Line# Source Line Microsoft C Compiler Version 4.00
55
56
57 if (lbrace != rbrace) {
58 printf("There are %3d left and %3d right braces \n",
59 lbrace, rbrace);
60 ++errorcount;
61 }
62
63 if (lpar != rpar) {
64 printf("There are %3d left and %3d right parentheses \n",
65 lpar, rpar);
66 ++errorcount;
67 }
68
69 if (lbrkt != rbrkt) {
70 printf("There are %3d left and %3d right brackets \n",
71 lbrkt,rbrkt);
72 ++errorcount;
73 }
74
75 if (squote %2) {
76 printf("The single quote marks are not paired \n");
77 ++errorcount;
78 }
79
80 if (dquote %2) {
81 printf("The double quote marks are not paired \n");
82 ++errorcount;
83 }
84
85 if (errorcount == 0) {
86 printf("No error found, OK to compile \n");
87 }
88 else
89 exit(errorcount);
90 }
main Local Symbols
Name Class Offset Register
rbrkt . . . . . . . . . . . . . auto -0018
bytecount . . . . . . . . . . . auto -0016
dquote. . . . . . . . . . . . . auto -0014
rpar. . . . . . . . . . . . . . auto -0012
rbrace. . . . . . . . . . . . . auto -0010
errorcount. . . . . . . . . . . auto -000e
infile. . . . . . . . . . . . . auto -000c
lbrkt . . . . . . . . . . . . . auto -000a
squote. . . . . . . . . . . . . auto -0008
lpar. . . . . . . . . . . . . . auto -0006
lbrace. . . . . . . . . . . . . auto -0004
c . . . . . . . . . . . . . . . auto -0002
argc. . . . . . . . . . . . . . param 0004
PAGE 3
09-11-87
11:38:02
Line# Source Line Microsoft C Compiler Version 4.00
argv. . . . . . . . . . . . . . param 0006
Global Symbols
Name Type Size Class Offset
exit. . . . . . . . . . . . . . near function *** extern ***
fclose. . . . . . . . . . . . . near function *** extern ***
fgetc . . . . . . . . . . . . . near function *** extern ***
fopen . . . . . . . . . . . . . near function *** extern ***
main. . . . . . . . . . . . . . near function *** global 0000
printf. . . . . . . . . . . . . near function *** extern ***
Code size = 01f1 (497)
Data size = 0190 (400)
Bss size = 0000 (0)
No errors detected