home *** CD-ROM | disk | FTP | other *** search
- /* ui_text.c --- (C) SichemSoft 1991 --- ASR 920613 */
- /* Roghorst 160, 6708 KS Wageningen, Netherlands */
- /* text module for language independent applications */
-
- #include <stdio.h>
- #include <alloc.h>
- #include <string.h>
- #include <process.h>
-
- #define UIT_ENCRYPT 53
-
- char **ui_text;
- static char *ui_textbuffer;
-
- void ui_loadtext(char *fname,char *vers)
- /* fname is name of desired .etf file without extension
- vers is optional version number, may also be "" */
- {
- char *q; FILE *fp; unsigned len,i,count;
- char buf[256],file[81]; unsigned long offset,size;
-
- /* open encrypted text file */
- strcpy(file,fname);
- if (!strchr(file,'.')) strcat(file,".ETF");
- if ((fp=fopen(file,"rb"))==0) goto fatal;
-
- /* read file header */
- len=strlen(file)+strlen(vers);
- if (!fread(buf,1,len+1,fp)) goto fatal;
- if (strnicmp(buf,file,strlen(file))) goto fatal;
- if (strnicmp(buf+strlen(file),vers,strlen(vers))) goto fatal;
-
- /* read number of items and characters and reserve space */
- if (!fread(&count,1,sizeof(count),fp)) goto fatal;
- ui_text=(char **)malloc(count*sizeof(char *));
- if (!fread(&size,1,sizeof(size),fp)) goto fatal;
- ui_textbuffer=(char *)malloc(size*sizeof(char));
- if (!ui_text || !ui_textbuffer) goto fatal;
-
- /* read offsets and compute pointers */
- for (i=0; i<count; i++) {
- if (!fread(&offset,1,sizeof(offset),fp)) goto fatal;
- ui_text[i]=ui_textbuffer+offset;
- }
-
- /* read text lines */
- fread(ui_textbuffer,size*sizeof(char),1,fp);
- fclose(fp);
-
- /* decrypt text lines */
- for (offset=0; offset<size; offset++) {
- q=ui_textbuffer+offset; if (*q) *q^=UIT_ENCRYPT;
- }
- return;
-
- fatal: printf("?? %s ??\n",file);
- exit(1);
- } /* ui_loadtext */
-
- void ui_unloadtext(void)
- {
- free(ui_text); free(ui_textbuffer);
- } /* ui_unloadtext */
-