HTPlain.c
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:3k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*       HTPlain.c
  2. ** PLAIN TEXT OBJECT
  3. **
  4. ** (c) COPYRIGHT MIT 1995.
  5. ** Please first read the full copyright statement in the file COPYRIGH.
  6. **
  7. ** This version of the stream object just writes to a socket.
  8. ** The socket is assumed open and left open.
  9. **
  10. ** Bugs:
  11. ** strings written must be less than buffer size.
  12. */
  13. /* Library include files */
  14. #include "tcp.h"
  15. #include "HTUtils.h"
  16. #include "HText.h"
  17. #include "HTStyle.h"
  18. #include "HTPlain.h"
  19. #define BUFFER_SIZE 4096; /* Tradeoff */
  20. extern HTStyleSheet * styleSheet;
  21. /* HTML Object
  22. ** -----------
  23. */
  24. struct _HTStream {
  25. CONST HTStreamClass * isa;
  26. HText *  text;
  27. };
  28. /* Write the buffer out to the socket
  29. ** ----------------------------------
  30. */
  31. /*_________________________________________________________________________
  32. **
  33. ** A C T I O N  R O U T I N E S
  34. */
  35. /* Character handling
  36. ** ------------------
  37. */
  38. PRIVATE int HTPlain_put_character (HTStream * me, char c)
  39. {
  40.     HText_appendCharacter(me->text, c);
  41.     return HT_OK;
  42. }
  43. /* String handling
  44. ** ---------------
  45. **
  46. */
  47. PRIVATE int HTPlain_put_string (HTStream * me, CONST char * s)
  48. {
  49.     HText_appendText(me->text, s);
  50.     return HT_OK;
  51. }
  52. PRIVATE int HTPlain_write (HTStream * me, CONST char* b, int l)
  53. {
  54.     while (l-- > 0)
  55. HText_appendCharacter(me->text, *b++);
  56.     return HT_OK;
  57. }
  58. /* Flush an Plain object
  59. ** --------------------
  60. */
  61. PRIVATE int HTPlain_flush (HTStream * me)
  62. {
  63.     return HT_OK;
  64. }
  65. /* Free an HTML object
  66. ** -------------------
  67. **
  68. ** Note that the SGML parsing context is freed, but the created object is not,
  69. ** as it takes on an existence of its own unless explicitly freed.
  70. */
  71. PRIVATE int HTPlain_free (HTStream * me)
  72. {
  73.     if (me) {
  74. HText_endAppend(me->text);
  75. HT_FREE(me);
  76.     }
  77.     return HT_OK;
  78. }
  79. /* End writing
  80. */
  81. PRIVATE int HTPlain_abort (HTStream * me, HTList * e)
  82. {
  83.     HTPlain_free(me);
  84.     return HT_ERROR;
  85. }
  86. /* Structured Object Class
  87. ** -----------------------
  88. */
  89. PRIVATE CONST HTStreamClass HTPlain =
  90. {
  91.     "PlainText",
  92.     HTPlain_flush,
  93.     HTPlain_free,
  94.     HTPlain_abort,
  95.     HTPlain_put_character,
  96.     HTPlain_put_string,
  97.     HTPlain_write,
  98. }; 
  99. /* New object
  100. ** ----------
  101. */
  102. PUBLIC HTStream* HTPlainPresent (HTRequest * request,
  103.  void * param,
  104.  HTFormat input_format,
  105.  HTFormat output_format,
  106.  HTStream * output_stream)
  107. {
  108.     HTStream* me;
  109.     if ((me = (HTStream *) HT_MALLOC(sizeof(HTStream))) == NULL)
  110.         HT_OUTOFMEM("HTPlain_new");
  111.     me->isa = &HTPlain;       
  112.     me->text = HText_new2(request, HTRequest_anchor(request), output_stream);
  113.     HText_beginAppend(me->text);
  114.     HText_setStyle(me->text, HTStyleNamed(styleSheet, "Example"));
  115.     return me;
  116. }