home *** CD-ROM | disk | FTP | other *** search
/ Gul´dan´s Rache / GULDAN.BIN / wartools / stred / stred.c next >
Encoding:
C/C++ Source or Header  |  1996-08-24  |  1.4 KB  |  92 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argn, char **argc) {
  5.  
  6.     FILE *fp;
  7.     char *buf, *temp;
  8.     int index, len[104];
  9.  
  10.     if (argn < 2) {
  11.  
  12.         fp = fopen("data\\strdat.war", "rb");
  13.  
  14.         if(!fp) {
  15.             printf("Error opening data\\strdat.war\n");
  16.             return(0);
  17.         }
  18.  
  19.         buf = (char *)malloc(0x04e1);
  20.  
  21.         fseek(fp, 0x05e4, 0);
  22.         fread(buf, 0x04e1, 1, fp);
  23.  
  24.         temp = buf;
  25.         index = 0;
  26.  
  27.         while(index++ < 104) {
  28.             printf("%s\n", temp);
  29.             while(*temp) temp++;
  30.             temp++;
  31.         }
  32.     }
  33.  
  34.     else {
  35.  
  36.         fp = fopen(argc[1], "rt");
  37.  
  38.         if(!fp) {
  39.             printf("Error opening %s\n", argc[1]);
  40.             return(0);
  41.         }
  42.  
  43.         fseek(fp, 0, 2);
  44.         if (ftell(fp) > 0x0549) {
  45.             printf("Names too long in %s\n", argc[1]);
  46.             return(0);
  47.         }
  48.         fseek(fp, 0, 0);
  49.  
  50.         buf = (char *)malloc(0x04e1);
  51.         temp = buf;
  52.  
  53.         index = 0;
  54.         while(index < 104) {
  55.  
  56.             if(feof(fp)) {
  57.                 printf("Not enough names in %s\n", argc[1]);
  58.                 free(buf);
  59.                 return(0);
  60.             }
  61.  
  62.             if(index) len[index] = len[index-1];
  63.             else len[index] = 0x03c1;
  64.  
  65.             fgets(temp, 80, fp);
  66.             while(*temp != '\n') {
  67.                 temp++;
  68.                 len[index]++;
  69.             }
  70.             *temp++ = 0;
  71.             len[index++]++;
  72.         }
  73.  
  74.         fclose(fp);
  75.         fp = fopen("data\\strdat.war", "r+b");
  76.  
  77.         if(!fp) {
  78.             printf("Error opening data\\strdat.war\n");
  79.             return(0);
  80.         }
  81.  
  82.         fseek(fp, 0x0229, 0);
  83.         fwrite(len, 206, 1, fp);
  84.  
  85.         fseek(fp, 0x05e4, 0);
  86.         fwrite(buf, 0x04e1, 1, fp);
  87.         fclose(fp);
  88.     }
  89.  
  90.     return(1);
  91. }
  92.