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

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.2       timbl      94:     free(me);
2.13      frystyk    95:     return HT_OK;
2.1       timbl      96: }
                     97: 
                     98: /*     End writing
                     99: */
                    100: 
2.18      frystyk   101: PRIVATE int HTPlain_abort (HTStream * me, HTList * 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: */
2.19    ! frystyk   112: PRIVATE CONST HTStreamClass HTPlain =
        !           113: {
        !           114:     "PlainText",
        !           115:     HTPlain_flush,
        !           116:     HTPlain_free,
        !           117:     HTPlain_abort,
        !           118:     HTPlain_put_character,
        !           119:     HTPlain_put_string,
        !           120:     HTPlain_write,
2.1       timbl     121: }; 
                    122: 
                    123: 
                    124: /*             New object
                    125: **             ----------
                    126: */
2.18      frystyk   127: PUBLIC HTStream* HTPlainPresent (HTRequest *   request,
                    128:                                 void *         param,
                    129:                                 HTFormat       input_format,
                    130:                                 HTFormat       output_format,
                    131:                                 HTStream *     output_stream)
2.1       timbl     132: {
2.18      frystyk   133:     HTStream* me = (HTStream*)malloc(sizeof(HTStream));
2.2       timbl     134:     if (me == NULL) outofmem(__FILE__, "HTPlain_new");
                    135:     me->isa = &HTPlain;       
2.16      frystyk   136:     me->text = HText_new2(HTRequest_anchor(request), output_stream);
2.8       timbl     137:     HText_beginAppend(me->text);
2.2       timbl     138:     HText_setStyle(me->text, HTStyleNamed(styleSheet, "Example"));
2.18      frystyk   139:     return me;
2.1       timbl     140: }
                    141: 
                    142: 

Webmaster