mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
Merge pull request #237 from Unidata/issue236
ncdump can generate nul characters � ; when dumping ncml using -x.
This commit is contained in:
commit
f5414bfee2
@ -49,6 +49,7 @@ typedef int ssize_t;
|
|||||||
#include "isnan.h"
|
#include "isnan.h"
|
||||||
#include "cdl.h"
|
#include "cdl.h"
|
||||||
|
|
||||||
|
#define XML_VERSION "1.0"
|
||||||
|
|
||||||
#define int64_t long long
|
#define int64_t long long
|
||||||
#define uint64_t unsigned long long
|
#define uint64_t unsigned long long
|
||||||
@ -393,8 +394,8 @@ done:
|
|||||||
static void
|
static void
|
||||||
pr_initx(int ncid, const char *path)
|
pr_initx(int ncid, const char *path)
|
||||||
{
|
{
|
||||||
printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<netcdf xmlns=\"http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2\" location=\"%s\">\n",
|
printf("<?xml version=\"%s\" encoding=\"UTF-8\"?>\n<netcdf xmlns=\"http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2\" location=\"%s\">\n",
|
||||||
path);
|
XML_VERSION, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -472,6 +473,7 @@ pr_att_string(
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
pr_attx_string(
|
pr_attx_string(
|
||||||
|
const char* attname,
|
||||||
size_t len,
|
size_t len,
|
||||||
const char *string
|
const char *string
|
||||||
)
|
)
|
||||||
@ -480,6 +482,7 @@ pr_attx_string(
|
|||||||
const char *cp;
|
const char *cp;
|
||||||
const char *sp;
|
const char *sp;
|
||||||
unsigned char uc;
|
unsigned char uc;
|
||||||
|
int nulcount = 0;
|
||||||
|
|
||||||
cp = string;
|
cp = string;
|
||||||
printf ("\"");
|
printf ("\"");
|
||||||
@ -510,6 +513,11 @@ pr_attx_string(
|
|||||||
case '\t':
|
case '\t':
|
||||||
printf ("	");
|
printf ("	");
|
||||||
break;
|
break;
|
||||||
|
case '\0':
|
||||||
|
printf ("�");
|
||||||
|
if(nulcount++ == 0)
|
||||||
|
fprintf(stderr,"Attribute: '%s'; value contains nul characters; producing illegal xml\n",attname);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (iscntrl(uc))
|
if (iscntrl(uc))
|
||||||
printf ("&#%d;",uc);
|
printf ("&#%d;",uc);
|
||||||
@ -1120,7 +1128,7 @@ pr_attx(
|
|||||||
varid != NC_GLOBAL ? " " : "",
|
varid != NC_GLOBAL ? " " : "",
|
||||||
att.name);
|
att.name);
|
||||||
/* print attvals as a string with XML escapes */
|
/* print attvals as a string with XML escapes */
|
||||||
pr_attx_string(attvalslen, attvals);
|
pr_attx_string(att.name, attvalslen, attvals);
|
||||||
} else { /* non-string attribute */
|
} else { /* non-string attribute */
|
||||||
char att_type_name[NC_MAX_NAME + 1];
|
char att_type_name[NC_MAX_NAME + 1];
|
||||||
get_type_name(ncid, att.type, att_type_name);
|
get_type_name(ncid, att.type, att_type_name);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<attribute name="gtatt" value="<, >, ', ", and &" />
|
<attribute name="gtatt" value="<, >, ', ", and &" />
|
||||||
<attribute name="gnatt" type="int" value="3 4" />
|
<attribute name="gnatt" type="int" value="3 4" />
|
||||||
<attribute name="gdatt" type="double" value="-7.02788826649782e-09 7.02788826649782e-09" />
|
<attribute name="gdatt" type="double" value="-7.02788826649782e-09 7.02788826649782e-09" />
|
||||||
|
<attribute name="gnul" value="�abcd��hello" />
|
||||||
<variable name="var" shape="t m" type="float">
|
<variable name="var" shape="t m" type="float">
|
||||||
<attribute name="tatt" value="text attribute value" />
|
<attribute name="tatt" value="text attribute value" />
|
||||||
<attribute name="natt" type="int" value="1 2" />
|
<attribute name="natt" type="int" value="1 2" />
|
||||||
|
@ -10,4 +10,5 @@ variables:
|
|||||||
:gtatt = "<, >, \', \", and &" ;
|
:gtatt = "<, >, \', \", and &" ;
|
||||||
:gnatt = 3, 4;
|
:gnatt = 3, 4;
|
||||||
:gdatt = -7.02788826649782e-09, 7.02788826649782e-09 ;
|
:gdatt = -7.02788826649782e-09, 7.02788826649782e-09 ;
|
||||||
|
char :gnul = "\000abcd\000\000hello\000" ;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user