# 2.11BSD#431 - /usr/src/local/mtools/mtype.c

##### Functions

    dir_flush         X
    disk_flush        X
    main              X

##### Variables

    clus_size         X
    dir_entries       X
    dir_len           X
    dir_start         X
    fat_error         X
    fd                X
    mcwd              X

       1: /*
       2:  * Display contents of an MSDOS file
       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:     extern int optind;
      28:     extern char *optarg;
      29:     int i, ismatch, entry, c, oops, textmode, stripmode;
      30:     unsigned int fat;
      31:     long size;
      32:     char *filename, *newfile, *get_name(), *unix_name(), *pathname;
      33:     char *get_path(), drive, get_drive(), last_drive, *fix_mcwd();
      34:     void exit();
      35:     struct directory *dir, *dir_read();
      36:
      37:                     /* get command line options */
      38:     oops = 0;
      39:     stripmode = 0;
      40:     textmode = 0;
      41:     while ((c = getopt(argc, argv, "st")) != EOF) {
      42:         switch (c) {
      43:             case 's':
      44:                 stripmode = 1;
      45:                 break;
      46:             case 't':
      47:                 textmode = 1;
      48:                 break;
      49:             default:
      50:                 oops = 1;
      51:                 break;
      52:         }
      53:     }
      54:
      55:     if (oops || (argc - optind) < 1) {
      56:         fprintf(stderr, "Mtools version %s, dated %s\n", VERSION, DATE);
      57:         fprintf(stderr, "Usage: %s [-st] msdosfile [msdosfiles...]\n", argv[0]);
      58:         exit(1);
      59:     }
      60:     last_drive = 'x';
      61:     mcwd = fix_mcwd();
      62:
      63:     for (i = optind; i < argc; i++) {
      64:         drive = get_drive(argv[i]);
      65:         if (drive != last_drive) {
      66:             if (init(drive, 0)) {
      67:                 fprintf(stderr, "%s: Cannot initialize '%c:'\n", argv[0], drive);
      68:                 continue;
      69:             }
      70:             last_drive = drive;
      71:         }
      72:         filename = get_name(argv[i]);
      73:         pathname = get_path(argv[i]);
      74:         if (subdir(drive, pathname))
      75:             continue;
      76:
      77:         ismatch = 0;
      78:         for (entry = 0; entry < dir_entries; entry++) {
      79:             dir = dir_read(entry);
      80:                     /* if empty */
      81:             if (dir->name[0] == 0x0)
      82:                 break;
      83:                     /* if erased */
      84:             if (dir->name[0] == 0xe5)
      85:                 continue;
      86:                     /* if dir or volume label */
      87:             if ((dir->attr & 0x10) || (dir->attr & 0x08))
      88:                 continue;
      89:
      90:             newfile = unix_name(dir->name, dir->ext);
      91:
      92:                     /* see it if matches the pattern */
      93:             if (match(newfile, filename)) {
      94:                 fat = dir->start[1] * 0x100 + dir->start[0];
      95:                 size = dir->size[3] * 0x1000000L + dir->size[2] * 0x10000L + dir->size[1] * 0x100 + dir->size[0];
      96:                 if (file_read(stdout, fat, textmode, stripmode, size))
      97:                     break;
      98:                 ismatch = 1;
      99:             }
     100:         }
     101:         if (fat_error)
     102:             break;
     103:
     104:         if (!ismatch)
     105:             fprintf(stderr, "%s: File \"%s\" not found\n", argv[0], filename);
     106:     }
     107:     close(fd);
     108:     exit(0);
     109: }
     110:
     111: /*
     112:  * stubs for read-only programs
     113:  */
     114:
     115: void
     116: disk_flush()
     117: {
     118:     extern int disk_dirty;
     119:
     120:     disk_dirty = 0;
     121:     return;
     122: }
     123:
     124: void
     125: dir_flush()
     126: {
     127:     extern int dir_dirty;
     128:
     129:     dir_dirty = 0;
     130:     return;
     131: }

#### Defined functions

dir_flush defined in line 124; never used
disk_flush defined in line 115; used 27 times

- in /usr/src/local/mtools/buf_read.c line 28, 51
- in /usr/src/local/mtools/mattrib.c line 35, 148
- in /usr/src/local/mtools/mdel.c line 34, 63, 125, 139, 145
- in /usr/src/local/mtools/mlabel.c line 32, 126
- in /usr/src/local/mtools/mmd.c line 37, 70, 153, 200, 206
- in /usr/src/local/mtools/mrd.c line 34, 56, 119, 176, 182
- in /usr/src/local/mtools/mren.c line 32, 115
- in /usr/src/local/mtools/mwrite.c line 46, 231, 321, 327

main defined in line 23; never used

#### Defined variables

clus_size defined in line 19; never used
dir_entries defined in line 18; used 1 times

- in line 78

dir_len defined in line 17; never used
dir_start defined in line 16; never used
fat_error defined in line 21; used 1 times

- in line 101

fd defined in line 15; used 1 times

- in line 107

mcwd defined in line 20; used 1 times

- in line 61

Last modified: 1992-06-24 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 567 |