*/
static const char vi_Version[] =
- "$Id: vi.c,v 1.26 2002/12/02 21:18:08 bug1 Exp $";
+ "$Id: vi.c,v 1.32 2004/02/04 11:19:44 andersen Exp $";
/*
* To compile for standalone use:
#if defined(CONFIG_FEATURE_VI_USE_SIGNALS) || defined(CONFIG_FEATURE_VI_CRASHME)
static int my_pid;
#endif
-#ifdef CONFIG_FEATURE_VI_WIN_RESIZE
-static struct winsize winsize; // remember the window size
-#endif /* CONFIG_FEATURE_VI_WIN_RESIZE */
#ifdef CONFIG_FEATURE_VI_DOT_CMD
static int adding2q; // are we currently adding user input to q
static Byte *last_modifying_cmd; // last modifying cmd for "."
for (; optind < argc; optind++) {
editing = 1; // 0=exit, 1=one file, 2+ =many files
free(cfn);
- cfn = (Byte *) xstrdup(argv[optind]);
+ cfn = (Byte *) bb_xstrdup(argv[optind]);
edit_file(cfn);
}
}
return (0);
}
+#ifdef CONFIG_FEATURE_VI_WIN_RESIZE
+//----- See what the window size currently is --------------------
+static inline void window_size_get(int fd)
+{
+ get_terminal_width_height(fd, &columns, &rows);
+}
+#endif /* CONFIG_FEATURE_VI_WIN_RESIZE */
+
static void edit_file(Byte * fn)
{
Byte c;
*q++ = *p;
*q = '\0';
}
- pat = (Byte *) xstrdup((char *) buf); // save copy of pattern
+ pat = (Byte *) bb_xstrdup((char *) buf); // save copy of pattern
if (*p == '/')
p++;
q = char_search(dot, pat, FORWARD, FULL);
// There is a read-able regular file
// make this the current file
- q = (Byte *) xstrdup((char *) fn); // save the cfn
+ q = (Byte *) bb_xstrdup((char *) fn); // save the cfn
free(cfn); // free the old name
cfn = q; // remember new cfn
if (strlen((char *) args) > 0) {
// user wants a new filename
free(cfn);
- cfn = (Byte *) xstrdup((char *) args);
+ cfn = (Byte *) bb_xstrdup((char *) args);
} else {
// user wants file status info
edit_status();
q = dot;
} else if (strchr("wW", c)) {
do_cmd(c); // execute movement cmd
- if (dot > text)
- dot--; // move back off of next word
+ // if we are at the next word's first char
+ // step back one char
+ // but check the possibilities when it is true
+ if (dot > text && ((isspace(dot[0]) && !isspace(dot[0]))
+ || (ispunct(dot[-1]) && !ispunct(dot[0]))
+ || (isalnum(dot[-1]) && !isalnum(dot[0]))))
+ dot--; // move back off of next word
if (dot > text && *dot == '\n')
dot--; // stay off NL
q = dot;
term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG ON- allow intr's
term_vi.c_iflag &= (~IXON & ~ICRNL);
term_vi.c_oflag &= (~ONLCR);
-#ifndef linux
term_vi.c_cc[VMIN] = 1;
term_vi.c_cc[VTIME] = 0;
-#endif
erase_char = term_vi.c_cc[VERASE];
tcsetattr(0, TCSANOW, &term_vi);
}
tcsetattr(0, TCSANOW, &term_orig);
}
-#ifdef CONFIG_FEATURE_VI_WIN_RESIZE
-//----- See what the window size currently is --------------------
-static void window_size_get(int sig)
-{
- int i;
-
- i = ioctl(0, TIOCGWINSZ, &winsize);
- if (i != 0) {
- // force 24x80
- winsize.ws_row = 24;
- winsize.ws_col = 80;
- }
- if (winsize.ws_row <= 1) {
- winsize.ws_row = 24;
- }
- if (winsize.ws_col <= 1) {
- winsize.ws_col = 80;
- }
- rows = (int) winsize.ws_row;
- columns = (int) winsize.ws_col;
-}
-#endif /* CONFIG_FEATURE_VI_WIN_RESIZE */
-
//----- Come here when we get a window resize signal ---------
#ifdef CONFIG_FEATURE_VI_USE_SIGNALS
static void winch_sig(int sig)
}
refresh(FALSE);
free(obufp);
- obufp = (Byte *) xstrdup((char *) buf);
+ obufp = (Byte *) bb_xstrdup((char *) buf);
return (obufp);
}
if (cmdcnt-- > 1) {
do_cmd(c);
} // repeat cnt
- dot = end_line(dot + 1);
+ dot = end_line(dot);
break;
case '%': // %- find matching char of pair () [] {}
for (q = dot; q < end && *q != '\n'; q++) {
// Stuff the last_modifying_cmd back into stdin
// and let it be re-executed.
if (last_modifying_cmd != 0) {
- ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd);
+ ioq = ioq_start = (Byte *) bb_xstrdup((char *) last_modifying_cmd);
}
break;
#endif /* CONFIG_FEATURE_VI_DOT_CMD */
if (strlen((char *) q) > 1) { // new pat- save it and find
// there is a new pat
free(last_search_pattern);
- last_search_pattern = (Byte *) xstrdup((char *) q);
+ last_search_pattern = (Byte *) bb_xstrdup((char *) q);
goto dc3; // now find the pattern
}
// user changed mind and erased the "/"- do nothing
{
static time_t oldtim;
time_t tim;
- char d[2], buf[BUFSIZ], msg[BUFSIZ];
+ char d[2], msg[BUFSIZ];
msg[0] = '\0';
if (end < text) {
if (strlen(msg) > 0) {
alarm(0);
- printf(buf, "\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
+ printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
totalcmds, last_input_char, msg, SOs, SOn);
fflush(stdout);
while (read(0, d, 1) > 0) {