Subversion Repositories SvarDOS

Rev

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

Rev 2065 Rev 2066
Line 41... Line 41...
41
#include <stdlib.h>
41
#include <stdlib.h>
42
#include <stdio.h>
42
#include <stdio.h>
43
#include <string.h>
43
#include <string.h>
44
 
44
 
45
#include "stack.h"
45
#include "stack.h"
-
 
46
#include "svarlang/svarlang.h"
-
 
47
 
46
 
48
 
47
/* The default extended forms of the lines used. */
49
/* The default extended forms of the lines used. */
48
#define VERTBAR_STR  "\xB3   "                 /* |    */
50
#define VERTBAR_STR  "\xB3   "                 /* |    */
49
#define TBAR_HORZBAR_STR "\xC3\xC4\xC4\xC4"    /* +--- */
51
#define TBAR_HORZBAR_STR "\xC3\xC4\xC4\xC4"    /* +--- */
50
#define CBAR_HORZBAR_STR "\xC0\xC4\xC4\xC4"    /* \--- */
52
#define CBAR_HORZBAR_STR "\xC0\xC4\xC4\xC4"    /* \--- */
Line 99... Line 101...
99
/* The hard coded strings used by the following show functions.            */
101
/* The hard coded strings used by the following show functions.            */
100
 
102
 
101
/* common to many functions [Set 1] */
103
/* common to many functions [Set 1] */
102
char newLine[MAXLINE] = "\n";
104
char newLine[MAXLINE] = "\n";
103
 
105
 
104
/* showUsage [Set 2] - Each %c will be replaced with proper switch/option */
-
 
105
char treeDescription[MAXLINE] = "Graphically displays the directory structure of a drive or path.\n";
-
 
106
char treeUsage[MAXLINE] =       "TREE [drive:][path] [%c%c] [%c%c]\n";
-
 
107
char treeFOption[MAXLINE] =     "   %c%c   Display the names of the files in each directory.\n";
-
 
108
char treeAOption[MAXLINE] =     "   %c%c   Use ASCII instead of extended characters.\n";
-
 
109
 
-
 
110
/* showInvalidUsage [Set 3] */
-
 
111
char invalidOption[MAXLINE] = "Invalid switch - %s\n";  /* Must include the %s for option given. */
-
 
112
char useTreeHelp[MAXLINE] =   "Use TREE %c? for usage information.\n"; /* %c replaced with switch */
-
 
113
 
-
 
114
/* showVersionInfo [Set 4] */
-
 
115
/* also uses treeDescription */
-
 
116
char treeGoal[MAXLINE] =      "Written to work with FreeDOS\n";
-
 
117
char treePlatforms[MAXLINE] = "Win32(c) console and DOS with LFN support.\n";
-
 
118
char version[MAXLINE] =       "Version %s\n"; /* Must include the %s for version string. */
-
 
119
char writtenBy[MAXLINE] =     "Written by: Kenneth J. Davis\n";
-
 
120
char writtenDate[MAXLINE] =   "Date:       2000, 2001, 2004\n";
-
 
121
char contact[MAXLINE] =       "Contact:    jeremyd@computer.org\n";
-
 
122
char copyright[MAXLINE] =     "Copyright (c): Public Domain [United States Definition]\n";
-
 
123
 
-
 
124
/* showInvalidDrive [Set 5] */
-
 
125
char invalidDrive[MAXLINE] = "Invalid drive specification\n";
-
 
126
 
-
 
127
/* showInvalidPath [Set 6] */
-
 
128
char invalidPath[MAXLINE] = "Invalid path - %s\n"; /* Must include %s for the invalid path given. */
-
 
129
 
-
 
130
/* Misc Error messages [Set 7] */
-
 
131
 
-
 
132
/* showOutOfMemory */
-
 
133
/* %s required to display what directory we were processing when ran out of memory. */
-
 
