Annotation of libwww/Library/src/HTPlain.c, revision 2.10.2.1

2.10      frystyk     1: /*                                                                   HTWrite.c
                      2: **     PLAIN TEXT OBJECT
                      3: **
                      4: **     (c) COPYRIGHT CERN 1994.
                      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: */
                     13: 
2.10.2.1! frystyk    14: /* Library include files */
        !            15: #include "tcp.h"
2.1       timbl      16: #include "HTUtils.h"
                     17: #include "HText.h"
                     18: #include "HTStyle.h"
2.10.2.1! frystyk    19: #include "HTPlain.h"
        !            20: 
        !            21: #define BUFFER_SIZE 4096;      /* Tradeoff */
2.1       timbl      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.2       timbl      51: PRIVATE void HTPlain_put_character ARGS2(HTStream *, me, char, c)
2.1       timbl      52: {
2.2       timbl      53:     HText_appendCharacter(me->text, c);
2.1       timbl      54: }
                     55: 
                     56: 
                     57: 
                     58: /*     String handling
                     59: **     ---------------
                     60: **
                     61: */
2.2       timbl      62: PRIVATE void HTPlain_put_string ARGS2(HTStream *, me, CONST char*, s)
2.1       timbl      63: {
2.2       timbl      64:     HText_appendText(me->text, s);
2.1       timbl      65: }
                     66: 
                     67: 
2.2       timbl      68: PRIVATE void HTPlain_write ARGS3(HTStream *, me, CONST char*, s, int, l)
2.1       timbl      69: {
                     70:     CONST char* p;
                     71:     CONST char* e = s+l;
2.4       timbl      72:     for (p=s; p<e; p++) HText_appendCharacter(me->text, *p);
2.1       timbl      73: }
                     74: 
                     75: 
                     76: 
                     77: /*     Free an HTML object
                     78: **     -------------------
                     79: **
                     80: **     Note that the SGML parsing context is freed, but the created object is not,
                     81: **     as it takes on an existence of its own unless explicitly freed.
                     82: */
2.9       frystyk    83: PRIVATE int HTPlain_free ARGS1(HTStream *, me)
2.1       timbl      84: {
2.2       timbl      85:     free(me);
2.9       frystyk    86:     return 0;
2.1       timbl      87: }
                     88: 
                     89: /*     End writing
                     90: */
                     91: 
2.9       frystyk    92: PRIVATE int HTPlain_abort ARGS2(HTStream *, me, HTError, e)
2.1       timbl      93: {
2.5       timbl      94:     HTPlain_free(me);
2.9       frystyk    95:     return EOF;
2.1       timbl      96: }
                     97: 
                     98: 
                     99: 
                    100: /*             Structured Object Class
                    101: **             -----------------------
                    102: */
                    103: PUBLIC CONST HTStreamClass HTPlain =
                    104: {              
2.7       luotonen  105:        "PlainText",
2.1       timbl     106:        HTPlain_free,
2.5       timbl     107:        HTPlain_abort,
2.1       timbl     108:        HTPlain_put_character,  HTPlain_put_string, HTPlain_write,
                    109: }; 
                    110: 
                    111: 
                    112: /*             New object
                    113: **             ----------
                    114: */
2.6       timbl     115: PUBLIC HTStream* HTPlainPresent ARGS5(
                    116:        HTRequest *,            request,
                    117:        void *,                 param,
                    118:        HTFormat,               input_format,
                    119:        HTFormat,               output_format,
                    120:        HTStream *,             output_stream)
2.1       timbl     121: {
                    122: 
2.3       timbl     123:     HTStream* me = (HTStream*)malloc(sizeof(*me));
2.2       timbl     124:     if (me == NULL) outofmem(__FILE__, "HTPlain_new");
                    125:     me->isa = &HTPlain;       
                    126: 
2.7       luotonen  127:     me->text = HText_new2(request->anchor, output_stream);
2.8       timbl     128:     HText_beginAppend(me->text);
2.2       timbl     129:     HText_setStyle(me->text, HTStyleNamed(styleSheet, "Example"));
2.1       timbl     130: 
2.2       timbl     131:     return (HTStream*) me;
2.1       timbl     132: }
                    133: 
                    134: 

Webmaster