+/**************************************************************************
+ * Function :
+ * getNameAttribute,getFormatAttribute,getSizeAttribute,getValueAttribute
+ * getValueStrAttribute
+ * Description :
+ * Read the attribute from the input file.
+ *
+ * Parameters :
+ * in , input file handle.
+ *
+ * Return values :
+ * address of the attribute.
+ *
+ **************************************************************************/
+
+char * getNameAttribute(parse_file *in)
+{
+ char * token, car;
+ token = getName(in);
+ if(strcmp("name",token))in->error(in,"name was expected");
+ getEqual(in);
+
+ car = seekNextChar(in);
+ if(car == EOF)in->error(in,"name was expected");
+ else if(car == '\"')token = getQuotedString(in);
+ else token = getName(in);
+ return token;
+}
+
+char * getFormatAttribute(parse_file *in)
+{
+ char * token;
+
+ //format is an option
+ token = getToken(in);
+ if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
+ ungetToken(in);
+ return NULL;
+ }
+
+ if(strcmp("format",token))in->error(in,"format was expected");
+ getEqual(in);
+ token = getQuotedString(in);
+ return token;
+}
+
+int getSizeAttribute(parse_file *in)
+{
+ /* skip name and equal */
+ getName(in);
+ getEqual(in);
+
+ return getSize(in);
+}
+
+int getValueAttribute(parse_file *in)
+{
+ /* skip name and equal */
+ getName(in);
+ getEqual(in);
+
+ return getNumber(in);
+}
+
+//for <label name=label_name value=n/>, value is an option
+char * getValueStrAttribute(parse_file *in)
+{
+ char * token;
+
+ token = getToken(in);
+ if(strcmp("/",token) == 0){
+ ungetToken(in);
+ return NULL;
+ }
+
+ if(strcmp("value",token))in->error(in,"value was expected");
+ getEqual(in);
+ token = getToken(in);
+ if(in->type != NUMBER) in->error(in,"number was expected");
+ return token;
+}
+
+char * getDescription(parse_file *in)
+{
+ long int pos;
+ char * token, car, *str;
+
+ pos = ftell(in->fp);
+
+ getLAnglebracket(in);
+ token = getName(in);
+ if(strcmp("description",token)){
+ fseek(in->fp, pos, SEEK_SET);
+ return NULL;
+ }
+
+ getRAnglebracket(in);
+
+ pos = 0;
+ while((car = getc(in->fp)) != EOF) {
+ if(car == '<') break;
+ if(car == '\0') continue;
+ in->buffer[pos] = car;
+ pos++;
+ }
+ if(car == EOF)in->error(in,"not a valid description");
+ in->buffer[pos] = '\0';
+
+ str = allocAndCopy(in->buffer);
+
+ getForwardslash(in);
+ token = getName(in);
+ if(strcmp("description", token))in->error(in,"not a valid description");
+ getRAnglebracket(in);
+
+ return str;
+}
+
+/*****************************************************************************
+ *Function name
+ * parseFacility : generate event list
+ *Input params
+ * in : input file handle
+ * fac : empty facility
+ *Output params
+ * fac : facility filled with event list
+ ****************************************************************************/
+
+void parseFacility(parse_file *in, facility_t * fac)
+{
+ char * token;
+ event_t *ev;
+
+ fac->name = allocAndCopy(getNameAttribute(in));
+ getRAnglebracket(in);
+
+ fac->description = getDescription(in);
+
+ while(1){
+ getLAnglebracket(in);
+
+ token = getToken(in);
+ if(in->type == ENDFILE)
+ in->error(in,"the definition of the facility is not finished");
+
+ if(strcmp("event",token) == 0){
+ ev = (event_t*) memAlloc(sizeof(event_t));
+ sequence_push(&(fac->events),ev);
+ parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types));
+ }else if(strcmp("type",token) == 0){
+ parseTypeDefinition(in, &(fac->unnamed_types), &(fac->named_types));
+ }else if(in->type == FORWARDSLASH){
+ break;
+ }else in->error(in,"event or type token expected\n");
+ }
+
+ token = getName(in);
+ if(strcmp("facility",token)) in->error(in,"not the end of the facility");
+ getRAnglebracket(in); //</facility>
+}