home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
POINT Software Programming
/
PPROG1.ISO
/
misc
/
lingua12
/
lingua.doc
< prev
next >
Wrap
Text File
|
1993-05-21
|
10KB
|
256 lines
---- LINGUA -- MULTILANGUAGE SUPPORT FOR YOUR PROGRAMS -- SHAREWARE ----
-- VERSION 1.2 -- (C) 1993 -- SICHEMSOFT -- WAGENINGEN -- NETHERLANDS --
The LINGUA package is designed to help C-programmers to develop applications
that must be released in multiple languages. The end user gets a program
plus one or more datafiles containing all text in the program. One
datafile for each different language. A language can be chosen at
run time. This thus avoids different .exe files for different languages.
The programmer needs only to compile one executable and to make a text data
file for every supported language. It's also easy to afterwards create
support for yet another language and send the data file to interested
customers.
HOW IT WORKS
The package consists of a program, LINGUA, and a module, UI_TEXT (UI
stands for User Interface). The module should be compiled and linked with
your application program. This module is the same for any language and
is very small (about 3.5KB when compiled with Borland C++ 3.1 under MSDOS).
For every supported language a text file is prepared by the programmer
according to a specified format. This text file is then encrypted by LINGUA,
so users cannot alter and perhaps corrupt it just by editing it. These
encrypted text files are shipped with the application and one of them is
loaded by the module UI_TEXT at run time so the application speaks the
desired language.
FILES IN THE PACKAGE
LINGUA.DOC You're reading it
LINGUA.EXE Utility to encrypt .TXT file to .ETF file
LINGUA.C Source of the above
UI_TEXT.OBJ Module to be linked with your application (large model)
UI_TEXT.C Source of the above
LINGDEMO.EXE Small demo program, usage e.g.: lingdemo francais
LINGDEMO.C Source of the above
LINGUA.H Include file for compilation of lingua.c and ui_text.c
FILES.INC Include file for ui_text.c, replace if desired (see below)
MAKEFILE Makefile for the above programs (DOS/BC++)
UNIX.MAK Makefile for the above programs (UNIX)
NOCR.C Source for carriage-return/end-of-file remover for UNIX
ENGLISH.TXT Text files for demo program
FRANCAIS.TXT
DEUTSCH.TXT
NL.TXT
ENGLISH.ETF Encrypted files for demo program
DEUTSCH.ETF
FRANCAIS.ETF
NL.ETF
UI_TEXT.H Header file created by LINGUA from .txt files above
The file FILES.INC defines all file functions for ui_text.c. FILES.INC uses
the standard C library file functions, like fopen, fseek etc. If you wish
to use other file functions, or C++ streams functions, or whatever, you can
write your own FILES.INC with these functions.
USAGE
First of all, do not use ANY literal strings in your C-source, but
always use identifiers, e.g. not "Press any key" but ANYKEY.
Write your program in any way you like while observing this main rule.
At the same time create and maintain a text file with all literal
text for the program in your native language. This file may have any
name but its extension should be .TXT for use by LINGUA. The lines in
this text file should all begin (at the first position!) with an identifier,
corresponding to the identifiers used in the program. Behind the identifier
follows the literal string that should be used in run time. Comment lines
are allowed, they must begin with #. In the literal strings _ signifies
a leading or trailing space, and - denotes an empty string. String arrays,
in which not every item has its own name, are represented by [ after an
identifier's name followed by one or more lines starting with only [.
Multiline strings are represented by / after an identifier's name followed
bye one or more lines starting with only /.
By default the text is loaded all at once into memory at the start of the
application (or rather by calling ui_loadtext) and deleted at the end of
the application (ui_unloadtext). If desired, part or all of the text can
be read from the file only when necessary. For this, use the directive
#FILE in the text file (see example below). All text after this directive
will only be loaded when necessary. All text before #FILE remains resident
in memory. You could place all frequently used strings before #FILE and
seldom used or very long strings after #FILE. If #FILE is used the text
file will remain open between ui_loadtext and ui_unloadtext.
Example file english.txt:
#english.txt
#empty string
ZEROTH -
#normal strings
FIRST one
SECOND two times
#array
THIRD[ three
[ four
[ five
[ -
[ seven
#leading and trailing spaces
EIGHTH __eight__
#FILE
#normal string again
NINTH nine
#multi line string
TENTH/ this is
/ a multiline
/ tenth string
#that's it!
ELEVEN eleven
Whenever any identifier in this text file has been added/edited/deleted,
run the utility LINGUA, like:
lingua english
and recompile (like you would also have to do if you had edited
literal strings in your source code).
LINGUA creates two files: english.etf and ui_text.h (ETF stands for
Encrypted Text File). The header file UI_TEXT.H must be included in the
source file that takes care of the loading and unloading of the text
at run time. Since this header is not language dependent, no
recompilation for another language is necessary. It contains only
defines for all identifiers as show below.
Example file ui_text.h:
/* ui_text.h */
int ui_loadtext(char *fname,char *vers);
void ui_unloadtext(void);
char *ui_filetext(unsigned pos);
char **ui_filearray(unsigned pos);
extern char **ui_text;
#define ZEROTH ui_text[0]
#define FIRST ui_text[1]
#define SECOND ui_text[2]
#define THIRD (ui_text+3)
#define EIGHTH ui_text[8]
#define NINTH ui_filetext(0)
#define TENTH ui_filetext(1)
#define ELEVEN ui_filetext(2)
When your application is finished, make a copy of the original .TXT
file and change the literal strings in the copy to another language.
Be careful not to change the identifiers at the start of every line though!
When you run LINGUA on this text file a new .ETF file is created
(and also a ui_text.h, but this one is identical to the one in the
original language).
In the application program, start with a call to ui_loadtext (in
the UI_TEXT module). End the application program with a call to
ui_unloadtext. Another language may be loaded at that point too.
Lingua also writes a checksum at the start of the .ETF file. ui_loadtext
returns 1 if the file was read and decoded successfully and the
computed checksum is equal to the one in the file and 0 if not.
You can then handle an error condition in your application (but
in what language?).
Example file lingdemo.c (link with ui_text.c):
#include <stdio.h>
#include <string.h>
#include "ui_text.h"
int main(int argc,char *argv[])
{
char filename[81],version[81];
if (argc>3) return 1;
if (argc==3) strcpy(version,argv[2]); else version[0]='\0';
if (argc>=2) strcpy(filename,argv[1]); else strcpy(filename,"english");
if (ui_loadtext(filename,version)) {
printf("%s",FIRST);
printf("%s",SECOND);
printf("%s",THIRD[0]);
printf("%s",THIRD[1]);
printf("%s",THIRD[2]);
printf("%s",THIRD[3]);
printf("%s",THIRD[4]);
printf("%s",EIGHTH);
printf("%s",NINTH);
printf("%s",TENTH);
printf("%s",ELEVEN);
ui_unloadtext();
} else puts("Fatal error");
return 0;
}
Execute this example program by:
lingdemo <name of etf-file without extension>
e.g.:
lingdemo english
If so desired an optional version number (or other string) may be
given as second argument for the LINGUA utility. This same version
number should then be used as the second parameter in the call
to ui_loadtext. This can be useful to let ui_loadtext reject a file
from a previous version of your application program.
NOTE: You should be aware of one snag when using the #FILE directive.
Every identifier that is defined after #FILE results in a pointer to the
same filebuffer. This means that when using two consecutive strings the
latter will overwrite the former. This leads to problems with something like:
printf("%s%s\n",TENTH,ELEVEN);
This will result in printing "eleven" twice. Instead, to be safe, use:
printf("%s",TENTH); printf("%s",ELEVEN);
NOTE 2: UNIX users should strip all carriage returns and the end-of-file
character from the sources. You may compile and use NOCR.C for this.
SHAREWARE NOTICE
You may copy and distribute this program freely, as long as all parts
of the package are included without modification. This is a shareware
(NOT public domain) package; if you like it and use it on a regular
basis please register it. Registration can be done at no charge by
sending me a picture postcard from were you live or work. Suggestions
for improvement are welcomed any time. Please do NOT modify the source
code and pass that on. Send modified source code to me and I will
include your modification, if I consider it useful, in a future release.
COMMERCIAL USERS -MUST- REGISTER AND -MUST- MENTION THE USE OF LINGUA
IN THEIR DOCUMENTATION: LINGUA 1.2 (C) SICHEMSOFT, WAGENINGEN, NETHERLANDS.
WE ALSO REQUEST A FREE COPY OF EVERY PRODUCT THAT MAKES USE OF LINGUA!!
I hope many people, programmers and users alike, will benefit from LINGUA!
Anneke Sicherer-Roetman
SichemSoft
Roghorst 160
6708 KS Wageningen
Netherlands
email: anneke@chem.ruu.nl
anneke@hutruu54.bitnet
VERSION HISTORY
1.0 - 920613 - initial release
1.1 - 930314 - added multi line string support
added checksum computation and check
changed ui_loadtext return type from void to int
fixed minor bug
1.2 - 930521 - added support for reading text from file at run time (#FILE)
added support for DOS vs. UNIX (makefiles, \r\n vs.\n)
added programmers' choice of file functions (FILES.INC)