134
char outOfMemory[MAXLINE] = "Out of memory on subdirectory: %s\n";
-
 
135
 
-
 
136
/* main [Set 1] */
-
 
137
char pathListingNoLabel[MAXLINE] = "Directory PATH listing\n";
-
 
138
char pathListingWithLabel[MAXLINE] = "Directory PATH listing for Volume %s\n"; /* %s for label */
-
 
139
char serialNumber[MAXLINE] = "Volume serial number is %s\n"; /* Must include %s for serial #   */
-
 
140
char noSubDirs[MAXLINE] = "No subdirectories exist\n\n";
-
 
141
char pauseMsg[MAXLINE]  = " --- Press any key to continue ---\n";
-
 
142
 
-
 
143
 
-
 
144
 
106
 
145
/* Procedures */
107
/* Procedures */
146
 
108
 
147
 
109
 
148
/* returns the current drive (A=0, B=1, etc) */
110
/* returns the current drive (A=0, B=1, etc) */
Line 309... Line 271...
309
        printf("%s", l);
271
        printf("%s", l);
310
        l[cols-lineCol] = c;
272
        l[cols-lineCol] = c;
311
        l += cols-lineCol;
273
        l += cols-lineCol;
312
 
274
 
313
        lineCnt--;  lineCol = 0;
275
        lineCnt--;  lineCol = 0;
314
        if (!lineCnt) { lineCnt= rows;  fflush(NULL);  fprintf(stderr, "%s", pauseMsg);  waitkey(); }
276
        if (!lineCnt) { lineCnt= rows;  fflush(NULL);  fprintf(stderr, "%s", svarlang_strid(0x0106));  waitkey(); }
315
      }
277
      }
316
 
278
 
317
      printf("%s", l); /* print out this line */
279
      printf("%s", l); /* print out this line */
318
      *t = c;          /* restore value */
280
      *t = c;          /* restore value */
319
      l = t;           /* mark beginning of next line */
281
      l = t;           /* mark beginning of next line */
320
 
282
 
321
      lineCnt--;  lineCol = 0;
283
      lineCnt--;  lineCol = 0;
322
      if (!lineCnt) { lineCnt= rows;  fflush(NULL);  fprintf(stderr, "%s", pauseMsg);  waitkey(); }
284
      if (!lineCnt) { lineCnt= rows;  fflush(NULL);  fprintf(stderr, "%s", svarlang_strid(0x0106));  waitkey(); }
323
    }
285
    }
324
    printf("%s", l);   /* print rest of string that lacks newline */
286
    printf("%s", l);   /* print rest of string that lacks newline */
325
    lineCol = strlen(l);
287
    lineCol = strlen(l);
326
  }
288
  }
327
  else  /* NOPAUSE */
289
  else  /* NOPAUSE */
Line 331... Line 293...
331
}
293
}
332
 
294
 
333
 
295
 
334
/* Displays to user valid options then exits program indicating no error */
296
/* Displays to user valid options then exits program indicating no error */
335
static void showUsage(void) {
297
static void showUsage(void) {
336
  printf("%s%s%s%s", treeDescription, newLine, treeUsage, newLine);
298
  printf(svarlang_strid(0x0201));
337
  printf("%s%s%s", treeFOption, treeAOption, newLine);
299
  printf(svarlang_strid(0x0202));
-
 
300
  puts("");
-
 
301
  printf(svarlang_strid(0x0203));
-
 
302
  printf(svarlang_strid(0x0204));
338
  exit(1);
303
  exit(1);
339
}
304
}
340
 
305
 
341
 
306
 
342
/* Displays error message then exits indicating error */
307
/* Displays error message then exits indicating error */
343
static void showInvalidUsage(char * badOption) {
308
static void showInvalidUsage(char * badOption) {
344
  printf(invalidOption, badOption);
309
  printf(svarlang_strid(0x0301), badOption); /* invalid switch - ... */
345
  printf("%s%s", useTreeHelp, newLine);
310
  printf("%s%s", svarlang_strid(0x0302), newLine); /* use TREE /? for usage info */
346
  exit(1);
311
  exit(1);
347
}
312
}
348
 
