File: sx.cxx

package info (click to toggle)
opensp 1.5.2-13
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 8,932 kB
  • ctags: 10,036
  • sloc: cpp: 65,784; ansic: 17,124; sh: 11,503; xml: 2,704; makefile: 926; perl: 561; yacc: 288; sed: 16
file content (165 lines) | stat: -rw-r--r-- 5,049 bytes parent folder | download | duplicates (8)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright (c) 1997 James Clark
// See the file COPYING for copying permission.

#include "config.h"
#include "sptchar.h"
#include "OutputCharStream.h"
#include "ParserApp.h"
#include "macros.h"
#include "XmlOutputEventHandler.h"
#include "SxMessages.h"

#include <stdlib.h>

#ifdef SP_NAMESPACE
using namespace SP_NAMESPACE;
#endif

static
struct {
  const ParserApp::AppChar *name;
  PackedBoolean XmlOutputEventHandler::Options::*ptr;
} outputOptionsTable[] = {
  { SP_T("nl-in-tag"), &XmlOutputEventHandler::Options::nlInTag },
  { SP_T("id"), &XmlOutputEventHandler::Options::id },
  { SP_T("notation"), &XmlOutputEventHandler::Options::notation },
  { SP_T("ndata"), &XmlOutputEventHandler::Options::ndata },
  { SP_T("cdata"), &XmlOutputEventHandler::Options::cdata },
  { SP_T("comment"), &XmlOutputEventHandler::Options::comment },
  { SP_T("lower"), &XmlOutputEventHandler::Options::lower },
  { SP_T("pi-escape"), &XmlOutputEventHandler::Options::piEscape },
  { SP_T("empty"), &XmlOutputEventHandler::Options::empty },
  { SP_T("attlist"), &XmlOutputEventHandler::Options::attlist },
  { SP_T("report-entities"), &XmlOutputEventHandler::Options::reportEnts },
  { SP_T("report-input-sources"), &XmlOutputEventHandler::Options::reportIS },
  { SP_T("expand-external"), &XmlOutputEventHandler::Options::expExt },
  { SP_T("expand-internal"), &XmlOutputEventHandler::Options::expInt },
  { SP_T("internal-decl"), &XmlOutputEventHandler::Options::intDecl },
  { SP_T("external-decl"), &XmlOutputEventHandler::Options::extDecl },
  { SP_T("sdata-as-pis"), &XmlOutputEventHandler::Options::sdataAsPi },
  { SP_T("preserve-case"), &XmlOutputEventHandler::Options::preserveCase },
  { SP_T("overwrite"), &XmlOutputEventHandler::Options::overwrite },
  { SP_T("write-outside-outdir"), &XmlOutputEventHandler::Options::writeOutsideOutDir },
};

class SxApp : public ParserApp {
public:
  SxApp();
  ErrorCountEventHandler *makeEventHandler();
  void processOption(AppChar opt, const AppChar *arg);
  int processSysid(const StringC &);
private:
  XmlOutputEventHandler::Options outputOptions_;
  StringC encodingName_;

  // These could be StringCs, which would be a lot of work (getting
  // the right encoding). It doesn't seem to me to be worth it, since
  // these strings are coming in from the OS and only being used to make
  // a file, so they should always be in the encoding that the OS
  // expects. -jphekman
  const char *outputDir_;
  const char *dtdLoc_;
};

SP_DEFINE_APP(SxApp)

SxApp::SxApp()
: ParserApp("unicode")
{
  outputCodingSystem_ = codingSystemKit_->makeCodingSystem("UTF-8", 0);
  changeOptionRegistration('x', AppChar(255));
  registerOption('x', SP_T("xml-output-option"), SxMessages::option,
                 SxMessages::xHelp);
  registerOption('d', SP_T("entity_output_location"), SxMessages::option,
		 SxMessages::xHelp);
  registerOption('l', SP_T("dtd_location"), SxMessages::option,
		 SxMessages::xHelp);
  registerInfo(SxMessages::info1);
  registerInfo(SxMessages::info2);
  registerInfo(SxMessages::info3);
  outputOptions_.nlInTag = 1;
  outputOptions_.intDecl = 1;
  outputOptions_.extDecl = 1;
  outputOptions_.expInt = 1;
  outputOptions_.expExt = 1;
  outputOptions_.overwrite = 1;
  outputOptions_.writeOutsideOutDir = 1;
  outputDir_ = NULL;
  dtdLoc_ = NULL;
}

int SxApp::processSysid(const StringC &sysid)
{
  if (outputOptions_.comment)
    options_.eventsWanted.addCommentDecls();
  if (outputOptions_.notation)
    options_.warnNotationSystemId = 1;
  if (outputOptions_.cdata)
    options_.eventsWanted.addMarkedSections();
  return ParserApp::processSysid(sysid);
}

void SxApp::processOption(AppChar opt, const AppChar *arg)
{
  switch (opt) {
  case AppChar(255):
    ParserApp::processOption('x', arg);
    break;
  case 'x':
    {
      PackedBoolean value;
      if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-') {
	value = 0;
	arg += 3;
      }
      else
	value = 1;
      Boolean found = 0;
      for (size_t i = 0; i < SIZEOF(outputOptionsTable); i++) {
	if (tcscmp(outputOptionsTable[i].name, arg) == 0) {
	  found = 1;
	  outputOptions_.*(outputOptionsTable[i].ptr) = value;
 	  break;
	}
      }
      if (!found)
	message(SxMessages::unknownOutputOption, StringMessageArg(convertInput(arg)));
      break;
    }
  case 'b':
    {
      // Need to generate appropriate encoding declaration.
      ParserApp::processOption(opt, arg);
      if (outputCodingSystem_)
	encodingName_ = convertInput(arg);
      else
	encodingName_.resize(0);
      break;
    }
  case 'd':
    {
      outputDir_ = (const char *)arg;
      break;
    }
  case 'l':
    {
      dtdLoc_ = (const char *)arg;
      break;
    }
  default:
    ParserApp::processOption(opt, arg);
    break;
  }
}

ErrorCountEventHandler *SxApp::makeEventHandler()
{
  return new XmlOutputEventHandler(outputOptions_,
				   new RecordOutputCharStream(makeStdOut()),
				   encodingName_,
				   outputDir_,
				   dtdLoc_,
                                   entityManager(),
				   systemCharset(),
				   this);
}