Browse Source

3.18

master
陈越 3 years ago
parent
commit
378517ebf4
9 changed files with 713 additions and 710 deletions
  1. +5
    -2
      fun.h
  2. +1
    -2
      fun_1.h
  3. +6
    -3
      fun_2.h
  4. BIN
      main
  5. +11
    -12
      main.c
  6. +2
    -3
      mytop.h

+ 5
- 2
fun.h View File

@ -1,19 +1,19 @@
#ifndef FUN_H_INCLUDED
#define FUN_H_INCLUDED
#define MAXLINE (80)
void eval(char *cmdline);
void sigint_handler();
pid_t getpid(void);
pid_t main_proc_pid;
int Is_pipe(char **argv);
int pipe(int *fd);
int Is_redirect(char **argv);
void history(char *cmdline);
void print_history(char *argv);
void mytop();
int fork();
int close(int arg);
int dup(int fd);
@ -24,4 +24,7 @@ int builtin_cmd(char **argv);
int dup2(int fd, int arg);
int chdir(const char *path );
#include "fun_1.h"
#include "fun_2.h"
#include "mytop.h"
#endif // FUN_H_INCLUDED

fun_1.c → fun_1.h View File

@ -3,8 +3,7 @@
#include <string.h>
#include <signal.h>
#include <fcntl.h>
#include "mytop.c"
#include "fun.h"
void eval(char *cmdline)
{

fun_2.c → fun_2.h View File

@ -3,7 +3,6 @@
#include <string.h>
#include<fcntl.h>
#include "fun.h"
static int num = 0;
static char storage[MAXLINE][MAXLINE];
@ -19,7 +18,9 @@ void print_history(char *argv)
if(argv == NULL)
{
for(; i<num; i++)
puts(storage[i]);
{
fputs(storage[i], stdout);
}
return;
}
i = num - atoi(argv);
@ -28,7 +29,9 @@ void print_history(char *argv)
i = 0;
}
for(; i<num; i++)
puts(storage[i]);
{
fputs(storage[i], stdout);
}
}

BIN
main View File


+ 11
- 12
main.c View File

@ -1,21 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include "fun.h"
#include "fun_2.c"
#include "fun_1.c";
#include "fun.h"
char *getcwd(char *buf,size_t size);
int main()
{
char cmdline[MAXLINE];
main_proc_pid = getpid();
//signal(SIGINT, sigint_handler);
char pwd[64];
signal(SIGINT, sigint_handler);
while(1)
{
printf("COMMAND->");
getcwd(pwd, 64);
printf("[root@yueshell %s]# ",pwd);
//printf("COMMAND->");
fflush(stdin);
fgets(cmdline, MAXLINE, stdin);
fgets(cmdline, MAXLINE, stdin);
eval(cmdline);
history(cmdline);
}
@ -24,9 +26,6 @@ int main()
void sigint_handler()
{
pid_t pid = getpid();
if(pid != main_proc_pid)
{
exit(0);
}
printf("\nWarning : shell exit!!\n");
exit(0);
}

mytop.c → mytop.h View File

@ -1,4 +1,4 @@
/*
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
@ -335,9 +335,8 @@ void mytop()
print_procs(prev_proc,proc,1);
return;
}
/*
*/
void mytop()
{
}
*/

Loading…
Cancel
Save