]> git.deb.at Git - pkg/abook.git/commitdiff
filter updates
authorJaakko Heinonen <jheinonen@users.sourceforge.net>
Fri, 7 Sep 2001 10:23:19 +0000 (10:23 +0000)
committerJaakko Heinonen <jheinonen@users.sourceforge.net>
Fri, 7 Sep 2001 10:23:19 +0000 (10:23 +0000)
ChangeLog
database.c
filter.c

index f6aa9d79d8f95aff35388bd2bfde0374e9576290..21a87ceb14d4a8c2c9f472209cdb1a9b51df6cb8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
  - csv export filter fix
  - minor html filter update
  - fixed a minor memory leak in pine import filter
+ - filter cleanups
  - fixes
 
 0.4.13
index 3d7f1a4b9b2c9e24d3019003ceff5c9a1e39e439..17aaf2fac0fef6722ff13bffc9773f259f1a739c 100644 (file)
@@ -107,9 +107,12 @@ parse_database(FILE *in)
                } else if((tmp = strchr(line, '=') ) && sec ) {
                        *tmp++ = '\0';
                        for(i=0; i<ITEM_FIELDS; i++)
-                               if( !strcmp(abook_fields[i].key, line) )
+                               if( !strcmp(abook_fields[i].key, line) ) {
                                        item[i] = strdup(tmp);
+                                       goto next;
+                               }
                }
+next:
                free(line);
        }
 
@@ -144,15 +147,17 @@ write_database(FILE *out, struct db_enumerator e)
        int j;
        int i = 0;
 
