Ejemplo n.º 1
0
struct cmd_list *
cmd_list_parse(int argc, char **argv, char **cause)
{
	struct cmd_list	*cmdlist;
	struct cmd	*cmd;
	int		 i, lastsplit;
	size_t		 arglen, new_argc;
	char	       **new_argv;

	cmdlist = xmalloc(sizeof *cmdlist);
	TAILQ_INIT(cmdlist);

	lastsplit = 0;
	for (i = 0; i < argc; i++) {
		arglen = strlen(argv[i]);
		if (arglen == 0 || argv[i][arglen - 1] != ';')
			continue;
		argv[i][arglen - 1] = '\0';

		if (arglen > 1 && argv[i][arglen - 2] == '\\') {
			argv[i][arglen - 2] = ';';
			continue;
		}

		new_argc = i - lastsplit;
		new_argv = argv + lastsplit;
		if (arglen != 1)
			new_argc++;

		cmd = cmd_parse(new_argc, new_argv, cause);
		if (cmd == NULL)
			goto bad;
		TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);

		lastsplit = i + 1;
	}

	if (lastsplit != argc) {
		cmd = cmd_parse(argc - lastsplit, argv + lastsplit, cause);
		if (cmd == NULL)
			goto bad;
		TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
	}

	return (cmdlist);

bad:
	cmd_list_free(cmdlist);
	return (NULL);
}
Ejemplo n.º 2
0
/* 简单的shell */
void my_shell(void) {
   cwd_cache[0] = '/';
   cwd_cache[1] = 0;
   while (1) {
      print_prompt(); 
      memset(final_path, 0, MAX_PATH_LEN);
      memset(cmd_line, 0, MAX_PATH_LEN);
      readline(cmd_line, MAX_PATH_LEN);
      if (cmd_line[0] == 0) {	 // 若只键入了一个回车
	 continue;
      }
      argc = -1;
      argc = cmd_parse(cmd_line, argv, ' ');
      if (argc == -1) {
	 printf("num of arguments exceed %d\n", MAX_ARG_NR);
	 continue;
      }
      
      char buf[MAX_PATH_LEN] = {0};
      int32_t arg_idx = 0;
      while(arg_idx < argc) {
	 make_clear_abs_path(argv[arg_idx], buf);
	 printf("%s -> %s\n", argv[arg_idx], buf); 
	 arg_idx++;
      }
   }
   panic("my_shell: should not be here");
}
Ejemplo n.º 3
0
/* con_do_input will mangle your input string, so plz don't rely on it after passing it here. */
static void con_do_input(char *input) {
	/* push the input history first. */
	strncpy(con_default->history[con_default->history_pos], input, CONSOLE_LINE_MAX_LEN);
	con_default->history_pos = (con_default->history_pos + 1) % CONSOLE_HISTORY_SIZE;
	
	cmd_parse(input, CONSOLE_LINE_MAX_LEN);
}
Ejemplo n.º 4
0
void cmd_handler()
{
    char c = Serial.read();
    if (c < 0x20 && c != '\r' && c != '\b')
    {
        return;
    }
    switch (c)
    {
    case '\r':
        // terminate the msg and reset the msg ptr. then send
        // it to the handler for processing.
        *msg_ptr = '\0';
        Serial.print("\r\n");
        cmd_parse((char *)msg);
        msg_ptr = msg;
        break;
    case '\b':
        // backspace 
        if (msg_ptr > msg)
        {
            Serial.write(c);
            msg_ptr--;
        }
        break;
    case '\0':
        // do noting 
        break;
    default:
        // normal character entered. add it to the buffer
        Serial.write(c);
        *msg_ptr++ = c;
        break;
    }
}
Ejemplo n.º 5
0
void eng_handle_cmd(const char* cmdstr)
{
    t_uicmd*  p_uicmd;
    const int cmd_id = cmd_parse(cmdstr, &p_uicmd);

    switch (cmd_id) {
        case UICMD_UCI:
            eng_handle_uci((t_uicmd_uci*)p_uicmd);
            break;

        case UICMD_DEBUG:
            eng_handle_debug((t_uicmd_debug*)p_uicmd);
            break;

        case UICMD_ISREADY:
            eng_handle_isready((t_uicmd_isready*)p_uicmd);
            break;

        case UICMD_SETOPTION:
            eng_handle_setoption((t_uicmd_setoption*)p_uicmd);
            break;

        case UICMD_REGISTER:
            eng_handle_register((t_uicmd_register*)p_uicmd);
            break;

        case UICMD_UCINEWGAME:
            eng_handle_ucinewgame((t_uicmd_ucinewgame*)p_uicmd);
            break;

        case UICMD_POSITION:
            eng_handle_position((t_uicmd_position*)p_uicmd);
            break;

        case UICMD_GO:
            eng_handle_go((t_uicmd_go*)p_uicmd);
            break;

        case UICMD_STOP:
            eng_handle_stop((t_uicmd_stop*)p_uicmd);
            break;

        case UICMD_PONDERHIT:
            eng_handle_ponderhit((t_uicmd_ponderhit*)p_uicmd);
            break;

        case UICMD_QUIT:
            eng_handle_quit((t_uicmd_quit*)p_uicmd);
            break;

        default:
            io_println("Invalid command");
            /* Do nothing */
            break;
    }

    if (p_uicmd != NULL) free(p_uicmd);
}
Ejemplo n.º 6
0
static int find_file () {
    struct parsed_cmd   *parsed_get;

        if (cmd_parse_failed ((parsed_get = cmd_parse (r->cmd, NULL))))
            return -1;

        /*
         *  Checking whether the arguments are valid.  If they are, retrieves the
         *  data (stored in the cache) about the file to be downloaded
         */
        if (parsed_get->argc == 1) {
            if (client_send (r->client,
                                " < get: you need to specify a key\n") < 0)
                log_failure (log_file, "cr_get: client_send () failed");
            goto error;
        }
        else {
            if (strlen (parsed_get->argv[1]) != FILE_KEY_SIZE) {
                if (client_send (r->client,
                                    " < get: hash size is not good, man\n") < 0)
                    log_failure (log_file, "cr_get: client_send () failed");
                goto error;
            }
            else {
                sem_wait (&file_cache_lock);
                file_to_dl = file_cache_get_by_key (file_cache, parsed_get->argv[1]);
                sem_post (&file_cache_lock);
                if (!file_to_dl) {
                    if (client_send (r->client,
                                    " < get: key not in cache, please list\n") < 0)
                        log_failure (log_file, "cr_get: client_send () failed");
                    goto error;
                }
                sprintf (answer,
                        "< get : seeder is %s:%d\n",
                        file_to_dl->seeders->ip,
                        file_to_dl->seeders->port);
                if (client_send (r->client, answer) < 0) {
                    log_failure (log_file, "cr_get: client_send () failed");
                    goto error;
                }
            }
        }
        
        cmd_parse_free (parsed_get);

        if (client_send (r->client, answer) < 0) {
            log_failure (log_file, "cr_get: client_send () failed");
            return -1;
        }

        return 0;

    error:
        if (parsed_get)
            cmd_parse_free (parsed_get);
        return -1;
    }
