Sat May 4 10:23:38 2002 Michael Jennings (mej)

Ran reformat-code on the tree.

Also merged in Azundris' Escreen patch.  It's disabled by default for
the moment pending further testing, but you can enable it manually by
defining ESCREEN.


SVN revision: 6202
This commit is contained in:
Michael Jennings 2002-05-04 14:25:30 +00:00
parent 43bd347fbb
commit 92ca20bcba
40 changed files with 18704 additions and 16443 deletions

View File

@ -4624,3 +4624,11 @@ Mon Apr 29 21:18:20 2002 Michael Jennings (mej)
Fixed the --install option which hasn't worked for ages.
----------------------------------------------------------------------
Sat May 4 10:23:38 2002 Michael Jennings (mej)
Ran reformat-code on the tree.
Also merged in Azundris' Escreen patch. It's disabled by default for
the moment pending further testing, but you can enable it manually by
defining ESCREEN.
----------------------------------------------------------------------

View File

@ -613,7 +613,14 @@ setuid root to do this.
.BI \-e " command" ", \-\-exec " command
Execute
.I command
rather than a shell.
rather than a shell. Forces Eterm mode.
.TP
.BI \-U " URL" ", \-\-url " URL
Pick up a "screen" session at
.I URL
rather than a local one. URLs look like so (screen://user@host.dom/options),
with all parts optional, defaulting to current user at localhost,
respectively. Forces Escreen mode, overrides \-\-exec.
.SH THEMES

View File

@ -3,8 +3,8 @@
for i in *.c src/*.c utils/*.c ; do
if test -f $i; then
echo Reformatting $i
indent -bap -br -ce -ci4 -cli2 -cs -di1 -i2 -l140 -lp -lps -nbc -npcs -nss -nsob -psl $i
indent -bap -br -ce -ci4 -cli2 -cs -di1 -i4 -l140 -lp -lps -nbc -npcs -nss -nsob -psl $i
fi
done
perl -p -i.bak -e 's/(\w+)_t (\*+)\s+/$1_t ($2)/g;' */*.[ch]
perl -p -i.bak -e 's/(\w+)_t (\*+)\s+/$1_t $2/g;' */*.[ch]

View File

@ -14,7 +14,7 @@ libEterm_la_SOURCES = actions.c actions.h buttons.c buttons.h command.c
screen.h script.c script.h scrollbar.c scrollbar.h \
startup.c startup.h system.c system.h term.c term.h \
timer.c timer.h utmp.c windows.c windows.h defaultfont.c \
defaultfont.h
defaultfont.h libscream.c scream.h screamcfg.h
EXTRA_libEterm_la_SOURCES = $(MMX_SRCS)

123
src/README.Escreen Normal file
View File

@ -0,0 +1,123 @@
ESCREEN
1 - What is it?
Eterm now offers you to compile in experimental support for the
"screen" program. "screen" is a terminal multiplexer (one window,
several shells). Yes, it's like konsole or multi-gnome-terminal,
only that your shells won't die just because X or the Window Manager
do. Oh, and you can pick up your home session from work, and vice
versa. And several people can connect to the same session at once,
and...
You get this picture -- if you're a power-user, this is for you.
Also, if you're not a power-user, this is *not* for you. It's alpha.
It's experimental. Reported bugs will get fixed where possible, but
there can be no newbie support at this time.
2 - How do I get it?
You already have all you need. Now, compile with ESCREEN defined in
the DEFS in src/Makefile.
If you don't know how to do that, sorry, but you're not Escreen's
intended audience at this point; please hold on.
Oh, and you also need the screen program. In our tests, we used
$ screen -version
Screen version 3.09.11 (FAU) 14-Feb-02
3 - How do I start it?
If you call it an Eterm, it will behave like one. Same for an Escreen.
(ln -s Eterm Escreen; ./Escreen).
Additionally, when called with a command-line (-e "/some/program"), the
suite will *always* behave like an Eterm, even if invoked as Escreen.
Likewise, when called with an URL (-U "screen://user@some.host.gov/"),
it will behave like an Escreen, even if invoked under another name.
4 - What should I expect from it? (subject to change)
An Eterm should open with a screen (without a status-line) running
inside of it. There should be a button-bar in the Eterm enumerating
the multiplexed terminal (you usually start with one). If you normally
don't use a button-bar, Escreen will create one for you. Otherwise, it
will add buttons to your existing bar.
5 - What should I expect in the future? (TODO)
* Limited support for scrolling. screen doesn't give us all the info
we'd need to make this really sexy. There will likely be limited
support for screen (we need to keep this, it will be what we'll find
on remote machine), and possibly support for enhanced screen-clones
(like the perchance forthcoming "scream").
* Support for ".screenrc". This was temporarily disabled to aid in
debugging and will soon return in conjunction with
* Escreen accepting non-default key setups and
* menus for "screen"-functions so those unfamiliar with the program
will not need to learn a dozen arcance key-sequences (or even get
used to ^A meaning something new).
9 - FAQ
Q I don't see any buttons!
A Debian-users reported this before, and it is presumed to be a problem
with the terminfo-data. Call up Eterm (or xterm, or whatnot). *Then*
call up "screen" from inside that terminal. Is the last line inverted?
If it isn'T, something is seriously weird with your setup, and it's not
a problem in Escreen. Sorry. : (
Q ^A does funny things!
A Well, yes. ^A talks to the screen program. You will be able to move
that to a key of your choice with the next release.
Q I'd like for the button labels to be in a different colour.
A At this time, the labels follow the general (text) colours.
You will be able to define colours for (foreground|background|active|bell)
windows' labels in later releases.
Q Escreen opens, then closes again.
A Escreen cannot run "screen". If you do have "screen", and it is in
the search path, screen apparently terminates right away. Normally
this means that your screen-sessions are messed up; "screen -ls" will
give you a list of them; "screen -wipe" will do the cleaning up.
NOTE: If this happens with a remote session, the remote end might just
find our terminal type confusing. The "--term-name" option with some-
thing vanilla (--term-name vt100) should remedy this.
Q "screen" support rocks! Can we have it in konsole/multi-gnome-terminal?
A I will not attempt anything like that before I am happy with Escreen.
The code, however, is GPL'd, and its use is documented by example of
Eterm. If you can work with that, do.
Q Who's responsible for this?
A Escreen is an Eterm extension conceived and written by Azundris.
Do not complain to KainX (who courteously added the patch for the
enjoyment of the hardy) if you break your Eterm by compiling this
in (or by trying to use the alpha-functionality). By using this,
you agree that anything happening while or because of using it is
your fault, and your fault only.
-- Azundris 2002/05/03 <escreen@azundris.com> http://www.azundris.com/

View File

@ -48,214 +48,213 @@ action_t *action_list = NULL;
unsigned char
action_handle_string(event_t *ev, action_t *action)
{
USE_VAR(ev);
REQUIRE_RVAL(action->param.string != NULL, 0);
cmd_write((unsigned char *) action->param.string, strlen(action->param.string));
return 1;
USE_VAR(ev);
REQUIRE_RVAL(action->param.string != NULL, 0);
cmd_write((unsigned char *) action->param.string, strlen(action->param.string));
return 1;
}
unsigned char
action_handle_echo(event_t *ev, action_t *action)
{
USE_VAR(ev);
REQUIRE_RVAL(action->param.string != NULL, 0);
tt_write((unsigned char *) action->param.string, strlen(action->param.string));
return 1;
USE_VAR(ev);
REQUIRE_RVAL(action->param.string != NULL, 0);
tt_write((unsigned char *) action->param.string, strlen(action->param.string));
return 1;
}
unsigned char
action_handle_script(event_t *ev, action_t *action)
{
USE_VAR(ev);
REQUIRE_RVAL(action->param.script != NULL, 0);
script_parse(action->param.script);
return 1;
USE_VAR(ev);
REQUIRE_RVAL(action->param.script != NULL, 0);
script_parse(action->param.script);
return 1;
}
unsigned char
action_handle_menu(event_t *ev, action_t *action)
{
REQUIRE_RVAL(action->param.menu != NULL, 0);
menu_invoke(ev->xbutton.x, ev->xbutton.y, TermWin.parent, action->param.menu, ev->xbutton.time);
return 1;
REQUIRE_RVAL(action->param.menu != NULL, 0);
menu_invoke(ev->xbutton.x, ev->xbutton.y, TermWin.parent, action->param.menu, ev->xbutton.time);
return 1;
}
action_t *
action_find_match(unsigned short mod, unsigned char button, KeySym keysym)
action_t *action_find_match(unsigned short mod, unsigned char button, KeySym keysym)
{
action_t *action;
action_t *action;
D_ACTIONS(("mod == 0x%08x, button == %d, keysym == 0x%08x\n", mod, button, keysym));
for (action = action_list; action; action = action->next) {
D_ACTIONS(("Checking action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym));
if ((action->mod == mod) && (action->button == button) && (action->keysym == keysym)) {
D_ACTIONS(("Match found at %8p\n", action));
return action;
D_ACTIONS(("mod == 0x%08x, button == %d, keysym == 0x%08x\n", mod, button, keysym));
for (action = action_list; action; action = action->next) {
D_ACTIONS(("Checking action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym));
if ((action->mod == mod) && (action->button == button) && (action->keysym == keysym)) {
D_ACTIONS(("Match found at %8p\n", action));
return action;
}
}
}
return NULL;
return NULL;
}
unsigned char
action_check_button(unsigned char button, int x_button)
{
/* The event we're looking at is a button press. Make sure the
current action is also, and that it matches. Continue if not. */
D_ACTIONS(("Checking button %d vs x_button %d\n", button, x_button));
if (button == BUTTON_NONE) {
/* It was a button press, and this action is not a button action. */
return FALSE;
}
if ((button != BUTTON_ANY) && (button != x_button)) {
/* It's a specific button, and the two don't match. */
return FALSE;
}
D_ACTIONS(("Button match confirmed.\n"));
return TRUE;
/* The event we're looking at is a button press. Make sure the
current action is also, and that it matches. Continue if not. */
D_ACTIONS(("Checking button %d vs x_button %d\n", button, x_button));
if (button == BUTTON_NONE) {
/* It was a button press, and this action is not a button action. */
return FALSE;
}
if ((button != BUTTON_ANY) && (button != x_button)) {
/* It's a specific button, and the two don't match. */
return FALSE;
}
D_ACTIONS(("Button match confirmed.\n"));
return TRUE;
}
unsigned char
action_check_keysym(KeySym keysym, KeySym x_keysym)
{
/* The event we're looking at is a key press. Make sure the
current action is also, and that it matches. Continue if not. */
D_ACTIONS(("Checking keysym 0x%08x vs x_keysym 0x%08x\n", keysym, x_keysym));
if (keysym == None) {
return FALSE;
} else if (keysym != x_keysym) {
return FALSE;
}
D_ACTIONS(("Keysym match confirmed.\n"));
return TRUE;
/* The event we're looking at is a key press. Make sure the
current action is also, and that it matches. Continue if not. */
D_ACTIONS(("Checking keysym 0x%08x vs x_keysym 0x%08x\n", keysym, x_keysym));
if (keysym == None) {
return FALSE;
} else if (keysym != x_keysym) {
return FALSE;
}
D_ACTIONS(("Keysym match confirmed.\n"));
return TRUE;
}
unsigned char
action_check_modifiers(unsigned short mod, int x_mod)
{
unsigned int m = (AltMask | MetaMask | NumLockMask);
unsigned int m = (AltMask | MetaMask | NumLockMask);
/* When we do have to check the modifiers, we do so in this order to eliminate the
most popular choices first. If any test fails, we return FALSE. */
D_ACTIONS(("Checking modifier set 0x%08x (" MOD_FMT ") vs. X modifier set 0x%08x (" MOD_FMT ")\n",
mod, SHOW_MODS(mod), x_mod, SHOW_X_MODS(x_mod)));
if (mod != MOD_ANY) {
/* LOGICAL_XOR() returns true if either the first parameter or the second parameter
is true, but not both...just like XOR. If the mask we're looking for is set in
mod but not in x_mod, or set in x_mod but not in mod, we don't have a match. */
if (LOGICAL_XOR((mod & MOD_CTRL), (x_mod & ControlMask))) {
return FALSE;
/* When we do have to check the modifiers, we do so in this order to eliminate the
most popular choices first. If any test fails, we return FALSE. */
D_ACTIONS(("Checking modifier set 0x%08x (" MOD_FMT ") vs. X modifier set 0x%08x (" MOD_FMT ")\n",
mod, SHOW_MODS(mod), x_mod, SHOW_X_MODS(x_mod)));
if (mod != MOD_ANY) {
/* LOGICAL_XOR() returns true if either the first parameter or the second parameter
is true, but not both...just like XOR. If the mask we're looking for is set in
mod but not in x_mod, or set in x_mod but not in mod, we don't have a match. */
if (LOGICAL_XOR((mod & MOD_CTRL), (x_mod & ControlMask))) {
return FALSE;
}
if (LOGICAL_XOR((mod & MOD_SHIFT), (x_mod & ShiftMask))) {
return FALSE;
}
if (MetaMask != AltMask) {
if (LOGICAL_XOR((mod & MOD_ALT), (x_mod & AltMask))) {
return FALSE;
}
if (LOGICAL_XOR((mod & MOD_META), (x_mod & MetaMask))) {
return FALSE;
}
} else {
if (LOGICAL_XOR((mod & (MOD_META | MOD_ALT)), (x_mod & (MetaMask | AltMask)))) {
return FALSE;
}
}
if (LOGICAL_XOR((mod & MOD_LOCK), (x_mod & LockMask))) {
return FALSE;
}
/* These tests can't use LOGICAL_XOR because the second test has an additional
restriction that the Mod?Mask cannot be set in m; i.e., we want to ignore
any Mod?Mask assigned to Alt, Meta, or the NumLock On state. */
if (((mod & MOD_MOD1) && !(x_mod & Mod1Mask)) || (!(mod & MOD_MOD1) && (x_mod & Mod1Mask) && !(Mod1Mask & m))) {
return FALSE;
}
if (((mod & MOD_MOD2) && !(x_mod & Mod2Mask)) || (!(mod & MOD_MOD2) && (x_mod & Mod2Mask) && !(Mod2Mask & m))) {
return FALSE;
}
if (((mod & MOD_MOD3) && !(x_mod & Mod3Mask)) || (!(mod & MOD_MOD3) && (x_mod & Mod3Mask) && !(Mod3Mask & m))) {
return FALSE;
}
if (((mod & MOD_MOD4) && !(x_mod & Mod4Mask)) || (!(mod & MOD_MOD4) && (x_mod & Mod4Mask) && !(Mod4Mask & m))) {
return FALSE;
}
if (((mod & MOD_MOD5) && !(x_mod & Mod5Mask)) || (!(mod & MOD_MOD5) && (x_mod & Mod5Mask) && !(Mod5Mask & m))) {
return FALSE;
}
}
if (LOGICAL_XOR((mod & MOD_SHIFT), (x_mod & ShiftMask))) {
return FALSE;
}
if (MetaMask != AltMask) {
if (LOGICAL_XOR((mod & MOD_ALT), (x_mod & AltMask))) {
return FALSE;
}
if (LOGICAL_XOR((mod & MOD_META), (x_mod & MetaMask))) {
return FALSE;
}
} else {
if (LOGICAL_XOR((mod & (MOD_META | MOD_ALT)), (x_mod & (MetaMask | AltMask)))) {
return FALSE;
}
}
if (LOGICAL_XOR((mod & MOD_LOCK), (x_mod & LockMask))) {
return FALSE;
}
/* These tests can't use LOGICAL_XOR because the second test has an additional
restriction that the Mod?Mask cannot be set in m; i.e., we want to ignore
any Mod?Mask assigned to Alt, Meta, or the NumLock On state. */
if (((mod & MOD_MOD1) && !(x_mod & Mod1Mask)) || (!(mod & MOD_MOD1) && (x_mod & Mod1Mask) && !(Mod1Mask & m))) {
return FALSE;
}
if (((mod & MOD_MOD2) && !(x_mod & Mod2Mask)) || (!(mod & MOD_MOD2) && (x_mod & Mod2Mask) && !(Mod2Mask & m))) {
return FALSE;
}
if (((mod & MOD_MOD3) && !(x_mod & Mod3Mask)) || (!(mod & MOD_MOD3) && (x_mod & Mod3Mask) && !(Mod3Mask & m))) {
return FALSE;
}
if (((mod & MOD_MOD4) && !(x_mod & Mod4Mask)) || (!(mod & MOD_MOD4) && (x_mod & Mod4Mask) && !(Mod4Mask & m))) {
return FALSE;
}
if (((mod & MOD_MOD5) && !(x_mod & Mod5Mask)) || (!(mod & MOD_MOD5) && (x_mod & Mod5Mask) && !(Mod5Mask & m))) {
return FALSE;
}
}
D_ACTIONS(("Modifier match confirmed.\n"));
return TRUE;
D_ACTIONS(("Modifier match confirmed.\n"));
return TRUE;
}
unsigned char
action_dispatch(event_t *ev, KeySym keysym)
{
action_t *action;
action_t *action;
ASSERT_RVAL(ev != NULL, 0);
ASSERT_RVAL(ev->xany.type == ButtonPress || ev->xany.type == KeyPress, 0);
D_ACTIONS(("Event %8p: Button %d, Keysym 0x%08x, Key State 0x%08x (modifiers " MOD_FMT ")\n",
ev, ev->xbutton.button, keysym, ev->xkey.state, SHOW_X_MODS(ev->xkey.state)));
for (action = action_list; action; action = action->next) {
/* The very first thing we do is match the event type to the type
of the current action. This means that we'll only run through
the modifier checks below if we absolutely have to. */
if ((ev->xany.type == ButtonPress && action_check_button(action->button, ev->xbutton.button))
|| (ev->xany.type == KeyPress && action_check_keysym(action->keysym, keysym))) {
if (action_check_modifiers(action->mod, ev->xkey.state)) {
D_ACTIONS(("Match found.\n"));
/* If we've passed all the above tests, it's a match. Dispatch the handler. */
return ((action->handler)(ev, action));
}
ASSERT_RVAL(ev != NULL, 0);
ASSERT_RVAL(ev->xany.type == ButtonPress || ev->xany.type == KeyPress, 0);
D_ACTIONS(("Event %8p: Button %d, Keysym 0x%08x, Key State 0x%08x (modifiers " MOD_FMT ")\n",
ev, ev->xbutton.button, keysym, ev->xkey.state, SHOW_X_MODS(ev->xkey.state)));
for (action = action_list; action; action = action->next) {
/* The very first thing we do is match the event type to the type
of the current action. This means that we'll only run through
the modifier checks below if we absolutely have to. */
if ((ev->xany.type == ButtonPress && action_check_button(action->button, ev->xbutton.button))
|| (ev->xany.type == KeyPress && action_check_keysym(action->keysym, keysym))) {
if (action_check_modifiers(action->mod, ev->xkey.state)) {
D_ACTIONS(("Match found.\n"));
/* If we've passed all the above tests, it's a match. Dispatch the handler. */
return ((action->handler) (ev, action));
}
}
}
}
return (0);
return (0);
}
void
action_add(unsigned short mod, unsigned char button, KeySym keysym, action_type_t type, void *param) {
action_add(unsigned short mod, unsigned char button, KeySym keysym, action_type_t type, void *param)
{
action_t *action;
action_t *action;
if (!action_list || (action = action_find_match(mod, button, keysym)) == NULL) {
action = (action_t *) MALLOC(sizeof(action_t));
action->next = action_list;
action_list = action;
} else {
if (action->type == ACTION_STRING || action->type == ACTION_ECHO || action->type == ACTION_SCRIPT) {
if (action->param.string) {
FREE(action->param.string);
}
if (!action_list || (action = action_find_match(mod, button, keysym)) == NULL) {
action = (action_t *) MALLOC(sizeof(action_t));
action->next = action_list;
action_list = action;
} else {
if (action->type == ACTION_STRING || action->type == ACTION_ECHO || action->type == ACTION_SCRIPT) {
if (action->param.string) {
FREE(action->param.string);
}
}
}
}
action->mod = mod;
action->button = button;
action->type = type;
action->keysym = keysym;
switch(type) {
case ACTION_STRING:
action->handler = (action_handler_t) action_handle_string;
action->param.string = (char *) MALLOC(strlen((char *) param) + 2);
strcpy(action->param.string, (char *) param);
parse_escaped_string(action->param.string);
break;
case ACTION_ECHO:
action->handler = (action_handler_t) action_handle_echo;
action->param.string = (char *) MALLOC(strlen((char *) param) + 2);
strcpy(action->param.string, (char *) param);
parse_escaped_string(action->param.string);
break;
case ACTION_SCRIPT:
action->handler = (action_handler_t) action_handle_script;
action->param.script = (char *) MALLOC(strlen((char *) param) + 2);
strcpy(action->param.script, (char *) param);
break;
case ACTION_MENU:
action->handler = (action_handler_t) action_handle_menu;
action->param.menu = (menu_t *) param;
break;
default:
break;
}
D_ACTIONS(("Added action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym));
action->mod = mod;
action->button = button;
action->type = type;
action->keysym = keysym;
switch (type) {
case ACTION_STRING:
action->handler = (action_handler_t) action_handle_string;
action->param.string = (char *) MALLOC(strlen((char *) param) + 2);
strcpy(action->param.string, (char *) param);
parse_escaped_string(action->param.string);
break;
case ACTION_ECHO:
action->handler = (action_handler_t) action_handle_echo;
action->param.string = (char *) MALLOC(strlen((char *) param) + 2);
strcpy(action->param.string, (char *) param);
parse_escaped_string(action->param.string);
break;
case ACTION_SCRIPT:
action->handler = (action_handler_t) action_handle_script;
action->param.script = (char *) MALLOC(strlen((char *) param) + 2);
strcpy(action->param.script, (char *) param);
break;
case ACTION_MENU:
action->handler = (action_handler_t) action_handle_menu;
action->param.menu = (menu_t *) param;
break;
default:
break;
}
D_ACTIONS(("Added action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym));
}

View File

@ -67,8 +67,7 @@ draw_string(buttonbar_t *bbar, Drawable d, GC gc, int x, int y, char *str, size_
return;
}
buttonbar_t *
bbar_create(void)
buttonbar_t *bbar_create(void)
{
buttonbar_t *bbar;
Cursor cursor;
@ -185,7 +184,8 @@ bbar_handle_enter_notify(event_t *ev)
return 0;
}
bbar_draw(bbar, IMAGE_STATE_SELECTED, 0);
XQueryPointer(Xdisplay, bbar->win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y), &unused_mask);
XQueryPointer(Xdisplay, bbar->win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y),
&unused_mask);
b = find_button_by_coords(bbar, ev->xbutton.x, ev->xbutton.y);
if (b) {
bbar_select_button(bbar, b);
@ -248,7 +248,8 @@ bbar_handle_button_release(event_t *ev)
return 0;
}
XQueryPointer(Xdisplay, bbar->win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y), &unused_mask);
XQueryPointer(Xdisplay, bbar->win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y),
&unused_mask);
b = find_button_by_coords(bbar, ev->xbutton.x, ev->xbutton.y);
if (b) {
@ -280,7 +281,8 @@ bbar_handle_motion_notify(event_t *ev)
return 0;
}
while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, MotionNotify, ev));
XQueryPointer(Xdisplay, bbar->win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y), &mask);
XQueryPointer(Xdisplay, bbar->win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y),
&mask);
D_BBAR((" -> Pointer is at %d, %d with mask 0x%08x\n", ev->xbutton.x, ev->xbutton.y, mask));
b = find_button_by_coords(bbar, ev->xbutton.x, ev->xbutton.y);
@ -309,8 +311,7 @@ bbar_dispatch_event(event_t *ev)
return (0);
}
buttonbar_t *
find_bbar_by_window(Window win)
buttonbar_t *find_bbar_by_window(Window win)
{
buttonbar_t *bbar;
@ -494,7 +495,8 @@ button_calc_size(buttonbar_t *bbar, button_t *button)
D_BBAR((" -> Final icon dimensions are %hux%hu\n", button->icon_w, button->icon_h));
}
#endif
D_BBAR((" -> Set button to %dx%d at %d, %d and icon to %dx%d\n", button->w, button->h, button->x, button->y, button->icon_w, button->icon_h));
D_BBAR((" -> Set button to %dx%d at %d, %d and icon to %dx%d\n", button->w, button->h, button->x, button->y, button->icon_w,
button->icon_h));
}
void
@ -542,7 +544,7 @@ bbar_add_button(buttonbar_t *bbar, button_t *button)
D_BBAR(("bbar_add_button(%8p, %8p): Adding button \"%s\".\n", bbar, button, button->text));
if (bbar->buttons) {
if (bbar->buttons) {
for (b = bbar->buttons; b->next; b = b->next);
b->next = button;
} else {
@ -570,7 +572,8 @@ bbar_set_font(buttonbar_t *bbar, const char *fontname)
ASSERT_RVAL(fontname != NULL, 0);
D_BBAR(("bbar_set_font(%8p, \"%s\"): Current font is %8p, dimensions %d/%d/%d\n", bbar, fontname, bbar->font, bbar->fwidth, bbar->fheight, bbar->h));
D_BBAR(("bbar_set_font(%8p, \"%s\"): Current font is %8p, dimensions %d/%d/%d\n", bbar, fontname, bbar->font, bbar->fwidth,
bbar->fheight, bbar->h));
if (bbar->font) {
free_font(bbar->font);
}
@ -595,8 +598,7 @@ bbar_set_font(buttonbar_t *bbar, const char *fontname)
return 1;
}
button_t *
find_button_by_text(buttonbar_t *bbar, char *text)
button_t *find_button_by_text(buttonbar_t *bbar, char *text)
{
register button_t *b;
@ -615,8 +617,7 @@ find_button_by_text(buttonbar_t *bbar, char *text)
return NULL;
}
button_t *
find_button_by_coords(buttonbar_t *bbar, int x, int y)
button_t *find_button_by_coords(buttonbar_t *bbar, int x, int y)
{
register button_t *b;
@ -635,8 +636,7 @@ find_button_by_coords(buttonbar_t *bbar, int x, int y)
return NULL;
}
button_t *
button_create(char *text)
button_t *button_create(char *text)
{
button_t *button;
@ -688,21 +688,21 @@ button_set_action(button_t *button, action_type_t type, char *action)
button->type = type;
switch (type) {
case ACTION_MENU:
button->action.menu = find_menu_by_title(menu_list, action);
break;
case ACTION_STRING:
case ACTION_ECHO:
button->action.string = (char *) MALLOC(strlen(action) + 2);
strcpy(button->action.string, action);
parse_escaped_string(button->action.string);
break;
case ACTION_SCRIPT:
button->action.script = (char *) MALLOC(strlen(action) + 2);
strcpy(button->action.script, action);
break;
default:
break;
case ACTION_MENU:
button->action.menu = find_menu_by_title(menu_list, action);
break;
case ACTION_STRING:
case ACTION_ECHO:
button->action.string = (char *) MALLOC(strlen(action) + 2);
strcpy(button->action.string, action);
parse_escaped_string(button->action.string);
break;
case ACTION_SCRIPT:
button->action.script = (char *) MALLOC(strlen(action) + 2);
strcpy(button->action.script, action);
break;
default:
break;
}
return 1;
}
@ -749,7 +749,8 @@ bbar_click_button(buttonbar_t *bbar, button_t *button)
if (image_mode_is(image_button, MODE_MASK)) {
paste_simage(images[image_button].clicked, image_button, bbar->win, bbar->win, button->x, button->y, button->w, button->h);
} else {
draw_shadow_from_colors(bbar->win, PixColors[menuBottomShadowColor], PixColors[menuTopShadowColor], button->x, button->y, button->w, button->h, 2);
draw_shadow_from_colors(bbar->win, PixColors[menuBottomShadowColor], PixColors[menuTopShadowColor], button->x, button->y, button->w,
button->h, 2);
}
if (image_mode_is(image_button, MODE_AUTO)) {
enl_ipc_sync();
@ -768,28 +769,28 @@ void
button_check_action(buttonbar_t *bbar, button_t *button, unsigned char press, Time t)
{
switch (button->type) {
case ACTION_MENU:
if (press) {
menu_invoke(button->x, button->y + button->h, bbar->win, button->action.menu, t);
}
break;
case ACTION_STRING:
if (!press) {
cmd_write((unsigned char *) button->action.string, strlen(button->action.string));
}
break;
case ACTION_ECHO:
if (!press) {
tt_write((unsigned char *) button->action.string, strlen(button->action.string));
}
break;
case ACTION_SCRIPT:
if (!press) {
script_parse((char *) button->action.script);
}
break;
default:
break;
case ACTION_MENU:
if (press) {
menu_invoke(button->x, button->y + button->h, bbar->win, button->action.menu, t);
}
break;
case ACTION_STRING:
if (!press) {
cmd_write((unsigned char *) button->action.string, strlen(button->action.string));
}
break;
case ACTION_ECHO:
if (!press) {
tt_write((unsigned char *) button->action.string, strlen(button->action.string));
}
break;
case ACTION_SCRIPT:
if (!press) {
script_parse((char *) button->action.script);
}
break;
default:
break;
}
}
@ -898,7 +899,19 @@ bbar_draw(buttonbar_t *bbar, unsigned char image_state, unsigned char force_mode
paste_simage(button->icon, image_max, bbar->win, bbar->bg, button->icon_x, button->icon_y, button->icon_w, button->icon_h);
}
if (button->len) {
draw_string(bbar, bbar->bg, bbar->gc, button->text_x, button->text_y, button->text, button->len);
#ifdef ESCREEN
GC gc; /* evil temporary hack */
XGCValues gcvalue;
gcvalue.foreground = PixColors[button->flags + 2];
gcvalue.font = bbar->font->fid;
if (button->flags && (gc = LIBAST_X_CREATE_GC(GCForeground | GCFont, &gcvalue))) {
draw_string(bbar, bbar->bg, gc, button->text_x, button->text_y, button->text, button->len);
XFreeGC(Xdisplay, gc);
} else
#endif
draw_string(bbar, bbar->bg, bbar->gc, button->text_x, button->text_y, button->text, button->len);
}
}
for (button = bbar->rbuttons; button; button = button->next) {
@ -965,8 +978,7 @@ bbar_calc_positions(void)
bbar->y = top_y;
top_y += bbar->h;
}
D_BBAR(("Set coordinates for buttonbar %8p (window 0x%08x) to %lu, %lu\n",
bbar, bbar->win, bbar->x, bbar->y));
D_BBAR(("Set coordinates for buttonbar %8p (window 0x%08x) to %lu, %lu\n", bbar, bbar->win, bbar->x, bbar->y));
if (TermWin.parent != None) {
XReparentWindow(Xdisplay, bbar->win, TermWin.parent, bbar->x, bbar->y);
XMoveResizeWindow(Xdisplay, bbar->win, bbar->x, bbar->y, bbar->w, bbar->h);

View File

@ -70,6 +70,9 @@ typedef struct button_struct {
unsigned short x, y, w, h;
unsigned short text_x, text_y;
unsigned short icon_x, icon_y, icon_w, icon_h;
#ifdef ESCREEN
int flags;
#endif
struct button_struct *next;
} button_t;

File diff suppressed because it is too large Load Diff

View File

@ -23,37 +23,37 @@
*/
const struct name2encoding n2e[] = {
#ifdef MULTI_CHARSET
{ "EUCJP", ENC_EUCJ },
{ "UJIS", ENC_EUCJ },
{ "SHIFTJIS", ENC_SJIS },
{ "SJIS", ENC_SJIS },
{ "EUCKR", ENC_EUCKR },
{ "EUCCN", ENC_GB },
{ "GB2312", ENC_GB },
{ "GB", ENC_GB },
{ "BIG5", ENC_BIG5 },
{ "BIGFIVE", ENC_BIG5 },
{ "BIG5HKSCS", ENC_BIG5 },
{ "UTF8", ENC_UTF8 },
#endif /* MULTI_CHARSET */
{ "KOI8R", ENC_KOI8R },
{ "KOI8U", ENC_KOI8U },
{ "ISO88591", ENC_ISO8859_1 },
{ "ISO88592", ENC_ISO8859_2 },
{ "ISO88593", ENC_ISO8859_3 },
{ "ISO88594", ENC_ISO8859_4 },
{ "ISO88595", ENC_ISO8859_5 },
{ "ISO88596", ENC_ISO8859_6 },
{ "ISO88597", ENC_ISO8859_7 },
{ "ISO88598", ENC_ISO8859_8 },
{ "ISO88599", ENC_ISO8859_9 },
{ "ISO885910", ENC_ISO8859_10 },
{ "ISO885911", ENC_ISO8859_11 },
{ "ISO885912", ENC_ISO8859_12 },
{ "ISO885913", ENC_ISO8859_13 },
{ "ISO885914", ENC_ISO8859_14 },
{ "ISO885915", ENC_ISO8859_15 },
{ NULL, ENC_DUMMY }
{"EUCJP", ENC_EUCJ},
{"UJIS", ENC_EUCJ},
{"SHIFTJIS", ENC_SJIS},
{"SJIS", ENC_SJIS},
{"EUCKR", ENC_EUCKR},
{"EUCCN", ENC_GB},
{"GB2312", ENC_GB},
{"GB", ENC_GB},
{"BIG5", ENC_BIG5},
{"BIGFIVE", ENC_BIG5},
{"BIG5HKSCS", ENC_BIG5},
{"UTF8", ENC_UTF8},
#endif /* MULTI_CHARSET */
{"KOI8R", ENC_KOI8R},
{"KOI8U", ENC_KOI8U},
{"ISO88591", ENC_ISO8859_1},
{"ISO88592", ENC_ISO8859_2},
{"ISO88593", ENC_ISO8859_3},
{"ISO88594", ENC_ISO8859_4},
{"ISO88595", ENC_ISO8859_5},
{"ISO88596", ENC_ISO8859_6},
{"ISO88597", ENC_ISO8859_7},
{"ISO88598", ENC_ISO8859_8},
{"ISO88599", ENC_ISO8859_9},
{"ISO885910", ENC_ISO8859_10},
{"ISO885911", ENC_ISO8859_11},
{"ISO885912", ENC_ISO8859_12},
{"ISO885913", ENC_ISO8859_13},
{"ISO885914", ENC_ISO8859_14},
{"ISO885915", ENC_ISO8859_15},
{NULL, ENC_DUMMY}
};
@ -79,49 +79,49 @@ const struct name2encoding n2e[] = {
*/
const struct name2encoding l2e[] = {
#ifdef MULTI_CHARSET
{ "ja_JP.EUC", ENC_EUCJ },
{ "ja_JP", ENC_EUCJ },
{ "ko_KR.EUC", ENC_EUCKR },
{ "ko_KR", ENC_EUCKR },
{ "zh_CN.EUC", ENC_GB },
{ "zh_CN", ENC_GB },
{ "zh_TW", ENC_BIG5 },
#endif /* MULTI_CHARSET */
{ "da", ENC_ISO8859_1 },
{ "de", ENC_ISO8859_1 },
{ "en", ENC_ISO8859_1 },
{ "fi", ENC_ISO8859_1 },
{ "fr", ENC_ISO8859_1 },
{ "is", ENC_ISO8859_1 },
{ "it", ENC_ISO8859_1 },
{ "la", ENC_ISO8859_1 },
{ "lt", ENC_ISO8859_1 },
{ "nl", ENC_ISO8859_1 },
{ "no", ENC_ISO8859_1 },
{ "pt", ENC_ISO8859_1 },
{ "sv", ENC_ISO8859_1 },
{ "cs", ENC_ISO8859_2 },
{ "hr", ENC_ISO8859_2 },
{ "hu", ENC_ISO8859_2 },
{ "la", ENC_ISO8859_2 },
{ "lt", ENC_ISO8859_2 },
{ "pl", ENC_ISO8859_2 },
{ "ro", ENC_ISO8859_2 },
{ "sk", ENC_ISO8859_2 },
{ "sl", ENC_ISO8859_2 },
{ "ar", ENC_ISO8859_6 },
{ "el", ENC_ISO8859_7 },
{ "tr", ENC_ISO8859_9 },
{ "lt", ENC_ISO8859_13 },
{ "lv", ENC_ISO8859_13 },
{ "mi", ENC_ISO8859_13 },
{ "ru", ENC_KOI8R }, /* ISO8859-5 ? */
{ "uk", ENC_KOI8U },
{"ja_JP.EUC", ENC_EUCJ},
{"ja_JP", ENC_EUCJ},
{"ko_KR.EUC", ENC_EUCKR},
{"ko_KR", ENC_EUCKR},
{"zh_CN.EUC", ENC_GB},
{"zh_CN", ENC_GB},
{"zh_TW", ENC_BIG5},
#endif /* MULTI_CHARSET */
{"da", ENC_ISO8859_1},
{"de", ENC_ISO8859_1},
{"en", ENC_ISO8859_1},
{"fi", ENC_ISO8859_1},
{"fr", ENC_ISO8859_1},
{"is", ENC_ISO8859_1},
{"it", ENC_ISO8859_1},
{"la", ENC_ISO8859_1},
{"lt", ENC_ISO8859_1},
{"nl", ENC_ISO8859_1},
{"no", ENC_ISO8859_1},
{"pt", ENC_ISO8859_1},
{"sv", ENC_ISO8859_1},
{"cs", ENC_ISO8859_2},
{"hr", ENC_ISO8859_2},
{"hu", ENC_ISO8859_2},
{"la", ENC_ISO8859_2},
{"lt", ENC_ISO8859_2},
{"pl", ENC_ISO8859_2},
{"ro", ENC_ISO8859_2},
{"sk", ENC_ISO8859_2},
{"sl", ENC_ISO8859_2},
{"ar", ENC_ISO8859_6},
{"el", ENC_ISO8859_7},
{"tr", ENC_ISO8859_9},
{"lt", ENC_ISO8859_13},
{"lv", ENC_ISO8859_13},
{"mi", ENC_ISO8859_13},
{"ru", ENC_KOI8R}, /* ISO8859-5 ? */
{"uk", ENC_KOI8U},
#if 0
{ "vi", ENC_VISCII },
{ "th", ENC_TIS620 },
{"vi", ENC_VISCII},
{"th", ENC_TIS620},
#endif
{ NULL, ENC_DUMMY }
{NULL, ENC_DUMMY}
};
@ -134,34 +134,34 @@ const struct name2encoding l2e[] = {
*/
const struct defaultfont defaultfont[] = {
#ifdef MULTI_CHARSET
{ ENC_EUCJ, "eucj", DEF_EUCJ, {NFONT_LIST_EUCJ}, {MFONT_LIST_EUCJ} },
{ ENC_SJIS, "sjis", DEF_EUCJ, {NFONT_LIST_EUCJ}, {MFONT_LIST_EUCJ} },
{ ENC_GB, "gb", DEF_GB, {NFONT_LIST_GB}, {MFONT_LIST_GB} },
{ ENC_BIG5, "big5", DEF_BIG5, {NFONT_LIST_BIG5}, {MFONT_LIST_BIG5} },
{ ENC_EUCKR, "euckr",DEF_EUCKR, {NFONT_LIST_EUCKR}, {MFONT_LIST_EUCKR} },
{ ENC_UTF8, "iso-10646",DEF_10646,{NFONT_LIST_10646},{MFONT_LIST_10646} },
#endif /* MULTI_CHARSET */
{ ENC_ISO8859_7,"none",DEF_7, {NFONT_LIST_7}, {MFONT_LIST_NULL} },
{ ENC_KOI8R, "none",DEF_KOI8R, {NFONT_LIST_KOI8R}, {MFONT_LIST_NULL} },
{ ENC_KOI8U, "none",DEF_KOI8U, {NFONT_LIST_KOI8U}, {MFONT_LIST_NULL} },
{ ENC_DUMMY, "none",DEF_DUMMY, {MFONT_LIST_NULL}, {MFONT_LIST_NULL} }
{ENC_EUCJ, "eucj", DEF_EUCJ, {NFONT_LIST_EUCJ}, {MFONT_LIST_EUCJ}},
{ENC_SJIS, "sjis", DEF_EUCJ, {NFONT_LIST_EUCJ}, {MFONT_LIST_EUCJ}},
{ENC_GB, "gb", DEF_GB, {NFONT_LIST_GB}, {MFONT_LIST_GB}},
{ENC_BIG5, "big5", DEF_BIG5, {NFONT_LIST_BIG5}, {MFONT_LIST_BIG5}},
{ENC_EUCKR, "euckr", DEF_EUCKR, {NFONT_LIST_EUCKR}, {MFONT_LIST_EUCKR}},
{ENC_UTF8, "iso-10646", DEF_10646, {NFONT_LIST_10646}, {MFONT_LIST_10646}},
#endif /* MULTI_CHARSET */
{ENC_ISO8859_7, "none", DEF_7, {NFONT_LIST_7}, {MFONT_LIST_NULL}},
{ENC_KOI8R, "none", DEF_KOI8R, {NFONT_LIST_KOI8R}, {MFONT_LIST_NULL}},
{ENC_KOI8U, "none", DEF_KOI8U, {NFONT_LIST_KOI8U}, {MFONT_LIST_NULL}},
{ENC_DUMMY, "none", DEF_DUMMY, {MFONT_LIST_NULL}, {MFONT_LIST_NULL}}
};
/* special common rule for ISO-8859-x */
const char *const defaultfont_8859[] = {
NFONT_LIST_ISO8859X
NFONT_LIST_ISO8859X
};
/* fallback defaults */
const int def_def_idx = DEF_10646;
const char *const def_fonts[] = {
NFONT_LIST_10646
NFONT_LIST_10646
};
#ifdef MULTI_CHARSET
const char *const def_mfonts[] = {
MFONT_LIST_10646
MFONT_LIST_10646
};
#endif
@ -170,120 +170,124 @@ const char *const def_mfonts[] = {
void
eterm_default_font_locale(char ***fonts, char ***mfonts, char **mencoding, int *def_idx)
{
char *locale;
char *encoding_str = NULL;
char encoding_buf[ENCODINGBUFLEN];
char *p, *p2;
enum enc_label encoding = ENC_DUMMY;
int j, k;
locale = setlocale(LC_CTYPE, "");
if (locale == NULL)
if ((locale = getenv("LC_ALL")) == NULL)
if ((locale = getenv("LC_CTYPE")) == NULL)
if ((locale = getenv("LANG")) == NULL)
locale = "C"; /* failsafe */
char *locale;
char *encoding_str = NULL;
char encoding_buf[ENCODINGBUFLEN];
char *p, *p2;
enum enc_label encoding = ENC_DUMMY;
int j, k;
/* Obtain a "normalized" name of current encoding.
* The current encoding is available via nl_langinfo().
* Otherwise, it comes from locale name.
*/
locale = setlocale(LC_CTYPE, "");
if (locale == NULL)
if ((locale = getenv("LC_ALL")) == NULL)
if ((locale = getenv("LC_CTYPE")) == NULL)
if ((locale = getenv("LANG")) == NULL)
locale = "C"; /* failsafe */
/* Obtain a "normalized" name of current encoding.
* The current encoding is available via nl_langinfo().
* Otherwise, it comes from locale name.
*/
#ifdef HAVE_NL_LANGINFO
encoding_str = nl_langinfo(CODESET);
encoding_str = nl_langinfo(CODESET);
#else
encoding_str = NULL;
encoding_str = NULL;
#endif
if (encoding_str && *encoding_str) {
for (j = 0; n2e[j].name; j++) {
if (!strcmp(encoding_str, n2e[j].name)) {
encoding = n2e[j].encoding;
break;
}
if (encoding_str && *encoding_str) {
for (j = 0; n2e[j].name; j++) {
if (!strcmp(encoding_str, n2e[j].name)) {
encoding = n2e[j].encoding;
break;
}
}
}
}
if (encoding == ENC_DUMMY) {
p = strchr(locale, '.');
if (p) {
strncpy(encoding_buf, p + 1, ENCODINGBUFLEN);
p = strchr(encoding_buf, '@');
if (p) *p = 0;
} else {
strncpy(encoding_buf, locale, ENCODINGBUFLEN);
if (encoding == ENC_DUMMY) {
p = strchr(locale, '.');
if (p) {
strncpy(encoding_buf, p + 1, ENCODINGBUFLEN);
p = strchr(encoding_buf, '@');
if (p)
*p = 0;
} else {
strncpy(encoding_buf, locale, ENCODINGBUFLEN);
}
encoding_buf[ENCODINGBUFLEN - 1] = 0;
for (p = p2 = encoding_buf; 1; p++, p2++) {
while (*p2 == '_' || *p2 == '-')
p2++;
if (!*p2)
break;
*p = toupper(*p2);
}
*p = 0;
for (j = 0; n2e[j].name; j++) {
if (!strcmp(encoding_buf, n2e[j].name)) {
encoding = n2e[j].encoding;
break;
}
}
}
encoding_buf[ENCODINGBUFLEN - 1] = 0;
for (p = p2 = encoding_buf; 1; p++, p2++) {
while (*p2 == '_' || *p2 == '-') p2++;
if (!*p2) break;
*p = toupper(*p2);
}
*p = 0;
for (j = 0; n2e[j].name; j++) {
if (!strcmp(encoding_buf, n2e[j].name)) {
encoding = n2e[j].encoding;
break;
}
}
}
/* If the conversion fails, try using "language"/"country"
* part of the locale name.
*/
if (encoding == ENC_DUMMY) {
for (j = 0; l2e[j].name; j++) {
if (!strncmp(locale, l2e[j].name, strlen(l2e[j].name))) {
encoding = l2e[j].encoding;
break;
}
/* If the conversion fails, try using "language"/"country"
* part of the locale name.
*/
if (encoding == ENC_DUMMY) {
for (j = 0; l2e[j].name; j++) {
if (!strncmp(locale, l2e[j].name, strlen(l2e[j].name))) {
encoding = l2e[j].encoding;
break;
}
}
}
}
/* Now, the encoding to be used has been determined.
* Fonts and encoding will be determined according to the encoding.
*/
for (j = 0; defaultfont[j].enc_label != ENC_DUMMY; j++) {
if (encoding == defaultfont[j].enc_label) {
*def_idx = defaultfont[j].def_idx;
/* Now, the encoding to be used has been determined.
* Fonts and encoding will be determined according to the encoding.
*/
for (j = 0; defaultfont[j].enc_label != ENC_DUMMY; j++) {
if (encoding == defaultfont[j].enc_label) {
*def_idx = defaultfont[j].def_idx;
#ifdef MULTI_CHARSET
*mencoding = STRDUP(defaultfont[j].encoding_method);
*mencoding = STRDUP(defaultfont[j].encoding_method);
#endif
for (k = 0; k < NFONTS; k++) {
eterm_font_add(fonts, defaultfont[j].font[k], k);
for (k = 0; k < NFONTS; k++) {
eterm_font_add(fonts, defaultfont[j].font[k], k);
#ifdef MULTI_CHARSET
eterm_font_add(mfonts, defaultfont[j].mfont[k], k);
eterm_font_add(mfonts, defaultfont[j].mfont[k], k);
#endif
}
return;
}
return;
}
}
}
/*
* fallback for unknown encodings. ISO-8559-* gets special treatment
*/
#ifdef MULTI_CHARSET
*mencoding = STRDUP("none");
*mencoding = STRDUP("none");
#endif
if (encoding >= ENC_ISO8859_1 && encoding <= ENC_ISO8859_LAST) {
/* fallback for ISO-8859-* encodings */
k = encoding - ENC_ISO8859_1 + 1;
*def_idx = DEF_8859;
} else {
/* fallback for "C", "POSIX", and invalid locales */
k = 0;
*def_idx = def_def_idx;
}
for (j = 0; j < NFONTS; j++) {
if (k == 0) eterm_font_add(fonts, def_fonts[j], j);
else {
/* couple of wasted bytes each but lots of future expansion */
sprintf(encoding_buf, defaultfont_8859[j], k);
eterm_font_add(fonts, encoding_buf, j);
if (encoding >= ENC_ISO8859_1 && encoding <= ENC_ISO8859_LAST) {
/* fallback for ISO-8859-* encodings */
k = encoding - ENC_ISO8859_1 + 1;
*def_idx = DEF_8859;
} else {
/* fallback for "C", "POSIX", and invalid locales */
k = 0;
*def_idx = def_def_idx;
}
for (j = 0; j < NFONTS; j++) {
if (k == 0)
eterm_font_add(fonts, def_fonts[j], j);
else {
/* couple of wasted bytes each but lots of future expansion */
sprintf(encoding_buf, defaultfont_8859[j], k);
eterm_font_add(fonts, encoding_buf, j);
}
#ifdef MULTI_CHARSET
eterm_font_add(mfonts, def_mfonts[j], j);
eterm_font_add(mfonts, def_mfonts[j], j);
#endif
}
}
}
#endif /* AUTO_ENCODING */

View File

@ -35,96 +35,97 @@ void
draw_shadow(Drawable d, GC gc_top, GC gc_bottom, int x, int y, int w, int h, int shadow)
{
ASSERT(w != 0);
ASSERT(h != 0);
LOWER_BOUND(shadow, 1);
ASSERT(w != 0);
ASSERT(h != 0);
LOWER_BOUND(shadow, 1);
for (w += x - 1, h += y - 1; shadow > 0; shadow--, w--, h--) {
XDrawLine(Xdisplay, d, gc_top, x, y, w, y);
XDrawLine(Xdisplay, d, gc_top, x, y, x, h);
x++; y++;
XDrawLine(Xdisplay, d, gc_bottom, w, h, w, y);
XDrawLine(Xdisplay, d, gc_bottom, w, h, x, h);
}
for (w += x - 1, h += y - 1; shadow > 0; shadow--, w--, h--) {
XDrawLine(Xdisplay, d, gc_top, x, y, w, y);
XDrawLine(Xdisplay, d, gc_top, x, y, x, h);
x++;
y++;
XDrawLine(Xdisplay, d, gc_bottom, w, h, w, y);
XDrawLine(Xdisplay, d, gc_bottom, w, h, x, h);
}
}
void
draw_shadow_from_colors(Drawable d, Pixel top, Pixel bottom, int x, int y, int w, int h, int shadow)
{
static GC gc_top = (GC) 0, gc_bottom = (GC) 0;
static GC gc_top = (GC) 0, gc_bottom = (GC) 0;
if (gc_top == 0) {
gc_top = LIBAST_X_CREATE_GC(0, NULL);
gc_bottom = LIBAST_X_CREATE_GC(0, NULL);
}
if (gc_top == 0) {
gc_top = LIBAST_X_CREATE_GC(0, NULL);
gc_bottom = LIBAST_X_CREATE_GC(0, NULL);
}
XSetForeground(Xdisplay, gc_top, top);
XSetForeground(Xdisplay, gc_bottom, bottom);
draw_shadow(d, gc_top, gc_bottom, x, y, w, h, shadow);
XSetForeground(Xdisplay, gc_top, top);
XSetForeground(Xdisplay, gc_bottom, bottom);
draw_shadow(d, gc_top, gc_bottom, x, y, w, h, shadow);
}
void
draw_arrow(Drawable d, GC gc_top, GC gc_bottom, int x, int y, int w, int shadow, unsigned char type)
{
BOUND(shadow, 1, 2);
BOUND(shadow, 1, 2);
switch (type) {
case DRAW_ARROW_UP:
for (; shadow > 0; shadow--, x++, y++, w--) {
XDrawLine(Xdisplay, d, gc_top, x, y + w, x + w / 2, y);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + w, x + w / 2, y);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + w, x, y + w);
}
break;
case DRAW_ARROW_DOWN:
for (; shadow > 0; shadow--, x++, y++, w--) {
XDrawLine(Xdisplay, d, gc_top, x, y, x + w / 2, y + w);
XDrawLine(Xdisplay, d, gc_top, x, y, x + w, y);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y, x + w / 2, y + w);
}
break;
case DRAW_ARROW_LEFT:
for (; shadow > 0; shadow--, x++, y++, w--) {
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + w, x + w, y);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + w, x, y + w / 2);
XDrawLine(Xdisplay, d, gc_top, x, y + w / 2, x + w, y);
}
break;
case DRAW_ARROW_RIGHT:
for (; shadow > 0; shadow--, x++, y++, w--) {
XDrawLine(Xdisplay, d, gc_top, x, y, x, y + w);
XDrawLine(Xdisplay, d, gc_top, x, y, x + w, y + w / 2);
XDrawLine(Xdisplay, d, gc_bottom, x, y + w, x + w, y + w / 2);
}
break;
default:
break;
}
switch (type) {
case DRAW_ARROW_UP:
for (; shadow > 0; shadow--, x++, y++, w--) {
XDrawLine(Xdisplay, d, gc_top, x, y + w, x + w / 2, y);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + w, x + w / 2, y);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + w, x, y + w);
}
break;
case DRAW_ARROW_DOWN:
for (; shadow > 0; shadow--, x++, y++, w--) {
XDrawLine(Xdisplay, d, gc_top, x, y, x + w / 2, y + w);
XDrawLine(Xdisplay, d, gc_top, x, y, x + w, y);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y, x + w / 2, y + w);
}
break;
case DRAW_ARROW_LEFT:
for (; shadow > 0; shadow--, x++, y++, w--) {
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + w, x + w, y);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + w, x, y + w / 2);
XDrawLine(Xdisplay, d, gc_top, x, y + w / 2, x + w, y);
}
break;
case DRAW_ARROW_RIGHT:
for (; shadow > 0; shadow--, x++, y++, w--) {
XDrawLine(Xdisplay, d, gc_top, x, y, x, y + w);
XDrawLine(Xdisplay, d, gc_top, x, y, x + w, y + w / 2);
XDrawLine(Xdisplay, d, gc_bottom, x, y + w, x + w, y + w / 2);
}
break;
default:
break;
}
}
void
draw_arrow_from_colors(Drawable d, Pixel top, Pixel bottom, int x, int y, int w, int shadow, unsigned char type)
{
static GC gc_top = (GC) 0, gc_bottom = (GC) 0;
static GC gc_top = (GC) 0, gc_bottom = (GC) 0;
if (gc_top == 0) {
gc_top = LIBAST_X_CREATE_GC(0, NULL);
gc_bottom = LIBAST_X_CREATE_GC(0, NULL);
}
if (gc_top == 0) {
gc_top = LIBAST_X_CREATE_GC(0, NULL);
gc_bottom = LIBAST_X_CREATE_GC(0, NULL);
}
XSetForeground(Xdisplay, gc_top, top);
XSetForeground(Xdisplay, gc_bottom, bottom);
draw_arrow(d, gc_top, gc_bottom, x, y, w, shadow, type);
XSetForeground(Xdisplay, gc_top, top);
XSetForeground(Xdisplay, gc_bottom, bottom);
draw_arrow(d, gc_top, gc_bottom, x, y, w, shadow, type);
}
void
draw_box(Drawable d, GC gc_top, GC gc_bottom, int x, int y, int w, int h)
{
XDrawLine(Xdisplay, d, gc_top, x + w, y, x, y);
XDrawLine(Xdisplay, d, gc_top, x, y, x, y + h);
XDrawLine(Xdisplay, d, gc_bottom, x, y + h, x + w, y + h);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + h, x + w, y);
XDrawLine(Xdisplay, d, gc_top, x + w, y, x, y);
XDrawLine(Xdisplay, d, gc_top, x, y, x, y + h);
XDrawLine(Xdisplay, d, gc_bottom, x, y + h, x + w, y + h);
XDrawLine(Xdisplay, d, gc_bottom, x + w, y + h, x + w, y);
}
#define SHADE_PIXEL(pixel, dir, tmp) do {(tmp) = ((((double)pixel)/depth_factor) + ((dir) ? 0.2 : -0.2)) * depth_factor; \
@ -134,104 +135,104 @@ draw_box(Drawable d, GC gc_top, GC gc_bottom, int x, int y, int w, int h)
v = ((r & mr) << br) | ((g & mg) << bg) | ((b & mb) >> bb); XPutPixel(ximg, (x), (y), v);} while (0)
void
bevel_pixmap(Pixmap p, int w, int h, Imlib_Border *bord, unsigned char up)
bevel_pixmap(Pixmap p, int w, int h, Imlib_Border * bord, unsigned char up)
{
XImage *ximg;
register unsigned long v;
double dv;
short x, y, xbound, ybound;
unsigned int r, g, b;
int real_depth = 0, depth_factor;
register int br, bg, bb; /* Bitshifts */
register unsigned int mr, mg, mb; /* Bitmasks */
GC gc;
XImage *ximg;
register unsigned long v;
double dv;
short x, y, xbound, ybound;
unsigned int r, g, b;
int real_depth = 0, depth_factor;
register int br, bg, bb; /* Bitshifts */
register unsigned int mr, mg, mb; /* Bitmasks */
GC gc;
if (!bord)
return;
if (!bord)
return;
depth_factor = 1 << Xdepth;
if (Xdepth <= 8) {
D_PIXMAP(("Depth of %d is not supported. Punt!\n", Xdepth));
return;
} else if (Xdepth == 16) {
depth_factor = 1 << Xdepth;
if (Xdepth <= 8) {
D_PIXMAP(("Depth of %d is not supported. Punt!\n", Xdepth));
return;
} else if (Xdepth == 16) {
XWindowAttributes xattr;
XWindowAttributes xattr;
XGetWindowAttributes(Xdisplay, Xroot, &xattr);
if ((xattr.visual->red_mask == 0x7c00) && (xattr.visual->green_mask == 0x3e0) && (xattr.visual->blue_mask == 0x1f)) {
real_depth = 15;
depth_factor = 1 << 15;
XGetWindowAttributes(Xdisplay, Xroot, &xattr);
if ((xattr.visual->red_mask == 0x7c00) && (xattr.visual->green_mask == 0x3e0) && (xattr.visual->blue_mask == 0x1f)) {
real_depth = 15;
depth_factor = 1 << 15;
}
}
}
if (!real_depth) {
real_depth = Xdepth;
}
ximg = XGetImage(Xdisplay, p, 0, 0, w, h, -1, ZPixmap);
if (ximg == NULL) {
return;
}
/* Determine bitshift and bitmask values */
switch (real_depth) {
case 15:
br = 7;
bg = 2;
bb = 3;
mr = mg = mb = 0xf8;
break;
case 16:
br = 8;
bg = bb = 3;
mr = mb = 0xf8;
mg = 0xfc;
break;
case 24:
case 32:
br = 16;
bg = 8;
bb = 0;
mr = mg = mb = 0xff;
break;
default:
return;
}
/* Left edge */
for (y = bord->top; y < h; y++) {
xbound = h - y;
if (xbound > bord->left)
xbound = bord->left;
for (x = 0; x < xbound; x++) {
MOD_PIXEL_HIGH(x, y, up);
if (!real_depth) {
real_depth = Xdepth;
}
}
/* Right edge */
ybound = h - bord->bottom;
for (y = 0; y < ybound; y++) {
xbound = bord->right - y;
if (xbound < 0)
xbound = 0;
for (x = xbound; x < bord->right; x++) {
MOD_PIXEL_HIGH(x + (w - bord->right), y, !up);
ximg = XGetImage(Xdisplay, p, 0, 0, w, h, -1, ZPixmap);
if (ximg == NULL) {
return;
}
}
/* Top edge */
for (y = 0; y < bord->top; y++) {
xbound = w - y;
for (x = 0; x < xbound; x++) {
MOD_PIXEL_HIGH(x, y, up);
/* Determine bitshift and bitmask values */
switch (real_depth) {
case 15:
br = 7;
bg = 2;
bb = 3;
mr = mg = mb = 0xf8;
break;
case 16:
br = 8;
bg = bb = 3;
mr = mb = 0xf8;
mg = 0xfc;
break;
case 24:
case 32:
br = 16;
bg = 8;
bb = 0;
mr = mg = mb = 0xff;
break;
default:
return;
}
}
/* Bottom edge */
for (y = h - bord->bottom; y < h; y++) {
for (x = h - y - 1; x < w; x++) {
MOD_PIXEL_HIGH(x, y, !up);
/* Left edge */
for (y = bord->top; y < h; y++) {
xbound = h - y;
if (xbound > bord->left)
xbound = bord->left;
for (x = 0; x < xbound; x++) {
MOD_PIXEL_HIGH(x, y, up);
}
}
}
gc = LIBAST_X_CREATE_GC(0, NULL);
XPutImage(Xdisplay, p, gc, ximg, 0, 0, 0, 0, w, h);
LIBAST_X_FREE_GC(gc);
XDestroyImage(ximg);
/* Right edge */
ybound = h - bord->bottom;
for (y = 0; y < ybound; y++) {
xbound = bord->right - y;
if (xbound < 0)
xbound = 0;
for (x = xbound; x < bord->right; x++) {
MOD_PIXEL_HIGH(x + (w - bord->right), y, !up);
}
}
/* Top edge */
for (y = 0; y < bord->top; y++) {
xbound = w - y;
for (x = 0; x < xbound; x++) {
MOD_PIXEL_HIGH(x, y, up);
}
}
/* Bottom edge */
for (y = h - bord->bottom; y < h; y++) {
for (x = h - y - 1; x < w; x++) {
MOD_PIXEL_HIGH(x, y, !up);
}
}
gc = LIBAST_X_CREATE_GC(0, NULL);
XPutImage(Xdisplay, p, gc, ximg, 0, 0, 0, 0, w, h);
LIBAST_X_FREE_GC(gc);
XDestroyImage(ximg);
}

322
src/e.c
View File

@ -47,217 +47,217 @@ static unsigned char timeout = 0;
unsigned char
check_for_enlightenment(void)
{
static signed char have_e = -1;
static signed char have_e = -1;
if (have_e == -1) {
if (props[PROP_ENL_COMMS] != None) {
D_ENL(("Enlightenment detected.\n"));
have_e = 1;
} else {
D_ENL(("Enlightenment not detected.\n"));
have_e = 0;
if (have_e == -1) {
if (props[PROP_ENL_COMMS] != None) {
D_ENL(("Enlightenment detected.\n"));
have_e = 1;
} else {
D_ENL(("Enlightenment not detected.\n"));
have_e = 0;
}
}
}
return (have_e);
return (have_e);
}
Window
enl_ipc_get_win(void)
{
unsigned char *str = NULL;
Atom prop;
unsigned long num, after;
int format;
Window dummy_win;
int dummy_int;
unsigned int dummy_uint;
unsigned char *str = NULL;
Atom prop;
unsigned long num, after;
int format;
Window dummy_win;
int dummy_int;
unsigned int dummy_uint;
D_ENL(("Searching for IPC window.\n"));
D_ENL(("Searching for IPC window.\n"));
if (props[PROP_ENL_COMMS] == None) {
D_ENL((" -> Enlightenment is not running. You lose!\n"));
return None;
}
XGetWindowProperty(Xdisplay, Xroot, props[PROP_ENL_COMMS], 0, 14, False, AnyPropertyType, &prop, &format, &num, &after, &str);
if (str) {
sscanf((char *) str, "%*s %x", (unsigned int *) &ipc_win);
XFree(str);
}
if (ipc_win != None) {
if (!XGetGeometry(Xdisplay, ipc_win, &dummy_win, &dummy_int, &dummy_int, &dummy_uint, &dummy_uint, &dummy_uint, &dummy_uint)) {
D_ENL((" -> IPC Window property is valid, but the window doesn't exist. I give up!\n"));
ipc_win = None;
if (props[PROP_ENL_COMMS] == None) {
D_ENL((" -> Enlightenment is not running. You lose!\n"));
return None;
}
XGetWindowProperty(Xdisplay, Xroot, props[PROP_ENL_COMMS], 0, 14, False, AnyPropertyType, &prop, &format, &num, &after, &str);
if (str) {
sscanf((char *) str, "%*s %x", (unsigned int *) &ipc_win);
XFree(str);
}
str = NULL;
if (ipc_win != None) {
XGetWindowProperty(Xdisplay, ipc_win, props[PROP_ENL_COMMS], 0, 14, False, AnyPropertyType, &prop, &format, &num, &after, &str);
if (str) {
XFree(str);
} else {
D_ENL((" -> IPC Window lacks the proper atom. I can't talk to fake IPC windows....\n"));
ipc_win = None;
}
if (!XGetGeometry(Xdisplay, ipc_win, &dummy_win, &dummy_int, &dummy_int, &dummy_uint, &dummy_uint, &dummy_uint, &dummy_uint)) {
D_ENL((" -> IPC Window property is valid, but the window doesn't exist. I give up!\n"));
ipc_win = None;
}
str = NULL;
if (ipc_win != None) {
XGetWindowProperty(Xdisplay, ipc_win, props[PROP_ENL_COMMS], 0, 14, False, AnyPropertyType, &prop, &format, &num, &after, &str);
if (str) {
XFree(str);
} else {
D_ENL((" -> IPC Window lacks the proper atom. I can't talk to fake IPC windows....\n"));
ipc_win = None;
}
}
}
}
if (ipc_win != None) {
D_ENL((" -> IPC Window found and verified as 0x%08x. Registering Eterm as an IPC client.\n", (int) ipc_win));
XSelectInput(Xdisplay, ipc_win, StructureNotifyMask | SubstructureNotifyMask);
enl_ipc_send("set clientname " APL_NAME);
enl_ipc_send("set version " VERSION);
enl_ipc_send("set email mej@eterm.org");
enl_ipc_send("set web http://www.eterm.org/");
enl_ipc_send("set info Eterm Enlightened Terminal Emulator");
}
if (my_ipc_win == None) {
my_ipc_win = XCreateSimpleWindow(Xdisplay, Xroot, -2, -2, 1, 1, 0, 0, 0);
}
return (ipc_win);
if (ipc_win != None) {
D_ENL((" -> IPC Window found and verified as 0x%08x. Registering Eterm as an IPC client.\n", (int) ipc_win));
XSelectInput(Xdisplay, ipc_win, StructureNotifyMask | SubstructureNotifyMask);
enl_ipc_send("set clientname " APL_NAME);
enl_ipc_send("set version " VERSION);
enl_ipc_send("set email mej@eterm.org");
enl_ipc_send("set web http://www.eterm.org/");
enl_ipc_send("set info Eterm Enlightened Terminal Emulator");
}
if (my_ipc_win == None) {
my_ipc_win = XCreateSimpleWindow(Xdisplay, Xroot, -2, -2, 1, 1, 0, 0, 0);
}
return (ipc_win);
}
void
enl_ipc_send(char *str)
{
static char *last_msg = NULL;
char buff[21];
register unsigned short i;
register unsigned char j;
unsigned short len;
XEvent ev;
static char *last_msg = NULL;
char buff[21];
register unsigned short i;
register unsigned char j;
unsigned short len;
XEvent ev;
if (str == NULL) {
ASSERT(last_msg != NULL);
str = last_msg;
D_ENL(("Resending last message \"%s\" to Enlightenment.\n", str));
} else {
if (last_msg != NULL) {
FREE(last_msg);
if (str == NULL) {
ASSERT(last_msg != NULL);
str = last_msg;
D_ENL(("Resending last message \"%s\" to Enlightenment.\n", str));
} else {
if (last_msg != NULL) {
FREE(last_msg);
}
last_msg = STRDUP(str);
D_ENL(("Sending \"%s\" to Enlightenment.\n", str));
}
last_msg = STRDUP(str);
D_ENL(("Sending \"%s\" to Enlightenment.\n", str));
}
if (ipc_win == None) {
if ((ipc_win = enl_ipc_get_win()) == None) {
D_ENL(("...or perhaps not, since Enlightenment doesn't seem to be running. No IPC window, no IPC. Sorry....\n"));
return;
if (ipc_win == None) {
if ((ipc_win = enl_ipc_get_win()) == None) {
D_ENL(("...or perhaps not, since Enlightenment doesn't seem to be running. No IPC window, no IPC. Sorry....\n"));
return;
}
}
}
len = strlen(str);
for (; XCheckTypedWindowEvent(Xdisplay, my_ipc_win, ClientMessage, &ev);); /* Discard any out-of-sync messages */
ev.xclient.type = ClientMessage;
ev.xclient.serial = 0;
ev.xclient.send_event = True;
ev.xclient.window = ipc_win;
ev.xclient.message_type = props[PROP_ENL_MSG];
ev.xclient.format = 8;
len = strlen(str);
for (; XCheckTypedWindowEvent(Xdisplay, my_ipc_win, ClientMessage, &ev);); /* Discard any out-of-sync messages */
ev.xclient.type = ClientMessage;
ev.xclient.serial = 0;
ev.xclient.send_event = True;
ev.xclient.window = ipc_win;
ev.xclient.message_type = props[PROP_ENL_MSG];
ev.xclient.format = 8;
for (i = 0; i < len + 1; i += 12) {
sprintf(buff, "%8x", (int) my_ipc_win);
for (j = 0; j < 12; j++) {
buff[8 + j] = str[i + j];
if (!str[i + j]) {
break;
}
for (i = 0; i < len + 1; i += 12) {
sprintf(buff, "%8x", (int) my_ipc_win);
for (j = 0; j < 12; j++) {
buff[8 + j] = str[i + j];
if (!str[i + j]) {
break;
}
}
buff[20] = 0;
for (j = 0; j < 20; j++) {
ev.xclient.data.b[j] = buff[j];
}
XSendEvent(Xdisplay, ipc_win, False, 0, (XEvent *) & ev);
}
buff[20] = 0;
for (j = 0; j < 20; j++) {
ev.xclient.data.b[j] = buff[j];
}
XSendEvent(Xdisplay, ipc_win, False, 0, (XEvent *) & ev);
}
D_ENL(("Message sent to IPC window 0x%08x.\n", ipc_win));
D_ENL(("Message sent to IPC window 0x%08x.\n", ipc_win));
}
static RETSIGTYPE
enl_ipc_timeout(int sig)
{
timeout = 1;
SIG_RETURN(sig);
sig = 0;
timeout = 1;
SIG_RETURN(sig);
sig = 0;
}
char *
enl_wait_for_reply(void)
{
XEvent ev;
static char msg_buffer[20];
register unsigned char i;
XEvent ev;
static char msg_buffer[20];
register unsigned char i;
alarm(3);
for (; !XCheckTypedWindowEvent(Xdisplay, my_ipc_win, ClientMessage, &ev) && !timeout;);
alarm(0);
if (ev.xany.type != ClientMessage) {
return (IPC_TIMEOUT);
}
for (i = 0; i < 20; i++) {
msg_buffer[i] = ev.xclient.data.b[i];
}
return (msg_buffer + 8);
alarm(3);
for (; !XCheckTypedWindowEvent(Xdisplay, my_ipc_win, ClientMessage, &ev) && !timeout;);
alarm(0);
if (ev.xany.type != ClientMessage) {
return (IPC_TIMEOUT);
}
for (i = 0; i < 20; i++) {
msg_buffer[i] = ev.xclient.data.b[i];
}
return (msg_buffer + 8);
}
char *
enl_ipc_get(const char *msg_data)
{
static char *message = NULL;
static unsigned short len = 0;
char buff[13], *ret_msg = NULL;
register unsigned char i;
unsigned char blen;
static char *message = NULL;
static unsigned short len = 0;
char buff[13], *ret_msg = NULL;
register unsigned char i;
unsigned char blen;
if (msg_data == IPC_TIMEOUT) {
return (IPC_TIMEOUT);
}
for (i = 0; i < 12; i++) {
buff[i] = msg_data[i];
}
buff[12] = 0;
blen = strlen(buff);
if (message != NULL) {
len += blen;
message = (char *) REALLOC(message, len + 1);
strcat(message, buff);
} else {
len = blen;
message = (char *) MALLOC(len + 1);
strcpy(message, buff);
}
if (blen < 12) {
ret_msg = message;
message = NULL;
D_ENL(("Received complete reply: \"%s\"\n", ret_msg));
}
return (ret_msg);
if (msg_data == IPC_TIMEOUT) {
return (IPC_TIMEOUT);
}
for (i = 0; i < 12; i++) {
buff[i] = msg_data[i];
}
buff[12] = 0;
blen = strlen(buff);
if (message != NULL) {
len += blen;
message = (char *) REALLOC(message, len + 1);
strcat(message, buff);
} else {
len = blen;
message = (char *) MALLOC(len + 1);
strcpy(message, buff);
}
if (blen < 12) {
ret_msg = message;
message = NULL;
D_ENL(("Received complete reply: \"%s\"\n", ret_msg));
}
return (ret_msg);
}
char *
enl_send_and_wait(char *msg)
{
char *reply = IPC_TIMEOUT;
eterm_sighandler_t old_alrm;
char *reply = IPC_TIMEOUT;
eterm_sighandler_t old_alrm;
if (ipc_win == None) {
/* The IPC window is missing. Wait for it to return or Eterm to be killed. */
for (; enl_ipc_get_win() == None;) {
sleep(1);
if (ipc_win == None) {
/* The IPC window is missing. Wait for it to return or Eterm to be killed. */
for (; enl_ipc_get_win() == None;) {
sleep(1);
}
}
}
old_alrm = (eterm_sighandler_t) signal(SIGALRM, (eterm_sighandler_t) enl_ipc_timeout);
for (; reply == IPC_TIMEOUT;) {
timeout = 0;
enl_ipc_send(msg);
for (; !(reply = enl_ipc_get(enl_wait_for_reply())););
if (reply == IPC_TIMEOUT) {
/* We timed out. The IPC window must be AWOL. Reset and resend message. */
D_ENL(("IPC timed out. IPC window 0x%08x has gone AWOL. Clearing ipc_win.\n", ipc_win));
XSelectInput(Xdisplay, ipc_win, None);
ipc_win = None;
(void) check_image_ipc(1);
old_alrm = (eterm_sighandler_t) signal(SIGALRM, (eterm_sighandler_t) enl_ipc_timeout);
for (; reply == IPC_TIMEOUT;) {
timeout = 0;
enl_ipc_send(msg);
for (; !(reply = enl_ipc_get(enl_wait_for_reply())););
if (reply == IPC_TIMEOUT) {
/* We timed out. The IPC window must be AWOL. Reset and resend message. */
D_ENL(("IPC timed out. IPC window 0x%08x has gone AWOL. Clearing ipc_win.\n", ipc_win));
XSelectInput(Xdisplay, ipc_win, None);
ipc_win = None;
(void) check_image_ipc(1);
}
}
}
signal(SIGALRM, old_alrm);
return (reply);
signal(SIGALRM, old_alrm);
return (reply);
}

View File

@ -47,195 +47,193 @@ enc_context_t *encoder = NULL;
static enc_context_t builtin_context_cyrillic, builtin_context_greek_elot_928, builtin_context_greek_ibm_437;
static trans_table_t in_table_iso_8859_5 = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xae, 0xfe, 0xf1, 0x20, 0xb3, 0x20, 0xfd, 0xa1, 0x20, 0xa4, 0x8b, 0x20, 0x20, 0x20, 0xa7,
0x20, 0x20, 0xa6, 0xa1, 0xd3, 0x20, 0x20, 0x20, 0xf1, 0xf0, 0xf4, 0x9b, 0xf8, 0xa5, 0xf5, 0xf7,
0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, 0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, 0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, 0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, 0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xae, 0xfe, 0xf1, 0x20, 0xb3, 0x20, 0xfd, 0xa1, 0x20, 0xa4, 0x8b, 0x20, 0x20, 0x20, 0xa7,
0x20, 0x20, 0xa6, 0xa1, 0xd3, 0x20, 0x20, 0x20, 0xf1, 0xf0, 0xf4, 0x9b, 0xf8, 0xa5, 0xf5, 0xf7,
0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, 0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, 0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, 0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, 0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca
};
static trans_table_t out_table_iso_8859_5 = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xb3, 0x80, 0x81, 0xaa, 0xbd, 0xb2, 0xaf, 0x4a, 0x8a, 0x8c, 0x8e, 0x8d, 0x20, 0xa1, 0x8f,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1,
0xb9, 0xa3, 0x90, 0x83, 0xba, 0xbe, 0x69, 0xbf, 0xbc, 0x9a, 0x9c, 0x9e, 0x9d, 0xa7, 0xa2, 0x9f
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xb3, 0x80, 0x81, 0xaa, 0xbd, 0xb2, 0xaf, 0x4a, 0x8a, 0x8c, 0x8e, 0x8d, 0x20, 0xa1, 0x8f,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1,
0xb9, 0xa3, 0x90, 0x83, 0xba, 0xbe, 0x69, 0xbf, 0xbc, 0x9a, 0x9c, 0x9e, 0x9d, 0xa7, 0xa2, 0x9f
};
static trans_table_t in_table_windows_1251 = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xb8, 0xa4, 0xa5, 0xa6, 0xa7, 0x22, 0xa9, 0x20, 0x22, 0x5e, 0x2d, 0xae, 0x7e,
0xb0, 0xb1, 0x20, 0xa8, 0x27, 0xb5, 0xb6, 0xb7, 0x2c, 0x20, 0x20, 0x22, 0x20, 0x20, 0x20, 0xd7,
0xfe, 0xe0, 0xe1, 0xf6, 0xe4, 0xe5, 0xf4, 0xe3, 0xf5, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee,
0xef, 0xff, 0xf0, 0xf1, 0xf2, 0xf3, 0xe6, 0xe2, 0xfc, 0xfb, 0xe7, 0xf8, 0xfd, 0xf9, 0xf7, 0xfa,
0xde, 0xc0, 0xc1, 0xd6, 0xc4, 0xc5, 0xd4, 0xc3, 0xd5, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
0xcf, 0xdf, 0xd0, 0xd1, 0xd2, 0xd3, 0xc6, 0xc2, 0xdc, 0xdb, 0xc7, 0xd8, 0xdd, 0xd9, 0xd7, 0xda
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xb8, 0xa4, 0xa5, 0xa6, 0xa7, 0x22, 0xa9, 0x20, 0x22, 0x5e, 0x2d, 0xae, 0x7e,
0xb0, 0xb1, 0x20, 0xa8, 0x27, 0xb5, 0xb6, 0xb7, 0x2c, 0x20, 0x20, 0x22, 0x20, 0x20, 0x20, 0xd7,
0xfe, 0xe0, 0xe1, 0xf6, 0xe4, 0xe5, 0xf4, 0xe3, 0xf5, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee,
0xef, 0xff, 0xf0, 0xf1, 0xf2, 0xf3, 0xe6, 0xe2, 0xfc, 0xfb, 0xe7, 0xf8, 0xfd, 0xf9, 0xf7, 0xfa,
0xde, 0xc0, 0xc1, 0xd6, 0xc4, 0xc5, 0xd4, 0xc3, 0xd5, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
0xcf, 0xdf, 0xd0, 0xd1, 0xd2, 0xd3, 0xc6, 0xc2, 0xdc, 0xdb, 0xc7, 0xd8, 0xdd, 0xd9, 0xd7, 0xda
};
static trans_table_t out_table_windows_1251 = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0x4a, 0xa4, 0xe7, 0x7c, 0xa7, 0xb3, 0xa9, 0xe5, 0x22, 0x5e, 0x2d, 0xae, 0x49,
0xb0, 0xb1, 0x49, 0x69, 0xc7, 0xb5, 0xb6, 0xb7, 0xa3, 0x4e, 0xc5, 0x22, 0x6a, 0x53, 0x73, 0xc0,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0x4a, 0xa4, 0xe7, 0x7c, 0xa7, 0xb3, 0xa9, 0xe5, 0x22, 0x5e, 0x2d, 0xae, 0x49,
0xb0, 0xb1, 0x49, 0x69, 0xc7, 0xb5, 0xb6, 0xb7, 0xa3, 0x4e, 0xc5, 0x22, 0x6a, 0x53, 0x73, 0xc0,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1
};
static trans_table_t in_table_alt_866 = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0xf9, 0x2d, 0x2d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xfa, 0x20,
0x20, 0x20, 0x20, 0xf1, 0xf5, 0x20, 0x69, 0xf9, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0xf0, 0xf4, 0x20, 0x49, 0xf8, 0x20, 0xfc, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0xee, 0xa0, 0xa1, 0xe6, 0xa4, 0xa5, 0xe4, 0xa3, 0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xa6, 0xa2, 0xec, 0xeb, 0xa7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
0x9e, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83, 0x95, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e,
0x8f, 0x9f, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82, 0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0xf9, 0x2d, 0x2d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xfa, 0x20,
0x20, 0x20, 0x20, 0xf1, 0xf5, 0x20, 0x69, 0xf9, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0xf0, 0xf4, 0x20, 0x49, 0xf8, 0x20, 0xfc, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0xee, 0xa0, 0xa1, 0xe6, 0xa4, 0xa5, 0xe4, 0xa3, 0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xa6, 0xa2, 0xec, 0xeb, 0xa7, 0xe8, 0xed, 0xe9, 0xe7, 0xea,
0x9e, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83, 0x95, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e,
0x8f, 0x9f, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82, 0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a
};
static trans_table_t out_table_alt_866 = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0x02, 0x02, 0x02, 0x19, 0x16, 0x16, 0x16, 0x0c, 0x0c, 0x16, 0x19, 0x0c, 0x0b, 0x0b, 0x0b, 0x0c,
0x0e, 0x17, 0x18, 0x15, 0x12, 0x0f, 0x15, 0x15, 0x0e, 0x0d, 0x17, 0x18, 0x15, 0x12, 0x0f, 0x17,
0x17, 0x18, 0x18, 0x0e, 0x0e, 0x0d, 0x0d, 0x0f, 0x0f, 0x0b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1,
0xb3, 0xa3, 0x20, 0x20, 0xb4, 0xa4, 0x49, 0x69, 0xb7, 0xa7, 0x20, 0x20, 0xb9, 0x20, 0x20, 0x20
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1,
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
0x02, 0x02, 0x02, 0x19, 0x16, 0x16, 0x16, 0x0c, 0x0c, 0x16, 0x19, 0x0c, 0x0b, 0x0b, 0x0b, 0x0c,
0x0e, 0x17, 0x18, 0x15, 0x12, 0x0f, 0x15, 0x15, 0x0e, 0x0d, 0x17, 0x18, 0x15, 0x12, 0x0f, 0x17,
0x17, 0x18, 0x18, 0x0e, 0x0e, 0x0d, 0x0d, 0x0f, 0x0f, 0x0b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1,
0xb3, 0xa3, 0x20, 0x20, 0xb4, 0xa4, 0x49, 0x69, 0xb7, 0xa7, 0x20, 0x20, 0xb9, 0x20, 0x20, 0x20
};
static enc_context_t *
enc_create_context(const char *id)
static enc_context_t *enc_create_context(const char *id)
{
enc_context_t *tmp;
enc_context_t *tmp;
tmp = (enc_context_t *) MALLOC(sizeof(enc_context_t));
MEMSET(tmp, 0, sizeof(enc_context_t));
tmp->id = STRDUP(id);
return tmp;
tmp = (enc_context_t *) MALLOC(sizeof(enc_context_t));
MEMSET(tmp, 0, sizeof(enc_context_t));
tmp->id = STRDUP(id);
return tmp;
}
static void
enc_context_add_state(enc_context_t *context, enc_state_t *state)
{
ASSERT(context != NULL);
ASSERT(state != NULL);
ASSERT(context != NULL);
ASSERT(state != NULL);
state->next = context->states;
context->states = state;
state->next = context->states;
context->states = state;
}
static enc_state_t *
enc_create_state(const char *id, unsigned char lifetime)
static enc_state_t *enc_create_state(const char *id, unsigned char lifetime)
{
enc_state_t *tmp;
enc_state_t *tmp;
tmp = (enc_state_t *) MALLOC(sizeof(enc_state_t));
MEMSET(tmp, 0, sizeof(enc_state_t));
tmp->id = STRDUP(id);
tmp->lifetime = lifetime;
return tmp;
tmp = (enc_state_t *) MALLOC(sizeof(enc_state_t));
MEMSET(tmp, 0, sizeof(enc_state_t));
tmp->id = STRDUP(id);
tmp->lifetime = lifetime;
return tmp;
}
static void
enc_state_add_switch(enc_state_t *state, unsigned char key, enc_state_t *next_state)
{
state_switch_t *stsw;
state_switch_t *stsw;
stsw = (state_switch_t *) MALLOC(sizeof(state_switch_t));
stsw->key = key;
stsw->next_state = next_state;
stsw->next = state->switches;
state->switches = stsw;
stsw = (state_switch_t *) MALLOC(sizeof(state_switch_t));
stsw->key = key;
stsw->next_state = next_state;
stsw->next = state->switches;
state->switches = stsw;
}
static void
enc_state_set_in_table(enc_state_t *state, trans_table_t in_tbl)
{
ASSERT(state != NULL);
state->in_tbl = in_tbl;
ASSERT(state != NULL);
state->in_tbl = in_tbl;
}
static void
enc_state_set_out_table(enc_state_t *state, trans_table_t out_tbl)
{
ASSERT(state != NULL);
state->out_tbl = out_tbl;
ASSERT(state != NULL);
state->out_tbl = out_tbl;
}
void
@ -247,33 +245,33 @@ enc_init(void)
static void
enc_init_builtins(void)
{
enc_state_t *st;
state_switch_t *stsw;
enc_state_t *st;
state_switch_t *stsw;
builtin_context_cyrillic.id = "Cyrillic";
st = enc_create_state("alt-866", 0);
enc_state_set_in_table(st, in_table_alt_866);
enc_state_set_out_table(st, out_table_alt_866);
enc_context_add_state(&builtin_context_cyrillic, st);
builtin_context_cyrillic.current = st;
builtin_context_cyrillic.id = "Cyrillic";
st = enc_create_state("alt-866", 0);
enc_state_set_in_table(st, in_table_alt_866);
enc_state_set_out_table(st, out_table_alt_866);
enc_context_add_state(&builtin_context_cyrillic, st);
builtin_context_cyrillic.current = st;
st = enc_create_state("windows-1251", 0);
enc_state_set_in_table(st, in_table_windows_1251);
enc_state_set_out_table(st, out_table_windows_1251);
enc_state_add_switcher(st, 0x0f, builtin_context_cyrillic.current);
enc_context_add_state(&builtin_context_cyrillic, st);
builtin_context_cyrillic.current = st;
st = enc_create_state("windows-1251", 0);
enc_state_set_in_table(st, in_table_windows_1251);
enc_state_set_out_table(st, out_table_windows_1251);
enc_state_add_switcher(st, 0x0f, builtin_context_cyrillic.current);
enc_context_add_state(&builtin_context_cyrillic, st);
builtin_context_cyrillic.current = st;
st = enc_create_state("iso-8859-5", 0);
enc_state_set_in_table(st, in_table_iso_8859_5);
enc_state_set_out_table(st, out_table_iso_8859_5);
enc_state_add_switcher(st, 0x0f, builtin_context_cyrillic.current);
enc_context_add_state(&builtin_context_cyrillic, st);
builtin_context_cyrillic.current = st;
st = enc_create_state("iso-8859-5", 0);
enc_state_set_in_table(st, in_table_iso_8859_5);
enc_state_set_out_table(st, out_table_iso_8859_5);
enc_state_add_switcher(st, 0x0f, builtin_context_cyrillic.current);
enc_context_add_state(&builtin_context_cyrillic, st);
builtin_context_cyrillic.current = st;
st = enc_create_state("koi8-r", 0);
enc_state_add_switcher(st, 0x0f, builtin_context_cyrillic.current);
enc_context_add_state(&builtin_context_cyrillic, st);
builtin_context_cyrillic.current = st;
st = enc_create_state("koi8-r", 0);
enc_state_add_switcher(st, 0x0f, builtin_context_cyrillic.current);
enc_context_add_state(&builtin_context_cyrillic, st);
builtin_context_cyrillic.current = st;
}

File diff suppressed because it is too large Load Diff

1075
src/font.c

File diff suppressed because it is too large Load Diff

View File

@ -62,33 +62,33 @@ typedef unsigned int u_int;
typedef unsigned long u_long;
typedef struct s_xlat {
u_int first, last;
u_int *pval; /* array of translated values */
u_int first, last;
u_int *pval; /* array of translated values */
} K_XLAT;
typedef struct s_switch {
u_char type; /* Ascii, Virtual, Scan */
u_int code;
u_char nextstate;
u_char on; /* current state of key: 0 = off */
u_char type; /* Ascii, Virtual, Scan */
u_int code;
u_char nextstate;
u_char on; /* current state of key: 0 = off */
} K_SWITCH;
typedef struct s_state {
u_int num_xlat; /* number of translations */
K_XLAT *xlat; /* State translations ((dynamic - realloc'ed) */
u_int num_switcher; /* number of switcher keys */
K_SWITCH switcher[MAX_SWITCHER]; /* switcher keys to other states */
u_char life; /* 0 = until switched by key */
u_char prev_state; /* filled when jumped to a new state */
u_int num_xlat; /* number of translations */
K_XLAT *xlat; /* State translations ((dynamic - realloc'ed) */
u_int num_switcher; /* number of switcher keys */
K_SWITCH switcher[MAX_SWITCHER]; /* switcher keys to other states */
u_char life; /* 0 = until switched by key */
u_char prev_state; /* filled when jumped to a new state */
} K_STATE;
/* type for each one of the different greek standards (xlat types) */
typedef struct s_xlat_type {
char *plain;
char *accent;
char *accent_xtra;
char *umlaut;
char *acc_uml;
char *plain;
char *accent;
char *accent_xtra;
char *umlaut;
char *acc_uml;
} XLAT_TYPE;
/* --- Local Data ------------ */
@ -105,30 +105,38 @@ static int GreekMode = GREEK_ELOT928;
* more flexibly.
*/
/* elot 928 xlations */
static char elot_xlat_plain[] = "65-122:193,194,216,196,197,214,195,199,201,206,202,203,204,205,207,208,81,209,211,212,200,217,87,215,213,198,91,92,93,94,95,96,225,226,248,228,229,246,227,231,233,238,234,235,236,237,239,240,113,241,243,244,232,249,242,247,245,230";
static char elot_xlat_plain[] =
"65-122:193,194,216,196,197,214,195,199,201,206,202,203,204,205,207,208,81,209,211,212,200,217,87,215,213,198,91,92,93,94,95,96,225,226,248,228,229,246,227,231,233,238,234,235,236,237,239,240,113,241,243,244,232,249,242,247,245,230";
/* c and s give copyright and section sign */
static char elot_xlat_acc[] = "65-122:182,194,216,196,184,214,195,185,186,206,202,203,204,205,188,208,81,209,211,212,200,191,87,215,190,198,91,92,93,94,95,96,220,226," /*248 */ "169,228,221,246,227,222,223,238,234,235,236,237,252,240,113,241," /*243 */ "167,244,232,254,242,247,253,230";
static char elot_xlat_acc[] =
"65-122:182,194,216,196,184,214,195,185,186,206,202,203,204,205,188,208,81,209,211,212,200,191,87,215,190,198,91,92,93,94,95,96,220,226,"
/*248 */ "169,228,221,246,227,222,223,238,234,235,236,237,252,240,113,241," /*243 */ "167,244,232,254,242,247,253,230";
static char elot_xlat_acc_xtra[] = "46-62:183,47,48,49,50,51,52,53,54,55,56,57,58,59,171,61,187"; /* anw teleia, quotes */
static char elot_xlat_uml[] = "65-122:193,194,216,196,197,214,195,199,218,206,202,203,204,205,207,208,81,209,211,212,200,217,87,215,219,198,91,92,93,94,95,96,225,226,248,228,229,246,227,231,250,238,234,235,236,237,239,240,113,241,243,244,232,249,242,247,251,230";
static char elot_xlat_umacc[] = "65-122:193,194,216,196,197,214,195,199,201,206,202,203,204,205,207,208,81,209,211,212,200,217,87,215,213,198,91,92,93,94,95,96,225,226,248,228,229,246,227,231,192,238,234,235,236,237,239,240,113,241,243,244,232,249,242,247,224,230";
static char elot_xlat_uml[] =
"65-122:193,194,216,196,197,214,195,199,218,206,202,203,204,205,207,208,81,209,211,212,200,217,87,215,219,198,91,92,93,94,95,96,225,226,248,228,229,246,227,231,250,238,234,235,236,237,239,240,113,241,243,244,232,249,242,247,251,230";
static char elot_xlat_umacc[] =
"65-122:193,194,216,196,197,214,195,199,201,206,202,203,204,205,207,208,81,209,211,212,200,217,87,215,213,198,91,92,93,94,95,96,225,226,248,228,229,246,227,231,192,238,234,235,236,237,239,240,113,241,243,244,232,249,242,247,224,230";
/* ibm 437 xlations */
static char i437_xlat_plain[] = "65-122:128,129,150,131,132,148,130,134,136,141,137,138,139,140,142,143,81,144,145,146,135,151,87,149,147,133,91,92,93,94,95,96,152,153,175,155,156,173,154,158,160,165,161,162,163,164,166,167,113,168,169,171,159,224,170,174,172,157";
static char i437_xlat_acc[] = "65-122:234,129,150,131,235,148,130,236,237,141,137,138,139,140,238,143,81,144,145,146,135,240,87,149,239,133,91,92,93,94,95,96,225,153,175,155,226,173,154,227,229,165,161,162,163,164,230,167,113,168,169,171,159,233,170,174,231,157";
static char i437_xlat_acc_xtra[] = "46-46:250"; /* anw teleia */
static char i437_xlat_uml[] = "65-122:128,129,150,131,132,148,130,134,136,141,137,138,139,140,142,143,81,144,145,146,135,151,87,149,147,133,91,92,93,94,95,96,152,153,175,155,156,173,154,158,228,165,161,162,163,164,166,167,113,168,169,171,159,224,170,174,232,157";
static char i437_xlat_umacc[] = "65-122:128,129,150,131,132,148,130,134,136,141,137,138,139,140,142,143,81,144,145,146,135,151,87,149,147,133,91,92,93,94,95,96,152,153,175,155,156,173,154,158,42,165,161,162,163,164,166,167,113,168,169,171,159,224,170,174,42,157";
static char i437_xlat_plain[] =
"65-122:128,129,150,131,132,148,130,134,136,141,137,138,139,140,142,143,81,144,145,146,135,151,87,149,147,133,91,92,93,94,95,96,152,153,175,155,156,173,154,158,160,165,161,162,163,164,166,167,113,168,169,171,159,224,170,174,172,157";
static char i437_xlat_acc[] =
"65-122:234,129,150,131,235,148,130,236,237,141,137,138,139,140,238,143,81,144,145,146,135,240,87,149,239,133,91,92,93,94,95,96,225,153,175,155,226,173,154,227,229,165,161,162,163,164,230,167,113,168,169,171,159,233,170,174,231,157";
static char i437_xlat_acc_xtra[] = "46-46:250"; /* anw teleia */
static char i437_xlat_uml[] =
"65-122:128,129,150,131,132,148,130,134,136,141,137,138,139,140,142,143,81,144,145,146,135,151,87,149,147,133,91,92,93,94,95,96,152,153,175,155,156,173,154,158,228,165,161,162,163,164,166,167,113,168,169,171,159,224,170,174,232,157";
static char i437_xlat_umacc[] =
"65-122:128,129,150,131,132,148,130,134,136,141,137,138,139,140,142,143,81,144,145,146,135,151,87,149,147,133,91,92,93,94,95,96,152,153,175,155,156,173,154,158,42,165,161,162,163,164,166,167,113,168,169,171,159,224,170,174,42,157";
/*
* currently ELOT928 and IBM437 are supported; easy to include others
* (not recommended: stick to just these 2 if not only the ELOT one)
*/
static XLAT_TYPE xlat_type[] =
{
{elot_xlat_plain, elot_xlat_acc, elot_xlat_acc_xtra, elot_xlat_uml, elot_xlat_umacc},
{i437_xlat_plain, i437_xlat_acc, i437_xlat_acc_xtra, i437_xlat_uml, i437_xlat_umacc},
static XLAT_TYPE xlat_type[] = {
{elot_xlat_plain, elot_xlat_acc, elot_xlat_acc_xtra, elot_xlat_uml, elot_xlat_umacc},
{i437_xlat_plain, i437_xlat_acc, i437_xlat_acc_xtra, i437_xlat_uml, i437_xlat_umacc},
};
/* the current trasnaltion type */
@ -144,34 +152,34 @@ static void kstate_set_life(char *str);
static void
kstate_setcurr(int stateno)
{
u_char prev_state;
u_char prev_state;
if ((u_int) stateno > (u_int) MAX_STATES)
return;
if (pStateNow->life == 1)
prev_state = pStateNow->prev_state;
else
prev_state = nStateNow;
pStateNow = &State[nStateNow = stateno];
pStateNow->prev_state = prev_state;
if ((u_int) stateno > (u_int) MAX_STATES)
return;
if (pStateNow->life == 1)
prev_state = pStateNow->prev_state;
else
prev_state = nStateNow;
pStateNow = &State[nStateNow = stateno];
pStateNow->prev_state = prev_state;
}
static void
kstate_init(void)
{
pStateNow->num_xlat = pStateNow->num_switcher = pStateNow->life = pStateNow->prev_state = 0;
pStateNow->xlat = NULL;
pStateNow->num_xlat = pStateNow->num_switcher = pStateNow->life = pStateNow->prev_state = 0;
pStateNow->xlat = NULL;
}
static void
kstate_end(void)
{
int i;
int i;
for (i = 0; i < pStateNow->num_xlat; i++)
FREE(pStateNow->xlat[i].pval);
if (pStateNow->num_xlat > 0)
FREE(pStateNow->xlat);
for (i = 0; i < pStateNow->num_xlat; i++)
FREE(pStateNow->xlat[i].pval);
if (pStateNow->num_xlat > 0)
FREE(pStateNow->xlat);
}
/*
@ -181,48 +189,48 @@ kstate_end(void)
static void
kstate_init_all(int greek_mode)
{
/* the translation tables for the 4 FSM states for ELOT-928 mappings */
int i;
/* the translation tables for the 4 FSM states for ELOT-928 mappings */
int i;
for (i = 0; i < MAX_STATES; i++) {
kstate_setcurr(i);
kstate_init();
}
if (greek_mode < 0 || greek_mode >= NUM_XLAT_TYPES) /* avoid death */
greek_mode = GREEK_ELOT928;
xlat_now = &xlat_type[greek_mode];
kstate_setcurr(0);
kstate_add_xlat(xlat_now->plain);
kstate_add_switcher("A;:1");
kstate_add_switcher("A::2");
kstate_set_life("L0");
for (i = 0; i < MAX_STATES; i++) {
kstate_setcurr(i);
kstate_init();
}
if (greek_mode < 0 || greek_mode >= NUM_XLAT_TYPES) /* avoid death */
greek_mode = GREEK_ELOT928;
xlat_now = &xlat_type[greek_mode];
kstate_setcurr(0);
kstate_add_xlat(xlat_now->plain);
kstate_add_switcher("A;:1");
kstate_add_switcher("A::2");
kstate_set_life("L0");
kstate_setcurr(1);
kstate_add_xlat(xlat_now->accent);
kstate_add_xlat(xlat_now->accent_xtra);
kstate_add_switcher("A::3");
kstate_set_life("L1");
kstate_setcurr(1);
kstate_add_xlat(xlat_now->accent);
kstate_add_xlat(xlat_now->accent_xtra);
kstate_add_switcher("A::3");
kstate_set_life("L1");
kstate_setcurr(2);
kstate_add_xlat(xlat_now->umlaut);
kstate_add_switcher("A;:3");
kstate_set_life("L1");
kstate_setcurr(2);
kstate_add_xlat(xlat_now->umlaut);
kstate_add_switcher("A;:3");
kstate_set_life("L1");
kstate_setcurr(3);
kstate_add_xlat(xlat_now->acc_uml);
kstate_set_life("L1");
kstate_setcurr(3);
kstate_add_xlat(xlat_now->acc_uml);
kstate_set_life("L1");
}
static void
kstate_end_all(void)
{
int i;
int i;
for (i = 0; i < MAX_STATES; i++) {
kstate_setcurr(i);
kstate_end();
}
kstate_setcurr(0);
for (i = 0; i < MAX_STATES; i++) {
kstate_setcurr(i);
kstate_end();
}
kstate_setcurr(0);
}
/*
@ -231,38 +239,38 @@ kstate_end_all(void)
static void
kstate_reset(void)
{
kstate_setcurr(0);
kstate_setcurr(0);
}
static void
kstate_add_xlat(char *str)
{
K_XLAT *xlat;
u_int *pval_tmp;
char *sval;
int i;
K_XLAT *xlat;
u_int *pval_tmp;
char *sval;
int i;
if (str == NULL)
return;
/* add a new xlat table in state */
if (pStateNow->num_xlat == 0) {
pStateNow->xlat = MALLOC(sizeof(K_XLAT));
} else /* prefer contiguous data, realloc */
pStateNow->xlat = REALLOC(pStateNow->xlat, (pStateNow->num_xlat + 1) * sizeof(K_XLAT));
xlat = &pStateNow->xlat[pStateNow->num_xlat];
/* parse str and derive first, last, values */
xlat->first = (u_int) atoi(strtok(str, "-"));
xlat->last = (u_int) atoi(strtok(NULL, ":"));
i = 0;
pval_tmp = CALLOC(MAX_VAL, sizeof(K_XLAT));
while ((sval = strtok(NULL, ",")) != NULL) {
pval_tmp[i++] = (u_int) (atoi(sval));
}
xlat->pval = CALLOC(i, sizeof(K_XLAT));
if (xlat->pval != NULL)
memcpy(xlat->pval, pval_tmp, i * sizeof(u_int));
FREE(pval_tmp);
pStateNow->num_xlat++;
if (str == NULL)
return;
/* add a new xlat table in state */
if (pStateNow->num_xlat == 0) {
pStateNow->xlat = MALLOC(sizeof(K_XLAT));
} else /* prefer contiguous data, realloc */
pStateNow->xlat = REALLOC(pStateNow->xlat, (pStateNow->num_xlat + 1) * sizeof(K_XLAT));
xlat = &pStateNow->xlat[pStateNow->num_xlat];
/* parse str and derive first, last, values */
xlat->first = (u_int) atoi(strtok(str, "-"));
xlat->last = (u_int) atoi(strtok(NULL, ":"));
i = 0;
pval_tmp = CALLOC(MAX_VAL, sizeof(K_XLAT));
while ((sval = strtok(NULL, ",")) != NULL) {
pval_tmp[i++] = (u_int) (atoi(sval));
}
xlat->pval = CALLOC(i, sizeof(K_XLAT));
if (xlat->pval != NULL)
memcpy(xlat->pval, pval_tmp, i * sizeof(u_int));
FREE(pval_tmp);
pStateNow->num_xlat++;
}
/*
@ -271,83 +279,83 @@ kstate_add_xlat(char *str)
static void
kstate_add_switcher(char *str)
{
K_SWITCH *switcher;
K_SWITCH *switcher;
if (str == NULL)
return;
if (pStateNow->num_switcher >= MAX_SWITCHER)
return;
switcher = &pStateNow->switcher[pStateNow->num_switcher];
switch (switcher->type = str[0]) {
case 'A': /* ascii eg: A;:2 */
switcher->code = str[1];
switcher->nextstate = atoi(&str[3]);
break;
}
switcher->on = 0;
pStateNow->num_switcher++;
if (str == NULL)
return;
if (pStateNow->num_switcher >= MAX_SWITCHER)
return;
switcher = &pStateNow->switcher[pStateNow->num_switcher];
switch (switcher->type = str[0]) {
case 'A': /* ascii eg: A;:2 */
switcher->code = str[1];
switcher->nextstate = atoi(&str[3]);
break;
}
switcher->on = 0;
pStateNow->num_switcher++;
}
/* L1 or L0 */
static void
kstate_set_life(char *str)
{
pStateNow->life = atoi(&str[1]);
pStateNow->life = atoi(&str[1]);
}
static unsigned int
kstate_cxlat(unsigned int c)
{
int i;
int i;
/* check for ascii switcher */
for (i = 0; i < pStateNow->num_switcher; i++)
if (pStateNow->switcher[i].type == 'A' && /* only ascii here */
c == pStateNow->switcher[i].code) {
kstate_setcurr(pStateNow->switcher[i].nextstate);
pStateNow->switcher[i].on = 1;
return ((unsigned int) -1);
}
/* do translation */
for (i = 0; i < pStateNow->num_xlat; i++)
if (c >= pStateNow->xlat[i].first && c <= pStateNow->xlat[i].last) {
c = pStateNow->xlat[i].pval[c - pStateNow->xlat[i].first];
break;
}
/* switch back to previous state if life of current is 1 */
if (pStateNow->life == 1)
kstate_setcurr(pStateNow->prev_state);
return (c);
/* check for ascii switcher */
for (i = 0; i < pStateNow->num_switcher; i++)
if (pStateNow->switcher[i].type == 'A' && /* only ascii here */
c == pStateNow->switcher[i].code) {
kstate_setcurr(pStateNow->switcher[i].nextstate);
pStateNow->switcher[i].on = 1;
return ((unsigned int) -1);
}
/* do translation */
for (i = 0; i < pStateNow->num_xlat; i++)
if (c >= pStateNow->xlat[i].first && c <= pStateNow->xlat[i].last) {
c = pStateNow->xlat[i].pval[c - pStateNow->xlat[i].first];
break;
}
/* switch back to previous state if life of current is 1 */
if (pStateNow->life == 1)
kstate_setcurr(pStateNow->prev_state);
return (c);
}
void
greek_init(void)
{
kstate_init_all(GreekMode);
kstate_init_all(GreekMode);
}
void
greek_end(void)
{
kstate_end_all();
kstate_end_all();
}
void
greek_reset(void)
{
kstate_reset();
kstate_reset();
}
void
greek_setmode(int greek_mode)
{
GreekMode = greek_mode;
GreekMode = greek_mode;
}
int
greek_getmode(void)
{
return (GreekMode);
return (GreekMode);
}
/*
@ -356,31 +364,31 @@ greek_getmode(void)
int
greek_xlat(char *s, int num_chars)
{
int i, count;
unsigned int c;
int i, count;
unsigned int c;
for (i = 0, count = 0; i < num_chars; i++) {
c = kstate_cxlat((unsigned int) s[i]);
if (c != -1)
s[count++] = (char) c;
}
s[count] = '\0';
return (count);
for (i = 0, count = 0; i < num_chars; i++) {
c = kstate_cxlat((unsigned int) s[i]);
if (c != -1)
s[count++] = (char) c;
}
s[count] = '\0';
return (count);
}
# ifdef TEST
int
main(void)
{
/*char text[] = "abcdef;aGDZXC"; */
char text[] = "abcdef;a:ibgdezhuiklmnjoprstyfxcv";
/*char text[] = "abcdef;aGDZXC"; */
char text[] = "abcdef;a:ibgdezhuiklmnjoprstyfxcv";
kstate_init_all(GREEK_ELOT928);
printf("text: %s\n", text);
greek_xlat(text, strlen(text));
printf("xlat'ed text: %s\n", text);
kstate_end_all();
return 0;
kstate_init_all(GREEK_ELOT928);
printf("text: %s\n", text);
greek_xlat(text, strlen(text));
printf("xlat'ed text: %s\n", text);
kstate_end_all();
return 0;
}
# endif

1183
src/libscream.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -28,5 +28,5 @@ extern int eterm_bootstrap(int argc, char *argv[]);
int
main(int argc, char *argv[])
{
return (eterm_bootstrap(argc, argv));
return (eterm_bootstrap(argc, argv));
}

File diff suppressed because it is too large Load Diff

View File

@ -45,9 +45,9 @@ const char *
my_basename(const char *str)
{
const char *base = strrchr(str, '/');
const char *base = strrchr(str, '/');
return (base ? base + 1 : str);
return (base ? base + 1 : str);
}
@ -59,18 +59,18 @@ unsigned long
str_leading_match(register const char *s1, register const char *s2)
{
register unsigned long n;
register unsigned long n;
if (!s1 || !s2) {
return (0);
}
for (n = 0; *s2; n++, s1++, s2++) {
if (*s1 != *s2) {
return 0;
if (!s1 || !s2) {
return (0);
}
for (n = 0; *s2; n++, s1++, s2++) {
if (*s1 != *s2) {
return 0;
}
}
}
return n;
return n;
}
/* Strip leading and trailing whitespace and quotes from a string */
@ -78,34 +78,34 @@ char *
str_trim(char *str)
{
register char *tmp = str;
size_t n;
register char *tmp = str;
size_t n;
if (str && *str) {
if (str && *str) {
chomp(str);
n = strlen(str);
chomp(str);
n = strlen(str);
if (!n) {
*str = 0;
return str;
if (!n) {
*str = 0;
return str;
}
/* strip leading/trailing quotes */
if (*tmp == '"') {
tmp++;
n--;
if (!n) {
*str = 0;
return str;
} else if (tmp[n - 1] == '"') {
tmp[--n] = '\0';
}
}
if (tmp != str) {
memmove(str, tmp, (strlen(tmp)) + 1);
}
}
/* strip leading/trailing quotes */
if (*tmp == '"') {
tmp++;
n--;
if (!n) {
*str = 0;
return str;
} else if (tmp[n - 1] == '"') {
tmp[--n] = '\0';
}
}
if (tmp != str) {
memmove(str, tmp, (strlen(tmp)) + 1);
}
}
return str;
return str;
}
/*
@ -127,210 +127,210 @@ int
parse_escaped_string(char *str)
{
register char *pold = str, *pnew;
unsigned char i;
register char *pold = str, *pnew;
unsigned char i;
D_STRINGS(("parse_escaped_string(\"%s\")\n", str));
D_STRINGS(("parse_escaped_string(\"%s\")\n", str));
if (!BEG_STRCASECMP(pold, "m-")) {
*pold = '\\';
*(pold + 1) = 'e';
}
for (pold = pnew = str; *pold; pold++, pnew++) {
D_STRINGS(("Looking at \"%s\"\n", pold));
if (!BEG_STRCASECMP(pold, "m-") && (isspace(*(pold - 1)) || !isprint(*(pold -1)))) {
*pold = '\\';
*(pold + 1) = 'e';
} else if (!BEG_STRCASECMP(pold, "c-")) {
*(++pold) = '^';
if (!BEG_STRCASECMP(pold, "m-")) {
*pold = '\\';
*(pold + 1) = 'e';
}
D_STRINGS(("Operating on \'%c\'\n", *pold));
switch (*pold) {
case '\\':
D_STRINGS(("Backslash + %c\n", *(pold + 1)));
switch (tolower(*(++pold))) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
for (i = 0; *pold >= '0' && *pold <= '7'; pold++) {
i = (i * 8) + (*pold - '0');
}
pold--;
D_STRINGS(("Octal number evaluates to %d\n", i));
*pnew = i;
break;
case 'n':
*pnew = '\n';
break;
case 'r':
*pnew = '\r';
break;
case 't':
*pnew = '\t';
break;
case 'b':
*pnew = '\b';
break;
case 'f':
*pnew = '\f';
break;
case 'a':
*pnew = '\a';
break;
case 'v':
*pnew = '\v';
break;
case 'e':
*pnew = '\033';
break;
case 'c':
pold++;
*pnew = MAKE_CTRL_CHAR(*pold);
break;
default:
*pnew = *pold;
break;
}
break;
case '^':
D_STRINGS(("Caret + %c\n", *(pold + 1)));
pold++;
*pnew = MAKE_CTRL_CHAR(*pold);
break;
default:
*pnew = *pold;
for (pold = pnew = str; *pold; pold++, pnew++) {
D_STRINGS(("Looking at \"%s\"\n", pold));
if (!BEG_STRCASECMP(pold, "m-") && (isspace(*(pold - 1)) || !isprint(*(pold - 1)))) {
*pold = '\\';
*(pold + 1) = 'e';
} else if (!BEG_STRCASECMP(pold, "c-")) {
*(++pold) = '^';
}
D_STRINGS(("Operating on \'%c\'\n", *pold));
switch (*pold) {
case '\\':
D_STRINGS(("Backslash + %c\n", *(pold + 1)));
switch (tolower(*(++pold))) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
for (i = 0; *pold >= '0' && *pold <= '7'; pold++) {
i = (i * 8) + (*pold - '0');
}
pold--;
D_STRINGS(("Octal number evaluates to %d\n", i));
*pnew = i;
break;
case 'n':
*pnew = '\n';
break;
case 'r':
*pnew = '\r';
break;
case 't':
*pnew = '\t';
break;
case 'b':
*pnew = '\b';
break;
case 'f':
*pnew = '\f';
break;
case 'a':
*pnew = '\a';
break;
case 'v':
*pnew = '\v';
break;
case 'e':
*pnew = '\033';
break;
case 'c':
pold++;
*pnew = MAKE_CTRL_CHAR(*pold);
break;
default:
*pnew = *pold;
break;
}
break;
case '^':
D_STRINGS(("Caret + %c\n", *(pold + 1)));
pold++;
*pnew = MAKE_CTRL_CHAR(*pold);
break;
default:
*pnew = *pold;
}
}
}
if (!BEG_STRCASECMP(str, "\033x") && *(pnew - 1) != '\r') {
D_STRINGS(("Adding carriage return\n"));
*(pnew++) = '\r';
} else if (!BEG_STRCASECMP(str, "\033]") && *(pnew - 1) != '\a') {
D_STRINGS(("Adding bell character\n"));
*(pnew++) = '\a';
}
*pnew = 0;
if (!BEG_STRCASECMP(str, "\033x") && *(pnew - 1) != '\r') {
D_STRINGS(("Adding carriage return\n"));
*(pnew++) = '\r';
} else if (!BEG_STRCASECMP(str, "\033]") && *(pnew - 1) != '\a') {
D_STRINGS(("Adding bell character\n"));
*(pnew++) = '\a';
}
*pnew = 0;
#if DEBUG >= DEBUG_STRINGS
if (DEBUG_LEVEL >= DEBUG_STRINGS) {
D_STRINGS(("New value is:\n"));
hex_dump(str, (size_t) (pnew - str));
}
if (DEBUG_LEVEL >= DEBUG_STRINGS) {
D_STRINGS(("New value is:\n"));
hex_dump(str, (size_t) (pnew - str));
}
#endif
return (pnew - str);
return (pnew - str);
}
char *
safe_print_string(char *str, unsigned long len)
{
static char *ret_buff = NULL;
static unsigned long rb_size = 0;
char *p;
unsigned long n = 0, i;
static char *ret_buff = NULL;
static unsigned long rb_size = 0;
char *p;
unsigned long n = 0, i;
if (len == ((unsigned long) -1)) {
len = strlen(str);
} else if (len == ((unsigned long) -2)) {
FREE(ret_buff);
rb_size = 0;
return ((char *) NULL);
}
if (ret_buff == NULL) {
rb_size = len;
ret_buff = (char *) MALLOC(rb_size + 1);
} else if (len > rb_size) {
rb_size = len;
ret_buff = (char *) REALLOC(ret_buff, rb_size + 1);
}
for (i = 0, p = ret_buff; i < len; i++, str++, n++) {
if (n + 2 >= rb_size) {
rb_size *= 2;
ret_buff = (char *) REALLOC(ret_buff, rb_size + 1);
p = ret_buff + n;
if (len == ((unsigned long) -1)) {
len = strlen(str);
} else if (len == ((unsigned long) -2)) {
FREE(ret_buff);
rb_size = 0;
return ((char *) NULL);
}
if ((unsigned char) *str < ' ') {
*p++ = '^';
*p++ = *str + '@';
n++;
} else {
*p++ = *str;
if (ret_buff == NULL) {
rb_size = len;
ret_buff = (char *) MALLOC(rb_size + 1);
} else if (len > rb_size) {
rb_size = len;
ret_buff = (char *) REALLOC(ret_buff, rb_size + 1);
}
}
*p = 0;
return ret_buff;
for (i = 0, p = ret_buff; i < len; i++, str++, n++) {
if (n + 2 >= rb_size) {
rb_size *= 2;
ret_buff = (char *) REALLOC(ret_buff, rb_size + 1);
p = ret_buff + n;
}
if ((unsigned char) *str < ' ') {
*p++ = '^';
*p++ = *str + '@';
n++;
} else {
*p++ = *str;
}
}
*p = 0;
return ret_buff;
}
unsigned long
add_carriage_returns(unsigned char *buff, unsigned long cnt)
{
register unsigned char *out, *outp, *in;
register unsigned long i;
register unsigned char *out, *outp, *in;
register unsigned long i;
D_CMD(("buff == %8p \"%s\", cnt == %lu\n", buff, safe_print_string(buff, cnt), cnt));
outp = out = (unsigned char *) MALLOC(cnt * 2);
for (i = 0, in = buff; i < cnt; i++) {
if (*in == '\n') {
*out++ = '\r';
D_CMD(("buff == %8p \"%s\", cnt == %lu\n", buff, safe_print_string(buff, cnt), cnt));
outp = out = (unsigned char *) MALLOC(cnt * 2);
for (i = 0, in = buff; i < cnt; i++) {
if (*in == '\n') {
*out++ = '\r';
}
*out++ = *in++;
}
*out++ = *in++;
}
i = (unsigned long) (out - outp);
memcpy(buff, outp, i);
FREE(outp);
D_CMD(("buff == %8p \"%s\", i == %lu\n", buff, safe_print_string(buff, i), i));
return i;
i = (unsigned long) (out - outp);
memcpy(buff, outp, i);
FREE(outp);
D_CMD(("buff == %8p \"%s\", i == %lu\n", buff, safe_print_string(buff, i), i));
return i;
}
unsigned char
mkdirhier(const char *path)
{
char *str, *pstr;
struct stat dst;
char *str, *pstr;
struct stat dst;
D_CMD(("path == %s\n", path));
str = STRDUP(path); /* We need to modify it. */
pstr = str;
if (*pstr == '/') {
pstr++;
}
for (; (pstr = strchr(pstr, '/'));) {
*pstr = 0;
D_CMD(("path == %s\n", path));
str = STRDUP(path); /* We need to modify it. */
pstr = str;
if (*pstr == '/') {
pstr++;
}
for (; (pstr = strchr(pstr, '/'));) {
*pstr = 0;
D_CMD(("Looking at \"%s\"\n", str));
if (stat(str, &dst)) {
/* It's not there. Create it. */
D_CMD(("stat() failed. Attempting to create it.\n"));
if (mkdir(str, 0755)) {
/* Couldn't create it. Return failure. */
D_CMD(("mkdir(%s, 0755) failed -- %s\n", str, strerror(errno)));
return 0;
}
} else if (!S_ISDIR(dst.st_mode)) {
/* It's there, but it's not a directory. Fail. */
D_CMD(("\"%s\" exists, but it's not a directory.\n", str));
return 0;
}
*pstr++ = '/';
}
D_CMD(("Looking at \"%s\"\n", str));
if (stat(str, &dst)) {
/* It's not there. Create it. */
D_CMD(("stat() failed. Attempting to create it.\n"));
if (mkdir(str, 0755)) {
/* Couldn't create it. Return failure. */
D_CMD(("mkdir(%s, 0755) failed -- %s\n", str, strerror(errno)));
return 0;
}
/* It's not there. Create it. */
D_CMD(("stat() failed. Attempting to create it.\n"));
if (mkdir(str, 0755)) {
/* Couldn't create it. Return failure. */
D_CMD(("mkdir(%s, 0755) failed -- %s\n", str, strerror(errno)));
return 0;
}
} else if (!S_ISDIR(dst.st_mode)) {
/* It's there, but it's not a directory. Fail. */
D_CMD(("\"%s\" exists, but it's not a directory.\n", str));
return 0;
/* It's there, but it's not a directory. Fail. */
D_CMD(("\"%s\" exists, but it's not a directory.\n", str));
return 0;
}
*pstr++ = '/';
}
D_CMD(("Looking at \"%s\"\n", str));
if (stat(str, &dst)) {
/* It's not there. Create it. */
D_CMD(("stat() failed. Attempting to create it.\n"));
if (mkdir(str, 0755)) {
/* Couldn't create it. Return failure. */
D_CMD(("mkdir(%s, 0755) failed -- %s\n", str, strerror(errno)));
return 0;
}
} else if (!S_ISDIR(dst.st_mode)) {
/* It's there, but it's not a directory. Fail. */
D_CMD(("\"%s\" exists, but it's not a directory.\n", str));
return 0;
}
D_CMD(("Done!\n"));
return 1;
D_CMD(("Done!\n"));
return 1;
}

View File

@ -69,62 +69,60 @@ char *
network_display(const char *display)
{
static char ipaddress[32] = "";
char buffer[1024], *rval = NULL;
struct ifconf ifc;
struct ifreq *ifr;
int i, skfd;
static char ipaddress[32] = "";
char buffer[1024], *rval = NULL;
struct ifconf ifc;
struct ifreq *ifr;
int i, skfd;
if (display[0] != ':' && strncmp(display, "unix:", 5))
return display; /* nothing to do */
if (display[0] != ':' && strncmp(display, "unix:", 5))
return display; /* nothing to do */
ifc.ifc_len = sizeof(buffer); /* Get names of all ifaces */
ifc.ifc_buf = buffer;
ifc.ifc_len = sizeof(buffer); /* Get names of all ifaces */
ifc.ifc_buf = buffer;
if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("socket");
return NULL;
}
if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
perror("SIOCGIFCONF");
close(skfd);
return NULL;
}
for (i = 0, ifr = ifc.ifc_req; i < (ifc.ifc_len / sizeof(struct ifreq)); i++, ifr++) {
struct ifreq ifr2;
strcpy(ifr2.ifr_name, ifr->ifr_name);
if (ioctl(skfd, SIOCGIFADDR, &ifr2) >= 0) {
unsigned long addr;
struct sockaddr_in *p_addr;
p_addr = (struct sockaddr_in *) &(ifr2.ifr_addr);
addr = htonl((unsigned long) p_addr->sin_addr.s_addr);
/*
* not "0.0.0.0" or "127.0.0.1" - so format the address
*/
if (addr && addr != 0x7F000001) {
char *colon = strchr(display, ':');
if (colon == NULL)
colon = ":0.0";
sprintf(ipaddress, "%d.%d.%d.%d%s",
(int) ((addr >> 030) & 0xFF),
(int) ((addr >> 020) & 0xFF),
(int) ((addr >> 010) & 0xFF),
(int) (addr & 0xFF), colon);
rval = ipaddress;
break;
}
if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("socket");
return NULL;
}
}
if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
perror("SIOCGIFCONF");
close(skfd);
return NULL;
}
for (i = 0, ifr = ifc.ifc_req; i < (ifc.ifc_len / sizeof(struct ifreq)); i++, ifr++) {
close(skfd);
return rval;
struct ifreq ifr2;
strcpy(ifr2.ifr_name, ifr->ifr_name);
if (ioctl(skfd, SIOCGIFADDR, &ifr2) >= 0) {
unsigned long addr;
struct sockaddr_in *p_addr;
p_addr = (struct sockaddr_in *) &(ifr2.ifr_addr);
addr = htonl((unsigned long) p_addr->sin_addr.s_addr);
/*
* not "0.0.0.0" or "127.0.0.1" - so format the address
*/
if (addr && addr != 0x7F000001) {
char *colon = strchr(display, ':');
if (colon == NULL)
colon = ":0.0";
sprintf(ipaddress, "%d.%d.%d.%d%s",
(int) ((addr >> 030) & 0xFF),
(int) ((addr >> 020) & 0xFF), (int) ((addr >> 010) & 0xFF), (int) (addr & 0xFF), colon);
rval = ipaddress;
break;
}
}
}
close(skfd);
return rval;
}
#endif /* DISPLAY_IS_IP */
/*----------------------- end-of-file (C source) -----------------------*/

