[BACK]Return to tokenizer.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libedit

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libedit/tokenizer.c between version 1.13 and 1.14

version 1.13, 2003/10/18 23:48:42 version 1.14, 2003/12/05 13:37:48
Line 46  __RCSID("$NetBSD$");
Line 46  __RCSID("$NetBSD$");
  */   */
 #include <string.h>  #include <string.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include "tokenizer.h"  #include "histedit.h"
   
 typedef enum {  typedef enum {
         Q_none, Q_single, Q_double, Q_one, Q_doubleone          Q_none, Q_single, Q_double, Q_one, Q_doubleone
Line 170  tok_end(Tokenizer *tok)
Line 170  tok_end(Tokenizer *tok)
   
   
 /* tok_line():  /* tok_line():
  *      Bourne shell like tokenizing   *      Bourne shell (sh(1)) like tokenizing
  *      Return:   *      Arguments:
  *              -1: Internal error   *              tok     current tokenizer state (setup with tok_init())
  *               3: Quoted return   *              line    line to parse
  *               2: Unmatched double quote   *      Returns:
  *               1: Unmatched single quote   *              -1      Internal error
  *               0: Ok   *               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
  */   */
 public int  public int
 tok_line(Tokenizer *tok, const char *line, int *argc, const char ***argv)  tok_line(Tokenizer *tok, const LineInfo *line,
       int *argc, const char ***argv, int *cursorc, int *cursoro)
 {  {
         const char *ptr;          const char *ptr;
           int cc, co;
   
         for (;;) {          cc = co = -1;
                 switch (*(ptr = line++)) {          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) {
                 case '\'':                  case '\'':
                         tok->flags |= TOK_KEEP;                          tok->flags |= TOK_KEEP;
                         tok->flags &= ~TOK_EAT;                          tok->flags &= ~TOK_EAT;
Line 283  tok_line(Tokenizer *tok, const char *lin
Line 301  tok_line(Tokenizer *tok, const char *lin
                         tok->flags &= ~TOK_EAT;                          tok->flags &= ~TOK_EAT;
                         switch (tok->quote) {                          switch (tok->quote) {
                         case Q_none:                          case Q_none:
                                 tok_finish(tok);                                  goto tok_line_outok;
                                 *argv = (const char **)tok->argv;  
                                 *argc = tok->argc;  
                                 return (0);  
   
                         case Q_single:                          case Q_single:
                         case Q_double:                          case Q_double:
Line 316  tok_line(Tokenizer *tok, const char *lin
Line 331  tok_line(Tokenizer *tok, const char *lin
                                         tok->flags &= ~TOK_EAT;                                          tok->flags &= ~TOK_EAT;
                                         return (3);                                          return (3);
                                 }                                  }
                                 tok_finish(tok);                                  goto tok_line_outok;
                                 *argv = (const char **)tok->argv;  
                                 *argc = tok->argc;  
                                 return (0);  
   
                         case Q_single:                          case Q_single:
                                 return (1);                                  return (1);
Line 404  tok_line(Tokenizer *tok, const char *lin
Line 416  tok_line(Tokenizer *tok, const char *lin
                         tok->argv = p;                          tok->argv = p;
                 }                  }
         }          }
    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);
   }
   
   /* 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));
 }  }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

CVSweb <webmaster@jp.NetBSD.org>