1: /*
   2:  * Change MSDOS directories
   3:  *
   4:  * Emmet P. Gray			US Army, HQ III Corps & Fort Hood
   5:  * ...!uunet!uiucuxc!fthood!egray	Attn: AFZF-DE-ENV
   6:  * fthood!egray@uxc.cso.uiuc.edu	Directorate of Engineering & Housing
   7:  * 					Environmental Management Office
   8:  * 					Fort Hood, TX 76544-5057
   9:  */
  10: 
  11: #include <stdio.h>
  12: #include "msdos.h"
  13: #include "patchlevel.h"
  14: 
  15: int fd = -1;                /* the file descriptor for the device */
  16: int dir_start;              /* starting sector for directory */
  17: int dir_len;                /* length of directory (in sectors) */
  18: int dir_entries;            /* number of directory entries */
  19: int clus_size;              /* cluster size (in sectors) */
  20: char *mcwd;             /* the Current Working Directory */
  21: int fat_error;              /* FAT error detected? */
  22: 
  23: main(argc, argv)
  24: int argc;
  25: char *argv[];
  26: {
  27:     FILE *fp;
  28:     char *fix_mcwd(), *strcpy(), newpath[MAX_PATH], *get_name();
  29:     char *get_path(), *pathname, *filename, drive, *strcat();
  30:     char get_drive(), *mcwd_path, *getenv(), *expand();
  31:     void exit();
  32: 
  33:     if (argc > 2) {
  34:         fprintf(stderr, "Mtools version %s, dated %s\n", VERSION, DATE);
  35:         fprintf(stderr, "Usage: %s: msdosdirectory\n", argv[0]);
  36:         exit(1);
  37:     }
  38:                     /* only report the mcwd */
  39:     mcwd = fix_mcwd();
  40:     if (argc == 1) {
  41:         printf("%s\n", mcwd);
  42:         exit(0);
  43:     }
  44: 
  45:     drive = get_drive(argv[1]);
  46:     filename = get_name(argv[1]);
  47:     pathname = get_path(argv[1]);
  48: 
  49:     if (init(drive, 0)) {
  50:         fprintf(stderr, "%s: Cannot initialize '%c:'\n", argv[0], drive);
  51:         exit(1);
  52:     }
  53: 
  54:     /*
  55: 	 * Move to "first guess" subdirectory, so that is_dir() can
  56: 	 * search to see if filename is also a directory.
  57: 	 */
  58:     if (subdir(drive, pathname)) {
  59:         fprintf(stderr, "%s: Directory not found\n", argv[0]);
  60:         exit(1);
  61:     }
  62:                     /* is filename really a subdirectory? */
  63:     strcpy(newpath, pathname);
  64:     if (is_dir(filename)) {
  65:         if (newpath[strlen(newpath) -1] != '/')
  66:             strcat(newpath, "/");
  67:         strcat(newpath, filename);
  68: 
  69:                     /* move to real subdirectory */
  70:         if (subdir(drive, newpath)) {
  71:             fprintf(stderr, "%s: Directory not found\n", argv[0]);
  72:             exit(1);
  73:         }
  74:     }
  75:     else {
  76:         if (*filename != '\0') {
  77:             fprintf(stderr, "%s: Directory not found\n", argv[0]);
  78:             exit(1);
  79:         }
  80:     }
  81:                     /* it checked out ok, so save it */
  82:     mcwd_path = getenv("MCWD");
  83:     if (mcwd_path == NULL || *mcwd_path == '\0')
  84:         mcwd_path = "$HOME/.mcwd";
  85: 
  86:     if (!(fp = fopen(expand(mcwd_path), "w"))) {
  87:         fprintf(stderr, "%s: Can't open '%s' for write\n", argv[0], expand(mcwd_path));
  88:         exit(1);
  89:     }
  90:     fprintf(fp, "%c:%s\n", drive, newpath);
  91:     fclose(fp);
  92:     exit(0);
  93: }
  94: 
  95: /*
  96:  * stubs for read-only programs
  97:  */
  98: 
  99: void
 100: disk_flush()
 101: {
 102:     extern int disk_dirty;
 103: 
 104:     disk_dirty = 0;
 105:     return;
 106: }
 107: 
 108: void
 109: dir_flush()
 110: {
 111:     extern int dir_dirty;
 112: 
 113:     dir_dirty = 0;
 114:     return;
 115: }

Defined functions

dir_flush defined in line 108; never used
disk_flush defined in line 99; never used
main defined in line 23; never used

Defined variables

clus_size defined in line 19; never used
dir_entries defined in line 18; never used
dir_len defined in line 17; never used
dir_start defined in line 16; never used
fat_error defined in line 21; never used
fd defined in line 15; never used
mcwd defined in line 20; used 2 times
Last modified: 1992-06-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2647
Valid CSS Valid XHTML 1.0 Strict