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