diff --git a/edit.c b/edit.c index 6144b6b..abde485 100644 --- a/edit.c +++ b/edit.c @@ -28,7 +28,7 @@ #ifndef MKSH_NO_CMDLINE_EDITING -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.252 2012/09/21 17:20:20 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.253 2012/10/03 15:50:29 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -242,7 +242,7 @@ x_print_expansions(int nwords, char * const *words, bool is_command) { bool use_copy = false; int prefix_len; - XPtrV l = { NULL, NULL, NULL }; + XPtrV l = { NULL, 0, 0 }; /* * Check if all matches are in the same directory (in this @@ -439,7 +439,7 @@ static int x_command_glob(int flags, char *toglob, char ***wordsp) { char *pat, *fpath; - int nwords; + size_t nwords; XPtrV w; struct block *l; @@ -470,7 +470,7 @@ x_command_glob(int flags, char *toglob, char ***wordsp) /* Sort by basename, then path order */ struct path_order_info *info, *last_info = NULL; char **words = (char **)XPptrv(w); - int i, path_order = 0; + size_t i, path_order = 0; info = (struct path_order_info *) alloc2(nwords, sizeof(struct path_order_info), ATEMP); @@ -492,7 +492,7 @@ x_command_glob(int flags, char *toglob, char ***wordsp) } else { /* Sort and remove duplicate entries */ char **words = (char **)XPptrv(w); - int i, j; + size_t i, j; qsort(words, nwords, sizeof(void *), xstrcmp); for (i = j = 0; i < nwords - 1; i++) { @@ -502,8 +502,7 @@ x_command_glob(int flags, char *toglob, char ***wordsp) afree(words[i], ATEMP); } words[j++] = words[i]; - nwords = j; - w.cur = (void **)&words[j]; + w.len = nwords = j; } XPput(w, NULL); @@ -796,7 +795,7 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath) } else afree(words[i], ATEMP); } - wp->cur = (void **)&words[j]; + wp->len = j; if (!*sp++) break; diff --git a/sh.h b/sh.h index 001b264..a7d7c7e 100644 --- a/sh.h +++ b/sh.h @@ -157,7 +157,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.588 2012/10/03 15:13:34 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.589 2012/10/03 15:50:31 tg Exp $"); #endif #define MKSH_VERSION "R40 2012/09/07" @@ -1413,35 +1413,38 @@ char *Xcheck_grow(XString *, const char *, size_t); * expandable vector of generic pointers */ -typedef struct XPtrV { - void **cur; /* next avail pointer */ - void **beg, **end; /* begin, end of vector */ +typedef struct { + /* begin of allocated area */ + void **beg; + /* currently used number of entries */ + size_t len; + /* allocated number of entries */ + size_t siz; } XPtrV; -#define XPinit(x, n) do { \ - void **XPinit_vp; \ - XPinit_vp = alloc2((n), sizeof(void *), ATEMP); \ - (x).cur = (x).beg = XPinit_vp; \ - (x).end = XPinit_vp + (n); \ -} while (/* CONSTCOND */ 0) +#define XPinit(x, n) do { \ + (x).siz = (n); \ + (x).len = 0; \ + (x).beg = alloc2((x).siz, sizeof(void *), ATEMP); \ +} while (/* CONSTCOND */ 0) \ -#define XPput(x, p) do { \ - if ((x).cur >= (x).end) { \ - size_t n = XPsize(x); \ - (x).beg = aresize2((x).beg, \ - n, 2 * sizeof(void *), ATEMP); \ - (x).cur = (x).beg + n; \ - (x).end = (x).cur + n; \ +#define XPput(x, p) do { \ + if ((x).len == (x).siz) { \ + (x).beg = aresize2((x).beg, (x).siz, \ + 2 * sizeof(void *), ATEMP); \ + (x).siz <<= 1; \ } \ - *(x).cur++ = (p); \ + (x).beg[(x).len++] = (p); \ } while (/* CONSTCOND */ 0) #define XPptrv(x) ((x).beg) -#define XPsize(x) ((x).cur - (x).beg) +#define XPsize(x) ((x).len) #define XPclose(x) aresize2((x).beg, XPsize(x), sizeof(void *), ATEMP) #define XPfree(x) afree((x).beg, ATEMP) -#define IDENT 64 +/* + * Lexer internals + */ typedef struct source Source; struct source { @@ -1542,10 +1545,12 @@ typedef union { #define CTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F) /* ASCII */ #define UNCTRL(x) ((x) ^ 0x40) /* ASCII */ +#define IDENT 64 + EXTERN Source *source; /* yyparse/yylex source */ EXTERN YYSTYPE yylval; /* result from yylex */ EXTERN struct ioword *heres[HERES], **herep; -EXTERN char ident[IDENT+1]; +EXTERN char ident[IDENT + 1]; EXTERN char **history; /* saved commands */ EXTERN char **histptr; /* last history item */ diff --git a/syn.c b/syn.c index a14b0bc..44a4337 100644 --- a/syn.c +++ b/syn.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.80 2012/08/17 18:34:25 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.81 2012/10/03 15:50:32 tg Exp $"); extern void yyskiputf8bom(void); @@ -319,7 +319,7 @@ get_command(int cf) ACCEPT; /* manipulate the vars string */ - tcp = *(--vars.cur); + tcp = XPptrv(vars)[(vars.len = 0)]; /* 'varname=' -> 'varname' */ tcp[wdscan(tcp, EOS) - tcp - 3] = EOS;