]> git.deb.at Git - pkg/abook.git/commitdiff
initial custom field support
authorJaakko Heinonen <jheinonen@users.sourceforge.net>
Fri, 21 Nov 2003 21:18:14 +0000 (21:18 +0000)
committerJaakko Heinonen <jheinonen@users.sourceforge.net>
Fri, 21 Nov 2003 21:18:14 +0000 (21:18 +0000)
ChangeLog
configure
configure.in
database.c
database.h
edit.c
edit.h
options.c
sample.abookrc

index 16e7e7f0a18286fe6dd1d22d64a7d8ff1a189df7..7538096262c24009c1d429ee5a7acfe1e047af9d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+0.5.2
+ - five custom fields added
+
 0.5.1
  - sort by field command
  - duplicate item command
index f2682ef4ed840a07bc0951ce51d8fa919d5acb5c..406e4aa601b80292e3bcbb5afba768fbc2a7f193 100755 (executable)
--- a/configure
+++ b/configure
@@ -1546,7 +1546,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE=abook
- VERSION=0.5.1
+ VERSION=0.5.2pre
 
 
 cat >>confdefs.h <<_ACEOF
index 70f81d44d8c40ef20f17b30e5194f0090c85db7f..c5284a635712e56a2e2434fbe02baf6c3c4277e1 100644 (file)
@@ -1,7 +1,7 @@
 dnl abook configure.in
 
 AC_INIT(abook.c)
-AM_INIT_AUTOMAKE(abook, 0.5.1)
+AM_INIT_AUTOMAKE(abook, 0.5.2pre)
 AM_CONFIG_HEADER(config.h)
 
 AC_DEFINE(HAVE_SNPRINTF, 0, [Define if snprintf is available.])
index c17adae62b7da64a6d4e19d83040b05729b83ae2..cf4f96632176f61604c8ffb5db5fb74b3783cfc4 100644 (file)
@@ -71,9 +71,26 @@ struct abook_field abook_fields[ITEM_FIELDS] = {
        {"Nickname/Alias", "nick",      TAB_OTHER},/* NICK */
        {"URL",         "url",          TAB_OTHER},/* URL */
        {"Notes",       "notes",        TAB_OTHER},/* NOTES */
+       {"Custom1",     "custom1",      TAB_CUSTOM},/* CUSTOM1 */
+       {"Custom2",     "custom2",      TAB_CUSTOM},/* CUSTOM2 */
+       {"Custom3",     "custom3",      TAB_CUSTOM},/* CUSTOM3 */
+       {"Custom4",     "custom4",      TAB_CUSTOM},/* CUSTOM4 */
+       {"Custom5",     "custom5",      TAB_CUSTOM},/* CUSTOM5 */
 };
 
 
+int
+find_field(const char *field)
+{
+       int i;
+
+       for(i = 0; i < ITEM_FIELDS; i++)
+               if( !strcmp(abook_fields[i].key, field) )
+                       return i;
+
+       return -1;
+}
+
 int
 parse_database(FILE *in)
 {
@@ -501,3 +518,42 @@ init_db_enumerator(int mode)
 
        return e;
 }
+
+static int
+assign_fieldname(const char *name, int i)
+{
+       char *s;
+
+       if(strcasecmp(abook_fields[i].name, name)) { /* name differs */
+               /*
+                * check if we are overwriting statically allocated default
+                */
+               if(strcasecmp(abook_fields[i].name, abook_fields[i].key))
+                       my_free(abook_fields[i].name);
+               
+               s = abook_malloc(MAX_FIELDNAME_LEN + 1);
+               snprintf(s, MAX_FIELDNAME_LEN, "%s", name);
+               abook_fields[i].name = s;
+       }
+
+       return 0;
+}
+
+int
+change_custom_field_name(const char *name, int n)
+{
+       int i;
+       char keyname[21];
+
+       snprintf(keyname, sizeof(keyname), "custom%d", n);
+
+       for(i = CUSTOM_MIN; i <= CUSTOM_MAX; i++) {
+               if(!strcasecmp(abook_fields[i].key, keyname)) {
+                       assign_fieldname(name, i);
+                       return i;
+               }
+       }
+
+       return -1;
+}
+
index 43b733817a06827d8ba848c91b25d4fc4c26d4cc..3bfeb4e385a342fed6cd77ad0a0c7793646c5ecd 100644 (file)
@@ -23,13 +23,23 @@ enum {
        NICK,
        URL,
        NOTES,
+       CUSTOM1,
+       CUSTOM2,
+       CUSTOM3,
+       CUSTOM4,
+       CUSTOM5,
        ITEM_FIELDS /* this is the last */
 };
 
 #define LAST_FIELD             (ITEM_FIELDS - 1)
 
+#define CUSTOM_MIN             CUSTOM1
+#define CUSTOM_MAX             CUSTOM5
+
 typedef char * list_item[ITEM_FIELDS];
 
