-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previous svn history is currently inaccessible. Starting git repository at current state... Signed-off-by: Kevin Locke <[email protected]>
- Loading branch information
0 parents
commit 277f313
Showing
19 changed files
with
1,795 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Authors of ultragetopt. | ||
See also the files THANKS and ChangeLog. | ||
|
||
ultragetopt is being actively developed by: | ||
Kevin Locke <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
This file documents known bugs/limitations of the software. | ||
|
||
* GNU getopt() handles option permutation somewhat differently. It shifts | ||
options around on calls subsequent to actually returning the next option (so | ||
cmd word -a) would return -a then on the next call shift the command line to | ||
read cmd -a word and return -1. It therefore also has different values for | ||
optind than ultragetopt in these cases. If there is a use case that requires | ||
this behavior, please let the maintainer know about it so that a change to | ||
ultragetopt to mimic this behavior can be considered. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2007, Kevin Locke <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
2007-06-23 12:55 Kevin Locke <[email protected]> | ||
|
||
* configure.ac: Bump version | ||
* ultragetopt.h: Renamed UGO_LONGONLY to UGO_SINGLELEADERLONG | ||
* ultragetopt.h: Added UGO_SINGLELEADERONLY to force all long options | ||
to be recognized only if they have a single leader character | ||
* ultragetopt.c: Integrated the above flag changes into the source | ||
|
||
2007-03-27 02:34 kevin | ||
|
||
* Makefile.am: Add Visual Studio build files to distribution files | ||
* configure.ac: Add checks for index() and rindex() | ||
* ultragetopt.c: Corrected strnicasecmp typo in ultragetopt.c and | ||
improper check for STR{C,}CHR without replacement check | ||
* ultragetopt.rc: New resources file for DLL versioning | ||
* ultragetopt.sln, ultragetopt.vcproj: New Visual Studio build files | ||
|
||
2007-03-26 21:38 Kevin Locke <[email protected]> | ||
|
||
* configure.ac: Added libtool for configuration | ||
* Makefile.am: Added libtool for building | ||
* ultragetopt.h: Added C++ checks | ||
* ultragetopt.c: Added better function checks based on autoconf | ||
|
||
2007-03-24 10:51 Kevin Locke <[email protected]> | ||
|
||
* *.*: Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
To install ultragetopt as a shared library, run | ||
|
||
./configure | ||
make | ||
make install | ||
|
||
where the final command is run with the necessary privileges (depending on the | ||
prefix argument given to configure or to access /usr/local if none specified). | ||
|
||
To include ultragetopt as part of a software package, simply copy | ||
ultragetopt.{c,h} into the appropriate directory and include it in the build | ||
scripts for the software package. To use ultragetopt*() functions as | ||
replacements for getopt(), define ULTRAGETOPT_REPLACE_GETOPT before including | ||
"ultragetopt.h". (Note: If you really need the opt* variables to not be | ||
macros, simply run sed 's/ultra//g' on the ultragetopt source files and do not | ||
define ULTRAGETOPT_REPLACE_GETOPT when including ultragetopt.h) | ||
|
||
Note also, for including ultragetopt.c as part of a software package, if | ||
targeted systems may not provide strcasecmp or strncasecmp you must provide a | ||
replacement for these functions. For systems (such as Windows) that provide | ||
_stricmp and _strnicmp, define HAVE__STRICMP and HAVE__STRNICMP and those | ||
functions will perform the needed function (for autoconf, this can be | ||
accomplished with AC_CHECK_FUNCS([strcasecmp strnicasecmp _stricmp _strnicmp]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Makefile.am - Script used in combination with automake to produce Makefile.in | ||
|
||
include_HEADERS = ultragetopt.h | ||
lib_LTLIBRARIES = libultragetopt.la | ||
libultragetopt_la_SOURCES = ultragetopt.h ultragetopt.c | ||
libultragetopt_la_LDFLAGS = -version-info 0:0:0 | ||
|
||
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure $(AUX_DIST) | ||
|
||
EXTRA_DIST = autogen.sh \ | ||
BUGS \ | ||
ultragetopt.rc \ | ||
ultragetopt.sln \ | ||
ultragetopt.vcproj \ | ||
tests/getopt.c \ | ||
tests/testargs.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ultragetopt -- History of visible changes. | ||
|
||
Version 0.5.0 | ||
|
||
* Initial Public Release | ||
|
||
------------------------------------------------------- | ||
Copying information: | ||
|
||
Copyright (C) 2007, Kevin Locke <[email protected]> | ||
|
||
Permission is granted to anyone to make or distribute verbatim copies | ||
of this document as received, in any medium, provided that the | ||
copyright notice and this permission notice are preserved, | ||
thus giving the recipient permission to redistribute in turn. | ||
|
||
Permission is granted to distribute modified versions | ||
of this document, or of portions of it, | ||
under the above conditions, provided also that they | ||
carry prominent notices stating who last changed them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
Welcome to UltraGetopt | ||
|
||
UltraGetopt is a replacement for getopt() with support for many common | ||
extensions, MS-DOS formatted option strings, and much more. UltraGetopt is | ||
free software. Please see the file COPYING for details. For building, | ||
installation, and usage instructions please see the INSTALL file. | ||
|
||
==== DEFINES ==== | ||
When compiling ultragetopt.c, there are several defines that change the default | ||
behavior of the (ultra)getopt functions. | ||
|
||
Meta-options: | ||
These options will set the other options below to appropriate values to mimic | ||
the functionality of other getopt suites. | ||
ULTRAGETOPT_LIKE_BSD | ||
Behave like BSD getopt() | ||
ULTRAGETOPT_LIKE_DARWIN | ||
Behave like Darwin (Mac OS) getopt() | ||
ULTRAGETOPT_LIKE_GNU | ||
Behave like GNU getopt() | ||
ULTRAGETOPT_LIKE_POSIX | ||
Behave like POSIX definition of getopt() | ||
|
||
Compiletime-only Behavior Options: | ||
These options change the default behavior of getopt() and do not have a | ||
corresponding runtime flag (although they may be affected by other arguments). | ||
ULTRAGETOPT_ASSIGNSPACE | ||
Parse "-o value" as "value" rather than " value" | ||
Note: Only applicable when argv[x] == "-o value", not for | ||
argv[x] == "-o" [x+1] == "value" | ||
ULTRAGETOPT_NO_OPTIONALARG | ||
Do not support GNU "::" optional argument. | ||
Note: Always supported in *_long*() functions. | ||
ULTRAGETOPT_NO_OPTIONASSIGN | ||
Do not support --option=value syntax | ||
|
||
Runtime-selectable options: | ||
These options can all be selected by passing their value as a flag to the | ||
ultragetopt_tunable() function, where ULTRAGETOPT_ is replaced by UGO_ for | ||
compactness of the source. Defining these values sets the default state of | ||
the flag when invoked from ultragetopt{_long,_dos}(). | ||
ULTRAGETOPT_DEFAULTOPTOPT | ||
Set optopt to this value by default on each call to getopt() | ||
ULTRAGETOPT_HYPHENARG | ||
Accept -option -arg as -option with argument "-arg" rather than -option | ||
missing argument | ||
ULTRAGETOPT_LONGOPTADJACENT | ||
Accept adjacent arguments to long options (e.g. --optionarg) based on | ||
first longest-match | ||
ULTRAGETOPT_OPTIONPERMUTE | ||
Permute options, do not stop at first non-option. A leading '+' in | ||
shortopts or when the $POSIXLY_CORRECT environmental variable are set, | ||
permuting will be stopped @ runtime | ||
ULTRAGETOPT_SHORTOPTASSIGN | ||
Support -o=file syntax for short options | ||
ULTRAGETOPT_SEPARATEDOPTIONAL | ||
Accept separated optional arguments. Parse -o file as -o with argument | ||
file rather than -o without an argument and non-option argument "file" | ||
ULTRAGETOPT_DOS_DASH | ||
Support - and -- options in ultragetopt*_dos() functions | ||
ULTRAGETOPT_NO_EATDASHDASH | ||
Do not increment optind when argv[optind] is -- as required by SUS/POSIX | ||
|
||
Error message options: | ||
These options change the formatting of the error messages produced by | ||
ultragetopt. | ||
ULTRAGETOPT_BSD_ERRORS | ||
Print error messages matching BSD getopt | ||
ULTRAGETOPT_DARWIN_ERRORS | ||
Print error messages matching Darwin getopt | ||
ULTRAGETOPT_GNU_ERRORS | ||
Print error messages matching GNU getopt | ||
|
||
|
||
==== CONTACT ==== | ||
If you have any suggestions, ideas, bugs, incompatibilities with existing getopt | ||
implementations, or other feedback please don't hesitate to let the current | ||
maintainer(s) know about it. (Contact information for the current maintainer | ||
is listed in AUTHORS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ultragetopt THANKS file | ||
|
||
Here is a (partial) list of the people who have contributed to ultragetopt: | ||
|
||
* Peter Nix - Thanks for helping to test the Darwin getopt behavior | ||
|
||
If someone has been overlooked, please contact the maintainer(s) of this project | ||
to make sure this file is updated. Thanks! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
This file contains a list of things that need work (or are being considered). | ||
Anyone can feel free to add thoughts for future features or plans for the | ||
software as they wish. This file is just for brainstorming and documenting | ||
ideas that have been proposed. | ||
|
||
* Create a thorough test script/framework and run on all variants of getopt | ||
that you can find and report on incompatibilities | ||
* Create man page? Are there systems using man pages that don't have getopt() | ||
documentation already? Would a separate ultragetopt man page be useful? | ||
* Compiled help file? Do Windows developers use these things? | ||
* Implement some/all of the features of egetopt()? | ||
http://groups.google.com/group/alt.sources/browse_thread/thread/13aa167188322555/b8912a259599366f%23b8912a259599366f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
set -x | ||
|
||
# Remove the auto* files and get fresh copies | ||
rm -f aclocal.m4 config.* depcomp install-sh missing ltmain.sh | ||
rm -rf autom4te.cache | ||
#rm -rf intl | ||
#gettextize --intl --no-changelog < /dev/null | ||
#mv configure.ac~ configure.ac | ||
#mv Makefile.am~ Makefile.am | ||
aclocal #-I m4 | ||
#autoheader | ||
libtoolize --copy | ||
automake --add-missing --copy | ||
autoconf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# configure.ac - Used with autoconf to create configure script | ||
# This script is part of ultragetopt, see COPYING for licensing details | ||
|
||
# Initialize and configure | ||
AC_INIT([ultragetopt], [0.6.0], [Kevin Locke <[email protected]>]) | ||
AC_CONFIG_SRCDIR([ultragetopt.c]) | ||
# AC_CONFIG_HEADER([src/config.h]) | ||
AC_CONFIG_FILES([Makefile]) | ||
# AC_GNU_SOURCE | ||
AM_INIT_AUTOMAKE | ||
|
||
# Support Windows DLL later... | ||
#AC_LIBTOOL_WIN32_DLL | ||
|
||
# Prevent AC_PROG_LIBTOOL from checking for C++, Fortran, and Java | ||
# this hack should be unnecessary soon | ||
m4_defun([_LT_AC_LANG_CXX_CONFIG], [:]) | ||
m4_defun([_LT_AC_LANG_F77_CONFIG], [:]) | ||
m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:]) | ||
|
||
# Checks for programs. | ||
AC_PROG_CC | ||
AC_PROG_LIBTOOL | ||
|
||
# Checks for header files. | ||
#AC_HEADER_STDC | ||
#AC_CHECK_HEADERS([stdarg.h stdlib.h string.h]) | ||
|
||
# Checks for typedefs, structures, and compiler characteristics. | ||
AC_C_CONST | ||
AC_TYPE_SIZE_T | ||
|
||
# Checks for libraries. | ||
|
||
# Checks for library functions. | ||
# Note: Could add replacements and get more advanced here but need | ||
# ultragetopt.c to work in standard build systems with little fuss | ||
#AC_REPLACE_FUNCS([strcasecmp strncasecmp]) | ||
AC_CHECK_FUNCS([strchr index], [break]) | ||
AC_CHECK_FUNCS([strrchr rindex], [break]) | ||
AC_CHECK_FUNCS([strcasecmp _stricmp], [break]) | ||
AC_CHECK_FUNCS([strncasecmp _strnicmp], [break]) | ||
|
||
AC_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <getopt.h> | ||
|
||
#ifdef ULTRAGETOPT_REPLACE_GETOPT | ||
#include "ultragetopt.h" | ||
#endif | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
struct option *longopts; | ||
char *shortopts, *name, *cur; | ||
int c, i, count; | ||
int longind = -1; | ||
|
||
if (argc < 4) { | ||
printf("Usage: %s <shortopts> <longopts> [args]\n", argv[0]); | ||
printf("<shortopts>\tString of shortopts to pass to getopt()\n"); | ||
printf("<longopts>\tSpace-separated list of long options.\n" | ||
"\t\tsame : notation for arguments as short options\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
shortopts = argv[1]; | ||
|
||
/* Count the number of long options passed */ | ||
cur = argv[2]; | ||
count = 2; /* For {0,0,0,0} */ | ||
while (*cur) | ||
if (*cur++ == ' ') | ||
count++; | ||
longopts = malloc(sizeof(struct option) * count); | ||
if (!longopts) { | ||
fprintf(stderr, "Unable to allocate memory for long options.\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
name = strtok(argv[2], " "); | ||
for (i=0; name != NULL; i++) { | ||
size_t namelen = strlen(name); | ||
if (namelen > 0 && name[namelen-1] == ':') { | ||
if (namelen > 1 && name[namelen-2] == ':') { | ||
longopts[i].has_arg = optional_argument; | ||
name[namelen-2] = '\0'; | ||
} else { | ||
longopts[i].has_arg = required_argument; | ||
name[namelen-1] = '\0'; | ||
} | ||
} else | ||
longopts[i].has_arg = no_argument; | ||
|
||
longopts[i].name = name; | ||
longopts[i].flag = 0; | ||
longopts[i].val = name[0]; | ||
|
||
name = strtok(NULL, " "); | ||
} | ||
assert(i < count); | ||
longopts[i].name = 0; | ||
longopts[i].has_arg = 0; | ||
longopts[i].flag = 0; | ||
longopts[i].val = 0; | ||
|
||
while ((c = getopt_long(argc-3, argv+3, shortopts, longopts, | ||
&longind)) != -1) { | ||
switch (c) { | ||
case 0: | ||
printf("Encountered option '%s' with arg '%s', flag set.\n", | ||
longopts[longind].name, optarg); | ||
break; | ||
case ':': | ||
printf("Encountered option '%c' missing argument\n", optopt); | ||
break; | ||
case '?': | ||
printf("Encountered unexpected option '%c'\n", optopt); | ||
break; | ||
default: | ||
printf("Encountered option '%c' with argument '%s'\n", | ||
c, optarg); | ||
break; | ||
} | ||
|
||
printf("optind=%d\topterr=%d\toptopt=%d\toptarg='%s'\tlongind='%d'\n", | ||
optind, opterr, optopt, optarg, longind); | ||
|
||
for (i=3; i<argc; i++) | ||
printf("argv[%d] = %s\n", i-3, argv[i]); | ||
} | ||
|
||
/* Print any remaining command line arguments (not options). */ | ||
if (optind+3 < argc) { | ||
printf("Remaining arguments: "); | ||
while (optind+3 < argc) { | ||
printf("'%s' ", argv[optind+3]); | ||
optind++; | ||
} | ||
putchar('\n'); | ||
} | ||
|
||
free(longopts); | ||
|
||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.