[news.software.anu-news] Generating missing header files

cur022@zodiac.ukc.ac.uk (Bob Eager) (01/09/90)

I noticed some people who had trouble with header files because they were
using V2.4 of VAXC. I too had this problem, but managed to solve it using
a useful command procedure which I haven't seen posted for a long time.

This command procedure generates a C header file from a set of symbol
definitions in SYS$LIBRARY:STARTLET.MLB or SYS$LIBRARY:LIB.MLB. I used it
to get most of the required files for V5.9C of ANU NEWS. It didn't manage
SORDEF.H, but in fact I believe that one can just be commented out since
the only symbol definition actually needed is adjacent to the #include
anyway.

I am still setting up V5.9C so I don't guarantee it will solve all problems;
it should however ease things a little, and will probably be useful in the
future.

There follows a VMS_SHARE file containing the command procedure. I make no
claims for it other than the above, and I didn't write it.

$! ................... Cut between dotted lines and save. ...................
$!...........................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.10 7-FEB-1989.
$!
$! VMS_SHARE was written by James Gray (Gray:OSBUSouth@Xerox.COM) from
$! VMS_SHAR by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au).
$!
$! To unpack, simply save, concatinate all parts into one file and
$! execute (@) that file.
$!
$! This archive was created by user CUR022 (Bob Eager, University of Kent)
$! on  9-JAN-1990 10:25:01.08.
$!
$! It contains the following 1 file:
$!        C_DEFS.COM
$!
$!============================================================================
$ SET SYMBOL/SCOPE=( NOLOCAL, NOGLOBAL )
$ VERSION = F$GETSYI( "VERSION" )
$ IF VERSION .GES "V4.4" THEN GOTO VERSION_OK
$ WRITE SYS$OUTPUT "You are running VMS ''VERSION'; ", -
    "VMS_SHARE V06.10 7-FEB-1989 requires VMS V4.4 or higher."
$ EXIT 44 ! SS$_ABORT
$VERSION_OK:
$ GOTO START
$!
$UNPACK_FILE:
$ WRITE SYS$OUTPUT "Creating ''FILE_IS'"
$ DEFINE/USER_MODE SYS$OUTPUT NL:
$ EDIT/TPU/COMMAND=SYS$INPUT/NODISPLAY/OUTPUT='FILE_IS'/NOSECTION -
    VMS_SHARE_DUMMY.DUMMY
