+0.5.2
+ - five custom fields added
+
0.5.1
- sort by field command
- duplicate item command
# Define the identity of the package.
PACKAGE=abook
- VERSION=0.5.1
+ VERSION=0.5.2pre
cat >>confdefs.h <<_ACEOF
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.])
{"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)
{
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;
+}
+
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;
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);
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)
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
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)
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 }
};
# 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
+