home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / parser / lingua / ui_text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-13  |  1.8 KB  |  64 lines

  1. /* ui_text.c --- (C) SichemSoft 1991 --- ASR 920613  */
  2. /* Roghorst 160,  6708 KS Wageningen,   Netherlands  */
  3. /* text module for language independent applications */
  4.  
  5. #include <stdio.h>
  6. #include <alloc.h>
  7. #include <string.h>
  8. #include <process.h>
  9.  
  10. #define UIT_ENCRYPT 53
  11.  
  12. char **ui_text;
  13. static char *ui_textbuffer;
  14.  
  15. void ui_loadtext(char *fname,char *vers)
  16. /* fname is name of desired .etf file without extension
  17.    vers is optional version number, may also be "" */
  18. {
  19.    char *q; FILE *fp; unsigned len,i,count;
  20.    char buf[256],file[81]; unsigned long offset,size;
  21.  
  22.    /* open encrypted text file */
  23.    strcpy(file,fname);
  24.    if (!strchr(file,'.')) strcat(file,".ETF");
  25.    if ((fp=fopen(file,"rb"))==0) goto fatal;
  26.  
  27.    /* read file header */
  28.    len=strlen(file)+strlen(vers);
  29.    if (!fread(buf,1,len+1,fp)) goto fatal;
  30.    if (strnicmp(buf,file,strlen(file))) goto fatal;
  31.    if (strnicmp(buf+strlen(file),vers,strlen(vers))) goto fatal;
  32.  
  33.    /* read number of items and characters and reserve space */
  34.    if (!fread(&count,1,sizeof(count),fp)) goto fatal;
  35.    ui_text=(char **)malloc(count*sizeof(char *));
  36.    if (!fread(&size,1,sizeof(size),fp)) goto fatal;
  37.    ui_textbuffer=(char *)malloc(size*sizeof(char));
  38.    if (!ui_text || !ui_textbuffer) goto fatal;
  39.  
  40.    /* read offsets and compute pointers */
  41.    for (i=0; i<count; i++) {
  42.       if (!fread(&offset,1,sizeof(offset),fp)) goto fatal;
  43.       ui_text[i]=ui_textbuffer+offset;
  44.    }
  45.  
  46.    /* read text lines */
  47.    fread(ui_textbuffer,size*sizeof(char),1,fp);
  48.    fclose(fp);
  49.  
  50.    /* decrypt text lines */
  51.    for (offset=0; offset<size; offset++) {
  52.       q=ui_textbuffer+offset; if (*q) *q^=UIT_ENCRYPT;
  53.    }
  54.    return;
  55.  
  56. fatal: printf("?? %s ??\n",file);
  57.    exit(1);
  58. } /* ui_loadtext */
  59.  
  60. void ui_unloadtext(void)
  61. {
  62.    free(ui_text); free(ui_textbuffer);
  63. } /* ui_unloadtext */
  64.