Annotation of libwww/Library/src/HText.c, revision 2.2
2.1 frystyk 1: /*
2: ** HYPERTEXT OBJECT BUILDER
3: **
4: ** (c) COPYRIGHT MIT 1999.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.2 ! frystyk 6: ** @(#) $Id: HText.c,v 2.1 1999/01/06 15:38:48 frystyk Exp $
2.1 frystyk 7: **
8: ** This generates of a hypertext object and calls the application
9: ** via callbacks.
10: */
11:
12: /* Library include files */
13: #include "wwwsys.h"
14: #include "WWWUtil.h"
15: #include "WWWCore.h"
16: #include "HText.h"
17: #include "HTextImp.h"
18:
19: /* Default callbacks that the application can register */
20: PRIVATE HText_new * text_new;
21: PRIVATE HText_delete * text_delete;
22: PRIVATE HText_build * text_build;
23: PRIVATE HText_addText * text_addText;
24: PRIVATE HText_foundLink * text_foundLink;
25: PRIVATE HText_beginElement * text_beginElement;
26: PRIVATE HText_endElement * text_endElement;
27: PRIVATE HText_unparsedBeginElement * text_unparsedBeginElement;
28: PRIVATE HText_unparsedEndElement * text_unparsedEndElement;
29: PRIVATE HText_unparsedEntity * text_unparsedEntity;
30:
31: /* HText handler instance */
32: struct _HTextImp {
33: HText * app;
34: HText_new * text_new;
35: HText_delete * text_delete;
36: HText_build * text_build;
37: HText_addText * text_addText;
38: HText_foundLink * text_foundLink;
39: HText_beginElement * text_beginElement;
40: HText_endElement * text_endElement;
41: HText_unparsedBeginElement *text_unparsedBeginElement;
42: HText_unparsedEndElement * text_unparsedEndElement;
43: HText_unparsedEntity * text_unparsedEntity;
44: };
45:
46: /* --------------------------------------------------------------------------- */
47:
48: PUBLIC HTextImp * HTextImp_new (HTRequest * request,
49: HTParentAnchor * anchor,
50: HTStream * output_stream)
51: {
52: HTextImp * me = NULL;
53: if ((me = (HTextImp *) HT_CALLOC(1, sizeof (HTextImp))) == NULL)
54: HT_OUTOFMEM("HTextImp_new");
55: me->text_new = text_new;
56: me->text_delete = text_delete;
57: me->text_build = text_build;
58: me->text_addText = text_addText;
59: me->text_foundLink = text_foundLink;
60: me->text_beginElement = text_beginElement;
61: me->text_endElement = text_endElement;
62: me->text_unparsedBeginElement = text_unparsedBeginElement;
63: me->text_unparsedEndElement = text_unparsedEndElement;
64: me->text_unparsedEntity = text_unparsedEntity;
2.2 ! frystyk 65: if (me->text_new) me->app = (*me->text_new)(request, anchor, output_stream);
2.1 frystyk 66: return me;
67: }
68:
69: PUBLIC BOOL HTextImp_delete (HTextImp * me)
70: {
71: if (me) {
72: HText * app = me->app;
73: HT_FREE(me);
74: return (me->app && me->text_delete) ? (*me->text_delete)(app) : NO;
75: }
76: return NO;
77: }
78:
79: PUBLIC void HTextImp_build (HTextImp * me, HTextStatus status)
80: {
81: if (me && me->text_build)
82: (*me->text_build)(me->app, status);
83: }
84:
85: PUBLIC void HTextImp_addText (HTextImp * me,
86: const char * buffer,
87: int length)
88: {
89: if (me && me->text_addText)
90: (*me->text_addText)(me->app, buffer, length);
91: }
92:
93: PUBLIC void HTextImp_foundLink (HTextImp * me,
94: int element_number,
95: int attribute_number,
96: HTChildAnchor *anchor,
97: const BOOL * present,
98: const char ** value)
99: {
100: if (me && me->text_foundLink)
101: (*me->text_foundLink)(me->app, element_number, attribute_number,
102: anchor, present, value);
103: }
104:
105: PUBLIC void HTextImp_beginElement (HTextImp * me,
106: int element_number,
107: const BOOL * present,
108: const char **value)
109: {
110: if (me && me->text_beginElement)
111: (*me->text_beginElement)(me->app, element_number, present, value);
112: }
113:
114: PUBLIC void HTextImp_endElement (HTextImp * me,
115: int element_number)
116: {
117: if (me && me->text_endElement)
118: (*me->text_endElement)(me->app, element_number);
119: }
120:
121: PUBLIC void HTextImp_unparsedBeginElement (HTextImp * me,
122: const char * buffer,
123: int length)
124: {
125: if (me && me->text_unparsedBeginElement)
126: (*me->text_unparsedBeginElement)(me->app, buffer, length);
127: }
128:
129: PUBLIC void HTextImp_unparsedEndElement (HTextImp * me,
130: const char * buffer,
131: int length)
132: {
133: if (me && me->text_unparsedEndElement)
134: (*me->text_unparsedEndElement)(me->app, buffer, length);
135: }
136:
137: PUBLIC void HTextImp_unparsedEntity (HTextImp * me,
138: const char * buffer,
139: int length)
140: {
141: if (me && me->text_unparsedEntity)
142: (*me->text_unparsedEntity)(me->app, buffer, length);
143: }
144:
145: /* --------------------------------------------------------------------------- */
146:
147: PUBLIC BOOL HText_registerCDCallback (HText_new * ncb,
148: HText_delete * dcb)
149: {
150: if (ncb && dcb) {
151: text_new = ncb;
152: text_delete = dcb;
153: return YES;
154: }
155: return NO;
156: }
157:
158: PUBLIC BOOL HText_unregisterCDCallback (void)
159: {
160: text_new = NULL;
161: text_delete = NULL;
162: return YES;
163: }
164:
165: PUBLIC BOOL HText_registerTextCallback (HText_addText * tcb)
166: {
167: text_addText = tcb;
168: return YES;
169: }
170:
171: PUBLIC BOOL HText_unregisterTextCallback (void)
172: {
173: text_addText = NULL;
174: return YES;
175: }
176:
177: PUBLIC BOOL HText_registerLinkCallback (HText_foundLink * lcb)
178: {
179: text_foundLink = lcb;
180: return YES;
181: }
182:
183: PUBLIC BOOL HText_unregisterLinkCallback (void)
184: {
185: text_foundLink = NULL;
186: return YES;
187: }
188:
189: PUBLIC BOOL HText_registerElementCallback (HText_beginElement * bcb,
190: HText_endElement * ecb)
191: {
192: text_beginElement = bcb;
193: text_endElement = ecb;
194: return YES;
195: }
196:
197: PUBLIC BOOL HText_unregisterElementCallback (void)
198: {
199: text_beginElement = NULL;
200: return YES;
201: }
202:
203: PUBLIC BOOL HText_registerUnparsedElementCallback (HText_unparsedBeginElement * ubcb,
204: HText_unparsedBeginElement * uecb)
205: {
206: text_unparsedBeginElement = ubcb;
207: text_unparsedEndElement = uecb;
208: return YES;
209: }
210:
211: PUBLIC BOOL HText_unregisterUnparsedElementCallback (void)
212: {
213: text_unparsedBeginElement = NULL;
214: text_unparsedEndElement = NULL;
215: return YES;
216: }
217:
218: PUBLIC BOOL HText_registerUnparsedEntityCallback (HText_unparsedEntity * tcb)
219: {
220: text_unparsedEntity = tcb;
221: return YES;
222: }
223:
224: PUBLIC BOOL HText_unregisterUnparsedEntityCallback (void)
225: {
226: text_unparsedEntity = NULL;
227: return YES;
228: }
Webmaster