Fix undefined references when using Visual Studio

Fix Issue https://github.com/Unidata/netcdf-c/issues/1725.
Replace PR https://github.com/Unidata/netcdf-c/pull/1726
Also replace PR https://github.com/Unidata/netcdf-c/pull/1694

The general problem is that under Visual Studio, we are seeing
a number of undefined reference and other scoping errors.
The reason is that the code is not properly using Visual Studio
_declspec() declarations.

The basic solution is to ensure that when compiling the code itself
one needs to ensure that _declspec(dllexport) is used. There
are several sets of macros to handle this, but they all rely
on the flag DLL_EXPORT being define when the code is compiled,
but not being defined when the code is used via a .h file.

As a test, I modified XGetOpt.c to build properly. I also
fixed the oc2 library to properly _declspec things like ocdebug.

I also made some misc. changes to get all the tests to run
if cygwin is installed (to get bash, sed, etc).

Misc. Changes:
* Put XGetOpt.c into libsrc and copy at build time
  to the other directories where it is needed.
This commit is contained in:
Dennis Heimbigner 2020-05-18 19:36:28 -06:00
parent 173339759f
commit c68c4c804d
31 changed files with 125 additions and 773 deletions

View File

@ -505,7 +505,6 @@ IF(WIN32)
SET(BUILD_DLL ON CACHE BOOL "")
ADD_DEFINITIONS(-DDLL_NETCDF)
ADD_DEFINITIONS(-DDLL_EXPORT)
ADD_DEFINITIONS(-DUTF8PROC_DLLEXPORT)
ENDIF()
ENDIF()
# Did the user specify a default minimum blocksize for posixio?
@ -891,11 +890,20 @@ IF(ENABLE_EXTRA_TESTS)
ENDIF()
# Option to use bundled XGetopt in place of getopt(). This is mostly useful
# for MSVC builds. If not building utilities, getopt() isn't required at all.
# for MSVC builds. If not building utilities or some tests,
# getopt() isn't required at all.
IF(MSVC)
OPTION(ENABLE_XGETOPT "Enable bundled XGetOpt instead of external getopt()." ON)
IF(ENABLE_XGETOPT)
SET(USE_X_GETOPT ON CACHE BOOL "")
# Copy XGetopt.c to everywhere it is needed. Avoids
# inconsistent code
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/ncgen3/)
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/ncgen/)
FILE(COPY ${netCDF_SOURCE_DIR}/libsrc/XGetopt.c
DESTINATION ${netCDF_BINARY_DIR}/ncdump/)
ENDIF()
ENDIF()

View File

