File: spcat.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 (165 lines) | stat: -rw-r--r-- 4,281 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) 1998, 1999 Matthias Clasen 
// See the file COPYING for copying permission.

#include "config.h"

#include "EntityApp.h"
#include "Entity.h"
#include "Text.h"
#include "Sd.h"
#include "sptchar.h"
#include "OutputCharStream.h"
#include "SpcatMessages.h"

#ifdef SP_NAMESPACE
using namespace SP_NAMESPACE;
#endif

class SpcatApp : public EntityApp {
public:
  SpcatApp();
  void processOption(AppChar opt, const AppChar *arg);
  int processArguments(int argc, AppChar **argv);
  int processSysid(const StringC &);
private:
  Boolean lastFound_;
};

SP_DEFINE_APP(SpcatApp)

SpcatApp::SpcatApp()
 : lastFound_(true)
{
  registerOption('P', SP_T("public-id"), 
                 SpcatMessages::literal, SpcatMessages::PHelp);
  registerOption('S', SP_T("system-id"), 
                 SpcatMessages::literal, SpcatMessages::SHelp);
  registerOption('p', SP_T("parameter-entity"), 
                 SpcatMessages::name, SpcatMessages::pHelp);
  registerOption('d', SP_T("doctype"), 
                 SpcatMessages::name, SpcatMessages::dHelp);
  registerOption('l', SP_T("linktype"),
                 SpcatMessages::name, SpcatMessages::lHelp);
  registerOption('e', SP_T("entity"), 
                 SpcatMessages::name, SpcatMessages::eHelp);
  registerOption('n', SP_T("notation"), 
                 SpcatMessages::name, SpcatMessages::nHelp);
  registerOption('s', SP_T("declaration"), 
                 SpcatMessages::name, SpcatMessages::sHelp);
  registerInfo(SpcatMessages::info1);
  registerInfo(SpcatMessages::info2);
  registerInfo(SpcatMessages::info3);
  registerInfo(SpcatMessages::info4);
}

void SpcatApp::processOption(AppChar opt, const AppChar *arg)
{
  //FIXME This is to avoid calling entityManager() for 
  //EntityApp options, since entityManager() fixes the set 
  //of catalogs and clearEntityManager() didn't work for me.
  switch (opt) {
  case 'P':
  case 'S':
  case 'e':
  case 'p':
  case 'd':
  case 'l':
  case 'n':
  case 's':
    break;
  default: 
    EntityApp::processOption(opt, arg);
    return ;
  }

  ExternalId exId;
  StringC name;
  EntityDecl::DeclType type = EntityDecl::generalEntity; 
  Ptr<EntityManager> ema(entityManager().pointer());
  Sd sd(ema);
  Syntax syntax(sd); 
  Text txt;
  Location loc;

  switch (opt) {
  case 'P':
    for (int i = 0; arg[i] != '\0'; i++) 
      txt.addChar(arg[i], loc);
    const MessageType1 *err, *err1;
    exId.setPublic(txt, systemCharset(), syntax.space(), err, err1);
    break;
  case 'S':
    for (int i = 0; arg[i] != '\0'; i++) 
      txt.addChar(arg[i], loc);
    exId.setSystem(txt);
    break;
  case 'e':
    type = EntityDecl::generalEntity;
    for (int i = 0; arg[i] != '\0'; i++) 
      name += arg[i]; 
    break;
  case 'p':
    type = EntityDecl::parameterEntity;
    //FIXME get a complete syntax from somewhere
    //so that we can say
    //name += syntax.peroDelim();
    name += '%';
    for (int i = 0; arg[i] != '\0'; i++) 
      name += arg[i]; 
    break;
  case 'd':
    type = EntityDecl::doctype;
    for (int i = 0; arg[i] != '\0'; i++) 
      name += arg[i]; 
    break;
  case 'l':
    type = EntityDecl::linktype;
    for (int i = 0; arg[i] != '\0'; i++) 
      name += arg[i]; 
    break;
  case 'n':
    type = EntityDecl::notation;
    for (int i = 0; arg[i] != '\0'; i++) 
      name += arg[i]; 
    break;
  case 's':
    type = EntityDecl::sgml;
    break;
  default:
    EntityApp::processOption(opt, arg);
    return ;
  }

  ExternalTextEntity ent(name, type, loc, exId);
  StringC ret;
  ConstPtr<EntityCatalog> cat = 
         entityManager()->makeCatalog(ret, systemCharset(), *this);
  StringC sysid;

  if ((type == EntityDecl::sgml && cat->sgmlDecl(systemCharset(), *this, sysid, ret)) 
      || cat->lookup(ent, syntax, systemCharset(), *this, ret)) {
    lastFound_ = true;
    //FIXME should use makeStdOut(), but it didn't work for me.
    //OutputCharStream *os = makeStdOut();
    //*os << ret << '\n';	
    //delete os;
    for (int i = 0; i < ret.size(); i++) 
      printf("%c", ret[i]);
    printf("\n");
  } 
  else
    lastFound_ = false;
}

int SpcatApp::processArguments(int argc, AppChar **argv)
{
  if (lastFound_) 
    return 0;
  else 
    return 1;
}

int SpcatApp::processSysid(const StringC &)
{
  return 0;
}