313
 
349
 
314
 
350
/* Displays author, copyright, etc info, then exits indicating no error. */
315
/* Displays author, copyright, etc info, then exits indicating no error. */
351
static void showVersionInfo(void) {
316
static void showVersionInfo(void) {
-
 
317
  printf(svarlang_strid(0x0201));
352
  printf("%s%s%s%s%s", treeDescription, newLine, treeGoal, treePlatforms, newLine);
318
  printf(svarlang_strid(0x0202));
353
  printf(version, VERSION);
319
  printf(svarlang_strid(0x0403), VERSION);
354
  printf("%s%s%s%s%s", writtenBy, writtenDate, contact, newLine, newLine);
320
  printf(svarlang_strid(0x0404));
355
  printf("%s%s", copyright, newLine);
321
  printf(svarlang_strid(0x0407));
356
  exit(1);
322
  exit(1);
357
}
323
}
358
 
324
 
359
 
325
 
360
/* Displays error messge for invalid drives and exits */
326
/* Displays error messge for invalid drives and exits */
361
static void showInvalidDrive(void) {
327
static void showInvalidDrive(void) {
362
  printf(invalidDrive);
328
  printf(svarlang_strid(0x0501)); /* invalid drive spec */
363
  exit(1);
329
  exit(1);
364
}
330
}
365
 
331
 
366
 
332
 
367
/**
333
/**
Line 372... Line 338...
372
static char *fixPathForDisplay(char *path);
338
static char *fixPathForDisplay(char *path);
373
 
339
 
374
/* Displays error message for invalid path; Does NOT exit */
340
/* Displays error message for invalid path; Does NOT exit */
375
static void showInvalidPath(const char *badpath) {
341
static void showInvalidPath(const char *badpath) {
376
  pprintf("%s\n", badpath);
342
  pprintf("%s\n", badpath);
377
  pprintf(invalidPath, badpath);
343
  pprintf(svarlang_strid(0x0601), badpath); /* invalid path - ... */
378
}
344
}
379
 
345
 
380
/* Displays error message for out of memory; Does NOT exit */
346
/* Displays error message for out of memory; Does NOT exit */
381
static void showOutOfMemory(const char *path) {
347
static void showOutOfMemory(const char *path) {
382
  pprintf(outOfMemory, path);
348
  pprintf(svarlang_strid(0x0702), path); /* out of memory on subdir ... */
383
}
349
}
384
 
350
 
385
 
351
 
386
/* Parses the command line and sets global variables. */
352
/* Parses the command line and sets global variables. */
387
static void parseArguments(int argc, char **argv) {
353
static void parseArguments(int argc, char **argv) {
Line 434... Line 400...
434
        showVersionInfo();       /* show version info and exit          */
400
        showVersionInfo();       /* show version info and exit          */
435
        break;
401
        break;
436
      case 'P': /* wait for keypress after each page (pause) */
402
      case 'P': /* wait for keypress after each page (pause) */
437
        pause = PAUSE;
403
        pause = PAUSE;
438
        break;
404
        break;
439
      case '?':
405
      case '?' & 0xDF:
440
        showUsage();             /* show usage info and exit            */
406
        showUsage();             /* show usage info and exit            */
441
        break;
407
        break;
442
      default: /* Invalid or unknown option */
408
      default: /* Invalid or unknown option */
443
        showInvalidUsage(argv[i]);
409
        showInvalidUsage(argv[i]);
444
    }
410
    }
Line 962... Line 928...
962
 
928
 
963
  return subdirsInInitialpath;
929
  return subdirsInInitialpath;
964
}
930
}
965
 
931
 
966
 
932
 
