/*********************************************************************
* Copyright (C) 2000 by Progress Software Corporation ("PSC"),       *
* 14 Oak Park, Bedford, MA 01730, and other contributors as listed   *
* below.  All Rights Reserved.                                       *
*                                                                    *
* The Initial Developer of the Original Code is PSC.  The Original   *
* Code is Progress IDE code released to open source December 1, 2000.*
*                                                                    *
* The contents of this file are subject to the Possenet Public       *
* License Version 1.0 (the "License"); you may not use this file     *
* except in compliance with the License.  A copy of the License is   *
* available as of the date of this notice at                         *
* http://www.possenet.org/license.html                               *
*                                                                    *
* Software distributed under the License is distributed on an "AS IS"*
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. You*
* should refer to the License for the specific language governing    *
* rights and limitations under the License.                          *
*                                                                    *
* Contributors:                                                      *
*                                                                    *
*********************************************************************/
/**************************************************************************
    Procedure:  _errmsgs.p
    
    Purpose:    Places PROGRESS Compiler error messages in the global
                _err_msg variable..

    Syntax :    RUN adecomm/_errmsgs.p (INPUT p_Comp_File, INPUT p_options).

    Parameters:
        INPUT   p_Comp_File     Name of temporary compile file.
        INPUT   p_Options       Comma-delimited list of Options
                  "Line-Numbers" -- show line numbers
        
    Description:
        Currently, this routine takes the the COMPILER error
        messages generated by a NO-ERROR statement (typically a
        COMPILE...NO-ERROR statement) and places them in a
        _err_msg variable.

        You must be careful here, if you have a COMPILE..NO-ERROR you
        want to check but your code uses a NO-ERROR statement between
        the COMPILE and the call to this routine, you'll get
        "erroneous" error messages displayed, if any at all.

    Authors: Bill Wood [From original adecomm/_errmsgs.p by John Palazzo]
    Create : March 7, 1997
**************************************************************************/
DEFINE INPUT PARAMETER p_Comp_File  AS CHARACTER     NO-UNDO.
DEFINE INPUT PARAMETER p_Options    AS CHARACTER     NO-UNDO.

&SCOPED-DEFINE PP-4345      4345    
  /* PROGRESS Preprocessor system message number. When we find this number,
     we do not remove the file name from the message. This allows the use
     of &MESSAGE {&FILE-NAME} to work. */


/* PROGRESS 4GL Compiler Messages that contain line numbers.
   I found these by searching the files in DLC\prohelp\msgdata
   for "line <number>". There are more, but we only want to exclude
   the ones that just mention "Could not understand Line <number>."
*/
&SCOPED-DEFINE CM-LINE      "193,196,198"

&SCOPED-DEFINE EOL          CHR(10)              
  /* End of Line character. Progress ensures this for all opsys. */


/* Include files */
{ workshop/sharvars.i }    /* Shared variables                               */

/* Local variables */
DEFINE VARIABLE Cur_Msg      AS CHARACTER     NO-UNDO.
DEFINE VARIABLE Error_Num      AS INTEGER       NO-UNDO.
DEFINE VARIABLE l_line-nums  AS LOGICAL       NO-UNDO.

/* Initialize the global variables. */
ASSIGN _err_msg = "".    
/* Initialize options */
ASSIGN l_line-nums = LOOKUP("line-numbers":U, p_options) > 0.   
  
/* Display compiler messages. */
DO Error_Num = 1 TO ERROR-STATUS:NUM-MESSAGES:

  /* Skip over line-numbers errors. */
  IF NOT (l_line-nums eq no AND
          CAN-DO ( {&CM-LINE}, STRING(ERROR-STATUS:GET-NUMBER( Error_Num )) ))
  THEN DO:

    ASSIGN _err_msg = _err_msg + {&EOL}.
    
    /* If the current message is not a PROGRESS Preprocessor message,
       remove the tempfile name. Otherwise, leave it, because the user
       may be trying to display the file name during preprocessing
       using {&FILE-NAME}.
    */
    ASSIGN Cur_Msg = ERROR-STATUS:GET-MESSAGE( Error_Num ).
    IF ERROR-STATUS:GET-NUMBER( Error_Num ) <> {&PP-4345} THEN
      ASSIGN Cur_Msg = REPLACE( Cur_Msg , p_Comp_File , "" ) .
  
    /* If desired, remove line number from message if its not the
       same as the error number. We don't want to lose the error number. */
    IF (l_line-nums eq no) AND
       (COMPILER:ERROR-ROW <> ERROR-STATUS:GET-NUMBER(Error_Num)) 
    THEN Cur_Msg = REPLACE(Cur_Msg, STRING(COMPILER:ERROR-ROW), "").
  
    /* Append the errors. */
    _err_msg = _err_msg + Cur_Msg.
  END. /* IF l_line-nums... */
END.
    
/* Get rid of the leading EOL. */
ASSIGN _err_msg = TRIM(_err_msg).

RETURN.

/* 
 * -- End of file --
 */
 
