16,20c16
< * 3. All advertising materials mentioning features or use of this software
< * must display the following acknowledgement:
< * This product includes software developed by the University of
< * California, Berkeley and its contributors.
< * 4. Neither the name of the University nor the names of its contributors
---
> * 3. Neither the name of the University nor the names of its contributors
36c32
< * $NetBSD: tokenizer.c,v 1.6 2000/09/04 22:06:33 lukem Exp $
---
> * $NetBSD: tokenizer.c,v 1.14 2003/12/05 13:37:48 lukem Exp $
43c39
< __FBSDID("$FreeBSD: head/lib/libedit/tokenizer.c 148814 2005-08-07 08:35:39Z stefanf $");
---
> __FBSDID("$FreeBSD: head/lib/libedit/tokenizer.c 148834 2005-08-07 20:55:59Z stefanf $");
51c47
< #include "tokenizer.h"
---
> #include "histedit.h"
64a61
> #define tok_strdup(a) strdup(a)
110c107,113
< tok->ifs = strdup(ifs ? ifs : IFS);
---
> if (tok == NULL)
> return NULL;
> tok->ifs = tok_strdup(ifs ? ifs : IFS);
> if (tok->ifs == NULL) {
> tok_free((ptr_t)tok);
> return NULL;
> }
114,115c117,121
< if (tok->argv == NULL)
< return (NULL);
---
> if (tok->argv == NULL) {
> tok_free((ptr_t)tok->ifs);
> tok_free((ptr_t)tok);
> return NULL;
> }
118,119c124,129
< if (tok->wspace == NULL)
< return (NULL);
---
> if (tok->wspace == NULL) {
> tok_free((ptr_t)tok->argv);
> tok_free((ptr_t)tok->ifs);
> tok_free((ptr_t)tok);
> return NULL;
> }
161,167c171,185
< * Bourne shell like tokenizing
< * Return:
< * -1: Internal error
< * 3: Quoted return
< * 2: Unmatched double quote
< * 1: Unmatched single quote
< * 0: Ok
---
> * Bourne shell (sh(1)) like tokenizing
> * Arguments:
> * tok current tokenizer state (setup with tok_init())
> * line line to parse
> * Returns:
> * -1 Internal error
> * 3 Quoted return
> * 2 Unmatched double quote
> * 1 Unmatched single quote
> * 0 Ok
> * Modifies (if return value is 0):
> * argc number of arguments
> * argv argument array
> * cursorc if !NULL, argv element containing cursor
> * cursorv if !NULL, offset in argv[cursorc] of cursor
170c188,189
< tok_line(Tokenizer *tok, const char *line, int *argc, char ***argv)
---
> tok_line(Tokenizer *tok, const LineInfo *line,
> int *argc, const char ***argv, int *cursorc, int *cursoro)
172a192
> int cc, co;
174,175c194,203
< for (;;) {
< switch (*(ptr = line++)) {
---
> cc = co = -1;
> ptr = line->buffer;
> for (ptr = line->buffer; ;ptr++) {
> if (ptr >= line->lastchar)
> ptr = "";
> if (ptr == line->cursor) {
> cc = tok->argc;
> co = tok->wptr - tok->wstart;
> }
> switch (*ptr) {
274,277c302
< tok_finish(tok);
< *argv = tok->argv;
< *argc = tok->argc;
< return (0);
---
> goto tok_line_outok;
307,310c332
< tok_finish(tok);
< *argv = tok->argv;
< *argc = tok->argc;
< return (0);
---
> goto tok_line_outok;
370,371d391
< /* SUPPRESS 22 */
< int offs = s - tok->wspace;
375c395
< if (offs != 0) {
---
> if (s != tok->wspace) {
377,381c397,402
< for (i = 0; i < tok->argc; i++)
< tok->argv[i] = tok->argv[i] + offs;
< tok->wptr = tok->wptr + offs;
< tok->wstart = tok->wstart + offs;
< tok->wmax = s + size;
---
> for (i = 0; i < tok->argc; i++) {
> tok->argv[i] =
> (tok->argv[i] - tok->wspace) + s;
> }
> tok->wptr = (tok->wptr - tok->wspace) + s;
> tok->wstart = (tok->wstart - tok->wspace) + s;
383a405
> tok->wmax = s + size;
394a417,429
> tok_line_outok:
> if (cc == -1 && co == -1) {
> cc = tok->argc;
> co = tok->wptr - tok->wstart;
> }
> if (cursorc != NULL)
> *cursorc = cc;
> if (cursoro != NULL)
> *cursoro = co;
> tok_finish(tok);
> *argv = (const char **)tok->argv;
> *argc = tok->argc;
> return (0);
395a431,445
>
> /* tok_str():
> * Simpler version of tok_line, taking a NUL terminated line
> * and splitting into words, ignoring cursor state.
> */
> public int
> tok_str(Tokenizer *tok, const char *line, int *argc, const char ***argv)
> {
> LineInfo li;
>
> memset(&li, 0, sizeof(li));
> li.buffer = line;
> li.cursor = li.lastchar = strchr(line, '\0');
> return (tok_line(tok, &li, argc, argv, NULL, NULL));
> }
< * 3. All advertising materials mentioning features or use of this software
< * must display the following acknowledgement:
< * This product includes software developed by the University of
< * California, Berkeley and its contributors.
< * 4. Neither the name of the University nor the names of its contributors
---
> * 3. Neither the name of the University nor the names of its contributors
36c32
< * $NetBSD: tokenizer.c,v 1.6 2000/09/04 22:06:33 lukem Exp $
---
> * $NetBSD: tokenizer.c,v 1.14 2003/12/05 13:37:48 lukem Exp $
43c39
< __FBSDID("$FreeBSD: head/lib/libedit/tokenizer.c 148814 2005-08-07 08:35:39Z stefanf $");
---
> __FBSDID("$FreeBSD: head/lib/libedit/tokenizer.c 148834 2005-08-07 20:55:59Z stefanf $");
51c47
< #include "tokenizer.h"
---
> #include "histedit.h"
64a61
> #define tok_strdup(a) strdup(a)
110c107,113
< tok->ifs = strdup(ifs ? ifs : IFS);
---
> if (tok == NULL)
> return NULL;
> tok->ifs = tok_strdup(ifs ? ifs : IFS);
> if (tok->ifs == NULL) {
> tok_free((ptr_t)tok);
> return NULL;
> }
114,115c117,121
< if (tok->argv == NULL)
< return (NULL);
---
> if (tok->argv == NULL) {
> tok_free((ptr_t)tok->ifs);
> tok_free((ptr_t)tok);
> return NULL;
> }
118,119c124,129
< if (tok->wspace == NULL)
< return (NULL);
---
> if (tok->wspace == NULL) {
> tok_free((ptr_t)tok->argv);
> tok_free((ptr_t)tok->ifs);
> tok_free((ptr_t)tok);
> return NULL;
> }
161,167c171,185
< * Bourne shell like tokenizing
< * Return:
< * -1: Internal error
< * 3: Quoted return
< * 2: Unmatched double quote
< * 1: Unmatched single quote
< * 0: Ok
---
> * Bourne shell (sh(1)) like tokenizing
> * Arguments:
> * tok current tokenizer state (setup with tok_init())
> * line line to parse
> * Returns:
> * -1 Internal error
> * 3 Quoted return
> * 2 Unmatched double quote
> * 1 Unmatched single quote
> * 0 Ok
> * Modifies (if return value is 0):
> * argc number of arguments
> * argv argument array
> * cursorc if !NULL, argv element containing cursor
> * cursorv if !NULL, offset in argv[cursorc] of cursor
170c188,189
< tok_line(Tokenizer *tok, const char *line, int *argc, char ***argv)
---
> tok_line(Tokenizer *tok, const LineInfo *line,
> int *argc, const char ***argv, int *cursorc, int *cursoro)
172a192
> int cc, co;
174,175c194,203
< for (;;) {
< switch (*(ptr = line++)) {
---
> cc = co = -1;
> ptr = line->buffer;
> for (ptr = line->buffer; ;ptr++) {
> if (ptr >= line->lastchar)
> ptr = "";
> if (ptr == line->cursor) {
> cc = tok->argc;
> co = tok->wptr - tok->wstart;
> }
> switch (*ptr) {
274,277c302
< tok_finish(tok);
< *argv = tok->argv;
< *argc = tok->argc;
< return (0);
---
> goto tok_line_outok;
307,310c332
< tok_finish(tok);
< *argv = tok->argv;
< *argc = tok->argc;
< return (0);
---
> goto tok_line_outok;
370,371d391
< /* SUPPRESS 22 */
< int offs = s - tok->wspace;
375c395
< if (offs != 0) {
---
> if (s != tok->wspace) {
377,381c397,402
< for (i = 0; i < tok->argc; i++)
< tok->argv[i] = tok->argv[i] + offs;
< tok->wptr = tok->wptr + offs;
< tok->wstart = tok->wstart + offs;
< tok->wmax = s + size;
---
> for (i = 0; i < tok->argc; i++) {
> tok->argv[i] =
> (tok->argv[i] - tok->wspace) + s;
> }
> tok->wptr = (tok->wptr - tok->wspace) + s;
> tok->wstart = (tok->wstart - tok->wspace) + s;
383a405
> tok->wmax = s + size;
394a417,429
> tok_line_outok:
> if (cc == -1 && co == -1) {
> cc = tok->argc;
> co = tok->wptr - tok->wstart;
> }
> if (cursorc != NULL)
> *cursorc = cc;
> if (cursoro != NULL)
> *cursoro = co;
> tok_finish(tok);
> *argv = (const char **)tok->argv;
> *argc = tok->argc;
> return (0);
395a431,445
>
> /* tok_str():
> * Simpler version of tok_line, taking a NUL terminated line
> * and splitting into words, ignoring cursor state.
> */
> public int
> tok_str(Tokenizer *tok, const char *line, int *argc, const char ***argv)
> {
> LineInfo li;
>
> memset(&li, 0, sizeof(li));
> li.buffer = line;
> li.cursor = li.lastchar = strchr(line, '\0');
> return (tok_line(tok, &li, argc, argv, NULL, NULL));
> }