Subversion Repositories SvarDOS

Rev

Rev 1963 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1963 Rev 1965
Line 6... Line 6...
6
#include <stdio.h>  /* printf(), fclose(), fopen()... */
6
#include <stdio.h>  /* printf(), fclose(), fopen()... */
7
#include <string.h> /* strcasecmp() */
7
#include <string.h> /* strcasecmp() */
8
#include <stdlib.h> /* malloc(), free() */
8
#include <stdlib.h> /* malloc(), free() */
9
 
9
 
10
#include "helpers.h" /* slash2backslash(), removeDoubleBackslashes()... */
10
#include "helpers.h" /* slash2backslash(), removeDoubleBackslashes()... */
11
#include "kprintf.h"
-
 
12
#include "svarlang.lib\svarlang.h"
11
#include "svarlang.lib\svarlang.h"
13
 
12
 
14
#include "loadconf.h"
13
#include "loadconf.h"
15
 
14
 
16
 
15
 
Line 28... Line 27...
28
static int checkfordoubledirlist(const struct customdirs *dirlist) {
27
static int checkfordoubledirlist(const struct customdirs *dirlist) {
29
  struct customdirs *curpos;
28
  struct customdirs *curpos;
30
  for (; dirlist != NULL; dirlist = dirlist->next) {
29
  for (; dirlist != NULL; dirlist = dirlist->next) {
31
    for (curpos = dirlist->next; curpos != NULL; curpos = curpos->next) {
30
    for (curpos = dirlist->next; curpos != NULL; curpos = curpos->next) {
32
      if (strcasecmp(curpos->name, dirlist->name) == 0) {
31
      if (strcasecmp(curpos->name, dirlist->name) == 0) {
-
 
32
        char msg[256];
33
        kitten_printf(7, 0, curpos->name); /* "ERROR: custom dir '%s' is listed twice!" */
33
        sprintf(msg, svarlang_str(7, 0), curpos->name); /* "ERROR: custom dir '%s' is listed twice!" */
34
        outputnl("");
34
        output(msg);
-
 
35
        outputnl(" (PKG.CFG)");
35
        return(-1);
36
        return(-1);
36
      }
37
      }
37
    }
38
    }
38
  }
39
  }
39
  return(0);
40
  return(0);
Line 42... Line 43...
42
 
43
 
43
/* validates dirlist entries: check that they are absolute paths and are not using restricted names */
44
/* validates dirlist entries: check that they are absolute paths and are not using restricted names */
44
static int validatedirlist(const struct customdirs *dirlist) {
45
static int validatedirlist(const struct customdirs *dirlist) {
45
  for (; dirlist != NULL; dirlist = dirlist->next) {
46
  for (; dirlist != NULL; dirlist = dirlist->next) {
46
    /* the location must be at least 3 characters long to be a valid absolute path (like 'c:\')*/
47
    /* the location must be at least 3 characters long to be a valid absolute path (like 'c:\')*/
47
    if (strlen(dirlist->location) < 3) {
48
    if (strlen(dirlist->location) < 3) goto INVALID_CUSTOM_DIR;
48
      kitten_printf(7, 15, dirlist->name); /* "ERROR: custom dir '%s' is not a valid absolute path!" */
-
 
49
      outputnl("");
-
 
50
      return(-1);
-
 
51
    }
49
 
52
    /* is it a valid absolute path? should start with [a..Z]:\ */
50
    /* is it a valid absolute path? should start with [a..Z]:\ */
53
    if ((dirlist->location[1] != ':') ||
51
    if ((dirlist->location[1] != ':') ||
54
       ((dirlist->location[2] != '/') && (dirlist->location[2] != '\\')) ||
52
       ((dirlist->location[2] != '/') && (dirlist->location[2] != '\\')) ||
55
       (((dirlist->location[0] < 'a') || (dirlist->location[0] > 'z')) && ((dirlist->location[0] < 'A') || (dirlist->location[0] > 'Z')))) {
53
       (((dirlist->location[0] < 'a') || (dirlist->location[0] > 'z')) && ((dirlist->location[0] < 'A') || (dirlist->location[0] > 'Z')))) {
56
      kitten_printf(7, 15, dirlist->name); /* "ERROR: custom dir '%s' is not a valid absolute path!" */
-
 
57
      outputnl("");
54
      goto INVALID_CUSTOM_DIR;
58
      return(-1);
-
 
59
    }
55
    }
-
 
56
 
60
    /* check for forbidden names */
57
    /* check for forbidden names */
61
    if ((strcasecmp(dirlist->name, "appinfo") == 0) ||
58
    if ((strcasecmp(dirlist->name, "appinfo") == 0) ||
62
        (strcasecmp(dirlist->name, "doc") == 0) ||
59
        (strcasecmp(dirlist->name, "doc") == 0) ||
63
        (strcasecmp(dirlist->name, "help") == 0) ||
60
        (strcasecmp(dirlist->name, "help") == 0) ||
64
        (strcasecmp(dirlist->name, "nls") == 0) ||
61
        (strcasecmp(dirlist->name, "nls") == 0) ||
65
        (strcasecmp(dirlist->name, "packages") == 0)) {
62
        (strcasecmp(dirlist->name, "packages") == 0)) {
66
      kitten_printf(7, 16, dirlist->name); /* "ERROR: custom dir '%s' is a reserved name!" */
-
 
67
      outputnl("");
63
      goto INVALID_CUSTOM_DIR;
68
      return(-1);
-
 
69
    }
64
    }
70
  }
65
  }
71
  return(0);
66
  return(0);
-
 
67
 
-
 
68
  INVALID_CUSTOM_DIR:
-
 
69
  output(svarlang_str(7, 15)); /* "ERROR: invalid custom dir:" */
-
 
70
  output(" ");
-
 
71
  output(dirlist->name);
-
 
72
  outputnl(" (PKG.CFG)");
-
 
73
  return(-1);
72
}
74
}
73
 
75
 
74
 
76
 
75
/* add (and allocates) a new custom dir entry to dirlist. Returns 0 on success,
77
/* add (and allocates) a new custom dir entry to dirlist. Returns 0 on success,
76
   or non-zero on failure (failures happen on out of memory events). */
78
   or non-zero on failure (failures happen on out of memory events). */
Line 91... Line 93...
91
  FILE *fd;
93
  FILE *fd;
92
  char *value = NULL;
94
  char *value = NULL;
93
  char token[512];
95
  char token[512];
94
  int nline = 0;
96
  int nline = 0;
95
  const char *PKG_CFG = " (PKG.CFG)";
97
  const char *PKG_CFG = " (PKG.CFG)";
-
 
98
  char msg[256];
96
 
99
 
97
  /* load config file from %DOSDIR%\PKG.CFG */
100
  /* load config file from %DOSDIR%\PKG.CFG */
98
  snprintf(token, sizeof(token), "%s\\pkg.cfg", dosdir);
101
  snprintf(token, sizeof(token), "%s\\pkg.cfg", dosdir);
99
  fd = fopen(token, "r");
102
  fd = fopen(token, "r");
100
  /* if not found then try the legacy location at %DOSDIR%\CFG\PKG.CFG */
103
  /* if not found then try the legacy location at %DOSDIR%\CFG\PKG.CFG */
101
  if (fd == NULL) {
104
  if (fd == NULL) {
102
    snprintf(token, sizeof(token), "%s\\cfg\\pkg.cfg", dosdir);
105
    snprintf(token, sizeof(token), "%s\\cfg\\pkg.cfg", dosdir);
103
    fd = fopen(token, "r");
106
    fd = fopen(token, "r");
104
    if (fd == NULL) {
107
    if (fd == NULL) {
105
      kitten_printf(7, 1, "%DOSDIR%\\PKG.CFG"); /* "ERROR: Could not open config file (%s)!" */
108
      sprintf(msg, svarlang_str(7, 1), "%DOSDIR%\\PKG.CFG"); /* "ERROR: Could not open config file (%s)!" */
-
 
109
      outputnl(msg);
106
    } else {
110
    } else {
107
      kitten_printf(7, 17, token);  /* "ERROR: PKG.CFG found at %s */
111
      sprintf(msg, svarlang_str(7, 17), token);  /* "ERROR: PKG.CFG found at %s */
108
      outputnl("");
112
      outputnl(msg);
109
      outputnl(svarlang_str(7, 18));    /* Please move it to %DOSDIR%\PKG.CFG */
113
      outputnl(svarlang_str(7, 18));    /* Please move it to %DOSDIR%\PKG.CFG */
110
    }
114
    }
111
    outputnl("");
-
 
112
    return(-1);
115
    return(-1);
113
  }
116
  }
114
 
117
 
115
  *dirlist = NULL;
118
  *dirlist = NULL;
116
  *bootdrive = 'C'; /* default */
119
  *bootdrive = 'C'; /* default */
Line 121... Line 124...
121
 
124
 
122
    /* skip comments and empty lines */
125
    /* skip comments and empty lines */
123
    if ((token[0] == '#') || (token[0] == 0)) continue;
126
    if ((token[0] == '#') || (token[0] == 0)) continue;
124
 
127
 
125
    if ((value == NULL) || (value[0] == 0)) {
128
    if ((value == NULL) || (value[0] == 0)) {
126
      kitten_printf(7, 4, nline); /* "Warning: token with empty value on line #%d" */
129
      sprintf(msg, svarlang_str(7, 4), nline); /* "Warning: token with empty value on line #%d" */
-
 
130
      output(msg);
127
      outputnl(PKG_CFG);
131
      outputnl(PKG_CFG);
128
      continue;
132
      continue;
129
    }
133
    }
130
 
134
 
131
    /* printf("token='%s' ; value = '%s'\n", token, value); */
135
    /* printf("token='%s' ; value = '%s'\n", token, value); */
Line 133... Line 137...
133
      char *location = NULL;
137
      char *location = NULL;
134
      int i;
138
      int i;
135
      /* find nearer space */
139
      /* find nearer space */
136
      for (i = 0; (value[i] != ' ') && (value[i] != 0); i++);
140
      for (i = 0; (value[i] != ' ') && (value[i] != 0); i++);
137
      if (value[i] == 0) {
141
      if (value[i] == 0) {
138
        kitten_printf(7, 11, nline); /* "Warning: Invalid 'DIR' directive found at line #%d" */
142
        sprintf(msg, svarlang_str(7, 11), nline); /* "Warning: Invalid 'DIR' directive found at line #%d" */
-
 
143
        output(msg);
139
        outputnl(PKG_CFG);
144
        outputnl(PKG_CFG);
140
        continue;
145
        continue;
141
      }
146
      }
142
      value[i] = 0;
147
      value[i] = 0;
143
      location = value + i + 1;
148
      location = value + i + 1;
Line 145... Line 150...
145
      /* add the entry to the list */
150
      /* add the entry to the list */
146
      slash2backslash(location);
151
      slash2backslash(location);
147
      removeDoubleBackslashes(location);
152
      removeDoubleBackslashes(location);
148
      if (location[strlen(location) - 1] != '\\') strcat(location, "\\"); /* make sure to end dirs with a backslash */
153
      if (location[strlen(location) - 1] != '\\') strcat(location, "\\"); /* make sure to end dirs with a backslash */
149
      if (addnewdir(dirlist, value, location) != 0) {
154
      if (addnewdir(dirlist, value, location) != 0) {
150
        kitten_printf(2, 14, "addnewdir"); /* "Out of memory! (%s)" */
155
        outputnl(svarlang_str(2, 14)); /* "Out of memory!" */
151
        outputnl("");
-
 
152
        freeconf(dirlist);
156
        freeconf(dirlist);
153
        fclose(fd);
157
        fclose(fd);
154
        return(-1);
158
        return(-1);
155
      }
159
      }
156
    } else if (strcasecmp(token, "BOOTDRIVE") == 0) { /* boot drive (used for kernel and command.com installation */
160
    } else if (strcasecmp(token, "BOOTDRIVE") == 0) { /* boot drive (used for kernel and command.com installation */
157
      *bootdrive = value[0];
161
      *bootdrive = value[0];
158
      *bootdrive &= 0xDF; /* upcase it */
162
      *bootdrive &= 0xDF; /* upcase it */
159
      if ((*bootdrive < 'A') || (*bootdrive > 'Z')) {
163
      if ((*bootdrive < 'A') || (*bootdrive > 'Z')) {
160
        kitten_printf(7, 5, nline); /* Warning: Invalid bootdrive at line #%d */
164
        sprintf(msg, svarlang_str(7, 5), nline); /* Warning: Invalid bootdrive at line #%d */
-
 
165
        output(msg);
161
        outputnl(PKG_CFG);
166
        outputnl(PKG_CFG);
162
        *bootdrive = 'C';
167
        *bootdrive = 'C';
163
      }
168
      }
164
    } else { /* unknown token */
169
    } else { /* unknown token */
165
      kitten_printf(7, 8, token, nline); /* "Warning: Unknown token '%s' at line #%d" */
170
      sprintf(msg, svarlang_str(7, 8), token, nline); /* "Warning: Unknown token '%s' at line #%d" */
166
      outputnl("");
171
      output(msg);
-
 
172
      outputnl(PKG_CFG);
167
    }
173
    }
168
  }
174
  }
169
  fclose(fd);
175
  fclose(fd);
170
 
176
 
171
  /* perform some validations */
177
  /* perform some validations */