Commit a4cc1dfe authored by Jonathan Jenkins's avatar Jonathan Jenkins

bye-bye "tools" files

parent 1436b67e
/*
* 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
*/
...@@ -50,7 +50,6 @@ nobase_include_HEADERS = \ ...@@ -50,7 +50,6 @@ nobase_include_HEADERS = \
codes/CodesIOKernelTypes.h \ codes/CodesIOKernelTypes.h \
codes/codeslexer.h \ codes/codeslexer.h \
codes/txt_configfile.h \ codes/txt_configfile.h \
codes/tools.h \
codes/codeslogging.h \ codes/codeslogging.h \
codes/timeline.h \ codes/timeline.h \
codes/codesparser.h \ codes/codesparser.h \
...@@ -97,8 +96,6 @@ src_libcodes_base_a_SOURCES = \ ...@@ -97,8 +96,6 @@ src_libcodes_base_a_SOURCES = \
src/modelconfig/configstoreadapter.c \ src/modelconfig/configstoreadapter.c \
codes/txt_configfile.h \ codes/txt_configfile.h \
src/modelconfig/txt_configfile.c \ src/modelconfig/txt_configfile.c \
codes/tools.h \
src/util/tools.c \
src/util/codes-callbacks.h \ src/util/codes-callbacks.h \
src/util/codes-callbacks.c \ src/util/codes-callbacks.c \
src/util/codes_mapping.c \ src/util/codes_mapping.c \
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
* *
*/ */
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "configglue.h" #include "configglue.h"
#include "codes/tools.h"
int cfgp_lex_error (ParserParams * p, int lineno, int colno, const char * msg) 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) ...@@ -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 /* doublecheck that if an error string is present, the error code is also
* set */ * set */
ALWAYS_ASSERT(!p->lexer_error_string || p->lexer_error_code); assert(!p->lexer_error_string || p->lexer_error_code);
ALWAYS_ASSERT(!p->parser_error_string || p->parser_error_code); assert(!p->parser_error_string || p->parser_error_code);
if (p->lexer_error_code) if (p->lexer_error_code)
{ {
safe_strncpy (buf, p->lexer_error_string, bufsize); strncpy (buf, p->lexer_error_string, bufsize);
return 0; return 0;
} }
if (p->parser_error_code) if (p->parser_error_code)
{ {
safe_strncpy (buf, p->parser_error_string, bufsize); strncpy (buf, p->parser_error_string, bufsize);
return 0; return 0;
} }
return 1; return 1;
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <string.h> #include <string.h>
#include "src/modelconfig/configglue.h" #include "src/modelconfig/configglue.h"
#include "src/modelconfig/configparser.h" #include "src/modelconfig/configparser.h"
#include "codes/tools.h"
#define YY_EXTRA_TYPE ParserParams * #define YY_EXTRA_TYPE ParserParams *
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include <assert.h> #include <assert.h>
#include "src/modelconfig/configglue.h" #include "src/modelconfig/configglue.h"
#include "codes/tools.h"
#if defined __GNUC__ #if defined __GNUC__
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
...@@ -116,7 +115,7 @@ singlekey: IDENTIFIER EQUAL_TOKEN LITERAL_STRING SEMICOLUMN { ...@@ -116,7 +115,7 @@ singlekey: IDENTIFIER EQUAL_TOKEN LITERAL_STRING SEMICOLUMN {
multikeynonzero: KOMMA LITERAL_STRING { multikeynonzero: KOMMA LITERAL_STRING {
param->keyvals[param->count++] = strdup ($<string_buf>2); param->keyvals[param->count++] = strdup ($<string_buf>2);
ALWAYS_ASSERT (param->count < param->maxsize); assert (param->count < param->maxsize);
} }
multikeyentry : multikeynonzero multikeyentry | ; multikeyentry : multikeynonzero multikeyentry | ;
...@@ -129,7 +128,7 @@ multikeyinit : /* empty */ { ...@@ -129,7 +128,7 @@ multikeyinit : /* empty */ {
multikeystart : LITERAL_STRING { multikeystart : LITERAL_STRING {
param->keyvals[param->count++] = strdup ($<string_buf>1); param->keyvals[param->count++] = strdup ($<string_buf>1);
ALWAYS_ASSERT (param->count < param->maxsize); assert (param->count < param->maxsize);
} }
/* this can probably be simplified */ /* this can probably be simplified */
...@@ -159,7 +158,7 @@ opt_semicolumn: SEMICOLUMN | ; ...@@ -159,7 +158,7 @@ opt_semicolumn: SEMICOLUMN | ;
subsection_openaction: IDENTIFIER OPENSECTION subsection_openaction: IDENTIFIER OPENSECTION
{ {
SectionHandle newsection; SectionHandle newsection;
ALWAYS_ASSERT(param->stacktop < ARRAY_SIZEOF(param->sectionstack)); assert(param->stacktop < sizeof(param->sectionstack)/sizeof(param->sectionstack[0]));
cf_createSection (param->configfile, cf_createSection (param->configfile,
param->sectionstack[param->stacktop], $1, param->sectionstack[param->stacktop], $1,
...@@ -172,7 +171,7 @@ subsection_openaction: IDENTIFIER OPENSECTION ...@@ -172,7 +171,7 @@ subsection_openaction: IDENTIFIER OPENSECTION
subsection_closeaction: CLOSESECTION opt_semicolumn subsection_closeaction: CLOSESECTION opt_semicolumn
{ {
ALWAYS_ASSERT (param->stacktop > 0); assert (param->stacktop > 0);
SectionHandle old = param->sectionstack[param->stacktop--]; SectionHandle old = param->sectionstack[param->stacktop--];
cf_closeSection (param->configfile, old); cf_closeSection (param->configfile, old);
}; };
......
...@@ -15,9 +15,18 @@ ...@@ -15,9 +15,18 @@
#include <string.h> #include <string.h>
#include "configstoreadapter.h" #include "configstoreadapter.h"
#include "codes/tools.h"
#include "configstore.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, static int cfsa_getKey (void * handle, SectionHandle section, const char * name,
char * buf, size_t bufsize) char * buf, size_t bufsize)
{ {
...@@ -53,7 +62,7 @@ static int cfsa_getKey (void * handle, SectionHandle section, const char * name ...@@ -53,7 +62,7 @@ static int cfsa_getKey (void * handle, SectionHandle section, const char * name
if (!dcount) if (!dcount)
{ {
ALWAYS_ASSERT (buf); assert(buf);
*buf = 0; *buf = 0;
ret = 0; ret = 0;
/* tmp was not modified no need to free */ /* tmp was not modified no need to free */
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include "codes/txt_configfile.h" #include "codes/txt_configfile.h"
#include "codes/tools.h"
#include "configglue.h" #include "configglue.h"
#include "src/modelconfig/configparser.h" #include "src/modelconfig/configparser.h"
#include "src/modelconfig/configlex.h" #include "src/modelconfig/configlex.h"
...@@ -112,7 +111,7 @@ static int dump_section (FILE * f, ConfigHandle h, SectionHandle s, unsigned ...@@ -112,7 +111,7 @@ static int dump_section (FILE * f, ConfigHandle h, SectionHandle s, unsigned
if (ret < 0) if (ret < 0)
goto fail; goto fail;
ALWAYS_ASSERT (sectionsize == count); assert(sectionsize == count);
for (i=0; i<count; ++i) for (i=0; i<count; ++i)
{ {
...@@ -133,8 +132,8 @@ fail: ...@@ -133,8 +132,8 @@ fail:
int txtfile_writeConfig (ConfigHandle cf, SectionHandle h, FILE * f, char ** err) int txtfile_writeConfig (ConfigHandle cf, SectionHandle h, FILE * f, char ** err)
{ {
int ret; int ret;
ALWAYS_ASSERT(err); assert(err);
ALWAYS_ASSERT(f); assert(f);
*err = 0; *err = 0;
...@@ -155,7 +154,7 @@ ConfigHandle txtfile_openStream (FILE * f, char ** err) ...@@ -155,7 +154,7 @@ ConfigHandle txtfile_openStream (FILE * f, char ** err)
int reject; int reject;
char buf[512]; char buf[512];
ALWAYS_ASSERT(err); assert(err);
*err=0; *err=0;
...@@ -179,12 +178,12 @@ ConfigHandle txtfile_openStream (FILE * f, char ** err) ...@@ -179,12 +178,12 @@ ConfigHandle txtfile_openStream (FILE * f, char ** err)
/* either we have a valid confighandle or we have a parser error... */ /* either we have a valid confighandle or we have a parser error... */
/* not true: we can have a partial config tree */ /* not true: we can have a partial config tree */
// ALWAYS_ASSERT((p.error_code || p.configfile) && (!p.error_code || !p.configfile)); // assert((p.error_code || p.configfile) && (!p.error_code || !p.configfile));
/* If ther parser failed we need to have an error code */ /* If ther parser failed we need to have an error code */
ALWAYS_ASSERT(!reject || p.parser_error_code || p.lexer_error_code); assert(!reject || p.parser_error_code || p.lexer_error_code);
ALWAYS_ASSERT(!p.lexer_error_string || p.lexer_error_code); assert(!p.lexer_error_string || p.lexer_error_code);
ALWAYS_ASSERT(!p.parser_error_string || p.parser_error_code); assert(!p.parser_error_string || p.parser_error_code);
if (!cfgp_parse_ok (&p, buf, sizeof(buf))) if (!cfgp_parse_ok (&p, buf, sizeof(buf)))
{ {
...@@ -192,8 +191,8 @@ ConfigHandle txtfile_openStream (FILE * f, char ** err) ...@@ -192,8 +191,8 @@ ConfigHandle txtfile_openStream (FILE * f, char ** err)
} }
else else
{ {
ALWAYS_ASSERT(!p.parser_error_string); assert(!p.parser_error_string);
ALWAYS_ASSERT(!p.lexer_error_string); assert(!p.lexer_error_string);
if (err) *err = 0; if (err) *err = 0;
} }
......
/*
* Copyright (C) 2013 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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
*/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment