home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
LINGU11A
/
UI_TEXT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-14
|
2KB
|
69 lines
/* ui_text.c ---- (C) SichemSoft 1991 --- ASR 930314 */
/* 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;
int 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,check,checksum=0;
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) return 0;
/* read file header */
if (!vers) vers="";
q=strrchr(file,'\\'); if (q) q++; else q=file;
len=strlen(q)+strlen(vers);
if (!fread(buf,(len+1)*sizeof(char),1,fp)) return 0;
if (strnicmp(buf,q,strlen(q))) return 0;
if (strnicmp(buf+strlen(q),vers,strlen(vers))) return 0;
/* read number of items and characters and reserve space */
if (!fread(&count,sizeof(count),1,fp)) return 0;
ui_text=(char **)malloc(count*sizeof(char *));
if (!fread(&size,sizeof(size),1,fp)) return 0;
ui_textbuffer=(char *)malloc(size*sizeof(char));
if (!ui_text || !ui_textbuffer) return 0;
/* read offsets and compute pointers */
for (i=0; i<count; i++) {
if (!fread(&offset,sizeof(offset),1,fp)) return 0;
ui_text[i]=ui_textbuffer+offset;
}
/* read text lines and checksum */
fread(ui_textbuffer,size*sizeof(char),1,fp);
fread(&check,sizeof(check),1,fp);
fclose(fp);
/* decrypt text lines and compute checksum */
for (offset=0; offset<size; offset++) {
q=ui_textbuffer+offset;
if (*q) { *q^=UIT_ENCRYPT; checksum+=(unsigned char)(*q); }
}
/* check checksum */
if (check!=checksum) return 0;
return 1;
} /* ui_loadtext */
void ui_unloadtext(void)
{
free(ui_text); free(ui_textbuffer);
} /* ui_unloadtext */