added index builder source code
authorecalot <ecalot>
Sun, 13 Jun 2004 06:34:25 +0000 (06:34 +0000)
committerecalot <ecalot>
Sun, 13 Jun 2004 06:34:25 +0000 (06:34 +0000)
stuff/data/bin/src/makeindex.c [new file with mode: 0644]

diff --git a/stuff/data/bin/src/makeindex.c b/stuff/data/bin/src/makeindex.c
new file mode 100644 (file)
index 0000000..0acc6f7
--- /dev/null
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int c, char** files) {
+       char* def;
+       char* index;
+       FILE* fpd;
+       FILE* fpi;
+       char filename[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+       unsigned short int i;
+       unsigned short int numbers[500];
+       
+       if (c!=3) {
+               fprintf(stderr,"Syntax: %s file.def file.index\n",files[0]);
+               exit(1);
+       }
+
+       def=files[1];
+       index=files[2];
+
+       //Start processing the file
+
+       //Open files
+       fpd=fopen(def,"rt");
+       if (fpd==NULL) {
+               fprintf(stderr,"Definition file (%s) not found\n",def);
+               exit(1);
+       }
+       fpi=fopen(index,"wb");
+       if (fpi==NULL) {
+               fprintf(stderr,"Index file (%s) not saved\n",index);
+               fclose(fpd);
+               exit(1);
+       }
+
+       //process filename
+       fgets(filename,sizeof(filename),fpd);
+       fwrite(filename,1,20,fpi);
+
+       //resd numbers
+       i=0;
+       while (!feof(fpd)) {
+               fgets(filename,sizeof(filename),fpd);
+               numbers[i]=atoi(filename);
+               i++;
+       }
+       i--; //ignore feof
+       
+       i--; //the first number is the type
+       
+       //write numbers
+       fwrite(&i,1,2,fpi);
+       i++;
+       fwrite(numbers,i,2,fpi);
+
+       //end files
+       fclose(fpi);
+       fclose(fpd);
+
+       exit(0);
+}
+