netcdf-c/ncdump/nctrunc.c
Dennis Heimbigner 4c92fc3405 Remove netcdf-4 conditional on the dispatch table.
Partially address: https://github.com/Unidata/netcdf-c/issues/1056

Currently, some of the entries in the dispatch table
are conditional'd on USE_NETCDF4.

As a step in upgrading the dispatch table for use
with user-defined tables, we remove that conditional.
This means that all dispatch tables must implement the
netcdf-4 specific functions even if only to make them
return NC_ENOTNC4. To simplify this, a set of default
functions are defined in libdispatch/dnotnc4.c to provide this
behavior. The file libdispatch/dnotnc3.c is also relevant to
this.

The primary fix is to modify the various dispatch tables to
remove the conditional and use the functions in
libdispatch/dnotnc4.c as appropriate. In practice, all of the
existing tables are prepared to handle this, so the only
real change is to remove the conditionals.

Misc. Unrelated fixes
1. Fix some annoying warnings in ncvalidator.

Notes:
1. This has not been tested with either pnetcdf or hdf4 enabled.
   When those are enabled, it is possible that there are still
   some conditionals that need to be fixed.
2019-07-20 13:59:40 -06:00

57 lines
1.1 KiB
C

/*********************************************************************
* Copyright 2018, UCAR/Unidata
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*********************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define BUFLEN 100000
int
main(int argc, char** argv)
{
unsigned char buffer[BUFLEN];
size_t count, red, avail, trunc;
unsigned char* p = buffer;
size_t i;
FILE* input = stdin;
if(argc > 1) {
input = fopen(argv[1],"r");
}
/* Read the whole file */
p = buffer;
red = 0;
avail = BUFLEN;
for(;;) {
count = fread(p,1,avail,input);
p += count;
red += count;
avail -= count;
if(feof(input)) break;
}
trunc = red;
for(i=(red-1);i>=0;i--) {
if(buffer[i] != '\0') {
trunc = i + 1;
break;
}
}
p = buffer;
avail = trunc;
for(;;) {
count = fwrite(p,1,avail,stdout);
if(count == 0) break;
p += count;
avail -= count;
if(avail == 0) break;
}
if(avail > 0)
exit(1);
else
exit(0);
}