Browse Source

change

master
陈越 3 years ago
parent
commit
302cec31c8
3 changed files with 50 additions and 48 deletions
  1. +2
    -1
      fun.h
  2. +48
    -47
      fun_2.c
  3. BIN
      main

+ 2
- 1
fun.h View File

@ -2,8 +2,9 @@
#define FUN_H_INCLUDED
#define MAXLINE (80)
#include "fun_1.c"
#include "fun_2.c"
#include "fun_1.c"
//void history(char *cmdline);
//void print_his(char *argv);

+ 48
- 47
fun_2.c View File

@ -23,43 +23,6 @@ void print_history(char *argv)
puts(storage[i]);
}
int Is_pipe(char **argv)
{
int i = 0;
int Ispipe = 0;
char *cmd_0[MAXLINE];
char *cmd_1[MAXLINE];
while (argv[i]!=NULL)
{
if (argv[i][0] == '|')
{
Ispipe = 1;
}
i++;
}
if(Ispipe == 0)
{
return 0;
}
i = 0;
while (argv[i][0] != '|')
{
cmd_0[i] = argv[i];
i++;
}
cmd_0[i] = NULL;
i++;
int j = 0;
while (argv[i]!=NULL)
{
cmd_1[j] = argv[i];
i++;
j++;
}
cmd_1[j] = NULL;
shell_pip(cmd_0, cmd_1);
return 1;
}
void shell_pip(char **prog1, char **prog2)
{
@ -93,29 +56,28 @@ void shell_pip(char **prog1, char **prog2)
close(des_p[1]);
wait(0);
wait(0);
return 0;
}
int Is_redirect(char **argv)
int Is_pipe(char **argv)
{
int i = 0;
int Isopen = 0;
int Ispipe = 0;
char *cmd_0[MAXLINE];
char *cmd_1[MAXLINE];
while (argv[i]!=NULL)
{
if (argv[i][0] == '>')
if (argv[i][0] == '|')
{
Isopen = 1;
Ispipe = 1;
}
i++;
}
if(Isopen == 0)
if(Ispipe == 0)
{
return 0;
}
i = 0;
while (argv[i][0] != '>')
while (argv[i][0] != '|')
{
cmd_0[i] = argv[i];
i++;
@ -129,12 +91,12 @@ int Is_redirect(char **argv)
i++;
j++;
}
cmd_1[j] = NULL;
shell_direct(cmd_0, cmd_1);
cmd_1[j] = NULL;
shell_pip(cmd_0, cmd_1);
return 1;
}
void shell_direct(char **prog1, char **prog2)
{
int fd;
@ -169,6 +131,45 @@ void shell_direct(char **prog1, char **prog2)
wait(0);
}
int Is_redirect(char **argv)
{
int i = 0;
int Isopen = 0;
char *cmd_0[MAXLINE];
char *cmd_1[MAXLINE];
while (argv[i]!=NULL)
{
if (argv[i][0] == '>')
{
Isopen = 1;
}
i++;
}
if(Isopen == 0)
{
return 0;
}
i = 0;
while (argv[i][0] != '>')
{
cmd_0[i] = argv[i];
i++;
}
cmd_0[i] = NULL;
i++;
int j = 0;
while (argv[i]!=NULL)
{
cmd_1[j] = argv[i];
i++;
j++;
}
cmd_1[j] = NULL;
shell_direct(cmd_0, cmd_1);
return 1;
}
/*
void mytop()
{

BIN
main View File


Loading…
Cancel
Save