diff options
Diffstat (limited to 'server/src/templateparser.cc')
| -rw-r--r-- | server/src/templateparser.cc | 95 | 
1 files changed, 40 insertions, 55 deletions
diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc index 8db6bbf..49cc29d 100644 --- a/server/src/templateparser.cc +++ b/server/src/templateparser.cc @@ -47,28 +47,14 @@  void TemplateParser::error(const char* fmt, ...)  { -  // TODO: Throw exception here. -    va_list argp; -  int s = 256; -  char *p = new char[s]; -  /* See printf(3) for details on the loop how to get the right buffersize. */ -  while(1) { -    va_start(argp, fmt); -    int n = vsnprintf(p, s, fmt, argp); -    va_end(argp); -    if(n > -1 && n < s) -      break; -    if(n > -1)  /* glibc 2.1 */ -      s = n+1;  /* precisely what is needed */ -    else        /* glibc 2.0 */ -      s *= 2;   /* twice the old size */ -    delete[] p; -    p = new char[s]; -  } +  char *p; +  va_start(argp, fmt); +  vasprintf(&p, fmt, argp); +  va_end(argp);    PRACRO_ERR_LOG(macro, "Error in TemplateParser: %s\n", p); -  delete[] p; -  throw Exception("Error in TemplateParser"); +  throw Exception(std::string("Error in TemplateParser: ") + p); +  free(p);  }  TemplateParser::TemplateParser(std::string course) @@ -77,11 +63,7 @@ TemplateParser::TemplateParser(std::string course)    t = new Template();    current_macro = NULL; -#ifndef TEST_TEMPLATEPARSER    file = Conf::xml_basedir + "/templates/" + course + ".xml"; -#else -  file = "../xml/templates/" + course + ".xml"; -#endif/*TEST_TEMPLATEPARSER*/    PRACRO_DEBUG(macro, "Using template file: %s\n", file.c_str()); @@ -114,7 +96,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri    }    // Create macro and enable parsing of queries, maps and window -  if(name == "macro") { +  if(name == "macro" || name == "header") {      if(state != COURSE) error("macro found outside course.");      state = MACRO; @@ -122,6 +104,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri      Macro m;      m.attributes = attributes; +    m.isHeader = name == "header";      t->course.macros.push_back(m);      current_macro = &(t->course.macros.back()); @@ -134,7 +117,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri  void TemplateParser::endTag(std::string name)  {    if(name == "course") state = UNDEFINED; -  if(name == "macro") { +  if(name == "macro" || name == "header") {      current_macro = NULL;      state = COURSE;    } @@ -182,41 +165,43 @@ void print_attributes(std::string prefix,  int main()  { +  Conf::xml_basedir = "../xml/"; +    try { -  TemplateParser parser("example"); -  parser.parse(); +    TemplateParser parser("example"); +    parser.parse(); -  Template *t = parser.getTemplate(); +    Template *t = parser.getTemplate(); -  printf("[Template]:\n"); -  print_attributes("\t-", t->attributes); +    printf("[Template]:\n"); +    print_attributes("\t-", t->attributes); -  printf("\t[Course]:\n"); -  print_attributes("\t\t-", t->course.attributes); +    printf("\t[Course]:\n"); +    print_attributes("\t\t-", t->course.attributes); -  printf("\t\t[Macros]:\n"); -  std::vector< Macro >::iterator i = t->course.macros.begin(); - -  while(i != t->course.macros.end()) { -    printf("\t\t\t[Macro]:\n"); -    print_attributes("\t\t\t\t-", (*i).attributes); -     -    std::vector< Query >::iterator qi = (*i).queries.begin(); -    while(qi != (*i).queries.end()) { -      printf("\t\t\t\t[Query]:\n"); -      print_attributes("\t\t\t\t\t-", (*qi).attributes); -      qi++; +    printf("\t\t[Macros]:\n"); +    std::vector< Macro >::iterator i = t->course.macros.begin(); + +    while(i != t->course.macros.end()) { +      printf("\t\t\t[Macro]:\n"); +      print_attributes("\t\t\t\t-", (*i).attributes); +       +      std::vector< Query >::iterator qi = (*i).queries.begin(); +      while(qi != (*i).queries.end()) { +        printf("\t\t\t\t[Query]:\n"); +        print_attributes("\t\t\t\t\t-", (*qi).attributes); +        qi++; +      } +       +      std::vector< Map >::iterator mi = (*i).maps.begin(); +      while(mi != (*i).maps.end()) { +        printf("\t\t\t\t[Map]:\n"); +        print_attributes("\t\t\t\t\t-", (*mi).attributes); +        mi++; +      } +       +      i++;      } - -    std::vector< Map >::iterator mi = (*i).maps.begin(); -    while(mi != (*i).maps.end()) { -      printf("\t\t\t\t[Map]:\n"); -      print_attributes("\t\t\t\t\t-", (*mi).attributes); -      mi++; -    } - -    i++; -  }    } catch(Exception &e) {      printf("ERROR: %s\n", e.what());      return 1;  | 