File diff suppressed because it is too large Load Diff

View File

@ -134,6 +134,9 @@ extern char *rs_preedit_type;
extern char *rs_name;
extern char *rs_theme;
extern char *rs_config_file;
#ifdef ESCREEN
extern char *rs_url;
#endif
extern unsigned int rs_line_space;
extern unsigned int rs_meta_mod, rs_alt_mod, rs_numlock_mod;
#ifndef NO_BOLDFONT

File diff suppressed because it is too large Load Diff

175
src/scream.h Normal file
View File

@ -0,0 +1,175 @@
/****************************************************************************
* scream::scream.h
* routines to connect to screen and or scream daemons.
* GNU Public Licence applies.
* 2002/04/19 Azundris incept
***************************************************************************/
#define NS_DK 0
#define NS_SSH 1
#define NS_LCL 2
#define NS_SU 3
#define NS_MODE_NEGOTIATE -1
#define NS_MODE_NONE 0
#define NS_MODE_SCREEN 1
#define NS_MODE_SCREAM 2
#define NS_SUCC (-1)
#define NS_FAIL 0
#define NS_OOM 1
#define NS_MALFORMED_URL 2
#define NS_UNKNOWN_USER 3
#define NS_INVALID_SESS 4
#define NS_UNKNOWN_PROTO 5
#define NS_CANT_RESOLVE 6
#define NS_CANT_CONNECT 7
#define NS_CANT_LOGIN 8
#define NS_CANT_ATTACH 9
#define NS_UNKNOWN_LOC 10
#define NS_SCREEN_STATUS 11
#define NS_SCREEN_ST_CLR 12
#define NS_EFUN_NOT_SET 13
#define NS_ERR_WEIRDSCREEN 1
#define NS_SCREAM_CURR 1
#define NS_SCREAM_PRVS 2
#define NS_SCREAM_UTMP 4
#define NS_SCREAM_BELL 8
#define NS_SCREAM_ACT 16
#define NS_SCREAM_FILE 32
#define NS_SCREAM_SHARED 64
#define NS_SCREAM_ZOMBIE 128
#define NS_SCREAM_MASK (~(NS_SCREAM_UTMP|NS_SCREAM_PRVS))
/***************************************************************************/
typedef struct __ns_sess { /* a whole screen-session with many clients */
int where; /* local/remote */
int backend; /* screen/scream */
int nesting; /* 0=topLevel, 1=screen within a screen etc */
char *proto; /* protocol. usually "screen" */
char *host; /* host. numeric or symbolic. often "localhost" */
int port; /* port. usually TCP22: SSH */
char *user; /* user. often current local user */
char *pass; /* password. used for su. for remote sessions, a
ssh-key should be placed on the remote machine. */
char *rsrc; /* additional parameter to screen/scream. URL-enc */
void *userdef; /* the term-app can store a pointer here */
int fd; /* fd for communication */
char escape,literal; /* talking to screen: defaults to ^A, a */
struct __ns_efuns *efuns; /* callbacks into the terminal program. */
struct __ns_disp *dsps; /* first display (that with the lowest index) */
struct __ns_disp *curr; /* current display (NULL for none) */
} _ns_sess;
typedef struct __ns_disp { /* describing the window of a single client */
int index; /* index 0..n */
char *name; /* arbitrary \0-terminated string. humans only. */
int sbb; /* scroll-back buffer. 0 if parent to more screens */
int x; /* rsvd */
int y; /* rsvd */
int w; /* rsvd */
int h; /* rsvd */
int flags; /* current, activity, logging, ... */
struct __ns_sess *sess; /* is child of... (always) */
struct __ns_sess *child; /* if parent of... (rarely) */
struct __ns_efuns *efuns; /* NULL to use its parent's efuns */
struct __ns_disp *prvs; /* left neighbour (<index) of this session */
struct __ns_disp *next; /* right neighbour (>index) of this session */
} _ns_disp;
typedef struct __ns_efuns { /* callbacks into the terminal program */
int refcount; /* use calls below to set this up */
int (*set_scroll_x)(void *,int);
int (*set_scroll_y)(void *,int);
int (*set_scroll_w)(void *,int);
int (*set_scroll_h)(void *,int);
int (*redraw)(void *);
int (*redraw_xywh)(void *,int,int,int,int);
int (*ins_disp)(void *,int,char *);
int (*del_disp)(void *,int);
int (*upd_disp)(void *,int,int,char *);
int (*err_msg)(void *,int,char *);
int (*execute)(void *,char **);
int (*inp_text)(void *,int,char *);
} _ns_efuns;
typedef struct __ns_parse {
int screen;
int real;
int flags;
char *name;
} _ns_parse;
/***************************************************************************/
/* constructors/destructors */
_ns_efuns *ns_new_efuns(void);
_ns_efuns *ns_dst_efuns(_ns_efuns **);
_ns_efuns *ns_get_efuns(_ns_sess *,_ns_disp *);
/* debug */
void ns_desc_sess(_ns_sess *,char *);
/* convenience */
_ns_disp *disp_fetch_or_make(_ns_sess *,int);
/* transparent attach/detach */
_ns_sess *ns_attach_by_sess(_ns_sess **,int *);
_ns_sess *ns_attach_by_URL(char *,_ns_efuns **,int *,void *);
/* what the terminal should call the last line -- screen's "hardstatus"
changes. submit session, terminal-width, and a pointer to said line. */
int parse_screen(_ns_sess *,int,int,char *);
/* things the term might ask screen/scream to do ***************************/
int ns_scroll2x(_ns_sess *,int);
int ns_scroll2y(_ns_sess *,int);
int ns_go2_disp(_ns_sess *,int);
int ns_add_disp(_ns_sess *,int,char *);
int ns_rsz_disp(_ns_sess *,int,int,int);
int ns_rem_disp(_ns_sess *,int);
int ns_ren_disp(_ns_sess *,int,char *);
int ns_log_disp(_ns_sess *,int,char *);
int ns_upd_stat(_ns_sess *);
/* register efuns (callbacks) **********************************************/
void ns_register_ssx(_ns_efuns *,int (*set_scroll_x)(void *,int));
void ns_register_ssy(_ns_efuns *,int (*set_scroll_y)(void *,int));
void ns_register_ssw(_ns_efuns *,int (*set_scroll_w)(void *,int));
void ns_register_ssh(_ns_efuns *,int (*set_scroll_h)(void *,int));
void ns_register_red(_ns_efuns *,int (*redraw)(void *));
void ns_register_rda(_ns_efuns *,int (*redraw_xywh)(void *,int,int,int,int));
void ns_register_ins(_ns_efuns *,int (*ins_disp)(void *,int,char *));
void ns_register_del(_ns_efuns *,int (*del_disp)(void *,int));
void ns_register_upd(_ns_efuns *,int (*upd_disp)(void *,int,int,char *));
void ns_register_err(_ns_efuns *,int (*err_msg)(void *,int,char *));
void ns_register_exe(_ns_efuns *,int (*execute)(void *,char **));
void ns_register_txt(_ns_efuns *,int (*inp_text)(void *,int,char *));
/***************************************************************************/

