/*********************************************************************
* 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:    Display PROGRESS Compiler error messages.

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

    Parameters:
        INPUT   p_Window        Handle of window to display alert-box in.
        INPUT   p_Error_File    Name of COMPILER:FILE-NAME (file with error).
        INPUT   p_Comp_File     Name of temporary compile file.
        
    Description:
        Currently, this routine displays the COMPILER error
        messages generated by a NO-ERROR statement (typically a
        COMPILE...NO-ERROR statement) in an Error Alert-Box.

        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: John Palazzo
    Create : June, 1994

    Updated: Sept, 1996 - John Palazzo
             Display all message including line number errors. However,
             when Section Editor is the caller, remove the line number
             from the message.
    Updated: May, 1995 - John Palazzo
             Display all messages except line number error messages.
**************************************************************************/

&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. */

&SCOPED-DEFINE MAX-DISPLAY  512
  /* Maximum characters to display in message box. Windows 3.1 maximum
     is used. */

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

DEFINE INPUT PARAMETER p_Window     AS WIDGET-HANDLE NO-UNDO.
DEFINE INPUT PARAMETER p_Error_File AS CHARACTER     NO-UNDO.
DEFINE INPUT PARAMETER p_Comp_File  AS CHARACTER     NO-UNDO.

DEFINE VARIABLE Error_Msg    AS CHARACTER     NO-UNDO.
DEFINE VARIABLE Error_Num    AS INTEGER       NO-UNDO.
DEFINE VARIABLE Error_File   AS CHARACTER     NO-UNDO.
DEFINE VARIABLE Num_Messages AS CHARACTER     NO-UNDO.
DEFINE VARIABLE Cur_Msg      AS CHARACTER     NO-UNDO.
DEFINE VARIABLE Line_Errors  AS CHARACTER     NO-UNDO.

DO ON STOP UNDO, LEAVE:
    IF NOT VALID-HANDLE( p_Window ) THEN
        ASSIGN p_Window = IF VALID-HANDLE(ACTIVE-WINDOW)
                          THEN ACTIVE-WINDOW
                          ELSE CURRENT-WINDOW.
    
    /* Display compiler messages. */
    DO Error_Num = 1 TO ERROR-STATUS:NUM-MESSAGES:

      ASSIGN Error_Msg = Error_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 Section Editor, remove line number from message if its not the
         same as the error number. We don't want to lose the error number. 
         Check on error-row is when the error is only a preprcessor message,
         in which case error-row is unknown (?) and we don't want to do
         the replace (message would be replaced with unknown). */
      IF (p_Window:NAME = "Section Editor") THEN
      DO:
         IF (COMPILER:ERROR-ROW <> ?) AND
         (COMPILER:ERROR-ROW <> ERROR-STATUS:GET-NUMBER(Error_Num)) THEN
         ASSIGN Cur_Msg = REPLACE(Cur_Msg, STRING(COMPILER:ERROR-ROW), "").
      END.
      
      ASSIGN Error_Msg = Error_Msg + Cur_Msg.
        
      IF LENGTH(Error_msg) > {&MAX-DISPLAY} THEN LEAVE.
    END.
        
    /* Get rid of the leading EOL. */
    ASSIGN Error_Msg   = TRIM( Error_Msg , CHR(10) ).
    IF Error_Msg <> "" THEN
    DO:
        RUN adecomm/_setcurs.p (INPUT "":U ).
        MESSAGE Error_Msg
            VIEW-AS ALERT-BOX ERROR IN WINDOW p_Window.
    END.
        
END. /* DO ON STOP */

