diff --git a/ChangeLog b/ChangeLog index d964e6e..4213786 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. +---------------------------------------------------------------------- diff --git a/doc/Eterm.1.in b/doc/Eterm.1.in index e741bcc..365a80b 100644 --- a/doc/Eterm.1.in +++ b/doc/Eterm.1.in @@ -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 diff --git a/reformat-code b/reformat-code index 6f39fbd..1de1c1e 100755 --- a/reformat-code +++ b/reformat-code @@ -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] diff --git a/src/Makefile.am b/src/Makefile.am index 2e10687..3e9faf1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) diff --git a/src/README.Escreen b/src/README.Escreen new file mode 100644 index 0000000..0bc8fc4 --- /dev/null +++ b/src/README.Escreen @@ -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 http://www.azundris.com/ diff --git a/src/actions.c b/src/actions.c index ce3f500..ce91f2c 100644 --- a/src/actions.c +++ b/src/actions.c @@ -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)); } - diff --git a/src/buttons.c b/src/buttons.c index 23705fb..3e47c01 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -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); diff --git a/src/buttons.h b/src/buttons.h index fb7bcd1..e86ddd3 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -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; diff --git a/src/command.c b/src/command.c index 57dd0e0..b2bd577 100644 --- a/src/command.c +++ b/src/command.c @@ -81,15 +81,15 @@ static const char cvs_ident[] = "$Id$"; # endif #endif #if defined (__svr4__) -# include /* for struct rlimit */ -# include /* for I_PUSH */ +# include /* for struct rlimit */ +# include /* for I_PUSH */ # ifdef HAVE_SYS_STRTIO_H # include # endif # ifdef HAVE_BSDTTY_H # include # endif -# define _NEW_TTY_CTRL /* to get proper defines in */ +# define _NEW_TTY_CTRL /* to get proper defines in */ #endif #ifdef HAVE_SYS_SELECT_H # include @@ -105,7 +105,7 @@ static const char cvs_ident[] = "$Id$"; #include #include #if defined(linux) -# include /* For N_TTY_BUF_SIZE. */ +# include /* For N_TTY_BUF_SIZE. */ #endif /* Eterm-specific Headers */ @@ -129,6 +129,10 @@ static const char cvs_ident[] = "$Id$"; #include "windows.h" #include "buttons.h" +#ifdef ESCREEN +# include "screamcfg.h" +#endif + static RETSIGTYPE handle_child_signal(int); static RETSIGTYPE handle_exit_signal(int); static RETSIGTYPE handle_crash(int); @@ -137,24 +141,24 @@ static RETSIGTYPE handle_crash(int); int my_ruid, my_euid, my_rgid, my_egid; char initial_dir[PATH_MAX + 1]; static char *ptydev = NULL, *ttydev = NULL; /* pty/tty name */ -int cmd_fd = -1; /* file descriptor connected to the command */ +int cmd_fd = -1; /* file descriptor connected to the command */ int pipe_fd = -1; -pid_t cmd_pid = -1; /* process id if child */ -int Xfd = -1; /* file descriptor of X server connection */ -unsigned int num_fds = 0; /* number of file descriptors being used */ -struct stat ttyfd_stat; /* original status of the tty we will use */ +pid_t cmd_pid = -1; /* process id if child */ +int Xfd = -1; /* file descriptor of X server connection */ +unsigned int num_fds = 0; /* number of file descriptors being used */ +struct stat ttyfd_stat; /* original status of the tty we will use */ int refresh_count = 0, refresh_limit = 1, refresh_type = FAST_REFRESH; unsigned char cmdbuf_base[CMD_BUF_SIZE], *cmdbuf_ptr, *cmdbuf_endp; /* Addresses pasting large amounts of data * code pinched from xterm */ -static char *v_buffer; /* pointer to physical buffer */ -static char *v_bufstr = NULL; /* beginning of area to write */ -static char *v_bufptr; /* end of area to write */ -static char *v_bufend; /* end of physical buffer */ +static char *v_buffer; /* pointer to physical buffer */ +static char *v_bufstr = NULL; /* beginning of area to write */ +static char *v_bufptr; /* end of area to write */ +static char *v_bufend; /* end of physical buffer */ #ifdef USE_XIM XIM xim_input_method = NULL; -XIC xim_input_context = NULL; /* input context */ +XIC xim_input_context = NULL; /* input context */ static XIMStyle xim_input_style = 0; # ifndef XSetIMValues extern char *XSetIMValues(XIM im, ...); @@ -166,10 +170,10 @@ extern char *XSetIMValues(XIM im, ...); int getdtablesize(void) { - struct rlimit rlim; + struct rlimit rlim; - getrlimit(RLIMIT_NOFILE, &rlim); - return rlim.rlim_cur; + getrlimit(RLIMIT_NOFILE, &rlim); + return rlim.rlim_cur; } # endif @@ -179,799 +183,795 @@ privileges(int mode) { #ifdef __CYGWIN32__ - return; + return; #endif - switch (mode) { - case IGNORE: - /* Revoke suid/sgid privs and return to normal uid/gid -- mej */ - D_UTMP(("[%ld]: Before privileges(REVERT): [ %ld, %ld ] [ %ld, %ld ]\n", - getpid(), getuid(), getgid(), geteuid(), getegid())); + switch (mode) { + case IGNORE: + /* Revoke suid/sgid privs and return to normal uid/gid -- mej */ + D_UTMP(("[%ld]: Before privileges(REVERT): [ %ld, %ld ] [ %ld, %ld ]\n", getpid(), getuid(), getgid(), geteuid(), getegid())); #ifdef HAVE_SETRESGID - setresgid(my_rgid, my_rgid, my_egid); + setresgid(my_rgid, my_rgid, my_egid); #elif defined(HAVE_SAVED_UIDS) - setregid(my_rgid, my_rgid); + setregid(my_rgid, my_rgid); #else - setregid(my_egid, -1); - setregid(-1, my_rgid); + setregid(my_egid, -1); + setregid(-1, my_rgid); #endif #ifdef HAVE_SETRESUID - setresuid(my_ruid, my_ruid, my_euid); + setresuid(my_ruid, my_ruid, my_euid); #elif defined(HAVE_SAVED_UIDS) - setreuid(my_ruid, my_ruid); + setreuid(my_ruid, my_ruid); #else - setreuid(my_euid, -1); - setreuid(-1, my_ruid); + setreuid(my_euid, -1); + setreuid(-1, my_ruid); #endif - D_UTMP(("[%ld]: After privileges(REVERT): [ %ld, %ld ] [ %ld, %ld ]\n", - getpid(), getuid(), getgid(), geteuid(), getegid())); - break; + D_UTMP(("[%ld]: After privileges(REVERT): [ %ld, %ld ] [ %ld, %ld ]\n", getpid(), getuid(), getgid(), geteuid(), getegid())); + break; - case SAVE: - break; + case SAVE: + break; - case RESTORE: - D_UTMP(("[%ld]: Before privileges(INVOKE): [ %ld, %ld ] [ %ld, %ld ]\n", - getpid(), getuid(), getgid(), geteuid(), getegid())); + case RESTORE: + D_UTMP(("[%ld]: Before privileges(INVOKE): [ %ld, %ld ] [ %ld, %ld ]\n", getpid(), getuid(), getgid(), geteuid(), getegid())); #ifdef HAVE_SETRESUID - setresuid(my_ruid, my_euid, my_euid); + setresuid(my_ruid, my_euid, my_euid); #elif defined(HAVE_SAVED_UIDS) - setreuid(my_ruid, my_euid); + setreuid(my_ruid, my_euid); #else - setreuid(-1, my_euid); - setreuid(my_ruid, -1); + setreuid(-1, my_euid); + setreuid(my_ruid, -1); #endif #ifdef HAVE_SETRESGID - setresgid(my_rgid, my_egid, my_egid); + setresgid(my_rgid, my_egid, my_egid); #elif defined(HAVE_SAVED_UIDS) - setregid(my_rgid, my_egid); + setregid(my_rgid, my_egid); #else - setregid(-1, my_egid); - setregid(my_rgid, -1); + setregid(-1, my_egid); + setregid(my_rgid, -1); #endif - D_UTMP(("[%ld]: After privileges(INVOKE): [ %ld, %ld ] [ %ld, %ld ]\n", - getpid(), getuid(), getgid(), geteuid(), getegid())); - break; - } + D_UTMP(("[%ld]: After privileges(INVOKE): [ %ld, %ld ] [ %ld, %ld ]\n", getpid(), getuid(), getgid(), geteuid(), getegid())); + break; + } } char * sig_to_str(int sig) { #ifdef SIGHUP - if (sig == SIGHUP) { - return ("SIGHUP"); - } + if (sig == SIGHUP) { + return ("SIGHUP"); + } #endif #ifdef SIGINT - if (sig == SIGINT) { - return ("SIGINT"); - } + if (sig == SIGINT) { + return ("SIGINT"); + } #endif #ifdef SIGQUIT - if (sig == SIGQUIT) { - return ("SIGQUIT"); - } + if (sig == SIGQUIT) { + return ("SIGQUIT"); + } #endif #ifdef SIGILL - if (sig == SIGILL) { - return ("SIGILL"); - } + if (sig == SIGILL) { + return ("SIGILL"); + } #endif #ifdef SIGTRAP - if (sig == SIGTRAP) { - return ("SIGTRAP"); - } + if (sig == SIGTRAP) { + return ("SIGTRAP"); + } #endif #ifdef SIGABRT - if (sig == SIGABRT) { - return ("SIGABRT"); - } + if (sig == SIGABRT) { + return ("SIGABRT"); + } #endif #ifdef SIGIOT - if (sig == SIGIOT) { - return ("SIGIOT"); - } + if (sig == SIGIOT) { + return ("SIGIOT"); + } #endif #ifdef SIGEMT - if (sig == SIGEMT) { - return ("SIGEMT"); - } + if (sig == SIGEMT) { + return ("SIGEMT"); + } #endif #ifdef SIGFPE - if (sig == SIGFPE) { - return ("SIGFPE"); - } + if (sig == SIGFPE) { + return ("SIGFPE"); + } #endif #ifdef SIGKILL - if (sig == SIGKILL) { - return ("SIGKILL"); - } + if (sig == SIGKILL) { + return ("SIGKILL"); + } #endif #ifdef SIGBUS - if (sig == SIGBUS) { - return ("SIGBUS"); - } + if (sig == SIGBUS) { + return ("SIGBUS"); + } #endif #ifdef SIGSEGV - if (sig == SIGSEGV) { - return ("SIGSEGV"); - } + if (sig == SIGSEGV) { + return ("SIGSEGV"); + } #endif #ifdef SIGSYS - if (sig == SIGSYS) { - return ("SIGSYS"); - } + if (sig == SIGSYS) { + return ("SIGSYS"); + } #endif #ifdef SIGPIPE - if (sig == SIGPIPE) { - return ("SIGPIPE"); - } + if (sig == SIGPIPE) { + return ("SIGPIPE"); + } #endif #ifdef SIGALRM - if (sig == SIGALRM) { - return ("SIGALRM"); - } + if (sig == SIGALRM) { + return ("SIGALRM"); + } #endif #ifdef SIGTERM - if (sig == SIGTERM) { - return ("SIGTERM"); - } + if (sig == SIGTERM) { + return ("SIGTERM"); + } #endif #ifdef SIGUSR1 - if (sig == SIGUSR1) { - return ("SIGUSR1"); - } + if (sig == SIGUSR1) { + return ("SIGUSR1"); + } #endif #ifdef SIGUSR2 - if (sig == SIGUSR2) { - return ("SIGUSR2"); - } + if (sig == SIGUSR2) { + return ("SIGUSR2"); + } #endif #ifdef SIGCHLD - if (sig == SIGCHLD) { - return ("SIGCHLD"); - } + if (sig == SIGCHLD) { + return ("SIGCHLD"); + } #endif #ifdef SIGCLD - if (sig == SIGCLD) { - return ("SIGCLD"); - } + if (sig == SIGCLD) { + return ("SIGCLD"); + } #endif #ifdef SIGPWR - if (sig == SIGPWR) { - return ("SIGPWR"); - } + if (sig == SIGPWR) { + return ("SIGPWR"); + } #endif #ifdef SIGVTALRM - if (sig == SIGVTALRM) { - return ("SIGVTALRM"); - } + if (sig == SIGVTALRM) { + return ("SIGVTALRM"); + } #endif #ifdef SIGPROF - if (sig == SIGPROF) { - return ("SIGPROF"); - } + if (sig == SIGPROF) { + return ("SIGPROF"); + } #endif #ifdef SIGIO - if (sig == SIGIO) { - return ("SIGIO"); - } + if (sig == SIGIO) { + return ("SIGIO"); + } #endif #ifdef SIGPOLL - if (sig == SIGPOLL) { - return ("SIGPOLL"); - } + if (sig == SIGPOLL) { + return ("SIGPOLL"); + } #endif #ifdef SIGWINCH - if (sig == SIGWINCH) { - return ("SIGWINCH"); - } + if (sig == SIGWINCH) { + return ("SIGWINCH"); + } #endif #ifdef SIGWINDOW - if (sig == SIGWINDOW) { - return ("SIGWINDOW"); - } + if (sig == SIGWINDOW) { + return ("SIGWINDOW"); + } #endif #ifdef SIGSTOP - if (sig == SIGSTOP) { - return ("SIGSTOP"); - } + if (sig == SIGSTOP) { + return ("SIGSTOP"); + } #endif #ifdef SIGTSTP - if (sig == SIGTSTP) { - return ("SIGTSTP"); - } + if (sig == SIGTSTP) { + return ("SIGTSTP"); + } #endif #ifdef SIGCONT - if (sig == SIGCONT) { - return ("SIGCONT"); - } + if (sig == SIGCONT) { + return ("SIGCONT"); + } #endif #ifdef SIGTTIN - if (sig == SIGTTIN) { - return ("SIGTTIN"); - } + if (sig == SIGTTIN) { + return ("SIGTTIN"); + } #endif #ifdef SIGTTOU - if (sig == SIGTTOU) { - return ("SIGTTOU"); - } + if (sig == SIGTTOU) { + return ("SIGTTOU"); + } #endif #ifdef SIGURG - if (sig == SIGURG) { - return ("SIGURG"); - } + if (sig == SIGURG) { + return ("SIGURG"); + } #endif #ifdef SIGLOST - if (sig == SIGLOST) { - return ("SIGLOST"); - } + if (sig == SIGLOST) { + return ("SIGLOST"); + } #endif #ifdef SIGRESERVE - if (sig == SIGRESERVE) { - return ("SIGRESERVE"); - } + if (sig == SIGRESERVE) { + return ("SIGRESERVE"); + } #endif #ifdef SIGDIL - if (sig == SIGDIL) { - return ("SIGDIL"); - } + if (sig == SIGDIL) { + return ("SIGDIL"); + } #endif #ifdef SIGXCPU - if (sig == SIGXCPU) { - return ("SIGXCPU"); - } + if (sig == SIGXCPU) { + return ("SIGXCPU"); + } #endif #ifdef SIGXFSZ - if (sig == SIGXFSZ) { - return ("SIGXFSZ"); - } + if (sig == SIGXFSZ) { + return ("SIGXFSZ"); + } #endif - return ("Unknown signal"); + return ("Unknown signal"); } const char * event_type_to_name(int type) { - if (type == KeyPress) { - return "KeyPress"; - } - if (type == KeyRelease) { - return "KeyRelease"; - } - if (type == ButtonPress) { - return "ButtonPress"; - } - if (type == ButtonRelease) { - return "ButtonRelease"; - } - if (type == MotionNotify) { - return "MotionNotify"; - } - if (type == EnterNotify) { - return "EnterNotify"; - } - if (type == LeaveNotify) { - return "LeaveNotify"; - } - if (type == FocusIn) { - return "FocusIn"; - } - if (type == FocusOut) { - return "FocusOut"; - } - if (type == KeymapNotify) { - return "KeymapNotify"; - } - if (type == Expose) { - return "Expose"; - } - if (type == GraphicsExpose) { - return "GraphicsExpose"; - } - if (type == NoExpose) { - return "NoExpose"; - } - if (type == VisibilityNotify) { - return "VisibilityNotify"; - } - if (type == CreateNotify) { - return "CreateNotify"; - } - if (type == DestroyNotify) { - return "DestroyNotify"; - } - if (type == UnmapNotify) { - return "UnmapNotify"; - } - if (type == MapNotify) { - return "MapNotify"; - } - if (type == MapRequest) { - return "MapRequest"; - } - if (type == ReparentNotify) { - return "ReparentNotify"; - } - if (type == ConfigureNotify) { - return "ConfigureNotify"; - } - if (type == ConfigureRequest) { - return "ConfigureRequest"; - } - if (type == GravityNotify) { - return "GravityNotify"; - } - if (type == ResizeRequest) { - return "ResizeRequest"; - } - if (type == CirculateNotify) { - return "CirculateNotify"; - } - if (type == CirculateRequest) { - return "CirculateRequest"; - } - if (type == PropertyNotify) { - return "PropertyNotify"; - } - if (type == SelectionClear) { - return "SelectionClear"; - } - if (type == SelectionRequest) { - return "SelectionRequest"; - } - if (type == SelectionNotify) { - return "SelectionNotify"; - } - if (type == ColormapNotify) { - return "ColormapNotify"; - } - if (type == ClientMessage) { - return "ClientMessage"; - } - if (type == MappingNotify) { - return "MappingNotify"; - } - return "Bad Event!"; + if (type == KeyPress) { + return "KeyPress"; + } + if (type == KeyRelease) { + return "KeyRelease"; + } + if (type == ButtonPress) { + return "ButtonPress"; + } + if (type == ButtonRelease) { + return "ButtonRelease"; + } + if (type == MotionNotify) { + return "MotionNotify"; + } + if (type == EnterNotify) { + return "EnterNotify"; + } + if (type == LeaveNotify) { + return "LeaveNotify"; + } + if (type == FocusIn) { + return "FocusIn"; + } + if (type == FocusOut) { + return "FocusOut"; + } + if (type == KeymapNotify) { + return "KeymapNotify"; + } + if (type == Expose) { + return "Expose"; + } + if (type == GraphicsExpose) { + return "GraphicsExpose"; + } + if (type == NoExpose) { + return "NoExpose"; + } + if (type == VisibilityNotify) { + return "VisibilityNotify"; + } + if (type == CreateNotify) { + return "CreateNotify"; + } + if (type == DestroyNotify) { + return "DestroyNotify"; + } + if (type == UnmapNotify) { + return "UnmapNotify"; + } + if (type == MapNotify) { + return "MapNotify"; + } + if (type == MapRequest) { + return "MapRequest"; + } + if (type == ReparentNotify) { + return "ReparentNotify"; + } + if (type == ConfigureNotify) { + return "ConfigureNotify"; + } + if (type == ConfigureRequest) { + return "ConfigureRequest"; + } + if (type == GravityNotify) { + return "GravityNotify"; + } + if (type == ResizeRequest) { + return "ResizeRequest"; + } + if (type == CirculateNotify) { + return "CirculateNotify"; + } + if (type == CirculateRequest) { + return "CirculateRequest"; + } + if (type == PropertyNotify) { + return "PropertyNotify"; + } + if (type == SelectionClear) { + return "SelectionClear"; + } + if (type == SelectionRequest) { + return "SelectionRequest"; + } + if (type == SelectionNotify) { + return "SelectionNotify"; + } + if (type == ColormapNotify) { + return "ColormapNotify"; + } + if (type == ClientMessage) { + return "ClientMessage"; + } + if (type == MappingNotify) { + return "MappingNotify"; + } + return "Bad Event!"; } const char * request_code_to_name(int code) { - if (code == X_CreateWindow) { - return "XCreateWindow"; - } - if (code == X_ChangeWindowAttributes) { - return "XChangeWindowAttributes"; - } - if (code == X_GetWindowAttributes) { - return "XGetWindowAttributes"; - } - if (code == X_DestroyWindow) { - return "XDestroyWindow"; - } - if (code == X_DestroySubwindows) { - return "XDestroySubwindows"; - } - if (code == X_ChangeSaveSet) { - return "XChangeSaveSet"; - } - if (code == X_ReparentWindow) { - return "XReparentWindow"; - } - if (code == X_MapWindow) { - return "XMapWindow"; - } - if (code == X_MapSubwindows) { - return "XMapSubwindows"; - } - if (code == X_UnmapWindow) { - return "XUnmapWindow"; - } - if (code == X_UnmapSubwindows) { - return "XUnmapSubwindows"; - } - if (code == X_ConfigureWindow) { - return "XConfigureWindow"; - } - if (code == X_CirculateWindow) { - return "XCirculateWindow"; - } - if (code == X_GetGeometry) { - return "XGetGeometry"; - } - if (code == X_QueryTree) { - return "XQueryTree"; - } - if (code == X_InternAtom) { - return "XInternAtom"; - } - if (code == X_GetAtomName) { - return "XGetAtomName"; - } - if (code == X_ChangeProperty) { - return "XChangeProperty"; - } - if (code == X_DeleteProperty) { - return "XDeleteProperty"; - } - if (code == X_GetProperty) { - return "XGetProperty"; - } - if (code == X_ListProperties) { - return "XListProperties"; - } - if (code == X_SetSelectionOwner) { - return "XSetSelectionOwner"; - } - if (code == X_GetSelectionOwner) { - return "XGetSelectionOwner"; - } - if (code == X_ConvertSelection) { - return "XConvertSelection"; - } - if (code == X_SendEvent) { - return "XSendEvent"; - } - if (code == X_GrabPointer) { - return "XGrabPointer"; - } - if (code == X_UngrabPointer) { - return "XUngrabPointer"; - } - if (code == X_GrabButton) { - return "XGrabButton"; - } - if (code == X_UngrabButton) { - return "XUngrabButton"; - } - if (code == X_ChangeActivePointerGrab) { - return "XChangeActivePointerGrab"; - } - if (code == X_GrabKeyboard) { - return "XGrabKeyboard"; - } - if (code == X_UngrabKeyboard) { - return "XUngrabKeyboard"; - } - if (code == X_GrabKey) { - return "XGrabKey"; - } - if (code == X_UngrabKey) { - return "XUngrabKey"; - } - if (code == X_AllowEvents) { - return "XAllowEvents"; - } - if (code == X_GrabServer) { - return "XGrabServer"; - } - if (code == X_UngrabServer) { - return "XUngrabServer"; - } - if (code == X_QueryPointer) { - return "XQueryPointer"; - } - if (code == X_GetMotionEvents) { - return "XGetMotionEvents"; - } - if (code == X_TranslateCoords) { - return "XTranslateCoords"; - } - if (code == X_WarpPointer) { - return "XWarpPointer"; - } - if (code == X_SetInputFocus) { - return "XSetInputFocus"; - } - if (code == X_GetInputFocus) { - return "XGetInputFocus"; - } - if (code == X_QueryKeymap) { - return "XQueryKeymap"; - } - if (code == X_OpenFont) { - return "XOpenFont"; - } - if (code == X_CloseFont) { - return "XCloseFont"; - } - if (code == X_QueryFont) { - return "XQueryFont"; - } - if (code == X_QueryTextExtents) { - return "XQueryTextExtents"; - } - if (code == X_ListFonts) { - return "XListFonts"; - } - if (code == X_ListFontsWithInfo) { - return "XListFontsWithInfo"; - } - if (code == X_SetFontPath) { - return "XSetFontPath"; - } - if (code == X_GetFontPath) { - return "XGetFontPath"; - } - if (code == X_CreatePixmap) { - return "XCreatePixmap"; - } - if (code == X_FreePixmap) { - return "XFreePixmap"; - } - if (code == X_CreateGC) { - return "XCreateGC"; - } - if (code == X_ChangeGC) { - return "XChangeGC"; - } - if (code == X_CopyGC) { - return "XCopyGC"; - } - if (code == X_SetDashes) { - return "XSetDashes"; - } - if (code == X_SetClipRectangles) { - return "XSetClipRectangles"; - } - if (code == X_FreeGC) { - return "XFreeGC"; - } - if (code == X_ClearArea) { - return "XClearArea"; - } - if (code == X_CopyArea) { - return "XCopyArea"; - } - if (code == X_CopyPlane) { - return "XCopyPlane"; - } - if (code == X_PolyPoint) { - return "XPolyPoint"; - } - if (code == X_PolyLine) { - return "XPolyLine"; - } - if (code == X_PolySegment) { - return "XPolySegment"; - } - if (code == X_PolyRectangle) { - return "XPolyRectangle"; - } - if (code == X_PolyArc) { - return "XPolyArc"; - } - if (code == X_FillPoly) { - return "XFillPoly"; - } - if (code == X_PolyFillRectangle) { - return "XPolyFillRectangle"; - } - if (code == X_PolyFillArc) { - return "XPolyFillArc"; - } - if (code == X_PutImage) { - return "XPutImage"; - } - if (code == X_GetImage) { - return "XGetImage"; - } - if (code == X_PolyText8) { - return "XPolyText8"; - } - if (code == X_PolyText16) { - return "XPolyText16"; - } - if (code == X_ImageText8) { - return "XImageText8"; - } - if (code == X_ImageText16) { - return "XImageText16"; - } - if (code == X_CreateColormap) { - return "XCreateColormap"; - } - if (code == X_FreeColormap) { - return "XFreeColormap"; - } - if (code == X_CopyColormapAndFree) { - return "XCopyColormapAndFree"; - } - if (code == X_InstallColormap) { - return "XInstallColormap"; - } - if (code == X_UninstallColormap) { - return "XUninstallColormap"; - } - if (code == X_ListInstalledColormaps) { - return "XListInstalledColormaps"; - } - if (code == X_AllocColor) { - return "XAllocColor"; - } - if (code == X_AllocNamedColor) { - return "XAllocNamedColor"; - } - if (code == X_AllocColorCells) { - return "XAllocColorCells"; - } - if (code == X_AllocColorPlanes) { - return "XAllocColorPlanes"; - } - if (code == X_FreeColors) { - return "XFreeColors"; - } - if (code == X_StoreColors) { - return "XStoreColors"; - } - if (code == X_StoreNamedColor) { - return "XStoreNamedColor"; - } - if (code == X_QueryColors) { - return "XQueryColors"; - } - if (code == X_LookupColor) { - return "XLookupColor"; - } - if (code == X_CreateCursor) { - return "XCreateCursor"; - } - if (code == X_CreateGlyphCursor) { - return "XCreateGlyphCursor"; - } - if (code == X_FreeCursor) { - return "XFreeCursor"; - } - if (code == X_RecolorCursor) { - return "XRecolorCursor"; - } - if (code == X_QueryBestSize) { - return "XQueryBestSize"; - } - if (code == X_QueryExtension) { - return "XQueryExtension"; - } - if (code == X_ListExtensions) { - return "XListExtensions"; - } - if (code == X_ChangeKeyboardMapping) { - return "XChangeKeyboardMapping"; - } - if (code == X_GetKeyboardMapping) { - return "XGetKeyboardMapping"; - } - if (code == X_ChangeKeyboardControl) { - return "XChangeKeyboardControl"; - } - if (code == X_GetKeyboardControl) { - return "XGetKeyboardControl"; - } - if (code == X_Bell) { - return "XBell"; - } - if (code == X_ChangePointerControl) { - return "XChangePointerControl"; - } - if (code == X_GetPointerControl) { - return "XGetPointerControl"; - } - if (code == X_SetScreenSaver) { - return "XSetScreenSaver"; - } - if (code == X_GetScreenSaver) { - return "XGetScreenSaver"; - } - if (code == X_ChangeHosts) { - return "XChangeHosts"; - } - if (code == X_ListHosts) { - return "XListHosts"; - } - if (code == X_SetAccessControl) { - return "XSetAccessControl"; - } - if (code == X_SetCloseDownMode) { - return "XSetCloseDownMode"; - } - if (code == X_KillClient) { - return "XKillClient"; - } - if (code == X_RotateProperties) { - return "XRotateProperties"; - } - if (code == X_ForceScreenSaver) { - return "XForceScreenSaver"; - } - if (code == X_SetPointerMapping) { - return "XSetPointerMapping"; - } - if (code == X_GetPointerMapping) { - return "XGetPointerMapping"; - } - if (code == X_SetModifierMapping) { - return "XSetModifierMapping"; - } - if (code == X_GetModifierMapping) { - return "XGetModifierMapping"; - } - if (code == X_NoOperation) { - return "XNoOperation"; - } - return "Unknown"; + if (code == X_CreateWindow) { + return "XCreateWindow"; + } + if (code == X_ChangeWindowAttributes) { + return "XChangeWindowAttributes"; + } + if (code == X_GetWindowAttributes) { + return "XGetWindowAttributes"; + } + if (code == X_DestroyWindow) { + return "XDestroyWindow"; + } + if (code == X_DestroySubwindows) { + return "XDestroySubwindows"; + } + if (code == X_ChangeSaveSet) { + return "XChangeSaveSet"; + } + if (code == X_ReparentWindow) { + return "XReparentWindow"; + } + if (code == X_MapWindow) { + return "XMapWindow"; + } + if (code == X_MapSubwindows) { + return "XMapSubwindows"; + } + if (code == X_UnmapWindow) { + return "XUnmapWindow"; + } + if (code == X_UnmapSubwindows) { + return "XUnmapSubwindows"; + } + if (code == X_ConfigureWindow) { + return "XConfigureWindow"; + } + if (code == X_CirculateWindow) { + return "XCirculateWindow"; + } + if (code == X_GetGeometry) { + return "XGetGeometry"; + } + if (code == X_QueryTree) { + return "XQueryTree"; + } + if (code == X_InternAtom) { + return "XInternAtom"; + } + if (code == X_GetAtomName) { + return "XGetAtomName"; + } + if (code == X_ChangeProperty) { + return "XChangeProperty"; + } + if (code == X_DeleteProperty) { + return "XDeleteProperty"; + } + if (code == X_GetProperty) { + return "XGetProperty"; + } + if (code == X_ListProperties) { + return "XListProperties"; + } + if (code == X_SetSelectionOwner) { + return "XSetSelectionOwner"; + } + if (code == X_GetSelectionOwner) { + return "XGetSelectionOwner"; + } + if (code == X_ConvertSelection) { + return "XConvertSelection"; + } + if (code == X_SendEvent) { + return "XSendEvent"; + } + if (code == X_GrabPointer) { + return "XGrabPointer"; + } + if (code == X_UngrabPointer) { + return "XUngrabPointer"; + } + if (code == X_GrabButton) { + return "XGrabButton"; + } + if (code == X_UngrabButton) { + return "XUngrabButton"; + } + if (code == X_ChangeActivePointerGrab) { + return "XChangeActivePointerGrab"; + } + if (code == X_GrabKeyboard) { + return "XGrabKeyboard"; + } + if (code == X_UngrabKeyboard) { + return "XUngrabKeyboard"; + } + if (code == X_GrabKey) { + return "XGrabKey"; + } + if (code == X_UngrabKey) { + return "XUngrabKey"; + } + if (code == X_AllowEvents) { + return "XAllowEvents"; + } + if (code == X_GrabServer) { + return "XGrabServer"; + } + if (code == X_UngrabServer) { + return "XUngrabServer"; + } + if (code == X_QueryPointer) { + return "XQueryPointer"; + } + if (code == X_GetMotionEvents) { + return "XGetMotionEvents"; + } + if (code == X_TranslateCoords) { + return "XTranslateCoords"; + } + if (code == X_WarpPointer) { + return "XWarpPointer"; + } + if (code == X_SetInputFocus) { + return "XSetInputFocus"; + } + if (code == X_GetInputFocus) { + return "XGetInputFocus"; + } + if (code == X_QueryKeymap) { + return "XQueryKeymap"; + } + if (code == X_OpenFont) { + return "XOpenFont"; + } + if (code == X_CloseFont) { + return "XCloseFont"; + } + if (code == X_QueryFont) { + return "XQueryFont"; + } + if (code == X_QueryTextExtents) { + return "XQueryTextExtents"; + } + if (code == X_ListFonts) { + return "XListFonts"; + } + if (code == X_ListFontsWithInfo) { + return "XListFontsWithInfo"; + } + if (code == X_SetFontPath) { + return "XSetFontPath"; + } + if (code == X_GetFontPath) { + return "XGetFontPath"; + } + if (code == X_CreatePixmap) { + return "XCreatePixmap"; + } + if (code == X_FreePixmap) { + return "XFreePixmap"; + } + if (code == X_CreateGC) { + return "XCreateGC"; + } + if (code == X_ChangeGC) { + return "XChangeGC"; + } + if (code == X_CopyGC) { + return "XCopyGC"; + } + if (code == X_SetDashes) { + return "XSetDashes"; + } + if (code == X_SetClipRectangles) { + return "XSetClipRectangles"; + } + if (code == X_FreeGC) { + return "XFreeGC"; + } + if (code == X_ClearArea) { + return "XClearArea"; + } + if (code == X_CopyArea) { + return "XCopyArea"; + } + if (code == X_CopyPlane) { + return "XCopyPlane"; + } + if (code == X_PolyPoint) { + return "XPolyPoint"; + } + if (code == X_PolyLine) { + return "XPolyLine"; + } + if (code == X_PolySegment) { + return "XPolySegment"; + } + if (code == X_PolyRectangle) { + return "XPolyRectangle"; + } + if (code == X_PolyArc) { + return "XPolyArc"; + } + if (code == X_FillPoly) { + return "XFillPoly"; + } + if (code == X_PolyFillRectangle) { + return "XPolyFillRectangle"; + } + if (code == X_PolyFillArc) { + return "XPolyFillArc"; + } + if (code == X_PutImage) { + return "XPutImage"; + } + if (code == X_GetImage) { + return "XGetImage"; + } + if (code == X_PolyText8) { + return "XPolyText8"; + } + if (code == X_PolyText16) { + return "XPolyText16"; + } + if (code == X_ImageText8) { + return "XImageText8"; + } + if (code == X_ImageText16) { + return "XImageText16"; + } + if (code == X_CreateColormap) { + return "XCreateColormap"; + } + if (code == X_FreeColormap) { + return "XFreeColormap"; + } + if (code == X_CopyColormapAndFree) { + return "XCopyColormapAndFree"; + } + if (code == X_InstallColormap) { + return "XInstallColormap"; + } + if (code == X_UninstallColormap) { + return "XUninstallColormap"; + } + if (code == X_ListInstalledColormaps) { + return "XListInstalledColormaps"; + } + if (code == X_AllocColor) { + return "XAllocColor"; + } + if (code == X_AllocNamedColor) { + return "XAllocNamedColor"; + } + if (code == X_AllocColorCells) { + return "XAllocColorCells"; + } + if (code == X_AllocColorPlanes) { + return "XAllocColorPlanes"; + } + if (code == X_FreeColors) { + return "XFreeColors"; + } + if (code == X_StoreColors) { + return "XStoreColors"; + } + if (code == X_StoreNamedColor) { + return "XStoreNamedColor"; + } + if (code == X_QueryColors) { + return "XQueryColors"; + } + if (code == X_LookupColor) { + return "XLookupColor"; + } + if (code == X_CreateCursor) { + return "XCreateCursor"; + } + if (code == X_CreateGlyphCursor) { + return "XCreateGlyphCursor"; + } + if (code == X_FreeCursor) { + return "XFreeCursor"; + } + if (code == X_RecolorCursor) { + return "XRecolorCursor"; + } + if (code == X_QueryBestSize) { + return "XQueryBestSize"; + } + if (code == X_QueryExtension) { + return "XQueryExtension"; + } + if (code == X_ListExtensions) { + return "XListExtensions"; + } + if (code == X_ChangeKeyboardMapping) { + return "XChangeKeyboardMapping"; + } + if (code == X_GetKeyboardMapping) { + return "XGetKeyboardMapping"; + } + if (code == X_ChangeKeyboardControl) { + return "XChangeKeyboardControl"; + } + if (code == X_GetKeyboardControl) { + return "XGetKeyboardControl"; + } + if (code == X_Bell) { + return "XBell"; + } + if (code == X_ChangePointerControl) { + return "XChangePointerControl"; + } + if (code == X_GetPointerControl) { + return "XGetPointerControl"; + } + if (code == X_SetScreenSaver) { + return "XSetScreenSaver"; + } + if (code == X_GetScreenSaver) { + return "XGetScreenSaver"; + } + if (code == X_ChangeHosts) { + return "XChangeHosts"; + } + if (code == X_ListHosts) { + return "XListHosts"; + } + if (code == X_SetAccessControl) { + return "XSetAccessControl"; + } + if (code == X_SetCloseDownMode) { + return "XSetCloseDownMode"; + } + if (code == X_KillClient) { + return "XKillClient"; + } + if (code == X_RotateProperties) { + return "XRotateProperties"; + } + if (code == X_ForceScreenSaver) { + return "XForceScreenSaver"; + } + if (code == X_SetPointerMapping) { + return "XSetPointerMapping"; + } + if (code == X_GetPointerMapping) { + return "XGetPointerMapping"; + } + if (code == X_SetModifierMapping) { + return "XSetModifierMapping"; + } + if (code == X_GetModifierMapping) { + return "XGetModifierMapping"; + } + if (code == X_NoOperation) { + return "XNoOperation"; + } + return "Unknown"; } const char * get_ctrl_char_name(char c) { - 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 */ + }; - return ((c < ' ') ? (lookup[(int) c]) : ("")); + return ((c < ' ') ? (lookup[(int) c]) : ("")); } static void -hard_exit(void) { +hard_exit(void) +{ #ifdef HAVE__EXIT - _exit(-1); + _exit(-1); #elif defined(SIGKILL) - kill(cmd_pid, SIGKILL); - abort(); + kill(cmd_pid, SIGKILL); + abort(); #else - kill(cmd_pid, 9); - abort(); + kill(cmd_pid, 9); + abort(); #endif } @@ -980,41 +980,41 @@ hard_exit(void) { void dump_stack_trace(void) { - char cmd[256]; - struct stat st; + char cmd[256]; + struct stat st; #ifdef NO_STACK_TRACE - return; + return; #endif - print_error("Attempting to dump a stack trace....\n"); - signal(SIGTSTP, exit); /* Don't block on tty output, just die */ + print_error("Attempting to dump a stack trace....\n"); + signal(SIGTSTP, exit); /* Don't block on tty output, just die */ #ifdef HAVE_U_STACK_TRACE - U_STACK_TRACE(); - return; -#elif defined(GDB) - if (((stat(GDB_CMD_FILE, &st)) != 0) || (!S_ISREG(st.st_mode))) { + U_STACK_TRACE(); return; - } - snprintf(cmd, sizeof(cmd), GDB " -x " GDB_CMD_FILE " " APL_NAME " %d", getpid()); +#elif defined(GDB) + if (((stat(GDB_CMD_FILE, &st)) != 0) || (!S_ISREG(st.st_mode))) { + return; + } + snprintf(cmd, sizeof(cmd), GDB " -x " GDB_CMD_FILE " " APL_NAME " %d", getpid()); #elif defined(PSTACK) - snprintf(cmd, sizeof(cmd), PSTACK " %d", getpid()); + snprintf(cmd, sizeof(cmd), PSTACK " %d", getpid()); #elif defined(DBX) # ifdef _AIX - snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " -a %d", getpid()); + snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " -a %d", getpid()); # elif defined(__sgi) - snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " -p %d", getpid()); + snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " -p %d", getpid()); # else - snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " %s %d", orig_argv0, getpid()); + snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " %s %d", orig_argv0, getpid()); # endif #else - print_error("Your system does not support any of the methods Eterm uses. Exiting.\n"); - return; + print_error("Your system does not support any of the methods Eterm uses. Exiting.\n"); + return; #endif - signal(SIGALRM, (eterm_sighandler_t) hard_exit); - alarm(3); - system(cmd); + signal(SIGALRM, (eterm_sighandler_t) hard_exit); + alarm(3); + system(cmd); } /* signal handling, exit handler */ @@ -1025,34 +1025,33 @@ static RETSIGTYPE handle_child_signal(int sig) { - int pid, save_errno = errno; + int pid, save_errno = errno; - D_CMD(("Received signal %s (%d)\n", sig_to_str(sig), sig)); + D_CMD(("Received signal %s (%d)\n", sig_to_str(sig), sig)); - do { - errno = 0; - } while ((-1 == (pid = waitpid(-1, NULL, WNOHANG))) && - (errno == EINTR)); + do { + errno = 0; + } while ((-1 == (pid = waitpid(-1, NULL, WNOHANG))) && (errno == EINTR)); - D_CMD(("pid == %d, cmd_pid == %d\n", pid, cmd_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 == cmd_pid && cmd_pid != -1) - || (pid == -1 && errno == ECHILD && cmd_pid != -1) - || (pid == 0)) { - if (Options & Opt_pause) { - paused = 1; - return; + D_CMD(("pid == %d, cmd_pid == %d\n", pid, cmd_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 == cmd_pid && cmd_pid != -1) + || (pid == -1 && errno == ECHILD && cmd_pid != -1) + || (pid == 0)) { + if (Options & Opt_pause) { + paused = 1; + return; + } + exit(EXIT_SUCCESS); } - exit(EXIT_SUCCESS); - } - errno = save_errno; + errno = save_errno; - D_CMD(("handle_child_signal: installing signal handler\n")); - signal(SIGCHLD, handle_child_signal); + D_CMD(("handle_child_signal: installing signal handler\n")); + signal(SIGCHLD, handle_child_signal); - SIG_RETURN(0); + SIG_RETURN(0); } /* Handles signals usually sent by a user, like HUP, TERM, INT. */ @@ -1060,18 +1059,18 @@ static RETSIGTYPE handle_exit_signal(int sig) { - print_error("Received terminal signal %s (%d)\n", sig_to_str(sig), sig); - signal(sig, SIG_DFL); + print_error("Received terminal signal %s (%d)\n", sig_to_str(sig), sig); + signal(sig, SIG_DFL); #ifdef UTMP_SUPPORT - privileges(INVOKE); - remove_utmp_entry(); - privileges(REVERT); + privileges(INVOKE); + remove_utmp_entry(); + privileges(REVERT); #endif - D_CMD(("exit(%s)\n", sig_to_str(sig))); - exit(sig); - SIG_RETURN(0); + D_CMD(("exit(%s)\n", sig_to_str(sig))); + exit(sig); + SIG_RETURN(0); } /* Handles abnormal termination signals -- mej */ @@ -1079,40 +1078,40 @@ static RETSIGTYPE handle_crash(int sig) { - print_error("Received terminal signal %s (%d)\n", sig_to_str(sig), sig); - signal(sig, SIG_DFL); /* Let the OS handle recursive seg faults */ + print_error("Received terminal signal %s (%d)\n", sig_to_str(sig), sig); + signal(sig, SIG_DFL); /* Let the OS handle recursive seg faults */ - /* Lock down security so we don't write any core files as root. */ - privileges(REVERT); - umask(077); + /* Lock down security so we don't write any core files as root. */ + privileges(REVERT); + umask(077); - /* Make an attempt to dump a stack trace */ - dump_stack_trace(); + /* Make an attempt to dump a stack trace */ + dump_stack_trace(); - /* Exit */ - exit(sig); - SIG_RETURN(0); + /* Exit */ + exit(sig); + SIG_RETURN(0); } void install_handlers(void) { - /* Ignore SIGHUP */ - /* signal(SIGHUP, handle_exit_signal); */ - signal(SIGHUP, SIG_IGN); + /* Ignore SIGHUP */ + /* signal(SIGHUP, handle_exit_signal); */ + signal(SIGHUP, SIG_IGN); #ifndef __svr4__ - signal(SIGINT, handle_exit_signal); + signal(SIGINT, handle_exit_signal); #endif - signal(SIGTERM, handle_exit_signal); - signal(SIGCHLD, handle_child_signal); - signal(SIGQUIT, handle_crash); - signal(SIGSEGV, handle_crash); - signal(SIGBUS, handle_crash); - signal(SIGABRT, handle_crash); - signal(SIGFPE, handle_crash); - signal(SIGILL, handle_crash); - signal(SIGSYS, handle_crash); - signal(SIGPIPE, SIG_IGN); + signal(SIGTERM, handle_exit_signal); + signal(SIGCHLD, handle_child_signal); + signal(SIGQUIT, handle_crash); + signal(SIGSEGV, handle_crash); + signal(SIGBUS, handle_crash); + signal(SIGABRT, handle_crash); + signal(SIGFPE, handle_crash); + signal(SIGILL, handle_crash); + signal(SIGSYS, handle_crash); + signal(SIGPIPE, SIG_IGN); } /* Exit gracefully, clearing the utmp entry and restoring tty attributes */ @@ -1120,66 +1119,66 @@ void clean_exit(void) { #if DEBUG >= DEBUG_MEM - if (DEBUG_LEVEL >= DEBUG_MEM) { - unsigned short i; + if (DEBUG_LEVEL >= DEBUG_MEM) { + unsigned short i; - /* Deallocate all our crap to help find memory leaks */ - selection_clear(); - scr_release(); - bbar_free(buttonbar); - menulist_clear(menu_list); - font_cache_clear(); - eterm_font_list_clear(); + /* Deallocate all our crap to help find memory leaks */ + selection_clear(); + scr_release(); + bbar_free(buttonbar); + menulist_clear(menu_list); + font_cache_clear(); + eterm_font_list_clear(); # ifdef PIXMAP_SUPPORT - FOREACH_IMAGE(free_eterm_image(&(images[idx]));); + FOREACH_IMAGE(free_eterm_image(&(images[idx])); + ); # endif - for (i = 0; i < NRS_COLORS; i++) { - if (rs_color[i]) { - FREE(rs_color[i]); - } - } - conf_free_subsystem(); + for (i = 0; i < NRS_COLORS; i++) { + if (rs_color[i]) { + FREE(rs_color[i]); + } + } + conf_free_subsystem(); # ifdef USE_XIM - if (xim_input_context) { - XUnsetICFocus(xim_input_context); - XDestroyIC(xim_input_context); - } - if (xim_input_method) { - XCloseIM(xim_input_method); - } + if (xim_input_context) { + XUnsetICFocus(xim_input_context); + XDestroyIC(xim_input_context); + } + if (xim_input_method) { + XCloseIM(xim_input_method); + } # endif - XCloseDisplay(Xdisplay); - } + XCloseDisplay(Xdisplay); + } #endif - privileges(INVOKE); + privileges(INVOKE); #ifndef __CYGWIN32__ - if (ttydev) { - D_CMD(("Restoring \"%s\" to mode %03o, uid %d, gid %d\n", ttydev, ttyfd_stat.st_mode, - ttyfd_stat.st_uid, ttyfd_stat.st_gid)); - if (chmod(ttydev, ttyfd_stat.st_mode) != 0) { - D_UTMP(("chmod(\"%s\", %03o) failed: %s\n", ttydev, ttyfd_stat.st_mode, strerror(errno))); + if (ttydev) { + D_CMD(("Restoring \"%s\" to mode %03o, uid %d, gid %d\n", ttydev, ttyfd_stat.st_mode, ttyfd_stat.st_uid, ttyfd_stat.st_gid)); + if (chmod(ttydev, ttyfd_stat.st_mode) != 0) { + D_UTMP(("chmod(\"%s\", %03o) failed: %s\n", ttydev, ttyfd_stat.st_mode, strerror(errno))); + } + if (chown(ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid) != 0) { + D_UTMP(("chown(\"%s\", %d, %d) failed: %s\n", ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid, strerror(errno))); + } } - if (chown(ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid) != 0) { - D_UTMP(("chown(\"%s\", %d, %d) failed: %s\n", ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid, strerror(errno))); - } - } #endif /* __CYGWIN32__ */ #ifdef UTMP_SUPPORT - remove_utmp_entry(); + remove_utmp_entry(); #endif - privileges(REVERT); + privileges(REVERT); #if DEBUG >= DEBUG_MEM - if (DEBUG_LEVEL >= DEBUG_MEM) { - MALLOC_DUMP(); - PIXMAP_DUMP(); - GC_DUMP(); - } + if (DEBUG_LEVEL >= DEBUG_MEM) { + MALLOC_DUMP(); + PIXMAP_DUMP(); + GC_DUMP(); + } #endif - PABLO_STOP_TRACING(); - DPRINTF1(("Cleanup done. I am outta here!\n")); + PABLO_STOP_TRACING(); + DPRINTF1(("Cleanup done. I am outta here!\n")); } /* Acquire a pseudo-teletype from the system. */ @@ -1197,12 +1196,12 @@ inline int sgi_get_pty(void); inline int sgi_get_pty(void) { - int fd = -1; + int fd = -1; - privileges(INVOKE); - ptydev = ttydev = _getpty(&fd, O_RDWR | O_NDELAY, 0620, 0); - privileges(REVERT); - return (ptydev == NULL ? -1 : fd); + privileges(INVOKE); + ptydev = ttydev = _getpty(&fd, O_RDWR | O_NDELAY, 0620, 0); + privileges(REVERT); + return (ptydev == NULL ? -1 : fd); } #endif @@ -1214,13 +1213,13 @@ inline int aix_get_pty(void) { - int fd = -1; + int fd = -1; - if ((fd = open("/dev/ptc", O_RDWR)) < 0) - return (-1); - else - ptydev = ttydev = ttyname(fd); - return (fd); + if ((fd = open("/dev/ptc", O_RDWR)) < 0) + return (-1); + else + ptydev = ttydev = ttyname(fd); + return (fd); } #endif @@ -1231,30 +1230,30 @@ inline int sco_get_pty(void) { - static char pty_name[] = "/dev/ptyp??\0\0\0"; - static char tty_name[] = "/dev/ttyp??\0\0\0"; - int idx; - int fd = -1; + static char pty_name[] = "/dev/ptyp??\0\0\0"; + static char tty_name[] = "/dev/ttyp??\0\0\0"; + int idx; + int fd = -1; - ptydev = pty_name; - ttydev = tty_name; + ptydev = pty_name; + ttydev = tty_name; - for (idx = 0; idx < 256; idx++) { + for (idx = 0; idx < 256; idx++) { - sprintf(ptydev, "/dev/ptyp%d", idx); - sprintf(ttydev, "/dev/ttyp%d", idx); + sprintf(ptydev, "/dev/ptyp%d", idx); + sprintf(ttydev, "/dev/ttyp%d", idx); - if (access(ttydev, F_OK) < 0) { - idx = 256; - break; + if (access(ttydev, F_OK) < 0) { + idx = 256; + break; + } + if ((fd = open(ptydev, O_RDWR)) >= 0) { + if (access(ttydev, R_OK | W_OK) == 0) + return (fd); + close(fd); + } } - if ((fd = open(ptydev, O_RDWR)) >= 0) { - if (access(ttydev, R_OK | W_OK) == 0) - return (fd); - close(fd); - } - } - return (-1); + return (-1); } #endif @@ -1265,27 +1264,27 @@ inline int svr_get_pty(void) { - int fd = -1; + int fd = -1; - /* open the STREAMS, clone device /dev/ptmx (master pty) */ - if ((fd = open("/dev/ptmx", O_RDWR)) < 0) { - return (-1); - } else { - if (grantpt(fd) != 0) { - print_error("grantpt(%d) failed: %s\n", fd, strerror(errno)); - return (-1); - } else if (unlockpt(fd) != 0) { - print_error("unlockpt(%d) failed: %s\n", fd, strerror(errno)); - return (-1); + /* open the STREAMS, clone device /dev/ptmx (master pty) */ + if ((fd = open("/dev/ptmx", O_RDWR)) < 0) { + return (-1); } else { - ptydev = ttydev = ptsname(fd); - if (ttydev == NULL) { - print_error("ptsname(%d) failed: %s\n", fd, strerror(errno)); - return (-1); - } + if (grantpt(fd) != 0) { + print_error("grantpt(%d) failed: %s\n", fd, strerror(errno)); + return (-1); + } else if (unlockpt(fd) != 0) { + print_error("unlockpt(%d) failed: %s\n", fd, strerror(errno)); + return (-1); + } else { + ptydev = ttydev = ptsname(fd); + if (ttydev == NULL) { + print_error("ptsname(%d) failed: %s\n", fd, strerror(errno)); + return (-1); + } + } } - } - return (fd); + return (fd); } #endif @@ -1298,56 +1297,56 @@ inline int gen_get_pty(void) { - static char pty_name[] = "/dev/pty??"; - static char tty_name[] = "/dev/tty??"; - int len = sizeof(tty_name); - char *c1, *c2; - int fd = -1; + static char pty_name[] = "/dev/pty??"; + static char tty_name[] = "/dev/tty??"; + int len = sizeof(tty_name); + char *c1, *c2; + int fd = -1; - ptydev = pty_name; - ttydev = tty_name; + ptydev = pty_name; + ttydev = tty_name; - for (c1 = PTYCHAR1; *c1; c1++) { - ptydev[len - 3] = ttydev[len - 3] = *c1; - for (c2 = PTYCHAR2; *c2; c2++) { - ptydev[len - 2] = ttydev[len - 2] = *c2; - if ((fd = open(ptydev, O_RDWR)) >= 0) { - if (access(ttydev, R_OK | W_OK) == 0) - return (fd); - close(fd); - } + for (c1 = PTYCHAR1; *c1; c1++) { + ptydev[len - 3] = ttydev[len - 3] = *c1; + for (c2 = PTYCHAR2; *c2; c2++) { + ptydev[len - 2] = ttydev[len - 2] = *c2; + if ((fd = open(ptydev, O_RDWR)) >= 0) { + if (access(ttydev, R_OK | W_OK) == 0) + return (fd); + close(fd); + } + } } - } - return (-1); + return (-1); } int get_pty(void) { - int fd = -1; + int fd = -1; #if defined(__sgi) - fd = sgi_get_pty(); + fd = sgi_get_pty(); #elif defined(HAVE_DEV_PTC) - fd = aix_get_pty(); + fd = aix_get_pty(); #elif defined(HAVE_DEV_PTMX) - fd = svr_get_pty(); + fd = svr_get_pty(); #elif defined(HAVE_SCO_PTYS) - fd = sco_get_pty(); + fd = sco_get_pty(); #endif - /* Fall back on this method */ - if (fd == -1) { - fd = gen_get_pty(); - } - if (fd != -1) { - fcntl(fd, F_SETFL, O_NDELAY); - return (fd); - } else { - print_error("Can't open pseudo-tty -- %s\n", strerror(errno)); - return (-1); - } + /* Fall back on this method */ + if (fd == -1) { + fd = gen_get_pty(); + } + if (fd != -1) { + fcntl(fd, F_SETFL, O_NDELAY); + return (fd); + } else { + print_error("Can't open pseudo-tty -- %s\n", strerror(errno)); + return (-1); + } } /* establish a controlling teletype for new session */ @@ -1358,144 +1357,144 @@ get_pty(void) int get_tty(void) { - int fd; - pid_t pid; + int fd; + pid_t pid; - /* - * setsid() [or setpgrp] must be before open of the terminal, - * otherwise there is no controlling terminal (Solaris 2.4, HP-UX 9) - */ + /* + * setsid() [or setpgrp] must be before open of the terminal, + * otherwise there is no controlling terminal (Solaris 2.4, HP-UX 9) + */ #ifndef ultrix -# ifdef NO_SETSID - pid = setpgrp(0, 0); -# else - pid = setsid(); -# endif - if (pid < 0) { - D_TTYMODE(("%s: setsid() failed: %s, PID == %d\n", rs_name, strerror(errno), pid)); - } -#endif /* ultrix */ - - privileges(INVOKE); - if (ttydev == NULL) { - print_error("Slave tty device name is NULL. Failed to open slave pty.\n"); - exit(EXIT_FAILURE); - } else if ((fd = open(ttydev, O_RDWR)) < 0) { - print_error("Can't open slave tty %s -- %s\n", ttydev, strerror(errno)); - exit(EXIT_FAILURE); - } else { - D_TTY(("Opened slave tty %s\n", ttydev)); - privileges(REVERT); - } - -#if defined (__svr4__) - /* - * Push STREAMS modules: - * ptem: pseudo-terminal hardware emulation module. - * ldterm: standard terminal line discipline. - * ttcompat: V7, 4BSD and XENIX STREAMS compatibility module. - */ - ioctl(fd, I_PUSH, "ptem"); - ioctl(fd, I_PUSH, "ldterm"); - ioctl(fd, I_PUSH, "ttcompat"); -#else /* __svr4__ */ - { - unsigned int mode = 0620; - gid_t gid = my_rgid; - -# ifdef PTY_GRP_NAME - { - struct group *gr = getgrnam(PTY_GRP_NAME); - - if (gr) { - gid = gr->gr_gid; - mode = 0620; - } - } -# endif - - privileges(INVOKE); -# ifndef __CYGWIN32__ - fchown(fd, my_ruid, gid); /* fail silently */ - fchmod(fd, mode); -# endif - privileges(REVERT); - } -#endif /* __svr4__ */ - - /* - * Close all file descriptors. If only stdin/out/err are closed, - * child processes remain alive upon deletion of the window. - */ - { - unsigned short i; - unsigned long max_fds; - - /* get number of available file descriptors */ -#ifdef _POSIX_VERSION - max_fds = sysconf(_SC_OPEN_MAX); -#else - max_fds = getdtablesize(); -#endif - - D_TTY(("Closing file descriptors 0-%d.\n", max_fds)); - for (i = 0; i < max_fds; i++) { - if (i != fd) - close(i); - } - D_TTY(("...closed.\n")); - } - - /* Reopen stdin, stdout and stderr over the tty file descriptor */ - dup(fd); /* 0: stdin */ - dup(fd); /* 1: stdout */ - dup(fd); /* 2: stderr */ - - if (fd > 2) - close(fd); - - privileges(INVOKE); - -#ifdef ultrix - if ((fd = open("/dev/tty", O_RDONLY)) >= 0) { - ioctl(fd, TIOCNOTTY, 0); - close(fd); - } else { # ifdef NO_SETSID pid = setpgrp(0, 0); # else pid = setsid(); # endif if (pid < 0) { - D_TTYMODE(("%s: setsid() failed: %s, PID == %d\n", rs_name, strerror(errno), pid)); + D_TTYMODE(("%s: setsid() failed: %s, PID == %d\n", rs_name, strerror(errno), pid)); } - } +#endif /* ultrix */ - /* no error, we could run with no tty to begin with */ + privileges(INVOKE); + if (ttydev == NULL) { + print_error("Slave tty device name is NULL. Failed to open slave pty.\n"); + exit(EXIT_FAILURE); + } else if ((fd = open(ttydev, O_RDWR)) < 0) { + print_error("Can't open slave tty %s -- %s\n", ttydev, strerror(errno)); + exit(EXIT_FAILURE); + } else { + D_TTY(("Opened slave tty %s\n", ttydev)); + privileges(REVERT); + } + +#if defined (__svr4__) + /* + * Push STREAMS modules: + * ptem: pseudo-terminal hardware emulation module. + * ldterm: standard terminal line discipline. + * ttcompat: V7, 4BSD and XENIX STREAMS compatibility module. + */ + ioctl(fd, I_PUSH, "ptem"); + ioctl(fd, I_PUSH, "ldterm"); + ioctl(fd, I_PUSH, "ttcompat"); +#else /* __svr4__ */ + { + unsigned int mode = 0620; + gid_t gid = my_rgid; + +# ifdef PTY_GRP_NAME + { + struct group *gr = getgrnam(PTY_GRP_NAME); + + if (gr) { + gid = gr->gr_gid; + mode = 0620; + } + } +# endif + + privileges(INVOKE); +# ifndef __CYGWIN32__ + fchown(fd, my_ruid, gid); /* fail silently */ + fchmod(fd, mode); +# endif + privileges(REVERT); + } +#endif /* __svr4__ */ + + /* + * Close all file descriptors. If only stdin/out/err are closed, + * child processes remain alive upon deletion of the window. + */ + { + unsigned short i; + unsigned long max_fds; + + /* get number of available file descriptors */ +#ifdef _POSIX_VERSION + max_fds = sysconf(_SC_OPEN_MAX); +#else + max_fds = getdtablesize(); +#endif + + D_TTY(("Closing file descriptors 0-%d.\n", max_fds)); + for (i = 0; i < max_fds; i++) { + if (i != fd) + close(i); + } + D_TTY(("...closed.\n")); + } + + /* Reopen stdin, stdout and stderr over the tty file descriptor */ + dup(fd); /* 0: stdin */ + dup(fd); /* 1: stdout */ + dup(fd); /* 2: stderr */ + + if (fd > 2) + close(fd); + + privileges(INVOKE); + +#ifdef ultrix + if ((fd = open("/dev/tty", O_RDONLY)) >= 0) { + ioctl(fd, TIOCNOTTY, 0); + close(fd); + } else { +# ifdef NO_SETSID + pid = setpgrp(0, 0); +# else + pid = setsid(); +# endif + if (pid < 0) { + D_TTYMODE(("%s: setsid() failed: %s, PID == %d\n", rs_name, strerror(errno), pid)); + } + } + + /* no error, we could run with no tty to begin with */ #else /* ultrix */ # ifdef TIOCSCTTY - ioctl(0, TIOCSCTTY, 0); + ioctl(0, TIOCSCTTY, 0); # endif - /* set process group */ + /* set process group */ # if defined (_POSIX_VERSION) || defined (__svr4__) - tcsetpgrp(0, pid); + tcsetpgrp(0, pid); # elif defined (TIOCSPGRP) - ioctl(0, TIOCSPGRP, &pid); + ioctl(0, TIOCSPGRP, &pid); # endif - /* svr4 problems: reports no tty, no job control */ - /* # if !defined (__svr4__) && defined (TIOCSPGRP) */ + /* svr4 problems: reports no tty, no job control */ + /* # if !defined (__svr4__) && defined (TIOCSPGRP) */ - close(open(ttydev, O_RDWR, 0)); - /* # endif */ + close(open(ttydev, O_RDWR, 0)); + /* # endif */ #endif /* ultrix */ - privileges(REVERT); + privileges(REVERT); - D_TTY(("Returning fd == %d\n", fd)); - return (fd); + D_TTY(("Returning fd == %d\n", fd)); + return (fd); } /* debug_ttymode() */ @@ -1514,65 +1513,65 @@ static void debug_ttymode(ttymode_t *ttymode) { - /* c_iflag bits */ - fprintf(stderr, "Input flags: "); - SHOW_TTY_FLAG(IGNBRK, "IGNBRK"); - SHOW_TTY_FLAG(BRKINT, "BRKINT"); - SHOW_TTY_FLAG(IGNPAR, "IGNPAR"); - SHOW_TTY_FLAG(PARMRK, "PARMRK"); - SHOW_TTY_FLAG(INPCK, "INPCK"); - SHOW_TTY_FLAG(ISTRIP, "ISTRIP"); - SHOW_TTY_FLAG(INLCR, "INLCR"); - SHOW_TTY_FLAG(IGNCR, "IGNCR"); - SHOW_TTY_FLAG(ICRNL, "ICRNL"); - SHOW_TTY_FLAG(IXON, "IXON"); - SHOW_TTY_FLAG(IXOFF, "IXOFF"); + /* c_iflag bits */ + fprintf(stderr, "Input flags: "); + SHOW_TTY_FLAG(IGNBRK, "IGNBRK"); + SHOW_TTY_FLAG(BRKINT, "BRKINT"); + SHOW_TTY_FLAG(IGNPAR, "IGNPAR"); + SHOW_TTY_FLAG(PARMRK, "PARMRK"); + SHOW_TTY_FLAG(INPCK, "INPCK"); + SHOW_TTY_FLAG(ISTRIP, "ISTRIP"); + SHOW_TTY_FLAG(INLCR, "INLCR"); + SHOW_TTY_FLAG(IGNCR, "IGNCR"); + SHOW_TTY_FLAG(ICRNL, "ICRNL"); + SHOW_TTY_FLAG(IXON, "IXON"); + SHOW_TTY_FLAG(IXOFF, "IXOFF"); # ifdef IUCLC - SHOW_TTY_FLAG(IUCLC, "IUCLC"); + SHOW_TTY_FLAG(IUCLC, "IUCLC"); # endif # ifdef IXANY - SHOW_TTY_FLAG(IXANY, "IXANY"); + SHOW_TTY_FLAG(IXANY, "IXANY"); # endif # ifdef IMAXBEL - SHOW_TTY_FLAG(IMAXBEL, "IMAXBEL"); + SHOW_TTY_FLAG(IMAXBEL, "IMAXBEL"); # endif - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); - fprintf(stderr, "Control character mappings: "); - SHOW_CONT_CHAR(VINTR, "VINTR"); - SHOW_CONT_CHAR(VQUIT, "VQUIT"); - SHOW_CONT_CHAR(VERASE, "VERASE"); - SHOW_CONT_CHAR(VKILL, "VKILL"); - SHOW_CONT_CHAR(VEOF, "VEOF"); - SHOW_CONT_CHAR(VEOL, "VEOL"); + fprintf(stderr, "Control character mappings: "); + SHOW_CONT_CHAR(VINTR, "VINTR"); + SHOW_CONT_CHAR(VQUIT, "VQUIT"); + SHOW_CONT_CHAR(VERASE, "VERASE"); + SHOW_CONT_CHAR(VKILL, "VKILL"); + SHOW_CONT_CHAR(VEOF, "VEOF"); + SHOW_CONT_CHAR(VEOL, "VEOL"); # ifdef VEOL2 - SHOW_CONT_CHAR(VEOL2, "VEOL2"); + SHOW_CONT_CHAR(VEOL2, "VEOL2"); # endif # ifdef VSWTC - SHOW_CONT_CHAR(VSWTC, "VSWTC"); + SHOW_CONT_CHAR(VSWTC, "VSWTC"); # endif # ifdef VSWTCH - SHOW_CONT_CHAR(VSWTCH, "VSWTCH"); + SHOW_CONT_CHAR(VSWTCH, "VSWTCH"); # endif - SHOW_CONT_CHAR(VSTART, "VSTART"); - SHOW_CONT_CHAR(VSTOP, "VSTOP"); - SHOW_CONT_CHAR(VSUSP, "VSUSP"); + SHOW_CONT_CHAR(VSTART, "VSTART"); + SHOW_CONT_CHAR(VSTOP, "VSTOP"); + SHOW_CONT_CHAR(VSUSP, "VSUSP"); # ifdef VDSUSP - SHOW_CONT_CHAR(VDSUSP, "VDSUSP"); + SHOW_CONT_CHAR(VDSUSP, "VDSUSP"); # endif # ifdef VREPRINT - SHOW_CONT_CHAR(VREPRINT, "VREPRINT"); + SHOW_CONT_CHAR(VREPRINT, "VREPRINT"); # endif # ifdef VDISCRD - SHOW_CONT_CHAR(VDISCRD, "VDISCRD"); + SHOW_CONT_CHAR(VDISCRD, "VDISCRD"); # endif # ifdef VWERSE - SHOW_CONT_CHAR(VWERSE, "VWERSE"); + SHOW_CONT_CHAR(VWERSE, "VWERSE"); # endif # ifdef VLNEXT - SHOW_CONT_CHAR(VLNEXT, "VLNEXT"); + SHOW_CONT_CHAR(VLNEXT, "VLNEXT"); # endif - fprintf(stderr, "\n\n"); + fprintf(stderr, "\n\n"); } # undef SHOW_TTY_FLAG @@ -1584,135 +1583,135 @@ static void get_ttymode(ttymode_t *tio) { #ifdef HAVE_TERMIOS_H - /* - * standard System V termios interface - */ - if (GET_TERMIOS(0, tio) < 0) { - /* return error - use system defaults */ - tio->c_cc[VINTR] = CINTR; - tio->c_cc[VQUIT] = CQUIT; - tio->c_cc[VERASE] = CERASE; - tio->c_cc[VKILL] = CKILL; - tio->c_cc[VSTART] = CSTART; - tio->c_cc[VSTOP] = CSTOP; - tio->c_cc[VSUSP] = CSUSP; + /* + * standard System V termios interface + */ + if (GET_TERMIOS(0, tio) < 0) { + /* return error - use system defaults */ + tio->c_cc[VINTR] = CINTR; + tio->c_cc[VQUIT] = CQUIT; + tio->c_cc[VERASE] = CERASE; + tio->c_cc[VKILL] = CKILL; + tio->c_cc[VSTART] = CSTART; + tio->c_cc[VSTOP] = CSTOP; + tio->c_cc[VSUSP] = CSUSP; # ifdef VDSUSP - tio->c_cc[VDSUSP] = CDSUSP; + tio->c_cc[VDSUSP] = CDSUSP; # endif # ifdef VREPRINT - tio->c_cc[VREPRINT] = CRPRNT; + tio->c_cc[VREPRINT] = CRPRNT; # endif # ifdef VDISCRD - tio->c_cc[VDISCRD] = CFLUSH; + tio->c_cc[VDISCRD] = CFLUSH; # endif # ifdef VWERSE - tio->c_cc[VWERSE] = CWERASE; + tio->c_cc[VWERSE] = CWERASE; # endif # ifdef VLNEXT - tio->c_cc[VLNEXT] = CLNEXT; + tio->c_cc[VLNEXT] = CLNEXT; # endif # ifdef VSTATUS - tio->c_cc[VSTATUS] = CSTATUS; + tio->c_cc[VSTATUS] = CSTATUS; # endif - } - tio->c_cc[VEOF] = CEOF; - tio->c_cc[VEOL] = VDISABLE; + } + tio->c_cc[VEOF] = CEOF; + tio->c_cc[VEOL] = VDISABLE; # ifdef VEOL2 - tio->c_cc[VEOL2] = VDISABLE; + tio->c_cc[VEOL2] = VDISABLE; # endif # ifdef VSWTC - tio->c_cc[VSWTC] = VDISABLE; + tio->c_cc[VSWTC] = VDISABLE; # endif # ifdef VSWTCH - tio->c_cc[VSWTCH] = VDISABLE; + tio->c_cc[VSWTCH] = VDISABLE; # endif # if VMIN != VEOF - tio->c_cc[VMIN] = 1; + tio->c_cc[VMIN] = 1; # endif # if VTIME != VEOL - tio->c_cc[VTIME] = 0; + tio->c_cc[VTIME] = 0; # endif - /* input modes */ - tio->c_iflag = (BRKINT | IGNPAR | ICRNL | IXON + /* input modes */ + tio->c_iflag = (BRKINT | IGNPAR | ICRNL | IXON # ifdef IMAXBEL - | IMAXBEL + | IMAXBEL # endif - ); + ); - /* output modes */ - tio->c_oflag = (OPOST | ONLCR); + /* output modes */ + tio->c_oflag = (OPOST | ONLCR); - /* control modes */ - tio->c_cflag = (CS8 | CREAD); + /* control modes */ + tio->c_cflag = (CS8 | CREAD); - /* line discipline modes */ - tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK + /* line discipline modes */ + tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK # if defined (ECHOCTL) && defined (ECHOKE) - | ECHOCTL | ECHOKE + | ECHOCTL | ECHOKE # endif - ); + ); #if defined(FORCE_BACKSPACE) && 0 - PrivMode(1, PrivMode_BackSpace); - tio->c_cc[VERASE] = '\b'; /* force ^H for stty setting... */ - SET_TERMIOS(0, tio); /* ...and make it stick -- casey */ + PrivMode(1, PrivMode_BackSpace); + tio->c_cc[VERASE] = '\b'; /* force ^H for stty setting... */ + SET_TERMIOS(0, tio); /* ...and make it stick -- casey */ #elif defined(FORCE_DELETE) && 0 - PrivMode(0, PrivMode_BackSpace); - tio->c_cc[VERASE] = 0x7f; /* force ^? for stty setting... */ - SET_TERMIOS(0, tio); /* ...and make it stick -- casey */ + PrivMode(0, PrivMode_BackSpace); + tio->c_cc[VERASE] = 0x7f; /* force ^? for stty setting... */ + SET_TERMIOS(0, tio); /* ...and make it stick -- casey */ #else - PrivMode((tio->c_cc[VERASE] == '\b'), PrivMode_BackSpace); + PrivMode((tio->c_cc[VERASE] == '\b'), PrivMode_BackSpace); #endif #else /* HAVE_TERMIOS_H */ - /* - * sgtty interface - */ + /* + * sgtty interface + */ - /* get parameters -- gtty */ - if (ioctl(0, TIOCGETP, &(tio->sg)) < 0) { - tio->sg.sg_erase = CERASE; /* ^H */ - tio->sg.sg_kill = CKILL; /* ^U */ - } - tio->sg.sg_flags = (CRMOD | ECHO | EVENP | ODDP); + /* get parameters -- gtty */ + if (ioctl(0, TIOCGETP, &(tio->sg)) < 0) { + tio->sg.sg_erase = CERASE; /* ^H */ + tio->sg.sg_kill = CKILL; /* ^U */ + } + tio->sg.sg_flags = (CRMOD | ECHO | EVENP | ODDP); - /* get special characters */ - if (ioctl(0, TIOCGETC, &(tio->tc)) < 0) { - tio->tc.t_intrc = CINTR; /* ^C */ - tio->tc.t_quitc = CQUIT; /* ^\ */ - tio->tc.t_startc = CSTART; /* ^Q */ - tio->tc.t_stopc = CSTOP; /* ^S */ - tio->tc.t_eofc = CEOF; /* ^D */ - tio->tc.t_brkc = -1; - } - /* get local special chars */ - if (ioctl(0, TIOCGLTC, &(tio->lc)) < 0) { - tio->lc.t_suspc = CSUSP; /* ^Z */ - tio->lc.t_dsuspc = CDSUSP; /* ^Y */ - tio->lc.t_rprntc = CRPRNT; /* ^R */ - tio->lc.t_flushc = CFLUSH; /* ^O */ - tio->lc.t_werasc = CWERASE; /* ^W */ - tio->lc.t_lnextc = CLNEXT; /* ^V */ - } - /* get line discipline */ - ioctl(0, TIOCGETD, &(tio->line)); + /* get special characters */ + if (ioctl(0, TIOCGETC, &(tio->tc)) < 0) { + tio->tc.t_intrc = CINTR; /* ^C */ + tio->tc.t_quitc = CQUIT; /* ^\ */ + tio->tc.t_startc = CSTART; /* ^Q */ + tio->tc.t_stopc = CSTOP; /* ^S */ + tio->tc.t_eofc = CEOF; /* ^D */ + tio->tc.t_brkc = -1; + } + /* get local special chars */ + if (ioctl(0, TIOCGLTC, &(tio->lc)) < 0) { + tio->lc.t_suspc = CSUSP; /* ^Z */ + tio->lc.t_dsuspc = CDSUSP; /* ^Y */ + tio->lc.t_rprntc = CRPRNT; /* ^R */ + tio->lc.t_flushc = CFLUSH; /* ^O */ + tio->lc.t_werasc = CWERASE; /* ^W */ + tio->lc.t_lnextc = CLNEXT; /* ^V */ + } + /* get line discipline */ + ioctl(0, TIOCGETD, &(tio->line)); # ifdef NTTYDISC - tio->line = NTTYDISC; -# endif /* NTTYDISC */ - tio->local = (LCRTBS | LCRTERA | LCTLECH | LPASS8 | LCRTKIL); + tio->line = NTTYDISC; +# endif /* NTTYDISC */ + tio->local = (LCRTBS | LCRTERA | LCTLECH | LPASS8 | LCRTKIL); # ifdef FORCE_BACKSPACE - PrivMode(1, PrivMode_BackSpace); - tio->sg.sg_erase = '\b'; - SET_TTYMODE(0, tio); + PrivMode(1, PrivMode_BackSpace); + tio->sg.sg_erase = '\b'; + SET_TTYMODE(0, tio); # elif defined (FORCE_DELETE) - PrivMode(0, PrivMode_BackSpace); - tio->sg.sg_erase = 0x7f; - SET_TTYMODE(0, tio); + PrivMode(0, PrivMode_BackSpace); + tio->sg.sg_erase = 0x7f; + SET_TTYMODE(0, tio); # else - PrivMode((tio->sg.sg_erase == '\b'), PrivMode_BackSpace); + PrivMode((tio->sg.sg_erase == '\b'), PrivMode_BackSpace); # endif #endif /* HAVE_TERMIOS_H */ @@ -1722,38 +1721,38 @@ get_ttymode(ttymode_t *tio) XFontSet create_fontset(const char *font1, const char *font2) { - XFontSet fontset = 0; - char *fontname, **ml, *ds; - int mc; - const char fs_base[] = ",-misc-fixed-*-r-*-*-*-120-*-*-*-*-*-*,*"; + XFontSet fontset = 0; + char *fontname, **ml, *ds; + int mc; + const char fs_base[] = ",-misc-fixed-*-r-*-*-*-120-*-*-*-*-*-*,*"; - ASSERT(font1 != NULL); + ASSERT(font1 != NULL); - if (font2) { - fontname = MALLOC(strlen(font1) + strlen(font2) + sizeof(fs_base) + 2); + if (font2) { + fontname = MALLOC(strlen(font1) + strlen(font2) + sizeof(fs_base) + 2); + if (fontname) { + strcpy(fontname, font1); + strcat(fontname, ","); + strcat(fontname, font2); + strcat(fontname, fs_base); + } + } else { + fontname = MALLOC(strlen(font1) + sizeof(fs_base) + 1); + if (fontname) { + strcpy(fontname, font1); + strcat(fontname, fs_base); + } + } if (fontname) { - strcpy(fontname, font1); - strcat(fontname, ","); - strcat(fontname, font2); - strcat(fontname, fs_base); + setlocale(LC_ALL, ""); + fontset = XCreateFontSet(Xdisplay, fontname, &ml, &mc, &ds); + FREE(fontname); + if (mc) { + XFreeStringList(ml); + fontset = 0; + } } - } else { - fontname = MALLOC(strlen(font1) + sizeof(fs_base) + 1); - if (fontname) { - strcpy(fontname, font1); - strcat(fontname, fs_base); - } - } - if (fontname) { - setlocale(LC_ALL, ""); - fontset = XCreateFontSet(Xdisplay, fontname, &ml, &mc, &ds); - FREE(fontname); - if (mc) { - XFreeStringList(ml); - fontset = 0; - } - } - return fontset; + return fontset; } #if defined(USE_XIM) || defined(MULTI_CHARSET) @@ -1762,328 +1761,330 @@ create_fontset(const char *font1, const char *font2) static int xim_real_init(void); # ifdef USE_X11R6_XIM static void xim_destroy_cb(XIM xim, XPointer client_data, XPointer call_data); -static void xim_instantiate_cb(Display *display, XPointer client_data, XPointer call_data); +static void xim_instantiate_cb(Display * display, XPointer client_data, XPointer call_data); # endif #endif void init_locale(void) { - char *locale = NULL; + char *locale = NULL; - locale = setlocale(LC_ALL, ""); - XSetLocaleModifiers(""); - TermWin.fontset = (XFontSet) 0; - if ((locale == NULL) || (!XSupportsLocale())) { - print_warning("Locale not supported; defaulting to portable \"C\" locale.\n"); - locale = setlocale(LC_ALL, "C"); + locale = setlocale(LC_ALL, ""); XSetLocaleModifiers(""); - REQUIRE(locale); - REQUIRE(XSupportsLocale()); - } else { + TermWin.fontset = (XFontSet) 0; + if ((locale == NULL) || (!XSupportsLocale())) { + print_warning("Locale not supported; defaulting to portable \"C\" locale.\n"); + locale = setlocale(LC_ALL, "C"); + XSetLocaleModifiers(""); + REQUIRE(locale); + REQUIRE(XSupportsLocale()); + } else { #ifdef USE_XIM #ifdef MULTI_CHARSET - TermWin.fontset = create_fontset(etfonts[def_font_idx], etmfonts[def_font_idx]); + TermWin.fontset = create_fontset(etfonts[def_font_idx], etmfonts[def_font_idx]); #else - TermWin.fontset = create_fontset(etfonts[def_font_idx], "-misc-fixed-medium-r-semicondensed--13-*-75-*-c-*-iso10646-1"); + TermWin.fontset = create_fontset(etfonts[def_font_idx], "-misc-fixed-medium-r-semicondensed--13-*-75-*-c-*-iso10646-1"); #endif - if ((TermWin.fontset == (XFontSet) 0) || (xim_real_init() != -1)) { - return; - } - + if ((TermWin.fontset == (XFontSet) 0) || (xim_real_init() != -1)) { + return; + } # ifdef USE_X11R6_XIM - XRegisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL); + XRegisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL); # endif #endif - } + } } -#endif /* USE_XIM || MULTI_CHARSET */ +#endif /* USE_XIM || MULTI_CHARSET */ #ifdef USE_XIM static void xim_set_size(XRectangle * size) { - size->x = TermWin.internalBorder; - size->y = TermWin.internalBorder + bbar_calc_docked_height(BBAR_DOCKED_TOP); - size->width = Width2Pixel(TermWin.ncol); - size->height = Height2Pixel(TermWin.nrow); + size->x = TermWin.internalBorder; + size->y = TermWin.internalBorder + bbar_calc_docked_height(BBAR_DOCKED_TOP); + size->width = Width2Pixel(TermWin.ncol); + size->height = Height2Pixel(TermWin.nrow); } static void xim_set_color(unsigned long *fg, unsigned long *bg) { - *fg = PixColors[fgColor]; - *bg = PixColors[bgColor]; + *fg = PixColors[fgColor]; + *bg = PixColors[bgColor]; } static void xim_send_spot(void) { - XPoint spot; - static XPoint oldSpot = { -1, -1 }; - XVaNestedList preedit_attr; + XPoint spot; + static XPoint oldSpot = { -1, -1 }; + XVaNestedList preedit_attr; - if (xim_input_context == NULL) { - return; - } - - if (xim_input_style & XIMPreeditPosition) { - xim_get_position(&spot); - if (spot.x != oldSpot.x || spot.y != oldSpot.y) { - oldSpot.x = spot.x; - oldSpot.y = spot.y; - preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); - XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL); - XFree(preedit_attr); + if (xim_input_context == NULL) { + return; + } + + if (xim_input_style & XIMPreeditPosition) { + xim_get_position(&spot); + if (spot.x != oldSpot.x || spot.y != oldSpot.y) { + oldSpot.x = spot.x; + oldSpot.y = spot.y; + preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); + XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL); + XFree(preedit_attr); + } } - } } static void -xim_get_area(XRectangle *preedit_rect, XRectangle *status_rect, - XRectangle *needed_rect) +xim_get_area(XRectangle * preedit_rect, XRectangle * status_rect, XRectangle * needed_rect) { - preedit_rect->x = needed_rect->width + (scrollbar_is_visible() && !(Options & Opt_scrollbar_right) ? (scrollbar_trough_width()) : 0); - preedit_rect->y = Height2Pixel(TermWin.nrow - 1); + preedit_rect->x = needed_rect->width + (scrollbar_is_visible() && !(Options & Opt_scrollbar_right) ? (scrollbar_trough_width()) : 0); + preedit_rect->y = Height2Pixel(TermWin.nrow - 1); - preedit_rect->width = Width2Pixel(TermWin.ncol + 1) - needed_rect->width + (!(Options & Opt_scrollbar_right) ? (scrollbar_trough_width()) : 0); - preedit_rect->height = Height2Pixel(1); + preedit_rect->width = + Width2Pixel(TermWin.ncol + 1) - needed_rect->width + (!(Options & Opt_scrollbar_right) ? (scrollbar_trough_width()) : 0); + preedit_rect->height = Height2Pixel(1); - status_rect->x = (scrollbar_is_visible() && !(Options & Opt_scrollbar_right)) ? (scrollbar_trough_width()) : 0; - status_rect->y = Height2Pixel(TermWin.nrow - 1); + status_rect->x = (scrollbar_is_visible() && !(Options & Opt_scrollbar_right)) ? (scrollbar_trough_width()) : 0; + status_rect->y = Height2Pixel(TermWin.nrow - 1); - status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); - status_rect->height = Height2Pixel(1); + status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); + status_rect->height = Height2Pixel(1); } #ifdef USE_X11R6_XIM static void xim_destroy_cb(XIM xim, XPointer client_data, XPointer call_data) { - xim_input_context = NULL; - xim_input_method = NULL; - XRegisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL); - xim = NULL; - client_data = call_data = (XPointer) 0; + xim_input_context = NULL; + xim_input_method = NULL; + XRegisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL); + xim = NULL; + client_data = call_data = (XPointer) 0; } static void -xim_instantiate_cb(Display *display, XPointer client_data, XPointer call_data) +xim_instantiate_cb(Display * display, XPointer client_data, XPointer call_data) { - xim_real_init(); - if (xim_input_context) { - XUnregisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL); - } - display = NULL; - client_data = call_data = (XPointer) 0; + xim_real_init(); + if (xim_input_context) { + XUnregisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL); + } + display = NULL; + client_data = call_data = (XPointer) 0; } #endif static int xim_real_init(void) { - char *p, *s, buf[64], tmp[1024]; - char *end, *next_s; - XIMStyles *xim_styles = NULL; - int found; - XPoint spot; - XRectangle rect, status_rect, needed_rect; - unsigned long fg, bg; - XVaNestedList preedit_attr = NULL; - XVaNestedList status_attr = NULL; + char *p, *s, buf[64], tmp[1024]; + char *end, *next_s; + XIMStyles *xim_styles = NULL; + int found; + XPoint spot; + XRectangle rect, status_rect, needed_rect; + unsigned long fg, bg; + XVaNestedList preedit_attr = NULL; + XVaNestedList status_attr = NULL; - REQUIRE_RVAL(xim_input_context == NULL, -1); + REQUIRE_RVAL(xim_input_context == NULL, -1); - xim_input_style = 0; + xim_input_style = 0; - if (rs_input_method && *rs_input_method) { - strncpy(tmp, rs_input_method, sizeof(tmp) - 1); - for (s = tmp; *s; s = next_s + 1) { - for (; *s && isspace(*s); s++); - if (!*s) { - break; - } - for (end = s; (*end && (*end != ',')); end++); - for (next_s = end--; ((end >= s) && isspace(*end)); end--); - *(end + 1) = '\0'; - if (*s) { - snprintf(buf, sizeof(buf), "@im=%s", s); - if (((p = XSetLocaleModifiers(buf)) != NULL) && (*p) && ((xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL)) != NULL)) { - break; + if (rs_input_method && *rs_input_method) { + strncpy(tmp, rs_input_method, sizeof(tmp) - 1); + for (s = tmp; *s; s = next_s + 1) { + for (; *s && isspace(*s); s++); + if (!*s) { + break; + } + for (end = s; (*end && (*end != ',')); end++); + for (next_s = end--; ((end >= s) && isspace(*end)); end--); + *(end + 1) = '\0'; + if (*s) { + snprintf(buf, sizeof(buf), "@im=%s", s); + if (((p = XSetLocaleModifiers(buf)) != NULL) && (*p) && ((xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL)) != NULL)) { + break; + } + } + if (!*next_s) { + break; + } } - } - if (!*next_s) { - break; - } } - } - /* try with XMODIFIERS env. var. */ - if (xim_input_method == NULL && getenv("XMODIFIERS") && (p = XSetLocaleModifiers("")) != NULL && *p) { - xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL); - } + /* try with XMODIFIERS env. var. */ + if (xim_input_method == NULL && getenv("XMODIFIERS") && (p = XSetLocaleModifiers("")) != NULL && *p) { + xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL); + } - /* try with no modifiers base */ - if (xim_input_method == NULL && (p = XSetLocaleModifiers("@im=none")) != NULL && *p) { - xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL); - } + /* try with no modifiers base */ + if (xim_input_method == NULL && (p = XSetLocaleModifiers("@im=none")) != NULL && *p) { + xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL); + } - if (xim_input_method == NULL) { - xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL); - } - - if (xim_input_method == NULL) { - return -1; - } + if (xim_input_method == NULL) { + xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL); + } + if (xim_input_method == NULL) { + return -1; + } #ifdef USE_X11R6_XIM - { - XIMCallback destroy_cb; + { + XIMCallback destroy_cb; - destroy_cb.callback = xim_destroy_cb; - destroy_cb.client_data = NULL; - if (XSetIMValues(xim_input_method, XNDestroyCallback, &destroy_cb, NULL)) { - print_error("Could not set destroy callback to IM\n"); + destroy_cb.callback = xim_destroy_cb; + destroy_cb.client_data = NULL; + if (XSetIMValues(xim_input_method, XNDestroyCallback, &destroy_cb, NULL)) { + print_error("Could not set destroy callback to IM\n"); + } } - } #endif - if ((XGetIMValues(xim_input_method, XNQueryInputStyle, &xim_styles, NULL)) || (!xim_styles)) { - print_error("input method doesn't support any style\n"); - XCloseIM(xim_input_method); - return -1; - } - strncpy(tmp, (rs_preedit_type ? rs_preedit_type : "OverTheSpot,OffTheSpot,Root"), sizeof(tmp) - 1); - for (found = 0, s = tmp; *s && !found; s = next_s + 1) { - unsigned short i; - - for (; *s && isspace(*s); s++); - if (!*s) { - break; + if ((XGetIMValues(xim_input_method, XNQueryInputStyle, &xim_styles, NULL)) || (!xim_styles)) { + print_error("input method doesn't support any style\n"); + XCloseIM(xim_input_method); + return -1; } - for (end = s; (*end && (*end != ',')); end++); - for (next_s = end--; ((end >= s) && isspace(*end)); end--); - *(end + 1) = '\0'; + strncpy(tmp, (rs_preedit_type ? rs_preedit_type : "OverTheSpot,OffTheSpot,Root"), sizeof(tmp) - 1); + for (found = 0, s = tmp; *s && !found; s = next_s + 1) { + unsigned short i; - if (!strcmp(s, "OverTheSpot")) { - xim_input_style = (XIMPreeditPosition | XIMStatusNothing); - } else if (!strcmp(s, "OffTheSpot")) { - xim_input_style = (XIMPreeditArea | XIMStatusArea); - } else if (!strcmp(s, "Root")) { - xim_input_style = (XIMPreeditNothing | XIMStatusNothing); + for (; *s && isspace(*s); s++); + if (!*s) { + break; + } + for (end = s; (*end && (*end != ',')); end++); + for (next_s = end--; ((end >= s) && isspace(*end)); end--); + *(end + 1) = '\0'; + + if (!strcmp(s, "OverTheSpot")) { + xim_input_style = (XIMPreeditPosition | XIMStatusNothing); + } else if (!strcmp(s, "OffTheSpot")) { + xim_input_style = (XIMPreeditArea | XIMStatusArea); + } else if (!strcmp(s, "Root")) { + xim_input_style = (XIMPreeditNothing | XIMStatusNothing); + } + + for (i = 0; i < xim_styles->count_styles; i++) { + if (xim_input_style == xim_styles->supported_styles[i]) { + found = 1; + break; + } + } } + XFree(xim_styles); - for (i = 0; i < xim_styles->count_styles; i++) { - if (xim_input_style == xim_styles->supported_styles[i]) { - found = 1; - break; - } + if (found == 0) { + print_error("input method doesn't support my preedit type\n"); + XCloseIM(xim_input_method); + return -1; } - } - XFree(xim_styles); - - if (found == 0) { - print_error("input method doesn't support my preedit type\n"); - XCloseIM(xim_input_method); - return -1; - } - if ((xim_input_style != (XIMPreeditNothing | XIMStatusNothing)) - && (xim_input_style != (XIMPreeditArea | XIMStatusArea)) - && (xim_input_style != (XIMPreeditPosition | XIMStatusNothing))) { - print_error("This program does not support the preedit type\n"); - XCloseIM(xim_input_method); - return -1; - } - if (xim_input_style & XIMPreeditPosition) { - xim_set_size(&rect); - xim_get_position(&spot); - xim_set_color(&fg, &bg); - preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNSpotLocation, &spot, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, NULL); - } else if (xim_input_style & XIMPreeditArea) { - xim_set_color(&fg, &bg); - /* The necessary width of preedit area is unknown until create input context. */ - needed_rect.width = 0; - xim_get_area(&rect, &status_rect, &needed_rect); - preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, NULL); - status_attr = XVaCreateNestedList(0, XNArea, &status_rect, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, NULL); - } - xim_input_context = XCreateIC(xim_input_method, XNInputStyle, xim_input_style, XNClientWindow, TermWin.parent, XNFocusWindow, TermWin.parent, - preedit_attr ? XNPreeditAttributes : NULL, preedit_attr, status_attr ? XNStatusAttributes : NULL, status_attr, NULL); - if (preedit_attr) { - XFree(preedit_attr); - } - if (status_attr) { - XFree(status_attr); - } - if (xim_input_context == NULL) { - print_error("Failed to create input context\n"); - XCloseIM(xim_input_method); - return -1; - } - if (xim_input_style & XIMPreeditArea) - xim_set_status_position(); - return 0; + if ((xim_input_style != (XIMPreeditNothing | XIMStatusNothing)) + && (xim_input_style != (XIMPreeditArea | XIMStatusArea)) + && (xim_input_style != (XIMPreeditPosition | XIMStatusNothing))) { + print_error("This program does not support the preedit type\n"); + XCloseIM(xim_input_method); + return -1; + } + if (xim_input_style & XIMPreeditPosition) { + xim_set_size(&rect); + xim_get_position(&spot); + xim_set_color(&fg, &bg); + preedit_attr = + XVaCreateNestedList(0, XNArea, &rect, XNSpotLocation, &spot, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, + NULL); + } else if (xim_input_style & XIMPreeditArea) { + xim_set_color(&fg, &bg); + /* The necessary width of preedit area is unknown until create input context. */ + needed_rect.width = 0; + xim_get_area(&rect, &status_rect, &needed_rect); + preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, NULL); + status_attr = XVaCreateNestedList(0, XNArea, &status_rect, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, NULL); + } + xim_input_context = + XCreateIC(xim_input_method, XNInputStyle, xim_input_style, XNClientWindow, TermWin.parent, XNFocusWindow, TermWin.parent, + preedit_attr ? XNPreeditAttributes : NULL, preedit_attr, status_attr ? XNStatusAttributes : NULL, status_attr, NULL); + if (preedit_attr) { + XFree(preedit_attr); + } + if (status_attr) { + XFree(status_attr); + } + if (xim_input_context == NULL) { + print_error("Failed to create input context\n"); + XCloseIM(xim_input_method); + return -1; + } + if (xim_input_style & XIMPreeditArea) + xim_set_status_position(); + return 0; } void xim_set_status_position(void) { - XRectangle preedit_rect, status_rect, *needed_rect, rect; - XVaNestedList preedit_attr, status_attr; - XPoint spot; + XRectangle preedit_rect, status_rect, *needed_rect, rect; + XVaNestedList preedit_attr, status_attr; + XPoint spot; - REQUIRE(xim_input_context != NULL); + REQUIRE(xim_input_context != NULL); - if (xim_input_style & XIMPreeditPosition) { - xim_set_size(&rect); - xim_get_position(&spot); + if (xim_input_style & XIMPreeditPosition) { + xim_set_size(&rect); + xim_get_position(&spot); - preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNSpotLocation, &spot, NULL); - XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL); - XFree(preedit_attr); - } else if (xim_input_style & XIMPreeditArea) { - /* Getting the necessary width of preedit area */ - status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); - XGetICValues(xim_input_context, XNStatusAttributes, status_attr, NULL); - XFree(status_attr); + preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNSpotLocation, &spot, NULL); + XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL); + XFree(preedit_attr); + } else if (xim_input_style & XIMPreeditArea) { + /* Getting the necessary width of preedit area */ + status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); + XGetICValues(xim_input_context, XNStatusAttributes, status_attr, NULL); + XFree(status_attr); - xim_get_area(&preedit_rect, &status_rect, needed_rect); + xim_get_area(&preedit_rect, &status_rect, needed_rect); - preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); - status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); - XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL); - XFree(preedit_attr); - XFree(status_attr); - } + preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); + status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); + XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL); + XFree(preedit_attr); + XFree(status_attr); + } } -void xim_set_fontset(void) +void +xim_set_fontset(void) { - XVaNestedList preedit_attr = NULL; - XVaNestedList status_attr = NULL; + XVaNestedList preedit_attr = NULL; + XVaNestedList status_attr = NULL; - REQUIRE(xim_input_context != NULL); + REQUIRE(xim_input_context != NULL); - if (xim_input_style & XIMStatusArea) { - status_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL); - } - if (xim_input_style & (XIMPreeditArea | XIMPreeditPosition)) { - preedit_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL); - } + if (xim_input_style & XIMStatusArea) { + status_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL); + } + if (xim_input_style & (XIMPreeditArea | XIMPreeditPosition)) { + preedit_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL); + } - if (status_attr && preedit_attr) { - XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL); - } else if (preedit_attr) { - XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL); - } else if (status_attr) { - XSetICValues(xim_input_context, XNStatusAttributes, status_attr, NULL); - } + if (status_attr && preedit_attr) { + XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL); + } else if (preedit_attr) { + XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL); + } else if (status_attr) { + XSetICValues(xim_input_context, XNStatusAttributes, status_attr, NULL); + } - if (preedit_attr) { - XFree(preedit_attr); - } - if (status_attr) { - XFree(status_attr); - } + if (preedit_attr) { + XFree(preedit_attr); + } + if (status_attr) { + XFree(status_attr); + } } #endif /* USE_XIM */ @@ -2097,206 +2098,507 @@ int run_command(char **argv) { - ttymode_t tio; - int ptyfd; + ttymode_t tio; + int ptyfd; - /* Save and then give up any super-user privileges */ - privileges(IGNORE); +#ifdef NS_DEBUG + { + char **a = argv; + if (a) { + while (*a) { + puts(*a); + a++; + } + } + } +#endif - ptyfd = get_pty(); - if (ptyfd < 0) - return (-1); - AT_LEAST(num_fds, ((unsigned int) (ptyfd + 1))); + /* Save and then give up any super-user privileges */ + privileges(IGNORE); - /* store original tty status for restoration clean_exit() -- rgg 04/12/95 */ - lstat(ttydev, &ttyfd_stat); - D_CMD(("Original settings of %s are mode %o, uid %d, gid %d\n", ttydev, ttyfd_stat.st_mode, - ttyfd_stat.st_uid, ttyfd_stat.st_gid)); + ptyfd = get_pty(); + if (ptyfd < 0) + return (-1); + AT_LEAST(num_fds, ((unsigned int) (ptyfd + 1))); - /* install exit handler for cleanup */ + /* store original tty status for restoration clean_exit() -- rgg 04/12/95 */ + lstat(ttydev, &ttyfd_stat); + D_CMD(("Original settings of %s are mode %o, uid %d, gid %d\n", ttydev, ttyfd_stat.st_mode, ttyfd_stat.st_uid, ttyfd_stat.st_gid)); + + /* install exit handler for cleanup */ #ifdef HAVE_ATEXIT - atexit(clean_exit); + atexit(clean_exit); #else # if defined (__sun__) - on_exit(clean_exit, NULL); /* non-ANSI exit handler */ + on_exit(clean_exit, NULL); /* non-ANSI exit handler */ # else - print_error("no atexit(), UTMP entries can't be cleaned\n"); + print_error("no atexit(), UTMP entries can't be cleaned\n"); # endif #endif - /* - * get tty settings before fork() - * and make a reasonable guess at the value for BackSpace - */ - get_ttymode(&tio); - /* add Backspace value */ - SavedModes |= (PrivateModes & PrivMode_BackSpace); + /* + * get tty settings before fork() + * and make a reasonable guess at the value for BackSpace + */ + get_ttymode(&tio); + /* add Backspace value */ + SavedModes |= (PrivateModes & PrivMode_BackSpace); - /* add value for scrollbar */ - if (scrollbar_is_visible()) { - PrivateModes |= PrivMode_scrollbar; - SavedModes |= PrivMode_scrollbar; - } + /* add value for scrollbar */ + if (scrollbar_is_visible()) { + PrivateModes |= PrivMode_scrollbar; + SavedModes |= PrivMode_scrollbar; + } #if DEBUG >= DEBUG_TTYMODE && defined(HAVE_TERMIOS_H) - if (DEBUG_LEVEL >= DEBUG_TTYMODE) { - debug_ttymode(&tio); - } + if (DEBUG_LEVEL >= DEBUG_TTYMODE) { + debug_ttymode(&tio); + } #endif - D_CMD(("Forking\n")); - cmd_pid = fork(); - D_CMD(("After fork(), cmd_pid == %d\n", cmd_pid)); - if (cmd_pid < 0) { - print_error("fork(): %s\n", strerror(errno)); - return (-1); - } - if (cmd_pid == 0) { + D_CMD(("Forking\n")); + cmd_pid = fork(); + D_CMD(("After fork(), cmd_pid == %d\n", cmd_pid)); + if (cmd_pid < 0) { + print_error("fork(): %s\n", strerror(errno)); + return (-1); + } + if (cmd_pid == 0) { - /* Child process. Reset the signal handlers right away. */ - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGCHLD, SIG_DFL); - signal(SIGSEGV, SIG_DFL); - signal(SIGBUS, SIG_DFL); - signal(SIGABRT, SIG_DFL); - signal(SIGFPE, SIG_DFL); - signal(SIGILL, SIG_DFL); - signal(SIGSYS, SIG_DFL); - signal(SIGALRM, SIG_DFL); + /* Child process. Reset the signal handlers right away. */ + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + signal(SIGCHLD, SIG_DFL); + signal(SIGSEGV, SIG_DFL); + signal(SIGBUS, SIG_DFL); + signal(SIGABRT, SIG_DFL); + signal(SIGFPE, SIG_DFL); + signal(SIGILL, SIG_DFL); + signal(SIGSYS, SIG_DFL); + signal(SIGALRM, SIG_DFL); #ifdef SIGTSTP - signal(SIGTSTP, SIG_IGN); - signal(SIGTTIN, SIG_IGN); - signal(SIGTTOU, SIG_IGN); + signal(SIGTSTP, SIG_IGN); + signal(SIGTTIN, SIG_IGN); + signal(SIGTTOU, SIG_IGN); #endif #ifdef HAVE_UNSETENV - unsetenv("LINES"); - unsetenv("COLUMNS"); - unsetenv("TERMCAP"); + unsetenv("LINES"); + unsetenv("COLUMNS"); + unsetenv("TERMCAP"); #endif - get_tty(); - SET_TTYMODE(0, &tio); + get_tty(); + SET_TTYMODE(0, &tio); - /* become virtual console, fail silently */ - if (Options & Opt_console) { - int fd = 1; + /* become virtual console, fail silently */ + if (Options & Opt_console) { + int fd = 1; - privileges(INVOKE); + privileges(INVOKE); #ifdef SRIOCSREDIR - fd = open(CONSOLE, O_WRONLY); - if (fd < 0 || ioctl(fd, SRIOCSREDIR, 0) < 0) { - if (fd >= 0) - close(fd); - } + fd = open(CONSOLE, O_WRONLY); + if (fd < 0 || ioctl(fd, SRIOCSREDIR, 0) < 0) { + if (fd >= 0) + close(fd); + } #elif defined(TIOCCONS) - ioctl(0, TIOCCONS, &fd); + ioctl(0, TIOCCONS, &fd); #endif /* SRIOCSREDIR */ - privileges(REVERT); - } - tt_winsize(0); /* set window size */ + privileges(REVERT); + } + tt_winsize(0); /* set window size */ - /* Permanently revoke all privileges for the child process. - Root shells for everyone are tres uncool.... ;^) -- mej */ + /* Permanently revoke all privileges for the child process. + Root shells for everyone are tres uncool.... ;^) -- mej */ #ifdef _HPUX_SOURCE - setresuid(my_ruid, my_ruid, my_euid); - setresgid(my_rgid, my_rgid, my_egid); + setresuid(my_ruid, my_ruid, my_euid); + setresgid(my_rgid, my_rgid, my_egid); #else - /* No special treatment is needed for systems with saved uids/gids, - because the exec*() calls reset the saved uid/gid to the - effective uid/gid -- mej */ + /* No special treatment is needed for systems with saved uids/gids, + because the exec*() calls reset the saved uid/gid to the + effective uid/gid -- mej */ # ifndef __CYGWIN32__ - setregid(my_rgid, my_rgid); - setreuid(my_ruid, my_ruid); -# endif /* __CYGWIN32__ */ + setregid(my_rgid, my_rgid); + setreuid(my_ruid, my_ruid); +# endif /* __CYGWIN32__ */ #endif /* _HPUX_SOURCE */ - D_UTMP(("Child process reset\n")); - my_euid = my_ruid; - my_egid = my_rgid; + D_UTMP(("Child process reset\n")); + my_euid = my_ruid; + my_egid = my_rgid; - usleep(10); /* Attempt to force a context switch so that the parent runs before us. */ - D_CMD(("[%d] About to spawn shell\n", getpid())); - if (chdir(initial_dir)) { - print_warning("Unable to chdir to \"%s\" -- %s\n", initial_dir, strerror(errno)); - } - if (argv != NULL) { + usleep(10); /* Attempt to force a context switch so that the parent runs before us. */ + D_CMD(("[%d] About to spawn shell\n", getpid())); + if (chdir(initial_dir)) { + print_warning("Unable to chdir to \"%s\" -- %s\n", initial_dir, strerror(errno)); + } + if (argv != NULL) { #if DEBUG >= DEBUG_CMD - if (DEBUG_LEVEL >= DEBUG_CMD) { - int i; + if (DEBUG_LEVEL >= DEBUG_CMD) { + int i; - for (i = 0; argv[i]; i++) { - DPRINTF(("argv[%d] = \"%s\"\n", i, argv[i])); - } - } + for (i = 0; argv[i]; i++) { + DPRINTF(("argv[%d] = \"%s\"\n", i, argv[i])); + } + } #endif - D_CMD(("[%d] execvp(\"%s\", %8p) is next. I'm outta here!\n", getpid(), NONULL(argv[0]), argv)); - execvp(argv[0], argv); - print_error("execvp() failed, cannot execute \"%s\": %s\n", argv[0], strerror(errno)); - } else { + D_CMD(("[%d] execvp(\"%s\", %8p) is next. I'm outta here!\n", getpid(), NONULL(argv[0]), argv)); + execvp(argv[0], argv); + print_error("execvp() failed, cannot execute \"%s\": %s\n", argv[0], strerror(errno)); + } else { - const char *argv0, *shell; + const char *argv0, *shell; - if ((shell = getenv("SHELL")) == NULL || *shell == '\0') - shell = "/bin/sh"; + if ((shell = getenv("SHELL")) == NULL || *shell == '\0') + shell = "/bin/sh"; - argv0 = my_basename(shell); - if (Options & Opt_login_shell) { - char *p = MALLOC(strlen(argv0) + 2); + argv0 = my_basename(shell); + if (Options & Opt_login_shell) { + char *p = MALLOC(strlen(argv0) + 2); - p[0] = '-'; - strcpy(&p[1], argv0); - argv0 = p; - } - execlp(shell, argv0, NULL); - print_error("execlp() failed, cannot execute \"%s\": %s\n", shell, strerror(errno)); + p[0] = '-'; + strcpy(&p[1], argv0); + argv0 = p; + } + execlp(shell, argv0, NULL); + print_error("execlp() failed, cannot execute \"%s\": %s\n", shell, strerror(errno)); + } + sleep(3); /* Sleep to make sure fork() returns in the parent, and so user can read error message */ + exit(EXIT_FAILURE); } - sleep(3); /* Sleep to make sure fork() returns in the parent, and so user can read error message */ - exit(EXIT_FAILURE); - } #ifdef UTMP_SUPPORT - privileges(RESTORE); - if (Options & Opt_write_utmp) { - add_utmp_entry(ttydev, display_name, ptyfd); - } - privileges(IGNORE); + privileges(RESTORE); + if (Options & Opt_write_utmp) { + add_utmp_entry(ttydev, display_name, ptyfd); + } + privileges(IGNORE); #endif - D_CMD(("Returning ptyfd == %d\n", ptyfd)); - return (ptyfd); + D_CMD(("Returning ptyfd == %d\n", ptyfd)); + return (ptyfd); } + + +/***************************************************************************/ +/* callbacks */ +/*************/ + + + +#ifdef ESCREEN +int +set_scroll_x(void *xd, int x) +{ + printf("set_scroll_x: %d\n", x); + return 0; +} + +int +set_scroll_y(void *xd, int y) +{ + printf("set_scroll_y: %d\n", y); + return 0; +} + +int +set_scroll_w(void *xd, int w) +{ + printf("set_scroll_w: %d\n", w); + return 0; +} + +int +set_scroll_h(void *xd, int h) +{ + printf("set_scroll_h: %d\n", h); + return 0; +} + +int +redraw(void *xd) +{ + puts("redraw"); + return 0; +} + +int +redraw_xywh(void *xd, int x, int y, int w, int h) +{ + printf("redraw_xywh: %d,%d %dx%d\n", x, y, w, h); + return 0; +} + + + +/* redraw a button bar */ +void +redraw_buttons(buttonbar_t *bbar) +{ + bbar_calc_button_sizes(bbar); + bbar_calc_button_positions(bbar); + bbar_draw(bbar, IMAGE_STATE_CURRENT, MODE_MASK); +} + + + +/* add a new screen display to button bar. + if our user's configured a bbar, we'll add to that, + otherwise, we'll create one. */ +int +ins_disp(void *xd, int after, char *name) +{ + buttonbar_t *bbar = *((buttonbar_t **) xd); + button_t *button; + int state = 1; + char p[3] = "\x01x"; + +#ifdef NS_DEBUG + fprintf(stderr, "ins_disp: %s after %d...\n", name, after); +#endif + + if (!bbar) { + if (!(bbar = bbar_create())) { + fprintf(stderr, "ins_disp: failed to create button-bar...\n"); + return 0; + } else { + bbar_set_font(bbar, "-adobe-helvetica-medium-r-normal--10-100-75-75-p-56-iso8859-1"); + bbar_set_docked(bbar, BBAR_DOCKED_TOP); + } + state = 0; + } + + button = button_create(name); + p[1] = '0' + after + 1; + button_set_action(button, ACTION_ECHO, p); + if (!bbar->buttons || after < 0) { /* first button */ + button->next = bbar->buttons; + bbar->buttons = button; + } else { + button_t *b = bbar->buttons; + while (after-- > 0 && b->next) + b = b->next; + button->next = b->next; + b->next = button; + } + + bbar->current = button; + + *((buttonbar_t **) xd) = bbar; /* ugly, but it will remain here till + bbar_event_init_dispatcher() + takes a bbar parameter */ + + if (!state) { + bbar_init(bbar, TermWin.width); + bbar_add(bbar); + } + + redraw_buttons(bbar); + + if (!state) { + parent_resize(); + } + + return 0; +} + + + +/* delete n'th button + n index of the button (not screen, not data -- the button) */ +int +del_disp(void *xd, int n) +{ + buttonbar_t *bbar = *((buttonbar_t **) xd); + button_t *button, *b2; + int bi = n; +#ifdef NS_DEBUG_ + int c; + + for (c = 0, b2 = bbar->buttons; b2; c++, b2 = b2->next) + fprintf(stderr, "%02d: \"%s\"\n", c, b2->text); +#endif + + if (!bbar || !(button = bbar->buttons)) + return 0; + + b2 = button = bbar->buttons; + if (!n) { + bbar->buttons = bbar->buttons->next; + if (bbar->current = button) + bbar->current = bbar->buttons; + } else { + while (n-- > 0) { + b2 = button; + if (!(button = button->next)) { + fprintf(stderr, "cannot delete button %d: does not exist...\n", bi); + return -1; + } + } + b2->next = button->next; + if (bbar->current == button) + bbar->current = b2; + } + +#ifdef NS_DEBUG_ + fprintf(stderr, "deleting button %d (%s)...\n", bi, button->text); +#endif + + button->next = NULL; + button_free(button); + + redraw_buttons(bbar); + + *((buttonbar_t **) xd) = bbar; /* ugly */ + + return 0; +} + + + +/* update the button-representation of a screen-display. + xd + n the button's index (in the list of buttons) + flags the new flags for the display (or -1 to ignore) + name the new name for the display (or NULL) + <- error code */ +int +upd_disp(void *xd, int n, int flags, char *name) +{ + buttonbar_t *bbar = *((buttonbar_t **) xd); + button_t *button; + + if (!bbar || !(button = bbar->buttons)) + return 0; + + button = bbar->buttons; + while (n-- > 0 && button->next) + button = button->next; + + if (name && (!button->text || strcmp(name, button->text))) { + if (button->text) + free(button->text); + + if (!(button->text = strdup(name))) { + button->len = 0; + return -1; + } + + button->len = strlen(name); + } + + if (flags >= 0) + button->flags = flags; + + redraw_buttons(bbar); + + *((buttonbar_t **) xd) = bbar; /* ugly */ + + return 0; +} + + + +/* display a status line the screen program sent us */ +int +err_msg(void *xd, int err, char *msg) +{ +#ifdef NS_DEBUG + if (err != NS_SCREEN_ST_CLR) + printf("err_msg #%d: \"%s\"\n", err, msg); +#endif + return 0; +} + + + +/* send text to the application (normally "screen") in the terminal */ +int +inp_text(void *xd, int id, char *txt) +{ + tt_write(txt, strlen(txt)); + return 0; +} + + + +/* run a program (normally "screen") inside the terminal */ +int +exe_prg(void *xd, char **argv) +{ + return run_command(argv); +} + +#endif + + + /* init_command() */ void init_command(char **argv) { - /* Initialize the command connection. This should be called after - the X server connection is established. */ +#ifdef ESCREEN + int ns_err; + _ns_efuns *efuns; - /* Enable delete window protocol */ - XSetWMProtocols(Xdisplay, TermWin.parent, &(props[PROP_DELETE_WINDOW]), 1); + efuns = ns_new_efuns(); - init_locale(); + ns_register_ssx(efuns, set_scroll_x); + ns_register_ssy(efuns, set_scroll_y); + ns_register_ssw(efuns, set_scroll_w); + ns_register_ssh(efuns, set_scroll_h); + + ns_register_red(efuns, redraw); + ns_register_rda(efuns, redraw_xywh); + + ns_register_ins(efuns, ins_disp); + ns_register_del(efuns, del_disp); + ns_register_upd(efuns, upd_disp); + + ns_register_err(efuns, err_msg); + ns_register_exe(efuns, exe_prg); + + ns_register_txt(efuns, inp_text); +#endif + + /* Initialize the command connection. This should be called after + the X server connection is established. */ + + /* Enable delete window protocol */ + XSetWMProtocols(Xdisplay, TermWin.parent, &(props[PROP_DELETE_WINDOW]), 1); + + init_locale(); #ifdef META8_OPTION - meta_char = (Options & Opt_meta8 ? 0x80 : 033); + meta_char = (Options & Opt_meta8 ? 0x80 : 033); #endif #ifdef GREEK_SUPPORT - greek_init(); + greek_init(); #endif - Xfd = XConnectionNumber(Xdisplay); - D_CMD(("Xfd = %d\n", Xfd)); - cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; - AT_LEAST((int) num_fds, Xfd + 1); - if (pipe_fd >= 0) { - AT_LEAST((int) num_fds, pipe_fd + 1); - } + Xfd = XConnectionNumber(Xdisplay); + D_CMD(("Xfd = %d\n", Xfd)); + cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; + AT_LEAST((int) num_fds, Xfd + 1); + if (pipe_fd >= 0) { + AT_LEAST((int) num_fds, pipe_fd + 1); + } +#ifdef ESCREEN + cmd_fd = -1; - if ((cmd_fd = run_command(argv)) < 0) { - print_error("aborting\n"); - exit(EXIT_FAILURE); - } + if (!TermWin.screen_mode) + cmd_fd = run_command(argv); + else if ((TermWin.screen = ns_attach_by_URL(rs_url, &efuns, &ns_err, (void *) &buttonbar))) + cmd_fd = TermWin.screen->fd; +# undef ETERM_PREFIX +# undef ESCREEN_PREFIX + if (cmd_fd < 0) { +#else + if ((cmd_fd = run_command(argv)) < 0) { +#endif + print_error("aborting\n"); + exit(EXIT_FAILURE); + } } /* window resizing */ @@ -2307,26 +2609,27 @@ init_command(char **argv) void tt_winsize(int fd) { - struct winsize ws; + struct winsize ws; - if (fd < 0) return; + if (fd < 0) + return; - MEMSET(&ws, 0, sizeof(struct winsize)); + MEMSET(&ws, 0, sizeof(struct winsize)); - ws.ws_row = (unsigned short) TermWin.nrow; - ws.ws_col = (unsigned short) TermWin.ncol; + ws.ws_row = (unsigned short) TermWin.nrow; + ws.ws_col = (unsigned short) TermWin.ncol; #ifndef __CYGWIN32__ - ws.ws_xpixel = (unsigned short) TermWin.width; - ws.ws_ypixel = (unsigned short) TermWin.height; + ws.ws_xpixel = (unsigned short) TermWin.width; + ws.ws_ypixel = (unsigned short) TermWin.height; #endif - D_CMD(("%hdx%hd (%hdx%hd)\n", ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel)); - ioctl(fd, TIOCSWINSZ, &ws); + D_CMD(("%hdx%hd (%hdx%hd)\n", ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel)); + ioctl(fd, TIOCSWINSZ, &ws); } void tt_resize(void) { - tt_winsize(cmd_fd); + tt_winsize(cmd_fd); } /* attempt to `write' COUNT to the input buffer */ @@ -2334,40 +2637,40 @@ unsigned int cmd_write(const unsigned char *str, unsigned int count) { - int n; + int n; - n = (count - (cmdbuf_ptr - cmdbuf_base)); - /* need to insert more chars that space available in the front */ - if (n > 0) { - /* try and get more space from the end */ - unsigned char *src, *dst; + n = (count - (cmdbuf_ptr - cmdbuf_base)); + /* need to insert more chars that space available in the front */ + if (n > 0) { + /* try and get more space from the end */ + unsigned char *src, *dst; - dst = (cmdbuf_base + sizeof(cmdbuf_base) - 1); /* max pointer */ + dst = (cmdbuf_base + sizeof(cmdbuf_base) - 1); /* max pointer */ - if ((cmdbuf_ptr + n) > dst) - n = (dst - cmdbuf_ptr); /* max # chars to insert */ + if ((cmdbuf_ptr + n) > dst) + n = (dst - cmdbuf_ptr); /* max # chars to insert */ - if ((cmdbuf_endp + n) > dst) - cmdbuf_endp = (dst - n); /* truncate end if needed */ + if ((cmdbuf_endp + n) > dst) + cmdbuf_endp = (dst - n); /* truncate end if needed */ - /* equiv: memmove ((cmdbuf_ptr+n), cmdbuf_ptr, n); */ - src = cmdbuf_endp; - dst = src + n; - /* FIXME: anything special to avoid possible pointer wrap? */ - while (src >= cmdbuf_ptr) - *dst-- = *src--; + /* equiv: memmove ((cmdbuf_ptr+n), cmdbuf_ptr, n); */ + src = cmdbuf_endp; + dst = src + n; + /* FIXME: anything special to avoid possible pointer wrap? */ + while (src >= cmdbuf_ptr) + *dst-- = *src--; - /* done */ - cmdbuf_ptr += n; - cmdbuf_endp += n; - } - while (count-- && cmdbuf_ptr > cmdbuf_base) { - /* sneak one in */ - cmdbuf_ptr--; - *cmdbuf_ptr = str[count]; - } + /* done */ + cmdbuf_ptr += n; + cmdbuf_endp += n; + } + while (count-- && cmdbuf_ptr > cmdbuf_base) { + /* sneak one in */ + cmdbuf_ptr--; + *cmdbuf_ptr = str[count]; + } - return (0); + return (0); } #ifdef BACKGROUND_CYCLING_SUPPORT @@ -2375,46 +2678,46 @@ RETSIGTYPE check_pixmap_change(int sig) { - static time_t last_update = 0; - time_t now; - static unsigned long image_idx = 0; - void (*old_handler) (int); - static unsigned char in_cpc = 0; + static time_t last_update = 0; + time_t now; + static unsigned long image_idx = 0; + void (*old_handler) (int); + static unsigned char in_cpc = 0; - if (in_cpc) - SIG_RETURN(0); - in_cpc = 1; - D_PIXMAP(("check_pixmap_change(%d): rs_anim_delay == %lu seconds, last_update == %lu\n", sig, rs_anim_delay, last_update)); - if (!rs_anim_delay) - SIG_RETURN(0); - if (last_update == 0) { - last_update = time(NULL); - old_handler = signal(SIGALRM, check_pixmap_change); - alarm(rs_anim_delay); - in_cpc = 0; - SIG_RETURN(0); - } - now = time(NULL); - D_PIXMAP(("now %lu >= %lu (last_update %lu + rs_anim_delay %lu) ?\n", now, last_update + rs_anim_delay, last_update, rs_anim_delay)); - if (now >= last_update + rs_anim_delay || 1) { - D_PIXMAP(("Time to update pixmap. now == %lu\n", now)); - imlib_context_set_image(images[image_bg].current->iml->im); - imlib_free_image_and_decache(); - images[image_bg].current->iml->im = NULL; - xterm_seq(XTerm_Pixmap, rs_anim_pixmaps[image_idx++]); - last_update = now; - old_handler = signal(SIGALRM, check_pixmap_change); - alarm(rs_anim_delay); - if (rs_anim_pixmaps[image_idx] == NULL) { - image_idx = 0; + if (in_cpc) + SIG_RETURN(0); + in_cpc = 1; + D_PIXMAP(("check_pixmap_change(%d): rs_anim_delay == %lu seconds, last_update == %lu\n", sig, rs_anim_delay, last_update)); + if (!rs_anim_delay) + SIG_RETURN(0); + if (last_update == 0) { + last_update = time(NULL); + old_handler = signal(SIGALRM, check_pixmap_change); + alarm(rs_anim_delay); + in_cpc = 0; + SIG_RETURN(0); + } + now = time(NULL); + D_PIXMAP(("now %lu >= %lu (last_update %lu + rs_anim_delay %lu) ?\n", now, last_update + rs_anim_delay, last_update, rs_anim_delay)); + if (now >= last_update + rs_anim_delay || 1) { + D_PIXMAP(("Time to update pixmap. now == %lu\n", now)); + imlib_context_set_image(images[image_bg].current->iml->im); + imlib_free_image_and_decache(); + images[image_bg].current->iml->im = NULL; + xterm_seq(XTerm_Pixmap, rs_anim_pixmaps[image_idx++]); + last_update = now; + old_handler = signal(SIGALRM, check_pixmap_change); + alarm(rs_anim_delay); + if (rs_anim_pixmaps[image_idx] == NULL) { + image_idx = 0; + } + } + in_cpc = 0; + if (old_handler) { + SIG_RETURN((*old_handler) (sig)); + } else { + SIG_RETURN(sig); } - } - in_cpc = 0; - if (old_handler) { - SIG_RETURN((*old_handler) (sig)); - } else { - SIG_RETURN(sig); - } } #endif /* BACKGROUND_CYCLING_SUPPORT */ @@ -2427,190 +2730,193 @@ unsigned char cmd_getc(void) { #define TIMEOUT_USEC 2500 - static short refreshed = 0; - fd_set readfds; - int retval; - struct timeval value, *delay; + static short refreshed = 0; + fd_set readfds; + int retval; + struct timeval value, *delay; - /* If there has been a lot of new lines, then update the screen - * What the heck I'll cheat and only refresh less than every page-full. - * the number of pages between refreshes is refresh_limit, which - * is incremented here because we must be doing flat-out scrolling. - * - * refreshing should be correct for small scrolls, because of the - * time-out - */ - if (refresh_count >= (refresh_limit * (TermWin.nrow - 1))) { - D_CMD(("Refresh count %d >= limit %d * rows. (Refresh period %d.)\n", - refresh_count, refresh_limit, REFRESH_PERIOD)); - if (refresh_limit < REFRESH_PERIOD) - refresh_limit++; - refresh_count = 0; - refreshed = 1; + /* If there has been a lot of new lines, then update the screen + * What the heck I'll cheat and only refresh less than every page-full. + * the number of pages between refreshes is refresh_limit, which + * is incremented here because we must be doing flat-out scrolling. + * + * refreshing should be correct for small scrolls, because of the + * time-out + */ + if (refresh_count >= (refresh_limit * (TermWin.nrow - 1))) { + D_CMD(("Refresh count %d >= limit %d * rows. (Refresh period %d.)\n", refresh_count, refresh_limit, REFRESH_PERIOD)); + if (refresh_limit < REFRESH_PERIOD) + refresh_limit++; + refresh_count = 0; + refreshed = 1; #ifdef PROFILE - P_CALL(scr_refresh(refresh_type), "cmd_getc()->scr_refresh()"); + P_CALL(scr_refresh(refresh_type), "cmd_getc()->scr_refresh()"); #else - scr_refresh(refresh_type); + scr_refresh(refresh_type); +#endif + } +#ifdef ESCREEN + if (TermWin.screen_mode) + parse_screen_status_if_necessary(); #endif - } - /* characters already read in */ - if (CHARS_READ()) { - RETURN_CHAR(); - } - for (;;) { - v_doPending(); - while (XPending(Xdisplay)) { /* process pending X events */ + /* characters already read in */ + if (CHARS_READ()) { + RETURN_CHAR(); + } - XEvent ev; + for (;;) { + v_doPending(); + while (XPending(Xdisplay)) { /* process pending X events */ - refreshed = 0; - XNextEvent(Xdisplay, &ev); + XEvent ev; + + refreshed = 0; + XNextEvent(Xdisplay, &ev); #ifdef USE_XIM - if (xim_input_context != NULL) { - if (!XFilterEvent(&ev, ev.xkey.window)) { - event_dispatch(&ev); - } - } else + if (xim_input_context != NULL) { + if (!XFilterEvent(&ev, ev.xkey.window)) { + event_dispatch(&ev); + } + } else #endif - event_dispatch(&ev); + event_dispatch(&ev); - /* in case button actions pushed chars to cmdbuf */ - if (CHARS_READ()) { - RETURN_CHAR(); - } - } - if (paused == 1 && cmd_fd == -1) { - const char *done = " -- Task Finished, ESC to exit"; + /* in case button actions pushed chars to cmdbuf */ + if (CHARS_READ()) { + RETURN_CHAR(); + } + } + if (paused == 1 && cmd_fd == -1) { + const char *done = " -- Task Finished, ESC to exit"; - append_to_title(rs_finished_title ? rs_finished_title : done); - append_to_icon_name(rs_finished_title ? rs_finished_title : done); + append_to_title(rs_finished_title ? rs_finished_title : done); + append_to_icon_name(rs_finished_title ? rs_finished_title : done); - paused++; - - if (rs_finished_text) { - cmd_write((unsigned char *) rs_finished_text, strlen(rs_finished_text)); - } - } + paused++; + if (rs_finished_text) { + cmd_write((unsigned char *) rs_finished_text, strlen(rs_finished_text)); + } + } #ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - if (scrollbar_uparrow_is_pressed()) { - if (!scroll_arrow_delay-- && scr_page(UP, 1)) { - scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY; - refreshed = 0; - } - } else if (scrollbar_downarrow_is_pressed()) { - if (!scroll_arrow_delay-- && scr_page(DN, 1)) { - scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY; - refreshed = 0; - } - } + if (scrollbar_uparrow_is_pressed()) { + if (!scroll_arrow_delay-- && scr_page(UP, 1)) { + scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY; + refreshed = 0; + } + } else if (scrollbar_downarrow_is_pressed()) { + if (!scroll_arrow_delay-- && scr_page(DN, 1)) { + scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY; + refreshed = 0; + } + } #endif /* SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ - /* Nothing to do! */ - FD_ZERO(&readfds); - if (cmd_fd >= 0) { - FD_SET(cmd_fd, &readfds); - } - FD_SET(Xfd, &readfds); - if (pipe_fd >= 0) { - FD_SET(pipe_fd, &readfds); - } - value.tv_usec = TIMEOUT_USEC; - value.tv_sec = 0; + /* Nothing to do! */ + FD_ZERO(&readfds); + if (cmd_fd >= 0) { + FD_SET(cmd_fd, &readfds); + } + FD_SET(Xfd, &readfds); + if (pipe_fd >= 0) { + FD_SET(pipe_fd, &readfds); + } + value.tv_usec = TIMEOUT_USEC; + value.tv_sec = 0; - if (refreshed + if (refreshed #ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - && !(scrollbar_arrow_is_pressed()) + && !(scrollbar_arrow_is_pressed()) #endif - ) { - delay = NULL; - } else { - delay = &value; - } - retval = select(num_fds, &readfds, NULL, NULL, delay); - - if (retval < 0) { - if (cmd_fd >= 0 && FD_ISSET(cmd_fd, &readfds)) { - print_error("Error reading from tty -- %s\n", strerror(errno)); - cmd_fd = -1; - } - if (pipe_fd >= 0 && FD_ISSET(pipe_fd, &readfds)) { - print_error("Error reading from pipe -- %s\n", strerror(errno)); - pipe_fd = -1; - } - if (pipe_fd < 0 && cmd_fd < 0 && !paused) { - exit(errno); - } - } else if (retval == 0) { - refresh_count = 0; - refresh_limit = 1; - if (!refreshed) { - refreshed = 1; - D_CMD(("select() timed out, time to update the screen.\n")); - scr_refresh(refresh_type); - if (scrollbar_is_visible()) { - scrollbar_anchor_update_position(1); + ) { + delay = NULL; + } else { + delay = &value; } -#ifdef USE_XIM - xim_send_spot(); -#endif - } - } else { - /* We have something to read from. */ - if (cmd_fd >= 0 && FD_ISSET(cmd_fd, &readfds)) { - /* See if we can read from the application */ - register unsigned int count = CMD_BUF_SIZE; + retval = select(num_fds, &readfds, NULL, NULL, delay); - cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; - while (count) { - - register int n = read(cmd_fd, cmdbuf_endp, count); - - if (n <= 0) { - if (paused) { - cmd_fd = -1; + if (retval < 0) { + if (cmd_fd >= 0 && FD_ISSET(cmd_fd, &readfds)) { + print_error("Error reading from tty -- %s\n", strerror(errno)); + cmd_fd = -1; } - break; - } - cmdbuf_endp += n; - count -= n; - } - /* some characters read in */ - if (CHARS_BUFFERED()) { - RETURN_CHAR(); - } - } - if (pipe_fd >= 0 && FD_ISSET(pipe_fd, &readfds)) { - register unsigned int count = CMD_BUF_SIZE / 2; + if (pipe_fd >= 0 && FD_ISSET(pipe_fd, &readfds)) { + print_error("Error reading from pipe -- %s\n", strerror(errno)); + pipe_fd = -1; + } + if (pipe_fd < 0 && cmd_fd < 0 && !paused) { + exit(errno); + } + } else if (retval == 0) { + refresh_count = 0; + refresh_limit = 1; + if (!refreshed) { + refreshed = 1; + D_CMD(("select() timed out, time to update the screen.\n")); + scr_refresh(refresh_type); + if (scrollbar_is_visible()) { + scrollbar_anchor_update_position(1); + } +#ifdef USE_XIM + xim_send_spot(); +#endif + } + } else { + /* We have something to read from. */ + if (cmd_fd >= 0 && FD_ISSET(cmd_fd, &readfds)) { + /* See if we can read from the application */ + register unsigned int count = CMD_BUF_SIZE; - cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; - while (count) { + cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; + while (count) { - register int n = read(pipe_fd, cmdbuf_endp, count); + register int n = read(cmd_fd, cmdbuf_endp, count); - if (n <= 0) - break; - n = add_carriage_returns(cmdbuf_endp, n); - cmdbuf_endp += n; - count -= n; + if (n <= 0) { + if (paused) { + cmd_fd = -1; + } + break; + } + cmdbuf_endp += n; + count -= n; + } + /* some characters read in */ + if (CHARS_BUFFERED()) { + RETURN_CHAR(); + } + } + if (pipe_fd >= 0 && FD_ISSET(pipe_fd, &readfds)) { + register unsigned int count = CMD_BUF_SIZE / 2; + + cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; + while (count) { + + register int n = read(pipe_fd, cmdbuf_endp, count); + + if (n <= 0) + break; + n = add_carriage_returns(cmdbuf_endp, n); + cmdbuf_endp += n; + count -= n; + } + /* some characters read in */ + if (CHARS_BUFFERED()) { + RETURN_CHAR(); + } + } } - /* some characters read in */ - if (CHARS_BUFFERED()) { - RETURN_CHAR(); - } - } } - } - return (0); + return (0); } /* Put a character back in the buffer. Only use this once at a time. */ void cmd_ungetc(void) { - cmdbuf_ptr--; + cmdbuf_ptr--; } /* tt_write(), tt_printf() - output to command */ @@ -2621,17 +2927,17 @@ void tt_write(const unsigned char *buf, unsigned int count) { - v_writeBig(cmd_fd, (char *) buf, count); + v_writeBig(cmd_fd, (char *) buf, count); -#if 0 /* Fixes the bug that hung Eterm when pasting a lot of stuff */ - while (count > 0) { - int n = write(cmd_fd, buf, count); +#if 0 /* Fixes the bug that hung Eterm when pasting a lot of stuff */ + while (count > 0) { + int n = write(cmd_fd, buf, count); - if (n > 0) { - count -= n; - buf += n; + if (n > 0) { + count -= n; + buf += n; + } } - } #endif } @@ -2642,106 +2948,105 @@ tt_write(const unsigned char *buf, unsigned int count) void tt_printf(const unsigned char *fmt, ...) { - static unsigned char buf[256]; - va_list arg_ptr; + static unsigned char buf[256]; + va_list arg_ptr; - va_start(arg_ptr, fmt); - vsnprintf((char *) buf, sizeof(buf), (char *) fmt, arg_ptr); - va_end(arg_ptr); - tt_write(buf, strlen((char *) buf)); + va_start(arg_ptr, fmt); + vsnprintf((char *) buf, sizeof(buf), (char *) fmt, arg_ptr); + va_end(arg_ptr); + tt_write(buf, strlen((char *) buf)); } /* Read and process output from the application */ void main_loop(void) { - /* int ch; */ - register int ch; + /* int ch; */ + register int ch; - D_CMD(("PID %d\n", getpid())); - D_CMD(("Command buffer base == %8p, length %lu, end at %8p\n", cmdbuf_base, CMD_BUF_SIZE, - cmdbuf_base + CMD_BUF_SIZE - 1)); + D_CMD(("PID %d\n", getpid())); + D_CMD(("Command buffer base == %8p, length %lu, end at %8p\n", cmdbuf_base, CMD_BUF_SIZE, cmdbuf_base + CMD_BUF_SIZE - 1)); #ifdef BACKGROUND_CYCLING_SUPPORT - if (rs_anim_delay) { - check_pixmap_change(0); - } -#endif - do { - while ((ch = cmd_getc()) == 0); /* wait for something */ - if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') { - /* Read a text string from the input buffer */ - int nlines = 0; - - /* unsigned char * str; */ - register unsigned char *str; - - D_CMD(("Command buffer contains %d characters.\n", cmdbuf_endp - cmdbuf_ptr)); - D_VT(("\n%s\n\n", safe_print_string(cmdbuf_ptr - 1, cmdbuf_endp - cmdbuf_ptr + 1))); - - /* - * point to the start of the string, - * decrement first since already did get_com_char () - */ - str = --cmdbuf_ptr; - while (cmdbuf_ptr < cmdbuf_endp) { - - ch = *cmdbuf_ptr++; -#if DEBUG >= DEBUG_VT - if (DEBUG_LEVEL >= DEBUG_VT) { - if (ch < 32) { - D_VT(("\'%s\' (%d 0x%02x %03o)\n", get_ctrl_char_name(ch), ch, ch, ch)); - } else { - D_VT(("\'%c\' (%d 0x%02x %03o)\n", ch, ch, ch, ch)); - } - } -#endif - if (ch >= ' ' || ch == '\t' || ch == '\r') { - /* nothing */ - } else if (ch == '\n') { - nlines++; - if (++refresh_count >= (refresh_limit * (TermWin.nrow - 1))) - break; - } else { /* unprintable */ - cmdbuf_ptr--; - break; - } - } - D_SCREEN(("Adding %d lines (%d chars); str == %8p, cmdbuf_ptr == %8p, cmdbuf_endp == %8p\n", - nlines, cmdbuf_ptr - str, str, cmdbuf_ptr, cmdbuf_endp)); - scr_add_lines(str, nlines, (cmdbuf_ptr - str)); - } else { - switch (ch) { -# ifdef NO_ENQ_ANS - case 005: - break; -# else - case 005: /* ^E (ENQ) terminal status enquiry */ - tt_printf(VT100_ANS); - break; -# endif - case 007: /* ^G (BEL) */ - scr_bell(); - break; - case '\b': - scr_backspace(); - break; - case 013: /* ^K (VT) */ - case 014: /* ^L (FF) */ - scr_index(UP); - break; - case 016: /* ^N (SO) shift out (enter ACS mode) */ - scr_charset_choose(1); - break; - case 017: /* ^O (SI) shift in (leave ACS mode) */ - scr_charset_choose(0); - break; - case 033: - process_escape_seq(); - break; - } + if (rs_anim_delay) { + check_pixmap_change(0); } - } while (ch != EOF); +#endif + do { + while ((ch = cmd_getc()) == 0); /* wait for something */ + if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') { + /* Read a text string from the input buffer */ + int nlines = 0; + + /* unsigned char * str; */ + register unsigned char *str; + + D_CMD(("Command buffer contains %d characters.\n", cmdbuf_endp - cmdbuf_ptr)); + D_VT(("\n%s\n\n", safe_print_string(cmdbuf_ptr - 1, cmdbuf_endp - cmdbuf_ptr + 1))); + + /* + * point to the start of the string, + * decrement first since already did get_com_char () + */ + str = --cmdbuf_ptr; + while (cmdbuf_ptr < cmdbuf_endp) { + + ch = *cmdbuf_ptr++; +#if DEBUG >= DEBUG_VT + if (DEBUG_LEVEL >= DEBUG_VT) { + if (ch < 32) { + D_VT(("\'%s\' (%d 0x%02x %03o)\n", get_ctrl_char_name(ch), ch, ch, ch)); + } else { + D_VT(("\'%c\' (%d 0x%02x %03o)\n", ch, ch, ch, ch)); + } + } +#endif + if (ch >= ' ' || ch == '\t' || ch == '\r') { + /* nothing */ + } else if (ch == '\n') { + nlines++; + if (++refresh_count >= (refresh_limit * (TermWin.nrow - 1))) + break; + } else { /* unprintable */ + cmdbuf_ptr--; + break; + } + } + D_SCREEN(("Adding %d lines (%d chars); str == %8p, cmdbuf_ptr == %8p, cmdbuf_endp == %8p\n", + nlines, cmdbuf_ptr - str, str, cmdbuf_ptr, cmdbuf_endp)); + scr_add_lines(str, nlines, (cmdbuf_ptr - str)); + } else { + switch (ch) { +# ifdef NO_ENQ_ANS + case 005: + break; +# else + case 005: /* ^E (ENQ) terminal status enquiry */ + tt_printf(VT100_ANS); + break; +# endif + case 007: /* ^G (BEL) */ + scr_bell(); + break; + case '\b': + scr_backspace(); + break; + case 013: /* ^K (VT) */ + case 014: /* ^L (FF) */ + scr_index(UP); + break; + case 016: /* ^N (SO) shift out (enter ACS mode) */ + scr_charset_choose(1); + break; + case 017: /* ^O (SI) shift in (leave ACS mode) */ + scr_charset_choose(0); + break; + case 033: + process_escape_seq(); + break; + } + } + } while (ch != EOF); } /* output a burst of any pending data from a paste... */ @@ -2749,10 +3054,10 @@ int v_doPending(void) { - if (v_bufstr >= v_bufptr) - return (0); - v_writeBig(cmd_fd, NULL, 0); - return (1); + if (v_bufstr >= v_bufptr) + return (0); + v_writeBig(cmd_fd, NULL, 0); + return (1); } /* Write data to the pty as typed by the user, pasted with the mouse, @@ -2763,102 +3068,101 @@ void v_writeBig(int f, char *d, int len) { - int written; - int c = len; + int written; + int c = len; - if (v_bufstr == NULL && len > 0) { + if (v_bufstr == NULL && len > 0) { - v_buffer = MALLOC(len); - v_bufstr = v_buffer; - v_bufptr = v_buffer; - v_bufend = v_buffer + len; - } - /* - * Append to the block we already have. - * Always doing this simplifies the code, and - * isn't too bad, either. If this is a short - * block, it isn't too expensive, and if this is - * a long block, we won't be able to write it all - * anyway. - */ - - if (len > 0) { - if (v_bufend < v_bufptr + len) { /* we've run out of room */ - if (v_bufstr != v_buffer) { - /* there is unused space, move everything down */ - /* possibly overlapping bcopy here */ - - /* bcopy(v_bufstr, v_buffer, v_bufptr - v_bufstr); */ - memcpy(v_buffer, v_bufstr, v_bufptr - v_bufstr); - v_bufptr -= v_bufstr - v_buffer; - v_bufstr = v_buffer; - } - if (v_bufend < v_bufptr + len) { - /* still won't fit: get more space */ - /* Don't use XtRealloc because an error is not fatal. */ - int size = v_bufptr - v_buffer; /* save across realloc */ - - v_buffer = REALLOC(v_buffer, size + len); - if (v_buffer) { - v_bufstr = v_buffer; - v_bufptr = v_buffer + size; - v_bufend = v_bufptr + len; - } else { - /* no memory: ignore entire write request */ - print_error("cannot allocate buffer space\n"); - v_buffer = v_bufstr; /* restore clobbered pointer */ - c = 0; - } - } + v_buffer = MALLOC(len); + v_bufstr = v_buffer; + v_bufptr = v_buffer; + v_bufend = v_buffer + len; } - if (v_bufend >= v_bufptr + len) { /* new stuff will fit */ - memcpy(v_bufptr, d, len); /* bcopy(d, v_bufptr, len); */ - v_bufptr += len; - } - } - /* - * Write out as much of the buffer as we can. - * Be careful not to overflow the pty's input silo. - * We are conservative here and only write - * a small amount at a time. - * - * If we can't push all the data into the pty yet, we expect write - * to return a non-negative number less than the length requested - * (if some data written) or -1 and set errno to EAGAIN, - * EWOULDBLOCK, or EINTR (if no data written). - * - * (Not all systems do this, sigh, so the code is actually - * a little more forgiving.) - */ + /* + * Append to the block we already have. + * Always doing this simplifies the code, and + * isn't too bad, either. If this is a short + * block, it isn't too expensive, and if this is + * a long block, we won't be able to write it all + * anyway. + */ - if (v_bufptr > v_bufstr) { - written = write(f, v_bufstr, v_bufptr - v_bufstr <= MAX_PTY_WRITE ? - v_bufptr - v_bufstr : MAX_PTY_WRITE); - if (written < 0) { - written = 0; - } - D_TTY(("Wrote %d characters\n", written)); - v_bufstr += written; - if (v_bufstr >= v_bufptr) /* we wrote it all */ - v_bufstr = v_bufptr = v_buffer; - } - /* - * If we have lots of unused memory allocated, return it - */ - if (v_bufend - v_bufptr > 1024) { /* arbitrary hysteresis */ - /* save pointers across realloc */ - int start = v_bufstr - v_buffer; - int size = v_bufptr - v_buffer; - int allocsize = size ? size : 1; + if (len > 0) { + if (v_bufend < v_bufptr + len) { /* we've run out of room */ + if (v_bufstr != v_buffer) { + /* there is unused space, move everything down */ + /* possibly overlapping bcopy here */ - v_buffer = REALLOC(v_buffer, allocsize); - if (v_buffer) { - v_bufstr = v_buffer + start; - v_bufptr = v_buffer + size; - v_bufend = v_buffer + allocsize; - } else { - /* should we print a warning if couldn't return memory? */ - v_buffer = v_bufstr - start; /* restore clobbered pointer */ + /* bcopy(v_bufstr, v_buffer, v_bufptr - v_bufstr); */ + memcpy(v_buffer, v_bufstr, v_bufptr - v_bufstr); + v_bufptr -= v_bufstr - v_buffer; + v_bufstr = v_buffer; + } + if (v_bufend < v_bufptr + len) { + /* still won't fit: get more space */ + /* Don't use XtRealloc because an error is not fatal. */ + int size = v_bufptr - v_buffer; /* save across realloc */ + + v_buffer = REALLOC(v_buffer, size + len); + if (v_buffer) { + v_bufstr = v_buffer; + v_bufptr = v_buffer + size; + v_bufend = v_bufptr + len; + } else { + /* no memory: ignore entire write request */ + print_error("cannot allocate buffer space\n"); + v_buffer = v_bufstr; /* restore clobbered pointer */ + c = 0; + } + } + } + if (v_bufend >= v_bufptr + len) { /* new stuff will fit */ + memcpy(v_bufptr, d, len); /* bcopy(d, v_bufptr, len); */ + v_bufptr += len; + } + } + /* + * Write out as much of the buffer as we can. + * Be careful not to overflow the pty's input silo. + * We are conservative here and only write + * a small amount at a time. + * + * If we can't push all the data into the pty yet, we expect write + * to return a non-negative number less than the length requested + * (if some data written) or -1 and set errno to EAGAIN, + * EWOULDBLOCK, or EINTR (if no data written). + * + * (Not all systems do this, sigh, so the code is actually + * a little more forgiving.) + */ + + if (v_bufptr > v_bufstr) { + written = write(f, v_bufstr, v_bufptr - v_bufstr <= MAX_PTY_WRITE ? v_bufptr - v_bufstr : MAX_PTY_WRITE); + if (written < 0) { + written = 0; + } + D_TTY(("Wrote %d characters\n", written)); + v_bufstr += written; + if (v_bufstr >= v_bufptr) /* we wrote it all */ + v_bufstr = v_bufptr = v_buffer; + } + /* + * If we have lots of unused memory allocated, return it + */ + if (v_bufend - v_bufptr > 1024) { /* arbitrary hysteresis */ + /* save pointers across realloc */ + int start = v_bufstr - v_buffer; + int size = v_bufptr - v_buffer; + int allocsize = size ? size : 1; + + v_buffer = REALLOC(v_buffer, allocsize); + if (v_buffer) { + v_bufstr = v_buffer + start; + v_bufptr = v_buffer + size; + v_bufend = v_buffer + allocsize; + } else { + /* should we print a warning if couldn't return memory? */ + v_buffer = v_bufstr - start; /* restore clobbered pointer */ + } } - } } diff --git a/src/defaultfont.c b/src/defaultfont.c index b1d9d96..6ae8d6d 100644 --- a/src/defaultfont.c +++ b/src/defaultfont.c @@ -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 */ diff --git a/src/draw.c b/src/draw.c index 70d2edc..68a3ae9 100644 --- a/src/draw.c +++ b/src/draw.c @@ -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); } diff --git a/src/e.c b/src/e.c index 0d1d037..f4ee4ed 100644 --- a/src/e.c +++ b/src/e.c @@ -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); } diff --git a/src/encoding.c b/src/encoding.c index 29268fa..c57aae5 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -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; } diff --git a/src/events.c b/src/events.c index 8da62cd..73fa903 100644 --- a/src/events.c +++ b/src/events.c @@ -50,115 +50,115 @@ static const char cvs_ident[] = "$Id$"; unsigned char paused = 0; event_master_t event_master; event_dispatcher_data_t primary_data; -mouse_button_state_t button_state = -{0, 0, 0, 0, 0, 0, 0, 0}; +mouse_button_state_t button_state = { 0, 0, 0, 0, 0, 0, 0, 0 }; /********** The Event Handling Subsystem **********/ void event_init_subsystem(event_dispatcher_t primary_dispatcher, event_dispatcher_init_t init) { - /* Initialize the subsystem with the main event dispatcher */ - event_master.num_dispatchers = 1; - event_master.dispatchers = (event_dispatcher_t *) MALLOC(sizeof(event_dispatcher_t)); - event_master.dispatchers[0] = (event_dispatcher_t) primary_dispatcher; - (init) (); /* Initialize the dispatcher's data */ + /* Initialize the subsystem with the main event dispatcher */ + event_master.num_dispatchers = 1; + event_master.dispatchers = (event_dispatcher_t *) MALLOC(sizeof(event_dispatcher_t)); + event_master.dispatchers[0] = (event_dispatcher_t) primary_dispatcher; + (init) (); /* Initialize the dispatcher's data */ } void event_register_dispatcher(event_dispatcher_t func, event_dispatcher_init_t init) { - /* Add a secondary event dispatcher */ - event_master.num_dispatchers++; - event_master.dispatchers = (event_dispatcher_t *) REALLOC(event_master.dispatchers, sizeof(event_dispatcher_t) * event_master.num_dispatchers); - event_master.dispatchers[event_master.num_dispatchers - 1] = (event_dispatcher_t) func; - (init) (); /* Initialize the dispatcher's data */ + /* Add a secondary event dispatcher */ + event_master.num_dispatchers++; + event_master.dispatchers = + (event_dispatcher_t *) REALLOC(event_master.dispatchers, sizeof(event_dispatcher_t) * event_master.num_dispatchers); + event_master.dispatchers[event_master.num_dispatchers - 1] = (event_dispatcher_t) func; + (init) (); /* Initialize the dispatcher's data */ } void event_dispatch(event_t *event) { - register unsigned char i; - register unsigned char handled; + register unsigned char i; + register unsigned char handled; - /* No debugging stuff here. If you need it, take it out when done. This should be ultra-fast. -- mej */ - for (i = 0; i < event_master.num_dispatchers; i++) { - handled = (event_master.dispatchers[i]) (event); - if (handled) { - break; + /* No debugging stuff here. If you need it, take it out when done. This should be ultra-fast. -- mej */ + for (i = 0; i < event_master.num_dispatchers; i++) { + handled = (event_master.dispatchers[i]) (event); + if (handled) { + break; + } } - } } void event_data_add_mywin(event_dispatcher_data_t *data, Window win) { - ASSERT(data != NULL); + ASSERT(data != NULL); - if (data->num_my_windows > 0) { - (data->num_my_windows)++; - data->my_windows = (Window *) REALLOC(data->my_windows, sizeof(Window) * data->num_my_windows); - data->my_windows[data->num_my_windows - 1] = win; - } else { - data->num_my_windows = 1; - data->my_windows = (Window *) MALLOC(sizeof(Window)); - data->my_windows[0] = win; - } + if (data->num_my_windows > 0) { + (data->num_my_windows)++; + data->my_windows = (Window *) REALLOC(data->my_windows, sizeof(Window) * data->num_my_windows); + data->my_windows[data->num_my_windows - 1] = win; + } else { + data->num_my_windows = 1; + data->my_windows = (Window *) MALLOC(sizeof(Window)); + data->my_windows[0] = win; + } } void event_data_add_parent(event_dispatcher_data_t *data, Window win) { - ASSERT(data != NULL); + ASSERT(data != NULL); - if (data->num_my_parents > 0) { - (data->num_my_parents)++; - data->my_parents = (Window *) REALLOC(data->my_parents, sizeof(Window) * data->num_my_parents); - data->my_parents[data->num_my_parents - 1] = win; - } else { - data->num_my_parents = 1; - data->my_parents = (Window *) MALLOC(sizeof(Window)); - data->my_parents[0] = win; - } + if (data->num_my_parents > 0) { + (data->num_my_parents)++; + data->my_parents = (Window *) REALLOC(data->my_parents, sizeof(Window) * data->num_my_parents); + data->my_parents[data->num_my_parents - 1] = win; + } else { + data->num_my_parents = 1; + data->my_parents = (Window *) MALLOC(sizeof(Window)); + data->my_parents[0] = win; + } } void event_init_primary_dispatcher(void) { - MEMSET(&primary_data, 0, sizeof(event_dispatcher_data_t)); + MEMSET(&primary_data, 0, sizeof(event_dispatcher_data_t)); - EVENT_DATA_ADD_HANDLER(primary_data, KeyPress, handle_key_press); - EVENT_DATA_ADD_HANDLER(primary_data, PropertyNotify, handle_property_notify); - EVENT_DATA_ADD_HANDLER(primary_data, DestroyNotify, handle_destroy_notify); - EVENT_DATA_ADD_HANDLER(primary_data, ClientMessage, handle_client_message); - EVENT_DATA_ADD_HANDLER(primary_data, MappingNotify, handle_mapping_notify); - EVENT_DATA_ADD_HANDLER(primary_data, VisibilityNotify, handle_visibility_notify); - EVENT_DATA_ADD_HANDLER(primary_data, EnterNotify, handle_enter_notify); - EVENT_DATA_ADD_HANDLER(primary_data, LeaveNotify, handle_leave_notify); - EVENT_DATA_ADD_HANDLER(primary_data, FocusIn, handle_focus_in); - EVENT_DATA_ADD_HANDLER(primary_data, FocusOut, handle_focus_out); - EVENT_DATA_ADD_HANDLER(primary_data, ConfigureNotify, handle_configure_notify); - EVENT_DATA_ADD_HANDLER(primary_data, SelectionClear, handle_selection_clear); - EVENT_DATA_ADD_HANDLER(primary_data, SelectionNotify, handle_selection_notify); - EVENT_DATA_ADD_HANDLER(primary_data, SelectionRequest, handle_selection_request); - EVENT_DATA_ADD_HANDLER(primary_data, GraphicsExpose, handle_expose); - EVENT_DATA_ADD_HANDLER(primary_data, Expose, handle_expose); - EVENT_DATA_ADD_HANDLER(primary_data, ButtonPress, handle_button_press); - EVENT_DATA_ADD_HANDLER(primary_data, ButtonRelease, handle_button_release); - EVENT_DATA_ADD_HANDLER(primary_data, MotionNotify, handle_motion_notify); + EVENT_DATA_ADD_HANDLER(primary_data, KeyPress, handle_key_press); + EVENT_DATA_ADD_HANDLER(primary_data, PropertyNotify, handle_property_notify); + EVENT_DATA_ADD_HANDLER(primary_data, DestroyNotify, handle_destroy_notify); + EVENT_DATA_ADD_HANDLER(primary_data, ClientMessage, handle_client_message); + EVENT_DATA_ADD_HANDLER(primary_data, MappingNotify, handle_mapping_notify); + EVENT_DATA_ADD_HANDLER(primary_data, VisibilityNotify, handle_visibility_notify); + EVENT_DATA_ADD_HANDLER(primary_data, EnterNotify, handle_enter_notify); + EVENT_DATA_ADD_HANDLER(primary_data, LeaveNotify, handle_leave_notify); + EVENT_DATA_ADD_HANDLER(primary_data, FocusIn, handle_focus_in); + EVENT_DATA_ADD_HANDLER(primary_data, FocusOut, handle_focus_out); + EVENT_DATA_ADD_HANDLER(primary_data, ConfigureNotify, handle_configure_notify); + EVENT_DATA_ADD_HANDLER(primary_data, SelectionClear, handle_selection_clear); + EVENT_DATA_ADD_HANDLER(primary_data, SelectionNotify, handle_selection_notify); + EVENT_DATA_ADD_HANDLER(primary_data, SelectionRequest, handle_selection_request); + EVENT_DATA_ADD_HANDLER(primary_data, GraphicsExpose, handle_expose); + EVENT_DATA_ADD_HANDLER(primary_data, Expose, handle_expose); + EVENT_DATA_ADD_HANDLER(primary_data, ButtonPress, handle_button_press); + EVENT_DATA_ADD_HANDLER(primary_data, ButtonRelease, handle_button_release); + EVENT_DATA_ADD_HANDLER(primary_data, MotionNotify, handle_motion_notify); - event_data_add_mywin(&primary_data, TermWin.parent); - event_data_add_mywin(&primary_data, TermWin.vt); + event_data_add_mywin(&primary_data, TermWin.parent); + event_data_add_mywin(&primary_data, TermWin.vt); #ifdef PIXMAP_SUPPORT - if (desktop_window != None) { - event_data_add_parent(&primary_data, desktop_window); - } + if (desktop_window != None) { + event_data_add_parent(&primary_data, desktop_window); + } #endif } @@ -166,692 +166,701 @@ unsigned char event_win_is_mywin(register event_dispatcher_data_t *data, Window win) { - register unsigned short i; + register unsigned short i; - ASSERT(data != NULL); + ASSERT(data != NULL); - for (i = 0; i < data->num_my_windows; i++) { - if (data->my_windows[i] == win) { - return 1; + for (i = 0; i < data->num_my_windows; i++) { + if (data->my_windows[i] == win) { + return 1; + } } - } - return 0; + return 0; } unsigned char event_win_is_parent(register event_dispatcher_data_t *data, Window win) { - register unsigned short i; + register unsigned short i; - ASSERT(data != NULL); + ASSERT(data != NULL); - for (i = 0; i < data->num_my_parents; i++) { - if (data->my_parents[i] == win) { - return 1; + for (i = 0; i < data->num_my_parents; i++) { + if (data->my_parents[i] == win) { + return 1; + } } - } - return 0; + return 0; } unsigned char handle_key_press(event_t *ev) { #ifdef COUNT_X_EVENTS - static unsigned long keypress_cnt = 0; + static unsigned long keypress_cnt = 0; #endif - PROF_INIT(handle_key_press); - D_EVENTS(("handle_key_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + PROF_INIT(handle_key_press); + D_EVENTS(("handle_key_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - COUNT_EVENT(keypress_cnt); - if (!(Options & Opt_no_input)) { - lookup_key(ev); - } - PROF_DONE(handle_key_press); - PROF_TIME(handle_key_press); - return 1; + COUNT_EVENT(keypress_cnt); + if (!(Options & Opt_no_input)) { + lookup_key(ev); + } + PROF_DONE(handle_key_press); + PROF_TIME(handle_key_press); + return 1; } unsigned char handle_property_notify(event_t *ev) { - D_EVENTS(("handle_property_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_property_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); #ifdef PIXMAP_OFFSET - if (background_is_trans()) { - Window win; - Pixmap pmap; + if (background_is_trans()) { + Window win; + Pixmap pmap; - if ((ev->xany.window == TermWin.parent) || (ev->xany.window == Xroot)) { - D_EVENTS(("On %s. prop (_WIN_WORKSPACE) == 0x%08x, ev->xproperty.atom == 0x%08x\n", - ((ev->xany.window == Xroot) ? "the root window" : "TermWin.parent"), - (int) props[PROP_DESKTOP], (int) ev->xproperty.atom)); - if (ev->xproperty.atom == props[PROP_DESKTOP]) { - win = get_desktop_window(); - if (win == (Window) 1) { - /* The desktop window is unchanged. Ignore this event. */ - return 1; + if ((ev->xany.window == TermWin.parent) || (ev->xany.window == Xroot)) { + D_EVENTS(("On %s. prop (_WIN_WORKSPACE) == 0x%08x, ev->xproperty.atom == 0x%08x\n", + ((ev->xany.window == Xroot) ? "the root window" : "TermWin.parent"), + (int) props[PROP_DESKTOP], (int) ev->xproperty.atom)); + if (ev->xproperty.atom == props[PROP_DESKTOP]) { + win = get_desktop_window(); + if (win == (Window) 1) { + /* The desktop window is unchanged. Ignore this event. */ + return 1; + } + /* The desktop window has changed somehow. */ + if (desktop_window == None) { + free_desktop_pixmap(); + FOREACH_IMAGE(if (image_mode_is(idx, MODE_TRANS)) { + image_set_mode(idx, MODE_IMAGE); image_allow_mode(idx, ALLOW_IMAGE);} + ); + return 1; + } + pmap = get_desktop_pixmap(); + if (pmap == (Pixmap) 1) { + /* Pixmap is unchanged */ + return 1; + } + redraw_images_by_mode(MODE_TRANS | MODE_VIEWPORT); + return 1; + } } - /* The desktop window has changed somehow. */ - if (desktop_window == None) { - free_desktop_pixmap(); - FOREACH_IMAGE(if (image_mode_is(idx, MODE_TRANS)) {image_set_mode(idx, MODE_IMAGE); image_allow_mode(idx, ALLOW_IMAGE);}); - return 1; + if (ev->xany.window == desktop_window) { + D_EVENTS(("On desktop_window [0x%08x]. prop (_XROOTPMAP_ID) == %d, ev->xproperty.atom == %d\n", + (int) desktop_window, (int) props[PROP_TRANS_PIXMAP], (int) ev->xproperty.atom)); + if (ev->xproperty.atom == props[PROP_TRANS_PIXMAP]) { + pmap = get_desktop_pixmap(); + if (pmap == (Pixmap) 1) { + /* Pixmap is unchanged */ + return 1; + } + redraw_images_by_mode(MODE_TRANS | MODE_VIEWPORT); + return 1; + } } - pmap = get_desktop_pixmap(); - if (pmap == (Pixmap) 1) { - /* Pixmap is unchanged */ - return 1; - } - redraw_images_by_mode(MODE_TRANS | MODE_VIEWPORT); - return 1; - } } - if (ev->xany.window == desktop_window) { - D_EVENTS(("On desktop_window [0x%08x]. prop (_XROOTPMAP_ID) == %d, ev->xproperty.atom == %d\n", - (int) desktop_window, (int) props[PROP_TRANS_PIXMAP], (int) ev->xproperty.atom)); - if (ev->xproperty.atom == props[PROP_TRANS_PIXMAP]) { - pmap = get_desktop_pixmap(); - if (pmap == (Pixmap) 1) { - /* Pixmap is unchanged */ - return 1; - } - redraw_images_by_mode(MODE_TRANS | MODE_VIEWPORT); - return 1; - } - } - } #endif - if ((ev->xany.window == Xroot) && (image_mode_any(MODE_AUTO))) { - D_EVENTS(("On the root window. prop (ENLIGHTENMENT_COMMS) == %d, ev->xproperty.atom == %d\n", (int) props[PROP_ENL_COMMS], (int) ev->xproperty.atom)); - if ((props[PROP_ENL_COMMS] != None) && (ev->xproperty.atom == props[PROP_ENL_COMMS])) { - if ((enl_ipc_get_win()) != None) { + if ((ev->xany.window == Xroot) && (image_mode_any(MODE_AUTO))) { + D_EVENTS(("On the root window. prop (ENLIGHTENMENT_COMMS) == %d, ev->xproperty.atom == %d\n", (int) props[PROP_ENL_COMMS], + (int) ev->xproperty.atom)); + if ((props[PROP_ENL_COMMS] != None) && (ev->xproperty.atom == props[PROP_ENL_COMMS])) { + if ((enl_ipc_get_win()) != None) { #ifdef PIXMAP_SUPPORT - redraw_images_by_mode(MODE_AUTO); + redraw_images_by_mode(MODE_AUTO); #endif - } + } + } } - } - if (ev->xany.window == TermWin.vt) { - D_EVENTS(("PropertyNotify on term window for atom %d, state %d. Selection atoms are %d and %d.\n", ev->xproperty.atom, - ev->xproperty.state, props[PROP_SELECTION_DEST], props[PROP_SELECTION_INCR])); - if (ev->xproperty.atom == props[PROP_SELECTION_DEST] && ev->xproperty.state == PropertyNewValue) { - D_SELECT(("Fetching next part of incremental selection.\n")); - selection_fetch(ev->xproperty.window, ev->xproperty.atom, True); + if (ev->xany.window == TermWin.vt) { + D_EVENTS(("PropertyNotify on term window for atom %d, state %d. Selection atoms are %d and %d.\n", ev->xproperty.atom, + ev->xproperty.state, props[PROP_SELECTION_DEST], props[PROP_SELECTION_INCR])); + if (ev->xproperty.atom == props[PROP_SELECTION_DEST] && ev->xproperty.state == PropertyNewValue) { + D_SELECT(("Fetching next part of incremental selection.\n")); + selection_fetch(ev->xproperty.window, ev->xproperty.atom, True); + } } - } - return 1; + return 1; } unsigned char handle_destroy_notify(event_t *ev) { - D_EVENTS(("handle_destroy_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_destroy_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - if (ev->xdestroywindow.window == ipc_win) { - D_EVENTS((" -> IPC window 0x%08x changed/destroyed. Clearing ipc_win.\n", ipc_win)); - XSelectInput(Xdisplay, ipc_win, None); - ipc_win = None; - (void) check_image_ipc(1); - } - return 1; + if (ev->xdestroywindow.window == ipc_win) { + D_EVENTS((" -> IPC window 0x%08x changed/destroyed. Clearing ipc_win.\n", ipc_win)); + XSelectInput(Xdisplay, ipc_win, None); + ipc_win = None; + (void) check_image_ipc(1); + } + return 1; } unsigned char handle_client_message(event_t *ev) { - D_EVENTS(("handle_client_message(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_client_message(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if (ev->xclient.format == 32 && ev->xclient.data.l[0] == (signed) props[PROP_DELETE_WINDOW]) - exit(EXIT_SUCCESS); - if (ev->xclient.format == 8 && ev->xclient.message_type == props[PROP_ENL_MSG]) { - char buff[13]; - unsigned char i; + if (ev->xclient.format == 32 && ev->xclient.data.l[0] == (signed) props[PROP_DELETE_WINDOW]) + exit(EXIT_SUCCESS); + if (ev->xclient.format == 8 && ev->xclient.message_type == props[PROP_ENL_MSG]) { + char buff[13]; + unsigned char i; - for (i = 0; i < 12; i++) { - buff[i] = ev->xclient.data.b[i + 8]; + for (i = 0; i < 12; i++) { + buff[i] = ev->xclient.data.b[i + 8]; + } + buff[12] = 0; + D_ENL(("Discarding unexpected Enlightenment IPC message: \"%s\"\n", buff)); + return 1; } - buff[12] = 0; - D_ENL(("Discarding unexpected Enlightenment IPC message: \"%s\"\n", buff)); - return 1; - } #ifdef OFFIX_DND - /* OffiX Dnd (drag 'n' drop) protocol */ - if (ev->xclient.message_type == props[PROP_DND_PROTOCOL] - && ((ev->xclient.data.l[0] == DndFile) || (ev->xclient.data.l[0] == DndDir) || (ev->xclient.data.l[0] == DndLink))) { - /* Get DnD data */ - Atom ActualType; - int ActualFormat; - unsigned char *data; - unsigned long Size, RemainingBytes; + /* OffiX Dnd (drag 'n' drop) protocol */ + if (ev->xclient.message_type == props[PROP_DND_PROTOCOL] + && ((ev->xclient.data.l[0] == DndFile) || (ev->xclient.data.l[0] == DndDir) || (ev->xclient.data.l[0] == DndLink))) { + /* Get DnD data */ + Atom ActualType; + int ActualFormat; + unsigned char *data; + unsigned long Size, RemainingBytes; - XGetWindowProperty(Xdisplay, Xroot, props[PROP_DND_SELECTION], 0L, 1000000L, False, AnyPropertyType, &ActualType, &ActualFormat, &Size, &RemainingBytes, &data); - if (data != NULL) { - XChangeProperty(Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, PropModeReplace, data, strlen(data)); - selection_paste(Xroot, XA_CUT_BUFFER0, True); - XSetInputFocus(Xdisplay, Xroot, RevertToNone, CurrentTime); - XFree(data); + XGetWindowProperty(Xdisplay, Xroot, props[PROP_DND_SELECTION], 0L, 1000000L, False, AnyPropertyType, &ActualType, &ActualFormat, + &Size, &RemainingBytes, &data); + if (data != NULL) { + XChangeProperty(Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, PropModeReplace, data, strlen(data)); + selection_paste(Xroot, XA_CUT_BUFFER0, True); + XSetInputFocus(Xdisplay, Xroot, RevertToNone, CurrentTime); + XFree(data); + } + return 1; } - return 1; - } #endif /* OFFIX_DND */ - if ((XInternAtom(Xdisplay, "_FVWM_COLORTUNER", True) == ev->xclient.message_type) && ev->xclient.send_event) { - if (ev->xclient.data.l[0] >= 0 && ev->xclient.data.l[0] <= 31) { - PixColors[(int) ev->xclient.data.l[0]] = ev->xclient.data.l[1]; + if ((XInternAtom(Xdisplay, "_FVWM_COLORTUNER", True) == ev->xclient.message_type) && ev->xclient.send_event) { + if (ev->xclient.data.l[0] >= 0 && ev->xclient.data.l[0] <= 31) { + PixColors[(int) ev->xclient.data.l[0]] = ev->xclient.data.l[1]; - if ((int) ev->xclient.data.l[0] == bgColor) { - XFocusChangeEvent fev; - event_t *pfev; + if ((int) ev->xclient.data.l[0] == bgColor) { + XFocusChangeEvent fev; + event_t *pfev; - fev.type = FocusIn; - fev.send_event = 1; - fev.display = Xdisplay; - fev.window = ev->xany.window; - pfev = (event_t *) &fev; - handle_focus_in(pfev); - redraw_image(image_bg); - } - scr_touch(); - scr_refresh(refresh_type); + fev.type = FocusIn; + fev.send_event = 1; + fev.display = Xdisplay; + fev.window = ev->xany.window; + pfev = (event_t *) & fev; + handle_focus_in(pfev); + redraw_image(image_bg); + } + scr_touch(); + scr_refresh(refresh_type); + } + return 1; } return 1; - } - return 1; } unsigned char handle_mapping_notify(event_t *ev) { - D_EVENTS(("handle_mapping_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_mapping_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - XRefreshKeyboardMapping(&(ev->xmapping)); - get_modifiers(); - return 1; + XRefreshKeyboardMapping(&(ev->xmapping)); + get_modifiers(); + return 1; } unsigned char handle_visibility_notify(event_t *ev) { - D_EVENTS(("handle_visibility_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_visibility_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - switch (ev->xvisibility.state) { - case VisibilityUnobscured: - D_X11(("Window completely visible. Using FAST_REFRESH.\n")); - refresh_type = FAST_REFRESH; - break; - case VisibilityPartiallyObscured: - D_X11(("Window partially hidden. Using SLOW_REFRESH.\n")); - refresh_type = SLOW_REFRESH; - break; - default: - D_X11(("Window completely hidden. Using NO_REFRESH.\n")); - refresh_type = NO_REFRESH; - break; - } - return 1; + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + switch (ev->xvisibility.state) { + case VisibilityUnobscured: + D_X11(("Window completely visible. Using FAST_REFRESH.\n")); + refresh_type = FAST_REFRESH; + break; + case VisibilityPartiallyObscured: + D_X11(("Window partially hidden. Using SLOW_REFRESH.\n")); + refresh_type = SLOW_REFRESH; + break; + default: + D_X11(("Window completely hidden. Using NO_REFRESH.\n")); + refresh_type = NO_REFRESH; + break; + } + return 1; } unsigned char handle_enter_notify(event_t *ev) { - D_EVENTS(("handle_enter_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_enter_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if (ev->xany.window == TermWin.vt) { - if (images[image_bg].norm != images[image_bg].selected) { - images[image_bg].current = images[image_bg].selected; - redraw_image(image_bg); + if (ev->xany.window == TermWin.vt) { + if (images[image_bg].norm != images[image_bg].selected) { + images[image_bg].current = images[image_bg].selected; + redraw_image(image_bg); + } + return 1; } - return 1; - } - return 0; + return 0; } unsigned char handle_leave_notify(event_t *ev) { - D_EVENTS(("handle_leave_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_leave_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if (ev->xany.window == TermWin.vt) { - if (images[image_bg].norm != images[image_bg].selected) { - images[image_bg].current = images[image_bg].norm; - redraw_image(image_bg); + if (ev->xany.window == TermWin.vt) { + if (images[image_bg].norm != images[image_bg].selected) { + images[image_bg].current = images[image_bg].norm; + redraw_image(image_bg); + } + return 1; } - return 1; - } - return 0; + return 0; } unsigned char handle_focus_in(event_t *ev) { - D_EVENTS(("handle_focus_in(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_focus_in(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if (!TermWin.focus) { - Window unused_root, child; - int unused_root_x, unused_root_y; - unsigned int unused_mask; + if (!TermWin.focus) { + Window unused_root, child; + int unused_root_x, unused_root_y; + unsigned int unused_mask; - TermWin.focus = 1; - XQueryPointer(Xdisplay, TermWin.parent, &unused_root, &child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y), &unused_mask); - if (child == TermWin.vt) { - if (images[image_bg].current != images[image_bg].selected) { - images[image_bg].current = images[image_bg].selected; - redraw_image(image_bg); - } - } else { - if (images[image_bg].current != images[image_bg].norm) { - images[image_bg].current = images[image_bg].norm; - redraw_image(image_bg); - } - } - if (Options & Opt_scrollbar_popup) { - map_scrollbar(Options & Opt_scrollbar); - } else { - scrollbar_set_focus(TermWin.focus); - scrollbar_draw(IMAGE_STATE_NORMAL, MODE_SOLID); - } - bbar_draw_all(IMAGE_STATE_NORMAL, MODE_SOLID); + TermWin.focus = 1; + XQueryPointer(Xdisplay, TermWin.parent, &unused_root, &child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y), + &unused_mask); + if (child == TermWin.vt) { + if (images[image_bg].current != images[image_bg].selected) { + images[image_bg].current = images[image_bg].selected; + redraw_image(image_bg); + } + } else { + if (images[image_bg].current != images[image_bg].norm) { + images[image_bg].current = images[image_bg].norm; + redraw_image(image_bg); + } + } + if (Options & Opt_scrollbar_popup) { + map_scrollbar(Options & Opt_scrollbar); + } else { + scrollbar_set_focus(TermWin.focus); + scrollbar_draw(IMAGE_STATE_NORMAL, MODE_SOLID); + } + bbar_draw_all(IMAGE_STATE_NORMAL, MODE_SOLID); #ifdef USE_XIM - if (xim_input_context != NULL) - XSetICFocus(xim_input_context); + if (xim_input_context != NULL) + XSetICFocus(xim_input_context); #endif - } - return 1; + } + return 1; } unsigned char handle_focus_out(event_t *ev) { - D_EVENTS(("handle_focus_out(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_focus_out(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if (TermWin.focus) { - TermWin.focus = 0; - if (images[image_bg].current != images[image_bg].disabled) { - images[image_bg].current = images[image_bg].disabled; - redraw_image(image_bg); - } - if (Options & Opt_scrollbar_popup) { - map_scrollbar(0); - } else { - scrollbar_set_focus(TermWin.focus); - scrollbar_draw(IMAGE_STATE_DISABLED, MODE_SOLID); - } - bbar_draw_all(IMAGE_STATE_DISABLED, MODE_SOLID); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + if (TermWin.focus) { + TermWin.focus = 0; + if (images[image_bg].current != images[image_bg].disabled) { + images[image_bg].current = images[image_bg].disabled; + redraw_image(image_bg); + } + if (Options & Opt_scrollbar_popup) { + map_scrollbar(0); + } else { + scrollbar_set_focus(TermWin.focus); + scrollbar_draw(IMAGE_STATE_DISABLED, MODE_SOLID); + } + bbar_draw_all(IMAGE_STATE_DISABLED, MODE_SOLID); #ifdef USE_XIM - if (xim_input_context != NULL) - XUnsetICFocus(xim_input_context); + if (xim_input_context != NULL) + XUnsetICFocus(xim_input_context); #endif - } - return 1; + } + return 1; } unsigned char handle_configure_notify(event_t *ev) { - D_EVENTS(("handle_configure_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_configure_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, ConfigureNotify, ev)) { - D_EVENTS(("New event: Window 0x%08x, %dx%d at %d, %d\n", ev->xany.window, ev->xconfigure.width, - ev->xconfigure.height, ev->xconfigure.x, ev->xconfigure.y)); - } - if (ev->xany.window == TermWin.parent) { - int x = ev->xconfigure.x, y = ev->xconfigure.y; - unsigned int width = ev->xconfigure.width, height = ev->xconfigure.height; - - D_EVENTS((" -> TermWin.parent is %ldx%ld at (%d, %d). Internal cache data shows %dx%d at (%hd, %hd). send_event is %d\n", - width, height, x, y, szHint.width, szHint.height, TermWin.x, TermWin.y, ev->xconfigure.send_event)); - /* If the font change count is non-zero, this event is telling us we resized ourselves. */ - if (font_chg > 0) { - font_chg--; + while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, ConfigureNotify, ev)) { + D_EVENTS(("New event: Window 0x%08x, %dx%d at %d, %d\n", ev->xany.window, ev->xconfigure.width, + ev->xconfigure.height, ev->xconfigure.x, ev->xconfigure.y)); } - if ((width != (unsigned int) szHint.width) || (height != (unsigned int) szHint.height)) { - /* We were resized externally. Handle the resize. */ - D_EVENTS((" -> External resize detected.\n")); - handle_resize(width, height); + if (ev->xany.window == TermWin.parent) { + int x = ev->xconfigure.x, y = ev->xconfigure.y; + unsigned int width = ev->xconfigure.width, height = ev->xconfigure.height; + + D_EVENTS((" -> TermWin.parent is %ldx%ld at (%d, %d). Internal cache data shows %dx%d at (%hd, %hd). send_event is %d\n", + width, height, x, y, szHint.width, szHint.height, TermWin.x, TermWin.y, ev->xconfigure.send_event)); + /* If the font change count is non-zero, this event is telling us we resized ourselves. */ + if (font_chg > 0) { + font_chg--; + } + if ((width != (unsigned int) szHint.width) || (height != (unsigned int) szHint.height)) { + /* We were resized externally. Handle the resize. */ + D_EVENTS((" -> External resize detected.\n")); + handle_resize(width, height); #ifdef USE_XIM - xim_set_status_position(); + xim_set_status_position(); #endif - /* A resize requires the additional handling of a move */ - if (ev->xconfigure.send_event) { - handle_move(x, y); - } - } else if (((x != TermWin.x) || (y != TermWin.y)) && (ev->xconfigure.send_event)) { - /* There was an external move, but no resize. Handle the move. */ - D_EVENTS((" -> External move detected.\n")); - handle_move(x, y); - } else { - D_EVENTS((" -> Bogus ConfigureNotify detected, ignoring.\n")); + /* A resize requires the additional handling of a move */ + if (ev->xconfigure.send_event) { + handle_move(x, y); + } + } else if (((x != TermWin.x) || (y != TermWin.y)) && (ev->xconfigure.send_event)) { + /* There was an external move, but no resize. Handle the move. */ + D_EVENTS((" -> External move detected.\n")); + handle_move(x, y); + } else { + D_EVENTS((" -> Bogus ConfigureNotify detected, ignoring.\n")); + } } - } - return 1; + return 1; } unsigned char handle_selection_clear(event_t *ev) { - D_EVENTS(("handle_selection_clear(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_selection_clear(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - selection_clear(); - return 1; + selection_clear(); + return 1; } unsigned char handle_selection_notify(event_t *ev) { - D_EVENTS(("handle_selection_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_selection_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - selection_fetch(ev->xselection.requestor, ev->xselection.property, True); - return 1; + selection_fetch(ev->xselection.requestor, ev->xselection.property, True); + return 1; } unsigned char handle_selection_request(event_t *ev) { - D_EVENTS(("handle_selection_request(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_selection_request(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - selection_send(&(ev->xselectionrequest)); - return 1; + selection_send(&(ev->xselectionrequest)); + return 1; } unsigned char handle_expose(event_t *ev) { - PROF_INIT(handle_expose); - D_EVENTS(("handle_expose(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + PROF_INIT(handle_expose); + D_EVENTS(("handle_expose(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if (ev->xany.window == TermWin.vt + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + if (ev->xany.window == TermWin.vt #ifdef PIXMAP_SUPPORT - && buffer_pixmap == None + && buffer_pixmap == None #endif - ) { - if (refresh_type == NO_REFRESH) { - refresh_type = FAST_REFRESH; + ) { + if (refresh_type == NO_REFRESH) { + refresh_type = FAST_REFRESH; + } + scr_expose(ev->xexpose.x, ev->xexpose.y, ev->xexpose.width, ev->xexpose.height); + } else { + + XEvent unused_xevent; + + while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, Expose, &unused_xevent)); + while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, GraphicsExpose, &unused_xevent)); } - scr_expose(ev->xexpose.x, ev->xexpose.y, ev->xexpose.width, ev->xexpose.height); - } else { - - XEvent unused_xevent; - - while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, Expose, &unused_xevent)); - while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, GraphicsExpose, &unused_xevent)); - } - PROF_DONE(handle_expose); - PROF_TIME(handle_expose); - return 1; + PROF_DONE(handle_expose); + PROF_TIME(handle_expose); + return 1; } unsigned char handle_button_press(event_t *ev) { - D_EVENTS(("handle_button_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_button_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if (action_dispatch(ev, 0)) { - button_state.ignore_release = 1; - return 1; - } - - button_state.bypass_keystate = (ev->xbutton.state & (Mod1Mask | ShiftMask)); - button_state.report_mode = (button_state.bypass_keystate ? 0 : ((PrivateModes & PrivMode_mouse_report) ? 1 : 0)); - - if (ev->xany.window == TermWin.vt) { - if (ev->xbutton.subwindow == None) { - if (button_state.report_mode) { - if (PrivateModes & PrivMode_MouseX10) { - /* no state info allowed */ - ev->xbutton.state = 0; - } -#ifdef MOUSE_REPORT_DOUBLECLICK - if (ev->xbutton.button == Button1) { - if (ev->xbutton.time - button_state.button_press < MULTICLICK_TIME) - button_state.clicks++; - else - button_state.clicks = 1; - } -#else - button_state.clicks = 1; -#endif /* MOUSE_REPORT_DOUBLECLICK */ - mouse_report(&(ev->xbutton)); - } else { - switch (ev->xbutton.button) { - case Button1: - if ((button_state.last_button_press == 1) && (ev->xbutton.time - button_state.button_press < MULTICLICK_TIME)) { - button_state.clicks++; - } else { - button_state.clicks = 1; - } - selection_click(button_state.clicks, ev->xbutton.x, ev->xbutton.y); - button_state.last_button_press = 1; - break; - - case Button3: - if ((button_state.last_button_press == 3) && (ev->xbutton.time - button_state.button_press < MULTICLICK_TIME)) { - selection_rotate(ev->xbutton.x, ev->xbutton.y); - } else { - selection_extend(ev->xbutton.x, ev->xbutton.y, 1); - } - button_state.last_button_press = 3; - break; -#ifdef MOUSEWHEEL - /* This section activates the following bindings: - * - * Mousewheel Up -- Scroll up 1 page - * Ctrl + Mousewheel Up -- Scroll up 5 pages - * Shift + Mousewheel Up -- Scroll up 1 line - * Alt + Mousewheel Up -- Send PgUp to tty - * Alt + Ctrl + Mousewheel Up -- Send 5 PgUp's to tty - * Alt + Shift + Mousewheel Up -- Send Up Arrow to tty - * - * Mousewheel Down -- Scroll down 1 page - * Ctrl + Mousewheel Down -- Scroll down 5 pages - * Shift + Mousewheel Down -- Scroll down 1 line - * Alt + Mousewheel Down -- Send PgDn to tty - * Alt + Ctrl + Mousewheel Down -- Send 5 PgDn's to tty - * Alt + Shift + Mousewheel Down -- Send Down Arrow to tty - * - * Note that the number of lines which constitute a "page" is equal to the number - * of text rows in the terminal window. The context lines are subtracted out *after* - * the conversion is done. In other words, scrolling 5 pages means scrolling - * (5 * LINES_PER_PAGE) - CONTEXT_LINES - * _not_ - * (LINES_PER_PAGE - CONTEXT_LINES) * 5 - * - * This is also true for the scroll() function in script.c. - */ - case Button4: - if (action_check_modifiers(MOD_CTRL, ev->xbutton.state)) { - scr_page(UP, (TermWin.nrow * 5) - CONTEXT_LINES); - } else if (action_check_modifiers(MOD_SHIFT, ev->xbutton.state)) { - scr_page(UP, 1); - } else if (action_check_modifiers(MOD_ALT, ev->xbutton.state)) { - tt_write("\033[5~", 4); - } else if (action_check_modifiers((MOD_ALT | MOD_SHIFT), ev->xbutton.state)) { - tt_write("\033[A", 3); - } else if (action_check_modifiers((MOD_ALT | MOD_CTRL), ev->xbutton.state)) { - tt_write("\033[5~\033[5~\033[5~\033[5~\033[5~", 20); - } else { - scr_page(UP, TermWin.nrow - CONTEXT_LINES); - } - button_state.last_button_press = 4; - break; - case Button5: - if (action_check_modifiers(MOD_CTRL, ev->xbutton.state)) { - scr_page(DN, (TermWin.nrow * 5) - CONTEXT_LINES); - } else if (action_check_modifiers(MOD_SHIFT, ev->xbutton.state)) { - scr_page(DN, 1); - } else if (action_check_modifiers(MOD_ALT, ev->xbutton.state)) { - tt_write("\033[6~", 4); - } else if (action_check_modifiers((MOD_ALT | MOD_SHIFT), ev->xbutton.state)) { - tt_write("\033[B", 3); - } else if (action_check_modifiers((MOD_ALT | MOD_CTRL), ev->xbutton.state)) { - tt_write("\033[6~\033[6~\033[6~\033[6~\033[6~", 20); - } else { - scr_page(DN, TermWin.nrow - CONTEXT_LINES); - } - button_state.last_button_press = 5; - break; -#endif - default: break; - } - } - button_state.button_press = ev->xbutton.time; - return (1); + if (action_dispatch(ev, 0)) { + button_state.ignore_release = 1; + return 1; } - } - return 0; + + button_state.bypass_keystate = (ev->xbutton.state & (Mod1Mask | ShiftMask)); + button_state.report_mode = (button_state.bypass_keystate ? 0 : ((PrivateModes & PrivMode_mouse_report) ? 1 : 0)); + + if (ev->xany.window == TermWin.vt) { + if (ev->xbutton.subwindow == None) { + if (button_state.report_mode) { + if (PrivateModes & PrivMode_MouseX10) { + /* no state info allowed */ + ev->xbutton.state = 0; + } +#ifdef MOUSE_REPORT_DOUBLECLICK + if (ev->xbutton.button == Button1) { + if (ev->xbutton.time - button_state.button_press < MULTICLICK_TIME) + button_state.clicks++; + else + button_state.clicks = 1; + } +#else + button_state.clicks = 1; +#endif /* MOUSE_REPORT_DOUBLECLICK */ + mouse_report(&(ev->xbutton)); + } else { + switch (ev->xbutton.button) { + case Button1: + if ((button_state.last_button_press == 1) && (ev->xbutton.time - button_state.button_press < MULTICLICK_TIME)) { + button_state.clicks++; + } else { + button_state.clicks = 1; + } + selection_click(button_state.clicks, ev->xbutton.x, ev->xbutton.y); + button_state.last_button_press = 1; + break; + + case Button3: + if ((button_state.last_button_press == 3) && (ev->xbutton.time - button_state.button_press < MULTICLICK_TIME)) { + selection_rotate(ev->xbutton.x, ev->xbutton.y); + } else { + selection_extend(ev->xbutton.x, ev->xbutton.y, 1); + } + button_state.last_button_press = 3; + break; +#ifdef MOUSEWHEEL + /* This section activates the following bindings: + * + * Mousewheel Up -- Scroll up 1 page + * Ctrl + Mousewheel Up -- Scroll up 5 pages + * Shift + Mousewheel Up -- Scroll up 1 line + * Alt + Mousewheel Up -- Send PgUp to tty + * Alt + Ctrl + Mousewheel Up -- Send 5 PgUp's to tty + * Alt + Shift + Mousewheel Up -- Send Up Arrow to tty + * + * Mousewheel Down -- Scroll down 1 page + * Ctrl + Mousewheel Down -- Scroll down 5 pages + * Shift + Mousewheel Down -- Scroll down 1 line + * Alt + Mousewheel Down -- Send PgDn to tty + * Alt + Ctrl + Mousewheel Down -- Send 5 PgDn's to tty + * Alt + Shift + Mousewheel Down -- Send Down Arrow to tty + * + * Note that the number of lines which constitute a "page" is equal to the number + * of text rows in the terminal window. The context lines are subtracted out *after* + * the conversion is done. In other words, scrolling 5 pages means scrolling + * (5 * LINES_PER_PAGE) - CONTEXT_LINES + * _not_ + * (LINES_PER_PAGE - CONTEXT_LINES) * 5 + * + * This is also true for the scroll() function in script.c. + */ + case Button4: + if (action_check_modifiers(MOD_CTRL, ev->xbutton.state)) { + scr_page(UP, (TermWin.nrow * 5) - CONTEXT_LINES); + } else if (action_check_modifiers(MOD_SHIFT, ev->xbutton.state)) { + scr_page(UP, 1); + } else if (action_check_modifiers(MOD_ALT, ev->xbutton.state)) { + tt_write("\033[5~", 4); + } else if (action_check_modifiers((MOD_ALT | MOD_SHIFT), ev->xbutton.state)) { + tt_write("\033[A", 3); + } else if (action_check_modifiers((MOD_ALT | MOD_CTRL), ev->xbutton.state)) { + tt_write("\033[5~\033[5~\033[5~\033[5~\033[5~", 20); + } else { + scr_page(UP, TermWin.nrow - CONTEXT_LINES); + } + button_state.last_button_press = 4; + break; + case Button5: + if (action_check_modifiers(MOD_CTRL, ev->xbutton.state)) { + scr_page(DN, (TermWin.nrow * 5) - CONTEXT_LINES); + } else if (action_check_modifiers(MOD_SHIFT, ev->xbutton.state)) { + scr_page(DN, 1); + } else if (action_check_modifiers(MOD_ALT, ev->xbutton.state)) { + tt_write("\033[6~", 4); + } else if (action_check_modifiers((MOD_ALT | MOD_SHIFT), ev->xbutton.state)) { + tt_write("\033[B", 3); + } else if (action_check_modifiers((MOD_ALT | MOD_CTRL), ev->xbutton.state)) { + tt_write("\033[6~\033[6~\033[6~\033[6~\033[6~", 20); + } else { + scr_page(DN, TermWin.nrow - CONTEXT_LINES); + } + button_state.last_button_press = 5; + break; +#endif + default: + break; + } + } + button_state.button_press = ev->xbutton.time; + return (1); + } + } + return 0; } unsigned char handle_button_release(event_t *ev) { - D_EVENTS(("handle_button_release(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("handle_button_release(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - if (button_state.ignore_release == 1) { - button_state.ignore_release = 0; - return 0; - } - - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - button_state.mouse_offset = 0; - button_state.report_mode = (button_state.bypass_keystate ? 0 : ((PrivateModes & PrivMode_mouse_report) ? 1 : 0)); - - if (ev->xany.window == TermWin.vt) { - if (ev->xbutton.subwindow == None) { - if (button_state.report_mode) { - switch (PrivateModes & PrivMode_mouse_report) { - case PrivMode_MouseX10: - break; - - case PrivMode_MouseX11: - ev->xbutton.state = button_state.bypass_keystate; - ev->xbutton.button = AnyButton; - mouse_report(&(ev->xbutton)); - break; - } - return (1); - } - /* - * dumb hack to compensate for the failure of click-and-drag - * when overriding mouse reporting - */ - if ((PrivateModes & PrivMode_mouse_report) && (button_state.bypass_keystate) && (ev->xbutton.button == Button1) && (clickOnce())) { - selection_extend(ev->xbutton.x, ev->xbutton.y, 0); - } - switch (ev->xbutton.button) { - case Button1: - case Button3: - selection_make(ev->xbutton.time); - break; - - case Button2: - selection_paste(XA_PRIMARY); - break; - default: break; - } + if (button_state.ignore_release == 1) { + button_state.ignore_release = 0; + return 0; } - } - return 0; + + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + button_state.mouse_offset = 0; + button_state.report_mode = (button_state.bypass_keystate ? 0 : ((PrivateModes & PrivMode_mouse_report) ? 1 : 0)); + + if (ev->xany.window == TermWin.vt) { + if (ev->xbutton.subwindow == None) { + if (button_state.report_mode) { + switch (PrivateModes & PrivMode_mouse_report) { + case PrivMode_MouseX10: + break; + + case PrivMode_MouseX11: + ev->xbutton.state = button_state.bypass_keystate; + ev->xbutton.button = AnyButton; + mouse_report(&(ev->xbutton)); + break; + } + return (1); + } + /* + * dumb hack to compensate for the failure of click-and-drag + * when overriding mouse reporting + */ + if ((PrivateModes & PrivMode_mouse_report) && (button_state.bypass_keystate) && (ev->xbutton.button == Button1) + && (clickOnce())) { + selection_extend(ev->xbutton.x, ev->xbutton.y, 0); + } + switch (ev->xbutton.button) { + case Button1: + case Button3: + selection_make(ev->xbutton.time); + break; + + case Button2: + selection_paste(XA_PRIMARY); + break; + default: + break; + } + } + } + return 0; } unsigned char handle_motion_notify(event_t *ev) { #ifdef COUNT_X_EVENTS - static unsigned long motion_cnt = 0; + static unsigned long motion_cnt = 0; #endif - PROF_INIT(handle_motion_notify); - D_EVENTS(("handle_motion_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + PROF_INIT(handle_motion_notify); + D_EVENTS(("handle_motion_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - COUNT_EVENT(motion_cnt); + COUNT_EVENT(motion_cnt); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if ((PrivateModes & PrivMode_mouse_report) && !(button_state.bypass_keystate)) - return 1; + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + if ((PrivateModes & PrivMode_mouse_report) && !(button_state.bypass_keystate)) + return 1; - if (ev->xany.window == TermWin.vt) { - if (ev->xbutton.state & (Button1Mask | Button3Mask)) { - Window unused_root, unused_child; - int unused_root_x, unused_root_y; - unsigned int unused_mask; + if (ev->xany.window == TermWin.vt) { + if (ev->xbutton.state & (Button1Mask | Button3Mask)) { + Window unused_root, unused_child; + int unused_root_x, unused_root_y; + unsigned int unused_mask; - while (XCheckTypedWindowEvent(Xdisplay, TermWin.vt, MotionNotify, ev)); - XQueryPointer(Xdisplay, TermWin.vt, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y), &unused_mask); + while (XCheckTypedWindowEvent(Xdisplay, TermWin.vt, MotionNotify, ev)); + XQueryPointer(Xdisplay, TermWin.vt, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), + &(ev->xbutton.y), &unused_mask); #ifdef MOUSE_THRESHOLD - /* deal with a `jumpy' mouse */ - if ((ev->xmotion.time - button_state.button_press) > MOUSE_THRESHOLD) + /* deal with a `jumpy' mouse */ + if ((ev->xmotion.time - button_state.button_press) > MOUSE_THRESHOLD) #endif - selection_extend((ev->xbutton.x), (ev->xbutton.y), (ev->xbutton.state & Button3Mask)); + selection_extend((ev->xbutton.x), (ev->xbutton.y), (ev->xbutton.state & Button3Mask)); + } + PROF_DONE(handle_motion_notify); + PROF_TIME(handle_motion_notify); + return 1; } PROF_DONE(handle_motion_notify); PROF_TIME(handle_motion_notify); return 1; - } - PROF_DONE(handle_motion_notify); - PROF_TIME(handle_motion_notify); - return 1; } unsigned char process_x_event(event_t *ev) { #ifdef COUNT_X_EVENTS - static unsigned long event_cnt = 0; + static unsigned long event_cnt = 0; #endif - COUNT_EVENT(event_cnt); + COUNT_EVENT(event_cnt); #if 0 - D_EVENTS(("process_x_event(ev [%8p] %s on window 0x%08x)\n", ev, event_type_to_name(ev->xany.type), ev->xany.window)); + D_EVENTS(("process_x_event(ev [%8p] %s on window 0x%08x)\n", ev, event_type_to_name(ev->xany.type), ev->xany.window)); #endif - if (primary_data.handlers[ev->type] != NULL) { - return ((primary_data.handlers[ev->type]) (ev)); - } - return (0); + if (primary_data.handlers[ev->type] != NULL) { + return ((primary_data.handlers[ev->type]) (ev)); + } + return (0); } XErrorHandler xerror_handler(Display * display, XErrorEvent * event) { - char err_string[2048]; + char err_string[2048]; - strcpy(err_string, ""); - XGetErrorText(display, event->error_code, err_string, sizeof(err_string)); - print_error("XError in function %s, resource 0x%08x (request %d.%d): %s (error %d)\n", request_code_to_name(event->request_code), - (int) event->resourceid, event->request_code, event->minor_code, err_string, event->error_code); + strcpy(err_string, ""); + XGetErrorText(display, event->error_code, err_string, sizeof(err_string)); + print_error("XError in function %s, resource 0x%08x (request %d.%d): %s (error %d)\n", request_code_to_name(event->request_code), + (int) event->resourceid, event->request_code, event->minor_code, err_string, event->error_code); #if DEBUG > DEBUG_X11 - if (DEBUG_LEVEL >= DEBUG_X11) { - dump_stack_trace(); - } + if (DEBUG_LEVEL >= DEBUG_X11) { + dump_stack_trace(); + } #endif - print_error("Attempting to continue...\n"); - return 0; + print_error("Attempting to continue...\n"); + return 0; } diff --git a/src/font.c b/src/font.c index f505653..d2db767 100644 --- a/src/font.c +++ b/src/font.c @@ -47,11 +47,11 @@ char *rs_font[NFONTS]; #ifdef MULTI_CHARSET char *rs_mfont[NFONTS]; char **etmfonts = NULL; -const char *def_mfontName[] = {MFONT0, MFONT1, MFONT2, MFONT3, MFONT4}; +const char *def_mfontName[] = { MFONT0, MFONT1, MFONT2, MFONT3, MFONT4 }; #endif -const char *def_fontName[] = {FONT0, FONT1, FONT2, FONT3, FONT4}; +const char *def_fontName[] = { FONT0, FONT1, FONT2, FONT3, FONT4 }; unsigned char font_chg = 0; -fontshadow_t fshadow = { { 0, 0, 0, 0 }, { 0, 0, 0, 1 }, 1 }; +fontshadow_t fshadow = { {0, 0, 0, 0}, {0, 0, 0, 1}, 1 }; static cachefont_t *font_cache = NULL, *cur_font = NULL; static void font_cache_add(const char *name, unsigned char type, void *info); @@ -64,280 +64,299 @@ static unsigned char get_corner(const char *corner); as defined in the attributes/multicharset contexts. They do NOT call the cache routines. The caller is responsible for adding/removing fonts to/from the cache. */ void -eterm_font_add(char ***plist, const char *fontname, unsigned char idx) { +eterm_font_add(char ***plist, const char *fontname, unsigned char idx) +{ - char **flist; + char **flist; - D_FONT(("Adding \"%s\" at %u (%8p)\n", NONULL(fontname), (unsigned int) idx, plist)); - ASSERT(plist != NULL); /* plist is the address of either etfonts or etmfonts */ + D_FONT(("Adding \"%s\" at %u (%8p)\n", NONULL(fontname), (unsigned int) idx, plist)); + ASSERT(plist != NULL); /* plist is the address of either etfonts or etmfonts */ - /* If we're adding the font at an index we don't have yet, we must resize to fit it. */ - if (idx >= font_cnt) { - unsigned char new_size = sizeof(char *) * (idx + 1); + /* If we're adding the font at an index we don't have yet, we must resize to fit it. */ + if (idx >= font_cnt) { + unsigned char new_size = sizeof(char *) * (idx + 1); - /* The below looks messy with all the cpp stuff, but it really just malloc's/realloc's - both etfonts and etmfonts at the same time to the same size, zeros all the new - memory space using MEMSET(), and then prints some goop. */ - if (etfonts) { - etfonts = (char **) REALLOC(etfonts, new_size); - MEMSET(etfonts + font_cnt, 0, sizeof(char *) * (idx - font_cnt + 1)); + /* The below looks messy with all the cpp stuff, but it really just malloc's/realloc's + both etfonts and etmfonts at the same time to the same size, zeros all the new + memory space using MEMSET(), and then prints some goop. */ + if (etfonts) { + etfonts = (char **) REALLOC(etfonts, new_size); + MEMSET(etfonts + font_cnt, 0, sizeof(char *) * (idx - font_cnt + 1)); #ifdef MULTI_CHARSET - etmfonts = (char **) REALLOC(etmfonts, new_size); - MEMSET(etmfonts + font_cnt, 0, sizeof(char *) * (idx - font_cnt + 1)); - D_FONT((" -> Reallocated font lists: %u bytes at %8p/%8p\n", new_size, etfonts, etmfonts)); + etmfonts = (char **) REALLOC(etmfonts, new_size); + MEMSET(etmfonts + font_cnt, 0, sizeof(char *) * (idx - font_cnt + 1)); + D_FONT((" -> Reallocated font lists: %u bytes at %8p/%8p\n", new_size, etfonts, etmfonts)); #else - D_FONT((" -> Reallocated font list: %u bytes at %8p\n", new_size, etfonts)); + D_FONT((" -> Reallocated font list: %u bytes at %8p\n", new_size, etfonts)); +#endif + } else { + etfonts = (char **) MALLOC(new_size); + MEMSET(etfonts, 0, new_size); +#ifdef MULTI_CHARSET + etmfonts = (char **) MALLOC(new_size); + MEMSET(etmfonts, 0, new_size); + D_FONT((" -> Allocated font lists: %u bytes at %8p/%8p\n", new_size, etfonts, etmfonts)); +#else + D_FONT((" -> Allocating font list: %u bytes at %8p\n", new_size, etfonts)); +#endif + } + + font_cnt = idx + 1; /* Update the font count. */ +#ifdef MULTI_CHARSET + flist = ((plist == &etfonts) ? (etfonts) : (etmfonts)); +#else + flist = etfonts; #endif } else { - etfonts = (char **) MALLOC(new_size); - MEMSET(etfonts, 0, new_size); -#ifdef MULTI_CHARSET - etmfonts = (char **) MALLOC(new_size); - MEMSET(etmfonts, 0, new_size); - D_FONT((" -> Allocated font lists: %u bytes at %8p/%8p\n", new_size, etfonts, etmfonts)); -#else - D_FONT((" -> Allocating font list: %u bytes at %8p\n", new_size, etfonts)); -#endif + flist = *plist; + if (flist[idx]) { + if ((flist[idx] == fontname) || (!strcasecmp(flist[idx], fontname))) { + return; /* We've already got the right font. */ + } + FREE(flist[idx]); /* We're replacing an old font. Get rid of the old name. */ + } } - - font_cnt = idx + 1; /* Update the font count. */ -#ifdef MULTI_CHARSET - flist = ((plist == &etfonts) ? (etfonts) : (etmfonts)); -#else - flist = etfonts; -#endif - } else { - flist = *plist; - if (flist[idx]) { - if ((flist[idx] == fontname) || (!strcasecmp(flist[idx], fontname))) { - return; /* We've already got the right font. */ - } - FREE(flist[idx]); /* We're replacing an old font. Get rid of the old name. */ - } - } - flist[idx] = STRDUP(fontname); - DUMP_FONTS(); + flist[idx] = STRDUP(fontname); + DUMP_FONTS(); } void -eterm_font_delete(char **flist, unsigned char idx) { +eterm_font_delete(char **flist, unsigned char idx) +{ - ASSERT(idx < font_cnt); + ASSERT(idx < font_cnt); - if (flist[idx]) { - FREE(flist[idx]); - } - flist[idx] = NULL; + if (flist[idx]) { + FREE(flist[idx]); + } + flist[idx] = NULL; } void eterm_font_list_clear(void) { - unsigned char idx; + unsigned char idx; - for (idx = 0; idx < font_cnt; idx++) { - eterm_font_delete(etfonts, idx); + for (idx = 0; idx < font_cnt; idx++) { + eterm_font_delete(etfonts, idx); #ifdef MULTI_CHARSET - eterm_font_delete(etmfonts, idx); + eterm_font_delete(etmfonts, idx); #endif - } - FREE(etfonts); + } + FREE(etfonts); #ifdef MULTI_CHARSET - FREE(etmfonts); + FREE(etmfonts); #endif } /* These font caching routines keep track of all the various fonts we allocate in the X server so that we only allocate each font once. Saves memory. */ static void -font_cache_add(const char *name, unsigned char type, void *info) { +font_cache_add(const char *name, unsigned char type, void *info) +{ - cachefont_t *font; + cachefont_t *font; - D_FONT(("font_cache_add(%s, %d, %8p) called.\n", NONULL(name), type, info)); + D_FONT(("font_cache_add(%s, %d, %8p) called.\n", NONULL(name), type, info)); - /* Allocate the cache info for the font and store the data */ - font = (cachefont_t *) MALLOC(sizeof(cachefont_t)); - font->name = STRDUP(name); - font->type = type; - font->ref_cnt = 1; - switch (type) { - case FONT_TYPE_X: font->fontinfo.xfontinfo = (XFontStruct *) info; break; - case FONT_TYPE_TTF: break; - case FONT_TYPE_FNLIB: break; - default: break; - } - D_FONT((" -> Created new cachefont_t struct at %p: \"%s\", %d, %p\n", font, font->name, font->type, font->fontinfo.xfontinfo)); + /* Allocate the cache info for the font and store the data */ + font = (cachefont_t *) MALLOC(sizeof(cachefont_t)); + font->name = STRDUP(name); + font->type = type; + font->ref_cnt = 1; + switch (type) { + case FONT_TYPE_X: + font->fontinfo.xfontinfo = (XFontStruct *) info; + break; + case FONT_TYPE_TTF: + break; + case FONT_TYPE_FNLIB: + break; + default: + break; + } + D_FONT((" -> Created new cachefont_t struct at %p: \"%s\", %d, %p\n", font, font->name, font->type, font->fontinfo.xfontinfo)); - /* Actually add the struct to the end of our cache linked list. */ - if (font_cache == NULL) { - font_cache = cur_font = font; - font->next = NULL; - D_FONT((" -> Stored as first font in cache. font_cache == cur_font == font == %p\n", font_cache)); - D_FONT((" -> font_cache->next == cur_font->next == font->next == %p\n", font_cache->next)); - } else { - D_FONT((" -> font_cache->next == %p, cur_font->next == %p\n", font_cache->next, cur_font->next)); - cur_font->next = font; - font->next = NULL; - cur_font = font; - D_FONT((" -> Stored font in cache. font_cache == %p, cur_font == %p\n", font_cache, cur_font)); - D_FONT((" -> font_cache->next == %p, cur_font->next == %p\n", font_cache->next, cur_font->next)); - } + /* Actually add the struct to the end of our cache linked list. */ + if (font_cache == NULL) { + font_cache = cur_font = font; + font->next = NULL; + D_FONT((" -> Stored as first font in cache. font_cache == cur_font == font == %p\n", font_cache)); + D_FONT((" -> font_cache->next == cur_font->next == font->next == %p\n", font_cache->next)); + } else { + D_FONT((" -> font_cache->next == %p, cur_font->next == %p\n", font_cache->next, cur_font->next)); + cur_font->next = font; + font->next = NULL; + cur_font = font; + D_FONT((" -> Stored font in cache. font_cache == %p, cur_font == %p\n", font_cache, cur_font)); + D_FONT((" -> font_cache->next == %p, cur_font->next == %p\n", font_cache->next, cur_font->next)); + } } static void -font_cache_del(const void *info) { +font_cache_del(const void *info) +{ - cachefont_t *current, *tmp; + cachefont_t *current, *tmp; - D_FONT(("font_cache_del(%8p) called.\n", info)); + D_FONT(("font_cache_del(%8p) called.\n", info)); - if (font_cache == NULL) { - return; /* No fonts in the cache. Theoretically this should never happen, but... */ - } - - /* Check the very first entry for a match. It's a special case. */ - if (((font_cache->type == FONT_TYPE_X) && (font_cache->fontinfo.xfontinfo == (XFontStruct *) info))) { - D_FONT((" -> Match found at font_cache (%8p). Font name is \"%s\"\n", font_cache, NONULL(font_cache->name))); - /* We've got a match. Decrement the reference count, and if it goes to 0, remove it from the cache. */ - if (--(font_cache->ref_cnt) == 0) { - D_FONT((" -> Reference count is now 0. Deleting from cache.\n")); - current = font_cache; - font_cache = current->next; - XFreeFont(Xdisplay, (XFontStruct *) info); - FREE(current->name); - FREE(current); - } else { - D_FONT((" -> Reference count is %d. Returning.\n", font_cache->ref_cnt)); + if (font_cache == NULL) { + return; /* No fonts in the cache. Theoretically this should never happen, but... */ } - return; -#if UNUSED_BLOCK - } else if ((font_cache->type == FONT_TYPE_TTF) && (0)) { - } else if ((font_cache->type == FONT_TYPE_FNLIB) && (0)) { -#endif - } else { - /* Search for a match. We test current->next, not current, so that we can - update the "next" pointer of the font prior to the one we're actually deleting. */ - for (current = font_cache; current->next; current = current->next) { - if (((current->next->type == FONT_TYPE_X) && (current->next->fontinfo.xfontinfo == (XFontStruct *) info))) { - D_FONT((" -> Match found at current->next (%8p, current == %8p). Font name is \"%s\"\n", current->next, current, NONULL(current->next->name))); - if (--(current->next->ref_cnt) == 0) { - D_FONT((" -> Reference count is now 0. Deleting from cache.\n")); - tmp = current->next; - current->next = current->next->next; - XFreeFont(Xdisplay, (XFontStruct *) info); - if (cur_font == tmp) { - cur_font = current; /* If we're nuking the last entry in the cache, point cur_font to the *new* last entry. */ - } - FREE(tmp->name); - FREE(tmp); + + /* Check the very first entry for a match. It's a special case. */ + if (((font_cache->type == FONT_TYPE_X) && (font_cache->fontinfo.xfontinfo == (XFontStruct *) info))) { + D_FONT((" -> Match found at font_cache (%8p). Font name is \"%s\"\n", font_cache, NONULL(font_cache->name))); + /* We've got a match. Decrement the reference count, and if it goes to 0, remove it from the cache. */ + if (--(font_cache->ref_cnt) == 0) { + D_FONT((" -> Reference count is now 0. Deleting from cache.\n")); + current = font_cache; + font_cache = current->next; + XFreeFont(Xdisplay, (XFontStruct *) info); + FREE(current->name); + FREE(current); } else { - D_FONT((" -> Reference count is %d. Returning.\n", font_cache->ref_cnt)); + D_FONT((" -> Reference count is %d. Returning.\n", font_cache->ref_cnt)); } return; #if UNUSED_BLOCK - } else if ((current->next->type == FONT_TYPE_TTF) && (0)) { - } else if ((current->next->type == FONT_TYPE_FNLIB) && (0)) { + } else if ((font_cache->type == FONT_TYPE_TTF) && (0)) { + } else if ((font_cache->type == FONT_TYPE_FNLIB) && (0)) { #endif - } + } else { + /* Search for a match. We test current->next, not current, so that we can + update the "next" pointer of the font prior to the one we're actually deleting. */ + for (current = font_cache; current->next; current = current->next) { + if (((current->next->type == FONT_TYPE_X) && (current->next->fontinfo.xfontinfo == (XFontStruct *) info))) { + D_FONT((" -> Match found at current->next (%8p, current == %8p). Font name is \"%s\"\n", current->next, current, + NONULL(current->next->name))); + if (--(current->next->ref_cnt) == 0) { + D_FONT((" -> Reference count is now 0. Deleting from cache.\n")); + tmp = current->next; + current->next = current->next->next; + XFreeFont(Xdisplay, (XFontStruct *) info); + if (cur_font == tmp) { + cur_font = current; /* If we're nuking the last entry in the cache, point cur_font to the *new* last entry. */ + } + FREE(tmp->name); + FREE(tmp); + } else { + D_FONT((" -> Reference count is %d. Returning.\n", font_cache->ref_cnt)); + } + return; +#if UNUSED_BLOCK + } else if ((current->next->type == FONT_TYPE_TTF) && (0)) { + } else if ((current->next->type == FONT_TYPE_FNLIB) && (0)) { +#endif + } + } } - } - /* If we get here, there was no match. No big deal. */ + /* If we get here, there was no match. No big deal. */ } void font_cache_clear(void) { - cachefont_t *current, *tmp; + cachefont_t *current, *tmp; - D_FONT(("Clearing the font cache.\n")); - for (current = font_cache; current; ) { - D_FONT((" -> Deleting \"%s\" from cache.\n", current->name)); - tmp = current; - current = current->next; - if (tmp->type == FONT_TYPE_X) { - XFreeFont(Xdisplay, (XFontStruct *) tmp->fontinfo.xfontinfo); - FREE(tmp->name); - FREE(tmp); + D_FONT(("Clearing the font cache.\n")); + for (current = font_cache; current;) { + D_FONT((" -> Deleting \"%s\" from cache.\n", current->name)); + tmp = current; + current = current->next; + if (tmp->type == FONT_TYPE_X) { + XFreeFont(Xdisplay, (XFontStruct *) tmp->fontinfo.xfontinfo); + FREE(tmp->name); + FREE(tmp); #if UNUSED_BLOCK - } else if (current->next->type == FONT_TYPE_TTF) { - } else if (current->next->type == FONT_TYPE_FNLIB) { + } else if (current->next->type == FONT_TYPE_TTF) { + } else if (current->next->type == FONT_TYPE_FNLIB) { #endif + } } - } - font_cache = cur_font = NULL; + font_cache = cur_font = NULL; } -static cachefont_t * -font_cache_find(const char *name, unsigned char type) { +static cachefont_t *font_cache_find(const char *name, unsigned char type) +{ - cachefont_t *current; + cachefont_t *current; - ASSERT_RVAL(name != NULL, NULL); + ASSERT_RVAL(name != NULL, NULL); - D_FONT(("font_cache_find(%s, %d) called.\n", NONULL(name), type)); + D_FONT(("font_cache_find(%s, %d) called.\n", NONULL(name), type)); - /* Find a matching name/type in the cache. Just a search; no reference counting happens here. */ - for (current = font_cache; current; current = current->next) { - D_FONT((" -> Checking current (%8p), type == %d, name == %s\n", current, current->type, NONULL(current->name))); - if ((current->type == type) && !strcasecmp(current->name, name)) { - D_FONT((" -> Match!\n")); - return (current); + /* Find a matching name/type in the cache. Just a search; no reference counting happens here. */ + for (current = font_cache; current; current = current->next) { + D_FONT((" -> Checking current (%8p), type == %d, name == %s\n", current, current->type, NONULL(current->name))); + if ((current->type == type) && !strcasecmp(current->name, name)) { + D_FONT((" -> Match!\n")); + return (current); + } } - } - D_FONT(("No matches found. =(\n")); - return ((cachefont_t *) NULL); + D_FONT(("No matches found. =(\n")); + return ((cachefont_t *) NULL); } static void * -font_cache_find_info(const char *name, unsigned char type) { +font_cache_find_info(const char *name, unsigned char type) +{ - cachefont_t *current; + cachefont_t *current; - REQUIRE_RVAL(name != NULL, NULL); + REQUIRE_RVAL(name != NULL, NULL); - D_FONT(("font_cache_find_info(%s, %d) called.\n", NONULL(name), type)); + D_FONT(("font_cache_find_info(%s, %d) called.\n", NONULL(name), type)); - /* This is also a simple search, but it returns the fontinfo rather than the cache entry. */ - for (current = font_cache; current; current = current->next) { - D_FONT((" -> Checking current (%8p), type == %d, name == %s\n", current, current->type, NONULL(current->name))); - if ((current->type == type) && !strcasecmp(current->name, name)) { - D_FONT((" -> Match!\n")); - switch (type) { - case FONT_TYPE_X: return ((void *) current->fontinfo.xfontinfo); break; - case FONT_TYPE_TTF: return (NULL); break; - case FONT_TYPE_FNLIB: return (NULL); break; - default: return (NULL); break; - } + /* This is also a simple search, but it returns the fontinfo rather than the cache entry. */ + for (current = font_cache; current; current = current->next) { + D_FONT((" -> Checking current (%8p), type == %d, name == %s\n", current, current->type, NONULL(current->name))); + if ((current->type == type) && !strcasecmp(current->name, name)) { + D_FONT((" -> Match!\n")); + switch (type) { + case FONT_TYPE_X: + return ((void *) current->fontinfo.xfontinfo); + break; + case FONT_TYPE_TTF: + return (NULL); + break; + case FONT_TYPE_FNLIB: + return (NULL); + break; + default: + return (NULL); + break; + } + } } - } - D_FONT(("No matches found. =(\n")); - return (NULL); + D_FONT(("No matches found. =(\n")); + return (NULL); } const char * get_font_name(void *info) { - cachefont_t *current; + cachefont_t *current; - REQUIRE_RVAL(info != NULL, NULL); + REQUIRE_RVAL(info != NULL, NULL); - D_FONT(("get_font_name(%8p) called.\n", info)); + D_FONT(("get_font_name(%8p) called.\n", info)); - /* This is also a simple search, but it returns the fontinfo rather than the cache entry. */ - for (current = font_cache; current; current = current->next) { - D_FONT((" -> Checking current (%8p), type == %d, name == %s\n", current, current->type, NONULL(current->name))); - if ((current->type == FONT_TYPE_X) && (((void *) current->fontinfo.xfontinfo) == info)) { - D_FONT((" -> Match!\n")); - return current->name; + /* This is also a simple search, but it returns the fontinfo rather than the cache entry. */ + for (current = font_cache; current; current = current->next) { + D_FONT((" -> Checking current (%8p), type == %d, name == %s\n", current, current->type, NONULL(current->name))); + if ((current->type == FONT_TYPE_X) && (((void *) current->fontinfo.xfontinfo) == info)) { + D_FONT((" -> Match!\n")); + return current->name; #if UNUSED_BLOCK - } else if ((current->type == FONT_TYPE_TTF) && (0)) { - } else if ((current->type == FONT_TYPE_FNLIB) && (0)) { + } else if ((current->type == FONT_TYPE_TTF) && (0)) { + } else if ((current->type == FONT_TYPE_FNLIB) && (0)) { #endif + } } - } - D_FONT(("No matches found. =(\n")); - return (NULL); + D_FONT(("No matches found. =(\n")); + return (NULL); } /* load_font() is the function that should be used to allocate fonts. */ @@ -345,76 +364,84 @@ void * load_font(const char *name, const char *fallback, unsigned char type) { - cachefont_t *font; - XFontStruct *xfont; + cachefont_t *font; + XFontStruct *xfont; - D_FONT(("load_font(%s, %s, %d) called.\n", NONULL(name), NONULL(fallback), type)); + D_FONT(("load_font(%s, %s, %d) called.\n", NONULL(name), NONULL(fallback), type)); - /* Default type is X font. */ - if (type == 0) { - type = FONT_TYPE_X; - } + /* Default type is X font. */ + if (type == 0) { + type = FONT_TYPE_X; + } - /* Specify some sane fallbacks */ - if (name == NULL) { - if (fallback) { - name = fallback; - fallback = "fixed"; - } else { - name = "fixed"; + /* Specify some sane fallbacks */ + if (name == NULL) { + if (fallback) { + name = fallback; + fallback = "fixed"; + } else { + name = "fixed"; #ifdef MULTI_CHARSET - fallback = "-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso10646-1"; + fallback = "-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso10646-1"; #else - fallback = "-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-1"; + fallback = "-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-1"; #endif + } + } else if (fallback == NULL) { + fallback = "fixed"; } - } else if (fallback == NULL) { - fallback = "fixed"; - } - D_FONT((" -> Using name == \"%s\" and fallback == \"%s\"\n", name, fallback)); + D_FONT((" -> Using name == \"%s\" and fallback == \"%s\"\n", name, fallback)); - /* Look for the font name in the cache. If it's there, add one to the - reference count and return the existing fontinfo pointer to the caller. */ - if ((font = font_cache_find(name, type)) != NULL) { - font_cache_add_ref(font); - D_FONT((" -> Font found in cache. Incrementing reference count to %d and returning existing data.\n", font->ref_cnt)); - switch (type) { - case FONT_TYPE_X: return ((void *) font->fontinfo.xfontinfo); break; - case FONT_TYPE_TTF: return (NULL); break; - case FONT_TYPE_FNLIB: return (NULL); break; - default: return (NULL); break; + /* Look for the font name in the cache. If it's there, add one to the + reference count and return the existing fontinfo pointer to the caller. */ + if ((font = font_cache_find(name, type)) != NULL) { + font_cache_add_ref(font); + D_FONT((" -> Font found in cache. Incrementing reference count to %d and returning existing data.\n", font->ref_cnt)); + switch (type) { + case FONT_TYPE_X: + return ((void *) font->fontinfo.xfontinfo); + break; + case FONT_TYPE_TTF: + return (NULL); + break; + case FONT_TYPE_FNLIB: + return (NULL); + break; + default: + return (NULL); + break; + } } - } - /* No match in the cache, so we'll have to add it. */ - if (type == FONT_TYPE_X) { - if ((xfont = XLoadQueryFont(Xdisplay, name)) == NULL) { - print_error("Unable to load font \"%s\". Falling back on \"%s\"\n", name, fallback); - if ((xfont = XLoadQueryFont(Xdisplay, fallback)) == NULL) { - fatal_error("Couldn't load the fallback font either. Giving up.\n"); - } else { - font_cache_add(fallback, type, (void *) xfont); - } - } else { - font_cache_add(name, type, (void *) xfont); - } - return ((void *) xfont); + /* No match in the cache, so we'll have to add it. */ + if (type == FONT_TYPE_X) { + if ((xfont = XLoadQueryFont(Xdisplay, name)) == NULL) { + print_error("Unable to load font \"%s\". Falling back on \"%s\"\n", name, fallback); + if ((xfont = XLoadQueryFont(Xdisplay, fallback)) == NULL) { + fatal_error("Couldn't load the fallback font either. Giving up.\n"); + } else { + font_cache_add(fallback, type, (void *) xfont); + } + } else { + font_cache_add(name, type, (void *) xfont); + } + return ((void *) xfont); #if UNUSED_BLOCK - } else if (type == FONT_TYPE_TTF) { - return (NULL); - } else if (type == FONT_TYPE_FNLIB) { - return (NULL); + } else if (type == FONT_TYPE_TTF) { + return (NULL); + } else if (type == FONT_TYPE_FNLIB) { + return (NULL); #endif - } - ASSERT_NOTREACHED_RVAL(NULL); + } + ASSERT_NOTREACHED_RVAL(NULL); } /* free_font() is the external function for deallocating fonts. */ void free_font(const void *info) { - ASSERT(info != NULL); - font_cache_del(info); + ASSERT(info != NULL); + font_cache_del(info); } /* change_font() handles the font changing escape sequences. It's also called to @@ -423,262 +450,264 @@ void change_font(int init, const char *fontname) { #ifndef NO_BOLDFONT - static XFontStruct *boldFont = NULL; + static XFontStruct *boldFont = NULL; #endif - short idx = 0, old_idx = font_idx; - int fh, fw = 0; + short idx = 0, old_idx = font_idx; + int fh, fw = 0; - D_FONT(("change_font(%d, \"%s\"): def_font_idx == %u, font_idx == %u\n", init, NONULL(fontname), (unsigned int) def_font_idx, (unsigned int) font_idx)); + D_FONT(("change_font(%d, \"%s\"): def_font_idx == %u, font_idx == %u\n", init, NONULL(fontname), (unsigned int) def_font_idx, + (unsigned int) font_idx)); - if (init) { - font_idx = def_font_idx; - ASSERT(etfonts != NULL); - ASSERT(etfonts[font_idx] != NULL); + if (init) { + font_idx = def_font_idx; + ASSERT(etfonts != NULL); + ASSERT(etfonts[font_idx] != NULL); #ifdef MULTI_CHARSET - ASSERT(etmfonts != NULL); - ASSERT(etmfonts[font_idx] != NULL); -#endif - } else { - ASSERT(fontname != NULL); + ASSERT(etmfonts != NULL); + ASSERT(etmfonts[font_idx] != NULL); +#endif + } else { + ASSERT(fontname != NULL); - switch (*fontname) { - /* Empty font name. Reset to default. */ - case '\0': - font_idx = def_font_idx; - fontname = NULL; - break; + switch (*fontname) { + /* Empty font name. Reset to default. */ + case '\0': + font_idx = def_font_idx; + fontname = NULL; + break; - /* A font escape sequence. See which one it is. */ - case FONT_CMD: - idx = atoi(++fontname); - switch (*fontname) { - case '+': - NEXT_FONT(idx); - break; + /* A font escape sequence. See which one it is. */ + case FONT_CMD: + idx = atoi(++fontname); + switch (*fontname) { + case '+': + NEXT_FONT(idx); + break; - case '-': - PREV_FONT(idx); - break; + case '-': + PREV_FONT(idx); + break; - default: - if (*fontname != '\0' && !isdigit(*fontname)) - return; /* It's not a number. Punt. */ - /* Set current font to font N */ - BOUND(idx, 0, (font_cnt - 1)); - font_idx = idx; - break; - } - /* NULL out the fontname so we don't try to load it */ - fontname = NULL; - break; + default: + if (*fontname != '\0' && !isdigit(*fontname)) + return; /* It's not a number. Punt. */ + /* Set current font to font N */ + BOUND(idx, 0, (font_cnt - 1)); + font_idx = idx; + break; + } + /* NULL out the fontname so we don't try to load it */ + fontname = NULL; + break; - default: - /* Change to the named font. See if we already have it, and if so, just set the index. */ - for (idx = 0; idx < font_cnt; idx++) { - if (!strcasecmp(etfonts[idx], fontname)) { - font_idx = idx; - fontname = NULL; - break; - } - } - break; + default: + /* Change to the named font. See if we already have it, and if so, just set the index. */ + for (idx = 0; idx < font_cnt; idx++) { + if (!strcasecmp(etfonts[idx], fontname)) { + font_idx = idx; + fontname = NULL; + break; + } + } + break; + } + + /* If we get here with a non-NULL fontname, we have to load a new font. Rats. */ + if (fontname != NULL) { + eterm_font_add(&etfonts, fontname, font_idx); + } else if (font_idx == old_idx) { + /* Sigh. What a waste of time, changing to the same font. */ + D_FONT((" -> Change to the same font index (%d) we had before? I don't think so.\n", font_idx)); + return; + } } - - /* If we get here with a non-NULL fontname, we have to load a new font. Rats. */ - if (fontname != NULL) { - eterm_font_add(&etfonts, fontname, font_idx); - } else if (font_idx == old_idx) { - /* Sigh. What a waste of time, changing to the same font. */ - D_FONT((" -> Change to the same font index (%d) we had before? I don't think so.\n", font_idx)); - return; + D_FONT((" -> Changing to font index %u (\"%s\")\n", (unsigned int) font_idx, NONULL(etfonts[font_idx]))); + if (TermWin.font) { + /* If we have a terminal font, but it's not our new current font, free it and load the new one. */ + if (font_cache_find_info(etfonts[font_idx], FONT_TYPE_X) != TermWin.font) { + free_font(TermWin.font); + TermWin.font = load_font(etfonts[font_idx], "fixed", FONT_TYPE_X); + } + } else { + /* Load the new font. */ + TermWin.font = load_font(etfonts[font_idx], "fixed", FONT_TYPE_X); } - } - D_FONT((" -> Changing to font index %u (\"%s\")\n", (unsigned int) font_idx, NONULL(etfonts[font_idx]))); - if (TermWin.font) { - /* If we have a terminal font, but it's not our new current font, free it and load the new one. */ - if (font_cache_find_info(etfonts[font_idx], FONT_TYPE_X) != TermWin.font) { - free_font(TermWin.font); - TermWin.font = load_font(etfonts[font_idx], "fixed", FONT_TYPE_X); - } - } else { - /* Load the new font. */ - TermWin.font = load_font(etfonts[font_idx], "fixed", FONT_TYPE_X); - } #ifndef NO_BOLDFONT - if (init && rs_boldFont != NULL) { - /* If we're initializing, load the bold font too. */ - boldFont = load_font(rs_boldFont, "-misc-fixed-bold-r-semicondensed--13-120-75-75-c-60-iso8859-1", FONT_TYPE_X); - } + if (init && rs_boldFont != NULL) { + /* If we're initializing, load the bold font too. */ + boldFont = load_font(rs_boldFont, "-misc-fixed-bold-r-semicondensed--13-120-75-75-c-60-iso8859-1", FONT_TYPE_X); + } #endif #ifdef MULTI_CHARSET - if (TermWin.mfont) { - /* Ditto the above, but for the multi-byte fonts. */ - if (font_cache_find_info(etmfonts[font_idx], FONT_TYPE_X) != TermWin.mfont) { - free_font(TermWin.mfont); - TermWin.mfont = load_font(etmfonts[font_idx], "k14", FONT_TYPE_X); + if (TermWin.mfont) { + /* Ditto the above, but for the multi-byte fonts. */ + if (font_cache_find_info(etmfonts[font_idx], FONT_TYPE_X) != TermWin.mfont) { + free_font(TermWin.mfont); + TermWin.mfont = load_font(etmfonts[font_idx], "k14", FONT_TYPE_X); + } + } else { + TermWin.mfont = load_font(etmfonts[font_idx], "k14", FONT_TYPE_X); } - } else { - TermWin.mfont = load_font(etmfonts[font_idx], "k14", FONT_TYPE_X); - } # ifdef USE_XIM - /* Changing fonts requires updating the FontSet */ - if (xim_input_context) { - if (TermWin.fontset) { - XFreeFontSet(Xdisplay, TermWin.fontset); + /* Changing fonts requires updating the FontSet */ + if (xim_input_context) { + if (TermWin.fontset) { + XFreeFontSet(Xdisplay, TermWin.fontset); + } + TermWin.fontset = create_fontset(etfonts[font_idx], etmfonts[font_idx]); + xim_set_fontset(); } - TermWin.fontset = create_fontset(etfonts[font_idx], etmfonts[font_idx]); - xim_set_fontset(); - } # endif #endif /* MULTI_CHARSET */ - if (!init) { - /* Unless we're initializing, set the font ID in the GC to our new font. */ - XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid); - } + if (!init) { + /* Unless we're initializing, set the font ID in the GC to our new font. */ + XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid); + } - /* Check the font dimensions to update our TermWin info */ - fw = TermWin.font->min_bounds.width; + /* Check the font dimensions to update our TermWin info */ + fw = TermWin.font->min_bounds.width; #ifdef MULTI_CHARSET - fh = (MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->ascent), TermWin.font->ascent) - + MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->descent), TermWin.font->descent) - + rs_line_space); + fh = (MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->ascent), TermWin.font->ascent) + + MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->descent), TermWin.font->descent) + + rs_line_space); #else - fh = TermWin.font->ascent + TermWin.font->descent + rs_line_space; + fh = TermWin.font->ascent + TermWin.font->descent + rs_line_space; #endif - D_FONT(("Font information: Ascent == %hd, Descent == %hd, width min/max %d/%d\n", TermWin.font->ascent, TermWin.font->descent, - TermWin.font->min_bounds.width, TermWin.font->max_bounds.width)); - if (TermWin.font->min_bounds.width == TermWin.font->max_bounds.width) - TermWin.fprop = 0; /* Mono-spaced (fixed width) font */ - else - TermWin.fprop = 1; /* Proportional font */ + D_FONT(("Font information: Ascent == %hd, Descent == %hd, width min/max %d/%d\n", TermWin.font->ascent, TermWin.font->descent, + TermWin.font->min_bounds.width, TermWin.font->max_bounds.width)); + if (TermWin.font->min_bounds.width == TermWin.font->max_bounds.width) + TermWin.fprop = 0; /* Mono-spaced (fixed width) font */ + else + TermWin.fprop = 1; /* Proportional font */ - /* For proportional fonts with large size variations, do some math-fu to try and help the appearance */ - if (TermWin.fprop && (Options & Opt_proportional) && TermWin.font->per_char - && (TermWin.font->max_bounds.width - TermWin.font->min_bounds.width >= 3)) { - int cw, n = 0, sum = 0, sumsq = 0, min_w, max_w; - unsigned int i; - double dev; + /* For proportional fonts with large size variations, do some math-fu to try and help the appearance */ + if (TermWin.fprop && (Options & Opt_proportional) && TermWin.font->per_char + && (TermWin.font->max_bounds.width - TermWin.font->min_bounds.width >= 3)) { + int cw, n = 0, sum = 0, sumsq = 0, min_w, max_w; + unsigned int i; + double dev; - min_w = fw; - LOWER_BOUND(min_w, 1); - max_w = TermWin.font->max_bounds.width; - UPPER_BOUND(max_w, 1024); - for (i = TermWin.font->min_char_or_byte2; i <= TermWin.font->max_char_or_byte2; i++) { - cw = TermWin.font->per_char[i].width; - if (cw >= min_w && cw <= max_w) { - sum += cw; - sumsq += (cw * cw); - n++; - } - } - if (n) { - dev = sqrt((sumsq - (sum * sum) / n) / n); - /* Final font width is the average width plus 2 standard - deviations, but no larger than the font's max width */ - fw = ((sum / n) + (((int) dev) << 1)); - D_FONT(("Proportional font optimizations: Average width %d, standard deviation %3.2f, new width %d\n", (sum / n), dev, fw)); - UPPER_BOUND(fw, max_w); + min_w = fw; + LOWER_BOUND(min_w, 1); + max_w = TermWin.font->max_bounds.width; + UPPER_BOUND(max_w, 1024); + for (i = TermWin.font->min_char_or_byte2; i <= TermWin.font->max_char_or_byte2; i++) { + cw = TermWin.font->per_char[i].width; + if (cw >= min_w && cw <= max_w) { + sum += cw; + sumsq += (cw * cw); + n++; + } + } + if (n) { + dev = sqrt((sumsq - (sum * sum) / n) / n); + /* Final font width is the average width plus 2 standard + deviations, but no larger than the font's max width */ + fw = ((sum / n) + (((int) dev) << 1)); + D_FONT(("Proportional font optimizations: Average width %d, standard deviation %3.2f, new width %d\n", (sum / n), dev, fw)); + UPPER_BOUND(fw, max_w); + } else { + LOWER_BOUND(fw, TermWin.font->max_bounds.width); + } } else { - LOWER_BOUND(fw, TermWin.font->max_bounds.width); - } - } else { - LOWER_BOUND(fw, TermWin.font->max_bounds.width); - } - - /* If the sizes haven't changed, we don't have to update the hints */ - if (fw == TermWin.fwidth && fh == TermWin.fheight) { - /* but we _do_ need to redraw to show the new font */ - scr_touch(); - return; - } - - TermWin.fwidth = fw; - TermWin.fheight = fh; - - /* Check the bold font size and make sure it matches the normal font */ -#ifndef NO_BOLDFONT - TermWin.boldFont = NULL; /* FIXME: Memory leak? Not that anyone uses bold fonts.... */ - if (boldFont != NULL) { - - fw = boldFont->min_bounds.width; - fh = boldFont->ascent + boldFont->descent + rs_line_space; - if (TermWin.fprop == 0) { /* bold font must also be monospaced */ - if (fw != boldFont->max_bounds.width) - fw = -1; - } else { - LOWER_BOUND(fw, boldFont->max_bounds.width); + LOWER_BOUND(fw, TermWin.font->max_bounds.width); } + /* If the sizes haven't changed, we don't have to update the hints */ if (fw == TermWin.fwidth && fh == TermWin.fheight) { - TermWin.boldFont = boldFont; + /* but we _do_ need to redraw to show the new font */ + scr_touch(); + return; + } + + TermWin.fwidth = fw; + TermWin.fheight = fh; + + /* Check the bold font size and make sure it matches the normal font */ +#ifndef NO_BOLDFONT + TermWin.boldFont = NULL; /* FIXME: Memory leak? Not that anyone uses bold fonts.... */ + if (boldFont != NULL) { + + fw = boldFont->min_bounds.width; + fh = boldFont->ascent + boldFont->descent + rs_line_space; + if (TermWin.fprop == 0) { /* bold font must also be monospaced */ + if (fw != boldFont->max_bounds.width) + fw = -1; + } else { + LOWER_BOUND(fw, boldFont->max_bounds.width); + } + + if (fw == TermWin.fwidth && fh == TermWin.fheight) { + TermWin.boldFont = boldFont; + } } - } #endif /* NO_BOLDFONT */ - set_colorfgbg(); + set_colorfgbg(); - TermWin.width = TermWin.ncol * TermWin.fwidth; - TermWin.height = TermWin.nrow * TermWin.fheight; - D_FONT((" -> New font width/height = %ldx%ld, making the terminal size %ldx%ld\n", TermWin.fwidth, TermWin.fheight, TermWin.width, TermWin.height)); + TermWin.width = TermWin.ncol * TermWin.fwidth; + TermWin.height = TermWin.nrow * TermWin.fheight; + D_FONT((" -> New font width/height = %ldx%ld, making the terminal size %ldx%ld\n", TermWin.fwidth, TermWin.fheight, TermWin.width, + TermWin.height)); - /* If we're initializing, *we* do the size hints. If not, resize the parent window. */ - if (init) { - szHint.width_inc = TermWin.fwidth; - szHint.height_inc = TermWin.fheight; + /* If we're initializing, *we* do the size hints. If not, resize the parent window. */ + if (init) { + szHint.width_inc = TermWin.fwidth; + szHint.height_inc = TermWin.fheight; - szHint.min_width = szHint.base_width + szHint.width_inc; - szHint.min_height = szHint.base_height + szHint.height_inc; + szHint.min_width = szHint.base_width + szHint.width_inc; + szHint.min_height = szHint.base_height + szHint.height_inc; - szHint.width = szHint.base_width + TermWin.width; - szHint.height = szHint.base_height + TermWin.height; + szHint.width = szHint.base_width + TermWin.width; + szHint.height = szHint.base_height + TermWin.height; - szHint.flags = PMinSize | PResizeInc | PBaseSize; - } else { - parent_resize(); - font_chg++; - } - return; + szHint.flags = PMinSize | PResizeInc | PBaseSize; + } else { + parent_resize(); + font_chg++; + } + return; } static unsigned char get_corner(const char *corner) { - if (!BEG_STRCASECMP(corner, "tl ") || !BEG_STRCASECMP(corner, "top_left")) { - return SHADOW_TOP_LEFT; - } else if (!BEG_STRCASECMP(corner, "tr ") || !BEG_STRCASECMP(corner, "top_right")) { - return SHADOW_TOP_RIGHT; - } else if (!BEG_STRCASECMP(corner, "bl ") || !BEG_STRCASECMP(corner, "bottom_left")) { - return SHADOW_BOTTOM_LEFT; - } else if (!BEG_STRCASECMP(corner, "br ") || !BEG_STRCASECMP(corner, "bottom_right")) { - return SHADOW_BOTTOM_RIGHT; - } else { - return 255; - } + if (!BEG_STRCASECMP(corner, "tl ") || !BEG_STRCASECMP(corner, "top_left")) { + return SHADOW_TOP_LEFT; + } else if (!BEG_STRCASECMP(corner, "tr ") || !BEG_STRCASECMP(corner, "top_right")) { + return SHADOW_TOP_RIGHT; + } else if (!BEG_STRCASECMP(corner, "bl ") || !BEG_STRCASECMP(corner, "bottom_left")) { + return SHADOW_BOTTOM_LEFT; + } else if (!BEG_STRCASECMP(corner, "br ") || !BEG_STRCASECMP(corner, "bottom_right")) { + return SHADOW_BOTTOM_RIGHT; + } else { + return 255; + } } void set_shadow_color_by_name(unsigned char which, const char *color_name) { - Pixel p; + Pixel p; - ASSERT(which <= 4); + ASSERT(which <= 4); - p = get_color_by_name(color_name, "#000000"); - fshadow.color[which] = p; - fshadow.shadow[which] = fshadow.do_shadow = 1; + p = get_color_by_name(color_name, "#000000"); + fshadow.color[which] = p; + fshadow.shadow[which] = fshadow.do_shadow = 1; } void set_shadow_color_by_pixel(unsigned char which, Pixel p) { - ASSERT(which <= 4); + ASSERT(which <= 4); - fshadow.color[which] = p; - fshadow.shadow[which] = fshadow.do_shadow = 1; + fshadow.color[which] = p; + fshadow.shadow[which] = fshadow.do_shadow = 1; } /* Possible syntax for the font effects line: @@ -694,87 +723,87 @@ set_shadow_color_by_pixel(unsigned char which, Pixel p) unsigned char parse_font_fx(const char *line) { - char *color, *corner; - unsigned char which, n; - Pixel p; + char *color, *corner; + unsigned char which, n; + Pixel p; - ASSERT(line != NULL); + ASSERT(line != NULL); - n = num_words(line); + n = num_words(line); - if (!BEG_STRCASECMP(line, "none")) { - MEMSET(&fshadow, 0, sizeof(fontshadow_t)); - } else if (!BEG_STRCASECMP(line, "outline")) { - if (n != 2) { - return 0; - } - color = get_word(2, line); - p = get_color_by_name(color, "black"); - FREE(color); - for (which = 0; which < 4; which++) { - set_shadow_color_by_pixel(which, p); - } - } else if (!BEG_STRCASECMP(line, "shadow")) { - if (n == 2) { - which = SHADOW_BOTTOM_RIGHT; - color = get_word(2, line); - } else if (n == 3) { - color = get_word(3, line); - corner = get_pword(2, line); - which = get_corner(corner); - if (which >= 4) { - return 0; - } - } else { - return 0; - } - set_shadow_color_by_name(which, color); - FREE(color); - } else if (!BEG_STRCASECMP(line, "emboss")) { - if (n != 3) { - return 0; - } - color = get_word(2, line); - p = get_color_by_name(color, "black"); - set_shadow_color_by_pixel(SHADOW_BOTTOM_RIGHT, p); - FREE(color); - - color = get_word(3, line); - p = get_color_by_name(color, "white"); - set_shadow_color_by_pixel(SHADOW_TOP_LEFT, p); - FREE(color); - } else if (!BEG_STRCASECMP(line, "carved")) { - if (n != 3) { - return 0; - } - color = get_word(2, line); - p = get_color_by_name(color, "black"); - set_shadow_color_by_pixel(SHADOW_TOP_LEFT, p); - FREE(color); - - color = get_word(3, line); - p = get_color_by_name(color, "white"); - set_shadow_color_by_pixel(SHADOW_BOTTOM_RIGHT, p); - FREE(color); - } else { - unsigned char i; - - for (i = 0; i < 4; i++) { - which = get_corner(line); - if (which >= 4) { - which = i; - color = get_word(1, line); - line = get_pword(2, line); - } else { + if (!BEG_STRCASECMP(line, "none")) { + MEMSET(&fshadow, 0, sizeof(fontshadow_t)); + } else if (!BEG_STRCASECMP(line, "outline")) { + if (n != 2) { + return 0; + } color = get_word(2, line); - line = get_pword(3, line); - } - set_shadow_color_by_name(which, color); - FREE(color); - if (line == NULL) { - break; - } + p = get_color_by_name(color, "black"); + FREE(color); + for (which = 0; which < 4; which++) { + set_shadow_color_by_pixel(which, p); + } + } else if (!BEG_STRCASECMP(line, "shadow")) { + if (n == 2) { + which = SHADOW_BOTTOM_RIGHT; + color = get_word(2, line); + } else if (n == 3) { + color = get_word(3, line); + corner = get_pword(2, line); + which = get_corner(corner); + if (which >= 4) { + return 0; + } + } else { + return 0; + } + set_shadow_color_by_name(which, color); + FREE(color); + } else if (!BEG_STRCASECMP(line, "emboss")) { + if (n != 3) { + return 0; + } + color = get_word(2, line); + p = get_color_by_name(color, "black"); + set_shadow_color_by_pixel(SHADOW_BOTTOM_RIGHT, p); + FREE(color); + + color = get_word(3, line); + p = get_color_by_name(color, "white"); + set_shadow_color_by_pixel(SHADOW_TOP_LEFT, p); + FREE(color); + } else if (!BEG_STRCASECMP(line, "carved")) { + if (n != 3) { + return 0; + } + color = get_word(2, line); + p = get_color_by_name(color, "black"); + set_shadow_color_by_pixel(SHADOW_TOP_LEFT, p); + FREE(color); + + color = get_word(3, line); + p = get_color_by_name(color, "white"); + set_shadow_color_by_pixel(SHADOW_BOTTOM_RIGHT, p); + FREE(color); + } else { + unsigned char i; + + for (i = 0; i < 4; i++) { + which = get_corner(line); + if (which >= 4) { + which = i; + color = get_word(1, line); + line = get_pword(2, line); + } else { + color = get_word(2, line); + line = get_pword(3, line); + } + set_shadow_color_by_name(which, color); + FREE(color); + if (line == NULL) { + break; + } + } } - } - return 1; + return 1; } diff --git a/src/grkelot.c b/src/grkelot.c index 494ea38..6edf51a 100644 --- a/src/grkelot.c +++ b/src/grkelot.c @@ -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 diff --git a/src/libscream.c b/src/libscream.c new file mode 100644 index 0000000..af84996 --- /dev/null +++ b/src/libscream.c @@ -0,0 +1,1183 @@ +/**************************************************************************** + * scream::libscream.c + * routines to connect to screen and or scream daemons. + * GNU Public Licence applies. + * 2002/04/19 Azundris incept + * 2002/05/04 Azundris support for esoteric screens, thanks to Till + ***************************************************************************/ + + + +#include /* stderr, fprintf, snprintf() */ +#include /* bzero() */ +#include /* getpwuid() */ +#include /* getpwuid() */ +#include /* getuid() */ +#include /* atoi() */ +#include /* getservbyname() */ +#include /* ntohs() */ +#include /* PATH_MAX */ + +#include "scream.h" /* structs, defs, headers */ +#include "screamcfg.h" /* user-tunables */ + +#ifndef MAXPATHLEN +# ifdef PATH_MAX +# define MAXPATHLEN PATH_MAX +# elif defined(MAX_PATHLEN) +# define MAXPATHLEN MAX_PATHLEN +# endif +#endif + + + +long err_inhibit = 0; /* bits. avoid telling user the same thing twice. */ + + + +/***************************************************************************/ +/* constructors/destructors */ +/****************************/ + + + +_ns_efuns * +ns_new_efuns(void) +{ + _ns_efuns *s = malloc(sizeof(_ns_efuns)); + if (s) { + bzero(s, sizeof(_ns_efuns)); + } + return s; +} + +_ns_efuns * +ns_ref_efuns(_ns_efuns ** ss) +{ + if (ss && *ss) { + (*ss)->refcount++; + return *ss; + } + return NULL; +} + +_ns_efuns * +ns_dst_efuns(_ns_efuns ** ss) +{ + if (ss && *ss) { + _ns_efuns *s = *ss; +#ifdef NS_DEBUG_MEM + *ss = NULL; +#endif + if (!--(s->refcount)) { +#ifdef NS_DEBUG_MEM + bzero(s, sizeof(_ns_efuns)); +#endif + free(s); + } + } + return NULL; +} + + + +_ns_disp * +ns_new_disp(void) +{ + _ns_disp *s = malloc(sizeof(_ns_disp)); + if (s) { + bzero(s, sizeof(_ns_disp)); + } + return s; +} + +_ns_disp * +ns_dst_disp(_ns_disp ** ss) +{ + if (ss && *ss) { + _ns_disp *s = *ss; + if (s->name) + free(s->name); + if (s->efuns) + ns_dst_efuns(&(s->efuns)); +#ifdef NS_DEBUG_MEM + *ss = NULL; + bzero(s, sizeof(_ns_disp)); +#endif + free(s); + } + return NULL; +} + +_ns_disp * +ns_dst_dsps(_ns_disp ** ss) +{ + if (ss && *ss) { + _ns_disp *s = *ss, *t; +#ifdef NS_DEBUG_MEM + *ss = NULL; +#endif + do { + t = s->next; + ns_dst_disp(&s); + s = t; + } while (s); + return NULL; + } +} + + + +_ns_sess * +ns_new_sess(void) +{ + _ns_sess *s = malloc(sizeof(_ns_sess)); + if (s) { + bzero(s, sizeof(_ns_sess)); + s->escape = NS_SCREEN_ESCAPE; /* default setup for the screen program */ + s->literal = NS_SCREEN_LITERAL; + } + return s; +} + +_ns_sess * +ns_dst_sess(_ns_sess ** ss) +{ + if (ss && *ss) { + _ns_sess *s = *ss; + ns_dst_dsps(&(s->dsps)); + if (s->host) + free(s->host); + if (s->user) + free(s->user); + if (s->pass) + free(s->pass); + if (s->efuns) + ns_dst_efuns(&(s->efuns)); +#ifdef NS_DEBUG_MEM + *ss = NULL; + bzero(s, sizeof(_ns_sess)); +#endif + free(s); + } + return NULL; +} + + + + +/***************************************************************************/ +/* send commands to screen */ +/***************************/ + + + +/* send a command string to a session, using the appropriate escape-char + sess the session + cmd the command string. escapes must be coded as NS_SCREEN_ESCAPE; + this routine will convert the string to use the escapes actually + used in the session + <- error code */ + +int +ns_screen_command(_ns_sess * sess, char *cmd) +{ + char *c; + int ret = NS_SUCC; + if (sess->efuns->inp_text) { + if ((c = strdup(cmd))) { + char *p = c; + while (*p) { + if (*p == NS_SCREEN_ESCAPE) /* replace default escape-char with that */ + *p = sess->escape; /* actually used in this session */ + p++; + } + sess->efuns->inp_text(NULL, sess->fd, c); + free(c); + } else + ret = NS_OOM; + } /* out of memory */ + else { + ret = NS_EFUN_NOT_SET; + fprintf(stderr, "ns_screen_command: sess->efuns->inp_text not set!\n"); + } + return ret; +} + + + +/* scroll horizontally to column x (dummy) */ +int +ns_scroll2x(_ns_sess * s, int x) +{ + return NS_FAIL; +} + +/* scroll vertically so line y of the scrollback buffer is the top line */ +int +ns_scroll2y(_ns_sess * s, int y) +{ + return NS_FAIL; +} + +/* go to display #d */ +int +ns_go2_disp(_ns_sess * s, int d) +{ + return NS_FAIL; +} + +/* add a client display with the name "name" after display number #after */ +int +ns_add_disp(_ns_sess * s, int after, char *name) +{ + return NS_FAIL; +} + +/* resize display #d to w*h */ +int +ns_rsz_disp(_ns_sess * s, int d, int w, int h) +{ + return NS_FAIL; +} + +/* remove display #d */ +int +ns_rem_disp(_ns_sess * s, int d) +{ + return NS_FAIL; +} + +/* rename display #d to "name" */ +int +ns_ren_disp(_ns_sess * s, int d, char *name) +{ + return NS_FAIL; +} + +/* log activity in display #d to file "logfile" */ +int +ns_log_disp(_ns_sess * s, int d, char *logfile) +{ + return NS_FAIL; +} + +/* force an update of the status line */ +int +ns_upd_stat(_ns_sess * s) +{ + return ns_screen_command(s, NS_SCREEN_UPDATE); +} + + + +/***************************************************************************/ +/* attach/detach */ +/*****************/ + + + + + +/* return port number for service SSH (secure shell). + <- a port number -- 22 in all likelihood. + */ +int +get_ssh_port(void) +{ + /* (fixme) replace with getservbyname_r on systems that have it */ + struct servent *srv = getservbyname("ssh", "tcp"); + return srv ? ntohs(srv->s_port) : NS_DFLT_SSH_PORT; +} + + + +/* ns_desc_sess + print basic info about a session. mostly for debugging. + sess: a session struct as generated by (eg) ns_attach_by_URL() + doc: info about the context + ! stdout: info about the session +*/ + +void +ns_desc_sess(_ns_sess * sess, char *doc) +{ + if (!sess) { + fprintf(stderr, "%s: ns_desc_sess called with broken pointer!\n", doc); + return; + } + if (sess->where == NS_LCL) + fprintf(stderr, "%s: (efuns@%p)\t (user %s) local %s ", doc, sess->efuns, sess->user, sess->proto); + else { + fprintf(stderr, "%s: (efuns@%p)\t %s://%s%s%s@%s", + doc, sess->efuns, sess->proto, sess->user, sess->pass ? ":" : "", sess->pass ? sess->pass : "", sess->host); + if (sess->port != NS_DFLT_SSH_PORT) + fprintf(stderr, ":%s", sess->port); + } + fprintf(stderr, "/%s\n", sess->rsrc); +} + + + +/* run a command. uses the terminal's internal run facility. + converts system/"char *" to exec/"arg **". + efuns: struct of callbacks into the terminal program. + ns_run() will fail if no callback to the terminal's "run program" + (exec) facility is provided. + cmd: a string to exec + <- whatever the callback returns. In Eterm, it's a file-descriptor. + */ +int +ns_run(_ns_efuns * efuns, char *cmd) +{ + char **args = NULL; + char *p = cmd; + int c, n = 0, s = 0; + + if (!efuns || !efuns->execute) + goto fail; + + if (cmd && *cmd) { /* count args (if any) */ +#ifdef NS_DEBUG + fprintf(stderr, "ns_run: executing \"%s\"...\n", cmd); +#endif + do { + n++; + while (*p && *p != ' ') { + if (*p == '\"') { + do { + p++; + if (s) + s = 0; + else if (*p == '\\') + s = 1; + else if (*p == '\"') + s = 2; + } + while (*p && s != 2); + } + p++; + } + while (*p == ' ') + p++; + } + while (*p); + + if (!(args = malloc((n + 2) * sizeof(char *)))) + goto fail; + + for (p = cmd, c = 0; c < n; c++) { + args[c] = p; + while (*p && *p != ' ') { + if (*p == '\"') { /* leave quoting stuff together as one arg */ + args[c] = &p[1]; /* but remove the quote signs */ + do { + p++; + if (s) + s = 0; + else if (*p == '\\') + s = 1; + else if (*p == '\"') + s = 2; + } + while (*p && s != 2); + *p = '\0'; + } + p++; + } + while (*p == ' ') + *(p++) = '\0'; + } + args[c++] = NULL; + } + + n = efuns->execute(NULL, args); + if (args) + free(args); + return n; + + fail: + return NS_FAIL; +} + + + +/* attach a local session (using screen/scream) + sp the session + <- NS_FAIL, or the result of ns_run() */ + +int +ns_attach_lcl(_ns_sess ** sp) +{ + _ns_sess *sess; +#define MAXCMD 512 + char cmd[MAXCMD + 1]; + int ret; + + if (!sp || !*sp) + return NS_FAIL; + sess = *sp; + ret = snprintf(cmd, MAXCMD, "%s %s", NS_SCREEN_CALL, NS_SCREEN_OPTS); + return (ret < 0 || ret > MAXCMD) ? NS_FAIL : ns_run(sess->efuns, cmd); +} + + + +/* attach a remote session (using screen/scream via ssh) + sp the session + <- NS_FAIL, or the result of ns_run() */ + +int +ns_attach_ssh(_ns_sess ** sp) +{ + _ns_sess *sess; + char cmd[MAXCMD + 1]; + int ret; + + if (!sp || !*sp) + return NS_FAIL; + sess = *sp; + ret = snprintf(cmd, MAXCMD, "%s %s -p %d %s@%s %s", NS_SSH_CALL, NS_SSH_OPTS, sess->port, sess->user, sess->host, NS_SCREEM_CALL); + return (ret < 0 || ret > MAXCMD) ? NS_FAIL : ns_run(sess->efuns, cmd); +} + + + +/* ns_attach_by_sess + attach/create a scream/screen session, locally or over the net. + sess: a session struct as generated by (eg) ns_attach_by_URL() + ! err: if non-NULL, variable pointed at will contain an error status + <- the requested session, or NULL in case of failure. + a session thus returned must be detached/closed later. +*/ + +_ns_sess * +ns_attach_by_sess(_ns_sess ** sp, int *err) +{ + _ns_sess *sess; + int err_dummy; + char *p; + + if (!err) + err = &err_dummy; + *err = NS_INVALID_SESS; + + if (!sp || !*sp) + return NULL; + sess = *sp; + +#ifdef NS_DEBUG + ns_desc_sess(sess, "ns_attach_by_sess()"); +#endif + + switch (sess->where) { + case NS_LCL: + sess->fd = ns_attach_lcl(&sess); + break; + case NS_SU: /* (fixme) uses ssh, should use su */ + /* local session, but for a different uid. */ + /* FALL-THROUGH */ + case NS_SSH: + sess->fd = ns_attach_ssh(&sess); + break; + default: + *err = NS_UNKNOWN_LOC; + goto fail; + } + +#ifdef NS_DEBUG + fprintf(stderr, "screen session-fd is %d\n", sess->fd); +#endif + + (void) ns_screen_command(sess, NS_SCREEN_INIT); + + return sess; + + fail: + return ns_dst_sess(sp); +} + + + +/* ns_attach_by_URL + parse URL into sess struct (with sensible defaults), then pick up/create + said session using ns_attach_by_sess() + url: URL to create/pick up a session at. + proto://user:password@host.domain:port (all parts optional) + NULL/empty string equivalent to + screen://current_user@localhost/-xRR + ef: a struct containing callbacks into client (resize scrollbars etc.) + while setting those callbacks is optional; omitting the struct + itself seems unwise. + ! err: if non-NULL, variable pointed at will contain an error status + xd: pointer to extra-data the terminal app wants to associate with + a session, or NULL + <- the requested session, or NULL in case of failure. + a session thus returned must be detached/closed later. +*/ + +_ns_sess * +ns_attach_by_URL(char *url, _ns_efuns ** ef, int *err, void *xd) +{ + int err_dummy; + char *p; + _ns_sess *sess = ns_new_sess(); + struct passwd *pwe = getpwuid(getuid()); + + if (!err) + err = &err_dummy; + *err = NS_OOM; + + if (!sess) + return NULL; + + if (url && strlen(url)) { + char *q, *d; + + if (!(d = strdup(url))) + goto fail; + + if ((q = strstr(d, "://"))) { /* protocol, if any */ + *q = '\0'; + if (!(sess->proto = strdup(d))) + goto fail; + q += 3; + } else + q = d; + + if ((p = strchr(q, '@'))) { /* user, if any */ + char *r; + if (p != q) { /* ignore empty user */ + *p = '\0'; + if ((r = strchr(q, ':'))) { /* password, if any */ + *(r++) = '\0'; + if (!(sess->pass = strdup(r))) /* password may be empty string! */ + goto fail; + } + sess->user = strdup(q); + } + q = p + 1; + } + + if ((p = strchr(q, ':'))) { /* port, if any */ + *(p++) = '\0'; + if (!*p || !(sess->port = atoi(p)) || sess->port > NS_MAX_PORT) { + *err = NS_MALFORMED_URL; + goto fail; + } + } + + if (strlen(q) && !(sess->host = strdup(q))) /* host, if any */ + goto fail; + + free(d); + } + + sess->where = NS_SSH; + + if (!sess->user) { /* default user (current user) */ + if (!pwe) { + *err = NS_UNKNOWN_USER; + goto fail; + } + if (!(sess->user = strdup(pwe->pw_name))) + goto fail; + } else if (pwe && strcmp(pwe->pw_name, sess->user)) { /* user!=current_user */ + sess->where = NS_SU; + } + + if (!sess->host) { /* no host */ + if (!(sess->host = strdup("localhost"))) + goto fail; + if (!sess->port) { /* no host/port */ + sess->where = NS_LCL; + } + } else if ((p = strchr(sess->host, '/'))) /* have host */ + *p = '\0'; + + if (!sess->port) /* no port -> default port (SSH) */ + sess->port = get_ssh_port(); + + sess->backend = NS_MODE_NEGOTIATE; + if (!sess->proto) { + if (!(sess->proto = strdup("scream"))) + goto fail; + } else if (!strcmp(sess->proto, "screen")) + sess->backend = NS_MODE_SCREEN; + else if (!strcmp(sess->proto, "scream")) + sess->backend = NS_MODE_SCREAM; + else { + *err = NS_UNKNOWN_PROTO; + goto fail; + } + + if (!sess->efuns && ef && *ef) { + sess->efuns = ns_ref_efuns(ef); + } + + sess->userdef = xd; + + *err = NS_SUCC; + return ns_attach_by_sess(&sess, err); + + fail: + return ns_dst_sess(&sess); +} + + + +/* detach a session and release its memory + sess the session + <- error code */ +int +ns_detach(_ns_sess ** sess) +{ + ns_desc_sess(*sess, "ns_detach"); + (void) ns_dst_sess(sess); + return NS_SUCC; +} + + + +/***************************************************************************/ +/* messages to the client */ +/* (register callbacks) */ +/**************************/ + + + +/* function that moves horizontal scrollbar to x/1000 % of width */ +void +ns_register_ssx(_ns_efuns * efuns, int (*set_scroll_x) (void *, int)) +{ + efuns->set_scroll_x = set_scroll_x; +} + +/* function that moves vertical scrollbar to y/1000 % of height */ +void +ns_register_ssy(_ns_efuns * efuns, int (*set_scroll_y) (void *, int)) +{ + efuns->set_scroll_y = set_scroll_y; +} + +/* function that sets horizontal scrollbar to w/1000 % of width */ +void +ns_register_ssw(_ns_efuns * efuns, int (*set_scroll_w) (void *, int)) +{ + efuns->set_scroll_w = set_scroll_w; +} + +/* function that sets vertical scrollbar to h/1000 % of height */ +void +ns_register_ssh(_ns_efuns * efuns, int (*set_scroll_h) (void *, int)) +{ + efuns->set_scroll_h = set_scroll_h; +} + +/* function that redraws the terminal */ +void +ns_register_red(_ns_efuns * efuns, int (*redraw) (void *)) +{ + efuns->redraw = redraw; +} + +/* function that redraw part of the terminal */ +void +ns_register_rda(_ns_efuns * efuns, int (*redraw_xywh) (void *, int, int, int, int)) +{ + efuns->redraw_xywh = redraw_xywh; +} + +/* function to call when a new client was added ("add tab"). + after denotes the index of the button after which this one should + be inserted (0..n, 0 denoting "make it the first button") */ +void +ns_register_ins(_ns_efuns * efuns, int (*ins_disp) (void *, int, char *)) +{ + efuns->ins_disp = ins_disp; +} + +/* function to call when a client was closed ("remove tab") */ +void +ns_register_del(_ns_efuns * efuns, int (*del_disp) (void *, int)) +{ + efuns->del_disp = del_disp; +} + +/* function to call when a client's title was changed ("update tab") */ +void +ns_register_upd(_ns_efuns * efuns, int (*upd_disp) (void *, int, int, char *)) +{ + efuns->upd_disp = upd_disp; +} + +/* function to pass status lines to */ +void +ns_register_err(_ns_efuns * efuns, int (*err_msg) (void *, int, char *)) +{ + efuns->err_msg = err_msg; +} + +/* function that will execute client programs (in pseudo-terminal et al) */ +void +ns_register_exe(_ns_efuns * efuns, int (*execute) (void *, char **)) +{ + efuns->execute = execute; +} + +/* function that will hand text as input to the client */ +void +ns_register_txt(_ns_efuns * efuns, int (*inp_text) (void *, int, char *)) +{ + efuns->inp_text = inp_text; +} + + + +/* get callbacks. at least one of session and display must be non-NULL. + s session, or NULL. if NULL, will be initialized from d->sess + d display, or NULL. if NULL, will be initialized from s->curr. + if set, will override session callbacks; + note that NULL pointers in d->efuns *will* + override (disable) non-NULL pointers in s->efuns! + <- callback-struct */ + +_ns_efuns * +ns_get_efuns(_ns_sess * s, _ns_disp * d) +{ + if (!s) { + if (!d || !d->sess) + return NULL; + else + s = d->sess; + } + if (!d) + d = s->curr; + if (d && d->efuns) + return d->efuns; + else + return s->efuns; +} + + + +/* test if we have a valid callback for function-type "e". + !p a variable of the "_ns_efuns *" type. will contain a pointer to + an efun struct containing a function pointer to the requested function + if such a struct exists, or NULL, if it doesn't exist + s a variable of the "_ns_sess *" type, or NULL (see ns_get_efuns()) + d a variable of the "_nd_disp *" type, or NULL (see ns_get_efuns()) + e the name of an element of "_ns_efuns" + !<- conditional execution of next (compound-) statement (which would + normally be (p)->(e)(...), the call of the function e). + */ +#define NS_IF_EFUN_EXISTS(p,s,d,e) if(((p)=ns_get_efuns((s),(d)))&&((p)->e)) + + + +/***************************************************************************/ +/* display-handling */ +/********************/ + + + +/* we need a certain display struct (index n in session s). + give it to us if it exists. + s the session the display should be in + n the index of the display (>=0). displays in a session are sorted + by index, but may be sparse (0, 1, 3, 7) + <- the requested display */ + +_ns_disp * +disp_fetch(_ns_sess * s, int n) +{ + _ns_disp *d, *e = NULL, *c; + + for (c = s->dsps; c && (c->index < n); c = c->next) + e = c; + if (c && (c->index == n)) /* found it */ + return c; + return NULL; +} + + + +/* we need a certain display struct (index n in session s). + give it to us. if you can't find it, make one up and insert it into + the list. + s the session the display should be in + n the index of the display (>=0). displays in a session are sorted + by index, but may be sparse (0, 1, 3, 7) + <- the requested display */ + +_ns_disp * +disp_fetch_or_make(_ns_sess * s, int n) +{ + _ns_disp *d, *e = NULL, *c; + + for (c = s->dsps; c && (c->index < n); c = c->next) + e = c; + + if (c && (c->index == n)) /* found it */ + return c; + + if (!(d = ns_new_disp())) /* not there, create new */ + return NULL; /* can't create, fail */ + + d->index = n; + + if ((d->next = c)) /* if not last element... */ + c->prvs = d; + if ((d->prvs = e)) /* if not first element */ + e->next = d; + else /* make first */ + s->dsps = d; + + d->sess = s; /* note session on display */ + +#if 1 + if (!d->sess->curr) /* note as current on session if first display */ + d->sess->curr = d; +#endif + + return d; +} + + + +/* get element number from screen-index (latter is sparse, former ain't) + screen the session in question + n the index screen gave us (sparse) + <- the real index (element number in our list of displays) */ + +int +disp_get_real_by_screen(_ns_sess * screen, int n) +{ + _ns_disp *d2 = screen->dsps; + int r = 0; + while (d2 && d2->index != n) { + d2 = d2->next; + r++; + } +#ifdef NS_DEBUG + if (!d2) + return -1; +#endif + return r; +} + + + +/* get screen-index from element number (former is sparse, latter ain't) + screen the session in question + n the real index (element number in our list of displays) + <- the index screen knows (sparse) */ + +int +disp_get_screen_by_real(_ns_sess * screen, int r) +{ + _ns_disp *d2 = screen->dsps; + while (d2 && (r-- > 0)) + d2 = d2->next; +#ifdef NS_DEBUG + if (!d2) + return -1; +#endif + return d2->index; +} + + + +/* remove a display from the internal list and release its struct and data + disp the display in question */ + +void +disp_kill(_ns_disp * d3) +{ + if (d3->prvs) { + d3->prvs->next = d3->next; + if (d3->sess->curr == d3) + d3->sess->curr = d3->prvs; + } else { + d3->sess->dsps = d3->next; + if (d3->sess->curr == d3) + d3->sess->curr = d3->next; + } + if (d3->next) + d3->next->prvs = d3->prvs; + ns_dst_disp(&d3); +} + + + +/***************************************************************************/ +/* parse status lines of the "screen" program */ +/**********************************************/ + + + +/* parse a message (not a display-list) set by the "screen" program + screen the session associated with that instance of screen, + as returned by ns_attach_by_URL() and related. + the session must contain a valid struct of callbacks (efuns), + as certain functionalities ("add a tab", "show status message") + may be called from here. + p the offending message-line + <- returns an error code. */ + +int +parse_screen_msg(_ns_sess * screen, char *p) +{ + _ns_efuns *efuns; + _ns_disp *disp; + char *p2; + int n, ret = NS_SUCC, type = (strlen(p) > 1) ? NS_SCREEN_STATUS : NS_SCREEN_ST_CLR; + + /* a screen display can disappear because the program in it dies, or + because we explicitly ask screen to kill the display. in the latter + case, screen messages upon success. rather than explicitly killing + the disp-struct here, we force a status-line update instead (in which + the status-line checker will notice the disp has gone, and delete it + from the struct-list). this way, we won't need to duplicate the + delete-logic here. */ + if (sscanf(p, "Window %d (%s) killed.", &n, p2) == 2) { + size_t x = strlen(p2); + ret = ns_upd_stat(screen); + } else { /* ignoble message */ + NS_IF_EFUN_EXISTS(efuns, screen, NULL, err_msg) + ret = efuns->err_msg(NULL, type, (type == NS_SCREEN_STATUS) ? p : ""); + } + return ret; +} + + + +/* parse the "hardstatus"-line of screens. + this is, and unfortunately has to be, a ton of heuristics. + I'm pretty sure there will be (esoteric) situations that are not handled + (correctly) by this code, particularly in connection with more sessions + than can be enumerated in the status-line (we do have workarounds for + that case, they're just not very well tested yet). + do not touch this unless you are absolutely sure you know what you're + doing. 2002/05/01 Azundris + + screen the session associated with that instance of screen, + as returned by ns_attach_by_URL() and related. + the session must contain a valid struct of callbacks (efuns), + as certain functionalities ("add a tab", "show status message") + may be called from here. + force the terminal wants us to update. if it doesn't, we may see + fit to do so anyway in certain cases. + width the terminal's width in columns (== that of the status line) + p the pointer to the status line. may point into the terminal's + line buffer if that holds plain text data (not interleaved with + colour- and boldness-data) + <- returns an error code. */ + +int +parse_screen(_ns_sess * screen, int force, int width, char *p) +{ + char *p4, *p3, *p2; /* pointers for parser magic */ + static const char *p5 = NS_SCREEN_FLAGS; + static size_t l = sizeof(NS_SCREEN_FLAGS); +#if (NS_SCREEN_UPD_FREQ>0) + static time_t t = 0; + time_t t2 = time(NULL); +#endif + int ret = NS_SUCC, tmp, status_blanks = 0, /* status-bar overflow? */ + parsed, /* no of *visible* elements in status line */ + n, /* screen's index (immutable, sparse) */ + r; /* real index (r'th element) */ + _ns_efuns *efuns; + _ns_disp *disp = NULL, *d2 = NULL; + + if (!p) + return NS_FAIL; + + if (!force) + return NS_SUCC; + +#if (NS_SCREEN_UPD_FREQ>0) + if ((t2 - t) > NS_SCREEN_UPD_FREQ) { + (void) ns_upd_stat(screen); + t = t2; + } +#endif + + if (p = strdup(p)) { + _ns_parse pd[NS_MAX_DISPS]; + p2 = &p[width - 1]; + while (p2 > p && *p2 == ' ') { + status_blanks++; + *(p2--) = '\0'; + } /* p2 now points behind last item */ + +#ifdef NS_DEBUG + fprintf(stderr, "::%s::\n", p); +#endif + +#ifdef NS_PARANOID_ + if (strlen(p) < 2) { /* special case: display 0 */ + disp = screen->dsps; /* might not get a status-line in d0! */ + if (disp && !(disp->flags & NS_SCREAM_CURR)) { /* flags need updating */ + disp->flags |= NS_SCREAM_CURR; /* set flag to avoid calling inp_text */ + ret = ns_upd_stat(screen); + } /* more thn once */ + free(p); + return ret; + } +#endif + + p3 = p; + while (isspace(*p3)) /* skip left padding */ + p3++; + + if (isdigit(*p3)) { /* list of displays */ + parsed = r = 0; + do { + n = atoi(p3); + pd[parsed].name = NULL; + pd[parsed].screen = n; + pd[parsed].real = r++; + + while (isdigit(*p3)) /* skip index */ + p3++; + + pd[parsed].flags = 0; /* get and skip flags */ + while (*p3 && *p3 != ' ') { + for (n = 0; n < l; n++) { + if (*p3 == p5[n]) { + pd[parsed].flags |= (1 << n); + break; + } + } + p3++; + } + + if (*p3 == ' ') { /* skip space, read name */ + *(p3++) = '\0'; + p4 = p3; + while (p3[0] && p3[1] && (p3[0] != ' ' || p3[1] != ' ')) + p3++; + if (p3[0] == ' ') { + *(p3++) = '\0'; + while (isspace(*p3)) + p3++; + } + pd[parsed++].name = p4; + if (parsed >= NS_MAX_DISPS) + p3 = &p3[strlen(p3)]; + } /* out of mem => skip remainder */ + else + p3 = &p3[strlen(p3)]; /* weirdness => skip remainder */ + } while (*p3); + +#ifdef NS_DEBUG + for (r = 0; r < parsed; r++) + if (pd[r].name) + printf("%d(%d/%d,%s) ", r, pd[r].screen, pd[r].real, pd[r].name); + puts("\n"); +#endif + + for (r = 0; r < parsed; r++) { + n = pd[r].screen; + disp = disp_fetch(screen, n); + + if (!disp) { /* new display */ + if (!(disp = disp_fetch_or_make(screen, n)) || !(disp->name = strdup(pd[r].name))) { + fprintf(stderr, "out of memory in parse_screen::new_display(%d)\n", n); + ret = NS_FAIL; + } else { + NS_IF_EFUN_EXISTS(efuns, screen, NULL, ins_disp) + ret = efuns->ins_disp(screen->userdef, pd[r].real - 1, disp->name); + } + } else if ((tmp = strcmp(disp->name, pd[r].name)) || /* upd display */ + (disp->flags != pd[r].flags)) { + if (tmp) { + free(disp->name); + if (!(disp->name = strdup(pd[r].name))) { + free(p); + return NS_FAIL; + } + } + if (pd[r].flags & NS_SCREAM_CURR) + disp->sess->curr = disp; + disp->flags = pd[r].flags & NS_SCREAM_MASK; + NS_IF_EFUN_EXISTS(efuns, screen, NULL, upd_disp) + ret = efuns->upd_disp(screen->userdef, r, disp->flags, disp->name); + } + + /* remove any displays from list that have disappeared + from the middle of the status-line */ + if (!d2 || d2->next != disp) { /* remove expired displays */ + _ns_disp *d3 = disp->prvs, *d4; + while (d3 && d3 != d2) { +#ifdef NS_DEBUG + fprintf(stderr, "remove expired middle %d \"%s\"...\n", d3->index, d3->name); +#endif + d4 = d3->prvs; + NS_IF_EFUN_EXISTS(efuns, screen, NULL, del_disp) + ret = efuns->del_disp(screen->userdef, disp_get_real_by_screen(screen, d3->index)); + disp_kill(d3); + d3 = d4; + } + if (!d2) + ns_upd_stat(screen); + } + d2 = disp; + } + + + +#ifdef NS_PARANOID + if (!r) { +# ifdef NS_DEBUG + if (!(err_inhibit & NS_ERR_WEIRDSCREEN)) { + err_inhibit |= NS_ERR_WEIRDSCREEN; + fprintf(stderr, "libscream::parse_screen() d2==NULL\n" + "This should never happen. It is assumed that you use a\n" + "rather unusual configuration for \"screen\". Please\n" + "send the result of 'screen --version' to \n" + "(together with your ~/.screenrc and /etc/screenrc if present).\n" + "If at all possible, please also run 'Eterm -e screen' and make\n" + "a screenshot of the offending window (and the window only, the\n" + "beauty of your desktop is not relevant to this investigation. : ).\n"); + } +# endif + ret = ns_upd_stat(screen); + free(p); + return NS_FAIL; + } else +#endif + /* kill overhang (o/t right) if status-line isn't side-scrolling + (as it will if not all the disp names fit in the status-line) */ + if (disp->next && status_blanks > (strlen(disp->next->name) + 6)) { + _ns_disp *d3 = disp; + for (disp = disp->next; disp;) { +#ifdef NS_DEBUG + fprintf(stderr, "remove expired right %d \"%s\"...\n", disp->index, disp->name); +#endif + d2 = disp; + if (d2->sess->curr == d2) + d2->sess->curr = d3; + disp = disp->next; + NS_IF_EFUN_EXISTS(efuns, screen, NULL, del_disp) + ret = efuns->del_disp(screen->userdef, disp_get_real_by_screen(screen, d2->index)); + disp_kill(d2); + } + d3->next = NULL; + } + } + + else /* not a list of displays, but a message. handle separately. */ + ret = parse_screen_msg(screen, p); + + free(p); + } + /* release our (modified) copy of the status-line */ + return ret; +} + + + +/***************************************************************************/ diff --git a/src/main.c b/src/main.c index 9bab00d..e4a8d0a 100644 --- a/src/main.c +++ b/src/main.c @@ -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)); } diff --git a/src/menus.c b/src/menus.c index 73bb83b..838acca 100644 --- a/src/menus.c +++ b/src/menus.c @@ -60,100 +60,100 @@ static inline void grab_pointer(Window win) { - int success; + int success; - D_EVENTS(("Grabbing control of pointer for window 0x%08x.\n", win)); - success = XGrabPointer(Xdisplay, win, False, - EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask - | Button1MotionMask | Button2MotionMask | Button3MotionMask, - GrabModeAsync, GrabModeAsync, None, None, CurrentTime); - if (success != GrabSuccess) { - switch (success) { - case GrabNotViewable: - D_MENU((" -> Unable to grab pointer -- Grab window is not viewable.\n")); - break; - case AlreadyGrabbed: - D_MENU((" -> Unable to grab pointer -- Pointer is already grabbed by another client.\n")); - break; - case GrabFrozen: - D_MENU((" -> Unable to grab pointer -- Pointer is frozen by another grab.\n")); - break; - case GrabInvalidTime: - D_MENU((" -> Unable to grab pointer -- Invalid grab time.\n")); - break; - default: - break; + D_EVENTS(("Grabbing control of pointer for window 0x%08x.\n", win)); + success = XGrabPointer(Xdisplay, win, False, + EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask + | Button1MotionMask | Button2MotionMask | Button3MotionMask, + GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + if (success != GrabSuccess) { + switch (success) { + case GrabNotViewable: + D_MENU((" -> Unable to grab pointer -- Grab window is not viewable.\n")); + break; + case AlreadyGrabbed: + D_MENU((" -> Unable to grab pointer -- Pointer is already grabbed by another client.\n")); + break; + case GrabFrozen: + D_MENU((" -> Unable to grab pointer -- Pointer is frozen by another grab.\n")); + break; + case GrabInvalidTime: + D_MENU((" -> Unable to grab pointer -- Invalid grab time.\n")); + break; + default: + break; + } } - } } static inline void ungrab_pointer(void) { - D_EVENTS(("Releasing pointer grab.\n")); - XUngrabPointer(Xdisplay, CurrentTime); + D_EVENTS(("Releasing pointer grab.\n")); + XUngrabPointer(Xdisplay, CurrentTime); } static inline void draw_string(Drawable d, GC gc, int x, int y, char *str, size_t len) { - D_MENU(("Writing string \"%s\" (length %lu) onto drawable 0x%08x at %d, %d\n", str, len, d, x, y)); + D_MENU(("Writing string \"%s\" (length %lu) onto drawable 0x%08x at %d, %d\n", str, len, d, x, y)); #ifdef MULTI_CHARSET - if (current_menu && current_menu->fontset && encoding_method != LATIN1) - XmbDrawString(Xdisplay, d, current_menu->fontset, gc, x, y, str, len); - else + if (current_menu && current_menu->fontset && encoding_method != LATIN1) + XmbDrawString(Xdisplay, d, current_menu->fontset, gc, x, y, str, len); + else #endif - XDrawString(Xdisplay, d, gc, x, y, str, len); + XDrawString(Xdisplay, d, gc, x, y, str, len); } static inline unsigned short center_coords(register unsigned short c1, register unsigned short c2) { - return (((c2 - c1) >> 1) + c1); + return (((c2 - c1) >> 1) + c1); } void menu_init(void) { - XGCValues gcvalue; + XGCValues gcvalue; - if (!menu_list || menu_list->nummenus == 0) { - return; - } - gcvalue.foreground = PixColors[menuTopShadowColor]; - topShadowGC = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); - gcvalue.foreground = PixColors[menuBottomShadowColor]; - botShadowGC = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); + if (!menu_list || menu_list->nummenus == 0) { + return; + } + gcvalue.foreground = PixColors[menuTopShadowColor]; + topShadowGC = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); + gcvalue.foreground = PixColors[menuBottomShadowColor]; + botShadowGC = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); - event_register_dispatcher(menu_dispatch_event, menu_event_init_dispatcher); + event_register_dispatcher(menu_dispatch_event, menu_event_init_dispatcher); } void menu_event_init_dispatcher(void) { - register unsigned char i; + register unsigned char i; - EVENT_DATA_ADD_HANDLER(menu_event_data, EnterNotify, menu_handle_enter_notify); - EVENT_DATA_ADD_HANDLER(menu_event_data, LeaveNotify, menu_handle_leave_notify); + EVENT_DATA_ADD_HANDLER(menu_event_data, EnterNotify, menu_handle_enter_notify); + EVENT_DATA_ADD_HANDLER(menu_event_data, LeaveNotify, menu_handle_leave_notify); #if 0 - EVENT_DATA_ADD_HANDLER(menu_event_data, GraphicsExpose, menu_handle_expose); - EVENT_DATA_ADD_HANDLER(menu_event_data, Expose, menu_handle_expose); + EVENT_DATA_ADD_HANDLER(menu_event_data, GraphicsExpose, menu_handle_expose); + EVENT_DATA_ADD_HANDLER(menu_event_data, Expose, menu_handle_expose); #endif - EVENT_DATA_ADD_HANDLER(menu_event_data, ButtonPress, menu_handle_button_press); - EVENT_DATA_ADD_HANDLER(menu_event_data, ButtonRelease, menu_handle_button_release); - EVENT_DATA_ADD_HANDLER(menu_event_data, MotionNotify, menu_handle_motion_notify); + EVENT_DATA_ADD_HANDLER(menu_event_data, ButtonPress, menu_handle_button_press); + EVENT_DATA_ADD_HANDLER(menu_event_data, ButtonRelease, menu_handle_button_release); + EVENT_DATA_ADD_HANDLER(menu_event_data, MotionNotify, menu_handle_motion_notify); - for (i = 0; i < menu_list->nummenus; i++) { - event_data_add_mywin(&menu_event_data, menu_list->menus[i]->win); - } + for (i = 0; i < menu_list->nummenus; i++) { + event_data_add_mywin(&menu_event_data, menu_list->menus[i]->win); + } - event_data_add_parent(&menu_event_data, TermWin.vt); - event_data_add_parent(&menu_event_data, TermWin.parent); + event_data_add_parent(&menu_event_data, TermWin.vt); + event_data_add_parent(&menu_event_data, TermWin.parent); } @@ -161,61 +161,61 @@ unsigned char menu_handle_enter_notify(event_t *ev) { - register menu_t *menu; + register menu_t *menu; - D_EVENTS(("menu_handle_enter_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("menu_handle_enter_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); - /* Take control of the pointer so we get all events for it, even those outside the menu window */ - menu = find_menu_by_window(menu_list, ev->xany.window); - if (menu && menu != current_menu) { - ungrab_pointer(); - if (menu->state & MENU_STATE_IS_MAPPED) { - grab_pointer(menu->win); - menu->state |= MENU_STATE_IS_FOCUSED; - current_menu = menu; - menu_reset_submenus(menu); - menuitem_change_current(find_item_by_coords(current_menu, ev->xbutton.x, ev->xbutton.y)); + /* Take control of the pointer so we get all events for it, even those outside the menu window */ + menu = find_menu_by_window(menu_list, ev->xany.window); + if (menu && menu != current_menu) { + ungrab_pointer(); + if (menu->state & MENU_STATE_IS_MAPPED) { + grab_pointer(menu->win); + menu->state |= MENU_STATE_IS_FOCUSED; + current_menu = menu; + menu_reset_submenus(menu); + menuitem_change_current(find_item_by_coords(current_menu, ev->xbutton.x, ev->xbutton.y)); + } } - } - return 1; + return 1; } unsigned char menu_handle_leave_notify(event_t *ev) { - D_EVENTS(("menu_handle_leave_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("menu_handle_leave_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); - if (current_menu) { - current_menu->state &= ~(MENU_STATE_IS_FOCUSED); - } - return 0; + if (current_menu) { + current_menu->state &= ~(MENU_STATE_IS_FOCUSED); + } + return 0; } unsigned char menu_handle_focus_in(event_t *ev) { - D_EVENTS(("menu_handle_focus_in(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("menu_handle_focus_in(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); - return 0; + return 0; } unsigned char menu_handle_focus_out(event_t *ev) { - D_EVENTS(("menu_handle_focus_out(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("menu_handle_focus_out(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); - return 0; + return 0; } #if 0 @@ -223,15 +223,15 @@ unsigned char menu_handle_expose(event_t *ev) { - XEvent unused_xevent; + XEvent unused_xevent; - D_EVENTS(("menu_handle_expose(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("menu_handle_expose(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); - while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, Expose, &unused_xevent)); - while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, GraphicsExpose, &unused_xevent)); - return 1; + while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, Expose, &unused_xevent)); + while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, GraphicsExpose, &unused_xevent)); + return 1; } #endif @@ -239,328 +239,334 @@ unsigned char menu_handle_button_press(event_t *ev) { - D_EVENTS(("menu_handle_button_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("menu_handle_button_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); - D_EVENTS(("ButtonPress at %d, %d\n", ev->xbutton.x, ev->xbutton.y)); + D_EVENTS(("ButtonPress at %d, %d\n", ev->xbutton.x, ev->xbutton.y)); - if (!current_menu || (ev->xbutton.x < 0) || (ev->xbutton.y < 0) || (ev->xbutton.x >= current_menu->w) || (ev->xbutton.y >= current_menu->h)) { - Window unused_win, child_win; + if (!current_menu || (ev->xbutton.x < 0) || (ev->xbutton.y < 0) || (ev->xbutton.x >= current_menu->w) + || (ev->xbutton.y >= current_menu->h)) { + Window unused_win, child_win; - /* Click outside the current menu, or there is no current menu. Reset. */ - ungrab_pointer(); - menu_reset_all(menu_list); - current_menu = NULL; - XTranslateCoordinates(Xdisplay, ev->xany.window, Xroot, ev->xbutton.x, ev->xbutton.y, &(ev->xbutton.x), &(ev->xbutton.y), &unused_win); - child_win = find_window_by_coords(Xroot, 0, 0, ev->xbutton.x, ev->xbutton.y); - if (child_win != None) { - XTranslateCoordinates(Xdisplay, Xroot, child_win, ev->xbutton.x, ev->xbutton.y, &(ev->xbutton.x), &(ev->xbutton.y), &unused_win); - ev->xany.window = child_win; - D_EVENTS(("Sending synthetic event on to window 0x%08x at %d, %d\n", child_win, ev->xbutton.x, ev->xbutton.y)); - XSendEvent(Xdisplay, child_win, False, 0, ev); + /* Click outside the current menu, or there is no current menu. Reset. */ + ungrab_pointer(); + menu_reset_all(menu_list); + current_menu = NULL; + XTranslateCoordinates(Xdisplay, ev->xany.window, Xroot, ev->xbutton.x, ev->xbutton.y, &(ev->xbutton.x), &(ev->xbutton.y), + &unused_win); + child_win = find_window_by_coords(Xroot, 0, 0, ev->xbutton.x, ev->xbutton.y); + if (child_win != None) { + XTranslateCoordinates(Xdisplay, Xroot, child_win, ev->xbutton.x, ev->xbutton.y, &(ev->xbutton.x), &(ev->xbutton.y), + &unused_win); + ev->xany.window = child_win; + D_EVENTS(("Sending synthetic event on to window 0x%08x at %d, %d\n", child_win, ev->xbutton.x, ev->xbutton.y)); + XSendEvent(Xdisplay, child_win, False, 0, ev); + } + } else { + button_press_time = ev->xbutton.time; + button_press_x = ev->xbutton.x; + button_press_y = ev->xbutton.y; + if (current_menu && (current_menu->state & MENU_STATE_IS_DRAGGING)) { + current_menu->state &= ~MENU_STATE_IS_DRAGGING; + } } - } else { - button_press_time = ev->xbutton.time; - button_press_x = ev->xbutton.x; - button_press_y = ev->xbutton.y; - if (current_menu && (current_menu->state & MENU_STATE_IS_DRAGGING)) { - current_menu->state &= ~MENU_STATE_IS_DRAGGING; - } - } - return 1; + return 1; } unsigned char menu_handle_button_release(event_t *ev) { - menuitem_t *item; + menuitem_t *item; - D_EVENTS(("menu_handle_button_release(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("menu_handle_button_release(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); - D_EVENTS(("ButtonRelease at %d, %d\n", ev->xbutton.x, ev->xbutton.y)); + D_EVENTS(("ButtonRelease at %d, %d\n", ev->xbutton.x, ev->xbutton.y)); - if (current_menu && (current_menu->state & MENU_STATE_IS_DRAGGING)) { + if (current_menu && (current_menu->state & MENU_STATE_IS_DRAGGING)) { - /* Dragging-and-release mode */ - D_MENU(("Drag-and-release mode, detected release. Button press time is %lu, release time is %lu\n", button_press_time, ev->xbutton.time)); - ungrab_pointer(); + /* Dragging-and-release mode */ + D_MENU(("Drag-and-release mode, detected release. Button press time is %lu, release time is %lu\n", button_press_time, + ev->xbutton.time)); + ungrab_pointer(); - if (button_press_time && (ev->xbutton.time - button_press_time > MENU_CLICK_TIME)) { - /* Take action here based on the current menu item */ - if ((item = menuitem_get_current(current_menu)) != NULL) { - if (item->type == MENUITEM_SUBMENU) { - menu_display_submenu(current_menu, item); + if (button_press_time && (ev->xbutton.time - button_press_time > MENU_CLICK_TIME)) { + /* Take action here based on the current menu item */ + if ((item = menuitem_get_current(current_menu)) != NULL) { + if (item->type == MENUITEM_SUBMENU) { + menu_display_submenu(current_menu, item); + } else { + menu_action(item); + menuitem_deselect(current_menu); + } + } + /* Reset the state of the menu system. */ + menu_reset_all(menu_list); + current_menu = NULL; } else { - menu_action(item); - menuitem_deselect(current_menu); - } - } - /* Reset the state of the menu system. */ - menu_reset_all(menu_list); - current_menu = NULL; - } else { - current_menu->state &= ~MENU_STATE_IS_DRAGGING; /* Click, brief drag, release == single click */ - } - - } else { - - /* Single-click mode */ - D_MENU(("Single click mode, detected click. Button press time is %lu, release time is %lu\n", button_press_time, ev->xbutton.time)); - if (current_menu && (ev->xbutton.x >= 0) && (ev->xbutton.y >= 0) && (ev->xbutton.x < current_menu->w) && (ev->xbutton.y < current_menu->h)) { - /* Click inside the menu window. Activate the current item. */ - if ((item = menuitem_get_current(current_menu)) != NULL) { - if (item->type == MENUITEM_SUBMENU) { - menu_display_submenu(current_menu, item); - } else { - menu_action(item); - menuitem_deselect(current_menu); - menu_reset_all(menu_list); + current_menu->state &= ~MENU_STATE_IS_DRAGGING; /* Click, brief drag, release == single click */ } - } - } else if (!(button_press_time && (ev->xbutton.time - button_press_time < MENU_CLICK_TIME)) || (button_press_x && button_press_y)) { - /* Single click which lasted too long, or the second click occured outside the menu */ - ungrab_pointer(); - /* Reset the state of the menu system. */ - menu_reset_all(menu_list); - current_menu = NULL; - } - } - button_press_time = 0; - button_press_x = button_press_y = 0; - return 1; + } else { + + /* Single-click mode */ + D_MENU(("Single click mode, detected click. Button press time is %lu, release time is %lu\n", button_press_time, + ev->xbutton.time)); + if (current_menu && (ev->xbutton.x >= 0) && (ev->xbutton.y >= 0) && (ev->xbutton.x < current_menu->w) + && (ev->xbutton.y < current_menu->h)) { + /* Click inside the menu window. Activate the current item. */ + if ((item = menuitem_get_current(current_menu)) != NULL) { + if (item->type == MENUITEM_SUBMENU) { + menu_display_submenu(current_menu, item); + } else { + menu_action(item); + menuitem_deselect(current_menu); + menu_reset_all(menu_list); + } + } + } else if (!(button_press_time && (ev->xbutton.time - button_press_time < MENU_CLICK_TIME)) || (button_press_x && button_press_y)) { + /* Single click which lasted too long, or the second click occured outside the menu */ + ungrab_pointer(); + /* Reset the state of the menu system. */ + menu_reset_all(menu_list); + current_menu = NULL; + } + } + button_press_time = 0; + button_press_x = button_press_y = 0; + + return 1; } unsigned char menu_handle_motion_notify(event_t *ev) { - register menuitem_t *item = NULL; + register menuitem_t *item = NULL; - D_EVENTS(("menu_handle_motion_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("menu_handle_motion_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &menu_event_data), 0); + + while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, MotionNotify, ev)); + if (!current_menu) { + return 1; + } + + D_MENU(("Mouse is in motion. Button press time is %lu, motion time is %lu\n", button_press_time, ev->xbutton.time)); + if ((ev->xbutton.x >= 0) && (ev->xbutton.y >= 0) && (ev->xbutton.x < current_menu->w) && (ev->xbutton.y < current_menu->h)) { + /* Motion within the current menu */ + if (button_press_time) { + current_menu->state |= MENU_STATE_IS_DRAGGING; + } + item = find_item_by_coords(current_menu, ev->xbutton.x, ev->xbutton.y); + if (!item || item != menuitem_get_current(current_menu)) { + menu_reset_submenus(current_menu); + } + menuitem_change_current(item); + } else { + /* Motion outside the current menu */ + int dest_x, dest_y; + Window child; + menu_t *menu; + + XTranslateCoordinates(Xdisplay, ev->xany.window, Xroot, ev->xbutton.x, ev->xbutton.y, &dest_x, &dest_y, &child); + menu = find_menu_by_window(menu_list, child); + if (menu && menu != current_menu) { + D_MENU(("Mouse is actually over window 0x%08x belonging to menu \"%s\"\n", child, menu->title)); + ungrab_pointer(); + grab_pointer(menu->win); + current_menu->state &= ~(MENU_STATE_IS_FOCUSED); + menu->state |= MENU_STATE_IS_FOCUSED; + if (!menu_is_child(current_menu, menu)) { + menu_reset_tree(current_menu); + } + current_menu = menu; + current_menu->state |= MENU_STATE_IS_DRAGGING; + XTranslateCoordinates(Xdisplay, ev->xany.window, child, ev->xbutton.x, ev->xbutton.y, &dest_x, &dest_y, &child); + item = find_item_by_coords(menu, dest_x, dest_y); + if (!item || item != menuitem_get_current(current_menu)) { + menu_reset_submenus(current_menu); + } + menuitem_change_current(item); + } else if (!menu) { + menuitem_change_current(NULL); + } + } - while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, MotionNotify, ev)); - if (!current_menu) { return 1; - } - - D_MENU(("Mouse is in motion. Button press time is %lu, motion time is %lu\n", button_press_time, ev->xbutton.time)); - if ((ev->xbutton.x >= 0) && (ev->xbutton.y >= 0) && (ev->xbutton.x < current_menu->w) && (ev->xbutton.y < current_menu->h)) { - /* Motion within the current menu */ - if (button_press_time) { - current_menu->state |= MENU_STATE_IS_DRAGGING; - } - item = find_item_by_coords(current_menu, ev->xbutton.x, ev->xbutton.y); - if (!item || item != menuitem_get_current(current_menu)) { - menu_reset_submenus(current_menu); - } - menuitem_change_current(item); - } else { - /* Motion outside the current menu */ - int dest_x, dest_y; - Window child; - menu_t *menu; - - XTranslateCoordinates(Xdisplay, ev->xany.window, Xroot, ev->xbutton.x, ev->xbutton.y, &dest_x, &dest_y, &child); - menu = find_menu_by_window(menu_list, child); - if (menu && menu != current_menu) { - D_MENU(("Mouse is actually over window 0x%08x belonging to menu \"%s\"\n", child, menu->title)); - ungrab_pointer(); - grab_pointer(menu->win); - current_menu->state &= ~(MENU_STATE_IS_FOCUSED); - menu->state |= MENU_STATE_IS_FOCUSED; - if (!menu_is_child(current_menu, menu)) { - menu_reset_tree(current_menu); - } - current_menu = menu; - current_menu->state |= MENU_STATE_IS_DRAGGING; - XTranslateCoordinates(Xdisplay, ev->xany.window, child, ev->xbutton.x, ev->xbutton.y, &dest_x, &dest_y, &child); - item = find_item_by_coords(menu, dest_x, dest_y); - if (!item || item != menuitem_get_current(current_menu)) { - menu_reset_submenus(current_menu); - } - menuitem_change_current(item); - } else if (!menu) { - menuitem_change_current(NULL); - } - } - - return 1; } unsigned char menu_dispatch_event(event_t *ev) { - if (menu_event_data.handlers[ev->type] != NULL) { - return ((menu_event_data.handlers[ev->type]) (ev)); - } - return (0); + if (menu_event_data.handlers[ev->type] != NULL) { + return ((menu_event_data.handlers[ev->type]) (ev)); + } + return (0); } -menulist_t * -menulist_add_menu(menulist_t *list, menu_t *menu) +menulist_t *menulist_add_menu(menulist_t *list, menu_t *menu) { - ASSERT_RVAL(menu != NULL, list); + ASSERT_RVAL(menu != NULL, list); - if (list) { - list->nummenus++; - list->menus = (menu_t **) REALLOC(list->menus, sizeof(menu_t *) * list->nummenus); - } else { - list = (menulist_t *) MALLOC(sizeof(menulist_t)); - list->nummenus = 1; - list->menus = (menu_t **) MALLOC(sizeof(menu_t *)); - } - list->menus[list->nummenus - 1] = menu; - return list; + if (list) { + list->nummenus++; + list->menus = (menu_t **) REALLOC(list->menus, sizeof(menu_t *) * list->nummenus); + } else { + list = (menulist_t *) MALLOC(sizeof(menulist_t)); + list->nummenus = 1; + list->menus = (menu_t **) MALLOC(sizeof(menu_t *)); + } + list->menus[list->nummenus - 1] = menu; + return list; } void menulist_clear(menulist_t *list) { - unsigned long i; + unsigned long i; - ASSERT(list != NULL); + ASSERT(list != NULL); - for (i = 0; i < list->nummenus; i++) { - menu_delete(list->menus[i]); - } - FREE(list->menus); - LIBAST_X_FREE_GC(topShadowGC); - LIBAST_X_FREE_GC(botShadowGC); - FREE(list); + for (i = 0; i < list->nummenus; i++) { + menu_delete(list->menus[i]); + } + FREE(list->menus); + LIBAST_X_FREE_GC(topShadowGC); + LIBAST_X_FREE_GC(botShadowGC); + FREE(list); } -menu_t * -menu_create(char *title) +menu_t *menu_create(char *title) { - menu_t *menu; - static Cursor cursor; - static long mask; - static XSetWindowAttributes xattr; + menu_t *menu; + static Cursor cursor; + static long mask; + static XSetWindowAttributes xattr; - if (!mask) { - xattr.border_pixel = BlackPixel(Xdisplay, Xscreen); - xattr.save_under = TRUE; - xattr.override_redirect = TRUE; - xattr.colormap = cmap; + if (!mask) { + xattr.border_pixel = BlackPixel(Xdisplay, Xscreen); + xattr.save_under = TRUE; + xattr.override_redirect = TRUE; + xattr.colormap = cmap; - cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); - mask = PointerMotionMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button2MotionMask | Button3MotionMask; - } - menu = (menu_t *) MALLOC(sizeof(menu_t)); - MEMSET(menu, 0, sizeof(menu_t)); - menu->title = STRDUP(title ? title : ""); + cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); + mask = + PointerMotionMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button2MotionMask | + Button3MotionMask; + } + menu = (menu_t *) MALLOC(sizeof(menu_t)); + MEMSET(menu, 0, sizeof(menu_t)); + menu->title = STRDUP(title ? title : ""); - menu->win = XCreateWindow(Xdisplay, Xroot, 0, 0, 1, 1, 0, Xdepth, InputOutput, CopyFromParent, - CWOverrideRedirect | CWSaveUnder | CWBorderPixel | CWColormap, &xattr); - XDefineCursor(Xdisplay, menu->win, cursor); - XSelectInput(Xdisplay, menu->win, mask); - XStoreName(Xdisplay, menu->win, menu->title); + menu->win = XCreateWindow(Xdisplay, Xroot, 0, 0, 1, 1, 0, Xdepth, InputOutput, CopyFromParent, + CWOverrideRedirect | CWSaveUnder | CWBorderPixel | CWColormap, &xattr); + XDefineCursor(Xdisplay, menu->win, cursor); + XSelectInput(Xdisplay, menu->win, mask); + XStoreName(Xdisplay, menu->win, menu->title); - menu->swin = XCreateWindow(Xdisplay, menu->win, 0, 0, 1, 1, 0, Xdepth, InputOutput, CopyFromParent, - CWOverrideRedirect | CWSaveUnder | CWBorderPixel | CWColormap, &xattr); + menu->swin = XCreateWindow(Xdisplay, menu->win, 0, 0, 1, 1, 0, Xdepth, InputOutput, CopyFromParent, + CWOverrideRedirect | CWSaveUnder | CWBorderPixel | CWColormap, &xattr); - menu->gc = LIBAST_X_CREATE_GC(0, NULL); - menuitem_clear_current(menu); + menu->gc = LIBAST_X_CREATE_GC(0, NULL); + menuitem_clear_current(menu); - return menu; + return menu; } void menu_delete(menu_t *menu) { - unsigned short i; + unsigned short i; - ASSERT(menu != NULL); + ASSERT(menu != NULL); - D_MENU(("Deleting menu \"%s\"\n", menu->title)); - for (i = 0; i < menu->numitems; i++) { - menuitem_delete(menu->items[i]); - } - FREE(menu->items); - if (menu->title) { - FREE(menu->title); - } - if (menu->bg) { - LIBAST_X_FREE_PIXMAP(menu->bg); - } - if (menu->gc) { - LIBAST_X_FREE_GC(menu->gc); - } + D_MENU(("Deleting menu \"%s\"\n", menu->title)); + for (i = 0; i < menu->numitems; i++) { + menuitem_delete(menu->items[i]); + } + FREE(menu->items); + if (menu->title) { + FREE(menu->title); + } + if (menu->bg) { + LIBAST_X_FREE_PIXMAP(menu->bg); + } + if (menu->gc) { + LIBAST_X_FREE_GC(menu->gc); + } #ifdef MULTI_CHARSET - if (menu->fontset) { - XFreeFontSet(Xdisplay, menu->fontset); - } + if (menu->fontset) { + XFreeFontSet(Xdisplay, menu->fontset); + } #endif - if (menu->font) { - free_font(menu->font); - } - if (menu->swin) { - XDestroyWindow(Xdisplay, menu->swin); - } - if (menu->win) { - XDestroyWindow(Xdisplay, menu->win); - } - FREE(menu); + if (menu->font) { + free_font(menu->font); + } + if (menu->swin) { + XDestroyWindow(Xdisplay, menu->swin); + } + if (menu->win) { + XDestroyWindow(Xdisplay, menu->win); + } + FREE(menu); } unsigned char menu_set_title(menu_t *menu, const char *title) { - ASSERT_RVAL(menu != NULL, 0); - REQUIRE_RVAL(title != NULL, 0); + ASSERT_RVAL(menu != NULL, 0); + REQUIRE_RVAL(title != NULL, 0); - FREE(menu->title); - menu->title = STRDUP(title); - XStoreName(Xdisplay, menu->win, menu->title); - return 1; + FREE(menu->title); + menu->title = STRDUP(title); + XStoreName(Xdisplay, menu->win, menu->title); + return 1; } unsigned char menu_set_font(menu_t *menu, const char *fontname) { - XFontStruct *font; - XGCValues gcvalue; + XFontStruct *font; + XGCValues gcvalue; - ASSERT_RVAL(menu != NULL, 0); - REQUIRE_RVAL(fontname != NULL, 0); + ASSERT_RVAL(menu != NULL, 0); + REQUIRE_RVAL(fontname != NULL, 0); - font = (XFontStruct *) load_font(fontname, "fixed", FONT_TYPE_X); + font = (XFontStruct *) load_font(fontname, "fixed", FONT_TYPE_X); #ifdef MULTI_CHARSET - menu->fontset = create_fontset(fontname, etmfonts[def_font_idx]); + menu->fontset = create_fontset(fontname, etmfonts[def_font_idx]); #endif - menu->font = font; - menu->fwidth = font->max_bounds.width; - menu->fheight = font->ascent + font->descent + rs_line_space; + menu->font = font; + menu->fwidth = font->max_bounds.width; + menu->fheight = font->ascent + font->descent + rs_line_space; - gcvalue.font = font->fid; - XChangeGC(Xdisplay, menu->gc, GCFont, &gcvalue); + gcvalue.font = font->fid; + XChangeGC(Xdisplay, menu->gc, GCFont, &gcvalue); - return 1; + return 1; } unsigned char menu_add_item(menu_t *menu, menuitem_t *item) { - ASSERT_RVAL(menu != NULL, 0); - ASSERT_RVAL(item != NULL, 0); + ASSERT_RVAL(menu != NULL, 0); + ASSERT_RVAL(item != NULL, 0); - if (menu->numitems) { - menu->numitems++; - menu->items = (menuitem_t **) REALLOC(menu->items, sizeof(menuitem_t *) * menu->numitems); - } else { - menu->numitems = 1; - menu->items = (menuitem_t **) MALLOC(sizeof(menuitem_t *)); - } + if (menu->numitems) { + menu->numitems++; + menu->items = (menuitem_t **) REALLOC(menu->items, sizeof(menuitem_t *) * menu->numitems); + } else { + menu->numitems = 1; + menu->items = (menuitem_t **) MALLOC(sizeof(menuitem_t *)); + } - menu->items[menu->numitems - 1] = item; - return 1; + menu->items[menu->numitems - 1] = item; + return 1; } @@ -568,671 +574,679 @@ menu_add_item(menu_t *menu, menuitem_t *item) unsigned char menu_is_child(menu_t *menu, menu_t *submenu) { - register unsigned char i; - register menuitem_t *item; + register unsigned char i; + register menuitem_t *item; - ASSERT_RVAL(menu != NULL, 0); - ASSERT_RVAL(submenu != NULL, 0); + ASSERT_RVAL(menu != NULL, 0); + ASSERT_RVAL(submenu != NULL, 0); - for (i = 0; i < menu->numitems; i++) { - item = menu->items[i]; - if (item->type == MENUITEM_SUBMENU && item->action.submenu != NULL) { - if (item->action.submenu == submenu) { - return 1; - } else if (menu_is_child(item->action.submenu, submenu)) { - return 1; - } + for (i = 0; i < menu->numitems; i++) { + item = menu->items[i]; + if (item->type == MENUITEM_SUBMENU && item->action.submenu != NULL) { + if (item->action.submenu == submenu) { + return 1; + } else if (menu_is_child(item->action.submenu, submenu)) { + return 1; + } + } } - } - return 0; + return 0; } -menu_t * -find_menu_by_title(menulist_t *list, char *title) +menu_t *find_menu_by_title(menulist_t *list, char *title) { - register unsigned char i; + register unsigned char i; - REQUIRE_RVAL(list != NULL, NULL); + REQUIRE_RVAL(list != NULL, NULL); - for (i = 0; i < list->nummenus; i++) { - if (!strcasecmp(list->menus[i]->title, title)) { - return (list->menus[i]); + for (i = 0; i < list->nummenus; i++) { + if (!strcasecmp(list->menus[i]->title, title)) { + return (list->menus[i]); + } } - } - return NULL; + return NULL; } -menu_t * -find_menu_by_window(menulist_t *list, Window win) +menu_t *find_menu_by_window(menulist_t *list, Window win) { - register unsigned char i; + register unsigned char i; - REQUIRE_RVAL(list != NULL, NULL); + REQUIRE_RVAL(list != NULL, NULL); - for (i = 0; i < list->nummenus; i++) { - if (list->menus[i]->win == win) { - return (list->menus[i]); + for (i = 0; i < list->nummenus; i++) { + if (list->menus[i]->win == win) { + return (list->menus[i]); + } } - } - return NULL; + return NULL; } -menuitem_t * -find_item_by_coords(menu_t *menu, int x, int y) +menuitem_t *find_item_by_coords(menu_t *menu, int x, int y) { - register unsigned char i; - register menuitem_t *item; + register unsigned char i; + register menuitem_t *item; - ASSERT_RVAL(menu != NULL, NULL); + ASSERT_RVAL(menu != NULL, NULL); - for (i = 0; i < menu->numitems; i++) { - item = menu->items[i]; - if ((x > item->x) && (y > item->y) && (x < item->x + item->w) && (y < item->y + item->h) && (item->type != MENUITEM_SEP)) { - return (item); + for (i = 0; i < menu->numitems; i++) { + item = menu->items[i]; + if ((x > item->x) && (y > item->y) && (x < item->x + item->w) && (y < item->y + item->h) && (item->type != MENUITEM_SEP)) { + return (item); + } } - } - return NULL; + return NULL; } unsigned short find_item_in_menu(menu_t *menu, menuitem_t *item) { - register unsigned char i; + register unsigned char i; - ASSERT_RVAL(menu != NULL, (unsigned short) -1); - ASSERT_RVAL(item != NULL, (unsigned short) -1); + ASSERT_RVAL(menu != NULL, (unsigned short) -1); + ASSERT_RVAL(item != NULL, (unsigned short) -1); - for (i = 0; i < menu->numitems; i++) { - if (item == menu->items[i]) { - return (i); + for (i = 0; i < menu->numitems; i++) { + if (item == menu->items[i]) { + return (i); + } } - } - return ((unsigned short) -1); + return ((unsigned short) -1); } void menuitem_change_current(menuitem_t *item) { - menuitem_t *current; + menuitem_t *current; - ASSERT(current_menu != NULL); + ASSERT(current_menu != NULL); - current = menuitem_get_current(current_menu); - if (current != item) { - D_MENU(("Changing current item in menu \"%s\" from \"%s\" to \"%s\"\n", current_menu->title, (current ? current->text : "(NULL)"), (item ? item->text : "(NULL)"))); - if (current) { - /* Reset the current item */ - menuitem_deselect(current_menu); - /* If we're changing from one submenu to another and neither is a child of the other, or if we're changing from a submenu to - no current item at all, reset the tree for the current submenu */ - if (current->type == MENUITEM_SUBMENU && current->action.submenu != NULL) { - if ((item && item->type == MENUITEM_SUBMENU && item->action.submenu != NULL - && !menu_is_child(current->action.submenu, item->action.submenu) - && !menu_is_child(item->action.submenu, current->action.submenu)) - || (!item)) { - menu_reset_tree(current->action.submenu); - } - } - } - if (item) { - menuitem_set_current(current_menu, find_item_in_menu(current_menu, item)); - menuitem_select(current_menu); - if (item->type == MENUITEM_SUBMENU) { - /* Display the submenu */ - menu_display_submenu(current_menu, item); - } + current = menuitem_get_current(current_menu); + if (current != item) { + D_MENU(("Changing current item in menu \"%s\" from \"%s\" to \"%s\"\n", current_menu->title, (current ? current->text : "(NULL)"), + (item ? item->text : "(NULL)"))); + if (current) { + /* Reset the current item */ + menuitem_deselect(current_menu); + /* If we're changing from one submenu to another and neither is a child of the other, or if we're changing from a submenu to + no current item at all, reset the tree for the current submenu */ + if (current->type == MENUITEM_SUBMENU && current->action.submenu != NULL) { + if ((item && item->type == MENUITEM_SUBMENU && item->action.submenu != NULL + && !menu_is_child(current->action.submenu, item->action.submenu) + && !menu_is_child(item->action.submenu, current->action.submenu)) + || (!item)) { + menu_reset_tree(current->action.submenu); + } + } + } + if (item) { + menuitem_set_current(current_menu, find_item_in_menu(current_menu, item)); + menuitem_select(current_menu); + if (item->type == MENUITEM_SUBMENU) { + /* Display the submenu */ + menu_display_submenu(current_menu, item); + } + } else { + menuitem_clear_current(current_menu); + } } else { - menuitem_clear_current(current_menu); + D_MENU(("Current item in menu \"%s\" does not require changing.\n", current_menu->title)); } - } else { - D_MENU(("Current item in menu \"%s\" does not require changing.\n", current_menu->title)); - } } -menuitem_t * -menuitem_create(char *text) +menuitem_t *menuitem_create(char *text) { - menuitem_t *menuitem; + menuitem_t *menuitem; - menuitem = (menuitem_t *) MALLOC(sizeof(menuitem_t)); - MEMSET(menuitem, 0, sizeof(menuitem_t)); + menuitem = (menuitem_t *) MALLOC(sizeof(menuitem_t)); + MEMSET(menuitem, 0, sizeof(menuitem_t)); - if (text) { - menuitem->text = STRDUP(text); - menuitem->len = strlen(text); - } - return menuitem; + if (text) { + menuitem->text = STRDUP(text); + menuitem->len = strlen(text); + } + return menuitem; } void menuitem_delete(menuitem_t *item) { - ASSERT(item != NULL); + ASSERT(item != NULL); - if (item->icon) { - free_simage(item->icon); - } - if (item->type == MENUITEM_STRING || item->type == MENUITEM_ECHO) { - FREE(item->action.string); - } else if (item->type == MENUITEM_SCRIPT) { - FREE(item->action.script); - } - if (item->text) { - FREE(item->text); - } - if (item->rtext) { - FREE(item->rtext); - } - FREE(item); + if (item->icon) { + free_simage(item->icon); + } + if (item->type == MENUITEM_STRING || item->type == MENUITEM_ECHO) { + FREE(item->action.string); + } else if (item->type == MENUITEM_SCRIPT) { + FREE(item->action.script); + } + if (item->text) { + FREE(item->text); + } + if (item->rtext) { + FREE(item->rtext); + } + FREE(item); } unsigned char menuitem_set_text(menuitem_t *item, const char *text) { - ASSERT_RVAL(item != NULL, 0); - REQUIRE_RVAL(text != NULL, 0); + ASSERT_RVAL(item != NULL, 0); + REQUIRE_RVAL(text != NULL, 0); - if (item->text) { - FREE(item->text); - } - item->text = STRDUP(text); - item->len = strlen(text); - return 1; + if (item->text) { + FREE(item->text); + } + item->text = STRDUP(text); + item->len = strlen(text); + return 1; } unsigned char menuitem_set_icon(menuitem_t *item, simage_t *icon) { - ASSERT_RVAL(item != NULL, 0); - ASSERT_RVAL(icon != NULL, 0); + ASSERT_RVAL(item != NULL, 0); + ASSERT_RVAL(icon != NULL, 0); - item->icon = icon; - return 1; + item->icon = icon; + return 1; } unsigned char menuitem_set_action(menuitem_t *item, unsigned char type, char *action) { - ASSERT_RVAL(item != NULL, 0); + ASSERT_RVAL(item != NULL, 0); - item->type = type; - switch (type) { - case MENUITEM_SUBMENU: - item->action.submenu = find_menu_by_title(menu_list, action); - break; - case MENUITEM_SCRIPT: - item->action.script = STRDUP(action); - break; - case MENUITEM_STRING: - case MENUITEM_ECHO: - item->action.string = (char *) MALLOC(strlen(action) + 2); - strcpy(item->action.string, action); - parse_escaped_string(item->action.string); - break; - default: - break; - } - return 1; + item->type = type; + switch (type) { + case MENUITEM_SUBMENU: + item->action.submenu = find_menu_by_title(menu_list, action); + break; + case MENUITEM_SCRIPT: + item->action.script = STRDUP(action); + break; + case MENUITEM_STRING: + case MENUITEM_ECHO: + item->action.string = (char *) MALLOC(strlen(action) + 2); + strcpy(item->action.string, action); + parse_escaped_string(item->action.string); + break; + default: + break; + } + return 1; } unsigned char menuitem_set_rtext(menuitem_t *item, char *rtext) { - ASSERT_RVAL(item != NULL, 0); - ASSERT_RVAL(rtext != NULL, 0); + ASSERT_RVAL(item != NULL, 0); + ASSERT_RVAL(rtext != NULL, 0); - item->rtext = STRDUP(rtext); - item->rlen = strlen(rtext); - return 1; + item->rtext = STRDUP(rtext); + item->rlen = strlen(rtext); + return 1; } void menu_reset(menu_t *menu) { - ASSERT(menu != NULL); + ASSERT(menu != NULL); - D_MENU(("menu_reset(menu %8p \"%s\"), window 0x%08x\n", menu, menu->title, menu->win)); - if (!(menu->state & MENU_STATE_IS_MAPPED)) { - return; - } - menu->state &= ~(MENU_STATE_IS_CURRENT | MENU_STATE_IS_DRAGGING | MENU_STATE_IS_MAPPED); - XUnmapWindow(Xdisplay, menu->swin); - XUnmapWindow(Xdisplay, menu->win); - menuitem_clear_current(menu); + D_MENU(("menu_reset(menu %8p \"%s\"), window 0x%08x\n", menu, menu->title, menu->win)); + if (!(menu->state & MENU_STATE_IS_MAPPED)) { + return; + } + menu->state &= ~(MENU_STATE_IS_CURRENT | MENU_STATE_IS_DRAGGING | MENU_STATE_IS_MAPPED); + XUnmapWindow(Xdisplay, menu->swin); + XUnmapWindow(Xdisplay, menu->win); + menuitem_clear_current(menu); } void menu_reset_all(menulist_t *list) { - register unsigned short i; + register unsigned short i; - ASSERT(list != NULL); + ASSERT(list != NULL); - if (list->nummenus == 0) - return; + if (list->nummenus == 0) + return; - D_MENU(("menu_reset_all(%8p) called\n", list)); - if (current_menu && menuitem_get_current(current_menu) != NULL) { - menuitem_deselect(current_menu); - } - for (i = 0; i < list->nummenus; i++) { - menu_reset(list->menus[i]); - } - current_menu = NULL; + D_MENU(("menu_reset_all(%8p) called\n", list)); + if (current_menu && menuitem_get_current(current_menu) != NULL) { + menuitem_deselect(current_menu); + } + for (i = 0; i < list->nummenus; i++) { + menu_reset(list->menus[i]); + } + current_menu = NULL; } void menu_reset_tree(menu_t *menu) { - register unsigned short i; - register menuitem_t *item; + register unsigned short i; + register menuitem_t *item; - ASSERT(menu != NULL); + ASSERT(menu != NULL); - D_MENU(("menu_reset_tree(menu %8p \"%s\"), window 0x%08x\n", menu, menu->title, menu->win)); - if (!(menu->state & MENU_STATE_IS_MAPPED)) { - return; - } - for (i = 0; i < menu->numitems; i++) { - item = menu->items[i]; - if (item->type == MENUITEM_SUBMENU && item->action.submenu != NULL) { - menu_reset_tree(item->action.submenu); + D_MENU(("menu_reset_tree(menu %8p \"%s\"), window 0x%08x\n", menu, menu->title, menu->win)); + if (!(menu->state & MENU_STATE_IS_MAPPED)) { + return; } - } - menu_reset(menu); + for (i = 0; i < menu->numitems; i++) { + item = menu->items[i]; + if (item->type == MENUITEM_SUBMENU && item->action.submenu != NULL) { + menu_reset_tree(item->action.submenu); + } + } + menu_reset(menu); } void menu_reset_submenus(menu_t *menu) { - register unsigned short i; - register menuitem_t *item; + register unsigned short i; + register menuitem_t *item; - ASSERT(menu != NULL); + ASSERT(menu != NULL); - D_MENU(("menu_reset_submenus(menu %8p \"%s\"), window 0x%08x\n", menu, menu->title, menu->win)); - for (i = 0; i < menu->numitems; i++) { - item = menu->items[i]; - if (item->type == MENUITEM_SUBMENU && item->action.submenu != NULL) { - menu_reset_tree(item->action.submenu); + D_MENU(("menu_reset_submenus(menu %8p \"%s\"), window 0x%08x\n", menu, menu->title, menu->win)); + for (i = 0; i < menu->numitems; i++) { + item = menu->items[i]; + if (item->type == MENUITEM_SUBMENU && item->action.submenu != NULL) { + menu_reset_tree(item->action.submenu); + } } - } } void menuitem_select(menu_t *menu) { - static Pixel top = 0, bottom = 0; - menuitem_t *item; + static Pixel top = 0, bottom = 0; + menuitem_t *item; - ASSERT(menu != NULL); + ASSERT(menu != NULL); - if (top == 0) { - top = get_top_shadow_color(images[image_submenu].selected->bg, "submenu top shadow color"); - bottom = get_bottom_shadow_color(images[image_submenu].selected->bg, "submenu bottom shadow color"); - } - - item = menuitem_get_current(menu); - REQUIRE(item != NULL); - D_MENU(("Selecting new current item \"%s\" within menu \"%s\" (window 0x%08x, selection window 0x%08x)\n", item->text, menu->title, menu->win, menu->swin)); - item->state |= MENU_STATE_IS_CURRENT; - XMoveWindow(Xdisplay, menu->swin, item->x, item->y); - XMapWindow(Xdisplay, menu->swin); - if (item->type == MENUITEM_SUBMENU) { - render_simage(images[image_submenu].selected, menu->swin, item->w - MENU_VGAP, item->h, image_submenu, 0); - if (image_mode_is(image_submenu, MODE_AUTO)) { - enl_ipc_sync(); - } else if (!image_mode_is(image_submenu, MODE_MASK)) { - draw_shadow_from_colors(menu->swin, top, bottom, 0, 0, item->w - MENU_VGAP, item->h, 2); - draw_arrow_from_colors(menu->swin, top, bottom, item->w - 3 * MENU_HGAP, (item->h - MENU_VGAP) / 2, MENU_VGAP, 2, DRAW_ARROW_RIGHT); + if (top == 0) { + top = get_top_shadow_color(images[image_submenu].selected->bg, "submenu top shadow color"); + bottom = get_bottom_shadow_color(images[image_submenu].selected->bg, "submenu bottom shadow color"); } - } else { - if (image_mode_is(image_menu, MODE_MASK)) { - render_simage(images[image_menu].selected, menu->swin, item->w - MENU_VGAP, item->h, image_menu, 0); + + item = menuitem_get_current(menu); + REQUIRE(item != NULL); + D_MENU(("Selecting new current item \"%s\" within menu \"%s\" (window 0x%08x, selection window 0x%08x)\n", item->text, menu->title, + menu->win, menu->swin)); + item->state |= MENU_STATE_IS_CURRENT; + XMoveWindow(Xdisplay, menu->swin, item->x, item->y); + XMapWindow(Xdisplay, menu->swin); + if (item->type == MENUITEM_SUBMENU) { + render_simage(images[image_submenu].selected, menu->swin, item->w - MENU_VGAP, item->h, image_submenu, 0); + if (image_mode_is(image_submenu, MODE_AUTO)) { + enl_ipc_sync(); + } else if (!image_mode_is(image_submenu, MODE_MASK)) { + draw_shadow_from_colors(menu->swin, top, bottom, 0, 0, item->w - MENU_VGAP, item->h, 2); + draw_arrow_from_colors(menu->swin, top, bottom, item->w - 3 * MENU_HGAP, (item->h - MENU_VGAP) / 2, MENU_VGAP, 2, + DRAW_ARROW_RIGHT); + } } else { - draw_shadow_from_colors(menu->swin, top, bottom, 0, 0, item->w - MENU_VGAP, item->h, 2); + if (image_mode_is(image_menu, MODE_MASK)) { + render_simage(images[image_menu].selected, menu->swin, item->w - MENU_VGAP, item->h, image_menu, 0); + } else { + draw_shadow_from_colors(menu->swin, top, bottom, 0, 0, item->w - MENU_VGAP, item->h, 2); + } + if (image_mode_is(image_menu, MODE_AUTO)) { + enl_ipc_sync(); + } } - if (image_mode_is(image_menu, MODE_AUTO)) { - enl_ipc_sync(); + XSetForeground(Xdisplay, menu->gc, images[image_menu].selected->fg); + draw_string(menu->swin, menu->gc, MENU_HGAP, item->h - MENU_VGAP, item->text, item->len); + if (item->rtext) { + draw_string(menu->swin, menu->gc, item->w - XTextWidth(menu->font, item->rtext, item->rlen) - 2 * MENU_HGAP, item->h - MENU_VGAP, + item->rtext, item->rlen); } - } - XSetForeground(Xdisplay, menu->gc, images[image_menu].selected->fg); - draw_string(menu->swin, menu->gc, MENU_HGAP, item->h - MENU_VGAP, item->text, item->len); - if (item->rtext) { - draw_string(menu->swin, menu->gc, item->w - XTextWidth(menu->font, item->rtext, item->rlen) - 2 * MENU_HGAP, item->h - MENU_VGAP, item->rtext, item->rlen); - } - XSetForeground(Xdisplay, menu->gc, images[image_menu].norm->fg); + XSetForeground(Xdisplay, menu->gc, images[image_menu].norm->fg); } void menuitem_deselect(menu_t *menu) { - menuitem_t *item; + menuitem_t *item; - ASSERT(menu != NULL); + ASSERT(menu != NULL); - item = menuitem_get_current(menu); - REQUIRE(item != NULL); - D_MENU(("Deselecting item \"%s\"\n", item->text)); - item->state &= ~(MENU_STATE_IS_CURRENT); - XUnmapWindow(Xdisplay, menu->swin); + item = menuitem_get_current(menu); + REQUIRE(item != NULL); + D_MENU(("Deselecting item \"%s\"\n", item->text)); + item->state &= ~(MENU_STATE_IS_CURRENT); + XUnmapWindow(Xdisplay, menu->swin); } void menu_display_submenu(menu_t *menu, menuitem_t *item) { - menu_t *submenu; + menu_t *submenu; - ASSERT(menu != NULL); - ASSERT(item != NULL); - REQUIRE(item->action.submenu != NULL); + ASSERT(menu != NULL); + ASSERT(item != NULL); + REQUIRE(item->action.submenu != NULL); - submenu = item->action.submenu; - D_MENU(("Displaying submenu \"%s\" (window 0x%08x) of menu \"%s\" (window 0x%08x)\n", submenu->title, submenu->win, menu->title, menu->win)); - menu_invoke(item->x + item->w, item->y, menu->win, submenu, CurrentTime); + submenu = item->action.submenu; + D_MENU(("Displaying submenu \"%s\" (window 0x%08x) of menu \"%s\" (window 0x%08x)\n", submenu->title, submenu->win, menu->title, + menu->win)); + menu_invoke(item->x + item->w, item->y, menu->win, submenu, CurrentTime); - /* Invoking the submenu makes it current. Undo that behavior. */ - ungrab_pointer(); - grab_pointer(menu->win); - current_menu->state &= ~(MENU_STATE_IS_CURRENT); - current_menu = menu; - menu->state |= MENU_STATE_IS_CURRENT; + /* Invoking the submenu makes it current. Undo that behavior. */ + ungrab_pointer(); + grab_pointer(menu->win); + current_menu->state &= ~(MENU_STATE_IS_CURRENT); + current_menu = menu; + menu->state |= MENU_STATE_IS_CURRENT; } void -menu_move(menu_t *menu, unsigned short x, unsigned short y) { +menu_move(menu_t *menu, unsigned short x, unsigned short y) +{ - ASSERT(menu != NULL); + ASSERT(menu != NULL); - D_MENU(("Moving menu \"%s\" to %hu, %hu\n", menu->title, x, y)); - menu->x = x; - menu->y = y; - XMoveWindow(Xdisplay, menu->win, menu->x, menu->y); - if (image_mode_is(image_menu, (MODE_TRANS | MODE_VIEWPORT))) { - menu_draw(menu); - } + D_MENU(("Moving menu \"%s\" to %hu, %hu\n", menu->title, x, y)); + menu->x = x; + menu->y = y; + XMoveWindow(Xdisplay, menu->win, menu->x, menu->y); + if (image_mode_is(image_menu, (MODE_TRANS | MODE_VIEWPORT))) { + menu_draw(menu); + } } void menu_draw(menu_t *menu) { - register unsigned short i, len; - unsigned long width, height; + register unsigned short i, len; + unsigned long width, height; #if 0 - char *safeaction; + char *safeaction; #endif - unsigned short str_x, str_y; - XGCValues gcvalue; - int ascent, descent, direction, dx, dy; - XCharStruct chars; - Screen *scr; + unsigned short str_x, str_y; + XGCValues gcvalue; + int ascent, descent, direction, dx, dy; + XCharStruct chars; + Screen *scr; - ASSERT(menu != NULL); + ASSERT(menu != NULL); - scr = ScreenOfDisplay(Xdisplay, Xscreen); - if (!menu->font) { - menu_set_font(menu, etfonts[def_font_idx]); - } - gcvalue.foreground = images[image_menu].norm->fg; - gcvalue.graphics_exposures = False; - XChangeGC(Xdisplay, menu->gc, GCForeground | GCGraphicsExposures, &gcvalue); + scr = ScreenOfDisplay(Xdisplay, Xscreen); + if (!menu->font) { + menu_set_font(menu, etfonts[def_font_idx]); + } + gcvalue.foreground = images[image_menu].norm->fg; + gcvalue.graphics_exposures = False; + XChangeGC(Xdisplay, menu->gc, GCForeground | GCGraphicsExposures, &gcvalue); - if (!menu->w) { - unsigned short longest; + if (!menu->w) { + unsigned short longest; + len = strlen(menu->title); + longest = XTextWidth(menu->font, menu->title, len); + height = menu->fheight + 3 * MENU_VGAP; + for (i = 0; i < menu->numitems; i++) { + unsigned short j = menu->items[i]->len; + menuitem_t *item = menu->items[i]; + + width = XTextWidth(menu->font, item->text, j); + if (item->rtext) { + width += XTextWidth(menu->font, item->rtext, item->rlen) + (2 * MENU_HGAP); + } + longest = (longest > width) ? longest : width; + height += ((item->type == MENUITEM_SEP) ? (MENU_VGAP) : (menu->fheight)) + MENU_VGAP; + } + width = longest + (4 * MENU_HGAP); + if (images[image_submenu].selected->iml->pad) { + width += images[image_submenu].selected->iml->pad->left + images[image_submenu].selected->iml->pad->right; + } + if (!image_mode_is(image_menu, MODE_MASK) || !image_mode_is(image_submenu, MODE_MASK)) { + width += 3 * MENU_VGAP; + } + menu->w = width; + menu->h = height; + } + + /* If the menu will come up offscreen, move all the other menus out of the way. */ + dx = scr->width - menu->w - menu->x; + dy = scr->height - menu->h - menu->y; + D_MENU((" -> Menu is %hux%hu at %hu, %hu, dx is %d, dy is %d\n", menu->w, menu->h, menu->x, menu->y, dx, dy)); + if (dx < 0 || dy < 0) { + register short i; + + if (dx >= 0) { + dx = 0; + } else if (menu->w > scr->width) { + dx = -menu->x; + menu->x = 0; + } else { + menu->x = scr->width - menu->w; + } + if (dy >= 0) { + dy = 0; + } else if (menu->h > scr->height) { + dy = -menu->y; + menu->y = 0; + } else { + menu->y = scr->height - menu->h; + } + D_MENU((" -> New x, y is %hu, %hu\n", menu->x, menu->y)); + for (i = menu_list->nummenus - 1; i >= 0; i--) { + menu_t *tmp = menu_list->menus[i]; + + if (tmp == menu) { + continue; + } + D_MENU((" -> Checking menu \"%s\" to see if it needs to be moved.\n", tmp->title)); + if (tmp->state & MENU_STATE_IS_MAPPED) { + int x = tmp->x + dx, y = tmp->y + dy; + int this_dx, this_dy; + + if (x < 0) { + x = 0; + this_dx = -tmp->x; + } else { + this_dx = dx; + } + if (y < 0) { + y = 0; + this_dy = -tmp->y; + } else { + this_dy = 0; + } + D_MENU((" -> Moving menu to %d, %d (a change of %d, %d from %d, %d)\n", x, y, this_dx, this_dy, tmp->x, tmp->y)); + XWarpPointer(Xdisplay, tmp->win, None, 0, 0, tmp->w, tmp->h, this_dx, this_dy); + menu_move(tmp, x, y); + } + } + } + XMoveResizeWindow(Xdisplay, menu->win, menu->x, menu->y, menu->w, menu->h); + + /* Size and render selected item window */ + XResizeWindow(Xdisplay, menu->swin, menu->w - 2 * MENU_HGAP, menu->fheight + MENU_VGAP); + /* This must come before the rendering of the menu window so that pmap->pixmap is guaranteed to be the menu background. */ + render_simage(images[image_menu].selected, menu->swin, menu->w - 2 * MENU_HGAP, menu->fheight + MENU_VGAP, image_menu, 0); + if (image_mode_is(image_menu, MODE_AUTO)) { + enl_ipc_sync(); + } + XUnmapWindow(Xdisplay, menu->swin); + + /* Draw menu background */ + render_simage(images[image_menu].norm, menu->win, menu->w, menu->h, image_menu, RENDER_FORCE_PIXMAP); + menu->bg = images[image_menu].norm->pmap->pixmap; + if (!image_mode_is(image_menu, MODE_MASK)) { + draw_shadow_from_colors(menu->bg, PixColors[menuTopShadowColor], PixColors[menuBottomShadowColor], 0, 0, menu->w, menu->h, 2); + } + D_MENU(("Menu background is 0x%08x\n", menu->bg)); + XMapWindow(Xdisplay, menu->win); + XRaiseWindow(Xdisplay, menu->win); + + str_x = 2 * MENU_HGAP; + if (images[image_menu].selected->iml->pad) { + str_x += images[image_menu].selected->iml->pad->left; + } + str_y = menu->fheight + MENU_VGAP; len = strlen(menu->title); - longest = XTextWidth(menu->font, menu->title, len); - height = menu->fheight + 3 * MENU_VGAP; + XTextExtents(menu->font, menu->title, len, &direction, &ascent, &descent, &chars); + draw_string(menu->bg, menu->gc, center_coords(2 * MENU_HGAP, menu->w - 2 * MENU_HGAP) - (chars.width >> 1), + str_y - chars.descent - MENU_VGAP / 2, menu->title, len); + draw_shadow(menu->bg, topShadowGC, botShadowGC, str_x, str_y - chars.descent - MENU_VGAP / 2 + 1, menu->w - (4 * MENU_HGAP), MENU_VGAP, + 2); + str_y += MENU_VGAP; + for (i = 0; i < menu->numitems; i++) { - unsigned short j = menu->items[i]->len; - menuitem_t *item = menu->items[i]; + menuitem_t *item = menu->items[i]; - width = XTextWidth(menu->font, item->text, j); - if (item->rtext) { - width += XTextWidth(menu->font, item->rtext, item->rlen) + (2 * MENU_HGAP); - } - longest = (longest > width) ? longest : width; - height += ((item->type == MENUITEM_SEP) ? (MENU_VGAP) : (menu->fheight)) + MENU_VGAP; - } - width = longest + (4 * MENU_HGAP); - if (images[image_submenu].selected->iml->pad) { - width += images[image_submenu].selected->iml->pad->left + images[image_submenu].selected->iml->pad->right; - } - if (!image_mode_is(image_menu, MODE_MASK) || !image_mode_is(image_submenu, MODE_MASK)) { - width += 3 * MENU_VGAP; - } - menu->w = width; - menu->h = height; - } + if (item->type == MENUITEM_SEP) { - /* If the menu will come up offscreen, move all the other menus out of the way. */ - dx = scr->width - menu->w - menu->x; - dy = scr->height - menu->h - menu->y; - D_MENU((" -> Menu is %hux%hu at %hu, %hu, dx is %d, dy is %d\n", menu->w, menu->h, menu->x, menu->y, dx, dy)); - if (dx < 0 || dy < 0) { - register short i; + str_y += 2 * MENU_VGAP; + if (!item->x) { + item->x = MENU_HGAP; + item->y = str_y - 2 * MENU_VGAP; + item->w = menu->w - MENU_HGAP; + item->h = 2 * MENU_VGAP; + D_MENU(("Hot Area at %hu, %hu to %hu, %hu (width %hu, height %hu)\n", item->x, item->y, item->x + item->w, + item->y + item->h, item->w, item->h)); + } + draw_shadow(menu->bg, botShadowGC, topShadowGC, str_x, str_y - MENU_VGAP - MENU_VGAP / 2, menu->w - 4 * MENU_HGAP, MENU_VGAP, + 2); - if (dx >= 0) { - dx = 0; - } else if (menu->w > scr->width) { - dx = -menu->x; - menu->x = 0; - } else { - menu->x = scr->width - menu->w; - } - if (dy >= 0) { - dy = 0; - } else if (menu->h > scr->height) { - dy = -menu->y; - menu->y = 0; - } else { - menu->y = scr->height - menu->h; - } - D_MENU((" -> New x, y is %hu, %hu\n", menu->x, menu->y)); - for (i = menu_list->nummenus - 1; i >= 0; i--) { - menu_t *tmp = menu_list->menus[i]; - - if (tmp == menu) { - continue; - } - D_MENU((" -> Checking menu \"%s\" to see if it needs to be moved.\n", tmp->title)); - if (tmp->state & MENU_STATE_IS_MAPPED) { - int x = tmp->x + dx, y = tmp->y + dy; - int this_dx, this_dy; - - if (x < 0) { - x = 0; - this_dx = -tmp->x; } else { - this_dx = dx; - } - if (y < 0) { - y = 0; - this_dy = -tmp->y; - } else { - this_dy = 0; - } - D_MENU((" -> Moving menu to %d, %d (a change of %d, %d from %d, %d)\n", x, y, this_dx, this_dy, tmp->x, tmp->y)); - XWarpPointer(Xdisplay, tmp->win, None, 0, 0, tmp->w, tmp->h, this_dx, this_dy); - menu_move(tmp, x, y); - } - } - } - XMoveResizeWindow(Xdisplay, menu->win, menu->x, menu->y, menu->w, menu->h); - - /* Size and render selected item window */ - XResizeWindow(Xdisplay, menu->swin, menu->w - 2 * MENU_HGAP, menu->fheight + MENU_VGAP); - /* This must come before the rendering of the menu window so that pmap->pixmap is guaranteed to be the menu background. */ - render_simage(images[image_menu].selected, menu->swin, menu->w - 2 * MENU_HGAP, menu->fheight + MENU_VGAP, image_menu, 0); - if (image_mode_is(image_menu, MODE_AUTO)) { - enl_ipc_sync(); - } - XUnmapWindow(Xdisplay, menu->swin); - - /* Draw menu background */ - render_simage(images[image_menu].norm, menu->win, menu->w, menu->h, image_menu, RENDER_FORCE_PIXMAP); - menu->bg = images[image_menu].norm->pmap->pixmap; - if (!image_mode_is(image_menu, MODE_MASK)) { - draw_shadow_from_colors(menu->bg, PixColors[menuTopShadowColor], PixColors[menuBottomShadowColor], 0, 0, menu->w, menu->h, 2); - } - D_MENU(("Menu background is 0x%08x\n", menu->bg)); - XMapWindow(Xdisplay, menu->win); - XRaiseWindow(Xdisplay, menu->win); - - str_x = 2 * MENU_HGAP; - if (images[image_menu].selected->iml->pad) { - str_x += images[image_menu].selected->iml->pad->left; - } - str_y = menu->fheight + MENU_VGAP; - len = strlen(menu->title); - XTextExtents(menu->font, menu->title, len, &direction, &ascent, &descent, &chars); - draw_string(menu->bg, menu->gc, center_coords(2 * MENU_HGAP, menu->w - 2 * MENU_HGAP) - (chars.width >> 1), - str_y - chars.descent - MENU_VGAP / 2, menu->title, len); - draw_shadow(menu->bg, topShadowGC, botShadowGC, str_x, str_y - chars.descent - MENU_VGAP / 2 + 1, menu->w - (4 * MENU_HGAP), MENU_VGAP, 2); - str_y += MENU_VGAP; - - for (i = 0; i < menu->numitems; i++) { - menuitem_t *item = menu->items[i]; - - if (item->type == MENUITEM_SEP) { - - str_y += 2 * MENU_VGAP; - if (!item->x) { - item->x = MENU_HGAP; - item->y = str_y - 2 * MENU_VGAP; - item->w = menu->w - MENU_HGAP; - item->h = 2 * MENU_VGAP; - D_MENU(("Hot Area at %hu, %hu to %hu, %hu (width %hu, height %hu)\n", item->x, item->y, item->x + item->w, item->y + item->h, item->w, item->h)); - } - draw_shadow(menu->bg, botShadowGC, topShadowGC, str_x, str_y - MENU_VGAP - MENU_VGAP / 2, menu->w - 4 * MENU_HGAP, MENU_VGAP, 2); - - } else { - str_y += menu->fheight + MENU_VGAP; - if (!item->x) { - item->x = MENU_HGAP; - item->y = str_y - menu->fheight - MENU_VGAP / 2; - item->w = menu->w - MENU_HGAP; - item->h = menu->fheight + MENU_VGAP; - D_MENU(("Hot Area at %hu, %hu to %hu, %hu (width %hu, height %hu)\n", item->x, item->y, item->x + item->w, item->y + item->h, item->w, item->h)); - } - switch (item->type) { - case MENUITEM_SUBMENU: - if (image_mode_is(image_submenu, MODE_MASK)) { - paste_simage(images[image_submenu].norm, image_submenu, menu->win, menu->bg, item->x, item->y, item->w - MENU_VGAP, item->h); - } else { - draw_arrow_from_colors(menu->bg, PixColors[menuTopShadowColor], PixColors[menuBottomShadowColor], - item->x + item->w - 3 * MENU_HGAP, item->y + (item->h - MENU_VGAP) / 2, MENU_VGAP, 2, DRAW_ARROW_RIGHT); - } - break; + str_y += menu->fheight + MENU_VGAP; + if (!item->x) { + item->x = MENU_HGAP; + item->y = str_y - menu->fheight - MENU_VGAP / 2; + item->w = menu->w - MENU_HGAP; + item->h = menu->fheight + MENU_VGAP; + D_MENU(("Hot Area at %hu, %hu to %hu, %hu (width %hu, height %hu)\n", item->x, item->y, item->x + item->w, + item->y + item->h, item->w, item->h)); + } + switch (item->type) { + case MENUITEM_SUBMENU: + if (image_mode_is(image_submenu, MODE_MASK)) { + paste_simage(images[image_submenu].norm, image_submenu, menu->win, menu->bg, item->x, item->y, item->w - MENU_VGAP, + item->h); + } else { + draw_arrow_from_colors(menu->bg, PixColors[menuTopShadowColor], PixColors[menuBottomShadowColor], + item->x + item->w - 3 * MENU_HGAP, item->y + (item->h - MENU_VGAP) / 2, MENU_VGAP, 2, + DRAW_ARROW_RIGHT); + } + break; #if 0 - case MENUITEM_STRING: - safeaction = STRDUP(item->action.string); - safe_str(safeaction, strlen(safeaction)); - D_MENU((" Item %hu: %s (string %s)\n", i, item->text, safeaction)); - FREE(safeaction); - break; - case MENUITEM_ECHO: - safeaction = STRDUP(item->action.string); - safe_str(safeaction, strlen(safeaction)); - D_MENU((" Item %hu: %s (echo %s)\n", i, item->text, safeaction)); - FREE(safeaction); - break; - default: - fatal_error("Internal Program Error: Unknown menuitem type: %u\n", item->type); - break; + case MENUITEM_STRING: + safeaction = STRDUP(item->action.string); + safe_str(safeaction, strlen(safeaction)); + D_MENU((" Item %hu: %s (string %s)\n", i, item->text, safeaction)); + FREE(safeaction); + break; + case MENUITEM_ECHO: + safeaction = STRDUP(item->action.string); + safe_str(safeaction, strlen(safeaction)); + D_MENU((" Item %hu: %s (echo %s)\n", i, item->text, safeaction)); + FREE(safeaction); + break; + default: + fatal_error("Internal Program Error: Unknown menuitem type: %u\n", item->type); + break; #endif - default: - break; - } - draw_string(menu->bg, menu->gc, str_x, str_y - MENU_VGAP / 2, item->text, item->len); - if (item->rtext) { - draw_string(menu->bg, menu->gc, str_x + item->w - XTextWidth(menu->font, item->rtext, item->rlen) - 3 * MENU_HGAP, str_y - MENU_VGAP / 2, - item->rtext, item->rlen); - } + default: + break; + } + draw_string(menu->bg, menu->gc, str_x, str_y - MENU_VGAP / 2, item->text, item->len); + if (item->rtext) { + draw_string(menu->bg, menu->gc, str_x + item->w - XTextWidth(menu->font, item->rtext, item->rlen) - 3 * MENU_HGAP, + str_y - MENU_VGAP / 2, item->rtext, item->rlen); + } + } } - } - XSetWindowBackgroundPixmap(Xdisplay, menu->win, menu->bg); - XClearWindow(Xdisplay, menu->win); + XSetWindowBackgroundPixmap(Xdisplay, menu->win, menu->bg); + XClearWindow(Xdisplay, menu->win); } void menu_display(int x, int y, menu_t *menu) { - ASSERT(menu != NULL); + ASSERT(menu != NULL); - menu->state |= (MENU_STATE_IS_CURRENT); - current_menu = menu; + menu->state |= (MENU_STATE_IS_CURRENT); + current_menu = menu; - /* Move, render, and map menu window */ - menu->x = x; - menu->y = y; - D_MENU(("Displaying menu \"%s\" (window 0x%08x) at root coordinates %d, %d\n", menu->title, menu->win, menu->x, menu->y)); + /* Move, render, and map menu window */ + menu->x = x; + menu->y = y; + D_MENU(("Displaying menu \"%s\" (window 0x%08x) at root coordinates %d, %d\n", menu->title, menu->win, menu->x, menu->y)); - PROF_FUNC(menu_draw, menu_draw(menu)); - menu->state |= (MENU_STATE_IS_MAPPED); + PROF_FUNC(menu_draw, menu_draw(menu)); + menu->state |= (MENU_STATE_IS_MAPPED); - /* Take control of the pointer so we get all events for it, even those outside the menu window */ - grab_pointer(menu->win); + /* Take control of the pointer so we get all events for it, even those outside the menu window */ + grab_pointer(menu->win); } void menu_action(menuitem_t *item) { - ASSERT(item != NULL); + ASSERT(item != NULL); - D_MENU(("menu_action() called to invoke %s\n", item->text)); - switch (item->type) { - case MENUITEM_SEP: - D_MENU(("Internal Program Error: menu_action() called for a separator.\n")); - break; - case MENUITEM_SUBMENU: - D_MENU(("Internal Program Error: menu_action() called for a submenu.\n")); - break; - case MENUITEM_STRING: - cmd_write((unsigned char *) item->action.string, strlen(item->action.string)); - break; - case MENUITEM_ECHO: - tt_write((unsigned char *) item->action.string, strlen(item->action.string)); - break; - case MENUITEM_SCRIPT: - script_parse((char *) item->action.script); - break; - default: - fatal_error("Internal Program Error: Unknown menuitem type: %u\n", item->type); - break; - } + D_MENU(("menu_action() called to invoke %s\n", item->text)); + switch (item->type) { + case MENUITEM_SEP: + D_MENU(("Internal Program Error: menu_action() called for a separator.\n")); + break; + case MENUITEM_SUBMENU: + D_MENU(("Internal Program Error: menu_action() called for a submenu.\n")); + break; + case MENUITEM_STRING: + cmd_write((unsigned char *) item->action.string, strlen(item->action.string)); + break; + case MENUITEM_ECHO: + tt_write((unsigned char *) item->action.string, strlen(item->action.string)); + break; + case MENUITEM_SCRIPT: + script_parse((char *) item->action.script); + break; + default: + fatal_error("Internal Program Error: Unknown menuitem type: %u\n", item->type); + break; + } } void menu_invoke(int x, int y, Window win, menu_t *menu, Time timestamp) { - int root_x, root_y; - Window unused; + int root_x, root_y; + Window unused; - REQUIRE(menu != NULL); + REQUIRE(menu != NULL); - if (timestamp != CurrentTime) { - button_press_time = timestamp; - } - if (win != Xroot) { - XTranslateCoordinates(Xdisplay, win, Xroot, x, y, &root_x, &root_y, &unused); - } - menu_display(root_x, root_y, menu); + if (timestamp != CurrentTime) { + button_press_time = timestamp; + } + if (win != Xroot) { + XTranslateCoordinates(Xdisplay, win, Xroot, x, y, &root_x, &root_y, &unused); + } + menu_display(root_x, root_y, menu); } void menu_invoke_by_title(int x, int y, Window win, char *title, Time timestamp) { - menu_t *menu; + menu_t *menu; - REQUIRE(title != NULL); - REQUIRE(menu_list != NULL); + REQUIRE(title != NULL); + REQUIRE(menu_list != NULL); - menu = find_menu_by_title(menu_list, title); - if (!menu) { - D_MENU(("Menu \"%s\" not found!\n", title)); - return; - } - menu_invoke(x, y, win, menu, timestamp); + menu = find_menu_by_title(menu_list, title); + if (!menu) { + D_MENU(("Menu \"%s\" not found!\n", title)); + return; + } + menu_invoke(x, y, win, menu, timestamp); } diff --git a/src/misc.c b/src/misc.c index 4de425b..f45f0f7 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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; } diff --git a/src/netdisp.c b/src/netdisp.c index 20b2e63..a735bfe 100644 --- a/src/netdisp.c +++ b/src/netdisp.c @@ -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) -----------------------*/ diff --git a/src/options.c b/src/options.c index 4c405ec..0a54e13 100644 --- a/src/options.c +++ b/src/options.c @@ -94,13 +94,13 @@ static char *rs_greek_keyboard = NULL; unsigned long Options = (Opt_scrollbar | Opt_select_trailing_spaces), image_toggles = 0; char *theme_dir = NULL, *user_dir = NULL; -char **rs_exec_args = NULL; /* Args to exec (-e or --exec) */ -char *rs_title = NULL; /* Window title */ -char *rs_iconName = NULL; /* Icon name */ -char *rs_geometry = NULL; /* Geometry string */ +char **rs_exec_args = NULL; /* Args to exec (-e or --exec) */ +char *rs_title = NULL; /* Window title */ +char *rs_iconName = NULL; /* Icon name */ +char *rs_geometry = NULL; /* Geometry string */ int rs_desktop = -1; char *rs_path = NULL; -int rs_saveLines = SAVELINES; /* Lines in the scrollback buffer */ +int rs_saveLines = SAVELINES; /* Lines in the scrollback buffer */ #ifdef USE_XIM char *rs_input_method = NULL; char *rs_preedit_type = NULL; @@ -136,10 +136,13 @@ static char *rs_pixmaps[image_max]; #endif char *rs_theme = NULL; char *rs_config_file = NULL; +#ifdef ESCREEN +char *rs_url = NULL; +#endif unsigned int rs_line_space = 0; unsigned int rs_meta_mod = 0, rs_alt_mod = 0, rs_numlock_mod = 0; #ifdef KEYSYM_ATTRIBUTE -unsigned char *KeySym_map[256]; /* probably mostly empty */ +unsigned char *KeySym_map[256]; /* probably mostly empty */ #endif #if defined (HOTKEY_CTRL) || defined (HOTKEY_META) /* recognized when combined with HOTKEY */ @@ -149,192 +152,182 @@ KeySym ks_smallfont = XK_less; /* Options structure */ static const struct { - char short_opt; - char *long_opt; - const char *const description; - unsigned short flag; - const void *pval; - unsigned long *maskvar; - int mask; + char short_opt; + char *long_opt; + const char *const description; + unsigned short flag; + const void *pval; + unsigned long *maskvar; + int mask; } optList[] = { - OPT_STR('t', "theme", "select a theme", &rs_theme), - OPT_STR('X', "config-file", "choose an alternate config file", &rs_config_file), - OPT_STR('d', "display", "X server to connect to", &display_name), -#if DEBUG <= 0 - OPT_ILONG("debug", "level of debugging information to show (support not compiled in)", &DEBUG_LEVEL), -#elif DEBUG == 1 - OPT_ILONG("debug", "level of debugging information to show (0-1)", &DEBUG_LEVEL), -#elif DEBUG == 2 - OPT_ILONG("debug", "level of debugging information to show (0-2)", &DEBUG_LEVEL), -#elif DEBUG == 3 - OPT_ILONG("debug", "level of debugging information to show (0-3)", &DEBUG_LEVEL), -#elif DEBUG == 4 - OPT_ILONG("debug", "level of debugging information to show (0-4)", &DEBUG_LEVEL), -#else - OPT_ILONG("debug", "level of debugging information to show (0-5)", &DEBUG_LEVEL), + OPT_STR('t', "theme", "select a theme", &rs_theme), + OPT_STR('X', "config-file", "choose an alternate config file", &rs_config_file), + OPT_STR('d', "display", "X server to connect to", &display_name), +#ifdef ESCREEN + OPT_STR('U', "URL", "an URL pointing at a screen-session to pick up", &rs_url), #endif - OPT_BLONG("install", "install a private colormap", &Options, Opt_install), - - OPT_BOOL('h', "help", "display usage information", NULL, 0), - OPT_BLONG("version", "display version and configuration information", NULL, 0), - +#if DEBUG <= 0 + OPT_ILONG("debug", "level of debugging information to show (support not compiled in)", &DEBUG_LEVEL), +#elif DEBUG == 1 + OPT_ILONG("debug", "level of debugging information to show (0-1)", &DEBUG_LEVEL), +#elif DEBUG == 2 + OPT_ILONG("debug", "level of debugging information to show (0-2)", &DEBUG_LEVEL), +#elif DEBUG == 3 + OPT_ILONG("debug", "level of debugging information to show (0-3)", &DEBUG_LEVEL), +#elif DEBUG == 4 + OPT_ILONG("debug", "level of debugging information to show (0-4)", &DEBUG_LEVEL), +#else + OPT_ILONG("debug", "level of debugging information to show (0-5)", &DEBUG_LEVEL), +#endif + OPT_BLONG("install", "install a private colormap", &Options, Opt_install), + OPT_BOOL('h', "help", "display usage information", NULL, 0), + OPT_BLONG("version", "display version and configuration information", NULL, 0), /* =======[ Color options ]======= */ - OPT_BOOL('r', "reverse-video", "reverse video", &Options, Opt_reverse_video), - OPT_STR('b', "background-color", "background color", &rs_color[bgColor]), - OPT_STR('f', "foreground-color", "foreground color", &rs_color[fgColor]), - OPT_LONG("color0", "color 0", &rs_color[minColor]), - OPT_LONG("color1", "color 1", &rs_color[minColor + 1]), - OPT_LONG("color2", "color 2", &rs_color[minColor + 2]), - OPT_LONG("color3", "color 3", &rs_color[minColor + 3]), - OPT_LONG("color4", "color 4", &rs_color[minColor + 4]), - OPT_LONG("color5", "color 5", &rs_color[minColor + 5]), - OPT_LONG("color6", "color 6", &rs_color[minColor + 6]), - OPT_LONG("color7", "color 7", &rs_color[minColor + 7]), + OPT_BOOL('r', "reverse-video", "reverse video", &Options, Opt_reverse_video), + OPT_STR('b', "background-color", "background color", &rs_color[bgColor]), + OPT_STR('f', "foreground-color", "foreground color", &rs_color[fgColor]), + OPT_LONG("color0", "color 0", &rs_color[minColor]), + OPT_LONG("color1", "color 1", &rs_color[minColor + 1]), + OPT_LONG("color2", "color 2", &rs_color[minColor + 2]), + OPT_LONG("color3", "color 3", &rs_color[minColor + 3]), + OPT_LONG("color4", "color 4", &rs_color[minColor + 4]), + OPT_LONG("color5", "color 5", &rs_color[minColor + 5]), + OPT_LONG("color6", "color 6", &rs_color[minColor + 6]), OPT_LONG("color7", "color 7", &rs_color[minColor + 7]), #ifndef NO_BRIGHTCOLOR - OPT_LONG("color8", "color 8", &rs_color[minBright]), - OPT_LONG("color9", "color 9", &rs_color[minBright + 1]), - OPT_LONG("color10", "color 10", &rs_color[minBright + 2]), - OPT_LONG("color11", "color 11", &rs_color[minBright + 3]), - OPT_LONG("color12", "color 12", &rs_color[minBright + 4]), - OPT_LONG("color13", "color 13", &rs_color[minBright + 5]), - OPT_LONG("color14", "color 14", &rs_color[minBright + 6]), - OPT_LONG("color15", "color 15", &rs_color[minBright + 7]), + OPT_LONG("color8", "color 8", &rs_color[minBright]), + OPT_LONG("color9", "color 9", &rs_color[minBright + 1]), + OPT_LONG("color10", "color 10", &rs_color[minBright + 2]), + OPT_LONG("color11", "color 11", &rs_color[minBright + 3]), + OPT_LONG("color12", "color 12", &rs_color[minBright + 4]), + OPT_LONG("color13", "color 13", &rs_color[minBright + 5]), + OPT_LONG("color14", "color 14", &rs_color[minBright + 6]), OPT_LONG("color15", "color 15", &rs_color[minBright + 7]), #endif /* NO_BRIGHTCOLOR */ #ifndef NO_BOLDUNDERLINE - OPT_LONG("colorBD", "bold color", &rs_color[colorBD]), - OPT_LONG("colorUL", "underline color", &rs_color[colorUL]), + OPT_LONG("colorBD", "bold color", &rs_color[colorBD]), OPT_LONG("colorUL", "underline color", &rs_color[colorUL]), #endif /* NO_BOLDUNDERLINE */ - OPT_LONG("pointer-color", "mouse pointer color", &rs_color[pointerColor]), + OPT_LONG("pointer-color", "mouse pointer color", &rs_color[pointerColor]), #ifndef NO_CURSORCOLOR - OPT_STR('c', "cursor-color", "cursor color", &rs_color[cursorColor]), - OPT_LONG("cursor-text-color", "cursor text color", &rs_color[cursorColor2]), + OPT_STR('c', "cursor-color", "cursor color", &rs_color[cursorColor]), + OPT_LONG("cursor-text-color", "cursor text color", &rs_color[cursorColor2]), #endif /* NO_CURSORCOLOR */ - /* =======[ X11 options ]======= */ - OPT_STR('g', "geometry", "WxH+X+Y = size and position", &rs_geometry), - OPT_BOOL('i', "iconic", "start iconified", &Options, Opt_iconic), - OPT_STR('n', "name", "client instance, icon, and title strings", &rs_name), - OPT_STR('T', "title", "title string", &rs_title), - OPT_LONG("icon-name", "icon name", &rs_iconName), - OPT_STR('B', "scrollbar-type", "choose the scrollbar type (motif, next, xterm)", &rs_scrollbar_type), - OPT_ILONG("scrollbar-width", "choose the width (in pixels) of the scrollbar", &rs_scrollbar_width), - OPT_INT('D', "desktop", "desktop to start on (requires GNOME-compliant window manager)", &rs_desktop), - OPT_ILONG("line-space", "number of extra dots between lines", &rs_line_space), + OPT_STR('g', "geometry", "WxH+X+Y = size and position", &rs_geometry), + OPT_BOOL('i', "iconic", "start iconified", &Options, Opt_iconic), + OPT_STR('n', "name", "client instance, icon, and title strings", &rs_name), + OPT_STR('T', "title", "title string", &rs_title), + OPT_LONG("icon-name", "icon name", &rs_iconName), + OPT_STR('B', "scrollbar-type", "choose the scrollbar type (motif, next, xterm)", &rs_scrollbar_type), + OPT_ILONG("scrollbar-width", "choose the width (in pixels) of the scrollbar", &rs_scrollbar_width), + OPT_INT('D', "desktop", "desktop to start on (requires GNOME-compliant window manager)", &rs_desktop), + OPT_ILONG("line-space", "number of extra dots between lines", &rs_line_space), #ifndef NO_BOLDFONT - OPT_LONG("bold-font", "bold text font", &rs_boldFont), + OPT_LONG("bold-font", "bold text font", &rs_boldFont), #endif - OPT_STR('F', "font", "normal text font", &rs_font[0]), - OPT_ILONG("default-font-index", "set the index of the default font", &def_font_idx), - OPT_LONG("font1", "font 1", &rs_font[1]), - OPT_LONG("font2", "font 2", &rs_font[2]), - OPT_LONG("font3", "font 3", &rs_font[3]), - OPT_LONG("font4", "font 4", &rs_font[4]), - OPT_BLONG("proportional", "toggle proportional font optimizations", &Options, Opt_proportional), - OPT_LONG("font-fx", "specify font effects for the terminal fonts", &rs_font_effects), - + OPT_STR('F', "font", "normal text font", &rs_font[0]), + OPT_ILONG("default-font-index", "set the index of the default font", &def_font_idx), + OPT_LONG("font1", "font 1", &rs_font[1]), + OPT_LONG("font2", "font 2", &rs_font[2]), + OPT_LONG("font3", "font 3", &rs_font[3]), + OPT_LONG("font4", "font 4", &rs_font[4]), + OPT_BLONG("proportional", "toggle proportional font optimizations", &Options, Opt_proportional), + OPT_LONG("font-fx", "specify font effects for the terminal fonts", &rs_font_effects), /* =======[ Pixmap options ]======= */ #ifdef PIXMAP_SUPPORT - OPT_STR('P', "background-pixmap", "background pixmap [scaling optional]", &rs_pixmaps[image_bg]), - OPT_STR('I', "icon", "icon pixmap", &rs_icon), - OPT_LONG("up-arrow-pixmap", "up arrow pixmap [scaling optional]", &rs_pixmaps[image_up]), - OPT_LONG("down-arrow-pixmap", "down arrow pixmap [scaling optional]", &rs_pixmaps[image_down]), - OPT_LONG("trough-pixmap", "scrollbar background (trough) pixmap [scaling optional]", &rs_pixmaps[image_sb]), - OPT_LONG("anchor-pixmap", "scrollbar anchor pixmap [scaling optional]", &rs_pixmaps[image_sa]), - OPT_LONG("menu-pixmap", "menu pixmap [scaling optional]", &rs_pixmaps[image_menu]), - OPT_BOOL('O', "trans", "creates a pseudo-transparent Eterm", &image_toggles, IMOPT_TRANS), - OPT_BOOL('0', "itrans", "use immotile-optimized transparency", &image_toggles, IMOPT_ITRANS), - OPT_BLONG("viewport-mode", "use viewport mode for the background image", &image_toggles, IMOPT_VIEWPORT), - OPT_ILONG("shade", "old-style shade percentage (deprecated)", &rs_shade), - OPT_LONG("tint", "old-style tint mask (deprecated)", &rs_tint), - OPT_LONG("cmod", "image color modifier (\"brightness contrast gamma\")", &rs_cmod_image), - OPT_LONG("cmod-red", "red-only color modifier (\"brightness contrast gamma\")", &rs_cmod_red), - OPT_LONG("cmod-green", "green-only color modifier (\"brightness contrast gamma\")", &rs_cmod_green), - OPT_LONG("cmod-blue", "blue-only color modifier (\"brightness contrast gamma\")", &rs_cmod_blue), - OPT_STR('p', "path", "pixmap file search path", &rs_path), - OPT_ILONG("cache", "set Imlib2 image/pixmap cache size", &rs_cache_size), + OPT_STR('P', "background-pixmap", "background pixmap [scaling optional]", &rs_pixmaps[image_bg]), + OPT_STR('I', "icon", "icon pixmap", &rs_icon), + OPT_LONG("up-arrow-pixmap", "up arrow pixmap [scaling optional]", &rs_pixmaps[image_up]), + OPT_LONG("down-arrow-pixmap", "down arrow pixmap [scaling optional]", &rs_pixmaps[image_down]), + OPT_LONG("trough-pixmap", "scrollbar background (trough) pixmap [scaling optional]", &rs_pixmaps[image_sb]), + OPT_LONG("anchor-pixmap", "scrollbar anchor pixmap [scaling optional]", &rs_pixmaps[image_sa]), + OPT_LONG("menu-pixmap", "menu pixmap [scaling optional]", &rs_pixmaps[image_menu]), + OPT_BOOL('O', "trans", "creates a pseudo-transparent Eterm", &image_toggles, IMOPT_TRANS), + OPT_BOOL('0', "itrans", "use immotile-optimized transparency", &image_toggles, IMOPT_ITRANS), + OPT_BLONG("viewport-mode", "use viewport mode for the background image", &image_toggles, IMOPT_VIEWPORT), + OPT_ILONG("shade", "old-style shade percentage (deprecated)", &rs_shade), + OPT_LONG("tint", "old-style tint mask (deprecated)", &rs_tint), + OPT_LONG("cmod", "image color modifier (\"brightness contrast gamma\")", &rs_cmod_image), + OPT_LONG("cmod-red", "red-only color modifier (\"brightness contrast gamma\")", &rs_cmod_red), + OPT_LONG("cmod-green", "green-only color modifier (\"brightness contrast gamma\")", &rs_cmod_green), + OPT_LONG("cmod-blue", "blue-only color modifier (\"brightness contrast gamma\")", &rs_cmod_blue), + OPT_STR('p', "path", "pixmap file search path", &rs_path), OPT_ILONG("cache", "set Imlib2 image/pixmap cache size", &rs_cache_size), # ifdef BACKGROUND_CYCLING_SUPPORT - OPT_STR('N', "anim", "a delay and list of pixmaps for cycling", &rs_anim_pixmap_list), -# endif /* BACKGROUND_CYCLING_SUPPORT */ + OPT_STR('N', "anim", "a delay and list of pixmaps for cycling", &rs_anim_pixmap_list), +# endif /* BACKGROUND_CYCLING_SUPPORT */ #endif /* PIXMAP_SUPPORT */ - /* =======[ Kanji options ]======= */ #ifdef MULTI_CHARSET - OPT_STR('M', "mfont", "normal text multichar font", &rs_mfont[0]), - OPT_LONG("mfont1", "multichar font 1", &rs_mfont[1]), - OPT_LONG("mfont2", "multichar font 2", &rs_mfont[2]), - OPT_LONG("mfont3", "multichar font 3", &rs_mfont[3]), - OPT_LONG("mfont4", "multichar font 4", &rs_mfont[4]), - OPT_LONG("mencoding", "multichar encoding mode (eucj/sjis/euckr/big5/gb)", &rs_multichar_encoding), + OPT_STR('M', "mfont", "normal text multichar font", &rs_mfont[0]), + OPT_LONG("mfont1", "multichar font 1", &rs_mfont[1]), + OPT_LONG("mfont2", "multichar font 2", &rs_mfont[2]), + OPT_LONG("mfont3", "multichar font 3", &rs_mfont[3]), + OPT_LONG("mfont4", "multichar font 4", &rs_mfont[4]), + OPT_LONG("mencoding", "multichar encoding mode (eucj/sjis/euckr/big5/gb)", &rs_multichar_encoding), #endif /* MULTI_CHARSET */ #ifdef USE_XIM - OPT_LONG("input-method", "XIM input method", &rs_input_method), - OPT_LONG("preedit-type", "XIM preedit type", &rs_preedit_type), + OPT_LONG("input-method", "XIM input method", &rs_input_method), OPT_LONG("preedit-type", "XIM preedit type", &rs_preedit_type), #endif - /* =======[ Toggles ]======= */ - OPT_BOOL('l', "login-shell", "login shell, prepend - to shell name", &Options, Opt_login_shell), - OPT_BOOL('s', "scrollbar", "display scrollbar", &Options, Opt_scrollbar), - OPT_BOOL('u', "utmp-logging", "make a utmp entry", &Options, Opt_write_utmp), - OPT_BOOL('v', "visual-bell", "visual bell", &Options, Opt_visual_bell), - OPT_BOOL('H', "home-on-output", "jump to bottom on output", &Options, Opt_home_on_output), - OPT_BLONG("home-on-input", "jump to bottom on input", &Options, Opt_home_on_input), - OPT_BOOL('q', "no-input", "configure for output only", &Options, Opt_no_input), - OPT_BLONG("scrollbar-right", "display the scrollbar on the right", &Options, Opt_scrollbar_right), - OPT_BLONG("scrollbar-floating", "display the scrollbar with no trough", &Options, Opt_scrollbar_floating), - OPT_BLONG("scrollbar-popup", "popup the scrollbar only when focused", &Options, Opt_scrollbar_popup), - OPT_BOOL('x', "borderless", "force Eterm to have no borders", &Options, Opt_borderless), + OPT_BOOL('l', "login-shell", "login shell, prepend - to shell name", &Options, Opt_login_shell), + OPT_BOOL('s', "scrollbar", "display scrollbar", &Options, Opt_scrollbar), + OPT_BOOL('u', "utmp-logging", "make a utmp entry", &Options, Opt_write_utmp), + OPT_BOOL('v', "visual-bell", "visual bell", &Options, Opt_visual_bell), + OPT_BOOL('H', "home-on-output", "jump to bottom on output", &Options, Opt_home_on_output), + OPT_BLONG("home-on-input", "jump to bottom on input", &Options, Opt_home_on_input), + OPT_BOOL('q', "no-input", "configure for output only", &Options, Opt_no_input), + OPT_BLONG("scrollbar-right", "display the scrollbar on the right", &Options, Opt_scrollbar_right), + OPT_BLONG("scrollbar-floating", "display the scrollbar with no trough", &Options, Opt_scrollbar_floating), + OPT_BLONG("scrollbar-popup", "popup the scrollbar only when focused", &Options, Opt_scrollbar_popup), + OPT_BOOL('x', "borderless", "force Eterm to have no borders", &Options, Opt_borderless), #ifndef NO_MAPALERT # ifdef MAPALERT_OPTION - OPT_BOOL('m', "map-alert", "uniconify on beep", &Options, Opt_map_alert), + OPT_BOOL('m', "map-alert", "uniconify on beep", &Options, Opt_map_alert), # endif #endif #ifdef META8_OPTION - OPT_BOOL('8', "meta-8", "Meta key toggles 8-bit", &Options, Opt_meta8), + OPT_BOOL('8', "meta-8", "Meta key toggles 8-bit", &Options, Opt_meta8), #endif - OPT_BLONG("double-buffer", "use double-buffering to reduce exposes (uses more memory)", &Options, Opt_double_buffer), - OPT_BLONG("no-cursor", "disable the text cursor", &Options, Opt_no_cursor), - OPT_BLONG("pause", "pause after the child process exits", &Options, Opt_pause), - OPT_BLONG("xterm-select", "duplicate xterm's broken selection behavior", &Options, Opt_xterm_select), - OPT_BLONG("select-line", "triple-click selects whole line", &Options, Opt_select_whole_line), - OPT_BLONG("select-trailing-spaces", "do not skip trailing spaces when selecting", &Options, Opt_select_trailing_spaces), - OPT_BLONG("report-as-keysyms", "report special keys as keysyms", &Options, Opt_report_as_keysyms), - OPT_BLONG("buttonbar", "toggle the display of all buttonbars", &rs_buttonbars, BBAR_FORCE_TOGGLE), - OPT_BLONG("resize-gravity", "toggle gravitation to nearest corner on resize", &Options, Opt_resize_gravity), - + OPT_BLONG("double-buffer", "use double-buffering to reduce exposes (uses more memory)", &Options, Opt_double_buffer), + OPT_BLONG("no-cursor", "disable the text cursor", &Options, Opt_no_cursor), + OPT_BLONG("pause", "pause after the child process exits", &Options, Opt_pause), + OPT_BLONG("xterm-select", "duplicate xterm's broken selection behavior", &Options, Opt_xterm_select), + OPT_BLONG("select-line", "triple-click selects whole line", &Options, Opt_select_whole_line), + OPT_BLONG("select-trailing-spaces", "do not skip trailing spaces when selecting", &Options, Opt_select_trailing_spaces), + OPT_BLONG("report-as-keysyms", "report special keys as keysyms", &Options, Opt_report_as_keysyms), + OPT_BLONG("buttonbar", "toggle the display of all buttonbars", &rs_buttonbars, BBAR_FORCE_TOGGLE), + OPT_BLONG("resize-gravity", "toggle gravitation to nearest corner on resize", &Options, Opt_resize_gravity), /* =======[ Keyboard options ]======= */ #if defined (HOTKEY_CTRL) || defined (HOTKEY_META) - OPT_LONG("big-font-key", "keysym for font size increase", &rs_bigfont_key), - OPT_LONG("small-font-key", "keysym for font size decrease", &rs_smallfont_key), + OPT_LONG("big-font-key", "keysym for font size increase", &rs_bigfont_key), + OPT_LONG("small-font-key", "keysym for font size decrease", &rs_smallfont_key), #endif - OPT_ILONG("meta-mod", "modifier to interpret as the Meta key", &rs_meta_mod), - OPT_ILONG("alt-mod", "modifier to interpret as the Alt key", &rs_alt_mod), - OPT_ILONG("numlock-mod", "modifier to interpret as the NumLock key", &rs_numlock_mod), + OPT_ILONG("meta-mod", "modifier to interpret as the Meta key", &rs_meta_mod), + OPT_ILONG("alt-mod", "modifier to interpret as the Alt key", &rs_alt_mod), + OPT_ILONG("numlock-mod", "modifier to interpret as the NumLock key", &rs_numlock_mod), #ifdef GREEK_SUPPORT - OPT_LONG("greek-keyboard", "greek keyboard mapping (iso or ibm)", &rs_greek_keyboard), + OPT_LONG("greek-keyboard", "greek keyboard mapping (iso or ibm)", &rs_greek_keyboard), #endif - OPT_BLONG("app-keypad", "application keypad mode", &PrivateModes, PrivMode_aplKP), - OPT_BLONG("app-cursor", "application cursor key mode", &PrivateModes, PrivMode_aplCUR), - + OPT_BLONG("app-keypad", "application keypad mode", &PrivateModes, PrivMode_aplKP), + OPT_BLONG("app-cursor", "application cursor key mode", &PrivateModes, PrivMode_aplCUR), /* =======[ Misc options ]======= */ - OPT_INT('L', "save-lines", "lines to save in scrollback buffer", &rs_saveLines), - OPT_ILONG("min-anchor-size", "minimum size of the scrollbar anchor", &rs_min_anchor_size), + OPT_INT('L', "save-lines", "lines to save in scrollback buffer", &rs_saveLines), + OPT_ILONG("min-anchor-size", "minimum size of the scrollbar anchor", &rs_min_anchor_size), #ifdef BORDER_WIDTH_OPTION - OPT_INT('w', "border-width", "term window border width", &(TermWin.internalBorder)), + OPT_INT('w', "border-width", "term window border width", &(TermWin.internalBorder)), #endif #ifdef PRINTPIPE - OPT_LONG("print-pipe", "print command", &rs_print_pipe), + OPT_LONG("print-pipe", "print command", &rs_print_pipe), #endif #ifdef CUTCHAR_OPTION - OPT_LONG("cut-chars", "seperators for double-click selection", &rs_cutchars), + OPT_LONG("cut-chars", "seperators for double-click selection", &rs_cutchars), #endif /* CUTCHAR_OPTION */ - OPT_LONG("finished-title", "text to add to window title after program termination", &rs_finished_title), - OPT_LONG("finished-text", "text to output after program termination", &rs_finished_text), - OPT_LONG("term-name", "value to use for setting $TERM", &rs_term_name), - OPT_LONG("pipe-name", "filename of console pipe to emulate -C", &rs_pipe_name), - OPT_STR('a', "attribute", "parse an attribute in the specified context", NULL), - OPT_BOOL('C', "console", "grab console messages", &Options, Opt_console), - OPT_ARGS('e', "exec", "execute a command rather than a shell", &rs_exec_args) + OPT_LONG("finished-title", "text to add to window title after program termination", &rs_finished_title), + OPT_LONG("finished-text", "text to output after program termination", &rs_finished_text), + OPT_LONG("term-name", "value to use for setting $TERM", &rs_term_name), + OPT_LONG("pipe-name", "filename of console pipe to emulate -C", &rs_pipe_name), + OPT_STR('a', "attribute", "parse an attribute in the specified context", NULL), + OPT_BOOL('C', "console", "grab console messages", &Options, Opt_console), + OPT_ARGS('e', "exec", "execute a command rather than a shell", &rs_exec_args) }; /* Print usage information */ @@ -343,41 +336,40 @@ static void usage(void) { - unsigned short i, col; + unsigned short i, col; - printf("Eterm Enlightened Terminal Emulator for the X Window System\n"); - printf("Copyright (c) 1997-2002, " AUTHORS "\n\n"); - printf("Usage for " APL_NAME " " VERSION ":\n\n"); - printf("%7s %17s %40s\n", "POSIX", "GNU", "Description"); - printf("%8s %10s %41s\n", "=======", "===============================", - "========================================="); - for (i = 0; i < optList_numoptions(); i++) { - printf("%" INDENT "s", " "); - if (optList[i].short_opt) { - printf("-%c, ", optList[i].short_opt); - } else { - printf(" "); + printf("Eterm Enlightened Terminal Emulator for the X Window System\n"); + printf("Copyright (c) 1997-2002, " AUTHORS "\n\n"); + printf("Usage for " APL_NAME " " VERSION ":\n\n"); + printf("%7s %17s %40s\n", "POSIX", "GNU", "Description"); + printf("%8s %10s %41s\n", "=======", "===============================", "========================================="); + for (i = 0; i < optList_numoptions(); i++) { + printf("%" INDENT "s", " "); + if (optList[i].short_opt) { + printf("-%c, ", optList[i].short_opt); + } else { + printf(" "); + } + printf("--%s", optList[i].long_opt); + for (col = strlen(optList[i].long_opt); col < 30; col++) { + printf(" "); + } + printf("%s\n", optList[i].description); } - printf("--%s", optList[i].long_opt); - for (col = strlen(optList[i].long_opt); col < 30; col++) { - printf(" "); - } - printf("%s\n", optList[i].description); - } - printf("\nOption types:\n"); - printf(" (bool) -- Boolean option ('1', 'on', 'yes', or 'true' to activate, '0', 'off', 'no', or 'false' to deactivate)\n"); - printf(" (int) -- Integer option (any signed number of reasonable value, usually in decimal/octal/hex)\n"); - printf(" (str) -- String option (be sure to quote strings if needed to avoid shell expansion)\n\n"); + printf("\nOption types:\n"); + printf(" (bool) -- Boolean option ('1', 'on', 'yes', or 'true' to activate, '0', 'off', 'no', or 'false' to deactivate)\n"); + printf(" (int) -- Integer option (any signed number of reasonable value, usually in decimal/octal/hex)\n"); + printf(" (str) -- String option (be sure to quote strings if needed to avoid shell expansion)\n\n"); - printf("NOTE: Long options can be separated from their values by an equal sign ('='), or you can\n"); - printf(" pass the value as the following argument on the command line (e.g., '--scrollbar 0'\n"); - printf(" or '--scrollbar=0'). Short options must have their values passed after them on the\n"); - printf(" command line, and in the case of boolean short options, cannot have values (they\n"); - printf(" default to true) (e.g., '-F shine' or '-s').\n"); + printf("NOTE: Long options can be separated from their values by an equal sign ('='), or you can\n"); + printf(" pass the value as the following argument on the command line (e.g., '--scrollbar 0'\n"); + printf(" or '--scrollbar=0'). Short options must have their values passed after them on the\n"); + printf(" command line, and in the case of boolean short options, cannot have values (they\n"); + printf(" default to true) (e.g., '-F shine' or '-s').\n"); - printf("\nPlease consult the Eterm(1) man page for more detailed\n"); - printf("information on command line options.\n\n"); - exit(EXIT_FAILURE); + printf("\nPlease consult the Eterm(1) man page for more detailed\n"); + printf("information on command line options.\n\n"); + exit(EXIT_FAILURE); } /* Print version and configuration information */ @@ -385,2345 +377,2362 @@ static void version(void) { - printf("Eterm " VERSION "\n"); - printf("Copyright (c) 1997-2002, " AUTHORS "\n\n"); + printf("Eterm " VERSION "\n"); + printf("Copyright (c) 1997-2002, " AUTHORS "\n\n"); - printf("Build info:\n"); - printf(" Built on " BUILD_DATE "\n"); - printf(" " ACTIONS_IDENT "\n" - " " BUTTONS_IDENT "\n" - " " COMMAND_IDENT "\n" - " " DRAW_IDENT "\n" - " " E_IDENT "\n" - " " EVENTS_IDENT "\n" - " " FONT_IDENT "\n" - " " GRKELOT_IDENT "\n" - " " MAIN_IDENT "\n" - " " MENUS_IDENT "\n" - " " MISC_IDENT "\n" - " " NETDISP_IDENT "\n" - " " OPTIONS_IDENT "\n" - " " PIXMAP_IDENT "\n" - " " SCREEN_IDENT "\n" - " " SCROLLBAR_IDENT "\n" - " " STARTUP_IDENT "\n" - " " SYSTEM_IDENT "\n" - " " TERM_IDENT "\n" - " " TIMER_IDENT "\n" - " " UTMP_IDENT "\n" - " " WINDOWS_IDENT "\n" - "\n"); + printf("Build info:\n"); + printf(" Built on " BUILD_DATE "\n"); + printf(" " ACTIONS_IDENT "\n" + " " BUTTONS_IDENT "\n" + " " COMMAND_IDENT "\n" + " " DRAW_IDENT "\n" + " " E_IDENT "\n" + " " EVENTS_IDENT "\n" + " " FONT_IDENT "\n" + " " GRKELOT_IDENT "\n" + " " MAIN_IDENT "\n" + " " MENUS_IDENT "\n" + " " MISC_IDENT "\n" + " " NETDISP_IDENT "\n" + " " OPTIONS_IDENT "\n" + " " PIXMAP_IDENT "\n" + " " SCREEN_IDENT "\n" + " " SCROLLBAR_IDENT "\n" + " " STARTUP_IDENT "\n" + " " SYSTEM_IDENT "\n" " " TERM_IDENT "\n" " " TIMER_IDENT "\n" " " UTMP_IDENT "\n" " " WINDOWS_IDENT "\n" "\n"); - printf("Debugging configuration: "); + printf("Debugging configuration: "); #ifdef DEBUG - printf("DEBUG=%d", DEBUG); + printf("DEBUG=%d", DEBUG); #else - printf("-DEBUG"); + printf("-DEBUG"); #endif #if DEBUG >= DEBUG_SCREEN - printf(" +DEBUG_SCREEN"); + printf(" +DEBUG_SCREEN"); #endif #if DEBUG >= DEBUG_CMD - printf(" +DEBUG_CMD"); + printf(" +DEBUG_CMD"); #endif #if DEBUG >= DEBUG_TTY - printf(" +DEBUG_TTY"); + printf(" +DEBUG_TTY"); #endif #if DEBUG >= DEBUG_SELECTION - printf(" +DEBUG_SELECTION"); + printf(" +DEBUG_SELECTION"); #endif #if DEBUG >= DEBUG_UTMP - printf(" +DEBUG_UTMP"); + printf(" +DEBUG_UTMP"); #endif #if DEBUG >= DEBUG_OPTIONS - printf(" +DEBUG_OPTIONS"); + printf(" +DEBUG_OPTIONS"); #endif #if DEBUG >= DEBUG_IMLIB - printf(" +DEBUG_IMLIB"); + printf(" +DEBUG_IMLIB"); #endif #if DEBUG >= DEBUG_PIXMAP - printf(" +DEBUG_PIXMAP"); + printf(" +DEBUG_PIXMAP"); #endif #if DEBUG >= DEBUG_EVENTS - printf(" +DEBUG_EVENTS"); + printf(" +DEBUG_EVENTS"); #endif #if DEBUG >= DEBUG_MEM - printf(" +DEBUG_MEM"); + printf(" +DEBUG_MEM"); #endif #if DEBUG >= DEBUG_X11 - printf(" +DEBUG_X11"); + printf(" +DEBUG_X11"); #endif #if DEBUG >= DEBUG_SCROLLBAR - printf(" +DEBUG_SCROLLBAR"); + printf(" +DEBUG_SCROLLBAR"); #endif #if DEBUG >= DEBUG_MENU - printf(" +DEBUG_MENU"); + printf(" +DEBUG_MENU"); #endif #if DEBUG >= DEBUG_TTYMODE - printf(" +DEBUG_TTYMODE"); + printf(" +DEBUG_TTYMODE"); #endif #if DEBUG >= DEBUG_COLORS - printf(" +DEBUG_COLORS"); + printf(" +DEBUG_COLORS"); #endif #if DEBUG >= DEBUG_X - printf(" +DEBUG_X"); + printf(" +DEBUG_X"); #endif - printf("\n\nCompile-time toggles: "); + printf("\n\nCompile-time toggles: "); #ifdef PROFILE - printf(" +PROFILE"); + printf(" +PROFILE"); #else - printf(" -PROFILE"); + printf(" -PROFILE"); #endif #ifdef PROFILE_SCREEN - printf(" +PROFILE_SCREEN"); + printf(" +PROFILE_SCREEN"); #else - printf(" -PROFILE_SCREEN"); + printf(" -PROFILE_SCREEN"); #endif #ifdef PROFILE_X_EVENTS - printf(" +PROFILE_X_EVENTS"); + printf(" +PROFILE_X_EVENTS"); #else - printf(" -PROFILE_X_EVENTS"); + printf(" -PROFILE_X_EVENTS"); #endif #ifdef COUNT_X_EVENTS - printf(" +COUNT_X_EVENTS"); + printf(" +COUNT_X_EVENTS"); #else - printf(" -COUNT_X_EVENTS"); + printf(" -COUNT_X_EVENTS"); #endif #ifdef OPTIMIZE_HACKS - printf(" +OPTIMIZE_HACKS"); + printf(" +OPTIMIZE_HACKS"); #else - printf(" -OPTIMIZE_HACKS"); + printf(" -OPTIMIZE_HACKS"); #endif #ifdef PIXMAP_SUPPORT - printf(" +PIXMAP_SUPPORT"); + printf(" +PIXMAP_SUPPORT"); #else - printf(" -PIXMAP_SUPPORT"); + printf(" -PIXMAP_SUPPORT"); #endif #ifdef PIXMAP_OFFSET - printf(" +PIXMAP_OFFSET"); + printf(" +PIXMAP_OFFSET"); #else - printf(" -PIXMAP_OFFSET"); + printf(" -PIXMAP_OFFSET"); #endif #ifdef BACKGROUND_CYCLING_SUPPORT - printf(" +BACKGROUND_CYCLING_SUPPORT"); + printf(" +BACKGROUND_CYCLING_SUPPORT"); #else - printf(" -BACKGROUND_CYCLING_SUPPORT"); + printf(" -BACKGROUND_CYCLING_SUPPORT"); #endif #ifdef USE_EFFECTS - printf(" +USE_EFFECTS"); + printf(" +USE_EFFECTS"); #else - printf(" -USE_EFFECTS"); + printf(" -USE_EFFECTS"); #endif #ifdef NO_CURSORCOLOR - printf(" +NO_CURSORCOLOR"); + printf(" +NO_CURSORCOLOR"); #else - printf(" -NO_CURSORCOLOR"); + printf(" -NO_CURSORCOLOR"); #endif #ifdef NO_BRIGHTCOLOR - printf(" +NO_BRIGHTCOLOR"); + printf(" +NO_BRIGHTCOLOR"); #else - printf(" -NO_BRIGHTCOLOR"); + printf(" -NO_BRIGHTCOLOR"); #endif #ifdef NO_BOLDUNDERLINE - printf(" +NO_BOLDUNDERLINE"); + printf(" +NO_BOLDUNDERLINE"); #else - printf(" -NO_BOLDUNDERLINE"); + printf(" -NO_BOLDUNDERLINE"); #endif #ifdef NO_BOLDOVERSTRIKE - printf(" +NO_BOLDOVERSTRIKE"); + printf(" +NO_BOLDOVERSTRIKE"); #else - printf(" -NO_BOLDOVERSTRIKE"); + printf(" -NO_BOLDOVERSTRIKE"); #endif #ifdef NO_BOLDFONT - printf(" +NO_BOLDFONT"); + printf(" +NO_BOLDFONT"); #else - printf(" -NO_BOLDFONT"); + printf(" -NO_BOLDFONT"); #endif #ifdef NO_SECONDARY_SCREEN - printf(" +NO_SECONDARY_SCREEN"); + printf(" +NO_SECONDARY_SCREEN"); #else - printf(" -NO_SECONDARY_SCREEN"); + printf(" -NO_SECONDARY_SCREEN"); #endif #ifdef FORCE_CLEAR_CHARS - printf(" +FORCE_CLEAR_CHARS"); + printf(" +FORCE_CLEAR_CHARS"); #else - printf(" -FORCE_CLEAR_CHARS"); + printf(" -FORCE_CLEAR_CHARS"); #endif #ifdef PREFER_24BIT - printf(" +PREFER_24BIT"); + printf(" +PREFER_24BIT"); #else - printf(" -PREFER_24BIT"); + printf(" -PREFER_24BIT"); #endif #ifdef OFFIX_DND - printf(" +OFFIX_DND"); + printf(" +OFFIX_DND"); #else - printf(" -OFFIX_DND"); + printf(" -OFFIX_DND"); #endif #ifdef BORDER_WIDTH_OPTION - printf(" +BORDER_WIDTH_OPTION"); + printf(" +BORDER_WIDTH_OPTION"); #else - printf(" -BORDER_WIDTH_OPTION"); + printf(" -BORDER_WIDTH_OPTION"); #endif #ifdef NO_DELETE_KEY - printf(" +NO_DELETE_KEY"); + printf(" +NO_DELETE_KEY"); #else - printf(" -NO_DELETE_KEY"); + printf(" -NO_DELETE_KEY"); #endif #ifdef FORCE_BACKSPACE - printf(" +FORCE_BACKSPACE"); + printf(" +FORCE_BACKSPACE"); #else - printf(" -FORCE_BACKSPACE"); + printf(" -FORCE_BACKSPACE"); #endif #ifdef FORCE_DELETE - printf(" +FORCE_DELETE"); + printf(" +FORCE_DELETE"); #else - printf(" -FORCE_DELETE"); + printf(" -FORCE_DELETE"); #endif #ifdef HOTKEY_CTRL - printf(" +HOTKEY_CTRL"); + printf(" +HOTKEY_CTRL"); #else - printf(" -HOTKEY_CTRL"); + printf(" -HOTKEY_CTRL"); #endif #ifdef HOTKEY_META - printf(" +HOTKEY_META"); + printf(" +HOTKEY_META"); #else - printf(" -HOTKEY_META"); + printf(" -HOTKEY_META"); #endif #ifdef LINUX_KEYS - printf(" +LINUX_KEYS"); + printf(" +LINUX_KEYS"); #else - printf(" -LINUX_KEYS"); + printf(" -LINUX_KEYS"); #endif #ifdef KEYSYM_ATTRIBUTE - printf(" +KEYSYM_ATTRIBUTE"); + printf(" +KEYSYM_ATTRIBUTE"); #else - printf(" -KEYSYM_ATTRIBUTE"); + printf(" -KEYSYM_ATTRIBUTE"); #endif #ifdef USE_XIM - printf(" +XIM"); + printf(" +XIM"); #else - printf(" -XIM"); + printf(" -XIM"); #endif #ifdef UNSHIFTED_SCROLLKEYS - printf(" +UNSHIFTED_SCROLLKEYS"); + printf(" +UNSHIFTED_SCROLLKEYS"); #else - printf(" -UNSHIFTED_SCROLLKEYS"); + printf(" -UNSHIFTED_SCROLLKEYS"); #endif #ifdef NO_SCROLLBAR_REPORT - printf(" +NO_SCROLLBAR_REPORT"); + printf(" +NO_SCROLLBAR_REPORT"); #else - printf(" -NO_SCROLLBAR_REPORT"); + printf(" -NO_SCROLLBAR_REPORT"); #endif #ifdef CUTCHAR_OPTION - printf(" +CUTCHAR_OPTION"); + printf(" +CUTCHAR_OPTION"); #else - printf(" -CUTCHAR_OPTION"); + printf(" -CUTCHAR_OPTION"); #endif #ifdef MOUSE_REPORT_DOUBLECLICK - printf(" +MOUSE_REPORT_DOUBLECLICK"); + printf(" +MOUSE_REPORT_DOUBLECLICK"); #else - printf(" -MOUSE_REPORT_DOUBLECLICK"); + printf(" -MOUSE_REPORT_DOUBLECLICK"); #endif #ifdef XTERM_SCROLLBAR - printf(" +XTERM_SCROLLBAR"); + printf(" +XTERM_SCROLLBAR"); #else - printf(" -XTERM_SCROLLBAR"); + printf(" -XTERM_SCROLLBAR"); #endif #ifdef MOTIF_SCROLLBAR - printf(" +MOTIF_SCROLLBAR"); + printf(" +MOTIF_SCROLLBAR"); #else - printf(" -MOTIF_SCROLLBAR"); + printf(" -MOTIF_SCROLLBAR"); #endif #ifdef NEXT_SCROLLBAR - printf(" +NEXT_SCROLLBAR"); + printf(" +NEXT_SCROLLBAR"); #else - printf(" -NEXT_SCROLLBAR"); + printf(" -NEXT_SCROLLBAR"); #endif #ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - printf(" +SCROLLBAR_BUTTON_CONTINUAL_SCROLLING"); + printf(" +SCROLLBAR_BUTTON_CONTINUAL_SCROLLING"); #else - printf(" -SCROLLBAR_BUTTON_CONTINUAL_SCROLLING"); + printf(" -SCROLLBAR_BUTTON_CONTINUAL_SCROLLING"); #endif #ifdef META8_OPTION - printf(" +META8_OPTION"); + printf(" +META8_OPTION"); #else - printf(" -META8_OPTION"); + printf(" -META8_OPTION"); #endif #ifdef GREEK_SUPPORT - printf(" +GREEK_SUPPORT"); + printf(" +GREEK_SUPPORT"); #else - printf(" -GREEK_SUPPORT"); + printf(" -GREEK_SUPPORT"); #endif #ifdef MULTI_CHARSET - printf(" +MULTI_CHARSET"); + printf(" +MULTI_CHARSET"); #else - printf(" -MULTI_CHARSET"); + printf(" -MULTI_CHARSET"); #endif #ifdef DISPLAY_IS_IP - printf(" +DISPLAY_IS_IP"); + printf(" +DISPLAY_IS_IP"); #else - printf(" -DISPLAY_IS_IP"); + printf(" -DISPLAY_IS_IP"); #endif #ifdef ENABLE_DISPLAY_ANSWER - printf(" +ENABLE_DISPLAY_ANSWER"); + printf(" +ENABLE_DISPLAY_ANSWER"); #else - printf(" -ENABLE_DISPLAY_ANSWER"); + printf(" -ENABLE_DISPLAY_ANSWER"); #endif #ifdef NO_VT100_ANS - printf(" +NO_VT100_ANS"); + printf(" +NO_VT100_ANS"); #else - printf(" -NO_VT100_ANS"); + printf(" -NO_VT100_ANS"); #endif #ifdef XTERM_COLOR_CHANGE - printf(" +XTERM_COLOR_CHANGE"); + printf(" +XTERM_COLOR_CHANGE"); #else - printf(" -XTERM_COLOR_CHANGE"); + printf(" -XTERM_COLOR_CHANGE"); #endif #ifdef DEFINE_XTERM_COLOR - printf(" +DEFINE_XTERM_COLOR"); + printf(" +DEFINE_XTERM_COLOR"); #else - printf(" -DEFINE_XTERM_COLOR"); + printf(" -DEFINE_XTERM_COLOR"); #endif #ifdef NO_MAPALERT - printf(" +NO_MAPALERT"); + printf(" +NO_MAPALERT"); #else - printf(" -NO_MAPALERT"); + printf(" -NO_MAPALERT"); #endif #ifdef MAPALERT_OPTION - printf(" +MAPALERT_OPTION"); + printf(" +MAPALERT_OPTION"); #else - printf(" -MAPALERT_OPTION"); + printf(" -MAPALERT_OPTION"); #endif #ifdef UTMP_SUPPORT - printf(" +UTMP_SUPPORT"); + printf(" +UTMP_SUPPORT"); #else - printf(" -UTMP_SUPPORT"); + printf(" -UTMP_SUPPORT"); #endif #ifdef HAVE_SAVED_UIDS - printf(" +HAVE_SAVED_UIDS"); + printf(" +HAVE_SAVED_UIDS"); #else - printf(" -HAVE_SAVED_UIDS"); + printf(" -HAVE_SAVED_UIDS"); #endif #ifdef ALLOW_BACKQUOTE_EXEC - printf(" +ALLOW_BACKQUOTE_EXEC"); + printf(" +ALLOW_BACKQUOTE_EXEC"); #else - printf(" -ALLOW_BACKQUOTE_EXEC"); + printf(" -ALLOW_BACKQUOTE_EXEC"); #endif #ifdef WARN_OLDER - printf(" +WARN_OLDER"); + printf(" +WARN_OLDER"); #else - printf(" -WARN_OLDER"); + printf(" -WARN_OLDER"); #endif - printf("\n\nCompile-time definitions:\n"); + printf("\n\nCompile-time definitions:\n"); #ifdef PATH_ENV - printf(" PATH_ENV=\"%s\"\n", safe_print_string(PATH_ENV, sizeof(PATH_ENV) - 1)); + printf(" PATH_ENV=\"%s\"\n", safe_print_string(PATH_ENV, sizeof(PATH_ENV) - 1)); #else - printf(" -PATH_ENV\n"); + printf(" -PATH_ENV\n"); #endif #ifdef REFRESH_PERIOD - printf(" REFRESH_PERIOD=%d\n", REFRESH_PERIOD); + printf(" REFRESH_PERIOD=%d\n", REFRESH_PERIOD); #else - printf(" -REFRESH_PERIOD\n"); + printf(" -REFRESH_PERIOD\n"); #endif #ifdef PRINTPIPE - printf(" PRINTPIPE=\"%s\"\n", safe_print_string(PRINTPIPE, sizeof(PRINTPIPE) - 1)); + printf(" PRINTPIPE=\"%s\"\n", safe_print_string(PRINTPIPE, sizeof(PRINTPIPE) - 1)); #else - printf(" -PRINTPIPE\n"); + printf(" -PRINTPIPE\n"); #endif #ifdef KS_DELETE - printf(" KS_DELETE=\"%s\"\n", safe_print_string(KS_DELETE, sizeof(KS_DELETE) - 1)); + printf(" KS_DELETE=\"%s\"\n", safe_print_string(KS_DELETE, sizeof(KS_DELETE) - 1)); #else - printf(" -KS_DELETE\n"); + printf(" -KS_DELETE\n"); #endif #ifdef SAVELINES - printf(" SAVELINES=%d\n", SAVELINES); + printf(" SAVELINES=%d\n", SAVELINES); #else - printf(" -SAVELINES\n"); + printf(" -SAVELINES\n"); #endif #ifdef CUTCHARS - printf(" CUTCHARS=\"%s\"\n", safe_print_string(CUTCHARS, sizeof(CUTCHARS) - 1)); + printf(" CUTCHARS=\"%s\"\n", safe_print_string(CUTCHARS, sizeof(CUTCHARS) - 1)); #else - printf(" -CUTCHARS\n"); + printf(" -CUTCHARS\n"); #endif #ifdef MULTICLICK_TIME - printf(" MULTICLICK_TIME=%d\n", MULTICLICK_TIME); + printf(" MULTICLICK_TIME=%d\n", MULTICLICK_TIME); #else - printf(" -MULTICLICK_TIME\n"); + printf(" -MULTICLICK_TIME\n"); #endif #ifdef SCROLLBAR_DEFAULT_TYPE - printf(" SCROLLBAR_DEFAULT_TYPE=%d\n", SCROLLBAR_DEFAULT_TYPE); + printf(" SCROLLBAR_DEFAULT_TYPE=%d\n", SCROLLBAR_DEFAULT_TYPE); #else - printf(" -SCROLLBAR_DEFAULT_TYPE\n"); + printf(" -SCROLLBAR_DEFAULT_TYPE\n"); #endif #ifdef SB_WIDTH - printf(" SB_WIDTH=%d\n", SB_WIDTH); + printf(" SB_WIDTH=%d\n", SB_WIDTH); #else - printf(" -SB_WIDTH\n"); + printf(" -SB_WIDTH\n"); #endif #ifdef SCROLLBAR_INITIAL_DELAY - printf(" SCROLLBAR_INITIAL_DELAY=%d\n", SCROLLBAR_INITIAL_DELAY); + printf(" SCROLLBAR_INITIAL_DELAY=%d\n", SCROLLBAR_INITIAL_DELAY); #else - printf(" -SCROLLBAR_INITIAL_DELAY\n"); + printf(" -SCROLLBAR_INITIAL_DELAY\n"); #endif #ifdef SCROLLBAR_CONTINUOUS_DELAY - printf(" SCROLLBAR_CONTINUOUS_DELAY=%d\n", SCROLLBAR_CONTINUOUS_DELAY); + printf(" SCROLLBAR_CONTINUOUS_DELAY=%d\n", SCROLLBAR_CONTINUOUS_DELAY); #else - printf(" -SCROLLBAR_CONTINUOUS_DELAY\n"); + printf(" -SCROLLBAR_CONTINUOUS_DELAY\n"); #endif #ifdef ESCZ_ANSWER - printf(" ESCZ_ANSWER=\"%s\"\n", safe_print_string(ESCZ_ANSWER, sizeof(ESCZ_ANSWER) - 1)); + printf(" ESCZ_ANSWER=\"%s\"\n", safe_print_string(ESCZ_ANSWER, sizeof(ESCZ_ANSWER) - 1)); #else - printf(" -ESCZ_ANSWER\n"); + printf(" -ESCZ_ANSWER\n"); #endif #ifdef PTY_GRP_NAME - printf(" PTY_GRP_NAME=\"%s\"\n", PTY_GRP_NAME); + printf(" PTY_GRP_NAME=\"%s\"\n", PTY_GRP_NAME); #else - printf(" -PTY_GRP_NAME\n"); + printf(" -PTY_GRP_NAME\n"); #endif #ifdef CONFIG_SEARCH_PATH - printf(" CONFIG_SEARCH_PATH=\"%s\"\n", CONFIG_SEARCH_PATH); + printf(" CONFIG_SEARCH_PATH=\"%s\"\n", CONFIG_SEARCH_PATH); #else - printf(" -CONFIG_SEARCH_PATH\n"); + printf(" -CONFIG_SEARCH_PATH\n"); #endif #ifdef THEME_CFG - printf(" THEME_CFG=\"%s\"\n", THEME_CFG); + printf(" THEME_CFG=\"%s\"\n", THEME_CFG); #else - printf(" -THEME_CFG\n"); + printf(" -THEME_CFG\n"); #endif #ifdef USER_CFG - printf(" USER_CFG=\"%s\"\n", USER_CFG); + printf(" USER_CFG=\"%s\"\n", USER_CFG); #else - printf(" -USER_CFG\n"); + printf(" -USER_CFG\n"); #endif - printf("\n"); - exit(EXIT_SUCCESS); + printf("\n"); + exit(EXIT_SUCCESS); } void get_options(int argc, char *argv[]) { - register unsigned long i, j, l; - unsigned char bad_opts = 0; + register unsigned long i, j, l; + unsigned char bad_opts = 0; - for (i = 1; i < (unsigned long) argc; i++) { + for (i = 1; i < (unsigned long) argc; i++) { - register char *opt = argv[i]; - char *val_ptr = NULL; - unsigned char islong = 0, hasequal = 0; + register char *opt = argv[i]; + char *val_ptr = NULL; + unsigned char islong = 0, hasequal = 0; - D_OPTIONS(("argv[%d] == \"%s\"\n", i, argv[i])); + D_OPTIONS(("argv[%d] == \"%s\"\n", i, argv[i])); - if (*opt != '-') { - print_error("unexpected argument %s -- expected option\n", opt); - CHECK_BAD(); - continue; - } - if (*(opt + 1) == '-') { - islong = 1; - D_OPTIONS(("Long option detected\n")); - } - if (islong) { - opt += 2; - for (j = 0; j < optList_numoptions(); j++) { - if (!strncasecmp(optList[j].long_opt, opt, (l = strlen(optList[j].long_opt))) && - (opt[l] == '=' || !opt[l])) { - D_OPTIONS(("Match found at %d: %s == %s\n", j, optList[j].long_opt, opt)); - break; - } - } - if (j == optList_numoptions()) { - print_error("unrecognized long option --%s\n", opt); - CHECK_BAD(); - continue; - } - /* Put option-specific warnings here -- mej */ -#if 0 /* No longer needed, since it works :) */ - if (optList[j].short_opt == 'w') { - print_error("warning: Use of the -w / --border-width option is discouraged and unsupported.\n"); - } + if (*opt != '-') { + print_error("unexpected argument %s -- expected option\n", opt); + CHECK_BAD(); + continue; + } + if (*(opt + 1) == '-') { + islong = 1; + D_OPTIONS(("Long option detected\n")); + } + if (islong) { + opt += 2; + for (j = 0; j < optList_numoptions(); j++) { + if (!strncasecmp(optList[j].long_opt, opt, (l = strlen(optList[j].long_opt))) && (opt[l] == '=' || !opt[l])) { + D_OPTIONS(("Match found at %d: %s == %s\n", j, optList[j].long_opt, opt)); + break; + } + } + if (j == optList_numoptions()) { + print_error("unrecognized long option --%s\n", opt); + CHECK_BAD(); + continue; + } + /* Put option-specific warnings here -- mej */ +#if 0 /* No longer needed, since it works :) */ + if (optList[j].short_opt == 'w') { + print_error("warning: Use of the -w / --border-width option is discouraged and unsupported.\n"); + } #endif - if ((val_ptr = strchr(opt, '=')) != NULL) { - *val_ptr = 0; - val_ptr++; - hasequal = 1; - } else { - if (argv[i + 1]) { - if (*argv[i + 1] != '-' || strcasestr(optList[j].long_opt, "font") || strcasestr(optList[j].long_opt, "geometry")) { - val_ptr = argv[++i]; - } - } - } - D_OPTIONS(("hasequal == %d val_ptr == %10.8p \"%s\"\n", hasequal, val_ptr, (val_ptr ? val_ptr : "(nil)"))); - if (j == 0 || j == 1) { - continue; - } - if (!(optList[j].flag & OPT_BOOLEAN) && (val_ptr == NULL)) { - print_error("long option --%s requires a%s value\n", opt, - (optList[j].flag & OPT_INTEGER ? "n integer" : " string")); - CHECK_BAD(); - continue; - } - if (!strcasecmp(opt, "exec")) { - D_OPTIONS(("--exec option detected\n")); - if (!hasequal) { + if ((val_ptr = strchr(opt, '=')) != NULL) { + *val_ptr = 0; + val_ptr++; + hasequal = 1; + } else { + if (argv[i + 1]) { + if (*argv[i + 1] != '-' || strcasestr(optList[j].long_opt, "font") || strcasestr(optList[j].long_opt, "geometry")) { + val_ptr = argv[++i]; + } + } + } + D_OPTIONS(("hasequal == %d val_ptr == %10.8p \"%s\"\n", hasequal, val_ptr, (val_ptr ? val_ptr : "(nil)"))); + if (j == 0 || j == 1) { + continue; + } + if (!(optList[j].flag & OPT_BOOLEAN) && (val_ptr == NULL)) { + print_error("long option --%s requires a%s value\n", opt, (optList[j].flag & OPT_INTEGER ? "n integer" : " string")); + CHECK_BAD(); + continue; + } + if (!strcasecmp(opt, "exec")) { + D_OPTIONS(("--exec option detected\n")); + if (!hasequal) { - register unsigned short k, len = argc - i; + register unsigned short k, len = argc - i; - rs_exec_args = (char **) MALLOC(sizeof(char *) * (argc - i + 1)); + rs_exec_args = (char **) MALLOC(sizeof(char *) * (argc - i + 1)); - for (k = 0; k < len; k++) { - rs_exec_args[k] = STRDUP(argv[k + i]); - D_OPTIONS(("rs_exec_args[%d] == %s\n", k, rs_exec_args[k])); - } - rs_exec_args[k] = (char *) NULL; - return; - } else { + for (k = 0; k < len; k++) { + rs_exec_args[k] = STRDUP(argv[k + i]); + D_OPTIONS(("rs_exec_args[%d] == %s\n", k, rs_exec_args[k])); + } + rs_exec_args[k] = (char *) NULL; + return; + } else { - register unsigned short k; + register unsigned short k; - rs_exec_args = (char **) MALLOC(sizeof(char *) * (num_words(val_ptr) + 1)); + rs_exec_args = (char **) MALLOC(sizeof(char *) * (num_words(val_ptr) + 1)); - for (k = 0; val_ptr; k++) { - rs_exec_args[k] = get_word(1, val_ptr); - val_ptr = get_pword(2, val_ptr); - D_OPTIONS(("rs_exec_args[%d] == %s\n", k, rs_exec_args[k])); - } - rs_exec_args[k] = (char *) NULL; - } - } else if (!strcasecmp(opt, "help")) { - usage(); - } else if (!strcasecmp(opt, "version")) { - version(); - } else if (!strcasecmp(opt, "attribute")) { - conf_parse_line(NULL, val_ptr); - } else { /* It's not --exec */ - if (optList[j].flag & OPT_BOOLEAN) { /* Boolean value */ - D_OPTIONS(("Boolean option detected\n")); - if (val_ptr) { - if (BOOL_OPT_ISTRUE(val_ptr)) { - D_OPTIONS(("\"%s\" == TRUE\n", val_ptr)); - if (optList[j].maskvar) { - *(optList[j].maskvar) |= optList[j].mask; - } - } else if (BOOL_OPT_ISFALSE(val_ptr)) { - D_OPTIONS(("\"%s\" == FALSE\n", val_ptr)); - if (optList[j].maskvar) { - *(optList[j].maskvar) &= ~(optList[j].mask); - } - } else { - print_error("unrecognized boolean value \"%s\" for option --%s\n", - val_ptr, optList[j].long_opt); - CHECK_BAD(); - } - } else { /* No value, so force it on */ - D_OPTIONS(("Forcing option --%s to TRUE\n", opt)); - if (optList[j].maskvar) { - *(optList[j].maskvar) |= optList[j].mask; - } - } - } else if (optList[j].flag & OPT_INTEGER) { /* Integer value */ - D_OPTIONS(("Integer option detected\n")); - *((int *) optList[j].pval) = strtol(val_ptr, (char **) NULL, 0); - } else { /* String value */ - D_OPTIONS(("String option detected\n")); - if (val_ptr && optList[j].pval) { - *((const char **) optList[j].pval) = STRDUP(val_ptr); - } - } - } - } else { /* It's a POSIX option */ + for (k = 0; val_ptr; k++) { + rs_exec_args[k] = get_word(1, val_ptr); + val_ptr = get_pword(2, val_ptr); + D_OPTIONS(("rs_exec_args[%d] == %s\n", k, rs_exec_args[k])); + } + rs_exec_args[k] = (char *) NULL; + } + } else if (!strcasecmp(opt, "help")) { + usage(); + } else if (!strcasecmp(opt, "version")) { + version(); + } else if (!strcasecmp(opt, "attribute")) { + conf_parse_line(NULL, val_ptr); + } else { /* It's not --exec */ + if (optList[j].flag & OPT_BOOLEAN) { /* Boolean value */ + D_OPTIONS(("Boolean option detected\n")); + if (val_ptr) { + if (BOOL_OPT_ISTRUE(val_ptr)) { + D_OPTIONS(("\"%s\" == TRUE\n", val_ptr)); + if (optList[j].maskvar) { + *(optList[j].maskvar) |= optList[j].mask; + } + } else if (BOOL_OPT_ISFALSE(val_ptr)) { + D_OPTIONS(("\"%s\" == FALSE\n", val_ptr)); + if (optList[j].maskvar) { + *(optList[j].maskvar) &= ~(optList[j].mask); + } + } else { + print_error("unrecognized boolean value \"%s\" for option --%s\n", val_ptr, optList[j].long_opt); + CHECK_BAD(); + } + } else { /* No value, so force it on */ + D_OPTIONS(("Forcing option --%s to TRUE\n", opt)); + if (optList[j].maskvar) { + *(optList[j].maskvar) |= optList[j].mask; + } + } + } else if (optList[j].flag & OPT_INTEGER) { /* Integer value */ + D_OPTIONS(("Integer option detected\n")); + *((int *) optList[j].pval) = strtol(val_ptr, (char **) NULL, 0); + } else { /* String value */ + D_OPTIONS(("String option detected\n")); + if (val_ptr && optList[j].pval) { + *((const char **) optList[j].pval) = STRDUP(val_ptr); + } + } + } + } else { /* It's a POSIX option */ - register unsigned short pos; - unsigned char done = 0; + register unsigned short pos; + unsigned char done = 0; - for (pos = 1; opt[pos] && !done; pos++) { - for (j = 0; j < optList_numoptions(); j++) { - if (optList[j].short_opt == opt[pos]) { - D_OPTIONS(("Match found at %d: %c == %c\n", j, optList[j].short_opt, opt[pos])); - break; - } - } - if (j == optList_numoptions()) { - print_error("unrecognized option -%c\n", opt[pos]); - CHECK_BAD(); - continue; - } - /* Put option-specific warnings here -- mej */ -#if 0 /* No longer needed, since it works :) */ - if (optList[j].short_opt == 'w') { - print_error("warning: Use of the -w / --border-width option is discouraged and unsupported.\n"); - } + for (pos = 1; opt[pos] && !done; pos++) { + for (j = 0; j < optList_numoptions(); j++) { + if (optList[j].short_opt == opt[pos]) { + D_OPTIONS(("Match found at %d: %c == %c\n", j, optList[j].short_opt, opt[pos])); + break; + } + } + if (j == optList_numoptions()) { + print_error("unrecognized option -%c\n", opt[pos]); + CHECK_BAD(); + continue; + } + /* Put option-specific warnings here -- mej */ +#if 0 /* No longer needed, since it works :) */ + if (optList[j].short_opt == 'w') { + print_error("warning: Use of the -w / --border-width option is discouraged and unsupported.\n"); + } #endif - if (!(optList[j].flag & OPT_BOOLEAN)) { - if (opt[pos + 1]) { - val_ptr = opt + pos + 1; - done = 1; - } else if ((val_ptr = argv[++i]) != NULL) { - done = 1; - } - D_OPTIONS(("val_ptr == %s done == %d\n", val_ptr, done)); - if (j == 0 || j == 1) { - continue; - } - if ((val_ptr == NULL) || ((*val_ptr == '-') && (optList[j].short_opt != 'F') && (optList[j].short_opt != 'g'))) { - print_error("option -%c requires a%s value\n", opt[pos], - (optList[j].flag & OPT_INTEGER ? "n integer" : " string")); - CHECK_BAD(); - if (val_ptr) { /* If the "arg" was actually an option, don't skip it */ - i--; - } - continue; - } - } - if (opt[pos] == 'e') { /* It's an exec */ + if (!(optList[j].flag & OPT_BOOLEAN)) { + if (opt[pos + 1]) { + val_ptr = opt + pos + 1; + done = 1; + } else if ((val_ptr = argv[++i]) != NULL) { + done = 1; + } + D_OPTIONS(("val_ptr == %s done == %d\n", val_ptr, done)); + if (j == 0 || j == 1) { + continue; + } + if ((val_ptr == NULL) || ((*val_ptr == '-') && (optList[j].short_opt != 'F') && (optList[j].short_opt != 'g'))) { + print_error("option -%c requires a%s value\n", opt[pos], (optList[j].flag & OPT_INTEGER ? "n integer" : " string")); + CHECK_BAD(); + if (val_ptr) { /* If the "arg" was actually an option, don't skip it */ + i--; + } + continue; + } + } + if (opt[pos] == 'e') { /* It's an exec */ - register unsigned short k, len; + register unsigned short k, len; - D_OPTIONS(("-e option detected\n")); + D_OPTIONS(("-e option detected\n")); - if (opt[pos + 1]) { - len = argc - i + 2; - k = i; - } else { - len = argc - i + 1; - k = i + 1; - } - D_OPTIONS(("len == %d k == %d\n", len, k)); - rs_exec_args = (char **) MALLOC(sizeof(char *) * len); + if (opt[pos + 1]) { + len = argc - i + 2; + k = i; + } else { + len = argc - i + 1; + k = i + 1; + } + D_OPTIONS(("len == %d k == %d\n", len, k)); + rs_exec_args = (char **) MALLOC(sizeof(char *) * len); - if (k == i) { - rs_exec_args[0] = STRDUP((char *) (val_ptr)); - D_OPTIONS(("rs_exec_args[0] == %s\n", rs_exec_args[0])); - k++; - } else { - rs_exec_args[0] = STRDUP(argv[k - 1]); - D_OPTIONS(("rs_exec_args[0] == %s\n", rs_exec_args[0])); - } - for (; k < argc; k++) { - rs_exec_args[k - i] = STRDUP(argv[k]); - D_OPTIONS(("rs_exec_args[%d] == %s\n", k - i, rs_exec_args[k - i])); - } - rs_exec_args[len - 1] = (char *) NULL; - return; - } else if (opt[pos] == 'h') { - usage(); - } else if (opt[pos] == 'a') { - conf_parse_line(NULL, val_ptr); - } else { - if (optList[j].flag & OPT_BOOLEAN) { /* Boolean value */ - D_OPTIONS(("Boolean option detected\n")); - if (optList[j].maskvar) { - *(optList[j].maskvar) |= optList[j].mask; - } - } else if (optList[j].flag & OPT_INTEGER) { /* Integer value */ - D_OPTIONS(("Integer option detected\n")); - *((int *) optList[j].pval) = strtol(val_ptr, (char **) NULL, 0); - D_OPTIONS(("Got value %d\n", *((int *) optList[j].pval))); - } else { /* String value */ - D_OPTIONS(("String option detected\n")); - if (optList[j].pval) { - *((const char **) optList[j].pval) = STRDUP(val_ptr); - } - } /* End if value type */ - } /* End if option type */ - } /* End if (exec or help or other) */ - } /* End if (islong) */ - } /* End main for loop */ + if (k == i) { + rs_exec_args[0] = STRDUP((char *) (val_ptr)); + D_OPTIONS(("rs_exec_args[0] == %s\n", rs_exec_args[0])); + k++; + } else { + rs_exec_args[0] = STRDUP(argv[k - 1]); + D_OPTIONS(("rs_exec_args[0] == %s\n", rs_exec_args[0])); + } + for (; k < argc; k++) { + rs_exec_args[k - i] = STRDUP(argv[k]); + D_OPTIONS(("rs_exec_args[%d] == %s\n", k - i, rs_exec_args[k - i])); + } + rs_exec_args[len - 1] = (char *) NULL; + return; + } else if (opt[pos] == 'h') { + usage(); + } else if (opt[pos] == 'a') { + conf_parse_line(NULL, val_ptr); + } else { + if (optList[j].flag & OPT_BOOLEAN) { /* Boolean value */ + D_OPTIONS(("Boolean option detected\n")); + if (optList[j].maskvar) { + *(optList[j].maskvar) |= optList[j].mask; + } + } else if (optList[j].flag & OPT_INTEGER) { /* Integer value */ + D_OPTIONS(("Integer option detected\n")); + *((int *) optList[j].pval) = strtol(val_ptr, (char **) NULL, 0); + D_OPTIONS(("Got value %d\n", *((int *) optList[j].pval))); + } else { /* String value */ + D_OPTIONS(("String option detected\n")); + if (optList[j].pval) { + *((const char **) optList[j].pval) = STRDUP(val_ptr); + } + } /* End if value type */ + } /* End if option type */ + } /* End if (exec or help or other) */ + } /* End if (islong) */ + } /* End main for loop */ } void get_initial_options(int argc, char *argv[]) { - register unsigned long i, j; + register unsigned long i, j; - for (i = 1; i < (unsigned long) argc; i++) { + for (i = 1; i < (unsigned long) argc; i++) { - register char *opt = argv[i]; - char *val_ptr = NULL; - unsigned char islong = 0, hasequal = 0; + register char *opt = argv[i]; + char *val_ptr = NULL; + unsigned char islong = 0, hasequal = 0; - D_OPTIONS(("argv[%d] == \"%s\"\n", i, argv[i])); + D_OPTIONS(("argv[%d] == \"%s\"\n", i, argv[i])); - if (*opt != '-') { - D_OPTIONS(("Non-option detected.\n")); - continue; - } - if (*(opt + 1) == '-') { - islong = 1; - D_OPTIONS(("Long option detected\n")); - } - if (islong) { - opt += 2; - if (!BEG_STRCASECMP(opt, "theme")) { - j = 0; - } else if (!BEG_STRCASECMP(opt, "config-file")) { - j = 1; - } else if (!BEG_STRCASECMP(opt, "display")) { - j = 2; - } else if (!BEG_STRCASECMP(opt, "debug")) { - j = 3; - } else if (!BEG_STRCASECMP(opt, "install")) { - j = 4; - } else if (!BEG_STRCASECMP(opt, "exec") && (*(opt+4) != '=')) { - i = (unsigned long) argc; - break; - } else - continue; - - if ((val_ptr = strchr(opt, '=')) != NULL) { - *val_ptr = 0; - val_ptr++; - hasequal = 1; - } else { - if (argv[i + 1]) { - if (*argv[i + 1] != '-') { - val_ptr = argv[++i]; - } - } - } - D_OPTIONS(("hasequal == %d val_ptr == %10.8p \"%s\"\n", hasequal, val_ptr, val_ptr)); - if (val_ptr == NULL && j != 4) { - print_error("long option --%s requires a%s value", opt, (j == 3 ? "n integer" : " string\n")); - continue; - } - if (j == 3) { - D_OPTIONS(("Integer option detected\n")); - *((int *) optList[j].pval) = strtol(val_ptr, (char **) NULL, 0); - } else if (j == 4) { - if (val_ptr) { - if (BOOL_OPT_ISTRUE(val_ptr)) { - D_OPTIONS(("\"%s\" == TRUE\n", val_ptr)); - if (optList[j].maskvar) { - *(optList[j].maskvar) |= optList[j].mask; - } - } else if (BOOL_OPT_ISFALSE(val_ptr)) { - D_OPTIONS(("\"%s\" == FALSE\n", val_ptr)); - if (optList[j].maskvar) { - *(optList[j].maskvar) &= ~(optList[j].mask); - } - } - } else { /* No value, so force it on */ - D_OPTIONS(("Forcing option --%s to TRUE\n", opt)); - if (optList[j].maskvar) { - *(optList[j].maskvar) |= optList[j].mask; - } - } - } else { - D_OPTIONS(("String option detected\n")); - if (val_ptr && optList[j].pval) { - *((const char **) optList[j].pval) = STRDUP(val_ptr); - } - } - } else { /* It's a POSIX option */ - - register unsigned short pos; - unsigned char done = 0; - - D_OPTIONS(("Short option detected.\n")); - for (pos = 1; opt[pos] && !done; pos++) { - if (opt[pos] == 't') { - j = 0; - } else if (opt[pos] == 'X') { - j = 1; - } else if (opt[pos] == 'd') { - j = 2; - } else if (opt[pos] == 'e') { - i = (unsigned long) argc; - break; - } else { - continue; + if (*opt != '-') { + D_OPTIONS(("Non-option detected.\n")); + continue; } + if (*(opt + 1) == '-') { + islong = 1; + D_OPTIONS(("Long option detected\n")); + } + if (islong) { + opt += 2; + if (!BEG_STRCASECMP(opt, "theme")) { + j = 0; + } else if (!BEG_STRCASECMP(opt, "config-file")) { + j = 1; + } else if (!BEG_STRCASECMP(opt, "display")) { + j = 2; + } else if (!BEG_STRCASECMP(opt, "debug")) { + j = 3; + } else if (!BEG_STRCASECMP(opt, "install")) { + j = 4; + } else if (!BEG_STRCASECMP(opt, "exec") && (*(opt + 4) != '=')) { + i = (unsigned long) argc; + break; + } else + continue; - if (opt[pos + 1]) { - val_ptr = opt + pos + 1; - done = 1; - } else if ((val_ptr = argv[++i]) != NULL) { - done = 1; - } - D_OPTIONS(("val_ptr == %s done == %d\n", val_ptr, done)); - if ((val_ptr == NULL) || (*val_ptr == '-')) { - print_error("option -%c requires a string value\n", opt[pos]); - if (val_ptr) { /* If the "arg" was actually an option, don't skip it */ - i--; - } - continue; - } - D_OPTIONS(("String option detected\n")); - if (optList[j].pval) { - *((const char **) optList[j].pval) = STRDUP(val_ptr); - } - } /* End for loop */ - } /* End if (islong) */ - } /* End main for loop */ + if ((val_ptr = strchr(opt, '=')) != NULL) { + *val_ptr = 0; + val_ptr++; + hasequal = 1; + } else { + if (argv[i + 1]) { + if (*argv[i + 1] != '-') { + val_ptr = argv[++i]; + } + } + } + D_OPTIONS(("hasequal == %d val_ptr == %10.8p \"%s\"\n", hasequal, val_ptr, val_ptr)); + if (val_ptr == NULL && j != 4) { + print_error("long option --%s requires a%s value", opt, (j == 3 ? "n integer" : " string\n")); + continue; + } + if (j == 3) { + D_OPTIONS(("Integer option detected\n")); + *((int *) optList[j].pval) = strtol(val_ptr, (char **) NULL, 0); + } else if (j == 4) { + if (val_ptr) { + if (BOOL_OPT_ISTRUE(val_ptr)) { + D_OPTIONS(("\"%s\" == TRUE\n", val_ptr)); + if (optList[j].maskvar) { + *(optList[j].maskvar) |= optList[j].mask; + } + } else if (BOOL_OPT_ISFALSE(val_ptr)) { + D_OPTIONS(("\"%s\" == FALSE\n", val_ptr)); + if (optList[j].maskvar) { + *(optList[j].maskvar) &= ~(optList[j].mask); + } + } + } else { /* No value, so force it on */ + D_OPTIONS(("Forcing option --%s to TRUE\n", opt)); + if (optList[j].maskvar) { + *(optList[j].maskvar) |= optList[j].mask; + } + } + } else { + D_OPTIONS(("String option detected\n")); + if (val_ptr && optList[j].pval) { + *((const char **) optList[j].pval) = STRDUP(val_ptr); + } + } + } else { /* It's a POSIX option */ + + register unsigned short pos; + unsigned char done = 0; + + D_OPTIONS(("Short option detected.\n")); + for (pos = 1; opt[pos] && !done; pos++) { + if (opt[pos] == 't') { + j = 0; + } else if (opt[pos] == 'X') { + j = 1; + } else if (opt[pos] == 'd') { + j = 2; + } else if (opt[pos] == 'e') { + i = (unsigned long) argc; + break; + } else { + continue; + } + + if (opt[pos + 1]) { + val_ptr = opt + pos + 1; + done = 1; + } else if ((val_ptr = argv[++i]) != NULL) { + done = 1; + } + D_OPTIONS(("val_ptr == %s done == %d\n", val_ptr, done)); + if ((val_ptr == NULL) || (*val_ptr == '-')) { + print_error("option -%c requires a string value\n", opt[pos]); + if (val_ptr) { /* If the "arg" was actually an option, don't skip it */ + i--; + } + continue; + } + D_OPTIONS(("String option detected\n")); + if (optList[j].pval) { + *((const char **) optList[j].pval) = STRDUP(val_ptr); + } + } /* End for loop */ + } /* End if (islong) */ + } /* End main for loop */ } /* The config file parsers. Each function handles a given context. */ static void * parse_color(char *buff, void *state) { - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } - if (!BEG_STRCASECMP(buff, "foreground ")) { - RESET_AND_ASSIGN(rs_color[fgColor], get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "background ")) { - RESET_AND_ASSIGN(rs_color[bgColor], get_word(2, buff)); + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; + } + if (!BEG_STRCASECMP(buff, "foreground ")) { + RESET_AND_ASSIGN(rs_color[fgColor], get_word(2, buff)); + } else if (!BEG_STRCASECMP(buff, "background ")) { + RESET_AND_ASSIGN(rs_color[bgColor], get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "cursor ")) { + } else if (!BEG_STRCASECMP(buff, "cursor ")) { #ifndef NO_CURSORCOLOR - RESET_AND_ASSIGN(rs_color[cursorColor], get_word(2, buff)); + RESET_AND_ASSIGN(rs_color[cursorColor], get_word(2, buff)); #else - print_warning("Support for the cursor attribute was not compiled in, ignoring\n"); + print_warning("Support for the cursor attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "cursor_text ")) { + } else if (!BEG_STRCASECMP(buff, "cursor_text ")) { #ifndef NO_CURSORCOLOR - RESET_AND_ASSIGN(rs_color[cursorColor2], get_word(2, buff)); + RESET_AND_ASSIGN(rs_color[cursorColor2], get_word(2, buff)); #else - print_warning("Support for the cursor_text attribute was not compiled in, ignoring\n"); + print_warning("Support for the cursor_text attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "pointer ")) { - RESET_AND_ASSIGN(rs_color[pointerColor], get_word(2, buff)); + } else if (!BEG_STRCASECMP(buff, "pointer ")) { + RESET_AND_ASSIGN(rs_color[pointerColor], get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "video ")) { + } else if (!BEG_STRCASECMP(buff, "video ")) { - char *tmp = get_pword(2, buff); + char *tmp = get_pword(2, buff); - if (!BEG_STRCASECMP(tmp, "reverse")) { - Options |= Opt_reverse_video; - } else if (BEG_STRCASECMP(tmp, "normal")) { - print_error("Parse error in file %s, line %lu: Invalid value \"%s\" for attribute video\n", - file_peek_path(), file_peek_line(), tmp); - } - } else if (!BEG_STRCASECMP(buff, "color ")) { + if (!BEG_STRCASECMP(tmp, "reverse")) { + Options |= Opt_reverse_video; + } else if (BEG_STRCASECMP(tmp, "normal")) { + print_error("Parse error in file %s, line %lu: Invalid value \"%s\" for attribute video\n", + file_peek_path(), file_peek_line(), tmp); + } + } else if (!BEG_STRCASECMP(buff, "color ")) { - char *tmp = 0, *r1, *g1, *b1; - unsigned int n, r, g, b, index = 0; + char *tmp = 0, *r1, *g1, *b1; + unsigned int n, r, g, b, index = 0; - n = num_words(buff); - if (n < 3) { - print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for \n" - "attribute color", file_peek_path(), file_peek_line(), NONULL(tmp)); - return NULL; - } - tmp = get_pword(2, buff); - r1 = get_pword(3, buff); - if (!isdigit(*r1)) { - if (isdigit(*tmp)) { - n = strtoul(tmp, (char **) NULL, 0); - if (n <= 7) { - index = minColor + n; - } else if (n >= 8 && n <= 15) { - index = minBright + n - 8; - } - RESET_AND_ASSIGN(rs_color[index], get_word(1, r1)); - return NULL; - } else { - if (!BEG_STRCASECMP(tmp, "bd ")) { + n = num_words(buff); + if (n < 3) { + print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for \n" + "attribute color", file_peek_path(), file_peek_line(), NONULL(tmp)); + return NULL; + } + tmp = get_pword(2, buff); + r1 = get_pword(3, buff); + if (!isdigit(*r1)) { + if (isdigit(*tmp)) { + n = strtoul(tmp, (char **) NULL, 0); + if (n <= 7) { + index = minColor + n; + } else if (n >= 8 && n <= 15) { + index = minBright + n - 8; + } + RESET_AND_ASSIGN(rs_color[index], get_word(1, r1)); + return NULL; + } else { + if (!BEG_STRCASECMP(tmp, "bd ")) { #ifndef NO_BOLDUNDERLINE - RESET_AND_ASSIGN(rs_color[colorBD], get_word(1, r1)); + RESET_AND_ASSIGN(rs_color[colorBD], get_word(1, r1)); #else - print_warning("Support for the color bd attribute was not compiled in, ignoring\n"); + print_warning("Support for the color bd attribute was not compiled in, ignoring\n"); #endif - return NULL; - } else if (!BEG_STRCASECMP(tmp, "ul ")) { + return NULL; + } else if (!BEG_STRCASECMP(tmp, "ul ")) { #ifndef NO_BOLDUNDERLINE - RESET_AND_ASSIGN(rs_color[colorUL], get_word(1, r1)); + RESET_AND_ASSIGN(rs_color[colorUL], get_word(1, r1)); #else - print_warning("Support for the color ul attribute was not compiled in, ignoring\n"); + print_warning("Support for the color ul attribute was not compiled in, ignoring\n"); #endif - return NULL; - } else { - tmp = get_word(1, tmp); - print_error("Parse error in file %s, line %lu: Invalid color index \"%s\"\n", - file_peek_path(), file_peek_line(), NONULL(tmp)); - FREE(tmp); - } - } - } - if (n != 5) { - print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for \n" - "attribute color", file_peek_path(), file_peek_line(), NONULL(tmp)); - return NULL; - } - g1 = get_pword(4, buff); - b1 = get_pword(5, buff); - if (isdigit(*tmp)) { - n = strtoul(tmp, (char **) NULL, 0); - r = strtoul(r1, (char **) NULL, 0); - g = strtoul(g1, (char **) NULL, 0); - b = strtoul(b1, (char **) NULL, 0); - if (n <= 7) { - index = minColor + n; - RESET_AND_ASSIGN(rs_color[index], MALLOC(14)); - sprintf(rs_color[index], "#%02x%02x%02x", r, g, b); - } else if (n >= 8 && n <= 15) { - index = minBright + n - 8; - RESET_AND_ASSIGN(rs_color[index], MALLOC(14)); - sprintf(rs_color[index], "#%02x%02x%02x", r, g, b); - } else { - print_error("Parse error in file %s, line %lu: Invalid color index %lu\n", - file_peek_path(), file_peek_line(), n); - } + return NULL; + } else { + tmp = get_word(1, tmp); + print_error("Parse error in file %s, line %lu: Invalid color index \"%s\"\n", + file_peek_path(), file_peek_line(), NONULL(tmp)); + FREE(tmp); + } + } + } + if (n != 5) { + print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for \n" + "attribute color", file_peek_path(), file_peek_line(), NONULL(tmp)); + return NULL; + } + g1 = get_pword(4, buff); + b1 = get_pword(5, buff); + if (isdigit(*tmp)) { + n = strtoul(tmp, (char **) NULL, 0); + r = strtoul(r1, (char **) NULL, 0); + g = strtoul(g1, (char **) NULL, 0); + b = strtoul(b1, (char **) NULL, 0); + if (n <= 7) { + index = minColor + n; + RESET_AND_ASSIGN(rs_color[index], MALLOC(14)); + sprintf(rs_color[index], "#%02x%02x%02x", r, g, b); + } else if (n >= 8 && n <= 15) { + index = minBright + n - 8; + RESET_AND_ASSIGN(rs_color[index], MALLOC(14)); + sprintf(rs_color[index], "#%02x%02x%02x", r, g, b); + } else { + print_error("Parse error in file %s, line %lu: Invalid color index %lu\n", file_peek_path(), file_peek_line(), n); + } - } else if (!BEG_STRCASECMP(tmp, "bd ")) { + } else if (!BEG_STRCASECMP(tmp, "bd ")) { #ifndef NO_BOLDUNDERLINE - RESET_AND_ASSIGN(rs_color[colorBD], MALLOC(14)); - r = strtoul(r1, (char **) NULL, 0); - g = strtoul(g1, (char **) NULL, 0); - b = strtoul(b1, (char **) NULL, 0); - sprintf(rs_color[colorBD], "#%02x%02x%02x", r, g, b); + RESET_AND_ASSIGN(rs_color[colorBD], MALLOC(14)); + r = strtoul(r1, (char **) NULL, 0); + g = strtoul(g1, (char **) NULL, 0); + b = strtoul(b1, (char **) NULL, 0); + sprintf(rs_color[colorBD], "#%02x%02x%02x", r, g, b); #else - print_warning("Support for the color bd attribute was not compiled in, ignoring\n"); + print_warning("Support for the color bd attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(tmp, "ul ")) { + } else if (!BEG_STRCASECMP(tmp, "ul ")) { #ifndef NO_BOLDUNDERLINE - RESET_AND_ASSIGN(rs_color[colorUL], MALLOC(14)); - r = strtoul(r1, (char **) NULL, 0); - g = strtoul(g1, (char **) NULL, 0); - b = strtoul(b1, (char **) NULL, 0); - sprintf(rs_color[colorUL], "#%02x%02x%02x", r, g, b); + RESET_AND_ASSIGN(rs_color[colorUL], MALLOC(14)); + r = strtoul(r1, (char **) NULL, 0); + g = strtoul(g1, (char **) NULL, 0); + b = strtoul(b1, (char **) NULL, 0); + sprintf(rs_color[colorUL], "#%02x%02x%02x", r, g, b); #else - print_warning("Support for the color ul attribute was not compiled in, ignoring\n"); + print_warning("Support for the color ul attribute was not compiled in, ignoring\n"); #endif + } else { + tmp = get_word(1, tmp); + print_error("Parse error in file %s, line %lu: Invalid color index \"%s\"\n", file_peek_path(), file_peek_line(), NONULL(tmp)); + FREE(tmp); + } } else { - tmp = get_word(1, tmp); - print_error("Parse error in file %s, line %lu: Invalid color index \"%s\"\n", - file_peek_path(), file_peek_line(), NONULL(tmp)); - FREE(tmp); + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context color\n", + file_peek_path(), file_peek_line(), buff); } - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context color\n", - file_peek_path(), file_peek_line(), buff); - } - return state; + return state; } static void * parse_attributes(char *buff, void *state) { - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } - if (!BEG_STRCASECMP(buff, "geometry ")) { - RESET_AND_ASSIGN(rs_geometry, get_word(2, buff)); + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; + } + if (!BEG_STRCASECMP(buff, "geometry ")) { + RESET_AND_ASSIGN(rs_geometry, get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "title ")) { - RESET_AND_ASSIGN(rs_title, get_word(2, buff)); + } else if (!BEG_STRCASECMP(buff, "title ")) { + RESET_AND_ASSIGN(rs_title, get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "name ")) { - RESET_AND_ASSIGN(rs_name, get_word(2, buff)); + } else if (!BEG_STRCASECMP(buff, "name ")) { + RESET_AND_ASSIGN(rs_name, get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "iconname ")) { - RESET_AND_ASSIGN(rs_iconName, get_word(2, buff)); + } else if (!BEG_STRCASECMP(buff, "iconname ")) { + RESET_AND_ASSIGN(rs_iconName, get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "desktop ")) { - rs_desktop = (int) strtol(buff, (char **) NULL, 0); + } else if (!BEG_STRCASECMP(buff, "desktop ")) { + rs_desktop = (int) strtol(buff, (char **) NULL, 0); - } else if (!BEG_STRCASECMP(buff, "scrollbar_type ")) { - RESET_AND_ASSIGN(rs_scrollbar_type, get_word(2, buff)); + } else if (!BEG_STRCASECMP(buff, "scrollbar_type ")) { + RESET_AND_ASSIGN(rs_scrollbar_type, get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "scrollbar_width ")) { - rs_scrollbar_width = strtoul(get_pword(2, buff), (char **) NULL, 0); + } else if (!BEG_STRCASECMP(buff, "scrollbar_width ")) { + rs_scrollbar_width = strtoul(get_pword(2, buff), (char **) NULL, 0); - } else if (!BEG_STRCASECMP(buff, "font ")) { + } else if (!BEG_STRCASECMP(buff, "font ")) { - char *tmp = get_pword(2, buff); - unsigned char n; + char *tmp = get_pword(2, buff); + unsigned char n; - if (!BEG_STRCASECMP(tmp, "fx ") || !BEG_STRCASECMP(tmp, "effect")) { - if (parse_font_fx(get_pword(2, tmp)) != 1) { - print_error("Parse error in file %s, line %lu: Syntax error in font effects specification\n", - file_peek_path(), file_peek_line()); - } - } else if (!BEG_STRCASECMP(tmp, "prop")) { - tmp = get_pword(2, tmp); - if (BOOL_OPT_ISTRUE(tmp)) { - Options |= Opt_proportional; - } else if (BOOL_OPT_ISFALSE(tmp)) { - Options &= ~(Opt_proportional); - } else { - print_error("Parse error in file %s, line %lu: Invalid/missing boolean value for attribute proportional\n", - file_peek_path(), file_peek_line()); - } - } else if (isdigit(*tmp)) { - n = (unsigned char) strtoul(tmp, (char **) NULL, 0); - if (n <= 255) { - eterm_font_add(&etfonts, get_pword(2, tmp), n); - } else { - print_error("Parse error in file %s, line %lu: Invalid font index %d\n", - file_peek_path(), file_peek_line(), n); - } - } else if (!BEG_STRCASECMP(tmp, "bold ")) { + if (!BEG_STRCASECMP(tmp, "fx ") || !BEG_STRCASECMP(tmp, "effect")) { + if (parse_font_fx(get_pword(2, tmp)) != 1) { + print_error("Parse error in file %s, line %lu: Syntax error in font effects specification\n", + file_peek_path(), file_peek_line()); + } + } else if (!BEG_STRCASECMP(tmp, "prop")) { + tmp = get_pword(2, tmp); + if (BOOL_OPT_ISTRUE(tmp)) { + Options |= Opt_proportional; + } else if (BOOL_OPT_ISFALSE(tmp)) { + Options &= ~(Opt_proportional); + } else { + print_error("Parse error in file %s, line %lu: Invalid/missing boolean value for attribute proportional\n", + file_peek_path(), file_peek_line()); + } + } else if (isdigit(*tmp)) { + n = (unsigned char) strtoul(tmp, (char **) NULL, 0); + if (n <= 255) { + eterm_font_add(&etfonts, get_pword(2, tmp), n); + } else { + print_error("Parse error in file %s, line %lu: Invalid font index %d\n", file_peek_path(), file_peek_line(), n); + } + } else if (!BEG_STRCASECMP(tmp, "bold ")) { #ifndef NO_BOLDFONT - RESET_AND_ASSIGN(rs_boldFont, get_word(2, tmp)); + RESET_AND_ASSIGN(rs_boldFont, get_word(2, tmp)); #else - print_warning("Support for the bold font attribute was not compiled in, ignoring\n"); + print_warning("Support for the bold font attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(tmp, "default ")) { - def_font_idx = strtoul(get_pword(2, tmp), (char **) NULL, 0); + } else if (!BEG_STRCASECMP(tmp, "default ")) { + def_font_idx = strtoul(get_pword(2, tmp), (char **) NULL, 0); + + } else { + tmp = get_word(1, tmp); + print_error("Parse error in file %s, line %lu: Invalid font index \"%s\"\n", file_peek_path(), file_peek_line(), NONULL(tmp)); + FREE(tmp); + } } else { - tmp = get_word(1, tmp); - print_error("Parse error in file %s, line %lu: Invalid font index \"%s\"\n", - file_peek_path(), file_peek_line(), NONULL(tmp)); - FREE(tmp); + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context attributes\n", + file_peek_path(), file_peek_line(), (buff ? buff : "")); } - - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context attributes\n", - file_peek_path(), file_peek_line(), (buff ? buff : "")); - } - return state; + return state; } static void * parse_toggles(char *buff, void *state) { - char *tmp; - unsigned char bool_val; + char *tmp; + unsigned char bool_val; - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } - if (!(tmp = get_pword(2, buff))) { - print_error("Parse error in file %s, line %lu: Missing boolean value in context toggles\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (BOOL_OPT_ISTRUE(tmp)) { - bool_val = 1; - } else if (BOOL_OPT_ISFALSE(tmp)) { - bool_val = 0; - } else { - print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" in context toggles\n", - file_peek_path(), file_peek_line(), tmp); - return NULL; - } + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; + } + if (!(tmp = get_pword(2, buff))) { + print_error("Parse error in file %s, line %lu: Missing boolean value in context toggles\n", file_peek_path(), file_peek_line()); + return NULL; + } + if (BOOL_OPT_ISTRUE(tmp)) { + bool_val = 1; + } else if (BOOL_OPT_ISFALSE(tmp)) { + bool_val = 0; + } else { + print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" in context toggles\n", + file_peek_path(), file_peek_line(), tmp); + return NULL; + } - if (!BEG_STRCASECMP(buff, "map_alert ")) { + if (!BEG_STRCASECMP(buff, "map_alert ")) { #if !defined(NO_MAPALERT) && defined(MAPALERT_OPTION) - if (bool_val) { - Options |= Opt_map_alert; - } else { - Options &= ~(Opt_map_alert); - } + if (bool_val) { + Options |= Opt_map_alert; + } else { + Options &= ~(Opt_map_alert); + } #else - print_warning("Support for the map_alert attribute was not compiled in, ignoring\n"); + print_warning("Support for the map_alert attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "visual_bell ")) { - if (bool_val) { - Options |= Opt_visual_bell; - } else { - Options &= ~(Opt_visual_bell); - } - } else if (!BEG_STRCASECMP(buff, "login_shell ")) { - if (bool_val) { - Options |= Opt_login_shell; - } else { - Options &= ~(Opt_login_shell); - } - } else if (!BEG_STRCASECMP(buff, "scrollbar ")) { - if (bool_val) { - Options |= Opt_scrollbar; - } else { - Options &= ~(Opt_scrollbar); - } + } else if (!BEG_STRCASECMP(buff, "visual_bell ")) { + if (bool_val) { + Options |= Opt_visual_bell; + } else { + Options &= ~(Opt_visual_bell); + } + } else if (!BEG_STRCASECMP(buff, "login_shell ")) { + if (bool_val) { + Options |= Opt_login_shell; + } else { + Options &= ~(Opt_login_shell); + } + } else if (!BEG_STRCASECMP(buff, "scrollbar ")) { + if (bool_val) { + Options |= Opt_scrollbar; + } else { + Options &= ~(Opt_scrollbar); + } - } else if (!BEG_STRCASECMP(buff, "utmp_logging ")) { + } else if (!BEG_STRCASECMP(buff, "utmp_logging ")) { #ifdef UTMP_SUPPORT - if (bool_val) { - Options |= Opt_write_utmp; - } else { - Options &= ~(Opt_write_utmp); - } + if (bool_val) { + Options |= Opt_write_utmp; + } else { + Options &= ~(Opt_write_utmp); + } #else - print_warning("Support for the utmp_logging attribute was not compiled in, ignoring\n"); + print_warning("Support for the utmp_logging attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "meta8 ")) { + } else if (!BEG_STRCASECMP(buff, "meta8 ")) { #ifdef META8_OPTION - if (bool_val) { - Options |= Opt_meta8; - } else { - Options &= ~(Opt_meta8); - } + if (bool_val) { + Options |= Opt_meta8; + } else { + Options &= ~(Opt_meta8); + } #else - print_warning("Support for the meta8 attribute was not compiled in, ignoring\n"); + print_warning("Support for the meta8 attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "iconic ")) { - if (bool_val) { - Options |= Opt_iconic; - } else { - Options &= ~(Opt_iconic); - } + } else if (!BEG_STRCASECMP(buff, "iconic ")) { + if (bool_val) { + Options |= Opt_iconic; + } else { + Options &= ~(Opt_iconic); + } - } else if (!BEG_STRCASECMP(buff, "home_on_output ")) { - if (bool_val) { - Options |= Opt_home_on_output; - } else { - Options &= ~(Opt_home_on_output); - } + } else if (!BEG_STRCASECMP(buff, "home_on_output ")) { + if (bool_val) { + Options |= Opt_home_on_output; + } else { + Options &= ~(Opt_home_on_output); + } - } else if (!BEG_STRCASECMP(buff, "home_on_input ")) { - if (bool_val) { - Options |= Opt_home_on_input; - } else { - Options &= ~(Opt_home_on_input); - } + } else if (!BEG_STRCASECMP(buff, "home_on_input ")) { + if (bool_val) { + Options |= Opt_home_on_input; + } else { + Options &= ~(Opt_home_on_input); + } - } else if (!BEG_STRCASECMP(buff, "no_input ")) { - if (bool_val) { - Options |= Opt_no_input; - } else { - Options &= ~(Opt_no_input); - } + } else if (!BEG_STRCASECMP(buff, "no_input ")) { + if (bool_val) { + Options |= Opt_no_input; + } else { + Options &= ~(Opt_no_input); + } - } else if (!BEG_STRCASECMP(buff, "scrollbar_floating ")) { - if (bool_val) { - Options |= Opt_scrollbar_floating; - } else { - Options &= ~(Opt_scrollbar_floating); - } + } else if (!BEG_STRCASECMP(buff, "scrollbar_floating ")) { + if (bool_val) { + Options |= Opt_scrollbar_floating; + } else { + Options &= ~(Opt_scrollbar_floating); + } - } else if (!BEG_STRCASECMP(buff, "scrollbar_right ")) { - if (bool_val) { - Options |= Opt_scrollbar_right; - } else { - Options &= ~(Opt_scrollbar_right); - } - } else if (!BEG_STRCASECMP(buff, "scrollbar_popup ")) { - if (bool_val) { - Options |= Opt_scrollbar_popup; - } else { - Options &= ~(Opt_scrollbar_popup); - } - } else if (!BEG_STRCASECMP(buff, "borderless ")) { - if (bool_val) { - Options |= Opt_borderless; - } else { - Options &= ~(Opt_borderless); - } - } else if (!BEG_STRCASECMP(buff, "double_buffer ")) { - if (bool_val) { - Options |= Opt_double_buffer; - } else { - Options &= ~(Opt_double_buffer); - } + } else if (!BEG_STRCASECMP(buff, "scrollbar_right ")) { + if (bool_val) { + Options |= Opt_scrollbar_right; + } else { + Options &= ~(Opt_scrollbar_right); + } + } else if (!BEG_STRCASECMP(buff, "scrollbar_popup ")) { + if (bool_val) { + Options |= Opt_scrollbar_popup; + } else { + Options &= ~(Opt_scrollbar_popup); + } + } else if (!BEG_STRCASECMP(buff, "borderless ")) { + if (bool_val) { + Options |= Opt_borderless; + } else { + Options &= ~(Opt_borderless); + } + } else if (!BEG_STRCASECMP(buff, "double_buffer ")) { + if (bool_val) { + Options |= Opt_double_buffer; + } else { + Options &= ~(Opt_double_buffer); + } - } else if (!BEG_STRCASECMP(buff, "no_cursor ")) { - if (bool_val) { - Options |= Opt_no_cursor; - } else { - Options &= ~(Opt_no_cursor); - } + } else if (!BEG_STRCASECMP(buff, "no_cursor ")) { + if (bool_val) { + Options |= Opt_no_cursor; + } else { + Options &= ~(Opt_no_cursor); + } - } else if (!BEG_STRCASECMP(buff, "pause ")) { - if (bool_val) { - Options |= Opt_pause; - } else { - Options &= ~(Opt_pause); - } + } else if (!BEG_STRCASECMP(buff, "pause ")) { + if (bool_val) { + Options |= Opt_pause; + } else { + Options &= ~(Opt_pause); + } - } else if (!BEG_STRCASECMP(buff, "xterm_select ")) { - if (bool_val) { - Options |= Opt_xterm_select; - } else { - Options &= ~(Opt_xterm_select); - } + } else if (!BEG_STRCASECMP(buff, "xterm_select ")) { + if (bool_val) { + Options |= Opt_xterm_select; + } else { + Options &= ~(Opt_xterm_select); + } - } else if (!BEG_STRCASECMP(buff, "select_line ")) { - if (bool_val) { - Options |= Opt_select_whole_line; - } else { - Options &= ~(Opt_select_whole_line); - } + } else if (!BEG_STRCASECMP(buff, "select_line ")) { + if (bool_val) { + Options |= Opt_select_whole_line; + } else { + Options &= ~(Opt_select_whole_line); + } - } else if (!BEG_STRCASECMP(buff, "select_trailing_spaces ")) { - if (bool_val) { - Options |= Opt_select_trailing_spaces; - } else { - Options &= ~(Opt_select_trailing_spaces); - } + } else if (!BEG_STRCASECMP(buff, "select_trailing_spaces ")) { + if (bool_val) { + Options |= Opt_select_trailing_spaces; + } else { + Options &= ~(Opt_select_trailing_spaces); + } - } else if (!BEG_STRCASECMP(buff, "report_as_keysyms ")) { - if (bool_val) { - Options |= Opt_report_as_keysyms; - } else { - Options &= ~(Opt_report_as_keysyms); - } + } else if (!BEG_STRCASECMP(buff, "report_as_keysyms ")) { + if (bool_val) { + Options |= Opt_report_as_keysyms; + } else { + Options &= ~(Opt_report_as_keysyms); + } - } else if (!BEG_STRCASECMP(buff, "mbyte_cursor ")) { - if (bool_val) { - Options |= Opt_mbyte_cursor; - } else { - Options &= ~(Opt_mbyte_cursor); - } + } else if (!BEG_STRCASECMP(buff, "mbyte_cursor ")) { + if (bool_val) { + Options |= Opt_mbyte_cursor; + } else { + Options &= ~(Opt_mbyte_cursor); + } - } else if (!BEG_STRCASECMP(buff, "itrans ") || !BEG_STRCASECMP(buff, "immotile_trans ")) { - if (bool_val) { - image_toggles |= IMOPT_ITRANS; - } else { - image_toggles &= ~IMOPT_ITRANS; - } + } else if (!BEG_STRCASECMP(buff, "itrans ") || !BEG_STRCASECMP(buff, "immotile_trans ")) { + if (bool_val) { + image_toggles |= IMOPT_ITRANS; + } else { + image_toggles &= ~IMOPT_ITRANS; + } - } else if (!BEG_STRCASECMP(buff, "buttonbar")) { - if (bool_val) { - FOREACH_BUTTONBAR(bbar_set_visible(bbar, 1);); - rs_buttonbars = 1; /* Reset for future use. */ - } else { - FOREACH_BUTTONBAR(bbar_set_visible(bbar, 0);); - rs_buttonbars = 1; /* Reset for future use. */ - } + } else if (!BEG_STRCASECMP(buff, "buttonbar")) { + if (bool_val) { + FOREACH_BUTTONBAR(bbar_set_visible(bbar, 1); + ); + rs_buttonbars = 1; /* Reset for future use. */ + } else { + FOREACH_BUTTONBAR(bbar_set_visible(bbar, 0); + ); + rs_buttonbars = 1; /* Reset for future use. */ + } - } else if (!BEG_STRCASECMP(buff, "resize_gravity")) { - if (bool_val) { - Options |= Opt_resize_gravity; + } else if (!BEG_STRCASECMP(buff, "resize_gravity")) { + if (bool_val) { + Options |= Opt_resize_gravity; + } else { + Options &= ~(Opt_resize_gravity); + } } else { - Options &= ~(Opt_resize_gravity); + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context toggles\n", file_peek_path(), + file_peek_line(), buff); } - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context toggles\n", file_peek_path(), file_peek_line(), buff); - } - return state; + return state; } static void * parse_keyboard(char *buff, void *state) { - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } - if (!BEG_STRCASECMP(buff, "smallfont_key ")) { + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; + } + if (!BEG_STRCASECMP(buff, "smallfont_key ")) { #if defined (HOTKEY_CTRL) || defined (HOTKEY_META) - RESET_AND_ASSIGN(rs_smallfont_key, get_word(2, buff)); - to_keysym(&ks_smallfont, rs_smallfont_key); + RESET_AND_ASSIGN(rs_smallfont_key, get_word(2, buff)); + to_keysym(&ks_smallfont, rs_smallfont_key); #else - print_warning("Support for the smallfont_key attribute was not compiled in, ignoring\n"); + print_warning("Support for the smallfont_key attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "bigfont_key ")) { + } else if (!BEG_STRCASECMP(buff, "bigfont_key ")) { #if defined (HOTKEY_CTRL) || defined (HOTKEY_META) - RESET_AND_ASSIGN(rs_bigfont_key, get_word(2, buff)); - to_keysym(&ks_bigfont, rs_bigfont_key); + RESET_AND_ASSIGN(rs_bigfont_key, get_word(2, buff)); + to_keysym(&ks_bigfont, rs_bigfont_key); #else - print_warning("Support for the bigfont_key attribute was not compiled in, ignoring\n"); + print_warning("Support for the bigfont_key attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "keysym ")) { + } else if (!BEG_STRCASECMP(buff, "keysym ")) { #ifdef KEYSYM_ATTRIBUTE - int sym, len; - char *str = buff + 7, *s; + int sym, len; + char *str = buff + 7, *s; - sym = (int) strtol(str, (char **) NULL, 0); - if (sym != (int) 2147483647L) { + sym = (int) strtol(str, (char **) NULL, 0); + if (sym != (int) 2147483647L) { - if (sym >= 0xff00) - sym -= 0xff00; - if (sym < 0 || sym > 0xff) { - print_error("Parse error in file %s, line %lu: Keysym 0x%x out of range 0xff00-0xffff\n", - file_peek_path(), file_peek_line(), sym + 0xff00); - return NULL; - } - s = get_word(3, buff); - str = (char *) MALLOC(strlen(s) + 2); - strcpy(str, s); - FREE(s); - chomp(str); - len = parse_escaped_string(str); - if (len > 255) - len = 255; /* We can only handle lengths that will fit in a char */ - if (len && KeySym_map[sym] == NULL) { + if (sym >= 0xff00) + sym -= 0xff00; + if (sym < 0 || sym > 0xff) { + print_error("Parse error in file %s, line %lu: Keysym 0x%x out of range 0xff00-0xffff\n", + file_peek_path(), file_peek_line(), sym + 0xff00); + return NULL; + } + s = get_word(3, buff); + str = (char *) MALLOC(strlen(s) + 2); + strcpy(str, s); + FREE(s); + chomp(str); + len = parse_escaped_string(str); + if (len > 255) + len = 255; /* We can only handle lengths that will fit in a char */ + if (len && KeySym_map[sym] == NULL) { - char *p = MALLOC(len + 1); + char *p = MALLOC(len + 1); - *p = len; - strncpy(p + 1, str, len); - KeySym_map[sym] = (unsigned char *) p; - } - } + *p = len; + strncpy(p + 1, str, len); + KeySym_map[sym] = (unsigned char *) p; + } + } #else - print_warning("Support for the keysym attributes was not compiled in, ignoring\n"); + print_warning("Support for the keysym attributes was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "meta_mod ")) { - char *tmp = get_pword(2, buff); + } else if (!BEG_STRCASECMP(buff, "meta_mod ")) { + char *tmp = get_pword(2, buff); - if (!tmp) { - print_error("Parse error in file %s, line %lu: Missing modifier value for attribute meta_mod\n", - file_peek_path(), file_peek_line()); - return NULL; - } - rs_meta_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing modifier value for attribute meta_mod\n", + file_peek_path(), file_peek_line()); + return NULL; + } + rs_meta_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); - } else if (!BEG_STRCASECMP(buff, "alt_mod ")) { - char *tmp = get_pword(2, buff); + } else if (!BEG_STRCASECMP(buff, "alt_mod ")) { + char *tmp = get_pword(2, buff); - if (!tmp) { - print_error("Parse error in file %s, line %lu: Missing modifier value for attribute alt_mod\n", - file_peek_path(), file_peek_line()); - return NULL; - } - rs_alt_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); - - } else if (!BEG_STRCASECMP(buff, "numlock_mod ")) { - char *tmp = get_pword(2, buff); + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing modifier value for attribute alt_mod\n", + file_peek_path(), file_peek_line()); + return NULL; + } + rs_alt_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); - if (!tmp) { - print_error("Parse error in file %s, line %lu: Missing modifier value for attribute numlock_mod\n", - file_peek_path(), file_peek_line()); - return NULL; - } - rs_numlock_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); - - } else if (!BEG_STRCASECMP(buff, "greek ")) { + } else if (!BEG_STRCASECMP(buff, "numlock_mod ")) { + char *tmp = get_pword(2, buff); + + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing modifier value for attribute numlock_mod\n", + file_peek_path(), file_peek_line()); + return NULL; + } + rs_numlock_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); + + } else if (!BEG_STRCASECMP(buff, "greek ")) { #ifdef GREEK_SUPPORT - char *tmp = get_pword(2, buff); + char *tmp = get_pword(2, buff); - if (!tmp) { - print_error("Parse error in file %s, line %lu: Missing boolean value for attribute greek\n", - file_peek_path(), file_peek_line()); - return NULL; - } - if (BOOL_OPT_ISTRUE(tmp)) { - RESET_AND_ASSIGN(rs_greek_keyboard, get_word(3, buff)); - if (BEG_STRCASECMP(rs_greek_keyboard, "iso")) { - greek_setmode(GREEK_ELOT928); - } else if (BEG_STRCASECMP(rs_greek_keyboard, "ibm")) { - greek_setmode(GREEK_IBM437); - } else { - print_error("Parse error in file %s, line %lu: Invalid greek keyboard mode \"%s\"\n", - file_peek_path(), file_peek_line(), (rs_greek_keyboard ? rs_greek_keyboard : "")); - } - } else if (BOOL_OPT_ISFALSE(tmp)) { - /* This space intentionally left no longer blank =^) */ - } else { - print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" for attribute %s\n", - file_peek_path(), file_peek_line(), tmp, buff); - return NULL; - } + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing boolean value for attribute greek\n", + file_peek_path(), file_peek_line()); + return NULL; + } + if (BOOL_OPT_ISTRUE(tmp)) { + RESET_AND_ASSIGN(rs_greek_keyboard, get_word(3, buff)); + if (BEG_STRCASECMP(rs_greek_keyboard, "iso")) { + greek_setmode(GREEK_ELOT928); + } else if (BEG_STRCASECMP(rs_greek_keyboard, "ibm")) { + greek_setmode(GREEK_IBM437); + } else { + print_error("Parse error in file %s, line %lu: Invalid greek keyboard mode \"%s\"\n", + file_peek_path(), file_peek_line(), (rs_greek_keyboard ? rs_greek_keyboard : "")); + } + } else if (BOOL_OPT_ISFALSE(tmp)) { + /* This space intentionally left no longer blank =^) */ + } else { + print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" for attribute %s\n", + file_peek_path(), file_peek_line(), tmp, buff); + return NULL; + } #else - print_warning("Support for the greek attribute was not compiled in, ignoring\n"); + print_warning("Support for the greek attribute was not compiled in, ignoring\n"); #endif - } else if (!BEG_STRCASECMP(buff, "app_keypad ")) { + } else if (!BEG_STRCASECMP(buff, "app_keypad ")) { - char *tmp = get_pword(2, buff); + char *tmp = get_pword(2, buff); + + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing boolean value for attribute app_keypad\n", + file_peek_path(), file_peek_line()); + return NULL; + } + if (BOOL_OPT_ISTRUE(tmp)) { + PrivateModes |= PrivMode_aplKP; + } else if (BOOL_OPT_ISFALSE(tmp)) { + PrivateModes &= ~(PrivMode_aplKP); + } else { + print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" for attribute app_keypad\n", + file_peek_path(), file_peek_line(), tmp); + return NULL; + } + + } else if (!BEG_STRCASECMP(buff, "app_cursor ")) { + + char *tmp = get_pword(2, buff); + + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing boolean value for attribute app_cursor\n", + file_peek_path(), file_peek_line()); + return NULL; + } + if (BOOL_OPT_ISTRUE(tmp)) { + PrivateModes |= PrivMode_aplCUR; + } else if (BOOL_OPT_ISFALSE(tmp)) { + PrivateModes &= ~(PrivMode_aplCUR); + } else { + print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" for attribute app_cursor\n", + file_peek_path(), file_peek_line(), tmp); + return NULL; + } - if (!tmp) { - print_error("Parse error in file %s, line %lu: Missing boolean value for attribute app_keypad\n", - file_peek_path(), file_peek_line()); - return NULL; - } - if (BOOL_OPT_ISTRUE(tmp)) { - PrivateModes |= PrivMode_aplKP; - } else if (BOOL_OPT_ISFALSE(tmp)) { - PrivateModes &= ~(PrivMode_aplKP); } else { - print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" for attribute app_keypad\n", - file_peek_path(), file_peek_line(), tmp); - return NULL; + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context keyboard\n", + file_peek_path(), file_peek_line(), buff); } - - } else if (!BEG_STRCASECMP(buff, "app_cursor ")) { - - char *tmp = get_pword(2, buff); - - if (!tmp) { - print_error("Parse error in file %s, line %lu: Missing boolean value for attribute app_cursor\n", - file_peek_path(), file_peek_line()); - return NULL; - } - if (BOOL_OPT_ISTRUE(tmp)) { - PrivateModes |= PrivMode_aplCUR; - } else if (BOOL_OPT_ISFALSE(tmp)) { - PrivateModes &= ~(PrivMode_aplCUR); - } else { - print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" for attribute app_cursor\n", - file_peek_path(), file_peek_line(), tmp); - return NULL; - } - - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context keyboard\n", - file_peek_path(), file_peek_line(), buff); - } - return state; + return state; } static void * parse_misc(char *buff, void *state) { - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } - if (!BEG_STRCASECMP(buff, "print_pipe ")) { -#ifdef PRINTPIPE - RESET_AND_ASSIGN(rs_print_pipe, STRDUP(get_pword(2, buff))); - chomp(rs_print_pipe); -#else - print_warning("Support for the print_pipe attribute was not compiled in, ignoring\n"); -#endif - - } else if (!BEG_STRCASECMP(buff, "save_lines ")) { - rs_saveLines = strtol(get_pword(2, buff), (char **) NULL, 0); - - } else if (!BEG_STRCASECMP(buff, "min_anchor_size ")) { - rs_min_anchor_size = strtol(get_pword(2, buff), (char **) NULL, 0); - - } else if (!BEG_STRCASECMP(buff, "border_width ")) { -#ifdef BORDER_WIDTH_OPTION - TermWin.internalBorder = (short) strtol(get_pword(2, buff), (char **) NULL, 0); -#else - print_warning("Support for the border_width attribute was not compiled in, ignoring\n"); -#endif - - } else if (!BEG_STRCASECMP(buff, "line_space ")) { - rs_line_space = strtol(get_pword(2, buff), (char **) NULL, 0); - - } else if (!BEG_STRCASECMP(buff, "finished_title ")) { - RESET_AND_ASSIGN(rs_finished_title, get_word(2, buff)); - - } else if (!BEG_STRCASECMP(buff, "finished_text ")) { - RESET_AND_ASSIGN(rs_finished_text, get_word(2, buff)); - - } else if (!BEG_STRCASECMP(buff, "term_name ")) { - RESET_AND_ASSIGN(rs_term_name, get_word(2, buff)); - - } else if (!BEG_STRCASECMP(buff, "debug ")) { - DEBUG_LEVEL = (unsigned int) strtoul(get_pword(2, buff), (char **) NULL, 0); - - } else if (!BEG_STRCASECMP(buff, "exec ")) { - - register unsigned short k, n; - - RESET_AND_ASSIGN(rs_exec_args, (char **) MALLOC(sizeof(char *) * ((n = num_words(get_pword(2, buff))) + 1))); - - for (k = 0; k < n; k++) { - rs_exec_args[k] = get_word(k + 2, buff); - D_OPTIONS(("rs_exec_args[%d] == %s\n", k, rs_exec_args[k])); + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; } - rs_exec_args[n] = (char *) NULL; - - } else if (!BEG_STRCASECMP(buff, "cut_chars ")) { -#ifdef CUTCHAR_OPTION - RESET_AND_ASSIGN(rs_cutchars, get_word(2, buff)); - chomp(rs_cutchars); + if (!BEG_STRCASECMP(buff, "print_pipe ")) { +#ifdef PRINTPIPE + RESET_AND_ASSIGN(rs_print_pipe, STRDUP(get_pword(2, buff))); + chomp(rs_print_pipe); #else - print_warning("Support for the cut_chars attribute was not compiled in, ignoring\n"); + print_warning("Support for the print_pipe attribute was not compiled in, ignoring\n"); #endif - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context misc\n", - file_peek_path(), file_peek_line(), buff); - } - return state; + } else if (!BEG_STRCASECMP(buff, "save_lines ")) { + rs_saveLines = strtol(get_pword(2, buff), (char **) NULL, 0); + + } else if (!BEG_STRCASECMP(buff, "min_anchor_size ")) { + rs_min_anchor_size = strtol(get_pword(2, buff), (char **) NULL, 0); + + } else if (!BEG_STRCASECMP(buff, "border_width ")) { +#ifdef BORDER_WIDTH_OPTION + TermWin.internalBorder = (short) strtol(get_pword(2, buff), (char **) NULL, 0); +#else + print_warning("Support for the border_width attribute was not compiled in, ignoring\n"); +#endif + + } else if (!BEG_STRCASECMP(buff, "line_space ")) { + rs_line_space = strtol(get_pword(2, buff), (char **) NULL, 0); + + } else if (!BEG_STRCASECMP(buff, "finished_title ")) { + RESET_AND_ASSIGN(rs_finished_title, get_word(2, buff)); + + } else if (!BEG_STRCASECMP(buff, "finished_text ")) { + RESET_AND_ASSIGN(rs_finished_text, get_word(2, buff)); + + } else if (!BEG_STRCASECMP(buff, "term_name ")) { + RESET_AND_ASSIGN(rs_term_name, get_word(2, buff)); + + } else if (!BEG_STRCASECMP(buff, "debug ")) { + DEBUG_LEVEL = (unsigned int) strtoul(get_pword(2, buff), (char **) NULL, 0); + + } else if (!BEG_STRCASECMP(buff, "exec ")) { + + register unsigned short k, n; + + RESET_AND_ASSIGN(rs_exec_args, (char **) MALLOC(sizeof(char *) * ((n = num_words(get_pword(2, buff))) + 1))); + + for (k = 0; k < n; k++) { + rs_exec_args[k] = get_word(k + 2, buff); + D_OPTIONS(("rs_exec_args[%d] == %s\n", k, rs_exec_args[k])); + } + rs_exec_args[n] = (char *) NULL; + + } else if (!BEG_STRCASECMP(buff, "cut_chars ")) { +#ifdef CUTCHAR_OPTION + RESET_AND_ASSIGN(rs_cutchars, get_word(2, buff)); + chomp(rs_cutchars); +#else + print_warning("Support for the cut_chars attribute was not compiled in, ignoring\n"); +#endif + + } else { + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context misc\n", + file_peek_path(), file_peek_line(), buff); + } + return state; } static void * parse_imageclasses(char *buff, void *state) { - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } - - if (!BEG_STRCASECMP(buff, "icon ")) { -#ifdef PIXMAP_SUPPORT - RESET_AND_ASSIGN(rs_icon, get_word(2, buff)); -#else - print_warning("Pixmap support was not compiled in, ignoring \"icon\" attribute\n"); -#endif - - } else if (!BEG_STRCASECMP(buff, "cache")) { -#ifdef PIXMAP_SUPPORT - rs_cache_size = strtoul(get_pword(2, buff), (char **) NULL, 0); -#else - print_warning("Pixmap support was not compiled in, ignoring \"cache\" attribute\n"); -#endif - - } else if (!BEG_STRCASECMP(buff, "path ")) { - RESET_AND_ASSIGN(rs_path, get_word(2, buff)); - - } else if (!BEG_STRCASECMP(buff, "anim ")) { -#ifdef BACKGROUND_CYCLING_SUPPORT - char *tmp = get_pword(2, buff); - - if (tmp) { - rs_anim_pixmap_list = STRDUP(tmp); - } else { - print_error("Parse error in file %s, line %lu: Invalid parameter list \"\" for attribute anim\n", file_peek_path(), file_peek_line()); + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; } + + if (!BEG_STRCASECMP(buff, "icon ")) { +#ifdef PIXMAP_SUPPORT + RESET_AND_ASSIGN(rs_icon, get_word(2, buff)); #else - print_warning("Support for the anim attribute was not compiled in, ignoring\n"); + print_warning("Pixmap support was not compiled in, ignoring \"icon\" attribute\n"); #endif - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context imageclasses\n", - file_peek_path(), file_peek_line(), buff); - } - return state; + } else if (!BEG_STRCASECMP(buff, "cache")) { +#ifdef PIXMAP_SUPPORT + rs_cache_size = strtoul(get_pword(2, buff), (char **) NULL, 0); +#else + print_warning("Pixmap support was not compiled in, ignoring \"cache\" attribute\n"); +#endif + + } else if (!BEG_STRCASECMP(buff, "path ")) { + RESET_AND_ASSIGN(rs_path, get_word(2, buff)); + + } else if (!BEG_STRCASECMP(buff, "anim ")) { +#ifdef BACKGROUND_CYCLING_SUPPORT + char *tmp = get_pword(2, buff); + + if (tmp) { + rs_anim_pixmap_list = STRDUP(tmp); + } else { + print_error("Parse error in file %s, line %lu: Invalid parameter list \"\" for attribute anim\n", file_peek_path(), + file_peek_line()); + } +#else + print_warning("Support for the anim attribute was not compiled in, ignoring\n"); +#endif + + } else { + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context imageclasses\n", + file_peek_path(), file_peek_line(), buff); + } + return state; } static void * parse_image(char *buff, void *state) { - int idx; + int idx; - if (*buff == CONF_BEGIN_CHAR) { - int *tmp; + if (*buff == CONF_BEGIN_CHAR) { + int *tmp; - tmp = (int *) MALLOC(sizeof(int)); - *tmp = -1; - return ((void *) tmp); - } - ASSERT_RVAL(state != NULL, (void *)(file_skip_to_end(), NULL)); - if (*buff == CONF_END_CHAR) { - int *tmp; + tmp = (int *) MALLOC(sizeof(int)); + *tmp = -1; + return ((void *) tmp); + } + ASSERT_RVAL(state != NULL, (void *) (file_skip_to_end(), NULL)); + if (*buff == CONF_END_CHAR) { + int *tmp; - tmp = (int *) state; - FREE(tmp); - return NULL; - } - idx = *((int *) state); - if (!BEG_STRCASECMP(buff, "type ")) { - char *type = get_pword(2, buff); + tmp = (int *) state; + FREE(tmp); + return NULL; + } + idx = *((int *) state); + if (!BEG_STRCASECMP(buff, "type ")) { + char *type = get_pword(2, buff); - if (!type) { - print_error("Parse error in file %s, line %lu: Missing image type\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!strcasecmp(type, "background")) { - idx = image_bg; - } else if (!strcasecmp(type, "trough")) { - idx = image_sb; - } else if (!strcasecmp(type, "anchor")) { - idx = image_sa; - } else if (!strcasecmp(type, "thumb")) { - idx = image_st; - } else if (!strcasecmp(type, "up_arrow")) { - idx = image_up; - } else if (!strcasecmp(type, "down_arrow")) { - idx = image_down; - } else if (!strcasecmp(type, "left_arrow")) { - idx = image_left; - } else if (!strcasecmp(type, "right_arrow")) { - idx = image_right; - } else if (!strcasecmp(type, "menu")) { - idx = image_menu; - } else if (!strcasecmp(type, "menuitem")) { - idx = image_menuitem; - } else if (!strcasecmp(type, "submenu")) { - idx = image_submenu; - } else if (!strcasecmp(type, "button")) { - idx = image_button; - } else if (!strcasecmp(type, "button_bar") || !strcasecmp(type, "buttonbar")) { - idx = image_bbar; - } else if (!strcasecmp(type, "grab_bar")) { - idx = image_gbar; - } else if (!strcasecmp(type, "dialog_box")) { - idx = image_dialog; - } else { - print_error("Parse error in file %s, line %lu: Invalid image type \"%s\"\n", file_peek_path(), file_peek_line(), type); - return NULL; - } - *((int *) state) = idx; + if (!type) { + print_error("Parse error in file %s, line %lu: Missing image type\n", file_peek_path(), file_peek_line()); + return NULL; + } + if (!strcasecmp(type, "background")) { + idx = image_bg; + } else if (!strcasecmp(type, "trough")) { + idx = image_sb; + } else if (!strcasecmp(type, "anchor")) { + idx = image_sa; + } else if (!strcasecmp(type, "thumb")) { + idx = image_st; + } else if (!strcasecmp(type, "up_arrow")) { + idx = image_up; + } else if (!strcasecmp(type, "down_arrow")) { + idx = image_down; + } else if (!strcasecmp(type, "left_arrow")) { + idx = image_left; + } else if (!strcasecmp(type, "right_arrow")) { + idx = image_right; + } else if (!strcasecmp(type, "menu")) { + idx = image_menu; + } else if (!strcasecmp(type, "menuitem")) { + idx = image_menuitem; + } else if (!strcasecmp(type, "submenu")) { + idx = image_submenu; + } else if (!strcasecmp(type, "button")) { + idx = image_button; + } else if (!strcasecmp(type, "button_bar") || !strcasecmp(type, "buttonbar")) { + idx = image_bbar; + } else if (!strcasecmp(type, "grab_bar")) { + idx = image_gbar; + } else if (!strcasecmp(type, "dialog_box")) { + idx = image_dialog; + } else { + print_error("Parse error in file %s, line %lu: Invalid image type \"%s\"\n", file_peek_path(), file_peek_line(), type); + return NULL; + } + *((int *) state) = idx; - } else if (!BEG_STRCASECMP(buff, "mode ")) { - char *mode = get_pword(2, buff); - char *allow_list = get_pword(4, buff); + } else if (!BEG_STRCASECMP(buff, "mode ")) { + char *mode = get_pword(2, buff); + char *allow_list = get_pword(4, buff); - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered \"mode\" with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!mode) { - print_error("Parse error in file %s, line %lu: Missing parameters for mode line\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!BEG_STRCASECMP(mode, "image")) { - images[idx].mode = (MODE_IMAGE | ALLOW_IMAGE); - } else if (!BEG_STRCASECMP(mode, "trans")) { - images[idx].mode = (MODE_TRANS | ALLOW_TRANS); - } else if (!BEG_STRCASECMP(mode, "viewport")) { - images[idx].mode = (MODE_VIEWPORT | ALLOW_VIEWPORT); - } else if (!BEG_STRCASECMP(mode, "auto")) { - images[idx].mode = (MODE_AUTO | ALLOW_AUTO); - } else if (!BEG_STRCASECMP(mode, "solid")) { - images[idx].mode = MODE_SOLID; - } else { - print_error("Parse error in file %s, line %lu: Invalid mode \"%s\"\n", file_peek_path(), file_peek_line(), mode); - } - if (allow_list) { - char *allow; + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered \"mode\" with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (!mode) { + print_error("Parse error in file %s, line %lu: Missing parameters for mode line\n", file_peek_path(), file_peek_line()); + return NULL; + } + if (!BEG_STRCASECMP(mode, "image")) { + images[idx].mode = (MODE_IMAGE | ALLOW_IMAGE); + } else if (!BEG_STRCASECMP(mode, "trans")) { + images[idx].mode = (MODE_TRANS | ALLOW_TRANS); + } else if (!BEG_STRCASECMP(mode, "viewport")) { + images[idx].mode = (MODE_VIEWPORT | ALLOW_VIEWPORT); + } else if (!BEG_STRCASECMP(mode, "auto")) { + images[idx].mode = (MODE_AUTO | ALLOW_AUTO); + } else if (!BEG_STRCASECMP(mode, "solid")) { + images[idx].mode = MODE_SOLID; + } else { + print_error("Parse error in file %s, line %lu: Invalid mode \"%s\"\n", file_peek_path(), file_peek_line(), mode); + } + if (allow_list) { + char *allow; - for (; (allow = (char *) strsep(&allow_list, " ")) != NULL;) { - if (!BEG_STRCASECMP("image", allow)) { - images[idx].mode |= ALLOW_IMAGE; - } else if (!BEG_STRCASECMP("transparent", allow)) { - images[idx].mode |= ALLOW_TRANS; - } else if (!BEG_STRCASECMP("viewport", allow)) { - images[idx].mode |= ALLOW_VIEWPORT; - } else if (!BEG_STRCASECMP("auto", allow)) { - images[idx].mode |= ALLOW_AUTO; - } else if (!BEG_STRCASECMP("solid", allow)) { - } else { - print_error("Parse error in file %s, line %lu: Invalid mode \"%s\"\n", file_peek_path(), file_peek_line(), allow); - } - } - } - } else if (!BEG_STRCASECMP(buff, "state ")) { - char *state = get_pword(2, buff), new = 0; + for (; (allow = (char *) strsep(&allow_list, " ")) != NULL;) { + if (!BEG_STRCASECMP("image", allow)) { + images[idx].mode |= ALLOW_IMAGE; + } else if (!BEG_STRCASECMP("transparent", allow)) { + images[idx].mode |= ALLOW_TRANS; + } else if (!BEG_STRCASECMP("viewport", allow)) { + images[idx].mode |= ALLOW_VIEWPORT; + } else if (!BEG_STRCASECMP("auto", allow)) { + images[idx].mode |= ALLOW_AUTO; + } else if (!BEG_STRCASECMP("solid", allow)) { + } else { + print_error("Parse error in file %s, line %lu: Invalid mode \"%s\"\n", file_peek_path(), file_peek_line(), allow); + } + } + } + } else if (!BEG_STRCASECMP(buff, "state ")) { + char *state = get_pword(2, buff), new = 0; - if (!state) { - print_error("Parse error in file %s, line %lu: Missing state\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered \"state\" with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!strcasecmp(state, "normal")) { - if (images[idx].norm == NULL) { - images[idx].norm = (simage_t *) MALLOC(sizeof(simage_t)); - new = 1; - } - images[idx].current = images[idx].norm; - } else if (!strcasecmp(state, "selected")) { - if (images[idx].selected == NULL) { - images[idx].selected = (simage_t *) MALLOC(sizeof(simage_t)); - new = 1; - } - images[idx].current = images[idx].selected; - } else if (!strcasecmp(state, "clicked")) { - if (images[idx].clicked == NULL) { - images[idx].clicked = (simage_t *) MALLOC(sizeof(simage_t)); - new = 1; - } - images[idx].current = images[idx].clicked; - } else if (!strcasecmp(state, "disabled")) { - if (images[idx].disabled == NULL) { - images[idx].disabled = (simage_t *) MALLOC(sizeof(simage_t)); - new = 1; - } - images[idx].current = images[idx].disabled; - } else { - print_error("Parse error in file %s, line %lu: Invalid state \"%s\"\n", file_peek_path(), file_peek_line(), state); - return NULL; - } - if (new) { - MEMSET(images[idx].current, 0, sizeof(simage_t)); - images[idx].current->pmap = (pixmap_t *) MALLOC(sizeof(pixmap_t)); - images[idx].current->iml = (imlib_t *) MALLOC(sizeof(imlib_t)); - MEMSET(images[idx].current->pmap, 0, sizeof(pixmap_t)); - MEMSET(images[idx].current->iml, 0, sizeof(imlib_t)); - } - } else if (!BEG_STRCASECMP(buff, "color ")) { - char *fg = get_word(2, buff), *bg = get_word(3, buff); + if (!state) { + print_error("Parse error in file %s, line %lu: Missing state\n", file_peek_path(), file_peek_line()); + return NULL; + } + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered \"state\" with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (!strcasecmp(state, "normal")) { + if (images[idx].norm == NULL) { + images[idx].norm = (simage_t *) MALLOC(sizeof(simage_t)); + new = 1; + } + images[idx].current = images[idx].norm; + } else if (!strcasecmp(state, "selected")) { + if (images[idx].selected == NULL) { + images[idx].selected = (simage_t *) MALLOC(sizeof(simage_t)); + new = 1; + } + images[idx].current = images[idx].selected; + } else if (!strcasecmp(state, "clicked")) { + if (images[idx].clicked == NULL) { + images[idx].clicked = (simage_t *) MALLOC(sizeof(simage_t)); + new = 1; + } + images[idx].current = images[idx].clicked; + } else if (!strcasecmp(state, "disabled")) { + if (images[idx].disabled == NULL) { + images[idx].disabled = (simage_t *) MALLOC(sizeof(simage_t)); + new = 1; + } + images[idx].current = images[idx].disabled; + } else { + print_error("Parse error in file %s, line %lu: Invalid state \"%s\"\n", file_peek_path(), file_peek_line(), state); + return NULL; + } + if (new) { + MEMSET(images[idx].current, 0, sizeof(simage_t)); + images[idx].current->pmap = (pixmap_t *) MALLOC(sizeof(pixmap_t)); + images[idx].current->iml = (imlib_t *) MALLOC(sizeof(imlib_t)); + MEMSET(images[idx].current->pmap, 0, sizeof(pixmap_t)); + MEMSET(images[idx].current->iml, 0, sizeof(imlib_t)); + } + } else if (!BEG_STRCASECMP(buff, "color ")) { + char *fg = get_word(2, buff), *bg = get_word(3, buff); - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered \"color\" with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (images[idx].current == NULL) { - print_error("Parse error in file %s, line %lu: Encountered \"color\" with no image state defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!fg || !bg) { - print_error("Parse error in file %s, line %lu: Foreground and background colors must be specified with \"color\"\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!BEG_STRCASECMP(fg, "0x")) { - images[idx].current->fg = get_color_by_pixel((Pixel) strtoul(fg, (char **) NULL, 0), WhitePixel(Xdisplay, Xscreen)); - } else { - images[idx].current->fg = get_color_by_name(fg, "white"); - } - if (!BEG_STRCASECMP(bg, "0x")) { - images[idx].current->bg = get_color_by_pixel((Pixel) strtoul(bg, (char **) NULL, 0), BlackPixel(Xdisplay, Xscreen)); - } else { - images[idx].current->bg = get_color_by_name(bg, "black"); - } - FREE(fg); - FREE(bg); + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered \"color\" with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (images[idx].current == NULL) { + print_error("Parse error in file %s, line %lu: Encountered \"color\" with no image state defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (!fg || !bg) { + print_error("Parse error in file %s, line %lu: Foreground and background colors must be specified with \"color\"\n", + file_peek_path(), file_peek_line()); + return NULL; + } + if (!BEG_STRCASECMP(fg, "0x")) { + images[idx].current->fg = get_color_by_pixel((Pixel) strtoul(fg, (char **) NULL, 0), WhitePixel(Xdisplay, Xscreen)); + } else { + images[idx].current->fg = get_color_by_name(fg, "white"); + } + if (!BEG_STRCASECMP(bg, "0x")) { + images[idx].current->bg = get_color_by_pixel((Pixel) strtoul(bg, (char **) NULL, 0), BlackPixel(Xdisplay, Xscreen)); + } else { + images[idx].current->bg = get_color_by_name(bg, "black"); + } + FREE(fg); + FREE(bg); #ifdef PIXMAP_SUPPORT - } else if (!BEG_STRCASECMP(buff, "file ")) { - char *filename = get_pword(2, buff); + } else if (!BEG_STRCASECMP(buff, "file ")) { + char *filename = get_pword(2, buff); - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered \"file\" with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (images[idx].current == NULL) { - print_error("Parse error in file %s, line %lu: Encountered \"file\" with no image state defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!filename) { - print_error("Parse error in file %s, line %lu: Missing filename\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!load_image(filename, images[idx].current)) { - images[idx].mode &= ~(MODE_IMAGE | ALLOW_IMAGE); - D_PIXMAP(("New image mode is 0x%02x, iml->im is 0x%08x\n", images[idx].mode, images[idx].current->iml->im)); - } + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered \"file\" with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (images[idx].current == NULL) { + print_error("Parse error in file %s, line %lu: Encountered \"file\" with no image state defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (!filename) { + print_error("Parse error in file %s, line %lu: Missing filename\n", file_peek_path(), file_peek_line()); + return NULL; + } + if (!load_image(filename, images[idx].current)) { + images[idx].mode &= ~(MODE_IMAGE | ALLOW_IMAGE); + D_PIXMAP(("New image mode is 0x%02x, iml->im is 0x%08x\n", images[idx].mode, images[idx].current->iml->im)); + } - } else if (!BEG_STRCASECMP(buff, "geom ")) { - char *geom = get_pword(2, buff); + } else if (!BEG_STRCASECMP(buff, "geom ")) { + char *geom = get_pword(2, buff); - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered \"geom\" with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (images[idx].current == NULL) { - print_error("Parse error in file %s, line %lu: Encountered \"geom\" with no image state defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!geom) { - print_error("Parse error in file %s, line %lu: Missing geometry string\n", file_peek_path(), file_peek_line()); - return NULL; - } - set_pixmap_scale(geom, images[idx].current->pmap); + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered \"geom\" with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (images[idx].current == NULL) { + print_error("Parse error in file %s, line %lu: Encountered \"geom\" with no image state defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (!geom) { + print_error("Parse error in file %s, line %lu: Missing geometry string\n", file_peek_path(), file_peek_line()); + return NULL; + } + set_pixmap_scale(geom, images[idx].current->pmap); - } else if (!BEG_STRCASECMP(buff, "cmod ") || !BEG_STRCASECMP(buff, "colormod ")) { - char *color = get_pword(2, buff); - char *mods = get_pword(3, buff); - unsigned char n; - imlib_t *iml = images[idx].current->iml; + } else if (!BEG_STRCASECMP(buff, "cmod ") || !BEG_STRCASECMP(buff, "colormod ")) { + char *color = get_pword(2, buff); + char *mods = get_pword(3, buff); + unsigned char n; + imlib_t *iml = images[idx].current->iml; - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered color modifier with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (images[idx].current == NULL) { - print_error("Parse error in file %s, line %lu: Encountered color modifier with no image state defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!color) { - print_error("Parse error in file %s, line %lu: Missing color name\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (!mods) { - print_error("Parse error in file %s, line %lu: Missing modifier(s)\n", file_peek_path(), file_peek_line()); - return NULL; - } - n = num_words(mods); + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered color modifier with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (images[idx].current == NULL) { + print_error("Parse error in file %s, line %lu: Encountered color modifier with no image state defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (!color) { + print_error("Parse error in file %s, line %lu: Missing color name\n", file_peek_path(), file_peek_line()); + return NULL; + } + if (!mods) { + print_error("Parse error in file %s, line %lu: Missing modifier(s)\n", file_peek_path(), file_peek_line()); + return NULL; + } + n = num_words(mods); - if (!BEG_STRCASECMP(color, "image ")) { - if (iml->mod) { - free_colormod(iml->mod); - } - iml->mod = create_colormod(); - iml->mod->brightness = (int) strtol(mods, (char **) NULL, 0); - if (n > 1) { - iml->mod->contrast = (int) strtol(get_pword(2, mods), (char **) NULL, 0); - } - if (n > 2) { - iml->mod->gamma = (int) strtol(get_pword(3, mods), (char **) NULL, 0); - } - update_cmod(iml->mod); - } else if (!BEG_STRCASECMP(color, "red ")) { - if (iml->rmod) { - free_colormod(iml->rmod); - } - iml->rmod = create_colormod(); - iml->rmod->brightness = (int) strtol(mods, (char **) NULL, 0); - if (n > 1) { - iml->rmod->contrast = (int) strtol(get_pword(2, mods), (char **) NULL, 0); - } - if (n > 2) { - iml->rmod->gamma = (int) strtol(get_pword(3, mods), (char **) NULL, 0); - } - update_cmod(iml->rmod); - } else if (!BEG_STRCASECMP(color, "green ")) { - if (iml->gmod) { - free_colormod(iml->gmod); - } - iml->gmod = create_colormod(); - iml->gmod->brightness = (int) strtol(mods, (char **) NULL, 0); - if (n > 1) { - iml->gmod->contrast = (int) strtol(get_pword(2, mods), (char **) NULL, 0); - } - if (n > 2) { - iml->gmod->gamma = (int) strtol(get_pword(3, mods), (char **) NULL, 0); - } - update_cmod(iml->gmod); - } else if (!BEG_STRCASECMP(color, "blue ")) { - if (iml->bmod) { - free_colormod(iml->bmod); - } - iml->bmod = create_colormod(); - iml->bmod->brightness = (int) strtol(mods, (char **) NULL, 0); - if (n > 1) { - iml->bmod->contrast = (int) strtol(get_pword(2, mods), (char **) NULL, 0); - } - if (n > 2) { - iml->bmod->gamma = (int) strtol(get_pword(3, mods), (char **) NULL, 0); - } - update_cmod(iml->bmod); - } else { - print_error("Parse error in file %s, line %lu: Color must be either \"image\", \"red\", \"green\", or \"blue\"\n", file_peek_path(), file_peek_line()); - return NULL; - } + if (!BEG_STRCASECMP(color, "image ")) { + if (iml->mod) { + free_colormod(iml->mod); + } + iml->mod = create_colormod(); + iml->mod->brightness = (int) strtol(mods, (char **) NULL, 0); + if (n > 1) { + iml->mod->contrast = (int) strtol(get_pword(2, mods), (char **) NULL, 0); + } + if (n > 2) { + iml->mod->gamma = (int) strtol(get_pword(3, mods), (char **) NULL, 0); + } + update_cmod(iml->mod); + } else if (!BEG_STRCASECMP(color, "red ")) { + if (iml->rmod) { + free_colormod(iml->rmod); + } + iml->rmod = create_colormod(); + iml->rmod->brightness = (int) strtol(mods, (char **) NULL, 0); + if (n > 1) { + iml->rmod->contrast = (int) strtol(get_pword(2, mods), (char **) NULL, 0); + } + if (n > 2) { + iml->rmod->gamma = (int) strtol(get_pword(3, mods), (char **) NULL, 0); + } + update_cmod(iml->rmod); + } else if (!BEG_STRCASECMP(color, "green ")) { + if (iml->gmod) { + free_colormod(iml->gmod); + } + iml->gmod = create_colormod(); + iml->gmod->brightness = (int) strtol(mods, (char **) NULL, 0); + if (n > 1) { + iml->gmod->contrast = (int) strtol(get_pword(2, mods), (char **) NULL, 0); + } + if (n > 2) { + iml->gmod->gamma = (int) strtol(get_pword(3, mods), (char **) NULL, 0); + } + update_cmod(iml->gmod); + } else if (!BEG_STRCASECMP(color, "blue ")) { + if (iml->bmod) { + free_colormod(iml->bmod); + } + iml->bmod = create_colormod(); + iml->bmod->brightness = (int) strtol(mods, (char **) NULL, 0); + if (n > 1) { + iml->bmod->contrast = (int) strtol(get_pword(2, mods), (char **) NULL, 0); + } + if (n > 2) { + iml->bmod->gamma = (int) strtol(get_pword(3, mods), (char **) NULL, 0); + } + update_cmod(iml->bmod); + } else { + print_error("Parse error in file %s, line %lu: Color must be either \"image\", \"red\", \"green\", or \"blue\"\n", + file_peek_path(), file_peek_line()); + return NULL; + } #endif - } else if (!BEG_STRCASECMP(buff, "border ")) { - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered \"border\" with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (num_words(buff + 7) < 4) { - print_error("Parse error in file %s, line %lu: Invalid parameter list for attribute \"border\"\n", file_peek_path(), file_peek_line()); - return NULL; - } - RESET_AND_ASSIGN(images[idx].current->iml->border, (Imlib_Border *) MALLOC(sizeof(Imlib_Border))); + } else if (!BEG_STRCASECMP(buff, "border ")) { + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered \"border\" with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (num_words(buff + 7) < 4) { + print_error("Parse error in file %s, line %lu: Invalid parameter list for attribute \"border\"\n", file_peek_path(), + file_peek_line()); + return NULL; + } + RESET_AND_ASSIGN(images[idx].current->iml->border, (Imlib_Border *) MALLOC(sizeof(Imlib_Border))); - images[idx].current->iml->border->left = (unsigned short) strtoul(get_pword(2, buff), (char **) NULL, 0); - images[idx].current->iml->border->right = (unsigned short) strtoul(get_pword(3, buff), (char **) NULL, 0); - images[idx].current->iml->border->top = (unsigned short) strtoul(get_pword(4, buff), (char **) NULL, 0); - images[idx].current->iml->border->bottom = (unsigned short) strtoul(get_pword(5, buff), (char **) NULL, 0); + images[idx].current->iml->border->left = (unsigned short) strtoul(get_pword(2, buff), (char **) NULL, 0); + images[idx].current->iml->border->right = (unsigned short) strtoul(get_pword(3, buff), (char **) NULL, 0); + images[idx].current->iml->border->top = (unsigned short) strtoul(get_pword(4, buff), (char **) NULL, 0); + images[idx].current->iml->border->bottom = (unsigned short) strtoul(get_pword(5, buff), (char **) NULL, 0); - if ((images[idx].current->iml->border->left == 0) && (images[idx].current->iml->border->right == 0) - && (images[idx].current->iml->border->top == 0) && (images[idx].current->iml->border->bottom == 0)) { - FREE(images[idx].current->iml->border); - images[idx].current->iml->border = (Imlib_Border *) NULL; /* No sense in wasting CPU time and memory if there are no borders */ - } - } else if (!BEG_STRCASECMP(buff, "bevel ")) { - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered \"bevel\" with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (images[idx].current == NULL) { - print_error("Parse error in file %s, line %lu: Encountered \"bevel\" with no image state defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (num_words(buff + 6) < 5) { - print_error("Parse error in file %s, line %lu: Invalid parameter list for attribute \"bevel\"\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (images[idx].current->iml->bevel != NULL) { - FREE(images[idx].current->iml->bevel->edges); - FREE(images[idx].current->iml->bevel); - } - images[idx].current->iml->bevel = (bevel_t *) MALLOC(sizeof(bevel_t)); - images[idx].current->iml->bevel->edges = (Imlib_Border *) MALLOC(sizeof(Imlib_Border)); + if ((images[idx].current->iml->border->left == 0) && (images[idx].current->iml->border->right == 0) + && (images[idx].current->iml->border->top == 0) && (images[idx].current->iml->border->bottom == 0)) { + FREE(images[idx].current->iml->border); + images[idx].current->iml->border = (Imlib_Border *) NULL; /* No sense in wasting CPU time and memory if there are no borders */ + } + } else if (!BEG_STRCASECMP(buff, "bevel ")) { + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered \"bevel\" with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (images[idx].current == NULL) { + print_error("Parse error in file %s, line %lu: Encountered \"bevel\" with no image state defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (num_words(buff + 6) < 5) { + print_error("Parse error in file %s, line %lu: Invalid parameter list for attribute \"bevel\"\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (images[idx].current->iml->bevel != NULL) { + FREE(images[idx].current->iml->bevel->edges); + FREE(images[idx].current->iml->bevel); + } + images[idx].current->iml->bevel = (bevel_t *) MALLOC(sizeof(bevel_t)); + images[idx].current->iml->bevel->edges = (Imlib_Border *) MALLOC(sizeof(Imlib_Border)); - if (!BEG_STRCASECMP(get_pword(2, buff), "down")) { - images[idx].current->iml->bevel->up = 0; + if (!BEG_STRCASECMP(get_pword(2, buff), "down")) { + images[idx].current->iml->bevel->up = 0; + } else { + images[idx].current->iml->bevel->up = 1; + } + images[idx].current->iml->bevel->edges->left = (unsigned short) strtoul(get_pword(3, buff), (char **) NULL, 0); + images[idx].current->iml->bevel->edges->right = (unsigned short) strtoul(get_pword(4, buff), (char **) NULL, 0); + images[idx].current->iml->bevel->edges->top = (unsigned short) strtoul(get_pword(5, buff), (char **) NULL, 0); + images[idx].current->iml->bevel->edges->bottom = (unsigned short) strtoul(get_pword(6, buff), (char **) NULL, 0); + + if ((images[idx].current->iml->bevel->edges->left == 0) && (images[idx].current->iml->bevel->edges->right == 0) + && (images[idx].current->iml->bevel->edges->top == 0) && (images[idx].current->iml->bevel->edges->bottom == 0)) { + FREE(images[idx].current->iml->bevel->edges); + images[idx].current->iml->bevel->edges = (Imlib_Border *) NULL; + FREE(images[idx].current->iml->bevel); + images[idx].current->iml->bevel = (bevel_t *) NULL; + } + } else if (!BEG_STRCASECMP(buff, "padding ")) { + if (!CHECK_VALID_INDEX(idx)) { + print_error("Parse error in file %s, line %lu: Encountered \"padding\" with no image type defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (images[idx].current == NULL) { + print_error("Parse error in file %s, line %lu: Encountered \"padding\" with no image state defined\n", file_peek_path(), + file_peek_line()); + return NULL; + } + if (num_words(buff + 8) < 4) { + print_error("Parse error in file %s, line %lu: Invalid parameter list for attribute \"padding\"\n", file_peek_path(), + file_peek_line()); + return NULL; + } + RESET_AND_ASSIGN(images[idx].current->iml->pad, (Imlib_Border *) MALLOC(sizeof(Imlib_Border))); + + images[idx].current->iml->pad->left = (unsigned short) strtoul(get_pword(2, buff), (char **) NULL, 0); + images[idx].current->iml->pad->right = (unsigned short) strtoul(get_pword(3, buff), (char **) NULL, 0); + images[idx].current->iml->pad->top = (unsigned short) strtoul(get_pword(4, buff), (char **) NULL, 0); + images[idx].current->iml->pad->bottom = (unsigned short) strtoul(get_pword(5, buff), (char **) NULL, 0); + + if ((images[idx].current->iml->pad->left == 0) && (images[idx].current->iml->pad->right == 0) + && (images[idx].current->iml->pad->top == 0) && (images[idx].current->iml->pad->bottom == 0)) { + FREE(images[idx].current->iml->pad); + images[idx].current->iml->pad = (Imlib_Border *) NULL; + } } else { - images[idx].current->iml->bevel->up = 1; + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context image\n", + file_peek_path(), file_peek_line(), buff); } - images[idx].current->iml->bevel->edges->left = (unsigned short) strtoul(get_pword(3, buff), (char **) NULL, 0); - images[idx].current->iml->bevel->edges->right = (unsigned short) strtoul(get_pword(4, buff), (char **) NULL, 0); - images[idx].current->iml->bevel->edges->top = (unsigned short) strtoul(get_pword(5, buff), (char **) NULL, 0); - images[idx].current->iml->bevel->edges->bottom = (unsigned short) strtoul(get_pword(6, buff), (char **) NULL, 0); - - if ((images[idx].current->iml->bevel->edges->left == 0) && (images[idx].current->iml->bevel->edges->right == 0) - && (images[idx].current->iml->bevel->edges->top == 0) && (images[idx].current->iml->bevel->edges->bottom == 0)) { - FREE(images[idx].current->iml->bevel->edges); - images[idx].current->iml->bevel->edges = (Imlib_Border *) NULL; - FREE(images[idx].current->iml->bevel); - images[idx].current->iml->bevel = (bevel_t *) NULL; - } - } else if (!BEG_STRCASECMP(buff, "padding ")) { - if (!CHECK_VALID_INDEX(idx)) { - print_error("Parse error in file %s, line %lu: Encountered \"padding\" with no image type defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (images[idx].current == NULL) { - print_error("Parse error in file %s, line %lu: Encountered \"padding\" with no image state defined\n", file_peek_path(), file_peek_line()); - return NULL; - } - if (num_words(buff + 8) < 4) { - print_error("Parse error in file %s, line %lu: Invalid parameter list for attribute \"padding\"\n", file_peek_path(), file_peek_line()); - return NULL; - } - RESET_AND_ASSIGN(images[idx].current->iml->pad, (Imlib_Border *) MALLOC(sizeof(Imlib_Border))); - - images[idx].current->iml->pad->left = (unsigned short) strtoul(get_pword(2, buff), (char **) NULL, 0); - images[idx].current->iml->pad->right = (unsigned short) strtoul(get_pword(3, buff), (char **) NULL, 0); - images[idx].current->iml->pad->top = (unsigned short) strtoul(get_pword(4, buff), (char **) NULL, 0); - images[idx].current->iml->pad->bottom = (unsigned short) strtoul(get_pword(5, buff), (char **) NULL, 0); - - if ((images[idx].current->iml->pad->left == 0) && (images[idx].current->iml->pad->right == 0) - && (images[idx].current->iml->pad->top == 0) && (images[idx].current->iml->pad->bottom == 0)) { - FREE(images[idx].current->iml->pad); - images[idx].current->iml->pad = (Imlib_Border *) NULL; - } - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context image\n", - file_peek_path(), file_peek_line(), buff); - } - return ((void *) state); + return ((void *) state); } static void * parse_actions(char *buff, void *state) { - unsigned short mod = MOD_NONE; - unsigned char button = BUTTON_NONE; - KeySym keysym = 0; - char *str; - unsigned short i; + unsigned short mod = MOD_NONE; + unsigned char button = BUTTON_NONE; + KeySym keysym = 0; + char *str; + unsigned short i; - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; + } - if (!BEG_STRCASECMP(buff, "bind ")) { - for (i = 2; (str = get_word(i, buff)) && strcasecmp(str, "to"); i++) { - if (!BEG_STRCASECMP(str, "anymod")) { - mod = MOD_ANY; - } else if (!BEG_STRCASECMP(str, "ctrl")) { - mod |= MOD_CTRL; - } else if (!BEG_STRCASECMP(str, "shift")) { - mod |= MOD_SHIFT; - } else if (!BEG_STRCASECMP(str, "lock")) { - mod |= MOD_LOCK; - } else if (!BEG_STRCASECMP(str, "meta")) { - mod |= MOD_META; - } else if (!BEG_STRCASECMP(str, "alt")) { - mod |= MOD_ALT; - } else if (!BEG_STRCASECMP(str, "mod1")) { - mod |= MOD_MOD1; - } else if (!BEG_STRCASECMP(str, "mod2")) { - mod |= MOD_MOD2; - } else if (!BEG_STRCASECMP(str, "mod3")) { - mod |= MOD_MOD3; - } else if (!BEG_STRCASECMP(str, "mod4")) { - mod |= MOD_MOD4; - } else if (!BEG_STRCASECMP(str, "mod5")) { - mod |= MOD_MOD5; - } else if (!BEG_STRCASECMP(str, "button")) { - button = *(str + 6) - '0'; - } else if (isdigit(*str)) { - keysym = (KeySym) strtoul(str, (char **) NULL, 0); - } else { - keysym = XStringToKeysym(str); - } - FREE(str); - } - if (!str) { - print_error("Parse error in file %s, line %lu: Syntax error (\"to\" not found)\n", file_peek_path(), file_peek_line()); - return NULL; - } - FREE(str); - if ((button == BUTTON_NONE) && (keysym == 0)) { - print_error("Parse error in file %s, line %lu: No valid button/keysym found for action\n", file_peek_path(), file_peek_line()); - return NULL; - } - i++; - str = get_pword(i, buff); - if (!BEG_STRCASECMP(str, "string")) { - str = get_word(i+1, buff); - action_add(mod, button, keysym, ACTION_STRING, (void *) str); - FREE(str); - } else if (!BEG_STRCASECMP(str, "echo")) { - str = get_word(i+1, buff); - action_add(mod, button, keysym, ACTION_ECHO, (void *) str); - FREE(str); - } else if (!BEG_STRCASECMP(str, "menu")) { - menu_t *menu; + if (!BEG_STRCASECMP(buff, "bind ")) { + for (i = 2; (str = get_word(i, buff)) && strcasecmp(str, "to"); i++) { + if (!BEG_STRCASECMP(str, "anymod")) { + mod = MOD_ANY; + } else if (!BEG_STRCASECMP(str, "ctrl")) { + mod |= MOD_CTRL; + } else if (!BEG_STRCASECMP(str, "shift")) { + mod |= MOD_SHIFT; + } else if (!BEG_STRCASECMP(str, "lock")) { + mod |= MOD_LOCK; + } else if (!BEG_STRCASECMP(str, "meta")) { + mod |= MOD_META; + } else if (!BEG_STRCASECMP(str, "alt")) { + mod |= MOD_ALT; + } else if (!BEG_STRCASECMP(str, "mod1")) { + mod |= MOD_MOD1; + } else if (!BEG_STRCASECMP(str, "mod2")) { + mod |= MOD_MOD2; + } else if (!BEG_STRCASECMP(str, "mod3")) { + mod |= MOD_MOD3; + } else if (!BEG_STRCASECMP(str, "mod4")) { + mod |= MOD_MOD4; + } else if (!BEG_STRCASECMP(str, "mod5")) { + mod |= MOD_MOD5; + } else if (!BEG_STRCASECMP(str, "button")) { + button = *(str + 6) - '0'; + } else if (isdigit(*str)) { + keysym = (KeySym) strtoul(str, (char **) NULL, 0); + } else { + keysym = XStringToKeysym(str); + } + FREE(str); + } + if (!str) { + print_error("Parse error in file %s, line %lu: Syntax error (\"to\" not found)\n", file_peek_path(), file_peek_line()); + return NULL; + } + FREE(str); + if ((button == BUTTON_NONE) && (keysym == 0)) { + print_error("Parse error in file %s, line %lu: No valid button/keysym found for action\n", file_peek_path(), file_peek_line()); + return NULL; + } + i++; + str = get_pword(i, buff); + if (!BEG_STRCASECMP(str, "string")) { + str = get_word(i + 1, buff); + action_add(mod, button, keysym, ACTION_STRING, (void *) str); + FREE(str); + } else if (!BEG_STRCASECMP(str, "echo")) { + str = get_word(i + 1, buff); + action_add(mod, button, keysym, ACTION_ECHO, (void *) str); + FREE(str); + } else if (!BEG_STRCASECMP(str, "menu")) { + menu_t *menu; + + str = get_word(i + 1, buff); + menu = find_menu_by_title(menu_list, str); + action_add(mod, button, keysym, ACTION_MENU, (void *) menu); + FREE(str); + } else if (!BEG_STRCASECMP(str, "script")) { + str = get_word(i + 1, buff); + action_add(mod, button, keysym, ACTION_SCRIPT, (void *) str); + FREE(str); + } else { + print_error + ("Parse error in file %s, line %lu: No valid action type found. Valid types are \"string,\" \"echo,\" \"menu,\" and \"script.\"\n", + file_peek_path(), file_peek_line()); + return NULL; + } - str = get_word(i+1, buff); - menu = find_menu_by_title(menu_list, str); - action_add(mod, button, keysym, ACTION_MENU, (void *) menu); - FREE(str); - } else if (!BEG_STRCASECMP(str, "script")) { - str = get_word(i+1, buff); - action_add(mod, button, keysym, ACTION_SCRIPT, (void *) str); - FREE(str); } else { - print_error("Parse error in file %s, line %lu: No valid action type found. Valid types are \"string,\" \"echo,\" \"menu,\" and \"script.\"\n", - file_peek_path(), file_peek_line()); - return NULL; + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context action\n", + file_peek_path(), file_peek_line(), buff); } - - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context action\n", - file_peek_path(), file_peek_line(), buff); - } - return state; + return state; } static void * parse_menu(char *buff, void *state) { - menu_t *menu; + menu_t *menu; - if (*buff == CONF_BEGIN_CHAR) { - char *title = get_pword(2, buff + 6); + if (*buff == CONF_BEGIN_CHAR) { + char *title = get_pword(2, buff + 6); - menu = menu_create(title); + menu = menu_create(title); + return ((void *) menu); + } + ASSERT_RVAL(state != NULL, (void *) (file_skip_to_end(), NULL)); + menu = (menu_t *) state; + if (*buff == CONF_END_CHAR) { + if (!(*(menu->title))) { + char tmp[20]; + + sprintf(tmp, "Eterm_Menu_%u", menu_list->nummenus); + menu_set_title(menu, tmp); + print_error("Parse error in file %s, line %lu: Menu context ended without giving a title. Defaulted to \"%s\".\n", + file_peek_path(), file_peek_line(), tmp); + } + menu_list = menulist_add_menu(menu_list, menu); + return NULL; + } + if (!BEG_STRCASECMP(buff, "title ")) { + char *title = get_word(2, buff); + + menu_set_title(menu, title); + FREE(title); + + } else if (!BEG_STRCASECMP(buff, "font ")) { + char *name = get_word(2, buff); + + if (!name) { + print_error("Parse error in file %s, line %lu: Missing font name.\n", file_peek_path(), file_peek_line()); + return ((void *) menu); + } + menu_set_font(menu, name); + FREE(name); + + } else if (!BEG_STRCASECMP(buff, "sep") || !BEG_STRCASECMP(buff, "-")) { + menuitem_t *item; + + item = menuitem_create((char *) NULL); + menu_add_item(menu, item); + menuitem_set_action(item, MENUITEM_SEP, (char *) NULL); + + } else { + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context menu\n", file_peek_path(), + file_peek_line(), buff); + } return ((void *) menu); - } - ASSERT_RVAL(state != NULL, (void *)(file_skip_to_end(), NULL)); - menu = (menu_t *) state; - if (*buff == CONF_END_CHAR) { - if (!(*(menu->title))) { - char tmp[20]; - - sprintf(tmp, "Eterm_Menu_%u", menu_list->nummenus); - menu_set_title(menu, tmp); - print_error("Parse error in file %s, line %lu: Menu context ended without giving a title. Defaulted to \"%s\".\n", file_peek_path(), file_peek_line(), tmp); - } - menu_list = menulist_add_menu(menu_list, menu); - return NULL; - } - if (!BEG_STRCASECMP(buff, "title ")) { - char *title = get_word(2, buff); - - menu_set_title(menu, title); - FREE(title); - - } else if (!BEG_STRCASECMP(buff, "font ")) { - char *name = get_word(2, buff); - - if (!name) { - print_error("Parse error in file %s, line %lu: Missing font name.\n", file_peek_path(), file_peek_line()); - return ((void *) menu); - } - menu_set_font(menu, name); - FREE(name); - - } else if (!BEG_STRCASECMP(buff, "sep") || !BEG_STRCASECMP(buff, "-")) { - menuitem_t *item; - - item = menuitem_create((char *) NULL); - menu_add_item(menu, item); - menuitem_set_action(item, MENUITEM_SEP, (char *) NULL); - - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context menu\n", file_peek_path(), file_peek_line(), buff); - } - return ((void *) menu); } static void * parse_menuitem(char *buff, void *state) { - static menu_t *menu; - menuitem_t *curitem; + static menu_t *menu; + menuitem_t *curitem; - ASSERT_RVAL(state != NULL, (void *)(file_skip_to_end(), NULL)); - if (*buff == CONF_BEGIN_CHAR) { - menu = (menu_t *) state; - curitem = menuitem_create(NULL); + ASSERT_RVAL(state != NULL, (void *) (file_skip_to_end(), NULL)); + if (*buff == CONF_BEGIN_CHAR) { + menu = (menu_t *) state; + curitem = menuitem_create(NULL); + return ((void *) curitem); + } + curitem = (menuitem_t *) state; + ASSERT_RVAL(menu != NULL, state); + if (*buff == CONF_END_CHAR) { + if (!(curitem->text)) { + print_error("Parse error in file %s, line %lu: Menuitem context ended with no text given. Discarding this entry.\n", + file_peek_path(), file_peek_line()); + FREE(curitem); + } else { + menu_add_item(menu, curitem); + } + return ((void *) menu); + } + if (!BEG_STRCASECMP(buff, "text ")) { + char *text = get_word(2, buff); + + if (!text) { + print_error("Parse error in file %s, line %lu: Missing menuitem text.\n", file_peek_path(), file_peek_line()); + return ((void *) curitem); + } + menuitem_set_text(curitem, text); + FREE(text); + + } else if (!BEG_STRCASECMP(buff, "rtext ")) { + char *rtext = get_word(2, buff); + + if (!rtext) { + print_error("Parse error in file %s, line %lu: Missing menuitem right-justified text.\n", file_peek_path(), file_peek_line()); + return ((void *) curitem); + } + menuitem_set_rtext(curitem, rtext); + FREE(rtext); + + } else if (!BEG_STRCASECMP(buff, "icon ")) { + + } else if (!BEG_STRCASECMP(buff, "action ")) { + char *type = get_pword(2, buff); + char *action = get_word(3, buff); + + if (!BEG_STRCASECMP(type, "submenu ")) { + menuitem_set_action(curitem, MENUITEM_SUBMENU, action); + + } else if (!BEG_STRCASECMP(type, "string ")) { + menuitem_set_action(curitem, MENUITEM_STRING, action); + + } else if (!BEG_STRCASECMP(type, "script ")) { + menuitem_set_action(curitem, MENUITEM_SCRIPT, action); + + } else if (!BEG_STRCASECMP(type, "echo ")) { + menuitem_set_action(curitem, MENUITEM_ECHO, action); + + } else if (!BEG_STRCASECMP(type, "separator")) { + menuitem_set_action(curitem, MENUITEM_SEP, action); + + } else { + print_error("Parse error in file %s, line %lu: Invalid menu item action \"%s\"\n", file_peek_path(), file_peek_line(), + NONULL(type)); + } + FREE(action); + + } else { + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context menu\n", file_peek_path(), + file_peek_line(), buff); + } return ((void *) curitem); - } - curitem = (menuitem_t *) state; - ASSERT_RVAL(menu != NULL, state); - if (*buff == CONF_END_CHAR) { - if (!(curitem->text)) { - print_error("Parse error in file %s, line %lu: Menuitem context ended with no text given. Discarding this entry.\n", file_peek_path(), file_peek_line()); - FREE(curitem); - } else { - menu_add_item(menu, curitem); - } - return ((void *) menu); - } - if (!BEG_STRCASECMP(buff, "text ")) { - char *text = get_word(2, buff); - - if (!text) { - print_error("Parse error in file %s, line %lu: Missing menuitem text.\n", file_peek_path(), file_peek_line()); - return ((void *) curitem); - } - menuitem_set_text(curitem, text); - FREE(text); - - } else if (!BEG_STRCASECMP(buff, "rtext ")) { - char *rtext = get_word(2, buff); - - if (!rtext) { - print_error("Parse error in file %s, line %lu: Missing menuitem right-justified text.\n", file_peek_path(), file_peek_line()); - return ((void *) curitem); - } - menuitem_set_rtext(curitem, rtext); - FREE(rtext); - - } else if (!BEG_STRCASECMP(buff, "icon ")) { - - } else if (!BEG_STRCASECMP(buff, "action ")) { - char *type = get_pword(2, buff); - char *action = get_word(3, buff); - - if (!BEG_STRCASECMP(type, "submenu ")) { - menuitem_set_action(curitem, MENUITEM_SUBMENU, action); - - } else if (!BEG_STRCASECMP(type, "string ")) { - menuitem_set_action(curitem, MENUITEM_STRING, action); - - } else if (!BEG_STRCASECMP(type, "script ")) { - menuitem_set_action(curitem, MENUITEM_SCRIPT, action); - - } else if (!BEG_STRCASECMP(type, "echo ")) { - menuitem_set_action(curitem, MENUITEM_ECHO, action); - - } else if (!BEG_STRCASECMP(type, "separator")) { - menuitem_set_action(curitem, MENUITEM_SEP, action); - - } else { - print_error("Parse error in file %s, line %lu: Invalid menu item action \"%s\"\n", file_peek_path(), file_peek_line(), NONULL(type)); - } - FREE(action); - - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context menu\n", file_peek_path(), file_peek_line(), buff); - } - return ((void *) curitem); } static void * parse_bbar(char *buff, void *state) { - buttonbar_t *bbar; + buttonbar_t *bbar; - if (*buff == CONF_BEGIN_CHAR) { - bbar = bbar_create(); - return ((void *) bbar); - } - ASSERT_RVAL(state != NULL, (void *)(file_skip_to_end(), NULL)); - bbar = (buttonbar_t *) state; - if (*buff == CONF_END_CHAR) { - bbar_add(bbar); - return NULL; - } - if (!BEG_STRCASECMP(buff, "font ")) { - char *font = get_word(2, buff); - - bbar_set_font(bbar, font); - FREE(font); - - } else if (!BEG_STRCASECMP(buff, "dock ")) { - char *where = get_pword(2, buff); - - if (!where) { - print_error("Parse error in file %s, line %lu: Attribute dock requires a parameter\n", file_peek_path(), file_peek_line()); - } else if (!BEG_STRCASECMP(where, "top")) { - bbar_set_docked(bbar, BBAR_DOCKED_TOP); - } else if (!BEG_STRCASECMP(where, "bot")) { /* "bot" or "bottom" */ - bbar_set_docked(bbar, BBAR_DOCKED_BOTTOM); - } else if (!BEG_STRCASECMP(where, "no")) { /* "no" or "none" */ - bbar_set_docked(bbar, BBAR_UNDOCKED); - } else { - print_error("Parse error in file %s, line %lu: Invalid parameter \"%s\" to attribute dock\n", file_peek_path(), file_peek_line(), where); - } - - } else if (!BEG_STRCASECMP(buff, "visible ")) { - char *tmp = get_pword(2, buff); - - if (BOOL_OPT_ISTRUE(tmp)) { - bbar_set_visible(bbar, 1); - } else if (BOOL_OPT_ISFALSE(tmp)) { - bbar_set_visible(bbar, 0); - } else { - print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" in context button_bar\n", file_peek_path(), file_peek_line(), tmp); - } - - } else if (!BEG_STRCASECMP(buff, "button ") || !BEG_STRCASECMP(buff, "rbutton ")) { - char *text = get_pword(2, buff); - char *icon = strcasestr(buff, "icon "); - char *action = strcasestr(buff, "action "); - button_t *button; - - if (text == icon) { - text = NULL; - } else { - text = get_word(2, buff); - } - if (!text && !icon) { - print_error("Parse error in file %s, line %lu: Missing button specifications\n", file_peek_path(), file_peek_line()); - return ((void *) bbar); - } - - button = button_create(text); - if (icon) { - simage_t *simg; - - icon = get_word(2, icon); - simg = create_simage(); - if (load_image(icon, simg)) { - button_set_icon(button, simg); - } else { - free_simage(simg); - } - FREE(icon); - } - if (action) { - char *type = get_pword(2, action); - - action = get_word(2, type); - if (!BEG_STRCASECMP(type, "menu ")) { - button_set_action(button, ACTION_MENU, action); - } else if (!BEG_STRCASECMP(type, "string ")) { - button_set_action(button, ACTION_STRING, action); - } else if (!BEG_STRCASECMP(type, "echo ")) { - button_set_action(button, ACTION_ECHO, action); - } else if (!BEG_STRCASECMP(type, "script ")) { - button_set_action(button, ACTION_SCRIPT, action); - } else { - print_error("Parse error in file %s, line %lu: Invalid button action \"%s\"\n", file_peek_path(), file_peek_line(), type); - FREE(action); - FREE(button); + if (*buff == CONF_BEGIN_CHAR) { + bbar = bbar_create(); return ((void *) bbar); - } - FREE(action); - } else { - print_error("Parse error in file %s, line %lu: Missing button action\n", file_peek_path(), file_peek_line()); - FREE(button); - return ((void *) bbar); } - if (tolower(*buff) == 'r') { - bbar_add_rbutton(bbar, button); - } else { - bbar_add_button(bbar, button); + ASSERT_RVAL(state != NULL, (void *) (file_skip_to_end(), NULL)); + bbar = (buttonbar_t *) state; + if (*buff == CONF_END_CHAR) { + bbar_add(bbar); + return NULL; } - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context menu\n", - file_peek_path(), file_peek_line(), buff); - } - return ((void *) bbar); + if (!BEG_STRCASECMP(buff, "font ")) { + char *font = get_word(2, buff); + + bbar_set_font(bbar, font); + FREE(font); + + } else if (!BEG_STRCASECMP(buff, "dock ")) { + char *where = get_pword(2, buff); + + if (!where) { + print_error("Parse error in file %s, line %lu: Attribute dock requires a parameter\n", file_peek_path(), file_peek_line()); + } else if (!BEG_STRCASECMP(where, "top")) { + bbar_set_docked(bbar, BBAR_DOCKED_TOP); + } else if (!BEG_STRCASECMP(where, "bot")) { /* "bot" or "bottom" */ + bbar_set_docked(bbar, BBAR_DOCKED_BOTTOM); + } else if (!BEG_STRCASECMP(where, "no")) { /* "no" or "none" */ + bbar_set_docked(bbar, BBAR_UNDOCKED); + } else { + print_error("Parse error in file %s, line %lu: Invalid parameter \"%s\" to attribute dock\n", file_peek_path(), + file_peek_line(), where); + } + + } else if (!BEG_STRCASECMP(buff, "visible ")) { + char *tmp = get_pword(2, buff); + + if (BOOL_OPT_ISTRUE(tmp)) { + bbar_set_visible(bbar, 1); + } else if (BOOL_OPT_ISFALSE(tmp)) { + bbar_set_visible(bbar, 0); + } else { + print_error("Parse error in file %s, line %lu: Invalid boolean value \"%s\" in context button_bar\n", file_peek_path(), + file_peek_line(), tmp); + } + + } else if (!BEG_STRCASECMP(buff, "button ") || !BEG_STRCASECMP(buff, "rbutton ")) { + char *text = get_pword(2, buff); + char *icon = strcasestr(buff, "icon "); + char *action = strcasestr(buff, "action "); + button_t *button; + + if (text == icon) { + text = NULL; + } else { + text = get_word(2, buff); + } + if (!text && !icon) { + print_error("Parse error in file %s, line %lu: Missing button specifications\n", file_peek_path(), file_peek_line()); + return ((void *) bbar); + } + + button = button_create(text); + if (icon) { + simage_t *simg; + + icon = get_word(2, icon); + simg = create_simage(); + if (load_image(icon, simg)) { + button_set_icon(button, simg); + } else { + free_simage(simg); + } + FREE(icon); + } + if (action) { + char *type = get_pword(2, action); + + action = get_word(2, type); + if (!BEG_STRCASECMP(type, "menu ")) { + button_set_action(button, ACTION_MENU, action); + } else if (!BEG_STRCASECMP(type, "string ")) { + button_set_action(button, ACTION_STRING, action); + } else if (!BEG_STRCASECMP(type, "echo ")) { + button_set_action(button, ACTION_ECHO, action); + } else if (!BEG_STRCASECMP(type, "script ")) { + button_set_action(button, ACTION_SCRIPT, action); + } else { + print_error("Parse error in file %s, line %lu: Invalid button action \"%s\"\n", file_peek_path(), file_peek_line(), type); + FREE(action); + FREE(button); + return ((void *) bbar); + } + FREE(action); + } else { + print_error("Parse error in file %s, line %lu: Missing button action\n", file_peek_path(), file_peek_line()); + FREE(button); + return ((void *) bbar); + } + if (tolower(*buff) == 'r') { + bbar_add_rbutton(bbar, button); + } else { + bbar_add_button(bbar, button); + } + } else { + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context menu\n", + file_peek_path(), file_peek_line(), buff); + } + return ((void *) bbar); } static void * parse_xim(char *buff, void *state) { #ifdef USE_XIM - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } - if (!BEG_STRCASECMP(buff, "input_method ")) { - RESET_AND_ASSIGN(rs_input_method, get_word(2, buff)); - } else if (!BEG_STRCASECMP(buff, "preedit_type ")) { - RESET_AND_ASSIGN(rs_preedit_type, get_word(2, buff)); - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context xim\n", - file_peek_path(), file_peek_line(), buff); - } + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; + } + if (!BEG_STRCASECMP(buff, "input_method ")) { + RESET_AND_ASSIGN(rs_input_method, get_word(2, buff)); + } else if (!BEG_STRCASECMP(buff, "preedit_type ")) { + RESET_AND_ASSIGN(rs_preedit_type, get_word(2, buff)); + } else { + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context xim\n", + file_peek_path(), file_peek_line(), buff); + } #else - print_warning("XIM support was not compiled in, ignoring entire context\n"); - file_poke_skip(1); + print_warning("XIM support was not compiled in, ignoring entire context\n"); + file_poke_skip(1); #endif - return state; - buff = NULL; + return state; + buff = NULL; } static void * parse_multichar(char *buff, void *state) { #ifdef MULTI_CHARSET - if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { - return NULL; - } - if (!BEG_STRCASECMP(buff, "encoding ")) { - RESET_AND_ASSIGN(rs_multichar_encoding, get_word(2, buff)); - if (rs_multichar_encoding != NULL) { - if (BEG_STRCASECMP(rs_multichar_encoding, "eucj") - && BEG_STRCASECMP(rs_multichar_encoding, "sjis") - && BEG_STRCASECMP(rs_multichar_encoding, "euckr") - && BEG_STRCASECMP(rs_multichar_encoding, "big5") - && BEG_STRCASECMP(rs_multichar_encoding, "gb") - && BEG_STRCASECMP(rs_multichar_encoding, "iso-10646") - && BEG_STRCASECMP(rs_multichar_encoding, "none")) { - print_error("Parse error in file %s, line %lu: Invalid multichar encoding mode \"%s\"\n", - file_peek_path(), file_peek_line(), rs_multichar_encoding); - FREE(rs_multichar_encoding); - return NULL; - } + if ((*buff == CONF_BEGIN_CHAR) || (*buff == CONF_END_CHAR)) { + return NULL; + } + if (!BEG_STRCASECMP(buff, "encoding ")) { + RESET_AND_ASSIGN(rs_multichar_encoding, get_word(2, buff)); + if (rs_multichar_encoding != NULL) { + if (BEG_STRCASECMP(rs_multichar_encoding, "eucj") + && BEG_STRCASECMP(rs_multichar_encoding, "sjis") + && BEG_STRCASECMP(rs_multichar_encoding, "euckr") + && BEG_STRCASECMP(rs_multichar_encoding, "big5") + && BEG_STRCASECMP(rs_multichar_encoding, "gb") + && BEG_STRCASECMP(rs_multichar_encoding, "iso-10646") + && BEG_STRCASECMP(rs_multichar_encoding, "none")) { + print_error("Parse error in file %s, line %lu: Invalid multichar encoding mode \"%s\"\n", + file_peek_path(), file_peek_line(), rs_multichar_encoding); + FREE(rs_multichar_encoding); + return NULL; + } + } else { + print_error("Parse error in file %s, line %lu: Invalid parameter list \"\" for attribute encoding\n", + file_peek_path(), file_peek_line()); + } + } else if (!BEG_STRCASECMP(buff, "font ")) { + + char *tmp = get_pword(2, buff); + unsigned char n; + + if (num_words(buff) != 3) { + print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for attribute font\n", + file_peek_path(), file_peek_line(), NONULL(tmp)); + return NULL; + } + if (isdigit(*tmp)) { + n = (unsigned char) strtoul(tmp, (char **) NULL, 0); + if (n <= 255) { + eterm_font_add(&etmfonts, get_pword(2, tmp), n); + } else { + print_error("Parse error in file %s, line %lu: Invalid font index %d\n", file_peek_path(), file_peek_line(), n); + } + } else { + tmp = get_word(1, tmp); + print_error("Parse error in file %s, line %lu: Invalid font index \"%s\"\n", file_peek_path(), file_peek_line(), NONULL(tmp)); + FREE(tmp); + } + } else { - print_error("Parse error in file %s, line %lu: Invalid parameter list \"\" for attribute encoding\n", - file_peek_path(), file_peek_line()); + print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context multichar\n", + file_peek_path(), file_peek_line(), buff); } - } else if (!BEG_STRCASECMP(buff, "font ")) { - - char *tmp = get_pword(2, buff); - unsigned char n; - - if (num_words(buff) != 3) { - print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for attribute font\n", - file_peek_path(), file_peek_line(), NONULL(tmp)); - return NULL; - } - if (isdigit(*tmp)) { - n = (unsigned char) strtoul(tmp, (char **) NULL, 0); - if (n <= 255) { - eterm_font_add(&etmfonts, get_pword(2, tmp), n); - } else { - print_error("Parse error in file %s, line %lu: Invalid font index %d\n", - file_peek_path(), file_peek_line(), n); - } - } else { - tmp = get_word(1, tmp); - print_error("Parse error in file %s, line %lu: Invalid font index \"%s\"\n", - file_peek_path(), file_peek_line(), NONULL(tmp)); - FREE(tmp); - } - - } else { - print_error("Parse error in file %s, line %lu: Attribute \"%s\" is not valid within context multichar\n", - file_peek_path(), file_peek_line(), buff); - } #else - if (*buff == CONF_BEGIN_CHAR) { - print_warning("Multichar support was not compiled in, ignoring entire context\n"); - file_poke_skip(1); - } + if (*buff == CONF_BEGIN_CHAR) { + print_warning("Multichar support was not compiled in, ignoring entire context\n"); + file_poke_skip(1); + } #endif - return state; - buff = NULL; + return state; + buff = NULL; } char * conf_parse_theme(char **theme, char *conf_name, unsigned char fallback) { - static char path[CONFIG_BUFF]; - char *ret = NULL; + static char path[CONFIG_BUFF]; + char *ret = NULL; - if (!(*path)) { - char *path_env; + if (!(*path)) { + char *path_env; - path_env = getenv(PATH_ENV); - if (path_env) { - strcpy(path, CONFIG_SEARCH_PATH ":"); - strcat(path, path_env); - } else { - strcpy(path, CONFIG_SEARCH_PATH); + path_env = getenv(PATH_ENV); + if (path_env) { + strcpy(path, CONFIG_SEARCH_PATH ":"); + strcat(path, path_env); + } else { + strcpy(path, CONFIG_SEARCH_PATH); + } + shell_expand(path); } - shell_expand(path); - } - if (fallback & PARSE_TRY_USER_THEME) { - if (theme && *theme && (ret = conf_parse(conf_name, *theme, path)) != NULL) { - return ret; + if (fallback & PARSE_TRY_USER_THEME) { + if (theme && *theme && (ret = conf_parse(conf_name, *theme, path)) != NULL) { + return ret; + } } - } - if (fallback & PARSE_TRY_DEFAULT_THEME) { - RESET_AND_ASSIGN(*theme, STRDUP(PACKAGE)); - if ((ret = conf_parse(conf_name, *theme, path)) != NULL) { - return ret; + if (fallback & PARSE_TRY_DEFAULT_THEME) { + RESET_AND_ASSIGN(*theme, STRDUP(PACKAGE)); + if ((ret = conf_parse(conf_name, *theme, path)) != NULL) { + return ret; + } } - } - if (fallback & PARSE_TRY_NO_THEME) { - RESET_AND_ASSIGN(*theme, NULL); - return (conf_parse(conf_name, *theme, path)); - } - return NULL; + if (fallback & PARSE_TRY_NO_THEME) { + RESET_AND_ASSIGN(*theme, NULL); + return (conf_parse(conf_name, *theme, path)); + } + return NULL; } /* Initialize the default values for everything */ @@ -2731,1237 +2740,1308 @@ void init_defaults(void) { #ifndef AUTO_ENCODING - unsigned char i; + unsigned char i; #endif #if DEBUG >= DEBUG_MEM - if (DEBUG_LEVEL >= DEBUG_MEM) { - memrec_init(); - } + if (DEBUG_LEVEL >= DEBUG_MEM) { + memrec_init(); + } #endif - Xdisplay = NULL; - rs_term_name = NULL; + Xdisplay = NULL; + rs_term_name = NULL; #ifdef CUTCHAR_OPTION - rs_cutchars = NULL; + rs_cutchars = NULL; #endif #ifndef NO_BOLDFONT - rs_boldFont = NULL; + rs_boldFont = NULL; #endif #ifdef PRINTPIPE - rs_print_pipe = NULL; + rs_print_pipe = NULL; #endif - rs_title = NULL; /* title name for window */ - rs_iconName = NULL; /* icon name for window */ - rs_geometry = NULL; /* window geometry */ + rs_title = NULL; /* title name for window */ + rs_iconName = NULL; /* icon name for window */ + rs_geometry = NULL; /* window geometry */ #ifdef PIXMAP_SUPPORT - rs_path = NULL; + rs_path = NULL; #endif #ifndef NO_BRIGHTCOLOR - colorfgbg = DEFAULT_RSTYLE; + colorfgbg = DEFAULT_RSTYLE; #endif - MEMSET(rs_font, 0, sizeof(char *) * NFONTS); + MEMSET(rs_font, 0, sizeof(char *) * NFONTS); #if AUTO_ENCODING #ifdef MULTI_CHARSET - eterm_default_font_locale(&etfonts, &etmfonts, &rs_multichar_encoding, &def_font_idx); + eterm_default_font_locale(&etfonts, &etmfonts, &rs_multichar_encoding, &def_font_idx); #else - eterm_default_font_locale(&etfonts, NULL, NULL, &def_font_idx); + eterm_default_font_locale(&etfonts, NULL, NULL, &def_font_idx); #endif #else - for (i = 0; i < NFONTS; i++) { - eterm_font_add(&etfonts, def_fontName[i], i); + for (i = 0; i < NFONTS; i++) { + eterm_font_add(&etfonts, def_fontName[i], i); #ifdef MULTI_CHARSET - eterm_font_add(&etmfonts, def_mfontName[i], i); + eterm_font_add(&etmfonts, def_mfontName[i], i); #endif - } + } #ifdef MULTI_CHARSET - rs_multichar_encoding = STRDUP(MULTICHAR_ENCODING); + rs_multichar_encoding = STRDUP(MULTICHAR_ENCODING); #endif #endif - TermWin.internalBorder = DEFAULT_BORDER_WIDTH; + TermWin.internalBorder = DEFAULT_BORDER_WIDTH; - /* Initialize the parser */ - conf_init_subsystem(); + /* Initialize the parser */ + conf_init_subsystem(); - /* Register Eterm's context parsers. */ - conf_register_context("color", parse_color); - conf_register_context("attributes", parse_attributes); - conf_register_context("toggles", parse_toggles); - conf_register_context("keyboard", parse_keyboard); - conf_register_context("misc", parse_misc); - conf_register_context("imageclasses", parse_imageclasses); - conf_register_context("image", parse_image); - conf_register_context("actions", parse_actions); - conf_register_context("menu", parse_menu); - conf_register_context("menuitem", parse_menuitem); - conf_register_context("button_bar", parse_bbar); - conf_register_context("xim", parse_xim); - conf_register_context("multichar", parse_multichar); + /* Register Eterm's context parsers. */ + conf_register_context("color", parse_color); + conf_register_context("attributes", parse_attributes); + conf_register_context("toggles", parse_toggles); + conf_register_context("keyboard", parse_keyboard); + conf_register_context("misc", parse_misc); + conf_register_context("imageclasses", parse_imageclasses); + conf_register_context("image", parse_image); + conf_register_context("actions", parse_actions); + conf_register_context("menu", parse_menu); + conf_register_context("menuitem", parse_menuitem); + conf_register_context("button_bar", parse_bbar); + conf_register_context("xim", parse_xim); + conf_register_context("multichar", parse_multichar); } /* Sync up options with our internal data after parsing options and configs */ void post_parse(void) { - register int i; + register int i; - if (rs_scrollbar_type) { - if (!strcasecmp(rs_scrollbar_type, "xterm")) { + if (rs_scrollbar_type) { + if (!strcasecmp(rs_scrollbar_type, "xterm")) { #ifdef XTERM_SCROLLBAR - scrollbar_set_type(SCROLLBAR_XTERM); + scrollbar_set_type(SCROLLBAR_XTERM); #else - print_error("Support for xterm scrollbars was not compiled in. Sorry.\n"); + print_error("Support for xterm scrollbars was not compiled in. Sorry.\n"); #endif - } else if (!strcasecmp(rs_scrollbar_type, "next")) { + } else if (!strcasecmp(rs_scrollbar_type, "next")) { #ifdef NEXT_SCROLLBAR - scrollbar_set_type(SCROLLBAR_NEXT); + scrollbar_set_type(SCROLLBAR_NEXT); #else - print_error("Support for NeXT scrollbars was not compiled in. Sorry.\n"); + print_error("Support for NeXT scrollbars was not compiled in. Sorry.\n"); #endif - } else if (!strcasecmp(rs_scrollbar_type, "motif")) { + } else if (!strcasecmp(rs_scrollbar_type, "motif")) { #ifdef MOTIF_SCROLLBAR - scrollbar_set_type(SCROLLBAR_MOTIF); + scrollbar_set_type(SCROLLBAR_MOTIF); #else - print_error("Support for motif scrollbars was not compiled in. Sorry.\n"); + print_error("Support for motif scrollbars was not compiled in. Sorry.\n"); #endif - } else { - print_error("Unrecognized scrollbar type \"%s\".\n", rs_scrollbar_type); + } else { + print_error("Unrecognized scrollbar type \"%s\".\n", rs_scrollbar_type); + } } - } - if (rs_scrollbar_width) { - scrollbar_set_width(rs_scrollbar_width); - } - - /* set any defaults not already set */ - if (rs_name == NULL) { - if (rs_exec_args != NULL) { - rs_name = STRDUP(rs_exec_args[0]); - } else { - rs_name = STRDUP(APL_NAME " " VERSION); + if (rs_scrollbar_width) { + scrollbar_set_width(rs_scrollbar_width); } - } - if (!rs_title) { - rs_title = rs_name; - } - if (!rs_iconName) { - rs_iconName = rs_name; - } - if ((TermWin.saveLines = rs_saveLines) < 0) { - TermWin.saveLines = SAVELINES; - } - /* no point having a scrollbar without having any scrollback! */ - if (!TermWin.saveLines) { - Options &= ~Opt_scrollbar; - } + /* set any defaults not already set */ + if (rs_name == NULL) { + if (rs_exec_args != NULL) { + rs_name = STRDUP(rs_exec_args[0]); + } else { + rs_name = STRDUP(APL_NAME " " VERSION); + } + } + if (!rs_title) { + rs_title = rs_name; + } + if (!rs_iconName) { + rs_iconName = rs_name; + } + if ((TermWin.saveLines = rs_saveLines) < 0) { + TermWin.saveLines = SAVELINES; + } + /* no point having a scrollbar without having any scrollback! */ + if (!TermWin.saveLines) { + Options &= ~Opt_scrollbar; + } #ifdef PRINTPIPE - if (!rs_print_pipe) { - rs_print_pipe = STRDUP(PRINTPIPE); - } + if (!rs_print_pipe) { + rs_print_pipe = STRDUP(PRINTPIPE); + } #endif #ifdef CUTCHAR_OPTION - if (!rs_cutchars) { - rs_cutchars = STRDUP(CUTCHARS); - } + if (!rs_cutchars) { + rs_cutchars = STRDUP(CUTCHARS); + } #endif #ifndef NO_BOLDFONT - if (rs_font[0] == NULL && rs_boldFont != NULL) { - rs_font[0] = rs_boldFont; - rs_boldFont = NULL; - } -#endif - for (i = 0; i < NFONTS; i++) { - if (rs_font[i]) { - if (def_font_idx == 0) { - eterm_font_add(&etfonts, rs_font[i], i); - RESET_AND_ASSIGN(rs_font[i], NULL); - } else { - eterm_font_add(&etfonts, rs_font[i], ((i == 0) ? def_font_idx : ((i <= def_font_idx) ? (i - 1) : i))); - RESET_AND_ASSIGN(rs_font[i], NULL); - } - } -#ifdef MULTI_CHARSET - if (rs_mfont[i]) { - if (def_font_idx == 0) { - eterm_font_add(&etmfonts, rs_mfont[i], i); - RESET_AND_ASSIGN(rs_mfont[i], NULL); - } else { - eterm_font_add(&etmfonts, rs_mfont[i], ((i == 0) ? def_font_idx : ((i <= def_font_idx) ? (i - 1) : i))); - RESET_AND_ASSIGN(rs_mfont[i], NULL); - } - } - if (rs_multichar_encoding != NULL) { - set_multichar_encoding(rs_multichar_encoding); + if (rs_font[0] == NULL && rs_boldFont != NULL) { + rs_font[0] = rs_boldFont; + rs_boldFont = NULL; } #endif - } - if (rs_font_effects) { - if (parse_font_fx(rs_font_effects) != 1) { - print_error("Syntax error in the font effects specified on the command line.\n"); - } - RESET_AND_ASSIGN(rs_font_effects, NULL); - } - - /* Clean up image stuff */ - for (i = 0; i < image_max; i++) { - simage_t *simg; - imlib_t *iml; - - if (images[i].norm) { - simg = images[i].norm; - iml = simg->iml; - /* If we have a bevel but no border, use the bevel as a border. */ - if (iml->bevel && !(iml->border)) { - iml->border = iml->bevel->edges; - } -#ifdef PIXMAP_SUPPORT - if (iml->im) { - imlib_context_set_image(iml->im); - update_cmod_tables(iml); - } -#endif - images[i].userdef = 1; - } else { - simg = images[i].norm = (simage_t *) MALLOC(sizeof(simage_t)); - simg->pmap = (pixmap_t *) MALLOC(sizeof(pixmap_t)); - simg->iml = (imlib_t *) MALLOC(sizeof(imlib_t)); - simg->fg = WhitePixel(Xdisplay, Xscreen); - simg->bg = BlackPixel(Xdisplay, Xscreen); - MEMSET(simg->pmap, 0, sizeof(pixmap_t)); - MEMSET(simg->iml, 0, sizeof(imlib_t)); - images[i].mode = MODE_IMAGE & ALLOW_IMAGE; - } - images[i].current = simg; -#ifdef PIXMAP_SUPPORT - if (rs_pixmaps[i]) { - reset_simage(images[i].norm, RESET_ALL_SIMG); - load_image(rs_pixmaps[i], images[i].norm); - FREE(rs_pixmaps[i]); /* These are created by STRDUP() */ - } -#else - /* Right now, solid mode is the only thing we can do without pixmap support. */ - images[i].mode = MODE_SOLID & ALLOW_SOLID; -#endif - - if (images[i].selected) { - simage_t *norm_simg = images[i].norm; - - simg = images[i].selected; - iml = simg->iml; - /* If we have a bevel but no border, use the bevel as a border. */ - if (iml->bevel && !(iml->border)) { - iml->border = iml->bevel->edges; - } - /* If normal has an image but we don't, copy it. */ - if (!(simg->iml->im) && (norm_simg->iml->im)) { - simg->iml->im = norm_simg->iml->im; - *(simg->pmap) = *(norm_simg->pmap); - } - if (simg->fg == 0 && simg->bg == 0) { - simg->fg = norm_simg->fg; - simg->bg = norm_simg->bg; - } -#ifdef PIXMAP_SUPPORT - if (iml->im) { - imlib_context_set_image(iml->im); - update_cmod_tables(iml); - } -#endif - } else { - D_PIXMAP(("No \"selected\" state for image %s. Setting fallback to the normal state.\n", get_image_type(i))); - images[i].selected = images[i].norm; - } - if (images[i].clicked) { - simage_t *norm_simg = images[i].norm; - - simg = images[i].clicked; - iml = simg->iml; - /* If we have a bevel but no border, use the bevel as a border. */ - if (iml->bevel && !(iml->border)) { - iml->border = iml->bevel->edges; - } - /* If normal has an image but we don't, copy it. */ - if (!(simg->iml->im) && (norm_simg->iml->im)) { - simg->iml->im = norm_simg->iml->im; - *(simg->pmap) = *(norm_simg->pmap); - } - if (simg->fg == 0 && simg->bg == 0) { - simg->fg = norm_simg->fg; - simg->bg = norm_simg->bg; - } -#ifdef PIXMAP_SUPPORT - if (iml->im) { - imlib_context_set_image(iml->im); - update_cmod_tables(iml); - } -#endif - } else { - D_PIXMAP(("No \"clicked\" state for image %s. Setting fallback to the selected state.\n", get_image_type(i))); - images[i].clicked = images[i].selected; - } - if (images[i].disabled) { - simage_t *norm_simg = images[i].norm; - - simg = images[i].disabled; - iml = simg->iml; - /* If we have a bevel but no border, use the bevel as a border. */ - if (iml->bevel && !(iml->border)) { - iml->border = iml->bevel->edges; - } - /* If normal has an image but we don't, copy it. */ - if (!(simg->iml->im) && (norm_simg->iml->im)) { - simg->iml->im = norm_simg->iml->im; - *(simg->pmap) = *(norm_simg->pmap); - } - if (simg->fg == 0 && simg->bg == 0) { - simg->fg = norm_simg->fg; - simg->bg = norm_simg->bg; - } -#ifdef PIXMAP_SUPPORT - if (iml->im) { - imlib_context_set_image(iml->im); - update_cmod_tables(iml); - } -#endif - } else { - D_PIXMAP(("No \"disabled\" state for image %s. Setting fallback to the normal state.\n", get_image_type(i))); - images[i].disabled = images[i].norm; - } - if ((image_toggles & IMOPT_TRANS) && (image_mode_is(i, ALLOW_TRANS))) { - D_PIXMAP(("Detected transparency option. Enabling transparency on image %s\n", get_image_type(i))); - image_set_mode(i, MODE_TRANS); - } else if ((image_toggles & IMOPT_VIEWPORT) && (image_mode_is(i, ALLOW_VIEWPORT))) { - D_PIXMAP(("Detected viewport option. Enabling viewport mode on image %s\n", get_image_type(i))); - image_set_mode(i, MODE_VIEWPORT); - } - } - if (images[image_bg].norm->fg || images[image_bg].norm->bg) { - /* They specified their colors here, so copy them to the right place. */ - PixColors[fgColor] = images[image_bg].norm->fg; - PixColors[bgColor] = images[image_bg].norm->bg; - } - - /* rs_buttonbars is set to 1. If it stays 1, the option was never - specified. If specified, it will either become 3 (on) or 0 (off). */ - if (rs_buttonbars != 1) { - if (rs_buttonbars) { - FOREACH_BUTTONBAR(bbar_set_visible(bbar, 1);); - } else { - FOREACH_BUTTONBAR(bbar_set_visible(bbar, 0);); - } - rs_buttonbars = 1; /* Reset for future use. */ - } - /* Update buttonbar sizes based on new imageclass info. */ - bbar_resize_all(-1); - -#ifdef PIXMAP_SUPPORT - /* Support the deprecated forms by converting the syntax to the new system */ - if (rs_shade != 0) { - char buff[10]; - - sprintf(buff, "0x%03x", ((100 - rs_shade) << 8) / 100); - rs_cmod_image = STRDUP(buff); - D_PIXMAP(("--shade value of %d converted to cmod value of %s\n", rs_shade, rs_cmod_image)); - } - if (rs_tint) { - char buff[10]; - unsigned long r, g, b, t; - - if (!isdigit(*rs_tint)) { - t = get_tint_by_color_name(rs_tint); - } else { - t = (unsigned long) strtoul(rs_tint, (char **) NULL, 0); - D_PIXMAP(("Got numerical tint 0x%06x\n", t)); - } - if (t != 0xffffff) { - r = (t & 0xff0000) >> 16; - if (r != 0xff) { - sprintf(buff, "0x%03lx", r); - rs_cmod_red = STRDUP(buff); - } - g = (t & 0xff00) >> 8; - if (g != 0xff) { - sprintf(buff, "0x%03lx", g); - rs_cmod_green = STRDUP(buff); - } - b = t & 0xff; - if (b != 0xff) { - sprintf(buff, "0x%03lx", b); - rs_cmod_blue = STRDUP(buff); - } - } - FREE(rs_tint); - } - if (rs_cmod_image) { - unsigned char n = num_words(rs_cmod_image); - imlib_t *iml = images[image_bg].norm->iml; - - if (iml->mod) { - free_colormod(iml->mod); - } - iml->mod = create_colormod(); - iml->mod->brightness = (int) strtol(rs_cmod_image, (char **) NULL, 0); - if (n > 1) { - iml->mod->contrast = (int) strtol(get_pword(2, rs_cmod_image), (char **) NULL, 0); - } - if (n > 2) { - iml->mod->gamma = (int) strtol(get_pword(3, rs_cmod_image), (char **) NULL, 0); - } - D_PIXMAP(("From image cmod string %s to brightness %d, contrast %d, and gamma %d\n", rs_cmod_image, - iml->mod->brightness, iml->mod->contrast, iml->mod->gamma)); - FREE(rs_cmod_image); - } - if (rs_cmod_red) { - unsigned char n = num_words(rs_cmod_red); - imlib_t *iml = images[image_bg].norm->iml; - - if (iml->rmod) { - free_colormod(iml->rmod); - } - iml->rmod = create_colormod(); - iml->rmod->brightness = (int) strtol(rs_cmod_red, (char **) NULL, 0); - if (n > 1) { - iml->rmod->contrast = (int) strtol(get_pword(2, rs_cmod_red), (char **) NULL, 0); - } - if (n > 2) { - iml->rmod->gamma = (int) strtol(get_pword(3, rs_cmod_red), (char **) NULL, 0); - } - D_PIXMAP(("From red cmod string %s to brightness %d, contrast %d, and gamma %d\n", rs_cmod_red, - iml->rmod->brightness, iml->rmod->contrast, iml->rmod->gamma)); - FREE(rs_cmod_red); - update_cmod(iml->rmod); - } - if (rs_cmod_green) { - unsigned char n = num_words(rs_cmod_green); - imlib_t *iml = images[image_bg].norm->iml; - - if (iml->gmod) { - free_colormod(iml->gmod); - } - iml->gmod = create_colormod(); - iml->gmod->brightness = (int) strtol(rs_cmod_green, (char **) NULL, 0); - if (n > 1) { - iml->gmod->contrast = (int) strtol(get_pword(2, rs_cmod_green), (char **) NULL, 0); - } - if (n > 2) { - iml->gmod->gamma = (int) strtol(get_pword(3, rs_cmod_green), (char **) NULL, 0); - } - D_PIXMAP(("From green cmod string %s to brightness %d, contrast %d, and gamma %d\n", rs_cmod_green, - iml->gmod->brightness, iml->gmod->contrast, iml->gmod->gamma)); - FREE(rs_cmod_green); - update_cmod(iml->gmod); - } - if (rs_cmod_blue) { - unsigned char n = num_words(rs_cmod_blue); - imlib_t *iml = images[image_bg].norm->iml; - - if (iml->bmod) { - free_colormod(iml->bmod); - } - iml->bmod = create_colormod(); - iml->bmod->brightness = (int) strtol(rs_cmod_blue, (char **) NULL, 0); - if (n > 1) { - iml->bmod->contrast = (int) strtol(get_pword(2, rs_cmod_blue), (char **) NULL, 0); - } - if (n > 2) { - iml->bmod->gamma = (int) strtol(get_pword(3, rs_cmod_blue), (char **) NULL, 0); - } - D_PIXMAP(("From blue cmod string %s to brightness %d, contrast %d, and gamma %d\n", rs_cmod_blue, - iml->bmod->brightness, iml->bmod->contrast, iml->bmod->gamma)); - FREE(rs_cmod_blue); - update_cmod(iml->bmod); - } - if (images[image_bg].norm->iml->im) { - imlib_context_set_image(images[image_bg].norm->iml->im); - update_cmod_tables(images[image_bg].norm->iml); - } - - if (rs_cache_size == (unsigned long) -1) { - imlib_set_cache_size(0); - } else { - imlib_set_cache_size(rs_cache_size); - } -#endif - - if (Options & Opt_reverse_video) { - char *tmp; - - /* swap foreground/background colors */ - - tmp = rs_color[fgColor]; - rs_color[fgColor] = rs_color[bgColor]; - rs_color[bgColor] = tmp; - - tmp = def_colorName[fgColor]; - def_colorName[fgColor] = def_colorName[bgColor]; - def_colorName[bgColor] = tmp; - } - - if (rs_meta_mod) { - MetaMask = modmasks[rs_meta_mod - 1]; - } - if (rs_alt_mod) { - AltMask = modmasks[rs_alt_mod - 1]; - } - if (rs_numlock_mod) { - NumLockMask = modmasks[rs_numlock_mod - 1]; - } - -#ifdef BACKGROUND_CYCLING_SUPPORT - if (rs_anim_pixmap_list != NULL) { - rs_anim_delay = strtoul(rs_anim_pixmap_list, (char **) NULL, 0); - fflush(stdout); - if (rs_anim_delay == 0) { - FREE(rs_anim_pixmap_list); - rs_anim_pixmap_list = NULL; - } else { - char *w1, *h1, *temp; - unsigned long w, h; - int count; - - count = num_words(rs_anim_pixmap_list) - 1; /* -1 for the delay */ - rs_anim_pixmaps = (char **) MALLOC(sizeof(char *) * (count + 1)); - - for (i = 0; i < count; i++) { - temp = get_word(i + 2, rs_anim_pixmap_list); /* +2 rather than +1 to account for the delay */ - if (temp == NULL) - break; - if (num_words(temp) != 3) { - if (num_words(temp) == 1) { - rs_anim_pixmaps[i] = temp; - } - } else { - w1 = get_pword(1, temp); - h1 = get_pword(2, temp); - w = strtol(w1, (char **) NULL, 0); - h = strtol(h1, (char **) NULL, 0); - if (w || h) { - rs_anim_pixmaps[i] = get_word(3, temp); - rs_anim_pixmaps[i] = (char *) REALLOC(rs_anim_pixmaps[i], strlen(rs_anim_pixmaps[i]) + 9); - strcat(rs_anim_pixmaps[i], "@100x100"); - } else { - rs_anim_pixmaps[i] = get_word(3, temp); - rs_anim_pixmaps[i] = (char *) REALLOC(rs_anim_pixmaps[i], strlen(rs_anim_pixmaps[i]) + 5); - strcat(rs_anim_pixmaps[i], "@0x0"); - } - FREE(temp); - } - } - rs_anim_pixmaps[count] = NULL; - FREE(rs_anim_pixmap_list); - } - } else { - rs_anim_delay = 0; - } -#endif - - if (rs_pipe_name) { - struct stat fst; - - if (lstat(rs_pipe_name, &fst) != 0) { - print_error("Unable to stat console pipe \"%s\" -- %s\n", rs_pipe_name, strerror(errno)); - } else { - if (S_ISREG(fst.st_mode) || S_ISDIR(fst.st_mode)) { - print_error("Directories and regular files are not valid console pipes. Sorry.\n"); - } else { - pipe_fd = open(rs_pipe_name, O_RDONLY | O_NDELAY | O_NOCTTY); - if (pipe_fd < 0) { - print_error("Unable to open console pipe -- %s\n", strerror(errno)); + for (i = 0; i < NFONTS; i++) { + if (rs_font[i]) { + if (def_font_idx == 0) { + eterm_font_add(&etfonts, rs_font[i], i); + RESET_AND_ASSIGN(rs_font[i], NULL); + } else { + eterm_font_add(&etfonts, rs_font[i], ((i == 0) ? def_font_idx : ((i <= def_font_idx) ? (i - 1) : i))); + RESET_AND_ASSIGN(rs_font[i], NULL); + } + } +#ifdef MULTI_CHARSET + if (rs_mfont[i]) { + if (def_font_idx == 0) { + eterm_font_add(&etmfonts, rs_mfont[i], i); + RESET_AND_ASSIGN(rs_mfont[i], NULL); + } else { + eterm_font_add(&etmfonts, rs_mfont[i], ((i == 0) ? def_font_idx : ((i <= def_font_idx) ? (i - 1) : i))); + RESET_AND_ASSIGN(rs_mfont[i], NULL); + } + } + if (rs_multichar_encoding != NULL) { + set_multichar_encoding(rs_multichar_encoding); + } +#endif + } + if (rs_font_effects) { + if (parse_font_fx(rs_font_effects) != 1) { + print_error("Syntax error in the font effects specified on the command line.\n"); + } + RESET_AND_ASSIGN(rs_font_effects, NULL); + } + + /* Clean up image stuff */ + for (i = 0; i < image_max; i++) { + simage_t *simg; + imlib_t *iml; + + if (images[i].norm) { + simg = images[i].norm; + iml = simg->iml; + /* If we have a bevel but no border, use the bevel as a border. */ + if (iml->bevel && !(iml->border)) { + iml->border = iml->bevel->edges; + } +#ifdef PIXMAP_SUPPORT + if (iml->im) { + imlib_context_set_image(iml->im); + update_cmod_tables(iml); + } +#endif + images[i].userdef = 1; + } else { + simg = images[i].norm = (simage_t *) MALLOC(sizeof(simage_t)); + simg->pmap = (pixmap_t *) MALLOC(sizeof(pixmap_t)); + simg->iml = (imlib_t *) MALLOC(sizeof(imlib_t)); + simg->fg = WhitePixel(Xdisplay, Xscreen); + simg->bg = BlackPixel(Xdisplay, Xscreen); + MEMSET(simg->pmap, 0, sizeof(pixmap_t)); + MEMSET(simg->iml, 0, sizeof(imlib_t)); + images[i].mode = MODE_IMAGE & ALLOW_IMAGE; + } + images[i].current = simg; +#ifdef PIXMAP_SUPPORT + if (rs_pixmaps[i]) { + reset_simage(images[i].norm, RESET_ALL_SIMG); + load_image(rs_pixmaps[i], images[i].norm); + FREE(rs_pixmaps[i]); /* These are created by STRDUP() */ + } +#else + /* Right now, solid mode is the only thing we can do without pixmap support. */ + images[i].mode = MODE_SOLID & ALLOW_SOLID; +#endif + + if (images[i].selected) { + simage_t *norm_simg = images[i].norm; + + simg = images[i].selected; + iml = simg->iml; + /* If we have a bevel but no border, use the bevel as a border. */ + if (iml->bevel && !(iml->border)) { + iml->border = iml->bevel->edges; + } + /* If normal has an image but we don't, copy it. */ + if (!(simg->iml->im) && (norm_simg->iml->im)) { + simg->iml->im = norm_simg->iml->im; + *(simg->pmap) = *(norm_simg->pmap); + } + if (simg->fg == 0 && simg->bg == 0) { + simg->fg = norm_simg->fg; + simg->bg = norm_simg->bg; + } +#ifdef PIXMAP_SUPPORT + if (iml->im) { + imlib_context_set_image(iml->im); + update_cmod_tables(iml); + } +#endif + } else { + D_PIXMAP(("No \"selected\" state for image %s. Setting fallback to the normal state.\n", get_image_type(i))); + images[i].selected = images[i].norm; + } + if (images[i].clicked) { + simage_t *norm_simg = images[i].norm; + + simg = images[i].clicked; + iml = simg->iml; + /* If we have a bevel but no border, use the bevel as a border. */ + if (iml->bevel && !(iml->border)) { + iml->border = iml->bevel->edges; + } + /* If normal has an image but we don't, copy it. */ + if (!(simg->iml->im) && (norm_simg->iml->im)) { + simg->iml->im = norm_simg->iml->im; + *(simg->pmap) = *(norm_simg->pmap); + } + if (simg->fg == 0 && simg->bg == 0) { + simg->fg = norm_simg->fg; + simg->bg = norm_simg->bg; + } +#ifdef PIXMAP_SUPPORT + if (iml->im) { + imlib_context_set_image(iml->im); + update_cmod_tables(iml); + } +#endif + } else { + D_PIXMAP(("No \"clicked\" state for image %s. Setting fallback to the selected state.\n", get_image_type(i))); + images[i].clicked = images[i].selected; + } + if (images[i].disabled) { + simage_t *norm_simg = images[i].norm; + + simg = images[i].disabled; + iml = simg->iml; + /* If we have a bevel but no border, use the bevel as a border. */ + if (iml->bevel && !(iml->border)) { + iml->border = iml->bevel->edges; + } + /* If normal has an image but we don't, copy it. */ + if (!(simg->iml->im) && (norm_simg->iml->im)) { + simg->iml->im = norm_simg->iml->im; + *(simg->pmap) = *(norm_simg->pmap); + } + if (simg->fg == 0 && simg->bg == 0) { + simg->fg = norm_simg->fg; + simg->bg = norm_simg->bg; + } +#ifdef PIXMAP_SUPPORT + if (iml->im) { + imlib_context_set_image(iml->im); + update_cmod_tables(iml); + } +#endif + } else { + D_PIXMAP(("No \"disabled\" state for image %s. Setting fallback to the normal state.\n", get_image_type(i))); + images[i].disabled = images[i].norm; + } + if ((image_toggles & IMOPT_TRANS) && (image_mode_is(i, ALLOW_TRANS))) { + D_PIXMAP(("Detected transparency option. Enabling transparency on image %s\n", get_image_type(i))); + image_set_mode(i, MODE_TRANS); + } else if ((image_toggles & IMOPT_VIEWPORT) && (image_mode_is(i, ALLOW_VIEWPORT))) { + D_PIXMAP(("Detected viewport option. Enabling viewport mode on image %s\n", get_image_type(i))); + image_set_mode(i, MODE_VIEWPORT); + } + } + if (images[image_bg].norm->fg || images[image_bg].norm->bg) { + /* They specified their colors here, so copy them to the right place. */ + PixColors[fgColor] = images[image_bg].norm->fg; + PixColors[bgColor] = images[image_bg].norm->bg; + } + + /* rs_buttonbars is set to 1. If it stays 1, the option was never + specified. If specified, it will either become 3 (on) or 0 (off). */ + if (rs_buttonbars != 1) { + if (rs_buttonbars) { + FOREACH_BUTTONBAR(bbar_set_visible(bbar, 1); + ); + } else { + FOREACH_BUTTONBAR(bbar_set_visible(bbar, 0); + ); + } + rs_buttonbars = 1; /* Reset for future use. */ + } + /* Update buttonbar sizes based on new imageclass info. */ + bbar_resize_all(-1); + +#ifdef PIXMAP_SUPPORT + /* Support the deprecated forms by converting the syntax to the new system */ + if (rs_shade != 0) { + char buff[10]; + + sprintf(buff, "0x%03x", ((100 - rs_shade) << 8) / 100); + rs_cmod_image = STRDUP(buff); + D_PIXMAP(("--shade value of %d converted to cmod value of %s\n", rs_shade, rs_cmod_image)); + } + if (rs_tint) { + char buff[10]; + unsigned long r, g, b, t; + + if (!isdigit(*rs_tint)) { + t = get_tint_by_color_name(rs_tint); + } else { + t = (unsigned long) strtoul(rs_tint, (char **) NULL, 0); + D_PIXMAP(("Got numerical tint 0x%06x\n", t)); + } + if (t != 0xffffff) { + r = (t & 0xff0000) >> 16; + if (r != 0xff) { + sprintf(buff, "0x%03lx", r); + rs_cmod_red = STRDUP(buff); + } + g = (t & 0xff00) >> 8; + if (g != 0xff) { + sprintf(buff, "0x%03lx", g); + rs_cmod_green = STRDUP(buff); + } + b = t & 0xff; + if (b != 0xff) { + sprintf(buff, "0x%03lx", b); + rs_cmod_blue = STRDUP(buff); + } + } + FREE(rs_tint); + } + if (rs_cmod_image) { + unsigned char n = num_words(rs_cmod_image); + imlib_t *iml = images[image_bg].norm->iml; + + if (iml->mod) { + free_colormod(iml->mod); + } + iml->mod = create_colormod(); + iml->mod->brightness = (int) strtol(rs_cmod_image, (char **) NULL, 0); + if (n > 1) { + iml->mod->contrast = (int) strtol(get_pword(2, rs_cmod_image), (char **) NULL, 0); + } + if (n > 2) { + iml->mod->gamma = (int) strtol(get_pword(3, rs_cmod_image), (char **) NULL, 0); + } + D_PIXMAP(("From image cmod string %s to brightness %d, contrast %d, and gamma %d\n", rs_cmod_image, + iml->mod->brightness, iml->mod->contrast, iml->mod->gamma)); + FREE(rs_cmod_image); + } + if (rs_cmod_red) { + unsigned char n = num_words(rs_cmod_red); + imlib_t *iml = images[image_bg].norm->iml; + + if (iml->rmod) { + free_colormod(iml->rmod); + } + iml->rmod = create_colormod(); + iml->rmod->brightness = (int) strtol(rs_cmod_red, (char **) NULL, 0); + if (n > 1) { + iml->rmod->contrast = (int) strtol(get_pword(2, rs_cmod_red), (char **) NULL, 0); + } + if (n > 2) { + iml->rmod->gamma = (int) strtol(get_pword(3, rs_cmod_red), (char **) NULL, 0); + } + D_PIXMAP(("From red cmod string %s to brightness %d, contrast %d, and gamma %d\n", rs_cmod_red, + iml->rmod->brightness, iml->rmod->contrast, iml->rmod->gamma)); + FREE(rs_cmod_red); + update_cmod(iml->rmod); + } + if (rs_cmod_green) { + unsigned char n = num_words(rs_cmod_green); + imlib_t *iml = images[image_bg].norm->iml; + + if (iml->gmod) { + free_colormod(iml->gmod); + } + iml->gmod = create_colormod(); + iml->gmod->brightness = (int) strtol(rs_cmod_green, (char **) NULL, 0); + if (n > 1) { + iml->gmod->contrast = (int) strtol(get_pword(2, rs_cmod_green), (char **) NULL, 0); + } + if (n > 2) { + iml->gmod->gamma = (int) strtol(get_pword(3, rs_cmod_green), (char **) NULL, 0); + } + D_PIXMAP(("From green cmod string %s to brightness %d, contrast %d, and gamma %d\n", rs_cmod_green, + iml->gmod->brightness, iml->gmod->contrast, iml->gmod->gamma)); + FREE(rs_cmod_green); + update_cmod(iml->gmod); + } + if (rs_cmod_blue) { + unsigned char n = num_words(rs_cmod_blue); + imlib_t *iml = images[image_bg].norm->iml; + + if (iml->bmod) { + free_colormod(iml->bmod); + } + iml->bmod = create_colormod(); + iml->bmod->brightness = (int) strtol(rs_cmod_blue, (char **) NULL, 0); + if (n > 1) { + iml->bmod->contrast = (int) strtol(get_pword(2, rs_cmod_blue), (char **) NULL, 0); + } + if (n > 2) { + iml->bmod->gamma = (int) strtol(get_pword(3, rs_cmod_blue), (char **) NULL, 0); + } + D_PIXMAP(("From blue cmod string %s to brightness %d, contrast %d, and gamma %d\n", rs_cmod_blue, + iml->bmod->brightness, iml->bmod->contrast, iml->bmod->gamma)); + FREE(rs_cmod_blue); + update_cmod(iml->bmod); + } + if (images[image_bg].norm->iml->im) { + imlib_context_set_image(images[image_bg].norm->iml->im); + update_cmod_tables(images[image_bg].norm->iml); + } + + if (rs_cache_size == (unsigned long) -1) { + imlib_set_cache_size(0); + } else { + imlib_set_cache_size(rs_cache_size); + } +#endif + + if (Options & Opt_reverse_video) { + char *tmp; + + /* swap foreground/background colors */ + + tmp = rs_color[fgColor]; + rs_color[fgColor] = rs_color[bgColor]; + rs_color[bgColor] = tmp; + + tmp = def_colorName[fgColor]; + def_colorName[fgColor] = def_colorName[bgColor]; + def_colorName[bgColor] = tmp; + } + + if (rs_meta_mod) { + MetaMask = modmasks[rs_meta_mod - 1]; + } + if (rs_alt_mod) { + AltMask = modmasks[rs_alt_mod - 1]; + } + if (rs_numlock_mod) { + NumLockMask = modmasks[rs_numlock_mod - 1]; + } +#ifdef BACKGROUND_CYCLING_SUPPORT + if (rs_anim_pixmap_list != NULL) { + rs_anim_delay = strtoul(rs_anim_pixmap_list, (char **) NULL, 0); + fflush(stdout); + if (rs_anim_delay == 0) { + FREE(rs_anim_pixmap_list); + rs_anim_pixmap_list = NULL; + } else { + char *w1, *h1, *temp; + unsigned long w, h; + int count; + + count = num_words(rs_anim_pixmap_list) - 1; /* -1 for the delay */ + rs_anim_pixmaps = (char **) MALLOC(sizeof(char *) * (count + 1)); + + for (i = 0; i < count; i++) { + temp = get_word(i + 2, rs_anim_pixmap_list); /* +2 rather than +1 to account for the delay */ + if (temp == NULL) + break; + if (num_words(temp) != 3) { + if (num_words(temp) == 1) { + rs_anim_pixmaps[i] = temp; + } + } else { + w1 = get_pword(1, temp); + h1 = get_pword(2, temp); + w = strtol(w1, (char **) NULL, 0); + h = strtol(h1, (char **) NULL, 0); + if (w || h) { + rs_anim_pixmaps[i] = get_word(3, temp); + rs_anim_pixmaps[i] = (char *) REALLOC(rs_anim_pixmaps[i], strlen(rs_anim_pixmaps[i]) + 9); + strcat(rs_anim_pixmaps[i], "@100x100"); + } else { + rs_anim_pixmaps[i] = get_word(3, temp); + rs_anim_pixmaps[i] = (char *) REALLOC(rs_anim_pixmaps[i], strlen(rs_anim_pixmaps[i]) + 5); + strcat(rs_anim_pixmaps[i], "@0x0"); + } + FREE(temp); + } + } + rs_anim_pixmaps[count] = NULL; + FREE(rs_anim_pixmap_list); + } + } else { + rs_anim_delay = 0; + } +#endif + + if (rs_pipe_name) { + struct stat fst; + + if (lstat(rs_pipe_name, &fst) != 0) { + print_error("Unable to stat console pipe \"%s\" -- %s\n", rs_pipe_name, strerror(errno)); + } else { + if (S_ISREG(fst.st_mode) || S_ISDIR(fst.st_mode)) { + print_error("Directories and regular files are not valid console pipes. Sorry.\n"); + } else { + pipe_fd = open(rs_pipe_name, O_RDONLY | O_NDELAY | O_NOCTTY); + if (pipe_fd < 0) { + print_error("Unable to open console pipe -- %s\n", strerror(errno)); + } + } } - } } - } } unsigned char save_config(char *path, unsigned char save_theme) { - register FILE *fp; - register short i; - char *tmp_str, dt_stamp[50]; - time_t cur_time = time(NULL); - struct tm *cur_tm; - struct stat fst; - simage_t *simg; - action_t *action; - buttonbar_t *bbar; + register FILE *fp; + register short i; + char *tmp_str, dt_stamp[50]; + time_t cur_time = time(NULL); + struct tm *cur_tm; + struct stat fst; + simage_t *simg; + action_t *action; + buttonbar_t *bbar; - D_OPTIONS(("Saving %s config to \"%s\"\n", (save_theme ? "theme" : "user"), NONULL(path))); + D_OPTIONS(("Saving %s config to \"%s\"\n", (save_theme ? "theme" : "user"), NONULL(path))); - cur_tm = localtime(&cur_time); + cur_tm = localtime(&cur_time); - if (save_theme) { - if (!path) { - path = (char *) MALLOC(PATH_MAX + 1); - strncpy(path, (theme_dir ? theme_dir : PKGDATADIR "/themes/Eterm"), PATH_MAX - sizeof("/" THEME_CFG)); - path[PATH_MAX] = 0; - if (stat(path, &fst) || !S_ISDIR(fst.st_mode) || !CAN_WRITE(fst)) { - char *tmp = NULL; + if (save_theme) { + if (!path) { + path = (char *) MALLOC(PATH_MAX + 1); + strncpy(path, (theme_dir ? theme_dir : PKGDATADIR "/themes/Eterm"), PATH_MAX - sizeof("/" THEME_CFG)); + path[PATH_MAX] = 0; + if (stat(path, &fst) || !S_ISDIR(fst.st_mode) || !CAN_WRITE(fst)) { + char *tmp = NULL; - D_OPTIONS(("Problem with \"%s\". S_ISDIR == %d, CAN_WRITE == %d\n", path, S_ISDIR(fst.st_mode), CAN_WRITE(fst))); - if (theme_dir) { - tmp = strrchr(theme_dir, '/'); - if (tmp) { - *tmp++ = 0; - } + D_OPTIONS(("Problem with \"%s\". S_ISDIR == %d, CAN_WRITE == %d\n", path, S_ISDIR(fst.st_mode), CAN_WRITE(fst))); + if (theme_dir) { + tmp = strrchr(theme_dir, '/'); + if (tmp) { + *tmp++ = 0; + } + } + snprintf(path, PATH_MAX, "%s/.Eterm/themes/%s", getenv("HOME"), (tmp ? tmp : "Eterm")); + D_OPTIONS(("Trying \"%s\" instead, tmp == \"%s\"\n", path, tmp)); + if (tmp) { + *(--tmp) = '/'; + } + if (!mkdirhier(path) || (stat(path, &fst) && !CAN_WRITE(fst))) { + print_error("I couldn't write to \"%s\" or \"%s\". I give up.", (theme_dir ? theme_dir : PKGDATADIR "/themes/Eterm\n"), + path); + return errno; + } + } + strcat(path, "/" THEME_CFG); + D_OPTIONS(("Final path is \"%s\"\n", path)); + path[PATH_MAX] = 0; } - snprintf(path, PATH_MAX, "%s/.Eterm/themes/%s", getenv("HOME"), (tmp ? tmp : "Eterm")); - D_OPTIONS(("Trying \"%s\" instead, tmp == \"%s\"\n", path, tmp)); - if (tmp) { - *(--tmp) = '/'; - } - if (!mkdirhier(path) || (stat(path, &fst) && !CAN_WRITE(fst))) { - print_error("I couldn't write to \"%s\" or \"%s\". I give up.", (theme_dir ? theme_dir : PKGDATADIR "/themes/Eterm\n"), path); - return errno; - } - } - strcat(path, "/" THEME_CFG); - D_OPTIONS(("Final path is \"%s\"\n", path)); - path[PATH_MAX] = 0; - } - } else { - if (!path) { - path = (char *) MALLOC(PATH_MAX + 1); - strncpy(path, (user_dir ? user_dir : PKGDATADIR "/themes/Eterm"), PATH_MAX - sizeof("/" USER_CFG)); - path[PATH_MAX] = 0; - if (stat(path, &fst) || !S_ISDIR(fst.st_mode) || !CAN_WRITE(fst)) { - char *tmp = NULL; - - D_OPTIONS(("Problem with \"%s\". S_ISDIR == %d, CAN_WRITE == %d\n", path, S_ISDIR(fst.st_mode), CAN_WRITE(fst))); - if (user_dir) { - tmp = strrchr(user_dir, '/'); - if (tmp) { - *tmp++ = 0; - } - } - snprintf(path, PATH_MAX, "%s/.Eterm/themes/%s", getenv("HOME"), (tmp ? tmp : "Eterm")); - D_OPTIONS(("Trying \"%s\" instead, tmp == \"%s\"\n", path, tmp)); - if (tmp) { - *(--tmp) = '/'; - } - if (!mkdirhier(path) || (stat(path, &fst) && !CAN_WRITE(fst))) { - print_error("I couldn't write to \"%s\" or \"%s\". I give up.", (user_dir ? user_dir : PKGDATADIR "/themes/Eterm\n"), path); - return errno; - } - } - strcat(path, "/" USER_CFG); - D_OPTIONS(("Final path is \"%s\"\n", path)); - path[PATH_MAX] = 0; - } - } - if (!lstat(path, &fst)) { - char bak_path[PATH_MAX], timestamp[16]; - - /* File exists. Make a backup. */ - strftime(timestamp, 16, "%Y%m%d.%H%M%S", cur_tm); - snprintf(bak_path, PATH_MAX - 1, "%s.%s", path, timestamp); - link(path, bak_path); - unlink(path); - } - if ((fp = fopen(path, "w")) == NULL) { - print_error("Unable to save configuration to file \"%s\" -- %s\n", path, strerror(errno)); - return errno; - } - strftime(dt_stamp, 50, "%Y/%m/%d at %X", cur_tm); - fprintf(fp, "<" APL_NAME "-" VERSION ">\n"); - fprintf(fp, "# Eterm Configuration File\n"); - fprintf(fp, "# Automatically generated by " APL_NAME "-" VERSION " on %s\n", dt_stamp); - - fprintf(fp, "begin color\n"); - fprintf(fp, " foreground %s\n", COLOR_NAME(fgColor)); - fprintf(fp, " background %s\n", COLOR_NAME(bgColor)); - fprintf(fp, " cursor %s\n", COLOR_NAME(cursorColor)); - fprintf(fp, " cursor_text %s\n", COLOR_NAME(cursorColor2)); - fprintf(fp, " pointer %s\n", COLOR_NAME(pointerColor)); - fprintf(fp, " video normal\n"); - for (i = 0; i < 16; i++) { - fprintf(fp, " color %d %s\n", i, COLOR_NAME(minColor + i)); - } -#ifndef NO_BOLDUNDERLINE - if (rs_color[colorBD]) { - fprintf(fp, " color bd %s\n", COLOR_NAME(colorBD)); - } - if (rs_color[colorUL]) { - fprintf(fp, " color ul %s\n", COLOR_NAME(colorUL)); - } -#endif - fprintf(fp, "end color\n\n"); - - fprintf(fp, "begin attributes\n"); - if (save_theme) { - if (rs_geometry) { - fprintf(fp, " geometry %s\n", rs_geometry); - } - XFetchName(Xdisplay, TermWin.parent, &tmp_str); - fprintf(fp, " title %s\n", tmp_str); - fprintf(fp, " name %s\n", rs_name); - XGetIconName(Xdisplay, TermWin.parent, &tmp_str); - fprintf(fp, " iconname %s\n", tmp_str); - if (rs_desktop != -1) { - fprintf(fp, " desktop %d\n", rs_desktop); - } - } - fprintf(fp, " scrollbar_type %s\n", (scrollbar_get_type() == SCROLLBAR_XTERM ? "xterm" : (scrollbar_get_type() == SCROLLBAR_MOTIF ? "motif" : "next"))); - fprintf(fp, " scrollbar_width %d\n", scrollbar_anchor_width()); - fprintf(fp, " font default %u\n", (unsigned int) font_idx); - fprintf(fp, " font proportional %d\n", ((Options & Opt_proportional) ? 1 : 0)); - for (i = 0; i < font_cnt; i++) { - if (etfonts[i]) { - fprintf(fp, " font %d %s\n", i, etfonts[i]); - } - } -#ifndef NO_BOLDFONT - if (rs_boldFont) { - fprintf(fp, " font bold %s\n", rs_boldFont); - } -#endif - fprintf(fp, "end attributes\n\n"); - - if (save_theme) { - fprintf(fp, "begin imageclasses\n"); - fprintf(fp, " path \"%s\"\n", rs_path); -#ifdef PIXMAP_SUPPORT - if (rs_icon != NULL) { - fprintf(fp, " icon %s\n", rs_icon); - } - if (rs_anim_delay) { - /* FIXME: Do something here! */ - } -#endif - for (i = 0; i < image_max; i++) { - fprintf(fp, " begin image\n"); - switch (i) { - case image_bg: fprintf(fp, " type background\n"); break; - case image_sb: fprintf(fp, " type trough\n"); break; - case image_sa: fprintf(fp, " type anchor\n"); break; - case image_st: fprintf(fp, " type thumb\n"); break; - case image_up: fprintf(fp, " type up_arrow\n"); break; - case image_down: fprintf(fp, " type down_arrow\n"); break; - case image_left: fprintf(fp, " type left_arrow\n"); break; - case image_right: fprintf(fp, " type right_arrow\n"); break; - case image_menu: fprintf(fp, " type menu\n"); break; - case image_menuitem: fprintf(fp, " type menuitem\n"); break; - case image_submenu: fprintf(fp, " type submenu\n"); break; - case image_button: fprintf(fp, " type button\n"); break; - case image_bbar: fprintf(fp, " type button_bar\n"); break; - case image_gbar: fprintf(fp, " type grab_bar\n"); break; - case image_dialog: fprintf(fp, " type dialog_box\n"); break; - } - fprintf(fp, " mode "); - switch (images[i].mode & MODE_MASK) { - case MODE_IMAGE: fprintf(fp, "image"); break; - case MODE_TRANS: fprintf(fp, "trans"); break; - case MODE_VIEWPORT: fprintf(fp, "viewport"); break; - case MODE_AUTO: fprintf(fp, "auto"); break; - default: fprintf(fp, "solid"); break; - } - if (images[i].mode & ALLOW_MASK) { - fprintf(fp, " allow"); - if (image_mode_is(i, ALLOW_IMAGE)) { - fprintf(fp, " image"); - } - if (image_mode_is(i, ALLOW_TRANS)) { - fprintf(fp, " trans"); - } - if (image_mode_is(i, ALLOW_VIEWPORT)) { - fprintf(fp, " viewport"); - } - if (image_mode_is(i, ALLOW_AUTO)) { - fprintf(fp, " auto"); - } - } - fprintf(fp, "\n"); - - /* Now save each state. */ - simg = images[i].norm; -#ifdef PIXMAP_SUPPORT - if (simg->iml->im) { - imlib_context_set_image(simg->iml->im); - } -#endif - fprintf(fp, " state normal\n"); - if (simg->fg || simg->bg) { - fprintf(fp, " color 0x%08x 0x%08x\n", (unsigned int) simg->fg, (unsigned int) simg->bg); - } -#ifdef PIXMAP_SUPPORT - if (simg->iml->im) { - fprintf(fp, " file %s\n", NONULL(imlib_image_get_filename())); - } - fprintf(fp, " geom %hdx%hd+%hd+%hd", simg->pmap->w, simg->pmap->h, simg->pmap->x, simg->pmap->y); - if (simg->pmap->op & OP_TILE) { - fprintf(fp, ":tiled"); - } - if ((simg->pmap->op & OP_SCALE) || ((simg->pmap->op & OP_HSCALE) && (simg->pmap->op & OP_VSCALE))) { - fprintf(fp, ":scaled"); - } else if (simg->pmap->op & OP_HSCALE) { - fprintf(fp, ":hscaled"); - } else if (simg->pmap->op & OP_VSCALE) { - fprintf(fp, ":vscaled"); - } - if (simg->pmap->op & OP_PROPSCALE) { - fprintf(fp, ":propscaled"); - } - fprintf(fp, "\n"); - if (simg->iml->mod) { - fprintf(fp, " colormod image 0x%02x 0x%02x 0x%02x\n", simg->iml->mod->brightness, simg->iml->mod->contrast, simg->iml->mod->gamma); - } - if (simg->iml->rmod) { - fprintf(fp, " colormod red 0x%02x 0x%02x 0x%02x\n", simg->iml->rmod->brightness, simg->iml->rmod->contrast, simg->iml->rmod->gamma); - } - if (simg->iml->gmod) { - fprintf(fp, " colormod green 0x%02x 0x%02x 0x%02x\n", simg->iml->gmod->brightness, simg->iml->gmod->contrast, simg->iml->gmod->gamma); - } - if (simg->iml->bmod) { - fprintf(fp, " colormod blue 0x%02x 0x%02x 0x%02x\n", simg->iml->bmod->brightness, simg->iml->bmod->contrast, simg->iml->bmod->gamma); - } -#endif - if (simg->iml->border) { - fprintf(fp, " border %hu %hu %hu %hu\n", simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, simg->iml->border->bottom); - } - if (simg->iml->bevel) { - fprintf(fp, " bevel %s %hu %hu %hu %hu\n", ((simg->iml->bevel->up) ? "up" : "down"), simg->iml->bevel->edges->left, simg->iml->bevel->edges->right, simg->iml->bevel->edges->top, simg->iml->bevel->edges->bottom); - } - if (simg->iml->pad) { - fprintf(fp, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, simg->iml->pad->bottom); - } - - /* Selected state */ - if (images[i].selected != images[i].norm) { - simg = images[i].selected; -#ifdef PIXMAP_SUPPORT - if (simg->iml->im) { - imlib_context_set_image(simg->iml->im); - } -#endif - fprintf(fp, " state selected\n"); - if (simg->fg || simg->bg) { - fprintf(fp, " color 0x%08x 0x%08x\n", (unsigned int) simg->fg, (unsigned int) simg->bg); - } -#ifdef PIXMAP_SUPPORT - if (simg->iml->im) { - fprintf(fp, " file %s\n", NONULL(imlib_image_get_filename())); - } - fprintf(fp, " geom %hdx%hd+%hd+%hd", simg->pmap->w, simg->pmap->h, simg->pmap->x, simg->pmap->y); - if (simg->pmap->op & OP_TILE) { - fprintf(fp, ":tiled"); - } - if ((simg->pmap->op & OP_SCALE) || ((simg->pmap->op & OP_HSCALE) && (simg->pmap->op & OP_VSCALE))) { - fprintf(fp, ":scaled"); - } else if (simg->pmap->op & OP_HSCALE) { - fprintf(fp, ":hscaled"); - } else if (simg->pmap->op & OP_VSCALE) { - fprintf(fp, ":vscaled"); - } - if (simg->pmap->op & OP_PROPSCALE) { - fprintf(fp, ":propscaled"); - } - fprintf(fp, "\n"); - if (simg->iml->mod) { - fprintf(fp, " colormod image 0x%02x 0x%02x 0x%02x\n", simg->iml->mod->brightness, simg->iml->mod->contrast, simg->iml->mod->gamma); - } - if (simg->iml->rmod) { - fprintf(fp, " colormod red 0x%02x 0x%02x 0x%02x\n", simg->iml->rmod->brightness, simg->iml->rmod->contrast, simg->iml->rmod->gamma); - } - if (simg->iml->gmod) { - fprintf(fp, " colormod green 0x%02x 0x%02x 0x%02x\n", simg->iml->gmod->brightness, simg->iml->gmod->contrast, simg->iml->gmod->gamma); - } - if (simg->iml->bmod) { - fprintf(fp, " colormod blue 0x%02x 0x%02x 0x%02x\n", simg->iml->bmod->brightness, simg->iml->bmod->contrast, simg->iml->bmod->gamma); - } -#endif - if (simg->iml->border) { - fprintf(fp, " border %hu %hu %hu %hu\n", simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, simg->iml->border->bottom); - } - if (simg->iml->bevel) { - fprintf(fp, " bevel %s %hu %hu %hu %hu\n", ((simg->iml->bevel->up) ? "up" : "down"), simg->iml->bevel->edges->left, simg->iml->bevel->edges->right, simg->iml->bevel->edges->top, simg->iml->bevel->edges->bottom); - } - if (simg->iml->pad) { - fprintf(fp, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, simg->iml->pad->bottom); - } - } - - /* Clicked state */ - if (images[i].clicked != images[i].norm) { - simg = images[i].clicked; -#ifdef PIXMAP_SUPPORT - if (simg->iml->im) { - imlib_context_set_image(simg->iml->im); - } -#endif - fprintf(fp, " state clicked\n"); - if (simg->fg || simg->bg) { - fprintf(fp, " color 0x%08x 0x%08x\n", (unsigned int) simg->fg, (unsigned int) simg->bg); - } -#ifdef PIXMAP_SUPPORT - if (simg->iml->im) { - fprintf(fp, " file %s\n", NONULL(imlib_image_get_filename())); - } - fprintf(fp, " geom %hdx%hd+%hd+%hd", simg->pmap->w, simg->pmap->h, simg->pmap->x, simg->pmap->y); - if (simg->pmap->op & OP_TILE) { - fprintf(fp, ":tiled"); - } - if ((simg->pmap->op & OP_SCALE) || ((simg->pmap->op & OP_HSCALE) && (simg->pmap->op & OP_VSCALE))) { - fprintf(fp, ":scaled"); - } else if (simg->pmap->op & OP_HSCALE) { - fprintf(fp, ":hscaled"); - } else if (simg->pmap->op & OP_VSCALE) { - fprintf(fp, ":vscaled"); - } - if (simg->pmap->op & OP_PROPSCALE) { - fprintf(fp, ":propscaled"); - } - fprintf(fp, "\n"); - if (simg->iml->mod) { - fprintf(fp, " colormod image 0x%02x 0x%02x 0x%02x\n", simg->iml->mod->brightness, simg->iml->mod->contrast, simg->iml->mod->gamma); - } - if (simg->iml->rmod) { - fprintf(fp, " colormod red 0x%02x 0x%02x 0x%02x\n", simg->iml->rmod->brightness, simg->iml->rmod->contrast, simg->iml->rmod->gamma); - } - if (simg->iml->gmod) { - fprintf(fp, " colormod green 0x%02x 0x%02x 0x%02x\n", simg->iml->gmod->brightness, simg->iml->gmod->contrast, simg->iml->gmod->gamma); - } - if (simg->iml->bmod) { - fprintf(fp, " colormod blue 0x%02x 0x%02x 0x%02x\n", simg->iml->bmod->brightness, simg->iml->bmod->contrast, simg->iml->bmod->gamma); - } -#endif - if (simg->iml->border) { - fprintf(fp, " border %hu %hu %hu %hu\n", simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, simg->iml->border->bottom); - } - if (simg->iml->bevel) { - fprintf(fp, " bevel %s %hu %hu %hu %hu\n", ((simg->iml->bevel->up) ? "up" : "down"), simg->iml->bevel->edges->left, simg->iml->bevel->edges->right, simg->iml->bevel->edges->top, simg->iml->bevel->edges->bottom); - } - if (simg->iml->pad) { - fprintf(fp, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, simg->iml->pad->bottom); - } - } - - /* Disabled state */ - if (images[i].disabled != images[i].norm) { - simg = images[i].disabled; -#ifdef PIXMAP_SUPPORT - if (simg->iml->im) { - imlib_context_set_image(simg->iml->im); - } -#endif - fprintf(fp, " state disabled\n"); - if (simg->fg || simg->bg) { - fprintf(fp, " color 0x%08x 0x%08x\n", (unsigned int) simg->fg, (unsigned int) simg->bg); - } -#ifdef PIXMAP_SUPPORT - if (simg->iml->im) { - fprintf(fp, " file %s\n", NONULL(imlib_image_get_filename())); - } - fprintf(fp, " geom %hdx%hd+%hd+%hd", simg->pmap->w, simg->pmap->h, simg->pmap->x, simg->pmap->y); - if (simg->pmap->op & OP_TILE) { - fprintf(fp, ":tiled"); - } - if ((simg->pmap->op & OP_SCALE) || ((simg->pmap->op & OP_HSCALE) && (simg->pmap->op & OP_VSCALE))) { - fprintf(fp, ":scaled"); - } else if (simg->pmap->op & OP_HSCALE) { - fprintf(fp, ":hscaled"); - } else if (simg->pmap->op & OP_VSCALE) { - fprintf(fp, ":vscaled"); - } - if (simg->pmap->op & OP_PROPSCALE) { - fprintf(fp, ":propscaled"); - } - fprintf(fp, "\n"); - if (simg->iml->mod) { - fprintf(fp, " colormod image 0x%02x 0x%02x 0x%02x\n", simg->iml->mod->brightness, simg->iml->mod->contrast, simg->iml->mod->gamma); - } - if (simg->iml->rmod) { - fprintf(fp, " colormod red 0x%02x 0x%02x 0x%02x\n", simg->iml->rmod->brightness, simg->iml->rmod->contrast, simg->iml->rmod->gamma); - } - if (simg->iml->gmod) { - fprintf(fp, " colormod green 0x%02x 0x%02x 0x%02x\n", simg->iml->gmod->brightness, simg->iml->gmod->contrast, simg->iml->gmod->gamma); - } - if (simg->iml->bmod) { - fprintf(fp, " colormod blue 0x%02x 0x%02x 0x%02x\n", simg->iml->bmod->brightness, simg->iml->bmod->contrast, simg->iml->bmod->gamma); - } -#endif - if (simg->iml->border) { - fprintf(fp, " border %hu %hu %hu %hu\n", simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, simg->iml->border->bottom); - } - if (simg->iml->bevel) { - fprintf(fp, " bevel %s %hu %hu %hu %hu\n", ((simg->iml->bevel->up) ? "up" : "down"), simg->iml->bevel->edges->left, simg->iml->bevel->edges->right, - simg->iml->bevel->edges->top, simg->iml->bevel->edges->bottom); - } - if (simg->iml->pad) { - fprintf(fp, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, simg->iml->pad->bottom); - } - } - fprintf(fp, " end image\n"); - } - fprintf(fp, "end imageclasses\n\n"); - - for (i = 0; i < menu_list->nummenus; i++) { - menu_t *menu = menu_list->menus[i]; - unsigned short j; - - fprintf(fp, "begin menu\n"); - fprintf(fp, " title \"%s\"\n", menu->title); - if (menu->font) { - unsigned long tmp; - - if ((XGetFontProperty(menu->font, XA_FONT_NAME, &tmp)) == True) { - fprintf(fp, " font '%s'\n", ((char *) tmp)); - } - } - for (j = 0; j < menu->numitems; j++) { - menuitem_t *item = menu->items[j]; - - if (item->type == MENUITEM_SEP) { - fprintf(fp, " -\n"); - } else { - fprintf(fp, " begin menuitem\n"); - fprintf(fp, " text \"%s\"\n", item->text); - if (item->rtext) { - fprintf(fp, " rtext \"%s\"\n", item->rtext); - } - fprintf(fp, " action "); - if (item->type == MENUITEM_STRING) { - fprintf(fp, "string '%s'\n", safe_print_string(item->action.string, -1)); - } else if (item->type == MENUITEM_ECHO) { - fprintf(fp, "echo '%s'\n", safe_print_string(item->action.string, -1)); - } else if (item->type == MENUITEM_SUBMENU) { - fprintf(fp, "submenu \"%s\"\n", (item->action.submenu)->title); - } else if (item->type == MENUITEM_SCRIPT) { - fprintf(fp, "script '%s'\n", item->action.script); - } - fprintf(fp, " end\n"); - } - } - fprintf(fp, "end menu\n"); - } - fprintf(fp, "\n"); - } - - fprintf(fp, "begin actions\n"); - for (action = action_list; action; action = action->next) { - fprintf(fp, " bind "); - if (action->mod != MOD_NONE) { - if (action->mod & MOD_ANY) { - fprintf(fp, "anymod "); - } - if (action->mod & MOD_CTRL) { - fprintf(fp, "ctrl "); - } - if (action->mod & MOD_SHIFT) { - fprintf(fp, "shift "); - } - if (action->mod & MOD_LOCK) { - fprintf(fp, "lock "); - } - if (action->mod & MOD_META) { - fprintf(fp, "meta "); - } - if (action->mod & MOD_ALT) { - fprintf(fp, "alt "); - } - if (action->mod & MOD_MOD1) { - fprintf(fp, "mod1 "); - } - if (action->mod & MOD_MOD2) { - fprintf(fp, "mod2 "); - } - if (action->mod & MOD_MOD3) { - fprintf(fp, "mod3 "); - } - if (action->mod & MOD_MOD4) { - fprintf(fp, "mod4 "); - } - if (action->mod & MOD_MOD5) { - fprintf(fp, "mod5 "); - } - } - if (action->keysym) { - fprintf(fp, "0x%04x", (unsigned int) action->keysym); } else { - fprintf(fp, "button%d", (int) action->button); + if (!path) { + path = (char *) MALLOC(PATH_MAX + 1); + strncpy(path, (user_dir ? user_dir : PKGDATADIR "/themes/Eterm"), PATH_MAX - sizeof("/" USER_CFG)); + path[PATH_MAX] = 0; + if (stat(path, &fst) || !S_ISDIR(fst.st_mode) || !CAN_WRITE(fst)) { + char *tmp = NULL; + + D_OPTIONS(("Problem with \"%s\". S_ISDIR == %d, CAN_WRITE == %d\n", path, S_ISDIR(fst.st_mode), CAN_WRITE(fst))); + if (user_dir) { + tmp = strrchr(user_dir, '/'); + if (tmp) { + *tmp++ = 0; + } + } + snprintf(path, PATH_MAX, "%s/.Eterm/themes/%s", getenv("HOME"), (tmp ? tmp : "Eterm")); + D_OPTIONS(("Trying \"%s\" instead, tmp == \"%s\"\n", path, tmp)); + if (tmp) { + *(--tmp) = '/'; + } + if (!mkdirhier(path) || (stat(path, &fst) && !CAN_WRITE(fst))) { + print_error("I couldn't write to \"%s\" or \"%s\". I give up.", (user_dir ? user_dir : PKGDATADIR "/themes/Eterm\n"), + path); + return errno; + } + } + strcat(path, "/" USER_CFG); + D_OPTIONS(("Final path is \"%s\"\n", path)); + path[PATH_MAX] = 0; + } } - fprintf(fp, " to "); - if (action->type == ACTION_STRING) { - fprintf(fp, "string '%s'\n", safe_print_string(action->param.string, -1)); - } else if (action->type == ACTION_ECHO) { - fprintf(fp, "echo '%s'\n", safe_print_string(action->param.string, -1)); - } else if (action->type == ACTION_MENU) { - fprintf(fp, "menu \"%s\"\n", (action->param.menu)->title); - } else if (action->type == ACTION_SCRIPT) { - fprintf(fp, "script '%s'\n", action->param.script); + if (!lstat(path, &fst)) { + char bak_path[PATH_MAX], timestamp[16]; + + /* File exists. Make a backup. */ + strftime(timestamp, 16, "%Y%m%d.%H%M%S", cur_tm); + snprintf(bak_path, PATH_MAX - 1, "%s.%s", path, timestamp); + link(path, bak_path); + unlink(path); } - } - fprintf(fp, "end actions\n\n"); + if ((fp = fopen(path, "w")) == NULL) { + print_error("Unable to save configuration to file \"%s\" -- %s\n", path, strerror(errno)); + return errno; + } + strftime(dt_stamp, 50, "%Y/%m/%d at %X", cur_tm); + fprintf(fp, "<" APL_NAME "-" VERSION ">\n"); + fprintf(fp, "# Eterm Configuration File\n"); + fprintf(fp, "# Automatically generated by " APL_NAME "-" VERSION " on %s\n", dt_stamp); + + fprintf(fp, "begin color\n"); + fprintf(fp, " foreground %s\n", COLOR_NAME(fgColor)); + fprintf(fp, " background %s\n", COLOR_NAME(bgColor)); + fprintf(fp, " cursor %s\n", COLOR_NAME(cursorColor)); + fprintf(fp, " cursor_text %s\n", COLOR_NAME(cursorColor2)); + fprintf(fp, " pointer %s\n", COLOR_NAME(pointerColor)); + fprintf(fp, " video normal\n"); + for (i = 0; i < 16; i++) { + fprintf(fp, " color %d %s\n", i, COLOR_NAME(minColor + i)); + } +#ifndef NO_BOLDUNDERLINE + if (rs_color[colorBD]) { + fprintf(fp, " color bd %s\n", COLOR_NAME(colorBD)); + } + if (rs_color[colorUL]) { + fprintf(fp, " color ul %s\n", COLOR_NAME(colorUL)); + } +#endif + fprintf(fp, "end color\n\n"); + + fprintf(fp, "begin attributes\n"); + if (save_theme) { + if (rs_geometry) { + fprintf(fp, " geometry %s\n", rs_geometry); + } + XFetchName(Xdisplay, TermWin.parent, &tmp_str); + fprintf(fp, " title %s\n", tmp_str); + fprintf(fp, " name %s\n", rs_name); + XGetIconName(Xdisplay, TermWin.parent, &tmp_str); + fprintf(fp, " iconname %s\n", tmp_str); + if (rs_desktop != -1) { + fprintf(fp, " desktop %d\n", rs_desktop); + } + } + fprintf(fp, " scrollbar_type %s\n", + (scrollbar_get_type() == SCROLLBAR_XTERM ? "xterm" : (scrollbar_get_type() == SCROLLBAR_MOTIF ? "motif" : "next"))); + fprintf(fp, " scrollbar_width %d\n", scrollbar_anchor_width()); + fprintf(fp, " font default %u\n", (unsigned int) font_idx); + fprintf(fp, " font proportional %d\n", ((Options & Opt_proportional) ? 1 : 0)); + for (i = 0; i < font_cnt; i++) { + if (etfonts[i]) { + fprintf(fp, " font %d %s\n", i, etfonts[i]); + } + } +#ifndef NO_BOLDFONT + if (rs_boldFont) { + fprintf(fp, " font bold %s\n", rs_boldFont); + } +#endif + fprintf(fp, "end attributes\n\n"); + + if (save_theme) { + fprintf(fp, "begin imageclasses\n"); + fprintf(fp, " path \"%s\"\n", rs_path); +#ifdef PIXMAP_SUPPORT + if (rs_icon != NULL) { + fprintf(fp, " icon %s\n", rs_icon); + } + if (rs_anim_delay) { + /* FIXME: Do something here! */ + } +#endif + for (i = 0; i < image_max; i++) { + fprintf(fp, " begin image\n"); + switch (i) { + case image_bg: + fprintf(fp, " type background\n"); + break; + case image_sb: + fprintf(fp, " type trough\n"); + break; + case image_sa: + fprintf(fp, " type anchor\n"); + break; + case image_st: + fprintf(fp, " type thumb\n"); + break; + case image_up: + fprintf(fp, " type up_arrow\n"); + break; + case image_down: + fprintf(fp, " type down_arrow\n"); + break; + case image_left: + fprintf(fp, " type left_arrow\n"); + break; + case image_right: + fprintf(fp, " type right_arrow\n"); + break; + case image_menu: + fprintf(fp, " type menu\n"); + break; + case image_menuitem: + fprintf(fp, " type menuitem\n"); + break; + case image_submenu: + fprintf(fp, " type submenu\n"); + break; + case image_button: + fprintf(fp, " type button\n"); + break; + case image_bbar: + fprintf(fp, " type button_bar\n"); + break; + case image_gbar: + fprintf(fp, " type grab_bar\n"); + break; + case image_dialog: + fprintf(fp, " type dialog_box\n"); + break; + } + fprintf(fp, " mode "); + switch (images[i].mode & MODE_MASK) { + case MODE_IMAGE: + fprintf(fp, "image"); + break; + case MODE_TRANS: + fprintf(fp, "trans"); + break; + case MODE_VIEWPORT: + fprintf(fp, "viewport"); + break; + case MODE_AUTO: + fprintf(fp, "auto"); + break; + default: + fprintf(fp, "solid"); + break; + } + if (images[i].mode & ALLOW_MASK) { + fprintf(fp, " allow"); + if (image_mode_is(i, ALLOW_IMAGE)) { + fprintf(fp, " image"); + } + if (image_mode_is(i, ALLOW_TRANS)) { + fprintf(fp, " trans"); + } + if (image_mode_is(i, ALLOW_VIEWPORT)) { + fprintf(fp, " viewport"); + } + if (image_mode_is(i, ALLOW_AUTO)) { + fprintf(fp, " auto"); + } + } + fprintf(fp, "\n"); + + /* Now save each state. */ + simg = images[i].norm; +#ifdef PIXMAP_SUPPORT + if (simg->iml->im) { + imlib_context_set_image(simg->iml->im); + } +#endif + fprintf(fp, " state normal\n"); + if (simg->fg || simg->bg) { + fprintf(fp, " color 0x%08x 0x%08x\n", (unsigned int) simg->fg, (unsigned int) simg->bg); + } +#ifdef PIXMAP_SUPPORT + if (simg->iml->im) { + fprintf(fp, " file %s\n", NONULL(imlib_image_get_filename())); + } + fprintf(fp, " geom %hdx%hd+%hd+%hd", simg->pmap->w, simg->pmap->h, simg->pmap->x, simg->pmap->y); + if (simg->pmap->op & OP_TILE) { + fprintf(fp, ":tiled"); + } + if ((simg->pmap->op & OP_SCALE) || ((simg->pmap->op & OP_HSCALE) && (simg->pmap->op & OP_VSCALE))) { + fprintf(fp, ":scaled"); + } else if (simg->pmap->op & OP_HSCALE) { + fprintf(fp, ":hscaled"); + } else if (simg->pmap->op & OP_VSCALE) { + fprintf(fp, ":vscaled"); + } + if (simg->pmap->op & OP_PROPSCALE) { + fprintf(fp, ":propscaled"); + } + fprintf(fp, "\n"); + if (simg->iml->mod) { + fprintf(fp, " colormod image 0x%02x 0x%02x 0x%02x\n", simg->iml->mod->brightness, simg->iml->mod->contrast, + simg->iml->mod->gamma); + } + if (simg->iml->rmod) { + fprintf(fp, " colormod red 0x%02x 0x%02x 0x%02x\n", simg->iml->rmod->brightness, simg->iml->rmod->contrast, + simg->iml->rmod->gamma); + } + if (simg->iml->gmod) { + fprintf(fp, " colormod green 0x%02x 0x%02x 0x%02x\n", simg->iml->gmod->brightness, simg->iml->gmod->contrast, + simg->iml->gmod->gamma); + } + if (simg->iml->bmod) { + fprintf(fp, " colormod blue 0x%02x 0x%02x 0x%02x\n", simg->iml->bmod->brightness, simg->iml->bmod->contrast, + simg->iml->bmod->gamma); + } +#endif + if (simg->iml->border) { + fprintf(fp, " border %hu %hu %hu %hu\n", simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, + simg->iml->border->bottom); + } + if (simg->iml->bevel) { + fprintf(fp, " bevel %s %hu %hu %hu %hu\n", ((simg->iml->bevel->up) ? "up" : "down"), simg->iml->bevel->edges->left, + simg->iml->bevel->edges->right, simg->iml->bevel->edges->top, simg->iml->bevel->edges->bottom); + } + if (simg->iml->pad) { + fprintf(fp, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, + simg->iml->pad->bottom); + } + + /* Selected state */ + if (images[i].selected != images[i].norm) { + simg = images[i].selected; +#ifdef PIXMAP_SUPPORT + if (simg->iml->im) { + imlib_context_set_image(simg->iml->im); + } +#endif + fprintf(fp, " state selected\n"); + if (simg->fg || simg->bg) { + fprintf(fp, " color 0x%08x 0x%08x\n", (unsigned int) simg->fg, (unsigned int) simg->bg); + } +#ifdef PIXMAP_SUPPORT + if (simg->iml->im) { + fprintf(fp, " file %s\n", NONULL(imlib_image_get_filename())); + } + fprintf(fp, " geom %hdx%hd+%hd+%hd", simg->pmap->w, simg->pmap->h, simg->pmap->x, simg->pmap->y); + if (simg->pmap->op & OP_TILE) { + fprintf(fp, ":tiled"); + } + if ((simg->pmap->op & OP_SCALE) || ((simg->pmap->op & OP_HSCALE) && (simg->pmap->op & OP_VSCALE))) { + fprintf(fp, ":scaled"); + } else if (simg->pmap->op & OP_HSCALE) { + fprintf(fp, ":hscaled"); + } else if (simg->pmap->op & OP_VSCALE) { + fprintf(fp, ":vscaled"); + } + if (simg->pmap->op & OP_PROPSCALE) { + fprintf(fp, ":propscaled"); + } + fprintf(fp, "\n"); + if (simg->iml->mod) { + fprintf(fp, " colormod image 0x%02x 0x%02x 0x%02x\n", simg->iml->mod->brightness, simg->iml->mod->contrast, + simg->iml->mod->gamma); + } + if (simg->iml->rmod) { + fprintf(fp, " colormod red 0x%02x 0x%02x 0x%02x\n", simg->iml->rmod->brightness, simg->iml->rmod->contrast, + simg->iml->rmod->gamma); + } + if (simg->iml->gmod) { + fprintf(fp, " colormod green 0x%02x 0x%02x 0x%02x\n", simg->iml->gmod->brightness, simg->iml->gmod->contrast, + simg->iml->gmod->gamma); + } + if (simg->iml->bmod) { + fprintf(fp, " colormod blue 0x%02x 0x%02x 0x%02x\n", simg->iml->bmod->brightness, simg->iml->bmod->contrast, + simg->iml->bmod->gamma); + } +#endif + if (simg->iml->border) { + fprintf(fp, " border %hu %hu %hu %hu\n", simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, + simg->iml->border->bottom); + } + if (simg->iml->bevel) { + fprintf(fp, " bevel %s %hu %hu %hu %hu\n", ((simg->iml->bevel->up) ? "up" : "down"), simg->iml->bevel->edges->left, + simg->iml->bevel->edges->right, simg->iml->bevel->edges->top, simg->iml->bevel->edges->bottom); + } + if (simg->iml->pad) { + fprintf(fp, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, + simg->iml->pad->bottom); + } + } + + /* Clicked state */ + if (images[i].clicked != images[i].norm) { + simg = images[i].clicked; +#ifdef PIXMAP_SUPPORT + if (simg->iml->im) { + imlib_context_set_image(simg->iml->im); + } +#endif + fprintf(fp, " state clicked\n"); + if (simg->fg || simg->bg) { + fprintf(fp, " color 0x%08x 0x%08x\n", (unsigned int) simg->fg, (unsigned int) simg->bg); + } +#ifdef PIXMAP_SUPPORT + if (simg->iml->im) { + fprintf(fp, " file %s\n", NONULL(imlib_image_get_filename())); + } + fprintf(fp, " geom %hdx%hd+%hd+%hd", simg->pmap->w, simg->pmap->h, simg->pmap->x, simg->pmap->y); + if (simg->pmap->op & OP_TILE) { + fprintf(fp, ":tiled"); + } + if ((simg->pmap->op & OP_SCALE) || ((simg->pmap->op & OP_HSCALE) && (simg->pmap->op & OP_VSCALE))) { + fprintf(fp, ":scaled"); + } else if (simg->pmap->op & OP_HSCALE) { + fprintf(fp, ":hscaled"); + } else if (simg->pmap->op & OP_VSCALE) { + fprintf(fp, ":vscaled"); + } + if (simg->pmap->op & OP_PROPSCALE) { + fprintf(fp, ":propscaled"); + } + fprintf(fp, "\n"); + if (simg->iml->mod) { + fprintf(fp, " colormod image 0x%02x 0x%02x 0x%02x\n", simg->iml->mod->brightness, simg->iml->mod->contrast, + simg->iml->mod->gamma); + } + if (simg->iml->rmod) { + fprintf(fp, " colormod red 0x%02x 0x%02x 0x%02x\n", simg->iml->rmod->brightness, simg->iml->rmod->contrast, + simg->iml->rmod->gamma); + } + if (simg->iml->gmod) { + fprintf(fp, " colormod green 0x%02x 0x%02x 0x%02x\n", simg->iml->gmod->brightness, simg->iml->gmod->contrast, + simg->iml->gmod->gamma); + } + if (simg->iml->bmod) { + fprintf(fp, " colormod blue 0x%02x 0x%02x 0x%02x\n", simg->iml->bmod->brightness, simg->iml->bmod->contrast, + simg->iml->bmod->gamma); + } +#endif + if (simg->iml->border) { + fprintf(fp, " border %hu %hu %hu %hu\n", simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, + simg->iml->border->bottom); + } + if (simg->iml->bevel) { + fprintf(fp, " bevel %s %hu %hu %hu %hu\n", ((simg->iml->bevel->up) ? "up" : "down"), simg->iml->bevel->edges->left, + simg->iml->bevel->edges->right, simg->iml->bevel->edges->top, simg->iml->bevel->edges->bottom); + } + if (simg->iml->pad) { + fprintf(fp, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, + simg->iml->pad->bottom); + } + } + + /* Disabled state */ + if (images[i].disabled != images[i].norm) { + simg = images[i].disabled; +#ifdef PIXMAP_SUPPORT + if (simg->iml->im) { + imlib_context_set_image(simg->iml->im); + } +#endif + fprintf(fp, " state disabled\n"); + if (simg->fg || simg->bg) { + fprintf(fp, " color 0x%08x 0x%08x\n", (unsigned int) simg->fg, (unsigned int) simg->bg); + } +#ifdef PIXMAP_SUPPORT + if (simg->iml->im) { + fprintf(fp, " file %s\n", NONULL(imlib_image_get_filename())); + } + fprintf(fp, " geom %hdx%hd+%hd+%hd", simg->pmap->w, simg->pmap->h, simg->pmap->x, simg->pmap->y); + if (simg->pmap->op & OP_TILE) { + fprintf(fp, ":tiled"); + } + if ((simg->pmap->op & OP_SCALE) || ((simg->pmap->op & OP_HSCALE) && (simg->pmap->op & OP_VSCALE))) { + fprintf(fp, ":scaled"); + } else if (simg->pmap->op & OP_HSCALE) { + fprintf(fp, ":hscaled"); + } else if (simg->pmap->op & OP_VSCALE) { + fprintf(fp, ":vscaled"); + } + if (simg->pmap->op & OP_PROPSCALE) { + fprintf(fp, ":propscaled"); + } + fprintf(fp, "\n"); + if (simg->iml->mod) { + fprintf(fp, " colormod image 0x%02x 0x%02x 0x%02x\n", simg->iml->mod->brightness, simg->iml->mod->contrast, + simg->iml->mod->gamma); + } + if (simg->iml->rmod) { + fprintf(fp, " colormod red 0x%02x 0x%02x 0x%02x\n", simg->iml->rmod->brightness, simg->iml->rmod->contrast, + simg->iml->rmod->gamma); + } + if (simg->iml->gmod) { + fprintf(fp, " colormod green 0x%02x 0x%02x 0x%02x\n", simg->iml->gmod->brightness, simg->iml->gmod->contrast, + simg->iml->gmod->gamma); + } + if (simg->iml->bmod) { + fprintf(fp, " colormod blue 0x%02x 0x%02x 0x%02x\n", simg->iml->bmod->brightness, simg->iml->bmod->contrast, + simg->iml->bmod->gamma); + } +#endif + if (simg->iml->border) { + fprintf(fp, " border %hu %hu %hu %hu\n", simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, + simg->iml->border->bottom); + } + if (simg->iml->bevel) { + fprintf(fp, " bevel %s %hu %hu %hu %hu\n", ((simg->iml->bevel->up) ? "up" : "down"), simg->iml->bevel->edges->left, + simg->iml->bevel->edges->right, simg->iml->bevel->edges->top, simg->iml->bevel->edges->bottom); + } + if (simg->iml->pad) { + fprintf(fp, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, + simg->iml->pad->bottom); + } + } + fprintf(fp, " end image\n"); + } + fprintf(fp, "end imageclasses\n\n"); + + for (i = 0; i < menu_list->nummenus; i++) { + menu_t *menu = menu_list->menus[i]; + unsigned short j; + + fprintf(fp, "begin menu\n"); + fprintf(fp, " title \"%s\"\n", menu->title); + if (menu->font) { + unsigned long tmp; + + if ((XGetFontProperty(menu->font, XA_FONT_NAME, &tmp)) == True) { + fprintf(fp, " font '%s'\n", ((char *) tmp)); + } + } + for (j = 0; j < menu->numitems; j++) { + menuitem_t *item = menu->items[j]; + + if (item->type == MENUITEM_SEP) { + fprintf(fp, " -\n"); + } else { + fprintf(fp, " begin menuitem\n"); + fprintf(fp, " text \"%s\"\n", item->text); + if (item->rtext) { + fprintf(fp, " rtext \"%s\"\n", item->rtext); + } + fprintf(fp, " action "); + if (item->type == MENUITEM_STRING) { + fprintf(fp, "string '%s'\n", safe_print_string(item->action.string, -1)); + } else if (item->type == MENUITEM_ECHO) { + fprintf(fp, "echo '%s'\n", safe_print_string(item->action.string, -1)); + } else if (item->type == MENUITEM_SUBMENU) { + fprintf(fp, "submenu \"%s\"\n", (item->action.submenu)->title); + } else if (item->type == MENUITEM_SCRIPT) { + fprintf(fp, "script '%s'\n", item->action.script); + } + fprintf(fp, " end\n"); + } + } + fprintf(fp, "end menu\n"); + } + fprintf(fp, "\n"); + } + + fprintf(fp, "begin actions\n"); + for (action = action_list; action; action = action->next) { + fprintf(fp, " bind "); + if (action->mod != MOD_NONE) { + if (action->mod & MOD_ANY) { + fprintf(fp, "anymod "); + } + if (action->mod & MOD_CTRL) { + fprintf(fp, "ctrl "); + } + if (action->mod & MOD_SHIFT) { + fprintf(fp, "shift "); + } + if (action->mod & MOD_LOCK) { + fprintf(fp, "lock "); + } + if (action->mod & MOD_META) { + fprintf(fp, "meta "); + } + if (action->mod & MOD_ALT) { + fprintf(fp, "alt "); + } + if (action->mod & MOD_MOD1) { + fprintf(fp, "mod1 "); + } + if (action->mod & MOD_MOD2) { + fprintf(fp, "mod2 "); + } + if (action->mod & MOD_MOD3) { + fprintf(fp, "mod3 "); + } + if (action->mod & MOD_MOD4) { + fprintf(fp, "mod4 "); + } + if (action->mod & MOD_MOD5) { + fprintf(fp, "mod5 "); + } + } + if (action->keysym) { + fprintf(fp, "0x%04x", (unsigned int) action->keysym); + } else { + fprintf(fp, "button%d", (int) action->button); + } + fprintf(fp, " to "); + if (action->type == ACTION_STRING) { + fprintf(fp, "string '%s'\n", safe_print_string(action->param.string, -1)); + } else if (action->type == ACTION_ECHO) { + fprintf(fp, "echo '%s'\n", safe_print_string(action->param.string, -1)); + } else if (action->type == ACTION_MENU) { + fprintf(fp, "menu \"%s\"\n", (action->param.menu)->title); + } else if (action->type == ACTION_SCRIPT) { + fprintf(fp, "script '%s'\n", action->param.script); + } + } + fprintf(fp, "end actions\n\n"); #ifdef MULTI_CHARSET - fprintf(fp, "begin multichar\n"); - if (rs_multichar_encoding) { - fprintf(fp, " encoding %s\n", rs_multichar_encoding); - } - for (i = 0; i < font_cnt; i++) { - if (etmfonts[i]) { - fprintf(fp, " font %d %s\n", i, etmfonts[i]); + fprintf(fp, "begin multichar\n"); + if (rs_multichar_encoding) { + fprintf(fp, " encoding %s\n", rs_multichar_encoding); } - } - fprintf(fp, "end multichar\n\n"); + for (i = 0; i < font_cnt; i++) { + if (etmfonts[i]) { + fprintf(fp, " font %d %s\n", i, etmfonts[i]); + } + } + fprintf(fp, "end multichar\n\n"); #endif #ifdef USE_XIM - fprintf(fp, "begin xim\n"); - if (rs_input_method) { - fprintf(fp, " input_method %s\n", rs_input_method); - } - if (rs_preedit_type) { - fprintf(fp, " preedit_type %s\n", rs_preedit_type); - } - fprintf(fp, "end xim\n\n"); + fprintf(fp, "begin xim\n"); + if (rs_input_method) { + fprintf(fp, " input_method %s\n", rs_input_method); + } + if (rs_preedit_type) { + fprintf(fp, " preedit_type %s\n", rs_preedit_type); + } + fprintf(fp, "end xim\n\n"); #endif - if (save_theme) { - for (bbar = buttonbar; bbar; bbar = bbar->next) { - button_t *b; + if (save_theme) { + for (bbar = buttonbar; bbar; bbar = bbar->next) { + button_t *b; - fprintf(fp, "begin button_bar\n"); - fprintf(fp, " font '%s'\n", NONULL(get_font_name(bbar->font))); - if (bbar_is_top_docked(bbar)) { - fprintf(fp, " dock top\n"); - } else if (bbar_is_bottom_docked(bbar)) { - fprintf(fp, " dock bottom\n"); - } else { - fprintf(fp, " dock none\n"); - } - fprintf(fp, " visible %s\n", (bbar_is_visible(bbar) ? "yes" : "no")); - for (b = bbar->buttons; b; b = b->next) { - if (b->len) { - fprintf(fp, " button \"%s\" ", safe_print_string(b->text, b->len)); - } else { - fprintf(fp, " button "); + fprintf(fp, "begin button_bar\n"); + fprintf(fp, " font '%s'\n", NONULL(get_font_name(bbar->font))); + if (bbar_is_top_docked(bbar)) { + fprintf(fp, " dock top\n"); + } else if (bbar_is_bottom_docked(bbar)) { + fprintf(fp, " dock bottom\n"); + } else { + fprintf(fp, " dock none\n"); + } + fprintf(fp, " visible %s\n", (bbar_is_visible(bbar) ? "yes" : "no")); + for (b = bbar->buttons; b; b = b->next) { + if (b->len) { + fprintf(fp, " button \"%s\" ", safe_print_string(b->text, b->len)); + } else { + fprintf(fp, " button "); + } + if (b->icon && b->icon->iml) { + imlib_context_set_image(b->icon->iml->im); + fprintf(fp, "icon \"%s\" ", NONULL(imlib_image_get_filename())); + } + fprintf(fp, "action "); + if (b->type == ACTION_STRING) { + fprintf(fp, "string '%s'\n", safe_print_string(b->action.string, -1)); + } else if (b->type == ACTION_ECHO) { + fprintf(fp, "echo '%s'\n", safe_print_string(b->action.string, -1)); + } else if (b->type == ACTION_MENU) { + fprintf(fp, "menu \"%s\"\n", (b->action.menu)->title); + } else if (b->type == ACTION_SCRIPT) { + fprintf(fp, "script '%s'\n", b->action.script); + } + } + for (b = bbar->rbuttons; b; b = b->next) { + if (b->len) { + fprintf(fp, " rbutton \"%s\" ", safe_print_string(b->text, b->len)); + } else { + fprintf(fp, " rbutton "); + } + if (b->icon && b->icon->iml) { + imlib_context_set_image(b->icon->iml->im); + fprintf(fp, "icon \"%s\" ", NONULL(imlib_image_get_filename())); + } + fprintf(fp, "action "); + if (b->type == ACTION_STRING) { + fprintf(fp, "string '%s'\n", safe_print_string(b->action.string, -1)); + } else if (b->type == ACTION_ECHO) { + fprintf(fp, "echo '%s'\n", safe_print_string(b->action.string, -1)); + } else if (b->type == ACTION_MENU) { + fprintf(fp, "menu \"%s\"\n", (b->action.menu)->title); + } else if (b->type == ACTION_SCRIPT) { + fprintf(fp, "script '%s'\n", b->action.script); + } + } } - if (b->icon && b->icon->iml) { - imlib_context_set_image(b->icon->iml->im); - fprintf(fp, "icon \"%s\" ", NONULL(imlib_image_get_filename())); - } - fprintf(fp, "action "); - if (b->type == ACTION_STRING) { - fprintf(fp, "string '%s'\n", safe_print_string(b->action.string, -1)); - } else if (b->type == ACTION_ECHO) { - fprintf(fp, "echo '%s'\n", safe_print_string(b->action.string, -1)); - } else if (b->type == ACTION_MENU) { - fprintf(fp, "menu \"%s\"\n", (b->action.menu)->title); - } else if (b->type == ACTION_SCRIPT) { - fprintf(fp, "script '%s'\n", b->action.script); - } - } - for (b = bbar->rbuttons; b; b = b->next) { - if (b->len) { - fprintf(fp, " rbutton \"%s\" ", safe_print_string(b->text, b->len)); - } else { - fprintf(fp, " rbutton "); - } - if (b->icon && b->icon->iml) { - imlib_context_set_image(b->icon->iml->im); - fprintf(fp, "icon \"%s\" ", NONULL(imlib_image_get_filename())); - } - fprintf(fp, "action "); - if (b->type == ACTION_STRING) { - fprintf(fp, "string '%s'\n", safe_print_string(b->action.string, -1)); - } else if (b->type == ACTION_ECHO) { - fprintf(fp, "echo '%s'\n", safe_print_string(b->action.string, -1)); - } else if (b->type == ACTION_MENU) { - fprintf(fp, "menu \"%s\"\n", (b->action.menu)->title); - } else if (b->type == ACTION_SCRIPT) { - fprintf(fp, "script '%s'\n", b->action.script); - } - } + fprintf(fp, "end button_bar\n\n"); } - fprintf(fp, "end button_bar\n\n"); - } - fprintf(fp, "begin toggles\n"); - fprintf(fp, " map_alert %d\n", (Options & Opt_map_alert ? 1 : 0)); - fprintf(fp, " visual_bell %d\n", (Options & Opt_visual_bell ? 1 : 0)); - fprintf(fp, " login_shell %d\n", (Options & Opt_login_shell ? 1 : 0)); - fprintf(fp, " scrollbar %d\n", (Options & Opt_scrollbar ? 1 : 0)); - fprintf(fp, " utmp_logging %d\n", (Options & Opt_write_utmp ? 1 : 0)); - fprintf(fp, " meta8 %d\n", (Options & Opt_meta8 ? 1 : 0)); - fprintf(fp, " iconic %d\n", (Options & Opt_iconic ? 1 : 0)); - fprintf(fp, " home_on_output %d\n", (Options & Opt_home_on_output ? 1 : 0)); - fprintf(fp, " home_on_input %d\n", (Options & Opt_home_on_input ? 1 : 0)); - fprintf(fp, " no_input %d\n", (Options & Opt_no_input ? 1 : 0)); - fprintf(fp, " scrollbar_floating %d\n", (Options & Opt_scrollbar_floating ? 1 : 0)); - fprintf(fp, " scrollbar_right %d\n", (Options & Opt_scrollbar_right ? 1 : 0)); - fprintf(fp, " scrollbar_popup %d\n", (Options & Opt_scrollbar_popup ? 1 : 0)); - fprintf(fp, " borderless %d\n", (Options & Opt_borderless ? 1 : 0)); - fprintf(fp, " double_buffer %d\n", (Options & Opt_double_buffer ? 1 : 0)); - fprintf(fp, " no_cursor %d\n", (Options & Opt_no_cursor ? 1 : 0)); - fprintf(fp, " pause %d\n", (Options & Opt_pause ? 1 : 0)); - fprintf(fp, " xterm_select %d\n", (Options & Opt_xterm_select ? 1 : 0)); - fprintf(fp, " select_line %d\n", (Options & Opt_select_whole_line ? 1 : 0)); - fprintf(fp, " select_trailing_spaces %d\n", (Options & Opt_select_trailing_spaces ? 1 : 0)); - fprintf(fp, " report_as_keysyms %d\n", (Options & Opt_report_as_keysyms ? 1 : 0)); - fprintf(fp, " itrans %d\n", (image_toggles & IMOPT_ITRANS ? 1 : 0)); - fprintf(fp, " buttonbar %d\n", ((buttonbar && bbar_is_visible(buttonbar)) ? 1 : 0)); - fprintf(fp, " resize_gravity %d\n", (Options & Opt_resize_gravity ? 1 : 0)); - fprintf(fp, "end toggles\n\n"); + fprintf(fp, "begin toggles\n"); + fprintf(fp, " map_alert %d\n", (Options & Opt_map_alert ? 1 : 0)); + fprintf(fp, " visual_bell %d\n", (Options & Opt_visual_bell ? 1 : 0)); + fprintf(fp, " login_shell %d\n", (Options & Opt_login_shell ? 1 : 0)); + fprintf(fp, " scrollbar %d\n", (Options & Opt_scrollbar ? 1 : 0)); + fprintf(fp, " utmp_logging %d\n", (Options & Opt_write_utmp ? 1 : 0)); + fprintf(fp, " meta8 %d\n", (Options & Opt_meta8 ? 1 : 0)); + fprintf(fp, " iconic %d\n", (Options & Opt_iconic ? 1 : 0)); + fprintf(fp, " home_on_output %d\n", (Options & Opt_home_on_output ? 1 : 0)); + fprintf(fp, " home_on_input %d\n", (Options & Opt_home_on_input ? 1 : 0)); + fprintf(fp, " no_input %d\n", (Options & Opt_no_input ? 1 : 0)); + fprintf(fp, " scrollbar_floating %d\n", (Options & Opt_scrollbar_floating ? 1 : 0)); + fprintf(fp, " scrollbar_right %d\n", (Options & Opt_scrollbar_right ? 1 : 0)); + fprintf(fp, " scrollbar_popup %d\n", (Options & Opt_scrollbar_popup ? 1 : 0)); + fprintf(fp, " borderless %d\n", (Options & Opt_borderless ? 1 : 0)); + fprintf(fp, " double_buffer %d\n", (Options & Opt_double_buffer ? 1 : 0)); + fprintf(fp, " no_cursor %d\n", (Options & Opt_no_cursor ? 1 : 0)); + fprintf(fp, " pause %d\n", (Options & Opt_pause ? 1 : 0)); + fprintf(fp, " xterm_select %d\n", (Options & Opt_xterm_select ? 1 : 0)); + fprintf(fp, " select_line %d\n", (Options & Opt_select_whole_line ? 1 : 0)); + fprintf(fp, " select_trailing_spaces %d\n", (Options & Opt_select_trailing_spaces ? 1 : 0)); + fprintf(fp, " report_as_keysyms %d\n", (Options & Opt_report_as_keysyms ? 1 : 0)); + fprintf(fp, " itrans %d\n", (image_toggles & IMOPT_ITRANS ? 1 : 0)); + fprintf(fp, " buttonbar %d\n", ((buttonbar && bbar_is_visible(buttonbar)) ? 1 : 0)); + fprintf(fp, " resize_gravity %d\n", (Options & Opt_resize_gravity ? 1 : 0)); + fprintf(fp, "end toggles\n\n"); - fprintf(fp, "begin keyboard\n"); - tmp_str = XKeysymToString(ks_smallfont); - if (tmp_str) { - fprintf(fp, " smallfont_key %s\n", tmp_str); - } - tmp_str = XKeysymToString(ks_bigfont); - if (tmp_str) { - fprintf(fp, " bigfont_key %s\n", tmp_str); - } - if (rs_meta_mod) { - fprintf(fp, " meta_mod %d\n", rs_meta_mod); - } - if (rs_alt_mod) { - fprintf(fp, " alt_mod %d\n", rs_alt_mod); - } - if (rs_numlock_mod) { - fprintf(fp, " numlock_mod %d\n", rs_numlock_mod); - } - for (i = 0; i < 256; i++) { - if (KeySym_map[i]) { - fprintf(fp, " keysym 0xff%02x \'%s\'\n", i, safe_print_string((char *) (KeySym_map[i] + 1), (unsigned long) KeySym_map[i][0])); + fprintf(fp, "begin keyboard\n"); + tmp_str = XKeysymToString(ks_smallfont); + if (tmp_str) { + fprintf(fp, " smallfont_key %s\n", tmp_str); + } + tmp_str = XKeysymToString(ks_bigfont); + if (tmp_str) { + fprintf(fp, " bigfont_key %s\n", tmp_str); + } + if (rs_meta_mod) { + fprintf(fp, " meta_mod %d\n", rs_meta_mod); + } + if (rs_alt_mod) { + fprintf(fp, " alt_mod %d\n", rs_alt_mod); + } + if (rs_numlock_mod) { + fprintf(fp, " numlock_mod %d\n", rs_numlock_mod); + } + for (i = 0; i < 256; i++) { + if (KeySym_map[i]) { + fprintf(fp, " keysym 0xff%02x \'%s\'\n", i, + safe_print_string((char *) (KeySym_map[i] + 1), (unsigned long) KeySym_map[i][0])); + } } - } #ifdef GREEK_SUPPORT - if (rs_greek_keyboard) { - fprintf(fp, " greek on %s\n", rs_greek_keyboard); - } -#endif - fprintf(fp, " app_keypad %d\n", (PrivateModes & PrivMode_aplKP ? 1 : 0)); - fprintf(fp, " app_cursor %d\n", (PrivateModes & PrivMode_aplCUR ? 1 : 0)); - fprintf(fp, "end keyboard\n\n"); - - fprintf(fp, "begin misc\n"); -#ifdef PRINTPIPE - if (rs_print_pipe) { - fprintf(fp, " print_pipe '%s'\n", rs_print_pipe); - } -#endif - fprintf(fp, " save_lines %d\n", rs_saveLines); - fprintf(fp, " min_anchor_size %d\n", rs_min_anchor_size); - fprintf(fp, " border_width %d\n", TermWin.internalBorder); - fprintf(fp, " term_name %s\n", getenv("TERM")); - fprintf(fp, " debug %d\n", DEBUG_LEVEL); - if (save_theme && rs_exec_args) { - fprintf(fp, " exec "); - for (i = 0; rs_exec_args[i]; i++) { - fprintf(fp, "'%s' ", rs_exec_args[i]); + if (rs_greek_keyboard) { + fprintf(fp, " greek on %s\n", rs_greek_keyboard); } - fprintf(fp, "\n"); - } -#ifdef CUTCHAR_OPTIONS - if (rs_cutchars) { - fprintf(fp, " cut_chars '%s'\n", rs_cutchars); - } #endif - fprintf(fp, "end misc\n\n"); + fprintf(fp, " app_keypad %d\n", (PrivateModes & PrivMode_aplKP ? 1 : 0)); + fprintf(fp, " app_cursor %d\n", (PrivateModes & PrivMode_aplCUR ? 1 : 0)); + fprintf(fp, "end keyboard\n\n"); - fclose(fp); - return 0; + fprintf(fp, "begin misc\n"); +#ifdef PRINTPIPE + if (rs_print_pipe) { + fprintf(fp, " print_pipe '%s'\n", rs_print_pipe); + } +#endif + fprintf(fp, " save_lines %d\n", rs_saveLines); + fprintf(fp, " min_anchor_size %d\n", rs_min_anchor_size); + fprintf(fp, " border_width %d\n", TermWin.internalBorder); + fprintf(fp, " term_name %s\n", getenv("TERM")); + fprintf(fp, " debug %d\n", DEBUG_LEVEL); + if (save_theme && rs_exec_args) { + fprintf(fp, " exec "); + for (i = 0; rs_exec_args[i]; i++) { + fprintf(fp, "'%s' ", rs_exec_args[i]); + } + fprintf(fp, "\n"); + } +#ifdef CUTCHAR_OPTIONS + if (rs_cutchars) { + fprintf(fp, " cut_chars '%s'\n", rs_cutchars); + } +#endif + fprintf(fp, "end misc\n\n"); + + fclose(fp); + return 0; } diff --git a/src/options.h b/src/options.h index 3bdcecc..9366995 100644 --- a/src/options.h +++ b/src/options.h @@ -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 diff --git a/src/pixmap.c b/src/pixmap.c index 0667084..1be71ef 100644 --- a/src/pixmap.c +++ b/src/pixmap.c @@ -68,22 +68,21 @@ Window desktop_window = None; unsigned char desktop_pixmap_is_mine = 0; #endif -image_t images[image_max] = -{ - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, - {None, 0, 0, NULL, NULL, NULL, NULL, NULL} +image_t images[image_max] = { + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL}, + {None, 0, 0, NULL, NULL, NULL, NULL, NULL} }; #ifdef PIXMAP_SUPPORT @@ -94,1349 +93,1460 @@ static void copy_buffer_pixmap(unsigned char mode, unsigned long fill, unsigned const char * get_image_type(unsigned char type) { - switch (type) { - case image_bg: return "image_bg"; break; - case image_up: return "image_up"; break; - case image_down: return "image_down"; break; - case image_left: return "image_left"; break; - case image_right: return "image_right"; break; - case image_sb: return "image_sb"; break; - case image_sa: return "image_sa"; break; - case image_st: return "image_st"; break; - case image_menu: return "image_menu"; break; - case image_menuitem: return "image_menuitem"; break; - case image_submenu: return "image_submenu"; break; - case image_button: return "image_button"; break; - case image_bbar: return "image_bbar"; break; - case image_gbar: return "image_gbar"; break; - case image_dialog: return "image_dialog"; break; - case image_max: - default: return "image_max"; break; - } - ASSERT_NOTREACHED_RVAL(""); + switch (type) { + case image_bg: + return "image_bg"; + break; + case image_up: + return "image_up"; + break; + case image_down: + return "image_down"; + break; + case image_left: + return "image_left"; + break; + case image_right: + return "image_right"; + break; + case image_sb: + return "image_sb"; + break; + case image_sa: + return "image_sa"; + break; + case image_st: + return "image_st"; + break; + case image_menu: + return "image_menu"; + break; + case image_menuitem: + return "image_menuitem"; + break; + case image_submenu: + return "image_submenu"; + break; + case image_button: + return "image_button"; + break; + case image_bbar: + return "image_bbar"; + break; + case image_gbar: + return "image_gbar"; + break; + case image_dialog: + return "image_dialog"; + break; + case image_max: + default: + return "image_max"; + break; + } + ASSERT_NOTREACHED_RVAL(""); } unsigned char image_mode_any(unsigned char mode) { - unsigned char ismode = 0; + unsigned char ismode = 0; - FOREACH_IMAGE(if (image_mode_is(idx, mode)) ismode=1;); - return ismode; + FOREACH_IMAGE(if (image_mode_is(idx, mode)) ismode = 1;); + return ismode; } #ifdef PIXMAP_SUPPORT const char * imlib_strerror(Imlib_Load_Error err) { - switch (err) { - case IMLIB_LOAD_ERROR_NONE: return "Success"; break; - case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: return "No such file or directory"; break; - case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: return "Is a directory"; break; - case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: return "Permission denied"; break; - case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: return "No loader available for that file format"; break; - case IMLIB_LOAD_ERROR_PATH_TOO_LONG: return "Path too long"; break; - case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: return "Path component does not exist"; break; - case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: return "Path component is not a directory"; break; - case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: return "Path points outside address space"; break; - case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: return "Too many symbolic links in path"; break; - case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: return "Out of memory"; break; - case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS: return "No more file descriptors"; break; - case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: return "Permission denied"; break; - case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: return "Disk full"; break; - case IMLIB_LOAD_ERROR_UNKNOWN: - default: return "Unknown error"; break; - } - ASSERT_NOTREACHED_RVAL(""); + switch (err) { + case IMLIB_LOAD_ERROR_NONE: + return "Success"; + break; + case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: + return "No such file or directory"; + break; + case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: + return "Is a directory"; + break; + case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: + return "Permission denied"; + break; + case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: + return "No loader available for that file format"; + break; + case IMLIB_LOAD_ERROR_PATH_TOO_LONG: + return "Path too long"; + break; + case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: + return "Path component does not exist"; + break; + case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: + return "Path component is not a directory"; + break; + case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: + return "Path points outside address space"; + break; + case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: + return "Too many symbolic links in path"; + break; + case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: + return "Out of memory"; + break; + case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS: + return "No more file descriptors"; + break; + case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: + return "Permission denied"; + break; + case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: + return "Disk full"; + break; + case IMLIB_LOAD_ERROR_UNKNOWN: + default: + return "Unknown error"; + break; + } + ASSERT_NOTREACHED_RVAL(""); } unsigned short parse_pixmap_ops(char *str) { - unsigned short op = OP_NONE; - char *token; + unsigned short op = OP_NONE; + char *token; - REQUIRE_RVAL(str && *str, OP_NONE); - D_PIXMAP(("parse_pixmap_ops(str [%s]) called.\n", str)); + REQUIRE_RVAL(str && *str, OP_NONE); + D_PIXMAP(("parse_pixmap_ops(str [%s]) called.\n", str)); - for (; (token = (char *) strsep(&str, ":"));) { - if (!BEG_STRCASECMP("tiled", token)) { - op |= OP_TILE; - } else if (!BEG_STRCASECMP("hscaled", token)) { - op |= OP_HSCALE; - } else if (!BEG_STRCASECMP("vscaled", token)) { - op |= OP_VSCALE; - } else if (!BEG_STRCASECMP("scaled", token)) { - op |= OP_SCALE; - } else if (!BEG_STRCASECMP("propscaled", token)) { - op |= OP_PROPSCALE; + for (; (token = (char *) strsep(&str, ":"));) { + if (!BEG_STRCASECMP("tiled", token)) { + op |= OP_TILE; + } else if (!BEG_STRCASECMP("hscaled", token)) { + op |= OP_HSCALE; + } else if (!BEG_STRCASECMP("vscaled", token)) { + op |= OP_VSCALE; + } else if (!BEG_STRCASECMP("scaled", token)) { + op |= OP_SCALE; + } else if (!BEG_STRCASECMP("propscaled", token)) { + op |= OP_PROPSCALE; + } } - } - return (op); + return (op); } unsigned short set_pixmap_scale(const char *geom, pixmap_t *pmap) { - static char str[GEOM_LEN + 1] = - {'\0'}; - unsigned int w = 0, h = 0; - int x = 0, y = 0; - unsigned short op; - int flags; - unsigned short changed = 0; - char *p, *opstr; - int n; + static char str[GEOM_LEN + 1] = { '\0' }; + unsigned int w = 0, h = 0; + int x = 0, y = 0; + unsigned short op; + int flags; + unsigned short changed = 0; + char *p, *opstr; + int n; - if (geom == NULL) - return 0; + if (geom == NULL) + return 0; - D_PIXMAP(("scale_pixmap(\"%s\")\n", geom)); - if (!strcmp(geom, "?")) { - sprintf(str, "[%dx%d+%d+%d]", pmap->w, pmap->h, pmap->x, pmap->y); - xterm_seq(XTerm_title, str); - return 0; - } - if ((opstr = strchr(geom, ':')) != NULL) { - *opstr++ = '\0'; - op = parse_pixmap_ops(opstr); - } else { - op = pmap->op; - } - if ((p = strchr(geom, ';')) == NULL) - p = strchr(geom, '\0'); - n = (p - geom); - if (n > GEOM_LEN - 1) - return 0; - - strncpy(str, geom, n); - str[n] = '\0'; - - flags = XParseGeometry(str, &x, &y, &w, &h); - - if (!flags) { - flags |= WidthValue; /* default is tile */ - w = 0; - } - if (!(flags & XValue)) { - x = 50; - } - if (!(flags & HeightValue)) { - h = w; - } - if (!(flags & YValue)) { - if (flags & XNegative) - flags |= YNegative; - y = x; - } - - if (flags & (WidthValue | HeightValue)) { - if (w && !h) { - w = pmap->w * ((float) w / 100); - h = pmap->h; - } else if (h && !w) { - w = pmap->w; - h = pmap->h * ((float) h / 100); + D_PIXMAP(("scale_pixmap(\"%s\")\n", geom)); + if (!strcmp(geom, "?")) { + sprintf(str, "[%dx%d+%d+%d]", pmap->w, pmap->h, pmap->x, pmap->y); + xterm_seq(XTerm_title, str); + return 0; } - } - if (pmap->w != (int) w) { - pmap->w = (int) w; - changed++; - } - if (pmap->h != (int) h) { - pmap->h = (int) h; - changed++; - } + if ((opstr = strchr(geom, ':')) != NULL) { + *opstr++ = '\0'; + op = parse_pixmap_ops(opstr); + } else { + op = pmap->op; + } + if ((p = strchr(geom, ';')) == NULL) + p = strchr(geom, '\0'); + n = (p - geom); + if (n > GEOM_LEN - 1) + return 0; - if (!(flags & WidthValue) && geom[0] != '=') { - x += pmap->x; - y += pmap->y; - } else { - if (flags & XNegative) - x += 100; - if (flags & YNegative) - y += 100; - } - BOUND(x, 0, 100); - BOUND(y, 0, 100); + strncpy(str, geom, n); + str[n] = '\0'; - if (pmap->x != x) { - pmap->x = x; - changed++; - } - if (pmap->y != y) { - pmap->y = y; - changed++; - } - if (pmap->op != op) { - pmap->op = op; - changed++; - } - D_PIXMAP(("Returning %hu, *pmap == { op [%hu], w [%hd], h [%hd], x [%hd], y [%hd] }\n", changed, pmap->op, pmap->w, pmap->h, pmap->x, pmap->y)); - return changed; + flags = XParseGeometry(str, &x, &y, &w, &h); + + if (!flags) { + flags |= WidthValue; /* default is tile */ + w = 0; + } + if (!(flags & XValue)) { + x = 50; + } + if (!(flags & HeightValue)) { + h = w; + } + if (!(flags & YValue)) { + if (flags & XNegative) + flags |= YNegative; + y = x; + } + + if (flags & (WidthValue | HeightValue)) { + if (w && !h) { + w = pmap->w * ((float) w / 100); + h = pmap->h; + } else if (h && !w) { + w = pmap->w; + h = pmap->h * ((float) h / 100); + } + } + if (pmap->w != (int) w) { + pmap->w = (int) w; + changed++; + } + if (pmap->h != (int) h) { + pmap->h = (int) h; + changed++; + } + + if (!(flags & WidthValue) && geom[0] != '=') { + x += pmap->x; + y += pmap->y; + } else { + if (flags & XNegative) + x += 100; + if (flags & YNegative) + y += 100; + } + BOUND(x, 0, 100); + BOUND(y, 0, 100); + + if (pmap->x != x) { + pmap->x = x; + changed++; + } + if (pmap->y != y) { + pmap->y = y; + changed++; + } + if (pmap->op != op) { + pmap->op = op; + changed++; + } + D_PIXMAP(("Returning %hu, *pmap == { op [%hu], w [%hd], h [%hd], x [%hd], y [%hd] }\n", changed, pmap->op, pmap->w, pmap->h, pmap->x, + pmap->y)); + return changed; } -image_t * -create_eterm_image(void) +image_t *create_eterm_image(void) { - image_t *i; + image_t *i; - i = (image_t *) MALLOC(sizeof(image_t)); - MEMSET(i, 0, sizeof(image_t)); - return (i); + i = (image_t *) MALLOC(sizeof(image_t)); + MEMSET(i, 0, sizeof(image_t)); + return (i); } void reset_eterm_image(image_t *img, unsigned long mask) { - ASSERT(img != NULL); + ASSERT(img != NULL); - D_PIXMAP(("reset_image(%8p, 0x%08x)\n", img, mask)); + D_PIXMAP(("reset_image(%8p, 0x%08x)\n", img, mask)); - if ((mask & RESET_NORM) && img->norm) { - reset_simage(img->norm, mask); - } - if ((mask & RESET_SELECTED) && img->selected) { - reset_simage(img->selected, mask); - } - if ((mask & RESET_CLICKED) && img->clicked) { - reset_simage(img->clicked, mask); - } - if ((mask & RESET_DISABLED) && img->disabled) { - reset_simage(img->disabled, mask); - } - if (mask & RESET_MODE) { - img->mode = 0; - } - if (mask & RESET_ALL) { - img->userdef = 0; - img->win = None; - img->current = img->norm; - } + if ((mask & RESET_NORM) && img->norm) { + reset_simage(img->norm, mask); + } + if ((mask & RESET_SELECTED) && img->selected) { + reset_simage(img->selected, mask); + } + if ((mask & RESET_CLICKED) && img->clicked) { + reset_simage(img->clicked, mask); + } + if ((mask & RESET_DISABLED) && img->disabled) { + reset_simage(img->disabled, mask); + } + if (mask & RESET_MODE) { + img->mode = 0; + } + if (mask & RESET_ALL) { + img->userdef = 0; + img->win = None; + img->current = img->norm; + } } void free_eterm_image(image_t *img) { - if (img->selected == img->norm) { - img->selected = NULL; - } - if (img->clicked == img->norm) { - img->clicked = NULL; - } - if (img->disabled == img->norm) { - img->disabled = NULL; - } - free_simage(img->norm); - if (img->clicked == img->selected) { - img->clicked = NULL; - } - if (img->disabled == img->selected || img->disabled == img->clicked) { - img->disabled = NULL; - } - if (img->selected) { - free_simage(img->selected); - } - if (img->clicked) { - free_simage(img->clicked); - } - if (img->disabled) { - free_simage(img->disabled); - } + if (img->selected == img->norm) { + img->selected = NULL; + } + if (img->clicked == img->norm) { + img->clicked = NULL; + } + if (img->disabled == img->norm) { + img->disabled = NULL; + } + free_simage(img->norm); + if (img->clicked == img->selected) { + img->clicked = NULL; + } + if (img->disabled == img->selected || img->disabled == img->clicked) { + img->disabled = NULL; + } + if (img->selected) { + free_simage(img->selected); + } + if (img->clicked) { + free_simage(img->clicked); + } + if (img->disabled) { + free_simage(img->disabled); + } #if 0 - /* FIXME: There should really be an option to specify whether or not - to free the image itself, but since we never MALLOC() an entire - image_t, it's not really needed at this point. And I'm lazy. :-) */ - FREE(img); + /* FIXME: There should really be an option to specify whether or not + to free the image itself, but since we never MALLOC() an entire + image_t, it's not really needed at this point. And I'm lazy. :-) */ + FREE(img); #endif } -simage_t * -create_simage(void) +simage_t *create_simage(void) { - simage_t *s; + simage_t *s; - s = (simage_t *) MALLOC(sizeof(simage_t)); - MEMSET(s, 0, sizeof(simage_t)); - s->pmap = (pixmap_t *) MALLOC(sizeof(pixmap_t)); - s->iml = (imlib_t *) MALLOC(sizeof(imlib_t)); - MEMSET(s->pmap, 0, sizeof(pixmap_t)); - MEMSET(s->iml, 0, sizeof(imlib_t)); - return s; + s = (simage_t *) MALLOC(sizeof(simage_t)); + MEMSET(s, 0, sizeof(simage_t)); + s->pmap = (pixmap_t *) MALLOC(sizeof(pixmap_t)); + s->iml = (imlib_t *) MALLOC(sizeof(imlib_t)); + MEMSET(s->pmap, 0, sizeof(pixmap_t)); + MEMSET(s->iml, 0, sizeof(imlib_t)); + return s; } void reset_simage(simage_t *simg, unsigned long mask) { - ASSERT(simg != NULL); + ASSERT(simg != NULL); - D_PIXMAP(("reset_simage(%8p, 0x%08x)\n", simg, mask)); + D_PIXMAP(("reset_simage(%8p, 0x%08x)\n", simg, mask)); - if ((mask & RESET_PMAP_PIXMAP) && simg->pmap->pixmap != None) { - IMLIB_FREE_PIXMAP(simg->pmap->pixmap); - simg->pmap->pixmap = None; - simg->pmap->mask = None; - } - if ((mask & RESET_IMLIB_IM) && simg->iml->im) { - imlib_context_set_image(simg->iml->im); - imlib_free_image_and_decache(); - simg->iml->im = NULL; - } - if ((mask & RESET_IMLIB_BORDER) && simg->iml->border) { - FREE(simg->iml->border); - simg->iml->border = NULL; - } - if ((mask & RESET_IMLIB_BEVEL) && simg->iml->bevel) { - FREE(simg->iml->bevel->edges); - FREE(simg->iml->bevel); - simg->iml->bevel = NULL; - } - if ((mask & RESET_IMLIB_PAD) && simg->iml->pad) { - FREE(simg->iml->pad); - simg->iml->pad = NULL; - } - if ((mask & RESET_IMLIB_MOD) && simg->iml->mod) { - FREE(simg->iml->mod); - simg->iml->mod = NULL; - } - if ((mask & RESET_IMLIB_RMOD) && simg->iml->rmod) { - if (simg->iml->rmod->imlib_mod) { - imlib_context_set_color_modifier(simg->iml->rmod->imlib_mod); - imlib_free_color_modifier(); + if ((mask & RESET_PMAP_PIXMAP) && simg->pmap->pixmap != None) { + IMLIB_FREE_PIXMAP(simg->pmap->pixmap); + simg->pmap->pixmap = None; + simg->pmap->mask = None; } - FREE(simg->iml->rmod); - simg->iml->rmod = NULL; - } - if ((mask & RESET_IMLIB_GMOD) && simg->iml->gmod) { - if (simg->iml->gmod->imlib_mod) { - imlib_context_set_color_modifier(simg->iml->gmod->imlib_mod); - imlib_free_color_modifier(); + if ((mask & RESET_IMLIB_IM) && simg->iml->im) { + imlib_context_set_image(simg->iml->im); + imlib_free_image_and_decache(); + simg->iml->im = NULL; } - FREE(simg->iml->gmod); - simg->iml->gmod = NULL; - } - if ((mask & RESET_IMLIB_BMOD) && simg->iml->bmod) { - if (simg->iml->bmod->imlib_mod) { - imlib_context_set_color_modifier(simg->iml->bmod->imlib_mod); - imlib_free_color_modifier(); + if ((mask & RESET_IMLIB_BORDER) && simg->iml->border) { + FREE(simg->iml->border); + simg->iml->border = NULL; + } + if ((mask & RESET_IMLIB_BEVEL) && simg->iml->bevel) { + FREE(simg->iml->bevel->edges); + FREE(simg->iml->bevel); + simg->iml->bevel = NULL; + } + if ((mask & RESET_IMLIB_PAD) && simg->iml->pad) { + FREE(simg->iml->pad); + simg->iml->pad = NULL; + } + if ((mask & RESET_IMLIB_MOD) && simg->iml->mod) { + FREE(simg->iml->mod); + simg->iml->mod = NULL; + } + if ((mask & RESET_IMLIB_RMOD) && simg->iml->rmod) { + if (simg->iml->rmod->imlib_mod) { + imlib_context_set_color_modifier(simg->iml->rmod->imlib_mod); + imlib_free_color_modifier(); + } + FREE(simg->iml->rmod); + simg->iml->rmod = NULL; + } + if ((mask & RESET_IMLIB_GMOD) && simg->iml->gmod) { + if (simg->iml->gmod->imlib_mod) { + imlib_context_set_color_modifier(simg->iml->gmod->imlib_mod); + imlib_free_color_modifier(); + } + FREE(simg->iml->gmod); + simg->iml->gmod = NULL; + } + if ((mask & RESET_IMLIB_BMOD) && simg->iml->bmod) { + if (simg->iml->bmod->imlib_mod) { + imlib_context_set_color_modifier(simg->iml->bmod->imlib_mod); + imlib_free_color_modifier(); + } + FREE(simg->iml->bmod); + simg->iml->bmod = NULL; + } + if (mask & RESET_PMAP_GEOM) { + simg->pmap->w = 0; + simg->pmap->h = 0; + simg->pmap->x = 50; + simg->pmap->y = 50; + simg->pmap->op = OP_NONE; } - FREE(simg->iml->bmod); - simg->iml->bmod = NULL; - } - if (mask & RESET_PMAP_GEOM) { - simg->pmap->w = 0; - simg->pmap->h = 0; - simg->pmap->x = 50; - simg->pmap->y = 50; - simg->pmap->op = OP_NONE; - } } void free_simage(simage_t *s) { - reset_simage(s, RESET_ALL_SIMG); - FREE(s->iml); - FREE(s->pmap); - FREE(s); + reset_simage(s, RESET_ALL_SIMG); + FREE(s->iml); + FREE(s->pmap); + FREE(s); } -colormod_t * -create_colormod(void) +colormod_t *create_colormod(void) { - colormod_t *cmod; + colormod_t *cmod; - cmod = (colormod_t *) MALLOC(sizeof(colormod_t)); - cmod->brightness = cmod->contrast = cmod->gamma = 0x100; - cmod->imlib_mod = NULL; - return cmod; + cmod = (colormod_t *) MALLOC(sizeof(colormod_t)); + cmod->brightness = cmod->contrast = cmod->gamma = 0x100; + cmod->imlib_mod = NULL; + return cmod; } void reset_colormod(colormod_t *cmod) { - ASSERT(cmod != NULL); - cmod->brightness = cmod->contrast = cmod->gamma = 0x100; - if (cmod->imlib_mod) { - imlib_context_set_color_modifier(cmod->imlib_mod); - imlib_reset_color_modifier(); - } + ASSERT(cmod != NULL); + cmod->brightness = cmod->contrast = cmod->gamma = 0x100; + if (cmod->imlib_mod) { + imlib_context_set_color_modifier(cmod->imlib_mod); + imlib_reset_color_modifier(); + } } void free_colormod(colormod_t *cmod) { - ASSERT(cmod != NULL); - if (cmod->imlib_mod) { - imlib_context_set_color_modifier(cmod->imlib_mod); - imlib_free_color_modifier(); - } - FREE(cmod); + ASSERT(cmod != NULL); + if (cmod->imlib_mod) { + imlib_context_set_color_modifier(cmod->imlib_mod); + imlib_free_color_modifier(); + } + FREE(cmod); } static const char * get_iclass_name(unsigned char which) { - switch (which) { - case image_bg: return "ETERM_BG"; break; - case image_up: return "ETERM_ARROW_UP"; break; - case image_down: return "ETERM_ARROW_DOWN"; break; - case image_left: return "ETERM_ARROW_LEFT"; break; - case image_right: return "ETERM_ARROW_RIGHT"; break; - case image_sb: return "ETERM_TROUGH"; break; - case image_sa: return "ETERM_ANCHOR"; break; - case image_st: return "ETERM_THUMB"; break; - case image_menu: return "ETERM_MENU_ITEM"; break; /* FIXME: This should be ETERM_MENU_BOX */ - case image_menuitem: return "ETERM_MENU_ITEM"; break; - case image_submenu: return "ETERM_MENU_SUBMENU"; break; - case image_button: return "ETERM_MENU_ITEM"; break; /* FIXME: These four should */ - case image_bbar: return "ETERM_MENU_BOX"; break; /* have their own image classes */ - case image_gbar: return "ETERM_ANCHOR"; break; - case image_dialog: return "ETERM_MENU_BOX"; break; - default: - ASSERT_NOTREACHED_RVAL(NULL); - break; - } + switch (which) { + case image_bg: + return "ETERM_BG"; + break; + case image_up: + return "ETERM_ARROW_UP"; + break; + case image_down: + return "ETERM_ARROW_DOWN"; + break; + case image_left: + return "ETERM_ARROW_LEFT"; + break; + case image_right: + return "ETERM_ARROW_RIGHT"; + break; + case image_sb: + return "ETERM_TROUGH"; + break; + case image_sa: + return "ETERM_ANCHOR"; + break; + case image_st: + return "ETERM_THUMB"; + break; + case image_menu: + return "ETERM_MENU_ITEM"; + break; /* FIXME: This should be ETERM_MENU_BOX */ + case image_menuitem: + return "ETERM_MENU_ITEM"; + break; + case image_submenu: + return "ETERM_MENU_SUBMENU"; + break; + case image_button: + return "ETERM_MENU_ITEM"; + break; /* FIXME: These four should */ + case image_bbar: + return "ETERM_MENU_BOX"; + break; /* have their own image classes */ + case image_gbar: + return "ETERM_ANCHOR"; + break; + case image_dialog: + return "ETERM_MENU_BOX"; + break; + default: + ASSERT_NOTREACHED_RVAL(NULL); + break; + } } unsigned char check_image_ipc(unsigned char reset) { - static unsigned char checked = 0; - register unsigned short i; - char buff[255], *reply; - const char *iclass; + static unsigned char checked = 0; + register unsigned short i; + char buff[255], *reply; + const char *iclass; - if (reset) { - checked = 0; - } - if (checked) { - return ((checked == 1) ? 1 : 0); - } - for (i=0; i < image_max; i++) { - if (!image_mode_is(i, MODE_AUTO)) { - continue; + if (reset) { + checked = 0; } - iclass = get_iclass_name(i); - snprintf(buff, sizeof(buff), "imageclass %s query", iclass); - reply = enl_send_and_wait(buff); - if (strstr(reply, "not")) { - print_error("ImageClass \"%s\" is not defined in Enlightenment. Disallowing \"auto\" mode for this image.\n", iclass); - image_mode_fallback(i); - } else if (strstr(reply, "Error")) { - print_error("Looks like this version of Enlightenment doesn't support the IPC commands I need. Disallowing \"auto\" mode for all images.\n"); - FOREACH_IMAGE(if (image_mode_is(idx, MODE_AUTO)) {if (image_mode_is(idx, ALLOW_IMAGE)) {image_set_mode(idx, MODE_IMAGE);} else {image_set_mode(idx, MODE_SOLID);}} \ - if (image_mode_is(idx, ALLOW_AUTO)) {image_disallow_mode(idx, ALLOW_AUTO);}); - FREE(reply); - checked = 2; - return 0; + if (checked) { + return ((checked == 1) ? 1 : 0); } - FREE(reply); - } - checked = 1; - return 1; + for (i = 0; i < image_max; i++) { + if (!image_mode_is(i, MODE_AUTO)) { + continue; + } + iclass = get_iclass_name(i); + snprintf(buff, sizeof(buff), "imageclass %s query", iclass); + reply = enl_send_and_wait(buff); + if (strstr(reply, "not")) { + print_error("ImageClass \"%s\" is not defined in Enlightenment. Disallowing \"auto\" mode for this image.\n", iclass); + image_mode_fallback(i); + } else if (strstr(reply, "Error")) { + print_error("Looks like this version of Enlightenment doesn't support the IPC commands I need. Disallowing \"auto\" mode for all images.\n"); + /* *INDENT-OFF* */ + FOREACH_IMAGE( + if (image_mode_is(idx, MODE_AUTO)) { + if (image_mode_is(idx, ALLOW_IMAGE)) { + image_set_mode(idx, MODE_IMAGE); + } else { + image_set_mode(idx, MODE_SOLID); + } + } + if (image_mode_is(idx, ALLOW_AUTO)) { + image_disallow_mode(idx, ALLOW_AUTO); + } + ); + /* *INDENT-ON* */ + FREE(reply); + checked = 2; + return 0; + } + FREE(reply); + } + checked = 1; + return 1; } Pixmap create_trans_pixmap(simage_t *simg, unsigned char which, Drawable d, int x, int y, unsigned short width, unsigned short height) { - int pw, ph; - Window dummy; - Screen *scr; - Pixmap p = None; - GC gc; + int pw, ph; + Window dummy; + Screen *scr; + Pixmap p = None; + GC gc; - D_PIXMAP(("create_trans_pixmap(%8p, 0x%08x, %u, %d, %d, %hu, %hu) called.\n", simg, d, which, x, y, width, height)); - scr = ScreenOfDisplay(Xdisplay, Xscreen); - if (!scr) - return None; + D_PIXMAP(("create_trans_pixmap(%8p, 0x%08x, %u, %d, %d, %hu, %hu) called.\n", simg, d, which, x, y, width, height)); + scr = ScreenOfDisplay(Xdisplay, Xscreen); + if (!scr) + return None; - if (!update_desktop_info(&pw, &ph)) { - D_PIXMAP(("update_desktop_info() failed.\n")); - return None; - } - if (refresh_type == NO_REFRESH) { - /* If we're hidden/shaded, translated coordinates to be parent relative, then use the - internal cache data to tell where we are on the desktop. Otherwise, just ask X. */ - XTranslateCoordinates(Xdisplay, d, TermWin.parent, x, y, &x, &y, &dummy); - x += TermWin.x; - y += TermWin.y; - } else { - XTranslateCoordinates(Xdisplay, d, desktop_window, x, y, &x, &y, &dummy); - } - p = LIBAST_X_CREATE_PIXMAP(width, height); - gc = LIBAST_X_CREATE_GC(0, NULL); - D_PIXMAP(("Created p [0x%08x] as a %hux%hu pixmap at %d, %d relative to window 0x%08x\n", p, width, height, x, y, desktop_window)); - if (p != None) { - if (pw < scr->width || ph < scr->height) { - D_PIXMAP(("Tiling %ux%u desktop pixmap 0x%08x onto p.\n", pw, ph, desktop_pixmap)); - XSetTile(Xdisplay, gc, desktop_pixmap); - XSetTSOrigin(Xdisplay, gc, pw - (x % pw), ph - (y % ph)); - XSetFillStyle(Xdisplay, gc, FillTiled); - XFillRectangle(Xdisplay, p, gc, 0, 0, width, height); + if (!update_desktop_info(&pw, &ph)) { + D_PIXMAP(("update_desktop_info() failed.\n")); + return None; + } + if (refresh_type == NO_REFRESH) { + /* If we're hidden/shaded, translated coordinates to be parent relative, then use the + internal cache data to tell where we are on the desktop. Otherwise, just ask X. */ + XTranslateCoordinates(Xdisplay, d, TermWin.parent, x, y, &x, &y, &dummy); + x += TermWin.x; + y += TermWin.y; } else { - D_PIXMAP(("Copying %hux%hu rectangle at %d, %d from %ux%u desktop pixmap 0x%08x onto p.\n", width, height, x, y, pw, ph, desktop_pixmap)); - XCopyArea(Xdisplay, desktop_pixmap, p, gc, x, y, width, height, 0, 0); + XTranslateCoordinates(Xdisplay, d, desktop_window, x, y, &x, &y, &dummy); } - if ((which != image_bg || (image_toggles & IMOPT_ITRANS) || images[image_bg].current != images[image_bg].norm) && need_colormod(simg->iml)) { - colormod_trans(p, simg->iml, gc, width, height); + p = LIBAST_X_CREATE_PIXMAP(width, height); + gc = LIBAST_X_CREATE_GC(0, NULL); + D_PIXMAP(("Created p [0x%08x] as a %hux%hu pixmap at %d, %d relative to window 0x%08x\n", p, width, height, x, y, desktop_window)); + if (p != None) { + if (pw < scr->width || ph < scr->height) { + D_PIXMAP(("Tiling %ux%u desktop pixmap 0x%08x onto p.\n", pw, ph, desktop_pixmap)); + XSetTile(Xdisplay, gc, desktop_pixmap); + XSetTSOrigin(Xdisplay, gc, pw - (x % pw), ph - (y % ph)); + XSetFillStyle(Xdisplay, gc, FillTiled); + XFillRectangle(Xdisplay, p, gc, 0, 0, width, height); + } else { + D_PIXMAP(("Copying %hux%hu rectangle at %d, %d from %ux%u desktop pixmap 0x%08x onto p.\n", width, height, x, y, pw, ph, + desktop_pixmap)); + XCopyArea(Xdisplay, desktop_pixmap, p, gc, x, y, width, height, 0, 0); + } + if ((which != image_bg || (image_toggles & IMOPT_ITRANS) || images[image_bg].current != images[image_bg].norm) + && need_colormod(simg->iml)) { + colormod_trans(p, simg->iml, gc, width, height); + } + if (simg->iml->bevel != NULL) { + D_PIXMAP(("Beveling pixmap 0x%08x with edges %d, %d, %d, %d\n", p, simg->iml->bevel->edges->left, simg->iml->bevel->edges->top, + simg->iml->bevel->edges->right, simg->iml->bevel->edges->bottom)); + bevel_pixmap(p, width, height, simg->iml->bevel->edges, simg->iml->bevel->up); + } } - if (simg->iml->bevel != NULL) { - D_PIXMAP(("Beveling pixmap 0x%08x with edges %d, %d, %d, %d\n", p, simg->iml->bevel->edges->left, simg->iml->bevel->edges->top, - simg->iml->bevel->edges->right, simg->iml->bevel->edges->bottom)); - bevel_pixmap(p, width, height, simg->iml->bevel->edges, simg->iml->bevel->up); - } - } - LIBAST_X_FREE_GC(gc); - return p; + LIBAST_X_FREE_GC(gc); + return p; } Pixmap create_viewport_pixmap(simage_t *simg, Drawable d, int x, int y, unsigned short width, unsigned short height) { - short xsize, ysize; - Window dummy; - unsigned int pw, ph, pb, pd; - int px, py; - Pixmap p = None, mask = None; - GC gc; - Screen *scr; + short xsize, ysize; + Window dummy; + unsigned int pw, ph, pb, pd; + int px, py; + Pixmap p = None, mask = None; + GC gc; + Screen *scr; - D_PIXMAP(("create_viewport_pixmap(%8p, 0x%08x, %d, %d, %hu, %hu) called.\n", simg, d, x, y, width, height)); - scr = ScreenOfDisplay(Xdisplay, Xscreen); - if (!scr) - return None; + D_PIXMAP(("create_viewport_pixmap(%8p, 0x%08x, %d, %d, %hu, %hu) called.\n", simg, d, x, y, width, height)); + scr = ScreenOfDisplay(Xdisplay, Xscreen); + if (!scr) + return None; - if (desktop_window == None) { - get_desktop_window(); if (desktop_window == None) { - D_PIXMAP(("No desktop window found.\n")); - return None; - } - } - if (viewport_pixmap == None) { - imlib_t *tmp_iml = images[image_bg].current->iml; - - imlib_context_set_image(tmp_iml->im); - imlib_context_set_drawable(d); - imlib_image_set_has_alpha(0); - imlib_context_set_anti_alias(1); - imlib_context_set_dither(1); - imlib_context_set_blend(0); - xsize = imlib_image_get_width(); - ysize = imlib_image_get_height(); - if (tmp_iml->border) { - imlib_image_set_border(tmp_iml->border); - } else { - imlib_image_set_border(&bord_none); - } - imlib_context_set_color_modifier((tmp_iml->mod && tmp_iml->mod->imlib_mod) ? tmp_iml->mod->imlib_mod : NULL); - - if ((images[image_bg].current->pmap->w > 0) || (images[image_bg].current->pmap->op & OP_SCALE)) { - D_PIXMAP(("Scaling image to %dx%d\n", scr->width, scr->height)); - imlib_render_pixmaps_for_whole_image_at_size(&viewport_pixmap, &mask, scr->width, scr->height); - } else { - D_PIXMAP(("Tiling image at %dx%d\n", xsize, ysize)); - imlib_render_pixmaps_for_whole_image(&viewport_pixmap, &mask); + get_desktop_window(); + if (desktop_window == None) { + D_PIXMAP(("No desktop window found.\n")); + return None; + } } if (viewport_pixmap == None) { - print_error("Delayed image load failure for \"%s\". Using solid color mode.\n", imlib_image_get_filename()); - image_set_mode(image_bg, MODE_SOLID); - reset_simage(simg, RESET_ALL_SIMG); - return None; - } - IMLIB_REGISTER_PIXMAP(viewport_pixmap); - D_PIXMAP(("Created viewport_pixmap == 0x%08x\n", viewport_pixmap)); - } else { - XGetGeometry(Xdisplay, viewport_pixmap, &dummy, &px, &py, &pw, &ph, &pb, &pd); - xsize = (short) pw; - ysize = (short) ph; - } - if (simg->pmap->pixmap != None) { - XGetGeometry(Xdisplay, simg->pmap->pixmap, &dummy, &px, &py, &pw, &ph, &pb, &pd); - if (pw != width || ph != height) { - IMLIB_FREE_PIXMAP(simg->pmap->pixmap); - simg->pmap->pixmap = None; - } else { - p = simg->pmap->pixmap; - } - } - if (p == None) { - p = LIBAST_X_CREATE_PIXMAP(width, height); - D_PIXMAP(("Created p == 0x%08x\n", p)); - } - gc = LIBAST_X_CREATE_GC(0, NULL); - XTranslateCoordinates(Xdisplay, d, desktop_window, x, y, &x, &y, &dummy); - D_PIXMAP(("Translated coords are %d, %d\n", x, y)); - if ((images[image_bg].current->pmap->w > 0) || (images[image_bg].current->pmap->op & OP_SCALE)) { - XCopyArea(Xdisplay, viewport_pixmap, p, gc, x, y, width, height, 0, 0); - } else { - XSetTile(Xdisplay, gc, viewport_pixmap); - XSetTSOrigin(Xdisplay, gc, xsize - (x % xsize), ysize - (y % ysize)); - XSetFillStyle(Xdisplay, gc, FillTiled); - XFillRectangle(Xdisplay, p, gc, 0, 0, width, height); - } - LIBAST_X_FREE_GC(gc); - return p; -} + imlib_t *tmp_iml = images[image_bg].current->iml; -void -paste_simage(simage_t *simg, unsigned char which, Window win, Drawable d, unsigned short x, unsigned short y, unsigned short w, unsigned short h) -{ - Pixmap pmap = None, mask = None; - GC gc; - - ASSERT(simg != NULL); - REQUIRE(d != None); - - D_PIXMAP(("paste_simage(%8p, %s, 0x%08x, 0x%08x, %hd, %hd, %hd, %hd) called.\n", simg, get_image_type(which), (int) win, (int) d, x, y, w, h)); - - if (which != image_max) { - if (image_mode_is(which, MODE_AUTO) && image_mode_is(which, ALLOW_AUTO)) { - char buff[255], *reply; - const char *iclass, *state; - - check_image_ipc(0); - if (image_mode_is(which, MODE_AUTO)) { - iclass = get_iclass_name(which); - if (simg == images[which].selected) { - state = "hilited"; - } else if (simg == images[which].clicked) { - state = "clicked"; + imlib_context_set_image(tmp_iml->im); + imlib_context_set_drawable(d); + imlib_image_set_has_alpha(0); + imlib_context_set_anti_alias(1); + imlib_context_set_dither(1); + imlib_context_set_blend(0); + xsize = imlib_image_get_width(); + ysize = imlib_image_get_height(); + if (tmp_iml->border) { + imlib_image_set_border(tmp_iml->border); } else { - state = "normal"; + imlib_image_set_border(&bord_none); } - D_PIXMAP((" -> iclass == \"%s\", state == \"%s\"\n", NONULL(iclass), NONULL(state))); + imlib_context_set_color_modifier((tmp_iml->mod && tmp_iml->mod->imlib_mod) ? tmp_iml->mod->imlib_mod : NULL); - if (iclass) { - snprintf(buff, sizeof(buff), "imageclass %s apply_copy 0x%x %s %hd %hd", iclass, (int) d, state, w, h); - reply = enl_send_and_wait(buff); - if (strstr(reply, "Error")) { - print_error("Enlightenment didn't seem to like something about my syntax. Disallowing \"auto\" mode for this image.\n"); - image_mode_fallback(which); - FREE(reply); - } else { - pmap = (Pixmap) strtoul(reply, (char **) NULL, 0); - mask = (Pixmap) strtoul(get_pword(2, reply), (char **) NULL, 0); - FREE(reply); - enl_ipc_sync(); - if (pmap) { - gc = LIBAST_X_CREATE_GC(0, NULL); - XSetClipMask(Xdisplay, gc, mask); - XSetClipOrigin(Xdisplay, gc, x, y); - XCopyArea(Xdisplay, pmap, d, gc, 0, 0, w, h, x, y); - snprintf(buff, sizeof(buff), "imageclass %s free_pixmap 0x%08x", iclass, (int) pmap); - enl_ipc_send(buff); - LIBAST_X_FREE_GC(gc); - return; - } else { - print_error("Enlightenment returned a null pixmap, which I can't use. Disallowing \"auto\" mode for this image.\n"); - FREE(reply); - image_mode_fallback(which); - } - } + if ((images[image_bg].current->pmap->w > 0) || (images[image_bg].current->pmap->op & OP_SCALE)) { + D_PIXMAP(("Scaling image to %dx%d\n", scr->width, scr->height)); + imlib_render_pixmaps_for_whole_image_at_size(&viewport_pixmap, &mask, scr->width, scr->height); + } else { + D_PIXMAP(("Tiling image at %dx%d\n", xsize, ysize)); + imlib_render_pixmaps_for_whole_image(&viewport_pixmap, &mask); } - } - } else if (image_mode_is(which, MODE_TRANS) && image_mode_is(which, ALLOW_TRANS)) { - Pixmap p; - - gc = LIBAST_X_CREATE_GC(0, NULL); - p = create_trans_pixmap(simg, which, win, x, y, w, h); - if (p != None) { - XCopyArea(Xdisplay, p, d, gc, 0, 0, w, h, x, y); - if (p != desktop_pixmap) { - LIBAST_X_FREE_PIXMAP(p); + if (viewport_pixmap == None) { + print_error("Delayed image load failure for \"%s\". Using solid color mode.\n", imlib_image_get_filename()); + image_set_mode(image_bg, MODE_SOLID); + reset_simage(simg, RESET_ALL_SIMG); + return None; } - } - LIBAST_X_FREE_GC(gc); - } else if (image_mode_is(which, MODE_VIEWPORT) && image_mode_is(which, ALLOW_VIEWPORT)) { - Pixmap p; - - gc = LIBAST_X_CREATE_GC(0, NULL); - p = create_viewport_pixmap(simg, win, x, y, w, h); - if (simg->iml->bevel != NULL) { - bevel_pixmap(p, w, h, simg->iml->bevel->edges, simg->iml->bevel->up); - } - XCopyArea(Xdisplay, p, d, gc, 0, 0, w, h, x, y); - LIBAST_X_FREE_PIXMAP(p); - LIBAST_X_FREE_GC(gc); - } - } - - if ((which == image_max) || (image_mode_is(which, MODE_IMAGE) && image_mode_is(which, ALLOW_IMAGE))) { - imlib_context_set_image(simg->iml->im); - imlib_context_set_drawable(d); - imlib_context_set_anti_alias(1); - imlib_context_set_dither(1); - imlib_context_set_blend(0); - if (simg->iml->border) { - imlib_image_set_border(simg->iml->border); + IMLIB_REGISTER_PIXMAP(viewport_pixmap); + D_PIXMAP(("Created viewport_pixmap == 0x%08x\n", viewport_pixmap)); } else { - imlib_image_set_border(&bord_none); + XGetGeometry(Xdisplay, viewport_pixmap, &dummy, &px, &py, &pw, &ph, &pb, &pd); + xsize = (short) pw; + ysize = (short) ph; } - imlib_context_set_color_modifier((simg->iml->mod && simg->iml->mod->imlib_mod) ? simg->iml->mod->imlib_mod : NULL); - - if (w == imlib_image_get_width() && h == imlib_image_get_height()) { - imlib_render_pixmaps_for_whole_image(&pmap, &mask); - } else { - imlib_render_pixmaps_for_whole_image_at_size(&pmap, &mask, w, h); + if (simg->pmap->pixmap != None) { + XGetGeometry(Xdisplay, simg->pmap->pixmap, &dummy, &px, &py, &pw, &ph, &pb, &pd); + if (pw != width || ph != height) { + IMLIB_FREE_PIXMAP(simg->pmap->pixmap); + simg->pmap->pixmap = None; + } else { + p = simg->pmap->pixmap; + } } - if (pmap == None) { - print_error("Delayed image load failure for \"%s\".\n", NONULL(imlib_image_get_filename())); - reset_simage(simg, RESET_ALL_SIMG); - return; + if (p == None) { + p = LIBAST_X_CREATE_PIXMAP(width, height); + D_PIXMAP(("Created p == 0x%08x\n", p)); } - IMLIB_REGISTER_PIXMAP(pmap); gc = LIBAST_X_CREATE_GC(0, NULL); - if (mask) { - XSetClipMask(Xdisplay, gc, mask); - XSetClipOrigin(Xdisplay, gc, x, y); + XTranslateCoordinates(Xdisplay, d, desktop_window, x, y, &x, &y, &dummy); + D_PIXMAP(("Translated coords are %d, %d\n", x, y)); + if ((images[image_bg].current->pmap->w > 0) || (images[image_bg].current->pmap->op & OP_SCALE)) { + XCopyArea(Xdisplay, viewport_pixmap, p, gc, x, y, width, height, 0, 0); + } else { + XSetTile(Xdisplay, gc, viewport_pixmap); + XSetTSOrigin(Xdisplay, gc, xsize - (x % xsize), ysize - (y % ysize)); + XSetFillStyle(Xdisplay, gc, FillTiled); + XFillRectangle(Xdisplay, p, gc, 0, 0, width, height); } - XCopyArea(Xdisplay, pmap, d, gc, 0, 0, w, h, x, y); - IMLIB_FREE_PIXMAP(pmap); LIBAST_X_FREE_GC(gc); - } + return p; } void -redraw_image(unsigned char which) { +paste_simage(simage_t *simg, unsigned char which, Window win, Drawable d, unsigned short x, unsigned short y, unsigned short w, + unsigned short h) +{ + Pixmap pmap = None, mask = None; + GC gc; - switch (which) { - case image_bg: - render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); - scr_touch(); - break; - case image_up: - scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, MODE_MASK); - break; - case image_down: - scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, MODE_MASK); - break; - case image_sb: - scrollbar_draw_trough(IMAGE_STATE_CURRENT, MODE_MASK); - break; - case image_sa: - case image_st: - scrollbar_draw_anchor(IMAGE_STATE_CURRENT, MODE_MASK); - break; - case image_button: - case image_bbar: - case image_gbar: - bbar_draw_all(IMAGE_STATE_CURRENT, MODE_MASK); - break; - default: - D_PIXMAP(("Bad value %u\n", which)); - break; - } -} + ASSERT(simg != NULL); + REQUIRE(d != None); -void -redraw_images_by_mode(unsigned char mode) { + D_PIXMAP(("paste_simage(%8p, %s, 0x%08x, 0x%08x, %hd, %hd, %hd, %hd) called.\n", simg, get_image_type(which), (int) win, (int) d, x, y, + w, h)); - if (mode == MODE_SOLID) { - redraw_all_images(); - } else { - if (image_mode_is(image_bg, mode)) { - render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); - scr_touch(); + if (which != image_max) { + if (image_mode_is(which, MODE_AUTO) && image_mode_is(which, ALLOW_AUTO)) { + char buff[255], *reply; + const char *iclass, *state; + + check_image_ipc(0); + if (image_mode_is(which, MODE_AUTO)) { + iclass = get_iclass_name(which); + if (simg == images[which].selected) { + state = "hilited"; + } else if (simg == images[which].clicked) { + state = "clicked"; + } else { + state = "normal"; + } + D_PIXMAP((" -> iclass == \"%s\", state == \"%s\"\n", NONULL(iclass), NONULL(state))); + + if (iclass) { + snprintf(buff, sizeof(buff), "imageclass %s apply_copy 0x%x %s %hd %hd", iclass, (int) d, state, w, h); + reply = enl_send_and_wait(buff); + if (strstr(reply, "Error")) { + print_error + ("Enlightenment didn't seem to like something about my syntax. Disallowing \"auto\" mode for this image.\n"); + image_mode_fallback(which); + FREE(reply); + } else { + pmap = (Pixmap) strtoul(reply, (char **) NULL, 0); + mask = (Pixmap) strtoul(get_pword(2, reply), (char **) NULL, 0); + FREE(reply); + enl_ipc_sync(); + if (pmap) { + gc = LIBAST_X_CREATE_GC(0, NULL); + XSetClipMask(Xdisplay, gc, mask); + XSetClipOrigin(Xdisplay, gc, x, y); + XCopyArea(Xdisplay, pmap, d, gc, 0, 0, w, h, x, y); + snprintf(buff, sizeof(buff), "imageclass %s free_pixmap 0x%08x", iclass, (int) pmap); + enl_ipc_send(buff); + LIBAST_X_FREE_GC(gc); + return; + } else { + print_error + ("Enlightenment returned a null pixmap, which I can't use. Disallowing \"auto\" mode for this image.\n"); + FREE(reply); + image_mode_fallback(which); + } + } + } + } + } else if (image_mode_is(which, MODE_TRANS) && image_mode_is(which, ALLOW_TRANS)) { + Pixmap p; + + gc = LIBAST_X_CREATE_GC(0, NULL); + p = create_trans_pixmap(simg, which, win, x, y, w, h); + if (p != None) { + XCopyArea(Xdisplay, p, d, gc, 0, 0, w, h, x, y); + if (p != desktop_pixmap) { + LIBAST_X_FREE_PIXMAP(p); + } + } + LIBAST_X_FREE_GC(gc); + } else if (image_mode_is(which, MODE_VIEWPORT) && image_mode_is(which, ALLOW_VIEWPORT)) { + Pixmap p; + + gc = LIBAST_X_CREATE_GC(0, NULL); + p = create_viewport_pixmap(simg, win, x, y, w, h); + if (simg->iml->bevel != NULL) { + bevel_pixmap(p, w, h, simg->iml->bevel->edges, simg->iml->bevel->up); + } + XCopyArea(Xdisplay, p, d, gc, 0, 0, w, h, x, y); + LIBAST_X_FREE_PIXMAP(p); + LIBAST_X_FREE_GC(gc); + } + } + + if ((which == image_max) || (image_mode_is(which, MODE_IMAGE) && image_mode_is(which, ALLOW_IMAGE))) { + imlib_context_set_image(simg->iml->im); + imlib_context_set_drawable(d); + imlib_context_set_anti_alias(1); + imlib_context_set_dither(1); + imlib_context_set_blend(0); + if (simg->iml->border) { + imlib_image_set_border(simg->iml->border); + } else { + imlib_image_set_border(&bord_none); + } + imlib_context_set_color_modifier((simg->iml->mod && simg->iml->mod->imlib_mod) ? simg->iml->mod->imlib_mod : NULL); + + if (w == imlib_image_get_width() && h == imlib_image_get_height()) { + imlib_render_pixmaps_for_whole_image(&pmap, &mask); + } else { + imlib_render_pixmaps_for_whole_image_at_size(&pmap, &mask, w, h); + } + if (pmap == None) { + print_error("Delayed image load failure for \"%s\".\n", NONULL(imlib_image_get_filename())); + reset_simage(simg, RESET_ALL_SIMG); + return; + } + IMLIB_REGISTER_PIXMAP(pmap); + gc = LIBAST_X_CREATE_GC(0, NULL); + if (mask) { + XSetClipMask(Xdisplay, gc, mask); + XSetClipOrigin(Xdisplay, gc, x, y); + } + XCopyArea(Xdisplay, pmap, d, gc, 0, 0, w, h, x, y); + IMLIB_FREE_PIXMAP(pmap); + LIBAST_X_FREE_GC(gc); } - scrollbar_draw(IMAGE_STATE_CURRENT, mode); - bbar_draw_all(IMAGE_STATE_CURRENT, mode); - } } -#endif /* PIXMAP_SUPPORT */ + +void +redraw_image(unsigned char which) +{ + + switch (which) { + case image_bg: + render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); + scr_touch(); + break; + case image_up: + scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, MODE_MASK); + break; + case image_down: + scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, MODE_MASK); + break; + case image_sb: + scrollbar_draw_trough(IMAGE_STATE_CURRENT, MODE_MASK); + break; + case image_sa: + case image_st: + scrollbar_draw_anchor(IMAGE_STATE_CURRENT, MODE_MASK); + break; + case image_button: + case image_bbar: + case image_gbar: + bbar_draw_all(IMAGE_STATE_CURRENT, MODE_MASK); + break; + default: + D_PIXMAP(("Bad value %u\n", which)); + break; + } +} + +void +redraw_images_by_mode(unsigned char mode) +{ + + if (mode == MODE_SOLID) { + redraw_all_images(); + } else { + if (image_mode_is(image_bg, mode)) { + render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); + scr_touch(); + } + scrollbar_draw(IMAGE_STATE_CURRENT, mode); + bbar_draw_all(IMAGE_STATE_CURRENT, mode); + } +} +#endif /* PIXMAP_SUPPORT */ static void copy_buffer_pixmap(unsigned char mode, unsigned long fill, unsigned short width, unsigned short height) { - GC gc; - XGCValues gcvalue; + GC gc; + XGCValues gcvalue; - ASSERT(buffer_pixmap == None); - buffer_pixmap = LIBAST_X_CREATE_PIXMAP(width, height); - gcvalue.foreground = (Pixel) fill; - gc = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); - XSetGraphicsExposures(Xdisplay, gc, False); + ASSERT(buffer_pixmap == None); + buffer_pixmap = LIBAST_X_CREATE_PIXMAP(width, height); + gcvalue.foreground = (Pixel) fill; + gc = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); + XSetGraphicsExposures(Xdisplay, gc, False); - if (mode == MODE_SOLID) { - simage_t *simg; + if (mode == MODE_SOLID) { + simage_t *simg; - simg = images[image_bg].current; - if (simg->pmap->pixmap) { - LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); + simg = images[image_bg].current; + if (simg->pmap->pixmap) { + LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); + } + simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); + XFillRectangle(Xdisplay, simg->pmap->pixmap, gc, 0, 0, width, height); + XCopyArea(Xdisplay, simg->pmap->pixmap, buffer_pixmap, gc, 0, 0, width, height, 0, 0); + } else { + XCopyArea(Xdisplay, (Pixmap) fill, buffer_pixmap, gc, 0, 0, width, height, 0, 0); } - simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); - XFillRectangle(Xdisplay, simg->pmap->pixmap, gc, 0, 0, width, height); - XCopyArea(Xdisplay, simg->pmap->pixmap, buffer_pixmap, gc, 0, 0, width, height, 0, 0); - } else { - XCopyArea(Xdisplay, (Pixmap) fill, buffer_pixmap, gc, 0, 0, width, height, 0, 0); - } - LIBAST_X_FREE_GC(gc); + LIBAST_X_FREE_GC(gc); } void render_simage(simage_t *simg, Window win, unsigned short width, unsigned short height, unsigned char which, renderop_t renderop) { - XGCValues gcvalue; - GC gc; - Pixmap pixmap = None; - Screen *scr; + XGCValues gcvalue; + GC gc; + Pixmap pixmap = None; + Screen *scr; #ifdef PIXMAP_SUPPORT - short xsize, ysize; - short xpos = 0, ypos = 0; - unsigned short rendered = 0; - unsigned short xscaled = 0, yscaled = 0; + short xsize, ysize; + short xpos = 0, ypos = 0; + unsigned short rendered = 0; + unsigned short xscaled = 0, yscaled = 0; #endif - scr = ScreenOfDisplay(Xdisplay, Xscreen); - if (!scr) - return; + scr = ScreenOfDisplay(Xdisplay, Xscreen); + if (!scr) + return; - ASSERT(simg != NULL); - ASSERT(simg->iml != NULL); - ASSERT(simg->pmap != NULL); - REQUIRE(win != None); + ASSERT(simg != NULL); + ASSERT(simg->iml != NULL); + ASSERT(simg->pmap != NULL); + REQUIRE(win != None); - D_PIXMAP(("Rendering simg->iml->im %8p (%s) at %hux%hu onto window 0x%08x\n", simg->iml->im, get_image_type(which), width, height, win)); - D_PIXMAP(("Image mode is 0x%02x\n", images[which].mode)); + D_PIXMAP(("Rendering simg->iml->im %8p (%s) at %hux%hu onto window 0x%08x\n", simg->iml->im, get_image_type(which), width, height, + win)); + D_PIXMAP(("Image mode is 0x%02x\n", images[which].mode)); #ifdef PIXMAP_SUPPORT - if ((which == image_bg) && image_mode_is(image_bg, MODE_VIEWPORT)) { - width = scr->width; - height = scr->height; - } + if ((which == image_bg) && image_mode_is(image_bg, MODE_VIEWPORT)) { + width = scr->width; + height = scr->height; + } #endif - if (!(width) || !(height)) - return; + if (!(width) || !(height)) + return; - gcvalue.foreground = gcvalue.background = PixColors[bgColor]; - gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground, &gcvalue); - pixmap = simg->pmap->pixmap; /* Save this for later */ - - if ((which == image_bg) && (buffer_pixmap != None)) { - LIBAST_X_FREE_PIXMAP(buffer_pixmap); - buffer_pixmap = None; - } + gcvalue.foreground = gcvalue.background = PixColors[bgColor]; + gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground, &gcvalue); + pixmap = simg->pmap->pixmap; /* Save this for later */ + if ((which == image_bg) && (buffer_pixmap != None)) { + LIBAST_X_FREE_PIXMAP(buffer_pixmap); + buffer_pixmap = None; + } #ifdef PIXMAP_SUPPORT - if ((images[which].mode & MODE_AUTO) && (images[which].mode & ALLOW_AUTO)) { - char buff[255]; - const char *iclass, *state; + if ((images[which].mode & MODE_AUTO) && (images[which].mode & ALLOW_AUTO)) { + char buff[255]; + const char *iclass, *state; - check_image_ipc(0); - if (image_mode_is(which, MODE_AUTO)) { - iclass = get_iclass_name(which); - if (simg == images[which].selected) { - state = "hilited"; - } else if (simg == images[which].clicked) { - state = "clicked"; - } else { - state = "normal"; - } - if (iclass) { - if (renderop & RENDER_FORCE_PIXMAP) { - char *reply; - - snprintf(buff, sizeof(buff), "imageclass %s apply_copy 0x%x %s %hd %hd", iclass, (int) win, state, width, height); - reply = enl_send_and_wait(buff); - if (strstr(reply, "Error")) { - print_error("Enlightenment didn't seem to like something about my syntax. Disallowing \"auto\" mode for this image.\n"); - image_mode_fallback(which); - FREE(reply); - } else { - Pixmap pmap, mask; - - pmap = (Pixmap) strtoul(reply, (char **) NULL, 0); - mask = (Pixmap) strtoul(get_pword(2, reply), (char **) NULL, 0); - FREE(reply); - enl_ipc_sync(); - if (pmap) { - if (mask) { - XSetClipMask(Xdisplay, gc, mask); - XSetClipOrigin(Xdisplay, gc, 0, 0); - } - if (simg->pmap->pixmap) { - LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); - simg->pmap->pixmap = None; - } - if (renderop & RENDER_FORCE_PIXMAP) { - simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); - XCopyArea(Xdisplay, pmap, simg->pmap->pixmap, gc, 0, 0, width, height, 0, 0); - XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); - } else { - XSetWindowBackgroundPixmap(Xdisplay, win, pmap); - } - snprintf(buff, sizeof(buff), "imageclass %s free_pixmap 0x%08x", iclass, (int) pmap); - enl_ipc_send(buff); + check_image_ipc(0); + if (image_mode_is(which, MODE_AUTO)) { + iclass = get_iclass_name(which); + if (simg == images[which].selected) { + state = "hilited"; + } else if (simg == images[which].clicked) { + state = "clicked"; } else { - print_error("Enlightenment returned a null pixmap, which I can't use. Disallowing \"auto\" mode for this image.\n"); - FREE(reply); - image_mode_fallback(which); + state = "normal"; } - } - } else { - snprintf(buff, sizeof(buff), "imageclass %s apply 0x%x %s", iclass, (int) win, state); - enl_ipc_send(buff); - LIBAST_X_FREE_GC(gc); - return; - } - } - } - } + if (iclass) { + if (renderop & RENDER_FORCE_PIXMAP) { + char *reply; + snprintf(buff, sizeof(buff), "imageclass %s apply_copy 0x%x %s %hd %hd", iclass, (int) win, state, width, height); + reply = enl_send_and_wait(buff); + if (strstr(reply, "Error")) { + print_error + ("Enlightenment didn't seem to like something about my syntax. Disallowing \"auto\" mode for this image.\n"); + image_mode_fallback(which); + FREE(reply); + } else { + Pixmap pmap, mask; + + pmap = (Pixmap) strtoul(reply, (char **) NULL, 0); + mask = (Pixmap) strtoul(get_pword(2, reply), (char **) NULL, 0); + FREE(reply); + enl_ipc_sync(); + if (pmap) { + if (mask) { + XSetClipMask(Xdisplay, gc, mask); + XSetClipOrigin(Xdisplay, gc, 0, 0); + } + if (simg->pmap->pixmap) { + LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); + simg->pmap->pixmap = None; + } + if (renderop & RENDER_FORCE_PIXMAP) { + simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); + XCopyArea(Xdisplay, pmap, simg->pmap->pixmap, gc, 0, 0, width, height, 0, 0); + XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); + } else { + XSetWindowBackgroundPixmap(Xdisplay, win, pmap); + } + snprintf(buff, sizeof(buff), "imageclass %s free_pixmap 0x%08x", iclass, (int) pmap); + enl_ipc_send(buff); + } else { + print_error + ("Enlightenment returned a null pixmap, which I can't use. Disallowing \"auto\" mode for this image.\n"); + FREE(reply); + image_mode_fallback(which); + } + } + } else { + snprintf(buff, sizeof(buff), "imageclass %s apply 0x%x %s", iclass, (int) win, state); + enl_ipc_send(buff); + LIBAST_X_FREE_GC(gc); + return; + } + } + } + } # ifdef PIXMAP_OFFSET - if (image_mode_is(which, MODE_TRANS) && image_mode_is(which, ALLOW_TRANS)) { - if (simg->pmap->pixmap != None) { - LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); - } - simg->pmap->pixmap = create_trans_pixmap(simg, which, win, 0, 0, width, height); - if (simg->pmap->pixmap != None) { - if ((which == image_bg) && (Options & Opt_double_buffer)) { - copy_buffer_pixmap(MODE_TRANS, (unsigned long) simg->pmap->pixmap, width, height); - XSetWindowBackgroundPixmap(Xdisplay, win, buffer_pixmap); - } else { - XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); - if (!(renderop & RENDER_FORCE_PIXMAP)) { - IMLIB_FREE_PIXMAP(simg->pmap->pixmap); - simg->pmap->pixmap = None; - } - } - } else { - image_mode_fallback(which); - } - } else if (image_mode_is(which, MODE_VIEWPORT) && image_mode_is(which, ALLOW_VIEWPORT)) { - Pixmap p; - - D_PIXMAP(("Viewport mode enabled. viewport_pixmap == 0x%08x and simg->pmap->pixmap == 0x%08x\n", viewport_pixmap, simg->pmap->pixmap)); - p = create_viewport_pixmap(simg, win, 0, 0, width, height); - if (p && (p != simg->pmap->pixmap)) { - if (simg->pmap->pixmap != None) { - LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); - } - simg->pmap->pixmap = p; - } - if (simg->pmap->pixmap != None) { - D_PIXMAP(("Setting background of window 0x%08x to 0x%08x\n", win, simg->pmap->pixmap)); - if ((which == image_bg) && (Options & Opt_double_buffer)) { - copy_buffer_pixmap(MODE_VIEWPORT, (unsigned long) simg->pmap->pixmap, width, height); - XSetWindowBackgroundPixmap(Xdisplay, win, buffer_pixmap); - } else { - XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); - if (!(renderop & RENDER_FORCE_PIXMAP)) { - IMLIB_FREE_PIXMAP(simg->pmap->pixmap); - simg->pmap->pixmap = None; - } - } - } else { - image_mode_fallback(which); - } - } -# endif - if (image_mode_is(which, MODE_IMAGE) && image_mode_is(which, ALLOW_IMAGE)) { - if (simg->iml->im) { - int w = simg->pmap->w; - int h = simg->pmap->h; - int x = simg->pmap->x; - int y = simg->pmap->y; - - imlib_context_set_image(simg->iml->im); - imlib_context_set_drawable(win); - imlib_context_set_anti_alias(1); - imlib_context_set_dither(1); - imlib_context_set_blend(0); - xsize = imlib_image_get_width(); - ysize = imlib_image_get_height(); - D_PIXMAP(("w == %d, h == %d, x == %d, y == %d, xsize == %d, ysize == %d\n", w, h, x, y, xsize, ysize)); - - if ((simg->pmap->op & OP_PROPSCALE) && w && h) { - double x_ratio, y_ratio; - - x_ratio = ((double) width) / ((double) xsize); - y_ratio = ((double) height) / ((double) ysize); - if (x_ratio > 1) { - /* Window is larger than image. Smaller ratio determines whether which image dimension is closer in value - to the corresponding window dimension, which is the scale factor we want to use */ - if (x_ratio > y_ratio) { - x_ratio = y_ratio; - } - } else { - if (x_ratio > y_ratio) { - x_ratio = y_ratio; - } - } - xscaled = (unsigned short) ((xsize * x_ratio) * ((float) w / 100.0)); - yscaled = (unsigned short) ((ysize * x_ratio) * ((float) h / 100.0)); - } else { - if (w > 0) { - xscaled = width * ((float) w / 100.0); - } else { - xscaled = xsize; - } - if (h > 0) { - yscaled = height * ((float) h / 100.0); - } else { - yscaled = ysize; - } - } - - xpos = (short) ((width - xscaled) * ((float) x / 100.0)); - ypos = (short) ((height - yscaled) * ((float) y / 100.0)); - D_PIXMAP(("Calculated scaled size as %hux%hu with origin at (%hd, %hd)\n", xscaled, yscaled, xpos, ypos)); - - if (simg->iml->border) { - D_PIXMAP(("Setting image border: { left [%d], right [%d], top [%d], bottom [%d] }\n", - simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, simg->iml->border->bottom)); - imlib_image_set_border(simg->iml->border); - } else { - imlib_image_set_border(&bord_none); - } - imlib_context_set_color_modifier((simg->iml->mod && simg->iml->mod->imlib_mod) ? simg->iml->mod->imlib_mod : NULL); - - D_PIXMAP(("Rendering image simg->iml->im [%8p] to %hdx%hd pixmap\n", simg->iml->im, xscaled, yscaled)); - imlib_render_pixmaps_for_whole_image_at_size(&simg->pmap->pixmap, &simg->pmap->mask, xscaled, yscaled); - rendered = 1; - if (simg->pmap->pixmap != None) { - IMLIB_REGISTER_PIXMAP(simg->pmap->pixmap); - if (pixmap != None && pixmap != simg->pmap->pixmap) { - IMLIB_FREE_PIXMAP(pixmap); + if (image_mode_is(which, MODE_TRANS) && image_mode_is(which, ALLOW_TRANS)) { + if (simg->pmap->pixmap != None) { + LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); } - if (xscaled != width || yscaled != height || xpos != 0 || ypos != 0) { - unsigned char single; - - /* This tells us if we have a single, non-tiled image which does not entirely fill the window */ - single = ((xscaled < width || yscaled < height) && !(simg->pmap->op & OP_TILE)) ? 1 : 0; - - pixmap = simg->pmap->pixmap; - simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); - if (single) { - XFillRectangle(Xdisplay, simg->pmap->pixmap, gc, 0, 0, width, height); - } - XSetTile(Xdisplay, gc, pixmap); - XSetTSOrigin(Xdisplay, gc, xpos, ypos); - XSetFillStyle(Xdisplay, gc, FillTiled); - if (single) { - XCopyArea(Xdisplay, pixmap, simg->pmap->pixmap, gc, 0, 0, xscaled, yscaled, xpos, ypos); - } else { - XFillRectangle(Xdisplay, simg->pmap->pixmap, gc, 0, 0, width, height); - } - IMLIB_FREE_PIXMAP(pixmap); - } else if (renderop & RENDER_FORCE_PIXMAP) { - pixmap = simg->pmap->pixmap; - simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); - XCopyArea(Xdisplay, pixmap, simg->pmap->pixmap, gc, 0, 0, width, height, 0, 0); - IMLIB_FREE_PIXMAP(pixmap); - } else if (simg->pmap->mask != None) { - shaped_window_apply_mask(win, simg->pmap->mask); - } - if (simg->iml->bevel != NULL) { - bevel_pixmap(simg->pmap->pixmap, width, height, simg->iml->bevel->edges, simg->iml->bevel->up); - } - D_PIXMAP(("Setting background of window 0x%08x to 0x%08x\n", win, simg->pmap->pixmap)); - if ((which == image_bg) && (Options & Opt_double_buffer)) { - copy_buffer_pixmap(MODE_VIEWPORT, (unsigned long) simg->pmap->pixmap, width, height); - XSetWindowBackgroundPixmap(Xdisplay, win, buffer_pixmap); + simg->pmap->pixmap = create_trans_pixmap(simg, which, win, 0, 0, width, height); + if (simg->pmap->pixmap != None) { + if ((which == image_bg) && (Options & Opt_double_buffer)) { + copy_buffer_pixmap(MODE_TRANS, (unsigned long) simg->pmap->pixmap, width, height); + XSetWindowBackgroundPixmap(Xdisplay, win, buffer_pixmap); + } else { + XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); + if (!(renderop & RENDER_FORCE_PIXMAP)) { + IMLIB_FREE_PIXMAP(simg->pmap->pixmap); + simg->pmap->pixmap = None; + } + } } else { - /* FIXME: For efficiency, just fill the window with the pixmap - and handle exposes by copying from simg->pmap->pixmap. */ - XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); - if (!(renderop & RENDER_FORCE_PIXMAP)) { - IMLIB_FREE_PIXMAP(simg->pmap->pixmap); - simg->pmap->pixmap = None; - } + image_mode_fallback(which); + } + } else if (image_mode_is(which, MODE_VIEWPORT) && image_mode_is(which, ALLOW_VIEWPORT)) { + Pixmap p; + + D_PIXMAP(("Viewport mode enabled. viewport_pixmap == 0x%08x and simg->pmap->pixmap == 0x%08x\n", viewport_pixmap, + simg->pmap->pixmap)); + p = create_viewport_pixmap(simg, win, 0, 0, width, height); + if (p && (p != simg->pmap->pixmap)) { + if (simg->pmap->pixmap != None) { + LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); + } + simg->pmap->pixmap = p; + } + if (simg->pmap->pixmap != None) { + D_PIXMAP(("Setting background of window 0x%08x to 0x%08x\n", win, simg->pmap->pixmap)); + if ((which == image_bg) && (Options & Opt_double_buffer)) { + copy_buffer_pixmap(MODE_VIEWPORT, (unsigned long) simg->pmap->pixmap, width, height); + XSetWindowBackgroundPixmap(Xdisplay, win, buffer_pixmap); + } else { + XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); + if (!(renderop & RENDER_FORCE_PIXMAP)) { + IMLIB_FREE_PIXMAP(simg->pmap->pixmap); + simg->pmap->pixmap = None; + } + } + } else { + image_mode_fallback(which); + } + } +# endif + if (image_mode_is(which, MODE_IMAGE) && image_mode_is(which, ALLOW_IMAGE)) { + if (simg->iml->im) { + int w = simg->pmap->w; + int h = simg->pmap->h; + int x = simg->pmap->x; + int y = simg->pmap->y; + + imlib_context_set_image(simg->iml->im); + imlib_context_set_drawable(win); + imlib_context_set_anti_alias(1); + imlib_context_set_dither(1); + imlib_context_set_blend(0); + xsize = imlib_image_get_width(); + ysize = imlib_image_get_height(); + D_PIXMAP(("w == %d, h == %d, x == %d, y == %d, xsize == %d, ysize == %d\n", w, h, x, y, xsize, ysize)); + + if ((simg->pmap->op & OP_PROPSCALE) && w && h) { + double x_ratio, y_ratio; + + x_ratio = ((double) width) / ((double) xsize); + y_ratio = ((double) height) / ((double) ysize); + if (x_ratio > 1) { + /* Window is larger than image. Smaller ratio determines whether which image dimension is closer in value + to the corresponding window dimension, which is the scale factor we want to use */ + if (x_ratio > y_ratio) { + x_ratio = y_ratio; + } + } else { + if (x_ratio > y_ratio) { + x_ratio = y_ratio; + } + } + xscaled = (unsigned short) ((xsize * x_ratio) * ((float) w / 100.0)); + yscaled = (unsigned short) ((ysize * x_ratio) * ((float) h / 100.0)); + } else { + if (w > 0) { + xscaled = width * ((float) w / 100.0); + } else { + xscaled = xsize; + } + if (h > 0) { + yscaled = height * ((float) h / 100.0); + } else { + yscaled = ysize; + } + } + + xpos = (short) ((width - xscaled) * ((float) x / 100.0)); + ypos = (short) ((height - yscaled) * ((float) y / 100.0)); + D_PIXMAP(("Calculated scaled size as %hux%hu with origin at (%hd, %hd)\n", xscaled, yscaled, xpos, ypos)); + + if (simg->iml->border) { + D_PIXMAP(("Setting image border: { left [%d], right [%d], top [%d], bottom [%d] }\n", + simg->iml->border->left, simg->iml->border->right, simg->iml->border->top, simg->iml->border->bottom)); + imlib_image_set_border(simg->iml->border); + } else { + imlib_image_set_border(&bord_none); + } + imlib_context_set_color_modifier((simg->iml->mod && simg->iml->mod->imlib_mod) ? simg->iml->mod->imlib_mod : NULL); + + D_PIXMAP(("Rendering image simg->iml->im [%8p] to %hdx%hd pixmap\n", simg->iml->im, xscaled, yscaled)); + imlib_render_pixmaps_for_whole_image_at_size(&simg->pmap->pixmap, &simg->pmap->mask, xscaled, yscaled); + rendered = 1; + if (simg->pmap->pixmap != None) { + IMLIB_REGISTER_PIXMAP(simg->pmap->pixmap); + if (pixmap != None && pixmap != simg->pmap->pixmap) { + IMLIB_FREE_PIXMAP(pixmap); + } + if (xscaled != width || yscaled != height || xpos != 0 || ypos != 0) { + unsigned char single; + + /* This tells us if we have a single, non-tiled image which does not entirely fill the window */ + single = ((xscaled < width || yscaled < height) && !(simg->pmap->op & OP_TILE)) ? 1 : 0; + + pixmap = simg->pmap->pixmap; + simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); + if (single) { + XFillRectangle(Xdisplay, simg->pmap->pixmap, gc, 0, 0, width, height); + } + XSetTile(Xdisplay, gc, pixmap); + XSetTSOrigin(Xdisplay, gc, xpos, ypos); + XSetFillStyle(Xdisplay, gc, FillTiled); + if (single) { + XCopyArea(Xdisplay, pixmap, simg->pmap->pixmap, gc, 0, 0, xscaled, yscaled, xpos, ypos); + } else { + XFillRectangle(Xdisplay, simg->pmap->pixmap, gc, 0, 0, width, height); + } + IMLIB_FREE_PIXMAP(pixmap); + } else if (renderop & RENDER_FORCE_PIXMAP) { + pixmap = simg->pmap->pixmap; + simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); + XCopyArea(Xdisplay, pixmap, simg->pmap->pixmap, gc, 0, 0, width, height, 0, 0); + IMLIB_FREE_PIXMAP(pixmap); + } else if (simg->pmap->mask != None) { + shaped_window_apply_mask(win, simg->pmap->mask); + } + if (simg->iml->bevel != NULL) { + bevel_pixmap(simg->pmap->pixmap, width, height, simg->iml->bevel->edges, simg->iml->bevel->up); + } + D_PIXMAP(("Setting background of window 0x%08x to 0x%08x\n", win, simg->pmap->pixmap)); + if ((which == image_bg) && (Options & Opt_double_buffer)) { + copy_buffer_pixmap(MODE_VIEWPORT, (unsigned long) simg->pmap->pixmap, width, height); + XSetWindowBackgroundPixmap(Xdisplay, win, buffer_pixmap); + } else { + /* FIXME: For efficiency, just fill the window with the pixmap + and handle exposes by copying from simg->pmap->pixmap. */ + XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); + if (!(renderop & RENDER_FORCE_PIXMAP)) { + IMLIB_FREE_PIXMAP(simg->pmap->pixmap); + simg->pmap->pixmap = None; + } + } + } else { + print_error("Delayed image load failure for \"%s\". Using solid color mode.\n", imlib_image_get_filename()); + image_set_mode(which, MODE_SOLID); + reset_simage(simg, RESET_ALL_SIMG); + } + } else { + image_set_mode(which, MODE_SOLID); + reset_simage(simg, RESET_ALL_SIMG); } - } else { - print_error("Delayed image load failure for \"%s\". Using solid color mode.\n", imlib_image_get_filename()); - image_set_mode(which, MODE_SOLID); - reset_simage(simg, RESET_ALL_SIMG); - } - } else { - image_set_mode(which, MODE_SOLID); - reset_simage(simg, RESET_ALL_SIMG); } - } #endif - /* Fall back to solid mode if all else fails. */ - if (!image_mode_is(which, MODE_MASK)) { - if ((which == image_bg) && (Options & Opt_double_buffer)) { - copy_buffer_pixmap(MODE_SOLID, (unsigned long) PixColors[bgColor], width, height); - XSetWindowBackgroundPixmap(Xdisplay, win, buffer_pixmap); - } else { - if ((renderop & RENDER_FORCE_PIXMAP) || (simg->iml->bevel != NULL)) { - if (simg->pmap->pixmap) { - LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); + /* Fall back to solid mode if all else fails. */ + if (!image_mode_is(which, MODE_MASK)) { + if ((which == image_bg) && (Options & Opt_double_buffer)) { + copy_buffer_pixmap(MODE_SOLID, (unsigned long) PixColors[bgColor], width, height); + XSetWindowBackgroundPixmap(Xdisplay, win, buffer_pixmap); + } else { + if ((renderop & RENDER_FORCE_PIXMAP) || (simg->iml->bevel != NULL)) { + if (simg->pmap->pixmap) { + LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); + } + simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); + XSetForeground(Xdisplay, gc, ((which == image_bg) ? (PixColors[bgColor]) : (simg->bg))); + XFillRectangle(Xdisplay, simg->pmap->pixmap, gc, 0, 0, width, height); + if (simg->iml->bevel != NULL && simg->iml->bevel->edges != NULL) { + DRAW_SOLID_BEVEL(simg->pmap->pixmap, width, height, simg->bg, simg->iml->bevel->up, simg->iml->bevel->edges->left); + } + /* FIXME: For efficiency, just fill the window with the pixmap + and handle exposes by copying from simg->pmap->pixmap. */ + XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); + } else { + XSetWindowBackground(Xdisplay, win, ((which == image_bg) ? (PixColors[bgColor]) : (simg->bg))); + } } - simg->pmap->pixmap = LIBAST_X_CREATE_PIXMAP(width, height); - XSetForeground(Xdisplay, gc, ((which == image_bg) ? (PixColors[bgColor]) : (simg->bg))); - XFillRectangle(Xdisplay, simg->pmap->pixmap, gc, 0, 0, width, height); - if (simg->iml->bevel != NULL && simg->iml->bevel->edges != NULL) { - DRAW_SOLID_BEVEL(simg->pmap->pixmap, width, height, simg->bg, simg->iml->bevel->up, simg->iml->bevel->edges->left); - } - /* FIXME: For efficiency, just fill the window with the pixmap - and handle exposes by copying from simg->pmap->pixmap. */ - XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap); - } else { - XSetWindowBackground(Xdisplay, win, ((which == image_bg) ? (PixColors[bgColor]) : (simg->bg))); - } } - } - XClearWindow(Xdisplay, win); - LIBAST_X_FREE_GC(gc); - return; + XClearWindow(Xdisplay, win); + LIBAST_X_FREE_GC(gc); + return; } #ifdef PIXMAP_SUPPORT const char * search_path(const char *pathlist, const char *file) { - static char name[PATH_MAX]; - char *p; - const char *path; - int maxpath, len; - struct stat fst; + static char name[PATH_MAX]; + char *p; + const char *path; + int maxpath, len; + struct stat fst; - if (!pathlist || !file) { /* If either one is NULL, there really isn't much point in going on.... */ - return ((const char *) NULL); - } - getcwd(name, PATH_MAX); - len = strlen(name); - D_OPTIONS(("search_path(\"%s\", \"%s\") called from \"%s\".\n", pathlist, file, name)); - if (len < PATH_MAX - 1) { - strcat(name, "/"); - strncat(name, file, PATH_MAX - len - 1); - } - D_OPTIONS(("Checking for file \"%s\"\n", name)); - if (!access(name, R_OK)) { - if (stat(name, &fst)) { - D_OPTIONS(("Unable to stat %s -- %s\n", name, strerror(errno))); - } else { - D_OPTIONS(("Stat returned mode 0x%08o, S_ISDIR() == %d\n", fst.st_mode, S_ISDIR(fst.st_mode))); + if (!pathlist || !file) { /* If either one is NULL, there really isn't much point in going on.... */ + return ((const char *) NULL); } - if (!S_ISDIR(fst.st_mode)) { - return name; - } else { - D_OPTIONS(("%s is a directory.\n", name)); + getcwd(name, PATH_MAX); + len = strlen(name); + D_OPTIONS(("search_path(\"%s\", \"%s\") called from \"%s\".\n", pathlist, file, name)); + if (len < PATH_MAX - 1) { + strcat(name, "/"); + strncat(name, file, PATH_MAX - len - 1); } - } else { - D_OPTIONS(("Unable to access %s -- %s\n", name, strerror(errno))); - } - - if ((p = strchr(file, '@')) == NULL) - p = strchr(file, '\0'); - len = (p - file); - - /* leave room for an extra '/' and trailing '\0' */ - maxpath = sizeof(name) - (len + 2); - if (maxpath <= 0) - return NULL; - - /* check if we can find it now */ - strncpy(name, file, len); - name[len] = '\0'; - - D_OPTIONS(("Checking for file \"%s\"\n", name)); - if (!access(name, R_OK)) { - if (stat(name, &fst)) { - D_OPTIONS(("Unable to stat %s -- %s\n", name, strerror(errno))); - } else { - D_OPTIONS(("Stat returned mode 0x%08o, S_ISDIR() == %d\n", fst.st_mode, S_ISDIR(fst.st_mode))); - } - if (!S_ISDIR(fst.st_mode)) { - return name; - } else { - D_OPTIONS(("%s is a directory.\n", name)); - } - } else { - D_OPTIONS(("Unable to access %s -- %s\n", name, strerror(errno))); - } - for (path = pathlist; path != NULL && *path != '\0'; path = p) { - int n; - - /* colon delimited */ - if ((p = strchr(path, ':')) == NULL) - p = strchr(path, '\0'); - - n = (p - path); - if (*p != '\0') - p++; - - if (n > 0 && n <= maxpath) { - - if (*path == '~') { - unsigned int l; - char *home_dir = getenv("HOME"); - - if (home_dir && *home_dir) { - l = strlen(home_dir); - if (l + n < (unsigned) maxpath) { - strcpy(name, home_dir); - strncat(name, path + 1, n - 1); - n += l - 1; - } - } - } else { - strncpy(name, path, n); - } - if (name[n - 1] != '/') - name[n++] = '/'; - name[n] = '\0'; - strncat(name, file, len); - - D_OPTIONS(("Checking for file \"%s\"\n", name)); - if (!access(name, R_OK)) { + D_OPTIONS(("Checking for file \"%s\"\n", name)); + if (!access(name, R_OK)) { if (stat(name, &fst)) { - D_OPTIONS(("Unable to stat %s -- %s\n", name, strerror(errno))); + D_OPTIONS(("Unable to stat %s -- %s\n", name, strerror(errno))); } else { - D_OPTIONS(("Stat returned mode 0x%08o, S_ISDIR() == %d\n", fst.st_mode, S_ISDIR(fst.st_mode))); + D_OPTIONS(("Stat returned mode 0x%08o, S_ISDIR() == %d\n", fst.st_mode, S_ISDIR(fst.st_mode))); } if (!S_ISDIR(fst.st_mode)) { - return name; + return name; } else { - D_OPTIONS(("%s is a directory.\n", name)); + D_OPTIONS(("%s is a directory.\n", name)); } - } else { + } else { D_OPTIONS(("Unable to access %s -- %s\n", name, strerror(errno))); - } } - } - D_OPTIONS(("File \"%s\" not found in path.\n", file)); - return ((const char *) NULL); + + if ((p = strchr(file, '@')) == NULL) + p = strchr(file, '\0'); + len = (p - file); + + /* leave room for an extra '/' and trailing '\0' */ + maxpath = sizeof(name) - (len + 2); + if (maxpath <= 0) + return NULL; + + /* check if we can find it now */ + strncpy(name, file, len); + name[len] = '\0'; + + D_OPTIONS(("Checking for file \"%s\"\n", name)); + if (!access(name, R_OK)) { + if (stat(name, &fst)) { + D_OPTIONS(("Unable to stat %s -- %s\n", name, strerror(errno))); + } else { + D_OPTIONS(("Stat returned mode 0x%08o, S_ISDIR() == %d\n", fst.st_mode, S_ISDIR(fst.st_mode))); + } + if (!S_ISDIR(fst.st_mode)) { + return name; + } else { + D_OPTIONS(("%s is a directory.\n", name)); + } + } else { + D_OPTIONS(("Unable to access %s -- %s\n", name, strerror(errno))); + } + for (path = pathlist; path != NULL && *path != '\0'; path = p) { + int n; + + /* colon delimited */ + if ((p = strchr(path, ':')) == NULL) + p = strchr(path, '\0'); + + n = (p - path); + if (*p != '\0') + p++; + + if (n > 0 && n <= maxpath) { + + if (*path == '~') { + unsigned int l; + char *home_dir = getenv("HOME"); + + if (home_dir && *home_dir) { + l = strlen(home_dir); + if (l + n < (unsigned) maxpath) { + strcpy(name, home_dir); + strncat(name, path + 1, n - 1); + n += l - 1; + } + } + } else { + strncpy(name, path, n); + } + if (name[n - 1] != '/') + name[n++] = '/'; + name[n] = '\0'; + strncat(name, file, len); + + D_OPTIONS(("Checking for file \"%s\"\n", name)); + if (!access(name, R_OK)) { + if (stat(name, &fst)) { + D_OPTIONS(("Unable to stat %s -- %s\n", name, strerror(errno))); + } else { + D_OPTIONS(("Stat returned mode 0x%08o, S_ISDIR() == %d\n", fst.st_mode, S_ISDIR(fst.st_mode))); + } + if (!S_ISDIR(fst.st_mode)) { + return name; + } else { + D_OPTIONS(("%s is a directory.\n", name)); + } + } else { + D_OPTIONS(("Unable to access %s -- %s\n", name, strerror(errno))); + } + } + } + D_OPTIONS(("File \"%s\" not found in path.\n", file)); + return ((const char *) NULL); } unsigned char load_image(const char *file, simage_t *simg) { - const char *f; - Imlib_Image *im; - Imlib_Load_Error im_err; - char *geom; + const char *f; + Imlib_Image *im; + Imlib_Load_Error im_err; + char *geom; - ASSERT_RVAL(file != NULL, 0); - ASSERT_RVAL(simg != NULL, 0); + ASSERT_RVAL(file != NULL, 0); + ASSERT_RVAL(simg != NULL, 0); - D_PIXMAP(("load_image(%s, %8p)\n", file, simg)); + D_PIXMAP(("load_image(%s, %8p)\n", file, simg)); - if (*file != '\0') { - if ((geom = strchr(file, '@')) != NULL) { - *geom++ = 0; - } else if ((geom = strchr(file, ';')) != NULL) { - *geom++ = 0; + if (*file != '\0') { + if ((geom = strchr(file, '@')) != NULL) { + *geom++ = 0; + } else if ((geom = strchr(file, ';')) != NULL) { + *geom++ = 0; + } + if (geom != NULL) { + set_pixmap_scale(geom, simg->pmap); + } + if ((f = search_path(rs_path, file)) == NULL) { + f = search_path(getenv(PATH_ENV), file); + } + if (f != NULL) { + im = imlib_load_image_with_error_return(f, &im_err); + if (im == NULL) { + print_error("Unable to load image file \"%s\" -- %s\n", file, imlib_strerror(im_err)); + return 0; + } else { + reset_simage(simg, (RESET_IMLIB_IM | RESET_PMAP_PIXMAP | RESET_PMAP_MASK)); + simg->iml->im = im; + } + D_PIXMAP(("Found image %8p.\n", im)); + return 1; + } else { + print_error("Unable to locate file \"%s\" in image path.\n"); + } } - if (geom != NULL) { - set_pixmap_scale(geom, simg->pmap); - } - if ((f = search_path(rs_path, file)) == NULL) { - f = search_path(getenv(PATH_ENV), file); - } - if (f != NULL) { - im = imlib_load_image_with_error_return(f, &im_err); - if (im == NULL) { - print_error("Unable to load image file \"%s\" -- %s\n", file, imlib_strerror(im_err)); - return 0; - } else { - reset_simage(simg, (RESET_IMLIB_IM | RESET_PMAP_PIXMAP | RESET_PMAP_MASK)); - simg->iml->im = im; - } - D_PIXMAP(("Found image %8p.\n", im)); - return 1; - } else { - print_error("Unable to locate file \"%s\" in image path.\n"); - } - } - reset_simage(simg, RESET_ALL_SIMG); - return 0; + reset_simage(simg, RESET_ALL_SIMG); + return 0; } void update_cmod(colormod_t *cmod) { - ASSERT(cmod != NULL); + ASSERT(cmod != NULL); - /* When a particular R/G/B color modifier is changed, this function must be called - to resync the Imlib2 color modifier (imlib_mod) with our new brightness, - contrast, and gamma values. */ - if (cmod->imlib_mod) { - imlib_context_set_color_modifier(cmod->imlib_mod); - imlib_reset_color_modifier(); - } else { - cmod->imlib_mod = imlib_create_color_modifier(); - imlib_context_set_color_modifier(cmod->imlib_mod); - } - if (cmod->brightness != 0x100) { - imlib_modify_color_modifier_brightness((double) (cmod->brightness - 255.0) / 255.0); - } - if (cmod->contrast != 0x100) { - imlib_modify_color_modifier_contrast((double) (cmod->contrast - 255.0) / 255.0); - } - if (cmod->gamma != 0x100) { - imlib_modify_color_modifier_gamma((double) (cmod->gamma - 255.0) / 255.0); - } - imlib_context_set_color_modifier(NULL); + /* When a particular R/G/B color modifier is changed, this function must be called + to resync the Imlib2 color modifier (imlib_mod) with our new brightness, + contrast, and gamma values. */ + if (cmod->imlib_mod) { + imlib_context_set_color_modifier(cmod->imlib_mod); + imlib_reset_color_modifier(); + } else { + cmod->imlib_mod = imlib_create_color_modifier(); + imlib_context_set_color_modifier(cmod->imlib_mod); + } + if (cmod->brightness != 0x100) { + imlib_modify_color_modifier_brightness((double) (cmod->brightness - 255.0) / 255.0); + } + if (cmod->contrast != 0x100) { + imlib_modify_color_modifier_contrast((double) (cmod->contrast - 255.0) / 255.0); + } + if (cmod->gamma != 0x100) { + imlib_modify_color_modifier_gamma((double) (cmod->gamma - 255.0) / 255.0); + } + imlib_context_set_color_modifier(NULL); } void update_cmod_tables(imlib_t *iml) { - colormod_t *mod = iml->mod, *rmod = iml->rmod, *gmod = iml->gmod, *bmod = iml->bmod; - DATA8 rt[256], gt[256], bt[256]; + colormod_t *mod = iml->mod, *rmod = iml->rmod, *gmod = iml->gmod, *bmod = iml->bmod; + DATA8 rt[256], gt[256], bt[256]; - REQUIRE(mod || rmod || gmod || bmod); + REQUIRE(mod || rmod || gmod || bmod); - /* When any changes is made to any individual color modifier for an image, - this function must be called to update the overall Imlib2 color modifier. */ - D_PIXMAP(("Updating color modifier tables for %8p\n", iml)); - if (!mod) { - mod = iml->mod = create_colormod(); - iml->mod->imlib_mod = imlib_create_color_modifier(); + /* When any changes is made to any individual color modifier for an image, + this function must be called to update the overall Imlib2 color modifier. */ + D_PIXMAP(("Updating color modifier tables for %8p\n", iml)); + if (!mod) { + mod = iml->mod = create_colormod(); + iml->mod->imlib_mod = imlib_create_color_modifier(); + imlib_context_set_color_modifier(mod->imlib_mod); + } else if (!mod->imlib_mod) { + mod->imlib_mod = imlib_create_color_modifier(); + imlib_context_set_color_modifier(mod->imlib_mod); + } else { + imlib_context_set_color_modifier(mod->imlib_mod); + imlib_reset_color_modifier(); + } + imlib_get_color_modifier_tables(rt, gt, bt, NULL); + + if (rmod && rmod->imlib_mod) { + imlib_context_set_color_modifier(rmod->imlib_mod); + imlib_get_color_modifier_tables(rt, NULL, NULL, NULL); + } + if (gmod && gmod->imlib_mod) { + imlib_context_set_color_modifier(gmod->imlib_mod); + imlib_get_color_modifier_tables(NULL, gt, NULL, NULL); + } + if (bmod && bmod->imlib_mod) { + imlib_context_set_color_modifier(bmod->imlib_mod); + imlib_get_color_modifier_tables(NULL, NULL, bt, NULL); + } imlib_context_set_color_modifier(mod->imlib_mod); - } else if (!mod->imlib_mod) { - mod->imlib_mod = imlib_create_color_modifier(); - imlib_context_set_color_modifier(mod->imlib_mod); - } else { - imlib_context_set_color_modifier(mod->imlib_mod); - imlib_reset_color_modifier(); - } - imlib_get_color_modifier_tables(rt, gt, bt, NULL); + imlib_set_color_modifier_tables(rt, gt, bt, NULL); - if (rmod && rmod->imlib_mod) { - imlib_context_set_color_modifier(rmod->imlib_mod); - imlib_get_color_modifier_tables(rt, NULL, NULL, NULL); - } - if (gmod && gmod->imlib_mod) { - imlib_context_set_color_modifier(gmod->imlib_mod); - imlib_get_color_modifier_tables(NULL, gt, NULL, NULL); - } - if (bmod && bmod->imlib_mod) { - imlib_context_set_color_modifier(bmod->imlib_mod); - imlib_get_color_modifier_tables(NULL, NULL, bt, NULL); - } - imlib_context_set_color_modifier(mod->imlib_mod); - imlib_set_color_modifier_tables(rt, gt, bt, NULL); - - if (mod->brightness != 0x100) { - imlib_modify_color_modifier_brightness((double) (mod->brightness - 255.0) / 255.0); - } - if (mod->contrast != 0x100) { - imlib_modify_color_modifier_contrast((double) (mod->contrast - 255.0) / 255.0); - } - if (mod->gamma != 0x100) { - imlib_modify_color_modifier_gamma((double) (mod->gamma - 255.0) / 255.0); - } + if (mod->brightness != 0x100) { + imlib_modify_color_modifier_brightness((double) (mod->brightness - 255.0) / 255.0); + } + if (mod->contrast != 0x100) { + imlib_modify_color_modifier_contrast((double) (mod->contrast - 255.0) / 255.0); + } + if (mod->gamma != 0x100) { + imlib_modify_color_modifier_gamma((double) (mod->gamma - 255.0) / 255.0); + } } # define MOD_IS_SET(mod) ((mod) && ((mod)->brightness != 0x100 || (mod)->contrast != 0x100 || (mod)->gamma != 0x100)) unsigned char need_colormod(register imlib_t *iml) { - if (MOD_IS_SET(iml->mod) || MOD_IS_SET(iml->rmod) || MOD_IS_SET(iml->gmod) || MOD_IS_SET(iml->bmod)) { - D_PIXMAP(("Color modifier active.\n")); - return 1; - } else { - D_PIXMAP(("No color modifier active.\n")); - return 0; - } + if (MOD_IS_SET(iml->mod) || MOD_IS_SET(iml->rmod) || MOD_IS_SET(iml->gmod) || MOD_IS_SET(iml->bmod)) { + D_PIXMAP(("Color modifier active.\n")); + return 1; + } else { + D_PIXMAP(("No color modifier active.\n")); + return 0; + } } /* New optimized routines for tinting XImages written by Willem Monsuwe */ @@ -1446,148 +1556,148 @@ need_colormod(register imlib_t *iml) static void shade_ximage_15(void *data, int bpl, int w, int h, int rm, int gm, int bm) { - unsigned char *ptr; - int x, y; + unsigned char *ptr; + int x, y; - ptr = (unsigned char *)data + (w * sizeof(DATA16)); - if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { - /* No saturation */ - for (y = h; --y >= 0; ) { - for (x = -w; x < 0; x++) { - int r, g, b; - b = ((DATA16 *)ptr)[x]; - r = (b & 0x7c00) * rm; - g = (b & 0x3e0) * gm; - b = (b & 0x1f) * bm; - ((DATA16 *)ptr)[x] = ((r >> 8) & 0x7c00) - | ((g >> 8) & 0x3e0) - | ((b >> 8) & 0x1f); - } - ptr += bpl; + ptr = (unsigned char *) data + (w * sizeof(DATA16)); + if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { + /* No saturation */ + for (y = h; --y >= 0;) { + for (x = -w; x < 0; x++) { + int r, g, b; + b = ((DATA16 *) ptr)[x]; + r = (b & 0x7c00) * rm; + g = (b & 0x3e0) * gm; + b = (b & 0x1f) * bm; + ((DATA16 *) ptr)[x] = ((r >> 8) & 0x7c00) + | ((g >> 8) & 0x3e0) + | ((b >> 8) & 0x1f); + } + ptr += bpl; + } + } else { + for (y = h; --y >= 0;) { + for (x = -w; x < 0; x++) { + int r, g, b; + b = ((DATA16 *) ptr)[x]; + r = (b & 0x7c00) * rm; + g = (b & 0x3e0) * gm; + b = (b & 0x1f) * bm; + r |= (!(r >> 15) - 1); + g |= (!(g >> 10) - 1); + b |= (!(b >> 5) - 1); + ((DATA16 *) ptr)[x] = ((r >> 8) & 0x7c00) + | ((g >> 8) & 0x3e0) + | ((b >> 8) & 0x1f); + } + ptr += bpl; + } } - } else { - for (y = h; --y >= 0; ) { - for (x = -w; x < 0; x++) { - int r, g, b; - b = ((DATA16 *)ptr)[x]; - r = (b & 0x7c00) * rm; - g = (b & 0x3e0) * gm; - b = (b & 0x1f) * bm; - r |= (!(r >> 15) - 1); - g |= (!(g >> 10) - 1); - b |= (!(b >> 5) - 1); - ((DATA16 *)ptr)[x] = ((r >> 8) & 0x7c00) - | ((g >> 8) & 0x3e0) - | ((b >> 8) & 0x1f); - } - ptr += bpl; - } - } } /* RGB 16 */ static void shade_ximage_16(void *data, int bpl, int w, int h, int rm, int gm, int bm) { - unsigned char *ptr; - int x, y; + unsigned char *ptr; + int x, y; - ptr = (unsigned char *)data + (w * sizeof(DATA16)); - if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { - /* No saturation */ - for (y = h; --y >= 0; ) { - for (x = -w; x < 0; x++) { - int r, g, b; - b = ((DATA16 *)ptr)[x]; - r = (b & 0xf800) * rm; - g = (b & 0x7e0) * gm; - b = (b & 0x1f) * bm; - ((DATA16 *)ptr)[x] = ((r >> 8) & 0xf800) - | ((g >> 8) & 0x7e0) - | ((b >> 8) & 0x1f); - } - ptr += bpl; + ptr = (unsigned char *) data + (w * sizeof(DATA16)); + if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { + /* No saturation */ + for (y = h; --y >= 0;) { + for (x = -w; x < 0; x++) { + int r, g, b; + b = ((DATA16 *) ptr)[x]; + r = (b & 0xf800) * rm; + g = (b & 0x7e0) * gm; + b = (b & 0x1f) * bm; + ((DATA16 *) ptr)[x] = ((r >> 8) & 0xf800) + | ((g >> 8) & 0x7e0) + | ((b >> 8) & 0x1f); + } + ptr += bpl; + } + } else { + for (y = h; --y >= 0;) { + for (x = -w; x < 0; x++) { + int r, g, b; + b = ((DATA16 *) ptr)[x]; + r = (b & 0xf800) * rm; + g = (b & 0x7e0) * gm; + b = (b & 0x1f) * bm; + r |= (!(r >> 16) - 1); + g |= (!(g >> 11) - 1); + b |= (!(b >> 5) - 1); + ((DATA16 *) ptr)[x] = ((r >> 8) & 0xf800) + | ((g >> 8) & 0x7e0) + | ((b >> 8) & 0x1f); + } + ptr += bpl; + } } - } else { - for (y = h; --y >= 0; ) { - for (x = -w; x < 0; x++) { - int r, g, b; - b = ((DATA16 *)ptr)[x]; - r = (b & 0xf800) * rm; - g = (b & 0x7e0) * gm; - b = (b & 0x1f) * bm; - r |= (!(r >> 16) - 1); - g |= (!(g >> 11) - 1); - b |= (!(b >> 5) - 1); - ((DATA16 *)ptr)[x] = ((r >> 8) & 0xf800) - | ((g >> 8) & 0x7e0) - | ((b >> 8) & 0x1f); - } - ptr += bpl; - } - } } /* RGB 32 */ static void shade_ximage_32(void *data, int bpl, int w, int h, int rm, int gm, int bm) { - unsigned char *ptr; - int x, y; + unsigned char *ptr; + int x, y; - ptr = (unsigned char *)data + (w * 4); - if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { - /* No saturation */ - for (y = h; --y >= 0; ) { - for (x = -(w * 4); x < 0; x += 4) { - int r, g, b; + ptr = (unsigned char *) data + (w * 4); + if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { + /* No saturation */ + for (y = h; --y >= 0;) { + for (x = -(w * 4); x < 0; x += 4) { + int r, g, b; # ifdef WORDS_BIGENDIAN - r = (ptr[x + 1] * rm) >> 8; - g = (ptr[x + 2] * gm) >> 8; - b = (ptr[x + 3] * bm) >> 8; - ptr[x + 1] = r; - ptr[x + 2] = g; - ptr[x + 3] = b; + r = (ptr[x + 1] * rm) >> 8; + g = (ptr[x + 2] * gm) >> 8; + b = (ptr[x + 3] * bm) >> 8; + ptr[x + 1] = r; + ptr[x + 2] = g; + ptr[x + 3] = b; # else - r = (ptr[x + 2] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 0] * bm) >> 8; - ptr[x + 2] = r; - ptr[x + 1] = g; - ptr[x + 0] = b; + r = (ptr[x + 2] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 0] * bm) >> 8; + ptr[x + 2] = r; + ptr[x + 1] = g; + ptr[x + 0] = b; # endif - } - ptr += bpl; + } + ptr += bpl; + } + } else { + for (y = h; --y >= 0;) { + for (x = -(w * 4); x < 0; x += 4) { + int r, g, b; +# ifdef WORDS_BIGENDIAN + r = (ptr[x + 1] * rm) >> 8; + g = (ptr[x + 2] * gm) >> 8; + b = (ptr[x + 3] * bm) >> 8; +# else + r = (ptr[x + 2] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 0] * bm) >> 8; +# endif + r |= (!(r >> 8) - 1); + g |= (!(g >> 8) - 1); + b |= (!(b >> 8) - 1); +# ifdef WORDS_BIGENDIAN + ptr[x + 1] = r; + ptr[x + 2] = g; + ptr[x + 3] = b; +# else + ptr[x + 2] = r; + ptr[x + 1] = g; + ptr[x + 0] = b; +# endif + } + ptr += bpl; + } } - } else { - for (y = h; --y >= 0; ) { - for (x = -(w * 4); x < 0; x += 4) { - int r, g, b; -# ifdef WORDS_BIGENDIAN - r = (ptr[x + 1] * rm) >> 8; - g = (ptr[x + 2] * gm) >> 8; - b = (ptr[x + 3] * bm) >> 8; -# else - r = (ptr[x + 2] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 0] * bm) >> 8; -# endif - r |= (!(r >> 8) - 1); - g |= (!(g >> 8) - 1); - b |= (!(b >> 8) - 1); -# ifdef WORDS_BIGENDIAN - ptr[x + 1] = r; - ptr[x + 2] = g; - ptr[x + 3] = b; -# else - ptr[x + 2] = r; - ptr[x + 1] = g; - ptr[x + 0] = b; -# endif - } - ptr += bpl; - } - } } #endif @@ -1595,62 +1705,62 @@ shade_ximage_32(void *data, int bpl, int w, int h, int rm, int gm, int bm) static void shade_ximage_24(void *data, int bpl, int w, int h, int rm, int gm, int bm) { - unsigned char *ptr; - int x, y; + unsigned char *ptr; + int x, y; - ptr = (unsigned char *)data + (w * 3); - if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { - /* No saturation */ - for (y = h; --y >= 0; ) { - for (x = -(w * 3); x < 0; x += 3) { - int r, g, b; + ptr = (unsigned char *) data + (w * 3); + if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { + /* No saturation */ + for (y = h; --y >= 0;) { + for (x = -(w * 3); x < 0; x += 3) { + int r, g, b; # ifdef WORDS_BIGENDIAN - r = (ptr[x + 0] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 2] * bm) >> 8; - ptr[x + 0] = r; - ptr[x + 1] = g; - ptr[x + 2] = b; + r = (ptr[x + 0] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 2] * bm) >> 8; + ptr[x + 0] = r; + ptr[x + 1] = g; + ptr[x + 2] = b; # else - r = (ptr[x + 2] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 0] * bm) >> 8; - ptr[x + 2] = r; - ptr[x + 1] = g; - ptr[x + 0] = b; + r = (ptr[x + 2] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 0] * bm) >> 8; + ptr[x + 2] = r; + ptr[x + 1] = g; + ptr[x + 0] = b; # endif - } - ptr += bpl; + } + ptr += bpl; + } + } else { + for (y = h; --y >= 0;) { + for (x = -(w * 3); x < 0; x += 3) { + int r, g, b; +# ifdef WORDS_BIGENDIAN + r = (ptr[x + 0] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 2] * bm) >> 8; +# else + r = (ptr[x + 2] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 0] * bm) >> 8; +# endif + r |= (!(r >> 8) - 1); + g |= (!(g >> 8) - 1); + b |= (!(b >> 8) - 1); +# ifdef WORDS_BIGENDIAN + ptr[x + 0] = r; + ptr[x + 1] = g; + ptr[x + 2] = b; +# else + ptr[x + 2] = r; + ptr[x + 1] = g; + ptr[x + 0] = b; +# endif + } + ptr += bpl; + } } - } else { - for (y = h; --y >= 0; ) { - for (x = -(w * 3); x < 0; x += 3) { - int r, g, b; -# ifdef WORDS_BIGENDIAN - r = (ptr[x + 0] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 2] * bm) >> 8; -# else - r = (ptr[x + 2] * rm) >> 8; - g = (ptr[x + 1] * gm) >> 8; - b = (ptr[x + 0] * bm) >> 8; -# endif - r |= (!(r >> 8) - 1); - g |= (!(g >> 8) - 1); - b |= (!(b >> 8) - 1); -# ifdef WORDS_BIGENDIAN - ptr[x + 0] = r; - ptr[x + 1] = g; - ptr[x + 2] = b; -# else - ptr[x + 2] = r; - ptr[x + 1] = g; - ptr[x + 0] = b; -# endif - } - ptr += bpl; - } - } } # ifdef PIXMAP_OFFSET @@ -1658,481 +1768,486 @@ void colormod_trans(Pixmap p, imlib_t *iml, GC gc, unsigned short w, unsigned short h) { - XImage *ximg; - register unsigned long i; + XImage *ximg; + register unsigned long i; #if 0 - register unsigned long v; - unsigned long x, y; - int r, g, b; - register int br, bg, bb; - register unsigned int mr, mg, mb; + register unsigned long v; + unsigned long x, y; + int r, g, b; + register int br, bg, bb; + register unsigned int mr, mg, mb; #endif - unsigned short rm, gm, bm, shade; - Imlib_Color ctab[256]; - int real_depth = 0; + unsigned short rm, gm, bm, shade; + Imlib_Color ctab[256]; + int real_depth = 0; - D_PIXMAP(("colormod_trans(p == 0x%08x, gc, w == %hu, h == %hu) called.\n", p, w, h)); - REQUIRE(p != None); + D_PIXMAP(("colormod_trans(p == 0x%08x, gc, w == %hu, h == %hu) called.\n", p, w, h)); + REQUIRE(p != None); - if (iml->mod) { - shade = iml->mod->brightness; - } else { - shade = 256; - } - if (iml->rmod) { - rm = (iml->rmod->brightness * shade) >> 8; - } else { - rm = shade; - } - if (iml->gmod) { - gm = (iml->gmod->brightness * shade) >> 8; - } else { - gm = shade; - } - if (iml->bmod) { - bm = (iml->bmod->brightness * shade) >> 8; - } else { - bm = shade; - } - - if (rm == 256 && gm == 256 && bm == 256) { - return; /* Nothing to do */ - } - D_PIXMAP((" -> rm == %hu, gm == %hu, bm == %hu, shade == %hu\n", rm, gm, bm, shade)); - - if (Xdepth <= 8) { - - XColor cols[256]; - - for (i = 0; i < (unsigned long) (1 << Xdepth); i++) { - cols[i].pixel = i; - cols[i].flags = DoRed | DoGreen | DoBlue; + if (iml->mod) { + shade = iml->mod->brightness; + } else { + shade = 256; } - XQueryColors(Xdisplay, cmap, cols, 1 << Xdepth); - for (i = 0; i < (unsigned long) (1 << Xdepth); i++) { - ctab[i].red = cols[i].red >> 8; - ctab[i].green = cols[i].green >> 8; - ctab[i].blue = cols[i].blue >> 8; + if (iml->rmod) { + rm = (iml->rmod->brightness * shade) >> 8; + } else { + rm = shade; + } + if (iml->gmod) { + gm = (iml->gmod->brightness * shade) >> 8; + } else { + gm = shade; + } + if (iml->bmod) { + bm = (iml->bmod->brightness * shade) >> 8; + } else { + bm = shade; } - } else if (Xdepth == 16) { - XWindowAttributes xattr; + if (rm == 256 && gm == 256 && bm == 256) { + return; /* Nothing to do */ + } + D_PIXMAP((" -> rm == %hu, gm == %hu, bm == %hu, shade == %hu\n", rm, gm, bm, shade)); - XGetWindowAttributes(Xdisplay, desktop_window, &xattr); - if ((xattr.visual->green_mask == 0x3e0)) { - real_depth = 15; - } - } - if (!real_depth) { - real_depth = Xdepth; - } - ximg = XGetImage(Xdisplay, p, 0, 0, w, h, -1, ZPixmap); - if (ximg == NULL) { - print_warning("XGetImage(Xdisplay, 0x%08x, 0, 0, %d, %d, -1, ZPixmap) returned NULL.\n", p, w, h); - return; - } - D_PIXMAP(("XGetImage(Xdisplay, 0x%08x, 0, 0, %d, %d, -1, ZPixmap) returned %8p.\n", p, w, h, ximg)); - if (Xdepth <= 8) { -#if FIXME_BLOCK - D_PIXMAP(("Rendering low-depth image, depth == %d\n", (int) Xdepth)); - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { - v = XGetPixel(ximg, x, y); - r = (ctab[v & 0xff].r * rm) >> 8; - g = (ctab[v & 0xff].g * gm) >> 8; - b = (ctab[v & 0xff].b * bm) >> 8; - v = Imlib_best_color_match(imlib_id, &r, &g, &b); - XPutPixel(ximg, x, y, v); - } - } -#endif - } else { - D_PIXMAP(("Rendering high-depth image, depth == %d\n", real_depth)); - /* Swap rm and bm for bgr */ - { - XWindowAttributes xattr; - XGetWindowAttributes(Xdisplay, desktop_window, &xattr); - if (xattr.visual->blue_mask > xattr.visual->red_mask) { - unsigned short tmp; - tmp = rm; - rm = bm; - bm = tmp; - } - } - /* Determine bitshift and bitmask values */ - switch (real_depth) { - case 15: -#ifdef HAVE_MMX - shade_ximage_15_mmx(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); -#else - shade_ximage_15(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); -#endif - break; - case 16: -#ifdef HAVE_MMX - shade_ximage_16_mmx(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); -#else - shade_ximage_16(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); -#endif - break; - case 24: - if (ximg->bits_per_pixel != 32) { - shade_ximage_24(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); + if (Xdepth <= 8) { + + XColor cols[256]; + + for (i = 0; i < (unsigned long) (1 << Xdepth); i++) { + cols[i].pixel = i; + cols[i].flags = DoRed | DoGreen | DoBlue; + } + XQueryColors(Xdisplay, cmap, cols, 1 << Xdepth); + for (i = 0; i < (unsigned long) (1 << Xdepth); i++) { + ctab[i].red = cols[i].red >> 8; + ctab[i].green = cols[i].green >> 8; + ctab[i].blue = cols[i].blue >> 8; + } + } else if (Xdepth == 16) { + + XWindowAttributes xattr; + + XGetWindowAttributes(Xdisplay, desktop_window, &xattr); + if ((xattr.visual->green_mask == 0x3e0)) { + real_depth = 15; } - /* drop */ - case 32: -#ifdef HAVE_MMX - shade_ximage_32_mmx(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); -#else - shade_ximage_32(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); -#endif - break; - default: - print_warning("Bit depth of %d is unsupported for tinting/shading.\n", real_depth); - return; } - } - XPutImage(Xdisplay, p, gc, ximg, 0, 0, 0, 0, w, h); - XDestroyImage(ximg); + if (!real_depth) { + real_depth = Xdepth; + } + ximg = XGetImage(Xdisplay, p, 0, 0, w, h, -1, ZPixmap); + if (ximg == NULL) { + print_warning("XGetImage(Xdisplay, 0x%08x, 0, 0, %d, %d, -1, ZPixmap) returned NULL.\n", p, w, h); + return; + } + D_PIXMAP(("XGetImage(Xdisplay, 0x%08x, 0, 0, %d, %d, -1, ZPixmap) returned %8p.\n", p, w, h, ximg)); + if (Xdepth <= 8) { +#if FIXME_BLOCK + D_PIXMAP(("Rendering low-depth image, depth == %d\n", (int) Xdepth)); + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + v = XGetPixel(ximg, x, y); + r = (ctab[v & 0xff].r * rm) >> 8; + g = (ctab[v & 0xff].g * gm) >> 8; + b = (ctab[v & 0xff].b * bm) >> 8; + v = Imlib_best_color_match(imlib_id, &r, &g, &b); + XPutPixel(ximg, x, y, v); + } + } +#endif + } else { + D_PIXMAP(("Rendering high-depth image, depth == %d\n", real_depth)); + /* Swap rm and bm for bgr */ + { + XWindowAttributes xattr; + XGetWindowAttributes(Xdisplay, desktop_window, &xattr); + if (xattr.visual->blue_mask > xattr.visual->red_mask) { + unsigned short tmp; + tmp = rm; + rm = bm; + bm = tmp; + } + } + /* Determine bitshift and bitmask values */ + switch (real_depth) { + case 15: +#ifdef HAVE_MMX + shade_ximage_15_mmx(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); +#else + shade_ximage_15(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); +#endif + break; + case 16: +#ifdef HAVE_MMX + shade_ximage_16_mmx(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); +#else + shade_ximage_16(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); +#endif + break; + case 24: + if (ximg->bits_per_pixel != 32) { + shade_ximage_24(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); + } + /* drop */ + case 32: +#ifdef HAVE_MMX + shade_ximage_32_mmx(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); +#else + shade_ximage_32(ximg->data, ximg->bytes_per_line, w, h, rm, gm, bm); +#endif + break; + default: + print_warning("Bit depth of %d is unsupported for tinting/shading.\n", real_depth); + return; + } + } + XPutImage(Xdisplay, p, gc, ximg, 0, 0, 0, 0, w, h); + XDestroyImage(ximg); } unsigned char update_desktop_info(int *w, int *h) { - unsigned int pw, ph, pb, pd; - int px, py; - Window dummy; + unsigned int pw, ph, pb, pd; + int px, py; + Window dummy; - if (w) { - *w = 0; - } - if (h) { - *h = 0; - } - if (desktop_window == None) { - get_desktop_window(); - } - if (desktop_window == None) { - print_error("Unable to locate desktop window. If you are running Enlightenment, please\n" - "restart. If not, please set your background image with Esetroot, then try again."); - return 0; - } - if (desktop_pixmap == None) { - get_desktop_pixmap(); - } - if (desktop_pixmap == None) { - return 0; - } - XGetGeometry(Xdisplay, desktop_pixmap, &dummy, &px, &py, &pw, &ph, &pb, &pd); - if ((pw <= 0) || (ph <= 0)) { - /* Reset and try again. */ - get_desktop_window(); - get_desktop_pixmap(); + if (w) { + *w = 0; + } + if (h) { + *h = 0; + } + if (desktop_window == None) { + get_desktop_window(); + } + if (desktop_window == None) { + print_error("Unable to locate desktop window. If you are running Enlightenment, please\n" + "restart. If not, please set your background image with Esetroot, then try again."); + return 0; + } + if (desktop_pixmap == None) { + get_desktop_pixmap(); + } + if (desktop_pixmap == None) { + return 0; + } XGetGeometry(Xdisplay, desktop_pixmap, &dummy, &px, &py, &pw, &ph, &pb, &pd); - } - if ((pw <= 0) || (ph <= 0)) { - print_error("Value of desktop pixmap property is invalid. Please restart your \n" - "window manager or use Esetroot to set a new one."); - desktop_pixmap = None; - return 0; - } - if (w) { - *w = pw; - } - if (h) { - *h = ph; - } - return 1; + if ((pw <= 0) || (ph <= 0)) { + /* Reset and try again. */ + get_desktop_window(); + get_desktop_pixmap(); + XGetGeometry(Xdisplay, desktop_pixmap, &dummy, &px, &py, &pw, &ph, &pb, &pd); + } + if ((pw <= 0) || (ph <= 0)) { + print_error("Value of desktop pixmap property is invalid. Please restart your \n" + "window manager or use Esetroot to set a new one."); + desktop_pixmap = None; + return 0; + } + if (w) { + *w = pw; + } + if (h) { + *h = ph; + } + return 1; } Window get_desktop_window(void) { - Atom type; - int format; - unsigned long length, after; - unsigned char *data; - unsigned int nchildren; - Window w, root, *children, parent; + Atom type; + int format; + unsigned long length, after; + unsigned char *data; + unsigned int nchildren; + Window w, root, *children, parent; - D_PIXMAP(("Current desktop window is 0x%08x\n", (unsigned int) desktop_window)); - if ((desktop_window != None) && (desktop_window != Xroot)) { - XSelectInput(Xdisplay, desktop_window, None); - } - - for (w = TermWin.parent; w; w = parent) { - - D_PIXMAP((" Current window ID is: 0x%08x\n", w)); - - if ((XQueryTree(Xdisplay, w, &root, &parent, &children, &nchildren)) == False) { - D_PIXMAP((" Egad! XQueryTree() returned false!\n")); - return None; - } - D_PIXMAP((" Window is 0x%08x with %d children, root is 0x%08x, parent is 0x%08x\n", - w, nchildren, root, parent)); - if (nchildren) { - XFree(children); + D_PIXMAP(("Current desktop window is 0x%08x\n", (unsigned int) desktop_window)); + if ((desktop_window != None) && (desktop_window != Xroot)) { + XSelectInput(Xdisplay, desktop_window, None); } + for (w = TermWin.parent; w; w = parent) { - if ((XGetWindowProperty(Xdisplay, w, props[PROP_TRANS_PIXMAP], 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data)) != Success) { - if ((XGetWindowProperty(Xdisplay, w, props[PROP_TRANS_COLOR], 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data)) != Success) { - continue; - } - } - XFree(data); - if (type != None) { - D_PIXMAP(("Found desktop as window 0x%08x\n", w)); - if (w != Xroot) { - XSelectInput(Xdisplay, w, PropertyChangeMask); - } - if (desktop_window == w) { - D_PIXMAP((" Desktop window has not changed.\n")); - return ((Window) 1); - } else { - D_PIXMAP((" Desktop window has changed Updating desktop_window.\n")); - return (desktop_window = w); - } - } - } + D_PIXMAP((" Current window ID is: 0x%08x\n", w)); - D_PIXMAP(("No suitable parent found.\n")); - return (desktop_window = None); + if ((XQueryTree(Xdisplay, w, &root, &parent, &children, &nchildren)) == False) { + D_PIXMAP((" Egad! XQueryTree() returned false!\n")); + return None; + } + D_PIXMAP((" Window is 0x%08x with %d children, root is 0x%08x, parent is 0x%08x\n", w, nchildren, root, parent)); + if (nchildren) { + XFree(children); + } + + + if ((XGetWindowProperty + (Xdisplay, w, props[PROP_TRANS_PIXMAP], 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data)) != Success) { + if ((XGetWindowProperty + (Xdisplay, w, props[PROP_TRANS_COLOR], 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, + &data)) != Success) { + continue; + } + } + XFree(data); + if (type != None) { + D_PIXMAP(("Found desktop as window 0x%08x\n", w)); + if (w != Xroot) { + XSelectInput(Xdisplay, w, PropertyChangeMask); + } + if (desktop_window == w) { + D_PIXMAP((" Desktop window has not changed.\n")); + return ((Window) 1); + } else { + D_PIXMAP((" Desktop window has changed Updating desktop_window.\n")); + return (desktop_window = w); + } + } + } + + D_PIXMAP(("No suitable parent found.\n")); + return (desktop_window = None); } Pixmap get_desktop_pixmap(void) { - Pixmap p; - Atom type; - int format; - static Pixmap color_pixmap = None, orig_desktop_pixmap; - unsigned long length, after; - unsigned char *data; + Pixmap p; + Atom type; + int format; + static Pixmap color_pixmap = None, orig_desktop_pixmap; + unsigned long length, after; + unsigned char *data; - D_PIXMAP(("Current desktop pixmap is 0x%08x\n", (unsigned int) desktop_pixmap)); - if (desktop_pixmap == None) { - orig_desktop_pixmap = None; /* Forced re-read. */ - } - if (desktop_window == None) { - D_PIXMAP(("No desktop window. Aborting.\n")); - free_desktop_pixmap(); - return (None); - } - - if (color_pixmap != None) { - D_PIXMAP(("Removing old solid color pixmap 0x%08x.\n", color_pixmap)); - LIBAST_X_FREE_PIXMAP(color_pixmap); - color_pixmap = None; - } - XGetWindowProperty(Xdisplay, desktop_window, props[PROP_TRANS_PIXMAP], 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data); - if (type == XA_PIXMAP) { - p = *((Pixmap *) data); - XFree(data); - if (p != None) { - D_PIXMAP((" Found pixmap 0x%08x\n", p)); - if (orig_desktop_pixmap == p) { - D_PIXMAP(("Desktop pixmap is unchanged.\n")); - return ((Pixmap) 1); - } else { - D_PIXMAP(("Desktop pixmap has changed. Updating desktop_pixmap\n")); - free_desktop_pixmap(); - orig_desktop_pixmap = p; - if (!(image_toggles & IMOPT_ITRANS) && need_colormod(images[image_bg].current->iml)) { - int px, py; - unsigned int pw, ph, pb, pd; - Window w; - GC gc; - XGCValues gcvalue; - Screen *scr = ScreenOfDisplay(Xdisplay, Xscreen); - - gcvalue.foreground = gcvalue.background = PixColors[bgColor]; - gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground, &gcvalue); - XGetGeometry(Xdisplay, p, &w, &px, &py, &pw, &ph, &pb, &pd); - D_PIXMAP(("XGetGeometry() returned w = 0x%08x, pw == %u, ph == %u\n", w, pw, ph)); - if (pw < (unsigned int) scr->width || ph < (unsigned int) scr->height) { - desktop_pixmap = LIBAST_X_CREATE_PIXMAP(pw, ph); - XCopyArea(Xdisplay, p, desktop_pixmap, gc, 0, 0, pw, ph, 0, 0); - colormod_trans(desktop_pixmap, images[image_bg].current->iml, gc, pw, ph); - } else { - desktop_pixmap = LIBAST_X_CREATE_PIXMAP(scr->width, scr->height); - XCopyArea(Xdisplay, p, desktop_pixmap, gc, 0, 0, scr->width, scr->height, 0, 0); - colormod_trans(desktop_pixmap, images[image_bg].current->iml, gc, scr->width, scr->height); - } - LIBAST_X_FREE_GC(gc); - desktop_pixmap_is_mine = 1; - D_PIXMAP(("Returning 0x%08x\n", (unsigned int) desktop_pixmap)); - return (desktop_pixmap); - } else { - desktop_pixmap_is_mine = 0; - D_PIXMAP(("Returning 0x%08x\n", (unsigned int) p)); - return (desktop_pixmap = p); - } - } + D_PIXMAP(("Current desktop pixmap is 0x%08x\n", (unsigned int) desktop_pixmap)); + if (desktop_pixmap == None) { + orig_desktop_pixmap = None; /* Forced re-read. */ + } + if (desktop_window == None) { + D_PIXMAP(("No desktop window. Aborting.\n")); + free_desktop_pixmap(); + return (None); } - } else { - XFree(data); - } - XGetWindowProperty(Xdisplay, desktop_window, props[PROP_TRANS_COLOR], 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data); - if (type == XA_CARDINAL) { - XGCValues gcvalue; - GC gc; - Pixel pix; + if (color_pixmap != None) { + D_PIXMAP(("Removing old solid color pixmap 0x%08x.\n", color_pixmap)); + LIBAST_X_FREE_PIXMAP(color_pixmap); + color_pixmap = None; + } + XGetWindowProperty(Xdisplay, desktop_window, props[PROP_TRANS_PIXMAP], 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, + &data); + if (type == XA_PIXMAP) { + p = *((Pixmap *) data); + XFree(data); + if (p != None) { + D_PIXMAP((" Found pixmap 0x%08x\n", p)); + if (orig_desktop_pixmap == p) { + D_PIXMAP(("Desktop pixmap is unchanged.\n")); + return ((Pixmap) 1); + } else { + D_PIXMAP(("Desktop pixmap has changed. Updating desktop_pixmap\n")); + free_desktop_pixmap(); + orig_desktop_pixmap = p; + if (!(image_toggles & IMOPT_ITRANS) && need_colormod(images[image_bg].current->iml)) { + int px, py; + unsigned int pw, ph, pb, pd; + Window w; + GC gc; + XGCValues gcvalue; + Screen *scr = ScreenOfDisplay(Xdisplay, Xscreen); + + gcvalue.foreground = gcvalue.background = PixColors[bgColor]; + gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground, &gcvalue); + XGetGeometry(Xdisplay, p, &w, &px, &py, &pw, &ph, &pb, &pd); + D_PIXMAP(("XGetGeometry() returned w = 0x%08x, pw == %u, ph == %u\n", w, pw, ph)); + if (pw < (unsigned int) scr->width || ph < (unsigned int) scr->height) { + desktop_pixmap = LIBAST_X_CREATE_PIXMAP(pw, ph); + XCopyArea(Xdisplay, p, desktop_pixmap, gc, 0, 0, pw, ph, 0, 0); + colormod_trans(desktop_pixmap, images[image_bg].current->iml, gc, pw, ph); + } else { + desktop_pixmap = LIBAST_X_CREATE_PIXMAP(scr->width, scr->height); + XCopyArea(Xdisplay, p, desktop_pixmap, gc, 0, 0, scr->width, scr->height, 0, 0); + colormod_trans(desktop_pixmap, images[image_bg].current->iml, gc, scr->width, scr->height); + } + LIBAST_X_FREE_GC(gc); + desktop_pixmap_is_mine = 1; + D_PIXMAP(("Returning 0x%08x\n", (unsigned int) desktop_pixmap)); + return (desktop_pixmap); + } else { + desktop_pixmap_is_mine = 0; + D_PIXMAP(("Returning 0x%08x\n", (unsigned int) p)); + return (desktop_pixmap = p); + } + } + } + } else { + XFree(data); + } + XGetWindowProperty(Xdisplay, desktop_window, props[PROP_TRANS_COLOR], 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, + &data); + if (type == XA_CARDINAL) { + XGCValues gcvalue; + GC gc; + Pixel pix; + + free_desktop_pixmap(); + pix = *((Pixel *) data); + XFree(data); + D_PIXMAP((" Found solid color 0x%08x\n", pix)); + gcvalue.foreground = pix; + gcvalue.background = pix; + gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground, &gcvalue); + + color_pixmap = LIBAST_X_CREATE_PIXMAP(16, 16); + XFillRectangle(Xdisplay, color_pixmap, gc, 0, 0, 16, 16); + D_PIXMAP(("Created solid color pixmap 0x%08x for desktop_pixmap.\n", color_pixmap)); + LIBAST_X_FREE_GC(gc); + return (desktop_pixmap = color_pixmap); + } else { + XFree(data); + } + D_PIXMAP(("No suitable attribute found.\n")); free_desktop_pixmap(); - pix = *((Pixel *) data); - XFree(data); - D_PIXMAP((" Found solid color 0x%08x\n", pix)); - gcvalue.foreground = pix; - gcvalue.background = pix; - gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground, &gcvalue); - - color_pixmap = LIBAST_X_CREATE_PIXMAP(16, 16); - XFillRectangle(Xdisplay, color_pixmap, gc, 0, 0, 16, 16); - D_PIXMAP(("Created solid color pixmap 0x%08x for desktop_pixmap.\n", color_pixmap)); - LIBAST_X_FREE_GC(gc); - return (desktop_pixmap = color_pixmap); - } else { - XFree(data); - } - D_PIXMAP(("No suitable attribute found.\n")); - free_desktop_pixmap(); - return (desktop_pixmap = None); + return (desktop_pixmap = None); } void free_desktop_pixmap(void) { - if (desktop_pixmap_is_mine && desktop_pixmap != None) { - LIBAST_X_FREE_PIXMAP(desktop_pixmap); - desktop_pixmap_is_mine = 0; - } - desktop_pixmap = None; + if (desktop_pixmap_is_mine && desktop_pixmap != None) { + LIBAST_X_FREE_PIXMAP(desktop_pixmap); + desktop_pixmap_is_mine = 0; + } + desktop_pixmap = None; } -# endif /* PIXMAP_OFFSET */ +# endif /* PIXMAP_OFFSET */ void shaped_window_apply_mask(Drawable d, Pixmap mask) { - static signed char have_shape = -1; + static signed char have_shape = -1; - REQUIRE(d != None); - REQUIRE(mask != None); + REQUIRE(d != None); + REQUIRE(mask != None); - D_PIXMAP(("shaped_window_apply_mask(d [0x%08x], mask [0x%08x]) called.\n", d, mask)); + D_PIXMAP(("shaped_window_apply_mask(d [0x%08x], mask [0x%08x]) called.\n", d, mask)); # ifdef HAVE_X_SHAPE_EXT - if (have_shape == -1) { /* Don't know yet. */ - int unused; + if (have_shape == -1) { /* Don't know yet. */ + int unused; - D_PIXMAP(("Looking for shape extension.\n")); - if (XQueryExtension(Xdisplay, "SHAPE", &unused, &unused, &unused)) { - have_shape = 1; - } else { - have_shape = 0; + D_PIXMAP(("Looking for shape extension.\n")); + if (XQueryExtension(Xdisplay, "SHAPE", &unused, &unused, &unused)) { + have_shape = 1; + } else { + have_shape = 0; + } + } + if (have_shape == 1) { + D_PIXMAP(("Shape extension available, applying mask.\n")); + XShapeCombineMask(Xdisplay, d, ShapeBounding, 0, 0, mask, ShapeSet); + } else if (have_shape == 0) { + D_PIXMAP(("Shape extension not available.\n")); + return; } - } - if (have_shape == 1) { - D_PIXMAP(("Shape extension available, applying mask.\n")); - XShapeCombineMask(Xdisplay, d, ShapeBounding, 0, 0, mask, ShapeSet); - } else if (have_shape == 0) { - D_PIXMAP(("Shape extension not available.\n")); - return; - } # else - D_PIXMAP(("Shape support disabled.\n")); + D_PIXMAP(("Shape support disabled.\n")); # endif } void set_icon_pixmap(char *filename, XWMHints * pwm_hints) { - const char *icon_path; - Imlib_Image temp_im = (Imlib_Image) NULL; - Imlib_Load_Error im_err; - Imlib_Color_Modifier tmp_cmod; - XWMHints *wm_hints; - int w = 8, h = 8; + const char *icon_path; + Imlib_Image temp_im = (Imlib_Image) NULL; + Imlib_Load_Error im_err; + Imlib_Color_Modifier tmp_cmod; + XWMHints *wm_hints; + int w = 8, h = 8; - if (pwm_hints) { - wm_hints = pwm_hints; - } else { - wm_hints = XGetWMHints(Xdisplay, TermWin.parent); - } - - /* Make sure no shading/tinting is applied to the icon. */ - tmp_cmod = imlib_create_color_modifier(); - imlib_context_set_color_modifier(tmp_cmod); - imlib_reset_color_modifier(); - - if (filename && *filename) { - if ((icon_path = search_path(rs_path, filename)) == NULL) - icon_path = search_path(getenv(PATH_ENV), filename); - - if (icon_path != NULL) { - XIconSize *icon_sizes; - int count, i; - - temp_im = imlib_load_image_with_error_return(filename, &im_err); - if (temp_im == NULL) { - print_error("Unable to load icon file \"%s\" -- %s\n", filename, imlib_strerror(im_err)); - } else { - /* If we're going to render the image anyway, might as well be nice and give it to the WM in a size it likes. */ - if (XGetIconSizes(Xdisplay, Xroot, &icon_sizes, &count)) { - for (i = 0; i < count; i++) { - D_PIXMAP(("Got icon sizes: Width %d to %d +/- %d, Height %d to %d +/- %d\n", icon_sizes[i].min_width, icon_sizes[i].max_width, - icon_sizes[i].width_inc, icon_sizes[i].min_height, icon_sizes[i].max_height, icon_sizes[i].height_inc)); - if (icon_sizes[i].max_width > 64 || icon_sizes[i].max_height > 64) { - continue; - } - /* Find the largest supported size <= 64 */ - w = MAX(icon_sizes[i].max_width, w); - h = MAX(icon_sizes[i].max_height, h); - } - fflush(stdout); - XFree(icon_sizes); - } else { - w = h = 48; - } - BOUND(w, 8, 64); - BOUND(h, 8, 64); - imlib_context_set_image(temp_im); - } + if (pwm_hints) { + wm_hints = pwm_hints; + } else { + wm_hints = XGetWMHints(Xdisplay, TermWin.parent); } - } - if (temp_im == NULL) { - w = h = 48; - temp_im = imlib_create_image_using_data(48, 48, (DATA32 *) icon_data); - imlib_context_set_image(temp_im); - imlib_image_set_has_alpha(1); - } - imlib_context_set_drawable(TermWin.parent); - imlib_context_set_anti_alias(1); - imlib_context_set_dither(1); - imlib_context_set_blend(0); - imlib_render_pixmaps_for_whole_image_at_size(&wm_hints->icon_pixmap, &wm_hints->icon_mask, w, h); - if (check_for_enlightenment()) { - wm_hints->flags |= IconPixmapHint | IconMaskHint; - } else { - wm_hints->icon_window = XCreateSimpleWindow(Xdisplay, TermWin.parent, 0, 0, w, h, 0, 0L, 0L); - shaped_window_apply_mask(wm_hints->icon_window, wm_hints->icon_mask); - XSetWindowBackgroundPixmap(Xdisplay, wm_hints->icon_window, wm_hints->icon_pixmap); - wm_hints->flags |= IconWindowHint; - } - imlib_free_image_and_decache(); + /* Make sure no shading/tinting is applied to the icon. */ + tmp_cmod = imlib_create_color_modifier(); + imlib_context_set_color_modifier(tmp_cmod); + imlib_reset_color_modifier(); - wm_hints->icon_x = wm_hints->icon_y = 0; - wm_hints->flags |= IconPositionHint; + if (filename && *filename) { + if ((icon_path = search_path(rs_path, filename)) == NULL) + icon_path = search_path(getenv(PATH_ENV), filename); - /* Only set the hints ourselves if we were passed a NULL pointer for pwm_hints */ - if (!pwm_hints) { - XSetWMHints(Xdisplay, TermWin.parent, wm_hints); - XFree(wm_hints); - } + if (icon_path != NULL) { + XIconSize *icon_sizes; + int count, i; + + temp_im = imlib_load_image_with_error_return(filename, &im_err); + if (temp_im == NULL) { + print_error("Unable to load icon file \"%s\" -- %s\n", filename, imlib_strerror(im_err)); + } else { + /* If we're going to render the image anyway, might as well be nice and give it to the WM in a size it likes. */ + if (XGetIconSizes(Xdisplay, Xroot, &icon_sizes, &count)) { + for (i = 0; i < count; i++) { + D_PIXMAP(("Got icon sizes: Width %d to %d +/- %d, Height %d to %d +/- %d\n", icon_sizes[i].min_width, + icon_sizes[i].max_width, icon_sizes[i].width_inc, icon_sizes[i].min_height, icon_sizes[i].max_height, + icon_sizes[i].height_inc)); + if (icon_sizes[i].max_width > 64 || icon_sizes[i].max_height > 64) { + continue; + } + /* Find the largest supported size <= 64 */ + w = MAX(icon_sizes[i].max_width, w); + h = MAX(icon_sizes[i].max_height, h); + } + fflush(stdout); + XFree(icon_sizes); + } else { + w = h = 48; + } + BOUND(w, 8, 64); + BOUND(h, 8, 64); + imlib_context_set_image(temp_im); + } + } + } + + if (temp_im == NULL) { + w = h = 48; + temp_im = imlib_create_image_using_data(48, 48, (DATA32 *) icon_data); + imlib_context_set_image(temp_im); + imlib_image_set_has_alpha(1); + } + imlib_context_set_drawable(TermWin.parent); + imlib_context_set_anti_alias(1); + imlib_context_set_dither(1); + imlib_context_set_blend(0); + imlib_render_pixmaps_for_whole_image_at_size(&wm_hints->icon_pixmap, &wm_hints->icon_mask, w, h); + if (check_for_enlightenment()) { + wm_hints->flags |= IconPixmapHint | IconMaskHint; + } else { + wm_hints->icon_window = XCreateSimpleWindow(Xdisplay, TermWin.parent, 0, 0, w, h, 0, 0L, 0L); + shaped_window_apply_mask(wm_hints->icon_window, wm_hints->icon_mask); + XSetWindowBackgroundPixmap(Xdisplay, wm_hints->icon_window, wm_hints->icon_pixmap); + wm_hints->flags |= IconWindowHint; + } + imlib_free_image_and_decache(); + + wm_hints->icon_x = wm_hints->icon_y = 0; + wm_hints->flags |= IconPositionHint; + + /* Only set the hints ourselves if we were passed a NULL pointer for pwm_hints */ + if (!pwm_hints) { + XSetWMHints(Xdisplay, TermWin.parent, wm_hints); + XFree(wm_hints); + } } #endif /* PIXMAP_SUPPORT */ diff --git a/src/scream.h b/src/scream.h new file mode 100644 index 0000000..3bab209 --- /dev/null +++ b/src/scream.h @@ -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 */ +} _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 *)); + + + +/***************************************************************************/ diff --git a/src/screamcfg.h b/src/screamcfg.h new file mode 100644 index 0000000..c5d20f9 --- /dev/null +++ b/src/screamcfg.h @@ -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 + + + +/***************************************************************************/ diff --git a/src/screen.c b/src/screen.c index c93f688..cc2ba36 100644 --- a/src/screen.c +++ b/src/screen.c @@ -25,7 +25,7 @@ static const char cvs_ident[] = "$Id$"; #include #include #include -#include /* CARD32 */ +#include /* CARD32 */ #ifdef HAVE_X11_XMU_ATOMS_H # include #endif @@ -52,32 +52,27 @@ static rend_t **buf_rend = NULL; /* Tab stop locations */ static char *tabs = NULL; -static screen_t screen = -{ - NULL, NULL, 0, 0, 0, 0, 0, Screen_DefaultFlags +static screen_t screen = { + NULL, NULL, 0, 0, 0, 0, 0, Screen_DefaultFlags }; -static screen_t swap = -{ - NULL, NULL, 0, 0, 0, 0, 0, Screen_DefaultFlags +static screen_t swap = { + NULL, NULL, 0, 0, 0, 0, 0, Screen_DefaultFlags }; -static save_t save = -{ - 0, 0, 0, 'B', DEFAULT_RSTYLE +static save_t save = { + 0, 0, 0, 'B', DEFAULT_RSTYLE }; -static selection_t selection = -{ - NULL, 0, SELECTION_CLEAR, PRIMARY, 0, - {0, 0}, - {0, 0}, - {0, 0} +static selection_t selection = { + NULL, 0, SELECTION_CLEAR, PRIMARY, 0, + {0, 0}, + {0, 0}, + {0, 0} }; -static char charsets[4] = -{ - 'B', 'B', 'B', 'B' /* all ascii */ +static char charsets[4] = { + 'B', 'B', 'B', 'B' /* all ascii */ }; static short current_screen = PRIMARY; @@ -90,7 +85,7 @@ unsigned char refresh_all = 0; static short multi_byte = 0; static short lost_multi = 0; static enum { - SBYTE, WBYTE + SBYTE, WBYTE } chstat = SBYTE; encoding_t encoding_method = LATIN1; @@ -105,12 +100,12 @@ inline void blank_line(text_t *et, rend_t *er, int width, rend_t efs) { /* int i = width; */ - register unsigned int i = width; - rend_t *r = er, fs = efs; + register unsigned int i = width; + rend_t *r = er, fs = efs; - MEMSET(et, ' ', i); - for (; i--;) - *r++ = fs; + MEMSET(et, ' ', i); + for (; i--;) + *r++ = fs; } /* Create a new row in the screen buffer and initialize it. */ @@ -118,267 +113,264 @@ inline void blank_screen_mem(text_t **, rend_t **, int, rend_t); inline void blank_screen_mem(text_t **tp, rend_t **rp, int row, rend_t efs) { - register unsigned int i = TermWin.ncol; - rend_t *r, fs = efs; + register unsigned int i = TermWin.ncol; + rend_t *r, fs = efs; - if (tp[row] == NULL) { - tp[row] = MALLOC(sizeof(text_t) * (TermWin.ncol + 1)); - rp[row] = MALLOC(sizeof(rend_t) * TermWin.ncol); - } - MEMSET(tp[row], ' ', i); - tp[row][i] = 0; - for (r = rp[row]; i--;) - *r++ = fs; + if (tp[row] == NULL) { + tp[row] = MALLOC(sizeof(text_t) * (TermWin.ncol + 1)); + rp[row] = MALLOC(sizeof(rend_t) * TermWin.ncol); + } + MEMSET(tp[row], ' ', i); + tp[row][i] = 0; + for (r = rp[row]; i--;) + *r++ = fs; } void scr_reset(void) { - int total_rows, prev_total_rows, chscr = 0; - register int i, j, k; - text_t tc; + int total_rows, prev_total_rows, chscr = 0; + register int i, j, k; + text_t tc; - D_SCREEN(("scr_reset()\n")); + D_SCREEN(("scr_reset()\n")); - TermWin.view_start = 0; - RESET_CHSTAT; + TermWin.view_start = 0; + RESET_CHSTAT; - if (TermWin.ncol == prev_ncol && TermWin.nrow == prev_nrow) - return; + if (TermWin.ncol == prev_ncol && TermWin.nrow == prev_nrow) + return; - if (current_screen != PRIMARY) { - short tmp = TermWin.nrow; + if (current_screen != PRIMARY) { + short tmp = TermWin.nrow; - TermWin.nrow = prev_nrow; - chscr = scr_change_screen(PRIMARY); - TermWin.nrow = tmp; - } - if (TermWin.ncol <= 0) - TermWin.ncol = 80; - if (TermWin.nrow <= 0) - TermWin.nrow = 24; - if (TermWin.saveLines <= 0) - TermWin.saveLines = 0; - - total_rows = TermWin.nrow + TermWin.saveLines; - prev_total_rows = prev_nrow + TermWin.saveLines; - - screen.tscroll = 0; - screen.bscroll = (TermWin.nrow - 1); - if (prev_nrow == -1) { - /* - * A: first time called so just malloc everything : don't rely on realloc - * Note: this is still needed so that all the scrollback lines are NULL - */ - screen.text = CALLOC(text_t *, total_rows); - buf_text = CALLOC(text_t *, total_rows); - drawn_text = CALLOC(text_t *, TermWin.nrow); - swap.text = CALLOC(text_t *, TermWin.nrow); - - screen.rend = CALLOC(rend_t *, total_rows); - buf_rend = CALLOC(rend_t *, total_rows); - drawn_rend = CALLOC(rend_t *, TermWin.nrow); - swap.rend = CALLOC(rend_t *, TermWin.nrow); - D_SCREEN(("screen.text == %8p, screen.rend == %8p, swap.text == %8p, swap.rend == %8p\n", screen.text, screen.rend, swap.text, swap.rend)); - - for (i = 0; i < TermWin.nrow; i++) { - j = i + TermWin.saveLines; - blank_screen_mem(screen.text, screen.rend, j, DEFAULT_RSTYLE); - blank_screen_mem(swap.text, swap.rend, i, DEFAULT_RSTYLE); - blank_screen_mem(drawn_text, drawn_rend, i, DEFAULT_RSTYLE); + TermWin.nrow = prev_nrow; + chscr = scr_change_screen(PRIMARY); + TermWin.nrow = tmp; } - TermWin.nscrolled = 0; /* no saved lines */ + if (TermWin.ncol <= 0) + TermWin.ncol = 80; + if (TermWin.nrow <= 0) + TermWin.nrow = 24; + if (TermWin.saveLines <= 0) + TermWin.saveLines = 0; - } else { - /* - * B1: add or delete rows as appropriate - */ - if (TermWin.nrow < prev_nrow) { - /* delete rows */ - k = MIN(TermWin.nscrolled, prev_nrow - TermWin.nrow); - scroll_text(0, prev_nrow - 1, k, 1); - - for (i = TermWin.nrow; i < prev_nrow; i++) { - j = i + TermWin.saveLines; - if (screen.text[j]) { - FREE(screen.text[j]); - FREE(screen.rend[j]); + total_rows = TermWin.nrow + TermWin.saveLines; + prev_total_rows = prev_nrow + TermWin.saveLines; + + screen.tscroll = 0; + screen.bscroll = (TermWin.nrow - 1); + if (prev_nrow == -1) { + /* + * A: first time called so just malloc everything : don't rely on realloc + * Note: this is still needed so that all the scrollback lines are NULL + */ + screen.text = CALLOC(text_t *, total_rows); + buf_text = CALLOC(text_t *, total_rows); + drawn_text = CALLOC(text_t *, TermWin.nrow); + swap.text = CALLOC(text_t *, TermWin.nrow); + + screen.rend = CALLOC(rend_t *, total_rows); + buf_rend = CALLOC(rend_t *, total_rows); + drawn_rend = CALLOC(rend_t *, TermWin.nrow); + swap.rend = CALLOC(rend_t *, TermWin.nrow); + D_SCREEN(("screen.text == %8p, screen.rend == %8p, swap.text == %8p, swap.rend == %8p\n", screen.text, screen.rend, swap.text, + swap.rend)); + + for (i = 0; i < TermWin.nrow; i++) { + j = i + TermWin.saveLines; + blank_screen_mem(screen.text, screen.rend, j, DEFAULT_RSTYLE); + blank_screen_mem(swap.text, swap.rend, i, DEFAULT_RSTYLE); + blank_screen_mem(drawn_text, drawn_rend, i, DEFAULT_RSTYLE); } - if (swap.text[i]) { - FREE(swap.text[i]); - FREE(swap.rend[i]); + TermWin.nscrolled = 0; /* no saved lines */ + + } else { + /* + * B1: add or delete rows as appropriate + */ + if (TermWin.nrow < prev_nrow) { + /* delete rows */ + k = MIN(TermWin.nscrolled, prev_nrow - TermWin.nrow); + scroll_text(0, prev_nrow - 1, k, 1); + + for (i = TermWin.nrow; i < prev_nrow; i++) { + j = i + TermWin.saveLines; + if (screen.text[j]) { + FREE(screen.text[j]); + FREE(screen.rend[j]); + } + if (swap.text[i]) { + FREE(swap.text[i]); + FREE(swap.rend[i]); + } + if (drawn_text[i]) { + FREE(drawn_text[i]); + FREE(drawn_rend[i]); + } + } + screen.text = REALLOC(screen.text, total_rows * sizeof(text_t *)); + buf_text = REALLOC(buf_text, total_rows * sizeof(text_t *)); + drawn_text = REALLOC(drawn_text, TermWin.nrow * sizeof(text_t *)); + swap.text = REALLOC(swap.text, TermWin.nrow * sizeof(text_t *)); + + screen.rend = REALLOC(screen.rend, total_rows * sizeof(rend_t *)); + buf_rend = REALLOC(buf_rend, total_rows * sizeof(rend_t *)); + drawn_rend = REALLOC(drawn_rend, TermWin.nrow * sizeof(rend_t *)); + swap.rend = REALLOC(swap.rend, TermWin.nrow * sizeof(rend_t *)); + D_SCREEN(("screen.text == %8p, screen.rend == %8p, swap.text == %8p, swap.rend == %8p\n", screen.text, screen.rend, swap.text, + swap.rend)); + + /* we have fewer rows so fix up number of scrolled lines */ + UPPER_BOUND(screen.row, TermWin.nrow - 1); + + } else if (TermWin.nrow > prev_nrow) { + /* add rows */ + screen.text = REALLOC(screen.text, total_rows * sizeof(text_t *)); + buf_text = REALLOC(buf_text, total_rows * sizeof(text_t *)); + drawn_text = REALLOC(drawn_text, TermWin.nrow * sizeof(text_t *)); + swap.text = REALLOC(swap.text, TermWin.nrow * sizeof(text_t *)); + + screen.rend = REALLOC(screen.rend, total_rows * sizeof(rend_t *)); + buf_rend = REALLOC(buf_rend, total_rows * sizeof(rend_t *)); + drawn_rend = REALLOC(drawn_rend, TermWin.nrow * sizeof(rend_t *)); + swap.rend = REALLOC(swap.rend, TermWin.nrow * sizeof(rend_t *)); + D_SCREEN(("screen.text == %8p, screen.rend == %8p, swap.text == %8p, swap.rend == %8p\n", screen.text, screen.rend, swap.text, + swap.rend)); + + k = MIN(TermWin.nscrolled, TermWin.nrow - prev_nrow); + for (i = prev_total_rows; i < total_rows - k; i++) { + screen.text[i] = NULL; + blank_screen_mem(screen.text, screen.rend, i, DEFAULT_RSTYLE); + } + for ( /* i = total_rows - k */ ; i < total_rows; i++) { + screen.text[i] = NULL; + screen.rend[i] = NULL; + } + for (i = prev_nrow; i < TermWin.nrow; i++) { + swap.text[i] = NULL; + drawn_text[i] = NULL; + blank_screen_mem(swap.text, swap.rend, i, DEFAULT_RSTYLE); + blank_screen_mem(drawn_text, drawn_rend, i, DEFAULT_RSTYLE); + } + if (k > 0) { + scroll_text(0, TermWin.nrow - 1, -k, 1); + screen.row += k; + TermWin.nscrolled -= k; + for (i = TermWin.saveLines - TermWin.nscrolled; k--; i--) { + if (screen.text[i] == NULL) { + blank_screen_mem(screen.text, screen.rend, i, DEFAULT_RSTYLE); + } + } + } } - if (drawn_text[i]) { - FREE(drawn_text[i]); - FREE(drawn_rend[i]); + /* B2: resize columns */ + if (TermWin.ncol != prev_ncol) { + for (i = 0; i < total_rows; i++) { + if (screen.text[i]) { + tc = screen.text[i][prev_ncol]; + screen.text[i] = REALLOC(screen.text[i], (TermWin.ncol + 1) * sizeof(text_t)); + screen.rend[i] = REALLOC(screen.rend[i], TermWin.ncol * sizeof(rend_t)); + screen.text[i][TermWin.ncol] = MIN(tc, TermWin.ncol); + if (TermWin.ncol > prev_ncol) + blank_line(&(screen.text[i][prev_ncol]), &(screen.rend[i][prev_ncol]), TermWin.ncol - prev_ncol, DEFAULT_RSTYLE); + } + } + for (i = 0; i < TermWin.nrow; i++) { + drawn_text[i] = REALLOC(drawn_text[i], (TermWin.ncol + 1) * sizeof(text_t)); + drawn_rend[i] = REALLOC(drawn_rend[i], TermWin.ncol * sizeof(rend_t)); + if (swap.text[i]) { + tc = swap.text[i][prev_ncol]; + swap.text[i] = REALLOC(swap.text[i], (TermWin.ncol + 1) * sizeof(text_t)); + swap.rend[i] = REALLOC(swap.rend[i], TermWin.ncol * sizeof(rend_t)); + swap.text[i][TermWin.ncol] = MIN(tc, TermWin.ncol); + if (TermWin.ncol > prev_ncol) + blank_line(&(swap.text[i][prev_ncol]), &(swap.rend[i][prev_ncol]), TermWin.ncol - prev_ncol, DEFAULT_RSTYLE); + } + if (TermWin.ncol > prev_ncol) + blank_line(&(drawn_text[i][prev_ncol]), &(drawn_rend[i][prev_ncol]), TermWin.ncol - prev_ncol, DEFAULT_RSTYLE); + } } - } - screen.text = REALLOC(screen.text, total_rows * sizeof(text_t*)); - buf_text = REALLOC(buf_text , total_rows * sizeof(text_t*)); - drawn_text = REALLOC(drawn_text , TermWin.nrow * sizeof(text_t*)); - swap.text = REALLOC(swap.text , TermWin.nrow * sizeof(text_t*)); - - screen.rend = REALLOC(screen.rend, total_rows * sizeof(rend_t*)); - buf_rend = REALLOC(buf_rend , total_rows * sizeof(rend_t*)); - drawn_rend = REALLOC(drawn_rend , TermWin.nrow * sizeof(rend_t*)); - swap.rend = REALLOC(swap.rend , TermWin.nrow * sizeof(rend_t*)); - D_SCREEN(("screen.text == %8p, screen.rend == %8p, swap.text == %8p, swap.rend == %8p\n", screen.text, screen.rend, swap.text, swap.rend)); - - /* we have fewer rows so fix up number of scrolled lines */ - UPPER_BOUND(screen.row, TermWin.nrow - 1); - - } else if (TermWin.nrow > prev_nrow) { - /* add rows */ - screen.text = REALLOC(screen.text, total_rows * sizeof(text_t*)); - buf_text = REALLOC(buf_text , total_rows * sizeof(text_t*)); - drawn_text = REALLOC(drawn_text , TermWin.nrow * sizeof(text_t*)); - swap.text = REALLOC(swap.text , TermWin.nrow * sizeof(text_t*)); - - screen.rend = REALLOC(screen.rend, total_rows * sizeof(rend_t*)); - buf_rend = REALLOC(buf_rend , total_rows * sizeof(rend_t*)); - drawn_rend = REALLOC(drawn_rend , TermWin.nrow * sizeof(rend_t*)); - swap.rend = REALLOC(swap.rend , TermWin.nrow * sizeof(rend_t*)); - D_SCREEN(("screen.text == %8p, screen.rend == %8p, swap.text == %8p, swap.rend == %8p\n", screen.text, screen.rend, swap.text, swap.rend)); - - k = MIN(TermWin.nscrolled, TermWin.nrow - prev_nrow); - for (i = prev_total_rows; i < total_rows - k; i++) { - screen.text[i] = NULL; - blank_screen_mem(screen.text, screen.rend, i, DEFAULT_RSTYLE); - } - for ( /* i = total_rows - k */ ; i < total_rows; i++) { - screen.text[i] = NULL; - screen.rend[i] = NULL; - } - for (i = prev_nrow; i < TermWin.nrow; i++) { - swap.text[i] = NULL; - drawn_text[i] = NULL; - blank_screen_mem(swap.text, swap.rend, i, DEFAULT_RSTYLE); - blank_screen_mem(drawn_text, drawn_rend, i, DEFAULT_RSTYLE); - } - if (k > 0) { - scroll_text(0, TermWin.nrow - 1, -k, 1); - screen.row += k; - TermWin.nscrolled -= k; - for (i = TermWin.saveLines - TermWin.nscrolled; k--; i--) { - if (screen.text[i] == NULL) { - blank_screen_mem(screen.text, screen.rend, i, DEFAULT_RSTYLE); - } - } - } + if (tabs) + FREE(tabs); } - /* B2: resize columns */ - if (TermWin.ncol != prev_ncol) { - for (i = 0; i < total_rows; i++) { - if (screen.text[i]) { - tc = screen.text[i][prev_ncol]; - screen.text[i] = REALLOC(screen.text[i], (TermWin.ncol + 1) * sizeof(text_t)); - screen.rend[i] = REALLOC(screen.rend[i], TermWin.ncol * sizeof(rend_t)); - screen.text[i][TermWin.ncol] = MIN(tc, TermWin.ncol); - if (TermWin.ncol > prev_ncol) - blank_line(&(screen.text[i][prev_ncol]), - &(screen.rend[i][prev_ncol]), - TermWin.ncol - prev_ncol, DEFAULT_RSTYLE); - } - } - for (i = 0; i < TermWin.nrow; i++) { - drawn_text[i] = REALLOC(drawn_text[i], (TermWin.ncol + 1) * sizeof(text_t)); - drawn_rend[i] = REALLOC(drawn_rend[i], TermWin.ncol * sizeof(rend_t)); - if (swap.text[i]) { - tc = swap.text[i][prev_ncol]; - swap.text[i] = REALLOC(swap.text[i], (TermWin.ncol + 1) * sizeof(text_t)); - swap.rend[i] = REALLOC(swap.rend[i], TermWin.ncol * sizeof(rend_t)); - swap.text[i][TermWin.ncol] = MIN(tc, TermWin.ncol); - if (TermWin.ncol > prev_ncol) - blank_line(&(swap.text[i][prev_ncol]), - &(swap.rend[i][prev_ncol]), - TermWin.ncol - prev_ncol, DEFAULT_RSTYLE); - } - if (TermWin.ncol > prev_ncol) - blank_line(&(drawn_text[i][prev_ncol]), - &(drawn_rend[i][prev_ncol]), - TermWin.ncol - prev_ncol, DEFAULT_RSTYLE); - } + tabs = MALLOC(TermWin.ncol); + + for (i = 0; i < TermWin.ncol; i++) + tabs[i] = (i % TABSIZE == 0) ? 1 : 0; + + prev_nrow = TermWin.nrow; + prev_ncol = TermWin.ncol; + + tt_resize(); + if (chscr) { + scr_change_screen(chscr); } - if (tabs) - FREE(tabs); - } - tabs = MALLOC(TermWin.ncol); - - for (i = 0; i < TermWin.ncol; i++) - tabs[i] = (i % TABSIZE == 0) ? 1 : 0; - - prev_nrow = TermWin.nrow; - prev_ncol = TermWin.ncol; - - tt_resize(); - if (chscr) { - scr_change_screen(chscr); - } } /* Release all screen memory. */ void scr_release(void) { - int total_rows; - register int i; + int total_rows; + register int i; - total_rows = TermWin.nrow + TermWin.saveLines; - for (i = 0; i < total_rows; i++) { - if (screen.text[i]) { - FREE(screen.text[i]); - FREE(screen.rend[i]); + total_rows = TermWin.nrow + TermWin.saveLines; + for (i = 0; i < total_rows; i++) { + if (screen.text[i]) { + FREE(screen.text[i]); + FREE(screen.rend[i]); + } } - } - for (i = 0; i < TermWin.nrow; i++) { - FREE(drawn_text[i]); - FREE(drawn_rend[i]); - FREE(swap.text[i]); - FREE(swap.rend[i]); - } - FREE(screen.text); - FREE(screen.rend); - FREE(drawn_text); - FREE(drawn_rend); - FREE(swap.text); - FREE(swap.rend); - FREE(buf_text); - FREE(buf_rend); - FREE(tabs); + for (i = 0; i < TermWin.nrow; i++) { + FREE(drawn_text[i]); + FREE(drawn_rend[i]); + FREE(swap.text[i]); + FREE(swap.rend[i]); + } + FREE(screen.text); + FREE(screen.rend); + FREE(drawn_text); + FREE(drawn_rend); + FREE(swap.text); + FREE(swap.rend); + FREE(buf_text); + FREE(buf_rend); + FREE(tabs); } /* Perform a full reset on the terminal. Called by the "\ec" sequence or by an xterm color change. */ void scr_poweron(void) { - D_SCREEN(("scr_poweron()\n")); + D_SCREEN(("scr_poweron()\n")); - /* Reset all character sets to Latin1 */ - MEMSET(charsets, 'B', sizeof(charsets)); - rvideo = 0; - /* Reset the rendering style to the default colors/style */ - scr_rendition(0, ~RS_None); + /* Reset all character sets to Latin1 */ + MEMSET(charsets, 'B', sizeof(charsets)); + rvideo = 0; + /* Reset the rendering style to the default colors/style */ + scr_rendition(0, ~RS_None); #if NSCREENS - /* Reset the secondary screen */ - scr_change_screen(SECONDARY); - scr_erase_screen(2); - swap.tscroll = 0; - swap.bscroll = TermWin.nrow - 1; - swap.row = swap.col = 0; - swap.charset = 0; - swap.flags = Screen_DefaultFlags; + /* Reset the secondary screen */ + scr_change_screen(SECONDARY); + scr_erase_screen(2); + swap.tscroll = 0; + swap.bscroll = TermWin.nrow - 1; + swap.row = swap.col = 0; + swap.charset = 0; + swap.flags = Screen_DefaultFlags; #endif - /* Reset the primary screen */ - scr_change_screen(PRIMARY); - scr_erase_screen(2); - screen.row = screen.col = 0; - screen.charset = 0; - screen.flags = Screen_DefaultFlags; + /* Reset the primary screen */ + scr_change_screen(PRIMARY); + scr_erase_screen(2); + screen.row = screen.col = 0; + screen.charset = 0; + screen.flags = Screen_DefaultFlags; - scr_cursor(SAVE); - TermWin.nscrolled = 0; - scr_reset(); - scr_refresh(SLOW_REFRESH); + scr_cursor(SAVE); + TermWin.nscrolled = 0; + scr_reset(); + scr_refresh(SLOW_REFRESH); } /* @@ -389,25 +381,25 @@ scr_poweron(void) void scr_cursor(int mode) { - D_SCREEN(("scr_cursor(%s)\n", (mode == SAVE ? "SAVE" : "RESTORE"))); + D_SCREEN(("scr_cursor(%s)\n", (mode == SAVE ? "SAVE" : "RESTORE"))); - switch (mode) { - case SAVE: - save.row = screen.row; - save.col = screen.col; - save.rstyle = rstyle; - save.charset = screen.charset; - save.charset_char = charsets[screen.charset]; - break; - case RESTORE: - screen.row = save.row; - screen.col = save.col; - rstyle = save.rstyle; - screen.charset = save.charset; - charsets[screen.charset] = save.charset_char; - set_font_style(); - break; - } + switch (mode) { + case SAVE: + save.row = screen.row; + save.col = screen.col; + save.rstyle = rstyle; + save.charset = screen.charset; + save.charset_char = charsets[screen.charset]; + break; + case RESTORE: + screen.row = save.row; + screen.col = save.col; + rstyle = save.rstyle; + screen.charset = save.charset; + charsets[screen.charset] = save.charset_char; + set_font_style(); + break; + } } /* @@ -418,48 +410,48 @@ scr_cursor(int mode) int scr_change_screen(int scrn) { - int i, offset, tmp; - text_t *t0; - rend_t *r0; + int i, offset, tmp; + text_t *t0; + rend_t *r0; - D_SCREEN(("scr_change_screen(%d)\n", scrn)); + D_SCREEN(("scr_change_screen(%d)\n", scrn)); - TermWin.view_start = 0; - RESET_CHSTAT; + TermWin.view_start = 0; + RESET_CHSTAT; - if (current_screen == scrn) - return current_screen; + if (current_screen == scrn) + return current_screen; - SWAP_IT(current_screen, scrn, tmp); + SWAP_IT(current_screen, scrn, tmp); #if NSCREENS - offset = TermWin.saveLines; - if (!screen.text || !screen.rend) - return (current_screen); - for (i = TermWin.nrow; i--;) { - SWAP_IT(screen.text[i + offset], swap.text[i], t0); - SWAP_IT(screen.rend[i + offset], swap.rend[i], r0); - } - SWAP_IT(screen.row, swap.row, tmp); - SWAP_IT(screen.col, swap.col, tmp); - SWAP_IT(screen.charset, swap.charset, tmp); - SWAP_IT(screen.flags, swap.flags, tmp); - screen.flags |= Screen_VisibleCursor; - swap.flags |= Screen_VisibleCursor; + offset = TermWin.saveLines; + if (!screen.text || !screen.rend) + return (current_screen); + for (i = TermWin.nrow; i--;) { + SWAP_IT(screen.text[i + offset], swap.text[i], t0); + SWAP_IT(screen.rend[i + offset], swap.rend[i], r0); + } + SWAP_IT(screen.row, swap.row, tmp); + SWAP_IT(screen.col, swap.col, tmp); + SWAP_IT(screen.charset, swap.charset, tmp); + SWAP_IT(screen.flags, swap.flags, tmp); + screen.flags |= Screen_VisibleCursor; + swap.flags |= Screen_VisibleCursor; #else # ifndef DONT_SCROLL_ME - if (current_screen == PRIMARY) - if (current_screen == PRIMARY) { - scroll_text(0, (TermWin.nrow - 1), TermWin.nrow, 0); - for (i = TermWin.saveLines; i < TermWin.nrow + TermWin.saveLines; i++) - if (screen.text[i] == NULL) { - blank_screen_mem(screen.text, screen.rend, i, DEFAULT_RSTYLE); - } - } + if (current_screen == PRIMARY) + if (current_screen == PRIMARY) { + scroll_text(0, (TermWin.nrow - 1), TermWin.nrow, 0); + for (i = TermWin.saveLines; i < TermWin.nrow + TermWin.saveLines; i++) + if (screen.text[i] == NULL) { + blank_screen_mem(screen.text, screen.rend, i, DEFAULT_RSTYLE); + } + } # endif #endif - return scrn; + return scrn; } /* @@ -469,41 +461,41 @@ void scr_color(unsigned int color, unsigned int Intensity) { - D_SCREEN(("scr_color(%u, %u) called.\n", color, Intensity)); - if (color == restoreFG) - color = fgColor; - else if (color == restoreBG) - color = bgColor; - else { - if (Xdepth <= 2) { /* Monochrome - ignore color changes */ - switch (Intensity) { - case RS_Bold: - color = fgColor; - break; - case RS_Blink: - color = bgColor; - break; - } - } else { + D_SCREEN(("scr_color(%u, %u) called.\n", color, Intensity)); + if (color == restoreFG) + color = fgColor; + else if (color == restoreBG) + color = bgColor; + else { + if (Xdepth <= 2) { /* Monochrome - ignore color changes */ + switch (Intensity) { + case RS_Bold: + color = fgColor; + break; + case RS_Blink: + color = bgColor; + break; + } + } else { #ifndef NO_BRIGHTCOLOR - if ((rstyle & Intensity) && color >= minColor && color <= maxColor) - color += (minBright - minColor); - else if (color >= minBright && color <= maxBright) { - if (rstyle & Intensity) - return; - color -= (minBright - minColor); - } + if ((rstyle & Intensity) && color >= minColor && color <= maxColor) + color += (minBright - minColor); + else if (color >= minBright && color <= maxBright) { + if (rstyle & Intensity) + return; + color -= (minBright - minColor); + } #endif + } + } + switch (Intensity) { + case RS_Bold: + rstyle = SET_FGCOLOR(rstyle, color); + break; + case RS_Blink: + rstyle = SET_BGCOLOR(rstyle, color); + break; } - } - switch (Intensity) { - case RS_Bold: - rstyle = SET_FGCOLOR(rstyle, color); - break; - case RS_Blink: - rstyle = SET_BGCOLOR(rstyle, color); - break; - } } /* @@ -512,164 +504,162 @@ scr_color(unsigned int color, unsigned int Intensity) void scr_rendition(int set, int style) { - unsigned int color; - int old_style = rstyle; + unsigned int color; + int old_style = rstyle; - D_SCREEN(("scr_rendition(%d, %d) called.\n", set, style)); - if (set) { + D_SCREEN(("scr_rendition(%d, %d) called.\n", set, style)); + if (set) { /* A: Set style */ - rstyle |= style; - switch (style) { - case RS_RVid: - if (rvideo) - rstyle &= ~RS_RVid; - break; + rstyle |= style; + switch (style) { + case RS_RVid: + if (rvideo) + rstyle &= ~RS_RVid; + break; #ifndef NO_BRIGHTCOLOR - case RS_Bold: - color = GET_FGCOLOR(rstyle); - scr_color((color == fgColor ? GET_FGCOLOR(colorfgbg) : color), - RS_Bold); - break; - case RS_Blink: - color = GET_BGCOLOR(rstyle); - scr_color((color == bgColor ? GET_BGCOLOR(colorfgbg) : color), - RS_Blink); - break; + case RS_Bold: + color = GET_FGCOLOR(rstyle); + scr_color((color == fgColor ? GET_FGCOLOR(colorfgbg) : color), RS_Bold); + break; + case RS_Blink: + color = GET_BGCOLOR(rstyle); + scr_color((color == bgColor ? GET_BGCOLOR(colorfgbg) : color), RS_Blink); + break; #endif - } - } else { + } + } else { /* B: Unset style */ - rstyle &= ~style; + rstyle &= ~style; - switch (style) { - case ~RS_None: /* default fg/bg colors */ - rstyle = DEFAULT_RSTYLE | (old_style & RS_fontMask); - /* FALLTHROUGH */ - case RS_RVid: - if (rvideo) - rstyle |= RS_RVid; - break; + switch (style) { + case ~RS_None: /* default fg/bg colors */ + rstyle = DEFAULT_RSTYLE | (old_style & RS_fontMask); + /* FALLTHROUGH */ + case RS_RVid: + if (rvideo) + rstyle |= RS_RVid; + break; #ifndef NO_BRIGHTCOLOR - case RS_Bold: - color = GET_FGCOLOR(rstyle); - if (color >= minBright && color <= maxBright) { - scr_color(color, RS_Bold); - if ((rstyle & RS_fgMask) == (colorfgbg & RS_fgMask)) - scr_color(restoreFG, RS_Bold); - } - break; - case RS_Blink: - color = GET_BGCOLOR(rstyle); - if (color >= minBright && color <= maxBright) { - scr_color(color, RS_Blink); - if ((rstyle & RS_bgMask) == (colorfgbg & RS_bgMask)) - scr_color(restoreBG, RS_Blink); - } - break; + case RS_Bold: + color = GET_FGCOLOR(rstyle); + if (color >= minBright && color <= maxBright) { + scr_color(color, RS_Bold); + if ((rstyle & RS_fgMask) == (colorfgbg & RS_fgMask)) + scr_color(restoreFG, RS_Bold); + } + break; + case RS_Blink: + color = GET_BGCOLOR(rstyle); + if (color >= minBright && color <= maxBright) { + scr_color(color, RS_Blink); + if ((rstyle & RS_bgMask) == (colorfgbg & RS_bgMask)) + scr_color(restoreBG, RS_Blink); + } + break; #endif + } } - } } /* Scroll text region from through by lines */ int scroll_text(int row1, int row2, int count, int spec) { - register int i, j; + register int i, j; - PROF_INIT(scroll_text); - D_SCREEN(("scroll_text(%d,%d,%d,%d): %s\n", row1, row2, count, spec, (current_screen == PRIMARY) ? "Primary" : "Secondary")); + PROF_INIT(scroll_text); + D_SCREEN(("scroll_text(%d,%d,%d,%d): %s\n", row1, row2, count, spec, (current_screen == PRIMARY) ? "Primary" : "Secondary")); - if (count == 0 || (row1 > row2)) - return 0; - if ((count > 0) && (row1 == 0) && (current_screen == PRIMARY)) { - TermWin.nscrolled += count; - UPPER_BOUND(TermWin.nscrolled, TermWin.saveLines); - } else if (!spec) - row1 += TermWin.saveLines; - row2 += TermWin.saveLines; + if (count == 0 || (row1 > row2)) + return 0; + if ((count > 0) && (row1 == 0) && (current_screen == PRIMARY)) { + TermWin.nscrolled += count; + UPPER_BOUND(TermWin.nscrolled, TermWin.saveLines); + } else if (!spec) + row1 += TermWin.saveLines; + row2 += TermWin.saveLines; - if (selection.op && current_screen == selection.screen) { - i = selection.beg.row + TermWin.saveLines; - j = selection.end.row + TermWin.saveLines; - if ((i < row1 && j > row1) - || (i < row2 && j > row2) - || (i - count < row1 && i >= row1) - || (i - count > row2 && i <= row2) - || (j - count < row1 && j >= row1) - || (j - count > row2 && j <= row2)) { - CLEAR_ALL_SELECTION; - selection.op = SELECTION_CLEAR; - } else if (j >= row1 && j <= row2) { - /* move selected region too */ - selection.beg.row -= count; - selection.end.row -= count; - selection.mark.row -= count; + if (selection.op && current_screen == selection.screen) { + i = selection.beg.row + TermWin.saveLines; + j = selection.end.row + TermWin.saveLines; + if ((i < row1 && j > row1) + || (i < row2 && j > row2) + || (i - count < row1 && i >= row1) + || (i - count > row2 && i <= row2) + || (j - count < row1 && j >= row1) + || (j - count > row2 && j <= row2)) { + CLEAR_ALL_SELECTION; + selection.op = SELECTION_CLEAR; + } else if (j >= row1 && j <= row2) { + /* move selected region too */ + selection.beg.row -= count; + selection.end.row -= count; + selection.mark.row -= count; + } } - } - CHECK_SELECTION; + CHECK_SELECTION; - if (count > 0) { + if (count > 0) { /* A: scroll up */ - UPPER_BOUND(count, row2 - row1 + 1); + UPPER_BOUND(count, row2 - row1 + 1); /* A1: Copy and blank out lines that will get clobbered by the rotation */ - for (i = 0, j = row1; i < count; i++, j++) { - buf_text[i] = screen.text[j]; - buf_rend[i] = screen.rend[j]; - if (buf_text[i] == NULL) { - /* A new ALLOC is done with size ncol and - blankline with size prev_ncol -- Sebastien van K */ - buf_text[i] = MALLOC(sizeof(text_t) * (prev_ncol + 1)); - buf_rend[i] = MALLOC(sizeof(rend_t) * prev_ncol); - } - blank_line(buf_text[i], buf_rend[i], prev_ncol, DEFAULT_RSTYLE); - buf_text[i][prev_ncol] = 0; - } + for (i = 0, j = row1; i < count; i++, j++) { + buf_text[i] = screen.text[j]; + buf_rend[i] = screen.rend[j]; + if (buf_text[i] == NULL) { + /* A new ALLOC is done with size ncol and + blankline with size prev_ncol -- Sebastien van K */ + buf_text[i] = MALLOC(sizeof(text_t) * (prev_ncol + 1)); + buf_rend[i] = MALLOC(sizeof(rend_t) * prev_ncol); + } + blank_line(buf_text[i], buf_rend[i], prev_ncol, DEFAULT_RSTYLE); + buf_text[i][prev_ncol] = 0; + } /* A2: Rotate lines */ - for (j = row1; (j + count) <= row2; j++) { - screen.text[j] = screen.text[j + count]; - screen.rend[j] = screen.rend[j + count]; - } + for (j = row1; (j + count) <= row2; j++) { + screen.text[j] = screen.text[j + count]; + screen.rend[j] = screen.rend[j + count]; + } /* A3: Resurrect lines */ - for (i = 0; i < count; i++, j++) { - screen.text[j] = buf_text[i]; - screen.rend[j] = buf_rend[i]; - } - } else if (count < 0) { + for (i = 0; i < count; i++, j++) { + screen.text[j] = buf_text[i]; + screen.rend[j] = buf_rend[i]; + } + } else if (count < 0) { /* B: scroll down */ - count = MIN(-count, row2 - row1 + 1); + count = MIN(-count, row2 - row1 + 1); /* B1: Copy and blank out lines that will get clobbered by the rotation */ - for (i = 0, j = row2; i < count; i++, j--) { - buf_text[i] = screen.text[j]; - buf_rend[i] = screen.rend[j]; - if (buf_text[i] == NULL) { - /* A new ALLOC is done with size ncol and - blankline with size prev_ncol -- Sebastien van K */ - buf_text[i] = MALLOC(sizeof(text_t) * (prev_ncol + 1)); - buf_rend[i] = MALLOC(sizeof(rend_t) * prev_ncol); - } - blank_line(buf_text[i], buf_rend[i], prev_ncol, DEFAULT_RSTYLE); - buf_text[i][prev_ncol] = 0; - } + for (i = 0, j = row2; i < count; i++, j--) { + buf_text[i] = screen.text[j]; + buf_rend[i] = screen.rend[j]; + if (buf_text[i] == NULL) { + /* A new ALLOC is done with size ncol and + blankline with size prev_ncol -- Sebastien van K */ + buf_text[i] = MALLOC(sizeof(text_t) * (prev_ncol + 1)); + buf_rend[i] = MALLOC(sizeof(rend_t) * prev_ncol); + } + blank_line(buf_text[i], buf_rend[i], prev_ncol, DEFAULT_RSTYLE); + buf_text[i][prev_ncol] = 0; + } /* B2: Rotate lines */ - for (j = row2; (j - count) >= row1; j--) { - screen.text[j] = screen.text[j - count]; - screen.rend[j] = screen.rend[j - count]; - } + for (j = row2; (j - count) >= row1; j--) { + screen.text[j] = screen.text[j - count]; + screen.rend[j] = screen.rend[j - count]; + } /* B3: Resurrect lines */ - for (i = 0, j = row1; i < count; i++, j++) { - screen.text[j] = buf_text[i]; - screen.rend[j] = buf_rend[i]; + for (i = 0, j = row1; i < count; i++, j++) { + screen.text[j] = buf_text[i]; + screen.rend[j] = buf_rend[i]; + } + count = -count; } - count = -count; - } - PROF_DONE(scroll_text); - PROF_TIME(scroll_text); - return count; + PROF_DONE(scroll_text); + PROF_TIME(scroll_text); + return count; } /* @@ -679,154 +669,159 @@ void scr_add_lines(const unsigned char *str, int nlines, int len) { /* char c; */ - register char c; + register char c; /* int i, j, row, last_col; */ - int last_col; - register int i, j, row; - text_t *stp; - rend_t *srp; - row_col_t beg, end; + int last_col; + register int i, j, row; + text_t *stp; + rend_t *srp; + row_col_t beg, end; - if (len <= 0) /* sanity */ - return; + if (len <= 0) /* sanity */ + return; - last_col = TermWin.ncol; + last_col = TermWin.ncol; - D_SCREEN(("scr_add_lines(*,%d,%d)\n", nlines, len)); - ZERO_SCROLLBACK; - if (nlines > 0) { - nlines += (screen.row - screen.bscroll); - D_SCREEN((" -> screen.row == %d, screen.bscroll == %d, new nlines == %d\n", screen.row, screen.bscroll, nlines)); - if ((nlines > 0) && (screen.tscroll == 0) && (screen.bscroll == (TermWin.nrow - 1))) { - /* _at least_ this many lines need to be scrolled */ - scroll_text(screen.tscroll, screen.bscroll, nlines, 0); - for (i = nlines, row = screen.bscroll + TermWin.saveLines + 1; row > 0 && i--;) { - /* Move row-- to beginning of loop to avoid segfault. -- added by Sebastien van K */ - row--; - blank_screen_mem(screen.text, screen.rend, row, rstyle); - } - screen.row -= nlines; - } - } - UPPER_BOUND(screen.col, last_col - 1); - BOUND(screen.row, -TermWin.nscrolled, TermWin.nrow - 1); - - row = screen.row + TermWin.saveLines; - if (screen.text[row] == NULL) { - blank_screen_mem(screen.text, screen.rend, row, DEFAULT_RSTYLE); - } /* avoid segfault -- added by Sebastien van K */ - beg.row = screen.row; - beg.col = screen.col; - stp = screen.text[row]; - srp = screen.rend[row]; - -#ifdef MULTI_CHARSET - if (lost_multi && screen.col > 0 - && ((srp[screen.col - 1] & RS_multiMask) == RS_multi1) - && *str != '\n' && *str != '\r' && *str != '\t') - chstat = WBYTE; -#endif - - for (i = 0; i < len;) { - c = str[i++]; -#ifdef MULTI_CHARSET - if ((encoding_method != LATIN1) && (chstat == WBYTE)) { - rstyle |= RS_multiMask; /* multibyte 2nd byte */ - chstat = SBYTE; - if (encoding_method == EUCJ) { - c |= 0x80; /* maybe overkill, but makes it selectable */ - } - } else if (chstat == SBYTE) { - if ((encoding_method != LATIN1) && (multi_byte || (c & 0x80))) { /* multibyte 1st byte */ - rstyle &= ~RS_multiMask; - rstyle |= RS_multi1; - chstat = WBYTE; - if (encoding_method == EUCJ) { - c |= 0x80; /* maybe overkill, but makes it selectable */ + D_SCREEN(("scr_add_lines(*,%d,%d)\n", nlines, len)); + ZERO_SCROLLBACK; + if (nlines > 0) { + nlines += (screen.row - screen.bscroll); + D_SCREEN((" -> screen.row == %d, screen.bscroll == %d, new nlines == %d\n", screen.row, screen.bscroll, nlines)); + if ((nlines > 0) && (screen.tscroll == 0) && (screen.bscroll == (TermWin.nrow - 1))) { + /* _at least_ this many lines need to be scrolled */ + scroll_text(screen.tscroll, screen.bscroll, nlines, 0); + for (i = nlines, row = screen.bscroll + TermWin.saveLines + 1; row > 0 && i--;) { + /* Move row-- to beginning of loop to avoid segfault. -- added by Sebastien van K */ + row--; + blank_screen_mem(screen.text, screen.rend, row, rstyle); + } + screen.row -= nlines; } - } else + } + UPPER_BOUND(screen.col, last_col - 1); + BOUND(screen.row, -TermWin.nscrolled, TermWin.nrow - 1); + + row = screen.row + TermWin.saveLines; + if (screen.text[row] == NULL) { + blank_screen_mem(screen.text, screen.rend, row, DEFAULT_RSTYLE); + } /* avoid segfault -- added by Sebastien van K */ + beg.row = screen.row; + beg.col = screen.col; + stp = screen.text[row]; + srp = screen.rend[row]; + +#ifdef MULTI_CHARSET + if (lost_multi && screen.col > 0 && ((srp[screen.col - 1] & RS_multiMask) == RS_multi1) + && *str != '\n' && *str != '\r' && *str != '\t') + chstat = WBYTE; #endif - switch (c) { - case 127: - continue; /* ummmm..... */ - case '\t': - scr_tab(1); - continue; - case '\n': - LOWER_BOUND(stp[last_col], screen.col); - screen.flags &= ~Screen_WrapNext; + + for (i = 0; i < len;) { + c = str[i++]; +#ifdef MULTI_CHARSET + if ((encoding_method != LATIN1) && (chstat == WBYTE)) { + rstyle |= RS_multiMask; /* multibyte 2nd byte */ + chstat = SBYTE; + if (encoding_method == EUCJ) { + c |= 0x80; /* maybe overkill, but makes it selectable */ + } + } else if (chstat == SBYTE) { + if ((encoding_method != LATIN1) && (multi_byte || (c & 0x80))) { /* multibyte 1st byte */ + rstyle &= ~RS_multiMask; + rstyle |= RS_multi1; + chstat = WBYTE; + if (encoding_method == EUCJ) { + c |= 0x80; /* maybe overkill, but makes it selectable */ + } + } else +#endif + switch (c) { + case 127: + continue; /* ummmm..... */ + case '\t': + scr_tab(1); + continue; + case '\n': + LOWER_BOUND(stp[last_col], screen.col); + screen.flags &= ~Screen_WrapNext; + if (screen.row == screen.bscroll) { + scroll_text(screen.tscroll, screen.bscroll, 1, 0); + j = screen.bscroll + TermWin.saveLines; + blank_screen_mem(screen.text, screen.rend, j, rstyle & ~RS_Uline); + } else if (screen.row < (TermWin.nrow - 1)) { + screen.row++; + row = screen.row + TermWin.saveLines; + } + stp = screen.text[row]; /* _must_ refresh */ + srp = screen.rend[row]; /* _must_ refresh */ + continue; + case '\r': + LOWER_BOUND(stp[last_col], screen.col); + screen.flags &= ~Screen_WrapNext; + screen.col = 0; + continue; + default: +#ifdef MULTI_CHARSET + rstyle &= ~RS_multiMask; +#endif + break; + } +#ifdef MULTI_CHARSET + } +#endif + if (screen.flags & Screen_WrapNext) { + stp[last_col] = WRAP_CHAR; if (screen.row == screen.bscroll) { - scroll_text(screen.tscroll, screen.bscroll, 1, 0); - j = screen.bscroll + TermWin.saveLines; - blank_screen_mem(screen.text, screen.rend, j, rstyle & ~RS_Uline); + scroll_text(screen.tscroll, screen.bscroll, 1, 0); + j = screen.bscroll + TermWin.saveLines; + /* blank_line(screen.text[j], screen.rend[j], TermWin.ncol, + rstyle); Bug fix from John Ellison - need to reset rstyle */ + blank_screen_mem(screen.text, screen.rend, j, rstyle & ~RS_Uline); } else if (screen.row < (TermWin.nrow - 1)) { - screen.row++; - row = screen.row + TermWin.saveLines; + screen.row++; + row = screen.row + TermWin.saveLines; } stp = screen.text[row]; /* _must_ refresh */ srp = screen.rend[row]; /* _must_ refresh */ - continue; - case '\r': - LOWER_BOUND(stp[last_col], screen.col); - screen.flags &= ~Screen_WrapNext; screen.col = 0; - continue; - default: -#ifdef MULTI_CHARSET - rstyle &= ~RS_multiMask; -#endif - break; + screen.flags &= ~Screen_WrapNext; + } + if (screen.flags & Screen_Insert) + scr_insdel_chars(1, INSERT); + stp[screen.col] = c; + srp[screen.col] = rstyle; + if (screen.col < (last_col - 1)) + screen.col++; + else { + stp[last_col] = last_col; + if (screen.flags & Screen_Autowrap) + screen.flags |= Screen_WrapNext; + else + screen.flags &= ~Screen_WrapNext; + } + } + LOWER_BOUND(stp[last_col], screen.col); + if (screen.col == 0) { + end.col = last_col - 1; + end.row = screen.row - 1; + } else { + end.col = screen.col - 1; + end.row = screen.row; + } + if (((selection.end.row > beg.row) + || (selection.end.row == beg.row && selection.end.col >= beg.col)) + && ((selection.beg.row < end.row) + || (selection.beg.row == end.row && selection.beg.col <= end.col))) + selection_reset(); + +#ifdef ESCREEN + if (TermWin.screen_mode) { + if (screen.row >= TermWin.nrow - 1) { /* last row -> upd-flag */ + TermWin.screen_pending |= 1; } -#ifdef MULTI_CHARSET } #endif - if (screen.flags & Screen_WrapNext) { - stp[last_col] = WRAP_CHAR; - if (screen.row == screen.bscroll) { - scroll_text(screen.tscroll, screen.bscroll, 1, 0); - j = screen.bscroll + TermWin.saveLines; - /* blank_line(screen.text[j], screen.rend[j], TermWin.ncol, - rstyle); Bug fix from John Ellison - need to reset rstyle */ - blank_screen_mem(screen.text, screen.rend, j, rstyle & ~RS_Uline); - } else if (screen.row < (TermWin.nrow - 1)) { - screen.row++; - row = screen.row + TermWin.saveLines; - } - stp = screen.text[row]; /* _must_ refresh */ - srp = screen.rend[row]; /* _must_ refresh */ - screen.col = 0; - screen.flags &= ~Screen_WrapNext; - } - if (screen.flags & Screen_Insert) - scr_insdel_chars(1, INSERT); - stp[screen.col] = c; - srp[screen.col] = rstyle; - if (screen.col < (last_col - 1)) - screen.col++; - else { - stp[last_col] = last_col; - if (screen.flags & Screen_Autowrap) - screen.flags |= Screen_WrapNext; - else - screen.flags &= ~Screen_WrapNext; - } - } - LOWER_BOUND(stp[last_col], screen.col); - if (screen.col == 0) { - end.col = last_col - 1; - end.row = screen.row - 1; - } else { - end.col = screen.col - 1; - end.row = screen.row; - } - if (((selection.end.row > beg.row) - || (selection.end.row == beg.row - && selection.end.col >= beg.col)) - && ((selection.beg.row < end.row) - || (selection.beg.row == end.row - && selection.beg.col <= end.col))) - selection_reset(); } /* @@ -837,14 +832,14 @@ void scr_backspace(void) { - RESET_CHSTAT; - if (screen.col == 0 && screen.row > 0) { - screen.col = TermWin.ncol - 1; - screen.row--; - } else if (screen.flags & Screen_WrapNext) { - screen.flags &= ~Screen_WrapNext; - } else - scr_gotorc(0, -1, RELATIVE); + RESET_CHSTAT; + if (screen.col == 0 && screen.row > 0) { + screen.col = TermWin.ncol - 1; + screen.row--; + } else if (screen.flags & Screen_WrapNext) { + screen.flags &= ~Screen_WrapNext; + } else + scr_gotorc(0, -1, RELATIVE); } /* @@ -855,31 +850,31 @@ scr_backspace(void) void scr_tab(int count) { - int i, x; + int i, x; - RESET_CHSTAT; - x = screen.col; - if (count == 0) - return; - else if (count > 0) { - for (i = x + 1; i < TermWin.ncol; i++) { - if (tabs[i]) { - x = i; - if (!--count) - break; - } + RESET_CHSTAT; + x = screen.col; + if (count == 0) + return; + else if (count > 0) { + for (i = x + 1; i < TermWin.ncol; i++) { + if (tabs[i]) { + x = i; + if (!--count) + break; + } + } + } else if (count < 0) { + for (i = x - 1; i >= 0; i--) { + if (tabs[i]) { + x = i; + if (!++count) + break; + } + } } - } else if (count < 0) { - for (i = x - 1; i >= 0; i--) { - if (tabs[i]) { - x = i; - if (!++count) - break; - } - } - } - if (x != screen.col) - scr_gotorc(0, x, R_RELATIVE); + if (x != screen.col) + scr_gotorc(0, x, R_RELATIVE); } /* @@ -888,37 +883,44 @@ scr_tab(int count) void scr_gotorc(int row, int col, int relative) { - ZERO_SCROLLBACK; - RESET_CHSTAT; + ZERO_SCROLLBACK; + RESET_CHSTAT; - screen.col = ((relative & C_RELATIVE) ? (screen.col + col) : col); - BOUND(screen.col, 0, TermWin.ncol - 1); + screen.col = ((relative & C_RELATIVE) ? (screen.col + col) : col); + BOUND(screen.col, 0, TermWin.ncol - 1); - if (screen.flags & Screen_WrapNext) { - screen.flags &= ~Screen_WrapNext; - } - if (relative & R_RELATIVE) { - if (row > 0) { - if (screen.row <= screen.bscroll - && (screen.row + row) > screen.bscroll) - screen.row = screen.bscroll; - else - screen.row += row; - } else if (row < 0) { - if (screen.row >= screen.tscroll - && (screen.row + row) < screen.tscroll) - screen.row = screen.tscroll; - else - screen.row += row; + if (screen.flags & Screen_WrapNext) { + screen.flags &= ~Screen_WrapNext; } - } else { - if (screen.flags & Screen_Relative) { /* relative origin mode */ - screen.row = row + screen.tscroll; - UPPER_BOUND(screen.row, screen.bscroll); - } else - screen.row = row; - } - BOUND(screen.row, 0, TermWin.nrow - 1); + if (relative & R_RELATIVE) { + if (row > 0) { + if (screen.row <= screen.bscroll && (screen.row + row) > screen.bscroll) + screen.row = screen.bscroll; + else + screen.row += row; + } else if (row < 0) { + if (screen.row >= screen.tscroll && (screen.row + row) < screen.tscroll) + screen.row = screen.tscroll; + else + screen.row += row; + } + } else { + if (screen.flags & Screen_Relative) { /* relative origin mode */ + screen.row = row + screen.tscroll; + UPPER_BOUND(screen.row, screen.bscroll); + } else + screen.row = row; + } +#ifdef ESCREEN + if (TermWin.screen_mode) { + if (screen.row >= TermWin.nrow - 1) { /* last row -> upd-flag */ + TermWin.screen_pending |= 1; + } else if (TermWin.screen_pending) { /* left last -> upd-finis */ + TermWin.screen_pending |= 2; + } + } +#endif + BOUND(screen.row, 0, TermWin.nrow - 1); } /* @@ -927,29 +929,29 @@ scr_gotorc(int row, int col, int relative) void scr_index(int direction) { - int dirn; + int dirn; - dirn = ((direction == UP) ? 1 : -1); - D_SCREEN(("scr_index(%d)\n", dirn)); + dirn = ((direction == UP) ? 1 : -1); + D_SCREEN(("scr_index(%d)\n", dirn)); - ZERO_SCROLLBACK; - RESET_CHSTAT; + ZERO_SCROLLBACK; + RESET_CHSTAT; - if (screen.flags & Screen_WrapNext) { - screen.flags &= ~Screen_WrapNext; - } - if ((screen.row == screen.bscroll && direction == UP) - || (screen.row == screen.tscroll && direction == DN)) { - scroll_text(screen.tscroll, screen.bscroll, dirn, 0); - if (direction == UP) - dirn = screen.bscroll + TermWin.saveLines; - else - dirn = screen.tscroll + TermWin.saveLines; - blank_screen_mem(screen.text, screen.rend, dirn, rstyle); - } else - screen.row += dirn; - BOUND(screen.row, 0, TermWin.nrow - 1); - CHECK_SELECTION; + if (screen.flags & Screen_WrapNext) { + screen.flags &= ~Screen_WrapNext; + } + if ((screen.row == screen.bscroll && direction == UP) + || (screen.row == screen.tscroll && direction == DN)) { + scroll_text(screen.tscroll, screen.bscroll, dirn, 0); + if (direction == UP) + dirn = screen.bscroll + TermWin.saveLines; + else + dirn = screen.tscroll + TermWin.saveLines; + blank_screen_mem(screen.text, screen.rend, dirn, rstyle); + } else + screen.row += dirn; + BOUND(screen.row, 0, TermWin.nrow - 1); + CHECK_SELECTION; } /* @@ -961,39 +963,39 @@ scr_index(int direction) void scr_erase_line(int mode) { - int row, col, num; + int row, col, num; - D_SCREEN(("scr_erase_line(%d) at screen row: %d\n", mode, screen.row)); - ZERO_SCROLLBACK; - RESET_CHSTAT; + D_SCREEN(("scr_erase_line(%d) at screen row: %d\n", mode, screen.row)); + ZERO_SCROLLBACK; + RESET_CHSTAT; - if (screen.flags & Screen_WrapNext) - screen.flags &= ~Screen_WrapNext; + if (screen.flags & Screen_WrapNext) + screen.flags &= ~Screen_WrapNext; - row = TermWin.saveLines + screen.row; - if (screen.text[row]) { - switch (mode) { - case 0: /* erase to end of line */ - col = screen.col; - num = TermWin.ncol - col; - UPPER_BOUND(screen.text[row][TermWin.ncol], col); - break; - case 1: /* erase to beginning of line */ - col = 0; - num = screen.col + 1; - break; - case 2: /* erase whole line */ - col = 0; - num = TermWin.ncol; - screen.text[row][TermWin.ncol] = 0; - break; - default: - return; + row = TermWin.saveLines + screen.row; + if (screen.text[row]) { + switch (mode) { + case 0: /* erase to end of line */ + col = screen.col; + num = TermWin.ncol - col; + UPPER_BOUND(screen.text[row][TermWin.ncol], col); + break; + case 1: /* erase to beginning of line */ + col = 0; + num = screen.col + 1; + break; + case 2: /* erase whole line */ + col = 0; + num = TermWin.ncol; + screen.text[row][TermWin.ncol] = 0; + break; + default: + return; + } + blank_line(&(screen.text[row][col]), &(screen.rend[row][col]), num, rstyle & ~RS_Uline); + } else { + blank_screen_mem(screen.text, screen.rend, row, rstyle & ~RS_Uline); } - blank_line(&(screen.text[row][col]), &(screen.rend[row][col]), num, rstyle & ~RS_Uline); - } else { - blank_screen_mem(screen.text, screen.rend, row, rstyle & ~RS_Uline); - } } /* @@ -1005,67 +1007,67 @@ scr_erase_line(int mode) void scr_erase_screen(int mode) { - int row, num, row_offset; - rend_t ren; - long gcmask; - XGCValues gcvalue; - Pixmap pmap = None; - Drawable draw_buffer; + int row, num, row_offset; + rend_t ren; + long gcmask; + XGCValues gcvalue; + Pixmap pmap = None; + Drawable draw_buffer; - if (buffer_pixmap) { - draw_buffer = buffer_pixmap; - pmap = images[image_bg].current->pmap->pixmap; - } else { - draw_buffer = TermWin.vt; - } - - D_SCREEN(("scr_erase_screen(%d) at screen row: %d\n", mode, screen.row)); - REFRESH_ZERO_SCROLLBACK; - RESET_CHSTAT; - row_offset = TermWin.saveLines; - - - switch (mode) { - case 0: /* erase to end of screen */ - scr_erase_line(0); - row = screen.row + 1; /* possible OOB */ - num = TermWin.nrow - row; - break; - case 1: /* erase to beginning of screen */ - scr_erase_line(1); - row = 0; /* possible OOB */ - num = screen.row; - break; - case 2: /* erase whole screen */ - row = 0; - num = TermWin.nrow; - break; - default: - return; - } - if (row >= 0 && row <= TermWin.nrow) { /* check OOB */ - UPPER_BOUND(num, (TermWin.nrow - row)); - if (rstyle & RS_RVid || rstyle & RS_Uline) - ren = -1; - else { - if (GET_BGCOLOR(rstyle) == bgColor) { - ren = DEFAULT_RSTYLE; - CLEAR_ROWS(row, num); - } else { - ren = (rstyle & (RS_fgMask | RS_bgMask)); - gcvalue.foreground = PixColors[GET_BGCOLOR(ren)]; - gcmask = GCForeground; - XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); - ERASE_ROWS(row, num); - gcvalue.foreground = PixColors[fgColor]; - XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); - } + if (buffer_pixmap) { + draw_buffer = buffer_pixmap; + pmap = images[image_bg].current->pmap->pixmap; + } else { + draw_buffer = TermWin.vt; } - for (; num--; row++) { - blank_screen_mem(screen.text, screen.rend, row + row_offset, rstyle & ~(RS_RVid | RS_Uline)); - blank_screen_mem(drawn_text, drawn_rend, row, ren); + + D_SCREEN(("scr_erase_screen(%d) at screen row: %d\n", mode, screen.row)); + REFRESH_ZERO_SCROLLBACK; + RESET_CHSTAT; + row_offset = TermWin.saveLines; + + + switch (mode) { + case 0: /* erase to end of screen */ + scr_erase_line(0); + row = screen.row + 1; /* possible OOB */ + num = TermWin.nrow - row; + break; + case 1: /* erase to beginning of screen */ + scr_erase_line(1); + row = 0; /* possible OOB */ + num = screen.row; + break; + case 2: /* erase whole screen */ + row = 0; + num = TermWin.nrow; + break; + default: + return; + } + if (row >= 0 && row <= TermWin.nrow) { /* check OOB */ + UPPER_BOUND(num, (TermWin.nrow - row)); + if (rstyle & RS_RVid || rstyle & RS_Uline) + ren = -1; + else { + if (GET_BGCOLOR(rstyle) == bgColor) { + ren = DEFAULT_RSTYLE; + CLEAR_ROWS(row, num); + } else { + ren = (rstyle & (RS_fgMask | RS_bgMask)); + gcvalue.foreground = PixColors[GET_BGCOLOR(ren)]; + gcmask = GCForeground; + XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); + ERASE_ROWS(row, num); + gcvalue.foreground = PixColors[fgColor]; + XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); + } + } + for (; num--; row++) { + blank_screen_mem(screen.text, screen.rend, row + row_offset, rstyle & ~(RS_RVid | RS_Uline)); + blank_screen_mem(drawn_text, drawn_rend, row, ren); + } } - } } /* @@ -1075,23 +1077,23 @@ scr_erase_screen(int mode) void scr_E(void) { - int i, j; - text_t *t; - rend_t *r, fs; + int i, j; + text_t *t; + rend_t *r, fs; - ZERO_SCROLLBACK; - RESET_CHSTAT; + ZERO_SCROLLBACK; + RESET_CHSTAT; - fs = rstyle; - for (i = TermWin.saveLines; i < TermWin.nrow + TermWin.saveLines; i++) { - t = screen.text[i]; - r = screen.rend[i]; - for (j = 0; j < TermWin.ncol; j++) { - *t++ = 'E'; - *r++ = fs; + fs = rstyle; + for (i = TermWin.saveLines; i < TermWin.nrow + TermWin.saveLines; i++) { + t = screen.text[i]; + r = screen.rend[i]; + for (j = 0; j < TermWin.ncol; j++) { + *t++ = 'E'; + *r++ = fs; + } + *t = '\0'; } - *t = '\0'; - } } /* @@ -1100,35 +1102,35 @@ scr_E(void) void scr_insdel_lines(int count, int insdel) { - int end; + int end; - ZERO_SCROLLBACK; - RESET_CHSTAT; + ZERO_SCROLLBACK; + RESET_CHSTAT; - if (screen.row > screen.bscroll) - return; + if (screen.row > screen.bscroll) + return; - end = screen.bscroll - screen.row + 1; - if (count > end) { - if (insdel == DELETE) - return; - else if (insdel == INSERT) - count = end; - } - if (screen.flags & Screen_WrapNext) { - screen.flags &= ~Screen_WrapNext; - } - scroll_text(screen.row, screen.bscroll, insdel * count, 0); + end = screen.bscroll - screen.row + 1; + if (count > end) { + if (insdel == DELETE) + return; + else if (insdel == INSERT) + count = end; + } + if (screen.flags & Screen_WrapNext) { + screen.flags &= ~Screen_WrapNext; + } + scroll_text(screen.row, screen.bscroll, insdel * count, 0); /* fill the inserted or new lines with rstyle. TODO: correct for delete? */ - if (insdel == DELETE) { - end = screen.bscroll + TermWin.saveLines; - } else if (insdel == INSERT) { - end = screen.row + count - 1 + TermWin.saveLines; - } - for (; count--; end--) { - blank_screen_mem(screen.text, screen.rend, end, rstyle); - } + if (insdel == DELETE) { + end = screen.bscroll + TermWin.saveLines; + } else if (insdel == INSERT) { + end = screen.row + count - 1 + TermWin.saveLines; + } + for (; count--; end--) { + blank_screen_mem(screen.text, screen.rend, end, rstyle); + } } /* @@ -1137,56 +1139,52 @@ scr_insdel_lines(int count, int insdel) void scr_insdel_chars(int count, int insdel) { - int col, row; + int col, row; - ZERO_SCROLLBACK; - RESET_CHSTAT; + ZERO_SCROLLBACK; + RESET_CHSTAT; - if (count <= 0) - return; + if (count <= 0) + return; - CHECK_SELECTION; - UPPER_BOUND(count, (TermWin.ncol - screen.col)); + CHECK_SELECTION; + UPPER_BOUND(count, (TermWin.ncol - screen.col)); - row = screen.row + TermWin.saveLines; - screen.flags &= ~Screen_WrapNext; + row = screen.row + TermWin.saveLines; + screen.flags &= ~Screen_WrapNext; - switch (insdel) { - case INSERT: - for (col = TermWin.ncol - 1; (col - count) >= screen.col; col--) { - screen.text[row][col] = screen.text[row][col - count]; - screen.rend[row][col] = screen.rend[row][col - count]; - } - screen.text[row][TermWin.ncol] += count; - UPPER_BOUND(screen.text[row][TermWin.ncol], TermWin.ncol); - /* FALLTHROUGH */ - case ERASE: - blank_line(&(screen.text[row][screen.col]), - &(screen.rend[row][screen.col]), - count, rstyle); - break; - case DELETE: - for (col = screen.col; (col + count) < TermWin.ncol; col++) { - screen.text[row][col] = screen.text[row][col + count]; - screen.rend[row][col] = screen.rend[row][col + count]; - } - blank_line(&(screen.text[row][TermWin.ncol - count]), - &(screen.rend[row][TermWin.ncol - count]), - count, rstyle); - screen.text[row][TermWin.ncol] -= count; - if (((int) (char) screen.text[row][TermWin.ncol]) < 0) - screen.text[row][TermWin.ncol] = 0; - break; - } + switch (insdel) { + case INSERT: + for (col = TermWin.ncol - 1; (col - count) >= screen.col; col--) { + screen.text[row][col] = screen.text[row][col - count]; + screen.rend[row][col] = screen.rend[row][col - count]; + } + screen.text[row][TermWin.ncol] += count; + UPPER_BOUND(screen.text[row][TermWin.ncol], TermWin.ncol); + /* FALLTHROUGH */ + case ERASE: + blank_line(&(screen.text[row][screen.col]), &(screen.rend[row][screen.col]), count, rstyle); + break; + case DELETE: + for (col = screen.col; (col + count) < TermWin.ncol; col++) { + screen.text[row][col] = screen.text[row][col + count]; + screen.rend[row][col] = screen.rend[row][col + count]; + } + blank_line(&(screen.text[row][TermWin.ncol - count]), &(screen.rend[row][TermWin.ncol - count]), count, rstyle); + screen.text[row][TermWin.ncol] -= count; + if (((int) (char) screen.text[row][TermWin.ncol]) < 0) + screen.text[row][TermWin.ncol] = 0; + break; + } #ifdef MULTI_CHARSET - if ((screen.rend[row][0] & RS_multiMask) == RS_multi2) { - screen.rend[row][0] &= ~RS_multiMask; - screen.text[row][0] = ' '; - } - if ((screen.rend[row][TermWin.ncol - 1] & RS_multiMask) == RS_multi1) { - screen.rend[row][TermWin.ncol - 1] &= ~RS_multiMask; - screen.text[row][TermWin.ncol - 1] = ' '; - } + if ((screen.rend[row][0] & RS_multiMask) == RS_multi2) { + screen.rend[row][0] &= ~RS_multiMask; + screen.text[row][0] = ' '; + } + if ((screen.rend[row][TermWin.ncol - 1] & RS_multiMask) == RS_multi1) { + screen.rend[row][TermWin.ncol - 1] &= ~RS_multiMask; + screen.text[row][TermWin.ncol - 1] = ' '; + } #endif } @@ -1197,13 +1195,13 @@ scr_insdel_chars(int count, int insdel) void scr_scroll_region(int top, int bot) { - LOWER_BOUND(top, 0); - UPPER_BOUND(bot, TermWin.nrow - 1); - if (top > bot) - return; - screen.tscroll = top; - screen.bscroll = bot; - scr_gotorc(0, 0, 0); + LOWER_BOUND(top, 0); + UPPER_BOUND(bot, TermWin.nrow - 1); + if (top > bot) + return; + screen.tscroll = top; + screen.bscroll = bot; + scr_gotorc(0, 0, 0); } /* @@ -1214,10 +1212,10 @@ scr_scroll_region(int top, int bot) void scr_cursor_visible(int mode) { - if (mode) - screen.flags |= Screen_VisibleCursor; - else - screen.flags &= ~Screen_VisibleCursor; + if (mode) + screen.flags |= Screen_VisibleCursor; + else + screen.flags &= ~Screen_VisibleCursor; } /* @@ -1228,10 +1226,10 @@ scr_cursor_visible(int mode) void scr_autowrap(int mode) { - if (mode) - screen.flags |= Screen_Autowrap; - else - screen.flags &= ~Screen_Autowrap; + if (mode) + screen.flags |= Screen_Autowrap; + else + screen.flags &= ~Screen_Autowrap; } /* @@ -1246,11 +1244,11 @@ scr_autowrap(int mode) void scr_relative_origin(int mode) { - if (mode) - screen.flags |= Screen_Relative; - else - screen.flags &= ~Screen_Relative; - scr_gotorc(0, 0, 0); + if (mode) + screen.flags |= Screen_Relative; + else + screen.flags &= ~Screen_Relative; + scr_gotorc(0, 0, 0); } /* @@ -1261,10 +1259,10 @@ scr_relative_origin(int mode) void scr_insert_mode(int mode) { - if (mode) - screen.flags |= Screen_Insert; - else - screen.flags &= ~Screen_Insert; + if (mode) + screen.flags |= Screen_Insert; + else + screen.flags &= ~Screen_Insert; } /* @@ -1276,11 +1274,11 @@ scr_insert_mode(int mode) void scr_set_tab(int mode) { - if (mode < 0) - MEMSET(tabs, 0, (unsigned int) TermWin.ncol); + if (mode < 0) + MEMSET(tabs, 0, (unsigned int) TermWin.ncol); - else if (screen.col < TermWin.ncol) - tabs[screen.col] = (mode ? 1 : 0); + else if (screen.col < TermWin.ncol) + tabs[screen.col] = (mode ? 1 : 0); } /* @@ -1291,18 +1289,18 @@ scr_set_tab(int mode) void scr_rvideo_mode(int mode) { - int i, j, maxlines; + int i, j, maxlines; - if (rvideo != mode) { - rvideo = mode; - rstyle ^= RS_RVid; + if (rvideo != mode) { + rvideo = mode; + rstyle ^= RS_RVid; - maxlines = TermWin.saveLines + TermWin.nrow; - for (i = TermWin.saveLines; i < maxlines; i++) - for (j = 0; j < TermWin.ncol + 1; j++) - screen.rend[i][j] ^= RS_RVid; - scr_refresh(SLOW_REFRESH); - } + maxlines = TermWin.saveLines + TermWin.nrow; + for (i = TermWin.saveLines; i < maxlines; i++) + for (j = 0; j < TermWin.ncol + 1; j++) + screen.rend[i][j] ^= RS_RVid; + scr_refresh(SLOW_REFRESH); + } } /* @@ -1312,32 +1310,32 @@ scr_rvideo_mode(int mode) void scr_report_position(void) { - tt_printf((unsigned char *) "\033[%d;%dR", screen.row + 1, screen.col + 1); + tt_printf((unsigned char *) "\033[%d;%dR", screen.row + 1, screen.col + 1); } /* Set font style */ void set_font_style(void) { - rstyle &= ~RS_fontMask; - switch (charsets[screen.charset]) { - case '0': /* DEC Special Character & Line Drawing Set */ - rstyle |= RS_acsFont; - break; - case 'A': /* United Kingdom (UK) */ - rstyle |= RS_ukFont; - break; - case 'B': /* United States (USASCII) */ - break; - case '<': /* Multinational character set */ - break; - case '5': /* Finnish character set */ - break; - case 'C': /* Finnish character set */ - break; - case 'K': /* German character set */ - break; - } + rstyle &= ~RS_fontMask; + switch (charsets[screen.charset]) { + case '0': /* DEC Special Character & Line Drawing Set */ + rstyle |= RS_acsFont; + break; + case 'A': /* United Kingdom (UK) */ + rstyle |= RS_ukFont; + break; + case 'B': /* United States (USASCII) */ + break; + case '<': /* Multinational character set */ + break; + case '5': /* Finnish character set */ + break; + case 'C': /* Finnish character set */ + break; + case 'K': /* German character set */ + break; + } } /* @@ -1350,8 +1348,8 @@ set_font_style(void) void scr_charset_choose(int set) { - screen.charset = set; - set_font_style(); + screen.charset = set; + set_font_style(); } /* @@ -1366,11 +1364,11 @@ void scr_charset_set(int set, unsigned int ch) { #ifdef MULTI_CHARSET - multi_byte = (set < 0); - set = abs(set); + multi_byte = (set < 0); + set = abs(set); #endif - charsets[set] = (unsigned char) ch; - set_font_style(); + charsets[set] = (unsigned char) ch; + set_font_style(); } #ifdef MULTI_CHARSET @@ -1385,47 +1383,47 @@ static void (*multichar_decode) (unsigned char *str, int len) = latin1; static void latin1(unsigned char *str, int len) { - return; - str = NULL; - len = 0; + return; + str = NULL; + len = 0; } static void eucj2jis(unsigned char *str, int len) { - register int i; + register int i; - for (i = 0; i < len; i++) - str[i] &= 0x7F; + for (i = 0; i < len; i++) + str[i] &= 0x7F; } static void sjis2jis(unsigned char *str, int len) { - register int i; - unsigned char *high, *low; + register int i; + unsigned char *high, *low; - for (i = 0; i < len; i += 2, str += 2) { - high = str; - low = str + 1; - (*high) -= (*high > 0x9F ? 0xB1 : 0x71); - *high = (*high) * 2 + 1; - if (*low > 0x9E) { - *low -= 0x7E; - (*high)++; - } else { - if (*low > 0x7E) - (*low)--; - *low -= 0x1F; + for (i = 0; i < len; i += 2, str += 2) { + high = str; + low = str + 1; + (*high) -= (*high > 0x9F ? 0xB1 : 0x71); + *high = (*high) * 2 + 1; + if (*low > 0x9E) { + *low -= 0x7E; + (*high)++; + } else { + if (*low > 0x7E) + (*low)--; + *low -= 0x1F; + } } - } } static void big5dummy(unsigned char *str, int len) { - str = NULL; - len = 0; + str = NULL; + len = 0; } #endif @@ -1433,24 +1431,24 @@ void set_multichar_encoding(const char *str) { #ifdef MULTI_CHARSET - if (str && *str) { - if (!strcasecmp(str, "sjis")) { - encoding_method = SJIS; - multichar_decode = sjis2jis; - } else if (!strcasecmp(str, "eucj") || !strcasecmp(str, "euckr") || !strcasecmp(str, "gb")) { - encoding_method = EUCJ; - multichar_decode = eucj2jis; - } else if (!strcasecmp(str, "big5")) { - encoding_method = BIG5; - multichar_decode = big5dummy; - } else { - encoding_method = LATIN1; - multichar_decode = latin1; + if (str && *str) { + if (!strcasecmp(str, "sjis")) { + encoding_method = SJIS; + multichar_decode = sjis2jis; + } else if (!strcasecmp(str, "eucj") || !strcasecmp(str, "euckr") || !strcasecmp(str, "gb")) { + encoding_method = EUCJ; + multichar_decode = eucj2jis; + } else if (!strcasecmp(str, "big5")) { + encoding_method = BIG5; + multichar_decode = big5dummy; + } else { + encoding_method = LATIN1; + multichar_decode = latin1; + } } - } #else - return; - str = NULL; + return; + str = NULL; #endif /* MULTI_CHARSET */ } @@ -1458,30 +1456,30 @@ set_multichar_encoding(const char *str) void scr_expose(int x, int y, int width, int height) { - int i; - register short nc, nr; - row_col_t rect_beg, rect_end; + int i; + register short nc, nr; + row_col_t rect_beg, rect_end; - REQUIRE(drawn_text != NULL); + REQUIRE(drawn_text != NULL); - nc = TermWin.ncol - 1; - nr = TermWin.nrow - 1; + nc = TermWin.ncol - 1; + nr = TermWin.nrow - 1; - rect_beg.col = Pixel2Col(x); - BOUND(rect_beg.col, 0, nc); - rect_beg.row = Pixel2Row(y); - BOUND(rect_beg.row, 0, nr); - rect_end.col = Pixel2Width(x + width + TermWin.fwidth - 1); - BOUND(rect_end.col, 0, nc); - rect_end.row = Pixel2Row(y + height + TermWin.fheight - 1); - BOUND(rect_end.row, 0, nr); + rect_beg.col = Pixel2Col(x); + BOUND(rect_beg.col, 0, nc); + rect_beg.row = Pixel2Row(y); + BOUND(rect_beg.row, 0, nr); + rect_end.col = Pixel2Width(x + width + TermWin.fwidth - 1); + BOUND(rect_end.col, 0, nc); + rect_end.row = Pixel2Row(y + height + TermWin.fheight - 1); + BOUND(rect_end.row, 0, nr); - D_SCREEN(("scr_expose(x:%d, y:%d, w:%d, h:%d) area (c:%d,r:%d)-(c:%d,r:%d)\n", x, y, width, height, rect_beg.col, rect_beg.row, - rect_end.col, rect_end.row)); + D_SCREEN(("scr_expose(x:%d, y:%d, w:%d, h:%d) area (c:%d,r:%d)-(c:%d,r:%d)\n", x, y, width, height, rect_beg.col, rect_beg.row, + rect_end.col, rect_end.row)); - for (i = rect_beg.row; i <= rect_end.row; i++) { - MEMSET(&(drawn_text[i][rect_beg.col]), 0, rect_end.col - rect_beg.col + 1); - } + for (i = rect_beg.row; i <= rect_end.row; i++) { + MEMSET(&(drawn_text[i][rect_beg.col]), 0, rect_end.col - rect_beg.col + 1); + } } /* Move the display so that the line represented by scrollbar value Y is at @@ -1489,31 +1487,31 @@ scr_expose(int x, int y, int width, int height) int scr_move_to(int y, int len) { - int start; + int start; - start = TermWin.view_start; - TermWin.view_start = ((len - y) * (TermWin.nrow - 1 + TermWin.nscrolled) - / (len)) - (TermWin.nrow - 1); - D_SCREEN(("scr_move_to(%d, %d) view_start:%d\n", y, len, TermWin.view_start)); + start = TermWin.view_start; + TermWin.view_start = ((len - y) * (TermWin.nrow - 1 + TermWin.nscrolled) + / (len)) - (TermWin.nrow - 1); + D_SCREEN(("scr_move_to(%d, %d) view_start:%d\n", y, len, TermWin.view_start)); - BOUND(TermWin.view_start, 0, TermWin.nscrolled); + BOUND(TermWin.view_start, 0, TermWin.nscrolled); - return (TermWin.view_start - start); + return (TermWin.view_start - start); } /* Scroll the visible region up/down by lines */ int scr_page(int direction, int nlines) { - int start; + int start; - D_SCREEN(("scr_page(%s, %d) view_start:%d\n", ((direction == UP) ? "UP" : "DN"), nlines, TermWin.view_start)); + D_SCREEN(("scr_page(%s, %d) view_start:%d\n", ((direction == UP) ? "UP" : "DN"), nlines, TermWin.view_start)); - start = TermWin.view_start; - BOUND(nlines, 1, TermWin.nrow); - TermWin.view_start += ((direction == UP) ? nlines : (-nlines)); - BOUND(TermWin.view_start, 0, TermWin.nscrolled); - return (TermWin.view_start - start); + start = TermWin.view_start; + BOUND(nlines, 1, TermWin.nrow); + TermWin.view_start += ((direction == UP) ? nlines : (-nlines)); + BOUND(TermWin.view_start, 0, TermWin.nscrolled); + return (TermWin.view_start - start); } void @@ -1521,45 +1519,45 @@ scr_bell(void) { #ifndef NO_MAPALERT #ifdef MAPALERT_OPTION - if (Options & Opt_map_alert) + if (Options & Opt_map_alert) #endif - XMapWindow(Xdisplay, TermWin.parent); + XMapWindow(Xdisplay, TermWin.parent); #endif - if (Options & Opt_visual_bell) { - scr_rvideo_mode(!rvideo); - scr_rvideo_mode(!rvideo); - } else - XBell(Xdisplay, 0); + if (Options & Opt_visual_bell) { + scr_rvideo_mode(!rvideo); + scr_rvideo_mode(!rvideo); + } else + XBell(Xdisplay, 0); } void scr_printscreen(int fullhist) { #ifdef PRINTPIPE - int i, r, nrows, row_offset; - text_t *t; - FILE *fd; + int i, r, nrows, row_offset; + text_t *t; + FILE *fd; - if ((fd = popen_printer()) == NULL) - return; - nrows = TermWin.nrow; - if (fullhist) { - /* Print the entire scrollback buffer. Always start from the top and go all the way to the bottom. */ - nrows += TermWin.nscrolled; - row_offset = TermWin.saveLines - TermWin.nscrolled; - } else { - /* Just print what's on the screen. */ - row_offset = TermWin.saveLines - TermWin.view_start; - } + if ((fd = popen_printer()) == NULL) + return; + nrows = TermWin.nrow; + if (fullhist) { + /* Print the entire scrollback buffer. Always start from the top and go all the way to the bottom. */ + nrows += TermWin.nscrolled; + row_offset = TermWin.saveLines - TermWin.nscrolled; + } else { + /* Just print what's on the screen. */ + row_offset = TermWin.saveLines - TermWin.view_start; + } - for (r = 0; r < nrows; r++) { - t = screen.text[r + row_offset]; - for (i = TermWin.ncol - 1; i >= 0; i--) - if (!isspace(t[i])) - break; - fprintf(fd, "%.*s\n", (i + 1), t); - } - pclose_printer(fd); + for (r = 0; r < nrows; r++) { + t = screen.text[r + row_offset]; + for (i = TermWin.ncol - 1; i >= 0; i--) + if (!isspace(t[i])) + break; + fprintf(fd, "%.*s\n", (i + 1), t); + } + pclose_printer(fd); #endif } @@ -1567,21 +1565,21 @@ scr_printscreen(int fullhist) int scr_multi1(void) { - rend_t rend; + rend_t rend; - rend = screen.rend[screen.row + TermWin.saveLines][screen.col]; - return ((rend & RS_multiMask) == RS_multi1); + rend = screen.rend[screen.row + TermWin.saveLines][screen.col]; + return ((rend & RS_multiMask) == RS_multi1); } int scr_multi2(void) { - rend_t rend; + rend_t rend; - if (screen.col == 0) - return 0; - rend = screen.rend[screen.row + TermWin.saveLines][screen.col - 1]; - return ((rend & RS_multiMask) == RS_multi2); + if (screen.col == 0) + return 0; + rend = screen.rend[screen.row + TermWin.saveLines][screen.col - 1]; + return ((rend & RS_multiMask) == RS_multi2); } #endif /* MULTI_CHARSET */ @@ -1594,719 +1592,722 @@ scr_multi2(void) void scr_refresh(int type) { - int i, /* tmp */ - scrrow, /* screen row offset */ - row_offset, /* basic offset in screen structure */ - boldlast = 0, /* last character in some row was bold */ - len, wlen, /* text length screen/buffer */ - fprop, /* proportional font used */ - is_cursor, /* cursor this position */ - rvid, /* reverse video this position */ - fore, back, /* desired foreground/background */ - wbyte, /* we're in multibyte */ - xpixel, /* x offset for start of drawing (font) */ - ypixel; /* y offset for start of drawing (font) */ - register int col, row, /* column/row we're processing */ - rend; /* rendition */ - static int focus = -1; /* screen in focus? */ - long gcmask; /* Graphics Context mask */ - unsigned long ltmp; - rend_t rt1, rt2, /* tmp rend values */ - lastrend; /* rend type of last char in drawing set */ - text_t lasttext; /* last char being replaced in drawing set */ - rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ - text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ - XGCValues gcvalue; /* Graphics Context values */ - char buf[MAX_COLS + 1]; - register char *buffer = buf; - Pixmap pmap = images[image_bg].current->pmap->pixmap; - int (*draw_string) (), (*draw_image_string) (); - register int low_x = 99999, low_y = 99999, high_x = 0, high_y = 0; - Drawable draw_buffer; + int i, /* tmp */ + scrrow, /* screen row offset */ + row_offset, /* basic offset in screen structure */ + boldlast = 0, /* last character in some row was bold */ + len, wlen, /* text length screen/buffer */ + fprop, /* proportional font used */ + is_cursor, /* cursor this position */ + rvid, /* reverse video this position */ + fore, back, /* desired foreground/background */ + wbyte, /* we're in multibyte */ + xpixel, /* x offset for start of drawing (font) */ + ypixel; /* y offset for start of drawing (font) */ + register int col, row, /* column/row we're processing */ + rend; /* rendition */ + static int focus = -1; /* screen in focus? */ + long gcmask; /* Graphics Context mask */ + unsigned long ltmp; + rend_t rt1, rt2, /* tmp rend values */ + lastrend; /* rend type of last char in drawing set */ + text_t lasttext; /* last char being replaced in drawing set */ + rend_t *drp, *srp; /* drawn-rend-pointer, screen-rend-pointer */ + text_t *dtp, *stp; /* drawn-text-pointer, screen-text-pointer */ + XGCValues gcvalue; /* Graphics Context values */ + char buf[MAX_COLS + 1]; + register char *buffer = buf; + Pixmap pmap = images[image_bg].current->pmap->pixmap; + int (*draw_string) (), (*draw_image_string) (); + register int low_x = 99999, low_y = 99999, high_x = 0, high_y = 0; + Drawable draw_buffer; #ifndef NO_BOLDFONT - int bfont = 0; /* we've changed font to bold font */ + int bfont = 0; /* we've changed font to bold font */ #endif #ifdef OPTIMIZE_HACKS - register int nrows = TermWin.nrow; - register int ncols = TermWin.ncol; + register int nrows = TermWin.nrow; + register int ncols = TermWin.ncol; #endif - int ascent, descent; + int ascent, descent; - PROF_INIT(scr_refresh); +#ifdef ESCREEN + if (TermWin.screen_mode) + nrows--; +#endif - switch (type) { - case NO_REFRESH: - D_SCREEN(("scr_refresh(NO_REFRESH) called.\n")); - break; - case SLOW_REFRESH: - D_SCREEN(("scr_refresh(SLOW_REFRESH) called.\n")); - break; - case FAST_REFRESH: - D_SCREEN(("scr_refresh(FAST_REFRESH) called.\n")); - break; - } - if (type == NO_REFRESH) - return; + PROF_INIT(scr_refresh); - if (buffer_pixmap) { - draw_buffer = buffer_pixmap; - } else { - draw_buffer = TermWin.vt; - } - - row_offset = TermWin.saveLines - TermWin.view_start; - fprop = TermWin.fprop; - - gcvalue.foreground = PixColors[fgColor]; - gcvalue.background = PixColors[bgColor]; - wbyte = 0; - - XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid); - - draw_string = XDrawString; - draw_image_string = XDrawImageString; - - BOUND(screen.row, 0, TermWin.nrow - 1); - BOUND(screen.col, 0, TermWin.ncol - 1); - - row = screen.row + TermWin.saveLines; - col = screen.col; - if (screen.flags & Screen_VisibleCursor) { - screen.rend[row][col] |= RS_Cursor; -#ifdef MULTI_CHARSET - srp = &screen.rend[row][col]; - if ((col < ncols - 1) && ((srp[0] & RS_multiMask) == RS_multi1) - && ((srp[1] & RS_multiMask) == RS_multi2)) { - screen.rend[row][col + 1] |= RS_Cursor; - } else if ((col > 0) && ((srp[0] & RS_multiMask) == RS_multi2) - && ((srp[-1] & RS_multiMask) == RS_multi1)) { - screen.rend[row][col - 1] |= RS_Cursor; + switch (type) { + case NO_REFRESH: + D_SCREEN(("scr_refresh(NO_REFRESH) called.\n")); + break; + case SLOW_REFRESH: + D_SCREEN(("scr_refresh(SLOW_REFRESH) called.\n")); + break; + case FAST_REFRESH: + D_SCREEN(("scr_refresh(FAST_REFRESH) called.\n")); + break; } -#endif - if (focus != TermWin.focus) { - focus = TermWin.focus; - if ((i = screen.row - TermWin.view_start) >= 0) { - drawn_rend[i][col] = RS_attrMask; -#ifdef MULTI_CHARSET - if ((col < ncols - 1) && ((srp[1] & RS_multiMask) == RS_multi2)) { - drawn_rend[i][col + 1] = RS_attrMask; - } else if ((col > 0) && ((srp[-1] & RS_multiMask) == RS_multi1)) { - drawn_rend[i][col - 1] = RS_attrMask; - } -#endif - } + if (type == NO_REFRESH) + return; + + if (buffer_pixmap) { + draw_buffer = buffer_pixmap; + } else { + draw_buffer = TermWin.vt; } - } - for (row = 0; row < nrows; row++) { - scrrow = row + row_offset; - stp = screen.text[scrrow]; - srp = screen.rend[scrrow]; - dtp = drawn_text[row]; - drp = drawn_rend[row]; + row_offset = TermWin.saveLines - TermWin.view_start; + fprop = TermWin.fprop; - for (col = 0; col < ncols; col++) { - if (!refresh_all) { - /* compare new text with old - if exactly the same then continue */ - rt1 = srp[col]; - rt2 = drp[col]; - if ((stp[col] == dtp[col]) /* must match characters to skip */ - && ((rt1 == rt2) /* either rendition the same or */ - || ((stp[col] == ' ') /* space w/ no bg change */ - && (GET_BGATTR(rt1) == GET_BGATTR(rt2))))) { + gcvalue.foreground = PixColors[fgColor]; + gcvalue.background = PixColors[bgColor]; + wbyte = 0; + + XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid); + + draw_string = XDrawString; + draw_image_string = XDrawImageString; + + BOUND(screen.row, 0, TermWin.nrow - 1); + BOUND(screen.col, 0, TermWin.ncol - 1); + + row = screen.row + TermWin.saveLines; + col = screen.col; + if (screen.flags & Screen_VisibleCursor) { + screen.rend[row][col] |= RS_Cursor; #ifdef MULTI_CHARSET - /* if first byte is multibyte then compare second bytes */ - if ((rt1 & RS_multiMask) != RS_multi1) - continue; - else if (stp[col + 1] == dtp[col + 1]) { - /* assume no corrupt characters on the screen */ - col++; - continue; - } -#else - continue; -#endif + srp = &screen.rend[row][col]; + if ((col < ncols - 1) && ((srp[0] & RS_multiMask) == RS_multi1) + && ((srp[1] & RS_multiMask) == RS_multi2)) { + screen.rend[row][col + 1] |= RS_Cursor; + } else if ((col > 0) && ((srp[0] & RS_multiMask) == RS_multi2) + && ((srp[-1] & RS_multiMask) == RS_multi1)) { + screen.rend[row][col - 1] |= RS_Cursor; } - } - lasttext = dtp[col]; - lastrend = drp[col]; - /* redraw one or more characters */ - dtp[col] = stp[col]; - rend = drp[col] = srp[col]; +#endif + if (focus != TermWin.focus) { + focus = TermWin.focus; + if ((i = screen.row - TermWin.view_start) >= 0) { + drawn_rend[i][col] = RS_attrMask; +#ifdef MULTI_CHARSET + if ((col < ncols - 1) && ((srp[1] & RS_multiMask) == RS_multi2)) { + drawn_rend[i][col + 1] = RS_attrMask; + } else if ((col > 0) && ((srp[-1] & RS_multiMask) == RS_multi1)) { + drawn_rend[i][col - 1] = RS_attrMask; + } +#endif + } + } + } - len = 0; - buffer[len++] = stp[col]; - xpixel = Col2Pixel(col); - wlen = 1; + for (row = 0; row < nrows; row++) { + scrrow = row + row_offset; + stp = screen.text[scrrow]; + srp = screen.rend[scrrow]; + dtp = drawn_text[row]; + drp = drawn_rend[row]; + + for (col = 0; col < ncols; col++) { + if (!refresh_all) { + /* compare new text with old - if exactly the same then continue */ + rt1 = srp[col]; + rt2 = drp[col]; + if ((stp[col] == dtp[col]) /* must match characters to skip */ + &&((rt1 == rt2) /* either rendition the same or */ + ||((stp[col] == ' ') /* space w/ no bg change */ + &&(GET_BGATTR(rt1) == GET_BGATTR(rt2))))) { +#ifdef MULTI_CHARSET + /* if first byte is multibyte then compare second bytes */ + if ((rt1 & RS_multiMask) != RS_multi1) + continue; + else if (stp[col + 1] == dtp[col + 1]) { + /* assume no corrupt characters on the screen */ + col++; + continue; + } +#else + continue; +#endif + } + } + lasttext = dtp[col]; + lastrend = drp[col]; + /* redraw one or more characters */ + dtp[col] = stp[col]; + rend = drp[col] = srp[col]; + + len = 0; + buffer[len++] = stp[col]; + xpixel = Col2Pixel(col); + wlen = 1; /* * Find out the longest string we can write out at once */ - if (fprop == 0) { /* Fixed width font */ + if (fprop == 0) { /* Fixed width font */ #ifdef MULTI_CHARSET - if (((rend & RS_multiMask) == RS_multi1) && (col < ncols - 1) - && ((srp[col + 1]) & RS_multiMask) == RS_multi2) { - if (!wbyte) { - wbyte = 1; - XSetFont(Xdisplay, TermWin.gc, TermWin.mfont->fid); - draw_string = XDrawString16; - draw_image_string = XDrawImageString16; - } - /* double stepping - we're in Multibyte mode */ - for (; ++col < ncols;) { - /* XXX: could check sanity on 2nd byte */ - dtp[col] = stp[col]; - drp[col] = srp[col]; - buffer[len++] = stp[col]; - col++; - if ((col == ncols) || (srp[col] != (unsigned int) rend)) - break; - if ((stp[col] == dtp[col]) - && (srp[col] == drp[col]) - && (stp[col + 1] == dtp[col + 1])) - break; - if (len == MAX_COLS) - break; - dtp[col] = stp[col]; - drp[col] = srp[col]; - buffer[len++] = stp[col]; - } - col--; - if (buffer[0] & 0x80) - multichar_decode(buffer, len); - wlen = len / 2; - } else { - if ((rend & RS_multiMask) == RS_multi1) { - /* XXX : maybe do the same thing for RS_multi2 */ - /* corrupt character - you're outta there */ - rend &= ~RS_multiMask; - drp[col] = rend; /* TODO check: may also want */ - dtp[col] = ' '; /* to poke into stp/srp */ - buffer[0] = ' '; - } - if (wbyte) { - wbyte = 0; - XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid); - draw_string = XDrawString; - draw_image_string = XDrawImageString; - } + if (((rend & RS_multiMask) == RS_multi1) && (col < ncols - 1) + && ((srp[col + 1]) & RS_multiMask) == RS_multi2) { + if (!wbyte) { + wbyte = 1; + XSetFont(Xdisplay, TermWin.gc, TermWin.mfont->fid); + draw_string = XDrawString16; + draw_image_string = XDrawImageString16; + } + /* double stepping - we're in Multibyte mode */ + for (; ++col < ncols;) { + /* XXX: could check sanity on 2nd byte */ + dtp[col] = stp[col]; + drp[col] = srp[col]; + buffer[len++] = stp[col]; + col++; + if ((col == ncols) || (srp[col] != (unsigned int) rend)) + break; + if ((stp[col] == dtp[col]) + && (srp[col] == drp[col]) + && (stp[col + 1] == dtp[col + 1])) + break; + if (len == MAX_COLS) + break; + dtp[col] = stp[col]; + drp[col] = srp[col]; + buffer[len++] = stp[col]; + } + col--; + if (buffer[0] & 0x80) + multichar_decode(buffer, len); + wlen = len / 2; + } else { + if ((rend & RS_multiMask) == RS_multi1) { + /* XXX : maybe do the same thing for RS_multi2 */ + /* corrupt character - you're outta there */ + rend &= ~RS_multiMask; + drp[col] = rend; /* TODO check: may also want */ + dtp[col] = ' '; /* to poke into stp/srp */ + buffer[0] = ' '; + } + if (wbyte) { + wbyte = 0; + XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid); + draw_string = XDrawString; + draw_image_string = XDrawImageString; + } #endif - /* single stepping - `normal' mode */ - for (; ++col < ncols - 1;) { - if ((unsigned int) rend != srp[col]) - break; - if ((stp[col] == dtp[col]) && (srp[col] == drp[col])) - break; - if (len == MAX_COLS) - break; - lasttext = dtp[col]; - lastrend = drp[col]; - dtp[col] = stp[col]; - drp[col] = srp[col]; - buffer[len++] = stp[col]; - } - col--; - wlen = len; + /* single stepping - `normal' mode */ + for (; ++col < ncols - 1;) { + if ((unsigned int) rend != srp[col]) + break; + if ((stp[col] == dtp[col]) && (srp[col] == drp[col])) + break; + if (len == MAX_COLS) + break; + lasttext = dtp[col]; + lastrend = drp[col]; + dtp[col] = stp[col]; + drp[col] = srp[col]; + buffer[len++] = stp[col]; + } + col--; + wlen = len; #ifdef MULTI_CHARSET - } -#endif - } - buffer[len] = '\0'; - - /* Determine the attributes for the string */ - fore = GET_FGCOLOR(rend); - back = GET_BGCOLOR(rend); - rend = GET_ATTR(rend); - gcmask = 0; - rvid = (rend & RS_RVid) ? 1 : 0; - if (rend & RS_Select) - rvid = !rvid; - if (rend & RS_Cursor) { - if (focus) { - is_cursor = 2; /* normal cursor */ - rvid = !rvid; - } else { - is_cursor = 1; /* outline cursor */ - rend &= ~RS_Cursor; - } - srp[col] &= ~RS_Cursor; - } else - is_cursor = 0; - switch (rend & RS_fontMask) { - case RS_acsFont: - for (i = 0; i < len; i++) - if (buffer[i] == 0x5f) - buffer[i] = 0x7f; - else if (buffer[i] > 0x5f && buffer[i] < 0x7f) - buffer[i] -= 0x5f; - break; - case RS_ukFont: - for (i = 0; i < len; i++) - if (buffer[i] == '#') - buffer[i] = 0x1e; - break; - } - if (rvid) - SWAP_IT(fore, back, i); - if (back != bgColor) { - gcvalue.background = PixColors[back]; - gcmask |= GCBackground; - } - if (fore != fgColor) { - gcvalue.foreground = PixColors[fore]; - gcmask |= GCForeground; - } -#ifndef NO_BOLDUNDERLINE - else if (rend & RS_Bold) { - if (PixColors[fore] != PixColors[colorBD] - && PixColors[back] != PixColors[colorBD]) { - gcvalue.foreground = PixColors[colorBD]; - gcmask |= GCForeground; - } - } else if (rend & RS_Uline) { - if (PixColors[fore] != PixColors[colorUL] - && PixColors[back] != PixColors[colorUL]) { - gcvalue.foreground = PixColors[colorUL]; - gcmask |= GCForeground; - } - } -#endif -#ifndef NO_CURSORCOLOR - if (rend & RS_Cursor) { - if (PixColors[cursorColor] != PixColors[bgColor]) { - gcvalue.background = PixColors[cursorColor]; - back = cursorColor; - gcmask |= GCBackground; - } - if (PixColors[cursorColor2] != PixColors[fgColor]) { - gcvalue.foreground = PixColors[cursorColor2]; - gcmask |= GCForeground; - } - } -#endif - if (gcmask) { - XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); - } -#ifndef NO_BOLDFONT - if (!wbyte && MONO_BOLD(rend) && TermWin.boldFont != NULL) { - XSetFont(Xdisplay, TermWin.gc, TermWin.boldFont->fid); - bfont = 1; - } else if (bfont) { - bfont = 0; - XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid); - } -#endif - -#ifdef MULTI_CHARSET - ascent = MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->ascent), TermWin.font->ascent); - descent = MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->descent), TermWin.font->descent); -#else - ascent = TermWin.font->ascent; - descent = TermWin.font->descent; -#endif - ypixel = ascent + Row2Pixel(row); - - - /* The actual drawing of the string is done here. */ - if (fprop) { - if (back != bgColor) { - SWAP_IT(gcvalue.foreground, gcvalue.background, ltmp); - gcmask |= (GCForeground | GCBackground); - XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); - XFillRectangle(Xdisplay, draw_buffer, TermWin.gc, xpixel, ypixel - ascent, Width2Pixel(1), Height2Pixel(1)); - SWAP_IT(gcvalue.foreground, gcvalue.background, ltmp); - XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); - } else { - CLEAR_CHARS(xpixel, ypixel - ascent, 1); - } - if (TermWin.font->per_char) { - int fw, cw; - - fw = TermWin.fwidth; - cw = TermWin.font->per_char[((int) (*buffer))].width; - if (cw > 0 && cw < TermWin.font->max_bounds.width) { - if (fw > cw) { - xpixel += ((fw - cw) >> 1); - } else { - xpixel -= ((cw - fw) >> 1); - if (col < ncols - 1) { - dtp[col + 1] = 0; - } - } - } - } - DRAW_STRING(draw_string, xpixel, ypixel, buffer, 1); - UPDATE_BOX(xpixel, ypixel - ascent, xpixel + Width2Pixel(1), ypixel + Height2Pixel(1)); -#ifndef NO_BOLDOVERSTRIKE - if (MONO_BOLD(rend)) { - DRAW_STRING(draw_string, xpixel + 1, ypixel, buffer, 1); - UPDATE_BOX(xpixel + 1, ypixel - ascent, xpixel + 1 + Width2Pixel(1), ypixel + Height2Pixel(1)); - } -#endif - } else { -#ifdef PIXMAP_SUPPORT - if (background_is_pixmap() && (back == bgColor)) { - if (fshadow.do_shadow) { - Pixel tmp; - int xx, yy, ww, hh; - - tmp = gcvalue.foreground; - xx = xpixel; - yy = ypixel - ascent; - ww = Width2Pixel(wlen); - hh = Height2Pixel(1); - CLEAR_CHARS(xpixel, ypixel - ascent, len); - if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_TOP_RIGHT]) { - yy--; - hh++; - } - if (fshadow.shadow[SHADOW_BOTTOM_LEFT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT]) { - hh++; - if (row < nrows - 1) { - int ii; - - for (ii = col - len + 1; ii <= col; ii++) { - drawn_text[row + 1][ii] = 0; } - } - } - if (fshadow.shadow[SHADOW_TOP_LEFT]) { - XSetForeground(Xdisplay, TermWin.gc, fshadow.color[SHADOW_TOP_LEFT]); - DRAW_STRING(draw_string, xpixel - 1, ypixel - 1, buffer, wlen); - if (col) { - dtp[col - 1] = 0; - } - } - if (fshadow.shadow[SHADOW_TOP_RIGHT]) { - XSetForeground(Xdisplay, TermWin.gc, fshadow.color[SHADOW_TOP_RIGHT]); - DRAW_STRING(draw_string, xpixel + 1, ypixel - 1, buffer, wlen); - if (col < ncols - 1) { - dtp[col + 1] = 0; - } - } - if (fshadow.shadow[SHADOW_BOTTOM_LEFT]) { - XSetForeground(Xdisplay, TermWin.gc, fshadow.color[SHADOW_BOTTOM_LEFT]); - DRAW_STRING(draw_string, xpixel - 1, ypixel + 1, buffer, wlen); - if (col) { - dtp[col - 1] = 0; - } - } - if (fshadow.shadow[SHADOW_BOTTOM_RIGHT]) { - XSetForeground(Xdisplay, TermWin.gc, fshadow.color[SHADOW_BOTTOM_RIGHT]); - DRAW_STRING(draw_string, xpixel + 1, ypixel + 1, buffer, wlen); - if (col < ncols - 1) { - dtp[col + 1] = 0; - } - } - XSetForeground(Xdisplay, TermWin.gc, tmp); - DRAW_STRING(draw_string, xpixel, ypixel, buffer, wlen); - UPDATE_BOX(xx, yy, xx + ww, yy + hh); - } else { - CLEAR_CHARS(xpixel, ypixel - ascent, len); - DRAW_STRING(draw_string, xpixel, ypixel, buffer, wlen); - UPDATE_BOX(xpixel, ypixel - ascent, xpixel + Width2Pixel(wlen), ypixel + Height2Pixel(1)); - } - } else #endif - { -#ifdef FORCE_CLEAR_CHARS - CLEAR_CHARS(xpixel, ypixel - ascent, len); -#endif - DRAW_STRING(draw_image_string, xpixel, ypixel, buffer, wlen); -#ifdef MULTI_CHARSET - { - XFontStruct *font = wbyte? TermWin.mfont: TermWin.font; + } + buffer[len] = '\0'; - if (font->ascent < ascent || font->descent < descent) { - SWAP_IT(gcvalue.foreground, gcvalue.background, ltmp); - gcmask |= (GCForeground | GCBackground); - XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); - if (font->ascent < ascent) { - XFillRectangle(Xdisplay, draw_buffer, TermWin.gc, xpixel, - Row2Pixel(row), - Width2Pixel(len), - ascent - font->ascent); - } - if (font->descent < descent) { - XFillRectangle(Xdisplay, draw_buffer, TermWin.gc, xpixel, - Row2Pixel(row) + ascent + font->descent, - Width2Pixel(len), - descent - font->descent); - } - SWAP_IT(gcvalue.foreground, gcvalue.background, ltmp); - XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); - } - } + /* Determine the attributes for the string */ + fore = GET_FGCOLOR(rend); + back = GET_BGCOLOR(rend); + rend = GET_ATTR(rend); + gcmask = 0; + rvid = (rend & RS_RVid) ? 1 : 0; + if (rend & RS_Select) + rvid = !rvid; + if (rend & RS_Cursor) { + if (focus) { + is_cursor = 2; /* normal cursor */ + rvid = !rvid; + } else { + is_cursor = 1; /* outline cursor */ + rend &= ~RS_Cursor; + } + srp[col] &= ~RS_Cursor; + } else + is_cursor = 0; + switch (rend & RS_fontMask) { + case RS_acsFont: + for (i = 0; i < len; i++) + if (buffer[i] == 0x5f) + buffer[i] = 0x7f; + else if (buffer[i] > 0x5f && buffer[i] < 0x7f) + buffer[i] -= 0x5f; + break; + case RS_ukFont: + for (i = 0; i < len; i++) + if (buffer[i] == '#') + buffer[i] = 0x1e; + break; + } + if (rvid) + SWAP_IT(fore, back, i); + if (back != bgColor) { + gcvalue.background = PixColors[back]; + gcmask |= GCBackground; + } + if (fore != fgColor) { + gcvalue.foreground = PixColors[fore]; + gcmask |= GCForeground; + } +#ifndef NO_BOLDUNDERLINE + else if (rend & RS_Bold) { + if (PixColors[fore] != PixColors[colorBD] + && PixColors[back] != PixColors[colorBD]) { + gcvalue.foreground = PixColors[colorBD]; + gcmask |= GCForeground; + } + } else if (rend & RS_Uline) { + if (PixColors[fore] != PixColors[colorUL] + && PixColors[back] != PixColors[colorUL]) { + gcvalue.foreground = PixColors[colorUL]; + gcmask |= GCForeground; + } + } #endif - UPDATE_BOX(xpixel, ypixel - ascent, xpixel + Width2Pixel(wlen), ypixel + Height2Pixel(1)); - } - } - - /* do the convoluted bold overstrike */ -#ifndef NO_BOLDOVERSTRIKE - if (MONO_BOLD(rend)) { - DRAW_STRING(draw_string, xpixel + 1, ypixel, buffer, wlen); - UPDATE_BOX(xpixel + 1, ypixel - ascent, xpixel + 1 + Width2Pixel(wlen), ypixel + Height2Pixel(1)); - } -#endif - - if (rend & RS_Uline) { - if (descent > 1) { - XDrawLine(Xdisplay, draw_buffer, TermWin.gc, xpixel, ypixel + 1, xpixel + Width2Pixel(wlen) - 1, ypixel + 1); - UPDATE_BOX(xpixel, ypixel + 1, xpixel + Width2Pixel(wlen) - 1, ypixel + 1); - } else { - XDrawLine(Xdisplay, draw_buffer, TermWin.gc, xpixel, ypixel - 1, xpixel + Width2Pixel(wlen) - 1, ypixel - 1); - UPDATE_BOX(xpixel, ypixel - 1, xpixel + Width2Pixel(wlen) - 1, ypixel - 1); - } - } - if (is_cursor == 1) { #ifndef NO_CURSORCOLOR - if (PixColors[cursorColor] != PixColors[bgColor]) { - XSetForeground(Xdisplay, TermWin.gc, PixColors[cursorColor]); - } + if (rend & RS_Cursor) { + if (PixColors[cursorColor] != PixColors[bgColor]) { + gcvalue.background = PixColors[cursorColor]; + back = cursorColor; + gcmask |= GCBackground; + } + if (PixColors[cursorColor2] != PixColors[fgColor]) { + gcvalue.foreground = PixColors[cursorColor2]; + gcmask |= GCForeground; + } + } +#endif + if (gcmask) { + XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); + } +#ifndef NO_BOLDFONT + if (!wbyte && MONO_BOLD(rend) && TermWin.boldFont != NULL) { + XSetFont(Xdisplay, TermWin.gc, TermWin.boldFont->fid); + bfont = 1; + } else if (bfont) { + bfont = 0; + XSetFont(Xdisplay, TermWin.gc, TermWin.font->fid); + } #endif - XDrawRectangle(Xdisplay, draw_buffer, TermWin.gc, xpixel, ypixel - ascent, Width2Pixel(1 + wbyte) - 1, Height2Pixel(1) - 1); - UPDATE_BOX(xpixel, ypixel - ascent, Width2Pixel(1 + wbyte) - 1, Height2Pixel(1) - 1); - XSetForeground(Xdisplay, TermWin.gc, PixColors[fgColor]); - } - if (gcmask) { /* restore normal colors */ - gcvalue.foreground = PixColors[fgColor]; - gcvalue.background = PixColors[bgColor]; - XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); - } - if (MONO_BOLD(lastrend)) { - if (col < ncols - 1) { - dtp[col + 1] = 0; - } else { - boldlast = 1; - } - } - } /* for (col = 0; col < TermWin.ncol; col++) */ - } /* for (row = 0; row < TermWin.nrow; row++) */ - row = screen.row + TermWin.saveLines; - col = screen.col; - if (screen.flags & Screen_VisibleCursor) { - screen.rend[row][col] &= ~RS_Cursor; #ifdef MULTI_CHARSET - /* very low overhead so don't check properly, just wipe it all out */ - if (screen.col < ncols - 1) - screen.rend[row][col + 1] &= ~RS_Cursor; - if (screen.col > 0) - screen.rend[row][col - 1] &= ~RS_Cursor; + ascent = MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->ascent), TermWin.font->ascent); + descent = MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->descent), TermWin.font->descent); +#else + ascent = TermWin.font->ascent; + descent = TermWin.font->descent; #endif - } - if (buffer_pixmap) { - D_SCREEN(("Update box dimensions: from (%d, %d) to (%d, %d). Dimensions %dx%d\n", low_x, low_y, high_x, high_y, - high_x - low_x + 1, high_y - low_y + 1)); - XClearArea(Xdisplay, TermWin.vt, low_x, low_y, high_x - low_x + 1, high_y - low_y + 1, False); - if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_BOTTOM_LEFT]) { - XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, TermWin.internalBorder - 1, 0, - 1, TermWin_TotalHeight() - 1, TermWin.internalBorder - 1, 0); - XClearArea(Xdisplay, TermWin.vt, TermWin.internalBorder - 1, 0, 1, TermWin_TotalHeight() - 1, False); - } - if (fshadow.shadow[SHADOW_TOP_RIGHT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT] || boldlast) { - XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, TermWin_TotalWidth() - 2, 0, - 1, TermWin_TotalHeight() - 1, TermWin_TotalWidth() - 2, 0); - XClearArea(Xdisplay, TermWin.vt, TermWin_TotalWidth() - 2, 0, 1, TermWin_TotalHeight() - 1, False); - } - if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_TOP_RIGHT]) { - XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, 0, TermWin.internalBorder - 1, - TermWin_TotalWidth() - 1, 1, 0, TermWin.internalBorder - 1); - XClearArea(Xdisplay, TermWin.vt, 0, TermWin.internalBorder - 1, TermWin_TotalWidth() - 1, 1, False); - } - if (fshadow.shadow[SHADOW_BOTTOM_LEFT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT]) { - XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, 0, TermWin_TotalHeight() - TermWin.internalBorder, - TermWin_TotalWidth() - 1, 1, 0, TermWin_TotalHeight() - TermWin.internalBorder); - XClearArea(Xdisplay, TermWin.vt, 0, TermWin_TotalHeight() - TermWin.internalBorder, TermWin_TotalWidth() - 1, 1, False); - } - } else { - if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_BOTTOM_LEFT]) { - XClearArea(Xdisplay, TermWin.vt, TermWin.internalBorder - 1, 0, 1, TermWin_TotalHeight() - 1, False); - } - if ((fshadow.shadow[SHADOW_TOP_RIGHT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT] || boldlast) && TermWin.internalBorder) { - XClearArea(Xdisplay, TermWin.vt, TermWin_TotalWidth() - 2, 0, 1, TermWin_TotalHeight() - 1, False); - } - if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_TOP_RIGHT]) { - XClearArea(Xdisplay, TermWin.vt, 0, TermWin.internalBorder - 1, TermWin_TotalWidth() - 1, 1, False); - } - if (fshadow.shadow[SHADOW_BOTTOM_LEFT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT]) { - XClearArea(Xdisplay, TermWin.vt, 0, TermWin_TotalHeight() - TermWin.internalBorder, TermWin_TotalWidth() - 1, 1, False); - } - } - if (type == SLOW_REFRESH) { - XSync(Xdisplay, False); - } - refresh_all = 0; - D_SCREEN(("Exiting.\n")); + ypixel = ascent + Row2Pixel(row); - PROF_DONE(scr_refresh); - PROF_TIME(scr_refresh); + + /* The actual drawing of the string is done here. */ + if (fprop) { + if (back != bgColor) { + SWAP_IT(gcvalue.foreground, gcvalue.background, ltmp); + gcmask |= (GCForeground | GCBackground); + XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); + XFillRectangle(Xdisplay, draw_buffer, TermWin.gc, xpixel, ypixel - ascent, Width2Pixel(1), Height2Pixel(1)); + SWAP_IT(gcvalue.foreground, gcvalue.background, ltmp); + XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); + } else { + CLEAR_CHARS(xpixel, ypixel - ascent, 1); + } + if (TermWin.font->per_char) { + int fw, cw; + + fw = TermWin.fwidth; + cw = TermWin.font->per_char[((int) (*buffer))].width; + if (cw > 0 && cw < TermWin.font->max_bounds.width) { + if (fw > cw) { + xpixel += ((fw - cw) >> 1); + } else { + xpixel -= ((cw - fw) >> 1); + if (col < ncols - 1) { + dtp[col + 1] = 0; + } + } + } + } + DRAW_STRING(draw_string, xpixel, ypixel, buffer, 1); + UPDATE_BOX(xpixel, ypixel - ascent, xpixel + Width2Pixel(1), ypixel + Height2Pixel(1)); +#ifndef NO_BOLDOVERSTRIKE + if (MONO_BOLD(rend)) { + DRAW_STRING(draw_string, xpixel + 1, ypixel, buffer, 1); + UPDATE_BOX(xpixel + 1, ypixel - ascent, xpixel + 1 + Width2Pixel(1), ypixel + Height2Pixel(1)); + } +#endif + } else { +#ifdef PIXMAP_SUPPORT + if (background_is_pixmap() && (back == bgColor)) { + if (fshadow.do_shadow) { + Pixel tmp; + int xx, yy, ww, hh; + + tmp = gcvalue.foreground; + xx = xpixel; + yy = ypixel - ascent; + ww = Width2Pixel(wlen); + hh = Height2Pixel(1); + CLEAR_CHARS(xpixel, ypixel - ascent, len); + if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_TOP_RIGHT]) { + yy--; + hh++; + } + if (fshadow.shadow[SHADOW_BOTTOM_LEFT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT]) { + hh++; + if (row < nrows - 1) { + int ii; + + for (ii = col - len + 1; ii <= col; ii++) { + drawn_text[row + 1][ii] = 0; + } + } + } + if (fshadow.shadow[SHADOW_TOP_LEFT]) { + XSetForeground(Xdisplay, TermWin.gc, fshadow.color[SHADOW_TOP_LEFT]); + DRAW_STRING(draw_string, xpixel - 1, ypixel - 1, buffer, wlen); + if (col) { + dtp[col - 1] = 0; + } + } + if (fshadow.shadow[SHADOW_TOP_RIGHT]) { + XSetForeground(Xdisplay, TermWin.gc, fshadow.color[SHADOW_TOP_RIGHT]); + DRAW_STRING(draw_string, xpixel + 1, ypixel - 1, buffer, wlen); + if (col < ncols - 1) { + dtp[col + 1] = 0; + } + } + if (fshadow.shadow[SHADOW_BOTTOM_LEFT]) { + XSetForeground(Xdisplay, TermWin.gc, fshadow.color[SHADOW_BOTTOM_LEFT]); + DRAW_STRING(draw_string, xpixel - 1, ypixel + 1, buffer, wlen); + if (col) { + dtp[col - 1] = 0; + } + } + if (fshadow.shadow[SHADOW_BOTTOM_RIGHT]) { + XSetForeground(Xdisplay, TermWin.gc, fshadow.color[SHADOW_BOTTOM_RIGHT]); + DRAW_STRING(draw_string, xpixel + 1, ypixel + 1, buffer, wlen); + if (col < ncols - 1) { + dtp[col + 1] = 0; + } + } + XSetForeground(Xdisplay, TermWin.gc, tmp); + DRAW_STRING(draw_string, xpixel, ypixel, buffer, wlen); + UPDATE_BOX(xx, yy, xx + ww, yy + hh); + } else { + CLEAR_CHARS(xpixel, ypixel - ascent, len); + DRAW_STRING(draw_string, xpixel, ypixel, buffer, wlen); + UPDATE_BOX(xpixel, ypixel - ascent, xpixel + Width2Pixel(wlen), ypixel + Height2Pixel(1)); + } + } else +#endif + { +#ifdef FORCE_CLEAR_CHARS + CLEAR_CHARS(xpixel, ypixel - ascent, len); +#endif + DRAW_STRING(draw_image_string, xpixel, ypixel, buffer, wlen); +#ifdef MULTI_CHARSET + { + XFontStruct *font = wbyte ? TermWin.mfont : TermWin.font; + + if (font->ascent < ascent || font->descent < descent) { + SWAP_IT(gcvalue.foreground, gcvalue.background, ltmp); + gcmask |= (GCForeground | GCBackground); + XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); + if (font->ascent < ascent) { + XFillRectangle(Xdisplay, draw_buffer, TermWin.gc, xpixel, + Row2Pixel(row), Width2Pixel(len), ascent - font->ascent); + } + if (font->descent < descent) { + XFillRectangle(Xdisplay, draw_buffer, TermWin.gc, xpixel, + Row2Pixel(row) + ascent + font->descent, Width2Pixel(len), descent - font->descent); + } + SWAP_IT(gcvalue.foreground, gcvalue.background, ltmp); + XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); + } + } +#endif + UPDATE_BOX(xpixel, ypixel - ascent, xpixel + Width2Pixel(wlen), ypixel + Height2Pixel(1)); + } + } + + /* do the convoluted bold overstrike */ +#ifndef NO_BOLDOVERSTRIKE + if (MONO_BOLD(rend)) { + DRAW_STRING(draw_string, xpixel + 1, ypixel, buffer, wlen); + UPDATE_BOX(xpixel + 1, ypixel - ascent, xpixel + 1 + Width2Pixel(wlen), ypixel + Height2Pixel(1)); + } +#endif + + if (rend & RS_Uline) { + if (descent > 1) { + XDrawLine(Xdisplay, draw_buffer, TermWin.gc, xpixel, ypixel + 1, xpixel + Width2Pixel(wlen) - 1, ypixel + 1); + UPDATE_BOX(xpixel, ypixel + 1, xpixel + Width2Pixel(wlen) - 1, ypixel + 1); + } else { + XDrawLine(Xdisplay, draw_buffer, TermWin.gc, xpixel, ypixel - 1, xpixel + Width2Pixel(wlen) - 1, ypixel - 1); + UPDATE_BOX(xpixel, ypixel - 1, xpixel + Width2Pixel(wlen) - 1, ypixel - 1); + } + } + if (is_cursor == 1) { +#ifndef NO_CURSORCOLOR + if (PixColors[cursorColor] != PixColors[bgColor]) { + XSetForeground(Xdisplay, TermWin.gc, PixColors[cursorColor]); + } +#endif + XDrawRectangle(Xdisplay, draw_buffer, TermWin.gc, xpixel, ypixel - ascent, Width2Pixel(1 + wbyte) - 1, Height2Pixel(1) - 1); + UPDATE_BOX(xpixel, ypixel - ascent, Width2Pixel(1 + wbyte) - 1, Height2Pixel(1) - 1); + XSetForeground(Xdisplay, TermWin.gc, PixColors[fgColor]); + } + if (gcmask) { /* restore normal colors */ + gcvalue.foreground = PixColors[fgColor]; + gcvalue.background = PixColors[bgColor]; + XChangeGC(Xdisplay, TermWin.gc, gcmask, &gcvalue); + } + if (MONO_BOLD(lastrend)) { + if (col < ncols - 1) { + dtp[col + 1] = 0; + } else { + boldlast = 1; + } + } + } /* for (col = 0; col < TermWin.ncol; col++) */ + } /* for (row = 0; row < TermWin.nrow; row++) */ + + row = screen.row + TermWin.saveLines; + col = screen.col; + if (screen.flags & Screen_VisibleCursor) { + screen.rend[row][col] &= ~RS_Cursor; +#ifdef MULTI_CHARSET + /* very low overhead so don't check properly, just wipe it all out */ + if (screen.col < ncols - 1) + screen.rend[row][col + 1] &= ~RS_Cursor; + if (screen.col > 0) + screen.rend[row][col - 1] &= ~RS_Cursor; +#endif + } + if (buffer_pixmap) { + D_SCREEN(("Update box dimensions: from (%d, %d) to (%d, %d). Dimensions %dx%d\n", low_x, low_y, high_x, high_y, + high_x - low_x + 1, high_y - low_y + 1)); + XClearArea(Xdisplay, TermWin.vt, low_x, low_y, high_x - low_x + 1, high_y - low_y + 1, False); + if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_BOTTOM_LEFT]) { + XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, TermWin.internalBorder - 1, 0, + 1, TermWin_TotalHeight() - 1, TermWin.internalBorder - 1, 0); + XClearArea(Xdisplay, TermWin.vt, TermWin.internalBorder - 1, 0, 1, TermWin_TotalHeight() - 1, False); + } + if (fshadow.shadow[SHADOW_TOP_RIGHT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT] || boldlast) { + XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, TermWin_TotalWidth() - 2, 0, + 1, TermWin_TotalHeight() - 1, TermWin_TotalWidth() - 2, 0); + XClearArea(Xdisplay, TermWin.vt, TermWin_TotalWidth() - 2, 0, 1, TermWin_TotalHeight() - 1, False); + } + if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_TOP_RIGHT]) { + XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, 0, TermWin.internalBorder - 1, + TermWin_TotalWidth() - 1, 1, 0, TermWin.internalBorder - 1); + XClearArea(Xdisplay, TermWin.vt, 0, TermWin.internalBorder - 1, TermWin_TotalWidth() - 1, 1, False); + } + if (fshadow.shadow[SHADOW_BOTTOM_LEFT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT]) { + XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, 0, TermWin_TotalHeight() - TermWin.internalBorder, + TermWin_TotalWidth() - 1, 1, 0, TermWin_TotalHeight() - TermWin.internalBorder); + XClearArea(Xdisplay, TermWin.vt, 0, TermWin_TotalHeight() - TermWin.internalBorder, TermWin_TotalWidth() - 1, 1, False); + } + } else { + if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_BOTTOM_LEFT]) { + XClearArea(Xdisplay, TermWin.vt, TermWin.internalBorder - 1, 0, 1, TermWin_TotalHeight() - 1, False); + } + if ((fshadow.shadow[SHADOW_TOP_RIGHT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT] || boldlast) && TermWin.internalBorder) { + XClearArea(Xdisplay, TermWin.vt, TermWin_TotalWidth() - 2, 0, 1, TermWin_TotalHeight() - 1, False); + } + if (fshadow.shadow[SHADOW_TOP_LEFT] || fshadow.shadow[SHADOW_TOP_RIGHT]) { + XClearArea(Xdisplay, TermWin.vt, 0, TermWin.internalBorder - 1, TermWin_TotalWidth() - 1, 1, False); + } + if (fshadow.shadow[SHADOW_BOTTOM_LEFT] || fshadow.shadow[SHADOW_BOTTOM_RIGHT]) { + XClearArea(Xdisplay, TermWin.vt, 0, TermWin_TotalHeight() - TermWin.internalBorder, TermWin_TotalWidth() - 1, 1, False); + } + } + if (type == SLOW_REFRESH) { + XSync(Xdisplay, False); + } + refresh_all = 0; + D_SCREEN(("Exiting.\n")); + + PROF_DONE(scr_refresh); + PROF_TIME(scr_refresh); } int scr_strmatch(unsigned long row, unsigned long col, const char *str) { - unsigned char c; - const char *s; + unsigned char c; + const char *s; - for (c = screen.text[row][col], s = str; s; s++) { - if (c != *s) { - return (0); + for (c = screen.text[row][col], s = str; s; s++) { + if (c != *s) { + return (0); + } } - } - return 1; + return 1; } /* Find and highlight all occurances of "str" in the scrollback. */ void scr_search_scrollback(char *str) { - unsigned char *c; - char *s; - static char *last_str = NULL; - unsigned int *i; - unsigned long row, lrow, col, rows, cols, len, k; + unsigned char *c; + char *s; + static char *last_str = NULL; + unsigned int *i; + unsigned long row, lrow, col, rows, cols, len, k; - if (str == NULL) { - if ((str = last_str) == NULL) { - return; - } - } else { - last_str = STRDUP(str); - } - lrow = rows = TermWin.nrow + TermWin.saveLines; - cols = TermWin.ncol; - len = strlen(str); - - D_SCREEN(("%d, %d\n", rows, cols)); - for (row = 0; row < rows; row++) { - if (screen.text[row]) { - c = screen.text[row]; - for (s = strstr(c, str); s; s = strstr(s + 1, str)) { - unsigned long j; - - col = (int) s - (int) c; - for (i = screen.rend[row] + col, j = 0; j < len; i++, j++) { - if (*i & RS_RVid) { - *i &= ~RS_RVid; - } else { - *i |= RS_RVid; - } + if (str == NULL) { + if ((str = last_str) == NULL) { + return; } - if ((long) row <= TermWin.saveLines) { - lrow = row; - } - } - for (s = screen.text[row] + cols - len + 1, k = len - 1; k; s++, k--) { - unsigned long j; + } else { + last_str = STRDUP(str); + } + lrow = rows = TermWin.nrow + TermWin.saveLines; + cols = TermWin.ncol; + len = strlen(str); - if ((row < rows - 1) && !strncasecmp(s, str, k) && screen.text[row + 1] && !strncasecmp(screen.text[row + 1], str + k, len - k)) { - col = (int) s - (int) c; - for (i = &(screen.rend[row][cols - k]), j = 0; j < k; i++, j++) { - (*i & RS_RVid) ? (*i &= ~RS_RVid) : (*i |= RS_RVid); - } - for (i = screen.rend[row + 1], j = 0, k = len - k; j < k; i++, j++) { - (*i & RS_RVid) ? (*i &= ~RS_RVid) : (*i |= RS_RVid); - } - if ((long) row <= TermWin.saveLines) { - lrow = row; - } - break; + D_SCREEN(("%d, %d\n", rows, cols)); + for (row = 0; row < rows; row++) { + if (screen.text[row]) { + c = screen.text[row]; + for (s = strstr(c, str); s; s = strstr(s + 1, str)) { + unsigned long j; + + col = (int) s - (int) c; + for (i = screen.rend[row] + col, j = 0; j < len; i++, j++) { + if (*i & RS_RVid) { + *i &= ~RS_RVid; + } else { + *i |= RS_RVid; + } + } + if ((long) row <= TermWin.saveLines) { + lrow = row; + } + } + for (s = screen.text[row] + cols - len + 1, k = len - 1; k; s++, k--) { + unsigned long j; + + if ((row < rows - 1) && !strncasecmp(s, str, k) && screen.text[row + 1] + && !strncasecmp(screen.text[row + 1], str + k, len - k)) { + col = (int) s - (int) c; + for (i = &(screen.rend[row][cols - k]), j = 0; j < k; i++, j++) { + (*i & RS_RVid) ? (*i &= ~RS_RVid) : (*i |= RS_RVid); + } + for (i = screen.rend[row + 1], j = 0, k = len - k; j < k; i++, j++) { + (*i & RS_RVid) ? (*i &= ~RS_RVid) : (*i |= RS_RVid); + } + if ((long) row <= TermWin.saveLines) { + lrow = row; + } + break; + } + } } - } } - } - if (last_str == str) { - FREE(last_str); - } else { - if (lrow != rows) { - TermWin.view_start = rows - lrow - TermWin.nrow; - BOUND(TermWin.view_start, 0, TermWin.nscrolled); - D_SCREEN(("New view start is %d\n", TermWin.view_start)); + if (last_str == str) { + FREE(last_str); + } else { + if (lrow != rows) { + TermWin.view_start = rows - lrow - TermWin.nrow; + BOUND(TermWin.view_start, 0, TermWin.nscrolled); + D_SCREEN(("New view start is %d\n", TermWin.view_start)); + } } - } - scr_refresh(refresh_type); + scr_refresh(refresh_type); } /* Dump the entire contents of the scrollback buffer to stderr in hex and ASCII */ void scr_dump(void) { - unsigned char *c; - unsigned int *i; - unsigned long row, col, rows, cols; + unsigned char *c; + unsigned int *i; + unsigned long row, col, rows, cols; - rows = TermWin.nrow + TermWin.saveLines; - cols = TermWin.ncol; + rows = TermWin.nrow + TermWin.saveLines; + cols = TermWin.ncol; - D_SCREEN(("%d, %d\n", rows, cols)); - for (row = 0; row < rows; row++) { - fprintf(stderr, "%lu: ", row); - if (screen.text[row]) { - for (col = 0, c = screen.text[row]; col < cols; c++, col++) { - fprintf(stderr, "%02x ", *c); - } - fprintf(stderr, "\""); - for (col = 0, c = screen.text[row]; col < cols; c++, col++) { - fprintf(stderr, "%c", ((isprint(*c)) ? (*c) : '.')); - } - fprintf(stderr, "\""); - for (col = 0, i = screen.rend[row]; col < cols; i++, col++) { - fprintf(stderr, " %08x", *i); - } - } else { - fprintf(stderr, "NULL"); + D_SCREEN(("%d, %d\n", rows, cols)); + for (row = 0; row < rows; row++) { + fprintf(stderr, "%lu: ", row); + if (screen.text[row]) { + for (col = 0, c = screen.text[row]; col < cols; c++, col++) { + fprintf(stderr, "%02x ", *c); + } + fprintf(stderr, "\""); + for (col = 0, c = screen.text[row]; col < cols; c++, col++) { + fprintf(stderr, "%c", ((isprint(*c)) ? (*c) : '.')); + } + fprintf(stderr, "\""); + for (col = 0, i = screen.rend[row]; col < cols; i++, col++) { + fprintf(stderr, " %08x", *i); + } + } else { + fprintf(stderr, "NULL"); + } + fprintf(stderr, "\n"); + fflush(stderr); } - fprintf(stderr, "\n"); - fflush(stderr); - } } /* Dump the entire contents of the scrollback buffer to a file */ void scr_dump_to_file(const char *fname) { - int outfd; - char *buff, *src, *dest; - unsigned long row, col, rows, cols; - struct stat st; + int outfd; + char *buff, *src, *dest; + unsigned long row, col, rows, cols; + struct stat st; - REQUIRE(fname != NULL); + REQUIRE(fname != NULL); - rows = TermWin.nrow + TermWin.saveLines; - cols = TermWin.ncol; - D_SCREEN(("Dumping to file \"%s\". %d rows, %d cols\n", fname, rows, cols)); + rows = TermWin.nrow + TermWin.saveLines; + cols = TermWin.ncol; + D_SCREEN(("Dumping to file \"%s\". %d rows, %d cols\n", fname, rows, cols)); - /* Remove it if it's there. If this fails, we don't - care, because open() will do the right thing. */ - if ((stat(fname, &st) == 0) || (errno != ENOENT)) { - D_SCREEN(("Refusing to use log file \"%s\" -- %s\n", fname, (errno ? strerror(errno) : "File exists"))); - return; - } - - /* Only open if it's a new file, and open with permissions 0600 */ - outfd = open(fname, O_CREAT | O_EXCL | O_NDELAY | O_WRONLY, S_IRUSR | S_IWUSR); - if (outfd < 0) { - D_SCREEN(("Unable to open \"%s\" for writing -- %s\n", fname, strerror(errno))); - return; - } - if (stat(fname, &st) || !S_ISREG(st.st_mode)) { - D_SCREEN(("Race condition exploit attempt detected on \"%s\"!\n", fname)); - close(outfd); - return; - } - buff = MALLOC(cols + 1); - for (row = 0; row < rows; row++) { - if (screen.text[row]) { - for (src = screen.text[row], dest = buff, col = 0; col < cols; col++) *dest++ = *src++; - *dest++ = '\n'; - *dest = 0; - write(outfd, buff, dest - buff); + /* Remove it if it's there. If this fails, we don't + care, because open() will do the right thing. */ + if ((stat(fname, &st) == 0) || (errno != ENOENT)) { + D_SCREEN(("Refusing to use log file \"%s\" -- %s\n", fname, (errno ? strerror(errno) : "File exists"))); + return; } - } - close(outfd); - FREE(buff); + + /* Only open if it's a new file, and open with permissions 0600 */ + outfd = open(fname, O_CREAT | O_EXCL | O_NDELAY | O_WRONLY, S_IRUSR | S_IWUSR); + if (outfd < 0) { + D_SCREEN(("Unable to open \"%s\" for writing -- %s\n", fname, strerror(errno))); + return; + } + if (stat(fname, &st) || !S_ISREG(st.st_mode)) { + D_SCREEN(("Race condition exploit attempt detected on \"%s\"!\n", fname)); + close(outfd); + return; + } + buff = MALLOC(cols + 1); + for (row = 0; row < rows; row++) { + if (screen.text[row]) { + for (src = screen.text[row], dest = buff, col = 0; col < cols; col++) + *dest++ = *src++; + *dest++ = '\n'; + *dest = 0; + write(outfd, buff, dest - buff); + } + } + close(outfd); + FREE(buff); } /* @@ -2316,288 +2317,291 @@ scr_dump_to_file(const char *fname) void selection_check(void) { - int c1, c2, r1, r2; + int c1, c2, r1, r2; - if (current_screen != selection.screen) - return; + if (current_screen != selection.screen) + return; - if ((selection.mark.row < -TermWin.nscrolled) - || (selection.mark.row >= TermWin.nrow) - || (selection.beg.row < -TermWin.nscrolled) - || (selection.beg.row >= TermWin.nrow) - || (selection.end.row < -TermWin.nscrolled) - || (selection.end.row >= TermWin.nrow)) { - selection_reset(); - return; - } - r1 = (screen.row - TermWin.view_start); + if ((selection.mark.row < -TermWin.nscrolled) + || (selection.mark.row >= TermWin.nrow) + || (selection.beg.row < -TermWin.nscrolled) + || (selection.beg.row >= TermWin.nrow) + || (selection.end.row < -TermWin.nscrolled) + || (selection.end.row >= TermWin.nrow)) { + selection_reset(); + return; + } + r1 = (screen.row - TermWin.view_start); - c1 = ((r1 - selection.mark.row) * (r1 - selection.end.row)); + c1 = ((r1 - selection.mark.row) * (r1 - selection.end.row)); /* * selection.mark.row > screen.row - TermWin.view_start * or * selection.end.row > screen.row - TermWin.view_start */ - if (c1 < 0) - selection_reset(); - else if (c1 == 0) { - if ((selection.mark.row < selection.end.row) - || ((selection.mark.row == selection.end.row) - && (selection.mark.col < selection.end.col))) { - r1 = selection.mark.row; - c1 = selection.mark.col; - r2 = selection.end.row; - c2 = selection.end.col; - } else { - r1 = selection.end.row; - c1 = selection.end.col; - r2 = selection.mark.row; - c2 = selection.mark.col; + if (c1 < 0) + selection_reset(); + else if (c1 == 0) { + if ((selection.mark.row < selection.end.row) + || ((selection.mark.row == selection.end.row) + && (selection.mark.col < selection.end.col))) { + r1 = selection.mark.row; + c1 = selection.mark.col; + r2 = selection.end.row; + c2 = selection.end.col; + } else { + r1 = selection.end.row; + c1 = selection.end.col; + r2 = selection.mark.row; + c2 = selection.mark.col; + } + if ((screen.row == r1) && (screen.row == r2)) { + if ((screen.col >= c1) && (screen.col <= c2)) + selection_reset(); + } else if (((screen.row == r1) && (screen.col >= c1)) + || ((screen.row == r2) && (screen.col <= c2))) + selection_reset(); } - if ((screen.row == r1) && (screen.row == r2)) { - if ((screen.col >= c1) && (screen.col <= c2)) - selection_reset(); - } else if (((screen.row == r1) && (screen.col >= c1)) - || ((screen.row == r2) && (screen.col <= c2))) - selection_reset(); - } } /* Write the selection out to the tty. */ void selection_write(unsigned char *data, size_t len) { - size_t num; - unsigned char *p, *cr = "\r"; + size_t num; + unsigned char *p, *cr = "\r"; - D_SELECT(("Writing %lu characters of selection data to tty.\n", len)); - D_SELECT(("\n%s\n\n", safe_print_string((char *) data, len))); - for (p = data, num = 0; len--; p++) { - /* Write out each line, replacing newlines with carriage returns. */ - if (*p != '\n') { - num++; - } else { - tt_write(data, num); - tt_write(cr, 1); - data += num + 1; - num = 0; + D_SELECT(("Writing %lu characters of selection data to tty.\n", len)); + D_SELECT(("\n%s\n\n", safe_print_string((char *) data, len))); + for (p = data, num = 0; len--; p++) { + /* Write out each line, replacing newlines with carriage returns. */ + if (*p != '\n') { + num++; + } else { + tt_write(data, num); + tt_write(cr, 1); + data += num + 1; + num = 0; + } + } + /* If there's anything left, write it out too. */ + if (num) { + tt_write(data, num); } - } - /* If there's anything left, write it out too. */ - if (num) { - tt_write(data, num); - } } /* Fetch the selection from the specified property and write it to the tty. */ void selection_fetch(Window win, unsigned prop, int delete) { - long nread; - unsigned long bytes_after, nitems; - unsigned char *data; - Atom actual_type; - int actual_fmt; + long nread; + unsigned long bytes_after, nitems; + unsigned char *data; + Atom actual_type; + int actual_fmt; - D_SELECT(("Fetching selection in property %d from window 0x%08x\n", (int) prop, (int) win)); - if (prop == None) { - return; - } - for (nread = 0, bytes_after = 1; bytes_after > 0;) { - if ((XGetWindowProperty(Xdisplay, win, prop, (nread / 4), PROP_SIZE, delete, AnyPropertyType, &actual_type, &actual_fmt, &nitems, &bytes_after, &data) != Success) - || (actual_type == None) || (data == NULL)) { - D_SELECT(("Unable to fetch the value of property %d from window 0x%08x\n", (int) prop, (int) win)); - if (data != NULL) { - XFree(data); - } - return; + D_SELECT(("Fetching selection in property %d from window 0x%08x\n", (int) prop, (int) win)); + if (prop == None) { + return; } - nread += nitems; - D_SELECT(("Got selection info: Actual type %d (format %d), %lu items at 0x%08x, %lu bytes left over.\n", - (int) actual_type, actual_fmt, nitems, data, bytes_after)); - - if (nitems == 0) { - D_SELECT(("Retrieval of incremental selection complete.\n")); - TermWin.mask &= ~(PropertyChangeMask); - XSelectInput(Xdisplay, TermWin.vt, TermWin.mask); - return; - } - if (actual_type == XA_STRING) { - /* We can handle strings directly. */ - selection_write(data, nitems); - } else if (actual_type == props[PROP_SELECTION_INCR]) { - D_SELECT(("Incremental selection transfer initiated. Length is at least %u bytes.\n", (unsigned) *((unsigned *) data))); - TermWin.mask |= PropertyChangeMask; - XSelectInput(Xdisplay, TermWin.vt, TermWin.mask); - } else { - int size, i; - XTextProperty xtextp; - char **cl = NULL; - - /* It's not a string, so convert it to one (or more). */ - D_SELECT(("Selection is not a string. Converting.\n")); - xtextp.value = data; - xtextp.encoding = actual_type; - xtextp.format = actual_fmt; - xtextp.nitems = nitems; - XmbTextPropertyToTextList(Xdisplay, &xtextp, &cl, &size); - - if (cl) { - D_SELECT(("Got string list 0x%08x with %d strings.\n", cl, size)); - for (i = 0; i < size; i++) { - if (cl[i]) { - selection_write(cl[i], strlen(cl[i])); - } + for (nread = 0, bytes_after = 1; bytes_after > 0;) { + if ((XGetWindowProperty + (Xdisplay, win, prop, (nread / 4), PROP_SIZE, delete, AnyPropertyType, &actual_type, &actual_fmt, &nitems, &bytes_after, + &data) != Success) + || (actual_type == None) || (data == NULL)) { + D_SELECT(("Unable to fetch the value of property %d from window 0x%08x\n", (int) prop, (int) win)); + if (data != NULL) { + XFree(data); + } + return; + } + nread += nitems; + D_SELECT(("Got selection info: Actual type %d (format %d), %lu items at 0x%08x, %lu bytes left over.\n", + (int) actual_type, actual_fmt, nitems, data, bytes_after)); + + if (nitems == 0) { + D_SELECT(("Retrieval of incremental selection complete.\n")); + TermWin.mask &= ~(PropertyChangeMask); + XSelectInput(Xdisplay, TermWin.vt, TermWin.mask); + return; + } + if (actual_type == XA_STRING) { + /* We can handle strings directly. */ + selection_write(data, nitems); + } else if (actual_type == props[PROP_SELECTION_INCR]) { + D_SELECT(("Incremental selection transfer initiated. Length is at least %u bytes.\n", (unsigned) *((unsigned *) data))); + TermWin.mask |= PropertyChangeMask; + XSelectInput(Xdisplay, TermWin.vt, TermWin.mask); + } else { + int size, i; + XTextProperty xtextp; + char **cl = NULL; + + /* It's not a string, so convert it to one (or more). */ + D_SELECT(("Selection is not a string. Converting.\n")); + xtextp.value = data; + xtextp.encoding = actual_type; + xtextp.format = actual_fmt; + xtextp.nitems = nitems; + XmbTextPropertyToTextList(Xdisplay, &xtextp, &cl, &size); + + if (cl) { + D_SELECT(("Got string list 0x%08x with %d strings.\n", cl, size)); + for (i = 0; i < size; i++) { + if (cl[i]) { + selection_write(cl[i], strlen(cl[i])); + } + } + XFreeStringList(cl); + } + } + if (data) { + XFree(data); } - XFreeStringList(cl); - } } - if (data) { - XFree(data); - } - } } /* Copy a specific string of a given length to the buffer specified. */ void selection_copy_string(Atom sel, char *str, size_t len) { - if (str == NULL || len == 0) { - return; - } - if (IS_SELECTION(sel)) { - D_SELECT(("Copying selection to selection %d\n", (int) sel)); - XSetSelectionOwner(Xdisplay, sel, TermWin.vt, CurrentTime); - if (XGetSelectionOwner(Xdisplay, sel) != TermWin.vt) { - print_error("Can't take ownership of selection\n"); + if (str == NULL || len == 0) { + return; + } + if (IS_SELECTION(sel)) { + D_SELECT(("Copying selection to selection %d\n", (int) sel)); + XSetSelectionOwner(Xdisplay, sel, TermWin.vt, CurrentTime); + if (XGetSelectionOwner(Xdisplay, sel) != TermWin.vt) { + print_error("Can't take ownership of selection\n"); + } + } else { + D_SELECT(("Copying selection to cut buffer %d\n", (int) sel)); + XChangeProperty(Xdisplay, Xroot, sel, XA_STRING, 8, PropModeReplace, str, len); } - } else { - D_SELECT(("Copying selection to cut buffer %d\n", (int) sel)); - XChangeProperty(Xdisplay, Xroot, sel, XA_STRING, 8, PropModeReplace, str, len); - } } /* Copy the currently-selected text to the buffer specified. */ void selection_copy(Atom sel) { - selection_copy_string(sel, selection.text, selection.len); + selection_copy_string(sel, selection.text, selection.len); } /* Paste the specified selection from the specified buffer. */ void selection_paste(Atom sel) { - if (selection.text != NULL) { - /* If we have a selection of our own, paste it. */ - D_SELECT(("Pasting my current selection of length %lu\n", selection.len)); - selection_write(selection.text, selection.len); - } else if (IS_SELECTION(sel)) { - if (XGetSelectionOwner(Xdisplay, sel) == None) { - /* If nobody owns the current selection, just try to paste it ourselves. */ - D_SELECT(("Current selection %d unowned. Attempting to paste the default cut buffer.\n", (int) sel)); - selection_fetch(Xroot, XA_CUT_BUFFER0, False); - } else { - /* If someone owns the current selection, send a request to that client to - convert the selection to the appropriate form (usually XA_STRING) and - save it for us in the VT_SELECTION property. We'll then get a SelectionNotify. */ - D_SELECT(("Requesting current selection (%d) -> VT_SELECTION (%d)\n", sel, props[PROP_SELECTION_DEST])); + if (selection.text != NULL) { + /* If we have a selection of our own, paste it. */ + D_SELECT(("Pasting my current selection of length %lu\n", selection.len)); + selection_write(selection.text, selection.len); + } else if (IS_SELECTION(sel)) { + if (XGetSelectionOwner(Xdisplay, sel) == None) { + /* If nobody owns the current selection, just try to paste it ourselves. */ + D_SELECT(("Current selection %d unowned. Attempting to paste the default cut buffer.\n", (int) sel)); + selection_fetch(Xroot, XA_CUT_BUFFER0, False); + } else { + /* If someone owns the current selection, send a request to that client to + convert the selection to the appropriate form (usually XA_STRING) and + save it for us in the VT_SELECTION property. We'll then get a SelectionNotify. */ + D_SELECT(("Requesting current selection (%d) -> VT_SELECTION (%d)\n", sel, props[PROP_SELECTION_DEST])); #if defined(MULTI_CHARSET) && defined(HAVE_X11_XMU_ATOMS_H) - if (encoding_method != LATIN1) { - XConvertSelection(Xdisplay, sel, XA_COMPOUND_TEXT(Xdisplay), props[PROP_SELECTION_DEST], TermWin.vt, CurrentTime); - } else { - XConvertSelection(Xdisplay, sel, XA_STRING, props[PROP_SELECTION_DEST], TermWin.vt, CurrentTime); - } + if (encoding_method != LATIN1) { + XConvertSelection(Xdisplay, sel, XA_COMPOUND_TEXT(Xdisplay), props[PROP_SELECTION_DEST], TermWin.vt, CurrentTime); + } else { + XConvertSelection(Xdisplay, sel, XA_STRING, props[PROP_SELECTION_DEST], TermWin.vt, CurrentTime); + } #else - XConvertSelection(Xdisplay, sel, XA_STRING, props[PROP_SELECTION_DEST], TermWin.vt, CurrentTime); + XConvertSelection(Xdisplay, sel, XA_STRING, props[PROP_SELECTION_DEST], TermWin.vt, CurrentTime); #endif + } + } else { + D_SELECT(("Pasting cut buffer %d.\n", (int) sel)); + selection_fetch(Xroot, sel, False); } - } else { - D_SELECT(("Pasting cut buffer %d.\n", (int) sel)); - selection_fetch(Xroot, sel, False); - } } /* Clear the selected state of all selected text. */ void selection_reset(void) { - int i, j, lrow, lcol; + int i, j, lrow, lcol; - D_SELECT(("selection_reset()\n")); + D_SELECT(("selection_reset()\n")); - lrow = TermWin.nrow + TermWin.saveLines; - lcol = TermWin.ncol; - selection.op = SELECTION_CLEAR; + lrow = TermWin.nrow + TermWin.saveLines; + lcol = TermWin.ncol; + selection.op = SELECTION_CLEAR; - i = (current_screen == PRIMARY) ? 0 : TermWin.saveLines; - for (; i < lrow; i++) { - if (screen.text[i]) { - for (j = 0; j < lcol; j++) { - screen.rend[i][j] &= ~RS_Select; - } + i = (current_screen == PRIMARY) ? 0 : TermWin.saveLines; + for (; i < lrow; i++) { + if (screen.text[i]) { + for (j = 0; j < lcol; j++) { + screen.rend[i][j] &= ~RS_Select; + } + } } - } } + /* Delete the current selection. */ void selection_clear(void) { - D_SELECT(("selection_clear()\n")); + D_SELECT(("selection_clear()\n")); - if (selection.text) { - FREE(selection.text); - } - selection.len = 0; - selection_reset(); + if (selection.text) { + FREE(selection.text); + } + selection.len = 0; + selection_reset(); } /* Set or clear between selected points (inclusive) */ void selection_setclr(int set, int startr, int startc, int endr, int endc) { - int row, col, last_col; - rend_t *rend; + int row, col, last_col; + rend_t *rend; - D_SELECT(("selection_setclr(%d) %s (%d,%d)-(%d,%d)\n", set, (set ? "set " : "clear"), startc, startr, endc, endr)); + D_SELECT(("selection_setclr(%d) %s (%d,%d)-(%d,%d)\n", set, (set ? "set " : "clear"), startc, startr, endc, endr)); - if ((startr < -TermWin.nscrolled) || (endr >= TermWin.nrow)) { - selection_reset(); - return; - } - last_col = TermWin.ncol - 1; - - LOWER_BOUND(startc, 0); - UPPER_BOUND(endc, last_col); - BOUND(startr, -TermWin.nscrolled, TermWin.nrow - 1); - BOUND(endr, -TermWin.nscrolled, TermWin.nrow - 1); - - startr += TermWin.saveLines; - endr += TermWin.saveLines; - - col = startc; - if (set) { - for (row = startr; row < endr; row++) { - rend = &(screen.rend[row][col]); - for (; col <= last_col; col++, rend++) - *rend |= RS_Select; - col = 0; + if ((startr < -TermWin.nscrolled) || (endr >= TermWin.nrow)) { + selection_reset(); + return; } - rend = &(screen.rend[row][col]); - for (; col <= endc; col++, rend++) - *rend |= RS_Select; - } else { - for (row = startr; row < endr; row++) { - rend = &(screen.rend[row][col]); - for (; col <= last_col; col++, rend++) - *rend &= ~RS_Select; - col = 0; + last_col = TermWin.ncol - 1; + + LOWER_BOUND(startc, 0); + UPPER_BOUND(endc, last_col); + BOUND(startr, -TermWin.nscrolled, TermWin.nrow - 1); + BOUND(endr, -TermWin.nscrolled, TermWin.nrow - 1); + + startr += TermWin.saveLines; + endr += TermWin.saveLines; + + col = startc; + if (set) { + for (row = startr; row < endr; row++) { + rend = &(screen.rend[row][col]); + for (; col <= last_col; col++, rend++) + *rend |= RS_Select; + col = 0; + } + rend = &(screen.rend[row][col]); + for (; col <= endc; col++, rend++) + *rend |= RS_Select; + } else { + for (row = startr; row < endr; row++) { + rend = &(screen.rend[row][col]); + for (; col <= last_col; col++, rend++) + *rend &= ~RS_Select; + col = 0; + } + rend = &(screen.rend[row][col]); + for (; col <= endc; col++, rend++) + *rend &= ~RS_Select; } - rend = &(screen.rend[row][col]); - for (; col <= endc; col++, rend++) - *rend &= ~RS_Select; - } } /* @@ -2606,8 +2610,8 @@ selection_setclr(int set, int startr, int startc, int endr, int endc) void selection_start(int x, int y) { - D_SELECT(("selection_start(%d, %d)\n", x, y)); - selection_start_colrow(Pixel2Col(x), Pixel2Row(y)); + D_SELECT(("selection_start(%d, %d)\n", x, y)); + selection_start_colrow(Pixel2Col(x), Pixel2Row(y)); } /* @@ -2616,29 +2620,27 @@ selection_start(int x, int y) void selection_start_colrow(int col, int row) { - int end_col; + int end_col; - D_SELECT(("selection_start_colrow(%d, %d)\n", col, row)); + D_SELECT(("selection_start_colrow(%d, %d)\n", col, row)); - if (selection.op) { - /* clear the old selection */ + if (selection.op) { + /* clear the old selection */ - if (selection.beg.row < -TermWin.nscrolled) - selection_reset(); - else - selection_setclr(0, - selection.beg.row, selection.beg.col, - selection.end.row, selection.end.col); - } - selection.op = SELECTION_INIT; - BOUND(row, 0, TermWin.nrow - 1); + if (selection.beg.row < -TermWin.nscrolled) + selection_reset(); + else + selection_setclr(0, selection.beg.row, selection.beg.col, selection.end.row, selection.end.col); + } + selection.op = SELECTION_INIT; + BOUND(row, 0, TermWin.nrow - 1); - row -= TermWin.view_start; - end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; - if (end_col != WRAP_CHAR && col > end_col) - col = TermWin.ncol; - selection.mark.col = col; - selection.mark.row = row; + row -= TermWin.view_start; + end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; + if (end_col != WRAP_CHAR && col > end_col) + col = TermWin.ncol; + selection.mark.col = col; + selection.mark.row = row; } /* @@ -2648,95 +2650,94 @@ selection_start_colrow(int col, int row) void selection_make(Time tm) { - int i, col, end_col, row, end_row; - text_t *new_selection_text; - char *str; - text_t *t; + int i, col, end_col, row, end_row; + text_t *new_selection_text; + char *str; + text_t *t; - D_SELECT(("selection.op=%d, selection.clicks=%d\n", selection.op, selection.clicks)); - switch (selection.op) { - case SELECTION_CONT: - break; - case SELECTION_INIT: - selection_reset(); - selection.end.row = selection.beg.row = selection.mark.row; - selection.end.col = selection.beg.col = selection.mark.col; - /* FALLTHROUGH */ - case SELECTION_BEGIN: - selection.op = SELECTION_DONE; - /* FALLTHROUGH */ - default: - return; - } - selection.op = SELECTION_DONE; + D_SELECT(("selection.op=%d, selection.clicks=%d\n", selection.op, selection.clicks)); + switch (selection.op) { + case SELECTION_CONT: + break; + case SELECTION_INIT: + selection_reset(); + selection.end.row = selection.beg.row = selection.mark.row; + selection.end.col = selection.beg.col = selection.mark.col; + /* FALLTHROUGH */ + case SELECTION_BEGIN: + selection.op = SELECTION_DONE; + /* FALLTHROUGH */ + default: + return; + } + selection.op = SELECTION_DONE; - if (selection.clicks == 4) - return; /* nothing selected, go away */ + if (selection.clicks == 4) + return; /* nothing selected, go away */ - if (selection.beg.row < -TermWin.nscrolled - || selection.end.row >= TermWin.nrow) { - selection_reset(); - return; - } - i = (selection.end.row - selection.beg.row + 1) * (TermWin.ncol + 1) + 1; - str = MALLOC(i * sizeof(char)); - new_selection_text = (unsigned char *) str; + if (selection.beg.row < -TermWin.nscrolled || selection.end.row >= TermWin.nrow) { + selection_reset(); + return; + } + i = (selection.end.row - selection.beg.row + 1) * (TermWin.ncol + 1) + 1; + str = MALLOC(i * sizeof(char)); + new_selection_text = (unsigned char *) str; - col = MAX(selection.beg.col, 0); - row = selection.beg.row + TermWin.saveLines; - end_row = selection.end.row + TermWin.saveLines; + col = MAX(selection.beg.col, 0); + row = selection.beg.row + TermWin.saveLines; + end_row = selection.end.row + TermWin.saveLines; /* * A: rows before end row */ - for (; row < end_row; row++) { - t = &(screen.text[row][col]); - if ((end_col = screen.text[row][TermWin.ncol]) == WRAP_CHAR) - end_col = TermWin.ncol; - for (; col < end_col; col++) - *str++ = *t++; - col = 0; - if (screen.text[row][TermWin.ncol] != WRAP_CHAR) { - if (!(Options & Opt_select_trailing_spaces)) { - for (str--; *str == ' ' || *str == '\t'; str--); - str++; - } - *str++ = '\n'; + for (; row < end_row; row++) { + t = &(screen.text[row][col]); + if ((end_col = screen.text[row][TermWin.ncol]) == WRAP_CHAR) + end_col = TermWin.ncol; + for (; col < end_col; col++) + *str++ = *t++; + col = 0; + if (screen.text[row][TermWin.ncol] != WRAP_CHAR) { + if (!(Options & Opt_select_trailing_spaces)) { + for (str--; *str == ' ' || *str == '\t'; str--); + str++; + } + *str++ = '\n'; + } } - } /* * B: end row */ - t = &(screen.text[row][col]); - end_col = screen.text[row][TermWin.ncol]; - if (end_col == WRAP_CHAR || selection.end.col <= end_col) { - i = 0; - end_col = selection.end.col + 1; - } else - i = 1; - UPPER_BOUND(end_col, TermWin.ncol); - for (; col < end_col; col++) - *str++ = *t++; - if (!(Options & Opt_select_trailing_spaces)) { - for (str--; *str == ' ' || *str == '\t'; str--); - str++; - } - if (i) - *str++ = '\n'; - *str = '\0'; - if ((i = strlen((char *) new_selection_text)) == 0) { - FREE(new_selection_text); - return; - } - selection.len = i; - if (selection.text) - FREE(selection.text); - selection.text = new_selection_text; - selection.screen = current_screen; + t = &(screen.text[row][col]); + end_col = screen.text[row][TermWin.ncol]; + if (end_col == WRAP_CHAR || selection.end.col <= end_col) { + i = 0; + end_col = selection.end.col + 1; + } else + i = 1; + UPPER_BOUND(end_col, TermWin.ncol); + for (; col < end_col; col++) + *str++ = *t++; + if (!(Options & Opt_select_trailing_spaces)) { + for (str--; *str == ' ' || *str == '\t'; str--); + str++; + } + if (i) + *str++ = '\n'; + *str = '\0'; + if ((i = strlen((char *) new_selection_text)) == 0) { + FREE(new_selection_text); + return; + } + selection.len = i; + if (selection.text) + FREE(selection.text); + selection.text = new_selection_text; + selection.screen = current_screen; - selection_copy(XA_PRIMARY); - D_SELECT(("selection.len=%d\n", selection.len)); - return; - tm = 0; + selection_copy(XA_PRIMARY); + D_SELECT(("selection.len=%d\n", selection.len)); + return; + tm = 0; } /* @@ -2752,15 +2753,14 @@ selection_click(int clicks, int x, int y) * row_col_t ext_beg, ext_end; */ - D_SELECT(("selection_click(%d, %d, %d)\n", clicks, x, y)); + D_SELECT(("selection_click(%d, %d, %d)\n", clicks, x, y)); - clicks = ((clicks - 1) % 3) + 1; - selection.clicks = clicks; /* save clicks so extend will work */ + clicks = ((clicks - 1) % 3) + 1; + selection.clicks = clicks; /* save clicks so extend will work */ - selection_start(x, y); /* adjusts for scroll offset */ - if (clicks == 2 || clicks == 3) - selection_extend_colrow(selection.mark.col, - selection.mark.row + TermWin.view_start, 0, 1); + selection_start(x, y); /* adjusts for scroll offset */ + if (clicks == 2 || clicks == 3) + selection_extend_colrow(selection.mark.col, selection.mark.row + TermWin.view_start, 0, 1); } /* @@ -2782,177 +2782,176 @@ selection_click(int clicks, int x, int y) void selection_delimit_word(int col, int row, row_col_t *beg, row_col_t *end) { - int beg_col, beg_row, end_col, end_row, last_col; - int row_offset, w1; - text_t *stp, *stp1, t; + int beg_col, beg_row, end_col, end_row, last_col; + int row_offset, w1; + text_t *stp, *stp1, t; #ifdef MULTI_CHARSET - int w2; - rend_t *srp, r; + int w2; + rend_t *srp, r; #endif - if (selection.clicks != 2) /* We only handle double clicks: go away */ - return; + if (selection.clicks != 2) /* We only handle double clicks: go away */ + return; - if (!screen.text || !screen.rend) - return; + if (!screen.text || !screen.rend) + return; - last_col = TermWin.ncol - 1; + last_col = TermWin.ncol - 1; - if (row >= TermWin.nrow) { - row = TermWin.nrow - 1; - col = last_col; - } else if (row < -TermWin.saveLines) { - row = -TermWin.saveLines; - col = 0; - } - beg_col = end_col = col; - beg_row = end_row = row; + if (row >= TermWin.nrow) { + row = TermWin.nrow - 1; + col = last_col; + } else if (row < -TermWin.saveLines) { + row = -TermWin.saveLines; + col = 0; + } + beg_col = end_col = col; + beg_row = end_row = row; - row_offset = TermWin.saveLines; + row_offset = TermWin.saveLines; /* A: find the beginning of the word */ - if (!screen.text[beg_row + row_offset] || !screen.rend[beg_row + row_offset]) - return; - if (!screen.text[end_row + row_offset] || !screen.rend[end_row + row_offset]) - return; + if (!screen.text[beg_row + row_offset] || !screen.rend[beg_row + row_offset]) + return; + if (!screen.text[end_row + row_offset] || !screen.rend[end_row + row_offset]) + return; #if 0 - if (!screen.text[beg_row + row_offset - 1] || !screen.rend[beg_row + row_offset - 1]) - return; - if (!screen.text[end_row + row_offset + 1] || !screen.rend[end_row + row_offset + 1]) - return; + if (!screen.text[beg_row + row_offset - 1] || !screen.rend[beg_row + row_offset - 1]) + return; + if (!screen.text[end_row + row_offset + 1] || !screen.rend[end_row + row_offset + 1]) + return; #endif - stp1 = stp = &(screen.text[beg_row + row_offset][beg_col]); - w1 = DELIMIT_TEXT(*stp); - if (w1 == 2) - w1 = 0; + stp1 = stp = &(screen.text[beg_row + row_offset][beg_col]); + w1 = DELIMIT_TEXT(*stp); + if (w1 == 2) + w1 = 0; #ifdef MULTI_CHARSET - srp = &(screen.rend[beg_row + row_offset][beg_col]); - w2 = DELIMIT_REND(*srp); + srp = &(screen.rend[beg_row + row_offset][beg_col]); + w2 = DELIMIT_REND(*srp); #endif - for (;;) { - for (; beg_col > 0; beg_col--) { - t = *--stp; - if (DELIMIT_TEXT(t) != w1 || (w1 && *stp1 != t && Options & Opt_xterm_select)) - break; + for (;;) { + for (; beg_col > 0; beg_col--) { + t = *--stp; + if (DELIMIT_TEXT(t) != w1 || (w1 && *stp1 != t && Options & Opt_xterm_select)) + break; #ifdef MULTI_CHARSET - r = *--srp; - if (DELIMIT_REND(r) != w2) - break; + r = *--srp; + if (DELIMIT_REND(r) != w2) + break; #endif - } - if (!(Options & Opt_xterm_select)) { - if (beg_col == col && beg_col > 0) { - if (DELIMIT_TEXT(*stp)) /* space or tab or cutchar */ - break; + } + if (!(Options & Opt_xterm_select)) { + if (beg_col == col && beg_col > 0) { + if (DELIMIT_TEXT(*stp)) /* space or tab or cutchar */ + break; #ifdef MULTI_CHARSET - srp = &(screen.rend[beg_row + row_offset][beg_col - 1]); + srp = &(screen.rend[beg_row + row_offset][beg_col - 1]); #endif - for (; --beg_col > 0;) { - t = *--stp; - if (DELIMIT_TEXT(t)) - break; + for (; --beg_col > 0;) { + t = *--stp; + if (DELIMIT_TEXT(t)) + break; #ifdef MULTI_CHARSET - r = *--srp; - if (DELIMIT_REND(r) != w2) - break; + r = *--srp; + if (DELIMIT_REND(r) != w2) + break; #endif - } - } - } - if (beg_col == 0 && (beg_row > -TermWin.nscrolled)) { - stp = &(screen.text[beg_row + row_offset - 1][last_col + 1]); - if (*stp == WRAP_CHAR) { - t = *(stp - 1); + } + } + } + if (beg_col == 0 && (beg_row > -TermWin.nscrolled)) { + stp = &(screen.text[beg_row + row_offset - 1][last_col + 1]); + if (*stp == WRAP_CHAR) { + t = *(stp - 1); #ifdef MULTI_CHARSET - srp = &(screen.rend[beg_row + row_offset - 1][last_col + 1]); - r = *(srp - 1); - if (DELIMIT_TEXT(t) == w1 && (!w1 || *stp == t || !(Options & Opt_xterm_select)) && DELIMIT_REND(r) == w2) { - srp--; + srp = &(screen.rend[beg_row + row_offset - 1][last_col + 1]); + r = *(srp - 1); + if (DELIMIT_TEXT(t) == w1 && (!w1 || *stp == t || !(Options & Opt_xterm_select)) && DELIMIT_REND(r) == w2) { + srp--; #else - if (DELIMIT_TEXT(t) == w1 && (!w1 || *stp == t || !(Options & Opt_xterm_select))) { + if (DELIMIT_TEXT(t) == w1 && (!w1 || *stp == t || !(Options & Opt_xterm_select))) { #endif - stp--; - beg_row--; - beg_col = last_col; - continue; - } - } + stp--; + beg_row--; + beg_col = last_col; + continue; + } + } + } + break; } - break; - } /* B: find the end of the word */ # ifdef OPTIMIZE_HACKS - stp = stp1; + stp = stp1; # else - stp1 = stp = &(screen.text[end_row + row_offset][end_col]); + stp1 = stp = &(screen.text[end_row + row_offset][end_col]); # endif #ifdef MULTI_CHARSET - srp = &(screen.rend[end_row + row_offset][end_col]); + srp = &(screen.rend[end_row + row_offset][end_col]); #endif - for (;;) { - for (; end_col < last_col; end_col++) { - t = *++stp; - if (DELIMIT_TEXT(t) != w1 || (w1 && *stp1 != t && Options & Opt_xterm_select)) - break; + for (;;) { + for (; end_col < last_col; end_col++) { + t = *++stp; + if (DELIMIT_TEXT(t) != w1 || (w1 && *stp1 != t && Options & Opt_xterm_select)) + break; #ifdef MULTI_CHARSET - r = *++srp; - if (DELIMIT_REND(r) != w2) - break; + r = *++srp; + if (DELIMIT_REND(r) != w2) + break; #endif - } - if (!(Options & Opt_xterm_select)) { - if (end_col == col && end_col < last_col) { - if (DELIMIT_TEXT(*stp)) /* space or tab or cutchar */ - break; + } + if (!(Options & Opt_xterm_select)) { + if (end_col == col && end_col < last_col) { + if (DELIMIT_TEXT(*stp)) /* space or tab or cutchar */ + break; #ifdef MULTI_CHARSET - srp = &(screen.rend[end_row + row_offset][end_col + 1]); + srp = &(screen.rend[end_row + row_offset][end_col + 1]); #endif - for (; ++end_col < last_col;) { - t = *++stp; - if (DELIMIT_TEXT(t)) - break; + for (; ++end_col < last_col;) { + t = *++stp; + if (DELIMIT_TEXT(t)) + break; #ifdef MULTI_CHARSET - r = *++srp; - if (DELIMIT_REND(r) != w2) - break; + r = *++srp; + if (DELIMIT_REND(r) != w2) + break; #endif - } - } - } - if (end_col == last_col - && (end_row < (TermWin.nrow - 1))) { - if (*++stp == WRAP_CHAR) { - stp = screen.text[end_row + row_offset + 1]; + } + } + } + if (end_col == last_col && (end_row < (TermWin.nrow - 1))) { + if (*++stp == WRAP_CHAR) { + stp = screen.text[end_row + row_offset + 1]; #ifdef MULTI_CHARSET - srp = screen.rend[end_row + row_offset + 1]; - if (DELIMIT_TEXT(*stp) == w1 && (!w1 || *stp1 == *stp || !(Options & Opt_xterm_select)) && DELIMIT_REND(*srp) == w2) { + srp = screen.rend[end_row + row_offset + 1]; + if (DELIMIT_TEXT(*stp) == w1 && (!w1 || *stp1 == *stp || !(Options & Opt_xterm_select)) && DELIMIT_REND(*srp) == w2) { #else - if (DELIMIT_TEXT(*stp) == w1 && (!w1 || *stp1 == *stp || !(Options & Opt_xterm_select))) { + if (DELIMIT_TEXT(*stp) == w1 && (!w1 || *stp1 == *stp || !(Options & Opt_xterm_select))) { #endif - end_row++; - end_col = 0; - continue; - } - } + end_row++; + end_col = 0; + continue; + } + } + } + break; } - break; - } - D_SELECT(("selection_delimit_word(%d, %d) says (%d,%d)->(%d,%d)\n", col, row, beg_col, beg_row, end_col, end_row)); + D_SELECT(("selection_delimit_word(%d, %d) says (%d,%d)->(%d,%d)\n", col, row, beg_col, beg_row, end_col, end_row)); /* Poke the values back in */ - beg->col = beg_col; - beg->row = beg_row; - end->col = end_col; - end->row = end_row; + beg->col = beg_col; + beg->row = beg_row; + end->col = end_col; + end->row = end_row; } /* @@ -2964,7 +2963,7 @@ selection_delimit_word(int col, int row, row_col_t *beg, row_col_t *end) void selection_extend(int x, int y, int flag) { - int col, row; + int col, row; /* * If we're selecting characters (single click) then we must check first @@ -2972,22 +2971,21 @@ selection_extend(int x, int y, int flag) * select nothing. Otherwise, if we're to the right of the mark, you have to * be _past_ a character for it to be selected. */ - col = Pixel2Col(x); - row = Pixel2Row(y); - BOUND(row, 0, TermWin.nrow - 1); - if (((selection.clicks % 3) == 1) && !flag && (col == selection.mark.col && (row == selection.mark.row + TermWin.view_start))) { - /* select nothing */ - selection_setclr(0, selection.beg.row, selection.beg.col, - selection.end.row, selection.end.col); - selection.beg.row = selection.end.row = selection.mark.row; - selection.beg.col = selection.end.col = selection.mark.col; - selection.clicks = 4; - D_SELECT(("selection.clicks = 4\n")); - return; - } - if (selection.clicks == 4) - selection.clicks = 1; - selection_extend_colrow(col, row, flag, 0); + col = Pixel2Col(x); + row = Pixel2Row(y); + BOUND(row, 0, TermWin.nrow - 1); + if (((selection.clicks % 3) == 1) && !flag && (col == selection.mark.col && (row == selection.mark.row + TermWin.view_start))) { + /* select nothing */ + selection_setclr(0, selection.beg.row, selection.beg.col, selection.end.row, selection.end.col); + selection.beg.row = selection.end.row = selection.mark.row; + selection.beg.col = selection.end.col = selection.mark.col; + selection.clicks = 4; + D_SELECT(("selection.clicks = 4\n")); + return; + } + if (selection.clicks == 4) + selection.clicks = 1; + selection_extend_colrow(col, row, flag, 0); } /* @@ -2996,223 +2994,221 @@ selection_extend(int x, int y, int flag) void selection_extend_colrow(int col, int row, int flag, int cont) { - int old_col, end_col; - row_col_t new_beg1, new_beg2, new_end1, new_end2, old_beg, old_end; - enum { - LEFT, RIGHT - } closeto = RIGHT; + int old_col, end_col; + row_col_t new_beg1, new_beg2, new_end1, new_end2, old_beg, old_end; + enum { + LEFT, RIGHT + } closeto = RIGHT; #ifdef MULTI_CHARSET - int r; + int r; #endif - D_SELECT(("selection_extend_colrow(%d, %d, %d, %d) clicks:%d\n", col, row, flag, cont, selection.clicks)); + D_SELECT(("selection_extend_colrow(%d, %d, %d, %d) clicks:%d\n", col, row, flag, cont, selection.clicks)); - switch (selection.op) { - case SELECTION_INIT: - selection_reset(); - selection.end.col = selection.beg.col = selection.mark.col; - selection.end.row = selection.beg.row = selection.mark.row; - selection.op = SELECTION_BEGIN; - /* FALLTHROUGH */ - case SELECTION_BEGIN: - break; - case SELECTION_DONE: - selection.op = SELECTION_CONT; - /* FALLTHROUGH */ - case SELECTION_CONT: - break; - case SELECTION_CLEAR: - selection_start_colrow(col, row); - /* FALLTHROUGH */ - default: - return; - } - if ((selection.beg.row < -TermWin.nscrolled) - || (selection.end.row < -TermWin.nscrolled)) { - selection_reset(); - return; - } - old_col = col; - BOUND(col, -1, TermWin.ncol); - old_beg.col = selection.beg.col; - old_beg.row = selection.beg.row; - old_end.col = selection.end.col; - old_end.row = selection.end.row; + switch (selection.op) { + case SELECTION_INIT: + selection_reset(); + selection.end.col = selection.beg.col = selection.mark.col; + selection.end.row = selection.beg.row = selection.mark.row; + selection.op = SELECTION_BEGIN; + /* FALLTHROUGH */ + case SELECTION_BEGIN: + break; + case SELECTION_DONE: + selection.op = SELECTION_CONT; + /* FALLTHROUGH */ + case SELECTION_CONT: + break; + case SELECTION_CLEAR: + selection_start_colrow(col, row); + /* FALLTHROUGH */ + default: + return; + } + if ((selection.beg.row < -TermWin.nscrolled) + || (selection.end.row < -TermWin.nscrolled)) { + selection_reset(); + return; + } + old_col = col; + BOUND(col, -1, TermWin.ncol); + old_beg.col = selection.beg.col; + old_beg.row = selection.beg.row; + old_end.col = selection.end.col; + old_end.row = selection.end.row; - if ((selection.op == SELECTION_BEGIN) && (cont || (row != selection.mark.row || col != selection.mark.col))) - selection.op = SELECTION_CONT; + if ((selection.op == SELECTION_BEGIN) && (cont || (row != selection.mark.row || col != selection.mark.col))) + selection.op = SELECTION_CONT; - row -= TermWin.view_start; /* adjust for scroll */ + row -= TermWin.view_start; /* adjust for scroll */ - if (flag) { - if (row < selection.beg.row - || (row == selection.beg.row && col < selection.beg.col)) - closeto = LEFT; - else if (row > selection.end.row - || (row == selection.end.row && col >= selection.end.col)) { - /* */ ; - } else if (((col - selection.beg.col) - + ((row - selection.beg.row) * TermWin.ncol)) - < ((selection.end.col - col) - + ((selection.end.row - row) * TermWin.ncol))) - closeto = LEFT; - } - if (selection.clicks == 1) { + if (flag) { + if (row < selection.beg.row || (row == selection.beg.row && col < selection.beg.col)) + closeto = LEFT; + else if (row > selection.end.row || (row == selection.end.row && col >= selection.end.col)) { + /* */ ; + } else if (((col - selection.beg.col) + + ((row - selection.beg.row) * TermWin.ncol)) + < ((selection.end.col - col) + + ((selection.end.row - row) * TermWin.ncol))) + closeto = LEFT; + } + if (selection.clicks == 1) { /* * A1: extension on single click - selection between points */ - if (flag) { /* button 3 extension */ - if (closeto == LEFT) { - selection.beg.row = row; - selection.beg.col = col; - end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; - if (end_col != WRAP_CHAR && selection.beg.col > end_col) { - if (selection.beg.row < selection.end.row) { - selection.beg.col = -1; - selection.beg.row++; - } else { - selection.beg.col = selection.mark.col; - selection.beg.row = selection.mark.row; - } - } - } else { - selection.end.row = row; - selection.end.col = col - 1; - end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; - if (end_col != WRAP_CHAR && selection.end.col >= end_col) - selection.end.col = TermWin.ncol - 1; - } - } else if ((row < selection.mark.row) - || (row == selection.mark.row && col < selection.mark.col)) { - /* select left of mark character excluding mark */ - selection.beg.row = row; - selection.beg.col = col; - selection.end.row = selection.mark.row; - selection.end.col = selection.mark.col - 1; - if (selection.end.col >= 0) { - end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; - if (end_col != WRAP_CHAR && selection.beg.col > end_col) { - if (selection.beg.row < selection.end.row) { - selection.beg.col = -1; - selection.beg.row++; - } else { - selection.beg.col = selection.mark.col; - selection.beg.row = selection.mark.row; - } - } - } - } else { - /* select right of mark character including mark */ - selection.beg.row = selection.mark.row; - selection.beg.col = selection.mark.col; - selection.end.row = row; - selection.end.col = col - 1; - if (old_col >= 0) { - end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; - if (end_col != WRAP_CHAR && selection.end.col >= end_col) - selection.end.col = TermWin.ncol - 1; - } - } + if (flag) { /* button 3 extension */ + if (closeto == LEFT) { + selection.beg.row = row; + selection.beg.col = col; + end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; + if (end_col != WRAP_CHAR && selection.beg.col > end_col) { + if (selection.beg.row < selection.end.row) { + selection.beg.col = -1; + selection.beg.row++; + } else { + selection.beg.col = selection.mark.col; + selection.beg.row = selection.mark.row; + } + } + } else { + selection.end.row = row; + selection.end.col = col - 1; + end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; + if (end_col != WRAP_CHAR && selection.end.col >= end_col) + selection.end.col = TermWin.ncol - 1; + } + } else if ((row < selection.mark.row) + || (row == selection.mark.row && col < selection.mark.col)) { + /* select left of mark character excluding mark */ + selection.beg.row = row; + selection.beg.col = col; + selection.end.row = selection.mark.row; + selection.end.col = selection.mark.col - 1; + if (selection.end.col >= 0) { + end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; + if (end_col != WRAP_CHAR && selection.beg.col > end_col) { + if (selection.beg.row < selection.end.row) { + selection.beg.col = -1; + selection.beg.row++; + } else { + selection.beg.col = selection.mark.col; + selection.beg.row = selection.mark.row; + } + } + } + } else { + /* select right of mark character including mark */ + selection.beg.row = selection.mark.row; + selection.beg.col = selection.mark.col; + selection.end.row = row; + selection.end.col = col - 1; + if (old_col >= 0) { + end_col = screen.text[row + TermWin.saveLines][TermWin.ncol]; + if (end_col != WRAP_CHAR && selection.end.col >= end_col) + selection.end.col = TermWin.ncol - 1; + } + } #ifdef MULTI_CHARSET - if ((selection.beg.col > 0) && (selection.beg.col < TermWin.ncol)) { - r = selection.beg.row + TermWin.saveLines; - if (((screen.rend[r][selection.beg.col] & RS_multiMask) == RS_multi2) - && ((screen.rend[r][selection.beg.col - 1] & RS_multiMask) == RS_multi1)) - selection.beg.col--; - } - if ((selection.end.col > 0) && (selection.end.col < (TermWin.ncol - 1))) { - r = selection.end.row + TermWin.saveLines; - if (((screen.rend[r][selection.end.col] & RS_multiMask) == RS_multi1) - && ((screen.rend[r][selection.end.col + 1] & RS_multiMask) == RS_multi2)) - selection.end.col++; - } + if ((selection.beg.col > 0) && (selection.beg.col < TermWin.ncol)) { + r = selection.beg.row + TermWin.saveLines; + if (((screen.rend[r][selection.beg.col] & RS_multiMask) == RS_multi2) + && ((screen.rend[r][selection.beg.col - 1] & RS_multiMask) == RS_multi1)) + selection.beg.col--; + } + if ((selection.end.col > 0) && (selection.end.col < (TermWin.ncol - 1))) { + r = selection.end.row + TermWin.saveLines; + if (((screen.rend[r][selection.end.col] & RS_multiMask) == RS_multi1) + && ((screen.rend[r][selection.end.col + 1] & RS_multiMask) == RS_multi2)) + selection.end.col++; + } #endif - } else if (selection.clicks == 2) { + } else if (selection.clicks == 2) { /* * A2: extension on double click - selection between words */ - selection_delimit_word(col, row, &new_beg2, &new_end2); - if (flag && closeto == LEFT) - selection_delimit_word(selection.end.col, selection.end.row, &new_beg1, &new_end1); - else if (flag && closeto == RIGHT) - selection_delimit_word(selection.beg.col, selection.beg.row, &new_beg1, &new_end1); - else - selection_delimit_word(selection.mark.col, selection.mark.row, &new_beg1, &new_end1); - if ((!flag && (selection.mark.row < row || (selection.mark.row == row && selection.mark.col <= col))) - || (flag && closeto == RIGHT)) { - selection.beg.col = new_beg1.col; - selection.beg.row = new_beg1.row; - selection.end.col = new_end2.col; - selection.end.row = new_end2.row; - } else { - selection.beg.col = new_beg2.col; - selection.beg.row = new_beg2.row; - selection.end.col = new_end1.col; - selection.end.row = new_end1.row; - } - } else if (selection.clicks == 3) { + selection_delimit_word(col, row, &new_beg2, &new_end2); + if (flag && closeto == LEFT) + selection_delimit_word(selection.end.col, selection.end.row, &new_beg1, &new_end1); + else if (flag && closeto == RIGHT) + selection_delimit_word(selection.beg.col, selection.beg.row, &new_beg1, &new_end1); + else + selection_delimit_word(selection.mark.col, selection.mark.row, &new_beg1, &new_end1); + if ((!flag && (selection.mark.row < row || (selection.mark.row == row && selection.mark.col <= col))) + || (flag && closeto == RIGHT)) { + selection.beg.col = new_beg1.col; + selection.beg.row = new_beg1.row; + selection.end.col = new_end2.col; + selection.end.row = new_end2.row; + } else { + selection.beg.col = new_beg2.col; + selection.beg.row = new_beg2.row; + selection.end.col = new_end1.col; + selection.end.row = new_end1.row; + } + } else if (selection.clicks == 3) { /* * A3: extension on triple click - selection between lines */ - if (flag) { - if (closeto == LEFT) - selection.beg.row = row; - else - selection.end.row = row; - } else if (row <= selection.mark.row) { - selection.beg.row = row; - selection.end.row = selection.mark.row; - } else { - selection.beg.row = selection.mark.row; - selection.end.row = row; + if (flag) { + if (closeto == LEFT) + selection.beg.row = row; + else + selection.end.row = row; + } else if (row <= selection.mark.row) { + selection.beg.row = row; + selection.end.row = selection.mark.row; + } else { + selection.beg.row = selection.mark.row; + selection.end.row = row; + } + if (Options & Opt_select_whole_line) { + selection.beg.col = 0; + } else { + selection.clicks = 2; + selection_delimit_word(col, row, &new_beg2, &new_end2); + selection.beg.col = new_beg2.col; + selection.clicks = 3; + } + selection.end.col = TermWin.ncol - 1; } - if (Options & Opt_select_whole_line) { - selection.beg.col = 0; - } else { - selection.clicks = 2; - selection_delimit_word(col, row, &new_beg2, &new_end2); - selection.beg.col = new_beg2.col; - selection.clicks = 3; - } - selection.end.col = TermWin.ncol - 1; - } - D_SELECT(("(c:%d,r:%d)-(c:%d,r:%d) old (c:%d,r:%d)-(c:%d,r:%d)\n", selection.beg.col, selection.beg.row, - selection.end.col, selection.end.row, old_beg.col, old_beg.row, old_end.col, old_end.row)); + D_SELECT(("(c:%d,r:%d)-(c:%d,r:%d) old (c:%d,r:%d)-(c:%d,r:%d)\n", selection.beg.col, selection.beg.row, + selection.end.col, selection.end.row, old_beg.col, old_beg.row, old_end.col, old_end.row)); /* * B1: clear anything before the current selection */ - if ((old_beg.row < selection.beg.row) || (old_beg.row == selection.beg.row && old_beg.col < selection.beg.col)) { - if (selection.beg.col < TermWin.ncol - 1) { - row = selection.beg.row; - col = selection.beg.col + 1; - } else { - row = selection.beg.row + 1; - col = 0; + if ((old_beg.row < selection.beg.row) || (old_beg.row == selection.beg.row && old_beg.col < selection.beg.col)) { + if (selection.beg.col < TermWin.ncol - 1) { + row = selection.beg.row; + col = selection.beg.col + 1; + } else { + row = selection.beg.row + 1; + col = 0; + } + selection_setclr(0, old_beg.row, old_beg.col, row, col); } - selection_setclr(0, old_beg.row, old_beg.col, row, col); - } /* * B2: clear anything after the current selection */ - if ((old_end.row > selection.end.row) || (old_end.row == selection.end.row && old_end.col > selection.end.col)) { - if (selection.end.col > 0) { - row = selection.end.row; - col = selection.end.col - 1; - } else { - row = selection.end.row - 1; - col = TermWin.ncol - 1; + if ((old_end.row > selection.end.row) || (old_end.row == selection.end.row && old_end.col > selection.end.col)) { + if (selection.end.col > 0) { + row = selection.end.row; + col = selection.end.col - 1; + } else { + row = selection.end.row - 1; + col = TermWin.ncol - 1; + } + selection_setclr(0, row, col, old_end.row, old_end.col); } - selection_setclr(0, row, col, old_end.row, old_end.col); - } /* * B3: set everything */ /* TODO: optimise this */ - selection_setclr(1, selection.beg.row, selection.beg.col, selection.end.row, selection.end.col); - return; + selection_setclr(1, selection.beg.row, selection.beg.col, selection.end.row, selection.end.col); + return; } /* @@ -3222,12 +3218,12 @@ selection_extend_colrow(int col, int row, int flag, int cont) void selection_rotate(int x, int y) { - int col, row; + int col, row; - col = Pixel2Col(x); - row = Pixel2Row(y); - selection.clicks = selection.clicks % 3 + 1; - selection_extend_colrow(col, row, 1, 0); + col = Pixel2Col(x); + row = Pixel2Row(y); + selection.clicks = selection.clicks % 3 + 1; + selection_extend_colrow(col, row, 1, 0); } /* @@ -3244,127 +3240,134 @@ typedef CARD32 Atom32; void selection_send(XSelectionRequestEvent * rq) { - XEvent ev; - Atom32 target_list[2]; + XEvent ev; + Atom32 target_list[2]; - ev.xselection.type = SelectionNotify; - ev.xselection.property = None; - ev.xselection.display = rq->display; - ev.xselection.requestor = rq->requestor; - ev.xselection.selection = rq->selection; - ev.xselection.target = rq->target; - ev.xselection.time = rq->time; + ev.xselection.type = SelectionNotify; + ev.xselection.property = None; + ev.xselection.display = rq->display; + ev.xselection.requestor = rq->requestor; + ev.xselection.selection = rq->selection; + ev.xselection.target = rq->target; + ev.xselection.time = rq->time; - if (rq->target == props[PROP_SELECTION_TARGETS]) { - target_list[0] = (Atom32) props[PROP_SELECTION_TARGETS]; - target_list[1] = (Atom32) XA_STRING; - XChangeProperty(Xdisplay, rq->requestor, rq->property, rq->target, - (8 * sizeof(target_list[0])), PropModeReplace, - (unsigned char *) target_list, - (sizeof(target_list) / sizeof(target_list[0]))); - ev.xselection.property = rq->property; -#if defined(MULTI_CHARSET) && defined(HAVE_X11_XMU_ATOMS_H) - } else if (rq->target == XA_TEXT(Xdisplay) || rq->target == XA_COMPOUND_TEXT(Xdisplay)) { - XTextProperty xtextp; - char *l[1]; - - *l = selection.text; - xtextp.value = NULL; - xtextp.nitems = 0; - if (XmbTextListToTextProperty(Xdisplay, l, 1, XCompoundTextStyle, &xtextp) == Success) { - if (xtextp.nitems > 0 && xtextp.value != NULL) { - XChangeProperty(Xdisplay, rq->requestor, rq->property, XA_COMPOUND_TEXT(Xdisplay), 8, PropModeReplace, xtextp.value, xtextp.nitems); + if (rq->target == props[PROP_SELECTION_TARGETS]) { + target_list[0] = (Atom32) props[PROP_SELECTION_TARGETS]; + target_list[1] = (Atom32) XA_STRING; + XChangeProperty(Xdisplay, rq->requestor, rq->property, rq->target, + (8 * sizeof(target_list[0])), PropModeReplace, + (unsigned char *) target_list, (sizeof(target_list) / sizeof(target_list[0]))); ev.xselection.property = rq->property; - } - } +#if defined(MULTI_CHARSET) && defined(HAVE_X11_XMU_ATOMS_H) + } else if (rq->target == XA_TEXT(Xdisplay) || rq->target == XA_COMPOUND_TEXT(Xdisplay)) { + XTextProperty xtextp; + char *l[1]; + + *l = selection.text; + xtextp.value = NULL; + xtextp.nitems = 0; + if (XmbTextListToTextProperty(Xdisplay, l, 1, XCompoundTextStyle, &xtextp) == Success) { + if (xtextp.nitems > 0 && xtextp.value != NULL) { + XChangeProperty(Xdisplay, rq->requestor, rq->property, XA_COMPOUND_TEXT(Xdisplay), 8, PropModeReplace, xtextp.value, + xtextp.nitems); + ev.xselection.property = rq->property; + } + } #endif - } else if (rq->target == XA_STRING) { - XChangeProperty(Xdisplay, rq->requestor, rq->property, rq->target, 8, PropModeReplace, selection.text, selection.len); - ev.xselection.property = rq->property; - } - XSendEvent(Xdisplay, rq->requestor, False, 0, &ev); + } else if (rq->target == XA_STRING) { + XChangeProperty(Xdisplay, rq->requestor, rq->property, rq->target, 8, PropModeReplace, selection.text, selection.len); + ev.xselection.property = rq->property; + } + XSendEvent(Xdisplay, rq->requestor, False, 0, &ev); } void mouse_report(XButtonEvent * ev) { - int button_number, key_state; + int button_number, key_state; - switch(ev->button) { - case AnyButton: /* Button release */ - button_number = 3; - break; - case Button1: /* Button press */ - case Button2: - case Button3: - button_number = ev->button - Button1; - break; - default: /* Wheel mouse */ - button_number = 64 + ev->button - Button3 - 1; - break; - } - key_state = ((ev->state & (ShiftMask | ControlMask)) - + ((ev->state & Mod1Mask) ? 2 : 0)); - tt_printf((unsigned char *) "\033[M%c%c%c", - (32 + button_number + (key_state << 2)), - (32 + Pixel2Col(ev->x) + 1), - (32 + Pixel2Row(ev->y) + 1)); + switch (ev->button) { + case AnyButton: /* Button release */ + button_number = 3; + break; + case Button1: /* Button press */ + case Button2: + case Button3: + button_number = ev->button - Button1; + break; + default: /* Wheel mouse */ + button_number = 64 + ev->button - Button3 - 1; + break; + } + key_state = ((ev->state & (ShiftMask | ControlMask)) + + ((ev->state & Mod1Mask) ? 2 : 0)); + tt_printf((unsigned char *) "\033[M%c%c%c", + (32 + button_number + (key_state << 2)), (32 + Pixel2Col(ev->x) + 1), (32 + Pixel2Row(ev->y) + 1)); } void debug_colors(void) { - int color; - char *name[] = - { - "fg", "bg", - "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white" - }; + int color; + char *name[] = { + "fg", "bg", + "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white" + }; - fprintf(stderr, "Color ( "); - if (rstyle & RS_RVid) - fprintf(stderr, "rvid "); - if (rstyle & RS_Bold) - fprintf(stderr, "bold "); - if (rstyle & RS_Blink) - fprintf(stderr, "blink "); - if (rstyle & RS_Uline) - fprintf(stderr, "uline "); - fprintf(stderr, "): "); + fprintf(stderr, "Color ( "); + if (rstyle & RS_RVid) + fprintf(stderr, "rvid "); + if (rstyle & RS_Bold) + fprintf(stderr, "bold "); + if (rstyle & RS_Blink) + fprintf(stderr, "blink "); + if (rstyle & RS_Uline) + fprintf(stderr, "uline "); + fprintf(stderr, "): "); - color = GET_FGCOLOR(rstyle); + color = GET_FGCOLOR(rstyle); #ifndef NO_BRIGHTCOLOR - if (color >= minBright && color <= maxBright) { - color -= (minBright - minColor); - fprintf(stderr, "bright "); - } + if (color >= minBright && color <= maxBright) { + color -= (minBright - minColor); + fprintf(stderr, "bright "); + } #endif - fprintf(stderr, "%s on ", name[color]); + fprintf(stderr, "%s on ", name[color]); - color = GET_BGCOLOR(rstyle); + color = GET_BGCOLOR(rstyle); #ifndef NO_BRIGHTCOLOR - if (color >= minBright && color <= maxBright) { - color -= (minBright - minColor); - fprintf(stderr, "bright "); - } + if (color >= minBright && color <= maxBright) { + color -= (minBright - minColor); + fprintf(stderr, "bright "); + } #endif - fprintf(stderr, "%s\n", name[color]); + fprintf(stderr, "%s\n", name[color]); } #ifdef USE_XIM -void xim_get_position(XPoint *pos) +void +xim_get_position(XPoint * pos) { - pos->x = Col2Pixel(screen.col); - if (scrollbar_is_visible() && !(Options & Opt_scrollbar_right)) { - pos->x += scrollbar_trough_width(); - } - pos->y = (Height2Pixel(screen.row) + pos->x = Col2Pixel(screen.col); + if (scrollbar_is_visible() && !(Options & Opt_scrollbar_right)) { + pos->x += scrollbar_trough_width(); + } + pos->y = (Height2Pixel(screen.row) # ifdef MULTI_CHARSET - + MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->ascent), TermWin.font->ascent) + + MAX((encoding_method == LATIN1 ? 0 : TermWin.mfont->ascent), TermWin.font->ascent) # else - + TermWin.font->ascent + + TermWin.font->ascent # endif - + TermWin.internalBorder - + bbar_calc_docked_height(BBAR_DOCKED_TOP)); + + TermWin.internalBorder + bbar_calc_docked_height(BBAR_DOCKED_TOP)); +} +#endif + +#ifdef ESCREEN +void +parse_screen_status_if_necessary(void) +{ + parse_screen(TermWin.screen, (TermWin.screen_pending > 1), TermWin.ncol, screen.text[TermWin.nrow + TermWin.saveLines - 1]); + if (TermWin.screen_pending > 1) + TermWin.screen_pending = 0; } #endif diff --git a/src/screen.h b/src/screen.h index c6aa1ba..97617df 100644 --- a/src/screen.h +++ b/src/screen.h @@ -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 diff --git a/src/script.c b/src/script.c index 366257c..e06f53e 100644 --- a/src/script.c +++ b/src/script.c @@ -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); } diff --git a/src/scrollbar.c b/src/scrollbar.c index b3d5f9c..b15be50 100644 --- a/src/scrollbar.c +++ b/src/scrollbar.c @@ -43,16 +43,16 @@ static const char cvs_ident[] = "$Id$"; event_dispatcher_data_t scrollbar_event_data; scrollbar_t scrollbar = { - None, None, None, None, - 0, 1, - 0, 1, - 0, - SCROLLBAR_DEFAULT_TYPE, - 0, - SHADOW, - SB_WIDTH, 0, - 0, 0, - 0, 0 + None, None, None, None, + 0, 1, + 0, 1, + 0, + SCROLLBAR_DEFAULT_TYPE, + 0, + SHADOW, + SB_WIDTH, 0, + 0, 0, + 0, 0 }; #ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING short scroll_arrow_delay; @@ -61,7 +61,7 @@ static GC gc_scrollbar; static short last_top = 0, last_bot = 0; #ifdef XTERM_SCROLLBAR static GC gc_stipple, gc_border; -static unsigned char xterm_sb_bits[] = {0xaa, 0x0a, 0x55, 0x05}; /* 12x2 bitmap */ +static unsigned char xterm_sb_bits[] = { 0xaa, 0x0a, 0x55, 0x05 }; /* 12x2 bitmap */ #endif #if defined(MOTIF_SCROLLBAR) || defined(NEXT_SCROLLBAR) static GC gc_top, gc_bottom; @@ -71,25 +71,25 @@ void scrollbar_event_init_dispatcher(void) { - MEMSET(&scrollbar_event_data, 0, sizeof(event_dispatcher_data_t)); + MEMSET(&scrollbar_event_data, 0, sizeof(event_dispatcher_data_t)); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, EnterNotify, sb_handle_enter_notify); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, LeaveNotify, sb_handle_leave_notify); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, FocusIn, sb_handle_focus_in); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, FocusOut, sb_handle_focus_out); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, GraphicsExpose, sb_handle_expose); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, Expose, sb_handle_expose); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, ButtonPress, sb_handle_button_press); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, ButtonRelease, sb_handle_button_release); - EVENT_DATA_ADD_HANDLER(scrollbar_event_data, MotionNotify, sb_handle_motion_notify); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, EnterNotify, sb_handle_enter_notify); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, LeaveNotify, sb_handle_leave_notify); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, FocusIn, sb_handle_focus_in); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, FocusOut, sb_handle_focus_out); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, GraphicsExpose, sb_handle_expose); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, Expose, sb_handle_expose); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, ButtonPress, sb_handle_button_press); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, ButtonRelease, sb_handle_button_release); + EVENT_DATA_ADD_HANDLER(scrollbar_event_data, MotionNotify, sb_handle_motion_notify); - event_data_add_mywin(&scrollbar_event_data, scrollbar.win); - event_data_add_mywin(&scrollbar_event_data, scrollbar.up_win); - event_data_add_mywin(&scrollbar_event_data, scrollbar.dn_win); - event_data_add_mywin(&scrollbar_event_data, scrollbar.sa_win); + event_data_add_mywin(&scrollbar_event_data, scrollbar.win); + event_data_add_mywin(&scrollbar_event_data, scrollbar.up_win); + event_data_add_mywin(&scrollbar_event_data, scrollbar.dn_win); + event_data_add_mywin(&scrollbar_event_data, scrollbar.sa_win); - event_data_add_parent(&scrollbar_event_data, TermWin.vt); - event_data_add_parent(&scrollbar_event_data, TermWin.parent); + event_data_add_parent(&scrollbar_event_data, TermWin.vt); + event_data_add_parent(&scrollbar_event_data, TermWin.parent); } @@ -97,943 +97,966 @@ unsigned char sb_handle_enter_notify(event_t *ev) { - D_EVENTS(("sb_handle_enter_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("sb_handle_enter_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); - if (scrollbar_win_is_uparrow(ev->xany.window)) { - scrollbar_draw_uparrow(IMAGE_STATE_SELECTED, 0); - } else if (scrollbar_win_is_downarrow(ev->xany.window)) { - scrollbar_draw_downarrow(IMAGE_STATE_SELECTED, 0); - } else if (scrollbar_win_is_anchor(ev->xany.window)) { - scrollbar_draw_anchor(IMAGE_STATE_SELECTED, 0); - } else if (scrollbar_win_is_trough(ev->xany.window)) { - scrollbar_draw_trough(IMAGE_STATE_SELECTED, 0); - } - return 1; + if (scrollbar_win_is_uparrow(ev->xany.window)) { + scrollbar_draw_uparrow(IMAGE_STATE_SELECTED, 0); + } else if (scrollbar_win_is_downarrow(ev->xany.window)) { + scrollbar_draw_downarrow(IMAGE_STATE_SELECTED, 0); + } else if (scrollbar_win_is_anchor(ev->xany.window)) { + scrollbar_draw_anchor(IMAGE_STATE_SELECTED, 0); + } else if (scrollbar_win_is_trough(ev->xany.window)) { + scrollbar_draw_trough(IMAGE_STATE_SELECTED, 0); + } + return 1; } unsigned char sb_handle_leave_notify(event_t *ev) { - D_EVENTS(("sb_handle_leave_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("sb_handle_leave_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); - if (scrollbar_win_is_uparrow(ev->xany.window)) { - scrollbar_draw_uparrow(IMAGE_STATE_NORMAL, 0); - } else if (scrollbar_win_is_downarrow(ev->xany.window)) { - scrollbar_draw_downarrow(IMAGE_STATE_NORMAL, 0); - } else if (scrollbar_win_is_anchor(ev->xany.window)) { - scrollbar_draw_anchor(IMAGE_STATE_NORMAL, 0); - } else if (scrollbar_win_is_trough(ev->xany.window)) { - scrollbar_draw_trough(IMAGE_STATE_NORMAL, 0); - } - return 1; + if (scrollbar_win_is_uparrow(ev->xany.window)) { + scrollbar_draw_uparrow(IMAGE_STATE_NORMAL, 0); + } else if (scrollbar_win_is_downarrow(ev->xany.window)) { + scrollbar_draw_downarrow(IMAGE_STATE_NORMAL, 0); + } else if (scrollbar_win_is_anchor(ev->xany.window)) { + scrollbar_draw_anchor(IMAGE_STATE_NORMAL, 0); + } else if (scrollbar_win_is_trough(ev->xany.window)) { + scrollbar_draw_trough(IMAGE_STATE_NORMAL, 0); + } + return 1; } unsigned char sb_handle_focus_in(event_t *ev) { - D_EVENTS(("sb_handle_focus_in(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("sb_handle_focus_in(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); - return 1; + return 1; } unsigned char sb_handle_focus_out(event_t *ev) { - D_EVENTS(("sb_handle_focus_out(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("sb_handle_focus_out(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); - return 1; + return 1; } unsigned char sb_handle_expose(event_t *ev) { - XEvent unused_xevent; + XEvent unused_xevent; - D_EVENTS(("sb_handle_expose(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("sb_handle_expose(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); - while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, Expose, &unused_xevent)); - while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, GraphicsExpose, &unused_xevent)); + while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, Expose, &unused_xevent)); + while (XCheckTypedWindowEvent(Xdisplay, ev->xany.window, GraphicsExpose, &unused_xevent)); - if (scrollbar_win_is_uparrow(ev->xany.window)) { - scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, 0); - } else if (scrollbar_win_is_downarrow(ev->xany.window)) { - scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, 0); - } else if (scrollbar_win_is_anchor(ev->xany.window)) { - scrollbar_draw_anchor(IMAGE_STATE_CURRENT, 0); - } else if (scrollbar_win_is_trough(ev->xany.window)) { - scrollbar_draw_trough(IMAGE_STATE_CURRENT, 0); - } - return 1; + if (scrollbar_win_is_uparrow(ev->xany.window)) { + scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, 0); + } else if (scrollbar_win_is_downarrow(ev->xany.window)) { + scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, 0); + } else if (scrollbar_win_is_anchor(ev->xany.window)) { + scrollbar_draw_anchor(IMAGE_STATE_CURRENT, 0); + } else if (scrollbar_win_is_trough(ev->xany.window)) { + scrollbar_draw_trough(IMAGE_STATE_CURRENT, 0); + } + return 1; } unsigned char sb_handle_button_press(event_t *ev) { - D_EVENTS(("sb_handle_button_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("sb_handle_button_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); - button_state.bypass_keystate = (ev->xbutton.state & (Mod1Mask | ShiftMask)); - button_state.report_mode = (button_state.bypass_keystate ? 0 : ((PrivateModes & PrivMode_mouse_report) ? 1 : 0)); - scrollbar_cancel_motion(); + button_state.bypass_keystate = (ev->xbutton.state & (Mod1Mask | ShiftMask)); + button_state.report_mode = (button_state.bypass_keystate ? 0 : ((PrivateModes & PrivMode_mouse_report) ? 1 : 0)); + scrollbar_cancel_motion(); #ifndef NO_SCROLLBAR_REPORT - if (button_state.report_mode) { - /* Mouse report disabled scrollbar. Arrows send cursor key up/down, trough sends pageup/pagedown */ - if (scrollbar_win_is_uparrow(ev->xany.window)) - tt_printf((unsigned char *) "\033[A"); - else if (scrollbar_win_is_downarrow(ev->xany.window)) - tt_printf((unsigned char *) "\033[B"); - else { - switch (ev->xbutton.button) { - case Button2: - tt_printf((unsigned char *) "\014"); - break; - case Button1: - tt_printf((unsigned char *) "\033[6~"); - break; - case Button3: - tt_printf((unsigned char *) "\033[5~"); - break; - } - } - } else + if (button_state.report_mode) { + /* Mouse report disabled scrollbar. Arrows send cursor key up/down, trough sends pageup/pagedown */ + if (scrollbar_win_is_uparrow(ev->xany.window)) + tt_printf((unsigned char *) "\033[A"); + else if (scrollbar_win_is_downarrow(ev->xany.window)) + tt_printf((unsigned char *) "\033[B"); + else { + switch (ev->xbutton.button) { + case Button2: + tt_printf((unsigned char *) "\014"); + break; + case Button1: + tt_printf((unsigned char *) "\033[6~"); + break; + case Button3: + tt_printf((unsigned char *) "\033[5~"); + break; + } + } + } else #endif /* NO_SCROLLBAR_REPORT */ - { - D_EVENTS(("ButtonPress event for window 0x%08x at %d, %d\n", ev->xany.window, ev->xbutton.x, ev->xbutton.y)); - D_EVENTS((" up [0x%08x], down [0x%08x], anchor [0x%08x], trough [0x%08x]\n", scrollbar.up_win, scrollbar.dn_win, scrollbar.sa_win, scrollbar.win)); + { + D_EVENTS(("ButtonPress event for window 0x%08x at %d, %d\n", ev->xany.window, ev->xbutton.x, ev->xbutton.y)); + D_EVENTS((" up [0x%08x], down [0x%08x], anchor [0x%08x], trough [0x%08x]\n", scrollbar.up_win, scrollbar.dn_win, scrollbar.sa_win, + scrollbar.win)); - if (scrollbar_win_is_uparrow(ev->xany.window)) { - scrollbar_draw_uparrow(IMAGE_STATE_CLICKED, 0); + if (scrollbar_win_is_uparrow(ev->xany.window)) { + scrollbar_draw_uparrow(IMAGE_STATE_CLICKED, 0); #ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY; + scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY; #endif - if (scr_page(UP, 1)) { - scrollbar_set_uparrow_pressed(1); - } - } else if (scrollbar_win_is_downarrow(ev->xany.window)) { - scrollbar_draw_downarrow(IMAGE_STATE_CLICKED, 0); + if (scr_page(UP, 1)) { + scrollbar_set_uparrow_pressed(1); + } + } else if (scrollbar_win_is_downarrow(ev->xany.window)) { + scrollbar_draw_downarrow(IMAGE_STATE_CLICKED, 0); #ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY; + scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY; #endif - if (scr_page(DN, 1)) { - scrollbar_set_downarrow_pressed(1); - } - } else { - if (scrollbar_win_is_anchor(ev->xany.window)) { - scrollbar_set_anchor_pressed(1); - scrollbar_draw_anchor(IMAGE_STATE_CLICKED, 0); - } - switch (ev->xbutton.button) { - case Button2: - button_state.mouse_offset = scrollbar_anchor_height() / 2; /* Align to center */ - if (!scrollbar_win_is_anchor(ev->xany.window)) { - scr_move_to(scrollbar_position(ev->xbutton.y) - button_state.mouse_offset, scrollbar_scrollarea_height()); - } else if (scrollbar.type == SCROLLBAR_XTERM) { - scr_move_to(scrollbar.anchor_top + ev->xbutton.y - button_state.mouse_offset, scrollbar_scrollarea_height()); - } - scrollbar_set_motion(1); - break; + if (scr_page(DN, 1)) { + scrollbar_set_downarrow_pressed(1); + } + } else { + if (scrollbar_win_is_anchor(ev->xany.window)) { + scrollbar_set_anchor_pressed(1); + scrollbar_draw_anchor(IMAGE_STATE_CLICKED, 0); + } + switch (ev->xbutton.button) { + case Button2: + button_state.mouse_offset = scrollbar_anchor_height() / 2; /* Align to center */ + if (!scrollbar_win_is_anchor(ev->xany.window)) { + scr_move_to(scrollbar_position(ev->xbutton.y) - button_state.mouse_offset, scrollbar_scrollarea_height()); + } else if (scrollbar.type == SCROLLBAR_XTERM) { + scr_move_to(scrollbar.anchor_top + ev->xbutton.y - button_state.mouse_offset, scrollbar_scrollarea_height()); + } + scrollbar_set_motion(1); + break; - case Button1: - button_state.mouse_offset = ((scrollbar_win_is_anchor(ev->xany.window)) ? (MAX(ev->xbutton.y, 1)) : (1)); - /* drop */ - case Button3: + case Button1: + button_state.mouse_offset = ((scrollbar_win_is_anchor(ev->xany.window)) ? (MAX(ev->xbutton.y, 1)) : (1)); + /* drop */ + case Button3: #if defined(MOTIF_SCROLLBAR) || defined(NEXT_SCROLLBAR) - if (scrollbar.type == SCROLLBAR_MOTIF || scrollbar.type == SCROLLBAR_NEXT) { - if (scrollbar_is_above_anchor(ev->xany.window, ev->xbutton.y)) { - scrollbar_draw_trough(IMAGE_STATE_CLICKED, 0); - scr_page(UP, TermWin.nrow - CONTEXT_LINES); - } else if (scrollbar_is_below_anchor(ev->xany.window, ev->xbutton.y)) { - scrollbar_draw_trough(IMAGE_STATE_CLICKED, 0); - scr_page(DN, TermWin.nrow - CONTEXT_LINES); - } else { - scrollbar_set_motion(1); - } - } + if (scrollbar.type == SCROLLBAR_MOTIF || scrollbar.type == SCROLLBAR_NEXT) { + if (scrollbar_is_above_anchor(ev->xany.window, ev->xbutton.y)) { + scrollbar_draw_trough(IMAGE_STATE_CLICKED, 0); + scr_page(UP, TermWin.nrow - CONTEXT_LINES); + } else if (scrollbar_is_below_anchor(ev->xany.window, ev->xbutton.y)) { + scrollbar_draw_trough(IMAGE_STATE_CLICKED, 0); + scr_page(DN, TermWin.nrow - CONTEXT_LINES); + } else { + scrollbar_set_motion(1); + } + } #endif /* MOTIF_SCROLLBAR || NEXT_SCROLLBAR */ #ifdef XTERM_SCROLLBAR - if (scrollbar.type == SCROLLBAR_XTERM) { - scr_page((ev->xbutton.button == Button1 ? DN : UP), TermWin.nrow - CONTEXT_LINES); - } + if (scrollbar.type == SCROLLBAR_XTERM) { + scr_page((ev->xbutton.button == Button1 ? DN : UP), TermWin.nrow - CONTEXT_LINES); + } #endif /* XTERM_SCROLLBAR */ - break; - } + break; + } + } } - } - return 1; + return 1; } unsigned char sb_handle_button_release(event_t *ev) { - Window root, child; - int root_x, root_y, win_x, win_y; - unsigned int mask; + Window root, child; + int root_x, root_y, win_x, win_y; + unsigned int mask; - D_EVENTS(("sb_handle_button_release(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("sb_handle_button_release(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); - button_state.mouse_offset = 0; - button_state.report_mode = (button_state.bypass_keystate ? 0 : ((PrivateModes & PrivMode_mouse_report) ? 1 : 0)); + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); + button_state.mouse_offset = 0; + button_state.report_mode = (button_state.bypass_keystate ? 0 : ((PrivateModes & PrivMode_mouse_report) ? 1 : 0)); - XQueryPointer(Xdisplay, scrollbar_get_win(), &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); - scrollbar_cancel_motion(); - if (scrollbar_win_is_uparrow(child)) { - scrollbar_draw_uparrow(IMAGE_STATE_SELECTED, 0); - } else { - scrollbar_draw_uparrow(IMAGE_STATE_NORMAL, 0); - } - if (scrollbar_win_is_downarrow(child)) { - scrollbar_draw_downarrow(IMAGE_STATE_SELECTED, 0); - } else { - scrollbar_draw_downarrow(IMAGE_STATE_NORMAL, 0); - } - if (scrollbar_win_is_anchor(child)) { - scrollbar_draw_anchor(IMAGE_STATE_SELECTED, 0); - } else { - scrollbar_draw_anchor(IMAGE_STATE_NORMAL, 0); - } - if (scrollbar_win_is_trough(child)) { - scrollbar_draw_trough(IMAGE_STATE_SELECTED, 0); - } else { - scrollbar_draw_trough(IMAGE_STATE_NORMAL, 0); - } - return 1; + XQueryPointer(Xdisplay, scrollbar_get_win(), &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); + scrollbar_cancel_motion(); + if (scrollbar_win_is_uparrow(child)) { + scrollbar_draw_uparrow(IMAGE_STATE_SELECTED, 0); + } else { + scrollbar_draw_uparrow(IMAGE_STATE_NORMAL, 0); + } + if (scrollbar_win_is_downarrow(child)) { + scrollbar_draw_downarrow(IMAGE_STATE_SELECTED, 0); + } else { + scrollbar_draw_downarrow(IMAGE_STATE_NORMAL, 0); + } + if (scrollbar_win_is_anchor(child)) { + scrollbar_draw_anchor(IMAGE_STATE_SELECTED, 0); + } else { + scrollbar_draw_anchor(IMAGE_STATE_NORMAL, 0); + } + if (scrollbar_win_is_trough(child)) { + scrollbar_draw_trough(IMAGE_STATE_SELECTED, 0); + } else { + scrollbar_draw_trough(IMAGE_STATE_NORMAL, 0); + } + return 1; } unsigned char sb_handle_motion_notify(event_t *ev) { - D_EVENTS(("sb_handle_motion_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); + D_EVENTS(("sb_handle_motion_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); - if ((PrivateModes & PrivMode_mouse_report) && !(button_state.bypass_keystate)) + REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &scrollbar_event_data), 0); + if ((PrivateModes & PrivMode_mouse_report) && !(button_state.bypass_keystate)) + return 1; + + D_EVENTS(("MotionNotify event for window 0x%08x\n", ev->xany.window)); + D_EVENTS((" up [0x%08x], down [0x%08x], anchor [0x%08x], trough [0x%08x]\n", scrollbar.up_win, scrollbar.dn_win, scrollbar.sa_win, + scrollbar.win)); + + if ((scrollbar_win_is_trough(ev->xany.window) || scrollbar_win_is_anchor(ev->xany.window)) && scrollbar_is_moving()) { + Window unused_root, unused_child; + int unused_root_x, unused_root_y; + unsigned int unused_mask; + + while (XCheckTypedWindowEvent(Xdisplay, scrollbar.win, MotionNotify, ev)); + XQueryPointer(Xdisplay, scrollbar.win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), + &(ev->xbutton.y), &unused_mask); + scr_move_to(scrollbar_position(ev->xbutton.y) - button_state.mouse_offset, scrollbar_scrollarea_height()); + refresh_count = refresh_limit = 0; + scr_refresh(refresh_type); + scrollbar_anchor_update_position(button_state.mouse_offset); + } return 1; - - D_EVENTS(("MotionNotify event for window 0x%08x\n", ev->xany.window)); - D_EVENTS((" up [0x%08x], down [0x%08x], anchor [0x%08x], trough [0x%08x]\n", scrollbar.up_win, scrollbar.dn_win, scrollbar.sa_win, scrollbar.win)); - - if ((scrollbar_win_is_trough(ev->xany.window) || scrollbar_win_is_anchor(ev->xany.window)) && scrollbar_is_moving()) { - Window unused_root, unused_child; - int unused_root_x, unused_root_y; - unsigned int unused_mask; - - while (XCheckTypedWindowEvent(Xdisplay, scrollbar.win, MotionNotify, ev)); - XQueryPointer(Xdisplay, scrollbar.win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y), &unused_mask); - scr_move_to(scrollbar_position(ev->xbutton.y) - button_state.mouse_offset, scrollbar_scrollarea_height()); - refresh_count = refresh_limit = 0; - scr_refresh(refresh_type); - scrollbar_anchor_update_position(button_state.mouse_offset); - } - return 1; } unsigned char scrollbar_dispatch_event(event_t *ev) { - if (scrollbar_event_data.handlers[ev->type] != NULL) { - return ((scrollbar_event_data.handlers[ev->type]) (ev)); - } - return (0); + if (scrollbar_event_data.handlers[ev->type] != NULL) { + return ((scrollbar_event_data.handlers[ev->type]) (ev)); + } + return (0); } /******************************************************************************/ void -scrollbar_draw_uparrow(unsigned char image_state, unsigned char force_modes) { +scrollbar_draw_uparrow(unsigned char image_state, unsigned char force_modes) +{ - D_SCROLLBAR(("scrollbar_draw_uparrow(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); - if (image_state != IMAGE_STATE_CURRENT) { - if ((image_state == IMAGE_STATE_NORMAL) && (images[image_up].current != images[image_up].norm)) { - images[image_up].current = images[image_up].norm; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_up].current != images[image_up].selected)) { - images[image_up].current = images[image_up].selected; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_up].current != images[image_up].clicked)) { - images[image_up].current = images[image_up].clicked; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_up].current != images[image_up].disabled)) { - images[image_up].current = images[image_up].disabled; - force_modes = MODE_MASK; + D_SCROLLBAR(("scrollbar_draw_uparrow(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); + if (image_state != IMAGE_STATE_CURRENT) { + if ((image_state == IMAGE_STATE_NORMAL) && (images[image_up].current != images[image_up].norm)) { + images[image_up].current = images[image_up].norm; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_up].current != images[image_up].selected)) { + images[image_up].current = images[image_up].selected; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_up].current != images[image_up].clicked)) { + images[image_up].current = images[image_up].clicked; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_up].current != images[image_up].disabled)) { + images[image_up].current = images[image_up].disabled; + force_modes = MODE_MASK; + } } - } - if (!image_mode_is(image_up, MODE_MASK)) { - /* Solid mode. Redraw every time since it's cheap. */ - if (Options & Opt_scrollbar_floating) { - XSetWindowBackground(Xdisplay, scrollbar.up_win, PixColors[bgColor]); - XClearWindow(Xdisplay, scrollbar.up_win); - } else { - XSetForeground(Xdisplay, gc_scrollbar, images[image_up].current->bg); - XFillRectangle(Xdisplay, scrollbar.up_win, gc_scrollbar, 0, 0, scrollbar_arrow_width(), scrollbar_arrow_height()); + if (!image_mode_is(image_up, MODE_MASK)) { + /* Solid mode. Redraw every time since it's cheap. */ + if (Options & Opt_scrollbar_floating) { + XSetWindowBackground(Xdisplay, scrollbar.up_win, PixColors[bgColor]); + XClearWindow(Xdisplay, scrollbar.up_win); + } else { + XSetForeground(Xdisplay, gc_scrollbar, images[image_up].current->bg); + XFillRectangle(Xdisplay, scrollbar.up_win, gc_scrollbar, 0, 0, scrollbar_arrow_width(), scrollbar_arrow_height()); + } + XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_up].current->bg, "")); + XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_up].current->bg, "")); + if (image_state == IMAGE_STATE_CLICKED) { + scrollbar_set_uparrow_pressed(1); + draw_uparrow_clicked(scrollbar.up_win, gc_top, gc_bottom, 0, 0, scrollbar_arrow_width() - 1, scrollbar_get_shadow()); + } else { + scrollbar_set_uparrow_pressed(0); + draw_uparrow_raised(scrollbar.up_win, gc_top, gc_bottom, 0, 0, scrollbar_arrow_width() - 1, scrollbar_get_shadow()); + } + return; } - XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_up].current->bg, "")); - XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_up].current->bg, "")); - if (image_state == IMAGE_STATE_CLICKED) { - scrollbar_set_uparrow_pressed(1); - draw_uparrow_clicked(scrollbar.up_win, gc_top, gc_bottom, 0, 0, scrollbar_arrow_width() - 1, scrollbar_get_shadow()); - } else { - scrollbar_set_uparrow_pressed(0); - draw_uparrow_raised(scrollbar.up_win, gc_top, gc_bottom, 0, 0, scrollbar_arrow_width() - 1, scrollbar_get_shadow()); + if (!((images[image_up].mode & MODE_MASK) & (force_modes))) { + return; } - return; - } - if (!((images[image_up].mode & MODE_MASK) & (force_modes))) { - return; - } - render_simage(images[image_up].current, scrollbar.up_win, scrollbar_arrow_width(), scrollbar_arrow_height(), image_up, 0); + render_simage(images[image_up].current, scrollbar.up_win, scrollbar_arrow_width(), scrollbar_arrow_height(), image_up, 0); } unsigned char -scrollbar_move_uparrow(void) { - static int last_x = -1, last_y = -1, last_w = -1, last_h = -1; - int x, y, w, h; +scrollbar_move_uparrow(void) +{ + static int last_x = -1, last_y = -1, last_w = -1, last_h = -1; + int x, y, w, h; - D_SCROLLBAR(("scrollbar_move_uparrow()\n")); - x = scrollbar_get_shadow(); - y = scrollbar_up_loc(); - w = scrollbar_arrow_width(); - h = scrollbar_arrow_height(); - if ((last_x == x) && (last_y == y) && (last_w == w) && (last_h == h)) { - D_SCROLLBAR((" -> No move required, returning 0.\n")); - return 0; - } - D_SCROLLBAR((" -> XMoveResizeWindow(Xdisplay, 0x%08x, %d, %d, %d, %d)\n", scrollbar.up_win, x, y, w, h)); - XMoveResizeWindow(Xdisplay, scrollbar.up_win, x, y, w, h); - last_x = x; - last_y = y; - last_w = w; - last_h = h; - return 1; + D_SCROLLBAR(("scrollbar_move_uparrow()\n")); + x = scrollbar_get_shadow(); + y = scrollbar_up_loc(); + w = scrollbar_arrow_width(); + h = scrollbar_arrow_height(); + if ((last_x == x) && (last_y == y) && (last_w == w) && (last_h == h)) { + D_SCROLLBAR((" -> No move required, returning 0.\n")); + return 0; + } + D_SCROLLBAR((" -> XMoveResizeWindow(Xdisplay, 0x%08x, %d, %d, %d, %d)\n", scrollbar.up_win, x, y, w, h)); + XMoveResizeWindow(Xdisplay, scrollbar.up_win, x, y, w, h); + last_x = x; + last_y = y; + last_w = w; + last_h = h; + return 1; } void -scrollbar_draw_downarrow(unsigned char image_state, unsigned char force_modes) { +scrollbar_draw_downarrow(unsigned char image_state, unsigned char force_modes) +{ - D_SCROLLBAR(("scrollbar_draw_downarrow(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); - if (image_state != IMAGE_STATE_CURRENT) { - if ((image_state == IMAGE_STATE_NORMAL) && (images[image_down].current != images[image_down].norm)) { - images[image_down].current = images[image_down].norm; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_down].current != images[image_down].selected)) { - images[image_down].current = images[image_down].selected; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_down].current != images[image_down].clicked)) { - images[image_down].current = images[image_down].clicked; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_down].current != images[image_down].disabled)) { - images[image_down].current = images[image_down].disabled; - force_modes = MODE_MASK; + D_SCROLLBAR(("scrollbar_draw_downarrow(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); + if (image_state != IMAGE_STATE_CURRENT) { + if ((image_state == IMAGE_STATE_NORMAL) && (images[image_down].current != images[image_down].norm)) { + images[image_down].current = images[image_down].norm; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_down].current != images[image_down].selected)) { + images[image_down].current = images[image_down].selected; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_down].current != images[image_down].clicked)) { + images[image_down].current = images[image_down].clicked; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_down].current != images[image_down].disabled)) { + images[image_down].current = images[image_down].disabled; + force_modes = MODE_MASK; + } } - } - if (!image_mode_is(image_down, MODE_MASK)) { - /* Solid mode. Redraw every time since it's cheap. */ - if (Options & Opt_scrollbar_floating) { - XSetWindowBackground(Xdisplay, scrollbar.dn_win, PixColors[bgColor]); - XClearWindow(Xdisplay, scrollbar.dn_win); - } else { - XSetForeground(Xdisplay, gc_scrollbar, images[image_down].current->bg); - XFillRectangle(Xdisplay, scrollbar.dn_win, gc_scrollbar, 0, 0, scrollbar_arrow_width(), scrollbar_arrow_height()); + if (!image_mode_is(image_down, MODE_MASK)) { + /* Solid mode. Redraw every time since it's cheap. */ + if (Options & Opt_scrollbar_floating) { + XSetWindowBackground(Xdisplay, scrollbar.dn_win, PixColors[bgColor]); + XClearWindow(Xdisplay, scrollbar.dn_win); + } else { + XSetForeground(Xdisplay, gc_scrollbar, images[image_down].current->bg); + XFillRectangle(Xdisplay, scrollbar.dn_win, gc_scrollbar, 0, 0, scrollbar_arrow_width(), scrollbar_arrow_height()); + } + XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_down].current->bg, "")); + XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_down].current->bg, "")); + if (image_state == IMAGE_STATE_CLICKED) { + scrollbar_set_downarrow_pressed(1); + draw_downarrow_clicked(scrollbar.dn_win, gc_top, gc_bottom, 0, 0, scrollbar_arrow_width() - 1, scrollbar_get_shadow()); + } else { + scrollbar_set_downarrow_pressed(0); + draw_downarrow_raised(scrollbar.dn_win, gc_top, gc_bottom, 0, 0, scrollbar_arrow_width() - 1, scrollbar_get_shadow()); + } + return; } - XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_down].current->bg, "")); - XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_down].current->bg, "")); - if (image_state == IMAGE_STATE_CLICKED) { - scrollbar_set_downarrow_pressed(1); - draw_downarrow_clicked(scrollbar.dn_win, gc_top, gc_bottom, 0, 0, scrollbar_arrow_width() - 1, scrollbar_get_shadow()); - } else { - scrollbar_set_downarrow_pressed(0); - draw_downarrow_raised(scrollbar.dn_win, gc_top, gc_bottom, 0, 0, scrollbar_arrow_width() - 1, scrollbar_get_shadow()); + if (!((images[image_down].mode & MODE_MASK) & (force_modes))) { + return; } - return; - } - if (!((images[image_down].mode & MODE_MASK) & (force_modes))) { - return; - } - render_simage(images[image_down].current, scrollbar.dn_win, scrollbar_arrow_width(), scrollbar_arrow_height(), image_down, 0); + render_simage(images[image_down].current, scrollbar.dn_win, scrollbar_arrow_width(), scrollbar_arrow_height(), image_down, 0); } unsigned char -scrollbar_move_downarrow(void) { - static int last_x = -1, last_y = -1, last_w = -1, last_h = -1; - int x, y, w, h; +scrollbar_move_downarrow(void) +{ + static int last_x = -1, last_y = -1, last_w = -1, last_h = -1; + int x, y, w, h; - D_SCROLLBAR(("scrollbar_move_downarrow()\n")); - x = scrollbar_get_shadow(); - y = scrollbar_dn_loc(); - w = scrollbar_arrow_width(); - h = scrollbar_arrow_height(); - if ((last_x == x) && (last_y == y) && (last_w == w) && (last_h == h)) { - D_SCROLLBAR((" -> No move required, returning 0.\n")); - return 0; - } - D_SCROLLBAR((" -> XMoveResizeWindow(Xdisplay, 0x%08x, %d, %d, %d, %d)\n", scrollbar.dn_win, x, y, w, h)); - XMoveResizeWindow(Xdisplay, scrollbar.dn_win, x, y, w, h); - last_x = x; - last_y = y; - last_w = w; - last_h = h; - return 1; + D_SCROLLBAR(("scrollbar_move_downarrow()\n")); + x = scrollbar_get_shadow(); + y = scrollbar_dn_loc(); + w = scrollbar_arrow_width(); + h = scrollbar_arrow_height(); + if ((last_x == x) && (last_y == y) && (last_w == w) && (last_h == h)) { + D_SCROLLBAR((" -> No move required, returning 0.\n")); + return 0; + } + D_SCROLLBAR((" -> XMoveResizeWindow(Xdisplay, 0x%08x, %d, %d, %d, %d)\n", scrollbar.dn_win, x, y, w, h)); + XMoveResizeWindow(Xdisplay, scrollbar.dn_win, x, y, w, h); + last_x = x; + last_y = y; + last_w = w; + last_h = h; + return 1; } void -scrollbar_draw_anchor(unsigned char image_state, unsigned char force_modes) { +scrollbar_draw_anchor(unsigned char image_state, unsigned char force_modes) +{ - D_SCROLLBAR(("scrollbar_draw_anchor(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); - if (image_state != IMAGE_STATE_CURRENT) { - if ((image_state == IMAGE_STATE_NORMAL) && (images[image_sa].current != images[image_sa].norm)) { - images[image_sa].current = images[image_sa].norm; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_sa].current != images[image_sa].selected)) { - images[image_sa].current = images[image_sa].selected; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_sa].current != images[image_sa].clicked)) { - images[image_sa].current = images[image_sa].clicked; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_sa].current != images[image_sa].disabled)) { - images[image_sa].current = images[image_sa].disabled; - force_modes = MODE_MASK; + D_SCROLLBAR(("scrollbar_draw_anchor(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); + if (image_state != IMAGE_STATE_CURRENT) { + if ((image_state == IMAGE_STATE_NORMAL) && (images[image_sa].current != images[image_sa].norm)) { + images[image_sa].current = images[image_sa].norm; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_sa].current != images[image_sa].selected)) { + images[image_sa].current = images[image_sa].selected; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_sa].current != images[image_sa].clicked)) { + images[image_sa].current = images[image_sa].clicked; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_sa].current != images[image_sa].disabled)) { + images[image_sa].current = images[image_sa].disabled; + force_modes = MODE_MASK; + } + if ((image_state == IMAGE_STATE_NORMAL) && (images[image_st].current != images[image_st].norm)) { + images[image_st].current = images[image_st].norm; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_st].current != images[image_st].selected)) { + images[image_st].current = images[image_st].selected; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_st].current != images[image_st].clicked)) { + images[image_st].current = images[image_st].clicked; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_st].current != images[image_st].disabled)) { + images[image_st].current = images[image_st].disabled; + force_modes = MODE_MASK; + } } - if ((image_state == IMAGE_STATE_NORMAL) && (images[image_st].current != images[image_st].norm)) { - images[image_st].current = images[image_st].norm; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_st].current != images[image_st].selected)) { - images[image_st].current = images[image_st].selected; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_st].current != images[image_st].clicked)) { - images[image_st].current = images[image_st].clicked; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_st].current != images[image_st].disabled)) { - images[image_st].current = images[image_st].disabled; - force_modes = MODE_MASK; - } - } - if (!image_mode_is(image_sa, MODE_MASK)) { - /* Solid mode. Redraw every time since it's cheap. */ + if (!image_mode_is(image_sa, MODE_MASK)) { + /* Solid mode. Redraw every time since it's cheap. */ #ifdef XTERM_SCROLLBAR - if (scrollbar.type == SCROLLBAR_XTERM) { - int x = ((Options & Opt_scrollbar_right) ? 1 : 0); + if (scrollbar.type == SCROLLBAR_XTERM) { + int x = ((Options & Opt_scrollbar_right) ? 1 : 0); - XSetForeground(Xdisplay, gc_stipple, images[image_sa].current->bg); - XFillRectangle(Xdisplay, scrollbar.sa_win, gc_stipple, x + 1, 0, scrollbar_anchor_width() - x - 1, scrollbar_anchor_height()); - XClearWindow(Xdisplay, scrollbar.sa_win); - } + XSetForeground(Xdisplay, gc_stipple, images[image_sa].current->bg); + XFillRectangle(Xdisplay, scrollbar.sa_win, gc_stipple, x + 1, 0, scrollbar_anchor_width() - x - 1, scrollbar_anchor_height()); + XClearWindow(Xdisplay, scrollbar.sa_win); + } #endif /* XTERM_SCROLLBAR */ #if defined(MOTIF_SCROLLBAR) || defined(NEXT_SCROLLBAR) - if (scrollbar.type == SCROLLBAR_MOTIF || scrollbar.type == SCROLLBAR_NEXT) { - if (Options & Opt_scrollbar_floating) { - XSetWindowBackground(Xdisplay, scrollbar.sa_win, PixColors[bgColor]); - XClearWindow(Xdisplay, scrollbar.sa_win); - } else { - XSetForeground(Xdisplay, gc_scrollbar, images[image_sa].current->bg); - XFillRectangle(Xdisplay, scrollbar.sa_win, gc_scrollbar, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height()); - } - XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_sa].current->bg, "")); - XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_sa].current->bg, "")); - if (scrollbar_anchor_is_pressed()) { - draw_shadow(scrollbar.sa_win, gc_bottom, gc_top, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height(), scrollbar_get_shadow()); - } else { - draw_shadow(scrollbar.sa_win, gc_top, gc_bottom, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height(), scrollbar_get_shadow()); - } - } + if (scrollbar.type == SCROLLBAR_MOTIF || scrollbar.type == SCROLLBAR_NEXT) { + if (Options & Opt_scrollbar_floating) { + XSetWindowBackground(Xdisplay, scrollbar.sa_win, PixColors[bgColor]); + XClearWindow(Xdisplay, scrollbar.sa_win); + } else { + XSetForeground(Xdisplay, gc_scrollbar, images[image_sa].current->bg); + XFillRectangle(Xdisplay, scrollbar.sa_win, gc_scrollbar, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height()); + } + XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_sa].current->bg, "")); + XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_sa].current->bg, "")); + if (scrollbar_anchor_is_pressed()) { + draw_shadow(scrollbar.sa_win, gc_bottom, gc_top, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height(), + scrollbar_get_shadow()); + } else { + draw_shadow(scrollbar.sa_win, gc_top, gc_bottom, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height(), + scrollbar_get_shadow()); + } + } #endif - return; - } - if (!((images[image_sa].mode & MODE_MASK) & (force_modes))) { - return; - } - if (scrollbar_anchor_height() > 1) { - unsigned char thumb; - Pixmap pmap; + return; + } + if (!((images[image_sa].mode & MODE_MASK) & (force_modes))) { + return; + } + if (scrollbar_anchor_height() > 1) { + unsigned char thumb; + Pixmap pmap; - thumb = (images[image_st].current->iml) ? 1 : 0; - render_simage(images[image_sa].current, scrollbar.sa_win, scrollbar_anchor_width(), scrollbar_anchor_height(), image_sa, thumb); - pmap = images[image_sa].current->pmap->pixmap; - /* Draw the thumb if there is one. */ - if (thumb) { - unsigned short tw = 0, th = 0; - imlib_t *iml = images[image_st].current->iml, *siml = images[image_sa].current->iml; + thumb = (images[image_st].current->iml) ? 1 : 0; + render_simage(images[image_sa].current, scrollbar.sa_win, scrollbar_anchor_width(), scrollbar_anchor_height(), image_sa, thumb); + pmap = images[image_sa].current->pmap->pixmap; + /* Draw the thumb if there is one. */ + if (thumb) { + unsigned short tw = 0, th = 0; + imlib_t *iml = images[image_st].current->iml, *siml = images[image_sa].current->iml; - if (image_mode_is(image_st, MODE_IMAGE) && iml->im) { + if (image_mode_is(image_st, MODE_IMAGE) && iml->im) { #ifdef PIXMAP_SUPPORT - imlib_context_set_image(iml->im); - tw = imlib_image_get_width(); - th = imlib_image_get_height(); + imlib_context_set_image(iml->im); + tw = imlib_image_get_width(); + th = imlib_image_get_height(); #endif - } else if (siml->bevel) { - tw = scrollbar_anchor_width() - (siml->bevel->edges->left + siml->bevel->edges->right); - th = scrollbar_anchor_width() - (siml->bevel->edges->top + siml->bevel->edges->bottom); - } else if (siml->border) { - tw = scrollbar_anchor_width() - (siml->border->left + siml->border->right); - th = scrollbar_anchor_width() - (siml->border->top + siml->border->bottom); - } else if (iml->bevel) { - tw = iml->bevel->edges->left + iml->bevel->edges->right + 4; - th = iml->bevel->edges->top + iml->bevel->edges->bottom + 4; - } - UPPER_BOUND(tw, scrollbar_anchor_width()); - UPPER_BOUND(th, scrollbar_anchor_height() >> 1); - D_SCROLLBAR(("Thumb width/height has been calculated at %hux%hu.\n", tw, th)); - if ((tw > 0) && (th > 0)) { - paste_simage(images[image_st].current, image_st, scrollbar.sa_win, pmap, - (scrollbar_anchor_width() - tw) >> 1, (scrollbar_anchor_height() - th) >> 1, tw, th); - XSetWindowBackgroundPixmap(Xdisplay, scrollbar.sa_win, pmap); - XClearWindow(Xdisplay, scrollbar.sa_win); - IMLIB_FREE_PIXMAP(pmap); - images[image_sa].current->pmap->pixmap = None; - } + } else if (siml->bevel) { + tw = scrollbar_anchor_width() - (siml->bevel->edges->left + siml->bevel->edges->right); + th = scrollbar_anchor_width() - (siml->bevel->edges->top + siml->bevel->edges->bottom); + } else if (siml->border) { + tw = scrollbar_anchor_width() - (siml->border->left + siml->border->right); + th = scrollbar_anchor_width() - (siml->border->top + siml->border->bottom); + } else if (iml->bevel) { + tw = iml->bevel->edges->left + iml->bevel->edges->right + 4; + th = iml->bevel->edges->top + iml->bevel->edges->bottom + 4; + } + UPPER_BOUND(tw, scrollbar_anchor_width()); + UPPER_BOUND(th, scrollbar_anchor_height() >> 1); + D_SCROLLBAR(("Thumb width/height has been calculated at %hux%hu.\n", tw, th)); + if ((tw > 0) && (th > 0)) { + paste_simage(images[image_st].current, image_st, scrollbar.sa_win, pmap, + (scrollbar_anchor_width() - tw) >> 1, (scrollbar_anchor_height() - th) >> 1, tw, th); + XSetWindowBackgroundPixmap(Xdisplay, scrollbar.sa_win, pmap); + XClearWindow(Xdisplay, scrollbar.sa_win); + IMLIB_FREE_PIXMAP(pmap); + images[image_sa].current->pmap->pixmap = None; + } + } } - } } unsigned char -scrollbar_move_anchor(void) { - static int last_x = -1, last_y = -1, last_w = -1, last_h = -1; - int x, y, w, h; +scrollbar_move_anchor(void) +{ + static int last_x = -1, last_y = -1, last_w = -1, last_h = -1; + int x, y, w, h; - D_SCROLLBAR(("Last values: %d, %d, %d, %d\n", last_x, last_y, last_w, last_h)); - x = scrollbar_get_shadow(); - y = scrollbar.anchor_top; - w = scrollbar_anchor_width(); - h = scrollbar_anchor_height(); - if ((last_x == x) && (last_y == y) && (last_w == w) && (last_h == h)) { - D_SCROLLBAR((" -> No move required, returning 0.\n")); - return 0; - } - D_SCROLLBAR((" -> XMoveResizeWindow(Xdisplay, 0x%08x, %d, %d, %d, %d)\n", scrollbar.sa_win, x, y, w, h)); - XMoveResizeWindow(Xdisplay, scrollbar.sa_win, x, y, w, h); - last_x = x; - last_y = y; - last_w = w; - last_h = h; - return 1; + D_SCROLLBAR(("Last values: %d, %d, %d, %d\n", last_x, last_y, last_w, last_h)); + x = scrollbar_get_shadow(); + y = scrollbar.anchor_top; + w = scrollbar_anchor_width(); + h = scrollbar_anchor_height(); + if ((last_x == x) && (last_y == y) && (last_w == w) && (last_h == h)) { + D_SCROLLBAR((" -> No move required, returning 0.\n")); + return 0; + } + D_SCROLLBAR((" -> XMoveResizeWindow(Xdisplay, 0x%08x, %d, %d, %d, %d)\n", scrollbar.sa_win, x, y, w, h)); + XMoveResizeWindow(Xdisplay, scrollbar.sa_win, x, y, w, h); + last_x = x; + last_y = y; + last_w = w; + last_h = h; + return 1; } void -scrollbar_draw_trough(unsigned char image_state, unsigned char force_modes) { +scrollbar_draw_trough(unsigned char image_state, unsigned char force_modes) +{ - D_SCROLLBAR(("scrollbar_draw_trough(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); - if (image_state != IMAGE_STATE_CURRENT) { - if ((image_state == IMAGE_STATE_NORMAL) && (images[image_sb].current != images[image_sb].norm)) { - images[image_sb].current = images[image_sb].norm; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_sb].current != images[image_sb].selected)) { - images[image_sb].current = images[image_sb].selected; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_sb].current != images[image_sb].clicked)) { - images[image_sb].current = images[image_sb].clicked; - force_modes = MODE_MASK; - } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_sb].current != images[image_sb].disabled)) { - images[image_sb].current = images[image_sb].disabled; - force_modes = MODE_MASK; + D_SCROLLBAR(("scrollbar_draw_trough(%u, 0x%02x)\n", (unsigned int) image_state, (unsigned int) force_modes)); + if (image_state != IMAGE_STATE_CURRENT) { + if ((image_state == IMAGE_STATE_NORMAL) && (images[image_sb].current != images[image_sb].norm)) { + images[image_sb].current = images[image_sb].norm; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_SELECTED) && (images[image_sb].current != images[image_sb].selected)) { + images[image_sb].current = images[image_sb].selected; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_CLICKED) && (images[image_sb].current != images[image_sb].clicked)) { + images[image_sb].current = images[image_sb].clicked; + force_modes = MODE_MASK; + } else if ((image_state == IMAGE_STATE_DISABLED) && (images[image_sb].current != images[image_sb].disabled)) { + images[image_sb].current = images[image_sb].disabled; + force_modes = MODE_MASK; + } } - } - if (!image_mode_is(image_sb, MODE_MASK)) { - /* Solid mode. Redraw every time since it's cheap. */ - if ((Options & Opt_scrollbar_floating) || (scrollbar.type == SCROLLBAR_XTERM)) { - XSetWindowBackground(Xdisplay, scrollbar.win, PixColors[bgColor]); - XClearWindow(Xdisplay, scrollbar.win); - } else { - XSetForeground(Xdisplay, gc_scrollbar, images[image_sb].current->bg); - XFillRectangle(Xdisplay, scrollbar.win, gc_scrollbar, 0, 0, scrollbar_trough_width(), scrollbar_trough_height()); - XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_sb].current->bg, "")); - XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_sb].current->bg, "")); - draw_shadow(scrollbar.win, gc_bottom, gc_top, 0, 0, scrollbar_trough_width(), scrollbar_trough_height(), scrollbar_get_shadow()); + if (!image_mode_is(image_sb, MODE_MASK)) { + /* Solid mode. Redraw every time since it's cheap. */ + if ((Options & Opt_scrollbar_floating) || (scrollbar.type == SCROLLBAR_XTERM)) { + XSetWindowBackground(Xdisplay, scrollbar.win, PixColors[bgColor]); + XClearWindow(Xdisplay, scrollbar.win); + } else { + XSetForeground(Xdisplay, gc_scrollbar, images[image_sb].current->bg); + XFillRectangle(Xdisplay, scrollbar.win, gc_scrollbar, 0, 0, scrollbar_trough_width(), scrollbar_trough_height()); + XSetForeground(Xdisplay, gc_top, get_top_shadow_color(images[image_sb].current->bg, "")); + XSetForeground(Xdisplay, gc_bottom, get_bottom_shadow_color(images[image_sb].current->bg, "")); + draw_shadow(scrollbar.win, gc_bottom, gc_top, 0, 0, scrollbar_trough_width(), scrollbar_trough_height(), + scrollbar_get_shadow()); + } + return; } - return; - } - if (!((images[image_sb].mode & MODE_MASK) & (force_modes))) { - return; - } - render_simage(images[image_sb].current, scrollbar.win, scrollbar_trough_width(), scrollbar_trough_height(), image_sb, 0); + if (!((images[image_sb].mode & MODE_MASK) & (force_modes))) { + return; + } + render_simage(images[image_sb].current, scrollbar.win, scrollbar_trough_width(), scrollbar_trough_height(), image_sb, 0); } void scrollbar_init(int width, int height) { - Cursor cursor; - long mask; + Cursor cursor; + long mask; - D_SCROLLBAR(("Initializing all scrollbar elements.\n")); + D_SCROLLBAR(("Initializing all scrollbar elements.\n")); - Attributes.background_pixel = images[image_sb].norm->bg; - Attributes.border_pixel = images[image_sb].norm->bg; - Attributes.override_redirect = TRUE; - Attributes.save_under = TRUE; - cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); - mask = ExposureMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask - | Button1MotionMask | Button2MotionMask | Button3MotionMask; - scrollbar_calc_size(width, height); - scrollbar.anchor_top = scrollbar.scrollarea_start; - scrollbar.anchor_bottom = scrollbar.scrollarea_end; + Attributes.background_pixel = images[image_sb].norm->bg; + Attributes.border_pixel = images[image_sb].norm->bg; + Attributes.override_redirect = TRUE; + Attributes.save_under = TRUE; + cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); + mask = ExposureMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask + | Button1MotionMask | Button2MotionMask | Button3MotionMask; + scrollbar_calc_size(width, height); + scrollbar.anchor_top = scrollbar.scrollarea_start; + scrollbar.anchor_bottom = scrollbar.scrollarea_end; - /* Create the scrollbar trough window. It will be the parent to the other windows. */ - scrollbar.win = XCreateWindow(Xdisplay, TermWin.parent, ((Options & Opt_scrollbar_right) ? (width - scrollbar_trough_width()) : (0)), bbar_calc_docked_height(BBAR_DOCKED_TOP), - scrollbar_trough_width(), height, 0, Xdepth, InputOutput, CopyFromParent, - CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap, &Attributes); - XDefineCursor(Xdisplay, scrollbar.win, cursor); - XSelectInput(Xdisplay, scrollbar.win, mask); - D_SCROLLBAR(("Created scrollbar window 0x%08x\n", scrollbar.win)); + /* Create the scrollbar trough window. It will be the parent to the other windows. */ + scrollbar.win = + XCreateWindow(Xdisplay, TermWin.parent, ((Options & Opt_scrollbar_right) ? (width - scrollbar_trough_width()) : (0)), + bbar_calc_docked_height(BBAR_DOCKED_TOP), scrollbar_trough_width(), height, 0, Xdepth, InputOutput, CopyFromParent, + CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap, &Attributes); + XDefineCursor(Xdisplay, scrollbar.win, cursor); + XSelectInput(Xdisplay, scrollbar.win, mask); + D_SCROLLBAR(("Created scrollbar window 0x%08x\n", scrollbar.win)); - /* Now the up arrow window. */ - scrollbar.up_win = XCreateWindow(Xdisplay, scrollbar.win, scrollbar_get_shadow(), scrollbar_up_loc(), scrollbar_arrow_width(), scrollbar_arrow_height(), - 0, Xdepth, InputOutput, CopyFromParent, CWOverrideRedirect | CWColormap, &Attributes); - XSelectInput(Xdisplay, scrollbar.up_win, mask); - D_SCROLLBAR(("Created scrollbar up arrow window 0x%08x\n", scrollbar.up_win)); + /* Now the up arrow window. */ + scrollbar.up_win = + XCreateWindow(Xdisplay, scrollbar.win, scrollbar_get_shadow(), scrollbar_up_loc(), scrollbar_arrow_width(), + scrollbar_arrow_height(), 0, Xdepth, InputOutput, CopyFromParent, CWOverrideRedirect | CWColormap, &Attributes); + XSelectInput(Xdisplay, scrollbar.up_win, mask); + D_SCROLLBAR(("Created scrollbar up arrow window 0x%08x\n", scrollbar.up_win)); - /* The down arrow window */ - scrollbar.dn_win = XCreateWindow(Xdisplay, scrollbar.win, scrollbar_get_shadow(), scrollbar_dn_loc(), scrollbar_arrow_width(), scrollbar_arrow_height(), - 0, Xdepth, InputOutput, CopyFromParent, CWOverrideRedirect | CWColormap, &Attributes); - XSelectInput(Xdisplay, scrollbar.dn_win, mask); - D_SCROLLBAR(("Created scrollbar down arrow window 0x%08x\n", scrollbar.dn_win)); + /* The down arrow window */ + scrollbar.dn_win = + XCreateWindow(Xdisplay, scrollbar.win, scrollbar_get_shadow(), scrollbar_dn_loc(), scrollbar_arrow_width(), + scrollbar_arrow_height(), 0, Xdepth, InputOutput, CopyFromParent, CWOverrideRedirect | CWColormap, &Attributes); + XSelectInput(Xdisplay, scrollbar.dn_win, mask); + D_SCROLLBAR(("Created scrollbar down arrow window 0x%08x\n", scrollbar.dn_win)); - /* The anchor window */ - scrollbar.sa_win = XCreateWindow(Xdisplay, scrollbar.win, scrollbar_get_shadow(), scrollbar.anchor_top, scrollbar_anchor_width(), scrollbar_anchor_height(), - 0, Xdepth, InputOutput, CopyFromParent, CWOverrideRedirect | CWSaveUnder | CWColormap, &Attributes); - XSelectInput(Xdisplay, scrollbar.sa_win, mask); - XMapWindow(Xdisplay, scrollbar.sa_win); - D_SCROLLBAR(("Created scrollbar anchor window 0x%08x\n", scrollbar.sa_win)); + /* The anchor window */ + scrollbar.sa_win = + XCreateWindow(Xdisplay, scrollbar.win, scrollbar_get_shadow(), scrollbar.anchor_top, scrollbar_anchor_width(), + scrollbar_anchor_height(), 0, Xdepth, InputOutput, CopyFromParent, CWOverrideRedirect | CWSaveUnder | CWColormap, + &Attributes); + XSelectInput(Xdisplay, scrollbar.sa_win, mask); + XMapWindow(Xdisplay, scrollbar.sa_win); + D_SCROLLBAR(("Created scrollbar anchor window 0x%08x\n", scrollbar.sa_win)); - if (scrollbar_get_type() != SCROLLBAR_XTERM) { - scrollbar_map_arrows(); - } - event_register_dispatcher(scrollbar_dispatch_event, scrollbar_event_init_dispatcher); + if (scrollbar_get_type() != SCROLLBAR_XTERM) { + scrollbar_map_arrows(); + } + event_register_dispatcher(scrollbar_dispatch_event, scrollbar_event_init_dispatcher); - scrollbar_drawing_init(); - scrollbar_draw(IMAGE_STATE_CURRENT, MODE_MASK); + scrollbar_drawing_init(); + scrollbar_draw(IMAGE_STATE_CURRENT, MODE_MASK); } unsigned char scrollbar_mapping(unsigned char show) { - unsigned char change = 0; + unsigned char change = 0; - D_SCROLLBAR(("scrollbar_mapping(%d)\n", show)); + D_SCROLLBAR(("scrollbar_mapping(%d)\n", show)); - if (show && !scrollbar_is_visible()) { - D_SCROLLBAR((" -> Mapping scrollbar window. Returning 1.\n")); - scrollbar_set_visible(1); - XMapWindow(Xdisplay, scrollbar.win); - change = 1; - } else if (!show && scrollbar_is_visible()) { - D_SCROLLBAR((" -> Unmapping scrollbar window. Returning 1.\n")); - scrollbar_set_visible(0); - XUnmapWindow(Xdisplay, scrollbar.win); - change = 1; - } else { - D_SCROLLBAR((" -> No action required. Returning 0.\n")); - } - return change; + if (show && !scrollbar_is_visible()) { + D_SCROLLBAR((" -> Mapping scrollbar window. Returning 1.\n")); + scrollbar_set_visible(1); + XMapWindow(Xdisplay, scrollbar.win); + change = 1; + } else if (!show && scrollbar_is_visible()) { + D_SCROLLBAR((" -> Unmapping scrollbar window. Returning 1.\n")); + scrollbar_set_visible(0); + XUnmapWindow(Xdisplay, scrollbar.win); + change = 1; + } else { + D_SCROLLBAR((" -> No action required. Returning 0.\n")); + } + return change; } void scrollbar_reset(void) { - D_SCROLLBAR(("scrollbar_reset()\n")); - last_top = last_bot = 0; - scrollbar.init = 0; + D_SCROLLBAR(("scrollbar_reset()\n")); + last_top = last_bot = 0; + scrollbar.init = 0; } void scrollbar_calc_size(int width, int height) { - D_SCROLLBAR(("scrollbar_calc_size(%d, %d), type == %u\n", width, height, scrollbar_get_type())); - scrollbar.scrollarea_start = 0; - scrollbar.scrollarea_end = height; - scrollbar.up_arrow_loc = 0; - scrollbar.down_arrow_loc = 0; + D_SCROLLBAR(("scrollbar_calc_size(%d, %d), type == %u\n", width, height, scrollbar_get_type())); + scrollbar.scrollarea_start = 0; + scrollbar.scrollarea_end = height; + scrollbar.up_arrow_loc = 0; + scrollbar.down_arrow_loc = 0; #ifdef MOTIF_SCROLLBAR - if (scrollbar.type == SCROLLBAR_MOTIF) { - /* arrows are as high as wide - leave 1 pixel gap */ - scrollbar.scrollarea_start += scrollbar_arrow_height() + scrollbar_get_shadow() + 1; - scrollbar.scrollarea_end -= scrollbar_arrow_height() + scrollbar_get_shadow() + 1; - scrollbar.up_arrow_loc = scrollbar_get_shadow(); - scrollbar.down_arrow_loc = scrollbar.scrollarea_end + 1; - } + if (scrollbar.type == SCROLLBAR_MOTIF) { + /* arrows are as high as wide - leave 1 pixel gap */ + scrollbar.scrollarea_start += scrollbar_arrow_height() + scrollbar_get_shadow() + 1; + scrollbar.scrollarea_end -= scrollbar_arrow_height() + scrollbar_get_shadow() + 1; + scrollbar.up_arrow_loc = scrollbar_get_shadow(); + scrollbar.down_arrow_loc = scrollbar.scrollarea_end + 1; + } #endif #ifdef NEXT_SCROLLBAR - if (scrollbar.type == SCROLLBAR_NEXT) { - scrollbar.scrollarea_start = scrollbar_get_shadow(); - scrollbar.scrollarea_end -= (scrollbar.width * 2 + (scrollbar_get_shadow() ? scrollbar_get_shadow() : 1) + 2); - scrollbar.up_arrow_loc = scrollbar.scrollarea_end + 1; - scrollbar.down_arrow_loc = scrollbar.scrollarea_end + scrollbar.width + 2; - } + if (scrollbar.type == SCROLLBAR_NEXT) { + scrollbar.scrollarea_start = scrollbar_get_shadow(); + scrollbar.scrollarea_end -= (scrollbar.width * 2 + (scrollbar_get_shadow()? scrollbar_get_shadow() : 1) + 2); + scrollbar.up_arrow_loc = scrollbar.scrollarea_end + 1; + scrollbar.down_arrow_loc = scrollbar.scrollarea_end + scrollbar.width + 2; + } #endif - scrollbar.height = height - (2 * scrollbar_get_shadow()); - scrollbar.win_width = scrollbar.width + (2 * scrollbar_get_shadow()); - scrollbar.win_height = height; - D_X11((" -> New scrollbar width/height == %hux%hu, win_width/height == %hux%hu\n", scrollbar.width, scrollbar.height, scrollbar.win_width, scrollbar.win_height)); - D_X11((" -> New scroll area start/end == %hu - %hu, up_arrow_loc == %hu, down_arrow_loc == %hu\n", scrollbar.scrollarea_start, scrollbar.scrollarea_end, - scrollbar.up_arrow_loc, scrollbar.down_arrow_loc)); + scrollbar.height = height - (2 * scrollbar_get_shadow()); + scrollbar.win_width = scrollbar.width + (2 * scrollbar_get_shadow()); + scrollbar.win_height = height; + D_X11((" -> New scrollbar width/height == %hux%hu, win_width/height == %hux%hu\n", scrollbar.width, scrollbar.height, + scrollbar.win_width, scrollbar.win_height)); + D_X11((" -> New scroll area start/end == %hu - %hu, up_arrow_loc == %hu, down_arrow_loc == %hu\n", scrollbar.scrollarea_start, + scrollbar.scrollarea_end, scrollbar.up_arrow_loc, scrollbar.down_arrow_loc)); } void scrollbar_resize(int width, int height) { - if (!scrollbar_is_visible()) { - return; - } + if (!scrollbar_is_visible()) { + return; + } - D_SCROLLBAR(("scrollbar_resize(%d, %d)\n", width, height)); - scrollbar_calc_size(width, height); - D_SCROLLBAR((" -> XMoveResizeWindow(Xdisplay, 0x%08x, %d, y, %d, %d)\n", scrollbar.win, ((Options & Opt_scrollbar_right) ? (width - scrollbar_trough_width()) : (0)), - scrollbar_trough_width(), scrollbar.win_height)); - XMoveResizeWindow(Xdisplay, scrollbar.win, ((Options & Opt_scrollbar_right) ? (width - scrollbar_trough_width()) : (0)), bbar_calc_docked_height(BBAR_DOCKED_TOP), - scrollbar_trough_width(), scrollbar.win_height); - scrollbar_draw_trough(IMAGE_STATE_CURRENT, MODE_MASK); - scrollbar_reposition_and_draw(MODE_MASK); - scrollbar.init = 0; + D_SCROLLBAR(("scrollbar_resize(%d, %d)\n", width, height)); + scrollbar_calc_size(width, height); + D_SCROLLBAR((" -> XMoveResizeWindow(Xdisplay, 0x%08x, %d, y, %d, %d)\n", scrollbar.win, + ((Options & Opt_scrollbar_right) ? (width - scrollbar_trough_width()) : (0)), scrollbar_trough_width(), + scrollbar.win_height)); + XMoveResizeWindow(Xdisplay, scrollbar.win, ((Options & Opt_scrollbar_right) ? (width - scrollbar_trough_width()) : (0)), + bbar_calc_docked_height(BBAR_DOCKED_TOP), scrollbar_trough_width(), scrollbar.win_height); + scrollbar_draw_trough(IMAGE_STATE_CURRENT, MODE_MASK); + scrollbar_reposition_and_draw(MODE_MASK); + scrollbar.init = 0; } void scrollbar_change_type(unsigned int type) { - D_SCROLLBAR(("scrollbar_change_type(0x%02x): Current scrollbar type is 0x%02x\n", type, scrollbar_get_type())); - if (scrollbar_get_type() == type) { - /* Nothing to do. */ - return; - } + D_SCROLLBAR(("scrollbar_change_type(0x%02x): Current scrollbar type is 0x%02x\n", type, scrollbar_get_type())); + if (scrollbar_get_type() == type) { + /* Nothing to do. */ + return; + } #ifdef XTERM_SCROLLBAR - if (scrollbar.type == SCROLLBAR_XTERM) { - scrollbar_map_arrows(); - } + if (scrollbar.type == SCROLLBAR_XTERM) { + scrollbar_map_arrows(); + } #endif #ifdef MOTIF_SCROLLBAR - if (scrollbar.type == SCROLLBAR_MOTIF) { - /* arrows are as high as wide - leave 1 pixel gap */ - scrollbar.scrollarea_start -= scrollbar_arrow_height() + scrollbar_get_shadow() + 1; - scrollbar.scrollarea_end += scrollbar_arrow_height() + scrollbar_get_shadow() + 1; - } + if (scrollbar.type == SCROLLBAR_MOTIF) { + /* arrows are as high as wide - leave 1 pixel gap */ + scrollbar.scrollarea_start -= scrollbar_arrow_height() + scrollbar_get_shadow() + 1; + scrollbar.scrollarea_end += scrollbar_arrow_height() + scrollbar_get_shadow() + 1; + } #endif #ifdef NEXT_SCROLLBAR - if (scrollbar.type == SCROLLBAR_NEXT) { - scrollbar.scrollarea_start = 0; - scrollbar.scrollarea_end += (scrollbar.width * 2 + (scrollbar_get_shadow() ? scrollbar_get_shadow() : 1) + 2); - } + if (scrollbar.type == SCROLLBAR_NEXT) { + scrollbar.scrollarea_start = 0; + scrollbar.scrollarea_end += (scrollbar.width * 2 + (scrollbar_get_shadow()? scrollbar_get_shadow() : 1) + 2); + } #endif - scrollbar_reset(); - scrollbar.type = type; + scrollbar_reset(); + scrollbar.type = type; #ifdef XTERM_SCROLLBAR - if (scrollbar.type == SCROLLBAR_XTERM) { - scrollbar_unmap_arrows(); - } + if (scrollbar.type == SCROLLBAR_XTERM) { + scrollbar_unmap_arrows(); + } #endif #ifdef MOTIF_SCROLLBAR - if (type == SCROLLBAR_MOTIF) { - scrollbar.scrollarea_start += scrollbar_arrow_height() + scrollbar_get_shadow() + 1; - scrollbar.scrollarea_end -= scrollbar_arrow_height() + scrollbar_get_shadow() + 1; - scrollbar.up_arrow_loc = scrollbar_get_shadow(); - scrollbar.down_arrow_loc = scrollbar.scrollarea_end + 1; - } + if (type == SCROLLBAR_MOTIF) { + scrollbar.scrollarea_start += scrollbar_arrow_height() + scrollbar_get_shadow() + 1; + scrollbar.scrollarea_end -= scrollbar_arrow_height() + scrollbar_get_shadow() + 1; + scrollbar.up_arrow_loc = scrollbar_get_shadow(); + scrollbar.down_arrow_loc = scrollbar.scrollarea_end + 1; + } #endif #ifdef NEXT_SCROLLBAR - if (type == SCROLLBAR_NEXT) { - scrollbar.scrollarea_start = scrollbar_get_shadow(); - scrollbar.scrollarea_end -= (scrollbar.width * 2 + (scrollbar_get_shadow() ? scrollbar_get_shadow() : 1) + 2); - scrollbar.up_arrow_loc = scrollbar.scrollarea_end + 1; - scrollbar.down_arrow_loc = scrollbar.scrollarea_end + scrollbar.width + 2; - } + if (type == SCROLLBAR_NEXT) { + scrollbar.scrollarea_start = scrollbar_get_shadow(); + scrollbar.scrollarea_end -= (scrollbar.width * 2 + (scrollbar_get_shadow()? scrollbar_get_shadow() : 1) + 2); + scrollbar.up_arrow_loc = scrollbar.scrollarea_end + 1; + scrollbar.down_arrow_loc = scrollbar.scrollarea_end + scrollbar.width + 2; + } #endif - scrollbar_reposition_and_draw(MODE_MASK); + scrollbar_reposition_and_draw(MODE_MASK); } void scrollbar_change_width(unsigned short width) { - D_SCROLLBAR(("scrollbar_change_width(%hu): Current width is %hu\n", width, scrollbar_get_width())); - if (width == 0) { - width = SB_WIDTH; - } - if (width == scrollbar.width) { - /* Nothing to do, so return. */ - return; - } - scrollbar_reset(); - scrollbar.width = width; - parent_resize(); + D_SCROLLBAR(("scrollbar_change_width(%hu): Current width is %hu\n", width, scrollbar_get_width())); + if (width == 0) { + width = SB_WIDTH; + } + if (width == scrollbar.width) { + /* Nothing to do, so return. */ + return; + } + scrollbar_reset(); + scrollbar.width = width; + parent_resize(); } void -scrollbar_drawing_init(void) { +scrollbar_drawing_init(void) +{ - XGCValues gcvalue; + XGCValues gcvalue; - D_SCROLLBAR(("Called.\n")); + D_SCROLLBAR(("Called.\n")); #ifdef XTERM_SCROLLBAR - gcvalue.stipple = XCreateBitmapFromData(Xdisplay, scrollbar.win, (char *) xterm_sb_bits, 12, 2); - if (!gcvalue.stipple) { - print_error("Unable to create xterm scrollbar bitmap.\n\n"); - if (scrollbar_get_type() == SCROLLBAR_XTERM) { - scrollbar_set_type(SCROLLBAR_MOTIF); + gcvalue.stipple = XCreateBitmapFromData(Xdisplay, scrollbar.win, (char *) xterm_sb_bits, 12, 2); + if (!gcvalue.stipple) { + print_error("Unable to create xterm scrollbar bitmap.\n\n"); + if (scrollbar_get_type() == SCROLLBAR_XTERM) { + scrollbar_set_type(SCROLLBAR_MOTIF); + } + } else { + gcvalue.fill_style = FillOpaqueStippled; + gcvalue.foreground = PixColors[fgColor]; + gcvalue.background = PixColors[bgColor]; + gc_stipple = LIBAST_X_CREATE_GC(GCForeground | GCBackground | GCFillStyle | GCStipple, &gcvalue); + gcvalue.foreground = PixColors[borderColor]; + gc_border = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); } - } else { - gcvalue.fill_style = FillOpaqueStippled; - gcvalue.foreground = PixColors[fgColor]; - gcvalue.background = PixColors[bgColor]; - gc_stipple = LIBAST_X_CREATE_GC(GCForeground | GCBackground | GCFillStyle | GCStipple, &gcvalue); - gcvalue.foreground = PixColors[borderColor]; - gc_border = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); - } #endif /* XTERM_SCROLLBAR */ #if defined(MOTIF_SCROLLBAR) || defined(NEXT_SCROLLBAR) - gcvalue.foreground = images[image_sb].norm->bg; - gc_scrollbar = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); - gcvalue.foreground = PixColors[topShadowColor]; - gc_top = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); - gcvalue.foreground = PixColors[bottomShadowColor]; - gc_bottom = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); + gcvalue.foreground = images[image_sb].norm->bg; + gc_scrollbar = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); + gcvalue.foreground = PixColors[topShadowColor]; + gc_top = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); + gcvalue.foreground = PixColors[bottomShadowColor]; + gc_bottom = LIBAST_X_CREATE_GC(GCForeground, &gcvalue); #endif /* MOTIF_SCROLLBAR || NEXT_SCROLLBAR */ } unsigned char -scrollbar_set_focus(short has_focus) { +scrollbar_set_focus(short has_focus) +{ - static short focus = -1; - XGCValues gcvalue; + static short focus = -1; + XGCValues gcvalue; - D_SCROLLBAR(("scrollbar_set_focus(%hd): focus == %hd\n", has_focus, focus)); - if (focus != has_focus) { - focus = has_focus; - gcvalue.foreground = (focus ? (images[image_sb].norm->bg) : (images[image_sb].disabled->bg)); - XChangeGC(Xdisplay, gc_scrollbar, GCForeground, &gcvalue); - gcvalue.foreground = PixColors[focus ? topShadowColor : unfocusedTopShadowColor]; - XChangeGC(Xdisplay, gc_top, GCForeground, &gcvalue); - gcvalue.foreground = PixColors[focus ? bottomShadowColor : unfocusedBottomShadowColor]; - XChangeGC(Xdisplay, gc_bottom, GCForeground, &gcvalue); - return (1); - } - return (0); + D_SCROLLBAR(("scrollbar_set_focus(%hd): focus == %hd\n", has_focus, focus)); + if (focus != has_focus) { + focus = has_focus; + gcvalue.foreground = (focus ? (images[image_sb].norm->bg) : (images[image_sb].disabled->bg)); + XChangeGC(Xdisplay, gc_scrollbar, GCForeground, &gcvalue); + gcvalue.foreground = PixColors[focus ? topShadowColor : unfocusedTopShadowColor]; + XChangeGC(Xdisplay, gc_top, GCForeground, &gcvalue); + gcvalue.foreground = PixColors[focus ? bottomShadowColor : unfocusedBottomShadowColor]; + XChangeGC(Xdisplay, gc_bottom, GCForeground, &gcvalue); + return (1); + } + return (0); } unsigned char -scrollbar_anchor_update_position(short mouseoffset) { +scrollbar_anchor_update_position(short mouseoffset) +{ - int top = (TermWin.nscrolled - TermWin.view_start); - int bot = top + (TermWin.nrow - 1); - int len = MAX((TermWin.nscrolled + (TermWin.nrow - 1)), 1); + int top = (TermWin.nscrolled - TermWin.view_start); + int bot = top + (TermWin.nrow - 1); + int len = MAX((TermWin.nscrolled + (TermWin.nrow - 1)), 1); - D_SCROLLBAR(("scrollbar_anchor_update_position(%hd): top == %d, bot == %d, len == %d\n", mouseoffset, top, bot, len)); - scrollbar.anchor_top = (scrollbar.scrollarea_start + (top * scrollbar_scrollarea_height()) / len); - scrollbar.anchor_bottom = (scrollbar.scrollarea_start + (bot * scrollbar_scrollarea_height()) / len); + D_SCROLLBAR(("scrollbar_anchor_update_position(%hd): top == %d, bot == %d, len == %d\n", mouseoffset, top, bot, len)); + scrollbar.anchor_top = (scrollbar.scrollarea_start + (top * scrollbar_scrollarea_height()) / len); + scrollbar.anchor_bottom = (scrollbar.scrollarea_start + (bot * scrollbar_scrollarea_height()) / len); - if (rs_min_anchor_size && scrollbar.type != SCROLLBAR_XTERM) { - if ((scrollbar_scrollarea_height() > rs_min_anchor_size) && (scrollbar_anchor_height() < rs_min_anchor_size)) { + if (rs_min_anchor_size && scrollbar.type != SCROLLBAR_XTERM) { + if ((scrollbar_scrollarea_height() > rs_min_anchor_size) && (scrollbar_anchor_height() < rs_min_anchor_size)) { - int grab_point = scrollbar.anchor_top + mouseoffset; + int grab_point = scrollbar.anchor_top + mouseoffset; - if (grab_point - mouseoffset < scrollbar.scrollarea_start) { - scrollbar.anchor_top = scrollbar.scrollarea_start; - scrollbar.anchor_bottom = rs_min_anchor_size + scrollbar.scrollarea_start; - } else if (scrollbar.anchor_top + rs_min_anchor_size > scrollbar.scrollarea_end) { - scrollbar.anchor_top = scrollbar.scrollarea_end - rs_min_anchor_size; - scrollbar.anchor_bottom = scrollbar.scrollarea_end; - } else { - scrollbar.anchor_top = grab_point - mouseoffset; - scrollbar.anchor_bottom = scrollbar.anchor_top + rs_min_anchor_size; - } - if (scrollbar.anchor_bottom == scrollbar.scrollarea_end) { - scr_move_to(scrollbar.scrollarea_end, scrollbar_scrollarea_height()); - scr_refresh(DEFAULT_REFRESH); - } + if (grab_point - mouseoffset < scrollbar.scrollarea_start) { + scrollbar.anchor_top = scrollbar.scrollarea_start; + scrollbar.anchor_bottom = rs_min_anchor_size + scrollbar.scrollarea_start; + } else if (scrollbar.anchor_top + rs_min_anchor_size > scrollbar.scrollarea_end) { + scrollbar.anchor_top = scrollbar.scrollarea_end - rs_min_anchor_size; + scrollbar.anchor_bottom = scrollbar.scrollarea_end; + } else { + scrollbar.anchor_top = grab_point - mouseoffset; + scrollbar.anchor_bottom = scrollbar.anchor_top + rs_min_anchor_size; + } + if (scrollbar.anchor_bottom == scrollbar.scrollarea_end) { + scr_move_to(scrollbar.scrollarea_end, scrollbar_scrollarea_height()); + scr_refresh(DEFAULT_REFRESH); + } + } + } + if ((scrollbar.anchor_top == last_top) && (scrollbar.anchor_bottom == last_bot) && (scrollbar.init)) { + return 0; + } + if (scrollbar_move_anchor()) { + scrollbar_draw_anchor(IMAGE_STATE_CURRENT, MODE_MASK); } - } - if ((scrollbar.anchor_top == last_top) && (scrollbar.anchor_bottom == last_bot) && (scrollbar.init)) { - return 0; - } - if (scrollbar_move_anchor()) { - scrollbar_draw_anchor(IMAGE_STATE_CURRENT, MODE_MASK); - } - last_top = scrollbar.anchor_top; - last_bot = scrollbar.anchor_bottom; - return 1; + last_top = scrollbar.anchor_top; + last_bot = scrollbar.anchor_bottom; + return 1; } void scrollbar_draw(unsigned char image_state, unsigned char force_modes) { - D_SCROLLBAR(("scrollbar_draw(%d, 0x%02x)\n", image_state, force_modes)); - scrollbar_draw_trough(image_state, force_modes); - scrollbar_draw_anchor(image_state, force_modes); - scrollbar_draw_uparrow(image_state, force_modes); - scrollbar_draw_downarrow(image_state, force_modes); - scrollbar.init = 1; + D_SCROLLBAR(("scrollbar_draw(%d, 0x%02x)\n", image_state, force_modes)); + scrollbar_draw_trough(image_state, force_modes); + scrollbar_draw_anchor(image_state, force_modes); + scrollbar_draw_uparrow(image_state, force_modes); + scrollbar_draw_downarrow(image_state, force_modes); + scrollbar.init = 1; } void scrollbar_reposition_and_draw(unsigned char force_modes) { - D_SCROLLBAR(("scrollbar_reposition_and_draw(0x%02x)\n", force_modes)); - if (scrollbar_move_uparrow()) { - scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, force_modes); - } - if (scrollbar_move_downarrow()) { - scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, force_modes); - } - if (!scrollbar_anchor_update_position(1)) { - scrollbar_draw_anchor(IMAGE_STATE_CURRENT, force_modes); - } - scrollbar.init = 1; + D_SCROLLBAR(("scrollbar_reposition_and_draw(0x%02x)\n", force_modes)); + if (scrollbar_move_uparrow()) { + scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, force_modes); + } + if (scrollbar_move_downarrow()) { + scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, force_modes); + } + if (!scrollbar_anchor_update_position(1)) { + scrollbar_draw_anchor(IMAGE_STATE_CURRENT, force_modes); + } + scrollbar.init = 1; } void scrollbar_reposition_and_always_draw(void) { - D_SCROLLBAR(("scrollbar_reposition_and_always_draw()\n")); - scrollbar_draw_trough(IMAGE_STATE_CURRENT, MODE_MASK); - scrollbar_move_uparrow(); - scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, MODE_MASK); - scrollbar_move_downarrow(); - scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, MODE_MASK); - scrollbar_anchor_update_position(1); - scrollbar_draw_anchor(IMAGE_STATE_CURRENT, MODE_MASK); - scrollbar.init = 1; + D_SCROLLBAR(("scrollbar_reposition_and_always_draw()\n")); + scrollbar_draw_trough(IMAGE_STATE_CURRENT, MODE_MASK); + scrollbar_move_uparrow(); + scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, MODE_MASK); + scrollbar_move_downarrow(); + scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, MODE_MASK); + scrollbar_anchor_update_position(1); + scrollbar_draw_anchor(IMAGE_STATE_CURRENT, MODE_MASK); + scrollbar.init = 1; } unsigned char scrollbar_show(short mouseoffset) { - unsigned char force_update = 0; + unsigned char force_update = 0; - if (!scrollbar_is_visible()) { - return 0; - } + if (!scrollbar_is_visible()) { + return 0; + } - D_SCROLLBAR(("scrollbar_show(%hd)\n", mouseoffset)); + D_SCROLLBAR(("scrollbar_show(%hd)\n", mouseoffset)); - force_update = scrollbar_set_focus(TermWin.focus); - if (!(scrollbar.init)) { - force_update++; - } - if (mouseoffset) { - force_update += scrollbar_anchor_update_position(mouseoffset); - } - scrollbar_draw_trough(IMAGE_STATE_CURRENT, (force_update) ? (MODE_TRANS | MODE_VIEWPORT) : (MODE_MASK)); - scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, (force_update) ? (MODE_TRANS | MODE_VIEWPORT) : (MODE_MASK)); - scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, (force_update) ? (MODE_TRANS | MODE_VIEWPORT) : (MODE_MASK)); - scrollbar.init = 1; - return 1; + force_update = scrollbar_set_focus(TermWin.focus); + if (!(scrollbar.init)) { + force_update++; + } + if (mouseoffset) { + force_update += scrollbar_anchor_update_position(mouseoffset); + } + scrollbar_draw_trough(IMAGE_STATE_CURRENT, (force_update) ? (MODE_TRANS | MODE_VIEWPORT) : (MODE_MASK)); + scrollbar_draw_uparrow(IMAGE_STATE_CURRENT, (force_update) ? (MODE_TRANS | MODE_VIEWPORT) : (MODE_MASK)); + scrollbar_draw_downarrow(IMAGE_STATE_CURRENT, (force_update) ? (MODE_TRANS | MODE_VIEWPORT) : (MODE_MASK)); + scrollbar.init = 1; + return 1; } diff --git a/src/startup.c b/src/startup.c index ef43fe7..758e0b1 100644 --- a/src/startup.c +++ b/src/startup.c @@ -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); } diff --git a/src/startup.h b/src/startup.h index 5b23511..2bfe529 100644 --- a/src/startup.h +++ b/src/startup.h @@ -31,6 +31,9 @@ #include #include #include "misc.h" +#ifdef ESCREEN +#include "scream.h" +#endif /************ Macros and Definitions ************/ #ifndef EXIT_SUCCESS /* missing from */ @@ -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 ************/ diff --git a/src/system.c b/src/system.c index 0638f36..e9da852 100644 --- a/src/system.c +++ b/src/system.c @@ -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); } diff --git a/src/term.c b/src/term.c index 80a9640..80204f6 100644 --- a/src/term.c +++ b/src/term.c @@ -50,40 +50,39 @@ static const char cvs_ident[] = "$Id$"; #include "windows.h" #ifdef META8_OPTION -unsigned char meta_char = 033; /* Alt-key prefix */ +unsigned char meta_char = 033; /* Alt-key prefix */ #endif unsigned long PrivateModes = PrivMode_Default; unsigned long SavedModes = PrivMode_Default; -char *def_colorName[] = -{ - "rgb:aa/aa/aa", "rgb:0/0/0", /* fg/bg */ - "rgb:0/0/0", /* 0: black (#000000) */ +char *def_colorName[] = { + "rgb:aa/aa/aa", "rgb:0/0/0", /* fg/bg */ + "rgb:0/0/0", /* 0: black (#000000) */ #ifndef NO_BRIGHTCOLOR /* low-intensity colors */ - "rgb:cc/00/00", /* 1: red */ - "rgb:00/cc/00", /* 2: green */ - "rgb:cc/cc/00", /* 3: yellow */ - "rgb:00/00/cc", /* 4: blue */ - "rgb:cc/00/cc", /* 5: magenta */ - "rgb:00/cc/cc", /* 6: cyan */ - "rgb:aa/aa/aa", /* 7: white */ + "rgb:cc/00/00", /* 1: red */ + "rgb:00/cc/00", /* 2: green */ + "rgb:cc/cc/00", /* 3: yellow */ + "rgb:00/00/cc", /* 4: blue */ + "rgb:cc/00/cc", /* 5: magenta */ + "rgb:00/cc/cc", /* 6: cyan */ + "rgb:aa/aa/aa", /* 7: white */ /* high-intensity colors */ - "rgb:33/33/33", /* 8: bright black */ -#endif /* NO_BRIGHTCOLOR */ - "rgb:ff/00/00", /* 1/9: bright red */ - "rgb:00/ff/00", /* 2/10: bright green */ - "rgb:ff/ff/00", /* 3/11: bright yellow */ - "rgb:00/00/ff", /* 4/12: bright blue */ - "rgb:ff/00/ff", /* 5/13: bright magenta */ - "rgb:00/ff/ff", /* 6/14: bright cyan */ - "rgb:ff/ff/ff", /* 7/15: bright white */ + "rgb:33/33/33", /* 8: bright black */ +#endif /* NO_BRIGHTCOLOR */ + "rgb:ff/00/00", /* 1/9: bright red */ + "rgb:00/ff/00", /* 2/10: bright green */ + "rgb:ff/ff/00", /* 3/11: bright yellow */ + "rgb:00/00/ff", /* 4/12: bright blue */ + "rgb:ff/00/ff", /* 5/13: bright magenta */ + "rgb:00/ff/ff", /* 6/14: bright cyan */ + "rgb:ff/ff/ff", /* 7/15: bright white */ #ifndef NO_CURSORCOLOR - NULL, NULL, /* cursorColor, cursorColor2 */ -#endif /* NO_CURSORCOLOR */ - NULL, NULL /* pointerColor, borderColor */ + NULL, NULL, /* cursorColor, cursorColor2 */ +#endif /* NO_CURSORCOLOR */ + NULL, NULL /* pointerColor, borderColor */ #ifndef NO_BOLDUNDERLINE - ,NULL, NULL /* colorBD, colorUL */ -#endif /* NO_BOLDUNDERLINE */ + , NULL, NULL /* colorBD, colorUL */ +#endif /* NO_BOLDUNDERLINE */ }; char *rs_color[NRS_COLORS]; Pixel PixColors[NRS_COLORS + NSHADOWCOLORS]; @@ -101,78 +100,78 @@ void get_modifiers(void) { - unsigned short i; - XModifierKeymap *modmap; - KeyCode *kc; + unsigned short i; + XModifierKeymap *modmap; + KeyCode *kc; - modmap = XGetModifierMapping(Xdisplay); - kc = modmap->modifiermap; + modmap = XGetModifierMapping(Xdisplay); + kc = modmap->modifiermap; - /* For each of the 5 modifier masks... */ - for (i = Mod5MapIndex; i >= Mod1MapIndex; i--) { - unsigned short j; - register unsigned short k, l; + /* For each of the 5 modifier masks... */ + for (i = Mod5MapIndex; i >= Mod1MapIndex; i--) { + unsigned short j; + register unsigned short k, l; - k = i * modmap->max_keypermod; - l = i - Mod1MapIndex; + k = i * modmap->max_keypermod; + l = i - Mod1MapIndex; - /* Find each key bound to it... */ - for (j = 0; j < modmap->max_keypermod; j++, k++) { - unsigned char match = 0; + /* Find each key bound to it... */ + for (j = 0; j < modmap->max_keypermod; j++, k++) { + unsigned char match = 0; - if (kc[k] == 0) { - break; - } - /* Check to see if it's one that we care about. */ - switch (XKeycodeToKeysym(Xdisplay, kc[k], 0)) { - case XK_Meta_L: - case XK_Meta_R: - D_X11(("Found Meta key as mod %d\n", l + 1)); - match = MetaMask = modmasks[l]; - break; - case XK_Alt_L: - case XK_Alt_R: - D_X11(("Found Alt key as mod %d\n", l + 1)); - match = AltMask = modmasks[l]; - break; - case XK_Num_Lock: - D_X11(("Found NumLock key as mod %d\n", l + 1)); - match = NumLockMask = modmasks[l]; - break; - default: - break; - } - if (match) { - break; - } + if (kc[k] == 0) { + break; + } + /* Check to see if it's one that we care about. */ + switch (XKeycodeToKeysym(Xdisplay, kc[k], 0)) { + case XK_Meta_L: + case XK_Meta_R: + D_X11(("Found Meta key as mod %d\n", l + 1)); + match = MetaMask = modmasks[l]; + break; + case XK_Alt_L: + case XK_Alt_R: + D_X11(("Found Alt key as mod %d\n", l + 1)); + match = AltMask = modmasks[l]; + break; + case XK_Num_Lock: + D_X11(("Found NumLock key as mod %d\n", l + 1)); + match = NumLockMask = modmasks[l]; + break; + default: + break; + } + if (match) { + break; + } + } } - } - XFreeModifiermap(modmap); - /* Fallbacks. */ - if (MetaMask == 0) { - if (AltMask != 0) { - D_X11(("Defaulted Meta key to match Alt mask\n")); - MetaMask = AltMask; - } else { - D_X11(("Defaulted Meta key to mod 1\n")); - MetaMask = Mod1Mask; + XFreeModifiermap(modmap); + /* Fallbacks. */ + if (MetaMask == 0) { + if (AltMask != 0) { + D_X11(("Defaulted Meta key to match Alt mask\n")); + MetaMask = AltMask; + } else { + D_X11(("Defaulted Meta key to mod 1\n")); + MetaMask = Mod1Mask; + } + } + if (AltMask == 0) { + D_X11(("Defaulted Alt key to match Meta mask\n")); + AltMask = MetaMask; /* MetaMask will always be defined at this point. */ } - } - if (AltMask == 0) { - D_X11(("Defaulted Alt key to match Meta mask\n")); - AltMask = MetaMask; /* MetaMask will always be defined at this point. */ - } - /* See if the user wants to override any of those */ - if (rs_meta_mod) { - MetaMask = modmasks[rs_meta_mod - 1]; - } - if (rs_alt_mod) { - AltMask = modmasks[rs_alt_mod - 1]; - } - if (rs_numlock_mod) { - NumLockMask = modmasks[rs_numlock_mod - 1]; - } + /* See if the user wants to override any of those */ + if (rs_meta_mod) { + MetaMask = modmasks[rs_meta_mod - 1]; + } + if (rs_alt_mod) { + AltMask = modmasks[rs_alt_mod - 1]; + } + if (rs_numlock_mod) { + NumLockMask = modmasks[rs_numlock_mod - 1]; + } } /* To handle buffer overflows properly, we must malloc a buffer. Free it when done. */ @@ -193,611 +192,610 @@ void lookup_key(XEvent * ev) { - static int numlock_state = 0; - int ctrl, meta, shft, len; - KeySym keysym; + static int numlock_state = 0; + int ctrl, meta, shft, len; + KeySym keysym; #ifdef USE_XIM - int valid_keysym = 0; - static unsigned char short_buf[256]; - unsigned char *kbuf = short_buf; - int kbuf_alloced = 0; + int valid_keysym = 0; + static unsigned char short_buf[256]; + unsigned char *kbuf = short_buf; + int kbuf_alloced = 0; #else - static unsigned char kbuf[KBUFSZ]; + static unsigned char kbuf[KBUFSZ]; #endif #ifdef GREEK_SUPPORT - static short greek_mode = 0; + static short greek_mode = 0; #endif - /* Quick boolean variables tell us which modifier keys were pressed. */ - shft = (ev->xkey.state & ShiftMask); - ctrl = (ev->xkey.state & ControlMask); - meta = (ev->xkey.state & MetaMask); + /* Quick boolean variables tell us which modifier keys were pressed. */ + shft = (ev->xkey.state & ShiftMask); + ctrl = (ev->xkey.state & ControlMask); + meta = (ev->xkey.state & MetaMask); - /* The num lock key toggles application keypad - mode. Num lock on, app. keypad mode off. */ - if (numlock_state || (ev->xkey.state & NumLockMask)) { - numlock_state = (ev->xkey.state & NumLockMask); - PrivMode((!numlock_state), PrivMode_aplKP); - } -#ifdef USE_XIM - if (xim_input_context != NULL) { - Status status_return; - - kbuf[0] = '\0'; - /* Lookup the string equivalent in terms of the XIM input context. */ - len = XmbLookupString(xim_input_context, &ev->xkey, (char *) kbuf, sizeof(short_buf), &keysym, &status_return); - D_TTY(("XmbLookupString() gave us len %d, keysym \"%s\" (0x%04x), and buffer \"%s\" based on the XIM input context %010p\n", - len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len), xim_input_context)); - /* Whoops, it's too long. Allocate a new buffer and repeat the call. */ - if (status_return == XBufferOverflow) { - kbuf = (unsigned char *) MALLOC(len + 1); - kbuf_alloced = 1; - len = XmbLookupString(xim_input_context, &ev->xkey, (char *) kbuf, len, &keysym, &status_return); - D_TTY(("XmbLookupString() gave us len %d, keysym \"%s\" (0x%04x), and buffer \"%s\" based on the XIM input context %010p\n", - len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len), xim_input_context)); + /* The num lock key toggles application keypad + mode. Num lock on, app. keypad mode off. */ + if (numlock_state || (ev->xkey.state & NumLockMask)) { + numlock_state = (ev->xkey.state & NumLockMask); + PrivMode((!numlock_state), PrivMode_aplKP); } - valid_keysym = (status_return == XLookupKeySym) || (status_return == XLookupBoth); - } else { - /* No XIM input context. Do it the normal way. */ - len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(short_buf), &keysym, NULL); +#ifdef USE_XIM + if (xim_input_context != NULL) { + Status status_return; + + kbuf[0] = '\0'; + /* Lookup the string equivalent in terms of the XIM input context. */ + len = XmbLookupString(xim_input_context, &ev->xkey, (char *) kbuf, sizeof(short_buf), &keysym, &status_return); + D_TTY(("XmbLookupString() gave us len %d, keysym \"%s\" (0x%04x), and buffer \"%s\" based on the XIM input context %010p\n", + len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len), xim_input_context)); + /* Whoops, it's too long. Allocate a new buffer and repeat the call. */ + if (status_return == XBufferOverflow) { + kbuf = (unsigned char *) MALLOC(len + 1); + kbuf_alloced = 1; + len = XmbLookupString(xim_input_context, &ev->xkey, (char *) kbuf, len, &keysym, &status_return); + D_TTY(("XmbLookupString() gave us len %d, keysym \"%s\" (0x%04x), and buffer \"%s\" based on the XIM input context %010p\n", + len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len), xim_input_context)); + } + valid_keysym = (status_return == XLookupKeySym) || (status_return == XLookupBoth); + } else { + /* No XIM input context. Do it the normal way. */ + len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(short_buf), &keysym, NULL); + D_TTY(("XLookupString() gave us len %d, keysym \"%s\" (0x%04x), and buffer \"%s\"\n", + len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len))); + valid_keysym = 1; + } +#else /* USE_XIM */ + /* Translate the key event into its corresponding string according to X. This also gets us a keysym. */ + len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(kbuf), &keysym, NULL); D_TTY(("XLookupString() gave us len %d, keysym \"%s\" (0x%04x), and buffer \"%s\"\n", len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len))); - valid_keysym = 1; - } -#else /* USE_XIM */ - /* Translate the key event into its corresponding string according to X. This also gets us a keysym. */ - len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(kbuf), &keysym, NULL); - D_TTY(("XLookupString() gave us len %d, keysym \"%s\" (0x%04x), and buffer \"%s\"\n", - len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len))); - /* If there is no string and it's a Latin2-7 character, replace it with the Latin1 character instead. */ - if (!len && (keysym >= 0x0100) && (keysym < 0x0900)) { - len = 1; - kbuf[0] = (keysym & 0xff); - } + /* If there is no string and it's a Latin2-7 character, replace it with the Latin1 character instead. */ + if (!len && (keysym >= 0x0100) && (keysym < 0x0900)) { + len = 1; + kbuf[0] = (keysym & 0xff); + } #endif /* USE_XIM */ #ifdef USE_XIM - /* Don't do anything without a valid keysym. */ - if (valid_keysym) { + /* Don't do anything without a valid keysym. */ + if (valid_keysym) { #endif - /* Check for a corresponding action binding. If there is one, we're done with this event. */ - if (action_dispatch(ev, keysym)) { - LK_RET(); - } - if (len) { - /* Only home for keypresses with length. */ - if (Options & Opt_home_on_input) { - TermWin.view_start = 0; - } - } + /* Check for a corresponding action binding. If there is one, we're done with this event. */ + if (action_dispatch(ev, keysym)) { + LK_RET(); + } + if (len) { + /* Only home for keypresses with length. */ + if (Options & Opt_home_on_input) { + TermWin.view_start = 0; + } + } - /* This is a special mode that reports all extended keysyms (above 0xff00) to the application - as escape sequences. Very few applications use it, but it can be a handy thing to have. */ - if ((Options & Opt_report_as_keysyms) && (keysym >= 0xff00)) { - len = sprintf((char *) kbuf, "\033[k%X;%X~", (unsigned int) (ev->xkey.state & 0xff), (unsigned int) (keysym & 0xff)); - tt_write(kbuf, len); - LK_RET(); - } + /* This is a special mode that reports all extended keysyms (above 0xff00) to the application + as escape sequences. Very few applications use it, but it can be a handy thing to have. */ + if ((Options & Opt_report_as_keysyms) && (keysym >= 0xff00)) { + len = sprintf((char *) kbuf, "\033[k%X;%X~", (unsigned int) (ev->xkey.state & 0xff), (unsigned int) (keysym & 0xff)); + tt_write(kbuf, len); + LK_RET(); + } #ifdef HOTKEY - /* Ctrl-> and Ctrl-< should change font sizes. (Meta if HOTKEY has been changed to Meta.) */ - if (HOTKEY) { - if (keysym == ks_bigfont) { - change_font(0, BIGGER_FONT); - LK_RET(); - } else if (keysym == ks_smallfont) { - change_font(0, SMALLER_FONT); - LK_RET(); - } - } + /* Ctrl-> and Ctrl-< should change font sizes. (Meta if HOTKEY has been changed to Meta.) */ + if (HOTKEY) { + if (keysym == ks_bigfont) { + change_font(0, BIGGER_FONT); + LK_RET(); + } else if (keysym == ks_smallfont) { + change_font(0, SMALLER_FONT); + LK_RET(); + } + } #endif #if defined(HAVE_X11_SUNKEYSYM_H) && defined(HAVE_X11_XMU_ATOMS_H) - switch (keysym) { - case SunXK_Copy: - case SunXK_Cut: - selection_copy(XA_CLIPBOARD(Xdisplay)); - LK_RET(); - break; - case SunXK_Paste: - selection_paste(XA_CLIPBOARD(Xdisplay)); - LK_RET(); - break; - case SunXK_Front: - xterm_seq(XTerm_Takeover, ""); - LK_RET(); - break; - default: - break; - } + switch (keysym) { + case SunXK_Copy: + case SunXK_Cut: + selection_copy(XA_CLIPBOARD(Xdisplay)); + LK_RET(); + break; + case SunXK_Paste: + selection_paste(XA_CLIPBOARD(Xdisplay)); + LK_RET(); + break; + case SunXK_Front: + xterm_seq(XTerm_Takeover, ""); + LK_RET(); + break; + default: + break; + } #endif - if (shft) { - /* Shift + F1 - F10 generates F11 - F20 */ - if (keysym >= XK_F1 && keysym <= XK_F10) { - keysym += (XK_F11 - XK_F1); - shft = 0; - } else if (!ctrl && !meta && (PrivateModes & PrivMode_ShiftKeys)) { - switch (keysym) { - case XK_Prior: /* Shift-PgUp scrolls up a page */ - if (TermWin.saveLines) { - scr_page(UP, (TermWin.nrow - CONTEXT_LINES)); - LK_RET(); - } - break; + if (shft) { + /* Shift + F1 - F10 generates F11 - F20 */ + if (keysym >= XK_F1 && keysym <= XK_F10) { + keysym += (XK_F11 - XK_F1); + shft = 0; + } else if (!ctrl && !meta && (PrivateModes & PrivMode_ShiftKeys)) { + switch (keysym) { + case XK_Prior: /* Shift-PgUp scrolls up a page */ + if (TermWin.saveLines) { + scr_page(UP, (TermWin.nrow - CONTEXT_LINES)); + LK_RET(); + } + break; - case XK_Next: /* Shift-PgDn scrolls down a page */ - if (TermWin.saveLines) { - scr_page(DN, (TermWin.nrow - CONTEXT_LINES)); - LK_RET(); - } - break; + case XK_Next: /* Shift-PgDn scrolls down a page */ + if (TermWin.saveLines) { + scr_page(DN, (TermWin.nrow - CONTEXT_LINES)); + LK_RET(); + } + break; - case XK_Insert: /* Shift-Ins pastes the current selection. */ - selection_paste(XA_PRIMARY); - LK_RET(); - break; + case XK_Insert: /* Shift-Ins pastes the current selection. */ + selection_paste(XA_PRIMARY); + LK_RET(); + break; - case XK_KP_Add: /* Shift-Plus on the keypad increases the font size */ - change_font(0, BIGGER_FONT); - LK_RET(); - break; + case XK_KP_Add: /* Shift-Plus on the keypad increases the font size */ + change_font(0, BIGGER_FONT); + LK_RET(); + break; - case XK_KP_Subtract: /* Shift-Minus on the keypad decreases the font size */ - change_font(0, SMALLER_FONT); - LK_RET(); - break; - } - } - } + case XK_KP_Subtract: /* Shift-Minus on the keypad decreases the font size */ + change_font(0, SMALLER_FONT); + LK_RET(); + break; + } + } + } #ifdef UNSHIFTED_SCROLLKEYS - /* Allow PgUp/PgDn by themselves to scroll. Not recommended. */ - else if (!ctrl && !meta) { - switch (keysym) { - case XK_Prior: - if (TermWin.saveLines) { - scr_page(UP, TermWin.nrow - CONTEXT_LINES); - LK_RET(); - } - break; + /* Allow PgUp/PgDn by themselves to scroll. Not recommended. */ + else if (!ctrl && !meta) { + switch (keysym) { + case XK_Prior: + if (TermWin.saveLines) { + scr_page(UP, TermWin.nrow - CONTEXT_LINES); + LK_RET(); + } + break; - case XK_Next: - if (TermWin.saveLines) { - scr_page(DN, TermWin.nrow - CONTEXT_LINES); - LK_RET(); - } - break; - } - } + case XK_Next: + if (TermWin.saveLines) { + scr_page(DN, TermWin.nrow - CONTEXT_LINES); + LK_RET(); + } + break; + } + } #endif - switch (keysym) { - case XK_Print: /* Print the screen contents out to the print pipe */ + switch (keysym) { + case XK_Print: /* Print the screen contents out to the print pipe */ #if DEBUG >= DEBUG_SELECTION - if (DEBUG_LEVEL >= DEBUG_SELECTION) { - scr_dump_to_file("/tmp/Eterm_screen_dump.log"); - } else + if (DEBUG_LEVEL >= DEBUG_SELECTION) { + scr_dump_to_file("/tmp/Eterm_screen_dump.log"); + } else #endif #ifdef PRINTPIPE - scr_printscreen(ctrl | shft); + scr_printscreen(ctrl | shft); #endif - LK_RET(); - break; + LK_RET(); + break; - case XK_Mode_switch: + case XK_Mode_switch: #ifdef GREEK_SUPPORT - greek_mode = !greek_mode; - if (greek_mode) { - xterm_seq(XTerm_title, (greek_getmode() == GREEK_ELOT928 ? "[Greek: iso]" : "[Greek: ibm]")); - greek_reset(); - } else - xterm_seq(XTerm_title, APL_NAME "-" VERSION); - LK_RET(); + greek_mode = !greek_mode; + if (greek_mode) { + xterm_seq(XTerm_title, (greek_getmode() == GREEK_ELOT928 ? "[Greek: iso]" : "[Greek: ibm]")); + greek_reset(); + } else + xterm_seq(XTerm_title, APL_NAME "-" VERSION); + LK_RET(); #endif - break; - } + break; + } - /* At this point, all the keystrokes that have special meaning to us have been handled. - If we're in pause mode, this is a keystroke asking us to exit. Otherwise, return here. */ - if (paused) { - if (keysym && len) { - exit(0); - } - LK_RET(); - } + /* At this point, all the keystrokes that have special meaning to us have been handled. + If we're in pause mode, this is a keystroke asking us to exit. Otherwise, return here. */ + if (paused) { + if (keysym && len) { + exit(0); + } + LK_RET(); + } - /* Process extended keysyms. This is where the conversion to escape sequences happens. */ - if (keysym >= 0xff00 && keysym <= 0xffff) { + /* Process extended keysyms. This is where the conversion to escape sequences happens. */ + if (keysym >= 0xff00 && keysym <= 0xffff) { #ifdef KEYSYM_ATTRIBUTE - /* The "keysym" attribute in the config file gets handled here. */ - if (!(shft | ctrl) && KeySym_map[keysym - 0xff00] != NULL) { + /* The "keysym" attribute in the config file gets handled here. */ + if (!(shft | ctrl) && KeySym_map[keysym - 0xff00] != NULL) { - const unsigned char *tmpbuf; - unsigned int len; + const unsigned char *tmpbuf; + unsigned int len; - tmpbuf = (KeySym_map[keysym - 0xff00]); - len = *tmpbuf++; + tmpbuf = (KeySym_map[keysym - 0xff00]); + len = *tmpbuf++; - /* escape prefix */ - if (meta + /* escape prefix */ + if (meta # ifdef META8_OPTION - && (meta_char == 033) + && (meta_char == 033) # endif - ) { - const unsigned char ch = '\033'; + ) { + const unsigned char ch = '\033'; - tt_write(&ch, 1); - } - tt_write(tmpbuf, len); - LK_RET(); - } else + tt_write(&ch, 1); + } + tt_write(tmpbuf, len); + LK_RET(); + } else #endif - /* This is a big-ass switch statement that handles all the special keysyms */ - switch (keysym) { - case XK_BackSpace: - len = 1; + /* This is a big-ass switch statement that handles all the special keysyms */ + switch (keysym) { + case XK_BackSpace: + len = 1; #ifdef FORCE_BACKSPACE - kbuf[0] = (!(shft | ctrl) ? '\b' : '\177'); + kbuf[0] = (!(shft | ctrl) ? '\b' : '\177'); #elif defined(FORCE_DELETE) - kbuf[0] = ((shft | ctrl) ? '\b' : '\177'); + kbuf[0] = ((shft | ctrl) ? '\b' : '\177'); #else - kbuf[0] = (((PrivateModes & PrivMode_BackSpace) ? !(shft | ctrl) : (shft | ctrl)) ? '\b' : '\177'); + kbuf[0] = (((PrivateModes & PrivMode_BackSpace) ? !(shft | ctrl) : (shft | ctrl)) ? '\b' : '\177'); #endif #ifdef MULTI_CHARSET - if ((Options & Opt_mbyte_cursor) && scr_multi2()) { - memmove(kbuf + len, kbuf, len); - len *= 2; - } + if ((Options & Opt_mbyte_cursor) && scr_multi2()) { + memmove(kbuf + len, kbuf, len); + len *= 2; + } #endif /* MULTI_CHARSET */ - break; + break; - /* Tab key is normal unless it's shift-tab. */ - case XK_Tab: - if (shft) { - len = 3; - strcpy(kbuf, "\033[Z"); - } - break; + /* Tab key is normal unless it's shift-tab. */ + case XK_Tab: + if (shft) { + len = 3; + strcpy(kbuf, "\033[Z"); + } + break; #ifdef XK_KP_Home - case XK_KP_Home: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033Ow"); - break; - } - /* -> else FALL THROUGH */ + case XK_KP_Home: + /* allow shift to override */ + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033Ow"); + break; + } + /* -> else FALL THROUGH */ #endif - case XK_Home: - len = strlen(strcpy(kbuf, KS_HOME)); - break; + case XK_Home: + len = strlen(strcpy(kbuf, KS_HOME)); + break; #ifdef XK_KP_Left - case XK_KP_Left: /* \033Ot or standard cursor key */ - case XK_KP_Up: /* \033Ox or standard cursor key */ - case XK_KP_Right: /* \033Ov or standard cursor key */ - case XK_KP_Down: /* \033Or or standard cursor key */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033OZ"); /* The Z is replaced by t, x, v, or r */ - kbuf[2] = ("txvr"[keysym - XK_KP_Left]); - break; - } else { - keysym = XK_Left + (keysym - XK_KP_Left); - } - /* Continue on with the normal cursor keys... */ + case XK_KP_Left: /* \033Ot or standard cursor key */ + case XK_KP_Up: /* \033Ox or standard cursor key */ + case XK_KP_Right: /* \033Ov or standard cursor key */ + case XK_KP_Down: /* \033Or or standard cursor key */ + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033OZ"); /* The Z is replaced by t, x, v, or r */ + kbuf[2] = ("txvr"[keysym - XK_KP_Left]); + break; + } else { + keysym = XK_Left + (keysym - XK_KP_Left); + } + /* Continue on with the normal cursor keys... */ #endif - case XK_Left: /* "\033[D" */ - case XK_Up: /* "\033[A" */ - case XK_Right: /* "\033[C" */ - case XK_Down: /* "\033[B" */ - len = 3; - strcpy(kbuf, "\033[@"); - kbuf[2] = ("DACB"[keysym - XK_Left]); - if (PrivateModes & PrivMode_aplCUR) { - kbuf[1] = 'O'; - } else if (shft) { /* do Shift first */ - kbuf[2] = ("dacb"[keysym - XK_Left]); - } else if (ctrl) { - kbuf[1] = 'O'; - kbuf[2] = ("dacb"[keysym - XK_Left]); - } + case XK_Left: /* "\033[D" */ + case XK_Up: /* "\033[A" */ + case XK_Right: /* "\033[C" */ + case XK_Down: /* "\033[B" */ + len = 3; + strcpy(kbuf, "\033[@"); + kbuf[2] = ("DACB"[keysym - XK_Left]); + if (PrivateModes & PrivMode_aplCUR) { + kbuf[1] = 'O'; + } else if (shft) { /* do Shift first */ + kbuf[2] = ("dacb"[keysym - XK_Left]); + } else if (ctrl) { + kbuf[1] = 'O'; + kbuf[2] = ("dacb"[keysym - XK_Left]); + } #ifdef MULTI_CHARSET - if ((Options & Opt_mbyte_cursor) - && ((keysym == XK_Left && scr_multi2()) - || (keysym == XK_Right && scr_multi1()))) { - memmove(kbuf + len, kbuf, len); - len *= 2; - } + if ((Options & Opt_mbyte_cursor) + && ((keysym == XK_Left && scr_multi2()) + || (keysym == XK_Right && scr_multi1()))) { + memmove(kbuf + len, kbuf, len); + len *= 2; + } #endif /* MULTI_CHARSET */ - break; + break; - /* Keypad and normal PgUp/PgDn */ + /* Keypad and normal PgUp/PgDn */ #ifndef UNSHIFTED_SCROLLKEYS # ifdef XK_KP_Prior - case XK_KP_Prior: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033Oy"); - break; - } - /* -> else FALL THROUGH */ -# endif /* XK_KP_Prior */ - case XK_Prior: - len = 4; - strcpy(kbuf, "\033[5~"); - break; + case XK_KP_Prior: + /* allow shift to override */ + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033Oy"); + break; + } + /* -> else FALL THROUGH */ +# endif /* XK_KP_Prior */ + case XK_Prior: + len = 4; + strcpy(kbuf, "\033[5~"); + break; # ifdef XK_KP_Next - case XK_KP_Next: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033Os"); - break; - } - /* -> else FALL THROUGH */ -# endif /* XK_KP_Next */ - case XK_Next: - len = 4; - strcpy(kbuf, "\033[6~"); - break; + case XK_KP_Next: + /* allow shift to override */ + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033Os"); + break; + } + /* -> else FALL THROUGH */ +# endif /* XK_KP_Next */ + case XK_Next: + len = 4; + strcpy(kbuf, "\033[6~"); + break; #endif /* UNSHIFTED_SCROLLKEYS */ - /* End key */ + /* End key */ #ifdef XK_KP_End - case XK_KP_End: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033Oq"); - break; - } - /* -> else FALL THROUGH */ + case XK_KP_End: + /* allow shift to override */ + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033Oq"); + break; + } + /* -> else FALL THROUGH */ #endif /* XK_KP_End */ - case XK_End: - len = strlen(strcpy(kbuf, KS_END)); - break; + case XK_End: + len = strlen(strcpy(kbuf, KS_END)); + break; - case XK_Select: - len = 4; - strcpy(kbuf, "\033[4~"); - break; + case XK_Select: + len = 4; + strcpy(kbuf, "\033[4~"); + break; #ifdef DXK_Remove - case DXK_Remove: + case DXK_Remove: #endif - case XK_Execute: - len = 4; - strcpy(kbuf, "\033[3~"); - break; + case XK_Execute: + len = 4; + strcpy(kbuf, "\033[3~"); + break; #ifdef XK_KP_Insert - case XK_KP_Insert: - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033Op"); - break; - } + case XK_KP_Insert: + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033Op"); + break; + } #endif - case XK_Insert: - len = 4; - strcpy(kbuf, "\033[2~"); - break; + case XK_Insert: + len = 4; + strcpy(kbuf, "\033[2~"); + break; #ifdef XK_KP_Delete - case XK_KP_Delete: - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033On"); - break; - } + case XK_KP_Delete: + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033On"); + break; + } #endif - case XK_Delete: + case XK_Delete: #ifdef KS_DELETE - len = strlen(strcpy(kbuf, KS_DELETE)); + len = strlen(strcpy(kbuf, KS_DELETE)); #ifdef MULTI_CHARSET - if ((Options & Opt_mbyte_cursor) && scr_multi1()) - { - memmove(kbuf + len, kbuf, len); - len *= 2; - } + if ((Options & Opt_mbyte_cursor) && scr_multi1()) { + memmove(kbuf + len, kbuf, len); + len *= 2; + } #endif /* MULTI_CHARSET */ #endif - break; + break; - case XK_Menu: - len = 5; - strcpy(kbuf, "\033[29~"); - break; - case XK_Find: - len = 4; - strcpy(kbuf, "\033[1~"); - break; - case XK_Help: - len = 5; - strcpy(kbuf, "\033[28~"); - break; + case XK_Menu: + len = 5; + strcpy(kbuf, "\033[29~"); + break; + case XK_Find: + len = 4; + strcpy(kbuf, "\033[1~"); + break; + case XK_Help: + len = 5; + strcpy(kbuf, "\033[28~"); + break; - case XK_KP_Enter: - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033OM"); - } else { - len = 1; - kbuf[0] = '\r'; - } - break; + case XK_KP_Enter: + /* allow shift to override */ + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033OM"); + } else { + len = 1; + kbuf[0] = '\r'; + } + break; #ifdef XK_KP_Begin - case XK_KP_Begin: - len = 3; - strcpy(kbuf, "\033Ou"); - break; + case XK_KP_Begin: + len = 3; + strcpy(kbuf, "\033Ou"); + break; #endif /* XK_KP_Begin */ - case XK_KP_F1: /* "\033OP" */ - case XK_KP_F2: /* "\033OQ" */ - case XK_KP_F3: /* "\033OR" */ - case XK_KP_F4: /* "\033OS" */ - len = 3; - strcpy(kbuf, "\033OP"); - kbuf[2] += (keysym - XK_KP_F1); - break; + case XK_KP_F1: /* "\033OP" */ + case XK_KP_F2: /* "\033OQ" */ + case XK_KP_F3: /* "\033OR" */ + case XK_KP_F4: /* "\033OS" */ + len = 3; + strcpy(kbuf, "\033OP"); + kbuf[2] += (keysym - XK_KP_F1); + break; - case XK_KP_Multiply: /* "\033Oj" : "*" */ - case XK_KP_Add: /* "\033Ok" : "+" */ - case XK_KP_Separator: /* "\033Ol" : "," */ - case XK_KP_Subtract: /* "\033Om" : "-" */ - case XK_KP_Decimal: /* "\033On" : "." */ - case XK_KP_Divide: /* "\033Oo" : "/" */ - case XK_KP_0: /* "\033Op" : "0" */ - case XK_KP_1: /* "\033Oq" : "1" */ - case XK_KP_2: /* "\033Or" : "2" */ - case XK_KP_3: /* "\033Os" : "3" */ - case XK_KP_4: /* "\033Ot" : "4" */ - case XK_KP_5: /* "\033Ou" : "5" */ - case XK_KP_6: /* "\033Ov" : "6" */ - case XK_KP_7: /* "\033Ow" : "7" */ - case XK_KP_8: /* "\033Ox" : "8" */ - case XK_KP_9: /* "\033Oy" : "9" */ - /* allow shift to override */ - if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { - len = 3; - strcpy(kbuf, "\033Oj"); - kbuf[2] += (keysym - XK_KP_Multiply); - } else { - len = 1; - kbuf[0] = ('*' + (keysym - XK_KP_Multiply)); - } - break; + case XK_KP_Multiply: /* "\033Oj" : "*" */ + case XK_KP_Add: /* "\033Ok" : "+" */ + case XK_KP_Separator: /* "\033Ol" : "," */ + case XK_KP_Subtract: /* "\033Om" : "-" */ + case XK_KP_Decimal: /* "\033On" : "." */ + case XK_KP_Divide: /* "\033Oo" : "/" */ + case XK_KP_0: /* "\033Op" : "0" */ + case XK_KP_1: /* "\033Oq" : "1" */ + case XK_KP_2: /* "\033Or" : "2" */ + case XK_KP_3: /* "\033Os" : "3" */ + case XK_KP_4: /* "\033Ot" : "4" */ + case XK_KP_5: /* "\033Ou" : "5" */ + case XK_KP_6: /* "\033Ov" : "6" */ + case XK_KP_7: /* "\033Ow" : "7" */ + case XK_KP_8: /* "\033Ox" : "8" */ + case XK_KP_9: /* "\033Oy" : "9" */ + /* allow shift to override */ + if ((PrivateModes & PrivMode_aplKP) ? !shft : shft) { + len = 3; + strcpy(kbuf, "\033Oj"); + kbuf[2] += (keysym - XK_KP_Multiply); + } else { + len = 1; + kbuf[0] = ('*' + (keysym - XK_KP_Multiply)); + } + break; #define FKEY(n,fkey) do { \ len = 5; \ sprintf((char *) kbuf,"\033[%02d~", (int)((n) + (keysym - fkey))); \ } while (0); - case XK_F1: /* "\033[11~" */ - case XK_F2: /* "\033[12~" */ - case XK_F3: /* "\033[13~" */ - case XK_F4: /* "\033[14~" */ - case XK_F5: /* "\033[15~" */ - FKEY(11, XK_F1); - break; + case XK_F1: /* "\033[11~" */ + case XK_F2: /* "\033[12~" */ + case XK_F3: /* "\033[13~" */ + case XK_F4: /* "\033[14~" */ + case XK_F5: /* "\033[15~" */ + FKEY(11, XK_F1); + break; - case XK_F6: /* "\033[17~" */ - case XK_F7: /* "\033[18~" */ - case XK_F8: /* "\033[19~" */ - case XK_F9: /* "\033[20~" */ - case XK_F10: /* "\033[21~" */ - FKEY(17, XK_F6); - break; + case XK_F6: /* "\033[17~" */ + case XK_F7: /* "\033[18~" */ + case XK_F8: /* "\033[19~" */ + case XK_F9: /* "\033[20~" */ + case XK_F10: /* "\033[21~" */ + FKEY(17, XK_F6); + break; - case XK_F11: /* "\033[23~" */ - case XK_F12: /* "\033[24~" */ - case XK_F13: /* "\033[25~" */ - case XK_F14: /* "\033[26~" */ - FKEY(23, XK_F11); - break; + case XK_F11: /* "\033[23~" */ + case XK_F12: /* "\033[24~" */ + case XK_F13: /* "\033[25~" */ + case XK_F14: /* "\033[26~" */ + FKEY(23, XK_F11); + break; - case XK_F15: /* "\033[28~" */ - case XK_F16: /* "\033[29~" */ - FKEY(28, XK_F15); - break; + case XK_F15: /* "\033[28~" */ + case XK_F16: /* "\033[29~" */ + FKEY(28, XK_F15); + break; - case XK_F17: /* "\033[31~" */ - case XK_F18: /* "\033[32~" */ - case XK_F19: /* "\033[33~" */ - case XK_F20: /* "\033[34~" */ - case XK_F21: /* "\033[35~" */ - case XK_F22: /* "\033[36~" */ - case XK_F23: /* "\033[37~" */ - case XK_F24: /* "\033[38~" */ - case XK_F25: /* "\033[39~" */ - case XK_F26: /* "\033[40~" */ - case XK_F27: /* "\033[41~" */ - case XK_F28: /* "\033[42~" */ - case XK_F29: /* "\033[43~" */ - case XK_F30: /* "\033[44~" */ - case XK_F31: /* "\033[45~" */ - case XK_F32: /* "\033[46~" */ - case XK_F33: /* "\033[47~" */ - case XK_F34: /* "\033[48~" */ - case XK_F35: /* "\033[49~" */ - FKEY(31, XK_F17); - break; + case XK_F17: /* "\033[31~" */ + case XK_F18: /* "\033[32~" */ + case XK_F19: /* "\033[33~" */ + case XK_F20: /* "\033[34~" */ + case XK_F21: /* "\033[35~" */ + case XK_F22: /* "\033[36~" */ + case XK_F23: /* "\033[37~" */ + case XK_F24: /* "\033[38~" */ + case XK_F25: /* "\033[39~" */ + case XK_F26: /* "\033[40~" */ + case XK_F27: /* "\033[41~" */ + case XK_F28: /* "\033[42~" */ + case XK_F29: /* "\033[43~" */ + case XK_F30: /* "\033[44~" */ + case XK_F31: /* "\033[45~" */ + case XK_F32: /* "\033[46~" */ + case XK_F33: /* "\033[47~" */ + case XK_F34: /* "\033[48~" */ + case XK_F35: /* "\033[49~" */ + FKEY(31, XK_F17); + break; #undef FKEY - } + } #ifdef META8_OPTION - if (meta && (meta_char == 0x80) && len > 0) { - kbuf[len - 1] |= 0x80; - } + if (meta && (meta_char == 0x80) && len > 0) { + kbuf[len - 1] |= 0x80; + } #endif - } else if (ctrl && keysym == XK_minus) { - len = 1; - kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ - } else { + } else if (ctrl && keysym == XK_minus) { + len = 1; + kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ + } else { #ifdef META8_OPTION - /* set 8-bit on */ - if (meta && (meta_char == 0x80)) { + /* set 8-bit on */ + if (meta && (meta_char == 0x80)) { - unsigned char *ch; + unsigned char *ch; - for (ch = kbuf; ch < kbuf + len; ch++) - *ch |= 0x80; - meta = 0; - } + for (ch = kbuf; ch < kbuf + len; ch++) + *ch |= 0x80; + meta = 0; + } #endif #ifdef GREEK_SUPPORT - if (greek_mode) - len = greek_xlat(kbuf, len); + if (greek_mode) + len = greek_xlat(kbuf, len); #endif - } + } #ifdef USE_XIM - } + } #endif - /* All processed. If there's still no string, we're done. */ - if (len <= 0) { - LK_RET(); - } + /* All processed. If there's still no string, we're done. */ + if (len <= 0) { + LK_RET(); + } - /* - * these modifications only affect the static keybuffer - * pass Shift/Control indicators for function keys ending with `~' - * - * eg, - * Prior = "ESC[5~" - * Shift+Prior = "ESC[5$" - * Ctrl+Prior = "ESC[5^" - * Ctrl+Shift+Prior = "ESC[5@" - */ - if (kbuf[0] == '\033' && kbuf[1] == '[' && kbuf[len - 1] == '~') { - kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); - } + /* + * these modifications only affect the static keybuffer + * pass Shift/Control indicators for function keys ending with `~' + * + * eg, + * Prior = "ESC[5~" + * Shift+Prior = "ESC[5$" + * Ctrl+Prior = "ESC[5^" + * Ctrl+Shift+Prior = "ESC[5@" + */ + if (kbuf[0] == '\033' && kbuf[1] == '[' && kbuf[len - 1] == '~') { + kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); + } - /* escape prefix */ - if (meta + /* escape prefix */ + if (meta #ifdef META8_OPTION - && (meta_char == 033) + && (meta_char == 033) #endif - ) { + ) { - const unsigned char ch = '\033'; + const unsigned char ch = '\033'; - tt_write(&ch, 1); - } - D_TTY(("After handling: len %d, keysym \"%s\" (0x%04x), and buffer \"%s\"\n", - len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len))); - tt_write(kbuf, len); /* Send the resulting string to the child process */ + tt_write(&ch, 1); + } + D_TTY(("After handling: len %d, keysym \"%s\" (0x%04x), and buffer \"%s\"\n", + len, XKeysymToString(keysym), keysym, safe_print_string(kbuf, len))); + tt_write(kbuf, len); /* Send the resulting string to the child process */ - LK_RET(); + LK_RET(); } #ifdef PRINTPIPE @@ -805,50 +803,50 @@ sprintf((char *) kbuf,"\033[%02d~", (int)((n) + (keysym - fkey))); \ FILE * popen_printer(void) { - FILE *stream; + FILE *stream; - if (((my_ruid != my_euid) || (my_rgid != my_egid)) && (strcmp(rs_print_pipe, PRINTPIPE))) { - print_warning("Running setuid/setgid. Refusing to use custom printpipe.\n"); - RESET_AND_ASSIGN(rs_print_pipe, STRDUP(PRINTPIPE)); - } - if ((stream = (FILE *) popen(rs_print_pipe, "w")) == NULL) { - print_error("Can't open printer pipe \"%s\" -- %s\n", rs_print_pipe, strerror(errno)); - } - return stream; + if (((my_ruid != my_euid) || (my_rgid != my_egid)) && (strcmp(rs_print_pipe, PRINTPIPE))) { + print_warning("Running setuid/setgid. Refusing to use custom printpipe.\n"); + RESET_AND_ASSIGN(rs_print_pipe, STRDUP(PRINTPIPE)); + } + if ((stream = (FILE *) popen(rs_print_pipe, "w")) == NULL) { + print_error("Can't open printer pipe \"%s\" -- %s\n", rs_print_pipe, strerror(errno)); + } + return stream; } /* Close the print pipe. */ int pclose_printer(FILE * stream) { - fflush(stream); - return pclose(stream); + fflush(stream); + return pclose(stream); } /* Print everything until we hit a \e[4i sequence. */ void process_print_pipe(void) { - const char *const escape_seq = "\033[4i"; - const char *const rev_escape_seq = "i4[\033"; - int index; - FILE *fd; + const char *const escape_seq = "\033[4i"; + const char *const rev_escape_seq = "i4[\033"; + int index; + FILE *fd; - if ((fd = popen_printer()) != NULL) { - for (index = 0; index < 4; /* nil */ ) { - unsigned char ch = cmd_getc(); + if ((fd = popen_printer()) != NULL) { + for (index = 0; index < 4; /* nil */ ) { + unsigned char ch = cmd_getc(); - if (ch == escape_seq[index]) - index++; - else if (index) - for ( /*nil */ ; index > 0; index--) - fputc(rev_escape_seq[index - 1], fd); + if (ch == escape_seq[index]) + index++; + else if (index) + for ( /*nil */ ; index > 0; index--) + fputc(rev_escape_seq[index - 1], fd); - if (index == 0) - fputc(ch, fd); + if (index == 0) + fputc(ch, fd); + } + pclose_printer(fd); } - pclose_printer(fd); - } } #endif /* PRINTPIPE */ @@ -861,83 +859,83 @@ process_print_pipe(void) void process_escape_seq(void) { - unsigned char ch = cmd_getc(); + unsigned char ch = cmd_getc(); - switch (ch) { - case '#': - if (cmd_getc() == '8') - scr_E(); - break; - case '(': - scr_charset_set(0, cmd_getc()); - break; - case ')': - scr_charset_set(1, cmd_getc()); - break; - case '*': - scr_charset_set(2, cmd_getc()); - break; - case '+': - scr_charset_set(3, cmd_getc()); - break; + switch (ch) { + case '#': + if (cmd_getc() == '8') + scr_E(); + break; + case '(': + scr_charset_set(0, cmd_getc()); + break; + case ')': + scr_charset_set(1, cmd_getc()); + break; + case '*': + scr_charset_set(2, cmd_getc()); + break; + case '+': + scr_charset_set(3, cmd_getc()); + break; #ifdef MULTI_CHARSET - case '$': - scr_charset_set(-2, cmd_getc()); - break; + case '$': + scr_charset_set(-2, cmd_getc()); + break; #endif - case '7': - scr_cursor(SAVE); - break; - case '8': - scr_cursor(RESTORE); - break; - case '=': - case '>': - PrivMode((ch == '='), PrivMode_aplKP); - break; - case '@': - (void) cmd_getc(); - break; - case 'D': - scr_index(UP); - break; - case 'E': - scr_add_lines((unsigned char *) "\n\r", 1, 2); - break; - case 'G': - if ((ch = cmd_getc()) == 'Q') { /* query graphics */ - tt_printf((unsigned char *) "\033G0\n"); /* no graphics */ - } else { - do { - ch = cmd_getc(); - } while (ch != ':'); - } - break; - case 'H': - scr_set_tab(1); - break; - case 'M': - scr_index(DN); - break; - case 'Z': - tt_printf((unsigned char *) ESCZ_ANSWER); - break; - case '[': - process_csi_seq(); - break; - case ']': - process_xterm_seq(); - break; - case 'c': - scr_poweron(); - break; - case 'n': - scr_charset_choose(2); - break; - case 'o': - scr_charset_choose(3); - break; - } + case '7': + scr_cursor(SAVE); + break; + case '8': + scr_cursor(RESTORE); + break; + case '=': + case '>': + PrivMode((ch == '='), PrivMode_aplKP); + break; + case '@': + (void) cmd_getc(); + break; + case 'D': + scr_index(UP); + break; + case 'E': + scr_add_lines((unsigned char *) "\n\r", 1, 2); + break; + case 'G': + if ((ch = cmd_getc()) == 'Q') { /* query graphics */ + tt_printf((unsigned char *) "\033G0\n"); /* no graphics */ + } else { + do { + ch = cmd_getc(); + } while (ch != ':'); + } + break; + case 'H': + scr_set_tab(1); + break; + case 'M': + scr_index(DN); + break; + case 'Z': + tt_printf((unsigned char *) ESCZ_ANSWER); + break; + case '[': + process_csi_seq(); + break; + case ']': + process_xterm_seq(); + break; + case 'c': + scr_poweron(); + break; + case 'n': + scr_charset_choose(2); + break; + case 'o': + scr_charset_choose(3); + break; + } } /* This function handles Code Sequence Introducer (CSI) escape sequences. At this point, @@ -948,347 +946,346 @@ void process_csi_seq(void) { - unsigned char ch; - unsigned char priv = 0; - unsigned int nargs = 0; - int arg[ESC_ARGS] = {0, 0}; - int ignore = 0; + unsigned char ch; + unsigned char priv = 0; + unsigned int nargs = 0; + int arg[ESC_ARGS] = { 0, 0 }; + int ignore = 0; - ch = cmd_getc(); /* Get the next character */ - if (ch >= '<' && ch <= '?') { - priv = ch; /* DEC private mode sequence. Get next character. */ - ch = cmd_getc(); - } - /* Read semicolon-delimited numerical arguments, if any. */ - do { - int n; - - for (n = 0; isdigit(ch); ch = cmd_getc()) - n = n * 10 + (ch - '0'); - - if (nargs < ESC_ARGS) - arg[nargs++] = n; - if (ch == '\b') { - scr_backspace(); - } else if (ch == 033) { - cmd_ungetc(); /* New escape sequence starting in the middle of one. Punt. */ - return; - } else if (ch < ' ') { - scr_add_lines(&ch, 0, 1); /* Insert verbatim non-printable character (NPC) */ - return; + ch = cmd_getc(); /* Get the next character */ + if (ch >= '<' && ch <= '?') { + priv = ch; /* DEC private mode sequence. Get next character. */ + ch = cmd_getc(); } - if (ch == '-') /* HACK: Ignore this sequence, but finish reading */ - ignore = 1; /* xterm ignores more than this, but we need this for vim */ - if (ch < '@') - ch = cmd_getc(); /* Separator. Go to next digit or operation. */ - } while (ch >= ' ' && ch < '@'); - if (ch == 033) { - cmd_ungetc(); - return; - } else if (ch < ' ') - return; /* An NPC. Punt. */ + /* Read semicolon-delimited numerical arguments, if any. */ + do { + int n; - if(ignore) - return; + for (n = 0; isdigit(ch); ch = cmd_getc()) + n = n * 10 + (ch - '0'); - switch (ch) { - case '@': - scr_insdel_chars((arg[0] ? arg[0] : 1), INSERT); - break; - case 'A': - case 'e': /* Cursor up n lines "\e[A" */ - scr_gotorc((arg[0] ? -arg[0] : -1), 0, RELATIVE); - break; - case 'B': /* Cursor down n lines "\e[B" */ - scr_gotorc((arg[0] ? +arg[0] : +1), 0, RELATIVE); - break; - case 'C': - case 'a': /* Cursor right n columns "\e[C" */ - scr_gotorc(0, (arg[0] ? +arg[0] : +1), RELATIVE); - break; - case 'D': /* Cursor left n columns "\e[D" */ - scr_gotorc(0, (arg[0] ? -arg[0] : -1), RELATIVE); - break; - case 'E': /* Cursor down n lines and to first column "\e[E" */ - scr_gotorc((arg[0] ? +arg[0] : +1), 0, R_RELATIVE); - break; - case 'F': /* Cursor up n lines and to first column "\e[F" */ - scr_gotorc((arg[0] ? -arg[0] : -1), 0, R_RELATIVE); - break; - case 'G': - case '`': /* Cursor to column n "\e[G" */ - scr_gotorc(0, (arg[0] ? arg[0] - 1 : +1), R_RELATIVE); - break; - case 'H': - case 'f': /* Cursor to row r, column c "\e[;H" */ - switch (nargs) { - case 0: - scr_gotorc(0, 0, 0); - break; - case 1: - scr_gotorc((arg[0] ? arg[0] - 1 : 0), 0, 0); - break; - default: - scr_gotorc(arg[0] - 1, arg[1] - 1, 0); - break; - } - break; - case 'I': /* Tab right n tab stops "\e[I" */ - scr_tab(arg[0] ? +arg[0] : +1); - break; - case 'J': /* Clear part or all of screen, depending on n "\e[J" */ - scr_erase_screen(arg[0]); - break; - case 'K': /* Clear part or all of line, depending on n "\e[K" */ - scr_erase_line(arg[0]); - break; - case 'L': - scr_insdel_lines((arg[0] ? arg[0] : 1), INSERT); - break; - case 'M': - scr_insdel_lines((arg[0] ? arg[0] : 1), DELETE); - break; - case 'P': - scr_insdel_chars((arg[0] ? arg[0] : 1), DELETE); - break; - case 'W': - switch (arg[0]) { - case 0: - scr_set_tab(1); - break; /* = ESC H */ - case 2: - scr_set_tab(0); - break; /* = ESC [ 0 g */ - case 5: - scr_set_tab(-1); - break; /* = ESC [ 3 g */ - } - break; - case 'X': - scr_insdel_chars((arg[0] ? arg[0] : 1), ERASE); - break; - case 'Z': /* Tab left n tab stops "\e[Z" */ - scr_tab(arg[0] ? -arg[0] : -1); - break; + if (nargs < ESC_ARGS) + arg[nargs++] = n; + if (ch == '\b') { + scr_backspace(); + } else if (ch == 033) { + cmd_ungetc(); /* New escape sequence starting in the middle of one. Punt. */ + return; + } else if (ch < ' ') { + scr_add_lines(&ch, 0, 1); /* Insert verbatim non-printable character (NPC) */ + return; + } + if (ch == '-') /* HACK: Ignore this sequence, but finish reading */ + ignore = 1; /* xterm ignores more than this, but we need this for vim */ + if (ch < '@') + ch = cmd_getc(); /* Separator. Go to next digit or operation. */ + } while (ch >= ' ' && ch < '@'); + if (ch == 033) { + cmd_ungetc(); + return; + } else if (ch < ' ') + return; /* An NPC. Punt. */ - case 'c': - /* TODO: A different response should be sent depending on the value of - priv and of arg[0], but what should those reponses be? */ + if (ignore) + return; + + switch (ch) { + case '@': + scr_insdel_chars((arg[0] ? arg[0] : 1), INSERT); + break; + case 'A': + case 'e': /* Cursor up n lines "\e[A" */ + scr_gotorc((arg[0] ? -arg[0] : -1), 0, RELATIVE); + break; + case 'B': /* Cursor down n lines "\e[B" */ + scr_gotorc((arg[0] ? +arg[0] : +1), 0, RELATIVE); + break; + case 'C': + case 'a': /* Cursor right n columns "\e[C" */ + scr_gotorc(0, (arg[0] ? +arg[0] : +1), RELATIVE); + break; + case 'D': /* Cursor left n columns "\e[D" */ + scr_gotorc(0, (arg[0] ? -arg[0] : -1), RELATIVE); + break; + case 'E': /* Cursor down n lines and to first column "\e[E" */ + scr_gotorc((arg[0] ? +arg[0] : +1), 0, R_RELATIVE); + break; + case 'F': /* Cursor up n lines and to first column "\e[F" */ + scr_gotorc((arg[0] ? -arg[0] : -1), 0, R_RELATIVE); + break; + case 'G': + case '`': /* Cursor to column n "\e[G" */ + scr_gotorc(0, (arg[0] ? arg[0] - 1 : +1), R_RELATIVE); + break; + case 'H': + case 'f': /* Cursor to row r, column c "\e[;H" */ + switch (nargs) { + case 0: + scr_gotorc(0, 0, 0); + break; + case 1: + scr_gotorc((arg[0] ? arg[0] - 1 : 0), 0, 0); + break; + default: + scr_gotorc(arg[0] - 1, arg[1] - 1, 0); + break; + } + break; + case 'I': /* Tab right n tab stops "\e[I" */ + scr_tab(arg[0] ? +arg[0] : +1); + break; + case 'J': /* Clear part or all of screen, depending on n "\e[J" */ + scr_erase_screen(arg[0]); + break; + case 'K': /* Clear part or all of line, depending on n "\e[K" */ + scr_erase_line(arg[0]); + break; + case 'L': + scr_insdel_lines((arg[0] ? arg[0] : 1), INSERT); + break; + case 'M': + scr_insdel_lines((arg[0] ? arg[0] : 1), DELETE); + break; + case 'P': + scr_insdel_chars((arg[0] ? arg[0] : 1), DELETE); + break; + case 'W': + switch (arg[0]) { + case 0: + scr_set_tab(1); + break; /* = ESC H */ + case 2: + scr_set_tab(0); + break; /* = ESC [ 0 g */ + case 5: + scr_set_tab(-1); + break; /* = ESC [ 3 g */ + } + break; + case 'X': + scr_insdel_chars((arg[0] ? arg[0] : 1), ERASE); + break; + case 'Z': /* Tab left n tab stops "\e[Z" */ + scr_tab(arg[0] ? -arg[0] : -1); + break; + + case 'c': + /* TODO: A different response should be sent depending on the value of + priv and of arg[0], but what should those reponses be? */ #ifndef NO_VT100_ANS - tt_printf(VT100_ANS); + tt_printf(VT100_ANS); #endif - break; - case 'd': /* Cursor to row n "\e[d" */ - scr_gotorc((arg[0] ? arg[0] - 1 : +1), 0, C_RELATIVE); - break; - case 'g': - switch (arg[0]) { - case 0: - scr_set_tab(0); - break; /* delete tab */ - case 3: - scr_set_tab(-1); - break; /* clear all tabs */ - } - break; + break; + case 'd': /* Cursor to row n "\e[d" */ + scr_gotorc((arg[0] ? arg[0] - 1 : +1), 0, C_RELATIVE); + break; + case 'g': + switch (arg[0]) { + case 0: + scr_set_tab(0); + break; /* delete tab */ + case 3: + scr_set_tab(-1); + break; /* clear all tabs */ + } + break; #ifdef PRINTPIPE - case 'i': - switch (arg[0]) { - case 0: - scr_printscreen(0); /* Print screen "\e[0i" */ - break; - case 5: - process_print_pipe(); /* Start printing to print pipe "\e[5i" */ - break; - } - break; + case 'i': + switch (arg[0]) { + case 0: + scr_printscreen(0); /* Print screen "\e[0i" */ + break; + case 5: + process_print_pipe(); /* Start printing to print pipe "\e[5i" */ + break; + } + break; #endif - case 'm': - process_sgr_mode(nargs, arg); - break; - case 'n': /* request for information */ - switch (arg[0]) { - case 5: - tt_printf((unsigned char *) "\033[0n"); - break; /* ready */ - case 6: - scr_report_position(); - break; + case 'm': + process_sgr_mode(nargs, arg); + break; + case 'n': /* request for information */ + switch (arg[0]) { + case 5: + tt_printf((unsigned char *) "\033[0n"); + break; /* ready */ + case 6: + scr_report_position(); + break; #if defined (ENABLE_DISPLAY_ANSWER) - case 7: - tt_write((unsigned char *) display_name, strlen(display_name)); - tt_write("\n", 1); - break; + case 7: + tt_write((unsigned char *) display_name, strlen(display_name)); + tt_write("\n", 1); + break; #endif - case 8: - xterm_seq(XTerm_title, APL_NAME "-" VERSION); - break; - case 9: + case 8: + xterm_seq(XTerm_title, APL_NAME "-" VERSION); + break; + case 9: #ifdef PIXMAP_OFFSET - if (image_mode_is(image_bg, MODE_TRANS)) { - char tbuff[70]; - char shading = 0; - unsigned long tint = 0xffffff; + if (image_mode_is(image_bg, MODE_TRANS)) { + char tbuff[70]; + char shading = 0; + unsigned long tint = 0xffffff; - if (images[image_bg].current->iml->mod) { - shading = images[image_bg].current->iml->mod->brightness / 0xff * 100; - } - if (images[image_bg].current->iml->rmod) { - tint = (tint & 0x00ffff) | ((images[image_bg].current->iml->rmod->brightness & 0xff) << 16); - } - if (images[image_bg].current->iml->gmod) { - tint = (tint & 0xff00ff) | ((images[image_bg].current->iml->gmod->brightness & 0xff) << 8); - } - if (images[image_bg].current->iml->bmod) { - tint = (tint & 0xffff00) | (images[image_bg].current->iml->bmod->brightness & 0xff); - } - snprintf(tbuff, sizeof(tbuff), APL_NAME "-" VERSION ": Transparent - %d%% shading - 0x%06lx tint mask", - shading, tint); - xterm_seq(XTerm_title, tbuff); - } else + if (images[image_bg].current->iml->mod) { + shading = images[image_bg].current->iml->mod->brightness / 0xff * 100; + } + if (images[image_bg].current->iml->rmod) { + tint = (tint & 0x00ffff) | ((images[image_bg].current->iml->rmod->brightness & 0xff) << 16); + } + if (images[image_bg].current->iml->gmod) { + tint = (tint & 0xff00ff) | ((images[image_bg].current->iml->gmod->brightness & 0xff) << 8); + } + if (images[image_bg].current->iml->bmod) { + tint = (tint & 0xffff00) | (images[image_bg].current->iml->bmod->brightness & 0xff); + } + snprintf(tbuff, sizeof(tbuff), APL_NAME "-" VERSION ": Transparent - %d%% shading - 0x%06lx tint mask", shading, tint); + xterm_seq(XTerm_title, tbuff); + } else #endif #ifdef PIXMAP_SUPPORT - { - char *tbuff; - unsigned short len; + { + char *tbuff; + unsigned short len; - if (background_is_pixmap()) { - const char *fname; + if (background_is_pixmap()) { + const char *fname; - imlib_context_set_image(images[image_bg].current->iml->im); - fname = imlib_image_get_filename(); - len = strlen(fname) + sizeof(APL_NAME) + sizeof(VERSION) + 5; - tbuff = MALLOC(len); - snprintf(tbuff, len, APL_NAME "-" VERSION ": %s", fname); - xterm_seq(XTerm_title, tbuff); - FREE(tbuff); - } else { - xterm_seq(XTerm_title, APL_NAME "-" VERSION ": No Pixmap"); - } - } + imlib_context_set_image(images[image_bg].current->iml->im); + fname = imlib_image_get_filename(); + len = strlen(fname) + sizeof(APL_NAME) + sizeof(VERSION) + 5; + tbuff = MALLOC(len); + snprintf(tbuff, len, APL_NAME "-" VERSION ": %s", fname); + xterm_seq(XTerm_title, tbuff); + FREE(tbuff); + } else { + xterm_seq(XTerm_title, APL_NAME "-" VERSION ": No Pixmap"); + } + } #endif /* PIXMAP_SUPPORT */ - break; - } - break; - case 'r': /* set top and bottom margins */ - if (priv != '?') { - if (nargs < 2 || arg[0] >= arg[1]) - scr_scroll_region(0, 10000); - else - scr_scroll_region(arg[0] - 1, arg[1] - 1); - break; - } - /* drop */ - case 't': - if (priv != '?') { - process_window_mode(nargs, arg); - break; - } - /* drop */ - case 's': - if (ch == 's' && !nargs) { - scr_cursor(SAVE); - break; - } - /* drop */ - case 'h': - case 'l': - process_terminal_mode(ch, priv, nargs, arg); - break; - case 'u': - if (!nargs) { - scr_cursor(RESTORE); - } - break; - } + break; + } + break; + case 'r': /* set top and bottom margins */ + if (priv != '?') { + if (nargs < 2 || arg[0] >= arg[1]) + scr_scroll_region(0, 10000); + else + scr_scroll_region(arg[0] - 1, arg[1] - 1); + break; + } + /* drop */ + case 't': + if (priv != '?') { + process_window_mode(nargs, arg); + break; + } + /* drop */ + case 's': + if (ch == 's' && !nargs) { + scr_cursor(SAVE); + break; + } + /* drop */ + case 'h': + case 'l': + process_terminal_mode(ch, priv, nargs, arg); + break; + case 'u': + if (!nargs) { + scr_cursor(RESTORE); + } + break; + } } /* process xterm text parameters sequences `ESC ] Ps ; Pt BEL' */ void process_xterm_seq(void) { - unsigned char ch, string[STRING_MAX]; - int arg; + unsigned char ch, string[STRING_MAX]; + int arg; - ch = cmd_getc(); - if (isdigit(ch)) { - for (arg = 0; isdigit(ch); ch = cmd_getc()) { - arg = arg * 10 + (ch - '0'); - } - } else if (ch == ';') { - arg = 0; - } else { - arg = ch; ch = cmd_getc(); - } - if (arg == 'R') { - stored_palette(RESTORE); - redraw_image(image_bg); - set_colorfgbg(); - scr_touch(); - scr_refresh(DEFAULT_REFRESH); - return; - } else if (arg == 'P') { - unsigned char i, idx; - - idx = ((ch <= '9') ? (ch - '0') : (tolower(ch) - 'a' + 10)) + minColor; - string[0] = '#'; - string[7] = 0; - for (i = 1; i < 7; i++) { - string[i] = cmd_getc(); + if (isdigit(ch)) { + for (arg = 0; isdigit(ch); ch = cmd_getc()) { + arg = arg * 10 + (ch - '0'); + } + } else if (ch == ';') { + arg = 0; + } else { + arg = ch; + ch = cmd_getc(); } - set_window_color(idx, string); - return; - } else if (ch == ';') { - unsigned long n = 0; + if (arg == 'R') { + stored_palette(RESTORE); + redraw_image(image_bg); + set_colorfgbg(); + scr_touch(); + scr_refresh(DEFAULT_REFRESH); + return; + } else if (arg == 'P') { + unsigned char i, idx; - while ((ch = cmd_getc()) != 007) { - if (ch) { - if (ch == '\t') - ch = ' '; /* translate '\t' to space */ - else if (ch < ' ') - return; /* control character - exit */ + idx = ((ch <= '9') ? (ch - '0') : (tolower(ch) - 'a' + 10)) + minColor; + string[0] = '#'; + string[7] = 0; + for (i = 1; i < 7; i++) { + string[i] = cmd_getc(); + } + set_window_color(idx, string); + return; + } else if (ch == ';') { + unsigned long n = 0; - if (n < sizeof(string) - 1) - string[n++] = ch; - } + while ((ch = cmd_getc()) != 007) { + if (ch) { + if (ch == '\t') + ch = ' '; /* translate '\t' to space */ + else if (ch < ' ') + return; /* control character - exit */ + + if (n < sizeof(string) - 1) + string[n++] = ch; + } + } + string[n] = '\0'; + xterm_seq(arg, (char *) string); + + } else { + unsigned long n = 0; + + for (; ch != '\033'; ch = cmd_getc()) { + if (ch) { + if (ch == '\t') + ch = ' '; /* translate '\t' to space */ + else if (ch < ' ') + return; /* control character - exit */ + + if (n < sizeof(string) - 1) + string[n++] = ch; + } + } + string[n] = '\0'; + + if ((ch = cmd_getc()) != '\\') { + return; + } + switch (arg) { + case 'l': + xterm_seq(XTerm_title, (char *) string); + break; + case 'L': + xterm_seq(XTerm_iconName, (char *) string); + break; + case 'I': + set_icon_pixmap((char *) string, NULL); + break; + default: + break; + } } - string[n] = '\0'; - xterm_seq(arg, (char *) string); - - } else { - unsigned long n = 0; - - for (; ch != '\033'; ch = cmd_getc()) { - if (ch) { - if (ch == '\t') - ch = ' '; /* translate '\t' to space */ - else if (ch < ' ') - return; /* control character - exit */ - - if (n < sizeof(string) - 1) - string[n++] = ch; - } - } - string[n] = '\0'; - - if ((ch = cmd_getc()) != '\\') { - return; - } - switch (arg) { - case 'l': - xterm_seq(XTerm_title, (char *) string); - break; - case 'L': - xterm_seq(XTerm_iconName, (char *) string); - break; - case 'I': - set_icon_pixmap((char *) string, NULL); - break; - default: - break; - } - } } /* Process window manipulations */ @@ -1296,102 +1293,103 @@ void process_window_mode(unsigned int nargs, int args[]) { - register unsigned int i; - int x, y; - Screen *scr; - Window dummy_child; - int dummy_x, dummy_y; - unsigned int dummy_border, dummy_depth; - char buff[1024], *name; + register unsigned int i; + int x, y; + Screen *scr; + Window dummy_child; + int dummy_x, dummy_y; + unsigned int dummy_border, dummy_depth; + char buff[1024], *name; - if (!nargs) - return; - scr = ScreenOfDisplay(Xdisplay, Xscreen); - if (!scr) - return; + if (!nargs) + return; + scr = ScreenOfDisplay(Xdisplay, Xscreen); + if (!scr) + return; - for (i = 0; i < nargs; i++) { - switch (args[i]) { - case 1: - XMapRaised(Xdisplay, TermWin.parent); - break; - case 2: - XIconifyWindow(Xdisplay, TermWin.parent, Xscreen); - break; - case 3: - if (i + 2 >= nargs) - return; /* Make sure there are 2 args left */ - x = args[++i]; - y = args[++i]; - if (((unsigned int) x > (unsigned int) scr->width) || ((unsigned int) y > (unsigned int) scr->height)) - return; /* Don't move off-screen */ - XMoveWindow(Xdisplay, TermWin.parent, x, y); - break; - case 4: - if (i + 2 >= nargs) - return; /* Make sure there are 2 args left */ - y = args[++i]; - x = args[++i]; - BOUND(y, szHint.min_height, scr->height); - BOUND(x, szHint.min_width, scr->width); - XResizeWindow(Xdisplay, TermWin.parent, x, y); - break; - case 5: - XRaiseWindow(Xdisplay, TermWin.parent); - break; - case 6: - XLowerWindow(Xdisplay, TermWin.parent); - break; - case 7: - XClearWindow(Xdisplay, TermWin.vt); - XSync(Xdisplay, False); - scr_touch(); - scr_refresh(DEFAULT_REFRESH); - break; - case 8: - if (i + 2 >= nargs) - return; /* Make sure there are 2 args left */ - y = args[++i]; - x = args[++i]; - BOUND(y, 1, scr->height / TermWin.fheight); - BOUND(x, 1, scr->width / TermWin.fwidth); - XResizeWindow(Xdisplay, TermWin.parent, - Width2Pixel(x) + 2 * TermWin.internalBorder + (scrollbar_is_visible()? scrollbar_trough_width() : 0), - Height2Pixel(y) + 2 * TermWin.internalBorder); - break; - case 11: - break; - case 13: - XTranslateCoordinates(Xdisplay, TermWin.parent, Xroot, 0, 0, &x, &y, &dummy_child); - snprintf(buff, sizeof(buff), "\033[3;%d;%dt", x, y); - tt_write((unsigned char *) buff, strlen(buff)); - break; - case 14: - /* Store current width and height in x and y */ - XGetGeometry(Xdisplay, TermWin.parent, &dummy_child, &dummy_x, &dummy_y, (unsigned int *) (&x), (unsigned int *) (&y), &dummy_border, &dummy_depth); - snprintf(buff, sizeof(buff), "\033[4;%d;%dt", y, x); - tt_write((unsigned char *) buff, strlen(buff)); - break; - case 18: - snprintf(buff, sizeof(buff), "\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); - tt_write((unsigned char *) buff, strlen(buff)); - break; - case 20: - XGetIconName(Xdisplay, TermWin.parent, &name); - snprintf(buff, sizeof(buff), "\033]L%s\033\\", name); - tt_write((unsigned char *) buff, strlen(buff)); - XFree(name); - break; - case 21: - XFetchName(Xdisplay, TermWin.parent, &name); - snprintf(buff, sizeof(buff), "\033]l%s\033\\", name); - tt_write((unsigned char *) buff, strlen(buff)); - XFree(name); - break; - default: - break; + for (i = 0; i < nargs; i++) { + switch (args[i]) { + case 1: + XMapRaised(Xdisplay, TermWin.parent); + break; + case 2: + XIconifyWindow(Xdisplay, TermWin.parent, Xscreen); + break; + case 3: + if (i + 2 >= nargs) + return; /* Make sure there are 2 args left */ + x = args[++i]; + y = args[++i]; + if (((unsigned int) x > (unsigned int) scr->width) || ((unsigned int) y > (unsigned int) scr->height)) + return; /* Don't move off-screen */ + XMoveWindow(Xdisplay, TermWin.parent, x, y); + break; + case 4: + if (i + 2 >= nargs) + return; /* Make sure there are 2 args left */ + y = args[++i]; + x = args[++i]; + BOUND(y, szHint.min_height, scr->height); + BOUND(x, szHint.min_width, scr->width); + XResizeWindow(Xdisplay, TermWin.parent, x, y); + break; + case 5: + XRaiseWindow(Xdisplay, TermWin.parent); + break; + case 6: + XLowerWindow(Xdisplay, TermWin.parent); + break; + case 7: + XClearWindow(Xdisplay, TermWin.vt); + XSync(Xdisplay, False); + scr_touch(); + scr_refresh(DEFAULT_REFRESH); + break; + case 8: + if (i + 2 >= nargs) + return; /* Make sure there are 2 args left */ + y = args[++i]; + x = args[++i]; + BOUND(y, 1, scr->height / TermWin.fheight); + BOUND(x, 1, scr->width / TermWin.fwidth); + XResizeWindow(Xdisplay, TermWin.parent, + Width2Pixel(x) + 2 * TermWin.internalBorder + (scrollbar_is_visible()? scrollbar_trough_width() : 0), + Height2Pixel(y) + 2 * TermWin.internalBorder); + break; + case 11: + break; + case 13: + XTranslateCoordinates(Xdisplay, TermWin.parent, Xroot, 0, 0, &x, &y, &dummy_child); + snprintf(buff, sizeof(buff), "\033[3;%d;%dt", x, y); + tt_write((unsigned char *) buff, strlen(buff)); + break; + case 14: + /* Store current width and height in x and y */ + XGetGeometry(Xdisplay, TermWin.parent, &dummy_child, &dummy_x, &dummy_y, (unsigned int *) (&x), (unsigned int *) (&y), + &dummy_border, &dummy_depth); + snprintf(buff, sizeof(buff), "\033[4;%d;%dt", y, x); + tt_write((unsigned char *) buff, strlen(buff)); + break; + case 18: + snprintf(buff, sizeof(buff), "\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); + tt_write((unsigned char *) buff, strlen(buff)); + break; + case 20: + XGetIconName(Xdisplay, TermWin.parent, &name); + snprintf(buff, sizeof(buff), "\033]L%s\033\\", name); + tt_write((unsigned char *) buff, strlen(buff)); + XFree(name); + break; + case 21: + XFetchName(Xdisplay, TermWin.parent, &name); + snprintf(buff, sizeof(buff), "\033]l%s\033\\", name); + tt_write((unsigned char *) buff, strlen(buff)); + XFree(name); + break; + default: + break; + } } - } } /* process DEC private mode sequences `ESC [ ? Ps mode' */ @@ -1406,227 +1404,227 @@ process_window_mode(unsigned int nargs, int args[]) void process_terminal_mode(int mode, int priv, unsigned int nargs, int arg[]) { - unsigned int i; - int state; /* This gets set by the PrivCases macro */ + unsigned int i; + int state; /* This gets set by the PrivCases macro */ - if (nargs == 0) - return; + if (nargs == 0) + return; - /* make lo/hi boolean */ - switch (mode) { - case 'l': - mode = 0; - break; - case 'h': - mode = 1; - break; - } + /* make lo/hi boolean */ + switch (mode) { + case 'l': + mode = 0; + break; + case 'h': + mode = 1; + break; + } - switch (priv) { - case 0: - if (mode && mode != 1) - return; /* only do high/low */ - for (i = 0; i < nargs; i++) - switch (arg[i]) { - case 4: - scr_insert_mode(mode); - break; - /* case 38: TEK mode */ - } - break; + switch (priv) { + case 0: + if (mode && mode != 1) + return; /* only do high/low */ + for (i = 0; i < nargs; i++) + switch (arg[i]) { + case 4: + scr_insert_mode(mode); + break; + /* case 38: TEK mode */ + } + break; - case '?': - for (i = 0; i < nargs; i++) - switch (arg[i]) { - case 1: /* application cursor keys */ - PrivCases(PrivMode_aplCUR); - break; + case '?': + for (i = 0; i < nargs; i++) + switch (arg[i]) { + case 1: /* application cursor keys */ + PrivCases(PrivMode_aplCUR); + break; - /* case 2: - reset charsets to USASCII */ + /* case 2: - reset charsets to USASCII */ - case 3: /* 80/132 */ - PrivCases(PrivMode_132); - if (PrivateModes & PrivMode_132OK) - set_width(state ? 132 : 80); - break; + case 3: /* 80/132 */ + PrivCases(PrivMode_132); + if (PrivateModes & PrivMode_132OK) + set_width(state ? 132 : 80); + break; - /* case 4: - smooth scrolling */ + /* case 4: - smooth scrolling */ - case 5: /* reverse video */ - PrivCases(PrivMode_rVideo); - scr_rvideo_mode(state); - break; + case 5: /* reverse video */ + PrivCases(PrivMode_rVideo); + scr_rvideo_mode(state); + break; - case 6: /* relative/absolute origins */ - PrivCases(PrivMode_relOrigin); - scr_relative_origin(state); - break; + case 6: /* relative/absolute origins */ + PrivCases(PrivMode_relOrigin); + scr_relative_origin(state); + break; - case 7: /* autowrap */ - PrivCases(PrivMode_Autowrap); - scr_autowrap(state); - break; + case 7: /* autowrap */ + PrivCases(PrivMode_Autowrap); + scr_autowrap(state); + break; - /* case 8: - auto repeat, can't do on a per window basis */ + /* case 8: - auto repeat, can't do on a per window basis */ - case 9: /* X10 mouse reporting */ - PrivCases(PrivMode_MouseX10); - /* orthogonal */ - if (PrivateModes & PrivMode_MouseX10) - PrivateModes &= ~(PrivMode_MouseX11); - break; + case 9: /* X10 mouse reporting */ + PrivCases(PrivMode_MouseX10); + /* orthogonal */ + if (PrivateModes & PrivMode_MouseX10) + PrivateModes &= ~(PrivMode_MouseX11); + break; - case 25: /* visible/invisible cursor */ - PrivCases(PrivMode_VisibleCursor); - scr_cursor_visible(state); - break; + case 25: /* visible/invisible cursor */ + PrivCases(PrivMode_VisibleCursor); + scr_cursor_visible(state); + break; - case 30: - PrivCases(PrivMode_scrollbar); - map_scrollbar(state); - break; + case 30: + PrivCases(PrivMode_scrollbar); + map_scrollbar(state); + break; - case 35: - PrivCases(PrivMode_ShiftKeys); - break; + case 35: + PrivCases(PrivMode_ShiftKeys); + break; - case 40: /* 80 <--> 132 mode */ - PrivCases(PrivMode_132OK); - break; + case 40: /* 80 <--> 132 mode */ + PrivCases(PrivMode_132OK); + break; - case 47: /* secondary screen */ - PrivCases(PrivMode_Screen); - scr_change_screen(state); - break; + case 47: /* secondary screen */ + PrivCases(PrivMode_Screen); + scr_change_screen(state); + break; - case 66: /* application key pad */ - PrivCases(PrivMode_aplKP); - break; + case 66: /* application key pad */ + PrivCases(PrivMode_aplKP); + break; - case 67: - PrivCases(PrivMode_BackSpace); - break; + case 67: + PrivCases(PrivMode_BackSpace); + break; - case 1000: /* X11 mouse reporting */ - PrivCases(PrivMode_MouseX11); - /* orthogonal */ - if (PrivateModes & PrivMode_MouseX11) - PrivateModes &= ~(PrivMode_MouseX10); - break; + case 1000: /* X11 mouse reporting */ + PrivCases(PrivMode_MouseX11); + /* orthogonal */ + if (PrivateModes & PrivMode_MouseX11) + PrivateModes &= ~(PrivMode_MouseX10); + break; #if 0 - case 1001: - break; /* X11 mouse highlighting */ + case 1001: + break; /* X11 mouse highlighting */ #endif - case 1010: /* Scroll to bottom on TTY output */ - if (Options & Opt_home_on_output) - Options &= ~Opt_home_on_output; - else - Options |= Opt_home_on_output; - break; - case 1012: /* Scroll to bottom on TTY input */ - if (Options & Opt_home_on_input) - Options &= ~Opt_home_on_input; - else - Options |= Opt_home_on_input; - break; - - case 1047: /* Alternate screen & clear */ - PrivCases(PrivMode_Screen); - if (!state) { - /* Only clear the screen before switching from - secondary to primary. */ - scr_erase_screen(2); - } - scr_change_screen(state); - break; - case 1048: /* Save/restore cursor pos */ - PrivCases(PrivMode_Screen); - scr_cursor(state ? SAVE : RESTORE); - break; - case 1049: /* Alternate screen & cursor */ - PrivCases(PrivMode_Screen); - scr_cursor(state ? SAVE : RESTORE); - if (!state) { - /* Only clear the screen before switching from - secondary to primary. */ - scr_erase_screen(2); - } - scr_change_screen(state); - break; - } - break; - } + case 1010: /* Scroll to bottom on TTY output */ + if (Options & Opt_home_on_output) + Options &= ~Opt_home_on_output; + else + Options |= Opt_home_on_output; + break; + case 1012: /* Scroll to bottom on TTY input */ + if (Options & Opt_home_on_input) + Options &= ~Opt_home_on_input; + else + Options |= Opt_home_on_input; + break; + + case 1047: /* Alternate screen & clear */ + PrivCases(PrivMode_Screen); + if (!state) { + /* Only clear the screen before switching from + secondary to primary. */ + scr_erase_screen(2); + } + scr_change_screen(state); + break; + case 1048: /* Save/restore cursor pos */ + PrivCases(PrivMode_Screen); + scr_cursor(state ? SAVE : RESTORE); + break; + case 1049: /* Alternate screen & cursor */ + PrivCases(PrivMode_Screen); + scr_cursor(state ? SAVE : RESTORE); + if (!state) { + /* Only clear the screen before switching from + secondary to primary. */ + scr_erase_screen(2); + } + scr_change_screen(state); + break; + } + break; + } } /* process sgr sequences */ void process_sgr_mode(unsigned int nargs, int arg[]) { - unsigned int i; + unsigned int i; - if (nargs == 0) { - scr_rendition(0, ~RS_None); - return; - } - for (i = 0; i < nargs; i++) - switch (arg[i]) { - case 0: - scr_rendition(0, ~RS_None); - break; - case 1: - scr_rendition(1, RS_Bold); - break; - case 4: - scr_rendition(1, RS_Uline); - break; - case 5: - scr_rendition(1, RS_Blink); - break; - case 7: - scr_rendition(1, RS_RVid); - break; - case 22: - scr_rendition(0, RS_Bold); - break; - case 24: - scr_rendition(0, RS_Uline); - break; - case 25: - scr_rendition(0, RS_Blink); - break; - case 27: - scr_rendition(0, RS_RVid); - break; - - case 30: - case 31: /* set fg color */ - case 32: - case 33: - case 34: - case 35: - case 36: - case 37: - scr_color(minColor + (arg[i] - 30), RS_Bold); - break; - case 39: /* default fg */ - scr_color(restoreFG, RS_Bold); - break; - - case 40: - case 41: /* set bg color */ - case 42: - case 43: - case 44: - case 45: - case 46: - case 47: - scr_color(minColor + (arg[i] - 40), RS_Blink); - break; - case 49: /* default bg */ - scr_color(restoreBG, RS_Blink); - break; + if (nargs == 0) { + scr_rendition(0, ~RS_None); + return; } + for (i = 0; i < nargs; i++) + switch (arg[i]) { + case 0: + scr_rendition(0, ~RS_None); + break; + case 1: + scr_rendition(1, RS_Bold); + break; + case 4: + scr_rendition(1, RS_Uline); + break; + case 5: + scr_rendition(1, RS_Blink); + break; + case 7: + scr_rendition(1, RS_RVid); + break; + case 22: + scr_rendition(0, RS_Bold); + break; + case 24: + scr_rendition(0, RS_Uline); + break; + case 25: + scr_rendition(0, RS_Blink); + break; + case 27: + scr_rendition(0, RS_RVid); + break; + + case 30: + case 31: /* set fg color */ + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + scr_color(minColor + (arg[i] - 30), RS_Bold); + break; + case 39: /* default fg */ + scr_color(restoreFG, RS_Bold); + break; + + case 40: + case 41: /* set bg color */ + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + scr_color(minColor + (arg[i] - 40), RS_Blink); + break; + case 49: /* default bg */ + scr_color(restoreBG, RS_Blink); + break; + } } /* find if fg/bg matches any of the normal (low-intensity) colors */ @@ -1634,129 +1632,130 @@ process_sgr_mode(unsigned int nargs, int arg[]) void set_colorfgbg(void) { - unsigned int i; - static char *colorfgbg_env = NULL; - char *p; - int fg = -1, bg = -1; + unsigned int i; + static char *colorfgbg_env = NULL; + char *p; + int fg = -1, bg = -1; - if (!colorfgbg_env) { - colorfgbg_env = (char *) MALLOC(30); - strcpy(colorfgbg_env, "COLORFGBG=default;default;bg"); - } - for (i = BlackColor; i <= WhiteColor; i++) { - if (PixColors[fgColor] == PixColors[i]) { - fg = (i - BlackColor); - break; + if (!colorfgbg_env) { + colorfgbg_env = (char *) MALLOC(30); + strcpy(colorfgbg_env, "COLORFGBG=default;default;bg"); } - } - for (i = BlackColor; i <= WhiteColor; i++) { - if (PixColors[bgColor] == PixColors[i]) { - bg = (i - BlackColor); - break; + for (i = BlackColor; i <= WhiteColor; i++) { + if (PixColors[fgColor] == PixColors[i]) { + fg = (i - BlackColor); + break; + } + } + for (i = BlackColor; i <= WhiteColor; i++) { + if (PixColors[bgColor] == PixColors[i]) { + bg = (i - BlackColor); + break; + } } - } - p = strchr(colorfgbg_env, '='); - p++; - if (fg >= 0) - sprintf(p, "%d;", fg); - else - strcpy(p, "default;"); - p = strchr(p, '\0'); - if (bg >= 0) - sprintf(p, + p = strchr(colorfgbg_env, '='); + p++; + if (fg >= 0) + sprintf(p, "%d;", fg); + else + strcpy(p, "default;"); + p = strchr(p, '\0'); + if (bg >= 0) + sprintf(p, # ifdef PIXMAP_SUPPORT - "default;" + "default;" # endif - "%d", bg); - else - strcpy(p, "default"); - putenv(colorfgbg_env); + "%d", bg); + else + strcpy(p, "default"); + putenv(colorfgbg_env); - colorfgbg = DEFAULT_RSTYLE; - for (i = minColor; i <= maxColor; i++) { - if (PixColors[fgColor] == PixColors[i] + colorfgbg = DEFAULT_RSTYLE; + for (i = minColor; i <= maxColor; i++) { + if (PixColors[fgColor] == PixColors[i] # ifndef NO_BOLDUNDERLINE - && PixColors[fgColor] == PixColors[colorBD] -# endif /* NO_BOLDUNDERLINE */ - /* if we wanted boldFont to have precedence */ -# if 0 /* ifndef NO_BOLDFONT */ - && TermWin.boldFont == NULL -# endif /* NO_BOLDFONT */ - ) - colorfgbg = SET_FGCOLOR(colorfgbg, i); - if (PixColors[bgColor] == PixColors[i]) - colorfgbg = SET_BGCOLOR(colorfgbg, i); - } + && PixColors[fgColor] == PixColors[colorBD] +# endif /* NO_BOLDUNDERLINE */ + /* if we wanted boldFont to have precedence */ +# if 0 /* ifndef NO_BOLDFONT */ + && TermWin.boldFont == NULL +# endif /* NO_BOLDFONT */ + ) + colorfgbg = SET_FGCOLOR(colorfgbg, i); + if (PixColors[bgColor] == PixColors[i]) + colorfgbg = SET_BGCOLOR(colorfgbg, i); + } } #endif /* NO_BRIGHTCOLOR */ void set_title(const char *str) { - static char *name = NULL; + static char *name = NULL; - if (!str) { - str = APL_NAME "-" VERSION; - } - if (name == NULL || strcmp(name, str)) { - if (name != NULL) { - FREE(name); + if (!str) { + str = APL_NAME "-" VERSION; + } + if (name == NULL || strcmp(name, str)) { + if (name != NULL) { + FREE(name); + } + D_X11(("Setting window title to \"%s\"\n", str)); + XStoreName(Xdisplay, TermWin.parent, str); + name = STRDUP(str); } - D_X11(("Setting window title to \"%s\"\n", str)); - XStoreName(Xdisplay, TermWin.parent, str); - name = STRDUP(str); - } } void set_icon_name(const char *str) { - static char *name = NULL; + static char *name = NULL; - if (!str) str = APL_NAME "-" VERSION; - if (name == NULL || strcmp(name, str)) { - if (name != NULL) { - FREE(name); + if (!str) + str = APL_NAME "-" VERSION; + if (name == NULL || strcmp(name, str)) { + if (name != NULL) { + FREE(name); + } + D_X11(("Setting window icon name to \"%s\"\n", str)); + XSetIconName(Xdisplay, TermWin.parent, str); + name = STRDUP(str); } - D_X11(("Setting window icon name to \"%s\"\n", str)); - XSetIconName(Xdisplay, TermWin.parent, str); - name = STRDUP(str); - } } void append_to_title(const char *str) { - char *name, *buff; + char *name, *buff; - REQUIRE(str != NULL); + REQUIRE(str != NULL); - XFetchName(Xdisplay, TermWin.parent, &name); - if (name != NULL) { - buff = (char *) MALLOC(strlen(name) + strlen(str) + 1); - strcpy(buff, name); - strcat(buff, str); - set_title(buff); - FREE(buff); - } + XFetchName(Xdisplay, TermWin.parent, &name); + if (name != NULL) { + buff = (char *) MALLOC(strlen(name) + strlen(str) + 1); + strcpy(buff, name); + strcat(buff, str); + set_title(buff); + FREE(buff); + } } void append_to_icon_name(const char *str) { - char *name, *buff; + char *name, *buff; - REQUIRE(str != NULL); + REQUIRE(str != NULL); - XGetIconName(Xdisplay, TermWin.parent, &name); - if (name != NULL) { - buff = (char *) MALLOC(strlen(name) + strlen(str) + 1); - strcpy(buff, name); - strcat(buff, str); - set_icon_name(buff); - FREE(buff); - } + XGetIconName(Xdisplay, TermWin.parent, &name); + if (name != NULL) { + buff = (char *) MALLOC(strlen(name) + strlen(str) + 1); + strcpy(buff, name); + strcat(buff, str); + set_icon_name(buff); + FREE(buff); + } } /* @@ -1780,601 +1779,635 @@ void xterm_seq(int op, const char *str) { - XColor xcol; - char *nstr, *tnstr, *valptr; - unsigned char eterm_seq_op; - XWMHints *wm_hints; + XColor xcol; + char *nstr, *tnstr, *valptr; + unsigned char eterm_seq_op; + XWMHints *wm_hints; #ifdef PIXMAP_SUPPORT - unsigned char changed = 0, scaled = 0, which = 0; - char *color, *mod, *orig_tnstr; + unsigned char changed = 0, scaled = 0, which = 0; + char *color, *mod, *orig_tnstr; #endif - if (!str) - return; + if (!str) + return; - tnstr = STRDUP(str); + tnstr = STRDUP(str); #ifdef PIXMAP_SUPPORT - orig_tnstr = tnstr; + orig_tnstr = tnstr; #endif - switch (op) { - case XTerm_title: - set_title(str); - break; - case XTerm_prop: - if ((nstr = (char *) strsep(&tnstr, ";")) == NULL) { - break; - } - if ((valptr = strchr(nstr, '=')) != NULL) { - *(valptr++) = 0; - } - set_text_property(TermWin.parent, nstr, valptr); - break; - case XTerm_name: - set_title(str); /* drop */ - case XTerm_iconName: - set_icon_name(str); - break; - case XTerm_Takeover: - XSetInputFocus(Xdisplay, TermWin.parent, RevertToParent, CurrentTime); - XRaiseWindow(Xdisplay, TermWin.parent); - break; - - case XTerm_EtermSeq: - - /* Eterm proprietary escape sequences. See technical reference for details. */ - D_CMD(("Got XTerm_EtermSeq sequence\n")); - nstr = (char *) strsep(&tnstr, ";"); - eterm_seq_op = (unsigned char) strtol(nstr, (char **) NULL, 10); - D_CMD((" XTerm_EtermSeq operation is %d\n", eterm_seq_op)); - /* Yes, there is order to the numbers for this stuff. And here it is: - 0-9 Image Class/Mode Configuration - 10-19 Scrollbar/Buttonbar/Menu Configuration - 20-39 Miscellaneous Toggles - 40-49 Foreground/Background Color Configuration - 50-69 Window/Window Manager Configuration/Interaction - 70+ Internal Eterm Operations - */ - switch (eterm_seq_op) { -#ifdef PIXMAP_SUPPORT - case 0: - nstr = (char *) strsep(&tnstr, ";"); - if (nstr) { - if (BOOL_OPT_ISTRUE(nstr)) { - D_CMD((" Request to enable transparency.\n")); - FOREACH_IMAGE(if (!image_mode_is(idx, MODE_TRANS) && image_mode_is(idx, ALLOW_TRANS)) { \ - image_set_mode(idx, MODE_TRANS); \ - if (images[idx].current->pmap->pixmap != None) { \ - imlib_free_pixmap_and_mask(images[idx].current->pmap->pixmap); \ - } \ - images[idx].current->pmap->pixmap = None; \ - }); - } else if (BOOL_OPT_ISFALSE(nstr)) { - D_CMD((" Request to disable transparency.\n")); - FOREACH_IMAGE(if (image_mode_is(idx, MODE_TRANS)) {if (image_mode_is(idx, ALLOW_IMAGE)) {image_set_mode(idx, MODE_IMAGE);} \ - else {image_set_mode(idx, MODE_SOLID);}}); - } else { - D_CMD((" Bad boolean value in transparency request.\n")); + switch (op) { + case XTerm_title: + set_title(str); + break; + case XTerm_prop: + if ((nstr = (char *) strsep(&tnstr, ";")) == NULL) { break; - } - } else { - D_CMD((" Request to toggle transparency.\n")); - FOREACH_IMAGE(if (!image_mode_is(idx, MODE_TRANS) && image_mode_is(idx, ALLOW_TRANS)) { \ - image_set_mode(idx, MODE_TRANS); \ - if (images[idx].current->pmap->pixmap != None) { \ - imlib_free_pixmap_and_mask(images[idx].current->pmap->pixmap); \ - } \ - images[idx].current->pmap->pixmap = None; \ - } else if (image_mode_is(idx, MODE_TRANS)) {if (image_mode_is(idx, ALLOW_IMAGE)) {image_set_mode(idx, MODE_IMAGE);} \ - else {image_set_mode(idx, MODE_SOLID);}}); } - redraw_all_images(); - break; - case 1: - changed = 0; - for (; 1;) { - if ((color = (char *) strsep(&tnstr, ";")) == NULL) { + if ((valptr = strchr(nstr, '=')) != NULL) { + *(valptr++) = 0; + } + set_text_property(TermWin.parent, nstr, valptr); + break; + case XTerm_name: + set_title(str); /* drop */ + case XTerm_iconName: + set_icon_name(str); + break; + case XTerm_Takeover: + XSetInputFocus(Xdisplay, TermWin.parent, RevertToParent, CurrentTime); + XRaiseWindow(Xdisplay, TermWin.parent); + break; + + case XTerm_EtermSeq: + + /* Eterm proprietary escape sequences. See technical reference for details. */ + D_CMD(("Got XTerm_EtermSeq sequence\n")); + nstr = (char *) strsep(&tnstr, ";"); + eterm_seq_op = (unsigned char) strtol(nstr, (char **) NULL, 10); + D_CMD((" XTerm_EtermSeq operation is %d\n", eterm_seq_op)); + /* Yes, there is order to the numbers for this stuff. And here it is: + 0-9 Image Class/Mode Configuration + 10-19 Scrollbar/Buttonbar/Menu Configuration + 20-39 Miscellaneous Toggles + 40-49 Foreground/Background Color Configuration + 50-69 Window/Window Manager Configuration/Interaction + 70+ Internal Eterm Operations + */ + switch (eterm_seq_op) { +#ifdef PIXMAP_SUPPORT + case 0: + nstr = (char *) strsep(&tnstr, ";"); + if (nstr) { + if (BOOL_OPT_ISTRUE(nstr)) { + D_CMD((" Request to enable transparency.\n")); + /* *INDENT-OFF* */ + FOREACH_IMAGE( + if (!image_mode_is(idx, MODE_TRANS) && image_mode_is(idx, ALLOW_TRANS)) { + image_set_mode(idx, MODE_TRANS); + if (images[idx].current->pmap->pixmap != None) { + imlib_free_pixmap_and_mask(images[idx].current->pmap->pixmap); + } + images[idx].current->pmap->pixmap = None; + } + ); + /* *INDENT-ON* */ + } else if (BOOL_OPT_ISFALSE(nstr)) { + D_CMD((" Request to disable transparency.\n")); + /* *INDENT-OFF* */ + FOREACH_IMAGE( + if (image_mode_is(idx, MODE_TRANS)) { + if (image_mode_is(idx, ALLOW_IMAGE)) { + image_set_mode(idx, MODE_IMAGE); + } else { + image_set_mode(idx, MODE_SOLID); + } + } + ); + /* *INDENT-ON* */ + } else { + D_CMD((" Bad boolean value in transparency request.\n")); + break; + } + } else { + D_CMD((" Request to toggle transparency.\n")); + /* *INDENT-OFF* */ + FOREACH_IMAGE( + if (!image_mode_is(idx, MODE_TRANS) && image_mode_is(idx, ALLOW_TRANS)) { + image_set_mode(idx, MODE_TRANS); + if (images[idx].current->pmap->pixmap != None) { + imlib_free_pixmap_and_mask(images[idx].current->pmap->pixmap); + } + images[idx].current->pmap->pixmap = None; + } else if (image_mode_is(idx, MODE_TRANS)) { + if (image_mode_is(idx, ALLOW_IMAGE)) { + image_set_mode(idx, MODE_IMAGE); + } else { + image_set_mode(idx, MODE_SOLID); + } + } + ); + /* *INDENT-ON* */ + } + redraw_all_images(); break; - } - which = image_max; - FOREACH_IMAGE(if (!strcasecmp(color, (get_image_type(idx) + 6))) {which = idx; break;}); - if (which != image_max) { - if ((color = (char *) strsep(&tnstr, ";")) == NULL) { + case 1: + changed = 0; + for (; 1;) { + if ((color = (char *) strsep(&tnstr, ";")) == NULL) { + break; + } + which = image_max; + FOREACH_IMAGE(if (!strcasecmp(color, (get_image_type(idx) + 6))) { + which = idx; break;} + ); + if (which != image_max) { + if ((color = (char *) strsep(&tnstr, ";")) == NULL) { + break; + } + } else { + which = image_bg; + } + if ((mod = (char *) strsep(&tnstr, ";")) == NULL) { + break; + } + if (!strcasecmp(mod, "clear")) { + imlib_t *iml = images[which].current->iml; + + D_CMD(("Clearing the %s color modifier of the %s image\n", color, get_image_type(which))); + if (!strcasecmp(color, "image")) { + FREE(iml->mod); + } else if (!strcasecmp(color, "red")) { + FREE(iml->rmod); + } else if (!strcasecmp(color, "green")) { + FREE(iml->gmod); + } else if (!strcasecmp(color, "blue")) { + FREE(iml->bmod); + } +# ifdef PIXMAP_OFFSET + if (image_mode_is(which, MODE_TRANS) && (desktop_pixmap != None)) { + free_desktop_pixmap(); + } else if (image_mode_is(which, MODE_VIEWPORT) && (viewport_pixmap != None)) { + LIBAST_X_FREE_PIXMAP(viewport_pixmap); + viewport_pixmap = None; /* Force the re-read */ + } +# endif + changed = 1; + continue; + } + if ((valptr = (char *) strsep(&tnstr, ";")) == NULL) { + break; + } + D_CMD(("Modifying the %s attribute of the %s color modifier of the %s image to be %s\n", mod, color, + get_image_type(which), valptr)); + changed = 1; +# ifdef PIXMAP_OFFSET + if (image_mode_is(which, MODE_TRANS) && (desktop_pixmap != None)) { + free_desktop_pixmap(); + } else if (image_mode_is(which, MODE_VIEWPORT) && (viewport_pixmap != None)) { + LIBAST_X_FREE_PIXMAP(viewport_pixmap); + viewport_pixmap = None; /* Force the re-read */ + } +# endif + if (!strcasecmp(color, "image")) { + imlib_t *iml = images[which].current->iml; + + if (iml->mod == NULL) { + iml->mod = create_colormod(); + } + if (!BEG_STRCASECMP("brightness", mod)) { + iml->mod->brightness = (int) strtol(valptr, (char **) NULL, 0); + } else if (!BEG_STRCASECMP("contrast", mod)) { + iml->mod->contrast = (int) strtol(valptr, (char **) NULL, 0); + } else if (!BEG_STRCASECMP("gamma", mod)) { + iml->mod->gamma = (int) strtol(valptr, (char **) NULL, 0); + } + update_cmod(iml->mod); + reload_image(iml); + update_cmod_tables(iml); + + } else if (!strcasecmp(color, "red")) { + imlib_t *iml = images[which].current->iml; + + if (iml->rmod == NULL) { + iml->rmod = create_colormod(); + } + if (!BEG_STRCASECMP("brightness", mod)) { + iml->rmod->brightness = (int) strtol(valptr, (char **) NULL, 0); + } else if (!BEG_STRCASECMP("contrast", mod)) { + iml->rmod->contrast = (int) strtol(valptr, (char **) NULL, 0); + } else if (!BEG_STRCASECMP("gamma", mod)) { + iml->rmod->gamma = (int) strtol(valptr, (char **) NULL, 0); + } + update_cmod(iml->rmod); + reload_image(iml); + update_cmod_tables(iml); + + } else if (!strcasecmp(color, "green")) { + imlib_t *iml = images[which].current->iml; + + if (iml->gmod == NULL) { + iml->gmod = create_colormod(); + } + if (!BEG_STRCASECMP("brightness", mod)) { + iml->gmod->brightness = (int) strtol(valptr, (char **) NULL, 0); + } else if (!BEG_STRCASECMP("contrast", mod)) { + iml->gmod->contrast = (int) strtol(valptr, (char **) NULL, 0); + } else if (!BEG_STRCASECMP("gamma", mod)) { + iml->gmod->gamma = (int) strtol(valptr, (char **) NULL, 0); + } + update_cmod(iml->gmod); + reload_image(iml); + update_cmod_tables(iml); + + } else if (!strcasecmp(color, "blue")) { + imlib_t *iml = images[which].current->iml; + + if (iml->bmod == NULL) { + iml->bmod = create_colormod(); + } + if (!BEG_STRCASECMP("brightness", mod)) { + iml->bmod->brightness = (int) strtol(valptr, (char **) NULL, 0); + } else if (!BEG_STRCASECMP("contrast", mod)) { + iml->bmod->contrast = (int) strtol(valptr, (char **) NULL, 0); + } else if (!BEG_STRCASECMP("gamma", mod)) { + iml->bmod->gamma = (int) strtol(valptr, (char **) NULL, 0); + } + update_cmod(iml->bmod); + reload_image(iml); + update_cmod_tables(iml); + } + } + if (changed) { + redraw_all_images(); + } break; - } - } else { - which = image_bg; - } - if ((mod = (char *) strsep(&tnstr, ";")) == NULL) { - break; - } - if (!strcasecmp(mod, "clear")) { - imlib_t *iml = images[which].current->iml; + case 2: + changed = 0; + which = image_max; + if ((nstr = (char *) strsep(&tnstr, ";")) == NULL || (valptr = (char *) strsep(&tnstr, ";")) == NULL) { + break; + } + FOREACH_IMAGE(if (!strcasecmp(valptr, (get_image_type(idx) + 6))) { + which = idx; break;} + ); + if (which != image_max) { + if ((valptr = (char *) strsep(&tnstr, ";")) == NULL) { + break; + } + } else { + which = image_bg; + } + D_PIXMAP(("Operation == \"%s\", which == %d, value == \"%s\"\n", nstr, (int) which, valptr)); + if (!strcasecmp(nstr, "shade")) { + imlib_t *iml = images[which].current->iml; + int s; - D_CMD(("Clearing the %s color modifier of the %s image\n", color, get_image_type(which))); - if (!strcasecmp(color, "image")) { - FREE(iml->mod); - } else if (!strcasecmp(color, "red")) { - FREE(iml->rmod); - } else if (!strcasecmp(color, "green")) { - FREE(iml->gmod); - } else if (!strcasecmp(color, "blue")) { - FREE(iml->bmod); - } + s = (int) strtol(valptr, (char **) NULL, 0); + s = ((100 - s) << 8) / 100; + if (s == 0x100) { + if (iml->mod != NULL) { + if (iml->mod->brightness != 0x100) { + iml->mod->brightness = 0x100; + changed = 1; + } + if (iml->mod->contrast == 0x100 && iml->mod->gamma == 0x100) { + FREE(iml->mod); + } + } + } else { + if (iml->mod == NULL) { + iml->mod = create_colormod(); + } + if (iml->mod->brightness != s) { + iml->mod->brightness = s; + changed = 1; + } + } + } else if (!strcasecmp(nstr, "tint")) { + imlib_t *iml = images[which].current->iml; + unsigned long t, r, g, b; + + if (!isdigit(*valptr)) { + t = get_tint_by_color_name(valptr); + } else { + t = (unsigned long) strtoul(valptr, (char **) NULL, 0); + D_PIXMAP(("Got numerical tint 0x%06x\n", t)); + } + r = (t & 0xff0000) >> 16; + if (r == 0xff) { + if (iml->rmod != NULL) { + if (iml->rmod->brightness != 0x100) { + iml->rmod->brightness = 0x100; + changed = 1; + if (iml->rmod->contrast == 0x100 && iml->rmod->gamma == 0x100) { + FREE(iml->rmod); + } + } + } + } else { + if (iml->rmod == NULL) { + iml->rmod = create_colormod(); + } + if (iml->rmod->brightness != (int) r) { + iml->rmod->brightness = r; + changed = 1; + } + } + g = (t & 0xff00) >> 8; + if (g == 0xff) { + if (iml->gmod != NULL) { + if (iml->gmod->brightness != 0x100) { + iml->gmod->brightness = 0x100; + changed = 1; + if (iml->gmod->contrast == 0x100 && iml->gmod->gamma == 0x100) { + FREE(iml->gmod); + } + } + } + } else { + if (iml->gmod == NULL) { + iml->gmod = create_colormod(); + } + if (iml->gmod->brightness != (int) g) { + iml->gmod->brightness = g; + changed = 1; + } + } + b = t & 0xff; + if (b == 0xff) { + if (iml->bmod != NULL) { + if (iml->bmod->brightness != 0x100) { + iml->bmod->brightness = 0x100; + changed = 1; + if (iml->bmod->contrast == 0x100 && iml->bmod->gamma == 0x100) { + FREE(iml->bmod); + } + } + } + } else { + if (iml->bmod == NULL) { + iml->bmod = create_colormod(); + iml->bmod->contrast = iml->bmod->gamma = 0x100; + } + if (iml->bmod->brightness != (int) b) { + iml->bmod->brightness = b; + changed = 1; + } + } + } + if (changed) { + if (image_mode_is(which, MODE_TRANS)) { + free_desktop_pixmap(); + } + redraw_image(which); + } + break; + case 3: # ifdef PIXMAP_OFFSET - if (image_mode_is(which, MODE_TRANS) && (desktop_pixmap != None)) { - free_desktop_pixmap(); - } else if (image_mode_is(which, MODE_VIEWPORT) && (viewport_pixmap != None)) { - LIBAST_X_FREE_PIXMAP(viewport_pixmap); - viewport_pixmap = None; /* Force the re-read */ - } + get_desktop_window(); + if (desktop_window == None) { + FOREACH_IMAGE(if (image_mode_is(idx, MODE_TRANS)) { + image_set_mode(idx, MODE_IMAGE); image_allow_mode(idx, ALLOW_IMAGE);} + ); + break; + } + get_desktop_pixmap(); + redraw_images_by_mode(MODE_TRANS | MODE_VIEWPORT); # endif - changed = 1; - continue; - } - if ((valptr = (char *) strsep(&tnstr, ";")) == NULL) { - break; - } - D_CMD(("Modifying the %s attribute of the %s color modifier of the %s image to be %s\n", mod, color, get_image_type(which), valptr)); - changed = 1; -# ifdef PIXMAP_OFFSET - if (image_mode_is(which, MODE_TRANS) && (desktop_pixmap != None)) { - free_desktop_pixmap(); - } else if (image_mode_is(which, MODE_VIEWPORT) && (viewport_pixmap != None)) { - LIBAST_X_FREE_PIXMAP(viewport_pixmap); - viewport_pixmap = None; /* Force the re-read */ - } -# endif - if (!strcasecmp(color, "image")) { - imlib_t *iml = images[which].current->iml; - - if (iml->mod == NULL) { - iml->mod = create_colormod(); - } - if (!BEG_STRCASECMP("brightness", mod)) { - iml->mod->brightness = (int) strtol(valptr, (char **) NULL, 0); - } else if (!BEG_STRCASECMP("contrast", mod)) { - iml->mod->contrast = (int) strtol(valptr, (char **) NULL, 0); - } else if (!BEG_STRCASECMP("gamma", mod)) { - iml->mod->gamma = (int) strtol(valptr, (char **) NULL, 0); - } - update_cmod(iml->mod); - reload_image(iml); - update_cmod_tables(iml); - - } else if (!strcasecmp(color, "red")) { - imlib_t *iml = images[which].current->iml; - - if (iml->rmod == NULL) { - iml->rmod = create_colormod(); - } - if (!BEG_STRCASECMP("brightness", mod)) { - iml->rmod->brightness = (int) strtol(valptr, (char **) NULL, 0); - } else if (!BEG_STRCASECMP("contrast", mod)) { - iml->rmod->contrast = (int) strtol(valptr, (char **) NULL, 0); - } else if (!BEG_STRCASECMP("gamma", mod)) { - iml->rmod->gamma = (int) strtol(valptr, (char **) NULL, 0); - } - update_cmod(iml->rmod); - reload_image(iml); - update_cmod_tables(iml); - - } else if (!strcasecmp(color, "green")) { - imlib_t *iml = images[which].current->iml; - - if (iml->gmod == NULL) { - iml->gmod = create_colormod(); - } - if (!BEG_STRCASECMP("brightness", mod)) { - iml->gmod->brightness = (int) strtol(valptr, (char **) NULL, 0); - } else if (!BEG_STRCASECMP("contrast", mod)) { - iml->gmod->contrast = (int) strtol(valptr, (char **) NULL, 0); - } else if (!BEG_STRCASECMP("gamma", mod)) { - iml->gmod->gamma = (int) strtol(valptr, (char **) NULL, 0); - } - update_cmod(iml->gmod); - reload_image(iml); - update_cmod_tables(iml); - - } else if (!strcasecmp(color, "blue")) { - imlib_t *iml = images[which].current->iml; - - if (iml->bmod == NULL) { - iml->bmod = create_colormod(); - } - if (!BEG_STRCASECMP("brightness", mod)) { - iml->bmod->brightness = (int) strtol(valptr, (char **) NULL, 0); - } else if (!BEG_STRCASECMP("contrast", mod)) { - iml->bmod->contrast = (int) strtol(valptr, (char **) NULL, 0); - } else if (!BEG_STRCASECMP("gamma", mod)) { - iml->bmod->gamma = (int) strtol(valptr, (char **) NULL, 0); - } - update_cmod(iml->bmod); - reload_image(iml); - update_cmod_tables(iml); - } - } - if (changed) { - redraw_all_images(); - } - break; - case 2: - changed = 0; - which = image_max; - if ((nstr = (char *) strsep(&tnstr, ";")) == NULL || (valptr = (char *) strsep(&tnstr, ";")) == NULL) { - break; - } - FOREACH_IMAGE(if (!strcasecmp(valptr, (get_image_type(idx) + 6))) {which = idx; break;}); - if (which != image_max) { - if ((valptr = (char *) strsep(&tnstr, ";")) == NULL) { - break; - } - } else { - which = image_bg; - } - D_PIXMAP(("Operation == \"%s\", which == %d, value == \"%s\"\n", nstr, (int) which, valptr)); - if (!strcasecmp(nstr, "shade")) { - imlib_t *iml = images[which].current->iml; - int s; - - s = (int) strtol(valptr, (char **) NULL, 0); - s = ((100 - s) << 8) / 100; - if (s == 0x100) { - if (iml->mod != NULL) { - if (iml->mod->brightness != 0x100) { - iml->mod->brightness = 0x100; - changed = 1; - } - if (iml->mod->contrast == 0x100 && iml->mod->gamma == 0x100) { - FREE(iml->mod); - } - } - } else { - if (iml->mod == NULL) { - iml->mod = create_colormod(); - } - if (iml->mod->brightness != s) { - iml->mod->brightness = s; - changed = 1; - } - } - } else if (!strcasecmp(nstr, "tint")) { - imlib_t *iml = images[which].current->iml; - unsigned long t, r, g, b; - - if (!isdigit(*valptr)) { - t = get_tint_by_color_name(valptr); - } else { - t = (unsigned long) strtoul(valptr, (char **) NULL, 0); - D_PIXMAP(("Got numerical tint 0x%06x\n", t)); - } - r = (t & 0xff0000) >> 16; - if (r == 0xff) { - if (iml->rmod != NULL) { - if (iml->rmod->brightness != 0x100) { - iml->rmod->brightness = 0x100; - changed = 1; - if (iml->rmod->contrast == 0x100 && iml->rmod->gamma == 0x100) { - FREE(iml->rmod); - } - } - } - } else { - if (iml->rmod == NULL) { - iml->rmod = create_colormod(); - } - if (iml->rmod->brightness != (int) r) { - iml->rmod->brightness = r; - changed = 1; - } - } - g = (t & 0xff00) >> 8; - if (g == 0xff) { - if (iml->gmod != NULL) { - if (iml->gmod->brightness != 0x100) { - iml->gmod->brightness = 0x100; - changed = 1; - if (iml->gmod->contrast == 0x100 && iml->gmod->gamma == 0x100) { - FREE(iml->gmod); - } - } - } - } else { - if (iml->gmod == NULL) { - iml->gmod = create_colormod(); - } - if (iml->gmod->brightness != (int) g) { - iml->gmod->brightness = g; - changed = 1; - } - } - b = t & 0xff; - if (b == 0xff) { - if (iml->bmod != NULL) { - if (iml->bmod->brightness != 0x100) { - iml->bmod->brightness = 0x100; - changed = 1; - if (iml->bmod->contrast == 0x100 && iml->bmod->gamma == 0x100) { - FREE(iml->bmod); - } - } - } - } else { - if (iml->bmod == NULL) { - iml->bmod = create_colormod(); - iml->bmod->contrast = iml->bmod->gamma = 0x100; - } - if (iml->bmod->brightness != (int) b) { - iml->bmod->brightness = b; - changed = 1; - } - } - } - if (changed) { - if (image_mode_is(which, MODE_TRANS)) { - free_desktop_pixmap(); - } - redraw_image(which); - } - break; - case 3: -# ifdef PIXMAP_OFFSET - get_desktop_window(); - if (desktop_window == None) { - FOREACH_IMAGE(if (image_mode_is(idx, MODE_TRANS)) {image_set_mode(idx, MODE_IMAGE); image_allow_mode(idx, ALLOW_IMAGE);}); - break; - } - get_desktop_pixmap(); - redraw_images_by_mode(MODE_TRANS | MODE_VIEWPORT); -# endif - break; + break; #endif - case 10: - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr) { - if (!strcasecmp(nstr, "xterm")) { + case 10: + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr) { + if (!strcasecmp(nstr, "xterm")) { #ifdef XTERM_SCROLLBAR - scrollbar_change_type(SCROLLBAR_XTERM); + scrollbar_change_type(SCROLLBAR_XTERM); #else - print_error("Support for xterm scrollbars was not compiled in. Sorry.\n"); + print_error("Support for xterm scrollbars was not compiled in. Sorry.\n"); #endif - } else if (!strcasecmp(nstr, "next")) { + } else if (!strcasecmp(nstr, "next")) { #ifdef NEXT_SCROLLBAR - scrollbar_change_type(SCROLLBAR_NEXT); + scrollbar_change_type(SCROLLBAR_NEXT); #else - print_error("Support for NeXT scrollbars was not compiled in. Sorry.\n"); + print_error("Support for NeXT scrollbars was not compiled in. Sorry.\n"); #endif - } else if (!strcasecmp(nstr, "motif")) { + } else if (!strcasecmp(nstr, "motif")) { #ifdef MOTIF_SCROLLBAR - scrollbar_change_type(SCROLLBAR_MOTIF); + scrollbar_change_type(SCROLLBAR_MOTIF); #else - print_error("Support for motif scrollbars was not compiled in. Sorry.\n"); + print_error("Support for motif scrollbars was not compiled in. Sorry.\n"); #endif - } else { - print_error("Unrecognized scrollbar type \"%s\".\n", nstr); - } - } - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr) { - scrollbar_change_width((unsigned short) strtoul(nstr, (char **) NULL, 0)); - } - break; - case 11: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_scrollbar_right); - scr_touch(); - parent_resize(); - break; - case 12: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_scrollbar_floating); - scrollbar_reposition_and_always_draw(); - break; - case 13: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_scrollbar_popup); - break; - case 14: - nstr = (char *) strsep(&tnstr, ";"); - if (!(nstr) || !(*(nstr))) { - bbar_show_all(-1); - parent_resize(); - } else if (BOOL_OPT_ISTRUE(nstr)) { - bbar_show_all(1); - parent_resize(); - } else if (BOOL_OPT_ISFALSE(nstr)) { - bbar_show_all(0); - parent_resize(); - } - break; - case 20: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_visual_bell); - break; + } else { + print_error("Unrecognized scrollbar type \"%s\".\n", nstr); + } + } + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr) { + scrollbar_change_width((unsigned short) strtoul(nstr, (char **) NULL, 0)); + } + break; + case 11: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_scrollbar_right); + scr_touch(); + parent_resize(); + break; + case 12: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_scrollbar_floating); + scrollbar_reposition_and_always_draw(); + break; + case 13: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_scrollbar_popup); + break; + case 14: + nstr = (char *) strsep(&tnstr, ";"); + if (!(nstr) || !(*(nstr))) { + bbar_show_all(-1); + parent_resize(); + } else if (BOOL_OPT_ISTRUE(nstr)) { + bbar_show_all(1); + parent_resize(); + } else if (BOOL_OPT_ISFALSE(nstr)) { + bbar_show_all(0); + parent_resize(); + } + break; + case 20: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_visual_bell); + break; #ifdef MAPALERT_OPTION - case 21: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_map_alert); - break; + case 21: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_map_alert); + break; #endif - case 22: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_xterm_select); - break; - case 23: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_select_whole_line); - break; - case 24: - nstr = (char *) strsep(&tnstr, ";"); - FOREACH_IMAGE(if (!image_mode_is(idx, MODE_VIEWPORT) && image_mode_is(idx, ALLOW_VIEWPORT)) {image_set_mode(idx, MODE_VIEWPORT);}); - redraw_images_by_mode(MODE_VIEWPORT); - break; - case 25: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_select_trailing_spaces); - break; - case 26: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_report_as_keysyms); - break; - case 27: - nstr = (char *) strsep(&tnstr, ";"); - OPT_SET_OR_TOGGLE(nstr, Options, Opt_no_input); - wm_hints = XGetWMHints(Xdisplay, TermWin.parent); - wm_hints->flags |= InputHint; - wm_hints->input = ((Options & Opt_no_input) ? False : True); - XSetWMHints(Xdisplay, TermWin.parent, wm_hints); - XFree(wm_hints); - break; - case 40: - nstr = (char *) strsep(&tnstr, ";"); - if (nstr) { - if (XParseColor(Xdisplay, cmap, nstr, &xcol) && XAllocColor(Xdisplay, cmap, &xcol)) { - PixColors[fgColor] = xcol.pixel; - scr_refresh(DEFAULT_REFRESH); - } - } - break; - case 41: - nstr = (char *) strsep(&tnstr, ";"); - if (nstr) { - if (XParseColor(Xdisplay, cmap, nstr, &xcol) && XAllocColor(Xdisplay, cmap, &xcol)) { - PixColors[bgColor] = xcol.pixel; - scr_refresh(DEFAULT_REFRESH); - } - } - break; - case 50: - /* Change desktops */ - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr) { - XClientMessageEvent xev; + case 22: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_xterm_select); + break; + case 23: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_select_whole_line); + break; + case 24: + nstr = (char *) strsep(&tnstr, ";"); + FOREACH_IMAGE(if (!image_mode_is(idx, MODE_VIEWPORT) && image_mode_is(idx, ALLOW_VIEWPORT)) { + image_set_mode(idx, MODE_VIEWPORT);} + ); + redraw_images_by_mode(MODE_VIEWPORT); + break; + case 25: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_select_trailing_spaces); + break; + case 26: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_report_as_keysyms); + break; + case 27: + nstr = (char *) strsep(&tnstr, ";"); + OPT_SET_OR_TOGGLE(nstr, Options, Opt_no_input); + wm_hints = XGetWMHints(Xdisplay, TermWin.parent); + wm_hints->flags |= InputHint; + wm_hints->input = ((Options & Opt_no_input) ? False : True); + XSetWMHints(Xdisplay, TermWin.parent, wm_hints); + XFree(wm_hints); + break; + case 40: + nstr = (char *) strsep(&tnstr, ";"); + if (nstr) { + if (XParseColor(Xdisplay, cmap, nstr, &xcol) && XAllocColor(Xdisplay, cmap, &xcol)) { + PixColors[fgColor] = xcol.pixel; + scr_refresh(DEFAULT_REFRESH); + } + } + break; + case 41: + nstr = (char *) strsep(&tnstr, ";"); + if (nstr) { + if (XParseColor(Xdisplay, cmap, nstr, &xcol) && XAllocColor(Xdisplay, cmap, &xcol)) { + PixColors[bgColor] = xcol.pixel; + scr_refresh(DEFAULT_REFRESH); + } + } + break; + case 50: + /* Change desktops */ + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr) { + XClientMessageEvent xev; - rs_desktop = (int) strtol(nstr, (char **) NULL, 0); - xev.type = ClientMessage; - xev.window = TermWin.parent; - xev.message_type = props[PROP_DESKTOP]; - xev.format = 32; - xev.data.l[0] = rs_desktop; - XChangeProperty(Xdisplay, TermWin.parent, xev.message_type, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &rs_desktop, 1); - XSendEvent(Xdisplay, Xroot, False, SubstructureNotifyMask, (XEvent *) & xev); - } - break; + rs_desktop = (int) strtol(nstr, (char **) NULL, 0); + xev.type = ClientMessage; + xev.window = TermWin.parent; + xev.message_type = props[PROP_DESKTOP]; + xev.format = 32; + xev.data.l[0] = rs_desktop; + XChangeProperty(Xdisplay, TermWin.parent, xev.message_type, XA_CARDINAL, 32, PropModeReplace, + (unsigned char *) &rs_desktop, 1); + XSendEvent(Xdisplay, Xroot, False, SubstructureNotifyMask, (XEvent *) & xev); + } + break; #if 0 - case 70: - /* Exit Eterm */ - exit(0); - break; - case 71: - /* Save current config */ - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr) { - valptr = (char *) strsep(&tnstr, ";"); - if (!strcasecmp(nstr, "theme")) { - save_config(valptr, SAVE_THEME_CONFIG); - } else { - save_config(valptr, SAVE_USER_CONFIG); - } - } else { - save_config(NULL, SAVE_USER_CONFIG); - } - break; + case 70: + /* Exit Eterm */ + exit(0); + break; + case 71: + /* Save current config */ + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr) { + valptr = (char *) strsep(&tnstr, ";"); + if (!strcasecmp(nstr, "theme")) { + save_config(valptr, SAVE_THEME_CONFIG); + } else { + save_config(valptr, SAVE_USER_CONFIG); + } + } else { + save_config(NULL, SAVE_USER_CONFIG); + } + break; #endif - case 72: - /* Search scrollback buffer for a string. NULL to clear. */ - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr) { - scr_search_scrollback(nstr); - } else { - scr_search_scrollback(NULL); - } - break; + case 72: + /* Search scrollback buffer for a string. NULL to clear. */ + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr) { + scr_search_scrollback(nstr); + } else { + scr_search_scrollback(NULL); + } + break; #if 0 - case 73: - /* Spawn a subprogram */ - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr) { - system_no_wait(nstr); - } - break; + case 73: + /* Spawn a subprogram */ + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr) { + system_no_wait(nstr); + } + break; #endif - case 80: - /* Set debugging level */ - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr) { - DEBUG_LEVEL = (unsigned int) strtoul(nstr, (char **) NULL, 0); - } - break; + case 80: + /* Set debugging level */ + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr) { + DEBUG_LEVEL = (unsigned int) strtoul(nstr, (char **) NULL, 0); + } + break; - default: - break; - } - break; + default: + break; + } + break; - case XTerm_Pixmap: + case XTerm_Pixmap: #ifdef PIXMAP_SUPPORT - FOREACH_IMAGE(if (!image_mode_is(idx, MODE_IMAGE) && image_mode_is(idx, ALLOW_IMAGE)) {image_set_mode(idx, MODE_IMAGE);}); - if (!strcmp(str, ";")) { - image_set_mode(image_bg, MODE_SOLID); - bg_needs_update = 1; - } else { - nstr = (char *) strsep(&tnstr, ";"); - if (nstr) { - if (*nstr) { - set_pixmap_scale("", images[image_bg].current->pmap); - bg_needs_update = 1; - load_image(nstr, images[image_bg].current); - } - while ((nstr = (char *) strsep(&tnstr, ";")) && *nstr) { - changed += set_pixmap_scale(nstr, images[image_bg].current->pmap); - scaled = 1; - } - } else { - image_set_mode(image_bg, MODE_SOLID); - bg_needs_update = 1; - } - } - if ((changed) || (bg_needs_update)) { - redraw_image(image_bg); - } + FOREACH_IMAGE(if (!image_mode_is(idx, MODE_IMAGE) && image_mode_is(idx, ALLOW_IMAGE)) { + image_set_mode(idx, MODE_IMAGE);} + ); + if (!strcmp(str, ";")) { + image_set_mode(image_bg, MODE_SOLID); + bg_needs_update = 1; + } else { + nstr = (char *) strsep(&tnstr, ";"); + if (nstr) { + if (*nstr) { + set_pixmap_scale("", images[image_bg].current->pmap); + bg_needs_update = 1; + load_image(nstr, images[image_bg].current); + } + while ((nstr = (char *) strsep(&tnstr, ";")) && *nstr) { + changed += set_pixmap_scale(nstr, images[image_bg].current->pmap); + scaled = 1; + } + } else { + image_set_mode(image_bg, MODE_SOLID); + bg_needs_update = 1; + } + } + if ((changed) || (bg_needs_update)) { + redraw_image(image_bg); + } #endif /* PIXMAP_SUPPORT */ - break; + break; - case XTerm_restoreFG: + case XTerm_restoreFG: #ifdef XTERM_COLOR_CHANGE - set_window_color(fgColor, str); + set_window_color(fgColor, str); #endif - break; - case XTerm_restoreBG: + break; + case XTerm_restoreBG: #ifdef XTERM_COLOR_CHANGE - set_window_color(bgColor, str); + set_window_color(bgColor, str); #endif - break; - case XTerm_DumpScreen: + break; + case XTerm_DumpScreen: #if 0 - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr) { - scr_dump_to_file(nstr); - } - break; + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr) { + scr_dump_to_file(nstr); + } + break; #endif - case XTerm_logfile: - nstr = (char *) strsep(&tnstr, ";"); - if (nstr && *nstr && BOOL_OPT_ISTRUE(nstr)) { - /* Logging on */ - } else { - /* Logging off */ - } - break; - case XTerm_font: - change_font(0, str); - break; - default: - D_CMD(("Unsupported xterm escape sequence operator: 0x%02x\n", op)); - break; - } + case XTerm_logfile: + nstr = (char *) strsep(&tnstr, ";"); + if (nstr && *nstr && BOOL_OPT_ISTRUE(nstr)) { + /* Logging on */ + } else { + /* Logging off */ + } + break; + case XTerm_font: + change_font(0, str); + break; + default: + D_CMD(("Unsupported xterm escape sequence operator: 0x%02x\n", op)); + break; + } #ifdef PIXMAP_SUPPORT - FREE(orig_tnstr); + FREE(orig_tnstr); #endif } diff --git a/src/timer.c b/src/timer.c index 291890a..26e4120 100644 --- a/src/timer.c +++ b/src/timer.c @@ -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); + } + } } - } } diff --git a/src/utmp.c b/src/utmp.c index 91c492e..8047636 100644 --- a/src/utmp.c +++ b/src/utmp.c @@ -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 */ } diff --git a/src/windows.c b/src/windows.c index e2bd151..31c4e80 100644 --- a/src/windows.c +++ b/src/windows.c @@ -48,265 +48,287 @@ static const char cvs_ident[] = "$Id$"; XWindowAttributes attr; XSetWindowAttributes Attributes; -XSizeHints szHint = -{ - PMinSize | PResizeInc | PBaseSize, - 0, 0, 80, 24, /* x, y, width, height */ - 1, 1, /* Min width, height */ - 0, 0, /* Max width, height - unused */ - 1, 1, /* increments: width, height */ - {1, 1}, /* increments: x, y */ - {0, 0}, /* Aspect ratio - unused */ - 0, 0, /* base size: width, height */ - NorthWestGravity /* gravity */ +XSizeHints szHint = { + PMinSize | PResizeInc | PBaseSize, + 0, 0, 80, 24, /* x, y, width, height */ + 1, 1, /* Min width, height */ + 0, 0, /* Max width, height - unused */ + 1, 1, /* increments: width, height */ + {1, 1}, /* increments: x, y */ + {0, 0}, /* Aspect ratio - unused */ + 0, 0, /* base size: width, height */ + NorthWestGravity /* gravity */ }; -Cursor TermWin_cursor; /* cursor for vt window */ +Cursor TermWin_cursor; /* cursor for vt window */ void set_text_property(Window win, char *propname, char *value) { - XTextProperty prop; - Atom atom; + XTextProperty prop; + Atom atom; - ASSERT(propname != NULL); + ASSERT(propname != NULL); - if (value == NULL) { - atom = XInternAtom(Xdisplay, propname, True); - if (atom == None) { - return; + if (value == NULL) { + atom = XInternAtom(Xdisplay, propname, True); + if (atom == None) { + return; + } + XDeleteProperty(Xdisplay, win, atom); + } else { + atom = XInternAtom(Xdisplay, propname, False); + prop.value = (unsigned char *) value; + prop.encoding = XA_STRING; + prop.format = 8; + prop.nitems = strlen(value); + XSetTextProperty(Xdisplay, win, &prop, atom); } - XDeleteProperty(Xdisplay, win, atom); - } else { - atom = XInternAtom(Xdisplay, propname, False); - prop.value = (unsigned char *) value; - prop.encoding = XA_STRING; - prop.format = 8; - prop.nitems = strlen(value); - XSetTextProperty(Xdisplay, win, &prop, atom); - } } unsigned long get_tint_by_color_name(const char *color) { - XColor wcol, xcol; - unsigned long r, g, b, t; + XColor wcol, xcol; + unsigned long r, g, b, t; - wcol.pixel = WhitePixel(Xdisplay, Xscreen); - XQueryColor(Xdisplay, cmap, &wcol); + wcol.pixel = WhitePixel(Xdisplay, Xscreen); + XQueryColor(Xdisplay, cmap, &wcol); - D_PIXMAP(("Tint string is \"%s\", white color is rgbi:%d/%d/%d\n", color, wcol.red, wcol.green, wcol.blue)); - if (!XParseColor(Xdisplay, cmap, color, &xcol)) { - print_error("Unable to parse tint color \"%s\". Ignoring.\n", color); - return 0xffffff; - } + D_PIXMAP(("Tint string is \"%s\", white color is rgbi:%d/%d/%d\n", color, wcol.red, wcol.green, wcol.blue)); + if (!XParseColor(Xdisplay, cmap, color, &xcol)) { + print_error("Unable to parse tint color \"%s\". Ignoring.\n", color); + return 0xffffff; + } - D_PIXMAP(("RGB values for color are %d/%d/%d\n", xcol.red, xcol.green, xcol.blue)); - if ((wcol.flags & DoRed) && (xcol.flags & DoRed)) { - r = (xcol.red << 8) / wcol.red; - D_PIXMAP(("Got red == %lu\n", r)); - if (r >= 0x100) r = 0xff; - } else { - r = 0xff; - } - if ((wcol.flags & DoGreen) && (xcol.flags & DoGreen)) { - g = (xcol.green << 8) / wcol.green; - D_PIXMAP(("Got green == %lu\n", g)); - if (g >= 0x100) g = 0xff; - } else { - g = 0xff; - } - if ((wcol.flags & DoBlue) && (xcol.flags & DoBlue)) { - b = (xcol.blue << 8) / wcol.blue; - D_PIXMAP(("Got blue == %lu\n", b)); - if (b >= 0x100) b = 0xff; - } else { - b = 0xff; - } - t = (r << 16) | (g << 8) | b; - D_PIXMAP(("Final tint is 0x%06x\n", t)); - return t; + D_PIXMAP(("RGB values for color are %d/%d/%d\n", xcol.red, xcol.green, xcol.blue)); + if ((wcol.flags & DoRed) && (xcol.flags & DoRed)) { + r = (xcol.red << 8) / wcol.red; + D_PIXMAP(("Got red == %lu\n", r)); + if (r >= 0x100) + r = 0xff; + } else { + r = 0xff; + } + if ((wcol.flags & DoGreen) && (xcol.flags & DoGreen)) { + g = (xcol.green << 8) / wcol.green; + D_PIXMAP(("Got green == %lu\n", g)); + if (g >= 0x100) + g = 0xff; + } else { + g = 0xff; + } + if ((wcol.flags & DoBlue) && (xcol.flags & DoBlue)) { + b = (xcol.blue << 8) / wcol.blue; + D_PIXMAP(("Got blue == %lu\n", b)); + if (b >= 0x100) + b = 0xff; + } else { + b = 0xff; + } + t = (r << 16) | (g << 8) | b; + D_PIXMAP(("Final tint is 0x%06x\n", t)); + return t; } Pixel get_bottom_shadow_color(Pixel norm_color, const char *type) { - XColor xcol; + XColor xcol; - xcol.pixel = norm_color; - XQueryColor(Xdisplay, cmap, &xcol); + xcol.pixel = norm_color; + XQueryColor(Xdisplay, cmap, &xcol); - xcol.red /= 2; - xcol.green /= 2; - xcol.blue /= 2; + xcol.red /= 2; + xcol.green /= 2; + xcol.blue /= 2; - if (!XAllocColor(Xdisplay, cmap, &xcol)) { - print_error("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map.\n", type, xcol.pixel, xcol.red, xcol.green, xcol.blue); - xcol.pixel = PixColors[minColor]; - } - return (xcol.pixel); + if (!XAllocColor(Xdisplay, cmap, &xcol)) { + print_error("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map.\n", type, xcol.pixel, xcol.red, + xcol.green, xcol.blue); + xcol.pixel = PixColors[minColor]; + } + return (xcol.pixel); } Pixel get_top_shadow_color(Pixel norm_color, const char *type) { - XColor xcol, white; + XColor xcol, white; # ifdef PREFER_24BIT - white.red = white.green = white.blue = r = g = b = ~0; - XAllocColor(Xdisplay, cmap, &white); + white.red = white.green = white.blue = r = g = b = ~0; + XAllocColor(Xdisplay, cmap, &white); # else - white.pixel = WhitePixel(Xdisplay, Xscreen); - XQueryColor(Xdisplay, cmap, &white); + white.pixel = WhitePixel(Xdisplay, Xscreen); + XQueryColor(Xdisplay, cmap, &white); # endif - xcol.pixel = norm_color; - XQueryColor(Xdisplay, cmap, &xcol); + xcol.pixel = norm_color; + XQueryColor(Xdisplay, cmap, &xcol); - xcol.red = MAX((white.red / 5), xcol.red); - xcol.green = MAX((white.green / 5), xcol.green); - xcol.blue = MAX((white.blue / 5), xcol.blue); + xcol.red = MAX((white.red / 5), xcol.red); + xcol.green = MAX((white.green / 5), xcol.green); + xcol.blue = MAX((white.blue / 5), xcol.blue); - xcol.red = MIN(white.red, (xcol.red * 7) / 5); - xcol.green = MIN(white.green, (xcol.green * 7) / 5); - xcol.blue = MIN(white.blue, (xcol.blue * 7) / 5); + xcol.red = MIN(white.red, (xcol.red * 7) / 5); + xcol.green = MIN(white.green, (xcol.green * 7) / 5); + xcol.blue = MIN(white.blue, (xcol.blue * 7) / 5); - if (!XAllocColor(Xdisplay, cmap, &xcol)) { - print_error("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map.\n", type, xcol.pixel, xcol.red, xcol.green, xcol.blue); - xcol.pixel = PixColors[WhiteColor]; - } - return (xcol.pixel); + if (!XAllocColor(Xdisplay, cmap, &xcol)) { + print_error("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map.\n", type, xcol.pixel, xcol.red, + xcol.green, xcol.blue); + xcol.pixel = PixColors[WhiteColor]; + } + return (xcol.pixel); } Pixel get_color_by_name(const char *name, const char *fallback) { - XColor xcol; + XColor xcol; - if (name == NULL) { - if (fallback == NULL) { - return ((Pixel) -1); - } else { - name = fallback; - } - } else if (isdigit(*name)) { - unsigned long c; + if (name == NULL) { + if (fallback == NULL) { + return ((Pixel) - 1); + } else { + name = fallback; + } + } else if (isdigit(*name)) { + unsigned long c; - c = strtoul(name, (char **) NULL, 0); - if (c <= 15) { - name = rs_color[c + minColor]; + c = strtoul(name, (char **) NULL, 0); + if (c <= 15) { + name = rs_color[c + minColor]; + } } - } - if (!XParseColor(Xdisplay, cmap, name, &xcol)) { - print_warning("Unable to resolve \"%s\" as a color name. Falling back on \"%s\".\n", name, NONULL(fallback)); - name = fallback; - if (name) { - if (!XParseColor(Xdisplay, cmap, name, &xcol)) { - print_warning("Unable to resolve \"%s\" as a color name. This should never fail. Please repair/restore your RGB database.\n", name); - return ((Pixel) -1); - } - } else { - return ((Pixel) -1); + if (!XParseColor(Xdisplay, cmap, name, &xcol)) { + print_warning("Unable to resolve \"%s\" as a color name. Falling back on \"%s\".\n", name, NONULL(fallback)); + name = fallback; + if (name) { + if (!XParseColor(Xdisplay, cmap, name, &xcol)) { + print_warning + ("Unable to resolve \"%s\" as a color name. This should never fail. Please repair/restore your RGB database.\n", + name); + return ((Pixel) - 1); + } + } else { + return ((Pixel) - 1); + } } - } - if (!XAllocColor(Xdisplay, cmap, &xcol)) { - print_warning("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map. Falling back on \"%s\".\n", - name, xcol.pixel, xcol.red, xcol.green, xcol.blue, NONULL(fallback)); - name = fallback; - if (name) { - if (!XAllocColor(Xdisplay, cmap, &xcol)) { - print_warning("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map.\n", name, xcol.pixel, xcol.red, xcol.green, xcol.blue); - return ((Pixel) -1); - } - } else { - return ((Pixel) -1); + if (!XAllocColor(Xdisplay, cmap, &xcol)) { + print_warning("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map. Falling back on \"%s\".\n", + name, xcol.pixel, xcol.red, xcol.green, xcol.blue, NONULL(fallback)); + name = fallback; + if (name) { + if (!XAllocColor(Xdisplay, cmap, &xcol)) { + print_warning("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map.\n", name, xcol.pixel, xcol.red, + xcol.green, xcol.blue); + return ((Pixel) - 1); + } + } else { + return ((Pixel) - 1); + } } - } - return (xcol.pixel); + return (xcol.pixel); } Pixel get_color_by_pixel(Pixel pixel, Pixel fallback) { - XColor xcol; + XColor xcol; - xcol.pixel = pixel; - if (!XQueryColor(Xdisplay, cmap, &xcol)) { - print_warning("Unable to convert pixel value 0x%08x to an XColor structure. Falling back on 0x%08x.\n", pixel, fallback); - xcol.pixel = fallback; + xcol.pixel = pixel; if (!XQueryColor(Xdisplay, cmap, &xcol)) { - print_warning("Unable to convert pixel value 0x%08x to an XColor structure.\n", xcol.pixel); - return ((Pixel) 0); + print_warning("Unable to convert pixel value 0x%08x to an XColor structure. Falling back on 0x%08x.\n", pixel, fallback); + xcol.pixel = fallback; + if (!XQueryColor(Xdisplay, cmap, &xcol)) { + print_warning("Unable to convert pixel value 0x%08x to an XColor structure.\n", xcol.pixel); + return ((Pixel) 0); + } } - } - if (!XAllocColor(Xdisplay, cmap, &xcol)) { - print_warning("Unable to allocate 0x%08x (0x%04x, 0x%04x, 0x%04x) in the color map. Falling back on 0x%08x.\n", xcol.pixel, xcol.red, xcol.green, xcol.blue, fallback); - xcol.pixel = fallback; if (!XAllocColor(Xdisplay, cmap, &xcol)) { - print_warning("Unable to allocate 0x%08x (0x%04x, 0x%04x, 0x%04x) in the color map.\n", xcol.pixel, xcol.red, xcol.green, xcol.blue); - return ((Pixel) 0); + print_warning("Unable to allocate 0x%08x (0x%04x, 0x%04x, 0x%04x) in the color map. Falling back on 0x%08x.\n", xcol.pixel, + xcol.red, xcol.green, xcol.blue, fallback); + xcol.pixel = fallback; + if (!XAllocColor(Xdisplay, cmap, &xcol)) { + print_warning("Unable to allocate 0x%08x (0x%04x, 0x%04x, 0x%04x) in the color map.\n", xcol.pixel, xcol.red, xcol.green, + xcol.blue); + return ((Pixel) 0); + } } - } - return (xcol.pixel); + return (xcol.pixel); } void process_colors(void) { - int i; - Pixel pixel; + int i; + Pixel pixel; - for (i = 0; i < NRS_COLORS; i++) { - if ((Xdepth <= 2) || ((pixel = get_color_by_name(rs_color[i], def_colorName[i])) == (Pixel) -1)) { - switch (i) { - case fgColor: - pixel = WhitePixel(Xdisplay, Xscreen); - break; - case bgColor: - pixel = BlackPixel(Xdisplay, Xscreen); - break; + for (i = 0; i < NRS_COLORS; i++) { + if ((Xdepth <= 2) || ((pixel = get_color_by_name(rs_color[i], def_colorName[i])) == (Pixel) - 1)) { + switch (i) { + case fgColor: + pixel = WhitePixel(Xdisplay, Xscreen); + break; + case bgColor: + pixel = BlackPixel(Xdisplay, Xscreen); + break; #ifndef NO_CURSORCOLOR - case cursorColor: pixel = PixColors[bgColor]; break; - case cursorColor2: pixel = PixColors[fgColor]; break; + case cursorColor: + pixel = PixColors[bgColor]; + break; + case cursorColor2: + pixel = PixColors[fgColor]; + break; #endif /* NO_CURSORCOLOR */ - case pointerColor: pixel = PixColors[fgColor]; break; - case borderColor: pixel = PixColors[bgColor]; break; + case pointerColor: + pixel = PixColors[fgColor]; + break; + case borderColor: + pixel = PixColors[bgColor]; + break; #ifndef NO_BOLDUNDERLINE - case colorBD: pixel = PixColors[fgColor]; break; - case colorUL: pixel = PixColors[fgColor]; break; + case colorBD: + pixel = PixColors[fgColor]; + break; + case colorUL: + pixel = PixColors[fgColor]; + break; #endif - default: - pixel = PixColors[fgColor]; /* None */ - break; - } + default: + pixel = PixColors[fgColor]; /* None */ + break; + } + } + PixColors[i] = pixel; } - PixColors[i] = pixel; - } - if (Xdepth <= 2) { /* Monochrome */ - PixColors[topShadowColor] = PixColors[fgColor]; - PixColors[bottomShadowColor] = PixColors[fgColor]; - PixColors[unfocusedTopShadowColor] = PixColors[fgColor]; - PixColors[unfocusedBottomShadowColor] = PixColors[fgColor]; + if (Xdepth <= 2) { /* Monochrome */ + PixColors[topShadowColor] = PixColors[fgColor]; + PixColors[bottomShadowColor] = PixColors[fgColor]; + PixColors[unfocusedTopShadowColor] = PixColors[fgColor]; + PixColors[unfocusedBottomShadowColor] = PixColors[fgColor]; - PixColors[menuTopShadowColor] = PixColors[fgColor]; - PixColors[menuBottomShadowColor] = PixColors[fgColor]; - PixColors[unfocusedMenuTopShadowColor] = PixColors[fgColor]; - PixColors[unfocusedMenuBottomShadowColor] = PixColors[fgColor]; - } else { - PixColors[bottomShadowColor] = get_bottom_shadow_color(images[image_sb].norm->bg, "bottomShadowColor"); - PixColors[unfocusedBottomShadowColor] = get_bottom_shadow_color(images[image_sb].disabled->bg, "unfocusedBottomShadowColor"); - PixColors[topShadowColor] = get_top_shadow_color(images[image_sb].norm->bg, "topShadowColor"); - PixColors[unfocusedTopShadowColor] = get_top_shadow_color(images[image_sb].disabled->bg, "unfocusedTopShadowColor"); + PixColors[menuTopShadowColor] = PixColors[fgColor]; + PixColors[menuBottomShadowColor] = PixColors[fgColor]; + PixColors[unfocusedMenuTopShadowColor] = PixColors[fgColor]; + PixColors[unfocusedMenuBottomShadowColor] = PixColors[fgColor]; + } else { + PixColors[bottomShadowColor] = get_bottom_shadow_color(images[image_sb].norm->bg, "bottomShadowColor"); + PixColors[unfocusedBottomShadowColor] = get_bottom_shadow_color(images[image_sb].disabled->bg, "unfocusedBottomShadowColor"); + PixColors[topShadowColor] = get_top_shadow_color(images[image_sb].norm->bg, "topShadowColor"); + PixColors[unfocusedTopShadowColor] = get_top_shadow_color(images[image_sb].disabled->bg, "unfocusedTopShadowColor"); - PixColors[menuBottomShadowColor] = get_bottom_shadow_color(images[image_menu].norm->bg, "menuBottomShadowColor"); - PixColors[unfocusedMenuBottomShadowColor] = get_bottom_shadow_color(images[image_menu].disabled->bg, "unfocusedMenuBottomShadowColor"); - PixColors[menuTopShadowColor] = get_top_shadow_color(images[image_menu].norm->bg, "menuTopShadowColor"); - PixColors[unfocusedMenuTopShadowColor] = get_top_shadow_color(images[image_menu].disabled->bg, "unfocusedMenuTopShadowColor"); - } - stored_palette(SAVE); + PixColors[menuBottomShadowColor] = get_bottom_shadow_color(images[image_menu].norm->bg, "menuBottomShadowColor"); + PixColors[unfocusedMenuBottomShadowColor] = + get_bottom_shadow_color(images[image_menu].disabled->bg, "unfocusedMenuBottomShadowColor"); + PixColors[menuTopShadowColor] = get_top_shadow_color(images[image_menu].norm->bg, "menuTopShadowColor"); + PixColors[unfocusedMenuTopShadowColor] = get_top_shadow_color(images[image_menu].disabled->bg, "unfocusedMenuTopShadowColor"); + } + stored_palette(SAVE); } /* Create_Windows() - Open and map the window */ @@ -314,266 +336,273 @@ void Create_Windows(int argc, char *argv[]) { - Cursor cursor; - XClassHint classHint; - XWMHints wmHint; - Atom prop = None; - CARD32 val; - int x = 0, y = 0, flags; - unsigned int width = 0, height = 0; - MWMHints mwmhints; + Cursor cursor; + XClassHint classHint; + XWMHints wmHint; + Atom prop = None; + CARD32 val; + int x = 0, y = 0, flags; + unsigned int width = 0, height = 0; + MWMHints mwmhints; - if (Options & Opt_borderless) { - prop = XInternAtom(Xdisplay, "_MOTIF_WM_INFO", True); - if (prop == None) { - print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n"); - Attributes.override_redirect = TRUE; - mwmhints.flags = 0; + if (Options & Opt_borderless) { + prop = XInternAtom(Xdisplay, "_MOTIF_WM_INFO", True); + if (prop == None) { + print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n"); + Attributes.override_redirect = TRUE; + mwmhints.flags = 0; + } else { + mwmhints.flags = MWM_HINTS_DECORATIONS; + mwmhints.decorations = 0; + } } else { - mwmhints.flags = MWM_HINTS_DECORATIONS; - mwmhints.decorations = 0; + mwmhints.flags = 0; } - } else { - mwmhints.flags = 0; - } - Attributes.colormap = cmap; + Attributes.colormap = cmap; - szHint.base_width = (2 * TermWin.internalBorder + ((Options & Opt_scrollbar) ? (scrollbar_get_width() + (2 * scrollbar_get_shadow())) : 0)); - szHint.base_height = (2 * TermWin.internalBorder) + bbar_calc_docked_height(BBAR_DOCKED); + szHint.base_width = + (2 * TermWin.internalBorder + ((Options & Opt_scrollbar) ? (scrollbar_get_width() + (2 * scrollbar_get_shadow())) : 0)); + szHint.base_height = (2 * TermWin.internalBorder) + bbar_calc_docked_height(BBAR_DOCKED); - flags = (rs_geometry ? XParseGeometry(rs_geometry, &x, &y, &width, &height) : 0); - D_X11(("XParseGeometry(geom, %d, %d, %d, %d)\n", x, y, width, height)); + flags = (rs_geometry ? XParseGeometry(rs_geometry, &x, &y, &width, &height) : 0); + D_X11(("XParseGeometry(geom, %d, %d, %d, %d)\n", x, y, width, height)); - if (flags & WidthValue) { - szHint.width = width; - szHint.flags |= USSize; - } - if (flags & HeightValue) { - szHint.height = height; - szHint.flags |= USSize; - } - TermWin.ncol = szHint.width; - TermWin.nrow = szHint.height; - - change_font(1, NULL); - - if (flags & XValue) { - if (flags & XNegative) { - x += (DisplayWidth(Xdisplay, Xscreen) - (szHint.width + TermWin.internalBorder)); + if (flags & WidthValue) { + szHint.width = width; + szHint.flags |= USSize; } - szHint.x = x; - szHint.flags |= USPosition; - } - if (flags & YValue) { - if (flags & YNegative) { - y += (DisplayHeight(Xdisplay, Xscreen) - (szHint.height + TermWin.internalBorder)); + if (flags & HeightValue) { + szHint.height = height; + szHint.flags |= USSize; } - szHint.y = y; - szHint.flags |= USPosition; - } - if (flags) { - D_X11(("Geometry values after parsing: %dx%d%+d%+d\n", width, height, x, y)); - } + TermWin.ncol = szHint.width; + TermWin.nrow = szHint.height; - Attributes.background_pixel = PixColors[bgColor]; - Attributes.border_pixel = PixColors[bgColor]; - D_X11(("Size Hints: x %d, y %d. Width/Height: Base %dx%d, Minimum %dx%d, Current %dx%d, Increment %dx%d\n", - szHint.x, szHint.y, szHint.base_width, szHint.base_height, szHint.min_width, szHint.min_height, - szHint.width, szHint.height, szHint.width_inc, szHint.height_inc)); - TermWin.parent = XCreateWindow(Xdisplay, Xroot, szHint.x, szHint.y, szHint.width, szHint.height, 0, Xdepth, InputOutput, + change_font(1, NULL); + + if (flags & XValue) { + if (flags & XNegative) { + x += (DisplayWidth(Xdisplay, Xscreen) - (szHint.width + TermWin.internalBorder)); + } + szHint.x = x; + szHint.flags |= USPosition; + } + if (flags & YValue) { + if (flags & YNegative) { + y += (DisplayHeight(Xdisplay, Xscreen) - (szHint.height + TermWin.internalBorder)); + } + szHint.y = y; + szHint.flags |= USPosition; + } + if (flags) { + D_X11(("Geometry values after parsing: %dx%d%+d%+d\n", width, height, x, y)); + } + + Attributes.background_pixel = PixColors[bgColor]; + Attributes.border_pixel = PixColors[bgColor]; + D_X11(("Size Hints: x %d, y %d. Width/Height: Base %dx%d, Minimum %dx%d, Current %dx%d, Increment %dx%d\n", + szHint.x, szHint.y, szHint.base_width, szHint.base_height, szHint.min_width, szHint.min_height, + szHint.width, szHint.height, szHint.width_inc, szHint.height_inc)); + TermWin.parent = XCreateWindow(Xdisplay, Xroot, szHint.x, szHint.y, szHint.width, szHint.height, 0, Xdepth, InputOutput, #ifdef PREFER_24BIT - Xvisual, + Xvisual, #else - CopyFromParent, + CopyFromParent, #endif - CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect, &Attributes); + CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect, &Attributes); - xterm_seq(XTerm_title, rs_title); - xterm_seq(XTerm_iconName, rs_iconName); - classHint.res_name = (char *) rs_name; - classHint.res_class = APL_NAME; - wmHint.window_group = TermWin.parent; - wmHint.input = ((Options & Opt_no_input) ? False : True); - wmHint.initial_state = (Options & Opt_iconic ? IconicState : NormalState); - wmHint.window_group = TermWin.parent; - wmHint.flags = (InputHint | StateHint | WindowGroupHint); + xterm_seq(XTerm_title, rs_title); + xterm_seq(XTerm_iconName, rs_iconName); + classHint.res_name = (char *) rs_name; + classHint.res_class = APL_NAME; + wmHint.window_group = TermWin.parent; + wmHint.input = ((Options & Opt_no_input) ? False : True); + wmHint.initial_state = (Options & Opt_iconic ? IconicState : NormalState); + wmHint.window_group = TermWin.parent; + wmHint.flags = (InputHint | StateHint | WindowGroupHint); #ifdef PIXMAP_SUPPORT - set_icon_pixmap(rs_icon, &wmHint); + set_icon_pixmap(rs_icon, &wmHint); #endif - XSetWMProperties(Xdisplay, TermWin.parent, NULL, NULL, argv, argc, &szHint, &wmHint, &classHint); - XSelectInput(Xdisplay, Xroot, PropertyChangeMask); - XSelectInput(Xdisplay, TermWin.parent, (KeyPressMask | FocusChangeMask | StructureNotifyMask | VisibilityChangeMask | PropertyChangeMask)); - if (mwmhints.flags) { - prop = XInternAtom(Xdisplay, "_MOTIF_WM_HINTS", False); - XChangeProperty(Xdisplay, TermWin.parent, prop, prop, 32, PropModeReplace, (unsigned char *) &mwmhints, PROP_MWM_HINTS_ELEMENTS); - } - /* vt cursor: Black-on-White is standard, but this is more popular */ - TermWin_cursor = XCreateFontCursor(Xdisplay, XC_xterm); - { + XSetWMProperties(Xdisplay, TermWin.parent, NULL, NULL, argv, argc, &szHint, &wmHint, &classHint); + XSelectInput(Xdisplay, Xroot, PropertyChangeMask); + XSelectInput(Xdisplay, TermWin.parent, + (KeyPressMask | FocusChangeMask | StructureNotifyMask | VisibilityChangeMask | PropertyChangeMask)); + if (mwmhints.flags) { + prop = XInternAtom(Xdisplay, "_MOTIF_WM_HINTS", False); + XChangeProperty(Xdisplay, TermWin.parent, prop, prop, 32, PropModeReplace, (unsigned char *) &mwmhints, PROP_MWM_HINTS_ELEMENTS); + } + /* vt cursor: Black-on-White is standard, but this is more popular */ + TermWin_cursor = XCreateFontCursor(Xdisplay, XC_xterm); + { - XColor fg, bg; + XColor fg, bg; - fg.pixel = PixColors[pointerColor]; - XQueryColor(Xdisplay, cmap, &fg); - bg.pixel = PixColors[bgColor]; - XQueryColor(Xdisplay, cmap, &bg); - XRecolorCursor(Xdisplay, TermWin_cursor, &fg, &bg); - } + fg.pixel = PixColors[pointerColor]; + XQueryColor(Xdisplay, cmap, &fg); + bg.pixel = PixColors[bgColor]; + XQueryColor(Xdisplay, cmap, &bg); + XRecolorCursor(Xdisplay, TermWin_cursor, &fg, &bg); + } - /* cursor (menu/scrollbar): Black-on-White */ - cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); + /* cursor (menu/scrollbar): Black-on-White */ + cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); - /* the vt window */ - TermWin.x = (((Options & Opt_scrollbar) && !(Options & Opt_scrollbar_right)) ? (scrollbar_get_width() + (2 * scrollbar_get_shadow())) : 0); - TermWin.y = bbar_calc_docked_height(BBAR_DOCKED_TOP); - TermWin.vt = XCreateWindow(Xdisplay, TermWin.parent, TermWin.x, TermWin.y, szHint.width, szHint.height, 0, Xdepth, InputOutput, CopyFromParent, - CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWColormap, &Attributes); - D_X11(("Created terminal window 0x%08x at %dx%d\n", TermWin.vt, TermWin.x, TermWin.y)); - if (!(background_is_pixmap()) && !(Options & Opt_borderless)) { + /* the vt window */ + TermWin.x = + (((Options & Opt_scrollbar) && !(Options & Opt_scrollbar_right)) ? (scrollbar_get_width() + (2 * scrollbar_get_shadow())) : 0); + TermWin.y = bbar_calc_docked_height(BBAR_DOCKED_TOP); + TermWin.vt = + XCreateWindow(Xdisplay, TermWin.parent, TermWin.x, TermWin.y, szHint.width, szHint.height, 0, Xdepth, InputOutput, CopyFromParent, + CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWColormap, &Attributes); + D_X11(("Created terminal window 0x%08x at %dx%d\n", TermWin.vt, TermWin.x, TermWin.y)); + if (!(background_is_pixmap()) && !(Options & Opt_borderless)) { + XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[bgColor]); + XClearWindow(Xdisplay, TermWin.vt); + } + XDefineCursor(Xdisplay, TermWin.vt, TermWin_cursor); + TermWin.mask = + (EnterWindowMask | LeaveWindowMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button3MotionMask); + XSelectInput(Xdisplay, TermWin.vt, TermWin.mask); + + /* If the user wants a specific desktop, tell the WM that */ + if (rs_desktop != -1) { + val = rs_desktop; + XChangeProperty(Xdisplay, TermWin.parent, props[PROP_DESKTOP], XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1); + } + + /* We're done creating our windows. Now let's initialize the event subsystem to handle them. */ + event_init_subsystem((event_dispatcher_t) process_x_event, (event_dispatcher_init_t) event_init_primary_dispatcher); + + XMapWindow(Xdisplay, TermWin.vt); + XMapWindow(Xdisplay, TermWin.parent); XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[bgColor]); - XClearWindow(Xdisplay, TermWin.vt); - } - XDefineCursor(Xdisplay, TermWin.vt, TermWin_cursor); - TermWin.mask = (EnterWindowMask | LeaveWindowMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button3MotionMask); - XSelectInput(Xdisplay, TermWin.vt, TermWin.mask); - /* If the user wants a specific desktop, tell the WM that */ - if (rs_desktop != -1) { - val = rs_desktop; - XChangeProperty(Xdisplay, TermWin.parent, props[PROP_DESKTOP], XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1); - } + render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); + if (image_mode_is(image_bg, MODE_AUTO)) { + enl_ipc_sync(); + } - /* We're done creating our windows. Now let's initialize the event subsystem to handle them. */ - event_init_subsystem((event_dispatcher_t) process_x_event, (event_dispatcher_init_t) event_init_primary_dispatcher); + /* graphics context for the vt window */ + { + XGCValues gcvalue; - XMapWindow(Xdisplay, TermWin.vt); - XMapWindow(Xdisplay, TermWin.parent); - XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[bgColor]); + gcvalue.font = TermWin.font->fid; + gcvalue.foreground = PixColors[fgColor]; + gcvalue.background = PixColors[bgColor]; + gcvalue.graphics_exposures = 0; + TermWin.gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground | GCFont | GCGraphicsExposures, &gcvalue); + } - render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); - if (image_mode_is(image_bg, MODE_AUTO)) { - enl_ipc_sync(); - } - - /* graphics context for the vt window */ - { - XGCValues gcvalue; - - gcvalue.font = TermWin.font->fid; - gcvalue.foreground = PixColors[fgColor]; - gcvalue.background = PixColors[bgColor]; - gcvalue.graphics_exposures = 0; - TermWin.gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground | GCFont | GCGraphicsExposures, &gcvalue); - } - - if (Options & Opt_no_cursor) { - scr_cursor_visible(0); - } + if (Options & Opt_no_cursor) { + scr_cursor_visible(0); + } } /* resize window keeping one point (determined by window geometry) in place */ void resize_parent(unsigned int width, unsigned int height) { - XWindowAttributes attr; + XWindowAttributes attr; - if (!(Options & Opt_resize_gravity) || !XGetWindowAttributes(Xdisplay, TermWin.parent, &attr)) { - XResizeWindow(Xdisplay, TermWin.parent, width, height); - } else { - Window junkwin; - int x, y, scr_w, scr_h; - int dx = 0, dy = 0; + if (!(Options & Opt_resize_gravity) || !XGetWindowAttributes(Xdisplay, TermWin.parent, &attr)) { + XResizeWindow(Xdisplay, TermWin.parent, width, height); + } else { + Window junkwin; + int x, y, scr_w, scr_h; + int dx = 0, dy = 0; - scr_w = WidthOfScreen(attr.screen); - scr_h = HeightOfScreen(attr.screen); - dx = attr.width - width; - dy = attr.height - height; - XTranslateCoordinates(Xdisplay, TermWin.parent, attr.root, 0, 0, &x, &y, &junkwin); - /* Check position of the center of the window */ - if (x < (scr_w - attr.width) / 2) { - /* left half */ - dx = 0; - } else if (x == (scr_w - attr.width) / 2 ) { - /* exact center */ - dx /= 2; + scr_w = WidthOfScreen(attr.screen); + scr_h = HeightOfScreen(attr.screen); + dx = attr.width - width; + dy = attr.height - height; + XTranslateCoordinates(Xdisplay, TermWin.parent, attr.root, 0, 0, &x, &y, &junkwin); + /* Check position of the center of the window */ + if (x < (scr_w - attr.width) / 2) { + /* left half */ + dx = 0; + } else if (x == (scr_w - attr.width) / 2) { + /* exact center */ + dx /= 2; + } + if (y < (scr_h - attr.height) / 2) { + /* top half */ + dy = 0; + } else if (y == (scr_h - attr.height) / 2) { + /* exact center */ + dy /= 2; + } + D_X11(("Calling XMoveResizeWindow(Xdisplay, 0x%08x, %d + %d, %d + %d, %d, %d)\n", TermWin.parent, x, dx, y, dy, width, height)); + XMoveResizeWindow(Xdisplay, TermWin.parent, x + dx, y + dy, width, height); } - if (y < (scr_h - attr.height) / 2) { - /* top half */ - dy = 0; - } else if (y == (scr_h - attr.height) / 2) { - /* exact center */ - dy /= 2; - } - D_X11(("Calling XMoveResizeWindow(Xdisplay, 0x%08x, %d + %d, %d + %d, %d, %d)\n", TermWin.parent, x, dx, y, dy, width, height)); - XMoveResizeWindow(Xdisplay, TermWin.parent, x + dx, y + dy, width, height); - } } /* good for toggling 80/132 columns */ void set_width(unsigned short width) { - unsigned short height = TermWin.nrow; + unsigned short height = TermWin.nrow; - if (width != TermWin.ncol) { - width = szHint.base_width + width * TermWin.fwidth; - height = szHint.base_height + height * TermWin.fheight; + if (width != TermWin.ncol) { + width = szHint.base_width + width * TermWin.fwidth; + height = szHint.base_height + height * TermWin.fheight; - resize_parent(width, height); - handle_resize(width, height); - } + resize_parent(width, height); + handle_resize(width, height); + } } void update_size_hints(void) { - D_X11(("Called.\n")); - szHint.base_width = (2 * TermWin.internalBorder) + ((scrollbar_is_visible()) ? (scrollbar_trough_width()) : (0)); - szHint.base_height = (2 * TermWin.internalBorder) + bbar_calc_docked_height(BBAR_DOCKED); + D_X11(("Called.\n")); + szHint.base_width = (2 * TermWin.internalBorder) + ((scrollbar_is_visible())? (scrollbar_trough_width()) : (0)); + szHint.base_height = (2 * TermWin.internalBorder) + bbar_calc_docked_height(BBAR_DOCKED); - szHint.width_inc = TermWin.fwidth; - szHint.height_inc = TermWin.fheight; + szHint.width_inc = TermWin.fwidth; + szHint.height_inc = TermWin.fheight; - D_X11(("Size Hints: base width/height == %lux%lu, width/height increment == %lux%lu\n", szHint.base_width, szHint.base_height, szHint.width_inc, szHint.height_inc)); + D_X11(("Size Hints: base width/height == %lux%lu, width/height increment == %lux%lu\n", szHint.base_width, szHint.base_height, + szHint.width_inc, szHint.height_inc)); - szHint.min_width = szHint.base_width + szHint.width_inc; - szHint.min_height = szHint.base_height + szHint.height_inc; - szHint.width = szHint.base_width + TermWin.width; - szHint.height = szHint.base_height + TermWin.height; - D_X11((" Minimum width/height == %lux%lu, width/height == %lux%lu\n", - szHint.min_width, szHint.min_height, szHint.width, szHint.height)); + szHint.min_width = szHint.base_width + szHint.width_inc; + szHint.min_height = szHint.base_height + szHint.height_inc; + szHint.width = szHint.base_width + TermWin.width; + szHint.height = szHint.base_height + TermWin.height; + D_X11((" Minimum width/height == %lux%lu, width/height == %lux%lu\n", + szHint.min_width, szHint.min_height, szHint.width, szHint.height)); - szHint.flags = PMinSize | PResizeInc | PBaseSize; - XSetWMNormalHints(Xdisplay, TermWin.parent, &szHint); + szHint.flags = PMinSize | PResizeInc | PBaseSize; + XSetWMNormalHints(Xdisplay, TermWin.parent, &szHint); } /* Resize terminal window and scrollbar window */ void term_resize(int width, int height) { - static int last_width = 0, last_height = 0; + static int last_width = 0, last_height = 0; - D_X11(("term_resize(%d, %d)\n", width, height)); - TermWin.width = TermWin.ncol * TermWin.fwidth; - TermWin.height = TermWin.nrow * TermWin.fheight; - D_X11((" -> New TermWin width/height == %lux%lu\n", TermWin.width, TermWin.height)); - width = TermWin_TotalWidth(); - height = TermWin_TotalHeight(); - XMoveResizeWindow(Xdisplay, TermWin.vt, ((Options & Opt_scrollbar_right) ? (0) : ((scrollbar_is_visible()) ? (scrollbar_trough_width()) : (0))), - bbar_calc_docked_height(BBAR_DOCKED_TOP), width, height); - if (width != last_width || height != last_height) { - render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); - scr_reset(); - scr_touch(); - if (image_mode_is(image_bg, MODE_AUTO)) { - enl_ipc_sync(); + D_X11(("term_resize(%d, %d)\n", width, height)); + TermWin.width = TermWin.ncol * TermWin.fwidth; + TermWin.height = TermWin.nrow * TermWin.fheight; + D_X11((" -> New TermWin width/height == %lux%lu\n", TermWin.width, TermWin.height)); + width = TermWin_TotalWidth(); + height = TermWin_TotalHeight(); + XMoveResizeWindow(Xdisplay, TermWin.vt, + ((Options & Opt_scrollbar_right) ? (0) : ((scrollbar_is_visible())? (scrollbar_trough_width()) : (0))), + bbar_calc_docked_height(BBAR_DOCKED_TOP), width, height); + if (width != last_width || height != last_height) { + render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 0); + scr_reset(); + scr_touch(); + if (image_mode_is(image_bg, MODE_AUTO)) { + enl_ipc_sync(); + } + last_width = width; + last_height = height; } - last_width = width; - last_height = height; - } #ifdef USE_XIM - xim_set_status_position(); + xim_set_status_position(); #endif } @@ -581,156 +610,160 @@ term_resize(int width, int height) void parent_resize(void) { - D_X11(("Called.\n")); - update_size_hints(); - resize_parent(szHint.width, szHint.height); - D_X11((" -> New parent width/height == %lux%lu\n", szHint.width, szHint.height)); - term_resize(szHint.width, szHint.height); - scrollbar_resize(szHint.width, szHint.height - bbar_calc_docked_height(BBAR_DOCKED)); - bbar_resize_all(szHint.width); + D_X11(("Called.\n")); + update_size_hints(); + resize_parent(szHint.width, szHint.height); + D_X11((" -> New parent width/height == %lux%lu\n", szHint.width, szHint.height)); + term_resize(szHint.width, szHint.height); + scrollbar_resize(szHint.width, szHint.height - bbar_calc_docked_height(BBAR_DOCKED)); + bbar_resize_all(szHint.width); } void handle_resize(unsigned int width, unsigned int height) { - static short first_time = 1; - int new_ncol = (width - szHint.base_width) / TermWin.fwidth; - int new_nrow = (height - szHint.base_height) / TermWin.fheight; + static short first_time = 1; + int new_ncol = (width - szHint.base_width) / TermWin.fwidth; + int new_nrow = (height - szHint.base_height) / TermWin.fheight; - D_EVENTS(("handle_resize(%u, %u)\n", width, height)); - if (first_time || (new_ncol != TermWin.ncol) || (new_nrow != TermWin.nrow)) { - TermWin.ncol = new_ncol; - TermWin.nrow = new_nrow; + D_EVENTS(("handle_resize(%u, %u)\n", width, height)); + if (first_time || (new_ncol != TermWin.ncol) || (new_nrow != TermWin.nrow)) { + TermWin.ncol = new_ncol; +#ifdef ESCREEN + TermWin.nrow = new_nrow + (TermWin.screen_mode ? 1 : 0); +#else + TermWin.nrow = new_nrow; +#endif - term_resize(width, height); - szHint.width = szHint.base_width + TermWin.width; - szHint.height = szHint.base_height + TermWin.height; - D_X11((" -> New szHint.width/height == %lux%lu\n", szHint.width, szHint.height)); - scrollbar_resize(width, szHint.height - bbar_calc_docked_height(BBAR_DOCKED)); - bbar_resize_all(szHint.width); - first_time = 0; - } + term_resize(width, height); + szHint.width = szHint.base_width + TermWin.width; + szHint.height = szHint.base_height + TermWin.height; + D_X11((" -> New szHint.width/height == %lux%lu\n", szHint.width, szHint.height)); + scrollbar_resize(width, szHint.height - bbar_calc_docked_height(BBAR_DOCKED)); + bbar_resize_all(szHint.width); + first_time = 0; + } } void handle_move(int x, int y) { - if ((TermWin.x != x) || (TermWin.y != y)) { - TermWin.x = x; - TermWin.y = y; - if (image_mode_any(MODE_TRANS | MODE_VIEWPORT)) { - redraw_images_by_mode(MODE_TRANS | MODE_VIEWPORT); + if ((TermWin.x != x) || (TermWin.y != y)) { + TermWin.x = x; + TermWin.y = y; + if (image_mode_any(MODE_TRANS | MODE_VIEWPORT)) { + redraw_images_by_mode(MODE_TRANS | MODE_VIEWPORT); + } } - } } #ifdef XTERM_COLOR_CHANGE void stored_palette(char op) { - static Pixel default_colors[NRS_COLORS + NSHADOWCOLORS]; - static unsigned char stored = 0; - unsigned char i; + static Pixel default_colors[NRS_COLORS + NSHADOWCOLORS]; + static unsigned char stored = 0; + unsigned char i; - if (op == SAVE) { - for (i = 0; i < NRS_COLORS; i++) { - default_colors[i] = PixColors[i]; + if (op == SAVE) { + for (i = 0; i < NRS_COLORS; i++) { + default_colors[i] = PixColors[i]; + } + stored = 1; + } else if (op == RESTORE && stored) { + for (i = 0; i < NRS_COLORS; i++) { + PixColors[i] = default_colors[i]; + } } - stored = 1; - } else if (op == RESTORE && stored) { - for (i = 0; i < NRS_COLORS; i++) { - PixColors[i] = default_colors[i]; - } - } } void set_window_color(int idx, const char *color) { - XColor xcol; - int i; + XColor xcol; + int i; - D_X11(("idx == %d, color == \"%s\"\n", idx, NONULL(color))); + D_X11(("idx == %d, color == \"%s\"\n", idx, NONULL(color))); - if (color == NULL || *color == '\0') - return; + if (color == NULL || *color == '\0') + return; - /* handle color aliases */ - if (isdigit(*color)) { - i = atoi(color); - if (i >= 8 && i <= 15) { /* bright colors */ - i -= 8; + /* handle color aliases */ + if (isdigit(*color)) { + i = atoi(color); + if (i >= 8 && i <= 15) { /* bright colors */ + i -= 8; # ifndef NO_BRIGHTCOLOR - PixColors[idx] = PixColors[minBright + i]; + PixColors[idx] = PixColors[minBright + i]; # endif - } + } # ifndef NO_BRIGHTCOLOR - else + else # endif - if (i >= 0 && i <= 7) { /* normal colors */ - PixColors[idx] = PixColors[minColor + i]; + if (i >= 0 && i <= 7) { /* normal colors */ + PixColors[idx] = PixColors[minColor + i]; + } else { + print_warning("Color index %d is invalid.\n", i); + return; + } + } else if (XParseColor(Xdisplay, cmap, color, &xcol)) { + if (!XAllocColor(Xdisplay, cmap, &xcol)) { + print_warning("Unable to allocate \"%s\" in the color map.\n", color); + return; + } + PixColors[idx] = xcol.pixel; } else { - print_warning("Color index %d is invalid.\n", i); - return; + print_warning("Unable to resolve \"%s\" as a color name.\n", color); + return; } - } else if (XParseColor(Xdisplay, cmap, color, &xcol)) { - if (!XAllocColor(Xdisplay, cmap, &xcol)) { - print_warning("Unable to allocate \"%s\" in the color map.\n", color); - return; - } - PixColors[idx] = xcol.pixel; - } else { - print_warning("Unable to resolve \"%s\" as a color name.\n", color); - return; - } - redraw_image(image_bg); - set_colorfgbg(); - scr_touch(); - scr_refresh(DEFAULT_REFRESH); + redraw_image(image_bg); + set_colorfgbg(); + scr_touch(); + scr_refresh(DEFAULT_REFRESH); } #endif /* XTERM_COLOR_CHANGE */ Window find_window_by_coords(Window win, int win_x, int win_y, int rel_x, int rel_y) { - Window *children = NULL; - XWindowAttributes attr; - Window child = 0, parent_win = 0, root_win = 0; - int i; - unsigned int ww, wh, num; - int wx, wy; + Window *children = NULL; + XWindowAttributes attr; + Window child = 0, parent_win = 0, root_win = 0; + int i; + unsigned int ww, wh, num; + int wx, wy; - D_X11(("win 0x%08x at %d, %d. Coords are %d, %d.\n", win, win_x, win_y, rel_x, rel_y)); + D_X11(("win 0x%08x at %d, %d. Coords are %d, %d.\n", win, win_x, win_y, rel_x, rel_y)); - /* Bad or invisible window. */ - if ((!XGetWindowAttributes(Xdisplay, win, &attr)) || (attr.map_state != IsViewable)) { - return None; - } - wx = attr.x + win_x; - wy = attr.y + win_y; - ww = attr.width; - wh = attr.height; - - if (!((rel_x >= wx) && (rel_y >= wy) && (rel_x < (int)(wx + ww)) && (rel_y < (int)(wy + wh)))) { - return None; - } - - if (!XQueryTree(Xdisplay, win, &root_win, &parent_win, &children, &num)) { - return win; - } - if (children) { - D_X11(("%d children.\n", num)); - for (i = num - 1; i >= 0; i--) { - D_X11(("Trying children[%d] (0x%08x)\n", i, children[i])); - if ((child = find_window_by_coords(children[i], wx, wy, rel_x, rel_y)) != None) { - D_X11(("Match!\n")); - XFree(children); - return child; - } + /* Bad or invisible window. */ + if ((!XGetWindowAttributes(Xdisplay, win, &attr)) || (attr.map_state != IsViewable)) { + return None; } - D_X11(("XFree(children)\n")); - XFree(children); - } - D_X11(("Returning 0x%08x\n", win)); - return win; + wx = attr.x + win_x; + wy = attr.y + win_y; + ww = attr.width; + wh = attr.height; + + if (!((rel_x >= wx) && (rel_y >= wy) && (rel_x < (int) (wx + ww)) && (rel_y < (int) (wy + wh)))) { + return None; + } + + if (!XQueryTree(Xdisplay, win, &root_win, &parent_win, &children, &num)) { + return win; + } + if (children) { + D_X11(("%d children.\n", num)); + for (i = num - 1; i >= 0; i--) { + D_X11(("Trying children[%d] (0x%08x)\n", i, children[i])); + if ((child = find_window_by_coords(children[i], wx, wy, rel_x, rel_y)) != None) { + D_X11(("Match!\n")); + XFree(children); + return child; + } + } + D_X11(("XFree(children)\n")); + XFree(children); + } + D_X11(("Returning 0x%08x\n", win)); + return win; } diff --git a/utils/Esetroot.c b/utils/Esetroot.c index 5fd529b..00acb7c 100644 --- a/utils/Esetroot.c +++ b/utils/Esetroot.c @@ -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 ] [-bgcolor ] [-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 ] [-bgcolor ] [-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 ] [-bgcolor ] [-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 ] [-bgcolor ] [-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; } diff --git a/utils/Etbg.c b/utils/Etbg.c index 8fd7e9c..a2de931 100644 --- a/utils/Etbg.c +++ b/utils/Etbg.c @@ -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; } diff --git a/utils/Ettable.c b/utils/Ettable.c index 3346e14..354bc2c 100644 --- a/utils/Ettable.c +++ b/utils/Ettable.c @@ -26,40 +26,39 @@ static const char cvs_ident[] = "$Id$"; #include -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; }