kopia lustrzana https://gitlab.com/sane-project/backends
frontend/scanimage.c / part for the "-f" command line option:
replaced the vprintf call with a loop of printf calls; fixed a "too stingy" malloc AbelDEVEL_2_0_BRANCH-1
rodzic
ef7221f8b7
commit
eee0a46577
|
@ -1491,17 +1491,12 @@ main (int argc, char **argv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i = 0, n = 0, maxarg = 8;
|
int i = 0, int_arg = 0;
|
||||||
char *percent;
|
char *percent, *start, *fmt;
|
||||||
char *start, *fmt;
|
const char *text_arg = 0;
|
||||||
const char **arglist = malloc(8 * sizeof(char**));
|
char cc, ftype;
|
||||||
if (arglist == 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: not enough memory\n", prog_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt = malloc(strlen(optarg));
|
fmt = malloc(strlen(optarg)+1);
|
||||||
if (fmt == 0)
|
if (fmt == 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: not enough memory\n", prog_name);
|
fprintf(stderr, "%s: not enough memory\n", prog_name);
|
||||||
|
@ -1510,71 +1505,82 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
for (i = 0; device_list[i]; ++i)
|
for (i = 0; device_list[i]; ++i)
|
||||||
{
|
{
|
||||||
n = 0;
|
|
||||||
strcpy(fmt, optarg);
|
strcpy(fmt, optarg);
|
||||||
start = fmt;
|
start = fmt;
|
||||||
while( (percent = strchr(start, '%')) )
|
while(*start && (percent = strchr(start, '%')) )
|
||||||
{
|
{
|
||||||
percent++;
|
percent++;
|
||||||
if (percent)
|
if (*percent)
|
||||||
{
|
{
|
||||||
if (n >= maxarg)
|
|
||||||
{
|
|
||||||
maxarg = 2 * maxarg;
|
|
||||||
arglist = realloc(arglist, maxarg * sizeof(char**));
|
|
||||||
if (arglist == 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: not enough memory\n",
|
|
||||||
prog_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (*percent)
|
switch (*percent)
|
||||||
{
|
{
|
||||||
case 'd':
|
case 'd':
|
||||||
arglist[n++] = device_list[i]->name;
|
text_arg = device_list[i]->name;
|
||||||
*percent = 's';
|
ftype = *percent = 's';
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
arglist[n++] = device_list[i]->vendor;
|
text_arg = device_list[i]->vendor;
|
||||||
*percent = 's';
|
ftype = *percent = 's';
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
arglist[n++] = device_list[i]->model;
|
text_arg = device_list[i]->model;
|
||||||
*percent = 's';
|
ftype = *percent = 's';
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
arglist[n++] = device_list[i]->type;
|
text_arg = device_list[i]->type;
|
||||||
*percent = 's';
|
ftype = *percent = 's';
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
arglist[n++] = (char *) i;
|
int_arg = i;
|
||||||
|
ftype = 'i';
|
||||||
break;
|
break;
|
||||||
case '%':
|
case '%':
|
||||||
|
ftype = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: unknown format specifier %%%c\n",
|
fprintf(stderr, "%s: unknown format specifier %%%c\n",
|
||||||
prog_name, *percent);
|
prog_name, *percent);
|
||||||
*percent = '%';
|
*percent = '%';
|
||||||
|
ftype = 0;
|
||||||
}
|
}
|
||||||
percent++;
|
percent++;
|
||||||
|
cc = *percent;
|
||||||
|
*percent = 0;
|
||||||
|
switch (ftype)
|
||||||
|
{
|
||||||
|
case 's':
|
||||||
|
printf(start, text_arg);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
printf(start, int_arg);
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
printf(start);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
*percent = cc;
|
||||||
start = percent;
|
start = percent;
|
||||||
}
|
}
|
||||||
vprintf(fmt, arglist);
|
else
|
||||||
va_end(arglist);
|
{
|
||||||
|
/* last char of the string is a '%', suppress it */
|
||||||
|
*start = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*start)
|
||||||
|
printf(start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0 && ch != 'f')
|
if (i == 0 && ch != 'f')
|
||||||
printf ("\nNo scanners were identified. If you were expecting "
|
printf ("\nNo scanners were identified. If you were expecting "
|
||||||
"something different,\ncheck that the scanner is plugged "
|
"something different,\ncheck that the scanner is plugged "
|
||||||
"in, turned on and detected by the\nsane-find-scanner tool "
|
"in, turned on and detected by the\nsane-find-scanner tool "
|
||||||
"(if appropriate). Please read the documentation\nwhich came "
|
"(if appropriate). Please read the documentation\nwhich came "
|
||||||
"with this software (README, FAQ, manpages).\n");
|
"with this software (README, FAQ, manpages).\n");
|
||||||
|
|
||||||
if (defdevname)
|
if (defdevname)
|
||||||
printf ("default device is `%s'\n", defdevname);
|
printf ("default device is `%s'\n", defdevname);
|
||||||
|
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue