home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / prodtool / epm / e_macros / saveload.e < prev    next >
Encoding:
Text File  |  1991-09-09  |  8.0 KB  |  260 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.    options = check_for_printer(name)    -- Returns 0 or printer number.
  52.    if options then                      -- If a printer (i.e., non-zero),
  53.       if not printer_ready(options) then  -- and it's not ready,
  54.          call messageNwait(PRINTER_NOT_READY__MSG'  'PRESS_A_KEY__MSG)
  55.          return 1
  56.       endif
  57.    elseif check_for_host_file(name) then
  58.       call save_host_file(name)
  59.       return 0      /* Return 0, some terminal emulators do not give us */
  60. compile if BACKUP_PATH
  61.    else
  62.        -- jbl 1/89 new feature.  Editors in the real marketplace keep at least
  63.        -- one backup copy when a file is written.
  64.  compile if EVERSION >= '4.10'    -- OS/2 - redirect STDOUT & STDERR
  65.       quietshell 'copy' name MakeBakName() '1>nul 2>nul'
  66.  compile else
  67.       quietshell 'copy' name MakeBakName() '>nul'
  68.  compile endif
  69. compile endif
  70.    endif            /* meaningful error codes.                          */
  71.    options=arg(2)
  72.    'xcom s 'options name; src=rc
  73.    if not rc and name=.filename then
  74.       .modify=0
  75.       'deleteautosavefile'
  76.    endif
  77.    return src
  78.  
  79. defproc namefile()
  80.    universal hostfileid,hostfilespec,hname,htype,hmode
  81.    newname=arg(1)
  82.    if check_for_host_file(newname) then
  83.       .filename=HOSTDRIVE||hostfilespec
  84.    elseif parse_filename(newname,.filename) then
  85.       sayerror INVALID_FILENAME__MSG
  86.    else
  87.       'xcom n 'newname
  88.    endif
  89.  
  90. defproc quitfile()
  91.    universal hostfileid,hostfilespec,hname,htype,hmode
  92.  
  93. compile if EVERSION < 5
  94.    if .windowoverlap then
  95.       modify=(.modify and .views=1)
  96.    else
  97.       modify=.modify
  98.    endif
  99.    k='Y'
  100.    if modify then
  101.  compile if SMARTQUIT
  102.       call message(QUIT_PROMPT1__MSG '('FILEKEY')')
  103.  compile else
  104.       call message(QUIT_PROMPT2__MSG)
  105.  compile endif
  106.       loop
  107.          k=upcase(getkey())
  108.  compile if SMARTQUIT
  109.          if k=$FILEKEY then 'File'; return 1              endif
  110.  compile endif
  111.          if k=YES_CHAR or k=NO_CHAR or k=esc then leave            endif
  112.       endloop
  113.       call message(1)
  114.    endif
  115.    if k<>YES_CHAR then
  116.       return 1
  117.    endif
  118.    if not .windowoverlap or .views=1 then
  119.       .modify=0
  120.    endif
  121. compile endif
  122.  
  123.    'deleteautosavefile'
  124. compile if EVERSION < 5
  125.    if .windowoverlap then
  126.       quitview
  127.    else
  128.       'xcom q'
  129.    endif
  130. compile else
  131.    'xcom q'
  132. compile endif
  133.  
  134. /* warning this procedure may sayerror Invalid host filename and stop */
  135. defproc check_for_host_file
  136.    universal hostfileid,hostfilespec,hname,htype,hmode
  137.  
  138.    hostfilespec=upcase(strip(arg(1)))
  139.    i=pos(HOSTDRIVE,hostfilespec)
  140.    if i<>1 then return 0 endif  -- Ver. 3.09  Don't accept garbage before H:
  141.    hostfilespec=substr(hostfilespec,i+length(HOSTDRIVE))
  142.    parse value hostfilespec with hname htype hmode
  143.    if hmode='' then hmode='A';hostfilespec=hostfilespec hmode endif
  144.    if htype='' or length(hmode)>2 then sayerror INVALID_FILENAME__MSG;stop endif
  145.    if verify(hostfilespec,':;?*\/|><.,','M') then
  146.       sayerror BAD_FILENAME_CHARS__MSG
  147.       stop
  148.    endif
  149.    hostfilespec=hname htype hmode   /* remove extra spaces */
  150.    return 1
  151.  
  152. defproc load_host_file(options)
  153.    universal hostfileid,hostfilespec,hname,htype,hmode
  154.    universal hostcopy
  155.    universal vTEMP_PATH
  156.  
  157. compile if not EPM
  158.    call message(LOADING__MSG HOSTDRIVE||hostfilespec)
  159. compile endif
  160.    quiet_shell hostcopy HOSTCOPYDRIVE||hname htype hmode vTEMP_PATH'eeeeeeee.'hostfileid HOSTCOPYOPTIONS
  161. compile if E3  -- Only E3 generates an "Insufficient memory" error.
  162.    if rc=sayerror("Insufficient memory") then
  163.       stop
  164.    endif
  165. compile endif
  166.    if rc then /* assume host file not found */
  167.       'xcom e 'options '/n .newfile'
  168.       call message(HOST_NOT_FOUND__MSG)
  169.       rc=-282  -- sayerror('New file')
  170.    else
  171.       'xcom e 'options vTEMP_PATH'eeeeeeee.'hostfileid
  172.       if rc then
  173.          call message(rc)
  174.          return
  175. compile if not EPM
  176.       else
  177.          call message(1)
  178. compile endif
  179.       endif
  180.    endif
  181.    call erasetemp(vTEMP_PATH'eeeeeeee.'hostfileid)
  182.    .filename=HOSTDRIVE||hostfilespec
  183.  
  184. defproc save_host_file
  185.    universal hostfileid,hostfilespec,hname,htype,hmode
  186.    universal hostcopy
  187.    universal vTEMP_PATH
  188.  
  189.    getfileid hostfileid
  190.    'xcom save' vTEMP_PATH'eeeeeeee.'hostfileid
  191.    if rc then stop; endif
  192. compile if not EPM
  193.    call message(SAVING__MSG HOSTDRIVE||hostfilespec)
  194. compile endif
  195.    /* is this a binary file ? */
  196.    if length(htype)>=3 then
  197. compile if EVERSION >= '5.17'
  198.       if upcase(rightstr(htype,3))=='BIN' then
  199. compile else
  200.       if upcase(substr(htype,length(htype)-2))=='BIN' then
  201. compile endif
  202.          hostfilespec=hostfilespec '/b'
  203.       endif
  204.    endif
  205.    quiet_shell hostcopy vTEMP_PATH'eeeeeeee.'hostfileid' 'HOSTCOPYDRIVE||hostfilespec HOSTCOPYOPTIONS
  206.    if rc then
  207. compile if E3  -- Only E3 generates an "Insufficient memory" error.
  208.       if rc=sayerror('Insufficient memory') then
  209.          emsg = 'Insufficient memory to call' hostcopy
  210.       else
  211.          emsg = 'Host error 'rc'; host save cancelled'
  212.       endif
  213.       sayerror emsg'.  File saved in 'vTEMP_PATH'eeeeeeee.'hostfileid
  214. compile else
  215.       sayerror HOST_ERROR__MSG rc'; 'HOST_CANCEL__MSG vTEMP_PATH'eeeeeeee.'hostfileid
  216. compile endif
  217.       stop
  218.    endif
  219.    if arg(1) = .filename then .modify=0; endif
  220.    call erasetemp(vTEMP_PATH'eeeeeeee.'hostfileid)
  221.    call message(1)
  222.  
  223.  
  224. defproc filetype()        -- Ver. 3.09 - split out from Select.E
  225.    universal htype
  226.    fileid=arg(1)
  227.    if fileid='' then fileid=.filename; endif
  228.    if check_for_host_file(fileid) then
  229.       return htype
  230.    endif
  231.    i=lastpos('\',fileid)
  232.    if i then
  233.       fileid=substr(fileid,i+1)
  234.    endif
  235.    i=lastpos('.',fileid)
  236.    if i then
  237.       return upcase(substr(fileid,i+1))
  238.    endif
  239. ;  return ''       -- added by ET; no need to duplicate.
  240.  
  241. defproc vmfile(var name, var cmdline)
  242.  
  243.   parse value name with fn ft fm cmdline
  244.  
  245.   if upcase(substr(fn,1,length(HOSTDRIVE)))<>HOSTDRIVE or pos('\',fn) or
  246.      pos('.',fn) or length(ft)>8 or pos(':',ft) or
  247.      pos('\',ft) or pos('.',ft) then
  248.     return 0
  249.   endif
  250.  
  251.   if fm='' or length(fm)>2 or verify(substr(fm,2,1),'1234567890 ') or
  252.      pos(':',fm) or pos('\',fm) or pos('.',fm) then
  253.     cmdline = fm cmdline
  254.     name = fn ft
  255.     return 1
  256.   endif
  257.  
  258.   name = fn ft fm
  259.   return 1                             --better be VM at this point
  260.