+#define        MAX_FIELDNAME_LEN       21
+
 struct abook_field {
        char *name;
        char *key;
@@ -46,6 +56,7 @@ struct db_enumerator {
        int mode; /* warning: read only */
 };
 
+int            find_field(const char *field);
 int            parse_database(FILE *in);
 int            write_database(FILE *out, struct db_enumerator e);
 int            load_database(char *filename);
@@ -63,6 +74,7 @@ int           is_valid_item(int item);
 
 int            real_db_enumerate_items(struct db_enumerator e);
 struct db_enumerator   init_db_enumerator(int mode);
+int            change_custom_field_name(const char *name, int n);
 
 #define LAST_ITEM      (items - 1)
 
diff --git a/edit.c b/edit.c
index 4300a18b6fc3eefc3d17460466082a1dbd7ae3ba..12028f8722d1191e4cc8bb91f6672e608afa0300 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -36,30 +36,32 @@ static void
 editor_tab(int tab)
 {
        int i;
+       int spacing = 12;
        char *tab_names[] = {
-               " CONTACT ",
-               " ADDRESS ",
-               "  PHONE  ",
-               "  OTHER  "
+               "CONTACT",
+               "ADDRESS",
+               " PHONE ",
+               " OTHER ",
+               "CUSTOM "
        };
 
        mvwhline(editw, TABLINE+1, 0, UI_HLINE_CHAR, EDITW_COLS);
        for(i=0; i < TABS; i++) {
-               mvwaddch(editw,  TABLINE+1, 16 * i + 2,  UI_TEE_CHAR);
-               mvwaddch(editw,  TABLINE+1, 16 * i + 14, UI_TEE_CHAR);
+               mvwaddch(editw,  TABLINE+1, spacing * i + 2,  UI_TEE_CHAR);
+               mvwaddch(editw,  TABLINE+1, spacing * i + 12, UI_TEE_CHAR);
        }
 
        for(i=0; i < TABS; i++) {
-               mvwaddch(editw,  TABLINE, 16 * i + 2,  UI_ULCORNER_CHAR);
-               mvwaddch(editw,  TABLINE, 16 * i + 3,  UI_LBOXLINE_CHAR);
-               mvwaddstr(editw, TABLINE, 16 * i + 4,  tab_names[i]);
-               mvwaddch(editw,  TABLINE, 16 * i + 13, UI_RBOXLINE_CHAR);
-               mvwaddch(editw,  TABLINE, 16 * i + 14, UI_URCORNER_CHAR);
+               mvwaddch(editw,  TABLINE, spacing * i + 2,  UI_ULCORNER_CHAR);
+               mvwaddch(editw,  TABLINE, spacing * i + 3,  UI_LBOXLINE_CHAR);
+               mvwaddstr(editw, TABLINE, spacing * i + 4,  tab_names[i]);
+               mvwaddch(editw,  TABLINE, spacing * i + 11, UI_RBOXLINE_CHAR);
+               mvwaddch(editw,  TABLINE, spacing * i + 12, UI_URCORNER_CHAR);
        }
 
-       mvwaddch(editw,  TABLINE+1, 16 * tab + 2, UI_LRCORNER_CHAR);
-       mvwaddstr(editw, TABLINE+1, 16 * tab + 3, "           ");
-       mvwaddch(editw,  TABLINE+1, 16 * tab + 14, UI_LLCORNER_CHAR);
+       mvwaddch(editw,  TABLINE+1, spacing * tab + 2, UI_LRCORNER_CHAR);
+       mvwaddstr(editw, TABLINE+1, spacing * tab + 3, "         ");
+       mvwaddch(editw,  TABLINE+1, spacing * tab + 12, UI_LLCORNER_CHAR);
 }
 
 void
diff --git a/edit.h b/edit.h
index f9154670ca8bf414b3a9690322735a6957d0ec19..54310d788dfb11a0aa7a737eb672c30fe594982c 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -24,10 +24,11 @@ enum {
        TAB_CONTACT,
        TAB_ADDRESS,
        TAB_PHONE,
-       TAB_OTHER
+       TAB_OTHER,
+       TAB_CUSTOM
 };
 
-#define MAX_TAB                TAB_OTHER
+#define MAX_TAB                TAB_CUSTOM
        
 #define TABS           (MAX_TAB+1)
 
index fe75878abb225b056e950f0c2a34cceaba7f9d72..fb5c7a635d61e10c8340e774bf280e1766bdb555 100644 (file)
--- a/options.c
+++ b/options.c
@@ -283,12 +283,41 @@ opt_parse_set(buffer *b)
        return "unknown option";
 }
 
+static char *
+opt_parse_customfield(buffer *b)
+{
+       char *p, num[5];
+       int n;
+       size_t len;
+
+       find_token_start(b);
+
+       p = b -> ptr;
+
+       find_token_end(b);
+
+       memset(num, 0, sizeof(num));
+
+       if((len = (b -> ptr - p)) > sizeof(num))
+               return "invalid custom field number";
+
+       strncpy(num, p, min(sizeof(num), len));
+       n = atoi(num);
+
+       find_token_start(b);
+
+       if(change_custom_field_name(b->ptr, n) == -1)
+               return "invalid custom field number";
+
+       return NULL;
+}
 
 static struct {
        char *token;
        char * (*func) (buffer *line);
 } opt_parsers[] = {
        { "set", opt_parse_set },
+       { "customfield", opt_parse_customfield },
        { NULL }
 };
 
index e11e42bf9f7aae376dcf0f42ee360313d2fb5457..bc352f3ae86e97e0bb6ec52e562698c67a1c8cd2 100644 (file)
@@ -51,3 +51,12 @@ set add_email_prevent_duplicates=false
 
 # field to be used with "sort by field" command
 set sort_field=nick
+
+# custom fields
+
+#customfield 1 Name1
+#customfield 2 Name2
+#customfield 3 Name3
+#customfield 4 Name4
+#customfield 5 Name5
+