Example #1
0
int		main(int argc, char *argv[], char *envp[])
{
	char	**current_env;
	char	*user_input;
	int		retour;

	if (argc)
	{
		if (!envp || !*envp)
			current_env = fill_empty_env(argv);
		else
			current_env = ft_dup_char_tab(envp);
		signal_handler();
		while (current_env)
		{
			draw_prompt(current_env);
			retour = get_next_line(0, &user_input);
			if (retour < 0 || parse_user_input(user_input, current_env))
				ft_putstr("Erreur");
			free(user_input);
			if (!retour)
				break ;
		}
	}
	return (0);
}
Example #2
0
int main(int argc, char *argv[]) {
    int c_num;
    char buf[BUFSIZE];
    command com[MAXCOMMAND];

    while (1) {
        /*初期化*/
        c_num = 0;
        memset(buf, 0, sizeof(buf));
        memset(com, 0, sizeof(com));
        mode = NORMAL;

        print_prompt(stdout);
        user_input(buf, stdin);
        if (is_empty(buf) == -1) {
            continue;
        } else 
        c_num = parse_user_input(buf, com);
        if (mode == PIPE) {
            exec_command_use_pipe(com, c_num);
        } else {
            exec_command(com, c_num);
        }
    }

    exit(EXIT_SUCCESS);
}
Example #3
0
int		main(int argc, char *argv[], char *envp[])
{
	t_key	*key;
	char	*user_input;
	int		retour;

	if (argc)
	{
		if (!envp || !*envp)
			envp = fill_empty_env(argv);
		key = env_str_to_list(envp);
		signal_handler();
		while (key)
		{
			draw_prompt(key);
			retour = get_next_line(0, &user_input);
			if (retour < 0 || parse_user_input(user_input, key))
				ft_putstr("Erreur");
			free(user_input);
			if (!retour)
				break ;
		}
	}
	return (0);
}
Example #4
0
static void parse_UI(enum sys_message msg)
{
    parse_user_input();

    uart0_p = 0;
    uart0_rx_enable = 1;
    LED_OFF;
}
Example #5
0
	/*
	 * PURPOSE: The command line driven program does matrix creation, reading, writing, and other 
	 *		miscellaneous operations. The program automatically creates a matrix and writes 
	 *		that out called temp_mat (in binary do not use the cat command on it). You are 
	 *		able to display any matrix by using the display command. You can create a new 
	 *		blank matrix with the command create. To fill a matrix with random values use the 
	 *		random command between a range of values. To get some experience with bit shifting 
	 *		there is a command called shift. If you want to write and read in a matrix from 
	 *		the filesystem use the respective read and write commands. To see memory operations 
	 *		in action use the duplicate and equal commands. The others commands are sum and add. 
	 *		To exit the program use the exit command.  
	 * INPUTS: No inputs needed
	 * RETURN: Returns 0 on successful exectution otherwise -1 if there was an error 
	 **/
