X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=filter.c;h=a4399399b168d267d47b4ed18374c501b77afc8a;hb=49aa0214d72eb609845e292772819de414034c55;hp=d401bf19c13eeaeb2c0bd7294bcea96c3ce309bf;hpb=05b0f3753902043fa8476a59c9251ab176675945;p=pkg%2Fabook.git diff --git a/filter.c b/filter.c index d401bf1..a439939 100644 --- a/filter.c +++ b/filter.c @@ -134,7 +134,7 @@ get_real_name() pwent = getpwnam(username); - if( (tmp = malloc(strlen(pwent->pw_gecos) +1)) == NULL) + if( (tmp = (char *)malloc(strlen(pwent->pw_gecos) +1)) == NULL) return strdup(username); rtn = sscanf(pwent->pw_gecos, "%[^,]", tmp); @@ -647,7 +647,7 @@ mutt_read_line(FILE *in, char **alias, char **rest) while( ! ISSPACE(*ptr) ) ptr++; - if( (*alias = malloc(ptr-tmp+1)) == NULL) + if( (*alias = (char *)malloc(ptr-tmp+1)) == NULL) return 1; strncpy(*alias, tmp, ptr-tmp); @@ -820,10 +820,14 @@ html_export_database(FILE *out, struct db_enumerator e) db_enumerate_items(e) { get_first_email(tmp, e.item); - fprintf(out, "\n%s\n", - tmp, - database[e.item][NAME] ); - + if (*tmp) + fprintf(out, "\n%s\n", + tmp, + database[e.item][NAME] ); + else + fprintf(out, "\n%s>\n", + database[e.item][NAME] ); + fprintf(out, "%s\n%s\n", database[e.item][EMAIL], safe_str(database[e.item][extra_column]) ); @@ -896,7 +900,7 @@ pine_convert_emails(char *s) *tmp=0; for(i=1; ( tmp = strchr(s, ',') ) != NULL ; i++, s=tmp+1 ) - if( i > 3 ) { + if( i > MAX_EMAILS - 1 ) { *tmp = 0; break; } @@ -950,7 +954,7 @@ pine_parse_file(FILE *in) while(!feof(in)) { for(i=2;;i++) { - buf = realloc(buf, i*LINESIZE); + buf = (char *) realloc(buf, i*LINESIZE); if(i==2) strcpy(buf, line); fgets(line, LINESIZE, in); @@ -962,8 +966,10 @@ pine_parse_file(FILE *in) strcat(buf, ptr); } - if( *buf == '#' ) + if( *buf == '#' ) { + my_free(buf); continue; + } pine_fixbuf(buf); pine_parse_buf(buf); @@ -1168,6 +1174,65 @@ mutt_alias_export(FILE *out, struct db_enumerator e) * printable export filter */ + +static void +text_write_address_us(FILE *out, int i) { + fprintf(out, "\n%s", database[i][ADDRESS]); + + 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]) + fputc(' ', out); + } + + if(database[i][ZIP]) + fprintf(out, "%s", database[i][ZIP]); + } + + if (database[i][COUNTRY]) + fprintf(out, "\n%s", database[i][COUNTRY]); +} + + +static void +text_write_address_uk(FILE *out, int i) { + int j; + + for (j = ADDRESS; j <= COUNTRY; j++) + if (database[i][j]) + fprintf(out, "\n%s", database[i][j]); +} + +static void +text_write_address_eu(FILE *out, int i) { + fprintf(out, "\n%s", database[i][ADDRESS]); + + if (database[i][ZIP] || database[i][CITY]) { + fputc('\n', out); + + if(database[i][ZIP]) { + fprintf(out, "%s", database[i][ZIP]); + if(database[i][CITY]) + fputc(' ', out); + } + + if(database[i][CITY]) + fprintf(out, "%s", database[i][CITY]); + } + + if (database[i][STATE]) + fprintf(out, "\n%s", database[i][STATE]); + + if (database[i][COUNTRY]) + fprintf(out, "\n%s", database[i][COUNTRY]); +} + static int text_export_database(FILE * out, struct db_enumerator e) { @@ -1199,42 +1264,12 @@ text_export_database(FILE * out, struct db_enumerator e) } /* Print address */ if (database[e.item][ADDRESS]) { - if (!safe_strcmp(style, "us")) { /* US like */ - fprintf(out, "\n%s", database[e.item][ADDRESS]); - if (database[e.item][CITY]) - fprintf(out, "\n%s", - database[e.item][CITY]); - if (database[e.item][STATE] || database[e.item][ZIP]) - fprintf(out, "\n%s %s", - safe_str(database[e.item] - [STATE]), - safe_str(database[e.item] - [ZIP])); - if (database[e.item][COUNTRY]) - fprintf(out, "\n%s", - database[e.item][COUNTRY]); - } - - else if (!safe_strcmp(style, "uk")) { /* UK like */ - for (j = ADDRESS; j <= COUNTRY; j++) - if (database[e.item][j]) - fprintf(out, "\n%s", - database[e.item][j]); - } else { /* EU like */ - fprintf(out, "\n%s", database[e.item][ADDRESS]); - if (database[e.item][ZIP] || - database[e.item][CITY]) - fprintf(out, "\n%s %s", - safe_str(database[e.item][ZIP]), - safe_str(database[e.item] - [CITY])); - if (database[e.item][STATE]) - fprintf(out, "\n%s", - database[e.item][STATE]); - if (database[e.item][COUNTRY]) - fprintf(out, "\n%s", - database[e.item][COUNTRY]); - } + if (!safe_strcmp(style, "us")) /* US like */ + text_write_address_us(out, e.item); + else if (!safe_strcmp(style, "uk")) /* UK like */ + text_write_address_uk(out, e.item); + else /* EU like */ + text_write_address_eu(out, e.item); fprintf(out, "\n"); }