Subversion Repositories SvarDOS

Rev

Rev 1301 | 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
 
25
#include "svarlang.h"
26
 
27
 
1306 mateusz.vi 28
int svarlang_autoload_pathlist(const char *progname, const char *pathlist, const char *lang) {
1277 mateusz.vi 29
  char buff[128];
1301 mateusz.vi 30
  unsigned short i, ii;
1277 mateusz.vi 31
 
1306 mateusz.vi 32
  /* read and validate LANG and pathlist */
33
  if ((!lang) || (lang[0] == 0) || (!pathlist)) return(-1);
1277 mateusz.vi 34
 
35
  /* look into every path in NLSPATH */
1306 mateusz.vi 36
  while (*pathlist != 0) {
1277 mateusz.vi 37
 
38
    /* skip any leading ';' separators */
1306 mateusz.vi 39
    while (*pathlist == ';') pathlist++;
1277 mateusz.vi 40
 
1306 mateusz.vi 41
    if (*pathlist == 0) return(-3);
1277 mateusz.vi 42
 
43
    /* copy nlspath to buff and remember len */
1306 mateusz.vi 44
    for (i = 0; (pathlist[i] != 0) && (pathlist[i] != ';'); i++) buff[i] = pathlist[i];
45
    pathlist += i;
1277 mateusz.vi 46
 
47
    /* add a trailing backslash if there is none (non-empty paths empty) */
48
    if ((i > 0) && (buff[i - 1] != '\\')) buff[i++] = '\\';
49
 
1301 mateusz.vi 50
    /* append progname + ".LNG" to the path */
51
    for (ii = 0; progname[ii] != 0; ii++) buff[i++] = progname[ii];
52
    buff[i++] = '.';
53
    buff[i++] = 'L';
54
    buff[i++] = 'N';
55
    buff[i++] = 'G';
56
    buff[i] = 0;
1277 mateusz.vi 57
 
58
    if (svarlang_load(buff, lang) == 0) return(0);
59
  }
60
  /* failed to load anything */
61
  return(-4);
62
}