From 7f3d9c0c0238b1fec92fff04f87730668100b73b Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周二, 04 8月 2015 00:39:04 +0800
Subject: [PATCH] Cleanup of macros and defines

---
 libscpi/inc/scpi/debug.h  |    4 
 libscpi/inc/scpi/error.h  |  292 +++++++++++++++++------------------
 libscpi/inc/scpi/types.h  |   37 ++--
 libscpi/src/parser.c      |   43 ++---
 libscpi/inc/scpi/config.h |   66 +++++--
 libscpi/src/error.c       |   22 +-
 libscpi/inc/scpi/parser.h |    1 
 libscpi/src/utils.c       |    6 
 8 files changed, 240 insertions(+), 231 deletions(-)

diff --git a/libscpi/inc/scpi/config.h b/libscpi/inc/scpi/config.h
index bb59d4f..e301c56 100644
--- a/libscpi/inc/scpi/config.h
+++ b/libscpi/inc/scpi/config.h
@@ -2,7 +2,7 @@
  * Copyright (c) 2012-2013 Jan Breuer,
  *
  * All Rights Reserved
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
  * met:
@@ -11,7 +11,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -28,10 +28,10 @@
 /**
  * @file   config.h
  * @date   Wed Mar 20 12:21:26 UTC 2013
- * 
+ *
  * @brief  SCPI Configuration
- * 
- * 
+ *
+ *
  */
 
 #ifndef __SCPI_CONFIG_H_
