Example #1
0
int put_avr_firmware(char *firmware_filename)
{
    int r;
    
    r = do_command(CMD_AVR_I2CRST, bigbuf, sizeof(bigbuf));
    if (r < 0) {
	printf("do_twiboot: CMD_AVR_I2CRST: failed, but may continue...\n");
	/* no return, because in bootloader mode, 
	 AVR doesn't need I2C reset */
	/* return -1; */
    }
    usleep(100*1000L);

    if (rpi_rev == 1) {
	r = do_command(CMD_TWIBOOT_I2CREV1, bigbuf, sizeof(bigbuf));
    }
    else if (rpi_rev == 2) {
	r = do_command(CMD_TWIBOOT_I2CREV2, bigbuf, sizeof(bigbuf));
    }
    else {
	printf("put_avr_firmware: rpi_rev incorrectly, or not set\n");
    }
    
    /* DO STUFF TO CHECK twiboot SUCCESS/FAILURE FROM bigbuf*/
    
    return r;
}
Example #2
0
/*
 * run /etc/rc. The environment is passed to the script, so the RC environment
 * variable can be used to decide what to do. RC may be set from LILO.
 */
static int do_rc(void)
{
	int rc;

	rc = do_command(_PATH_BSHELL, _PATH_RC, 1);
	if (rc)
		return(rc);
#ifdef CONFIG_USER_INIT_RUN_FIREWALL
	rc = do_command(_PATH_FIREWALL, "-i", 1);
	if (rc)
		err(_PATH_FIREWALL " failed!");
#endif
#ifdef CONFIG_USER_FLATFSD_FLATFSD
	rc = do_command(_PATH_BSHELL, _PATH_CONFIGRC, 1);
	if (rc)
		err(_PATH_CONFIGRC " failed!");
#endif
#ifdef CONFIG_USER_INIT_RUN_FIREWALL
	rc = do_command(_PATH_FIREWALL, NULL, 0);
	if (rc)
		err(_PATH_FIREWALL " failed!");
#endif
#ifdef INCLUDE_TIMEZONE
	/* We read the timezone file here, because the flat file system
	 * has probably been created by now.
	 */
	set_tz();
#endif
	return(0);
}
Example #3
0
File: main.c Project: sagara-/lhasa
int main(int argc, char *argv[])
{
	ProgramMode mode;
	LHAOptions options;

#ifdef TEST_BUILD
	// When running tests, give output to stdout in binary mode;
	// on Windows, this gives the expected output (which was
	// constructed for Unix):

	lha_arch_set_binary(stdout);
#endif

	// Parse the command line options and run command.
	// As a shortcut, a single argument can be provided to list the
	// contents of an archive ("lha foo.lzh" == "lha l foo.lzh").

	init_options(&options);

	if (argc >= 3 && parse_command_line(argv[1], &mode, &options)) {
		return !do_command(mode, argv[2], &options,
		                   argv + 3, argc - 3);
	} else if (argc == 2) {
		return !do_command(MODE_LIST, argv[1], &options, NULL, 0);
	} else {
		help_page(argv[0]);
		return 0;
	}
}
Example #4
0
void test3(int fd) {
  /* encrypt */
  do_command(fd, (unsigned char*) "CMDencrypt#", "123456test");

  /* decrypt */
  do_command(fd, (unsigned char*) "CMDdecrypt#", "abcdwt6'16");
}
Example #5
0
void execute(WINDOW* w, ToxWindow *self, Tox *m, char *cmd, int mode)
{
    if (string_is_empty(cmd))
        return;

    char args[MAX_NUM_ARGS][MAX_STR_SIZE] = {0};
    int num_args = parse_command(w, cmd, args);

    if (num_args == -1)
        return;

    /* Try to match input command to command functions. If non-global command mode is specified, 
       try specified mode's commands first, then upon failure try global commands. 

       Note: Global commands must come last in case of duplicate command names */
    switch (mode) {
    case CHAT_COMMAND_MODE:
        if (do_command(w, self, m, num_args, CHAT_NUM_COMMANDS, chat_commands, args) == 0)
            return;
        break;

    case GROUPCHAT_COMMAND_MODE:
        break;
    }

    if (do_command(w, self, m, num_args, GLOBAL_NUM_COMMANDS, global_commands, args) == 0)
        return;

    wprintw(w, "Invalid command.\n");
}
Example #6
0
void execute(WINDOW *w, ToxWindow *self, Tox *m, const char *input, int mode)
{
    if (string_is_empty(input))
        return;

    char args[MAX_NUM_ARGS][MAX_STR_SIZE];
    int num_args = parse_command(w, self, input, args);

    if (num_args == -1)
        return;

    /* Try to match input command to command functions. If non-global command mode is specified,
       try specified mode's commands first, then upon failure try global commands.

       Note: Global commands must come last in case of duplicate command names */
    switch (mode) {
        case CHAT_COMMAND_MODE:
            if (do_command(w, self, m, num_args, chat_commands, args) == 0)
                return;

            break;

        case GROUPCHAT_COMMAND_MODE:
            break;
    }

    if (do_command(w, self, m, num_args, global_commands, args) == 0)
        return;

    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid command.");
}
Example #7
0
static int timeout_func(gpointer data)
{
	int pos;
	gboolean playing;
	static char *previous_file = NULL;
	static gboolean cmd_after_already_run = FALSE;
	char *current_file;

	GDK_THREADS_ENTER();

	playing = xmms_remote_is_playing(sc_gp.xmms_session);
	pos = xmms_remote_get_playlist_pos(sc_gp.xmms_session);
	current_file = xmms_remote_get_playlist_file(sc_gp.xmms_session, pos);
	
	if ((pos != previous_song ||
	     (!previous_file && current_file) ||
	     (previous_file && !current_file) ||
	     (previous_file && current_file &&
	      strcmp(previous_file, current_file))) &&
	    xmms_remote_get_output_time(sc_gp.xmms_session) > 0)
	{
		do_command(cmd_line, current_file, pos);
		g_free(previous_file);
		previous_file = g_strdup(current_file);
		previous_song = pos;
		cmd_after_already_run = FALSE;
	}
	if (!cmd_after_already_run &&
	    ((xmms_remote_get_playlist_time(sc_gp.xmms_session,pos) -
	      xmms_remote_get_output_time(sc_gp.xmms_session)) < 100))
	{
		do_command(cmd_line_after, current_file, pos);
		cmd_after_already_run = TRUE;
	}

	if (playing)
	{
		int playlist_length = xmms_remote_get_playlist_length(sc_gp.xmms_session);
		if (pos + 1 == playlist_length)
			possible_pl_end = TRUE;
		else
			possible_pl_end = FALSE;
	}
	else if (possible_pl_end)
	{
		if (pos == 0)
			do_command(cmd_line_end, current_file, pos);
		possible_pl_end = FALSE;
		g_free(previous_file);
		previous_file = NULL;
	}

	g_free(current_file);
	current_file = NULL;

	GDK_THREADS_LEAVE();

	return TRUE;
}
Example #8
0
void upsdrv_shutdown(void)
{
	char reply[8];
	
	if(!(do_command(cmd_setOutOffMode, reply, 8) != -1) &&
	(do_command(cmd_setOutOffDelay, reply, 8) != -1) &&
	(do_command(cmd_sysLoadKey, reply, 6) != -1) &&
	(do_command(cmd_shutdown, reply, 8) != -1))
	upslogx(LOG_ERR, "Failed to shutdown UPS");
}
Example #9
0
int main(int argc, char *argv[])
{
	cmdname = "";
	arg1 = NULL;
	arg1len = 0;
	arg2 = NULL;
	arg2len = 0;

	if (argv[1]) {
		cmdname = "open";
		arg1 = argv[1];
		do_command();
		cmdname =  "";
		arg1 = NULL;
	}

	switch (argc) {
	case 1:
	case 2:
		/* Interactive mode */
		while ((cmdname = tdb_getline("tdb> "))) {
			arg2 = arg1 = NULL;
			if ((arg1 = strchr((const char *)cmdname,' ')) != NULL) {
				arg1++;
				arg2 = arg1;
				while (*arg2) {
					if (*arg2 == ' ') {
						*arg2++ = '\0';
						break;
					}
					if ((*arg2++ == '\\') && (*arg2 == ' ')) {
						arg2++;
					}
				}
			}
			if (arg1) arg1 = tdb_convert_string(arg1,&arg1len);
			if (arg2) arg2 = tdb_convert_string(arg2,&arg2len);
			if (do_command()) break;
		}
		break;
	case 5:
		arg2 = tdb_convert_string(argv[4],&arg2len);
	case 4:
		arg1 = tdb_convert_string(argv[3],&arg1len);
	case 3:
		cmdname = argv[2];
	default:
		do_command();
		break;
	}

	if (tdb) tdb_close(tdb);

	return 0;
}
Example #10
0
static void set_identification(const char *val) {
	char response[MAX_RESPONSE_LENGTH];

	if (do_command(POLL, IDENTIFICATION, "", response) < 0)
		return;
	if (strcmp(val, response)) {
		strncpy(response, val, MAX_RESPONSE_LENGTH);
		response[MAX_RESPONSE_LENGTH - 1] = '\0';
		do_command(SET, IDENTIFICATION, response, NULL);
	}
}
Example #11
0
void		do_reverse_command(t_app *app, unsigned char command)
{
	if (command >= RA && command <= RR)
		do_command(app, command + 3);
	else if (command >= RRA && command <= RRR)
		do_command(app, command - 3);
	else if (command == PA)
		do_command(app, command + 1);
	else if (command == PB)
		do_command(app, command - 1);
	else
		do_command(app, command);
}
Example #12
0
void run_commands(unsigned int num_command, const char commands_list[max_commands][max_command_length], int to_file)
{
    if(to_file)
    {
        FILE* f = fopen("/home/box/result.out", "w");
        if(f)
        {
            close(STDOUT_FILENO);
            dup2(f->_fileno, STDOUT_FILENO);
            fclose(f);
        }
    }

    if(num_command > 0)
    {
        int pfd[2];
        pipe(pfd);

        if(!fork())
        {
            // child
            close(STDOUT_FILENO);
            dup2(pfd[1], STDOUT_FILENO);

            close(pfd[1]);
            close(pfd[0]);

            run_commands(num_command-1, commands_list, 0);
        }
        else
        {
            // parent
            close(STDIN_FILENO);
            dup2(pfd[0], STDIN_FILENO);

            close(pfd[1]);
            close(pfd[0]);

            char params[2][max_command_length];
            parce_command(commands_list[num_command], params);
            do_command(params);
        }
    }
    else
    {
        char params[2][max_command_length];
        parce_command(commands_list[num_command], params);
        do_command(params);
    }
}
Example #13
0
void upsdrv_shutdown(void)
{
	char parm[20];

	if (!init_comm())
		printf("Status failed.  Assuming it's on battery and trying a shutdown anyway.\n");
	auto_reboot(1);
	/* in case the power is on, tell it to automatically reboot.  if
	   it is off, this has no effect. */
	snprintf(parm, sizeof(parm), "%d", 1); /* delay before reboot, in minutes */
	do_command(SET, SHUTDOWN_RESTART, parm, NULL);
	snprintf(parm, sizeof(parm), "%d", 5); /* delay before shutdown, in seconds */
	do_command(SET, SHUTDOWN_ACTION, parm, NULL);
}
Example #14
0
int get_avr_serial(char *sermem)
{
    int r;
    FILE *eepfile;
    
    r = do_command(CMD_AVR_QUIET R_EEPROM, bigbuf, sizeof(bigbuf));
    if (r < 0) {
	return -1;
    }
    
    if ((eepfile = fopen("eep.raw", "r")) == NULL) {
	printf("%s: open eep.raw file failed\n", __func__);
	return -2;
    }
    fseek(eepfile, 512-16, SEEK_SET);
    fread(sermem, 1, 16, eepfile);
    fclose(eepfile);
    sermem[16] = 0;

#if 0
    for (i = 0, p = serial_mem; i < 16; i++, p++) {
	if (i !=0 && (i % 8) == 0)   printf("\n");
	printf("%c 0x%02x ", isprint(*p) ? *p : '.', *p);
    }
    printf("\n");
#endif

    return 0;
}
Example #15
0
static int				/* O - Status from cups-lpd */
remove_job(int  outfd,			/* I - Command file descriptor */
           int  infd,			/* I - Response file descriptor */
	   char *dest,			/* I - Destination */
	   char **args)			/* I - Arguments */
{
  int		i;			/* Looping var */
  char		command[1024];		/* Command buffer */

 /*
  * Send the "remove jobs" command...
  */

  snprintf(command, sizeof(command), "\005%s", dest);

  for (i = 0; args[i]; i ++)
  {
    strlcat(command, " ", sizeof(command));
    strlcat(command, args[i], sizeof(command));
  }

  strlcat(command, "\n", sizeof(command));

  return (do_command(outfd, infd, command));
}
Example #16
0
int					main(int ac, char **av, char **env)
{
	char	*line2;
	t_e		e;

	(void)ac;
	(void)av;
	e.list = ft_env_cpy(env);
	signal(SIGQUIT, ft_signal);
	show_prompt(e.list);
	while (get_next_line(0, &(e.line)) == 1)
	{
		line2 = exange_tab_or_space(e.line);
		e.args = ft_strsplit(line2, ' ');
		if (e.args && e.args[0])
		{
			if (ft_strchr(e.args[0], '/'))
				exec_absolu(e.line, e.list);
			else
				do_command(&(e.list), e.line);
		}
		free(e.line);
		show_prompt(e.list);
		free_char_array(e.args);
	}
	ft_putchar('\n');
	return (0);
}
Example #17
0
int main()
{
	int running = 1;
	character player;

	/* SET START --------------------------------*/
	room start; 
	strcpy(start.description , "Game Name. [goto] the bedroom to start.");
	/* SET START --------------------------------*/

	/* SET BEDROOM --------------------------------*/
	room bedroom = {"Bedroom", {"pencil", "towel", "backpack"}};
	strcpy(bedroom.entrance_msg, "You wake up.");
	/* SET BEDROOM --------------------------------*/

	player.current_room = start;

	while (running)
	{
		print_room_summary(player.current_room);
		char command[100];
		scanf("%[^\n]", command);
		do_command(command);

	}
	return 0;
}
Example #18
0
void command_prompt(void *pvParameters)
{
	char buf[128];
	char *argv[20];
        char hint[] = USER_NAME "@" USER_NAME "-STM32:~$ ";

	fio_printf(1, "\rWelcome to FreeRTOS Shell\r\n");
	while(1){
		fio_printf(1, "%s", hint);
		fio_read(0, buf, 127);
	
		int n=parse_command(buf, argv);

		/* will return pointer to the command function */
		//if (*argv[0]=='\0')
		cmdfunc *fptr=do_command(argv[0]);
		if(fptr!=NULL)
			fptr(n, argv);
		else if (*argv[0]!='\0')
			fio_printf(2, "\r\n\"%s\" command not found.\r\n", argv[0]);
		else
			fio_printf(1, "\r\n");
	}

}
Example #19
0
int			main(void)
{
	char	*line;
	char	*line2;
	t_list	*list;
	char	**args;

	list = ft_env_cpy();
	signal(SIGINT, ft_signal);
	show_prompt(list);
	while (get_next_line(0, &line) == 1)
	{
		line2 = exchange_tab_for_space(line);
		args = ft_strsplit(line2, ' ');
		if (args && args[0])
		{
			if (ft_strchr(args[0], '/'))
				exec_absolu(line, list);
			else
				do_command(&list, line);
		}
		free(line);
		show_prompt(list);
		free_char_array(args);
	}
	ft_putchar('\n');
	return (0);
}
Example #20
0
static int do_client(void)
{
	int rv;

	rv = setup_config(CLIENT);
	if (rv < 0) {
		log_error("cannot read config");
		goto out;
	}

	switch (cl.op) {
	case CMD_LIST:
	case CMD_PEERS:
		rv = query_get_string_answer(cl.op);
		break;

	case CMD_GRANT:
	case CMD_REVOKE:
		rv = do_command(cl.op);
		break;
	}

out:
	return rv;
}
Example #21
0
File: fl.c Project: pavel-krush/fl
int main(int argc, char **argv) {
	parse_options(argc, argv);
	exec_info();

	while (1) {
		printf("> ");
		char command_line[1024];
		memset(command_line, 0, 1024);
		fgets(command_line, 1024, stdin);

		if (strlen(command_line) == 0 && feof(stdin)) {
			printf("\n");
			break;
		}

		//printf("command: %s\n", command_line);

		do_command(command_line);
	}

	int i;
	for (i = 0; i < files_count; i++) {
		file_delete(files[i]);
	}
	free(files);
	return 0;
}
Example #22
0
/* Perform an imitation lseek operation on remote tape connection
   HANDLE.  Return the new file offset if successful, -1 if on error.  */
