From: mquinson Date: Thu, 11 Oct 2007 07:41:42 +0000 (+0000) Subject: Move string buffers from 'private to tesh' to 'public in xbt' (I'm gonna use them... X-Git-Tag: v3.3~984 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/46784b142aab6e4849a92709f781a09e0a567260?ds=sidebyside Move string buffers from 'private to tesh' to 'public in xbt' (I'm gonna use them in logs for messages too long to fit into the statically sized string buffer) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@4807 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/Makefile.am b/include/Makefile.am index 23c6aa9f07..7ad075dd0e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -10,7 +10,7 @@ nobase_include_HEADERS = \ xbt/misc.h \ xbt/sysdep.h \ xbt/virtu.h \ - xbt/str.h \ + xbt/str.h xbt/strbuff.h \ xbt/function_types.h \ xbt/asserts.h xbt/ex.h \ xbt/log.h \ diff --git a/include/Makefile.in b/include/Makefile.in index 879c3ca56e..b2ede01bf4 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -217,7 +217,7 @@ nobase_include_HEADERS = \ xbt/misc.h \ xbt/sysdep.h \ xbt/virtu.h \ - xbt/str.h \ + xbt/str.h xbt/strbuff.h \ xbt/function_types.h \ xbt/asserts.h xbt/ex.h \ xbt/log.h \ diff --git a/include/xbt/strbuff.h b/include/xbt/strbuff.h new file mode 100644 index 0000000000..4a64e9202e --- /dev/null +++ b/include/xbt/strbuff.h @@ -0,0 +1,36 @@ +/* $Id: buff.h 3483 2007-05-07 11:18:56Z mquinson $ */ + +/* strbuff -- string buffers */ + +/* Copyright (c) 2007 Martin Quinson. */ +/* All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef XBT_STRBUFF_H +#define XBT_STRBUFF_H + +#include "portable.h" +#include "xbt/sysdep.h" +#include "xbt/function_types.h" +#include "xbt/log.h" +#include "xbt/str.h" + +/** + ** Buffer code + **/ +typedef struct { + char *data; + int used,size; +} s_xbt_strbuff_t, *xbt_strbuff_t; + + +XBT_PUBLIC(void) xbt_strbuff_empty(xbt_strbuff_t b); +XBT_PUBLIC(xbt_strbuff_t) xbt_strbuff_new(void); +XBT_PUBLIC(void) xbt_strbuff_free(xbt_strbuff_t b); +XBT_PUBLIC(void) xbt_strbuff_append(xbt_strbuff_t b, const char *toadd); +XBT_PUBLIC(void) xbt_strbuff_chomp(xbt_strbuff_t b); +XBT_PUBLIC(void) xbt_strbuff_trim(xbt_strbuff_t b); + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 51157cd2c4..2eee700504 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -120,7 +120,7 @@ VERSION_INFO= -version-info 2:0:0 XBT_SRC=\ \ - xbt/snprintf.c xbt/xbt_str.c \ + xbt/snprintf.c xbt/xbt_str.c xbt/xbt_strbuff.c \ xbt/ex.c \ \ xbt_modinter.h gras_modinter.h \ diff --git a/src/Makefile.in b/src/Makefile.in index 720535d714..701da54653 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -95,13 +95,13 @@ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ libLTLIBRARIES_INSTALL = $(INSTALL) LTLIBRARIES = $(lib_LTLIBRARIES) libgras_la_LIBADD = -am__objects_1 = snprintf.lo xbt_str.lo ex.lo xbt_virtu.lo \ - xbt_os_time.lo asserts.lo log.lo xbt_log_appender_file.lo \ - xbt_log_layout_simple.lo xbt_log_layout_format.lo \ - mallocator.lo dynar.lo dict.lo dict_elm.lo dict_cursor.lo \ - dict_multi.lo heap.lo fifo.lo swag.lo graph.lo set.lo \ - xbt_matrix.lo xbt_queue.lo xbt_peer.lo xbt_main.lo config.lo \ - cunit.lo graphxml_parse.lo +am__objects_1 = snprintf.lo xbt_str.lo xbt_strbuff.lo ex.lo \ + xbt_virtu.lo xbt_os_time.lo asserts.lo log.lo \ + xbt_log_appender_file.lo xbt_log_layout_simple.lo \ + xbt_log_layout_format.lo mallocator.lo dynar.lo dict.lo \ + dict_elm.lo dict_cursor.lo dict_multi.lo heap.lo fifo.lo \ + swag.lo graph.lo set.lo xbt_matrix.lo xbt_queue.lo xbt_peer.lo \ + xbt_main.lo config.lo cunit.lo graphxml_parse.lo am__objects_2 = gras.lo transport.lo gras_msg_mod.lo gras_msg_types.lo \ gras_msg_exchange.lo gras_msg_listener.lo rpc.lo timer.lo \ process.lo gras_module.lo ddt_create.lo ddt_convert.lo \ @@ -120,9 +120,9 @@ libgras_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libgras_la_LDFLAGS) $(LDFLAGS) -o $@ libsimgrid_la_LIBADD = -am__libsimgrid_la_SOURCES_DIST = xbt/snprintf.c xbt/xbt_str.c xbt/ex.c \ - xbt_modinter.h gras_modinter.h xbt/xbt_virtu.c \ - xbt/xbt_os_time.c xbt/asserts.c xbt/log.c \ +am__libsimgrid_la_SOURCES_DIST = xbt/snprintf.c xbt/xbt_str.c \ + xbt/xbt_strbuff.c xbt/ex.c xbt_modinter.h gras_modinter.h \ + xbt/xbt_virtu.c xbt/xbt_os_time.c xbt/asserts.c xbt/log.c \ xbt/xbt_log_appender_file.c xbt/xbt_log_layout_simple.c \ xbt/xbt_log_layout_format.c xbt/mallocator.c xbt/dynar.c \ xbt/dict.c xbt/dict_elm.c xbt/dict_cursor.c xbt/dict_multi.c \ @@ -190,8 +190,8 @@ libsimgrid_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ $(CXXFLAGS) $(libsimgrid_la_LDFLAGS) $(LDFLAGS) -o $@ libsimgrid4java_la_LIBADD = am__libsimgrid4java_la_SOURCES_DIST = xbt/snprintf.c xbt/xbt_str.c \ - xbt/ex.c xbt_modinter.h gras_modinter.h xbt/xbt_virtu.c \ - xbt/xbt_os_time.c xbt/asserts.c xbt/log.c \ + xbt/xbt_strbuff.c xbt/ex.c xbt_modinter.h gras_modinter.h \ + xbt/xbt_virtu.c xbt/xbt_os_time.c xbt/asserts.c xbt/log.c \ xbt/xbt_log_appender_file.c xbt/xbt_log_layout_simple.c \ xbt/xbt_log_layout_format.c xbt/mallocator.c xbt/dynar.c \ xbt/dict.c xbt/dict_elm.c xbt/dict_cursor.c xbt/dict_multi.c \ @@ -507,7 +507,7 @@ VERSION_INFO = -version-info 2:0:0 ################################################ XBT_SRC = \ \ - xbt/snprintf.c xbt/xbt_str.c \ + xbt/snprintf.c xbt/xbt_str.c xbt/xbt_strbuff.c \ xbt/ex.c \ \ xbt_modinter.h gras_modinter.h \ @@ -956,6 +956,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_sg_time.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_str.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_str_unit.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_strbuff.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_virtu.Plo@am__quote@ .c.o: @@ -993,6 +994,13 @@ xbt_str.lo: xbt/xbt_str.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xbt_str.lo `test -f 'xbt/xbt_str.c' || echo '$(srcdir)/'`xbt/xbt_str.c +xbt_strbuff.lo: xbt/xbt_strbuff.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xbt_strbuff.lo -MD -MP -MF $(DEPDIR)/xbt_strbuff.Tpo -c -o xbt_strbuff.lo `test -f 'xbt/xbt_strbuff.c' || echo '$(srcdir)/'`xbt/xbt_strbuff.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/xbt_strbuff.Tpo $(DEPDIR)/xbt_strbuff.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='xbt/xbt_strbuff.c' object='xbt_strbuff.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xbt_strbuff.lo `test -f 'xbt/xbt_strbuff.c' || echo '$(srcdir)/'`xbt/xbt_strbuff.c + ex.lo: xbt/ex.c @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ex.lo -MD -MP -MF $(DEPDIR)/ex.Tpo -c -o ex.lo `test -f 'xbt/ex.c' || echo '$(srcdir)/'`xbt/ex.c @am__fastdepCC_TRUE@ mv -f $(DEPDIR)/ex.Tpo $(DEPDIR)/ex.Plo diff --git a/tools/tesh/buff.c b/src/xbt/xbt_strbuff.c similarity index 67% rename from tools/tesh/buff.c rename to src/xbt/xbt_strbuff.c index 691d53df08..12355c2335 100644 --- a/tools/tesh/buff.c +++ b/src/xbt/xbt_strbuff.c @@ -1,6 +1,6 @@ -/* $Id$ */ +/* $Id: buff.c 3483 2007-05-07 11:18:56Z mquinson $ */ -/* buff -- buffers as needed by tesh */ +/* strbuff -- string buffers */ /* Copyright (c) 2007 Martin Quinson. */ /* All rights reserved. */ @@ -13,34 +13,34 @@ #pragma hdrstop #endif -#include "buff.h" +#include "xbt/strbuff.h" -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(strbuff,xbt,"String buffers"); /** ** Buffer code **/ -void buff_empty(buff_t b) { +void xbt_strbuff_empty(xbt_strbuff_t b) { b->used=0; b->data[0]='\n'; b->data[1]='\0'; } -buff_t buff_new(void) { - buff_t res=malloc(sizeof(s_buff_t)); +xbt_strbuff_t xbt_strbuff_new(void) { + xbt_strbuff_t res=malloc(sizeof(s_xbt_strbuff_t)); res->data=malloc(512); res->size=512; - buff_empty(res); + xbt_strbuff_empty(res); return res; } -void buff_free(buff_t b) { +void xbt_strbuff_free(xbt_strbuff_t b) { if (b) { if (b->data) free(b->data); free(b); } } -void buff_append(buff_t b, const char *toadd) { +void xbt_strbuff_append(xbt_strbuff_t b, const char *toadd) { int addlen; int needed_space; @@ -57,7 +57,7 @@ void buff_append(buff_t b, const char *toadd) { strcpy(b->data+b->used, toadd); b->used += addlen; } -void buff_chomp(buff_t b) { +void xbt_strbuff_chomp(xbt_strbuff_t b) { while (b->data[b->used] == '\n') { b->data[b->used] = '\0'; if (b->used) @@ -65,7 +65,7 @@ void buff_chomp(buff_t b) { } } -void buff_trim(buff_t b) { +void xbt_strbuff_trim(xbt_strbuff_t b) { xbt_str_trim(b->data," "); b->used = strlen(b->data); } diff --git a/tools/tesh/Makefile.am b/tools/tesh/Makefile.am index cab98ac715..fdb844a0a0 100644 --- a/tools/tesh/Makefile.am +++ b/tools/tesh/Makefile.am @@ -11,7 +11,7 @@ INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/src/include -I$(top_srcdir)/s bin_PROGRAMS = tesh -tesh_SOURCES = run_context.c run_context.h tesh.c tesh.h buff.h buff.c signal.c +tesh_SOURCES = run_context.c run_context.h tesh.c tesh.h signal.c tesh_LDADD = $(top_builddir)/src/libgras.la TESTS_ENVIRONMENT=./tesh diff --git a/tools/tesh/Makefile.in b/tools/tesh/Makefile.in index f2048a6788..add46ff791 100644 --- a/tools/tesh/Makefile.in +++ b/tools/tesh/Makefile.in @@ -65,7 +65,7 @@ CONFIG_CLEAN_FILES = am__installdirs = "$(DESTDIR)$(bindir)" binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) -am_tesh_OBJECTS = run_context.$(OBJEXT) tesh.$(OBJEXT) buff.$(OBJEXT) \ +am_tesh_OBJECTS = run_context.$(OBJEXT) tesh.$(OBJEXT) \ signal.$(OBJEXT) tesh_OBJECTS = $(am_tesh_OBJECTS) tesh_DEPENDENCIES = $(top_builddir)/src/libgras.la @@ -223,7 +223,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AM_CFLAGS = -g INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/src/include -I$(top_srcdir)/src -tesh_SOURCES = run_context.c run_context.h tesh.c tesh.h buff.h buff.c signal.c +tesh_SOURCES = run_context.c run_context.h tesh.c tesh.h signal.c tesh_LDADD = $(top_builddir)/src/libgras.la TESTS_ENVIRONMENT = ./tesh TESTS = basic.tesh cd.tesh \ @@ -305,7 +305,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buff.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run_context.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tesh.Po@am__quote@ diff --git a/tools/tesh/buff.h b/tools/tesh/buff.h deleted file mode 100644 index 55a2e9f610..0000000000 --- a/tools/tesh/buff.h +++ /dev/null @@ -1,36 +0,0 @@ -/* $Id$ */ - -/* buff -- buffers as needed by tesh */ - -/* Copyright (c) 2007 Martin Quinson. */ -/* All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef TESH_BUFF_H -#define TESH_BUFF_H - -#include "portable.h" -#include "xbt/sysdep.h" -#include "xbt/function_types.h" -#include "xbt/log.h" -#include "xbt/str.h" - -/** - ** Buffer code - **/ -typedef struct { - char *data; - int used,size; -} s_buff_t, *buff_t; - - -void buff_empty(buff_t b); -buff_t buff_new(void); -void buff_free(buff_t b); -void buff_append(buff_t b, const char *toadd); -void buff_chomp(buff_t b); -void buff_trim(buff_t b); - -#endif diff --git a/tools/tesh/run_context.c b/tools/tesh/run_context.c index 645cae14d4..f9fbdaeb08 100644 --- a/tools/tesh/run_context.c +++ b/tools/tesh/run_context.c @@ -116,17 +116,17 @@ void rctx_empty(rctx_t rc) { rc->brokenpipe = 0; rc->timeout = 0; rc->interrupted = 0; - buff_empty(rc->input); - buff_empty(rc->output_wanted); - buff_empty(rc->output_got); + xbt_strbuff_empty(rc->input); + xbt_strbuff_empty(rc->output_wanted); + xbt_strbuff_empty(rc->output_got); } rctx_t rctx_new() { rctx_t res = xbt_new0(s_rctx_t,1); - res->input=buff_new(); - res->output_wanted=buff_new(); - res->output_got=buff_new(); + res->input=xbt_strbuff_new(); + res->output_wanted=xbt_strbuff_new(); + res->output_got=xbt_strbuff_new(); res->interruption = xbt_os_mutex_init(); rctx_empty(res); return res; @@ -143,9 +143,9 @@ void rctx_free(rctx_t rctx) { if (rctx->filepos) free(rctx->filepos); xbt_os_mutex_destroy(rctx->interruption); - buff_free(rctx->input); - buff_free(rctx->output_got); - buff_free(rctx->output_wanted); + xbt_strbuff_free(rctx->input); + xbt_strbuff_free(rctx->output_got); + xbt_strbuff_free(rctx->output_wanted); free(rctx); } @@ -195,14 +195,14 @@ void rctx_pushline(const char* filepos, char kind, char *line) { case '<': rctx->is_empty = 0; - buff_append(rctx->input,line); - buff_append(rctx->input,"\n"); + xbt_strbuff_append(rctx->input,line); + xbt_strbuff_append(rctx->input,"\n"); break; case '>': rctx->is_empty = 0; - buff_append(rctx->output_wanted,line); - buff_append(rctx->output_wanted,"\n"); + xbt_strbuff_append(rctx->output_wanted,line); + xbt_strbuff_append(rctx->output_wanted,"\n"); break; case '!': @@ -298,7 +298,7 @@ static void *thread_reader(void *r) { } if (posr>0) { buffout[posr]='\0'; - buff_append(rctx->output_got,buffout); + xbt_strbuff_append(rctx->output_got,buffout); } else { usleep(100); } @@ -435,10 +435,10 @@ void *rctx_wait(void* r) { return NULL; xbt_os_mutex_lock(rctx->interruption);*/ - buff_chomp(rctx->output_got); - buff_chomp(rctx->output_wanted); - buff_trim(rctx->output_got); - buff_trim(rctx->output_wanted); + xbt_strbuff_chomp(rctx->output_got); + xbt_strbuff_chomp(rctx->output_wanted); + xbt_strbuff_trim(rctx->output_got); + xbt_strbuff_trim(rctx->output_wanted); /* Check for broken pipe */ if (rctx->brokenpipe) diff --git a/tools/tesh/run_context.h b/tools/tesh/run_context.h index 57046720f8..bc76e3bf6c 100644 --- a/tools/tesh/run_context.h +++ b/tools/tesh/run_context.h @@ -46,9 +46,9 @@ typedef struct { int expected_return; /* the exepeted return code of following command */ /* buffers */ - buff_t input; - buff_t output_wanted; - buff_t output_got; + xbt_strbuff_t input; + xbt_strbuff_t output_wanted; + xbt_strbuff_t output_got; /* Threads */ xbt_os_thread_t writer, reader; /* IO handlers */ diff --git a/tools/tesh/tesh.c b/tools/tesh/tesh.c index bfeb4c0763..fa34d0b136 100644 --- a/tools/tesh/tesh.c +++ b/tools/tesh/tesh.c @@ -88,7 +88,7 @@ static void handle_suite(const char* filename, FILE* IN) { int line_num=0; char file_pos[256]; - buff_t buff=buff_new(); + xbt_strbuff_t buff=xbt_strbuff_new(); int buffbegin = 0; rctx = rctx_new(); @@ -135,12 +135,12 @@ static void handle_suite(const char* filename, FILE* IN) { } if (buff->used || to_be_continued) { - buff_append(buff,line); + xbt_strbuff_append(buff,line); if (!to_be_continued) { snprintf(file_pos,256,"%s:%d",filename,buffbegin); handle_line(file_pos, buff->data); - buff_empty(buff); + xbt_strbuff_empty(buff); } } else { @@ -159,7 +159,7 @@ static void handle_suite(const char* filename, FILE* IN) { /* Clear buffers */ if (line) free(line); - buff_free(buff); + xbt_strbuff_free(buff); } diff --git a/tools/tesh/tesh.h b/tools/tesh/tesh.h index c0127eac1a..b95708783a 100644 --- a/tools/tesh/tesh.h +++ b/tools/tesh/tesh.h @@ -12,9 +12,7 @@ #define TESH_H #include "xbt/xbt_os_thread.h" -/*** Buffers ***/ -/***************/ -#include "buff.h" +#include "xbt/strbuff.h" /*** What we need to know about signals ***/ /******************************************/