• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ parsecmd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中parsecmd函数的典型用法代码示例。如果您正苦于以下问题:C++ parsecmd函数的具体用法?C++ parsecmd怎么用?C++ parsecmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parsecmd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int
main(void)
{
  static char buf[100];
  static char bufCNM[100];
  int fd;
  
  // Assumes three file descriptors open.
  while((fd = open("console", O_RDWR)) >= 0){
    if(fd >= 3){
      close(fd);
      break;
    }
  }
  
  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        printf(2, "cannot cd %s\n", buf+3);
      else{
        if((buf + 3)[0] == '.' && (buf + 3)[1] == '.' && (buf + 3)[2] == 0){
            cutChild(currentDir);
            if(currentDir[0] == 0) isRootDir = 1;
            continue;
        }
        if(isRootDir){
            catenate(currentDir, buf + 3);
            isRootDir = 0;
        }
        else{
            append(currentDir, '/');
            catenate(currentDir, buf + 3);
        }
      }
      continue;
    }

    if(fork1() == 0) {
      int i;
      int len = strlen(buf);
      for(i = len + 1; i > 0; i--) {
        bufCNM[i] = buf[i-1];        
      }   
      bufCNM[0] = '/';
      runcmd(parsecmd(buf));
      if(buf[0] != '/') {
        runcmd(parsecmd(bufCNM));
      }
      exit();
    }
    wait();
  }
  exit();
}
开发者ID:lishuwnc,项目名称:Xv6,代码行数:58,代码来源:sh.c


示例2: main

int main(int argc, char **argv) {
    bool          succeed  = false;
    char         *redirout = (char*)stdout;
    char         *redirerr = (char*)stderr;
    char         *defs     = NULL;

    con_init();
    OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16;

    /*
     * Command line option parsing commences now We only need to support
     * a few things in the test suite.
     */
    while (argc > 1) {
        ++argv;
        --argc;

        if (argv[0][0] == '-') {
            if (parsecmd("redirout", &argc, &argv, &redirout, 1, false))
                continue;
            if (parsecmd("redirerr", &argc, &argv, &redirerr, 1, false))
                continue;
            if (parsecmd("defs",     &argc, &argv, &defs,     1, false))
                continue;

            con_change(redirout, redirerr);

            if (!strcmp(argv[0]+1, "debug")) {
                OPTS_OPTION_BOOL(OPTION_DEBUG) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "memchk")) {
                OPTS_OPTION_BOOL(OPTION_MEMCHK) = true;
                continue;
            }
            if (!strcmp(argv[0]+1, "nocolor")) {
                con_color(0);
                continue;
            }

            con_err("invalid argument %s\n", argv[0]+1);
            return -1;
        }
    }
    con_change(redirout, redirerr);
    succeed = test_perform("tests", defs);
    stat_info();

    return (succeed) ? EXIT_SUCCESS : EXIT_FAILURE;
}
开发者ID:CurrentResident,项目名称:gmqcc,代码行数:50,代码来源:test.c


示例3: sed

/* sed: perform a basic sed substitution command on input */
int sed(char *s, size_t max, const char *input, const char *sedcmd)
{
	char cmd[MAX_MSG];
	struct sedinfo sedbuf;
	std::regex pattern;
	auto type = std::regex_constants::format_sed;

	strncpy(cmd, sedcmd, MAX_MSG);
	if (!parsecmd(&sedbuf, cmd)) {
		puterr(s, max, &sedbuf);
		return 0;
	}

	try {
		if (!sedbuf.ignore)
			pattern = std::regex(sedbuf.regex);
		else
			pattern = std::regex(sedbuf.regex, std::regex::icase);
	} catch (std::regex_error) {
		snprintf(s, max, "sed: invalid regex");
		return 0;
	}

	if (!sedbuf.global)
		type |= std::regex_constants::format_first_only;
	snprintf(s, max, "%s", std::regex_replace(input, pattern,
				sedbuf.replace, type).c_str());
	return 1;
}
开发者ID:frolv,项目名称:lynxbot,代码行数:30,代码来源:sed.cpp


