Ejemplo n.º 1
0
MODULE get_next_token (void)
{
    char
        thisch;

    while (condition [column] == ' ')   /*  Skip leading spaces              */
        column++;

    thisch     = condition [column];
    token_len  = 0;
    token_posn = column;

    if (is_valid (thisch))
      {
        get_normal_token ();
        the_next_event = normal_event;
      }
    else
    if (is_relat (thisch))
      {
        get_relator_token ();
        the_next_event = relator_event;
      }
    else
    if (is_quote (thisch))
      {
        get_string_token ();
        the_next_event = string_event;
      }
    else
    if (thisch == 0)
        the_next_event = finished_event;
    else
        signal_error (MSG_EVAL_INVALID_TOKEN);
}
Ejemplo n.º 2
0
static void	fill_tab(t_data *data, int *i, int *n, char *s)
{
	if (is_quote(data->line[*i]))
	{
		data->error_quote = data->line[*i];
		while (data->line[*i])
		{
			s[(*n)++] = data->line[(*i)++];
			if (data->line[*i] && *i > 0 && ((data->error_quote ==
				data->line[*i] && data->error_quote != '(') ||
						(data->error_quote == '(' && data->line[*i] == ')')))
			{
				s[(*n)++] = data->line[(*i)++];
				break ;
			}
		}
	}
	if (!data->line[*i])
		return ;
	if (ft_isspace(data->line[*i]))
	{
		s[(*n)++] = data->line[(*i)++];
		while (data->line[*i] && ft_isspace(data->line[*i]))
			*i = *i + 1;
	}
	else
		s[(*n)++] = data->line[(*i)++];
}
Ejemplo n.º 3
0
int			is_quote_missing(t_data *data)
{
	int		i;
	char	quote;
	int		backslash;

	backslash = 0;
	i = -1;
	quote = 0;
	while (data->line[++i])
	{
		data->old_backslash = 0;
		backslash = set_backslash(backslash, data->line, i, data);
		if (!backslash && !quote && is_quote(data->line[i]))
		{
			quote = data->line[i];
			continue ;
		}
		if (((quote && quote == data->line[i] && quote != '(') ||
			(quote == '(' && data->line[i] == ')')) && !data->old_backslash)
			quote = 0;
	}
	if (backslash)
		quote = '\\';
	return (quote);
}
Ejemplo n.º 4
0
static int	get_total_len(t_data *data)
{
	int	i;
	int	n;

	n = 0;
	i = 0;
	while (data->line[i])
	{
		if (is_quote(data->line[i]))
			i = go_forward(data->line, i, &n);
		if (ft_isspace(data->line[i]))
		{
			i++;
			n++;
			while (data->line[i] && ft_isspace(data->line[i]))
				i++;
		}
		else
		{
			i++;
			n++;
		}
	}
	return (n);
}
Ejemplo n.º 5
0
void	sup_quote(char **token)
{
	static int		i[5] = {0, 0, 0, 0, 0};

	while ((*token)[i[0]] != '\0')
	{
		if ((*token)[i[0]] == BACK_SLASH || i[1])
		{
			if ((*token)[i[0]] == BACK_SLASH)
				i[0]++;
			i[1] = !i[1];
		}
		if ((*token)[i[0]] == DOUBLE_QUOTE)
			i[2] = (i[3]) ? i[2] : !i[2];
		if ((*token)[i[0]] == QUOTE)
			i[3] = (i[2]) ? i[3] : !i[3];
		if (!is_quote((*token)[i[0]])
		|| ((*token)[i[0]] == DOUBLE_QUOTE && i[3])
		|| ((*token)[i[0]] == QUOTE && i[2]) || i[1])
			(*token)[i[4]++] = (*token)[i[0]];
		i[0]++;
	}
	while ((*token)[i[4]] != '\0')
		(*token)[i[4]++] = '\0';
}
Ejemplo n.º 6
0
Archivo: Csv.hpp Proyecto: urykhy/stuff
        bool operator()(InputIterator& next,InputIterator end,Token& tok)
        {
            bool bInQuote = false;
            tok = Token();

            if (next == end) {
                bool rc = !hit_last;
                hit_last = true;
                return rc;
            }
            if (is_quote(*next)) {
                bInQuote = true;
                next++;
            }
            for (;next != end;++next) {
                if (bInQuote) {
                    if (is_escape(*next)) {
                        if (next+1 != end && is_quote(*(next+1))) {
                            next++;
                            tok += *next;
                            continue;
                        }
                    }
                    if (is_quote(*next)) {
                        bInQuote = false;
                        continue;
                    }
                } else {
                    if (is_separator(*next)) {
                        next++;
                        return true;
                    }
                    if (is_escape(*next)) {
                        if (next+1 != end) {
                            next++;
                            tok += *next;
                            continue;
                        } else {
                            throw csv_error("unexpected escape symbol");
                        }
                    }
                }
                tok += *next;
            }
            hit_last = true;
            return true;
        }
