Пример #1
0
/*******************************************
Open a marcXMLFile and parse into its tree
Pre: marcXMLfp contains a pointer to a an xmlFile 
Post: Returns pointer to a parsed tree datastructure, Caller is responsible for
freeing marcXMLfp
*******************************************/
static XmElem * openXmElemTree( FILE *marcXMLfp ){
  char *schemaPath = getenv("MXTOOL_XSD"); //get the pathname of marc21 schema  
  xmlSchemaPtr schemaPtr = mxInit( schemaPath );
  if (schemaPtr==NULL){
    fprintf(stderr, "Error, check MXTOOL_XSD environment variable\n");
    return NULL;
  }
  
  if (marcXMLfp==NULL){
    fprintf(stderr, "Error, could not open xml file\n");
    mxTerm(schemaPtr);
    return NULL;
  }
  
  XmElem *top = NULL;
  int mxReadFileError = mxReadFile( marcXMLfp, schemaPtr, &top );
  mxTerm(schemaPtr);
  
  if (mxReadFileError == 1){
    fprintf(stderr, "\nFailed to parse XML file\n");
    return NULL;
  }else if (mxReadFileError == 2){
    fprintf(stderr, "\nXml did not match schema\n");
    return NULL;
  }
  
  return (top);
}
Пример #2
0
pmatrix createMatrix(mxdata mx, uint rows, uint cols){
	if (mx == NULL || rows == 0 || cols == 0) return NULL;
	pmatrix res = mxInit(cols * rows, rows, cols);
	for (uint i = 0; i < rows; ++i) {
		res->cells[i] = (vecdata)calloc(cols, sizeof(double));
		for (uint j = 0; j < cols; ++j)
			res->cells[i][j] = mx[i][j];
	}
	return res;
}
Пример #3
0
PyObject * Mx_init ( PyObject * self, PyObject * args ){
	XSDFILE = getenv( "MXTOOL_XSD" );
	schemaPtr = mxInit( XSDFILE );
	if ( schemaPtr == NULL ){
		//	error, fix this
		return Py_BuildValue ( "i", 0 );
	} else {
		return Py_BuildValue ( "i", 1 );
	}
}
Пример #4
0
PyObject * Mx_getEnv ( PyObject * self, PyObject * args ){
	const char * fileName;
	PyArg_ParseTuple( args, "s", &fileName );
//	xmlSchemaPtr schemaPtr = NULL;
	schemaPtr = mxInit( fileName );
	if ( schemaPtr == NULL ){
		return Py_BuildValue ( "s", "schema is BAD" );
	} else {
		//	schema is valid
		return Py_BuildValue ( "s", "schema is GOOD" );
	}
}