Subversion Repositories SvarDOS

Rev

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

Rev 2051 Rev 2052
Line 39... Line 39...
39
/* Include files */
39
/* Include files */
40
#include <dos.h>
40
#include <dos.h>
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
#include <direct.h>
-
 
45
#include <ctype.h>
-
 
46
#include <limits.h>
-
 
47
 
44
 
48
#include "stack.h"
45
#include "stack.h"
49
 
46
 
50
/* DOS disk accesses */
47
/* DOS disk accesses */
51
#include "dosdisk.h"
48
#include "dosdisk.h"
Line 134... Line 131...
134
 
131
 
135
/* showInvalidPath [Set 6] */
132
/* showInvalidPath [Set 6] */
136
char invalidPath[MAXLINE] = "Invalid path - %s\n"; /* Must include %s for the invalid path given. */
133
char invalidPath[MAXLINE] = "Invalid path - %s\n"; /* Must include %s for the invalid path given. */
137
 
134
 
138
/* Misc Error messages [Set 7] */
135
/* Misc Error messages [Set 7] */
139
/* showBufferOverrun */
-
 
140
/* %u required to show what the buffer's current size is. */
-
 
141
char bufferToSmall[MAXLINE] = "Error: File path specified exceeds maximum buffer = %u bytes\n";
-
 
-
 
136
 
142
/* showOutOfMemory */
137
/* showOutOfMemory */
143
/* %s required to display what directory we were processing when ran out of memory. */
138
/* %s required to display what directory we were processing when ran out of memory. */
144
char outOfMemory[MAXLINE] = "Out of memory on subdirectory: %s\n";
139
char outOfMemory[MAXLINE] = "Out of memory on subdirectory: %s\n";
145
 
140
 
146
/* main [Set 1] */
141
/* main [Set 1] */
Line 196... Line 191...
196
"DONE:" \
191
"DONE:" \
197
modify [ax bx dx] \
192
modify [ax bx dx] \
198
value [al]
193
value [al]
199
 
194
 
200
 
195
 
-
 
196
static int truename(char *path, const char *origpath) {
-
 
197
  unsigned short origpath_seg = FP_SEG(origpath);
-
 
198
  unsigned short origpath_off = FP_OFF(origpath);
-
 
199
  unsigned short dstpath_seg = FP_SEG(path);
-
 
200
  unsigned short dstpath_off = FP_OFF(path);
-
 
201
  unsigned char cflag = 0;
-
 
202
 
-
 
203
  /* resolve path with truename */
-
 
204
  _asm {
-
 
205
    push ax
-
 
206
    push si
-
 
207
    push di
-
 
208
    push es
-
 
209
    push ds
-
 
210
 
-
 
211
    mov ah, 0x60          /* AH = 0x60 -> TRUENAME */
-
 
212
    mov di, dstpath_off   /* ES:DI -> dst buffer */
-
 
213
    mov es, dstpath_seg
-
 
214
    mov si, origpath_off  /* DS:SI -> src path */
-
 
215
    mov ds, origpath_seg
-
 
216
    int 0x21
-
 
217
    jnc DONE
-
 
218
    mov cflag, 1
-
 
219
    DONE:
-
 
220
 
-
 
221
    pop ds
-
 
222
    pop es
-
 
223
    pop di
-
 
224
    pop si
-
 
225
    pop ax
-
 
226
  }
-
 
227
 
-
 
228
  return(cflag);
-
 
229
}
-
 
230
 
-
 
231
 
201
/* sets rows & cols to size of actual console window
232
/* sets rows & cols to size of actual console window
202
 * force NOPAUSE if appears output redirected to a file or
233
 * force NOPAUSE if appears output redirected to a file or
203
 * piped to another program
234
 * piped to another program
204
 * Uses hard coded defaults and leaves pause flag unchanged
235
 * Uses hard coded defaults and leaves pause flag unchanged
205
 * if unable to obtain information.
236
 * if unable to obtain information.
Line 345... Line 376...
345
/* Displays error message for out of memory; Does NOT exit */
376
/* Displays error message for out of memory; Does NOT exit */
346
static void showOutOfMemory(char *path) {
377
static void showOutOfMemory(char *path) {
347
  pprintf(outOfMemory, path);
378
  pprintf(outOfMemory, path);
348
}
379
}
349
 
380
 
350
/* Displays buffer exceeded message and exits */
-
 
351
static void showBufferOverrun(WORD maxSize) {
-
 
352
  printf(bufferToSmall, maxSize);
-
 
353
  exit(1);
-
 
354
}
-
 
