-static void
-print_percentage (long bytes, long expected)
-{
- int percentage = (int)(100.0 * bytes / expected);
- logprintf (LOG_VERBOSE, "%3d%%", percentage);
-}
-
-/* Show the dotted progress report of file loading. Called with
- length and a flag to tell it whether to reset or not. It keeps the
- offset information in static local variables.
-
- Return value: 1 or 0, designating whether any dots have been drawn.
-
- If the init argument is set, the routine will initialize.
-
- If the res is non-zero, res/line_bytes lines are skipped
- (meaning the appropriate number ok kilobytes), and the number of
- "dots" fitting on the first line are drawn as ','. */
-static int
-show_progress (long res, long expected, enum spflags flags)
-{
- static long line_bytes;
- static long offs, initial_skip;
- static int ndot, nrow;
- static long last_timer, time_offset;
- int any_output = 0;
-
- if (flags == SP_FINISH)
- {
- if (expected)
- {
- int dot = ndot;
- char *tmpstr = (char *)alloca (2 * opt.dots_in_line + 1);
- char *tmpp = tmpstr;
- time_offset = elapsed_time () - last_timer;
- for (; dot < opt.dots_in_line; dot++)
- {
- if (!(dot % opt.dot_spacing))
- *tmpp++ = ' ';
- *tmpp++ = ' ';
- }
- *tmpp = '\0';
- logputs (LOG_VERBOSE, tmpstr);
- print_percentage (nrow * line_bytes + ndot * opt.dot_bytes + offs,
- expected);
- logprintf (LOG_VERBOSE, " @%s",
- rate (ndot * opt.dot_bytes
- + offs - (initial_skip % line_bytes),
- time_offset, 1));
- }
- logputs (LOG_VERBOSE, "\n\n");
- return 0;
- }
-
- /* Temporarily disable flushing. */
- opt.no_flush = 1;
- /* init set means initialization. If res is set, it also means that
- the retrieval is *not* done from the beginning. The part that
- was already retrieved is not shown again. */
- if (flags == SP_INIT)
- {
- /* Generic initialization of static variables. */
- offs = 0L;
- ndot = nrow = 0;
- line_bytes = (long)opt.dots_in_line * opt.dot_bytes;
- last_timer = elapsed_time ();
- time_offset = 0;
- initial_skip = res;
- if (res)
- {
- if (res >= line_bytes)
- {
- nrow = res / line_bytes;
- res %= line_bytes;
- logprintf (LOG_VERBOSE,
- _("\n [ skipping %dK ]"),
- (int) ((nrow * line_bytes) / 1024));
- ndot = 0;
- }
- }
- logprintf (LOG_VERBOSE, "\n%5ldK", nrow * line_bytes / 1024);
- }
- /* Offset gets incremented by current value. */
- offs += res;
- /* While offset is >= opt.dot_bytes, print dots, taking care to
- precede every 50th dot with a status message. */
- for (; offs >= opt.dot_bytes; offs -= opt.dot_bytes)
- {
- if (!(ndot % opt.dot_spacing))
- logputs (LOG_VERBOSE, " ");
- any_output = 1;
- logputs (LOG_VERBOSE, flags == SP_INIT ? "," : ".");
- ++ndot;
- if (ndot == opt.dots_in_line)
- {
- time_offset = elapsed_time () - last_timer;
- last_timer += time_offset;