Subversion Repositories SvarDOS

Rev

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

Rev 592 Rev 593
Line 34... Line 34...
34
#define PDATE "2015-2022"
34
#define PDATE "2015-2022"
35
 
35
 
36
 
36
 
37
static void about(void) {
37
static void about(void) {
38
  puts("localcfg ver " PVER " - locales configuration for DOS\n"
38
  puts("localcfg ver " PVER " - locales configuration for DOS\n"
39
       "Copyright (C) Mateusz Viste " PDATE "\n"
39
       "Copyright (C) " PDATE " Mateusz Viste\n"
40
       "\n"
40
       "\n"
41
       "localcfg creates a custom COUNTRY.SYS-like file matching your preferences.\n"
41
       "localcfg creates or edits a custom COUNTRY.SYS-like file with your preferences.\n"
42
       "\n"
42
       "\n"
43
       "usage: localcfg myprefs.sys [options]\n"
43
       "usage: localcfg [COUNTRY.SYS] [options]\n"
44
       "\n"
44
       "\n"
45
       "options allow to configure country locales to your likening, as follows:\n"
45
       "options allow to configure country locales to your likening, as follows:\n"
46
       "  /country:XX indicates your country code is XX (1 for USA, 33 for France, etc)\n"
46
       "  /country:XX indicates your country code is XX (1 for USA, 33 for France, etc)\n"
47
       "  /cp:XXX     adapts country data for codepage XXX (example: '437')\n"
47
       "  /cp:XXX     adapts country data for codepage XXX (example: '437')\n"
48
       "  /decim:X    reconfigures the decimal symbol to be 'X'");
48
       "  /decim:X    reconfigures the decimal symbol to be 'X'");
Line 56... Line 56...
56
  puts("              0=currency precedes the value, 1=currency follows the value and\n"
56
  puts("              0=currency precedes the value, 1=currency follows the value and\n"
57
       "              2=currency replaces the decimal sign\n"
57
       "              2=currency replaces the decimal sign\n"
58
       "  /currspc:X  space between the currency and the value (0=no, 1=yes)\n"
58
       "  /currspc:X  space between the currency and the value (0=no, 1=yes)\n"
59
       "  /currprec:X currency's precision (number of decimal digits, 0..9)\n"
59
       "  /currprec:X currency's precision (number of decimal digits, 0..9)\n"
60
       "  /yesno:XY   sets the 'Yes/No' letter to XY (default: YN)\n"
60
       "  /yesno:XY   sets the 'Yes/No' letter to XY (default: YN)\n"
-
 
61
       "\n"
-
 
62
       "If COUNTRY.SYS location is not provided, then localcfg tries loading it\n"
-
 
63
       "from %DOSDIR%\\CFG\\COUNTRY.SYS\n"
61
      );
64
      );
62
}
65
}
63
 
66
 
64
 
67
 
65
static char *datestring(struct country *c) {
68
static char *datestring(struct country *c) {
Line 277... Line 280...
277
  }
280
  }
278
  return(res);
281
  return(res);
279
}
282
}
280
 
283
 
281
 
284
 
-
 
285
static void default_country_path(char *s) {
-
 
286
  char *dosdir = getenv("DOSDIR");
-
 
287
  size_t dosdirlen;
-
 
288
  s[0] = 0;
-
 
289
  if (dosdir == NULL) return;
-
 
290
  dosdirlen = strlen(dosdir);
-
 
291
  if (dosdirlen == 0) return;
-
 
292
  /* drop trailing backslash if present */
-
 
293
  if (dosdir[dosdirlen - 1] == '\\') dosdirlen--;
-
 
294
  /* copy dosdir to s and append the rest of the path */
-
 
295
  memcpy(s, dosdir, dosdirlen);
-
 
296
  strcpy(s + dosdirlen, "\\CFG\\COUNTRY.SYS");
-
 
297
}
-
 
298
 
-
 
299
 
