Annotation of libwww/Library/src/HTTee.c, revision 2.5

2.5     ! frystyk     1: /*                                                                      HTee.c
        !             2: **     TEE CLASS STREAM DEFINITION
        !             3: **
        !             4: **     (c) COPYRIGHT CERN 1994.
        !             5: **     Please first read the full copyright statement in the file COPYRIGH.
2.1       timbl       6: **
                      7: **     The Tee class just writes to two streams.  Easy.
                      8: **     See also the Black Hole stream which is even easier.
2.3       duns        9: **
                     10: ** HISTORY:
                     11: **      8 Jul 94  FM   Insulate free() from _free structure element.
                     12: **
2.1       timbl      13: */
                     14: 
                     15: 
                     16: #include "HTTee.h"
                     17: 
                     18: 
                     19: /*             Stream Object
                     20: **             ------------
                     21: */
                     22: 
                     23: struct _HTStream {
                     24:        CONST HTStreamClass *   isa;
                     25:        
                     26:        HTStream *              s1;
                     27:        HTStream *              s2;
                     28: };
                     29: 
                     30: 
                     31: PRIVATE void HTTee_put_character ARGS2(HTStream *, me, char, c)
                     32: {
                     33:     (*me->s1->isa->put_character)(me->s1, c);
                     34:     (*me->s2->isa->put_character)(me->s2, c);
                     35: }
                     36: PRIVATE void HTTee_put_string ARGS2(HTStream *, me, CONST char*, s)
                     37: {
                     38:     (*me->s1->isa->put_string)(me->s1, s);
                     39:     (*me->s2->isa->put_string)(me->s2, s);
                     40: }
                     41: PRIVATE void HTTee_write ARGS3(HTStream *, me, CONST char*, s, int, l)
                     42: {
                     43:     (*me->s1->isa->put_block)(me->s1, s, l);
                     44:     (*me->s2->isa->put_block)(me->s2, s, l);
                     45: }
2.4       frystyk    46: PRIVATE int HTTee_free ARGS1(HTStream *, me)
2.1       timbl      47: {
2.3       duns       48:     (*me->s1->isa->_free)(me->s1);
                     49:     (*me->s2->isa->_free)(me->s2);
2.2       luotonen   50:     free(me);
2.4       frystyk    51:     return 0;
2.1       timbl      52: }
2.4       frystyk    53: PRIVATE int HTTee_abort ARGS2(HTStream *, me, HTError, e)
2.1       timbl      54: {
                     55:     (*me->s1->isa->abort)(me->s1, e);
                     56:     (*me->s2->isa->abort)(me->s2, e);
2.2       luotonen   57:     free(me);
2.4       frystyk    58:     return EOF;
2.1       timbl      59: }
                     60: 
                     61: 
                     62: /*     Tee stream
                     63: **     ----------
                     64: */
                     65: PRIVATE CONST HTStreamClass HTTeeClass =
                     66: {              
                     67:        "Tee",
                     68:        HTTee_free,
                     69:        HTTee_abort,
                     70:        HTTee_put_character,    HTTee_put_string,
                     71:        HTTee_write
                     72: }; 
                     73: 
                     74: 
                     75: /*     Tee creation
                     76: */
                     77: PUBLIC HTStream * HTTee ARGS2(HTStream *, s1,HTStream *, s2)
                     78: {
                     79:     HTStream * me = (HTStream*)malloc(sizeof(*me));
                     80:     if (!me) outofmem(__FILE__, "HTTee");
                     81:     me->isa = &HTTeeClass;
                     82:     me->s1 = s1;
                     83:     me->s2 = s2;
                     84:     return me;
                     85: }
                     86: 
                     87: 

Webmaster