home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / www / library / implemen / htplain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  2.3 KB  |  129 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"capalloc.h"
  11. #include "HTPlain.h"
  12. #include"capstdio.h"
  13.  
  14. #define BUFFER_SIZE 4096;    /* Tradeoff */
  15.  
  16. #include "HTUtils.h"
  17. #include "HText.h"
  18. #include "HTStyle.h"
  19.  
  20. extern HTStyleSheet * styleSheet;
  21.  
  22.  
  23.  
  24. /*        HTML Object
  25. **        -----------
  26. */
  27.  
  28. struct _HTStream {
  29.     CONST HTStreamClass *    isa;
  30.  
  31.     HText *         text;
  32. };
  33.  
  34. /*    Write the buffer out to the socket
  35. **    ----------------------------------
  36. */
  37.  
  38.  
  39. /*_________________________________________________________________________
  40. **
  41. **            A C T I O N     R O U T I N E S
  42. */
  43.  
  44. /*    Character handling
  45. **    ------------------
  46. */
  47.  
  48. PRIVATE void HTPlain_put_character ARGS2(HTStream *, me, char, c)
  49. {
  50.     HText_appendCharacter(me->text, c);
  51. }
  52.  
  53.  
  54.  
  55. /*    String handling
  56. **    ---------------
  57. **
  58. */
  59. PRIVATE void HTPlain_put_string ARGS2(HTStream *, me, CONST char*, s)
  60. {
  61.     HText_appendText(me->text, s);
  62. }
  63.  
  64.  
  65. PRIVATE void HTPlain_write ARGS3(HTStream *, me, CONST char*, s, int, l)
  66. {
  67.     CONST char* p;
  68.     CONST char* e = s+l;
  69.     for (p=s; p<e; p++) HText_appendCharacter(me->text, *p);
  70. }
  71.  
  72.  
  73.  
  74. /*    Free an HTML object
  75. **    -------------------
  76. **
  77. **    Note that the SGML parsing context is freed, but the created object is not,
  78. **    as it takes on an existence of its own unless explicitly freed.
  79. */
  80. PRIVATE void HTPlain_free ARGS1(HTStream *, me)
  81. {
  82.     free(me);
  83. }
  84.  
  85. /*    End writing
  86. */
  87.  
  88. PRIVATE void HTPlain_abort ARGS2(HTStream *, me, HTError, e)
  89. {
  90.     HTPlain_free(me);
  91. }
  92.  
  93.  
  94.  
  95. /*        Structured Object Class
  96. **        -----------------------
  97. */
  98. PUBLIC CONST HTStreamClass HTPlain =
  99. {        
  100.     "SocketWriter",
  101.     HTPlain_free,
  102.     HTPlain_abort,
  103.     HTPlain_put_character,     HTPlain_put_string, HTPlain_write,
  104. }; 
  105.  
  106.  
  107. /*        New object
  108. **        ----------
  109. */
  110. PUBLIC HTStream* HTPlainPresent ARGS3(
  111.     HTPresentation *,    pres,
  112.     HTParentAnchor *,    anchor,    
  113.     HTStream *,        sink)
  114. {
  115.  
  116.     HTStream* me = (HTStream*)malloc(sizeof(*me));
  117.  
  118.     if (me == NULL) outofmem(__FILE__, "HTPlain_new");
  119.     me->isa = &HTPlain;
  120.  
  121.     me->text = HText_new(anchor);
  122.     HText_setStyle(me->text, HTStyleNamed(styleSheet, "Example"));
  123.     HText_beginAppend(me->text);
  124.  
  125.     return (HTStream*) me;
  126. }
  127.  
  128.  
  129.