Example #1
0
char		*set_local_var(char **arg, int opt, t_sh *t)
{
	static char	**vars = NULL;
	t_lv		*lv;
	int			i;

	i = -1;
	lv = (t_lv *)malloc(sizeof(t_lv));
	lv->d = strchri((*arg), '$');
	if (vars && (opt == 6 || opt == 7))
		return (find_del(vars, arg, opt));
	if (vars && opt == 1)
	{
		if (!scan_op(arg, lv))
			return (NULL);
		i = search_cmp(i, vars, cpy_to(&((*arg)[lv->d + 1]), ';'));
		lv->o = search_ope(&(*arg)[lv->d], t->ope, len(&(*arg)[lv->d]));
		lv->a = ft_strsub((*arg), 0, lv->d);
		lv->b = ft_strdup(ft_strchr(&(*arg)[lv->d], lv->o));
		if (vars[i])
			found_var(vars, lv, arg, i);
		else
		{
			ft_strdel(arg);
			*arg = ft_strjoin_free(lv->a, lv->b, 3);
		}
		return (*arg);
	}
	if (opt == 1 || opt == 6 || opt == 7)
		return (NULL);
	if (!vars)
	{
		vars = (char **)malloc(sizeof(char *) * 100);
		vars[0] = NULL;
	}
	free(lv);
	return (assign_alias(vars, i, arg));
}
Example #2
0
bool tokz_get_token(Tokenizer *tokz, Token *tok)
{
    int c, c2, e;
    
    if (!(tokz->flags&TOKZ_READ_FROM_BUFFER))
    assert(tokz->file!=NULL);
    
    tok_free(tok);
    
    if(!TOK_IS_INVALID(&(tokz->ungettok))){
        *tok=tokz->ungettok;
        tokz->ungettok.type=TOK_INVALID;
        return TRUE;
    }

    while(1){
    
        e=0;
        
        do{
            c=GETCH();
        }while(c!='\n' && c!=EOF && isspace(c));
    
        tok->line=tokz->line;
    
        switch(c){
        case EOF:
            TOK_SET_OP(tok, OP_EOF);
            return TRUE;
            
        case '\n':
            INC_LINE();
            
            if(tokz->flags&TOKZ_IGNORE_NEXTLINE)
                continue;
            
            TOK_SET_OP(tok, OP_NEXTLINE);
            
            return TRUE;
            
        case '\\':
            do{
                c=GETCH();
                if(c==EOF){
                    TOK_SET_OP(tok, OP_EOF);
                    return FALSE;
                }
                if(!isspace(c) && e==0){
                    e=E_TOKZ_EOL_EXPECTED;
                    tokz_warn_error(tokz, tokz->line, e);
                    if(!(tokz->flags&TOKZ_ERROR_TOLERANT))
                        return FALSE;
                }
            }while(c!='\n');
            
            INC_LINE();
            continue;

        case '#':
            if(tokz->flags&TOKZ_READ_COMMENTS){
                e=scan_line_comment(tok, tokz);
                break;
            }else if((e=skip_line_comment(tokz))){
                break;
            }
            
            continue;
            
        case '/':
            c2=GETCH();
            
            if(c2=='='){
                TOK_SET_OP(tok, OP_AS_DIV);
                return TRUE;
            }
            
            if(c2!='*'){
                UNGETCH(c2);
                TOK_SET_OP(tok, OP_DIV);
                return TRUE;
            }
            
            if(tokz->flags&TOKZ_READ_COMMENTS){
                e=scan_c_comment(tok, tokz);
                break;
            }else if((e=skip_c_comment(tokz))){
                break;
            }
            
            continue;
            
        case '\"':
            e=scan_string(tok, tokz, TRUE);
            break;

        case '\'':
            e=scan_char(tok, tokz);
            break;

        default: 
            if(('0'<=c && c<='9') || c=='-' || c=='+'){
                e=scan_number(tok, tokz, c);
                break;
            }

             if(START_IDENT(c))
                e=scan_identifier(tok, tokz, c);
            else
                e=scan_op(tok, tokz, c);
        }
        
        if(!e)
            return TRUE;
        
        tokz_warn_error(tokz, tokz->line, e);
        return FALSE;
    }
}