Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 599 → Rev 598

/svarlang.lib/autoload.c
File deleted
/svarlang.lib/makefile
1,33 → 1,10
#
# make instructions to build svarlang and tlumacz.exe with OpenWatcom
# Copyright (C) 2021-2022 Mateusz Viste
# make instructions to build tlumacz.exe with OpenWatcom
# Copyright (C) 2021 Mateusz Viste
#
 
all: svarlngs.lib svarlngc.lib svarlngm.lib svarlngl.lib tlumacz.exe
all: tlumacz.exe
 
CFLAGS=-0 -wx -we -ox
 
svarlngs.lib: autoload.c svarlang.c
wcc $(CFLAGS) -ms autoload.c
wcc $(CFLAGS) -ms svarlang.c
wlib svarlngs.lib +autoload.obj +svarlang.obj
 
svarlngc.lib: autoload.c svarlang.c
wcc $(CFLAGS) -mc autoload.c
wcc $(CFLAGS) -mc svarlang.c
wlib svarlngc.lib +autoload.obj +svarlang.obj
 
svarlngm.lib: autoload.c svarlang.c
wcc $(CFLAGS) -mm autoload.c
wcc $(CFLAGS) -mm svarlang.c
wlib svarlngm.lib +autoload.obj +svarlang.obj
 
svarlngl.lib: autoload.c svarlang.c
wcc $(CFLAGS) -ml autoload.c
wcc $(CFLAGS) -ml svarlang.c
wlib svarlngl.lib +autoload.obj +svarlang.obj
 
 
tlumacz.exe: tlumacz.c
wcl -0 -y -cc -wx -mc -lr -we -ox tlumacz.c
del *.obj
/svarlang.lib/svarlang.c
26,14 → 26,11
#include <stdlib.h> /* NULL */
#include <string.h> /* memcmp(), strcpy() */
 
#include "deflang.c"
 
#include "svarlang.h"
 
 
/* supplied through DEFLANG.C */
extern char svarlang_mem[];
extern const unsigned short svarlang_memsz;
 
 
const char *svarlang_strid(unsigned short id) {
const char *ptr = svarlang_mem;
/* find the string id in langblock memory */
89,7 → 86,7
}
 
/* found - but do I have enough memory space? */
if (buff16[1] >= svarlang_memsz) {
if (buff16[1] >= sizeof(svarlang_mem)) {
fclose(fd);
return(-4);
}
/svarlang.lib/svarlang.h
25,21 → 25,10
#ifndef SVARLANG_H
#define SVARLANG_H
 
/* loads translations for program PROGNAME, language LANG, in the path NLSPATH.
* returns 0 on success. */
int svarlang_load(const char *progname, const char *lang, const char *nlspath);
 
/* same as svarlang_load(), but relies on getenv() to pull LANG and NLSPATH. */
int svarlang_autoload(const char *progname);
 
/* Returns a pointer to the string "id". Does not require svalang_load() to be
* executed, but then it will only return the reference language strings.
* a string id is the concatenation of the CATS-style identifiers, for example
* string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc. */
const char *svarlang_strid(unsigned short id);
 
/* a convenience definition to fetch strings by their CATS-style pairs instead
* of the 16-bit id. */
#define svarlang_str(x, y) svarlang_strid((x << 8) | y)
 
#endif
/svarlang.lib/svarlang.txt
1,71 → 1,14
tlumacz is a "compiler" that builds the SvarCOM multi-lang ressource file out
of a collection of CATS/Kitten text files.
 
SVARLANG.LIB - THE SVARDOS TRANSLATION C LIBRARY
usage: tlumacz en fr pl ...
 
tlumacz generates a SVARCOM.LNG file that contains all language ressources.
This file must be then placed in the %NLSPATH% directory so SvarCOM can find it.
SvarCOM's language is controlled by the LANG variable (eg. "SET LANG=PL").
 
SvarLANG is a library and tooling for enabling SvarDOS applications to easily
support multiple languages.
the first language acts as a reference, its strings will be used to fill any
missing translations in other files.
 
 
### PREPARING TRANSLATION FILES ###
 
The translation files must be CATS-style text files in the usual format:
 
1.1:Hello, World!
1.2:Help screen
2.0:Type /? for more options
 
The files must be named as EN.TXT, DE.TXT, FR.TXT, etc. Then, they must be
"compiled" into SvarLANG's binary format using the TLUMACZ tool:
 
tlumacz en fr pl (...)
 
The first language provided in the command line is the reference language and
is used both as the default (embedded in the application) language, as well as
to substitute messages missing in other languages.
 
TLUMACZ computes two files:
 
* OUT.LNG - the binary file that contains all translations
* DEFLANG.C - the default translations that will be embedded into the program
 
Then, DEFLANG.C must be compiled and linked to your program along with
SVARLNGx.LIB. From there, you will be able to use the following calls:
 
/* loads translations for program PROGNAME, language LANG, in the path NLSPATH.
* returns 0 on success. */
int svarlang_load(const char *progname, const char *lang, const char *nlspath);
 
/* same as svarlang_load(), but relies on getenv() to pull LANG and NLSPATH. */
int svarlang_autoload(const char *progname);
 
/* Returns a pointer to the string "id". Does not require svalang_load() to be
* executed, but then it will only return the reference language strings.
* a string id is the concatenation of the CATS-style identifiers, for example
* string 1,0 becomes 0x0100, string 2.10 is 0x020A, etc. */
const char *svarlang_strid(unsigned short id);
 
/* a convenience definition to fetch strings by their CATS-style pairs instead
* of the 16-bit id. */
#define svarlang_str(x, y) svarlang_strid((x << 8) | y)
 
 
### ENVIRONMENT ###
 
All translations files should be placed in the %NLSPATH% directory and should
be named the same as the program's name, with the LNG extension (for example
"INSTALL.LNG" if the program is named "INSTALL").
 
The %LANG% environment variable defines what language should be loaded.
 
 
### WHY IS IT BETTER THAN CATS? ###
 
The CATS library is heavier and slower, as it embeds a text-file parser.
Translations also take more disk space since each file is in a separate file
leading to cluster waste. Finally, CATS requires default strings to be part of
the application's source code, while SvarLANG keeps all strings in TXT files
and embedds the default one inside the application in an automated way at
compile time.
 
 
======================================================================= EOF ===
a DEFAULT.LNG file is also generated, it contains only translation strings for
the reference language. This file is only useful for building SvarCOM.
/svarlang.lib/tlumacz.c
181,7 → 181,7
}
 
 
#define MEMBLOCKSZ 65000
#define MEMBLOCKSZ 65500
 
int main(int argc, char **argv) {
FILE *fd;
255,8 → 255,7
break;
}
fprintf(fd2, "/* THIS FILE HAS BEEN AUTOGENERATE BY TLUMACZ (PART OF THE SVARLANG LIBRARY) */\r\n");
fprintf(fd2, "const unsigned short svarlang_memsz = %uu;\r\n", sz * 2);
fprintf(fd2, "char svarlang_mem[%u] = {\r\n", sz * 2);
fprintf(fd2, "static char svarlang_mem[%u] = {\r\n", sz * 2);
for (x = 0; x < sz; x++) {
fprintf(fd2, "%u", buff[x]);
if (x + 1 < sz) fprintf(fd2, ",");