Skip to content

Commit

Permalink
odbc: Use bool for condition in test parser
Browse files Browse the repository at this point in the history
Just style change.

Signed-off-by: Frediano Ziglio <[email protected]>
  • Loading branch information
freddy77 committed Dec 8, 2024
1 parent d2bc9d4 commit 49eb124
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/odbc/unittests/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ lookup(const char *name, const struct odbc_lookup_int *table)
int
main(void)
{
int cond = 1;
bool cond = true;

#define TEST_FILE "data.in"
const char *in_file = FREETDS_SRCDIR "/" TEST_FILE;
Expand Down
2 changes: 1 addition & 1 deletion src/odbc/unittests/describecol.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ check_attr_none(ATTR_PARAMS)
int
main(void)
{
int cond = 1;
bool cond = true;
#define TEST_FILE "describecol.in"
const char *in_file = FREETDS_SRCDIR "/" TEST_FILE;
FILE *f;
Expand Down
30 changes: 14 additions & 16 deletions src/odbc/unittests/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,14 @@ odbc_get_str(char **p)
enum { MAX_BOOLS = 64 };
typedef struct {
char *name;
int value;
bool value;
} bool_t;
static bool_t bools[MAX_BOOLS];

void
odbc_set_bool(const char *name, int value)
odbc_set_bool(const char *name, bool value)
{
unsigned n;
value = !!value;
for (n = 0; n < MAX_BOOLS && bools[n].name; ++n)
if (!strcmp(bools[n].name, name)) {
bools[n].value = value;
Expand All @@ -121,7 +120,7 @@ odbc_set_bool(const char *name, int value)
bools[n].value = value;
}

static int
static bool
get_bool(const char *name)
{
unsigned n;
Expand All @@ -132,7 +131,7 @@ get_bool(const char *name)
return bools[n].value;

odbc_fatal(": boolean variable %s not found\n", name);
return 0;
return false;
}

/** initialize booleans, call after connection */
Expand Down Expand Up @@ -160,28 +159,27 @@ odbc_clear_bools(void)
}

enum { MAX_CONDITIONS = 32 };
static char conds[MAX_CONDITIONS];
static bool conds[MAX_CONDITIONS];
static unsigned cond_level = 0;

static int
static bool
pop_condition(void)
{
if (cond_level == 0) odbc_fatal(": no related if\n");
return conds[--cond_level];
}

static void
push_condition(int cond)
push_condition(bool cond)
{
if (cond != 0 && cond != 1) odbc_fatal(": invalid cond value %d\n", cond);
if (cond_level >= MAX_CONDITIONS) odbc_fatal(": too much nested conditions\n");
conds[cond_level++] = cond;
}

static int
static bool
get_not_cond(char **p)
{
int cond;
bool cond;
const char *tok = odbc_get_tok(p);
if (!tok) odbc_fatal(": wrong condition syntax\n");

Expand All @@ -193,10 +191,10 @@ get_not_cond(char **p)
return cond;
}

static int
static bool
get_condition(char **p)
{
int cond1 = get_not_cond(p), cond2;
bool cond1 = get_not_cond(p), cond2;
const char *tok;

while ((tok=odbc_get_tok(p)) != NULL) {
Expand Down Expand Up @@ -226,7 +224,7 @@ odbc_init_parser(FILE *f)
}

const char *
odbc_get_cmd_line(char **p_s, int *cond)
odbc_get_cmd_line(char **p_s, bool *cond)
{
while (fgets(line_buf, sizeof(line_buf), parse_file)) {
char *p = line_buf;
Expand All @@ -242,7 +240,7 @@ odbc_get_cmd_line(char **p_s, int *cond)

/* conditional statement */
if (!strcmp(cmd, "else")) {
int c = pop_condition();
bool c = pop_condition();
push_condition(c);
*cond = c && !*cond;
continue;
Expand All @@ -264,7 +262,7 @@ odbc_get_cmd_line(char **p_s, int *cond)
const char *s_ver = odbc_get_tok(&p);
int ver = odbc_tds_version();
int expected;
int res;
bool res;
unsigned M, m;

if (!cmp || !s_ver)
Expand Down
4 changes: 2 additions & 2 deletions src/odbc/unittests/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ void odbc_fatal(const char *msg, ...)
const char *odbc_get_tok(char **p);
const char *odbc_get_str(char **p);

void odbc_set_bool(const char *name, int value);
void odbc_set_bool(const char *name, bool value);
void odbc_init_bools(void);
void odbc_clear_bools(void);

void odbc_init_parser(FILE *f);
const char *odbc_get_cmd_line(char **p, int *cond);
const char *odbc_get_cmd_line(char **p, bool *cond);

#include <freetds/popvis.h>

0 comments on commit 49eb124

Please sign in to comment.