home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac2.zip / MAKEACTN.E < prev    next >
Text File  |  1996-01-31  |  21KB  |  488 lines

  1. ; This is a Toolbar Actions file.  You add a line to your ACTIONS.LST:
  2. ;    makeactn
  3. ; to indicate that this should be invoked to build the list of defined
  4. ; actions when the user asks for a list.
  5.  
  6. const
  7.    WANT_DYNAMIC_PROMPTS = 1  -- Force definition of menu prompts in ENGLISH.E.
  8. include 'stdconst.e'
  9. include 'english.e'
  10.  
  11. const
  12.    makeactn_msgbox_title = 'Make Actions'
  13.    a_build_PROMPT = 'Creates a shell and start a build in it.'
  14.    a_build2_PROMPT = '  Parameters are a key name for the project, a path in which to start the build, and a command to start the build.  E.g.,  "projfoo d:\foo nmake -f foo.mak"'
  15.    a_makeme_PROMPT = 'Creates a shell and start a build of the current MAKE file in it.'
  16. ;  Following string too long for UCMENU support; gets truncated at '*'...
  17. ;  a_makeme2_PROMPT = '  Parameters are a key name for the project, a path in which to start the build (use "=" for path of cur. file), and a command to start the build.  Current filename will be appended to end of*command.'
  18.    a_makeme2_PROMPT = '  Parameters are a key name for the project, a path to start the build in (use "=" for path of cur. file), and a command to start the build.  Current filename will be appended to end of cmd.'
  19.    a_view_PROMPT = 'Parse the lines of the build shell and store the error information.'
  20.    a_view2_PROMPT = '  Optional parameter is the project''s key name; default is to extract it from the current'
  21.    a_view3_PROMPT = 'shell window.'
  22.    a_file3_PROMPT = 'file.'
  23. ;; a_next_err_PROMPT = 'Move to next compiler error'
  24. ;; a_prev_err_PROMPT = 'Move to previous compiler error'
  25.    a_descr_PROMPT = 'Display the current error.'
  26.  
  27. ; Here is the <file_name>_ACTIONLIST command that adds the action commands
  28. ; to the list.
  29.  
  30. defc makeactn_actionlist
  31.    universal ActionsList_FileID  -- This is the fileid that gets the lines
  32.  
  33.    insertline "makea_build"a_build_PROMPT || a_build2_PROMPT"makeactn", ActionsList_FileID.last+1, ActionsList_FileID
  34.    insertline "makea_makeme"a_makeme_PROMPT || a_makeme2_PROMPT"makeactn", ActionsList_FileID.last+1, ActionsList_FileID
  35.    insertline "makea_view_err"a_view_PROMPT || a_view2_PROMPT a_view3_PROMPT"makeactn", ActionsList_FileID.last+1, ActionsList_FileID
  36.    insertline "makea_next_err"NEXT_COMPILER_MENUP__MSG'.'a_view2_PROMPT a_file3_PROMPT"makeactn", ActionsList_FileID.last+1, ActionsList_FileID
  37.    insertline "makea_prev_err"PREV_COMPILER_MENUP__MSG'.'a_view2_PROMPT a_file3_PROMPT"makeactn", ActionsList_FileID.last+1, ActionsList_FileID
  38.    insertline "makea_curr_descr"a_descr_PROMPT || a_view2_PROMPT a_file3_PROMPT"makeactn", ActionsList_FileID.last+1, ActionsList_FileID
  39.  
  40. defc makea_build
  41.    makea_common_action(arg(1), 'MK_BUILD', a_build_PROMPT)
  42.  
  43. defc makea_makeme
  44.    parse arg action_letter index path build_command
  45.    if action_letter = 'I' then       -- button Initialized
  46.       display -8
  47.       sayerror a_makeme_PROMPT
  48.       display 8
  49.    elseif action_letter = 'S' then   -- button Selected
  50.       sayerror 0
  51.       if path='=' then
  52.          path = leftstr(.filename, lastpos('\', .filename)-1)
  53.       endif
  54.       'MK_BUILD' index path build_command .filename
  55.    elseif action_letter = 'H' then   -- button Help
  56.       call winmessagebox(makeactn_msgbox_title, a_makeme_PROMPT, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  57.    endif
  58.  
  59. defc makea_view_err
  60.    makea_common_action(arg(1), 'MK_VIEW_ERROR', a_view_PROMPT)
  61.  
  62. defc makea_next_err
  63.    makea_common_action(arg(1), 'MK_NEXT_ERR', substr(NEXT_COMPILER_MENUP__MSG, 2))
  64.  
  65. defc makea_prev_err
  66.    makea_common_action(arg(1), 'MK_PREV_ERR', substr(PREV_COMPILER_MENUP__MSG, 2))
  67.  
  68. defc makea_curr_descr
  69.    makea_common_action(arg(1), 'MK_CUR_DESCR', a_descr_PROMPT)
  70.  
  71. defproc makea_common_action(arg1, command, prompt)
  72.    parse value arg1 with action_letter parms
  73.    if action_letter = 'I' then       -- button Initialized
  74.       display -8
  75.       sayerror prompt
  76.       display 8
  77.    elseif action_letter = 'S' then   -- button Selected
  78.       sayerror 0
  79.       command parms
  80.    elseif action_letter = 'H' then   -- button Help
  81.       call winmessagebox(makeactn_msgbox_title, prompt, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  82. ;; elseif action_letter = 'E' then   -- button End
  83. ;;    sayerror 0
  84.    endif
  85.  
  86. -- Set of macros to build programs in the EPM shell
  87. -- and displaye the errors.
  88. -- for the users :
  89. --    mk_build
  90. --    mk_view_error
  91. --    mk_next_err
  92. --    mk_prev_err
  93. --    mk_cur_err
  94. --    mk_view_shell
  95. -- used internally only :
  96. --    mk_bringfile
  97. --    mk_parse_errline_default
  98. -- procedure used if defined by the user
  99. --    mk_parse_errline
  100.  
  101. ; Buildargs, saved in the build_array, indexed by the key, are:
  102. ;  parse value buildargs with build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  103. ; build_drive ('c:') the drive to switch to before doing the build
  104. ; build_dir ('c:\thisdir') the directory to switch to before doing the build
  105. ; build_shellid (1) the shell ID in which the builds for this index are being executed
  106. ; build_command ('nmake foo.mak') the command to execute to kick off the build
  107. ; build_cur_err (12) the current error number we're on in the build output
  108. ; build_start_line (123) the line number of the shell file on which the current build started
  109. ; build_number (1) the number of times we've run a build of this index in this window
  110. ; build_error_num (12) the number of errors found in the output of this build
  111.  
  112. const MK_ERROR_MARKTYPE = 5
  113.  
  114. ---------------------------------------------------------------------------------------
  115.  
  116. -- Proc called to try to extract error informations from a line
  117. -- It works for error lines generated by the IBM C/set++ compiler
  118. -- This procedure is called by default, but if mk_parse_errline is defined it is
  119. --  called instead of mk_parse_errline_default
  120. -- It allows the users to extract error informations for other compilers
  121. -- errorline : line to check for error informations
  122. -- error_level : 0 if the line contained no error information, 1 if Info; 2 if Warning;
  123. --               3 if Error; 4 if Severe Error; 5 if Fatal Error; 9 if looked like an error but we don't know which class
  124. -- FileName : name of the file where the error is
  125. -- LineNum : line of the error in the file
  126. -- ColumnNum : column of the error in the file
  127. -- ErrorMsg : message describing the error
  128. defproc mk_parse_errline_default( errorline, VAR FileName, VAR LineNum, VAR ColumnNum, VAR ErrorMsg, VAR error_level )
  129.    parse value errorline with Filename '(' LineNum ')'  ErrorMsg
  130.    parse value LineNum with LineNum ':' ColumnNum
  131.    if ColumnNum='' then
  132.       ColumnNum = 1
  133.    endif
  134.    if not ((FileName<>'' & isnum(LineNum) & isnum(ColumnNum) & ErrorMsg<>'')) then
  135.       error_level = 0
  136.       return
  137.    endif
  138.    if word(errorMsg, 1)=':' then
  139.         ErrorMsg = subword(ErrorMsg, 2)
  140.    endif
  141.    w1 = upcase(word(ErrorMsg, 1))
  142.    if abbrev('INFORMATIONAL', w1, 4) then
  143.       error_level = 1
  144.    elseif w1 = 'WARNING' then
  145.       error_level = 2
  146.    elseif w1 = 'ERROR' then
  147.       error_level = 3
  148.    elseif w1 = 'SEVERE' then
  149.       error_level = 4
  150.    elseif w1 = 'CRITICAL' | w1 = 'FATAL' then
  151.       error_level = 5
  152.    else
  153.       error_level = 9  -- Unknown ???
  154.    endif
  155.    return error_level
  156. ---------------------------------------------------------------------------------------
  157.  
  158. -- Brings a file to the edit window (load it if necessary)
  159. -- Sets up the error bookmarks if necessary
  160. defc mk_bringfile
  161.    parse arg myFileName build_drive build_dir build_number build_error_num Errors_array_ID index
  162.    getfileid myfileid, myFileName
  163.    dir = directory()
  164.    call directory( build_drive||build_dir )
  165.    'e 'myFilename
  166.    call directory( dir )
  167.    parse value .userstring with foo''file_build_number
  168.    if myfileid='' OR file_build_number<>build_number then
  169.       -- The file was not already loaded or the bookmarks are for a previous build
  170.       if myfileid<>'' then  -- Remove previous temp bookmarks
  171.          'deletebmclass' MK_ERROR_MARKTYPE
  172.       endif
  173.       -- set bookmarks
  174.       for i = 1 to build_error_num
  175.          do_array 3, Errors_array_id, i, Error_parms
  176. --       parse value Error_parms  with FileName''LineNum''ColumnNum''ErrorMsg''ShellLine
  177.          parse value Error_parms  with FileName''LineNum''ColumnNum''foo
  178.          if FileName = myFileName then
  179.             sayerror 'setting bookmark #'i
  180.             markname = 'Error_'index'_'i MK_ERROR_MARKTYPE LineNum ColumnNum
  181.             'setmark' markname
  182.          endif
  183.       endfor
  184.       -- set index
  185.       .userstring = index''build_number
  186.    endif
  187.  
  188. ---------------------------------------------------------------------------------------
  189.  
  190.  
  191. -- Creates a shell and start a build in it
  192. -- index     : name given to this build environment, used as a key ( eg projfoo )
  193. -- path      : path in which to start the build ( eg d:\foo )
  194. -- command   : command to start the build ( eg nmake -f foo.mak )
  195. defc MK_build
  196.    universal shell_index -- used to get the id of a created shell
  197.    universal Build_array_id
  198.    universal EPM_Utility_array_ID -- used to retrieve the fileid of a shell form its shellid
  199.    parse arg index path command
  200.    if command='' then
  201.       sayerror 'Missing required arguments.'
  202.       return
  203.    endif
  204.    -- if the array of build environments doesn't exist, create it
  205.    do_array 1, Build_array_id, "Build environments"
  206.    -- look if there is an entry for the given index
  207.    display -2
  208.    do_array 3, Build_array_id, index, buildargs
  209.    display 2
  210.    if buildargs='' then
  211.       -- if not do as if it was found (in both cases we'll save it after using it)
  212.       buildargs = '0'
  213.    endif
  214.  
  215.    parse value buildargs with build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  216.  
  217.    if path='=' then
  218.       path = leftstr(.filename, lastpos('\', .filename)-1)
  219.    endif
  220.  
  221. ;  if path <> '' then
  222.       parse value path with build_drive':'build_dir
  223.       build_drive = build_drive':'
  224. ;  endif
  225.  
  226. ;  if command <> '' then
  227.       build_command = command
  228. ;  endif
  229.  
  230.   -- Check if there is an active shell for this build env
  231.   display -2
  232.   do_array 3, EPM_Utility_array_ID, 'Shell_f'build_shellid, shell_fileid
  233.   rc = 0
  234.   activatefile shell_fileid
  235.   display 2
  236.    build_number = build_number + 1
  237.   if rc=-260 then
  238.      -- activatefile failed -> invalid fileid
  239.      'shell'
  240.      build_shellid = shell_index
  241.      .userstring = index''build_number -- store the build envir associated to this shell
  242.    endif
  243.    -- go to the chosen directory
  244.    'shell_write' build_shellid build_drive
  245.    'shell_write' build_shellid ' cd ' build_dir
  246.    -- save the shell line in which the build begins
  247.    do_array 3, EPM_Utility_array_ID, 'Shell_f'build_shellid, build_shell_fileid
  248.    build_start_line = build_shell_fileid.last
  249.    -- actually start the build
  250.    'shell_write' build_shellid build_command
  251.    -- save the build environment parameters
  252.    buildargs    = build_drive''build_dir''build_shellid''build_command''build_start_line''build_number''build_error_num
  253.    do_array 2, Build_array_id, index, buildargs
  254.    -- Erase any previous array of errors for this build environment.
  255.    Errors_array_name = 'Errors_'index
  256.    display -2
  257.    do_array 6, Errors_array_id, Errors_array_name
  258.    display 2
  259.    if Errors_array_id<>-1 then
  260.       -- Eradicate this array
  261.       getfileid startid
  262.       activatefile Errors_array_id
  263.       'xcom quit'
  264.       activatefile startid
  265.    endif
  266.  
  267.  
  268. ---------------------------------------------------------------------------------------
  269.  
  270. -- Used after mk_build has been called
  271. -- Parse the lines of the build shell and store the error informations
  272. -- If the cursor is on an error line, display this error
  273. -- Else display the first error
  274. -- If an argument is given, it must be the index of the build environment
  275. -- If no argument is given, the build environment is retrieved from the current file .userstring
  276. --  (-> it must have been loaded by the mk_* macros)
  277. defc MK_view_error
  278.    universal Build_array_id
  279.    universal EPM_Utility_array_ID
  280.  
  281.    -- save the current line
  282.    myline = .line
  283.    parse arg index
  284.    if index='' then
  285.       -- retrieve the environment index we stored in .userstring
  286.       parse value .userstring with index''foo
  287.    endif
  288.    if index='' then
  289.       sayerror 'MK_Build must be called before MK_View_Error.'
  290.       return
  291.    endif
  292.    -- get the environment informations
  293.    do_array 3, Build_array_id, index, buildargs
  294.    parse value buildargs with build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  295.    myerror_num = 0
  296.    ------------------------------------------------------------
  297.    -- If the errors array for this env doesn't exist, create it
  298.    ------------------------------------------------------------
  299.    Errors_array_name = 'Errors_'index
  300.    display -2
  301.    do_array 6, Errors_array_id, Errors_array_name
  302.    display 2
  303.    if Errors_array_id=-1 then
  304.       do_array 1, Errors_array_id, 'Errors_'index
  305.       build_error_num   = 0
  306.       do_array 3, EPM_Utility_array_id, 'Shell_f'build_shellid, build_shell_fileid
  307.       for line = build_start_line to build_shell_fileid.last
  308.          getline errorline, line, build_shell_fileid
  309.          if isadefproc( 'mk_parse_errline' ) then
  310.             call mk_parse_errline( errorline, FileName, LineNum, ColumnNum, ErrorMsg, error_level )
  311.          else
  312.             call mk_parse_errline_default( errorline, FileName, LineNum, ColumnNum, ErrorMsg, error_level )
  313.          endif
  314.          -- was it actually an error line?
  315.          if error_level then
  316.             build_error_num = build_error_num + 1
  317.             Error_parms = FileName''LineNum''ColumnNum''error_level''ErrorMsg''line
  318.             do_array 2, Errors_array_id,  build_error_num, Error_parms
  319.             if line=myline then
  320.                myerror_num = build_error_num
  321.                myErrormsg  = Errormsg
  322.                myfilename  = FileName
  323.             endif
  324.          endif
  325.       endfor
  326.    else
  327.       -- browse the array of errors to find our line
  328.       for i = 1 to build_error_num
  329.          do_array 3, Errors_array_id, i, Error_parms
  330.          parse value Error_parms with FileName''LineNum''ColumnNum''error_level''ErrorMsg''ShellLine
  331.          if ShellLine=myline then
  332.                myerror_num = i
  333.                myErrormsg  = Errormsg
  334.                myfilename  = FileName
  335.          endif
  336.       endfor
  337.    endif
  338.    ------------------------------------------------------------
  339.    -- End of errors array creation
  340.    ------------------------------------------------------------
  341.  
  342.    if myerror_num=0 then
  343.       -- The cursor was not on an error line, so display the first error
  344.       --  get MyFileName myerrornum and myerrormsg
  345.       myerror_num = 1
  346.       do_array 3, Errors_array_id,  myerror_num, Error_parms
  347.       parse value Error_parms with myFileName''myLineNum''myColumnNum''myErrorMsg''ShellLine
  348.    endif
  349.  
  350.  
  351.    'mk_bringfile' myFileName build_drive build_dir build_number build_error_num Errors_array_id index
  352.  
  353.    markname = 'Error_'index'_'myerror_num
  354.    'gomark'  markname
  355.    sayerror myErrormsg
  356.    -- set the current error in the environment array
  357.    build_cur_err = myerror_num
  358.    buildargs = build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  359.    do_array 2, Build_array_id, index, buildargs
  360.  
  361. ---------------------------------------------------------------------------------------
  362.  
  363. -- Used after mk_build and mk_view_error have been called
  364. -- Display the next error
  365. -- If an argument is given, it must be the index of the build environment
  366. -- If no argument is given, the build environment is retrieved from the current file .userstring
  367. --  (-> it must have been loaded by the mk_* macros)
  368. defc MK_next_err
  369.    universal Build_array_id
  370.  
  371.    parse arg index min_level
  372.    if index='' | index='=' then
  373.       -- retrieve the environment index we stored in .userstring
  374.       parse value .userstring with index''foo
  375.    endif
  376.    if index='' then
  377.       sayerror 'MK_Build and MK_View_Error must be called before MK_Next_Err.'
  378.       return
  379.    endif
  380.    do_array 3, Build_array_id, index, buildargs
  381.    parse value buildargs with build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  382.    do forever
  383.       build_cur_err = build_cur_err + 1
  384.       Errors_array_name = 'Errors_'index
  385.       do_array 6, Errors_array_id, Errors_array_name
  386.       do_array 3, Errors_array_id, build_cur_err, error_parms
  387.       parse value error_parms with FileName''line''column''error_level''Error_msg''ShellLine
  388.       if min_level = '' | error_parms = '' then
  389.          leave
  390.       endif
  391.       if error_level >= min_level then
  392.          leave
  393.       endif
  394.    enddo
  395.    if error_parms<>'' then
  396.       'mk_bringfile' FileName build_drive build_dir build_number build_error_num Errors_array_id index
  397.       markname = 'Error_'index'_'build_cur_err
  398.       'gomark'  markname
  399.       sayerror Error_msg
  400.       -- update build_cur_err
  401.       buildargs = build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  402.       do_array 2, Build_array_id, index, buildargs
  403.    else
  404.       sayerror ' ------- no more errors ---------- '
  405.    endif
  406.  
  407. ----------------------------------------------------------------------------------------------------
  408.  
  409. -- Used after mk_build and mk_view_error have been called
  410. -- Display the previous error
  411. -- If an argument is given, it must be the index of the build environment
  412. -- If no argument is given, the build environment is retrieved from the current file .userstring
  413. --  (-> it must have been loaded by the mk_* macros)
  414. defc MK_prev_err
  415.    universal Build_array_id
  416.  
  417.    parse arg index min_level
  418.    if index='' | index='=' then
  419.       -- retrieve the environment index we stored in .userstring
  420.       parse value .userstring with index''foo
  421.    endif
  422.    if index='' then
  423.       sayerror 'MK_Build and MK_View_Error must be called before MK_Prev_Err.'
  424.       return
  425.    endif
  426.    do_array 3, Build_array_id, index, buildargs
  427.    parse value buildargs with build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  428.    do forever
  429.       build_cur_err = build_cur_err - 1
  430.       Errors_array_name = 'Errors_'index
  431.       do_array 6, Errors_array_id, Errors_array_name
  432.       do_array 3, Errors_array_id, build_cur_err, error_parms
  433.       parse value error_parms with FileName''line''column''error_level''Error_msg''ShellLine
  434.       if min_level = '' | error_parms = '' then
  435.          leave
  436.       endif
  437.       if error_level >= min_level then
  438.          leave
  439.       endif
  440.    enddo
  441.    if error_parms<>'' then
  442.       'mk_bringfile' FileName build_drive build_dir build_number build_error_num Errors_array_id index
  443.       markname = 'Error_'index'_'build_cur_err
  444.       'gomark'  markname
  445.       sayerror Error_msg
  446.       -- update cur_err
  447.       buildargs = build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  448.       do_array 2, Build_array_id, index, buildargs
  449.    else
  450.       sayerror ' ------- no errors before ---------- '
  451.    endif
  452.  
  453. ----------------------------------------------------------------------------------------------------
  454.  
  455. -- Used after mk_build and mk_view_error have been called
  456. -- Display the current error
  457. -- If an argument is given, it must be the index of the build environment
  458. -- If no argument is given, the build environment is retrieved from the current file .userstring
  459. --  (-> it must have been loaded by the mk_* macros)
  460. defc MK_cur_descr
  461.    universal Build_array_id
  462.  
  463.    parse arg index min_level
  464.    if index='' | index='=' then
  465.       -- retrieve the environment index we stored in .userstring
  466.       parse value .userstring with index''foo
  467.    endif
  468.    if index='' then
  469.       sayerror 'MK_Build and MK_View_Error must be called before MK_Cur_Descr.'
  470.       return
  471.    endif
  472.    do_array 3, Build_array_id, index, buildargs
  473.    parse value buildargs with build_drive''build_dir''build_shellid''build_command''build_cur_err''build_start_line''build_number''build_error_num
  474.    Errors_array_name = 'Errors_'index
  475.    do_array 6, Errors_array_id, Errors_array_name
  476.    do_array 3, Errors_array_id, build_cur_err, error_parms
  477.    if error_parms<>'' then
  478.       parse value error_parms with FileName''line''column''error_level''Error_msg''ShellLine
  479.       'mk_bringfile' FileName build_drive build_dir build_number build_error_num Errors_array_id index
  480.       markname = 'Error_'index'_'build_cur_err
  481.       'gomark'  markname
  482.       sayerror Error_msg
  483.    else
  484.       sayerror ' ------- no current error ---------- '
  485.    endif
  486.  
  487. EA_comment 'This is a toolbar "actions" file which lets you run a MAKE in a shell and parse the output.'
  488.