File:  [Public] / libwww / Library / src / HTPlain.c
Revision 2.26: download - view: text, annotated - select for diffs
Wed Jan 6 15:38:47 1999 UTC (25 years, 4 months ago) by frystyk
Branches: MAIN
CVS tags: Release-5-3-1, Release-5-2-8, Release-5-2-6, HEAD, Before-New-Trace-Messages, Amaya_2_4, Amaya-6-3, Amaya-6-1, Amaya-5-2, Amaya-4-3-2, Amaya-4-3-1, Amaya-4-3, Amaya-4-1-2, Amaya-4-1-0, Amaya-4-0-0, Amaya-3-2-1, Amaya-3-2
A completely rewritten HText interface that makes it a lot easier to use the libwww HTML parser and also doesn't throw away tags or entities that are not defined in the libwww HTML DTD. The new interface is based on registering callbacks so that the application doesn't have to provide the old HText functions that it didn't use. The HTML parser itself has also improved as it now knows about several HTML 4.0 tags. Finally, there are three new sample applications called showtags, showtext, and showlinks which illustrate how to use the new HText interface. Currently the line mode browser hasn't been updated so it doesn't compile for the moment.

/*								      HTPlain.c
**	PLAIN TEXT OBJECT
**
**	(c) COPYRIGHT MIT 1995.
**	Please first read the full copyright statement in the file COPYRIGH.
**	@(#) $Id: HTPlain.c,v 2.26 1999/01/06 15:38:47 frystyk Exp $
**
**	This version of the stream object just writes to a socket.
**	The socket is assumed open and left open.
**
*/

/* Library include files */
#include "wwwsys.h"
#include "HTUtils.h"
#include "HTStyle.h"
#include "HTPlain.h"
#include "HTextImp.h"

struct _HTStream {
    const HTStreamClass *	isa;
    HTextImp * 			text;
};

/* -------------------------------------------------------------------------- */

PRIVATE int HTPlain_put_character (HTStream * me, char c)
{
    HTextImp_addText(me->text, &c, 1);
    return HT_OK;
}

PRIVATE int HTPlain_put_string (HTStream * me, const char * s)
{
    HTextImp_addText(me->text, s, strlen(s));
    return HT_OK;
}

PRIVATE int HTPlain_write (HTStream * me, const char* b, int l)
{
    HTextImp_addText(me->text, b, l);
    return HT_OK;
}

PRIVATE int HTPlain_flush (HTStream * me)
{
    return HT_OK;
}

PRIVATE int HTPlain_free (HTStream * me)
{
    if (me) {
	HTextImp_build(me->text, HTEXT_END);
	HT_FREE(me);
    }
    return HT_OK;
}

PRIVATE int HTPlain_abort (HTStream * me, HTList * e)
{
    if (me) {
	HTextImp_build(me->text, HTEXT_ABORT);
	HT_FREE(me);
    }
    return HT_ERROR;
}

PRIVATE const HTStreamClass HTPlain =
{
    "PlainText",
    HTPlain_flush,
    HTPlain_free,
    HTPlain_abort,
    HTPlain_put_character,
    HTPlain_put_string,
    HTPlain_write,
}; 

PUBLIC HTStream* HTPlainPresent (HTRequest *	request,
				 void *		param,
				 HTFormat	input_format,
				 HTFormat	output_format,
				 HTStream *	output_stream)
{
    HTStream * me;
    if ((me = (HTStream *) HT_CALLOC(1, sizeof(HTStream))) == NULL)
        HT_OUTOFMEM("HTPlain_new");
    me->isa = &HTPlain;       
    me->text = HTextImp_new(request, HTRequest_anchor(request), output_stream);
    HTextImp_build(me->text, HTEXT_BEGIN);
    return me;
}



Webmaster