Annotation of libwww/Library/src/HTPlain.c, revision 2.14.6.1
2.14.6.1! frystyk 1: /* HTPlain.c
2.10 frystyk 2: ** PLAIN TEXT OBJECT
3: **
2.14 frystyk 4: ** (c) COPYRIGHT MIT 1995.
2.10 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
2.1 timbl 6: **
7: ** This version of the stream object just writes to a socket.
8: ** The socket is assumed open and left open.
9: **
10: ** Bugs:
11: ** strings written must be less than buffer size.
12: */
2.11 roeber 13:
2.12 frystyk 14: /* Library include files */
15: #include "tcp.h"
16: #include "HTUtils.h"
17: #include "HText.h"
18: #include "HTStyle.h"
2.1 timbl 19: #include "HTPlain.h"
20:
21: #define BUFFER_SIZE 4096; /* Tradeoff */
22:
23: extern HTStyleSheet * styleSheet;
24:
25:
26:
27: /* HTML Object
28: ** -----------
29: */
30:
31: struct _HTStream {
32: CONST HTStreamClass * isa;
33:
34: HText * text;
35: };
36:
37: /* Write the buffer out to the socket
38: ** ----------------------------------
39: */
40:
41:
42: /*_________________________________________________________________________
43: **
44: ** A C T I O N R O U T I N E S
45: */
46:
47: /* Character handling
48: ** ------------------
49: */
50:
2.13 frystyk 51: PRIVATE int HTPlain_put_character ARGS2(HTStream *, me, char, c)
2.1 timbl 52: {
2.2 timbl 53: HText_appendCharacter(me->text, c);
2.13 frystyk 54: return HT_OK;
2.1 timbl 55: }
56:
57:
58: /* String handling
59: ** ---------------
60: **
61: */
2.13 frystyk 62: PRIVATE int HTPlain_put_string ARGS2(HTStream *, me, CONST char*, s)
2.1 timbl 63: {
2.2 timbl 64: HText_appendText(me->text, s);
2.13 frystyk 65: return HT_OK;
2.1 timbl 66: }
67:
68:
2.13 frystyk 69: PRIVATE int HTPlain_write ARGS3(HTStream *, me, CONST char*, b, int, l)
2.1 timbl 70: {
2.13 frystyk 71: while (l-- > 0)
72: HText_appendCharacter(me->text, *b++);
73: return HT_OK;
2.1 timbl 74: }
75:
76:
77:
2.13 frystyk 78: /* Flush an Plain object
79: ** --------------------
80: */
81: PRIVATE int HTPlain_flush ARGS1(HTStream *, me)
82: {
83: return HT_OK;
84: }
85:
2.1 timbl 86: /* Free an HTML object
87: ** -------------------
88: **
89: ** Note that the SGML parsing context is freed, but the created object is not,
90: ** as it takes on an existence of its own unless explicitly freed.
91: */
2.9 frystyk 92: PRIVATE int HTPlain_free ARGS1(HTStream *, me)
2.1 timbl 93: {
2.2 timbl 94: free(me);
2.13 frystyk 95: return HT_OK;
2.1 timbl 96: }
97:
98: /* End writing
99: */
100:
2.9 frystyk 101: PRIVATE int HTPlain_abort ARGS2(HTStream *, me, HTError, e)
2.1 timbl 102: {
2.5 timbl 103: HTPlain_free(me);
2.13 frystyk 104: return HT_ERROR;
2.1 timbl 105: }
106:
107:
108:
109: /* Structured Object Class
110: ** -----------------------
111: */
112: PUBLIC CONST HTStreamClass HTPlain =
113: {
2.7 luotonen 114: "PlainText",
2.13 frystyk 115: HTPlain_flush,
2.1 timbl 116: HTPlain_free,
2.5 timbl 117: HTPlain_abort,
2.1 timbl 118: HTPlain_put_character, HTPlain_put_string, HTPlain_write,
119: };
120:
121:
122: /* New object
123: ** ----------
124: */
2.6 timbl 125: PUBLIC HTStream* HTPlainPresent ARGS5(
126: HTRequest *, request,
127: void *, param,
128: HTFormat, input_format,
129: HTFormat, output_format,
130: HTStream *, output_stream)
2.1 timbl 131: {
132:
2.3 timbl 133: HTStream* me = (HTStream*)malloc(sizeof(*me));
2.2 timbl 134: if (me == NULL) outofmem(__FILE__, "HTPlain_new");
135: me->isa = &HTPlain;
136:
2.7 luotonen 137: me->text = HText_new2(request->anchor, output_stream);
2.8 timbl 138: HText_beginAppend(me->text);
2.2 timbl 139: HText_setStyle(me->text, HTStyleNamed(styleSheet, "Example"));
2.1 timbl 140:
2.2 timbl 141: return (HTStream*) me;
2.1 timbl 142: }
143:
144:
Webmaster