56
src/screamcfg.h Normal file
View File

@ -0,0 +1,56 @@
/****************************************************************************
* scream::screamcfg.h
* user-tunable parameters for the routines to connect to screen and/or
* scream daemons.
* GNU Public Licence applies.
* 2002/04/19 Azundris incept
***************************************************************************/
/* NS_PARANOID enables checks for deviant "screen" behaviour.
libscream is a little more efficient (and still stable on my box)
without it, but leaving the checks out in the official version
would turn this into the living support nightmare. Thus, if you
undef it, you're on your own. */
#define NS_PARANOID
/* define NS_DEBUG to get debug-info. no support for those who undef this. */
#define NS_DEBUG
/* debug memory stuff. never actually used this. */
#undef NS_DEBUG_MEM
#define NS_SSH_CALL "ssh"
#define NS_SSH_OPTS "-t"
#define NS_SCREAM_CALL "scream"
#define NS_SCREAM_OPTS "-xRR"
#define NS_SCREEN_CALL "screen"
#define NS_SCREEN_OPTS "-c /dev/null -xRR"
#define NS_SCREEM_CALL "\"" NS_SCREAM_CALL " " NS_SCREAM_OPTS " 2>/dev/null || " NS_SCREEN_CALL " " NS_SCREEN_OPTS "\""
/* this should never change. the escape-char for an out-of-the-box "screen".
don't change this just because you set something else in your .screenrc */
#define NS_SCREEN_ESCAPE '\x01'
#define NS_SCREEN_LITERAL 'a'
/* the following must use the char defined in NS_SCREEN_ESCAPE. if something
else is used in the session, libscream will convert it on the fly. */
/* DO NOT use \005Lw for your status, it breaks older screens!! */
#define NS_SCREEN_UPDATE "\x01w"
#define NS_SCREEN_INIT "\x01:hardstatus lastline\r\x01:defhstatus \"\\005w\"\r\x01:hstatus \"\\005w\"\r" NS_SCREEN_UPDATE
#define NS_DFLT_SSH_PORT 22
#define NS_MAX_PORT 65535
#define NS_MAX_DISPS 512
#define NS_SCREEN_FLAGS "*-$!@L&Z"
/* if >0, force an update every NS_SCREEN_UPD_FREQ seconds.
a bit of a last resort. */
#define NS_SCREEN_UPD_FREQ 0
/***************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -305,6 +305,9 @@ extern void debug_colors(void);
extern int scr_multi2(void);
extern int scr_multi1(void);
#endif /* MULTI_CHARSET */
#ifdef ESCREEN
extern void parse_screen_status_if_necessary(void);
#endif
_XFUNCPROTOEND

