//----------------------------------------------------------------------------- // Copyright (c) David Welch, 1996 //----------------------------------------------------------------------------- #include #include #include FILE *in; FILE *out; unsigned char sort; char inname[64]; char outname[64]; char line[128]; char s[16][128]; unsigned short ra; unsigned short rb; //----------------------------------------------------------------------------- unsigned char comp ( char *a, char *b ) { static unsigned short r; for(r=0;;r++) { if(a[r]==0) return(0); if(b[r]==0) return(1); if(a[r]==b[r]) continue; if(a[r]7) { printf("What?\n"); exit(1); } sprintf(outname,"%s.dns",argv[1]); in=fopen(outname,"rt"); if(in==NULL) { printf("Error opening file [%s]\n",inname); exit(1); } sprintf(inname,"%s.srt",argv[1]); out=fopen(inname,"wt"); if(out==NULL) { printf("Error creating file [%s]\n",outname); exit(1); } while(fgets(line,127,in)) { if(strlen(line)<9) continue; fprintf(out,"%s",line); } fclose(in); fclose(out); sprintf(outname,"%s.out",argv[1]); for(sort=1;sort;) { sort=0; putchar('.'); fflush(stdout); in=fopen(inname,"rt"); if(in==NULL) { printf("Error opening file\n"); exit(1); } out=fopen(outname,"wt"); if(out==NULL) { printf("Error creating file\n"); exit(1); } for(ra=1;ra<16;ra++) { if(fgets(s[ra],127,in)==NULL) { printf("Could not even start\n"); exit(1); } if(strlen(s[ra])<9) { ra--; } } while(1) { for(ra=1;ra<16;ra++) strcpy(s[ra-1],s[ra]); while(1) { if(fgets(s[15],127,in)==NULL) { for(ra=0;ra<15;ra++) { fprintf(out,"%s",s[ra]); } goto labelabel; } if(strlen(s[15])<9) continue; break; } while(1) { rb=1; for(ra=1;ra<16;ra++) { if(comp(s[ra-1],s[ra])) { rb=0; sort=1; strcpy(line,s[ra-1]); strcpy(s[ra-1],s[ra]); strcpy(s[ra],line); } } if(rb) break; } fprintf(out,"%s",s[0]); } labelabel: fclose(in); fclose(out); remove(inname); rename(outname,inname); } } //----------------------------------------------------------------------------- // Copyright (c) David Welch, 1996 //-----------------------------------------------------------------------------