示例4: dlwrite

static long
dlwrite(Chan *c, void *a, long n, vlong voffset)
{
	Cmdbuf *cmd;
	Cmdtab *ct;

	USED(voffset);
	switch((ulong)c->qid.path){
	case Qdynld:
		cmd = parsecmd(a, n);
		qlock(&dllock);
		if(waserror()){
			qunlock(&dllock);
			free(cmd);
			nexterror();
		}
		ct = lookupcmd(cmd, dlcmd, nelem(dlcmd));
		switch(ct->index){
		case DLdev:
			devload(cmd->f[1]);
			break;
		case DLudev:
			devunload(cmd->f[1]);
			break;
		}
		poperror();
		qunlock(&dllock);
		free(cmd);
		break;
	default:
		error(Egreg);
	}
	return n;
}
开发者ID:8l,项目名称:inferno,代码行数:34,代码来源:devdynld.c


示例5: main

int
main(void)
{
  static char buf[100];
  int fd;

  // Assumes three file descriptors open.
  while((fd = open("console", O_RDWR)) >= 0) {
    if(fd >= 3){
      close(fd);

      break;
    }
  }

  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0) {
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        printf(2, "cannot cd %s\n", buf+3);
      continue;
    } else if(buf[0] == 'v' && buf[1] == 'e' && buf[2] == 'r' && buf[3] == 's' && buf[4] == 'i' && buf[5] == 'o' && buf[6] == 'n')
    	printf(1, "uNIX Version 0-1 \n Build Version 3");

    if(fork1() == 0)
      runcmd(parsecmd(buf));
    wait();
  }
  exit();
}
开发者ID:DylanEHolland,项目名称:Operating_Systems,代码行数:33,代码来源:sh.c


示例6: main

int
main(void)
{
  static char buf[100];
  int fd, r;

  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        fprintf(stderr, "cannot cd %s\n", buf+3);
      continue;
    }
    if(strncmp(buf, "exit", 4) == 0) {
      fprintf(stdout, "Exit, good bye.\n");
      exit(0);
    }
    if(fork1() == 0)
      runcmd(parsecmd(buf));
    wait(&r);
  }
  exit(0);
}
开发者ID:yycsysu,项目名称:Operating-systems-6.828,代码行数:26,代码来源:sh.c


示例7: sysconwrite

static int	
sysconwrite(void *va, ulong count)
{
	Cmdbuf *cb;
	int e;
	cb = parsecmd(va, count);
	if(waserror()){
		free(cb);
		nexterror();
	}
	if(cb->nf == 0)
		error(Enoctl);
	if(strcmp(cb->f[0], "reboot") == 0){
		osreboot(rebootargv[0], rebootargv);
		error("reboot not supported");
	}else if(strcmp(cb->f[0], "halt") == 0){
		if(cb->nf > 1)
			e = atoi(cb->f[1]);
		else
			e = 0;
		cleanexit(e);		/* XXX ignored for the time being (and should be a string anyway) */
	}else if(strcmp(cb->f[0], "broken") == 0)
		keepbroken = 1;
	else if(strcmp(cb->f[0], "nobroken") == 0)
		keepbroken = 0;
	else if(strcmp(cb->f[0], "exdebug") == 0)
		exdebug = !exdebug;
	else
		error(Enoctl);
	poperror();
	free(cb);
	return count;
} 
开发者ID:Mekapaedia,项目名称:inferno-rpi,代码行数:33,代码来源:devcons.c


示例8: execute

void execute (char **args, char *command_line){
        pid_t pid;
        pid = fork();
        int status;
        if (pid == -1){
                perror("Fork failed, ABORT!");
                exit(1);
        }
        if (pid == 0){/*child process*/
		parsecmd(command_line, args);
               		if (execvp(args[0], args) < 0){
                        if (strcmp(strerror(errno), "No such file or directory") == 0)
                                printf("Invalid command, n00b.");
                        else
                                printf("%s", strerror(errno));
                        printf("%c" , '\n');
                }
                exit(0);

        }
        else{/* parent */
                if(wait(&status) == -1)
                        perror("Error while waiting for command to complete");
                /*else check the status of the child*/
                else{
                        if (WIFSIGNALED(status) != 0)
                                printf("Error signal : %d\n",WTERMSIG(status));
                        else if (WIFEXITED(status) != 0)
                                ;/*success!*/
			else
				printf("Error in evaluating command."); 
		}
	}
}
开发者ID:magwe25,项目名称:Helms-Deep,代码行数:34,代码来源:shell.c


