Subversion Repositories SvarDOS

Rev

Rev 1306 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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