off_t
rmt_lseek__ (int handle, off_t offset, int whence)
{
  char command_buffer[COMMAND_BUFFER_SIZE];
  char operand_buffer[UINTMAX_STRSIZE_BOUND];
  uintmax_t u = offset < 0 ? - (uintmax_t) offset : (uintmax_t) offset;
  char *p = operand_buffer + sizeof operand_buffer;

  *--p = 0;
  do
    *--p = '0' + (int) (u % 10);
  while ((u /= 10) != 0);
  if (offset < 0)
    *--p = '-';

  switch (whence)
    {
    case SEEK_SET: whence = 0; break;
    case SEEK_CUR: whence = 1; break;
    case SEEK_END: whence = 2; break;
    default: abort ();
    }

  sprintf (command_buffer, "L%s\n%d\n", p, whence);

  if (do_command (handle, command_buffer) == -1)
    return -1;

  return get_status_off (handle);
}
Example #23
0
File: main.c Project: cyrozap/misoc
int main(int i, char **c)
{
	char buffer[64];
	int sdr_ok;

	irq_setmask(0);
	irq_setie(1);
	uart_init();
	puts("\nMiSoC BIOS\n"
	"(c) Copyright 2007-2016 M-Labs Limited\n"
	"Built "__DATE__" "__TIME__"\n");
	crcbios();
#ifdef CSR_ETHMAC_BASE
	eth_init();
#endif
#ifdef CSR_DFII_BASE
	sdr_ok = sdrinit();
#else
	sdr_ok = 1;
#endif
	if(sdr_ok)
		boot_sequence();
	else
		printf("Memory initialization failed\n");

	while(1) {
		putsnonl("\e[1mBIOS>\e[0m ");
		readstr(buffer, 64);
		do_command(buffer);
	}
	return 0;
}
Example #24
0
/* Write LENGTH bytes from BUFFER to remote tape connection HANDLE.
   Return the number of bytes written.  */
