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 "cdl.h"
|
||||
|
||||
#define XML_VERSION "1.0"
|
||||
|
||||
#define int64_t long long
|
||||
#define uint64_t unsigned long long
|
||||
@ -393,8 +394,8 @@ done:
|
||||
static void
|
||||
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",
|
||||
path);
|
||||
printf("<?xml version=\"%s\" encoding=\"UTF-8\"?>\n<netcdf xmlns=\"http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2\" location=\"%s\">\n",
|
||||
XML_VERSION, path);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -472,6 +473,7 @@ pr_att_string(
|
||||
*/
|
||||
static void
|
||||
pr_attx_string(
|
||||
const char* attname,
|
||||
size_t len,
|
||||
const char *string
|
||||
)
|
||||
@ -480,6 +482,7 @@ pr_attx_string(
|
||||
const char *cp;
|
||||
const char *sp;
|
||||
unsigned char uc;
|
||||
int nulcount = 0;
|
||||
|
||||
cp = string;
|
||||
printf ("\"");
|
||||
@ -510,6 +513,11 @@ pr_attx_string(
|
||||
case '\t':
|
||||
printf ("	");
|
||||
break;
|
||||
case '\0':
|
||||
printf ("�");
|
||||
if(nulcount++ == 0)
|
||||
fprintf(stderr,"Attribute: '%s'; value contains nul characters; producing illegal xml\n",attname);
|
||||
break;
|
||||
default:
|
||||
if (iscntrl(uc))
|
||||
printf ("&#%d;",uc);
|
||||
@ -1120,7 +1128,7 @@ pr_attx(
|
||||
varid != NC_GLOBAL ? " " : "",
|
||||
att.name);
|
||||
/* print attvals as a string with XML escapes */
|
||||
pr_attx_string(attvalslen, attvals);
|
||||
pr_attx_string(att.name, attvalslen, attvals);
|
||||
} else { /* non-string attribute */
|
||||
char att_type_name[NC_MAX_NAME + 1];
|
||||
get_type_name(ncid, att.type, att_type_name);
|
||||
|
@ -5,6 +5,7 @@
|
||||
<attribute name="gtatt" value="<, >, ', ", and &" />
|
||||
<attribute name="gnatt" type="int" value="3 4" />
|
||||
<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">
|
||||
<attribute name="tatt" value="text attribute value" />
|
||||
<attribute name="natt" type="int" value="1 2" />
|
||||
|
@ -10,4 +10,5 @@ variables:
|
||||
:gtatt = "<, >, \', \", and &" ;
|
||||
:gnatt = 3, 4;
|
||||
:gdatt = -7.02788826649782e-09, 7.02788826649782e-09 ;
|
||||
char :gnul = "\000abcd\000\000hello\000" ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user