run a bit of indent over it
not really suitable tho
This commit is contained in:
211
edit.c
211
edit.c
@ -1,4 +1,4 @@
|
|||||||
/** $MirOS: src/bin/mksh/edit.c,v 1.6 2005/06/08 21:51:20 tg Exp $ */
|
/** $MirOS: src/bin/mksh/edit.c,v 1.7 2005/06/08 22:22:23 tg Exp $ */
|
||||||
/* $OpenBSD: edit.c,v 1.29 2005/04/13 02:33:08 deraadt Exp $ */
|
/* $OpenBSD: edit.c,v 1.29 2005/04/13 02:33:08 deraadt Exp $ */
|
||||||
/* $OpenBSD: edit.h,v 1.8 2005/03/28 21:28:22 deraadt Exp $ */
|
/* $OpenBSD: edit.h,v 1.8 2005/03/28 21:28:22 deraadt Exp $ */
|
||||||
/* $OpenBSD: emacs.c,v 1.37 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: emacs.c,v 1.37 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
@ -10,7 +10,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.6 2005/06/08 21:51:20 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.7 2005/06/08 22:22:23 tg Exp $");
|
||||||
|
|
||||||
#define BEL 0x07
|
#define BEL 0x07
|
||||||
|
|
||||||
@ -41,10 +41,10 @@ int promptlen(const char *, const char **);
|
|||||||
int x_do_comment(char *, int, int *);
|
int x_do_comment(char *, int, int *);
|
||||||
void x_print_expansions(int, char *const *, int);
|
void x_print_expansions(int, char *const *, int);
|
||||||
int x_cf_glob(int, const char *, int, int, int *, int *, char ***, int *);
|
int x_cf_glob(int, const char *, int, int, int *, int *, char ***, int *);
|
||||||
int x_longest_prefix(int , char *const *);
|
int x_longest_prefix(int, char *const *);
|
||||||
int x_basename(const char *, const char *);
|
int x_basename(const char *, const char *);
|
||||||
void x_free_words(int, char **);
|
void x_free_words(int, char **);
|
||||||
int x_escape(const char *, size_t, int (*)(const char *, size_t));
|
int x_escape(const char *, size_t, int (*) (const char *, size_t));
|
||||||
int x_emacs(char *, size_t);
|
int x_emacs(char *, size_t);
|
||||||
void x_init_emacs(void);
|
void x_init_emacs(void);
|
||||||
void x_emacs_keys(X_chars *);
|
void x_emacs_keys(X_chars *);
|
||||||
@ -70,7 +70,8 @@ x_init(void)
|
|||||||
/* default value for deficient systems */
|
/* default value for deficient systems */
|
||||||
edchars.werase = 027; /* ^W */
|
edchars.werase = 027; /* ^W */
|
||||||
|
|
||||||
if (setsig(&sigtraps[SIGWINCH], x_sigwinch, SS_RESTORE_ORIG|SS_SHTRAP))
|
if (setsig(&sigtraps[SIGWINCH], x_sigwinch,
|
||||||
|
SS_RESTORE_ORIG | SS_SHTRAP))
|
||||||
sigtraps[SIGWINCH].flags |= TF_SHELL_USES;
|
sigtraps[SIGWINCH].flags |= TF_SHELL_USES;
|
||||||
check_sigwinch(); /* force initial check */
|
check_sigwinch(); /* force initial check */
|
||||||
|
|
||||||
@ -103,10 +104,10 @@ check_sigwinch(void)
|
|||||||
x_cols = ws.ws_col < MIN_COLS ? MIN_COLS : ws.ws_col;
|
x_cols = ws.ws_col < MIN_COLS ? MIN_COLS : ws.ws_col;
|
||||||
|
|
||||||
if ((vp = typeset("COLUMNS", 0, 0, 0, 0)))
|
if ((vp = typeset("COLUMNS", 0, 0, 0, 0)))
|
||||||
setint(vp, (long) ws.ws_col);
|
setint(vp, (long)ws.ws_col);
|
||||||
}
|
}
|
||||||
if (ws.ws_row && (vp = typeset("LINES", 0, 0, 0, 0)))
|
if (ws.ws_row && (vp = typeset("LINES", 0, 0, 0, 0)))
|
||||||
setint(vp, (long) ws.ws_row);
|
setint(vp, (long)ws.ws_row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +149,7 @@ x_getc(void)
|
|||||||
}
|
}
|
||||||
if (n != 1)
|
if (n != 1)
|
||||||
return -1;
|
return -1;
|
||||||
return (int) (unsigned char) c;
|
return (int)(unsigned char)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -194,8 +195,8 @@ x_mode(bool onoff)
|
|||||||
edchars.quit = cb.c_cc[VQUIT];
|
edchars.quit = cb.c_cc[VQUIT];
|
||||||
edchars.eof = cb.c_cc[VEOF];
|
edchars.eof = cb.c_cc[VEOF];
|
||||||
edchars.werase = cb.c_cc[VWERASE];
|
edchars.werase = cb.c_cc[VWERASE];
|
||||||
cb.c_iflag &= ~(INLCR|ICRNL);
|
cb.c_iflag &= ~(INLCR | ICRNL);
|
||||||
cb.c_lflag &= ~(ISIG|ICANON|ECHO);
|
cb.c_lflag &= ~(ISIG | ICANON | ECHO);
|
||||||
/* osf/1 processes lnext when ~icanon */
|
/* osf/1 processes lnext when ~icanon */
|
||||||
cb.c_cc[VLNEXT] = _POSIX_VDISABLE;
|
cb.c_cc[VLNEXT] = _POSIX_VDISABLE;
|
||||||
/* sunos 4.1.x & osf/1 processes discard(flush) when ~icanon */
|
/* sunos 4.1.x & osf/1 processes discard(flush) when ~icanon */
|
||||||
@ -247,7 +248,6 @@ promptlen(const char *cp, const char **spp)
|
|||||||
delimiter = *cp;
|
delimiter = *cp;
|
||||||
cp += 2;
|
cp += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; *cp; cp++) {
|
for (; *cp; cp++) {
|
||||||
if (indelimit && *cp != delimiter)
|
if (indelimit && *cp != delimiter)
|
||||||
;
|
;
|
||||||
@ -281,7 +281,7 @@ set_editmode(const char *ed)
|
|||||||
if ((rcp = strrchr(ed, '/')))
|
if ((rcp = strrchr(ed, '/')))
|
||||||
ed = ++rcp;
|
ed = ++rcp;
|
||||||
for (i = 0; i < NELEM(edit_flags); i++)
|
for (i = 0; i < NELEM(edit_flags); i++)
|
||||||
if (strstr(ed, options[(int) edit_flags[i]].name)) {
|
if (strstr(ed, options[(int)edit_flags[i]].name)) {
|
||||||
change_flag(edit_flags[i], OF_SPECIAL, 1);
|
change_flag(edit_flags[i], OF_SPECIAL, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ static void glob_table(const char *, XPtrV *, struct table *);
|
|||||||
static void glob_path(int flags, const char *, XPtrV *, const char *);
|
static void glob_path(int flags, const char *, XPtrV *, const char *);
|
||||||
|
|
||||||
void
|
void
|
||||||
x_print_expansions(int nwords, char *const *words, int is_command)
|
x_print_expansions(int nwords, char * const *words, int is_command)
|
||||||
{
|
{
|
||||||
int use_copy = 0;
|
int use_copy = 0;
|
||||||
int prefix_len;
|
int prefix_len;
|
||||||
@ -380,13 +380,12 @@ x_print_expansions(int nwords, char *const *words, int is_command)
|
|||||||
XPput(l, NULL);
|
XPput(l, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enumerate expansions
|
* Enumerate expansions
|
||||||
*/
|
*/
|
||||||
x_putc('\r');
|
x_putc('\r');
|
||||||
x_putc('\n');
|
x_putc('\n');
|
||||||
pr_list(use_copy ? (char **) XPptrv(l) : words);
|
pr_list(use_copy ? (char **)XPptrv(l) : words);
|
||||||
|
|
||||||
if (use_copy)
|
if (use_copy)
|
||||||
XPfree(l); /* not x_free_words() */
|
XPfree(l); /* not x_free_words() */
|
||||||
@ -427,7 +426,8 @@ x_file_glob(int flags __attribute__((unused)), const char *str,
|
|||||||
|
|
||||||
toglob[idx] = toglob[i];
|
toglob[idx] = toglob[i];
|
||||||
idx++;
|
idx++;
|
||||||
if (escaping) escaping = 0;
|
if (escaping)
|
||||||
|
escaping = 0;
|
||||||
}
|
}
|
||||||
toglob[idx] = '\0';
|
toglob[idx] = '\0';
|
||||||
|
|
||||||
@ -438,16 +438,16 @@ x_file_glob(int flags __attribute__((unused)), const char *str,
|
|||||||
s = pushs(SWSTR, ATEMP);
|
s = pushs(SWSTR, ATEMP);
|
||||||
s->start = s->str = toglob;
|
s->start = s->str = toglob;
|
||||||
source = s;
|
source = s;
|
||||||
if (yylex(ONEWORD|LQCHAR) != LWORD) {
|
if (yylex(ONEWORD | LQCHAR) != LWORD) {
|
||||||
source = sold;
|
source = sold;
|
||||||
internal_errorf(0, "fileglob: substitute error");
|
internal_errorf(0, "fileglob: substitute error");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
source = sold;
|
source = sold;
|
||||||
XPinit(w, 32);
|
XPinit(w, 32);
|
||||||
expand(yylval.cp, &w, DOGLOB|DOTILDE|DOMARKDIRS);
|
expand(yylval.cp, &w, DOGLOB | DOTILDE | DOMARKDIRS);
|
||||||
XPput(w, NULL);
|
XPput(w, NULL);
|
||||||
words = (char **) XPclose(w);
|
words = (char **)XPclose(w);
|
||||||
|
|
||||||
for (nwords = 0; words[nwords]; nwords++)
|
for (nwords = 0; words[nwords]; nwords++)
|
||||||
;
|
;
|
||||||
@ -512,7 +512,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
|
|||||||
toglob = add_glob(str, slen);
|
toglob = add_glob(str, slen);
|
||||||
|
|
||||||
/* Convert "foo*" (toglob) to a pattern for future use */
|
/* Convert "foo*" (toglob) to a pattern for future use */
|
||||||
pat = evalstr(toglob, DOPAT|DOTILDE);
|
pat = evalstr(toglob, DOPAT | DOTILDE);
|
||||||
afree(toglob, ATEMP);
|
afree(toglob, ATEMP);
|
||||||
|
|
||||||
XPinit(w, 32);
|
XPinit(w, 32);
|
||||||
@ -534,13 +534,12 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
|
|||||||
XPfree(w);
|
XPfree(w);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sort entries */
|
/* Sort entries */
|
||||||
if (flags & XCF_FULLPATH) {
|
if (flags & XCF_FULLPATH) {
|
||||||
/* Sort by basename, then path order */
|
/* Sort by basename, then path order */
|
||||||
struct path_order_info *info;
|
struct path_order_info *info;
|
||||||
struct path_order_info *last_info = 0;
|
struct path_order_info *last_info = 0;
|
||||||
char **words = (char **) XPptrv(w);
|
char **words = (char **)XPptrv(w);
|
||||||
int path_order = 0;
|
int path_order = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -560,13 +559,13 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
|
|||||||
path_order_cmp);
|
path_order_cmp);
|
||||||
for (i = 0; i < nwords; i++)
|
for (i = 0; i < nwords; i++)
|
||||||
words[i] = info[i].word;
|
words[i] = info[i].word;
|
||||||
afree((void *) info, ATEMP);
|
afree((void *)info, ATEMP);
|
||||||
} else {
|
} else {
|
||||||
/* Sort and remove duplicate entries */
|
/* Sort and remove duplicate entries */
|
||||||
char **words = (char **) XPptrv(w);
|
char **words = (char **)XPptrv(w);
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
qsortp(XPptrv(w), (size_t) nwords, xstrcmp);
|
qsortp(XPptrv(w), (size_t)nwords, xstrcmp);
|
||||||
|
|
||||||
for (i = j = 0; i < nwords - 1; i++) {
|
for (i = j = 0; i < nwords - 1; i++) {
|
||||||
if (strcmp(words[i], words[i + 1]))
|
if (strcmp(words[i], words[i + 1]))
|
||||||
@ -576,11 +575,11 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
|
|||||||
}
|
}
|
||||||
words[j++] = words[i];
|
words[j++] = words[i];
|
||||||
nwords = j;
|
nwords = j;
|
||||||
w.cur = (void **) &words[j];
|
w.cur = (void **)&words[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
XPput(w, NULL);
|
XPput(w, NULL);
|
||||||
*wordsp = (char **) XPclose(w);
|
*wordsp = (char **)XPclose(w);
|
||||||
|
|
||||||
return nwords;
|
return nwords;
|
||||||
}
|
}
|
||||||
@ -608,11 +607,11 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
|
|||||||
* one blank after the end of a word)
|
* one blank after the end of a word)
|
||||||
*/
|
*/
|
||||||
for (; (start > 0 && IS_WORDC(buf[start - 1])) ||
|
for (; (start > 0 && IS_WORDC(buf[start - 1])) ||
|
||||||
(start > 1 && buf[start-2] == '\\'); start--)
|
(start > 1 && buf[start - 2] == '\\'); start--)
|
||||||
;
|
;
|
||||||
/* Go forwards to end of word */
|
/* Go forwards to end of word */
|
||||||
for (end = start; end < buflen && IS_WORDC(buf[end]); end++) {
|
for (end = start; end < buflen && IS_WORDC(buf[end]); end++) {
|
||||||
if (buf[end] == '\\' && (end+1) < buflen)
|
if (buf[end] == '\\' && (end + 1) < buflen)
|
||||||
end++;
|
end++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,7 +634,6 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
|
|||||||
}
|
}
|
||||||
*is_commandp = iscmd;
|
*is_commandp = iscmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
*startp = start;
|
*startp = start;
|
||||||
|
|
||||||
return end - start;
|
return end - start;
|
||||||
@ -660,13 +658,12 @@ x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp,
|
|||||||
if (len == 0 && is_command)
|
if (len == 0 && is_command)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
nwords = (is_command ? x_command_glob : x_file_glob)(flags,
|
nwords = (is_command ? x_command_glob : x_file_glob) (flags,
|
||||||
buf + *startp, len, &words);
|
buf + *startp, len, &words);
|
||||||
if (nwords == 0) {
|
if (nwords == 0) {
|
||||||
*wordsp = NULL;
|
*wordsp = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_commandp)
|
if (is_commandp)
|
||||||
*is_commandp = is_command;
|
*is_commandp = is_command;
|
||||||
*wordsp = words;
|
*wordsp = words;
|
||||||
@ -701,7 +698,7 @@ add_glob(const char *str, int slen)
|
|||||||
if (*s == '\\' && s[1])
|
if (*s == '\\' && s[1])
|
||||||
s++;
|
s++;
|
||||||
else if (*s == '*' || *s == '[' || *s == '?' || *s == '$'
|
else if (*s == '*' || *s == '[' || *s == '?' || *s == '$'
|
||||||
|| (s[1] == '(' /*)*/ && strchr("*+?@!", *s)))
|
|| (s[1] == '(' && strchr("*+?@!", *s)))
|
||||||
break;
|
break;
|
||||||
else if (*s == '/')
|
else if (*s == '/')
|
||||||
saw_slash = true;
|
saw_slash = true;
|
||||||
@ -710,7 +707,6 @@ add_glob(const char *str, int slen)
|
|||||||
toglob[slen] = '*';
|
toglob[slen] = '*';
|
||||||
toglob[slen + 1] = '\0';
|
toglob[slen + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return toglob;
|
return toglob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -718,7 +714,7 @@ add_glob(const char *str, int slen)
|
|||||||
* Find longest common prefix
|
* Find longest common prefix
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
x_longest_prefix(int nwords, char *const *words)
|
x_longest_prefix(int nwords, char * const * words)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
int prefix_len;
|
int prefix_len;
|
||||||
@ -841,7 +837,7 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath)
|
|||||||
newsize = XPsize(*wp);
|
newsize = XPsize(*wp);
|
||||||
|
|
||||||
/* Check that each match is executable... */
|
/* Check that each match is executable... */
|
||||||
words = (char **) XPptrv(*wp);
|
words = (char **)XPptrv(*wp);
|
||||||
for (i = j = oldsize; i < newsize; i++) {
|
for (i = j = oldsize; i < newsize; i++) {
|
||||||
staterr = 0;
|
staterr = 0;
|
||||||
if ((search_access(words[i], X_OK, &staterr) >= 0) ||
|
if ((search_access(words[i], X_OK, &staterr) >= 0) ||
|
||||||
@ -854,7 +850,7 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath)
|
|||||||
} else
|
} else
|
||||||
afree(words[i], ATEMP);
|
afree(words[i], ATEMP);
|
||||||
}
|
}
|
||||||
wp->cur = (void **) &words[j];
|
wp->cur = (void **)&words[j];
|
||||||
|
|
||||||
if (!*sp++)
|
if (!*sp++)
|
||||||
break;
|
break;
|
||||||
@ -872,7 +868,7 @@ x_escape(const char *s, size_t len, int (*putbuf_func) (const char *, size_t))
|
|||||||
{
|
{
|
||||||
size_t add, wlen;
|
size_t add, wlen;
|
||||||
const char *ifs = str_val(local("IFS", 0));
|
const char *ifs = str_val(local("IFS", 0));
|
||||||
int rval=0;
|
int rval = 0;
|
||||||
|
|
||||||
for (add = 0, wlen = len; wlen - add > 0; add++) {
|
for (add = 0, wlen = len; wlen - add > 0; add++) {
|
||||||
if (strchr("\\$()[{}*&;#|<>\"'`", s[add]) || strchr(ifs, s[add])) {
|
if (strchr("\\$()[{}*&;#|<>\"'`", s[add]) || strchr(ifs, s[add])) {
|
||||||
@ -880,7 +876,6 @@ x_escape(const char *s, size_t len, int (*putbuf_func) (const char *, size_t))
|
|||||||
rval = -1;
|
rval = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
putbuf_func("\\", 1);
|
putbuf_func("\\", 1);
|
||||||
putbuf_func(&s[add], 1);
|
putbuf_func(&s[add], 1);
|
||||||
|
|
||||||
@ -1315,7 +1310,6 @@ x_emacs(char *buf, size_t len)
|
|||||||
x_load_hist(histptr - off);
|
x_load_hist(histptr - off);
|
||||||
x_nextcmd = -1;
|
x_nextcmd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
x_flush();
|
x_flush();
|
||||||
if ((c = x_e_getc()) < 0)
|
if ((c = x_e_getc()) < 0)
|
||||||
@ -1325,9 +1319,8 @@ x_emacs(char *buf, size_t len)
|
|||||||
c = META(c);
|
c = META(c);
|
||||||
x_curprefix = 1;
|
x_curprefix = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
f = x_curprefix == -1 ? XFUNC_insert :
|
f = x_curprefix == -1 ? XFUNC_insert :
|
||||||
x_tab[x_curprefix][c&CHARMASK];
|
x_tab[x_curprefix][c & CHARMASK];
|
||||||
|
|
||||||
if (!(x_ftab[f].xf_flags & XF_PREFIX) &&
|
if (!(x_ftab[f].xf_flags & XF_PREFIX) &&
|
||||||
x_last_command != XFUNC_set_arg) {
|
x_last_command != XFUNC_set_arg) {
|
||||||
@ -1378,7 +1371,7 @@ x_ins_string(int c)
|
|||||||
x_e_putc(BEL);
|
x_e_putc(BEL);
|
||||||
return KSTD;
|
return KSTD;
|
||||||
}
|
}
|
||||||
macroptr = x_atab[c>>8][c & CHARMASK];
|
macroptr = x_atab[c >> 8][c & CHARMASK];
|
||||||
if (macroptr && !*macroptr) {
|
if (macroptr && !*macroptr) {
|
||||||
/* XXX bell? */
|
/* XXX bell? */
|
||||||
macroptr = NULL;
|
macroptr = NULL;
|
||||||
@ -1391,12 +1384,11 @@ static int x_do_ins(const char *cp, int len);
|
|||||||
static int
|
static int
|
||||||
x_do_ins(const char *cp, int len)
|
x_do_ins(const char *cp, int len)
|
||||||
{
|
{
|
||||||
if (xep+len >= xend) {
|
if (xep + len >= xend) {
|
||||||
x_e_putc(BEL);
|
x_e_putc(BEL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
memmove(xcp + len, xcp, xep - xcp + 1);
|
||||||
memmove(xcp+len, xcp, xep - xcp + 1);
|
|
||||||
memmove(xcp, cp, len);
|
memmove(xcp, cp, len);
|
||||||
xcp += len;
|
xcp += len;
|
||||||
xep += len;
|
xep += len;
|
||||||
@ -1424,7 +1416,6 @@ x_ins(char *s)
|
|||||||
for (cp = xlp; cp > xcp; )
|
for (cp = xlp; cp > xcp; )
|
||||||
x_bs(*--cp);
|
x_bs(*--cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
x_adj_ok = 1;
|
x_adj_ok = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1477,7 +1468,7 @@ x_del_char(int c __attribute__((unused)))
|
|||||||
static void
|
static void
|
||||||
x_delete(int nc, int push)
|
x_delete(int nc, int push)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i, j;
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
if (nc == 0)
|
if (nc == 0)
|
||||||
@ -1488,7 +1479,6 @@ x_delete(int nc, int push)
|
|||||||
else
|
else
|
||||||
xmp -= nc;
|
xmp -= nc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This lets us yank a word we have deleted.
|
* This lets us yank a word we have deleted.
|
||||||
*/
|
*/
|
||||||
@ -1502,7 +1492,7 @@ x_delete(int nc, int push)
|
|||||||
while (i--) {
|
while (i--) {
|
||||||
j += x_size(*cp++);
|
j += x_size(*cp++);
|
||||||
}
|
}
|
||||||
memmove(xcp, xcp+nc, xep - xcp + 1); /* Copies the null */
|
memmove(xcp, xcp + nc, xep - xcp + 1); /* Copies the null */
|
||||||
x_adj_ok = 0; /* don't redraw */
|
x_adj_ok = 0; /* don't redraw */
|
||||||
x_zots(xcp);
|
x_zots(xcp);
|
||||||
/*
|
/*
|
||||||
@ -1522,7 +1512,7 @@ x_delete(int nc, int push)
|
|||||||
/*x_goto(xcp);*/
|
/*x_goto(xcp);*/
|
||||||
x_adj_ok = 1;
|
x_adj_ok = 1;
|
||||||
xlp_valid = false;
|
xlp_valid = false;
|
||||||
for (cp = x_lastcp(); cp > xcp; )
|
for (cp = x_lastcp(); cp > xcp;)
|
||||||
x_bs(*--cp);
|
x_bs(*--cp);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -1641,7 +1631,7 @@ x_size_str(char *cp)
|
|||||||
static int
|
static int
|
||||||
x_size(int c)
|
x_size(int c)
|
||||||
{
|
{
|
||||||
if (c=='\t')
|
if (c == '\t')
|
||||||
return 4; /* Kludge, tabs are always four spaces. */
|
return 4; /* Kludge, tabs are always four spaces. */
|
||||||
if (iscntrl(c)) /* control char */
|
if (iscntrl(c)) /* control char */
|
||||||
return 2;
|
return 2;
|
||||||
@ -1845,7 +1835,7 @@ static int
|
|||||||
x_search_hist(int c)
|
x_search_hist(int c)
|
||||||
{
|
{
|
||||||
int offset = -1; /* offset of match in xbuf, else -1 */
|
int offset = -1; /* offset of match in xbuf, else -1 */
|
||||||
char pat [256+1]; /* pattern buffer */
|
char pat[256 + 1]; /* pattern buffer */
|
||||||
char *p = pat;
|
char *p = pat;
|
||||||
u_char f;
|
u_char f;
|
||||||
|
|
||||||
@ -1858,7 +1848,7 @@ x_search_hist(int c)
|
|||||||
x_flush();
|
x_flush();
|
||||||
if ((c = x_e_getc()) < 0)
|
if ((c = x_e_getc()) < 0)
|
||||||
return KSTD;
|
return KSTD;
|
||||||
f = x_tab[0][c&CHARMASK];
|
f = x_tab[0][c & CHARMASK];
|
||||||
if (c == MKCTRL('['))
|
if (c == MKCTRL('['))
|
||||||
break;
|
break;
|
||||||
else if (f == XFUNC_search_hist)
|
else if (f == XFUNC_search_hist)
|
||||||
@ -1910,7 +1900,7 @@ x_search(char *pat, int sameline, int offset)
|
|||||||
char **hp;
|
char **hp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (hp = x_histp - (sameline ? 0 : 1) ; hp >= history; --hp) {
|
for (hp = x_histp - (sameline ? 0 : 1); hp >= history; --hp) {
|
||||||
i = x_match(*hp, pat);
|
i = x_match(*hp, pat);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
@ -1930,7 +1920,7 @@ static int
|
|||||||
x_match(char *str, char *pat)
|
x_match(char *str, char *pat)
|
||||||
{
|
{
|
||||||
if (*pat == '^') {
|
if (*pat == '^') {
|
||||||
return (strncmp(str, pat+1, strlen(pat+1)) == 0) ? 0 : -1;
|
return (strncmp(str, pat + 1, strlen(pat + 1)) == 0) ? 0 : -1;
|
||||||
} else {
|
} else {
|
||||||
char *q = strstr(str, pat);
|
char *q = strstr(str, pat);
|
||||||
return (q == NULL) ? -1 : q - str;
|
return (q == NULL) ? -1 : q - str;
|
||||||
@ -2140,7 +2130,7 @@ x_yank(int c __attribute__((unused)))
|
|||||||
killtp = KILLSIZE;
|
killtp = KILLSIZE;
|
||||||
else
|
else
|
||||||
killtp = killsp;
|
killtp = killsp;
|
||||||
killtp --;
|
killtp--;
|
||||||
if (killstack[killtp] == 0) {
|
if (killstack[killtp] == 0) {
|
||||||
x_e_puts("\nnothing to yank");
|
x_e_puts("\nnothing to yank");
|
||||||
x_redraw(-1);
|
x_redraw(-1);
|
||||||
@ -2277,7 +2267,7 @@ x_print(int prefix, int key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
x_bind( const char *a1, const char *a2,
|
x_bind(const char *a1, const char *a2,
|
||||||
int macro, /* bind -m */
|
int macro, /* bind -m */
|
||||||
int list) /* bind -l */
|
int list) /* bind -l */
|
||||||
{
|
{
|
||||||
@ -2290,7 +2280,6 @@ x_bind( const char *a1, const char *a2,
|
|||||||
bi_errorf("cannot bind, not a tty");
|
bi_errorf("cannot bind, not a tty");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* List function names */
|
/* List function names */
|
||||||
if (list) {
|
if (list) {
|
||||||
for (f = 0; f < NELEM(x_ftab); f++)
|
for (f = 0; f < NELEM(x_ftab); f++)
|
||||||
@ -2299,7 +2288,6 @@ x_bind( const char *a1, const char *a2,
|
|||||||
shprintf("%s\n", x_ftab[f].xf_name);
|
shprintf("%s\n", x_ftab[f].xf_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a1 == NULL) {
|
if (a1 == NULL) {
|
||||||
for (prefix = 0; prefix < X_NTABS; prefix++)
|
for (prefix = 0; prefix < X_NTABS; prefix++)
|
||||||
for (key = 0; key < X_TABSZ; key++) {
|
for (key = 0; key < X_TABSZ; key++) {
|
||||||
@ -2311,7 +2299,6 @@ x_bind( const char *a1, const char *a2,
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m1 = x_mapin(a1);
|
m1 = x_mapin(a1);
|
||||||
prefix = key = 0;
|
prefix = key = 0;
|
||||||
for (;; m1++) {
|
for (;; m1++) {
|
||||||
@ -2328,7 +2315,6 @@ x_bind( const char *a1, const char *a2,
|
|||||||
x_print(prefix, key);
|
x_print(prefix, key);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*a2 == 0)
|
if (*a2 == 0)
|
||||||
f = XFUNC_insert;
|
f = XFUNC_insert;
|
||||||
else if (!macro) {
|
else if (!macro) {
|
||||||
@ -2370,7 +2356,7 @@ x_init_emacs(void)
|
|||||||
ainit(AEDIT);
|
ainit(AEDIT);
|
||||||
x_nextcmd = -1;
|
x_nextcmd = -1;
|
||||||
|
|
||||||
x_tab = (u_char (*)[X_TABSZ]) alloc(sizeofN(*x_tab, X_NTABS), AEDIT);
|
x_tab = (u_char (*)[X_TABSZ])alloc(sizeofN(*x_tab, X_NTABS), AEDIT);
|
||||||
for (j = 0; j < X_TABSZ; j++)
|
for (j = 0; j < X_TABSZ; j++)
|
||||||
x_tab[0][j] = XFUNC_insert;
|
x_tab[0][j] = XFUNC_insert;
|
||||||
for (i = 1; i < X_NTABS; i++)
|
for (i = 1; i < X_NTABS; i++)
|
||||||
@ -2380,7 +2366,7 @@ x_init_emacs(void)
|
|||||||
x_tab[(unsigned char)x_defbindings[i].xdb_tab][x_defbindings[i].xdb_char]
|
x_tab[(unsigned char)x_defbindings[i].xdb_tab][x_defbindings[i].xdb_char]
|
||||||
= x_defbindings[i].xdb_func;
|
= x_defbindings[i].xdb_func;
|
||||||
|
|
||||||
x_atab = (char *(*)[X_TABSZ]) alloc(sizeofN(*x_atab, X_NTABS), AEDIT);
|
x_atab = (char *(*)[X_TABSZ])alloc(sizeofN(*x_atab, X_NTABS), AEDIT);
|
||||||
for (i = 1; i < X_NTABS; i++)
|
for (i = 1; i < X_NTABS; i++)
|
||||||
for (j = 0; j < X_TABSZ; j++)
|
for (j = 0; j < X_TABSZ; j++)
|
||||||
x_atab[i][j] = NULL;
|
x_atab[i][j] = NULL;
|
||||||
@ -2459,7 +2445,7 @@ x_xchg_point_mark(int c __attribute__((unused)))
|
|||||||
}
|
}
|
||||||
tmp = xmp;
|
tmp = xmp;
|
||||||
xmp = xcp;
|
xmp = xcp;
|
||||||
x_goto( tmp );
|
x_goto(tmp);
|
||||||
return KSTD;
|
return KSTD;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2569,7 +2555,6 @@ x_expand(int c __attribute__((unused)))
|
|||||||
x_e_putc(BEL);
|
x_e_putc(BEL);
|
||||||
return KSTD;
|
return KSTD;
|
||||||
}
|
}
|
||||||
|
|
||||||
x_goto(xbuf + start);
|
x_goto(xbuf + start);
|
||||||
x_delete(end - start, false);
|
x_delete(end - start, false);
|
||||||
for (i = 0; i < nwords;) {
|
for (i = 0; i < nwords;) {
|
||||||
@ -2602,14 +2587,12 @@ do_complete(int flags, /* XCF_{COMMAND,FILE,COMMAND_FILE} */
|
|||||||
x_e_putc(BEL);
|
x_e_putc(BEL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == CT_LIST) {
|
if (type == CT_LIST) {
|
||||||
x_print_expansions(nwords, words, is_command);
|
x_print_expansions(nwords, words, is_command);
|
||||||
x_redraw(0);
|
x_redraw(0);
|
||||||
x_free_words(nwords, words);
|
x_free_words(nwords, words);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
olen = end - start;
|
olen = end - start;
|
||||||
nlen = x_longest_prefix(nwords, words);
|
nlen = x_longest_prefix(nwords, words);
|
||||||
/* complete */
|
/* complete */
|
||||||
@ -2625,12 +2608,10 @@ do_complete(int flags, /* XCF_{COMMAND,FILE,COMMAND_FILE} */
|
|||||||
x_ins(space);
|
x_ins(space);
|
||||||
completed = 1;
|
completed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == CT_COMPLIST && !completed) {
|
if (type == CT_COMPLIST && !completed) {
|
||||||
x_print_expansions(nwords, words, is_command);
|
x_print_expansions(nwords, words, is_command);
|
||||||
completed = 1;
|
completed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completed)
|
if (completed)
|
||||||
x_redraw(0);
|
x_redraw(0);
|
||||||
|
|
||||||
@ -3127,7 +3108,9 @@ struct macro_state {
|
|||||||
};
|
};
|
||||||
static struct macro_state macro;
|
static struct macro_state macro;
|
||||||
|
|
||||||
enum expand_mode { NONE, EXPAND, COMPLETE, PRINT };
|
enum expand_mode {
|
||||||
|
NONE, EXPAND, COMPLETE, PRINT
|
||||||
|
};
|
||||||
static enum expand_mode expanded = NONE; /* last input was expanded */
|
static enum expand_mode expanded = NONE; /* last input was expanded */
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -3177,7 +3160,9 @@ x_vi(char *buf, size_t len)
|
|||||||
x_flush();
|
x_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
x_putc('\r'); x_putc('\n'); x_flush();
|
x_putc('\r');
|
||||||
|
x_putc('\n');
|
||||||
|
x_flush();
|
||||||
|
|
||||||
if (c == -1 || (ssize_t)len <= es->linelen)
|
if (c == -1 || (ssize_t)len <= es->linelen)
|
||||||
return -1;
|
return -1;
|
||||||
@ -3335,7 +3320,7 @@ vi_hook(int ch)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
locpat[srchlen] = '\0';
|
locpat[srchlen] = '\0';
|
||||||
(void) strlcpy(srchpat, locpat, sizeof srchpat);
|
(void)strlcpy(srchpat, locpat, sizeof srchpat);
|
||||||
}
|
}
|
||||||
state = VCMD;
|
state = VCMD;
|
||||||
} else if (ch == edchars.erase || ch == Ctrl('h')) {
|
} else if (ch == edchars.erase || ch == Ctrl('h')) {
|
||||||
@ -3520,7 +3505,7 @@ vi_insert(int ch)
|
|||||||
inslen--;
|
inslen--;
|
||||||
es->cursor--;
|
es->cursor--;
|
||||||
es->linelen--;
|
es->linelen--;
|
||||||
memmove(&es->cbuf[es->cursor], &es->cbuf[es->cursor+1],
|
memmove(&es->cbuf[es->cursor], &es->cbuf[es->cursor + 1],
|
||||||
es->linelen - es->cursor + 1);
|
es->linelen - es->cursor + 1);
|
||||||
}
|
}
|
||||||
expanded = NONE;
|
expanded = NONE;
|
||||||
@ -3609,7 +3594,7 @@ vi_insert(int ch)
|
|||||||
return -1;
|
return -1;
|
||||||
ibuf[inslen++] = ch;
|
ibuf[inslen++] = ch;
|
||||||
if (insert == INSERT) {
|
if (insert == INSERT) {
|
||||||
memmove(&es->cbuf[es->cursor+1], &es->cbuf[es->cursor],
|
memmove(&es->cbuf[es->cursor + 1], &es->cbuf[es->cursor],
|
||||||
es->linelen - es->cursor);
|
es->linelen - es->cursor);
|
||||||
es->linelen++;
|
es->linelen++;
|
||||||
}
|
}
|
||||||
@ -3669,7 +3654,7 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
if (!cmd[1] || !ap || !(ap->flag & ISSET))
|
if (!cmd[1] || !ap || !(ap->flag & ISSET))
|
||||||
return -1;
|
return -1;
|
||||||
/* check if this is a recursive call... */
|
/* check if this is a recursive call... */
|
||||||
if ((p = (char *) macro.p))
|
if ((p = (char *)macro.p))
|
||||||
while ((p = strchr(p, '\0')) && p[1])
|
while ((p = strchr(p, '\0')) && p[1])
|
||||||
if (*++p == cmd[1])
|
if (*++p == cmd[1])
|
||||||
return -1;
|
return -1;
|
||||||
@ -3688,20 +3673,22 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
nbuf[nlen++] = '\0';
|
nbuf[nlen++] = '\0';
|
||||||
nbuf[nlen++] = '\0';
|
nbuf[nlen++] = '\0';
|
||||||
}
|
}
|
||||||
macro.p = macro.buf = (unsigned char *) nbuf;
|
macro.p = macro.buf = (unsigned char *)nbuf;
|
||||||
macro.len = nlen;
|
macro.len = nlen;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
if (es->linelen != 0)
|
if (es->linelen != 0)
|
||||||
es->cursor++;
|
es->cursor++;
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'A':
|
case 'A':
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
del_range(0, 0);
|
del_range(0, 0);
|
||||||
es->cursor = es->linelen;
|
es->cursor = es->linelen;
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
@ -3710,7 +3697,8 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
case 'S':
|
case 'S':
|
||||||
es->cursor = domove(1, "^", 1);
|
es->cursor = domove(1, "^", 1);
|
||||||
del_range(es->cursor, es->linelen);
|
del_range(es->cursor, es->linelen);
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3729,7 +3717,7 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
if ((ncursor = domove(argcnt, &cmd[1], 1)) < 0)
|
if ((ncursor = domove(argcnt, &cmd[1], 1)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (*cmd == 'c' &&
|
if (*cmd == 'c' &&
|
||||||
(cmd[1]=='w' || cmd[1]=='W') &&
|
(cmd[1] == 'w' || cmd[1] == 'W') &&
|
||||||
!isspace(es->cbuf[es->cursor])) {
|
!isspace(es->cbuf[es->cursor])) {
|
||||||
while (isspace(es->cbuf[--ncursor]))
|
while (isspace(es->cbuf[--ncursor]))
|
||||||
;
|
;
|
||||||
@ -3752,13 +3740,15 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
es->cursor = c1;
|
es->cursor = c1;
|
||||||
}
|
}
|
||||||
if (*cmd == 'c') {
|
if (*cmd == 'c') {
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
if (es->linelen != 0)
|
if (es->linelen != 0)
|
||||||
es->cursor++;
|
es->cursor++;
|
||||||
while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0)
|
while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0)
|
||||||
@ -3770,7 +3760,8 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'P':
|
case 'P':
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
any = 0;
|
any = 0;
|
||||||
while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0)
|
while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0)
|
||||||
any = 1;
|
any = 1;
|
||||||
@ -3781,7 +3772,8 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
del_range(es->cursor, es->linelen);
|
del_range(es->cursor, es->linelen);
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
break;
|
break;
|
||||||
@ -3811,12 +3803,14 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
es->cursor = domove(1, "^", 1);
|
es->cursor = domove(1, "^", 1);
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
break;
|
break;
|
||||||
@ -3846,7 +3840,8 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
case 'r':
|
case 'r':
|
||||||
if (es->linelen == 0)
|
if (es->linelen == 0)
|
||||||
return -1;
|
return -1;
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
if (cmd[1] == 0)
|
if (cmd[1] == 0)
|
||||||
vi_error();
|
vi_error();
|
||||||
else {
|
else {
|
||||||
@ -3861,14 +3856,16 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'R':
|
case 'R':
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
insert = REPLACE;
|
insert = REPLACE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
if (es->linelen == 0)
|
if (es->linelen == 0)
|
||||||
return -1;
|
return -1;
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
if (es->cursor + argcnt > es->linelen)
|
if (es->cursor + argcnt > es->linelen)
|
||||||
argcnt = es->linelen - es->cursor;
|
argcnt = es->linelen - es->cursor;
|
||||||
del_range(es->cursor, es->cursor + argcnt);
|
del_range(es->cursor, es->cursor + argcnt);
|
||||||
@ -3897,7 +3894,8 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
case 'x':
|
case 'x':
|
||||||
if (es->linelen == 0)
|
if (es->linelen == 0)
|
||||||
return -1;
|
return -1;
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
if (es->cursor + argcnt > es->linelen)
|
if (es->cursor + argcnt > es->linelen)
|
||||||
argcnt = es->linelen - es->cursor;
|
argcnt = es->linelen - es->cursor;
|
||||||
yank_range(es->cursor, es->cursor + argcnt);
|
yank_range(es->cursor, es->cursor + argcnt);
|
||||||
@ -3906,7 +3904,8 @@ vi_cmd(int argcnt, const char *cmd)
|
|||||||
|
|
||||||
case 'X':
|
case 'X':
|
||||||
if (es->cursor > 0) {
|
if (es->cursor > 0) {
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
if (es->cursor < argcnt)
|
if (es->cursor < argcnt)
|
||||||
argcnt = es->cursor;
|
argcnt = es->cursor;
|
||||||
yank_range(es->cursor - argcnt, es->cursor);
|
yank_range(es->cursor - argcnt, es->cursor);
|
||||||
@ -4234,7 +4233,7 @@ static int
|
|||||||
redo_insert(int count)
|
redo_insert(int count)
|
||||||
{
|
{
|
||||||
while (count-- > 0)
|
while (count-- > 0)
|
||||||
if (putbuf(ibuf, inslen, insert==REPLACE) != 0)
|
if (putbuf(ibuf, inslen, insert == REPLACE) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (es->cursor > 0)
|
if (es->cursor > 0)
|
||||||
es->cursor--;
|
es->cursor--;
|
||||||
@ -4361,8 +4360,8 @@ edit_reset(char *buf, size_t len)
|
|||||||
wbuf[0] = aresize(wbuf[0], wbuf_len, APERM);
|
wbuf[0] = aresize(wbuf[0], wbuf_len, APERM);
|
||||||
wbuf[1] = aresize(wbuf[1], wbuf_len, APERM);
|
wbuf[1] = aresize(wbuf[1], wbuf_len, APERM);
|
||||||
}
|
}
|
||||||
(void) memset(wbuf[0], ' ', wbuf_len);
|
(void)memset(wbuf[0], ' ', wbuf_len);
|
||||||
(void) memset(wbuf[1], ' ', wbuf_len);
|
(void)memset(wbuf[1], ' ', wbuf_len);
|
||||||
winwidth = x_cols - pwidth - 3;
|
winwidth = x_cols - pwidth - 3;
|
||||||
win = 0;
|
win = 0;
|
||||||
morec = ' ';
|
morec = ' ';
|
||||||
@ -4573,7 +4572,7 @@ grabhist(int save, int n)
|
|||||||
ohnum = n;
|
ohnum = n;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(void) histnum(n);
|
(void)histnum(n);
|
||||||
if ((hptr = *histpos()) == NULL) {
|
if ((hptr = *histpos()) == NULL) {
|
||||||
internal_errorf(0, "grabhist: bad history array");
|
internal_errorf(0, "grabhist: bad history array");
|
||||||
return -1;
|
return -1;
|
||||||
@ -4595,7 +4594,7 @@ grabsearch(int save, int start, int fwd, char *pat)
|
|||||||
int hist;
|
int hist;
|
||||||
int anchored;
|
int anchored;
|
||||||
|
|
||||||
if ((start == 0 && fwd == 0) || (start >= hlast-1 && fwd == 1))
|
if ((start == 0 && fwd == 0) || (start >= hlast - 1 && fwd == 1))
|
||||||
return -1;
|
return -1;
|
||||||
if (fwd)
|
if (fwd)
|
||||||
start++;
|
start++;
|
||||||
@ -4625,7 +4624,7 @@ grabsearch(int save, int start, int fwd, char *pat)
|
|||||||
static void
|
static void
|
||||||
redraw_line(int newl)
|
redraw_line(int newl)
|
||||||
{
|
{
|
||||||
(void) memset(wbuf[win], ' ', wbuf_len);
|
(void)memset(wbuf[win], ' ', wbuf_len);
|
||||||
if (newl) {
|
if (newl) {
|
||||||
x_putc('\r');
|
x_putc('\r');
|
||||||
x_putc('\n');
|
x_putc('\n');
|
||||||
@ -4658,7 +4657,7 @@ outofwin(void)
|
|||||||
col = 0;
|
col = 0;
|
||||||
cur = es->winleft;
|
cur = es->winleft;
|
||||||
while (cur < es->cursor)
|
while (cur < es->cursor)
|
||||||
col = newcol((unsigned char) es->cbuf[cur++], col);
|
col = newcol((unsigned char)es->cbuf[cur++], col);
|
||||||
if (col >= winwidth)
|
if (col >= winwidth)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
@ -4680,10 +4679,10 @@ rewindow(void)
|
|||||||
holdcur2 = tcur;
|
holdcur2 = tcur;
|
||||||
holdcol2 = tcol;
|
holdcol2 = tcol;
|
||||||
}
|
}
|
||||||
tcol = newcol((unsigned char) es->cbuf[tcur++], tcol);
|
tcol = newcol((unsigned char)es->cbuf[tcur++], tcol);
|
||||||
}
|
}
|
||||||
while (tcol - holdcol1 > winwidth / 2)
|
while (tcol - holdcol1 > winwidth / 2)
|
||||||
holdcol1 = newcol((unsigned char) es->cbuf[holdcur1++],
|
holdcol1 = newcol((unsigned char)es->cbuf[holdcur1++],
|
||||||
holdcol1);
|
holdcol1);
|
||||||
es->winleft = holdcur1;
|
es->winleft = holdcur1;
|
||||||
}
|
}
|
||||||
@ -4860,7 +4859,8 @@ expand_word(int cmd)
|
|||||||
i = buf->cursor - end;
|
i = buf->cursor - end;
|
||||||
if (rval == 0 && i > 0)
|
if (rval == 0 && i > 0)
|
||||||
es->cursor += i;
|
es->cursor += i;
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
lastac = 0;
|
lastac = 0;
|
||||||
refresh(0);
|
refresh(0);
|
||||||
@ -4964,7 +4964,8 @@ complete_word(int cmd, int count)
|
|||||||
}
|
}
|
||||||
x_free_words(nwords, words);
|
x_free_words(nwords, words);
|
||||||
|
|
||||||
modified = 1; hnum = hlast;
|
modified = 1;
|
||||||
|
hnum = hlast;
|
||||||
insert = INSERT;
|
insert = INSERT;
|
||||||
lastac = 0; /* prevent this from being redone... */
|
lastac = 0; /* prevent this from being redone... */
|
||||||
refresh(0);
|
refresh(0);
|
||||||
@ -4980,7 +4981,7 @@ print_expansions(struct edstate *est, int cmd __attribute__((unused)))
|
|||||||
char **words;
|
char **words;
|
||||||
int is_command;
|
int is_command;
|
||||||
|
|
||||||
nwords = x_cf_glob(XCF_COMMAND_FILE|XCF_FULLPATH,
|
nwords = x_cf_glob(XCF_COMMAND_FILE | XCF_FULLPATH,
|
||||||
est->cbuf, est->linelen, est->cursor,
|
est->cbuf, est->linelen, est->cursor,
|
||||||
&start, &end, &words, &is_command);
|
&start, &end, &words, &is_command);
|
||||||
if (nwords == 0) {
|
if (nwords == 0) {
|
||||||
@ -5043,6 +5044,6 @@ vi_macro_reset(void)
|
|||||||
{
|
{
|
||||||
if (macro.p) {
|
if (macro.p) {
|
||||||
afree(macro.buf, APERM);
|
afree(macro.buf, APERM);
|
||||||
memset((char *) ¯o, 0, sizeof(macro));
|
memset((char *)¯o, 0, sizeof(macro));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
main.c
73
main.c
@ -1,4 +1,4 @@
|
|||||||
/** $MirOS: src/bin/mksh/main.c,v 1.11 2005/06/08 21:51:21 tg Exp $ */
|
/** $MirOS: src/bin/mksh/main.c,v 1.12 2005/06/08 22:22:24 tg Exp $ */
|
||||||
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
|
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
|
||||||
@ -13,21 +13,21 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.11 2005/06/08 21:51:21 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.12 2005/06/08 22:22:24 tg Exp $");
|
||||||
|
|
||||||
const char ksh_version[] = "@(#)MIRBSD KSH R23 2005/06/08";
|
const char ksh_version[] = "@(#)MIRBSD KSH R23 2005/06/08";
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
static void reclaim(void);
|
static void reclaim(void);
|
||||||
static void remove_temps(struct temp *tp);
|
static void remove_temps(struct temp * tp);
|
||||||
static int is_restricted(char *name);
|
static int is_restricted(char *name);
|
||||||
|
|
||||||
static const char initifs[] = "IFS= \t\n";
|
static const char initifs[] = "IFS= \t\n";
|
||||||
|
|
||||||
static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }";
|
static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }";
|
||||||
|
|
||||||
static const char *initcoms [] = {
|
static const char *initcoms[] = {
|
||||||
"typeset", "-r", "KSH_VERSION", NULL,
|
"typeset", "-r", "KSH_VERSION", NULL,
|
||||||
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
|
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
|
||||||
"typeset", "-i", "PGRP=0", "PPID", NULL,
|
"typeset", "-i", "PGRP=0", "PPID", NULL,
|
||||||
@ -76,7 +76,7 @@ main(int argc, char *argv[])
|
|||||||
"mksh", NULL
|
"mksh", NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
argv = (char **) empty_argv;
|
argv = (char **)empty_argv;
|
||||||
argc = 1;
|
argc = 1;
|
||||||
}
|
}
|
||||||
kshname = *argv;
|
kshname = *argv;
|
||||||
@ -171,7 +171,7 @@ main(int argc, char *argv[])
|
|||||||
/* import environment */
|
/* import environment */
|
||||||
if (environ != NULL)
|
if (environ != NULL)
|
||||||
for (wp = environ; *wp != NULL; wp++)
|
for (wp = environ; *wp != NULL; wp++)
|
||||||
typeset(*wp, IMPORT|EXPORT, 0, 0, 0);
|
typeset(*wp, IMPORT | EXPORT, 0, 0, 0);
|
||||||
|
|
||||||
kshpid = procpid = getpid();
|
kshpid = procpid = getpid();
|
||||||
typeset(initifs, 0, 0, 0, 0); /* for security */
|
typeset(initifs, 0, 0, 0, 0); /* for security */
|
||||||
@ -206,13 +206,13 @@ main(int argc, char *argv[])
|
|||||||
#if !HAVE_ARC4RANDOM
|
#if !HAVE_ARC4RANDOM
|
||||||
srand((*((long *)kshname)) ^ ((long)time(NULL) * kshpid * ppid));
|
srand((*((long *)kshname)) ^ ((long)time(NULL) * kshpid * ppid));
|
||||||
#endif
|
#endif
|
||||||
setint(global("PPID"), (long) ppid);
|
setint(global("PPID"), (long)ppid);
|
||||||
/* setstr can't fail here */
|
/* setstr can't fail here */
|
||||||
if (!Flag(FSH))
|
if (!Flag(FSH))
|
||||||
setstr(global("KSH_VERSION"), ksh_version, KSH_RETURN_ERROR);
|
setstr(global("KSH_VERSION"), ksh_version, KSH_RETURN_ERROR);
|
||||||
|
|
||||||
/* execute initialisation statements */
|
/* execute initialisation statements */
|
||||||
for (wp = (char**) initcoms; *wp != NULL; wp++) {
|
for (wp = (char **)initcoms; *wp != NULL; wp++) {
|
||||||
shcomexec(wp);
|
shcomexec(wp);
|
||||||
for (; *wp != NULL; wp++)
|
for (; *wp != NULL; wp++)
|
||||||
;
|
;
|
||||||
@ -254,7 +254,8 @@ main(int argc, char *argv[])
|
|||||||
} else if (argi < argc && !Flag(FSTDIN)) {
|
} else if (argi < argc && !Flag(FSTDIN)) {
|
||||||
s = pushs(SFILE, ATEMP);
|
s = pushs(SFILE, ATEMP);
|
||||||
s->file = kshname = argv[argi++];
|
s->file = kshname = argv[argi++];
|
||||||
s->u.shf = shf_open(s->file, O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC);
|
s->u.shf = shf_open(s->file, O_RDONLY, 0,
|
||||||
|
SHF_MAPHI | SHF_CLEXEC);
|
||||||
if (s->u.shf == NULL) {
|
if (s->u.shf == NULL) {
|
||||||
exstat = 127; /* POSIX */
|
exstat = 127; /* POSIX */
|
||||||
errorf("%s: %s", s->file, strerror(errno));
|
errorf("%s: %s", s->file, strerror(errno));
|
||||||
@ -294,7 +295,7 @@ main(int argc, char *argv[])
|
|||||||
l = e->loc;
|
l = e->loc;
|
||||||
l->argv = &argv[argi - 1];
|
l->argv = &argv[argi - 1];
|
||||||
l->argc = argc - argi;
|
l->argc = argc - argi;
|
||||||
l->argv[0] = (char *) kshname;
|
l->argv[0] = (char *)kshname;
|
||||||
getopts_reset(1);
|
getopts_reset(1);
|
||||||
|
|
||||||
/* Disable during .profile/ENV reading */
|
/* Disable during .profile/ENV reading */
|
||||||
@ -315,7 +316,6 @@ main(int argc, char *argv[])
|
|||||||
include(substitute("$HOME/.profile", 0), 0,
|
include(substitute("$HOME/.profile", 0), 0,
|
||||||
NULL, 1);
|
NULL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Flag(FPRIVILEGED))
|
if (Flag(FPRIVILEGED))
|
||||||
include("/etc/suid_profile", 0, NULL, 1);
|
include("/etc/suid_profile", 0, NULL, 1);
|
||||||
else {
|
else {
|
||||||
@ -335,7 +335,7 @@ main(int argc, char *argv[])
|
|||||||
"ENV", "SHELL",
|
"ENV", "SHELL",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
shcomexec((char **) restr_com);
|
shcomexec((char **)restr_com);
|
||||||
/* After typeset command... */
|
/* After typeset command... */
|
||||||
Flag(FRESTRICTED) = 1;
|
Flag(FRESTRICTED) = 1;
|
||||||
}
|
}
|
||||||
@ -361,7 +361,7 @@ include(const char *name, int argc, char **argv, int intr_ok)
|
|||||||
volatile int old_argc;
|
volatile int old_argc;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
shf = shf_open(name, O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC);
|
shf = shf_open(name, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
|
||||||
if (shf == NULL)
|
if (shf == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -431,7 +431,7 @@ command(const char *comm)
|
|||||||
* run the commands from the input source, returning status.
|
* run the commands from the input source, returning status.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
shell(Source *volatile s, volatile int toplevel)
|
shell(Source * volatile s, volatile int toplevel)
|
||||||
{
|
{
|
||||||
struct op *t;
|
struct op *t;
|
||||||
volatile int wastty = s->flags & SF_TTY;
|
volatile int wastty = s->flags & SF_TTY;
|
||||||
@ -483,7 +483,6 @@ shell(Source *volatile s, volatile int toplevel)
|
|||||||
/*NOREACHED*/
|
/*NOREACHED*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (trap)
|
if (trap)
|
||||||
runtraps(0);
|
runtraps(0);
|
||||||
@ -494,12 +493,10 @@ shell(Source *volatile s, volatile int toplevel)
|
|||||||
else
|
else
|
||||||
s->flags &= ~SF_ECHO;
|
s->flags &= ~SF_ECHO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
j_notify();
|
j_notify();
|
||||||
set_prompt(PS1, s);
|
set_prompt(PS1, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
t = compile(s);
|
t = compile(s);
|
||||||
if (t != NULL && t->type == TEOF) {
|
if (t != NULL && t->type == TEOF) {
|
||||||
if (wastty && Flag(FIGNOREEOF) && --attempts > 0) {
|
if (wastty && Flag(FIGNOREEOF) && --attempts > 0) {
|
||||||
@ -520,7 +517,6 @@ shell(Source *volatile s, volatile int toplevel)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t && (!Flag(FNOEXEC) || (s->flags & SF_TTY)))
|
if (t && (!Flag(FNOEXEC) || (s->flags & SF_TTY)))
|
||||||
exstat = execute(t, 0);
|
exstat = execute(t, 0);
|
||||||
|
|
||||||
@ -600,7 +596,6 @@ quitenv(struct shf *shf)
|
|||||||
if (ep->savefd[2]) /* Clear any write errors */
|
if (ep->savefd[2]) /* Clear any write errors */
|
||||||
shf_reopen(2, SHF_WR, shl_out);
|
shf_reopen(2, SHF_WR, shl_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bottom of the stack.
|
/* Bottom of the stack.
|
||||||
* Either main shell is exiting or cleanup_parents_env() was called.
|
* Either main shell is exiting or cleanup_parents_env() was called.
|
||||||
*/
|
*/
|
||||||
@ -620,7 +615,7 @@ quitenv(struct shf *shf)
|
|||||||
if ((sig == SIGINT || sig == SIGTERM) &&
|
if ((sig == SIGINT || sig == SIGTERM) &&
|
||||||
getpgrp() == kshpid) {
|
getpgrp() == kshpid) {
|
||||||
setsig(&sigtraps[sig], SIG_DFL,
|
setsig(&sigtraps[sig], SIG_DFL,
|
||||||
SS_RESTORE_CURR|SS_FORCE);
|
SS_RESTORE_CURR | SS_FORCE);
|
||||||
kill(0, sig);
|
kill(0, sig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -736,7 +731,6 @@ tty_init(int init_ttystate)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tfd < 0) {
|
if (tfd < 0) {
|
||||||
do_close = 0;
|
do_close = 0;
|
||||||
if (isatty(0))
|
if (isatty(0))
|
||||||
@ -1113,7 +1107,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist)
|
|||||||
dir = tmpdir ? tmpdir : "/tmp";
|
dir = tmpdir ? tmpdir : "/tmp";
|
||||||
len = strlen(dir) + 6 + 10 + 1;
|
len = strlen(dir) + 6 + 10 + 1;
|
||||||
tp = (struct temp *) alloc(sizeof(struct temp) + len, ap);
|
tp = (struct temp *) alloc(sizeof(struct temp) + len, ap);
|
||||||
tp->name = pathname = (char *) &tp[1];
|
tp->name = pathname = (char *)&tp[1];
|
||||||
tp->shf = NULL;
|
tp->shf = NULL;
|
||||||
tp->type = type;
|
tp->type = type;
|
||||||
shf_snprintf(pathname, len, "%s/mksh.XXXXXXXXXX", dir);
|
shf_snprintf(pathname, len, "%s/mksh.XXXXXXXXXX", dir);
|
||||||
@ -1159,28 +1153,28 @@ texpand(struct table *tp, int nsize)
|
|||||||
struct tbl **ntblp, **otblp = tp->tbls;
|
struct tbl **ntblp, **otblp = tp->tbls;
|
||||||
int osize = tp->size;
|
int osize = tp->size;
|
||||||
|
|
||||||
ntblp = (struct tbl**) alloc(sizeofN(struct tbl *, nsize), tp->areap);
|
ntblp = (struct tbl **)alloc(sizeofN(struct tbl *, nsize), tp->areap);
|
||||||
for (i = 0; i < nsize; i++)
|
for (i = 0; i < nsize; i++)
|
||||||
ntblp[i] = NULL;
|
ntblp[i] = NULL;
|
||||||
tp->size = nsize;
|
tp->size = nsize;
|
||||||
tp->nfree = 8*nsize/10; /* table can get 80% full */
|
tp->nfree = 8 * nsize / 10; /* table can get 80% full */
|
||||||
tp->tbls = ntblp;
|
tp->tbls = ntblp;
|
||||||
if (otblp == NULL)
|
if (otblp == NULL)
|
||||||
return;
|
return;
|
||||||
for (i = 0; i < osize; i++)
|
for (i = 0; i < osize; i++)
|
||||||
if ((tblp = otblp[i]) != NULL) {
|
if ((tblp = otblp[i]) != NULL) {
|
||||||
if ((tblp->flag&DEFINED)) {
|
if ((tblp->flag & DEFINED)) {
|
||||||
for (p = &ntblp[hash(tblp->name) &
|
for (p = &ntblp[hash(tblp->name) &
|
||||||
(tp->size-1)]; *p != NULL; p--)
|
(tp->size - 1)]; *p != NULL; p--)
|
||||||
if (p == ntblp) /* wrap */
|
if (p == ntblp) /* wrap */
|
||||||
p += tp->size;
|
p += tp->size;
|
||||||
*p = tblp;
|
*p = tblp;
|
||||||
tp->nfree--;
|
tp->nfree--;
|
||||||
} else if (!(tblp->flag & FINUSE)) {
|
} else if (!(tblp->flag & FINUSE)) {
|
||||||
afree((void*)tblp, tp->areap);
|
afree((void *)tblp, tp->areap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
afree((void*)otblp, tp->areap);
|
afree((void *)otblp, tp->areap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* table */
|
/* table */
|
||||||
@ -1195,9 +1189,9 @@ tsearch(struct table *tp, const char *n, unsigned int h)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* search for name in hashed table */
|
/* search for name in hashed table */
|
||||||
for (pp = &tp->tbls[h & (tp->size-1)]; (p = *pp) != NULL; pp--) {
|
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
||||||
if (*p->name == *n && strcmp(p->name, n) == 0 &&
|
if (*p->name == *n && strcmp(p->name, n) == 0 &&
|
||||||
(p->flag&DEFINED))
|
(p->flag & DEFINED))
|
||||||
return p;
|
return p;
|
||||||
if (pp == tp->tbls) /* wrap */
|
if (pp == tp->tbls) /* wrap */
|
||||||
pp += tp->size;
|
pp += tp->size;
|
||||||
@ -1217,9 +1211,9 @@ tenter(struct table *tp, const char *n, unsigned int h)
|
|||||||
|
|
||||||
if (tp->size == 0)
|
if (tp->size == 0)
|
||||||
texpand(tp, INIT_TBLS);
|
texpand(tp, INIT_TBLS);
|
||||||
Search:
|
Search:
|
||||||
/* search for name in hashed table */
|
/* search for name in hashed table */
|
||||||
for (pp = &tp->tbls[h & (tp->size-1)]; (p = *pp) != NULL; pp--) {
|
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
||||||
if (*p->name == *n && strcmp(p->name, n) == 0)
|
if (*p->name == *n && strcmp(p->name, n) == 0)
|
||||||
return p; /* found */
|
return p; /* found */
|
||||||
if (pp == tp->tbls) /* wrap */
|
if (pp == tp->tbls) /* wrap */
|
||||||
@ -1227,13 +1221,12 @@ tenter(struct table *tp, const char *n, unsigned int h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tp->nfree <= 0) { /* too full */
|
if (tp->nfree <= 0) { /* too full */
|
||||||
texpand(tp, 2*tp->size);
|
texpand(tp, 2 * tp->size);
|
||||||
goto Search;
|
goto Search;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create new tbl entry */
|
/* create new tbl entry */
|
||||||
len = strlen(n) + 1;
|
len = strlen(n) + 1;
|
||||||
p = (struct tbl *) alloc(offsetof(struct tbl, name[0]) + len,
|
p = (struct tbl *)alloc(offsetof(struct tbl, name[0])+len,
|
||||||
tp->areap);
|
tp->areap);
|
||||||
p->flag = 0;
|
p->flag = 0;
|
||||||
p->type = 0;
|
p->type = 0;
|
||||||
@ -1266,7 +1259,7 @@ tnext(struct tstate *ts)
|
|||||||
{
|
{
|
||||||
while (--ts->left >= 0) {
|
while (--ts->left >= 0) {
|
||||||
struct tbl *p = *ts->next++;
|
struct tbl *p = *ts->next++;
|
||||||
if (p != NULL && (p->flag&DEFINED))
|
if (p != NULL && (p->flag & DEFINED))
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1284,15 +1277,15 @@ tsort(struct table *tp)
|
|||||||
int i;
|
int i;
|
||||||
struct tbl **p, **sp, **dp;
|
struct tbl **p, **sp, **dp;
|
||||||
|
|
||||||
p = (struct tbl **)alloc(sizeofN(struct tbl *, tp->size+1), ATEMP);
|
p = (struct tbl **)alloc(sizeofN(struct tbl *, tp->size + 1), ATEMP);
|
||||||
sp = tp->tbls; /* source */
|
sp = tp->tbls; /* source */
|
||||||
dp = p; /* dest */
|
dp = p; /* dest */
|
||||||
for (i = 0; i < tp->size; i++)
|
for (i = 0; i < tp->size; i++)
|
||||||
if ((*dp = *sp++) != NULL && (((*dp)->flag&DEFINED) ||
|
if ((*dp = *sp++) != NULL && (((*dp)->flag & DEFINED) ||
|
||||||
((*dp)->flag&ARRAY)))
|
((*dp)->flag & ARRAY)))
|
||||||
dp++;
|
dp++;
|
||||||
i = dp - p;
|
i = dp - p;
|
||||||
qsortp((void**)p, (size_t)i, tnamecmp);
|
qsortp((void **)p, (size_t)i, tnamecmp);
|
||||||
p[i] = NULL;
|
p[i] = NULL;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user