Fix mixed declarations and code warnings (ISO C90)

merge-requests/1/head
Olaf Meeuwissen 2015-09-23 20:22:16 +09:00 zatwierdzone przez m. allan noah
rodzic 2f72ee5b8f
commit 4c49c87827
4 zmienionych plików z 49 dodań i 29 usunięć

Wyświetl plik

@ -225,9 +225,11 @@ static SANE_Status esci2_cmd_simple(epsonds_scanner* s, char *cmd, SANE_Status (
SANE_Status esci2_fin(epsonds_scanner *s) SANE_Status esci2_fin(epsonds_scanner *s)
{ {
SANE_Status status;
DBG(5, "%s\n", __func__); DBG(5, "%s\n", __func__);
SANE_Status status = esci2_cmd_simple(s, "FIN x0000000", NULL); status = esci2_cmd_simple(s, "FIN x0000000", NULL);
s->locked = 0; s->locked = 0;
return status; return status;
} }
@ -261,6 +263,7 @@ static int decode_value(char *buf, int len)
static char *decode_binary(char *buf) static char *decode_binary(char *buf)
{ {
char tmp[6]; char tmp[6];
int hl;
memcpy(tmp, buf, 4); memcpy(tmp, buf, 4);
tmp[4] = '\0'; tmp[4] = '\0';
@ -268,7 +271,7 @@ static char *decode_binary(char *buf)
if (buf[0] != 'h') if (buf[0] != 'h')
return NULL; return NULL;
int hl = strtol(tmp + 1, NULL, 16); hl = strtol(tmp + 1, NULL, 16);
if (hl) { if (hl) {
char *v = malloc(hl + 1); char *v = malloc(hl + 1);
@ -283,12 +286,12 @@ static char *decode_binary(char *buf)
static char *decode_string(char *buf) static char *decode_string(char *buf)
{ {
char *s = decode_binary(buf); char *p, *s = decode_binary(buf);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
/* trim white space at the end */ /* trim white space at the end */
char *p = s + strlen(s); p = s + strlen(s);
while (*--p == ' ') while (*--p == ' ')
*p = '\0'; *p = '\0';
@ -309,13 +312,14 @@ static void debug_token(int level, const char *func, char *token, int len)
static SANE_Status info_cb(void *userdata, char *token, int len) static SANE_Status info_cb(void *userdata, char *token, int len)
{ {
epsonds_scanner *s = (epsonds_scanner *)userdata; epsonds_scanner *s = (epsonds_scanner *)userdata;
char *value;
if (DBG_LEVEL >= 11) { if (DBG_LEVEL >= 11) {
debug_token(DBG_LEVEL, __func__, token, len); debug_token(DBG_LEVEL, __func__, token, len);
} }
/* pointer to the token's value */ /* pointer to the token's value */
char *value = token + 3; value = token + 3;
/* nrd / nrdBUSY */ /* nrd / nrdBUSY */
@ -537,11 +541,11 @@ static SANE_Status info_cb(void *userdata, char *token, int len)
SANE_Status esci2_info(epsonds_scanner *s) SANE_Status esci2_info(epsonds_scanner *s)
{ {
DBG(1, "= gathering device information\n");
SANE_Status status; SANE_Status status;
int i = 4; int i = 4;
DBG(1, "= gathering device information\n");
do { do {
status = esci2_cmd_simple(s, "INFOx0000000", &info_cb); status = esci2_cmd_simple(s, "INFOx0000000", &info_cb);
if (status == SANE_STATUS_DEVICE_BUSY) { if (status == SANE_STATUS_DEVICE_BUSY) {
@ -800,11 +804,11 @@ static SANE_Status img_cb(void *userdata, char *token, int len)
if (strncmp("err", token, 3) == 0) { if (strncmp("err", token, 3) == 0) {
s->scanning = 0;
char *option = token + 3; /* ADF, TPU, FB */ char *option = token + 3; /* ADF, TPU, FB */
char *cause = token + 3 + 4; /* OPN, PJ, PE, ERR, LTF, LOCK, DFED, DTCL, AUT, PERM */ char *cause = token + 3 + 4; /* OPN, PJ, PE, ERR, LTF, LOCK, DFED, DTCL, AUT, PERM */
s->scanning = 0;
DBG(1, "%s: error on option %3.3s, cause %4.4s\n", DBG(1, "%s: error on option %3.3s, cause %4.4s\n",
__func__, option, cause); __func__, option, cause);
@ -839,6 +843,9 @@ SANE_Status
esci2_img(struct epsonds_scanner *s, SANE_Int *length) esci2_img(struct epsonds_scanner *s, SANE_Int *length)
{ {
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
SANE_Status parse_status;
unsigned int more;
ssize_t read;
*length = 0; *length = 0;
@ -859,13 +866,13 @@ esci2_img(struct epsonds_scanner *s, SANE_Int *length)
} }
/* check if we need to read any image data */ /* check if we need to read any image data */
unsigned int more = 0; more = 0;
if (!esci2_check_header("IMG ", (char *)s->buf, &more)) { if (!esci2_check_header("IMG ", (char *)s->buf, &more)) {
return SANE_STATUS_IO_ERROR; return SANE_STATUS_IO_ERROR;
} }
/* this handles eof and errors */ /* this handles eof and errors */
SANE_Status parse_status = esci2_parse_block((char *)s->buf + 12, 64 - 12, s, &img_cb); parse_status = esci2_parse_block((char *)s->buf + 12, 64 - 12, s, &img_cb);
/* no more data? return using the status of the esci2_parse_block /* no more data? return using the status of the esci2_parse_block
* call, which might hold other error conditions. * call, which might hold other error conditions.
@ -875,7 +882,7 @@ esci2_img(struct epsonds_scanner *s, SANE_Int *length)
} }
/* ALWAYS read image data */ /* ALWAYS read image data */
ssize_t read = eds_recv(s, s->buf, more, &status); read = eds_recv(s, s->buf, more, &status);
if (status != SANE_STATUS_GOOD) { if (status != SANE_STATUS_GOOD) {
return status; return status;
} }

Wyświetl plik

@ -48,16 +48,17 @@ METHODDEF(boolean)
jpeg_fill_input_buffer(j_decompress_ptr cinfo) jpeg_fill_input_buffer(j_decompress_ptr cinfo)
{ {
epsonds_src_mgr *src = (epsonds_src_mgr *)cinfo->src; epsonds_src_mgr *src = (epsonds_src_mgr *)cinfo->src;
int avail, size;
/* read from the scanner or the ring buffer */ /* read from the scanner or the ring buffer */
int avail = eds_ring_avail(src->s->current); avail = eds_ring_avail(src->s->current);
if (avail == 0) { if (avail == 0) {
return FALSE; return FALSE;
} }
/* read from scanner if no data? */ /* read from scanner if no data? */
int size = min(1024, avail); size = min(1024, avail);
eds_ring_read(src->s->current, src->buffer, size); eds_ring_read(src->s->current, src->buffer, size);
@ -129,12 +130,14 @@ eds_jpeg_read_header(epsonds_scanner *s)
if (jpeg_start_decompress(&s->jpeg_cinfo)) { if (jpeg_start_decompress(&s->jpeg_cinfo)) {
int size;
DBG(3, "%s: w: %d, h: %d, components: %d\n", DBG(3, "%s: w: %d, h: %d, components: %d\n",
__func__, __func__,
s->jpeg_cinfo.output_width, s->jpeg_cinfo.output_height, s->jpeg_cinfo.output_width, s->jpeg_cinfo.output_height,
s->jpeg_cinfo.output_components); s->jpeg_cinfo.output_components);
int size = s->jpeg_cinfo.output_width * s->jpeg_cinfo.output_components * 1; size = s->jpeg_cinfo.output_width * s->jpeg_cinfo.output_components * 1;
src->linebuffer = (*s->jpeg_cinfo.mem->alloc_large)((j_common_ptr)&s->jpeg_cinfo, src->linebuffer = (*s->jpeg_cinfo.mem->alloc_large)((j_common_ptr)&s->jpeg_cinfo,
JPOOL_PERMANENT, size); JPOOL_PERMANENT, size);
@ -168,11 +171,13 @@ eds_jpeg_read(SANE_Handle handle, SANE_Byte *data,
{ {
epsonds_scanner *s = handle; epsonds_scanner *s = handle;
*length = 0;
struct jpeg_decompress_struct cinfo = s->jpeg_cinfo; struct jpeg_decompress_struct cinfo = s->jpeg_cinfo;
epsonds_src_mgr *src = (epsonds_src_mgr *)s->jpeg_cinfo.src; epsonds_src_mgr *src = (epsonds_src_mgr *)s->jpeg_cinfo.src;
int l;
*length = 0;
/* copy from line buffer if available */ /* copy from line buffer if available */
if (src->linebuffer_size && src->linebuffer_index < src->linebuffer_size) { if (src->linebuffer_size && src->linebuffer_index < src->linebuffer_size) {
@ -196,7 +201,7 @@ eds_jpeg_read(SANE_Handle handle, SANE_Byte *data,
* only one line at time is supported * only one line at time is supported
*/ */
int l = jpeg_read_scanlines(&cinfo, s->jdst->buffer, 1); l = jpeg_read_scanlines(&cinfo, s->jdst->buffer, 1);
if (l == 0) { if (l == 0) {
return; return;
} }

Wyświetl plik

@ -48,9 +48,10 @@ eds_dev_init(epsonds_device *dev)
SANE_Status SANE_Status
eds_dev_post_init(struct epsonds_device *dev) eds_dev_post_init(struct epsonds_device *dev)
{ {
SANE_String_Const *source_list_add = source_list;
DBG(10, "%s\n", __func__); DBG(10, "%s\n", __func__);
SANE_String_Const *source_list_add = source_list;
if (dev->has_fb) if (dev->has_fb)
*source_list_add++ = FBF_STR; *source_list_add++ = FBF_STR;
@ -337,12 +338,13 @@ eds_copy_image_from_ring(epsonds_scanner *s, SANE_Byte *data, SANE_Int max_lengt
while (lines--) { while (lines--) {
int i;
SANE_Byte *p;
eds_ring_read(s->current, s->line_buffer, s->params.bytes_per_line); eds_ring_read(s->current, s->line_buffer, s->params.bytes_per_line);
eds_ring_skip(s->current, s->dummy); eds_ring_skip(s->current, s->dummy);
int i; p = s->line_buffer;
SANE_Byte *p = s->line_buffer;
for (i = 0; i < s->params.bytes_per_line; i++) { for (i = 0; i < s->params.bytes_per_line; i++) {
*data++ = ~*p++; *data++ = ~*p++;
@ -379,12 +381,14 @@ SANE_Status eds_ring_init(ring_buffer *ring, SANE_Int size)
SANE_Status eds_ring_write(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) SANE_Status eds_ring_write(ring_buffer *ring, SANE_Byte *buf, SANE_Int size)
{ {
SANE_Int tail;
if (size > (ring->size - ring->fill)) { if (size > (ring->size - ring->fill)) {
DBG(1, "ring buffer full, requested: %d, available: %d\n", size, ring->size - ring->fill); DBG(1, "ring buffer full, requested: %d, available: %d\n", size, ring->size - ring->fill);
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
} }
SANE_Int tail = ring->end - ring->wp; tail = ring->end - ring->wp;
if (size < tail) { if (size < tail) {
memcpy(ring->wp, buf, size); memcpy(ring->wp, buf, size);
@ -409,6 +413,8 @@ SANE_Status eds_ring_write(ring_buffer *ring, SANE_Byte *buf, SANE_Int size)
SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size) SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size)
{ {
SANE_Int tail;
DBG(18, "reading from ring, %d bytes available\n", (int)ring->fill); DBG(18, "reading from ring, %d bytes available\n", (int)ring->fill);
/* limit read to available */ /* limit read to available */
@ -417,7 +423,7 @@ SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size)
size = ring->fill; size = ring->fill;
} }
SANE_Int tail = ring->end - ring->rp; tail = ring->end - ring->rp;
if (size < tail) { if (size < tail) {
memcpy(buf, ring->rp, size); memcpy(buf, ring->rp, size);
@ -444,11 +450,12 @@ SANE_Int eds_ring_read(ring_buffer *ring, SANE_Byte *buf, SANE_Int size)
SANE_Int eds_ring_skip(ring_buffer *ring, SANE_Int size) SANE_Int eds_ring_skip(ring_buffer *ring, SANE_Int size)
{ {
SANE_Int tail;
/* limit skip to available */ /* limit skip to available */
if (size > ring->fill) if (size > ring->fill)
size = ring->fill; size = ring->fill;
SANE_Int tail = ring->end - ring->rp; tail = ring->end - ring->rp;
if (size < tail) { if (size < tail) {
ring->rp += size; ring->rp += size;
} else { } else {

Wyświetl plik

@ -330,10 +330,11 @@ static SANE_Status
attach(const char *name, int type) attach(const char *name, int type)
{ {
SANE_Status status; SANE_Status status;
epsonds_scanner * s;
DBG(7, "%s: devname = %s, type = %d\n", __func__, name, type); DBG(7, "%s: devname = %s, type = %d\n", __func__, name, type);
epsonds_scanner *s = device_detect(name, type, &status); s = device_detect(name, type, &status);
if (s == NULL) if (s == NULL)
return status; return status;
@ -1041,6 +1042,7 @@ sane_start(SANE_Handle handle)
{ {
epsonds_scanner *s = (epsonds_scanner *)handle; epsonds_scanner *s = (epsonds_scanner *)handle;
char buf[64]; char buf[64];
char cmd[100]; /* take care not to overflow */
SANE_Status status = 0; SANE_Status status = 0;
s->pages++; s->pages++;
@ -1103,8 +1105,6 @@ sane_start(SANE_Handle handle)
/* set scanning parameters */ /* set scanning parameters */
char cmd[100]; /* take care not to overflow */
/* document source */ /* document source */
if (strcmp(source_list[s->val[OPT_SOURCE].w], ADF_STR) == 0) { if (strcmp(source_list[s->val[OPT_SOURCE].w], ADF_STR) == 0) {
@ -1194,6 +1194,7 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length,
SANE_Int *length) SANE_Int *length)
{ {
SANE_Int read = 0, tries = 3; SANE_Int read = 0, tries = 3;
SANE_Int available;
SANE_Status status = 0; SANE_Status status = 0;
epsonds_scanner *s = (epsonds_scanner *)handle; epsonds_scanner *s = (epsonds_scanner *)handle;
@ -1208,7 +1209,7 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length,
} }
/* anything in the buffer? pass it to the frontend */ /* anything in the buffer? pass it to the frontend */
SANE_Int available = eds_ring_avail(s->current); available = eds_ring_avail(s->current);
if (available) { if (available) {
DBG(18, "reading from ring buffer, %d left\n", available); DBG(18, "reading from ring buffer, %d left\n", available);