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