Make the -U parser tolerate colons in filenames.

Document the change, including changing one of the texinfo examples
to use a Windows-like filename that contains a space (and thus
requires quoting).

This fixes bug #6764.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@386 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Joerg Wunsch 2003-11-26 22:05:02 +00:00
parent 44617af1ed
commit 19d4d87047
3 changed files with 49 additions and 41 deletions

View File

@ -19,7 +19,7 @@
.\" .\"
.\" $Id$ .\" $Id$
.\" .\"
.Dd DATE July 24, 2003 .Dd DATE November 26, 2003
.Os .Os
.Dt AVRDUDE 1 .Dt AVRDUDE 1
.Sh NAME .Sh NAME
@ -387,6 +387,13 @@ field is optional and contains the format of the file to read or
write. See the write. See the
.Fl f .Fl f
option for possible values. option for possible values.
Note that if
.Ar filename
contains a colon, the
.Ar format
field is no longer optional since the filename part following the colon
would otherwise be misinterpreted as
.Ar format .
.It Fl v .It Fl v
Enable verbose output. Enable verbose output.
.It Fl V .It Fl V

View File

@ -495,6 +495,9 @@ The @var{filename} field indicates the name of the file to read or
write. The @var{format} field is optional and contains the format of write. The @var{format} field is optional and contains the format of
the file to read or write. See the @option{-f} option for possible the file to read or write. See the @option{-f} option for possible
values. values.
Note that if @var{filename} contains a colon, the @var{format} field is
no longer optional since the filename part following the colon would
otherwise be misinterpreted as @var{format}.
@item -v @item -v
Enable verbose output. Enable verbose output.
@ -574,11 +577,11 @@ avrdude done. Thank you.
@noindent @noindent
Upload the flash memory from the ATmega128 connected to the STK500 Upload the flash memory from the ATmega128 connected to the STK500
programmer and save it in raw binary format in the file named programmer and save it in raw binary format in the file named
@code{diag.flash}: @code{c:/diag flash.bin}:
@example @example
@cartouche @cartouche
% avrdude -p m128 -c stk500 -U flash:r:diag.flash:r % avrdude -p m128 -c stk500 -U flash:r:"c:/diag flash.bin":r
avrdude: AVR device initialized and ready to accept instructions avrdude: AVR device initialized and ready to accept instructions
@ -589,7 +592,7 @@ avrdude: reading flash memory:
Reading | ################################################## | 100% 46.10s Reading | ################################################## | 100% 46.10s
avrdude: writing output file "diag.flash" avrdude: writing output file "c:/diag flash.bin"
avrdude done. Thank you. avrdude done. Thank you.

View File

@ -393,9 +393,10 @@ static void update_progress_no_tty (int percent, double etime, char *hdr)
UPDATE * parse_op(char * s) UPDATE * parse_op(char * s)
{ {
char buf[1024]; char buf[1024];
char * p; char * p, * cp, c;
UPDATE * upd; UPDATE * upd;
int i; int i;
size_t fnlen;
upd = (UPDATE *)malloc(sizeof(UPDATE)); upd = (UPDATE *)malloc(sizeof(UPDATE));
if (upd == NULL) { if (upd == NULL) {
@ -457,55 +458,52 @@ UPDATE * parse_op(char * s)
p++; p++;
i = 0; /*
while ((i < (sizeof(buf)-1) && *p && (*p != ':'))) * Now, parse the filename component. Instead of looking for the
buf[i++] = *p++; * leftmost possible colon delimiter, we look for the rightmost one.
* If we found one, we do have a trailing :format specifier, and
if (!((*p == ':')||(*p == 0))) { * process it. Otherwise, the remainder of the string is our file
fprintf(stderr, "%s: invalid update specification\n", progname); * name component. That way, the file name itself is allowed to
free(upd->memtype); * contain a colon itself (e. g. C:/some/file.hex), except the
free(upd); * optional format specifier becomes mandatory then.
return NULL; */
} cp = p;
p = strrchr(cp, ':');
buf[i] = 0; if (p == NULL) {
upd->format = FMT_AUTO;
upd->filename = (char *)malloc(strlen(buf)+1); fnlen = strlen(cp);
if (upd->filename == NULL) { upd->filename = (char *)malloc(fnlen + 1);
fprintf(stderr, "%s: out of memory\n", progname); } else {
free(upd->memtype); fnlen = p - cp;
free(upd); upd->filename = (char *)malloc(fnlen +1);
return NULL; c = *++p;
} if (c && p[1])
strcpy(upd->filename, buf); /* More than one char - force failure below. */
c = '?';
upd->format = FMT_AUTO; switch (c) {
if (*p == ':') {
p++;
switch (*p) {
case 'a': upd->format = FMT_AUTO; break; case 'a': upd->format = FMT_AUTO; break;
case 's': upd->format = FMT_SREC; break; case 's': upd->format = FMT_SREC; break;
case 'i': upd->format = FMT_IHEX; break; case 'i': upd->format = FMT_IHEX; break;
case 'r': upd->format = FMT_RBIN; break; case 'r': upd->format = FMT_RBIN; break;
case 'm': upd->format = FMT_IMM; break; case 'm': upd->format = FMT_IMM; break;
default: default:
fprintf(stderr, "%s: invalid file format '%c' in update specifier\n", fprintf(stderr, "%s: invalid file format '%s' in update specifier\n",
progname, *p); progname, p);
free(upd->memtype); free(upd->memtype);
free(upd->filename);
free(upd); free(upd);
return NULL; return NULL;
} }
p++;
} }
if (*p != 0) { if (upd->filename == NULL) {
fprintf(stderr, fprintf(stderr, "%s: out of memory\n", progname);
"%s: WARNING, extraneous data (%s) in update specifier ignored\n", free(upd->memtype);
progname, p); free(upd);
return NULL;
} }
memcpy(upd->filename, cp, fnlen);
upd->filename[fnlen] = 0;
return upd; return upd;
} }