From addc54efb596b39b0e4e6ce219ee0f1506337475 Mon Sep 17 00:00:00 2001 From: Gerfried Fuchs Date: Thu, 22 Mar 2012 17:32:42 +0100 Subject: [PATCH] Imported Upstream version 0.5.4 --- BUGS | 23 ++- ChangeLog | 9 ++ FAQ | 6 +- Makefile.am | 4 +- Makefile.in | 42 +++-- NEWS | 2 +- THANKS | 6 + abook.c | 141 +++++++---------- abook.h | 8 +- abook.spec | 4 +- abook.spec.in | 2 +- abook_rl.c | 75 ++++++--- abookrc.5 | 7 + aclocal.m4 | 178 +++++++++++++++++---- config.h.in | 6 - configure | 74 +++++---- configure.in | 6 +- contrib/ldap-abook/comms.pl-en | 2 +- contrib/ldap-abook/ldap2abook | 11 +- database.c | 122 +++++++------- database.h | 2 +- edit.c | 131 ++++++++-------- edit.h | 2 +- filter.c | 279 ++++++++++++++++----------------- getname.c | 20 +-- getopt.c | 10 +- getopt1.c | 4 +- ldif.c | 187 +++++++++++----------- list.c | 30 ++-- misc.c | 222 +++++++++++++------------- options.c | 31 ++-- options.h | 1 + sample.abookrc | 3 + ui.c | 82 +++++----- ui.h | 2 +- xmalloc.c | 150 ++++++++++++++++++ xmalloc.h | 23 +++ 37 files changed, 1117 insertions(+), 790 deletions(-) create mode 100644 xmalloc.c create mode 100644 xmalloc.h diff --git a/BUGS b/BUGS index 7b4c3be..8899c06 100644 --- a/BUGS +++ b/BUGS @@ -1,19 +1,28 @@ 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 $ diff --git a/ChangeLog b/ChangeLog index ba73747..148d696 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +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 diff --git a/FAQ b/FAQ index 8295ade..f417c7b 100644 --- a/FAQ +++ b/FAQ @@ -27,7 +27,7 @@ A: When "To:" or "Cc:" prompt appears press ^t for query. (After query 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. @@ -49,7 +49,7 @@ A: Export to palmcsv format, and import from there. Several GUI 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: @@ -66,4 +66,4 @@ A: Yes, version 0.5.2 added multibyte character support. 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 $ diff --git a/Makefile.am b/Makefile.am index 342465d..bb6b505 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,9 +4,11 @@ bin_PROGRAMS = abook 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 diff --git a/Makefile.in b/Makefile.in index af64afe..d02c4a6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,4 @@ -# 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, @@ -36,6 +36,7 @@ POST_INSTALL = : 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 \ @@ -60,19 +61,13 @@ PROGRAMS = $(bin_PROGRAMS) 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) @@ -142,6 +137,8 @@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ 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@ @@ -173,9 +170,11 @@ target_alias = @target_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 @@ -284,21 +283,20 @@ distclean-compile: @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: @@ -386,15 +384,15 @@ distdir: $(DISTFILES) ! -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 @@ -407,7 +405,7 @@ dist-zip: 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 @@ -416,11 +414,11 @@ dist dist-all: distdir 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*) \ @@ -503,7 +501,7 @@ mostlyclean-generic: 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" diff --git a/NEWS b/NEWS index 8b13789..58378c1 100644 --- a/NEWS +++ b/NEWS @@ -1 +1 @@ - +See ChangeLog diff --git a/THANKS b/THANKS index 86c84cd..8a7017a 100644 --- a/THANKS +++ b/THANKS @@ -12,5 +12,11 @@ Gustavo Niemeyer Brian Medley Takahashi Tamotsu Liam K Morland +Cheryl Homiak +Christoph Sobotka +Morten Brix Pedersen +Jeff Covey +Giuseppe Corbelli +Mariusz Balewski See also AUTHORS diff --git a/abook.c b/abook.c index f29d597..3eacdc0 100644 --- a/abook.c +++ b/abook.c @@ -1,25 +1,26 @@ /* - * $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 * * Copyright (C) Jaakko Heinonen */ +#include +#include +#include #include -#include #include #include +#include #include -#include -#include -#include #ifdef HAVE_CONFIG_H # include "config.h" #endif #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE) # include #endif +#include #include "abook.h" #include "ui.h" #include "database.h" @@ -30,7 +31,7 @@ #include "options.h" #include "getname.h" #include "getopt.h" -#include +#include "xmalloc.h" static void init_abook(); static void quit_abook_sig(int i); @@ -44,7 +45,7 @@ static void convert(char *srcformat, char *srcfile, static void add_email(int); char *datafile = NULL; -char *rcfile = NULL; +static char *rcfile = NULL; bool alternative_datafile = FALSE; bool alternative_rcfile = FALSE; @@ -82,23 +83,37 @@ check_abook_directory() 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() { @@ -110,11 +125,10 @@ 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); @@ -129,7 +143,7 @@ init_abook() free_opts(); /*close_database();*/ close_ui(); - exit(1); + exit(EXIT_FAILURE); } } else load_database(datafile); @@ -153,7 +167,7 @@ quit_abook(int save_db) close_ui(); - exit(0); + exit(EXIT_SUCCESS); } static void @@ -168,12 +182,13 @@ main(int argc, char **argv) #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); @@ -183,8 +198,8 @@ main(int argc, char **argv) static void free_filenames() { - my_free(rcfile); - my_free(datafile); + xfree(rcfile); + xfree(datafile); } @@ -195,7 +210,7 @@ set_filenames() 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) @@ -228,7 +243,7 @@ change_mode(int *current, int mode) fprintf(stderr, "Cannot combine options --mutt-query, " "--convert, " "--add-email or --add-email-quiet\n"); - exit(1); + exit(EXIT_FAILURE); } *current = mode; @@ -244,7 +259,7 @@ set_filename(char **var, char *path) assert(path != NULL); if(*path == '/') { - *var = strdup(path); + *var = xstrdup(path); return; } @@ -258,7 +273,7 @@ set_filename(char **var, char *path) #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) @@ -312,7 +327,7 @@ parse_command_line(int argc, char **argv) switch(c) { case 'h': show_usage(); - exit(1); + exit(EXIT_SUCCESS); case OPT_ADD_EMAIL: change_mode(&mode, MODE_ADD_EMAIL); break; @@ -348,16 +363,16 @@ parse_command_line(int argc, char **argv) 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) { @@ -378,7 +393,7 @@ show_usage() { puts (PACKAGE " v " VERSION "\n"); puts (" -h --help show usage"); - puts (" -C --config use an alternative configuration file"); + puts (" -C --config use an alternative configuration file"); puts (" --datafile use an alternative addressbook file"); puts (" --mutt-query make a query for mutt"); puts (" --add-email " @@ -450,7 +465,7 @@ mutt_query(char *str) 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) { @@ -459,7 +474,7 @@ mutt_query(char *str) } } - quit_mutt_query(0); + quit_mutt_query(EXIT_SUCCESS); } static void @@ -471,8 +486,8 @@ init_mutt_query() if( load_database(datafile) ) { printf("Cannot open database\n"); - quit_mutt_query(1); - exit(1); + quit_mutt_query(EXIT_FAILURE); + exit(EXIT_FAILURE); } } @@ -488,7 +503,7 @@ make_mailstr(int item) ret = *database[item][EMAIL] ? mkstr("%s <%s>", name, email) : - strdup(name); + xstrdup(name); free(name); @@ -539,7 +554,7 @@ launch_mutt(int item) #ifdef DEBUG fprintf(stderr, "cmd: %s\n", cmd); #endif - system(cmd); + system(cmd); free(cmd); /* @@ -574,47 +589,14 @@ launch_wwwbrowser(int item) 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; @@ -637,7 +619,7 @@ convert(char *srcformat, char *srcfile, char *dstformat, char *dstfile) if( !strcasecmp(srcformat, dstformat) ) { printf( "input and output formats are the same\n" "exiting...\n"); - exit(1); + exit(EXIT_FAILURE); } #endif @@ -689,14 +671,14 @@ quit_add_email() 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 @@ -709,7 +691,6 @@ static void init_add_email() { set_filenames(); - atexit(free_filenames); check_abook_directory(); init_opts(); load_opts(rcfile); @@ -739,14 +720,14 @@ add_email_add_item(int quiet, char *name, char *email) 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 { @@ -764,8 +745,8 @@ add_email_add_item(int quiet, char *name, char *email) } 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; @@ -780,7 +761,7 @@ add_email(int quiet) 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(); @@ -791,10 +772,10 @@ add_email(int quiet) 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(); diff --git a/abook.h b/abook.h index 20bad88..0cdc513 100644 --- a/abook.h +++ b/abook.h @@ -3,8 +3,6 @@ #include -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); @@ -19,8 +17,8 @@ int strncasecmp (const char *, const char *, size_t); #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" @@ -39,9 +37,7 @@ int strncasecmp (const char *, const char *, size_t); #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)) diff --git a/abook.spec b/abook.spec index 9d62396..027d563 100644 --- a/abook.spec +++ b/abook.spec @@ -1,13 +1,13 @@ 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 diff --git a/abook.spec.in b/abook.spec.in index 445f32f..ffa96ae 100644 --- a/abook.spec.in +++ b/abook.spec.in @@ -7,7 +7,7 @@ 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 diff --git a/abook_rl.c b/abook_rl.c index b450d94..5d0c273 100644 --- a/abook_rl.c +++ b/abook_rl.c @@ -1,5 +1,5 @@ /* - * $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 * @@ -12,9 +12,6 @@ #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 @@ -23,12 +20,18 @@ # include #elif defined(HAVE_READLINE_H) # include +#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 #elif defined(HAVE_HISTORY_H) # include +#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 @@ -45,7 +48,7 @@ static bool rl_cancelled; static void rl_refresh() { - /*refresh();*/ + /* refresh(); */ wrefresh(rl_win); } @@ -59,13 +62,13 @@ rline_calc_point() 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), @@ -85,6 +88,39 @@ rline_compdisp(char **matches, int n, int max_len) /* 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) { @@ -99,19 +135,22 @@ static void 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 { @@ -124,7 +163,7 @@ abook_rl_init(bool use_completion) clear_history(); rl_cancelled = FALSE; -} +} char * abook_readline(WINDOW *w, int y, int x, char *s, int limit, bool use_completion) @@ -138,20 +177,8 @@ 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); diff --git a/abookrc.5 b/abookrc.5 index eaedf7d..0602c98 100644 --- a/abookrc.5 +++ b/abookrc.5 @@ -103,6 +103,10 @@ Defines whether to avoid adding addresses already in data. Default is false. \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 @@ -159,6 +163,9 @@ set add_email_prevent_duplicates=false # 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 diff --git a/aclocal.m4 b/aclocal.m4 index a95ead1..e97e770 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,4 +1,4 @@ -# 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. @@ -33,14 +33,14 @@ # ---------------------------- # 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 @@ -108,7 +108,7 @@ am_aux_dir=`cd $ac_aux_dir && pwd` # 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 @@ -145,8 +145,8 @@ else 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 -*- @@ -319,7 +319,8 @@ AC_SUBST([AMDEPBACKSLASH]) # 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 @@ -355,27 +356,21 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], 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 @@ -430,7 +425,7 @@ AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)]) # 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 @@ -506,7 +501,6 @@ AM_MISSING_PROG(AUTOCONF, autoconf) 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 @@ -515,7 +509,9 @@ 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)], @@ -758,13 +754,21 @@ fi # 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 @@ -967,4 +971,112 @@ fi 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 /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]) diff --git a/config.h.in b/config.h.in index 68fa99e..7f64307 100644 --- a/config.h.in +++ b/config.h.in @@ -16,9 +16,6 @@ /* Define if you have a readline compatible library */ #undef HAVE_LIBREADLINE -/* Define to 1 if you have the header file. */ -#undef HAVE_LINUX_TERMIOS_H - /* Define to 1 if you have the header file. */ #undef HAVE_LOCALE_H @@ -86,9 +83,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H -/* Define to 1 if you have the header file. */ -#undef HAVE_TERMIOS_H - /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H diff --git a/configure b/configure index 8c210bb..5e87a7c 100755 --- a/configure +++ b/configure @@ -309,7 +309,7 @@ ac_includes_default="\ # include #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. @@ -1306,7 +1306,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -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 @@ -1483,13 +1483,21 @@ echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} 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 @@ -1605,7 +1613,7 @@ fi # Define the identity of the package. PACKAGE=abook - VERSION=0.5.3 + VERSION=0.5.4 cat >>confdefs.h <<_ACEOF @@ -1633,9 +1641,6 @@ AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} 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 @@ -1728,6 +1733,13 @@ INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s" # 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 -' + + @@ -4011,9 +4023,7 @@ fi - - -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 @@ -6799,7 +6809,7 @@ else fi; if test x$debug = xtrue; then - CPPFLAGS="-DDEBUG $CPPFLAGS" + CPPFLAGS="-DDEBUG=1 $CPPFLAGS" CFLAGS="-g $CFLAGS" fi @@ -7457,7 +7467,6 @@ s,@AUTOCONF@,$AUTOCONF,;t t 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 @@ -7466,6 +7475,9 @@ s,@mkdir_p@,$mkdir_p,;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 @@ -8118,27 +8130,21 @@ echo X"$mf" | 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 diff --git a/configure.in b/configure.in index a9f1e6f..01b2193 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ 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 @@ -15,7 +15,7 @@ fi 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 header file.]),AC_MSG_ERROR([*** stdarg.h is missing on your system ***])) AC_FUNC_STRCOLL AC_CHECK_FUNCS(setlocale) @@ -108,7 +108,7 @@ AC_ARG_ENABLE(debug, [ --enable-debug Enable debugging support ], [cas esac], [debug=false]) if test x$debug = xtrue; then - CPPFLAGS="-DDEBUG $CPPFLAGS" + CPPFLAGS="-DDEBUG=1 $CPPFLAGS" CFLAGS="-g $CFLAGS" fi diff --git a/contrib/ldap-abook/comms.pl-en b/contrib/ldap-abook/comms.pl-en index 04acd62..92be10c 100644 --- a/contrib/ldap-abook/comms.pl-en +++ b/contrib/ldap-abook/comms.pl-en @@ -1,4 +1,4 @@ -$TMPERR="Cannot open file /tmp/ldap2abook/tmp"; +$TMPERR="Cannot open temporary file"; $DESTFILEERR="Cannot open file $DESTFILE"; $REPORT="entries created"; 1; diff --git a/contrib/ldap-abook/ldap2abook b/contrib/ldap-abook/ldap2abook index c86de4f..58b7936 100644 --- a/contrib/ldap-abook/ldap2abook +++ b/contrib/ldap-abook/ldap2abook @@ -11,6 +11,7 @@ # # Author: Mariusz Balewski # 03.06.2004 +# 29.08.2005 Tried to fix insecure tempfile handling (untested) # # GPL licensed # Feel free to send me your comments @@ -55,12 +56,16 @@ ############################### ############################### +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,"$DESTFILE") || die "$DESTFILEERR"; flock(F1,8); flock(F2,8); @@ -82,7 +87,7 @@ open(F2,">$DESTFILE") || die "$DESTFILEERR"; close(F2); close(F1); -system("rm /tmp/ldap2abook.tmp"); +unlink($file); print "\n$i "; print "$REPORT\n\n"; diff --git a/database.c b/database.c index e19d946..07fe9ab 100644 --- a/database.c +++ b/database.c @@ -1,6 +1,6 @@ /* - * $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 * @@ -19,27 +19,24 @@ #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 @@ -59,7 +56,7 @@ struct abook_field abook_fields[ITEM_FIELDS] = { {"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 */ @@ -100,58 +97,57 @@ parse_database(FILE *in) 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 _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); } } @@ -278,20 +274,19 @@ adjust_list_capacity() 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); @@ -307,27 +302,26 @@ remove_selected_items() { 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(); @@ -343,7 +337,7 @@ get_surname(char *s) while(p > s && *(p - 1) != ' ') p--; - return strdup(p); + return xstrdup(p); } static int @@ -379,8 +373,8 @@ namecmp(const void *i1, const void *i2) 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 @@ -415,7 +409,7 @@ sort_by_field(int field) } sort_field = field; - + qsort((void *)database, items, sizeof(list_item), namecmp); refresh_screen(); @@ -443,18 +437,20 @@ find_item(char *str, int start, int search_fields[]) 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); } } @@ -482,7 +478,7 @@ real_db_enumerate_items(struct db_enumerator e) { int item = max(0, e.item + 1); int i; - + switch(e.mode) { #ifdef DEBUG case ENUM_ALL: @@ -532,9 +528,9 @@ assign_fieldname(const char *name, int i) * 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; } diff --git a/database.h b/database.h index 3bfeb4e..8722885 100644 --- a/database.h +++ b/database.h @@ -36,7 +36,7 @@ enum { #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 diff --git a/edit.c b/edit.c index 44c76f8..7b719d2 100644 --- a/edit.c +++ b/edit.c @@ -1,6 +1,6 @@ /* - * $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 * @@ -17,6 +17,7 @@ #include "list.h" #include "edit.h" #include "misc.h" +#include "xmalloc.h" #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -46,13 +47,13 @@ editor_tab(const int tab) "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]); @@ -97,7 +98,7 @@ roll_emails(int item) strcpy(database[item][EMAIL], p+1); strcat(database[item][EMAIL], ","); - strcat(database[item][EMAIL], tmp); + strcat(database[item][EMAIL], tmp); } static void @@ -109,17 +110,50 @@ init_editor() 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() @@ -135,12 +169,12 @@ print_editor_header(int item) 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); @@ -163,7 +197,7 @@ editor_print_data(int tab, int item) 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); @@ -181,7 +215,8 @@ editor_print_data(int tab, int item) } if(j > 1) { - getyx(editw, y, x); y++; + getyx(editw, y, x); + y++; } else y = FIELDS_START_Y; @@ -218,7 +253,7 @@ change_field(char *msg, char **field) char *old; int ret = 0; - if( !strncmp("E-mail", msg, 6) ) + if(!strncmp("E-mail", msg, 6)) max_len = MAX_EMAIL_LEN; old = *field; @@ -226,9 +261,9 @@ change_field(char *msg, char **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; @@ -245,21 +280,21 @@ change_name_field(char **field) { 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; } @@ -273,7 +308,7 @@ edit_emails(char c, int item) 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 ) */ @@ -284,7 +319,7 @@ edit_emails(char c, int item) } else *emails[email_num] = 0; - my_free(database[item][EMAIL]); + xfree(database[item][EMAIL]); for(i = 0; i < MAX_EMAILS; i++) { if( *emails[i] ) { @@ -297,7 +332,7 @@ edit_emails(char c, int item) if(tmp[len -1] == ',') tmp[len-1] =0; - database[item][EMAIL] = strdup(tmp); + database[item][EMAIL] = xstrdup(tmp); } static int @@ -325,14 +360,14 @@ edit_field(int tab, char c, int item) 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); @@ -343,40 +378,6 @@ edit_field(int tab, char c, int item) 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) { @@ -394,7 +395,7 @@ 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; @@ -411,7 +412,7 @@ edit_loop(int item) 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; @@ -436,7 +437,7 @@ edit_item(int item) 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(); diff --git a/edit.h b/edit.h index 54310d7..5a8db07 100644 --- a/edit.h +++ b/edit.h @@ -29,7 +29,7 @@ enum { }; #define MAX_TAB TAB_CUSTOM - + #define TABS (MAX_TAB+1) #endif diff --git a/filter.c b/filter.c index 9f62171..9549017 100644 --- a/filter.c +++ b/filter.c @@ -1,6 +1,6 @@ /* - * $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 * @@ -22,6 +22,7 @@ #include "list.h" #include "misc.h" #include "options.h" +#include "xmalloc.h" #include extern int items; @@ -96,14 +97,14 @@ void 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, @@ -144,13 +145,13 @@ get_real_name() 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; } @@ -158,21 +159,21 @@ get_real_name() /* * 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, @@ -190,27 +191,27 @@ import_database() 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); @@ -225,14 +226,14 @@ i_read_file(char *filename, int (*func) (FILE *in)) 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 @@ -243,30 +244,30 @@ import_file(char filtname[FILTNAME_LEN], char *filename) 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; } @@ -281,7 +282,7 @@ static void export_screen() { int i; - + clear(); @@ -289,9 +290,9 @@ export_screen() 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); @@ -307,17 +308,17 @@ export_database() 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': @@ -329,16 +330,16 @@ export_database() } 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); @@ -353,16 +354,16 @@ e_write_file(char *filename, int (*func) (FILE *in, struct db_enumerator e), 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; } @@ -373,10 +374,10 @@ fexport(char filtname[FILTNAME_LEN], FILE *handle, int enum_mode) 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; } @@ -394,21 +395,21 @@ export_file(char filtname[FILTNAME_LEN], char *filename) 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); @@ -430,10 +431,10 @@ static void ldif_fix_string(char *str); #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", @@ -455,7 +456,7 @@ static int ldif_conv_table[LDIF_ITEM_FIELDS] = { NAME, /* "cn" */ EMAIL, /* "mail" */ ADDRESS, /* "streetaddress" */ - ADDRESS2, /* "streetaddress2" */ + ADDRESS2, /* "streetaddress2" */ CITY, /* "locality" */ STATE, /* "st" */ ZIP, /* "postalcode" */ @@ -471,7 +472,7 @@ static int ldif_conv_table[LDIF_ITEM_FIELDS] = { }; -static char * +static char * ldif_read_line(FILE *in) { char *buf = NULL; @@ -484,10 +485,10 @@ ldif_read_line(FILE *in) pos = ftell(in); line = getaline(in); - - if( feof(in) || !line ) + + if(feof(in) || !line) break; - + if(i == 1) { buf = line; continue; @@ -518,27 +519,27 @@ ldif_read_line(FILE *in) } 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]); } @@ -547,19 +548,19 @@ ldif_convert(ldif_item item, char *type, char *value) { 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); } } } @@ -575,11 +576,11 @@ ldif_parse_file(FILE *handle) 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 */ } @@ -587,7 +588,7 @@ ldif_parse_file(FILE *handle) ldif_convert(item, type, value); - my_free(line); + xfree(line); } while ( !feof(handle) ); ldif_convert(item, "dn", ""); @@ -630,7 +631,7 @@ mutt_read_line(FILE *in, char **alias, char **rest) while( ISSPACE(*ptr) ) ptr++; - if( strncmp("alias", ptr, 5) ) { + if(strncmp("alias", ptr, 5)) { free(line); return 1; } @@ -645,21 +646,17 @@ mutt_read_line(FILE *in, char **alias, char **rest) 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; @@ -725,7 +722,7 @@ mutt_parse_email(list_item item) free(item[EMAIL]); item[EMAIL] = tmp; } else { - my_free(email); + xfree(email); } } } @@ -740,11 +737,11 @@ mutt_parse_file(FILE *in) 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; } @@ -792,7 +789,7 @@ ldif_export_database(FILE *out, struct db_enumerator e) 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, @@ -829,7 +826,7 @@ html_export_database(FILE *out, struct db_enumerator e) { char tmp[MAX_EMAILSTR_LEN]; - if( items < 1 ) + if(items < 1) return 2; extra_column = (extra_column > 2 && extra_column < ITEM_FIELDS) ? @@ -883,7 +880,7 @@ html_export_write_tail(FILE *out) fprintf(out, "\n\n"); fprintf(out, "\n\n\n"); } - + /* * end of html export filter */ @@ -910,7 +907,7 @@ pine_convert_emails(char *s) int i; char *tmp; - if( s == NULL || *s != '(' ) + if(s == NULL || *s != '(') return; for(i=0; s[i]; i++ ) @@ -919,10 +916,10 @@ pine_convert_emails(char *s) 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; } } @@ -937,10 +934,10 @@ pine_parse_buf(char *buf) 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); @@ -951,7 +948,7 @@ pine_parse_buf(char *buf) 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; } @@ -971,32 +968,32 @@ pine_parse_file(FILE *in) 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; @@ -1041,9 +1038,9 @@ pine_export_database(FILE *out, struct db_enumerator e) /* 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 '#' @@ -1084,13 +1081,13 @@ csv_convert_emails(char *s) 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; } } @@ -1101,24 +1098,24 @@ csv_remove_quotes(char *s) 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 @@ -1136,7 +1133,7 @@ csv_store_field(list_item item, char *s, int field) && csv_conv_table[field] >= 0) { item[csv_conv_table[field]] = newstr; } else { - my_free(newstr); + xfree(newstr); } } @@ -1155,7 +1152,7 @@ allcsv_store_field(list_item item, char *s, int field) && allcsv_conv_table[field] >= 0) { item[allcsv_conv_table[field]] = newstr; } else { - my_free(newstr); + xfree(newstr); } } @@ -1272,7 +1269,7 @@ csv_parse_file(FILE *in) if(line && *line && *line != CSV_COMMENT_CHAR) csv_parse_line(line); - my_free(line); + xfree(line); } return 0; @@ -1289,7 +1286,7 @@ allcsv_parse_file(FILE *in) if(line && *line && *line != CSV_COMMENT_CHAR) allcsv_parse_line(line); - my_free(line); + xfree(line); } return 0; @@ -1353,7 +1350,7 @@ csv_export_database(FILE *out, struct db_enumerator e) }; csv_export_common(out, e, csv_export_fields, NULL); - + return 0; } @@ -1411,7 +1408,7 @@ allcsv_export_database(FILE *out, struct db_enumerator e) fprintf(out, "\"CUSTOM5\"\n"); csv_export_common(out, e, allcsv_export_fields, NULL); - + return 0; } @@ -1423,7 +1420,7 @@ allcsv_export_database(FILE *out, struct db_enumerator e) #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; @@ -1442,7 +1439,7 @@ palm_split_and_write_name(FILE *out, char *name) } } -static void +static void palm_csv_handle_specials(FILE *out, int item, int field) { switch(field) { @@ -1472,7 +1469,7 @@ palm_export_database(FILE *out, struct db_enumerator e) FAX, /* FAX */ MOBILEPHONE, /* OTHER */ EMAIL, /* EMAIL */ - ADDRESS, /* ADDRESS */ + ADDRESS, /* ADDRESS */ CITY, /* CITY */ STATE, /* STATE */ ZIP, /* ZIP */ @@ -1515,25 +1512,25 @@ gcrd_export_database(FILE *out, struct db_enumerator e) 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]) @@ -1546,19 +1543,19 @@ gcrd_export_database(FILE *out, struct db_enumerator e) 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; @@ -1577,18 +1574,18 @@ static char * 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 @@ -1605,7 +1602,7 @@ mutt_alias_export(FILE *out, struct db_enumerator e) alias, database[e.item][NAME], email); - my_free(alias); + xfree(alias); } return 0; @@ -1630,10 +1627,10 @@ text_write_address_us(FILE *out, int i) { 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]) @@ -1677,7 +1674,7 @@ text_write_address_eu(FILE *out, int i) { if(database[i][CITY]) fprintf(out, "%s", database[i][CITY]); } - + if (database[i][STATE]) fprintf(out, "\n%s", database[i][STATE]); @@ -1772,7 +1769,7 @@ elm_alias_export(FILE *out, struct db_enumerator e) alias, database[e.item][NAME], email); - my_free(alias); + xfree(alias); } return 0; diff --git a/getname.c b/getname.c index 41b8503..3deea8c 100644 --- a/getname.c +++ b/getname.c @@ -102,12 +102,12 @@ spamify(char *input) ** From: [blank From: line] ** From: uu.net!kent [uucp addresses - no comment] ** From: uu.net!kent (kent) [uucp addresses - with comment] -** From: "(Joe Bloggs)" +** From: "(Joe Bloggs)" ** From: "Roy T. Fielding" ** From: kent@localhost ** From: kent@uu.net (Kent Landfield) ** From: (George Burgyan) -** From: (George Burgyan) +** From: (George Burgyan) ** From: Kent B. Landfield ** 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 @@ -159,7 +159,7 @@ getname(char *line, char **namep, char **emailp) ** 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) */ @@ -177,7 +177,7 @@ getname(char *line, char **namep, char **emailp) 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 @@ -197,7 +197,7 @@ getname(char *line, char **namep, char **emailp) 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) { @@ -281,7 +281,7 @@ getname(char *line, char **namep, char **emailp) 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 */ @@ -326,7 +326,7 @@ getname(char *line, char **namep, char **emailp) 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)) @@ -341,9 +341,9 @@ getname(char *line, char **namep, char **emailp) 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); diff --git a/getopt.c b/getopt.c index 46da471..0a24ce5 100644 --- a/getopt.c +++ b/getopt.c @@ -23,7 +23,7 @@ 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. */ - + /* This tells Alpha OSF/1 not to define a getopt prototype in . Ditto for AIX 3.2 and . */ #ifndef _NO_PROTO @@ -198,7 +198,7 @@ ordering; /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; - + #ifdef __GNU_LIBRARY__ /* We want to avoid inclusion of string.h with non-GNU libraries because there are many ways it can cause trouble. @@ -241,7 +241,7 @@ extern int strlen(const char *); #endif /* __GNUC__ */ #endif /* not __GNU_LIBRARY__ */ - + /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have @@ -408,7 +408,7 @@ static const char * return optstring; } - + /* Scan elements of ARGV (whose length is ARGC) for option characters given in OPTSTRING. @@ -933,7 +933,7 @@ int } #endif /* Not ELIDE_CODE. */ - + #ifdef TEST /* Compile with -DTEST to make an executable for use in testing diff --git a/getopt1.c b/getopt1.c index fe414f3..289ed44 100644 --- a/getopt1.c +++ b/getopt1.c @@ -18,7 +18,7 @@ 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. */ - + #ifdef HAVE_CONFIG_H #include #endif @@ -91,7 +91,7 @@ int } #endif /* Not ELIDE_CODE. */ - + #ifdef TEST #include diff --git a/ldif.c b/ldif.c index 617cefc..e8996d7 100644 --- a/ldif.c +++ b/ldif.c @@ -1,5 +1,6 @@ /* + * $Id: ldif.c,v 1.5 2005/07/29 06:28:55 jheinonen Exp $ * adapted to use with abook by JH */ @@ -29,7 +30,7 @@ #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) \ @@ -44,7 +45,7 @@ #define CONTINUED_LINE_MARKER '\001' static char nib2b64[0x40f] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static unsigned char b642nib[0x80] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -73,110 +74,107 @@ static unsigned char b642nib[0x80] = { */ 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 @@ -196,21 +194,21 @@ str_parse_line( */ 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; @@ -218,23 +216,23 @@ str_getline( char **next ) (*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)++ = ':'; @@ -245,16 +243,16 @@ put_type_and_value( char **out, char *t, char *val, int vlen ) 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; @@ -262,36 +260,37 @@ put_type_and_value( char **out, char *t, char *val, int vlen ) *(*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; @@ -299,18 +298,19 @@ put_type_and_value( char **out, char *t, char *val, int vlen ) 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) = '='; } } @@ -320,29 +320,28 @@ put_type_and_value( char **out, char *t, char *val, int vlen ) 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); } - diff --git a/list.c b/list.c index 6bd1793..40db302 100644 --- a/list.c +++ b/list.c @@ -1,6 +1,6 @@ /* - * $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 * @@ -17,6 +17,7 @@ #include "list.h" #include "misc.h" #include "options.h" +#include "xmalloc.h" #define MIN_EXTRA_COLUMN ADDRESS /* 2 */ #define MAX_EXTRA_COLUMN LAST_FIELD @@ -32,7 +33,7 @@ extern int items; 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) @@ -82,17 +83,17 @@ void 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; @@ -110,6 +111,11 @@ refresh_list() 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); } @@ -127,7 +133,7 @@ print_list_line(int i, int line, int highlight) 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)) @@ -150,7 +156,7 @@ print_list_line(int i, int line, int highlight) if(highlight) wstandend(list); } - + void list_headerline() @@ -196,10 +202,10 @@ page_up() { if(curitem < 1) return; - + curitem = curitem == first_list_item ? ((curitem -= LIST_LINES) < 0 ? 0 : curitem) : first_list_item; - + refresh_list(); } @@ -262,7 +268,7 @@ goto_home() { if(items > 0) curitem = 0; - + refresh_list(); } @@ -349,7 +355,7 @@ duplicate_item() 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)) diff --git a/misc.c b/misc.c index 24123a6..c8d0d73 100644 --- a/misc.c +++ b/misc.c @@ -1,15 +1,14 @@ /* - * $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 * * 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 #include #include @@ -23,9 +22,7 @@ # include #endif #include "misc.h" -#ifdef ABOOK_SRC -# include "abook.h" -#endif +#include "xmalloc.h" #ifndef DEBUG # define NDEBUG 1 @@ -55,12 +52,12 @@ strtrim(char *s) 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'; @@ -89,13 +86,8 @@ mkstr (const char *format, ... ) { 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(;;) { @@ -112,13 +104,8 @@ mkstr (const char *format, ... ) 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); } } @@ -140,15 +127,8 @@ strconcat (const char *str, ...) 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); @@ -193,23 +173,45 @@ my_getcwd() 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) @@ -233,7 +235,7 @@ 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); @@ -241,7 +243,7 @@ getaline(FILE *f) 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; @@ -250,7 +252,7 @@ getaline(FILE *f) } if (len == 0) { - free(buf); + xfree(buf); return NULL; /* nothing read (eof or error) */ } @@ -258,7 +260,7 @@ getaline(FILE *f) 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; @@ -320,9 +322,9 @@ bytes2width(const char *s, int width) * 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 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 03/05/98 for mutt 0.90.8 @@ -371,7 +373,7 @@ bytes2width(const char *s, int width) /*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); @@ -424,7 +426,7 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args) int flags; int cflags; size_t currlen; - + state = DP_S_DEFAULT; currlen = flags = cflags = min = 0; max = -1; @@ -432,20 +434,20 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args) 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; @@ -473,49 +475,49 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args) } 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; @@ -535,11 +537,11 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args) 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); @@ -608,7 +610,7 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args) 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; @@ -617,19 +619,19 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args) 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 *); @@ -659,9 +661,9 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; /* some picky compilers need this */ } } - if (currlen < maxlen - 1) + if (currlen < maxlen - 1) buffer[currlen] = '\0'; - else + else buffer[maxlen - 1] = '\0'; } @@ -670,7 +672,7 @@ static void fmtstr (char *buffer, size_t *currlen, size_t maxlen, { int padlen, strln; /* amount to pad */ int cnt = 0; - + if (value == 0) { value = ""; @@ -678,23 +680,23 @@ static void fmtstr (char *buffer, size_t *currlen, size_t maxlen, 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; @@ -714,7 +716,7 @@ static void fmtint (char *buffer, size_t *currlen, size_t maxlen, int spadlen = 0; /* amount to space pad */ int zpadlen = 0; /* amount to zero pad */ int caps = 0; - + if (max < 0) max = 0; @@ -733,7 +735,7 @@ static void fmtint (char *buffer, size_t *currlen, size_t maxlen, if (flags & DP_F_SPACE) signvalue = ' '; } - + if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */ do { @@ -754,7 +756,7 @@ static void fmtint (char *buffer, size_t *currlen, size_t maxlen, zpadlen = MAX(zpadlen, spadlen); spadlen = 0; } - if (flags & DP_F_MINUS) + if (flags & DP_F_MINUS) spadlen = -spadlen; /* Left Justifty */ #ifdef DEBUG_SNPRINTF @@ -763,18 +765,18 @@ static void fmtint (char *buffer, size_t *currlen, size_t maxlen, #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) { @@ -784,9 +786,9 @@ static void fmtint (char *buffer, size_t *currlen, size_t maxlen, } /* 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, ' '); @@ -813,7 +815,7 @@ static long double pow10 (int exp) result *= 10; exp--; } - + return result; } @@ -839,12 +841,12 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, 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 */ @@ -868,8 +870,8 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, 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) @@ -909,18 +911,18 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, 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; @@ -937,10 +939,10 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, 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]); /* @@ -949,7 +951,7 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, */ dopr_outch (buffer, currlen, maxlen, '.'); - while (fplace > 0) + while (fplace > 0) dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]); while (zpadlen > 0) @@ -958,7 +960,7 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, --zpadlen; } - while (padlen < 0) + while (padlen < 0) { dopr_outch (buffer, currlen, maxlen, ' '); ++padlen; @@ -995,7 +997,7 @@ int snprintf (va_alist) va_dcl char *fmt; #endif VA_LOCAL_DECL; - + VA_START (fmt); VA_SHIFT (str, char *); VA_SHIFT (count, size_t ); @@ -1027,7 +1029,7 @@ int main (void) "%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", @@ -1055,7 +1057,7 @@ int main (void) 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++; } @@ -1069,7 +1071,7 @@ int main (void) 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++; } diff --git a/options.c b/options.c index 8196bcd..fbbd2a3 100644 --- a/options.c +++ b/options.c @@ -1,6 +1,6 @@ /* - * $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 * @@ -16,6 +16,7 @@ #include "options.h" #include "abook.h" #include "misc.h" +#include "xmalloc.h" #ifndef FALSE # define FALSE 0 @@ -55,17 +56,18 @@ static struct option abook_vars[] = { { "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 } }; @@ -98,7 +100,7 @@ set_str(enum str_opts opt, char *value) if(str_opts[opt]) free(str_opts[opt]); - str_opts[opt] = strdup(value); + str_opts[opt] = xstrdup(value); } int @@ -209,7 +211,7 @@ void find_token_start(buffer *b) { assert(b); - + for(; ISSPACE(*b -> ptr); b -> ptr ++); } @@ -229,7 +231,7 @@ static char * opt_set_set_option(char *var, char *p, struct option *opt) { int len; - + strtrim(p); len = strlen(p); @@ -260,7 +262,7 @@ opt_set_set_option(char *var, char *p, struct option *opt) default: assert(0); } - + return NULL; } @@ -275,13 +277,13 @@ opt_parse_set(buffer *b) *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"; } @@ -328,7 +330,7 @@ opt_parse_line(char *line, int n, char *fn) char *err = NULL; char *token; buffer b; - + assert(line && fn); b.ptr = line; @@ -353,7 +355,7 @@ opt_parse_line(char *line, int n, char *fn) return FALSE; break; } - + fprintf(stderr, "%s: parse error at line %d: ", fn, n); if(err) fprintf(stderr, "%s\n", err); @@ -370,11 +372,11 @@ load_opts(char *filename) 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); @@ -387,7 +389,8 @@ load_opts(char *filename) err += opt_parse_line(line, n, filename) ? 1:0; } - my_free(line); + free(line); + line = NULL; } free(line); diff --git a/options.h b/options.h index cfdaa6c..73b300c 100644 --- a/options.h +++ b/options.h @@ -18,6 +18,7 @@ enum bool_opts { BOOL_MUTT_RETURN_ALL_EMAILS, BOOL_USE_ASCII_ONLY, BOOL_ADD_EMAIL_PREVENT_DUPLICATES, + BOOL_SHOW_CURSOR, BOOL_MAX }; diff --git a/sample.abookrc b/sample.abookrc index bc352f3..086235f 100644 --- a/sample.abookrc +++ b/sample.abookrc @@ -52,6 +52,9 @@ set add_email_prevent_duplicates=false # 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 diff --git a/ui.c b/ui.c index 756a981..3777fe7 100644 --- a/ui.c +++ b/ui.c @@ -1,6 +1,6 @@ /* - * $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 * @@ -22,16 +22,10 @@ #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 -#else -# ifdef HAVE_LINUX_TERMIOS_H -# include -# endif -#endif #ifdef HAVE_SYS_IOCTL_H # include #endif @@ -45,25 +39,24 @@ 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); } @@ -82,13 +75,13 @@ resize_abook() #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); @@ -112,10 +105,10 @@ resize_abook() static void win_changed(int i) { - if( can_resize ) + if(can_resize) resize_abook(); else - should_resize = TRUE; + should_resize = TRUE; } #endif /* SIGWINCH */ @@ -155,15 +148,15 @@ init_ui() 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; } @@ -198,7 +191,7 @@ void refresh_screen() { #ifdef SIGWINCH - if( should_resize ) { + if(should_resize) { resize_abook(); return; } @@ -217,7 +210,7 @@ int statusline_msg(char *msg) { int c; - + clear_statusline(); statusline_addstr(msg); c = getch(); @@ -265,11 +258,13 @@ statusline_ask_boolean(char *msg, int def) free(msg2); - switch( tolower(getch()) ) { + switch(tolower(getch())) { case 'n': + case 'N': ret = FALSE; break; case 'y': + case 'Y': ret = TRUE; break; default: @@ -282,7 +277,6 @@ statusline_ask_boolean(char *msg, int def) return ret; } - void refresh_statusline() { @@ -294,7 +288,6 @@ refresh_statusline() wrefresh(bottom); } - char * ask_filename(char *prompt) { @@ -343,10 +336,10 @@ display_help(int help) 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(); @@ -375,13 +368,15 @@ get_commands() 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() ? @@ -463,7 +458,6 @@ get_commands() } } - void ui_remove_items() { @@ -473,7 +467,7 @@ ui_remove_items() if(statusline_ask_boolean("Remove selected item(s)", TRUE)) remove_selected_items(); - clear_statusline(); + clear_statusline(); refresh_list(); } @@ -496,7 +490,7 @@ ui_find(int next) clear_statusline(); if(next) { - if( !*findstr ) + if(!*findstr) return; } else { char *s; @@ -546,12 +540,12 @@ ui_print_database() 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; @@ -573,7 +567,7 @@ ui_print_database() return; fexport("text", handle, mode); - + pclose(handle); } @@ -585,13 +579,13 @@ ui_open_datafile() 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(); @@ -600,12 +594,12 @@ ui_open_datafile() 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(); diff --git a/ui.h b/ui.h index fdb4dca..f7fd48d 100644 --- a/ui.h +++ b/ui.h @@ -33,7 +33,7 @@ void ui_print_database(); 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 diff --git a/xmalloc.c b/xmalloc.c new file mode 100644 index 0000000..78ba89b --- /dev/null +++ b/xmalloc.c @@ -0,0 +1,150 @@ +/* + * $Id: xmalloc.c,v 1.5 2005/08/13 10:49:25 jheinonen Exp $ + * + * Common xmalloc memory allocation routines + * + * written by Jaakko Heinonen + */ + +/* + * 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 +#include +#include +#include +#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); +} + diff --git a/xmalloc.h b/xmalloc.h new file mode 100644 index 0000000..9b0f6de --- /dev/null +++ b/xmalloc.h @@ -0,0 +1,23 @@ +#ifndef _XMALLOC_H +#define _XMALLOC_H + +#include /* 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 -- 2.39.2