home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / LINKCMDS.E < prev    next >
Text File  |  1995-01-12  |  5KB  |  143 lines

  1. compile if not defined(SMALL)  -- If being externally compiled...
  2. include 'STDCONST.E'
  3. define INCLUDING_FILE = 'LINKCMDS.E'
  4. const
  5.    tryinclude 'MYCNF.E'
  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. const
  15.  compile if not defined(WANT_ET_COMMAND)
  16.    WANT_ET_COMMAND = 1
  17.  compile endif
  18.  compile if not defined(NLS_LANGUAGE)
  19.    NLS_LANGUAGE = 'ENGLISH'
  20.  compile endif
  21.  include NLS_LANGUAGE'.e'
  22. compile endif
  23.  
  24. ;  Link <modulename>          Example:  link draw
  25. ;  A simple front end to the link statement to allow command-line invocation.
  26. ;
  27. defc link
  28.    link arg(1)
  29.    if RC>=0 then
  30.       sayerror LINK_COMPLETED__MSG RC
  31. compile if EVERSION < 5.20    -- EPM now does the sayerror internally
  32.    else
  33.       sayerror rc
  34. compile endif
  35.    endif
  36.  
  37.  
  38. ;  Unlink <modulename>        Example:  unlink draw
  39. ;  A simple front end to the unlink statement to allow command-line invocation.
  40. ;
  41. defc unlink
  42.    unlink arg(1)
  43.    if RC then sayerror RC endif
  44.  
  45.  
  46. compile if WANT_ET_COMMAND
  47. ;  Relink [modulename]
  48. ;
  49. ;  Compiles the module, unlinks it and links it again.  A fast way to
  50. ;  recompile/reload a macro under development without leaving the editor.
  51. ;  Note that the unlink is necessary in case the module is already linked,
  52. ;  else the link will merely reinitialize the previous version.
  53. ;
  54. ;  If modulename is omitted, the current filename is assumed.
  55. ;
  56. defc relink
  57.    modulename=arg(1)
  58.    if modulename='' then                           -- If no name given,
  59.       p = lastpos('.', .filename)
  60.       if upcase(substr(.filename,p))<>'.E' then
  61.          sayerror 'Not a .E file'
  62.          return
  63.       endif
  64.       modulename = substr(.filename, 1, p-1)       -- use current file.
  65.       if .modify then
  66.          's'                                       -- Save it if changed.
  67.          if rc then return; endif
  68.       endif
  69.    endif
  70.  compile if EVERSION < 5
  71.    'et' modulename
  72.  compile else
  73.    'etpm' modulename  -- This is the macro ETPM command.
  74.  compile endif
  75.    if rc then return; endif
  76.    unlink modulename
  77.    if RC & (RC <> -310) then sayerror RC; return; endif  -- -310 = "Unlink:  unknown module"
  78.    link modulename
  79.  compile if EVERSION < 5.20    -- EPM now does the sayerror internally
  80.    if RC<0 then
  81.       sayerror rc
  82.    endif
  83.  compile endif
  84. compile endif  -- WANT_ET_COMMAND
  85.  
  86.  
  87. ;  New command to query whether a module is linked.  Of course if
  88. ;  you're not sure whether a module is linked, you can always just repeat the
  89. ;  link command.  E won't reload the file from disk if it's already linked, but
  90. ;  it will rerun the module's DEFINIT which might not be desirable.
  91. ;
  92. ;  This also serves to document the new linked() function.  Linked() returns:
  93. ;     module number        (a small integer, >= 0) if linked.
  94. ;     -1                   if found on disk but not currently linked.
  95. ;     -307                 if module can't be found on disk.  This RC value
  96. ;                          is the same as sayerror("Link: file not found").
  97. ;     -308                 if bad module name, can't be expanded.  Same as
  98. ;                          sayerror("Link: invalid filename").
  99. ;
  100. defc qlink, qlinked, ql
  101.    module = arg(1)
  102.    if module='' then
  103.       sayerror QLINK_PROMPT__MSG
  104.    else
  105.       result = linked(arg(1))
  106.       if result= -307 or    -- sayerror("Link: file not found")
  107.          result= -308 then  -- sayerror("Link: invalid filename")
  108.          sayerror CANT_FIND1__MSG module CANT_FIND2__MSG
  109.       elseif result<0 then    -- return of -1 means file exists but not linked
  110.          sayerror module NOT_LINKED__MSG
  111.       else
  112.          sayerror module LINKED_AS__MSG result'.'
  113.       endif
  114.    endif
  115.  
  116. defc linkverify
  117.    module = arg(1)
  118.    link module
  119.    if RC<0 then
  120.       if RC=-290 then  -- sayerror('Invalid EX file or incorrect version')
  121.          if filetype(module)<>'.EX' then module=module'.ex'; endif
  122.          findfile module1, module, EPATH
  123.          if rc then findfile module1, module, 'PATH'; endif
  124.          if not rc then module = module1; endif
  125.          RC=-290
  126.       endif
  127. compile if EPM
  128.       call winmessagebox(UNABLE_TO_LINK__MSG module, sayerrortext(rc), 16416)  -- OK + ICON_EXCLAMATION + MB+MOVEABLE
  129. compile else
  130.       messageNwait(UNABLE_TO_LINK__MSG module"."  PRESS_A_KEY__MSG)
  131. compile endif
  132.    endif
  133.  
  134. ; Routine to link a .ex file, then execute a command in that file.
  135. defproc link_exec(ex_file, cmd_name)
  136.    'linkverify' ex_file
  137.    if RC>=0 then
  138.       cmd_name arg(3)
  139.    else
  140.       sayerror UNABLE_TO_EXECUTE__MSG cmd_name
  141.    endif
  142.  
  143.