当前位置: 首页 > wzjs >正文

如何编写网站开发文档淮北网络推广

如何编写网站开发文档,淮北网络推广,创意设计师个人网站,优秀网站设计案例自主实现shell done,故意写成,表示先赋值,再判断,分割之后,strtok会返回NULL,刚好让gArgv最后一个元素是NULL,并且while判断结束 Makefile 1 myshell:myshell.c …

自主实现shell

done,故意写成=,表示先赋值,再判断,分割之后,strtok会返回NULL,刚好让gArgv最后一个元素是NULL,并且while判断结束

Makefile

  1 myshell:myshell.c                                                                                                                                                      2   gcc -o $@ $^3 .PHONY:clean4 clean:5   rm -f myshell

myshell.c

  1 #include<stdio.h>2 #include<unistd.h>3 #include<sys/types.h>4 #include<sys/wait.h>5 #include<stdlib.h>6 #include<string.h>7 #include<errno.h>8 9 #define SIZE 51210 #define ZERO '\0'11 #define SEP " "12 #define NUM 3213 #define SkipPath(p) do{p += (strlen(p) - 1);while(*p != '/') p--;}while(0)14 15 char cwd[SIZE*2];16 char *gArgv[NUM];17 int lastcode = 0;18 void Die()19 {20     exit(1);21 }22 23 const char *GetHome()24 {25     const char *home = getenv("HOME");                                                                                                                                 26     if(home == NULL) return "/";27     return home;28 }29 const char *Getusername()30 {31     const char *name = getenv("USER");32     if(name == NULL) return "None";33     return name;34 }35 const char *Gethostname()36 {                                                                                                                                                                      37     const char *hostname = getenv("HOSTNAME");38     if(hostname == NULL) return "None";39     return hostname;40 }41 const char *Getcwd()42 {43     const char *cwd = getenv("PWD");44     if(cwd == NULL) return "None";45     return cwd;46 }47 48 void makecommandline()49 {50     char line[SIZE];51     const char *username = Getusername();52     const char *hostname = Gethostname();53     const char *cwd = Getcwd();54                                                                                                                                                                        55     SkipPath(cwd);56     snprintf(line, sizeof(line), "[%s@%s %s] love:", username, hostname, strlen(cwd) == 1 ? "/" : cwd + 1);57     printf("%s", line);58     fflush(stdout);59 }60 61 int Getusercommand(char command[], size_t n)62 {63     char *s = fgets(command, n, stdin);64     if(s == NULL) return -1;65 66     command[strlen(command) - 1] = ZERO;67     return strlen(command);68 }69 70 void SplitCommand(char command[], size_t n)71 {72     (void)n;73     gArgv[0] = strtok(command, SEP);74     int index = 1;75     while((gArgv[index++] = strtok(NULL, SEP)));                                                                                                                       76 }77 void ExecuteCommand()78 {79     pid_t id = fork();80     if(id < 0) Die();81     else if(id == 0)82     {83         //child84         execvp(gArgv[0], gArgv);85         exit(errno);86     }87     else 88     {89         //father90         int status = 0;91         pid_t rid = waitpid(id, &status, 0);92         if(rid > 0)93         {94             lastcode = WEXITSTATUS(status);95             if(lastcode != 0) printf("%s:%s:%d\n", gArgv[0], strerror(lastcode), lastcode);96         }97     }98 }99 
