annotate src/readpstlog.c @ 136:16770fc77139

fix for const correctness on Fedora 11
author Carl Byington <carl@five-ten-sg.com>
date Sat, 07 Feb 2009 09:29:29 -0800
parents fc11b1d1ad34
children 6954d315aaa8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
122
bdb38b434c0a more changes from Fridrich Strba to avoid installing our config.h
Carl Byington <carl@five-ten-sg.com>
parents: 118
diff changeset
1
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
2 #include "define.h"
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
3
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 #define BUF_SIZE 4096
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 75
diff changeset
6 void usage();
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 size_t get(void * buf, int size, unsigned int count, FILE *fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8 int split_args(char *args, int **targ);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9 int is_in(int a, int *b, int c);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 75
diff changeset
11 int main(int argc, char* const* argv) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
12 int identity = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
13 int level = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
14 int x, ptr, stop=0, flag;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
15 char *fname, *buf, rec_type;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
16 unsigned char version;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
17 int *show_type=NULL, show_size=0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
18 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
19 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
20 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
21 char ch;
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
22 FILE *fp;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
23 struct pst_debug_file_rec_m mfile_rec;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
24 struct pst_debug_file_rec_l lfile_rec;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
25 char format = 'D'; // default
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
26 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
27 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
28 switch(ch) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
29 case 'f':
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
30 // change the output format
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
31 format = toupper(optarg[0]);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
32 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
33 case 't':
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
34 //change the type of statements shown
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
35 show_size = split_args(optarg, &show_type);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
36 // type = atoi(optarg);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
37 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
38 case 'x':
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
39 // change the type of statements excluded
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
40 ex_size = split_args(optarg, &ex_type);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
41 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
42 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
43 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
44 if (argc > optind) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
45 fname = argv[optind++];
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
46 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
47 usage();
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
48 exit(2);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
49 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
50
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
51 fp = fopen(fname, "rb");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
52 if (fp == NULL) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
53 printf("Error. couldn't open debug file\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
54 return 2;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
55 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
56 if (get(&version, sizeof(char), 1, fp)==0) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
57 printf("Error. could not read version byte from front of file");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
58 return 3;
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 if (version > DEBUG_VERSION) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
62 printf("Version number is higher than the format I know about.");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
63 return 4;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
64 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
65
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
66 buf = (char*) xmalloc(BUF_SIZE);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
67
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
68 while (!stop) {
125
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
69 int64_t temp;
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
70 if (fread(&temp, sizeof(int64_t), 1, fp)<=0) break;
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
71 x = (int)temp;
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
72 ptr = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
73 if (x > 0) {
125
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
74 int64_t i[x+1]; // plus 1 because we want to read the offset of the next index
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
75 if (get(i, sizeof(int64_t), x+1, fp)==0) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
76 // we have reached the end of the debug file
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
77 printf("oh dear. we must now end\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
78 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
79 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
80 while (ptr < x) {
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
81 fseeko(fp, i[ptr++], SEEK_SET);
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
82 get(&rec_type, 1, sizeof(char), fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
83 if (rec_type == 'L') {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
84 get(&lfile_rec, sizeof(lfile_rec), 1, fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
85 funcname=lfile_rec.funcname;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
86 filename=lfile_rec.filename;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
87 text = lfile_rec.text;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
88 end = lfile_rec.end;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
89 dtype = lfile_rec.type;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
90 line = lfile_rec.line;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
91 } else if (rec_type == 'M') {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
92 get(&mfile_rec, sizeof(mfile_rec), 1, fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
93 funcname = mfile_rec.funcname;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
94 filename = mfile_rec.filename;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
95 text = mfile_rec.text;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
96 end = mfile_rec.end;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
97 dtype = mfile_rec.type;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
98 line = mfile_rec.line;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
99 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
100 if (dtype == DEBUG_FUNCENT_NO) level++;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
101 if ((show_type == NULL || is_in(dtype, show_type, show_size)) &&
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
102 (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
103 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
104 flag = 0;
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
105 while (c < end) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
106 int ii = (level-1) * 4;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
107 if (ii < 0) ii = 0;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
108 if (ii > 64) ii = 64;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
109 char indent[ii+1];
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
110 memset(indent, ' ', ii);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
111 indent[ii] = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
112 if (c + (BUF_SIZE-1) < end) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
113 get(buf, 1, BUF_SIZE-1, fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
114 buf[BUF_SIZE-1] = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
115 c += BUF_SIZE-1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
116 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
117 get(buf, 1, end-c, fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
118 buf[end-c] = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
119 c = end;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
120 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
121 if (flag == 0) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
122 if (format == 'I') { // indented text format
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
123 char *b = buf+text;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
124 identity++;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
125 //printf("%s %d %s/%s[%d]: ", indent, identity, &buf[filename], &buf[funcname], line);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
126 printf("%s %s/%s[%d]: ", indent, &buf[filename], &buf[funcname], line);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
127 while (b) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
128 char *p = strchr(b, '\n');
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
129 if (p) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
130 *p = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
131 printf("%s\n%s ", b, indent);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
132 b = p + 1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
133 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
134 else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
135 printf("%s", b);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
136 b = NULL;
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 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
140 else if (format == 'T') { // text format
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
141 printf("%s/%s[%d]: %s", &buf[filename], &buf[funcname], line, &buf[text]);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
142 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
143 printf("Type: %d\nFile[line]: %s[%d]\nFunction:%s\nText:%s", dtype,
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
144 &buf[filename], line, &buf[funcname], &buf[text]);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
145 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
146 flag = 1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
147 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
148 if (format == 'I') {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
149 char *b = buf;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
150 while (b) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
151 char *p = strchr(b, '\n');
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
152 if (p) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
153 *p = '\0';
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
154 printf("%s\n%s ", b, indent);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
155 b = p + 1;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
156 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
157 else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
158 printf("%s", b);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
159 b = NULL;
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 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
163 else printf("%s", buf);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
164 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
165 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
166 printf("\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
167 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
168 if (dtype == DEBUG_FUNCRET_NO) level--;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
169 }
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
170 if (fseeko(fp, i[ptr], SEEK_SET)==-1) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
171 printf("finished\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
172 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
173 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
174 } else {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
175 printf("...no more items\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
176 break;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
177 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
178 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
179 free(buf);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
180 fclose(fp);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
181 if (format == 'I') printf("final indent level = %i\n", level);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
182 return 0;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
183 }
36
6fe121a971c9 valgrind fixes
carl
parents: 16
diff changeset
184
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 36
diff changeset
185 size_t get(void *buf, int size, unsigned int count, FILE *fp) {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
186 size_t z;
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
187 if ((z=fread(buf, size, count, fp)) < count) {
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
188 printf("Read Failed! (size=%d, count=%d,z=%ld)\n", size, count, (long)z);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
189 exit(1);
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
190 }
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
191 return z;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
192 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
193
118
0f1492b7fe8b patch from Fridrich Strba for building on mingw and general cleanup of autoconf files
Carl Byington <carl@five-ten-sg.com>
parents: 75
diff changeset
194 void usage() {
52
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
195 printf("readlog -t[show_type] -x[exclude_type] -f[format] filename\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
196 printf("\tformat:\n\t\tt: text log format\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
197 printf("\t\ti: indented text log format\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
198 printf("\tshow_type:\n\t\tcomma separated list of types to show "
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
199 "[ie, 2,4,1,6]\n");
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
200 printf("\texclude_type:\n\t\tcomma separated list of types to exclude "
034641c26ab9 code cleanup
carl
parents: 48
diff changeset
201 "[ie, 1,5,3,7]\n");
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 }