示例#1
0
文件: loc_var.c 项目: jalcim/42sh
int		search_cmp(int i, char **tb, char *str)
{
	while (tb[++i])
		if (!ft_strncmp(cpy_to(tb[i], '='), str, befor_egal(tb[i])))
			break ;
	return (i);
}
示例#2
0
文件: mod_env.c 项目: jalcim/42sh
void		modif_e2(t_sh *t, t_linez *lz, int k, int *j)
{
	char	*tmp;
	int x = 0;
	if (ft_strncmp("unsetenv", lz->ep_l, 8))
	{
		tmp = ft_strdup(lz->ep_l);
		t->env = realloc_tb(t->env);
		if (search_oplen(&lz->ep_l[k], " =", 10000)
			< search_oplen(&lz->ep_l[k], "<>|&;", 10000))
		{
			if (ft_strchr(&(tmp[k]), '='))
			{
				t->env[++j[1]] = cpy_to(&(tmp[k]), '=');
				x = strchri(&(tmp[k]), '=');
				while (tmp[k + x] == ' ' || tmp[k + x] == '=')
					x++;
			}
			else
			{
				t->env[++j[1]] = cpy_to(&(tmp[k]), ' ');
				x = strchri(&(tmp[k]), ' ');
				while (tmp[k + x] == ' ' || tmp[k + x] == '=')
					x++;
			}
		}
		else
			t->env[++j[1]] = ft_strdup(&(tmp[k]));
		if (x && tmp[k + x])
		{
			replace_char(t->env[j[1]], '=', ' ');
			t->env[j[1]] = epur_str(t->env[j[1]], t);
			if (t->env[j[1]][len(t->env[j[1]]) - 1] == ' ')
				t->env[j[1]][len(t->env[j[1]]) - 1] = '\0';
			t->env[j[1]] = ft_strjoin_free(t->env[j[1]], "=", 1);
			t->env[j[1]] = ft_strjoin_free(t->env[j[1]], &tmp[k + x], 1);
		}
		else
			t->env[j[1]] = ft_strjoin_free(t->env[j[1]], "=", 1);
		ft_strdel(&tmp);
	}
	t->env[++j[1]] = 0;
}
示例#3
0
/* build an ACK from the given invite and reply.
 * NOTE: space has to be allocated allready for the ACK */
void build_ack(char *invite, char *reply, char *ack) {
	char *body;
	int len;

	body = STRSTR(invite, "\r\n\r\n");
	if (body) {
		body++; body++;
		len = body - invite;
		memcpy(ack, invite, len);
		*(ack+len+1) = '\0';
		replace_string(ack, "INVITE", "ACK");
		cpy_to(ack,reply);
		set_cl(ack, 0);
	}
}
示例#4
0
文件: loc_var.c 项目: jalcim/42sh
int		scan_op(char **arg, t_lv *lv)
{
	ft_bzero((void *)lv->flag, 3);
	if ((lv->f = search_ope(&(*arg)[lv->d], "+-*%/=",
			strchri(&(*arg)[lv->d], ';'))))
	{
		if (lv->f == '=')
			return (0);
		lv->flag[0] = search_opi(&(*arg)[lv->d], "+-*%/=",
				strchri(&(*arg)[lv->d], ';'));
		lv->flag[1] = search_ope(ft_strchr(&(*arg)[lv->d],
			lv->f) + 1, "+-*%/=", 1);
	}
	else if (ft_strchr(cpy_to(&(*arg)[lv->d],
			search_opi(&(*arg)[lv->d], ";&<>|", 10000)), '.'))
		lv->f = '.';
	return (1);
}
示例#5
0
文件: loc_var.c 项目: jalcim/42sh
char	*find_del(char **vars, char **arg, int opt)
{
	int		i;
	int		d;
	char	*str;

	i = -1;
	while (vars[++i])
	{
		str = cpy_to(vars[i], '=');
		if (befor_egal(vars[i]) == len(&((*arg)[opt])))
			if (!ft_strncmp(str, &((*arg)[opt]), befor_egal(str)))
				break ;
		ft_strdel(&str);
	}
	d = -1;
	if (vars[i] && opt == 6)
		while (vars[i][++d])
			vars[i][d] = ' ';
	return (vars[i]);
}
示例#6
0
文件: minitools.c 项目: jalcim/42sh
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));
}