@ -7,6 +7,9 @@ This file contains a high-level description of this package's evolution. Release
## 4.8.0 - TBD
* [Bug Fix] Add necessary __declspec declarations to allow compilation
of netcdf library without causing errors or (_declspec related)
warnings [https://github.com/Unidata/netcdf-c/issues/1725].
* [Enhancement] When a filter is applied twice with different
parameters, then the second set is used for writing the dataset
[https://github.com/Unidata/netcdf-c/issues/1713].

View File

@ -1,40 +1,40 @@
// XGetopt.h Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef XGETOPT_H
#define XGETOPT_H
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#if defined(DLL_NETCDF)
# if defined(DLL_EXPORT)
# define GTOPT_EXTRA __declspec(dllexport)
# else
# define GTOPT_EXTRA __declspec(dllimport)
# endif
GTOPT_EXTRA extern int optind, opterr;
#else
extern int optind, opterr;
#endif
extern TCHAR *optarg;
int getopt(int argc, TCHAR *argv[], TCHAR *optstring);
#endif //XGETOPT_H
// XGetopt.h Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef XGETOPT_H
#define XGETOPT_H
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#if 0
#ifdef _MSC_VER
# ifdef DLL_EXPORT
# define GTOPT_EXTRA __declspec(dllexport)
# else
# define GTOPT_EXTRA __declspec(dllimport)
# endif
#else
# define GTOP_EXTRA
#endif
#endif
#define GTOPT_EXTRA
GTOPT_EXTRA extern int optind, opterr;
GTOPT_EXTRA extern TCHAR* optarg;
GTOPT_EXTRA extern int getopt(int argc, TCHAR *argv[], TCHAR *optstring);
#endif //XGETOPT_H

View File

@ -82,9 +82,9 @@ EXTERNL int nc_var_filter_remove(int ncid, int varid, unsigned int id);
last arg is void*, but is actually H5Z_class2_t*.
It is void* to avoid having to reference hdf.h.
*/
EXTERNL int nc_filter_client_register(unsigned int id, void*/*H5Z_class2_t* */);
EXTERNL int nc_filter_client_register(unsigned int id, void*);
EXTERNL int nc_filter_client_unregister(unsigned int id);
EXTERNL int nc_filter_client_inq(unsigned int id, void*/*H5Z_class2_t* */);
EXTERNL int nc_filter_client_inq(unsigned int id, void*);
/* HDF5 specific filter info */
typedef struct NC4_Filterspec {

View File

@ -29,6 +29,10 @@
///////////////////////////////////////////////////////////////////////////////
#ifndef DLL_EXPORT
#define DLL_EXPORT
#endif
#include "XGetopt.h"
@ -144,9 +148,11 @@
//
///////////////////////////////////////////////////////////////////////////////
TCHAR *optarg; // global argument pointer
int optind = 0; // global argv index
GTOPT_EXTRA TCHAR *optarg; // global argument pointer
GTOPT_EXTRA int optind = 0; // global argv index
GTOPT_EXTRA int opterr; // print error
GTOPT_EXTRA
int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
{
static TCHAR *next = NULL;

View File

@ -82,7 +82,8 @@ main(int argc, char **argv)
nc_type xtype_in;
char name_in[NC_MAX_NAME + 1];
int i;
nc_set_log_level(4);
nc_set_log_level(0);
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
/*create dimensions*/

View File

@ -96,7 +96,8 @@ main(int argc, char **argv)
char vals[MAX_VALS];
int i;
nc_set_log_level(4);
nc_set_log_level(0);
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
/* Define dimensions and two vars, a 1D coordinate var for

View File

@ -199,7 +199,7 @@ echo "*** Testing multiple filters"
rm -f ./multifilter.nc ./multi.txt ./smulti.cdl
rm -f nccopyF.cdl nccopyF.nc ncgenF.cdl ncgenF.nc
${execdir}/tst_multifilter
${NCDUMP} -hs ./multifilter.nc >./multi.cdl
${NCDUMP} -hs multifilter.nc >./multi.cdl
# Remove irrelevant -s output
sclean ./multi.cdl ./smulti.cdl
diff -b -w ${srcdir}/ref_multi.cdl ./smulti.cdl

View File

@ -4,10 +4,10 @@
# University Corporation for Atmospheric Research/Unidata.
# See netcdf-c/COPYRIGHT file for more info.
IF(BUILD_SHARED_LIBS AND WIN32)
remove_definitions(-DDLL_EXPORT)
remove_definitions(-DDLL_NETCDF)
ENDIF()
#IF(BUILD_SHARED_LIBS AND WIN32)
# remove_definitions(-DDLL_EXPORT)
# remove_definitions(-DDLL_NETCDF)
#ENDIF()
SET(ncdump_FILES ncdump.c vardata.c dumplib.c indent.c nctime0.c utils.c nciter.c)
SET(nccopy_FILES nccopy.c nciter.c chunkspec.c utils.c dimmap.c list.c)
@ -272,25 +272,22 @@ ENDIF()
ENDIF()
IF(MSVC)
SET_TARGET_PROPERTIES(ncdump
PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
SET_TARGET_PROPERTIES(nccopy
PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
SET_TARGET_PROPERTIES(ncvalidator
PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
IF(ENABLE_DAP)
SET_TARGET_PROPERTIES(ocprint
PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
)
ENDIF(ENABLE_DAP)
ENDIF()
#IF(MSVC)
# SET_TARGET_PROPERTIES(ncdump
# PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
# )
# SET_TARGET_PROPERTIES(nccopy
# PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
# )
# SET_TARGET_PROPERTIES(ncvalidator
# PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
# )
# IF(ENABLE_DAP)
# SET_TARGET_PROPERTIES(ocprint
# PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT"
# )
# ENDIF(ENABLE_DAP)
#ENDIF()
INSTALL(TARGETS ncdump RUNTIME DESTINATION bin COMPONENT utilities)
INSTALL(TARGETS nccopy RUNTIME DESTINATION bin COMPONENT utilities)

View File

@ -138,7 +138,7 @@ inttags.cdl inttags4.cdl ref_inttags.cdl ref_inttags4.cdl \
ref_tst_ncf213.cdl tst_h_scalar.sh run_utf8_nc4_tests.sh \
tst_formatx3.sh tst_formatx4.sh ref_tst_utf8_4.cdl \
ref_tst_nc4_utf8_4.cdl tst_inttags.sh tst_inttags4.sh CMakeLists.txt \
XGetopt.c tst_bom.sh tst_inmemory_nc3.sh tst_dimsizes.sh \
tst_bom.sh tst_inmemory_nc3.sh tst_dimsizes.sh \
tst_inmemory_nc4.sh tst_fileinfo.sh run_ncgen_tests.sh \
ref_test_360_day_1900.nc ref_test_365_day_1900.nc \
ref_test_366_day_1900.nc ref_test_360_day_1900.cdl \

View File

@ -1,214 +0,0 @@
// XGetopt.cpp Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// Description:
// XGetopt.cpp implements getopt(), a function to parse command lines.
//
// History
// Version 1.2 - 2003 May 17
// - Added Unicode support
//
// Version 1.1 - 2002 March 10
// - Added example to XGetopt.cpp module header
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are not using precompiled headers then include these lines:
///////////////////////////////////////////////////////////////////////////////
#include "XGetopt.h"
///////////////////////////////////////////////////////////////////////////////
//
// X G e t o p t . c p p
//
//
// NAME
// getopt -- parse command line options
//
// SYNOPSIS
// int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
//
// extern TCHAR *optarg;
// extern int optind;
//
// DESCRIPTION
// The getopt() function parses the command line arguments. Its
// arguments argc and argv are the argument count and array as
// passed into the application on program invocation. In the case
// of Visual C++ programs, argc and argv are available via the
// variables __argc and __argv (double underscores), respectively.
// getopt returns the next option letter in argv that matches a
// letter in optstring. (Note: Unicode programs should use
// __targv instead of __argv. Also, all character and string
// literals should be enclosed in _T( ) ).
//
// optstring is a string of recognized option letters; if a letter
// is followed by a colon, the option is expected to have an argument
// that may or may not be separated from it by white space. optarg
// is set to point to the start of the option argument on return from
// getopt.
//
// Option letters may be combined, e.g., "-ab" is equivalent to
// "-a -b". Option letters are case sensitive.
//
// getopt places in the external variable optind the argv index
// of the next argument to be processed. optind is initialized
// to 0 before the first call to getopt.
//
// When all options have been processed (i.e., up to the first
// non-option argument), getopt returns EOF, optarg will point
// to the argument, and optind will be set to the argv index of
// the argument. If there are no non-option arguments, optarg
// will be set to NULL.
//
// The special option "--" may be used to delimit the end of the
// options; EOF will be returned, and "--" (and everything after it)
// will be skipped.
//
// RETURN VALUE
// For option letters contained in the string optstring, getopt
// will return the option letter. getopt returns a question mark (?)
// when it encounters an option letter not included in optstring.
// EOF is returned when processing is finished.
//
// BUGS
// 1) Long options are not supported.
// 2) The GNU double-colon extension is not supported.
// 3) The environment variable POSIXLY_CORRECT is not supported.
// 4) The + syntax is not supported.
// 5) The automatic permutation of arguments is not supported.
// 6) This implementation of getopt() returns EOF if an error is
// encountered, instead of -1 as the latest standard requires.
//
// EXAMPLE
// BOOL CMyApp::ProcessCommandLine(int argc, TCHAR *argv[])
// {
// int c;
//
// while ((c = getopt(argc, argv, _T("aBn:"))) != EOF)
// {
// switch (c)
// {
// case _T('a'):
// TRACE(_T("option a\n"));
// //
// // set some flag here
// //
// break;
//
// case _T('B'):
// TRACE( _T("option B\n"));
// //
// // set some other flag here
// //
// break;
//
// case _T('n'):
// TRACE(_T("option n: value=%d\n"), atoi(optarg));
// //
// // do something with value here
// //
// break;
//
// case _T('?'):
// TRACE(_T("ERROR: illegal option %s\n"), argv[optind-1]);
// return FALSE;
// break;
//
// default:
// TRACE(_T("WARNING: no handler for option %c\n"), c);
// return FALSE;
// break;
// }
// }
// //
// // check for non-option args here
// //
// return TRUE;
// }
//
///////////////////////////////////////////////////////////////////////////////
TCHAR *optarg; // global argument pointer
int optind = 0; // global argv index
int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
{
static TCHAR *next = NULL;
TCHAR c;
TCHAR *cp = malloc(sizeof(TCHAR)*1024);
if (optind == 0)
next = NULL;
optarg = NULL;
if (next == NULL || *next == _T('\0'))
{
if (optind == 0)
optind++;
if (optind >= argc || argv[optind][0] != _T('-') || argv[optind][1] == _T('\0'))
{
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
if (_tcscmp(argv[optind], _T("--")) == 0)
{
optind++;
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
next = argv[optind];
next++; // skip past -
optind++;
}
c = *next++;
cp = strchr(optstring, c);
if (cp == NULL || c == _T(':'))
return _T('?');
cp++;
if (*cp == _T(':'))
{
if (*next != _T('\0'))
{
optarg = next;
next = NULL;
}
else if (optind < argc)
{
optarg = argv[optind];
optind++;
}
else
{
return _T('?');
}
}
return c;
}

View File

@ -12,6 +12,12 @@
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef _MSC_VER
#include "XGetopt.h"
#define snprintf _snprintf
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -27,13 +33,6 @@
#undef DEBUGFILTER
#ifdef _MSC_VER
#include "XGetopt.h"
#define snprintf _snprintf
int opterr;
int optind;
#endif
/* default bytes of memory we are willing to allocate for variable
* values during copy */
#define COPY_BUFFER_SIZE (5000000)
@ -2191,7 +2190,6 @@ main(int argc, char**argv)
chunkspecinit();
option_chunkspecs = listnew();
opterr = 1;
progname = argv[0];
if (argc <= 1)
@ -2199,6 +2197,7 @@ main(int argc, char**argv)
usage();
}
opterr = 1;
while ((c = getopt(argc, argv, "k:3467d:sum:c:h:e:rwxg:G:v:V:F:L:M:")) != -1) {
switch(c) {
case 'k': /* for specifying variant of netCDF format to be generated

View File

@ -8,10 +8,11 @@ Research/Unidata. See \ref copyright file for more info. */
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef _MSC_VER /* Microsoft Compilers */
#include <io.h>
#ifdef _MSC_VER
#include "XGetopt.h"
#define snprintf _snprintf
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -19,13 +20,6 @@ Research/Unidata. See \ref copyright file for more info. */
#include <fcntl.h>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#include "XGetopt.h"
int opterr;
int optind;
#endif
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@ -2194,7 +2188,6 @@ main(int argc, char *argv[])
#ifdef HAVE_LOCALE_H
setlocale(LC_ALL, "C"); /* CDL may be ambiguous with other locales */
#endif /* HAVE_LOCALE_H */
opterr = 1;
progname = argv[0];
set_formats(FLT_DIGITS, DBL_DIGITS); /* default for float, double data */
@ -2206,6 +2199,7 @@ main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
opterr = 1;
while ((c = getopt(argc, argv, "b:cd:f:g:hikl:n:p:stv:xwKL:X:")) != EOF)
switch(c) {
case 'h': /* dump header only, no data */

View File

@ -77,8 +77,6 @@ THIS SOFTWARE.
#include <io.h>
#define snprintf _snprintf
#include "XGetopt.h"
int opterr;
int optind;
#endif
#define X_ALIGN 4

4
ncdump/ocprint.c Normal file → Executable file
View File

@ -32,8 +32,6 @@
#ifdef _MSC_VER
#include "XGetopt.h"
int opterr, optind;
char* optarg;
#endif
#ifndef nulldup
@ -56,8 +54,6 @@ char* optarg;
/*Mnemonic*/
#define TOPLEVEL 1
int ocdebug;
static OCerror ocstat;
static OClink glink;

View File

@ -41,9 +41,9 @@ rm -f ./tst_fileinfo.tmp
if test -e $NCF ; then
# look at the _IsNetcdf4 flag
N_IS=`${NCDUMP} -s $NCF | fgrep '_IsNetcdf4' | tr -d ' ;'`
N_IS=`${NCDUMP} -s $NCF | fgrep '_IsNetcdf4' | tr -d ' ;\r'`
N_IS=`echo $N_IS | cut -d= -f2`
H_IS=`${NCDUMP} -s $HDF | fgrep '_IsNetcdf4' | tr -d ' ;'`
H_IS=`${NCDUMP} -s $HDF | fgrep '_IsNetcdf4' | tr -d ' ;\r'`
H_IS=`echo $H_IS | cut -d= -f2`
if test "x$N_IS" = 'x0' ;then
echo "FAIL: $NCF is marked as not netcdf-4"

View File

@ -16,7 +16,7 @@ rm -f L512.hdf5
# verify size of L512.bin
#LSIZE=`wc -c ${srcdir}/L512.bin | cut -d ' ' -f 1`
cat ${srcdir}/L512.bin offset.nc > L512.hdf5
K=`${NCDUMP} -k L512.hdf5`
K=`${NCDUMP} -k L512.hdf5 | tr -d '\r'`
if test "x$K" = "xnetCDF-4" ; then
echo "***Pass: 512 offset"
else
@ -27,7 +27,7 @@ fi
# Test a 1024 byte offset
rm -f L1024.hdf5
cat ${srcdir}/L512.bin ${srcdir}/L512.bin offset.nc > L1024.hdf5
K=`${NCDUMP} -k L1024.hdf5`
K=`${NCDUMP} -k L1024.hdf5 | tr -d '\r'`
if test "x$K" = "xnetCDF-4" ; then
echo "***Pass: 1024 offset"
else

View File

@ -25,7 +25,7 @@ diff -b tst_output_c1.cdl $srcdir/ref_ctest1_nc4c.cdl
echo "*** comparing ncdump of C program output (ctest1.cdl) with c1.cdl..."
diff -b tst_output_c1.cdl tst_output_ctest1.cdl
echo "*** test output for ncdump -k"
KIND=`${NCDUMP} -k tst_output_c0.nc`
KIND=`${NCDUMP} -k tst_output_c0.nc |tr -d '\r'`
test "$KIND" = "classic";
${NCGEN} -k $KIND -b -o tst_output_c0tmp.nc ${ncgenc0}
cmp tst_output_c0tmp.nc tst_output_c0.nc
@ -34,7 +34,7 @@ echo "*** test output for ncdump -x"
echo "*** creating tst_ncml.nc from tst_ncml.cdl"
${NCGEN} -b -o tst_ncml.nc $srcdir/tst_ncml.cdl
echo "*** creating c1.ncml from tst_ncml.nc"
${NCDUMP} -x tst_ncml.nc | sed 's/e-00/e-0/g' > c1.ncml
${NCDUMP} -x tst_ncml.nc | sed 's/e-00/e-0/g' |tr -d '\000' > c1.ncml
echo "*** comparing ncdump -x of generated file with ref1.ncml ..."
diff -b c1.ncml $srcdir/ref1.ncml
@ -63,7 +63,8 @@ ${NCDUMP} -n c1 tst_output_c0_64.nc | sed 's/e+0/e+/g' > tst_output_c1_64.cdl
echo "*** comparing ncdump of C program output (ctest1_64.cdl) with tst_output_c1_64.cdl..."
diff -b tst_output_c1_64.cdl tst_output_ctest1_64.cdl
echo "*** test output for ncdump -k"
test "`${NCDUMP} -k tst_output_c0_64.nc`" = "64-bit offset";
KIND=`${NCDUMP} -k tst_output_c0_64.nc | tr -d '\r'`
test "$KIND" = "64-bit offset";
${NCGEN} -k nc6 -b -o tst_output_c0_64_tmp.nc ${ncgenc0}
cmp tst_output_c0_64_tmp.nc tst_output_c0_64.nc

View File

@ -11,15 +11,14 @@ ENDIF()
SET(ncgen_FILES generate.c main.c cdata.c bindata.c genchar.c cvt.c data.c debug.c escapes.c genc.c genbin.c generr.c genlib.c getfill.c odom.c semantics.c ncgeny.c dump.c util.c bytebuffer.c list.c genf77.c f77data.c genj.c jdata.c nc_iter.c ncgen.h)
# don't add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
IF(USE_X_GETOPT)
SET(ncgen_FILES ${ncgen_FILES} XGetopt.c)
ENDIF()
# don't add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
ADD_EXECUTABLE(ncgen ${ncgen_FILES})
TARGET_LINK_LIBRARIES(ncgen netcdf ${ALL_TLL_LIBS})

View File

@ -23,7 +23,7 @@ man_MANS = ncgen.1
# These files all need to be distributed.
EXTRA_DIST = ncgen.y ncgen.l ncgenl.c $(man_MANS) internals.html \
c0.cdl c0_4.cdl ref_camrun.cdl \
ncf199.cdl CMakeLists.txt XGetopt.c c5.cdl \
ncf199.cdl CMakeLists.txt c5.cdl \
compound_datasize_test.cdl compound_datasize_test2.cdl \
tst_gattenum.cdl tst_usuffix.cdl

View File

@ -1,214 +0,0 @@
// XGetopt.cpp Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// Description:
// XGetopt.cpp implements getopt(), a function to parse command lines.
//
// History
// Version 1.2 - 2003 May 17
// - Added Unicode support
//
// Version 1.1 - 2002 March 10
// - Added example to XGetopt.cpp module header
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are not using precompiled headers then include these lines:
///////////////////////////////////////////////////////////////////////////////
#include "XGetopt.h"
///////////////////////////////////////////////////////////////////////////////
//
// X G e t o p t . c p p
//
//
// NAME
// getopt -- parse command line options
//
// SYNOPSIS
// int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
//
// extern TCHAR *optarg;
// extern int optind;
//
// DESCRIPTION
// The getopt() function parses the command line arguments. Its
// arguments argc and argv are the argument count and array as
// passed into the application on program invocation. In the case
// of Visual C++ programs, argc and argv are available via the
// variables __argc and __argv (double underscores), respectively.
// getopt returns the next option letter in argv that matches a
// letter in optstring. (Note: Unicode programs should use
// __targv instead of __argv. Also, all character and string
// literals should be enclosed in _T( ) ).
//
// optstring is a string of recognized option letters; if a letter
// is followed by a colon, the option is expected to have an argument
// that may or may not be separated from it by white space. optarg
// is set to point to the start of the option argument on return from
// getopt.
//
// Option letters may be combined, e.g., "-ab" is equivalent to
// "-a -b". Option letters are case sensitive.
//
// getopt places in the external variable optind the argv index
// of the next argument to be processed. optind is initialized
// to 0 before the first call to getopt.
//
// When all options have been processed (i.e., up to the first
// non-option argument), getopt returns EOF, optarg will point
// to the argument, and optind will be set to the argv index of
// the argument. If there are no non-option arguments, optarg
// will be set to NULL.
//
// The special option "--" may be used to delimit the end of the
// options; EOF will be returned, and "--" (and everything after it)
// will be skipped.
//
// RETURN VALUE
// For option letters contained in the string optstring, getopt
// will return the option letter. getopt returns a question mark (?)
// when it encounters an option letter not included in optstring.
// EOF is returned when processing is finished.
//
// BUGS
// 1) Long options are not supported.
// 2) The GNU double-colon extension is not supported.
// 3) The environment variable POSIXLY_CORRECT is not supported.
// 4) The + syntax is not supported.
// 5) The automatic permutation of arguments is not supported.
// 6) This implementation of getopt() returns EOF if an error is
// encountered, instead of -1 as the latest standard requires.
//
// EXAMPLE
// BOOL CMyApp::ProcessCommandLine(int argc, TCHAR *argv[])
// {
// int c;
//
// while ((c = getopt(argc, argv, _T("aBn:"))) != EOF)
// {
// switch (c)
// {
// case _T('a'):
// TRACE(_T("option a\n"));
// //
// // set some flag here
// //
// break;
//
// case _T('B'):
// TRACE( _T("option B\n"));
// //
// // set some other flag here
// //
// break;
//
// case _T('n'):
// TRACE(_T("option n: value=%d\n"), atoi(optarg));
// //
// // do something with value here
// //
// break;
//
// case _T('?'):
// TRACE(_T("ERROR: illegal option %s\n"), argv[optind-1]);
// return FALSE;
// break;
//
// default:
// TRACE(_T("WARNING: no handler for option %c\n"), c);
// return FALSE;
// break;
// }
// }
// //
// // check for non-option args here
// //
// return TRUE;
// }
//
///////////////////////////////////////////////////////////////////////////////
TCHAR *optarg; // global argument pointer
int optind = 0; // global argv index
int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
{
static TCHAR *next = NULL;
TCHAR c;
TCHAR *cp = malloc(sizeof(TCHAR)*1024);
if (optind == 0)
next = NULL;
optarg = NULL;
if (next == NULL || *next == _T('\0'))
{
if (optind == 0)
optind++;
if (optind >= argc || argv[optind][0] != _T('-') || argv[optind][1] == _T('\0'))
{
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
if (_tcscmp(argv[optind], _T("--")) == 0)
{
optind++;
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
next = argv[optind];
next++; // skip past -
optind++;
}
c = *next++;
cp = strchr(optstring, c);
if (cp == NULL || c == _T(':'))
return _T('?');
cp++;
if (*cp == _T(':'))
{
if (*next != _T('\0'))
{
optarg = next;
next = NULL;
}
else if (optind < argc)
{
optarg = argv[optind];
optind++;
}
else
{
return _T('?');
}
}
return c;
}

View File

@ -14,8 +14,6 @@
#ifdef _MSC_VER
#include "XGetopt.h"
int opterr;
int optind;
#endif
/* Default is netcdf-3 mode 1 */

View File

@ -6,6 +6,10 @@
# See netcdf-c/COPYRIGHT file for more info.
SET(ncgen3_FILES main.c load.c escapes.c getfill.c init.c genlib.c ncgentab.c)
IF(USE_X_GETOPT)
SET(ncgen3_FILES ${ncgen3_FILES} XGetopt.c)
ENDIF()
FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl)
FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE)
@ -20,10 +24,6 @@ IF(NOT EXISTS ${netCDF_SOURCE_DIR}/ncgen3/ncgentab.c AND NOT EXISTS
)
ENDIF()
IF(USE_X_GETOPT)
SET(ncgen3_FILES ${ncgen3_FILES} XGetopt.c)
ENDIF()
ADD_EXECUTABLE(ncgen3 ${ncgen3_FILES})
TARGET_LINK_LIBRARIES(ncgen3 netcdf ${ALL_TLL_LIBS})
####
@ -62,7 +62,7 @@ ENDIF()
## Specify files to be distributed by 'make dist'
FILE(GLOB CUR_EXTRA_DIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.sh)
SET(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} CMakeLists.txt XGetopt.c Makefile.am ncgen.y ncgenyy.c ncgen.l c0.cdl ncgen3.1)
SET(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} CMakeLists.txt Makefile.am ncgen.y ncgenyy.c ncgen.l c0.cdl ncgen3.1)
ADD_EXTRA_DIST("${CUR_EXTRA_DIST}")

View File

@ -19,7 +19,7 @@ man_MANS = ncgen3.1
# These files all need to be distributed.
EXTRA_DIST = ncgen.y ncgenyy.c ncgen.l c0.cdl run_tests.sh \
run_nc4_tests.sh XGetopt.c $(man_MANS)
run_nc4_tests.sh $(man_MANS) CMakeLists.txt
# There is a netcdf classic and netcdf-4 test script, but don't run
# them for DLL builds.
@ -33,7 +33,6 @@ endif # USE_HDF5
CLEANFILES = c0.nc c0_64.nc c0_4.nc c0_4c.nc
EXTRA_DIST += CMakeLists.txt XGetopt.c
# This is used if someone wants to rebuild ncgenyy.c or ncgentab.c
# Otherwise never invoked, but records how to do it. Don't forget to

View File

@ -1,214 +0,0 @@
// XGetopt.cpp Version 1.2
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// Description:
// XGetopt.cpp implements getopt(), a function to parse command lines.
//
// History
// Version 1.2 - 2003 May 17
// - Added Unicode support
//
// Version 1.1 - 2002 March 10
// - Added example to XGetopt.cpp module header
//
// This software is released into the public domain.
// You are free to use it in any way you like.
//
// This software is provided "as is" with no expressed
// or implied warranty. I accept no liability for any
// damage or loss of business that this software may cause.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// if you are not using precompiled headers then include these lines:
///////////////////////////////////////////////////////////////////////////////
#include "XGetopt.h"
///////////////////////////////////////////////////////////////////////////////
//
// X G e t o p t . c p p
//
//
// NAME
// getopt -- parse command line options
//
// SYNOPSIS
// int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
//
// extern TCHAR *optarg;
// extern int optind;
//
// DESCRIPTION
// The getopt() function parses the command line arguments. Its
// arguments argc and argv are the argument count and array as
// passed into the application on program invocation. In the case
// of Visual C++ programs, argc and argv are available via the
// variables __argc and __argv (double underscores), respectively.
// getopt returns the next option letter in argv that matches a
// letter in optstring. (Note: Unicode programs should use
// __targv instead of __argv. Also, all character and string
// literals should be enclosed in _T( ) ).
//
// optstring is a string of recognized option letters; if a letter
// is followed by a colon, the option is expected to have an argument
// that may or may not be separated from it by white space. optarg
// is set to point to the start of the option argument on return from
// getopt.
//
// Option letters may be combined, e.g., "-ab" is equivalent to
// "-a -b". Option letters are case sensitive.
//
// getopt places in the external variable optind the argv index
// of the next argument to be processed. optind is initialized
// to 0 before the first call to getopt.
//
// When all options have been processed (i.e., up to the first
// non-option argument), getopt returns EOF, optarg will point
// to the argument, and optind will be set to the argv index of
// the argument. If there are no non-option arguments, optarg
// will be set to NULL.
//
// The special option "--" may be used to delimit the end of the
// options; EOF will be returned, and "--" (and everything after it)
// will be skipped.
//
// RETURN VALUE
// For option letters contained in the string optstring, getopt
// will return the option letter. getopt returns a question mark (?)
// when it encounters an option letter not included in optstring.
// EOF is returned when processing is finished.
//
// BUGS
// 1) Long options are not supported.
// 2) The GNU double-colon extension is not supported.
// 3) The environment variable POSIXLY_CORRECT is not supported.
// 4) The + syntax is not supported.
// 5) The automatic permutation of arguments is not supported.
// 6) This implementation of getopt() returns EOF if an error is
// encountered, instead of -1 as the latest standard requires.
//
// EXAMPLE
// BOOL CMyApp::ProcessCommandLine(int argc, TCHAR *argv[])
// {
// int c;
//
// while ((c = getopt(argc, argv, _T("aBn:"))) != EOF)
// {
// switch (c)
// {
// case _T('a'):
// TRACE(_T("option a\n"));
// //
// // set some flag here
// //
// break;
//
// case _T('B'):
// TRACE( _T("option B\n"));
// //
// // set some other flag here
// //
// break;
//
// case _T('n'):
// TRACE(_T("option n: value=%d\n"), atoi(optarg));
// //
// // do something with value here
// //
// break;
//
// case _T('?'):
// TRACE(_T("ERROR: illegal option %s\n"), argv[optind-1]);
// return FALSE;
// break;
//
// default:
// TRACE(_T("WARNING: no handler for option %c\n"), c);
// return FALSE;
// break;
// }
// }
// //
// // check for non-option args here
// //
// return TRUE;
// }
//
///////////////////////////////////////////////////////////////////////////////
TCHAR *optarg; // global argument pointer
int optind = 0; // global argv index
int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
{
static TCHAR *next = NULL;
TCHAR c;
TCHAR *cp = malloc(sizeof(TCHAR)*1024);
if (optind == 0)
next = NULL;
optarg = NULL;
if (next == NULL || *next == _T('\0'))
{
if (optind == 0)
optind++;
if (optind >= argc || argv[optind][0] != _T('-') || argv[optind][1] == _T('\0'))
{
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
if (_tcscmp(argv[optind], _T("--")) == 0)
{
optind++;
optarg = NULL;
if (optind < argc)
optarg = argv[optind];
return EOF;
}
next = argv[optind];
next++; // skip past -
optind++;
}
c = *next++;
cp = strchr(optstring, c);
if (cp == NULL || c == _T(':'))
return _T('?');
cp++;
if (*cp == _T(':'))
{
if (*next != _T('\0'))
{
optarg = next;
next = NULL;
}
else if (optind < argc)
{
optarg = argv[optind];
optind++;
}
else
{
return _T('?');
}
}
return c;
}

View File

@ -18,8 +18,6 @@
#ifdef _MSC_VER
#include "XGetopt.h"
#define snprintf _snprintf
int opterr;
int optind;
#endif
#ifdef __hpux
@ -89,9 +87,6 @@ main(
int argc,
char *argv[])
{
/* MSC_EXTRA extern int optind;
MSC_EXTRA extern int opterr;
MSC_EXTRA extern char *optarg;*/
int any_error;
int c;
FILE *fp;
@ -104,7 +99,6 @@ main(
malloc_debug(2) ; /* helps find malloc/free errors on Sun */
#endif /* MDEBUG */
opterr = 1; /* print error message if bad option */
progname = ubasename(argv[0]);
cdlname = "-";

View File

@ -6,6 +6,7 @@
#include <strings.h>
#endif
#include "oc.h"
#include "dapparselex.h"
#include "dapy.h"

View File

@ -596,6 +596,8 @@ EXTERNL OCerror oc_ping(const char* url);
*/
EXTERNL OCerror oc_raw_xdrsize(OClink,OCddsnode,off_t*);
EXTERNL int ocdebug;
#ifdef __cplusplus
}
#endif

View File

@ -8,8 +8,6 @@
#include "ocinternal.h"
#include "ocdebug.h"
int ocdebug;
#ifdef OCCATCHERROR
/* Place breakpoint here to catch errors close to where they occur*/
OCerror

View File

@ -58,9 +58,6 @@ about how IO is getting along.
*/
#undef OCPROGRESS
EXTERNL int ocdebug;
EXTERNL int cedebug;
/*extern char* dent2(int n);*/
/*/extern char* dent(int n);*/
extern int ocpanic(const char* fmt, ...);

View File

@ -57,6 +57,8 @@ static OCerror ocget_rcproperties(OCstate*);
extern OCnode* makeunlimiteddimension(void);
EXTERNL int ocdebug = 0;
int ocinitialized = 0;
OCerror