annotate src/readpstlog.c @ 80:4a760802ef29 stable-0-6-13

bump version number
author Carl Byington <carl@five-ten-sg.com>
date Fri, 13 Jun 2008 20:49:29 -0700
parents 987aa872294e
children 0f1492b7fe8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
1 #include "define.h"
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
2
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3 #define BUF_SIZE 4096
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 int usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6 size_t get(void * buf, int size, unsigned int count, FILE *fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 int split_args(char *args, int **targ);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8 int is_in(int a, int *b, int c);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10 int main(int argc, char** argv) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
11 int identity = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
12 int level = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
13 int x, ptr, stop=0, flag;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
14 char *fname, *buf, rec_type;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
15 unsigned char version;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
16 int *show_type=NULL, show_size=0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
17 int *ex_type=NULL, ex_size=0;
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
18 unsigned int funcname=0, filename=0, text=0, end=0, dtype=0, line=0;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
19 int c;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
20 char ch;
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
21 FILE *fp;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
22 struct pst_debug_file_rec_m mfile_rec;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
23 struct pst_debug_file_rec_l lfile_rec;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
24 char format = 'D'; // default
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
25 while ((c = getopt(argc, argv, "f:t:x:")) != -1) {
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
26 ch = c;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
27 switch(ch) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
28 case 'f':
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
29 // change the output format
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
30 format = toupper(optarg[0]);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
31 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
32 case 't':
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
33 //change the type of statements shown
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
34 show_size = split_args(optarg, &show_type);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
35 // type = atoi(optarg);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
36 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
37 case 'x':
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
38 // change the type of statements excluded
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
39 ex_size = split_args(optarg, &ex_type);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
40 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
41 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
42 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
43 if (argc > optind) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
44 fname = argv[optind++];
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
45 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
46 usage();
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
47 exit(2);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
48 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
49
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
50 fp = fopen(fname, "rb");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
51 if (fp == NULL) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
52 printf("Error. couldn't open debug file\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
53 return 2;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
54 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
55 if (get(&version, sizeof(char), 1, fp)==0) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
56 printf("Error. could not read version byte from front of file");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
57 return 3;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
58 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
59
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
60 if (version > DEBUG_VERSION) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
61 printf("Version number is higher than the format I know about.");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
62 return 4;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
63 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
64
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
65 buf = (char*) xmalloc(BUF_SIZE);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
66
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
67 while (!stop) {
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
68 off_t temp;
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
69 if (fread(&temp, sizeof(off_t), 1, fp)<=0) break;
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
70 x = (int)temp;
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
71 ptr = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
72 if (x > 0) {
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
73 off_t i[x+1]; // plus 1 because we want to read the offset of the next index
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
74 if (get(i, sizeof(off_t), x+1, fp)==0) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
75 // we have reached the end of the debug file
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
76 printf("oh dear. we must now end\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
77 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
78 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
79 while (ptr < x) {
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
80 fseeko(fp, i[ptr++], SEEK_SET);
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
81 get(&rec_type, 1, sizeof(char), fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
82 if (rec_type == 'L') {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
83 get(&lfile_rec, sizeof(lfile_rec), 1, fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
84 funcname=lfile_rec.funcname;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
85 filename=lfile_rec.filename;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
86 text = lfile_rec.text;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
87 end = lfile_rec.end;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
88 dtype = lfile_rec.type;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
89 line = lfile_rec.line;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
90 } else if (rec_type == 'M') {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
91 get(&mfile_rec, sizeof(mfile_rec), 1, fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
92 funcname = mfile_rec.funcname;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
93 filename = mfile_rec.filename;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
94 text = mfile_rec.text;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
95 end = mfile_rec.end;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
96 dtype = mfile_rec.type;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
97 line = mfile_rec.line;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
98 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
99 if (dtype == DEBUG_FUNCENT_NO) level++;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
100 if ((show_type == NULL || is_in(dtype, show_type, show_size)) &&
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
101 (ex_type == NULL || !is_in(dtype, ex_type, ex_size))) {
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
102 unsigned int c = 0;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
103 flag = 0;
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
104 while (c < end) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
105 int ii = (level-1) * 4;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
106 if (ii < 0) ii = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
107 if (ii > 64) ii = 64;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
108 char indent[ii+1];
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
109 memset(indent, ' ', ii);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
110 indent[ii] = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
111 if (c + (BUF_SIZE-1) < end) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
112 get(buf, 1, BUF_SIZE-1, fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
113 buf[BUF_SIZE-1] = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
114 c += BUF_SIZE-1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
115 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
116 get(buf, 1, end-c, fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
117 buf[end-c] = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
118 c = end;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
119 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
120 if (flag == 0) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
121 if (format == 'I') { // indented text format
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
122 char *b = buf+text;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
123 identity++;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
124 //printf("%s %d %s/%s[%d]: ", indent, identity, &buf[filename], &buf[funcname], line);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
125 printf("%s %s/%s[%d]: ", indent, &buf[filename], &buf[funcname], line);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
126 while (b) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
127 char *p = strchr(b, '\n');
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
128 if (p) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
129 *p = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
130 printf("%s\n%s ", b, indent);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
131 b = p + 1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
132 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
133 else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
134 printf("%s", b);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
135 b = NULL;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
136 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
137 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
138 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
139 else if (format == 'T') { // text format
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
140 printf("%s/%s[%d]: %s", &buf[filename], &buf[funcname], line, &buf[text]);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
141 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
142 printf("Type: %d\nFile[line]: %s[%d]\nFunction:%s\nText:%s", dtype,
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
143 &buf[filename], line, &buf[funcname], &buf[text]);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
144 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
145 flag = 1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
146 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
147 if (format == 'I') {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
148 char *b = buf;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
149 while (b) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
150 char *p = strchr(b, '\n');
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
151 if (p) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
152 *p = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
153 printf("%s\n%s ", b, indent);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
154 b = p + 1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
155 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
156 else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
157 printf("%s", b);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
158 b = NULL;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
159 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
160 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
161 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
162 else printf("%s", buf);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
163 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
164 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
165 printf("\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
166 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
167 if (dtype == DEBUG_FUNCRET_NO) level--;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
168 }
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
169 if (fseeko(fp, i[ptr], SEEK_SET)==-1) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
170 printf("finished\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
171 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
172 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
173 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
174 printf("...no more items\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
175 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
176 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
177 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
178 free(buf);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
179 fclose(fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
180 if (format == 'I') printf("final indent level = %i\n", level);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
181 return 0;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
182 }
36
6fe121a971c9 valgrind fixes
carl
parents: 16
diff changeset
183
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 36
diff changeset
184 size_t get(void *buf, int size, unsigned int count, FILE *fp) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
185 size_t z;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
186 if ((z=fread(buf, size, count, fp)) < count) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
187 printf("Read Failed! (size=%d, count=%d,z=%ld)\n", size, count, (long)z);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
188 exit(1);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
189 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
190 return z;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
191 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
192
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
193 int usage() {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
194 printf("readlog -t[show_type] -x[exclude_type] -f[format] filename\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
195 printf("\tformat:\n\t\tt: text log format\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
196 printf("\t\ti: indented text log format\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
197 printf("\tshow_type:\n\t\tcomma separated list of types to show "
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
198 "[ie, 2,4,1,6]\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
199 printf("\texclude_type:\n\t\tcomma separated list of types to exclude "
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
200 "[ie, 1,5,3,7]\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
201 return 0;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
202 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
203
36
6fe121a971c9 valgrind fixes
carl
parents: 16
diff changeset
204
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
205 int split_args(char *args, int **targ) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
206 int count = 1, *i, x, z;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
207 char *tmp = args, *y;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
208 if (*targ != NULL) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
209 free(*targ);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
210 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
211 // find the number of tokens in the string. Starting
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
212 // from 1 cause there will always be one
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
213 while ((tmp = strchr(tmp, ',')) != NULL) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
214 tmp++; count++;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
215 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
216 *targ = (int*)xmalloc(count * sizeof(int));
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
217 i = *targ; // for convienience
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
218 tmp = args;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
219 z = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
220 for (x = 0; x < count; x++) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
221 y = strtok(tmp, ",");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
222 tmp = NULL; // must be done after first call
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
223 if (y != NULL) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
224 i[x] = atoi(y);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
225 z++;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
226 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
227 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
228 return z;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
229 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
230
36
6fe121a971c9 valgrind fixes
carl
parents: 16
diff changeset
231
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
232 // checks to see if the first arg is in the array of the second arg,
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
233 // the size of which is specified with the third arg. If the second
36
6fe121a971c9 valgrind fixes
carl
parents: 16
diff changeset
234 // arg is NULL, then it is obvious that it is not there.
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
235 int is_in(int a, int *b, int c){
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
236 int d = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
237 if (b == NULL || c == 0) { // no array or no items in array
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
238 return 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
239 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
240 while (d < c) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
241 if (a == b[d]) return 1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
242 d++;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
243 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
244 return 0;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
245 }