home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / PUT.E < prev    next >
Text File  |  1994-06-21  |  4KB  |  120 lines

  1. ;  For linking version, PUT can be an external module.
  2.  
  3. compile if not defined(SMALL)  -- If SMALL not defined, then being separately
  4.  define INCLUDING_FILE = 'PUT.E'
  5.    tryinclude 'MYCNF.E'        -- the user's configuration customizations.
  6.  
  7.  compile if not defined(SITE_CONFIG)
  8.     const SITE_CONFIG = 'SITECNF.E'
  9.  compile endif
  10.  compile if SITE_CONFIG
  11.     tryinclude SITE_CONFIG
  12.  compile endif
  13.  
  14.  compile if not defined(NLS_LANGUAGE)
  15.   const NLS_LANGUAGE = 'ENGLISH'
  16.  compile endif
  17. include NLS_LANGUAGE'.e'
  18.  compile if EVERSION >= 6
  19.    EA_comment 'This defines the PUT command; it can be linked, or executed directly.'
  20.  compile endif
  21. compile endif
  22.  
  23. defmain     -- External modules always start execution at DEFMAIN.
  24.    'put' arg(1)
  25.  
  26. defc app, append, put =
  27.    universal last_append_file
  28.  
  29.    -- Put and append work the same, and the same as XEdit's PUT.
  30.    -- If the file already exists, append to it.
  31.    -- If no file is specified, use same file as last specified.
  32.    -- If no mark, use append the entire file.
  33.    name = arg(1)
  34.    call parse_leading_options(name,options)
  35.    if name = '' then
  36.       app_file=last_append_file
  37.    else
  38.       app_file=parse_file_n_opts(name)
  39.       last_append_file=app_file
  40.    endif
  41.    if app_file='' then
  42.       sayerror NO_FILENAME__MSG 'PUT'
  43.       stop
  44.    endif
  45.    is_console = upcase(app_file)='CON' | upcase(app_file)='CON:'
  46. compile if EVERSION > 5
  47.    if is_console then
  48.       sayerror NO_CONSOLE__MSG
  49.       return
  50.    endif
  51. compile endif
  52.    getfileid fileid
  53.    if marktype() then
  54.       had_mark = 1
  55.       call psave_mark(save_mark)
  56.       call prestore_mark(save_mark)
  57.    elseif .last = 0 then sayerror FILE_IS_EMPTY__MSG; stop
  58.    else
  59.       had_mark = 0
  60.       call pset_mark(1,.last,1,1,'LINE',fileid)
  61.    endif
  62.    /* If file is already in memory, we'll leave it there for speed. */
  63.    parse value 1 check_for_printer(app_file) with already_in_ring is_printer .
  64.    if is_printer | is_console then
  65.       'e /q /c' app_file   /* force creation of a new file */
  66.    else
  67.       'e /q /n' app_file   /* look for file already in ring */
  68.       if rc=-282 then  -- -282 = sayerror("New file")
  69.          already_in_ring = 0
  70.          'q'
  71.          'e /q' app_file  /* not 'xcom e', so we can append to host files */
  72.       endif
  73.    endif
  74.    if is_printer or is_console or not already_in_ring then
  75.       if rc=-282 then
  76.          deleteline
  77.       elseif rc then
  78.          stop
  79.       endif
  80.    endif
  81.    getfileid tempofid
  82.    if marktype()<>'LINE' then
  83.       insertline '',tempofid.last+1
  84.    endif
  85.    bottom
  86.    copyrc=pcopy_mark()
  87.    if copyrc then /* Check memory full, invalid path, etc. */
  88.       .modify=0; 'q'
  89.       sayerror copyrc
  90.       stop
  91.    endif
  92.    error_saving=0
  93.    /* If the app_file was already in memory, don't file it. */
  94.    if is_printer or is_console or not already_in_ring then
  95. compile if EVERSION < 5
  96.       if is_console then pause; endif
  97. compile endif
  98.       'save' options
  99. compile if EVERSION < 5
  100.       if is_console then pause; endif
  101. compile endif
  102.       error_saving=rc
  103.       activatefile tempofid; tempofid.modify=0; 'q'
  104.    endif
  105.    activatefile fileid
  106.    if had_mark then
  107.       call prestore_mark(save_mark)
  108.    else
  109.       unmark
  110.    endif
  111. compile if EVERSION < 5
  112.    if not error_saving then
  113.       sayerror MARK_APPENDED__MSG app_file
  114.    endif
  115. compile else
  116.    refresh
  117.    -- call settitletext(.filename) /* done internally */
  118.    call repaint_window()
  119. compile endif
  120.