X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=tests%2Fcompare_dump_files.c;h=6bc5145b29536f0a8b7e05e9d3af1acf00e35600;hb=07ae149955db833fea2a785c9655153252751bc1;hp=42ef2fbb33f841ba4991a4e45ca4b19104b54dcc;hpb=c2b0a8101b21babd3e3572c18497df2c9a1f85ac;p=openjpeg.git diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index 42ef2fbb..6bc5145b 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -1,3 +1,29 @@ +/* + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /* * compare_dump_files.c * @@ -11,7 +37,7 @@ #include #include -#include "getopt.h" +#include "opj_getopt.h" typedef struct test_cmp_parameters { @@ -24,7 +50,7 @@ typedef struct test_cmp_parameters /******************************************************************************* * Command line help function *******************************************************************************/ -void compare_dump_files_help_display() { +static void compare_dump_files_help_display(void) { fprintf(stdout,"\nList of parameters for the compare_dump_files function \n"); fprintf(stdout,"\n"); fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n"); @@ -34,53 +60,53 @@ void compare_dump_files_help_display() { /******************************************************************************* * Parse command line *******************************************************************************/ -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; int index; const char optlist[] = "b:t:"; int c; - // Init parameters + /* Init parameters */ param->base_filename = NULL; param->test_filename = NULL; - opterr = 0; + opj_opterr = 0; - while ((c = getopt(argc, argv, optlist)) != -1) + while ((c = opj_getopt(argc, argv, optlist)) != -1) switch (c) { case 'b': - sizemembasefile = (int)strlen(optarg)+1; + sizemembasefile = (int)strlen(opj_optarg)+1; param->base_filename = (char*) malloc(sizemembasefile); param->base_filename[0] = '\0'; - strncpy(param->base_filename, optarg, strlen(optarg)); - param->base_filename[strlen(optarg)] = '\0'; - //printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile ); + 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 );*/ break; case 't': - sizememtestfile = (int) strlen(optarg) + 1; + sizememtestfile = (int) strlen(opj_optarg) + 1; param->test_filename = (char*) malloc(sizememtestfile); param->test_filename[0] = '\0'; - strncpy(param->test_filename, optarg, strlen(optarg)); - param->test_filename[strlen(optarg)] = '\0'; - //printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile); + 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);*/ break; case '?': - if ( (optopt == 'b') || (optopt == 't') ) - fprintf(stderr, "Option -%c requires an argument.\n", optopt); + if ( (opj_optopt == 'b') || (opj_optopt == 't') ) + fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); else - if (isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt); - else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); + if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); + else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); return 1; default: - fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, optarg); + fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); break; } - if (optind != argc) + if (opj_optind != argc) { - for (index = optind; index < argc; index++) + for (index = opj_optind; index < argc; index++) fprintf(stderr,"Non-option argument %s\n", argv[index]); return EXIT_FAILURE; } @@ -106,7 +132,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - // Display Parameters + /* Display Parameters*/ printf("******Parameters********* \n"); printf(" base_filename = %s\n" " test_filename = %s\n", @@ -154,7 +180,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - // CRLF problem (Baseline must be always generated by unix platform) + /* CRLF problem (Baseline must be always generated by unix platform)*/ if (chbase == '\n' && chtest == '\r') if (fgetc(ftest) == '\n') chtest = '\n'; @@ -164,13 +190,12 @@ int main(int argc, char **argv) size_t nbytes = 2048; int CRLF_shift=1; char *strbase, *strtest, *strbase_d, *strtest_d; - char *return_value_fgets; printf("Files differ at line %lu:\n", l); fseek(fbase,pos,SEEK_SET); - // Take into account CRLF characters when we write \n into - // dump file when we used WIN platform + /* Take into account CRLF characters when we write \n into + // dump file when we used WIN platform*/ #ifdef _WIN32 CRLF_shift = 2; fseek(ftest,pos + l - 1,SEEK_SET); @@ -181,27 +206,29 @@ int main(int argc, char **argv) strbase = (char *) malloc(nbytes + 1); strtest = (char *) malloc(nbytes + 1); - return_value_fgets = fgets(strbase, nbytes, fbase); - if (!strcmp(return_value_fgets,strbase)) - fprintf(stderr,"\nWARNING: fgets return a value different that the first argument"); - free(return_value_fgets); - - return_value_fgets = fgets(strtest, nbytes, ftest); - if (!strcmp(return_value_fgets,strtest)) - fprintf(stderr,"\nWARNING: fgets return a value different that the first argument"); - free(return_value_fgets); - - strbase_d = (char *) malloc(strlen(strbase)+1); - strtest_d = (char *) malloc(strlen(strtest)+1); - strncpy(strbase_d, strbase, strlen(strbase)-1); - strncpy(strtest_d, strtest, strlen(strtest)-CRLF_shift); - strbase_d[strlen(strbase)-1] = '\0'; - strtest_d[strlen(strtest)-CRLF_shift] = '\0'; - printf("<%s> vs. <%s>\n", strbase_d, strtest_d); - - free(strbase);free(strtest); - free(strbase_d);free(strtest_d); - same = 0; + if (fgets(strbase, nbytes, fbase) == NULL) + fprintf(stderr,"\nWARNING: fgets return a NULL value"); + else + { + if (fgets(strtest, nbytes, ftest) == NULL) + fprintf(stderr,"\nWARNING: fgets return a NULL value"); + else + { + strbase_d = (char *) malloc(strlen(strbase)+1); + strtest_d = (char *) malloc(strlen(strtest)+1); + strncpy(strbase_d, strbase, strlen(strbase)-1); + strncpy(strtest_d, strtest, strlen(strtest)-CRLF_shift); + strbase_d[strlen(strbase)-1] = '\0'; + strtest_d[strlen(strtest)-CRLF_shift] = '\0'; + printf("<%s> vs. <%s>\n", strbase_d, strtest_d); + free(strbase_d);free(strtest_d); + } + } + + free(strbase);free(strtest); + + same = 0; + break; } else @@ -214,11 +241,11 @@ int main(int argc, char **argv) } } - //Close File + /*Close File*/ fclose(fbase); fclose(ftest); - // Free memory + /* Free memory*/ free(inParam.base_filename); free(inParam.test_filename);