-       fprintf(out, "# abook addressbook file\n\n");
-       fprintf(out, "[format]\n");
-       fprintf(out, "program=" PACKAGE "\n");
-       fprintf(out, "version=" VERSION "\n");
-       fprintf(out, "\n\n");
+       fprintf(out,
+               "# abook addressbook file\n\n"
+               "[format]\n"
+               "program=" PACKAGE "\n"
+               "version=" VERSION "\n"
+               "\n\n"
+       );
 
        db_enumerate_items(e) {
                fprintf(out, "[%d]\n", i);
-               for(j=0; j<ITEM_FIELDS; j++) {
+               for(j = 0; j < ITEM_FIELDS; j++) {
                        if( database[e.item][j] != NULL &&
                                        *database[e.item][j] )
                                fprintf(out, "%s=%s\n",
index 5d20a3743c42471bc455b3bac120edac0e57a162..a0bc2e485f4a120f9b154d135691a5101768900f 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -415,10 +415,6 @@ export(char filtname[FILTNAME_LEN], char *filename)
 
 static void    ldif_fix_string(char *str);
 
-#ifndef LINESIZE
-#      define LINESIZE 1024
-#endif
-
 #define        LDIF_ITEM_FIELDS        15
 
 typedef char*  ldif_item[LDIF_ITEM_FIELDS];
@@ -463,36 +459,39 @@ static int ldif_conv_table[LDIF_ITEM_FIELDS] = {
 static char * 
 ldif_read_line(FILE *in)
 {
-       char line[LINESIZE];
-       char *buf=NULL;
+       char *buf = NULL;
        char *ptr, *tmp;
        long pos;
        int i;
 
-       for(i=1;;i++) {
+       for(i = 1;;i++) {
+               char *line;
+
                pos = ftell(in);
-               fgets(line, LINESIZE, in);
+               line = getaline(in);
                
-               if( feof(in) )
+               if( feof(in) || !line )
                        break;
                
                if(i == 1) {
-                       buf = strdup(line);
+                       buf = line;
                        continue;
                }
                
                if(*line != ' ') {
                        fseek(in, pos, SEEK_SET);
+                       free(line);
                        break;
                }
 
-               ptr = (char *)&line;
+               ptr = line;
                while( *ptr == ' ')
                        ptr++;
 
                tmp = buf;
                buf = strconcat(buf, ptr, NULL);
                free(tmp);
+               free(line);
        }
 
        if( *buf == '#' ) {
@@ -500,12 +499,6 @@ ldif_read_line(FILE *in)
                return NULL;
        }
                
-       if(buf) {
-               int i,j;
-               for(i=0,j=0; j < strlen(buf); i++, j++)
-                       buf[i] = buf[j] == '\n' ? buf[++j] : buf[j];
-       }
-
        return buf;
 }
 
@@ -614,29 +607,21 @@ enum {
        MUTT_EMAIL
 };
 
-static void
-remove_newlines(char *buf)
-{
-       int i,j;
-       
-       for(i=0,j=0; j < strlen(buf); i++, j++)
-               buf[i] = buf[j] == '\n' ? buf[++j] : buf[j];
-}
-
 static int
 mutt_read_line(FILE *in, char **alias, char **rest)
 {
-       char line[LINESIZE];
-       char *ptr=(char *)&line;
+       char *line;
+       char *ptr;
        char *tmp;
 
-       fgets(line, LINESIZE, in);
-       remove_newlines(line);
+       if( !(line = ptr = getaline(in)) )
+               return 1; /* error / EOF */
 
        while( ISSPACE(*ptr) )
                ptr++;
 
        if( strncmp("alias", ptr, 5) ) {
+               free(line);
                return 1;
        }
                
@@ -650,8 +635,10 @@ mutt_read_line(FILE *in, char **alias, char **rest)
        while( ! ISSPACE(*ptr) )
                ptr++;
 
-       if( (*alias = (char *)malloc(ptr-tmp+1)) == NULL)
+       if( (*alias = (char *)malloc(ptr-tmp+1)) == NULL) {
+               free(line);
                return 1;
+       }
 
        strncpy(*alias, tmp, ptr-tmp);
        *(*alias+(ptr-tmp)) = 0;
@@ -660,7 +647,8 @@ mutt_read_line(FILE *in, char **alias, char **rest)
                ptr++;
 
        *rest = strdup(ptr);    
-       
+
+       free(line);
        return 0;
 }
 
@@ -716,11 +704,9 @@ mutt_parse_file(FILE *in)
 
                memset(mutt_item, 0, sizeof(mutt_item) );
                
-               if( mutt_read_line(in, &mutt_item[MUTT_ALIAS],
+               if( !mutt_read_line(in, &mutt_item[MUTT_ALIAS],
                                &mutt_item[MUTT_NAME]) )
-                       continue;
-
-               mutt_parse_email(mutt_item);
+                       mutt_parse_email(mutt_item);
 
                if( feof(in) ) {
                        free(mutt_item[MUTT_ALIAS]);
@@ -949,23 +935,24 @@ static int
 pine_parse_file(FILE *in)
 {
        char line[LINESIZE];
-       char *buf=NULL;
+       char *buf = NULL;
        char *ptr;
        int i;
 
        fgets(line, LINESIZE, in);      
        
        while(!feof(in)) {
-               for(i=2;;i++) {
+               for(i = 2;;i++) {
                        buf = (char *) realloc(buf, i*LINESIZE);
-                       if(i==2)
+                       if(i == 2)
                                strcpy(buf, line);
                        fgets(line, LINESIZE, in);
                        ptr=(char *)&line;
                        if(*ptr != ' ' || feof(in) )
                                break;
                        else
-                               while( *ptr == ' ') ptr++;
+                               while( *ptr == ' ')
+                                       ptr++;
                                
                        strcat(buf, ptr);
                }
@@ -1136,13 +1123,13 @@ csv_parse_line(char *line)
        memset(item, 0, sizeof(item));
 
        for(p = start = line, field = 0; *p; p++) {
-               if(!in_quote) {
+               if(in_quote) {
+                       if(csv_is_valid_quote_end(p))
+                               in_quote = FALSE;
+               } else {
                        if ( (((p - start) / sizeof (char)) < 2 ) &&
                                csv_is_valid_quote_start(p) )
                                in_quote = TRUE;
-               } else {
-                       if(csv_is_valid_quote_end(p))
-                               in_quote = FALSE;
                }
 
                if( *p == ',' && !in_quote) {