diff options
author | tjr <tjr@FreeBSD.org> | 2004-04-17 07:16:34 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2004-04-17 07:16:34 +0000 |
commit | 44c4d557e2436dfbb703a9fc3e78fac79c574d4b (patch) | |
tree | f46d7e51d83360c5b6bdacf5b08e16a415ed61b5 /contrib/less/cmdbuf.c | |
parent | c0c85bc41cb6c023adae56cf0a7e3495bd528cb2 (diff) | |
download | FreeBSD-src-44c4d557e2436dfbb703a9fc3e78fac79c574d4b.zip FreeBSD-src-44c4d557e2436dfbb703a9fc3e78fac79c574d4b.tar.gz |
Import less v381.
Diffstat (limited to 'contrib/less/cmdbuf.c')
-rw-r--r-- | contrib/less/cmdbuf.c | 83 |
1 files changed, 56 insertions, 27 deletions
diff --git a/contrib/less/cmdbuf.c b/contrib/less/cmdbuf.c index e6862b8..dbf5f2a 100644 --- a/contrib/less/cmdbuf.c +++ b/contrib/less/cmdbuf.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2000 Mark Nudelman + * Copyright (C) 1984-2002 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -64,25 +64,25 @@ struct mlist */ struct mlist mlist_search = { &mlist_search, &mlist_search, &mlist_search, NULL }; -public void constant *ml_search = (void *) &mlist_search; +public void * constant ml_search = (void *) &mlist_search; struct mlist mlist_examine = { &mlist_examine, &mlist_examine, &mlist_examine, NULL }; -public void constant *ml_examine = (void *) &mlist_examine; +public void * constant ml_examine = (void *) &mlist_examine; #if SHELL_ESCAPE || PIPEC struct mlist mlist_shell = { &mlist_shell, &mlist_shell, &mlist_shell, NULL }; -public void constant *ml_shell = (void *) &mlist_shell; +public void * constant ml_shell = (void *) &mlist_shell; #endif #else /* CMD_HISTORY */ /* If CMD_HISTORY is off, these are just flags. */ -public void constant *ml_search = (void *)1; -public void constant *ml_examine = (void *)2; +public void * constant ml_search = (void *)1; +public void * constant ml_examine = (void *)2; #if SHELL_ESCAPE || PIPEC -public void constant *ml_shell = (void *)3; +public void * constant ml_shell = (void *)3; #endif #endif /* CMD_HISTORY */ @@ -730,7 +730,10 @@ delimit_word() char *word; #if SPACES_IN_FILENAMES char *p; - int quoted; + int delim_quoted = 0; + int meta_quoted = 0; + char *esc = get_meta_escape(); + int esclen = strlen(esc); #endif /* @@ -751,6 +754,7 @@ delimit_word() * We're already at the end of the word. */ ; +#if 0 } else { /* @@ -758,9 +762,10 @@ delimit_word() * Huh? There's no word here. */ return (NULL); +#endif } /* - * Search backwards for beginning of the word. + * Find the beginning of the word which the cursor is in. */ if (cp == cmdbuf) return (NULL); @@ -770,24 +775,34 @@ delimit_word() * without a corresponding close quote), we return everything * from the open quote, including spaces. */ - quoted = 0; + for (word = cmdbuf; word < cp; word++) + if (*word != ' ') + break; + if (word >= cp) + return (cp); for (p = cmdbuf; p < cp; p++) { - if (!quoted && *p == openquote) + if (meta_quoted) + { + meta_quoted = 0; + } else if (esclen > 0 && p + esclen < cp && + strncmp(p, esc, esclen) == 0) + { + meta_quoted = 1; + p += esclen - 1; + } else if (delim_quoted) { - quoted = 1; - word = p; - } else if (quoted && *p == closequote) + if (*p == closequote) + delim_quoted = 0; + } else /* (!delim_quoted) */ { - quoted = 0; + if (*p == openquote) + delim_quoted = 1; + else if (*p == ' ') + word = p+1; } } - if (quoted) - return (word); #endif - for (word = cp-1; word > cmdbuf; word--) - if (word[-1] == ' ') - break; return (word); } @@ -835,11 +850,20 @@ init_compl() */ c = *cp; *cp = '\0'; -#if SPACES_IN_FILENAMES - if (*word == openquote) - word++; -#endif - tk_text = fcomplete(word); + if (*word != openquote) + { + tk_text = fcomplete(word); + } else + { + char *qword = shell_quote(word+1); + if (qword == NULL) + tk_text = fcomplete(word+1); + else + { + tk_text = fcomplete(qword); + free(qword); + } + } *cp = c; } @@ -1006,10 +1030,15 @@ cmd_char(c) /* * Return the number currently in the command buffer. */ - public int + public LINENUM cmd_int() { - return (atoi(cmdbuf)); + register char *p; + LINENUM n = 0; + + for (p = cmdbuf; *p != '\0'; p++) + n = (10 * n) + (*p - '0'); + return (n); } /* |