Building Controls Virtual Test Bed
util/utilXml.c
Go to the documentation of this file.
1 // Methods for parsing XML files.
2 
3 /*
4 ********************************************************************
5 Copyright Notice
6 ----------------
7 
8 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008, The
9 Regents of the University of California, through Lawrence Berkeley
10 National Laboratory (subject to receipt of any required approvals from
11 the U.S. Dept. of Energy). All rights reserved.
12 
13 If you have questions about your rights to use or distribute this
14 software, please contact Berkeley Lab's Technology Transfer Department
15 at TTD@lbl.gov
16 
17 NOTICE. This software was developed under partial funding from the U.S.
18 Department of Energy. As such, the U.S. Government has been granted for
19 itself and others acting on its behalf a paid-up, nonexclusive,
20 irrevocable, worldwide license in the Software to reproduce, prepare
21 derivative works, and perform publicly and display publicly. Beginning
22 five (5) years after the date permission to assert copyright is obtained
23 from the U.S. Department of Energy, and subject to any subsequent five
24 (5) year renewals, the U.S. Government is granted for itself and others
25 acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide
26 license in the Software to reproduce, prepare derivative works,
27 distribute copies to the public, perform publicly and display publicly,
28 and to permit others to do so.
29 
30 
31 Modified BSD License agreement
32 ------------------------------
33 
34 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008, The
35 Regents of the University of California, through Lawrence Berkeley
36 National Laboratory (subject to receipt of any required approvals from
37 the U.S. Dept. of Energy). All rights reserved.
38 
39 Redistribution and use in source and binary forms, with or without
40 modification, are permitted provided that the following conditions are met:
41 
42  1. Redistributions of source code must retain the above copyright
43  notice, this list of conditions and the following disclaimer.
44  2. Redistributions in binary form must reproduce the above copyright
45  notice, this list of conditions and the following disclaimer in
46  the documentation and/or other materials provided with the
47  distribution.
48  3. Neither the name of the University of California, Lawrence
49  Berkeley National Laboratory, U.S. Dept. of Energy nor the names
50  of its contributors may be used to endorse or promote products
51  derived from this software without specific prior written permission.
52 
53 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
54 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
56 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
57 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
60 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 
65 You are under no obligation whatsoever to provide any bug fixes,
66 patches, or upgrades to the features, functionality or performance of
67 the source code ("Enhancements") to anyone; however, if you choose to
68 make your Enhancements available either publicly, or directly to
69 Lawrence Berkeley National Laboratory, without imposing a separate
70 written license agreement for such Enhancements, then you hereby grant
71 the following license: a non-exclusive, royalty-free perpetual license
72 to install, use, modify, prepare derivative works, incorporate into
73 other computer software, distribute, and sublicense such enhancements or
74 derivative works thereof, in binary and source code form.
75 
76 ********************************************************************
77 */
78 
103 
104 #include "utilXml.h"
105 
114 static void XMLCALL
115 EPstart(void *data, const char *el, const char **attr)
116 {
117  int i, j, k;
118  if(ERROR_STATUS == 1) return;
119  if( 0 == strcmp(el, "BCVTB-variables") )
120  return;
121  if( 0 == strcmp(el, "variable") ) {
122  if( 0 == strcmp(attr[1], "EnergyPlus") )
123  source = 0;
124  else
125  source = 1;
126  return;
127  }
128  if( 0 == strcmp(el, "EnergyPlus") ) {
129  if( 0 == source){
130  for(i=0; attr[i]; i++)i=i;
131  if (i != 4) {
132  fprintf(stderr, "Error: Variable configuration file invalid.\n"
133  " Expected two attribute values for source\n"
134  " of EnergyPlus: 'name' and 'type'.\n");
135  ERROR_STATUS = 1; return;
136  }
137  if ( 0 == strcmp(attr[0], "name") && 0 == strcmp(attr[2], "type") )
138  i = 0;
139  else if( 0 == strcmp(attr[2], "name") && 0 == strcmp(attr[0],"type"))
140  i = 2;
141  else {
142  fprintf(stderr, "Error: Variable configuration file not valide.\n"
143  " Expected two attribute values for source\n"
144  " of EnergyPlus: 'name' and 'type'.\n");
145  ERROR_STATUS = 1; return;
146  }
147 
148  if( (strlen(outputVarsName)+strlen(attr[(i+1)%4])+2) > (*strLen) ){
149  fprintf(stderr, "Error: Not enough memory allocated for EnergyPlus output.\n"
150  " Allocated: %d.\n", *strLen);
151  ERROR_STATUS = 1; return;
152  }
153  strcat(outputVarsName,(char*) attr[(i+1)%4]);
154  strcat(outputVarsName, (char*) ";");
155 
156  if( (strlen(outputVarsType)+strlen(attr[(i+3)%4])+2) > *strLen ){
157  fprintf(stderr, "Error: Not enough memory allocated for EnergyPlus output.\n"
158  " Allocated: %d.\n", *strLen);
159  ERROR_STATUS = 1; return;
160  }
161  strcat(outputVarsType, (char*) attr[(i+3)%4]);
162  strcat(outputVarsType, (char*) ";");
163 
165  }
166  else if( 1 == source) {
167  for( i=0; attr[i]; i++)i=i;
168  if( 2 != i ){
169  fprintf(stderr, "Error: Expecting one input variable in one\n"
170  " element in xml file.\n");
171  ERROR_STATUS = 1; return;
172  }
173  for( j=0; j< numInputKeys; j++) {
174  if( 0 == strcmp((char*)inputKeys[j], (char*)attr[0]) ){
175  if( (strlen(inputVars)+strlen(attr[1])+2) > *strLen){
176  fprintf(stderr, "Error: Memory allocated for parsed E+ input\n"
177  " variables name is not enough,\n"
178  " allocated: %d.\n", *strLen);
179  ERROR_STATUS = 1; return;
180  }
181  inputVarsType[*numInputVars] = j+1;
182  strcat(inputVars,attr[1]);
183  strcat(inputVars, ";");
184  *numInputVars = *numInputVars + 1;
185  break;
186  }
187  }
188  if( numInputKeys == j) {
189  fprintf(stderr, "Error: Unknown input variable type: %s.\n", attr[0]);
190  ERROR_STATUS = 1; return;
191  }
192  }
193  }
194 }
195 
203 static void XMLCALL
204 EPend(void *data, const char *el)
205 {
206  source = -1;
207 }
208 
209 
216 void freeResource(char** strArr, int n){
217  int i;
218  for(i=0; i<n; i++)
219  free(strArr[i]);
220  free(strArr);
221 }
222 
223 
240 
241 int getepvariables( char* const fileName,
242  char* const myOutputVarsName,
243  char* const myOutputVarsType,
244  int* const myNumOutputVars,
245  char* const myInputKeys,
246  int* const myNumInputKeys,
247  char* const myInputVars,
248  int* const myNumInputVars,
249  int* const myInputVarsType,
250  int* const myStrLen){
251 
252  FILE * fd;
253  XML_Parser p;
254  int i, j, count, ret;
255  ret = check_variable_cfg_Validate(fileName);
256  if(-1 == ret)
257  return -1;
258 
259  fd = fopen(fileName, "r");
260  if(!fd){
261  fprintf(stderr, "Error: Could not open file '%s' when getting EnergyPlus variables.\n", fileName);
262  return -1;
263  }
264  p = XML_ParserCreate(NULL);
265  if(!p){
266  fprintf(stderr, "Error: Could not allocate memory for parser in function 'getepvariables'.\n");
267  return -1;
268  }
269 
270  outputVarsName = myOutputVarsName;
271  outputVarsType = myOutputVarsType;
272  numOutputVars = myNumOutputVars;
273  inputVars = myInputVars;
274  inputVarsType = myInputVarsType;
275  numInputVars = myNumInputVars;
276  numInputKeys = *myNumInputKeys;
277  strLen = myStrLen;
278  i=0; j=0; count=0;
279  inputKeys = NULL;
280  while(1){
281  if(myInputKeys[count] == '\0') {
282  if(inputKeys[i][j] != '\0')
283  inputKeys[i][j] = '\0';
284  break;
285  }
286  if(myInputKeys[count] == ','){
287  inputKeys[i][j]='\0';
288  i++;
289  j=0;
290  count++;
291  }
292  else {
293  if(j == 0) {
294  inputKeys = (char**) realloc(inputKeys, sizeof(char*) * (i+1) );
295  if(inputKeys == NULL) {
296  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'\n");
297  return -1;
298  }
299  inputKeys[i] = NULL;
300  }
301 
302  inputKeys[i] = (char*)realloc(inputKeys[i], sizeof(char) * (j+2) );
303  if(inputKeys[i] == NULL) {
304  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'.\n");
305  return -1;
306  }
307  inputKeys[i][j] = myInputKeys[count];
308  j++; count++;
309  }
310  }
311  if((i+1) != *myNumInputKeys ){
312  fprintf(stderr,
313  "Error: Number of input variables keys found does not match:\nFound %d, expected %d\n",
314  i+1, * myNumInputKeys);
315  freeResource(inputKeys, i+1);
316  return -1;
317  }
318  *numOutputVars = 0;
319  *numInputVars = 0;
320  outputVarsName[0] = '\0';
321  outputVarsType[0] = '\0';
322  inputVars[0] = '\0';
323  source = -1;
324  ERROR_STATUS = 0;
325  XML_SetElementHandler(p, EPstart, EPend);
326 
327  for (;;) {
328  int done;
329  int len;
330 
331  len = (int)fread(Buff, 1, BUFFSIZE, fd);
332  if (ferror(fd)) {
333  fprintf(stderr, "Error when reading xml variables in '%s'.\n", fileName);
335  return -1;
336  }
337  done = feof(fd);
338 
339  if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR
340  || ERROR_STATUS == 1) {
341  fprintf(stderr, "Error: Parser error in file '%s':\n%s\n",
342  fileName,
343  XML_ErrorString(XML_GetErrorCode(p)));
345  return -1;
346  }
347 
348  if (done)
349  break;
350  }
351  XML_ParserFree(p);
352  fclose(fd);
354  return 0;
355 }
356 
374 
375 int getepvariablesFMU( char* const fileName,
376  char* const myOutputVarsName,
377  char* const myOutputVarsType,
378  int* const myNumOutputVars,
379  char* const myInputKeys,
380  int* const myNumInputKeys,
381  char* const myInputVars,
382  int* const myNumInputVars,
383  int* const myInputVarsType,
384  int* const myStrLen){
385 
386  FILE * fd;
387  XML_Parser p;
388  int i, j, count, ret;
389  //ret = check_variable_cfg_Validate(fileName);
390  //if(-1 == ret)
391  //return -1;
392 
393  fd = fopen(fileName, "r");
394  if(!fd){
395  fprintf(stderr, "Error: Could not open file '%s' when getting EnergyPlus variables.\n", fileName);
396  return -1;
397  }
398  p = XML_ParserCreate(NULL);
399  if(!p){
400  fprintf(stderr, "Error: Could not allocate memory for parser in function 'getepvariables'.\n");
401  return -1;
402  }
403 
404  outputVarsName = myOutputVarsName;
405  outputVarsType = myOutputVarsType;
406  numOutputVars = myNumOutputVars;
407  inputVars = myInputVars;
408  inputVarsType = myInputVarsType;
409  numInputVars = myNumInputVars;
410  numInputKeys = *myNumInputKeys;
411  strLen = myStrLen;
412  i=0; j=0; count=0;
413  inputKeys = NULL;
414  while(1){
415  if(myInputKeys[count] == '\0') {
416  if(inputKeys[i][j] != '\0')
417  inputKeys[i][j] = '\0';
418  break;
419  }
420  if(myInputKeys[count] == ','){
421  inputKeys[i][j]='\0';
422  i++;
423  j=0;
424  count++;
425  }
426  else {
427  if(j == 0) {
428  inputKeys = (char**) realloc(inputKeys, sizeof(char*) * (i+1) );
429  if(inputKeys == NULL) {
430  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'\n");
431  return -1;
432  }
433  inputKeys[i] = NULL;
434  }
435 
436  inputKeys[i] = (char*)realloc(inputKeys[i], sizeof(char) * (j+2) );
437  if(inputKeys[i] == NULL) {
438  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'.\n");
439  return -1;
440  }
441  inputKeys[i][j] = myInputKeys[count];
442  j++; count++;
443  }
444  }
445  if((i+1) != *myNumInputKeys ){
446  fprintf(stderr,
447  "Error: Number of input variables keys found does not match:\nFound %d, expected %d\n",
448  i+1, * myNumInputKeys);
449  freeResource(inputKeys, i+1);
450  return -1;
451  }
452  *numOutputVars = 0;
453  *numInputVars = 0;
454  outputVarsName[0] = '\0';
455  outputVarsType[0] = '\0';
456  inputVars[0] = '\0';
457  source = -1;
458  ERROR_STATUS = 0;
459  XML_SetElementHandler(p, EPstart, EPend);
460 
461  for (;;) {
462  int done;
463  int len;
464 
465  len = (int)fread(Buff, 1, BUFFSIZE, fd);
466  if (ferror(fd)) {
467  fprintf(stderr, "Error when reading xml variables in '%s'.\n", fileName);
469  return -1;
470  }
471  done = feof(fd);
472 
473  if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR
474  || ERROR_STATUS == 1) {
475  fprintf(stderr, "Error: Parser error in file '%s':\n%s\n",
476  fileName,
477  XML_ErrorString(XML_GetErrorCode(p)));
479  return -1;
480  }
481 
482  if (done)
483  break;
484  }
485  XML_ParserFree(p);
486  fclose(fd);
488  return 0;
489 }
490 
491 
497  if(0==expStk.top)
498  return -1;
499  free((expStk.head)[expStk.top]);
500  expStk.head = (char**) realloc(expStk.head, sizeof(char*) * (expStk.top));
501  if(expStk.head == NULL) {
502  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'.\n");
503  return -1;
504  }
505  expStk.top--;
506  return expStk.top;
507 }
508 
513 int stackPushBCVTB(char* str){
514  if(!str) return -1;
515  expStk.top++;
516  expStk.head = (char**) realloc(expStk.head, sizeof(char*) * (expStk.top+1));
517  if(expStk.head == NULL) {
518  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'");
519  return -1;
520  }
521  expStk.head[expStk.top] = (char*)malloc(sizeof(char) * (strlen(str)+1) );
522  if(expStk.head[expStk.top] == NULL) {
523  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'");
524  return -1;
525  }
526  strcpy(expStk.head[expStk.top], str);
527  return expStk.top;
528 }
529 
530 
548 int
549 getxmlvalues(char* const fileName,
550  char* const exp,
551  char* const myVals,
552  int* const myNumVals,
553  int const myStrLen){
554 
555  char* temp;
556  int i,j;
557  FILE * fd;
558  XML_Parser p;
559  vals = myVals;
560  numVals = myNumVals;
561  *numVals = 0;
562  strLen = &myStrLen;
563  att = NULL;
564  expStk.head = NULL;
565  expStk.top = -1;
566  expStk.cur = -1;
567  fd = fopen(fileName, "r");
568  if(!fd) {
569  fprintf(stderr, "Error: Could not open file '%s'.\n", fileName);
570  return -1;
571  }
572  p = XML_ParserCreate(NULL);
573  if (!p) {
574  fprintf(stderr, "Error: Could not allocate memory for parser in function 'getxmlvalue'.\n");
575  return -1;
576  }
577  i=2; j=0;
578  if(!exp || '\0' == exp[0])
579  return -1;
580  if( exp[0] != '/' || exp[1] != '/')
581  return -1;
582 
583  temp = NULL;
584  while(exp[i] != '\0'){
585  if( exp[i] == '/' || exp[i] == '[' || exp[i] == ']') {
586  if(0==j && 0==expStk.top) {
587  fprintf(stderr, "Error when parsing expression in 'utilXml.c'.\n");
588  return -1;
589  }
590  i++;
591  if(strchr(temp, '@'))
592  break;
593  stackPushBCVTB(temp);
594  free(temp);
595  temp = NULL;
596  j=0;
597  }
598  else {
599  j++;
600  temp = (char*) realloc(temp, sizeof(char)*(j+1));
601  if(temp == NULL) {
602  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'.\n");
603  return -1;
604  }
605  temp[j-1]=exp[i];
606  temp[j]='\0';
607  i++;
608  }
609  }
610  if(temp[0] == '@'){
611  att = (char*) malloc(sizeof(char) * (strlen(temp) ) );
612  if(att == NULL) {
613  fprintf(stderr, "Error: Memory allocation failed in 'utilXml.c'.\n");
614  free(temp);
615  return -1;
616  }
617  for(i=1; i<strlen(temp); i++)
618  att[i-1] = temp[i];
619  att[i-1]='\0';
620  free(temp);
621  }
622  else {
623  fprintf(stderr, "Error when parsing expression in 'utilXml.c'.\n");
624  free(temp);
625  free(att);
626  while(i!= -1) stackPopBCVTB();
627  return -1;
628  }
629  expStk.cur = 0;
630  if(1 == PARSEVALUE)
631  vals[0]='\0';
632  *numVals = 0;
633  XML_SetElementHandler(p, start, end);
634 
635  for (;;) {
636  int done;
637  int len;
638 
639  len = (int)fread(Buff, 1, BUFFSIZE, fd);
640  if (ferror(fd)) {
641  fprintf(stderr, "Error when reading xml variables in '%s'.\n", fileName);
642  return -1;
643  }
644  done = feof(fd);
645 
646  if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) {
647  fprintf(stderr, "Error: Parse error in file '%s':\n%s\n",
648  fileName,
649  XML_ErrorString(XML_GetErrorCode(p)));
650  return -1;
651  }
652 
653  if (done)
654  break;
655  }
656  if( 0 == *numVals ){
657  fprintf(stderr, "Error: Did not find xml value\n for expression '%s'.\n in file '%s'\n",
658  exp, fileName);
659  }
660  while( i != -1 )
661  i = stackPopBCVTB();
662  att = NULL;
663  XML_ParserFree(p);
664  fclose(fd);
665  return 0;
666 
667 }
668 
671 //
674 static void XMLCALL
675 start(void *data, const char *el, const char **attr)
676 {
677  int i;
678  if(0 == strcmp(el, expStk.head[expStk.cur]) && expStk.cur < expStk.top )
679  expStk.cur++;
680  if(expStk.cur == expStk.top){
681  for(i=0; attr[i]; i += 2) {
682  if( 0 == strcmp(attr[i], att) ){
683  if(1 == PARSEVALUE){
684  if( (strlen(vals)+strlen(attr[i+1])+2) > *strLen){
685  fprintf(stderr, "Error: Memory allocated for parsed attribute\n"
686  " values is not enough, allocated: %d.\n",
687  *strLen);
688  *numVals = strlen(vals) + strlen(attr[i+1])+2;
689  return;
690  }
691  if(vals[0] != '\0')
692  strcat(vals, ";");
693  strcat(vals, attr[i+1]);
694  }
695  *numVals = *numVals + 1;
696  }
697  }
698  }
699 }
700 
703 //
706 static void XMLCALL
707 end(void *data, const char *el)
708 {
709  if(!strcmp(el, expStk.head[expStk.cur])&& expStk.cur>0)
710  expStk.cur--;
711 }
712 
713 
729 int getnumberofxmlvalues( char* const fileName,
730  char* const exp){
731  int n, ret;
732  char* str;
733  int strLen = 0;
734  n=0;
735  str = NULL;
736  PARSEVALUE = 0;
737  ret = getxmlvalues(fileName,
738  exp,
739  str,
740  &n,
741  strLen);
742  if(-1 == ret){
743  fprintf(stderr, "Error: In getnumberofxmlvalues.\n");
744  return ret;
745  }
746  return n;
747 }
748 
775 int getxmlvaluesf(char* const fileName,
776  char* const exp,
777  char* const atrName,
778  int* const nVal,
779  char* const str,
780  int* const strLen) {
784  int ret = check_variable_cfg_Validate(fileName);
785  if(-1 == ret)
786  return -1;
788  PARSEVALUE = 1;
789  ret = getxmlvalues(fileName,
790  exp,
791  str,
792  nVal,
793  *strLen);
794  if( -1 == ret || *nVal > *strLen )
795  return -1;
796  if( strlen(str)+2 >= *strLen ) {
797  fprintf(stderr, "Error: Not enough memory allocated for parsed xml\n"
798  " values in getxmlvaluesf, allocated: %zx.\n",
799  (size_t)*strlen);
800  return -1;
801  }
802  strcat(str,";");
803  return 0;
804 
805 }
806 
828 int getxmlvalue(char* const fileName,
829  char* const exp,
830  char* const str,
831  int* const nVals,
832  int const strLen) {
833  int ret;
834  PARSEVALUE = 1;
835  ret = getxmlvalues(fileName,
836  exp,
837  str,
838  nVals,
839  strLen);
840 
841  if(ret != 0){
842  fprintf(stderr,"Error: Error when attempting to parse file '%s'\n",fileName);
843  return -1;
844  }
845  if(*nVals == 0){
846  fprintf(stderr,"Error: No xml value parsed in file '%s'\n",fileName);
847  return -1;
848  }
849  if(*nVals > 1){
850  fprintf(stderr, "Error: More than one xml values parsed, \n"
851  " while expecting one value. \n"
852  " number of xml values parsed is: %d\n"
853  " xPath: '%s'\n",
854  *nVals, exp);
855  return -1;
856  }
857  return 0;
858 }
869 int check_variable_cfg_Validate(char* const fileName){
870 
871  char *BCVTB_HOME, *dtdFileName;
872  char *command;
873  FILE *dtdF;
874  int ret;
875 #ifdef _MSC_VER /************* Windows specific code ********/
876  const char *const xmlPath = "\\lib\\xml\\";
877  const char *const jarPath = "\\lib\\xml\\build\\jar\\DTDValidator.jar";
878 #else /************* End of Windows specific code *******/
879  const char *const xmlPath = "/lib/xml/";
880  const char *const jarPath = "/lib/xml/build/jar/DTDValidator.jar";
881 #endif
882 
883  BCVTB_HOME = getenv("BCVTB_HOME");
884  if(NULL == BCVTB_HOME){
885  fprintf(stderr, "Error: Cannot get environment variable: BCVTB_HOME.\n");
886  return -1;
887  }
888  command = (char*) malloc( sizeof(char) *
889  ( strlen(BCVTB_HOME) +
890  strlen(fileName) +
891  strlen("variables.dtd")
892  + 20
893  )
894  * 3
895  );
896  if(NULL == command) {
897  fprintf(stderr, "Error: Memory allocation failed in"
898  " check_variable_cfg_Validate"
899  " when parsing file '%s'.\n"
900  " Program aborting.\n", fileName);
901  return -1;
902  }
903  dtdFileName = (char*) malloc( sizeof (char) * ( strlen(BCVTB_HOME) + 30));
904  if(NULL == command) {
905  fprintf(stderr, "Error: Memory allocation failed in"
906  " check_variable_cfg_Validate"
907  " when parsing file '%s'. \n"
908  " Program aborting.\n", fileName);
909  return -1;
910  }
911 
912  sprintf(dtdFileName, "%s%s%s", BCVTB_HOME, xmlPath, "variables.dtd");
913  dtdF = fopen(dtdFileName, "r");
914  if( NULL == dtdF ){
915  fprintf(stderr, "Error: Cannot open '%s'.\n", dtdFileName);
916  return -1;
917  }
918  else fclose(dtdF);
919  sprintf(command, "java -jar \"%s%s\" \"%s\" \"%s%s\"",
920  BCVTB_HOME, jarPath, fileName, BCVTB_HOME, xmlPath);
921  ret = system(command);
922  if( ret != 0)
923  return -1;
924  else
925  return 0;
926 }
927 
for i
Definition: compile.m:69
int cur
Definition: util/utilXml.h:135
int * inputVarsType
the ineger array to store the types of each input variables
Definition: util/utilXml.h:155
#define BUFFSIZE
Definition: util/utilXml.h:125
char Buff[BUFFSIZE]
Local buffer for reading in the xml file.
Definition: util/utilXml.h:127
int getxmlvalues(char *const fileName, char *const exp, char *const myVals, int *const myNumVals, int const myStrLen)
Definition: util/utilXml.c:549
static void XMLCALL EPstart(void *data, const char *el, const char **attr)
Call back functions that will be used by the expat xml parser.
Definition: util/utilXml.c:115
int * numVals
Local global variable for function getxmlvalue.
Definition: util/utilXml.h:143
int getepvariables(char *const fileName, char *const myOutputVarsName, char *const myOutputVarsType, int *const myNumOutputVars, char *const myInputKeys, int *const myNumInputKeys, char *const myInputVars, int *const myNumInputVars, int *const myInputVarsType, int *const myStrLen)
This method will return the input and output variable for EnergyPlus in sequence. ...
Definition: util/utilXml.c:241
Stack expStk
Variables for getxmlvalue function.
Definition: util/utilXml.h:139
int getepvariablesFMU(char *const fileName, char *const myOutputVarsName, char *const myOutputVarsType, int *const myNumOutputVars, char *const myInputKeys, int *const myNumInputKeys, char *const myInputVars, int *const myNumInputVars, int *const myInputVarsType, int *const myStrLen)
This method will return the input and output variable for EnergyPlus in sequence. ...
Definition: util/utilXml.c:375
int * numOutputVars
the integer pointer to the number of output variables
Definition: util/utilXml.h:152
char * outputVarsName
local global variables for function getepvariables
Definition: util/utilXml.h:150
fprintf([' ', 'Trying to send client error from MATLAB to the BCVTB.'])
int PARSEVALUE
flag for parsing xml values 1 if parse, 0 if not parse
Definition: util/utilXml.h:144
char * vals
Local global variable for function getxmlvalue.
Definition: util/utilXml.h:142
int stackPushBCVTB(char *str)
Stack operation, will push one element into the stack and will allocate memory for the new element...
Definition: util/utilXml.c:513
int check_variable_cfg_Validate(char *const fileName)
This method checks the validity of the variables configuration xml file for a given dtd file that is ...
Definition: util/utilXml.c:869
int getnumberofxmlvalues(char *const fileName, char *const exp)
Definition: util/utilXml.c:729
int top
Definition: util/utilXml.h:134
static void XMLCALL start(void *data, const char *el, const char **attr)
Call back functions that will be used by the expat xml parser.
Definition: util/utilXml.c:675
int stackPopBCVTB()
Stack operation, this function will pop one element from stack and will free the resource unused...
Definition: util/utilXml.c:496
static void XMLCALL end(void *data, const char *el)
Call back functions that will be used by the expat xml parser.
Definition: util/utilXml.c:707
const int * strLen
the length of string parsed to this function
Definition: util/utilXml.h:159
char * att
Local global variable for function getxmlvalue.
Definition: util/utilXml.h:141
char ** head
Definition: util/utilXml.h:133
int numInputKeys
the number of input variable types
Definition: util/utilXml.h:157
static void XMLCALL EPend(void *data, const char *el)
Call back functions that will be used by the expat xml parser.
Definition: util/utilXml.c:204
int getxmlvaluesf(char *const fileName, char *const exp, char *const atrName, int *const nVal, char *const str, int *const strLen)
Definition: util/utilXml.c:775
int ERROR_STATUS
flag for xml element handler error status settings
Definition: util/utilXml.h:145
void freeResource(char **strArr, int n)
This method frees the local memory allocated.
Definition: util/utilXml.c:216
int source
flag for function /c getepvariables 0=EnergyPlus, 1=Ptolemy
Definition: util/utilXml.h:158
char * outputVarsType
the string pointer to the parsed output variable types
Definition: util/utilXml.h:151
char ** inputKeys
the string array to store the types of input variable types
Definition: util/utilXml.h:156
int * numInputVars
the integer pointer to the number of input variables
Definition: util/utilXml.h:154
char * inputVars
the string pointer to the input variables
Definition: util/utilXml.h:153
if strcmp(retVal, '') disp('Simulink is not installed on this computer.') disp('The Simulink library will not be compiled.') else makeSBlock
int getxmlvalue(char *const fileName, char *const exp, char *const str, int *const nVals, int const strLen)
Definition: util/utilXml.c:828