[comp.sources.misc] v18i104: parseargs - functions to parse command line arguments, Patch04d/4

brad@hcx1.ssd.csd.harris.com (Brad Appleton) (04/26/91)

Submitted-by: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
Posting-number: Volume 18, Issue 104
Archive-name: parseargs/patch04d
Patch-To: parseargs: Volume 17, Issue 45-57

#!/bin/sh
# This is part 4 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file PATCH continued
#
if test ! -r _shar_seq_.tmp; then
	echo 'Please unpack part 1 first!'
	exit 1
fi
(read Scheck
 if test "$Scheck" != 4; then
	echo Please unpack part "$Scheck" next!
	exit 1
 else
	exit 0
 fi
) < _shar_seq_.tmp || exit 1
echo 'x - continuing file PATCH'
sed 's/^X//' << 'SHAR_EOF' >> 'PATCH' &&
X  
X        /* scan for missing required args */
X     if ( SYNTAX_ERROR(rc, argd) ) {
***************
*** 1971,1976 ****
--- 2003,2011 ----
X        exit( 2 );
X     }
X  
+       /* reset previous parse flags */
+    cmd_flags(argd)  =  saveflags;
+ 
X     return  rc;
X  }
X  
***************
*** 1997,2003 ****
X    
X  /* ^DESCRIPTION:
X  **    Given an ArgList and an argdesc array, lparseargs will parse arguments
! **    in an ArgList in much the same manner as parseargs.
X  **
X  ** ^REQUIREMENTS:
X  **    <argls> should be an ArgList of strings
--- 2032,2038 ----
X    
X  /* ^DESCRIPTION:
X  **    Given an ArgList and an argdesc array, lparseargs will parse arguments
! **    in an ArgList in the same manner as parseargs.
X  **
X  ** ^REQUIREMENTS:
X  **    <argls> should be an ArgList of strings
***************
*** 2055,2063 ****
X     BSET(cmd_flags(argd), pa_ARGV0);
X     rc = parse_argv_style( argv, parse_init( &argd ) );
X  
-       /* reset previous parse-flags */
-    cmd_flags(argd) = saveflags;
- 
X        /* scan for missing required arguments */
X     if ( SYNTAX_ERROR(rc, argd) ) {
X        fputc( '\n', stderr );
--- 2090,2095 ----
***************
*** 2065,2070 ****
--- 2097,2105 ----
X        exit( 2 );
X     }
X  
+       /* reset previous parse-flags */
+    cmd_flags(argd) = saveflags;
+ 
X     return   rc;
X  }
X  
***************
*** 2093,2099 ****
X  /* ^DESCRIPTION:
X  **    Vparseargs takes an argdesc array, the number of arguments to parse,
X  **    and a (possibly NULL terminated) list of argument-strings and parses
! **    them in much the same manner as parseargs.  Unlike sparseargs,
X  **    vparseargs assumes that all parameters are already split up into
X  **    tokens, hence any whitespace characters contained in any of the
X  **    string-parameters are used as is (and will be considered a part of
--- 2128,2134 ----
X  /* ^DESCRIPTION:
X  **    Vparseargs takes an argdesc array, the number of arguments to parse,
X  **    and a (possibly NULL terminated) list of argument-strings and parses
! **    them in the same manner as parseargs.  Unlike sparseargs,
X  **    vparseargs assumes that all parameters are already split up into
X  **    tokens, hence any whitespace characters contained in any of the
X  **    string-parameters are used as is (and will be considered a part of
***************
*** 2158,2166 ****
X  
X     rc = parse_argv_style( argv, parse_init( &argd ) );
X  
-       /* reset previous parse-flags */
-    cmd_flags(argd) = saveflags;
- 
X        /* scan for missing required arguments */
X     if ( SYNTAX_ERROR(rc, argd) ) {
X        fputc( '\n', stderr );
--- 2193,2198 ----
***************
*** 2168,2173 ****
--- 2200,2208 ----
X        exit( 2 );
X     }
X  
+       /* reset previous parse-flags */
+    cmd_flags(argd) = saveflags;
+ 
X     return   rc;
X  }
X  
***************
*** 2241,2249 ****
X  
X     rc = parse_argv_style( av, parse_init( &argd ) );
X  
-       /* reset previous parse-flags */
-    cmd_flags(cmd) = saveflags;
- 
X        /* scan for missing required arguments */
X     if ( SYNTAX_ERROR(rc, argd) ) {
X        fputc( '\n', stderr );
--- 2276,2281 ----
***************
*** 2250,2255 ****
--- 2282,2290 ----
X        usage( argd );
X        exit( 2 );
X     }
+ 
+       /* reset previous parse-flags */
+    cmd_flags(cmd) = saveflags;
X  
X     return  rc;
X  }
SHAR_EOF
echo 'File PATCH is complete' &&
chmod 0664 PATCH ||
echo 'restore of PATCH failed'
Wc_c="`wc -c < 'PATCH'`"
test 79034 -eq "$Wc_c" ||
	echo 'PATCH: original size 79034, current size' "$Wc_c"
