annotate src/readpstlog.c @ 44:d4606d460daf

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