Lhogho
0.0.027
|
Functions | |
IMPLEMENT_PARSERS_REGISTER_FUNCTION (PARSERS_LIST) | |
Generate implementation of register function. | |
static void | print_help () |
Print command line usage information. | |
static RESULT | parse_arg (char **argv, int argc, int *ind) |
Parse one command line argument. | |
static RESULT | parse_args (int argc, char **argv) |
Parse command line arguments. | |
static RESULT | init_tester (int argc, char **argv) |
Initialize parser. | |
static RESULT | uninit_tester () |
Free used resources. | |
int | main (int argc, char **argv) |
Entry point of test application. |
IMPLEMENT_PARSERS_REGISTER_FUNCTION | ( | PARSERS_LIST | ) |
void print_help | ( | ) | [static] |
Print command line usage information
{ printf("Program usage:\n"); printf("TestMaker [options]\n"); printf(" Valid options are:\n"); printf(" -d (--dir) <folder name> - Specify the input folder. Default is current.\n"); printf(" -o (--out) <file name> - Specify the output file. Default is stdout.\n"); printf(" -e (--exec) - Set execution mode.\n"); printf(" -b (--build) - Set test build mode.\n"); printf(" -p (--param) <file name> - Specify parameters passed to compiler.\n"); printf(" -c (--compiler) <app name> - Specify the compiler which will be called.\n"); printf(" -v (--verbose) - Set verbose info mode.\n"); printf(" -s (--strict) - Set strict text compare mode.\n"); printf(" -h (--help) - Print this info.\n"); printf("\n"); }
argv | list of arguments |
argc | argument count |
ind | index of argument to be parsed |
RESULT
code (see error.h)Parse one command line argument. If it uses another token increase ind
Modifies g_parameters
{ char * arg = argv[*ind]; int start = 1; if (arg[0] != '-') { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } if (arg[1] == '-') ++start; switch(arg[start]) { case 'd': if (arg[start + 1] && strcmp(arg + start, ARG_DIR)) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } ++(*ind); if (*ind == argc || argv[*ind][0] == '-') { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } m_strdup(&g_parameters.input_directory, argv[*ind]); break; case 'p': if (arg[start + 1] && strcmp(arg + start, ARG_PARAM)) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } ++(*ind); if (*ind == argc) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } m_strdup(&g_parameters.global_params, argv[*ind]); break; case 'o': if (arg[start + 1] && strcmp(arg + start, ARG_OUT)) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } ++(*ind); if (*ind == argc || argv[*ind][0] == '-') { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } g_parameters.output_file = fopen(argv[*ind], "wt"); if (!g_parameters.output_file) { LOG_ERROR("can't open output file"); return ERR_FILE; } break; case 'c': if (arg[start + 1] && strcmp(arg + start, ARG_OUT)) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } ++(*ind); if (*ind == argc || argv[*ind][0] == '-') { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } m_strdup(&g_parameters.compiler_name, argv[*ind]); break; case 'v': if (arg[start + 1] && strcmp(arg + start, ARG_VERBOSE)) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } g_parameters.verbose_flag = TRUE; break; case 's': if (arg[start + 1] && strcmp(arg + start, ARG_STRICT_MODE)) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } g_parameters.strict_flag = TRUE; break; case 'b': if (arg[start + 1] && strcmp(arg + start, ARG_BUILD_MODE)) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } g_parameters.tester_mode = MODE_BUILD; break; case 'e': if (arg[start + 1] && strcmp(arg + start, ARG_EXEC_MODE)) { printf("Unknown argument %s\n", arg); print_help(); return ERR_INVALID_ARG; } g_parameters.tester_mode = MODE_EXECUTE; break; case 'h': print_help(); return SUCCESS_EMPTY; default: print_help(); return ERR_INVALID_ARG; } return SUCCESS_FULL; }
RESULT parse_args | ( | int | argc, |
char ** | argv | ||
) | [static] |
argv | list of arguments |
argc | argument count |
RESULT
code (see error.h)Parse all command line arguments. Modifies g_parameters
{ int i; RESULT res; memset(&g_parameters, 0, sizeof(g_parameters)); g_parameters.output_file = fdopen(1, "a"); g_parameters.tester_mode = MODE_TEST; for (i = 1; i < argc; ++ i) { res = parse_arg(argv, argc, &i); if (res != SUCCESS_FULL) { if (IS_ERROR(res)) { LOG_ERROR("parse_arg failed"); } return res; } } return SUCCESS_FULL; }
RESULT init_tester | ( | int | argc, |
char ** | argv | ||
) | [static] |
argv | list of command line arguments |
argc | argument count |
RESULT
code (see error.h)Initialize parser. This includes global parameters, Param parsers ans so on. Must be called at the begining! Modifies g_parameters
{ RESULT res; INIT_LOGER; res = init_param_parsers(); if (IS_ERROR(res)) { LOG_ERROR("init_param_parsers failed"); return res; } res = parse_args(argc, argv); if (IS_ERROR(res)) { LOG_ERROR("parse_args failed"); return res; } g_parameters.num_failed = 0; g_parameters.num_passed = 0; return SUCCESS_FULL; }
RESULT uninit_tester | ( | ) | [static] |
RESULT
code (see error.h)Free used resources. Must be last function called
{ if (g_parameters.output_file) { fclose(g_parameters.output_file); } SAFE_FREE(g_parameters.global_params); SAFE_FREE(g_parameters.input_directory); SAFE_FREE(g_parameters.compiler_name); UNINIT_LOGER; return SUCCESS_FULL; }
int main | ( | int | argc, |
char ** | argv | ||
) |
{ RESULT res; res = init_tester(argc, argv); if (res != SUCCESS_FULL) { LOG_ERROR("init_tester failed"); uninit_tester(); return GET_CODE(res); } res = process_directory(); if (IS_ERROR(res)) { LOG_ERROR("process_directory failed"); } if (g_parameters.verbose_flag) { fprintf (g_parameters.output_file, "\n%5d files passed\n%5d files failed\n\n", g_parameters.num_passed, g_parameters.num_failed); if (g_parameters.num_failed) { fprintf (g_parameters.output_file, "Test FAILED!\n\n"); } else { fprintf (g_parameters.output_file, "Test SUCCESS!\n\n"); } } res = uninit_tester(); if (IS_ERROR(res)) { LOG_ERROR("uninit_tester failed"); } return GET_CODE(res); }