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