From clauflibitFriiDump-0.5.3.1

This commit is contained in:
Braden McDaniel 2013-11-01 12:26:04 -04:00
parent fe937e7f4b
commit 87b108d6a1
63 changed files with 11067 additions and 26 deletions

50
src/CMakeLists.txt Normal file
View file

@ -0,0 +1,50 @@
# Make sure the compiler can find include files from our Hello library.
include_directories (
${FriiDump_SOURCE_DIR}/libfriidump
)
# Make sure the linker can find the Hello library once it is built.
link_directories (
${FriiDump_BINARY_DIR}/libfriidump
)
# Add executable called "helloDemo" that is built from the source files
# "demo.cxx" and "demo_b.cxx". The extensions are automatically found.
if (WIN32)
set(
additional_sources
getopt-win32.h
getopt-win32.c
getopt_long-win32.c
)
endif (WIN32)
add_executable (
friidump
friidump.c
${additional_sources}
)
# Link the executable to the Hello library.
target_link_libraries (
friidump
friidumplib
)
if (WIN32)
# We only want a version number on Windows (Is it any use?)
set_target_properties (friidump PROPERTIES VERSION 0.2)
install(
TARGETS friidump
RUNTIME DESTINATION /
)
else (WIN32)
install(
TARGETS friidump
RUNTIME DESTINATION bin
)
endif (WIN32)

11
src/Makefile.am Normal file
View file

@ -0,0 +1,11 @@
mylibdir = $(top_builddir)/libfriidump
myincludedir = $(top_srcdir)/libfriidump
bin_PROGRAMS = friidump
friidump_SOURCES = config.h.cmake friidump.c
friidump_LDADD = $(mylibdir)/libfriidump.la
friidump_LDFLAGS = $(all_libraries)
# noinst_HEADERS =
INCLUDES = $(all_includes) -I$(myincludedir)

455
src/Makefile.in Normal file
View file

