Subversion Repositories SvarDOS

Rev

Rev 1634 | Rev 1931 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1634 Rev 1892
Line 84... Line 84...
84
  *dirlist = newentry;
84
  *dirlist = newentry;
85
  return(0);
85
  return(0);
86
}
86
}
87
 
87
 
88
 
88
 
89
int loadconf(const char *dosdir, struct customdirs **dirlist) {
89
int loadconf(const char *dosdir, struct customdirs **dirlist, char *bootdrive) {
90
  FILE *fd;
90
  FILE *fd;
91
  char *value = NULL;
91
  char *value = NULL;
92
  char token[512];
92
  char token[512];
93
  int nline = 0;
93
  int nline = 0;
-
 
94
  const char *PKG_CFG = " (PKG.CFG)";
94
 
95
 
95
  snprintf(token, sizeof(token), "%s\\cfg\\pkg.cfg", dosdir);
96
  snprintf(token, sizeof(token), "%s\\cfg\\pkg.cfg", dosdir);
96
  fd = fopen(token, "r");
97
  fd = fopen(token, "r");
97
  if (fd == NULL) {
98
  if (fd == NULL) {
98
    kitten_printf(7, 1, token); /* "ERROR: Could not open config file (%s)!" */
99
    kitten_printf(7, 1, token); /* "ERROR: Could not open config file (%s)!" */
99
    puts("");
100
    puts("");
100
    return(-1);
101
    return(-1);
101
  }
102
  }
102
 
103
 
103
  *dirlist = NULL;
104
  *dirlist = NULL;
-
 
105
  *bootdrive = 'C'; /* default */
104
 
106
 
105
  /* read the config file line by line */
107
  /* read the config file line by line */
106
  while (freadtokval(fd, token, sizeof(token), &value, ' ') == 0) {
108
  while (freadtokval(fd, token, sizeof(token), &value, ' ') == 0) {
107
    nline++;
109
    nline++;
108
 
110
 
109
    /* skip comments and empty lines */
111
    /* skip comments and empty lines */
110
    if ((token[0] == '#') || (token[0] == 0)) continue;
112
    if ((token[0] == '#') || (token[0] == 0)) continue;
111
 
113
 
112
    if ((value == NULL) || (value[0] == 0)) {
114
    if ((value == NULL) || (value[0] == 0)) {
113
      kitten_printf(7, 4, nline); /* "Warning: token with empty value on line #%d" */
115
      kitten_printf(7, 4, nline); /* "Warning: token with empty value on line #%d" */
114
      puts("");
116
      puts(PKG_CFG);
115
      continue;
117
      continue;
116
    }
118
    }
117
 
119
 
118
    /* printf("token='%s' ; value = '%s'\n", token, value); */
120
    /* printf("token='%s' ; value = '%s'\n", token, value); */
119
    if (strcasecmp(token, "DIR") == 0) { /* custom directory entry */
121
    if (strcasecmp(token, "DIR") == 0) { /* custom directory entry */
Line 121... Line 123...
121
      int i;
123
      int i;
122
      /* find nearer space */
124
      /* find nearer space */
123
      for (i = 0; (value[i] != ' ') && (value[i] != 0); i++);
125
      for (i = 0; (value[i] != ' ') && (value[i] != 0); i++);
124
      if (value[i] == 0) {
126
      if (value[i] == 0) {
125
        kitten_printf(7, 11, nline); /* "Warning: Invalid 'DIR' directive found at line #%d" */
127
        kitten_printf(7, 11, nline); /* "Warning: Invalid 'DIR' directive found at line #%d" */
126
        puts("");
128
        puts(PKG_CFG);
127
        continue;
129
        continue;
128
      }
130
      }
129
      value[i] = 0;
131
      value[i] = 0;
130
      location = value + i + 1;
132
      location = value + i + 1;
131
 
133
 
Line 138... Line 140...
138
        puts("");
140
        puts("");
139
        freeconf(dirlist);
141
        freeconf(dirlist);
140
        fclose(fd);
142
        fclose(fd);
141
        return(-1);
143
        return(-1);
142
      }
144
      }
-
 
145
    } else if (strcasecmp(token, "BOOTDRIVE") == 0) { /* boot drive (used for kernel and command.com installation */
-
 
146
      *bootdrive = value[0];
-
 
147
      *bootdrive &= 0xDF; /* upcase it */
-
 
148
      if ((*bootdrive < 'A') || (*bootdrive > 'Z')) {
-
 
149
        kitten_printf(7, 5, nline); /* Warning: Invalid bootdrive at line #%d */
-
 
150
        puts(PKG_CFG);
-
 
151
        *bootdrive = 'C';
-
 
152
      }
143
    } else { /* unknown token */
153
    } else { /* unknown token */
144
      kitten_printf(7, 8, token, nline); /* "Warning: Unknown token '%s' at line #%d" */
154
      kitten_printf(7, 8, token, nline); /* "Warning: Unknown token '%s' at line #%d" */
145
      puts("");
155
      puts("");
146
    }
156
    }
147
  }
157
  }