Exchange of fprintf(stderr, ...) with avrdude_message(...).

This change was made for the shared library, since library functions
should not write to std-streams directly. Instead avrdude_message()
has to be implemented by the library user. For the avrdude application
this function is implemented in main.c.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1305 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Axel Wachtler
2014-05-18 08:41:46 +00:00
parent 52dd5cc7ac
commit eb5fcb581f
45 changed files with 2380 additions and 2896 deletions

View File

@@ -76,13 +76,13 @@
#endif
#if 0
#define DEBUG(...) do { fprintf(stderr, __VA_ARGS__); } while(0)
#define DEBUG(...) do { avrdude_message(__VA_ARGS__); } while(0)
#else
#define DEBUG(...) ((void)0)
#endif
#if 0
#define DEBUGRECV(...) do { fprintf(stderr, __VA_ARGS__); } while(0)
#define DEBUGRECV(...) do { avrdude_message(__VA_ARGS__); } while(0)
#else
#define DEBUGRECV(...) ((void)0)
#endif
@@ -169,9 +169,8 @@ static void pickit2_setup(PROGRAMMER * pgm)
{
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0)
{
fprintf(stderr,
"%s: pickit2_setup(): Out of memory allocating private data\n",
progname);
avrdude_message("%s: pickit2_setup(): Out of memory allocating private data\n",
progname);
exit(1);
}
memset(pgm->cookie, 0, sizeof(struct pdata));
@@ -193,9 +192,8 @@ static int pickit2_open(PROGRAMMER * pgm, char * port)
if (PDATA(pgm)->usb_handle == INVALID_HANDLE_VALUE)
{
/* no PICkit2 found */
fprintf(stderr,
"%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
progname, PICKIT2_VID, PICKIT2_PID);
avrdude_message("%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
progname, PICKIT2_VID, PICKIT2_PID);
return -1;
}
else
@@ -215,9 +213,8 @@ static int pickit2_open(PROGRAMMER * pgm, char * port)
if (usb_open_device(&(PDATA(pgm)->usb_handle), PICKIT2_VID, PICKIT2_PID) < 0)
{
/* no PICkit2 found */
fprintf(stderr,
"%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
progname, PICKIT2_VID, PICKIT2_PID);
avrdude_message("%s: error: could not find PICkit2 with vid=0x%x pid=0x%x\n",
progname, PICKIT2_VID, PICKIT2_PID);
return -1;
}
#endif
@@ -267,7 +264,7 @@ static int pickit2_initialize(PROGRAMMER * pgm, AVRPART * p)
{
if (verbose)
{
fprintf(stderr, "%s: %s firmware version %d.%d.%d\n", progname, pgm->desc, (int)report[1], (int)report[2], (int)report[3]);
avrdude_message("%s: %s firmware version %d.%d.%d\n", progname, pgm->desc, (int)report[1], (int)report[2], (int)report[3]);
}
// set the pins, apply reset,
@@ -303,19 +300,19 @@ static int pickit2_initialize(PROGRAMMER * pgm, AVRPART * p)
if (pickit2_write_report(pgm, report) < 0)
{
fprintf(stderr, "pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror());
avrdude_message("pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1;
}
}
else
{
fprintf(stderr, "pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror());
avrdude_message("pickit2_read_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1;
}
}
else
{
fprintf(stderr, "pickit2_write_report failed (ec %d). %s\n", errorCode, usb_strerror());
avrdude_message("pickit2_write_report failed (ec %d). %s\n", errorCode, usb_strerror());
return -1;
}
@@ -428,7 +425,7 @@ static int pickit2_program_enable(struct programmer_t * pgm, AVRPART * p)
if (p->op[AVR_OP_PGM_ENABLE] == NULL)
{
fprintf(stderr, "program enable instruction not defined for part \"%s\"\n",
avrdude_message("program enable instruction not defined for part \"%s\"\n",
p->desc);
return -1;
}
@@ -440,13 +437,13 @@ static int pickit2_program_enable(struct programmer_t * pgm, AVRPART * p)
if (verbose)
{
int i;
fprintf(stderr, "program_enable(): sending command. Resp = ");
avrdude_message("program_enable(): sending command. Resp = ");
for (i = 0; i < 4; i++)
{
fprintf(stderr, "%x ", (int)res[i]);
avrdude_message("%x ", (int)res[i]);
}
fprintf(stderr, "\n");
avrdude_message("\n");
}
// check for sync character
@@ -463,7 +460,7 @@ static int pickit2_chip_erase(struct programmer_t * pgm, AVRPART * p)
if (p->op[AVR_OP_CHIP_ERASE] == NULL)
{
fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n",
avrdude_message("chip erase instruction not defined for part \"%s\"\n",
p->desc);
return -1;
}
@@ -540,7 +537,7 @@ static int pickit2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
}
else
{
fprintf(stderr, "no read command specified\n");
avrdude_message("no read command specified\n");
return -1;
}
@@ -552,7 +549,7 @@ static int pickit2_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (bytes_read < 0)
{
fprintf(stderr, "Failed @ pgm->spi()\n");
avrdude_message("Failed @ pgm->spi()\n");
pgm->err_led(pgm, ON);
return -1;
}
@@ -586,9 +583,8 @@ static int pickit2_commit_page(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
wp = mem->op[AVR_OP_WRITEPAGE];
if (wp == NULL)
{
fprintf(stderr,
"pickit2_commit_page(): memory \"%s\" not configured for page writes\n",
mem->desc);
avrdude_message("pickit2_commit_page(): memory \"%s\" not configured for page writes\n",
mem->desc);
return -1;
}
@@ -635,7 +631,7 @@ static int pickit2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
// only paged write for flash implemented
if (strcmp(mem->desc, "flash") != 0 && strcmp(mem->desc, "eeprom") != 0)
{
fprintf(stderr, "Part does not support %d paged write of %s\n", page_size, mem->desc);
avrdude_message("Part does not support %d paged write of %s\n", page_size, mem->desc);
return -1;
}
@@ -692,7 +688,7 @@ static int pickit2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
writeop = mem->op[AVR_OP_WRITE_LO];
caddr = addr; // maybe this should divide by 2 & use the write_high opcode also
fprintf(stderr, "Error AVR_OP_WRITE_LO defined only (where's the HIGH command?)\n");
avrdude_message("Error AVR_OP_WRITE_LO defined only (where's the HIGH command?)\n");
return -1;
}
else
@@ -717,7 +713,7 @@ static int pickit2_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
if (bytes_read < 0)
{
fprintf(stderr, "Failed @ pgm->spi()\n");
avrdude_message("Failed @ pgm->spi()\n");
pgm->err_led(pgm, ON);
return -1;
}
@@ -1159,7 +1155,7 @@ static int usb_open_device(struct usb_dev_handle **device, int vendor, int produ
if (handle == NULL)
{
errorCode = USB_ERROR_ACCESS;
fprintf(stderr, "%s: Warning: cannot open USB device: %s\n", progname, usb_strerror());
avrdude_message("%s: Warning: cannot open USB device: %s\n", progname, usb_strerror());
continue;
}
@@ -1168,18 +1164,18 @@ static int usb_open_device(struct usb_dev_handle **device, int vendor, int produ
{
if (verbose)
{
fprintf(stderr, "Device %p seemed to open OK.\n", handle);
avrdude_message("Device %p seemed to open OK.\n", handle);
}
if ((errorCode = usb_set_configuration(handle, 1)) < 0)
{
fprintf(stderr, "Could not set configuration. Error code %d, %s.\n"
avrdude_message("Could not set configuration. Error code %d, %s.\n"
"You may need to run avrdude as root or set up correct usb port permissions.", errorCode, usb_strerror());
}
if ((errorCode = usb_claim_interface(handle, 0)) < 0)
{
fprintf(stderr, "Could not claim interface. Error code %d, %s\n"
avrdude_message("Could not claim interface. Error code %d, %s\n"
"You may need to run avrdude as root or set up correct usb port permissions.", errorCode, usb_strerror());
}
@@ -1222,9 +1218,8 @@ static int pickit2_parseextparams(struct programmer_t * pgm, LISTID extparms)
int clock_rate;
if (sscanf(extended_param, "clockrate=%i", &clock_rate) != 1 || clock_rate <= 0)
{
fprintf(stderr,
"%s: pickit2_parseextparms(): invalid clockrate '%s'\n",
progname, extended_param);
avrdude_message("%s: pickit2_parseextparms(): invalid clockrate '%s'\n",
progname, extended_param);
rv = -1;
continue;
}
@@ -1234,9 +1229,8 @@ static int pickit2_parseextparams(struct programmer_t * pgm, LISTID extparms)
if (verbose >= 2)
{
fprintf(stderr,
"%s: pickit2_parseextparms(): clockrate set to 0x%02x\n",
progname, clock_rate);
avrdude_message("%s: pickit2_parseextparms(): clockrate set to 0x%02x\n",
progname, clock_rate);
}
PDATA(pgm)->clock_period = clock_period;
@@ -1248,27 +1242,24 @@ static int pickit2_parseextparams(struct programmer_t * pgm, LISTID extparms)
int timeout;
if (sscanf(extended_param, "timeout=%i", &timeout) != 1 || timeout <= 0)
{
fprintf(stderr,
"%s: pickit2_parseextparms(): invalid timeout '%s'\n",
progname, extended_param);
avrdude_message("%s: pickit2_parseextparms(): invalid timeout '%s'\n",
progname, extended_param);
rv = -1;
continue;
}
if (verbose >= 2)
{
fprintf(stderr,
"%s: pickit2_parseextparms(): usb timeout set to 0x%02x\n",
progname, timeout);
avrdude_message("%s: pickit2_parseextparms(): usb timeout set to 0x%02x\n",
progname, timeout);
}
PDATA(pgm)->transaction_timeout = timeout;
continue;
}
fprintf(stderr,
"%s: pickit2_parseextparms(): invalid extended parameter '%s'\n",
progname, extended_param);
avrdude_message("%s: pickit2_parseextparms(): invalid extended parameter '%s'\n",
progname, extended_param);
rv = -1;
}
@@ -1333,7 +1324,7 @@ void pickit2_initpgm (PROGRAMMER * pgm)
}
#else
static int pickit2_nousb_open (struct programmer_t *pgm, char * name) {
fprintf(stderr,
avrdude_message(
#ifdef WIN32NATIVE
"%s: error: no usb or hid support. Please compile again with libusb or HID support from Win32 DDK installed.\n",
#else