]> git.deb.at Git - pkg/abook.git/commitdiff
merged palmcsv export filter
authorJaakko Heinonen <jheinonen@users.sourceforge.net>
Wed, 20 Mar 2002 09:17:24 +0000 (09:17 +0000)
committerJaakko Heinonen <jheinonen@users.sourceforge.net>
Wed, 20 Mar 2002 09:17:24 +0000 (09:17 +0000)
AUTHORS
ChangeLog
database.h
filter.c
filter.h

diff --git a/AUTHORS b/AUTHORS
index 2d83e7e6a8c97d953f0fed4ba79290ad67c01951..5460fb05003fe04d91cc8d3e2c5f39022cddfa92 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -18,4 +18,5 @@ Matt Kraai            <kraai@alumni.carnegiemellon.edu>
 
 Koenraad Heijlen       <vipie@ulyssis.org>
  - csv import filter
+ - palmcsv export filter
  - fixes
index 7cad6e55a3e82849745c8d2dd44ff478201978f4..0c957794f328056ec9d5f2b8e2b5a4fe0ae7478e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2002-xx-xx
  - options.c rewritten (new mutt style rc file support)
+ - palmcsv export filter (Koenraad Heijlen)
  - added a spec file for rpm support
  - bugfixes
 
index 142d1b01eb7be0666a0e76f6cc437311ee77621e..10b31f85a669a1c1f9377ec379d3bca4fa765237 100644 (file)
@@ -23,11 +23,10 @@ enum {
        NICK,
        URL,
        NOTES,
+       ITEM_FIELDS /* this is the last */
 };
 
-#define LAST_FIELD             NOTES
-
-#define ITEM_FIELDS            (LAST_FIELD+1)
+#define LAST_FIELD             (ITEM_FIELDS - 1)
 
 typedef char * list_item[ITEM_FIELDS];
 
index 08f49b069b538d962257b8857a4946643ab11923..d699a5c6774abf6150f0f47c8a70d3d2040ddbae 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -49,6 +49,7 @@ static int      ldif_export_database(FILE *out, struct db_enumerator e);
 static int     html_export_database(FILE *out, struct db_enumerator e);
 static int     pine_export_database(FILE *out, struct db_enumerator e);
 static int     csv_export_database(FILE *out, struct db_enumerator e);
+static int     palm_export_database(FILE *out, struct db_enumerator e);
 static int     gcrd_export_database(FILE *out, struct db_enumerator e);
 static int     mutt_alias_export(FILE *out, struct db_enumerator e);
 static int     elm_alias_export(FILE *out, struct db_enumerator e);
@@ -76,6 +77,7 @@ struct abook_output_filter e_filters[] = {
        { "pine", "pine addressbook", pine_export_database },
        { "gcrd", "GnomeCard (VCard) addressbook", gcrd_export_database },
        { "csv", "comma separated values", csv_export_database },
+       { "palmcsv", "Palm comma separated values", palm_export_database},
        { "elm", "elm alias", elm_alias_export },
        { "text", "plain text", text_export_database },
        { "spruce", "Spruce address book", spruce_export_database },
@@ -1204,6 +1206,102 @@ csv_export_database(FILE *out, struct db_enumerator e)
  */
 
 
+/*
+ * Palm csv addressbook export filter
+ */
+
+/* A few contants, not the best way to init them but better dan
+ * some number that will break things later on...              */
+#define        PALM_CSV_UNDEFINED       (LAST_FIELD+1)
+#define        PALM_CSV_END             (LAST_FIELD+2)
+#define        PALM_CSV_CAT             (LAST_FIELD+3)
+
+static void 
+palm_split_and_write_name(FILE *out, char *name) {
+       char *p;
+
+       assert(name);
+
+       if ( (p = strchr(name, ' ')) ) {
+               /*
+                * last name first
+                */
+               fprintf(out, "\"%s\",\"" , p + 1);
+               fwrite((void *)name, p - name, sizeof(char), out);
+               fputc('\"', out);
+       } else {
+               fprintf(out, "\"%s\"", safe_str(name));
+       }
+}
+
+static int
+palm_export_database(FILE *out, struct db_enumerator e)
+{
+       int j;
+       int palm_export_fields[] = {
+               NAME,                   /* LASTNAME, FIRSTNAME  */
+               PALM_CSV_UNDEFINED,     /* TITLE,               */
+               PALM_CSV_UNDEFINED,     /* COMPAGNY,            */
+               WORKPHONE,              /* WORK PHONE           */
+               PHONE,                  /* HOME PHONE           */
+               FAX,                    /* FAX                  */
+               MOBILEPHONE,            /* OTHER                */
+               EMAIL,                  /* EMAIL                */
+               ADDRESS,                /* ADDRESS              */ 
+               CITY,                   /* CITY                 */
+               STATE,                  /* STATE                */
+               ZIP,                    /* ZIP                  */
+               COUNTRY,                /* COUNTRY              */
+               NICK,                   /* DEFINED 1            */
+               URL,                    /* DEFINED 2            */
+               PALM_CSV_UNDEFINED,     /* DEFINED 3            */
+               PALM_CSV_UNDEFINED,     /* DEFINED 4            */
+               NOTES,                  /* NOTE                 */
+               PALM_CSV_END,           /* "0"                  */
+               PALM_CSV_CAT,           /* CATEGORY             */
+               -1
+       };
+
+       db_enumerate_items(e) {
+               for(j = 0; palm_export_fields[j] >= 0; j++) {
+
+               switch( palm_export_fields[j] ) {
+
+                       case PALM_CSV_UNDEFINED:
+                               fprintf(out, "\"\"");
+                               break;
+                       case PALM_CSV_END:
+                               fprintf(out, "\"0\"");
+                               break;
+                       case PALM_CSV_CAT:
+                               fprintf(out, "\"abook\"");
+                               break;
+                       case NAME:
+                               palm_split_and_write_name(out,
+                                               safe_str(database[e.item]
+                                               [palm_export_fields[j]])) ;
+                               break;
+
+                       default:
+                               fprintf(out, "\"%s\"" ,
+                                       safe_str(database[e.item]
+                                               [palm_export_fields[j]]));
+                       }
+
+                       if(palm_export_fields[j+1] >= 0)
+                               fputc(',', out);
+               }
+               fputc('\n', out);
+       }
+
+       return 0;
+}
+
+/*
+ * end of palm csv export filter
+ */
+
+
 /*
  * GnomeCard (VCard) addressbook export filter
  */
index d5fb1d2968cd7a50f0dd85214e5e9813eb6a87db..6957b0405b32d1b6957f54d0038ad6a781a3bcc7 100644 (file)
--- a/filter.h
+++ b/filter.h
@@ -3,7 +3,7 @@
 
 #include "database.h"
 
-#define                FILTNAME_LEN    7
+#define                FILTNAME_LEN    8
 
 
 struct abook_output_filter {