瀏覽代碼

change

master
陈越 3 年之前
父節點
當前提交
302cec31c8
共有 3 個檔案被更改,包括 50 行新增48 行删除
  1. +2
    -1
      fun.h
  2. +48
    -47
      fun_2.c
  3. 二進制
      main

+ 2
- 1
fun.h 查看文件

@ -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 查看文件

@ -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()
{

二進制
main 查看文件


Loading…
取消
儲存