[comp.os.vms] TIP: Using the Message Utility with PASCAL

W_COSTA@UNHH.BITNET (11/04/87)

Hello Netlanders...

    I wanted to use the Message Utility with my VAX Pascal programs.
    Unfortunately there does not appear to be any way of declaring external
    constants in VAX Pascal.  This means that you would have to hand-code
    the "condition codes" values found in the Message Utility listing of
    your message file into your Pascal program.  Uck! However, I think I've
    worked out what I think is a better way. The trick is to declare some
    [EXTERNAL] variables with the same name as the condition code symbols
    that you defined in your message file.  These variables will contain
    nothing (and thus waste a little space), but they will be recognized by
    the linker as being the same as the symbols defined in the message OBJ
    file.

    Now, when you want to use the condition code represented by one of
    these 'variables', you simply pass the address of the variable to the
    routine that needs it. For example:

     In the EX_MESSAGES.MSG file we have...
    +---------------------------------------------------------------
    |.FACILITY       EX,1/PREFIX=EX_
    |
    |.SEVERITY       SUCCESS
    |                Mess1           <Here is the first message.>
    |                 :                   :
    |                 :                   :

    Of course the command:

        $ MESSAGE EX_MESSAGES/LIST

    will create the OBJ file containing the symbol "EX_Mess1" with it's
    associated condition value.  As I've said, we could look at the listing
    file to find out what that value is and code it into our program - OR -
    we could:

     In EXAMPLE.PAS
    +----------------------------------------------------------------
    |
    | VAR
    |     EX_Mess1   : [EXTERNAL,VOLATILE] UNSIGNED;
    |        :            :
    |        :            :
    |
    | BEGIN
    |         :
    |        LIB$SIGNAL(IADDRESS(EX_Mess1::UNSIGNED));
    |         :
    | END.
    |

    Compilation and linkage are as usual:

        $ PASCAL EXAMPLE
        $ LINK EXAMPLE, EX_MESSAGES

    The advantage of course is that when you add new messages or remove old
    ones, you don't have to worry about the condition values changing. Just
    add/remove like named variables in your program.  The references will
    be taken care of automatically at link time (and ain't that what
    computers are for?). The SHAR file that follows this letter contains a
    simple example MESSAGE file and PASCAL program that uses this
    technique.

    **NOW** - I have a question for the VMS/VAX Pascal *gurus* out there.
    Could you give me a hint (in other words show me) how to declare
    LIB$SIGNAL in VAX Pascal so I can pass FAO arguments?  I thought I
    understood from the manual what was wanted for the argument
    definitions, but I'll be darned if I can get it to work.  I've tried to
    define it to take a variable number of FAO arguments (with some max
    like 5).  That didn't work, so I tried to keep it simple and declared
    it with a fixed number of FAO arguments (i.e. 1).  That didn't work
    either. All I get back for a message is the message string with the FAO
    directive unsatisfied. If you've already successfully used FAO argments
    with LIB$SIGNAL (or LIB$STOP, etc.) in a VAX Pascal program, I'd love
    to see your code!

    Thanks in advanced.....


 ##    ##    ##    ## +-------------------------------------------------------+
 ##    ###   ##    ## !  Bill Costa                 PHONE: (603) 862-3056     !
 ##    ####  ##    ## !  University Computing      BITNET: W_COSTA@UNHH       !
 ##    ## ## ######## !  Kingsbury Hall                                       !
 ##    ##  ####    ## !  Durham, NH  03824                                    !
 ##    ##   ###    ## !  USA                <Insert Standard Disclaimer Here> !
  #######    ##    ## +-------------------------------------------------------+

...................... Cut between dotted lines and save ......................
$!..............................................................................
$! VAX/VMS archive file created by VMS_SHAR V-4.03 05-Aug-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by W_COSTA
$!      on Wednesday 4-NOV-1987 00:02:40.28
$!
$! It contains the following 2 files:
$! EXAMPLE.PAS EX_MESSAGES.MSG
$!=============================================================================

$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
                ", but this procedure requires V4.4 or higher."
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
        VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set (Output_File,b,o);
Position (Beginning_of(b));Loop x:=Erase_Character(1); Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;Move_Horizontal
(-Current_Offset);EndLoop;Move_Vertical(1);ExitIf Mark(None)=End_of(b)
EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="EXAMPLE.PAS"
$ Check_Sum_is=1999389060
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
XPROGRAM Example;
X
X{  Shows how to use the Message Utility with Pascal without having to
X   hard-code the condition values generated by the message utility.
X}
X
XVAR
X     EX_Mess1   : [EXTERNAL,VOLATILE] UNSIGNED;
X     EX_Mess2   : [EXTERNAL,VOLATILE] UNSIGNED;
X     EX_Mess3   : [EXTERNAL,VOLATILE] UNSIGNED;
X
X{-----------------------------------------------------------------------------}
X
X[ASYNCHRONOUS] PROCEDURE LIB$SIGNAL( Cond_Value : [IMMEDIATE] UNSIGNED );
X
X        EXTERN;
X
X{-----------------------------------------------------------------------------}
X
X
XBEGIN
X        LIB$SIGNAL(IADDRESS(EX_Mess1::UNSIGNED));
X        LIB$SIGNAL(IADDRESS(EX_Mess2::UNSIGNED));
X        LIB$SIGNAL(IADDRESS(EX_Mess3::UNSIGNED));
XEND.
$ GoSub Convert_File
$ File_is="EX_MESSAGES.MSG"
$ Check_Sum_is=338256694
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X
X.TITLE          Example of using Message Facility with VAX/VMS Pascal V3.5
X.FACILITY       EX,1/PREFIX=EX_
X.IDENT          'Example'
X
X.SEVERITY       SUCCESS
X                Mess1           <Here is the first message.>
X
X.SEVERITY       INFORMATIONAL
X                Mess2           <And this is the second.>
X
X.SEVERITY       WARNING
X                Mess3           <And this is your last warning...>
X.END
X
$ GoSub Convert_File
$ Exit