Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libterminfo/compile.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libterminfo/compile.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.1 retrieving revision 1.5.4.2 diff -u -p -r1.1 -r1.5.4.2 --- src/lib/libterminfo/compile.c 2010/02/22 23:05:39 1.1 +++ src/lib/libterminfo/compile.c 2012/10/30 18:59:18 1.5.4.2 @@ -1,7 +1,7 @@ -/* $NetBSD: compile.c,v 1.1 2010/02/22 23:05:39 roy Exp $ */ +/* $NetBSD: compile.c,v 1.5.4.2 2012/10/30 18:59:18 yamt Exp $ */ /* - * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. + * Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc. * * This code is derived from software contributed to The NetBSD Foundation * by Roy Marples. @@ -32,7 +32,11 @@ #endif #include -__RCSID("$NetBSD: compile.c,v 1.1 2010/02/22 23:05:39 roy Exp $"); +__RCSID("$NetBSD: compile.c,v 1.5.4.2 2012/10/30 18:59:18 yamt Exp $"); + +#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H +#include +#endif #include #include @@ -47,7 +51,7 @@ __RCSID("$NetBSD: compile.c,v 1.1 2010/0 #include #include -static void __attribute__((__format__(__printf__, 2, 3))) +static void __printflike(2, 3) dowarn(int flags, const char *fmt, ...) { va_list va; @@ -70,7 +74,7 @@ _ti_grow_tbuf(TBUF *tbuf, size_t len) l = tbuf->bufpos + len; if (l > tbuf->buflen) { - if (tbuf->bufpos == 0) + if (tbuf->buflen == 0) buf = malloc(l); else buf = realloc(tbuf->buf, l); @@ -235,7 +239,7 @@ _ti_flatten(uint8_t **buf, const TIC *ti return -1; cap = *buf; - *cap++ = 2; /* version */ + *cap++ = 1; le16enc(cap, len); cap += sizeof(uint16_t); memcpy(cap, tic->name, len); @@ -335,7 +339,7 @@ encode_string(const char *term, const ch if (ch == '?') ch = '\177'; else if ((ch &= 037) == 0) - ch = 128; + ch = (char)128; } *p++ = ch; last = ch; @@ -404,11 +408,10 @@ encode_string(const char *term, const ch return 0; } -static char * -get_token(char **cap) +char * +_ti_get_token(char **cap, char sep) { - char *token; - int esc; + char esc, *token; while (isspace((unsigned char)**cap)) (*cap)++; @@ -416,16 +419,21 @@ get_token(char **cap) return NULL; /* We can't use stresep(3) as ^ we need two escape chars */ - esc = 0; + esc = '\0'; for (token = *cap; - **cap != '\0' && (esc == 1 || **cap != ','); + **cap != '\0' && (esc != '\0' || **cap != sep); (*cap)++) { - if (esc == 0) { + if (esc == '\0') { if (**cap == '\\' || **cap == '^') - esc = 1; - } else - esc = 0; + esc = **cap; + } else { + /* termcap /E/ is valid */ + if (sep == ':' && esc == '\\' && **cap == 'E') + esc = 'x'; + else + esc = '\0'; + } } if (**cap != '\0') @@ -439,7 +447,8 @@ _ti_compile(char *cap, int flags) { char *token, *p, *e, *name, *desc, *alias; signed char flag; - long num; + long cnum; + short num; ssize_t ind; size_t len; TBUF buf; @@ -447,7 +456,7 @@ _ti_compile(char *cap, int flags) _DIAGASSERT(cap != NULL); - name = get_token(&cap); + name = _ti_get_token(&cap, ','); if (name == NULL) { dowarn(flags, "no seperator found: %s", cap); return NULL; @@ -480,9 +489,9 @@ _ti_compile(char *cap, int flags) goto error; } - for (token = get_token(&cap); + for (token = _ti_get_token(&cap, ','); token != NULL && *token != '\0'; - token = get_token(&cap)) + token = _ti_get_token(&cap, ',')) { /* Skip commented caps */ if (!(flags & TIC_COMMENT) && token[0] == '.') @@ -551,17 +560,18 @@ _ti_compile(char *cap, int flags) _ti_find_cap(&tic->nums, 'n', ind) != NULL) continue; - num = strtol(p, &e, 0); + cnum = strtol(p, &e, 0); if (*e != '\0') { dowarn(flags, "%s: %s: not a number", tic->name, token); continue; } - if (!VALID_NUMERIC(num)) { + if (!VALID_NUMERIC(cnum)) { dowarn(flags, "%s: %s: number out of range", tic->name, token); continue; } + num = (short)cnum; if (ind == -1) _ti_store_extra(tic, 1, token, 'n', -1, num, NULL, 0, flags); @@ -595,7 +605,7 @@ _ti_compile(char *cap, int flags) le16enc(tic->nums.buf + tic->nums.bufpos, ind); tic->nums.bufpos += sizeof(uint16_t); le16enc(tic->nums.buf + tic->nums.bufpos, - CANCELLED_NUMERIC); + (uint16_t)CANCELLED_NUMERIC); tic->nums.bufpos += sizeof(uint16_t); tic->nums.entries++; continue; @@ -644,6 +654,7 @@ _ti_freetic(TIC *tic) free(tic->name); free(tic->alias); free(tic->desc); + free(tic->extras.buf); free(tic->flags.buf); free(tic->nums.buf); free(tic->strs.buf);