From 730831504cde7db84721e75a8f942ffc32300fe2 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周三, 25 12月 2013 04:56:32 +0800 Subject: [PATCH] Refactor bool_t to scpi_bool_t --- libscpi/inc/scpi/units.h | 2 libscpi/inc/scpi/fifo.h | 6 +- libscpi/src/parser.c | 20 +++++----- libscpi/src/fifo.c | 6 +- examples/common/scpi-def.c | 2 libscpi/inc/scpi/debug.h | 2 libscpi/inc/scpi/types.h | 6 +- libscpi/src/ieee488.c | 2 libscpi/src/units.c | 8 ++-- libscpi/test/test_scpi_utils.c | 8 ++-- libscpi/src/debug.c | 2 libscpi/src/utils.h | 12 +++--- libscpi/inc/scpi/parser.h | 14 +++--- libscpi/src/utils.c | 20 +++++----- libscpi/test/test_lib.c | 4 +- 15 files changed, 57 insertions(+), 57 deletions(-) diff --git a/examples/common/scpi-def.c b/examples/common/scpi-def.c index b84cdd9..3a863c9 100644 --- a/examples/common/scpi-def.c +++ b/examples/common/scpi-def.c @@ -118,7 +118,7 @@ } scpi_result_t TEST_Bool(scpi_t * context) { - bool_t param1; + scpi_bool_t param1; fprintf(stderr, "TEST:BOOL\r\n"); // debug command name // read first parameter if present diff --git a/libscpi/inc/scpi/debug.h b/libscpi/inc/scpi/debug.h index e882902..b1e8047 100644 --- a/libscpi/inc/scpi/debug.h +++ b/libscpi/inc/scpi/debug.h @@ -48,7 +48,7 @@ #define SCPI_DEBUG_COMMAND(a) - bool_t SCPI_DebugCommand(scpi_t * context); + scpi_bool_t SCPI_DebugCommand(scpi_t * context); #ifdef __cplusplus diff --git a/libscpi/inc/scpi/fifo.h b/libscpi/inc/scpi/fifo.h index 9429e9e..63ba6b4 100644 --- a/libscpi/inc/scpi/fifo.h +++ b/libscpi/inc/scpi/fifo.h @@ -56,9 +56,9 @@ void fifo_init(fifo_t * fifo); void fifo_clear(fifo_t * fifo); - bool_t fifo_add(fifo_t * fifo, int16_t value); - bool_t fifo_remove(fifo_t * fifo, int16_t * value); - bool_t fifo_count(fifo_t * fifo, int16_t * value); + scpi_bool_t fifo_add(fifo_t * fifo, int16_t value); + scpi_bool_t fifo_remove(fifo_t * fifo, int16_t * value); + scpi_bool_t fifo_count(fifo_t * fifo, int16_t * value); #ifdef __cplusplus } diff --git a/libscpi/inc/scpi/parser.h b/libscpi/inc/scpi/parser.h index 9e1678f..002ef8c 100644 --- a/libscpi/inc/scpi/parser.h +++ b/libscpi/inc/scpi/parser.h @@ -54,14 +54,14 @@ size_t SCPI_ResultInt(scpi_t * context, int32_t val); size_t SCPI_ResultDouble(scpi_t * context, double val); size_t SCPI_ResultText(scpi_t * context, const char * data); - size_t SCPI_ResultBool(scpi_t * context, bool_t val); + size_t SCPI_ResultBool(scpi_t * context, scpi_bool_t val); - bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory); - bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory); - bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, bool_t mandatory); - bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, bool_t mandatory); - bool_t SCPI_ParamBool(scpi_t * context, bool_t * value, bool_t mandatory); - bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, bool_t mandatory); + scpi_bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, scpi_bool_t mandatory); + scpi_bool_t SCPI_ParamDouble(scpi_t * context, double * value, scpi_bool_t mandatory); + scpi_bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory); + scpi_bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory); + scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory); + scpi_bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, scpi_bool_t mandatory); #ifdef __cplusplus diff --git a/libscpi/inc/scpi/types.h b/libscpi/inc/scpi/types.h index 982caae..3597275 100644 --- a/libscpi/inc/scpi/types.h +++ b/libscpi/inc/scpi/types.h @@ -55,8 +55,8 @@ #endif /* basic data types */ - typedef bool bool_t; - /* typedef enum { FALSE = 0, TRUE } bool_t; */ + typedef bool scpi_bool_t; + /* typedef enum { FALSE = 0, TRUE } scpi_bool_t; */ /* IEEE 488.2 registers */ enum _scpi_reg_name_t { @@ -202,7 +202,7 @@ scpi_interface_t * interface; int_fast16_t output_count; int_fast16_t input_count; - bool_t cmd_error; + scpi_bool_t cmd_error; scpi_error_queue_t error_queue; scpi_reg_val_t * registers; const scpi_unit_def_t * units; diff --git a/libscpi/inc/scpi/units.h b/libscpi/inc/scpi/units.h index 8a06301..e66e521 100644 --- a/libscpi/inc/scpi/units.h +++ b/libscpi/inc/scpi/units.h @@ -46,7 +46,7 @@ extern const scpi_unit_def_t scpi_units_def[]; extern const scpi_special_number_def_t scpi_special_numbers_def[]; - bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, bool_t mandatory); + scpi_bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, scpi_bool_t mandatory); size_t SCPI_NumberToStr(scpi_t * context, scpi_number_t * value, char * str, size_t len); #ifdef __cplusplus diff --git a/libscpi/src/debug.c b/libscpi/src/debug.c index a0b5f57..832bd93 100644 --- a/libscpi/src/debug.c +++ b/libscpi/src/debug.c @@ -42,7 +42,7 @@ * @param context * @return */ -bool_t SCPI_DebugCommand(scpi_t * context) { +scpi_bool_t SCPI_DebugCommand(scpi_t * context) { size_t res; printf("**DEBUG: %s (\"", context->paramlist.cmd->pattern); res = fwrite(context->paramlist.parameters, 1, context->paramlist.length, stdout); diff --git a/libscpi/src/fifo.c b/libscpi/src/fifo.c index cb9d385..ff8a345 100644 --- a/libscpi/src/fifo.c +++ b/libscpi/src/fifo.c @@ -12,7 +12,7 @@ fifo->rd = 0; } -bool_t fifo_add(fifo_t * fifo, int16_t value) { +scpi_bool_t fifo_add(fifo_t * fifo, int16_t value) { /* FIFO full? */ if (fifo->wr == ((fifo->rd + fifo->size) % (fifo->size + 1))) { fifo_remove(fifo, NULL); @@ -24,7 +24,7 @@ return TRUE; } -bool_t fifo_remove(fifo_t * fifo, int16_t * value) { +scpi_bool_t fifo_remove(fifo_t * fifo, int16_t * value) { /* FIFO empty? */ if (fifo->wr == fifo->rd) { return FALSE; @@ -39,7 +39,7 @@ return TRUE; } -bool_t fifo_count(fifo_t * fifo, int16_t * value) { +scpi_bool_t fifo_count(fifo_t * fifo, int16_t * value) { *value = fifo->wr - fifo->rd; if (*value < 0) { *value += (fifo->size + 1); diff --git a/libscpi/src/ieee488.c b/libscpi/src/ieee488.c index 789613b..73701ec 100644 --- a/libscpi/src/ieee488.c +++ b/libscpi/src/ieee488.c @@ -98,7 +98,7 @@ * @param val - new value */ void SCPI_RegSet(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t val) { - bool_t srq = FALSE; + scpi_bool_t srq = FALSE; scpi_reg_val_t mask; scpi_reg_val_t old_val; diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index d5728af..1f4e9d7 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -52,7 +52,7 @@ static void paramSkipBytes(scpi_t * context, size_t num); static void paramSkipWhitespace(scpi_t * context); -static bool_t paramNext(scpi_t * context, bool_t mandatory); +static scpi_bool_t paramNext(scpi_t * context, scpi_bool_t mandatory); /* int _strnicmp(const char* s1, const char* s2, size_t len) { @@ -226,7 +226,7 @@ * @param context * @result TRUE if context->paramlist is filled with correct values */ -static bool_t findCommand(scpi_t * context, const char * cmdline_ptr, size_t cmdline_len, size_t cmd_len) { +static scpi_bool_t findCommand(scpi_t * context, const char * cmdline_ptr, size_t cmdline_len, size_t cmd_len) { int32_t i; const scpi_command_t * cmd; @@ -392,7 +392,7 @@ * @param val * @return */ -size_t SCPI_ResultBool(scpi_t * context, bool_t val) { +size_t SCPI_ResultBool(scpi_t * context, scpi_bool_t val) { return SCPI_ResultInt(context, val ? 1 : 0); } @@ -459,7 +459,7 @@ * @param mandatory * @return */ -bool_t paramNext(scpi_t * context, bool_t mandatory) { +scpi_bool_t paramNext(scpi_t * context, scpi_bool_t mandatory) { paramSkipWhitespace(context); if (context->paramlist.length == 0) { if (mandatory) { @@ -487,7 +487,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory) { +scpi_bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, scpi_bool_t mandatory) { const char * param; size_t param_len; size_t num_len; @@ -517,7 +517,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory) { +scpi_bool_t SCPI_ParamDouble(scpi_t * context, double * value, scpi_bool_t mandatory) { const char * param; size_t param_len; size_t num_len; @@ -548,7 +548,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, bool_t mandatory) { +scpi_bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) { size_t length; if (!value || !len) { @@ -579,7 +579,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, bool_t mandatory) { +scpi_bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) { size_t length; if (!value || !len) { @@ -608,7 +608,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamBool(scpi_t * context, bool_t * value, bool_t mandatory) { +scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory) { const char * param; size_t param_len; size_t num_len; @@ -648,7 +648,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, bool_t mandatory) { +scpi_bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, scpi_bool_t mandatory) { const char * param; size_t param_len; size_t res; diff --git a/libscpi/src/units.c b/libscpi/src/units.c index 493c4ce..958b61e 100644 --- a/libscpi/src/units.c +++ b/libscpi/src/units.c @@ -122,7 +122,7 @@ * @param value resultin value * @return TRUE if str matches one of specs patterns */ -static bool_t translateSpecialNumber(const scpi_special_number_def_t * specs, const char * str, size_t len, scpi_number_t * value) { +static scpi_bool_t translateSpecialNumber(const scpi_special_number_def_t * specs, const char * str, size_t len, scpi_number_t * value) { int i; value->value = 0.0; @@ -218,7 +218,7 @@ * @param value preparsed numeric value * @return TRUE if value parameter was converted to base units */ -static bool_t transformNumber(scpi_t * context, const char * unit, size_t len, scpi_number_t * value) { +static scpi_bool_t transformNumber(scpi_t * context, const char * unit, size_t len, scpi_number_t * value) { size_t s; const scpi_unit_def_t * unitDef; s = skipWhitespace(unit, len); @@ -248,8 +248,8 @@ * @param mandatory if the parameter is mandatory * @return */ -bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, bool_t mandatory) { - bool_t result; +scpi_bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, scpi_bool_t mandatory) { + scpi_bool_t result; const char * param; size_t len; size_t numlen; diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c index 6a41e54..5b5cf04 100644 --- a/libscpi/src/utils.c +++ b/libscpi/src/utils.c @@ -146,7 +146,7 @@ * @param len2 * @return TRUE if len1==len2 and "len" characters of both strings are equal */ -bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) { +scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) { if (len1 != len2) { return FALSE; } @@ -179,7 +179,7 @@ /** * Test locate text state, if it is correct final state */ -static bool_t isFinalState(locate_text_states state) { +static scpi_bool_t isFinalState(locate_text_states state) { return ( ((state) == STATE_COMMA) || ((state) == STATE_LAST_WHITESPACE) @@ -193,7 +193,7 @@ * @param nfa stores automaton state * @param c current char processed */ -static bool_t locateTextAutomaton(locate_text_nfa * nfa, unsigned char c) { +static scpi_bool_t locateTextAutomaton(locate_text_nfa * nfa, unsigned char c) { switch(nfa->state) { /* first state locating only white spaces */ case STATE_FIRST_WHITESPACE: @@ -257,7 +257,7 @@ * @param len2 length of result * @return string str1 contains text and str2 was set */ -bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) { +scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) { locate_text_nfa nfa; nfa.state = STATE_FIRST_WHITESPACE; nfa.startIdx = 0; @@ -288,7 +288,7 @@ * @param nfa stores automaton state * @param c current char processed */ -static bool_t locateStrAutomaton(locate_text_nfa * nfa, unsigned char c) { +static scpi_bool_t locateStrAutomaton(locate_text_nfa * nfa, unsigned char c) { switch(nfa->state) { /* first state locating only white spaces */ case STATE_FIRST_WHITESPACE: @@ -332,7 +332,7 @@ * @param len2 length of result * @return string str1 contains text and str2 was set */ -bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) { +scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) { locate_text_nfa nfa; nfa.state = STATE_FIRST_WHITESPACE; nfa.startIdx = 0; @@ -435,7 +435,7 @@ * @param str_len * @return */ -bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) { +scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) { int pattern_sep_pos_short = patternSeparatorShortPos(pattern, pattern_len); return compareStr(pattern, pattern_len, str, str_len) || compareStr(pattern, pattern_sep_pos_short, str, str_len); @@ -448,8 +448,8 @@ * @param len - max search length * @return TRUE if pattern matches, FALSE otherwise */ -bool_t matchCommand(const char * pattern, const char * cmd, size_t len) { - bool_t result = FALSE; +scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len) { + scpi_bool_t result = FALSE; int leftFlag = 0; // flag for '[' on left int rightFlag = 0; // flag for ']' on right int cmd_sep_pos = 0; @@ -598,7 +598,7 @@ * * */ -bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, +scpi_bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen) { char * ptr; size_t len; diff --git a/libscpi/src/utils.h b/libscpi/src/utils.h index 0969ce7..f3b6859 100644 --- a/libscpi/src/utils.h +++ b/libscpi/src/utils.h @@ -52,18 +52,18 @@ #endif const char * strnpbrk(const char *str, size_t size, const char *set) LOCAL; - bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL; + scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL; size_t longToStr(int32_t val, char * str, size_t len) LOCAL; size_t doubleToStr(double val, char * str, size_t len) LOCAL; size_t strToLong(const char * str, int32_t * val) LOCAL; size_t strToDouble(const char * str, double * val) LOCAL; - bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; - bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; + scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; + scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; size_t skipWhitespace(const char * cmd, size_t len) LOCAL; size_t skipColon(const char * cmd, size_t len) LOCAL; - bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) LOCAL; - bool_t matchCommand(const char * pattern, const char * cmd, size_t len) LOCAL; - bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); + scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) LOCAL; + scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len) LOCAL; + scpi_bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); #if !HAVE_STRNLEN size_t BSD_strnlen(const char *s, size_t maxlen); diff --git a/libscpi/test/test_lib.c b/libscpi/test/test_lib.c index 650e036..c5be44f 100644 --- a/libscpi/test/test_lib.c +++ b/libscpi/test/test_lib.c @@ -106,8 +106,8 @@ return SCPI_RES_OK; } -bool_t TST_executed = FALSE; -bool_t RST_executed = FALSE; +scpi_bool_t TST_executed = FALSE; +scpi_bool_t RST_executed = FALSE; static scpi_result_t SCPI_Test(scpi_t * context) { TST_executed = TRUE; return SCPI_RES_OK; diff --git a/libscpi/test/test_scpi_utils.c b/libscpi/test/test_scpi_utils.c index 43f3339..8fd42f5 100644 --- a/libscpi/test/test_scpi_utils.c +++ b/libscpi/test/test_scpi_utils.c @@ -264,7 +264,7 @@ } void test_matchPattern() { - bool_t result; + scpi_bool_t result; #define TEST_MATCH_PATTERN(p, s, r) \ do { \ @@ -280,7 +280,7 @@ } void test_matchCommand() { - bool_t result; + scpi_bool_t result; #define TEST_MATCH_COMMAND(p, s, r) \ do { \ @@ -398,7 +398,7 @@ char * cmd = buffer + c2_pos; \ size_t len_prev = c1_len; \ size_t len = c2_len; \ - bool_t res; \ + scpi_bool_t res; \ \ strcpy(buffer, b); \ res = composeCompoundCommand(cmd_prev, len_prev, &cmd, &len); \ @@ -419,7 +419,7 @@ TEST_COMPOSE_COMMAND(":A:B;:C", 4, 5, 2, ":C", TRUE); TEST_COMPOSE_COMMAND(":A;C", 2, 3, 1, ":C", TRUE); - bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); + scpi_bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); } -- Gitblit v1.9.1