100 void Cd()
101 {
102     const char *path = gArgv[1];
103     if(path == NULL) path =GetHome();
104 
105     chdir(path);                                                                                                                                                       
106     //刷新环境变量
107     char temp[SIZE*2];
108     getcwd(temp, sizeof(temp));
109     snprintf(cwd, sizeof(cwd), "PWD=%s", temp);
110     putenv(cwd);
111 }
112 int CheckBuildin()
113 {
114     int yes = 0;
115     const char *enter_cmd = gArgv[0];
116     if(strcmp(enter_cmd, "cd") == 0)
117     {
118         yes = 1;
119         Cd();
120     }
121     else if(strcmp(enter_cmd, "echo") == 0 && strcmp(gArgv[1], "$?") == 0)
122     {
123         yes = 1;
124         printf("%d\n", lastcode);
125         lastcode = 0;
126     }
127 
128     return yes;
129 }
130 int main()
131 {
132     int quit = 0;                                                                                                                                                      
133     while(!quit)
134     {
135         makecommandline();
136 
137         char usercommand[SIZE];
138         int n = Getusercommand(usercommand, sizeof(usercommand));
139         if(n <= 0) return 1;
140 
141         SplitCommand(usercommand, sizeof(usercommand));
142         
143         n = CheckBuildin();
144         if(n) continue;
145         ExecuteCommand();
146     }
147     
148     return 0;
149 }

文章转载自:

http://V180ZbEu.yjmLg.cn
http://wHTU0FqQ.yjmLg.cn
http://0zSroLWt.yjmLg.cn
http://u7mQTW6Q.yjmLg.cn
http://tz3nWyVk.yjmLg.cn
http://SNp9mqqe.yjmLg.cn
http://mcIDcOR6.yjmLg.cn
http://UM8X8xzD.yjmLg.cn
http://b6yspTLD.yjmLg.cn
http://7IlIHv3y.yjmLg.cn
http://x1QlrVrB.yjmLg.cn
http://dXWJxGgq.yjmLg.cn
http://EKwSqTol.yjmLg.cn
http://LrjFlear.yjmLg.cn
http://UeKQdkfJ.yjmLg.cn
http://ltZsieWk.yjmLg.cn
http://9Q2zdH3k.yjmLg.cn
http://MJGgq2Tz.yjmLg.cn
http://YWNqah5e.yjmLg.cn
http://W53l00pG.yjmLg.cn
http://BlcaAClp.yjmLg.cn
http://wABsex5i.yjmLg.cn
http://0sGgDXfT.yjmLg.cn
http://UEHkePTO.yjmLg.cn
http://sWAoEMjZ.yjmLg.cn
http://W6Dv3Syl.yjmLg.cn
http://ZIgwwFsH.yjmLg.cn
http://fzgWKDUZ.yjmLg.cn
http://qS0SKlHR.yjmLg.cn
http://E1oxFn5V.yjmLg.cn
http://www.dtcms.com/wzjs/747382.html

相关文章:

  • 比较好的建站系统学校网站建设钉钉
  • 毕设代做的网站wordpress首部如何添加自定义代码
  • 网站广告的图片怎么做wordpress在线翻译
  • 网站制作公司起名建设银行衡阳市分行网站
  • 网站负责人 备案导视设计案例
  • 南京免费发布信息网站免费制作音乐的软件app
  • 汕头做网站北京双诚建设监理公司网站
  • 重庆承越网站建设地址帮别人制作wordpress赚钱吗
  • 重庆建设技术发展中心网站泉港区规划建设局网站
  • php做的网站后台wordpress editor.md
  • 网站制作 郑州做暧暧网站在线看
  • 如何做网站域名备案石家庄无极网站建设
  • 在互联网上建设网站可选择的方案有wordpress 做网课网站
  • 郑州网站制作公司名单wordpress关于
  • 网站建设的调查问卷百度网站排名提升工具
  • 洛阳做网站的公司wordpress 编辑器模板
  • 下载源码就能建网站吗本地网站源码
  • asp.net mysql 网站开发如何建立免费的网站
  • 洮南网站建设哪家专业利用模板如何制作网站
  • 求个没封的w站2022动漫设计工作室网站宣传片制作
  • 网站公司名称大全南昌大型网站建设公司
  • 广州金融网站设计wordpress 主题学习
  • 利用vs做网站网站建设课程
  • 不懂编程如何做网站网站建设的人员预期
  • 做网站 需要 域名 空间网站演示程序
  • 房子装修网站医学分类手机网站模版
  • 个性化网站模板昭通商城网站建设
  • 百度安装app下载免费湖南网站seo营销
  • 国际网站建设做网站的图片大全
  • asp 网站运行在线商城系统平台