示例9: regresswrite

static long
regresswrite(struct chan *c, void *a, long n, int64_t unused)
{
	ERRSTACK(1);
	uintptr_t pc;
	struct cmdbuf *cb;
	cb = parsecmd(a, n);

	if (waserror()) {
		kfree(cb);
		nexterror();
	}

	switch((int)(c->qid.path)){
	case Monitorctlqid:
		if(strncmp(a, "ktest", 5) == 0){
			run_registered_ktest_suites();
		} else {
			error(EFAIL, "regresswrite: only commands are %s", ctlcommands);
		}
		break;

	case Monitordataqid:
		if (onecmd(cb->nf, cb->f, NULL) < 0)
			n = -1;
		break;
	default:
		error(EBADFD, ERROR_FIXME);
	}
	kfree(cb);
	poperror();
	return n;
}
开发者ID:GanShun,项目名称:akaros,代码行数:33,代码来源:regress.c


示例10: cmdloop

void
cmdloop(int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;
	enum skipstate skip;

	TRACE(("cmdloop(%d) called\n", top));
	setstackmark(&smark);
	for (;;) {
		if (pendingsigs)
			dotrap();
		inter = 0;
		if (iflag == 1 && top) {
			inter = 1;
			showjobs(out2, SHOW_CHANGED);
			chkmail(0);
			flushout(&errout);
			nflag = 0;
		}
		n = parsecmd(inter);
		TRACE(("cmdloop: "); showtree(n));
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (nflag)
				break;
			if (!stoppedjobs()) {
				if (!iflag || !Iflag)
					break;
				out2str("\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag == 0) {
			job_warning = (job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(n, EV_MORE);
		}
		popstackmark(&smark);
		setstackmark(&smark);

		/*
		 * Any SKIP* can occur here!  SKIP(FUNC|BREAK|CONT) occur when
		 * a dotcmd is in a loop or a function body and appropriate
		 * built-ins occurs in file scope in the sourced file.  Values
		 * other than SKIPFILE are reset by the appropriate eval*()
		 * that contained the dotcmd() call.
		 */
		skip = current_skipstate();
		if (skip != SKIPNONE) {
			if (skip == SKIPFILE)
				stop_skipping();
			break;
		}
	}
	popstackmark(&smark);
}
开发者ID:tombibsd,项目名称:netbsd-src,代码行数:60,代码来源:main.c


示例11: parsecmd

void Users::handle_command(char *buf, User *u){
    netmsg m = parsecmd(buf);
    switch(m.cmd){
    case CMD_NAME:
        if (u->name != NULL){
            free(u->name);
        }
        u->name = strdup(m.arg);
        break;
    case CMD_SAY:
        char buf[MAXLEN];
        sprintf(buf,"%s: %s",u->name,m.arg);
        this->u->messages->addMessage(Message(buf, 20000, 0xffffff ) );
        send("say %s\n",buf);
        break;
    case CMD_KILL:
        //ignore
        break;
    case CMD_PING:
        send(u,"pong %s\n",m.arg);
        break;
    default:
        printf("unknown network command from user %s: %d '%s'\n",u->name,m.cmd,m.arg);
    }
}
开发者ID:qartis,项目名称:qonk,代码行数:25,代码来源:network.cpp


示例12: iigwrite

static int32_t
iigwrite(Chan* c, void* a, int32_t n, int64_t off)
{
	Proc *up = externup();
	Cmdbuf *cb;
	switch((uint32_t)c->qid.path){
	case Qdir:
		error(Eperm);

	case Qiigctl:
		if(off || n >= READSTR)
			error(Ebadarg);
		cb = parsecmd(a, n);
		if(waserror()){
			free(cb);
			nexterror();
		}
		iigctl(cb);
		poperror();
		free(cb);
		return n;
	default:
		error(Egreg);
		break;
	}

	return 0;
}
开发者ID:dancrossnyc,项目名称:harvey,代码行数:28,代码来源:deviig.c


示例13: main

int main(int argc, char* argv[])
{
    static char buf[BUFSIZ];
    int fd;

    whitespace = " \t\r\n\v";
    symbols = "<|>&;()";

    if (argc == 2 && !strcmp(argv[1], "-i"))
        interactive = 1;

    // Assumes three file descriptors open.
    while ((fd = open("/dev/console", O_RDWR)) >= 0) {
        if (fd >= 3) {
            close(fd);
            break;
        }
    }

    // Read and run input commands.
    while (getcmd(buf) >= 0) {
        if (!memcmp(buf, "cd ", 3)) {
            // Clumsy but will have to do for now.
            // Chdir has no effect on the parent if run in the child.
            if (chdir(buf + 3) < 0)
                dprintf(2, "cannot cd %s\n", buf + 3);
            continue;
        } else if (!strcmp(buf, "exit"))
            return 0; // XXX should allow return code (exit [n])
        if (fork1() == 0)
            runcmd(parsecmd(buf));
        wait();
    }
    return 0;
}
开发者ID:JianxinMa,项目名称:v9.js,代码行数:35,代码来源:sh.c


示例14: executer

int executer(char *line)
{
	/* Insert your code to execute the command line
	 * identically to the standard execution scheme:
	 * parsecmd, then fork+execvp, for a single command.
	 * pipe and i/o redirection are not required.
	 */
	//printf("Not implemented: can not execute %s\n", line);

	
	struct cmdline *l;
	l = parsecmd( & line);
	if (l->err) {
		/* Syntax error, read another command */
		printf("error: %s\n", l->err);
		return 1;
	}
	pid_t process = create_processes(l->seq, l->in, l->out, l->bg);
	if(!l->bg){
		while(1){
			waitpid(process, NULL, 0);
			if(waitpid(process, NULL, 0) == -1){
				break;
			}
		}
		//waitpid(process, NULL, 0);
	}

	/* Remove this line when using parsecmd as it will free it */
	//free(line);
	
	return 0;
}
开发者ID:ggramlich26,项目名称:TP2-SEPC,代码行数:33,代码来源:ensishell.c


示例15: main

int
main(void)
{
  static char buf[100];
  int fd, status;
  
  // Assumes three file descriptors open.
  while((fd = open("console", O_RDWR)) >= 0){
    if(fd >= 3){
      close(fd);
      break;
    }
  }
  
  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        printf(2, "cannot cd %s\n", buf+3);
      continue;
    }
    if(fork1() == 0)
      runcmd(parsecmd(buf));
    wait(&status);
  }
  exit(0);
}
开发者ID:galmam,项目名称:OS152,代码行数:30,代码来源:sh.c


示例16: cmdloop

void
cmdloop(void)
{
	Cmd *cmdp;
	File *ocurfile;
	int loaded;

	for(;;){
		if(!downloaded && curfile && curfile->unread)
			load(curfile);
		if((cmdp = parsecmd(0))==0){
			if(downloaded){
				rescue();
				exits("eof");
			}
			break;
		}
		ocurfile = curfile;
		loaded = curfile && !curfile->unread;
		if(cmdexec(curfile, cmdp) == 0)
			break;
		freecmd();
		cmdupdate();
		update();
		if(downloaded && curfile &&
		    (ocurfile!=curfile || (!loaded && !curfile->unread)))
			outTs(Hcurrent, curfile->tag);
			/* don't allow type ahead on files that aren't bound */
		if(downloaded && curfile && curfile->rasp == 0)
			terminp = termoutp;
	}
}
开发者ID:CoryXie,项目名称:nix-os,代码行数:32,代码来源:cmd.c


示例17: main

int
main(void)
{
  static char buf[100];
  int fd, r;

  // Read and run input commands.
  while(getcmd(buf, sizeof(buf)) >= 0){
    if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
      // Clumsy but will have to do for now.
      // Chdir has no effect on the parent if run in the child.
      buf[strlen(buf)-1] = 0;  // chop \n
      if(chdir(buf+3) < 0)
        fprintf(stderr, "cannot cd %s\n", buf+3);
      continue;
    }
    /* also clumsy: can't use exit* programs, but ok since not 
      traversing PATH anyway.*/
    if(!strncmp(buf, "exit", 4)) {
	exit(0);
    }
    if(fork1() == 0)
      runcmd(parsecmd(buf));
    wait(&r);
  }
  exit(0);
}
开发者ID:dcashman,项目名称:Coursework,代码行数:27,代码来源:sh.c