size_t
rmt_write__ (int handle, char *buffer, size_t length)
{
  char command_buffer[COMMAND_BUFFER_SIZE];
  RETSIGTYPE (*pipe_handler) (int);
  size_t written;

  sprintf (command_buffer, "W%lu\n", (unsigned long) length);
  if (do_command (handle, command_buffer) == -1)
    return 0;

  pipe_handler = signal (SIGPIPE, SIG_IGN);
  written = full_write (WRITE_SIDE (handle), buffer, length);
  signal (SIGPIPE, pipe_handler);
  if (written == length)
    {
      long int r = get_status (handle);
      if (r < 0)
	return 0;
      if (r == length)
	return length;
      written = r;
    }

  /* Write error.  */

  _rmt_shutdown (handle, EIO);
  return written;
}
Example #25
0
int main(int i, char **c)
{
	char buffer[64];

	brd_desc = get_board_desc();

	/* Check for double baud rate */
	if(brd_desc != NULL) {
		if(CSR_GPIO_IN & GPIO_DIP2)
			CSR_UART_DIVISOR = brd_desc->clk_frequency/230400/16;
	}

	/* Display a banner as soon as possible to show that the system is alive */
	putsnonl(banner);
	
	crcbios();
	display_board();
	display_capabilities();
	
	boot_sequence();

	splash_showerr();
	while(1) {
		putsnonl("\e[1mBIOS>\e[0m ");
		readstr(buffer, 64);
		do_command(buffer);
	}
	return 0;
}
Example #26
0
void	ft_setenv(t_env *env, char **sa)
{
	int		k;
	int		l;

	l = 1;
	if (ft_strchr(sa[l], '=') == NULL)
	{
		ft_putstr(E_MESS09);
		return ;
	}
	k = 0;
	while (sa[l] != NULL)
	{
		while (E_EN[k] != NULL && !(is_var(E_EN[k], sa[l])))
			k++;
		if (k > 100)
		{
			ft_putstr(E_MESS07);
			return ;
		}
		else if (ft_strchr(sa[l], '=') == NULL)
			do_command(env, sa[l]);
		else
			E_EN[k] = ft_strdup(sa[l]);
		l++;
	}
}
int main(int argc, char *argv[])
{
	ebt_early_init_once();
	strcpy(replace.name, "filter");
	do_command(argc, argv, &replace);
	return 0;
}
Example #28
0
void
do_minidisplay(globalstate *gstate)

