Jan Breuer
2013-10-21 f4d3fcc03f61df6becf302f555b27da7e361eae5
Merge branch 'master' of git://github.com/andrey-nakin/scpi-parser into andrey-nakin-master
4个文件已修改
35 ■■■■■ 已修改文件
libscpi/inc/scpi/error.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libscpi/inc/scpi/parser.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libscpi/src/error.c 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libscpi/src/parser.c 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libscpi/inc/scpi/error.h
@@ -59,6 +59,7 @@
#define SCPI_ERROR_SUFFIX_NOT_ALLOWED   -138
#define SCPI_ERROR_EXECUTION_ERROR      -200
#define SCPI_ERROR_ILLEGAL_PARAMETER_VALUE    -224
    
#ifdef    __cplusplus
}
libscpi/inc/scpi/parser.h
@@ -61,6 +61,7 @@
    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[], size_t * value, bool_t mandatory);
#ifdef    __cplusplus
libscpi/src/error.c
@@ -181,6 +181,7 @@
        case SCPI_ERROR_MISSING_PARAMETER: return "Missing parameter";
        case SCPI_ERROR_INVALID_SUFFIX: return "Invalid suffix";
        case SCPI_ERROR_SUFFIX_NOT_ALLOWED: return "Suffix not allowed";
        case SCPI_ERROR_ILLEGAL_PARAMETER_VALUE: return "Illegal parameter value";
        default: return "Unknown error";
    }
}
libscpi/src/parser.c
@@ -617,3 +617,35 @@
    return TRUE;
}
/**
 * Parse choice parameter
 * @param context
 * @param options
 * @param value
 * @param mandatory
 * @return
 */
bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], size_t * value, bool_t mandatory) {
    const char * param;
    size_t param_len;
    size_t res;
    if (!options || !value) {
        return FALSE;
    }
    if (!SCPI_ParamString(context, &param, &param_len, mandatory)) {
        return FALSE;
    }
    for (res = 0; options[res]; ++res) {
        if (matchPattern(options[res], strlen(options[res]), param, param_len)) {
            *value = res;
            return TRUE;
        }
    }
    SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
    return FALSE;
}