From 52c3b99c492bec60b10d682e197697a2fe964157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cchenyue=E2=80=9D?= <10195501438@stu.ecnu.edu.cn> Date: Wed, 10 Mar 2021 23:55:17 +0800 Subject: [PATCH] 3.10 commit --- fun.h | 5 ++++- fun_1.c | 36 +++++++++++++++++++++++++----------- fun_2.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- hello | Bin 0 -> 12744 bytes main | Bin 0 -> 22512 bytes main.c | 5 ++++- 6 files changed, 85 insertions(+), 14 deletions(-) create mode 100755 hello create mode 100755 main diff --git a/fun.h b/fun.h index 0f4f5ee..967fdf1 100644 --- a/fun.h +++ b/fun.h @@ -1,8 +1,11 @@ #ifndef FUN_H_INCLUDED #define FUN_H_INCLUDED - #define MAXLINE (80) +#include "fun_1.c" +#include "fun_2.c" + + void history(char *cmdline); void print_his(char *argv); diff --git a/fun_1.c b/fun_1.c index 9640173..1570845 100644 --- a/fun_1.c +++ b/fun_1.c @@ -1,7 +1,8 @@ #include #include #include -#include "fun.h" +#include +//#include "fun.h" void eval(char *cmdline) @@ -10,10 +11,8 @@ void eval(char *cmdline) char buf[MAXLINE]; int isBg; int pid; - strcpy(buf,cmdline); isBg = parseline(cmdline,argv); - if(argv[0] == NULL) { return; @@ -21,28 +20,23 @@ void eval(char *cmdline) if(!builtin_cmd(argv)) { -/* if((pid=fork())==0) { - setpgid(0,0); if(execvp(argv[0],argv)<0) { printf("%s:Command not found.\n",argv[0]); exit(0); } } - if(!isBg) { - waitfg(pid); + wait(NULL); } else { - printf("[%d] (%d) %s",pid2jid(pid),pid,cmdline); + return; } -*/ } - return; } int parseline(const char *cmdline, char **argv) @@ -103,6 +97,10 @@ int parseline(const char *cmdline, char **argv) int builtin_cmd(char **argv) { + if(Is_pipe(argv)==1) + { + return 1; + } if(!strcmp(argv[0],"quit")||!strcmp(argv[0],"exit")) { exit(0); @@ -112,7 +110,23 @@ int builtin_cmd(char **argv) print_his(argv[1]); return 1; } - if(!strcmp(argv[0],"jobs")) + if(!strcmp(argv[0],"cd")) + { + if (argv[1] == NULL) + { + return 1; + } + else + { + if (chdir(argv[1]) != 0) + { + perror("Error: "); + } + return 1; + } + } + + if(!strcmp(argv[0],"mytop")) { return 1; } diff --git a/fun_2.c b/fun_2.c index b7d0d71..7892d3c 100644 --- a/fun_2.c +++ b/fun_2.c @@ -1,5 +1,5 @@ #include -#include "fun.h" +//#include "fun.h" static int num = 0; static char storage[MAXLINE][MAXLINE]; @@ -20,4 +20,55 @@ void print_his(char *argv) } for(; i8K1lJE3fl8Z5lTz^|m;Ylh*6lO@c!cdgu7DuADg7mp;^{>+{{(KIMF8 z_V&Q85LCFdG9>LuKvnSv>L1XD5K@KID*RItxwJy6P>L!Z3Kc18AO)%#K_3J)$M?;C z-`(xrZWQroLGmQ$Z|3(s=9_P3XJ=;T%L5~W!9YN83X0DNEInHnm5}{c2yKTf64oo$ zh^V+;d_pt;QU|}NugvsWe<_o6VE15D%o_t z(JnF-LXiOKp|2t=i$Evr4AFM-qk|~xVG;Erq!%H1rf0}8rrbVk8~);CFCL6S3CmF= zqF?^4P?W`V_`H>pdeT{tZ-`2q={{K!f+_2L7W7DkBrZ=P#2%yi{Nf@w9z?0RqAQc0 z+_S4Ilj_W*vxWK2`QAO9dv>Y$oZ2JXjrLJ?=+F^a6ZSWoLZ7dOA7aQ~_sZ7KHFYh< zfBtLb);qrQ$n=)hOW#0U{z3MN(@v07JfznFw$TGe%nKg@T=9^<#|IY>k0dsKkC-#l zS!+t@IzoEhN|=^Dn@DHH(8zG#0li1DgSCG<93lQ&9RBEXNg#0r?NctKo01He{RygUcazT5!zQzS;5j7ZSlpXWhu{pO1n*9 zm$q5(x4A6}IV{g0`>k`OQVH#JzdgM4>V4YM@3h4?R}ROAUp}QYM1}V9>1XSay!;rD z(x$bb_qQU-FHfn>Z4b&CirR_&-N4XJ)bBvD_XBGaxb%y)kO!C6l+HD`J%EzSL_t0v z<#%61neCUf)0aZp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z98>5YCO&VUA$|U?ZF6m3IgfM+e%1O#s=rA33JO&v`Hc_COuq^FYJEQcc$W0#d4q>O zL*I7k^Z8f@HHgoCS)R;tQ9MEV9Dm*q^pZZ0UsmAwartSNKA*S6Nq-*;5_Q-Ayi1?Y z<%*<#!KLr6{}k}?iZ%_G%K06FklgZIX8H=q;P(aA=Y40>73%*AbkSAT=kq|mH-3gD zENV{KAMXD*Ko><=pU(}?(MJyjc-4vhX8LAU-j znp3v=F4<)Nd0*Flh58q%{+(ruc82wDcHvw<(-35E{^rEzpNFab^?Xr-1iaeAW1npx zouDJuBI)CEFa|%48_z4q=C(t&oK|kMv-`N?iNk)gAbunE(!Y7TEpe?&!BrIh1T@q4 A-v9sr literal 0 HcmV?d00001 diff --git a/main b/main new file mode 100755 index 0000000000000000000000000000000000000000..1f82560f9ee43e95a1b8424a801b1b63522769a5 GIT binary patch literal 22512 zcmeHP4Rlo1oxg7;FPX_ClTRRgD5HW!Fp~t30z#bt0}~7%6;ROP%VcJfj3zVb%$u0d zS}7qeQ=kod{GeO9OZT{2dyczn+tsCNH5LW6-7dC0%C6gO+Ed)5&^B7DXjS(2zwh3e zH!m~R-96jxp5;R3fB(P#$G!J|@4N54d*6F^`CHf86otuTV;^J04Lf`sGJYAG*vMId zEoDyTV{_OQtQbfU{(M|Q)W}JCUbvRjA@uB^WVh62084E?o{@Bx0W(Qu4T-8kW)Pp? z4C<&cSVkMK@W&}G|B>n9l>N*DeNkRzNDwfF_NURebhGk+baBS zwfVpi?<2z2@ZT&YT}qqJ=wZq~SIJpWAJ0gt8!(ep+I<{$ynRCc`-pJQZV=@aiVG9< zmsB*DHFQVYmn?4R4%c@_W2yf7{-sOmmn`-sWAZp+7-u0GR!dk?PlS30SfoFyvpa(L>5U{3@dWEl z=}FcRPuvcTa5Tnx6VaI7!8$r4z+u!KiLp>uIGTWIB-Gc-f_gm4y>%rx>FH&fM&)Qp zJ($q7o*=xeYi(JzT3hH{=)Hz%En7Ee;YcFV8BOYu#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IJ7+x z>gml@Fs(;gK9{3~lX0yJuL0AibZEVeKH;O$vZOhR386O17#pvrmxd>mzrim^W)--$wNDeRR_`IL}p)VEX+R>+qauMcD4)kE@ z5mZkYv`gl&&>KnMB!{=8Bi`m!E%kb^Q*fQJl$V+uuE$QQm$)u^mem^`h{2yhv3$-Y zeOMW%M_J8`1{qFqK{61z-fo<=d9=NHq#t=cti6diA9~(MmpCH3!myQ`VPPDahK0<- zaj++f3x-a*8o-a27hpI;|1d8mi5?vIM!k4ryg^-0MB7t3CKhiv(w^#sw_vO@%SK}z zxF!*z_Vz@iPjY-CKu8ck2@7-cb=7}0Pb*`%#HB4cp5(f${EnS`zd?w(uFMm?0)Mzf z%h=2HTlt+h4`k*fueT-EgpAo`^!_^~vd7)Ic%m=+e#_^9k%~~ytdsAiL4jmlxfNkG zg!oP4&uo9R#K&bvh5ZEQvOkp~E9pJp&Gz!XZCEt)S>Z=|kam*)GmE`^mUz2RESHLc zTI+vQ*vt6K`_e99PvgU!Wc(%eATm^cX)nL4D8IL;OGQDgUp|KuKnxw0RB3R_Z<_Hy51bT&XF5C6^nNP9_Ng~)85+20U``?97yC+#HtwZ&ephwKyf z*8ZZh%;~pa$d|1DQBNBeAMkL(hVjgbIeE+s^6%h}d^TEeX@9i^m*q=pN5*`J$o-dN z9>cIqzECFoSlcrl_R^QRsAsM+IBUJEy7LOyzai}H=E}jP)qZgS`?o~F^lYy=Sy;BJ zfc?KOG^~1L#|S4@`;Efh+Rm*@gh2s&>4)}3WZqoQt;-C~>es4Eyqr7C_WOi=TbY4g q4sr|r^}ekcUJ@e literal 0 HcmV?d00001 diff --git a/main.c b/main.c index 010211e..d717389 100644 --- a/main.c +++ b/main.c @@ -2,16 +2,19 @@ #include #include "fun.h" + int main() { char cmdline[MAXLINE]; while(1) { + int bufsize = MAXLINE; printf("COMMAND->"); - fgets(cmdline, MAXLINE, stdin); + fgets(cmdline, MAXLINE, stdin); eval(cmdline); history(cmdline); } + return 0; }