1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Updated the console screen driver.

committer: mfx <mfx> 968571822 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2000-09-10 07:43:42 +00:00
parent ce00884d1e
commit 46b10df26d
3 changed files with 34 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* c_screen.cpp -- screen driver console output /* c_screen.cpp -- console screen driver
This file is part of the UPX executable compressor. This file is part of the UPX executable compressor.
@ -91,6 +91,8 @@ static void do_destroy(void)
{ {
if (screen) if (screen)
{ {
if (screen->atExit)
screen->atExit();
screen->destroy(screen); screen->destroy(screen);
screen = NULL; screen = NULL;
} }
@ -107,11 +109,22 @@ static int cur_bg = -1;
static int init(FILE *f, int o, int now) static int init(FILE *f, int o, int now)
{ {
int fd = fileno(f); int fd = fileno(f);
int n = CON_INIT; int n;
UNUSED(now); UNUSED(now);
assert(screen == NULL); assert(screen == NULL);
atexit(do_destroy);
if (o == CON_SCREEN)
n = CON_SCREEN;
else if (o == CON_INIT) /* use by default */
n = CON_SCREEN;
else if (o == CON_ANSI_COLOR) /* can emulate ANSI color */
n = CON_ANSI_COLOR;
else if (o == CON_ANSI_MONO) /* can emulate ANSI mono */
n = CON_ANSI_MONO;
else
return CON_INIT;
#if defined(__DJGPP__) #if defined(__DJGPP__)
if (!screen) if (!screen)
screen = do_construct(screen_djgpp2_construct(),fd); screen = do_construct(screen_djgpp2_construct(),fd);
@ -130,23 +143,14 @@ static int init(FILE *f, int o, int now)
#endif #endif
if (!screen) if (!screen)
return CON_INIT; return CON_INIT;
mode = screen->getMode(screen); mode = screen->getMode(screen);
init_fg = cur_fg = screen->getFg(screen); init_fg = cur_fg = screen->getFg(screen);
init_bg = cur_bg = screen->getBg(screen); init_bg = cur_bg = screen->getBg(screen);
if (screen->isMono(screen)) if (screen->isMono(screen))
cur_fg = -1; cur_fg = -1;
if (o == CON_SCREEN) atexit(do_destroy);
n = CON_SCREEN;
if (o == CON_INIT) /* use by default */
n = CON_SCREEN;
if (o == CON_ANSI_COLOR) /* can emulate ANSI color */
n = CON_ANSI_COLOR;
if (o == CON_ANSI_MONO) /* can emulate ANSI mono */
n = CON_ANSI_MONO;
if (screen->atExit)
atexit(screen->atExit);
return n; return n;
} }
@ -185,8 +189,6 @@ static void print0(FILE *f, const char *ss)
{ {
int cx, cy; int cx, cy;
int c_cx, c_cy; int c_cx, c_cy;
char p[256+1];
int pi = 0, px = -1, py = -1;
const int sx = screen->getCols(screen); const int sx = screen->getCols(screen);
const int sy = screen->getRows(screen); const int sy = screen->getRows(screen);
int pass; int pass;
@ -200,6 +202,9 @@ static void print0(FILE *f, const char *ss)
for (pass = 0; pass < 2; pass++) for (pass = 0; pass < 2; pass++)
{ {
const char *s = ss; const char *s = ss;
// char buffer for pass == 1
char p[256+1];
int pi = 0, px = -1, py = -1;
for (;;) for (;;)
{ {
@ -227,8 +232,9 @@ static void print0(FILE *f, const char *ss)
} }
if (pass > 0) if (pass > 0)
{ {
if (pi > 0 && py != c_cy) if (pi > 0 && (*s == 0 || py != c_cy))
{ {
p[pi] = 0;
screen->putString(screen,p,px,py); screen->putString(screen,p,px,py);
pi = 0; pi = 0;
} }
@ -242,15 +248,17 @@ static void print0(FILE *f, const char *ss)
} }
} }
if (!*s) if (*s == 0)
break; break;
if (pass > 0) if (pass > 0)
{ {
if (pi == 0) if (pi == 0)
px = c_cx, py = c_cy; {
px = c_cx;
py = c_cy;
}
p[pi++] = *s; p[pi++] = *s;
p[pi] = 0;
} }
c_cx++; c_cx++;
s++; s++;
@ -271,8 +279,7 @@ static void print0(FILE *f, const char *ss)
c_cy = cy; c_cy = cy;
} }
} }
if (pi > 0)
screen->putString(screen,p,px,py);
screen->setCursor(screen,c_cx,c_cy); screen->setCursor(screen,c_cx,c_cy);
screen->refresh(screen); screen->refresh(screen);
} }

View File

@ -48,7 +48,11 @@ void init_options(struct options_t *o)
o->backup = -1; o->backup = -1;
o->overlay = -1; o->overlay = -1;
#if defined(__MFX_DOS) || defined(__MFX_WIN)
o->console = CON_INIT; o->console = CON_INIT;
#else
o->console = CON_FILE;
#endif
o->verbose = 2; o->verbose = 2;
o->w32pe.compress_exports = 1; o->w32pe.compress_exports = 1;
@ -704,7 +708,6 @@ static const struct mfx_option longopts[] =
{"no-color", 0, 0, 512}, {"no-color", 0, 0, 512},
{"mono", 0, 0, 513}, {"mono", 0, 0, 513},
{"color", 0, 0, 514}, {"color", 0, 0, 514},
//{"intro", 0, 0, 515},
// compression method // compression method
{"2b", 0x10, 0, 702}, // --2b {"2b", 0x10, 0, 702}, // --2b

View File

@ -395,6 +395,7 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
(void) con_fg(stdout,fg); (void) con_fg(stdout,fg);
fflush(stdout); fflush(stdout);
printSetNl(1); printSetNl(1);
UNUSED(fg);
return; return;
} }