]> git.deb.at Git - pkg/abook.git/blobdiff - filter.c
a bunch of bugfixes
[pkg/abook.git] / filter.c
index ad80f45ca61ab0e28b031368ebe46322f28b33ce..d98ad117e3e1406b3a8148691d530586cd74d944 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <pwd.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include "abook_curses.h"
 #include "filter.h"
@@ -193,7 +194,7 @@ import_database()
        
        mvaddstr(5+filter, 2, "->");
        
-       filename = ask_filename("Filename: ", 1);
+       filename = ask_filename("Filename: ");
        if( !filename ) {
                refresh_screen();
                return 2;
@@ -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 )
@@ -320,7 +324,7 @@ export_database()
                clear_statusline();
        }
        
-       filename = ask_filename("Filename: ", 0);
+       filename = ask_filename("Filename: ");
        if( !filename ) {
                refresh_screen();
                return 2;
@@ -499,7 +503,7 @@ ldif_read_line(FILE *in)
                free(line);
        }
 
-       if( *buf == '#' ) {
+       if(buf && *buf == '#' ) {
                free(buf);
                return NULL;
        }
@@ -820,14 +824,13 @@ html_export_write_head(FILE *out, int extra_column)
 {
        char *realname = get_real_name();
 
-       fprintf(out, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n");
-       fprintf(out, "<html>\n<head>\n  <title>%s's addressbook</title>",
-                       realname );
+       fprintf(out, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
+       fprintf(out, "<html>\n<head>\n <title>%s's addressbook</title>", realname );
        fprintf(out, "\n</head>\n<body>\n");
        fprintf(out, "\n<h2>%s's addressbook</h2>\n", realname );
        fprintf(out, "<br><br>\n\n");
 
-       fprintf(out, "<center><table border>\n");
+       fprintf(out, "<table border=\"1\" align=\"center\">\n");
        fprintf(out, "\n<tr><th>Name<th>E-mail address(es)<th>%s</tr>\n\n",
                        abook_fields[extra_column].name);
 
@@ -837,7 +840,7 @@ html_export_write_head(FILE *out, int extra_column)
 static void
 html_export_write_tail(FILE *out)
 {
-       fprintf(out, "\n</table></center>\n");
+       fprintf(out, "\n</table>\n");
        fprintf(out, "\n</body>\n</html>\n");
 }
        
@@ -1105,7 +1108,7 @@ csv_parse_line(char *line)
 {
        char *p, *start;
        int field;
-       int in_quote = FALSE;
+       bool in_quote = FALSE;
        list_item item;
 
        memset(item, 0, sizeof(item));