@@ -41,24 +41,41 @@
 extern "C" {
 #endif
 
-/* set the termination character(s)   */
-#define ENDCODE_CR              1      /*   use a <CR> carriage return aka '\r' as termination charcter */
-#define ENDCODE_LF              2      /*   use a <LF> line feed aka       '\n' as termination charcter */
-#define ENDCODE_CRLF            3      /*   use <CR><LF> carriage return + line feed aka "\r\n" as termination charcters */
-   
-#define USED_ENDCODE            ENDCODE_LF
-   
-/* select the error list(s) */
-#define ERR_SCPI_MINIMUM        1
-#define ERR_SCPI_FULL           2
-#define ERR_SCPI_MIN_PLUS_USER  3
-#define ERR_SCPI_FULL_PLUS_USER 4
+#ifdef SCPI_USER_CONFIG
+#include "scpi_user_config.h"
+#endif
 
-#define USED_SCPI_ERROR_LIST    ERR_SCPI_MIN_PLUS_USER
-   
+/* set the termination character(s)   */
+#define LINE_ENDING_CR          "\r"    /*   use a <CR> carriage return as termination charcter */
+#define LINE_ENDING_LF          "\n"    /*   use a <LF> line feed as termination charcter */
+#define LINE_ENDING_CRLF        "\r\n"  /*   use <CR><LF> carriage return + line feed as termination charcters */
+
+#ifndef SCPI_LINE_ENDING
+#define SCPI_LINE_ENDING        LINE_ENDING_CRLF
+#endif
+
+/* Enable full error list
+ * 0 = Minimal set of errors
+ * 1 = Full set of errors
+ *
+ * For small systems, full set of errors will occupy large ammount of data
+ */
+#ifndef USE_FULL_ERROR_LIST
+#define USE_FULL_ERROR_LIST 0
+#endif
+
+/**
+ * Enable also LIST_OF_USER_ERRORS to be included
+ * 0 = Use only library defined errors
+ * 1 = Use also LIST_OF_USER_ERRORS
+ */
+#ifndef USE_USER_ERROR_LIST
+#define USE_USER_ERROR_LIST 0
+#endif
+
 /* Compiler specific */
-/* ARM, e.g. Cortex-M CPUs */
-#if defined(__arm__)
+/* RealView/Keil ARM Compiler, e.g. Cortex-M CPUs */
+#if defined(__CC_ARM)
 #define HAVE_STRNLEN            0
 #define HAVE_STRNCASECMP        1
 #define HAVE_STRNICMP           0
@@ -68,7 +85,8 @@
 #if defined(_CVI_)
 #define HAVE_STRNLEN            0
 #define HAVE_STRNCASECMP        0
-#define HAVE_STRNICMP           0
+#define HAVE_STRNICMP           1
+#define HAVE_STDBOOL            0
 #endif
 
 /* 8bit PIC - PIC16, etc */
@@ -111,6 +129,10 @@
 #define HAVE_STRNICMP           0
 #endif
 
+#ifndef HAVE_STDBOOL
+#define HAVE_STDBOOL            1
+#endif
+
 /* define local macros depending on existance of strnlen */
 #if HAVE_STRNLEN
 #define SCPIDEFINE_strnlen(s, l)	strnlen((s), (l))
diff --git a/libscpi/inc/scpi/debug.h b/libscpi/inc/scpi/debug.h
index b1e8047..8526a74 100644
--- a/libscpi/inc/scpi/debug.h
+++ b/libscpi/inc/scpi/debug.h
@@ -26,7 +26,7 @@
  */
 
 /**
- * @file   scpi_debug.h
+ * @file   debug.h
  * @date   Thu Nov 15 10:58:45 UTC 2012
  * 
  * @brief  SCPI debug function
@@ -44,7 +44,7 @@
 #endif
 
 
-    /* #define SCPI_DEBUG_COMMAND(a)   scpi_debug_command(a) */
+    /* #define SCPI_DEBUG_COMMAND(a)   SCPI_DebugCommand(a) */
     #define SCPI_DEBUG_COMMAND(a)
 
 
diff --git a/libscpi/inc/scpi/error.h b/libscpi/inc/scpi/error.h
index dd21e70..75d1166 100644
--- a/libscpi/inc/scpi/error.h
+++ b/libscpi/inc/scpi/error.h
@@ -35,12 +35,12 @@
  */
 
 #ifndef SCPI_ERROR_H
-#define  SCPI_ERROR_H
+#define SCPI_ERROR_H
 
-#include "scpi/types.h"
 #include "scpi/config.h"
+#include "scpi/types.h"
 
-#ifdef   __cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -52,163 +52,153 @@
     const char * SCPI_ErrorTranslate(int16_t err);
 
 
-/* http://en.wikipedia.org/wiki/X_Macro */
-#if ((USED_SCPI_ERROR_LIST == ERR_SCPI_MINIMUM) || (USED_SCPI_ERROR_LIST == ERR_SCPI_MIN_PLUS_USER))
-
+/* Using X-Macro technique to define everything once
+ * http://en.wikipedia.org/wiki/X_Macro
+ *
+ * X macro is for minimal set of errors for library itself
+ * XE macro is for full set of SCPI errors available to user application
+ */
 #define LIST_OF_ERRORS \
-    X(SCPI_ERROR_INVALID_CHARACTER,          -101, "Invalid character")                            \
-    X(SCPI_ERROR_SYNTAX,                     -102, "Syntax error")                                 \
-    X(SCPI_ERROR_INVALID_SEPARATOR,          -103, "Invalid separator")                            \
-    X(SCPI_ERROR_DATA_TYPE_ERROR,            -104, "Data type error")                              \
-    X(SCPI_ERROR_PARAMETER_NOT_ALLOWED,      -108, "Parameter not allowed")                        \
-    X(SCPI_ERROR_MISSING_PARAMETER,          -109, "Missing parameter")                            \
-    X(SCPI_ERROR_UNDEFINED_HEADER,           -113, "Undefined header")                             \
-    X(SCPI_ERROR_INVALID_SUFFIX,             -131, "Invalid suffix")                               \
-    X(SCPI_ERROR_SUFFIX_NOT_ALLOWED,         -138, "Suffix not allowed")                           \
-    X(SCPI_ERROR_INVALID_STRING_DATA,        -151, "Invalid string data")                          \
-    X(SCPI_ERROR_INVALID_BLOCK_DATA,         -161, "Invalid block data")                           \
-    X(SCPI_ERROR_EXECUTION_ERROR,            -200, "Execution error")                              \
-    X(SCPI_ERROR_ILLEGAL_PARAMETER_VALUE,    -224,"Illegal parameter value")                       \
-    X(SCPI_ERROR_SYSTEM_ERROR,               -310, "System error")                                 \
-
-
-#elif ((USED_SCPI_ERROR_LIST == ERR_SCPI_FULL) || (USED_SCPI_ERROR_LIST == ERR_SCPI_FULL_PLUS_USER))
-
-#define LIST_OF_ERRORS \
-    X(SCPI_ERROR_COMMAND,                    -100, "Command error")                                \
-    X(SCPI_ERROR_INVALID_CHARACTER,          -101, "Invalid character")                            \
-    X(SCPI_ERROR_SYNTAX,                     -102, "Syntax error")                                 \
-    X(SCPI_ERROR_INVALID_SEPARATOR,          -103, "Invalid separator")                            \
-    X(SCPI_ERROR_DATA_TYPE_ERROR,            -104, "Data type error")                              \
-    X(SCPI_ERROR_GET_NOT_ALLOWED,            -105, "GET not allowed")                              \
-    X(SCPI_ERROR_PARAMETER_NOT_ALLOWED,      -108, "Parameter not allowed")                        \
-    X(SCPI_ERROR_MISSING_PARAMETER,          -109, "Missing parameter")                            \
-    X(SCPI_ERROR_COMMAND_HEADER,             -110, "Command header error")                         \
-    X(SCPI_ERROR_HEADER_SEPARATOR,           -111, "Header separator error")                       \
-    X(SCPI_ERROR_PRG_MNEMONIC_TOO_LONG,      -112, "Program mnemonic too long")                    \
-    X(SCPI_ERROR_UNDEFINED_HEADER,           -113, "Undefined header")                             \
-    X(SCPI_ERROR_HEADER_SUFFIX_OUTOFRANGE,   -114, "Header suffix out of range")                   \
-    X(SCPI_ERROR_UNEXP_NUM_OF_PARAMETER,     -115, "Unexpected number of parameters")              \
-    X(SCPI_ERROR_NUMERIC_DATA_ERROR,         -120, "Numeric data error")                           \
-    X(SCPI_ERROR_INVAL_CHAR_IN_NUMBER,       -121, "Invalid character in number")                  \
-    X(SCPI_ERROR_EXPONENT_TOO_LONG,          -123, "Exponent too large")                           \
-    X(SCPI_ERROR_TOO_MANY_DIGITS,            -124, "Too many digits")                              \
-    X(SCPI_ERROR_NUMERIC_DATA_NOT_ALLOWED,   -128, "Numeric data not allowed")                     \
-    X(SCPI_ERROR_SUFFIX_ERROR,               -130, "Suffix error")                                 \
-    X(SCPI_ERROR_INVALID_SUFFIX,             -131, "Invalid suffix")                               \
-    X(SCPI_ERROR_SUFFIX_TOO_LONG,            -134, "Suffix too long")                              \
-    X(SCPI_ERROR_SUFFIX_NOT_ALLOWED,         -138, "Suffix not allowed")                           \
-    X(SCPI_ERROR_CHARACTER_DATA_ERROR,       -140, "Character data error")                         \
-    X(SCPI_ERROR_INVAL_CHARACTER_DATA,       -141, "Invalid character data")                       \
-    X(SCPI_ERROR_CHARACTER_DATA_TOO_LONG,    -144, "Character data too long")                      \
-    X(SCPI_ERROR_CHARACTER_DATA_NOT_ALLOWED, -148, "Character data not allowed")                   \
-    X(SCPI_ERROR_STRING_DATA_ERROR,          -150, "String data error")                            \
-    X(SCPI_ERROR_INVALID_STRING_DATA,        -151, "Invalid string data")                          \
-    X(SCPI_ERROR_STRING_DATA_NOT_ALLOWED,    -158, "String data not allowed")                      \
-    X(SCPI_ERROR_BLOCK_DATA_ERROR,           -160, "Block data error")                             \
-    X(SCPI_ERROR_INVALID_BLOCK_DATA,         -161, "Invalid block data")                           \
-    X(SCPI_ERROR_BLOCK_DATA_NOT_ALLOWED,     -168, "Block data not allowed")                       \
-    X(SCPI_ERROR_EXPRESSION_PARSING_ERROR,    -170, "Expression error")                             \
-    X(SCPI_ERROR_INVAL_EXPRESSION,           -171, "Invalid expression")                           \
-    X(SCPI_ERROR_EXPRESSION_DATA_NOT_ALLOWED,-178, "Expression data not allowed")                  \
-    X(SCPI_ERROR_MACRO_DEFINITION_ERROR,     -180, "Macro error")                                  \
-    X(SCPI_ERROR_INVAL_OUTSIDE_MACRO_DEF,    -181, "Invalid outside macro definition")             \
-    X(SCPI_ERROR_INVAL_INSIDE_MACRO_DEF,     -183, "Invalid inside macro definition")              \
-    X(SCPI_ERROR_MACRO_PARAMETER_ERROR,      -184, "Macro parameter error")                        \
-    X(SCPI_ERROR_EXECUTION_ERROR,            -200, "Execution error")                              \
-    X(SCPI_ERROR_INVAL_WHILE_IN_LOCAL,       -201, "Invalid while in local")                       \
-    X(SCPI_ERROR_SETTINGS_LOST_DUE_TO_RTL,   -202, "Settings lost due to rtl")                     \
-    X(SCPI_ERROR_COMMAND_PROTECTED,          -203, "Command protected TK024")                      \
-    X(SCPI_ERROR_TRIGGER_ERROR,              -210, "Trigger error")                                \
-    X(SCPI_ERROR_TRIGGER_IGNORED,            -211, "Trigger ignored")                              \
-    X(SCPI_ERROR_ARM_IGNORED,                -212, "Arm ignored")                                  \
-    X(SCPI_ERROR_INIT_IGNORED,               -213, "Init ignored")                                 \
-    X(SCPI_ERROR_TRIGGER_DEADLOCK,           -214, "Trigger deadlock")                             \
-    X(SCPI_ERROR_ARM_DEADLOCK,               -215, "Arm deadlock")                                 \
-    X(SCPI_ERROR_PARAMETER_ERROR,            -220, "Parameter error")                              \
-    X(SCPI_ERROR_SETTINGS_CONFLICT,          -221, "Settings conflict")                            \
-    X(SCPI_ERROR_DATA_OUT_OF_RANGE,          -222, "Data out of range")                            \
-    X(SCPI_ERROR_TOO_MUCH_DATA,              -223, "Too much data")                                \
-    X(SCPI_ERROR_ILLEGAL_PARAMETER_VALUE,    -224, "Illegal parameter value")                      \
-    X(SCPI_ERROR_OUT_OF_MEMORY_FOR_REQ_OP,   -225, "Out of memory")                                \
-    X(SCPI_ERROR_LISTS_NOT_SAME_LENGTH,      -226, "Lists not same length")                        \
-    X(SCPI_ERROR_DATA_CORRUPT,               -230, "Data corrupt or stale")                        \
-    X(SCPI_ERROR_DATA_QUESTIONABLE,          -231, "Data questionable")                            \
-    X(SCPI_ERROR_INVAL_VERSION,              -233, "Invalid version")                              \
-    X(SCPI_ERROR_HARDWARE_ERROR,             -240, "Hardware error")                               \
-    X(SCPI_ERROR_HARDWARE_MISSING,           -241, "Hardware missing")                             \
-    X(SCPI_ERROR_MASS_STORAGE_ERROR,         -250, "Mass storage error")                           \
-    X(SCPI_ERROR_MISSING_MASS_STORAGE,       -251, "Missing mass storage")                         \
-    X(SCPI_ERROR_MISSING_MASS_MEDIA,         -252, "Missing media")                                \
-    X(SCPI_ERROR_CORRUPT_MEDIA,              -253, "Corrupt media")                                \
-    X(SCPI_ERROR_MEDIA_FULL,                 -254, "Media full")                                   \
-    X(SCPI_ERROR_DIRECTORY_FULL,             -255, "Directory full")                               \
-    X(SCPI_ERROR_FILE_NAME_NOT_FOUND,        -256, "File name not found")                          \
-    X(SCPI_ERROR_FILE_NAME_ERROR,            -257, "File name error")                              \
-    X(SCPI_ERROR_MEDIA_PROTECTED,            -258, "Media protected")                              \
-    X(SCPI_ERROR_EXPRESSION_EXECUTING_ERROR, -260, "Expression error")                             \
-    X(SCPI_ERROR_MATH_ERROR_IN_EXPRESSION,   -261, "Math error in expression")                     \
-    X(SCPI_ERROR_MACRO_UNDEF_EXEC_ERROR,     -270, "Macro error")                                  \
-    X(SCPI_ERROR_MACRO_SYNTAX_ERROR,         -271, "Macro syntax error")                           \
-    X(SCPI_ERROR_MACRO_EXECUTION_ERROR,      -272, "Macro execution error")                        \
-    X(SCPI_ERROR_ILLEGAL_MACRO_LABEL,        -273, "Illegal macro label")                          \
-    X(SCPI_ERROR_IMPROPER_USED_MACRO_PARAM,  -274, "Macro parameter error")                        \
-    X(SCPI_ERROR_MACRO_DEFINITION_TOO_LONG,  -275, "Macro definition too long")                    \
-    X(SCPI_ERROR_MACRO_RECURSION_ERROR,      -276, "Macro recursion error")                        \
-    X(SCPI_ERROR_MACRO_REDEF_NOT_ALLOWED,    -277, "Macro redefinition not allowed")               \
-    X(SCPI_ERROR_MACRO_HEADER_NOT_FOUND,     -278, "Macro header not found")                       \
-    X(SCPI_ERROR_PROGRAM_ERROR,              -280, "Program error")                                \
-    X(SCPI_ERROR_CANNOT_CREATE_PROGRAM,      -281, "Cannot create program")                        \
-    X(SCPI_ERROR_ILLEGAL_PROGRAM_NAME,       -282, "Illegal program name")                         \
-    X(SCPI_ERROR_ILLEGAL_VARIABLE_NAME,      -283, "Illegal variable name")                        \
-    X(SCPI_ERROR_PROGRAM_CURRENTLY_RUNNING,  -284, "Program currently running")                    \
-    X(SCPI_ERROR_PROGRAM_SYNTAX_ERROR,       -285, "Program syntax error")                         \
-    X(SCPI_ERROR_PROGRAM_RUNTIME_ERROR,      -286, "Program runtime error")                        \
-    X(SCPI_ERROR_MEMORY_USE_ERROR,           -290, "Memory use error")                             \
-    X(SCPI_ERROR_OUT_OF_MEMORY,              -291, "Out of memory")                                \
-    X(SCPI_ERROR_REF_NAME_DOES_NOT_EXIST,    -292, "Referenced name does not exist")               \
-    X(SCPI_ERROR_REF_NAME_ALREADY_EXISTS,    -293, "Referenced name already exists")               \
-    X(SCPI_ERROR_INCOMPATIBLE_TYPE,          -294, "Incompatible type")                            \
-    X(SCPI_ERROR_DEVICE_ERROR,               -300, "Device specific error")                        \
-    X(SCPI_ERROR_SYSTEM_ERROR,               -310, "System error")                                 \
-    X(SCPI_ERROR_MEMORY_ERROR,               -311, "Memory error")                                 \
-    X(SCPI_ERROR_PUD_MEMORY_LOST,            -312, "PUD memory lost")                              \
-    X(SCPI_ERROR_CALIBRATION_MEMORY_LOST,    -313, "Calibration memory lost")                      \
-    X(SCPI_ERROR_SAVE_RECALL_MEMORY_LOST,    -314, "Save/recall memory lost")                      \
-    X(SCPI_ERROR_CONFIGURATION_MEMORY_LOST,  -315, "Configuration memory lost")                    \
-    X(SCPI_ERROR_STORAGE_FAULT,              -320, "Storage fault")                                \
-    X(SCPI_ERROR_OUT_OF_DEVICE_MEMORY,       -321, "Out of memory")                                \
-    X(SCPI_ERROR_SELF_TEST_FAILED,           -330, "Self-test failed")                             \
-    X(SCPI_ERROR_CALIBRATION_FAILED,         -340, "Calibration failed")                           \
-    X(SCPI_ERROR_QUEUE_OVERFLOW,             -350, "Queue overflow")                               \
-    X(SCPI_ERROR_COMMUNICATION_ERROR,        -360, "Communication error")                          \
-    X(SCPI_ERROR_PARITY_ERROR_IN_CMD_MSG,    -361, "Parity error in program message")              \
-    X(SCPI_ERROR_FRAMING_ERROR_IN_CMD_MSG,   -362, "Framing error in program message")             \
-    X(SCPI_ERROR_INPUT_BUFFER_OVERRUN,       -363, "Input buffer overrun")                         \
-    X(SCPI_ERROR_TIME_OUT,                   -365, "Time out error")                               \
-    X(SCPI_ERROR_QUERY_ERROR,                -400, "Query error")                                  \
-    X(SCPI_ERROR_QUERY_INTERRUPTED,          -410, "Query INTERRUPTED")                            \
-    X(SCPI_ERROR_QUERY_UNTERMINATED,         -420, "Query UNTERMINATED")                           \
-    X(SCPI_ERROR_QUERY_DEADLOCKED,           -430, "Query DEADLOCKED")                             \
-    X(SCPI_ERROR_QUERY_UNTERM_INDEF_RESP,    -440, "Query UNTERMINATED after indefinite response") \
-    X(SCPI_ERROR_POWER_ON,                   -500, "Power on")                                     \
-    X(SCPI_ERROR_USER_REQUEST,               -600, "User request")                                 \
-    X(SCPI_ERROR_REQUEST_CONTROL,            -700, "Request control")                              \
-    X(SCPI_ERROR_OPERATION_COMPLETE,         -800, "Operation complete")                           \
-
-#else
-#error no SCPI error list defined!
-#endif
+    XE(SCPI_ERROR_COMMAND,                      -100, "Command error")                                \
+    X(SCPI_ERROR_INVALID_CHARACTER,             -101, "Invalid character")                            \
+    XE(SCPI_ERROR_SYNTAX,                       -102, "Syntax error")                                 \
+    X(SCPI_ERROR_INVALID_SEPARATOR,             -103, "Invalid separator")                            \
+    X(SCPI_ERROR_DATA_TYPE_ERROR,               -104, "Data type error")                              \
+    XE(SCPI_ERROR_GET_NOT_ALLOWED,              -105, "GET not allowed")                              \
+    X(SCPI_ERROR_PARAMETER_NOT_ALLOWED,         -108, "Parameter not allowed")                        \
+    X(SCPI_ERROR_MISSING_PARAMETER,             -109, "Missing parameter")                            \
+    XE(SCPI_ERROR_COMMAND_HEADER,               -110, "Command header error")                         \
+    XE(SCPI_ERROR_HEADER_SEPARATOR,             -111, "Header separator error")                       \
+    XE(SCPI_ERROR_PRG_MNEMONIC_TOO_LONG,        -112, "Program mnemonic too long")                    \
+    X(SCPI_ERROR_UNDEFINED_HEADER,              -113, "Undefined header")                             \
+    XE(SCPI_ERROR_HEADER_SUFFIX_OUTOFRANGE,     -114, "Header suffix out of range")                   \
+    XE(SCPI_ERROR_UNEXP_NUM_OF_PARAMETER,       -115, "Unexpected number of parameters")              \
+    XE(SCPI_ERROR_NUMERIC_DATA_ERROR,           -120, "Numeric data error")                           \
+    XE(SCPI_ERROR_INVAL_CHAR_IN_NUMBER,         -121, "Invalid character in number")                  \
+    XE(SCPI_ERROR_EXPONENT_TOO_LONG,            -123, "Exponent too large")                           \
+    XE(SCPI_ERROR_TOO_MANY_DIGITS,              -124, "Too many digits")                              \
+    XE(SCPI_ERROR_NUMERIC_DATA_NOT_ALLOWED,     -128, "Numeric data not allowed")                     \
+    XE(SCPI_ERROR_SUFFIX_ERROR,                 -130, "Suffix error")                                 \
+    X(SCPI_ERROR_INVALID_SUFFIX,                -131, "Invalid suffix")                               \
+    XE(SCPI_ERROR_SUFFIX_TOO_LONG,              -134, "Suffix too long")                              \
+    X(SCPI_ERROR_SUFFIX_NOT_ALLOWED,            -138, "Suffix not allowed")                           \
+    XE(SCPI_ERROR_CHARACTER_DATA_ERROR,         -140, "Character data error")                         \
+    XE(SCPI_ERROR_INVAL_CHARACTER_DATA,         -141, "Invalid character data")                       \
+    XE(SCPI_ERROR_CHARACTER_DATA_TOO_LONG,      -144, "Character data too long")                      \
+    XE(SCPI_ERROR_CHARACTER_DATA_NOT_ALLOWED,   -148, "Character data not allowed")                   \
+    XE(SCPI_ERROR_STRING_DATA_ERROR,            -150, "String data error")                            \
+    X(SCPI_ERROR_INVALID_STRING_DATA,           -151, "Invalid string data")                          \
+    XE(SCPI_ERROR_STRING_DATA_NOT_ALLOWED,      -158, "String data not allowed")                      \
+    XE(SCPI_ERROR_BLOCK_DATA_ERROR,             -160, "Block data error")                             \
+    XE(SCPI_ERROR_INVALID_BLOCK_DATA,           -161, "Invalid block data")                           \
+    XE(SCPI_ERROR_BLOCK_DATA_NOT_ALLOWED,       -168, "Block data not allowed")                       \
+    XE(SCPI_ERROR_EXPRESSION_PARSING_ERROR,     -170, "Expression error")                             \
+    XE(SCPI_ERROR_INVAL_EXPRESSION,             -171, "Invalid expression")                           \
+    XE(SCPI_ERROR_EXPRESSION_DATA_NOT_ALLOWED,  -178, "Expression data not allowed")                  \
+    XE(SCPI_ERROR_MACRO_DEFINITION_ERROR,       -180, "Macro error")                                  \
+    XE(SCPI_ERROR_INVAL_OUTSIDE_MACRO_DEF,      -181, "Invalid outside macro definition")             \
+    XE(SCPI_ERROR_INVAL_INSIDE_MACRO_DEF,       -183, "Invalid inside macro definition")              \
+    XE(SCPI_ERROR_MACRO_PARAMETER_ERROR,        -184, "Macro parameter error")                        \
+    X(SCPI_ERROR_EXECUTION_ERROR,               -200, "Execution error")                              \
+    XE(SCPI_ERROR_INVAL_WHILE_IN_LOCAL,         -201, "Invalid while in local")                       \
+    XE(SCPI_ERROR_SETTINGS_LOST_DUE_TO_RTL,     -202, "Settings lost due to rtl")                     \
+    XE(SCPI_ERROR_COMMAND_PROTECTED,            -203, "Command protected TK024")                      \
+    XE(SCPI_ERROR_TRIGGER_ERROR,                -210, "Trigger error")                                \
+    XE(SCPI_ERROR_TRIGGER_IGNORED,              -211, "Trigger ignored")                              \
+    XE(SCPI_ERROR_ARM_IGNORED,                  -212, "Arm ignored")                                  \
+    XE(SCPI_ERROR_INIT_IGNORED,                 -213, "Init ignored")                                 \
+    XE(SCPI_ERROR_TRIGGER_DEADLOCK,             -214, "Trigger deadlock")                             \
+    XE(SCPI_ERROR_ARM_DEADLOCK,                 -215, "Arm deadlock")                                 \
+    XE(SCPI_ERROR_PARAMETER_ERROR,              -220, "Parameter error")                              \
+    XE(SCPI_ERROR_SETTINGS_CONFLICT,            -221, "Settings conflict")                            \
+    XE(SCPI_ERROR_DATA_OUT_OF_RANGE,            -222, "Data out of range")                            \
+    XE(SCPI_ERROR_TOO_MUCH_DATA,                -223, "Too much data")                                \
+    X(SCPI_ERROR_ILLEGAL_PARAMETER_VALUE,       -224, "Illegal parameter value")                      \
+    XE(SCPI_ERROR_OUT_OF_MEMORY_FOR_REQ_OP,     -225, "Out of memory")                                \
+    XE(SCPI_ERROR_LISTS_NOT_SAME_LENGTH,        -226, "Lists not same length")                        \
+    XE(SCPI_ERROR_DATA_CORRUPT,                 -230, "Data corrupt or stale")                        \
+    XE(SCPI_ERROR_DATA_QUESTIONABLE,            -231, "Data questionable")                            \
+    XE(SCPI_ERROR_INVAL_VERSION,                -233, "Invalid version")                              \
+    XE(SCPI_ERROR_HARDWARE_ERROR,               -240, "Hardware error")                               \
+    XE(SCPI_ERROR_HARDWARE_MISSING,             -241, "Hardware missing")                             \
+    XE(SCPI_ERROR_MASS_STORAGE_ERROR,           -250, "Mass storage error")                           \
+    XE(SCPI_ERROR_MISSING_MASS_STORAGE,         -251, "Missing mass storage")                         \
+    XE(SCPI_ERROR_MISSING_MASS_MEDIA,           -252, "Missing media")                                \
+    XE(SCPI_ERROR_CORRUPT_MEDIA,                -253, "Corrupt media")                                \
+    XE(SCPI_ERROR_MEDIA_FULL,                   -254, "Media full")                                   \
+    XE(SCPI_ERROR_DIRECTORY_FULL,               -255, "Directory full")                               \
+    XE(SCPI_ERROR_FILE_NAME_NOT_FOUND,          -256, "File name not found")                          \
+    XE(SCPI_ERROR_FILE_NAME_ERROR,              -257, "File name error")                              \
+    XE(SCPI_ERROR_MEDIA_PROTECTED,              -258, "Media protected")                              \
+    XE(SCPI_ERROR_EXPRESSION_EXECUTING_ERROR,   -260, "Expression error")                             \
+    XE(SCPI_ERROR_MATH_ERROR_IN_EXPRESSION,     -261, "Math error in expression")                     \
+    XE(SCPI_ERROR_MACRO_UNDEF_EXEC_ERROR,       -270, "Macro error")                                  \
+    XE(SCPI_ERROR_MACRO_SYNTAX_ERROR,           -271, "Macro syntax error")                           \
+    XE(SCPI_ERROR_MACRO_EXECUTION_ERROR,        -272, "Macro execution error")                        \
+    XE(SCPI_ERROR_ILLEGAL_MACRO_LABEL,          -273, "Illegal macro label")                          \
+    XE(SCPI_ERROR_IMPROPER_USED_MACRO_PARAM,    -274, "Macro parameter error")                        \
+    XE(SCPI_ERROR_MACRO_DEFINITION_TOO_LONG,    -275, "Macro definition too long")                    \
+    XE(SCPI_ERROR_MACRO_RECURSION_ERROR,        -276, "Macro recursion error")                        \
+    XE(SCPI_ERROR_MACRO_REDEF_NOT_ALLOWED,      -277, "Macro redefinition not allowed")               \
+    XE(SCPI_ERROR_MACRO_HEADER_NOT_FOUND,       -278, "Macro header not found")                       \
+    XE(SCPI_ERROR_PROGRAM_ERROR,                -280, "Program error")                                \
+    XE(SCPI_ERROR_CANNOT_CREATE_PROGRAM,        -281, "Cannot create program")                        \
+    XE(SCPI_ERROR_ILLEGAL_PROGRAM_NAME,         -282, "Illegal program name")                         \
+    XE(SCPI_ERROR_ILLEGAL_VARIABLE_NAME,        -283, "Illegal variable name")                        \
+    XE(SCPI_ERROR_PROGRAM_CURRENTLY_RUNNING,    -284, "Program currently running")                    \
+    XE(SCPI_ERROR_PROGRAM_SYNTAX_ERROR,         -285, "Program syntax error")                         \
+    XE(SCPI_ERROR_PROGRAM_RUNTIME_ERROR,        -286, "Program runtime error")                        \
+    XE(SCPI_ERROR_MEMORY_USE_ERROR,             -290, "Memory use error")                             \
+    XE(SCPI_ERROR_OUT_OF_MEMORY,                -291, "Out of memory")                                \
+    XE(SCPI_ERROR_REF_NAME_DOES_NOT_EXIST,      -292, "Referenced name does not exist")               \
+    XE(SCPI_ERROR_REF_NAME_ALREADY_EXISTS,      -293, "Referenced name already exists")               \
+    XE(SCPI_ERROR_INCOMPATIBLE_TYPE,            -294, "Incompatible type")                            \
+    XE(SCPI_ERROR_DEVICE_ERROR,                 -300, "Device specific error")                        \
+    X(SCPI_ERROR_SYSTEM_ERROR,                  -310, "System error")                                 \
+    XE(SCPI_ERROR_MEMORY_ERROR,                 -311, "Memory error")                                 \
+    XE(SCPI_ERROR_PUD_MEMORY_LOST,              -312, "PUD memory lost")                              \
+    XE(SCPI_ERROR_CALIBRATION_MEMORY_LOST,      -313, "Calibration memory lost")                      \
+    XE(SCPI_ERROR_SAVE_RECALL_MEMORY_LOST,      -314, "Save/recall memory lost")                      \
+    XE(SCPI_ERROR_CONFIGURATION_MEMORY_LOST,    -315, "Configuration memory lost")                    \
+    XE(SCPI_ERROR_STORAGE_FAULT,                -320, "Storage fault")                                \
+    XE(SCPI_ERROR_OUT_OF_DEVICE_MEMORY,         -321, "Out of memory")                                \
+    XE(SCPI_ERROR_SELF_TEST_FAILED,             -330, "Self-test failed")                             \
+    XE(SCPI_ERROR_CALIBRATION_FAILED,           -340, "Calibration failed")                           \
+    XE(SCPI_ERROR_QUEUE_OVERFLOW,               -350, "Queue overflow")                               \
+    XE(SCPI_ERROR_COMMUNICATION_ERROR,          -360, "Communication error")                          \
+    XE(SCPI_ERROR_PARITY_ERROR_IN_CMD_MSG,      -361, "Parity error in program message")              \
+    XE(SCPI_ERROR_FRAMING_ERROR_IN_CMD_MSG,     -362, "Framing error in program message")             \
+    XE(SCPI_ERROR_INPUT_BUFFER_OVERRUN,         -363, "Input buffer overrun")                         \
+    XE(SCPI_ERROR_TIME_OUT,                     -365, "Time out error")                               \
+    XE(SCPI_ERROR_QUERY_ERROR,                  -400, "Query error")                                  \
+    XE(SCPI_ERROR_QUERY_INTERRUPTED,            -410, "Query INTERRUPTED")                            \
+    XE(SCPI_ERROR_QUERY_UNTERMINATED,           -420, "Query UNTERMINATED")                           \
+    XE(SCPI_ERROR_QUERY_DEADLOCKED,             -430, "Query DEADLOCKED")                             \
+    XE(SCPI_ERROR_QUERY_UNTERM_INDEF_RESP,      -440, "Query UNTERMINATED after indefinite response") \
+    XE(SCPI_ERROR_POWER_ON,                     -500, "Power on")                                     \
+    XE(SCPI_ERROR_USER_REQUEST,                 -600, "User request")                                 \
+    XE(SCPI_ERROR_REQUEST_CONTROL,              -700, "Request control")                              \
+    XE(SCPI_ERROR_OPERATION_COMPLETE,           -800, "Operation complete")                           \
 
 enum {
 #define X(def, val, str) def = val,
+#if USE_FULL_ERROR_LIST
+#define XE X
+#else
+#define XE(def, val, str)
+#endif
 LIST_OF_ERRORS
+
+#if USE_USER_ERROR_LIST
+LIST_OF_USER_ERRORS
+#endif
 #undef X
+#undef XE
 };
 
-#ifdef   __cplusplus
+#ifdef __cplusplus
 }
 #endif
 
