Skip to content
Snippets Groups Projects
Commit 0380de97 authored by Fredrik Noring's avatar Fredrik Noring
Browse files

New progress system. Stderr is redirected to a file called dumpmodule.log.

Rev: src/dumpmodule.pike:1.13
parent 012c916c
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,60 @@ string fakeroot(string s)
#define fakeroot(X) X
#endif
class ProgressBar
{
private constant width = 45;
private float phase_base, phase_size;
private int max, cur;
private string name;
void set_current(int _cur)
{
cur = _cur;
}
void set_phase(float _phase_base, float _phase_size)
{
phase_base = _phase_base;
phase_size = _phase_size;
}
void update(int increment)
{
cur += increment;
cur = min(cur, max);
float ratio = phase_base + ((float)cur/(float)max) * phase_size;
if(1.0 < ratio)
ratio = 1.0;
int bar = (int)(ratio * (float)width);
int is_full = (bar == width);
write("\r %-13s |%s%c%s%s %4.1f %% ",
name+":",
"="*bar,
is_full ? '|' : ({ '\\', '|', '/', '-' })[cur & 3],
is_full ? "" : " "*(width-bar-1),
is_full ? "" : "|",
100.0 * ratio);
}
void create(string _name, int _cur, int _max,
float|void _phase_base, float|void _phase_size)
/* NOTE: max must be greater than zero. */
{
name = _name;
max = _max;
cur = _cur;
phase_base = _phase_base || 0.0;
phase_size = _phase_size || 1.0 - phase_base;
}
}
ProgressBar progress_bar;
#define error(X) throw( ({ (X), backtrace() }) )
......@@ -231,30 +283,11 @@ void dumpit(string file)
}
}
constant progress_width = 45;
int progress_bar = 0;
int progress_offset = 0;
int progress_max = 0;
void update_progress(string name, int cur, int max)
{
float ratio = (float)cur/(float)max;
int bar = (int)(ratio * (float)progress_width);
int is_full = bar == progress_width;
werror("\r %s: |%s%c%s%s %4.1f %% ",
name,
"="*bar,
is_full ? '|' : ({ '\\', '|', '/', '-' })[cur & 3],
is_full ? "" : " "*(progress_width-bar-1),
is_full ? "" : "|",
100.0 * ratio);
}
int main(int argc, string *argv)
{
/* Redirect all debug and error messages to a logfile. */
Stdio.File("dumpmodule.log", "caw")->dup2(Stdio.stderr);
foreach( (array)all_constants(), [string name, mixed func])
function_names[func]="efun:"+name;
......@@ -290,8 +323,9 @@ int main(int argc, string *argv)
quiet = 2;
logfile = Stdio.File("dumpmodule.log","caw");
progress_bar = 1;
sscanf(argv[1], "%d,%d", progress_offset, progress_max);
progress_bar = ProgressBar("Precompiling",
@array_sscanf(argv[1], "%d,%d"),
0.2, 0.8);
argv = argv[2..];
}
......@@ -299,7 +333,7 @@ int main(int argc, string *argv)
foreach(argv, string file)
{
if(progress_bar)
update_progress("Precompiling", progress_offset++, progress_max);
progress_bar->update(1);
dumpit(file);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment