本文整理汇总了C++中parse_cmd函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_cmd函数的具体用法?C++ parse_cmd怎么用?C++ parse_cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_cmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parsing
int parsing(char *str, t_shenv *shenv, int n)
{
char **cmd;
int ret;
int i;
i = -1;
if (!(init_parsing(&str, shenv, &ret, &cmd)))
return (EXIT_SUCCESS);
while (cmd && cmd[++i])
{
if (!strncmp(cmd[i], ";", 1) && cmd[i + 1]
&& strncmp(cmd[i + 1], ";", 1))
ret = parse_cmd(cmd[++i], shenv, n);
if (!strncmp(cmd[i], "&&", 2) && cmd[i + 1]
&& strncmp(cmd[i + 1], "&&", 2))
(!ret) ? (ret = parse_cmd(cmd[++i], shenv, n)) : ++i;
if (!strncmp(cmd[i], "||", 2) && cmd[i + 1]
&& strncmp(cmd[i + 1], "||", 2))
(ret == EXIT_FAILURE) ? (ret = parse_cmd(cmd[++i], shenv, n)) : ++i;
if (ret == -1)
return (EXIT_FAILURE);
n = 0;
}
my_free_tab(cmd);
return (EXIT_SUCCESS);
}
示例2: main
/*
* run the program
*/
int main()
{
// holds the directories in the path
char path_dirs[ MAX_PATHS ][ MAX_PATH_LEN ];
int num_dirs = parse_path( path_dirs );
char line[ LINE_LEN ];
command_t cmd;
// get input
print_prompt();
read_cmd( line );
parse_cmd( line, &cmd );
// until we get a line that starts with exit or quit
while( !cmd.argv[0] ||
( strcmp( cmd.argv[0], "quit" ) &&
strcmp( cmd.argv[0], "exit" ) ) )
{
if( cmd.argv[0] )
cmd.name = lookup_path( cmd.argv, path_dirs, num_dirs );
if( cmd.name && cmd.argc > 0 )
{
// create the child
pid_t child_pid = fork();
if( child_pid < 0 )
perror( "fork" );
else if( child_pid == 0 ) // child
execv( cmd.name, cmd.argv );
else // parent
{
if( !cmd.concurrent )
{
int status;
waitpid( child_pid, &status, 0 );
}
}
}
cleanup_cmd( &cmd );
// get input
print_prompt();
read_cmd( line );
parse_cmd( line, &cmd );
}
return 0;
}
示例3: main_thread
static int main_thread(SceSize args, void *argp)
{
char cmdbuf[128];
int cpos;
int retv;
cpos = 0;
while(1){
if(usbAsyncRead(ASYNC_STDOUT, (unsigned char*)&cmdbuf[cpos], 1)<1){
sceKernelDelayThread(250000);
continue;
}
if(cmdbuf[cpos]=='\n'){
cmdbuf[cpos] = 0;
retv = parse_cmd(cmdbuf);
cpos = 0;
}else{
if(cpos<127)
cpos++;
}
}
sceKernelExitDeleteThread(0);
return 0;
}
示例4: mu_config_new
MuConfig*
mu_config_new (int *argcp, char ***argvp)
{
MuConfig *config;
g_return_val_if_fail (argcp && argvp, NULL);
config = g_new0 (MuConfig, 1);
if (!parse_cmd (config, argcp, argvp) ||
!parse_params(config, argcp, argvp)) {
mu_config_destroy (config);
return NULL;
}
/* fill in the defaults if user did not specify */
set_group_mu_defaults (config);
set_group_index_defaults (config);
set_group_find_defaults (config);
set_group_cfind_defaults (config);
set_group_view_defaults (config);
/* set_group_mkdir_defaults (config); */
return config;
}
示例5: run_script
int run_script(FILE *script)
{
int scripting = 1;
int size;
char **args, cmd[100];
while (scripting && !feof(script)) {
size = 0;
redirect_in = 0;
dup2(defin, STDIN_FILENO);
dup2(defout, STDOUT_FILENO);
/* get the input from user. */
fgets(cmd, 100, script);
args = parse_cmd(cmd, &size);
if (pipeFlag) {
scripting = run_pipe_cmd(size, args);
pipeFlag = 0;
} else {
scripting = run_cmd(size, args);
}
}
return cmd_exit_status;
}
示例6: wait_for_input
int wait_for_input(t_socket *socket)
{
char *in[2];
t_buffs buffs;
fd_set fs[2];
char *cmd;
struct timeval tv;
if (!create_buffer(&buffs) || !(in[0] = malloc(4097)) ||
!(in[1] = malloc(4097)) || !memset(in[0], 0, 4097) ||
!memset(in[1], 0, 4097) || gethostname(in[1], 4096) == -1)
return (-1);
while (1)
{
tv.tv_sec = 1;
tv.tv_usec = 0;
set_fds(&fs[1], &fs[0], socket->fd, &buffs);
if (select(socket->fd != -1 ? socket->fd + 1 : 1,
&fs[0], &fs[1], NULL, &tv) == -1)
return (puterr_int(ERR_SELECT, -1));
if (!(cmd = read_all(socket->fd, &fs[0], &buffs, in)) ||
write_all(&fs[1], &buffs, socket->fd) == -1 ||
(cmd && strcmp(cmd, "") && parse_cmd(cmd, socket,
&buffs, in[0]) == -1))
return (free(in[0]), free(in[1]), -1);
}
}
示例7: manage_stdin
static void manage_stdin(char **env, char **path, int count)
{
int i;
char *line;
char **cmd;
cmd = NULL;
line = NULL;
while (1)
{
prompt(env, count);
if (get_next_line(0, &line) > 0)
{
i = -1;
cmd = ft_strsplit(line, ';');
ft_strdel(&line);
while (cmd[++i])
env = parse_cmd(env, cmd, cmd[i], path);
free(cmd);
cmd = NULL;
free_tab(path);
ft_putchar('\n');
}
count++;
}
free_tab(env);
}
示例8: main
void main(void)
{
UCHAR cmd[0x8000];
BOOL exitflag;
log_init();
hello();
log(greeting);
log("DosLogWrite address: %x\n", DosLogWrite);
exitflag=FALSE;
// Ok. Here we just in endless loop. Except for EXIT command.
// create the global env. array
env_create();
while (!exitflag)
{
showpath();
read_cmd (cmd);
exitflag = parse_cmd (cmd);
}
// destroy the global env. array
env_destroy();
exit(0);
}
示例9: prompt
void prompt() {
char line[MAX_PROMPT_LINE];
Command_Info* cmd_info = newCommand_Info(MAX_PROMPT_LINE);
pid_t child = 0;
int status = 0;
while (1) {
printf("msh$ "); fflush(stdout);
fgets(line, MAX_PROMPT_LINE, stdin);
if (feof(stdin) || ferror(stdin))
break;
if (parse_cmd(line, cmd_info) != 0) {
if (!cmd_empty(cmd_info))
fprintf(stderr, "Syntax error!\n");
continue;
}
if (strcmp(cmd_info->arg[0], "exit") == 0) // builtin command exit
break;
if ((child = exec_simple(cmd_info)) > 0) {
waitpid(child, &status, 0);
if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
fprintf(stderr, "Command Not Found!\n");
}
}
deleteCommand_Info(cmd_info);
}
示例10: main
int main(void)
{
char *argv[MAX_ARGC];
int i, argc;
char buf[2040];
printf("\n\rEnter the interative mode, please make your command as follow.\n\n\r");
for(i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i ++)
printf("\n\r %s", cmd_table[i].command);
printf("\n\n\r");
do{
printf("Wlan: ");
gets(buf);
printf("The command entered is : %s\n\r", buf);
strcpy(cmd_buf, buf);
if((argc = parse_cmd(buf, argv)) > 0) {
int found = 0;
for(i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i ++) {
if(strcmp((const char *)argv[0], (const char *)(cmd_table[i].command)) == 0) {
cmd_table[i].function(argc, argv);
found = 1;
break;
}
}
if(!found)
printf("unknown command '%s'\n\r", argv[0]);
}
}while(global_exit);
return 0;
}
示例11: usbshell_task
static void
usbshell_task (void *pvParameters)
{
static portCHAR buf[128], c, *p = buf;
shell_print (PROMPT);
for (;;)
{
if (!vUSBRecvByte (&c, sizeof (c), 100))
continue;
if (c == '\n' || c == '\r')
{
*p = '\0';
parse_cmd (buf);
p = buf;
shell_print (PROMPT);
continue;
}
else if (c < ' ')
continue;
if (p == buf + sizeof (buf) - 1)
{
p = buf;
*p = '\0';
}
/* local echo */
vUSBSendByte (c);
*p++ = c;
}
}
示例12: mu_config_init
MuConfig*
mu_config_init (int *argcp, char ***argvp, GError **err)
{
g_return_val_if_fail (argcp && argvp, NULL);
memset (&MU_CONFIG, 0, sizeof(MU_CONFIG));
MU_CONFIG.maxnum = -1; /* By default, output all matching entries. */
if (!parse_cmd (argcp, argvp, err))
goto errexit;
if (!parse_params(argcp, argvp, err))
goto errexit;
/* fill in the defaults if user did not specify */
set_group_mu_defaults();
set_group_index_defaults();
set_group_find_defaults();
set_group_cfind_defaults();
set_group_view_defaults();
set_group_extract_defaults();
/* set_group_mkdir_defaults (config); */
return &MU_CONFIG;
errexit:
mu_config_uninit (&MU_CONFIG);
return NULL;
}
示例13: parse_pipe
static void parse_pipe(cmds* cmd, prog_args* prog)
{
prog_args* elem = NULL;
/* parse a command */
parse_cmd(cmd, prog);
/* not in pipe? */
if (lookahead.kind!=STROKE)
{
return;
}
/* builtin and starting pipe? */
if( !(cmd->kind==PROG || cmd->kind==PIPE) )
{
raise_error(PARSER_ILLEGAL_COMBINATION);
}
/* in pipe */
cmd->kind=PIPE;
/* output redirection? */
if (prog->output != NULL)
{
raise_error(PARSER_ILLEGAL_REDIRECTION);
}
/* skip pipe symbol and parse next command */
scan();
elem = prog_new();
prog->next=elem;
parse_pipe(cmd,elem);
}
示例14: main
int main(int argc, char* argv[])
{
char* cmd = NULL;
MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);
int socket_fd;
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, SIG_IGN);
signal(SIGINT, sign_handler);
signal(SIGTERM, sign_handler);
if((socket_fd = parse_cmd_line(argc, argv, mem_pool)) <= 0)
{
mem_pool_destroy(mem_pool);
return 0;
}
while (global_start) {
if ((cmd = readline("MILE>")) == NULL) {
break;
}
parse_cmd(cmd,socket_fd,mem_pool);
mem_pool_reset(mem_pool);
if(cmd != NULL)
{
free(cmd);
cmd = NULL;
}
}
mem_pool_destroy(mem_pool);
return 0;
}
示例15: mu_config_init
MuConfig*
mu_config_init (int *argcp, char ***argvp)
{
g_return_val_if_fail (argcp && argvp, NULL);
memset (&MU_CONFIG, 0, sizeof(MU_CONFIG));
if (!parse_cmd (argcp, argvp))
goto errexit;
if (!parse_params(argcp, argvp))
goto errexit;
/* fill in the defaults if user did not specify */
set_group_mu_defaults();
set_group_index_defaults();
set_group_find_defaults();
set_group_cfind_defaults();
set_group_view_defaults();
/* set_group_mkdir_defaults (config); */
return &MU_CONFIG;
errexit:
mu_config_uninit (&MU_CONFIG);
return NULL;
}