C Programming Tutorial (K&R version 4) _Part5

C Programming Tutorial (K&R version 4) _Part5 -...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Listing Cref.c 1 /********************************************************/ 2 /* */ 3 /* C programming utility : variable referencer */ 4 /* */ 5 /********************************************************/ 6 7 /* See notes above */ 8 9 #include <stdio.h> 10 #include <ctype.h> 11 12 #define TRUE 1 13 #define FALSE 0 14 #define DUMMY 0 15 #define MAXSTR 512 16 #define MAXIDSIZE 32 17 #define WORDTABLE 33 18 19 int LINECOUNT = 1; /* Contains line no. in file */ 20 char BUFFER[MAXIDSIZE]; /* Input BUFFER for IDs */ 21 char CH; /* Current input character */ 22 char SPECIALCHAR; /* macro/pointer flag */ 23 24 /**********************************************************/ 25 /* TABLE */ 26 /**********************************************************/ 27 28 char *WORDTABLE [WORDTABLE] = /* Table of resvd words */ 29 30 { 31 "auto" , 32 "break" , 33 "case" , 34 "char" , 35 "const", 36 "continue", 37 "default" , 38 "do" , 39 "double" , 40 "else" , 41 "entry" , 42 "enum" , 43 "extern" , 44 "float" , 45 "for" , 46 "goto" , 47 "if" , 48 "int" , 49 "long" , 50 "register", 51 "return" , 52 "short" , 53 "signed" , 54 "sizeof" ,
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
55 "static" , 56 "struct" , 57 "switch" , 58 "typedef" , 59 "union" , 60 "unsigned", 61 "void" , 62 "volatile", 63 "while" , 64 }; 65 66 /********************************************************/ 67 /** STRUCTURES **/ 68 /********************************************************/ 69 70 struct heap 71 72 { 73 short num; 74 char spec; 75 struct heap *next; 76 }; 77 78 /**********************************************************/ 79 80 struct BinaryTree 81 82 { 83 char *name; 84 struct heap *line; 85 struct BinaryTree *left; 86 struct BinaryTree *right; 87 } 88 89 *tree = NULL; 90 91 /**********************************************************/ 92 /* LEVEL 0 : main program */ 93 /**********************************************************/ 94 95 main () 96 97 { FILE *fp; 98 char *filename(); 99 struct BinaryTree *CloseDataStruct(); 100 101 printf ("\nIdentifier Cross Reference V 1.0\n\n"); 102 if ((fp = fopen (filename(),"r")) == NULL) 103 { 104 printf ("Can't read file . . Aborted!\n\n"); 105 exit(0); 106 } 107 CH = getc(fp); 108 109 while (!feof(fp)) 110 { 111 SkipBlanks (fp);
Background image of page 2
112 RecordWord (fp); 113 } 114 115 listIDs (tree); 116 CloseDataStruct(tree); 117 printf ("\n%d lines in source file\n",LINECOUNT); 118 } 119 120 /**********************************************************/ 121 /* LEVEL 1 */ 122 /**********************************************************/ 123 124 SkipBlanks (fp) /* Skip irrelevant characters */ 125 126 FILE *fp; 127 128 { 129 130 while (!feof(fp)) 131 132 { 133 if (iscsymf(CH)) 134 { 135 return(DUMMY); 136 } 137 else 138 { 139 ParticularSkip(fp); 140 } 141 } 142 } 143 144 /**********************************************************/ 145 146 RecordWord (fp) /* get ID in buffer & tube it to data */ 147 148 FILE *fp; 149 150 { int tok; 151 152 CopyNextID (fp); 153 154 if ((tok = token()) == 0) /* if not resved word */ 155 { 156 RecordUserID(isfunction(fp));
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/08/2012.

Page1 / 70

C Programming Tutorial (K&amp;amp;R version 4) _Part5 -...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online