e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
24ddc71998-03-28Henrik Grubbström (Grubba) 
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifndef DYNAMIC_BUFFER_H #define DYNAMIC_BUFFER_H
d59ea42016-11-08Arne Goedeke #include "buffer.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke typedef struct byte_buffer dynamic_buffer; typedef struct byte_buffer dynbuf_string;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke #define MACRO static inline PIKE_UNUSED_ATTRIBUTE
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke /* Prototypes begin here */ MACRO char *low_make_buf_space(ptrdiff_t space, dynamic_buffer *buf) { if (space < 0) { void * ret = buffer_dst(buf); buffer_remove(buf, -space); return ret; } else { return buffer_alloc(buf, space); } } MACRO void low_my_putchar(int b,dynamic_buffer *buf) { buffer_add_char(buf, b); } MACRO void low_my_binary_strcat(const char *b, size_t l, dynamic_buffer *buf) { buffer_memcpy(buf, b, l); }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke // NOTE: dynamic buffer did zero terminate MACRO void initialize_buf(dynamic_buffer *buf) { buffer_init(buf); } MACRO void low_reinit_buf(dynamic_buffer *buf) { buffer_clear(buf); } MACRO void toss_buffer(dynamic_buffer *buf) { buffer_free(buf); } MACRO struct pike_string *low_free_buf(dynamic_buffer *buf) { return buffer_finish_pike_string(buf); }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke /* GLOBAL BUFFER LOGIC */
b3b24f2004-11-05Henrik Grubbström (Grubba) 
d59ea42016-11-08Arne Goedeke PMOD_EXPORT extern dynamic_buffer pike_global_buffer;
9fa0ee2003-11-09Martin Stjernholm 
d59ea42016-11-08Arne Goedeke MACRO dynbuf_string complex_free_buf(dynamic_buffer *old_buf) { dynbuf_string tmp; if(!buffer_ptr(&pike_global_buffer)) return pike_global_buffer; tmp=pike_global_buffer; buffer_add_char(&tmp, 0); buffer_remove(&tmp, 1); pike_global_buffer = *old_buf; return tmp; } MACRO char *simple_free_buf(dynamic_buffer *old_buf) { dynbuf_string tmp; if(!buffer_ptr(&pike_global_buffer)) return 0; tmp = complex_free_buf(old_buf); buffer_add_char(&tmp, 0); return buffer_ptr(&tmp); } MACRO struct pike_string *free_buf(dynamic_buffer *old_buf) { struct pike_string *res = low_free_buf(&pike_global_buffer); pike_global_buffer = *old_buf; return res; }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke MACRO void abandon_buf(dynamic_buffer *old_buf) { toss_buffer(&pike_global_buffer); pike_global_buffer = *old_buf; }
3c0c281998-01-26Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke MACRO char *make_buf_space(INT32 space) { return low_make_buf_space(space,&pike_global_buffer); }
3c0c281998-01-26Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke MACRO void my_putchar(int b) { low_my_putchar(b,&pike_global_buffer); }
3c0c281998-01-26Fredrik Hübinette (Hubbe) 
d59ea42016-11-08Arne Goedeke MACRO void my_binary_strcat(const char *b, ptrdiff_t l) { low_my_binary_strcat(b,l,&pike_global_buffer); } MACRO void my_strcat(const char *b) { my_binary_strcat(b,strlen(b)); } MACRO void init_buf(dynamic_buffer *old_buf) { *old_buf = pike_global_buffer; initialize_buf(&pike_global_buffer); } MACRO void save_buffer (dynamic_buffer *save_buf) { *save_buf = pike_global_buffer; initialize_buf(&pike_global_buffer); } MACRO void restore_buffer (const dynamic_buffer *save_buf) { #ifdef PIKE_DEBUG if (buffer_content_length(&pike_global_buffer)) Pike_fatal ("Global buffer already in use.\n");
61e9a01998-01-25Fredrik Hübinette (Hubbe) #endif
d59ea42016-11-08Arne Goedeke  pike_global_buffer = *save_buf; }
61e9a01998-01-25Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif