本文整理汇总了C++中parsecmd函数的典型用法代码示例。如果您正苦于以下问题:C++ parsecmd函数的具体用法?C++ parsecmd怎么用?C++ parsecmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parsecmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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.");
}
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}