@ -0,0 +1,455 @@
# Makefile.in generated by automake 1.9.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = friidump$(EXEEXT)
subdir = src
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_friidump_OBJECTS = friidump.$(OBJEXT)
friidump_OBJECTS = $(am_friidump_OBJECTS)
friidump_DEPENDENCIES = $(mylibdir)/libfriidump.la
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(friidump_SOURCES)
DIST_SOURCES = $(friidump_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
mylibdir = $(top_builddir)/libfriidump
myincludedir = $(top_srcdir)/libfriidump
friidump_SOURCES = config.h.cmake friidump.c
friidump_LDADD = $(mylibdir)/libfriidump.la
friidump_LDFLAGS = $(all_libraries)
# noinst_HEADERS =
INCLUDES = $(all_includes) -I$(myincludedir)
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
|| test -f $$p1 \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
friidump$(EXEEXT): $(friidump_OBJECTS) $(friidump_DEPENDENCIES)
@rm -f friidump$(EXEEXT)
$(LINK) $(friidump_LDFLAGS) $(friidump_OBJECTS) $(friidump_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/friidump.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS)
installdirs:
for dir in "$(DESTDIR)$(bindir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-libtool distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am:
install-exec-am: install-binPROGRAMS
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-info-am
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
clean-generic clean-libtool ctags distclean distclean-compile \
distclean-generic distclean-libtool distclean-tags distdir dvi \
dvi-am html html-am info info-am install install-am \
install-binPROGRAMS install-data install-data-am install-exec \
install-exec-am install-info install-info-am install-man \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
pdf pdf-am ps ps-am tags uninstall uninstall-am \
uninstall-binPROGRAMS uninstall-info-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

760
src/friidump.c Normal file
View file

@ -0,0 +1,760 @@
/***************************************************************************
* Copyright (C) 2007 by Arep *
* Support is provided through the forums at *
* http://wii.console-tribe.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "misc.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "disc.h"
#include "dumper.h"
#include "unscrambler.h"
#define USECS_PER_SEC 1000000
/* Name of package */
#define PACKAGE "friidump"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "arep@no.net"
/* Define to the full name of this package. */
#define PACKAGE_NAME "FriiDump"
/* Define to the version of this package. */
#define PACKAGE_VERSION "0.5.3.1"
#ifdef WIN32
#include "getopt-win32.h"
#else
#include <sys/time.h>
#include <getopt.h>
#endif
/* Struct for program options */
struct {
char *device;
bool autodump;
bool gui;
char *raw_in;
char *raw_out;
char *iso_out;
bool resume;
int dump_method;
u_int32_t command;
u_int32_t start_sector;
u_int32_t sectors_no;
u_int32_t speed;
u_int32_t disctype;
u_int32_t sec_disc;
u_int32_t sec_mem;
bool no_hashing;
bool no_unscrambling;
bool no_flushing;
bool stop_unit;
bool allmethods;
} options;
/* Struct for progress data */
typedef struct {
struct timeval start_time;
struct timeval end_time;
double mb_total;
double mb_total_real;
u_int32_t sectors_skipped;
} progstats;
void progress_for_guis (bool start, u_int32_t sectors_done, u_int32_t total_sectors, progstats *stats) {
int perc;
double elapsed, mb_done, mb_done_real, mb_hour, seconds_left;
struct timeval now;
time_t eta;
struct tm etatm;
char buf[50];
if (start) {
gettimeofday (&(stats -> start_time), NULL);
stats -> mb_total = (double) total_sectors * 2064 / 1024 / 1024;
stats -> mb_total_real = (double) (total_sectors - sectors_done) * 2064 / 1024 / 1024;
stats -> sectors_skipped = sectors_done;
} else {
perc = (int) (100.0 * sectors_done / total_sectors);
gettimeofday (&now, NULL);
elapsed = difftime (now.tv_sec, (stats -> start_time).tv_sec);
mb_done = (double) sectors_done * 2064 / 1024 / 1024;
mb_done_real = (double) (sectors_done - stats -> sectors_skipped) * 2064 / 1024 / 1024;
mb_hour = mb_done_real / elapsed * 60 * 60;
seconds_left = stats -> mb_total_real / mb_hour * 60 * 60;
eta = (time_t) ((stats -> start_time).tv_sec + seconds_left);
if (localtime_r (&eta, &etatm))
strftime (buf, 50, "%d/%m/%Y %H:%M:%S", &etatm);
else
sprintf (buf, "N/A");
/* This is the only thing we print to stdout, so that other programs can easily capture and parse our output */
fprintf (stdout, "%d%%|%u/%u sectors|%.2lf/%.0lf MB|%.0lf/%.0lf seconds|%.2lf MB/h|%s\n",
perc, sectors_done, total_sectors, mb_done, stats -> mb_total, elapsed, seconds_left, mb_hour, buf);
fflush (stdout);
}
/* Save return time, in case this will be the last call */
gettimeofday (&(stats -> end_time), NULL);
return;
}
void progress (bool start, u_int32_t sectors_done, u_int32_t total_sectors, progstats *stats) {
int perc, i;
double elapsed, mb_done, mb_done_real, mb_hour, seconds_left;
struct timeval now;
time_t eta;
struct tm etatm;
char buf[50];
if (start) {
gettimeofday (&(stats -> start_time), NULL);
stats -> mb_total = (double) total_sectors * 2064 / 1024 / 1024;
stats -> mb_total_real = (double) (total_sectors - sectors_done) * 2064 / 1024 / 1024;
stats -> sectors_skipped = sectors_done;
} else {
perc = (int) (100.0 * sectors_done / total_sectors);
gettimeofday (&now, NULL);
elapsed = difftime (now.tv_sec, (stats -> start_time).tv_sec);
mb_done = (double) sectors_done * 2064 / 1024 / 1024;
mb_done_real = (double) (sectors_done - stats -> sectors_skipped) * 2064 / 1024 / 1024;
mb_hour = mb_done_real / elapsed * 60 * 60;
seconds_left = stats -> mb_total_real / mb_hour * 60 * 60;
eta = (time_t) ((stats -> start_time).tv_sec + seconds_left);
if (localtime_r (&eta, &etatm))
strftime (buf, 50, "%d/%m/%Y %H:%M:%S", &etatm);
else
sprintf (buf, "N/A");
fprintf (stdout, "\r%3d%% ", perc);
fprintf (stdout, "|");
for (i = 0; i < 100 / 3; i++) {
if (i == perc / 3)
fprintf (stdout, "*");
else
fprintf (stdout, "-");
}
fprintf (stdout, "| ");
fprintf (stdout, "%.2lf MB/h, ETA: %s", mb_hour, buf);
fflush (stdout);
}
if (sectors_done == total_sectors)
printf ("\n");
/* Save return time, in case this will be the last call */
gettimeofday (&(stats -> end_time), NULL);
return;
}
void welcome (void) {
/* Welcome text */
fprintf (stderr,
"FriiDump " PACKAGE_VERSION " - Copyright (C) 2007 Arep\n"
"This software comes with ABSOLUTELY NO WARRANTY.\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions; see COPYING for details.\n"
"\n"
"Official support forum: http://wii.console-tribe.com\n"
"\n"
"Forum for this UNOFFICIAL VERSION: http://forum.redump.org\n"
"\n"
);
fflush (stderr);
return;
}
void help (void) {
/* 80 cols guide:
* |-------------------------------------------------------------------------------|
*/
fprintf (stderr, "\n"
"Available command line options:\n"
"\n"
" -h, --help Show this help\n"
" -a, --autodump Dump the disc to an ISO file with an\n"
" automatically-generated name, resuming the dump\n"
" if possible\n"
" -g, --gui Use more verbose output that can be easily\n"
" parsed by a GUI frontend\n"
" -d, --device <device> Dump disc from device <device>\n"
" -p, --stop Instruct device to stop disc rotation\n"
" -c, --command <nr> Force memory dump command:\n"
" 0 - vanilla 2064\n"
" 1 - vanilla 2384\n"
" 2 - Hitachi\n"
" 3 - Lite-On\n"
" 4 - Renesas\n"
" -x, --speed <x> Set streaming speed (1, 24, 32, 64, etc.,\n"
" where 1 = 150 KiB/s and so on)\n"
" -T, --type <nr> Force disc type:\n"
" 0 - GameCube\n"
" 1 - Wii\n"
" 2 - Wii_DL\n"
" 3 - DVD\n"
" -S, --size <sectors> Force disc size\n"
" -r, --raw <file> Output to file <file> in raw format (2064-byte\n"
" sectors)\n"
" -i, --iso <file> Output to file <file> in ISO format (2048-byte\n"
" sectors)\n"
" -u, --unscramble <file> Convert (unscramble) raw image contained in\n"
" <file> to ISO format\n"
" -H, --nohash Do not compute CRC32/MD5/SHA-1 hashes\n"
" for generated files\n"
" -s, --resume Resume partial dump\n"
" - General -----------------------------------\n"
" -0, --method0[=<req>,<exp>] Use dumping method 0 (Optional argument\n"
" specifies how many sectors to request from disc\n"
" and read from cache at a time. Values should be\n"
" separated with a comma. Default 16,16)\n"
" - Non-Streaming -----------------------------\n"
" -1, --method1[=<req>,<exp>] Use dumping method 1 (Default 16,16)\n"
" -2, --method2[=<req>,<exp>] Use dumping method 2 (Default 16,16)\n"
" -3, --method3[=<req>,<exp>] Use dumping method 3 (Default 16,16)\n"
" - Streaming ---------------------------------\n"
" -4, --method4[=<req>,<exp>] Use dumping method 4 (Default 27,27)\n"
" -5, --method5[=<req>,<exp>] Use dumping method 5 (Default 27,27)\n"
" -6, --method6[=<req>,<exp>] Use dumping method 6 (Default 27,27)\n"
" - Hitachi -----------------------------------\n"
" -7, --method7 Use dumping method 7 (Read and dump 5 blocks\n"
" at a time, using streaming read)\n"
" -8, --method8 Use dumping method 8 (Read and dump 5 blocks\n"
" at a time, using streaming read, using DMA)\n"
" -9, --method9 Use dumping method 9 (Read and dump 5 blocks\n"
" at a time, using streaming read, using DMA and\n"
" some speed tricks)\n"
" -A, --allmethods Try all known methods and commands until\n"
" one works.\n"
#ifdef DEBUG
" -n, --donottunscramble Do not try unscrambling to check EDC. Only\n"
" useful for testing the raw performance of the\n"
" different methods\n"
" -f, --donottflush Do not call fflush() after every fwrite()\n"
#endif
);
return;
}
bool optparse (int argc, char **argv) {
bool out;
char *result = NULL;
int c;
int option_index = 0;
static struct option long_options[] = {
{"help", 0, 0, 'h'}, //0 - no_argument
{"autodump", 0, 0, 'a'},
{"gui", 0, 0, 'g'},
{"device", 1, 0, 'd'}, //1 - required_argument
{"raw", 1, 0, 'r'},
{"iso", 1, 0, 'i'},
{"unscramble", 1, 0, 'u'},
{"nohash", 0, 0, 'H'},
{"resume", 0, 0, 's'},
{"method0", 2, 0, '0'}, //2 - optional_argument
{"method1", 2, 0, '1'},
{"method2", 2, 0, '2'},
{"method3", 2, 0, '3'},
{"method4", 2, 0, '4'},
{"method5", 2, 0, '5'},
{"method6", 2, 0, '6'},
{"method7", 0, 0, '7'},
{"method8", 0, 0, '8'},
{"method9", 0, 0, '9'},
{"stop", 0, 0, 'p'},
{"command", 1, 0, 'c'},
{"startsector", 1, 0, 't'},
{"size", 1, 0, 'S'},
{"speed", 1, 0, 'x'},
{"type", 1, 0, 'T'},
{"allmethods", 0, 0, 'A'},
#ifdef DEBUG
/* We don't want newbies to generate and put into circulation bad dumps, so this options are disabled for releases */
{"donottunscramble", 0, 0, 'n'},
{"donottflush", 0, 0, 'f'},
#endif
{0, 0, 0, 0}
};
if (argc == 1) {
help ();
exit (1);
}
/* Init options to default values */
options.device = NULL;
options.autodump = false;
options.gui = false;
options.raw_in = NULL;
options.raw_out = NULL;
options.iso_out = NULL;
options.no_hashing = false;
options.resume = false;
options.dump_method = -1;
options.command = -1;
options.start_sector = -1;
options.sectors_no = -1;
options.speed = -1;
options.disctype = -1;
options.sec_disc = -1;
options.sec_mem = -1;
options.no_unscrambling = false;
options.no_flushing = false;
options.stop_unit = false;
options.allmethods = false;
do {
#ifdef DEBUG
c = getopt_long (argc, argv, "hpagd:r:i:u:Hs0::1::2::3::4::5::6::789c:t:S:x:T:Anf", long_options, &option_index);
#else
c = getopt_long (argc, argv, "hpagd:r:i:u:Hs0::1::2::3::4::5::6::789c:t:S:x:T:A", long_options, &option_index);
#endif
switch (c) {
case 'h':
help ();
exit (1);
break;
case 'p':
options.stop_unit = true;
break;
case 'a':
options.autodump = true;
options.resume = true;
break;
case 'g':
options.gui = true;
break;
case 'd':
my_strdup (options.device, optarg);
break;
case 'r':
my_strdup (options.raw_out, optarg);
break;
case 'i':
my_strdup (options.iso_out, optarg);
break;
case 'u':
my_strdup (options.raw_in, optarg);
break;
case 'H':
options.no_hashing = true;
break;
case 's':
options.resume = true;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
options.dump_method = c - '0';
if (optarg) {
result = strtok(optarg, ",");
result = strtok(NULL, ",");
options.sec_disc = atol(strpbrk(optarg,"1234567890"));
if (result) options.sec_mem = atol(result);
else {
help ();
exit (1);
}
}
break;
case '7':
case '8':
case '9':
options.dump_method = c - '0';
break;
case 'c':
options.command = atol (optarg);
if (options.command > 4) {
help ();
exit (1);
};
break;
case 't':
options.start_sector = atol (optarg);
break;
case 'S':
options.sectors_no = atol (optarg);
break;
case 'x':
options.speed = atol (optarg);
break;
case 'T':
options.disctype = atol (optarg);
if (options.disctype > 3) {
help ();
exit (1);
};
unscrambler_set_disctype (options.disctype);
break;
case 'A':
options.allmethods = true;
options.resume = true;
break;
#ifdef DEBUG
case 'n':
options.no_unscrambling = true;
break;
case 'f':
options.no_flushing = true;
break;
#endif
case -1:
break;
default:
// fprintf (stderr, "?? getopt returned character code 0%o ??\n", c);
exit (7);
break;
}
} while (c != -1);
if (optind < argc) {
/* Command-line arguments remaining. Ignore them, warning the user. */
fprintf (stderr, "WARNING: Extra parameters ignored\n");
}
/* Sanity checks... */
out = false;
if (!options.device && !options.raw_in) {
fprintf (stderr, "No operation specified. Please use the -d or -u options.\n");
} else if (options.raw_in && options.raw_out) {
fprintf (stderr,
"Are you sure you want to convert a raw image to another raw image? ;)\n"
"Take a look at the -i and -a options!\n"
);
} else if (options.autodump && (options.raw_out || options.iso_out)) {
fprintf (stderr, "The -r and -i options cannot be used together with -a.\n");
} else {
/* Specified options seem to make sense */
out = true;
}
return (out);
}
int dologic (disc *d, progstats stats) {
disc_type type_id;
char *type, *game_id, *region, *maker_id, *maker, *version, *title, tmp[0x03E0 + 4 + 1];
bool drive_supported;
int out;
dumper *dmp;
u_int32_t current_sector;
if (options.stop_unit) { //stop rotation, if requested
fprintf (stderr, "Issuing STOP command... %s\n", (disc_stop_unit (d, false)) ? "OK" : "Failed");
exit (1);
}
else disc_stop_unit(d, true); //else start rotation
drive_supported = disc_get_drive_support_status (d);
fprintf (stderr,
"\n"
"Drive information:\n"
"----------------------------------------------------------------------\n"
"Drive model........: %s\n"
"Supported..........: %s\n", disc_get_drive_model_string (d), drive_supported ? "Yes" : "No"
);
init_range(d, options.sec_disc, options.sec_mem);
if (!(disc_set_read_method (d, options.dump_method)))
exit (2);
if (options.command!=-1) fprintf (stderr,
"Command............: %d (forced)\n", disc_get_command(d));
else fprintf (stderr,
"Command............: %d\n", disc_get_command(d));
options.dump_method=disc_get_method(d);
if (disc_get_def_method(d)!=options.dump_method) fprintf (stderr,
"Method.............: %d (forced)\n", options.dump_method);
else fprintf (stderr,
"Method.............: %d\n", options.dump_method);
if ((options.dump_method==0)
|| (options.dump_method==1) || (options.dump_method==2) || (options.dump_method==3)
|| (options.dump_method==4) || (options.dump_method==5) || (options.dump_method==6)
){
fprintf (stderr,
"Requested sectors..: %d\n", disc_get_sec_disc(d));
fprintf (stderr,
"Expected sectors...: %d\n", disc_get_sec_mem(d));
}
fprintf (stderr, "\nPress Ctrl+C at any time to terminate\n");
fprintf (stderr, "\nRetrieving disc seeds, this might take a while... ");
//set speed for 1st time
if (options.speed != -1) disc_set_speed(d, options.speed * 177);
if (options.speed != -1) disc_set_streaming_speed(d, options.speed * 177);
// disc_set_speed(d, 0xffff);
if (!disc_init (d, options.disctype, options.sectors_no)) {
fprintf (stderr, "Failed\n");
out = false;
} else {
fprintf (stderr, "OK\n");
disc_get_type (d, &type_id, &type);
disc_get_gameid (d, &game_id);
disc_get_region (d, NULL, &region);
disc_get_maker (d, &maker_id, &maker);
disc_get_version (d, NULL, &version);
disc_get_title (d, &title);
fprintf (stderr,
"\n"
"Disc information:\n"
"----------------------------------------------------------------------\n");
if (options.disctype!=-1) fprintf (stderr,
"Disc type..........: %s (forced)\n", type);
else fprintf (stderr,
"Disc type..........: %s\n", type);
if (options.sectors_no!=-1) fprintf (stderr,
"Disc size..........: %d (forced)\n", disc_get_sectors_no(d));
else fprintf (stderr,
"Disc size..........: %d\n", disc_get_sectors_no(d));
if (disc_get_layerbreak(d)>0 && type_id==DISC_TYPE_DVD) fprintf (stderr,
"Layer break........: %d\n", disc_get_layerbreak(d));
if ((type_id==DISC_TYPE_GAMECUBE) || (type_id==DISC_TYPE_WII) || (type_id==DISC_TYPE_WII_DL)) fprintf (stderr,
"Game ID............: %s\n"
"Region.............: %s\n"
"Maker..............: %s - %s\n"
"Version............: %s\n"
"Game title.........: %s\n", game_id, region, maker_id, maker, version, title
);
if (type_id == DISC_TYPE_WII || type_id == DISC_TYPE_WII_DL)
fprintf (stderr, "Contains update....: %s\n" , disc_get_update (d) ? "Yes" : "No");
fprintf (stderr, "\n");
disc_set_unscrambling (d, !options.no_unscrambling);
unscrambler_set_disctype (type_id);
if (options.autodump) {
snprintf (tmp, sizeof (tmp), "%s.iso", title);
my_strdup (options.iso_out, tmp);
}
//set speed 2nd time after rotation is started and some sectors read
if (options.speed != -1) disc_set_streaming_speed(d, options.speed * 177);
if (options.speed != -1) disc_set_speed(d, options.speed * 177);
/* If at least an output file was specified, proceed dumping, otherwise stop here */
if (options.raw_out || options.iso_out) {
if (options.raw_out)
fprintf (stderr, "Writing to file \"%s\" in raw format\n", options.raw_out);
if (options.iso_out)
fprintf (stderr, "Writing to file \"%s\" in ISO format\n", options.iso_out);
fprintf (stderr, "\n");
dmp = dumper_new (d);
dumper_set_hashing (dmp, !options.no_hashing);
dumper_set_flushing (dmp, !options.no_flushing);
if (!dumper_set_raw_output_file (dmp, options.raw_out, options.resume)) {
fprintf (stderr, "Cannot setup raw output file\n");
} else if (!dumper_set_iso_output_file (dmp, options.iso_out, options.resume)) {
fprintf (stderr, "Cannot setup ISO output file\n");
} else if (!dumper_prepare (dmp)) {
fprintf (stderr, "Cannot prepare dumper");
} else {
// fprintf (stderr, "Starting dump process from sector %u...\n", dmp -> start_sector);
// opdd.start_sector = options.start_sector;
if (options.gui)
dumper_set_progress_callback (dmp, (progress_func) progress_for_guis, &stats);
else
dumper_set_progress_callback (dmp, (progress_func) progress, &stats);
if (dumper_dump (dmp, &current_sector)) {
fprintf (stderr, "Dump completed successfully!\n");
if (!options.no_hashing && options.raw_out)
fprintf (stderr,
"Raw image hashes:\n"
"CRC32...: %s\n"
//"MD4.....: %s\n"
"MD5.....: %s\n"
"SHA-1...: %s\n"
/*"ED2K....: %s\n"*/,
dumper_get_raw_crc32 (dmp), /*dumper_get_raw_md4 (dmp),*/ dumper_get_raw_md5 (dmp),
dumper_get_raw_sha1 (dmp)/*, dumper_get_raw_ed2k (dmp)*/
);
if (!options.no_hashing && options.iso_out)
fprintf (stderr,
"ISO image hashes:\n"
"CRC32...: %s\n"
//"MD4.....: %s\n"
"MD5.....: %s\n"
"SHA-1...: %s\n"
/*"ED2K....: %s\n"*/,
dumper_get_iso_crc32 (dmp), /*dumper_get_iso_md4 (dmp),*/ dumper_get_iso_md5 (dmp),
dumper_get_iso_sha1 (dmp)/*, dumper_get_iso_ed2k (dmp)*/
);
out = true;
disc_stop_unit (d, 0);
} else {
fprintf (stderr, "\nDump failed at sectors: %u..%u\n", current_sector, current_sector+15);
out = false;
//disc_stop_unit (d, 0);
}
}
dmp = dumper_destroy (dmp);
} else {
fprintf (stderr, "No output file for dumping specified, please take a look at the -i, -r and -a options\n");
}
}
return out;
}
int main (int argc, char *argv[]) {
disc *d;
progstats stats;
double duration;
suseconds_t us;
int out, ret;
unscrambler *u;
unscrambler_progress_func pfunc;
u_int32_t current_sector;
/* First of all... */
drop_euid ();
welcome ();
d = NULL;
out = false;
if (optparse (argc, argv)) {
if (options.device) {
/* Dump DVD to file */
fprintf (stderr, "Initializing DVD drive... ");
if (!(d = disc_new (options.device, options.command))) {
fprintf (stderr, "Failed\n");
#ifndef WIN32
fprintf (stderr,
"Probably you do not have access to the DVD device. Ask the administrator\n"
"to add you to the proper group, or use 'sudo'.\n"
);
#endif
} else {
fprintf (stderr, "OK\n");
if(options.allmethods)
{
fprintf (stderr, "Trying all methods... This will take a LOOOONG time and generate an insanely long console output :p\n");
for(options.command=0;options.command<=4;options.command++)
{
for(options.dump_method=0;options.dump_method<=9;options.dump_method++)
{
fprintf (stderr, "Trying with command %d, method %d\n", options.command, options.dump_method);
out = dologic(d, stats);
if(out==true)
{
break;
}
}
if(out==true)
{
fprintf (stderr, "Command %d and method %d combination worked!\n", options.command, options.dump_method);
break;
}
}
} else {
out = dologic(d, stats);
}
d = disc_destroy (d);
}
} else if (options.raw_in) {
/* Convert raw image to ISO format */
u = unscrambler_new ();
if (options.gui)
pfunc = (unscrambler_progress_func) progress_for_guis;
else
pfunc = (unscrambler_progress_func) progress;
if ((out = unscrambler_unscramble_file (u, options.raw_in, options.iso_out, pfunc, &stats, &current_sector)))
fprintf (stderr, "Unscrambling completed successfully!\n");
else
fprintf (stderr, "\nUnscrambling failed at sectors: %u..%u\n", current_sector, current_sector+15);
u = unscrambler_destroy (u);
} else {
MY_ASSERT (0);
}
if (out) {
duration = stats.end_time.tv_sec - stats.start_time.tv_sec;
if (stats.end_time.tv_usec >= stats.start_time.tv_usec) {
us = stats.end_time.tv_usec - stats.start_time.tv_usec;
} else {
if (duration > 0)
duration--;
us = USECS_PER_SEC + stats.end_time.tv_usec - stats.start_time.tv_usec;
}
duration += ((double) us / (double) USECS_PER_SEC);
if (duration < 0)
duration = 0;
fprintf (stderr, "Operation took %.2f seconds\n", duration);
ret = EXIT_SUCCESS;
} else {
ret = EXIT_FAILURE;
}
my_free (options.device);
my_free (options.iso_out);
my_free (options.raw_out);
my_free (options.raw_in);
}
return (out);
}

130
src/getopt-win32.c Normal file
View file

@ -0,0 +1,130 @@
/* $Id$ */
/*
** Copyright (C) 2002 Martin Roesch <roesch@sourcefire.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License Version 2 as
** published by the Free Software Foundation. You may not use, modify or
** distribute this program under any other version of the GNU General
** Public License.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef SNORT_GETOPT
#include <stdio.h> /* for EOF */
#include <string.h> /* for strchr() */
#include "getopt.h"
/* static (global) variables that are specified as exported by getopt() */
char *optarg = NULL; /* pointer to the start of the option argument */
int optind = 1; /* number of the next argv[] to be evaluated */
int opterr = 1; /* non-zero if a question mark should be returned
when a non-valid option character is detected */
int optopt;
int getopt(int argc, char *argv[], char *opstring)
{
static char *pIndexPosition = NULL; /* place inside current argv string */
char *pArgString = NULL; /* where to start from next */
char *pOptString; /* the string in our program */
if (pIndexPosition != NULL) {
/* we last left off inside an argv string */
if (*(++pIndexPosition)) {
/* there is more to come in the most recent argv */
pArgString = pIndexPosition;
}
}
if (pArgString == NULL) {
/* we didn't leave off in the middle of an argv string */
if (optind >= argc) {
/* more command-line arguments than the argument count */
pIndexPosition = NULL; /* not in the middle of anything */
return EOF; /* used up all command-line arguments */
}
/*---------------------------------------------------------------------
* If the next argv[] is not an option, there can be no more options.
*-------------------------------------------------------------------*/
pArgString = argv[optind++]; /* set this to the next argument ptr */
if (('/' != *pArgString) && /* doesn't start with a slash or a dash? */
('-' != *pArgString)) {
--optind; /* point to current arg once we're done */
optarg = NULL; /* no argument follows the option */
pIndexPosition = NULL; /* not in the middle of anything */
return EOF; /* used up all the command-line flags */
}
/* check for special end-of-flags markers */
if ((strcmp(pArgString, "-") == 0) ||
(strcmp(pArgString, "--") == 0)) {
optarg = NULL; /* no argument follows the option */
pIndexPosition = NULL; /* not in the middle of anything */
return EOF; /* encountered the special flag */
}
pArgString++; /* look past the / or - */
}
if (':' == *pArgString) { /* is it a colon? */
/*---------------------------------------------------------------------
* Rare case: if opterr is non-zero, return a question mark;
* otherwise, just return the colon we're on.
*-------------------------------------------------------------------*/
return (opterr ? (int)'?' : (int)':');
}
else if ((pOptString = strchr(opstring, *pArgString)) == 0) {
/*---------------------------------------------------------------------
* The letter on the command-line wasn't any good.
*-------------------------------------------------------------------*/
optarg = NULL; /* no argument follows the option */
pIndexPosition = NULL; /* not in the middle of anything */
return (opterr ? (int)'?' : (int)*pArgString);
}
else {
/*---------------------------------------------------------------------
* The letter on the command-line matches one we expect to see
*-------------------------------------------------------------------*/
if (':' == _next_char(pOptString)) { /* is the next letter a colon? */
/* It is a colon. Look for an argument string. */
if ('\0' != _next_char(pArgString)) { /* argument in this argv? */
optarg = &pArgString[1]; /* Yes, it is */
}
else {
/*-------------------------------------------------------------
* The argument string must be in the next argv.
* But, what if there is none (bad input from the user)?
* In that case, return the letter, and optarg as NULL.
*-----------------------------------------------------------*/
if (optind < argc)
optarg = argv[optind++];
else {
optarg = NULL;
return (opterr ? (int)'?' : (int)*pArgString);
}
}
pIndexPosition = NULL; /* not in the middle of anything */
}
else {
/* it's not a colon, so just return the letter */
optarg = NULL; /* no argument follows the option */
pIndexPosition = pArgString; /* point to the letter we're on */
}
return (int)*pArgString; /* return the letter that matched */
}
}
#endif

36
src/getopt-win32.h Normal file
View file

@ -0,0 +1,36 @@
/* $Id$ */
/*
** Copyright (C) 2002 Martin Roesch <roesch@sourcefire.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License Version 2 as
** published by the Free Software Foundation. You may not use, modify or
** distribute this program under any other version of the GNU General
** Public License.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _SNORT_GETOPT_H_
#define _SNORT_GETOPT_H_
#ifdef SNORT_GETOPT
#define _next_char(string) (char)(*(string+1))
extern char * optarg;
extern int optind;
int getopt(int, char**, char*);
#else
#include "getopt1.h"
#endif
#endif /* _SNORT_GETOPT_H_ */

130
src/getopt1.h Normal file
View file

@ -0,0 +1,130 @@
/* Declarations for getopt.
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
it under the terms of the GNU General Public License Version 2 as
published by the Free Software Foundation. You may not use, modify or
distribute this program under any other version of the GNU General
Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. */
#ifndef _GETOPT1_H
#define _GETOPT1_H 1
#ifndef HAVE_GETOPT_LONG
#ifdef __cplusplus
extern "C" {
#endif
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
#if __STDC__
const char *name;
#else
char *name;
#endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
#define no_argument 0
#define required_argument 1
#define optional_argument 2
#if __STDC__
#ifndef HAVE_GETOPT
extern int getopt (int argc, char *const *argv, const char *optstring);
#endif
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind,
int long_only);
#else /* not __STDC__ */
#ifndef HAVE_GETOPT
extern int getopt ();
#endif
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
#endif /* not __STDC__ */
#ifdef __cplusplus
}
#endif
#endif /* HAVE_GETOPT_LONG */
#endif /* _GETOPT_H */

