コード例 #1
0
ファイル: call_redir.c プロジェクト: ikamikaz3/my_42sh
int		call_redir(t_list *list, int i, char **env)
{
  t_point	point;
  int		a;

  a = 0;
  if (i > 0 && (list[i - 1].operand[0] == '<' ||
		list[i - 1].operand[0] == '>')
      && (list[i].operand[0] == ';' ||
              list[i].operand[0] == '&' ||
	  (list[i].operand[0] == '|' && list[i].operand[1] == '|')))
    {
      point.point = 1;
      point.env = env;
      a = check_redir(list[i].option, list[i + 1].option,
                      list[i].operand, &point);
    }
  else
    {
      point.point = 0;
      point.env = env;
      a = check_redir(list[i].option, list[i + 1].option,
		      list[i].operand, &point);
    }
  return (a);
}
コード例 #2
0
ファイル: parser.c プロジェクト: Fusiow/msh
char				*check_line_cmd(char *str)
{
	int		i;

	i = 0;
	while (str[i] == ' ' && str[i])
		++i;
	if (!str[i])
		return (NULL);
	i = 0;
	if (check_line(str) == 2 || check_redir(str) == 1)
	{
		ft_putendl("msh: Parse error");
		return (NULL);
	}
	while (check_line(str) == 1 || str[ft_strlen(str) - 1] == '\\')
	{
		ft_putstr("parse> ");
		str = ft_strjoin(str, take_cmd(1));
	}
	if (check_line(str) == 2 || check_redir(str) == 1)
	{
		ft_putendl("msh: Parse error");
		return (NULL);
	}
	return (str);
}
コード例 #3
0
ファイル: parser.c プロジェクト: gmorer/minishell
t_lex			*parser(t_lex *lex)
{
	t_lex		*cursor;
	t_detail	*det_error;
	t_lex		*sep_error;

	cursor = lex;
	det_error = NULL;
	sep_error = NULL;
	while (cursor && !det_error)
	{
		if (!is_sep(cursor->str))
		{
			if ((cursor->lst = str_to_lst(cursor->str)) == NULL)
				return (free_all(lex));
			det_error = check_cmd_syntax(cursor->lst);
			if (!det_error && !(det_error = check_redir(cursor->lst)))
				assign_redir(cursor->lst, NULL, &det_error);
		}
		else
			cursor->lst = NULL;
		cursor = cursor->next;
	}
	if (det_error)
		return (free_all(lex));
	sep_error = check_sep_syntax(lex);
	return (sep_error ? free_all(lex) : lex);
}
コード例 #4
0
ファイル: fash.c プロジェクト: dfritter4/Fash-Shell
void execute(char *cmd)
{
	/* Arguments:
			*cmd --- the program to run
		
		Purpose:
			this function takes a string and forks off
			a new process with the global args array
			
			this will first check to see if aliases exist for 
			the command. check_alias will deal with 
			changing arg[0] if an alias exists, so always
			call execvp with arg[0] (instead of cmd arg) in
			case check_alias changes the cmd
			
			it will then check to see if the cmd is a built in
			command. if it is, then this doesnt fork any process
	*/
	int i;
	check_alias(cmd);
	i = check_builtin(args[0]);
	if(!i) { return;} //cmd was a built in (like "cd")
	if(fork() == 0) {		
		//now in child process
		check_redir(); //check for redirections
		i = execvp(args[0], args); //using execvp to avoid PATH crap		
		if(i < 0) {
			printf("-fash: %s: command not found\n", cmd); //error, we'll just say not found
			exit(1);
		}
	}
	else { handleSig = 1; wait(NULL); }
	handleSig = 0;
}
コード例 #5
0
ファイル: call_redir.c プロジェクト: ikamikaz3/my_42sh
int		call_multi_redir(t_list *list, int i, char **env)
{
  t_point	point;

  point.point = 0;
  point.env = env;
  check_redir(list[i].option, list[i + 2].option, list[i].operand, &point);
  return (0);
}
コード例 #6
0
ファイル: redir.c プロジェクト: dfritter4/Fash-Shell
void pipe_execute(char *cmd, int readWrite)
{
		/* Arguments:
			*cmd --- the program to run
			*fds   --- array of two file descriptors for pipe
			readWrite --- 0 = read, 1 = write, 2 = both
		
		Purpose:
			this function takes a string and forks off
			a new process with the global args array
			
			this will first check to see if aliases exist for 
			the command. check_alias will deal with 
			changing arg[0] if an alias exists, so always
			call execvp with arg[0] (instead of cmd arg) in
			case check_alias changes the cmd
			
			it will then check to see if the cmd is a built in
			command. if it is, then this doesnt fork any process
	*/
	int i;
	check_alias(cmd);
	i = check_builtin(args[0]);
	if(!i) { return;} //cmd was a built in (like "cd")
	if(fork() == 0) {
		//in child
		check_redir();
		int newfd, readfd, writefd;
		if(readWrite == 2){ //this is a middle command, no closing, dup both stdin and stdout			
			readfd = open("pipe", O_RDONLY);	
			writefd = open("pipe_middle", O_WRONLY | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH);	
			close(0);
			dup(readfd);
			close(1);
			dup(writefd);		
		}else if (readWrite == 1){ //first command, purely writing	
			newfd = open("pipe", O_WRONLY | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH);	
			dup2(newfd,1);
			close(newfd);
		}else{ //last command, purely reading
			newfd = open("pipe", O_RDONLY);			
			close(0);		
			dup(newfd);
			close(newfd);
		}
		i = execvp(args[0], args);	
			
		if(i < 0) {
			printf("-fash: %s: command not found\n", cmd); //error, we'll just say not found
			exit(1);
		}
		if(readWrite == 0){ close(0);close(newfd);}
		else if(readWrite ==1){close(1);close(newfd);}
		else{ close(0);close(1);close(readfd);close(writefd);system("mv pipe_middle pipe");}
	} else {wait(NULL);}	//wait for everyone
}
コード例 #7
0
ファイル: cmd_translator.c プロジェクト: ekersale/42SH
int		cmd_translator(char *cmd, t_data *data)
{
  t_his		*stor;

  data->conf = NULL;
  if (!(stor = cmd_to_list(cmd)))
    return (SH_FAIL);
  if (!check_redir(stor))
    return (SH_FAIL);
  if (!(list_to_conf(data, stor)))
    return (SH_FAIL);
  if (!check_cmd(data->conf))
    return (SH_FAIL);
  return (SH_OK);
}
コード例 #8
0
ファイル: process.c プロジェクト: Kafei59/epitech-projects
void		my_cmd(t_list *list, char *s, char **env, int i)
{
  char		*epur_s;
  char		**tab;

  epur_s = epur_str(s);
  tab = my_str_to_wordtab(epur_s, &i);
  if ((my_builtin(list, s, tab, env)) == 0 &&		\
      check_redir(epur_s, tab, env, i) == 0)
      my_fork(tab[0], tab, env);
  if (check_env(tab, env) == 1)
    env = env_cpy(list);
  check_recurs(list, s, env, i - 1);
  my_mini_free(epur_s, tab);
}
コード例 #9
0
ファイル: redir.c プロジェクト: kamiky/gunk-and-junk
int		gere_redir(char **path, char **cmd)
{
  int		red;

  red = check_redir(cmd);
  if (red == 1)
    return (redir_droite(path, cmd));
  if (red == 2)
    return (redir_droite_double(path, cmd));
  if (red == 3)
    return (redir_gauche(path, cmd));
  if (red == 4)
    return (redir_gauche_double(path, cmd));
  return (0);
}
コード例 #10
0
ファイル: redirect.c プロジェクト: cern-it-sdc-id/davix
static int simple(void)
{
    struct redir_args args[] = {
        {301, DEST, PATH},
        {302, DEST, PATH},
        {303, DEST, PATH},
        {307, DEST, PATH},
        {0, NULL, NULL}
    };
    int n;

    for (n = 0; args[n].code; n++)
        CALL(check_redir(&args[n], DEST));

    return OK;
}
コード例 #11
0
ファイル: execution.c プロジェクト: Sadzeih/42sh
int			execute_redir(t_redir *redir, t_fd *fd)
{
  if (check_redir(redir) == 1)
    return (1);
  if (redir->left != NULL)
    if (left_redir(fd, redir) == 1)
      return (1);
  if (redir->right != NULL)
    if (right_redir(fd, redir) == 1)
      return (1);
  if (redir->d_right != NULL)
    if (dright_redir(fd, redir) == 1)
      return (1);
  if (redir->d_left != NULL)
    if (dleft_redir(fd, redir) == 1)
      return (1);
  return (0);
}
コード例 #12
0
ファイル: cut.c プロジェクト: FlorianDewulf/42sh
static char	*sort_chain(char *str, int *cur)
{
  int		tmp;
  char		*str2;

  tmp = *cur;
  *cur = move_curs(str, *cur);
  if (str[*cur] == '|' || str[*cur] == ';')
    return (check_around(tmp, *cur, str, str[*cur]));
  else if (str[*cur] == '>' && (str2 = check_redir(str, cur, tmp)))
    return (str2);
  else if (str[*cur] == '<' && (str2 = check_left_redir(str, tmp, cur)))
    return (str2);
  else if (str[*cur] == '&' && (str2 = check_and(tmp, cur, str)))
    return (str2);
  else if (!str[*cur])
    return (cut_chain(tmp, *cur, str));
  else
    return (NULL);
}
コード例 #13
0
ファイル: redirect.c プロジェクト: cern-it-sdc-id/davix
static int relative_2(void)
{
    struct redir_args args = {302, "wishbone", "/foo/bar/"};
    return check_redir(&args, "http://localhost:7777/foo/bar/wishbone");
}
コード例 #14
0
ファイル: redirect.c プロジェクト: cern-it-sdc-id/davix
static int relative_1(void)
{
    struct redir_args args = {302, "norman", "/foo/bar"};
    return check_redir(&args, "http://localhost:7777/foo/norman");
}
コード例 #15
0
ファイル: redirect.c プロジェクト: cern-it-sdc-id/davix
/* check that a non-absoluteURI is qualified properly */
static int non_absolute(void)
{
    struct redir_args args = {302, "/foo/bar/blah", PATH};
    return check_redir(&args, "http://localhost:7777/foo/bar/blah");
}