# ============= doc/Makefile ==============
if test ! -d 'doc'; then
    echo 'x - creating directory doc'
    mkdir 'doc'
fi
echo 'x - extracting doc/Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'doc/Makefile' &&
# $Header: Man.mk,v 1.0 90/03/05 09:21:28 brad Exp $
X
###
# target directories
###
MAN1=	man1
MAN3=	man3
LOCALMAN=	local_man
MANDIR=	/usr/man/${LOCALMAN}
CATMANDIR=	/usr/catman/${LOCALMAN}
X
###
# commands
###
COL=	col
COLFLAGS=	-b
SOELIM=	/usr/ucb/soelim
MANTOCATMAN=	/usr/ucb/mantocatman
TROFF=	roff
TRFLAGS=	-man -dimagen1
NROFF=	nroff
NRFLAGS=	-man
SPELL=	spell
COPY=	/bin/cp
DEL=	/bin/rm -f
X
###
# files used
###
INCS=	*.inc
SRCS=	argtype.man3  parseargs.man1  parseargs.man3  parsecntl.man3
MANIFEST=	Manifest
MAN3FILES=	argtype.3  parseargs.3  parsecntl.3
MAN1FILES=	parseargs.1
CATMAN3FILES=	argtype.3.z  parseargs.3.z  parsecntl.3.z
CATMAN1FILES=	parseargs.1.z
X
###
# target dependencies
###
.SUFFIXES: .man1 .man3 .1 .3
X
.man1.1:
X	${SOELIM} $< >$*.1
X	${MANTOCATMAN} $*.1
X
.man3.3:
X	${SOELIM} $< >$*.3
X	${MANTOCATMAN} $*.3
X
###
# give a usage message if no target is given
###
usage:
X	@echo "Usage: make <target>"
X	@echo " "
X	@echo "where <target> is one of the following: "
X	@echo " "
X	@echo "   install  -- to install the documentation"
X	@echo "   installman  -- to install the unpacked documentation"
X	@echo "   installcatman  -- to install the packed documentation"
X	@echo "   print  -- to print the documentation"
X	@echo "   view   -- to view the documentation"
X	@echo "   text   -- to build text copies of the documentation"
X	@echo "   spell  -- to spell check the documentation"
X	@echo "   clean  -- to remove all intermediate files"
X	@echo "   clobber  -- to remove all created files"
X
###
# installation dependencies
###
install: installman installcatman
X
installman: installman1 installman3
X
installcatman: installcatman1 installcatman3
X
installman1: ${MAN1FILES}
X	${COPY} ${MAN1FILES} ${MANDIR}/${MAN1}
X
installcatman1: ${CATMAN1FILES}
X	${COPY} ${CATMAN1FILES} ${CATMANDIR}/${MAN1}
X
installman3: ${MAN3FILES}
X	${COPY} ${MAN3FILES} ${MANDIR}/${MAN3}
X
installcatman3: ${CATMAN3FILES}
X	${COPY} ${CATMAN3FILES} ${CATMANDIR}/${MAN3}
X
###
# include dependencies
###
argtype.3:
parseargs.1:
parseargs.3:
parsecntl.3:
X
X
###
# maintenance dependencies
###
clean:
X	${DEL} ${MAN1FILES} ${MAN3FILES} ${CATMAN1FILES} ${CATMAN3FILES}
X
clobber: clean
X	${DEL} *.txt
X
spell: ${INCS} ${SRCS}}
X	${SPELL} ${SPELLFLAGS} ${INCS} ${SRCS}
X
print: ${MANFILES} ${INCS}
X	${TROFF} ${TRFLAGS} ${SRCS}
X
text: ascii
txt: ascii
ascii:
X	${NROFF} ${NRFLAGS} argtype.man3 | ${COL} ${COLFLAGS} >argtype3.txt
X	${NROFF} ${NRFLAGS} parseargs.man1 | ${COL} ${COLFLAGS} >parseargs1.txt
X	${NROFF} ${NRFLAGS} parseargs.man3 | ${COL} ${COLFLAGS} >parseargs3.txt
X	${NROFF} ${NRFLAGS} parsecntl.man3 | ${COL} ${COLFLAGS} >parsecntl3.txt
X
view: ${MANFILES} ${INCS}
X	${NROFF} ${NRFLAGS} ${SRCS}
X
SHAR_EOF
chmod 0664 doc/Makefile ||
echo 'restore of doc/Makefile failed'
Wc_c="`wc -c < 'doc/Makefile'`"
test 2667 -eq "$Wc_c" ||
	echo 'doc/Makefile: original size 2667, current size' "$Wc_c"
