예제 #1
0
static void forward_test_case(int case_num)
{
	if ((debug == 2) || (debug == 3)) {
		if (case_num == 0) {
			char *user_input_name = DEFAULT_USER_INPUT_NAME;
			char *user_output_name = DEFAULT_USER_OUTPUT_NAME;

	              if (access(DEFAULT_USER_INPUT_NAME, F_OK) != 0) {
				create_user_file(user_input_name);
	                }
			debug_printf("create default user file (%s)\n", DEFAULT_USER_INPUT_NAME);
			inputfd = open(user_input_name, O_RDONLY);
			if (!inputfd) {
				error_printf("can't open file: %s\n", user_input_name);
				exit (EXIT_FAILURE);
			}
			
	              if (access(DEFAULT_USER_OUTPUT_NAME, F_OK) != 0) {
				create_user_file(user_output_name);
	               }
			debug_printf("create default user file (%s)\n", DEFAULT_USER_OUTPUT_NAME);
			outputfd = open(user_output_name, O_WRONLY);
			if (!outputfd) {
				error_printf("can't open file: %s\n", user_output_name);
				exit (EXIT_FAILURE);
			}
		}
		else if ((case_num == 1) && (debug == 2)) {
			debug_printf("Test case 1 => begin \n");
			debug_printf("from input file: %s to ttyfd: %s\n", DEFAULT_USER_INPUT_NAME, tty_name);
			forward_message(inputfd, ttyfd);
			debug_printf("from ttyfd: %s to output file: %s\n", tty_name, DEFAULT_USER_OUTPUT_NAME);	
			forward_message(ttyfd, outputfd);
			if (0 != close(inputfd))
				error_printf("Note: couldn't close file: %s correctly\n", DEFAULT_USER_INPUT_NAME);
			if (0 != close(outputfd))
				error_printf("Note: couldn't close file: %s correctly\n", DEFAULT_USER_OUTPUT_NAME);
			debug_printf("Test case 1 => end \n");
			exit (EXIT_SUCCESS);
		}
		else if ((case_num == 2) && (debug == 3)) {
			int err = 0;
			debug_printf("Test case 2 => begin \n");
			do {
				debug_printf("from input file: %s to socketfd: %d\n", DEFAULT_USER_INPUT_NAME, clientfd);
				err = forward_message(inputfd, clientfd);
				debug_printf("from socketfd: %d to output file: %s\n", clientfd, DEFAULT_USER_OUTPUT_NAME);	
				err = forward_message(clientfd, outputfd);
			} while (err == READ_WRITE_OK);
			close(serverfd);
		 	close(clientfd);
			if (0 != close(inputfd))
				error_printf("Note: couldn't close file: %s correctly\n", DEFAULT_USER_INPUT_NAME);
			if (0 != close(outputfd))
				error_printf("Note: couldn't close file: %s correctly\n", DEFAULT_USER_OUTPUT_NAME);
			debug_printf("Test case 2 => end \n");		
			exit(EXIT_SUCCESS);
		}
	}
}
예제 #2
0
static void parse_command_line(int argc, char *argv[])
{
	int c;
	char *debug_level;
	opterr = 0;
	while ((c = getopt(argc, argv, "t:d:cioh")) != -1) {
		switch (c) {
		case 't':
			tty_name = optarg;
			break;
		case 'c':
			create_config_file(DEFAULT_TTY_CONFIG);
			printf("Options:\n" "    -c        : create default tty config file (%s)\n", DEFAULT_TTY_CONFIG);
			exit(EXIT_SUCCESS);
			break;
		case 'i':
			create_user_file(DEFAULT_USER_INPUT_NAME);
			printf("create default user file (%s)\n", DEFAULT_USER_INPUT_NAME);
			exit(EXIT_SUCCESS);
			break;
		case 'o':
			create_user_file(DEFAULT_USER_OUTPUT_NAME);
			printf("create default user file (%s)\n", DEFAULT_USER_INPUT_NAME);
			exit(EXIT_SUCCESS);
			break;
		case 'd':
			debug_level = optarg;
			debug = atoi(debug_level);
			break;
		case 'h':
			usage(argv[0]);
			break;
		case '?':
			if (optopt == 't')
				fprintf(stderr, "Option -%c requires an argument.\n", optopt);
			else if (isprint(optopt))
				fprintf(stderr, "Unknown option `-%c'.\n", optopt);
			else
				fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
			exit(EXIT_SUCCESS);
			break;
		default:
			abort();
			exit(EXIT_FAILURE);
		}
	}
}
예제 #3
0
파일: main.c 프로젝트: LastAvenger/srain
int main(int argc, char **argv){
    create_user_file();
    signal(SIGINT, quit);

    i18n_init();
    plugin_init();

#ifndef UI_TEST
    srv_init();
#endif

#ifndef IRC_TEST
    ui_init(argc, argv);
#endif

    quit();

    return 0;
}