annotate src/readpstlog.c @ 60:97b7706bdda2

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