summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1899507)
raw | patch | inline | side by side (parent: 1899507)
author | Jonas Fonseca <fonseca@diku.dk> | |
Sun, 28 May 2006 18:59:31 +0000 (20:59 +0200) | ||
committer | Jonas Fonseca <fonseca@antimatter.localdomain> | |
Sun, 28 May 2006 18:59:31 +0000 (20:59 +0200) |
tig.c | patch | blob | history |
index 982c1cc8a0eee0ce591d10fad17838aae2d62e32..121c5db76ddbff53f0f18d6923564631076f36e3 100644 (file)
--- a/tig.c
+++ b/tig.c
#define set_attribute(attr, name, namelen) \
set_from_int_map(attr_map, ARRAY_SIZE(attr_map), attr, name, namelen)
+static int config_lineno;
+static bool config_errors;
+static char *config_msg;
+
static int
-read_option(char *opt, int optlen, char *value, int valuelen)
+set_option(char *opt, int optlen, char *value, int valuelen)
{
- optlen = strcspn(opt, "#;");
- if (optlen == 0) {
- /* The whole line is a comment. */
- return OK;
-
- } else if (opt[optlen] != 0) {
- /* Part of the option name is a comment, so the value part
- * should be ignored. */
- valuelen = 0;
- opt[optlen] = value[valuelen] = 0;
- } else {
- /* Else look for comment endings in the value. */
- valuelen = strcspn(value, "#;");
- value[valuelen] = 0;
- }
-
/* Reads: "color" object fgcolor bgcolor [attr] */
if (!strcmp(opt, "color")) {
struct line_info *info;
value = chomp_string(value);
valuelen = strcspn(value, " \t");
info = get_line_info(value, valuelen);
- if (!info)
+ if (!info) {
+ config_msg = "Unknown color name";
return ERR;
+ }
value = chomp_string(value + valuelen);
valuelen = strcspn(value, " \t");
- if (set_color(&info->fg, value, valuelen) == ERR)
+ if (set_color(&info->fg, value, valuelen) == ERR) {
+ config_msg = "Unknown color";
return ERR;
+ }
value = chomp_string(value + valuelen);
valuelen = strcspn(value, " \t");
- if (set_color(&info->bg, value, valuelen) == ERR)
+ if (set_color(&info->bg, value, valuelen) == ERR) {
+ config_msg = "Unknown color";
return ERR;
+ }
value = chomp_string(value + valuelen);
if (*value &&
- set_attribute(&info->attr, value, strlen(value)) == ERR)
+ set_attribute(&info->attr, value, strlen(value)) == ERR) {
+ config_msg = "Unknown attribute";
return ERR;
+ }
return OK;
}
return ERR;
}
+static int
+read_option(char *opt, int optlen, char *value, int valuelen)
+{
+ config_lineno++;
+ config_msg = "Internal error";
+
+ optlen = strcspn(opt, "#;");
+ if (optlen == 0) {
+ /* The whole line is a commend or empty. */
+ return OK;
+
+ } else if (opt[optlen] != 0) {
+ /* Part of the option name is a comment, so the value part
+ * should be ignored. */
+ valuelen = 0;
+ opt[optlen] = value[valuelen] = 0;
+ } else {
+ /* Else look for comment endings in the value. */
+ valuelen = strcspn(value, "#;");
+ value[valuelen] = 0;
+ }
+
+ if (set_option(opt, optlen, value, valuelen) == ERR) {
+ fprintf(stderr, "Error on line %d, near '%.*s' option: %s\n",
+ config_lineno, optlen, opt, config_msg);
+ config_errors = TRUE;
+ }
+
+ /* Always keep going if errors are encountered. */
+ return OK;
+}
+
static int
load_options(void)
{
char buf[1024];
FILE *file;
+ config_lineno = 0;
+ config_errors = FALSE;
+
if (!home ||
snprintf(buf, sizeof(buf), "%s/.tig", home) >= sizeof(buf))
return ERR;
if (!file)
return OK;
- return read_properties(file, " \t", read_option);
+ if (read_properties(file, " \t", read_option) == ERR ||
+ config_errors == TRUE)
+ fprintf(stderr, "Errors while loading %s.\n", buf);
+
+ return OK;
}
valuelen = 0;
}
- if (namelen)
- state = read_property(name, namelen, value, valuelen);
+ state = read_property(name, namelen, value, valuelen);
}
if (state != ERR && ferror(pipe))