[r76]: src / multi_parse.cc  Maximize  Restore  History

Download this file

745 lines (653 with data), 22.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_linalg.h>
#include "full_util.h"
#include "peteys_tmpl_lib.h"
#include "agf_lib.h"
#include "multi_parse.h"
//because we love arbitrary limitations:
#define MAXNPART 200
using namespace std;
using namespace libpetey;
namespace libagf {
//scan for a file name:
char * scan_class_model1(FILE *fs, int &lineno) {
int c1;
char c2;
char *fname;
int namelen;
int numflag=0;
do {
c1=fgetc(fs);
if (c1==EOF) return NULL;
c2=(char) c1;
//printf("1.(%c)\n", c2);
if (c2=='\n') lineno++;
//filename has to start with a letter:
if (isalpha(c2)) break;
if (c2>='0' && c2<='9') {
numflag=1;
break;
}
if (isspace(c1)==0) return NULL;
} while (1);
//scan until we reach the end of the file name:
namelen=1;
do {
c1=fgetc(fs);
if (c1==EOF) return NULL;
c2=(char) c1;
//printf("2.(%c)\n", c2);
//filename can contain any non-whitespace character:
if (numflag) {
if (c2<'0' || c2>'9') break;
} else if (isspace(c1)) {
//make sure to increment line counter if whitespace is a linebreak:
if (c2=='\n') lineno++;
break;
}
namelen++;
} while (1);
//put the filename in a string (whether or not we need it...):
fname=new char[namelen+1];
fseek(fs, -namelen-1, SEEK_CUR);
for (int i=0; i<namelen; i++) fname[i]=fgetc(fs);
fname[namelen]='\0';
//printf("%s\n", fname);
return fname;
}
//scan for a set of options enclosed in quotation marks:
char * scan_class_model2(FILE *fs, int &lineno) {
int c1;
char c2;
char *fname;
int namelen;
int numflag=0;
do {
c1=fgetc(fs);
if (c1==EOF) return NULL;
c2=(char) c1;
//printf("1.(%c)\n", c2);
if (c2=='\n') lineno++;
if (c2=='"') break;
if (c2>='0' && c2<='9') {
numflag=1;
break;
}
if (isspace(c1)==0) return NULL;
} while (1);
//scan until we reach the end of the file name:
namelen=numflag;
do {
c1=fgetc(fs);
if (c1==EOF) return NULL;
c2=(char) c1;
//printf("2.(%c)\n", c2);
if (numflag) {
if (c2<'0' || c2>'9') {
//make sure to increment line counter if whitespace is a linebreak:
if (c2=='\n') lineno++;
break;
}
} else if (c2=='"') {
break;
}
//we don't allow line-breaks in the middle of options lists:
if (c2=='\n') return NULL;
namelen++;
} while (1);
//put the filename in a string (whether or not we need it...):
fname=new char[namelen+1];
fseek(fs, -namelen-1, SEEK_CUR);
for (int i=0; i<namelen; i++) fname[i]=fgetc(fs);
fname[namelen]='\0';
if (numflag==0) c1=fgetc(fs);
//printf("scan_class_model2: %s\n", fname);
return fname;
}
//scan specifically for a class label:
//- if one is found, return it as a string
//- if not, rewind to the first non-whitespace character
char * scan_class_label(FILE *fs, int &lineno) {
int c1;
char c2;
char *fname;
int namelen;
do {
c1=fgetc(fs);
if (c1==EOF) return NULL;
c2=(char) c1;
//printf("1.(%c)\n", c2);
if (c2>='0' && c2<='9') {
break;
}
if (isspace(c1)==0) {
fseek(fs, -1, SEEK_CUR);
return NULL;
}
} while (1);
namelen=1;
do {
c1=fgetc(fs);
//we won't make any assumptions about characters beyond the number:
if (c1==EOF) break;
c2=(char) c1;
//printf("2.(%c)\n", c2);
if (c2<'0' || c2>'9') break;
namelen++;
} while (1);
//put the class label in a string:
fname=new char[namelen+1];
fseek(fs, -namelen-1, SEEK_CUR);
for (int i=0; i<namelen; i++) fname[i]=fgetc(fs);
fname[namelen]='\0';
//printf("scan_class_label: label=%s\n", fname);
return fname;
}
template <class cls_t>
int parse_multi_partitions(multi_parse_param *param, char **model, cls_t **partition, int maxn) {
int namelen;
int npart=0;
int nread;
int c1;
char c2;
char cold;
cls_t ncls;
for (int i=0; i<maxn; i++) {
if (param->trainflag) {
model[npart]=scan_class_model2(param->infs, param->lineno);
} else {
model[npart]=scan_class_model1(param->infs, param->lineno);
}
if (model[npart]==NULL) {
fseek(param->infs, -1, SEEK_CUR);
break;
}
if (model[npart][0]>='0' && model[npart][0]<='9') {
fprintf(stderr, "parse_multi_partitions: syntax error, line %d at %s\n", param->lineno, model[npart]);
exit(FILE_READ_ERROR);
}
if (param->trainflag) {
//if options are a special case, pull them from the stack
//add new options to the stack
if (param->optstack[param->stackptr]!=NULL &&
strcmp(model[npart], ".")==0) {
delete [] model[npart];
model[npart]=new char [strlen(param->optstack[param->stackptr])+1];
strcpy(model[npart], param->optstack[param->stackptr]);
} else {
if (strlen(model[npart])==0) {
delete [] model[npart];
model[npart]=new char[strlen(param->optstack[0])+1];
strcpy(model[npart], param->optstack[0]);
} else if (strcmp(model[npart], ".")==0) {
delete [] model[npart];
model[npart]=new char[strlen(param->optstack[param->stackptr-1])+1];
strcpy(model[npart], param->optstack[param->stackptr-1]);
}
if (param->optstack[param->stackptr]!=NULL) {
delete [] param->optstack[param->stackptr];
}
param->optstack[param->stackptr]=new char [strlen(model[npart])+1];
strcpy(param->optstack[param->stackptr], model[npart]);
}
}
nread=0;
cold=' ';
ncls=0;
do {
c1=fgetc(param->infs);
nread++;
if (c1==EOF) {
fprintf(stderr, "parse_multi_partitions: %d, unexpected end of file(1).\n", param->lineno);
exit(FILE_READ_ERROR);
}
c2=(char) c1;
//printf("3.(%c)\n", c2);
if (c2<='9' && c2>='0') {
if (cold>'9' || cold<'0') ncls++;
} else if (c2==PARTITION_SYMBOL) {
break;
} else if (c2=='\n') {
param->lineno++;
} else if (c2!=' ' && c2!='\t') {
fprintf(stderr, "parse_multi_partitions: %d, syntax error in control file(2).\n", param->lineno);
exit(FILE_READ_ERROR);
}
cold=c2;
} while (1);
//printf("ncls=%d\n", ncls);
fseek(param->infs, -nread, SEEK_CUR);
partition[2*npart]=new cls_t[ncls+1];
for (int i=0; i<ncls; i++) {
fscanf(param->infs, "%d", partition[2*npart]+i);
//printf("%d\n", partition[2*npart][i]);
}
partition[2*npart][ncls]=-1;
do {
c1=fgetc(param->infs);
c2=(char) c1;
} while (c2!=PARTITION_SYMBOL);
nread=0;
cold=' ';
ncls=0;
do {
c1=fgetc(param->infs);
nread++;
if (c1==EOF) {
fprintf(stderr, "parse_multi_partitions: %d, unexpected end of file(2).\n", param->lineno);
exit(FILE_READ_ERROR);
}
c2=(char) c1;
//printf("4.(%c)\n", c2);
if (c2<='9' && c2>='0') {
if (cold>'9' || cold<'0') ncls++;
} else if (c2==';') {
break;
} else if (c2=='\n') {
param->lineno++;
} else if (c2!=' ' && c2!='\t') {
fprintf(stderr, "parse_multi_partitions: %d, syntax error in control file(3).\n", param->lineno);
exit(FILE_READ_ERROR);
}
cold=c2;
} while (1);
//printf("ncls=%d\n", ncls);
fseek(param->infs, -nread, SEEK_CUR);
partition[2*npart+1]=new cls_t[ncls+1];
partition[2*npart+1][ncls]=-1;
for (cls_t i=0; i<ncls; i++) {
fscanf(param->infs, "%d", partition[2*npart+1]+i);
//printf("%d\n", partition[2*npart+1][i]);
}
do {
c1=fgetc(param->infs);
c2=(char) c1;
} while (c2!=';');
if (npart < MAXNPART) {
npart++;
} else {
fprintf(stderr, "parse_multi_partitions: Maximum of %d partitions allowed.\n", MAXNPART);
fprintf(stderr, " Re-run after increasing MAXNPART macro. Sorry.\n");
exit(PARAMETER_OUT_OF_RANGE);
}
}
if (npart==0) return 0;
//check them over:
//1. each partition must have the same number of classes
//2. there must be one of each class present between 0 and ncls-1
cls_t j, k;
cls_t *tbl;
//printf("partition: %d\n", npart);
for (ncls=0; partition[0][ncls]>=0; ncls++) {
//printf("%d ", partition[0][ncls]);
}
//printf("| ");
for (j=0; partition[1][j]>=0; j++) {
//printf("%d\n", partition[1][j]);
}
//printf("\n");
ncls+=j;
//printf("ncls=%d\n", ncls);
tbl=new cls_t[ncls];
for (cls_t i=0; i<npart; i++) {
for (j=0; j<ncls; j++) tbl[j]=0;
for (j=0; partition[2*i][j]>=0; j++) {
if (j>=ncls || partition[2*i][j]>=ncls) {
fprintf(stderr, "parse_multi_partitions: too many classes or out-of-bounds label in partition.\n");
fprintf(stderr, " left side; partition #=%d; class #=%d; class=%d\n",
i, j, partition[2*i][j]);
exit(PARAMETER_OUT_OF_RANGE);
}
tbl[partition[2*i][j]]+=1;
}
for (k=0; partition[2*i+1][k]>=0; k++) {
if (k+j-1>=ncls || partition[2*i+1][k]>=ncls) {
fprintf(stderr, "parse_multi_partitions: too many classes or out-of-bounds label in partition.\n");
fprintf(stderr, " right side; partition #=%d; class #=%d; class=%d\n",
i, j+k-1, partition[2*i+1][k]);
exit(PARAMETER_OUT_OF_RANGE);
}
tbl[partition[2*i+1][k]]+=1;
}
for (j=0; j<ncls; j++) {
if (tbl[j]!=1) {
fprintf(stderr, "parse_multi_partitions: missing or duplicate class in partition.\n");
exit(PARAMETER_OUT_OF_RANGE);
}
}
}
//augment stack pointer:
if (param->trainflag) {
if (param->stackptr<param->maxnstack) {
param->stackptr++;
} else {
fprintf(stderr, "parse_multi_partitions: option stack exausted (%d levels)\n", param->stackptr);
exit(PARAMETER_OUT_OF_RANGE);
}
}
delete [] tbl;
return npart;
}
char * parse_multi_start(multi_parse_param *param, //all the parameters globbed into one
int &flag) //0=regular 2-class model, 1=multi-class model, 2=single class label
{
char *fname;
int nextra;
int nextra2;
int c1;
char c2;
long *sind;
flag=0;
//scan for the file containing the model:
if (param->trainflag) {
fname=scan_class_model2(param->infs, param->lineno);
//in case model is a multi-partition model, rewind extra 2 characters because of quotes:
nextra2=2;
} else {
fname=scan_class_model1(param->infs, param->lineno);
//filenames for final model not enclosed by quotes:
nextra2=0;
}
if (fname==NULL) {
c1=fgetc(param->infs);
if (c1==EOF) {
fprintf(stderr, "parse_multi_start: %d, syntax error at end of file(1)\n", param->lineno);
} else {
c2=char(c1);
if (c2=='\n') {
fprintf(stderr, "parse_multi_start: %d, syntax error in control file(2) at end of line\n", param->lineno);
} else {
fprintf(stderr, "parse_multi_start: %d, syntax error in control file(3) at \"%c\"\n", param->lineno, c2);
}
}
exit(FILE_READ_ERROR);
}
//if we just have a number, return with it in a string:
if (fname[0]>='0' && fname[0]<='9') {
flag=2;
return fname;
}
param->depth++;
//scan forward until we find the opening bracket or a number:
nextra=0;
do {
c1=fgetc(param->infs);
if (c1==EOF) {
fprintf(stderr, "parse_multi_start: %d, unexpected end of file(3).\n", param->lineno);
exit(FILE_READ_ERROR);
}
nextra++;
c2=(char) c1;
//printf("5.(%c)\n", c2);
if (c2=='{') {
//we've moved to the next level
break;
}
if (c2>='0' && c2<='9') {
fseek(param->infs, -strlen(fname)-nextra-nextra2, SEEK_CUR);
flag=1;
break;
}
if (c2!=' ' && c2!='\t' && c2!='\n') {
fprintf(stderr, "parse_multi_start: %d, syntax error in control file(4) at \"%c\".\n", param->lineno, c2);
exit(FILE_READ_ERROR);
}
if (c2=='\n') param->lineno++;
} while (1);
return fname;
}
void print_opt_stack(multi_parse_param *param) {
for (int i=0; i<param->stackptr; i++) printf("%s\n", param->optstack[i]);
}
template <class cls_t>
void print_partition_list(FILE *fs, cls_t **part, cls_t npart) {
for (cls_t i=0; i<npart; i++) {
for (cls_t j=0; part[0][j]>=0; j++) {
fprintf(fs, "%d ", part[i*2][j]);
}
fprintf(fs, "%c", PARTITION_SYMBOL);
for (cls_t j=0; part[1][j]>=0; j++) {
fprintf(fs, " %d", part[i*2+1][j]);
}
fprintf(fs, "\n");
}
}
template <class cls_t>
cls_t parse_multi_train(multi_parse_param *param, char *fbase, cls_t *cls) {
char *options; //options section
int namelen; //length of file name
int c1;
char c2;
int flag; //state after reading options-list
cls_t nbranch; //number of branchs
cls_t ncls; //total number of classes (so far)
char *fbase2; //base-name for next level
long *sind;
//number of classes for each branch:
cls_t *bncls;
cls_t *bnclst; //running total
//if we have multi-class model (more than two branches):
cls_t *part[MAXNPART];
char *opt2[MAXNPART];
cls_t npart;
int popflag=1;
if (param->trainflag!=1) {
fprintf(stderr, "parse_multi_train: internal error: trainflag must be set\n");
exit(INTERNAL_ERROR);
}
//scan for the file containing the model:
options=parse_multi_start(param, flag);
//print_opt_stack(param);
//we have a class number:
if (flag==2) {
sscanf(options, "%d", cls);
for (int k=0; k<param->depth; k++) fprintf(param->outfs, " ");
fprintf(param->outfs, "%d\n", cls[0]);
delete [] options;
return 1;
}
//otherwise print a line-break:
//fprintf(param->outfs, "\n");
fbase2=new char [strlen(fbase)+7];
//if the next symbol is a number, then the there are more than two classes
//and more than one class-border: (non-hierarchical multi-borders)
if (flag==1) {
npart=parse_multi_partitions(param, opt2, part, MAXNPART);
if (npart==0) {
fprintf(stderr, "parse_multi_train: %d, syntax error in control file(1) at \"%s\".\n", param->lineno, options);
exit(FILE_READ_ERROR);
}
//printf("npart=%d\n", npart);
//count the number of classes:
cls_t nbranch2;
for (nbranch=0; part[0][nbranch]>=0; nbranch++);
for (nbranch2=0; part[1][nbranch2]>=0; nbranch2++);
nbranch+=nbranch2;
//printf("nbranch=%d\n", nbranch);
//scan forward until we find the opening bracket:
do {
c1=fgetc(param->infs);
if (c1==EOF) {
fprintf(stderr, "parse_multi_train: %d, unexpected end of file(1).\n", param->lineno);
exit(FILE_READ_ERROR);
}
c2=(char) c1;
//printf("6.(%c)\n", c2);
if (c2=='{') {
//we've moved to the next level:
break;
}
if (c2!=' ' || c2!='\t' || c2!='\n') {
fprintf(stderr, "parse_multi_train: %d, syntax error in control file(2) at \"%c\".\n", param->lineno, c2);
exit(FILE_READ_ERROR);
}
if (c2=='\n') param->lineno++;
} while (1);
for (cls_t i=0; i<npart; i++) {
sprintf(fbase2, "%s-%2.2d", fbase, i);
for (int k=1; k<param->depth; k++) fprintf(param->outfs, " ");
fprintf(param->outfs, "%s", fbase2);
for (cls_t j=0; part[i*2][j]>=0; j++) fprintf(param->outfs, " %d", part[i*2][j]);
fprintf(param->outfs, " %c", PARTITION_SYMBOL);
for (cls_t j=0; part[i*2+1][j]>=0; j++) fprintf(param->outfs, " %d", part[i*2+1][j]);
fprintf(param->outfs, ";\n");
}
for (int k=1; k<param->depth; k++) fprintf(param->outfs, " ");
fprintf(param->outfs, "{\n");
} else {
if (param->optstack[param->stackptr]!=NULL &&
strcmp(options, ".")==0) {
delete [] options;
options=new char[strlen(param->optstack[param->stackptr])+1];
strcpy(options, param->optstack[param->stackptr]);
} else {
if (strlen(options)==0) {
delete [] options;
options=new char[strlen(param->optstack[0])+1];
strcpy(options, param->optstack[0]);
} else if (strcmp(options, ".")==0) {
delete [] options;
options=new char[strlen(param->optstack[param->stackptr-1])+1];
strcpy(options, param->optstack[param->stackptr-1]);
}
if (param->optstack[param->stackptr]!=NULL) {
delete [] param->optstack[param->stackptr];
}
param->optstack[param->stackptr]=new char[strlen(options)+1];
//option stack has to be independent of parsing operations:
strcpy(param->optstack[param->stackptr], options);
}
if (param->stackptr<param->maxnstack) {
param->stackptr++;
} else {
fprintf(stderr, "parse_multi_train: option stack exausted (%d levels)\n", param->stackptr);
exit(PARAMETER_OUT_OF_RANGE);
}
//otherwise we're using a two-class model:
nbranch=2;
for (int k=1; k<param->depth; k++) fprintf(param->outfs, " ");
fprintf(param->outfs, "%s {\n", fbase);
}
bncls=new cls_t[nbranch];
bnclst=new cls_t[nbranch+1];
//go to the next level in the hierarchy:
bnclst[0]=0;
for (int i=0; i<nbranch; i++) {
sprintf(fbase2, "%s.%2.2d", fbase, i);
bncls[i]=parse_multi_train(param, fbase2, cls+bnclst[i]);
bnclst[i+1]=bnclst[i]+bncls[i];
}
ncls=bnclst[nbranch];
//scan for the closing bracket:
do {
c1=fgetc(param->infs);
if (c1==EOF) {
fprintf(stderr, "parse_multi_train: %d, unexpected end of file(2).\n", param->lineno);
exit(FILE_READ_ERROR);
}
c2=(char) c1;
//printf("7.(%c)\n", c2);
if (c2=='}') {
for (int k=1; k<param->depth; k++) fprintf(param->outfs, " ");
fprintf(param->outfs, "}\n");
break;
}
if (c2!=' ' && c2!='\t' && c2!='\n') {
fprintf(stderr, "parse_multi_train: %d, syntax error in control file(3) at \"%c\".\n", param->lineno, c2);
exit(FILE_READ_ERROR);
}
if (c2=='\n') param->lineno++;
} while (1);
//check to make sure everything's Kosher:
sind=heapsort(cls, ncls);
for (int i=1; i<ncls; i++) {
if (cls[sind[i-1]]==cls[sind[i]]) {
fprintf(stderr, "parse_multi_train: %d, error, duplicate classes\n", param->lineno);
exit(OTHER_ERROR);
}
}
//print out the commands to generate the border data:
if (flag==1) {
int k;
for (cls_t i=0; i<npart; i++) {
sprintf(fbase2, "%s-%2.2d", fbase, i);
fprintf(param->commandfs, "%s %s %s %s", param->commandname, opt2[i], param->train, fbase2);
for (cls_t j=0; part[i*2][j]>=0; j++) {
k=0;
for (cls_t k=bnclst[part[i*2][j]]; k<bnclst[part[i*2][j]+1]; k++) {
fprintf(param->commandfs, " %d", cls[k]);
}
}
fprintf(param->commandfs, " %c", PARTITION_SYMBOL);
for (cls_t j=0; part[i*2+1][j]>=0; j++) {
k=0;
for (cls_t k=bnclst[part[i*2+1][j]]; k<bnclst[part[i*2+1][j]+1]; k++) {
fprintf(param->commandfs, " %d", cls[k]);
}
}
fprintf(param->commandfs, "\n");
}
//clean up:
for (cls_t i=0; i<npart; i++) {
delete [] opt2[i];
delete [] part[i*2];
delete [] part[i*2+1];
}
//param->stackptr-=npart;
} else {
fprintf(param->commandfs, "%s %s %s %s", param->commandname,
options, param->train, fbase);
for (cls_t i=0; i<bnclst[1]; i++) fprintf(param->commandfs, " %d", cls[i]);
fprintf(param->commandfs, " %c", PARTITION_SYMBOL);
for (cls_t i=bnclst[1]; i<bnclst[2]; i++) fprintf(param->commandfs, " %d", cls[i]);
fprintf(param->commandfs, "\n");
}
//delete everything in the stack above the current pointer:
if (param->optstack[param->stackptr+1]!=NULL) {
delete [] param->optstack[param->stackptr+1];
param->optstack[param->stackptr+1]=NULL;
}
param->stackptr--;
param->depth--; //just use stackptr for this purpose?
delete [] options;
delete [] fbase2;
delete [] bncls;
delete [] bnclst;
delete [] sind;
return ncls;
}
void multi_train_begin(multi_parse_param *param, int argc, char **argv, int maxstacksize) {
int optlen;
//concatinate options:
optlen=argc+1;
for (int i=0; i<argc; i++) optlen+=strlen(argv[i]);
param->maxnstack=maxstacksize;
param->optstack=new char *[param->maxnstack];
param->optstack[0]=new char [optlen];
strcpy(param->optstack[0], "");
for (int i=0; i<argc; i++) {
strcat(param->optstack[0], argv[i]);
strcat(param->optstack[0], " ");
}
for (int i=1; i<param->maxnstack; i++) param->optstack[i]=NULL;
param->stackptr=1;
param->trainflag=1;
param->lineno=1;
param->depth=0; //not sure if I use this...oh well...
}
void multi_train_end(multi_parse_param *param) {
for (int i=0; i<param->maxnstack; i++) {
if (param->optstack[i]!=NULL) delete [] param->optstack[i];
}
delete [] param->optstack;
param->stackptr=0;
param->optstack=NULL;
}
template cls_ta parse_multi_train<cls_ta>(multi_parse_param *, char *, cls_ta *);
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks