From 4d1fd23d7e4f7b2b2f97dab76da44c4ffca3b592 Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Wed, 15 Mar 2000 03:17:45 +0000 Subject: [PATCH] Tue Mar 14 19:11:26 PST 2000 Michael Jennings Some further fixes for inline functions, 2 new winop actions, brand new and improved profiling macros, some miscellaneous fixes for SGI from Kimball Thurston , and more robust checking in the pasting code. SVN revision: 2235 --- ChangeLog | 8 ++++ configure.in | 2 +- doc/Eterm.1.in | 2 +- src/buttons.c | 4 +- src/command.c | 24 ++++++----- src/debug.h | 4 ++ src/e.c | 30 ++++++++++++++ src/events.c | 36 +++++++---------- src/menus.c | 16 ++++---- src/misc.c | 10 ++++- src/misc.h | 1 + src/options.c | 8 ++-- src/pixmap.c | 5 ++- src/pixmap.h | 2 +- src/profile.h | 105 ++++++++++++++++++------------------------------- src/screen.c | 65 +++++++++++------------------- src/startup.h | 2 +- src/term.c | 19 ++++----- utils/Etwinop | 8 +--- 19 files changed, 170 insertions(+), 181 deletions(-) diff --git a/ChangeLog b/ChangeLog index 629f731..ff873c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3339,3 +3339,11 @@ Wed Mar 8 19:35:36 PST 2000 Michael Jennings named pipe rather than to /dev/tty0. ------------------------------------------------------------------------------- +Tue Mar 14 19:11:26 PST 2000 Michael Jennings + + Some further fixes for inline functions, 2 new winop actions, brand + new and improved profiling macros, some miscellaneous fixes for SGI + from Kimball Thurston , and more robust checking + in the pasting code. + +------------------------------------------------------------------------------- diff --git a/configure.in b/configure.in index 5f9e066..a16d6c2 100644 --- a/configure.in +++ b/configure.in @@ -6,7 +6,7 @@ AM_INIT_AUTOMAKE(Eterm, 0.9.1) dnl# Set some basic variables DATE="`date '+%d %B %Y'`" AC_SUBST(DATE) -AUTHORS="Michael Jennings (mej@eterm.org) and Tuomo Venäläinen (vendu@cc.hut.fi) " +AUTHORS="Michael Jennings (mej@eterm.org) " AC_SUBST(AUTHORS) AC_DEFINE_UNQUOTED(AUTHORS, "$AUTHORS") diff --git a/doc/Eterm.1.in b/doc/Eterm.1.in index 54bc03b..3da740a 100644 --- a/doc/Eterm.1.in +++ b/doc/Eterm.1.in @@ -1542,7 +1542,7 @@ directive to allow for separation of the configuration information into multiple files. .SH AUTHORS -Michael Jennings (mej@eterm.org) and Tuomo Venäläinen (vendu@cc.hut.fi). +Michael Jennings (mej@eterm.org) Man page re-written for version 0.8 by Shaleh (shaleh@debian.org). .SH URL(s) diff --git a/src/buttons.c b/src/buttons.c index 2f99922..dd7d7e2 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -46,12 +46,12 @@ static const char cvs_ident[] = "$Id$"; #include "term.h" #include "windows.h" -static __inline__ void draw_string(buttonbar_t *, Drawable, GC, int, int, char *, size_t); +static inline void draw_string(buttonbar_t *, Drawable, GC, int, int, char *, size_t); buttonbar_t *buttonbar = NULL; long bbar_total_h = -1; -static __inline__ void +static inline void draw_string(buttonbar_t *bbar, Drawable d, GC gc, int x, int y, char *str, size_t len) { diff --git a/src/command.c b/src/command.c index 2ccba4a..4394003 100644 --- a/src/command.c +++ b/src/command.c @@ -45,6 +45,7 @@ static const char cvs_ident[] = "$Id$"; #include #include #include +#include #ifdef HAVE_FCNTL_H # include #endif @@ -106,9 +107,6 @@ static const char cvs_ident[] = "$Id$"; #if defined(linux) # include /* For N_TTY_BUF_SIZE. */ #endif -#if defined(linux) -# include /* For strsep(). -vendu */ -#endif /* Eterm-specific Headers */ #include "command.h" @@ -1130,9 +1128,9 @@ clean_exit(void) */ #ifdef __sgi -__inline__ int sgi_get_pty(void); +inline int sgi_get_pty(void); -__inline__ int +inline int sgi_get_pty(void) { int fd = -1; @@ -1146,9 +1144,9 @@ sgi_get_pty(void) #endif #ifdef HAVE_DEV_PTC -__inline__ int aix_get_pty(void); +inline int aix_get_pty(void); -__inline__ int +inline int aix_get_pty(void) { @@ -1163,9 +1161,9 @@ aix_get_pty(void) #endif #ifdef HAVE_SCO_PTYS -__inline__ int sco_get_pty(void); +inline int sco_get_pty(void); -__inline__ int +inline int sco_get_pty(void) { @@ -1197,9 +1195,9 @@ sco_get_pty(void) #endif #ifdef HAVE_DEV_PTMX -__inline__ int svr_get_pty(void); +inline int svr_get_pty(void); -__inline__ int +inline int svr_get_pty(void) { @@ -1230,9 +1228,9 @@ svr_get_pty(void) #define PTYCHAR1 "pqrstuvwxyz" #define PTYCHAR2 "0123456789abcdefghijklmnopqrstuvwxyz" -__inline__ int gen_get_pty(void); +inline int gen_get_pty(void); -__inline__ int +inline int gen_get_pty(void) { diff --git a/src/debug.h b/src/debug.h index d817151..a0ce11c 100644 --- a/src/debug.h +++ b/src/debug.h @@ -27,6 +27,10 @@ #include #include +#if defined(__GNUC__) && !defined(inline) +# define inline __inline__ +#endif + extern unsigned int debug_level; /* Assert macros stolen from my work on Ebar. If these macros break with your cpp, let me know -- mej@eterm.org */ diff --git a/src/e.c b/src/e.c index 3604290..cef3476 100644 --- a/src/e.c +++ b/src/e.c @@ -369,6 +369,36 @@ eterm_handle_winop(char *action) XMapWindow(Xdisplay, win); } else if (!BEG_STRCASECMP(action, "unmap")) { XUnmapWindow(Xdisplay, win); + } else if (!BEG_STRCASECMP(action, "move")) { + int x, y, n; + char *xx, *yy; + + n = NumWords(action); + if (n == 3 || n == 4) { + if (n == 3) { + win = TermWin.parent; + } + xx = PWord(n - 1, action); + yy = PWord(n, action); + x = (int) strtol(xx, (char **) NULL, 0); + y = (int) strtol(yy, (char **) NULL, 0); + XMoveWindow(Xdisplay, win, x, y); + } + } else if (!BEG_STRCASECMP(action, "resize")) { + int w, h, n; + char *ww, *hh; + + n = NumWords(action); + if (n == 3 || n == 4) { + if (n == 3) { + win = TermWin.parent; + } + ww = PWord(n - 1, action); + hh = PWord(n, action); + w = (int) strtol(ww, (char **) NULL, 0); + h = (int) strtol(hh, (char **) NULL, 0); + XResizeWindow(Xdisplay, win, w, h); + } } else if (!BEG_STRCASECMP(action, "kill")) { XKillClient(Xdisplay, win); } else if (!BEG_STRCASECMP(action, "iconify")) { diff --git a/src/events.c b/src/events.c index 194a7a8..25b2ae4 100644 --- a/src/events.c +++ b/src/events.c @@ -46,6 +46,7 @@ static const char cvs_ident[] = "$Id$"; #include "menus.h" #include "options.h" #include "pixmap.h" +#include "profile.h" #include "screen.h" #include "scrollbar.h" #include "term.h" @@ -199,21 +200,18 @@ event_win_is_parent(register event_dispatcher_data_t * data, Window win) unsigned char handle_key_press(event_t * ev) { - #ifdef COUNT_X_EVENTS static long long keypress_cnt = 0; #endif -#ifdef PROFILE_X_EVENTS - struct timeval keypress_start, keypress_stop; -#endif - P_SETTIMEVAL(keypress_start); + PROF_INIT(handle_key_press); D_EVENTS(("handle_key_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); - COUNT_EVENT(keypress_cnt); REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); + + COUNT_EVENT(keypress_cnt); lookup_key(ev); - P_SETTIMEVAL(keypress_stop); - P_EVENT_TIME("KeyPress", keypress_start, keypress_stop); + PROF_DONE(handle_key_press); + PROF_TIME(handle_key_press); return 1; } @@ -550,15 +548,11 @@ handle_selection_request(event_t * ev) unsigned char handle_expose(event_t * ev) { - #ifdef COUNT_X_EVENTS static long long expose_cnt = 0; #endif -#ifdef PROFILE_X_EVENTS - struct timeval expose_start, expose_stop; -#endif - P_SETTIMEVAL(expose_start); + PROF_INIT(handle_expose); D_EVENTS(("handle_expose(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); @@ -581,8 +575,8 @@ handle_expose(event_t * ev) XSelectInput(Xdisplay, desktop_window, PropertyChangeMask); } #endif - P_SETTIMEVAL(expose_stop); - P_EVENT_TIME("Expose", expose_start, expose_stop); + PROF_DONE(handle_expose); + PROF_TIME(handle_expose); return 1; } @@ -712,18 +706,14 @@ handle_button_release(event_t * ev) unsigned char handle_motion_notify(event_t * ev) { - #ifdef COUNT_X_EVENTS static long long motion_cnt = 0; #endif -#ifdef PROFILE_X_EVENTS - struct timeval motion_start, motion_stop; -#endif + PROF_INIT(handle_motion_notify); D_EVENTS(("handle_motion_notify(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window)); COUNT_EVENT(motion_cnt); - P_SETTIMEVAL(motion_start); REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); if ((PrivateModes & PrivMode_mouse_report) && !(button_state.bypass_keystate)) @@ -743,10 +733,12 @@ handle_motion_notify(event_t * ev) #endif selection_extend((ev->xbutton.x), (ev->xbutton.y), (ev->xbutton.state & Button3Mask)); } - P_SETTIMEVAL(motion_stop); - P_EVENT_TIME("MotionNotify", motion_start, motion_stop); + PROF_DONE(handle_motion_notify); + PROF_TIME(handle_motion_notify); return 1; } + PROF_DONE(handle_motion_notify); + PROF_TIME(handle_motion_notify); return 1; } diff --git a/src/menus.c b/src/menus.c index 9ca04a0..42a667a 100644 --- a/src/menus.c +++ b/src/menus.c @@ -52,12 +52,12 @@ static Time button_press_time; static int button_press_x = 0, button_press_y = 0; static menu_t *current_menu; -static __inline__ void grab_pointer(Window win); -static __inline__ void ungrab_pointer(void); -static __inline__ void draw_string(Drawable d, GC gc, int x, int y, char *str, size_t len); -static __inline__ unsigned short center_coords(register unsigned short c1, register unsigned short c2); +static inline void grab_pointer(Window win); +static inline void ungrab_pointer(void); +static inline void draw_string(Drawable d, GC gc, int x, int y, char *str, size_t len); +static inline unsigned short center_coords(register unsigned short c1, register unsigned short c2); -static __inline__ void +static inline void grab_pointer(Window win) { @@ -88,7 +88,7 @@ grab_pointer(Window win) } } -static __inline__ void +static inline void ungrab_pointer(void) { @@ -96,7 +96,7 @@ ungrab_pointer(void) XUngrabPointer(Xdisplay, CurrentTime); } -static __inline__ void +static inline void draw_string(Drawable d, GC gc, int x, int y, char *str, size_t len) { @@ -110,7 +110,7 @@ draw_string(Drawable d, GC gc, int x, int y, char *str, size_t len) XDrawString(Xdisplay, d, gc, x, y, str, len); } -static __inline__ unsigned short +static inline unsigned short center_coords(register unsigned short c1, register unsigned short c2) { diff --git a/src/misc.c b/src/misc.c index afc7068..3b859cb 100644 --- a/src/misc.c +++ b/src/misc.c @@ -297,9 +297,17 @@ safe_print_string(char *str, unsigned long len) char *p; unsigned long n = 0, i; + if (len == ((unsigned long) -1)) { + FREE(ret_buff); + rb_size = 0; + return ((char *) NULL); + } if (ret_buff == NULL) { - ret_buff = (char *) MALLOC(len + 1); rb_size = len; + ret_buff = (char *) MALLOC(rb_size + 1); + } else if (len > rb_size) { + rb_size = len; + ret_buff = (char *) REALLOC(ret_buff, rb_size + 1); } for (i = 0, p = ret_buff; i < len; i++, str++, n++) { if (n + 2 >= rb_size) { diff --git a/src/misc.h b/src/misc.h index 04f5606..14f91c2 100644 --- a/src/misc.h +++ b/src/misc.h @@ -42,6 +42,7 @@ extern char *str_trim(char *str); extern int parse_escaped_string(char *str); extern const char *search_path(const char *pathlist, const char *file, const char *ext); extern const char *find_file(const char *file, const char *ext); +extern char *safe_print_string(char *buff, unsigned long len); extern unsigned long add_carriage_returns(unsigned char *buff, unsigned long cnt); _XFUNCPROTOEND diff --git a/src/options.c b/src/options.c index f61f79a..52b6ca6 100644 --- a/src/options.c +++ b/src/options.c @@ -2504,7 +2504,7 @@ parse_image(char *buff, void *state) tmp = (int *) MALLOC(sizeof(int)); return ((void *) tmp); } - ASSERT_RVAL(state != NULL, (file_skip_to_end(), NULL)); + ASSERT_RVAL(state != NULL, (void *)(file_skip_to_end(), NULL)); if (*buff == CONF_END_CHAR) { int *tmp; @@ -2973,7 +2973,7 @@ parse_menu(char *buff, void *state) menu = menu_create(title); return ((void *) menu); } - ASSERT_RVAL(state != NULL, (file_skip_to_end(), NULL)); + ASSERT_RVAL(state != NULL, (void *)(file_skip_to_end(), NULL)); menu = (menu_t *) state; if (*buff == CONF_END_CHAR) { if (!(*(menu->title))) { @@ -3021,7 +3021,7 @@ parse_menuitem(char *buff, void *state) static menu_t *menu; menuitem_t *curitem; - ASSERT_RVAL(state != NULL, (file_skip_to_end(), NULL)); + ASSERT_RVAL(state != NULL, (void *)(file_skip_to_end(), NULL)); if (*buff == CONF_BEGIN_CHAR) { menu = (menu_t *) state; curitem = menuitem_create(NULL); @@ -3096,7 +3096,7 @@ parse_bbar(char *buff, void *state) bbar = bbar_create(); return ((void *) bbar); } - ASSERT_RVAL(state != NULL, (file_skip_to_end(), NULL)); + ASSERT_RVAL(state != NULL, (void *)(file_skip_to_end(), NULL)); bbar = (buttonbar_t *) state; if (*buff == CONF_END_CHAR) { bbar_add(bbar); diff --git a/src/pixmap.c b/src/pixmap.c index 47a30b6..f061039 100644 --- a/src/pixmap.c +++ b/src/pixmap.c @@ -45,6 +45,7 @@ static const char cvs_ident[] = "$Id$"; #include "screen.h" #include "scrollbar.h" #include "term.h" +#include "windows.h" #ifdef PIXMAP_SUPPORT static ImlibBorder bord_none = { 0, 0, 0, 0 }; @@ -1556,7 +1557,7 @@ get_desktop_pixmap(void) if (desktop_window == None) { D_PIXMAP(("No desktop window. Aborting.\n")); free_desktop_pixmap(); - return (desktop_pixmap = None); + return (None); } prop = XInternAtom(Xdisplay, "_XROOTPMAP_ID", True); @@ -1564,7 +1565,7 @@ get_desktop_pixmap(void) if (prop == None && prop2 == None) { free_desktop_pixmap(); - return (desktop_pixmap = None); + return (None); } if (color_pixmap != None) { D_PIXMAP(("Removing old solid color pixmap 0x%08x.\n", color_pixmap)); diff --git a/src/pixmap.h b/src/pixmap.h index 1a1fcc7..d504372 100644 --- a/src/pixmap.h +++ b/src/pixmap.h @@ -51,7 +51,7 @@ # define delete_simage(simg) NOP #endif #define PIXMAP_EXT NULL -/* '[', 2*4 + 2*3 digits + 3 delimiters, ']'. -vendu */ + #define GEOM_LEN 19 enum { diff --git a/src/profile.h b/src/profile.h index ec44bbc..743fe67 100644 --- a/src/profile.h +++ b/src/profile.h @@ -1,78 +1,49 @@ -/* profile.h for Eterm. - * 25 Mar 1998, vendu. +/* + * Copyright (C) 1997-2000, Michael Jennings + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef _PROFILE_H # define _PROFILE_H -/* included for a possible #define PROFILE */ -# include +#ifdef ENABLE_PROFILE + # include # include -/* NOTE: if PROFILE is not defined, all macros in this file will - * be set to (void)0 so they won't get compiled into binaries. - */ -# ifdef ENABLE_PROFILE - -/* Data structures */ - typedef struct { - long long total; - struct timeval start; - struct timeval stop; -} P_counter_t; + const char *func_name; + struct timeval start_time, end_time; +} prof_time_t; -/* Profiling macros */ +# define PROF_INIT(f) prof_time_t f##_prof_time = { #f, { 0, 0 }, { 0, 0 } }; gettimeofday(& f##_prof_time.start_time, NULL) +# define PROF_DONE(f) gettimeofday(& f##_prof_time.end_time, NULL) +# define PROF_TIME(f) do {prof_time_t t = f##_prof_time; unsigned long s, u; s = t.end_time.tv_sec - t.start_time.tv_sec; u = t.end_time.tv_usec - t.start_time.tv_usec; \ + if (u > 1000000UL) {s--; u += 1000000UL;} D_PROFILE(("Elapsed time for function %s: %d.%06d seconds.\n", #f, s, u));} while (0) +# define PROF_FUNC(f, c) do {PROF_INIT(f); c; PROF_DONE(f); PROF_TIME(f);} while (0) +#else +# define PROF_INIT(f) NOP +# define PROF_DONE(f) NOP +# define PROF_TIME(f) NOP +# define PROF_FUNC(f, c) NOP +#endif /* ENABLE_PROFILE */ -/* Sets tv to current time. - * struct timeval tv; - * Usage: P_SETTIMEVAL(struct timeval tv); - */ -# define P_SETTIMEVAL(tv) gettimeofday(&(tv), NULL) - -/* NOT FINISHED YET */ -# define P_UPDATETOTAL(cnt) { \ - cnt.total += P_CMPTIMEVALS_USEC(cnt.start, cnt.stop); \ -} - -/* Declare cnt and initialize by setting to zero. - * P_counter_t cnt; - * Usage: P_INITCOUNTER(counter); - * NOTES: cnt will be declared. This means that you'll - * probably need to localize a block where to use this; see - * the definition of P_CALL() elsewhere in this file. - */ -# define P_INITCOUNTER(cnt) \ - P_counter_t cnt = { 0, { 0, 0 }, { 0, 0 } } -/* Time from start to stop in microseconds - * struct timeval start, stop; - */ -# define P_CMPTIMEVALS_USEC(start, stop) \ - ((stop.tv_sec - start.tv_sec)*1000000 \ - + (stop.tv_usec - start.tv_usec)) - -/* Counts the time spent in the call f and outputs - * str: