Merge branch 'obsd-master'

Sync from OpenBSD.
This commit is contained in:
Thomas Adam 2012-12-08 20:29:37 +00:00
commit fb83914bd7
5 changed files with 57 additions and 45 deletions

32
cfg.c
View File

@ -73,46 +73,50 @@ cfg_add_cause(struct causelist *causes, const char *fmt, ...)
* Load configuration file. Returns -1 for an error with a list of messages in
* causes. Note that causes must be initialised by the caller!
*/
int
enum cmd_retval
load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
{
FILE *f;
u_int n;
char *buf, *line, *cause;
size_t len;
size_t len, newlen;
struct cmd_list *cmdlist;
struct cmd_ctx ctx;
enum cmd_retval retval;
if ((f = fopen(path, "rb")) == NULL) {
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
return (-1);
return (CMD_RETURN_ERROR);
}
n = 0;
cfg_references++;
n = 0;
line = NULL;
retval = CMD_RETURN_NORMAL;
while ((buf = fgetln(f, &len))) {
if (buf[len - 1] == '\n')
len--;
if (line != NULL)
line = xrealloc(line, 1, strlen(line) + len + 1);
else {
line = xmalloc(len + 1);
/* Current line is the continuation of the previous one. */
if (line != NULL) {
newlen = strlen(line) + len + 1;
line = xrealloc(line, 1, newlen);
} else {
newlen = len + 1;
line = xmalloc(newlen);
*line = '\0';
}
/* Append buffer to line. strncat will terminate. */
strncat(line, buf, len);
/* Append current line to the previous. */
strlcat(line, buf, newlen);
n++;
/* Continuation: get next line? */
len = strlen(line);
if (len > 0 && line[len - 1] == '\\') {
line[len - 1] = '\0';
/* Ignore escaped backslash at EOL. */
if (len > 1 && line[len - 2] != '\\')
continue;
@ -127,11 +131,10 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
free(cause);
continue;
} else
free(buf);
}
free(buf);
if (cmdlist == NULL)
continue;
cfg_cause = NULL;
if (ctxin == NULL) {
ctx.msgdata = NULL;
@ -162,8 +165,7 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
}
cmd_list_free(cmdlist);
if (cfg_cause != NULL) {
cfg_add_cause(
causes, "%s: %d: %s", path, n, cfg_cause);
cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
free(cfg_cause);
}
}

View File

@ -31,11 +31,12 @@
* Parse a command from a string.
*/
int cmd_string_getc(const char *, size_t *);
void cmd_string_ungetc(size_t *);
char *cmd_string_string(const char *, size_t *, char, int);
char *cmd_string_variable(const char *, size_t *);
char *cmd_string_expand_tilde(const char *, size_t *);
int cmd_string_getc(const char *, size_t *);
void cmd_string_ungetc(size_t *);
void cmd_string_copy(char **, char *, size_t *);
char *cmd_string_string(const char *, size_t *, char, int);
char *cmd_string_variable(const char *, size_t *);
char *cmd_string_expand_tilde(const char *, size_t *);
int
cmd_string_getc(const char *s, size_t *p)
@ -84,26 +85,17 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
case '\'':
if ((t = cmd_string_string(s, &p, '\'', 0)) == NULL)
goto error;
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
free(t);
cmd_string_copy(&buf, t, &len);
break;
case '"':
if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
goto error;
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
free(t);
cmd_string_copy(&buf, t, &len);
break;
case '$':
if ((t = cmd_string_variable(s, &p)) == NULL)
goto error;
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
free(t);
cmd_string_copy(&buf, t, &len);
break;
case '#':
/* Comment: discard rest of line. */
@ -147,12 +139,10 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
goto out;
case '~':
if (buf == NULL) {
if ((t = cmd_string_expand_tilde(s, &p)) == NULL)
t = cmd_string_expand_tilde(s, &p);
if (t == NULL)
goto error;
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
free(t);
cmd_string_copy(&buf, t, &len);
break;
}
/* FALLTHROUGH */
@ -181,6 +171,20 @@ out:
return (rval);
}
void
cmd_string_copy(char **dst, char *src, size_t *len)
{
size_t srclen;
srclen = strlen(src);
*dst = xrealloc(*dst, 1, *len + srclen + 1);
strlcpy(*dst + *len, src, srclen + 1);
*len += srclen;
free(src);
}
char *
cmd_string_string(const char *s, size_t *p, char endch, int esc)
{
@ -220,10 +224,7 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
break;
if ((t = cmd_string_variable(s, p)) == NULL)
goto error;
buf = xrealloc(buf, 1, len + strlen(t) + 1);
strlcpy(buf + len, t, strlen(t) + 1);
len += strlen(t);
free(t);
cmd_string_copy(&buf, t, &len);
continue;
}

View File

@ -324,6 +324,9 @@ screen_write_parsestyle(
fg = defgc->fg;
bg = defgc->bg;
attr = defgc->attr;
flags &= ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
flags |=
defgc->flags & (GRID_FLAG_FG256|GRID_FLAG_BG256);
} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
if ((val = colour_fromstring(tmp + 3)) == -1)
return;
@ -335,8 +338,11 @@ screen_write_parsestyle(
} else
flags &= ~GRID_FLAG_FG256;
fg = val;
} else
} else {
fg = defgc->fg;
flags &= ~GRID_FLAG_FG256;
flags |= defgc->flags & GRID_FLAG_FG256;
}
} else if (*in == 'b' || *in == 'B') {
if (val != 8) {
if (val & 0x100) {
@ -345,8 +351,11 @@ screen_write_parsestyle(
} else
flags &= ~GRID_FLAG_BG256;
bg = val;
} else
} else {
bg = defgc->bg;
flags &= ~GRID_FLAG_BG256;
flags |= defgc->flags & GRID_FLAG_BG256;
}
} else
return;
} else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {

View File

@ -167,7 +167,7 @@ server_start(int lockfd, char *lockfile)
load_cfg(SYSTEM_CFG, NULL, &cfg_causes);
else if (errno != ENOENT) {
cfg_add_cause(
&cfg_causes, "%s: %s", strerror(errno), SYSTEM_CFG);
&cfg_causes, "%s: %s", SYSTEM_CFG, strerror(errno));
}
if (cfg_file != NULL)
load_cfg(cfg_file, NULL, &cfg_causes);

2
tmux.h
View File

@ -1516,7 +1516,7 @@ extern int cfg_finished;
extern int cfg_references;
extern struct causelist cfg_causes;
void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
int load_cfg(const char *, struct cmd_ctx *, struct causelist *);
enum cmd_retval load_cfg(const char *, struct cmd_ctx *, struct causelist *);
void show_cfg_causes(struct session *);
/* format.c */