Ejemplo n.º 7
0
// returns the space delimited or quote-delimited word
// starting at strpos in the string str 
// maximum word length: MAX_PATH*2
static BOOL
getword(TCHAR *str, TCHAR **strpos, TCHAR *result)
{
    result[0] = _T('\0');
    int i = 0;
    TCHAR *pos = *strpos;
    TCHAR quote = _T('\0');

    if (pos < str || pos >= str + _tcslen(str))
        return FALSE;

    if (*pos == _T('\0'))
        return FALSE; /* no more words */

    /* eat leading spaces */
    while (is_whitespace(*pos)) {
        pos++;
    }

    /* extract the word */
    if (is_quote(*pos)) {
        quote = *pos;
        pos++; /* don't include surrounding quotes in word */
    }
    while (*pos) {
        if (quote != _T('\0')) {
            /* if quoted, only end on matching quote */
            if (*pos == quote) {
                pos++; /* include the quote */
                break;
            }
        } else {
            /* if not quoted, end on whitespace */
            if (is_whitespace(*pos))
                break;
        }
        result[i++] = *pos;
        pos++;
        assert(i < MAX_PATH*2);
    }
    if (i == 0)
        return NULL; /* no more words */

    result[i] = _T('\0');
    *strpos = pos;

    return TRUE;
}
Ejemplo n.º 8
0
Archivo: args.hpp Proyecto: xaizek/dit
    bool operator()(InputIterator &next, InputIterator end, Token &tok)
    {
        bool bInQuote = false;
        tok = Token();

        if (next == end) {
            return false;
        }
        while (next != end) {
            if (is_escape(*next)) {
                do_escape(next, end, tok);
            } else if (is_c(*next)) {
                if (!bInQuote) {
                    do {
                        ++next;
                    } while (next != end && is_c(*next));

                    if (tok.empty()) {
                        if (next == end) {
                            return false;
                        }
                        continue;
                    }

                    return true;
                } else {
                    tok += *next;
                }
            } else if (is_quote(*next)) {
                bInQuote = !bInQuote;
            } else {
                tok += *next;
            }

            ++next;
        }
        if (bInQuote) {
            throw boost::escaped_list_error(
                std::string("incomplete quoted argument")
            );
        }
        return true;
    }
Ejemplo n.º 9
0
Archivo: args.hpp Proyecto: xaizek/dit
 void do_escape(Iterator &next, Iterator end, Token &tok)
 {
     if (++next == end) {
         throw boost::escaped_list_error(
             std::string("cannot end with escape")
         );
     } else if (Traits::eq(*next, 'n')) {
         tok += '\n';
     } else if (is_quote(*next)) {
         tok += *next;
     } else if (is_c(*next)) {
         tok += *next;
     } else if (is_escape(*next)) {
         tok += *next;
     } else {
         throw boost::escaped_list_error(
             std::string("unknown escape sequence")
         );
     }
 }
