diff --git a/codes/tools.h b/codes/tools.h deleted file mode 100644 index ed5fc2ada4088ede8178c2cbdde4438671ac3f9e..0000000000000000000000000000000000000000 --- a/codes/tools.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2013 University of Chicago. - * See COPYRIGHT notice in top-level directory. - * - */ - -#ifndef SRC_COMMON_UTIL_TOOLS_H -#define SRC_COMMON_UTIL_TOOLS_H - -#ifdef UNUSED -#elif defined(__GNUC__) -# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) -#elif defined(__LCLINT__) -# define UNUSED(x) /*@unused@*/ x -#else -# define UNUSED(x) x -#endif /* UNUSED */ - -#define codesmin(a,b) ((a)<(b) ? (a):(b)) -#define codesmax(a,b) ((a)>(b) ? (a):(b)) - -void always_assert_error(const char * expr, const char * file, int lineno); - -#define ALWAYS_ASSERT(a) if (!(a)) always_assert_error(#a,__FILE__, __LINE__); - -#define ARRAY_SIZEOF(a) (sizeof(a)/sizeof(a[0])) - -char * safe_strncpy(char * buf, const char * source, unsigned int bufsize); - -#define CODES_FLAG_ISSET(mode_, flag_) ((mode_ & flag_) != 0) -#define CODES_FLAG_SET(mode_, flag_, branch_) \ -do \ -{ \ - mode_ = mode_ | flag_; \ - branch_ = 1; \ -}while(0) - -#define CODES_FLAG_SET_RC(mode_, flag_, branch_) \ -do \ -{ \ - if(branch_) \ - { \ - mode_ = mode_ & (~flag_); \ - } \ -}while(0) - -#endif - -/* - * Local variables: - * c-indent-level: 4 - * c-basic-offset: 4 - * End: - * - * vim: ts=8 sts=4 sw=4 expandtab - */ diff --git a/src/Makefile.subdir b/src/Makefile.subdir index 1c5a594f541585ee36dd28b942d9ac0620fe6303..f6de420ac20dc56d9d1c722db0de41bf10347d34 100644 --- a/src/Makefile.subdir +++ b/src/Makefile.subdir @@ -50,7 +50,6 @@ nobase_include_HEADERS = \ codes/CodesIOKernelTypes.h \ codes/codeslexer.h \ codes/txt_configfile.h \ - codes/tools.h \ codes/codeslogging.h \ codes/timeline.h \ codes/codesparser.h \ @@ -97,8 +96,6 @@ src_libcodes_base_a_SOURCES = \ src/modelconfig/configstoreadapter.c \ codes/txt_configfile.h \ src/modelconfig/txt_configfile.c \ - codes/tools.h \ - src/util/tools.c \ src/util/codes-callbacks.h \ src/util/codes-callbacks.c \ src/util/codes_mapping.c \ diff --git a/src/modelconfig/configglue.c b/src/modelconfig/configglue.c index 62dfe99ff7d63c4cd8e9b4bbcd67a5d5c57b60c8..7abec32281b329ee47aa45488216f8439d1fbaf8 100644 --- a/src/modelconfig/configglue.c +++ b/src/modelconfig/configglue.c @@ -4,10 +4,10 @@ * */ +#include #include #include #include "configglue.h" -#include "codes/tools.h" int cfgp_lex_error (ParserParams * p, int lineno, int colno, const char * msg) { @@ -68,17 +68,17 @@ int cfgp_parse_ok (const ParserParams * p, char * buf, int bufsize) { /* doublecheck that if an error string is present, the error code is also * set */ - ALWAYS_ASSERT(!p->lexer_error_string || p->lexer_error_code); - ALWAYS_ASSERT(!p->parser_error_string || p->parser_error_code); + assert(!p->lexer_error_string || p->lexer_error_code); + assert(!p->parser_error_string || p->parser_error_code); if (p->lexer_error_code) { - safe_strncpy (buf, p->lexer_error_string, bufsize); + strncpy (buf, p->lexer_error_string, bufsize); return 0; } if (p->parser_error_code) { - safe_strncpy (buf, p->parser_error_string, bufsize); + strncpy (buf, p->parser_error_string, bufsize); return 0; } return 1; diff --git a/src/modelconfig/configlex.l b/src/modelconfig/configlex.l index ff0863338e4569fb98fa7ccdb89e0ac0398755f6..ef47f32b85ae2d84c75e8891c5552935819b7e38 100644 --- a/src/modelconfig/configlex.l +++ b/src/modelconfig/configlex.l @@ -3,7 +3,6 @@ #include #include "src/modelconfig/configglue.h" #include "src/modelconfig/configparser.h" -#include "codes/tools.h" #define YY_EXTRA_TYPE ParserParams * diff --git a/src/modelconfig/configparser.y b/src/modelconfig/configparser.y index 1029d61d4318f35ec0e2b7f13691ee420c6f704e..9be8873233f489d23bd7044433ea7d0cb80dfec2 100644 --- a/src/modelconfig/configparser.y +++ b/src/modelconfig/configparser.y @@ -18,7 +18,6 @@ #include #include "src/modelconfig/configglue.h" -#include "codes/tools.h" #if defined __GNUC__ #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -116,7 +115,7 @@ singlekey: IDENTIFIER EQUAL_TOKEN LITERAL_STRING SEMICOLUMN { multikeynonzero: KOMMA LITERAL_STRING { param->keyvals[param->count++] = strdup ($2); - ALWAYS_ASSERT (param->count < param->maxsize); + assert (param->count < param->maxsize); } multikeyentry : multikeynonzero multikeyentry | ; @@ -129,7 +128,7 @@ multikeyinit : /* empty */ { multikeystart : LITERAL_STRING { param->keyvals[param->count++] = strdup ($1); - ALWAYS_ASSERT (param->count < param->maxsize); + assert (param->count < param->maxsize); } /* this can probably be simplified */ @@ -159,7 +158,7 @@ opt_semicolumn: SEMICOLUMN | ; subsection_openaction: IDENTIFIER OPENSECTION { SectionHandle newsection; - ALWAYS_ASSERT(param->stacktop < ARRAY_SIZEOF(param->sectionstack)); + assert(param->stacktop < sizeof(param->sectionstack)/sizeof(param->sectionstack[0])); cf_createSection (param->configfile, param->sectionstack[param->stacktop], $1, @@ -172,7 +171,7 @@ subsection_openaction: IDENTIFIER OPENSECTION subsection_closeaction: CLOSESECTION opt_semicolumn { - ALWAYS_ASSERT (param->stacktop > 0); + assert (param->stacktop > 0); SectionHandle old = param->sectionstack[param->stacktop--]; cf_closeSection (param->configfile, old); }; diff --git a/src/modelconfig/configstoreadapter.c b/src/modelconfig/configstoreadapter.c index 434401438bd50db654fc8f930bb220c24cde088e..f75286e8a51b8717887e612f83c56d647594898e 100644 --- a/src/modelconfig/configstoreadapter.c +++ b/src/modelconfig/configstoreadapter.c @@ -15,9 +15,18 @@ #include #include "configstoreadapter.h" -#include "codes/tools.h" #include "configstore.h" +/* unused attribute is only used here, so use directly in source */ +#ifdef UNUSED +#elif defined(__GNUC__) +# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) +#elif defined(__LCLINT__) +# define UNUSED(x) /*@unused@*/ x +#else +# define UNUSED(x) x +#endif /* UNUSED */ + static int cfsa_getKey (void * handle, SectionHandle section, const char * name, char * buf, size_t bufsize) { @@ -53,7 +62,7 @@ static int cfsa_getKey (void * handle, SectionHandle section, const char * name if (!dcount) { - ALWAYS_ASSERT (buf); + assert(buf); *buf = 0; ret = 0; /* tmp was not modified no need to free */ diff --git a/src/modelconfig/txt_configfile.c b/src/modelconfig/txt_configfile.c index 1f80e0b3aed538ccd5e05c09c83804d3dbd0eaac..7e13c7373627cab46944decb3371ec5344055b33 100644 --- a/src/modelconfig/txt_configfile.c +++ b/src/modelconfig/txt_configfile.c @@ -7,7 +7,6 @@ #include #include #include "codes/txt_configfile.h" -#include "codes/tools.h" #include "configglue.h" #include "src/modelconfig/configparser.h" #include "src/modelconfig/configlex.h" @@ -112,7 +111,7 @@ static int dump_section (FILE * f, ConfigHandle h, SectionHandle s, unsigned if (ret < 0) goto fail; - ALWAYS_ASSERT (sectionsize == count); + assert(sectionsize == count); for (i=0; i -#include -#include -#include "codes/tools.h" - -char * safe_strncpy(char * buf, const char * source, unsigned int size) -{ - ALWAYS_ASSERT(buf); - ALWAYS_ASSERT(source); - ALWAYS_ASSERT(size); - - strncpy (buf, source, size); - - /* size will be >0 (assert above); */ - buf[size-1]=0; - return buf; -} - -void always_assert_error(const char * expr, const char * file, int lineno) -{ - fprintf(stderr, "Assertion '%s' failed (%s:%i)!\n", expr, file, lineno); - abort(); -} - -/* - * Local variables: - * c-indent-level: 4 - * c-basic-offset: 4 - * End: - * - * vim: ts=8 sts=4 sw=4 expandtab - */