Subversion Repositories SvarDOS

Rev

Rev 1277 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1277 mateusz.vi 1
/* This file is part of the svarlang project and is published under the terms
2
 * of the MIT license.
3
 *
4
 * Copyright (C) 2021-2023 Mateusz Viste
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
23
 */
24
 
1301 mateusz.vi 25
#include <stdlib.h>  /* getenv(), NULL */
1277 mateusz.vi 26
#include "svarlang.h"
27
 
28
 
29
int svarlang_autoload_nlspath(const char *progname) {
30
  const char *lang;
31
  const char *nlspath;
32
  char buff[128];
1301 mateusz.vi 33
  unsigned short i, ii;
1277 mateusz.vi 34
 
35
  /* read and validate LANG */
36
  lang = getenv("LANG");
1301 mateusz.vi 37
  if ((lang == NULL) || (lang[0] == 0)) return(-1);
1277 mateusz.vi 38
 
39
  /* read and validate NLSPATH */
40
  nlspath = getenv("NLSPATH");
41
  if (nlspath == NULL) return(-2);
42
 
43
  /* look into every path in NLSPATH */
44
  while (*nlspath != 0) {
45
 
46
    /* skip any leading ';' separators */
47
    while (*nlspath == ';') nlspath++;
48
 
49
    if (*nlspath == 0) return(-3);
50
 
51
    /* copy nlspath to buff and remember len */
52
    for (i = 0; (nlspath[i] != 0) && (nlspath[i] != ';'); i++) buff[i] = nlspath[i];
53
    nlspath += i;
54
 
55
    /* add a trailing backslash if there is none (non-empty paths empty) */
56
    if ((i > 0) && (buff[i - 1] != '\\')) buff[i++] = '\\';
57
 
1301 mateusz.vi 58
    /* append progname + ".LNG" to the path */
59
    for (ii = 0; progname[ii] != 0; ii++) buff[i++] = progname[ii];
60
    buff[i++] = '.';
61
    buff[i++] = 'L';
62
    buff[i++] = 'N';
63
    buff[i++] = 'G';
64
    buff[i] = 0;
1277 mateusz.vi 65
 
66
    if (svarlang_load(buff, lang) == 0) return(0);
67
  }
68
  /* failed to load anything */
69
  return(-4);
70
}