Ejemplo n.º 7
0
int main(void)
{
    // board setup stuff
    led_init();
    uart_init();
    floppy_low_init();
    sdpin_init();
    spi_low_cs_init();
    spi_low_mst_init();
    //timer_init();

    // say hello
    uart_send_string((u08 *)"--- dfx-sampler sam7x/SPI ---");
    uart_send_crlf();

    // do initial setup
    rtc_init();
    memory_init();
    floppy_select_on();
    track_init();
    floppy_select_off();
    net_init();

    // print current RTC
    uart_send_string((u08 *)"rtc:  ");
    uart_send_string((u08 *)rtc_get_time_str());
    uart_send_crlf();

    // show network info
    net_info();

    while(1) {
        uart_send_string((u08 *)"> ");
        
        led_green(1);
        
        // get next command via SPI
        u08 *cmd;
        u08 len = cmd_uart_get_next(&cmd);

        led_green(0);
        
        if(len>0) {
            u08 result[CMD_MAX_SIZE];
            u08 res_size = CMD_MAX_SIZE;
            
            // parse and execute command
            cmd_parse(len, cmd, &res_size, result);
            
            // report result
            if(res_size > 0) {
                uart_send_data(result, res_size);
                uart_send_crlf();
            }
        }
    }
}
Ejemplo n.º 8
0
int main()
{
	int err = 0,i,j,k;
	char s[50];
	char * *cmd_list;
	int no_cmd;
	char * * * argv_list;
	int * argc_list;
	printf("\n v_shell-> ");
		gets(s);

	do
	{		
		no_cmd = 0;
		argv_list = cmd_parse(s,&no_cmd,&argc_list);
		
		//printf("%d",no_cmd);
		/*if(err)
		{	printf("Parsing error...");
			exit(1);
		}
		/*for(i =0; i <= no_cmd;i++)
		{
			printf("%d: ",argc_list[i]);
			for(j=0;j<=argc_list[i];j++)
			{
				printf(" %s \n",argv_list[i][j]);
			}

		}*/

		err = cmd_executor(no_cmd,argv_list,argc_list);
//		if (err)
//		{	printf("Execution Error...");
//			exit(1);
//		}
		
		//clear memory of argv & argc		
		for(i =0; i < no_cmd;i++)
		{
			for(j=0;j<=argc_list[i];j++)
			{
				free(argv_list[i][j]);
			}
			free(argv_list[i]);
			//free(argc_list[i]);
		}
		free(argv_list);
		free(argc_list);

		printf("\n v_shell-> ");
		gets(s);

	}while(strcmp(s,"exit")!=0 && strcmp(s,"Exit") != 0 && strcmp(s,"EXIT") != 0);
	return 0;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[]) {
	params_t par;
	double timer_scan;
	gk_clearwctimer(par.timer_global);
	gk_clearwctimer(par.timer_1);
	gk_clearwctimer(par.timer_2);
	gk_clearwctimer(par.timer_3);
	gk_clearwctimer(par.timer_4);
	gk_startwctimer(par.timer_global);
	int k;
	printf("\nScan - OMP_Scan\n");
	gk_startwctimer(par.timer_4);
	cmd_parse(argc, argv, &par);
	gk_stopwctimer(par.timer_4);

	memcpy(par.a,par.b,(par.nalloc + 1)*sizeof(int));
	OMP_Scan(&par);
	timer_scan=par.timer_2;

	for (k = 0; k < EXATRA; ++k) {
		memcpy(par.a,par.b,(par.nalloc + 1)*sizeof(int));
		OMP_Scan(&par);
		timer_scan=MIN(timer_scan,par.timer_2);
	}
	par.timer_2=timer_scan;

	for (k = 0; k < EXATRA; ++k) {
		Scan_Serial_Seq(&par);
	}


	WriteOut(&par);

	for (k = 0; k < EXATRA; ++k) {
		OMP_Sscan(&par);
	}


	gk_stopwctimer(par.timer_global);

	printf("  wclock         (sec): \t%.8lf\n",
			gk_getwctimer(par.timer_global));
	printf("  timer4  Init   (sec): \t%.8lf\n", gk_getwctimer(par.timer_4));
	printf("  timer3  Serial (sec) on %d runs: \t%.8lf\n", EXATRA,
			gk_getwctimer(par.timer_3) );
	printf("  timer2  Scan   (sec) on %d runs: \t%.8lf\n", EXATRA,
			gk_getwctimer(par.timer_2) );
	printf("  timer1  Sscan  (sec) on %d runs: \t%.8lf\n", EXATRA,
			gk_getwctimer(par.timer_1) );
	cleanup(&par);
	return 0;
}
Ejemplo n.º 10
0
/* ======
 * con_update - Check for new console input. If it's there, use it.
 * ======
 */