int main (int argc, char **argv) {
	srand(time(NULL));		
	char *line = NULL;
	Commands_t* cmd;

	Matrix_t *mats[10];
	memset(&mats,0, sizeof(Matrix_t*) * 10); // IMPORTANT C FUNCTION TO LEARN

	Matrix_t *temp = NULL;
	
	// TODO ERROR CHECK
	if(!create_matrix (&temp,"temp_mat", 5, 5)) { 
		return -1; 
	}
 
	//TODO ERROR CHECK NEEDED
	if( (add_matrix_to_array(mats,temp, 10)) < 0) {
		return -1;
	}

	int mat_idx = find_matrix_given_name(mats,10,"temp_mat");

	if (mat_idx < 0) {
		perror("PROGRAM FAILED TO INIT\n");
		return -1;
	}
	random_matrix(mats[mat_idx], 10, 15);
	
	// TODO ERROR CHECK
	if(!write_matrix("temp_mat", mats[mat_idx])) {
		return -1; 
	}

	line = readline("> ");
	while (strncmp(line,"exit", strlen("exit")  + 1) != 0) {
		
		if (!parse_user_input(line,&cmd)) {
			printf("Failed at parsing command\n\n");
		}
		
		if (cmd->num_cmds > 1) {	
			run_commands(cmd,mats,10);
		}
		if (line) {
			free(line);
		}
		destroy_commands(&cmd);
		line = readline("> ");
	}
	free(line);
	destroy_remaining_heap_allocations(mats,10);
	return 0;	
}
Example #6
0
int				main(int argc, char **argv)
{
	t_state		state;
	int			i;

	if (argc > 1)
	{
		i = argc - 1;
		init_state(&state);
		parse_user_input(&state, argv, i);
		play_game(&state);
	}
	else
	{
		ft_putstr("No Input Given. Usage - ./corewar [-dump nbr_cycles] ");
		ft_putendl("[[-n number] champion1.cor] ...");
	}
	return (0);
}
Example #7
0
int main (int argc, char **argv) {
	srand(time(NULL));	
	char *line = NULL;
	Commands_t* cmd;
	line = readline("> ");

	Matrix_t mats[10];
	memset(&mats,0, sizeof(Matrix_t) * 10);

	while (strncmp(line,"exit", strlen("exit")  + 1) != 0) {
		
		if (!parse_user_input(line,&cmd)) {
			printf("ERROR\n\n");
		}
		
		run_commands(cmd,mats,10);

		free(line);
		destroy_commands(&cmd);
		line = readline("> ");
	}
	free(line);
	return 0;	
}
Example #8
0
int main(int argc, char **argv)
{
	char read_tty[TTY_LEN] = { 0 };
	int ip_version;
	int socket_domain = AF_UNSPEC;
	char cmd[COMMAND_LEN] = { 0 };

	/* Open the error log file */
	error_file = fopen(error_log_file, "a+");
	if (!error_file) {
		printf("Error: Unable to open log file - %m\n");
		return 1;
	}

	/* Register actions upon interrupts */
	register_kill();

	/* Parse the user input */
	if (!parse_user_input(argc, argv, read_tty, sizeof(read_tty), &ip_version)) {
		return 2;
	}

	snprintf(cmd, sizeof(cmd), "%s %s", uS_console, "connect");
	if (system(cmd) == -1) {
		errlog("Error: Unable to connect to the micro-server\n");
		return 3;
	}

	/* Create a socket to communicate with the netcons server */
	socket_domain = (ip_version == IPV4) ? AF_INET : AF_INET6;
	fd_soc = socket(socket_domain, SOCK_DGRAM, 0);
	if (fd_soc == -1) {
		errlog("Error: Socket creation failed -  %m\n");
		return 4;
	}

	if (ip_version == IPV4) {	/* IPv4 */
		struct sockaddr_in tgt_addr;
		if (!prepare_sock(&tgt_addr)) {
			close(fd_soc);
			errlog("Error: Socket not valid\n");
			return 5;
		}

		if (connect(fd_soc, (struct sockaddr *)&tgt_addr, sizeof(tgt_addr)) == -1) {
			close(fd_soc);
			errlog("Error: Socket connection failed - %m\n");
			return 6;
		}

	} else {		/* IPv6 */

		struct sockaddr_in6 tgt_addr6;
		if (!prepare_sock6(&tgt_addr6)) {
			close(fd_soc);
			errlog("Error: Socket not valid\n");
			return 5;
		}

		if (connect(fd_soc, (struct sockaddr *)&tgt_addr6, sizeof(tgt_addr6)) == -1) {
			close(fd_soc);
			errlog("Error: Socket connection failed - %m\n");
			return 6;
		}
	}

	/* TTY Operations */
	if ((fd_tty = open(read_tty, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1) {
		close(fd_soc);
		errlog("Error: Serial Port %s open failed - %m\n", read_tty);
		return 7;
	}

	if (!set_tty(fd_tty)) {
		errlog("Error: tty not set properly\n");
		cleanup();
		return 8;
	}

	/* Read, prepare and send the logs */
	if (!read_send(fd_tty, fd_soc)) {
		errlog("Error: Sending logs failed\n");
		cleanup();
		return 9;
	}

	cleanup();
	return 0;
}