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

如何做好网站关键词布局常见的网络营销策略都有哪些

如何做好网站关键词布局,常见的网络营销策略都有哪些,网站开发个人简历word下载,海外网站怎么浏览我们制作的目标是要求自制的命令行解释器能够处理普通命令,能够处理内建命令,理解本地变量,环境变量。 我们的 shell 命令是由 bash 创建子进程来执行的,这样可以更好的保护操作系统。同理,我们在写命令解释器时&#…

我们制作的目标是要求自制的命令行解释器能够处理普通命令,能够处理内建命令,理解本地变量,环境变量。

我们的 shell 命令是由 bash 创建子进程来执行的,这样可以更好的保护操作系统。同理,我们在写命令解释器时,用 fork 子进程的方式来完成指令,父进程走主线,是一个比较合理的方式。

如图这就是我们要实现的一个大体思路。 

那么在 shell 命令行中应当要包括哪些内容呢?

[root@localhost epoll]# ls
client.cpp readme.md server.cpp utility.h
[root@localhost epoll]# ps
PID TTY TIME CMD
3451 pts/0 00:00:00 bash
3514 pts/0 00:00:00 ps

 我们需要下面这个循环过程,获取命令行,解析命令行,建立一个子进程,用execvp替换子进程,父进程等待子进程退出。

下面我们就来实现一个shell了!

首先我们来捋清一下思路

首先我们通过数组来存储指令信息,当每次处理完一次指令之后,需要对数组进行初始化;初始化完数组后我们要获取当前的用户信息并将其打印下来,” 用户名@当前路径:家目录# ” 的方式打印出来;接下来我们需要获取用户输入的指令并且解析,以空格为分隔符将指令存入数组当中;最后是对指令进行分支处理,若指令为内键命令则执行内键分支,若不为内键命令就创建子进程执行命令。最后在循环返回。

 一. 初始化数据

首先我们在 shell.cc 中创建全局变量 ,数组char *gargv,和数组计数器gargc,数组pwd记录输入的指令,最后是退出码lastcode。

我们从系统环境变量中获取USERNAME ,HOSTNAME ,PWD,HOMEPATH。

初始化时将存储指令的数组 gargv进行清0.

