renamed getopt.{c/h} to opj_getopt.{c/h} and forced the use of these files rather...
authorAntonin Descampe <antonin@gmail.com>
Thu, 1 Sep 2011 11:24:08 +0000 (11:24 +0000)
committerAntonin Descampe <antonin@gmail.com>
Thu, 1 Sep 2011 11:24:08 +0000 (11:24 +0000)
29 files changed:
CHANGES
CMake/CheckHaveGetopt.cmake [deleted file]
CMakeLists.txt
applications/JavaOpenJPEG/CMakeLists.txt
applications/JavaOpenJPEG/JavaOpenJPEG.c
applications/JavaOpenJPEG/JavaOpenJPEGDecoder.c
applications/JavaOpenJPEG/Makefile
applications/Makefile.am
applications/codec/CMakeLists.txt
applications/codec/Makefile.am
applications/codec/convert.c
applications/codec/image_to_j2k.c
applications/codec/j2k_dump.c
applications/codec/j2k_to_image.c
applications/codec/windirent.h
applications/common/getopt.c [deleted file]
applications/common/getopt.h [deleted file]
applications/common/opj_getopt.c [new file with mode: 0644]
applications/common/opj_getopt.h [new file with mode: 0644]
applications/mj2/CMakeLists.txt
applications/mj2/Makefile.am
applications/mj2/frames_to_mj2.c
applications/mj2/mj2_to_metadata.c
applications/mj2/mj2_to_metadata.vcproj
tests/CMakeLists.txt
tests/comparePGXimages.c
tests/compareRAWimages.c
tests/compare_dump_files.c
tests/nonregression/CMakeLists.txt

diff --git a/CHANGES b/CHANGES
index 078998663b25ac3c88ca7a1622e301c607b7b323..05a5c2f6d4f6d0a70a76fc81eed44e7afadf58a7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,9 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+September 1st, 2011
+! [antonin] renamed getopt.{c/h} to opj_getopt.{c/h} and forced the use of these files rather than the system ones. This fixed issue 78. Credit to Winfried.
+
 August 31, 2011
 * [mickael] fixed a segfault with fgets return value for some cases inside test function compare_dump_file()
 + [mickael] enhance the encoding test suite and remove unsued CONFIGURE_FILE into a CMakeList
diff --git a/CMake/CheckHaveGetopt.cmake b/CMake/CheckHaveGetopt.cmake
deleted file mode 100644 (file)
index c0fd5dc..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-# Check if getopt is present:
-INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
-SET(DONT_HAVE_GETOPT 1)
-IF(UNIX) #I am pretty sure only *nix sys have this anyway
-  CHECK_INCLUDE_FILE("getopt.h" CMAKE_HAVE_GETOPT_H)
-  # Seems like we need the contrary:
-  IF(CMAKE_HAVE_GETOPT_H)
-    SET(DONT_HAVE_GETOPT 0)
-  ENDIF(CMAKE_HAVE_GETOPT_H)
-ENDIF(UNIX)
-
-IF(DONT_HAVE_GETOPT)
-  ADD_DEFINITIONS(-DDONT_HAVE_GETOPT)
-ENDIF(DONT_HAVE_GETOPT)
-
index 2a0ef893bd1df593cf146b71dbdee626fd065a9a..1af3a073352dd3af0980c759f0db1a77e1751f8b 100644 (file)
@@ -110,10 +110,6 @@ ENDIF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
 # Test for some required system information.
 INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
 
