home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / iwftech.zip / samples / SOMopt / somparse.c < prev    next >
Text File  |  1994-07-21  |  10KB  |  240 lines

  1. /*+--------------------------------------------------------------------------+*/
  2. /*| SOMOPT - WorkFrame/2-enabled SOM actions support (Options DLL)           |*/
  3. /*|--------------------------------------------------------------------------|*/
  4. /*|                                                                          |*/
  5. /*| PROGRAM NAME: SOMOPT                                                     |*/
  6. /*| -------------                                                            |*/
  7. /*|                                                                          |*/
  8. /*| COPYRIGHT:                                                               |*/
  9. /*| ----------                                                               |*/
  10. /*| Copyright (C) International Business Machines Corp., 1991,1992,1993,1994 |*/
  11. /*|                                                                          |*/
  12. /*| DISCLAIMER OF WARRANTIES:                                                |*/
  13. /*| -------------------------                                                |*/
  14. /*| The following [enclosed] code is sample code created by IBM              |*/
  15. /*| Corporation.  This sample code is not part of any standard IBM product   |*/
  16. /*| and is provided to you solely for the purpose of assisting you in the    |*/
  17. /*| development of your applications.  The code is provided "AS IS",         |*/
  18. /*| without warranty of any kind.  IBM shall not be liable for any damages   |*/
  19. /*| arising out of your use of the sample code, even if they have been       |*/
  20. /*| advised of the possibility of such damages.                              |*/
  21. /*|                                                                          |*/
  22. /*| REVISION LEVEL: 2.1                                                      |*/
  23. /*| -------------------                                                      |*/
  24. /*|                                                                          |*/
  25. /*| This program demonstrates providing WorkFrame/2 actions support (i.e.    |*/
  26. /*| Options DLL) for the SOM compiler.                                       |*/
  27. /*+--------------------------------------------------------------------------+*/
  28.  
  29. #define INCL_PM
  30. #define INCL_WIN
  31. #define INCL_DOS
  32. #define INCL_DOSERRORS
  33. #include <os2.h>
  34.  
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38.  
  39. #define  INCL_WKFOPT
  40. #include <wkf.h>
  41.  
  42. #include "somopt.h"
  43.  
  44. static APIRET ProcessLine( HWND hwndErrorBox,
  45.                            HWND hwndFileNames,
  46.                            USHORT Index,
  47.                            USHORT *pusInsertedAt );
  48.  
  49.  
  50. /******************************************************************************/
  51. /*                                                                            */
  52. /* FUNCTION: deflparParseError                                                */
  53. /*                                                                            */
  54. /*  The entrypoint             in the Compiler Options DLL is invoked during  */
  55. /*  processing of the output of a Compile, Make or Build operation.           */
  56. /*  The interface is provided with a line of output form the compiler         */
  57. /*  and is expected to return the filename, line number, and column number    */
  58. /*  associated with the error message on that line.                           */
  59. /*                                                                            */
  60. /*   Inputs:                                                                  */
  61. /*                                                                            */
  62. /*     HWND    - window handle of the error message listbox                   */
  63. /*     PUSHORT - pointer to first line containing an error message            */
  64. /*               in listbox                                                   */
  65. /*     PUSHORT - pointer to last line containing an error message             */
  66. /*     HWND    - window handle of listbox to insert filenames into            */
  67. /*     PUSHORT - index of selected filename in filename listbox               */
  68. /*     PVOID   - pointer to area containing options                           */
  69. /*     PULONG  - validity of options (initialized or not)                     */
  70. /*                                                                            */
  71. /*   Returns:    0 if successful, 1 if cancel selected, 2 if error            */
  72. /******************************************************************************/
  73.  
  74. extern ULONG APIENTRY WKFCOMPILEPARSEERROR( HWND     hwndErrorBox,
  75.                                             PSZ      pszProject,
  76.                                             USHORT * pusStartLine,
  77.                                             USHORT * pusEndLine,
  78.                                             HWND     hwndFileNames,
  79.                                             USHORT * pusCurrentFile,
  80.                                             VOID   * pvOptions,
  81.                                             ULONG  * pulSetting )
  82. {
  83.    APIRET         rc;
  84.  
  85.    short          sIndex, i;
  86.    short          sCount;
  87.    USHORT         usInsertIndex;
  88.  
  89.  
  90.    /**************************************/
  91.    /* Get the index of the selected line */
  92.    /**************************************/
  93.    sIndex = WinQueryLboxSelectedItem( hwndErrorBox );
  94.    if( sIndex == LIT_NONE )
  95.       return WKFRC_PARSEERROR_ERROR;
  96.  
  97.    /*********************************/
  98.    /* Get the total number of lines */
  99.    /*********************************/
  100.    sCount = WinQueryLboxCount( hwndErrorBox );
  101.  
  102.    rc = ProcessLine( hwndErrorBox,
  103.                      hwndFileNames,
  104.                      sIndex,
  105.                      pusCurrentFile );
  106.    if( rc )
  107.       return( WKFRC_PARSEERROR_INVALID );
  108.  
  109.    i = sIndex ;
  110.  
  111.    *pusStartLine = 1;                     /* we will be processing all of list */
  112.    *pusEndLine = sCount;
  113.  
  114.    /**************************************/
  115.    /* Now, scan backwards from the       */
  116.    /* selected line, and collect info    */
  117.    /* about ALL errors that occurred.    */
  118.    /* (line numbers and file names)      */
  119.    /**************************************/
  120.  
  121.    while ( --i > 0)
  122.    {
  123.       rc = ProcessLine( hwndErrorBox,
  124.                         hwndFileNames,
  125.                         i,
  126.                        &usInsertIndex );  /* Not needed here, just a place holder */
  127.  
  128.       if( rc & rc != WKFRC_PARSEERROR_INVALID )
  129.          return( rc );
  130.    }
  131.  
  132.    /*******************************************/
  133.    /* Scan from 'LIT' line + 1 and forwards   */
  134.    /* for all interesting lines.              */
  135.    /*******************************************/
  136.  
  137.    i = sIndex ;
  138.  
  139.    while (++i < sCount)
  140.    {
  141.       rc = ProcessLine( hwndErrorBox,
  142.                         hwndFileNames,
  143.                         i,
  144.                        &usInsertIndex );  /* Not needed here, just a place holder */
  145.  
  146.       if( rc & rc != WKFRC_PARSEERROR_INVALID )
  147.          return( rc );
  148.    }
  149.  
  150.    return( WKFRC_PARSEERROR_SUCCESS ); 
  151. }
  152.  
  153.  
  154.  
  155. static APIRET ProcessLine( HWND hwndErrorBox,
  156.                            HWND hwndFileNames,
  157.                            USHORT Index,
  158.                            USHORT *pusInsertedAt )
  159. {
  160.    WKF_TAGPARAM   mpParam;
  161.    char           szBuffer[CCHMAXPATH];
  162.    char           pszMessage[CCHMAXPATH];
  163.    char           pszFilename[CCHMAXPATH];
  164.    int            LineNumber;
  165.    short          insertIndex;
  166.    int            matched;
  167.  
  168.    /*****************************************/
  169.    /* With Index, we can retrieve the line  */
  170.    /* the user selected, and pick up the    */
  171.    /* name of the file he is interested in. */
  172.    /*****************************************/
  173.    WinQueryLboxItemText( hwndErrorBox, 
  174.                          Index, 
  175.                          szBuffer, 
  176.                          sizeof(szBuffer) );
  177.  
  178.  
  179.    /**********************************************/
  180.    /*   Now we actually parse the line.  This    */
  181.    /*   example is hardcoded for the format of   */
  182.    /*   the SOM compiler.  You can either        */
  183.    /*   adjust the format to match the messages  */
  184.    /*   you expect to parse, or develop a        */
  185.    /*   generic pattern matching routine.        */
  186.    /*                                            */
  187.    /*   The following matches lines in the form: */
  188.    /*    "som1.csc": 22: Error in pre-processor  */
  189.    /**********************************************/
  190.    memset( pszFilename, 0, sizeof( pszFilename ) );
  191.    memset( pszMessage, 0, sizeof( pszMessage ) );
  192.  
  193.    matched = sscanf( szBuffer,
  194.                      "\"%[^\"]\": %d: %[^\n]",
  195.                      pszFilename, 
  196.                     &LineNumber, 
  197.                      pszMessage );
  198.  
  199.    if( matched != 3 )
  200.       return WKFRC_PARSEERROR_INVALID;
  201.  
  202.    /**********************************************/
  203.    /* Has this filename been inserted into the   */
  204.    /* filename box yet?                          */
  205.    /**********************************************/
  206.    insertIndex = SHORT1FROMMR( WinSendMsg(hwndFileNames,
  207.                                LM_SEARCHSTRING,
  208.                                MPFROM2SHORT(LSS_CASESENSITIVE,LIT_FIRST),
  209.                                MPFROMP( pszFilename )));
  210.  
  211.    if( insertIndex == LIT_ERROR )
  212.       return WKFRC_PARSEERROR_ERROR;
  213.  
  214.    /************************************************/
  215.    /*      Add the file name to the list box       */
  216.    /************************************************/
  217.    if( insertIndex == LIT_NONE )
  218.       insertIndex = WinInsertLboxItem( hwndFileNames, 
  219.                                        LIT_END, 
  220.                                        pszFilename );
  221.  
  222.  
  223.    /**************************************/
  224.    /* Set the tag for the selected line. */
  225.    /* Offset starts at zero.             */
  226.    /**************************************/
  227.    mpParam.sub.errorLine   = LineNumber;
  228.    mpParam.sub.offset      = 0;
  229.    mpParam.sub.fileNumber  = (char) (*pusInsertedAt = insertIndex) ;
  230.  
  231.    WinSendMsg( hwndErrorBox,
  232.                LM_SETITEMHANDLE,
  233.                MPFROMSHORT(Index),
  234.                (MPARAM)(mpParam.tagParam) );
  235.  
  236.    return WKFRC_PARSEERROR_SUCCESS;
  237. }
  238.  
  239.   
  240.