mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-02-17 16:50:18 +08:00
Fix build on pre-C99 compilers
- Make sure that the variables are declared at the top of the block. - Add fix to enable inline for various compilers
This commit is contained in:
parent
2b72835c55
commit
1b91bd89d4
@ -10,6 +10,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
|
@ -1133,11 +1133,13 @@ keyword(const char* name)
|
||||
int n = sizeof(keywordmap)/sizeof(KEYWORDINFO);
|
||||
int L = 0;
|
||||
int R = (n - 1);
|
||||
int m, cmp;
|
||||
struct KEYWORDINFO* p;
|
||||
for(;;) {
|
||||
if(L > R) break;
|
||||
int m = (L + R) / 2;
|
||||
struct KEYWORDINFO* p = &keywordmap[m];
|
||||
int cmp = strcasecmp(p->tag,name);
|
||||
m = (L + R) / 2;
|
||||
p = &keywordmap[m];
|
||||
cmp = strcasecmp(p->tag,name);
|
||||
if(cmp == 0) return p;
|
||||
if(cmp < 0)
|
||||
L = (m + 1);
|
||||
@ -1196,13 +1198,14 @@ lookupAtomictype(NCD4parser* parser, const char* name)
|
||||
int n = nclistlength(parser->atomictypes);
|
||||
int L = 0;
|
||||
int R = (n - 1);
|
||||
int m, cmp;
|
||||
NCD4node* p;
|
||||
|
||||
for(;;) {
|
||||
if(L > R) break;
|
||||
int m = (L + R) / 2;
|
||||
m = (L + R) / 2;
|
||||
p = (NCD4node*)nclistget(parser->atomictypes,m);
|
||||
int cmp = strcasecmp(p->name,name);
|
||||
cmp = strcasecmp(p->name,name);
|
||||
if(cmp == 0) return p;
|
||||
if(cmp < 0)
|
||||
L = (m + 1);
|
||||
|
@ -102,6 +102,7 @@ char*
|
||||
NCD4_makeFQN(NCD4node* node)
|
||||
{
|
||||
char* fqn = NULL;
|
||||
char* escaped;
|
||||
int i;
|
||||
NCD4node* g = node;
|
||||
NClist* path = nclistnew();
|
||||
@ -121,7 +122,7 @@ NCD4_makeFQN(NCD4node* node)
|
||||
NCD4node* elem = (NCD4node*)nclistget(path,i);
|
||||
if(elem->sort != NCD4_GROUP) break;
|
||||
/* Add in the group name */
|
||||
char* escaped = backslashEscape(elem->name);
|
||||
escaped = backslashEscape(elem->name);
|
||||
if(escaped == NULL) {free(fqn); fqn = NULL; goto done;}
|
||||
strcat(fqn,"/");
|
||||
strcat(fqn,escaped);
|
||||
@ -342,8 +343,8 @@ NCD4_saveblob(NCD4meta* meta, void* mem)
|
||||
int
|
||||
NCD4_error(int code, const int line, const char* file, const char* fmt, ...)
|
||||
{
|
||||
fprintf(stderr,"(%s:%d) ",file,line);
|
||||
va_list argv;
|
||||
fprintf(stderr,"(%s:%d) ",file,line);
|
||||
va_start(argv,fmt);
|
||||
vfprintf(stderr,fmt,argv);
|
||||
fprintf(stderr,"\n");
|
||||
|
@ -66,6 +66,7 @@ NC_combinehostport(NCURI* uri)
|
||||
size_t len;
|
||||
char* host = NULL;
|
||||
char* port = NULL;
|
||||
char* hp = NULL;
|
||||
if(uri == NULL) return NULL;
|
||||
host = uri->host;
|
||||
port = uri->port;
|
||||
@ -73,7 +74,7 @@ NC_combinehostport(NCURI* uri)
|
||||
if(port != NULL && strlen(port) == 0) port = NULL;
|
||||
len = strlen(host);
|
||||
if(port != NULL) len += (1+strlen(port));
|
||||
char* hp = (char*)malloc(len+1);
|
||||
hp = (char*)malloc(len+1);
|
||||
if(hp == NULL) return NULL;
|
||||
strncpy(hp,host,len);
|
||||
if(port != NULL) {
|
||||
|
@ -338,7 +338,8 @@ done:
|
||||
static struct NCTriple*
|
||||
rclocate(const char* key, const char* hostport)
|
||||
{
|
||||
int i,found;
|
||||
int i, found, t;
|
||||
size_t hplen;
|
||||
NClist* rc = ncrc_globalstate.rcinfo.triples;
|
||||
NCTriple* triple = NULL;
|
||||
|
||||
@ -350,8 +351,7 @@ rclocate(const char* key, const char* hostport)
|
||||
|
||||
for(found=0,i=0;i<nclistlength(rc);i++) {
|
||||
triple = (NCTriple*)nclistget(rc,i);
|
||||
size_t hplen = strlen(triple->host);
|
||||
int t;
|
||||
hplen = strlen(triple->host);
|
||||
if(strcmp(key,triple->key) != 0) continue; /* keys do not match */
|
||||
/* If the triple entry has no url, then use it
|
||||
(because we have checked all other cases)*/
|
||||
|
@ -289,9 +289,10 @@ static nc_utf8proc_bool nc_grapheme_break_simple(int lbc, int tbc) {
|
||||
static nc_utf8proc_bool nc_grapheme_break_extended(int lbc, int tbc, nc_utf8proc_int32_t *state)
|
||||
{
|
||||
int lbc_override = lbc;
|
||||
nc_utf8proc_bool break_permitted;
|
||||
if (state && *state != UTF8PROC_BOUNDCLASS_START)
|
||||
lbc_override = *state;
|
||||
nc_utf8proc_bool break_permitted = nc_grapheme_break_simple(lbc_override, tbc);
|
||||
break_permitted = nc_grapheme_break_simple(lbc_override, tbc);
|
||||
if (state) {
|
||||
// Special support for GB 12/13 made possible by GB999. After two RI
|
||||
// class codepoints we want to force a break. Do this by resetting the
|
||||
|
@ -1778,11 +1778,12 @@ NC3_inq_var_fill(const NC_var *varp, void *fill_value)
|
||||
*/
|
||||
attrpp = NC_findattr(&varp->attrs, _FillValue);
|
||||
if ( attrpp != NULL ) {
|
||||
const void *xp;
|
||||
/* User defined fill value */
|
||||
if ( (*attrpp)->type != varp->type || (*attrpp)->nelems != 1 )
|
||||
return NC_EBADTYPE;
|
||||
|
||||
const void *xp = (*attrpp)->xvalue;
|
||||
xp = (*attrpp)->xvalue;
|
||||
/* value stored in xvalue is in external representation, may need byte-swap */
|
||||
switch(varp->type) {
|
||||
case NC_CHAR: return ncx_getn_text (&xp, 1, (char*)fill_value);
|
||||
|
11
libsrc/ncx.h
11
libsrc/ncx.h
@ -45,6 +45,17 @@
|
||||
#define CRAYFLOAT 1 /* CRAY Floating point */
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#if __STDC_VERSION__ == 199901L /* C99 */
|
||||
/* "inline" is a keyword */
|
||||
#elif _MSC_VER >= 1500 /* MSVC 9 or newer */
|
||||
#define inline __inline
|
||||
#elif __GNUC__ >= 3 /* GCC 3 or newer */
|
||||
#define inline __inline
|
||||
#else /* Unknown or ancient */
|
||||
#define inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* External sizes of the primitive elements.
|
||||
|
@ -2267,6 +2267,9 @@ APIPrefix`x_get_size_t'(const void **xpp, size_t *ulp)
|
||||
int
|
||||
APIPrefix`x_put_off_t'(void **xpp, const off_t *lp, size_t sizeof_off_t)
|
||||
{
|
||||
/* similar to put_ix_int() */
|
||||
uchar *cp = (uchar *) *xpp;
|
||||
|
||||
/* No negative offsets stored in netcdf */
|
||||
if (*lp < 0) {
|
||||
/* Assume this is an overflow of a 32-bit int... */
|
||||
@ -2275,9 +2278,6 @@ APIPrefix`x_put_off_t'(void **xpp, const off_t *lp, size_t sizeof_off_t)
|
||||
|
||||
assert(sizeof_off_t == 4 || sizeof_off_t == 8);
|
||||
|
||||
/* similar to put_ix_int() */
|
||||
uchar *cp = (uchar *) *xpp;
|
||||
|
||||
if (sizeof_off_t == 4) {
|
||||
*cp++ = (uchar) ((*lp) >> 24);
|
||||
*cp++ = (uchar)(((*lp) & 0x00ff0000) >> 16);
|
||||
|
@ -1382,6 +1382,7 @@ int
|
||||
TestFunc(att)_text(AttVarArgs)
|
||||
{
|
||||
int i, j, err, ncid, nok=0;
|
||||
double dtmp;
|
||||
IntType k, ndx[1];
|
||||
text value[MAX_NELS];
|
||||
|
||||
@ -1426,7 +1427,7 @@ TestFunc(att)_text(AttVarArgs)
|
||||
|
||||
for (k = 0; k < ATT_LEN(i,j); k++) {
|
||||
ndx[0] = k;
|
||||
double dtmp = hash(ATT_TYPE(i,j), -1, ndx);
|
||||
dtmp = hash(ATT_TYPE(i,j), -1, ndx);
|
||||
value[k] = (text)dtmp;
|
||||
}
|
||||
err = PutAtt(text)(ncid, i, ATT_NAME(i,j), ATT_LEN(i,j), value);
|
||||
|
@ -2504,7 +2504,7 @@ TestFunc(set_default_format)(void)
|
||||
int
|
||||
TestFunc(delete)(void)
|
||||
{
|
||||
int err, nok=0;;
|
||||
int err, nok=0;
|
||||
int ncid;
|
||||
|
||||
err = FileCreate(scratch, NC_CLOBBER, &ncid);
|
||||
|
@ -284,6 +284,7 @@ main(int argc, char **argv)
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing enum interuptus...");
|
||||
{
|
||||
unsigned char ubyte_value = 42;
|
||||
#define GEEKY_NAME "Galadriel"
|
||||
|
||||
/* Create a file. */
|
||||
@ -304,7 +305,6 @@ main(int argc, char **argv)
|
||||
/* Close the file. */
|
||||
if (nc_close(ncid) != NC_EINVAL) ERR;
|
||||
|
||||
unsigned char ubyte_value = 42;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_insert_enum(ncid, typeid, "name", &ubyte_value)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
@ -54,6 +54,7 @@ OCerror
|
||||
ocinternalinitialize(void)
|
||||
{
|
||||
int stat = OC_NOERR;
|
||||
CURLcode cstat = CURLE_OK;
|
||||
|
||||
if(ocinitialized) return OC_NOERR;
|
||||
ocinitialized = 1;
|
||||
@ -68,7 +69,6 @@ ocinternalinitialize(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
CURLcode cstat = CURLE_OK;
|
||||
cstat = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(cstat != CURLE_OK)
|
||||
fprintf(stderr,"curl_global_init failed!\n");
|
||||
|
@ -365,14 +365,15 @@ mergedas1(OCnode* dds, OCnode* das)
|
||||
for(i=0;i<nclistlength(das->subnodes);i++) {
|
||||
OCnode* attnode = (OCnode*)nclistget(das->subnodes,i);
|
||||
if(attnode->octype == OC_Attribute) {
|
||||
OCattribute* att;
|
||||
if(dds->octype == OC_Atomic
|
||||
|| dds->octype == OC_Sequence
|
||||
|| dds->octype == OC_Structure
|
||||
|| dds->octype == OC_Grid)
|
||||
attnode->att.var = dds;
|
||||
OCattribute* att = makeattribute(attnode->name,
|
||||
attnode->etype,
|
||||
attnode->att.values);
|
||||
att = makeattribute(attnode->name,
|
||||
attnode->etype,
|
||||
attnode->att.values);
|
||||
nclistpush(dds->attributes,(void*)att);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user