-#endif   /* SCPI_ERROR_H */
+#endif /* SCPI_ERROR_H */
 
diff --git a/libscpi/inc/scpi/parser.h b/libscpi/inc/scpi/parser.h
index 549312b..4bb8d2c 100644
--- a/libscpi/inc/scpi/parser.h
+++ b/libscpi/inc/scpi/parser.h
@@ -39,7 +39,6 @@
 
 #include <string.h>
 #include "scpi/types.h"
-#include "scpi/scpi_debug.h"
 
 #ifdef	__cplusplus
 extern "C" {
diff --git a/libscpi/inc/scpi/types.h b/libscpi/inc/scpi/types.h
index 1dda5c1..db52e81 100644
--- a/libscpi/inc/scpi/types.h
+++ b/libscpi/inc/scpi/types.h
@@ -4,7 +4,7 @@
  * Copyright (c) 2012 Jan Breuer
  *
  * All Rights Reserved
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
  * met:
@@ -13,7 +13,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -30,10 +30,10 @@
 /**
  * @file   scpi_types.h
  * @date   Thu Nov 15 10:58:45 UTC 2012
- * 
+ *
  * @brief  SCPI data types
- * 
- * 
+ *
+ *
  */
 
 #ifndef SCPI_TYPES_H
@@ -41,15 +41,18 @@
 
 #include <stddef.h>
 #include <stdint.h>
+#include "scpi/config.h"
 
-#if defined(_CVI_)
-   typedef unsigned char bool;
-#else
+#if HAVE_STDBOOL
 #include <stdbool.h>
 #endif
 
 #ifdef  __cplusplus
 extern "C" {
+#endif
+
+#if !HAVE_STDBOOL
+   typedef unsigned char bool;
 #endif
 
 #ifndef FALSE
@@ -122,7 +125,7 @@
         char * data;
     };
     typedef struct _scpi_buffer_t scpi_buffer_t;
-    
+
     struct _scpi_const_buffer_t {
         size_t length;
         size_t position;
@@ -178,14 +181,14 @@
     };
     typedef struct _lex_state_t lex_state_t;
 
-    /* scpi parser */   
+    /* scpi parser */
     enum _message_termination_t {
         SCPI_MESSAGE_TERMINATION_NONE,
         SCPI_MESSAGE_TERMINATION_NL,
-        SCPI_MESSAGE_TERMINATION_SEMICOLON,                
+        SCPI_MESSAGE_TERMINATION_SEMICOLON,
     };
     typedef enum _message_termination_t message_termination_t;
-    
+
     struct _scpi_parser_state_t {
         scpi_token_t programHeader;
         scpi_token_t programData;
@@ -246,8 +249,8 @@
         lex_state_t lex_state;
         scpi_const_buffer_t cmd_raw;
     };
-    typedef struct _scpi_param_list_t scpi_param_list_t;  
-    
+    typedef struct _scpi_param_list_t scpi_param_list_t;
+
     struct _scpi_number_parameter_t {
         scpi_bool_t special;
         union {
@@ -261,12 +264,12 @@
 
     struct _scpi_data_parameter_t {
         const char * ptr;
-        int32_t len;        
+        int32_t len;
     };
     typedef struct _scpi_data_parameter_t scpi_data_parameter_t;
-    
+
     typedef scpi_token_t scpi_parameter_t;
-    
+
     struct _scpi_command_t {
         const char * pattern;
         scpi_command_callback_t callback;
diff --git a/libscpi/src/error.c b/libscpi/src/error.c
index be98d79..d856db3 100644
--- a/libscpi/src/error.c
+++ b/libscpi/src/error.c
@@ -39,7 +39,6 @@
 #include "scpi/parser.h"
 #include "scpi/ieee488.h"
 #include "scpi/error.h"
-#include "scpi-def.h"            /* this file is needed for the user provided SCPI errors */
 #include "fifo_private.h"
 
 /* basic FIFO */
@@ -179,18 +178,19 @@
 const char * SCPI_ErrorTranslate(int16_t err) {
     switch (err) {
         case 0: return "No error";
-#if ((USED_SCPI_ERROR_LIST == ERR_SCPI_MINIMUM) || (USED_SCPI_ERROR_LIST == ERR_SCPI_FULL))
-        #define X(def, val, str) case def: return str;
-        LIST_OF_ERRORS
-        #undef X
-#elif ((USED_SCPI_ERROR_LIST == ERR_SCPI_MIN_PLUS_USER) || (USED_SCPI_ERROR_LIST == ERR_SCPI_FULL_PLUS_USER))
-        #define X(def, val, str) case def: return str;
-        LIST_OF_ERRORS
-        LIST_OF_USER_ERRORS
-        #undef X        
+#define X(def, val, str) case def: return str;
+#if USE_FULL_ERROR_LIST
+#define XE X
 #else
-#error no SCPI error list defined!
+#define XE(def, val, str)
 #endif
+LIST_OF_ERRORS
+
+#if USE_USER_ERROR_LIST
+LIST_OF_USER_ERRORS
+#endif
+#undef X
+#undef XE
         default: return "Unknown error";
     }
 }
diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 21ac60a..921e885 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -44,7 +44,7 @@
 #include "scpi/error.h"
 #include "scpi/constants.h"
 #include "scpi/utils.h"
-#include "scpi/scpi_debug.h"
+#include "scpi/debug.h"
 
 /**
  * Write data to SCPI output
@@ -91,15 +91,10 @@
 static size_t writeNewLine(scpi_t * context) {
     if (context->output_count > 0) {
         size_t len;
-#if   (USED_ENDCODE == ENDCODE_CR)
-         len = writeData(context, "\r", 1);
-#elif (USED_ENDCODE == ENDCODE_LF)
-         len = writeData(context, "\n", 1);
-#elif (USED_ENDCODE == ENDCODE_CRLF)
-        len = writeData(context, "\r\n", 2);
-#else
+#ifndef SCPI_LINE_ENDING
 #error no termination character defined
 #endif
+        len = writeData(context, SCPI_LINE_ENDING, strlen(SCPI_LINE_ENDING));
         flushData(context);
         return len;
     } else {
@@ -336,7 +331,7 @@
 /**
  * Return prefix of nondecimal base
  * @param base
- * @return 
+ * @return
  */
 static const char * getBasePrefix(int8_t base) {
     switch (base) {
@@ -352,7 +347,7 @@
  * @param context
  * @param val
  * @param base
- * @return 
+ * @return
  */
 size_t SCPI_ResultIntBase(scpi_t * context, int32_t val, int8_t base) {
     char buffer[33];
@@ -411,7 +406,7 @@
  * @param context
  * @param data
  * @param len
- * @return 
+ * @return
  */
 size_t SCPI_ResultArbitraryBlock(scpi_t * context, const char * data, size_t len) {
     size_t result = 0;
@@ -458,7 +453,7 @@
  * @param context
  * @param parameter
  * @param mandatory
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_Parameter(scpi_t * context, scpi_parameter_t * parameter, scpi_bool_t mandatory) {
     lex_state_t * state;
@@ -516,7 +511,7 @@
  * Detect if parameter is number
  * @param parameter
  * @param suffixAllowed
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_ParamIsNumber(scpi_parameter_t * parameter, scpi_bool_t suffixAllowed) {
     switch (parameter->type) {
@@ -596,7 +591,7 @@
  * @param context
  * @param value
  * @param mandatory
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_ParamDouble(scpi_t * context, double * value, scpi_bool_t mandatory) {
     scpi_bool_t result;
@@ -627,7 +622,7 @@
  * @param context
  * @param value
  * @param mandatory
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, scpi_bool_t mandatory) {
     scpi_bool_t result;
@@ -659,7 +654,7 @@
  * @param value
  * @param len
  * @param mandatory
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_ParamCharacters(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) {
     scpi_bool_t result;
@@ -687,7 +682,7 @@
  * @param value result pointer to data
  * @param len result length of data
  * @param mandatory
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_ParamArbitraryBlock(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) {
     scpi_bool_t result;
@@ -757,7 +752,7 @@
  * @param parameter - should be PROGRAM_MNEMONIC
  * @param options - NULL terminated list of choices
  * @param value - index to options
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_ParamToChoice(scpi_t * context, scpi_parameter_t * parameter, const scpi_choice_def_t * options, int32_t * value) {
     size_t res;
@@ -812,7 +807,7 @@
  * @param context
  * @param value
  * @param mandatory
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory) {
     scpi_bool_t result;
@@ -853,7 +848,7 @@
  * @param options
  * @param value
  * @param mandatory
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_ParamChoice(scpi_t * context, const scpi_choice_def_t * options, int32_t * value, scpi_bool_t mandatory) {
     scpi_bool_t result;
@@ -876,7 +871,7 @@
  * Parse one parameter and detect type
  * @param state
  * @param token
- * @return 
+ * @return
  */
 int scpiParser_parseProgramData(lex_state_t * state, scpi_token_t * token) {
     scpi_token_t tmp;
@@ -915,7 +910,7 @@
  * @param state
  * @param token
  * @param numberOfParameters
- * @return 
+ * @return
  */
 int scpiParser_parseAllProgramData(lex_state_t * state, scpi_token_t * token, int * numberOfParameters) {
 
@@ -965,7 +960,7 @@
  * @param state
  * @param buffer
  * @param len
- * @return 
+ * @return
  */
 int scpiParser_detectProgramMessageUnit(scpi_parser_state_t * state, char * buffer, int len) {
     lex_state_t lex_state;
@@ -1018,7 +1013,7 @@
  *  - suitable for one handle to multiple commands
  * @param context
  * @param cmd
- * @return 
+ * @return
  */
 scpi_bool_t SCPI_IsCmd(scpi_t * context, const char * cmd) {
     const char * pattern;
diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c
index 26e4973..be9f93e 100644
--- a/libscpi/src/utils.c
+++ b/libscpi/src/utils.c
@@ -338,7 +338,7 @@
     int rightFlag = 0; // flag for ']' on right
     int cmd_sep_pos = 0;
 
-    int32_t numbers_idx = -1;         /* Lutz Hoerl, Thorlabs: changed type from size_t to int, size_t is positive only, int does not produce unsigne warnings */
+    size_t numbers_idx = 0;
     int32_t *number_ptr = NULL;
 
     const char * pattern_ptr = pattern;
@@ -379,13 +379,13 @@
         }
 
         if (pattern_ptr[pattern_sep_pos - 1] == '#') {
-            numbers_idx++;
             if (numbers && (numbers_idx < numbers_len)) {
                 number_ptr = numbers + numbers_idx;
                 *number_ptr = 1; // default value
             } else {
                 number_ptr = NULL;
             }
+            numbers_idx++;
         } else {
             number_ptr = NULL;
         }
@@ -548,7 +548,7 @@
         if (c1 != c2) {
             return c1 - c2;
         }
-        if (c1 == '\0') {        /* Lutz Hoerl, Thorlabs: think this (c1 = '\0') was really a bug */
+        if (c1 == '\0') {
             return 0;
         }
     }

--
Gitblit v1.9.1