Permalink
Browse files

Initial commit for getopt-1.1.4.

  • Loading branch information...
1 parent 179c37d commit 37df18556ec6120f93c0def08e8ffe60ceb0d223 @hungc hungc committed Dec 9, 2011
Showing with 5,025 additions and 0 deletions.
  1. +339 −0 COPYING
  2. +38 −0 Changelog
  3. +108 −0 Makefile
  4. +54 −0 Makefile.util-linux
  5. +81 −0 README
  6. +8 −0 TODO
  7. +16 −0 getopt-1.1.4.lsm
  8. +47 −0 getopt-parse.bash
  9. +77 −0 getopt-parse.tcsh
  10. +6 −0 getopt-test.bash
  11. +7 −0 getopt-test.tcsh
  12. +441 −0 getopt.1
  13. +470 −0 getopt.c
  14. +1,050 −0 gnu/getopt.c
  15. +131 −0 gnu/getopt.h
  16. +187 −0 gnu/getopt1.c
  17. +49 −0 nls.h
  18. +237 −0 po/cs.po
  19. +250 −0 po/de.po
  20. +240 −0 po/es.po
  21. +246 −0 po/fr.po
  22. +239 −0 po/it.po
  23. +239 −0 po/ja.po
  24. +225 −0 po/nl.po
  25. +240 −0 po/pt_BR.po
