kopia lustrzana https://gitlab.com/sane-project/frontends
Porównaj commity
56 Commity
RELEASE_1_
...
master
Autor | SHA1 | Data |
---|---|---|
Ralph Little | a7fec47bec | |
Ralph Little | e25307a8a7 | |
Michael Klein | c33752c719 | |
Ralph Little | 013a47c03b | |
Zdenek Dohnal | 6d9554dbf0 | |
Ralph Little | 0d7bff9d8f | |
Florian Weimer | d0e542df76 | |
Florian Weimer | 25e9a5e13e | |
Ralph Little | b2b5f1ca61 | |
Zdenek Dohnal | 22d951a407 | |
Ralph Little | 4c234b1512 | |
Ralph Little | 02478dc10b | |
Ralph Little | 009b99cb02 | |
Ralph Little | 0d96bd19fb | |
Ralph Little | 7ebdf2cd62 | |
Olaf Meeuwissen | 572980c815 | |
Zdenek Dohnal | 6eefbc70f5 | |
Olaf Meeuwissen | a6615c06cc | |
Olaf Meeuwissen | c270790e01 | |
Olaf Meeuwissen | 41c62621d6 | |
Olaf Meeuwissen | c3e739702f | |
Olaf Meeuwissen | 2275d0cf08 | |
Olaf Meeuwissen | f803c74554 | |
Olaf Meeuwissen | 687c0c19ea | |
Olaf Meeuwissen | 54821724ef | |
Olaf Meeuwissen | c1b77855e4 | |
Olaf Meeuwissen | a5672d9bd9 | |
Olaf Meeuwissen | d045349101 | |
Olaf Meeuwissen | e650072b46 | |
Olaf Meeuwissen | 5e2b3662a9 | |
Nils Philippsen | 29a0cf06c4 | |
Tom Callaway | 237215cf04 | |
Nils Philippsen | 7e079e3771 | |
Jakub Wilk | cf9b7b61ce | |
m. allan noah | 1928f945ee | |
Julien BLACHE | 745efdeabb | |
Stphane Voltz | c554cfce37 | |
Julien BLACHE | aed8faa20e | |
Stéphane Voltz | 9d6c0a1c08 | |
Julien BLACHE | fe7c5b707c | |
Peter Kirchgessner | 25db05c0d3 | |
Peter Kirchgessner | a271046762 | |
Stéphane Voltz | 5e96223e49 | |
Gerard Klaver | b011ab97f7 | |
Gerard Klaver | 7336b06465 | |
Julien BLACHE | 98b025d3de | |
Julien BLACHE | 35438c151e | |
Julien BLACHE | a2e675d686 | |
Julien BLACHE | 690c38e645 | |
Rene Rebe | 749cc8af23 | |
Gerhard Jaeger | 059076f5d8 | |
Gerhard Jaeger | 5113e3de39 | |
Henning Geinitz | 395252831d | |
Rene Rebe | f79f2c3016 | |
Henning Geinitz | 032982c557 | |
Julien BLACHE | 9f48c4e386 |
|
@ -0,0 +1,8 @@
|
|||
*.o
|
||||
*.a
|
||||
*~
|
||||
autom4te.cache/
|
||||
Makefile
|
||||
config.cache
|
||||
config.log
|
||||
config.status
|
|
@ -0,0 +1,28 @@
|
|||
# .gitlab-ci.yml -- to build source tarball snapshots
|
||||
# Copyright (C) 2017 Olaf Meeuwissen
|
||||
#
|
||||
# License: GPL-3.0+
|
||||
|
||||
variables:
|
||||
REGISTRY_HUB: "registry.gitlab.com/sane-project/ci-envs"
|
||||
|
||||
stages:
|
||||
- archive
|
||||
|
||||
archive:
|
||||
stage: archive
|
||||
image: $REGISTRY_HUB:debian-buster-full
|
||||
before_script:
|
||||
- apt-get update --quiet
|
||||
- apt-get install --quiet --assume-yes libsane-dev
|
||||
script:
|
||||
- build=$(git describe --match '1.*' | sed 's/.*\.//; s/-.*//');
|
||||
sed -i "/^V_BUILD/s/=.*/=$build/" configure.in;
|
||||
extra=$(git describe --dirty --match '1.*' | sed 's/^[^-]*//');
|
||||
sed -i "/^V_EXTRA/s/=.*/=$extra/" configure.in
|
||||
- autoconf --force
|
||||
- ./configure
|
||||
- make dist
|
||||
artifacts:
|
||||
paths:
|
||||
- sane-frontends-*.tar.gz
|
88
Changelog
88
Changelog
|
@ -1,3 +1,91 @@
|
|||
For the latest changes please refer to the output of `git log` or the
|
||||
on-line log at:
|
||||
|
||||
https://gitlab.com/sane-project/frontends/commits/master
|
||||
|
||||
Note to developers:
|
||||
For 1.0.15 and beyond we will generate the ChangeLog from the git
|
||||
commit messages at release time. Instead of documenting your work
|
||||
here, just document it in your commit messages.
|
||||
|
||||
2014-06-05 Tom Callaway <spot@fedoraproject.org>
|
||||
* lib/snprintf.c: update to newer version from LPRng. The old version is
|
||||
licensed under the Artistic License 1.0 which isn't compatible with the
|
||||
GPL and arguably non-free.
|
||||
|
||||
2010-05-24 m. allan noah <kitno455 at gmail dot com>
|
||||
* src/preview.c, src/scanadf.c, src/xcam.c, src/xscanimage.c:
|
||||
- hide SANE_STATUS_WARMING_UP, patch by Ilmars Poikans
|
||||
* configure.in, configure: change version number to 1.0.15git
|
||||
- dont require sane-backends version >= 1.1.0
|
||||
|
||||
2009-11-14 Julien Blache <jb@jblache.org>
|
||||
* src/gtkglue.c: fix handling of word list when the current value is
|
||||
not in the list. Patch from Jan Echternach <jan@goneko.de>.
|
||||
|
||||
2009-06-24 Stéphane Voltz <stef.dev@free.fr>
|
||||
* src/gtkglue.c: fixed handling of SANE_CAP_ALWAYS_SETTABLE existence
|
||||
in gsg_set_sensitivity()
|
||||
|
||||
2008-09-23 Stéphane Voltz <stef.dev@free.fr>
|
||||
* src/progress.c src/progress.h: add an estimated time remaining
|
||||
on the progress window, based on a patch by Jonas Berlin
|
||||
<xkr47@outerspace.dyndns.org>
|
||||
|
||||
2008-08-05 Julien Blache <jb@jblache.org>
|
||||
* src/scanadf.c: fetch_options(): get option descriptor for option 0
|
||||
before getting the value for option 0.
|
||||
|
||||
2008-07-03 Peter Kirchgeßner <peter@kirchgessner.net>
|
||||
* doc/scanadf.man: Fix description of options for sane-hp-backend.
|
||||
A patch for sane-hp to be used with scanadf is not necessary
|
||||
and --source=ADF should be specified.
|
||||
|
||||
2008-06-06 Stéphane Voltz <stef.dev@free.fr>
|
||||
* src/gtkglue.c src/preview.c src/progress.c src/progress.h
|
||||
src/scanadf.c src/xcam.c src/xscanimage.c configure.in configure:
|
||||
change version to SANE 1.1, compile fixes for SANE 1.1, progress
|
||||
dialog improvement and handling of SANE_STATUS_WRMING_UP
|
||||
|
||||
2008-04-30 Gerard Klaver <gerard at gkall dot hobby dot nl>
|
||||
* src/xcam.c: For GRAY view mode added time stamp option,
|
||||
removed compiler warning for DBG line
|
||||
|
||||
2008-03-01 Julien Blache <jb@jblache.org>
|
||||
* doc/xcam.man: Fix typo reported by Justin Pryzby via Debian.
|
||||
|
||||
2007-10-08 Julien Blache <jb@jblache.org>
|
||||
* doc/xcam.man: Fix typo reported by Reuben Thomas via Debian.
|
||||
|
||||
2006-03-01 Rene Rebe <rene@exactcode.de>
|
||||
|
||||
* src/xscanimage.c: Fixed scan_button sensitivity after a failure
|
||||
at sane_start time, e.g. no documents. Formerly the button was left
|
||||
inactive.
|
||||
|
||||
2006-01-18 Gerhard Jaeger <gerhard@gjaeger.de>
|
||||
|
||||
* src/xscanimage.c: Fixed bug reported by Johannes Meixner, see
|
||||
http://alioth-lists.debian.net/pipermail/sane-devel/2006-January/015941.html
|
||||
|
||||
2005-12-31 Henning Meier-Geinitz <henning@meier-geinitz.de>
|
||||
|
||||
* src/xscanimage.c: Call set_gimp_PLUG_IN_INFO only if gimp 1.2 is
|
||||
used (from Franz Bakan <fbakan@gmx.net>).
|
||||
|
||||
2005-12-04 Rene Rebe <rene@exactcode.de>
|
||||
|
||||
* src/scanadf.c doc/scanadf.man: Added -p, --pipe option to scanadf
|
||||
to pass data to the scripts via stdin and thus process the image
|
||||
data parallel to the scan.
|
||||
|
||||
2005-10-09 Henning Meier-Geinitz <henning@meier-geinitz.de>
|
||||
|
||||
* configure configure.in: Changed version to 1.0.14-cvs.
|
||||
|
||||
2005-09-20 Julien Blache <jb@jblache.org>
|
||||
* src/xcam.c: remove dead code in load_defaults().
|
||||
|
||||
****** Release of sane-frontends-1.0.14 *****
|
||||
|
||||
2005-09-18 Henning Meier-Geinitz <henning@meier-geinitz.de>
|
||||
|
|
|
@ -33,7 +33,7 @@ INSTALL_DATA = @INSTALL_DATA@
|
|||
|
||||
@SET_MAKE@
|
||||
|
||||
SUBDIRS = include lib sanei src doc
|
||||
SUBDIRS = include sanei src doc
|
||||
|
||||
DISTFILES = AUTHORS COPYING Changelog INSTALL Makefile.in NEWS PROBLEMS \
|
||||
README acinclude.m4 aclocal.m4 config.guess config.sub configure \
|
||||
|
|
7
README
7
README
|
@ -22,11 +22,10 @@ and the network daemon saned.
|
|||
For details about installation please read the INSTALL file.
|
||||
|
||||
For a list of other SANE frontends look at
|
||||
http://www.sane-project.org//sane-frontends.html.
|
||||
http://www.sane-project.org/sane-frontends.html.
|
||||
|
||||
Developers may wish to look at the SANE standard (sane.tex). It can be found
|
||||
in the sane-backends distribution or in various file formats at the website:
|
||||
http://www.sane-project.org/docs.html
|
||||
Developers may wish to look at the SANE standard. It can be found at:
|
||||
https://sane-project.gitlab.io/standard/
|
||||
|
||||
Please report bugs and missing features at our bug-tracking system:
|
||||
http://www.sane-project.org/bugs.html
|
||||
|
|
|
@ -484,6 +484,7 @@ dnl
|
|||
AC_TRY_RUN([
|
||||
#include <sane/sane.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
|
|
|
@ -494,6 +494,7 @@ dnl
|
|||
AC_TRY_RUN([
|
||||
#include <sane/sane.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
|
|
Plik diff jest za duży
Load Diff
13
configure.in
13
configure.in
|
@ -7,8 +7,8 @@ AC_CONFIG_HEADER(include/sane/config.h)
|
|||
# version code:
|
||||
V_MAJOR=1
|
||||
V_MINOR=0
|
||||
V_BUILD=14
|
||||
V_EXTRA=
|
||||
V_BUILD=15
|
||||
V_EXTRA=git
|
||||
|
||||
PACKAGE=sane-frontends
|
||||
|
||||
|
@ -75,7 +75,7 @@ esac
|
|||
|
||||
dnl Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(os2.h fcntl.h unistd.h libc.h sys/time.h sys/types.h)
|
||||
AC_CHECK_HEADERS(os2.h fcntl.h unistd.h libc.h sys/time.h sys/types.h sys/socket.h)
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
|
@ -112,7 +112,7 @@ fi
|
|||
|
||||
AC_CHECK_TOOL(RANLIB, ranlib, :)
|
||||
|
||||
AM_PATH_SANE(1.0.0, HAVE_SANE=yes, )
|
||||
AM_PATH_SANE(1.0.10, HAVE_SANE=yes, )
|
||||
dnl Print error message if sane is missing
|
||||
if test "x${HAVE_SANE}" = "x"; then
|
||||
echo "**********************************************************************"
|
||||
|
@ -199,7 +199,7 @@ AC_ARG_ENABLE(foo2, [
|
|||
To add include or library paths call:
|
||||
[env] CPPFLAGS=\"-I/path/to/foo/include\" LDFLAGS=\"-L/path/to/foo/libs\" ./configure])
|
||||
|
||||
AC_OUTPUT([Makefile lib/Makefile src/Makefile sanei/Makefile doc/Makefile
|
||||
AC_OUTPUT([Makefile src/Makefile sanei/Makefile doc/Makefile
|
||||
include/Makefile],)
|
||||
|
||||
echo "****************************************************************"
|
||||
|
@ -235,7 +235,6 @@ echo "* ... PLEASE READ SANE DOCUMENTATION BEFORE STARTING SANE ... *"
|
|||
echo "* ------------------------------------------------------------ *"
|
||||
echo "* *"
|
||||
echo "* If you experience any problems with sane-frontends please *"
|
||||
echo "* write to the sane mailing list or contact: *"
|
||||
echo "* Oliver Rauch <Oliver.Rauch@Rauch-domain.de> *"
|
||||
echo "* write to the sane list at sane-devel@alioth-lists.debian.net *"
|
||||
echo "* *"
|
||||
echo "****************************************************************"
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
*.1
|
||||
|
|
@ -20,6 +20,7 @@ scanadf - acquire multiple images from a scanner equipped with an ADF
|
|||
.IR num ]
|
||||
.RB [ -e | --end-count
|
||||
.IR num ]
|
||||
.RB [ -p | --pipe ]
|
||||
.RB [ -r | --raw ]
|
||||
.RI [ device-specific-options ]
|
||||
.SH DESCRIPTION
|
||||
|
@ -158,11 +159,14 @@ information about the parameters of the image.
|
|||
.B SCAN_FORMAT_ID
|
||||
- the numeric image format identifier
|
||||
.br
|
||||
.B SCAN_PIPE
|
||||
- non-zero if a pipe is used for data transfer (instead of files)
|
||||
.br
|
||||
.RE
|
||||
|
||||
.PP
|
||||
If the
|
||||
.B --scipt-wait
|
||||
.B --script-wait
|
||||
option is given, scanadf will wait until all scan-scripts have been finished before
|
||||
exiting. That will be useful if scanadf is used in conjunction with tools to modify
|
||||
the scanned images.
|
||||
|
@ -199,6 +203,16 @@ the file to a more useful format. NOTE: With support for the
|
|||
optional frame types and the default handling of unrecognized
|
||||
frametypes, this option becomes less and less useful.
|
||||
|
||||
The
|
||||
.B -p
|
||||
or
|
||||
.B --pipe
|
||||
option allows passing the image date to the scan-script via a pipe
|
||||
rather than saving it to a file and executing the script thereafter.
|
||||
It might be useful for high-performance batch scans that should do
|
||||
post-processing, such as format convertion, on-the-fly.
|
||||
|
||||
.PP
|
||||
As you might imagine, much of the power of
|
||||
.B scanadf
|
||||
comes from the fact that it can control any SANE backend. Thus, the
|
||||
|
@ -234,7 +248,7 @@ bnhscan by Sean Reifschneider of tummy.com, ltd.
|
|||
|
||||
.SH BUGS
|
||||
Please send reports to
|
||||
.IR sane\-devel@lists.alioth.debian.org .
|
||||
.IR sane\-devel@alioth-lists.debian.net .
|
||||
.PP
|
||||
This program relies on the backend to return the
|
||||
.B SANE_STATUS_NO_DOCS
|
||||
|
@ -251,13 +265,17 @@ work at this time are:
|
|||
|
||||
.RS
|
||||
.br
|
||||
.B sane-avision
|
||||
- Avision (and compatible) scanners. For batch scanning the --source "ADF",
|
||||
"ADF Rear" or "ADF Duplex" should be used.
|
||||
.br
|
||||
.B sane-bh
|
||||
- Bell+Howell Copiscan II series scanners.
|
||||
.br
|
||||
.B sane-hp
|
||||
- Hewlett Packard scanners. A patch to the sane-hp backend
|
||||
is necessary. The --scantype=ADF option must be specified (earlier
|
||||
versions of the backend used the --scan-from-adf option, instead).
|
||||
- Hewlett Packard scanners. The --source=ADF option must be specified (earlier
|
||||
versions of the backend used the options --scantype=ADF
|
||||
or --scan-from-adf option, instead).
|
||||
.br
|
||||
.B sane-umax
|
||||
- UMAX scanners. Support exists in build 12 and later.
|
||||
|
|
11
doc/xcam.man
11
doc/xcam.man
|
@ -1,10 +1,10 @@
|
|||
.TH xcam 1 "11 April 2005"
|
||||
.TH xcam 1 "19 February 2008"
|
||||
.IX xcam
|
||||
.SH NAME
|
||||
xcam - a graphical camera frontend for SANE
|
||||
.SH SYNOPSIS
|
||||
.B xcam
|
||||
.RB [ --buffer | -B ]
|
||||
.RB [ --buffersize | -B ]
|
||||
.RB [ --version | -V ]
|
||||
.RB [ --help | -h ]
|
||||
|
||||
|
@ -12,7 +12,7 @@ xcam - a graphical camera frontend for SANE
|
|||
.B xcam
|
||||
provides a graphical user-interface to control an image
|
||||
acquisition device such as a flatbed scanner or a camera. It allows
|
||||
scanning invidual images and can be invoked directly from the command-line.
|
||||
scanning individual images and can be invoked directly from the command-line.
|
||||
|
||||
.B xcam
|
||||
acts as a stand-alone program that saves acquired images in a suitable
|
||||
|
@ -30,7 +30,7 @@ presents a menu listing of all known and available devices.
|
|||
.SH OPTIONS
|
||||
.PP
|
||||
If the
|
||||
.B --Buffer (-B)
|
||||
.B --buffersize (-B)
|
||||
option is given,
|
||||
.B xcam
|
||||
will use a 1024 kByte input buffer instead of the default 32 kByte.
|
||||
|
@ -43,12 +43,11 @@ will output its version number.
|
|||
.PP
|
||||
The
|
||||
.B --help (-h)
|
||||
.B xcam
|
||||
flag prints a short summary of options.
|
||||
.PP
|
||||
.TP
|
||||
.B SANE_DEBUG_XCAM
|
||||
This environment variable controls the debug level xscanimage. Higher
|
||||
This environment variable controls the debug level of xcam. Higher
|
||||
debug levels increase the verbosity of the output.
|
||||
|
||||
Value Descsription
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
config.h
|
||||
|
|
@ -108,6 +108,9 @@
|
|||
/* Define to 1 if you have the `strtod' function. */
|
||||
#undef HAVE_STRTOD
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
|
|
|
@ -59,18 +59,17 @@
|
|||
* Please use the SANEI functions wherever possible.
|
||||
*
|
||||
* This documentation was created by the use of doxygen, the
|
||||
* doc/doxygen-sanei.conf configuration file and dcoumentation in the sanei_*.h
|
||||
* doc/doxygen-sanei.conf configuration file and documentation in the sanei_*.h
|
||||
* files.
|
||||
*
|
||||
* This documenation is far from complete. Any help is appreciated.
|
||||
* This documentation is far from complete. Any help is appreciated.
|
||||
*
|
||||
* @section additional Additional documentation
|
||||
* - The SANE standard can be found at <a
|
||||
* href="http://www.sane-project.org/html/">the SANE webserver</a>.
|
||||
* - The <a href="https://sane-project.gitlab.io/standard/">SANE Standard</a>.
|
||||
* - Information on how to write a backend: <a
|
||||
* href="../backend-writing.txt">backend-writing.txt</a>.
|
||||
* - General SANE documentation is on <a
|
||||
* href="http://www.sane-project.org/docs.html>the SANE documentation
|
||||
* href="http://www.sane-project.org/docs.html">the SANE documentation
|
||||
* page</a>.
|
||||
*
|
||||
* @section contact Contact
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
SHELL = /bin/sh
|
||||
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
top_builddir = ..
|
||||
|
||||
PACKAGE = @PACKAGE@
|
||||
VERSION = @VERSION@
|
||||
distdir = $(top_srcdir)/$(PACKAGE)-$(VERSION)
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
libexecdir = @libexecdir@
|
||||
datadir = @datadir@
|
||||
sysconfdir = @sysconfdir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
localstatedir = @localstatedir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
mandir = @mandir@
|
||||
includedir = @includedir@
|
||||
oldincludedir = /usr/include
|
||||
configdir = ${sysconfdir}/sane.d
|
||||
sanedatadir = ${datadir}/sane
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
||||
RANLIB = @RANLIB@
|
||||
|
||||
CC = @CC@
|
||||
INCLUDES = -I. -I$(srcdir) \
|
||||
-I$(top_builddir)/include/sane -I$(top_srcdir)/include
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CFLAGS = @CFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
DEFS = @DEFS@
|
||||
|
||||
COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
LIBLIB_OBJS = alloca.o getopt.o getopt1.o strndup.o \
|
||||
strdup.o strsep.o snprintf.o usleep.o isfdtype.o \
|
||||
vsyslog.o getenv.o
|
||||
LIBLIB_LTOBJS = alloca.lo getopt.lo getopt1.lo strndup.lo \
|
||||
strdup.lo strsep.lo snprintf.lo usleep.lo isfdtype.lo \
|
||||
vsyslog.lo getenv.lo
|
||||
|
||||
TARGETS = $(LIBLIB_OBJS)
|
||||
TARGETS = liblib.a
|
||||
|
||||
DISTFILES = Makefile.in alloca.c getenv.c getopt.c getopt1.c isfdtype.c \
|
||||
snprintf.c strdup.c strndup.c strsep.c usleep.c vsyslog.c
|
||||
|
||||
.PHONY: all check clean depend dist distclean install uninstall
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .o
|
||||
.c.o:
|
||||
$(COMPILE) $<
|
||||
@test -f $@ || $(COMPILE) $<
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
liblib.a: $(LIBLIB_OBJS)
|
||||
ar r $@ $(LIBLIB_OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
install: all
|
||||
|
||||
uninstall:
|
||||
|
||||
check:
|
||||
|
||||
depend:
|
||||
makedepend -I. -I../include *.c
|
||||
|
||||
clean:
|
||||
rm -f *.out *.o *.lo *~ *.a *.bak $(TESTPROGRAMS)
|
||||
rm -rf .libs
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile
|
||||
|
||||
dist: $(DISTFILES)
|
||||
for file in $(DISTFILES); do \
|
||||
ln $$file $(distdir)/lib 2> /dev/null \
|
||||
|| cp -p $$file $(distdir)/lib ; \
|
||||
done
|
493
lib/alloca.c
493
lib/alloca.c
|
@ -1,493 +0,0 @@
|
|||
/* alloca.c -- allocate automatically reclaimed memory
|
||||
(Mostly) portable public-domain implementation -- D A Gwyn
|
||||
|
||||
This implementation of the PWB library alloca function,
|
||||
which is used to allocate space off the run-time stack so
|
||||
that it is automatically reclaimed upon procedure exit,
|
||||
was inspired by discussions with J. Q. Johnson of Cornell.
|
||||
J.Otto Tennant <jot@cray.com> contributed the Cray support.
|
||||
|
||||
There are some preprocessor constants that can
|
||||
be defined when compiling for your specific system, for
|
||||
improved efficiency; however, the defaults should be okay.
|
||||
|
||||
The general concept of this implementation is to keep
|
||||
track of all alloca-allocated blocks, and reclaim any
|
||||
that are found to be deeper in the stack than the current
|
||||
invocation. This heuristic does not reclaim storage as
|
||||
soon as it becomes invalid, but it will do so eventually.
|
||||
|
||||
As a special case, alloca(0) reclaims storage without
|
||||
allocating any. It is a good idea to use alloca(0) in
|
||||
your main control loop, etc. to force garbage collection. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <../include/sane/config.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ALLOCA
|
||||
|
||||
#ifdef emacs
|
||||
#include "blockinput.h"
|
||||
#endif
|
||||
|
||||
/* If compiling with GCC 2, this file's not needed. */
|
||||
#if !defined (__GNUC__) || __GNUC__ < 2
|
||||
|
||||
/* If someone has defined alloca as a macro,
|
||||
there must be some other way alloca is supposed to work. */
|
||||
#ifndef alloca
|
||||
|
||||
#ifdef emacs
|
||||
#ifdef static
|
||||
/* actually, only want this if static is defined as ""
|
||||
-- this is for usg, in which emacs must undefine static
|
||||
in order to make unexec workable
|
||||
*/
|
||||
#ifndef STACK_DIRECTION
|
||||
you
|
||||
lose
|
||||
-- must know STACK_DIRECTION at compile-time
|
||||
#endif /* STACK_DIRECTION undefined */
|
||||
#endif /* static */
|
||||
#endif /* emacs */
|
||||
|
||||
/* If your stack is a linked list of frames, you have to
|
||||
provide an "address metric" ADDRESS_FUNCTION macro. */
|
||||
|
||||
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
|
||||
long i00afunc ();
|
||||
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
|
||||
#else
|
||||
#define ADDRESS_FUNCTION(arg) &(arg)
|
||||
#endif
|
||||
|
||||
#if __STDC__
|
||||
typedef void *pointer;
|
||||
#else
|
||||
typedef char *pointer;
|
||||
#endif
|
||||
|
||||
#define NULL 0
|
||||
|
||||
/* Different portions of Emacs need to call different versions of
|
||||
malloc. The Emacs executable needs alloca to call xmalloc, because
|
||||
ordinary malloc isn't protected from input signals. On the other
|
||||
hand, the utilities in lib-src need alloca to call malloc; some of
|
||||
them are very simple, and don't have an xmalloc routine.
|
||||
|
||||
Non-Emacs programs expect this to call xmalloc.
|
||||
|
||||
Callers below should use malloc. */
|
||||
|
||||
extern pointer malloc ();
|
||||
|
||||
/* Define STACK_DIRECTION if you know the direction of stack
|
||||
growth for your system; otherwise it will be automatically
|
||||
deduced at run-time.
|
||||
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown */
|
||||
|
||||
#ifndef STACK_DIRECTION
|
||||
#define STACK_DIRECTION 0 /* Direction unknown. */
|
||||
#endif
|
||||
|
||||
#if STACK_DIRECTION != 0
|
||||
|
||||
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
|
||||
|
||||
#else /* STACK_DIRECTION == 0; need run-time code. */
|
||||
|
||||
static int stack_dir; /* 1 or -1 once known. */
|
||||
#define STACK_DIR stack_dir
|
||||
|
||||
static void
|
||||
find_stack_direction ()
|
||||
{
|
||||
static char *addr = NULL; /* Address of first `dummy', once known. */
|
||||
auto char dummy; /* To get stack address. */
|
||||
|
||||
if (addr == NULL)
|
||||
{ /* Initial entry. */
|
||||
addr = ADDRESS_FUNCTION (dummy);
|
||||
|
||||
find_stack_direction (); /* Recurse once. */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Second entry. */
|
||||
if (ADDRESS_FUNCTION (dummy) > addr)
|
||||
stack_dir = 1; /* Stack grew upward. */
|
||||
else
|
||||
stack_dir = -1; /* Stack grew downward. */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* STACK_DIRECTION == 0 */
|
||||
|
||||
/* An "alloca header" is used to:
|
||||
(a) chain together all alloca'ed blocks;
|
||||
(b) keep track of stack depth.
|
||||
|
||||
It is very important that sizeof(header) agree with malloc
|
||||
alignment chunk size. The following default should work okay. */
|
||||
|
||||
#ifndef ALIGN_SIZE
|
||||
#define ALIGN_SIZE sizeof(double)
|
||||
#endif
|
||||
|
||||
typedef union hdr
|
||||
{
|
||||
char align[ALIGN_SIZE]; /* To force sizeof(header). */
|
||||
struct
|
||||
{
|
||||
union hdr *next; /* For chaining headers. */
|
||||
char *deep; /* For stack depth measure. */
|
||||
} h;
|
||||
} header;
|
||||
|
||||
static header *last_alloca_header = NULL; /* -> last alloca header. */
|
||||
|
||||
/* Return a pointer to at least SIZE bytes of storage,
|
||||
which will be automatically reclaimed upon exit from
|
||||
the procedure that called alloca. Originally, this space
|
||||
was supposed to be taken from the current stack frame of the
|
||||
caller, but that method cannot be made to work for some
|
||||
implementations of C, for example under Gould's UTX/32. */
|
||||
|
||||
pointer
|
||||
alloca (size)
|
||||
unsigned size;
|
||||
{
|
||||
auto char probe; /* Probes stack depth: */
|
||||
register char *depth = ADDRESS_FUNCTION (probe);
|
||||
|
||||
#if STACK_DIRECTION == 0
|
||||
if (STACK_DIR == 0) /* Unknown growth direction. */
|
||||
find_stack_direction ();
|
||||
#endif
|
||||
|
||||
/* Reclaim garbage, defined as all alloca'd storage that
|
||||
was allocated from deeper in the stack than currently. */
|
||||
|
||||
{
|
||||
register header *hp; /* Traverses linked list. */
|
||||
|
||||
#ifdef emacs
|
||||
BLOCK_INPUT;
|
||||
#endif
|
||||
|
||||
for (hp = last_alloca_header; hp != NULL;)
|
||||
if ((STACK_DIR > 0 && hp->h.deep > depth)
|
||||
|| (STACK_DIR < 0 && hp->h.deep < depth))
|
||||
{
|
||||
register header *np = hp->h.next;
|
||||
|
||||
free ((pointer) hp); /* Collect garbage. */
|
||||
|
||||
hp = np; /* -> next header. */
|
||||
}
|
||||
else
|
||||
break; /* Rest are not deeper. */
|
||||
|
||||
last_alloca_header = hp; /* -> last valid storage. */
|
||||
|
||||
#ifdef emacs
|
||||
UNBLOCK_INPUT;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
return NULL; /* No allocation required. */
|
||||
|
||||
/* Allocate combined header + user data storage. */
|
||||
|
||||
{
|
||||
register pointer new = malloc (sizeof (header) + size);
|
||||
/* Address of header. */
|
||||
|
||||
((header *) new)->h.next = last_alloca_header;
|
||||
((header *) new)->h.deep = depth;
|
||||
|
||||
last_alloca_header = (header *) new;
|
||||
|
||||
/* User storage begins just after header. */
|
||||
|
||||
return (pointer) ((char *) new + sizeof (header));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
|
||||
|
||||
#ifdef DEBUG_I00AFUNC
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifndef CRAY_STACK
|
||||
#define CRAY_STACK
|
||||
#ifndef CRAY2
|
||||
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
|
||||
struct stack_control_header
|
||||
{
|
||||
long shgrow:32; /* Number of times stack has grown. */
|
||||
long shaseg:32; /* Size of increments to stack. */
|
||||
long shhwm:32; /* High water mark of stack. */
|
||||
long shsize:32; /* Current size of stack (all segments). */
|
||||
};
|
||||
|
||||
/* The stack segment linkage control information occurs at
|
||||
the high-address end of a stack segment. (The stack
|
||||
grows from low addresses to high addresses.) The initial
|
||||
part of the stack segment linkage control information is
|
||||
0200 (octal) words. This provides for register storage
|
||||
for the routine which overflows the stack. */
|
||||
|
||||
struct stack_segment_linkage
|
||||
{
|
||||
long ss[0200]; /* 0200 overflow words. */
|
||||
long sssize:32; /* Number of words in this segment. */
|
||||
long ssbase:32; /* Offset to stack base. */
|
||||
long:32;
|
||||
long sspseg:32; /* Offset to linkage control of previous
|
||||
segment of stack. */
|
||||
long:32;
|
||||
long sstcpt:32; /* Pointer to task common address block. */
|
||||
long sscsnm; /* Private control structure number for
|
||||
microtasking. */
|
||||
long ssusr1; /* Reserved for user. */
|
||||
long ssusr2; /* Reserved for user. */
|
||||
long sstpid; /* Process ID for pid based multi-tasking. */
|
||||
long ssgvup; /* Pointer to multitasking thread giveup. */
|
||||
long sscray[7]; /* Reserved for Cray Research. */
|
||||
long ssa0;
|
||||
long ssa1;
|
||||
long ssa2;
|
||||
long ssa3;
|
||||
long ssa4;
|
||||
long ssa5;
|
||||
long ssa6;
|
||||
long ssa7;
|
||||
long sss0;
|
||||
long sss1;
|
||||
long sss2;
|
||||
long sss3;
|
||||
long sss4;
|
||||
long sss5;
|
||||
long sss6;
|
||||
long sss7;
|
||||
};
|
||||
|
||||
#else /* CRAY2 */
|
||||
/* The following structure defines the vector of words
|
||||
returned by the STKSTAT library routine. */
|
||||
struct stk_stat
|
||||
{
|
||||
long now; /* Current total stack size. */
|
||||
long maxc; /* Amount of contiguous space which would
|
||||
be required to satisfy the maximum
|
||||
stack demand to date. */
|
||||
long high_water; /* Stack high-water mark. */
|
||||
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
|
||||
long hits; /* Number of internal buffer hits. */
|
||||
long extends; /* Number of block extensions. */
|
||||
long stko_mallocs; /* Block allocations by $STKOFEN. */
|
||||
long underflows; /* Number of stack underflow calls ($STKRETN). */
|
||||
long stko_free; /* Number of deallocations by $STKRETN. */
|
||||
long stkm_free; /* Number of deallocations by $STKMRET. */
|
||||
long segments; /* Current number of stack segments. */
|
||||
long maxs; /* Maximum number of stack segments so far. */
|
||||
long pad_size; /* Stack pad size. */
|
||||
long current_address; /* Current stack segment address. */
|
||||
long current_size; /* Current stack segment size. This
|
||||
number is actually corrupted by STKSTAT to
|
||||
include the fifteen word trailer area. */
|
||||
long initial_address; /* Address of initial segment. */
|
||||
long initial_size; /* Size of initial segment. */
|
||||
};
|
||||
|
||||
/* The following structure describes the data structure which trails
|
||||
any stack segment. I think that the description in 'asdef' is
|
||||
out of date. I only describe the parts that I am sure about. */
|
||||
|
||||
struct stk_trailer
|
||||
{
|
||||
long this_address; /* Address of this block. */
|
||||
long this_size; /* Size of this block (does not include
|
||||
this trailer). */
|
||||
long unknown2;
|
||||
long unknown3;
|
||||
long link; /* Address of trailer block of previous
|
||||
segment. */
|
||||
long unknown5;
|
||||
long unknown6;
|
||||
long unknown7;
|
||||
long unknown8;
|
||||
long unknown9;
|
||||
long unknown10;
|
||||
long unknown11;
|
||||
long unknown12;
|
||||
long unknown13;
|
||||
long unknown14;
|
||||
};
|
||||
|
||||
#endif /* CRAY2 */
|
||||
#endif /* not CRAY_STACK */
|
||||
|
||||
#ifdef CRAY2
|
||||
/* Determine a "stack measure" for an arbitrary ADDRESS.
|
||||
I doubt that "lint" will like this much. */
|
||||
|
||||
static long
|
||||
i00afunc (long *address)
|
||||
{
|
||||
struct stk_stat status;
|
||||
struct stk_trailer *trailer;
|
||||
long *block, size;
|
||||
long result = 0;
|
||||
|
||||
/* We want to iterate through all of the segments. The first
|
||||
step is to get the stack status structure. We could do this
|
||||
more quickly and more directly, perhaps, by referencing the
|
||||
$LM00 common block, but I know that this works. */
|
||||
|
||||
STKSTAT (&status);
|
||||
|
||||
/* Set up the iteration. */
|
||||
|
||||
trailer = (struct stk_trailer *) (status.current_address
|
||||
+ status.current_size
|
||||
- 15);
|
||||
|
||||
/* There must be at least one stack segment. Therefore it is
|
||||
a fatal error if "trailer" is null. */
|
||||
|
||||
if (trailer == 0)
|
||||
abort ();
|
||||
|
||||
/* Discard segments that do not contain our argument address. */
|
||||
|
||||
while (trailer != 0)
|
||||
{
|
||||
block = (long *) trailer->this_address;
|
||||
size = trailer->this_size;
|
||||
if (block == 0 || size == 0)
|
||||
abort ();
|
||||
trailer = (struct stk_trailer *) trailer->link;
|
||||
if ((block <= address) && (address < (block + size)))
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set the result to the offset in this segment and add the sizes
|
||||
of all predecessor segments. */
|
||||
|
||||
result = address - block;
|
||||
|
||||
if (trailer == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (trailer->this_size <= 0)
|
||||
abort ();
|
||||
result += trailer->this_size;
|
||||
trailer = (struct stk_trailer *) trailer->link;
|
||||
}
|
||||
while (trailer != 0);
|
||||
|
||||
/* We are done. Note that if you present a bogus address (one
|
||||
not in any segment), you will get a different number back, formed
|
||||
from subtracting the address of the first block. This is probably
|
||||
not what you want. */
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
#else /* not CRAY2 */
|
||||
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
|
||||
Determine the number of the cell within the stack,
|
||||
given the address of the cell. The purpose of this
|
||||
routine is to linearize, in some sense, stack addresses
|
||||
for alloca. */
|
||||
|
||||
static long
|
||||
i00afunc (long address)
|
||||
{
|
||||
long stkl = 0;
|
||||
|
||||
long size, pseg, this_segment, stack;
|
||||
long result = 0;
|
||||
|
||||
struct stack_segment_linkage *ssptr;
|
||||
|
||||
/* Register B67 contains the address of the end of the
|
||||
current stack segment. If you (as a subprogram) store
|
||||
your registers on the stack and find that you are past
|
||||
the contents of B67, you have overflowed the segment.
|
||||
|
||||
B67 also points to the stack segment linkage control
|
||||
area, which is what we are really interested in. */
|
||||
|
||||
stkl = CRAY_STACKSEG_END ();
|
||||
ssptr = (struct stack_segment_linkage *) stkl;
|
||||
|
||||
/* If one subtracts 'size' from the end of the segment,
|
||||
one has the address of the first word of the segment.
|
||||
|
||||
If this is not the first segment, 'pseg' will be
|
||||
nonzero. */
|
||||
|
||||
pseg = ssptr->sspseg;
|
||||
size = ssptr->sssize;
|
||||
|
||||
this_segment = stkl - size;
|
||||
|
||||
/* It is possible that calling this routine itself caused
|
||||
a stack overflow. Discard stack segments which do not
|
||||
contain the target address. */
|
||||
|
||||
while (!(this_segment <= address && address <= stkl))
|
||||
{
|
||||
#ifdef DEBUG_I00AFUNC
|
||||
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
|
||||
#endif
|
||||
if (pseg == 0)
|
||||
break;
|
||||
stkl = stkl - pseg;
|
||||
ssptr = (struct stack_segment_linkage *) stkl;
|
||||
size = ssptr->sssize;
|
||||
pseg = ssptr->sspseg;
|
||||
this_segment = stkl - size;
|
||||
}
|
||||
|
||||
result = address - this_segment;
|
||||
|
||||
/* If you subtract pseg from the current end of the stack,
|
||||
you get the address of the previous stack segment's end.
|
||||
This seems a little convoluted to me, but I'll bet you save
|
||||
a cycle somewhere. */
|
||||
|
||||
while (pseg != 0)
|
||||
{
|
||||
#ifdef DEBUG_I00AFUNC
|
||||
fprintf (stderr, "%011o %011o\n", pseg, size);
|
||||
#endif
|
||||
stkl = stkl - pseg;
|
||||
ssptr = (struct stack_segment_linkage *) stkl;
|
||||
size = ssptr->sssize;
|
||||
pseg = ssptr->sspseg;
|
||||
result += size;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
#endif /* not CRAY2 */
|
||||
#endif /* CRAY */
|
||||
|
||||
#endif /* no alloca */
|
||||
#endif /* not GCC version 2 */
|
||||
|
||||
#endif /* !HAVE_ALLOCA */
|
18
lib/getenv.c
18
lib/getenv.c
|
@ -1,18 +0,0 @@
|
|||
#include "../include/sane/config.h"
|
||||
|
||||
#ifndef HAVE_GETENV
|
||||
|
||||
char *
|
||||
getenv(const char *name)
|
||||
{
|
||||
char *retval = 0;
|
||||
#ifdef HAVE_OS2_H
|
||||
if (0 != DosScanEnv (buf, &retval))
|
||||
retval = 0;
|
||||
#else
|
||||
# error "Missing getenv() on this platform. Please implement."
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_GETENV */
|
831
lib/getopt.c
831
lib/getopt.c
|
@ -1,831 +0,0 @@
|
|||
/* 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, 95, 1996
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
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, 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <../include/sane/config.h>
|
||||
#endif
|
||||
|
||||
#if !defined (__STDC__) || !__STDC__
|
||||
/* This is a separate conditional since some stdc systems
|
||||
reject `defined (const)'. */
|
||||
#ifndef const
|
||||
#define const
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* 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>
|
||||
#if defined (_LIBC) || defined (HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif /* GNU C library. */
|
||||
|
||||
#ifdef VMS
|
||||
#include <unixlib.h>
|
||||
#if HAVE_STRING_H - 0
|
||||
#include <string.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
/* It's not Unix, really. See? Capital letters. */
|
||||
#include <windows.h>
|
||||
#define getpid() GetCurrentProcessId()
|
||||
#endif
|
||||
|
||||
#ifndef _
|
||||
/* This is for other GNU distributions with internationalized messages.
|
||||
When compiling libc, the _ macro is predefined. */
|
||||
#ifdef HAVE_LIBINTL_H
|
||||
# include <libintl.h>
|
||||
# define _(msgid) gettext (msgid)
|
||||
#else
|
||||
# define _(msgid) (msgid)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 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 "getopt.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. */
|
||||
|
||||
char *getenv ();
|
||||
|
||||
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. */
|
||||
#if !defined (__STDC__) || !__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;
|
||||
|
||||
/* Bash 2.0 gives us an environment variable containing flags
|
||||
indicating ARGV elements that should not be considered arguments. */
|
||||
|
||||
static const char *nonoption_flags;
|
||||
static int nonoption_flags_len;
|
||||
|
||||
/* 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. */
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
static void exchange (char **);
|
||||
#endif
|
||||
|
||||
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. */
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
static const char *_getopt_initialize (const char *);
|
||||
#endif
|
||||
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;
|
||||
|
||||
if (posixly_correct == NULL)
|
||||
{
|
||||
/* Bash 2.0 puts a special variable in the environment for each
|
||||
command it runs, specifying which ARGV elements are the results of
|
||||
file name wildcard expansion and therefore should not be
|
||||
considered as options. */
|
||||
char var[100];
|
||||
sprintf (var, "_%d_GNU_nonoption_argv_flags_", getpid ());
|
||||
nonoption_flags = getenv (var);
|
||||
if (nonoption_flags == NULL)
|
||||
nonoption_flags_len = 0;
|
||||
else
|
||||
nonoption_flags_len = strlen (nonoption_flags);
|
||||
}
|
||||
|
||||
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);
|
||||
optind = 1; /* Don't scan ARGV[0], the program name. */
|
||||
}
|
||||
|
||||
/* Test whether ARGV[optind] points to a non-option argument.
|
||||
Either it does not have option syntax, or there is an environment flag
|
||||
from the shell indicating it is not an option. */
|
||||
#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
|
||||
|| (optind < nonoption_flags_len \
|
||||
&& nonoption_flags[optind] == '1'))
|
||||
|
||||
if (nextchar == NULL || *nextchar == '\0')
|
||||
{
|
||||
/* Advance to the next ARGV-element. */
|
||||
|
||||
/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
|
||||
moved back by the user (who may also have changed the arguments). */
|
||||
if (last_nonopt > optind)
|
||||
last_nonopt = optind;
|
||||
if (first_nonopt > optind)
|
||||
first_nonopt = optind;
|
||||
|
||||
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 && NONOPTION_P)
|
||||
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 (NONOPTION_P)
|
||||
{
|
||||
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. */ ;
|
||||
|
||||
#ifdef lint /* Suppress `used before initialized' warning. */
|
||||
indfound = 0;
|
||||
#endif
|
||||
|
||||
/* 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 == 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++;
|
||||
optopt = 0;
|
||||
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);
|
||||
|
||||
optopt = pfound->val;
|
||||
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);
|
||||
optopt = pfound->val;
|
||||
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++;
|
||||
optopt = 0;
|
||||
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);
|
||||
}
|
||||
|
||||
#endif /* _LIBC or not __GNU_LIBRARY__. */
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
/* Compile with -DTEST to make an executable for use in testing
|
||||
the above definition of `getopt'. */
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
|
||||
c = getopt (argc, argv, "abc:d:0123456789");
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf ("option c with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
180
lib/getopt1.c
180
lib/getopt1.c
|
@ -1,180 +0,0 @@
|
|||
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
||||
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993, 1994
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
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, 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <../include/sane/config.h>
|
||||
#endif
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
#if !defined (__STDC__) || !__STDC__
|
||||
/* This is a separate conditional since some stdc systems
|
||||
reject `defined (const)'. */
|
||||
#ifndef const
|
||||
#define const
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* 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__
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
char *getenv ();
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
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__. */
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
int option_index = 0;
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"add", 1, 0, 0},
|
||||
{"append", 0, 0, 0},
|
||||
{"delete", 1, 0, 0},
|
||||
{"verbose", 0, 0, 0},
|
||||
{"create", 0, 0, 0},
|
||||
{"file", 1, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long (argc, argv, "abc:d:0123456789",
|
||||
long_options, &option_index);
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
printf ("option %s", long_options[option_index].name);
|
||||
if (optarg)
|
||||
printf (" with arg %s", optarg);
|
||||
printf ("\n");
|
||||
break;
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf ("option c with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
printf ("option d with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
|
@ -1,25 +0,0 @@
|
|||
#include "../include/sane/config.h"
|
||||
|
||||
#ifndef HAVE_ISFDTYPE
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
int
|
||||
isfdtype(int fd, int fdtype)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (fstat(fd, &st) == -1) return 0; /* couldn't stat fd */
|
||||
|
||||
if (st.st_mode == 0)
|
||||
return 1; /* At least Irix doesn't seem to know socket type */
|
||||
#if defined(S_ISSOCK)
|
||||
return S_ISSOCK(st.st_mode) != 0;
|
||||
#elif defined(S_IFSOCK) && defined(S_IFMT)
|
||||
return (st.st_mode & S_IFMT) == S_IFSOCK;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !HAVE_ISFDTYPE */
|
532
lib/snprintf.c
532
lib/snprintf.c
|
@ -1,532 +0,0 @@
|
|||
#include <../include/sane/config.h>
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
|
||||
/***************************************************************************
|
||||
* LPRng - An Extended Print Spooler System
|
||||
*
|
||||
* Copyright 1988-1997, Patrick Powell, San Diego, CA
|
||||
* papowell@sdsu.edu
|
||||
* See below for conditions of use.
|
||||
*
|
||||
***************************************************************************
|
||||
* MODULE: snprintf.c
|
||||
* PURPOSE: LPRng version of printf - absolutely bombproof (hopefully!)
|
||||
**************************************************************************/
|
||||
#if 0
|
||||
|
||||
The "Artistic License"
|
||||
|
||||
Preamble
|
||||
|
||||
The intent of this document is to state the conditions under which a
|
||||
Package may be copied, such that the Copyright Holder maintains some
|
||||
semblance of artistic control over the development of the package,
|
||||
while giving the users of the package the right to use and distribute
|
||||
the Package in a more-or-less customary fashion, plus the right to make
|
||||
reasonable modifications.
|
||||
|
||||
Definitions:
|
||||
|
||||
"Package" refers to the collection of files distributed by the
|
||||
Copyright Holder, and derivatives of that collection of files
|
||||
created through textual modification.
|
||||
|
||||
"Standard Version" refers to such a Package if it has not been
|
||||
modified, or has been modified in accordance with the wishes
|
||||
of the Copyright Holder as specified below.
|
||||
|
||||
"Copyright Holder" is whoever is named in the copyright or
|
||||
copyrights for the package.
|
||||
|
||||
"You" is you, if you are thinking about copying or distributing
|
||||
this Package.
|
||||
|
||||
"Reasonable copying fee" is whatever you can justify on the
|
||||
basis of media cost, duplication charges, time of people involved,
|
||||
and so on. (You will not be required to justify it to the
|
||||
Copyright Holder, but only to the computing community at large
|
||||
as a market that must bear the fee.)
|
||||
|
||||
"Freely Available" means that no fee is charged for the item
|
||||
itself, though there may be fees involved in handling the item.
|
||||
It also means that recipients of the item may redistribute it
|
||||
under the same conditions they received it.
|
||||
|
||||
1. You may make and give away verbatim copies of the source form of the
|
||||
Standard Version of this Package without restriction, provided that you
|
||||
duplicate all of the original copyright notices and associated disclaimers.
|
||||
|
||||
2. You may apply bug fixes, portability fixes and other modifications
|
||||
derived from the Public Domain or from the Copyright Holder. A Package
|
||||
modified in such a way shall still be considered the Standard Version.
|
||||
|
||||
3. You may otherwise modify your copy of this Package in any way, provided
|
||||
that you insert a prominent notice in each changed file stating how and
|
||||
when you changed that file, and provided that you do at least ONE of the
|
||||
following:
|
||||
|
||||
a) place your modifications in the Public Domain or otherwise make them
|
||||
Freely Available, such as by posting said modifications to Usenet or
|
||||
an equivalent medium, or placing the modifications on a major archive
|
||||
site such as uunet.uu.net, or by allowing the Copyright Holder to include
|
||||
your modifications in the Standard Version of the Package.
|
||||
|
||||
b) use the modified Package only within your corporation or organization.
|
||||
|
||||
c) rename any non-standard executables so the names do not conflict
|
||||
with standard executables, which must also be provided, and provide
|
||||
a separate manual page for each non-standard executable that clearly
|
||||
documents how it differs from the Standard Version.
|
||||
|
||||
d) make other distribution arrangements with the Copyright Holder.
|
||||
|
||||
4. You may distribute the programs of this Package in object code or
|
||||
executable form, provided that you do at least ONE of the following:
|
||||
|
||||
a) distribute a Standard Version of the executables and library files,
|
||||
together with instructions (in the manual page or equivalent) on where
|
||||
to get the Standard Version.
|
||||
|
||||
b) accompany the distribution with the machine-readable source of
|
||||
the Package with your modifications.
|
||||
|
||||
c) give non-standard executables non-standard names, and clearly
|
||||
document the differences in manual pages (or equivalent), together
|
||||
with instructions on where to get the Standard Version.
|
||||
|
||||
d) make other distribution arrangements with the Copyright Holder.
|
||||
|
||||
5. You may charge a reasonable copying fee for any distribution of this
|
||||
Package. You may charge any fee you choose for support of this
|
||||
Package. You may not charge a fee for this Package itself. However,
|
||||
you may distribute this Package in aggregate with other (possibly
|
||||
commercial) programs as part of a larger (possibly commercial) software
|
||||
distribution provided that you do not advertise this Package as a
|
||||
product of your own.
|
||||
|
||||
6. The name of the Copyright Holder may not be used to endorse or promote
|
||||
products derived from this software without specific prior written permission.
|
||||
|
||||
7. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
The End
|
||||
#include "lp.h"
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#define HAVE_STDARGS /* let's hope that works everywhere (mj) */
|
||||
#define VA_LOCAL_DECL va_list ap;
|
||||
#define VA_START(f) va_start(ap, f)
|
||||
#define VA_SHIFT(v,t) ; /* no-op for ANSI */
|
||||
#define VA_END va_end(ap)
|
||||
|
||||
/**** ENDINCLUDE ****/
|
||||
|
||||
static char *const _id = "$Id$";
|
||||
|
||||
/*
|
||||
* dopr(): poor man's version of doprintf
|
||||
*/
|
||||
|
||||
static char * plp_Errormsg ( int err );
|
||||
static void dopr( char *buffer, const char *format, va_list args );
|
||||
static void fmtstr( char *value, int ljust, int len, int zpad, int precision );
|
||||
static void fmtnum( long value, int base, int dosign,
|
||||
int ljust, int len, int zpad, int precision );
|
||||
static void fmtdouble( int fmt, double value,
|
||||
int ljust, int len, int zpad, int precision );
|
||||
static void dostr( char * );
|
||||
static char *output;
|
||||
static void dopr_outch( int c );
|
||||
static char *end;
|
||||
int visible_control = 1;
|
||||
|
||||
/**************************************************************
|
||||
* Original:
|
||||
* Patrick Powell Tue Apr 11 09:48:21 PDT 1995
|
||||
* A bombproof version of doprnt (dopr) included.
|
||||
* Sigh. This sort of thing is always nasty do deal with. Note that
|
||||
* the version here does not include floating point...
|
||||
*
|
||||
* plp_snprintf() is used instead of sprintf() as it does limit checks
|
||||
* for string length. This covers a nasty loophole.
|
||||
*
|
||||
* The other functions are there to prevent NULL pointers from
|
||||
* causing nast effects.
|
||||
**************************************************************/
|
||||
|
||||
int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
|
||||
{
|
||||
str[0] = 0;
|
||||
end = str+count-1;
|
||||
dopr( str, fmt, args );
|
||||
if( count>0 ){
|
||||
end[0] = 0;
|
||||
}
|
||||
return(strlen(str));
|
||||
}
|
||||
|
||||
/* VARARGS3 */
|
||||
#ifdef HAVE_STDARGS
|
||||
int snprintf (char *str,size_t count,const char *fmt,...)
|
||||
#else
|
||||
int snprintf (va_alist) va_dcl
|
||||
#endif
|
||||
{
|
||||
#ifndef HAVE_STDARGS
|
||||
char *str;
|
||||
size_t count;
|
||||
char *fmt;
|
||||
#endif
|
||||
VA_LOCAL_DECL
|
||||
|
||||
VA_START (fmt);
|
||||
VA_SHIFT (str, char *);
|
||||
VA_SHIFT (count, size_t );
|
||||
VA_SHIFT (fmt, char *);
|
||||
(void) vsnprintf ( str, count, fmt, ap);
|
||||
VA_END;
|
||||
return( strlen( str ) );
|
||||
}
|
||||
|
||||
static void dopr( char *buffer, const char *format, va_list args )
|
||||
{
|
||||
int ch;
|
||||
long value;
|
||||
int longflag = 0;
|
||||
char *strvalue;
|
||||
int ljust;
|
||||
int len;
|
||||
int zpad;
|
||||
int precision;
|
||||
int set_precision;
|
||||
double dval;
|
||||
int err = errno;
|
||||
|
||||
output = buffer;
|
||||
while( (ch = *format++) ){
|
||||
switch( ch ){
|
||||
case '%':
|
||||
ljust = len = zpad = 0;
|
||||
precision = -1; set_precision = 0;
|
||||
nextch:
|
||||
ch = *format++;
|
||||
switch( ch ){
|
||||
case 0:
|
||||
dostr( "**end of format**" );
|
||||
return;
|
||||
case '-': ljust = 1; goto nextch;
|
||||
case '.': set_precision = 1; precision = 0; goto nextch;
|
||||
case '*': len = va_arg( args, int ); goto nextch;
|
||||
case '0': /* set zero padding if len not set */
|
||||
if(len==0 && set_precision == 0 ) zpad = '0';
|
||||
case '1': case '2': case '3':
|
||||
case '4': case '5': case '6':
|
||||
case '7': case '8': case '9':
|
||||
if( set_precision ){
|
||||
precision = precision*10 + ch - '0';
|
||||
} else {
|
||||
len = len*10 + ch - '0';
|
||||
}
|
||||
goto nextch;
|
||||
case 'l': longflag = 1; goto nextch;
|
||||
case 'u': case 'U':
|
||||
/*fmtnum(value,base,dosign,ljust,len, zpad, precision) */
|
||||
if( longflag ){
|
||||
value = va_arg( args, long );
|
||||
} else {
|
||||
value = va_arg( args, int );
|
||||
}
|
||||
fmtnum( value, 10,0, ljust, len, zpad, precision ); break;
|
||||
case 'o': case 'O':
|
||||
/*fmtnum(value,base,dosign,ljust,len, zpad, precision) */
|
||||
if( longflag ){
|
||||
value = va_arg( args, long );
|
||||
} else {
|
||||
value = va_arg( args, int );
|
||||
}
|
||||
fmtnum( value, 8,0, ljust, len, zpad, precision ); break;
|
||||
case 'd': case 'D':
|
||||
if( longflag ){
|
||||
value = va_arg( args, long );
|
||||
} else {
|
||||
value = va_arg( args, int );
|
||||
}
|
||||
fmtnum( value, 10,1, ljust, len, zpad, precision ); break;
|
||||
case 'x':
|
||||
if( longflag ){
|
||||
value = va_arg( args, long );
|
||||
} else {
|
||||
value = va_arg( args, int );
|
||||
}
|
||||
fmtnum( value, 16,0, ljust, len, zpad, precision ); break;
|
||||
case 'X':
|
||||
if( longflag ){
|
||||
value = va_arg( args, long );
|
||||
} else {
|
||||
value = va_arg( args, int );
|
||||
}
|
||||
fmtnum( value,-16,0, ljust, len, zpad, precision ); break;
|
||||
case 's':
|
||||
strvalue = va_arg( args, char *);
|
||||
fmtstr( strvalue,ljust,len, zpad, precision );
|
||||
break;
|
||||
case 'c':
|
||||
ch = va_arg( args, int );
|
||||
{ char b[2];
|
||||
int vsb = visible_control;
|
||||
b[0] = ch;
|
||||
b[1] = 0;
|
||||
visible_control = 0;
|
||||
fmtstr( b,ljust,len, zpad, precision );
|
||||
visible_control = vsb;
|
||||
}
|
||||
break;
|
||||
case 'f': case 'g':
|
||||
dval = va_arg( args, double );
|
||||
fmtdouble( ch, dval,ljust,len, zpad, precision ); break;
|
||||
case 'm':
|
||||
fmtstr( plp_Errormsg(err),ljust,len, zpad, precision ); break;
|
||||
case '%': dopr_outch( ch ); continue;
|
||||
default:
|
||||
dostr( "???????" );
|
||||
}
|
||||
longflag = 0;
|
||||
break;
|
||||
default:
|
||||
dopr_outch( ch );
|
||||
break;
|
||||
}
|
||||
}
|
||||
*output = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Format '%[-]len[.precision]s'
|
||||
* - = left justify (ljust)
|
||||
* len = minimum length
|
||||
* precision = numbers of chars in string to use
|
||||
*/
|
||||
static void
|
||||
fmtstr( char *value, int ljust, int len, int zpad, int precision )
|
||||
{
|
||||
int padlen, strlen, i, c; /* amount to pad */
|
||||
|
||||
if( value == 0 ){
|
||||
value = "<NULL>";
|
||||
}
|
||||
if( precision > 0 ){
|
||||
strlen = precision;
|
||||
} else {
|
||||
/* cheap strlen so you do not have library call */
|
||||
for( strlen = 0; (c=value[strlen]); ++ strlen ){
|
||||
if( visible_control && iscntrl( c ) && !isspace( c ) ){
|
||||
++strlen;
|
||||
}
|
||||
}
|
||||
}
|
||||
padlen = len - strlen;
|
||||
if( padlen < 0 ) padlen = 0;
|
||||
if( ljust ) padlen = -padlen;
|
||||
while( padlen > 0 ) {
|
||||
dopr_outch( ' ' );
|
||||
--padlen;
|
||||
}
|
||||
/* output characters */
|
||||
for( i = 0; (c = value[i]); ++i ){
|
||||
if( visible_control && iscntrl( c ) && !isspace( c ) ){
|
||||
dopr_outch('^');
|
||||
c = ('@' | (c & 0x1F));
|
||||
}
|
||||
dopr_outch(c);
|
||||
}
|
||||
while( padlen < 0 ) {
|
||||
dopr_outch( ' ' );
|
||||
++padlen;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fmtnum( long value, int base, int dosign, int ljust,
|
||||
int len, int zpad, int precision )
|
||||
{
|
||||
int signvalue = 0;
|
||||
unsigned long uvalue;
|
||||
char convert[20];
|
||||
int place = 0;
|
||||
int padlen = 0; /* amount to pad */
|
||||
int caps = 0;
|
||||
|
||||
/* DEBUGP(("value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
|
||||
value, base, dosign, ljust, len, zpad )); */
|
||||
uvalue = value;
|
||||
if( dosign ){
|
||||
if( value < 0 ) {
|
||||
signvalue = '-';
|
||||
uvalue = -value;
|
||||
}
|
||||
}
|
||||
if( base < 0 ){
|
||||
caps = 1;
|
||||
base = -base;
|
||||
}
|
||||
do{
|
||||
convert[place++] =
|
||||
(caps? "0123456789ABCDEF":"0123456789abcdef")
|
||||
[uvalue % (unsigned)base ];
|
||||
uvalue = (uvalue / (unsigned)base );
|
||||
}while(uvalue);
|
||||
convert[place] = 0;
|
||||
padlen = len - place;
|
||||
if( padlen < 0 ) padlen = 0;
|
||||
if( ljust ) padlen = -padlen;
|
||||
/* DEBUGP(( "str '%s', place %d, sign %c, padlen %d\n",
|
||||
convert,place,signvalue,padlen)); */
|
||||
if( zpad && padlen > 0 ){
|
||||
if( signvalue ){
|
||||
dopr_outch( signvalue );
|
||||
--padlen;
|
||||
signvalue = 0;
|
||||
}
|
||||
while( padlen > 0 ){
|
||||
dopr_outch( zpad );
|
||||
--padlen;
|
||||
}
|
||||
}
|
||||
while( padlen > 0 ) {
|
||||
dopr_outch( ' ' );
|
||||
--padlen;
|
||||
}
|
||||
if( signvalue ) dopr_outch( signvalue );
|
||||
while( place > 0 ) dopr_outch( convert[--place] );
|
||||
while( padlen < 0 ){
|
||||
dopr_outch( ' ' );
|
||||
++padlen;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fmtdouble( int fmt, double value, int ljust, int len, int zpad, int precision )
|
||||
{
|
||||
char convert[128];
|
||||
char fmtstr[128];
|
||||
int l;
|
||||
|
||||
if( len == 0 ) len = 10;
|
||||
if( len > sizeof(convert) - 10 ){
|
||||
len = sizeof(convert) - 10;
|
||||
}
|
||||
if( precision > sizeof(convert) - 10 ){
|
||||
precision = sizeof(convert) - 10;
|
||||
}
|
||||
if( precision > len ) precision = len;
|
||||
strcpy( fmtstr, "%" );
|
||||
if( ljust ) strcat(fmtstr, "-" );
|
||||
if( len ){
|
||||
sprintf( fmtstr+strlen(fmtstr), "%d", len );
|
||||
}
|
||||
if( precision > 0 ){
|
||||
sprintf( fmtstr+strlen(fmtstr), ".%d", precision );
|
||||
}
|
||||
l = strlen( fmtstr );
|
||||
fmtstr[l] = fmt;
|
||||
fmtstr[l+1] = 0;
|
||||
sprintf( convert, fmtstr, value );
|
||||
dostr( convert );
|
||||
}
|
||||
|
||||
static void dostr( char *str )
|
||||
{
|
||||
while(*str) dopr_outch(*str++);
|
||||
}
|
||||
|
||||
static void dopr_outch( int c )
|
||||
{
|
||||
if( end == 0 || output < end ){
|
||||
*output++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* static char *plp_errormsg( int err )
|
||||
* returns a printable form of the
|
||||
* errormessage corresponding to the valie of err.
|
||||
* This is the poor man's version of sperror(), not available on all systems
|
||||
* Patrick Powell Tue Apr 11 08:05:05 PDT 1995
|
||||
****************************************************************************/
|
||||
/****************************************************************************/
|
||||
#if !defined(HAVE_STRERROR)
|
||||
|
||||
# if defined(HAVE_SYS_NERR)
|
||||
# if !defined(HAVE_SYS_NERR_DEF)
|
||||
extern int sys_nerr;
|
||||
# endif
|
||||
# define num_errors (sys_nerr)
|
||||
# else
|
||||
# define num_errors (-1) /* always use "errno=%d" */
|
||||
# endif
|
||||
|
||||
# if defined(HAVE_SYS_ERRLIST)
|
||||
# if !defined(HAVE_SYS_ERRLIST_DEF)
|
||||
extern const char *const sys_errlist[];
|
||||
# endif
|
||||
# else
|
||||
# undef num_errors
|
||||
# define num_errors (-1) /* always use "errno=%d" */
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
static char * plp_Errormsg ( int err )
|
||||
{
|
||||
char *cp;
|
||||
|
||||
#if defined(HAVE_STRERROR)
|
||||
cp = (void *)strerror(err);
|
||||
#else
|
||||
# if defined(HAVE_SYS_ERRLIST)
|
||||
if (err >= 0 && err < num_errors) {
|
||||
cp = (void *)sys_errlist[err];
|
||||
} else
|
||||
# endif
|
||||
{
|
||||
static char msgbuf[32]; /* holds "errno=%d". */
|
||||
/* SAFE use of sprintf */
|
||||
(void) sprintf (msgbuf, "errno=%d", err);
|
||||
cp = msgbuf;
|
||||
}
|
||||
#endif
|
||||
return (cp);
|
||||
}
|
||||
|
||||
#if defined(TEST)
|
||||
#include <stdio.h>
|
||||
int main( void )
|
||||
{
|
||||
char buffer[128];
|
||||
char *t;
|
||||
char *test1 = "01234";
|
||||
errno = 1;
|
||||
plp_snprintf( buffer, sizeof(buffer), (t="errno '%m'")); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%s"), test1 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%12s"), test1 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%-12s"), test1 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%12.2s"), test1 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%-12.2s"), test1 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%g"), 1.25 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%g"), 1.2345 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%12g"), 1.25 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%12.2g"), 1.25 ); printf( "%s = '%s'\n", t, buffer );
|
||||
plp_snprintf( buffer, sizeof(buffer), (t = "%0*d"), 6, 1 ); printf( "%s = '%s'\n", t, buffer );
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* HAVE_SNPRINTF */
|
38
lib/strdup.c
38
lib/strdup.c
|
@ -1,38 +0,0 @@
|
|||
/* Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <../include/sane/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
|
||||
char *
|
||||
strdup (const char * s)
|
||||
{
|
||||
char *clone;
|
||||
size_t size;
|
||||
|
||||
size = strlen (s) + 1;
|
||||
clone = malloc (size);
|
||||
memcpy (clone, s, size);
|
||||
return clone;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRDUP */
|
|
@ -1,39 +0,0 @@
|
|||
/* Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <../include/sane/config.h>
|
||||
|
||||
#ifndef HAVE_STRNDUP
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
char *
|
||||
strndup (const char * s, size_t n)
|
||||
{
|
||||
char *clone;
|
||||
|
||||
clone = malloc (n + 1);
|
||||
strncpy (clone, s, n);
|
||||
clone[n] = '\0';
|
||||
return clone;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRNDUP */
|
49
lib/strsep.c
49
lib/strsep.c
|
@ -1,49 +0,0 @@
|
|||
/* Copyright (C) 1992, 1993, 1996 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <../include/sane/config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifndef HAVE_STRSEP
|
||||
|
||||
char *
|
||||
strsep (char **stringp, const char *delim)
|
||||
{
|
||||
char *begin, *end;
|
||||
|
||||
begin = *stringp;
|
||||
if (! begin || *begin == '\0')
|
||||
return NULL;
|
||||
|
||||
/* Find the end of the token. */
|
||||
end = strpbrk (begin, delim);
|
||||
if (end)
|
||||
{
|
||||
/* Terminate the token and set *STRINGP past NUL character. */
|
||||
*end++ = '\0';
|
||||
*stringp = end;
|
||||
}
|
||||
else
|
||||
/* No more delimiters; this is the last token. */
|
||||
*stringp = NULL;
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRSEP */
|
64
lib/usleep.c
64
lib/usleep.c
|
@ -1,64 +0,0 @@
|
|||
/* Copyright (C) 1992 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#ifdef __TANDEM
|
||||
#include <floss.h>
|
||||
#endif
|
||||
|
||||
#include <../include/sane/config.h>
|
||||
|
||||
#ifndef HAVE_USLEEP
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
# include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#ifdef apollo
|
||||
# include <apollo/base.h>
|
||||
# include <apollo/time.h>
|
||||
static time_$clock_t DomainTime100mS =
|
||||
{
|
||||
0, 100000/4
|
||||
};
|
||||
static status_$t DomainStatus;
|
||||
#endif
|
||||
|
||||
/* Sleep USECONDS microseconds, or until a previously set timer goes off. */
|
||||
unsigned int
|
||||
usleep (unsigned int useconds)
|
||||
{
|
||||
#ifdef apollo
|
||||
/* The usleep function does not work under the SYS5.3 environment.
|
||||
Use the Domain/OS time_$wait call instead. */
|
||||
time_$wait (time_$relative, DomainTime100mS, &DomainStatus);
|
||||
#else
|
||||
struct timeval delay;
|
||||
|
||||
delay.tv_sec = 0;
|
||||
delay.tv_usec = useconds;
|
||||
select (0, 0, 0, 0, &delay);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !HAVE_USLEEP */
|
|
@ -1,17 +0,0 @@
|
|||
#include "../include/sane/config.h"
|
||||
|
||||
#include "stdio.h"
|
||||
#include <syslog.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifndef HAVE_VSYSLOG
|
||||
|
||||
void
|
||||
vsyslog(int priority, const char *format, va_list args)
|
||||
{
|
||||
char buf[1024];
|
||||
vsnprintf(buf, sizeof(buf), format, args);
|
||||
syslog(priority, "%s", buf);
|
||||
}
|
||||
|
||||
#endif /* !HAVE_VSYSLOG */
|
|
@ -97,30 +97,31 @@ sanei_debug_msg
|
|||
(int level, int max_level, const char *be, const char *fmt, va_list ap)
|
||||
{
|
||||
char *msg;
|
||||
|
||||
|
||||
if (max_level >= level)
|
||||
{
|
||||
if ( 1 == isfdtype(fileno(stderr), S_IFSOCK) )
|
||||
{
|
||||
msg = (char *)malloc (sizeof(char) * (strlen(be) + strlen(fmt) + 4));
|
||||
if (msg == NULL)
|
||||
{
|
||||
syslog (LOG_DEBUG, "[sanei_debug] malloc() failed\n");
|
||||
vsyslog (LOG_DEBUG, fmt, ap);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (msg, "[%s] %s", be, fmt);
|
||||
struct stat sb;
|
||||
if ( 0 == fstat(fileno(stderr), &sb) && S_IFSOCK == (sb.st_mode & S_IFMT) )
|
||||
{
|
||||
msg = (char *)malloc (sizeof(char) * (strlen(be) + strlen(fmt) + 4));
|
||||
if (msg == NULL)
|
||||
{
|
||||
syslog (LOG_DEBUG, "[sanei_debug] malloc() failed\n");
|
||||
vsyslog (LOG_DEBUG, fmt, ap);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (msg, "[%s] %s", be, fmt);
|
||||
vsyslog(LOG_DEBUG, msg, ap);
|
||||
free (msg);
|
||||
}
|
||||
}
|
||||
free (msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "[%s] ", be);
|
||||
{
|
||||
fprintf (stderr, "[%s] ", be);
|
||||
vfprintf (stderr, fmt, ap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ sanei_w_array (Wire * w, SANE_Word * len_ptr, void **v,
|
|||
|| (w->allocated_memory + len * element_size) > MAX_MEM)
|
||||
{
|
||||
DBG (0, "sanei_w_array: DECODE: maximum amount of allocated memory "
|
||||
"exceeded (limit: %u, new allocation: %u, total: %u bytes)\n",
|
||||
"exceeded (limit: %u, new allocation: %zu, total: %zu bytes)\n",
|
||||
MAX_MEM, len * element_size, MAX_MEM + len * element_size);
|
||||
w->status = ENOMEM;
|
||||
return;
|
||||
|
@ -289,7 +289,7 @@ sanei_w_ptr (Wire * w, void **v, WireCodecFunc w_value, size_t value_size)
|
|||
if (value_size > MAX_MEM)
|
||||
{
|
||||
DBG (0, "sanei_w_ptr: DECODE: maximum amount of allocated memory "
|
||||
"exceeded (limit: %u, new allocation: %u, total: %u bytes)\n",
|
||||
"exceeded (limit: %u, new allocation: %zu, total: %zu bytes)\n",
|
||||
MAX_MEM, value_size, (w->allocated_memory + value_size));
|
||||
w->status = ENOMEM;
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
scanadf
|
||||
xcam
|
||||
xscanimage
|
||||
|
|
@ -51,7 +51,6 @@ LINK = $(CC) $(LDFLAGS) -o $@
|
|||
@SET_MAKE@
|
||||
|
||||
PROGRAMS = $(BINPROGS)
|
||||
LIBLIB = ../lib/liblib.a
|
||||
LIBSANEI = ../sanei/libsanei.a
|
||||
|
||||
XSCANIMAGE_OBJS = xscanimage.o progress.o preview.o preferences.o gtkglue.o
|
||||
|
@ -92,16 +91,16 @@ uninstall:
|
|||
done
|
||||
rm -f $(sanedatadir)/sane-style.rc
|
||||
|
||||
xscanimage: $(XSCANIMAGE_OBJS) $(LIBSANEI) $(LIBLIB)
|
||||
xscanimage: $(XSCANIMAGE_OBJS) $(LIBSANEI)
|
||||
$(LINK) $(XSCANIMAGE_OBJS) $(LIBSANEI) \
|
||||
$(LIBLIB) $(GIMP_LIBS) $(GTK_LIBS) $(LIBS)
|
||||
$(GIMP_LIBS) $(GTK_LIBS) $(LIBS)
|
||||
|
||||
xcam: $(XCAM_OBJS) $(LIBSANEI) $(LIBLIB)
|
||||
xcam: $(XCAM_OBJS) $(LIBSANEI)
|
||||
$(LINK) $(XCAM_OBJS) $(LIBSANEI) \
|
||||
$(LIBLIB) $(GTK_LIBS) $(LIBS)
|
||||
$(GTK_LIBS) $(LIBS)
|
||||
|
||||
scanadf: $(SCANADF_OBJS) $(LIBLIB)
|
||||
$(LINK) $(SCANADF_OBJS) $(LIBLIB) $(LIBS)
|
||||
scanadf: $(SCANADF_OBJS)
|
||||
$(LINK) $(SCANADF_OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f *.o *~ .*~ *.bak
|
||||
|
|
|
@ -403,10 +403,10 @@ button_update (GtkWidget * widget, GSGDialogElement * elem)
|
|||
{
|
||||
GSGDialog *dialog = elem->dialog;
|
||||
int opt_num = elem - dialog->element;
|
||||
const SANE_Option_Descriptor *opt;
|
||||
// const SANE_Option_Descriptor *opt;
|
||||
SANE_Word val = SANE_FALSE;
|
||||
|
||||
opt = sane_get_option_descriptor (dialog->dev, opt_num);
|
||||
// opt = sane_get_option_descriptor (dialog->dev, opt_num);
|
||||
if (GTK_TOGGLE_BUTTON (widget)->active)
|
||||
val = SANE_TRUE;
|
||||
set_option (dialog, opt_num, &val, SANE_ACTION_SET_VALUE);
|
||||
|
@ -913,6 +913,7 @@ panel_build (GSGDialog * dialog)
|
|||
char **str_list;
|
||||
int i, j;
|
||||
int num_vector_opts = 0, *vector_opts;
|
||||
SANE_Bool val_in_list;
|
||||
|
||||
main_hbox = gtk_hbox_new (FALSE, 2);
|
||||
|
||||
|
@ -1073,13 +1074,23 @@ panel_build (GSGDialog * dialog)
|
|||
case SANE_CONSTRAINT_WORD_LIST:
|
||||
/* use a "list-selection" widget */
|
||||
num_words = opt->constraint.word_list[0];
|
||||
if (num_words == 0)
|
||||
{
|
||||
fprintf (stderr, "panel_build: empty word list!\n");
|
||||
break;
|
||||
}
|
||||
val_in_list = SANE_FALSE;
|
||||
str_list = malloc ((num_words + 1) * sizeof (str_list[0]));
|
||||
for (j = 0; j < num_words; ++j)
|
||||
{
|
||||
if (opt->constraint.word_list[j + 1] == val)
|
||||
val_in_list = SANE_TRUE;
|
||||
sprintf (str, "%d", opt->constraint.word_list[j + 1]);
|
||||
str_list[j] = strdup (str);
|
||||
}
|
||||
str_list[j] = 0;
|
||||
if (!val_in_list)
|
||||
val = opt->constraint.word_list[1];
|
||||
sprintf (str, "%d", val);
|
||||
option_menu_new (parent, title, str_list, str, elem,
|
||||
dialog->tooltips, opt->desc,
|
||||
|
@ -1409,12 +1420,16 @@ gsg_sync (GSGDialog * dialog)
|
|||
if (!SANE_OPTION_IS_ACTIVE (opt->cap))
|
||||
continue;
|
||||
|
||||
if (opt->type != SANE_TYPE_INT && opt->type != SANE_TYPE_FIXED)
|
||||
if ((opt->type != SANE_TYPE_INT) && (opt->type != SANE_TYPE_FIXED))
|
||||
continue;
|
||||
|
||||
if (opt->size == sizeof (SANE_Word))
|
||||
continue;
|
||||
|
||||
// If curves is hidden (advanced option perhaps) then nothing to do.
|
||||
if (!dialog->element[i].widget)
|
||||
continue;
|
||||
|
||||
/* ok, we're dealing with an active vector */
|
||||
|
||||
optlen = opt->size / sizeof (SANE_Word);
|
||||
|
@ -1475,9 +1490,12 @@ gsg_set_sensitivity (GSGDialog * dialog, int sensitive)
|
|||
if (!SANE_OPTION_IS_ACTIVE (opt->cap)
|
||||
|| opt->type == SANE_TYPE_GROUP || !dialog->element[i].widget)
|
||||
continue;
|
||||
|
||||
#ifdef SANE_CAP_ALWAYS_SETTABLE
|
||||
if (!(opt->cap & SANE_CAP_ALWAYS_SETTABLE))
|
||||
gtk_widget_set_sensitive (dialog->element[i].widget, sensitive);
|
||||
#else
|
||||
gtk_widget_set_sensitive (dialog->element[i].widget, sensitive);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,11 +73,13 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "gtkglue.h"
|
||||
#include "preview.h"
|
||||
#include "preferences.h"
|
||||
#include "progress.h"
|
||||
|
||||
#define DBG_fatal 0
|
||||
#define DBG_error 1
|
||||
|
@ -860,6 +862,10 @@ scan_start (Preview * p)
|
|||
SANE_Status status;
|
||||
char buf[256];
|
||||
int fd, y;
|
||||
Progress_t *progress;
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
struct timeval start, current;
|
||||
#endif
|
||||
|
||||
gtk_widget_set_sensitive (p->cancel, TRUE);
|
||||
gtk_widget_set_sensitive (p->preview, FALSE);
|
||||
|
@ -881,6 +887,30 @@ scan_start (Preview * p)
|
|||
gsg_sync (p->dialog);
|
||||
|
||||
status = sane_start (dev);
|
||||
#ifdef SANE_STATUS_WARMING_UP
|
||||
if (status == SANE_STATUS_WARMING_UP)
|
||||
{
|
||||
snprintf (buf, sizeof (buf), "Scanner is warming up.");
|
||||
progress =
|
||||
progress_new ("Warming up ...", buf, GTK_WINDOW(p->top), NULL, 0);
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
gettimeofday (&start, NULL);
|
||||
#endif
|
||||
while (status == SANE_STATUS_WARMING_UP)
|
||||
{
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
gettimeofday (¤t, NULL);
|
||||
/* we assume that warming up won't exceed 60 seconds */
|
||||
progress_update (progress,
|
||||
(current.tv_sec - start.tv_sec) / (gfloat) 60);
|
||||
#endif
|
||||
while (gtk_events_pending ())
|
||||
gtk_main_iteration ();
|
||||
status = sane_start (dev);
|
||||
}
|
||||
progress_free (progress);
|
||||
}
|
||||
#endif /* SANE_STATUS_WARMING_UP */
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
snprintf (buf, sizeof (buf),
|
||||
|
|
102
src/progress.c
102
src/progress.c
|
@ -20,12 +20,12 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include <gtk/gtk.h>
|
||||
#include "progress.h"
|
||||
|
||||
static const int progress_x = 5;
|
||||
static const int progress_y = 5;
|
||||
|
||||
void
|
||||
progress_cancel (GtkWidget * widget, gpointer data)
|
||||
{
|
||||
|
@ -36,18 +36,27 @@ progress_cancel (GtkWidget * widget, gpointer data)
|
|||
|
||||
|
||||
Progress_t *
|
||||
progress_new (char *title, char *text,
|
||||
progress_new (char *title, char *text, GtkWindow * parent,
|
||||
GtkSignalFunc callback, gpointer callback_data)
|
||||
{
|
||||
GtkWidget *button, *label;
|
||||
GtkBox *vbox, *hbox;
|
||||
Progress_t *p;
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
gint x, y;
|
||||
#endif
|
||||
|
||||
p = (Progress_t *) malloc (sizeof (Progress_t));
|
||||
p->callback = callback;
|
||||
p->firstTime = 0;
|
||||
|
||||
p->shell = gtk_dialog_new ();
|
||||
gtk_widget_set_uposition (p->shell, progress_x, progress_y);
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
gtk_window_get_position (GTK_WINDOW (parent), &x, &y);
|
||||
gtk_widget_set_uposition (p->shell, x, y);
|
||||
#else
|
||||
gtk_window_set_transient_for (GTK_WINDOW (p->shell), parent);
|
||||
#endif
|
||||
gtk_window_set_title (GTK_WINDOW (p->shell), title);
|
||||
vbox = GTK_BOX (GTK_DIALOG (p->shell)->vbox);
|
||||
hbox = GTK_BOX (GTK_DIALOG (p->shell)->action_area);
|
||||
|
@ -62,14 +71,28 @@ progress_new (char *title, char *text,
|
|||
gtk_widget_set_usize (p->pbar, 200, 20);
|
||||
gtk_box_pack_start (vbox, p->pbar, TRUE, TRUE, 0);
|
||||
|
||||
button = gtk_toggle_button_new_with_label ("Cancel");
|
||||
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||
(GtkSignalFunc) progress_cancel, p);
|
||||
gtk_box_pack_start (hbox, button, TRUE, TRUE, 0);
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
p->etaIndicator = gtk_label_new (ETA_LABEL ": ?");
|
||||
gtk_misc_set_alignment (GTK_MISC (p->etaIndicator), 0.0, 0.5);
|
||||
gtk_box_pack_start (vbox, p->etaIndicator, FALSE, TRUE, 0);
|
||||
#endif
|
||||
|
||||
/* no cancel button if no callback */
|
||||
if (callback != NULL)
|
||||
{
|
||||
button = gtk_toggle_button_new_with_label ("Cancel");
|
||||
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||
(GtkSignalFunc) progress_cancel, p);
|
||||
gtk_box_pack_start (hbox, button, TRUE, TRUE, 0);
|
||||
}
|
||||
|
||||
gtk_widget_show (label);
|
||||
gtk_widget_show (p->pbar);
|
||||
gtk_widget_show (button);
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
gtk_widget_show (p->etaIndicator);
|
||||
#endif
|
||||
if (callback != NULL)
|
||||
gtk_widget_show (button);
|
||||
gtk_widget_show (GTK_WIDGET (p->shell));
|
||||
gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), 0);
|
||||
return p;
|
||||
|
@ -88,6 +111,61 @@ progress_free (Progress_t * p)
|
|||
void
|
||||
progress_update (Progress_t * p, gfloat newval)
|
||||
{
|
||||
if (p)
|
||||
gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), newval);
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
struct timeval tv;
|
||||
int now;
|
||||
char buff[40];
|
||||
int remaining;
|
||||
#endif
|
||||
|
||||
if (!p)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), newval);
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
gettimeofday (&tv, NULL);
|
||||
now = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
|
||||
if (p->firstTime == 0)
|
||||
{
|
||||
p->lastTime = p->firstTime = now;
|
||||
p->firstVal = newval;
|
||||
return;
|
||||
}
|
||||
|
||||
if (newval > p->firstVal && now - p->lastTime > 1000)
|
||||
{
|
||||
remaining =
|
||||
(int) ((now - p->firstTime) * (1.0 - newval) / (newval -
|
||||
p->firstVal) /
|
||||
1000.0 + 0.9);
|
||||
|
||||
p->lastTime = now;
|
||||
|
||||
if (remaining >= 3600)
|
||||
{
|
||||
snprintf (buff, sizeof (buff), ETA_LABEL ": %d h %d min",
|
||||
remaining / 3600, (remaining / 60) % 60);
|
||||
}
|
||||
else if (remaining >= 600)
|
||||
{
|
||||
snprintf (buff, sizeof (buff), ETA_LABEL ": %d min",
|
||||
remaining / 60);
|
||||
}
|
||||
else if (remaining >= 60)
|
||||
{
|
||||
snprintf (buff, sizeof (buff), ETA_LABEL ": %d min %d sec",
|
||||
remaining / 60, remaining % 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (buff, sizeof (buff), ETA_LABEL ": %d sec", remaining);
|
||||
}
|
||||
|
||||
gtk_label_set_text (GTK_LABEL (p->etaIndicator), buff);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -18,17 +18,24 @@
|
|||
#ifndef progress_h
|
||||
#define progress_h
|
||||
|
||||
#define ETA_LABEL "Estimated time remaining"
|
||||
|
||||
typedef struct Progress_t
|
||||
{
|
||||
GtkSignalFunc callback;
|
||||
gpointer callback_data;
|
||||
GtkWidget *shell;
|
||||
GtkWidget *pbar;
|
||||
}
|
||||
{
|
||||
GtkSignalFunc callback;
|
||||
gpointer callback_data;
|
||||
GtkWidget *shell;
|
||||
GtkWidget *pbar;
|
||||
GtkWidget *etaIndicator;
|
||||
gfloat firstVal;
|
||||
int firstTime;
|
||||
int lastTime;
|
||||
}
|
||||
Progress_t;
|
||||
|
||||
extern Progress_t *progress_new (char *, char *, GtkSignalFunc, void *);
|
||||
extern void progress_free (Progress_t *);
|
||||
extern void progress_update (Progress_t *, gfloat);
|
||||
extern Progress_t * progress_new (char *title, char *text, GtkWindow *parent,
|
||||
GtkSignalFunc callback, gpointer callback_data);
|
||||
extern void progress_free (Progress_t *p);
|
||||
extern void progress_update (Progress_t *p, gfloat newval);
|
||||
|
||||
#endif /* progress_h */
|
||||
|
|
343
src/scanadf.c
343
src/scanadf.c
|
@ -4,6 +4,7 @@
|
|||
scanimage by Andreas Beck and David Mosberger
|
||||
|
||||
Copyright (C) 1999 Tom Martone
|
||||
Copyright (C) 2005 Rene Rebe ([ -p | --pipe] script option)
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
|
@ -49,23 +50,49 @@
|
|||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
#ifndef sane_isbasicframe
|
||||
#define SANE_FRAME_TEXT 10
|
||||
#define SANE_FRAME_JPEG 11
|
||||
#define SANE_FRAME_G31D 12
|
||||
#define SANE_FRAME_G32D 13
|
||||
#define SANE_FRAME_G42D 14
|
||||
#define sane_strframe(f) ( (f) == SANE_FRAME_GRAY ? "gray" : \
|
||||
(f) == SANE_FRAME_RGB ? "RGB" : \
|
||||
(f) == SANE_FRAME_RED ? "red" : \
|
||||
(f) == SANE_FRAME_GREEN ? "green" : \
|
||||
(f) == SANE_FRAME_BLUE ? "blue" : \
|
||||
(f) == SANE_FRAME_TEXT ? "text" : \
|
||||
(f) == SANE_FRAME_JPEG ? "jpeg" : \
|
||||
(f) == SANE_FRAME_G31D ? "g31d" : \
|
||||
(f) == SANE_FRAME_G32D ? "g32d" : \
|
||||
(f) == SANE_FRAME_G42D ? "g42d" : \
|
||||
"unknown" )
|
||||
const char*
|
||||
sane_strframe (SANE_Frame f)
|
||||
{
|
||||
switch (f)
|
||||
{
|
||||
case SANE_FRAME_GRAY:
|
||||
return "gray";
|
||||
|
||||
case SANE_FRAME_RGB:
|
||||
return "RBG";
|
||||
|
||||
case SANE_FRAME_RED:
|
||||
return "red";
|
||||
|
||||
case SANE_FRAME_GREEN:
|
||||
return "green";
|
||||
|
||||
case SANE_FRAME_BLUE:
|
||||
return "blue";
|
||||
|
||||
#if 0 // Not currently support by SANE
|
||||
|
||||
case SANE_FRAME_TEXT:
|
||||
return "text";
|
||||
|
||||
case SANE_FRAME_JPEG:
|
||||
return "jpeg";
|
||||
|
||||
case SANE_FRAME_G31D:
|
||||
return "g31d";
|
||||
|
||||
case SANE_FRAME_G32D:
|
||||
return "g32d";
|
||||
|
||||
case SANE_FRAME_G42D:
|
||||
return "g42d";
|
||||
#endif
|
||||
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define sane_isbasicframe(f) ( (f) == SANE_FRAME_GRAY || \
|
||||
(f) == SANE_FRAME_RGB || \
|
||||
|
@ -73,7 +100,6 @@
|
|||
(f) == SANE_FRAME_GREEN || \
|
||||
(f) == SANE_FRAME_BLUE )
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ATEXIT
|
||||
# define atexit(func) on_exit(func, 0) /* works for SunOS, at least */
|
||||
|
@ -105,10 +131,11 @@ static struct option basic_options[] =
|
|||
{ "scan-script", required_argument, 0, 'S' },
|
||||
{ "script-wait", no_argument, 0, 128 },
|
||||
{ "raw", no_argument, 0, 'r' },
|
||||
{ "pipe", no_argument, 0, 'p' },
|
||||
{0, }
|
||||
};
|
||||
|
||||
#define BASE_OPTSTRING "d:hLvVNTo:s:e:S:r"
|
||||
#define BASE_OPTSTRING "d:hLvVNTo:s:e:S:pr"
|
||||
#define STRIP_HEIGHT 256 /* # lines we increment image height */
|
||||
|
||||
static struct option * all_options;
|
||||
|
@ -124,6 +151,8 @@ static int resolution_opt = -1, x_resolution_opt = -1, y_resolution_opt = -1;
|
|||
static SANE_Word window_val[2];
|
||||
static int window_val_user[2]; /* is width/height user-specified? */
|
||||
|
||||
static void scanadf_exit (int);
|
||||
|
||||
static const char usage[] = "Usage: %s [OPTION]...\n\
|
||||
\n\
|
||||
Start image acquisition on a scanner device and write image data to\n\
|
||||
|
@ -379,7 +408,7 @@ parse_scalar (const SANE_Option_Descriptor * opt, const char * str,
|
|||
fprintf (stderr,
|
||||
"%s: option --%s: bad option value (rest of option: %s)\n",
|
||||
prog_name, opt->name, str);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
str = end;
|
||||
|
||||
|
@ -480,7 +509,7 @@ parse_vector (const SANE_Option_Descriptor * opt, const char * str,
|
|||
{
|
||||
fprintf (stderr, "%s: option --%s: closing bracket missing "
|
||||
"(rest of option: %s)\n", prog_name, opt->name, str);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
str = end + 1;
|
||||
}
|
||||
|
@ -491,20 +520,20 @@ parse_vector (const SANE_Option_Descriptor * opt, const char * str,
|
|||
{
|
||||
fprintf (stderr, "%s: option --%s: index %d out of range [0..%ld]\n",
|
||||
prog_name, opt->name, index, (long) vector_length - 1);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
/* read value */
|
||||
str = parse_scalar (opt, str, &value);
|
||||
if (!str)
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
|
||||
if (*str && *str != '-' && *str != ',')
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: option --%s: illegal separator (rest of option: %s)\n",
|
||||
prog_name, opt->name, str);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
/* store value: */
|
||||
|
@ -550,15 +579,33 @@ fetch_options (SANE_Device * device)
|
|||
const SANE_Option_Descriptor * opt;
|
||||
SANE_Int num_dev_options;
|
||||
int i, option_count;
|
||||
SANE_Status status;
|
||||
|
||||
/* and now build the full table of long options: */
|
||||
|
||||
sane_control_option (device, 0, SANE_ACTION_GET_VALUE, &num_dev_options, 0);
|
||||
opt = sane_get_option_descriptor (device, 0);
|
||||
if (opt == NULL)
|
||||
{
|
||||
fprintf (stderr, "Could not get option descriptor for option 0\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
status = sane_control_option (device, 0, SANE_ACTION_GET_VALUE, &num_dev_options, 0);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
fprintf (stderr, "Could not get value for option 0: %s\n", sane_strstatus (status));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
option_count = 0;
|
||||
for (i = 0; i < num_dev_options; ++i)
|
||||
for (i = 1; i < num_dev_options; ++i)
|
||||
{
|
||||
opt = sane_get_option_descriptor (device, i);
|
||||
if (opt == NULL)
|
||||
{
|
||||
fprintf (stderr, "Could not get option descriptor for option %d\n", i);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!SANE_OPTION_IS_SETTABLE (opt->cap))
|
||||
continue;
|
||||
|
@ -652,6 +699,28 @@ fetch_options (SANE_Device * device)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
scanadf_exit (int status)
|
||||
{
|
||||
if (device)
|
||||
{
|
||||
if (verbose > 1)
|
||||
fprintf (stderr, "Closing device\n");
|
||||
sane_close (device);
|
||||
}
|
||||
if (verbose > 1)
|
||||
fprintf (stderr, "Calling sane_exit\n");
|
||||
sane_exit ();
|
||||
|
||||
if (all_options)
|
||||
free (all_options);
|
||||
if (option_number)
|
||||
free (option_number);
|
||||
if (verbose > 1)
|
||||
fprintf (stderr, "scanimage: finished\n");
|
||||
exit (status);
|
||||
}
|
||||
|
||||
static void
|
||||
set_option (SANE_Handle device, int optnum, void * valuep)
|
||||
{
|
||||
|
@ -671,7 +740,7 @@ set_option (SANE_Handle device, int optnum, void * valuep)
|
|||
{
|
||||
fprintf (stderr, "%s: setting of option --%s failed (%s)\n",
|
||||
prog_name, opt->name, sane_strstatus (status));
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
if ((info & SANE_INFO_INEXACT) && opt->size == sizeof (SANE_Word))
|
||||
|
@ -706,7 +775,7 @@ process_backend_option (SANE_Handle device, int optnum, const char * optarg)
|
|||
{
|
||||
fprintf (stderr, "%s: attempted to set inactive option %s\n",
|
||||
prog_name, opt->name);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
if ((opt->cap & SANE_CAP_AUTOMATIC) && strncasecmp (optarg, "auto", 4) == 0)
|
||||
|
@ -717,7 +786,7 @@ process_backend_option (SANE_Handle device, int optnum, const char * optarg)
|
|||
{
|
||||
fprintf (stderr, "%s: failed to set option --%s to automatic (%s)\n",
|
||||
prog_name, opt->name, sane_strstatus (status));
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -737,7 +806,7 @@ process_backend_option (SANE_Handle device, int optnum, const char * optarg)
|
|||
{
|
||||
fprintf (stderr, "%s: option --%s: bad option value `%s'\n",
|
||||
prog_name, opt->name, optarg);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -753,7 +822,7 @@ process_backend_option (SANE_Handle device, int optnum, const char * optarg)
|
|||
if (!vector)
|
||||
{
|
||||
fprintf (stderr, "%s: out of memory\n", prog_name);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
}
|
||||
parse_vector (opt, optarg, vector, vector_length);
|
||||
|
@ -875,8 +944,95 @@ get_resolution(SANE_Device *device)
|
|||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
exec_script (const char *script, const char* fname, SANE_Bool use_pipe,
|
||||
SANE_Parameters *parm, int *fd)
|
||||
{
|
||||
static char cmd[PATH_MAX * 2];
|
||||
static char env[7][PATH_MAX * 2];
|
||||
int pid;
|
||||
SANE_Int res;
|
||||
SANE_Frame format;
|
||||
extern char **environ;
|
||||
int pipefd[2];
|
||||
|
||||
res = get_resolution(device);
|
||||
|
||||
format = parm->format;
|
||||
if (format == SANE_FRAME_RED ||
|
||||
format == SANE_FRAME_GREEN ||
|
||||
format == SANE_FRAME_BLUE)
|
||||
{
|
||||
/* the resultant format is RGB */
|
||||
format = SANE_FRAME_RGB;
|
||||
}
|
||||
|
||||
snprintf (env[0], sizeof(env[0]), "SCAN_RES=%d", res);
|
||||
if (putenv (env[0]))
|
||||
fprintf (stderr, "putenv:failed\n");
|
||||
|
||||
snprintf (env[1], sizeof(env[1]), "SCAN_WIDTH=%d", parm->pixels_per_line);
|
||||
if (putenv (env[1]))
|
||||
fprintf (stderr, "putenv:failed\n");
|
||||
|
||||
snprintf (env[2], sizeof(env[2]), "SCAN_HEIGHT=%d", parm->lines);
|
||||
if (putenv (env[2]))
|
||||
fprintf (stderr, "putenv:failed\n");
|
||||
|
||||
snprintf (env[3], sizeof(env[3]), "SCAN_FORMAT_ID=%d", (int) parm->format);
|
||||
if (putenv (env[3]))
|
||||
fprintf (stderr, "putenv:failed\n");
|
||||
|
||||
snprintf (env[4], sizeof(env[4]), "SCAN_FORMAT=%s",
|
||||
sane_strframe (parm->format));
|
||||
if (putenv (env[4]))
|
||||
fprintf (stderr, "putenv:failed\n");
|
||||
|
||||
snprintf (env[5], sizeof(env[5]), "SCAN_DEPTH=%d", parm->depth);
|
||||
if (putenv (env[5]))
|
||||
fprintf (stderr, "putenv:failed\n");
|
||||
|
||||
snprintf (env[6], sizeof(env[6]), "SCAN_PIPE=%d", use_pipe);
|
||||
if (putenv (env[6]))
|
||||
fprintf (stderr, "putenv:failed\n");
|
||||
|
||||
if (use_pipe) {
|
||||
|
||||
pipe(pipefd);
|
||||
}
|
||||
|
||||
/*signal(SIGCHLD, SIG_IGN);*/
|
||||
switch ((pid = fork()))
|
||||
{
|
||||
case -1:
|
||||
/* fork failed */
|
||||
fprintf(stderr, "Error forking: %s (%d)\n", strerror(errno), errno);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
/* in child process */
|
||||
if (use_pipe) {
|
||||
dup2(pipefd[0],0); close(pipefd[0]); close(pipefd[1]);
|
||||
}
|
||||
sprintf(cmd, "%s '%s'", script, fname);
|
||||
execle(script, script, fname, NULL, environ);
|
||||
exit(0);
|
||||
|
||||
default:
|
||||
if (verbose)
|
||||
fprintf(stderr, "Started script `%s' as pid=%d\n", script, pid);
|
||||
break;
|
||||
}
|
||||
if (use_pipe) {
|
||||
close(pipefd[0]);
|
||||
*fd = pipefd[1];
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
static SANE_Status
|
||||
scan_it_raw (const char *fname, SANE_Bool raw, const char *script)
|
||||
scan_it_raw (const char *fname, SANE_Bool raw, const char *script,
|
||||
SANE_Bool use_pipe)
|
||||
{
|
||||
int i, len, first_frame = 1, offset = 0, must_buffer = 0;
|
||||
SANE_Byte buffer[32*1024], min = 0xff, max = 0;
|
||||
|
@ -884,10 +1040,18 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script)
|
|||
SANE_Status status;
|
||||
Image image = {0, };
|
||||
FILE *fp = NULL;
|
||||
int pid = 0;
|
||||
|
||||
do
|
||||
{
|
||||
#ifdef SANE_STATUS_WARMING_UP
|
||||
do
|
||||
{
|
||||
status = sane_start (device);
|
||||
} while (status == SANE_STATUS_WARMING_UP);
|
||||
#else
|
||||
status = sane_start (device);
|
||||
#endif
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
if (status != SANE_STATUS_NO_DOCS)
|
||||
|
@ -906,7 +1070,15 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
fp = fopen(fname, "wb");
|
||||
if (script && use_pipe)
|
||||
{
|
||||
int fd = 0;
|
||||
pid = exec_script(script, fname, use_pipe, &parm, &fd);
|
||||
fp = fdopen (fd, "wb");
|
||||
}
|
||||
else
|
||||
fp = fopen(fname, "wb");
|
||||
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Error opening output `%s': %s (%d)\n",
|
||||
fname, strerror(errno), errno);
|
||||
|
@ -984,6 +1156,7 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script)
|
|||
}
|
||||
break;
|
||||
|
||||
#if 0 // Not currently supported by SANE
|
||||
case SANE_FRAME_TEXT:
|
||||
case SANE_FRAME_JPEG:
|
||||
case SANE_FRAME_G31D:
|
||||
|
@ -998,6 +1171,7 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script)
|
|||
}
|
||||
/* write them out without a header; don't buffer */
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
/* Default action for unknown frametypes; write them out
|
||||
|
@ -1147,65 +1321,16 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script)
|
|||
fp = NULL;
|
||||
}
|
||||
|
||||
if (script)
|
||||
{
|
||||
static char cmd[PATH_MAX * 2];
|
||||
static char env[6][PATH_MAX * 2];
|
||||
int pid;
|
||||
SANE_Int res;
|
||||
SANE_Frame format;
|
||||
extern char **environ;
|
||||
if (script && !use_pipe)
|
||||
pid = exec_script (script, fname, use_pipe, &parm, NULL);
|
||||
|
||||
res = get_resolution(device);
|
||||
|
||||
format = parm.format;
|
||||
if (format == SANE_FRAME_RED ||
|
||||
format == SANE_FRAME_GREEN ||
|
||||
format == SANE_FRAME_BLUE)
|
||||
{
|
||||
/* the resultant format is RGB */
|
||||
format = SANE_FRAME_RGB;
|
||||
}
|
||||
sprintf(env[0], "SCAN_RES=%d", res);
|
||||
if (putenv(env[0]))
|
||||
fprintf(stderr, "putenv:failed\n");
|
||||
sprintf(env[1], "SCAN_WIDTH=%d", parm.pixels_per_line);
|
||||
if (putenv(env[1]))
|
||||
fprintf(stderr, "putenv:failed\n");
|
||||
sprintf(env[2], "SCAN_HEIGHT=%d", parm.lines);
|
||||
if (putenv(env[2]))
|
||||
fprintf(stderr, "putenv:failed\n");
|
||||
sprintf(env[3], "SCAN_FORMAT_ID=%d", (int) parm.format);
|
||||
if (putenv(env[3]))
|
||||
fprintf(stderr, "putenv:failed\n");
|
||||
sprintf(env[4], "SCAN_FORMAT=%s",
|
||||
sane_strframe(parm.format));
|
||||
if (putenv(env[4]))
|
||||
fprintf(stderr, "putenv:failed\n");
|
||||
sprintf(env[5], "SCAN_DEPTH=%d", parm.depth);
|
||||
if (putenv(env[5]))
|
||||
fprintf(stderr, "putenv:failed\n");
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
switch ((pid = fork()))
|
||||
{
|
||||
case -1:
|
||||
/* fork failed */
|
||||
fprintf(stderr, "Error forking: %s (%d)\n", strerror(errno), errno);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
/* in child process */
|
||||
sprintf(cmd, "%s '%s'", script, fname);
|
||||
/* system(cmd); */
|
||||
execle(script, script, fname, NULL, environ);
|
||||
exit(0);
|
||||
|
||||
default:
|
||||
if (verbose)
|
||||
fprintf(stderr, "Started script `%s' as pid=%d\n", script, pid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (script) {
|
||||
int exit_status = 0;
|
||||
waitpid (pid, &exit_status, 0);
|
||||
if (exit_status && verbose)
|
||||
fprintf(stderr, "%s: WARNING: child exited with %d\n",
|
||||
prog_name, exit_status);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (image.data)
|
||||
|
@ -1216,7 +1341,8 @@ cleanup:
|
|||
}
|
||||
|
||||
static SANE_Int
|
||||
scan_docs (int start, int end, int no_overwrite, SANE_Bool raw, const char *outfmt, const char *script)
|
||||
scan_docs (int start, int end, int no_overwrite, SANE_Bool raw,
|
||||
const char *outfmt, const char *script, SANE_Bool use_pipe)
|
||||
{
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
SANE_Int scannedPages = 0;
|
||||
|
@ -1226,8 +1352,7 @@ scan_docs (int start, int end, int no_overwrite, SANE_Bool raw, const char *outf
|
|||
|
||||
while (end < 0 || start <= end)
|
||||
{
|
||||
/*!!! buffer overflow; need protection */
|
||||
sprintf(fname, outfmt, start);
|
||||
snprintf(fname, sizeof (fname), outfmt, start);
|
||||
|
||||
/* does the filename already exist? */
|
||||
if (no_overwrite)
|
||||
|
@ -1242,7 +1367,7 @@ scan_docs (int start, int end, int no_overwrite, SANE_Bool raw, const char *outf
|
|||
|
||||
/* Scan the document */
|
||||
if (status == SANE_STATUS_GOOD)
|
||||
status = scan_it_raw(fname, raw, script);
|
||||
status = scan_it_raw(fname, raw, script, use_pipe);
|
||||
|
||||
/* Any scan errors? */
|
||||
if (status == SANE_STATUS_NO_DOCS)
|
||||
|
@ -1283,6 +1408,7 @@ main (int argc, char **argv)
|
|||
SANE_Status status;
|
||||
char *full_optstring;
|
||||
SANE_Bool raw = SANE_FALSE;
|
||||
SANE_Bool use_pipe = SANE_FALSE;
|
||||
const char *scanScript = NULL; /* script to run at end of scan */
|
||||
int scriptWait = 0;
|
||||
const char *outputFile = "image-%04d"; /* file name(format) to write output to */
|
||||
|
@ -1325,7 +1451,7 @@ main (int argc, char **argv)
|
|||
{
|
||||
fprintf (stderr, "%s: sane_get_devices() failed: %s\n",
|
||||
prog_name, sane_strstatus (status));
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
for (i = 0; device_list[i]; ++i)
|
||||
|
@ -1334,7 +1460,7 @@ main (int argc, char **argv)
|
|||
device_list[i]->name, device_list[i]->vendor,
|
||||
device_list[i]->model, device_list[i]->type);
|
||||
}
|
||||
exit (0);
|
||||
scanadf_exit (0);
|
||||
}
|
||||
|
||||
case 'o': outputFile = optarg; break;
|
||||
|
@ -1343,6 +1469,7 @@ main (int argc, char **argv)
|
|||
case 's': startNum = atoi(optarg); break;
|
||||
case 'e': endNum = atoi(optarg); break;
|
||||
case 'r': raw = SANE_TRUE; break;
|
||||
case 'p': use_pipe = SANE_TRUE; break;
|
||||
|
||||
case 'V':
|
||||
printf ("scanadf (%s) %s\n", PACKAGE, VERSION);
|
||||
|
@ -1369,12 +1496,12 @@ main (int argc, char **argv)
|
|||
{
|
||||
fprintf (stderr, "%s: sane_get_devices() failed: %s\n",
|
||||
prog_name, sane_strstatus (status));
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
if (!device_list[0])
|
||||
{
|
||||
fprintf (stderr, "%s: no SANE devices found\n", prog_name);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
devname = device_list[0]->name;
|
||||
}
|
||||
|
@ -1387,7 +1514,7 @@ main (int argc, char **argv)
|
|||
if (help)
|
||||
device = 0;
|
||||
else
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
if (device)
|
||||
|
@ -1399,7 +1526,7 @@ main (int argc, char **argv)
|
|||
{
|
||||
fprintf (stderr, "%s: unable to determine option count\n",
|
||||
prog_name);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
all_options_len = num_dev_options + NELEMS(basic_options) + 1;
|
||||
|
@ -1410,7 +1537,7 @@ main (int argc, char **argv)
|
|||
{
|
||||
fprintf (stderr, "%s: out of memory in fetch_options()\n",
|
||||
prog_name);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
fetch_options (device);
|
||||
|
@ -1440,7 +1567,7 @@ main (int argc, char **argv)
|
|||
if (!full_optstring)
|
||||
{
|
||||
fprintf (stderr, "%s: out of memory\n", prog_name);
|
||||
exit (1);
|
||||
scanadf_exit (1);
|
||||
}
|
||||
|
||||
strcpy (full_optstring, BASE_OPTSTRING);
|
||||
|
@ -1460,10 +1587,10 @@ main (int argc, char **argv)
|
|||
{
|
||||
case ':':
|
||||
case '?':
|
||||
exit (1); /* error message is printed by getopt_long() */
|
||||
scanadf_exit (1); /* error message is printed by getopt_long() */
|
||||
|
||||
case 'd': case 'h': case 'v': case 'V': case 'T':
|
||||
case 'o': case 'S': case 's': case 'e': case 'r':
|
||||
case 'o': case 'S': case 's': case 'e': case 'p': case 'r':
|
||||
|
||||
/* previously handled options */
|
||||
break;
|
||||
|
@ -1569,7 +1696,7 @@ List of available devices:", prog_name);
|
|||
}
|
||||
}
|
||||
fputc ('\n', stdout);
|
||||
exit (0);
|
||||
scanadf_exit (0);
|
||||
}
|
||||
|
||||
signal (SIGHUP, sighandler);
|
||||
|
@ -1577,10 +1704,12 @@ List of available devices:", prog_name);
|
|||
signal (SIGPIPE, sighandler);
|
||||
signal (SIGTERM, sighandler);
|
||||
|
||||
status = scan_docs (startNum, endNum, no_overwrite, raw, outputFile, scanScript);
|
||||
status = scan_docs (startNum, endNum, no_overwrite, raw,
|
||||
outputFile, scanScript, use_pipe);
|
||||
|
||||
sane_cancel (device);
|
||||
sane_close (device);
|
||||
sane_exit();
|
||||
|
||||
if (scriptWait)
|
||||
while (wait(NULL) != -1);
|
||||
|
|
106
src/xcam.c
106
src/xcam.c
|
@ -6,6 +6,8 @@
|
|||
The add_text routine and font_6x11.h file are taken from the (GPLed)
|
||||
webcam.c file, part of xawtv, (c) 1998-2002 Gerd Knorr.
|
||||
add_text was modified for this program (xcam_add_text).
|
||||
Update 2008 Gerard Klaver
|
||||
Added add_text routine to gray images.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
|
@ -339,6 +341,8 @@ xcam_add_text (SANE_Byte * image, int width, int height, char *txt)
|
|||
int i, x, y, f, len;
|
||||
char fmtstring[25] = " %Y-%m-%d %H:%M:%S";
|
||||
char fmttxt[46];
|
||||
char buf[100];
|
||||
|
||||
|
||||
DBG (DBG_debug, "xcam_add_text: enter\n");
|
||||
time (&t);
|
||||
|
@ -351,28 +355,64 @@ xcam_add_text (SANE_Byte * image, int width, int height, char *txt)
|
|||
|
||||
len = strftime (line, MSG_MAXLEN, fmttxt, tm);
|
||||
|
||||
for (y = 0; y < CHAR_HEIGHT; y++)
|
||||
switch (win.params.format)
|
||||
{
|
||||
ptr = image + 3 * width * (height - CHAR_HEIGHT - 2 + y) + 12;
|
||||
case SANE_FRAME_RGB:
|
||||
|
||||
for (x = 0; x < len; x++)
|
||||
for (y = 0; y < CHAR_HEIGHT; y++)
|
||||
{
|
||||
f = fontdata[line[x] * CHAR_HEIGHT + y];
|
||||
for (i = CHAR_WIDTH - 1; i >= 0; i--)
|
||||
{
|
||||
if (f & (CHAR_START << i))
|
||||
{
|
||||
ptr[0] = 255;
|
||||
ptr[1] = 255;
|
||||
ptr[2] = 255;
|
||||
}
|
||||
ptr += 3;
|
||||
} /* for i */
|
||||
} /* for x */
|
||||
} /* for y */
|
||||
ptr = image + 3 * width * (height - CHAR_HEIGHT - 2 + y) + 12;
|
||||
|
||||
for (x = 0; x < len; x++)
|
||||
{
|
||||
f = fontdata[line[x] * CHAR_HEIGHT + y];
|
||||
for (i = CHAR_WIDTH - 1; i >= 0; i--)
|
||||
{
|
||||
if (f & (CHAR_START << i))
|
||||
{
|
||||
ptr[0] = 255;
|
||||
ptr[1] = 255;
|
||||
ptr[2] = 255;
|
||||
}
|
||||
ptr += 3;
|
||||
} /* for i */
|
||||
} /* for x */
|
||||
} /* for y */
|
||||
break;
|
||||
case SANE_FRAME_GRAY:
|
||||
|
||||
for (y = 0; y < CHAR_HEIGHT; y++)
|
||||
{
|
||||
ptr = image + width * (height - CHAR_HEIGHT - 2 + y) + 12;
|
||||
|
||||
for (x = 0; x < len; x++)
|
||||
{
|
||||
f = fontdata[line[x] * CHAR_HEIGHT + y];
|
||||
for (i = CHAR_WIDTH - 1; i >= 0; i--)
|
||||
{
|
||||
if (f & (CHAR_START << i))
|
||||
{
|
||||
ptr[0] = 255;
|
||||
}
|
||||
ptr += 1;
|
||||
} /* for i */
|
||||
} /* for x */
|
||||
} /* for y */
|
||||
case SANE_FRAME_RED:
|
||||
case SANE_FRAME_GREEN:
|
||||
case SANE_FRAME_BLUE:
|
||||
snprintf (buf, sizeof (buf),
|
||||
"Time stamp for separate channel transfers are not supported");
|
||||
break;
|
||||
default:
|
||||
snprintf (buf, sizeof (buf),
|
||||
"Unsupported image format %d", win.params.format);
|
||||
DBG (DBG_error, "xcam_add_text: unsupported image format %d\n",
|
||||
win.params.format);
|
||||
status = SANE_STATUS_INVAL;
|
||||
}
|
||||
DBG (DBG_debug, "xcam_add_text: exit vw=%d, vh=%d\n", width, height);
|
||||
status = (SANE_STATUS_GOOD);
|
||||
status = SANE_STATUS_GOOD;
|
||||
return status;
|
||||
|
||||
}
|
||||
|
@ -536,16 +576,14 @@ static void
|
|||
load_defaults (int silent)
|
||||
{
|
||||
char filename[PATH_MAX];
|
||||
int fd;
|
||||
|
||||
DBG (DBG_debug, "xcam, load_defaults: enter\n");
|
||||
if (make_default_filename (sizeof (filename), filename, dialog->dev_name)
|
||||
< 0)
|
||||
return;
|
||||
if (fd < 0)
|
||||
return;
|
||||
|
||||
load_settings (filename, silent);
|
||||
sanei_load_values (fd, dialog->dev);
|
||||
|
||||
DBG (DBG_debug, "xcam, load_defaults: exit\n");
|
||||
}
|
||||
|
||||
|
@ -574,7 +612,7 @@ prompt_for_device_name (GtkWidget * widget, gpointer data)
|
|||
{
|
||||
GtkWidget *vbox, *hbox, *label, *text;
|
||||
GtkWidget *button, *dialog;
|
||||
|
||||
|
||||
DBG (DBG_debug, "xcam: prompt_for_device_name: enter\n");
|
||||
|
||||
dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
@ -702,7 +740,7 @@ static GtkWidget *
|
|||
build_files_menu (void)
|
||||
{
|
||||
GtkWidget *menu, *item;
|
||||
|
||||
|
||||
DBG (DBG_debug, "xcam: build_files_menu: enter\n");
|
||||
|
||||
menu = gtk_menu_new ();
|
||||
|
@ -1109,7 +1147,7 @@ input_available (gpointer ignore, gint source, GdkInputCondition cond)
|
|||
(win.fps_old3 + win.fps_old2 + win.fps_old1 + win.fps) / 4;
|
||||
|
||||
DBG (DBG_debug,
|
||||
"xcam: input_available fps count=%d, frame_time * 30 = %2.3f, fps=%2.3f, fps_av=%2.3f\n",
|
||||
"xcam: input_available fps count=%ld, frame_time * 30 = %2.3f, fps=%2.3f, fps_av=%2.3f\n",
|
||||
win.f_count, frame_time, win.fps, win.fps_av);
|
||||
win.i_time = 0;
|
||||
|
||||
|
@ -1183,7 +1221,15 @@ next_frame (void)
|
|||
DBG (DBG_debug, "xcam: next frame, start gsg_sync\n");
|
||||
gsg_sync (dialog);
|
||||
|
||||
#ifdef SANE_STATUS_WARMING_UP
|
||||
do
|
||||
{
|
||||
status = sane_start (gsg_dialog_get_device (dialog));
|
||||
}
|
||||
while (status == SANE_STATUS_WARMING_UP);
|
||||
#else
|
||||
status = sane_start (gsg_dialog_get_device (dialog));
|
||||
#endif
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
sprintf (buf, "Failed to start webcam: %s.", sane_strstatus (status));
|
||||
|
@ -1289,7 +1335,7 @@ save_frame_button (GtkWidget * widget, gpointer client_data,
|
|||
|
||||
/* test for pnm formats */
|
||||
strncpy (testfilename, preferences.filename, sizeof (testfilename));
|
||||
testfilename[sizeof (testfilename)] = 0;
|
||||
testfilename[sizeof (testfilename) - 1] = 0;
|
||||
g_strreverse (testfilename);
|
||||
if (!((!strncmp (testfilename, "mnp.", 4)) ||
|
||||
(!strncmp (testfilename, "mgp.", 4)) ||
|
||||
|
@ -1405,6 +1451,8 @@ save_frame (void)
|
|||
case SANE_FRAME_GRAY:
|
||||
frame_type = "gray";
|
||||
break;
|
||||
default:
|
||||
frame_type = "RGB";
|
||||
}
|
||||
|
||||
if (!win.header_size)
|
||||
|
@ -1440,6 +1488,11 @@ save_frame (void)
|
|||
win.params.pixels_per_line, win.params.lines,
|
||||
(win.params.depth <= 8) ? 255 : 65535);
|
||||
break;
|
||||
default:
|
||||
snprintf (buf, sizeof (buf),
|
||||
"Unsupported image format %d", win.params.format);
|
||||
DBG (DBG_error, "xcam_add_text: unsupported image format %d\n",
|
||||
win.params.format);
|
||||
}
|
||||
win.header_size = ftell (win.out);
|
||||
fwrite (win.buf, 1, win.num_bytes, win.out);
|
||||
|
@ -1599,7 +1652,8 @@ main (int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
DBG (DBG_debug, "xcam.main: buf_backend_size 0x%x\n", win.buf_backend_size);
|
||||
DBG (DBG_debug, "xcam.main: buf_backend_size 0x%x\n",
|
||||
(unsigned) win.buf_backend_size);
|
||||
|
||||
win.buf = malloc (win.buf_backend_size);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
Andreas Beck <becka@sunserver1.rz.uni-duesseldorf.de>
|
||||
Tristan Tarrant <ttarrant@etnoteam.it>
|
||||
David Mosberger-Tang <davidm@azstarnet.com>
|
||||
Rene Rebe <rene@exactcode.de>
|
||||
|
||||
Copyright (C) 1997, 1998 Andreas Beck, Tristan Tarrant, and David
|
||||
Mosberger
|
||||
|
@ -48,9 +49,9 @@
|
|||
#define BACKEND_NAME xscanimage
|
||||
#include "../include/sane/sanei_debug.h"
|
||||
|
||||
#include <progress.h>
|
||||
#include <preferences.h>
|
||||
#include <preview.h>
|
||||
#include "progress.h"
|
||||
#include "preferences.h"
|
||||
#include "preview.h"
|
||||
|
||||
#ifndef PATH_MAX
|
||||
# define PATH_MAX 1024
|
||||
|
@ -1025,11 +1026,11 @@ scan_done (void)
|
|||
}
|
||||
|
||||
static void
|
||||
progress_cancel (void)
|
||||
cancel_action (void)
|
||||
{
|
||||
DBG (DBG_debug, "progress_cancel\n");
|
||||
DBG (DBG_debug, "cancel_action\n");
|
||||
sane_cancel (gsg_dialog_get_device (dialog));
|
||||
DBG (DBG_debug, "progress_cancel: done\n");
|
||||
DBG (DBG_debug, "cancel_action: done\n");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1042,6 +1043,10 @@ scan_start (void)
|
|||
SANE_Word resolution;
|
||||
#endif /* HAVE_LIBGIMP_GIMP_H */
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
struct timeval start, current;
|
||||
#endif
|
||||
|
||||
const char *frame_type = 0;
|
||||
char buf[256];
|
||||
int fd;
|
||||
|
@ -1088,10 +1093,38 @@ scan_start (void)
|
|||
|
||||
while (gtk_events_pending ())
|
||||
gtk_main_iteration ();
|
||||
|
||||
status = sane_start (dev);
|
||||
#ifdef SANE_STATUS_WARMING_UP
|
||||
if (status == SANE_STATUS_WARMING_UP)
|
||||
{
|
||||
if (scan_win.progress)
|
||||
progress_free (scan_win.progress);
|
||||
snprintf (buf, sizeof (buf), "Scanner is warming up.");
|
||||
scan_win.progress = progress_new ("Warming up ...", buf, scan_win.shell,
|
||||
(GtkSignalFunc) cancel_action, NULL);
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
gettimeofday(&start,NULL);
|
||||
#endif
|
||||
while (status == SANE_STATUS_WARMING_UP)
|
||||
{
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
gettimeofday(¤t,NULL);
|
||||
/* we assume that warming up won't exceed 60 seconds */
|
||||
progress_update (scan_win.progress, (gfloat)(current.tv_sec - start.tv_sec) / (gfloat) 60);
|
||||
#endif
|
||||
while (gtk_events_pending ())
|
||||
gtk_main_iteration ();
|
||||
status = sane_start (dev);
|
||||
}
|
||||
progress_free (scan_win.progress);
|
||||
scan_win.progress = 0;
|
||||
}
|
||||
#endif /* SANE_STATUS_WARMING_UP */
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
gsg_set_sensitivity (dialog, TRUE);
|
||||
gtk_widget_set_sensitive (scan_win.scan_button, TRUE);
|
||||
snprintf (buf, sizeof (buf), "Failed to start scanner: %s",
|
||||
sane_strstatus (status));
|
||||
gsg_error (buf);
|
||||
|
@ -1112,6 +1145,7 @@ scan_start (void)
|
|||
if (scan_win.param.lines == -1)
|
||||
{
|
||||
gsg_set_sensitivity (dialog, TRUE);
|
||||
gtk_widget_set_sensitive (scan_win.scan_button, TRUE);
|
||||
snprintf (buf, sizeof (buf), "Hand-Scanner mode not supported");
|
||||
gsg_error (buf);
|
||||
scan_done ();
|
||||
|
@ -1153,6 +1187,7 @@ scan_start (void)
|
|||
if (scan_win.param.depth > 8)
|
||||
{
|
||||
gsg_set_sensitivity (dialog, TRUE);
|
||||
gtk_widget_set_sensitive (scan_win.scan_button, TRUE);
|
||||
snprintf (buf, sizeof (buf),
|
||||
"Separate channel transfers are not supported "
|
||||
"with %d bits/channel.", scan_win.param.depth);
|
||||
|
@ -1197,6 +1232,7 @@ scan_start (void)
|
|||
if (scan_win.param.depth > 8)
|
||||
{
|
||||
gsg_set_sensitivity (dialog, TRUE);
|
||||
gtk_widget_set_sensitive (scan_win.scan_button, TRUE);
|
||||
snprintf (buf, sizeof (buf), "The Gimp doesn't support images "
|
||||
"with %d bits/channel.", scan_win.param.depth);
|
||||
gsg_error (buf);
|
||||
|
@ -1254,8 +1290,8 @@ scan_start (void)
|
|||
#endif /* HAVE_LIBGIMP_GIMP_H */
|
||||
if (scan_win.progress)
|
||||
progress_free (scan_win.progress);
|
||||
scan_win.progress = progress_new ("Scanning", buf,
|
||||
(GtkSignalFunc) progress_cancel, 0);
|
||||
scan_win.progress = progress_new ("Scanning", buf, GTK_WINDOW(scan_win.shell),
|
||||
(GtkSignalFunc) cancel_action, 0);
|
||||
|
||||
scan_win.input_tag = -1;
|
||||
if (sane_set_io_mode (dev, SANE_TRUE) == SANE_STATUS_GOOD
|
||||
|
@ -1284,7 +1320,7 @@ scan_dialog (GtkWidget * widget, gpointer call_data)
|
|||
{ /* We are running in standalone mode */
|
||||
/* test for pnm formats */
|
||||
strncpy (testfilename, preferences.filename, sizeof (testfilename));
|
||||
testfilename[sizeof (testfilename)] = 0;
|
||||
testfilename[sizeof (testfilename) - 1] = 0;
|
||||
g_strreverse (testfilename);
|
||||
if (!((!strncmp (testfilename, "mnp.", 4)) ||
|
||||
(!strncmp (testfilename, "mgp.", 4)) ||
|
||||
|
@ -2203,8 +2239,10 @@ main (int argc, char **argv)
|
|||
old_print_func = g_set_print_handler (null_print_func);
|
||||
old_printerr_func = g_set_printerr_handler (null_print_func);
|
||||
/* gimp_main () returns 1 if xscanimage wasn't invoked by GIMP */
|
||||
# ifdef HAVE_OS2_H
|
||||
# ifdef ENABLE_GIMP_1_2
|
||||
# ifdef HAVE_OS2_H
|
||||
set_gimp_PLUG_IN_INFO (&PLUG_IN_INFO);
|
||||
# endif
|
||||
# endif
|
||||
# ifndef ENABLE_GIMP_1_2
|
||||
result = gimp_main (&PLUG_IN_INFO, argc, argv);
|
||||
|
|
Ładowanie…
Reference in New Issue