Return to test1.c CVS log | Up to [local] / OpenXM / src / hgm / mh / src |
File: [local] / OpenXM / src / hgm / mh / src / test1.c (download)
Revision 1.4, Thu Feb 21 07:30:56 2013 UTC (11 years, 4 months ago) by takayama
1. JK_byFile is introduced. 2. jk_freeWorkArea() and jk_initialzeWorkArea(). 3. The --bystring option is implemented. 4. Repeated use of jk_main outputs wrong answers. Try ./test2 Testdata/tmp-idata3.txt This bug has not been fixed. (#ticket 2013-02-21-a#) 5. A bug of mh_fputs is fixed. |
#include <stdio.h> #include "sfile.h" /* $OpenXM: OpenXM/src/hgm/mh/src/test1.c,v 1.4 2013/02/21 07:30:56 takayama Exp $ test of the --string mode ./test1 Testdata/tmp-idata2.txt >tt.xt diff tt.txt Testdata/tmp-data2-out.txt */ char *readAsString(FILE *fp) { static char *s = NULL; static int size= 102400; int p = 0; char *s2; int c; if (fp == NULL) { s=NULL; return(NULL); } if (s == NULL) { s = (char *) malloc(size); if (s == NULL) { fprintf(stderr,"no more memory.\n"); exit(10); } } s[0] = 0; while ((c=fgetc(fp)) != EOF) { s[p++] = c; s[p] = 0; if (p >= size-2) { s2 = s; size = 2*size; s = (char *) malloc(size); if (s == NULL) { fprintf(stderr,"no more memory.\n"); exit(10); } strcpy(s,s2); free(s2); } } return s; } main(int argc,char *argv[]) { int i; char *s; FILE *fp; struct MH_RESULT *rp; struct SFILE *sfp; char *argv2[10]; mh_exit(MH_RESET_EXIT); /* standalone mode */ if (argc != 2) { mh_main(argc,argv); return(0);} fp = fopen(argv[1],"r"); if (fp == NULL) { fprintf(stderr,"File %s is not found.\n",argv[1]); return(-1); } s = readAsString(fp); fclose(fp); argv2[0] = "dummy"; argv2[1] = "--bystring"; argv2[2] = "--idata"; argv2[3] = s; argv2[4] = "--dataf"; argv2[5] = "aa"; rp=mh_main(6,argv2); sfp = (rp->sfpp)[0]; if (sfp) { printf("0, len=%d\n",sfp->len); if (sfp->s) printf("%s",sfp->s); } sfp = (rp->sfpp)[1]; if (sfp) { printf("1, len=%d\n",sfp->len); if (sfp->s) printf("1:%s",sfp->s); } fflush(NULL); /* deallocate the memory */ for (i=0; i<rp->size; i++) mh_fclose((rp->sfpp)[i]); mh_freeWorkArea(); /* second try */ rp=mh_main(6,argv2); }