View
339 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,38 @@
+20051107: Bumped up version number to 1.1.4
+20051107: Makefile: package target
+20051107: Changed email and website to current ones
+20051107: Fixed a few typos in the manpage (sync with util-linux (2.12r)
+20030123: Bumped up version number to 1.1.3
+20030123: Changed WITH_GETTEXT option to WITHOUT_GETTEXT
+20030123: Renamed example programs to have the string getopt- prepended
+20030123: Manpage: all minus signs are now escaped
+20030123: Sync with util-linux (2.11y)
+20010329: Bumped up version number to 1.1.2
+20010329: Sync with util-linux
+20010311: Bumped up version number to 1.1.1
+20010311: Fixed stupid compilation error if NLS not selected
+20000630: Bumped up version number to 1.1.0
+20000630: Ported the Native Language Support patches from util-linux
+ They are written by Arkadiusz Mi�kiewicz <misiek@pld.org.pl>
+20000627: Bumped up version number to 1.0.6
+20000627: A few manpage tweaks
+20000616: Introduced DESTDIR and directory creation in the Makefile.
+19990716: Bumped up version number to 1.0.5
+19990622: Made -u work
+19990101: Bumped up version number to 1.0.4 (aka. 1.0.3a in util-linux)
+19990101: Very small fix in main()
+19990101: Updated util-linux Makefile
+19980628: Bumped up version number to 1.0.3
+19980628: Removed remaining incompatibility with tcsh-6.02 from parse.tcsh
+980626: Added separate Makefile for util-linux
+19980625: Removed several bugs from parse.tcsh, partly thanks to Volker Kuhlmann
+ (v.kuhlmann@elec.canterbury.ac.nz).
+19980612: Removed reference to getopt in util-linux
+19980611: Bumped up version number to 1.0.2
+19980611: Fixed --version bug (was not available, though documented!)
+19980611: Removed compiler warnings.
+19980603: Bumped up version number to 1.0.1
+19980603: Fixed sizeof() bug (should be strlen) in getopt.c, thanks to
+ Bob Proulx (rwp@hprwp.fc.hp.com).
+19980505: Changed date field in LSM to proper syntax
+19980505: Released version 1.0
View
108 Makefile
@@ -0,0 +1,108 @@
+.SUFFIXES:
+
+DESTDIR=
+prefix=/usr/local
+bindir=$(prefix)/bin
+mandir=$(prefix)/man
+man1dir=$(mandir)/man1
+libdir=$(prefix)/lib
+sharedir=$(prefix)/share
+getoptdir=$(libdir)/getopt
+localedir=$(sharedir)/locale
+
+# Define this to 0 to use the getopt(3) routines in this package.
+LIBCGETOPT=1
+
+# Define this to 1 if you do not have the gettext routines
+WITHOUT_GETTEXT=0
+
+# For creating the archive
+PACKAGE=getopt
+VERSION=1.1.4
+BASENAME=$(PACKAGE)-$(VERSION)
+UNLIKELYNAME=a8vwjfd92
+
+SHELL=/bin/sh
+
+CC=gcc
+LD=ld
+RM=rm -f
+INSTALL=install
+MSGFMT=msgfmt
+
+LANGUAGES = cs de es fr it ja nl pt_BR
+MOFILES:=$(patsubst %,po/%.mo,$(LANGUAGES))
+
+CPPFLAGS=-DLIBCGETOPT=$(LIBCGETOPT) -DWITH_GETTEXT=$(WITH_GETTEXT) -DLOCALEDIR=\"$(localedir)\" -DNOT_UTIL_LINUX
+ifeq ($(LIBCGETOPT),0)
+CPPFLAGS+=-I./gnu
+endif
+WARNINGS=-Wall \
+ -W -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-qual \
+ -Wcast-align -Wmissing-declarations \
+ -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes \
+ -Wnested-externs -Winline
+OPTIMIZE=-O3 -fno-strength-reduce
+CFLAGS=$(WARNINGS) $(OPTIMIZE)
+LDFLAGS=
+
+sources=getopt.c
+ifeq ($(LIBCGETOPT),0)
+sources+=gnu/getopt.c gnu/getopt1.c
+endif
+
+objects=$(sources:.c=.o)
+
+binaries=getopt
+
+.PHONY: all clean realclean
+all: $(binaries) all_po
+
+clean: clean_po
+ -$(RM) $(objects) $(binaries)
+
+getopt: $(objects)
+ $(CC) $(LDFLAGS) -o $@ $(objects)
+
+install: getopt install_po
+ $(INSTALL) -m 755 -d $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir)
+ $(INSTALL) -m 755 getopt $(DESTDIR)$(bindir)
+ $(INSTALL) -m 644 getopt.1 $(DESTDIR)$(man1dir)
+
+install_doc:
+ $(INSTALL) -m 755 -d $(DESTDIR)$(getoptdir)
+ $(INSTALL) -m 755 getopt-parse.bash getopt-parse.tcsh \
+ getopt-test.bash getopt-test.tcsh \
+ $(DESTDIR)$(getoptdir)
+
+ifeq ($(WITH_GETTEXT),1)
+all_po: $(MOFILES)
+install_po: all_po
+ $(INSTALL) -m 755 -d $(DESTDIR)$(localedir)
+ for lang in $(LANGUAGES) ; do \
+ dir=$(localedir)/$$lang/LC_MESSAGES; \
+ $(INSTALL) -m 755 -d $(DESTDIR)$$dir ;\
+ $(INSTALL) -m 644 po/$$lang.mo $(DESTDIR)$$dir/getopt.mo ;\
+ done
+clean_po:
+ $(RM) $(MOFILES)
+else
+all_po:
+install_po:
+clean_po:
+endif
+
+%.o: %.c
+ $(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c -o $*.o
+
+%.mo: %.po
+ $(MSGFMT) -o $@ $<
+
+# You need GNU tar for this to work!
+.PHONY: package
+package: clean
+ $(RM) -r $(UNLIKELYNAME)
+ mkdir $(UNLIKELYNAME)
+ ln -s .. $(UNLIKELYNAME)/$(BASENAME)
+ cd $(UNLIKELYNAME) && tar cfvzp ../$(BASENAME).tar.gz --exclude='CVS' --exclude='*.tar.gz' --exclude=$(UNLIKELYNAME) $(BASENAME)/*
+ $(RM) -r $(UNLIKELYNAME)
View
@@ -0,0 +1,54 @@
+.SUFFIXES:
+
+include ../make_include
+include ../MCONFIG
+
+GETOPTDIR=$(USRSHAREMISCDIR)/getopt
+
+# Define this to 0 to use the getopt(3) routines in this package.
+LIBCGETOPT=1
+
+SHELL=/bin/sh
+
+LD=ld
+RM=rm -f
+INSTALL=install
+
+CPPFLAGS=-DLIBCGETOPT=$(LIBCGETOPT)
+ifeq ($(LIBCGETOPT),0)
+CPPFLAGS+=-I./gnu
+endif
+
+# -Wcast-align causes problems with the identifier stderr on alpha's
+# with an old glibc.
+# -Wbad-function-cast and -Wmissing-declarations are unknown for gcc 2.5.8.
+WARNINGS=-Wall \
+ -W -Wshadow -Wpointer-arith -Wcast-qual \
+ -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes \
+ -Wnested-externs -Winline
+# CFLAGS= $(WARNINGS) $(OPT)
+
+SOURCES=getopt.c
+ifeq ($(LIBCGETOPT),0)
+SOURCES+=gnu/getopt.c gnu/getopt1.c
+endif
+
+OBJECTS=$(SOURCES:.c=.o)
+
+BINARIES=getopt
+
+.PHONY: all clean realclean
+all: $(BINARIES)
+
+clean:
+ -$(RM) $(OBJECTS) $(BINARIES)
+
+getopt: $(OBJECTS)
+ $(CC) $(LDFLAGS) $< -o $@
+
+install: getopt
+ $(INSTALLDIR) $(USRBINDIR) $(MAN1DIR) $(GETOPTDIR)
+ $(INSTALLBIN) getopt $(USRBINDIR)
+ $(INSTALLMAN) getopt.1 $(MAN1DIR)
+ $(INSTALLBIN) getopt-parse.bash getopt-parse.tcsh \
+ getopt-test.bash getopt-test.tcsh $(GETOPTDIR)
View
81 README
@@ -0,0 +1,81 @@
+This package contains a reimplementation of getopt(1).
+
+PREFACE
+
+Getopt(1) is a program to help shell scripts parse command-line parameters.
+It is for example included in the util-linux distribution (upto version
+2.7.1). But, there are some problems with that getopt(1) implementation,
+as listed in the 'BUGS' section of its man-page:
+
+>BUGS
+> Whatever getopt(3) has.
+>
+> Arguments containing white space or imbedded shell metacharacters gener-
+> ally will not survive intact; this looks easy to fix but isn't.
+>
+> The error message for an invalid option is identified as coming from
+> getopt rather than from the shell procedure containing the invocation of
+> getopt; this again is hard to fix.
+>
+> The precise best way to use the set command to set the arguments without
+> disrupting the value(s) of shell options varies from one shell version to
+> another.
+
+This implementation of getopt(1) is written to solve some of these problems,
+while still staying (for all practical purposes) completely compatible with
+other getopt(1) implementations.
+
+
+INSTALLATION
+
+Installation should be very easy. Just type 'make' to compile the sources.
+It should compile cleanly, without any warnings, but even if it does not
+you probably don't have to worry. You must use GNU Make and gcc, or you
+will have to edit the Makefile.
+
+Type 'make install' to install the binary and the manual page. It installs
+by default in /usr/local/bin and /usr/local/man/man1, to install in /usr/bin
+and /usr/man/man1 try 'make install prefix=/usr'.
+
+The example files can be installed in /usr/local/lib/getopt by calling
+'make install_doc'.
+
+If you do not trust the getopt(3) in your libc, or if you do not use a libc
+with the GNU getopt(3) routines, you can use the gnu sources as provided
+in the gnu directory. Try 'make LIBCGETOPT=0'. Ignore any compile warnings.
+
+You can check whether the new implementation of getopt is found first
+in your path by calling 'bash test.bash'.
+
+
+HIGHLIGHTS
+
+It can do anything that the GNU getopt(3) routines can do.
+
+It can cope with spaces and shell metacharacters within arguments.
+
+It can parse long parameters.
+
+It can shuffle parameters, so you can mix options and other parameters on
+the command-line.
+
+It can be easily identified as an enhanced getopt(1) from within shell scripts.
+
+It can report parse errors as coming from the shell script.
+
+It is fully compatible with other getopt(1) implementations.
+
+COPYING
+
+This program comes under the GNU general public licence version 2. See the
+file COPYING included in this package. Note that though you may freely
+copy it, it is copyright (c) 1997-2005 by Frodo Looijaard
+<frodo@frodo.looijaard.name>.
+Files in the gnu directory are from glibc-2.0.4: copyright (C) 1987, 88,
+89, 90, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+
+
+DOWNLOADING
+
+You can find the latest version of this program at:
+ http://software.frodo.looijaard.name/getopt/
View
8 TODO
@@ -0,0 +1,8 @@
+Other shells, like zsh and ash, should be supported (perhaps they will work
+already, depending on quoting conventions). (zsh seems OK).
+
+Perhaps a nice configure script?
+
+Add a `test' target in Makefile.
+
+Resync po-files with util-linux
View
@@ -0,0 +1,16 @@
+Begin3
+Title: Getopt
+Version: 1.1.4
+Entered-date: 07Nov05
+Description: An improved implementation of getopt(1), a program to parse
+ options within a shell script. Fully compatible with other
+ getopt(1) implementations, but with many additions like
+ long options and mixing of options and parameters.
+Keywords: getopt script parse bash tcsh
+Author: frodo@frodo.looijaard.name (Frodo Looijaard)
+Primary-site: http://software.frodo.looijaard.name/getopt/
+ 28kB getopt-1.1.3.tar.gz
+ 689 getopt-1.1.3.lsm
+Copying-policy: GPL
+End
+
View
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# A small example program for using the new getopt(1) program.
+# This program will only work with bash(1)
+# An similar program using the tcsh(1) script language can be found
+# as parse.tcsh
+
+# Example input and output (from the bash prompt):
+# ./parse.bash -a par1 'another arg' --c-long 'wow!*\?' -cmore -b " very long "
+# Option a
+# Option c, no argument
+# Option c, argument `more'
+# Option b, argument ` very long '
+# Remaining arguments:
+# --> `par1'
+# --> `another arg'
+# --> `wow!*\?'
+
+# Note that we use `"$@"' to let each command-line parameter expand to a
+# separate word. The quotes around `$@' are essential!
+# We need TEMP as the `eval set --' would nuke the return value of getopt.
+TEMP=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \
+ -n 'example.bash' -- "$@"`
+
+if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
+
+# Note the quotes around `$TEMP': they are essential!
+eval set -- "$TEMP"
+
+while true ; do
+ case "$1" in
+ -a|--a-long) echo "Option a" ; shift ;;
+ -b|--b-long) echo "Option b, argument \`$2'" ; shift 2 ;;
+ -c|--c-long)
+ # c has an optional argument. As we are in quoted mode,
+ # an empty parameter will be generated if its optional
+ # argument is not found.
+ case "$2" in
+ "") echo "Option c, no argument"; shift 2 ;;
+ *) echo "Option c, argument \`$2'" ; shift 2 ;;
+ esac ;;
+ --) shift ; break ;;
+ *) echo "Internal error!" ; exit 1 ;;
+ esac
+done
+echo "Remaining arguments:"
+for arg do echo '--> '"\`$arg'" ; done
Oops, something went wrong.

0 comments on commit 37df185

Please sign in to comment.