* src/buffer.c (format_total_stats): The format arg is const
All uses updated.
(default_total_format): const
* src/checkpoint.c (tty, tty_cleanup): New static.
(format_checkpoint_string): New "canned" format %c
(checkpoint_finish): New function.
* src/common.h (checkpoint_finish): New proto.
* src/tar.c (main): Call checkpoint_finish.`
from the archive), EOL is a delimiter to add at the end of the output
line. */
int
from the archive), EOL is a delimiter to add at the end of the output
line. */
int
-format_total_stats (FILE *fp, char **formats, int eor, int eol)
+format_total_stats (FILE *fp, const char **formats, int eor, int eol)
-char *default_total_format[] = {
+const char *default_total_format[] = {
N_("Total bytes read"),
/* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
N_("Total bytes written"),
N_("Total bytes read"),
/* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
N_("Total bytes written"),
checkpoint_option = DEFAULT_CHECKPOINT;
}
checkpoint_option = DEFAULT_CHECKPOINT;
}
-static char *checkpoint_total_format[] = {
+static const char *checkpoint_total_format[] = {
"R",
"W",
"D"
};
static int
"R",
"W",
"D"
};
static int
-static void
-format_checkpoint_string (FILE *fp, const char *input, bool do_write,
+static const char *def_format = "%s: %t: %T%*\r";
+
+static int
+format_checkpoint_string (FILE *fp, size_t len,
+ const char *input, bool do_write,
unsigned cpn)
{
const char *opstr = do_write ? gettext ("write") : gettext ("read");
char uintbuf[UINTMAX_STRSIZE_BOUND];
char *cps = STRINGIFY_BIGINT (cpn, uintbuf);
const char *ip;
unsigned cpn)
{
const char *opstr = do_write ? gettext ("write") : gettext ("read");
char uintbuf[UINTMAX_STRSIZE_BOUND];
char *cps = STRINGIFY_BIGINT (cpn, uintbuf);
const char *ip;
static char *argbuf = NULL;
static size_t arglen = 0;
static char *argbuf = NULL;
static size_t arglen = 0;
+ case 'c':
+ len += format_checkpoint_string (fp, len, def_format, do_write,
+ cpn);
+ break;
+
case 'u':
fputs (cps, fp);
len += strlen (cps);
case 'u':
fputs (cps, fp);
len += strlen (cps);
{
struct timeval tv;
struct tm *tm;
{
struct timeval tv;
struct tm *tm;
- char *fmt = arg ? arg : "%c";
+ const char *fmt = arg ? arg : "%c";
gettimeofday (&tv, NULL);
tm = localtime (&tv.tv_sec);
gettimeofday (&tv, NULL);
tm = localtime (&tv.tv_sec);
{
fputc (*ip, fp);
if (*ip == '\r')
{
fputc (*ip, fp);
if (*ip == '\r')
+ {
+ len = 0;
+ tty_cleanup = 1;
+ }
else
len++;
}
}
fflush (fp);
else
len++;
}
}
fflush (fp);
+static FILE *tty = NULL;
+
static void
run_checkpoint_actions (bool do_write)
{
struct checkpoint_action *p;
static void
run_checkpoint_actions (bool do_write)
{
struct checkpoint_action *p;
for (p = checkpoint_action; p; p = p->next)
{
for (p = checkpoint_action; p; p = p->next)
{
- fprintf (stderr, "%s: ", program_name);
- format_checkpoint_string (stderr, p->v.command, do_write, checkpoint);
- fputc ('\n', stderr);
+ {
+ int n = fprintf (stderr, "%s: ", program_name);
+ format_checkpoint_string (stderr, n, p->v.command, do_write,
+ checkpoint);
+ fputc ('\n', stderr);
+ }
break;
case cop_ttyout:
if (!tty)
tty = fopen ("/dev/tty", "w");
if (tty)
break;
case cop_ttyout:
if (!tty)
tty = fopen ("/dev/tty", "w");
if (tty)
- {
- format_checkpoint_string (tty, p->v.command, do_write,
- checkpoint);
- fflush (tty);
- }
+ format_checkpoint_string (tty, 0, p->v.command, do_write,
+ checkpoint);
print_total_stats ();
}
}
print_total_stats ();
}
}
+}
+
+static void
+finish_checkpoint_actions (void)
+{
+ struct checkpoint_action *p;
+
+ for (p = checkpoint_action; p; p = p->next)
+ {
+ switch (p->opcode)
+ {
+ case cop_ttyout:
+ if (tty && tty_cleanup)
+ {
+ int w = getwidth (tty);
+ while (w--)
+ fputc (' ', tty);
+ fputc ('\r', tty);
+ }
+ break;
+ default:
+ /* nothing */;
+ }
+ }
if (checkpoint_option && !(++checkpoint % checkpoint_option))
run_checkpoint_actions (do_write);
}
if (checkpoint_option && !(++checkpoint % checkpoint_option))
run_checkpoint_actions (do_write);
}
+
+void
+checkpoint_finish (void)
+{
+ if (checkpoint_option)
+ finish_checkpoint_actions ();
+}
#define TF_READ 0
#define TF_WRITE 1
#define TF_DELETED 2
#define TF_READ 0
#define TF_WRITE 1
#define TF_DELETED 2
-int format_total_stats (FILE *fp, char **formats, int eor, int eol);
+int format_total_stats (FILE *fp, const char **formats, int eor, int eol);
void print_total_stats (void);
void mv_begin_write (const char *file_name, off_t totsize, off_t sizeleft);
void print_total_stats (void);
void mv_begin_write (const char *file_name, off_t totsize, off_t sizeleft);
void checkpoint_compile_action (const char *str);
void checkpoint_finish_compile (void);
void checkpoint_run (bool do_write);
void checkpoint_compile_action (const char *str);
void checkpoint_finish_compile (void);
void checkpoint_run (bool do_write);
+void checkpoint_finish (void);
/* Module warning.c */
#define WARN_ALONE_ZERO_BLOCK 0x00000001
/* Module warning.c */
#define WARN_ALONE_ZERO_BLOCK 0x00000001
+ checkpoint_finish ();
+
if (totals_option)
print_total_stats ();
if (totals_option)
print_total_stats ();