Annotation of libwww/Library/src/HTMerge.c, revision 2.1

2.1     ! frystyk     1: /*
        !             2: **     MERGE CLASS STREAM DEFINITION
        !             3: **
        !             4: **     (c) COPYRIGHT MIT 1995.
        !             5: **     Please first read the full copyright statement in the file COPYRIGH.
        !             6: **     @(#) $Id: HTTee.c,v 2.17 1996/06/01 17:46:54 frystyk Exp $
        !             7: **
        !             8: **     The Merge class just is a n entry stream. Easy. The reason for having
        !             9: **     this stream is that we must be able to handle free and abort in an
        !            10: **     organized manner.
        !            11: **     You can also check out the. Tee stream and the Black hole stream.
        !            12: **
        !            13: ** HISTORY:
        !            14: **     25 Sep 96  HFN  Written
        !            15: */
        !            16: 
        !            17: /* Library include files */
        !            18: #include "sysdep.h"
        !            19: #include "WWWUtil.h"
        !            20: #include "HTMerge.h"
        !            21: 
        !            22: struct _HTStream {
        !            23:     const HTStreamClass *      isa;
        !            24:     HTStream *                 target;
        !            25:     int                                feeds;                    /* Number of feeds */
        !            26: };
        !            27: 
        !            28: PRIVATE int HTMerge_putCharacter (HTStream * me, char c)
        !            29: {
        !            30:     return (me->feeds > 0) ?
        !            31:        (*me->target->isa->put_character)(me->target, c) : HT_OK;
        !            32: }
        !            33: 
        !            34: PRIVATE int HTMerge_putString (HTStream * me, const char * s)
        !            35: {
        !            36:     return (me->feeds > 0) ?
        !            37:        (*me->target->isa->put_string)(me->target, s) : HT_OK;
        !            38: }
        !            39: 
        !            40: PRIVATE int HTMerge_putBlock (HTStream * me, const char * s, int l)
        !            41: {
        !            42:     return (me->feeds > 0) ?
        !            43:        (*me->target->isa->put_block)(me->target, s, l) : HT_OK;
        !            44: }
        !            45: 
        !            46: PRIVATE int HTMerge_flush (HTStream * me)
        !            47: {
        !            48:     return (me->feeds > 0) ?
        !            49:        (*me->target->isa->flush)(me->target) : HT_OK;
        !            50: }
        !            51: 
        !            52: /*
        !            53: **  We expect n number of calls to this method but as long as our number
        !            54: **  of feeds is not down to 1, we just ignore it. Abort works the same way
        !            55: */
        !            56: PRIVATE int HTMerge_free (HTStream * me)
        !            57: {
        !            58:     if (me) {
        !            59:        if (STREAM_TRACE)
        !            60:            HTTrace("Merge Free.. Called with %d feeds\n", me->feeds);
        !            61:        if (--me->feeds <= 0) {
        !            62:            (*me->target->isa->_free)(me->target);
        !            63:            HT_FREE(me);
        !            64:        }
        !            65:        return HT_OK;
        !            66:     }
        !            67:     return HT_ERROR;
        !            68: }
        !            69: 
        !            70: PRIVATE int HTMerge_abort (HTStream * me, HTList * e)
        !            71: {
        !            72:     if (me) {
        !            73:        if (STREAM_TRACE)
        !            74:            HTTrace("Merge Abort. Called with %d feeds\n", me->feeds);
        !            75:        if (--me->feeds <= 0) {
        !            76:            (*me->target->isa->abort)(me->target, e);
        !            77:            HT_FREE(me);
        !            78:        }
        !            79:     }
        !            80:     return HT_ERROR;
        !            81: }
        !            82: 
        !            83: PRIVATE const HTStreamClass HTMergeClass =
        !            84: {              
        !            85:     "MergeStream",
        !            86:     HTMerge_flush,
        !            87:     HTMerge_free,
        !            88:     HTMerge_abort,
        !            89:     HTMerge_putCharacter,
        !            90:     HTMerge_putString,
        !            91:     HTMerge_putBlock
        !            92: }; 
        !            93: 
        !            94: PUBLIC HTStream * HTMerge (HTStream * target, int feeds)
        !            95: {
        !            96:     HTStream * me;
        !            97:     if ((me = (HTStream  *) HT_CALLOC(1, sizeof(*me))) == NULL)
        !            98:         HT_OUTOFMEM("HTMerge");
        !            99:     me->isa = &HTMergeClass;
        !           100:     me->target = target ? target : HTBlackHole();
        !           101:     me->feeds = feeds >= 1 ? feeds : 1;                               /* Min 1 feed */
        !           102:     if (STREAM_TRACE) HTTrace("Merge....... Created stream %p\n", me);
        !           103:     return me;
        !           104: }

Webmaster