home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / ios_src / langload.c < prev    next >
C/C++ Source or Header  |  1993-01-31  |  2KB  |  120 lines

  1. /*
  2. **    Recompile this module after each change in the language file.
  3. */
  4.  
  5. #include     <stdio.h>
  6. #include     <string.h>
  7. #include     <stdlib.h>
  8. #include     <ext.h>
  9. #include     <time.h>
  10.  
  11. #include     "portab.h"
  12. #include     "defs.h"
  13. #include    "lang.h"
  14.  
  15. #include     "vars.h"
  16. #include     "modules.h"
  17. #include     "strutil.h"
  18.  
  19. MLOCAL BYTE *RDlang_line(VOID);
  20.  
  21. MLOCAL BYTE *RDlang_line() {
  22.     MLOCAL BYTE buffer[1024];
  23.     BYTE        *p;
  24.     WORD        j;
  25.     
  26.     p = buffer;
  27.     
  28.     while(1) {
  29.         j = getc(FDUMMY);
  30.         if(feof(FDUMMY)) return (NULL);
  31.         
  32.         if (j == '\n' || j == '\r')
  33.         break;
  34.         
  35.         *p++ = (BYTE)j;
  36.     }
  37.     
  38.     *p = EOS;
  39.     
  40.     return (buffer);
  41. }
  42.     
  43. BOOLEAN langload() {
  44.     BYTE *buffer,
  45.          *p,*q;
  46.     WORD i,
  47.          lang = 0;
  48.     
  49.     if ((FDUMMY = fopen(LANG_FILE,"r")) == NULL) {
  50.         printf("Can't open language file, check for %s",LANG_FILE);
  51.         return (FALSE);
  52.     }
  53.     
  54.     while (!feof(FDUMMY)) {
  55.         buffer = RDlang_line();
  56.         if (!buffer) break;
  57.         
  58.         p = skip_blanks(buffer);
  59.         
  60.         if (*p == ';') continue;
  61.         if ((i = (WORD)strlen(p)) < 3) continue;
  62.         if ((q = strrchr(p,';')) != NULL) *q = EOS;
  63.         
  64.         q = &p[--i];
  65.         if (*q == '\r' || *q == '\n') *q = EOS;
  66.         
  67.         p = skip_after_blanks(p);
  68.         
  69.         Logmessage[ lang ] = (BYTE *)malloc(strlen(p) +2L);
  70.         
  71.         if (!Logmessage[ lang ]) {
  72.             printf ("Memory error ....");
  73.             return (FALSE);
  74.         }
  75.         
  76.         strcpy(Logmessage[lang++], p);
  77.         if (lang == LAST_MESSAGE) break;
  78.     }
  79.     fclose (FDUMMY);
  80.     
  81.     if (lang < LAST_MESSAGE) {
  82.         printf("Languagefile must be at least %d lines.",LAST_MESSAGE + 1);
  83.         return (FALSE);
  84.     }
  85.  
  86. /*
  87. **    Read productcode file from disk.
  88. */
  89.     
  90.     if ((FDUMMY = fopen(PRD_FILE, "r")) != NULL) {
  91.         while (fgets(buffer, 1024, FDUMMY)) {
  92.             p = skip_blanks (buffer);
  93.             if (*p == ';') continue;
  94.             if ((i = (WORD)strlen(p)) < 3) continue;
  95.             if ((q = strchr(p, ';')) != NULL) *q = EOS;
  96.             
  97.             q = &p [--i];
  98.             if (*q == '\n' || *q == '\r') *q = EOS;
  99.             
  100.             p = skip_after_blanks(p);
  101.             
  102.             PRDcode[maxPRD] = (BYTE *)malloc (strlen (p) + 2L);
  103.             if (PRDcode[maxPRD]) {
  104.                 strcpy(PRDcode[maxPRD++], p);
  105.                 
  106.                 if (maxPRD > 255) break;
  107.                 
  108.                 continue;
  109.             } else {
  110.                 printf("Memory error ....");
  111.                 return (FALSE);
  112.             }
  113.         }
  114.         fclose (FDUMMY);
  115.     }
  116.     
  117.     
  118.     return (TRUE);
  119. }
  120.