From: Jaakko Heinonen Date: Mon, 11 Mar 2002 15:36:00 +0000 (+0000) Subject: a bunch of bugfixes X-Git-Tag: upstream/0.6.1~2^2~286 X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=f23af6b90ad6dbe1180c0e660112739be70fd86a;p=pkg%2Fabook.git a bunch of bugfixes --- diff --git a/ChangeLog b/ChangeLog index ce2b05a..158339e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2002-xx-xx - added a spec file for rpm support + - bugfixes 2002-03-11 - readline support diff --git a/abook.c b/abook.c index faa8055..fd3e336 100644 --- a/abook.c +++ b/abook.c @@ -604,13 +604,13 @@ abook_fopen (const char *path, const char *mode) { struct stat s; - if( ! strchr(mode, 'r') ) - return fopen(path, mode); - - if ( (stat(path, &s)) == -1 ) + if((stat(path, &s)) == -1) return NULL; - - return S_ISREG(s.st_mode) ? fopen(path, mode) : NULL; + + if(strchr(mode, 'r')) + return S_ISREG(s.st_mode) ? fopen(path, mode) : NULL; + else + return S_ISDIR(s.st_mode) ? NULL : fopen(path, mode); } @@ -754,6 +754,12 @@ add_email(int quiet) { char *line; char *name = NULL, *email = NULL; + struct stat s; + + if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode)) { + fprintf(stderr, "stdin is a directory or cannot stat stdin\n"); + exit(1); + } init_add_email(); diff --git a/abook.spec.in b/abook.spec.in index 2d0b407..1756657 100644 --- a/abook.spec.in +++ b/abook.spec.in @@ -2,7 +2,7 @@ Summary: Text-based addressbook program Name: @PACKAGE@ Version: @VERSION@ Release: 1 -Source: http://prdownloads.sourceforge.net/abook/abook-%{version}.tar.gz +Source: http://prdownloads.sourceforge.net/abook/%{name}-%{version}.tar.gz URL: http://abook.sourceforge.net/ License: GPL Group: Utilities @@ -20,7 +20,7 @@ use with mutt mail client. make CFLAGS="$RPM_OPT_FLAGS $CFLAGS" %install -make install-strip +make install %clean rm -rf "$RPM_BUILD_ROOT" diff --git a/filter.c b/filter.c index 5eb1191..d98ad11 100644 --- a/filter.c +++ b/filter.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "abook_curses.h" #include "filter.h" @@ -201,8 +202,7 @@ import_database() 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(); @@ -219,7 +219,7 @@ i_read_file(char *filename, int (*func) (FILE *in)) FILE *in; int ret = 0; - if( ( in = fopen( filename, "r" ) ) == NULL ) + if( ( in = abook_fopen( filename, "r" ) ) == NULL ) return 1; ret = (*func) (in); @@ -249,9 +249,13 @@ import_file(char filtname[FILTNAME_LEN], char *filename) if( i<0 ) return -1; - if( !strcmp(filename, "-") ) - ret = (*i_filters[i].func) (stdin); - else + if( !strcmp(filename, "-") ) { + struct stat s; + 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 ) @@ -499,7 +503,7 @@ ldif_read_line(FILE *in) free(line); } - if( *buf == '#' ) { + if(buf && *buf == '#' ) { free(buf); return NULL; } diff --git a/ui.c b/ui.c index 4103eba..b15d8ba 100644 --- a/ui.c +++ b/ui.c @@ -242,17 +242,21 @@ char * ui_readline(char *prompt, char *s, int limit, int use_completion) { int y, x; + char *ret; mvwaddstr(bottom, 1, 0, prompt); - //mvwaddstr(stdscr, LINES - 1, 0, prompt); - /* - * FIXME: stdscr shoulnd't be used ??? - */ -// getyx(stdscr, y, x); getyx(bottom, y, x); - return abook_readline(bottom, y, x, s, limit, use_completion); + ret = abook_readline(bottom, y, x, s, limit, use_completion); + + if(ret && !*ret) + my_free(ret); + + if(ret) + strtrim(ret); + + return ret; } int