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

2.15      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.18      frystyk    51: PRIVATE int HTPlain_put_character (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.18      frystyk    62: PRIVATE int HTPlain_put_string (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.18      frystyk    69: PRIVATE int HTPlain_write (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: */
2.18      frystyk    81: PRIVATE int HTPlain_flush (HTStream * me)
2.13      frystyk    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.18      frystyk    92: PRIVATE int HTPlain_free (HTStream * me)
2.1       timbl      93: {
2.21      frystyk    94:     if (me) {
                     95:        HText_endAppend(me->text);
2.22    ! frystyk    96:        HT_FREE(me);
2.21      frystyk    97:     }
2.13      frystyk    98:     return HT_OK;
2.1       timbl      99: }
                    100: 
                    101: /*     End writing
                    102: */
                    103: 
2.18      frystyk   104: PRIVATE int HTPlain_abort (HTStream * me, HTList * e)
2.1       timbl     105: {
2.5       timbl     106:     HTPlain_free(me);
2.13      frystyk   107:     return HT_ERROR;
2.1       timbl     108: }
                    109: 
                    110: 
                    111: 
                    112: /*             Structured Object Class
                    113: **             -----------------------
                    114: */
2.19      frystyk   115: PRIVATE CONST HTStreamClass HTPlain =
                    116: {
                    117:     "PlainText",
                    118:     HTPlain_flush,
                    119:     HTPlain_free,
                    120:     HTPlain_abort,
                    121:     HTPlain_put_character,
                    122:     HTPlain_put_string,
                    123:     HTPlain_write,
2.1       timbl     124: }; 
                    125: 
                    126: 
                    127: /*             New object
                    128: **             ----------
                    129: */
2.18      frystyk   130: PUBLIC HTStream* HTPlainPresent (HTRequest *   request,
                    131:                                 void *         param,
                    132:                                 HTFormat       input_format,
                    133:                                 HTFormat       output_format,
                    134:                                 HTStream *     output_stream)
2.1       timbl     135: {
2.22    ! frystyk   136:     HTStream* me;
        !           137:     if ((me = (HTStream *) HT_MALLOC(sizeof(HTStream))) == NULL)
        !           138:         HT_OUTOFMEM("HTPlain_new");
2.2       timbl     139:     me->isa = &HTPlain;       
2.20      frystyk   140:     me->text = HText_new2(request, HTRequest_anchor(request), output_stream);
2.8       timbl     141:     HText_beginAppend(me->text);
2.2       timbl     142:     HText_setStyle(me->text, HTStyleNamed(styleSheet, "Example"));
2.18      frystyk   143:     return me;
2.1       timbl     144: }
                    145: 
                    146: 

Webmaster