home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / wf_expl / parserr.c < prev    next >
Text File  |  1992-05-05  |  9KB  |  312 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* COPYRIGHT IBM CORP., 1992                                                */
  4. /*                                                                          */
  5. /****************************************************************************/
  6. #define INCL_PM
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <os2.h>
  11. #include <stdlib.h>
  12. #include <ctype.h>
  13. #include <sys\types.h>
  14. #include <sys\stat.h>
  15.  
  16. #define ERROR_CODE      1
  17. #define NO_ERROR_CODE   0
  18.  
  19. int splitLine(char *, char *,  int * );
  20.  
  21. int EXPENTRY ParseError(HWND    hwndErrorBox,
  22.                         USHORT *usStartline,
  23.                         USHORT *usEndline,
  24.                         HWND    hwndFilenames,
  25.                         USHORT *usCurrentFile,
  26.                         VOID   *pvCompilerOptions,
  27.                         ULONG  *pulAction)
  28.  
  29.    {
  30.  
  31.    typedef  union  _TAGPARAM
  32.       {
  33.       unsigned long  tagParam ;
  34.       struct
  35.          {
  36.          USHORT  errorLine  ;
  37.          char    offset     ;
  38.          char    fileNumber ;
  39.          } sub  ;
  40.       } TAGPARAM;
  41.  
  42.    TAGPARAM  mpParam;
  43.  
  44.    short sIndex , i , insertIndex ;
  45.    short sCount;
  46.    int   lineNumber;
  47.    char work[260+30];
  48.    char pszSourceFile[260+30];
  49.  
  50.  
  51.    /**************************************/
  52.    /* Get the index of the selected line */
  53.    /*     Currently, the selected line   */
  54.    /*     must be a valid line.          */
  55.    /**************************************/
  56.  
  57.    if ((sIndex= SHORT1FROMMR( WinSendMsg(hwndErrorBox,
  58.                               LM_QUERYSELECTION,
  59.                               (MPARAM)NULL,
  60.                               (MPARAM)NULL)))
  61.                  == LIT_NONE)
  62.       return ERROR_CODE;
  63.  
  64.  
  65.     /*********************************/
  66.     /* Get the total number of lines */
  67.     /*********************************/
  68.  
  69.     sCount= SHORT1FROMMR( WinSendMsg(hwndErrorBox,
  70.                           LM_QUERYITEMCOUNT,
  71.                           (MPARAM)NULL,
  72.                           (MPARAM)NULL));
  73.  
  74.  
  75.    /*****************************************/
  76.    /* With sIndex, we can retrieve the line */
  77.    /* the user selected, and pick up the    */
  78.    /* name of the file he is interested in. */
  79.    /*****************************************/
  80.  
  81.    WinSendMsg(hwndErrorBox,
  82.               LM_QUERYITEMTEXT,
  83.               MPFROM2SHORT(sIndex,sizeof(work)),
  84.               MPFROMP(work));
  85.  
  86.  
  87.    /**********************************************/
  88.    /* WindSendMsg has stored in 'work' the LIT   */
  89.    /* line. We will get the filename from 'work'.*/
  90.    /**********************************************/
  91.  
  92.    if ( splitLine(work,pszSourceFile,&lineNumber) )
  93.       return ERROR_CODE ;
  94.  
  95.  
  96.    insertIndex = SHORT1FROMMR(WinSendMsg(hwndFilenames,
  97.                                  LM_SEARCHSTRING,
  98.                                  MPFROM2SHORT(LSS_CASESENSITIVE,LIT_FIRST),
  99.                                  MPFROMP(pszSourceFile)));
  100.  
  101.  
  102.    if (insertIndex == LIT_ERROR)
  103.       return ERROR_CODE;
  104.  
  105.    if (insertIndex == LIT_NONE)
  106.        insertIndex = SHORT1FROMMR(WinSendMsg(hwndFilenames,
  107.                                   LM_INSERTITEM,
  108.                                   MPFROMSHORT(LIT_END),
  109.                                   (MPARAM)pszSourceFile));
  110.  
  111.  
  112.    /**************************************/
  113.    /* Set the tag for the selected line. */
  114.    /**************************************/
  115.  
  116.    mpParam.sub.errorLine   = lineNumber  ;
  117.    mpParam.sub.offset      = 0           ;
  118.    mpParam.sub.fileNumber  = *usCurrentFile = insertIndex ;
  119.  
  120.    WinSendMsg(hwndErrorBox,
  121.               LM_SETITEMHANDLE,
  122.               MPFROMSHORT(sIndex),
  123.               (MPARAM)(ULONG)(mpParam.tagParam));
  124.  
  125.  
  126.    *usStartline = i = sIndex ;
  127.  
  128.    while ( i-- > 0)
  129.       {
  130.       WinSendMsg(hwndErrorBox,
  131.                       LM_QUERYITEMTEXT,
  132.                       MPFROM2SHORT(i,sizeof(work)),
  133.                       MPFROMP(work));
  134.  
  135.       if ( splitLine(work,pszSourceFile,&lineNumber) )
  136.          {
  137.          ;
  138.          }
  139.       else
  140.          {
  141.          insertIndex = SHORT1FROMMR(WinSendMsg(hwndFilenames,
  142.                                        LM_SEARCHSTRING,
  143.                                        MPFROM2SHORT(LSS_CASESENSITIVE,LIT_FIRST),
  144.                                        MPFROMP(pszSourceFile)));
  145.  
  146.          if (insertIndex == LIT_ERROR)
  147.             return ERROR_CODE;
  148.  
  149.          if (insertIndex == LIT_NONE)
  150.              insertIndex = SHORT1FROMMR(WinSendMsg(hwndFilenames,
  151.                         LM_INSERTITEM,
  152.                         MPFROMSHORT(LIT_END),
  153.                         (MPARAM)pszSourceFile));
  154.  
  155.  
  156.          /**************************************/
  157.          /* Set the tag for the selected line. */
  158.          /**************************************/
  159.  
  160.          mpParam.sub.errorLine   = lineNumber  ;
  161.          mpParam.sub.offset      = 0           ;
  162.          mpParam.sub.fileNumber  = insertIndex ;
  163.  
  164.          WinSendMsg(hwndErrorBox,
  165.                     LM_SETITEMHANDLE,
  166.                     MPFROMSHORT(i),
  167.                     (MPARAM)(ULONG)(mpParam.tagParam));
  168.  
  169.          }
  170.  
  171.       *usStartline = i;
  172.       }
  173.  
  174.  
  175.    /*******************************************/
  176.    /* Scan from 'LIT' line + 1 and down for   */
  177.    /* all interested lines.                   */
  178.    /*******************************************/
  179.  
  180.    *usEndline = i = sIndex ;
  181.  
  182.    while (i++ < sCount)
  183.       {
  184.       WinSendMsg(hwndErrorBox,
  185.                       LM_QUERYITEMTEXT,
  186.                       MPFROM2SHORT(i,sizeof(work)),
  187.                       MPFROMP(work));
  188.  
  189.       if ( splitLine(work,pszSourceFile,&lineNumber) )
  190.          {
  191.          ;
  192.          }
  193.       else
  194.          {
  195.          insertIndex = SHORT1FROMMR(WinSendMsg(hwndFilenames,
  196.                                        LM_SEARCHSTRING,
  197.                                        MPFROM2SHORT(LSS_CASESENSITIVE,LIT_FIRST),
  198.                                        MPFROMP(pszSourceFile)));
  199.  
  200.          if (insertIndex == LIT_ERROR)
  201.             return ERROR_CODE;
  202.  
  203.          if (insertIndex == LIT_NONE)
  204.              insertIndex = SHORT1FROMMR(WinSendMsg(hwndFilenames,
  205.                         LM_INSERTITEM,
  206.                         MPFROMSHORT(LIT_END),
  207.                         (MPARAM)pszSourceFile));
  208.  
  209.  
  210.          /**************************************/
  211.          /* Set the tag for the selected line. */
  212.          /**************************************/
  213.  
  214.          mpParam.sub.errorLine   = lineNumber  ;
  215.          mpParam.sub.offset      = 0           ;
  216.          mpParam.sub.fileNumber  = insertIndex ;
  217.  
  218.          WinSendMsg(hwndErrorBox,
  219.                     LM_SETITEMHANDLE,
  220.                     MPFROMSHORT(i),
  221.                     (MPARAM)(ULONG)(mpParam.tagParam));
  222.  
  223.          }
  224.  
  225.       *usEndline = i;
  226.       }
  227.  
  228.    return NO_ERROR_CODE;
  229.    }
  230.  
  231.  
  232.            /****************************************/
  233.            /*               splitLine              */
  234.            /*                                      */
  235.            /* Takes an input line and returns the  */
  236.            /* filename for the line as well as its */
  237.            /* line number.                         */
  238.            /****************************************/
  239.  
  240. int splitLine(char * inputLine , char * fileName ,  int * lineNumber)
  241.    {
  242.    char *s , *s2 , *temp;
  243.    struct stat buf;
  244.  
  245.    /* Scanning for the Left Paranthesis: */
  246.  
  247.    if ((s = strchr(inputLine,'(')) == NULL)
  248.       return ERROR_CODE ;
  249.  
  250.    if (s == inputLine)       /* Check if line starts with '(' */
  251.       return ERROR_CODE ;
  252.  
  253.    *s = '\0' ;
  254.  
  255.    strcpy(fileName,inputLine) ;
  256.  
  257.    *s++ = '(' ;               /* Restore char to the original value */
  258.  
  259.  
  260.    /****************************/
  261.    /* Check filename is valid. */
  262.    /****************************/
  263.  
  264.  
  265.    if ( stat(fileName, &buf) )         /* Must be able to get file info */
  266.       return ERROR_CODE ;
  267.  
  268.    if ( ! (buf.st_mode &  S_IFREG) )   /* Must be a regukar file */
  269.       return ERROR_CODE ;
  270.  
  271.    /* Scanning for the Right Paranthesis: */
  272.  
  273.    if ((s2 = strchr(s,')')) == NULL)
  274.       return ERROR_CODE ;
  275.  
  276.    /* Check that there is a ':' right of the ')' */
  277.  
  278.    if ((temp = strchr(s2,':')) == NULL)
  279.       return ERROR_CODE ;
  280.  
  281.    *s2 = '\0' ;
  282.  
  283.    /***********************************/
  284.    /* Check if the string is a string */
  285.    /* of all numbers, and it is less  */
  286.    /* than 6 digits in length.        */
  287.    /***********************************/
  288.  
  289.    temp = s ;
  290.  
  291.    /***********************************/
  292.    /* A simple test to see that all   */
  293.    /* characters between '(' and ')'  */
  294.    /* are digits or spaces.           */
  295.    /***********************************/
  296.  
  297.    while ( *temp )
  298.       {
  299.       if ( ! isdigit(*temp)  && !isspace(*temp)  )
  300.          return ERROR_CODE ;
  301.       ++temp;
  302.       }
  303.  
  304.    *lineNumber = atoi(s) ;
  305.  
  306.    *s2 = ')' ;           /* Restore char to the original value */
  307.  
  308.    return NO_ERROR_CODE ;
  309.    }
  310.  
  311.  
  312.