home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 110_01 / getc.c < prev    next >
Text File  |  1984-03-03  |  5KB  |  133 lines

  1. /*    from STDLIB1.C
  2.     The "getc" function modified to return ERROR following the
  3.     last real sector of the file, even when the file is not a
  4.     multiple of NSECTS in length.
  5.  
  6.     The only change is to the 2nd to last line, from
  7.         ... NSECTS * SECSIZ - 1 ...
  8.     to
  9.         ... nsecs * SECSIZ - 1 ...
  10.  
  11. */
  12.  
  13. int getc(iobuf)
  14. struct _buf *iobuf;
  15. {
  16.     int nsecs;
  17.     if (iobuf == 0) return getchar();
  18.     if (iobuf == 3) return bdos(3);
  19.     if (iobuf -> _nleft--) return *iobuf -> _nextp++;
  20.     if ((nsecs = read(iobuf -> _fd, iobuf -> _buff, NSECTS)) <= 0)
  21.                 return ERROR;
  22.     iobuf -> _nleft = (nsecs * SECSIZ - 1);
  23.     iobuf -> _nextp = iobuf -> _buff;
  24.     return *iobuf->_nextp++;
  25. }
  26.  
  27.  
  28.  
  29. ddr,sad;
  30. char fnbuf[30], *fname;        /* filename buffer & ptr */
  31. char onbuf[30], *oname;        /* output filename buf & ptr */
  32. char ibuf[BUFSIZ];    /* buffered input buffer */
  33. char obuf[BUFSIZ];    /* buffered output */
  34. char hextab[16];
  35. char kybdbuf[20];
  36. char su/*
  37.  
  38. This program rewritten Sept 9, 1981 by Robert Ward.  All but some low
  39. level functions and the command line argument handling have been 
  40. redone.  The object was to create code that would work with double
  41. density and other controllers. 
  42.  
  43. To compile correctly for your system. You must know the number of 
  44. sectors per track (SPT), the number of tracks per disk (TPD),
  45. the maximum blocks on a drive (MAXBLKS), the size of each sector in 
  46. bytes (SECSIZE), the size of each block in sectors (BLKSIZE), and the
  47. location of your sector translate table (we are assuming cpm 2.2x), and
  48. the size of the directory(DIRSIZE). 
  49.  
  50. All of these items are set in #define statements on or about line 100.
  51. Most of the information is available by "stat" on the drive. The 
  52. TXTABLE value may be found by loading ddt, loading a program that 
  53. does file I/O, putting a break (FF?) at vector 16 (sectran call) in
  54. the bios. Once the breakpoint is set, execute the program and 
  55. the value in DE when the breakpoint is encountered is TXTABLE for
  56. that density disk only!
  57. */
  58. /*
  59.     DISK UTILITY PROGRAM
  60.  
  61.     Written by Richard Damon
  62.     Version 1.0 May 1980
  63.  
  64.     This program allows the operator to examine and modify
  65. a CPM diskette.
  66.  
  67.     The commands available in this package are :
  68.  
  69. Tn  set current track to n (0-76)
  70. Sn  set current sector to n (1-SECS_PER_TRACK)
  71. Dn  set current disk number to n (0-3)
  72. Bn  set current track and sector to point to block n (0-F2)
  73. N   set current track and sector to next sector/block
  74.     next sector if last set command was for track or sector
  75.     next block if last set command was for block
  76. I   increment sector, if sector>SECS_PER_TRACK set to 1 and increment track
  77. R   read sector/block into buffer
  78. W   write sector/block from buffer
  79. P   print out contents of buffer, allong with track/sector/block information
  80. Ea n n n n
  81.     edit buffer starting from location a filling with values n n n.
  82. Fn  Fill buffer with value n
  83. X   exit program
  84. M   print disk allocation map
  85.  
  86. Notes:
  87.     1)  Multiple commands may be specified on a line except for X
  88. which must be the only command on the line followed by return.
  89.     2)  Commands may be in upper or lower case letters
  90.     3)  Spaces are ignored except in the E command where they are used
  91.     as separaters for the numbers
  92.  
  93. Typical commands:
  94. d0t0s1rp    read in the track 0 sector 1 of disk 0 (Drive A) and print it
  95. e1A 4F 20 11    set buffer location 1A to 4F, 1B to 20, and 1C to 11.
  96. e0a 00w        set buffer location 0a to 0 and write buffer
  97.             Note no space after last data byte
  98. nrp        get next buffer and print it
  99.  
  100. Disk Allocation Map
  101.     The M command is designed to allow the directory blocks (blocks 0 and 1)
  102. to be printed out in a convient format. The directory is print out in the
  103. following format:
  104.  
  105.  Section 1:
  106.     The top half of the directory listing is a listing of the name
  107.     inforamtion of the directory entries.  Each line corresponds to 1 sector
  108.     of the directory.  A typical entry would be f=DISKTESTCOM/1 4c
  109.     The first letter is a code letter used to referance into section 2.
  110.     The equal sign indicats that the file exists, a star here indicates
  111.       that this entry is a deleted file.
  112.     Next comes the filename and extension.
  113.     The following /n is printed if this is other then the first extent 
  114.       (extent 0) of a file where n is the extent number of this entry.
  115.     The following number is the hex record count for this extent.
  116.  
  117.  Section 2:
  118.     The bottom half of the directory listing is a disk allocation map
  119.     showing which blocks are in use and by which file. Free blocks are
  120.     indicated by a dot while used blocks are marked by the file control
  121.     letter asigned to a file in section 1.  This listing has been blocked off
  122.     in groups of 8 and 16 to ease reading.
  123.  
  124. CPM FILE STRUCTURE
  125.  
  126.     To help the user of this program the following is a brief description
  127. of the format used in CPM.  The first 2 tracks of a disk are reserved
  128. for the bootstrap and the copy of the CPM operating system.  Tracks 2
  129. through 76 store the data.  To speed up disk access CPM does not store
  130. consecutive data in consecutive sectors.  Insteed it uses every 6th sector
  131. for data. Thus to read logical consecutive sectors you must read the
  132. sectors in the following order:
  133.  1 7 13 19 25 5 11 17 23 3 9 15 21 2 8 14 2