home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gwm18a.zip / contrib / gwmsh / PATCH-GWM < prev    next >
Text File  |  1995-07-03  |  3KB  |  107 lines

  1. This will give you with-output-to-string function
  2. gwmsh uses to get back results from gwm.
  3.  
  4. (with-output-to-string
  5.   <form1>
  6.   ...
  7.   <formN>)
  8.  
  9. Forms are evaluated as in prog, but all output from calls to print
  10. is directed to string returned as with-output-to-string value.
  11.  
  12. diff -c gwm-1.7o-dist/wool.c gwm-1.7o/wool.c
  13. *** gwm-1.7o-dist/wool.c    Fri Sep 30 21:06:51 1994
  14. --- gwm-1.7o/wool.c    Fri Sep 30 21:07:17 1994
  15. ***************
  16. *** 1145,1150 ****
  17. --- 1145,1186 ----
  18.       return result;
  19.   }
  20.   
  21. + /*XXX-UWE-XXX*/
  22. + static int expand_string_stream ();
  23. + WOOL_OBJECT
  24. + wool_with_output_to_string (argc, argv)
  25. +   int argc;
  26. +   WOOL_OBJECT *argv;
  27. + {
  28. +     WOOL_STRING_STREAM str, WOOL_STRING_STREAM_make (); 
  29. +     int old_type;
  30. +     char *old_stream;
  31. +     WOOL_OBJECT result;
  32. +     str = WOOL_STRING_STREAM_make (256, expand_string_stream);
  33. +     old_type = wool_output_redirect (1, str, &old_stream);
  34. +     progn (argc, argv);
  35. +     wool_output_redirect (old_type, old_stream, NULL);
  36. +     result = (WOOL_OBJECT) WLString_make (str->buffer);
  37. +     WOOL_STRING_STREAM_free (str);
  38. +     return result;
  39. + }
  40. + static int
  41. + expand_string_stream (str)
  42. +   WOOL_STRING_STREAM str;
  43. + {
  44. +     char *new_buf;
  45. +     int nbytes = str->last - str->buffer + 1;
  46. +     int ptr_pos = str->ptr - str->buffer;
  47. +     str->buffer = Realloc (str->buffer, 2*nbytes);        
  48. +     str->last = str->buffer + nbytes - 1;
  49. +     str->ptr = str->buffer + ptr_pos;
  50. + }
  51. + /*XXX-UWE-XXX*/
  52.   /*
  53.    * (progn inst1 ... instn)
  54.    * evals the n instructions then return the last one's result
  55. ***************
  56. *** 1987,1992 ****
  57. --- 2023,2032 ----
  58.       wool_subr_make(WLSubr, shell, "!", NARY);
  59.       increase_reference(wool_atom("print") -> c_val =
  60.                  wool_subr_make(WLSubr, wool_print_nary, "?", NARY));
  61. + /*XXX-UWE-XXX*/
  62. +     wool_subr_make(WLFSubr, wool_with_output_to_string,
  63. +                    "with-output-to-string", NARY);
  64. + /*XXX-UWE-XXX*/
  65.       wool_subr_make(WLSubr, not, "not", 1);
  66.       wool_subr_make(WLFSubr, and, "and", NARY);
  67.       wool_subr_make(WLFSubr, or, "or", NARY);
  68. diff -c gwm-1.7o-dist/wool.flex gwm-1.7o/wool.flex
  69. *** gwm-1.7o-dist/wool.flex    Fri Sep 30 21:06:51 1994
  70. --- gwm-1.7o/wool.flex    Fri Sep 30 21:07:17 1994
  71. ***************
  72. *** 135,142 ****
  73.   yyoutflush(){
  74.       if(yyout_is_string){
  75.           ASSERT(yystrout->overflow_handler);
  76. !     (*(yystrout->overflow_handler))(yystrout->buffer);
  77. !     yystrout->ptr = yystrout-> buffer;
  78.       }else{
  79.       fflush(yyout);
  80.       }
  81. --- 135,144 ----
  82.   yyoutflush(){
  83.       if(yyout_is_string){
  84.           ASSERT(yystrout->overflow_handler);
  85. ! /*XXX-UWE-XXX*/
  86. !     (*(yystrout->overflow_handler))(yystrout);
  87. !     /* yystrout->ptr = yystrout-> buffer; */
  88. ! /*XXX-UWE-XXX*/
  89.       }else{
  90.       fflush(yyout);
  91.       }
  92. ***************
  93. *** 271,276 ****
  94. --- 273,279 ----
  95.       WOOL_STRING_STREAM str = (WOOL_STRING_STREAM)
  96.           Malloc(sizeof(struct _WOOL_STRING_STREAM));
  97.       str->buffer = (char *) Malloc(nbytes);
  98. +     *str->buffer = '\0';        /*XXX-UWE-XXX*/
  99.       str->ptr = str->buffer;
  100.       str->last = str->buffer + nbytes -1;
  101.       str->overflow_handler = handler;
  102.