diff --git a/ChangeLog b/ChangeLog index 070c15a..c197087 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4679,3 +4679,7 @@ Thu May 23 14:12:28 2002 Michael Jennings (mej) More cleanups and warning removals. ---------------------------------------------------------------------- +Sun Jun 2 20:23:07 2002 Michael Jennings (mej) + +Latest Escreen patch along with twin support from Azundris. +---------------------------------------------------------------------- diff --git a/doc/Eterm.1.in b/doc/Eterm.1.in index ce136da..b5e6c78 100644 --- a/doc/Eterm.1.in +++ b/doc/Eterm.1.in @@ -618,9 +618,14 @@ rather than a shell. Forces Eterm mode. .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. +rather than a local (-U "") one. URLs look like so +(screen://user@host.dom:port/screen_options), with all parts optional, +defaulting to "screen://current_user@localhost:22/-xRR". Forces Escreen mode, +overrides \-\-exec. Note that only screen-options (see "man screen") are +allowed; do not pass a command (with or without arguments) here: to pass +a command to the screen-session, use +.I screen [] [] +instead. .TP .BI \-Z " lclport:fw:fwport,delay" ", \-\-fw " lclport:fw:fwport,delay The URL given to \-U is in an intranet behind firewall diff --git a/reformat-code b/reformat-code index 1de1c1e..d50b5d8 100755 --- a/reformat-code +++ b/reformat-code @@ -1,10 +1,17 @@ #!/bin/sh +TYPENAMES="" + +for i in button_t buttonbar_t menu_t menuitem_t ; do + TYPENAMES="$TYPENAMES -T $i" +done + 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 -i4 -l140 -lp -lps -nbc -npcs -nss -nsob -psl $i - fi + if test -f $i; then + echo Reformatting $i + indent -bad -bap -bbo -br -brs -cdw -ce -ci4 -cli2 -cs -di1 -i4 -l180 \ + -lp -lps -nbc -nbfda -npcs -nprs -nsob -nss -nut -psl -saf -sai -saw $TYPENAMES $i + fi done perl -p -i.bak -e 's/(\w+)_t (\*+)\s+/$1_t $2/g;' */*.[ch] diff --git a/src/actions.c b/src/actions.c index 2379ea9..22daa7f 100644 --- a/src/actions.c +++ b/src/actions.c @@ -42,6 +42,9 @@ static const char cvs_ident[] = "$Id$"; #include "scrollbar.h" #include "term.h" #include "windows.h" +#ifdef ESCREEN +# include "screamcfg.h" +#endif action_t *action_list = NULL; @@ -60,9 +63,12 @@ action_handle_echo(event_t *ev, action_t *action) USE_VAR(ev); REQUIRE_RVAL(action->param.string != NULL, 0); #ifdef ESCREEN - if (TermWin.screen_mode && TermWin.screen) /* translate escapes */ + if (TermWin.screen && TermWin.screen->backend) { +# ifdef NS_HAVE_SCREEN + /* translate escapes */ ns_parse_screen_interactive(TermWin.screen, action->param.string); - else +# endif + } else #endif tt_write((unsigned char *) action->param.string, strlen(action->param.string)); return 1; @@ -140,8 +146,7 @@ action_check_modifiers(unsigned short mod, int x_mod) /* 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))); + 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 @@ -197,8 +202,7 @@ action_dispatch(event_t *ev, KeySym keysym) 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))); + 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 diff --git a/src/buttons.c b/src/buttons.c index 68d59a5..9d449af 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -50,6 +50,10 @@ static const char cvs_ident[] = "$Id$"; static inline void draw_string(buttonbar_t *, Drawable, GC, int, int, char *, size_t); buttonbar_t *buttonbar = NULL; + +#ifdef ESCREEN +button_t *drag = NULL; +#endif long bbar_total_h = -1; static inline void @@ -70,8 +74,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; @@ -188,8 +191,7 @@ 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); @@ -231,6 +233,9 @@ bbar_handle_button_press(event_t *ev) if (bbar->current) { bbar_click_button(bbar, bbar->current); button_check_action(bbar, bbar->current, ev->xbutton.button, ev->xbutton.time); +#ifdef ESCREEN + drag = bbar->current; +#endif } return 1; } @@ -244,6 +249,10 @@ bbar_handle_button_release(event_t *ev) int unused_root_x, unused_root_y; unsigned int unused_mask; +#ifdef ESCREEN + drag = NULL; +#endif + D_EVENTS(("bbar_handle_button_release(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &buttonbar->event_data), 0); @@ -252,8 +261,7 @@ 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) { @@ -285,8 +293,7 @@ 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); @@ -315,8 +322,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; @@ -500,8 +506,7 @@ 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 @@ -577,8 +582,7 @@ 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); } @@ -603,8 +607,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; @@ -623,8 +626,7 @@ find_button_by_text(buttonbar_t *bbar, char *text) return NULL; } -button_t * -find_button_by_index(buttonbar_t *bbar, long idx) +button_t *find_button_by_index(buttonbar_t *bbar, long idx) { register button_t *b; long i; @@ -639,8 +641,7 @@ find_button_by_index(buttonbar_t *bbar, long idx) return ((i == idx) ? (b) : (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; @@ -659,8 +660,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; @@ -791,8 +791,7 @@ 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(); @@ -826,38 +825,48 @@ button_check_action(buttonbar_t *bbar, button_t *button, unsigned char press, Ti case ACTION_ECHO: if (!press) { #ifdef ESCREEN - if (TermWin.screen_mode && TermWin.screen) { /* translate escapes */ - if (prvs != 1) { - button_t *b = bbar->buttons; - _ns_disp *d2 = TermWin.screen->dsps; - int n = (button->action.string)[1] - '0'; + if (TermWin.screen && TermWin.screen->backend) { /* translate escapes */ + button_t *b = bbar->buttons; + _ns_disp *d2 = TermWin.screen->dsps; + int n = (button->action.string)[1] - '0'; - while (b && !(b->flags & NS_SCREAM_CURR)) /* find active disp */ - b = b->next; /* when trying to change name of non- */ - if (b && b != button) { /* active display, make that disp active */ + if (prvs != 1) { + /* find active disp */ + for (; b && !(b->flags & NS_SCREAM_CURR); b = b->next); + + if (b && b != button) { + /* when trying to change name of non- */ + /* active display, make that disp active */ button->flags |= NS_SCREAM_CURR; b->flags &= ~NS_SCREAM_CURR; bbar_draw(bbar, IMAGE_STATE_CURRENT, MODE_MASK); button->flags &= ~NS_SCREAM_CURR; b->flags |= NS_SCREAM_CURR; - while (d2 && d2->index != n) - d2 = d2->next; - if (d2) - TermWin.screen->curr = d2; /* pre-adjust curr ptr */ - else + for (; d2 && d2->index != n; d2 = d2->next); + if (d2) { + /* pre-adjust curr ptr */ + TermWin.screen->curr = d2; + } else { D_ESCREEN(("no display %d in this session : (\n", n)); - (void) ns_screen_command(TermWin.screen, button->action.string); + } + ns_go2_disp(TermWin.screen, n); } - if (prvs == 2) /* middle button -- kill */ - (void) ns_parse_screen_key(TermWin.screen, NS_SCREEN_KILL); - else /* right button -- rename */ - (void) ns_parse_screen_key(TermWin.screen, NS_SCREEN_RENAME); - } else /* left button -- select */ - (void) ns_screen_command(TermWin.screen, button->action.string); - } else /* not in screen-mode, use normal facilities */ + if (prvs == 2) { + /* middle button -- kill */ + (void) ns_rem_disp(TermWin.screen, n); + } else { + /* right button -- rename */ + (void) ns_ren_disp(TermWin.screen, n, NULL); + } + } else { + /* left button -- select */ + ns_go2_disp(TermWin.screen, n); + } + } else #endif + /* not in screen-mode, use normal facilities */ tt_write((unsigned char *) button->action.string, strlen(button->action.string)); } break; @@ -1138,6 +1147,7 @@ buttonbar_t *bbar_insert_button(buttonbar_t *bbar, button_t *button, int after, } else { int c = 0; button_t *b = bbar->rbuttons; + do { c++; } while ((b = b->next)); @@ -1154,11 +1164,12 @@ buttonbar_t *bbar_insert_button(buttonbar_t *bbar, button_t *button, int after, } } } else { /* add to buttons */ - if (!bbar->buttons || after < 0) { /* first button */ + 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; @@ -1173,6 +1184,7 @@ buttonbar_t *bbar_insert_button(buttonbar_t *bbar, button_t *button, int after, if (!state) { if (buttonbar) { buttonbar_t *bar = buttonbar; + while (bar->next) bar = bar->next; bar->next = bbar; diff --git a/src/buttons.h b/src/buttons.h index 1e1f92f..5bd7e6b 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -96,6 +96,9 @@ typedef struct buttonbar_struct { /************ Variables ************/ extern buttonbar_t *buttonbar; extern long bbar_total_h; +#ifdef ESCREEN +extern button_t *drag; +#endif /************ Function Prototypes ************/ _XFUNCPROTOBEGIN diff --git a/src/command.c b/src/command.c index 9515c6f..e13c0fe 100644 --- a/src/command.c +++ b/src/command.c @@ -141,7 +141,7 @@ static RETSIGTYPE handle_crash(int); /* local variables */ int my_ruid, my_euid, my_rgid, my_egid; char initial_dir[PATH_MAX + 1]; -static char *ptydev = NULL, *ttydev = NULL; /* pty/tty name */ +static char *ptydev = NULL, *ttydev = NULL; /* pty/tty name */ int cmd_fd = -1; /* file descriptor connected to the command */ int pipe_fd = -1; pid_t cmd_pid = -1; /* process id if child */ @@ -150,6 +150,7 @@ 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 */ @@ -157,10 +158,12 @@ 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 */ static XIMStyle xim_input_style = 0; + # ifndef XSetIMValues extern char *XSetIMValues(XIM im, ...); # endif @@ -952,10 +955,10 @@ 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 */ + "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]) : ("")); @@ -1416,7 +1419,7 @@ get_tty(void) privileges(INVOKE); # ifndef __CYGWIN32__ - fchown(fd, my_ruid, gid); /* fail silently */ + fchown(fd, my_ruid, gid); /* fail silently */ fchmod(fd, mode); # endif privileges(REVERT); @@ -1673,28 +1676,28 @@ get_ttymode(ttymode_t *tio) /* 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_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_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 */ + 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)); @@ -1760,6 +1763,7 @@ create_fontset(const char *font1, const char *font2) #ifdef USE_XIM 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); @@ -1843,8 +1847,7 @@ xim_get_area(XRectangle * preedit_rect, XRectangle * status_rect, XRectangle * n 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->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; @@ -1995,9 +1998,7 @@ xim_real_init(void) 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); + 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. */ @@ -2270,12 +2271,14 @@ run_command(char **argv) return (ptyfd); } + +#ifdef ESCREEN + /***************************************************************************/ /* Escreen: callbacks */ /***********************/ -#ifdef ESCREEN -int +static int set_scroll_x(void *xd, int x) { USE_VAR(xd); @@ -2283,7 +2286,7 @@ set_scroll_x(void *xd, int x) return NS_FAIL; } -int +static int set_scroll_y(void *xd, int y) { USE_VAR(xd); @@ -2291,7 +2294,7 @@ set_scroll_y(void *xd, int y) return NS_FAIL; } -int +static int set_scroll_w(void *xd, int w) { USE_VAR(xd); @@ -2299,7 +2302,7 @@ set_scroll_w(void *xd, int w) return NS_FAIL; } -int +static int set_scroll_h(void *xd, int h) { USE_VAR(xd); @@ -2307,7 +2310,7 @@ set_scroll_h(void *xd, int h) return NS_FAIL; } -int +static int redraw(void *xd) { USE_VAR(xd); @@ -2315,7 +2318,7 @@ redraw(void *xd) return NS_FAIL; } -int +static int redraw_xywh(void *xd, int x, int y, int w, int h) { USE_VAR(xd); @@ -2323,8 +2326,7 @@ redraw_xywh(void *xd, int x, int y, int w, int h) return NS_FAIL; } -static button_t * -screen_button_create(char *text, char code) +static button_t *screen_button_create(char *text, char code) { button_t *b; char p[3]; @@ -2344,9 +2346,12 @@ screen_button_create(char *text, char code) /* 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) + otherwise, we'll create one. + xd address of the pointer to the buttonbar in question + after insert after which display? + name the display's name */ +static int +ins_disp(void *xd, int after, int as, char *name) { buttonbar_t *bbar; button_t *button; @@ -2357,12 +2362,10 @@ ins_disp(void *xd, int after, char *name) bbar = *((buttonbar_t **) xd); - if (!(button = screen_button_create(name, '0' + after + 1))) { + if (!(button = screen_button_create(name, '0' + as))) { return NS_FAIL; } - D_ESCREEN(("%s after %d...\n", name, after)); - if ((bbar = bbar_insert_button(bbar, button, after, FALSE))) { *((buttonbar_t **) xd) = bbar; return NS_SUCC; @@ -2372,7 +2375,8 @@ ins_disp(void *xd, int after, char *name) return NS_FAIL; } -# if 0 +#if 0 + /* add supa-dupa right buttons for screen-features. if our user's configured a bbar, we'll add to that, otherwise, we'll create one. */ @@ -2388,9 +2392,9 @@ add_screen_ctl_button(buttonbar_t **xd, char *name, char key) bbar = *xd; - if (!(button = screen_button_create(name, key))) { + if (!(button = screen_button_create(name, key))) return NS_FAIL; - } + if ((bbar = bbar_insert_button(bbar, button, -1, TRUE))) { *xd = bbar; return NS_SUCC; @@ -2399,11 +2403,12 @@ add_screen_ctl_button(buttonbar_t **xd, char *name, char key) button_free(button); return NS_FAIL; } -# endif +#endif /* delete n'th button - n index of the button (not screen, not data -- the button) */ -int + xd address of the pointer to the buttonbar in question + n index of the button (not screen, not data -- the button) */ +static int del_disp(void *xd, int n) { buttonbar_t *bbar = *((buttonbar_t **) xd); @@ -2413,16 +2418,6 @@ del_disp(void *xd, int n) REQUIRE_RVAL(bbar, NS_FAIL); REQUIRE_RVAL(bbar->buttons, NS_FAIL); -#if DEBUG >= DEBUG_ESCREEN - if (DEBUG_LEVEL >= DEBUG_ESCREEN) { - int c; - - for (c = 0, b2 = bbar->buttons; b2; c++, b2 = b2->next) { - D_ESCREEN(("%02d: \"%s\"\n", c, b2->text)); - } - } -#endif - b2 = button = bbar->buttons; if (n == 0) { bbar->buttons = bbar->buttons->next; @@ -2443,8 +2438,6 @@ del_disp(void *xd, int n) } } - D_ESCREEN(("deleting button %d (%s)...\n", bi, button->text)); - button->next = NULL; button_free(button); @@ -2454,12 +2447,12 @@ del_disp(void *xd, int n) } /* update the button-representation of a screen-display. - xd + xd address of the pointer to the buttonbar in question 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 +static int upd_disp(void *xd, int n, int flags, char *name) { buttonbar_t *bbar = *((buttonbar_t **) xd); @@ -2484,20 +2477,49 @@ upd_disp(void *xd, int n, int flags, char *name) return NS_SUCC; } +/* expire all buttons + xd address of the pointer to the buttonbar in question + n how many buttons do we want to throw out (normally all of them)? + <- error code */ +static int +expire_buttons(void *xd, int n) +{ + buttonbar_t *bbar = *((buttonbar_t **) xd); + button_t *b, *p; + + REQUIRE_RVAL(bbar, NS_FAIL); + if (n < 1) { + return NS_FAIL; + } + + if ((b = bbar->buttons)) { + for (; n; n--) { + p = b; + b = b->next; + } + p->next = NULL; + button_free(bbar->buttons); + bbar->buttons = b; + } + + return NS_SUCC; +} + /* display a status line the screen program sent us */ -int +static int err_msg(void *xd, int err, char *msg) { - char *sc[] = { "Copy mode", "Bell in" }; + char *sc[] = { "Copy mode", "Bell in", "Wuff, Wuff!!" }; int n, nsc = sizeof(sc) / sizeof(char *); - USE_VAR(xd); - USE_VAR(err); - /* there are certain things that would make sense if we were displaying a status-line; they do not, however, warrant an alert-box, so we drop them here. */ - if (msg && *msg) { + + USE_VAR(xd); + USE_VAR(err); + + if (strlen(msg)) { for (n = 0; n < nsc; n++) { if (!strncmp(msg, sc[n], strlen(sc[n]))) { break; @@ -2511,7 +2533,7 @@ err_msg(void *xd, int err, char *msg) } /* send text to the application (normally "screen") in the terminal */ -int +static int inp_text(void *xd, int id, char *txt) { USE_VAR(xd); @@ -2522,7 +2544,7 @@ inp_text(void *xd, int id, char *txt) } /* open a dialog */ -int +static int input_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (void *, char *, size_t, size_t)) { switch (menu_dialog(xd, prompt, maxlen, retstr, inp_tab)) { @@ -2536,19 +2558,21 @@ input_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) ( } /* run a program (normally "screen") inside the terminal */ -int +static int exe_prg(void *xd, char **argv) { USE_VAR(xd); return run_command(argv); } -/********************* Azundris' toys ***************************/ + +/****** Azundris' playthings :-) ******/ #define DIRECT_MASK (~(RS_Cursor|RS_Select|RS_fontMask)) #define COLOUR_MASK (RS_fgMask|RS_bgMask) #define DIRECT_SET_SCREEN(x,y,fg,bg) (screen.text[ys+y])[x]=fg; (screen.rend[ys+y])[x]=bg&DIRECT_MASK; #define CLEAR (1<<16) + static void direct_write_screen(int x, int y, char *fg, rend_t bg) { @@ -2569,10 +2593,12 @@ bosconian(int n) { int x, y; int ys = TermWin.saveLines - TermWin.view_start; + for (; n != 0; n--) { for (y = 0; y < TermWin.nrow; y++) { text_t *t = screen.text[ys + y]; rend_t *r = screen.rend[ys + y]; + for (x = 0; x < TermWin.ncol; x++) { t[x] = random() & 0xff; r[x] = random() & COLOUR_MASK; @@ -2588,10 +2614,12 @@ unbosconian(void) int x, y; int ys = TermWin.saveLines - TermWin.view_start; rend_t bg; + do { bg = CLEAR; for (y = 0; (bg == CLEAR) && y < TermWin.nrow; y++) { rend_t *r = screen.rend[ys + y]; + for (x = 0; (bg == CLEAR) && x < TermWin.ncol; x++) { if (r[x] != CLEAR) { bg = r[x]; @@ -2602,6 +2630,7 @@ unbosconian(void) for (y = 0; y < TermWin.nrow; y++) { text_t *t = screen.text[ys + y]; rend_t *r = screen.rend[ys + y]; + for (x = 0; x < TermWin.ncol; x++) { if (r[x] == bg) { r[x] = CLEAR; @@ -2613,12 +2642,11 @@ unbosconian(void) } } while (bg != CLEAR); } + #undef DIRECT_MASK #undef COLOUR_MASK #undef DIRECT_SET_SCREEN -#define MATRIX_HI CLEAR -#define MATRIX_LO ((4<<8)|CLEAR) static void matrix(int n) { @@ -2634,8 +2662,10 @@ matrix(int n) } MEMSET(s, 0, TermWin.ncol); +#define MATRIX_HI CLEAR +#define MATRIX_LO ((4<<8)|CLEAR) - for (; n != 0; n--) { + while (n--) { for (x = 0; x < TermWin.ncol; x++) { if (!(random() & 3)) { if ((y = s[x])) { @@ -2684,7 +2714,8 @@ matrix(int n) } break; - default: t[x] = random() & 0xff; /* hold */ + default: + t[x] = random() & 0xff; /* hold */ } } } @@ -2692,6 +2723,7 @@ matrix(int n) } FREE(s); } + #undef MATRIX_HI #undef MATRIX_LO @@ -2701,11 +2733,9 @@ waitstate(void *xd, int ms) { int y = 1; time_t dur = (time_t) (ms / 1000); -#if 0 - time_t fin = dur + time(NULL); -#endif USE_VAR(xd); + if (!(random() & 7)) { if (!(random() & 3)) { matrix(31); @@ -2725,8 +2755,10 @@ waitstate(void *xd, int ms) scr_refresh(FAST_REFRESH); sleep(dur); + return 0; } + #undef CLEAR /* Set everything up for escreen mode */ @@ -2745,6 +2777,7 @@ escreen_init(char **argv) ns_register_red(efuns, redraw); ns_register_rda(efuns, redraw_xywh); + ns_register_exb(efuns, expire_buttons); ns_register_ins(efuns, ins_disp); ns_register_del(efuns, del_disp); @@ -2767,7 +2800,7 @@ escreen_init(char **argv) menuitem_t *i; if (rs_delay >= 0) { - TermWin.screen->delay = rs_delay; /* more flexible ways later */ + TermWin.screen->delay = rs_delay; /* more flexible ways later */ } if ((m = menu_create(NS_MENU_TITLE))) { char *sc[] = { @@ -2793,11 +2826,8 @@ escreen_init(char **argv) int n, nsc = sizeof(sc) / sizeof(char *); if (menu_list) { - for (n = 0; n < menu_list->nummenus; n++) { /* blend in w/ l&f */ + for (n = 0; n < menu_list->nummenus; n++) { /* blend in w/ l&f */ if (menu_list->menus[n]->font) { -#ifdef NS_DEBUG - D_ESCREEN(("%d: %p\n", n, menu_list->menus[n]->font)); -#endif m->font = menu_list->menus[n]->font; m->fwidth = menu_list->menus[n]->fwidth; m->fheight = menu_list->menus[n]->fheight; @@ -2810,22 +2840,16 @@ escreen_init(char **argv) } for (n = 0; n < (nsc - 1); n += 2) { - if (!strcmp(sc[n], "-")) { /* separator */ + if (!strcmp(sc[n], "-")) { + /* separator */ if ((i = menuitem_create(NULL))) { menu_add_item(m, i); menuitem_set_action(i, MENUITEM_SEP, NULL); } - } /* menu entry */ - else if ((i = menuitem_create(sc[n]))) { + } else if ((i = menuitem_create(sc[n]))) { + /* menu entry */ menuitem_set_action(i, n && strcmp(sc[n + 1], NS_SCREEN_INIT) && strcmp(sc[n + 1], NS_SCREEN_PRVS_REG) ? MENUITEM_ECHO : MENUITEM_LITERAL, sc[n + 1]); -# ifdef NS_DEBUG - { - char buf[64]; - sprintf(buf, NS_PREFIX "escreen_menu: registered %s as", sc[n]); - ns_desc_string(i->action.string, buf); - } -# endif menu_add_item(m, i); } } @@ -2846,32 +2870,31 @@ escreen_init(char **argv) button_free(button); } else { int j, k = menu_list ? menu_list->nummenus : 0; + menu_list = menulist_add_menu(menu_list, m); - for (j = k; j < menu_list->nummenus; j++) + for (j = k; j < menu_list->nummenus; j++) { event_data_add_mywin(&menu_event_data, menu_list->menus[j]->win); + } if (!k) menu_init(); button_set_action(button, ACTION_MENU, NS_MENU_TITLE); } } } -/* add_screen_ctl_button(&buttonbar,"New",'c'); */ - cmd_fd = TermWin.screen->fd; - } else { - return -1; + /* add_screen_ctl_button(&buttonbar,"New",'c'); */ + return TermWin.screen->fd; } -# undef ETERM_PREFIX -# undef ESCREEN_PREFIX - return cmd_fd; + return -1; } - #endif + + /* init_command() */ void init_command(char **argv) { - int (*command_func)(char **); + int (*command_func) (char **); /* Use init function appropriate for how we were compiled. */ #ifdef ESCREEN @@ -2953,13 +2976,13 @@ cmd_write(const unsigned char *str, unsigned int count) /* 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 */ + n = (dst - cmdbuf_ptr); /* max # chars to insert */ if ((cmdbuf_endp + n) > dst) - cmdbuf_endp = (dst - n); /* truncate end if needed */ + cmdbuf_endp = (dst - n); /* truncate end if needed */ /* equiv: memmove ((cmdbuf_ptr+n), cmdbuf_ptr, n); */ src = cmdbuf_endp; @@ -3064,8 +3087,26 @@ cmd_getc(void) #endif } #ifdef ESCREEN - if (TermWin.screen_mode) - parse_screen_status_if_necessary(); + if (TermWin.screen) { + switch (TermWin.screen->backend) { + case NS_MODE_NONE: + break; + case NS_MODE_NEGOTIATE: +# ifdef NS_HAVE_SCREEN + case NS_MODE_SCREEN: + parse_screen_status_if_necessary(); + break; +# endif +# ifdef NS_HAVE_SCREAM + case NS_MODE_SCREAM: + break; +# endif + default: + D_ESCREEN(("mode %d not supported...\n", TermWin.screen->backend)); + TermWin.screen->backend = NS_MODE_NONE; + TermWin.screen_mode = NS_MODE_NONE; + } + } #endif /* characters already read in */ @@ -3075,7 +3116,7 @@ cmd_getc(void) for (;;) { v_doPending(); - while (XPending(Xdisplay)) { /* process pending X events */ + while (XPending(Xdisplay)) { /* process pending X events */ XEvent ev; @@ -3282,7 +3323,7 @@ main_loop(void) #endif do { - while ((ch = cmd_getc()) == 0); /* wait for something */ + 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; @@ -3321,8 +3362,7 @@ main_loop(void) 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)); + 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) { @@ -3397,7 +3437,7 @@ v_writeBig(int f, char *d, int len) */ if (len > 0) { - if (v_bufend < v_bufptr + len) { /* we've run out of room */ + 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 */ @@ -3410,7 +3450,7 @@ v_writeBig(int f, char *d, int len) 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 */ + int size = v_bufptr - v_buffer; /* save across realloc */ v_buffer = REALLOC(v_buffer, size + len); if (v_buffer) { @@ -3420,13 +3460,13 @@ v_writeBig(int f, char *d, int len) } else { /* no memory: ignore entire write request */ print_error("cannot allocate buffer space\n"); - v_buffer = v_bufstr; /* restore clobbered pointer */ + 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); */ + if (v_bufend >= v_bufptr + len) { /* new stuff will fit */ + memcpy(v_bufptr, d, len); /* bcopy(d, v_bufptr, len); */ v_bufptr += len; } } @@ -3452,13 +3492,13 @@ v_writeBig(int f, char *d, int len) } D_TTY(("Wrote %d characters\n", written)); v_bufstr += written; - if (v_bufstr >= v_bufptr) /* we wrote it all */ + 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 */ + if (v_bufend - v_bufptr > 1024) { /* arbitrary hysteresis */ /* save pointers across realloc */ int start = v_bufstr - v_buffer; int size = v_bufptr - v_buffer; @@ -3471,7 +3511,7 @@ v_writeBig(int f, char *d, int len) v_bufend = v_buffer + allocsize; } else { /* should we print a warning if couldn't return memory? */ - v_buffer = v_bufstr - start; /* restore clobbered pointer */ + v_buffer = v_bufstr - start; /* restore clobbered pointer */ } } } diff --git a/src/command.h b/src/command.h index b99a0e3..bd4ee03 100644 --- a/src/command.h +++ b/src/command.h @@ -238,6 +238,7 @@ if (test) PrivateModes |= (bit); else PrivateModes &= ~(bit);} while (0) #endif #define VT100_ANS "\033[?1;2c" /* vt100 answerback */ +#define LINUX_ANS "\033[?6;5c" /* linux answerback */ #ifndef ESCZ_ANSWER # define ESCZ_ANSWER VT100_ANS /* obsolete ANSI ESC[c */ #endif @@ -359,6 +360,7 @@ extern void init_locale(void); #else # define init_locale() ((void)0) #endif +extern int escreen_init(char **); extern int run_command(char **); extern void init_command(char **); extern void tt_winsize(int); diff --git a/src/defaultfont.c b/src/defaultfont.c index 6ae8d6d..7c6cf43 100644 --- a/src/defaultfont.c +++ b/src/defaultfont.c @@ -182,7 +182,7 @@ eterm_default_font_locale(char ***fonts, char ***mfonts, char **mencoding, int * if ((locale = getenv("LC_ALL")) == NULL) if ((locale = getenv("LC_CTYPE")) == NULL) if ((locale = getenv("LANG")) == NULL) - locale = "C"; /* failsafe */ + locale = "C"; /* failsafe */ /* Obtain a "normalized" name of current encoding. * The current encoding is available via nl_langinfo(). diff --git a/src/draw.c b/src/draw.c index 68a3ae9..c2adfa1 100644 --- a/src/draw.c +++ b/src/draw.c @@ -144,7 +144,7 @@ bevel_pixmap(Pixmap p, int w, int h, Imlib_Border * bord, unsigned char up) unsigned int r, g, b; int real_depth = 0, depth_factor; register int br, bg, bb; /* Bitshifts */ - register unsigned int mr, mg, mb; /* Bitmasks */ + register unsigned int mr, mg, mb; /* Bitmasks */ GC gc; if (!bord) diff --git a/src/e.c b/src/e.c index f4ee4ed..dccc778 100644 --- a/src/e.c +++ b/src/e.c @@ -144,7 +144,7 @@ enl_ipc_send(char *str) } } len = strlen(str); - for (; XCheckTypedWindowEvent(Xdisplay, my_ipc_win, ClientMessage, &ev);); /* Discard any out-of-sync messages */ + 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; diff --git a/src/eterm_debug.h b/src/eterm_debug.h index 3ac316d..b5545fe 100644 --- a/src/eterm_debug.h +++ b/src/eterm_debug.h @@ -72,7 +72,7 @@ # define DEBUG_ACTIONS 4 # define D_ACTIONS(x) DPRINTF4(x) # define DEBUG_ESCREEN 4 -# define D_ESCREEN(x) DPRINTF4(x) +# define D_ESCREEN(x) DPRINTF4(x) # define DEBUG_PROFILE 5 # define D_PROFILE(x) DPRINTF5(x) diff --git a/src/events.c b/src/events.c index 73fa903..2945655 100644 --- a/src/events.c +++ b/src/events.c @@ -46,6 +46,9 @@ static const char cvs_ident[] = "$Id$"; #include "scrollbar.h" #include "term.h" #include "windows.h" +#ifdef ESCREEN +# include "screamcfg.h" +#endif unsigned char paused = 0; event_master_t event_master; @@ -70,8 +73,7 @@ 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_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 */ } @@ -226,8 +228,7 @@ handle_property_notify(event_t *ev) 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)); + ((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) { @@ -267,8 +268,7 @@ handle_property_notify(event_t *ev) } #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)); + 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 @@ -333,8 +333,7 @@ handle_client_message(event_t *ev) unsigned char *data; unsigned long Size, RemainingBytes; - XGetWindowProperty(Xdisplay, Xroot, props[PROP_DND_SELECTION], 0L, 1000000L, False, AnyPropertyType, &ActualType, &ActualFormat, - &Size, &RemainingBytes, &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); @@ -453,8 +452,7 @@ handle_focus_in(event_t *ev) 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); + 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; @@ -517,8 +515,7 @@ handle_configure_notify(event_t *ev) 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)); + 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; @@ -740,6 +737,62 @@ handle_button_release(event_t *ev) D_EVENTS(("handle_button_release(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); +#ifdef ESCREEN + if (!XEVENT_IS_MYWIN(ev, &primary_data) && drag && TermWin.screen && TermWin.screen->backend && TermWin.screen->userdef) { + buttonbar_t *bbar = *((buttonbar_t **) (TermWin.screen->userdef)); + button_t *b; + int fm = 0, to = 0; + + if (!bbar || !(b = bbar->buttons)) { + return 0; + } + + while (b && (b != drag)) { + b = b->next; + fm++; + } + if (!b) { + /* dragged button is not on the bar with our displays on */ + return 0; + } + + if (bbar->current) { + b = bbar->buttons; + while (b && (b != bbar->current)) { + b = b->next; + to++; + } + if (!b) { + /* dragged-to button is not on the bar with our displays */ + return 0; + } + } + + if (!bbar->current) { + /* tab torn off */ + char *u = ns_get_url(TermWin.screen, fm); + + if (u) { + char *c; + size_t l = strlen(orig_argv0) + strlen(u) + 7; + + if ((c = MALLOC(l))) { + snprintf(c, l, "%s%s -U %s", ((orig_argv0[0] == '/') || ((orig_argv0[0] == '.') && (orig_argv0[1] == '/'))) ? "" : "./", orig_argv0, u); + D_ESCREEN(("(experimental) creating other frame using \"%s\"\n", c)); + (void) ns_run(TermWin.screen->efuns, c); + FREE(c); + } + FREE(u); + } + return 1; + } else if (buttonbar->current != drag) { + /* tab "moved" */ + ns_mov_disp(TermWin.screen, fm, to); + return 1; + } + } +#endif + if (button_state.ignore_release == 1) { button_state.ignore_release = 0; return 0; @@ -802,8 +855,11 @@ handle_motion_notify(event_t *ev) COUNT_EVENT(motion_cnt); REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); - if ((PrivateModes & PrivMode_mouse_report) && !(button_state.bypass_keystate)) + + if ((PrivateModes & PrivMode_mouse_report) && !(button_state.bypass_keystate)) { + mouse_drag_report(&(ev->xbutton)); return 1; + } if (ev->xany.window == TermWin.vt) { if (ev->xbutton.state & (Button1Mask | Button3Mask)) { @@ -812,8 +868,7 @@ handle_motion_notify(event_t *ev) 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); + 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) diff --git a/src/font.c b/src/font.c index d2db767..42f10de 100644 --- a/src/font.c +++ b/src/font.c @@ -44,6 +44,7 @@ char **etfonts = NULL; unsigned char font_idx = DEF_FONT_IDX, font_cnt = 0; int def_font_idx = DEF_FONT_IDX; char *rs_font[NFONTS]; + #ifdef MULTI_CHARSET char *rs_mfont[NFONTS]; char **etmfonts = NULL; @@ -229,15 +230,14 @@ font_cache_del(const void *info) 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))); + 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. */ + 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); @@ -455,8 +455,7 @@ change_font(int init, const char *fontname) 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; @@ -585,8 +584,7 @@ change_font(int init, const char *fontname) 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)) { + 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; @@ -634,7 +632,7 @@ change_font(int init, const char *fontname) fw = boldFont->min_bounds.width; fh = boldFont->ascent + boldFont->descent + rs_line_space; - if (TermWin.fprop == 0) { /* bold font must also be monospaced */ + if (TermWin.fprop == 0) { /* bold font must also be monospaced */ if (fw != boldFont->max_bounds.width) fw = -1; } else { @@ -651,8 +649,7 @@ change_font(int init, const char *fontname) 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)); + 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) { diff --git a/src/grkelot.c b/src/grkelot.c index 6edf51a..a8b856d 100644 --- a/src/grkelot.c +++ b/src/grkelot.c @@ -53,9 +53,9 @@ static const char cvs_ident[] = "$Id$"; # include /* --- Macros, Types --------- */ -# define MAX_STATES 4 /* max # states for the FSM */ -# define MAX_SWITCHER 2U /* per state */ -# define MAX_VAL 256 /* for temp allocation */ +# define MAX_STATES 4 /* max # states for the FSM */ +# define MAX_SWITCHER 2U /* per state */ +# define MAX_VAL 256 /* for temp allocation */ typedef unsigned char u_char; typedef unsigned int u_int; @@ -77,7 +77,7 @@ 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 */ + 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; @@ -109,10 +109,9 @@ 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," +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_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[] = @@ -123,7 +122,7 @@ 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_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[] = @@ -196,7 +195,7 @@ kstate_init_all(int greek_mode) kstate_setcurr(i); kstate_init(); } - if (greek_mode < 0 || greek_mode >= NUM_XLAT_TYPES) /* avoid death */ + if (greek_mode < 0 || greek_mode >= NUM_XLAT_TYPES) /* avoid death */ greek_mode = GREEK_ELOT928; xlat_now = &xlat_type[greek_mode]; kstate_setcurr(0); @@ -310,7 +309,7 @@ kstate_cxlat(unsigned int c) /* check for ascii switcher */ for (i = 0; i < pStateNow->num_switcher; i++) - if (pStateNow->switcher[i].type == 'A' && /* only ascii here */ + 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; diff --git a/src/libscream.c b/src/libscream.c index 761c719..96a4a8e 100644 --- a/src/libscream.c +++ b/src/libscream.c @@ -1,23 +1,27 @@ /**************************************************************************** * scream::libscream.c Azundris * - * routines to connect to screen and or scream daemons. + * routines for terminal emulators to connect to screen and/or scream daemons. * libscream is a double-transparency layer -- it abstracts the backend * (screen or a replacement, locally or ssh-tunneled) to the front-end - * (a terminal-emulation such as Eterm) and vice versa. + * (a terminal-emulation such as Eterm, konsole, or multi-gnome-terminal) + * and vice versa. several sessions can be open at once. * * Lesser GNU Public Licence applies. * Thread-safe: untested + * * 2002/04/19 Azundris incept * 2002/05/04 Azundris support for esoteric screens, thanks to Till * 2002/05/12 Azundris edit display names, send statement, tab completion * 2002/05/13 Azundris ssh tunnel through firewall * 2002/05/17 Azundris supports systemwide screenrc (thanks mej) * 2002/05/18 Azundris remote handling improved (thanks tillsan, tfing) + * 2002/05/21 Azundris code restruction, basic tab tear-off ***************************************************************************/ -#include "config.h" -#include "src/feature.h" + + +#undef NS_DEBUG #include /* stderr, fprintf, snprintf() */ #include /* bzero() */ @@ -32,7 +36,21 @@ #include /* isspace() */ #include /* errno */ -#include +#include "config.h" +#include "src/feature.h" + +/* use libast if we have it */ +#ifdef DEBUG_ESCREEN +# include +#else +# define MALLOC(a) malloc(a) +# define FREE(a) free(a) +# ifdef NS_DEBUG +# define D_ESCREEN(a) fprintf(stderr,a); +# else +# define D_ESCREEN(a) +# endif +#endif #include "scream.h" /* structs, defs, headers */ #include "screamcfg.h" /* user-tunables */ @@ -47,20 +65,6 @@ -/* 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_EFUN_EXISTS(p,s,d,e) (((p) = ns_get_efuns((s),(d))) && ((p)->e)) - - - /***************************************************************************/ /* module-global vars */ /**********************/ @@ -73,15 +77,80 @@ static _ns_hop *ha = NULL; /* anchor for hop list */ +/***************************************************************************/ +/* forward declarations */ +/************************/ + + + +static void ns_desc_hop(_ns_hop *, char *); +static int ns_parse_screenrc(_ns_sess *, char *, int); +static int ns_mov_screen_disp(_ns_sess *, int, int); +static _ns_sess *ns_dst_sess(_ns_sess **); + + + +/**************************************************************************** + _ _ _ _ _ + _ __ ___ (_) __| | __| | | ___ | | __ _ _ _ ___ _ __ +| '_ ` _ \| |/ _` |/ _` | |/ _ \ | |/ _` | | | |/ _ \ '__| +| | | | | | | (_| | (_| | | __/ | | (_| | |_| | __/ | +|_| |_| |_|_|\__,_|\__,_|_|\___| |_|\__,_|\__, |\___|_| + |___/ + +central abstraction layer + + this abstracts the front-end (terminal emulator) against the back-end + (local or remote terminal server), and the back-end against the front-end: + + - front-end hands us an URL we attach to (without knowing about the backend) + - CAL receives messages from back-end and calls the external function (efun) + the front-end registered for this event + - CAL functions are called from the front-end and send data fitting the + session-type to the backend +*/ + + + +/* 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_EFUN_EXISTS(p,s,d,e) (((p)=ns_get_efuns((s),(d)))&&((p)->e)) + + + /***************************************************************************/ /* constructors/destructors */ /****************************/ +/* ns_free + free a string (or whatever) */ + +static void +* +ns_free(char **x) +{ + if (x && !*x) { + FREE(*x); + *x = NULL; + } + return NULL; +} + + + /* ns_new_hop. create and initialize a hop struct. lp local port. if 0: if otherwise matching hop exists, reuse that. - otherwise, find the first free (as in, not used + otherwise, find the first FREE (as in, not used by us) port, starting with NS_MIN_PORT. fw firewall machine. numeric or symbolic. fp foreign port. if 0: default to SSH port. @@ -98,17 +167,16 @@ ns_new_hop(int lp, char *fw, int fp, int delay, _ns_sess * s) return NULL; if (!fp) - fp = get_ssh_port(); /* remote port defaults to SSH */ + fp = ns_get_ssh_port(); /* remote port defaults to SSH */ if (s) { /* see if we already have a matching hop. */ - while (h && !(((h->localport == lp) || (!lp)) && - (!strcmp(h->fw, fw)) && (h->fwport == fp) && (h->sess->port == s->port) && (!strcmp(h->sess->host, s->host)))) + while (h && !(((h->localport == lp) || (!lp)) && (!strcmp(h->fw, fw)) && (h->fwport == fp) && (h->sess->port == s->port) && (!strcmp(h->sess->host, s->host)))) h = h->next; if (h) { if (delay) - h->delay = delay; /* may change delay! */ + h->delay = delay; /* may change delay! */ h->refcount++; return h; } @@ -119,11 +187,13 @@ ns_new_hop(int lp, char *fw, int fp, int delay, _ns_sess * s) bzero(h, sizeof(_ns_hop)); if ((h->fw = strdup(fw))) { if (!lp) { - lp = NS_MIN_PORT; /* local port defaults to */ + lp = NS_MIN_PORT; /* local port defaults to */ if (ha) { /* NS_MIN_PORT. if that's */ - int f; /* taken, use next free port. */ - do { /* free as in, not used by us. */ + int f; /* taken, use next FREE port. */ + + do { /* FREE as in, not used by us. */ _ns_hop *i = ha; + f = 0; while (i) if (i->localport == lp) { @@ -155,7 +225,7 @@ ns_new_hop(int lp, char *fw, int fp, int delay, _ns_sess * s) /* ns_dst_hop. deref (and, where necessary, release) a hop struct. if sp is provided, additional integrity magic will take place. - ss hop to deref/free + ss hop to deref/FREE sp session that the hop used to belong to (NULL for none (as if)) <- NULL */ @@ -165,23 +235,19 @@ ns_dst_hop(_ns_hop ** ss, _ns_sess * sp) if (ss && *ss) { _ns_hop *s = *ss; -#ifdef NS_DEBUG_MEM if (s->refcount <= 0) { - D_ESCREEN(("leak alert -- trying to double-free hop...\n")); + D_ESCREEN(("ns_dst_hop: leak alert -- trying to double-FREE hop...\n")); return NULL; } -#endif - if (!--(s->refcount)) { /* was last ref to hop => free hop */ + if (!--(s->refcount)) { /* was last ref to hop => FREE hop */ if (s->fw) FREE(s->fw); -#ifdef NS_DEBUG_MEM - bzero(s, sizeof(_ns_hop)); -#endif if (ha == s) /* delist */ ha = s->next; else { _ns_hop *h = ha; + while (h && h->next != s) h = h->next; if (h) @@ -193,12 +259,11 @@ ns_dst_hop(_ns_hop ** ss, _ns_sess * sp) as it's probably about to die. fix the back ref to a session that's actually valid. */ _ns_sess *p = sa; + while (p && ((p == sp) || (p->port != sp->port) || (strcmp(p->host, sp->host)))) p = p->next; if (!p) - ns_desc_hop(s, - NS_PREFIX - "ns_dst_sess: Leak alert -- found a hop that is only\n referenced once, but has a refcount > 1. Hop data follow"); + ns_desc_hop(s, NS_PREFIX "ns_dst_sess: Leak alert -- found a hop that is only\n referenced once, but has a refcount > 1. Hop data follow"); else s->sess = p; } @@ -213,6 +278,7 @@ _ns_efuns * ns_new_efuns(void) { _ns_efuns *s = MALLOC(sizeof(_ns_efuns)); + if (s) { bzero(s, sizeof(_ns_efuns)); } @@ -234,11 +300,9 @@ ns_dst_efuns(_ns_efuns ** ss) { if (ss && *ss) { _ns_efuns *s = *ss; + *ss = NULL; if (!--(s->refcount)) { -#ifdef NS_DEBUG_MEM - bzero(s, sizeof(_ns_efuns)); -#endif FREE(s); } } @@ -251,29 +315,26 @@ static _ns_disp * ns_new_disp(void) { _ns_disp *s = MALLOC(sizeof(_ns_disp)); + if (s) { bzero(s, sizeof(_ns_disp)); } return s; } -_ns_sess *ns_dst_sess(_ns_sess **); /* forward, sorry */ - static _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)); if (s->child) /* nested screen? */ - ns_dst_sess(&(s->child)); /* forward, sorry */ + ns_dst_sess(&(s->child)); *ss = NULL; -#ifdef NS_DEBUG_MEM - bzero(s, sizeof(_ns_disp)); -#endif FREE(s); } return NULL; @@ -284,6 +345,7 @@ ns_dst_dsps(_ns_disp ** ss) { if (ss && *ss) { _ns_disp *s = *ss, *t; + *ss = NULL; do { t = s->next; @@ -300,14 +362,16 @@ static _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; + s->escape = NS_SCREEN_ESCAPE; /* default setup for the screen program */ + s->literal = NS_SCREEN_LITERAL; /* set even ifndef NS_HAVE_SCREEN */ s->dsbb = NS_SCREEN_DEFSBB; s->delay = NS_INIT_DELAY; if (sa) { /* add to end of list */ _ns_sess *r = sa; + while (r->next) r = r->next; r->next = s; @@ -317,11 +381,12 @@ ns_new_sess(void) return s; } -_ns_sess * +static _ns_sess * ns_dst_sess(_ns_sess ** ss) { if (ss && *ss) { _ns_sess *s = *ss; + ns_dst_dsps(&(s->dsps)); if (s->hop) ns_dst_hop(&(s->hop), s); @@ -340,9 +405,6 @@ ns_dst_sess(_ns_sess ** ss) if (s->next) s->next->prvs = s->prvs; *ss = NULL; -#ifdef NS_DEBUG_MEM - bzero(s, sizeof(_ns_sess)); -#endif FREE(s); } return NULL; @@ -352,168 +414,136 @@ ns_dst_sess(_ns_sess ** ss) /***************************************************************************/ -/* send commands to screen */ -/***************************/ +/* display-list handling */ +/*************************/ -/* 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 */ +/* 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 */ + +static _ns_disp * +disp_fetch(_ns_sess * s, int n) +{ + _ns_disp *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 */ + +static _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 (!d->sess->curr) /* note as current on session if first display */ + d->sess->curr = d; + + 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 -ns_screen_command(_ns_sess * sess, char *cmd) +disp_get_real_by_screen(_ns_sess * screen, int n) { - _ns_efuns *efuns; - char *c; - int ret = NS_SUCC; + _ns_disp *d2 = screen->dsps; + int r = 0; - if (!cmd || !*cmd) { - return NS_FAIL; + while (d2 && d2->index != n) { + d2 = d2->next; + r++; } - - if (NS_EFUN_EXISTS(efuns, sess, NULL, inp_text)) { - if ((c = strdup(cmd))) { - char *p; /* replace default escape-char with that */ - - for (p = c; *p; p++) { /* actually used in this session */ - if (*p == NS_SCREEN_ESCAPE) { - *p = sess->escape; - } - } -#ifdef NS_DEBUG - ns_desc_string(c, "ns_screen_command: xlated string"); +#ifdef NS_PARANOID + if (!d2) + return -1; #endif - efuns->inp_text(NULL, sess->fd, c); - FREE(c); - } else { - /* out of memory */ - ret = NS_OOM; - } + 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_PARANOID + 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 */ + +static 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 { - ret = NS_EFUN_NOT_SET; - D_ESCREEN(("sess->efuns->inp_text not set!\n")); + d3->sess->dsps = d3->next; + if (d3->sess->curr == d3) + d3->sess->curr = d3->next; } - return ret; -} - - - -/* send a single command string to screen, adding the equiv of ^A: - s the session - cmd the command string - <- error code */ - -int -ns_screen_xcommand(_ns_sess * s, char prefix, char *cmd) -{ - char *i; - int ret = NS_OOM; - if ((i = MALLOC(strlen(cmd) + 4))) { - size_t l = strlen(cmd) + 2; - strcpy(&i[2], cmd); - i[0] = s->escape; - i[1] = prefix; - i[l] = '\n'; - i[++l] = '\0'; - ret = ns_screen_command(s, i); - FREE(i); - } - 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); -} - - - -/* ns_input_dialog - open a dialog - s the session - !retstr where we'll store a pointer to the result (the user's input) - prompt the prompt to appear in the dialog box - <- msg */ - - -int -ns_input_dialog(_ns_sess * s, char *prompt, int maxlen, char **retstr, int (*inp_tab) (void *, char *, size_t, size_t)) -{ - _ns_efuns *efuns; - char *c; - int ret = NS_SUCC; - - if (NS_EFUN_EXISTS(efuns, s, NULL, input_dialog)) { - (void) efuns->input_dialog((void *) s, prompt, maxlen, retstr, inp_tab); - } else { - ret = NS_EFUN_NOT_SET; - D_ESCREEN(("sess->efuns->input_dialog not set!\n")); - } - return ret; + if (d3->next) + d3->next->prvs = d3->prvs; + ns_dst_disp(&d3); } @@ -532,10 +562,12 @@ ns_input_dialog(_ns_sess * s, char *prompt, int maxlen, char **retstr, int (*inp int ns_sess_init(_ns_sess * sess) { +#ifdef NS_HAVE_SCREEN if ((sess->backend == NS_MODE_NEGOTIATE) || (sess->backend == NS_MODE_SCREEN)) { (void) ns_parse_screenrc(sess, sess->sysrc, NS_ESC_SYSSCREENRC); return ns_parse_screenrc(sess, sess->home, NS_ESC_SCREENRC); } +#endif return NS_SUCC; } @@ -545,10 +577,11 @@ ns_sess_init(_ns_sess * sess) <- a port number -- 22 in all likelihood. */ int -get_ssh_port(void) +ns_get_ssh_port(void) { static int port = 0; struct servent *srv; + if (port) return port; /* (fixme) replace with getservbyname_r on systems that have it */ @@ -567,10 +600,10 @@ get_ssh_port(void) <- a hop struct, or NULL */ -_ns_hop * +static _ns_hop * ns_parse_hop(_ns_sess * s, char *h) { - char *p = h, *e, *fw = NULL; + char *p = h, *e; int f = 0, v, lp = 0, fp = 0, delay = 0; if (!h || !*h) @@ -619,31 +652,32 @@ ns_parse_hop(_ns_sess * s, char *h) doc context-info !stdout the string, in human-readable form */ -void +static void ns_desc_string(char *c, char *doc) { char *p = c; - if (doc) - D_ESCREEN((" ", doc)); + if (doc) { + D_ESCREEN(("%s: ", doc)); + } if (!c) { - fputs("NULL\n", stderr); + D_ESCREEN(("NULL\n")); return; } else if (!*c) { - fputs("empty\n", stderr); + D_ESCREEN(("empty\n")); return; } while (*p) { if (*p < ' ') - fprintf(stderr, "^%c", *p + 'A' - 1); + D_ESCREEN(("^%c", *p + 'A' - 1)); else - fputc(*p, stderr); + D_ESCREEN(("%c", *p)); p++; } - fputs("\n", stderr); + D_ESCREEN(("\n")); return; } @@ -656,20 +690,19 @@ ns_desc_string(char *c, char *doc) doc: info about the context ! stderr: info about the hop */ -void +static void ns_desc_hop(_ns_hop * h, char *doc) { if (!h && doc) { - D_ESCREEN(("ns_desc_hop called with broken pointer!\n", doc)); + D_ESCREEN(("%s: ns_desc_hop called with broken pointer!\n", doc)); return; } if (doc) - D_ESCREEN(("\n", doc)); + D_ESCREEN(("%s:\n", doc)); - fprintf(stderr, NS_PREFIX "tunnel from localhost:%d to %s:%d to %s:%d is %s. (delay %d, %d ref%s)\n", - h->localport, h->fw, h->fwport, - h->sess->host, h->sess->port, h->established ? "up" : "down", h->delay, h->refcount, h->refcount == 1 ? "" : "s"); + D_ESCREEN(("tunnel from localhost:%d to %s:%d to %s:%d is %s. (delay %d, %d ref%s)\n", + h->localport, h->fw, h->fwport, h->sess->host, h->sess->port, h->established ? "up" : "down", h->delay, h->refcount, h->refcount == 1 ? "" : "s")); } @@ -680,31 +713,29 @@ ns_desc_hop(_ns_hop * h, char *doc) doc: info about the context ! stderr: info about the session */ -void +static void ns_desc_sess(_ns_sess * sess, char *doc) { if (!sess) { - D_ESCREEN(("ns_desc_sess called with broken pointer!\n", doc)); - fflush(stderr); + D_ESCREEN(("%s: ns_desc_sess called with broken pointer!\n", doc)); return; } if (sess->where == NS_LCL) - D_ESCREEN(("(efuns@%p)\t (user %s) local %s", doc, sess->efuns, sess->user, sess->proto)); + D_ESCREEN(("%s: (efuns@%p)\t (user %s) local %s", doc, sess->efuns, sess->user, sess->proto)); else { - fprintf(stderr, NS_PREFIX "%s: (efuns@%p)\t %s://%s%s%s@%s", - doc, sess->efuns, sess->proto, sess->user, sess->pass ? ":" : "", sess->pass ? sess->pass : "", sess->host); + D_ESCREEN(("%s: (efuns@%p)\t %s://%s%s%s@%s", + doc, sess->efuns, sess->proto ? sess->proto : "???", sess->user, sess->pass ? ":" : "", sess->pass ? sess->pass : "", sess->host)); if (sess->port != NS_DFLT_SSH_PORT) - fprintf(stderr, ":%s", sess->port); + D_ESCREEN((":%s", sess->port)); } - fprintf(stderr, "%c%s\n", sess->where == NS_LCL ? ' ' : '/', sess->rsrc); + D_ESCREEN(("%c%s\n", sess->where == NS_LCL ? ' ' : '/', sess->rsrc)); if (sess->hop) ns_desc_hop(sess->hop, NULL); if (sess->sysrc) - D_ESCREEN(("searching for sysrc in %s\n", sess->sysrc)); + D_ESCREEN(("%s: searching for sysrc in %s\n", doc, sess->sysrc)); if (sess->home) - D_ESCREEN(("searching for usrrc in %s\n", sess->home)); - D_ESCREEN(("escapes set to ^%c-%c\n", sess->escape + 'A' - 1, sess->literal)); - fflush(stderr); + D_ESCREEN(("%s: searching for usrrc in %s\n", doc, sess->home)); + D_ESCREEN(("%s: escapes set to ^%c-%c\n", doc, sess->escape + 'A' - 1, sess->literal)); } @@ -728,9 +759,7 @@ ns_run(_ns_efuns * efuns, char *cmd) goto fail; if (cmd && *cmd) { /* count args (if any) */ -#ifdef NS_DEBUG - D_ESCREEN(("executing \"%s\"...\n", cmd)); -#endif + D_ESCREEN(("ns_run: executing \"%s\"...\n", cmd)); do { n++; while (*p && *p != ' ') { @@ -759,8 +788,8 @@ ns_run(_ns_efuns * efuns, char *cmd) 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 */ + if (*p == '\"') { /* leave quoting stuff together as one arg */ + args[c] = &p[1]; /* but remove the quote signs */ do { p++; if (s) @@ -796,12 +825,12 @@ ns_run(_ns_efuns * efuns, char *cmd) tmpl the template. should contain one %s dflt the default value opt the user-supplied value (or NULL) - <- a new malloc'd string (or NULL) */ + <- a new MALLOC'd string (or NULL) */ -char * +static char * ns_make_call_el(char *tmpl, char *dflt, char *opt) { - size_t l, r; + int l, r; char *p; if (tmpl && dflt && *tmpl && strstr(tmpl, "%s")) { @@ -819,7 +848,7 @@ ns_make_call_el(char *tmpl, char *dflt, char *opt) -char * +static char * ns_make_call(_ns_sess * sess) { char *call, *tmp = NULL, *screen = NULL, *scream = NULL, *screem = NULL; @@ -827,24 +856,27 @@ ns_make_call(_ns_sess * sess) /* unless decidedly in other mode... */ if (sess->backend != NS_MODE_SCREEN) tmp = scream = ns_make_call_el(NS_SCREAM_CALL, NS_SCREAM_OPTS, sess->rsrc); +#ifdef NS_HAVE_SCREEN if (sess->backend != NS_MODE_SCREAM) tmp = screen = ns_make_call_el(NS_SCREEN_CALL, NS_SCREEN_OPTS, sess->rsrc); +#endif if (sess->backend == NS_MODE_NEGOTIATE) { - size_t r, l = strlen(NS_SCREEM_CALL) + strlen(scream) + strlen(screen) - 3; + int r, l = strlen(NS_SCREEM_CALL) + (scream ? strlen(scream) : 0) + (screen ? strlen(screen) : 0) - 3; + if ((screem = MALLOC(l))) { - r = snprintf(screem, l, NS_SCREEM_CALL, scream, screen); + r = snprintf(screem, l, NS_SCREEM_CALL, scream ? scream : "", screen ? screen : ""); #ifdef NS_PARANOID if ((r < 0) || (r > l)) { - FREE(screem); + ns_free(&screem); } #endif } tmp = screem; } call = ns_make_call_el(NS_WRAP_CALL, tmp, NULL); - FREE(screen); - FREE(scream); - FREE(screem); + ns_free(&screen); + ns_free(&scream); + ns_free(&screem); return call; } @@ -854,7 +886,7 @@ ns_make_call(_ns_sess * sess) sp the session <- NS_FAIL, or the result of ns_run() */ -int +static int ns_attach_lcl(_ns_sess ** sp) { _ns_sess *sess; @@ -866,12 +898,13 @@ ns_attach_lcl(_ns_sess ** sp) sess = *sp; - if (call = ns_make_call(sess)) { + if ((call = ns_make_call(sess))) { char *c2 = ns_make_call_el("/bin/sh -c \"%s\"", call, NULL); - FREE(call); + + ns_free(&call); if (c2) { ret = ns_run(sess->efuns, c2); - FREE(c2); + ns_free(&c2); } } return ret; @@ -883,7 +916,7 @@ ns_attach_lcl(_ns_sess ** sp) sp the session <- -1, or the result of ns_run() */ -int +static int ns_attach_ssh(_ns_sess ** sp) { _ns_sess *sess; @@ -899,10 +932,9 @@ ns_attach_ssh(_ns_sess ** sp) call = ns_make_call(sess); if (sess->hop) { - if (sess->hop->established == NS_HOP_DOWN) { /* the nightmare foe */ + if (sess->hop->established == NS_HOP_DOWN) { /* the nightmare foe */ ret = snprintf(cmd, NS_MAXCMD, "%s %s -p %d -L %d:%s:%d %s@%s", - NS_SSH_CALL, NS_SSH_TUNNEL_OPTS, - sess->hop->fwport, sess->hop->localport, sess->host, sess->port, sess->user, sess->hop->fw); + NS_SSH_CALL, NS_SSH_TUNNEL_OPTS, sess->hop->fwport, sess->hop->localport, sess->host, sess->port, sess->user, sess->hop->fw); if (ret < 0 || ret > NS_MAXCMD) return NS_FAIL; ns_run(sess->efuns, cmd); @@ -912,14 +944,10 @@ ns_attach_ssh(_ns_sess ** sp) NS_SSH_CALL, NS_SSH_OPTS, sess->hop->localport, sess->user, call, sess->escape + 'A' - 1, sess->literal); } else { ret = - snprintf(cmd, NS_MAXCMD, "%s %s -p %d %s@%s \"%s -e^%c%c\"", NS_SSH_CALL, NS_SSH_OPTS, sess->port, sess->user, sess->host, call, - sess->escape + 'A' - 1, sess->literal); + snprintf(cmd, NS_MAXCMD, "%s %s -p %d %s@%s \"%s -e^%c%c\"", NS_SSH_CALL, NS_SSH_OPTS, sess->port, sess->user, sess->host, call, sess->escape + 'A' - 1, sess->literal); } - FREE(call); -#ifdef NS_DEBUG - fprintf(stderr, "\n\n>>%s\n>>%s\n\n", call, cmd); - fflush(stderr); -#endif + ns_free(&call); + return (ret < 0 || ret > NS_MAXCMD) ? NS_FAIL : ns_run(sess->efuns, cmd); } @@ -938,7 +966,6 @@ ns_attach_by_sess(_ns_sess ** sp, int *err) { _ns_sess *sess; int err_dummy; - char *p; if (!err) err = &err_dummy; @@ -948,9 +975,7 @@ ns_attach_by_sess(_ns_sess ** sp, int *err) return NULL; sess = *sp; -#ifdef NS_DEBUG ns_desc_sess(sess, "ns_attach_by_sess()"); -#endif (void) ns_sess_init(sess); @@ -962,6 +987,9 @@ ns_attach_by_sess(_ns_sess ** sp, int *err) /* local session, but for a different uid. */ /* FALL-THROUGH */ case NS_SSH: + if (!sess->delay) { + sess->delay = NS_INIT_DELAY ? NS_INIT_DELAY : 1; + } sess->fd = ns_attach_ssh(&sess); break; default: @@ -969,9 +997,7 @@ ns_attach_by_sess(_ns_sess ** sp, int *err) goto fail; } -#ifdef NS_DEBUG - D_ESCREEN(("screen session-fd is %d, ^%c-%c\n", sess->fd, sess->escape + 'A' - 1, sess->literal)); -#endif + D_ESCREEN(("ns_attach_by_sess: screen session-fd is %d, ^%c-%c\n", sess->fd, sess->escape + 'A' - 1, sess->literal)); return sess; @@ -1022,7 +1048,7 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) if (!(d = strdup(url))) goto fail; - if ((q = strstr(d, "://"))) { /* protocol, if any */ + if ((q = strstr(d, "://"))) { /* protocol, if any */ *q = '\0'; if (!(sess->proto = strdup(d))) goto fail; @@ -1030,13 +1056,14 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) } else q = d; - if ((p = strchr(q, '@'))) { /* user, if any */ + if ((p = strchr(q, '@'))) { /* user, if any */ char *r; + if (p != q) { /* ignore empty user */ *p = '\0'; - if ((r = strchr(q, ':'))) { /* password, if any */ + if ((r = strchr(q, ':'))) { /* password, if any */ *(r++) = '\0'; - if (!(sess->pass = strdup(r))) /* password may be empty string! */ + if (!(sess->pass = strdup(r))) /* password may be empty string! */ goto fail; } sess->user = strdup(q); @@ -1049,6 +1076,7 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) if (strlen(p)) { char *r = p; int f; + while (*r) { if (*r == '+') *(r++) = ' '; @@ -1056,6 +1084,7 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) long v; char *e; char b[3]; + b[0] = r[1]; b[1] = r[2]; b[2] = '\0'; @@ -1070,32 +1099,33 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) r = p; f = 0; while (*r) { - if (*r == ' ') { /* Padding between arguments */ + if (*r == ' ') { /* Padding between arguments */ while (*r == ' ') r++; } else { if (*r == '-') { - if (*(++r) == 'e') { /* set escape */ +# ifdef NS_HAVE_SCREEN + if (*(++r) == 'e') { /* set escape */ char x = 0, y = 0; + while (*(++r) == ' '); if ((x = ns_parse_esc(&r)) && (y = ns_parse_esc(&r))) { sess->escape = x; sess->literal = y; sess->escdef = NS_ESC_CMDLINE; } - } else if (*r == 'c') { /* alt screenrc */ + } else if (*r == 'c') { /* alt screenrc */ char *rc, *rx; + while (*(++r) == ' '); if ((rx = strchr(r, ' '))) *rx = '\0'; if (*r != '/') - D_ESCREEN(("path for screen's option -c should be absolute (%s)\n", r)); + D_ESCREEN(("URL: path for screen's option -c should be absolute (%s)\n", r)); if ((rc = strdup(r))) { - if (sess->home) /* this should never happen */ + if (sess->home) /* this should never happen */ FREE(sess->home); -#ifdef NS_DEBUG - D_ESCREEN(("searching for rc in %s\n", rc)); -#endif + D_ESCREEN(("URL: searching for rc in %s\n", rc)); sess->home = rc; } if (rx) { @@ -1103,13 +1133,14 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) *rx = ' '; } } +# endif while (*r && (f || *r != ' ')) { if (*r == '\"') f = 1 - f; r++; } } - while (*r && *r != ' ') /* proceed to space */ + while (*r && *r != ' ') /* proceed to space */ r++; } } @@ -1119,7 +1150,7 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) } } - if ((p = strchr(q, ':'))) { /* port, if any */ + if ((p = strchr(q, ':'))) { /* port, if any */ *(p++) = '\0'; if (!*p || !(sess->port = atoi(p)) || sess->port > NS_MAX_PORT) { *err = NS_MALFORMED_URL; @@ -1127,7 +1158,7 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) } } - if (strlen(q) && !(sess->host = strdup(q))) /* host, if any */ + if (strlen(q) && !(sess->host = strdup(q))) /* host, if any */ goto fail; FREE(d); @@ -1142,24 +1173,32 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) } if (!(sess->user = strdup(pwe->pw_name))) goto fail; - } else if (pwe && strcmp(pwe->pw_name, sess->user)) { /* user!=current_user */ + } else if ((sess->host && strcmp(sess->host, "localhost") && strcmp(sess->host, "127.0.0.1")) || sess->port) { + pwe = NULL; + } else if (!pwe || strcmp(pwe->pw_name, sess->user)) { /* user!=current_user */ sess->where = NS_SU; - if (!(pwe = getpwnam(sess->user)) && !sess->host && !sess->port) { + if (!(pwe = getpwnam(sess->user))) { *err = NS_UNKNOWN_USER; goto fail; } + } else { + *err = NS_UNKNOWN_USER; + goto fail; } - if (getenv("SYSSCREENRC")) { /* $SYSSCREENRC */ + +#ifdef NS_HAVE_SCREEN + if (getenv("SYSSCREENRC")) { /* $SYSSCREENRC */ if (!(sess->sysrc = strdup(getenv("SCREENRC")))) goto fail; } else { - char *loc[] = { "/usr/local/etc/screenrc", /* official */ + char *loc[] = { "/usr/local/etc/screenrc", /* official */ "/etc/screenrc", /* actual (on SuSE) */ "/usr/etc/screenrc", "/opt/etc/screenrc" }; int n, nloc = sizeof(loc) / sizeof(char *); + for (n = 0; n < nloc; n++) if (!access(loc[n], R_OK)) { if (!(sess->sysrc = strdup(loc[n]))) @@ -1170,11 +1209,11 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) if (getenv("SCREENRC")) { /* $SCREENRC */ sess->home = strdup(getenv("SCREENRC")); - } else if (pwe && !sess->home) { /* ~/.screenrc */ + } else if (pwe && !sess->home) { /* ~/.screenrc */ if ((sess->home = MALLOC(strlen(pwe->pw_dir) + strlen(NS_SCREEN_RC) + 2))) sprintf(sess->home, "%s/%s", pwe->pw_dir, NS_SCREEN_RC); - } else - goto fail; + } +#endif if (!sess->host) { /* no host */ if (!(sess->host = strdup("localhost"))) @@ -1182,23 +1221,25 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) if (!sess->port) { /* no host/port */ sess->where = NS_LCL; } - } else if ((p = strchr(sess->host, '/'))) /* have host */ + } else if ((p = strchr(sess->host, '/'))) /* have host */ *p = '\0'; if (!sess->port) /* no port -> default port (SSH) */ - sess->port = get_ssh_port(); + sess->port = ns_get_ssh_port(); sess->backend = NS_MODE_NEGOTIATE; - if (!sess->proto) { - if (!(sess->proto = strdup("screXX"))) + if (sess->proto) { +#ifdef NS_HAVE_SCREEN + if (!strcmp(sess->proto, "screen")) { + sess->backend = NS_MODE_SCREEN; + } else +#endif + if (!strcmp(sess->proto, "scream")) { + sess->backend = NS_MODE_SCREAM; + } else { + *err = NS_UNKNOWN_PROTO; 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) { @@ -1210,7 +1251,7 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) if (hop && strlen(hop)) { sess->hop = ns_parse_hop(sess, hop); if (sess->hop && (!strcmp(sess->host, sess->hop->fw) || !strcmp(sess->host, "localhost") || !strcmp(sess->host, "127.0.0.1"))) - D_ESCREEN(("routing in circles...\n")); + D_ESCREEN(("ns_attach_by_URL: routing in circles...\n")); } *err = NS_SUCC; @@ -1231,310 +1272,439 @@ ns_attach_by_URL(char *url, char *hop, _ns_efuns ** ef, int *err, void *xd) int ns_detach(_ns_sess ** sess) { -#ifdef NS_DEBUG ns_desc_sess(*sess, "ns_detach"); -#endif (void) ns_dst_sess(sess); return NS_SUCC; } -/***************************************************************************/ -/* messages to the client */ -/* (register callbacks) */ -/**************************/ +/**************************************************************************** + ____ _ _ +| __ ) __ _ ___| | __ ___ _ __ __| | +| _ \ / _` |/ __| |/ /____ / _ \ '_ \ / _` | +| |_) | (_| | (__| <_____| __/ | | | (_| | +|____/ \__,_|\___|_|\_\ \___|_| |_|\__,_| + + +backend abstraction (utils) + + this abstracts the backend against the frontend; the terminal-emulator + calls these functions without knowing what the backend is. */ -/* function that moves horizontal scrollbar to x/1000 % of width */ -void -ns_register_ssx(_ns_efuns * efuns, int (*set_scroll_x) (void *, int)) +/* scroll horizontally to column x (dummy) */ +int +ns_scroll2x(_ns_sess * s, int x) { - efuns->set_scroll_x = set_scroll_x; + return NS_FAIL; } -/* function that moves vertical scrollbar to y/1000 % of height */ -void -ns_register_ssy(_ns_efuns * efuns, int (*set_scroll_y) (void *, int)) +/* scroll vertically so line y of the scrollback buffer is the top line */ +int +ns_scroll2y(_ns_sess * s, int y) { - efuns->set_scroll_y = set_scroll_y; + return NS_FAIL; } -/* function that sets horizontal scrollbar to w/1000 % of width */ -void -ns_register_ssw(_ns_efuns * efuns, int (*set_scroll_w) (void *, int)) +/* go to display #d */ +int +ns_go2_disp(_ns_sess * s, int d) { - efuns->set_scroll_w = set_scroll_w; -} + char b[] = "\x01_"; -/* 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; -} - - - -/* function that will open a dialog */ -void -ns_register_inp(_ns_efuns * efuns, int (*input_dialog) (void *, char *, int, char **, int (*)(void *, char *, size_t, size_t))) -{ - efuns->input_dialog = input_dialog; -} - - - -/* function that will handle tab-completion in a dialog */ -void -ns_register_tab(_ns_efuns * efuns, int (*inp_tab) (void *, char *[], int, char *, size_t, size_t)) -{ - efuns->inp_tab = inp_tab; -} - - - -/* function that will do whatever while waiting */ -void -ns_register_fun(_ns_efuns * efuns, int (*inp_fun) (void *, int)) -{ - efuns->waitstate = inp_fun; -} - - - -/* 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; + switch (s->backend) { +#ifdef NS_HAVE_SCREEN + case NS_MODE_SCREEN: + b[1] = '0' + d; + return ns_screen_command(s, b); +#endif + default: + 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) +{ + switch (s->backend) { + default: + return NS_FAIL; + } +} + + +/* move client display #fm to display slot #to */ +int +ns_mov_disp(_ns_sess * s, int fm, int to) +{ + _ns_efuns *efuns; + _ns_disp *d; + int n = 0; + + if (fm == to) + return NS_SUCC; + + if (!(d = s->dsps)) /* this should never happen */ + return NS_FAIL; + + while (d) { + n++; + d = d->next; + } + + d = s->dsps; + + if ((fm < 0) || (to < 0)) + return NS_FAIL; + + fm = disp_get_screen_by_real(s, fm); + to = disp_get_screen_by_real(s, to); + + while (d->next) /* find last display */ + d = d->next; + + switch (s->backend) { +#ifdef NS_HAVE_SCREEN + case NS_MODE_SCREEN: + D_ESCREEN(("ns_mov_disp: move #%d to #%d\n", fm, to)); + +#if 0 + while (d && (d->index >= to)) { + ns_mov_screen_disp(s, d->index, d->index + 1); + d = d->prvs; + } + ns_mov_screen_disp(s, fm + (to < fm) ? 1 : 0, to); + + /* done. now unsparse. */ + if (to > fm) { /* moved right */ + d = s->dsps; + while (d->index != fm) + d = d->next; + while (d) { + ns_mov_screen_disp(s, d->index, d->index - 1); + d = d->next; + } + } +#else + ns_mov_screen_disp(s, fm, to); +#endif + if (NS_EFUN_EXISTS(efuns, s, NULL, expire_buttons)) { + efuns->expire_buttons(s->userdef, n); + } + + break; +#endif + } + return NS_FAIL; +} + +/* resize display #d to w*h */ +int +ns_rsz_disp(_ns_sess * s, int d, int w, int h) +{ + switch (s->backend) { + default: + return NS_FAIL; + } +} + +/* remove display #d */ +int +ns_rem_disp(_ns_sess * s, int d) +{ + char *b = "\x01_\x01ky\r"; + + switch (s->backend) { +#ifdef NS_HAVE_SCREEN + case NS_MODE_SCREEN: +# if 0 + b[1] = '0' + d; + return ns_screen_command(s, b); +# endif + return ns_parse_screen_key(s, NS_SCREEN_KILL); +#endif + default: + return NS_FAIL; + } +} + +/* rename display #d to "name" */ +int +ns_ren_disp(_ns_sess * s, int d, char *name) +{ + switch (s->backend) { +#ifdef NS_HAVE_SCREEN + case NS_MODE_SCREEN: + if (!name || !*name) + return ns_parse_screen_key(s, NS_SCREEN_RENAME); +#endif + } + return NS_FAIL; +} + +/* log activity in display #d to file "logfile" */ +int +ns_log_disp(_ns_sess * s, int d, char *logfile) +{ + switch (s->backend) { + default: + return NS_FAIL; + } +} + +/* force an update of the status line */ +int +ns_upd_stat(_ns_sess * s) +{ + switch (s->backend) { +#ifdef NS_HAVE_SCREEN + case NS_MODE_SCREEN: + return ns_screen_command(s, NS_SCREEN_UPDATE); +#endif + default: + return NS_FAIL; } - if (!d) - d = s->curr; - if (d && d->efuns) - return d->efuns; - else - return s->efuns; } -/***************************************************************************/ -/* 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) +char * +ns_get_url(_ns_sess * s, int d) { - _ns_disp *d, *e = NULL, *c; + int r, l; + char *u; + char esc[] = "^_\0"; + char lit[] = "^_\0"; + + if (!s) { + return NULL; + } + + l = ((s->proto) ? strlen(s->proto) + 3 : 0) + strlen(s->user) + 1 + strlen(s->host) + 1 + 5 + 1 + ((s->rsrc) ? strlen(s->rsrc) : 0) + + 7 + (s->name ? strlen(s->name) + 4 : 0) + 1; + + if ((u = malloc(l + 1))) { + if (!s->escape) { + esc[0] = '\0'; + } else if (s->escape < ' ') { + esc[1] = s->escape + 'A' - 1; + } else { + esc[0] = s->escape; + esc[1] = '\0'; + } + if (!s->literal) { + lit[0] = '\0'; + } else if (s->literal < ' ') { + lit[1] = s->literal + 'A' - 1; + } else { + lit[0] = s->literal; + lit[1] = '\0'; + } + r = snprintf(u, l, "%s%s%s@%s:%d/%s%s%s%s%s%s", s->proto ? s->proto : "", s->proto ? "://" : "", s->user, s->host, s->port, + ((s->rsrc) ? s->rsrc : ""), ((s->escape) ? "+-e" : ""), esc, ((s->escape) ? lit : ""), ((s->name) ? "+-x+" : ""), ((s->name) ? s->name : "")); + D_ESCREEN(("ns_get_url: URL is %s\n", u)); + if ((r >= 0) && (r < l)) { + return u; + } + FREE(u); + } - 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 */ +/**************************************************************************** + _ __ _ + ___ ___ _ __ ___ ___ _ __ ___ _ __ ___ ___(_)/ _(_) ___ +/ __|/ __| '__/ _ \/ _ \ '_ \ _____/ __| '_ \ / _ \/ __| | |_| |/ __| +\__ \ (__| | | __/ __/ | | |_____\__ \ |_) | __/ (__| | _| | (__ +|___/\___|_| \___|\___|_| |_| |___/ .__/ \___|\___|_|_| |_|\___| + |_| +screen-specific routines -_ns_disp * -disp_fetch_or_make(_ns_sess * s, int n) + these routines handle a specific backend, the GNU "screen" program. */ + + + +#ifdef NS_HAVE_SCREEN + +/* ns_mov_screen_disp - move a screen display to a new position + s session + fm from (old index) + to to (new index) + <- error code */ + +static int +ns_mov_screen_disp(_ns_sess * s, int fm, int to) { - _ns_disp *d, *e = NULL, *c; + char *t1 = "\x01'%d\r"; + char *t2 = "\x01:number %d\r"; + char b[NS_MAXCMD + 1]; + int l; + _ns_disp *d, *d2; - for (c = s->dsps; c && (c->index < n); c = c->next) - e = c; + if ((fm > 9999) || (to > 9999)) + return NS_FAIL; - if (c && (c->index == n)) /* found it */ - return c; + if (!s->curr || s->curr->index != fm) { + s->curr = disp_fetch(s, fm); - if (!(d = ns_new_disp())) /* not there, create new */ - return NULL; /* can't create, fail */ + l = snprintf(b, NS_MAXCMD, t1, fm); + if ((l <= 0) || (l > NS_MAXCMD)) { + return NS_FAIL; + } - d->index = n; + (void) ns_screen_command(s, b); + } - 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; + l = snprintf(b, NS_MAXCMD, t2, to); + if ((l <= 0) || (l > NS_MAXCMD)) { + return NS_FAIL; + } - d->sess = s; /* note session on display */ + (void) ns_screen_command(s, b); - if (!d->sess->curr) /* note as current on session if first display */ - d->sess->curr = d; +#if 0 + d = s->dsps; /* swap-o-matic */ + while (d) { + if (d->index == to) { + d->index = fm; + d = NULL; + } else { + d = d->next; + } + } - return d; + s->curr->index = to; + + do { /* sort displays */ + d = s->dsps; + while (d && d->next && (d->index < d->next->index)) /* find one in wrong pos */ + d = d->next; + + if (d) { /* found one */ + d2 = s->dsps; + if (d->prvs) { /* take out of list */ + d->prvs->next = d->next; + } /* wasn n'th el */ + else { + s->dsps = d->next; /* was first el */ + } + if (d->next) { + d->next->prvs = d->prvs; + } + + /* put in again at new correct position */ + if (d2->index > d->index) { /* new first el */ + d->prvs = NULL; + d->next = d2; + d2->prvs = d; + s->dsps = d; + } else { + while (d2->index < d->index) { + d2 = d2->next; + } + if (d2) { + d->next = d2; + if ((d->prvs = d2->prvs)) { + d->prvs->next = d; + } + d2->prvs = d; + } + } + } + } while (d); +#else + s->curr = NULL; + ns_dst_dsps(&(s->dsps)); +#endif + + return NS_SUCC; } -/* 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) */ +/* 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 -disp_get_real_by_screen(_ns_sess * screen, int n) +ns_screen_command(_ns_sess * sess, char *cmd) { - _ns_disp *d2 = screen->dsps; - int r = 0; - while (d2 && d2->index != n) { - d2 = d2->next; - r++; + _ns_efuns *efuns; + char *c; + int ret = NS_SUCC; + + if (!cmd || !*cmd) + return NS_FAIL; + + if (NS_EFUN_EXISTS(efuns, sess, NULL, inp_text)) { + if ((c = strdup(cmd))) { + { + char *p = c; /* replace default escape-char with that */ + + while (*p) { /* actually used in this session */ + if (*p == NS_SCREEN_ESCAPE) + *p = sess->escape; + p++; + } + } + ns_desc_string(c, "ns_screen_command: xlated string"); + efuns->inp_text(NULL, sess->fd, c); + FREE(c); + } else + ret = NS_OOM; + } /* out of memory */ + else { + ret = NS_EFUN_NOT_SET; + D_ESCREEN(("ns_screen_command: sess->efuns->inp_text not set!\n")); } -#ifdef NS_DEBUG - if (!d2) - return -1; -#endif - return r; + return ret; } -/* 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) */ +/* send a single command string to screen, adding the equiv of ^A: + s the session + cmd the command string + <- error code */ int -disp_get_screen_by_real(_ns_sess * screen, int r) +ns_screen_xcommand(_ns_sess * s, char prefix, char *cmd) { - _ns_disp *d2 = screen->dsps; - while (d2 && (r-- > 0)) - d2 = d2->next; -#ifdef NS_DEBUG - if (!d2) - return -1; -#endif - return d2->index; -} + char *i; + int ret = NS_OOM; + if ((i = MALLOC(strlen(cmd) + 4))) { + size_t l = strlen(cmd) + 2; - -/* 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; + strcpy(&i[2], cmd); + i[0] = s->escape; + i[1] = prefix; + i[l] = '\n'; + i[++l] = '\0'; + ret = ns_screen_command(s, i); + FREE(i); } - if (d3->next) - d3->next->prvs = d3->prvs; - ns_dst_disp(&d3); + return ret; } -/***************************************************************************/ -/* parse status lines of the "screen" program */ -/**********************************************/ - - - /* tab completion for screen-commands !b current entry (changes) l number of characters to compare in current entry m maximum number of characters in entry (size of input buffer) <- error code */ -int +static int ns_inp_tab(void *xd, char *b, size_t l, size_t m) { char *sc[] = { "acladd", "addacl", "aclchg", "chacl", "acldel", "aclgrp", @@ -1576,11 +1746,10 @@ ns_inp_tab(void *xd, char *b, size_t l, size_t m) _ns_sess *s = (_ns_sess *) xd; int nsc = sizeof(sc) / sizeof(char *); - if (NS_EFUN_EXISTS(efuns, s, NULL, inp_tab)) { + if (NS_EFUN_EXISTS(efuns, s, NULL, inp_tab)) return efuns->inp_tab((void *) s, sc, nsc, b, l, m) < 0 ? NS_FAIL : NS_SUCC; - } - D_ESCREEN(("sess->efuns->inp_tab not set!\n")); + D_ESCREEN(("ns_screen_command: sess->efuns->inp_tab not set!\n")); return NS_EFUN_NOT_SET; } @@ -1600,12 +1769,12 @@ ns_parse_esc(char **x) if (**x == '\\') { (*x)++; r = **x; - if (r >= '0' && r <= '7') { /* octal, otherwise literal */ + if (r >= '0' && r <= '7') { /* octal, otherwise literal */ char b[4] = "\0\0\0"; char *e = *x; - long v; size_t l = 0; - while ((*e >= '0' && *e <= '7') && (l < 3)) { /* can't use endptr here : ( */ + + while ((*e >= '0' && *e <= '7') && (l < 3)) { /* can't use endptr here : ( */ e++; l++; } @@ -1651,8 +1820,9 @@ ns_parse_screen_cmd(_ns_sess * s, char *p, int whence) if (!p || !*p) return NS_FAIL; - if ((p2 = strchr(p, ' '))) { /* first argument */ + if ((p2 = strchr(p, ' '))) { /* first argument */ char *e; + while (isspace(*p2)) p2++; v1 = strtol(p2, &e, 0); /* magic conversion mode */ @@ -1661,25 +1831,26 @@ ns_parse_screen_cmd(_ns_sess * s, char *p, int whence) } #define IS_CMD(b) (strncasecmp(p,b,strlen(b))==0) if (!p2) { - D_ESCREEN(("ignoring \"%s\" without an argument...\n", p)); + D_ESCREEN(("screenrc: ignoring \"%s\" without an argument...\n", p)); /* must return success so it's fowarded to screen in interactive mode. that way, the user can read the original reply instead of a fake one from us. */ return NS_SUCC; } else if (IS_CMD("defescape")) - D_ESCREEN(("ignoring \"defescape\", did you mean \"escape\"?\n")); + D_ESCREEN(("screenrc: ignoring \"defescape\", did you mean \"escape\"?\n")); else if (IS_CMD("defhstatus") || IS_CMD("hardstatus") || IS_CMD("echo") || IS_CMD("colon") || IS_CMD("wall") || #ifdef NS_PARANOID IS_CMD("nethack") || #endif IS_CMD("info") || IS_CMD("time") || IS_CMD("title") || IS_CMD("lastmsg") || IS_CMD("msgwait") || IS_CMD("msgminwait")) { - D_ESCREEN(("ignoring \"%s\", not applicable...\n", p)); + D_ESCREEN(("screenrc: ignoring \"%s\", not applicable...\n", p)); return NS_NOT_ALLOWED; } else if (IS_CMD("escape")) { char x = 0, y = 0; + if ((x = ns_parse_esc(&p2)) && (y = ns_parse_esc(&p2))) { if (s->escdef == NS_ESC_CMDLINE) { - D_ESCREEN(("ignoring \"escape\"; overridden on command-line...\n", x, y)); + D_ESCREEN(("screenrc: ignoring \"escape\"; overridden on command-line...\n", x, y)); return NS_NOT_ALLOWED; } else { s->escape = x; @@ -1688,30 +1859,28 @@ ns_parse_screen_cmd(_ns_sess * s, char *p, int whence) return NS_SUCC; } } else - D_ESCREEN(("ignoring \"escape\" because of invalid arguments %o %o...\n", x, y)); + D_ESCREEN(("screenrc: ignoring \"escape\" because of invalid arguments %o %o...\n", x, y)); } else if (IS_CMD("defscrollback")) { if (v1 < NS_SCREEN_DEFSBB) - D_ESCREEN(("ignoring \"%s\" for value < %d...\n", p, NS_SCREEN_DEFSBB)); + D_ESCREEN(("screenrc: ignoring \"%s\" for value < %d...\n", p, NS_SCREEN_DEFSBB)); else { s->dsbb = v1; return NS_SUCC; } } else if (IS_CMD("scrollback")) { if (v1 < NS_SCREEN_DEFSBB) - D_ESCREEN(("ignoring \"%s\" for value < %d...\n", p, NS_SCREEN_DEFSBB)); + D_ESCREEN(("screenrc: ignoring \"%s\" for value < %d...\n", p, NS_SCREEN_DEFSBB)); else { if (!s->curr) s->curr = s->dsps; if (!s->curr) - D_ESCREEN(("ignoring \"%s\", cannot determine current display!?...\n", p)); + D_ESCREEN(("screenrc: ignoring \"%s\", cannot determine current display!?...\n", p)); else s->curr->sbb = v1; return NS_SUCC; } } else { -#ifdef NS_DEBUG - D_ESCREEN(("bored now \"%s\"\n", p)); -#endif + D_ESCREEN(("screenrc: bored now \"%s\"\n", p)); return NS_SUCC; } return NS_FAIL; @@ -1739,21 +1908,19 @@ ns_parse_screen_key(_ns_sess * s, char c) b[1] = c; b[2] = '\0'; -#ifdef NS_DEBUG if (c < 27) - D_ESCREEN(("^%c-^%c %d\n", s->escape + 'A' - 1, c + 'A' - 1, c)); + D_ESCREEN(("screen_key: ^%c-^%c %d\n", s->escape + 'A' - 1, c + 'A' - 1, c)); else - D_ESCREEN(("^%c-%c %d\n", s->escape + 'A' - 1, c, c)); -#endif + D_ESCREEN(("screen_key: ^%c-%c %d\n", s->escape + 'A' - 1, c, c)); switch (c) { case NS_SCREEN_CMD: /* send command (statement) to screen server */ - (void) ns_input_dialog((void *) s, "Enter a command to send to the \"screen\" program", 64, &i, ns_inp_tab); + (void) ns_inp_dial((void *) s, "Enter a command to send to the \"screen\" program", 64, &i, ns_inp_tab); if (i) { if ((ret = ns_parse_screen_cmd(s, i, NS_ESC_INTERACTIVE)) == NS_SUCC) { ret = ns_screen_xcommand(s, c, i); } else if (ret == NS_NOT_ALLOWED) { - menu_dialog(NULL, "Sorry, David, I cannot allow that.", 0, NULL, NULL); + ns_inp_dial(NULL, "Sorry, David, I cannot allow that.", 0, NULL, NULL); } FREE(i); } @@ -1761,9 +1928,10 @@ ns_parse_screen_key(_ns_sess * s, char c) case NS_SCREEN_RENAME: /* rename current display */ i = s->curr->name; l = strlen(i); - (void) ns_input_dialog(s, "Enter a new name for the current display", 12, &i, NULL); + (void) ns_inp_dial(s, "Enter a new name for the current display", 12, &i, NULL); if (i && *i) { char *n; + if ((n = MALLOC(strlen(i) + l + 1))) { strcpy(&n[l], i); while (l) @@ -1774,6 +1942,18 @@ ns_parse_screen_key(_ns_sess * s, char c) FREE(i); } break; + case NS_SCREEN_KILL: + i = NULL; + (void) ns_inp_dial(s, "Really close display?", 1, &i, NULL); + if (i) { + if ((*i == 'y') || (*i == 'Y')) { + char *b = "\x01ky\r"; + + ret = ns_screen_command(s, b); + } + FREE(i); + } + break; default: ret = ns_screen_command(s, b); } @@ -1837,12 +2017,11 @@ ns_parse_screen_interactive(_ns_sess * sess, char *c) whence which screenrc are we in? <- error code */ -int +static int ns_parse_screenrc(_ns_sess * s, char *fn, int whence) { int fd = -1; char *rc = NULL; - char _e = '\0', _l = '\0', *esc = NULL; if (fn) { struct stat st; @@ -1852,6 +2031,7 @@ ns_parse_screenrc(_ns_sess * s, char *fn, int whence) if (!fstat(fd, &st)) { if ((rc = MALLOC(st.st_size + 1))) { char *p; + while (((rd = read(fd, rc, st.st_size)) < 0) && (errno == EINTR)); if (rd < 0) goto fail; @@ -1861,10 +2041,11 @@ ns_parse_screenrc(_ns_sess * s, char *fn, int whence) while (*p) { char *p2 = p, *n; int f = 0; - while (*p2 && *p2 != '\n' && *p2 != '\r') /* find EOL */ + + while (*p2 && *p2 != '\n' && *p2 != '\r') /* find EOL */ p2++; n = p2; - while (*n == '\r' || *n == '\n') /* delete EOL */ + while (*n == '\r' || *n == '\n') /* delete EOL */ *(n++) = '\0'; while (isspace(*p)) p++; @@ -1873,19 +2054,19 @@ ns_parse_screenrc(_ns_sess * s, char *fn, int whence) while (*p2) { if (*p2 == '\\') { p2++; - if (*p2) /* sanity check */ + if (*p2) /* sanity check */ p2++; } else { if (*p2 == '\"') f = 1 - f; - if (!f && *p2 == '#') /* comment, kill to EOL */ + if (!f && *p2 == '#') /* comment, kill to EOL */ *p2 = '\0'; else p2++; } } - if (strlen(p)) /* any commands in line? */ + if (strlen(p)) /* any commands in line? */ ns_parse_screen_cmd(s, p, whence); p = n; /* done, next line */ } @@ -1917,13 +2098,13 @@ ns_parse_screenrc(_ns_sess * s, char *fn, int whence) p the offending message-line <- returns an error code. */ -int +static int ns_parse_screen_msg(_ns_sess * screen, char *p) { _ns_efuns *efuns; - _ns_disp *disp; - char *p2, *p3, *d; - int ma, mi, mu, n, ret = NS_SUCC, type; + char *p2; + char vdate[33], vtype[3], vrem[17]; + int ma, mi, mu, ret = NS_SUCC, type; if (!p) return NS_FAIL; @@ -1936,9 +2117,8 @@ ns_parse_screen_msg(_ns_sess * screen, char *p) type = (strlen(p) > 1) ? NS_SCREEN_STATUS : NS_SCREEN_ST_CLR; if (type == NS_SCREEN_ST_CLR) { - if (NS_EFUN_EXISTS(efuns, screen, NULL, err_msg)) { + if (NS_EFUN_EXISTS(efuns, screen, NULL, err_msg)) ret = efuns->err_msg(NULL, type, ""); - } } /* a screen display can disappear because the program in it dies, or because we explicitly ask screen to kill the display. in the latter @@ -1948,36 +2128,43 @@ ns_parse_screen_msg(_ns_sess * screen, char *p) from the struct-list). this way, we won't need to duplicate the delete-logic here. */ else if (!strncmp(p, "Window ", strlen("Window ")) && (p2 = strrchr(p, ' ')) && !strcmp(p2, " killed.")) { -#ifdef NS_DEBUG - D_ESCREEN(("window kill detected.\n")); -#endif ret = ns_upd_stat(screen); p = NULL; - } else if (!strcmp(p, "New screen...") || !strncmp(p, "msgwait", strlen("msgwait")) || !strncmp(p, "msgminwait", strlen("msgminwait"))) + } else if (!strncmp(p, NS_SCREEN_SESS_T, strlen(NS_SCREEN_SESS_T))) { + if (screen->name) { + FREE(screen->name); + } + if ((screen->name = strdup(&p[strlen(NS_SCREEN_SESS_T)]))) { + size_t lsn = strlen(screen->name); + + if (lsn) { + screen->name[--lsn] = '\0'; + } + D_ESCREEN(("ns_parse_screen_msg: session is \"%s\"\n", screen->name)); + } p = NULL; -#ifndef NS_PARANOID - /* FIXME. */ - else if (sscanf(p, NS_SCREEN_VERSION, &p3, &ma, &mi, &mu, &p2, &d) == 6) { - if (!strcmp("en", p3)) + } else if (!strcmp(p, "New screen...") || + !strncmp(p, "msgwait", strlen("msgwait")) || + !strncmp(p, "msgminwait", strlen("msgminwait")) || + !strcmp(p, "Press ^@ to destroy or ^@ to resurrect window") || !strcmp(p, "Aborted because of window size change.")) + p = NULL; + else if (sscanf(p, NS_SCREEN_VERSION_T, vtype, &ma, &mi, &mu, vrem, vdate) == 6) { + if (!strcmp("en", vtype)) screen->backend = NS_MODE_SCREEN; - else if (!strcmp("am", p3)) + else if (!strcmp("am", vtype)) screen->backend = NS_MODE_SCREAM; -# ifdef NS_DEBUG - D_ESCREEN(("scre%s %d.%2d.%2d %s a/o %s\n", p3, ma, mi, mu, p2, d)); -# endif - } -#endif - else if (!strcmp(p, NS_SCREEN_NO_DEBUG)) + p = NULL; + D_ESCREEN(("ns_parse_screen_msg: scre%s %d.%2d.%2d %s a/o %s -> mode %d\n", vtype, ma, mi, mu, vrem, vdate, screen->backend)); + } else if (!strcmp(p, NS_SCREEN_NO_DEBUG)) p = "debug info was not compiled into \"screen\"..."; - else if (!strncmp(p, NS_SCREEN_DK_CMD, strlen(NS_SCREEN_DK_CMD))) { + else if (!strncmp(p, NS_SCREEN_DK_CMD_T, strlen(NS_SCREEN_DK_CMD_T))) { p[strlen(p) - 1] = '\0'; - p2 = &p[strlen(NS_SCREEN_DK_CMD)]; + p2 = &p[strlen(NS_SCREEN_DK_CMD_T)]; p = "unknown screen statement ignored"; } if (p) { /* status. send to status-line or dialog or whatever */ - if (NS_EFUN_EXISTS(efuns, screen, NULL, err_msg)) { + if (NS_EFUN_EXISTS(efuns, screen, NULL, err_msg)) ret = efuns->err_msg(NULL, type, p); - } } return ret; } @@ -2000,7 +2187,7 @@ ns_parse_screen_msg(_ns_sess * screen, char *p) 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) + width the terminal's width in columns (ie 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) @@ -2011,12 +2198,9 @@ ns_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) - 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 */ + static int l = sizeof(NS_SCREEN_FLAGS); + size_t status_blanks = 0; /* status-bar overflow? */ + int ret = NS_SUCC, tmp, parsed, /* no of *visible* elements in status line */ n, /* screen's index (immutable, sparse) */ r; /* real index (r'th element) */ _ns_efuns *efuns; @@ -2028,37 +2212,54 @@ ns_parse_screen(_ns_sess * screen, int force, int width, char *p) if (!force && screen->timestamp) return NS_SUCC; - if (p = strdup(p)) { + 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 - D_ESCREEN(("screen sends ::%s::\n", p)); -#endif + D_ESCREEN(("parse_screen: screen sends ::%s::\n", p)); 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 */ + 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 than once */ else if (!screen->timestamp) { - screen->timestamp = time(NULL); + /* send init string the first time around, just to be on + the safe side. we could send it before entering this + function for the first time, but that would break if + escapes or screenrc were set from the + command-line. don't ask. */ + + D_ESCREEN(("parse_screen: preparing screen...\n")); + if (screen->delay > 0) { + screen->timestamp = time(NULL) + screen->delay; if (NS_EFUN_EXISTS(efuns, screen, NULL, waitstate)) { ret = efuns->waitstate(NULL, screen->delay * 1000); - } else { - sleep(screen->delay); } + (void) ns_upd_stat(screen); + } else { + (void) ns_screen_command(screen, NS_SCREEN_INIT); + screen->timestamp = 1; } + } else if ((screen->timestamp > 1) && (time(NULL) >= screen->timestamp)) { (void) ns_screen_command(screen, NS_SCREEN_INIT); + screen->timestamp = 1; + D_ESCREEN(("parse_screen: resetting screen...\n")); } FREE(p); return ret; + } else if (screen->backend == NS_MODE_NEGOTIATE) { + /* I can't believe we haven't decided on a backend yet! Ask! */ + (void) ns_screen_command(screen, NS_SCREEN_VERSION); + (void) ns_screen_command(screen, NS_SCREEN_SESSION); + screen->timestamp = time(NULL); } p3 = p; @@ -2073,10 +2274,10 @@ ns_parse_screen(_ns_sess * screen, int force, int width, char *p) pd[parsed].screen = n; pd[parsed].real = r++; - while (isdigit(*p3)) /* skip index */ + while (isdigit(*p3)) /* skip index */ p3++; - pd[parsed].flags = 0; /* get and skip flags */ + pd[parsed].flags = 0; /* get and skip flags */ while (*p3 && *p3 != ' ') { for (n = 0; n < l; n++) { if (*p3 == p5[n]) { @@ -2087,7 +2288,7 @@ ns_parse_screen(_ns_sess * screen, int force, int width, char *p) p3++; } - if (*p3 == ' ') { /* skip space, read name */ + if (*p3 == ' ') { /* skip space, read name */ *(p3++) = '\0'; p4 = p3; while (p3[0] && p3[1] && (p3[0] != ' ' || p3[1] != ' ')) @@ -2102,31 +2303,22 @@ ns_parse_screen(_ns_sess * screen, int force, int width, char *p) p3 = &p3[strlen(p3)]; } /* out of mem => skip remainder */ else - p3 = &p3[strlen(p3)]; /* weirdness => skip remainder */ + p3 = &p3[strlen(p3)]; /* weirdness => skip remainder */ } while (*p3); -#ifdef NS_DEBUG_ - fputs(NS_PREFIX "parse_screen: found ", stderr); - for (r = 0; r < parsed; r++) - if (pd[r].name) - fprintf(stderr, "%d(%d/%d,%s) ", r, pd[r].screen, pd[r].real, pd[r].name); - fputs("\n\n", stderr); -#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))) { - D_ESCREEN(("out of memory in new_display(%d)\n", n)); + D_ESCREEN(("parse_screen: out of memory in new_display(%d)\n", n)); ret = NS_FAIL; } else { - if (NS_EFUN_EXISTS(efuns, screen, NULL, ins_disp)) { - ret = efuns->ins_disp(screen->userdef, pd[r].real - 1, disp->name); - } + if (NS_EFUN_EXISTS(efuns, screen, NULL, ins_disp)) + ret = efuns->ins_disp(screen->userdef, pd[r].real - 1, pd[r].screen, disp->name); } - } else if ((tmp = strcmp(disp->name, pd[r].name)) || /* upd display */ + } else if ((tmp = strcmp(disp->name, pd[r].name)) || /* upd display */ (disp->flags != pd[r].flags)) { if (tmp) { FREE(disp->name); @@ -2138,23 +2330,20 @@ ns_parse_screen(_ns_sess * screen, int force, int width, char *p) if (pd[r].flags & NS_SCREAM_CURR) disp->sess->curr = disp; disp->flags = pd[r].flags & NS_SCREAM_MASK; - if (NS_EFUN_EXISTS(efuns, screen, NULL, upd_disp)) { + if (NS_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 */ + if (!d2 || d2->next != disp) { /* remove expired displays */ _ns_disp *d3 = disp->prvs, *d4; + while (d3 && d3 != d2) { -#ifdef NS_DEBUG - D_ESCREEN(("remove expired middle %d \"%s\"...\n", d3->index, d3->name)); -#endif + D_ESCREEN(("parse_screen: remove expired middle %d \"%s\"...\n", d3->index, d3->name)); d4 = d3->prvs; - if (NS_EFUN_EXISTS(efuns, screen, NULL, del_disp)) { + if (NS_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; } @@ -2168,14 +2357,13 @@ ns_parse_screen(_ns_sess * screen, int force, int width, char *p) if (!r) { if (!(err_inhibit & NS_ERR_WEIRDSCREEN)) { err_inhibit |= NS_ERR_WEIRDSCREEN; - fprintf(stderr, NS_PREFIX "parse_screen: !r\n" + fprintf(stderr, "parse_screen: !r\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"); + "a screenshot of the offending window (and the window only, the\n" "beauty of your desktop is not relevant to this investigation. : ).\n"); } ret = ns_upd_stat(screen); FREE(p); @@ -2186,17 +2374,15 @@ ns_parse_screen(_ns_sess * screen, int force, int width, char *p) (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 - D_ESCREEN(("remove expired right %d \"%s\"...\n", disp->index, disp->name)); -#endif + D_ESCREEN(("parse_screen: remove expired right %d \"%s\"...\n", disp->index, disp->name)); d2 = disp; if (d2->sess->curr == d2) d2->sess->curr = d3; disp = disp->next; - if (NS_EFUN_EXISTS(efuns, screen, NULL, del_disp)) { + if (NS_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; @@ -2209,17 +2395,199 @@ ns_parse_screen(_ns_sess * screen, int force, int width, char *p) FREE(p); /* release our (modified) copy of the status-line */ } - /* send init string the first time around, just to be on the safe side. - we could send it before entering this function for the first time, - but that would break if escapes or screenrc were set from the - command-line. don't ask. */ -#if (NS_SCREEN_UPD_FREQ>0) - if ((t2 - screen->timestamp) > NS_SCREEN_UPD_FREQ) { - (void) ns_upd_stat(screen); - screen->timestamp = t2; - } + return ret; +} + #endif + + +/**************************************************************************** + _____ _ _ +| ___| __ ___ _ __ | |_ ___ _ __ __| | +| |_ | '__/ _ \| '_ \| __|____ / _ \ '_ \ / _` | +| _|| | | (_) | | | | ||_____| __/ | | | (_| | +|_| |_| \___/|_| |_|\__| \___|_| |_|\__,_| + + +frontend abstraction (callbacks for messages to the client) + + this abstracts the frontend against the backend; the abstraction-layer + (libscream) calls these in response to message from the backend (screen, + or whatever) without really knowing what terminal-emulator (Eterm, + konsole, multi-gnome-terminal, ...) the frontend is. */ + + + +/* 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 that redraw part of the terminal */ +void +ns_register_exb(_ns_efuns * efuns, int (*expire_buttons) (void *, int)) +{ + efuns->expire_buttons = expire_buttons; +} + +/* 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, 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; +} + + + +/* function that will open a dialog */ +void +ns_register_inp(_ns_efuns * efuns, int (*inp_dial) (void *, char *, int, char **, int (*)(void *, char *, size_t, size_t))) +{ + efuns->inp_dial = inp_dial; +} + + + +/* function that will handle tab-completion in a dialog */ +void +ns_register_tab(_ns_efuns * efuns, int (*inp_tab) (void *, char *[], int, char *, size_t, size_t)) +{ + efuns->inp_tab = inp_tab; +} + + + +/* function that will do whatever while waiting */ +void +ns_register_fun(_ns_efuns * efuns, int (*inp_fun) (void *, int)) +{ + efuns->waitstate = inp_fun; +} + + + +/* 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; +} + + + +/* ns_inp_dial + open a dialog (wrapp around efuns->inp_dial) + s the session + !retstr where we'll store a pointer to the result (the user's input) + prompt the prompt to appear in the dialog box + <- msg */ + + +int +ns_inp_dial(_ns_sess * s, char *prompt, int maxlen, char **retstr, int (*inp_tab) (void *, char *, size_t, size_t)) +{ + _ns_efuns *efuns; + int ret = NS_SUCC; + + if (NS_EFUN_EXISTS(efuns, s, NULL, inp_dial)) { + (void) efuns->inp_dial((void *) s, prompt, maxlen, retstr, inp_tab); + } else { + ret = NS_EFUN_NOT_SET; + D_ESCREEN(("ns_inp_dial: sess->efuns->inp_dial not set!\n")); + } return ret; } diff --git a/src/menus.c b/src/menus.c index b0c4022..09856a4 100644 --- a/src/menus.c +++ b/src/menus.c @@ -47,18 +47,16 @@ static const char cvs_ident[] = "$Id$"; # include "screamcfg.h" #endif -menulist_t *menu_list = NULL; -#ifndef ESCREEN -static -#endif -event_dispatcher_data_t menu_event_data; static GC topShadowGC, botShadowGC; static Time button_press_time; static int button_press_x = 0, button_press_y = 0; + #ifndef ESCREEN static #endif menu_t *current_menu; +menulist_t *menu_list = NULL; +event_dispatcher_data_t menu_event_data; static inline void grab_pointer(Window win); static inline void ungrab_pointer(void); @@ -74,8 +72,7 @@ grab_pointer(Window win) 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); + | Button1MotionMask | Button2MotionMask | Button3MotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); if (success != GrabSuccess) { switch (success) { case GrabNotViewable: @@ -262,12 +259,10 @@ menu_handle_button_press(event_t *ev) 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); + 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); + 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); @@ -297,8 +292,7 @@ menu_handle_button_release(event_t *ev) 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)); + 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)) { @@ -315,14 +309,13 @@ menu_handle_button_release(event_t *ev) menu_reset_all(menu_list); current_menu = NULL; } else { - current_menu->state &= ~MENU_STATE_IS_DRAGGING; /* Click, brief drag, release == single click */ + 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)); + 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. */ @@ -463,22 +456,18 @@ menu_t *menu_create(char *title) xattr.colormap = cmap; cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); - mask = - PointerMotionMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button2MotionMask | - Button3MotionMask; + 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); + 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); @@ -674,16 +663,14 @@ menuitem_change_current(menuitem_t *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)"))); + 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) + 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); @@ -896,8 +883,7 @@ menuitem_select(menu_t *menu) 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)); + 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); @@ -907,8 +893,7 @@ menuitem_select(menu_t *menu) 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); + 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 { if (image_mode_is(image_menu, MODE_MASK)) { @@ -923,8 +908,7 @@ menuitem_select(menu_t *menu) 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); + 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); } @@ -953,8 +937,7 @@ menu_display_submenu(menu_t *menu, menuitem_t *item) 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)); + 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. */ @@ -985,6 +968,7 @@ menu_draw(menu_t *menu) { register unsigned short i, len; unsigned long width, height; + #if 0 char *safeaction; #endif @@ -1113,10 +1097,8 @@ menu_draw(menu_t *menu) 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); + 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++) { @@ -1130,11 +1112,9 @@ menu_draw(menu_t *menu) 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)); + 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); + 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; @@ -1143,18 +1123,15 @@ menu_draw(menu_t *menu) 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)); + 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); + 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); + item->x + item->w - 3 * MENU_HGAP, item->y + (item->h - MENU_VGAP) / 2, MENU_VGAP, 2, DRAW_ARROW_RIGHT); } break; #if 0 @@ -1179,8 +1156,7 @@ menu_draw(menu_t *menu) } 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); + 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); } } } @@ -1226,16 +1202,34 @@ menu_action(menuitem_t *item) break; case MENUITEM_ECHO: #ifdef ESCREEN - if (TermWin.screen_mode && TermWin.screen) { /* translate escapes */ - ns_parse_screen_interactive(TermWin.screen, item->action.string); + if (TermWin.screen && TermWin.screen->backend) { + /* translate escapes */ + switch (TermWin.screen->backend) { +# ifdef NS_HAVE_SCREEN + case NS_MODE_SCREEN: + ns_parse_screen_interactive(TermWin.screen, item->action.string); + break; +# endif + default: + tt_write((unsigned char *) item->action.string, strlen(item->action.string)); + } } else #endif tt_write((unsigned char *) item->action.string, strlen(item->action.string)); break; case MENUITEM_LITERAL: #ifdef ESCREEN - if (TermWin.screen_mode && TermWin.screen) { /* translate escapes */ - (void) ns_screen_command(TermWin.screen, item->action.string); + if (TermWin.screen) { + /* translate escapes */ + switch (TermWin.screen->backend) { +# ifdef NS_HAVE_SCREEN + case NS_MODE_SCREEN: + (void) ns_screen_command(TermWin.screen, item->action.string); + break; +# endif + default: + tt_write((unsigned char *) item->action.string, strlen(item->action.string)); + } } else #endif tt_write((unsigned char *) item->action.string, strlen(item->action.string)); @@ -1310,7 +1304,7 @@ menu_tab(void *xd, char *sc[], int nsc, char *b, size_t l, size_t m) for (n = n2; n < nsc; n++) { if (!strncasecmp(b, sc[n], l)) { if (strcmp(b, sc[n])) { - if (strlen(sc[n]) >= m) /* buffer would overflow => fail */ + if (strlen(sc[n]) >= m) /* buffer would overflow => fail */ return -1; strcpy(b, sc[n]); return 0; @@ -1366,8 +1360,8 @@ menu_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (v } if ((m = menu_create(prompt))) { - for (l = 0; l < menu_list->nummenus; l++) { /* copycat font entry to */ - if (menu_list->menus[l]->font) { /* blend in with l&f */ + for (l = 0; l < menu_list->nummenus; l++) { /* copycat font entry to */ + if (menu_list->menus[l]->font) { /* blend in with l&f */ m->font = menu_list->menus[l]->font; m->fwidth = menu_list->menus[l]->fwidth; m->fheight = menu_list->menus[l]->fheight; @@ -1385,17 +1379,21 @@ menu_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (v if (m->font) { /* pre-calc width so we can center the dialog */ l = strlen(prompt); - if (i->len > l) + if (i->len > l) { l = XTextWidth(m->font, i->text, i->len); - else + } else { l = XTextWidth(m->font, prompt, l); - } else + } + } else { l = 200; + } menuitem_set_action(i, MENUITEM_STRING, "error"); menu_add_item(m, i); menu_invoke((int) ((TermWin_TotalWidth() - l) / 2), (int) (TermWin_TotalHeight() / 2) - 20, TermWin.parent, m, CurrentTime); + ungrab_pointer(); + do { do { while (!XPending(Xdisplay)); @@ -1413,18 +1411,26 @@ menu_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (v if (l < maxlen) { b[l + 1] = '\0'; b[l] = ch; + if (!l && (maxlen == 1)) { + /* special case: one char */ + /* answer auto-returns */ + f = 1; + } } - } else if ((ch == '\n') || (ch == '\r')) + } else if ((ch == '\n') || (ch == '\r')) { f = 1; - else if (ch == '\x08') { - if (maxlen && l) + } else if (ch == '\x08') { + if (maxlen && l) { b[--l] = '\0'; + } } else if ((ch == '\t') && inp_tab) { - if (!tab) + if (!tab) { tab = l; + } inp_tab(xd, b, tab, maxlen); - } else if (ch == '\x1b') + } else if (ch == '\x1b') { f = 2; + } i->len = strlen(b); menu_draw(m); } while (!f); @@ -1433,8 +1439,9 @@ menu_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (v i->len = strlen(old); /* we could just return b, but it might be longer than we need */ - if (retstr) + if (retstr) { *retstr = (!maxlen || (f == 2)) ? NULL : strdup(b); + } ret = (f == 2) ? -2 : 0; } m->font = NULL; diff --git a/src/netdisp.c b/src/netdisp.c index a735bfe..7c42bc1 100644 --- a/src/netdisp.c +++ b/src/netdisp.c @@ -78,7 +78,7 @@ network_display(const char *display) if (display[0] != ':' && strncmp(display, "unix:", 5)) return display; /* nothing to do */ - ifc.ifc_len = sizeof(buffer); /* Get names of all ifaces */ + ifc.ifc_len = sizeof(buffer); /* Get names of all ifaces */ ifc.ifc_buf = buffer; if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { @@ -111,9 +111,7 @@ network_display(const char *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); + 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; diff --git a/src/options.c b/src/options.c index 3702292..966956c 100644 --- a/src/options.c +++ b/src/options.c @@ -75,12 +75,14 @@ static void *parse_xim(char *, void *); static void *parse_multichar(char *, void *); static char *rs_pipe_name = NULL; + #ifdef PIXMAP_SUPPORT static int rs_shade = 0; static char *rs_tint = NULL; #endif static unsigned long rs_buttonbars = 1; static char *rs_font_effects = NULL; + #if defined (HOTKEY_CTRL) || defined (HOTKEY_META) static char *rs_bigfont_key = NULL; static char *rs_smallfont_key = NULL; @@ -101,11 +103,13 @@ char *rs_geometry = NULL; /* Geometry string */ int rs_desktop = -1; char *rs_path = NULL; int rs_saveLines = SAVELINES; /* Lines in the scrollback buffer */ + #ifdef USE_XIM char *rs_input_method = NULL; char *rs_preedit_type = NULL; #endif char *rs_name = NULL; + #ifndef NO_BOLDFONT char *rs_boldFont = NULL; #endif @@ -119,6 +123,7 @@ unsigned long rs_scrollbar_width = 0; char *rs_finished_title = NULL; char *rs_finished_text = NULL; char *rs_term_name = NULL; + #ifdef PIXMAP_SUPPORT char *rs_pixmapScale = NULL; char *rs_icon = NULL; @@ -127,6 +132,7 @@ char *rs_cmod_red = NULL; char *rs_cmod_green = NULL; char *rs_cmod_blue = NULL; unsigned long rs_cache_size = (unsigned long) -1; + # ifdef BACKGROUND_CYCLING_SUPPORT char *rs_anim_pixmap_list = NULL; char **rs_anim_pixmaps = NULL; @@ -136,6 +142,7 @@ static char *rs_pixmaps[image_max]; #endif char *rs_theme = NULL; char *rs_config_file = NULL; + #ifdef ESCREEN char *rs_url = NULL; char *rs_hop = NULL; @@ -143,6 +150,7 @@ int rs_delay = -1; #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 */ #endif @@ -164,8 +172,7 @@ static const struct { } 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), + 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), OPT_STR('Z', "[lclport:]fw[:fwport]", "the destination machine -U can only be seen by the firewall fw. tunnel.", &rs_hop), @@ -185,8 +192,7 @@ static const struct { 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), + 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]), @@ -196,8 +202,7 @@ static const struct { 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_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]), @@ -212,8 +217,7 @@ static const struct { #endif /* NO_BOLDUNDERLINE */ 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), @@ -265,8 +269,7 @@ static const struct { 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_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), @@ -302,20 +305,16 @@ static const struct { 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("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), #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)), #endif @@ -330,8 +329,7 @@ static const struct { 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_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 */ @@ -402,8 +400,7 @@ version(void) " " 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"); + " " STARTUP_IDENT "\n" " " SYSTEM_IDENT "\n" " " TERM_IDENT "\n" " " TIMER_IDENT "\n" " " UTMP_IDENT "\n" " " WINDOWS_IDENT "\n" "\n"); printf("Debugging configuration: "); #ifdef DEBUG @@ -894,7 +891,7 @@ get_options(int argc, char *argv[]) } else if (!strcasecmp(opt, "attribute")) { conf_parse_line(NULL, val_ptr); } else { /* It's not --exec */ - if (optList[j].flag & OPT_BOOLEAN) { /* Boolean value */ + if (optList[j].flag & OPT_BOOLEAN) { /* Boolean value */ D_OPTIONS(("Boolean option detected\n")); if (val_ptr) { if (BOOL_OPT_ISTRUE(val_ptr)) { @@ -917,7 +914,7 @@ get_options(int argc, char *argv[]) *(optList[j].maskvar) |= optList[j].mask; } } - } else if (optList[j].flag & OPT_INTEGER) { /* Integer value */ + } 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 */ @@ -965,13 +962,13 @@ get_options(int argc, char *argv[]) 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 */ + 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 (opt[pos] == 'e') { /* It's an exec */ register unsigned short k, len; @@ -1006,12 +1003,12 @@ get_options(int argc, char *argv[]) } else if (opt[pos] == 'a') { conf_parse_line(NULL, val_ptr); } else { - if (optList[j].flag & OPT_BOOLEAN) { /* Boolean value */ + 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 */ + } 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))); @@ -1140,7 +1137,7 @@ get_initial_options(int argc, char *argv[]) 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 */ + if (val_ptr) { /* If the "arg" was actually an option, don't skip it */ i--; } continue; @@ -1191,8 +1188,7 @@ parse_color(char *buff, void *state) 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); + 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 ")) { @@ -1201,8 +1197,7 @@ parse_color(char *buff, void *state) 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)); + 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); @@ -1234,15 +1229,13 @@ parse_color(char *buff, void *state) 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)); + 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)); + 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); @@ -1292,8 +1285,7 @@ parse_color(char *buff, void *state) FREE(tmp); } } 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); + 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; } @@ -1332,8 +1324,7 @@ parse_attributes(char *buff, void *state) 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()); + 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); @@ -1342,8 +1333,7 @@ parse_attributes(char *buff, void *state) } 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()); + 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); @@ -1369,8 +1359,7 @@ parse_attributes(char *buff, void *state) } } 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 : "")); + 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; } @@ -1393,8 +1382,7 @@ parse_toggles(char *buff, void *state) } 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); + 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; } @@ -1584,8 +1572,7 @@ parse_toggles(char *buff, void *state) Options &= ~(Opt_resize_gravity); } } 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); + 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; } @@ -1624,8 +1611,7 @@ parse_keyboard(char *buff, void *state) 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); + 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); @@ -1653,8 +1639,7 @@ parse_keyboard(char *buff, void *state) 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()); + 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); @@ -1663,8 +1648,7 @@ parse_keyboard(char *buff, void *state) 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()); + 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); @@ -1673,8 +1657,7 @@ parse_keyboard(char *buff, void *state) 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()); + 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); @@ -1685,8 +1668,7 @@ parse_keyboard(char *buff, void *state) 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()); + 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)) { @@ -1702,8 +1684,7 @@ parse_keyboard(char *buff, void *state) } 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); + 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 @@ -1715,8 +1696,7 @@ parse_keyboard(char *buff, void *state) 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()); + 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)) { @@ -1724,8 +1704,7 @@ parse_keyboard(char *buff, void *state) } 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); + 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; } @@ -1734,8 +1713,7 @@ parse_keyboard(char *buff, void *state) 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()); + 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)) { @@ -1743,14 +1721,12 @@ parse_keyboard(char *buff, void *state) } 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); + 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); + 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; } @@ -1818,8 +1794,7 @@ parse_misc(char *buff, void *state) #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); + 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; } @@ -1855,16 +1830,14 @@ parse_imageclasses(char *buff, void *state) 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()); + 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); + 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; } @@ -1938,8 +1911,7 @@ parse_image(char *buff, void *state) 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()); + 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) { @@ -1985,8 +1957,7 @@ parse_image(char *buff, void *state) 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()); + 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")) { @@ -2028,18 +1999,15 @@ parse_image(char *buff, void *state) 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()); + 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()); + 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()); + 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")) { @@ -2060,13 +2028,11 @@ parse_image(char *buff, void *state) 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()); + 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()); + 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) { @@ -2082,13 +2048,11 @@ parse_image(char *buff, void *state) 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()); + 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()); + 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) { @@ -2104,13 +2068,11 @@ parse_image(char *buff, void *state) 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()); + 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()); + 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) { @@ -2176,21 +2138,18 @@ parse_image(char *buff, void *state) } 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()); + 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()); + 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()); + 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))); @@ -2203,22 +2162,19 @@ parse_image(char *buff, void *state) 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 */ + 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()); + 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()); + 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()); + 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) { @@ -2247,18 +2203,15 @@ parse_image(char *buff, void *state) } } 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()); + 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()); + 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()); + 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))); @@ -2274,8 +2227,7 @@ parse_image(char *buff, void *state) 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); + 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); } @@ -2364,8 +2316,7 @@ parse_actions(char *buff, void *state) } } 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); + 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; } @@ -2389,8 +2340,7 @@ parse_menu(char *buff, void *state) 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); + 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; @@ -2419,8 +2369,7 @@ parse_menu(char *buff, void *state) 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); + 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); } @@ -2441,8 +2390,7 @@ parse_menuitem(char *buff, void *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()); + 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); @@ -2491,14 +2439,12 @@ parse_menuitem(char *buff, void *state) 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)); + 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); + 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); } @@ -2531,13 +2477,12 @@ parse_bbar(char *buff, void *state) 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" */ + } 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" */ + } 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); + 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 ")) { @@ -2548,8 +2493,7 @@ parse_bbar(char *buff, void *state) } 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); + 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 ")) { @@ -2611,8 +2555,7 @@ parse_bbar(char *buff, void *state) 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); + 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); } @@ -2629,8 +2572,7 @@ parse_xim(char *buff, void *state) } 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); + 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"); @@ -2657,14 +2599,12 @@ parse_multichar(char *buff, void *state) && 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); + 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()); + 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 ")) { @@ -2672,8 +2612,7 @@ parse_multichar(char *buff, void *state) 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)); + 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)) { @@ -2690,8 +2629,7 @@ parse_multichar(char *buff, void *state) } } 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); + 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) { @@ -2950,7 +2888,7 @@ post_parse(void) 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() */ + FREE(rs_pixmaps[i]); /* These are created by STRDUP() */ } #else /* Right now, solid mode is the only thing we can do without pixmap support. */ @@ -3123,8 +3061,7 @@ post_parse(void) 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)); + 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) { @@ -3142,8 +3079,7 @@ post_parse(void) 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)); + 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); } @@ -3162,8 +3098,7 @@ post_parse(void) 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)); + 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); } @@ -3182,8 +3117,7 @@ post_parse(void) 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)); + 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); } @@ -3234,11 +3168,11 @@ post_parse(void) unsigned long w, h; int count; - count = num_words(rs_anim_pixmap_list) - 1; /* -1 for the delay */ + 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 */ + 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) { @@ -3326,8 +3260,7 @@ save_config(char *path, unsigned char save_theme) *(--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); + print_error("I couldn't write to \"%s\" or \"%s\". I give up.", (theme_dir ? theme_dir : PKGDATADIR "/themes/Eterm\n"), path); return errno; } } @@ -3356,8 +3289,7 @@ save_config(char *path, unsigned char save_theme) *(--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); + print_error("I couldn't write to \"%s\" or \"%s\". I give up.", (user_dir ? user_dir : PKGDATADIR "/themes/Eterm\n"), path); return errno; } } @@ -3418,8 +3350,7 @@ save_config(char *path, unsigned char save_theme) 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_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)); @@ -3561,33 +3492,27 @@ save_config(char *path, unsigned char save_theme) } 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); + 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); + 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); + 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); + 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); + 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, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, simg->iml->pad->bottom); } /* Selected state */ @@ -3622,33 +3547,27 @@ save_config(char *path, unsigned char save_theme) } 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); + 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); + 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); + 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); + 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); + 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, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, simg->iml->pad->bottom); } } @@ -3684,33 +3603,27 @@ save_config(char *path, unsigned char save_theme) } 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); + 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); + 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); + 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); + 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); + 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, " padding %hu %hu %hu %hu\n", simg->iml->pad->left, simg->iml->pad->right, simg->iml->pad->top, simg->iml->pad->bottom); } } @@ -3746,33 +3659,27 @@ save_config(char *path, unsigned char save_theme) } 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); + 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); + 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); + 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); + 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); + 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, " 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"); @@ -4008,8 +3915,7 @@ save_config(char *path, unsigned char save_theme) } 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, " keysym 0xff%02x \'%s\'\n", i, safe_print_string((char *) (KeySym_map[i] + 1), (unsigned long) KeySym_map[i][0])); } } #ifdef GREEK_SUPPORT diff --git a/src/pixmap.c b/src/pixmap.c index 353e748..9d86ddb 100644 --- a/src/pixmap.c +++ b/src/pixmap.c @@ -62,6 +62,7 @@ static Imlib_Border bord_none = { 0, 0, 0, 0 }; #endif Pixmap buffer_pixmap = None; + #ifdef PIXMAP_OFFSET Pixmap desktop_pixmap = None, viewport_pixmap = None; Window desktop_window = None; @@ -333,8 +334,7 @@ set_pixmap_scale(const char *geom, pixmap_t *pmap) 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)); + 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; } @@ -628,8 +628,7 @@ check_image_ipc(unsigned char reset) } ); /* *INDENT-ON* */ - print_error("Looks like this version of Enlightenment doesn't support the IPC " - "commands I need. Disallowing \"auto\" mode for all images.\n"); + print_error("Looks like this version of Enlightenment doesn't support the IPC " "commands I need. Disallowing \"auto\" mode for all images.\n"); FREE(reply); checked = 2; return 0; @@ -678,8 +677,7 @@ create_trans_pixmap(simage_t *simg, unsigned char which, Drawable d, int x, int 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)); + 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) @@ -706,6 +704,7 @@ create_viewport_pixmap(simage_t *simg, Drawable d, int x, int y, unsigned short 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) @@ -719,6 +718,7 @@ create_viewport_pixmap(simage_t *simg, Drawable d, int x, int y, unsigned short } 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); @@ -782,19 +782,19 @@ create_viewport_pixmap(simage_t *simg, Drawable d, int x, int y, unsigned short } 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) +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)); + 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); @@ -810,8 +810,7 @@ paste_simage(simage_t *simg, unsigned char which, Window win, Drawable d, unsign 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"); + 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 { @@ -829,8 +828,7 @@ paste_simage(simage_t *simg, unsigned char which, Window win, Drawable d, unsign 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"); + 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); } @@ -839,6 +837,7 @@ paste_simage(simage_t *simg, unsigned char which, Window win, Drawable d, unsign } } 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) { @@ -850,6 +849,7 @@ paste_simage(simage_t *simg, unsigned char which, Window win, Drawable d, unsign 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) { @@ -950,6 +950,7 @@ copy_buffer_pixmap(unsigned char mode, unsigned long fill, unsigned short width, { GC gc; XGCValues gcvalue; + ASSERT(buffer_pixmap == None); buffer_pixmap = LIBAST_X_CREATE_PIXMAP(width, height); gcvalue.foreground = (Pixel) fill; @@ -957,6 +958,7 @@ copy_buffer_pixmap(unsigned char mode, unsigned long fill, unsigned short width, XSetGraphicsExposures(Xdisplay, gc, False); if (mode == MODE_SOLID) { simage_t *simg; + simg = images[image_bg].current; if (simg->pmap->pixmap) { LIBAST_X_FREE_PIXMAP(simg->pmap->pixmap); @@ -977,6 +979,7 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h GC gc; Pixmap pixmap = None; Screen *scr; + #ifdef PIXMAP_SUPPORT short xsize, ysize; short xpos = 0, ypos = 0; @@ -990,8 +993,7 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h 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(("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)) { @@ -1003,7 +1005,7 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h return; gcvalue.foreground = gcvalue.background = PixColors[bgColor]; gc = LIBAST_X_CREATE_GC(GCForeground | GCBackground, &gcvalue); - pixmap = simg->pmap->pixmap; /* Save this for later */ + pixmap = simg->pmap->pixmap; /* Save this for later */ if ((which == image_bg) && (buffer_pixmap != None)) { LIBAST_X_FREE_PIXMAP(buffer_pixmap); buffer_pixmap = None; @@ -1012,6 +1014,7 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h 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); @@ -1025,15 +1028,16 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h 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"); + 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); @@ -1057,8 +1061,7 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h 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"); + 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); } @@ -1094,8 +1097,8 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h } } 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)); + + 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) { @@ -1126,6 +1129,7 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h 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); @@ -1136,6 +1140,7 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h 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) { @@ -1185,6 +1190,7 @@ render_simage(simage_t *simg, Window win, unsigned short width, unsigned short h } 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; @@ -1275,6 +1281,7 @@ search_path(const char *pathlist, const char *file) 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); } @@ -1328,6 +1335,7 @@ search_path(const char *pathlist, const char *file) } for (path = pathlist; path != NULL && *path != '\0'; path = p) { int n; + /* colon delimited */ if ((p = strchr(path, ':')) == NULL) p = strchr(path, '\0'); @@ -1339,6 +1347,7 @@ search_path(const char *pathlist, const char *file) if (*path == '~') { unsigned int l; char *home_dir = getenv("HOME"); + if (home_dir && *home_dir) { l = strlen(home_dir); if (l + n < (unsigned) maxpath) { @@ -1382,6 +1391,7 @@ load_image(const char *file, simage_t *simg) Imlib_Image *im; Imlib_Load_Error im_err; char *geom; + ASSERT_RVAL(file != NULL, 0); ASSERT_RVAL(simg != NULL, 0); D_PIXMAP(("load_image(%s, %8p)\n", file, simg)); @@ -1447,6 +1457,7 @@ 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]; + 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. */ @@ -1510,12 +1521,14 @@ shade_ximage_15(void *data, int bpl, int w, int h, int rm, int gm, int bm) { 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; @@ -1530,6 +1543,7 @@ shade_ximage_15(void *data, int bpl, int w, int h, int rm, int gm, int bm) 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; @@ -1552,12 +1566,14 @@ shade_ximage_16(void *data, int bpl, int w, int h, int rm, int gm, int bm) { 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; @@ -1572,6 +1588,7 @@ shade_ximage_16(void *data, int bpl, int w, int h, int rm, int gm, int bm) 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; @@ -1594,12 +1611,14 @@ shade_ximage_32(void *data, int bpl, int w, int h, int rm, int gm, int bm) { 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; + # ifdef WORDS_BIGENDIAN r = (ptr[x + 1] * rm) >> 8; g = (ptr[x + 2] * gm) >> 8; @@ -1622,6 +1641,7 @@ shade_ximage_32(void *data, int bpl, int w, int h, int rm, int gm, int bm) 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; @@ -1656,12 +1676,14 @@ shade_ximage_24(void *data, int bpl, int w, int h, int rm, int gm, int bm) { 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; + # ifdef WORDS_BIGENDIAN r = (ptr[x + 0] * rm) >> 8; g = (ptr[x + 1] * gm) >> 8; @@ -1684,6 +1706,7 @@ shade_ximage_24(void *data, int bpl, int w, int h, int rm, int gm, int bm) 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; @@ -1718,6 +1741,7 @@ colormod_trans(Pixmap p, imlib_t *iml, GC gc, unsigned short w, unsigned short h XImage *ximg; register unsigned long i; + #if 0 register unsigned long v; unsigned long x, y; @@ -1728,6 +1752,7 @@ colormod_trans(Pixmap p, imlib_t *iml, GC gc, unsigned short w, unsigned short h 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); if (iml->mod) { @@ -1758,6 +1783,7 @@ colormod_trans(Pixmap p, imlib_t *iml, GC gc, unsigned short w, unsigned short h 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; @@ -1771,6 +1797,7 @@ colormod_trans(Pixmap p, imlib_t *iml, GC gc, unsigned short w, unsigned short h } else if (Xdepth == 16) { XWindowAttributes xattr; + XGetWindowAttributes(Xdisplay, desktop_window, &xattr); if ((xattr.visual->green_mask == 0x3e0)) { real_depth = 15; @@ -1804,9 +1831,11 @@ colormod_trans(Pixmap p, imlib_t *iml, GC gc, unsigned short w, unsigned short h /* 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; @@ -1855,6 +1884,7 @@ update_desktop_info(int *w, int *h) unsigned int pw, ph, pb, pd; int px, py; Window dummy; + if (w) { *w = 0; } @@ -1883,8 +1913,7 @@ update_desktop_info(int *w, int *h) 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."); + 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; } @@ -1907,6 +1936,7 @@ get_desktop_window(void) 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); @@ -1925,11 +1955,8 @@ get_desktop_window(void) } - 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) { + 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; } } @@ -1962,9 +1989,10 @@ get_desktop_pixmap(void) 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. */ + orig_desktop_pixmap = None; /* Forced re-read. */ } if (desktop_window == None) { D_PIXMAP(("No desktop window. Aborting.\n")); @@ -1977,8 +2005,7 @@ get_desktop_pixmap(void) 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); + 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); @@ -1998,6 +2025,7 @@ get_desktop_pixmap(void) 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); @@ -2025,12 +2053,12 @@ get_desktop_pixmap(void) } else { XFree(data); } - XGetWindowProperty(Xdisplay, desktop_window, props[PROP_TRANS_COLOR], 0L, 1L, False, AnyPropertyType, &type, - &format, &length, &after, &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); @@ -2068,12 +2096,14 @@ shaped_window_apply_mask(Drawable d, Pixmap mask) { static signed char have_shape = -1; + REQUIRE(d != None); REQUIRE(mask != None); 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; + D_PIXMAP(("Looking for shape extension.\n")); if (XQueryExtension(Xdisplay, "SHAPE", &unused, &unused, &unused)) { have_shape = 1; @@ -2102,6 +2132,7 @@ set_icon_pixmap(char *filename, XWMHints * pwm_hints) Imlib_Color_Modifier tmp_cmod; XWMHints *wm_hints; int w = 8, h = 8; + if (pwm_hints) { wm_hints = pwm_hints; } else { @@ -2118,6 +2149,7 @@ set_icon_pixmap(char *filename, XWMHints * pwm_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)); @@ -2126,8 +2158,7 @@ set_icon_pixmap(char *filename, XWMHints * pwm_hints) 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)); + 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; } diff --git a/src/scream.h b/src/scream.h index df3686c..07f31a9 100644 --- a/src/scream.h +++ b/src/scream.h @@ -90,6 +90,7 @@ typedef struct __ns_sess { /* a whole screen-session with many clients */ char *home; /* user's home dir. so we can find .screenrc */ char *sysrc; /* global screen config */ void *userdef; /* the term-app can store a pointer here */ + char *name; /* session name */ int fd; /* fd for communication */ char escape,literal; /* talking to screen: defaults to ^A, a */ int escdef; /* where was the escape sequence defined? */ @@ -131,13 +132,14 @@ typedef struct __ns_efuns { /* callbacks into the terminal program */ int (*set_scroll_h)(void *,int); int (*redraw)(void *); int (*redraw_xywh)(void *,int,int,int,int); - int (*ins_disp)(void *,int,char *); + int (*expire_buttons)(void *,int); + int (*ins_disp)(void *,int,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 *); - int (*input_dialog)(void *,char *,int,char **,int (*)(void *,char *,size_t,size_t)); + int (*inp_dial)(void *,char *,int,char **,int (*)(void *,char *,size_t,size_t)); int (*inp_tab)(void *,char *[],int,char *,size_t,size_t); int (*waitstate)(void *,int); } _ns_efuns; @@ -162,18 +164,16 @@ _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_string(char *,char *); -void ns_desc_hop(_ns_hop *,char *); -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 *,char *,_ns_efuns **,int *,void *); +int ns_detach(_ns_sess **); +/* convenience */ +int ns_run(_ns_efuns *, char *); +int ns_get_ssh_port(void); +int disp_get_real_by_screen(_ns_sess *,int); +int disp_get_screen_by_real(_ns_sess *,int); /* send command to screen */ int ns_screen_command(_ns_sess *, char *); @@ -202,21 +202,25 @@ int ns_parse_screen(_ns_sess *,int,int,char *); +/* backend abstraction */ /* 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_mov_disp(_ns_sess * s,int,int); 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 *); -int ns_input_dialog(_ns_sess *,char *,int,char **,int (*)(void *,char *,size_t,size_t)); +int ns_inp_dial(_ns_sess *,char *,int,char **,int (*)(void *,char *,size_t,size_t)); +char *ns_get_url(_ns_sess *,int); -/* register efuns (callbacks) **********************************************/ +/* frontend abstraction */ +/* things we might ask the terminal to do (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)); @@ -224,8 +228,9 @@ 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_exb(_ns_efuns *,int (*expire_buttons)(void *,int)); -void ns_register_ins(_ns_efuns *,int (*ins_disp)(void *,int,char *)); +void ns_register_ins(_ns_efuns *,int (*ins_disp)(void *,int,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 *)); @@ -238,20 +243,6 @@ void ns_register_inp(_ns_efuns *,int (*)(void *,char *,int,char **,int (*)(void void ns_register_tab(_ns_efuns *,int (*)(void *,char *[],int,char *,size_t,size_t)); void ns_register_fun(_ns_efuns *,int (*)(void *,int)); -/* from command.c */ -extern int set_scroll_x(void *, int); -extern int set_scroll_y(void *, int); -extern int set_scroll_w(void *, int); -extern int set_scroll_h(void *, int); -extern int redraw(void *); -extern int redraw_xywh(void *, int, int, int, int); -extern int ins_disp(void *, int, char *); -extern int del_disp(void *, int); -extern int upd_disp(void *, int, int, char *); -extern int err_msg(void *, int, char *); -extern int inp_text(void *, int, char *); -extern int input_dialog(void *, char *, int, char **, int (*) (void *, char *, size_t, size_t)); -extern int exe_prg(void *, char **); -extern int escreen_init(char **); + /***************************************************************************/ diff --git a/src/screamcfg.h b/src/screamcfg.h index 8ae78e0..6cbf709 100644 --- a/src/screamcfg.h +++ b/src/screamcfg.h @@ -15,11 +15,8 @@ undef it, you're on your own. */ #define NS_PARANOID -/* define NS_DEBUG to get debug-info. no support for those who undef this. */ -#undef NS_DEBUG - -/* debug memory stuff. never actually used this. */ -#undef NS_DEBUG_MEM +/* compile in support for the GNU "screen" program as a backend */ +#define NS_HAVE_SCREEN 1 #define NS_MAXCMD 512 @@ -32,7 +29,7 @@ #define NS_SCREEN_OPTS "-xRR" #define NS_SCREEN_GREP "grep escape \"$SCREENRC\" 2>/dev/null || grep escape ~/.screenrc 2>/dev/null || grep escape \"$SYSSCREENRC\" 2>/dev/null || grep escape /etc/screenrc 2>/dev/null || grep escape /usr/local/etc/screenrc 2>/dev/null || echo \"escape ^Aa\"\n" #define NS_SCREEM_CALL "%s 2>/dev/null || %s" -#define NS_WRAP_CALL "export TERM=vt100; %s" +#define NS_WRAP_CALL "export TERM=vt100; screen -wipe; %s" #define NS_SCREEN_RC ".screenrc" /* this should never change. the escape-char for an out-of-the-box "screen". @@ -48,7 +45,9 @@ 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 "\x0c\x01Z\x01:hardstatus lastline\r\x01:defhstatus \"\\005w\"\r\x01:hstatus \"\\005w\"\r\x01:msgminwait 0\r\x01:msgwait 1\r\x01:nethack off\r" NS_SCREEN_UPDATE +#define NS_SCREEN_VERSION "\x01v" +#define NS_SCREEN_SESSION "\x01:sessionname\r" +#define NS_SCREEN_INIT "\x01:msgminwait 0\r\x01:msgwait 1\r\x01:hardstatus lastline\r\x01:defhstatus \"\\005w\"\r\x01:hstatus \"\\005w\"\r\x01:nethack off\r\x0c" NS_SCREEN_UPDATE NS_SCREEN_VERSION NS_SCREEN_SESSION #define NS_SCREEN_PRVS_REG "\x01:focus up\r" #define NS_DFLT_SSH_PORT 22 @@ -59,14 +58,11 @@ #define NS_SCREEN_FLAGS "*-$!@L&Z" -#define NS_SCREEN_DK_CMD "unknown command '" -#define NS_SCREEN_VERSION "scre%s %d.%d.%d %s %s" +#define NS_SCREEN_DK_CMD_T "unknown command '" +#define NS_SCREEN_SESS_T "This session is named '" +#define NS_SCREEN_VERSION_T "scre%2s %d.%d.%d %16s %32s" #define NS_SCREEN_NO_DEBUG "Sorry, screen was compiled without -DDEBUG option." -/* if >0, force an update every NS_SCREEN_UPD_FREQ seconds. - a bit of a last resort. */ -#define NS_SCREEN_UPD_FREQ 0 - /* should be 1s */ #define NS_INIT_DELAY 1 @@ -79,7 +75,7 @@ #define NS_MENU_TITLE "Escreen" /* prefix for debug info */ -#define NS_PREFIX "libscream::" +#define NS_PREFIX "screamClient::" diff --git a/src/screen.c b/src/screen.c index fa459d0..3210caf 100644 --- a/src/screen.c +++ b/src/screen.c @@ -41,6 +41,12 @@ static const char cvs_ident[] = "$Id$"; #include "profile.h" #include "term.h" +#ifdef ESCREEN +# include "screamcfg.h" +#endif + +static int pb = 0; + /* These arrays store the text and rendering info that were last drawn to the screen. */ static text_t **drawn_text = NULL; static rend_t **drawn_rend = NULL; @@ -177,8 +183,7 @@ scr_reset(void) 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)); + 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; @@ -221,8 +226,7 @@ scr_reset(void) 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)); + 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); @@ -238,8 +242,7 @@ scr_reset(void) 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)); + 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++) { @@ -724,13 +727,13 @@ scr_add_lines(const unsigned char *str, int nlines, int len) c = str[i++]; #ifdef MULTI_CHARSET if ((encoding_method != LATIN1) && (chstat == WBYTE)) { - rstyle |= RS_multiMask; /* multibyte 2nd byte */ + 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 */ + if ((encoding_method != LATIN1) && (multi_byte || (c & 0x80))) { /* multibyte 1st byte */ rstyle &= ~RS_multiMask; rstyle |= RS_multi1; chstat = WBYTE; @@ -756,8 +759,8 @@ scr_add_lines(const unsigned char *str, int nlines, int len) screen.row++; row = screen.row + TermWin.saveLines; } - stp = screen.text[row]; /* _must_ refresh */ - srp = screen.rend[row]; /* _must_ refresh */ + stp = screen.text[row]; /* _must_ refresh */ + srp = screen.rend[row]; /* _must_ refresh */ continue; case '\r': LOWER_BOUND(stp[last_col], screen.col); @@ -785,8 +788,8 @@ scr_add_lines(const unsigned char *str, int nlines, int len) screen.row++; row = screen.row + TermWin.saveLines; } - stp = screen.text[row]; /* _must_ refresh */ - srp = screen.rend[row]; /* _must_ refresh */ + stp = screen.text[row]; /* _must_ refresh */ + srp = screen.rend[row]; /* _must_ refresh */ screen.col = 0; screen.flags &= ~Screen_WrapNext; } @@ -820,7 +823,7 @@ scr_add_lines(const unsigned char *str, int nlines, int len) #ifdef ESCREEN if (TermWin.screen_mode) { - if (screen.row >= TermWin.nrow - 1) { /* last row -> upd-flag */ + if (screen.row >= TermWin.nrow - 1) { /* last row -> upd-flag */ TermWin.screen_pending |= 1; } } @@ -908,7 +911,7 @@ scr_gotorc(int row, int col, int relative) screen.row += row; } } else { - if (screen.flags & Screen_Relative) { /* relative origin mode */ + if (screen.flags & Screen_Relative) { /* relative origin mode */ screen.row = row + screen.tscroll; UPPER_BOUND(screen.row, screen.bscroll); } else @@ -916,9 +919,9 @@ scr_gotorc(int row, int col, int relative) } #ifdef ESCREEN if (TermWin.screen_mode) { - if (screen.row >= TermWin.nrow - 1) { /* last row -> upd-flag */ + if (screen.row >= TermWin.nrow - 1) { /* last row -> upd-flag */ TermWin.screen_pending |= 1; - } else if (TermWin.screen_pending) { /* left last -> upd-finis */ + } else if (TermWin.screen_pending) { /* left last -> upd-finis */ TermWin.screen_pending |= 2; } } @@ -1048,7 +1051,7 @@ scr_erase_screen(int mode) default: return; } - if (row >= 0 && row <= TermWin.nrow) { /* check OOB */ + if (row >= 0 && row <= TermWin.nrow) { /* check OOB */ UPPER_BOUND(num, (TermWin.nrow - row)); if (rstyle & RS_RVid || rstyle & RS_Uline) ren = -1; @@ -1477,8 +1480,7 @@ scr_expose(int x, int y, int width, int height) 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); @@ -1624,6 +1626,7 @@ scr_refresh(int type) 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 */ #endif @@ -1716,9 +1719,9 @@ scr_refresh(int type) /* 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 */ + 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 */ @@ -1786,8 +1789,8 @@ scr_refresh(int type) /* 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 */ + drp[col] = rend; /* TODO check: may also want */ + dtp[col] = ' '; /* to poke into stp/srp */ buffer[0] = ' '; } if (wbyte) { @@ -1829,10 +1832,10 @@ scr_refresh(int type) rvid = !rvid; if (rend & RS_Cursor) { if (focus) { - is_cursor = 2; /* normal cursor */ + is_cursor = 2; /* normal cursor */ rvid = !rvid; } else { - is_cursor = 1; /* outline cursor */ + is_cursor = 1; /* outline cursor */ rend &= ~RS_Cursor; } srp[col] &= ~RS_Cursor; @@ -2028,12 +2031,10 @@ scr_refresh(int type) 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); + 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); + 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); @@ -2099,22 +2100,18 @@ scr_refresh(int type) #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)); + 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); + 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); + 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); + 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]) { @@ -2409,9 +2406,7 @@ selection_fetch(Window win, unsigned prop, int delete) 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) + 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) { @@ -2420,8 +2415,7 @@ selection_fetch(Window win, unsigned prop, int delete) 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)); + 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")); @@ -2850,7 +2844,7 @@ selection_delimit_word(int col, int row, row_col_t *beg, row_col_t *end) } if (!(Options & Opt_xterm_select)) { if (beg_col == col && beg_col > 0) { - if (DELIMIT_TEXT(*stp)) /* space or tab or cutchar */ + if (DELIMIT_TEXT(*stp)) /* space or tab or cutchar */ break; #ifdef MULTI_CHARSET srp = &(screen.rend[beg_row + row_offset][beg_col - 1]); @@ -2913,7 +2907,7 @@ selection_delimit_word(int col, int row, row_col_t *beg, row_col_t *end) } if (!(Options & Opt_xterm_select)) { if (end_col == col && end_col < last_col) { - if (DELIMIT_TEXT(*stp)) /* space or tab or cutchar */ + if (DELIMIT_TEXT(*stp)) /* space or tab or cutchar */ break; #ifdef MULTI_CHARSET srp = &(screen.rend[end_row + row_offset][end_col + 1]); @@ -3258,8 +3252,7 @@ selection_send(XSelectionRequestEvent * rq) 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]))); + (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)) { @@ -3271,8 +3264,7 @@ selection_send(XSelectionRequestEvent * rq) 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); + XChangeProperty(Xdisplay, rq->requestor, rq->property, XA_COMPOUND_TEXT(Xdisplay), 8, PropModeReplace, xtextp.value, xtextp.nitems); ev.xselection.property = rq->property; } } @@ -3284,6 +3276,30 @@ selection_send(XSelectionRequestEvent * rq) XSendEvent(Xdisplay, rq->requestor, False, 0, &ev); } +void /* drag report as used by the "twin" program */ +mouse_drag_report(XButtonEvent * ev) +{ + int button_number, key_state, x = Pixel2Col(ev->x), y = Pixel2Row(ev->y); + + switch (ev->button) { + case AnyButton: /* Button release */ + button_number = pb + Button1; /* yeah, yeah */ + break; + case Button1: /* Button press */ + case Button2: + case Button3: + pb = 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[5M%c%c%c%c%c", + (32 + button_number + (key_state << 2)), (32 + (x & 0x7f) + 1), (32 + ((x >> 7) & 0x7f) + 1), (32 + (y & 0x7f) + 1), (32 + ((y >> 7) & 0x7f) + 1)); +} + void mouse_report(XButtonEvent * ev) { @@ -3296,7 +3312,7 @@ mouse_report(XButtonEvent * ev) case Button1: /* Button press */ case Button2: case Button3: - button_number = ev->button - Button1; + pb = button_number = ev->button - Button1; break; default: /* Wheel mouse */ button_number = 64 + ev->button - Button3 - 1; @@ -3304,8 +3320,7 @@ mouse_report(XButtonEvent * ev) } 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)); + 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 @@ -3366,27 +3381,13 @@ xim_get_position(XPoint * pos) #endif #ifdef ESCREEN +# ifdef NS_HAVE_SCREEN void parse_screen_status_if_necessary(void) { -#if 0 - static int hc = 0; -#endif - ns_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; -#if 0 - { - FILE *fh; - int c; - if ((fh = fopen("Escreen.log", "a"))) { - for (c = 0; c < 8; c++) - if (strcmp(drawn_text[c], drawn_text[c + 1])) - fprintf(fh, "%2d \"%s\"\n", c, drawn_text[c]); - fclose(fh); - } - } -#endif } +# endif #endif diff --git a/src/screen.h b/src/screen.h index 2190263..a64aa26 100644 --- a/src/screen.h +++ b/src/screen.h @@ -302,6 +302,7 @@ extern void selection_extend_colrow(int, int, int, int); extern void selection_rotate(int, int); extern void selection_send(XSelectionRequestEvent *); extern void mouse_report(XButtonEvent *); +extern void mouse_drag_report(XButtonEvent *); extern void mouse_tracking(int, int, int, int, int); extern void debug_colors(void); #ifdef MULTI_CHARSET diff --git a/src/scrollbar.c b/src/scrollbar.c index b15be50..74d950b 100644 --- a/src/scrollbar.c +++ b/src/scrollbar.c @@ -54,14 +54,16 @@ scrollbar_t scrollbar = { 0, 0, 0, 0 }; + #ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING short scroll_arrow_delay; #endif 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; @@ -216,8 +218,7 @@ sb_handle_button_press(event_t *ev) #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((" 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); @@ -242,7 +243,7 @@ sb_handle_button_press(event_t *ev) } switch (ev->xbutton.button) { case Button2: - button_state.mouse_offset = scrollbar_anchor_height() / 2; /* Align to center */ + 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) { @@ -332,8 +333,7 @@ sb_handle_motion_notify(event_t *ev) 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)); + 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; @@ -341,8 +341,7 @@ sb_handle_motion_notify(event_t *ev) 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); + 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); @@ -558,11 +557,9 @@ scrollbar_draw_anchor(unsigned char image_state, unsigned char force_modes) 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()); + 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()); + draw_shadow(scrollbar.sa_win, gc_top, gc_bottom, 0, 0, scrollbar_anchor_width(), scrollbar_anchor_height(), scrollbar_get_shadow()); } } #endif @@ -603,8 +600,7 @@ scrollbar_draw_anchor(unsigned char image_state, unsigned char force_modes) 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); + 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); @@ -668,8 +664,7 @@ scrollbar_draw_trough(unsigned char image_state, unsigned char force_modes) 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()); + draw_shadow(scrollbar.win, gc_bottom, gc_top, 0, 0, scrollbar_trough_width(), scrollbar_trough_height(), scrollbar_get_shadow()); } return; } @@ -693,8 +688,7 @@ scrollbar_init(int width, int height) Attributes.override_redirect = TRUE; Attributes.save_under = TRUE; cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); - mask = ExposureMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask - | Button1MotionMask | Button2MotionMask | Button3MotionMask; + 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; @@ -725,8 +719,7 @@ scrollbar_init(int width, int height) /* 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); + 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)); @@ -776,6 +769,11 @@ void scrollbar_calc_size(int width, int height) { D_SCROLLBAR(("scrollbar_calc_size(%d, %d), type == %u\n", width, height, scrollbar_get_type())); +#ifdef ESCREEN + if (TermWin.screen && TermWin.screen->backend != NS_MODE_NONE) { + UPPER_BOUND(height, Height2Pixel(TermWin.nrow)); + } +#endif scrollbar.scrollarea_start = 0; scrollbar.scrollarea_end = height; scrollbar.up_arrow_loc = 0; @@ -800,8 +798,7 @@ scrollbar_calc_size(int width, int height) 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 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)); } @@ -816,8 +813,7 @@ scrollbar_resize(int width, int height) 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)); + ((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); diff --git a/src/startup.c b/src/startup.c index 82e6846..564f602 100644 --- a/src/startup.c +++ b/src/startup.c @@ -76,7 +76,8 @@ 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 */ + static char windowid_string[20], *display_string, *term_string; /* "WINDOWID=\0" = 10 chars, UINT_MAX = 10 chars */ + orig_argv0 = argv[0]; /* Security enhancements -- mej */ @@ -156,8 +157,7 @@ eterm_bootstrap(int argc, char *argv[]) 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) { + 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)); @@ -172,7 +172,7 @@ eterm_bootstrap(int argc, char *argv[]) len = strlen(initial_dir); if (rs_path) { - len += strlen(rs_path) + 1; /* +1 for the colon */ + len += strlen(rs_path) + 1; /* +1 for the colon */ } if (theme_dir) { len += strlen(theme_dir) + 1; @@ -204,15 +204,6 @@ eterm_bootstrap(int argc, char *argv[]) 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, URL is \"%s\")\n", TermWin.screen_mode, TermWin.nrow, rs_url); -# endif } #endif diff --git a/src/system.c b/src/system.c index e9da852..a3ab577 100644 --- a/src/system.c +++ b/src/system.c @@ -56,7 +56,7 @@ wait_for_chld(int system_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. */ + if ((pid == -1) && (errno == ECHILD)) { /* No children exist. Punt. */ errno = save_errno; break; } diff --git a/src/term.c b/src/term.c index 8f401c4..5c95cc6 100644 --- a/src/term.c +++ b/src/term.c @@ -58,7 +58,7 @@ unsigned char meta_char = 033; /* Alt-key prefix */ unsigned long PrivateModes = PrivMode_Default; unsigned long SavedModes = PrivMode_Default; char *def_colorName[] = { - "rgb:aa/aa/aa", "rgb:0/0/0", /* fg/bg */ + "rgb:aa/aa/aa", "rgb:0/0/0", /* fg/bg */ "rgb:0/0/0", /* 0: black (#000000) */ #ifndef NO_BRIGHTCOLOR /* low-intensity colors */ @@ -200,6 +200,7 @@ lookup_key(XEvent * ev) 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]; @@ -244,15 +245,13 @@ lookup_key(XEvent * ev) } 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))); + 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))); + 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)) { @@ -262,6 +261,7 @@ lookup_key(XEvent * ev) #endif /* USE_XIM */ #ifdef ESCREEN +# ifdef NS_HAVE_SCREEN if (escreen_escape) { if (kbuf[0]) { escreen_escape = 0; @@ -273,6 +273,7 @@ lookup_key(XEvent * ev) escreen_escape = 1; LK_RET(); } +# endif #endif #ifdef USE_XIM @@ -338,31 +339,31 @@ lookup_key(XEvent * ev) shft = 0; } else if (!ctrl && !meta && (PrivateModes & PrivMode_ShiftKeys)) { switch (keysym) { - case XK_Prior: /* Shift-PgUp scrolls up a page */ + 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 */ + 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. */ + 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 */ + 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 */ + case XK_KP_Subtract: /* Shift-Minus on the keypad decreases the font size */ change_font(0, SMALLER_FONT); LK_RET(); break; @@ -495,13 +496,13 @@ lookup_key(XEvent * ev) 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 */ + 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 */ + strcpy(kbuf, "\033OZ"); /* The Z is replaced by t, x, v, or r */ kbuf[2] = ("txvr"[keysym - XK_KP_Left]); break; } else { @@ -509,16 +510,16 @@ lookup_key(XEvent * ev) } /* Continue on with the normal cursor keys... */ #endif - case XK_Left: /* "\033[D" */ + case XK_Left: /* "\033[D" */ case XK_Up: /* "\033[A" */ - case XK_Right: /* "\033[C" */ - case XK_Down: /* "\033[B" */ + 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 */ + } else if (shft) { /* do Shift first */ kbuf[2] = ("dacb"[keysym - XK_Left]); } else if (ctrl) { kbuf[1] = 'O'; @@ -658,31 +659,31 @@ lookup_key(XEvent * ev) 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" */ + 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" */ + 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; @@ -811,8 +812,7 @@ sprintf((char *) kbuf,"\033[%02d~", (int)((n) + (keysym - fkey))); \ 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))); + 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(); @@ -923,8 +923,8 @@ process_escape_seq(void) 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 */ + if ((ch = cmd_getc()) == 'Q') { /* query graphics */ + tt_printf((unsigned char *) "\033G0\n"); /* no graphics */ } else { do { ch = cmd_getc(); @@ -992,7 +992,7 @@ process_csi_seq(void) 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) */ + scr_add_lines(&ch, 0, 1); /* Insert verbatim non-printable character (NPC) */ return; } if (ch == '-') /* HACK: Ignore this sequence, but finish reading */ @@ -1093,7 +1093,7 @@ process_csi_seq(void) /* 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((unsigned char *) VT100_ANS); #endif break; case 'd': /* Cursor to row n "\e[d" */ @@ -1113,10 +1113,10 @@ process_csi_seq(void) case 'i': switch (arg[0]) { case 0: - scr_printscreen(0); /* Print screen "\e[0i" */ + scr_printscreen(0); /* Print screen "\e[0i" */ break; case 5: - process_print_pipe(); /* Start printing to print pipe "\e[5i" */ + process_print_pipe(); /* Start printing to print pipe "\e[5i" */ break; } break; @@ -1373,8 +1373,7 @@ process_window_mode(unsigned int nargs, int args[]) 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); + Width2Pixel(x) + 2 * TermWin.internalBorder + (scrollbar_is_visible()? scrollbar_trough_width() : 0), Height2Pixel(y) + 2 * TermWin.internalBorder); break; case 11: break; @@ -1385,8 +1384,7 @@ process_window_mode(unsigned int nargs, int args[]) 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); + 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; @@ -1536,6 +1534,7 @@ process_terminal_mode(int mode, int priv, unsigned int nargs, int arg[]) 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; @@ -1803,6 +1802,7 @@ xterm_seq(int op, const char *str) 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; @@ -1949,7 +1949,7 @@ xterm_seq(int op, const char *str) 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 */ + viewport_pixmap = None; /* Force the re-read */ } # endif changed = 1; @@ -1958,15 +1958,14 @@ xterm_seq(int op, const char *str) 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)); + 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 */ + viewport_pixmap = None; /* Force the re-read */ } # endif if (!strcasecmp(color, "image")) { @@ -2307,8 +2306,7 @@ xterm_seq(int op, const char *str) 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); + XChangeProperty(Xdisplay, TermWin.parent, xev.message_type, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &rs_desktop, 1); XSendEvent(Xdisplay, Xroot, False, SubstructureNotifyMask, (XEvent *) & xev); } break; diff --git a/src/timer.c b/src/timer.c index 26e4120..322446d 100644 --- a/src/timer.c +++ b/src/timer.c @@ -62,8 +62,7 @@ timer_add(unsigned long msec, timer_handler_t handler, void *data) 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)); + 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); } diff --git a/src/utmp.c b/src/utmp.c index 8047636..2e5624b 100644 --- a/src/utmp.c +++ b/src/utmp.c @@ -93,6 +93,7 @@ void add_utmp_entry(const char *pty, const char *hostname, int fd) { struct passwd *pwent = getpwuid(my_ruid); + # ifdef HAVE_UTMPX_H struct utmpx utmp; struct utmp utmp2; @@ -109,12 +110,12 @@ add_utmp_entry(const char *pty, const char *hostname, int fd) 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 */ + 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 */ + 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 */ @@ -340,7 +341,7 @@ add_utmp_entry(const char *pty, const char *hostname, int fd) 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 */ + 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 */ diff --git a/src/windows.c b/src/windows.c index 31c4e80..8bfb263 100644 --- a/src/windows.c +++ b/src/windows.c @@ -144,8 +144,7 @@ get_bottom_shadow_color(Pixel norm_color, const char *type) 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); + 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); @@ -177,8 +176,7 @@ get_top_shadow_color(Pixel norm_color, const char *type) 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); + 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); @@ -208,9 +206,7 @@ get_color_by_name(const char *name, const char *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); + 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 { @@ -223,8 +219,7 @@ get_color_by_name(const char *name, const char *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); + 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 { @@ -249,12 +244,10 @@ get_color_by_pixel(Pixel pixel, Pixel fallback) } } 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); + 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); + 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); } } @@ -299,7 +292,7 @@ process_colors(void) break; #endif default: - pixel = PixColors[fgColor]; /* None */ + pixel = PixColors[fgColor]; /* None */ break; } } @@ -323,8 +316,7 @@ process_colors(void) 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[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"); } @@ -360,8 +352,7 @@ Create_Windows(int argc, char *argv[]) } Attributes.colormap = cmap; - szHint.base_width = - (2 * TermWin.internalBorder + ((Options & Opt_scrollbar) ? (scrollbar_get_width() + (2 * scrollbar_get_shadow())) : 0)); + 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); @@ -401,8 +392,7 @@ Create_Windows(int argc, char *argv[]) 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)); + 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, @@ -426,8 +416,7 @@ Create_Windows(int argc, char *argv[]) XSetWMProperties(Xdisplay, TermWin.parent, NULL, NULL, argv, argc, &szHint, &wmHint, &classHint); XSelectInput(Xdisplay, Xroot, PropertyChangeMask); - XSelectInput(Xdisplay, TermWin.parent, - (KeyPressMask | FocusChangeMask | StructureNotifyMask | VisibilityChangeMask | 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); @@ -449,20 +438,17 @@ Create_Windows(int argc, char *argv[]) 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.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); + 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); + TermWin.mask = (EnterWindowMask | LeaveWindowMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button2MotionMask | Button3MotionMask); XSelectInput(Xdisplay, TermWin.vt, TermWin.mask); /* If the user wants a specific desktop, tell the WM that */ @@ -562,15 +548,13 @@ update_size_hints(void) 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)); + 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); @@ -691,7 +675,7 @@ set_window_color(int idx, const char *color) /* handle color aliases */ if (isdigit(*color)) { i = atoi(color); - if (i >= 8 && i <= 15) { /* bright colors */ + if (i >= 8 && i <= 15) { /* bright colors */ i -= 8; # ifndef NO_BRIGHTCOLOR PixColors[idx] = PixColors[minBright + i]; diff --git a/utils/Esetroot.c b/utils/Esetroot.c index 00acb7c..6f5ac12 100644 --- a/utils/Esetroot.c +++ b/utils/Esetroot.c @@ -55,8 +55,7 @@ set_pixmap_property(Pixmap p) 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); + 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__, @@ -64,8 +63,7 @@ set_pixmap_property(Pixmap p) } 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); + fprintf(stderr, "%s:%d: set_pixmap_property(0x%08x): XKillClient() is being called.\n", __FILE__, __LINE__, (unsigned int) p); } XKillClient(Xdisplay, *((Pixmap *) data_root)); } @@ -84,8 +82,7 @@ set_pixmap_property(Pixmap p) 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); + 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); @@ -147,15 +144,13 @@ main(int argc, char *argv[]) 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 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)"); + fprintf(stderr, "%s:%d: Display name set to %s via getenv(\"DISPLAY\")\n", __FILE__, __LINE__, displayname ? displayname : "(nil)"); } } if (!displayname) { diff --git a/utils/Ettable.c b/utils/Ettable.c index 354bc2c..f4a36db 100644 --- a/utils/Ettable.c +++ b/utils/Ettable.c @@ -27,10 +27,10 @@ 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 */ + "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