home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / SAVELOAD.E < prev    next >
Text File  |  1995-10-03  |  9KB  |  285 lines

  1. /****************************************/
  2. /*   procedures for host file support   */
  3. /*                                      */
  4. /****************************************/
  5.  
  6. compile if not defined(HOSTDRIVE)
  7. const
  8.    HOSTDRIVE= 'H:'         -- Dummy drive letter to stand for Host files.
  9. compile endif              -- Make sure the drive letter is in upper case.
  10.  
  11. compile if not defined(HOSTCOPYDRIVE)
  12. const
  13.    HOSTCOPYDRIVE= 'H:'     -- This is the drive letter used on the HOSTCOPY
  14. compile endif              -- command.  Distinct from HOSTDRIVE, for users who
  15.                            -- have a real H: drive on the PC.
  16.  
  17. compile if not defined(HOSTCOPYOPTIONS)
  18. const
  19.    HOSTCOPYOPTIONS= ''     -- Any options you want appended to the HOSTCOPY
  20. compile endif              -- command.  E.g., for CP78COPY, you might want '/Q'.
  21.  
  22. defproc loadfile(files,options)
  23.    universal hostfileid,hostfilespec
  24.  
  25.    if check_for_host_file(files) then
  26.       /* check if file is already in ring */
  27.       hostall = HOSTDRIVE||hostfilespec
  28.       getfileid hostfileid,hostall
  29.       create_flag = isoption(options,'C')
  30.       if hostfileid='' | isoption(options,'D') | create_flag then
  31. compile if EVERSION >= '4.10'
  32.          'xcom e' options '/c .'   -- 'E /C' forces creation of a new file
  33. compile else
  34.          'xcom e' options '/n .'   -- Old E; must rely on using an unlikely name
  35. compile endif
  36.          if isoption(options,'N') | create_flag then
  37.             .filename=hostall
  38.          else
  39.             getfileid hostfileid
  40.             'xcom q'
  41.             call load_host_file(options)
  42.          endif
  43.       else
  44.          activatefile hostfileid
  45.       endif
  46.    else
  47.       'xcom e' options files
  48.    endif
  49.  
  50. defproc savefile(name)
  51. compile if EVERSION >= '5.50'  --@HPFS
  52.    name_same = (name = .filename)
  53. compile endif
  54.    options = check_for_printer(name)    -- Returns 0 or printer number.
  55.    if options then                      -- If a printer (i.e., non-zero),
  56.       if not printer_ready(options) then  -- and it's not ready,
  57.          call messageNwait(PRINTER_NOT_READY__MSG'  'PRESS_A_KEY__MSG)
  58.          return 1
  59.       endif
  60.    elseif check_for_host_file(name) then
  61.       call save_host_file(name)
  62.       return 0      /* Return 0, some terminal emulators do not give us */
  63. compile if BACKUP_PATH
  64.    else
  65.  compile if EVERSION >= '5.50'  --@HPFS
  66.       if pos(' ',name) & leftstr(name,1)<>'"' then
  67.          name = '"'name'"'
  68.       endif
  69.  compile endif
  70.        -- jbl 1/89 new feature.  Editors in the real marketplace keep at least
  71.        -- one backup copy when a file is written.
  72.  compile if EVERSION >= '4.10'    -- OS/2 - redirect STDOUT & STDERR
  73.       quietshell 'copy' name MakeBakName() '1>nul 2>nul'
  74.  compile else
  75.       quietshell 'copy' name MakeBakName() '>nul'
  76.  compile endif
  77. compile endif
  78.    endif            /* meaningful error codes.                          */
  79. compile if BACKUP_PATH = '' & EVERSION >= '5.50'  --@HPFS
  80.    if pos(' ',name) & leftstr(name,1)<>'"' then
  81.       name = '"'name'"'
  82.    endif
  83. compile endif
  84.    options=arg(2)
  85.    'xcom s 'options name; src=rc
  86. compile if EVERSION >= '5.50'  --@HPFS
  87.    if not rc and name_same then
  88. compile else
  89.    if not rc and name=.filename then
  90. compile endif
  91.       .modify=0
  92.       'deleteautosavefile'
  93.    endif
  94.    return src
  95.  
  96. defproc namefile()
  97.    universal hostfileid,hostfilespec,hname,htype,hmode
  98.    newname=arg(1)
  99.    if check_for_host_file(newname) then
  100.       .filename=HOSTDRIVE||hostfilespec
  101.    elseif parse_filename(newname,.filename) then
  102.       sayerror INVALID_FILENAME__MSG
  103.    else
  104. compile if EVERSION >= '5.50'  --@HPFS
  105.       if pos(' ',newname) & leftstr(newname,1)<>'"' then
  106.          newname = '"'newname'"'
  107.       endif
  108. compile endif
  109.       'xcom n 'newname
  110.    endif
  111.  
  112. defproc quitfile()
  113.    universal hostfileid,hostfilespec,hname,htype,hmode
  114.  
  115. compile if EVERSION < 5
  116.    if .windowoverlap then
  117.       modify=(.modify and .views=1)
  118.    else
  119.       modify=.modify
  120.    endif
  121.    k='Y'
  122.    if modify then
  123.  compile if SMARTQUIT
  124.       call message(QUIT_PROMPT1__MSG '('FILEKEY')')
  125.  compile else
  126.       call message(QUIT_PROMPT2__MSG)
  127.  compile endif
  128.       loop
  129.          k=upcase(getkey())
  130.  compile if SMARTQUIT
  131.          if k=$FILEKEY then 'File'; return 1              endif
  132.  compile endif
  133.          if k=YES_CHAR or k=NO_CHAR or k=esc then leave            endif
  134.       endloop
  135.       call message(1)
  136.    endif
  137.    if k<>YES_CHAR then
  138.       return 1
  139.    endif
  140.    if not .windowoverlap or .views=1 then
  141.       .modify=0
  142.    endif
  143. compile endif
  144.  
  145.    'deleteautosavefile'
  146. compile if EVERSION < 5
  147.    if .windowoverlap then
  148.       quitview
  149.    else
  150.       'xcom q'
  151.    endif
  152. compile else
  153.    'xcom q'
  154. compile endif
  155.  
  156. /* warning this procedure may sayerror Invalid host filename and stop */
  157. defproc check_for_host_file
  158.    universal hostfileid,hostfilespec,hname,htype,hmode
  159.  
  160.    hostfilespec=upcase(strip(arg(1)))
  161.    i=pos(HOSTDRIVE,hostfilespec)
  162.    if i<>1 then return 0 endif  -- Ver. 3.09  Don't accept garbage before H:
  163.    hostfilespec=substr(hostfilespec,i+length(HOSTDRIVE))
  164.    parse value hostfilespec with hname htype hmode
  165.    if hmode='' then hmode='A';hostfilespec=hostfilespec hmode endif
  166.    if htype='' or length(hmode)>2 then sayerror INVALID_FILENAME__MSG;stop endif
  167.    if verify(hostfilespec,':;?*\/|><.,','M') then
  168.       sayerror BAD_FILENAME_CHARS__MSG
  169.       stop
  170.    endif
  171.    hostfilespec=hname htype hmode   /* remove extra spaces */
  172.    return 1
  173.  
  174. defproc load_host_file(options)
  175.    universal hostfileid,hostfilespec,hname,htype,hmode
  176.    universal hostcopy
  177.    universal vTEMP_PATH
  178.  
  179. compile if not EPM
  180.    call message(LOADING__MSG HOSTDRIVE||hostfilespec)
  181. compile endif
  182.    quiet_shell hostcopy HOSTCOPYDRIVE||hname htype hmode vTEMP_PATH'eeeeeeee.'hostfileid HOSTCOPYOPTIONS
  183. compile if E3  -- Only E3 generates an "Insufficient memory" error.
  184.    if rc=sayerror("Insufficient memory") then
  185.       stop
  186.    endif
  187. compile endif
  188.    if rc then /* assume host file not found */
  189.       'xcom e 'options '/n .newfile'
  190.       call message(HOST_NOT_FOUND__MSG)
  191.       rc=-282  -- sayerror('New file')
  192.    else
  193.       'xcom e 'options vTEMP_PATH'eeeeeeee.'hostfileid
  194.       if rc then
  195.          call message(rc)
  196.          return
  197. compile if not EPM
  198.       else
  199.          call message(1)
  200. compile endif
  201.       endif
  202.    endif
  203.    call erasetemp(vTEMP_PATH'eeeeeeee.'hostfileid)
  204.    .filename=HOSTDRIVE||hostfilespec
  205.  
  206. defproc save_host_file
  207.    universal hostfileid,hostfilespec,hname,htype,hmode
  208.    universal hostcopy
  209.    universal vTEMP_PATH
  210.  
  211.    getfileid hostfileid
  212.    'xcom save' vTEMP_PATH'eeeeeeee.'hostfileid
  213.    if rc then stop; endif
  214. compile if not EPM
  215.    call message(SAVING__MSG HOSTDRIVE||hostfilespec)
  216. compile endif
  217.    /* is this a binary file ? */
  218.    if length(htype)>=3 then
  219. compile if EVERSION >= '5.17'
  220.       if upcase(rightstr(htype,3))=='BIN' then
  221. compile else
  222.       if upcase(substr(htype,length(htype)-2))=='BIN' then
  223. compile endif
  224.          hostfilespec=hostfilespec '/b'
  225.       endif
  226.    endif
  227.    quiet_shell hostcopy vTEMP_PATH'eeeeeeee.'hostfileid' 'HOSTCOPYDRIVE||hostfilespec HOSTCOPYOPTIONS
  228.    if rc then
  229. compile if E3  -- Only E3 generates an "Insufficient memory" error.
  230.       if rc=sayerror('Insufficient memory') then
  231.          emsg = 'Insufficient memory to call' hostcopy
  232.       else
  233.          emsg = 'Host error 'rc'; host save cancelled'
  234.       endif
  235.       sayerror emsg'.  File saved in 'vTEMP_PATH'eeeeeeee.'hostfileid
  236. compile else
  237.       sayerror HOST_ERROR__MSG rc'; 'HOST_CANCEL__MSG vTEMP_PATH'eeeeeeee.'hostfileid
  238. compile endif
  239.       stop
  240.    endif
  241.    if arg(1) = .filename then .modify=0; endif
  242.    call erasetemp(vTEMP_PATH'eeeeeeee.'hostfileid)
  243.    call message(1)
  244.  
  245.  
  246. defproc filetype()        -- Ver. 3.09 - split out from Select.E
  247.    universal htype
  248.    fileid=arg(1)
  249.    if fileid='' then fileid=.filename; endif
  250.    if substr(fileid, 1, 5)=='.DOS ' then
  251.       return ''
  252.    endif
  253.    if check_for_host_file(fileid) then
  254.       return htype
  255.    endif
  256.    i=lastpos('\',fileid)
  257.    if i then
  258.       fileid=substr(fileid,i+1)
  259.    endif
  260.    i=lastpos('.',fileid)
  261.    if i then
  262.       return upcase(substr(fileid,i+1))
  263.    endif
  264. ;  return ''       -- added by ET; no need to duplicate.
  265.  
  266. defproc vmfile(var name, var cmdline)
  267.  
  268.   parse value name with fn ft fm cmdline
  269.  
  270.   if upcase(substr(fn,1,length(HOSTDRIVE)))<>HOSTDRIVE or pos('\',fn) or
  271.      pos('.',fn) or length(ft)>8 or pos(':',ft) or
  272.      pos('\',ft) or pos('.',ft) then
  273.     return 0
  274.   endif
  275.  
  276.   if fm='' or length(fm)>2 or verify(substr(fm,2,1),'1234567890 ') or
  277.      pos(':',fm) or pos('\',fm) or pos('.',fm) then
  278.     cmdline = fm cmdline
  279.     name = fn ft
  280.     return 1
  281.   endif
  282.  
  283.   name = fn ft fm
  284.   return 1                             --better be VM at this point
  285.