home *** CD-ROM | disk | FTP | other *** search
- /* lingua.c -- (C) SichemSoft 1991 -- ASR 920613 */
- /* Roghorst 160, 6708 KS Wageningen, Netherlands */
- /* utility for language independent applications */
-
- #include <stdio.h>
- #include <string.h>
-
- #define UIT_ENCRYPT 53
-
- static FILE *openfile(char *name,char *mode)
- {
- FILE *fp;
-
- fp=fopen(name,mode);
- if (!fp) printf("%s not opened\n",name);
- return fp;
- } /* openfile */
-
- int main(int argc,char *argv[])
- {
- FILE *txt,*etf,*header; char fname[81];
- unsigned long offset=0,filpos=0;
- unsigned count=0,len=0,array=0,l=0;
- char buf[256],*p,*q;
-
- if (argc!=2 && argc!=3) {
- puts("lingua <file> [<version>]"); return 1;
- }
-
- /* open all files */
- strcpy(fname,argv[1]); strupr(fname);
- if (!strchr(fname,'.')) strcat(fname,".TXT");
- if ((txt=openfile(fname,"r"))==NULL) return 2;
- if ((header=openfile("UI_TEXT.H","w"))==NULL) return 2;
- strcpy(strchr(fname,'.')+1,"ETF");
- if ((etf=openfile(fname,"wb"))==NULL) return 2;
-
- /* start of UI_TEXT.H */
- fputs("/* UI_TEXT.H */\n\n",header);
- fputs("void ui_loadtext(char *fname,char *vers);\n",header);
- fputs("void ui_unloadtext(void);\n",header);
- fputs("extern char **ui_text;\n\n",header);
-
- /* start of .ETF (filename+version) */
- fprintf(etf,"%s%s\032",fname,argc==3?argv[2]:"");
- filpos=ftell(etf);
- fwrite(&count,sizeof(count),1,etf);
- fwrite(&offset,sizeof(offset),1,etf);
-
- /* count lines, determine offsets and write to .ETF and .H */
- while (fgets(buf,255,txt)) {
- if (buf[0]=='#') continue; /* comment */
- p=strchr(buf,' '); if (!p) goto fatal;
- *p=0; p++; while (*p==' ') p++;
- len=strlen(p); p[len-1]='\0'; if (!strcmp(p,"-")) len=1;
- l=strlen(buf)-1;
- if (buf[l]=='[') { /* array identifier */
- if (l>1) {
- if (array) goto fatal; array=1; buf[l]='\0';
- fprintf(header,"#define %-30s (ui_text+%u)\n",buf,count);
- } else if (!array) goto fatal;
- } else { /* normal identifier */
- if (array) array=0;
- fprintf(header,"#define %-30s ui_text[%u]\n",buf,count);
- }
- fwrite(&offset,sizeof(offset),1,etf);
- offset+=len; count++;
- }
-
- /* encrypt lines and write to .ETF */
- rewind(txt);
- while (fgets(buf,255,txt)) {
- if (buf[0]=='#') continue; /* comment */
- p=strchr(buf,' ');
- *p=0; p++; while (*p==' ') p++;
- len=strlen(p); p[len-1]='\0'; if (!strcmp(p,"-")) p[0]='\0';
- for (q=p; *q=='_'; q++) *q=' ';
- for (q=p+len-2; *q=='_'; q--) *q=' ';
- for (q=p; *q; q++) *q^=UIT_ENCRYPT;
- fprintf(etf,p); putc('\0',etf);
- }
-
- /* write number of lines and bytes to .ETF */
- fseek(etf,filpos,SEEK_SET);
- fwrite(&count,sizeof(count),1,etf);
- fwrite(&offset,sizeof(offset),1,etf);
-
- /* close all files */
- fclose(txt); fclose(etf); fclose(header);
- printf("%u items, %lu bytes\n",count,offset);
-
- return 0;
-
- fatal: puts("fatal in text file");
- return 3;
- }
-