diff --git a/sanei/sanei_init_debug.c b/sanei/sanei_init_debug.c index 62fed63..ef1535f 100644 --- a/sanei/sanei_init_debug.c +++ b/sanei/sanei_init_debug.c @@ -97,10 +97,11 @@ 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) ) + struct stat statbuf; + if ((0 == fstat (fileno (stderr), &statbuf)) && S_ISSOCK(statbuf.st_mode)) { msg = (char *)malloc (sizeof(char) * (strlen(be) + strlen(fmt) + 4)); if (msg == NULL) @@ -120,7 +121,7 @@ sanei_debug_msg fprintf (stderr, "[%s] ", be); vfprintf (stderr, fmt, ap); } - + } } diff --git a/sanei/sanei_thread.c b/sanei/sanei_thread.c index 0c95fdb..f02be48 100644 --- a/sanei/sanei_thread.c +++ b/sanei/sanei_thread.c @@ -163,7 +163,7 @@ sanei_thread_begin( int (*func)(void *args), void* args ) DBG( 1, "_beginthread() failed\n" ); return -1; } - + DBG( 2, "_beginthread() created thread %d\n", pid ); return pid; } @@ -249,7 +249,7 @@ restore_sigpipe( void ) sigemptyset( &act.sa_mask ); act.sa_flags = 0; act.sa_handler = SIG_DFL; - + DBG( 2, "restoring SIGPIPE to SIG_DFL\n" ); sigaction( SIGPIPE, &act, NULL ); } @@ -327,7 +327,7 @@ sanei_thread_begin( int (func)(void *args), void* args ) /* run in child context... */ int status = func( args ); - + /* don't use exit() since that would run the atexit() handlers */ _exit( status ); } @@ -375,7 +375,7 @@ sanei_thread_waitpid( int pid, int *status ) DBG(2, "* result = %d (%p)\n", stat, (void*)status ); result = pid; } - /* call detach in any case to make sure that the thread resources + /* call detach in any case to make sure that the thread resources * will be freed, when the thread has terminated */ DBG(2, "* detaching thread(%d)\n", pid ); diff --git a/sanei/sanei_wire.c b/sanei/sanei_wire.c index 05b9f40..45b56d6 100644 --- a/sanei/sanei_wire.c +++ b/sanei/sanei_wire.c @@ -67,7 +67,7 @@ sanei_w_space (Wire * w, size_t howmuch) if (w->status != 0) { - DBG (1, "sanei_w_space: wire is in invalid state %d\n", + DBG (1, "sanei_w_space: wire is in invalid state %d\n", w->status); return; } @@ -81,7 +81,7 @@ sanei_w_space (Wire * w, size_t howmuch) case WIRE_ENCODE: nbytes = w->buffer.curr - w->buffer.start; w->buffer.curr = w->buffer.start; - DBG (4, "sanei_w_space: ENCODE: sending %lu bytes\n", + DBG (4, "sanei_w_space: ENCODE: sending %lu bytes\n", (u_long) nbytes); while (nbytes > 0) { @@ -184,7 +184,7 @@ sanei_w_array (Wire * w, SANE_Word * len_ptr, void **v, else DBG (1, "sanei_w_array: FREE: tried to free array but *len_ptr or *v " "was NULL\n"); - + DBG (4, "sanei_w_array: FREE: done\n"); return; } @@ -200,14 +200,14 @@ sanei_w_array (Wire * w, SANE_Word * len_ptr, void **v, return; } DBG (4, "sanei_w_array: array has %d elements\n", len); - + if (w->direction == WIRE_DECODE) { *len_ptr = len; if (len) { - if (((unsigned int) len) > MAX_MEM - || ((unsigned int) len * element_size) > MAX_MEM + if (((unsigned int) len) > MAX_MEM + || ((unsigned int) len * element_size) > MAX_MEM || (w->allocated_memory + len * element_size) > MAX_MEM) { DBG (0, "sanei_w_array: DECODE: maximum amount of allocated memory " @@ -579,8 +579,8 @@ flush (Wire * w) void sanei_w_set_dir (Wire * w, WireDirection dir) { - DBG (3, "sanei_w_set_dir: wire %d, old direction WIRE_%s\n", w->io.fd, - w->direction == WIRE_ENCODE ? "ENCODE" : + DBG (3, "sanei_w_set_dir: wire %d, old direction WIRE_%s\n", w->io.fd, + w->direction == WIRE_ENCODE ? "ENCODE" : (w->direction == WIRE_DECODE ? "DECODE" : "FREE")); if (w->direction == WIRE_DECODE && w->buffer.curr != w->buffer.end) DBG (1, "sanei_w_set_dir: WARNING: will delete %lu bytes from buffer\n", @@ -589,8 +589,8 @@ sanei_w_set_dir (Wire * w, WireDirection dir) w->direction = dir; DBG (4, "sanei_w_set_dir: direction changed\n"); flush (w); - DBG (3, "sanei_w_set_dir: wire %d, new direction WIRE_%s\n", w->io.fd, - dir == WIRE_ENCODE ? "ENCODE" : + DBG (3, "sanei_w_set_dir: wire %d, new direction WIRE_%s\n", w->io.fd, + dir == WIRE_ENCODE ? "ENCODE" : (dir == WIRE_DECODE ? "DECODE" : "FREE")); } @@ -654,13 +654,13 @@ void sanei_w_init (Wire * w, void (*codec_init_func) (Wire *)) { DBG_INIT (); - + DBG (3, "sanei_w_init: initializing\n"); w->status = 0; w->direction = WIRE_ENCODE; w->buffer.size = 8192; w->buffer.start = malloc (w->buffer.size); - + if (w->buffer.start == 0) { /* Malloc failed, so return an error. */ diff --git a/src/progress.c b/src/progress.c index b16ec4d..6117956 100644 --- a/src/progress.c +++ b/src/progress.c @@ -114,7 +114,7 @@ progress_update (Progress_t * p, gfloat newval) #ifdef HAVE_SYS_TIME_H struct timeval tv; int now; - char buff[40]; + char buff[100]; int remaining; #endif @@ -126,6 +126,8 @@ progress_update (Progress_t * p, gfloat newval) gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), newval); #ifdef HAVE_SYS_TIME_H + + fprintf(stderr, "Hello!!!!!!!\n"); gettimeofday (&tv, NULL); now = tv.tv_sec * 1000 + tv.tv_usec / 1000; @@ -138,6 +140,7 @@ progress_update (Progress_t * p, gfloat newval) if (newval > p->firstVal && now - p->lastTime > 1000) { + fprintf(stderr, "Hello2!!!!!!!\n"); remaining = (int) ((now - p->firstTime) * (1.0 - newval) / (newval - p->firstVal) / diff --git a/src/scanadf.c b/src/scanadf.c index 2a13cef..d72d478 100644 --- a/src/scanadf.c +++ b/src/scanadf.c @@ -1,6 +1,6 @@ -/* saneadf - a SANE front end for document scanning +/* saneadf - a SANE front end for document scanning based on - bnhscan by tummy.com and + bnhscan by tummy.com and scanimage by Andreas Beck and David Mosberger Copyright (C) 1999 Tom Martone @@ -123,7 +123,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'}, + {"no-overwrite", no_argument, NULL, 'N'}, { "output-file", required_argument, 0, 'o' }, { "start-count", required_argument, 0, 's' }, @@ -299,9 +299,9 @@ print_option (SANE_Device *device, int opt_num, char short_name) break; } } - if (opt->type == SANE_TYPE_STRING || - opt->type == SANE_TYPE_BOOL || - opt->type == SANE_TYPE_INT || + if (opt->type == SANE_TYPE_STRING || + opt->type == SANE_TYPE_BOOL || + opt->type == SANE_TYPE_INT || opt->type == SANE_TYPE_FIXED) { /* print current option value */ @@ -913,23 +913,23 @@ get_resolution(SANE_Device *device) { opt = sane_get_option_descriptor (device, resolution_opt); - sane_control_option (device, resolution_opt, + sane_control_option (device, resolution_opt, SANE_ACTION_GET_VALUE, &val, 0); switch (opt->type) { case SANE_TYPE_INT: res = val; break; - + case SANE_TYPE_FIXED: res = (SANE_Int) SANE_UNFIX(val); break; - + case SANE_TYPE_STRING: case SANE_TYPE_BOOL: default: if (verbose) - fprintf(stderr, + fprintf(stderr, "Peculiar option data type for resolution, " "using default value.\n"); break; @@ -1002,9 +1002,9 @@ exec_script (const char *script, const char* fname, SANE_Bool use_pipe, } /*signal(SIGCHLD, SIG_IGN);*/ - switch ((pid = fork())) + switch ((pid = fork())) { - case -1: + case -1: /* fork failed */ fprintf(stderr, "Error forking: %s (%d)\n", strerror(errno), errno); break; @@ -1017,9 +1017,9 @@ exec_script (const char *script, const char* fname, SANE_Bool use_pipe, sprintf(cmd, "%s '%s'", script, fname); execle(script, script, fname, NULL, environ); exit(0); - + default: - if (verbose) + if (verbose) fprintf(stderr, "Started script `%s' as pid=%d\n", script, pid); break; } @@ -1149,7 +1149,7 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script, } else { - write_pnm_header_to_file (fp, parm.format, + write_pnm_header_to_file (fp, parm.format, parm.pixels_per_line, parm.lines, parm.depth); } @@ -1174,7 +1174,7 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script, #endif default: - /* Default action for unknown frametypes; write them out + /* Default action for unknown frametypes; write them out * without a header; issue a warning in verbose mode. * Since we're not writing a header, there's no need to * buffer. @@ -1210,7 +1210,7 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script, else image.height = 0; image.Bpp = 3; - if (parm.format == SANE_FRAME_GRAY || + if (parm.format == SANE_FRAME_GRAY || !sane_isbasicframe(parm.format)) image.Bpp = 1; image.x = image.width - 1; @@ -1226,7 +1226,7 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script, offset = parm.format - SANE_FRAME_RED; image.x = image.y = 0; } - + while (1) { status = sane_read (device, buffer, sizeof (buffer), &len); @@ -1309,13 +1309,13 @@ scan_it_raw (const char *fname, SANE_Bool raw, const char *script, if (raw == SANE_FALSE) { /* if we're writing raw, we skip the header */ - write_pnm_header_to_file (fp, parm.format, image.width, + write_pnm_header_to_file (fp, parm.format, image.width, image.height, parm.depth); } fwrite (image.data, image.Bpp, image.height * image.width, fp); } - if (fp) + if (fp) { fclose(fp); fp = NULL; @@ -1340,7 +1340,7 @@ cleanup: return status; } -static SANE_Int +static SANE_Int scan_docs (int start, int end, int no_overwrite, SANE_Bool raw, const char *outfmt, const char *script, SANE_Bool use_pipe) { @@ -1350,27 +1350,27 @@ scan_docs (int start, int end, int no_overwrite, SANE_Bool raw, struct stat statbuf; int res; - while (end < 0 || start <= end) + while (end < 0 || start <= end) { snprintf(fname, sizeof (fname), outfmt, start); /* does the filename already exist? */ - if (no_overwrite) + if (no_overwrite) { res = stat (fname, &statbuf); - if (res == 0) + 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) + if (status == SANE_STATUS_GOOD) status = scan_it_raw(fname, raw, script, use_pipe); /* Any scan errors? */ - if (status == SANE_STATUS_NO_DOCS) + if (status == SANE_STATUS_NO_DOCS) { /* out of paper in the hopper; this is our normal exit */ status = SANE_STATUS_GOOD; @@ -1384,7 +1384,7 @@ scan_docs (int start, int end, int no_overwrite, SANE_Bool raw, scannedPages++; start++; } - else + else { /* unexpected error */ fprintf(stderr, "%s\n", sane_strstatus(status)); @@ -1715,4 +1715,3 @@ List of available devices:", prog_name); return (status == SANE_STATUS_GOOD) ? 0 : 1; } - diff --git a/src/xcam.c b/src/xcam.c index 69cf178..62eb545 100644 --- a/src/xcam.c +++ b/src/xcam.c @@ -1,9 +1,9 @@ /* xcam -- X-based camera frontend Uses the SANE library. Copyright (C) 1997 David Mosberger and Tristan Tarrant - + Update 2005 Gerard Klaver - The add_text routine and font_6x11.h file are taken from the (GPLed) + 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 @@ -326,9 +326,9 @@ save_settings (const char *filename) } #define MSG_MAXLEN 45 -#define CHAR_HEIGHT 11 -#define CHAR_WIDTH 6 -#define CHAR_START 4 +#define TEXT_HEIGHT 11 +#define TEXT_WIDTH 6 +#define TEXT_START 4 static SANE_Status xcam_add_text (SANE_Byte * image, int width, int height, char *txt) @@ -359,16 +359,16 @@ xcam_add_text (SANE_Byte * image, int width, int height, char *txt) { case SANE_FRAME_RGB: - for (y = 0; y < CHAR_HEIGHT; y++) + for (y = 0; y < TEXT_HEIGHT; y++) { - ptr = image + 3 * width * (height - CHAR_HEIGHT - 2 + y) + 12; + ptr = image + 3 * width * (height - TEXT_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--) + f = fontdata[line[x] * TEXT_HEIGHT + y]; + for (i = TEXT_WIDTH - 1; i >= 0; i--) { - if (f & (CHAR_START << i)) + if (f & (TEXT_START << i)) { ptr[0] = 255; ptr[1] = 255; @@ -381,29 +381,32 @@ xcam_add_text (SANE_Byte * image, int width, int height, char *txt) break; case SANE_FRAME_GRAY: - for (y = 0; y < CHAR_HEIGHT; y++) + for (y = 0; y < TEXT_HEIGHT; y++) { - ptr = image + width * (height - CHAR_HEIGHT - 2 + y) + 12; + ptr = image + width * (height - TEXT_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--) + f = fontdata[line[x] * TEXT_HEIGHT + y]; + for (i = TEXT_WIDTH - 1; i >= 0; i--) { - if (f & (CHAR_START << i)) + if (f & (TEXT_START << i)) { ptr[0] = 255; } ptr += 1; } /* for i */ } /* for x */ - } /* for y */ + } /* for y */ + break; + 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);