int find_group(char s[], int ngrps, char **grpname) { int aa, i, n; char string[STRLEN]; gmx_bool bMultiple; bMultiple = FALSE; n = strlen(s); aa=NOTSET; /* first look for whole name match */ if (aa==NOTSET) for(i=0; i<ngrps; i++) if (gmx_strcasecmp_min(s,grpname[i])==0) { if(aa!=NOTSET) bMultiple = TRUE; aa=i; } /* second look for first string match */ if (aa==NOTSET) for(i=0; i<ngrps; i++) if (gmx_strncasecmp_min(s,grpname[i],n)==0) { if(aa!=NOTSET) bMultiple = TRUE; aa=i; } /* last look for arbitrary substring match */ if (aa==NOTSET) { upstring(s); minstring(s); for(i=0; i<ngrps; i++) { strcpy(string, grpname[i]); upstring(string); minstring(string); if (strstr(string,s)!=NULL) { if(aa!=NOTSET) bMultiple = TRUE; aa=i; } } } if (bMultiple) { printf("Error: Multiple groups '%s' selected\n", s); aa=NOTSET; } return aa; }
void main(int argc, char * argv[]) { FILE *f; FILE *fKey; FILE *fTrad; FILE *fIndex; long nKey, nTrad, total; long maxlen = 0; // Just to know how long is the longest traslation char * buf = new char [16384]; TIndex * index = new TIndex [MAXINDEX]; for (total=0; total < MAXINDEX; total++) { index[total].Key = -1; index[total].Trad = -1; } if (argc < 2) { printf("Dictionary Parser - (C)1998 by Mirko Buffoni\n\n"); printf("This program create a file of keywords (.key), a file of translations (.dct)\nand an index file (.idx), starting from an input text file.\n\n"); printf("USAGE: MkDict.exe <filename>\n"); exit(-1); } printf("\nParsing file: %s\n\n", argv[1]); f = fopen(argv[1], "r"); char keywordsFilename[512]; char dataFilename[512]; char indexFilename[512]; strcpy(keywordsFilename, argv[1]); strcpy(dataFilename, argv[1]); strcpy(indexFilename, argv[1]); StripExtension(keywordsFilename); StripExtension(dataFilename); StripExtension(indexFilename); strcat(keywordsFilename, ".key"); strcat(dataFilename, ".dct"); strcat(indexFilename, ".idx"); fKey = fopen(keywordsFilename, "wb"); fTrad = fopen(dataFilename, "wb"); fIndex = fopen(indexFilename, "wb"); nKey = 0; nTrad = 0; total = 0; while (f && !feof(f)) { memset(buf,0,8192); fgets(buf, 8192, f); if (strlen(buf) > 0) buf[strlen(buf)-1] = 0; if (strlen(buf) > maxlen) maxlen = strlen(buf); buf = minstring(buf); if (strlen(buf) > 0) // Skip empty lines { char *p = buf; p = strtok(buf," "); if (p) // If there is no space, it's probably an error :) { if (index[total].Key == -1) { index[total].Key = FileGetPos(fKey); index[total].Trad = FileGetPos(fTrad); } // printf("%s -> ", p); fwrite(p, 1, strlen(p)+1, fKey); p += strlen(p)+1; // printf("%s\n", p); fwrite(p, 1, strlen(p)+1, fTrad); total++; printf("\x0dProc. terms: %d", total); } } } printf("\nTotal number of keywords in dictionary: %d\n", total); fwrite(index,sizeof(TIndex),total,fIndex); fclose(fIndex); fclose(fTrad); fclose(fKey); delete [] index; delete [] buf; }