1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include <s2_dsapi/cx_docu2.hxx>
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <../../parser/inc/tokens/parseinc.hxx>
28 #include <s2_dsapi/tokrecv.hxx>
29 #include <s2_dsapi/tk_html.hxx>
30 #include <s2_dsapi/tk_xml.hxx>
31 #include <s2_dsapi/tk_docw2.hxx>
32 #include <x_parse2.hxx>
33 
34 
35 
36 namespace csi
37 {
38 namespace dsapi
39 {
40 
41 
42 
43 bool
PassNewToken()44 Cx_Base::PassNewToken()
45 {
46 	if (pNewToken)
47 	{
48 		rReceiver.Receive(*pNewToken.Release());
49 
50 		return true;
51 	}
52 	return false;
53 }
54 
55 TkpContext &
FollowUpContext()56 Cx_Base::FollowUpContext()
57 {
58 	csv_assert(pFollowUpContext != 0);
59 	return *pFollowUpContext;
60 }
61 
62 void
Handle_DocuSyntaxError(CharacterSource & io_rText)63 Cx_Base::Handle_DocuSyntaxError( CharacterSource & io_rText )
64 {
65     // KORR_FUTURE
66     // Put this into Error Log File
67 
68     Cerr() << "Error:  Syntax error in documentation within "
69               << "this text:\n\""
70               << io_rText.CutToken()
71               << "\"."
72               << Endl();
73     SetToken( new Tok_Word(io_rText.CurToken()) );
74 }
75 
76 void
ReadCharChain(CharacterSource & io_rText)77 Cx_EoHtml::ReadCharChain( CharacterSource & io_rText )
78 {
79 	if ( NULCH == jumpTo(io_rText,'>') )
80 		throw X_AutodocParser(X_AutodocParser::x_UnexpectedEOF);
81 	io_rText.MoveOn();
82 	SetToken(new Tok_HtmlTag(io_rText.CutToken(),bToken_IsStartOfParagraph));
83 }
84 
85 void
ReadCharChain(CharacterSource & io_rText)86 Cx_EoXmlConst::ReadCharChain( CharacterSource & io_rText )
87 {
88     char c = jumpTo(io_rText,'>','*');
89 	if ( NULCH == c OR '*' == c )
90     {
91         Handle_DocuSyntaxError(io_rText);
92         return;
93     }
94 
95 	io_rText.MoveOn();
96 	io_rText.CutToken();
97 	SetToken(new Tok_XmlConst(eTokenId));
98 }
99 
100 void
ReadCharChain(CharacterSource & io_rText)101 Cx_EoXmlLink_BeginTag::ReadCharChain( CharacterSource & io_rText )
102 {
103 	String 	sScope;
104 	String 	sDim;
105 
106     do {
107         char cReached = jumpTo(io_rText,'"','>','*');
108         switch (cReached)
109     	{
110 	    	case '"':
111             {
112             	io_rText.MoveOn();
113 			    io_rText.CutToken();
114                 char c = jumpTo(io_rText,'"','*', '>');
115             	if ( NULCH == c OR '*' == c OR '>' == c)
116                 {
117                     if ( '>' == c )
118                     	io_rText.MoveOn();
119                     Handle_DocuSyntaxError(io_rText);
120                     return;
121                 }
122 
123 		    	const char * pAttribute = io_rText.CutToken();
124                 if ( *pAttribute != '[' )
125                     sScope = pAttribute;
126                 else
127                     sDim = pAttribute;
128 
129                 io_rText.MoveOn();
130     			break;
131             }
132 	    	case '>':
133 		    	break;
134             case '*':
135                 Handle_DocuSyntaxError(io_rText);
136                 return;
137     		default:
138 	    		throw X_AutodocParser(X_AutodocParser::x_UnexpectedEOF);
139     	}   // end switch
140     }   while ( io_rText.CurChar() != '>' );
141 
142 	io_rText.MoveOn();
143 	io_rText.CutToken();
144 	SetToken( new Tok_XmlLink_BeginTag(eTokenId, sScope.c_str(), sDim.c_str()) );
145 }
146 
147 void
ReadCharChain(CharacterSource & io_rText)148 Cx_EoXmlLink_EndTag::ReadCharChain( CharacterSource & io_rText )
149 {
150     char c = jumpTo(io_rText,'>','*');
151     if ( NULCH == c OR '*' == c )
152     {
153         Handle_DocuSyntaxError(io_rText);
154         return;
155     }
156 
157 	io_rText.MoveOn();
158 	io_rText.CutToken();
159 	SetToken(new Tok_XmlLink_EndTag(eTokenId));
160 }
161 
162 void
ReadCharChain(CharacterSource & io_rText)163 Cx_EoXmlFormat_BeginTag::ReadCharChain( CharacterSource & io_rText )
164 {
165 	String 	sDim;
166 
167     char cReached = jumpTo(io_rText,'"','>','*');
168     switch (cReached)
169     {
170         case '"':
171         {
172             io_rText.MoveOn();
173 			io_rText.CutToken();
174 
175             char c = jumpTo(io_rText,'"','*','>');
176             if ( NULCH == c OR '*' == c OR '>' == c )
177             {
178                 if ('>' == c )
179                     io_rText.MoveOn();
180                 Handle_DocuSyntaxError(io_rText);
181                 return;
182             }
183 
184 		    sDim = io_rText.CutToken();
185 
186             c = jumpTo(io_rText,'>','*');
187             if ( NULCH == c OR '*' == c )
188             {
189                 Handle_DocuSyntaxError(io_rText);
190                 return;
191             }
192     		break;
193         }
194         case '>':
195 		   	break;
196         case '*':
197             Handle_DocuSyntaxError(io_rText);
198             return;
199     	default:
200 	    	throw X_AutodocParser(X_AutodocParser::x_UnexpectedEOF);
201     }   // end switch
202 
203 	io_rText.MoveOn();
204 	io_rText.CutToken();
205 	SetToken(new Tok_XmlFormat_BeginTag(eTokenId, sDim));
206 }
207 
208 void
ReadCharChain(CharacterSource & io_rText)209 Cx_EoXmlFormat_EndTag::ReadCharChain( CharacterSource & io_rText )
210 {
211     char c = jumpTo(io_rText,'>','*');
212     if ( NULCH == c OR '*' == c )
213     {
214         Handle_DocuSyntaxError(io_rText);
215         return;
216     }
217 
218 	io_rText.MoveOn();
219 	io_rText.CutToken();
220 	SetToken(new Tok_XmlFormat_EndTag(eTokenId));
221 }
222 
223 void
ReadCharChain(CharacterSource & io_rText)224 Cx_CheckStar::ReadCharChain( CharacterSource & io_rText )
225 {
226 	bEndTokenFound = false;
227 	if (bIsEnd)
228 	{
229 		char cNext = jumpOver(io_rText,'*');
230 		if ( NULCH == cNext )
231 			throw X_AutodocParser(X_AutodocParser::x_UnexpectedEOF);
232 		if (cNext == '/')
233 		{
234 			io_rText.MoveOn();
235 			SetToken(new Tok_DocuEnd);
236             bEndTokenFound = true;
237 		}
238 		else
239 		{
240 			SetToken( new Tok_Word(io_rText.CutToken()) );
241 		}
242 	}
243 	else
244 	{
245 		jumpToWhite(io_rText);
246 		SetToken( new Tok_Word(io_rText.CutToken()) );
247 	}
248 }
249 
250 TkpContext &
FollowUpContext()251 Cx_CheckStar::FollowUpContext()
252 {
253 	if (bEndTokenFound)
254 		return *pEnd_FollowUpContext;
255 	else
256 		return Cx_Base::FollowUpContext();
257 }
258 
259 }   // namespace dsapi
260 }   // namespace csi
261 
262