preventde seg fault when unknown long options and fixed ability to use USE_SYSTEM_GETOPT

This commit is contained in:
Antonin Descampe 2015-09-15 18:00:52 +02:00
parent 2d47938b25
commit 31e35fcf7b
5 changed files with 42 additions and 16 deletions

View File

@ -591,7 +591,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
{"POC",REQ_ARG, NULL ,'P'},
{"ROI",REQ_ARG, NULL ,'R'},
{"jpip",NO_ARG, NULL, 'J'},
#ifdef USE_SYSTEM_GETOPT
{0,0,0,0} /* GNU getopt_long requirement */
#endif
};
/* parse the command line */
@ -601,7 +603,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#endif /* USE_JPWL */
"h";
totlen=sizeof(long_option)-1;
totlen=sizeof(long_option);
img_fol->set_out_format=0;
raw_cp->rawWidth = 0;
@ -1392,8 +1394,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
default:
fprintf(stderr, "ERROR -> Command line not valid\n");
return 1;
fprintf(stderr, "[WARNING] An invalid option has been ignored\n");
break;
}
}while(c != -1);

View File

@ -201,13 +201,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
int totlen, c;
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
#ifdef USE_SYSTEM_GETOPT
{0,0,0,0} /* GNU getopt_long requirement */
#endif
};
const char optlist[] = "i:o:h";
OPJ_ARG_NOT_USED(indexfilename);
totlen=sizeof(long_option)-1;
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
#ifdef USE_SYSTEM_GETOPT
@ -265,7 +267,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
default:
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
fprintf(stderr,"[WARNING] An invalid option has been ignored\n");
break;
}
}while(c != -1);

View File

@ -243,7 +243,9 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'},
#ifdef USE_SYSTEM_GETOPT
{0,0,0,0} /* GNU getopt_long requirement */
#endif
};
const char optlist[] = "i:o:r:l:x:"
@ -254,7 +256,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
#endif /* USE_JPWL */
/* <<UniPG */
"h" ;
totlen=sizeof(long_option) - 1;
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
#ifdef USE_SYSTEM_GETOPT
@ -461,7 +463,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ----------------------------------------------------- */
default:
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
fprintf(stderr,"[WARNING] An invalid option has been ignored\n");
break;
}
}while(c != -1);

View File

@ -12,14 +12,34 @@ include_directories(
set(compare_images_SRCS compare_images.c
${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c
# ${OPENJPEG_SOURCE_DIR}/applications/codec/converttif.c
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
# ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
if(NOT USE_SYSTEM_GETOPT)
list(APPEND compare_images_SRCS
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
endif()
set(compare_dump_files_SRCS compare_dump_files.c
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
#${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
if(NOT USE_SYSTEM_GETOPT)
list(APPEND compare_dump_files_SRCS
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
endif()
set(compare_raw_files_SRCS compare_raw_files.c
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
#${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
if(NOT USE_SYSTEM_GETOPT)
list(APPEND compare_raw_files_SRCS
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
endif()
add_executable(compare_images ${compare_images_SRCS})
target_link_libraries(compare_images