# ============= doc/effects.inc ==============
echo 'x - extracting doc/effects.inc (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'doc/effects.inc' &&
.\"----------------------------------------------------------------------------
.\"-- This text was extracted using the following command:
.\"--   xdoc -man -n -p '[ \t]*' -I SIDE-EFFECTS  ../xparse.c
.\"----------------------------------------------------------------------------
.SH "SIDE EFFECTS"
.PP
Each of the functions in the \fIparseargs\fP library will set the external
character string \fIProgName\fP to be the name of the last command that
was operated upon by any of the library routines.
.PP
When an argument-descriptor array is first encountered by any of the
parseargs library routines, it is initially compiled into an intermediate
form that is more convenient to manipulate. As a direct result, it is not
advisable to attempt to index directly into the array to manipulate one
of the argument descriptors (because the argdesc that you thought was there
may actually be somewhere else). After the array has been given its initial
value(s), only \fIparsecntl\fP(3) should be used to manipulate or query the
attributes of an argument descriptor.
SHAR_EOF
chmod 0664 doc/effects.inc ||
echo 'restore of doc/effects.inc failed'
Wc_c="`wc -c < 'doc/effects.inc'`"
test 1060 -eq "$Wc_c" ||
	echo 'doc/effects.inc: original size 1060, current size' "$Wc_c"
# ============= patchlevel.h ==============
echo 'x - extracting patchlevel.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'patchlevel.h' &&
/*************************************************************************
** ^FILE: patchlevel.h - current patchlevel for parseargs
**
** ^HISTORY:
**    04/10/91	Brad Appleton	<brad@ssd.csd.harris.com>
**    Patch04
**    - fixed problem with prompting in xparse.c:prompt_user()
**    - under vms, getenv was defined to be 'getsymbol', it should be
**      'get_symbol' (note the underscore).
**    - now uses <errno.h>
**    - parseargs no longer included <fcntl.h>
**    - fix bug in vms_args.c printing '[]' for required args and vis-a-vis
**    - fixed bug in argInput and argOutput in argtype.c
**    - fixed bug in <os>_args.c where ARGVALGIVEN was improperly being
**      cleared if the argument was a list or a vector. This was causing
**      parseargs(1) to screw up on optional lists.
**    - fixed bug in strfuncs.c:strnicmp()
**    - changed strfuncs.[ch] so that my version of strdup is always used
**      (my version dies if malloc failed, others return NULL).
**    - Added some changes for SUN and VAX
**    - Added -1 option to parseargs(1)
**    - Unhid the -# option to parseargs(1)
**    - More documentation fixes
**
**    04/04/91	Brad Appleton	<brad@ssd.csd.harris.com>
**    Patch04 (continued)
**    - fixed bug in xparse.c with PARSECNTL='Prompt' being ignored.
**    - added test.pl to test.all and added options to test.all
**    - fixed newline printing error in perl-scripts for parseargs(1)
**    - added -C option to parseargs(1) and to the docs
**    - added "patchlevel.h" to distribution
**    - added "what" string with version and patch level for parseargs(1)
**    - added hidden -# option to parseargs(1)
**    - add "doc/effects.inc" to distribution
**    - fix docs
**    - fix test.rc for Plan 9 shell
**    - fix parseargs(1) quoting for perl
**
**    03/22/91	Brad Appleton	<brad@ssd.csd.harris.com>
**    Patch03
**    - ascii docs fix
**
**    03/21/91	Brad Appleton	<brad@ssd.csd.harris.com>
**    Patch02
**    - documentation fix
**
**    03/12/91	Brad Appleton	<brad@ssd.csd.harris.com>
**    Patch01
**    - documentation fix
**
**    03/02/91	Brad Appleton	<brad@ssd.csd.harris.com>	Created
***^^********************************************************************/
X
#define  VERSION     2
#define  REVISION    0
#define  PATCHLEVEL  4
X
#ifdef __STDC__
X   static const char
#else
X   static char
#endif
X   _Ident[] = "@(#)parseargs  2.0  patchlevel 4";
SHAR_EOF
chmod 0664 patchlevel.h ||
echo 'restore of patchlevel.h failed'
Wc_c="`wc -c < 'patchlevel.h'`"
test 2409 -eq "$Wc_c" ||
	echo 'patchlevel.h: original size 2409, current size' "$Wc_c"
rm -f _shar_seq_.tmp
echo You have unpacked the last part
exit 0
exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.