#include <string.h>
#include <ctype.h>
#include <pwd.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include "abook_curses.h"
#include "filter.h"
mvaddstr(5+filter, 2, "->");
- filename = ask_filename("Filename: ", 1);
+ filename = ask_filename("Filename: ");
if( !filename ) {
refresh_screen();
return 2;
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();
FILE *in;
int ret = 0;
- if( ( in = fopen( filename, "r" ) ) == NULL )
+ if( ( in = abook_fopen( filename, "r" ) ) == NULL )
return 1;
ret = (*func) (in);
}
int
-import(char filtname[FILTNAME_LEN], char *filename)
+import_file(char filtname[FILTNAME_LEN], char *filename)
{
int i;
int tmp = items;
int ret = 0;
for(i=0;; i++) {
- if( ! strncmp(i_filters[i].filtname, filtname, FILTNAME_LEN) )
+ if( ! strncasecmp(i_filters[i].filtname, filtname,
+ FILTNAME_LEN) )
break;
if( ! *i_filters[i].filtname ) {
i = -1;
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 )
filter = getch() - 'a';
if(filter == 'x' - 'a' ||
- filter >= number_of_output_filters(e_filters) || filter < 0) {
+ filter >= number_of_output_filters() || filter < 0) {
refresh_screen();
return 1;
}
clear_statusline();
}
- filename = ask_filename("Filename: ", 0);
+ filename = ask_filename("Filename: ");
if( !filename ) {
refresh_screen();
return 2;
struct db_enumerator e = init_db_enumerator(enum_mode);
for(i=0;; i++) {
- if( ! strncmp(e_filters[i].filtname, filtname, FILTNAME_LEN) )
+ if( ! strncasecmp(e_filters[i].filtname, filtname,
+ FILTNAME_LEN) )
break;
if( ! *e_filters[i].filtname ) {
i = -1;
int
-export(char filtname[FILTNAME_LEN], char *filename)
+export_file(char filtname[FILTNAME_LEN], char *filename)
{
const int mode = ENUM_ALL;
int i;
struct db_enumerator e = init_db_enumerator(mode);
for(i=0;; i++) {
- if( ! strncmp(e_filters[i].filtname, filtname, FILTNAME_LEN) )
+ if( ! strncasecmp(e_filters[i].filtname, filtname,
+ FILTNAME_LEN) )
break;
if( ! *e_filters[i].filtname ) {
i = -1;
static void ldif_fix_string(char *str);
-#define LDIF_ITEM_FIELDS 15
+#define LDIF_ITEM_FIELDS 16
typedef char* ldif_item[LDIF_ITEM_FIELDS];
"cn",
"mail",
"streetaddress",
+ "streetaddress2",
"locality",
"st",
"postalcode",
NAME, /* "cn" */
EMAIL, /* "mail" */
ADDRESS, /* "streetaddress" */
+ ADDRESS2, /* "streetaddress2" */
CITY, /* "locality" */
STATE, /* "st" */
ZIP, /* "postalcode" */
free(line);
}
- if( *buf == '#' ) {
+ if(buf && *buf == '#' ) {
free(buf);
return NULL;
}
{
int i, j;
- for( i = 0, j = 0; j < strlen(str); i++, j++)
+ for( i = 0, j = 0; j < (int)strlen(str); i++, j++)
str[i] = ( str[j] == (char)0xc3 ?
(char) str[++j] + (char) 0x40 :
str[j] );
static void html_export_write_head(FILE *out, int extra_column);
static void html_export_write_tail(FILE *out);
+extern int extra_column;
+
static int
html_export_database(FILE *out, struct db_enumerator e)
{
char tmp[MAX_EMAILSTR_LEN];
- int extra_column = options_get_int("extra_column");
if( items < 1 )
return 2;
tmp,
database[e.item][NAME] );
else
- fprintf(out, "<tr>\n<td>%s>\n",
+ fprintf(out, "<tr>\n<td>%s\n",
database[e.item][NAME] );
fprintf(out, "<td>%s\n<td>%s\n",
{
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);
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");
}
{
int i,j;
- for(i=0,j=0; j < strlen(buf); i++, j++)
+ for(i=0,j=0; j < (int)strlen(buf); i++, j++)
buf[i] = buf[j] == '\n' ? buf[++j] : buf[j];
}
len = last ? strlen(start) : (int) (end-start);
len = min(len, 400-1);
- if(i < sizeof(pine_conv_table) / sizeof(*pine_conv_table)
+ if(i < (int)(sizeof(pine_conv_table) / sizeof(*pine_conv_table))
&& pine_conv_table[i] >= 0) {
strncpy(tmp, start, len);
tmp[len] = 0;
if( !(newstr = csv_remove_quotes(s)) )
return;
- if(field < (sizeof(csv_conv_table) / sizeof(*csv_conv_table))
+ if(field < (int)(sizeof(csv_conv_table) / sizeof(*csv_conv_table))
&& csv_conv_table[field] >= 0) {
item[csv_conv_table[field]] = newstr;
+ } else {
+ my_free(newstr);
}
}
{
char *p, *start;
int field;
- int in_quote = FALSE;
+ bool in_quote = FALSE;
list_item item;
memset(item, 0, sizeof(item));
free(name);
if ( database[e.item][ADDRESS] )
- fprintf(out, "ADR:;;%s;%s;%s;%s;%s\n",
+ 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][CITY]),
safe_str(database[e.item][STATE]),
safe_str(database[e.item][ZIP]),
static void
text_write_address_us(FILE *out, int i) {
fprintf(out, "\n%s", database[i][ADDRESS]);
-
+
+ if (database[i][ADDRESS2])
+ fprintf(out, "\n%s", database[i][ADDRESS2]);
+
if (database[i][CITY])
fprintf(out, "\n%s", database[i][CITY]);
static void
text_write_address_eu(FILE *out, int i) {
fprintf(out, "\n%s", database[i][ADDRESS]);
-
+
+ if (database[i][ADDRESS2])
+ fprintf(out, "\n%s", database[i][ADDRESS2]);
+
if (database[i][ZIP] || database[i][CITY]) {
fputc('\n', out);
char emails[MAX_EMAILS][MAX_EMAIL_LEN];
int j;
char *realname = get_real_name();
- char *style = options_get_str("address_style");
+ char *style = opt_get_str(STR_ADDRESS_STYLE);
fprintf(out,
"-----------------------------------------\n%s's address book\n"