Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 1277 → Rev 1276

/svarlang.lib/trunk/auto_nls.c
File deleted
/svarlang.lib/trunk/autoload.c
22,9 → 22,17
* DEALINGS IN THE SOFTWARE.
*/
 
#include <stdlib.h>
 
#include "svarlang.h"
 
int svarlang_autoload(const char *progname) {
if (svarlang_autoload_nlspath(progname) == 0) return(0);
return(-1);
const char *s;
char langid[3];
s = getenv("LANG");
if ((s == NULL) || (*s == 0)) return(-1);
langid[0] = s[0];
langid[1] = s[1];
langid[2] = 0;
return(svarlang_load(progname, langid, getenv("NLSPATH")));
}
/svarlang.lib/trunk/makefile
7,37 → 7,33
 
CFLAGS=-0 -wx -we -ox
 
svarlngs.lib: autoload.c auto_nls.c svarlang.c version.c
svarlngs.lib: autoload.c svarlang.c version.c
wcc $(CFLAGS) -ms autoload.c
wcc $(CFLAGS) -ms auto_nls.c
wcc $(CFLAGS) -ms svarlang.c
wcc $(CFLAGS) -ms version.c
if exist svarlngs.lib del svarlngs.lib
wlib -n svarlngs.lib +autoload.obj +auto_nls.obj +svarlang.obj +version.obj
wlib -n svarlngs.lib +autoload.obj +svarlang.obj +version.obj
 
svarlngc.lib: autoload.c auto_nls.c svarlang.c version.c
svarlngc.lib: autoload.c svarlang.c version.c
wcc $(CFLAGS) -mc autoload.c
wcc $(CFLAGS) -mc auto_nls.c
wcc $(CFLAGS) -mc svarlang.c
wcc $(CFLAGS) -mc version.c
if exist svarlngc.lib del svarlngc.lib
wlib -n svarlngc.lib +autoload.obj +auto_nls.obj +svarlang.obj +version.obj
wlib -n svarlngc.lib +autoload.obj +svarlang.obj +version.obj
 
svarlngm.lib: autoload.c auto_nls.c svarlang.c version.c
svarlngm.lib: autoload.c svarlang.c version.c
wcc $(CFLAGS) -mm autoload.c
wcc $(CFLAGS) -mm auto_nls.c
wcc $(CFLAGS) -mm svarlang.c
wcc $(CFLAGS) -mm version.c
if exist svarlngm.lib del svarlngm.lib
wlib -n svarlngm.lib +autoload.obj +auto_nls.obj +svarlang.obj +version.obj
wlib -n svarlngm.lib +autoload.obj +svarlang.obj +version.obj
 
svarlngl.lib: autoload.c auto_nls.c svarlang.c version.c
svarlngl.lib: autoload.c svarlang.c version.c
wcc $(CFLAGS) -ml autoload.c
wcc $(CFLAGS) -ml auto_nls.c
wcc $(CFLAGS) -ml svarlang.c
wcc $(CFLAGS) -ml version.c
if exist svarlngl.lib del svarlngl.lib
wlib -n svarlngl.lib +autoload.obj +auto_nls.obj +svarlang.obj +version.obj
wlib -n svarlngl.lib +autoload.obj +svarlang.obj +version.obj
 
 
tlumacz.exe: tlumacz.c
/svarlang.lib/trunk/svarlang.c
135,20 → 135,42
}
 
 
int svarlang_load(const char *fname, const char *lang) {
int svarlang_load(const char *progname, const char *lang, const char *nlspath) {
unsigned short langid;
unsigned short fd;
char hdr[4];
char buff[128];
unsigned short buff16[2];
unsigned short i;
 
if (lang == NULL) return(-1);
if (nlspath == NULL) nlspath = ""; /* nlspath can be NULL, treat is as empty */
 
langid = *((unsigned short *)lang);
langid &= 0xDFDF; /* make sure lang is upcase */
 
fd = FOPEN(fname);
if (fd == 0xffff) return(-1);
TRYNEXTPATH:
 
/* skip any leading ';' separators */
while (*nlspath == ';') nlspath++;
 
/* copy nlspath to buff and remember len */
for (i = 0; (nlspath[i] != 0) && (nlspath[i] != ';'); i++) buff[i] = nlspath[i];
nlspath += i;
 
/* add a trailing backslash if there is none (non-empty paths empty) */
if ((i > 0) && (buff[i - 1] != '\\')) buff[i++] = '\\';
 
strcpy(buff + i, progname);
strcat(buff + i, ".lng");
 
fd = FOPEN(buff);
if (fd == 0xffff) { /* failed to open file - either abort or try next path */
if (*nlspath == 0) return(-2);
goto TRYNEXTPATH;
}
 
/* read hdr, should be "SvL\33" */
if ((FREAD(fd, hdr, 4) != 4) || (memcmp(hdr, "SvL\33", 4) != 0)) {
if ((FREAD(fd, buff, 4) != 4) || (memcmp(buff, "SvL\33", 4) != 0)) {
FCLOSE(fd);
return(-3);
}
/svarlang.lib/trunk/svarlang.h
26,34 → 26,35
#define SVARLANG_H
 
/* library version */
#define SVARLANGVER "20230709"
#define SVARLANGVER "20230630"
 
/* returns a pointer to a string with the SvarLANG's library version,
* independently of the SVARLANGVER string above. */
const char *svarlang_getver(void);
 
/* loads lang translations from file fname.
/* loads translations for program progname, language lang, in paths.
*
* only the two first letters of the lang strings are meaningful and they are
* case insensitive.
*
* a typical call would be: svarlang_load("myprog.lng", "PL");
* paths can be either a directory path (like "C:\DATA") or a list of paths
* separated by a semicolon (example: "C:\DATA;.\LANGS;."). It may also be
* NULL, in which case only the current directory will be searched.
*
* a typical call would be this: svarlang_load("myprog", "PL", NULL);
*
* this function returns 0 on success, non-zero otherwise. It is still possible
* to call svarlang_strid() after a load failure, the previously loaded
* language will be used then, or the default language if no loading has been
* done yet. */
int svarlang_load(const char *fname, const char *lang);
int svarlang_load(const char *progname, const char *lang, const char *paths);
 
 
/* this relies on getenv() to pull LANG and NLSPATH variables and looks
* for a translation file named "%NLSPATH%\progname.lng".
/* same as svarlang_load(), but relies on getenv() to pull LANG and NLSPATH.
* this call should be used only by "CORE" SvarDOS programs. */
int svarlang_autoload_nlspath(const char *progname);
 
/* alias to svarlang_autoload_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
/svarlang.lib/trunk/svarlang.txt
37,7 → 37,7
Then, DEFLANG.C must be compiled and linked to your program along with
SVARLNGx.LIB. From there you will be able to use SvarLANG calls, typically:
 
svarlang_load("myprogram.lng", "pl"); /* load PL lang from myprogram.lng */
svarlang_load("myprogram", "pl", "."); /* load .\myprogram.lng */
puts(svarlang_str(2, 0)); /* display the string with id 2.0 */
 
Read svarlang.h for more information about available functions.