home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / ERRPARSE.E < prev    next >
Text File  |  1992-08-26  |  11KB  |  233 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*  I took ERRPARSE.E from E3 PROCS, made a few optimizations, then added   */
  4. /*  a CL command to call the OS/2 Compile/Link program from within EOS2 and */
  5. /*  show the user all errors, if there were any.  I also changed the        */
  6. /*  comments on the error lines from "/*=====> Error message <=====*/" to   */
  7. /*  "/*====> Error message <====*/", since I liked having the downwards-  */
  8. /*  pointing arrows to remind me that the error message referred to the     */
  9. /*  line below the message.                                                 */
  10. /*                                                                          */
  11. /*                        Larry Margolis                                    */
  12. /*                                                                          */
  13. /****************************************************************************/
  14. /*                                                                          */
  15. /*  ERRPARSE.E  - A C error parser.                                         */
  16. /*    by Steven Christensen                                                 */
  17. /*                                                                          */
  18. /*    If you are like me, while developing a C program, it is sometimes     */
  19. /*    difficult to relate the IBM C compiler's messages to the error.       */
  20. /*    Often they scroll past the screen, or if you put them in a file,      */
  21. /*    you must jump back and forth and search for that particular line      */
  22. /*    number.                                                               */
  23. /*                                                                          */
  24. /*  [enter ERRPARSE]                                                        */
  25. /*                                                                          */
  26. /*    But no more!  ERRPARSE.E will take the file of errors (generated      */
  27. /*    by directing output to the file <sourcename>.ERR) and construct a     */
  28. /*    C comment, and insert it before the error in the source file.         */
  29. /*                                                                          */
  30. /*    You can then use the Ctrl-N key to go to the Next error, and          */
  31. /*    all the while correcting errors as you go.                            */
  32. /*                                                                          */
  33. /*    When you are done correcting, you type a Ctrl-O to Obliterate the     */
  34. /*    error comments from the source before saving your file.               */
  35. /*                                                                          */
  36. /*    If you happen to forget to delete the error lines, no problem, since  */
  37. /*    they are C comments, the compiler will ignore them!                   */
  38. /*                                                                          */
  39. /*    To use: When you compile your program "file.c", direct the output to  */
  40. /*            a file "file.err". You then use E to edit the source file,    */
  41. /*            and at the command line type Alt-Q. Typing Ctrl-N passes you  */
  42. /*            to the Next error, while Ctrl-O removes the error comments.   */
  43. /*            You can also invoke the parser from the DOS command line by:  */
  44. /*              e file.c 'errparse'                                         */
  45. /*                                                                          */
  46. /*    Known restrictions: There is one - your source file cannot contain    */
  47. /*    comment lines that begin with the C comment start plus "=====> "      */
  48. /*    in column one. The Ctrl-O will delete them.                           */
  49. /*                                                                          */
  50. /*    Installation: Put the line "include 'errparse.e' in MYKEYS.E          */
  51. /*                                                                          */
  52. /*    Change History (most recent first):                                   */
  53. /*    ==================================                                    */
  54. /*      8-19-88 - Now correctly parses files made by the OS/2 command       */
  55. /*          "cc filename.c 2> filename.err" (i.e. with IBM C header)        */
  56. /*                                                                          */
  57. /****************************************************************************/
  58.  
  59. compile if not defined(EPM)
  60.    include 'stdconst.e'
  61. compile endif
  62.  
  63. compile if EPM
  64. definit
  65.    universal activemenu,defaultmenu
  66. ;  'loaddefaultmenu C_menu'
  67.    buildsubmenu defaultmenu, 19, 'Compile', '', 0 , 0
  68.      buildmenuitem defaultmenu, 19, 1900, 'Compile',                         'CC',    0, 0
  69.      buildmenuitem defaultmenu, 19, 1901, 'Compile & Link',                  'CL',    0, 0
  70.      buildmenuitem defaultmenu, 19, 1902, 'Make',                            'MAKE',  0, 16384
  71.      buildmenuitem defaultmenu, 19, 1903, \0,                                '',      4, 0
  72.      buildmenuitem defaultmenu, 19, 1904, 'Find Next Error'\9'Ctrl+N',       'EPNEXT',0, 0
  73.      buildmenuitem defaultmenu, 19, 1905, 'Obliterate Error Msgs'\9'Ctrl+O', 'EOBLIT',0, 0
  74.    if activemenu=defaultmenu then showmenu activemenu; endif
  75.  
  76. defselect
  77.    universal activemenu, defaultmenu
  78.  
  79.    ft = filetype()
  80.    SetMenuAttribute( 19, 16384, (ft = 'C' or ft = 'MAK'))
  81.    if activemenu=defaultmenu then showmenu activemenu; endif
  82.  
  83. ;defselect
  84. ;   universal activemenu,defaultmenu
  85. ;   ft = filetype()
  86. ;   if (ft = 'C' or ft = 'MAK') & activemenu <> 'C_menu'  then
  87. ;      activemenu = 'C_menu'
  88. ;      showmenu activemenu
  89. ;   elseif activemenu = 'C_menu' then
  90. ;      activemenu = defaultmenu        /* show the default EPM menu           */
  91. ;      showmenu activemenu
  92. ;   endif
  93.  
  94. compile endif
  95.  
  96. defc cl= call cl('CL',arg(1))
  97. defc cc= call cl('CC',arg(1))
  98. defproc cl=
  99.    universal vTEMP_PATH
  100.    cl=arg(1)
  101.    infile=arg(2)
  102.    if infile='' then
  103.       infile=.filename
  104.       old_mod = .modify
  105.       'Eoblit'               -- Delete error messages from last time, if any.
  106.       if old_mod then 'save'; endif
  107.    else
  108.       if not exist(infile) then
  109.          sayerror 'Source file' infile 'not found.'
  110.          return
  111.       endif
  112.    endif
  113. compile if EPM  -- Open a new edit window, execute the command, and edit the output.
  114.    'open "clopen 'cl infile'"'
  115.  
  116. defc clopen =
  117.    universal vTEMP_PATH
  118.    parse arg cl infile
  119.                -- Note:  2>&1 redirects STDERR to same place as STDOUT for OS/2.
  120.    quietshell 'dos 'cl infile' >'vTEMP_PATH'CL'getpminfo(5)'.ERR 2>&1'
  121. compile else
  122.    sayerror 'Compiling'
  123.    quietshell 'dos 'cl infile' >'vTEMP_PATH'cl.err 2>&1'
  124. compile endif
  125.    if rc=(-2) then
  126.       sayerror CL'.Exe not found'
  127.       return
  128.    endif
  129.    if rc then
  130.       orc = rc
  131.       'errparse'
  132.       if orc=2 then
  133.          0
  134.          'EPnext'         -- Position at first error
  135.       else
  136.          sayerror 'RC was 'orc
  137.       endif
  138.    else
  139.       if cl='CL' then  -- For CL can erase object file.  Not for CC!
  140.          indx = lastpos('\',infile)
  141.          if not indx then indx = lastpos(':',infile) endif
  142.          if indx then infile=substr(infile,indx+1) endif
  143.          indx = pos('.',infile)
  144.          if indx then infile=substr(infile,1,indx-1) endif
  145.          call erasetemp(infile'.obj')    -- Link succeeded; don't need .obj file.
  146.       endif
  147.       sayerror 'Compilation of 'infile' completed successfully.'
  148. compile if EPM
  149.       'xcom q'
  150. compile endif
  151.    endif
  152.  
  153. defc errparse =             /* put error messages in the source file */
  154.    universal vTEMP_PATH
  155. compile if EPM
  156.     'xcom e /d 'vTEMP_PATH'cl'getpminfo(5)'.err'      /* edit the error file */
  157. compile else
  158.     sayerror 'Parsing errors.'
  159.     'xcom e /d 'vTEMP_PATH'cl.err'      /* edit the error file */
  160. compile endif
  161.     getfileid fileid                    /* save the file ID */
  162.     done=0
  163.     while fileid.last>0 do              /* start putting the errors in */
  164.                                         /* start at bottom so line numbers are OK */
  165.         getline temp,fileid.last,fileid
  166.         parse value temp with filename '(' linenum ') :' message
  167.         if linenum = '' then            /* if there is a strange line, */
  168.             leave                       /* stop processing here */
  169.                                         /* (we reached the compiler banner) */
  170.         else
  171.             'xcom e 'filename
  172.             insertline '/*====> 'message' <====*/',linenum
  173.             deleteline fileid.last,fileid
  174.             done=1                      -- Set flag saying we've seen an error.
  175.         endif
  176.     endwhile
  177.     activatefile fileid
  178.     .modify = 0                         /* to quit the file */
  179.     if not done then         -- No error messages found.  Must be:
  180.        sayerror temp         -- 'File not found', linker error or some such.
  181.     else
  182.        'xcom q'              -- Don't need error file any more.
  183.        sayerror 'Press C_N to find Next error; C_O to Obliterate ===> lines.'
  184.     endif
  185.  
  186. defc EPNext=
  187.  compile if not EPM
  188.     cursor_data
  189.  compile endif
  190.     unmark
  191.     getsearch old_search
  192.     'xcom l ./*====> .'                /* find special comments */
  193.     if rc <> 0 then
  194.         sayerror 'No more errors found.'
  195.     else
  196.         refresh
  197.         mark_block                      /* hilite errors */
  198.         end_line
  199.         mark_block
  200.         begin_line
  201.         '+1'
  202.     endif
  203.     setsearch old_search
  204.  
  205. defc Eoblit=
  206. compile if not EPM
  207.     sayerror 'Removing errors.'
  208. compile endif
  209. ;   unmark                  /* get rid of marks */     -- Why?  LAM
  210.     startline = .line
  211.     0
  212.     getsearch old_search
  213.     'xcom l ./*====> .'    /* look for comment header */
  214.     do forever
  215.         if rc <> 0 then sayerror 1; leave; endif  /* no more errors */
  216.         if .col = 1 then    /* the error must start in column one */
  217.             deleteline
  218.             if .line < startline then startline=startline-1; endif
  219.         else
  220.             '+1'
  221.         endif
  222.         repeatfind
  223.     end
  224.     setsearch old_search
  225.     startline
  226.     sayerror 'Error messages removed.'
  227.  
  228. ; def a_q ='errparse'     /* Errparse the file */
  229. def c_n ='EPNext'       /* define Ctrl-N to find next error */
  230. def c_o ='Eoblit'       /* Obliterate errors */
  231.  
  232. /*  End of ERRPARSE.E  */
  233.