View File

@ -41,24 +41,23 @@ static const char cvs_ident[] = "$Id$";
#include "startup.h"
#include "system.h"
static eterm_script_handler_t script_handlers[] =
{
{ "copy", script_handler_copy },
{ "die", script_handler_exit },
{ "echo", script_handler_echo },
{ "exec", script_handler_spawn },
{ "exit", script_handler_exit },
{ "kill", script_handler_kill },
{ "paste", script_handler_paste },
{ "quit", script_handler_exit },
{ "save", script_handler_save },
{ "save_buff", script_handler_save_buff },
{ "scroll", script_handler_scroll },
{ "search", script_handler_search },
{ "spawn", script_handler_spawn },
{ "string", script_handler_string },
static eterm_script_handler_t script_handlers[] = {
{"copy", script_handler_copy},
{"die", script_handler_exit},
{"echo", script_handler_echo},
{"exec", script_handler_spawn},
{"exit", script_handler_exit},
{"kill", script_handler_kill},
{"paste", script_handler_paste},
{"quit", script_handler_exit},
{"save", script_handler_save},
{"save_buff", script_handler_save_buff},
{"scroll", script_handler_scroll},
{"search", script_handler_search},
{"spawn", script_handler_spawn},
{"string", script_handler_string},
{ "nop", script_handler_nop }
{"nop", script_handler_nop}
};
static size_t handler_count = sizeof(script_handlers) / sizeof(eterm_script_handler_t);
@ -66,63 +65,63 @@ static size_t handler_count = sizeof(script_handlers) / sizeof(eterm_script_hand
void
eterm_handle_winop(char *action)
{
char *winid;
Window win = 0;
char *winid;
Window win = 0;
ASSERT(action != NULL);
ASSERT(action != NULL);
winid = strchr(action, ' ');
if (winid) {
win = (Window) strtoul(winid + 1, (char **) NULL, 0);
}
if (win == 0) { /* If no window ID was given, or if the strtoul() call failed */
win = TermWin.parent;
}
if (!BEG_STRCASECMP(action, "raise")) {
XRaiseWindow(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "lower")) {
XLowerWindow(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "map")) {
XMapWindow(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "unmap")) {
XUnmapWindow(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "move")) {
int x, y, n;
char *xx, *yy;
n = num_words(action);
if (n == 3 || n == 4) {
if (n == 3) {
win = TermWin.parent;
}
xx = get_pword(n - 1, action);
yy = get_pword(n, action);
x = (int) strtol(xx, (char **) NULL, 0);
y = (int) strtol(yy, (char **) NULL, 0);
XMoveWindow(Xdisplay, win, x, y);
winid = strchr(action, ' ');
if (winid) {
win = (Window) strtoul(winid + 1, (char **) NULL, 0);
}
} else if (!BEG_STRCASECMP(action, "resize")) {
int w, h, n;
char *ww, *hh;
n = num_words(action);
if (n == 3 || n == 4) {
if (n == 3) {
if (win == 0) { /* If no window ID was given, or if the strtoul() call failed */
win = TermWin.parent;
}
ww = get_pword(n - 1, action);
hh = get_pword(n, action);
w = (int) strtol(ww, (char **) NULL, 0);
h = (int) strtol(hh, (char **) NULL, 0);
XResizeWindow(Xdisplay, win, w, h);
}
} else if (!BEG_STRCASECMP(action, "kill")) {
XKillClient(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "iconify")) {
XIconifyWindow(Xdisplay, win, Xscreen);
} else {
print_error("IPC Error: Unrecognized window operation \"%s\"\n", action);
}
if (!BEG_STRCASECMP(action, "raise")) {
XRaiseWindow(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "lower")) {
XLowerWindow(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "map")) {
XMapWindow(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "unmap")) {
XUnmapWindow(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "move")) {
int x, y, n;
char *xx, *yy;
n = num_words(action);
if (n == 3 || n == 4) {
if (n == 3) {
win = TermWin.parent;
}
xx = get_pword(n - 1, action);
yy = get_pword(n, action);
x = (int) strtol(xx, (char **) NULL, 0);
y = (int) strtol(yy, (char **) NULL, 0);
XMoveWindow(Xdisplay, win, x, y);
}
} else if (!BEG_STRCASECMP(action, "resize")) {
int w, h, n;
char *ww, *hh;
n = num_words(action);
if (n == 3 || n == 4) {
if (n == 3) {
win = TermWin.parent;
}
ww = get_pword(n - 1, action);
hh = get_pword(n, action);
w = (int) strtol(ww, (char **) NULL, 0);
h = (int) strtol(hh, (char **) NULL, 0);
XResizeWindow(Xdisplay, win, w, h);
}
} else if (!BEG_STRCASECMP(action, "kill")) {
XKillClient(Xdisplay, win);
} else if (!BEG_STRCASECMP(action, "iconify")) {
XIconifyWindow(Xdisplay, win, Xscreen);
} else {
print_error("IPC Error: Unrecognized window operation \"%s\"\n", action);
}
}
#endif
@ -142,28 +141,28 @@ eterm_handle_winop(char *action)
void
script_handler_copy(char **params)
{
unsigned char i;
char *buffer_id;
Atom sel = XA_PRIMARY;
unsigned char i;
char *buffer_id;
Atom sel = XA_PRIMARY;
if (params) {
for (i = 0; (buffer_id = params[i]) != NULL; i++) {
if (*buffer_id) {
if (*buffer_id >= '0' && *buffer_id <= '7') {
sel = (Atom) ((int) XA_CUT_BUFFER0 + (int) *buffer_id);
} else if (!BEG_STRCASECMP(buffer_id, "clipboard")) {
sel = XA_CLIPBOARD(Xdisplay);
} else if (!BEG_STRCASECMP(buffer_id, "primary")) {
sel = XA_PRIMARY;
} else if (!BEG_STRCASECMP(buffer_id, "secondary")) {
sel = XA_SECONDARY;
} else {
print_error("Invalid parameter to copy(): \"%s\"\n", buffer_id);
if (params) {
for (i = 0; (buffer_id = params[i]) != NULL; i++) {
if (*buffer_id) {
if (*buffer_id >= '0' && *buffer_id <= '7') {
sel = (Atom) ((int) XA_CUT_BUFFER0 + (int) *buffer_id);
} else if (!BEG_STRCASECMP(buffer_id, "clipboard")) {
sel = XA_CLIPBOARD(Xdisplay);
} else if (!BEG_STRCASECMP(buffer_id, "primary")) {
sel = XA_PRIMARY;
} else if (!BEG_STRCASECMP(buffer_id, "secondary")) {
sel = XA_SECONDARY;
} else {
print_error("Invalid parameter to copy(): \"%s\"\n", buffer_id);
}
}
}
}
}
}
selection_copy(sel);
selection_copy(sel);
}
/* echo(): Send a string to the pty
@ -175,11 +174,11 @@ script_handler_copy(char **params)
void
script_handler_echo(char **params)
{
char **tmp;
char **tmp;
for (tmp = params; tmp && *tmp; tmp++) {
tt_write(*tmp, strlen(*tmp));
}
for (tmp = params; tmp && *tmp; tmp++) {
tt_write(*tmp, strlen(*tmp));
}
}
/* exit(): Exit Eterm with an optional message or return code
@ -194,19 +193,19 @@ script_handler_echo(char **params)
void
script_handler_exit(char **params)
{
unsigned char code = 0;
char *tmp;
unsigned char code = 0;
char *tmp;
if (params && *params) {
if (isdigit(params[0][0]) || (params[0][0] == '-' && isdigit(params[0][1]))) {
code = (unsigned char) atoi(params[0]);
} else {
tmp = join(" ", params);
printf("Exiting: %s\n", tmp);
FREE(tmp);
if (params && *params) {
if (isdigit(params[0][0]) || (params[0][0] == '-' && isdigit(params[0][1]))) {
code = (unsigned char) atoi(params[0]);
} else {
tmp = join(" ", params);
printf("Exiting: %s\n", tmp);
FREE(tmp);
}
}
}
exit(code);
exit(code);
}
/* kill(): Send a given signal to Eterm's child process
@ -219,14 +218,14 @@ script_handler_exit(char **params)
void
script_handler_kill(char **params)
{
int sig;
int sig;
if (params && *params) {
sig = atoi(params[0]);
} else {
sig = SIGTERM;
}
kill(cmd_pid, sig);
if (params && *params) {
sig = atoi(params[0]);
} else {
sig = SIGTERM;
}
kill(cmd_pid, sig);
}
/* paste(): Paste the contents of the specified clipboard or cut buffer
@ -243,28 +242,28 @@ script_handler_kill(char **params)
void
script_handler_paste(char **params)
{
unsigned char i;
char *buffer_id;
Atom sel = XA_PRIMARY;
unsigned char i;
char *buffer_id;
Atom sel = XA_PRIMARY;
if (params) {
for (i = 0; (buffer_id = params[i]) != NULL; i++) {
if (*buffer_id) {
if (*buffer_id >= '0' && *buffer_id <= '7') {
sel = (Atom) ((int) XA_CUT_BUFFER0 + (int) *buffer_id);
} else if (!BEG_STRCASECMP(buffer_id, "clipboard")) {
sel = XA_CLIPBOARD(Xdisplay);
} else if (!BEG_STRCASECMP(buffer_id, "primary")) {
sel = XA_PRIMARY;
} else if (!BEG_STRCASECMP(buffer_id, "secondary")) {
sel = XA_SECONDARY;
} else {
print_error("Invalid parameter to paste(): \"%s\"\n", buffer_id);
if (params) {
for (i = 0; (buffer_id = params[i]) != NULL; i++) {
if (*buffer_id) {
if (*buffer_id >= '0' && *buffer_id <= '7') {
sel = (Atom) ((int) XA_CUT_BUFFER0 + (int) *buffer_id);
} else if (!BEG_STRCASECMP(buffer_id, "clipboard")) {
sel = XA_CLIPBOARD(Xdisplay);
} else if (!BEG_STRCASECMP(buffer_id, "primary")) {
sel = XA_PRIMARY;
} else if (!BEG_STRCASECMP(buffer_id, "secondary")) {
sel = XA_SECONDARY;
} else {
print_error("Invalid parameter to paste(): \"%s\"\n", buffer_id);
}
}
}
}
}
}
selection_paste(sel);
selection_paste(sel);
}
/* save(): Save the current theme/user configuration
@ -280,15 +279,15 @@ script_handler_paste(char **params)
void
script_handler_save(char **params)
{
if (params && *params) {
if (!strcasecmp(params[0], "theme")) {
save_config(params[1], SAVE_THEME_CONFIG);
if (params && *params) {
if (!strcasecmp(params[0], "theme")) {
save_config(params[1], SAVE_THEME_CONFIG);
} else {
save_config(params[0], SAVE_USER_CONFIG);
}
} else {
save_config(params[0], SAVE_USER_CONFIG);
save_config(NULL, SAVE_USER_CONFIG);
}
} else {
save_config(NULL, SAVE_USER_CONFIG);
}
}
/* save_buff(): Dump the scrollback buffer to a file
@ -301,9 +300,9 @@ script_handler_save(char **params)
void
script_handler_save_buff(char **params)
{
if (params && *params) {
scr_dump_to_file(params[0]);
}
if (params && *params) {
scr_dump_to_file(params[0]);
}
}
/* scroll(): Scroll backward or forward in the scrollback buffer
@ -321,43 +320,43 @@ script_handler_save_buff(char **params)
void
script_handler_scroll(char **params)
{
char *type;
double cnt_float;
long count;
int direction = DN;
char *type;
double cnt_float;
long count;
int direction = DN;
if (params && *params) {
cnt_float = strtod(params[0], &type);
if (cnt_float == 0.0) {
return;
} else if (cnt_float < 0.0) {
cnt_float = -cnt_float;
direction = UP;
}
if (!type) {
type = params[1];
}
if (type && *type) {
for (; *type && !isalpha(*type); type++);
if (str_leading_match("lines", type)) {
count = (long) cnt_float;
} else if (str_leading_match("pages", type) || str_leading_match("screens", type)) {
count = (long) ((cnt_float * TermWin.nrow) - CONTEXT_LINES);
} else if (str_leading_match("buffers", type)) {
count = (long) (cnt_float * (TermWin.nrow + TermWin.saveLines));
} else {
print_error("Invalid modifier \"%s\" in scroll()\n", type);
return;
}
} else {
count = (long) cnt_float;
}
if (params && *params) {
cnt_float = strtod(params[0], &type);
if (cnt_float == 0.0) {
return;
} else if (cnt_float < 0.0) {
cnt_float = -cnt_float;
direction = UP;
}
if (!type) {
type = params[1];
}
if (type && *type) {
for (; *type && !isalpha(*type); type++);
if (str_leading_match("lines", type)) {
count = (long) cnt_float;
} else if (str_leading_match("pages", type) || str_leading_match("screens", type)) {
count = (long) ((cnt_float * TermWin.nrow) - CONTEXT_LINES);
} else if (str_leading_match("buffers", type)) {
count = (long) (cnt_float * (TermWin.nrow + TermWin.saveLines));
} else {
print_error("Invalid modifier \"%s\" in scroll()\n", type);
return;
}
} else {
count = (long) cnt_float;
}
if (count <= 0) {
return;
if (count <= 0) {
return;
}
scr_page(direction, count);
}
scr_page(direction, count);
}
}
/* search(): Search the scrollback buffer for a string and highlight
@ -371,7 +370,7 @@ script_handler_scroll(char **params)
void
script_handler_search(char **params)
{
scr_search_scrollback(params ? params[0] : NULL);
scr_search_scrollback(params ? params[0] : NULL);
}
/* spawn(): Spawns a child process to execute a sub-command
@ -383,15 +382,15 @@ script_handler_search(char **params)
void
script_handler_spawn(char **params)
{
char *tmp;
char *tmp;
if (params && *params) {
tmp = join(" ", params);
system_no_wait(tmp);
FREE(tmp);
} else {
system_no_wait("Eterm");
}
if (params && *params) {
tmp = join(" ", params);
system_no_wait(tmp);
FREE(tmp);
} else {
system_no_wait("Eterm");
}
}
/* string(): Send a string to Eterm's escape code handler
@ -403,11 +402,11 @@ script_handler_spawn(char **params)
void
script_handler_string(char **params)
{
char **tmp;
char **tmp;
for (tmp = params; tmp && *tmp; tmp++) {
cmd_write(*tmp, strlen(*tmp));
}
for (tmp = params; tmp && *tmp; tmp++) {
cmd_write(*tmp, strlen(*tmp));
}
}
/* nop(): Do nothing
@ -419,92 +418,91 @@ script_handler_string(char **params)
void
script_handler_nop(char **params)
{
USE_VAR(params);
USE_VAR(params);
}
/********* ENGINE *********/
eterm_script_handler_t *
script_find_handler(const char *name)
eterm_script_handler_t *script_find_handler(const char *name)
{
register unsigned long i;
register unsigned long i;
for (i = 0; i < handler_count; i++) {
/* Small optimization. Only call strcasecmp() if the first letter matches. */
if ((tolower(name[0]) == tolower(script_handlers[i].name[0]))
&& !strcasecmp(name, script_handlers[i].name)) {
return &script_handlers[i];
for (i = 0; i < handler_count; i++) {
/* Small optimization. Only call strcasecmp() if the first letter matches. */
if ((tolower(name[0]) == tolower(script_handlers[i].name[0]))
&& !strcasecmp(name, script_handlers[i].name)) {
return &script_handlers[i];
}
}
}
return NULL;
return NULL;
}
void
script_parse(char *s)
{
char **token_list, **param_list;
register char *pstr;
register unsigned long i;
char *func_name, *params, *tmp;
size_t len;
eterm_script_handler_t *func;
char **token_list, **param_list;
register char *pstr;
register unsigned long i;
char *func_name, *params, *tmp;
size_t len;
eterm_script_handler_t *func;
REQUIRE(s != NULL);
REQUIRE(s != NULL);
D_SCRIPT(("Parsing: \"%s\"\n", s));
D_SCRIPT(("Parsing: \"%s\"\n", s));
token_list = split(";", s);
if (token_list == NULL) {
D_SCRIPT(("No tokens found; ignoring script.\n"));
return;
}
for (i = 0; token_list[i]; i++) {
pstr = token_list[i];
chomp(pstr);
if (!(*pstr)) {
continue;
}
if ((params = strchr(pstr, '(')) != NULL) {
if (params != pstr) {
len = params - pstr;
func_name = (char *) MALLOC(len + 1);
strncpy(func_name, pstr, len);
func_name[len] = 0;
} else {
print_error("Error in script \"%s\": Missing function name before \"%s\".\n", s, params);
free_array((void **) token_list, 0);
token_list = split(";", s);
if (token_list == NULL) {
D_SCRIPT(("No tokens found; ignoring script.\n"));
return;
}
} else {
func_name = STRDUP(pstr);
}
if (!func_name) {
free_array((void **) token_list, 0);
return;
for (i = 0; token_list[i]; i++) {
pstr = token_list[i];
chomp(pstr);
if (!(*pstr)) {
continue;
}
if ((params = strchr(pstr, '(')) != NULL) {
if (params != pstr) {
len = params - pstr;
func_name = (char *) MALLOC(len + 1);
strncpy(func_name, pstr, len);
func_name[len] = 0;
} else {
print_error("Error in script \"%s\": Missing function name before \"%s\".\n", s, params);
free_array((void **) token_list, 0);
return;
}
} else {
func_name = STRDUP(pstr);
}
if (!func_name) {
free_array((void **) token_list, 0);
return;
}
if (params) {
params++;
if ((tmp = strrchr(params, ')')) != NULL) {
*tmp = 0;
} else {
print_error("Error in script \"%s\": Missing closing parentheses for \"%s\".\n", s, token_list[i]);
free_array((void **) token_list, 0);
return;
}
param_list = split(", \t", params);
} else {
param_list = NULL;
}
D_SCRIPT(("Calling function %s with parameters: %s\n", func_name, NONULL(params)));
if ((func = script_find_handler(func_name)) != NULL) {
(func->handler) (param_list);
} else {
print_error("Error in script \"%s\": No such function \"%s\".\n", s, func_name);
}
}
if (params) {
params++;
if ((tmp = strrchr(params, ')')) != NULL) {
*tmp = 0;
} else {
print_error("Error in script \"%s\": Missing closing parentheses for \"%s\".\n", s, token_list[i]);
free_array((void **) token_list, 0);
return;
}
param_list = split(", \t", params);
} else {
param_list = NULL;
free_array((void **) param_list, 0);
}
D_SCRIPT(("Calling function %s with parameters: %s\n", func_name, NONULL(params)));
if ((func = script_find_handler(func_name)) != NULL) {
(func->handler)(param_list);
} else {
print_error("Error in script \"%s\": No such function \"%s\".\n", s, func_name);
}
}
if (params) {
free_array((void **) param_list, 0);
}
free_array((void **) token_list, 0);
free_array((void **) token_list, 0);
}

File diff suppressed because it is too large Load Diff

View File

@ -53,6 +53,8 @@ static const char cvs_ident[] = "$Id$";
#include "term.h"
#include "windows.h"
#include "screamcfg.h"
char *orig_argv0;
#ifdef PIXMAP_SUPPORT
@ -62,7 +64,7 @@ char *orig_argv0;
short bg_needs_update = 1;
#endif
TermWin_t TermWin;
Display *Xdisplay; /* display */
Display *Xdisplay; /* display */
Colormap cmap;
char *display_name = NULL;
unsigned int colorfgbg;
@ -72,234 +74,257 @@ int
eterm_bootstrap(int argc, char *argv[])
{
int i;
char *val;
static char windowid_string[20], *display_string, *term_string; /* "WINDOWID=\0" = 10 chars, UINT_MAX = 10 chars */
orig_argv0 = argv[0];
int i;
char *val;
static char windowid_string[20], *display_string, *term_string; /* "WINDOWID=\0" = 10 chars, UINT_MAX = 10 chars */
orig_argv0 = argv[0];
/* Security enhancements -- mej */
putenv("IFS= \t\n");
my_ruid = getuid();
my_euid = geteuid();
my_rgid = getgid();
my_egid = getegid();
privileges(REVERT);
install_handlers();
/* Security enhancements -- mej */
putenv("IFS= \t\n");
my_ruid = getuid();
my_euid = geteuid();
my_rgid = getgid();
my_egid = getegid();
privileges(REVERT);
install_handlers();
PABLO_START_TRACING();
getcwd(initial_dir, PATH_MAX);
PABLO_START_TRACING();
getcwd(initial_dir, PATH_MAX);
libast_set_program_name(PACKAGE);
libast_set_program_version(VERSION);
libast_set_program_name(PACKAGE);
libast_set_program_version(VERSION);
/* Open display, get options/resources and create the window */
if (getenv("DISPLAY") == NULL) {
display_name = STRDUP(":0");
} else {
display_name = STRDUP(getenv("DISPLAY"));
}
/* Open display, get options/resources and create the window */
if (getenv("DISPLAY") == NULL) {
display_name = STRDUP(":0");
} else {
display_name = STRDUP(getenv("DISPLAY"));
}
/* This MUST be called before any other Xlib functions */
/* This MUST be called before any other Xlib functions */
get_initial_options(argc, argv);
init_defaults();
get_initial_options(argc, argv);
init_defaults();
#ifdef NEED_LINUX_HACK
privileges(INVOKE); /* xdm in new Linux versions requires ruid != root to open the display -- mej */
privileges(INVOKE); /* xdm in new Linux versions requires ruid != root to open the display -- mej */
#endif
Xdisplay = XOpenDisplay(display_name);
Xdisplay = XOpenDisplay(display_name);
#ifdef NEED_LINUX_HACK
privileges(REVERT);
privileges(REVERT);
#endif
if (!Xdisplay) {
print_error("can't open display %s\n", display_name);
exit(EXIT_FAILURE);
}
XSetErrorHandler((XErrorHandler) xerror_handler);
if (!Xdisplay) {
print_error("can't open display %s\n", display_name);
exit(EXIT_FAILURE);
}
XSetErrorHandler((XErrorHandler) xerror_handler);
if (Options & Opt_install) {
cmap = XCreateColormap(Xdisplay, Xroot, Xvisual, AllocNone);
XInstallColormap(Xdisplay, cmap);
} else {
cmap = Xcmap;
}
if (Options & Opt_install) {
cmap = XCreateColormap(Xdisplay, Xroot, Xvisual, AllocNone);
XInstallColormap(Xdisplay, cmap);
} else {
cmap = Xcmap;
}
#ifdef PIXMAP_SUPPORT
imlib_context_set_display(Xdisplay);
imlib_context_set_visual(Xvisual);
imlib_context_set_colormap(cmap);
imlib_context_set_dither_mask(0);
imlib_context_set_display(Xdisplay);
imlib_context_set_visual(Xvisual);
imlib_context_set_colormap(cmap);
imlib_context_set_dither_mask(0);
#endif
get_modifiers(); /* Set up modifier masks before parsing config files. */
get_modifiers(); /* Set up modifier masks before parsing config files. */
/* Get all our properties set up. */
MEMSET(props, 0, sizeof(props));
props[PROP_DESKTOP] = XInternAtom(Xdisplay, "_WIN_WORKSPACE", False);
props[PROP_TRANS_PIXMAP] = XInternAtom(Xdisplay, "_XROOTPMAP_ID", False);
props[PROP_TRANS_COLOR] = XInternAtom(Xdisplay, "_XROOTCOLOR_PIXEL", False);
props[PROP_SELECTION_DEST] = XInternAtom(Xdisplay, "VT_SELECTION", False);
props[PROP_SELECTION_INCR] = XInternAtom(Xdisplay, "INCR", False);
props[PROP_SELECTION_TARGETS] = XInternAtom(Xdisplay, "TARGETS", False);
props[PROP_ENL_COMMS] = XInternAtom(Xdisplay, "ENLIGHTENMENT_COMMS", True);
props[PROP_ENL_MSG] = XInternAtom(Xdisplay, "ENL_MSG", False);
props[PROP_DELETE_WINDOW] = XInternAtom(Xdisplay, "WM_DELETE_WINDOW", False);
props[PROP_DND_PROTOCOL] = XInternAtom(Xdisplay, "DndProtocol", False);
props[PROP_DND_SELECTION] = XInternAtom(Xdisplay, "DndSelection", False);
/* Get all our properties set up. */
MEMSET(props, 0, sizeof(props));
props[PROP_DESKTOP] = XInternAtom(Xdisplay, "_WIN_WORKSPACE", False);
props[PROP_TRANS_PIXMAP] = XInternAtom(Xdisplay, "_XROOTPMAP_ID", False);
props[PROP_TRANS_COLOR] = XInternAtom(Xdisplay, "_XROOTCOLOR_PIXEL", False);
props[PROP_SELECTION_DEST] = XInternAtom(Xdisplay, "VT_SELECTION", False);
props[PROP_SELECTION_INCR] = XInternAtom(Xdisplay, "INCR", False);
props[PROP_SELECTION_TARGETS] = XInternAtom(Xdisplay, "TARGETS", False);
props[PROP_ENL_COMMS] = XInternAtom(Xdisplay, "ENLIGHTENMENT_COMMS", True);
props[PROP_ENL_MSG] = XInternAtom(Xdisplay, "ENL_MSG", False);
props[PROP_DELETE_WINDOW] = XInternAtom(Xdisplay, "WM_DELETE_WINDOW", False);
props[PROP_DND_PROTOCOL] = XInternAtom(Xdisplay, "DndProtocol", False);
props[PROP_DND_SELECTION] = XInternAtom(Xdisplay, "DndSelection", False);
if ((theme_dir = conf_parse_theme(&rs_theme, THEME_CFG, PARSE_TRY_ALL)) != NULL) {
char *tmp;
if ((theme_dir = conf_parse_theme(&rs_theme, THEME_CFG, PARSE_TRY_ALL)) != NULL) {
char *tmp;
D_OPTIONS(("conf_parse_theme() returned \"%s\"\n", theme_dir));
tmp = (char *) MALLOC(strlen(theme_dir) + sizeof("ETERM_THEME_ROOT=\0"));
sprintf(tmp, "ETERM_THEME_ROOT=%s", theme_dir);
putenv(tmp);
}
if ((user_dir = conf_parse_theme(&rs_theme, (rs_config_file ? rs_config_file : USER_CFG),
(PARSE_TRY_USER_THEME | PARSE_TRY_NO_THEME))) != NULL) {
char *tmp;
D_OPTIONS(("conf_parse_theme() returned \"%s\"\n", user_dir));
tmp = (char *) MALLOC(strlen(user_dir) + sizeof("ETERM_USER_ROOT=\0"));
sprintf(tmp, "ETERM_USER_ROOT=%s", user_dir);
putenv(tmp);
}
D_OPTIONS(("conf_parse_theme() returned \"%s\"\n", theme_dir));
tmp = (char *) MALLOC(strlen(theme_dir) + sizeof("ETERM_THEME_ROOT=\0"));
sprintf(tmp, "ETERM_THEME_ROOT=%s", theme_dir);
putenv(tmp);
}
if ((user_dir = conf_parse_theme(&rs_theme, (rs_config_file ? rs_config_file : USER_CFG),
(PARSE_TRY_USER_THEME | PARSE_TRY_NO_THEME))) != NULL) {
char *tmp;
D_OPTIONS(("conf_parse_theme() returned \"%s\"\n", user_dir));
tmp = (char *) MALLOC(strlen(user_dir) + sizeof("ETERM_USER_ROOT=\0"));
sprintf(tmp, "ETERM_USER_ROOT=%s", user_dir);
putenv(tmp);
}
#if defined(PIXMAP_SUPPORT)
if (rs_path || theme_dir || user_dir) {
register unsigned long len;
register char *tmp;
if (rs_path || theme_dir || user_dir) {
register unsigned long len;
register char *tmp;
len = strlen(initial_dir);
if (rs_path) {
len += strlen(rs_path) + 1; /* +1 for the colon */
len = strlen(initial_dir);
if (rs_path) {
len += strlen(rs_path) + 1; /* +1 for the colon */
}
if (theme_dir) {
len += strlen(theme_dir) + 1;
}
if (user_dir) {
len += strlen(user_dir) + 1;
}
tmp = MALLOC(len + 1); /* +1 here for the NUL */
snprintf(tmp, len + 1, "%s%s%s%s%s%s%s", (rs_path ? rs_path : ""), (rs_path ? ":" : ""), initial_dir,
(theme_dir ? ":" : ""), (theme_dir ? theme_dir : ""), (user_dir ? ":" : ""), (user_dir ? user_dir : ""));
tmp[len] = '\0';
FREE(rs_path);
rs_path = tmp;
D_OPTIONS(("New rs_path set to \"%s\"\n", rs_path));
}
if (theme_dir) {
len += strlen(theme_dir) + 1;
}
if (user_dir) {
len += strlen(user_dir) + 1;
}
tmp = MALLOC(len + 1); /* +1 here for the NUL */
snprintf(tmp, len + 1, "%s%s%s%s%s%s%s", (rs_path ? rs_path : ""), (rs_path ? ":" : ""), initial_dir,
(theme_dir ? ":" : ""), (theme_dir ? theme_dir : ""), (user_dir ? ":" : ""), (user_dir ? user_dir : ""));
tmp[len] = '\0';
FREE(rs_path);
rs_path = tmp;
D_OPTIONS(("New rs_path set to \"%s\"\n", rs_path));
}
#endif
get_options(argc, argv);
D_UTMP(("Saved real uid/gid = [ %d, %d ] effective uid/gid = [ %d, %d ]\n", my_ruid, my_rgid, my_euid, my_egid));
D_UTMP(("Now running with real uid/gid = [ %d, %d ] effective uid/gid = [ %d, %d ]\n", getuid(), getgid(), geteuid(),
getegid()));
get_options(argc, argv);
D_UTMP(("Saved real uid/gid = [ %d, %d ] effective uid/gid = [ %d, %d ]\n", my_ruid, my_rgid, my_euid, my_egid));
D_UTMP(("Now running with real uid/gid = [ %d, %d ] effective uid/gid = [ %d, %d ]\n", getuid(), getgid(), geteuid(), getegid()));
post_parse();
#ifdef ESCREEN
TermWin.screen = NULL;
TermWin.screen_mode = NS_MODE_NONE;
{
char *p = strrchr(orig_argv0, '/');
# define ESCREEN_PREFIX "Escreen"
# define ETERM_PREFIX "Eterm"
p = p ? (p + 1) : orig_argv0;
if (rs_url || !strncasecmp(ESCREEN_PREFIX, p, strlen(ESCREEN_PREFIX)))
TermWin.screen_mode = NS_MODE_SCREEN;
# ifdef NS_DEBUG
if (!strncasecmp(ESCREEN_PREFIX, p, strlen(ESCREEN_PREFIX)))
fputs("You called me \"Escreen\"!\n", stderr);
else if (!strncasecmp(ETERM_PREFIX, p, strlen(ETERM_PREFIX)))
fputs("You called me \"Eterm\"!\n", stderr);
else
fputs("Stop calling me funky names!\n", stderr);
fprintf(stderr, "Escreen mode is %d (%d rows, %s)\n", TermWin.screen_mode, TermWin.nrow, rs_url);
# endif
}
#endif
post_parse();
#ifdef PREFER_24BIT
cmap = DefaultColormap(Xdisplay, Xscreen);
cmap = DefaultColormap(Xdisplay, Xscreen);
/*
* If depth is not 24, look for a 24bit visual.
*/
if (Xdepth != 24) {
XVisualInfo vinfo;
/*
* If depth is not 24, look for a 24bit visual.
*/
if (Xdepth != 24) {
XVisualInfo vinfo;
if (XMatchVisualInfo(Xdisplay, Xscreen, 24, TrueColor, &vinfo)) {
Xdepth = 24;
Xvisual = vinfo.visual;
cmap = XCreateColormap(Xdisplay, RootWindow(Xdisplay, Xscreen),
Xvisual, AllocNone);
if (XMatchVisualInfo(Xdisplay, Xscreen, 24, TrueColor, &vinfo)) {
Xdepth = 24;
Xvisual = vinfo.visual;
cmap = XCreateColormap(Xdisplay, RootWindow(Xdisplay, Xscreen), Xvisual, AllocNone);
}
}
}
#endif
process_colors();
process_colors();
Create_Windows(argc, argv);
scr_reset(); /* initialize screen */
Create_Windows(argc, argv);
#ifdef ESCREEN
if (TermWin.screen_mode)
TermWin.nrow++;
#endif
scr_reset(); /* initialize screen */
/* Initialize the scrollbar */
scrollbar_init(szHint.width, szHint.height - bbar_calc_docked_height(BBAR_DOCKED));
scrollbar_mapping((Options & Opt_scrollbar) && !((Options & Opt_scrollbar_popup) && !TermWin.focus));
/* Initialize the scrollbar */
scrollbar_init(szHint.width, szHint.height - bbar_calc_docked_height(BBAR_DOCKED));
scrollbar_mapping((Options & Opt_scrollbar) && !((Options & Opt_scrollbar_popup) && !TermWin.focus));
/* Initialize the menu subsystem. */
menu_init();
if (buttonbar) {
bbar_init(buttonbar, szHint.width);
}
/* Initialize the menu subsystem. */
menu_init();
if (buttonbar) {
bbar_init(buttonbar, szHint.width);
}
#if DEBUG >= DEBUG_X
if (DEBUG_LEVEL >= DEBUG_X) {
XSync(Xdisplay, False);
XSynchronize(Xdisplay, True);
}
if (DEBUG_LEVEL >= DEBUG_X) {
XSync(Xdisplay, False);
XSynchronize(Xdisplay, True);
}
#endif
#ifdef DISPLAY_IS_IP
/* Fixup display_name for export over pty to any interested terminal
* clients via "ESC[7n" (e.g. shells). Note we use the pure IP number
* (for the first non-loopback interface) that we get from
* network_display(). This is more "name-resolution-portable", if you
* will, and probably allows for faster x-client startup if your name
* server is beyond a slow link or overloaded at client startup. Of
* course that only helps the shell's child processes, not us.
*
* Giving out the display_name also affords a potential security hole
*/
/* Fixup display_name for export over pty to any interested terminal
* clients via "ESC[7n" (e.g. shells). Note we use the pure IP number
* (for the first non-loopback interface) that we get from
* network_display(). This is more "name-resolution-portable", if you
* will, and probably allows for faster x-client startup if your name
* server is beyond a slow link or overloaded at client startup. Of
* course that only helps the shell's child processes, not us.
*
* Giving out the display_name also affords a potential security hole
*/
val = display_name = network_display(display_name);
if (val == NULL)
val = display_name = network_display(display_name);
if (val == NULL)
#endif /* DISPLAY_IS_IP */
val = XDisplayString(Xdisplay);
if (display_name == NULL)
display_name = val; /* use broken `:0' value */
val = XDisplayString(Xdisplay);
if (display_name == NULL)
display_name = val; /* use broken `:0' value */
i = strlen(val);
display_string = MALLOC(i + 9);
i = strlen(val);
display_string = MALLOC(i + 9);
sprintf(display_string, "DISPLAY=%s", val);
sprintf(windowid_string, "WINDOWID=%u", (unsigned int) TermWin.parent);
sprintf(display_string, "DISPLAY=%s", val);
sprintf(windowid_string, "WINDOWID=%u", (unsigned int) TermWin.parent);
/* add entries to the environment:
* DISPLAY: X display name
* WINDOWID: X windowid of the window
* COLORTERM: Terminal supports color
* COLORTERM_BCE: Terminal supports BCE
* TERM: Terminal type for termcap/terminfo
*/
putenv(display_string);
putenv(windowid_string);
if (Xdepth <= 2) {
putenv("COLORTERM=" COLORTERMENV "-mono");
putenv("COLORTERM_BCE=" COLORTERMENV "-mono");
putenv("TERM=" TERMENV);
} else {
if (rs_term_name != NULL) {
i = strlen(rs_term_name);
term_string = MALLOC(i + 6);
sprintf(term_string, "TERM=%s", rs_term_name);
putenv(term_string);
/* add entries to the environment:
* DISPLAY: X display name
* WINDOWID: X windowid of the window
* COLORTERM: Terminal supports color
* COLORTERM_BCE: Terminal supports BCE
* TERM: Terminal type for termcap/terminfo
*/
putenv(display_string);
putenv(windowid_string);
if (Xdepth <= 2) {
putenv("COLORTERM=" COLORTERMENV "-mono");
putenv("COLORTERM_BCE=" COLORTERMENV "-mono");
putenv("TERM=" TERMENV);
} else {
if (rs_term_name != NULL) {
i = strlen(rs_term_name);
term_string = MALLOC(i + 6);
sprintf(term_string, "TERM=%s", rs_term_name);
putenv(term_string);
} else {
#ifdef DEFINE_XTERM_COLOR
if (Xdepth <= 2)
putenv("TERM=" TERMENV);
else
putenv("TERM=" TERMENV "-color");
if (Xdepth <= 2)
putenv("TERM=" TERMENV);
else
putenv("TERM=" TERMENV "-color");
#else
putenv("TERM=" TERMENV);
putenv("TERM=" TERMENV);
#endif
}
putenv("COLORTERM=" COLORTERMENV);
putenv("COLORTERM_BCE=" COLORTERMENV);
}
putenv("COLORTERM=" COLORTERMENV);
putenv("COLORTERM_BCE=" COLORTERMENV);
}
putenv("ETERM_VERSION=" VERSION);
putenv("ETERM_VERSION=" VERSION);
D_CMD(("init_command()\n"));
init_command(rs_exec_args);
D_CMD(("init_command()\n"));
init_command(rs_exec_args);
main_loop();
main_loop();
return (EXIT_SUCCESS);
return (EXIT_SUCCESS);
}

View File

@ -31,6 +31,9 @@
#include <stdlib.h>
#include <string.h>
#include "misc.h"
#ifdef ESCREEN
#include "scream.h"
#endif
/************ Macros and Definitions ************/
#ifndef EXIT_SUCCESS /* missing from <stdlib.h> */
@ -107,6 +110,11 @@ typedef struct {
#ifdef MULTI_CHARSET
XFontStruct * mfont; /* multibyte font structure */
#endif
#ifdef ESCREEN
_ns_sess *screen;
short screen_pending;
short screen_mode;
#endif
} TermWin_t;
/************ Variables ************/

View File

@ -45,37 +45,37 @@ static const char cvs_ident[] = "$Id$";
int
wait_for_chld(int system_pid)
{
int pid, status = 0, save_errno = errno, code;
int pid, status = 0, save_errno = errno, code;
D_OPTIONS(("wait_for_chld(%ld) called.\n", system_pid));
D_OPTIONS(("wait_for_chld(%ld) called.\n", system_pid));
while (1) {
do {
errno = 0;
} while ((((pid = waitpid(system_pid, &status, WNOHANG)) == -1) && (errno == EINTR)) || !pid);
/* If the child that exited is the command we spawned, or if the
child exited before fork() returned in the parent, it must be
our immediate child that exited. We exit gracefully. */
if ((pid == -1) && (errno == ECHILD)) { /* No children exist. Punt. */
errno = save_errno;
break;
while (1) {
do {
errno = 0;
} while ((((pid = waitpid(system_pid, &status, WNOHANG)) == -1) && (errno == EINTR)) || !pid);
/* If the child that exited is the command we spawned, or if the
child exited before fork() returned in the parent, it must be
our immediate child that exited. We exit gracefully. */
if ((pid == -1) && (errno == ECHILD)) { /* No children exist. Punt. */
errno = save_errno;
break;
}
D_OPTIONS(("%ld exited.\n", pid));
if (pid == system_pid || system_pid == -1) {
if (WIFEXITED(status)) {
code = WEXITSTATUS(status);
D_OPTIONS(("Child process exited with return code %lu\n", code));
} else if (WIFSIGNALED(status)) {
code = WTERMSIG(status);
D_OPTIONS(("Child process was terminated by unhandled signal %lu\n", code));
} else {
code = 0;
}
return (code);
}
errno = save_errno;
}
D_OPTIONS(("%ld exited.\n", pid));
if (pid == system_pid || system_pid == -1) {
if (WIFEXITED(status)) {
code = WEXITSTATUS(status);
D_OPTIONS(("Child process exited with return code %lu\n", code));
} else if (WIFSIGNALED(status)) {
code = WTERMSIG(status);
D_OPTIONS(("Child process was terminated by unhandled signal %lu\n", code));
} else {
code = 0;
}
return (code);
}
errno = save_errno;
}
return 0;
return 0;
}
/* Replace the system() call with a fork-and-exec that unprivs the child process */
@ -84,37 +84,37 @@ int
system_wait(char *command)
{
pid_t pid;
pid_t pid;
D_OPTIONS(("system_wait(%s) called.\n", command));
D_OPTIONS(("system_wait(%s) called.\n", command));
if (!(pid = fork())) {
setreuid(my_ruid, my_ruid);
setregid(my_rgid, my_rgid);
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
print_error("execl(%s) failed -- %s\n", command, strerror(errno));
exit(EXIT_FAILURE);
} else {
D_OPTIONS(("%d: fork() returned %d\n", getpid(), pid));
return (wait_for_chld(pid));
}
ASSERT_NOTREACHED_RVAL(0);
if (!(pid = fork())) {
setreuid(my_ruid, my_ruid);
setregid(my_rgid, my_rgid);
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
print_error("execl(%s) failed -- %s\n", command, strerror(errno));
exit(EXIT_FAILURE);
} else {
D_OPTIONS(("%d: fork() returned %d\n", getpid(), pid));
return (wait_for_chld(pid));
}
ASSERT_NOTREACHED_RVAL(0);
}
int
system_no_wait(char *command)
{
pid_t pid;
pid_t pid;
D_OPTIONS(("system_no_wait(%s) called.\n", command));
D_OPTIONS(("system_no_wait(%s) called.\n", command));
if (!(pid = fork())) {
setreuid(my_ruid, my_ruid);
setregid(my_rgid, my_rgid);
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
print_error("execl(%s) failed -- %s\n", command, strerror(errno));
exit(EXIT_FAILURE);
}
return (0);
if (!(pid = fork())) {
setreuid(my_ruid, my_ruid);
setregid(my_rgid, my_rgid);
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
print_error("execl(%s) failed -- %s\n", command, strerror(errno));
exit(EXIT_FAILURE);
}
return (0);
}

3843
src/term.c

File diff suppressed because it is too large Load Diff

View File

@ -41,85 +41,91 @@ static const char cvs_ident[] = "$Id$";
static etimer_t *timers = NULL;
timerhdl_t
timer_add(unsigned long msec, timer_handler_t handler, void *data) {
timer_add(unsigned long msec, timer_handler_t handler, void *data)
{
static etimer_t *timer;
struct timeval tv;
static struct timezone tz;
static etimer_t *timer;
struct timeval tv;
static struct timezone tz;
if (!timers) {
timers = (etimer_t *) MALLOC(sizeof(etimer_t));
timer = timers;
} else {
timer->next = (etimer_t *) MALLOC(sizeof(etimer_t));
timer = timer->next;
}
timer->msec = msec;
gettimeofday(&tv, &tz);
timer->time.tv_sec = (msec / 1000) + tv.tv_sec;
timer->time.tv_usec = ((msec % 1000) * 1000) + tv.tv_usec;
timer->handler = handler;
timer->data = data;
timer->next = NULL;
D_TIMER(("Added timer. Timer set to %lu/%lu with handler %8p and data %8p\n", timer->time.tv_sec, timer->time.tv_usec, timer->handler, timer->data));
return ((timerhdl_t) timer);
}
unsigned char
timer_del(timerhdl_t handle) {
register etimer_t *current;
etimer_t *temp;
if (timers == handle) {
timers = handle->next;
FREE(handle);
return 1;
}
for (current = timers; current->next; current = current->next) {
if (current->next == handle) {
break;
if (!timers) {
timers = (etimer_t *) MALLOC(sizeof(etimer_t));
timer = timers;
} else {
timer->next = (etimer_t *) MALLOC(sizeof(etimer_t));
timer = timer->next;
}
}
if (!(current->next)) {
return 0;
}
temp = current->next;
current->next = temp->next;
FREE(temp);
return 1;
timer->msec = msec;
gettimeofday(&tv, &tz);
timer->time.tv_sec = (msec / 1000) + tv.tv_sec;
timer->time.tv_usec = ((msec % 1000) * 1000) + tv.tv_usec;
timer->handler = handler;
timer->data = data;
timer->next = NULL;
D_TIMER(("Added timer. Timer set to %lu/%lu with handler %8p and data %8p\n", timer->time.tv_sec, timer->time.tv_usec, timer->handler,
timer->data));
return ((timerhdl_t) timer);
}
unsigned char
timer_change_delay(timerhdl_t handle, unsigned long msec) {
timer_del(timerhdl_t handle)
{
struct timeval tv;
static struct timezone tz;
register etimer_t *current;
etimer_t *temp;
handle->msec = msec;
gettimeofday(&tv, &tz);
handle->time.tv_sec = (msec / 1000) + tv.tv_sec;
handle->time.tv_usec = ((msec % 1000) * 1000) + tv.tv_usec;
return 1;
if (timers == handle) {
timers = handle->next;
FREE(handle);
return 1;
}
for (current = timers; current->next; current = current->next) {
if (current->next == handle) {
break;
}
}
if (!(current->next)) {
return 0;
}
temp = current->next;
current->next = temp->next;
FREE(temp);
return 1;
}
unsigned char
timer_change_delay(timerhdl_t handle, unsigned long msec)
{
struct timeval tv;
static struct timezone tz;
handle->msec = msec;
gettimeofday(&tv, &tz);
handle->time.tv_sec = (msec / 1000) + tv.tv_sec;
handle->time.tv_usec = ((msec % 1000) * 1000) + tv.tv_usec;
return 1;
}
void
timer_check(void) {
timer_check(void)
{
register etimer_t *current;
struct timeval tv;
static struct timezone tz;
register etimer_t *current;
struct timeval tv;
static struct timezone tz;
if (!timers) return;
if (!timers)
return;
gettimeofday(&tv, &tz);
for (current = timers; current; current = current->next) {
if ((current->time.tv_sec > tv.tv_sec) || ((current->time.tv_sec == tv.tv_sec) && (current->time.tv_usec >= tv.tv_usec))) {
if (!((current->handler)(current->data))) {
timer_del(current);
} else {
timer_change_delay(current, current->msec);
}
gettimeofday(&tv, &tz);
for (current = timers; current; current = current->next) {
if ((current->time.tv_sec > tv.tv_sec) || ((current->time.tv_sec == tv.tv_sec) && (current->time.tv_usec >= tv.tv_usec))) {
if (!((current->handler) (current->data))) {
timer_del(current);
} else {
timer_change_delay(current, current->msec);
}
}
}
}
}

View File

@ -39,9 +39,9 @@ static const char cvs_ident[] = "$Id$";
/* don't go off end of ut_id & remember if an entry has been made */
# if defined(USE_SYSV_UTMP) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
static char ut_id[5]; /* remember if entry to utmp made */
static char ut_id[5]; /* remember if entry to utmp made */
# else
static int utmp_pos; /* BSD position of utmp-stamp */
static int utmp_pos; /* BSD position of utmp-stamp */
# endif
# ifdef USE_SYSV_UTMP
@ -50,171 +50,171 @@ static int utmp_pos; /* BSD position of utmp-stamp */
# undef WTMP_FILENAME
# define WTMP_FILENAME WTMPX_FILE
# define update_wtmp updwtmpx
# else /* HAVE_UTMPX_H */
# else /* HAVE_UTMPX_H */
static void
update_wtmp(char *fname, struct utmp *putmp)
{
int fd, retry = 10; /* 10 attempts at locking */
struct flock lck; /* fcntl locking scheme */
int fd, retry = 10; /* 10 attempts at locking */
struct flock lck; /* fcntl locking scheme */
if ((fd = open(fname, O_WRONLY | O_APPEND, 0)) < 0) {
D_UTMP(("Warning: Unable to open \"%s\" for writing -- %s\n", fname, strerror(errno)));
return;
}
lck.l_whence = SEEK_END; /* start lock at current eof */
lck.l_len = 0; /* end at ``largest possible eof'' */
lck.l_start = 0;
lck.l_type = F_WRLCK; /* we want a write lock */
/* attempt lock with F_SETLK - F_SETLKW would cause a deadlock! */
while (retry--) {
if ((fcntl(fd, F_SETLK, &lck) < 0) && errno != EACCESS) {
D_UTMP(("Warning: Unable to establish file lock on \"%s\" -- %s\n", fname, strerror(errno)));
close(fd);
return; /* failed for unknown reason: give up */
} else if (errno == EACCESS) {
D_UTMP(("Warning: Unable to establish file lock on \"%s\" -- %s\n", fname, strerror(errno)));
if ((fd = open(fname, O_WRONLY | O_APPEND, 0)) < 0) {
D_UTMP(("Warning: Unable to open \"%s\" for writing -- %s\n", fname, strerror(errno)));
return;
}
}
lck.l_whence = SEEK_END; /* start lock at current eof */
lck.l_len = 0; /* end at ``largest possible eof'' */
lck.l_start = 0;
lck.l_type = F_WRLCK; /* we want a write lock */
write(fd, putmp, sizeof(struct utmp));
/* attempt lock with F_SETLK - F_SETLKW would cause a deadlock! */
while (retry--) {
if ((fcntl(fd, F_SETLK, &lck) < 0) && errno != EACCESS) {
D_UTMP(("Warning: Unable to establish file lock on \"%s\" -- %s\n", fname, strerror(errno)));
close(fd);
return; /* failed for unknown reason: give up */
} else if (errno == EACCESS) {
D_UTMP(("Warning: Unable to establish file lock on \"%s\" -- %s\n", fname, strerror(errno)));
}
}
/* unlocking the file */
lck.l_type = F_UNLCK;
fcntl(fd, F_SETLK, &lck);
write(fd, putmp, sizeof(struct utmp));
close(fd);
/* unlocking the file */
lck.l_type = F_UNLCK;
fcntl(fd, F_SETLK, &lck);
close(fd);
}
# endif /* HAVE_UTMPX_H */
void
add_utmp_entry(const char *pty, const char *hostname, int fd)
{
struct passwd *pwent = getpwuid(my_ruid);
struct passwd *pwent = getpwuid(my_ruid);
# ifdef HAVE_UTMPX_H
struct utmpx utmp;
struct utmp utmp2;
MEMSET(&utmp, 0, sizeof(struct utmpx));
struct utmpx utmp;
struct utmp utmp2;
MEMSET(&utmp, 0, sizeof(struct utmpx));
# else
struct utmp utmp;
MEMSET(&utmp, 0, sizeof(struct utmp));
struct utmp utmp;
MEMSET(&utmp, 0, sizeof(struct utmp));
# endif
# ifdef WITH_DMALLOC
return;
return;
# endif
if (!strncmp(pty, "/dev/", 5))
pty += 5; /* skip /dev/ prefix */
if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3))
strncpy(ut_id, (pty + 3), sizeof(ut_id)); /* bsd naming */
else {
int n;
if (sscanf(pty, "pts/%d", &n) == 1)
sprintf(ut_id, "vt%02x", n); /* sysv naming */
if (!strncmp(pty, "/dev/", 5))
pty += 5; /* skip /dev/ prefix */
if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3))
strncpy(ut_id, (pty + 3), sizeof(ut_id)); /* bsd naming */
else {
print_error("can't parse tty name \"%s\"\n", pty);
ut_id[0] = '\0'; /* entry not made */
return;
int n;
if (sscanf(pty, "pts/%d", &n) == 1)
sprintf(ut_id, "vt%02x", n); /* sysv naming */
else {
print_error("can't parse tty name \"%s\"\n", pty);
ut_id[0] = '\0'; /* entry not made */
return;
}
}
}
strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
utmp.ut_type = DEAD_PROCESS;
strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
utmp.ut_type = DEAD_PROCESS;
privileges(INVOKE);
privileges(INVOKE);
# ifdef HAVE_UTMPX_H
getutmp(&utmp, &utmp2);
getutid(&utmp2); /* position to entry in utmp file */
getutmp(&utmp, &utmp2);
getutid(&utmp2); /* position to entry in utmp file */
# else
getutid(&utmp); /* position to entry in utmp file */
getutid(&utmp); /* position to entry in utmp file */
# endif
/* set up the new entry */
strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
strncpy(utmp.ut_line, pty, sizeof(utmp.ut_line));
strncpy(utmp.ut_name, pwent->pw_name, sizeof(utmp.ut_name));
strncpy(utmp.ut_user, pwent->pw_name, sizeof(utmp.ut_user));
strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
utmp.ut_type = USER_PROCESS;
utmp.ut_pid = getpid();
/* set up the new entry */
strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
strncpy(utmp.ut_line, pty, sizeof(utmp.ut_line));
strncpy(utmp.ut_name, pwent->pw_name, sizeof(utmp.ut_name));
strncpy(utmp.ut_user, pwent->pw_name, sizeof(utmp.ut_user));
strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
utmp.ut_type = USER_PROCESS;
utmp.ut_pid = getpid();
# ifdef HAVE_UTMPX_H
utmp.ut_session = getsid(0);
utmp.ut_xtime = time(NULL);
utmp.ut_tv.tv_usec = 0;
utmp.ut_session = getsid(0);
utmp.ut_xtime = time(NULL);
utmp.ut_tv.tv_usec = 0;
# else
utmp.ut_time = time(NULL);
utmp.ut_time = time(NULL);
# endif
/*
* write a utmp entry to the utmp file
*/
utmpname(UTMP_FILENAME);
/*
* write a utmp entry to the utmp file
*/
utmpname(UTMP_FILENAME);
# ifdef HAVE_UTMPX_H
getutmp(&utmp, &utmp2);
pututline(&utmp2);
pututxline(&utmp);
getutmp(&utmp, &utmp2);
pututline(&utmp2);
pututxline(&utmp);
# else
pututline(&utmp);
pututline(&utmp);
# endif
update_wtmp(WTMP_FILENAME, &utmp);
endutent(); /* close the file */
privileges(REVERT);
return;
fd = 0;
update_wtmp(WTMP_FILENAME, &utmp);
endutent(); /* close the file */
privileges(REVERT);
return;
fd = 0;
}
void
remove_utmp_entry(void)
{
# ifdef HAVE_UTMPX_H
struct utmp utmp;
struct utmpx utmpx;
struct utmp utmp;
struct utmpx utmpx;
if (!ut_id[0])
return; /* entry not made */
if (!ut_id[0])
return; /* entry not made */
utmpname(UTMP_FILENAME);
setutent();
strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
utmp.ut_type = USER_PROCESS;
if (getutid(&utmp) == NULL) {
return;
}
utmp.ut_type = DEAD_PROCESS;
utmp.ut_time = time(NULL);
pututline(&utmp);
getutmpx(&utmp, &utmpx);
update_wtmp(WTMP_FILENAME, &utmpx);
endutent();
utmpname(UTMP_FILENAME);
setutent();
strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
utmp.ut_type = USER_PROCESS;
if (getutid(&utmp) == NULL) {
return;
}
utmp.ut_type = DEAD_PROCESS;
utmp.ut_time = time(NULL);
pututline(&utmp);
getutmpx(&utmp, &utmpx);
update_wtmp(WTMP_FILENAME, &utmpx);
endutent();
# else /* HAVE_UTMPX_H */
struct utmp *putmp;
pid_t pid = getpid();
struct utmp *putmp;
pid_t pid = getpid();
if (!ut_id[0])
return; /* entry not made */
if (!ut_id[0])
return; /* entry not made */
utmpname(UTMP_FILENAME);
setutent();
/*
* The following code waw copied from the poeigl-1.20 login/init package.
* Special thanks to poe for the code examples.
*/
while ((putmp = getutent()) != NULL) {
if (putmp->ut_pid == pid) {
putmp->ut_type = DEAD_PROCESS;
putmp->ut_pid = 0;
putmp->ut_user[0] = '\0';
putmp->ut_time = time(NULL);
pututline(putmp);
update_wtmp(WTMP_FILENAME, putmp);
break;
utmpname(UTMP_FILENAME);
setutent();
/*
* The following code waw copied from the poeigl-1.20 login/init package.
* Special thanks to poe for the code examples.
*/
while ((putmp = getutent()) != NULL) {
if (putmp->ut_pid == pid) {
putmp->ut_type = DEAD_PROCESS;
putmp->ut_pid = 0;
putmp->ut_user[0] = '\0';
putmp->ut_time = time(NULL);
pututline(putmp);
update_wtmp(WTMP_FILENAME, putmp);
break;
}
}
}
endutent();
endutent();
# endif /* HAVE_UTMPX_H */
}
@ -229,48 +229,48 @@ static char ut_line[32];
static int
get_tslot(const char *ttyname)
{
register struct ttyent *ttyp;
register int slot;
register struct ttyent *ttyp;
register int slot;
setttyent();
for (slot = 1; (ttyp = getttyent()); ++slot)
if (!strcmp(ttyp->ty_name, ttyname)) {
endttyent();
return (slot);
}
endttyent();
return 0;
setttyent();
for (slot = 1; (ttyp = getttyent()); ++slot)
if (!strcmp(ttyp->ty_name, ttyname)) {
endttyent();
return (slot);
}
endttyent();
return 0;
}
void
b_login(struct utmp *ut)
{
/*
** replacement for freebsd's login(), which uses ttyslot()
**
** like I shouldn't have just KNOWN that from the comment on get_tslot
** below...
** - brian
*/
register int fd;
int tty;
/*
** replacement for freebsd's login(), which uses ttyslot()
**
** like I shouldn't have just KNOWN that from the comment on get_tslot
** below...
** - brian
*/
register int fd;
int tty;
tty = get_tslot(ut->ut_line);
if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY | O_CREAT, 0644)) >= 0) {
(void) lseek(fd, (off_t) (tty * sizeof(struct utmp)), L_SET);
(void) write(fd, ut, sizeof(struct utmp));
tty = get_tslot(ut->ut_line);
if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY | O_CREAT, 0644)) >= 0) {
(void) lseek(fd, (off_t) (tty * sizeof(struct utmp)), L_SET);
(void) write(fd, ut, sizeof(struct utmp));
(void) close(fd);
}
if ((fd = open(_PATH_WTMP, O_WRONLY | O_APPEND, 0)) >= 0) {
(void) write(fd, ut, sizeof(struct utmp));
(void) close(fd);
}
if ((fd = open(_PATH_WTMP, O_WRONLY | O_APPEND, 0)) >= 0) {
(void) write(fd, ut, sizeof(struct utmp));
(void) close(fd);
}
(void) close(fd);
}
}
# else /* __FreeBSD__ || NetBSD || BSDI */
static int utmp_pos = 0; /* position of utmp-stamp */
static int utmp_pos = 0; /* position of utmp-stamp */
/*----------------------------------------------------------------------*
* get_tslot() - grabbed from xvt-1.0 - modified by David Perry
@ -282,23 +282,23 @@ static int utmp_pos = 0; /* position of utmp-stamp */
static int
get_tslot(const char *ttyname)
{
char buf[256], name[256];
FILE *fd;
char buf[256], name[256];
FILE *fd;
if ((fd = fopen(UTMP_FILENAME, "r")) != NULL) {
int i;
if ((fd = fopen(UTMP_FILENAME, "r")) != NULL) {
int i;
for (i = 1; fgets(buf, sizeof(buf), fd) != NULL; i++) {
if (*buf == '#' || sscanf(buf, "%s", name) != 1)
continue;
if (!strcmp(ttyname, name)) {
fclose(fd);
return i;
}
for (i = 1; fgets(buf, sizeof(buf), fd) != NULL; i++) {
if (*buf == '#' || sscanf(buf, "%s", name) != 1)
continue;
if (!strcmp(ttyname, name)) {
fclose(fd);
return i;
}
}
fclose(fd);
}
fclose(fd);
}
return -1;
return -1;
}
/*
@ -307,24 +307,24 @@ get_tslot(const char *ttyname)
static int
write_utmp(struct utmp *putmp)
{
int rval = 0;
FILE *fd;
int rval = 0;
FILE *fd;
fprintf(stderr, "Utmp file is %s\n", UTMP_FILENAME);
privileges(INVOKE);
if ((fd = fopen(UTMP_FILENAME, "r+")) != NULL) {
utmp_pos = get_tslot(putmp->ut_line) * sizeof(struct utmp);
fprintf(stderr, "Utmp file is %s\n", UTMP_FILENAME);
privileges(INVOKE);
if ((fd = fopen(UTMP_FILENAME, "r+")) != NULL) {
utmp_pos = get_tslot(putmp->ut_line) * sizeof(struct utmp);
if (utmp_pos >= 0) {
fseek(fd, utmp_pos, 0);
fwrite(putmp, sizeof(struct utmp), 1, fd);
if (utmp_pos >= 0) {
fseek(fd, utmp_pos, 0);
fwrite(putmp, sizeof(struct utmp), 1, fd);
rval = 1;
rval = 1;
}
fclose(fd);
}
fclose(fd);
}
privileges(REVERT);
return rval;
privileges(REVERT);
return rval;
}
# endif /* __FreeBSD__ || NetBSD || BSDI */
@ -332,41 +332,41 @@ write_utmp(struct utmp *putmp)
void
add_utmp_entry(const char *pty, const char *hostname, int fd)
{
struct passwd *pwent = getpwuid(my_ruid);
struct utmp utmp;
struct passwd *pwent = getpwuid(my_ruid);
struct utmp utmp;
MEMSET(&utmp, 0, sizeof(struct utmp));
MEMSET(&utmp, 0, sizeof(struct utmp));
if (!strncmp(pty, "/dev/", 5))
pty += 5; /* skip /dev/ prefix */
if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3))
strncpy(ut_id, (pty + 3), sizeof(ut_id)); /* bsd naming */
else {
print_error("can't parse tty name \"%s\"\n", pty);
ut_id[0] = '\0'; /* entry not made */
return;
}
if (!strncmp(pty, "/dev/", 5))
pty += 5; /* skip /dev/ prefix */
if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3))
strncpy(ut_id, (pty + 3), sizeof(ut_id)); /* bsd naming */
else {
print_error("can't parse tty name \"%s\"\n", pty);
ut_id[0] = '\0'; /* entry not made */
return;
}
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
strncpy(ut_line, pty, 31);
strncpy(ut_line, pty, 31);
strncpy(utmp.ut_line, pty, UT_LINESIZE);
strncpy(utmp.ut_name, pwent->pw_name, UT_NAMESIZE);
strncpy(utmp.ut_host, hostname, UT_HOSTSIZE);
utmp.ut_time = time(NULL);
strncpy(utmp.ut_line, pty, UT_LINESIZE);
strncpy(utmp.ut_name, pwent->pw_name, UT_NAMESIZE);
strncpy(utmp.ut_host, hostname, UT_HOSTSIZE);
utmp.ut_time = time(NULL);
b_login(&utmp);
b_login(&utmp);
# else /* __FreeBSD__ || NetBSD || BSDI */
strncpy(utmp.ut_line, ut_id, sizeof(utmp.ut_line));
strncpy(utmp.ut_name, pwent->pw_name, sizeof(utmp.ut_name));
strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
utmp.ut_time = time(NULL);
strncpy(utmp.ut_line, ut_id, sizeof(utmp.ut_line));
strncpy(utmp.ut_name, pwent->pw_name, sizeof(utmp.ut_name));
strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
utmp.ut_time = time(NULL);
if (write_utmp(&utmp) < 0)
ut_id[0] = '\0'; /* entry not made */
if (write_utmp(&utmp) < 0)
ut_id[0] = '\0'; /* entry not made */
# endif
return;
fd = 0;
return;
fd = 0;
}
/*
@ -376,22 +376,22 @@ void
remove_utmp_entry(void)
{
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
logout(ut_line);
logwtmp(ut_line, "", "");
logout(ut_line);
logwtmp(ut_line, "", "");
# else /* __FreeBSD__ */
FILE *fd;
FILE *fd;
privileges(INVOKE);
if (!ut_id[0] && (fd = fopen(UTMP_FILENAME, "r+")) != NULL) {
struct utmp utmp;
MEMSET(&utmp, 0, sizeof(struct utmp));
privileges(INVOKE);
if (!ut_id[0] && (fd = fopen(UTMP_FILENAME, "r+")) != NULL) {
struct utmp utmp;
MEMSET(&utmp, 0, sizeof(struct utmp));
fseek(fd, utmp_pos, 0);
fwrite(&utmp, sizeof(struct utmp), 1, fd);
fseek(fd, utmp_pos, 0);
fwrite(&utmp, sizeof(struct utmp), 1, fd);
fclose(fd);
}
privileges(REVERT);
fclose(fd);
}
privileges(REVERT);
# endif /* __FreeBSD__ || NetBSD || BSDI */
}

File diff suppressed because it is too large Load Diff

View File

@ -40,56 +40,55 @@ void
set_pixmap_property(Pixmap p)
{
Atom prop_root, prop_esetroot, type;
int format;
unsigned long length, after;
unsigned char *data_root, *data_esetroot;
Atom prop_root, prop_esetroot, type;
int format;
unsigned long length, after;
unsigned char *data_root, *data_esetroot;
prop_root = XInternAtom(Xdisplay, "_XROOTPMAP_ID", True);
prop_esetroot = XInternAtom(Xdisplay, "ESETROOT_PMAP_ID", True);
prop_root = XInternAtom(Xdisplay, "_XROOTPMAP_ID", True);
prop_esetroot = XInternAtom(Xdisplay, "ESETROOT_PMAP_ID", True);
if (debug) {
fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): prop_root == 0x%08x, prop_esetroot == 0x%08x\n", __FILE__, __LINE__,
(unsigned int) p, (unsigned int) prop_root, (unsigned int) prop_esetroot);
}
if (prop_root != None && prop_esetroot != None) {
XGetWindowProperty(Xdisplay, Xroot, prop_root, 0L, 1L, False, AnyPropertyType,
&type, &format, &length, &after, &data_root);
if (type == XA_PIXMAP) {
XGetWindowProperty(Xdisplay, Xroot, prop_esetroot, 0L, 1L, False, AnyPropertyType,
&type, &format, &length, &after, &data_esetroot);
if (data_root && data_esetroot) {
if (debug) {
fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): data_root == 0x%08x, data_esetroot == 0x%08x\n", __FILE__, __LINE__,
(unsigned int) p, (unsigned int) *((Pixmap *) data_root), (unsigned int) *((Pixmap *) data_esetroot));
}
if (type == XA_PIXMAP && *((Pixmap *) data_root) == *((Pixmap *) data_esetroot)) {
if (debug) {
fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): XKillClient() is being called.\n", __FILE__, __LINE__, (unsigned int) p);
}
XKillClient(Xdisplay, *((Pixmap *) data_root));
}
}
if (debug) {
fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): prop_root == 0x%08x, prop_esetroot == 0x%08x\n", __FILE__, __LINE__,
(unsigned int) p, (unsigned int) prop_root, (unsigned int) prop_esetroot);
}
}
/* This will locate the property, creating it if it doesn't exist */
prop_root = XInternAtom(Xdisplay, "_XROOTPMAP_ID", False);
prop_esetroot = XInternAtom(Xdisplay, "ESETROOT_PMAP_ID", False);
if (prop_root != None && prop_esetroot != None) {
XGetWindowProperty(Xdisplay, Xroot, prop_root, 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data_root);
if (type == XA_PIXMAP) {
XGetWindowProperty(Xdisplay, Xroot, prop_esetroot, 0L, 1L, False, AnyPropertyType,
&type, &format, &length, &after, &data_esetroot);
if (data_root && data_esetroot) {
if (debug) {
fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): data_root == 0x%08x, data_esetroot == 0x%08x\n", __FILE__,
__LINE__, (unsigned int) p, (unsigned int) *((Pixmap *) data_root), (unsigned int) *((Pixmap *) data_esetroot));
}
if (type == XA_PIXMAP && *((Pixmap *) data_root) == *((Pixmap *) data_esetroot)) {
if (debug) {
fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): XKillClient() is being called.\n", __FILE__, __LINE__,
(unsigned int) p);
}
XKillClient(Xdisplay, *((Pixmap *) data_root));
}
}
}
}
/* This will locate the property, creating it if it doesn't exist */
prop_root = XInternAtom(Xdisplay, "_XROOTPMAP_ID", False);
prop_esetroot = XInternAtom(Xdisplay, "ESETROOT_PMAP_ID", False);
/* The call above should have created it. If that failed, we can't continue. */
if (prop_root == None || prop_esetroot == None) {
fprintf(stderr, "Esetroot: creation of pixmap property failed.\n");
exit(1);
}
XChangeProperty(Xdisplay, Xroot, prop_root, XA_PIXMAP, 32, PropModeReplace,
(unsigned char *) &p, 1);
XChangeProperty(Xdisplay, Xroot, prop_esetroot, XA_PIXMAP, 32, PropModeReplace,
(unsigned char *) &p, 1);
if (debug) {
fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): _XROOTPMAP_ID and ESETROOT_PMAP_ID set to 0x%08x.\n", __FILE__, __LINE__, (unsigned int) p, (unsigned int) p);
}
XSetCloseDownMode(Xdisplay, RetainPermanent);
XFlush(Xdisplay);
/* The call above should have created it. If that failed, we can't continue. */
if (prop_root == None || prop_esetroot == None) {
fprintf(stderr, "Esetroot: creation of pixmap property failed.\n");
exit(1);
}
XChangeProperty(Xdisplay, Xroot, prop_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &p, 1);
XChangeProperty(Xdisplay, Xroot, prop_esetroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &p, 1);
if (debug) {
fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): _XROOTPMAP_ID and ESETROOT_PMAP_ID set to 0x%08x.\n", __FILE__, __LINE__,
(unsigned int) p, (unsigned int) p);
}
XSetCloseDownMode(Xdisplay, RetainPermanent);
XFlush(Xdisplay);
}
#endif
@ -97,181 +96,183 @@ int
main(int argc, char *argv[])
{
#ifdef PIXMAP_SUPPORT
unsigned char scale = 0, center = 0, fit = 0, mirror = 0;
char *displayname = NULL, *fname = NULL, *bgcolor = NULL;
Imlib_Image im;
Pixmap p = None, temp_pmap = None, m = None;
register unsigned char i;
GC gc;
XGCValues gcv;
XColor xcolor;
int w, h, x, y;
unsigned char scale = 0, center = 0, fit = 0, mirror = 0;
char *displayname = NULL, *fname = NULL, *bgcolor = NULL;
Imlib_Image im;
Pixmap p = None, temp_pmap = None, m = None;
register unsigned char i;
GC gc;
XGCValues gcv;
XColor xcolor;
int w, h, x, y;
if (argc < 2) {
fprintf(stderr, "%s [-display <display_name>] [-bgcolor <color>] [-scale] [-center] [-fit] [-mirror] pixmap\n", *argv);
fprintf(stderr, "\t Short options are also recognized (-d, -b, -s, -c, -f, and -m)\n");
exit(0);
}
for (i = 1; i < argc; i++) {
if (*argv[i] != '-') {
break;
if (argc < 2) {
fprintf(stderr, "%s [-display <display_name>] [-bgcolor <color>] [-scale] [-center] [-fit] [-mirror] pixmap\n", *argv);
fprintf(stderr, "\t Short options are also recognized (-d, -b, -s, -c, -f, and -m)\n");
exit(0);
}
if (argv[i][1] == 'd') {
displayname = argv[++i];
} else if (argv[i][1] == 'b') {
bgcolor = argv[++i];
} else if (argv[i][1] == 's') {
scale = 1;
} else if (argv[i][1] == 'c') {
center = 1;
} else if (argv[i][1] == 'f') {
fit = 1;
} else if (argv[i][1] == 'm') {
mirror = 1;
} else if (argv[i][1] == 'x') {
fprintf(stderr, "Debugging activated.\n");
debug = 1;
for (i = 1; i < argc; i++) {
if (*argv[i] != '-') {
break;
}
if (argv[i][1] == 'd') {
displayname = argv[++i];
} else if (argv[i][1] == 'b') {
bgcolor = argv[++i];
} else if (argv[i][1] == 's') {
scale = 1;
} else if (argv[i][1] == 'c') {
center = 1;
} else if (argv[i][1] == 'f') {
fit = 1;
} else if (argv[i][1] == 'm') {
mirror = 1;
} else if (argv[i][1] == 'x') {
fprintf(stderr, "Debugging activated.\n");
debug = 1;
} else {
fprintf(stderr, "%s: Unrecognized option \'%c\'\n\n", *argv, argv[i][1]);
fprintf(stderr, "%s [-display <display_name>] [-bgcolor <color>] [-scale] [-center] [-fit] [-mirror] pixmap\n", *argv);
fprintf(stderr, "\t Short options are also recognized (-d, -b, -s, -c, -f, and -m)\n");
exit(2);
}
}
fname = argv[i];
if (scale) {
center = 0;
mirror = 0;
}
if (debug) {
fprintf(stderr, "%s:%d: Display name is \"%s\"\n", __FILE__, __LINE__, displayname ? displayname : "(nil)");
fprintf(stderr, "%s:%d: Background color name is \"%s\"\n", __FILE__, __LINE__, bgcolor ? bgcolor : "(nil)");
fprintf(stderr, "%s:%d: Image will be %s\n", __FILE__, __LINE__,
scale ? "scaled" : (center ? "centered" : (fit ? "fit" : "tiled")));
fprintf(stderr, "%s:%d: Image file is %s\n", __FILE__, __LINE__, fname ? fname : "(nil)");
}
if (!displayname) {
displayname = getenv("DISPLAY");
if (debug) {
fprintf(stderr, "%s:%d: Display name set to %s via getenv(\"DISPLAY\")\n", __FILE__, __LINE__,
displayname ? displayname : "(nil)");
}
}
if (!displayname) {
displayname = ":0.0";
if (debug) {
fprintf(stderr, "%s:%d: Display name defaulted to %s\n", __FILE__, __LINE__, displayname ? displayname : "(nil)");
}
}
if ((Xdisplay = XOpenDisplay(displayname)) == 0) {
fprintf(stderr, "%s: Unable to open display %s\n", *argv, displayname);
exit(1);
}
screen = DefaultScreen(Xdisplay);
Xroot = RootWindow(Xdisplay, screen);
scr = ScreenOfDisplay(Xdisplay, screen);
if (debug) {
fprintf(stderr, "%s:%d: Chose screen %d\n", __FILE__, __LINE__, screen);
fprintf(stderr, "%s:%d: Root window is 0x%08x\n", __FILE__, __LINE__, (unsigned int) Xroot);
fprintf(stderr, "%s:%d: Found screen information at %8p\n", __FILE__, __LINE__, scr);
}
imlib_context_set_display(Xdisplay);
imlib_context_set_visual(DefaultVisual(Xdisplay, DefaultScreen(Xdisplay)));
im = imlib_load_image_immediately(fname);
if (im == NULL) {
fprintf(stderr, "%s: Unable to load image file \"%s\".\n", *argv, fname);
exit(1);
} else if (debug) {
fprintf(stderr, "%s:%d: The Imlib Image is at %8p\n", __FILE__, __LINE__, im);
}
imlib_context_set_image(im);
if (scale) {
w = scr->width;
h = scr->height;
} else if (mirror) {
w = imlib_image_get_width() * 2;
h = imlib_image_get_height() * 2;
} else {
fprintf(stderr, "%s: Unrecognized option \'%c\'\n\n", *argv, argv[i][1]);
fprintf(stderr, "%s [-display <display_name>] [-bgcolor <color>] [-scale] [-center] [-fit] [-mirror] pixmap\n", *argv);
fprintf(stderr, "\t Short options are also recognized (-d, -b, -s, -c, -f, and -m)\n");
exit(2);
w = imlib_image_get_width();
h = imlib_image_get_height();
}
}
if (fit) {
double x_ratio, y_ratio;
fname = argv[i];
if (scale) {
center = 0;
mirror=0;
}
x_ratio = ((double) scr->width) / ((double) w);
y_ratio = ((double) scr->height) / ((double) h);
if (x_ratio > y_ratio) {
x_ratio = y_ratio;
}
w = (int) (w * x_ratio);
h = (int) (h * x_ratio);
}
if (debug) {
fprintf(stderr, "%s:%d: Display name is \"%s\"\n", __FILE__, __LINE__, displayname ? displayname : "(nil)");
fprintf(stderr, "%s:%d: Background color name is \"%s\"\n", __FILE__, __LINE__, bgcolor ? bgcolor : "(nil)");
fprintf(stderr, "%s:%d: Image will be %s\n", __FILE__, __LINE__, scale ? "scaled" : (center ? "centered" : (fit ? "fit" : "tiled")));
fprintf(stderr, "%s:%d: Image file is %s\n", __FILE__, __LINE__, fname ? fname : "(nil)");
}
if (!displayname) {
displayname = getenv("DISPLAY");
if (debug) {
fprintf(stderr, "%s:%d: Display name set to %s via getenv(\"DISPLAY\")\n", __FILE__, __LINE__, displayname ? displayname : "(nil)");
p = XCreatePixmap(Xdisplay, Xroot, scr->width, scr->height, Xdepth);
gcv.foreground = gcv.background = BlackPixel(Xdisplay, screen);
if (bgcolor && XParseColor(Xdisplay, DefaultColormap(Xdisplay, screen), bgcolor, &xcolor)
&& XAllocColor(Xdisplay, DefaultColormap(Xdisplay, screen), &xcolor)) {
gcv.foreground = gcv.background = xcolor.pixel;
}
}
if (!displayname) {
displayname = ":0.0";
if (debug) {
fprintf(stderr, "%s:%d: Display name defaulted to %s\n", __FILE__, __LINE__, displayname ? displayname : "(nil)");
gc = XCreateGC(Xdisplay, p, (GCForeground | GCBackground), &gcv);
if (scale) {
XFillRectangle(Xdisplay, p, gc, 0, 0, w, h);
}
}
if ((Xdisplay = XOpenDisplay(displayname)) == 0) {
fprintf(stderr, "%s: Unable to open display %s\n", *argv, displayname);
exit(1);
}
screen = DefaultScreen(Xdisplay);
Xroot = RootWindow(Xdisplay, screen);
scr = ScreenOfDisplay(Xdisplay, screen);
if (debug) {
fprintf(stderr, "%s:%d: Chose screen %d\n", __FILE__, __LINE__, screen);
fprintf(stderr, "%s:%d: Root window is 0x%08x\n", __FILE__, __LINE__, (unsigned int) Xroot);
fprintf(stderr, "%s:%d: Found screen information at %8p\n", __FILE__, __LINE__, scr);
}
imlib_context_set_display(Xdisplay);
imlib_context_set_visual(DefaultVisual(Xdisplay, DefaultScreen(Xdisplay)));
im = imlib_load_image_immediately(fname);
if (im == NULL) {
fprintf(stderr, "%s: Unable to load image file \"%s\".\n", *argv, fname);
exit(1);
} else if (debug) {
fprintf(stderr, "%s:%d: The Imlib Image is at %8p\n", __FILE__, __LINE__, im);
}
imlib_context_set_image(im);
if (scale) {
w = scr->width;
h = scr->height;
} else if (mirror) {
w = imlib_image_get_width() * 2;
h = imlib_image_get_height() * 2;
} else {
w = imlib_image_get_width();
h = imlib_image_get_height();
}
if (fit) {
double x_ratio, y_ratio;
x_ratio = ((double) scr->width) / ((double) w);
y_ratio = ((double) scr->height) / ((double) h);
if (x_ratio > y_ratio) {
x_ratio = y_ratio;
}
w = (int) (w * x_ratio);
h = (int) (h * x_ratio);
}
p = XCreatePixmap(Xdisplay, Xroot, scr->width, scr->height, Xdepth);
gcv.foreground = gcv.background = BlackPixel(Xdisplay, screen);
if (bgcolor && XParseColor(Xdisplay, DefaultColormap(Xdisplay, screen), bgcolor, &xcolor)
&& XAllocColor(Xdisplay, DefaultColormap(Xdisplay, screen), &xcolor)) {
gcv.foreground = gcv.background = xcolor.pixel;
}
gc = XCreateGC(Xdisplay, p, (GCForeground | GCBackground), &gcv);
if (scale) {
XFillRectangle(Xdisplay, p, gc, 0, 0, w, h);
}
if (center || fit) {
XFillRectangle(Xdisplay, p, gc, 0, 0, scr->width, scr->height);
x = (scr->width - w) >> 1;
y = (scr->height - h) >> 1;
} else {
x = 0;
y = 0;
}
if (debug) {
fprintf(stderr, "%s:%d: Assigned width and height for rendering as %dx%d\n", __FILE__, __LINE__, w, h);
fprintf(stderr, "%s:%d: Created %dx%d+%d+%d pixmap 0x%08x\n", __FILE__, __LINE__, scr->width, scr->height, x, y, (unsigned int) p);
fprintf(stderr, "%s:%d: Applied Graphics Context %8p to pixmap.\n", __FILE__, __LINE__, gc);
}
imlib_context_set_anti_alias(1);
imlib_context_set_dither(1);
imlib_context_set_blend(0);
if (mirror) {
temp_pmap = XCreatePixmap(Xdisplay, Xroot, w, h, Xdepth);
imlib_context_set_drawable(temp_pmap);
imlib_render_image_on_drawable(0, 0);
imlib_image_flip_horizontal();
imlib_render_image_on_drawable(imlib_image_get_width(), 0);
imlib_image_flip_vertical();
imlib_render_image_on_drawable(imlib_image_get_width(), imlib_image_get_height());
imlib_image_flip_horizontal();
imlib_render_image_on_drawable(0, imlib_image_get_height());
} else {
imlib_context_set_drawable(Xroot);
imlib_render_pixmaps_for_whole_image_at_size(&temp_pmap, &m, w, h);
}
if (debug) {
fprintf(stderr, "%s:%d: Rendered at %dx%d onto pixmap 0x%08x\n", __FILE__, __LINE__, w, h, (unsigned int) temp_pmap);
}
if (temp_pmap != None) {
if (m) {
XFreePixmap(Xdisplay, m);
m = None;
}
XSetTile(Xdisplay, gc, temp_pmap);
XSetTSOrigin(Xdisplay, gc, x, y);
XSetFillStyle(Xdisplay, gc, FillTiled);
if (center || fit) {
XFillRectangle(Xdisplay, p, gc, x, y, w, h);
XFillRectangle(Xdisplay, p, gc, 0, 0, scr->width, scr->height);
x = (scr->width - w) >> 1;
y = (scr->height - h) >> 1;
} else {
XFillRectangle(Xdisplay, p, gc, x, y, scr->width, scr->height);
x = 0;
y = 0;
}
if (debug) {
fprintf(stderr, "%s:%d: Assigned width and height for rendering as %dx%d\n", __FILE__, __LINE__, w, h);
fprintf(stderr, "%s:%d: Created %dx%d+%d+%d pixmap 0x%08x\n", __FILE__, __LINE__, scr->width, scr->height, x, y, (unsigned int) p);
fprintf(stderr, "%s:%d: Applied Graphics Context %8p to pixmap.\n", __FILE__, __LINE__, gc);
}
imlib_context_set_anti_alias(1);
imlib_context_set_dither(1);
imlib_context_set_blend(0);
if (mirror) {
temp_pmap = XCreatePixmap(Xdisplay, Xroot, w, h, Xdepth);
imlib_context_set_drawable(temp_pmap);
imlib_render_image_on_drawable(0, 0);
imlib_image_flip_horizontal();
imlib_render_image_on_drawable(imlib_image_get_width(), 0);
imlib_image_flip_vertical();
imlib_render_image_on_drawable(imlib_image_get_width(), imlib_image_get_height());
imlib_image_flip_horizontal();
imlib_render_image_on_drawable(0, imlib_image_get_height());
} else {
imlib_context_set_drawable(Xroot);
imlib_render_pixmaps_for_whole_image_at_size(&temp_pmap, &m, w, h);
}
if (debug) {
fprintf(stderr, "%s:%d: Rendered at %dx%d onto pixmap 0x%08x\n", __FILE__, __LINE__, w, h, (unsigned int) temp_pmap);
}
if (temp_pmap != None) {
if (m) {
XFreePixmap(Xdisplay, m);
m = None;
}
XSetTile(Xdisplay, gc, temp_pmap);
XSetTSOrigin(Xdisplay, gc, x, y);
XSetFillStyle(Xdisplay, gc, FillTiled);
if (center || fit) {
XFillRectangle(Xdisplay, p, gc, x, y, w, h);
} else {
XFillRectangle(Xdisplay, p, gc, x, y, scr->width, scr->height);
}
XGrabServer(Xdisplay);
set_pixmap_property(p);
XSetWindowBackgroundPixmap(Xdisplay, Xroot, p);
XClearWindow(Xdisplay, Xroot);
XUngrabServer(Xdisplay);
XFlush(Xdisplay);
}
XGrabServer(Xdisplay);
set_pixmap_property(p);
XSetWindowBackgroundPixmap(Xdisplay, Xroot, p);
XClearWindow(Xdisplay, Xroot);
XUngrabServer(Xdisplay);
XFlush(Xdisplay);
}
#else
fprintf(stderr, "Eterm was built without pixmap support, so Esetroot is fairly useless. Sorry.\n");
fprintf(stderr, "Eterm was built without pixmap support, so Esetroot is fairly useless. Sorry.\n");
#endif
return 0;
return 0;
}

View File

@ -38,29 +38,29 @@
int
main(int argc, char **argv)
{
int scale = FALSE, trans = FALSE;
unsigned int pic = 0;
int i;
int scale = FALSE, trans = FALSE;
unsigned int pic = 0;
int i;
for (i = 1; i < argc; i++) {
if (strcasecmp(argv[i], "-scale") == 0) {
scale = TRUE;
} else if (strcasecmp(argv[i], "-trans") == 0) {
trans = TRUE;
} else if (strncasecmp(argv[i], "-h", 2) == 0) {
printf("Usage: %s [[-scale] file] [-trans]\n", argv[0]);
return 0;
} else {
pic = i;
for (i = 1; i < argc; i++) {
if (strcasecmp(argv[i], "-scale") == 0) {
scale = TRUE;
} else if (strcasecmp(argv[i], "-trans") == 0) {
trans = TRUE;
} else if (strncasecmp(argv[i], "-h", 2) == 0) {
printf("Usage: %s [[-scale] file] [-trans]\n", argv[0]);
return 0;
} else {
pic = i;
}
}
}
if (pic && argv[pic]) {
printf("\033]6;0;0\a");
printf("\033]20;%s%s\a", argv[pic], scale ? "@100x100+50+50:scale" : "@0x0+0+0:tile");
}
if (trans) {
printf("\033]6;0;1\a");
}
return 0;
if (pic && argv[pic]) {
printf("\033]6;0;0\a");
printf("\033]20;%s%s\a", argv[pic], scale ? "@100x100+50+50:scale" : "@0x0+0+0:tile");
}
if (trans) {
printf("\033]6;0;1\a");
}
return 0;
}

View File

@ -26,40 +26,39 @@ static const char cvs_ident[] = "$Id$";
#include <stdio.h>
const char *lookup[] =
{
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", /* 0-7 */
"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", /* 8-15 */
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", /* 16-23 */
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" /* 24-31 */
const char *lookup[] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", /* 0-7 */
"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", /* 8-15 */
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", /* 16-23 */
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" /* 24-31 */
};
int
main(void)
{
unsigned short i;
unsigned short i;
printf("+-----------+---------+-------------+--------+\n");
printf("| Character | Decimal | Hexadecimal | Octal |\n");
printf("+-----------+---------+-------------+--------+\n");
printf("+-----------+---------+-------------+--------+\n");
printf("| Character | Decimal | Hexadecimal | Octal |\n");
printf("+-----------+---------+-------------+--------+\n");
for (i = 0; i < 32; i++) {
printf("| %3s ^%c | %3d | 0x%02x | %03o |\n", lookup[i], ('@' + i), i, i, i);
}
for (; i < 256; i++) {
printf("| '%c' | %3d | 0x%02x | %c%03o |\n", (i == 127 ? ' ' : i), i, i, (i > '\077' ? '0' : ' '), i);
}
printf("+-----------+---------+-------------+--------+\n");
for (i = 0; i < 32; i++) {
printf("| %3s ^%c | %3d | 0x%02x | %03o |\n", lookup[i], ('@' + i), i, i, i);
}
for (; i < 256; i++) {
printf("| '%c' | %3d | 0x%02x | %c%03o |\n", (i == 127 ? ' ' : i), i, i, (i > '\077' ? '0' : ' '), i);
}
printf("+-----------+---------+-------------+--------+\n");
printf("+---------------+---------+-------------+-------+\n");
printf("| ACS Character | Decimal | Hexadecimal | Octal |\n");
printf("+---------------+---------+-------------+-------+\n");
printf("\033)0");
printf("+---------------+---------+-------------+-------+\n");
printf("| ACS Character | Decimal | Hexadecimal | Octal |\n");
printf("+---------------+---------+-------------+-------+\n");
printf("\033)0");
for (i = 1; i < 32; i++) {
printf("| \016%c\017 (%c) | %3d | 0x%02x | %03o |\n", i + 0x5e, i + 0x5e, i, i, i);
}
printf("+---------------+---------+-------------+-------+\n");
return 0;
for (i = 1; i < 32; i++) {
printf("| \016%c\017 (%c) | %3d | 0x%02x | %03o |\n", i + 0x5e, i + 0x5e, i, i, i);
}
printf("+---------------+---------+-------------+-------+\n");
return 0;
}