annotate src/readpstlog.c @ 46:b2a7f2e0926a

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