From:	MERC::"uunet!WKUVX1.BITNET!FILESERV-Mgr" 12-JUN-1992 14:08:17.05
To:	galaxy::gleeve
CC:	
Subj:	GREP.12_OF_12

-+-+-+-+-+-+-+-+ START OF PART 12 -+-+-+-+-+-+-+-+
X/* -=- STATIC FUNCTION -=- */
X
X/* truncate_argv_0
X**--------------------------------------------------------------------------
V---
X** Functional Description
X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E
X**  Programs written in VAX C, when run under VMS DCL, will have their entir
Ve
X** filespec (i.e., the filespec of the running image) in the main() function
V's
X** `60argv`5B0`5D' variable.  While this makes sense from a VMS standpoint,
V it does
X** not look very good in programs ported from GNU, which often use `60argv`5
VB0`5D' as
X** an error message prefix.
X**  This function, which is called from shell_mung(), truncates the filespec
V in
X** `60argv`5B0`5D' to just the filename or, if the filetype is not ".EXE", t
Vo the
X** filename and filetype.
X**--------------------------------------------------------------------------
V---
X** Calling Sequence
X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E
X** new_argv`5B0`5D = truncate_argv_0(given_filespec);
X**--------------------------------------------------------------------------
V---
X** Formal Argument      Description
X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E      `7E`7E`7E`7E`7E`7E`7E`
V7E`7E`7E`7E
X** given_filespec       The filespec to be truncated.  Assumed to be `60argv
V`5B0`5D'
X**                      or a pointer to the same thing `60argv`5B0`5D' point
Vs to.
X**--------------------------------------------------------------------------
V---
X** Implicit Inputs:     None
X**--------------------------------------------------------------------------
V---
X** Implicit Outputs:    None
X**--------------------------------------------------------------------------
V---
X** Return Value
X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E
X**  Returns the truncated filespec, which is in newly-allocated memory.
X**--------------------------------------------------------------------------
V---
X** Side Effects
X** `7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E`7E
X**  Memory is allocated for the truncated filespec.
X**--------------------------------------------------------------------------
V---
X*/
Xstatic char *
Xtruncate_argv_0(given_filespec)
X char *  given_filespec;
X`7B
X  /* --- LOCAL VARIABLES --- */
X
X  register char *  character_p;         /* General-purpose character pointer
V,
X                                        ** used to lowercase filespec.
X                                        */
X  char  * expanded_filespec;`09`09/* v1.2-004 */
X                                        /* Buffer to hold the expanded files
Vpec
X                                        ** from a call to sys$parse().
X                                        */
X  register char *  filespec_p;          /* Pointer to truncated filespec to
V be
X                                        ** returned.
X                                        */
X  struct FAB  fab = cc$rms_fab;         /* RMS file access block for file.
X                                        */
X  struct NAM  nam = cc$rms_nam;         /* RMS name block for file.
X                                        */
X
X  /* --- INITIALIZE FABS AND NAMS --- */
X
X  expanded_filespec = xmalloc(NAM$C_MAXRSS + 1);`09/* v1.2-004 */
X  fab.fab$l_fna = given_filespec;
X  fab.fab$b_fns = strlen(given_filespec);
X  fab.fab$l_nam = &nam;
X  nam.nam$l_esa = expanded_filespec;`09`09`09/* v1.2-004 */
X  nam.nam$b_ess = NAM$C_MAXRSS;
X  nam.nam$b_nop = NAM$M_SYNCHK;
X
X  /* --- PARSE OUT THE GIVEN FILESPEC --- */
X
X  sys$parse(&fab);
X
X  /* --- NUL-TERMINATE AND LOWERCASE FILESPEC --- */
X
X  *nam.nam$l_ver = '\0';
X
X  for (character_p = nam.nam$l_esa; *character_p; ++character_p)
X   *character_p = _tolower(*character_p);`09/* v1.2-004 */
X
X  /* --- RETURN TRUNCATED FILESPEC --- */
X
X  if (strcmp(nam.nam$l_type,".exe"))
X   filespec_p = xmalloc(nam.nam$b_name + nam.nam$b_type + 1);
X  else
X  `7B
X    *nam.nam$l_type = '\0';
X    filespec_p = xmalloc(nam.nam$b_name + 1);
X  `7D
X
X  strcpy(filespec_p,nam.nam$l_name);
X  return filespec_p;
X
X`7D /* truncate_argv_0() */
$ CALL UNPACK [.GREP016]SHELL_MUNG.C;1 593217989
$ create 'f'
X$ save_verify = 'f$verify(0)'
X$!
X$!  VMSMAKE.COM - DCL command procedure to build GNU grep on VMS
X$!
X$!  To use VAX C, define CC = "CC"
X$!  To use GNU C, define CC = "GCC"
X$!
X$ CC = "CC"
X$! CC = "GCC"
X$ say := write sys$output
X$ if f$search("egrep.c") .eqs. "" then copy grep.c egrep.c
X$ say "Compiling alloca...."
X$ 'cc' alloca
X$ say "Compiling dfa...."
X$ 'cc' dfa
X$ say "Compiling getopt...."
X$ 'cc' getopt
X$ say "Compiling regex...."
X$ 'cc' regex
X$ say "Compiling shell_mung...."
X$ 'cc' shell_mung
X$ say "Compiling grep...."
X$ 'cc' grep
X$ say "Compiling egrep...."
X$ 'cc'/define=egrep egrep
X$ say "Linking grep...."
X$ if cc.eqs."CC"
X$ then`09open/write opt grep.opt
X`09write opt "SYS$SHARE:VAXCRTL.EXE/SHARE"
X`09close opt
X`09opt = "GREP.OPT"
X$ else`09opt = "GNU_CC:`5B000000`5DOPTIONS.OPT"
X$ endif
X$ link/notrace grep,shell_mung,alloca,dfa,getopt,regex,-
X`09'opt'/options
X$ say "Linking egrep...."
X$ link/notrace egrep,shell_mung,alloca,dfa,getopt,regex,-
X`09'opt'/options
X$ say "Generating on-line help"
X$ runoff grep.rnh
X$ say "Build completed"
X$ exit 1.or.f$verify(save_verify)
$ CALL UNPACK [.GREP016]VMSMAKE.COM;1 560883994
$ create 'f'
X1)  Muammar Qaddafi
X2)  Mo'ammar Gadhafi
X3)  Muammar Kaddafi
X4)  Muammar Qadhafi
X5)  Moammar El Kadhafi
X6)  Muammar Gadafi
X7)  Mu'ammar al-Qadafi
X8)  Moamer El Kazzafi
X9)  Moamar al-Gaddafi
X10) Mu'ammar Al Qathafi
X11) Muammar Al Qathafi
X12) Mo'ammar el-Gadhafi
X13) Moamar El Kadhafi
X14) Muammar al-Qadhafi
X15) Mu'ammar al-Qadhdhafi
X16) Mu'ammar Qadafi
X17) Moamar Gaddafi
X18) Mu'ammar Qadhdhafi
X19) Muammar Khaddafi
X20) Muammar al-Khaddafi
X21) Mu'amar al-Kadafi
X22) Muammar Ghaddafy
X23) Muammar Ghadafi
X24) Muammar Ghaddafi
X25) Muamar Kaddafi
X26) Muammar Quathafi
X27) Muammar Gheddafi
X28) Muamar Al-Kaddafi
X29) Moammar Khadafy
X30) Moammar Qudhafi
X31) Mu'ammar al-Qaddafi
X32) Mulazim Awwal Mu'ammar Muhammad Abu Minyar al-Qadhafi
$ CALL UNPACK [.GREP016.TESTS]KHADAFY.LINES;1 1763254040
$ create 'f'
XM`5Bou`5D'?am+`5Bae`5Dr .*(`5BAEae`5Dl`5B- `5D)?`5BGKQ`5Dh?`5Baeu`5D+(`5Bdtz
V`5D`5Bdhz`5D?)+af`5Biy`5D
$ CALL UNPACK [.GREP016.TESTS]KHADAFY.REGEXP;1 1417500268
$ create 'f'
X#! /bin/sh
X# Regression test for GNU e?grep.
X# Usage: regress.sh `5Bdir-containing-egrep`5D
X
Xbuilddir=$`7B1-..`7D
X
Xfailures=0
X
X# The Khadafy test is brought to you by Scott Anderson . . .
X$builddir/egrep -f khadafy.regexp khadafy.lines > khadafy.out
Xif cmp khadafy.lines khadafy.out
Xthen
X`09rm khadafy.out
Xelse
X`09echo Khadafy test failed -- output left on khadafy.out
X`09failures=1
Xfi
X
X# . . . and the following by Henry Spencer.
X
Xawk -F: -f scriptgen.awk spencer.tests > tmp.script
X
Xif sh tmp.script $builddir
Xthen
X`09rm tmp.script
X`09exit $failures
Xelse
X`09rm tmp.script
X`09exit 1
Xfi
$ CALL UNPACK [.GREP016.TESTS]REGRESS.SH;1 1546261734
$ create 'f'
XBEGIN `7B print "failures=0"; `7D
X!/`5E#/ && NF == 3 `7B
X`09print "echo '" $3 "' `7C $1/egrep -e '" $2 "' > /dev/null 2>&1";
X`09print "if `5B $? != " $1 " `5D"
X`09print "then"
X`09printf "\techo Spencer test \\#%d failed\n", ++n
X`09print "\tfailures=1"
X`09print "fi"
X`7D
XEND `7B print "exit $failures"; `7D
$ CALL UNPACK [.GREP016.TESTS]SCRIPTGEN.AWK;1 1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Eab`5D*:cde
X0:(`5E)*:-
X0:(ab`7C)*:-
X2:)(:-
X1:abc:
X1:abc:
X0:a*:
X0:(`5Babc`5D)*d:abbbcd
X0:(`5Babc`5D)*bcd:abcd
X0:a`7Cb`7Cc`7Cd`7Ce:e
X0:(a`7Cb`7Cc`7Cd`7Ce)f:ef
X0:((a*`7Cb))*:-
X0:abcd*efg:abcdefg
X0:ab*:xabyabbbz
X0:ab*:xayabbbz
X0:(ab`7Ccd)e:abcde
X0:`5Babhgefdc`5Dij:hij
X1:`5E(ab`7Ccd)e:abcde
X0:(abc`7C)ef:abcdef
X0:(a`7Cb)c*d:abcd
X0:(ab`7Cab*)bc:abc
X0:a(`5Bbc`5D*)c*:abc
X0:a(`5Bbc`5D*)(c*d):abcd
X0:a(`5Bbc`5D+)(c*d):abcd
X0:a(`5Bbc`5D*)(c+d):abcd
X0:a`5Bbcd`5D*dcdcde:adcdcde
X1:a`5Bbcd`5D+dcdcde:adcdcde
X0:(ab`7Ca)b*c:abc
X0:((a)(b)c)(d):abcd
X0:`5BA-Za-z_`5D`5BA-Za-z0-9_`5D*:alpha
X0:`5Ea(bc+`7Cb`5Beh`5D)g`7C.h$:abh
X0:(bc+d$`7Cef*g.`7Ch?i(j`7Ck)):effgz
X0:(bc+d$`7Cef*g.`7Ch?i(j`7Ck)):ij
X1:(bc+d$`7Cef*g.`7Ch?i(j`7Ck)):effg
X1:(bc+d$`7Cef*g.`7Ch?i(j`7Ck)):bcdd
X0:(bc+d$`7Cef*g.`7Ch?i(j`7Ck)):reffgz
X1:((((((((((a)))))))))):-
X0:(((((((((a))))))))):a
X1:multiple words of text:uh-uh
X0:multiple words:multiple words, yeah
X0:(.*)c(.*):abcde
X1:\((.*),:(.*)\)
X1:`5Bk`5D:ab
X0:abcd:abcd
X0:a(bc)d:abcd
X0:a`5B`01-`03`5D?c:a`02c
X0:(....).*\1:beriberi
$ CALL UNPACK [.GREP016.TESTS]SPENCER.TESTS;1 889900547
$ create 'f'
X$!
X$!  VMS DCL command procedure to check out GNU egrep
X$!
X$!`09Hunter Goatley, 12-SEP-1991
X$!
X$ if f$type(egrep) .eqs. ""
X$ then`09write sys$output "egrep foreign command is not defined"
X$`09exit
X$ endif
X$ failures=0
X$!
X$! The Khadafy test is brought to you by Scott Anderson . . .
X$!
X$ write sys$output "Executing Anderson tests...."
X$ egrep -f khadafy.regexp khadafy.lines >khadafy.out
X$!
X$!  Now use DIFF to check the files
X$!
X$ define/user sys$output nl:
X$ define/user sys$error nl:
X$ diff khadafy.lines khadafy.out
X$ if $status.eq.%X006C8009
X$ then`09write sys$output "egrep passed the khadafy test"
X$`09delete/nolog khadafy.out;
X$ else`09write sys$output "egrep failed the khadafy test"
X$`09write sys$output "Output left in khadafy.out"
X$`09failures = 1
X$ endif
X$!
X$!# . . . and the following by Henry Spencer.
X$!
X$ if f$type(gawk) .eqs. ""
X$ then`09write sys$output "Gawk foreign command not defined"
X$`09write sys$output "Skipping Spencer tests"
X$`09exit
X$ else`09write sys$output "Executing Spencer tests...."
X$`09gawk "-F:" -f vmsscriptgen.awk spencer.tests > temp.com
X$`09if f$search("temp.com").nes."" then @temp.com
X$`09delete/nolog temp.com;
X$ endif
X$ exit
$ CALL UNPACK [.GREP016.TESTS]VMSREGRESS.COM;1 1784819319
$ create 'f'
X#
X#  GNU awk program for VMS to create a command procedure to execute the
X#`09suite of grep tests developed by Henry Spencer and distributed
X#`09with GNU grep.
X#
X#  Author:`09Hunter Goatley, 12-SEP-1991, based on original awk program
X#
X#  To use:
X#
X#`09$ gawk "F:" -f vmsspencer.awk spencer.tests >spencer.com
X#
XBEGIN `7B print "$! DCL command procedure to test GNU egrep";
X`09print "$ set noon"; print "$ failures=0"; `7D
X!/`5E#/ && NF == 3 `7B
X`09#
X`09#  Because the exit statuses were changed for VMS, reflect those
X`09#  changes here.
X`09#
X`09if ($1 == 1)
X`09   stat = 3
X`09else
X`09   if ($1 == 2)
X`09      stat = 44
X`09   else
X`09      stat = 1
X`09print "$ define/user sys$output nl:"
X`09print "$ define/user sys$error nl:"
X`09print "$ egrep \042" $2 "\042 >NL:"
X`09print $3
X`09printf "$ if $status.ne.%d\n",stat
X`09printf "$ then write sys$output \042Spencer test \#%d failed\042\n", ++n
X`09print "$\tfailures=1"
X`09print "$ endif"
X`7D
XEND `7B print "$ write sys$output \042''failures' failures\042";`20
X`09print "$ exit"; `7D
$ CALL UNPACK [.GREP016.TESTS]VMSSCRIPTGEN.AWK;1 153046014
$ v=f$verify(v)
$ EXIT
