File: spent.cxx

package info (click to toggle)
opensp 1.5.2-13
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, 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 (76 lines) | stat: -rw-r--r-- 1,702 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
// Copyright (c) 1995 James Clark
// See the file COPYING for copying permission.

#include "config.h"

#include "sptchar.h"
#include "EntityApp.h"
#include "InputSource.h"
#include "OutputCharStream.h"
#include "SpentMessages.h"

#ifdef SP_NAMESPACE
using namespace SP_NAMESPACE;
#endif

class SpentApp : public EntityApp {
public:
  SpentApp();
  void processOption(AppChar opt, const AppChar *arg);
  int processSysid(const StringC &);
private:
  Boolean isNdata_;
  Boolean rawOutput_;
};

SP_DEFINE_APP(SpentApp)

SpentApp::SpentApp()
: rawOutput_(0), isNdata_(0)
{
  registerOption('n', SP_T("non-sgml"), SpentMessages::nHelp);
  registerOption('r', SP_T("raw"), SpentMessages::rHelp);
  registerInfo(SpentMessages::info1);
  registerInfo(SpentMessages::info2);
}

void SpentApp::processOption(AppChar opt, const AppChar *arg)
{
  switch (opt) {
  case 'n':
    isNdata_ = 1;
    if (!outputCodingSystem_)
      outputCodingSystem_ = codingSystemKit_->identityCodingSystem();
    rawOutput_ = 1;
    break;
  case 'r':
    rawOutput_ = 1;
    break;
  default:
    EntityApp::processOption(opt, arg);
    break;
  }
}

int SpentApp::processSysid(const StringC &sysid)
{
  InputSource *in = entityManager()->open(sysid,
					  systemCharset(),
					  InputSourceOrigin::make(),
					  isNdata_ ? ExtendEntityManager::isNdata : 0,
					  *this);
  if (!in)
    return 1;
  OutputCharStream *os = makeStdOut();
  if (!rawOutput_)
    os = new RecordOutputCharStream(os);
  for (;;) {
    Xchar c = in->get(*this);
    if (c == InputSource::eE)
      break;
    in->extendToBufferEnd();
    os->write(in->currentTokenStart(), in->currentTokenLength());
  }
  delete os;
  return in->accessError();
}