- Port to SL-5
SKIPPED: psi/tecs/make_crv
This commit is contained in:
74
nxio.c
74
nxio.c
@@ -25,8 +25,15 @@
|
||||
*/
|
||||
#include <mxml.h>
|
||||
#include <assert.h>
|
||||
#include "napi.h"
|
||||
#include "nxio.h"
|
||||
#include "nxdataset.h"
|
||||
#include "napiconfig.h"
|
||||
|
||||
/* fix for mxml-2.3 */
|
||||
#ifndef MXML_WRAP
|
||||
#define MXML_WRAP 79
|
||||
#endif
|
||||
|
||||
/* #define TESTMAIN 1 */
|
||||
/*=================== type code handling ================================= */
|
||||
@@ -36,7 +43,8 @@ typedef struct {
|
||||
int nx_type;
|
||||
}type_code;
|
||||
|
||||
static type_code typecode[9];
|
||||
#define NTYPECODE 11
|
||||
static type_code typecode[NTYPECODE];
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void initializeNumberFormats(){
|
||||
type_code myCode;
|
||||
@@ -76,21 +84,31 @@ void initializeNumberFormats(){
|
||||
myCode.nx_type = NX_INT32;
|
||||
typecode[6] = myCode;
|
||||
|
||||
strcpy(myCode.name,"NX_UNIT32");
|
||||
strcpy(myCode.name,"NX_UINT32");
|
||||
strcpy(myCode.format,"%12d");
|
||||
myCode.nx_type = NX_UINT32;
|
||||
typecode[7] = myCode;
|
||||
|
||||
strcpy(myCode.name,"NX_INT64");
|
||||
strcpy(myCode.format,"%24" PRINTF_INT64 );
|
||||
myCode.nx_type = NX_INT64;
|
||||
typecode[8] = myCode;
|
||||
|
||||
strcpy(myCode.name,"NX_UINT64");
|
||||
strcpy(myCode.format,"%24" PRINTF_UINT64);
|
||||
myCode.nx_type = NX_UINT64;
|
||||
typecode[9] = myCode;
|
||||
|
||||
strcpy(myCode.name,"NX_CHAR");
|
||||
strcpy(myCode.format,"%c");
|
||||
myCode.nx_type = NX_CHAR;
|
||||
typecode[8] = myCode;
|
||||
typecode[10] = myCode;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
void setNumberFormat(int nx_type, char *format){
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 9; i++){
|
||||
for(i = 0; i < NTYPECODE; i++){
|
||||
if(typecode[i].nx_type == nx_type){
|
||||
strncpy(typecode[i].format,format,29);
|
||||
}
|
||||
@@ -100,7 +118,7 @@ void setNumberFormat(int nx_type, char *format){
|
||||
static void getNumberFormat(int nx_type, char format[30]){
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 9; i++){
|
||||
for(i = 0; i < NTYPECODE; i++){
|
||||
if(typecode[i].nx_type == nx_type){
|
||||
strncpy(format,typecode[i].format,29);
|
||||
}
|
||||
@@ -110,7 +128,7 @@ static void getNumberFormat(int nx_type, char format[30]){
|
||||
void getNumberText(int nx_type, char *typestring, int typeLen){
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 9; i++){
|
||||
for(i = 0; i < NTYPECODE; i++){
|
||||
if(typecode[i].nx_type == nx_type){
|
||||
strncpy(typestring,typecode[i].name,typeLen);
|
||||
}
|
||||
@@ -138,9 +156,14 @@ myxml_add_char(int ch, /* I - Character to add */
|
||||
*/
|
||||
|
||||
if (*bufsize < 1024)
|
||||
{
|
||||
(*bufsize) *= 2;
|
||||
}
|
||||
else
|
||||
(*bufsize) += 1024;
|
||||
{
|
||||
(*bufsize) *= 3;
|
||||
(*bufsize) /= 2;
|
||||
}
|
||||
|
||||
newbuffer = (char *)malloc(*bufsize*sizeof(char));
|
||||
if(!newbuffer){
|
||||
@@ -204,7 +227,7 @@ extern char *stptok(char *s, char *tok, size_t toklen, char *brk);
|
||||
/*=====================================================================
|
||||
actual stuff for implementing the callback functions
|
||||
=====================================================================*/
|
||||
static void analyzeDim(const char *typeString, int *rank,
|
||||
void analyzeDim(const char *typeString, int *rank,
|
||||
int *iDim, int *type){
|
||||
char dimString[132];
|
||||
char dim[20];
|
||||
@@ -219,6 +242,8 @@ static void analyzeDim(const char *typeString, int *rank,
|
||||
case NX_UINT16:
|
||||
case NX_INT32:
|
||||
case NX_UINT32:
|
||||
case NX_INT64:
|
||||
case NX_UINT64:
|
||||
case NX_FLOAT32:
|
||||
case NX_FLOAT64:
|
||||
iDim[0] = 1;
|
||||
@@ -258,7 +283,7 @@ static void analyzeDim(const char *typeString, int *rank,
|
||||
int translateTypeCode(char *code){
|
||||
int i, result = -1;
|
||||
|
||||
for(i = 0; i < 9; i++){
|
||||
for(i = 0; i < NTYPECODE; i++){
|
||||
if(strstr(code,typecode[i].name) != NULL){
|
||||
result = typecode[i].nx_type;
|
||||
break;
|
||||
@@ -346,7 +371,11 @@ mxml_type_t nexusTypeCallback(mxml_node_t *parent){
|
||||
*/
|
||||
return MXML_OPAQUE;
|
||||
} else{
|
||||
return MXML_CUSTOM;
|
||||
if(strstr(typeString,"NX_CHAR") != NULL){
|
||||
return MXML_OPAQUE;
|
||||
} else {
|
||||
return MXML_CUSTOM;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -411,12 +440,19 @@ static void formatNumber(double value, char *txt, int txtLen,
|
||||
case NX_UINT32:
|
||||
snprintf(txt,txtLen,format,(int)value);
|
||||
break;
|
||||
case NX_INT64:
|
||||
snprintf(txt,txtLen,format,(int64_t)value);
|
||||
break;
|
||||
case NX_UINT64:
|
||||
snprintf(txt,txtLen,format,(uint64_t)value);
|
||||
break;
|
||||
case NX_FLOAT32:
|
||||
case NX_FLOAT64:
|
||||
snprintf(txt,txtLen,format,value);
|
||||
break;
|
||||
default:
|
||||
assert(0); /* something is very wrong here */
|
||||
/*assert(0); something is very wrong here */
|
||||
printf("Problem\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -534,8 +570,12 @@ static int isTextData(mxml_node_t *node){
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* note: not reentrant or thead safe; returns pointer to static storage
|
||||
*/
|
||||
const char *NXwhitespaceCallback(mxml_node_t *node, int where){
|
||||
char *indent;
|
||||
static char *indent = NULL;
|
||||
int len;
|
||||
|
||||
if(strstr(node->value.element.name,"?xml") != NULL){
|
||||
@@ -545,6 +585,11 @@ const char *NXwhitespaceCallback(mxml_node_t *node, int where){
|
||||
if(isTextData(node)){
|
||||
if(where == MXML_WS_BEFORE_OPEN){
|
||||
len = countDepth(node)*2 + 2;
|
||||
if (indent != NULL)
|
||||
{
|
||||
free(indent);
|
||||
indent = NULL;
|
||||
}
|
||||
indent = (char *)malloc(len*sizeof(char));
|
||||
if(indent != NULL){
|
||||
memset(indent,' ',len);
|
||||
@@ -558,6 +603,11 @@ const char *NXwhitespaceCallback(mxml_node_t *node, int where){
|
||||
|
||||
if(where == MXML_WS_BEFORE_OPEN || where == MXML_WS_BEFORE_CLOSE){
|
||||
len = countDepth(node)*2 + 2;
|
||||
if (indent != NULL)
|
||||
{
|
||||
free(indent);
|
||||
indent = NULL;
|
||||
}
|
||||
indent = (char *)malloc(len*sizeof(char));
|
||||
if(indent != NULL){
|
||||
memset(indent,' ',len);
|
||||
|
||||
Reference in New Issue
Block a user