282
int main(int argc, char **argv) {
300
int main(int argc, char **argv) {
283
  struct country cntdata;
301
  struct country cntdata;
284
  int changedflag;
302
  int changedflag;
285
  int x;
303
  int x;
286
  static char fname[130];
304
  static char fname[130];
287
 
305
 
-
 
306
  /* scan argv looking for the path to country.sys */
-
 
307
  for (x = 1; x < argc; x++) {
288
  if ((argc < 2) || (argv[1][0] == '/')) {
308
    if (argv[x][0] != '/') {
-
 
309
      if (fname[0] != 0) {
-
 
310
        puts("ERROR: file path can be provided only once");
-
 
311
        return(1);
-
 
312
      }
-
 
313
      /* */
-
 
314
      if (file_truename(fname, argv[x]) != 0) {
-
 
315
        puts("ERROR: bad file path");
-
 
316
        return(1);
-
 
317
      }
-
 
318
    } else if (strcmp(argv[x], "/?") == 0) { /* is it /? */
289
    about();
319
      about();
290
    return(1);
320
      return(1);
-
 
321
    }
291
  }
322
  }
292
 
323
 
293
  if (file_truename(fname, argv[1]) != 0) {
324
  /* if no file path provided, look into %DOSDIR%\CFG\COUNTRY.SYS */
294
    puts("ERROR: bad file path");
325
  if (fname[0] == 0) default_country_path(fname);
295
    return(1);
-
 
296
  }
-
 
297
 
326
 
298
  x = country_read(&cntdata, fname);
327
  x = country_read(&cntdata, fname);
299
  if (x != 0) {
328
  if (x != 0) {
300
    printf("ERROR: failed to read the preference file [%d]\n", x);
329
    printf("ERROR: failed to read the preference file [%d]\n", x);
301
    return(2);
330
    return(2);
302
  }
331
  }
303
 
332
 
304
  changedflag = argc - 2;
333
  changedflag = 0;
305
 
334
 
306
  /* process command line arguments */
335
  /* process command line arguments */
307
  while (--argc > 1) {
336
  for (x = 1; x < argc; x++) {
-
 
337
    if (argv[x][0] != '/') continue; /* skip country.sys filename (processed earlier) */
-
 
338
    changedflag++;
308
    if (processarg(argv[argc], &cntdata) != 0) {
339
    if (processarg(argv[x], &cntdata) != 0) {
309
      about();
340
      puts("ERROR: invalid parameter syntax");
310
      return(3);
341
      return(3);
311
    }
342
    }
312
  }
343
  }
313
 
344
 
314
  printf("Country intl code.....: %03d\n", cntdata.CTYINFO.id);
345
  printf("Country intl code.....: %03d\n", cntdata.CTYINFO.id);
Line 319... Line 350...
319
  printf("Time format...........: %s\n", timestring(&cntdata));
350
  printf("Time format...........: %s\n", timestring(&cntdata));
320
  printf("Yes/No letters........: %c/%c\n", cntdata.YESNO.yes[0], cntdata.YESNO.no[0]);
351
  printf("Yes/No letters........: %c/%c\n", cntdata.YESNO.yes[0], cntdata.YESNO.no[0]);
321
  printf("Currency example......: %s\n", currencystring(&cntdata));
352
  printf("Currency example......: %s\n", currencystring(&cntdata));
322
 
353
 
323
  printf("\n"
354
  printf("\n"
324
         "Please make sure your CONFIG.SYS contains a COUNTRY directive that points to\n"
355
         "Make sure that your CONFIG.SYS contains this directive:\n"
325
         "your custom preferences file:\n"
-
 
326
         "COUNTRY=%03d,%03d,%s\n\n", cntdata.CTYINFO.id, cntdata.CTYINFO.codepage, fname);
356
         "COUNTRY=%03d,%03d,%s\n\n", cntdata.CTYINFO.id, cntdata.CTYINFO.codepage, fname);
327
 
357
 
328
  /* if anything changed, write the new file */
358
  /* if anything changed, write the new file */
329
  if (changedflag != 0) country_write(fname, &cntdata);
359
  if (changedflag != 0) country_write(fname, &cntdata);
330
 
360