967
static void FixOptionText(void) {
-
 
968
  char buffer[MAXLINE];  /* sprintf can have problems with src==dest */
-
 
969
 
-
 
970
  /* Handle %c for options within messages using Set 8 */
-
 
971
  strcpy(buffer, treeUsage);
-
 
972
  sprintf(treeUsage, buffer, '/', 'f', '/', 'a');
-
 
973
  strcpy(buffer, treeFOption);
-
 
974
  sprintf(treeFOption, buffer, '/', 'f');
-
 
975
  strcpy(buffer, treeAOption);
-
 
976
  sprintf(treeAOption, buffer, '/', 'a');
-
 
977
  strcpy(buffer, useTreeHelp);
-
 
978
  sprintf(useTreeHelp, buffer, '/');
-
 
979
}
-
 
980
 
-
 
981
 
-
 
982
/* Loads all messages from the message catalog. */
-
 
983
static void loadAllMessages(void) {
-
 
984
  /* Changes %c in certain lines with proper option characters. */
-
 
985
  FixOptionText();
-
 
986
}
-
 
987
 
-
 
988
 
-
 
989
int main(int argc, char **argv) {
933
int main(int argc, char **argv) {
990
  char serial[SERIALLEN]; /* volume serial #  0000:0000 */
934
  char serial[SERIALLEN]; /* volume serial #  0000:0000 */
991
  char volume[VOLLEN];    /* volume name (label), possibly none */
935
  char volume[VOLLEN];    /* volume name (label), possibly none */
992
 
936
 
993
  /* Load all text from message catalog (or uses hard coded text) */
937
  /* load translation strings */
994
  loadAllMessages();
938
  svarlang_autoload_exepath(argv[0], getenv("LANG"));
995
 
939
 
996
  /* Parse any command line arguments, obtain path */
940
  /* Parse any command line arguments, obtain path */
997
  parseArguments(argc, argv);
941
  parseArguments(argc, argv);
998
 
942
 
999
  /* Initialize screen size, may reset pause to NOPAUSE if redirected */
943
  /* Initialize screen size, may reset pause to NOPAUSE if redirected */
1000
  getConsoleSize();
944
  getConsoleSize();
1001
 
945
 
1002
  /* Get Volume & Serial Number */
946
  /* Get Volume & Serial Number */
1003
  GetVolumeAndSerial(volume, serial, path);
947
  GetVolumeAndSerial(volume, serial, path);
1004
  if (strlen(volume) == 0)
948
  if (volume[0] == 0) {
1005
    pprintf(pathListingNoLabel);
949
    pprintf(svarlang_strid(0x0102)); /* Dir PATH listing */
1006
  else
950
  } else {
1007
    pprintf(pathListingWithLabel, volume);
951
    pprintf(svarlang_strid(0x0103), volume); /* Dir PATH listing for volume ... */
-
 
952
  }
1008
  if (serial[0] != '\0')  /* Don't print anything if no serial# found */
953
  if (serial[0] != '\0') {  /* Don't print anything if no serial# found */
1009
    pprintf(serialNumber, serial);
954
    pprintf(svarlang_strid(0x0104), serial); /* vol serial num is ... */
-
 
955
  }
1010
 
956
 
1011
  /* now traverse & print tree, returns nonzero if has subdirectories */
957
  /* now traverse & print tree, returns nonzero if has subdirectories */
1012
  if (traverseTree(path) == 0)
958
  if (traverseTree(path) == 0) {
1013
    pprintf(noSubDirs);
959
    pprintf(svarlang_strid(0x0105)); /* no subdirs exist */
1014
  else if (dspSumDirs) /* show count of directories processed */
960
  } else if (dspSumDirs) { /* show count of directories processed */
1015
    pprintf("\n    %lu total directories\n", totalSubDirCnt+1);
961
    pprintf("\n    %lu total directories\n", totalSubDirCnt+1);
-
 
962
  }
1016
 
963
 
1017
  return 0;
964
  return(0);
1018
}
965
}