727
src/getopt_long-win32.c Normal file
View file

@ -0,0 +1,727 @@
/* Getopt for GNU.
NOTE: getopt is now part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
before changing it!
Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
it under the terms of the GNU General Public License Version 2 as
published by the Free Software Foundation. You may not use, modify or
distribute this program under any other version of the GNU General
Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. */
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
Ditto for AIX 3.2 and <stdlib.h>. */
#ifndef _NO_PROTO
#define _NO_PROTO
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_CONFIG_H
#if defined (emacs) || defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
(which it would do because it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#ifndef __STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
#include <stdlib.h>
#endif /* GNU C library. */
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
to intersperse the options with the other arguments.
As `getopt' works, it permutes the elements of ARGV so that,
when it is done, all the options precede everything else. Thus
all application programs are extended to handle flexible argument order.
Setting the environment variable POSIXLY_CORRECT disables permutation.
Then the behavior is completely standard.
GNU application programs can use a third alternative mode in which
they can distinguish the relative order of options and other arguments. */
#include "getopt1.h"
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
char *optarg = NULL;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
/* XXX 1003.2 says this must be 1 before any call. */
int optind = 0;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
This allows us to pick up the scan where we left off.
If this is zero, or a null string, it means resume the scan
by advancing to the next ARGV-element. */
static char *nextchar;
/* Callers store zero here to inhibit the error message
for unrecognized options. */
int opterr = 1;
/* Set to an option character which was unrecognized.
This must be initialized on some systems to avoid linking in the
system's own getopt implementation. */
int optopt = '?';
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters.
PERMUTE is the default. We permute the contents of ARGV as we scan,
so that eventually all the non-options are at the end. This allows options
to be given in any order, even with programs that were not written to
expect this.
RETURN_IN_ORDER is an option available to programs that were written
to expect options and other ARGV-elements in any order and that care about
the ordering of the two. We describe each non-option ARGV-element
as if it were the argument of an option with character code 1.
Using `-' as the first character of the list of option characters
selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
static enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} ordering;
/* Value of POSIXLY_CORRECT environment variable. */
static char *posixly_correct;
#ifdef __GNU_LIBRARY__
/* We want to avoid inclusion of string.h with non-GNU libraries
because there are many ways it can cause trouble.
On some systems, it contains special magic macros that don't work
in GCC. */
#include <string.h>
#define my_index strchr
#else
/* Avoid depending on library functions or files
whose names are inconsistent. */
#if !defined(_WIN32)
char *getenv ();
#endif
static char *
my_index (str, chr)
const char *str;
int chr;
{
while (*str)
{
if (*str == chr)
return (char *) str;
str++;
}
return 0;
}
/* If using GCC, we can safely declare strlen this way.
If not using GCC, it is ok not to declare it. */
#ifdef __GNUC__
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
That was relevant to code that was here before. */
#ifndef __STDC__
/* gcc with -traditional declares the built-in strlen to return int,
and has done so at least since version 2.4.5. -- rms. */
extern int strlen (const char *);
#endif /* not __STDC__ */
#endif /* __GNUC__ */
#endif /* not __GNU_LIBRARY__ */
/* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have
been skipped. `first_nonopt' is the index in ARGV of the first of them;
`last_nonopt' is the index after the last of them. */
static int first_nonopt;
static int last_nonopt;
/* Exchange two adjacent subsequences of ARGV.
One subsequence is elements [first_nonopt,last_nonopt)
which contains all the non-options that have been skipped so far.
The other is elements [last_nonopt,optind), which contains all
the options processed since those non-options were skipped.
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
static void
exchange (argv)
char **argv;
{
int bottom = first_nonopt;
int middle = last_nonopt;
int top = optind;
char *tem;
/* Exchange the shorter segment with the far end of the longer segment.
That puts the shorter segment into the right place.
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
{
/* Bottom segment is the short one. */
int len = middle - bottom;
register int i;
/* Swap it with the top part of the top segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
}
else
{
/* Top segment is the short one. */
int len = top - middle;
register int i;
/* Swap it with the bottom part of the bottom segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
}
}
/* Update records for the slots the non-options now occupy. */
first_nonopt += (optind - last_nonopt);
last_nonopt = optind;
}
/* Initialize the internal data when the first call is made. */
static const char *
_getopt_initialize (optstring)
const char *optstring;
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
first_nonopt = last_nonopt = optind = 1;
nextchar = NULL;
posixly_correct = getenv ("POSIXLY_CORRECT");
/* Determine how to handle the ordering of options and nonoptions. */
if (optstring[0] == '-')
{
ordering = RETURN_IN_ORDER;
++optstring;
}
else if (optstring[0] == '+')
{
ordering = REQUIRE_ORDER;
++optstring;
}
else if (posixly_correct != NULL)
ordering = REQUIRE_ORDER;
else
ordering = PERMUTE;
return optstring;
}
/* Scan elements of ARGV (whose length is ARGC) for option characters
given in OPTSTRING.
If an element of ARGV starts with '-', and is not exactly "-" or "--",
then it is an option element. The characters of this element
(aside from the initial '-') are option characters. If `getopt'
is called repeatedly, it returns successively each of the option characters
from each of the option elements.
If `getopt' finds another option character, it returns that character,
updating `optind' and `nextchar' so that the next call to `getopt' can
resume the scan with the following option character or ARGV-element.
If there are no more option characters, `getopt' returns `EOF'.
Then `optind' is the index in ARGV of the first ARGV-element
that is not an option. (The ARGV-elements have been permuted
so that those that are not options now come last.)
OPTSTRING is a string containing the legitimate option characters.
If an option character is seen that is not listed in OPTSTRING,
return '?' after printing an error message. If you set `opterr' to
zero, the error message is suppressed but we still return '?'.
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
so the following text in the same ARGV-element, or the text of the following
ARGV-element, is returned in `optarg'. Two colons mean an option that
wants an optional arg; if there is text in the current ARGV-element,
it is returned in `optarg', otherwise `optarg' is set to zero.
If OPTSTRING starts with `-' or `+', it requests different methods of
handling the non-option ARGV-elements.
See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
Long-named options begin with `--' instead of `-'.
Their names may be abbreviated as long as the abbreviation is unique
or is an exact match for some defined option. If they have an
argument, it follows the option name in the same ARGV-element, separated
from the option name by a `=', or else the in next ARGV-element.
When `getopt' finds a long-named option, it returns 0 if that option's
`flag' field is nonzero, the value of the option's `val' field
if the `flag' field is zero.
The elements of ARGV aren't really const, because we permute them.
But we pretend they're const in the prototype to be compatible
with other systems.
LONGOPTS is a vector of `struct option' terminated by an
element containing a name which is zero.
LONGIND returns the index in LONGOPT of the long-named option found.
It is only valid when a long-named option has been found by the most
recent call.
If LONG_ONLY is nonzero, '-' as well as '--' can introduce
long-named options. */
int
_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
int argc;
char *const *argv;
const char *optstring;
const struct option *longopts;
int *longind;
int long_only;
{
optarg = NULL;
if (optind == 0)
optstring = _getopt_initialize (optstring);
if (nextchar == NULL || *nextchar == '\0')
{
/* Advance to the next ARGV-element. */
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange ((char **) argv);
else if (last_nonopt != optind)
first_nonopt = optind;
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
while (optind < argc
&& (argv[optind][0] != '-' || argv[optind][1] == '\0'))
optind++;
last_nonopt = optind;
}
/* The special ARGV-element `--' means premature end of options.
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
if (optind != argc && !strcmp (argv[optind], "--"))
{
optind++;
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange ((char **) argv);
else if (first_nonopt == last_nonopt)
first_nonopt = optind;
last_nonopt = argc;
optind = argc;
}
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
if (optind == argc)
{
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
optind = first_nonopt;
return EOF;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
{
if (ordering == REQUIRE_ORDER)
return EOF;
optarg = argv[optind++];
return 1;
}
/* We have found another option-ARGV-element.
Skip the initial punctuation. */
nextchar = (argv[optind] + 1
+ (longopts != NULL && argv[optind][1] == '-'));
}
/* Decode the current option-ARGV-element. */
/* Check whether the ARGV-element is a long option.
If long_only and the ARGV-element has the form "-f", where f is
a valid short option, don't consider it an abbreviated form of
a long option that starts with f. Otherwise there would be no
way to give the -f short option.
On the other hand, if there's a long option "fubar" and
the ARGV-element is "-fu", do consider that an abbreviation of
the long option, just like "--fu", and not "-f" with arg "u".
This distinction seems to be the most useful approach. */
if (longopts != NULL
&& (argv[optind][1] == '-'
|| (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
{
char *nameend;
const struct option *p;
const struct option *pfound = NULL;
int exact = 0;
int ambig = 0;
int indfound;
int option_index;
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
/* Do nothing. */ ;
/* Test all long options for either exact match
or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp (p->name, nextchar, nameend - nextchar))
{
if (nameend - nextchar == (int) strlen (p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
if (opterr)
fprintf (stderr, "%s: option `%s' is ambiguous\n",
argv[0], argv[optind]);
nextchar += strlen (nextchar);
optind++;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
optind++;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
optarg = nameend + 1;
else
{
if (opterr)
{
if (argv[optind - 1][1] == '-')
/* --option */
fprintf (stderr,
"%s: option `--%s' doesn't allow an argument\n",
argv[0], pfound->name);
else
/* +option or -option */
fprintf (stderr,
"%s: option `%c%s' doesn't allow an argument\n",
argv[0], argv[optind - 1][0], pfound->name);
}
nextchar += strlen (nextchar);
return '?';
}
}
else if (pfound->has_arg == 1)
{
if (optind < argc)
optarg = argv[optind++];
else
{
if (opterr)
fprintf (stderr, "%s: option `%s' requires an argument\n",
argv[0], argv[optind - 1]);
nextchar += strlen (nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
/* Can't find it as a long option. If this is not getopt_long_only,
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-'
|| my_index (optstring, *nextchar) == NULL)
{
if (opterr)
{
if (argv[optind][1] == '-')
/* --option */
fprintf (stderr, "%s: unrecognized option `--%s'\n",
argv[0], nextchar);
else
/* +option or -option */
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
argv[0], argv[optind][0], nextchar);
}
nextchar = (char *) "";
optind++;
return '?';
}
}
/* Look at and handle the next short option-character. */
{
char c = *nextchar++;
char *temp = my_index (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
++optind;
if (temp == NULL || c == ':')
{
if (opterr)
{
if (posixly_correct)
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
else
fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c);
}
optopt = c;
return '?';
}
if (temp[1] == ':')
{
if (temp[2] == ':')
{
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0')
{
optarg = nextchar;
optind++;
}
else
optarg = NULL;
nextchar = NULL;
}
else
{
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
optind++;
}
else if (optind == argc)
{
if (opterr)
{
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: option requires an argument -- %c\n",
argv[0], c);
}
optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
}
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
optarg = argv[optind++];
nextchar = NULL;
}
}
return c;
}
}
int
getopt (argc, argv, optstring)
int argc;
char *const *argv;
const char *optstring;
{
return _getopt_internal (argc, argv, optstring,
(const struct option *) 0,
(int *) 0,
0);
}
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
it under the terms of the GNU General Public License Version 2 as
published by the Free Software Foundation. You may not use, modify or
distribute this program under any other version of the GNU General
Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. */
int
getopt_long (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
If an option that starts with '-' (not '--') doesn't match a long option,
but does match a short option, it is parsed as a short option
instead. */
int
getopt_long_only (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}
#endif /* _LIBC or not __GNU_LIBRARY__. */