示例18: evalstring

void
evalstring(char *s, int flags)
{
	union node *n;
	struct stackmark smark;
	int flags_exit;

	flags_exit = flags & EV_EXIT;
	flags &= ~EV_EXIT;
	setstackmark(&smark);
	setinputstring(s, 1);
	while ((n = parsecmd(0)) != NEOF) {
		if (n != NULL) {
			if (flags_exit && preadateof())
				evaltree(n, flags | EV_EXIT);
			else
				evaltree(n, flags);
		}
		popstackmark(&smark);
	}
	popfile();
	popstackmark(&smark);
	if (flags_exit)
		exitshell(exitstatus);
}
开发者ID:grayshadow212,项目名称:usr.src,代码行数:25,代码来源:eval.c


示例19: evalstring

void
evalstring(char *s, int flags)
{
	union node *n;
	struct stackmark smark;
	int flags_exit;
	int any;

	flags_exit = flags & EV_EXIT;
	flags &= ~EV_EXIT;
	any = 0;
	setstackmark(&smark);
	setinputstring(s, 1);
	while ((n = parsecmd(0)) != NEOF) {
		if (n != NULL && !nflag) {
			if (flags_exit && preadateof())
				evaltree(n, flags | EV_EXIT);
			else
				evaltree(n, flags);
			any = 1;
		}
		popstackmark(&smark);
		setstackmark(&smark);
	}
	popfile();
	popstackmark(&smark);
	if (!any)
		exitstatus = 0;
	if (flags_exit)
		exraise(EXEXIT);
}
开发者ID:dpl0,项目名称:soc2013,代码行数:31,代码来源:eval.c


示例20: netlogctl

void
netlogctl(Fs *f, char* s, int n)
{
	int i, set;
	Netlogflag *fp;
	Cmdbuf *cb;
	Cmdtab *ct;

	cb = parsecmd(s, n);
	if(waserror()){
		free(cb);
		nexterror();
	}

	if(cb->nf < 2)
		error(Ebadnetctl);

	ct = lookupcmd(cb, routecmd, nelem(routecmd));

	SET(set);

	switch(ct->index){
	case CMset:
		set = 1;
		break;

	case CMclear:
		set = 0;
		break;

	case CMonly:
		parseip(f->alog->iponly, cb->f[1]);
		if(ipcmp(f->alog->iponly, IPnoaddr) == 0)
			f->alog->iponlyset = 0;
		else
			f->alog->iponlyset = 1;
		free(cb);
		poperror();
		return;

	default:
		cmderror(cb, "unknown netlog control message");
	}

	for(i = 1; i < cb->nf; i++){
		for(fp = flags; fp->name; fp++)
			if(strcmp(fp->name, cb->f[i]) == 0)
				break;
		if(fp->name == nil)
			continue;
		if(set)
			f->alog->logmask |= fp->mask;
		else
			f->alog->logmask &= ~fp->mask;
	}

	free(cb);
	poperror();
}
开发者ID:0intro,项目名称:enhanced-plan9,代码行数:59,代码来源:netlog.c



注:本文中的parsecmd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ parsed函数代码示例发布时间:2022-05-30
下一篇:
C++ parseargs函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap