Wed Aug 30 22:58:18 PDT 2000 Michael Jennings <mej@eterm.org>
Massive reorganization/rewrite to libmej. It should now be 100% independent of Eterm. There still may be some gremlins in the memory debugging code, so don't use too high a number with --debug.... SVN revision: 3282
This commit is contained in:
parent
eb4400feea
commit
9a6507f458
|
@ -3834,3 +3834,10 @@ Tue Aug 22 21:35:50 PDT 2000 Michael Jennings <mej@eterm.org>
|
|||
This should fix the selection problems between Eterm and other apps.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Wed Aug 30 22:58:18 PDT 2000 Michael Jennings <mej@eterm.org>
|
||||
|
||||
Massive reorganization/rewrite to libmej. It should now be 100%
|
||||
independent of Eterm. There still may be some gremlins in the memory
|
||||
debugging code, so don't use too high a number with --debug....
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
|
|
@ -128,7 +128,7 @@ dnl# Checks for header files.
|
|||
AC_HEADER_SYS_WAIT
|
||||
AC_CHECK_HEADERS(fcntl.h termios.h \
|
||||
sys/ioctl.h sys/select.h sys/time.h \
|
||||
sys/sockio.h sys/byteorder.h \
|
||||
sys/sockio.h sys/byteorder.h malloc.h \
|
||||
utmpx.h unistd.h bsd/signal.h regex.h \
|
||||
regexp.h stdarg.h X11/Xmu/Atoms.h)
|
||||
AC_HEADER_TIME
|
||||
|
@ -141,7 +141,10 @@ AC_TYPE_UID_T
|
|||
|
||||
dnl# Checks for library functions.
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS(atexit _exit unsetenv setutent seteuid memmove putenv strsep setresuid setresgid memmem usleep snprintf)
|
||||
AC_CHECK_FUNCS(atexit _exit unsetenv setutent \
|
||||
seteuid memmove putenv strsep setresuid setresgid \
|
||||
memmem usleep snprintf strcasestr strcasechr \
|
||||
strcasepbrk strrev)
|
||||
dps_snprintf_oflow()
|
||||
AC_CHECK_LIB(m, pow, LIBS="$LIBS -lm", , $SUBLIBS)
|
||||
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
# $Id$
|
||||
|
||||
lib_LTLIBRARIES = libmej.la
|
||||
include_HEADERS = libmej.h
|
||||
|
||||
libmej_la_SOURCES = debug.c mem.c strings.c snprintf.c
|
||||
libmej_la_SOURCES = debug.c mem.c msgs.c strings.c snprintf.c libmej.h
|
||||
|
||||
INCLUDES = -I. -I.. -I$(includedir) -I$(prefix)/include
|
||||
|
||||
libmej_la_LDFLAGS = -release $(VERSION)
|
||||
|
||||
EXTRA_DIST = debug.h global.h mem.h strings.h strptime.h strptime.c
|
||||
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*********************************************************
|
||||
* DEBUG.C -- Standardized debugging output *
|
||||
* -- Michael Jennings *
|
||||
* -- 20 December 1996 *
|
||||
*********************************************************/
|
||||
/*
|
||||
* Copyright (C) 1997-2000, Michael Jennings
|
||||
*
|
||||
|
@ -28,31 +23,14 @@
|
|||
|
||||
static const char cvs_ident[] = "$Id$";
|
||||
|
||||
#include "config.h"
|
||||
#include "../src/feature.h"
|
||||
|
||||
#include "global.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef WITH_DMALLOC
|
||||
# include <malloc.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include "debug.h"
|
||||
|
||||
int
|
||||
real_dprintf(const char *format,...)
|
||||
{
|
||||
#include "libmej.h"
|
||||
|
||||
va_list args;
|
||||
int n;
|
||||
/* FIXME: Change this to an unsigned short once the
|
||||
options parser can handle function pointers. */
|
||||
unsigned int libmej_debug_level = 0;
|
||||
unsigned long libmej_debug_flags = 0;
|
||||
|
||||
va_start(args, format);
|
||||
n = vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
fflush(stderr);
|
||||
return (n);
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/**********************************************************
|
||||
* DEBUG.H -- Header file for DEBUG.C *
|
||||
* -- Michael Jennings *
|
||||
* -- 20 December 1996 *
|
||||
**********************************************************/
|
||||
/*
|
||||
* 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 _LIBMEJ_DEBUG_H
|
||||
# define _LIBMEJ_DEBUG_H
|
||||
|
||||
extern int real_dprintf(const char *, ...);
|
||||
|
||||
#include "../src/debug.h"
|
||||
|
||||
#endif /* _LIBMEJ_DEBUG_H */
|
|
@ -0,0 +1,347 @@
|
|||
/*
|
||||
* 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 _LIBMEJ_H_
|
||||
#define _LIBMEJ_H_
|
||||
|
||||
/* This GNU goop has to go before the system headers */
|
||||
#ifdef __GNUC__
|
||||
# ifndef __USE_GNU
|
||||
# define __USE_GNU
|
||||
# endif
|
||||
# ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# ifndef _BSD_SOURCE
|
||||
# define _BSD_SOURCE
|
||||
# endif
|
||||
# ifndef inline
|
||||
# define inline __inline__
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#ifdef HAVE_REGEX_H
|
||||
# include <regex.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDARG_H
|
||||
# include <stdarg.h>
|
||||
#endif
|
||||
#ifdef WITH_DMALLOC
|
||||
# include <dmalloc.h>
|
||||
#elif defined(HAVE_MALLOC_H)
|
||||
# include <malloc.h>
|
||||
#endif
|
||||
|
||||
/******************************* GENERIC GOOP *********************************/
|
||||
#ifndef TRUE
|
||||
# define TRUE ((unsigned char)(1))
|
||||
# define FALSE ((unsigned char)(0))
|
||||
#endif
|
||||
|
||||
#ifndef PACKAGE
|
||||
# define PACKAGE "libmej"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****************************** DEBUGGING GOOP ********************************/
|
||||
#ifndef LIBMEJ_DEBUG_FD
|
||||
# define LIBMEJ_DEBUG_FD (stderr)
|
||||
#endif
|
||||
#ifndef DEBUG
|
||||
# define DEBUG 0
|
||||
#endif
|
||||
|
||||
#define DEBUG_LEVEL (libmej_debug_level)
|
||||
#define DEBUG_FLAGS (libmej_debug_flags)
|
||||
|
||||
/* A NOP. Does nothing. */
|
||||
#define NOP ((void)0)
|
||||
|
||||
/* A macro and an #define to FIXME-ize individual calls or entire code blocks. */
|
||||
#define FIXME_NOP(x)
|
||||
#define FIXME_BLOCK 0
|
||||
|
||||
/* The basic debugging output leader. */
|
||||
#if defined(__FILE__) && defined(__LINE__)
|
||||
# ifdef __GNUC__
|
||||
# define __DEBUG() fprintf(LIBMEJ_DEBUG_FD, "[%lu] %12s | %4d: %s(): ", (unsigned long) time(NULL), __FILE__, __LINE__, __FUNCTION__)
|
||||
# else
|
||||
# define __DEBUG() fprintf(LIBMEJ_DEBUG_FD, "[%lu] %12s | %4d: ", (unsigned long) time(NULL), __FILE__, __LINE__)
|
||||
# endif
|
||||
#else
|
||||
# define __DEBUG() NOP
|
||||
#endif
|
||||
|
||||
/* A quick and dirty macro to say, "Hi! I got here without crashing!" */
|
||||
#define MOO() do { __DEBUG(); fprintf(LIBMEJ_DEBUG_FD, "Moo.\n"); fflush(LIBMEJ_DEBUG_FD); } while (0)
|
||||
|
||||
/* Assertion/abort macros which are quite a bit more useful than assert() and abort(). */
|
||||
#if defined(__FILE__) && defined(__LINE__)
|
||||
# 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.\n")
|
||||
#endif
|
||||
|
||||
#define REQUIRE(x) do {if (!(x)) {if (DEBUG_LEVEL>=1) {__DEBUG(); libmej_dprintf("REQUIRE failed: %s\n", #x);} return;}} while (0)
|
||||
#define REQUIRE_RVAL(x, v) do {if (!(x)) {if (DEBUG_LEVEL>=1) {__DEBUG(); libmej_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(); libmej_dprintf x; } while (0)
|
||||
# endif
|
||||
# define DPRINTF1(x) do { if (DEBUG_LEVEL >= 1) {__DEBUG(); libmej_dprintf x;} } while (0)
|
||||
# define DPRINTF2(x) do { if (DEBUG_LEVEL >= 2) {__DEBUG(); libmej_dprintf x;} } while (0)
|
||||
# define DPRINTF3(x) do { if (DEBUG_LEVEL >= 3) {__DEBUG(); libmej_dprintf x;} } while (0)
|
||||
# define DPRINTF4(x) do { if (DEBUG_LEVEL >= 4) {__DEBUG(); libmej_dprintf x;} } while (0)
|
||||
# define DPRINTF5(x) do { if (DEBUG_LEVEL >= 5) {__DEBUG(); libmej_dprintf x;} } while (0)
|
||||
# define DPRINTF6(x) do { if (DEBUG_LEVEL >= 6) {__DEBUG(); libmej_dprintf x;} } while (0)
|
||||
# define DPRINTF7(x) do { if (DEBUG_LEVEL >= 7) {__DEBUG(); libmej_dprintf x;} } while (0)
|
||||
# define DPRINTF8(x) do { if (DEBUG_LEVEL >= 8) {__DEBUG(); libmej_dprintf x;} } while (0)
|
||||
# define DPRINTF9(x) do { if (DEBUG_LEVEL >= 9) {__DEBUG(); libmej_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
|
||||
# define DPRINTF6(x) NOP
|
||||
# define DPRINTF7(x) NOP
|
||||
# define DPRINTF8(x) NOP
|
||||
# define DPRINTF9(x) NOP
|
||||
#endif
|
||||
|
||||
/* Use this for stuff that you only want turned on in dire situations */
|
||||
#define D_NEVER(x) NOP
|
||||
|
||||
#define DEBUG_MEM 5
|
||||
#define D_MEM(x) DPRINTF5(x)
|
||||
#define DEBUG_STRINGS 9999
|
||||
#define D_STRINGS(x) D_NEVER(x)
|
||||
|
||||
|
||||
|
||||
/********************************* MEM GOOP ***********************************/
|
||||
typedef struct ptr_struct {
|
||||
void *ptr;
|
||||
size_t size;
|
||||
} ptr_t;
|
||||
typedef struct memrec_struct {
|
||||
unsigned char init;
|
||||
unsigned long cnt;
|
||||
ptr_t *ptrs;
|
||||
} memrec_t;
|
||||
|
||||
#if (DEBUG >= DEBUG_MEM)
|
||||
# define MALLOC(sz) libmej_malloc(__FILE__, __LINE__, (sz))
|
||||
# define CALLOC(type,n) libmej_calloc(__FILE__, __LINE__, (n), (sizeof(type)))
|
||||
# define REALLOC(mem,sz) libmej_realloc(#mem, __FILE__, __LINE__, (mem), (sz))
|
||||
# define FREE(ptr) do { libmej_free(#ptr, __FILE__, __LINE__, (ptr)); (ptr) = NULL; } while (0)
|
||||
# define STRDUP(s) libmej_strdup(#s, __FILE__, __LINE__, (s))
|
||||
# define MALLOC_MOD 25
|
||||
# define REALLOC_MOD 25
|
||||
# define CALLOC_MOD 25
|
||||
# define FREE_MOD 25
|
||||
#else
|
||||
# define MALLOC(sz) malloc(sz)
|
||||
# define CALLOC(type,n) calloc((n),(sizeof(type)))
|
||||
# define REALLOC(mem,sz) ((sz) ? ((mem) ? (realloc((mem), (sz))) : (malloc(sz))) : ((mem) ? (free(mem), NULL) : (NULL)))
|
||||
# define FREE(ptr) do { free(ptr); (ptr) = NULL; } while (0)
|
||||
# define STRDUP(s) strdup(s)
|
||||
#endif
|
||||
|
||||
/* Fast memset() macro contributed by vendu */
|
||||
#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)
|
||||
|
||||
|
||||
|
||||
/******************************* STRINGS GOOP *********************************/
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define SWAP(a, b) __extension__ ({__typeof__(a) tmp = (a); (a) = (b); (b) = tmp;})
|
||||
#else
|
||||
# define SWAP(a, b) do {void *tmp = ((void *)(a)); (a) = (b); (b) = tmp;} while (0)
|
||||
#endif
|
||||
|
||||
#define CONST_STRLEN(x) (sizeof(x) - 1)
|
||||
#define BEG_STRCASECMP(s, constr) (strncasecmp(s, constr, CONST_STRLEN(constr)))
|
||||
|
||||
|
||||
|
||||
/******************************** PROTOTYPES **********************************/
|
||||
|
||||
/* msgs.c */
|
||||
extern int libmej_dprintf(const char *, ...);
|
||||
extern void print_error(const char *fmt, ...);
|
||||
extern void print_warning(const char *fmt, ...);
|
||||
extern void fatal_error(const char *fmt, ...);
|
||||
|
||||
/* debug.c */
|
||||
extern unsigned int DEBUG_LEVEL;
|
||||
|
||||
/* mem.c */
|
||||
extern void memrec_init(void);
|
||||
extern void memrec_add_var(void *, size_t);
|
||||
extern void memrec_rem_var(const char *, const char *, unsigned long, void *);
|
||||
extern void memrec_chg_var(const char *, const char *, unsigned long, void *, void *, size_t);
|
||||
extern void memrec_dump(void);
|
||||
extern void *libmej_malloc(const char *, unsigned long, size_t);
|
||||
extern void *libmej_realloc(const char *, const char *, unsigned long, void *, size_t);
|
||||
extern void *libmej_calloc(const char *, unsigned long, size_t, size_t);
|
||||
extern void libmej_free(const char *, const char *, unsigned long, void *);
|
||||
extern char *libmej_strdup(const char *, const char *, unsigned long, const char *);
|
||||
extern void libmej_handle_sigsegv(int);
|
||||
|
||||
/* strings.c */
|
||||
extern char *left_str(const char *, unsigned long);
|
||||
extern char *mid_str(const char *, unsigned long, unsigned long);
|
||||
extern char *right_str(const char *, unsigned long);
|
||||
#ifdef HAVE_REGEX_H
|
||||
extern unsigned char regexp_match(const char *, const char *);
|
||||
#endif
|
||||
extern char *get_word(unsigned long, const char *);
|
||||
extern char *get_pword(unsigned long, const char *);
|
||||
extern unsigned long num_words(const char *);
|
||||
extern char *strip_whitespace(char *);
|
||||
extern char *downcase_str(char *);
|
||||
extern char *upcase_str(char *);
|
||||
#ifndef HAVE_STRCASESTR
|
||||
extern char *strcasestr(char *, const char *);
|
||||
#endif
|
||||
#ifndef HAVE_STRCASECHR
|
||||
extern char *strcasechr(char *, char);
|
||||
#endif
|
||||
#ifndef HAVE_STRCASEPBRK
|
||||
extern char *strcasepbrk(char *, char *);
|
||||
#endif
|
||||
#ifndef HAVE_STRREV
|
||||
extern char *strrev(char *);
|
||||
#endif
|
||||
#if !(HAVE_STRSEP)
|
||||
extern char *strsep(char **, char *);
|
||||
#endif
|
||||
extern char *safe_str(char *, unsigned short);
|
||||
extern char *garbage_collect(char *, size_t);
|
||||
extern char *file_garbage_collect(char *, size_t);
|
||||
extern char *condense_whitespace(char *);
|
||||
extern void hex_dump(void *, size_t);
|
||||
#ifndef HAVE_MEMMEM
|
||||
extern void *memmem(void *, size_t, void *, size_t);
|
||||
#endif
|
||||
#ifndef HAVE_USLEEP
|
||||
extern void usleep(unsigned long);
|
||||
#endif
|
||||
#ifndef HAVE_SNPRINTF
|
||||
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
|
||||
extern int snprintf(char *str, size_t count, const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
#endif /* _LIBMEJ_H_ */
|
308
libmej/mem.c
308
libmej/mem.c
|
@ -1,9 +1,4 @@
|
|||
|
||||
/***************************************************************
|
||||
* MEM.C -- Memory allocation handlers *
|
||||
* -- Michael Jennings *
|
||||
* -- 07 January 1997 *
|
||||
***************************************************************/
|
||||
/*
|
||||
* Copyright (C) 1997-2000, Michael Jennings
|
||||
*
|
||||
|
@ -29,20 +24,11 @@
|
|||
|
||||
static const char cvs_ident[] = "$Id$";
|
||||
|
||||
#include "config.h"
|
||||
#include "../src/feature.h"
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "global.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "mem.h"
|
||||
#include "libmej.h"
|
||||
|
||||
/*
|
||||
* These're added for a pretty obvious reason -- they're implemented towards
|
||||
|
@ -56,276 +42,244 @@ static int realloc_count = 0;
|
|||
static int free_count = 0;
|
||||
#endif
|
||||
|
||||
MemRec memrec =
|
||||
{0, 0, 0, (void **) NULL, (size_t *) NULL};
|
||||
|
||||
char *
|
||||
SafeStr(register char *str, unsigned short len)
|
||||
{
|
||||
register unsigned short i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (iscntrl(str[i])) {
|
||||
str[i] = '.';
|
||||
}
|
||||
}
|
||||
|
||||
return (str);
|
||||
}
|
||||
static memrec_t memrec;
|
||||
|
||||
void
|
||||
memrec_init(void)
|
||||
{
|
||||
memrec.Count = 0;
|
||||
D_MALLOC(("Constructing memrec\n"));
|
||||
memrec.Ptrs = (void **) malloc(sizeof(void *));
|
||||
|
||||
memrec.Size = (size_t *) malloc(sizeof(size_t));
|
||||
D_MEM(("Constructing memrec\n"));
|
||||
memrec.ptrs = (ptr_t *) malloc(sizeof(ptr_t));
|
||||
memrec.init = 1;
|
||||
}
|
||||
|
||||
void
|
||||
memrec_add_var(void *ptr, size_t size)
|
||||
{
|
||||
memrec.Count++;
|
||||
if ((memrec.Ptrs = (void **) realloc(memrec.Ptrs, sizeof(void *) * memrec.Count)) == NULL) {
|
||||
D_MALLOC(("Unable to reallocate pointer list -- %s\n", strerror(errno)));
|
||||
register ptr_t *p;
|
||||
|
||||
memrec.cnt++;
|
||||
if ((memrec.ptrs = (ptr_t *) realloc(memrec.ptrs, sizeof(ptr_t) * memrec.cnt)) == NULL) {
|
||||
D_MEM(("Unable to reallocate pointer list -- %s\n", strerror(errno)));
|
||||
}
|
||||
if ((memrec.Size = (size_t *) realloc(memrec.Size, sizeof(size_t) * memrec.Count)) == NULL) {
|
||||
D_MALLOC(("Unable to reallocate pointer size list -- %s\n", strerror(errno)));
|
||||
}
|
||||
D_MALLOC(("Adding variable of size %lu at %8p\n", size, ptr));
|
||||
memrec.Ptrs[memrec.Count - 1] = ptr;
|
||||
memrec.Size[memrec.Count - 1] = size;
|
||||
D_MEM(("Adding variable of size %lu at %8p\n", size, ptr));
|
||||
p = memrec.ptrs + memrec.cnt - 1;
|
||||
p->ptr = ptr;
|
||||
p->size = size;
|
||||
}
|
||||
|
||||
void
|
||||
memrec_rem_var(const char *filename, unsigned long line, void *ptr)
|
||||
memrec_rem_var(const char *var, const char *filename, unsigned long line, void *ptr)
|
||||
{
|
||||
register ptr_t *p = NULL;
|
||||
register unsigned long i;
|
||||
|
||||
unsigned long i;
|
||||
|
||||
for (i = 0; i < memrec.Count; i++)
|
||||
if (memrec.Ptrs[i] == ptr)
|
||||
for (i = 0; i < memrec.cnt; i++) {
|
||||
if (memrec.ptrs[i].ptr == ptr) {
|
||||
p = memrec.ptrs + i;
|
||||
break;
|
||||
if (i == memrec.Count && memrec.Ptrs[i] != ptr) {
|
||||
D_MALLOC(("ERROR: File %s, line %d attempted to free a pointer not allocated with Malloc/Realloc: %8p\n", filename, line, ptr));
|
||||
}
|
||||
}
|
||||
if (!p) {
|
||||
D_MEM(("ERROR: File %s, line %d attempted to free variable %s (%8p) which was not allocated with MALLOC/REALLOC\n", filename, line, var, ptr));
|
||||
return;
|
||||
}
|
||||
memrec.Count--;
|
||||
D_MALLOC(("Removing variable of size %lu at %8p\n", memrec.Size[i], memrec.Ptrs[i]));
|
||||
memmove(memrec.Ptrs + i, memrec.Ptrs + i + 1, sizeof(void *) * (memrec.Count - i));
|
||||
|
||||
memmove(memrec.Size + i, memrec.Size + i + 1, sizeof(size_t) * (memrec.Count - i));
|
||||
memrec.Ptrs = (void **) realloc(memrec.Ptrs, sizeof(void *) * memrec.Count);
|
||||
|
||||
memrec.Size = (size_t *) realloc(memrec.Size, sizeof(size_t) * memrec.Count);
|
||||
memrec.cnt--;
|
||||
D_MEM(("Removing variable of size %lu at %8p\n", p->size, p->ptr));
|
||||
memmove(p, p + 1, sizeof(ptr_t) * (memrec.cnt - i));
|
||||
memrec.ptrs = (ptr_t *) realloc(memrec.ptrs, sizeof(ptr_t) * memrec.cnt);
|
||||
}
|
||||
|
||||
void
|
||||
memrec_chg_var(const char *filename, unsigned long line, void *oldp, void *newp, size_t size)
|
||||
memrec_chg_var(const char *var, const char *filename, unsigned long line, void *oldp, void *newp, size_t size)
|
||||
{
|
||||
register ptr_t *p = NULL;
|
||||
register unsigned long i;
|
||||
|
||||
unsigned long i;
|
||||
|
||||
for (i = 0; i < memrec.Count; i++)
|
||||
if (memrec.Ptrs[i] == oldp)
|
||||
for (i = 0; i < memrec.cnt; i++) {
|
||||
if (memrec.ptrs[i].ptr == oldp) {
|
||||
p = memrec.ptrs + i;
|
||||
break;
|
||||
if (i == memrec.Count && memrec.Ptrs[i] != oldp) {
|
||||
D_MALLOC(("ERROR: File %s, line %d attempted to realloc a pointer not allocated with Malloc/Realloc: %8p\n", filename, line, oldp));
|
||||
}
|
||||
}
|
||||
if (i == memrec.cnt) {
|
||||
D_MEM(("ERROR: File %s, line %d attempted to realloc variable %s (%8p) which was not allocated with MALLOC/REALLOC\n", filename, line, var, oldp));
|
||||
return;
|
||||
}
|
||||
D_MALLOC(("Changing variable of %lu bytes at %8p to one of %lu bytes at %8p\n", memrec.Size[i], memrec.Ptrs[i], size, newp));
|
||||
memrec.Ptrs[i] = newp;
|
||||
memrec.Size[i] = size;
|
||||
D_MEM(("Changing variable of %lu bytes at %8p to one of %lu bytes at %8p\n", p->size, p->ptr, size, newp));
|
||||
p->ptr = newp;
|
||||
p->size = size;
|
||||
}
|
||||
|
||||
void
|
||||
memrec_dump(void)
|
||||
{
|
||||
|
||||
register ptr_t *p;
|
||||
unsigned long i, j, k, l, total = 0;
|
||||
unsigned long len1, len2;
|
||||
unsigned char *ptr;
|
||||
unsigned long len;
|
||||
unsigned char buff[9];
|
||||
|
||||
fprintf(stderr, "DUMP :: %lu pointers stored.\n", memrec.Count);
|
||||
fprintf(stderr, "DUMP :: Pointer | Address | Size | Offset | 00 01 02 03 04 05 06 07 | ASCII \n");
|
||||
fflush(stderr);
|
||||
fprintf(stderr, "DUMP :: ---------+----------+--------+---------+-------------------------+---------\n");
|
||||
fflush(stderr);
|
||||
len1 = sizeof(void *) * memrec.Count;
|
||||
fprintf(LIBMEJ_DEBUG_FD, "DUMP :: %lu pointers stored.\n", memrec.cnt);
|
||||
fprintf(LIBMEJ_DEBUG_FD, "DUMP :: Pointer | Address | Size | Offset | 00 01 02 03 04 05 06 07 | ASCII \n");
|
||||
fprintf(LIBMEJ_DEBUG_FD, "DUMP :: ---------+----------+--------+---------+-------------------------+---------\n");
|
||||
fflush(LIBMEJ_DEBUG_FD);
|
||||
len = sizeof(ptr_t) * memrec.cnt;
|
||||
memset(buff, 0, sizeof(buff));
|
||||
|
||||
len2 = sizeof(size_t) * memrec.Count;
|
||||
for (ptr = (unsigned char *) memrec.Ptrs, j = 0; j < len1; j += 8) {
|
||||
fprintf(stderr, "DUMP :: %07lu | %8p | %06lu | %07x | ", (unsigned long) 0, memrec.Ptrs, (unsigned long) (sizeof(void *) * memrec.Count), (unsigned int) j);
|
||||
/* First, dump the contents of the memrec.ptrs[] array. */
|
||||
for (p = memrec.ptrs, j = 0; j < len; p++, j += 8) {
|
||||
fprintf(LIBMEJ_DEBUG_FD, "DUMP :: %07lu | %8p | %06lu | %07x | ", (unsigned long) 0, memrec.ptrs, (unsigned long) (sizeof(ptr_t) * memrec.cnt), (unsigned int) j);
|
||||
/* l is the number of characters we're going to output */
|
||||
l = ((len - j < 8) ? (len - j) : (8));
|
||||
/* Copy l bytes (up to 8) from memrec.ptrs[] (p) to buffer */
|
||||
memcpy(buff, p + j, l);
|
||||
for (k = 0; k < l; k++) {
|
||||
fprintf(LIBMEJ_DEBUG_FD, "%02x ", buff[k]);
|
||||
}
|
||||
/* If we printed less than 8 bytes worth, pad with 3 spaces per byte */
|
||||
for (; k < 8; k++) {
|
||||
fprintf(LIBMEJ_DEBUG_FD, " ");
|
||||
}
|
||||
/* Finally, print the printable ASCII string for those l bytes */
|
||||
fprintf(LIBMEJ_DEBUG_FD, "| %-8s\n", safe_str((char *) buff, l));
|
||||
/* Flush after every line in case we crash */
|
||||
fflush(LIBMEJ_DEBUG_FD);
|
||||
}
|
||||
|
||||
l = ((len1 - j < 8) ? (len1 - j) : (8));
|
||||
memset(buff, 0, 9);
|
||||
memcpy(buff, ptr + j, l);
|
||||
/* Now print out each pointer and its contents. */
|
||||
for (p = memrec.ptrs, i = 0; i < memrec.cnt; p++, i++) {
|
||||
/* Add this pointer's size to our total */
|
||||
total += p->size;
|
||||
for (j = 0; j < p->size; j += 8) {
|
||||
fprintf(LIBMEJ_DEBUG_FD, "DUMP :: %07lu | %8p | %06lu | %07x | ", i + 1, p->ptr, (unsigned long) p->size, (unsigned int) j);
|
||||
/* l is the number of characters we're going to output */
|
||||
l = ((p->size - j < 8) ? (p->size - j) : (8));
|
||||
/* Copy l bytes (up to 8) from p->ptr to buffer */
|
||||
memcpy(buff, p->ptr + j, l);
|
||||
for (k = 0; k < l; k++) {
|
||||
fprintf(stderr, "%02x ", buff[k]);
|
||||
fprintf(LIBMEJ_DEBUG_FD, "%02x ", buff[k]);
|
||||
}
|
||||
/* If we printed less than 8 bytes worth, pad with 3 spaces per byte */
|
||||
for (; k < 8; k++) {
|
||||
fprintf(stderr, " ");
|
||||
fprintf(LIBMEJ_DEBUG_FD, " ");
|
||||
}
|
||||
fprintf(stderr, "| %-8s\n", SafeStr((char *) buff, l));
|
||||
fflush(stderr);
|
||||
}
|
||||
for (ptr = (unsigned char *) memrec.Size, j = 0; j < len2; j += 8) {
|
||||
fprintf(stderr, "DUMP :: %07lu | %8p | %06lu | %07x | ", (unsigned long) 0, memrec.Size, sizeof(size_t) * memrec.Count, (unsigned int) j);
|
||||
l = ((len2 - j < 8) ? (len2 - j) : (8));
|
||||
memset(buff, 0, 9);
|
||||
memcpy(buff, ptr + j, l);
|
||||
for (k = 0; k < l; k++) {
|
||||
fprintf(stderr, "%02x ", buff[k]);
|
||||
}
|
||||
for (; k < 8; k++) {
|
||||
fprintf(stderr, " ");
|
||||
}
|
||||
fprintf(stderr, "| %-8s\n", SafeStr((char *) buff, l));
|
||||
fflush(stderr);
|
||||
}
|
||||
for (i = 0; i < memrec.Count; i++) {
|
||||
total += memrec.Size[i];
|
||||
for (ptr = (unsigned char *) memrec.Ptrs[i], j = 0; j < memrec.Size[i]; j += 8) {
|
||||
fprintf(stderr, "DUMP :: %07lu | %8p | %06lu | %07x | ", i + 1, memrec.Ptrs[i], (unsigned long) memrec.Size[i], (unsigned int) j);
|
||||
l = ((memrec.Size[i] - j < 8) ? (memrec.Size[i] - j) : (8));
|
||||
memset(buff, 0, 9);
|
||||
memcpy(buff, ptr + j, l);
|
||||
for (k = 0; k < l; k++) {
|
||||
fprintf(stderr, "%02x ", buff[k]);
|
||||
}
|
||||
for (; k < 8; k++) {
|
||||
fprintf(stderr, " ");
|
||||
}
|
||||
fprintf(stderr, "| %-8s\n", SafeStr((char *) buff, l));
|
||||
fflush(stderr);
|
||||
/* Finally, print the printable ASCII string for those l bytes */
|
||||
fprintf(LIBMEJ_DEBUG_FD, "| %-8s\n", safe_str((char *) buff, l));
|
||||
/* Flush after every line in case we crash */
|
||||
fflush(LIBMEJ_DEBUG_FD);
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "DUMP :: Total allocated memory: %10lu bytes\n\n", total);
|
||||
fflush(stderr);
|
||||
fprintf(LIBMEJ_DEBUG_FD, "DUMP :: Total allocated memory: %10lu bytes\n\n", total);
|
||||
fflush(LIBMEJ_DEBUG_FD);
|
||||
}
|
||||
|
||||
/************* Function prototypes ****************/
|
||||
|
||||
void *
|
||||
Malloc(const char *filename, unsigned long line, size_t size)
|
||||
libmej_malloc(const char *filename, unsigned long line, size_t size)
|
||||
{
|
||||
|
||||
void *temp;
|
||||
|
||||
#ifdef MALLOC_CALL_DEBUG
|
||||
++malloc_count;
|
||||
if (!(malloc_count % MALLOC_MOD)) {
|
||||
fprintf(stderr, "Calls to malloc(): %d\n", malloc_count);
|
||||
fprintf(LIBMEJ_DEBUG_FD, "Calls to malloc(): %d\n", malloc_count);
|
||||
}
|
||||
#endif
|
||||
|
||||
D_MALLOC(("Malloc(%lu) called at %s:%lu\n", size, filename, line));
|
||||
if (!memrec.init) {
|
||||
D_MALLOC(("WARNING: You must call memrec_init() before using the libmej memory management calls.\n"));
|
||||
memrec_init();
|
||||
}
|
||||
D_MEM(("libmej_malloc(%lu) called at %s:%lu\n", size, filename, line));
|
||||
|
||||
temp = (void *) malloc(size);
|
||||
if (!temp)
|
||||
return NULL;
|
||||
if (debug_level >= DEBUG_MALLOC) {
|
||||
ASSERT_RVAL(temp != NULL, NULL);
|
||||
if (DEBUG_LEVEL >= DEBUG_MEM) {
|
||||
memrec_add_var(temp, size);
|
||||
}
|
||||
return (temp);
|
||||
}
|
||||
|
||||
void *
|
||||
Realloc(const char *var, const char *filename, unsigned long line, void *ptr, size_t size)
|
||||
libmej_realloc(const char *var, const char *filename, unsigned long line, void *ptr, size_t size)
|
||||
{
|
||||
|
||||
void *temp;
|
||||
|
||||
#ifdef MALLOC_CALL_DEBUG
|
||||
++realloc_count;
|
||||
if (!(realloc_count % REALLOC_MOD)) {
|
||||
fprintf(stderr, "Calls to realloc(): %d\n", realloc_count);
|
||||
D_MEM(("Calls to realloc(): %d\n", realloc_count));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!memrec.init) {
|
||||
D_MALLOC(("WARNING: You must call memrec_init() before using the libmej memory management calls.\n"));
|
||||
memrec_init();
|
||||
}
|
||||
|
||||
D_MALLOC(("Realloc(%lu) called for variable %s (%8p) at %s:%lu\n", size, var, ptr, filename, line));
|
||||
D_MEM(("libmej_realloc(%lu) called for variable %s (%8p) at %s:%lu\n", size, var, ptr, filename, line));
|
||||
if (ptr == NULL) {
|
||||
temp = (void *) Malloc(__FILE__, __LINE__, size);
|
||||
temp = (void *) libmej_malloc(__FILE__, __LINE__, size);
|
||||
} else {
|
||||
temp = (void *) realloc(ptr, size);
|
||||
if (debug_level >= DEBUG_MALLOC) {
|
||||
memrec_chg_var(filename, line, ptr, temp, size);
|
||||
ASSERT_RVAL(temp != NULL, ptr);
|
||||
if (DEBUG_LEVEL >= DEBUG_MEM) {
|
||||
memrec_chg_var(var, filename, line, ptr, temp, size);
|
||||
}
|
||||
}
|
||||
return (temp);
|
||||
}
|
||||
|
||||
void *
|
||||
Calloc(const char *filename, unsigned long line, size_t count, size_t size)
|
||||
libmej_calloc(const char *filename, unsigned long line, size_t count, size_t size)
|
||||
{
|
||||
|
||||
char *temp;
|
||||
void *temp;
|
||||
|
||||
#ifdef MALLOC_CALL_DEBUG
|
||||
++calloc_count;
|
||||
if (!(calloc_count % CALLOC_MOD)) {
|
||||
fprintf(stderr, "Calls to calloc(): %d\n", calloc_count);
|
||||
fprintf(LIBMEJ_DEBUG_FD, "Calls to calloc(): %d\n", calloc_count);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!memrec.init) {
|
||||
D_MALLOC(("WARNING: You must call memrec_init() before using the libmej memory management calls.\n"));
|
||||
memrec_init();
|
||||
}
|
||||
|
||||
D_MALLOC(("Calloc(%lu, %lu) called at %s:%lu\n", count, size, filename, line));
|
||||
temp = (char *) calloc(count, size);
|
||||
if (debug_level >= DEBUG_MALLOC) {
|
||||
D_MEM(("libmej_calloc(%lu, %lu) called at %s:%lu\n", count, size, filename, line));
|
||||
temp = (void *) calloc(count, size);
|
||||
ASSERT_RVAL(temp != NULL, NULL);
|
||||
if (DEBUG_LEVEL >= DEBUG_MEM) {
|
||||
memrec_add_var(temp, size * count);
|
||||
}
|
||||
return (temp);
|
||||
}
|
||||
|
||||
void
|
||||
Free(const char *var, const char *filename, unsigned long line, void *ptr)
|
||||
libmej_free(const char *var, const char *filename, unsigned long line, void *ptr)
|
||||
{
|
||||
|
||||
#ifdef MALLOC_CALL_DEBUG
|
||||
++free_count;
|
||||
if (!(free_count % FREE_MOD)) {
|
||||
fprintf(stderr, "Calls to free(): %d\n", free_count);
|
||||
fprintf(LIBMEJ_DEBUG_FD, "Calls to free(): %d\n", free_count);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!memrec.init) {
|
||||
D_MALLOC(("WARNING: You must call memrec_init() before using the libmej memory management calls.\n"));
|
||||
memrec_init();
|
||||
}
|
||||
|
||||
D_MALLOC(("Free() called for variable %s (%8p) at %s:%lu\n", var, ptr, filename, line));
|
||||
D_MEM(("libmej_free() called for variable %s (%8p) at %s:%lu\n", var, ptr, filename, line));
|
||||
if (ptr) {
|
||||
if (debug_level >= DEBUG_MALLOC) {
|
||||
memrec_rem_var(filename, line, ptr);
|
||||
if (DEBUG_LEVEL >= DEBUG_MEM) {
|
||||
memrec_rem_var(var, filename, line, ptr);
|
||||
}
|
||||
free(ptr);
|
||||
} else {
|
||||
D_MALLOC(("ERROR: Caught attempt to free NULL pointer\n"));
|
||||
D_MEM(("ERROR: Caught attempt to free NULL pointer\n"));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HandleSigSegv(int sig)
|
||||
char *
|
||||
libmej_strdup(const char *var, const char *filename, unsigned long line, const char *str)
|
||||
{
|
||||
register char *newstr;
|
||||
register size_t len;
|
||||
|
||||
#if DEBUG >= DEBUG_MALLOC
|
||||
fprintf(stderr, "Fatal memory fault (%d)! Dumping memory table.\n", sig);
|
||||
D_MEM(("libmej_strdup() called for variable %s (%8p) at %s:%lu\n", var, str, filename, line));
|
||||
|
||||
len = strlen(str) + 1; /* Copy NUL byte also */
|
||||
newstr = (char *) libmej_malloc(filename, line, len);
|
||||
strcpy(newstr, str);
|
||||
return (newstr);
|
||||
}
|
||||
|
||||
void
|
||||
libmej_handle_sigsegv(int sig)
|
||||
{
|
||||
#if DEBUG >= DEBUG_MEM
|
||||
fprintf(LIBMEJ_DEBUG_FD, "Fatal memory fault (%d)! Dumping memory table.\n", sig);
|
||||
memrec_dump();
|
||||
#endif
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
73
libmej/mem.h
73
libmej/mem.h
|
@ -1,73 +0,0 @@
|
|||
/***************************************************************
|
||||
* MEM.H -- Header file for mem.c *
|
||||
* -- Michael Jennings *
|
||||
* -- 07 January 1997 *
|
||||
***************************************************************/
|
||||
/*
|
||||
* 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 _MEM_H_
|
||||
|
||||
#define _MEM_H_
|
||||
|
||||
typedef struct memrec_struct {
|
||||
unsigned char init;
|
||||
unsigned long Count, TotalSize;
|
||||
void **Ptrs;
|
||||
size_t *Size;
|
||||
} MemRec;
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
# include <dmalloc.h>
|
||||
#endif
|
||||
#if (DEBUG >= DEBUG_MALLOC)
|
||||
# define MALLOC(sz) Malloc(__FILE__, __LINE__, (sz))
|
||||
# define CALLOC(type,n) Calloc(__FILE__, __LINE__, (n),(sizeof(type)))
|
||||
# define REALLOC(mem,sz) Realloc(#mem, __FILE__, __LINE__, (mem),(sz))
|
||||
# define FREE(ptr) do { Free(#ptr, __FILE__, __LINE__, (ptr)); (ptr) = NULL; } while (0)
|
||||
# define MALLOC_MOD 25
|
||||
# define REALLOC_MOD 25
|
||||
# define CALLOC_MOD 25
|
||||
# define FREE_MOD 25
|
||||
#else
|
||||
# define MALLOC(sz) malloc(sz)
|
||||
# define CALLOC(type,n) calloc((n),(sizeof(type)))
|
||||
# define REALLOC(mem,sz) ((sz) ? ((mem) ? (realloc((mem), (sz))) : (malloc(sz))) : ((mem) ? (free(mem), NULL) : (NULL)))
|
||||
# define FREE(ptr) do { free(ptr); (ptr) = NULL; } while (0)
|
||||
#endif
|
||||
|
||||
extern char *SafeStr(char *, unsigned short);
|
||||
extern MemRec memrec;
|
||||
extern void memrec_init(void);
|
||||
extern void memrec_add_var(void *, size_t);
|
||||
extern void memrec_rem_var(const char *, unsigned long, void *);
|
||||
extern void memrec_chg_var(const char *, unsigned long, void *, void *, size_t);
|
||||
extern void memrec_dump(void);
|
||||
extern void *Malloc(const char *, unsigned long, size_t);
|
||||
extern void *Realloc(const char *, const char *, unsigned long, void *, size_t);
|
||||
extern void *Calloc(const char *, unsigned long, size_t, size_t);
|
||||
extern void Free(const char *, const char *, unsigned long, void *);
|
||||
extern void HandleSigSegv(int);
|
||||
|
||||
#endif /* _MEM_H_ */
|
||||
|
|
@ -1,8 +1,3 @@
|
|||
/***************************************************************
|
||||
* GLOBAL.H -- Compile-time options header file *
|
||||
* -- Michael Jennings *
|
||||
* -- 16 January 1997 *
|
||||
***************************************************************/
|
||||
/*
|
||||
* Copyright (C) 1997-2000, Michael Jennings
|
||||
*
|
||||
|
@ -26,21 +21,61 @@
|
|||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _GLOBAL_H_
|
||||
|
||||
#define _GLOBAL_H_
|
||||
|
||||
/* Other compile-time defines */
|
||||
#ifdef LINUX
|
||||
# define _GNU_SOURCE
|
||||
# define __USE_GNU
|
||||
# define _BSD_SOURCE
|
||||
#elif defined(IRIX)
|
||||
# define _MODERN_C_
|
||||
# define _BSD_TYPES
|
||||
# define _SGI_SOURCE
|
||||
#elif defined(HP_UX)
|
||||
static const char cvs_ident[] = "$Id$";
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#endif /* _GLOBAL_H_ */
|
||||
#include "libmej.h"
|
||||
|
||||
int
|
||||
libmej_dprintf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int n;
|
||||
|
||||
va_start(args, format);
|
||||
n = vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
fflush(stderr);
|
||||
return (n);
|
||||
}
|
||||
|
||||
/* Print a non-terminal error message */
|
||||
void
|
||||
print_error(const char *fmt, ...)
|
||||
{
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, fmt);
|
||||
fprintf(stderr, PACKAGE ": Error: ");
|
||||
vfprintf(stderr, fmt, arg_ptr);
|
||||
va_end(arg_ptr);
|
||||
}
|
||||
|
||||
/* Print a simple warning */
|
||||
void
|
||||
print_warning(const char *fmt, ...)
|
||||
{
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, fmt);
|
||||
fprintf(stderr, PACKAGE ": Warning: ");
|
||||
vfprintf(stderr, fmt, arg_ptr);
|
||||
va_end(arg_ptr);
|
||||
}
|
||||
|
||||
/* Print a fatal error message and terminate */
|
||||
void
|
||||
fatal_error(const char *fmt, ...)
|
||||
{
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, fmt);
|
||||
fprintf(stderr, PACKAGE ": FATAL: ");
|
||||
vfprintf(stderr, fmt, arg_ptr);
|
||||
va_end(arg_ptr);
|
||||
exit(-1);
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
#include "config.h"
|
||||
#include "../src/feature.h"
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "global.h"
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_STDARG_H
|
||||
# include <stdarg.h>
|
||||
#endif
|
||||
|
||||
static const char cvs_ident[] = "$Id$";
|
||||
|
||||
|
@ -18,10 +21,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
|
||||
#if !defined(HAVE_SNPRINTF) || (HAVE_SNPRINTF_BUG == 1)
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
#define VA_LOCAL_DECL va_list ap
|
||||
#define VA_START(f) va_start(ap, f)
|
||||
#define VA_SHIFT(v,t) ; /* no-op for ANSI */
|
||||
|
@ -452,7 +451,7 @@ dopr_outch(int c)
|
|||
* Copyright Holder, but only to the computing community at large
|
||||
* as a market that must bear the fee.)
|
||||
*
|
||||
* "Freely Available" means that no fee is charged for the item
|
||||
* "libmej_freely Available" means that no fee is charged for the item
|
||||
* itself, though there may be fees involved in handling the item.
|
||||
* It also means that recipients of the item may redistribute it
|
||||
* under the same conditions they received it.
|
||||
|
@ -471,7 +470,7 @@ dopr_outch(int c)
|
|||
* following:
|
||||
*
|
||||
* a) place your modifications in the Public Domain or otherwise make them
|
||||
* Freely Available, such as by posting said modifications to Usenet or
|
||||
* libmej_freely Available, such as by posting said modifications to Usenet or
|
||||
* an equivalent medium, or placing the modifications on a major archive
|
||||
* site such as uunet.uu.net, or by allowing the Copyright Holder to include
|
||||
* your modifications in the Standard Version of the Package.
|
||||
|
|
183
libmej/strings.c
183
libmej/strings.c
|
@ -1,8 +1,3 @@
|
|||
/***************************************************************
|
||||
* STRINGS.C -- String manipulation routines *
|
||||
* -- Michael Jennings *
|
||||
* -- 08 January 1997 *
|
||||
***************************************************************/
|
||||
/*
|
||||
* Copyright (C) 1997-2000, Michael Jennings
|
||||
*
|
||||
|
@ -28,22 +23,11 @@
|
|||
|
||||
static const char cvs_ident[] = "$Id$";
|
||||
|
||||
#include "config.h"
|
||||
#include "../src/feature.h"
|
||||
|
||||
#include "global.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#ifndef WITH_DMALLOC
|
||||
# include <malloc.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
#include "debug.h"
|
||||
#include "mem.h"
|
||||
#include "strings.h"
|
||||
|
||||
#include <libmej.h>
|
||||
|
||||
#ifndef HAVE_MEMMEM
|
||||
/* Find first occurance of bytestring needle of size needlelen in memory region
|
||||
|
@ -51,7 +35,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
void *
|
||||
memmem(void *haystack, register size_t haystacklen, void *needle, register size_t needlelen)
|
||||
{
|
||||
|
||||
register char *hs = (char *) haystack;
|
||||
register char *n = (char *) needle;
|
||||
register unsigned long i;
|
||||
|
@ -70,7 +53,6 @@ memmem(void *haystack, register size_t haystacklen, void *needle, register size_
|
|||
void
|
||||
usleep(unsigned long usec)
|
||||
{
|
||||
|
||||
struct timeval delay;
|
||||
|
||||
delay.tv_sec = 0;
|
||||
|
@ -92,9 +74,8 @@ nanosleep(unsigned long nsec) {
|
|||
|
||||
/* Return the leftmost cnt characters of str */
|
||||
char *
|
||||
LeftStr(const char *str, unsigned long cnt)
|
||||
left_str(const char *str, unsigned long cnt)
|
||||
{
|
||||
|
||||
char *tmpstr;
|
||||
|
||||
tmpstr = (char *) MALLOC(cnt + 1);
|
||||
|
@ -105,9 +86,8 @@ LeftStr(const char *str, unsigned long cnt)
|
|||
|
||||
/* Return cnt characters from str, starting at position index (from 0) */
|
||||
char *
|
||||
MidStr(const char *str, unsigned long index, unsigned long cnt)
|
||||
mid_str(const char *str, unsigned long index, unsigned long cnt)
|
||||
{
|
||||
|
||||
char *tmpstr;
|
||||
const char *pstr = str;
|
||||
|
||||
|
@ -120,9 +100,8 @@ MidStr(const char *str, unsigned long index, unsigned long cnt)
|
|||
|
||||
/* Return the rightmost characters of str */
|
||||
char *
|
||||
RightStr(const char *str, unsigned long cnt)
|
||||
right_str(const char *str, unsigned long cnt)
|
||||
{
|
||||
|
||||
char *tmpstr;
|
||||
const char *pstr = str;
|
||||
|
||||
|
@ -136,37 +115,21 @@ RightStr(const char *str, unsigned long cnt)
|
|||
/* Returns TRUE if str matches regular expression pattern, FALSE otherwise */
|
||||
#if defined(HAVE_REGEX_H) || defined(IRIX)
|
||||
unsigned char
|
||||
Match(register const char *str, register const char *pattern)
|
||||
regexp_match(register const char *str, register const char *pattern)
|
||||
{
|
||||
|
||||
register regex_t *rexp;
|
||||
register int result;
|
||||
|
||||
#ifndef IRIX
|
||||
char errbuf[256];
|
||||
|
||||
rexp = (regex_t *) MALLOC(sizeof(regex_t));
|
||||
#endif
|
||||
|
||||
#ifdef IRIX
|
||||
if ((rexp = compile((const char *) pattern, (char *) NULL, (char *) NULL)) == NULL) {
|
||||
fprintf(stderr, "Unable to compile regexp %s\n", pattern);
|
||||
return (FALSE);
|
||||
}
|
||||
#else
|
||||
if ((result = regcomp(rexp, pattern, REG_EXTENDED)) != 0) {
|
||||
regerror(result, rexp, errbuf, 256);
|
||||
fprintf(stderr, "Unable to compile regexp %s -- %s.\n", pattern, errbuf);
|
||||
FREE(rexp);
|
||||
return (FALSE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef IRIX
|
||||
result = step((const char *) str, rexp);
|
||||
FREE(rexp);
|
||||
return (result);
|
||||
#else
|
||||
if (((result = regexec(rexp, str, (size_t) 0, (regmatch_t *) NULL, 0))
|
||||
!= 0) && (result != REG_NOMATCH)) {
|
||||
regerror(result, rexp, errbuf, 256);
|
||||
|
@ -176,22 +139,22 @@ Match(register const char *str, register const char *pattern)
|
|||
}
|
||||
FREE(rexp);
|
||||
return (!result);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return malloc'd pointer to index-th word in str. "..." counts as 1 word. */
|
||||
char *
|
||||
Word(unsigned long index, const char *str)
|
||||
{
|
||||
#define IS_DELIM(c) (delim ? ((c) == delim) : (isspace(c)))
|
||||
|
||||
char *
|
||||
get_word(unsigned long index, const char *str)
|
||||
{
|
||||
char *tmpstr;
|
||||
char *delim = DEFAULT_DELIM;
|
||||
char delim = 0;
|
||||
register unsigned long i, j, k;
|
||||
|
||||
k = strlen(str) + 1;
|
||||
if ((tmpstr = (char *) MALLOC(k)) == NULL) {
|
||||
fprintf(stderr, "Word(%lu, %s): Unable to allocate memory -- %s.\n",
|
||||
fprintf(stderr, "get_word(%lu, %s): Unable to allocate memory -- %s.\n",
|
||||
index, str, strerror(errno));
|
||||
return ((char *) NULL);
|
||||
}
|
||||
|
@ -200,17 +163,17 @@ Word(unsigned long index, const char *str)
|
|||
for (; isspace(str[i]); i++);
|
||||
switch (str[i]) {
|
||||
case '\"':
|
||||
delim = "\"";
|
||||
delim = '\"';
|
||||
i++;
|
||||
break;
|
||||
case '\'':
|
||||
delim = "\'";
|
||||
delim = '\'';
|
||||
i++;
|
||||
break;
|
||||
default:
|
||||
delim = DEFAULT_DELIM;
|
||||
delim = 0;
|
||||
}
|
||||
for (k = 0; str[i] && !strchr(delim, str[i]);) {
|
||||
for (k = 0; str[i] && !IS_DELIM(str[i]);) {
|
||||
if (str[i] == '\\') {
|
||||
if (str[i + 1] == '\'' || str[i + 1] == '\"') {
|
||||
i++;
|
||||
|
@ -229,20 +192,19 @@ Word(unsigned long index, const char *str)
|
|||
|
||||
if (j != index) {
|
||||
FREE(tmpstr);
|
||||
D_STRINGS(("Word(%lu, %s) returning NULL.\n", index, str));
|
||||
D_STRINGS(("get_word(%lu, %s) returning NULL.\n", index, str));
|
||||
return ((char *) NULL);
|
||||
} else {
|
||||
tmpstr = (char *) REALLOC(tmpstr, strlen(tmpstr) + 1);
|
||||
D_STRINGS(("Word(%lu, %s) returning \"%s\".\n", index, str, tmpstr));
|
||||
D_STRINGS(("get_word(%lu, %s) returning \"%s\".\n", index, str, tmpstr));
|
||||
return (tmpstr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return pointer into str to index-th word in str. "..." counts as 1 word. */
|
||||
char *
|
||||
PWord(unsigned long index, const char *str)
|
||||
get_pword(unsigned long index, const char *str)
|
||||
{
|
||||
|
||||
register const char *tmpstr = str;
|
||||
register unsigned long j;
|
||||
|
||||
|
@ -258,38 +220,37 @@ PWord(unsigned long index, const char *str)
|
|||
tmpstr++;
|
||||
}
|
||||
if (*tmpstr == '\0') {
|
||||
D_STRINGS(("PWord(%lu, %s) returning NULL.\n", index, str));
|
||||
D_STRINGS(("get_pword(%lu, %s) returning NULL.\n", index, str));
|
||||
return ((char *) NULL);
|
||||
} else {
|
||||
D_STRINGS(("PWord(%lu, %s) returning \"%s\"\n", index, str, tmpstr));
|
||||
D_STRINGS(("get_pword(%lu, %s) returning \"%s\"\n", index, str, tmpstr));
|
||||
return (char *) tmpstr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns the number of words in str, for use with Word() and PWord(). "..." counts as 1 word. */
|
||||
/* Returns the number of words in str, for use with get_word() and get_pword(). "..." counts as 1 word. */
|
||||
unsigned long
|
||||
NumWords(const char *str)
|
||||
num_words(const char *str)
|
||||
{
|
||||
|
||||
register unsigned long cnt = 0;
|
||||
char *delim = DEFAULT_DELIM;
|
||||
char delim = 0;
|
||||
register unsigned long i;
|
||||
|
||||
for (i = 0; str[i] && strchr(delim, str[i]); i++);
|
||||
for (i = 0; str[i] && IS_DELIM(str[i]); i++);
|
||||
for (; str[i]; cnt++) {
|
||||
switch (str[i]) {
|
||||
case '\"':
|
||||
delim = "\"";
|
||||
delim = '\"';
|
||||
i++;
|
||||
break;
|
||||
case '\'':
|
||||
delim = "\'";
|
||||
delim = '\'';
|
||||
i++;
|
||||
break;
|
||||
default:
|
||||
delim = DEFAULT_DELIM;
|
||||
delim = 0;
|
||||
}
|
||||
for (; str[i] && !strchr(delim, str[i]); i++);
|
||||
for (; str[i] && !IS_DELIM(str[i]); i++);
|
||||
switch (str[i]) {
|
||||
case '\"':
|
||||
case '\'':
|
||||
|
@ -299,14 +260,13 @@ NumWords(const char *str)
|
|||
for (; str[i] && isspace(str[i]); i++);
|
||||
}
|
||||
|
||||
D_STRINGS(("NumWords() returning %lu\n", cnt));
|
||||
D_STRINGS(("num_words() returning %lu\n", cnt));
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
char *
|
||||
StripWhitespace(register char *str)
|
||||
strip_whitespace(register char *str)
|
||||
{
|
||||
|
||||
register unsigned long i, j;
|
||||
|
||||
if ((j = strlen(str))) {
|
||||
|
@ -320,35 +280,33 @@ StripWhitespace(register char *str)
|
|||
}
|
||||
|
||||
char *
|
||||
LowerStr(char *str)
|
||||
downcase_str(char *str)
|
||||
{
|
||||
|
||||
register char *tmp;
|
||||
|
||||
for (tmp = str; *tmp; tmp++) {
|
||||
*tmp = tolower(*tmp);
|
||||
}
|
||||
D_STRINGS(("LowerStr() returning %s\n", str));
|
||||
D_STRINGS(("downcase_str() returning %s\n", str));
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *
|
||||
UpStr(char *str)
|
||||
upcase_str(char *str)
|
||||
{
|
||||
|
||||
register char *tmp;
|
||||
|
||||
for (tmp = str; *tmp; tmp++) {
|
||||
*tmp = toupper(*tmp);
|
||||
}
|
||||
D_STRINGS(("UpStr() returning %s\n", str));
|
||||
D_STRINGS(("upcase_str() returning %s\n", str));
|
||||
return (str);
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRCASESTR
|
||||
char *
|
||||
StrCaseStr(char *haystack, register const char *needle)
|
||||
strcasestr(char *haystack, register const char *needle)
|
||||
{
|
||||
|
||||
register char *t;
|
||||
register size_t len = strlen(needle);
|
||||
|
||||
|
@ -359,11 +317,12 @@ StrCaseStr(char *haystack, register const char *needle)
|
|||
}
|
||||
return (NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCASECHR
|
||||
char *
|
||||
StrCaseChr(char *haystack, register char needle)
|
||||
strcasechr(char *haystack, register char needle)
|
||||
{
|
||||
|
||||
register char *t;
|
||||
|
||||
for (t = haystack; t && *t; t++) {
|
||||
|
@ -373,47 +332,37 @@ StrCaseChr(char *haystack, register char needle)
|
|||
}
|
||||
return (NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCASEPBRK
|
||||
char *
|
||||
StrCasePBrk(char *haystack, register char *needle)
|
||||
strcasepbrk(char *haystack, register char *needle)
|
||||
{
|
||||
|
||||
register char *t;
|
||||
|
||||
for (t = haystack; t && *t; t++) {
|
||||
if (StrCaseChr(needle, *t)) {
|
||||
if (strcasechr(needle, *t)) {
|
||||
return (t);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRREV
|
||||
char *
|
||||
StrRev(register char *str)
|
||||
strrev(register char *str)
|
||||
{
|
||||
|
||||
register int i, j;
|
||||
|
||||
i = strlen(str);
|
||||
for (j = 0, i--; i > j; i--, j++) {
|
||||
cswap(str[j], str[i]);
|
||||
SWAP(str[j], str[i]);
|
||||
}
|
||||
return (str);
|
||||
|
||||
}
|
||||
|
||||
char *
|
||||
StrDup(register const char *str)
|
||||
{
|
||||
|
||||
register char *newstr;
|
||||
register unsigned long len;
|
||||
|
||||
len = strlen(str) + 1; /* Copy NUL byte also */
|
||||
newstr = (char *) MALLOC(len);
|
||||
strcpy(newstr, str);
|
||||
return (newstr);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(HAVE_STRSEP)
|
||||
char *
|
||||
|
@ -444,7 +393,7 @@ strsep(char **str, register char *sep)
|
|||
#endif
|
||||
|
||||
char *
|
||||
GarbageCollect(char *buff, size_t len)
|
||||
garbage_collect(char *buff, size_t len)
|
||||
{
|
||||
|
||||
register char *tbuff = buff, *pbuff = buff;
|
||||
|
@ -460,7 +409,7 @@ GarbageCollect(char *buff, size_t len)
|
|||
}
|
||||
|
||||
char *
|
||||
FGarbageCollect(char *buff, size_t len)
|
||||
file_garbage_collect(char *buff, size_t len)
|
||||
{
|
||||
|
||||
register char *tbuff = buff, *pbuff = buff;
|
||||
|
@ -529,17 +478,17 @@ FGarbageCollect(char *buff, size_t len)
|
|||
|
||||
/* And the final step, garbage collect the buffer to condense all
|
||||
those nulls we just put in. */
|
||||
return (GarbageCollect(buff, len));
|
||||
return (garbage_collect(buff, len));
|
||||
}
|
||||
|
||||
char *
|
||||
CondenseWhitespace(char *s)
|
||||
condense_whitespace(char *s)
|
||||
{
|
||||
|
||||
register unsigned char gotspc = 0;
|
||||
register char *pbuff = s, *pbuff2 = s;
|
||||
|
||||
D_STRINGS(("CondenseWhitespace(%s) called.\n", s));
|
||||
D_STRINGS(("condense_whitespace(%s) called.\n", s));
|
||||
for (; *pbuff2; pbuff2++) {
|
||||
if (isspace(*pbuff2)) {
|
||||
if (!gotspc) {
|
||||
|
@ -556,12 +505,26 @@ CondenseWhitespace(char *s)
|
|||
if ((pbuff >= s) && (isspace(*(pbuff - 1))))
|
||||
pbuff--;
|
||||
*pbuff = 0;
|
||||
D_STRINGS(("CondenseWhitespace() returning \"%s\".\n", s));
|
||||
D_STRINGS(("condense_whitespace() returning \"%s\".\n", s));
|
||||
return (REALLOC(s, strlen(s) + 1));
|
||||
}
|
||||
|
||||
char *
|
||||
safe_str(register char *str, unsigned short len)
|
||||
{
|
||||
register unsigned short i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (iscntrl(str[i])) {
|
||||
str[i] = '.';
|
||||
}
|
||||
}
|
||||
|
||||
return (str);
|
||||
}
|
||||
|
||||
void
|
||||
HexDump(void *buff, register size_t count)
|
||||
hex_dump(void *buff, register size_t count)
|
||||
{
|
||||
|
||||
register unsigned long j, k, l;
|
||||
|
@ -581,6 +544,6 @@ HexDump(void *buff, register size_t count)
|
|||
for (; k < 8; k++) {
|
||||
fprintf(stderr, " ");
|
||||
}
|
||||
fprintf(stderr, "| %-8s\n", SafeStr((char *) buffr, l));
|
||||
fprintf(stderr, "| %-8s\n", safe_str((char *) buffr, l));
|
||||
}
|
||||
}
|
||||
|
|
115
libmej/strings.h
115
libmej/strings.h
|
@ -1,115 +0,0 @@
|
|||
/***************************************************************
|
||||
* STRINGS.H -- String manipulation routines *
|
||||
* -- Michael Jennings *
|
||||
* -- 08 January 1997 *
|
||||
***************************************************************/
|
||||
/*
|
||||
* 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 _STRINGS_H_
|
||||
|
||||
#define _STRINGS_H_
|
||||
|
||||
#include "global.h"
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE ((unsigned char)(1))
|
||||
# define FALSE ((unsigned char)(0))
|
||||
#endif
|
||||
|
||||
#ifndef swap
|
||||
# define swap(a, b) (((int)(b)) ^= ((int)(a)) ^= ((int)(b)) ^= ((int)(a)))
|
||||
#endif
|
||||
|
||||
#ifndef cswap
|
||||
# define cswap(a, b) ((b) ^= (a) ^= (b) ^= (a))
|
||||
#endif
|
||||
|
||||
#define DEFAULT_DELIM " \r\n\f\t\v"
|
||||
|
||||
#define CONST_STRLEN(x) (sizeof(x) - 1)
|
||||
#define BEG_STRCASECMP(s, constr) (strncasecmp(s, constr, CONST_STRLEN(constr)))
|
||||
|
||||
#ifdef IRIX
|
||||
# define regex_t char
|
||||
# define NBRA 9
|
||||
extern char *braslist[NBRA];
|
||||
extern char *braelist[NBRA];
|
||||
extern int nbra, regerrno, reglength;
|
||||
extern char *loc1, *loc2, *locs;
|
||||
|
||||
extern "C" int step(const char *, const char *);
|
||||
extern "C" int advance(const char *, char *);
|
||||
extern "C" char *compile(const char *, char *, char *);
|
||||
#elif defined(HAVE_REGEX_H)
|
||||
# include <regex.h>
|
||||
#endif
|
||||
|
||||
extern char *LeftStr(const char *, unsigned long);
|
||||
extern char *MidStr(const char *, unsigned long, unsigned long);
|
||||
extern char *RightStr(const char *, unsigned long);
|
||||
#if defined(HAVE_REGEX_H) || defined(IRIX)
|
||||
extern unsigned char Match(const char *, const char *);
|
||||
#endif
|
||||
extern char *Word(unsigned long, const char *);
|
||||
extern char *PWord(unsigned long, const char *);
|
||||
extern unsigned long NumWords(const char *);
|
||||
extern char *StripWhitespace(char *);
|
||||
extern char *LowerStr(char *);
|
||||
extern char *UpStr(char *);
|
||||
extern char *StrCaseStr(char *, const char *);
|
||||
extern char *StrCaseChr(char *, char);
|
||||
extern char *StrCasePBrk(char *, char *);
|
||||
extern char *StrRev(char *);
|
||||
extern char *StrDup(const char *);
|
||||
#if !(HAVE_STRSEP)
|
||||
extern char *strsep(char **, char *);
|
||||
#endif
|
||||
extern char *SafeStr(char *, unsigned short);
|
||||
extern char *GarbageCollect(char *, size_t);
|
||||
extern char *FGarbageCollect(char *, size_t);
|
||||
extern char *CondenseWhitespace(char *);
|
||||
extern void HexDump(void *, size_t);
|
||||
#ifndef HAVE_MEMMEM
|
||||
extern void *memmem(void *, size_t, void *, size_t);
|
||||
#endif
|
||||
#ifndef HAVE_USLEEP
|
||||
extern void usleep(unsigned long);
|
||||
#endif
|
||||
#ifndef HAVE_SNPRINTF
|
||||
# ifdef HAVE_STDARG_H
|
||||
# include <stdarg.h>
|
||||
# endif
|
||||
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
|
||||
extern int snprintf(char *str, size_t count, const char *fmt, ...);
|
||||
#endif
|
||||
/*
|
||||
#ifndef HAVE_NANOSLEEP
|
||||
extern void nanosleep(unsigned long);
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif /* _STRINGS_H_ */
|
|
@ -1,276 +0,0 @@
|
|||
|
||||
/***************************************************************
|
||||
* STRPTIME.C -- strptime() for IRIX *
|
||||
* -- Michael Jennings *
|
||||
* -- 2 April 1997 *
|
||||
***************************************************************/
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
static const char cvs_ident[] = "$Id$";
|
||||
|
||||
#ifdef IRIX
|
||||
|
||||
#include "config.h"
|
||||
#include "../src/feature.h"
|
||||
|
||||
#include "global.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include "strptime.h"
|
||||
|
||||
char *
|
||||
strptime(char *buf, const char *format, struct tm *tm)
|
||||
{
|
||||
|
||||
register char c;
|
||||
register const char *tmp;
|
||||
register int i, len;
|
||||
|
||||
for (tmp = format; *tmp;) {
|
||||
if (!(*buf))
|
||||
break;
|
||||
|
||||
if ((c = *tmp++) != '%') {
|
||||
if (!isspace(*buf) && c != *buf++)
|
||||
return ((char *) NULL);
|
||||
for (; *buf != 0 && isspace(*buf); buf++);
|
||||
continue;
|
||||
}
|
||||
switch ((c = *tmp++)) {
|
||||
case 0:
|
||||
case '%':
|
||||
if (*buf++ != '%')
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
buf = strptime(buf, USMap.LocaleDateFormat, tm);
|
||||
if (!buf)
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
buf = strptime(buf, "%x %X", tm);
|
||||
if (!buf)
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
buf = strptime(buf, "%m/%d/%y", tm);
|
||||
if (!buf)
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
buf = strptime(buf, "%H:%M", tm);
|
||||
if (!buf)
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
buf = strptime(buf, "%I:%M:%S %p", tm);
|
||||
if (!buf)
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
buf = strptime(buf, "%H:%M:%S", tm);
|
||||
if (!buf)
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
buf = strptime(buf, USMap.TimeFormat, tm);
|
||||
if (!buf)
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
buf = strptime(buf, USMap.DateFormat, tm);
|
||||
if (!buf)
|
||||
return ((char *) NULL);
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
if (!isdigit(*buf))
|
||||
return ((char *) NULL);
|
||||
for (i = 0; *buf != 0 && isdigit(*buf); buf++) {
|
||||
i *= 10;
|
||||
i += *buf - '0';
|
||||
}
|
||||
if (i > 365)
|
||||
return ((char *) NULL);
|
||||
tm->tm_yday = i;
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
case 'S':
|
||||
if (!(*buf) || isspace(*buf))
|
||||
break;
|
||||
if (!isdigit(*buf))
|
||||
return ((char *) NULL);
|
||||
for (i = 0; *buf != 0 && isdigit(*buf); buf++) {
|
||||
i *= 10;
|
||||
i += *buf - '0';
|
||||
}
|
||||
if (i > 59)
|
||||
return ((char *) NULL);
|
||||
if (c == 'M')
|
||||
tm->tm_min = i;
|
||||
else
|
||||
tm->tm_sec = i;
|
||||
|
||||
if (*buf && isspace(*buf))
|
||||
for (; *tmp && !isspace(*tmp); tmp++);
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
case 'I':
|
||||
case 'k':
|
||||
case 'l':
|
||||
if (!isdigit(*buf))
|
||||
return ((char *) NULL);
|
||||
for (i = 0; *buf && isdigit(*buf); buf++) {
|
||||
i *= 10;
|
||||
i += *buf - '0';
|
||||
}
|
||||
if (c == 'H' || c == 'k') {
|
||||
if (i > 23)
|
||||
return ((char *) NULL);
|
||||
} else if (i > 11)
|
||||
return ((char *) NULL);
|
||||
tm->tm_hour = i;
|
||||
if (*buf && isspace(*buf))
|
||||
for (; *tmp && !isspace(*tmp); tmp++);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
len = strlen(USMap.AM);
|
||||
if (!strncasecmp(buf, USMap.AM, len)) {
|
||||
if (tm->tm_hour > 12)
|
||||
return ((char *) NULL);
|
||||
if (tm->tm_hour == 12)
|
||||
tm->tm_hour = 0;
|
||||
buf += len;
|
||||
break;
|
||||
}
|
||||
len = strlen(USMap.PM);
|
||||
if (!strncasecmp(buf, USMap.PM, len)) {
|
||||
if (tm->tm_hour > 12)
|
||||
return ((char *) NULL);
|
||||
if (tm->tm_hour != 12)
|
||||
tm->tm_hour += 12;
|
||||
buf += len;
|
||||
break;
|
||||
}
|
||||
return ((char *) NULL);
|
||||
|
||||
case 'A':
|
||||
case 'a':
|
||||
for (i = 0; i < NUM_DAYS; i++) {
|
||||
len = strlen(USMap.Days[i]);
|
||||
if (!strncasecmp(buf, USMap.Days[i], len))
|
||||
break;
|
||||
len = strlen(USMap.DaysAbbrev[i]);
|
||||
if (!strncasecmp(buf, USMap.DaysAbbrev[i], len))
|
||||
break;
|
||||
}
|
||||
if (i == NUM_DAYS)
|
||||
return ((char *) NULL);
|
||||
tm->tm_wday = i;
|
||||
buf += len;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
case 'e':
|
||||
if (!isdigit(*buf))
|
||||
return ((char *) NULL);
|
||||
for (i = 0; *buf && isdigit(*buf); buf++) {
|
||||
i *= 10;
|
||||
i += *buf - '0';
|
||||
}
|
||||
if (i > 31)
|
||||
return ((char *) NULL);
|
||||
tm->tm_mday = i;
|
||||
if (*buf && isspace(*buf))
|
||||
for (; *tmp && !isspace(*tmp); tmp++);
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
case 'b':
|
||||
case 'h':
|
||||
for (i = 0; i < NUM_MONTHS; i++) {
|
||||
len = strlen(USMap.Months[i]);
|
||||
if (!strncasecmp(buf, USMap.Months[i], len))
|
||||
break;
|
||||
len = strlen(USMap.MonthsAbbrev[i]);
|
||||
if (!strncasecmp(buf, USMap.MonthsAbbrev[i], len))
|
||||
break;
|
||||
}
|
||||
if (i == NUM_MONTHS)
|
||||
return ((char *) NULL);
|
||||
tm->tm_mon = i;
|
||||
buf += len;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
if (!isdigit(*buf))
|
||||
return ((char *) NULL);
|
||||
for (i = 0; *buf && isdigit(*buf); buf++) {
|
||||
i *= 10;
|
||||
i += *buf - '0';
|
||||
}
|
||||
if (i < 1 || i > 12)
|
||||
return ((char *) NULL);
|
||||
tm->tm_mon = i - 1;
|
||||
if (*buf && isspace(*buf))
|
||||
for (; *tmp && !isspace(*tmp); tmp++);
|
||||
break;
|
||||
|
||||
case 'Y':
|
||||
case 'y':
|
||||
if (!(*buf) || isspace(*buf))
|
||||
break;
|
||||
if (!isdigit(*buf))
|
||||
return ((char *) NULL);
|
||||
for (i = 0; *buf && isdigit(*buf); buf++) {
|
||||
i *= 10;
|
||||
i += *buf - '0';
|
||||
}
|
||||
if (c == 'Y')
|
||||
i -= 1900;
|
||||
if (i < 0)
|
||||
return ((char *) NULL);
|
||||
tm->tm_year = i;
|
||||
if (*buf && isspace(*buf))
|
||||
for (; *tmp && !isspace(*tmp); tmp++);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (buf);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,70 +0,0 @@
|
|||
/***************************************************************
|
||||
* STRPTIME.H -- Header file for strptime() *
|
||||
* -- Michael Jennings *
|
||||
* -- 2 April 1997 *
|
||||
***************************************************************/
|
||||
/*
|
||||
* 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 _STRPTIME_H_
|
||||
|
||||
#define _STRPTIME_H_
|
||||
|
||||
#define sizeofone(s) (sizeof(s) / sizeof((s)[0]))
|
||||
|
||||
#define NUM_MONTHS 12
|
||||
#define NUM_DAYS 7
|
||||
|
||||
typedef struct dtmap_struct {
|
||||
char *Months[NUM_MONTHS];
|
||||
char *MonthsAbbrev[NUM_MONTHS];
|
||||
char *Days[NUM_DAYS];
|
||||
char *DaysAbbrev[NUM_DAYS];
|
||||
char *DateFormat;
|
||||
char *TimeFormat;
|
||||
char *DateTimeFormat;
|
||||
char *LocaleDateFormat;
|
||||
char *AM;
|
||||
char *PM;
|
||||
} DTMap;
|
||||
|
||||
static DTMap USMap = {
|
||||
{ "January", "February", "March", "April",
|
||||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December" },
|
||||
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
|
||||
{ "Sunday", "Monday", "Tuesday", "Wednesday",
|
||||
"Thursday", "Friday", "Saturday" },
|
||||
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
|
||||
"%m/%d/%y",
|
||||
"%H:%M:%S",
|
||||
"%a %b %e %T %Z %Y",
|
||||
"%A, %B, %e, %Y",
|
||||
"AM",
|
||||
"PM"
|
||||
};
|
||||
|
||||
extern char *strptime(char *, const char *, struct tm *);
|
||||
|
||||
#endif /* _STRPTIME_H_ */
|
|
@ -26,17 +26,10 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include "config.h"
|
||||
#include "feature.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "startup.h"
|
||||
#include "mem.h"
|
||||
#include "strings.h"
|
||||
#include "actions.h"
|
||||
#include "command.h"
|
||||
#include "e.h"
|
||||
|
|
|
@ -28,9 +28,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
|
||||
#include <X11/cursorfont.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "buttons.h"
|
||||
#include "command.h"
|
||||
#include "draw.h"
|
||||
|
@ -580,7 +577,7 @@ button_create(char *text)
|
|||
MEMSET(button, 0, sizeof(button_t));
|
||||
|
||||
if (text) {
|
||||
button->text = StrDup(text);
|
||||
button->text = STRDUP(text);
|
||||
button->len = strlen(text);
|
||||
} else {
|
||||
button->text = "";
|
||||
|
|
|
@ -111,10 +111,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
/* Eterm-specific Headers */
|
||||
#include "command.h"
|
||||
#include "startup.h"
|
||||
#include "../libmej/debug.h"
|
||||
#include "debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "events.h"
|
||||
#include "font.h"
|
||||
#include "grkelot.h"
|
||||
|
@ -1017,7 +1013,7 @@ dump_stack_trace(void)
|
|||
print_error("Your system does not support any of the methods Eterm uses. Exiting.\n");
|
||||
return;
|
||||
#endif
|
||||
signal(SIGALRM, (sighandler_t) hard_exit);
|
||||
signal(SIGALRM, (eterm_sighandler_t) hard_exit);
|
||||
alarm(10);
|
||||
system(cmd);
|
||||
}
|
||||
|
@ -1063,7 +1059,7 @@ static RETSIGTYPE
|
|||
handle_exit_signal(int sig)
|
||||
{
|
||||
|
||||
print_error("Received terminal signal %s (%d)", sig_to_str(sig), sig);
|
||||
print_error("Received terminal signal %s (%d)\n", sig_to_str(sig), sig);
|
||||
signal(sig, SIG_DFL);
|
||||
|
||||
#ifdef UTMP_SUPPORT
|
||||
|
@ -1082,7 +1078,7 @@ static RETSIGTYPE
|
|||
handle_crash(int sig)
|
||||
{
|
||||
|
||||
print_error("Received terminal signal %s (%d)", sig_to_str(sig), sig);
|
||||
print_error("Received terminal signal %s (%d)\n", sig_to_str(sig), sig);
|
||||
signal(sig, SIG_DFL); /* Let the OS handle recursive seg faults */
|
||||
|
||||
/* Lock down security so we don't write any core files as root. */
|
||||
|
@ -1140,6 +1136,7 @@ clean_exit(void)
|
|||
remove_utmp_entry();
|
||||
#endif
|
||||
privileges(REVERT);
|
||||
memrec_dump();
|
||||
PABLO_STOP_TRACING();
|
||||
DPRINTF1(("Cleanup done. I am outta here!\n"));
|
||||
}
|
||||
|
@ -1307,7 +1304,7 @@ get_pty(void)
|
|||
fcntl(fd, F_SETFL, O_NDELAY);
|
||||
return (fd);
|
||||
} else {
|
||||
print_error("Can't open pseudo-tty -- %s", strerror(errno));
|
||||
print_error("Can't open pseudo-tty -- %s\n", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
@ -1343,7 +1340,7 @@ get_tty(void)
|
|||
print_error("Slave tty device name is NULL. Failed to open slave pty.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else if ((fd = open(ttydev, O_RDWR)) < 0) {
|
||||
print_error("Can't open slave tty %s -- %s", ttydev, strerror(errno));
|
||||
print_error("Can't open slave tty %s -- %s\n", ttydev, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
D_TTY(("Opened slave tty %s\n", ttydev));
|
||||
|
@ -1727,7 +1724,7 @@ init_locale(void)
|
|||
locale = setlocale(LC_ALL, "");
|
||||
TermWin.fontset = (XFontSet) -1;
|
||||
if (locale == NULL) {
|
||||
print_error("Setting locale failed.");
|
||||
print_error("Setting locale failed.\n");
|
||||
} else {
|
||||
#ifdef MULTI_CHARSET
|
||||
TermWin.fontset = create_fontset(etfonts[def_font_idx], etmfonts[def_font_idx]);
|
||||
|
@ -1896,13 +1893,13 @@ xim_real_init(void)
|
|||
destroy_cb.callback = xim_destroy_cb;
|
||||
destroy_cb.client_data = NULL;
|
||||
if (XSetIMValues(xim, XNDestroyCallback, &destroy_cb, NULL)) {
|
||||
print_error("Could not set destroy callback to IM");
|
||||
print_error("Could not set destroy callback to IM\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL)) || (!xim_styles)) {
|
||||
print_error("input method doesn't support any style");
|
||||
print_error("input method doesn't support any style\n");
|
||||
XCloseIM(xim);
|
||||
return -1;
|
||||
}
|
||||
|
@ -1936,14 +1933,14 @@ xim_real_init(void)
|
|||
XFree(xim_styles);
|
||||
|
||||
if (found == 0) {
|
||||
print_error("input method doesn't support my preedit type");
|
||||
print_error("input method doesn't support my preedit type\n");
|
||||
XCloseIM(xim);
|
||||
return -1;
|
||||
}
|
||||
if ((xim_input_style != (XIMPreeditNothing | XIMStatusNothing))
|
||||
&& (xim_input_style != (XIMPreeditArea | XIMStatusArea))
|
||||
&& (xim_input_style != (XIMPreeditPosition | XIMStatusNothing))) {
|
||||
print_error("This program does not support the preedit type");
|
||||
print_error("This program does not support the preedit type\n");
|
||||
XCloseIM(xim);
|
||||
return -1;
|
||||
}
|
||||
|
@ -1969,7 +1966,7 @@ xim_real_init(void)
|
|||
XFree(status_attr);
|
||||
}
|
||||
if (xim_input_context == NULL) {
|
||||
print_error("Failed to create input context");
|
||||
print_error("Failed to create input context\n");
|
||||
XCloseIM(xim);
|
||||
return -1;
|
||||
}
|
||||
|
@ -2065,7 +2062,7 @@ run_command(char *argv[])
|
|||
# if defined (__sun__)
|
||||
on_exit(clean_exit, NULL); /* non-ANSI exit handler */
|
||||
# else
|
||||
print_error("no atexit(), UTMP entries can't be cleaned");
|
||||
print_error("no atexit(), UTMP entries can't be cleaned\n");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
@ -2083,7 +2080,7 @@ run_command(char *argv[])
|
|||
SavedModes |= PrivMode_scrollbar;
|
||||
}
|
||||
#if DEBUG >= DEBUG_TTYMODE && defined(HAVE_TERMIOS_H)
|
||||
if (debug_level >= DEBUG_TTYMODE) {
|
||||
if (DEBUG_LEVEL >= DEBUG_TTYMODE) {
|
||||
debug_ttymode(&tio);
|
||||
}
|
||||
#endif
|
||||
|
@ -2092,7 +2089,7 @@ run_command(char *argv[])
|
|||
cmd_pid = fork();
|
||||
D_CMD(("After fork(), cmd_pid == %d\n", cmd_pid));
|
||||
if (cmd_pid < 0) {
|
||||
print_error("fork(): %s", strerror(errno));
|
||||
print_error("fork(): %s\n", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
if (cmd_pid == 0) {
|
||||
|
@ -2166,7 +2163,7 @@ run_command(char *argv[])
|
|||
}
|
||||
if (argv != NULL) {
|
||||
#if DEBUG >= DEBUG_CMD
|
||||
if (debug_level >= DEBUG_CMD) {
|
||||
if (DEBUG_LEVEL >= DEBUG_CMD) {
|
||||
int i;
|
||||
|
||||
for (i = 0; argv[i]; i++) {
|
||||
|
@ -2175,7 +2172,7 @@ run_command(char *argv[])
|
|||
}
|
||||
#endif
|
||||
execvp(argv[0], argv);
|
||||
print_error("execvp() failed, cannot execute \"%s\": %s", argv[0], strerror(errno));
|
||||
print_error("execvp() failed, cannot execute \"%s\": %s\n", argv[0], strerror(errno));
|
||||
} else {
|
||||
|
||||
const char *argv0, *shell;
|
||||
|
@ -2192,7 +2189,7 @@ run_command(char *argv[])
|
|||
argv0 = p;
|
||||
}
|
||||
execlp(shell, argv0, NULL);
|
||||
print_error("execlp() failed, cannot execute \"%s\": %s", shell, strerror(errno));
|
||||
print_error("execlp() failed, cannot execute \"%s\": %s\n", shell, strerror(errno));
|
||||
}
|
||||
sleep(3); /* Sleep to make sure fork() returns in the parent, and so user can read error message */
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -2249,7 +2246,7 @@ init_command(char *argv[])
|
|||
cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
|
||||
|
||||
if ((cmd_fd = run_command(argv)) < 0) {
|
||||
print_error("aborting");
|
||||
print_error("aborting\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
@ -2621,7 +2618,7 @@ main_loop(void)
|
|||
|
||||
ch = *cmdbuf_ptr++;
|
||||
#if DEBUG >= DEBUG_VT
|
||||
if (debug_level >= DEBUG_VT) {
|
||||
if (DEBUG_LEVEL >= DEBUG_VT) {
|
||||
if (ch < 32) {
|
||||
D_VT(("\'%s\' (%d 0x%02x %03o)\n", get_ctrl_char_name(ch), ch, ch, ch));
|
||||
} else {
|
||||
|
@ -2730,7 +2727,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. */
|
||||
/* Don't use Xtlibmej_realloc because an error is not fatal. */
|
||||
int size = v_bufptr - v_buffer; /* save across realloc */
|
||||
|
||||
v_buffer = REALLOC(v_buffer, size + len);
|
||||
|
|
239
src/debug.h
239
src/debug.h
|
@ -1,239 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/* A NOP. Does nothing. */
|
||||
# define NOP ((void)0)
|
||||
|
||||
/* A macro and an #undef to FIXME-ize individual calls or entire code blocks. */
|
||||
# define FIXME_NOP(x)
|
||||
# undef FIXME_BLOCK
|
||||
|
||||
/* The basic debugging output leader. */
|
||||
#if defined(__FILE__) && defined(__LINE__)
|
||||
# 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
|
||||
#else
|
||||
# define __DEBUG() NOP
|
||||
#endif
|
||||
|
||||
/* A quick and dirty macro to say, "Hi! I got here without crashing!" */
|
||||
# define MOO() do { __DEBUG(); fprintf(stderr, "Moo.\n"); fflush(stderr); } while (0)
|
||||
|
||||
/* Assertion/abort macros which are quite a bit more useful than assert() and abort(). */
|
||||
#if defined(__FILE__) && defined(__LINE__)
|
||||
# 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
|
||||
|
||||
#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)
|
||||
# define DPRINTF6(x) do { if (debug_level >= 6) {__DEBUG(); real_dprintf x;} } while (0)
|
||||
# define DPRINTF7(x) do { if (debug_level >= 7) {__DEBUG(); real_dprintf x;} } while (0)
|
||||
# define DPRINTF8(x) do { if (debug_level >= 8) {__DEBUG(); real_dprintf x;} } while (0)
|
||||
# define DPRINTF9(x) do { if (debug_level >= 9) {__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
|
||||
# define DPRINTF6(x) NOP
|
||||
# define DPRINTF7(x) NOP
|
||||
# define DPRINTF8(x) NOP
|
||||
# define DPRINTF9(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)
|
||||
# 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_ACTIONS 4
|
||||
# define D_ACTIONS(x) DPRINTF4(x)
|
||||
|
||||
# define DEBUG_MALLOC 5
|
||||
# define D_MALLOC(x) DPRINTF5(x)
|
||||
# define DEBUG_PROFILE 5
|
||||
# define D_PROFILE(x) DPRINTF5(x)
|
||||
|
||||
# define DEBUG_VT 6
|
||||
# define D_VT(x) DPRINTF6(x)
|
||||
|
||||
# define DEBUG_X 9
|
||||
|
||||
# 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 */
|
|
@ -26,10 +26,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include "config.h"
|
||||
#include "feature.h"
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "draw.h"
|
||||
#include "misc.h"
|
||||
#include "pixmap.h"
|
||||
|
|
38
src/e.c
38
src/e.c
|
@ -33,10 +33,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include <X11/cursorfont.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "e.h"
|
||||
#include "command.h"
|
||||
#include "startup.h"
|
||||
|
@ -140,7 +136,7 @@ enl_ipc_send(char *str)
|
|||
if (last_msg != NULL) {
|
||||
FREE(last_msg);
|
||||
}
|
||||
last_msg = StrDup(str);
|
||||
last_msg = STRDUP(str);
|
||||
D_ENL(("Sending \"%s\" to Enlightenment.\n", str));
|
||||
}
|
||||
|
||||
|
@ -249,7 +245,7 @@ enl_send_and_wait(char *msg)
|
|||
{
|
||||
|
||||
char *reply = IPC_TIMEOUT;
|
||||
sighandler_t old_alrm;
|
||||
eterm_sighandler_t old_alrm;
|
||||
|
||||
if (ipc_win == None) {
|
||||
/* The IPC window is missing. Wait for it to return or Eterm to be killed. */
|
||||
|
@ -257,7 +253,7 @@ enl_send_and_wait(char *msg)
|
|||
sleep(1);
|
||||
}
|
||||
}
|
||||
old_alrm = (sighandler_t) signal(SIGALRM, (sighandler_t) enl_ipc_timeout);
|
||||
old_alrm = (eterm_sighandler_t) signal(SIGALRM, (eterm_sighandler_t) enl_ipc_timeout);
|
||||
for (; reply == IPC_TIMEOUT;) {
|
||||
timeout = 0;
|
||||
enl_ipc_send(msg);
|
||||
|
@ -290,43 +286,43 @@ eterm_ipc_parse(char *str)
|
|||
if (params) {
|
||||
tt_write((unsigned char *) params, strlen(params));
|
||||
} else {
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"", str);
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"\n", str);
|
||||
}
|
||||
} else if (!strcasecmp(str, "parse")) {
|
||||
if (params) {
|
||||
cmd_write((unsigned char *) params, strlen(params));
|
||||
} else {
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"", str);
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"\n", str);
|
||||
}
|
||||
} else if (!strcasecmp(str, "enl_send")) {
|
||||
if (params) {
|
||||
enl_ipc_send(params);
|
||||
} else {
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"", str);
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"\n", str);
|
||||
}
|
||||
} else if (!strcasecmp(str, "enl_query")) {
|
||||
if (params) {
|
||||
char *reply, header[512];
|
||||
|
||||
reply = enl_send_and_wait(params);
|
||||
snprintf(header, sizeof(header), "Enlightenment IPC Reply to \"%s\":\n\n", params);
|
||||
snprintf(header, sizeof(header), "Enlightenment IPC Reply to \"%s\":\n", params);
|
||||
tt_write((unsigned char *) header, strlen(header));
|
||||
tt_write((unsigned char *) reply, strlen(reply));
|
||||
tt_write((unsigned char *) "\n", 1);
|
||||
FREE(reply);
|
||||
} else {
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"", str);
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"\n", str);
|
||||
}
|
||||
} else if (!strcasecmp(str, "winop")) {
|
||||
if (params) {
|
||||
eterm_handle_winop(params);
|
||||
} else {
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"", str);
|
||||
print_error("IPC Error: Invalid syntax in command \"%s\"\n", str);
|
||||
}
|
||||
} else if (!strcasecmp(str, "exit")) {
|
||||
exit(0);
|
||||
} else {
|
||||
print_error("IPC Error: Unrecognized command \"%s\"", str);
|
||||
print_error("IPC Error: Unrecognized command \"%s\"\n", str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,13 +369,13 @@ eterm_handle_winop(char *action)
|
|||
int x, y, n;
|
||||
char *xx, *yy;
|
||||
|
||||
n = NumWords(action);
|
||||
n = num_words(action);
|
||||
if (n == 3 || n == 4) {
|
||||
if (n == 3) {
|
||||
win = TermWin.parent;
|
||||
}
|
||||
xx = PWord(n - 1, action);
|
||||
yy = PWord(n, action);
|
||||
xx = get_pword(n - 1, action);
|
||||
yy = get_pword(n, action);
|
||||
x = (int) strtol(xx, (char **) NULL, 0);
|
||||
y = (int) strtol(yy, (char **) NULL, 0);
|
||||
XMoveWindow(Xdisplay, win, x, y);
|
||||
|
@ -388,13 +384,13 @@ eterm_handle_winop(char *action)
|
|||
int w, h, n;
|
||||
char *ww, *hh;
|
||||
|
||||
n = NumWords(action);
|
||||
n = num_words(action);
|
||||
if (n == 3 || n == 4) {
|
||||
if (n == 3) {
|
||||
win = TermWin.parent;
|
||||
}
|
||||
ww = PWord(n - 1, action);
|
||||
hh = PWord(n, action);
|
||||
ww = get_pword(n - 1, action);
|
||||
hh = get_pword(n, action);
|
||||
w = (int) strtol(ww, (char **) NULL, 0);
|
||||
h = (int) strtol(hh, (char **) NULL, 0);
|
||||
XResizeWindow(Xdisplay, win, w, h);
|
||||
|
@ -404,6 +400,6 @@ eterm_handle_winop(char *action)
|
|||
} else if (!BEG_STRCASECMP(action, "iconify")) {
|
||||
XIconifyWindow(Xdisplay, win, Xscreen);
|
||||
} else {
|
||||
print_error("IPC Error: Unrecognized window operation \"%s\"", action);
|
||||
print_error("IPC Error: Unrecognized window operation \"%s\"\n", action);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ enc_create_context(const char *id)
|
|||
|
||||
tmp = (enc_context_t *) MALLOC(sizeof(enc_context_t));
|
||||
MEMSET(tmp, 0, sizeof(enc_context_t));
|
||||
tmp->id = StrDup(id);
|
||||
tmp->id = STRDUP(id);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ enc_create_state(const char *id, unsigned char lifetime)
|
|||
|
||||
tmp = (enc_state_t *) MALLOC(sizeof(enc_state_t));
|
||||
MEMSET(tmp, 0, sizeof(enc_state_t));
|
||||
tmp->id = StrDup(id);
|
||||
tmp->id = STRDUP(id);
|
||||
tmp->lifetime = lifetime;
|
||||
return tmp;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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 _ETERM_DEBUG_H
|
||||
# define _ETERM_DEBUG_H
|
||||
|
||||
/* 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)
|
||||
# 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_ACTIONS 4
|
||||
# define D_ACTIONS(x) DPRINTF4(x)
|
||||
|
||||
# define DEBUG_PROFILE 5
|
||||
# define D_PROFILE(x) DPRINTF5(x)
|
||||
|
||||
# define DEBUG_VT 6
|
||||
# define D_VT(x) DPRINTF6(x)
|
||||
|
||||
# define DEBUG_X 9
|
||||
|
||||
# define DEBUG_PARSE 9999
|
||||
# define D_PARSE(x) D_NEVER(x)
|
||||
|
||||
#endif /* _ETERM_DEBUG_H */
|
11
src/events.c
11
src/events.c
|
@ -31,12 +31,7 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "startup.h"
|
||||
#include "mem.h"
|
||||
#include "strings.h"
|
||||
#include "actions.h"
|
||||
#include "buttons.h"
|
||||
#include "command.h"
|
||||
|
@ -783,13 +778,13 @@ xerror_handler(Display * display, XErrorEvent * event)
|
|||
|
||||
strcpy(err_string, "");
|
||||
XGetErrorText(display, event->error_code, err_string, sizeof(err_string));
|
||||
print_error("XError in function %s, resource 0x%08x (request %d.%d): %s (error %d)", request_code_to_name(event->request_code),
|
||||
print_error("XError in function %s, resource 0x%08x (request %d.%d): %s (error %d)\n", request_code_to_name(event->request_code),
|
||||
(int) event->resourceid, event->request_code, event->minor_code, err_string, event->error_code);
|
||||
#if DEBUG > DEBUG_X11
|
||||
if (debug_level >= DEBUG_X11) {
|
||||
if (DEBUG_LEVEL >= DEBUG_X11) {
|
||||
dump_stack_trace();
|
||||
}
|
||||
#endif
|
||||
print_error("Attempting to continue...");
|
||||
print_error("Attempting to continue...\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
# define COUNT_EVENT(x) NOP
|
||||
#endif
|
||||
#ifdef PROFILE_X_EVENTS
|
||||
# define P_EVENT_TIME(type, start, stop) real_dprintf(type ": %ld microseconds\n", P_CMPTIMEVALS_USEC((start), (stop)))
|
||||
# define P_EVENT_TIME(type, start, stop) libmej_dprintf(type ": %ld microseconds\n", P_CMPTIMEVALS_USEC((start), (stop)))
|
||||
#else
|
||||
# define P_EVENT_TIME(type, start, stop) NOP
|
||||
#endif
|
||||
|
|
|
@ -89,7 +89,8 @@
|
|||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
# include "debug.h"
|
||||
# include <libmej.h>
|
||||
# include "eterm_debug.h"
|
||||
|
||||
/********************* Color, screen, and image stuff *********************/
|
||||
|
||||
|
|
40
src/font.c
40
src/font.c
|
@ -32,10 +32,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include <limits.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "command.h"
|
||||
#include "font.h"
|
||||
#include "startup.h"
|
||||
|
@ -78,9 +74,9 @@ eterm_font_add(char ***plist, const char *fontname, unsigned char idx) {
|
|||
etfonts = (char **) REALLOC(etfonts, new_size);
|
||||
#ifdef MULTI_CHARSET
|
||||
etmfonts = (char **) REALLOC(etmfonts, new_size);
|
||||
D_FONT((" -> Reallocating fonts lists to a size of %u bytes gives %8p/%8p\n", new_size, etfonts, etmfonts));
|
||||
D_FONT((" -> libmej_reallocating fonts lists to a size of %u bytes gives %8p/%8p\n", new_size, etfonts, etmfonts));
|
||||
#else
|
||||
D_FONT((" -> Reallocating fonts list to a size of %u bytes gives %8p\n", new_size, etfonts));
|
||||
D_FONT((" -> libmej_reallocating fonts list to a size of %u bytes gives %8p\n", new_size, etfonts));
|
||||
#endif
|
||||
} else {
|
||||
etfonts = (char **) MALLOC(new_size);
|
||||
|
@ -109,7 +105,7 @@ eterm_font_add(char ***plist, const char *fontname, unsigned char idx) {
|
|||
FREE(flist[idx]);
|
||||
}
|
||||
}
|
||||
flist[idx] = StrDup(fontname);
|
||||
flist[idx] = STRDUP(fontname);
|
||||
DUMP_FONTS();
|
||||
}
|
||||
|
||||
|
@ -132,7 +128,7 @@ font_cache_add(const char *name, unsigned char type, void *info) {
|
|||
D_FONT(("font_cache_add(%s, %d, %8p) called.\n", NONULL(name), type, info));
|
||||
|
||||
font = (cachefont_t *) MALLOC(sizeof(cachefont_t));
|
||||
font->name = StrDup(name);
|
||||
font->name = STRDUP(name);
|
||||
font->type = type;
|
||||
font->ref_cnt = 1;
|
||||
switch (type) {
|
||||
|
@ -295,7 +291,7 @@ load_font(const char *name, const char *fallback, unsigned char type)
|
|||
if ((xfont = XLoadQueryFont(Xdisplay, name)) == NULL) {
|
||||
print_error("Unable to load font \"%s\". Falling back on \"%s\"\n", name, fallback);
|
||||
if ((xfont = XLoadQueryFont(Xdisplay, fallback)) == NULL) {
|
||||
fatal_error("Couldn't load the fallback font either. Giving up.");
|
||||
fatal_error("Couldn't load the fallback font either. Giving up.\n");
|
||||
} else {
|
||||
font_cache_add(fallback, type, (void *) xfont);
|
||||
}
|
||||
|
@ -579,7 +575,7 @@ parse_font_fx(const char *line)
|
|||
|
||||
ASSERT(line != NULL);
|
||||
|
||||
n = NumWords(line);
|
||||
n = num_words(line);
|
||||
|
||||
if (!BEG_STRCASECMP(line, "none")) {
|
||||
MEMSET(&fshadow, 0, sizeof(fontshadow_t));
|
||||
|
@ -587,7 +583,7 @@ parse_font_fx(const char *line)
|
|||
if (n != 2) {
|
||||
return 0;
|
||||
}
|
||||
color = Word(2, line);
|
||||
color = get_word(2, line);
|
||||
p = get_color_by_name(color, "black");
|
||||
FREE(color);
|
||||
for (which = 0; which < 4; which++) {
|
||||
|
@ -596,10 +592,10 @@ parse_font_fx(const char *line)
|
|||
} else if (!BEG_STRCASECMP(line, "shadow")) {
|
||||
if (n == 2) {
|
||||
which = SHADOW_BOTTOM_RIGHT;
|
||||
color = Word(2, line);
|
||||
color = get_word(2, line);
|
||||
} else if (n == 3) {
|
||||
color = Word(3, line);
|
||||
corner = PWord(2, line);
|
||||
color = get_word(3, line);
|
||||
corner = get_pword(2, line);
|
||||
which = get_corner(corner);
|
||||
if (which >= 4) {
|
||||
return 0;
|
||||
|
@ -613,12 +609,12 @@ parse_font_fx(const char *line)
|
|||
if (n != 3) {
|
||||
return 0;
|
||||
}
|
||||
color = Word(2, line);
|
||||
color = get_word(2, line);
|
||||
p = get_color_by_name(color, "black");
|
||||
set_shadow_color_by_pixel(SHADOW_BOTTOM_RIGHT, p);
|
||||
FREE(color);
|
||||
|
||||
color = Word(3, line);
|
||||
color = get_word(3, line);
|
||||
p = get_color_by_name(color, "white");
|
||||
set_shadow_color_by_pixel(SHADOW_TOP_LEFT, p);
|
||||
FREE(color);
|
||||
|
@ -626,12 +622,12 @@ parse_font_fx(const char *line)
|
|||
if (n != 3) {
|
||||
return 0;
|
||||
}
|
||||
color = Word(2, line);
|
||||
color = get_word(2, line);
|
||||
p = get_color_by_name(color, "black");
|
||||
set_shadow_color_by_pixel(SHADOW_TOP_LEFT, p);
|
||||
FREE(color);
|
||||
|
||||
color = Word(3, line);
|
||||
color = get_word(3, line);
|
||||
p = get_color_by_name(color, "white");
|
||||
set_shadow_color_by_pixel(SHADOW_BOTTOM_RIGHT, p);
|
||||
FREE(color);
|
||||
|
@ -642,11 +638,11 @@ parse_font_fx(const char *line)
|
|||
which = get_corner(line);
|
||||
if (which >= 4) {
|
||||
which = i;
|
||||
color = Word(1, line);
|
||||
line = PWord(2, line);
|
||||
color = get_word(1, line);
|
||||
line = get_pword(2, line);
|
||||
} else {
|
||||
color = Word(2, line);
|
||||
line = PWord(3, line);
|
||||
color = get_word(2, line);
|
||||
line = get_pword(3, line);
|
||||
}
|
||||
set_shadow_color_by_name(which, color);
|
||||
FREE(color);
|
||||
|
|
21
src/menus.c
21
src/menus.c
|
@ -28,9 +28,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
|
||||
#include <X11/cursorfont.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "command.h"
|
||||
#include "draw.h"
|
||||
#include "e.h"
|
||||
|
@ -442,7 +439,7 @@ menu_create(char *title)
|
|||
}
|
||||
menu = (menu_t *) MALLOC(sizeof(menu_t));
|
||||
MEMSET(menu, 0, sizeof(menu_t));
|
||||
menu->title = StrDup(title ? title : "");
|
||||
menu->title = STRDUP(title ? title : "");
|
||||
|
||||
menu->win = XCreateWindow(Xdisplay, Xroot, 0, 0, 1, 1, 0, Xdepth, InputOutput, CopyFromParent,
|
||||
CWOverrideRedirect | CWSaveUnder | CWBackingStore | CWBorderPixel | CWColormap, &xattr);
|
||||
|
@ -466,7 +463,7 @@ menu_set_title(menu_t *menu, const char *title)
|
|||
REQUIRE_RVAL(title != NULL, 0);
|
||||
|
||||
FREE(menu->title);
|
||||
menu->title = StrDup(title);
|
||||
menu->title = STRDUP(title);
|
||||
XStoreName(Xdisplay, menu->win, menu->title);
|
||||
return 1;
|
||||
}
|
||||
|
@ -656,7 +653,7 @@ menuitem_create(char *text)
|
|||
MEMSET(menuitem, 0, sizeof(menuitem_t));
|
||||
|
||||
if (text) {
|
||||
menuitem->text = StrDup(text);
|
||||
menuitem->text = STRDUP(text);
|
||||
menuitem->len = strlen(text);
|
||||
}
|
||||
return menuitem;
|
||||
|
@ -671,7 +668,7 @@ menuitem_set_text(menuitem_t * item, const char *text)
|
|||
if (item->text) {
|
||||
FREE(item->text);
|
||||
}
|
||||
item->text = StrDup(text);
|
||||
item->text = STRDUP(text);
|
||||
item->len = strlen(text);
|
||||
return 1;
|
||||
}
|
||||
|
@ -717,7 +714,7 @@ menuitem_set_rtext(menuitem_t * item, char *rtext)
|
|||
ASSERT_RVAL(item != NULL, 0);
|
||||
ASSERT_RVAL(rtext != NULL, 0);
|
||||
|
||||
item->rtext = StrDup(rtext);
|
||||
item->rtext = STRDUP(rtext);
|
||||
item->rlen = strlen(rtext);
|
||||
return 1;
|
||||
}
|
||||
|
@ -1043,14 +1040,14 @@ menu_draw(menu_t * menu)
|
|||
break;
|
||||
#if 0
|
||||
case MENUITEM_STRING:
|
||||
safeaction = StrDup(item->action.string);
|
||||
SafeStr(safeaction, strlen(safeaction));
|
||||
safeaction = STRDUP(item->action.string);
|
||||
safe_str(safeaction, strlen(safeaction));
|
||||
D_MENU((" Item %hu: %s (string %s)\n", i, item->text, safeaction));
|
||||
FREE(safeaction);
|
||||
break;
|
||||
case MENUITEM_ECHO:
|
||||
safeaction = StrDup(item->action.string);
|
||||
SafeStr(safeaction, strlen(safeaction));
|
||||
safeaction = STRDUP(item->action.string);
|
||||
safe_str(safeaction, strlen(safeaction));
|
||||
D_MENU((" Item %hu: %s (echo %s)\n", i, item->text, safeaction));
|
||||
FREE(safeaction);
|
||||
break;
|
||||
|
|
55
src/misc.c
55
src/misc.c
|
@ -36,10 +36,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "command.h"
|
||||
#include "startup.h"
|
||||
#include "misc.h"
|
||||
|
@ -55,49 +51,6 @@ my_basename(const char *str)
|
|||
|
||||
}
|
||||
|
||||
/* Print a non-terminal error message */
|
||||
void
|
||||
print_error(const char *fmt,...)
|
||||
{
|
||||
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, fmt);
|
||||
fprintf(stderr, APL_NAME ": ");
|
||||
vfprintf(stderr, fmt, arg_ptr);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(arg_ptr);
|
||||
}
|
||||
|
||||
/* Print a simple warning. */
|
||||
void
|
||||
print_warning(const char *fmt,...)
|
||||
{
|
||||
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, fmt);
|
||||
fprintf(stderr, APL_NAME ": warning: ");
|
||||
vfprintf(stderr, fmt, arg_ptr);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(arg_ptr);
|
||||
}
|
||||
|
||||
/* Print a fatal error message and terminate */
|
||||
void
|
||||
fatal_error(const char *fmt,...)
|
||||
{
|
||||
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, fmt);
|
||||
fprintf(stderr, APL_NAME ": FATAL: ");
|
||||
vfprintf(stderr, fmt, arg_ptr);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(arg_ptr);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compares the first n characters of s1 and s2, where n is strlen(s2)
|
||||
* Returns strlen(s2) if they match, 0 if not.
|
||||
|
@ -264,9 +217,9 @@ parse_escaped_string(char *str)
|
|||
*pnew = 0;
|
||||
|
||||
#if DEBUG >= DEBUG_STRINGS
|
||||
if (debug_level >= DEBUG_STRINGS) {
|
||||
D_STRINGS(("New value is:\n\n"));
|
||||
HexDump(str, (size_t) (pnew - str));
|
||||
if (DEBUG_LEVEL >= DEBUG_STRINGS) {
|
||||
D_STRINGS(("New value is:\n"));
|
||||
hex_dump(str, (size_t) (pnew - str));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -360,7 +313,7 @@ mkdirhier(const char *path)
|
|||
struct stat dst;
|
||||
|
||||
D_CMD(("path == %s\n", path));
|
||||
str = StrDup(path); /* We need to modify it. */
|
||||
str = STRDUP(path); /* We need to modify it. */
|
||||
pstr = str;
|
||||
if (*pstr == '/') {
|
||||
pstr++;
|
||||
|
|
|
@ -37,9 +37,6 @@
|
|||
_XFUNCPROTOBEGIN
|
||||
|
||||
extern const char *my_basename(const char *str);
|
||||
extern void print_error(const char *fmt,...);
|
||||
extern void print_warning(const char *fmt,...);
|
||||
extern void fatal_error(const char *fmt,...);
|
||||
extern unsigned long str_leading_match(register const char *, register const char *);
|
||||
extern char *str_trim(char *str);
|
||||
extern int parse_escaped_string(char *str);
|
||||
|
|
709
src/options.c
709
src/options.c
File diff suppressed because it is too large
Load Diff
|
@ -102,10 +102,10 @@
|
|||
#define BAD_THRESHOLD 3
|
||||
#define CHECK_BAD() do { \
|
||||
if (++bad_opts >= BAD_THRESHOLD) { \
|
||||
print_error("Error threshold exceeded, giving up."); \
|
||||
print_error("Error threshold exceeded, giving up.\n"); \
|
||||
usage(); \
|
||||
} else { \
|
||||
print_error("Attempting to continue, but strange things may happen."); \
|
||||
print_error("Attempting to continue, but strange things may happen.\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
@ -160,6 +160,7 @@
|
|||
#define to_keysym(p,s) do { KeySym sym; \
|
||||
if (s && ((sym = XStringToKeysym(s)) != 0)) *p = sym; \
|
||||
} while (0)
|
||||
#define CHECK_VALID_INDEX(i) (((i) >= image_bg) && ((i) < image_max))
|
||||
|
||||
#define RESET_AND_ASSIGN(var, val) do {if ((var) != NULL) FREE(var); (var) = (val);} while (0)
|
||||
|
||||
|
@ -251,7 +252,7 @@ extern KeySym ks_smallfont;
|
|||
/************ Function Prototypes ************/
|
||||
_XFUNCPROTOBEGIN
|
||||
|
||||
unsigned long NumWords(const char *str);
|
||||
unsigned long num_words(const char *str);
|
||||
extern void get_initial_options(int, char **);
|
||||
extern void get_options(int, char **);
|
||||
extern void conf_init_subsystem(void);
|
||||
|
|
23
src/pixmap.c
23
src/pixmap.c
|
@ -38,9 +38,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
# include <X11/extensions/shape.h>
|
||||
#endif
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "draw.h"
|
||||
#include "e.h"
|
||||
#include "icon.h"
|
||||
|
@ -591,7 +588,7 @@ create_viewport_pixmap(simage_t *simg, Drawable d, int x, int y, unsigned short
|
|||
imlib_render_pixmaps_for_whole_image(&viewport_pixmap, &mask);
|
||||
}
|
||||
if (viewport_pixmap == None) {
|
||||
print_error("Delayed image load failure for \"%s\". Using solid color mode.", imlib_image_get_filename());
|
||||
print_error("Delayed image load failure for \"%s\". Using solid color mode.\n", imlib_image_get_filename());
|
||||
image_set_mode(image_bg, MODE_SOLID);
|
||||
reset_simage(simg, RESET_ALL_SIMG);
|
||||
return None;
|
||||
|
@ -667,7 +664,7 @@ paste_simage(simage_t *simg, unsigned char which, Drawable d, unsigned short x,
|
|||
FREE(reply);
|
||||
} else {
|
||||
pmap = (Pixmap) strtoul(reply, (char **) NULL, 0);
|
||||
mask = (Pixmap) strtoul(PWord(2, reply), (char **) NULL, 0);
|
||||
mask = (Pixmap) strtoul(get_pword(2, reply), (char **) NULL, 0);
|
||||
FREE(reply);
|
||||
enl_ipc_sync();
|
||||
if (pmap) {
|
||||
|
@ -729,7 +726,7 @@ paste_simage(simage_t *simg, unsigned char which, Drawable d, unsigned short x,
|
|||
imlib_render_pixmaps_for_whole_image_at_size(&pmap, &mask, w, h);
|
||||
}
|
||||
if (pmap == None) {
|
||||
print_error("Delayed image load failure for \"%s\".", NONULL(imlib_image_get_filename()));
|
||||
print_error("Delayed image load failure for \"%s\".\n", NONULL(imlib_image_get_filename()));
|
||||
reset_simage(simg, RESET_ALL_SIMG);
|
||||
return;
|
||||
}
|
||||
|
@ -892,7 +889,7 @@ render_simage(simage_t * simg, Window win, unsigned short width, unsigned short
|
|||
Pixmap pmap, mask;
|
||||
|
||||
pmap = (Pixmap) strtoul(reply, (char **) NULL, 0);
|
||||
mask = (Pixmap) strtoul(PWord(2, reply), (char **) NULL, 0);
|
||||
mask = (Pixmap) strtoul(get_pword(2, reply), (char **) NULL, 0);
|
||||
FREE(reply);
|
||||
enl_ipc_sync();
|
||||
if (pmap) {
|
||||
|
@ -1073,7 +1070,7 @@ render_simage(simage_t * simg, Window win, unsigned short width, unsigned short
|
|||
XSetWindowBackgroundPixmap(Xdisplay, win, simg->pmap->pixmap);
|
||||
}
|
||||
} else {
|
||||
print_error("Delayed image load failure for \"%s\". Using solid color mode.", imlib_image_get_filename());
|
||||
print_error("Delayed image load failure for \"%s\". Using solid color mode.\n", imlib_image_get_filename());
|
||||
image_set_mode(which, MODE_SOLID);
|
||||
reset_simage(simg, RESET_ALL_SIMG);
|
||||
}
|
||||
|
@ -1253,7 +1250,7 @@ load_image(const char *file, simage_t *simg)
|
|||
if (f != NULL) {
|
||||
im = imlib_load_image_immediately(f);
|
||||
if (im == NULL) {
|
||||
print_error("Unable to load image file \"%s\"", file);
|
||||
print_error("Unable to load image file \"%s\"\n", file);
|
||||
return 0;
|
||||
} else {
|
||||
reset_simage(simg, (RESET_IMLIB_IM | RESET_PMAP_PIXMAP | RESET_PMAP_MASK));
|
||||
|
@ -1640,12 +1637,12 @@ colormod_trans(Pixmap p, imlib_t *iml, GC gc, unsigned short w, unsigned short h
|
|||
}
|
||||
ximg = XGetImage(Xdisplay, p, 0, 0, w, h, -1, ZPixmap);
|
||||
if (ximg == NULL) {
|
||||
print_warning("XGetImage(Xdisplay, 0x%08x, 0, 0, %d, %d, -1, ZPixmap) returned NULL.", p, w, h);
|
||||
print_warning("XGetImage(Xdisplay, 0x%08x, 0, 0, %d, %d, -1, ZPixmap) returned NULL.\n", p, w, h);
|
||||
return;
|
||||
}
|
||||
D_PIXMAP(("XGetImage(Xdisplay, 0x%08x, 0, 0, %d, %d, -1, ZPixmap) returned %8p.\n", p, w, h, ximg));
|
||||
if (Xdepth <= 8) {
|
||||
#ifdef FIXME_BLOCK
|
||||
#if FIXME_BLOCK
|
||||
D_PIXMAP(("Rendering low-depth image, depth == %d\n", (int) Xdepth));
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < w; x++) {
|
||||
|
@ -1700,7 +1697,7 @@ colormod_trans(Pixmap p, imlib_t *iml, GC gc, unsigned short w, unsigned short h
|
|||
#endif
|
||||
break;
|
||||
default:
|
||||
print_warning("Bit depth of %d is unsupported for tinting/shading.", real_depth);
|
||||
print_warning("Bit depth of %d is unsupported for tinting/shading.\n", real_depth);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1743,7 +1740,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 "
|
||||
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;
|
||||
|
|
|
@ -54,7 +54,7 @@ typedef void *Imlib_Color_Modifier;
|
|||
# define CONVERT_TINT_RED(t) (((t) & 0xff0000) >> 16)
|
||||
# define CONVERT_TINT_GREEN(t) (((t) & 0x00ff00) >> 8)
|
||||
# define CONVERT_TINT_BLUE(t) ((t) & 0x0000ff)
|
||||
# define IMLIB_FREE_PIXMAP(p) do {D_PIXMAP(("Freeing pixmap: imlib_free_pixmap_and_mask(0x%08x)\n", (p))); imlib_free_pixmap_and_mask(p);} while (0)
|
||||
# define IMLIB_FREE_PIXMAP(p) do {D_PIXMAP(("libmej_freeing pixmap: imlib_free_pixmap_and_mask(0x%08x)\n", (p))); imlib_free_pixmap_and_mask(p);} while (0)
|
||||
#else
|
||||
# define background_is_image() (0)
|
||||
# define background_is_trans() (0)
|
||||
|
@ -75,8 +75,8 @@ typedef void *Imlib_Color_Modifier;
|
|||
# define X_CREATE_PIXMAP(w, h) (XCreatePixmap(Xdisplay, TermWin.parent, (w), (h), Xdepth))
|
||||
# define X_CREATE_GC(flags, gcv) (XCreateGC(Xdisplay, TermWin.parent, (flags), (gcv)))
|
||||
#endif
|
||||
#define X_FREE_PIXMAP(p) do {D_PIXMAP(("Freeing pixmap: XFreePixmap(Xdisplay, 0x%08x)\n", (p))); XFreePixmap(Xdisplay, (p));} while (0)
|
||||
#define X_FREE_GC(gc) do {D_PIXMAP(("Freeing GC: XFreeGC(Xdisplay, 0x%08x)\n", (gc))); XFreeGC(Xdisplay, (gc));} while (0)
|
||||
#define X_FREE_PIXMAP(p) do {D_PIXMAP(("libmej_freeing pixmap: XFreePixmap(Xdisplay, 0x%08x)\n", (p))); XFreePixmap(Xdisplay, (p));} while (0)
|
||||
#define X_FREE_GC(gc) do {D_PIXMAP(("libmej_freeing GC: XFreeGC(Xdisplay, 0x%08x)\n", (gc))); XFreeGC(Xdisplay, (gc));} while (0)
|
||||
#define PIXMAP_EXT NULL
|
||||
|
||||
#define GEOM_LEN 19
|
||||
|
|
|
@ -30,12 +30,8 @@ static const char cvs_ident[] = "$Id$";
|
|||
# include <X11/Xmu/Atoms.h>
|
||||
#endif
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "buttons.h"
|
||||
#include "command.h"
|
||||
#include "debug.h"
|
||||
#include "font.h"
|
||||
#include "startup.h"
|
||||
#include "screen.h"
|
||||
|
@ -2157,7 +2153,7 @@ scr_search_scrollback(char *str)
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
last_str = StrDup(str);
|
||||
last_str = STRDUP(str);
|
||||
}
|
||||
lrow = rows = TermWin.nrow + TermWin.saveLines;
|
||||
cols = TermWin.ncol;
|
||||
|
@ -2670,7 +2666,7 @@ selection_make(Time tm)
|
|||
|
||||
XSetSelectionOwner(Xdisplay, XA_PRIMARY, TermWin.vt, tm);
|
||||
if (XGetSelectionOwner(Xdisplay, XA_PRIMARY) != TermWin.vt)
|
||||
print_error("can't get primary selection");
|
||||
print_error("can't get primary selection\n");
|
||||
XChangeProperty(Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8,
|
||||
PropModeReplace, selection.text, selection.len);
|
||||
D_SELECT(("selection.len=%d\n", selection.len));
|
||||
|
|
|
@ -28,9 +28,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
|
||||
#include <X11/cursorfont.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "debug.h"
|
||||
#include "buttons.h"
|
||||
#include "command.h"
|
||||
#include "draw.h"
|
||||
|
@ -880,7 +877,7 @@ scrollbar_drawing_init(void) {
|
|||
#ifdef XTERM_SCROLLBAR
|
||||
gcvalue.stipple = XCreateBitmapFromData(Xdisplay, scrollbar.win, (char *) xterm_sb_bits, 12, 2);
|
||||
if (!gcvalue.stipple) {
|
||||
print_error("Unable to create xterm scrollbar bitmap.");
|
||||
print_error("Unable to create xterm scrollbar bitmap.\n\n");
|
||||
if (scrollbar_get_type() == SCROLLBAR_XTERM) {
|
||||
scrollbar_set_type(SCROLLBAR_MOTIF);
|
||||
}
|
||||
|
|
|
@ -40,10 +40,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include <X11/Xatom.h>
|
||||
#include <X11/Xos.h>
|
||||
|
||||
#include "../libmej/debug.h" /* from libmej */
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "startup.h"
|
||||
#include "actions.h"
|
||||
#include "buttons.h"
|
||||
|
@ -68,7 +64,6 @@ short bg_needs_update = 1;
|
|||
TermWin_t TermWin;
|
||||
Display *Xdisplay; /* display */
|
||||
Colormap cmap;
|
||||
unsigned int debug_level = 0; /* Level of debugging information to display */
|
||||
const char *display_name = NULL;
|
||||
unsigned int colorfgbg;
|
||||
|
||||
|
@ -110,7 +105,7 @@ eterm_bootstrap(int argc, char *argv[])
|
|||
privileges(REVERT);
|
||||
#endif
|
||||
if (!Xdisplay) {
|
||||
print_error("can't open display %s", display_name);
|
||||
print_error("can't open display %s\n", display_name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
XSetErrorHandler((XErrorHandler) xerror_handler);
|
||||
|
@ -217,7 +212,7 @@ eterm_bootstrap(int argc, char *argv[])
|
|||
}
|
||||
|
||||
#if DEBUG >= DEBUG_X
|
||||
if (debug_level >= DEBUG_X) {
|
||||
if (DEBUG_LEVEL >= DEBUG_X) {
|
||||
XSync(Xdisplay, False);
|
||||
XSynchronize(Xdisplay, True);
|
||||
}
|
||||
|
|
|
@ -36,13 +36,11 @@ static const char cvs_ident[] = "$Id$";
|
|||
# include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "debug.h"
|
||||
#include "command.h"
|
||||
#include "misc.h"
|
||||
#include "system.h"
|
||||
|
||||
/*static sighandler_t old_handler = (sighandler_t) NULL;*/
|
||||
/*static eterm_sighandler_t old_handler = (eterm_sighandler_t) NULL;*/
|
||||
|
||||
int
|
||||
wait_for_chld(int system_pid)
|
||||
|
@ -94,7 +92,7 @@ system_wait(char *command)
|
|||
setreuid(my_ruid, my_ruid);
|
||||
setregid(my_rgid, my_rgid);
|
||||
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
|
||||
print_error("execl(%s) failed -- %s", command, strerror(errno));
|
||||
print_error("execl(%s) failed -- %s\n", command, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
D_OPTIONS(("%d: fork() returned %d\n", getpid(), pid));
|
||||
|
@ -114,7 +112,7 @@ system_no_wait(char *command)
|
|||
setreuid(my_ruid, my_ruid);
|
||||
setregid(my_rgid, my_rgid);
|
||||
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
|
||||
print_error("execl(%s) failed -- %s", command, strerror(errno));
|
||||
print_error("execl(%s) failed -- %s\n", command, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return (0);
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
# define system(c) system_no_wait((c))
|
||||
#endif
|
||||
|
||||
typedef RETSIGTYPE (*sighandler_t)(int);
|
||||
typedef RETSIGTYPE (*eterm_sighandler_t)(int);
|
||||
|
||||
extern int wait_for_chld(int);
|
||||
extern int system_wait(char *);
|
||||
|
|
30
src/term.c
30
src/term.c
|
@ -31,10 +31,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "actions.h"
|
||||
#include "buttons.h"
|
||||
#include "command.h"
|
||||
|
@ -181,7 +177,7 @@ get_modifiers(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* To handle buffer overflows properly, we must malloc a buffer. Free it when done. */
|
||||
/* To handle buffer overflows properly, we must malloc a buffer. libmej_free it when done. */
|
||||
#ifdef USE_XIM
|
||||
# define LK_RET() do {if (kbuf_alloced) FREE(kbuf); return;} while (0)
|
||||
#else
|
||||
|
@ -359,7 +355,7 @@ lookup_key(XEvent * ev)
|
|||
switch (keysym) {
|
||||
case XK_Print: /* Print the screen contents out to the print pipe */
|
||||
#if DEBUG >= DEBUG_SELECTION
|
||||
if (debug_level >= DEBUG_SELECTION) {
|
||||
if (DEBUG_LEVEL >= DEBUG_SELECTION) {
|
||||
debug_selection();
|
||||
}
|
||||
#endif
|
||||
|
@ -770,11 +766,11 @@ popen_printer(void)
|
|||
FILE *stream;
|
||||
|
||||
if (((my_ruid != my_euid) || (my_rgid != my_egid)) && (strcmp(rs_print_pipe, PRINTPIPE))) {
|
||||
print_warning("Running setuid/setgid. Refusing to use custom printpipe.");
|
||||
RESET_AND_ASSIGN(rs_print_pipe, StrDup(PRINTPIPE));
|
||||
print_warning("Running setuid/setgid. Refusing to use custom printpipe.\n");
|
||||
RESET_AND_ASSIGN(rs_print_pipe, STRDUP(PRINTPIPE));
|
||||
}
|
||||
if ((stream = (FILE *) popen(rs_print_pipe, "w")) == NULL) {
|
||||
print_error("Can't open printer pipe \"%s\" -- %s", rs_print_pipe, strerror(errno));
|
||||
print_error("Can't open printer pipe \"%s\" -- %s\n", rs_print_pipe, strerror(errno));
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
@ -1646,7 +1642,7 @@ set_title(const char *str)
|
|||
}
|
||||
D_X11(("Setting window title to \"%s\"\n", str));
|
||||
XStoreName(Xdisplay, TermWin.parent, str);
|
||||
name = StrDup(str);
|
||||
name = STRDUP(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1662,7 +1658,7 @@ set_icon_name(const char *str)
|
|||
}
|
||||
D_X11(("Setting window icon name to \"%s\"\n", str));
|
||||
XSetIconName(Xdisplay, TermWin.parent, str);
|
||||
name = StrDup(str);
|
||||
name = STRDUP(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1733,7 +1729,7 @@ xterm_seq(int op, const char *str)
|
|||
return;
|
||||
|
||||
#ifdef PIXMAP_SUPPORT
|
||||
orig_tnstr = tnstr = StrDup(str);
|
||||
orig_tnstr = tnstr = STRDUP(str);
|
||||
#endif
|
||||
|
||||
switch (op) {
|
||||
|
@ -2104,22 +2100,22 @@ xterm_seq(int op, const char *str)
|
|||
#ifdef XTERM_SCROLLBAR
|
||||
scrollbar_change_type(SCROLLBAR_XTERM);
|
||||
#else
|
||||
print_error("Support for xterm scrollbars was not compiled in. Sorry.");
|
||||
print_error("Support for xterm scrollbars was not compiled in. Sorry.\n");
|
||||
#endif
|
||||
} else if (!strcasecmp(nstr, "next")) {
|
||||
#ifdef NEXT_SCROLLBAR
|
||||
scrollbar_change_type(SCROLLBAR_NEXT);
|
||||
#else
|
||||
print_error("Support for NeXT scrollbars was not compiled in. Sorry.");
|
||||
print_error("Support for NeXT scrollbars was not compiled in. Sorry.\n");
|
||||
#endif
|
||||
} else if (!strcasecmp(nstr, "motif")) {
|
||||
#ifdef MOTIF_SCROLLBAR
|
||||
scrollbar_change_type(SCROLLBAR_MOTIF);
|
||||
#else
|
||||
print_error("Support for motif scrollbars was not compiled in. Sorry.");
|
||||
print_error("Support for motif scrollbars was not compiled in. Sorry.\n");
|
||||
#endif
|
||||
} else {
|
||||
print_error("Unrecognized scrollbar type \"%s\".", nstr);
|
||||
print_error("Unrecognized scrollbar type \"%s\".\n", nstr);
|
||||
}
|
||||
}
|
||||
nstr = (char *) strsep(&tnstr, ";");
|
||||
|
@ -2267,7 +2263,7 @@ xterm_seq(int op, const char *str)
|
|||
/* Set debugging level */
|
||||
nstr = (char *) strsep(&tnstr, ";");
|
||||
if (nstr && *nstr) {
|
||||
debug_level = (unsigned int) strtoul(nstr, (char **) NULL, 0);
|
||||
DEBUG_LEVEL = (unsigned int) strtoul(nstr, (char **) NULL, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -31,11 +31,7 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "startup.h"
|
||||
#include "mem.h"
|
||||
#include "command.h"
|
||||
#include "events.h"
|
||||
#include "options.h"
|
||||
|
|
26
src/utmp.c
26
src/utmp.c
|
@ -68,13 +68,11 @@ static const char cvs_ident[] = "$Id$";
|
|||
# ifdef HAVE_LASTLOG_H
|
||||
# include <lastlog.h>
|
||||
# endif
|
||||
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
|
||||
# if defined(__libmej_freeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
|
||||
# include <ttyent.h>
|
||||
# endif
|
||||
|
||||
# include "eterm_utmp.h"
|
||||
# include "debug.h"
|
||||
# include "../libmej/debug.h"
|
||||
# include "command.h"
|
||||
# include "screen.h"
|
||||
|
||||
|
@ -85,7 +83,7 @@ static const char cvs_ident[] = "$Id$";
|
|||
|
||||
/* don't go off end of ut_id & remember if an entry has been made */
|
||||
# ifndef HAVE_UTEMPTER
|
||||
# if defined(USE_SYSV_UTMP) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
|
||||
# if defined(USE_SYSV_UTMP) || defined(__libmej_freeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
|
||||
static char ut_id[5]; /* remember if entry to utmp made */
|
||||
# else
|
||||
static int utmp_pos; /* BSD position of utmp-stamp */
|
||||
|
@ -170,7 +168,7 @@ add_utmp_entry(const char *pty, const char *hostname, int fd)
|
|||
if (sscanf(pty, "pts/%d", &n) == 1)
|
||||
sprintf(ut_id, "vt%02x", n); /* sysv naming */
|
||||
else {
|
||||
print_error("can't parse tty name \"%s\"", pty);
|
||||
print_error("can't parse tty name \"%s\"\n", pty);
|
||||
ut_id[0] = '\0'; /* entry not made */
|
||||
return;
|
||||
}
|
||||
|
@ -276,7 +274,7 @@ remove_utmp_entry(void)
|
|||
# else /* USE_SYSV_UTMP */
|
||||
/* BSD utmp support */
|
||||
|
||||
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
|
||||
# if defined(__libmej_freeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
|
||||
|
||||
/* used to hold the line we are using */
|
||||
static char ut_line[32];
|
||||
|
@ -324,7 +322,7 @@ b_login(struct utmp *ut)
|
|||
}
|
||||
}
|
||||
|
||||
# else /* __FreeBSD__ || NetBSD || BSDI */
|
||||
# else /* __libmej_freeBSD__ || NetBSD || BSDI */
|
||||
static int utmp_pos = 0; /* position of utmp-stamp */
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
|
@ -382,7 +380,7 @@ write_utmp(struct utmp *putmp)
|
|||
return rval;
|
||||
}
|
||||
|
||||
# endif /* __FreeBSD__ || NetBSD || BSDI */
|
||||
# endif /* __libmej_freeBSD__ || NetBSD || BSDI */
|
||||
|
||||
void
|
||||
add_utmp_entry(const char *pty, const char *hostname, int fd)
|
||||
|
@ -397,12 +395,12 @@ add_utmp_entry(const char *pty, const char *hostname, int fd)
|
|||
if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3))
|
||||
strncpy(ut_id, (pty + 3), sizeof(ut_id)); /* bsd naming */
|
||||
else {
|
||||
print_error("can't parse tty name \"%s\"", pty);
|
||||
print_error("can't parse tty name \"%s\"\n", pty);
|
||||
ut_id[0] = '\0'; /* entry not made */
|
||||
return;
|
||||
}
|
||||
|
||||
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
|
||||
# if defined(__libmej_freeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
|
||||
strncpy(ut_line, pty, 31);
|
||||
|
||||
strncpy(utmp.ut_line, pty, UT_LINESIZE);
|
||||
|
@ -411,7 +409,7 @@ add_utmp_entry(const char *pty, const char *hostname, int fd)
|
|||
utmp.ut_time = time(NULL);
|
||||
|
||||
b_login(&utmp);
|
||||
# else /* __FreeBSD__ || NetBSD || BSDI */
|
||||
# else /* __libmej_freeBSD__ || NetBSD || BSDI */
|
||||
strncpy(utmp.ut_line, ut_id, sizeof(utmp.ut_line));
|
||||
strncpy(utmp.ut_name, pwent->pw_name, sizeof(utmp.ut_name));
|
||||
strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
|
||||
|
@ -430,10 +428,10 @@ add_utmp_entry(const char *pty, const char *hostname, int fd)
|
|||
void
|
||||
remove_utmp_entry(void)
|
||||
{
|
||||
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
|
||||
# if defined(__libmej_freeBSD__) || defined(__NetBSD__) || defined(__bsdi__)
|
||||
logout(ut_line);
|
||||
logwtmp(ut_line, "", "");
|
||||
# else /* __FreeBSD__ */
|
||||
# else /* __libmej_freeBSD__ */
|
||||
FILE *fd;
|
||||
|
||||
privileges(INVOKE);
|
||||
|
@ -447,7 +445,7 @@ remove_utmp_entry(void)
|
|||
fclose(fd);
|
||||
}
|
||||
privileges(REVERT);
|
||||
# endif /* __FreeBSD__ || NetBSD || BSDI */
|
||||
# endif /* __libmej_freeBSD__ || NetBSD || BSDI */
|
||||
}
|
||||
|
||||
# endif /* USE_SYSV_UTMP */
|
||||
|
|
|
@ -32,10 +32,6 @@ static const char cvs_ident[] = "$Id$";
|
|||
#include <limits.h>
|
||||
#include <X11/cursorfont.h>
|
||||
|
||||
#include "../libmej/debug.h"
|
||||
#include "../libmej/mem.h"
|
||||
#include "../libmej/strings.h"
|
||||
#include "debug.h"
|
||||
#include "buttons.h"
|
||||
#include "command.h"
|
||||
#include "e.h"
|
||||
|
@ -101,7 +97,7 @@ get_tint_by_color_name(const char *color)
|
|||
|
||||
D_PIXMAP(("Tint string is \"%s\", white color is rgbi:%d/%d/%d\n", color, wcol.red, wcol.green, wcol.blue));
|
||||
if (!XParseColor(Xdisplay, Xcmap, color, &xcol)) {
|
||||
print_error("Unable to parse tint color \"%s\". Ignoring.", color);
|
||||
print_error("Unable to parse tint color \"%s\". Ignoring.\n", color);
|
||||
return 0xffffff;
|
||||
}
|
||||
|
||||
|
@ -146,7 +142,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.", 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);
|
||||
|
@ -178,7 +174,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.", 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);
|
||||
|
@ -197,11 +193,11 @@ get_color_by_name(const char *name, const char *fallback)
|
|||
}
|
||||
}
|
||||
if (!XParseColor(Xdisplay, cmap, name, &xcol)) {
|
||||
print_warning("Unable to resolve \"%s\" as a color name. Falling back on \"%s\".", name, NONULL(fallback));
|
||||
print_warning("Unable to resolve \"%s\" as a color name. Falling back on \"%s\".\n", name, NONULL(fallback));
|
||||
name = fallback;
|
||||
if (name) {
|
||||
if (!XParseColor(Xdisplay, cmap, name, &xcol)) {
|
||||
print_warning("Unable to resolve \"%s\" as a color name. This should never fail. Please repair/restore your RGB database.", 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 {
|
||||
|
@ -209,12 +205,12 @@ get_color_by_name(const char *name, const char *fallback)
|
|||
}
|
||||
}
|
||||
if (!XAllocColor(Xdisplay, cmap, &xcol)) {
|
||||
print_warning("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map. Falling back on \"%s\".",
|
||||
print_warning("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map. Falling back on \"%s\".\n",
|
||||
name, xcol.pixel, xcol.red, xcol.green, xcol.blue, NONULL(fallback));
|
||||
name = fallback;
|
||||
if (name) {
|
||||
if (!XAllocColor(Xdisplay, cmap, &xcol)) {
|
||||
print_warning("Unable to allocate \"%s\" (0x%08x: 0x%04x, 0x%04x, 0x%04x) in the color map.", 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 {
|
||||
|
@ -231,18 +227,18 @@ get_color_by_pixel(Pixel pixel, Pixel fallback)
|
|||
|
||||
xcol.pixel = pixel;
|
||||
if (!XQueryColor(Xdisplay, cmap, &xcol)) {
|
||||
print_warning("Unable to convert pixel value 0x%08x to an XColor structure. Falling back on 0x%08x.", pixel, fallback);
|
||||
print_warning("Unable to convert pixel value 0x%08x to an XColor structure. Falling back on 0x%08x.\n", pixel, fallback);
|
||||
xcol.pixel = fallback;
|
||||
if (!XQueryColor(Xdisplay, cmap, &xcol)) {
|
||||
print_warning("Unable to convert pixel value 0x%08x to an XColor structure.", xcol.pixel);
|
||||
print_warning("Unable to convert pixel value 0x%08x to an XColor structure.\n", xcol.pixel);
|
||||
return ((Pixel) 0);
|
||||
}
|
||||
}
|
||||
if (!XAllocColor(Xdisplay, cmap, &xcol)) {
|
||||
print_warning("Unable to allocate 0x%08x (0x%04x, 0x%04x, 0x%04x) in the color map. Falling back on 0x%08x.", 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.", 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);
|
||||
}
|
||||
}
|
||||
|
@ -323,7 +319,7 @@ Create_Windows(int argc, char *argv[])
|
|||
if (Options & Opt_borderless) {
|
||||
prop = XInternAtom(Xdisplay, "_MOTIF_WM_HINTS", True);
|
||||
if (prop == None) {
|
||||
print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.");
|
||||
print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n");
|
||||
Attributes.override_redirect = TRUE;
|
||||
mwmhints.flags = 0;
|
||||
} else {
|
||||
|
@ -663,17 +659,17 @@ set_window_color(int idx, const char *color)
|
|||
if (i >= 0 && i <= 7) { /* normal colors */
|
||||
PixColors[idx] = PixColors[minColor + i];
|
||||
} else {
|
||||
print_warning("Color index %d is invalid.", i);
|
||||
print_warning("Color index %d is invalid.\n", i);
|
||||
return;
|
||||
}
|
||||
} else if (XParseColor(Xdisplay, cmap, color, &xcol)) {
|
||||
if (!XAllocColor(Xdisplay, cmap, &xcol)) {
|
||||
print_warning("Unable to allocate \"%s\" in the color map.", color);
|
||||
print_warning("Unable to allocate \"%s\" in the color map.\n", color);
|
||||
return;
|
||||
}
|
||||
PixColors[idx] = xcol.pixel;
|
||||
} else {
|
||||
print_warning("Unable to resolve \"%s\" as a color name.", color);
|
||||
print_warning("Unable to resolve \"%s\" as a color name.\n", color);
|
||||
return;
|
||||
}
|
||||
redraw_image(image_bg);
|
||||
|
|
Loading…
Reference in New Issue