Subject: Re: Advice wanted: m4 and I4GL?

From: [email-masked] (Jonathan Leffler)
Date: Mon, 5 Oct 92 11:08:18 GMT

>From: uunet!diku.dk!berner (Niels Berner)
>Subject: Advice wanted: m4 and I4GL?
>Date: 2 Oct 92 11:22:45 GMT
>X-Informix-List-Id: <news.1909>
>
>Hey Netlanders.
>
>If they are any of you outthere, who have any experience with m4 in
>conjunction with informix, I would be happy to hear from you.
>
>Any kind of advice, hints og pointers will help.
>
>Please email to: [email-masked]
>Thanks in advance.
>Niels Berner.

I've never used this in anger, but it was designed to use m4 to provide
an include and define mechanism.  The m4 code is inscrutable (incomprehensible)
but works.   The dnl's stop you get extraneous space in the output.
The shell archive includes a manual page -- miracles sometimes occur!

Yours,
Jonathan Leffler ([email-masked]) #include <disclaimer.h>

:	"@(#)shar.sh	1.8"
#! /bin/sh
#
#	This is a shell archive.
#	Remove everything above this line and run sh on the resulting file.
#	If this archive is complete, you will see this message at the end:
#	"All files extracted"
#
#	Created: Mon Oct  5 11:06:27 GMT 1992 by johnl at Informix Software Ltd.
#	Files archived in this archive:
#	m4gl
#	m4gl.man
#
#--------------------
if [ -f m4gl -a "$1" != "-c" ]
then echo shar: m4gl already exists
else
echo 'x - m4gl (1248 characters)'
sed -e 's/^X//' >m4gl <<'SHAR-EOF'
X:	"@(#)m4gl.sh	1.3 90/09/20"
X#
X#	Preprocess I4GL files with M4.
X#	Be very careful in changing the control script.
X#	There are far too many quotes for comfort.
X
Xset -- `getopt o: $*`
Xoutfile=
Xerr=no
Xwhile [ $# -gt 0 ]
Xdo
X	case "$1" in
X	-o)	outfile=">$2"; shift 2;;
X	--) shift; break;;
X	*)	err=yes; break;;
X	esac
Xdone
X
Xif [ $# = 0 -o "$err" = yes ]
Xthen
X	echo "Usage: `basename $0 .sh` [-o file] file [...]" >&2
X	exit 1
Xfi
X
X# All leading tabs in document are removed by the shell, not m4!
Xcat - <<-'EOF' |
Xdefine(i4gl_include,
X	`dnl
X	ifelse(eval(in_i4gl_include == 0), 1,
X		`popdef(`define')popdef(`index')popdef(`len')')dnl
X	pushdef(`x', `eval(in_i4gl_include + 1)')dnl
X	define(`in_i4gl_include', x)popdef(`x')dnl
X	ifelse(eval(in_i4gl_include == 1), 1, ``#i4gl_include($*)'
X											divert(-1)')dnl
X	include($*)
X	ifelse(eval(in_i4gl_include == 1), 1, `divert(0)')dnl
X	pushdef(`x', `eval(in_i4gl_include - 1)')dnl
X	define(`in_i4gl_include', x)popdef(`x')dnl
X	ifelse(eval(in_i4gl_include == 0), 1,
X		`pushdef(`define',``define'')dnl
X		pushdef(`index',``index'')dnl
X		pushdef(`len',``len'')')dnl
X	dnl')dnl
Xdefine(in_i4gl_include, 0)dnl
Xpushdef(`define',``define'')dnl
Xpushdef(`index',``index'')dnl
Xpushdef(`len',``len'')dnl
XEOF
Xeval m4 - $* $outfile
SHAR-EOF
chmod 555 m4gl
if [ `wc -c <m4gl` -ne 1248 ]
then echo shar: m4gl unpacked with wrong size
fi
# end of overwriting check
fi
#--------------------
if [ -f m4gl.man -a "$1" != "-c" ]
then echo shar: m4gl.man already exists
else
echo 'x - m4gl.man (2740 characters)'
sed -e 's/^X//' >m4gl.man <<'SHAR-EOF'
X'\" @(#)m4gl.man	1.2 90/09/20
X'\" @(#)Manual page: M4GL -- Preprocessor for I4GL
X.ds fC "Version: 1.2 (90/09/20)
X.TH M4GL 1J "JLSS Informix Tools"
X.SH NAME
Xm4gl \(em pre-processor for I4GL
X.SH SYNOPSIS
X\fBm4gl\fP [-o file] file [...]
X.SH DESCRIPTION
X\fBM4gl\fP is a preprocessor script which uses \fBm4\fP(1)
Xto preprocess files.
XIt defines a single \fBm4\fP macro, `\fBi4gl_include\fP(\fIfile\fP)'
Xwhich is used to import a series of \fBm4\fP definitions.
XOutside of the scope of \fIi4gl_include\fP, the normal definition
Xof the \fBm4\fP built-in \fIdefine\fP is suppressed.
XThe \fIi4gl_include\fP macro echoes a copy of the invocation
Xpreceded by a hash `#'; this preserves the line numbering of the
Xoriginal input file.
XWithin the scope of \fIi4gl_include\fP, all output except the echo mentioned
Xabove is suppressed.
X.P
XThe types of definitions that can be used are illustrated below:
X.eS
Xdefine(CONST1, 1)
Xdefine(CONST2, 2)
Xdefine(CONST3, `eval(CONST1 + CONST2)')
X.eE
XNote the use of \fIeval\fP in the last example; \fBm4\fP has a built-in integer
Xarithmetic capability, which is more than can be said for Informix-4GL,
Xand therefore \fIeval\fP should be used for complex definitions so that the
Xresult can be used anywhere.
X.P
XYou can nest calls to \fIi4gl_include\fP arbitrarily
Xwithin the limits of \fBm4\fP.
XAll the other facilities of \fBm4\fP are available.
XYou should not alter the variable
X\fIin_i4gl_include\fP anywhere; it is used internally.
XIf you undivert the output in a set of defines, please ensure you divert it
Xback to channel -1 before you finish;
Xif you don't do this, the mess you produce is your own affair.
X.SH "EXAMPLE"
XThe source file \*cxxx.4gm\*d is:
X.eS
Xi4gl_include(i4gl1.4gh)
Xi4gl_include(i4gl2.4gh)
X
Xdefine
X	i integer
Xmain
X	define
X		len		integer
X	for_loop(i, CONST1, CONST2)
X		display i, CONST3
X	end for
X	create index ix_1 on abidjan(pkey)
Xend main
X.eE
XThe include file \*ci4gl1.4gh\*d is:
X.eS
Xdefine(CONST1, 1)
Xdefine(CONST2, 2)
Xi4gl_include(i4gl3.4gh)
X.eE
XThe include file \*ci4gl2.4gh\*d is:
X.eS
Xdefine(CONST3, `eval(CONST1 + CONST2)')
X.eE
XThe include file \*ci4gl3.4gh\*d is:
X.eS
Xdefine(for_loop, FOR $1 = $2 TO $3)
X.eE
XThe command run is:
X.eS
X$ m4gl -o xxx.4gl xxx.4gm
X$
X.eE
XThe output file is
X.eS
X#i4gl_include(i4gl1.4gh)
X#i4gl_include(i4gl2.4gh)
X
Xdefine
X	i integer
Xmain
X	define
X		len		integer
X	FOR i = 1 TO 2
X		display i, 3
X	end for
X	create index ix_1 on abidjan(pkey)
Xend main
X.eE
X.SH "SEE ALSO"
X\fBm4\fP(1)
X.SH DIAGNOSTICS
XFrom \fBm4\fP.
X.SH BUGS
XBeware the use of m4 built-ins in source code.
XThe only ones you are protected from automatically
Xare \fIdefine\fP, \fIindex\fP and \fIlen\fP.
X\fBM4\fP is case-sensitive.
X.SH AUTHOR
XJonathan Leffler
X.br
XIRL Project Services
X.br
X20th September 1990
SHAR-EOF
chmod 444 m4gl.man
if [ `wc -c <m4gl.man` -ne 2740 ]
then echo shar: m4gl.man unpacked with wrong size
fi
# end of overwriting check
fi
echo All files extracted
exit 0