[trunk] First pass to cleanup compare_dump_files
This commit is contained in:
parent
24966ffbda
commit
7aee50de97
|
@ -62,7 +62,7 @@ static void compare_dump_files_help_display(void) {
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
|
static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
|
||||||
{
|
{
|
||||||
int sizemembasefile, sizememtestfile;
|
size_t sizemembasefile, sizememtestfile;
|
||||||
int index;
|
int index;
|
||||||
const char optlist[] = "b:t:";
|
const char optlist[] = "b:t:";
|
||||||
int c;
|
int c;
|
||||||
|
@ -77,19 +77,15 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'b':
|
case 'b':
|
||||||
sizemembasefile = (int)strlen(opj_optarg)+1;
|
sizemembasefile = strlen(opj_optarg) + 1;
|
||||||
param->base_filename = (char*) malloc((size_t)sizemembasefile);
|
param->base_filename = (char*) malloc(sizemembasefile);
|
||||||
param->base_filename[0] = '\0';
|
strcpy(param->base_filename, opj_optarg);
|
||||||
strncpy(param->base_filename, opj_optarg, strlen(opj_optarg));
|
|
||||||
param->base_filename[strlen(opj_optarg)] = '\0';
|
|
||||||
/*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/
|
/*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
sizememtestfile = (int) strlen(opj_optarg) + 1;
|
sizememtestfile = strlen(opj_optarg) + 1;
|
||||||
param->test_filename = (char*) malloc((size_t)sizememtestfile);
|
param->test_filename = (char*) malloc(sizememtestfile);
|
||||||
param->test_filename[0] = '\0';
|
strcpy(param->test_filename, opj_optarg);
|
||||||
strncpy(param->test_filename, opj_optarg, strlen(opj_optarg));
|
|
||||||
param->test_filename[strlen(opj_optarg)] = '\0';
|
|
||||||
/*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/
|
/*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
|
@ -108,11 +104,12 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
|
||||||
{
|
{
|
||||||
for (index = opj_optind; index < argc; index++)
|
for (index = opj_optind; index < argc; index++)
|
||||||
fprintf(stderr,"Non-option argument %s\n", argv[index]);
|
fprintf(stderr,"Non-option argument %s\n", argv[index]);
|
||||||
return EXIT_FAILURE;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* MAIN
|
* MAIN
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -124,12 +121,10 @@ int main(int argc, char **argv)
|
||||||
int same = 1;
|
int same = 1;
|
||||||
unsigned long l=1, pos;
|
unsigned long l=1, pos;
|
||||||
|
|
||||||
if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE )
|
if( parse_cmdline_cmp(argc, argv, &inParam) == 1 )
|
||||||
{
|
{
|
||||||
compare_dump_files_help_display();
|
compare_dump_files_help_display();
|
||||||
if (!inParam.base_filename) free(inParam.base_filename);
|
goto cleanup;
|
||||||
if (!inParam.test_filename) free(inParam.test_filename);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display Parameters*/
|
/* Display Parameters*/
|
||||||
|
@ -143,10 +138,7 @@ int main(int argc, char **argv)
|
||||||
printf("Try to open: %s for reading ... ", inParam.base_filename);
|
printf("Try to open: %s for reading ... ", inParam.base_filename);
|
||||||
if((fbase = fopen(inParam.base_filename, "rb"))==NULL)
|
if((fbase = fopen(inParam.base_filename, "rb"))==NULL)
|
||||||
{
|
{
|
||||||
printf("Failed.\n");
|
goto cleanup;
|
||||||
free(inParam.base_filename);
|
|
||||||
free(inParam.test_filename);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
printf("Ok.\n");
|
printf("Ok.\n");
|
||||||
|
|
||||||
|
@ -154,11 +146,7 @@ int main(int argc, char **argv)
|
||||||
printf("Try to open: %s for reading ... ", inParam.test_filename);
|
printf("Try to open: %s for reading ... ", inParam.test_filename);
|
||||||
if((ftest = fopen(inParam.test_filename, "rb"))==NULL)
|
if((ftest = fopen(inParam.test_filename, "rb"))==NULL)
|
||||||
{
|
{
|
||||||
printf("Failed.\n");
|
goto cleanup;
|
||||||
fclose(fbase);
|
|
||||||
free(inParam.base_filename);
|
|
||||||
free(inParam.test_filename);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
printf("Ok.\n");
|
printf("Ok.\n");
|
||||||
|
|
||||||
|
@ -170,14 +158,14 @@ int main(int argc, char **argv)
|
||||||
if(ferror(fbase))
|
if(ferror(fbase))
|
||||||
{
|
{
|
||||||
printf("Error reading base file.\n");
|
printf("Error reading base file.\n");
|
||||||
return EXIT_FAILURE;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
chtest = fgetc(ftest);
|
chtest = fgetc(ftest);
|
||||||
if(ferror(ftest))
|
if(ferror(ftest))
|
||||||
{
|
{
|
||||||
printf("Error reading test file.\n");
|
printf("Error reading test file.\n");
|
||||||
return EXIT_FAILURE;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* CRLF problem (Baseline must be always generated by unix platform)*/
|
/* CRLF problem (Baseline must be always generated by unix platform)*/
|
||||||
|
@ -221,14 +209,15 @@ int main(int argc, char **argv)
|
||||||
strbase_d[strlen(strbase)-1] = '\0';
|
strbase_d[strlen(strbase)-1] = '\0';
|
||||||
strtest_d[strlen(strtest)-(size_t)CRLF_shift] = '\0';
|
strtest_d[strlen(strtest)-(size_t)CRLF_shift] = '\0';
|
||||||
printf("<%s> vs. <%s>\n", strbase_d, strtest_d);
|
printf("<%s> vs. <%s>\n", strbase_d, strtest_d);
|
||||||
free(strbase_d);free(strtest_d);
|
free(strbase_d);
|
||||||
|
free(strtest_d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(strbase);free(strtest);
|
free(strbase);
|
||||||
|
free(strtest);
|
||||||
|
|
||||||
same = 0;
|
same = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -241,18 +230,15 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\n***** TEST SUCCEED: Files are the same. *****\n");
|
||||||
|
cleanup:
|
||||||
/*Close File*/
|
/*Close File*/
|
||||||
fclose(fbase);
|
if(fbase) fclose(fbase);
|
||||||
fclose(ftest);
|
if(ftell) fclose(ftest);
|
||||||
|
|
||||||
/* Free memory*/
|
/* Free memory*/
|
||||||
free(inParam.base_filename);
|
free(inParam.base_filename);
|
||||||
free(inParam.test_filename);
|
free(inParam.test_filename);
|
||||||
|
|
||||||
if(same)
|
return same ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
{
|
|
||||||
printf("\n***** TEST SUCCEED: Files are the same. *****\n");
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
else return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue