home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / HTPlain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  2.3 KB  |  134 lines

  1. /*        Plain text object        HTWrite.c
  2. **        =================
  3. **
  4. **    This version of the stream object just writes to a socket.
  5. **    The socket is assumed open and left open.
  6. **
  7. **    Bugs:
  8. **        strings written must be less than buffer size.
  9. */
  10. #include "HTUtils.h"
  11.  
  12. #include "HTPlain.h"
  13.  
  14. #define BUFFER_SIZE 4096;    /* Tradeoff */
  15.  
  16. #include "HText.h"
  17. #include "HTStyle.h"
  18.  
  19. #include "LYLeaks.h"
  20.  
  21. extern HTStyleSheet * styleSheet;
  22.  
  23.  
  24.  
  25. /*        HTML Object
  26. **        -----------
  27. */
  28.  
  29. struct _HTStream {
  30.     CONST HTStreamClass *    isa;
  31.  
  32.     HText *         text;
  33. };
  34.  
  35. /*    Write the buffer out to the socket
  36. **    ----------------------------------
  37. */
  38.  
  39.  
  40. /*_________________________________________________________________________
  41. **
  42. **            A C T I O N     R O U T I N E S
  43. */
  44.  
  45. /*    Character handling
  46. **    ------------------
  47. */
  48.  
  49. PRIVATE void HTPlain_put_character ARGS2(HTStream *, me, char, c)
  50. {
  51.     /* throw away \r's */
  52.     if(c != '\r')
  53.        HText_appendCharacter(me->text, c);
  54. }
  55.  
  56.  
  57.  
  58. /*    String handling
  59. **    ---------------
  60. **
  61. */
  62. PRIVATE void HTPlain_put_string ARGS2(HTStream *, me, CONST char*, s)
  63. {
  64.     HText_appendText(me->text, s);
  65. }
  66.  
  67.  
  68. PRIVATE void HTPlain_write ARGS3(HTStream *, me, CONST char*, s, int, l)
  69. {
  70.     CONST char* p;
  71.     CONST char* e = s+l;
  72.     /* append the whole string, but remove any \r's */
  73.     for (p=s; p<e; p++) 
  74.        if(*p != '\r')
  75.         HText_appendCharacter(me->text, *p);
  76. }
  77.  
  78.  
  79.  
  80. /*    Free an HTML object
  81. **    -------------------
  82. **
  83. **    Note that the SGML parsing context is freed, but the created object is not,
  84. **    as it takes on an existence of its own unless explicitly freed.
  85. */
  86. PRIVATE void HTPlain_free ARGS1(HTStream *, me)
  87. {
  88.     free(me);
  89. }
  90.  
  91. /*    End writing
  92. */
  93.  
  94. PRIVATE void HTPlain_abort ARGS2(HTStream *, me, HTError, e)
  95. {
  96.     HTPlain_free(me);
  97. }
  98.  
  99.  
  100.  
  101. /*        Structured Object Class
  102. **        -----------------------
  103. */
  104. PUBLIC CONST HTStreamClass HTPlain =
  105. {        
  106.     "SocketWriter",
  107.     HTPlain_free,
  108.     HTPlain_abort,
  109.     HTPlain_put_character,     HTPlain_put_string, HTPlain_write,
  110. }; 
  111.  
  112.  
  113. /*        New object
  114. **        ----------
  115. */
  116. PUBLIC HTStream* HTPlainPresent ARGS3(
  117.     HTPresentation *,    pres,
  118.     HTParentAnchor *,    anchor,    
  119.     HTStream *,        sink)
  120. {
  121.  
  122.     HTStream* me = (HTStream*)malloc(sizeof(*me));
  123.     if (me == NULL) outofmem(__FILE__, "HTPlain_new");
  124.     me->isa = &HTPlain;       
  125.  
  126.     me->text = HText_new(anchor);
  127.     HText_setStyle(me->text, HTStyleNamed(styleSheet, "Example"));
  128.     HText_beginAppend(me->text);
  129.  
  130.     return (HTStream*) me;
  131. }
  132.  
  133.  
  134.