home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / sprint / appenfil.zip / APPENFIL.SPM
Text File  |  1993-08-31  |  4KB  |  96 lines

  1.                      Append a Region to a File
  2.  
  3.    The "WriteSelected" macro in the Borland interface allows you to 
  4.    WRITE selected regions (or columns) to a file.  The following
  5.    macros use the DOS copy command to extend that capability to 
  6.    APPEND to a file.  
  7.  
  8.             
  9.                Description of Included Macros
  10. -----------------------------------------------------------------------
  11. *ScratchFile* is for convenience.  It is a general purpose macro
  12. for creating temporary filenames. An argument to ScratchFile
  13. (e.g., 4 ScratchFile) puts the temporary filename into Q-register
  14. specified by the argument (e.g, Q4 in this example).
  15.  
  16. *AppendCommand* is only for convenience.  It simply composes the
  17. command to be passed to DOS.  It is hardcoded to use QD for the
  18. command, currently expects the filename of the to-be-appended
  19. file to be in Q0, and Q4 holds the name of a temporary file.
  20.  
  21. *BlockWrite* is based on Borland's WriteSelected (from sp.spm),
  22. with additional tests for the append command.  If the argument to
  23. BlockWrite is non-zero, then it will append the region to a file
  24. (or create the file if it does not exist).  (All the action is
  25. here. You could easily collapse ScratchFile and AppendCommand
  26. into BlockWrite if you wanted.)  BlockWrite is also generalized
  27. so that you can enter wildcards (or no filename at all) to get a
  28. menu to choose from. The "overwrite?" test works in all cases if
  29. you are writing a file. It is skipped over in the case of append.
  30.  
  31. *BlockAppend* is for convenience so that it can be assigned to a
  32. key.  Its only function is to pass a value to BlockWrite.
  33.  
  34. -----------------------------------------------------------------------
  35.  
  36. ; for convenience - composing an append copy 
  37.  
  38. ;; ideally "G:" is a ramdisk
  39. ScratchFile : ->x  (set qnumber x "G:\\xxxxzzzz.$$$") ; 
  40.  
  41. AppendCommand :
  42.    mark {to QD clear "command /c copy " insert Q0  "+" insert Q4  " "insert Q0}
  43.  
  44. BlockWrite : ->int appendfile
  45.    if !select (NoBlock return)
  46.    set Q0 ""
  47.    appendfile ? (message "\nAppend"  4 Scratchfile) 
  48.               : message "\nWrite" 
  49.    message " block to: " set Q0 
  50.    if !length Q0 (16 set Q0 flist "*") ; if no file entered, then allow menu choice
  51.    16 set Q0 flist Q0                  ; check for unique choice or wildcards
  52.    if (!(32 exist Q0) || (if !appendfile ask "Overwrite existing file? " else true) ) {
  53.       if !ColMode {
  54.          appendfile ? {writeregion togmark Q4 AppendCommand call QD}
  55.                     : (writeregion togmark Q0)
  56.          mark {
  57.             if (buffind Q0) ReReadFile ; if file was open, reread
  58.             }
  59.          }
  60.       else {
  61.          ColCopy     ; get column to QH
  62.          mark {
  63.             to QH          ; get into column buffer
  64.             appendfile ?  {write Q4 AppendCommand call QD }
  65.                        : if length (write Q0) ; and write it
  66.             if (buffind Q0) ReReadFile ; if file was open, re-read
  67.             }
  68.          }
  69.       }
  70.  
  71. ; dummy command for the menus/keys
  72. BlockAppend : 1 BlockWrite
  73.  
  74. -----------------------------------------------------------------------
  75.  
  76.                      Conditions of Use
  77.  
  78. Use the code as you want, don't sell it, and give credit where
  79. due.  Let me know if you try it out, find problems, make
  80. improvements, etc.  If get some programming ideas/code
  81. from all this, then I would be grateful if you would share some
  82. of your own interesting macros or formatter hacking with me.  If
  83. you don't have any code to share, a postcard or email will be
  84. just fine.  Enjoy.
  85.  
  86. Seth Chaiklin
  87. Institute of Psychology
  88. University of Aarhus
  89. 8240 Risskov
  90. DENMARK
  91.  
  92. email:  psykseth@aau.dk
  93. fax:   +45 (86) 17 59 73
  94.  
  95. 31 August 1993
  96.