rbb 99/07/27 10:58:42
Modified: apr configure.in
apr/misc/unix Makefile.in
apr/test Makefile.in
include apr_errno.h apr_general.h
Added: apr/misc/unix getopt.c
apr/test testargs.c
Log:
Added getopt function to apr. Also added program to test getopt. Tested
under
Linux, should be tested on other platforms.
Submitted by: Jim Jagielski and Ryan Bloom
Revision Changes Path
1.31 +2 -2 apache-apr/apr/configure.in
Index: configure.in
===================================================================
RCS file: /home/cvs/apache-apr/apr/configure.in,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- configure.in 1999/07/23 14:41:35 1.30
+++ configure.in 1999/07/27 17:58:27 1.31
@@ -1,6 +1,6 @@
AC_CONFIG_AUX_DIR(./helpers)
-OS=`config.guess`
-OS=`config.sub $OS`
+OS=`./config.guess`
+OS=`./config.sub $OS`
echo "Configuring APR library"
echo "Platform: ${OS}"
1.7 +2 -1 apache-apr/apr/misc/unix/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apache-apr/apr/misc/unix/Makefile.in,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Makefile.in 1999/07/23 14:41:41 1.6
+++ Makefile.in 1999/07/27 17:58:31 1.7
@@ -16,7 +16,7 @@
LIB=../libmisc.a
-OBJS=start.o
+OBJS=start.o getopt.o
.c.o:
$(CC) $(CFLAGS) -c $(INCLUDES) $<
@@ -51,6 +51,7 @@
&& rm Makefile.new
# DO NOT REMOVE
+getopt.o: getopt.c
start.o: start.c ../../../include/apr_general.h \
$(INCDIR)/apr_config.h ../../../include/apr_errno.h \
$(INCDIR)/apr_pools.h $(INCDIR)/apr_lib.h \
1.1 apache-apr/apr/misc/unix/getopt.c
Index: getopt.c
===================================================================
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc.h"
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""
/*
* getopt --
* Parse argc/argv argument vector.
*/
ap_status_t ap_getopt(struct context_t *cont, int nargc, char *const *nargv,
const char *ostr, ap_int32_t *rv)
{
char *p;
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
*rv = optopt;
return (APR_EOF);
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
*rv = optopt;
return (APR_EOF);
}
} /* option letter okay? */
if ((optopt = (int) *place++) == (int) ':' ||
!(oli = strchr(ostr, optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (optopt == (int) '-')
*rv = optopt;
return (APR_EOF);
if (!*place)
++optind;
if (opterr && *ostr != ':') {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
"%s: illegal option -- %c\n", p, optopt);
}
*rv = optopt;
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
*rv = optopt;
return (APR_BADARG);
if (opterr) {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void) fprintf(stderr,
"%s: option requires an argument -- %c\n",
p, optopt);
}
*rv = optopt;
return (APR_BADCH);
}
else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
*rv = optopt;
return APR_SUCCESS;
}
1.13 +30 -12 apache-apr/apr/test/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apache-apr/apr/test/Makefile.in,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Makefile.in 1999/07/23 14:41:45 1.12
+++ Makefile.in 1999/07/27 17:58:34 1.13
@@ -20,7 +20,8 @@
[EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
- [EMAIL PROTECTED]@
+ [EMAIL PROTECTED]@ \
+ [EMAIL PROTECTED]@
OBJS= testfile.o \
testproc.o \
@@ -28,8 +29,8 @@
testthread.o \
ab_apr.o \
testtime.o \
- testsig.o
-
+ testsig.o \
+ testargs.o
.c.o:
$(CC) -c $(CFLAGS) $(INCLUDES) $<
@@ -38,6 +39,9 @@
[EMAIL PROTECTED]@: testfile.o
$(CC) $(CFLAGS) testfile.o -o [EMAIL PROTECTED]@ $(LDFLAGS)
[EMAIL PROTECTED]@: testargs.o
+ $(CC) $(CFLAGS) testargs.o -o [EMAIL PROTECTED]@ $(LDFLAGS)
+
[EMAIL PROTECTED]@: ab_apr.o
$(CC) $(CFLAGS) ab_apr.o -o [EMAIL PROTECTED]@ $(LDFLAGS)
@@ -82,22 +86,36 @@
# DO NOT REMOVE
ab_apr.o: ab_apr.c ../../include/apr_network_io.h \
- ../../include/apr_general.h ../../include/apr_errno.h \
- ../../include/apr_file_io.h
+ ../../include/apr_general.h $(INCDIR)/apr_config.h \
+ ../../include/apr_errno.h ../../include/apr_file_io.h
client.o: client.c ../../include/apr_network_io.h \
- ../../include/apr_general.h ../../include/apr_errno.h
+ ../../include/apr_general.h $(INCDIR)/apr_config.h \
+ ../../include/apr_errno.h
server.o: server.c ../../include/apr_network_io.h \
- ../../include/apr_general.h ../../include/apr_errno.h
+ ../../include/apr_general.h $(INCDIR)/apr_config.h \
+ ../../include/apr_errno.h
+testargs.o: testargs.c ../../include/apr_file_io.h \
+ ../../include/apr_general.h $(INCDIR)/apr_config.h \
+ ../../include/apr_errno.h $(INCDIR)/apr_lib.h $(INCDIR)/hsregex.h
testfile.o: testfile.c ../../include/apr_file_io.h \
- ../../include/apr_general.h ../../include/apr_errno.h
+ ../../include/apr_general.h $(INCDIR)/apr_config.h \
+ ../../include/apr_errno.h $(INCDIR)/apr_lib.h $(INCDIR)/hsregex.h
testproc.o: testproc.c ../../include/apr_thread_proc.h \
../../include/apr_file_io.h ../../include/apr_general.h \
- ../../include/apr_errno.h
+ $(INCDIR)/apr_config.h ../../include/apr_errno.h \
+ $(INCDIR)/apr_win.h $(INCDIR)/apr_lib.h $(INCDIR)/hsregex.h
+testsig.o: testsig.c ../../include/apr_thread_proc.h \
+ ../../include/apr_file_io.h ../../include/apr_general.h \
+ $(INCDIR)/apr_config.h ../../include/apr_errno.h \
+ $(INCDIR)/apr_win.h $(INCDIR)/apr_lib.h $(INCDIR)/hsregex.h
testsock.o: testsock.c ../../include/apr_thread_proc.h \
../../include/apr_file_io.h ../../include/apr_general.h \
- ../../include/apr_errno.h
+ $(INCDIR)/apr_config.h ../../include/apr_errno.h \
+ $(INCDIR)/apr_win.h $(INCDIR)/apr_lib.h $(INCDIR)/hsregex.h
testthread.o: testthread.c ../../include/apr_thread_proc.h \
../../include/apr_file_io.h ../../include/apr_general.h \
- ../../include/apr_errno.h ../../include/apr_lock.h
+ $(INCDIR)/apr_config.h ../../include/apr_errno.h \
+ $(INCDIR)/apr_win.h ../../include/apr_lock.h
testtime.o: testtime.c ../../include/apr_time.h \
- ../../include/apr_general.h ../../include/apr_errno.h
+ ../../include/apr_general.h $(INCDIR)/apr_config.h \
+ ../../include/apr_errno.h
1.1 apache-apr/apr/test/testargs.c
Index: testargs.c
===================================================================
/* ====================================================================
* Copyright (c) 1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
#include <stdio.h>
#include "apr_file_io.h"
#include "apr_errno.h"
#include "apr_general.h"
#include "apr_lib.h"
#ifdef BEOS
#include <unistd.h>
#endif
int main(int argc, char * const argv[])
{
ap_context_t *context;
ap_int32_t data;
ap_create_context(NULL, NULL, &context);
while (ap_getopt(context, argc, argv, "abc:d::", &data) == APR_SUCCESS) {
switch(data) {
case 'a':
case 'b':
printf("option %c\n", data);
break;
case 'c':
printf("option %c with %s\n", data, optarg);
break;
case 'd':
printf("option %c", data);
if (optarg) {
printf(" with %s\n", optarg);
}
else {
printf("\n");
}
break;
}
}
}
1.21 +3 -0 apache-apr/include/apr_errno.h
Index: apr_errno.h
===================================================================
RCS file: /home/cvs/apache-apr/include/apr_errno.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- apr_errno.h 1999/06/22 16:57:38 1.20
+++ apr_errno.h 1999/07/27 17:58:37 1.21
@@ -409,6 +409,9 @@
#define APR_ALLSTD 5009
#define APR_STDOUT 5010
#define APR_STDERR 5011
+#define APR_BADCH 5012
+#define APR_BADARG 5013
+#define APR_EOF 5014
#ifdef __cplusplus
}
1.24 +3 -0 apache-apr/include/apr_general.h
Index: apr_general.h
===================================================================
RCS file: /home/cvs/apache-apr/include/apr_general.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- apr_general.h 1999/07/14 11:57:47 1.23
+++ apr_general.h 1999/07/27 17:58:38 1.24
@@ -224,6 +224,9 @@
ap_status_t ap_send_signal(ap_context_t *, ap_signum_t);
ap_status_t ap_setup_signal(ap_context_t *, ap_signum_t, Sigfunc *);
+ap_status_t ap_getopt(ap_context_t *, ap_int32_t, char *const *, const char
*,
+ ap_int32_t *);
+
#ifdef __cplusplus
}
#endif