File: Dtd.cxx

package info (click to toggle)
opensp 1.5.2-15.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,168 kB
  • sloc: cpp: 65,784; ansic: 17,124; sh: 11,193; xml: 2,704; makefile: 895; perl: 561; yacc: 288; sed: 16
file content (94 lines) | stat: -rw-r--r-- 2,084 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 1994 James Clark
// See the file COPYING for copying permission.

#ifdef __GNUG__
#pragma implementation
#endif
#include "splib.h"
#include "Dtd.h"
#include "Syntax.h"

#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif

Dtd::Dtd(const StringC &name, Boolean isBase)
: name_(new StringResource<Char>(name)),
  nCurrentAttribute_(0),
  nElementDefinition_(0),
  nAttributeDefinitionList_(0),
  nElementType_(0),
  isBase_(isBase),
  isInstantitated_(0)
{
  documentElementType_ = new ElementType(name, allocElementTypeIndex());
  insertElementType(documentElementType_);
}

Dtd::~Dtd() {}

Boolean Dtd::shortrefIndex(const StringC &str, const Syntax &syntax,
			   size_t &index)
{
  const int *indexP = shortrefTable_.lookup(str);
  if (indexP) {
    index = *indexP;
    return 1;
  }
  if (!syntax.isValidShortref(str))
    return 0;
  shortrefTable_.insert(str, int(shortrefs_.size()));
  index = shortrefs_.size();
  shortrefs_.push_back(str);
  return 1;
}

void Dtd::addNeededShortref(const StringC &str)
{
  if (!shortrefTable_.lookup(str)) {
    shortrefTable_.insert(str, shortrefs_.size());
    shortrefs_.push_back(str);
  }
}

void Dtd::setDefaultEntity(const Ptr<Entity> &entity,
			   ParserState &parser)
{
  defaultEntity_ = entity;
  
  // If the new default entity was defined in a DTD, then
  // any defaulted entities must have come from an LPD
  // on the first pass, in which case we shouldn't replace them.
  // Otherwise we need to replace all the defaulted entities.
  if (entity->declInActiveLpd()) {
    NamedResourceTable<Entity> tem;
    {
      EntityIter iter(generalEntityTable_);
      for (;;) {
	Ptr<Entity> old(iter.next());
	if (old.isNull())
	  break;
	if (old->defaulted()) {
	  Ptr<Entity> e(defaultEntity_->copy());
	  e->setDefaulted();
	  e->setName(old->name());
	  e->generateSystemId(parser);
	  tem.insert(e);
	}
      }
    }
    {
      EntityIter iter(tem);
      for (;;) {
	Ptr<Entity> e(iter.next());
	if (e.isNull())
	  break;
	generalEntityTable_.insert(e, 1);
      }
    }
  }
}

#ifdef SP_NAMESPACE
}
#endif