예제 #1
0
파일: alli.cpp 프로젝트: citic/botNeumann
int main(int argc, char* argv[])
{
	global_program_name.setValue2( argv[0] );
	sorted_arguments = (InputArgument**) malloc( argc * sizeof(InputArgument*) );

	try
	{
		for ( int index = 0; index < argc; ++index )
			all_arguments.push_back( new InputArgument(index, argv[index]) );

		assert(argc >= 2);
		InputArgument input_count(1, argv[1]);
		read_arguments( input_count.valueToUll() );

		std::thread printer1( print_arguments_1, 0 );
		std::thread sorter( sort_arguments );

		printer1.join();
		sorter.join();
		std::thread printer2( print_arguments_2 );

		printer2.join();
		delete_arguments();

		return 0;
	}
	catch(std::exception& exc)
	{
		std::cerr << "Exception: " << exc.what() << std::endl;
		return 1;
	}
}
예제 #2
0
int main(int argc, char *argv[]) {
    /* allocates the space for the "final" result code
    that is going to be returned as part of the normal
    command execution, a positive or negative values
    should idicate an error, a zero value indicates that
    a normal execution has just finished */
    ERROR_CODE return_value;

    /* allocates space for the name of the program
    (process) to be executed */
    char *program_name;

    /* allocates the map that will contain the various
    processed arguments, indexed by name */
    struct hash_map_t *arguments;

    /* prints a debug message */
    V_DEBUG_F("Receiving %d argument(s)\n", argc);

    /* in case the number of arguments is less than one
    (exception case) returns in error */
    if(argc < 1) {
        cleanup(NULL);
        RAISE_ERROR_S(1);
    }

    /* retrieves the first argument value as the name
    of the process (program) to be executed */
    program_name = argv[0];

    /* processes the various arguments into a map and then
    executes the corresponding (initial) actions */
    process_arguments(argc, argv, &arguments);
    return_value = execute_arguments(program_name, arguments);

    /* cleans the current process information so that
    no remaining structure or resource is left in an
    invalid or erroneous state */
    cleanup(arguments);

    /* deletes the processed arguments and then cleans up
    the pool based memory allocation system releasing all
    of its memory before the exit (no leaks) */
    delete_arguments(arguments);
    cleanup_palloc();

    /* prints a debug message about the ending of the sytem
    for the execution of the service and then returns the
    normal return code (success status) to the caller process */
    V_DEBUG_F(
        "Finishing process [%ld pending]\n",
        (long int) ALLOCATIONS
    );
    RAISE_AGAIN(return_value);
}