void con_update(void)
{
#if 0
    char buffer[CMD_MAX_LENGTH], *t;

    /* Check for new input */
    t = fgets(buffer, sizeof(buffer), stdin);
    if (t == NULL) return;

    cmd_parse(buffer);
#endif
    con_draw();
}
Ejemplo n.º 11
0
static sw_error_t
cmd_run_one(char *cmd_str)
{
    a_uint32_t *arg_list;
    int cmd_index = 0, cmd_index_sub = 0;

    if ((arg_list = cmd_parse(cmd_str, &cmd_index, &cmd_index_sub)) != NULL)
    {
        cmd_exec(arg_list, cmd_index, cmd_index_sub);
    }

    return SW_OK;
}
Ejemplo n.º 12
0
void Shell::run(void)
{
    int argc = 0;
    int bytes = _read(str, sizeof(str));

    if (bytes)
    {
        //_write(str, strlen(str));
        argc = cmd_prepare(str, bytes);
        cmd_parse(argc, argv);
        memset(str, 0, sizeof(str));
        uart_prompt();
    }
}
Ejemplo n.º 13
0
static void loop()
{
	char *line;
	char *argv[SHELL_ARGS_MAX_NUM];
	int argc;

	while (!is_exit) {
		line = readline(CONFIG_PROMPT);
		argc = cmd_parse(line, argv, SHELL_ARGS_MAX_NUM);
		if (argc <= 0)
			continue;
		cmd_exec(argc, argv);
	}
}
Ejemplo n.º 14
0
//TODO
static char *split_tab(const char *prefix,
    char **p_pre_word, char **p_tails)
{
    size_t len = 0;
    size_t pre_len = 0;
    char *endp = NULL;
    char *tmp_word = NULL;
    char *pre_word  = NULL;
    char *tails     =  NULL;

    if (prefix != NULL) {
        pre_len = strlen(prefix);
    }

    //prefix -> pre_word
    if ((pre_word = malloc(pre_len+2)) == NULL) { 
        fprintf(stderr, "func(%s), line(%d): malloc failed.\n",
                __FUNCTION__, (int)__LINE__);
        return NULL;
    }
    memset(pre_word, 0, pre_len+1);
    strncpy(pre_word, prefix, pre_len);

    if ((endp = strrchr(pre_word, CHR_TAB)) != NULL) {
        tails = rpl_strdup(endp+1);
        endp[0] = '\0';
    }

    str_rm_char(pre_word, CHR_TAB);
    len = strlen(pre_word);
    pre_word[len] = CHR_EOL;
    pre_word[len+1] = '\0';

    //cmd_parse
    inbuf_preparse(pre_word);
    tmp_word = cmd_parse(pre_word);
    free(pre_word);
    pre_word = tmp_word;

    tmp_word = NULL;
    len = strlen(pre_word);
    pre_word[len] = '\0';

    (*p_pre_word) = pre_word;
    (*p_tails)    = tails;

    pre_word = tails = NULL;
    return (*p_pre_word);
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
	CmdlineParser cmd_parse(lpstrCmdLine);
	std::wstring server_start_event_name = cmd_parse.GetValueByKey(L"crash_server");
	if (!server_start_event_name.empty())
	{
		GuardProcess::GuardProcessMain(server_start_event_name);
		return 0;
	}
	else
	{
		WorkProcess::WorkProcessMain(hInstance);
		return 0;
	}
}
Ejemplo n.º 16
0
static void handle_exec_cmd(__unused struct tmate_session *session,
			    struct tmate_unpacker *uk)
{
	struct cmd_q *cmd_q;
	struct cmd_list *cmdlist;
	struct cmd *cmd;
	char *cause;
	u_int i;
	unsigned int argc;
	char **argv;

