home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / UTILS / DIRUTL / SETDRU.ART < prev    next >
Text File  |  2000-06-30  |  17KB  |  351 lines

  1. FURTHER ADVENTURES WITH CORRECT-IT: Z80DOS, PUBLIC FILES AND SETDRU
  2.                              - or -
  3.                  'WHERE'D THAT FILE COME FROM?'
  4.  
  5. by Rick Charnes
  6. San Francisco, Oct. 18, 1987
  7.  
  8.  
  9.     Hooray - I've cracked the code!
  10.      
  11.     ...
  12.  
  13.     Ever notice how sometimes the most valuable lessons in life 
  14. come from errors you've made?
  15.  
  16.                          * * *
  17.   
  18.     For the last several days I've been been using fellow Morrow 
  19. owner and programmer par excellence Carson Wilson's new operating 
  20. system, Z80DOS.  This new BDOS for Z80 computers provides full 
  21. datestamping (and time-stamping, if a real time clock is present) 
  22. integrated in to the directory.  ZRDOS, the BDOS used with the 
  23. "official" Z-System has no internal datestamping, so it is 
  24. therefore generally done via an external program, DateStamper.  
  25. DateStamper, however, is fully compatible with Z80DOS and one can 
  26. quite readily have both date/time-stamping environments 
  27. simultaneously operative and this is indeed how I have arranged 
  28. my system.  I have been running the two side by side with no 
  29. problem for several days.
  30.          
  31.     (I will henceforth refer to "date and time-stamping, if a 
  32. real time clock is present" as simply "datestamping.)
  33.          
  34.     The original CP/M BDOS of course has no datestamping.  Since 
  35. historically CP/M programmers had no OS support the utiltiies 
  36. they developed almost without exception were without 
  37. datestamping.  Although there are now several other CP/M 
  38. replacements that do have datestamping -- QP/M, DOS+, SUPERDOS 
  39. and P2DOS noteworthy among them -- we have had a situation where 
  40. there was scarcely anything in software we could do with their 
  41. datestamps save for running the small number of utilities 
  42. supplied with them!  In addition, a fairly sophisticated 
  43. programming protocol was necessary in order to incorporate 
  44. datestamping into the various CP/M utilities and applications.  
  45. There certainly has been no standard.  This has indirectly been 
  46. the weakness of all previously existing date/time-stamping CP/M 
  47. BDOS replacements.  This is of course in marked contrast to the 
  48. MS-DOS world where to my knowledge all programs are integrated 
  49. with a datestamping system built into the OS.
  50.          
  51.     Z80DOS, however, does its datestamping by implementing two 
  52. new BDOS functions exclusive to Z80DOS which allow programs that 
  53. modify or copy files to maintain file date and time stamps with 
  54. very little programming overhead.  It does this in a way that 
  55. none of the above BDOS'es or even DateStamper can do.  This means 
  56. that programmers can include datestamping support in new progams, 
  57. or -- significantly, add it to existing programs -- with very 
  58. little difficulty or extra code.  Because of this ease of 
  59. programming we now have great potential for creating a standard.
  60.          
  61.     One major advantage of this for me has been the existence of 
  62. a utility supplied with Z80DOS -- a counterpart for which exists 
  63. for none of the other systems -- that uses these new functions to 
  64. enable a user to do something that I have missed sorely: the 
  65. retention over successive editings of the 'date of creation' 
  66. stamp of a word-processed file.  (In all systems the 'date of 
  67. last modification' stamp is of course renewed and changed 
  68. accordingly.)  Because of the way CP/M word processors modify 
  69. files, on all other CP/M-compatible datestamping systems when a 
  70. word-processed file is edited and modified the date of creation 
  71. stamp suddenly becomes the same as the date of modification!  
  72. This new feature, by the way, in my opinion makes Z80DOS' 
  73. datestamping system superior to that of MS-DOS which does not 
  74. have a function for 'date of creation' at all but rather only for 
  75. last update.
  76.    
  77.     I commend Z80DOS to all CP/M users and urge all interested 
  78. parties to investigate its superlative features.  It is in the 
  79. public domain and may be found on BBS's as Z80DOS10.LBR.
  80.  
  81.                          * * *
  82.  
  83.     But this isn't why I'm excited.
  84.  
  85.     One of the other features of Z80DOS is its implementation of 
  86. a sytem whereby certain files, usually overlays and the like, can 
  87. be made available from all user areas in a drive.  These files 
  88. are then considered 'public'.  Some provision of this sort is 
  89. implemented in most of the CP/M 2.2 enhancements, including CP/M 
  90. 3.0 and ZRDOS.  In different systems it is implemented in 
  91. different ways.  With ZRDOS one has 'public directories' wherein 
  92. any file residing inside that directory is automatically made 
  93. public.  With Z80DOS one sets the file attribute bit of the 
  94. second character of the filename.  For all intents and purposes 
  95. the net result is the same.  
  96.          
  97.     I have been using the public directory feature of ZRDOS for 
  98. the year and a quarter I've been using ZCPR3.  One of the 
  99. programs for which on a hard disk it is quite literally 
  100. indispensable is the Morrow spell-checker Correct- It.  Without 
  101. some sort of public file feature one can only run Correct-It from 
  102. a single user area -- unless, that is, one has a copy of the 96k 
  103. DICT.BIN, the 2k DINDEX.BIN and the 24k FIXUP.COM on each and 
  104. every user area on one's hard disk!
  105.   
  106.     As implemented in most BDOS's including Echelon's ZRDOS, 
  107. however, there is one danger to something as powerful as this 
  108. 'public' feature.  Erasing, or even simply creating, writing to 
  109. or copying a non-public file with the same name as a public file 
  110. erases the public file!  Needless to say this can be quite 
  111. disconcerting and if you don't know what's going on trying to 
  112. trace the cause of your misfortune can be extremely frustrating.
  113.          
  114.     Z80DOS comes equipped with a safety feature to deal with this 
  115. problem.  A public file can only be erased if it is in the 
  116. currently logged user area.  Otherwise a read-only error is 
  117. considered to have occurred.
  118.  
  119.     But I didn't know all this at the time.
  120.  
  121.     I was sitting pretty correcting a file one day, my mind as 
  122. far away as could be from public files, safety features and the 
  123. like -- and I got hit with my first R/O error message.  I 
  124. couldn't figure out what was happening.  I was running my CORRECT- 
  125. IT alias that I had always used with ZRDOS; what could be 
  126. different this time?  And to make things worse, when the error 
  127. message displayed on the sceen it mentioned something about a 
  128. file called 'XXPED.$$$'.  What the heck was that and what was 
  129. going on?
  130.          
  131.     It took me a couple of times running the alias before I 
  132. realized that something that was happening was probably related 
  133. to this public file safety feature.  I then recalled how ZRDOS 
  134. worked with this alias (previously released in my CORREC10.LBR).  
  135. One must have AUXDICT.TXT, DICT.BIN, DINDEX.BIN and FIXUP.COM all 
  136. in the public directory area, thus making them public files.  But 
  137. it does something else: when FIXUP.COM writes your newly 
  138. "learned" words to your old AUXDICT.TXT, one eventually notices 
  139. to one's distress that it ends up putting the resultant file not 
  140. back in the public directory area where it must be located at 
  141. alias invocation but rather in the currently logged user area!
  142.                   
  143.     I have since figured out that what happens is similar to how 
  144. all CP/M word processor work when they modify ("write to") a 
  145. presently-existing file.  A new file is created with a temporary 
  146. name, the old one is erased, then the new is renamed to the old.  
  147. (This, by the way, is why datestamping systems have such 
  148. difficulty maintaining the time/date stamp of a word-processed 
  149. file: they're essentially working with a new file.  Once the 
  150. original file is erased the new file has no way of knowing what 
  151. the old file's creation date was.)
  152.          
  153.     So ZRDOS' public feature finds AUXDICT.TXT since it's in a 
  154. public directory, opens it and reads its contents, and proceeds 
  155. to create a new file with a temporary name.  Since we're probably 
  156. not logged on the public directory this new file is written to 
  157. the currently logged user area.  When that is done FIXUP.COM 
  158. looks again to AUXDICT.TXT, still a public file, and erases it.  
  159. Finally the temporary file residing on the currently logged user 
  160. area is renamed to AUXDICT.TXT and no one is any the wiser.
  161.  
  162.     This worked fine with ZRDOS.  The only drawback is that at 
  163. alias exit we were then left with an AUXDICT.TXT that was no 
  164. longer in a public directory, not a public file and therefore 
  165. inaccessible to the next run of CORRECT-IT.  So I dealt with this 
  166. problem easily by putting one more command at the end of the 
  167. alias that has the utility MOVE.COM move it from where it was 
  168. back to the public directory.  No actual copying takes place; 
  169. only the user number is changed in the directory and the 
  170. operation takes place extremely quickly.
  171.          
  172.     So why wasn't this working with Z80DOS?  It took quite a bit 
  173. of head-scratching to figure this out, especially since my 
  174. understanding of what was happening with ZRDOS as above only came 
  175. to me after going through the process of figuring out the error 
  176. with Z80DOS.  I hadn't the slightest idea what 'XXPED.$$$' was.  
  177. All I knew is that I was always finding a file by this name left 
  178. on the currently logged user area, and it was exact replica of my 
  179. original AUXDICT.TXT only with the new learned words added.  This 
  180. was the file that AUXDICT.TXT _should_ now have been.  I still 
  181. hadn't yet pinned down exactly where the error was occurring.  
  182. All I knew is that ZEX file that my alias invoked was aborting 
  183. somewhere right in the middle and I was getting a R/O error.
  184.                   
  185.     So I did what I've taught myself, actually with Ted 
  186. Silveira's help, to do in these situations:  simplify.  Take 
  187. everything line by line, one by one, operation by operation and 
  188. study exactly what is going on with each.  Strip out all 
  189. unnecessary overhead.  I ran the alias several times with 
  190. printouts in front of me of both the ZEX batch file and the alias 
  191. and paid careful attention to what was going on on the screen.  I 
  192. realized that it was happening immediately after the disk 
  193. finished its grinding from having written the new AUXDICT.TXT to 
  194. disk.  I looked and thought, thought and looked, and studied some 
  195. more, and finally realized: something somewhere is trying to 
  196. erase AUXDICT.TXT and the operating system isn't letting it.  It 
  197. was then that I pieced together the scheme above of how 
  198. the new AUXDICT.TXT gets written.  It was of course the Z80DOS 
  199. safety feature:  FIXUP.COM was trying to erase AUXDICT.TXT, a 
  200. public file, and the OS wouldn't let it.  
  201.                   
  202.     But I was still puzzled by this mysterious 'XXPED.$$$'.  I 
  203. assumed it was some sort of temporary file, but where was it 
  204. coming from?  The BDOS?  I looked through the code to the Z80DOS 
  205. source, which is provided along with Z80DOS10.LBR.  I found the 
  206. routines for file deletion and R/O errors, hoping to find that it 
  207. creates a file named (for some reason) XXPED.$$$ when it is asked 
  208. to erase a public file and the anti-deletiion safety feature is 
  209. invoked.  I did a string search and found -- nothing.
  210.              
  211.     I then hit upon another idea.  I loaded up ZPATCH, the ZCPR3 
  212. file patcher that makes the CP/M ZAP look like a 1979 version of 
  213. ED.COM, and took a look at the binary code inside FIXUP.COM.  
  214. Eureka!! -- there it was:  XXPED.$$$.  I'm quite certain only God 
  215. and Correct-It's author know where the name 'XXPED.$$$' is 
  216. supposed to mean, but it's quite obviously the name FIXUP.COM 
  217. gives to its temporary file just before it erases the old 
  218. AUXDICT.TXT.  I guess the author couldn't think of a good name 
  219. for it and gave it the name that he felt was the most 
  220. XXPEDient...
  221.  
  222.                          * * *
  223.  
  224. But what is the "code" that I say I cracked?  I'm getting to that.
  225.  
  226.     So what was I to do now?  The BDOS, perhaps quite properly, 
  227. will not let me erase the old AUXDICT.TXT.  How is FIXUP going to 
  228. work properly?
  229.          
  230.     I suppose I could add several new commands to the alias:
  231.  
  232. (1)  Log on to the specific user area on which the old 
  233.      AUXDICT.TXT is located
  234.  
  235. (2)  Erase it.
  236.  
  237. (3)  Make the new XXPED.$$$ a public file.
  238.  
  239. (4)  Rename it to AUXDICT.TXT
  240.          
  241.     How boring.
  242.     
  243.     Enter SETDRU.
  244.     
  245.     SETDRU is one of those good old classic CP/M utilities that 
  246. few people use anymore but were as valuable as a gold mine in 
  247. their heyday.  It does, as a standalone program, what an 
  248. operating system's public feature does generally.  It is used to 
  249. modify other COM files.  A program modified by SETDRU puts a 
  250. "filter" in high memory which then redirects all the program's 
  251. internal "calls" made to other, supplemental and subsidiary files 
  252. it may need for its operation -- overlays, other COM files, text 
  253. files, etc -- to specific, user-specified user numbers.  It is 
  254. perfect for our purposes.
  255.  
  256.     But I had tried and failed, six or nine months ago, to get 
  257. SETDRU to work properly on Correct-It.  I had initially felt that 
  258. the extra step at the end of the ZRDOS alias that MOVEs 
  259. AUXDICT.TXT back to the public user area was inelegant and 
  260. unprofessional.  Computers shouldn't have to work like that.
  261.          
  262.     In order to get SETDRU to modify a file properly you must 
  263. provide it the name of each and every subsidiary file to which 
  264. the main program makes a call, and then specify the user number 
  265. to which you wish to redirect said call.  This is often difficult 
  266. to do.  A call can be either a "read" or a "write", and both must 
  267. be specified.  I remember nine months agao sitting and spending 
  268. two or three hours with Correct-It, tracing every operation and 
  269. guessing at when DINDEX.BIN is being invoked, when DICT.BIN is 
  270. being read, the exact order of invocation, etc.  After some time 
  271. I managed to get the whole shebang working successfully --- until 
  272. the time that FIXUP should have written the new learned words to 
  273. AUXDICT.TXT.  
  274.          
  275.     I just couldn't figure out how to get that right.  After 
  276. prompting me for "Name of auxiliary dictionary to write to?  " 
  277. I would enter 'AUXDICT.TXT' and the operation would abort; it 
  278. acted as if it were unable to find the file, even though I knew 
  279. it was there.  I knew that some call was being made, but I was 
  280. damned if I could find out what, who, when, where or how.
  281.          
  282.     I gave up.  I wrote the simple MOVE command line into the 
  283. alias and forgot about it.  
  284.     
  285.     Until last night, nine months later.
  286.  
  287.     I figured: it must be XXPED.$$$.  That was the secret.  It 
  288. was the missing call.  I sat down, found my yellowed, dog-eared 
  289. notes from my SETDRU experience of those many moons ago, put my 
  290. programmer's cap back on and loaded up SETDRU one more time.  I 
  291. went through all the same call redirections I found on my paper, 
  292. but this time additionally redirected FIXUP to XXPED.$$$, and 
  293. specified the user number.  Exited SETDRU, turned off the public 
  294. file feature on all relevant files, called up my alias, and held 
  295. my breath.
  296.          
  297.     It worked like a charm.  CORRECT.COM found FIXUP, FIXUP found 
  298. DICT.BIN, and FIXUP finally did "find" AUXDICT.TXT.  Hard work, 
  299. study -- and learning from your errors -- does pay off.  Thank 
  300. you, my new friend, XXPED.$$$.
  301.  
  302.                              * * *
  303.              
  304.     Here's how to do it:  put CORRECT.COM along your path and put 
  305. DINDEX.BIN, DICT.BIN, AUXDICT.TXT, and FIXUP.COM all in the same 
  306. directory.  I put mine in user 6.  Do NOT make them public files. 
  307. Then run SETDRU first on CORRECT.COM as follows and exactly in 
  308. this order:
  309.              
  310. Redirect call to DINDEX .BIN to user 6
  311. Redirect call to DICT   .BIN to user 6
  312. Redirect call to AUXDICT.TXT to user 6
  313. Redirect call to FIXUP  .COM to user 6
  314.  
  315. Then run SETDRU on FIXUP.COM as follows:
  316.  
  317. Redirect call to DINDEX .BIN to user 6
  318. Redirect call to AUXDICT.TXT to user 6
  319. Redirect call to XXPED  .$$$ to user 6
  320. Redirect call to AUXDICT.TXT to user 6
  321.  
  322. I've left out several details of the entire alias for which you 
  323. should consult my CORRECT10.LBR but this takes care of the 
  324. crucial part.
  325.               
  326.     CORRECT-IT can finally be used with any BDOS, with or without 
  327. a provision for public files, and with or without an otherwise 
  328. valuable safety feature.
  329.  
  330.     It _is_ rather ironic that in this age of modern operating 
  331. systems with public files and safety features I would rely on for 
  332. a solution deliberately overriding one of the modern features and 
  333. utilize instead something from the bad old days of the CP/M 
  334. yesteryear, but all sorts of things in life are ironic.
  335.  
  336.     I thoroughly enjoyed this adventure in debugging.  Doing this 
  337. kind of work gives me a great deal of satisfaction.
  338.    
  339.     Happy CORRECT-ing...
  340.  
  341.                                        - Rick Charnes
  342.  
  343. I greatly solicit comments, suggestions and other assorted 
  344. hoots and catcalls regarding the above flights of fancy.  I can 
  345. be reached at Z-Node Central (Los Altos, CA), Ladera Z-Node (Los 
  346. Angeles), Newton Centre Z-Node (Boston), Lillipute Z-Node 
  347. (Chicago), or, God forbid, by voice at (415) 826-9448.  
  348.  
  349.  
  350.                          --==**==--
  351.