home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / prodtool / epm / e_macros / linkcmds.e < prev    next >
Encoding:
Text File  |  1992-06-17  |  4.0 KB  |  126 lines

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