Ejemplo n.º 10
0
int				verif_empty_quote(char *str, size_t *i)
{
	size_t tmp;

	tmp = *i + 1;
	if (!str[tmp] || ft_isspace2(str[tmp]))
	{
		return (1);
	}
	while ((!is_quote_close(str[*i], str[tmp]) && str[tmp]) ||
	is_escaped_char(str, tmp))
	{
		if ((!is_quote(str[tmp]) && !ft_isspace2(str[tmp])) ||
		is_escaped_char(str, tmp))
			return (1);
		tmp++;
	}
	if (str[tmp])
		*i = tmp + 1;
	return (0);
}
Ejemplo n.º 11
0
    bool operator()(InputIterator& next,InputIterator end,Token& tok) {
      bool bInQuote = false;
      tok = Token();

      if (next == end) {
        if (last_) {
          last_ = false;
          return true;
        }
        else
          return false;
      }
      last_ = false;
      for (;next != end;++next) {
        if (is_escape(*next)) {
          do_escape(next,end,tok);
        }
        else if (is_c(*next)) {
          if (!bInQuote) {
            // If we are not in quote, then we are done
            ++next;
            // The last character was a c, that means there is
            // 1 more blank field
            last_ = true; 
            return true;
          }
          else tok+=*next;
        }
        else if (is_quote(*next)) {
          bInQuote=!bInQuote;
        }
        else {
          tok += *next;
        }
      }
      return true;
    }
Ejemplo n.º 12
0
void aliasexpand(char * const cmd, const int maxlen)
{	char *hbuf;				/* work buffer */
	char *cp, *p;
	unsigned ofs, *expanded, *he;
	int i, numExpanded;

	assert(cmd);
	assert(strlen(cmd) < maxlen);

	if((hbuf = malloc(maxlen)) == 0) {
		error_out_of_memory();
		return;
	}
	numExpanded = 0;
	expanded = 0;

redo:						/* iteration to expand all aliases */
	cp = ltrimcl(cmd);		/* skip leading whitespaces */

	/* Check if the user disabled alias expansion */
	if(*cp == '*') {
		memmove(cmd, cp + 1, strlen(cp));
		goto errRet;
	}

	/* Get the name of this command */
	for(p = hbuf; is_fnchar(*cp) || *cp == '.';)
		*p++ = *cp++;
	if(p == hbuf || is_pathdelim(*cp) || is_quote(*cp))
		/* no name || part of path -> no alias */
		goto errRet;

	*p = 0;
	StrFUpr(hbuf);			/* all aliases are uppercased */
	if((ofs = env_findVar(ctxtAlias, hbuf)) == (unsigned)-1)
		/* not found -> no alias */
		goto errRet;

	/* Prevent recursion by recording the offset of the found variable */
	for(i = 0; i < numExpanded; ++i)
		if(expanded[i] == ofs)		/* already used -> ignore */
			goto errRet;

	if((he = realloc(expanded, ++numExpanded)) == 0) {
		error_out_of_memory();
		goto errRet;
	}
	expanded = he;
	expanded[numExpanded - 1] = ofs;

	/************ Expand the command line "cp" with the alias at
						MK_FP(ctxtAlias, ofs)  ***********************/
	ofs += strlen(hbuf) + 1;		/* advance to value */
	if(_fstrlen(MK_FP(ctxtAlias, ofs)) < maxlen - strlen(cp)) {
		/* prepend alias value to remaining command line */
		_fstrcpy(TO_FP(hbuf), MK_FP(ctxtAlias, ofs));
		strcat(hbuf, cp);
		assert(strlen(hbuf) < maxlen);
		strcpy(cmd, hbuf);
		goto redo;				/* next expansion */
	}

	error_command_too_long();

errRet:							/* return to caller */
	free(expanded);
	free(hbuf);
}