Building Controls Virtual Test Bed
util/utilXml.h
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 <stdio.h>
105 //#include <stdlib.h>
106 #include <string.h>
107 #include <expat.h>
108 //#include <errno.h>
109 
110 #if defined(__amigaos__) && defined(__USE_INLINE__)
111 #include <proto/expat.h>
112 #endif
113 
114 #ifdef XML_LARGE_SIZE
115 #if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
116 #define XML_FMT_INT_MOD "I64"
117 #else
118 #define XML_FMT_INT_MOD "ll"
119 #endif
120 #else
121 #define XML_FMT_INT_MOD "l"
122 #endif
123 
124 
125 #define BUFFSIZE 8192
126 
127 char Buff[BUFFSIZE];
128 
132 typedef struct Stack{
133  char** head;
134  int top;
135  int cur;
136 } Stack;
137 
138 
140 
141 char* att;
142 char* vals;
143 int* numVals;
146 
153 char * inputVars;
156 char** inputKeys;
158 int source;
159 const int * strLen;
160 
169 static void XMLCALL
170 EPstart(void *data, const char *el, const char **attr);
171 
179 static void XMLCALL
180 EPend(void *data, const char *el);
181 
182 
189 void freeResource(char** strArr, int n);
190 
191 
208 
209 int getepvariables( char* const fileName,
210  char* const myOutputVarsName,
211  char* const myOutputVarsType,
212  int* const myNumOutputVars,
213  char* const myInputKeys,
214  int* const myNumInputKeys,
215  char* const myInputVars,
216  int* const myNumInputVars,
217  int* const myInputVarsType,
218  int* const myStrLen);
219 
237 
238 int getepvariablesFMU( char* const fileName,
239  char* const myOutputVarsName,
240  char* const myOutputVarsType,
241  int* const myNumOutputVars,
242  char* const myInputKeys,
243  int* const myNumInputKeys,
244  char* const myInputVars,
245  int* const myNumInputVars,
246  int* const myInputVarsType,
247  int* const myStrLen);
248 
253 int stackPopBCVTB();
254 
259 int stackPushBCVTB(char* str);
260 
278 int
279 getxmlvalues(char* const fileName,
280  char* const exp,
281  char* const myVals,
282  int* const myNumVals,
283  int const myStrLen);
284 
287 //
290 static void XMLCALL
291 start(void *data, const char *el, const char **attr);
292 
295 //
298 static void XMLCALL
299 end(void *data, const char *el);
300 
316 int getnumberofxmlvalues( char* const fileName,
317  char* const exp);
318 
345 int getxmlvaluesf(char* const fileName,
346  char* const exp,
347  char* const atrName,
348  int* const nVal,
349  char* const str,
350  int* const strLen);
351 
373 int getxmlvalue(char* const fileName,
374  char* const exp,
375  char* const str,
376  int* const nVals,
377  int const strLen);
378 
389 int check_variable_cfg_Validate(char* const fileName);
390 
static void XMLCALL EPstart(void *data, const char *el, const char **attr)
Call back functions that will be used by the expat xml parser.
static void XMLCALL EPend(void *data, const char *el)
Call back functions that will be used by the expat xml parser.
int cur
Definition: util/utilXml.h:135
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 * 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 * numVals
Local global variable for function getxmlvalue.
Definition: util/utilXml.h:143
Stack expStk
Variables for getxmlvalue function.
Definition: util/utilXml.h:139
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
struct Stack Stack
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
void freeResource(char **strArr, int n)
This method frees the local memory allocated.
Definition: util/utilXml.c:216
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 top
Definition: util/utilXml.h:134
int getxmlvalue(char *const fileName, char *const exp, char *const str, int *const nVals, int const strLen)
Definition: util/utilXml.c:828
int getxmlvalues(char *const fileName, char *const exp, char *const myVals, int *const myNumVals, int const myStrLen)
Definition: util/utilXml.c:549
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
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
static void XMLCALL start(void *data, const char *el, const char **attr)
Call back functions that will be used by the expat xml parser.
static void XMLCALL end(void *data, const char *el)
Call back functions that will be used by the expat xml parser.
int ERROR_STATUS
flag for xml element handler error status settings
Definition: util/utilXml.h:145
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 stackPopBCVTB()
Stack operation, this function will pop one element from stack and will free the resource unused...
Definition: util/utilXml.c:496
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