//svarlang.lib/trunk/auto_exe.c |
---|
0,0 → 1,77 |
/* This file is part of the svarlang project and is published under the terms |
* of the MIT license. |
* |
* Copyright (C) 2021-2023 Mateusz Viste |
* |
* Permission is hereby granted, free of charge, to any person obtaining a |
* copy of this software and associated documentation files (the "Software"), |
* to deal in the Software without restriction, including without limitation |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
* and/or sell copies of the Software, and to permit persons to whom the |
* Software is furnished to do so, subject to the following conditions: |
* |
* The above copyright notice and this permission notice shall be included in |
* all copies or substantial portions of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
* DEALINGS IN THE SOFTWARE. |
*/ |
#include <stdlib.h> /* _psp */ |
#include <string.h> /* _fmemcpy() */ |
#include <i86.h> /* MK_FP() */ |
#include "svarlang.h" |
int svarlang_autoload_exepath(const char *lang) { |
unsigned short far *psp_envseg = MK_FP(_psp, 0x2c); /* pointer to my env segment field in the PSP */ |
char far *myenv = MK_FP(*psp_envseg, 0); |
unsigned short len; |
char orig_ext[3]; |
int res; |
/* who am i? look into my own environment, at the end of it should be my EXEPATH string */ |
while (*myenv != 0) { |
/* consume a NULL-terminated string */ |
while (*myenv != 0) myenv++; |
/* move to next string */ |
myenv++; |
} |
myenv++; /* skip the nul terminator */ |
/* check next word, if 1 then EXEPATH follows */ |
if (*myenv != 1) return(-1); |
myenv++; |
if (*myenv != 0) return(-1); |
myenv++; |
/* myenv contains my full name, find end of string now */ |
for (len = 0; myenv[len] != 0; len++); |
/* must be at least 5 bytes long and 4th char from end must be a dot (like "a.exe") */ |
if ((len < 5) || (myenv[len - 4] != '.')) return(-1); |
/* copy extension to buffer and replace it with "lng" */ |
orig_ext[0] = myenv[len - 3]; |
orig_ext[1] = myenv[len - 2]; |
orig_ext[2] = myenv[len - 1]; |
myenv[len - 3] = 'L'; |
myenv[len - 2] = 'N'; |
myenv[len - 1] = 'G'; |
/* try loading it now */ |
res = svarlang_load(myenv, lang); /* TODO FIXME myenv is a far pointer, while svarlang_load() in small or medium memory models expects a near ptr */ |
/* restore the original filename and quit */ |
myenv[len - 3] = orig_ext[0]; |
myenv[len - 2] = orig_ext[1]; |
myenv[len - 1] = orig_ext[2]; |
return(res); |
} |
//svarlang.lib/trunk/makefile |
---|
7,37 → 7,41 |
CFLAGS=-0 -wx -we -ox |
svarlngs.lib: autoload.c auto_nls.c svarlang.c version.c |
svarlngs.lib: autoload.c auto_exe.c auto_nls.c svarlang.c version.c |
wcc $(CFLAGS) -ms autoload.c |
wcc $(CFLAGS) -ms auto_exe.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 +auto_exe.obj +auto_nls.obj +svarlang.obj +version.obj |
svarlngc.lib: autoload.c auto_nls.c svarlang.c version.c |
svarlngc.lib: autoload.c auto_exe.c auto_nls.c svarlang.c version.c |
wcc $(CFLAGS) -mc autoload.c |
wcc $(CFLAGS) -mc auto_exe.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 +auto_exe.obj +auto_nls.obj +svarlang.obj +version.obj |
svarlngm.lib: autoload.c auto_nls.c svarlang.c version.c |
svarlngm.lib: autoload.c auto_exe.c auto_nls.c svarlang.c version.c |
wcc $(CFLAGS) -mm autoload.c |
wcc $(CFLAGS) -mm auto_exe.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 +auto_exe.obj +auto_nls.obj +svarlang.obj +version.obj |
svarlngl.lib: autoload.c auto_nls.c svarlang.c version.c |
svarlngl.lib: autoload.c auto_exe.c auto_nls.c svarlang.c version.c |
wcc $(CFLAGS) -ml autoload.c |
wcc $(CFLAGS) -ml auto_exe.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 +auto_exe.obj +auto_nls.obj +svarlang.obj +version.obj |
tlumacz.exe: tlumacz.c |
//svarlang.lib/trunk/svarlang.h |
---|
45,6 → 45,9 |
* done yet. */ |
int svarlang_load(const char *fname, const char *lang); |
/* tries loading lang strings from a file located in the executable's |
* directory that is named like the executable but with an *.LNG extension */ |
int svarlang_autoload_exepath(const char *lang); |
/* this relies on getenv() to pull LANG and NLSPATH variables and looks |
* for a translation file named "%NLSPATH%\progname.lng". |
51,9 → 54,6 |
* 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 |