b_part := CREATE_BUFFER( "{Part}", GET_INFO( COMMAND_LINE, "file_name" ) )
; s_file_spec := GET_INFO( COMMAND_LINE, "output_file" ); SET( OUTPUT_FILE
, b_part, s_file_spec ); b_errors := CREATE_BUFFER( "{Errors}" ); i_errors 
:= 0; pat_beg_1 := ANCHOR & "-+-+-+ Beginning"; pat_beg_2 := LINE_BEGIN 
& "+-+-+-+ Beginning"; pat_end := ANCHOR & "+-+-+-+-+ End"; POSITION
( BEGINNING_OF( b_part ) ); LOOP EXITIF SEARCH( SPAN( ' ' )@r_trail 
& LINE_END, FORWARD) = 0; POSITION( r_trail ); ERASE( r_trail ); ENDLOOP
; POSITION( BEGINNING_OF( b_part ) ); i_append_line := 0; LOOP EXITIF MARK
( NONE ) = END_OF( b_part ); s_x := ERASE_CHARACTER( 1 )
; IF s_x = '+' THEN r_skip := SEARCH( pat_beg_1, FORWARD, EXACT ); IF r_skip 
<> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ERASE_LINE; ENDIF
; ENDIF; IF s_x = '-' THEN r_skip := SEARCH( pat_end, FORWARD, EXACT )
; IF r_skip <> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); m_skip 
:= MARK( NONE ); r_skip := SEARCH( pat_beg_2, FORWARD, EXACT ); IF r_skip 
<> 0 THEN POSITION( END_OF( r_skip ) ); MOVE_HORIZONTAL( -CURRENT_OFFSET )
; MOVE_VERTICAL( 1 ); MOVE_HORIZONTAL( -1 ); ELSE POSITION( END_OF( b_part 
) ); ENDIF; ERASE( CREATE_RANGE( m_skip, MARK( NONE ), NONE ) ); ENDIF; ENDIF
; IF s_x = 'V' THEN s_x := ''; IF i_append_line <> 0 THEN APPEND_LINE
; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF; i_append_line := 1
; MOVE_VERTICAL( 1 ); ENDIF; IF s_x = 'X' THEN s_x := ''; IF i_append_line 
<> 0 THEN APPEND_LINE; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF
; i_append_line := 0; MOVE_VERTICAL( 1 ); ENDIF; IF s_x <> '' THEN i_errors 
:= i_errors + 1; s_text := CURRENT_LINE; POSITION( b_errors ); COPY_TEXT
( "The following line could not be unpacked properly:" ); SPLIT_LINE
; COPY_TEXT( s_x ); COPY_TEXT( s_text ); POSITION( b_part ); MOVE_VERTICAL
( 1 ); ENDIF; ENDLOOP; POSITION( BEGINNING_OF( b_part ) ); LOOP r_x := SEARCH
( "`", FORWARD, EXACT ); EXITIF r_x = 0; POSITION( r_x ); ERASE_CHARACTER
( 1 ); COPY_TEXT( ASCII( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDLOOP
; IF i_errors = 0 THEN SET( NO_WRITE, b_errors, ON ); ELSE POSITION
( BEGINNING_OF( b_errors ) ); COPY_TEXT( FAO
( "The following !UL errors were detected while unpacking !AS", i_errors
, s_file_spec ) ); SPLIT_LINE; SET( OUTPUT_FILE, b_errors, "SYS$COMMAND" )
; ENDIF; EXIT; 
$ DELETE VMS_SHARE_DUMMY.DUMMY;*
$ CHECKSUM 'FILE_IS
$ WRITE SYS$OUTPUT " CHECKSUM ", -
  F$ELEMENT( CHECKSUM_IS .EQ. CHECKSUM$CHECKSUM, ",", "failed!!,passed." )
$ RETURN
$!
$START: 
$ FILE_IS = "C_DEFS.COM"
$ CHECKSUM_IS = 1595550659
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$!
X$! Drive generation of C #define header file from MACRO definitions
X$!
X$! Usage:
X$!`009`009@C_DEFS`009name
X$!
X$! where $NAME is a definitional macro in either STARLET.MLB or LIB.MLB.
X$! Output: []'p1'.H
X$!
V$! Note:  This command file can be changed to produce files in languages othe
Xr
X$! than C.  To do this, change the definitions of "lang" and "type" to the
V$! language name and default file type for include files; the "write DEFS_MAR
X"
X$! statements to create header and trailer comments appropriate to the new
X$! language; and the definition of the macro EMIT to produce the right kind
X$! of definition lines.
X$!
X$! Originally written and posted to INFOVAX by:
X$!
V$! W.J.Moeller, GWDG, D-3400 Goettingen, F.R.Germany  <GWD21T@DGOGWD01.BITNET
X>
X$!                                                 Phone +49 551 201516
X$!
X$! Later revised by Jerry Leichter (LEICHTER@YALE)
X$!`032
X$! Revision History
X$! 0.0`009??-???-?? WJM`009Creation
V$! 1.0`009 6-Apr-87 JSL`009Centralize actual creation of output lines in the
X EMIT
X$!`009`009`009macro; this makes changes a lot easier.  Similarly,
X$!`009`009`009define the output file type ("type") and the language
X$!`009`009`009("lang") in symbols to simplify changes.  Allow for
X$!`009`009`009special handling of negative values in EMIT - for C,
X$!`009`009`009wrap them in parentheses.  Try to warn the user if
X$!`009`009`009it looks like there was an error.
X$ set noon
X$ on control_y then goto fin
X$ lang = "C"
X$ type = "H"
X$ open/write DEFS_MAR []defs.tmp
X$ write DEFS_MAR "    .print;/*"
X$ write DEFS_MAR "    .print; *`009`009`009`009''p1'.''type'"
X$ write DEFS_MAR "    .print; *"
X$ write DEFS_MAR "    .print; * Definitions created by ''lang'_DEFS",`009-
X`009`009`009`009`009" at ''f$time()'"
X$ write DEFS_MAR "    .print; */"
X$ write DEFS_MAR "    $''p1'"
X$ write DEFS_MAR "    .print;/*"
X$ write DEFS_MAR "    .print; * End of ''lang'_DEFS definitions"
X$ write DEFS_MAR "    .print; */"
X$ write DEFS_MAR "    .end"
X$ close DEFS_MAR
X$!
X$ define/user SYS$ERROR 'p1'.'type`009! MACRO puts .PRINT output here
X$ macro/nolist/noobject SYS$INPUT+SYS$LIBRARY:LIB/LIB+SYS$DISK:[]defs.tmp
X        .MACRO  $GBLINI GBL
X`009.MACRO`009EMIT`009SYM,VALUE
X`009.IF`009LT`009%LOCATE(<->,VALUE)-%LENGTH(VALUE)
X.print;#define SYM`009(VALUE)
X`009.IFF
X.print;#define SYM`009VALUE
X`009.ENDC
X`009.ENDM
X        .MACRO  $DEF    SYM,ALLOC,SIZ
X        .if     NB,SYM
XSYM:
X`009EMIT`009SYM,\SYM
X        .endc
X        .IIF    NB,ALLOC,       ALLOC   SIZ
X        .ENDM   $DEF
X        .MACRO  $EQU    SYM,VAL
X        SYM=VAL
X`009EMIT`009SYM,\SYM
X        .ENDM   $EQU
X        .MACRO  $VIELD1 MOD,SEP,SYM,SIZ,MSK
X        SIZ...=1
X        .IIF    NB,SIZ, SIZ...=SIZ
X        .IF     NB,SYM
X        MOD'SEP'V_'SYM=BIT...
X`009EMIT`009MOD'SEP'V_'SYM,\MOD'SEP'V_'SYM
X        .if     nb,siz
XMOD'SEP'S_'SYM=SIZ
X`009EMIT`009MOD'SEP'S_'SYM,\MOD'SEP'S_'SYM
X        .endc
X        .if     nb,msk
XMOD'SEP'M_'SYM=<<<1@SIZ...>-1>@BIT...>
X`009EMIT`009MOD'SEP'M_'SYM,\MOD'SEP'M_'SYM
X        .endc
X        .ENDC
X        BIT...=BIT...+SIZ...
X        .ENDM   $VIELD1
X        .ENDM   $GBLINI
X$`032
X$!
X$ assign/user _NL: SYS$ERROR`009`009`009!Avoid "No strings matched"
X$ assign/user _NL: SYS$OUTPUT
X$ search/nooutput 'p1'.'type' "%MACRO-"
X$ if $severity .ne. 1 then goto fin
X$ write SYS$ERROR "Error in producing ''p1'.''type' - file not usable."
X$ write SYS$ERROR "(This probably means that there is no $",p1," macro.)"
X$fin:
X$ close/err=noerrdefs DEFS_MAR
X$noerrdefs:
X$ delete/nolog []defs.tmp;
$ GOSUB UNPACK_FILE
$ EXIT
---------------------+-----------------------------------------------------
Bob Eager            | University of Kent at Canterbury
rde@ukc.ac.uk        | +44 227 764000 ext 7589
---------------------+-----------------------------------------------------
*** NB *** Do NOT use the return path in the article header ***************
---------------------------------------------------------------------------