* file parsing
*/
+typedef struct {
+ char *data, *ptr;
+} buffer;
+
static void
opt_line_remove_comments(char *p)
{
}
}
-static char *
-get_token_start(char *p)
+void
+find_token_start(buffer *b)
{
- assert(p);
+ assert(b);
- for(; ISSPACE(*p); p++);
-
- return p;
+ for(; ISSPACE(*b -> ptr); b -> ptr ++);
}
-static char *
-get_token_end(char *p)
+void
+find_token_end(buffer *b)
{
- assert(p);
+ assert(b);
- for(p = get_token_start(p); *p; p++) {
- if(ISSPACE(*p)) {
+ for(find_token_start(b); *(b -> ptr); b -> ptr ++) {
+ if(ISSPACE(*(b -> ptr))) {
break;
}
}
-
- return p;
}
static char *
}
static char *
-opt_parse_set(char *p)
+opt_parse_set(buffer *b)
{
- char *var;
int i;
+ char *p;
- var = get_token_start(p);
- if((p = strchr(var, '=')))
+ find_token_start(b);
+ if((p = strchr(b -> ptr, '=')))
*p++ = 0;
else
return "invalid value assignment";
- strtrim(var);
+ strtrim(b -> ptr);
for(i = 0;abook_vars[i].option; i++)
- if(!strcmp(abook_vars[i].option, var))
- return opt_set_set_option(var, p, &abook_vars[i]);
+ if(!strcmp(abook_vars[i].option, b -> ptr))
+ return opt_set_set_option(b -> ptr, p, &abook_vars[i]);
return "unknown option";
}
static struct {
char *token;
- char * (*func) (char *line);
+ char * (*func) (buffer *line);
} opt_parsers[] = {
{ "set", opt_parse_set },
{ NULL }
opt_parse_line(char *line, int n, char *fn)
{
int i;
- char *p;
char *err = NULL;
+ char *token;
+ buffer b;
assert(line && fn);
- line = get_token_start(line);
- p = get_token_end(line);
- *p++ = 0;
+ b.ptr = line;
+
+ find_token_start(&b);
+ b.data = b.ptr;
+ find_token_end(&b);
+ *b.ptr++ = 0;
if(!*line)
return FALSE;
- strtrim(line);
- strtrim(p);
+ strtrim(b.data);
+ strtrim(b.ptr);
+
+ token = b.data;
+ b.data = b.ptr = b.ptr;
for(i = 0; opt_parsers[i].token; i++)
- if(!strcmp(opt_parsers[i].token, line)) {
- if(!(err = opt_parsers[i].func(p)))
+ if(!strcmp(opt_parsers[i].token, token)) {
+ if(!(err = opt_parsers[i].func(&b)))
return FALSE;
break;
}
if(err)
fprintf(stderr, "%s\n", err);
else
- fprintf(stderr, "unknown token %s\n", line);
+ fprintf(stderr, "unknown token %s\n", token);
return TRUE;
}
# see abookrc(5) for detailed explanation
# Automatically save database on exit
-autosave=true
+set autosave=true
# Show all email addresses in list
-show_all_emails=true
+set show_all_emails=true
# Screen column for email field to start
-emailpos=25
+set emailpos=25
# Field to be used in the extra column
-extra_column=phone
+set extra_column=phone
# frequently used values:
# -1 disabled
# phone Home Phone
# Specify an alternative field to be displayed in the extra
# column if there is no data for the field specified in
# extra_column for a particular item.
-extra_alternative=-1
+set extra_alternative=-1
# Screen column for the extra field to start
-extrapos=65
+set extrapos=65
# Command used to start mutt
-mutt_command=mutt
+set mutt_command=mutt
# Return all email addresses to a mutt query
-mutt_return_all_emails=true
+set mutt_return_all_emails=true
# Command used to print
-print_command=lpr
-
-# Sort files in fileselector (alphabetic order)
-filesel_sort=false
+set print_command=lpr
# Command used to start the web browser
-www_command=lynx
+set www_command=lynx
# address style [eu|us|uk]
-address_style=eu
+set address_style=eu
# use ASCII characters only
-use_ascii_only=false
+set use_ascii_only=false