eterm/src/debug.h

221 lines
9.8 KiB
C
Raw Normal View History

/*
* 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 _DEBUG_H
# define _DEBUG_H
#include <stdlib.h>
#include <time.h>
#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 */
# define NOP ((void)0)
#if defined(__FILE__) && defined(__LINE__)
Thu Feb 10 15:10:01 PST 2000 Michael Jennings <mej@eterm.org> This is the first public availability of the work thus far on Eterm 0.9.1. There's quite a bit of new stuff here. * Added scrollbar thumb support. * Completely redid the terminfo/termcap stuff. The terminfo file is now compiled (by tic) and installed by default (unless you specify --without-terminfo). The config files still say xterm, though, because some programs (like SLang and GNU mc) use the silly algorithm of "Is $TERM set to xterm?" to detect mouse reporting support in a terminal. =P But if you don't ever use xterm, you can use Eterm's termcap and just name it "xterm" instead. Thanks to Marius Gedminas <mgedmin@takas.lt> for his patch that started this whole revamp. * Added the kEsetroot script for KDE users from Dax Games <dgames@isoc.net>. * You can now configure the Home and End emulation via --with-home= and --with-end= options to configure. The --with-terminfo option is also new, and --enable-xim is now the default. * Added a new image state, disabled, for when Eterm loses focus. This is supported by all widgets (well, all those that could possibly be on screen when Eterm lost focus), even the background image. So you could actually have all your images darken on focus out and restore to normal on focus in. * Widget colors formerly dealt with as colors (menu text color, scrollbar color, etc.) are now handled by the imageclasses. Each image state can have a foreground and background color defined. The current exception is the background image; I hope to add that later. The foreground is the text color and the background is the object color (for solid color mode). So menu text color is set by the menu imageclass. And again, for unfocused colors, use the disabled state of the imageclass. * Proportionally-spaced fonts are now handled much better. They are still forced into evenly-spaced columns (it's a terminal for crying out loud!) but at least you don't end up with Eterm's wider than your screen. :-) * Home on refresh is gone, as is home on echo. It's now much simpler. There are two options: home on output, and home on input, the former being a combination of echo and refresh. Also, keypresses that don't necessarily have corresonding output can trigger a home on input, like Ctrl-End or whatever...ones that don't have special meaning. Credit to Darren Stuart Embry <dse@louisville.edu> for pointing out this issue and the one with "m-" in font names. * I finally got around to re-merging the new parser stuff from my work on the Not Game. Closed up some old potential behavior quirks with theme parsing. * Added a new escape sequence to fork-and-exec a program. Also added a scrollback search capability to highlight all occurances of a string in your scrollback buffer. Use the new "Etsearch" utility to access it. "Etsearch string" to search for a string, then "Etsearch" by itself to reset the highlighting. * And of course, the biggie. Eterm now supports a completely- customizeable buttonbar. Not a menubar, a buttonbar. It can have an arbitrary number of buttons, and each button can perform an action, just like a menuitem. So a button could bring up a menu (like a menubar) or launch a program (like a launchbar) or perform an operation (like a toolbar). Each button can have an icon, text, or both. And you can have buttons left- or right-justified in the buttonbar. You will eventually be able to have an arbitrary number of buttonbars, but I'm still working on that. As with any change this big, things could very easily be broken. So beware. :-) I have tested this myself, and everything seems to work, but I can't test every possibility. Let me know if you find anything that's broken, and enjoy! SVN revision: 2048
2000-02-10 16:25:07 -08:00
# ifdef __GNUC__
# define __DEBUG() fprintf(stderr, "[%lu] %12s | %4d: %s(): ", (unsigned long) time(NULL), __FILE__, __LINE__, __FUNCTION__)
# else
# define __DEBUG() fprintf(stderr, "[%lu] %12s | %4d: ", (unsigned long) time(NULL), __FILE__, __LINE__)
# endif
#endif
#if defined(__FILE__) && defined(__LINE__)
Thu Feb 10 15:10:01 PST 2000 Michael Jennings <mej@eterm.org> This is the first public availability of the work thus far on Eterm 0.9.1. There's quite a bit of new stuff here. * Added scrollbar thumb support. * Completely redid the terminfo/termcap stuff. The terminfo file is now compiled (by tic) and installed by default (unless you specify --without-terminfo). The config files still say xterm, though, because some programs (like SLang and GNU mc) use the silly algorithm of "Is $TERM set to xterm?" to detect mouse reporting support in a terminal. =P But if you don't ever use xterm, you can use Eterm's termcap and just name it "xterm" instead. Thanks to Marius Gedminas <mgedmin@takas.lt> for his patch that started this whole revamp. * Added the kEsetroot script for KDE users from Dax Games <dgames@isoc.net>. * You can now configure the Home and End emulation via --with-home= and --with-end= options to configure. The --with-terminfo option is also new, and --enable-xim is now the default. * Added a new image state, disabled, for when Eterm loses focus. This is supported by all widgets (well, all those that could possibly be on screen when Eterm lost focus), even the background image. So you could actually have all your images darken on focus out and restore to normal on focus in. * Widget colors formerly dealt with as colors (menu text color, scrollbar color, etc.) are now handled by the imageclasses. Each image state can have a foreground and background color defined. The current exception is the background image; I hope to add that later. The foreground is the text color and the background is the object color (for solid color mode). So menu text color is set by the menu imageclass. And again, for unfocused colors, use the disabled state of the imageclass. * Proportionally-spaced fonts are now handled much better. They are still forced into evenly-spaced columns (it's a terminal for crying out loud!) but at least you don't end up with Eterm's wider than your screen. :-) * Home on refresh is gone, as is home on echo. It's now much simpler. There are two options: home on output, and home on input, the former being a combination of echo and refresh. Also, keypresses that don't necessarily have corresonding output can trigger a home on input, like Ctrl-End or whatever...ones that don't have special meaning. Credit to Darren Stuart Embry <dse@louisville.edu> for pointing out this issue and the one with "m-" in font names. * I finally got around to re-merging the new parser stuff from my work on the Not Game. Closed up some old potential behavior quirks with theme parsing. * Added a new escape sequence to fork-and-exec a program. Also added a scrollback search capability to highlight all occurances of a string in your scrollback buffer. Use the new "Etsearch" utility to access it. "Etsearch string" to search for a string, then "Etsearch" by itself to reset the highlighting. * And of course, the biggie. Eterm now supports a completely- customizeable buttonbar. Not a menubar, a buttonbar. It can have an arbitrary number of buttons, and each button can perform an action, just like a menuitem. So a button could bring up a menu (like a menubar) or launch a program (like a launchbar) or perform an operation (like a toolbar). Each button can have an icon, text, or both. And you can have buttons left- or right-justified in the buttonbar. You will eventually be able to have an arbitrary number of buttonbars, but I'm still working on that. As with any change this big, things could very easily be broken. So beware. :-) I have tested this myself, and everything seems to work, but I can't test every possibility. Let me know if you find anything that's broken, and enjoy! SVN revision: 2048
2000-02-10 16:25:07 -08:00
# ifdef __GNUC__
# define ASSERT(x) do {if (!(x)) {if (debug_level>=1) {fatal_error("ASSERT failed in %s() at %s:%d: %s", __FUNCTION__, __FILE__, __LINE__, #x);} \
else {print_warning("ASSERT failed in %s() at %s:%d: %s", __FUNCTION__, __FILE__, __LINE__, #x);}}} while (0)
# define ASSERT_RVAL(x, val) do {if (!(x)) {if (debug_level>=1) {fatal_error("ASSERT failed in %s() at %s:%d: %s", __FUNCTION__, __FILE__, __LINE__, #x);} \
else {print_warning("ASSERT failed in %s() at %s:%d: %s", __FUNCTION__, __FILE__, __LINE__, #x);} \
return (val);}} while (0)
# define ASSERT_NOTREACHED() do {if (debug_level>=1) {fatal_error("ASSERT failed in %s() at %s:%d: This code should not be reached.", __FUNCTION__, __FILE__, __LINE__);} \
else {print_warning("ASSERT failed in %s() at %s:%d: This code should not be reached.", __FUNCTION__, __FILE__, __LINE__);} \
} while (0)
# define ASSERT_NOTREACHED_RVAL(val) do {if (debug_level>=1) {fatal_error("ASSERT failed in %s() at %s:%d: This code should not be reached.", __FUNCTION__, __FILE__, __LINE__);} \
else {print_warning("ASSERT failed in %s() at %s:%d: This code should not be reached.", __FUNCTION__, __FILE__, __LINE__);} \
return (val);} while (0)
# define ABORT() fatal_error("Aborting in %s() at %s:%d.", __FUNCTION__, __FILE__, __LINE__)
# else
# define ASSERT(x) do {if (!(x)) {if (debug_level>=1) {fatal_error("ASSERT failed at %s:%d: %s", __FILE__, __LINE__, #x);} \
else {print_warning("ASSERT failed at %s:%d: %s", __FILE__, __LINE__, #x);}}} while (0)
# define ASSERT_RVAL(x, val) do {if (!(x)) {if (debug_level>=1) {fatal_error("ASSERT failed at %s:%d: %s", __FILE__, __LINE__, #x);} \
else {print_warning("ASSERT failed at %s:%d: %s", __FILE__, __LINE__, #x);} \
return (val);}} while (0)
# define ASSERT_NOTREACHED() do {if (debug_level>=1) {fatal_error("ASSERT failed at %s:%d: This code should not be reached.", __FILE__, __LINE__);} \
else {print_warning("ASSERT failed at %s:%d: This code should not be reached.", __FILE__, __LINE__);} \
} while (0)
# define ASSERT_NOTREACHED_RVAL(val) do {if (debug_level>=1) {fatal_error("ASSERT failed at %s:%d: This code should not be reached.", __FILE__, __LINE__);} \
else {print_warning("ASSERT failed at %s:%d: This code should not be reached.", __FILE__, __LINE__);} \
return (val);} while (0)
# define ABORT() fatal_error("Aborting at %s:%d.", __FILE__, __LINE__)
# endif
#else
# define ASSERT(x) do {if (!(x)) {if (debug_level>=1) {fatal_error("ASSERT failed: %s", #x);} \
else {print_warning("ASSERT failed: %s", #x);}}} while (0)
# define ASSERT_RVAL(x, val) do {if (!(x)) {if (debug_level>=1) {fatal_error("ASSERT failed: %s", #x);} \
else {print_warning("ASSERT failed: %s", #x);} return (val);}} while (0)
# define ASSERT_NOTREACHED() return
# define ASSERT_NOTREACHED_RVAL(x) return (x)
# define ABORT() fatal_error("Aborting.")
#endif
#ifndef __DEBUG
# define __DEBUG() NOP
#endif
#define REQUIRE(x) do {if (!(x)) {if (debug_level>=1) {__DEBUG(); real_dprintf("REQUIRE failed: %s\n", #x);} return;}} while (0)
#define REQUIRE_RVAL(x, v) do {if (!(x)) {if (debug_level>=1) {__DEBUG(); real_dprintf("REQUIRE failed: %s\n", #x);} return (v);}} while (0)
#define NONULL(x) ((x) ? (x) : ("<null>"))
/* Macros for printing debugging messages */
# if DEBUG >= 1
# ifndef DPRINTF
# define DPRINTF(x) do { __DEBUG(); real_dprintf x; } while (0)
# endif
# define DPRINTF1(x) do { if (debug_level >= 1) {__DEBUG(); real_dprintf x;} } while (0)
# define DPRINTF2(x) do { if (debug_level >= 2) {__DEBUG(); real_dprintf x;} } while (0)
# define DPRINTF3(x) do { if (debug_level >= 3) {__DEBUG(); real_dprintf x;} } while (0)
# define DPRINTF4(x) do { if (debug_level >= 4) {__DEBUG(); real_dprintf x;} } while (0)
# define DPRINTF5(x) do { if (debug_level >= 5) {__DEBUG(); real_dprintf x;} } while (0)
# else
# ifndef DPRINTF
# define DPRINTF(x) NOP
# endif
# define DPRINTF1(x) NOP
# define DPRINTF2(x) NOP
# define DPRINTF3(x) NOP
# define DPRINTF4(x) NOP
# define DPRINTF5(x) NOP
# endif
/* Use this for stuff that you only want turned on in dire situations */
# define D_NEVER(x) NOP
/* Debugging macros/defines which set the debugging levels for each output type.
To change the debugging level at which something appears, change the number in
both the DEBUG_ definition and the D_ macro (if there is one). -- mej */
# define DEBUG_SCREEN 1
# define D_SCREEN(x) DPRINTF1(x)
# define DEBUG_CMD 1
# define D_CMD(x) DPRINTF1(x)
# define DEBUG_TTY 1
# define D_TTY(x) DPRINTF1(x)
# define DEBUG_SELECTION 1
# define D_SELECT(x) DPRINTF1(x)
# define DEBUG_UTMP 1
# define D_UTMP(x) DPRINTF1(x)
# define DEBUG_OPTIONS 1
# define D_OPTIONS(x) DPRINTF1(x)
# define DEBUG_IMLIB 1
# define D_IMLIB(x) DPRINTF1(x)
# define DEBUG_PIXMAP 1
# define D_PIXMAP(x) DPRINTF1(x)
# define DEBUG_EVENTS 1
# define D_EVENTS(x) DPRINTF1(x)
# define DEBUG_X11 2
# define D_X11(x) DPRINTF2(x)
# define DEBUG_ENL 2
# define D_ENL(x) DPRINTF2(x)
# define DEBUG_SCROLLBAR 2
# define D_SCROLLBAR(x) DPRINTF2(x)
Thu Feb 10 15:10:01 PST 2000 Michael Jennings <mej@eterm.org> This is the first public availability of the work thus far on Eterm 0.9.1. There's quite a bit of new stuff here. * Added scrollbar thumb support. * Completely redid the terminfo/termcap stuff. The terminfo file is now compiled (by tic) and installed by default (unless you specify --without-terminfo). The config files still say xterm, though, because some programs (like SLang and GNU mc) use the silly algorithm of "Is $TERM set to xterm?" to detect mouse reporting support in a terminal. =P But if you don't ever use xterm, you can use Eterm's termcap and just name it "xterm" instead. Thanks to Marius Gedminas <mgedmin@takas.lt> for his patch that started this whole revamp. * Added the kEsetroot script for KDE users from Dax Games <dgames@isoc.net>. * You can now configure the Home and End emulation via --with-home= and --with-end= options to configure. The --with-terminfo option is also new, and --enable-xim is now the default. * Added a new image state, disabled, for when Eterm loses focus. This is supported by all widgets (well, all those that could possibly be on screen when Eterm lost focus), even the background image. So you could actually have all your images darken on focus out and restore to normal on focus in. * Widget colors formerly dealt with as colors (menu text color, scrollbar color, etc.) are now handled by the imageclasses. Each image state can have a foreground and background color defined. The current exception is the background image; I hope to add that later. The foreground is the text color and the background is the object color (for solid color mode). So menu text color is set by the menu imageclass. And again, for unfocused colors, use the disabled state of the imageclass. * Proportionally-spaced fonts are now handled much better. They are still forced into evenly-spaced columns (it's a terminal for crying out loud!) but at least you don't end up with Eterm's wider than your screen. :-) * Home on refresh is gone, as is home on echo. It's now much simpler. There are two options: home on output, and home on input, the former being a combination of echo and refresh. Also, keypresses that don't necessarily have corresonding output can trigger a home on input, like Ctrl-End or whatever...ones that don't have special meaning. Credit to Darren Stuart Embry <dse@louisville.edu> for pointing out this issue and the one with "m-" in font names. * I finally got around to re-merging the new parser stuff from my work on the Not Game. Closed up some old potential behavior quirks with theme parsing. * Added a new escape sequence to fork-and-exec a program. Also added a scrollback search capability to highlight all occurances of a string in your scrollback buffer. Use the new "Etsearch" utility to access it. "Etsearch string" to search for a string, then "Etsearch" by itself to reset the highlighting. * And of course, the biggie. Eterm now supports a completely- customizeable buttonbar. Not a menubar, a buttonbar. It can have an arbitrary number of buttons, and each button can perform an action, just like a menuitem. So a button could bring up a menu (like a menubar) or launch a program (like a launchbar) or perform an operation (like a toolbar). Each button can have an icon, text, or both. And you can have buttons left- or right-justified in the buttonbar. You will eventually be able to have an arbitrary number of buttonbars, but I'm still working on that. As with any change this big, things could very easily be broken. So beware. :-) I have tested this myself, and everything seems to work, but I can't test every possibility. Let me know if you find anything that's broken, and enjoy! SVN revision: 2048
2000-02-10 16:25:07 -08:00
# define DEBUG_BBAR 2
# define D_BBAR(x) DPRINTF2(x)
# define DEBUG_TIMER 2
# define D_TIMER(x) DPRINTF2(x)
# define DEBUG_MENU 3
# define D_MENU(x) DPRINTF3(x)
# define DEBUG_FONT 3
# define D_FONT(x) DPRINTF3(x)
# define DEBUG_TTYMODE 3
# define D_TTYMODE(x) DPRINTF3(x)
# define DEBUG_COLORS 3
# define D_COLORS(x) DPRINTF3(x)
# define DEBUG_MALLOC 4
# define D_MALLOC(x) DPRINTF4(x)
# define DEBUG_ACTIONS 4
# define D_ACTIONS(x) DPRINTF4(x)
# define DEBUG_PROFILE 4
# define D_PROFILE(x) DPRINTF4(x)
# define DEBUG_X 5
# define DEBUG_PARSE 9999
# define D_PARSE(x) D_NEVER(x)
# define DEBUG_STRINGS 9999
# define D_STRINGS(x) D_NEVER(x)
#if (SIZEOF_LONG == 8)
# define MEMSET_LONG() l |= l<<32
#else
# define MEMSET_LONG() ((void)0)
#endif
#define MEMSET(s, c, count) do { \
char *end = (char *)(s) + (count); \
long l; \
long *l_dest = (long *)(s); \
char *c_dest; \
\
/* areas of less than 4 * sizeof(long) are set in 1-byte chunks. */ \
if (((unsigned long) count) >= 4 * sizeof(long)) { \
/* fill l with c. */ \
l = (c) | (c)<<8; \
l |= l<<16; \
MEMSET_LONG(); \
\
/* fill in 1-byte chunks until boundary of long is reached. */ \
if ((unsigned long)l_dest & (unsigned long)(sizeof(long) -1)) { \
c_dest = (char *)l_dest; \
while ((unsigned long)c_dest & (unsigned long)(sizeof(long) -1)) { \
*(c_dest++) = (c); \
} \
l_dest = (long *)c_dest; \
} \
\
/* fill in long-size chunks as long as possible. */ \
while (((unsigned long) (end - (char *)l_dest)) >= sizeof(long)) { \
*(l_dest++) = l; \
} \
} \
\
/* fill the tail in 1-byte chunks. */ \
if ((char *)l_dest < end) { \
c_dest = (char *)l_dest; \
*(c_dest++) = (c); \
while (c_dest < end) { \
*(c_dest++) = (c); \
} \
} \
} while (0)
#include "profile.h"
#endif /* _DEBUG_H */