355
 
-
 
356
 
381
 
357
/**
382
/**
358
 * Takes a fullpath, splits into drive (C:, or \\server\share) and path
383
 * Takes a fullpath, splits into drive (C:, or \\server\share) and path
359
 * It assumes a colon as the 2nd character means drive specified,
384
 * It assumes a colon as the 2nd character means drive specified,
360
 * a double slash \\ (\\, //, \/, or /\) specifies network share.
385
 * a double slash \\ (\\, //, \/, or /\) specifies network share.
Line 438... Line 463...
438
    }
463
    }
439
  }
464
  }
440
}
465
}
441
 
466
 
442
 
467
 
443
/* Converts given path to full path */
-
 
444
static void getProperPath(char *fullpath) {
-
 
445
  char drive[MAXBUF];
-
 
446
  char path[MAXBUF];
-
 
447
 
-
 
448
  splitpath(fullpath, drive, path);
-
 
449
 
-
 
450
  /* if no drive specified use current */
-
 
451
  if (drive[0] == '\0')
-
 
452
  {
-
 
453
    sprintf(fullpath, "%c:%s", 'A'+ getdrive(), path);
-
 
454
  }
-
 
455
  else if (path[0] == '\0') /* else if drive but no path specified */
-
 
456
  {
-
 
457
    if ((drive[0] == '\\') || (drive[0] == '/'))
-
 
458
    {
-
 
459
      /* if no path specified and network share, use root   */
-
 
460
      sprintf(fullpath, "%s%s", drive, "\\");
-
 
461
    }
-
 
462
    else
-
 
463
    {
-
 
464
      /* if no path specified and drive letter, use current path */
-
 
465
      sprintf(fullpath, "%s%s", drive, ".");
-
 
466
    }
-
 
467
  }
-
 
468
  /* else leave alone, it has both a drive and path specified */
-
 
469
}
-
 
470
 
-
 
471
 
-
 
472
/* Parses the command line and sets global variables. */
468
/* Parses the command line and sets global variables. */
473
static void parseArguments(int argc, char *argv[]) {
469
static void parseArguments(int argc, char *argv[]) {
474
  int i;     /* temp loop variable */
470
  int i;     /* temp loop variable */
475
 
471
 
476
  /* if no drive specified on command line, use current */
472
  /* if no drive specified on command line, use current */
477
  sprintf(path, "%c:.", 'A'+ getdrive());
473
  if (truename(path, ".") != 0) showInvalidDrive();
478
 
474
 
479
  for (i = 1; i < argc; i++)
475
  for (i = 1; i < argc; i++)
480
  {
476
  {
481
    /* Check if user is giving an option or drive/path */
477
    /* Check if user is giving an option or drive/path */
482
    if ((argv[i][0] == optionchar1) || (argv[i][0] == optionchar2) )
478
    if ((argv[i][0] == optionchar1) || (argv[i][0] == optionchar2) )
Line 519... Line 515...
519
        else if ((argv[i][1] == OptPause[0]) || (argv[i][1] == OptPause[1]))
515
        else if ((argv[i][1] == OptPause[0]) || (argv[i][1] == OptPause[1]))
520
          pause = PAUSE;     /* wait for keypress after each page (pause) */
516
          pause = PAUSE;     /* wait for keypress after each page (pause) */
521
        else /* Invalid or unknown option */
517
        else /* Invalid or unknown option */
522
          showInvalidUsage(argv[i]);
518
          showInvalidUsage(argv[i]);
523
      }
519
      }
524
    }
-
 
525
    else /* should be a drive/path */
520
    } else { /* should be a drive/path */
526
    {
-
 
527
      char *dptr = path;
-
 
528
      char *cptr;
-
 
529
 
-
 
530
      if (strlen(argv[i]) > MAXBUF) showBufferOverrun(MAXBUF);
521
      if (truename(path, argv[i]) != 0) showInvalidDrive();
531
 
-
 
532
      /* copy path over, making all caps to look prettier, can be strcpy */
-
 
533
      for (cptr = argv[i]; *cptr != '\0'; cptr++, dptr++) {
-
 
534
        *dptr = toupper(*cptr);
-
 
535
      }
-
 
536
      *dptr = '\0';
-
 
537
 
-
 
538
      /* Converts given path to full path */
-
 
539
      getProperPath(path);
-
 
540
    }
522
    }
541
  }
523
  }
542
}
524
}
543
 
525
 
544
 
526