kopia lustrzana https://gitlab.com/sane-project/frontends
Added -N option to stop scanadf from overwriting files (patch from Paul Walmsley
<paul@booyaka.com>).33-incorporate-downstream-patches
rodzic
098602b407
commit
37309355cb
|
@ -1,3 +1,9 @@
|
|||
2004-07-09 Henning Meier-Geinitz <henning@meier-geinitz.de>
|
||||
|
||||
* doc/scanadf.man src/scanadf.c: Added -N option to stop scanadf
|
||||
from overwriting files (patch from Paul Walmsley
|
||||
<paul@booyaka.com>).
|
||||
|
||||
2004-05-12 Henning Meier-Geinitz <henning@meier-geinitz.de>
|
||||
|
||||
* acinclude.m4 aclocal.m4 configure sane-frontends.lsm: Removed
|
||||
|
|
|
@ -12,6 +12,7 @@ scanadf - acquire multiple images from a scanner equipped with an ADF
|
|||
.RB [ -V | --version ]
|
||||
.RB [ -o | --output-file
|
||||
.IR name ]
|
||||
.RB [ -N | --no-overwrite ]
|
||||
.RB [ -S | --scan-script
|
||||
.IR name ]
|
||||
.RB [ -s | --start-count
|
||||
|
@ -116,6 +117,15 @@ write the image data to. You can use %d replacement in the output file
|
|||
name; this will be replaced with the current page number. The default
|
||||
format string is image-%04d.
|
||||
|
||||
.PP
|
||||
The
|
||||
.B -N
|
||||
or
|
||||
.B --no-overwrite
|
||||
option prevents
|
||||
.B scanadf
|
||||
from overwriting existing image files.
|
||||
|
||||
.PP
|
||||
The
|
||||
.B -S
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sane/sane.h"
|
||||
#include "sane/sanei.h"
|
||||
|
@ -95,6 +96,7 @@ static struct option basic_options[] =
|
|||
{"help", no_argument, NULL, 'h'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{"version", no_argument, NULL, 'V'},
|
||||
{"no-overwrite", no_argument, NULL, 'N'},
|
||||
|
||||
{ "output-file", required_argument, 0, 'o' },
|
||||
{ "start-count", required_argument, 0, 's' },
|
||||
|
@ -104,7 +106,7 @@ static struct option basic_options[] =
|
|||
{0, }
|
||||
};
|
||||
|
||||
#define BASE_OPTSTRING "d:hLvVTo:s:e:S:r"
|
||||
#define BASE_OPTSTRING "d:hLvVNTo:s:e:S:r"
|
||||
#define STRIP_HEIGHT 256 /* # lines we increment image height */
|
||||
|
||||
static struct option * all_options;
|
||||
|
@ -130,6 +132,7 @@ output files.\n\
|
|||
[ -L | --list-devices ] show available scanner devices.\n\
|
||||
[ -v | --verbose ] give even more status messages.\n\
|
||||
[ -V | --version ] print version information.\n\
|
||||
[ -N | --no-overwrite ] don't overwrite existing files.\n\
|
||||
\n\
|
||||
[ -o | --output-file <name> ] name of file to write image data\n\
|
||||
(%%d replacement in output file name).\n\
|
||||
|
@ -1210,18 +1213,35 @@ cleanup:
|
|||
}
|
||||
|
||||
static SANE_Int
|
||||
scan_docs (int start, int end, 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_Status status = SANE_STATUS_GOOD;
|
||||
SANE_Int scannedPages = 0;
|
||||
SANE_Char fname[PATH_MAX];
|
||||
struct stat statbuf;
|
||||
int res;
|
||||
|
||||
while (end < 0 || start <= end)
|
||||
{
|
||||
/*!!! buffer overflow; need protection */
|
||||
sprintf(fname, outfmt, start);
|
||||
|
||||
status = scan_it_raw(fname, raw, script);
|
||||
/* does the filename already exist? */
|
||||
if (no_overwrite)
|
||||
{
|
||||
res = stat (fname, &statbuf);
|
||||
if (res == 0)
|
||||
{
|
||||
status = SANE_STATUS_INVAL;
|
||||
fprintf (stderr, "Filename %s already exists; will not overwrite\n", fname);
|
||||
}
|
||||
}
|
||||
|
||||
/* Scan the document */
|
||||
if (status == SANE_STATUS_GOOD)
|
||||
status = scan_it_raw(fname, raw, script);
|
||||
|
||||
/* Any scan errors? */
|
||||
if (status == SANE_STATUS_NO_DOCS)
|
||||
{
|
||||
/* out of paper in the hopper; this is our normal exit */
|
||||
|
@ -1263,6 +1283,7 @@ main (int argc, char **argv)
|
|||
const char *scanScript = NULL; /* script to run at end of scan */
|
||||
const char *outputFile = "image-%04d"; /* file name(format) to write output to */
|
||||
int startNum = 1, endNum = -1; /* start/end numbers of pages to scan */
|
||||
int no_overwrite = 0;
|
||||
|
||||
atexit (sane_exit);
|
||||
|
||||
|
@ -1289,6 +1310,7 @@ main (int argc, char **argv)
|
|||
|
||||
case 'd': devname = optarg; break;
|
||||
case 'h': help = 1; break;
|
||||
case 'N': no_overwrite = 1; break;
|
||||
case 'v': ++verbose; break;
|
||||
case 'L':
|
||||
{
|
||||
|
@ -1547,7 +1569,7 @@ List of available devices:", prog_name);
|
|||
signal (SIGPIPE, sighandler);
|
||||
signal (SIGTERM, sighandler);
|
||||
|
||||
status = scan_docs (startNum, endNum, raw, outputFile, scanScript);
|
||||
status = scan_docs (startNum, endNum, no_overwrite, raw, outputFile, scanScript);
|
||||
|
||||
sane_cancel (device);
|
||||
sane_close (device);
|
||||
|
|
Ładowanie…
Reference in New Issue