	int client_id = unpack_int(uk);

	argc = uk->argc;
	argv = xmalloc(sizeof(char *) * argc);
	for (i = 0; i < argc; i++)
		argv[i] = unpack_string(uk);

	cmd = cmd_parse(argc, argv, NULL, 0, &cause);
	if (!cmd) {
		tmate_failed_cmd(client_id, cause);
		free(cause);
		goto out;
	}

	cmdlist = xcalloc(1, sizeof *cmdlist);
	cmdlist->references = 1;
	TAILQ_INIT(&cmdlist->list);
	TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);

	cmd_q = cmdq_new(NULL);
	cmdq_run(cmd_q, cmdlist, NULL);
	cmd_list_free(cmdlist);
	cmdq_free(cmd_q);

	/* error messages land in cfg_causes */
	for (i = 0; i < cfg_ncauses; i++) {
		tmate_failed_cmd(client_id, cfg_causes[i]);
		free(cfg_causes[i]);
	}

	free(cfg_causes);
	cfg_causes = NULL;
	cfg_ncauses = 0;

out:
	cmd_free_argv(argc, argv);
}
Ejemplo n.º 17
0
void shell_help(void)
{
	uint8_t count = 0 ;
	uint8_t idx ;
	int8_t ret ;
	count = input(usart_rx_buf,0xFF);
	if(!count)
	{
		return ;
	}

#if 1
	ret = cmd_parse(usart_rx_buf,&count);
	if(ret != ARG_OK)
	{
		printf("parse arg error %d\n",ret);
//		printf("%x %s %x %x\n",usart_rx_buf[0],usart_rx_buf,usart_rx_buf[strlen(usart_rx_buf)-2],usart_rx_buf[strlen(usart_rx_buf)-1]);
		return ;
	}

#endif
	
	if(usart_dbg == 1)
	{
		printf("recv %s\n",usart_rx_buf);
		for(ret = 0 ; ret < count ; ret ++)
		{
			printf("%d : %s\n",ret+1,cmd_pointer[ret]);
		}
	}

	count = sizeof(shell_cmd)/sizeof(cmd_typedef);
	for(idx = 0 ; idx < count ; idx++)
	{
	//	printf("cmp str :%s,%s,%d,%d\n",shell_cmd[idx].fun_str,cmd_pointer[0],strlen(cmd_pointer[0]),strlen(shell_cmd[idx].fun_str));
		
		if(!strcmp(cmd_pointer[0],shell_cmd[idx].fun_str))
		{
			shell_cmd[idx].function();
			return  ;
		}
	}

	printf("unfind\n");
}	
Ejemplo n.º 18
0
/* Shell Mode */
int shell_mode()
{
	//Call interactive mode shell
	
//	printf("SHELL MODE\n");
	struct command execcmd;
	struct command* cmd = &execcmd;

	//Print the shell prompt, accept the command and check for the length
	while(1){   //strcmp(cmd->type, "exit") != 0
		cmd = sh_prompt(cmd);

		//If command length is correct, tokenize and parse the commands
		cmd = cmd_parse(cmd);
		
		char* home = getenv("HOME");
		//If no command is found in exec_args[0] then wrong command is entered
		if(cmd->opt_cnt != 0){
			if(cmd->cmd_flag == 0)
				error(4);
			else if( strcmp(cmd->type, "exit") == 0)
				exit(0);
			else if (strcmp(cmd->type, "cd") == 0)
			{
				int derror =0;
				if(cmd->opt_cnt ==1)
					derror = chdir(home);
				else
					derror = chdir(cmd ->eargv[1]);
				if(derror <0)
					error(5);
			}
			else{
				//If command present, then parse the options
				int ret_e = exec_cmd(cmd);
				if (ret_e != 0)
					error(6);
			}
		}

	}

	return 0;
}
Ejemplo n.º 19
0
void rx()
{
    U8 i, c, ep_num, len;
    usb_pcb_t *pcb = usb_pcb_get();

    // get the ep number of any endpoint with pending rx data
    if ((ep_num = usb_buf_data_pending(DIR_OUT)) != 0xFF)
    {
        // get the length of data in the OUT buffer
        len = pcb->fifo[ep_num].len;

        // read out the data in the buffer and echo it back to the host. 
        for (i=0; i<len; i++)
        {
            c = usb_buf_read(ep_num);

            switch (c)
            {
            case '\r':
                // terminate the msg and reset the msg ptr. then send
                // it to the handler for processing.
                *msg_ptr = '\0';
                printf_P(PSTR("\n\r"));
                cmd_parse((char *)msg);
                msg_ptr = msg;
                break;
            
            case '\b':
                usb_buf_write(EP_1, c);
                if (msg_ptr > msg)
                {
                    msg_ptr--;
                }
                break;
            
            default:
                usb_buf_write(EP_1, c);
                *msg_ptr++ = c;
                break;
            }
        }
        pcb->flags |= (1 << TX_DATA_AVAIL);
    }
}
Ejemplo n.º 20
0
void shell_process(uint8_t *shell_str,uint8_t count)
{
	uint8_t idx ;
	int8_t ret ;
//	count = usart_get_buff(usart_rx_buf,USART_BUFF_SIZE);
	if(!count || (0 == shell_str))
	{
		return ;
	}

#if 1
	ret = cmd_parse(shell_str,&count);
	if(ret != ARG_OK)
	{
		printf("parse arg error %d\n",ret);
//		printf("%x %s %x %x\n",usart_rx_buf[0],usart_rx_buf,usart_rx_buf[strlen(usart_rx_buf)-2],usart_rx_buf[strlen(usart_rx_buf)-1]);
		return ;
	}

#endif
	
	if(usart_dbg == 1)
	{
		printf("recv %s\n",shell_str);
		for(ret = 0 ; ret < count ; ret ++)
		{
			printf("%d : %s\n",ret+1,cmd_pointer[ret]);
		}
	}

	count = sizeof(shell_cmd)/sizeof(cmd_typedef);
	for(idx = 0 ; idx < count ; idx++)
	{
	//	printf("cmp str :%s,%s,%d,%d\n",shell_cmd[idx].fun_str,cmd_pointer[0],strlen(cmd_pointer[0]),strlen(shell_cmd[idx].fun_str));
		
		if(!strcmp(cmd_pointer[0],shell_cmd[idx].fun_str))
		{
			shell_cmd[idx].function();
			return  ;
		}
	}

	printf("\r\n");
}	
Ejemplo n.º 21
0
//================
static char *getcmd(char *buf, char **prdlinecmd, const char *rl_name)
{
    char *tmpbuf = NULL;
    int len = 0;

    len = strlen(buf);

    str_rm_char(buf, CHR_BELL);

    if ((tmpbuf = malloc(len+1)) == NULL) {
        fprintf(stderr, "malloc error(line: %d, func: %s)",
            __LINE__, __FUNCTION__);
        return NULL;
    }
    
    memset(tmpbuf, 0, len+1);
    strncpy(tmpbuf, buf, len);
    tmpbuf[len] = '\0';

    inbuf_preparse(tmpbuf);
    cmd_preparse(tmpbuf);

    len = strlen(tmpbuf);
    tmpbuf[len-1] = CHR_EOL;
    tmpbuf[len] = '\0';


    (*prdlinecmd) = cmd_parse(tmpbuf);
    //dbg("\ncmd_parse:\n inbuf:(%s)\n rdlinecmd=(%s)\n", tmpbuf, *prdlinecmd);
 
    (*prdlinecmd)[strlen(*prdlinecmd)] = '\0';

    free(tmpbuf);
    tmpbuf = NULL;

    //free rdlinecmd, inbuf at EVT_WRITE side
    dbg("EVT_RD: ... done.\n");

    return (*prdlinecmd);
}
Ejemplo n.º 22
0
void cmd_handler()
{
    unsigned char c = 0x00;
    if(HAL_OK ==  HAL_UART_Receive(&huart1, &c, 1, 100))
    {
        switch (c)
        {
        case '\r':
            // terminate the msg and reset the msg ptr. then send
            // it to the handler for processing.
            *msg_ptr = '\0';
            tfp_printf("\r\n");
            cmd_parse((char *)msg);
            msg_ptr = msg;
            break;

        case '\b':
            // backspace
            tfp_printf("%c",c);
            if (msg_ptr > msg)
            {
                msg_ptr--;
            }
            break;

        default:
            // normal character entered. add it to the buffer
            tfp_printf("%c",c);
            *msg_ptr++ = c;
            break;
        }
    }
    else
    {
        tfp_printf("%s","timeout occurred");
        cmd_display_prompt();
    }
}
Ejemplo n.º 23
0
int main(void)
{
    cmd_init();

    cmd_register_array(custom_shell_table, ARRAY_SIZE(custom_shell_table));
    
    while(1)
    {
        memset(in_buf, 0, MAX_CMD_LEN);
        buf_idx = 0;
        printf("%s", CMD_PROMPT);

        while ((in_buf[buf_idx++] = getchar()) != '\n');
        //printf("%s", in_buf);

        buf_idx --;
        in_buf[buf_idx++] = '\r';
        in_buf[buf_idx++] = '\n';

        cmd_parse((uint8_t *)in_buf);
    }

    return 0;
}
Ejemplo n.º 24
0
int main(int argc, char *argv[]) {
	params_t par;
	double timer_sscan;
	Tclear(par.timer_global);
	Tclear(par.timer_1);
	Tclear(par.timer_2);
	Tclear(par.timer_3);
	Tclear(par.timer_4);
	Tstart(par.timer_global);
	int k;
	printf("\nScan - OMP_Sscan\n");
	Tstart(par.timer_4);
	cmd_parse(argc, argv, &par);
	Tstop(par.timer_4);

	OMP_Sscan(&par);
	timer_sscan = par.timer_1;
	for (k = 0; k < EXTRA; ++k) {
		memcpy(par.a, par.b, sizeof(int) * (1 + par.nalloc));
		memcpy(par.f, par.fb, (1 + par.nalloc) * (sizeof(char)));
		OMP_Sscan(&par);
		timer_sscan = MIN(par.timer_1,timer_sscan);
	}
	par.timer_1 = timer_sscan;
//	PrintAll(&par);
	WriteOut(&par);
	Tstop(par.timer_global);


	printf("  wclock         (sec): \t%.8lf\n", Tget(par.timer_global));
	printf("  timer4  Init   (sec): \t%.8lf\n", Tget(par.timer_4));
	printf("  timer1  Sscan  (sec) on %d runs: \t%.8lf\n", 1 + EXTRA,
			Tget(par.timer_1));
	cleanup(&par);
	return 0;
}
Ejemplo n.º 25
0
void sysproc_hotkeys(void)
{
	char *newPid, *newPrio;
	int pid, prio;
	
    msg_envelope_t *msg;
	cmd_register("%C");

    while (1) {
        msg = receive_message(NULL);
				if (msg->header.type == CMD_NOTIFY_MSG) {
					newPid = &msg->data[3];
					newPrio = cmd_parse(newPid);
					pid = atoi(newPid);
					prio = atoi(newPrio);
					if (proc_is_valid_pid(pid) && prio >= HIGH && prio <= LOWEST) {
						set_priority(prio, pid);
					}
				} else {
					switch (msg->header.ctrl) {
							case 'v': {
									proc_print(msg, RDY);
							} break;

							case 'x': {
									proc_print(msg, BLOCKED);
							} break;
							
							case 'c': {
									proc_print(msg, MSG_BLOCKED);
							} break;
					}
				}
        free_message(msg);
    }
}
Ejemplo n.º 26
0
/* Accepts messages and routes them to their respective registered processes */
void sysproc_command_decoder(void)
{
	msg_envelope_t *msg;
	int message_target;
    int source;
	
	while (1) 
	{
		msg = receive_message(&source);
        
        switch (msg->header.type) {
            case CMD_REGISTER_MSG: {
                cmd_put(msg->data, source);
                free_message(msg);
            } break;
            
            case CMD_NOTIFY_MSG: {
                cmd_parse(msg->data);
                message_target = cmd_get(msg->data);
                send_message(message_target, msg);
            } break;
        }
	}
}
Ejemplo n.º 27
0
void launcher (char *commbuff, FlowSource_t *FlowSource, char *process, int expire) {
FlowSource_t	*fs;
struct sigaction act;
char 		*args[MAXARGS];
int 		pid, stat;
srecord_t	*InfoRecord;

	InfoRecord = (srecord_t *)commbuff;

	syslog(LOG_INFO, "Launcher: Startup. auto-expire %s", expire ? "enabled" : "off" );
	done = launch = child_exit = 0;

	// process may be NULL, if we only expire data files
	if ( process ) {
		char 		*cmd = NULL;
		srecord_t	TestRecord;
		// check for valid command expansion
		strncpy(TestRecord.fname, "test", FNAME_SIZE-1);
		TestRecord.fname[FNAME_SIZE-1] = 0;
		strncpy(TestRecord.tstring, "200407110845", 15);	
		TestRecord.tstring[15] = 0;
		TestRecord.tstamp = 1;

		fs = FlowSource;
		while ( fs ) {
			cmd = cmd_expand(&TestRecord, fs->Ident, fs->datadir, process);
			if ( cmd == NULL ) {
				syslog(LOG_ERR, "Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process);
				exit(255);
			}

			fs = fs->next;
		}
	}

	/* Signal handling */
	memset((void *)&act,0,sizeof(struct sigaction));
	act.sa_handler = SignalHandler;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	sigaction(SIGCHLD, &act, NULL);	// child process terminated
	sigaction(SIGTERM, &act, NULL);	// we are done
	sigaction(SIGINT, &act, NULL);	// we are done
	sigaction(SIGHUP, &act, NULL);	// run command

	while ( !done ) {
		// sleep until we get signaled
		syslog(LOG_DEBUG, "Launcher: Sleeping");
		select(0, NULL, NULL, NULL, NULL);
		syslog(LOG_DEBUG, "Launcher: Wakeup");
		if ( launch ) {	// SIGHUP
			launch = 0;

			if ( process ) {
				char 		*cmd = NULL;

				fs = FlowSource;
				while ( fs ) {
					// Expand % placeholders
					cmd = cmd_expand(InfoRecord, fs->Ident, fs->datadir, process);
					if ( cmd == NULL ) {
						syslog(LOG_ERR, "Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process);
						continue;
					}
					// printf("Launcher: run command: '%s'\n", cmd);
					syslog(LOG_DEBUG, "Launcher: ident: %s run command: '%s'", fs->Ident, cmd);

					// prepare args array
					cmd_parse(cmd, args);
					if ( args[0] )
						cmd_execute(args);

					// do not flood the system with new processes
					sleep(1);
					// else cmd_parse already reported the error
					free(cmd);
					fs = fs->next;
				}
			}

			fs = FlowSource;
			while ( fs ) {
				if ( expire ) 
					do_expire(fs->datadir);
				fs = fs->next;
			}
		}
		if ( child_exit ) {
			syslog(LOG_INFO, "laucher child exit %d childs.", child_exit);
			while ( (pid = waitpid (-1, &stat, WNOHANG)) > 0  ) {
				if ( WIFEXITED(stat) ) {
					syslog(LOG_DEBUG, "launcher child %i exit status: %i", pid, WEXITSTATUS(stat));
				}
				if (  WIFSIGNALED(stat) ) {
					syslog(LOG_WARNING, "laucher child %i died due to signal %i", pid, WTERMSIG(stat));
				}

				child_exit--;
			}
			syslog(LOG_INFO, "laucher waiting childs done. %d childs", child_exit);
			child_exit = 0;
		}
		if ( done ) {
			syslog(LOG_INFO, "Launcher: Terminating.");
		}
	}

	waitpid (-1, &stat, 0);

	// we are done
	syslog(LOG_INFO, "Launcher: exit.");

} // End of launcher
Ejemplo n.º 28
0
void*
daemon_request_file (void* arg) {
    struct daemon_request   *r;
    struct parsed_cmd       *pcmd;
    struct client           *lister;
    char                    error_buffer[BUFFSIZE];

    r = (struct daemon_request *) arg;
    if (!r)
        return NULL;

    /*
     * First, did someone asked "list"?
     */
    lister = list_client;
    if (!lister)
        return NULL;

    /*
     * cmd is supposedly:
     * file NAME KEY SIZE IP:PORT
     *  0    1    2   3      4
     */
    if (cmd_parse_failed ((pcmd = cmd_parse (r->cmd, NULL)))) {
        sprintf (error_buffer,
                 "error %s: Command parse failed",
                 __FUNCTION__);
        daemon_send (r->daemon, error_buffer);
        return NULL;
    }
    if (pcmd->argc < 5) {
        cmd_parse_free (pcmd);
        sprintf (error_buffer,
                 "error %s: Invalid number of arguments",
                 __FUNCTION__);
        daemon_send (r->daemon, error_buffer);
        return NULL;
    }

    /*
     * Hackety hack:
     * IP:PORT\0   ->   IP\0PORT\0
     */
    char *port = strchr (pcmd->argv[4], ':');
    *port = '\0';
    port++;
    file_cache = file_cache_add (file_cache,
                                pcmd->argv[1],
                                pcmd->argv[2],
                                atol (pcmd->argv[3]),
                                pcmd->argv[4],
                                atoi (port));
    cmd_parse_free (pcmd);
    char *answer = (char *)malloc ((strlen (r->cmd) + 5) * sizeof (char));
    sprintf (answer,
            " < %s\n",
            r->cmd);
    client_send (lister, answer);
    free (answer);

    return NULL;
}
Ejemplo n.º 29
0
/* === entry point === */
int main(int argc, char** argv)
{
	char cmdbuf[4096];
	tsk_buffer_t* buffer = tsk_null;
	cmd_t* cmd = tsk_null;
	tsk_bool_t comment = tsk_false;
	int ret;
	int i, index;
	const char* start = tsk_null, *end = tsk_null;

	int a = 32 | 1 | 2;

	/* Copyright */
	printf("Doubango Project (tinyDEMO)\nCopyright (C) 2009 - 2013 Mamadou Diop \n\n");

	/* Initialize Network Layer ==> Mandatory */
	tnet_startup();
	/* Initialize Doubango Audio/Video Framework ==> will register all plugins(codecs and sessions) 
	* Not mandatory if you have your own plugins*/
	tdav_init();

	/* Print Usage */
	//cmd_print_help();

	/* create user's ctx */
	if(!(ctx = ctx_create()) || !ctx->stack){
		TSK_DEBUG_ERROR("Failed to create user's ctx.");
		goto bail;
	}

	/* create new buffer */
	if(!(buffer = tsk_buffer_create_null())){
		TSK_DEBUG_ERROR("Failed to create new buffer.");
		goto bail;
	}

	/* initial args */
	for(i=1 /* index zero contains the exe path */, index=0; i<argc && argv[i]; i++){
		if(index){
			tsk_buffer_append(buffer, " ", 1);
		}
		tsk_buffer_append(buffer, argv[i], tsk_strlen(argv[i]));
	}
	
	/* If initial args ==> parse it now */
	if(buffer->size){
		TSK_DEBUG_INFO("Initial command-line: %s", buffer->data);
		goto init_buffer;
	}

	/* always use fgets() instead of gets. gets() is considered to be unsafe.(Android and Mac OS X will warn) */
	while(fgets(cmdbuf, sizeof(cmdbuf), stdin)){
		TSK_DEBUG_INFO("Command-Line: %s", cmdbuf);
		tsk_buffer_cleanup(buffer); /* cannot read from console while executing scenario */
		tsk_buffer_append(buffer, cmdbuf, tsk_strlen(cmdbuf));
init_buffer:
		start = buffer->data;
		//start = trim(start);
		end = start + buffer->size;
		if(start >= end){
			TSK_DEBUG_INFO("Empty buffer");
			continue;
		}
parse_buffer:
		TSK_OBJECT_SAFE_FREE(cmd); /* Free old value */
		cmd = cmd_parse(start, (end-start), &comment, ctx->params);
		if(cmd){
			if(comment || cmd->type == cmd_none){
				goto nex_line;
			}
		}
		else{
			continue;
		}

		/* Load from scenario file? */
		if(cmd->type == cmd_scenario){
			FILE* file;
			const opt_t* opt;
			tsk_size_t read = 0;
			tsk_bool_t rm_lf = tsk_false;
			if((opt = opt_get_by_type(cmd->opts, opt_path)) && !tsk_strnullORempty(opt->value)){ /* --path option */
				if((file = fopen(opt->value, "r"))){
					memset(cmdbuf, '\0', sizeof(cmdbuf)), cmdbuf[0] = '\n';
					read = fread(cmdbuf+1, sizeof(uint8_t), sizeof(cmdbuf)-1, file);
					fclose(file), file = tsk_null;

					if(read == 0){
						TSK_DEBUG_ERROR("[%s] is empty.", opt->value);
						goto nex_line;
					}
					else if(read == sizeof(cmdbuf)-1){
						TSK_DEBUG_ERROR("Buffer too short.");
						
						goto nex_line;
					}
					read++; /* \n */
					/* repplace all '\' with spaces (easier than handling that in the ragel file) */
					for(i=0; ((tsk_size_t)i)<read; i++){
						if(cmdbuf[i] == '\\'){
							cmdbuf[i] = ' ';
							rm_lf = tsk_true;
						}
						else if(rm_lf && cmdbuf[i] == '\n'){
							cmdbuf[i] = ' ';
							rm_lf = tsk_false;
						}
					}
					cmdbuf[read] = '\n';
					
					/* insert embedded scenario */
					if((index = tsk_strindexOf(start, (end-start), "\n")) == -1){ /* ++sn line */
						index = buffer->size;
					}
					else{
						index += (start - ((const char*)buffer->data));
					}
				
					if(tsk_buffer_insert(buffer, index, cmdbuf, read)){
						continue;
					}
					else{
						start = ((const char*)buffer->data) + index; // because insert use realloc()
						end = (((const char*)buffer->data) + buffer->size);
						goto nex_line;
					}
				}
				else{
					TSK_DEBUG_ERROR("Failed to open scenario-file [%s].", opt->value);
					goto nex_line;
				}
				continue;
			}
			else{
				TSK_DEBUG_ERROR("++scenario command must have --path option.");
				continue;
			}
		}
		
		/* execute current command */
		switch(cmd->type){
			case cmd_exit:
					TSK_DEBUG_INFO("Exit/Quit");
					goto bail;
			default:
				ret = execute(cmd);
				break;
		}

		/* next line */
nex_line:
		if((index = tsk_strindexOf(start, (end - start), "\n")) !=-1){
			start += index;
			while((start < end) && isspace(*start)){
				start ++;
			}
			if((start + 2/*++*/) < end){
				goto parse_buffer; /* next line */
			}
			else{
				continue; /* wait for new commands */
			}
		}
	} /* while(buffer) */


bail:
	
	/* Free current command */
	TSK_OBJECT_SAFE_FREE(cmd);
	/* Free buffer */
	TSK_OBJECT_SAFE_FREE(buffer);
	/* Destroy the user's ctx */
	TSK_OBJECT_SAFE_FREE(ctx);
	/* Deinitialize Doubango Audio/Video Framework ==> will unregister all plugins(codecs and sessions) 
	* Not mandatory */
	tdav_init();
	/* Uninitilize Network Layer */
	tnet_cleanup();

#if ANDROID
	exit(0);
#endif
	return 0;
}
Ejemplo n.º 30
0
void con_parse(ConsoleInformation *console, char *command)
{
    cmd_parse(command);
}