[1.5] Rework r2768 in fact getopt_long is slightly different on GNU. Adapt signature...
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Tue, 18 Mar 2014 16:26:39 +0000 (16:26 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Tue, 18 Mar 2014 16:26:39 +0000 (16:26 +0000)
Update issue 301

applications/codec/image_to_j2k.c
applications/codec/j2k_dump.c
applications/codec/j2k_to_image.c
applications/common/opj_getopt.h

index ed8b4198a0e4e3f6675e072fb8d79acd0bdb0d1f..d9cafd6ace027f1d50575eb96d6492b982bd3f6a 100644 (file)
@@ -590,7 +590,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
                {"OutFor",REQ_ARG, NULL ,'O'},
                {"POC",REQ_ARG, NULL ,'P'},
                {"ROI",REQ_ARG, NULL ,'R'},
-               {"jpip",NO_ARG, NULL, 'J'}
+               {"jpip",NO_ARG, NULL, 'J'},
+               {0,0,0,0} /* GNU getopt_long requirement */
        };
 
        /* parse the command line */
@@ -600,12 +601,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
 #endif /* USE_JPWL */
                "h";
 
-       totlen=sizeof(long_option);
+       totlen=sizeof(long_option)-1;
        img_fol->set_out_format=0;
        raw_cp->rawWidth = 0;
 
        do{
+#ifdef USE_SYSTEM_GETOPT
+               c = opj_getopt_long(argc, argv, optlist,long_option,0);
+#else
                c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
+#endif
                if (c == -1)
                        break;
                switch (c) {
index 5ffc7736a2d0eb91710ac245e3bd6d5dcc53a382..63cce3a27c1f384b456129639d74f0ae0761181d 100644 (file)
@@ -201,15 +201,20 @@ 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'},
+               {0,0,0,0} /* GNU getopt_long requirement */
        };
        const char optlist[] = "i:o:h";
 
        OPJ_ARG_NOT_USED(indexfilename);
 
-       totlen=sizeof(long_option);
+       totlen=sizeof(long_option)-1;
        img_fol->set_out_format = 0;
        do {
+#ifdef USE_SYSTEM_GETOPT
+               c = opj_getopt_long(argc, argv,optlist,long_option,0);
+#else
                c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
+#endif
                if (c == -1)
                        break;
                switch (c) {
index b0dbf547cabf7a59ad4b46bee864c85ff83fe8b1..6f215a2cb71fcf5830e31bc7056f5ad75ae69908 100644 (file)
@@ -243,6 +243,7 @@ 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'},
+               {0,0,0,0} /* GNU getopt_long requirement */
        };
 
        const char optlist[] = "i:o:r:l:x:"
@@ -253,10 +254,14 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
 #endif /* USE_JPWL */
 /* <<UniPG */
                        "h"             ;
-       totlen=sizeof(long_option);
+       totlen=sizeof(long_option) - 1;
        img_fol->set_out_format = 0;
        do {
+#ifdef USE_SYSTEM_GETOPT
+               c = opj_getopt_long(argc, argv,optlist,long_option,0);
+#else
                c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
+#endif
                if (c == -1)
                        break;
                switch (c) {
index 1fa3558df7a2a328a7892c13c8b129d26eb95ab9..704701b1be7e4c42e52feea563b58e72b6104f3e 100644 (file)
@@ -2,6 +2,25 @@
 
 #include "opj_config.h"
 
+#ifdef USE_SYSTEM_GETOPT
+#include <getopt.h>
+
+#define opj_opterr opterr
+#define opj_optind optind
+#define opj_optopt optopt
+#define opj_optreset optreset
+#define opj_optarg optarg
+
+typedef struct option opj_option_t;
+
+#define NO_ARG no_argument
+#define REQ_ARG required_argument
+#define OPT_ARG optional_argument
+
+#define opj_getopt getopt
+#define opj_getopt_long getopt_long
+
+#else
 #ifndef _GETOPT_H_
 #define _GETOPT_H_
 
@@ -17,19 +36,6 @@ typedef struct opj_option
 #define REQ_ARG        1
 #define OPT_ARG        2
 
-#ifdef USE_SYSTEM_GETOPT
-#include <getopt.h>
-
-#define opj_opterr opterr
-#define opj_optind optind
-#define opj_optopt optopt
-#define opj_optreset optreset
-#define opj_optarg optarg
-
-#define opj_getopt getopt
-#define opj_getopt_long getopt_long
-
-#else
 extern int opj_opterr;
 extern int opj_optind;
 extern int opj_optopt;
@@ -41,5 +47,5 @@ extern int opj_getopt_long(int argc, char * const argv[], const char *optstring,
                        const opj_option_t *longopts, int totlen);
 extern void reset_options_reading(void);
 
-#endif /* USE_SYSTEM_GETOPT */
 #endif                         /* _GETOPT_H_ */
+#endif /* USE_SYSTEM_GETOPT */