known bugs in abook
-* in X terminals keyboard may not behave as expected - this is probably
+* with certain terminals keyboard may not behave as expected - this is probably
a ncurses problem
* incompatible with some terminals
- - there seems to be some problems with some gnome-terminal versions -
+ - there seems to be problems with some (old?) gnome-terminal versions -
gnome-terminal bug?
* some keys may cause readline to crash - this is a readline (4.3) problem
- - there is a fix available:
+ - there is a fix available for readline:
ftp://ftp.gnu.org/gnu/readline/readline-4.3-patches/readline43-001
+* cursor disappears in some cases with abook_readline() on Solaris. If
+ you have problems it is recommended to use the ncurses library
+
+* terminal state is not restored correctly on exit with certain ncurses and
+ readline combination (more information is needed on this)
+
+* file format is not tolerant for character set changes
+
+Filters:
* mutt / elm / pine export filters allow to create a file with duplicate
aliases
-misc:
-* Cursor disappears in some cases with abook_readline() on Solaris. If
- you have problems it is recommended to use ncurses library
-* fseek in ldif import filter should be eliminated
* mutt import filter imports only first e-mail address
+
+* fseek in ldif import filter should be eliminated
+
+$Id: BUGS,v 1.16 2005/08/29 10:02:50 jheinonen Exp $
+0.5.4
+ - add show_cursor config option (idea from Cheryl Homiak)
+ - autoconf/automake update
+ - replace abook_malloc, abook_realloc and my_free with new xmalloc routines
+ - replace strdup with xstrdup
+ - update for abook_rl (abook_readline)
+ - make it compile with tcc (Tiny C Compiler)
+ - code cleanups and minor fixes
+
0.5.3
- add allcvs filters (Christoph Sobotka)
- removed a lefover debug message
Q: Can I add addresses to the abook addressbook from mutt?
-A: Yes, it is possible starting from abook 0.4.15. See --add-email
+A: Yes, it is possible starting from abook version 0.4.15. See --add-email
command line option and README.
Q: Can I use abook in UTF-8 terminal emulator?
-A: Yes, version 0.5.2 added multibyte character support.
+A: Yes, the version 0.5.2 added a multibyte character support.
There are currently some issues:
you use UTF-8 charset the input is expected to be UTF-8 encoded.
-last update: $Date: 2004/02/18 19:48:46 $
+last update: $Date: 2005/02/28 09:21:31 $
abook_SOURCES = abook.c database.c filter.c list.c misc.c \
options.c edit.c ldif.c ui.c getname.c \
getopt.c getopt1.c abook_rl.c mbswidth.c \
+ xmalloc.c \
abook.h database.h filter.h list.h misc.h help.h \
options.h edit.h ldif.h abook_curses.h ui.h getname.h \
- getopt.h abook_rl.h mbswidth.h
+ getopt.h abook_rl.h mbswidth.h \
+ xmalloc.h
EXTRA_DIST = ANNOUNCE BUGS FAQ abook.1 abookrc.5 sample.abookrc abook.spec \
contrib
-# Makefile.in generated by automake 1.8.5 from Makefile.am.
+# Makefile.in generated by automake 1.9.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
+build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = abook$(EXEEXT)
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
am_abook_OBJECTS = abook.$(OBJEXT) database.$(OBJEXT) filter.$(OBJEXT) \
list.$(OBJEXT) misc.$(OBJEXT) options.$(OBJEXT) edit.$(OBJEXT) \
ldif.$(OBJEXT) ui.$(OBJEXT) getname.$(OBJEXT) getopt.$(OBJEXT) \
- getopt1.$(OBJEXT) abook_rl.$(OBJEXT) mbswidth.$(OBJEXT)
+ getopt1.$(OBJEXT) abook_rl.$(OBJEXT) mbswidth.$(OBJEXT) \
+ xmalloc.$(OBJEXT)
abook_OBJECTS = $(am_abook_OBJECTS)
abook_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/abook.Po ./$(DEPDIR)/abook_rl.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/database.Po ./$(DEPDIR)/edit.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/filter.Po ./$(DEPDIR)/getname.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/getopt.Po ./$(DEPDIR)/getopt1.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/ldif.Po ./$(DEPDIR)/list.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/mbswidth.Po ./$(DEPDIR)/misc.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/options.Po ./$(DEPDIR)/ui.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
abook_SOURCES = abook.c database.c filter.c list.c misc.c \
options.c edit.c ldif.c ui.c getname.c \
getopt.c getopt1.c abook_rl.c mbswidth.c \
+ xmalloc.c \
abook.h database.h filter.h list.h misc.h help.h \
options.h edit.h ldif.h abook_curses.h ui.h getname.h \
- getopt.h abook_rl.h mbswidth.h
+ getopt.h abook_rl.h mbswidth.h \
+ xmalloc.h
EXTRA_DIST = ANNOUNCE BUGS FAQ abook.1 abookrc.5 sample.abookrc abook.spec \
contrib
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmalloc.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
uninstall-info-am:
! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \
|| chmod -R a+r $(distdir)
dist-gzip: distdir
- $(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+ tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
dist-bzip2: distdir
- $(AMTAR) chof - $(distdir) | bzip2 -9 -c >$(distdir).tar.bz2
+ tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
$(am__remove_distdir)
dist-tarZ: distdir
- $(AMTAR) chof - $(distdir) | compress -c >$(distdir).tar.Z
+ tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
$(am__remove_distdir)
dist-shar: distdir
$(am__remove_distdir)
dist dist-all: distdir
- $(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+ tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
# This target untars the dist file and tries a VPATH configuration. Then
distcheck: dist
case '$(DIST_ARCHIVES)' in \
*.tar.gz*) \
- GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf - ;;\
+ GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\
*.tar.bz2*) \
- bunzip2 -c $(distdir).tar.bz2 | $(AMTAR) xf - ;;\
+ bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\
*.tar.Z*) \
- uncompress -c $(distdir).tar.Z | $(AMTAR) xf - ;;\
+ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
*.shar.gz*) \
GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
*.zip*) \
clean-generic:
distclean-generic:
- -rm -f $(CONFIG_CLEAN_FILES)
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
Brian Medley
Takahashi Tamotsu
Liam K Morland
+Cheryl Homiak
+Christoph Sobotka
+Morten Brix Pedersen
+Jeff Covey
+Giuseppe Corbelli
+Mariusz Balewski
See also AUTHORS
/*
- * $Id: abook.c,v 1.42 2004/06/30 19:47:42 jheinonen Exp $
+ * $Id: abook.c,v 1.50 2005/08/13 10:49:25 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
* Copyright (C) Jaakko Heinonen
*/
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
#include <stdio.h>
-#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <sys/stat.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
# include <locale.h>
#endif
+#include <assert.h>
#include "abook.h"
#include "ui.h"
#include "database.h"
#include "options.h"
#include "getname.h"
#include "getopt.h"
-#include <assert.h>
+#include "xmalloc.h"
static void init_abook();
static void quit_abook_sig(int i);
static void add_email(int);
char *datafile = NULL;
-char *rcfile = NULL;
+static char *rcfile = NULL;
bool alternative_datafile = FALSE;
bool alternative_rcfile = FALSE;
if(errno != ENOENT) {
perror(dir);
free(dir);
- exit(1);
+ exit(EXIT_FAILURE);
}
if(mkdir(dir, 0700) == -1) {
printf("Cannot create directory %s\n", dir);
perror(dir);
free(dir);
- exit(1);
+ exit(EXIT_FAILURE);
}
} else if(!S_ISDIR(s.st_mode)) {
printf("%s is not a directory\n", dir);
free(dir);
- exit(1);
+ exit(EXIT_FAILURE);
}
free(dir);
}
+static void
+xmalloc_error_handler(int err)
+{
+ /*
+ * We don't try to save addressbook here because we don't know
+ * if it's fully loaded to memory.
+ */
+ if(is_ui_initialized())
+ close_ui();
+
+ fprintf(stderr, "Memory allocation failure: %s\n", strerror(err));
+ exit(EXIT_FAILURE);
+}
+
static void
init_abook()
{
fgetc(stdin);
}
- signal(SIGKILL, quit_abook_sig);
signal(SIGTERM, quit_abook_sig);
- if( init_ui() )
- exit(1);
+ if(init_ui())
+ exit(EXIT_FAILURE);
umask(DEFAULT_UMASK);
free_opts();
/*close_database();*/
close_ui();
- exit(1);
+ exit(EXIT_FAILURE);
}
} else
load_database(datafile);
close_ui();
- exit(0);
+ exit(EXIT_SUCCESS);
}
static void
#if defined(HAVE_SETLOCALE) && defined(HAVE_LOCALE_H)
setlocale(LC_ALL, "");
#endif
+ xmalloc_set_error_handler(xmalloc_error_handler);
parse_command_line(argc, argv);
init_abook();
- get_commands();
+ get_commands();
quit_abook(QUIT_SAVE);
static void
free_filenames()
{
- my_free(rcfile);
- my_free(datafile);
+ xfree(rcfile);
+ xfree(datafile);
}
if( (stat(getenv("HOME"), &s)) == -1 || ! S_ISDIR(s.st_mode) ) {
fprintf(stderr,"%s is not a valid HOME directory\n", getenv("HOME") );
- exit(1);
+ exit(EXIT_FAILURE);
}
if(!datafile)
fprintf(stderr, "Cannot combine options --mutt-query, "
"--convert, "
"--add-email or --add-email-quiet\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
*current = mode;
assert(path != NULL);
if(*path == '/') {
- *var = strdup(path);
+ *var = xstrdup(path);
return;
}
#define set_convert_var(X) do { if(mode != MODE_CONVERT) {\
fprintf(stderr, "please use option --%s after --convert option\n",\
long_options[option_index].name);\
- exit(1);\
+ exit(EXIT_FAILURE);\
} else\
X = optarg;\
} while(0)
switch(c) {
case 'h':
show_usage();
- exit(1);
+ exit(EXIT_SUCCESS);
case OPT_ADD_EMAIL:
change_mode(&mode, MODE_ADD_EMAIL);
break;
break;
case OPT_FORMATS:
print_filters();
- exit(0);
+ exit(EXIT_SUCCESS);
default:
- exit(1);
+ exit(EXIT_FAILURE);
}
}
if (optind < argc) {
fprintf(stderr, "%s: unrecognized arguments on command line\n",
argv[0]);
- exit(1);
+ exit(EXIT_FAILURE);
}
switch(mode) {
{
puts (PACKAGE " v " VERSION "\n");
puts (" -h --help show usage");
- puts (" -C --config <file> use an alternative configuration file");
+ puts (" -C --config <file> use an alternative configuration file");
puts (" --datafile <file> use an alternative addressbook file");
puts (" --mutt-query <string> make a query for mutt");
puts (" --add-email "
int i;
if( (i = find_item(str, 0, search_fields)) < 0 ) {
printf("Not found\n");
- quit_mutt_query(1);
+ quit_mutt_query(EXIT_FAILURE);
}
putchar('\n');
while(i >= 0) {
}
}
- quit_mutt_query(0);
+ quit_mutt_query(EXIT_SUCCESS);
}
static void
if( load_database(datafile) ) {
printf("Cannot open database\n");
- quit_mutt_query(1);
- exit(1);
+ quit_mutt_query(EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
}
ret = *database[item][EMAIL] ?
mkstr("%s <%s>", name, email) :
- strdup(name);
+ xstrdup(name);
free(name);
#ifdef DEBUG
fprintf(stderr, "cmd: %s\n", cmd);
#endif
- system(cmd);
+ system(cmd);
free(cmd);
/*
ui_init_curses();
}
-void *
-abook_malloc(size_t size)
-{
- void *ptr;
-
- if ( (ptr = malloc(size)) == NULL ) {
- if( is_ui_initialized() )
- quit_abook(QUIT_SAVE);
- perror("malloc() failed");
- exit(1);
- }
-
- return ptr;
-}
-
-void *
-abook_realloc(void *ptr, size_t size)
-{
- ptr = realloc(ptr, size);
-
- if(size == 0)
- return NULL;
-
- if(ptr == NULL) {
- if(is_ui_initialized())
- quit_abook(QUIT_SAVE);
- perror("realloc() failed");
- exit(1);
- }
-
- return ptr;
-}
-
FILE *
abook_fopen (const char *path, const char *mode)
-{
+{
struct stat s;
bool stat_ok;
stat_ok = (stat(path, &s) != -1);
-
+
if(strchr(mode, 'r'))
return (stat_ok && S_ISREG(s.st_mode)) ?
fopen(path, mode) : NULL;
if( !strcasecmp(srcformat, dstformat) ) {
printf( "input and output formats are the same\n"
"exiting...\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
#endif
if(add_email_count > 0) {
if(save_database() < 0) {
fprintf(stderr, "cannot open %s\n", datafile);
- exit(1);
+ exit(EXIT_FAILURE);
}
printf("%d item(s) added to %s\n", add_email_count, datafile);
} else {
puts("Valid sender address not found");
}
- exit(0);
+ exit(EXIT_SUCCESS);
}
static void
init_add_email()
{
set_filenames();
- atexit(free_filenames);
check_abook_directory();
init_opts();
load_opts(rcfile);
return 0;
}
}
-
+
if(!quiet) {
FILE *in = fopen("/dev/tty", "r");
char c;
if(!in) {
fprintf(stderr, "cannot open /dev/tty\n"
"you may want to use --add-email-quiet\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
do {
}
memset(item, 0, sizeof(item));
- item[NAME] = strdup(name);
- item[EMAIL] = strdup(email);
+ item[NAME] = xstrdup(name);
+ item[EMAIL] = xstrdup(email);
add_item2database(item);
return 1;
if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode) ) {
fprintf(stderr, "stdin is a directory or cannot stat stdin\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
init_add_email();
getname(line, &name, &email);
add_email_count += add_email_add_item(quiet,
name, email);
- my_free(name);
- my_free(email);
+ xfree(name);
+ xfree(email);
}
- my_free(line);
+ xfree(line);
} while( !feof(stdin) );
quit_add_email();
#include <stdio.h>
-void *abook_malloc(size_t size);
-void *abook_realloc(void *ptr, size_t size);
FILE *abook_fopen (const char *path, const char *mode);
void quit_abook(int save_db);
void launch_wwwbrowser(int item);
#define Y_STATUSLINE (LINES - 2)
-#define MIN_LINES 20
-#define MIN_COLS 70
+#define MIN_LINES 20
+#define MIN_COLS 70
#define DEFAULT_UMASK 066
#define DIR_IN_HOME ".abook"
#define show_cursor() curs_set(1)
#define safe_atoi(X) ((X == NULL) ? 0 : atoi(X))
-#define my_free(X) do {free(X); X=NULL;} while(0)
#define safe_str(X) ((X == NULL) ? "" : X)
-#define safe_strdup(X) ((X == NULL) ? NULL : strdup(X))
#ifndef min
# define min(x,y) (((x)<(y)) ? (x):(y))
Summary: Text-based addressbook program
Name: abook
-Version: 0.5.3
+Version: 0.5.4
Release: 1
Copyright: GPL
Group: Utilities
Source: http://prdownloads.sourceforge.net/abook/%{name}-%{version}.tar.gz
URL: http://abook.sourceforge.net/
BuildPreReq: ncurses-devel readline-devel
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%description
Source: http://prdownloads.sourceforge.net/abook/%{name}-%{version}.tar.gz
URL: http://abook.sourceforge.net/
BuildPreReq: ncurses-devel readline-devel
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%description
/*
- * $Id: abook_rl.c,v 1.11 2004/02/18 19:41:37 jheinonen Exp $
+ * $Id: abook_rl.c,v 1.15 2005/08/08 05:13:51 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
#include "abook.h"
#include "abook_rl.h"
-#define KEYPAD_HACK 1 /* enable keypad hack */
-#define CBREAK_HACK 1 /* enable cbreak hack */
-
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
# include <readline/readline.h>
#elif defined(HAVE_READLINE_H)
# include <readline.h>
+#else
+# error "You don't seem to have readline.h"
+# error "No HAVE_READLINE_READLINE_H or HAVE_READLINE_H defined"
#endif
#if defined(HAVE_READLINE_HISTORY_H)
# include <readline/history.h>
#elif defined(HAVE_HISTORY_H)
# include <history.h>
+#else
+# error "You don't seem to have history.h"
+# error "No HAVE_READLINE_HISTORY_H or HAVE_HISTORY_H defined"
#endif
#ifdef HANDLE_MULTIBYTE
static void
rl_refresh()
{
- /*refresh();*/
+ /* refresh(); */
wrefresh(rl_win);
}
static void
rline_update()
-{
+{
#ifdef HANDLE_MULTIBYTE
int real_point = rline_calc_point() + rl_x;
#else
int real_point = rl_point + rl_x;
#endif
-
+
if(real_point > (COLS - 1))
mvwaddnstr(rl_win, rl_y, rl_x,
rl_line_buffer + (1 + real_point - COLS),
/* dummy */
}
+static void
+rline_prep_terminal(int dummy)
+{
+#if (RL_VERSION_MAJOR == 4 && RL_VERSION_MINOR > 2) || (RL_VERSION_MAJOR > 4)
+ /* nothing */
+#else
+ /*
+ * #warning is an extension. Not all compilers support it.
+ */
+# ifdef __GNUC__
+# warning "You seem to have rather old readline version or \
+non-GNU version of it. If you have problems please use \
+GNU readline 4.3 or newer. \
+GNU readline versions 4.0, 4.1 and 4.2 should be OK despite \
+of this warning."
+# endif
+ /*
+ * this kludge avoids older readline libraries to print a newline
+ */
+ extern int readline_echoing_p;
+ readline_echoing_p = 0;
+#endif
+ raw();
+ keypad(rl_win, FALSE);
+}
+
+static void
+rline_deprep_terminal(void)
+{
+ cbreak();
+ keypad(rl_win, TRUE);
+}
+
static int
rl_cancel(int dummy1, int dummy2)
{
abook_rl_init(bool use_completion)
{
rl_readline_name = RL_READLINE_NAME;
-
+
#if RL_VERSION_MAJOR >= 4
rl_already_prompted = 1;
#endif
rl_catch_sigwinch = 0;
-
+ rl_erase_empty_line = 0;
+
rl_redisplay_function = rline_update;
rl_completion_display_matches_hook = rline_compdisp;
+ rl_prep_term_function = rline_prep_terminal;
+ rl_deprep_term_function = rline_deprep_terminal;
rl_unbind_function_in_map(rl_clear_screen, rl_get_keymap());
rl_unbind_function_in_map(rl_reverse_search_history, rl_get_keymap());
rl_unbind_function_in_map(rl_re_read_init_file, rl_get_keymap());
-
+
if(use_completion) {
rl_bind_key('\t', rl_menu_complete);
} else {
clear_history();
rl_cancelled = FALSE;
-}
+}
char *
abook_readline(WINDOW *w, int y, int x, char *s, int limit, bool use_completion)
if(s && *s)
add_history(s);
-
-#ifdef KEYPAD_HACK
- keypad(w, FALSE);
-#endif
-#ifdef CBREAK_HACK
- nocbreak();
-#endif
+
ret = readline(NULL);
-#ifdef CBREAK_HACK
- cbreak();
-#endif
-#ifdef KEYPAD_HACK
- keypad(w, TRUE);
-#endif
if(rl_cancelled && ret) {
free(ret);
\fBsort_field\fP=field
Defines the field to be used by the "sort by field" command. Default is "nick" (Nickname/Alias).
+.TP
+\fBshow_cursor\fP=[true|false]
+Defines if the cursor is visible in main display. Default is false.
+
.SH SAMPLE CONFIGURATION FILE
.nf
# field to be used with "sort by field" command
set sort_field=nick
+# show cursor in main display
+set show_cursor=false
+
.fi
.SH SEE ALSO
-# generated automatically by aclocal 1.8.5 -*- Autoconf -*-
+# generated automatically by aclocal 1.9.3 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
# Free Software Foundation, Inc.
# ----------------------------
# Automake X.Y traces this macro to ensure aclocal.m4 has been
# generated from the m4 files accompanying Automake X.Y.
-AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version="1.8"])
+AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version="1.9"])
# AM_SET_CURRENT_AUTOMAKE_VERSION
# -------------------------------
# Call AM_AUTOMAKE_VERSION so it can be traced.
# This function is AC_REQUIREd by AC_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
- [AM_AUTOMAKE_VERSION([1.8.5])])
+ [AM_AUTOMAKE_VERSION([1.9.3])])
# AM_AUX_DIR_EXPAND
# AM_CONDITIONAL -*- Autoconf -*-
-# Copyright (C) 1997, 2000, 2001, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1997, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
fi
AC_CONFIG_COMMANDS_PRE(
[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
- AC_MSG_ERROR([conditional "$1" was never defined.
-Usually this means the macro was only invoked conditionally.])
+ AC_MSG_ERROR([[conditional "$1" was never defined.
+Usually this means the macro was only invoked conditionally.]])
fi])])
# serial 7 -*- Autoconf -*-
# Generate code to set up dependency tracking. -*- Autoconf -*-
-# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
+# Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
else
continue
fi
- grep '^DEP_FILES *= *[[^ @%:@]]' < "$mf" > /dev/null || continue
- # Extract the definition of DEP_FILES from the Makefile without
- # running `make'.
+ # Extract the definition of DEPDIR, am__include, and am__quote
+ # from the Makefile without running `make'.
DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
test -z "$DEPDIR" && continue
+ am__include=`sed -n 's/^am__include = //p' < "$mf"`
+ test -z "am__include" && continue
+ am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
# When using ansi2knr, U may be empty or an underscore; expand it
U=`sed -n 's/^U = //p' < "$mf"`
- test -d "$dirpart/$DEPDIR" || mkdir "$dirpart/$DEPDIR"
- # We invoke sed twice because it is the simplest approach to
- # changing $(DEPDIR) to its actual value in the expansion.
- for file in `sed -n '
- /^DEP_FILES = .*\\\\$/ {
- s/^DEP_FILES = //
- :loop
- s/\\\\$//
- p
- n
- /\\\\$/ b loop
- p
- }
- /^DEP_FILES = / s/^DEP_FILES = //p' < "$mf" | \
+ # Find all dependency output files, they are included files with
+ # $(DEPDIR) in their names. We invoke sed twice because it is the
+ # simplest approach to changing $(DEPDIR) to its actual value in the
+ # expansion.
+ for file in `sed -n "
+ s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
# Make sure the directory exists.
test -f "$dirpart/$file" && continue
# This macro actually does too much some checks are only needed if
# your package does certain things. But this isn't really a big deal.
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
# Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
AM_MISSING_PROG(AUTOHEADER, autoheader)
AM_MISSING_PROG(MAKEINFO, makeinfo)
-AM_MISSING_PROG(AMTAR, tar)
AM_PROG_INSTALL_SH
AM_PROG_INSTALL_STRIP
AC_REQUIRE([AM_PROG_MKDIR_P])dnl
AC_REQUIRE([AC_PROG_AWK])dnl
AC_REQUIRE([AC_PROG_MAKE_SET])dnl
AC_REQUIRE([AM_SET_LEADING_DOT])dnl
-
+_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
+ [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+ [_AM_PROG_TAR([v7])])])
_AM_IF_OPTION([no-dependencies],,
[AC_PROVIDE_IFELSE([AC_PROG_CC],
[_AM_DEPENDENCIES(CC)],
# this.)
AC_DEFUN([AM_PROG_MKDIR_P],
[if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
- # Keeping the `.' argument allows $(mkdir_p) to be used without
- # argument. Indeed, we sometimes output rules like
+ # We used to keeping the `.' as first argument, in order to
+ # allow $(mkdir_p) to be used without argument. As in
# $(mkdir_p) $(somedir)
- # where $(somedir) is conditionally defined.
- # (`test -n '$(somedir)' && $(mkdir_p) $(somedir)' is a more
- # expensive solution, as it forces Make to start a sub-shell.)
- mkdir_p='mkdir -p -- .'
+ # where $(somedir) is conditionally defined. However this is wrong
+ # for two reasons:
+ # 1. if the package is installed by a user who cannot write `.'
+ # make install will fail,
+ # 2. the above comment should most certainly read
+ # $(mkdir_p) $(DESTDIR)$(somedir)
+ # so it does not work when $(somedir) is undefined and
+ # $(DESTDIR) is not.
+ # To support the latter case, we have to write
+ # test -z "$(somedir)" || $(mkdir_p) $(DESTDIR)$(somedir),
+ # so the `.' trick is pointless.
+ mkdir_p='mkdir -p --'
else
# On NextStep and OpenStep, the `mkdir' command does not
# recognize any option. It will interpret all options as
INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])
+# Check how to create a tarball. -*- Autoconf -*-
+
+# Copyright (C) 2004 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+# serial 1
+
+
+# _AM_PROG_TAR(FORMAT)
+# --------------------
+# Check how to create a tarball in format FORMAT.
+# FORMAT should be one of `v7', `ustar', or `pax'.
+#
+# Substitute a variable $(am__tar) that is a command
+# writing to stdout a FORMAT-tarball containing the directory
+# $tardir.
+# tardir=directory && $(am__tar) > result.tar
+#
+# Substitute a variable $(am__untar) that extract such
+# a tarball read from stdin.
+# $(am__untar) < result.tar
+AC_DEFUN([_AM_PROG_TAR],
+[# Always define AMTAR for backward compatibility.
+AM_MISSING_PROG([AMTAR], [tar])
+m4_if([$1], [v7],
+ [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+ [m4_case([$1], [ustar],, [pax],,
+ [m4_fatal([Unknown tar format])])
+AC_MSG_CHECKING([how to create a $1 tar archive])
+# Loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
+_am_tools=${am_cv_prog_tar_$1-$_am_tools}
+# Do not fold the above two line into one, because Tru64 sh and
+# Solaris sh will not grok spaces in the rhs of `-'.
+for _am_tool in $_am_tools
+do
+ case $_am_tool in
+ gnutar)
+ for _am_tar in tar gnutar gtar;
+ do
+ AM_RUN_LOG([$_am_tar --version]) && break
+ done
+ am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
+ am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
+ am__untar="$_am_tar -xf -"
+ ;;
+ plaintar)
+ # Must skip GNU tar: if it does not support --format= it doesn't create
+ # ustar tarball either.
+ (tar --version) >/dev/null 2>&1 && continue
+ am__tar='tar chf - "$$tardir"'
+ am__tar_='tar chf - "$tardir"'
+ am__untar='tar xf -'
+ ;;
+ pax)
+ am__tar='pax -L -x $1 -w "$$tardir"'
+ am__tar_='pax -L -x $1 -w "$tardir"'
+ am__untar='pax -r'
+ ;;
+ cpio)
+ am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
+ am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
+ am__untar='cpio -i -H $1 -d'
+ ;;
+ none)
+ am__tar=false
+ am__tar_=false
+ am__untar=false
+ ;;
+ esac
+
+ # If the value was cached, stop now. We just wanted to have am__tar
+ # and am__untar set.
+ test -n "${am_cv_prog_tar_$1}" && break
+
+ # tar/untar a dummy directory, and stop if the command works
+ rm -rf conftest.dir
+ mkdir conftest.dir
+ echo GrepMe > conftest.dir/file
+ AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
+ rm -rf conftest.dir
+ if test -s conftest.tar; then
+ AM_RUN_LOG([$am__untar <conftest.tar])
+ grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
+ fi
+done
+rm -rf conftest.dir
+
+AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
+AC_MSG_RESULT([$am_cv_prog_tar_$1])])
+AC_SUBST([am__tar])
+AC_SUBST([am__untar])
+]) # _AM_PROG_TAR
+
m4_include([acinclude.m4])
/* Define if you have a readline compatible library */
#undef HAVE_LIBREADLINE
-/* Define to 1 if you have the <linux/termios.h> header file. */
-#undef HAVE_LINUX_TERMIOS_H
-
/* Define to 1 if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
-/* Define to 1 if you have the <termios.h> header file. */
-#undef HAVE_TERMIOS_H
-
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
# include <unistd.h>
#endif"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE CPP EGREP U ANSI2KNR LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE CPP EGREP U ANSI2KNR LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
-am__api_version="1.8"
+am__api_version="1.9"
ac_aux_dir=
for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
if test -f $ac_dir/install-sh; then
fi
if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
- # Keeping the `.' argument allows $(mkdir_p) to be used without
- # argument. Indeed, we sometimes output rules like
+ # We used to keeping the `.' as first argument, in order to
+ # allow $(mkdir_p) to be used without argument. As in
# $(mkdir_p) $(somedir)
- # where $(somedir) is conditionally defined.
- # (`test -n '$(somedir)' && $(mkdir_p) $(somedir)' is a more
- # expensive solution, as it forces Make to start a sub-shell.)
- mkdir_p='mkdir -p -- .'
+ # where $(somedir) is conditionally defined. However this is wrong
+ # for two reasons:
+ # 1. if the package is installed by a user who cannot write `.'
+ # make install will fail,
+ # 2. the above comment should most certainly read
+ # $(mkdir_p) $(DESTDIR)$(somedir)
+ # so it does not work when $(somedir) is undefined and
+ # $(DESTDIR) is not.
+ # To support the latter case, we have to write
+ # test -z "$(somedir)" || $(mkdir_p) $(DESTDIR)$(somedir),
+ # so the `.' trick is pointless.
+ mkdir_p='mkdir -p --'
else
# On NextStep and OpenStep, the `mkdir' command does not
# recognize any option. It will interpret all options as
# Define the identity of the package.
PACKAGE=abook
- VERSION=0.5.3
+ VERSION=0.5.4
cat >>confdefs.h <<_ACEOF
MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
-
-AMTAR=${AMTAR-"${am_missing_run}tar"}
-
install_sh=${install_sh-"$am_aux_dir/install-sh"}
# Installed binaries are usually stripped using `strip' when the user
# We need awk for the "check" target. The system "awk" is bad on
# some platforms.
+# Always define AMTAR for backward compatibility.
+
+AMTAR=${AMTAR-"${am_missing_run}tar"}
+
+am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
+
+
-
-
-for ac_header in unistd.h locale.h termios.h linux/termios.h sys/ioctl.h
+for ac_header in unistd.h locale.h sys/ioctl.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
fi;
if test x$debug = xtrue; then
- CPPFLAGS="-DDEBUG $CPPFLAGS"
+ CPPFLAGS="-DDEBUG=1 $CPPFLAGS"
CFLAGS="-g $CFLAGS"
fi
s,@AUTOMAKE@,$AUTOMAKE,;t t
s,@AUTOHEADER@,$AUTOHEADER,;t t
s,@MAKEINFO@,$MAKEINFO,;t t
-s,@AMTAR@,$AMTAR,;t t
s,@install_sh@,$install_sh,;t t
s,@STRIP@,$STRIP,;t t
s,@ac_ct_STRIP@,$ac_ct_STRIP,;t t
s,@AWK@,$AWK,;t t
s,@SET_MAKE@,$SET_MAKE,;t t
s,@am__leading_dot@,$am__leading_dot,;t t
+s,@AMTAR@,$AMTAR,;t t
+s,@am__tar@,$am__tar,;t t
+s,@am__untar@,$am__untar,;t t
s,@build@,$build,;t t
s,@build_cpu@,$build_cpu,;t t
s,@build_vendor@,$build_vendor,;t t
else
continue
fi
- grep '^DEP_FILES *= *[^ #]' < "$mf" > /dev/null || continue
- # Extract the definition of DEP_FILES from the Makefile without
- # running `make'.
+ # Extract the definition of DEPDIR, am__include, and am__quote
+ # from the Makefile without running `make'.
DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
test -z "$DEPDIR" && continue
+ am__include=`sed -n 's/^am__include = //p' < "$mf"`
+ test -z "am__include" && continue
+ am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
# When using ansi2knr, U may be empty or an underscore; expand it
U=`sed -n 's/^U = //p' < "$mf"`
- test -d "$dirpart/$DEPDIR" || mkdir "$dirpart/$DEPDIR"
- # We invoke sed twice because it is the simplest approach to
- # changing $(DEPDIR) to its actual value in the expansion.
- for file in `sed -n '
- /^DEP_FILES = .*\\\\$/ {
- s/^DEP_FILES = //
- :loop
- s/\\\\$//
- p
- n
- /\\\\$/ b loop
- p
- }
- /^DEP_FILES = / s/^DEP_FILES = //p' < "$mf" | \
+ # Find all dependency output files, they are included files with
+ # $(DEPDIR) in their names. We invoke sed twice because it is the
+ # simplest approach to changing $(DEPDIR) to its actual value in the
+ # expansion.
+ for file in `sed -n "
+ s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
# Make sure the directory exists.
test -f "$dirpart/$file" && continue
dnl abook configure.in
AC_INIT(abook.c)
-AM_INIT_AUTOMAKE(abook, 0.5.3)
+AM_INIT_AUTOMAKE(abook, 0.5.4)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST
AC_C_INLINE
AC_PROG_INSTALL
AC_HEADER_STDC
-AC_CHECK_HEADERS(unistd.h locale.h termios.h linux/termios.h sys/ioctl.h)
+AC_CHECK_HEADERS(unistd.h locale.h sys/ioctl.h)
AC_CHECK_HEADER(stdarg.h,AC_DEFINE(HAVE_STDARG_H, 1, [Define if you have the <stdarg.h> header file.]),AC_MSG_ERROR([*** stdarg.h is missing on your system ***]))
AC_FUNC_STRCOLL
AC_CHECK_FUNCS(setlocale)
esac], [debug=false])
if test x$debug = xtrue; then
- CPPFLAGS="-DDEBUG $CPPFLAGS"
+ CPPFLAGS="-DDEBUG=1 $CPPFLAGS"
CFLAGS="-g $CFLAGS"
fi
-$TMPERR="Cannot open file /tmp/ldap2abook/tmp";
+$TMPERR="Cannot open temporary file";
$DESTFILEERR="Cannot open file $DESTFILE";
$REPORT="entries created";
1;
#
# Author: Mariusz Balewski <M.Balewski@wp.pl>
# 03.06.2004
+# 29.08.2005 Tried to fix insecure tempfile handling (untested)
#
# GPL licensed
# Feel free to send me your comments
###############################
###############################
+use File::Temp qw/ :mktemp /;
+$file = mktemp("/tmp/tmpfileXXXXXXX");
+
+
require 'comms.pl';
-system("ldapsearch -h $HOST $SIMPLEAUTH $AUTHDN $PASS \"$FINDDN=*\" $BASEDN -LLL > /tmp/ldap2abook.tmp");
+system("ldapsearch -h $HOST $SIMPLEAUTH $AUTHDN $PASS \"$FINDDN=*\" $BASEDN -LLL > $file");
$i=0;
-open(F1,"</tmp/ldap2abook.tmp") || die "$TMPERR";
+open(F1,"<$file") || die "$TMPERR";
open(F2,">$DESTFILE") || die "$DESTFILEERR";
flock(F1,8);
flock(F2,8);
close(F2);
close(F1);
-system("rm /tmp/ldap2abook.tmp");
+unlink($file);
print "\n$i ";
print "$REPORT\n\n";
/*
- * $Id: database.c,v 1.20 2003/11/22 13:46:02 jheinonen Exp $
+ * $Id: database.c,v 1.27 2005/08/13 10:49:25 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
#include "misc.h"
#include "options.h"
#include "filter.h"
+#include "xmalloc.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-static void free_item(int i);
-
-
list_item *database = NULL;
int items = 0;
#define INITIAL_LIST_CAPACITY 30
-int list_capacity = 0;
+static int list_capacity = 0;
extern int first_list_item;
extern int curitem;
extern char *selected;
extern char *datafile;
-extern char *rcfile;
/*
* field definitions
{"Name", "name", TAB_CONTACT},/* NAME */
{"E-mails", "email", TAB_CONTACT},/* EMAIL */
{"Address", "address", TAB_ADDRESS},/* ADDRESS */
- {"Address2", "address2", TAB_ADDRESS},/* ADDRESS2 */
+ {"Address2", "address2", TAB_ADDRESS},/* ADDRESS2 */
{"City", "city", TAB_ADDRESS},/* CITY */
{"State/Province","state", TAB_ADDRESS},/* STATE */
{"ZIP/Postal Code","zip", TAB_ADDRESS},/* ZIP */
list_item item;
memset(&item, 0, sizeof(item));
-
+
for(;;) {
line = getaline(in);
- if( feof(in) ) {
- if( item[NAME] && sec )
+ if(feof(in)) {
+ if(item[NAME] && sec)
add_item2database(item);
else
free_list_item(item);
break;
}
- if( !*line || *line == '\n' || *line == '#' ) {
- free(line);
- continue;
- } else if( *line == '[' ) {
+ if(!*line || *line == '\n' || *line == '#') {
+ goto next;
+ } else if(*line == '[') {
if( item[NAME] && sec )
add_item2database(item);
else
free_list_item(item);
memset(&item, 0, sizeof(item));
sec = 1;
- if ( !(tmp = strchr(line, ']')))
+ if(!(tmp = strchr(line, ']')))
sec = 0; /*incorrect section lines are skipped*/
- } else if((tmp = strchr(line, '=') ) && sec ) {
+ } else if((tmp = strchr(line, '=') ) && sec) {
*tmp++ = '\0';
- for(i=0; i<ITEM_FIELDS; i++)
- if( !strcmp(abook_fields[i].key, line) ) {
- item[i] = strdup(tmp);
+ for(i = 0; i < ITEM_FIELDS; i++)
+ if(!strcmp(abook_fields[i].key, line)) {
+ item[i] = xstrdup(tmp);
goto next;
}
}
next:
- free(line);
+ xfree(line);
}
- free(line);
+ xfree(line);
return 0;
}
-
+
int
load_database(char *filename)
{
FILE *in;
- if( database != NULL )
+ if(database != NULL)
close_database();
- if ( (in = abook_fopen(filename, "r")) == NULL )
+ if ((in = abook_fopen(filename, "r")) == NULL)
return -1;
-
+
parse_database(in);
return (items == 0) ? 2 : 0;
if( (out = abook_fopen(datafile, "w")) == NULL )
return -1;
- if( list_is_empty() ) {
+ if(list_is_empty()) {
fclose(out);
unlink(datafile);
return 1;
}
-
+
write_database(out, e);
-
+
fclose(out);
-
+
return 0;
}
int i;
for(i=0; i<ITEM_FIELDS; i++)
- my_free(item[i]);
+ xfree(item[i]);
}
void
close_database()
{
int i;
-
+
for(i=0; i < items; i++)
free_item(i);
{
int i;
char *tmp;
-
+
if(item[EMAIL] == NULL)
- item[EMAIL] = strdup("");
+ item[EMAIL] = xstrdup("");
for(i=0; i<ITEM_FIELDS; i++)
if( item[i] && ((int)strlen(item[i]) > _MAX_FIELD_LEN(i) ) ) {
tmp = item[i];
item[i][_MAX_FIELD_LEN(i)-1] = 0;
- item[i] = strdup(item[i]);
+ item[i] = xstrdup(item[i]);
free(tmp);
}
}
else
return;
- database = (list_item *)abook_realloc(database,
- sizeof(list_item) * list_capacity);
- selected = (char *)abook_realloc(selected, list_capacity);
+ database = xrealloc(database, sizeof(list_item) * list_capacity);
+ selected = xrealloc(selected, list_capacity);
}
int
add_item2database(list_item item)
{
- if( item[NAME] == NULL || ! *item[NAME] ) {
+ if(item[NAME] == NULL || ! *item[NAME]) {
free_list_item(item);
return 1;
}
- if( ++items > list_capacity)
+ if(++items > list_capacity)
adjust_list_capacity();
validate_item(item);
{
int i, j;
- if( list_is_empty() )
+ if(list_is_empty())
return;
- if( ! selected_items() )
- selected[ curitem ] = 1;
-
- for( j = LAST_ITEM; j >= 0; j-- ) {
- if( selected[j] ) {
+ if(!selected_items())
+ selected[curitem] = 1;
+
+ for(j = LAST_ITEM; j >= 0; j--) {
+ if(selected[j]) {
free_item(j); /* added for .4 data_s_ */
- for( i = j; i < LAST_ITEM; i++ ) {
- itemcpy(database[ i ], database[ i + 1 ]);
- selected[ i ] = selected[ i + 1 ];
+ for(i = j; i < LAST_ITEM; i++) {
+ itemcpy(database[i], database[i + 1]);
+ selected[i] = selected[i + 1];
}
- items--;
+ items--;
}
}
- if( curitem > LAST_ITEM && items > 0 )
+ if(curitem > LAST_ITEM && items > 0)
curitem = LAST_ITEM;
-
adjust_list_capacity();
select_none();
while(p > s && *(p - 1) != ' ')
p--;
- return strdup(p);
+ return xstrdup(p);
}
static int
itemcpy(a, i1);
itemcpy(b, i2);
-
- return safe_strcoll( a[sort_field], b[sort_field] );
+
+ return safe_strcoll(a[sort_field], b[sort_field]);
}
static int
}
sort_field = field;
-
+
qsort((void *)database, items, sizeof(list_item), namecmp);
refresh_screen();
if(list_is_empty() || !is_valid_item(start))
return -2; /* error */
- findstr = strdup(str);
+ findstr = xstrdup(str);
findstr = strlower(findstr);
e.item = start - 1; /* must be "real start" - 1 */
db_enumerate_items(e) {
- for( i = 0; search_fields[i] >= 0; i++ ) {
- tmp = safe_strdup(database[e.item][search_fields[i]]);
+ for(i = 0; search_fields[i] >= 0; i++) {
+ if(database[e.item][search_fields[i]] == NULL)
+ continue;
+ tmp = xstrdup(database[e.item][search_fields[i]]);
if( tmp && strstr(strlower(tmp), findstr) ) {
ret = e.item;
goto out;
}
- my_free(tmp);
+ xfree(tmp);
}
}
{
int item = max(0, e.item + 1);
int i;
-
+
switch(e.mode) {
#ifdef DEBUG
case ENUM_ALL:
* check if we are overwriting statically allocated default
*/
if(strcasecmp(abook_fields[i].name, abook_fields[i].key))
- my_free(abook_fields[i].name);
-
- s = abook_malloc(MAX_FIELDNAME_LEN + 1);
+ xfree(abook_fields[i].name);
+
+ s = xmalloc_inc(MAX_FIELDNAME_LEN, 1);
snprintf(s, MAX_FIELDNAME_LEN, "%s", name);
abook_fields[i].name = s;
}
#define CUSTOM_MIN CUSTOM1
#define CUSTOM_MAX CUSTOM5
-typedef char * list_item[ITEM_FIELDS];
+typedef char *list_item[ITEM_FIELDS];
#define MAX_FIELDNAME_LEN 21
/*
- * $Id: edit.c,v 1.32 2004/04/03 16:05:41 jheinonen Exp $
+ * $Id: edit.c,v 1.38 2005/08/13 10:49:25 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
#include "list.h"
#include "edit.h"
#include "misc.h"
+#include "xmalloc.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
"CUSTOM "
};
- mvwhline(editw, TABLINE+1, 0, UI_HLINE_CHAR, EDITW_COLS);
- for(i=0; i < TABS; i++) {
+ mvwhline(editw, TABLINE + 1, 0, UI_HLINE_CHAR, EDITW_COLS);
+ for(i = 0; i < TABS; i++) {
mvwaddch(editw, TABLINE+1, spacing * i + 2, UI_TEE_CHAR);
mvwaddch(editw, TABLINE+1, spacing * i + 12, UI_TEE_CHAR);
}
- for(i=0; i < TABS; i++) {
+ for(i = 0; i < TABS; i++) {
mvwaddch(editw, TABLINE, spacing * i + 2, UI_ULCORNER_CHAR);
mvwaddch(editw, TABLINE, spacing * i + 3, UI_LBOXLINE_CHAR);
mvwaddstr(editw, TABLINE, spacing * i + 4, tab_names[i]);
strcpy(database[item][EMAIL], p+1);
strcat(database[item][EMAIL], ",");
- strcat(database[item][EMAIL], tmp);
+ strcat(database[item][EMAIL], tmp);
}
static void
refresh_statusline();
}
-/*
- * we have to introduce edit_undo here
- */
-static void edit_undo(int item, int mode);
-
enum {
BACKUP_ITEM,
RESTORE_ITEM,
CLEAR_UNDO
};
+static void
+edit_undo(int item, int mode)
+{
+ int i;
+ static list_item *backup = NULL;
+
+ switch(mode) {
+ case CLEAR_UNDO:
+ if(backup) {
+ free_list_item(backup[0]);
+ xfree(backup);
+ }
+ break;
+ case BACKUP_ITEM:
+ if(backup) {
+ free_list_item(backup[0]);
+ xfree(backup);
+ }
+ backup = xmalloc(sizeof(list_item));
+ for(i = 0; i < ITEM_FIELDS; i++)
+ if(database[item][i] == NULL)
+ backup[0][i] = NULL;
+ else
+ backup[0][i] =
+ xstrdup(database[item][i]);
+ break;
+ case RESTORE_ITEM:
+ if(backup) {
+ free_list_item(database[item]);
+ itemcpy(database[item], backup[0]);
+ xfree(backup);
+ }
+ break;
+ default:
+ assert(0);
+ }
+}
+
static void
close_editor()
char *header;
char email[MAX_EMAIL_LEN];
- if( (header = (char *)malloc(EDITW_COLS)) == NULL )
+ if((header = xmalloc(EDITW_COLS)) == NULL)
return;
get_first_email(email, item);
- if( *database[item][EMAIL] )
+ if(*database[item][EMAIL])
snprintf(header, EDITW_COLS, "%s <%s>",
database[item][NAME],
email);
if(abook_fields[i].tab != tab)
continue;
- if(i==EMAIL) { /* special field */
+ if(i == EMAIL) { /* special field */
int k;
char emails[MAX_EMAILS][MAX_EMAIL_LEN];
split_emailstr(item, emails);
}
if(j > 1) {
- getyx(editw, y, x); y++;
+ getyx(editw, y, x);
+ y++;
} else
y = FIELDS_START_Y;
char *old;
int ret = 0;
- if( !strncmp("E-mail", msg, 6) )
+ if(!strncmp("E-mail", msg, 6))
max_len = MAX_EMAIL_LEN;
old = *field;
*field = ui_readline(msg, old, max_len - 1, 0);
if(*field) {
- free(old);
+ xfree(old);
if(!**field)
- my_free(*field);
+ xfree(*field);
} else {
*field = old;
ret = 1;
{
char *tmp;
- tmp = strdup(*field);
+ tmp = xstrdup(*field);
change_field("Name: ", field);
- if( *field == NULL || ! **field ) {
- my_free(*field);
- *field = strdup(tmp);
+ if(*field == NULL || ! **field) {
+ xfree(*field);
+ *field = xstrdup(tmp);
}
- my_free(tmp);
+ xfree(tmp);
}
static void
fix_email_str(char *str)
{
- for(; *str; str++ )
+ for(; *str; str++)
*str = *str == ',' ? '_' : *str;
}
int email_num = c - '2';
split_emailstr(item, emails);
- field = strdup(emails[email_num]);
+ field = xstrdup(emails[email_num]);
if(change_field("E-mail: ", &field))
return; /* user cancelled ( C-g ) */
} else
*emails[email_num] = 0;
- my_free(database[item][EMAIL]);
+ xfree(database[item][EMAIL]);
for(i = 0; i < MAX_EMAILS; i++) {
if( *emails[i] ) {
if(tmp[len -1] == ',')
tmp[len-1] =0;
- database[item][EMAIL] = strdup(tmp);
+ database[item][EMAIL] = xstrdup(tmp);
}
static int
return 1;
}
- for(i=0, j=0; i< ITEM_FIELDS; i++) {
+ for(i = 0, j = 0; i< ITEM_FIELDS; i++) {
if(abook_fields[i].tab == tab)
j++;
if(j==n)
break;
}
- if(j!=n)
+ if(j != n)
return 0;
str = mkstr("%s: ", abook_fields[i].name);
return 1;
}
-static void
-edit_undo(int item, int mode)
-{
- int i;
- static list_item *backup = NULL;
-
- switch(mode) {
- case CLEAR_UNDO:
- if(backup) {
- free_list_item(backup[0]);
- my_free(backup);
- }
- break;
- case BACKUP_ITEM:
- if(backup) {
- free_list_item(backup[0]);
- my_free(backup);
- }
- backup = (list_item *)abook_malloc(sizeof(list_item));
- for(i = 0; i < ITEM_FIELDS; i++)
- backup[0][i] = safe_strdup(database[item][i]);
- break;
- case RESTORE_ITEM:
- if(backup) {
- free_list_item(database[item]);
- itemcpy(database[item], backup[0]);
- my_free(backup);
- }
- break;
- default:
- assert(0);
- }
-}
-
static int
edit_loop(int item)
{
refresh();
wrefresh(editw);
- switch( (c = getch()) ) {
+ switch((c = getch())) {
case 'c': tab = TAB_CONTACT; break;
case 'a': tab = TAB_ADDRESS; break;
case 'p': tab = TAB_PHONE; break;
case 'k': if(is_valid_item(item-1)) item--; break;
case KEY_DOWN:
case '>':
- case 'j': if(is_valid_item(item+1)) item++; break;
+ case 'j': if(is_valid_item(item + 1)) item++; break;
case 'r': roll_emails(item); break;
case '?': display_help(HELP_EDITOR); break;
case 'u': edit_undo(item, RESTORE_ITEM); break;
init_editor();
- while( (item = edit_loop(item)) >= 0 )
+ while((item = edit_loop(item)) >= 0)
curitem = item; /* hmm, this is not very clean way to go */
close_editor();
};
#define MAX_TAB TAB_CUSTOM
-
+
#define TABS (MAX_TAB+1)
#endif
/*
- * $Id: filter.c,v 1.31 2004/06/30 19:48:28 jheinonen Exp $
+ * $Id: filter.c,v 1.38 2005/08/13 14:10:57 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
#include "list.h"
#include "misc.h"
#include "options.h"
+#include "xmalloc.h"
#include <assert.h>
extern int items;
print_filters()
{
int i;
-
+
puts("input:");
for(i=0; *i_filters[i].filtname ; i++)
printf("\t%s\t%s\n", i_filters[i].filtname,
i_filters[i].desc);
putchar('\n');
-
+
puts("output:");
for(i=0; *e_filters[i].filtname ; i++)
printf("\t%s\t%s\n", e_filters[i].filtname,
pwent = getpwnam(username);
- if((tmp = strdup(pwent->pw_gecos)) == NULL)
- return strdup(username);
+ if((tmp = xstrdup(pwent->pw_gecos)) == NULL)
+ return xstrdup(username);
rtn = sscanf(pwent->pw_gecos, "%[^,]", tmp);
if (rtn == EOF || rtn == 0) {
free(tmp);
- return strdup(username);
+ return xstrdup(username);
} else
return tmp;
}
/*
* import
*/
-
+
static int i_read_file(char *filename, int (*func) (FILE *in));
static void
import_screen()
{
int i;
-
+
clear();
refresh_statusline();
headerline("import database");
mvaddstr(3, 1, "please select a filter");
-
+
for(i=0; *i_filters[i].filtname ; i++)
mvprintw(5 + i, 6, "%c -\t%s\t%s\n", 'a' + i,
int tmp = items;
import_screen();
-
+
filter = getch() - 'a';
if(filter == 'x' - 'a' ||
filter >= number_of_input_filters() || filter < 0) {
refresh_screen();
return 1;
}
-
+
mvaddstr(5+filter, 2, "->");
-
+
filename = ask_filename("Filename: ");
- if( !filename ) {
+ if(!filename) {
refresh_screen();
return 2;
}
-
- if( i_read_file(filename, i_filters[filter].func ) )
+
+ if(i_read_file(filename, i_filters[filter].func ))
statusline_msg("Error occured while opening the file");
- else if( tmp == items )
+ else if(tmp == items)
statusline_msg("Hmm.., file seems not to be a valid file");
-
+
refresh_screen();
free(filename);
FILE *in;
int ret = 0;
- if( ( in = abook_fopen( filename, "r" ) ) == NULL )
+ if( (in = abook_fopen( filename, "r" )) == NULL )
return 1;
ret = (*func) (in);
fclose(in);
- return ret;
+ return ret;
}
int
int ret = 0;
for(i=0;; i++) {
- if( ! strncasecmp(i_filters[i].filtname, filtname,
+ if(! strncasecmp(i_filters[i].filtname, filtname,
FILTNAME_LEN) )
break;
- if( ! *i_filters[i].filtname ) {
+ if(! *i_filters[i].filtname) {
i = -1;
break;
}
}
- if( i<0 )
+ if(i < 0)
return -1;
- if( !strcmp(filename, "-") ) {
+ if(!strcmp(filename, "-")) {
struct stat s;
- if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode))
+ if((fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode))
ret = 1;
else
ret = (*i_filters[i].func) (stdin);
} else
ret = i_read_file(filename, i_filters[i].func);
-
- if( tmp == items )
+
+ if(tmp == items)
ret = 1;
-
+
return ret;
}
export_screen()
{
int i;
-
+
clear();
headerline("export database");
mvaddstr(3, 1, "please select a filter");
-
- for(i=0; *e_filters[i].filtname ; i++)
+
+ for(i = 0; *e_filters[i].filtname ; i++)
mvprintw(5 + i, 6, "%c -\t%s\t%s\n", 'a' + i,
e_filters[i].filtname,
e_filters[i].desc);
char *filename;
export_screen();
-
+
filter = getch() - 'a';
if(filter == 'x' - 'a' ||
filter >= number_of_output_filters() || filter < 0) {
refresh_screen();
return 1;
}
-
+
mvaddstr(5+filter, 2, "->");
- if( selected_items() ) {
+ if(selected_items()) {
statusline_addstr("Export All/Selected/Cancel (A/s/c)");
switch( tolower(getch()) ) {
case 's':
}
clear_statusline();
}
-
+
filename = ask_filename("Filename: ");
- if( !filename ) {
+ if(!filename) {
refresh_screen();
return 2;
}
-
- if( e_write_file(filename, e_filters[filter].func, enum_mode ) )
+
+ if( e_write_file(filename, e_filters[filter].func, enum_mode))
statusline_msg("Error occured while exporting");
-
+
refresh_screen();
free(filename);
int ret = 0;
struct db_enumerator enumerator = init_db_enumerator(mode);
- if( (out = fopen(filename, "a")) == NULL )
+ if((out = fopen(filename, "a")) == NULL)
return 1;
- if( ftell(out) )
+ if(ftell(out))
return 1;
ret = (*func) (out, enumerator);
-
+
fclose(out);
-
+
return ret;
}
struct db_enumerator e = init_db_enumerator(enum_mode);
for(i=0;; i++) {
- if( ! strncasecmp(e_filters[i].filtname, filtname,
- FILTNAME_LEN) )
+ if(!strncasecmp(e_filters[i].filtname, filtname,
+ FILTNAME_LEN))
break;
- if( ! *e_filters[i].filtname ) {
+ if(!*e_filters[i].filtname) {
i = -1;
break;
}
int i;
int ret = 0;
struct db_enumerator e = init_db_enumerator(mode);
-
+
for(i=0;; i++) {
- if( ! strncasecmp(e_filters[i].filtname, filtname,
- FILTNAME_LEN) )
+ if(!strncasecmp(e_filters[i].filtname, filtname,
+ FILTNAME_LEN))
break;
- if( ! *e_filters[i].filtname ) {
+ if(!*e_filters[i].filtname) {
i = -1;
break;
}
}
- if( i<0 )
+ if(i < 0)
return -1;
- if( !strcmp(filename, "-") )
+ if(!strcmp(filename, "-"))
ret = (e_filters[i].func) (stdout, e);
else
ret = e_write_file(filename, e_filters[i].func, mode);
#define LDIF_ITEM_FIELDS 16
-typedef char* ldif_item[LDIF_ITEM_FIELDS];
+typedef char *ldif_item[LDIF_ITEM_FIELDS];
static ldif_item ldif_field_names = {
- "cn",
+ "cn",
"mail",
"streetaddress",
"streetaddress2",
NAME, /* "cn" */
EMAIL, /* "mail" */
ADDRESS, /* "streetaddress" */
- ADDRESS2, /* "streetaddress2" */
+ ADDRESS2, /* "streetaddress2" */
CITY, /* "locality" */
STATE, /* "st" */
ZIP, /* "postalcode" */
};
-static char *
+static char *
ldif_read_line(FILE *in)
{
char *buf = NULL;
pos = ftell(in);
line = getaline(in);
-
- if( feof(in) || !line )
+
+ if(feof(in) || !line)
break;
-
+
if(i == 1) {
buf = line;
continue;
}
static void
-ldif_add_item(ldif_item ldif_item)
+ldif_add_item(ldif_item li)
{
list_item abook_item;
int i;
memset(abook_item, 0, sizeof(abook_item));
- if( !ldif_item[LDIF_ITEM_FIELDS -1] )
+ if(!li[LDIF_ITEM_FIELDS -1])
goto bail_out;
for(i=0; i < LDIF_ITEM_FIELDS; i++) {
- if(ldif_conv_table[i] >= 0 && ldif_item[i] && *ldif_item[i] )
- abook_item[ldif_conv_table[i]] = strdup(ldif_item[i]);
+ if(ldif_conv_table[i] >= 0 && li[i] && *li[i])
+ abook_item[ldif_conv_table[i]] = xstrdup(li[i]);
}
add_item2database(abook_item);
bail_out:
for(i=0; i < LDIF_ITEM_FIELDS; i++)
- my_free(ldif_item[i]);
+ xfree(li[i]);
}
{
int i;
- if( !strcmp(type, "dn") ) {
+ if(!strcmp(type, "dn")) {
ldif_add_item(item);
return;
}
for(i=0; i < LDIF_ITEM_FIELDS; i++) {
- if( !safe_strcmp(ldif_field_names[i], type) && *value ) {
- if( i == LDIF_ITEM_FIELDS -1) /* this is a dirty hack */
- if( safe_strcmp("person", value))
+ if(!safe_strcmp(ldif_field_names[i], type) && *value) {
+ if(i == LDIF_ITEM_FIELDS - 1) /* this is a dirty hack */
+ if(safe_strcmp("person", value))
break;
if(item[i])
- my_free(item[i]);
- item[i] = strdup(value);
+ xfree(item[i]);
+ item[i] = xstrdup(value);
}
}
}
memset(item, 0, sizeof(item));
do {
- if( ! (line = ldif_read_line(handle)) )
+ if( !(line = ldif_read_line(handle)) )
continue;
- if( -1 == ( str_parse_line(line, &type, &value, &vlen)) ) {
- my_free(line);
+ if(-1 == (str_parse_line(line, &type, &value, &vlen))) {
+ xfree(line);
continue; /* just skip the errors */
}
ldif_convert(item, type, value);
- my_free(line);
+ xfree(line);
} while ( !feof(handle) );
ldif_convert(item, "dn", "");
while( ISSPACE(*ptr) )
ptr++;
- if( strncmp("alias", ptr, 5) ) {
+ if(strncmp("alias", ptr, 5)) {
free(line);
return 1;
}
while( ! ISSPACE(*ptr) )
ptr++;
- /* includes also the trailing zero */
- alias_len = (size_t)(ptr - tmp + 1);
+ alias_len = (size_t)(ptr - tmp);
- if( (*alias = (char *)malloc(alias_len)) == NULL) {
- free(line);
- return 1;
- }
+ *alias = xmalloc_inc(alias_len, 1);
- strncpy(*alias, tmp, alias_len - 1);
- *(*alias + alias_len - 1) = 0;
+ strncpy(*alias, tmp, alias_len);
+ *(*alias + alias_len) = 0;
while(ISSPACE(*ptr))
ptr++;
- *rest = strdup(ptr);
+ *rest = xstrdup(ptr);
free(line);
return 0;
free(item[EMAIL]);
item[EMAIL] = tmp;
} else {
- my_free(email);
+ xfree(email);
}
}
}
for(;;) {
memset(item, 0, sizeof(item));
- if( !mutt_read_line(in, &item[NICK],
+ if(!mutt_read_line(in, &item[NICK],
&item[NAME]) )
mutt_parse_email(item);
- if( feof(in) ) {
+ if(feof(in)) {
free_list_item(item);
break;
}
ldif_fput_type_and_value(out, "dn", tmp);
free(tmp);
- for(j=0; j < LDIF_ITEM_FIELDS; j++) {
+ for(j = 0; j < LDIF_ITEM_FIELDS; j++) {
if(ldif_conv_table[j] >= 0) {
if(ldif_conv_table[j] == EMAIL)
ldif_fput_type_and_value(out,
{
char tmp[MAX_EMAILSTR_LEN];
- if( items < 1 )
+ if(items < 1)
return 2;
extra_column = (extra_column > 2 && extra_column < ITEM_FIELDS) ?
fprintf(out, "\n</table>\n");
fprintf(out, "\n</body>\n</html>\n");
}
-
+
/*
* end of html export filter
*/
int i;
char *tmp;
- if( s == NULL || *s != '(' )
+ if(s == NULL || *s != '(')
return;
for(i=0; s[i]; i++ )
if( ( tmp = strchr(s,')')) )
*tmp=0;
- for(i=1; ( tmp = strchr(s, ',') ) != NULL ; i++, s=tmp+1 )
- if( i > MAX_EMAILS - 1 ) {
+ for(i = 1; ( tmp = strchr(s, ',') ) != NULL ; i++, s = tmp + 1)
+ if(i > MAX_EMAILS - 1) {
*tmp = 0;
- break;
+ break;
}
}
int i, len, last;
int pine_conv_table[]= {NICK, NAME, EMAIL, -1, NOTES};
- memset(&item, 0, sizeof(item) );
-
+ memset(&item, 0, sizeof(item));
+
for(i=0, last=0; !last ; i++) {
- if( ! (end = strchr(start, '\t')) )
+ if( !(end = strchr(start, '\t')) )
last=1;
len = last ? strlen(start) : (int) (end-start);
strncpy(tmp, start, len);
tmp[len] = 0;
if(*tmp)
- item[pine_conv_table[i]] = strdup(tmp);
+ item[pine_conv_table[i]] = xstrdup(tmp);
}
start = end + 1;
}
char *ptr;
int i;
- fgets(line, LINESIZE, in);
+ fgets(line, LINESIZE, in);
while(!feof(in)) {
for(i = 2;;i++) {
- buf = (char *) realloc(buf, i*LINESIZE);
+ buf = xrealloc(buf, i*LINESIZE);
if(i == 2)
strcpy(buf, line);
fgets(line, LINESIZE, in);
ptr=(char *)&line;
- if(*ptr != ' ' || feof(in) )
+ if(*ptr != ' ' || feof(in))
break;
else
- while( *ptr == ' ')
+ while(*ptr == ' ')
ptr++;
strcat(buf, ptr);
}
- if( *buf == '#' ) {
- my_free(buf);
+ if(*buf == '#') {
+ xfree(buf);
continue;
}
pine_fixbuf(buf);
pine_parse_buf(buf);
- my_free(buf);
+ xfree(buf);
}
return 0;
/* FIXME
* these files should be parsed according to a certain
- * lay out, or the default if layout is not given, at
+ * lay out, or the default if layout is not given, at
* the moment only default is done...
- */
+ */
#define CSV_COMMENT_CHAR '#'
int i;
char *tmp;
- if( s == NULL )
+ if(s == NULL)
return;
- for(i=1; ( tmp = strchr(s, ',') ) != NULL ; i++, s = tmp + 1 )
- if( i > MAX_EMAILS - 1 ) {
+ for(i = 1; ( tmp = strchr(s, ',') ) != NULL ; i++, s = tmp + 1 )
+ if(i > MAX_EMAILS - 1) {
*tmp = 0;
- break;
+ break;
}
}
char *copy, *trimmed;
int len;
- copy = trimmed = strdup(s);
+ copy = trimmed = xstrdup(s);
strtrim(trimmed);
len = strlen(trimmed);
if(trimmed[len - 1] == '\"' && *trimmed == '\"') {
if(len < 3) {
- my_free(copy);
+ xfree(copy);
return NULL;
}
trimmed[len - 1] = 0;
trimmed++;
- trimmed = strdup(trimmed);
+ trimmed = xstrdup(trimmed);
free(copy);
return trimmed;
}
- my_free(copy);
- return strdup(s);
+ xfree(copy);
+ return xstrdup(s);
}
static void
&& csv_conv_table[field] >= 0) {
item[csv_conv_table[field]] = newstr;
} else {
- my_free(newstr);
+ xfree(newstr);
}
}
&& allcsv_conv_table[field] >= 0) {
item[allcsv_conv_table[field]] = newstr;
} else {
- my_free(newstr);
+ xfree(newstr);
}
}
if(line && *line && *line != CSV_COMMENT_CHAR)
csv_parse_line(line);
- my_free(line);
+ xfree(line);
}
return 0;
if(line && *line && *line != CSV_COMMENT_CHAR)
allcsv_parse_line(line);
- my_free(line);
+ xfree(line);
}
return 0;
};
csv_export_common(out, e, csv_export_fields, NULL);
-
+
return 0;
}
fprintf(out, "\"CUSTOM5\"\n");
csv_export_common(out, e, allcsv_export_fields, NULL);
-
+
return 0;
}
#define PALM_CSV_END CSV_SPECIAL(1)
#define PALM_CSV_CAT CSV_SPECIAL(2)
-static void
+static void
palm_split_and_write_name(FILE *out, char *name)
{
char *p;
}
}
-static void
+static void
palm_csv_handle_specials(FILE *out, int item, int field)
{
switch(field) {
FAX, /* FAX */
MOBILEPHONE, /* OTHER */
EMAIL, /* EMAIL */
- ADDRESS, /* ADDRESS */
+ ADDRESS, /* ADDRESS */
CITY, /* CITY */
STATE, /* STATE */
ZIP, /* ZIP */
for( j = strlen(database[e.item][NAME]) - 1; j >= 0; j-- ) {
if(database[e.item][NAME][j] == ' ')
break;
- }
+ }
fprintf(out, "N:%s;%.*s\n",
safe_str(name),
j,
safe_str(database[e.item][NAME])
- );
+ );
free(name);
if ( database[e.item][ADDRESS] )
fprintf(out, "ADR:;;%s;%s;%s;%s;%s;%s\n",
safe_str(database[e.item][ADDRESS]),
- safe_str(database[e.item][ADDRESS2]),
+ safe_str(database[e.item][ADDRESS2]),
safe_str(database[e.item][CITY]),
safe_str(database[e.item][STATE]),
safe_str(database[e.item][ZIP]),
safe_str(database[e.item][COUNTRY])
);
-
+
if (database[e.item][PHONE])
fprintf(out, "TEL;HOME:%s\n", database[e.item][PHONE]);
if (database[e.item][WORKPHONE])
if ( database[e.item][EMAIL] ) {
split_emailstr(e.item, emails);
for(j=0; j < MAX_EMAILS ; j++) {
- if ( *emails[j] )
+ if ( *emails[j] )
fprintf(out, "EMAIL;INTERNET:%s\n",
emails[j]);
}
}
-
- if ( database[e.item][NOTES] )
+
+ if ( database[e.item][NOTES] )
fprintf(out, "NOTE:%s\n", database[e.item][NOTES]);
if (database[e.item][URL])
fprintf(out, "URL:%s\n", database[e.item][URL]);
fprintf(out, "END:VCARD\n\n");
-
+
}
return 0;
mutt_alias_genalias(int i)
{
char *tmp, *pos;
-
+
if(database[i][NICK])
- return strdup(database[i][NICK]);
+ return xstrdup(database[i][NICK]);
- tmp = strdup(database[i][NAME]);
+ tmp = xstrdup(database[i][NAME]);
if( ( pos = strchr(tmp, ' ') ) )
*pos = 0;
strlower(tmp);
- return tmp;
+ return tmp;
}
static int
alias,
database[e.item][NAME],
email);
- my_free(alias);
+ xfree(alias);
}
return 0;
if (database[i][CITY])
fprintf(out, "\n%s", database[i][CITY]);
-
+
if (database[i][STATE] || database[i][ZIP]) {
fputc('\n', out);
-
+
if(database[i][STATE]) {
fprintf(out, "%s", database[i][STATE]);
if(database[i][ZIP])
if(database[i][CITY])
fprintf(out, "%s", database[i][CITY]);
}
-
+
if (database[i][STATE])
fprintf(out, "\n%s", database[i][STATE]);
alias,
database[e.item][NAME],
email);
- my_free(alias);
+ xfree(alias);
}
return 0;
** From: [blank From: line]
** From: uu.net!kent [uucp addresses - no comment]
** From: uu.net!kent (kent) [uucp addresses - with comment]
-** From: "(Joe Bloggs)" <joe@anorg.com>
+** From: "(Joe Bloggs)" <joe@anorg.com>
** From: "Roy T. Fielding" <fielding@kiwi.ics.uci.edu>
** From: kent@localhost
** From: kent@uu.net (Kent Landfield)
** From: (George Burgyan) <gburgyan@cybercon.com>
-** From: <gburgyan@cybercon.com> (George Burgyan)
+** From: <gburgyan@cybercon.com> (George Burgyan)
** From: Kent B. Landfield <kent@landfield.com>
** From: IN%"fekete+reply@c2.net" 26-JAN-1997 13:28:55.36
** From: IN%"vicric@panix.com" "Vicki Richman" 13-AUG-1996 10:54:33.38
** First, is there an '@' sign we can use as an anchor ?
*/
if ((c = hm_strchr(line, '@')) == NULL) {
- /*
+ /*
** No '@' sign here so ...
*/
if (strchr(line, '(')) { /* From: bob (The Big Guy) */
email[i++] = *c;
email[i] = '\0';
} else {
- /*
+ /*
* - check to see if the From: line is blank, (taken care of)
* - check if From: uu.net!kent formatted line
* - check if "From: kent" formatted line
else if (use_domainaddr) {
/*
- * check if site domainizes addresses
+ * check if site domainizes addresses
* but don't modify uucp addresses
*/
if ((c = strchr(email, '!')) == NULL) {
comment_fnd = 1;
} else {
/*
- * Is there an email address available
+ * Is there an email address available
* that we can use for the name ?
*/
if (!strcmp(email, NOEMAIL)) /* No */
name[i] = '\0';
/*
- * Is the name string blank ? If so then
+ * Is the name string blank ? If so then
* force it to get filled with something.
*/
if (blankstring(name))
strcpymax(name, email, NAMESTRLEN);
}
- /*
- * need to strip spaces off the end of
- * the email and name strings
+ /*
+ * need to strip spaces off the end of
+ * the email and name strings
*/
c = email + (strlen(email) - 1);
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-\f
+
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
Ditto for AIX 3.2 and <stdlib.h>. */
#ifndef _NO_PROTO
/* Value of POSIXLY_CORRECT environment variable. */
static char *posixly_correct;
-\f
+
#ifdef __GNU_LIBRARY__
/* We want to avoid inclusion of string.h with non-GNU libraries
because there are many ways it can cause trouble.
#endif /* __GNUC__ */
#endif /* not __GNU_LIBRARY__ */
-\f
+
/* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have
return optstring;
}
-\f
+
/* Scan elements of ARGV (whose length is ARGC) for option characters
given in OPTSTRING.
}
#endif /* Not ELIDE_CODE. */
-\f
+
#ifdef TEST
/* Compile with -DTEST to make an executable for use in testing
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-\f
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
}
#endif /* Not ELIDE_CODE. */
-\f
+
#ifdef TEST
#include <stdio.h>
/*
+ * $Id: ldif.c,v 1.5 2005/07/29 06:28:55 jheinonen Exp $
* adapted to use with abook by JH <jheinonen@users.sourceforge.net>
*/
#define LDAP_DEBUG_PARSE 0x800
#define LDAP_DEBUG_ANY 0xffff
-#define LDIF_LINE_WIDTH 76 /* maximum length of LDIF lines */
+#define LDIF_LINE_WIDTH 76 /* maximum length of LDIF lines */
#define LDIF_BASE64_LEN(vlen) (((vlen) * 4 / 3 ) + 3)
#define LDIF_SIZE_NEEDED(tlen,vlen) \
#define CONTINUED_LINE_MARKER '\001'
static char nib2b64[0x40f] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static unsigned char b642nib[0x80] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
*/
int
-str_parse_line(
- char *line,
- char **type,
- char **value,
- int *vlen
-)
+str_parse_line(char *line, char **type, char **value, int *vlen)
{
- char *p, *s, *d, *byte, *stop;
- char nib;
- int i, b64;
+ char *p, *s, *d, *byte, *stop;
+ char nib;
+ int i, b64;
/* skip any leading space */
- while ( ISSPACE( *line ) ) {
+ while(ISSPACE(*line)) {
line++;
}
*type = line;
- for ( s = line; *s && *s != ':'; s++ )
- ; /* NULL */
- if ( *s == '\0' ) {
- Debug( LDAP_DEBUG_PARSE, "parse_line missing ':'\n", 0, 0, 0 );
- return( -1 );
+ for(s = line; *s && *s != ':'; s++); /* NULL */
+ if(*s == '\0') {
+ Debug(LDAP_DEBUG_PARSE, "parse_line missing ':'\n", 0, 0,
+ 0);
+ return (-1);
}
/* trim any space between type and : */
- for ( p = s - 1; p > line && ISSPACE( *p ); p-- ) {
+ for(p = s - 1; p > line && ISSPACE(*p); p--) {
*p = '\0';
}
*s++ = '\0';
/* check for double : - indicates base 64 encoded value */
- if ( *s == ':' ) {
+ if(*s == ':') {
s++;
b64 = 1;
- /* single : - normally encoded value */
+ /* single : - normally encoded value */
} else {
b64 = 0;
}
/* skip space between : and value */
- while ( ISSPACE( *s ) ) {
+ while(ISSPACE(*s)) {
s++;
}
/* if no value is present, error out */
- if ( *s == '\0' ) {
- Debug( LDAP_DEBUG_PARSE, "parse_line missing value\n", 0,0,0 );
- return( -1 );
+ if(*s == '\0') {
+ Debug(LDAP_DEBUG_PARSE, "parse_line missing value\n", 0, 0,
+ 0);
+ return (-1);
}
/* check for continued line markers that should be deleted */
- for ( p = s, d = s; *p; p++ ) {
- if ( *p != CONTINUED_LINE_MARKER )
+ for(p = s, d = s; *p; p++) {
+ if(*p != CONTINUED_LINE_MARKER)
*d++ = *p;
}
*d = '\0';
*value = s;
- if ( b64 ) {
- stop = strchr( s, '\0' );
+ if(b64) {
+ stop = strchr(s, '\0');
byte = s;
- for ( p = s, *vlen = 0; p < stop; p += 4, *vlen += 3 ) {
- for ( i = 0; i < 3; i++ ) {
- if ( p[i] != '=' && (p[i] & 0x80 ||
- b642nib[ p[i] & 0x7f ] > 0x3f) ) {
- Debug( LDAP_DEBUG_ANY,
- "invalid base 64 encoding char (%c) 0x%x\n",
- p[i], p[i], 0 );
- return( -1 );
+ for(p = s, *vlen = 0; p < stop; p += 4, *vlen += 3) {
+ for(i = 0; i < 3; i++) {
+ if(p[i] != '=' && (p[i] & 0x80 ||
+ b642nib[p[i] & 0x7f] >
+ 0x3f)) {
+ Debug(LDAP_DEBUG_ANY,
+ "invalid base 64 encoding char (%c) 0x%x\n",
+ p[i], p[i], 0);
+ return (-1);
}
}
/* first digit */
- nib = b642nib[ p[0] & 0x7f ];
+ nib = b642nib[p[0] & 0x7f];
byte[0] = nib << 2;
/* second digit */
- nib = b642nib[ p[1] & 0x7f ];
+ nib = b642nib[p[1] & 0x7f];
byte[0] |= nib >> 4;
byte[1] = (nib & RIGHT4) << 4;
/* third digit */
- if ( p[2] == '=' ) {
+ if(p[2] == '=') {
*vlen += 1;
break;
}
- nib = b642nib[ p[2] & 0x7f ];
+ nib = b642nib[p[2] & 0x7f];
byte[1] |= nib >> 2;
byte[2] = (nib & RIGHT2) << 6;
/* fourth digit */
- if ( p[3] == '=' ) {
+ if(p[3] == '=') {
*vlen += 2;
break;
}
- nib = b642nib[ p[3] & 0x7f ];
+ nib = b642nib[p[3] & 0x7f];
byte[2] |= nib;
byte += 3;
}
- s[ *vlen ] = '\0';
+ s[*vlen] = '\0';
} else {
*vlen = (int) (d - s);
}
- return( 0 );
+ return (0);
}
#if 0
*/
char *
-str_getline( char **next )
+str_getline(char **next)
{
- char *l;
- char c;
+ char *l;
+ char c;
- if ( *next == NULL || **next == '\n' || **next == '\0' ) {
- return( NULL );
+ if(*next == NULL || **next == '\n' || **next == '\0') {
+ return (NULL);
}
l = *next;
- while ( (*next = strchr( *next, '\n' )) != NULL ) {
+ while((*next = strchr(*next, '\n')) != NULL) {
c = *(*next + 1);
- if ( ISSPACE( c ) && c != '\n' ) {
+ if(ISSPACE(c) && c != '\n') {
**next = CONTINUED_LINE_MARKER;
- *(*next+1) = CONTINUED_LINE_MARKER;
+ *(*next + 1) = CONTINUED_LINE_MARKER;
} else {
*(*next)++ = '\0';
break;
(*next)++;
}
- return( l );
+ return (l);
}
#endif
void
-put_type_and_value( char **out, char *t, char *val, int vlen )
+put_type_and_value(char **out, char *t, char *val, int vlen)
{
- unsigned char *byte, *p, *stop;
- unsigned char buf[3];
- unsigned long bits;
- char *save;
- int i, b64, pad, len, savelen;
+ unsigned char *byte, *p, *stop;
+ unsigned char buf[3];
+ unsigned long bits;
+ char *save;
+ int i, b64, pad, len, savelen;
len = 0;
/* put the type + ": " */
- for ( p = (unsigned char *) t; *p; p++, len++ ) {
+ for(p = (unsigned char *) t; *p; p++, len++) {
*(*out)++ = *p;
}
*(*out)++ = ':';
b64 = 0;
stop = (unsigned char *) (val + vlen);
- if ( isascii( val[0] ) && (ISSPACE( val[0] ) || val[0] == ':') ) {
+ if(isascii(val[0]) && (ISSPACE(val[0]) || val[0] == ':')) {
b64 = 1;
} else {
- for ( byte = (unsigned char *) val; byte < stop;
- byte++, len++ ) {
- if ( !isascii( *byte ) || !isprint( *byte ) ) {
+ for(byte = (unsigned char *) val; byte < stop;
+ byte++, len++) {
+ if(!isascii(*byte) || !isprint(*byte)) {
b64 = 1;
break;
}
- if ( len > LDIF_LINE_WIDTH ) {
+ if(len > LDIF_LINE_WIDTH) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
*(*out)++ = *byte;
}
}
- if ( b64 ) {
+ if(b64) {
*out = save;
*(*out)++ = ':';
*(*out)++ = ' ';
len = savelen + 2;
/* convert to base 64 (3 bytes => 4 base 64 digits) */
- for ( byte = (unsigned char *) val; byte < stop - 2;
- byte += 3 ) {
+ for(byte = (unsigned char *) val; byte < stop - 2;
+ byte += 3) {
bits = (byte[0] & 0xff) << 16;
bits |= (byte[1] & 0xff) << 8;
bits |= (byte[2] & 0xff);
- for ( i = 0; i < 4; i++, len++, bits <<= 6 ) {
- if ( len > LDIF_LINE_WIDTH ) {
+ for(i = 0; i < 4; i++, len++, bits <<= 6) {
+ if(len > LDIF_LINE_WIDTH) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
}
/* get b64 digit from high order 6 bits */
- *(*out)++ = nib2b64[ (bits & 0xfc0000L) >> 18 ];
+ *(*out)++ =
+ nib2b64[(bits & 0xfc0000L) >> 18];
}
}
/* add padding if necessary */
- if ( byte < stop ) {
- for ( i = 0; byte + i < stop; i++ ) {
+ if(byte < stop) {
+ for(i = 0; byte + i < stop; i++) {
buf[i] = byte[i];
}
- for ( pad = 0; i < 3; i++, pad++ ) {
+ for(pad = 0; i < 3; i++, pad++) {
buf[i] = '\0';
}
byte = buf;
bits |= (byte[1] & 0xff) << 8;
bits |= (byte[2] & 0xff);
- for ( i = 0; i < 4; i++, len++, bits <<= 6 ) {
- if ( len > LDIF_LINE_WIDTH ) {
+ for(i = 0; i < 4; i++, len++, bits <<= 6) {
+ if(len > LDIF_LINE_WIDTH) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
}
/* get b64 digit from low order 6 bits */
- *(*out)++ = nib2b64[ (bits & 0xfc0000L) >> 18 ];
+ *(*out)++ =
+ nib2b64[(bits & 0xfc0000L) >> 18];
}
- for ( ; pad > 0; pad-- ) {
+ for(; pad > 0; pad--) {
*(*out - pad) = '=';
}
}
char *
-ldif_type_and_value( char *type, char *val, int vlen )
+ldif_type_and_value(char *type, char *val, int vlen)
/*
* return malloc'd, zero-terminated LDIF line
*/
{
- char *buf, *p;
- int tlen;
- size_t bufsize, t;
+ char *buf, *p;
+ int tlen;
+ size_t bufsize, t;
- tlen = strlen( type );
+ tlen = strlen(type);
- t = LDIF_SIZE_NEEDED( tlen, vlen );
- if((bufsize = t + 1) <= t)
- return NULL;
+ t = LDIF_SIZE_NEEDED(tlen, vlen);
+ if((bufsize = t + 1) <= t)
+ return NULL;
- if (( buf = (char *)malloc( bufsize )) == NULL ) {
- return NULL;
- }
+ if((buf = malloc(bufsize)) == NULL) {
+ return NULL;
+ }
- p = buf;
- put_type_and_value( &p, type, val, vlen );
- *p = '\0';
+ p = buf;
+ put_type_and_value(&p, type, val, vlen);
+ *p = '\0';
- return( buf );
+ return (buf);
}
-
/*
- * $Id: list.c,v 1.21 2004/06/30 19:47:43 jheinonen Exp $
+ * $Id: list.c,v 1.26 2005/08/13 10:49:25 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
#include "list.h"
#include "misc.h"
#include "options.h"
+#include "xmalloc.h"
#define MIN_EXTRA_COLUMN ADDRESS /* 2 */
#define MAX_EXTRA_COLUMN LAST_FIELD
extern list_item *database;
extern struct abook_field abook_fields[];
-WINDOW *list = NULL;
+static WINDOW *list = NULL;
static int
init_extra_field(enum str_opts option)
refresh_list()
{
int i, line;
-
+
werase(list);
ui_print_number_of_items();
-
- if(items < 1) {
+
+ if(list_is_empty()) {
refresh();
wrefresh(list);
return;
}
-
+
if(curitem < 0)
curitem = 0;
print_list_line(i, line, i == curitem);
}
+ if(opt_get_bool(BOOL_SHOW_CURSOR)) {
+ wmove(list, curitem - first_list_item, 0);
+ /* need to call refresh() to update the cursor positions */
+ refresh();
+ }
wrefresh(list);
}
if(selected[i])
mvwaddch(list, line, 0, '*' );
-
+
mvwaddnstr(list, line, NAMEPOS, database[i][NAME],
bytes2width(database[i][NAME], NAMELEN));
if(opt_get_bool(BOOL_SHOW_ALL_EMAILS))
if(highlight)
wstandend(list);
}
-
+
void
list_headerline()
{
if(curitem < 1)
return;
-
+
curitem = curitem == first_list_item ?
((curitem -= LIST_LINES) < 0 ? 0 : curitem) : first_list_item;
-
+
refresh_list();
}
{
if(items > 0)
curitem = 0;
-
+
refresh_list();
}
return 1;
for(i = 0; i < ITEM_FIELDS; i++)
- item[i] = database[curitem][i] ? strdup(database[curitem][i]) :
+ item[i] = database[curitem][i] ? xstrdup(database[curitem][i]) :
NULL;
if(add_item2database(item))
/*
- * $Id: misc.c,v 1.14 2004/02/18 19:40:57 jheinonen Exp $
+ * $Id: misc.c,v 1.19 2005/08/11 07:32:35 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
* Copyright (C) Jaakko Heinonen
+ * getaline() Copyright (C) Lars Wirzenius
+ * sprintf and snprintf copyright is owned by various people
*/
-#define ABOOK_SRC 1
-/*#undef ABOOK_SRC*/
-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
# include <mbswidth.h>
#endif
#include "misc.h"
-#ifdef ABOOK_SRC
-# include "abook.h"
-#endif
+#include "xmalloc.h"
#ifndef DEBUG
# define NDEBUG 1
assert(s != NULL);
- for(t = s; ISSPACE(*t); t++);
+ for(t = s; isspace(*t); t++);
memmove(s, t, strlen(t)+1);
for (tt = t = s; *t != '\0'; t++)
- if(!ISSPACE(*t))
+ if(!isspace(*t))
tt = t+1;
*tt = '\0';
{
MY_VA_LOCAL_DECL;
size_t size = 100;
- char *buffer =
-#ifdef ABOOK_SRC
- (char *) abook_malloc (size);
-#else
- (char *) xmalloc (size);
-#endif
-
+ char *buffer = xmalloc (size);
+
assert(format != NULL);
for(;;) {
size = n + 1;
else
size *= 2;
-
- buffer =
-#ifdef ABOOK_SRC
- (char *) abook_realloc (buffer, size);
-#else
- (char *) xrealloc (buffer, size);
-#endif
+
+ buffer = xrealloc(buffer, size);
}
}
MY_VA_SHIFT(s, char*);
}
MY_VA_END;
-
- concat = (char *)
-#ifdef ABOOK_SRC
- abook_malloc(l);
-#else
- xmalloc(l);
-#endif
- if(concat == NULL)
- return NULL;
+
+ concat = xmalloc(l);
strcpy (concat, str);
MY_VA_START(str);
char *dir = NULL;
size_t size = 100;
- if( (dir = (char *)malloc(size)) == NULL)
+ if( (dir = xmalloc(size)) == NULL)
return NULL;
*dir = 0;
-
+
while( getcwd(dir, size) == NULL && errno == ERANGE )
- if( (dir = (char *)realloc(dir, size *=2)) == NULL)
+ if( (dir = xrealloc(dir, size *=2)) == NULL)
return NULL;
return dir;
}
-#define INITIAL_SIZE 128
-#ifndef ABOOK_SRC
-# define abook_malloc(X) xmalloc(X)
-# define abook_realloc(X, XX) xrealloc(X, XX)
-#endif
+/*
+ * getaline()
+ *
+ * Copyright (c) 1994 Lars Wirzenius
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
char *
getaline(FILE *f)
len = 0;
size = thres;
- buf = (char *)abook_malloc(size);
+ buf = xmalloc(size);
while (fgets(buf+len, size-len, f) != NULL) {
len += strlen(buf+len);
break; /* the whole line has been read */
for (inc = size, p = NULL; inc > mininc; inc /= 2)
- if ((p = (char *)abook_realloc(buf, size + inc)) !=
+ if ((p = xrealloc_inc(buf, size, inc)) !=
NULL)
break;
}
if (len == 0) {
- free(buf);
+ xfree(buf);
return NULL; /* nothing read (eof or error) */
}
buf[--len] = '\0';
if (size - len > mucho) { /* a plenitude of unused memory? */
- p = (char *)abook_realloc(buf, len+1);
+ p = xrealloc_inc(buf, len, 1);
if (p != NULL) {
buf = p;
size = len+1;
* original. Also, there is now a builtin-test, just compile with:
* gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
* and run snprintf for results.
- *
+ *
* Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
- * The PGP code was using unsigned hexadecimal formats.
+ * The PGP code was using unsigned hexadecimal formats.
* Unfortunately, unsigned formats simply didn't work.
*
* Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
/*int snprintf (char *str, size_t count, const char *fmt, ...);*/
/*int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);*/
-static void dopr (char *buffer, size_t maxlen, const char *format,
+static void dopr (char *buffer, size_t maxlen, const char *format,
va_list args);
static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max);
int flags;
int cflags;
size_t currlen;
-
+
state = DP_S_DEFAULT;
currlen = flags = cflags = min = 0;
max = -1;
while (state != DP_S_DONE)
{
- if ((ch == '\0') || (currlen >= maxlen))
+ if ((ch == '\0') || (currlen >= maxlen))
state = DP_S_DONE;
- switch(state)
+ switch(state)
{
case DP_S_DEFAULT:
- if (ch == '%')
+ if (ch == '%')
state = DP_S_FLAGS;
- else
+ else
dopr_outch (buffer, &currlen, maxlen, ch);
ch = *format++;
break;
case DP_S_FLAGS:
- switch (ch)
+ switch (ch)
{
case '-':
flags |= DP_F_MINUS;
}
break;
case DP_S_MIN:
- if (isdigit((unsigned char)ch))
+ if (isdigit((unsigned char)ch))
{
min = 10*min + char_to_int (ch);
ch = *format++;
- }
- else if (ch == '*')
+ }
+ else if (ch == '*')
{
min = va_arg (args, int);
ch = *format++;
state = DP_S_DOT;
- }
- else
+ }
+ else
state = DP_S_DOT;
break;
case DP_S_DOT:
- if (ch == '.')
+ if (ch == '.')
{
state = DP_S_MAX;
ch = *format++;
- }
- else
+ }
+ else
state = DP_S_MOD;
break;
case DP_S_MAX:
- if (isdigit((unsigned char)ch))
+ if (isdigit((unsigned char)ch))
{
if (max < 0)
max = 0;
max = 10*max + char_to_int (ch);
ch = *format++;
- }
- else if (ch == '*')
+ }
+ else if (ch == '*')
{
max = va_arg (args, int);
ch = *format++;
state = DP_S_MOD;
- }
- else
+ }
+ else
state = DP_S_MOD;
break;
case DP_S_MOD:
/* Currently, we don't support Long Long, bummer */
- switch (ch)
+ switch (ch)
{
case 'h':
cflags = DP_C_SHORT;
state = DP_S_CONV;
break;
case DP_S_CONV:
- switch (ch)
+ switch (ch)
{
case 'd':
case 'i':
- if (cflags == DP_C_SHORT)
+ if (cflags == DP_C_SHORT)
value = va_arg (args, short int);
else if (cflags == DP_C_LONG)
value = va_arg (args, long int);
break;
case 's':
strvalue = va_arg (args, char *);
- if (max < 0)
+ if (max < 0)
max = maxlen; /* ie, no max */
fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
break;
fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
break;
case 'n':
- if (cflags == DP_C_SHORT)
+ if (cflags == DP_C_SHORT)
{
short int *num;
num = va_arg (args, short int *);
*num = currlen;
- }
- else if (cflags == DP_C_LONG)
+ }
+ else if (cflags == DP_C_LONG)
{
long int *num;
num = va_arg (args, long int *);
*num = currlen;
- }
- else
+ }
+ else
{
int *num;
num = va_arg (args, int *);
break; /* some picky compilers need this */
}
}
- if (currlen < maxlen - 1)
+ if (currlen < maxlen - 1)
buffer[currlen] = '\0';
- else
+ else
buffer[maxlen - 1] = '\0';
}
{
int padlen, strln; /* amount to pad */
int cnt = 0;
-
+
if (value == 0)
{
value = "<NULL>";
for (strln = 0; value[strln]; ++strln); /* strlen */
padlen = min - strln;
- if (padlen < 0)
+ if (padlen < 0)
padlen = 0;
- if (flags & DP_F_MINUS)
+ if (flags & DP_F_MINUS)
padlen = -padlen; /* Left Justify */
- while ((padlen > 0) && (cnt < max))
+ while ((padlen > 0) && (cnt < max))
{
dopr_outch (buffer, currlen, maxlen, ' ');
--padlen;
++cnt;
}
- while (*value && (cnt < max))
+ while (*value && (cnt < max))
{
dopr_outch (buffer, currlen, maxlen, *value++);
++cnt;
}
- while ((padlen < 0) && (cnt < max))
+ while ((padlen < 0) && (cnt < max))
{
dopr_outch (buffer, currlen, maxlen, ' ');
++padlen;
int spadlen = 0; /* amount to space pad */
int zpadlen = 0; /* amount to zero pad */
int caps = 0;
-
+
if (max < 0)
max = 0;
if (flags & DP_F_SPACE)
signvalue = ' ';
}
-
+
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
do {
zpadlen = MAX(zpadlen, spadlen);
spadlen = 0;
}
- if (flags & DP_F_MINUS)
+ if (flags & DP_F_MINUS)
spadlen = -spadlen; /* Left Justifty */
#ifdef DEBUG_SNPRINTF
#endif
/* Spaces */
- while (spadlen > 0)
+ while (spadlen > 0)
{
dopr_outch (buffer, currlen, maxlen, ' ');
--spadlen;
}
/* Sign */
- if (signvalue)
+ if (signvalue)
dopr_outch (buffer, currlen, maxlen, signvalue);
/* Zeros */
- if (zpadlen > 0)
+ if (zpadlen > 0)
{
while (zpadlen > 0)
{
}
/* Digits */
- while (place > 0)
+ while (place > 0)
dopr_outch (buffer, currlen, maxlen, convert[--place]);
-
+
/* Left Justified spaces */
while (spadlen < 0) {
dopr_outch (buffer, currlen, maxlen, ' ');
result *= 10;
exp--;
}
-
+
return result;
}
int iplace = 0;
int fplace = 0;
int padlen = 0; /* amount to pad */
- int zpadlen = 0;
+ int zpadlen = 0;
int caps = 0;
long intpart;
long fracpart;
-
- /*
+
+ /*
* AIX manpage says the default is 0, but Solaris says the default
* is 6, and sprintf on AIX defaults to 6
*/
intpart = ufvalue;
- /*
- * Sorry, we only support 9 digits past the decimal because of our
+ /*
+ * Sorry, we only support 9 digits past the decimal because of our
* conversion method
*/
if (max > 9)
fconvert[fplace] = 0;
/* -1 for decimal point, another -1 if we are printing a sign */
- padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
+ padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
zpadlen = max - fplace;
if (zpadlen < 0)
zpadlen = 0;
- if (padlen < 0)
+ if (padlen < 0)
padlen = 0;
- if (flags & DP_F_MINUS)
+ if (flags & DP_F_MINUS)
padlen = -padlen; /* Left Justifty */
- if ((flags & DP_F_ZERO) && (padlen > 0))
+ if ((flags & DP_F_ZERO) && (padlen > 0))
{
- if (signvalue)
+ if (signvalue)
{
dopr_outch (buffer, currlen, maxlen, signvalue);
--padlen;
dopr_outch (buffer, currlen, maxlen, ' ');
--padlen;
}
- if (signvalue)
+ if (signvalue)
dopr_outch (buffer, currlen, maxlen, signvalue);
- while (iplace > 0)
+ while (iplace > 0)
dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
/*
*/
dopr_outch (buffer, currlen, maxlen, '.');
- while (fplace > 0)
+ while (fplace > 0)
dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
while (zpadlen > 0)
--zpadlen;
}
- while (padlen < 0)
+ while (padlen < 0)
{
dopr_outch (buffer, currlen, maxlen, ' ');
++padlen;
char *fmt;
#endif
VA_LOCAL_DECL;
-
+
VA_START (fmt);
VA_SHIFT (str, char *);
VA_SHIFT (count, size_t );
"%3.2f",
NULL
};
- double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
+ double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
0.9996, 1.996, 4.136, 0};
char *int_fmt[] = {
"%-1.5d",
sprintf (buf2, fp_fmt[x], fp_nums[y]);
if (strcmp (buf1, buf2))
{
- printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n",
+ printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n",
fp_fmt[x], buf1, buf2);
fail++;
}
sprintf (buf2, int_fmt[x], int_nums[y]);
if (strcmp (buf1, buf2))
{
- printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n",
+ printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n",
int_fmt[x], buf1, buf2);
fail++;
}
/*
- * $Id: options.c,v 1.21 2003/12/05 18:11:55 jheinonen Exp $
+ * $Id: options.c,v 1.25 2005/08/13 10:49:25 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
#include "options.h"
#include "abook.h"
#include "misc.h"
+#include "xmalloc.h"
#ifndef FALSE
# define FALSE 0
{ "mutt_command", OT_STR, STR_MUTT_COMMAND, UL "mutt" },
{ "mutt_return_all_emails", OT_BOOL, BOOL_MUTT_RETURN_ALL_EMAILS,
TRUE },
-
+
{ "print_command", OT_STR, STR_PRINT_COMMAND, UL "lpr" },
{ "www_command", OT_STR, STR_WWW_COMMAND, UL "lynx" },
-
+
{ "address_style", OT_STR, STR_ADDRESS_STYLE, UL "eu" },
{ "use_ascii_only", OT_BOOL, BOOL_USE_ASCII_ONLY, FALSE },
{ "add_email_prevent_duplicates", OT_BOOL, BOOL_ADD_EMAIL_PREVENT_DUPLICATES, FALSE },
{ "sort_field", OT_STR, STR_SORT_FIELD, UL "nick" },
+ { "show_cursor", OT_BOOL, BOOL_SHOW_CURSOR, FALSE },
{ NULL }
};
if(str_opts[opt])
free(str_opts[opt]);
- str_opts[opt] = strdup(value);
+ str_opts[opt] = xstrdup(value);
}
int
find_token_start(buffer *b)
{
assert(b);
-
+
for(; ISSPACE(*b -> ptr); b -> ptr ++);
}
opt_set_set_option(char *var, char *p, struct option *opt)
{
int len;
-
+
strtrim(p);
len = strlen(p);
default:
assert(0);
}
-
+
return NULL;
}
*p++ = 0;
else
return "invalid value assignment";
-
+
strtrim(b -> ptr);
for(i = 0;abook_vars[i].option; i++)
if(!strcmp(abook_vars[i].option, b -> ptr))
return opt_set_set_option(b -> ptr, p, &abook_vars[i]);
-
+
return "unknown option";
}
char *err = NULL;
char *token;
buffer b;
-
+
assert(line && fn);
b.ptr = line;
return FALSE;
break;
}
-
+
fprintf(stderr, "%s: parse error at line %d: ", fn, n);
if(err)
fprintf(stderr, "%s\n", err);
char *line = NULL;
int n;
int err = 0;
-
+
if((in = fopen(filename, "r")) == NULL)
return -1;
-
+
for(n = 1;!feof(in); n++) {
line = getaline(in);
err += opt_parse_line(line, n, filename) ? 1:0;
}
- my_free(line);
+ free(line);
+ line = NULL;
}
free(line);
BOOL_MUTT_RETURN_ALL_EMAILS,
BOOL_USE_ASCII_ONLY,
BOOL_ADD_EMAIL_PREVENT_DUPLICATES,
+ BOOL_SHOW_CURSOR,
BOOL_MAX
};
# field to be used with "sort by field" command
set sort_field=nick
+# show cursor in main display
+set show_cursor=false
+
# custom fields
#customfield 1 Name1
/*
- * $Id: ui.c,v 1.31 2004/04/19 17:08:00 jheinonen Exp $
+ * $Id: ui.c,v 1.39 2005/08/23 10:03:34 jheinonen Exp $
*
* by JH <jheinonen@users.sourceforge.net>
*
#include "misc.h"
#include "options.h"
#include "filter.h"
+#include "xmalloc.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#ifdef HAVE_TERMIOS_H
-# include <termios.h>
-#else
-# ifdef HAVE_LINUX_TERMIOS_H
-# include <linux/termios.h>
-# endif
-#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
extern int items, curitem;
extern char *datafile;
-extern int alternative_datafile;
+extern bool alternative_datafile;
/*
* internal variables
*/
-bool ui_initialized = FALSE;
+static bool ui_initialized = FALSE;
-bool should_resize = FALSE;
-bool can_resize = FALSE;
+static bool should_resize = FALSE;
+static bool can_resize = FALSE;
-WINDOW *top = NULL, *bottom = NULL;
+static WINDOW *top = NULL, *bottom = NULL;
static void
init_windows()
{
top = newwin(LIST_TOP - 1, COLS, 0, 0);
-
bottom = newwin(LINES - LIST_BOTTOM, COLS, LIST_BOTTOM, 0);
}
#ifdef TIOCGWINSZ
struct winsize winsz;
- ioctl (0, TIOCGWINSZ, &winsz);
+ ioctl(0, TIOCGWINSZ, &winsz);
#ifdef DEBUG
if(winsz.ws_col >= MIN_COLS && winsz.ws_row >= MIN_LINES) {
fprintf(stderr, "Warning: COLS=%d, LINES=%d\n", winsz.ws_col, winsz.ws_row);
}
#endif
-
+
if(winsz.ws_col >= MIN_COLS && winsz.ws_row >= MIN_LINES) {
#ifdef HAVE_RESIZETERM
resizeterm(winsz.ws_row, winsz.ws_col);
static void
win_changed(int i)
{
- if( can_resize )
+ if(can_resize)
resize_abook();
else
- should_resize = TRUE;
+ should_resize = TRUE;
}
#endif /* SIGWINCH */
return 1;
}
-#ifdef SIGWINCH
- signal(SIGWINCH, win_changed);
-#endif
-
init_list();
init_windows();
ui_initialized = TRUE;
+#ifdef SIGWINCH
+ signal(SIGWINCH, win_changed);
+#endif
+
return 0;
}
refresh_screen()
{
#ifdef SIGWINCH
- if( should_resize ) {
+ if(should_resize) {
resize_abook();
return;
}
statusline_msg(char *msg)
{
int c;
-
+
clear_statusline();
statusline_addstr(msg);
c = getch();
free(msg2);
- switch( tolower(getch()) ) {
+ switch(tolower(getch())) {
case 'n':
+ case 'N':
ret = FALSE;
break;
case 'y':
+ case 'Y':
ret = TRUE;
break;
default:
return ret;
}
-
void
refresh_statusline()
{
wrefresh(bottom);
}
-
char *
ask_filename(char *prompt)
{
erase();
headerline("help");
- for( i = 0; tbl[i] != NULL; i++) {
+ for(i = 0; tbl[i] != NULL; i++) {
waddstr(helpw, tbl[i]);
- if( ( !( (i+1) % (LINES-8) ) ) ||
- (tbl[i+1] == NULL) ) {
+ if( (!((i + 1) % (LINES - 8))) ||
+ (tbl[i + 1] == NULL) ) {
refresh();
wrefresh(helpw);
refresh_statusline();
for(;;) {
can_resize = TRUE; /* it's safe to resize now */
- hide_cursor();
- if( should_resize )
+ if(!opt_get_bool(BOOL_SHOW_CURSOR))
+ hide_cursor();
+ if(should_resize)
refresh_screen();
ch = getch();
- show_cursor();
+ if(!opt_get_bool(BOOL_SHOW_CURSOR))
+ show_cursor();
can_resize = FALSE; /* it's not safe to resize anymore */
- switch( ch ) {
+ switch(ch) {
case 'q': return;
case 'Q': quit_abook(QUIT_DONTSAVE); break;
case 'P': print_stderr(selected_items() ?
}
}
-
void
ui_remove_items()
{
if(statusline_ask_boolean("Remove selected item(s)", TRUE))
remove_selected_items();
- clear_statusline();
+ clear_statusline();
refresh_list();
}
clear_statusline();
if(next) {
- if( !*findstr )
+ if(!*findstr)
return;
} else {
char *s;
char *command = opt_get_str(STR_PRINT_COMMAND);
int mode;
- if( list_is_empty() )
+ if(list_is_empty())
return;
statusline_addstr("Print All/Selected/Cancel (a/s/C)?");
- switch( tolower(getch()) ) {
+ switch(tolower(getch())) {
case 'a':
mode = ENUM_ALL;
break;
return;
fexport("text", handle, mode);
-
+
pclose(handle);
}
filename = ask_filename("File to open: ");
- if( !filename || ! *filename) {
+ if(!filename || ! *filename) {
free(filename);
refresh_screen();
return;
}
- if( opt_get_bool(BOOL_AUTOSAVE) )
+ if(opt_get_bool(BOOL_AUTOSAVE))
save_database();
else if(statusline_ask_boolean("Save current database", FALSE))
save_database();
load_database(filename);
- if( items == 0 ) {
+ if(items == 0) {
statusline_msg("Sorry, that specified file appears not to be a valid abook addressbook");
load_database(datafile);
} else {
free(datafile);
- datafile = strdup(filename);
+ datafile = xstrdup(filename);
}
refresh_screen();
void ui_open_datafile();
-#include "options.h" /* needed for options_get_int */
+#include "options.h" /* needed for options_get_bool */
#define UI_HLINE_CHAR opt_get_bool(BOOL_USE_ASCII_ONLY) ? \
'-' : ACS_HLINE
--- /dev/null
+/*
+ * $Id: xmalloc.c,v 1.5 2005/08/13 10:49:25 jheinonen Exp $
+ *
+ * Common xmalloc memory allocation routines
+ *
+ * written by Jaakko Heinonen <jheinonen@users.sourceforge.net>
+ */
+
+/*
+ * Copyright (c) 2005 Jaakko Heinonen
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "xmalloc.h"
+
+static void
+xmalloc_default_error_handler(int err)
+{
+ fprintf(stderr, "Memory allocation failure: %s\n", strerror(err));
+ exit(EXIT_FAILURE);
+}
+
+static void (*xmalloc_handle_error)(int err) = xmalloc_default_error_handler;
+
+void
+xmalloc_set_error_handler(void (*func)(int err))
+{
+ if(func)
+ xmalloc_handle_error = func;
+ else
+ xmalloc_handle_error = xmalloc_default_error_handler;
+}
+
+void *
+xmalloc(size_t size)
+{
+ void *p;
+
+ if((p = malloc(size)) == NULL)
+ (*xmalloc_handle_error)(errno);
+
+ return p;
+}
+
+void *
+xmalloc0(size_t size)
+{
+ void *p;
+
+ p = xmalloc(size);
+ if(p)
+ memset(p, 0, size);
+
+ return p;
+}
+
+static void *
+_xmalloc_inc(size_t size, size_t inc, int zero)
+{
+ size_t total_size = size + inc;
+
+ /*
+ * check if the calculation overflowed
+ */
+ if(total_size < size) {
+ (*xmalloc_handle_error)(EINVAL);
+ return NULL;
+ }
+
+ return zero ? xmalloc0(total_size) : xmalloc(total_size);
+}
+
+void *
+xmalloc_inc(size_t size, size_t inc)
+{
+ return _xmalloc_inc(size, inc, 0);
+}
+
+void *
+xmalloc0_inc(size_t size, size_t inc)
+{
+ return _xmalloc_inc(size, inc, 1);
+}
+
+void *
+xrealloc(void *ptr, size_t size)
+{
+ if((ptr = realloc(ptr, size)) == NULL)
+ (*xmalloc_handle_error)(errno);
+
+ return ptr;
+}
+
+void *
+xrealloc_inc(void *ptr, size_t size, size_t inc)
+{
+ size_t total_size = size + inc;
+
+ /*
+ * check if the calculation overflowed
+ */
+ if(total_size < size) {
+ (*xmalloc_handle_error)(EINVAL);
+ return NULL;
+ }
+
+ if((ptr = realloc(ptr, total_size)) == NULL)
+ (*xmalloc_handle_error)(errno);
+
+ return ptr;
+}
+
+char *
+xstrdup(const char *s)
+{
+ size_t len = strlen(s);
+ void *new;
+
+ new = xmalloc_inc(len, 1);
+ if(new == NULL)
+ return NULL;
+
+ return (char *)memcpy(new, s, len + 1);
+}
+
--- /dev/null
+#ifndef _XMALLOC_H
+#define _XMALLOC_H
+
+#include <stdlib.h> /* for size_t */
+
+/*
+ * avoid possible collision with readline xmalloc functions
+ */
+
+#define xmalloc _xmalloc_xmalloc
+#define xrealloc _xmalloc_xrealloc
+
+void xmalloc_set_error_handler(void (*)(int));
+void * xmalloc(size_t);
+void * xmalloc0(size_t);
+void * xmalloc_inc(size_t, size_t);
+void * xrealloc(void *, size_t);
+void * xrealloc_inc(void *, size_t, size_t);
+char * xstrdup(const char *s);
+
+#define xfree(ptr) do { free(ptr); ptr = NULL; } while(0)
+
+#endif