-#-----------------------------------------------------------------------------
-# Test for getopt being available in this system
-INCLUDE (${OPENJPEG_SOURCE_DIR}/CMake/CheckHaveGetopt.cmake )
-
 #-----------------------------------------------------------------------------
 # Setup file for setting custom ctest vars
 CONFIGURE_FILE(
index 6b1720b3fd3d3b404a78c746fa000ec71c1077f3..ecc8340d33ded443163ad5567071a4c37c6ae81f 100644 (file)
@@ -4,16 +4,9 @@
 SET(common_SRCS
   ../codec/convert.c
   ../codec/index.c
+  ../common/opj_getopt.c
   )
 
-# If not getopt was found then add it to the lib:
-IF(DONT_HAVE_GETOPT)
-  SET(common_SRCS
-    ${common_SRCS}
-    ../common/getopt.c
-  )
-ENDIF(DONT_HAVE_GETOPT)
-
 
 # Headers file are located here:
 INCLUDE_DIRECTORIES(
index b1f03028c587e1964f9776cba7c5b71b2687b9f5..f03de1c3de06d69ccd1b05f1eb579c0789e863ea 100644 (file)
@@ -37,7 +37,7 @@
 #include <math.h>\r
 \r
 #include "openjpeg.h"\r
-#include "getopt.h"\r
+#include "opj_getopt.h"\r
 #include "convert.h"\r
 #include "index.h"\r
 #include "dirent.h"\r
@@ -492,7 +492,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_
 int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,\r
                                                                                                        img_fol_t *img_fol, char *indexfilename) {\r
        int i, j,totlen;\r
-       option_t long_option[]={\r
+       opj_option_t long_option[]={\r
                {"cinema2K",REQ_ARG, NULL ,'w'},\r
                {"cinema4K",NO_ARG, NULL ,'y'},\r
                {"ImgDir",REQ_ARG, NULL ,'z'},\r
@@ -523,7 +523,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
        reset_options_reading();\r
 \r
        while (1) {\r
-    int c = getopt_long(argc, argv, optlist,long_option,totlen);\r
+    int c = opj_getopt_long(argc, argv, optlist,long_option,totlen);\r
                if (c == -1)\r
                        break;\r
                switch (c) {\r
@@ -532,7 +532,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'o':                       /* output file */\r
                        {\r
-                               char *outfile = optarg;\r
+                               char *outfile = opj_optarg;\r
                                parameters->cod_format = get_file_format(outfile);\r
                                switch(parameters->cod_format) {\r
                                        case J2K_CFMT:\r
@@ -550,14 +550,14 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'O':                       /* output format */\r
                                {\r
                                        char outformat[50];\r
-                                       char *of = optarg;\r
+                                       char *of = opj_optarg;\r
                                        sprintf(outformat,".%s",of);\r
                                        img_fol->set_out_format = 1;\r
                                        parameters->cod_format = get_file_format(outformat);\r
                                        switch(parameters->cod_format) {\r
                                                case J2K_CFMT:\r
                                                case JP2_CFMT:\r
-                                                       img_fol->out_format = optarg;\r
+                                                       img_fol->out_format = opj_optarg;\r
                                                        break;\r
                                                default:\r
                                                        fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n");\r
@@ -572,7 +572,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'r':                       /* rates rates/distorsion */\r
                        {\r
-                               char *s = optarg;\r
+                               char *s = opj_optarg;\r
                                while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {\r
                                        parameters->tcp_numlayers++;\r
                                        while (*s && *s != ',') {\r
@@ -590,7 +590,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'q':                       /* add fixed_quality */\r
                        {\r
-                               char *s = optarg;\r
+                               char *s = opj_optarg;\r
                                while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {\r
                                        parameters->tcp_numlayers++;\r
                                        while (*s && *s != ',') {\r
@@ -612,7 +612,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                int *row = NULL, *col = NULL;\r
                                int numlayers = 0, numresolution = 0, matrix_width = 0;\r
 \r
-                               char *s = optarg;\r
+                               char *s = opj_optarg;\r
                                sscanf(s, "%d", &numlayers);\r
                                s++;\r
                                if (numlayers > 9)\r
@@ -656,7 +656,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 't':                       /* tiles */\r
                        {\r
-                               sscanf(optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);\r
+                               sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);\r
                                parameters->tile_size_on = true;\r
                        }\r
                        break;\r
@@ -665,7 +665,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'n':                       /* resolution */\r
                        {\r
-                               sscanf(optarg, "%d", &parameters->numresolution);\r
+                               sscanf(opj_optarg, "%d", &parameters->numresolution);\r
                        }\r
                        break;\r
 \r
@@ -675,7 +675,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                char sep;\r
                                int res_spec = 0;\r
 \r
-                               char *s = optarg;\r
+                               char *s = opj_optarg;\r
                                do {\r
                                        sep = 0;\r
                                        sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],\r
@@ -694,7 +694,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'b':                       /* code-block dimension */\r
                        {\r
                                int cblockw_init = 0, cblockh_init = 0;\r
-                               sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);\r
+                               sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);\r
                                if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024\r
                                        || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {\r
                                        fprintf(stderr,\r
@@ -711,7 +711,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'x':                       /* creation of index file */\r
                        {\r
-                               char *index = optarg;\r
+                               char *index = opj_optarg;\r
                                strncpy(indexfilename, index, OPJ_PATH_LEN);\r
                        }\r
                        break;\r
@@ -722,7 +722,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        {\r
                                char progression[4];\r
 \r
-                               strncpy(progression, optarg, 4);\r
+                               strncpy(progression, opj_optarg, 4);\r
                                parameters->prog_order = give_progression(progression);\r
                                if (parameters->prog_order == -1) {\r
                                        fprintf(stderr, "Unrecognized progression order "\r
@@ -736,7 +736,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 's':                       /* subsampling factor */\r
                        {\r
-                               if (sscanf(optarg, "%d,%d", &parameters->subsampling_dx,\r
+                               if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,\r
                                     &parameters->subsampling_dy) != 2) {\r
                                        fprintf(stderr, "'-s' sub-sampling argument error !  [-s dx,dy]\n");\r
                                        return 1;\r
@@ -748,7 +748,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'd':                       /* coordonnate of the reference grid */\r
                        {\r
-                               if (sscanf(optarg, "%d,%d", &parameters->image_offset_x0,\r
+                               if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,\r
                                     &parameters->image_offset_y0) != 2) {\r
                                        fprintf(stderr, "-d 'coordonnate of the reference grid' argument "\r
             "error !! [-d x0,y0]\n");\r
@@ -770,7 +770,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                int numpocs = 0;                /* number of progression order change (POC) default 0 */\r
                                opj_poc_t *POC = NULL;  /* POC : used in case of Progression order change */\r
 \r
-                               char *s = optarg;\r
+                               char *s = opj_optarg;\r
                                POC = parameters->POC;\r
 \r
                                while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,\r
@@ -812,7 +812,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'M':                       /* Mode switch pas tous au point !! */\r
                        {\r
                                int value = 0;\r
-                               if (sscanf(optarg, "%d", &value) == 1) {\r
+                               if (sscanf(opj_optarg, "%d", &value) == 1) {\r
                                        for (i = 0; i <= 5; i++) {\r
                                                int cache = value & (1 << i);\r
                                                if (cache)\r
@@ -826,7 +826,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'R':                       /* ROI */\r
                        {\r
-                               if (sscanf(optarg, "c=%d,U=%d", &parameters->roi_compno,\r
+                               if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,\r
                                            &parameters->roi_shift) != 2) {\r
                                        fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");\r
                                        return 1;\r
@@ -838,7 +838,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'T':                       /* Tile offset */\r
                        {\r
-                               if (sscanf(optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {\r
+                               if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {\r
                                        fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");\r
                                        return 1;\r
                                }\r
@@ -849,9 +849,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 \r
                        case 'C':                       /* add a comment */\r
                        {\r
-                               parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);\r
+                               parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);\r
                                if(parameters->cp_comment) {\r
-                                       strcpy(parameters->cp_comment, optarg);\r
+                                       strcpy(parameters->cp_comment, opj_optarg);\r
                                }\r
                        }\r
                        break;\r
@@ -869,7 +869,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        \r
                        case 'v':                       /* Tile part generation*/\r
                        {\r
-                               parameters->tp_flag = optarg[0];\r
+                               parameters->tp_flag = opj_optarg[0];\r
                                parameters->tp_on = 1;\r
                        }\r
                        break;  \r
@@ -878,8 +878,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        \r
                        case 'z':                       /* Image Directory path */\r
                        {\r
-                               img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);\r
-                               strcpy(img_fol->imgdirpath,optarg);\r
+                               img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);\r
+                               strcpy(img_fol->imgdirpath,opj_optarg);\r
                                img_fol->set_imgdir=1;\r
                        }\r
                        break;\r
@@ -889,7 +889,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'w':                       /* Digital Cinema 2K profile compliance*/\r
                        {\r
                                int fps=0;\r
-                               sscanf(optarg,"%d",&fps);\r
+                               sscanf(opj_optarg,"%d",&fps);\r
                                if(fps == 24){\r
                                        parameters->cp_cinema = CINEMA2K_24;\r
                                }else if(fps == 48 ){\r
@@ -933,7 +933,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                /* search for different protection methods */\r
 \r
                                /* break the option in comma points and parse the result */\r
-                               token = strtok(optarg, ",");\r
+                               token = strtok(opj_optarg, ",");\r
                                while(token != NULL) {\r
 \r
                                        /* search header error protection method */\r
index decc1373d122e623a434789dcab0129d6bcc2a95..a273028c6f1d72572fa52d24128471e3551aaa6b 100644 (file)
@@ -37,7 +37,7 @@
 #include <math.h>\r
 \r
 #include "openjpeg.h"\r
-#include "getopt.h"\r
+#include "opj_getopt.h"\r
 #include "convert.h"\r
 #include "dirent.h"\r
 #include "org_openJpeg_OpenJPEGJavaDecoder.h"\r
@@ -206,7 +206,7 @@ int get_file_format(char *filename) {
 int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {\r
        /* parse the command line */\r
        int totlen;\r
-       option_t long_option[]={\r
+       opj_option_t long_option[]={\r
                {"ImgDir",REQ_ARG, NULL ,'y'},\r
                {"OutFor",REQ_ARG, NULL ,'O'},\r
        };\r
@@ -229,13 +229,13 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
        reset_options_reading();\r
 \r
        while (1) {\r
-               int c = getopt_long(argc, argv,optlist,long_option,totlen);\r
+               int c = opj_getopt_long(argc, argv,optlist,long_option,totlen);\r
                if (c == -1)\r
                        break;\r
                switch (c) {\r
                        case 'i':                       /* input file */\r
                        {\r
-                               char *infile = optarg;\r
+                               char *infile = opj_optarg;\r
                                parameters->decod_format = get_file_format(infile);\r
                                switch(parameters->decod_format) {\r
                                        case J2K_CFMT:\r
@@ -256,7 +256,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 \r
                        case 'o':                       /* output file */\r
                        {\r
-                               char *outfile = optarg;\r
+                               char *outfile = opj_optarg;\r
                                parameters->cod_format = get_file_format(outfile);\r
                                switch(parameters->cod_format) {\r
                                        case PGX_DFMT:\r
@@ -279,7 +279,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                        case 'O':                       /* output format */\r
                        {\r
                                char outformat[50];\r
-                               char *of = optarg;\r
+                               char *of = opj_optarg;\r
                                sprintf(outformat,".%s",of);\r
                                img_fol->set_out_format = 1;\r
                                parameters->cod_format = get_file_format(outformat);\r
@@ -315,7 +315,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 \r
                        case 'r':               /* reduce option */\r
                        {\r
-                               sscanf(optarg, "%d", &parameters->cp_reduce);\r
+                               sscanf(opj_optarg, "%d", &parameters->cp_reduce);\r
                        }\r
                        break;\r
                        \r
@@ -324,7 +324,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 \r
                        case 'l':               /* layering option */\r
                        {\r
-                               sscanf(optarg, "%d", &parameters->cp_layer);\r
+                               sscanf(opj_optarg, "%d", &parameters->cp_layer);\r
                        }\r
                        break;\r
                        \r
@@ -338,8 +338,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 \r
                        case 'y':                       /* Image Directory path */\r
                                {\r
-                                       img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);\r
-                                       strcpy(img_fol->imgdirpath,optarg);\r
+                                       img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);\r
+                                       strcpy(img_fol->imgdirpath,opj_optarg);\r
                                        img_fol->set_imgdir=1;\r
                                }\r
                                break;\r
@@ -351,7 +351,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                        {\r
                                char *token = NULL;\r
 \r
-                               token = strtok(optarg, ",");\r
+                               token = strtok(opj_optarg, ",");\r
                                while(token != NULL) {\r
 \r
                                        /* search expected number of components */\r
@@ -418,7 +418,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                                /* ----------------------------------------------------- */\r
                        \r
                        default:\r
-                               fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);\r
+                               fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);\r
                                break;\r
                }\r
        }\r
index 9ac3e4070130bcb14a826121e2660771856ab1ee..74d94056a00cd72bfd777cdea675a34b456804e8 100644 (file)
@@ -5,10 +5,10 @@ CFLAGS = -O3 -lstdc++ # -g -p -pg
 all: j2k_to_image image_to_j2k
 
 j2k_to_image: j2k_to_image.c ../libopenjpeg.a
-       gcc $(CFLAGS) ../common/getopt.c convert.c j2k_to_image.c -o j2k_to_image -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
+       gcc $(CFLAGS) ../common/opj_getopt.c convert.c j2k_to_image.c -o j2k_to_image -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
 
 image_to_j2k: image_to_j2k.c ../libopenjpeg.a
-       gcc $(CFLAGS) ../common/getopt.c convert.c image_to_j2k.c -o image_to_j2k -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
+       gcc $(CFLAGS) ../common/opj_getopt.c convert.c image_to_j2k.c -o image_to_j2k -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
 
 clean:
        rm -f j2k_to_image image_to_j2k
index e7d11e52f88bbd3d7daf38aae27fd444c234db69..113afbe8afebf53ea591d1250c8354325b89114d 100644 (file)
@@ -15,5 +15,5 @@ CMakeLists.txt \
 common/color.c \
 common/color.h \
 common/format_defs.h \
-common/getopt.c \
-common/getopt.h
+common/opj_getopt.c \
+common/opj_getopt.h
index 8c1d3c25ac9414b7aa16dd85b5333d39dafb43c1..77759f7b4e8b6c7bbf3c2f9a795c42d27fa84480 100644 (file)
@@ -5,15 +5,8 @@ SET(common_SRCS
   convert.c
   index.c
   ${OPENJPEG_SOURCE_DIR}/applications/common/color.c
-)
-
-# If not getopt was found then add it to the lib:
-IF(DONT_HAVE_GETOPT)
-  SET(common_SRCS
-    ${common_SRCS}
-    ${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c
+  ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
   )
-ENDIF(DONT_HAVE_GETOPT)
 
 # Headers file are located here:
 INCLUDE_DIRECTORIES(
index 10542b04b61fb827bec9b2d1b10c10c8824f1765..17be3b881182b6cbf2979acd59c2304043e69f52 100644 (file)
@@ -22,7 +22,7 @@ j2k_to_image_CFLAGS =
 j2k_to_image_LDADD = $(top_builddir)/libopenjpeg/libopenjpeg.la @LCMS1_LIBS@ @LCMS2_LIBS@ @TIFF_LIBS@ @PNG_LIBS@ -lm
 j2k_to_image_SOURCES = \
 ../common/color.c \
-../common/getopt.c \
+../common/opj_getopt.c \
 convert.c \
 index.c \
 j2k_to_image.c \
@@ -41,7 +41,7 @@ image_to_j2k_CPPFLAGS = \
 image_to_j2k_CFLAGS = 
 image_to_j2k_LDADD = $(top_builddir)/libopenjpeg/libopenjpeg.la @TIFF_LIBS@ @PNG_LIBS@ -lm
 image_to_j2k_SOURCES = \
-../common/getopt.c \
+../common/opj_getopt.c \
 convert.c \
 index.c \
 image_to_j2k.c \
@@ -60,10 +60,10 @@ j2k_dump_CPPFLAGS = \
 j2k_dump_CFLAGS = 
 j2k_dump_LDADD = $(top_builddir)/libopenjpeg/libopenjpeg.la -lm
 j2k_dump_SOURCES = \
-../common/getopt.c \
+../common/opj_getopt.c \
 index.c \
 j2k_dump.c \
-../common/getopt.h \
+../common/opj_getopt.h \
 index.h
 
 JPWL_j2k_to_image_CPPFLAGS = \
@@ -81,7 +81,7 @@ JPWL_j2k_to_image_CFLAGS =
 JPWL_j2k_to_image_LDADD = $(top_builddir)/libopenjpeg/jpwl/libopenjpeg_JPWL.la  @LCMS1_LIBS@ @LCMS2_LIBS@ @TIFF_LIBS@ @PNG_LIBS@
 JPWL_j2k_to_image_SOURCES = \
 ../common/color.c \
-../common/getopt.c \
+../common/opj_getopt.c \
 index.c \
 convert.c \
 j2k_to_image.c
@@ -99,7 +99,7 @@ JPWL_image_to_j2k_CFLAGS =
 JPWL_image_to_j2k_LDADD = $(top_builddir)/libopenjpeg/jpwl/libopenjpeg_JPWL.la @TIFF_LIBS@ @PNG_LIBS@
 
 JPWL_image_to_j2k_SOURCES = \
-../common/getopt.c \
+../common/opj_getopt.c \
 index.c \
 convert.c \
 image_to_j2k.c
index c7afc07439773cb684d7bfc966a2f4b88ce32c8e..fae8b1311fa7172af23115c415c160aa06d2edf6 100644 (file)
@@ -67,9 +67,9 @@ static int int_floorlog2(int a) {
 
  <<-- <<-- <<-- <<-- */
 
+#ifdef INFORMATION_ONLY
 // TGA header definition.
-#pragma pack(push,1) // Pack structure byte aligned
-typedef struct tga_header
+struct tga_header
 {                           
     unsigned char   id_length;              /* Image id field length    */
     unsigned char   colour_map_type;        /* Colour map type          */
@@ -89,35 +89,66 @@ typedef struct tga_header
     unsigned short  image_height;           /* Image height             */
     unsigned char   pixel_depth;            /* Pixel depth              */
     unsigned char   image_desc;             /* Image descriptor         */
-} tga_header;
-#pragma pack(pop) // Return to normal structure packing alignment.
+};
+#endif /* INFORMATION_ONLY */
+
+static unsigned short get_ushort(unsigned short val) {
+
+#ifdef ORDER_BIGENDIAN
+    return( ((val & 0xff) << 8) + (val >> 8) );
+#else
+    return( val );
+#endif
+
+}
+
+#define TGA_HEADER_SIZE 18
 
 int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, 
        unsigned int *width, unsigned int *height, int *flip_image)
 {
        int palette_size;
-       tga_header tga ;
+       unsigned char *tga ;
+       unsigned char id_len, cmap_type, image_type;
+       unsigned char pixel_depth, image_desc;
+       unsigned short cmap_index, cmap_len, cmap_entry_size;
+       unsigned short x_origin, y_origin, image_w, image_h;
 
        if (!bits_per_pixel || !width || !height || !flip_image)
                return 0;
-       
-       // Read TGA header
-       if ( fread((unsigned char*)&tga, sizeof(tga_header), 1, fp) != 1 )
+       tga = (unsigned char*)malloc(18);
+
+       if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 )
        {
                fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
            return 0 ;
        }
+       id_len = (unsigned char)tga[0];
+       cmap_type = (unsigned char)tga[1];
+       image_type = (unsigned char)tga[2];
+       cmap_index = get_ushort(*(unsigned short*)(&tga[3]));
+       cmap_len = get_ushort(*(unsigned short*)(&tga[5]));
+       cmap_entry_size = (unsigned char)tga[7];
 
-       *bits_per_pixel = tga.pixel_depth;
-       
-       *width  = tga.image_width;
-       *height = tga.image_height ;
+
+       x_origin = get_ushort(*(unsigned short*)(&tga[8]));
+       y_origin = get_ushort(*(unsigned short*)(&tga[10]));
+       image_w = get_ushort(*(unsigned short*)(&tga[12]));
+       image_h = get_ushort(*(unsigned short*)(&tga[14]));
+       pixel_depth = (unsigned char)tga[16];
+       image_desc  = (unsigned char)tga[17];
+
+       free(tga);
+
+       *bits_per_pixel = (unsigned int)pixel_depth;
+       *width  = (unsigned int)image_w;
+       *height = (unsigned int)image_h;
 
        // Ignore tga identifier, if present ...
-       if (tga.id_length)
+       if (id_len)
        {
-               unsigned char *id = (unsigned char *) malloc(tga.id_length);
-               if ( !fread(id, tga.id_length, 1, fp) )
+               unsigned char *id = (unsigned char *) malloc(id_len);
+               if ( !fread(id, id_len, 1, fp) )
                {
                        fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
                        free(id);
@@ -129,16 +160,16 @@ int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
        // Test for compressed formats ... not yet supported ...
        // Note :-  9 - RLE encoded palettized.
        //                 10 - RLE encoded RGB.
-       if (tga.image_type > 8)
+       if (image_type > 8)
        {
                fprintf(stderr, "Sorry, compressed tga files are not currently supported.\n");
                return 0 ;
        }
 
-       *flip_image = !(tga.image_desc & 32);
+       *flip_image = !(image_desc & 32);
 
        // Palettized formats are not yet supported, skip over the palette, if present ... 
-       palette_size = tga.colour_map_length * (tga.colour_map_entry_size/8);
+       palette_size = cmap_len * (cmap_entry_size/8);
        
        if (palette_size>0)
        {
@@ -151,31 +182,56 @@ int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
 int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height, 
        opj_bool flip_image)
 {
-       tga_header tga;
+       unsigned short image_w, image_h, us0;
+       unsigned char uc0, image_type;
+       unsigned char pixel_depth, image_desc;
 
        if (!bits_per_pixel || !width || !height)
                return 0;
 
-       memset(&tga, 0, sizeof(tga_header));
+       pixel_depth = 0;
 
        if ( bits_per_pixel < 256 )
-               tga.pixel_depth = (unsigned char)bits_per_pixel;
+               pixel_depth = (unsigned char)bits_per_pixel;
        else{
                fprintf(stderr,"ERROR: Wrong bits per pixel inside tga_header");
                return 0;
        }
-       tga.image_width  = (unsigned short)width;
-       tga.image_height = (unsigned short)height;
-       tga.image_type = 2; // Uncompressed.
-       tga.image_desc = 8; // 8 bits per component.
+       uc0 = 0;
 
-       if (flip_image)
-               tga.image_desc |= 32;
+       if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; // id_length
+       if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; // colour_map_type
+
+       image_type = 2; // Uncompressed.
+       if(fwrite(&image_type, 1, 1, fp) != 1) goto fails;
+
+       us0 = 0;
+       if(fwrite(&us0, 2, 1, fp) != 1) goto fails; // colour_map_index
+       if(fwrite(&us0, 2, 1, fp) != 1) goto fails; // colour_map_length
+       if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; // colour_map_entry_size
+
+       if(fwrite(&us0, 2, 1, fp) != 1) goto fails; // x_origin
+       if(fwrite(&us0, 2, 1, fp) != 1) goto fails; // y_origin
+
+       image_w = (unsigned short)width;
+       image_h = (unsigned short) height;
+
+       if(fwrite(&image_w, 2, 1, fp) != 1) goto fails;
+       if(fwrite(&image_h, 2, 1, fp) != 1) goto fails;
 
-       // Write TGA header
-       fwrite((unsigned char*)&tga, sizeof(tga_header), 1, fp);
+       if(fwrite(&pixel_depth, 1, 1, fp) != 1) goto fails;
+
+       image_desc = 8; // 8 bits per component.
+
+       if (flip_image)
+               image_desc |= 32;
+       if(fwrite(&image_desc, 1, 1, fp) != 1) goto fails;
 
        return 1;
+
+fails:
+       fputs("\nwrite_tgaheader: write ERROR\n", stderr);
+       return 0;
 }
 
 opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
index 92353970ebd974ec84480b574c2e104bca255a16..fa04a6fba44f2ab3412f7a3eb1ca58fd75779254 100644 (file)
@@ -51,7 +51,7 @@
 
 #include "opj_config.h"
 #include "openjpeg.h"
-#include "getopt.h"
+#include "opj_getopt.h"
 #include "convert.h"
 #include "index.h"
 
@@ -574,7 +574,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_
 int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                                                                                        img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
        int i, j, totlen, c;
-       option_t long_option[]={
+       opj_option_t long_option[]={
                {"cinema2K",REQ_ARG, NULL ,'w'},
                {"cinema4K",NO_ARG, NULL ,'y'},
                {"ImgDir",REQ_ARG, NULL ,'z'},
@@ -598,13 +598,13 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
        raw_cp->rawWidth = 0;
 
        do{
-               c = getopt_long(argc, argv, optlist,long_option,totlen);
+               c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
                if (c == -1)
                        break;
                switch (c) {
                        case 'i':                       /* input file */
                        {
-                               char *infile = optarg;
+                               char *infile = opj_optarg;
                                parameters->decod_format = get_file_format(infile);
                                switch(parameters->decod_format) {
                                        case PGX_DFMT:
@@ -630,7 +630,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'o':                       /* output file */
                        {
-                               char *outfile = optarg;
+                               char *outfile = opj_optarg;
                                parameters->cod_format = get_file_format(outfile);
                                switch(parameters->cod_format) {
                                        case J2K_CFMT:
@@ -648,14 +648,14 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'O':                       /* output format */
                                {
                                        char outformat[50];
-                                       char *of = optarg;
+                                       char *of = opj_optarg;
                                        sprintf(outformat,".%s",of);
                                        img_fol->set_out_format = 1;
                                        parameters->cod_format = get_file_format(outformat);
                                        switch(parameters->cod_format) {
                                                case J2K_CFMT:
                                                case JP2_CFMT:
-                                                       img_fol->out_format = optarg;
+                                                       img_fol->out_format = opj_optarg;
                                                        break;
                                                default:
                                                        fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n");
@@ -670,7 +670,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'r':                       /* rates rates/distorsion */
                        {
-                               char *s = optarg;
+                               char *s = opj_optarg;
                                parameters->tcp_numlayers = 0;
                                while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
                                        parameters->tcp_numlayers++;
@@ -691,7 +691,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'F':                       /* Raw image format parameters */
                        {
                                char signo;
-                               char *s = optarg;
+                               char *s = opj_optarg;
                                if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) {
                                        if (signo == 's') {
                                                raw_cp->rawSigned = OPJ_TRUE;
@@ -724,7 +724,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'q':                       /* add fixed_quality */
                        {
-                               char *s = optarg;
+                               char *s = opj_optarg;
                                while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
                                        parameters->tcp_numlayers++;
                                        while (*s && *s != ',') {
@@ -746,7 +746,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                int *row = NULL, *col = NULL;
                                int numlayers = 0, numresolution = 0, matrix_width = 0;
 
-                               char *s = optarg;
+                               char *s = opj_optarg;
                                sscanf(s, "%d", &numlayers);
                                s++;
                                if (numlayers > 9)
@@ -790,7 +790,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 't':                       /* tiles */
                        {
-                               sscanf(optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
+                               sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
                                parameters->tile_size_on = OPJ_TRUE;
                        }
                        break;
@@ -799,7 +799,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'n':                       /* resolution */
                        {
-                               sscanf(optarg, "%d", &parameters->numresolution);
+                               sscanf(opj_optarg, "%d", &parameters->numresolution);
                        }
                        break;
 
@@ -809,7 +809,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                char sep;
                                int res_spec = 0;
 
-                               char *s = optarg;
+                               char *s = opj_optarg;
                                do {
                                        sep = 0;
                                        sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
@@ -828,7 +828,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'b':                       /* code-block dimension */
                        {
                                int cblockw_init = 0, cblockh_init = 0;
-                               sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
+                               sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
                                if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
                                        || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
                                        fprintf(stderr,
@@ -845,7 +845,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'x':                       /* creation of index file */
                        {
-                               char *index = optarg;
+                               char *index = opj_optarg;
                                strncpy(indexfilename, index, OPJ_PATH_LEN);
                        }
                        break;
@@ -856,7 +856,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        {
                                char progression[4];
 
-                               strncpy(progression, optarg, 4);
+                               strncpy(progression, opj_optarg, 4);
                                parameters->prog_order = give_progression(progression);
                                if (parameters->prog_order == -1) {
                                        fprintf(stderr, "Unrecognized progression order "
@@ -870,7 +870,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 's':                       /* subsampling factor */
                        {
-                               if (sscanf(optarg, "%d,%d", &parameters->subsampling_dx,
+                               if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,
                                     &parameters->subsampling_dy) != 2) {
                                        fprintf(stderr, "'-s' sub-sampling argument error !  [-s dx,dy]\n");
                                        return 1;
@@ -882,7 +882,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'd':                       /* coordonnate of the reference grid */
                        {
-                               if (sscanf(optarg, "%d,%d", &parameters->image_offset_x0,
+                               if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,
                                     &parameters->image_offset_y0) != 2) {
                                        fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
             "error !! [-d x0,y0]\n");
@@ -904,7 +904,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                int numpocs = 0;                /* number of progression order change (POC) default 0 */
                                opj_poc_t *POC = NULL;  /* POC : used in case of Progression order change */
 
-                               char *s = optarg;
+                               char *s = opj_optarg;
                                POC = parameters->POC;
 
                                while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
@@ -946,7 +946,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'M':                       /* Mode switch pas tous au point !! */
                        {
                                int value = 0;
-                               if (sscanf(optarg, "%d", &value) == 1) {
+                               if (sscanf(opj_optarg, "%d", &value) == 1) {
                                        for (i = 0; i <= 5; i++) {
                                                int cache = value & (1 << i);
                                                if (cache)
@@ -960,7 +960,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'R':                       /* ROI */
                        {
-                               if (sscanf(optarg, "c=%d,U=%d", &parameters->roi_compno,
+                               if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,
                                            &parameters->roi_shift) != 2) {
                                        fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
                                        return 1;
@@ -972,7 +972,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'T':                       /* Tile offset */
                        {
-                               if (sscanf(optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
+                               if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
                                        fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
                                        return 1;
                                }
@@ -983,9 +983,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'C':                       /* add a comment */
                        {
-                               parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);
+                               parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
                                if(parameters->cp_comment) {
-                                       strcpy(parameters->cp_comment, optarg);
+                                       strcpy(parameters->cp_comment, opj_optarg);
                                }
                        }
                        break;
@@ -1003,7 +1003,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'v':                       /* Tile part generation*/
                        {
-                               parameters->tp_flag = optarg[0];
+                               parameters->tp_flag = opj_optarg[0];
                                parameters->tp_on = 1;
                        }
                        break;
@@ -1012,8 +1012,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
 
                        case 'z':                       /* Image Directory path */
                        {
-                               img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
-                               strcpy(img_fol->imgdirpath,optarg);
+                               img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
+                               strcpy(img_fol->imgdirpath,opj_optarg);
                                img_fol->set_imgdir=1;
                        }
                        break;
@@ -1023,7 +1023,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                        case 'w':                       /* Digital Cinema 2K profile compliance*/
                        {
                                int fps=0;
-                               sscanf(optarg,"%d",&fps);
+                               sscanf(opj_optarg,"%d",&fps);
                                if(fps == 24){
                                        parameters->cp_cinema = CINEMA2K_24;
                                }else if(fps == 48 ){
@@ -1067,7 +1067,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
                                /* search for different protection methods */
 
                                /* break the option in comma points and parse the result */
-                               token = strtok(optarg, ",");
+                               token = strtok(opj_optarg, ",");
                                while(token != NULL) {
 
                                        /* search header error protection method */
index 02f8316c0d43724d5b237d44c742bf9c4f0f549c..b490f4d49d1ca0e3c6c755161b2b1f3a8adc2673 100644 (file)
@@ -47,7 +47,7 @@
 #include "openjpeg.h"
 #include "j2k.h"
 #include "jp2.h"
-#include "getopt.h"
+#include "opj_getopt.h"
 #include "convert.h"
 #include "index.h"
 
@@ -197,7 +197,7 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
 int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
        /* parse the command line */
        int totlen, c;
-       option_t long_option[]={
+       opj_option_t long_option[]={
                {"ImgDir",REQ_ARG, NULL ,'y'},
        };
        const char optlist[] = "i:o:h";
@@ -207,13 +207,13 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
        totlen=sizeof(long_option);
        img_fol->set_out_format = 0;
        do {
-               c = getopt_long(argc, argv,optlist,long_option,totlen);
+               c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
                if (c == -1)
                        break;
                switch (c) {
                        case 'i':                       /* input file */
                        {
-                               char *infile = optarg;
+                               char *infile = opj_optarg;
                                parameters->decod_format = get_file_format(infile);
                                switch(parameters->decod_format) {
                                        case J2K_CFMT:
@@ -234,7 +234,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'o':     /* output file */
                        {
-                         char *outfile = optarg;
+                         char *outfile = opj_optarg;
                          strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
                        }
                        break;
@@ -249,8 +249,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'y':                       /* Image Directory path */
                                {
-                                       img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
-                                       strcpy(img_fol->imgdirpath,optarg);
+                                       img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
+                                       strcpy(img_fol->imgdirpath,opj_optarg);
                                        img_fol->set_imgdir=1;
                                }
                                break;
@@ -258,7 +258,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, optarg);
+                               fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
                                break;
                }
        }while(c != -1);
index 2b4213693874d43b3fe55d1d8a4136727fde3705..85bca04ccb8e65d0d66652359ce047372c463248 100644 (file)
@@ -51,7 +51,7 @@
 
 #include "opj_config.h"
 #include "openjpeg.h"
-#include "getopt.h"
+#include "opj_getopt.h"
 #include "convert.h"
 #include "index.h"
 
@@ -238,7 +238,7 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
 int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
        /* parse the command line */
        int totlen, c;
-       option_t long_option[]={
+       opj_option_t long_option[]={
                {"ImgDir",REQ_ARG, NULL ,'y'},
                {"OutFor",REQ_ARG, NULL ,'O'},
        };
@@ -254,13 +254,13 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
        totlen=sizeof(long_option);
        img_fol->set_out_format = 0;
        do {
-               c = getopt_long(argc, argv,optlist,long_option,totlen);
+               c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
                if (c == -1)
                        break;
                switch (c) {
                        case 'i':                       /* input file */
                        {
-                               char *infile = optarg;
+                               char *infile = opj_optarg;
                                parameters->decod_format = get_file_format(infile);
                                switch(parameters->decod_format) {
                                        case J2K_CFMT:
@@ -281,7 +281,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'o':                       /* output file */
                        {
-                               char *outfile = optarg;
+                               char *outfile = opj_optarg;
                                parameters->cod_format = get_file_format(outfile);
                                switch(parameters->cod_format) {
                                        case PGX_DFMT:
@@ -305,7 +305,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                        case 'O':                       /* output format */
                        {
                                char outformat[50];
-                               char *of = optarg;
+                               char *of = opj_optarg;
                                sprintf(outformat,".%s",of);
                                img_fol->set_out_format = 1;
                                parameters->cod_format = get_file_format(outformat);
@@ -344,7 +344,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'r':               /* reduce option */
                        {
-                               sscanf(optarg, "%d", &parameters->cp_reduce);
+                               sscanf(opj_optarg, "%d", &parameters->cp_reduce);
                        }
                        break;
                        
@@ -353,7 +353,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'l':               /* layering option */
                        {
-                               sscanf(optarg, "%d", &parameters->cp_layer);
+                               sscanf(opj_optarg, "%d", &parameters->cp_layer);
                        }
                        break;
                        
@@ -367,15 +367,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
 
                        case 'y':                       /* Image Directory path */
                                {
-                                       img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
-                                       strcpy(img_fol->imgdirpath,optarg);
+                                       img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
+                                       strcpy(img_fol->imgdirpath,opj_optarg);
                                        img_fol->set_imgdir=1;
                                }
                                break;
                                /* ----------------------------------------------------- */                                                             
                        case 'x':                       /* Creation of index file */
                                {
-                                       char *index = optarg;
+                                       char *index = opj_optarg;
                                        strncpy(indexfilename, index, OPJ_PATH_LEN);
                                }
                                break;
@@ -387,7 +387,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
                        {
                                char *token = NULL;
 
-                               token = strtok(optarg, ",");
+                               token = strtok(opj_optarg, ",");
                                while(token != NULL) {
 
                                        /* search expected number of components */
@@ -454,7 +454,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, optarg);
+                               fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
                                break;
                }
        }while(c != -1);
index 6bcc7787e2c1cb455dd6fe2f777b8b995dba4411..7dd7fef343acefe20683efa8ada16a06a6b3248a 100644 (file)
 #   error "not implemented"\r
 # elif defined(__sgi)                          /* Silicon Graphics */\r
 #   define HAVE_DIRENT_H\r
-# elif defined(sun) || defined(_sun)           /* Sun Solaris */\r
+# elif defined(sun) || defined(__sun)           /* Sun Solaris */\r
 #   define HAVE_DIRENT_H\r
 # elif defined(__FreeBSD__)                    /* FreeBSD */\r
 #   define HAVE_DIRENT_H\r
diff --git a/applications/common/getopt.c b/applications/common/getopt.c
deleted file mode 100644 (file)
index 3edd969..0000000
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright (c) 1987, 1993, 1994
- *     The Regents of the University of California.  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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-/* last review : october 29th, 2002 */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getopt.c   8.3 (Berkeley) 4/27/95";
-#endif                         /* LIBC_SCCS and not lint */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int opterr = 1,                        /* if error message should be printed */
- optind = 1,                   /* index into parent argv vector */
- optopt,                       /* character checked for validity */
- optreset;                     /* reset getopt */
-const char *optarg;                    /* argument associated with option */
-
-typedef struct option
-{
-       const char *name;
-       int has_arg;
-       int *flag;
-       int val;
-}option_t;
-
-#define        BADCH   (int)'?'
-#define        BADARG  (int)':'
-#define        EMSG    ""
-
-/* As this class remembers its values from one Java call to the other, reset the values before each use */
-void reset_options_reading(void) {
-       opterr = 1;
-       optind = 1;
-}
-
-/*
- * getopt --
- *     Parse argc/argv argument vector.
- */
-int getopt(int nargc, char *const *nargv, const char *ostr) {
-#  define __progname nargv[0]
-  static const char *place = EMSG;     /* option letter processing */
-  char *oli;                   /* option letter list index */
-
-  if (optreset || !*place) {   /* update scanning pointer */
-    optreset = 0;
-    if (optind >= nargc || *(place = nargv[optind]) != '-') {
-      place = EMSG;
-      return (-1);
-    }
-    if (place[1] && *++place == '-') { /* found "--" */
-      ++optind;
-      place = EMSG;
-      return (-1);
-    }
-  }                            /* option letter okay? */
-  if ((optopt = (int) *place++) == (int) ':' ||
-      !(oli = strchr(ostr, optopt))) {
-    /*
-     * if the user didn't specify '-' as an option,
-     * assume it means -1.
-     */
-    if (optopt == (int) '-')
-      return (-1);
-    if (!*place)
-      ++optind;
-               if (opterr && *ostr != ':') {
-      fprintf(stderr,
-                    "%s: illegal option -- %c\n", __progname, optopt);
-                       return (BADCH);
-               }
-  }
-  if (*++oli != ':') {         /* don't need argument */
-    optarg = NULL;
-    if (!*place)
-      ++optind;
-  } else {                     /* need an argument */
-    if (*place)                        /* no white space */
-      optarg = place;
-    else if (nargc <= ++optind) {      /* no arg */
-      place = EMSG;
-      if (*ostr == ':')
-       return (BADARG);
-                       if (opterr) {
-                               fprintf(stderr,
-                      "%s: option requires an argument -- %c\n",
-                      __progname, optopt);
-                               return (BADCH);
-                       }
-    } else                     /* white space */
-      optarg = nargv[optind];
-    place = EMSG;
-    ++optind;
-  }
-  return (optopt);             /* dump back option letter */
-}
-
-
-int getopt_long(int argc, char * const argv[], const char *optstring,
-const struct option *longopts, int totlen) {
-       static int lastidx,lastofs;
-       char *tmp;
-       int i,len;
-       char param = 1;
-
-again:
-       if (optind >= argc || !argv[optind] || *argv[optind]!='-')
-               return -1;
-
-       if (argv[optind][0]=='-' && argv[optind][1]==0) {
-               if(optind >= (argc - 1)){ /* no more input parameters */
-                       param = 0;
-               }
-               else{ /* more input parameters */
-                       if(argv[optind + 1][0] == '-'){
-                               param = 0; /* Missing parameter after '-' */
-                       }
-                       else{
-                               param = 2;
-                       }
-               }
-       }
-
-       if (param == 0) {
-               ++optind;
-               return (BADCH);
-       }
-
-       if (argv[optind][0]=='-') {     /* long option */
-               char* arg=argv[optind]+1;
-               const struct option* o;
-               o=longopts;
-               len=sizeof(longopts[0]);
-
-               if (param > 1){
-                       arg = argv[optind+1];
-                       optind++;
-               }
-               else
-                       arg = argv[optind]+1;
-
-               if(strlen(arg)>1){
-                       for (i=0;i<totlen;i=i+len,o++) {
-                               if (!strcmp(o->name,arg)) {     /* match */
-                                       if (o->has_arg == 0) {
-                                               if ((argv[optind+1])&&(!(argv[optind+1][0]=='-'))){
-                                                       fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[optind+1]);
-                                                       ++optind;
-                                               }
-                                       }else{ 
-                                               optarg=argv[optind+1];
-                                               if(optarg){
-                                                       if (optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */                                                                
-                                                               if (opterr) {
-                                                                       fprintf(stderr,"%s: option requires an argument\n",arg);
-                                                                       return (BADCH);
-                                                               }
-                                                       }
-                                               }
-                                               if (!optarg && o->has_arg==1) { /* no argument there */
-                                                       if (opterr) {
-                                                               fprintf(stderr,"%s: option requires an argument \n",arg);
-                                                               return (BADCH);
-                                                       }
-                                               }
-                                               ++optind;
-                                       }
-                                       ++optind;
-                                       if (o->flag)
-                                               *(o->flag)=o->val;
-                                       else
-                                               return o->val;
-                                       return 0;
-                               }
-                       }//(end for)String not found in the list
-                       fprintf(stderr,"Invalid option %s\n",arg);
-                       ++optind;
-                       return (BADCH);
-               }else{ /*Single character input parameter*/
-                       if (*optstring==':') return ':';
-                       if (lastidx!=optind) {
-                               lastidx=optind; lastofs=0;
-                       }
-                       optopt=argv[optind][lastofs+1];
-                       if ((tmp=strchr(optstring,optopt))) {/*Found input parameter in list*/
-                               if (*tmp==0) {  /* apparently, we looked for \0, i.e. end of argument */
-                                       ++optind;
-                                       goto again;
-                               }
-                               if (tmp[1]==':') {      /* argument expected */
-                                       if (tmp[2]==':' || argv[optind][lastofs+2]) {   /* "-foo", return "oo" as optarg */
-                                               if (!*(optarg=argv[optind]+lastofs+2)) optarg=0;
-                                               goto found;
-                                       }
-                                       optarg=argv[optind+1];
-                                       if(optarg){
-                                               if (optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
-                                                       if (opterr) {
-                                                               fprintf(stderr,"%s: option requires an argument\n",arg);
-                                                               return (BADCH);
-                                                       }
-                                               }
-                                       }
-                                       if (!optarg) {  /* missing argument */
-                                               if (opterr) {
-                                                       fprintf(stderr,"%s: option requires an argument\n",arg);
-                                                       return (BADCH);
-                                               }
-                                       }
-                                       ++optind;
-                               }else {/*Argument not expected*/
-                                       ++lastofs;
-                                       return optopt;
-                               }
-found:
-                               ++optind;
-                               return optopt;
-                       }       else {  /* not found */
-                               fprintf(stderr,"Invalid option %s\n",arg);
-                               ++optind;
-                               return (BADCH);
-                       }//end of not found
-               
-               }// end of single character
-       }//end '-'
-       fprintf(stderr,"Invalid option\n");
-       ++optind;
-       return (BADCH);;
-}//end function
diff --git a/applications/common/getopt.h b/applications/common/getopt.h
deleted file mode 100644 (file)
index 1b32d2b..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/* last review : october 29th, 2002 */
-
-#ifndef _GETOPT_H_
-#define _GETOPT_H_
-
-typedef struct option
-{
-       const char *name;
-       int has_arg;
-       int *flag;
-       int val;
-}option_t;
-
-#define        NO_ARG  0
-#define REQ_ARG        1
-#define OPT_ARG        2
-
-extern int opterr;
-extern int optind;
-extern int optopt;
-extern int optreset;
-extern char *optarg;
-
-extern int getopt(int nargc, char *const *nargv, const char *ostr);
-extern int getopt_long(int argc, char * const argv[], const char *optstring,
-                       const struct option *longopts, int totlen);
-extern void reset_options_reading(void);
-
-#endif                         /* _GETOPT_H_ */
diff --git a/applications/common/opj_getopt.c b/applications/common/opj_getopt.c
new file mode 100644 (file)
index 0000000..f6e6500
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 1987, 1993, 1994
+ *     The Regents of the University of California.  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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+/* last review : october 29th, 2002 */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)opj_getopt.c       8.3 (Berkeley) 4/27/95";
+#endif                         /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "opj_getopt.h"
+
+int opj_opterr = 1,                    /* if error message should be printed */
+ opj_optind = 1,                       /* index into parent argv vector */
+ opj_optopt,                   /* character checked for validity */
+ opj_optreset;                 /* reset getopt */
+ char *opj_optarg;                     /* argument associated with option */
+
+#define        BADCH   (int)'?'
+#define        BADARG  (int)':'
+static char EMSG[]={""};
+
+/* As this class remembers its values from one Java call to the other, reset the values before each use */
+void reset_options_reading(void) {
+       opj_opterr = 1;
+       opj_optind = 1;
+}
+
+/*
+ * getopt --
+ *     Parse argc/argv argument vector.
+ */
+int opj_getopt(int nargc, char *const *nargv, const char *ostr) {
+#  define __progname nargv[0]
+  static char *place = EMSG;   /* option letter processing */
+  char *oli;                   /* option letter list index */
+
+  if (opj_optreset || !*place) {       /* update scanning pointer */
+    opj_optreset = 0;
+    if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') {
+      place = EMSG;
+      return (-1);
+    }
+    if (place[1] && *++place == '-') { /* found "--" */
+      ++opj_optind;
+      place = EMSG;
+      return (-1);
+    }
+  }                            /* option letter okay? */
+  if ((opj_optopt = (int) *place++) == (int) ':' ||
+      !(oli = strchr(ostr, opj_optopt))) {
+    /*
+     * if the user didn't specify '-' as an option,
+     * assume it means -1.
+     */
+    if (opj_optopt == (int) '-')
+      return (-1);
+    if (!*place)
+      ++opj_optind;
+               if (opj_opterr && *ostr != ':') {
+      fprintf(stderr,
+                    "%s: illegal option -- %c\n", __progname, opj_optopt);
+                       return (BADCH);
+               }
+  }
+  if (*++oli != ':') {         /* don't need argument */
+    opj_optarg = NULL;
+    if (!*place)
+      ++opj_optind;
+  } else {                     /* need an argument */
+    if (*place)                        /* no white space */
+      opj_optarg = place;
+    else if (nargc <= ++opj_optind) {  /* no arg */
+      place = EMSG;
+      if (*ostr == ':')
+       return (BADARG);
+                       if (opj_opterr) {
+                               fprintf(stderr,
+                      "%s: option requires an argument -- %c\n",
+                      __progname, opj_optopt);
+                               return (BADCH);
+                       }
+    } else                     /* white space */
+      opj_optarg = nargv[opj_optind];
+    place = EMSG;
+    ++opj_optind;
+  }
+  return (opj_optopt);         /* dump back option letter */
+}
+
+
+int opj_getopt_long(int argc, char * const argv[], const char *optstring,
+const opj_option_t *longopts, int totlen) {
+       static int lastidx,lastofs;
+       char *tmp;
+       int i,len;
+       char param = 1;
+
+again:
+       if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind]!='-')
+               return -1;
+
+       if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
+               if(opj_optind >= (argc - 1)){ /* no more input parameters */
+                       param = 0;
+               }
+               else{ /* more input parameters */
+                       if(argv[opj_optind + 1][0] == '-'){
+                               param = 0; /* Missing parameter after '-' */
+                       }
+                       else{
+                               param = 2;
+                       }
+               }
+       }
+
+       if (param == 0) {
+               ++opj_optind;
+               return (BADCH);
+       }
+
+       if (argv[opj_optind][0]=='-') { /* long option */
+               char* arg=argv[opj_optind]+1;
+               const opj_option_t* o;
+               o=longopts;
+               len=sizeof(longopts[0]);
+
+               if (param > 1){
+                       arg = argv[opj_optind+1];
+                       opj_optind++;
+               }
+               else
+                       arg = argv[opj_optind]+1;
+
+               if(strlen(arg)>1){
+                       for (i=0;i<totlen;i=i+len,o++) {
+                               if (!strcmp(o->name,arg)) {     /* match */
+                                       if (o->has_arg == 0) {
+                                               if ((argv[opj_optind+1])&&(!(argv[opj_optind+1][0]=='-'))){
+                                                       fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[opj_optind+1]);
+                                                       ++opj_optind;
+                                               }
+                                       }else{ 
+                                               opj_optarg=argv[opj_optind+1];
+                                               if(opj_optarg){
+                                                       if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */                                                            
+                                                               if (opj_opterr) {
+                                                                       fprintf(stderr,"%s: option requires an argument\n",arg);
+                                                                       return (BADCH);
+                                                               }
+                                                       }
+                                               }
+                                               if (!opj_optarg && o->has_arg==1) {     /* no argument there */
+                                                       if (opj_opterr) {
+                                                               fprintf(stderr,"%s: option requires an argument \n",arg);
+                                                               return (BADCH);
+                                                       }
+                                               }
+                                               ++opj_optind;
+                                       }
+                                       ++opj_optind;
+                                       if (o->flag)
+                                               *(o->flag)=o->val;
+                                       else
+                                               return o->val;
+                                       return 0;
+                               }
+                       }//(end for)String not found in the list
+                       fprintf(stderr,"Invalid option %s\n",arg);
+                       ++opj_optind;
+                       return (BADCH);
+               }else{ /*Single character input parameter*/
+                       if (*optstring==':') return ':';
+                       if (lastidx!=opj_optind) {
+                               lastidx=opj_optind; lastofs=0;
+                       }
+                       opj_optopt=argv[opj_optind][lastofs+1];
+                       if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/
+                               if (*tmp==0) {  /* apparently, we looked for \0, i.e. end of argument */
+                                       ++opj_optind;
+                                       goto again;
+                               }
+                               if (tmp[1]==':') {      /* argument expected */
+                                       if (tmp[2]==':' || argv[opj_optind][lastofs+2]) {       /* "-foo", return "oo" as opj_optarg */
+                                               if (!*(opj_optarg=argv[opj_optind]+lastofs+2)) opj_optarg=0;
+                                               goto found;
+                                       }
+                                       opj_optarg=argv[opj_optind+1];
+                                       if(opj_optarg){
+                                               if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
+                                                       if (opj_opterr) {
+                                                               fprintf(stderr,"%s: option requires an argument\n",arg);
+                                                               return (BADCH);
+                                                       }
+                                               }
+                                       }
+                                       if (!opj_optarg) {      /* missing argument */
+                                               if (opj_opterr) {
+                                                       fprintf(stderr,"%s: option requires an argument\n",arg);
+                                                       return (BADCH);
+                                               }
+                                       }
+                                       ++opj_optind;
+                               }else {/*Argument not expected*/
+                                       ++lastofs;
+                                       return opj_optopt;
+                               }
+found:
+                               ++opj_optind;
+                               return opj_optopt;
+                       }       else {  /* not found */
+                               fprintf(stderr,"Invalid option %s\n",arg);
+                               ++opj_optind;
+                               return (BADCH);
+                       }//end of not found
+               
+               }// end of single character
+       }//end '-'
+       fprintf(stderr,"Invalid option\n");
+       ++opj_optind;
+       return (BADCH);;
+}//end function
diff --git a/applications/common/opj_getopt.h b/applications/common/opj_getopt.h
new file mode 100644 (file)
index 0000000..e1f41a5
--- /dev/null
@@ -0,0 +1,29 @@
+/* last review : october 29th, 2002 */
+
+#ifndef _GETOPT_H_
+#define _GETOPT_H_
+
+typedef struct opj_option
+{
+       const char *name;
+       int has_arg;
+       int *flag;
+       int val;
+}opj_option_t;
+
+#define        NO_ARG  0
+#define REQ_ARG        1
+#define OPT_ARG        2
+
+extern int opj_opterr;
+extern int opj_optind;
+extern int opj_optopt;
+extern int opj_optreset;
+extern char *opj_optarg;
+
+extern int opj_getopt(int nargc, char *const *nargv, const char *ostr);
+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                         /* _GETOPT_H_ */
index 4a43886f0fe8e7f50a19e991b29608345dd08e1a..32008a31a8f4ad79430c7312f37864c85524395d 100644 (file)
@@ -1,9 +1,6 @@
 # Makefile for the MJ2 codecs of the OpenJPEG library: frames_to_mj2, mj2_to_frames, extract_j2k_from_mj2 and wrap_j2k_in_mj2
 
-SET(common_SRCS "")
-IF(DONT_HAVE_GETOPT)
-  SET(common_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c)
-ENDIF(DONT_HAVE_GETOPT)
+SET(common_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
 
 # While mj2 executables do not use the API correctly, we do not link with the library but rather compile the sources files.
 SET(OPJ_SRCS
index 6f8c225cd6b86467756136a308cb3fdaf2307997..91bb341456d29a9bef547de7183415290bfdff05 100644 (file)
@@ -37,7 +37,7 @@ frames_to_mj2_CFLAGS =
 frames_to_mj2_LDADD = -lm
 frames_to_mj2_SOURCES = \
 $(OPJ_SRC) \
-../common/getopt.c \
+../common/opj_getopt.c \
 mj2_convert.c \
 mj2.c \
 frames_to_mj2.c \
@@ -58,7 +58,7 @@ mj2_to_frames_LDADD = @LCMS2_LIBS@ @LCMS1_LIBS@
 mj2_to_frames_SOURCES = \
 $(OPJ_SRC) \
 ../common/color.c \
-../common/getopt.c \
+../common/opj_getopt.c \
 mj2_convert.c \
 mj2.c \
 mj2_to_frames.c \
index 1e0d29a9b37a7268d8a7cc82af09532ea05f7c22..799d42ab9f7e604356f5558ed2d03c5eb73875de 100644 (file)
@@ -36,7 +36,7 @@
 #include "cio.h"
 #include "mj2.h"
 #include "mj2_convert.h"
-#include "getopt.h"
+#include "opj_getopt.h"
 
 /**
 Size of memory first allocated for MOOV box
@@ -289,15 +289,15 @@ int main(int argc, char **argv)
        }
 
   while (1) {
-    int c = getopt(argc, argv,
+    int c = opj_getopt(argc, argv,
       "i:o:r:q:f:t:n:c:b:p:s:d:P:S:E:M:R:T:C:I:W:F:D:h");
     if (c == -1)
       break;
     switch (c) {
     case 'i':                  /* IN fill */
                        {
-                               char *infile = optarg;
-                               s = optarg;
+                               char *infile = opj_optarg;
+                               s = opj_optarg;
                                while (*s) {
                                        s++;
                                }
@@ -324,7 +324,7 @@ int main(int argc, char **argv)
       /* ----------------------------------------------------- */
     case 'o':                  /* OUT fill */
                        {
-                               char *outfile = optarg;
+                               char *outfile = opj_optarg;
                                while (*outfile) {
                                        outfile++;
                                }
@@ -335,7 +335,7 @@ int main(int argc, char **argv)
                                outfile--;
                                S1 = *outfile;
                                
-                               outfile = optarg;
+                               outfile = opj_optarg;
                                
                                if ((S1 == 'm' && S2 == 'j' && S3 == '2')
                                        || (S1 == 'M' && S2 == 'J' && S3 == '2'))
@@ -353,7 +353,7 @@ int main(int argc, char **argv)
     case 'r':                  /* rates rates/distorsion */
                        {
                                float rate;
-                               s = optarg;
+                               s = opj_optarg;
                                while (sscanf(s, "%f", &rate) == 1) {
                                        j2k_parameters->tcp_rates[j2k_parameters->tcp_numlayers] = rate * 2;
                                        j2k_parameters->tcp_numlayers++;
@@ -369,7 +369,7 @@ int main(int argc, char **argv)
       break;
       /* ----------------------------------------------------- */
     case 'q':                  /* add fixed_quality */
-      s = optarg;
+      s = opj_optarg;
                        while (sscanf(s, "%f", &j2k_parameters->tcp_distoratio[j2k_parameters->tcp_numlayers]) == 1) {
                                j2k_parameters->tcp_numlayers++;
                                while (*s && *s != ',') {
@@ -388,7 +388,7 @@ int main(int argc, char **argv)
                                int *row = NULL, *col = NULL;
                                int numlayers = 0, numresolution = 0, matrix_width = 0;
                                
-                               s = optarg;
+                               s = opj_optarg;
                                sscanf(s, "%d", &numlayers);
                                s++;
                                if (numlayers > 9)
@@ -429,12 +429,12 @@ int main(int argc, char **argv)
                        break;
       /* ----------------------------------------------------- */
     case 't':                  /* tiles */
-      sscanf(optarg, "%d,%d", &j2k_parameters->cp_tdx, &j2k_parameters->cp_tdy);
+      sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tdx, &j2k_parameters->cp_tdy);
                        j2k_parameters->tile_size_on = OPJ_TRUE;
       break;
       /* ----------------------------------------------------- */
     case 'n':                  /* resolution */
-      sscanf(optarg, "%d", &j2k_parameters->numresolution);
+      sscanf(opj_optarg, "%d", &j2k_parameters->numresolution);
       break;
       /* ----------------------------------------------------- */
     case 'c':                  /* precinct dimension */
@@ -442,7 +442,7 @@ int main(int argc, char **argv)
                                char sep;
                                int res_spec = 0;
 
-                               char *s = optarg;
+                               char *s = opj_optarg;
                                do {
                                        sep = 0;
                                        sscanf(s, "[%d,%d]%c", &j2k_parameters->prcw_init[res_spec],
@@ -460,7 +460,7 @@ int main(int argc, char **argv)
     case 'b':                  /* code-block dimension */
                        {
                                int cblockw_init = 0, cblockh_init = 0;
-                               sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
+                               sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
                                if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
                                        || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
                                        fprintf(stderr,
@@ -477,7 +477,7 @@ int main(int argc, char **argv)
                        {
                                char progression[5];
                                
-                               strncpy(progression, optarg, 5);
+                               strncpy(progression, opj_optarg, 5);
                                j2k_parameters->prog_order = give_progression(progression);
                                if (j2k_parameters->prog_order == -1) {
                                        fprintf(stderr, "Unrecognized progression order "
@@ -489,7 +489,7 @@ int main(int argc, char **argv)
       /* ----------------------------------------------------- */
     case 's':                  /* subsampling factor */
       {
-                               if (sscanf(optarg, "%d,%d", &j2k_parameters->subsampling_dx,
+                               if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->subsampling_dx,
                                     &j2k_parameters->subsampling_dy) != 2) {
                                        fprintf(stderr, "'-s' sub-sampling argument error !  [-s dx,dy]\n");
                                        return 1;
@@ -499,7 +499,7 @@ int main(int argc, char **argv)
       /* ----------------------------------------------------- */
     case 'd':                  /* coordonnate of the reference grid */
       {
-                               if (sscanf(optarg, "%d,%d", &j2k_parameters->image_offset_x0,
+                               if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->image_offset_x0,
                                     &j2k_parameters->image_offset_y0) != 2) {
                                        fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
             "error !! [-d x0,y0]\n");
@@ -518,7 +518,7 @@ int main(int argc, char **argv)
                                int numpocs = 0;                /* number of progression order change (POC) default 0 */
                                opj_poc_t *POC = NULL;  /* POC : used in case of Progression order change */
 
-                               char *s = optarg;
+                               char *s = opj_optarg;
                                POC = j2k_parameters->POC;
 
                                while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
@@ -548,7 +548,7 @@ int main(int argc, char **argv)
       break;
       /* ------------------------------------------------------ */
     case 'M':                  /* Mode switch pas tous au point !! */
-      if (sscanf(optarg, "%d", &value) == 1) {
+      if (sscanf(opj_optarg, "%d", &value) == 1) {
                                for (i = 0; i <= 5; i++) {
                                        int cache = value & (1 << i);
                                        if (cache)
@@ -559,7 +559,7 @@ int main(int argc, char **argv)
       /* ------------------------------------------------------ */
     case 'R':                  /* ROI */
       {
-                               if (sscanf(optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno,
+                               if (sscanf(opj_optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno,
                                            &j2k_parameters->roi_shift) != 2) {
                                        fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
                                        return 1;
@@ -569,7 +569,7 @@ int main(int argc, char **argv)
       /* ------------------------------------------------------ */
     case 'T':                  /* Tile offset */
                        {
-                               if (sscanf(optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) {
+                               if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) {
                                        fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
                                        return 1;
                                }
@@ -578,9 +578,9 @@ int main(int argc, char **argv)
       /* ------------------------------------------------------ */
     case 'C':                  /* Add a comment */
                        {
-                               j2k_parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);
+                               j2k_parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
                                if(j2k_parameters->cp_comment) {
-                                       strcpy(j2k_parameters->cp_comment, optarg);
+                                       strcpy(j2k_parameters->cp_comment, opj_optarg);
                                }
                        }
                        break;
@@ -593,7 +593,7 @@ int main(int argc, char **argv)
       /* ------------------------------------------------------ */
     case 'W':                  /* Width and Height and Cb and Cr subsampling in case of YUV format files */
       if (sscanf
-                               (optarg, "%d,%d,%d,%d", &mj2_parameters.w, &mj2_parameters.h, &mj2_parameters.CbCr_subsampling_dx,
+                               (opj_optarg, "%d,%d,%d,%d", &mj2_parameters.w, &mj2_parameters.h, &mj2_parameters.CbCr_subsampling_dx,
                                &mj2_parameters.CbCr_subsampling_dy) != 4) {
                                fprintf(stderr, "-W argument error");
                                return 1;
@@ -601,14 +601,14 @@ int main(int argc, char **argv)
       break;
       /* ------------------------------------------------------ */
     case 'F':                  /* Video frame rate */
-      if (sscanf(optarg, "%d", &mj2_parameters.frame_rate) != 1) {
+      if (sscanf(opj_optarg, "%d", &mj2_parameters.frame_rate) != 1) {
                                fprintf(stderr, "-F argument error");
                                return 1;
       }
       break;
       /* ------------------------------------------------------ */
        case 'D': /* Depth: the precision */
-               if(sscanf(optarg, "%d", &prec) != 1) prec = 0;
+               if(sscanf(opj_optarg, "%d", &prec) != 1) prec = 0;
                break;
 
     default:
index ed2ce413b08febd323c35ffdfebe27cfdb2f02d4..489f19cb4855ce3fae1cb3132c622a06c272bf9d 100644 (file)
@@ -16,7 +16,7 @@ can be bound by the Open JPEG open-source license and disclaimer, expressed else
 
 #include "mj2_to_metadata.h"
 #include <string.h>
-#include "getopt.h"
+#include "opj_getopt.h"
 
 /* -------------------------------------------------------------------------- */
 
index 4207365cfde58380b07f6b77558fa55689bc3325..b280bfe56d907fa0aeab66a2f3508005bb079056 100644 (file)
                                Name="MJ2 Header Files"\r
                                >\r
                                <File\r
-                                       RelativePath="compat\getopt.h"\r
+                                       RelativePath="compat\opj_getopt.h"\r
                                        >\r
                                </File>\r
                                <File\r
                                Name="MJ2 Source Files"\r
                                >\r
                                <File\r
-                                       RelativePath="compat\getopt.c"\r
+                                       RelativePath="compat\opj_getopt.c"\r
                                        >\r
                                        <FileConfiguration\r
                                                Name="Debug|Win32"\r
index 972e9e99c5da1e6ae2d47097acda0d1d85c8aa9d..0a6215c48df106466534b9467067ba0ac4efbcb5 100644 (file)
@@ -9,30 +9,11 @@ INCLUDE_DIRECTORIES(${OPENJPEG_SOURCE_DIR}/libopenjpeg
                     )
 
 # First thing define the common source:
-SET(comparePGXimages_SRCS comparePGXimages.c ${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c)
-
-SET(compare_dump_files_SRCS compare_dump_files.c)
-
-SET(compareRAWimages_SRCS compareRAWimages.c)
-
-# If not getopt was found then add it to the exe:
-IF(DONT_HAVE_GETOPT)
-  message("dont have getopt, we will add it")
-  SET(comparePGXimages_SRCS
-    ${comparePGXimages_SRCS}
-    ${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c
-  )
-  
-  SET(compare_dump_files_SRCS
-    ${compare_dump_files_SRCS}
-    ${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c
-  )
-  
-  SET(compareRAWimages_SRCS
-    ${compareRAWimages_SRCS}
-    ${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c
-  )
-ENDIF(DONT_HAVE_GETOPT)
+SET(comparePGXimages_SRCS comparePGXimages.c ${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
+
+SET(compare_dump_files_SRCS compare_dump_files.c ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
+
+SET(compareRAWimages_SRCS compareRAWimages.c ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
 
 ADD_EXECUTABLE(comparePGXimages ${comparePGXimages_SRCS})
 TARGET_LINK_LIBRARIES(comparePGXimages ${OPENJPEG_LIBRARY_NAME}
@@ -51,4 +32,4 @@ IF(NOT HAVE_LIBPNG)
 ENDIF(NOT HAVE_LIBPNG)
 
 ADD_SUBDIRECTORY(conformance)
-ADD_SUBDIRECTORY(nonregression)
\ No newline at end of file
+ADD_SUBDIRECTORY(nonregression)
index 7839e299d5867352bfdd778a9216750c0770aafd..97cd0baa4fc3340d205cf85b09be2e29b5ffea5b 100644 (file)
@@ -38,7 +38,7 @@
 #include <ctype.h>
 
 #include "opj_config.h"
-#include "getopt.h"
+#include "opj_getopt.h"
 
 #include "openjpeg.h"
 #include "format_defs.h"
@@ -110,60 +110,60 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
   param->tabPEAKvalues = NULL;
   param->nr_flag = 0;
 
-  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';
+        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';
+        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 'n':
-        param->nbcomp = atoi(optarg);
+        param->nbcomp = atoi(opj_optarg);
         break;
       case 'm':
-        MSElistvalues = optarg;
+        MSElistvalues = opj_optarg;
         flagM = 1;
         break;
       case 'p':
-        PEAKlistvalues = optarg;
+        PEAKlistvalues = opj_optarg;
         flagP = 1;
         break;
       case 'd':
         param->nr_flag = 1;
         break;
       case 's':
-        separatorList = optarg;
+        separatorList = opj_optarg;
         break;
       case '?':
-        if ((optopt == 'b') || (optopt == 't') || (optopt == 'n') || (optopt == 'p') || (optopt == 'm') || (optopt
+        if ((opj_optopt == 'b') || (opj_optopt == 't') || (opj_optopt == 'n') || (opj_optopt == 'p') || (opj_optopt == 'm') || (opj_optopt
             == 's'))
-          fprintf(stderr, "Option -%c requires an argument.\n", optopt);
+          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;
     }
index 631d028d785719bc5edbcea6362c2aef4837763b..24738873662d92f604398db67612c7683be830c7 100644 (file)
@@ -36,7 +36,7 @@
 #include <string.h>
 #include <ctype.h>
 
-#include "getopt.h"
+#include "opj_getopt.h"
 
 void compareRAWimages_help_display(void);
 
@@ -73,40 +73,40 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
        param->base_filename = NULL;
        param->test_filename = NULL;
 
-       opterr = 0;
+       opj_opterr = 0;
        while ((c = 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';
+                       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';
+                       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) {
-               for (index = optind; index < argc; index++)
+       if (opj_optind != argc) {
+               for (index = opj_optind; index < argc; index++)
                        fprintf(stderr,"Non-option argument %s\n", argv[index]);
                return EXIT_FAILURE;
     }
index 687cc9486257388474eed54ba6b262f485bf44e1..cd962bd42aab293f2dbb3782eb93b76939df95a4 100644 (file)
@@ -37,7 +37,7 @@
 #include <string.h>
 #include <ctype.h>
 
-#include "getopt.h"
+#include "opj_getopt.h"
 
 typedef struct test_cmp_parameters
 {
@@ -71,42 +71,42 @@ int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
   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';
+        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';
+        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;
     }
index e9c00dd493c37071b51e4aa48e6dbba4509b0995..18ef15a112492c4b51cb5ecefa8001dbecb85b7a 100644 (file)
@@ -79,7 +79,7 @@ ENDIF (NOT WIN32)
    
 string(COMPARE EQUAL ${REF_DECODER_BIN_PATH} "NOTFOUND" REF_DECODER_NOTFOUND)            
 IF (REF_DECODER_NOTFOUND)
-  MESSAGE(STATUS "REF_DECODER_BIN_PATH not found, if you want all the encoding tests suite please provide a ragular path")  
+  MESSAGE(STATUS "REF_DECODER_BIN_PATH not found, if you want all the encoding tests suite please provide a regular path")  
 ENDIF (REF_DECODER_NOTFOUND)