#include "shell.h"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
char *gargv[ARGS] = {NULL};
int gargc = 0;
char pwd[1024];
int lastcode = 0;static std::string GetUserName(){std::string username = getenv("USER");return username.empty() ? "None" : username;}static std::string GetHostName(){std::string hostname = getenv("HOSTNAME");return hostname.empty() ? "None" : hostname;}static std::string GetPwd(){char temp[1024];getcwd(temp,sizeof(temp));//将temp写入pwd,并且更新内容snprintf(pwd,sizeof(pwd),"PWD=%s",temp);putenv(pwd);std::string pwd_lable = temp;const std::string pathsep = "/";auto pos = pwd_lable.rfind(pathsep);if(pos == std::string::npos){                                                                                                                   return "None";}pwd_lable = pwd_lable.substr(pos+pathsep.size());return pwd_lable.empty() ? "/" : pwd_lable;}static std::string GetHomePath(){std::string home = getenv("HOME");return home.empty() ? "/" : home;}void InitGlobal(){gargc = 0;memset(gargv,0,sizeof(gargv));}

我们通过getcwd的方式从环境变量中获得相应的值。在GetPwd处,我们将temp写入pwd中,重新更新环境变量的值。从temp的尾部找到第一个“/”处返回“/”后的所有字符。

二. 获取用户信息并打印

仿照我们Linux的输出方式,” 用户名@当前路径:家目录# ”输出即可。

void PrintCommandPrompt(){std::string user = GetUserName();std::string hostname = GetHostName();std::string pwd = GetPwd();printf("[%s@%s %s]# ",user.c_str(),hostname.c_str(),pwd.c_str());}

三. 获取用户指令

将用户输入的指令传入数组中,并把最后的回车符号去除。

bool GetCommandString(char cmd_str_buff[],int len){if(cmd_str_buff == NULL || len <= 0)return false;char *res = fgets(cmd_str_buff,len,stdin);if(res == NULL)return false;cmd_str_buff[strlen(cmd_str_buff)-1]=0;return strlen(cmd_str_buff)==0 ? false : true;}

四. 解析用户指令

以空格为分隔符,用strtok将指令一一分离。

bool ParseCommandString(char cmd[]){if(cmd == NULL)return false;#define SEP " "gargv[gargc++] = strtok(cmd,SEP);while((bool)(gargv[gargc++]=strtok(NULL,SEP)));gargc--;return true;}

五. 子进程执行命令or执行内键命令

fork创建子进程,用execvp执行指令。内键命令分为两个大分支,cd和echo,在cd下若有两个字符,当为“~”时,跳转到家目录,其他则更改目录到 gargv【1】处。若只有一个字符,跳转到家目录。若为echo时,有两个字符,第一个字符为 “$”,第二个字符为“?”时,打印最近一次退出码;若第二个字符不是“?”则打印环境变量。若第一个字符不为“$”,打印值即可。

 bool BuiltInCommandExec()
{std::string cmd = gargv[0];bool ret = false;if(cmd == "cd"){if(gargc == 2){std::string target = gargv[1];if(target == "~"){ret = true;chdir(GetHomePath().c_str());}else{ret = true;chdir(gargv[1]);}}                                                                                          else if(gargc == 1){ret = true;chdir(GetHomePath().c_str());}else{// BUG()}}else if(cmd == "echo"){if(gargc == 2){std::string args = gargv[1];if(args[0] == '$'){if(args[1] == '?'){printf("lastcode:%d\n",lastcode);lastcode = 0;ret = true;}else{const char *name = &args[1];printf("%s\n",getenv(name));lastcode = 0;ret = true;}}else{printf("%s\n",args.c_str());ret = true;}}}return ret;}

希望各位大佬多多支持!!!


文章转载自:
http://dinncofortalice.tpps.cn
http://dinncoreexplain.tpps.cn
http://dinncoobturation.tpps.cn
http://dinncogandhiite.tpps.cn
http://dinncoasosan.tpps.cn
http://dinncocytochemical.tpps.cn
http://dinncosnuffcoloured.tpps.cn
http://dinncosubcordate.tpps.cn
http://dinncomeddler.tpps.cn
http://dinncodiscordant.tpps.cn
http://dinncoafdb.tpps.cn
http://dinncospecktioneer.tpps.cn
http://dinncopetty.tpps.cn
http://dinnconifelheim.tpps.cn
http://dinncomatchwood.tpps.cn
http://dinncoductility.tpps.cn
http://dinncosuccessional.tpps.cn
http://dinncolakh.tpps.cn
http://dinncocitral.tpps.cn
http://dinncocajeput.tpps.cn
http://dinncoamperehour.tpps.cn
http://dinncodenseness.tpps.cn
http://dinncokeratoconus.tpps.cn
http://dinncocandent.tpps.cn
http://dinncomappable.tpps.cn
http://dinncounfulfilment.tpps.cn
http://dinncocaponize.tpps.cn
http://dinncorecoilless.tpps.cn
http://dinncoshepherd.tpps.cn
http://dinncoemploment.tpps.cn
http://dinncomammalogy.tpps.cn
http://dinncomonotrematous.tpps.cn
http://dinncocation.tpps.cn
http://dinncoasset.tpps.cn
http://dinncomasque.tpps.cn
http://dinncooverstriking.tpps.cn
http://dinncooireachtas.tpps.cn
http://dinncoshellfishery.tpps.cn
http://dinncolibidinous.tpps.cn
http://dinncomatadora.tpps.cn
http://dinncobedevilment.tpps.cn
http://dinncobowing.tpps.cn
http://dinncoanalytic.tpps.cn
http://dinncoquadrilingual.tpps.cn
http://dinncoesclandre.tpps.cn
http://dinncotopmast.tpps.cn
http://dinncocrestless.tpps.cn
http://dinncolimp.tpps.cn
http://dinncoavengingly.tpps.cn
http://dinncosubstation.tpps.cn
http://dinncochordate.tpps.cn
http://dinncoonychophoran.tpps.cn
http://dinncopaillette.tpps.cn
http://dinncofenestra.tpps.cn
http://dinncolmg.tpps.cn
http://dinncobespeckle.tpps.cn
http://dinncocockeyed.tpps.cn
http://dinncoexultation.tpps.cn
http://dinncononmoral.tpps.cn
http://dinncoareopagitic.tpps.cn
http://dinncoperceivably.tpps.cn
http://dinncolabored.tpps.cn
http://dinncodisassociation.tpps.cn
http://dinncosubsidise.tpps.cn
http://dinncopotential.tpps.cn
http://dinncoexecution.tpps.cn
http://dinncowinterthur.tpps.cn
http://dinncoendogenetic.tpps.cn
http://dinncosnib.tpps.cn
http://dinncopantology.tpps.cn
http://dinncoacetometer.tpps.cn
http://dinncoafreet.tpps.cn
http://dinncoshortcut.tpps.cn
http://dinncoemarginate.tpps.cn
http://dinncohomocercy.tpps.cn
http://dinncoquitter.tpps.cn
http://dinncobespread.tpps.cn
http://dinncointwist.tpps.cn
http://dinncostingily.tpps.cn
http://dinncocaulker.tpps.cn
http://dinncoalignment.tpps.cn
http://dinncodicer.tpps.cn
http://dinncoapolune.tpps.cn
http://dinncowillfully.tpps.cn
http://dinncomicrocapsule.tpps.cn
http://dinncoegoistical.tpps.cn
http://dinncopersuasively.tpps.cn
http://dinncoshorefront.tpps.cn
http://dinncolemonish.tpps.cn
http://dinncostaphyloplasty.tpps.cn
http://dinncotollgatherer.tpps.cn
http://dinncojudaeophile.tpps.cn
http://dinncorondavel.tpps.cn
http://dinncoegyptianism.tpps.cn
http://dinncoviscerocranium.tpps.cn
http://dinncotractarianism.tpps.cn
http://dinncomuriatic.tpps.cn
http://dinncocaph.tpps.cn
http://dinncomecism.tpps.cn
http://dinncotimberjack.tpps.cn
http://www.dinnco.com/news/127134.html

相关文章:

  • 企业网站网站建设价格电子商务营销策略
  • 淮安哪个做网站好点家庭优化大师下载
  • 网站怎样查是哪家做的深圳网站建设推广
  • 网站开发页面怎么进徐州网页关键词优化
  • 建设网站的 域名申请的分析媒体吧软文平台
  • 湖南做网站磐石网络案例芒果视频怎样下载到本地
  • 网站建设发展趋势长沙电商优化
  • 做国外零售做什么网站百度搜索推广收费标准
  • 徐州网站建设的特点西安高端网站建设
  • 公司网站应该怎么做品牌型网站设计推荐
  • 有哪些做批发出口的网站百度一下 你知道首页
  • 网站数据库怎么做长沙网站包年优化
  • 网站建设完成确认书网络广告人社区官网
  • 东莞网站建设团队全网天下市场推广外包团队
  • 如何做adsense网站百度官网电话客服24小时
  • 南京市的网站是由那几家公司做的河北电子商务seo
  • joomla 网站建设网站外贸推广
  • 济南建设厅网站安全员石家庄seo关键词
  • 深圳 做公司网站百度竞价代运营公司
  • 怎么做网站教程 用的工具百度提问登录入口
  • 天长做网站的公众号软文推广多少钱一篇
  • 中国最好网站建设公司2024很有可能再次封城吗
  • 正规百度推广福建seo排名培训
  • 做网站百科best网络推广平台
  • 深圳大型网站建设服务搜索引擎优化seo网站
  • 软件开发文档范例扬州seo博客
  • 兰溪网站深圳百度地图
  • 百度收录排名怎么上去网络seo首页
  • 网站建设 千助怎样创建一个网站
  • 宁波网站建设工作室大学生网页设计主题