[net.sources] Looking for a PD getopt?

toma@killer.UUCP (Tom Armistead) (04/17/87)

Is there a version of getopt in the Public Domain - not the one used by
Shell but the function. getopt(3) I think???

Anyway, anything would appreciated!!!

Thanks,
Tom
UUCP:           ihnp4\
                      \killer!toma
  infoswx!convex!dj3b1/
Tom Armistead

gwyn@brl-smoke.ARPA (Doug Gwyn ) (04/21/87)

In article <778@killer.UUCP> toma@killer.UUCP (Tom Armistead) writes:
>Is there a version of getopt in the Public Domain - not the one used by
>Shell but the function. getopt(3) I think???

AT&T placed their implementation of getopt(3) into the public domain as a
special exception to their general proprietary calims for their software.
If you're registered with the UNIX System ToolChest, you can get a copy
for just the transmission fee.  It differs from the SVR2.0 version only
in the copyright notices (and perhaps SCCS ID).

mohamed@hscfvax.UUCP (750025@Mohamed_el_Lozy) (04/22/87)

In article <5779@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <778@killer.UUCP> toma@killer.UUCP (Tom Armistead) writes:
>>Is there a version of getopt in the Public Domain - not the one used by
>>Shell but the function. getopt(3) I think???
>
>AT&T placed their implementation of getopt(3) into the public domain as a
>special exception to their general proprietary calims for their software.
>If you're registered with the UNIX System ToolChest, you can get a copy
>for just the transmission fee.  It differs from the SVR2.0 version only
>in the copyright notices (and perhaps SCCS ID).

There are two public domain getopt(3) implementations in the mod.sources
archives, one of them the AT&T one.

rs@mirror.TMC.COM (Rich Salz) (04/22/87)

The getopt available through the AT&T Toolchest is identical to the
source released at the Dallas 1985 UniForum, except that it contains
(past tense?) a notice about declaring it to be "unpublished
proprietary source code of AT&T" -- you go figure it out.

Anyhow here's the public version, as published in comp.std.unix (nee
mod.std.unix) and mod.sources (soon to be comp.sources.unix) some time
ago.

If someone would write a public-domain manpage, that'd be great.
	/r$
-------------------------------------------------------
Newsgroups: mod.std.unix
Subject: public domain AT&T getopt source
Date: 3 Nov 85 19:34:15 GMT

Here's something you've all been waiting for:  the AT&T public domain
source for getopt(3).  It is the code which was given out at the 1985
UNIFORUM conference in Dallas.  I obtained it by electronic mail
directly from AT&T.  The people there assure me that it is indeed
in the public domain.

There is no manual page.  That is because the one they gave out at
UNIFORUM was slightly different from the current System V Release 2
manual page.  The difference apparently involved a note about the
famous rules 5 and 6, recommending using white space between an option
and its first argument, and not grouping options that have arguments.
Getopt itself is currently lenient about both of these things:  White
space is allowed, but not mandatory, and the last option in a group can
have an argument.  That particular version of the man page evidently
has no official existence, and my source at AT&T did not send a copy.
The current SVR2 man page reflects the actual behavor of this getopt.
However, I am not about to post a copy of anything licensed by AT&T.

...

#! /bin/sh
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
# If this archive is complete, you will see the message:
#		"End of shell archive."
# Contents:  getopt.c
# Wrapped by rs@mirror on Wed Apr 22 10:40:53 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
echo shar: Extracting \"getopt.c\" \(1247 characters\)
if test -f getopt.c ; then 
  echo shar: Will not over-write existing file \"getopt.c\"
else
sed "s/^X//" >getopt.c <<'END_OF_getopt.c'
X/*LINTLIBRARY*/
X#define NULL	0
X#define EOF	(-1)
X#define ERR(s, c)	if(opterr){\
X	extern int strlen(), write();\
X	char errbuf[2];\
X	errbuf[0] = c; errbuf[1] = '\n';\
X	(void) write(2, argv[0], (unsigned)strlen(argv[0]));\
X	(void) write(2, s, (unsigned)strlen(s));\
X	(void) write(2, errbuf, 2);}
X
Xextern int strcmp();
Xextern char *strchr();
X
Xint	opterr = 1;
Xint	optind = 1;
Xint	optopt;
Xchar	*optarg;
X
Xint
Xgetopt(argc, argv, opts)
Xint	argc;
Xchar	**argv, *opts;
X{
X	static int sp = 1;
X	register int c;
X	register char *cp;
X
X	if(sp == 1)
X		if(optind >= argc ||
X		   argv[optind][0] != '-' || argv[optind][1] == '\0')
X			return(EOF);
X		else if(strcmp(argv[optind], "--") == NULL) {
X			optind++;
X			return(EOF);
X		}
X	optopt = c = argv[optind][sp];
X	if(c == ':' || (cp=strchr(opts, c)) == NULL) {
X		ERR(": illegal option -- ", c);
X		if(argv[optind][++sp] == '\0') {
X			optind++;
X			sp = 1;
X		}
X		return('?');
X	}
X	if(*++cp == ':') {
X		if(argv[optind][sp+1] != '\0')
X			optarg = &argv[optind++][sp+1];
X		else if(++optind >= argc) {
X			ERR(": option requires an argument -- ", c);
X			sp = 1;
X			return('?');
X		} else
X			optarg = argv[optind++];
X		sp = 1;
X	} else {
X		if(argv[optind][++sp] == '\0') {
X			sp = 1;
X			optind++;
X		}
X		optarg = NULL;
X	}
X	return(c);
X}
END_OF_getopt.c
if test 1247 -ne `wc -c <getopt.c`; then
    echo shar: \"getopt.c\" unpacked with wrong size!?
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
--
Rich $alz					"Drug tests p**s me off"
Mirror Systems, Cambridge Massachusetts		rs@mirror.TMC.COM
{cbosgd, cca.cca.com, harvard!wjh12, ihnp4, mit-eddie, seismo}!mirror!rs