{
    int real_delay;
    struct system_info si;

    /* save the real delay and substitute 1 second */
    real_delay = gstate->delay;
    gstate->delay = 1;

    /* wait 1 second for a command */
    time_mark(&(gstate->now));
    do_command(gstate);

    /* do a mini update that only updates the cpustates */
    get_system_info(&si);
    u_cpustates(si.cpustates);

    /* restore the delay time */
    gstate->delay = real_delay;

    /* done */
    i_endscreen();
}
Example #29
0
/* Read up to LENGTH bytes into BUFFER from remote tape connection HANDLE.
   Return the number of bytes read on success, SAFE_READ_ERROR on error.  */
size_t
rmt_read__ (int handle, char *buffer, size_t length)
{
  char command_buffer[COMMAND_BUFFER_SIZE];
  size_t status;
  size_t rlen;
  size_t counter;

  sprintf (command_buffer, "R%lu\n", (unsigned long) length);
  if (do_command (handle, command_buffer) == -1
      || (status = get_status (handle)) == SAFE_READ_ERROR
      || status > length)
    return SAFE_READ_ERROR;

  for (counter = 0; counter < status; counter += rlen, buffer += rlen)
    {
      rlen = safe_read (READ_SIDE (handle), buffer, status - counter);
      if (rlen == SAFE_READ_ERROR || rlen == 0)
	{
	  _rmt_shutdown (handle, EIO);
	  return SAFE_READ_ERROR;
	}
    }

  return status;
}
Example #30
0
// Iptables command.  Essentially the same as the command line version.
static int __lua_iptables(lua_State *L)
{
    int i, r;
    char *rule_copy = NULL;
    const char *table = luaL_checkstring(L, 1);
    const char *rule = luaL_checkstring(L, 2);

    i = find_table(table);

    if(i == -1)
        return eprintf("Invalid table: %s", table);

    if(!tables[i].handle)
        return eprintf("Invalid table: %s", table);

    if(debug) syslog(LOG_DEBUG, "iptables -t %s %s", table, rule);

    rule_copy = strdup(rule);
    argv_parse(table, rule_copy);

    r = do_command(iptc_argc, iptc_argv, &iptc_argv[2], &tables[i].handle);
    if(!r) return eprintf("iptables -t %s %s", table, rule);

    argv_free();
    free(rule_copy);

    return 0;
}