]> git.deb.at Git - pkg/abook.git/blobdiff - options.c
Imported Upstream version 0.5.5
[pkg/abook.git] / options.c
index 8196bcd50a74e1498dc08c52a8593b8bfe79c6e0..235da40b1bbde08e80ac8cb3b1cc8d5973d48559 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1,6 +1,6 @@
 
 /*
- * $Id: options.c,v 1.21 2003/12/05 18:11:55 jheinonen Exp $
+ * $Id: options.c,v 1.27 2005/09/21 16:50:31 jheinonen Exp $
  *
  * by JH <jheinonen@users.sourceforge.net>
  *
@@ -15,7 +15,9 @@
 #include <assert.h>
 #include "options.h"
 #include "abook.h"
+#include "gettext.h"
 #include "misc.h"
+#include "xmalloc.h"
 
 #ifndef FALSE
 #      define FALSE    0
@@ -55,17 +57,18 @@ static struct option abook_vars[] = {
        { "mutt_command", OT_STR, STR_MUTT_COMMAND, UL "mutt" },
        { "mutt_return_all_emails", OT_BOOL, BOOL_MUTT_RETURN_ALL_EMAILS,
                TRUE },
-       
+
        { "print_command", OT_STR, STR_PRINT_COMMAND, UL "lpr" },
 
        { "www_command", OT_STR, STR_WWW_COMMAND, UL "lynx" },
-       
+
        { "address_style", OT_STR, STR_ADDRESS_STYLE, UL "eu" },
 
        { "use_ascii_only", OT_BOOL, BOOL_USE_ASCII_ONLY, FALSE },
 
        { "add_email_prevent_duplicates", OT_BOOL, BOOL_ADD_EMAIL_PREVENT_DUPLICATES, FALSE },
        { "sort_field", OT_STR, STR_SORT_FIELD, UL "nick" },
+       { "show_cursor", OT_BOOL, BOOL_SHOW_CURSOR, FALSE },
 
        { NULL }
 };
@@ -98,7 +101,7 @@ set_str(enum str_opts opt, char *value)
        if(str_opts[opt])
                free(str_opts[opt]);
 
-       str_opts[opt] = strdup(value);
+       str_opts[opt] = xstrdup(value);
 }
 
 int
@@ -186,10 +189,8 @@ opt_line_remove_comments(char *p)
        for(; *p; p++) {
                switch(*p) {
                        case '\"':
-                               if(!escape) {
+                               if(!escape)
                                        in_quote = !in_quote;
-                                       escape = FALSE;
-                               }
                                break;
                        case '\\':
                                escape = TRUE;
@@ -209,7 +210,7 @@ void
 find_token_start(buffer *b)
 {
        assert(b);
-       
+
        for(; ISSPACE(*b -> ptr); b -> ptr ++);
 }
 
@@ -229,14 +230,14 @@ static char *
 opt_set_set_option(char *var, char *p, struct option *opt)
 {
        int len;
-       
+
        strtrim(p);
 
        len = strlen(p);
 
        if(p[len - 1] == '\"' && *p == '\"') {
                if(len < 3)
-                       return "invalid value";
+                       return _("invalid value");
                p[len - 1] = 0;
                p++;
        }
@@ -255,12 +256,12 @@ opt_set_set_option(char *var, char *p, struct option *opt)
                                        !strcasecmp(p, "off"))
                                set_bool(opt -> data, FALSE);
                        else
-                               return "invalid value";
+                               return _("invalid value");
                        break;
                default:
                        assert(0);
        }
-       
+
        return NULL;
 }
 
@@ -274,15 +275,15 @@ opt_parse_set(buffer *b)
        if((p = strchr(b -> ptr, '=')))
                *p++ = 0;
        else
-               return "invalid value assignment";
-       
+               return _("invalid value assignment");
+
        strtrim(b -> ptr);
 
        for(i = 0;abook_vars[i].option; i++)
                if(!strcmp(abook_vars[i].option, b -> ptr))
                        return opt_set_set_option(b -> ptr, p, &abook_vars[i]);
-       
-       return "unknown option";
+
+       return _("unknown option");
 }
 
 #include "database.h" /* needed for change_custom_field_name */
@@ -307,7 +308,7 @@ opt_parse_customfield(buffer *b)
        find_token_start(b);
 
        if(change_custom_field_name(b->ptr, n) == -1)
-               return "invalid custom field number";
+               return _("invalid custom field number");
 
        return NULL;
 }
@@ -328,7 +329,7 @@ opt_parse_line(char *line, int n, char *fn)
        char *err = NULL;
        char *token;
        buffer b;
-       
+
        assert(line && fn);
 
        b.ptr = line;
@@ -353,12 +354,12 @@ opt_parse_line(char *line, int n, char *fn)
                                return FALSE;
                        break;
                }
-       
-       fprintf(stderr, "%s: parse error at line %d: ", fn, n);
+
+       fprintf(stderr, _("%s: parse error at line %d: "), fn, n);
        if(err)
                fprintf(stderr, "%s\n", err);
        else
-               fprintf(stderr, "unknown token %s\n", token);
+               fprintf(stderr, _("unknown token %s\n"), token);
 
        return TRUE;
 }
@@ -370,11 +371,11 @@ load_opts(char *filename)
        char *line = NULL;
        int n;
        int err = 0;
-       
+
        if((in = fopen(filename, "r")) == NULL)
                return -1;
 
-       
+
        for(n = 1;!feof(in); n++) {
                line = getaline(in);
 
@@ -387,7 +388,8 @@ load_opts(char *filename)
                                err += opt_parse_line(line, n, filename) ? 1:0;
                }
 
-               my_free(line);
+               free(line);
+               line = NULL;
        }
 
        free(line);