mirror of
https://github.com/avrdudes/avrdude.git
synced 2026-09-29 04:18:54 +03:00
Merge remote-tracking branch 'upstream/main' into swig_libavrdude
This commit is contained in:
1
NEWS
1
NEWS
@@ -35,6 +35,7 @@ Changes since version 7.3:
|
||||
- Replace msg_info() by msg_debug() in jtag3_prmsg()
|
||||
and jtag3_prevent() #1727
|
||||
- Remove unused avrdude_message() #1730
|
||||
- Add lmsg_xyz() functions to start message at left margin #1728
|
||||
|
||||
* Internals:
|
||||
|
||||
|
||||
88
src/avr.c
88
src/avr.c
@@ -1625,24 +1625,88 @@ int avr_unlock(const PROGRAMMER *pgm, const AVRPART *p) {
|
||||
/*
|
||||
* Report the progress of a read or write operation from/to the device
|
||||
*
|
||||
* The first call of report_progress() should look like this (for a write):
|
||||
* Potentially time-consuming libavrdude functions such as avr_read() and
|
||||
* avr_write() use this interface to inform the user of their progress.
|
||||
*
|
||||
* report_progress(0, 1, "Writing");
|
||||
* The first call of report_progress() normally looks like this, eg, for a
|
||||
* write-to-device operation:
|
||||
*
|
||||
* Then hdr should be passed NULL on subsequent calls *
|
||||
* report_progress(k, n, NULL); // k/n signifies proportion of work done
|
||||
* report_progress(0, 1, "Writing");
|
||||
*
|
||||
* with 0 <= k < n, while the operation is progressing. Once the operation is
|
||||
* complete, a final call should be made as such to ensure proper termination
|
||||
* of the progress report; choose one of the following three forms:
|
||||
* Then hdr should be passed NULL on subsequent calls
|
||||
*
|
||||
* report_progress(n, n, NULL); // finished OK, terminate with double \n
|
||||
* report_progress(1, 0, NULL); // finished OK, do not print terminating \n
|
||||
* report_progress(1, -1, NULL); // finished not OK, print double \n
|
||||
* report_progress(k, n, NULL); // k/n signifies proportion of work done
|
||||
*
|
||||
* with 0 <= k < n, while the operation is progressing. Once the operation
|
||||
* is complete, a final call must be made to ensure proper termination of
|
||||
* the progress report; choose one of the following three forms:
|
||||
*
|
||||
* report_progress(n, n, NULL); // Finished OK: terminate display
|
||||
* report_progress(1, 0, NULL); // Finished OK: do not terminate display
|
||||
* report_progress(1, -1, NULL); // Finished on error: task not completed
|
||||
*
|
||||
* It is OK to call report_progress(1, -1, NULL) in a subroutine when
|
||||
* encountering a fatal error to terminate the reporting here and there even
|
||||
* though no report may have been started.
|
||||
* encountering a fatal error to terminate the reporting here and there
|
||||
* even though no report may have been started. It is also OK to skip the
|
||||
* first call report_progress(0, 1, "<title>") in which case the following
|
||||
* report_progress() calls should not generate any report.
|
||||
*
|
||||
* In fact, avr_read() and avr_write(), or their core parts avr_read_mem()
|
||||
* and avr_write_mem() for that matter, internally only issue ongoing
|
||||
*
|
||||
* report_progress(k, n, NULL);
|
||||
*
|
||||
* reporting and leave it to the caller whether or not reports should be
|
||||
* generated at all: the caller's responsibility is to initiate the
|
||||
* reporting or not by calling report_progress(0, 1, "Reading/Writing") or
|
||||
* not. An example of good practice is the following sequence:
|
||||
*
|
||||
* if(mem->size > 32 || verbose > 1) // Reporting required?
|
||||
* report_progress(0, 1, "Reading");
|
||||
* rc = avr_read(pgm, part, mem->desc, 0); // Errors terminate reporting
|
||||
* report_progress(1, 1, NULL); // Ensure reporting finishes
|
||||
*
|
||||
*
|
||||
* report_progress() relies on an application specific function
|
||||
*
|
||||
* void app_updprg(int percent, double etime, const char *hdr, int finish);
|
||||
*
|
||||
* being pointed at by the global function pointer update_progress. This
|
||||
* function controls how the application informs the user how much
|
||||
* progress the particular operation has made. This could be, eg, showing
|
||||
* a video of an increasing number of dancing hamsters, playing the audio
|
||||
* of a drum roll, showing a countdown clock or a progress bar. It is the
|
||||
* application's responsibility to provide that function and to assign it
|
||||
*
|
||||
* update_progress = app_updprg; // Install progress updating
|
||||
*
|
||||
* before the application's first call of progress_report(). The update
|
||||
* function has to keep track whether reporting was initiated or has been
|
||||
* prematurely cut short, eg, by an error. It received an int percentage
|
||||
* in [0, 100] of how much progress has been made, a double etime of how
|
||||
* much time in seconds has passed since the activity started, a string
|
||||
* hdr that describes the activity, eg, "Reading" (device memory) and an
|
||||
* integer finish that tells the routine how the task has finished.
|
||||
*
|
||||
* Reporting should only start upon the first non-NULL hdr string was
|
||||
* passed. Reporting should end immediately after percent reaches 100.
|
||||
* Calls to update_progress() once reporting has ended should not show
|
||||
* progress until the next time a non-NULL hdr was passed. The last
|
||||
* argument finish can have three values:
|
||||
* -1 A severe error occurred and reporting ends; as the current
|
||||
* percent value will be 100 the most recently passed percent of a
|
||||
* previous call, if any, indicates how far the task has come before
|
||||
* the error occurred.
|
||||
* 0 If percent is 100 reporting ends and the caller does not wish the
|
||||
* display to be terminated; for an ASCII progress bar this means
|
||||
* that no terminating \n is printed
|
||||
* 1 If percent is 100 reporting ends and the caller wishes the
|
||||
* display to be terminated; for an ASCII progress bar this means
|
||||
* that two terminating \n are printed
|
||||
*
|
||||
* As an example see how term.c's void update_progress_tty() function
|
||||
* shows an ASCII progress bar.
|
||||
*
|
||||
*/
|
||||
|
||||
void report_progress(int completed, int total, const char *hdr) {
|
||||
|
||||
@@ -53,27 +53,39 @@ int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int
|
||||
#define msg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_TRACE, __VA_ARGS__)
|
||||
#define msg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_TRACE2, __VA_ARGS__)
|
||||
|
||||
#define pmsg_ext_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH, MSG_EXT_ERROR, __VA_ARGS__)
|
||||
#define pmsg_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH, MSG_ERROR, __VA_ARGS__)
|
||||
#define pmsg_warning(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH, MSG_WARNING, __VA_ARGS__)
|
||||
#define pmsg_info(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
|
||||
#define pmsg_notice(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_NOTICE, __VA_ARGS__)
|
||||
#define pmsg_notice2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_NOTICE2, __VA_ARGS__)
|
||||
#define pmsg_debug(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_DEBUG, __VA_ARGS__)
|
||||
#define pmsg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_TRACE, __VA_ARGS__)
|
||||
#define pmsg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_TRACE2, __VA_ARGS__)
|
||||
#define pmsg_ext_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_EXT_ERROR, __VA_ARGS__)
|
||||
#define pmsg_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_ERROR, __VA_ARGS__)
|
||||
#define pmsg_warning(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_WARNING, __VA_ARGS__)
|
||||
#define pmsg_info(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_INFO, __VA_ARGS__)
|
||||
#define pmsg_notice(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_NOTICE, __VA_ARGS__)
|
||||
#define pmsg_notice2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_NOTICE2, __VA_ARGS__)
|
||||
#define pmsg_debug(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_DEBUG, __VA_ARGS__)
|
||||
#define pmsg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_TRACE, __VA_ARGS__)
|
||||
#define pmsg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_TRACE2, __VA_ARGS__)
|
||||
|
||||
#define imsg_ext_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH, MSG_EXT_ERROR, __VA_ARGS__)
|
||||
#define imsg_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH, MSG_ERROR, __VA_ARGS__)
|
||||
#define imsg_warning(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH, MSG_WARNING, __VA_ARGS__)
|
||||
#define imsg_info(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
|
||||
#define imsg_notice(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_NOTICE, __VA_ARGS__)
|
||||
#define imsg_notice2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_NOTICE2, __VA_ARGS__)
|
||||
#define imsg_debug(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_DEBUG, __VA_ARGS__)
|
||||
#define imsg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_TRACE, __VA_ARGS__)
|
||||
#define imsg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_TRACE2, __VA_ARGS__)
|
||||
#define imsg_ext_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_EXT_ERROR, __VA_ARGS__)
|
||||
#define imsg_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_ERROR, __VA_ARGS__)
|
||||
#define imsg_warning(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_WARNING, __VA_ARGS__)
|
||||
#define imsg_info(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_INFO, __VA_ARGS__)
|
||||
#define imsg_notice(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_NOTICE, __VA_ARGS__)
|
||||
#define imsg_notice2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_NOTICE2, __VA_ARGS__)
|
||||
#define imsg_debug(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_DEBUG, __VA_ARGS__)
|
||||
#define imsg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_TRACE, __VA_ARGS__)
|
||||
#define imsg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_TRACE2, __VA_ARGS__)
|
||||
|
||||
#define lmsg_ext_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_EXT_ERROR, __VA_ARGS__)
|
||||
#define lmsg_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_ERROR, __VA_ARGS__)
|
||||
#define lmsg_warning(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_WARNING, __VA_ARGS__)
|
||||
#define lmsg_info(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_INFO, __VA_ARGS__)
|
||||
#define lmsg_notice(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_NOTICE, __VA_ARGS__)
|
||||
#define lmsg_notice2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_NOTICE2, __VA_ARGS__)
|
||||
#define lmsg_debug(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_DEBUG, __VA_ARGS__)
|
||||
#define lmsg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_TRACE, __VA_ARGS__)
|
||||
#define lmsg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_LEFT_MARGIN, MSG_TRACE2, __VA_ARGS__)
|
||||
|
||||
#define term_out(...) avrdude_message2(stdout, __LINE__, __FILE__, __func__, MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
|
||||
#define lterm_out(...) avrdude_message2(stdout, __LINE__, __FILE__, __func__, MSG2_FLUSH|MSG2_LEFT_MARGIN, MSG_INFO, __VA_ARGS__)
|
||||
|
||||
#define fmsg_out(fp, ...) avrdude_message2(fp, __LINE__, __FILE__, __func__, MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
40
src/main.c
40
src/main.c
@@ -74,12 +74,10 @@ static const char *avrdude_message_type(int msglvl) {
|
||||
|
||||
|
||||
/*
|
||||
* Core msg_xyz() routine
|
||||
* Core messaging routine for msg_xyz(), [pli]msg_xyz() and term_out()
|
||||
* See #define lines in avrdude.h of how it is normally called
|
||||
* Side note: if format starts with \v print \n but only if *not* at beginning of line
|
||||
*
|
||||
* Function is named that way since there used to be a different avrdude_message()
|
||||
* before which is gone now.
|
||||
* Named that way as there used to be a now gone different avrdude_message()
|
||||
*/
|
||||
int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int msgmode, int msglvl, const char *format, ...) {
|
||||
int rc = 0;
|
||||
@@ -110,9 +108,21 @@ int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int
|
||||
|
||||
// Reduce effective verbosity level by number of -q above one when printing to stderr
|
||||
if ((quell_progress < 2 || fp != stderr? verbose: verbose+1-quell_progress) >= msglvl) {
|
||||
if(msgmode & MSG2_PROGNAME) {
|
||||
if(!bols[bi].bol)
|
||||
if(msgmode & MSG2_LEFT_MARGIN && !bols[bi].bol) {
|
||||
fprintf(fp, "\n");
|
||||
bols[bi].bol = 1;
|
||||
}
|
||||
|
||||
// Keep vertical tab at start of format string as conditional new line
|
||||
if(*format == '\v') {
|
||||
format++;
|
||||
if(!bols[bi].bol) {
|
||||
fprintf(fp, "\n");
|
||||
bols[bi].bol = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(msgmode & MSG2_PROGNAME) {
|
||||
fprintf(fp, "%s", progname);
|
||||
if(verbose >= MSG_NOTICE && (msgmode & MSG2_FUNCTION))
|
||||
fprintf(fp, " %s()", func);
|
||||
@@ -137,15 +147,6 @@ int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int
|
||||
bols[bi].bol = 0;
|
||||
}
|
||||
|
||||
// Vertical tab at start of format string is a conditional new line
|
||||
if(*format == '\v') {
|
||||
format++;
|
||||
if(!bols[bi].bol) {
|
||||
fprintf(fp, "\n");
|
||||
bols[bi].bol = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out whether this print will leave us at beginning of line
|
||||
|
||||
// Determine required size first
|
||||
@@ -512,7 +513,6 @@ static int suggest_programmers(const char *programmer, LISTID programmers) {
|
||||
}
|
||||
|
||||
static void programmer_not_found(const char *programmer, PROGRAMMER *pgm, int pmode) {
|
||||
msg_error("\v");
|
||||
if(!programmer || !*programmer) {
|
||||
pmsg_error("no programmer has been specified on the command line or in the\n");
|
||||
imsg_error("config file(s); specify one using the -c option and try again\n");
|
||||
@@ -520,7 +520,7 @@ static void programmer_not_found(const char *programmer, PROGRAMMER *pgm, int pm
|
||||
}
|
||||
|
||||
if(str_eq(programmer, "?")) {
|
||||
msg_error("Valid programmers are:\n");
|
||||
lmsg_error("Valid programmers are:\n");
|
||||
list_programmers(stderr, " ", programmers, ~0);
|
||||
msg_error("\n");
|
||||
return;
|
||||
@@ -543,7 +543,7 @@ static void programmer_not_found(const char *programmer, PROGRAMMER *pgm, int pm
|
||||
}
|
||||
}
|
||||
if(pmatches) {
|
||||
msg_error("%s is not a unique start of a programmer name; consider:\n", programmer);
|
||||
pmsg_error("%s is not a unique start of a programmer name; consider:\n", programmer);
|
||||
for(LNODEID ln1=lfirst(programmers); ln1; ln1=lnext(ln1)) {
|
||||
PROGRAMMER *pg = ldata(ln1);
|
||||
if(is_programmer(pg) && (pg->prog_modes & pmode))
|
||||
@@ -1142,7 +1142,7 @@ int main(int argc, char * argv [])
|
||||
list_available_serialports(programmers);
|
||||
exit(0);
|
||||
} else if(str_eq(port, "?sa")) {
|
||||
msg_error("\vValid serial adapters are:\n");
|
||||
lmsg_error("Valid serial adapters are:\n");
|
||||
list_serialadapters(stderr, " ", programmers);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1495,7 +1495,7 @@ skipopen:
|
||||
programmer_display(pgm, progbuf);
|
||||
}
|
||||
|
||||
msg_info("\v");
|
||||
lmsg_info("");
|
||||
|
||||
exitrc = 0;
|
||||
|
||||
|
||||
@@ -447,11 +447,10 @@ void list_serialadapters(FILE *fp, const char *prefix, LISTID programmers) {
|
||||
}
|
||||
|
||||
void serialadapter_not_found(const char *sea_id) {
|
||||
msg_error("\v");
|
||||
if(sea_id && *sea_id)
|
||||
pmsg_error("cannot find serial adapter id %s\n", sea_id);
|
||||
|
||||
msg_error("\nValid serial adapters are:\n");
|
||||
lmsg_error("\nValid serial adapters are:\n");
|
||||
list_serialadapters(stderr, " ", programmers);
|
||||
msg_error("\n");
|
||||
}
|
||||
|
||||
53
src/term.c
53
src/term.c
@@ -349,7 +349,7 @@ static int cmd_dump(const PROGRAMMER *pgm, const AVRPART *p, int argc, const cha
|
||||
report_progress(1, 1, NULL);
|
||||
|
||||
hexdump_buf(stdout, mem, read_mem[i].addr, buf, read_mem[i].len);
|
||||
term_out("\v");
|
||||
lterm_out("");
|
||||
|
||||
free(buf);
|
||||
|
||||
@@ -598,7 +598,7 @@ static int cmd_write(const PROGRAMMER *pgm, const AVRPART *p, int argc, const ch
|
||||
len + bytes_grown, str_plural(len + bytes_grown), addr);
|
||||
if (write_mode == WRITE_MODE_FILL && filling)
|
||||
msg_notice2("; remaining space filled with %s", argv[argc - 2]);
|
||||
msg_notice2("\v");
|
||||
msg_notice2("\n");
|
||||
|
||||
report_progress(0, 1, avr_has_paged_access(pgm, mem)? "Caching": "Writing");
|
||||
for (i = 0; i < len + bytes_grown; i++) {
|
||||
@@ -1904,7 +1904,7 @@ static int cmd_part(const PROGRAMMER *pgm, const AVRPART *p, int argc, const cha
|
||||
avr_mem_display(stdout, p, "");
|
||||
avr_variants_display(stdout, p, "");
|
||||
}
|
||||
term_out("\v");
|
||||
lterm_out("");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1968,7 +1968,7 @@ static int cmd_parms(const PROGRAMMER *pgm, const AVRPART *p, int argc, const ch
|
||||
}
|
||||
|
||||
pgm->print_parms(pgm, stdout);
|
||||
term_out("\v");
|
||||
lterm_out("");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2549,7 +2549,7 @@ static void term_gotline(char *cmdstr) {
|
||||
}
|
||||
} else {
|
||||
// End of file or terminal ^D
|
||||
term_out("\v");
|
||||
lterm_out("");
|
||||
cmd_quit(term_pgm, term_p, 0, NULL);
|
||||
term_running = 0;
|
||||
}
|
||||
@@ -2665,11 +2665,11 @@ static int cmd_include(const PROGRAMMER *pgm, const AVRPART *p, int argc, const
|
||||
if(verbose > 0)
|
||||
term_out("%d: ", lineno);
|
||||
term_out("%s", buffer);
|
||||
term_out("\v");
|
||||
lterm_out("");
|
||||
}
|
||||
if(process_line(buffer, pgm, p) < 0)
|
||||
rc = -1;
|
||||
term_out("\v");
|
||||
lterm_out("");
|
||||
}
|
||||
if(errstr) {
|
||||
pmsg_error("(include) read error in file %s: %s\n", argv[1], errstr);
|
||||
@@ -2681,26 +2681,44 @@ static int cmd_include(const PROGRAMMER *pgm, const AVRPART *p, int argc, const
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ASCII progress bar
|
||||
*
|
||||
* A 50 character bar is gradually filled with hash marks (#) to indicate
|
||||
* progress, and completed with hyphen (-) once an error occurred:
|
||||
*
|
||||
* Reading | ############################## | 59% 0.41 s
|
||||
*
|
||||
* Reading | ###############################------------------- | 61% 0.42 s
|
||||
*
|
||||
* First non-NULL heading hdr starts reporting, percent=100 stops reporting;
|
||||
* etime is the wall-clock time in seconds that the task has taken so for;
|
||||
* finish can take on three values:
|
||||
* -1 task ended in error, show the last valid percentage and fill
|
||||
* progress bar with hyphens instead of hashes
|
||||
* 0 do not terminate progress bar with \n when finishing at 100 percent
|
||||
* 1 terminate progress bar with \n when finishing at 100 percent
|
||||
*/
|
||||
static void update_progress_tty(int percent, double etime, const char *hdr, int finish) {
|
||||
static char *header;
|
||||
static int last, done = 1;
|
||||
int i;
|
||||
|
||||
setvbuf(stderr, (char *) NULL, _IONBF, 0);
|
||||
setvbuf(stderr, (char *) NULL, _IONBF, 0); // Set stderr to be ubuffered
|
||||
|
||||
if(hdr) {
|
||||
msg_info("\v");
|
||||
last = done = 0;
|
||||
lmsg_info(""); // Print new line unless already done before
|
||||
last = done = 0; // OK, we have a header, start reporting
|
||||
if(header)
|
||||
free(header);
|
||||
header = cfg_strdup("update_progress_tty()", hdr);
|
||||
header = cfg_strdup(__func__, hdr);
|
||||
}
|
||||
|
||||
percent = percent > 100? 100: percent < 0? 0: percent;
|
||||
|
||||
if(!done) {
|
||||
if(!header)
|
||||
header = cfg_strdup("update_progress_tty()", "report");
|
||||
header = cfg_strdup(__func__, "report");
|
||||
|
||||
int showperc = finish >= 0? percent: last;
|
||||
|
||||
@@ -2710,16 +2728,17 @@ static void update_progress_tty(int percent, double etime, const char *hdr, int
|
||||
hashes[i/2] = '#';
|
||||
hashes[50] = 0;
|
||||
|
||||
// Overwrite line using \r
|
||||
msg_info("\r%s | %s | %d%% %0.2f s ", header, hashes, showperc, etime);
|
||||
if(percent == 100) {
|
||||
if(finish)
|
||||
msg_info("\v");
|
||||
done = 1;
|
||||
lmsg_info("");
|
||||
done = 1; // Stop future reporting
|
||||
}
|
||||
}
|
||||
last = percent;
|
||||
|
||||
setvbuf(stderr, (char *) NULL, _IOLBF, 0);
|
||||
setvbuf(stderr, (char *) NULL, _IOLBF, 0); // Set stderr to be line buffered
|
||||
}
|
||||
|
||||
static void update_progress_no_tty(int percent, double etime, const char *hdr, int finish) {
|
||||
@@ -2730,7 +2749,7 @@ static void update_progress_no_tty(int percent, double etime, const char *hdr, i
|
||||
percent = percent > 100? 100: percent < 0? 0: percent;
|
||||
|
||||
if(hdr) {
|
||||
msg_info("\v%s | ", hdr);
|
||||
lmsg_info("%s | ", hdr);
|
||||
last = done = 0;
|
||||
}
|
||||
|
||||
@@ -2741,7 +2760,7 @@ static void update_progress_no_tty(int percent, double etime, const char *hdr, i
|
||||
if(percent == 100) {
|
||||
msg_info(" | %d%% %0.2fs", finish >= 0? 100: last, etime);
|
||||
if(finish)
|
||||
msg_info("\v");
|
||||
lmsg_info("");
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ int do_op(const PROGRAMMER *pgm, const AVRPART *p, const UPDATE *upd, enum updat
|
||||
Filestats fs, fs_patched;
|
||||
char *tofree;
|
||||
|
||||
msg_info("\v\n");
|
||||
lmsg_info("\n"); // Ensure an empty line for visual separation of operations
|
||||
pmsg_info("processing %s\n", tofree = update_str(upd));
|
||||
free(tofree);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user