Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce SCPI_HelpQ with descriptions #135

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
28b17f7
output block data with delimiter
MisterHW Feb 1, 2022
8ed2623
fix typos
MisterHW Feb 2, 2022
bc4f1d5
introduce SCPI_HelpQ
MisterHW Feb 3, 2022
315f20d
introduce help search
MisterHW Feb 7, 2022
159fe83
drop C++20 keyword
MisterHW Feb 7, 2022
d099d9a
rename to USE_HELP_FILTER
MisterHW Feb 7, 2022
aa660db
fix expression
MisterHW Feb 7, 2022
1460793
add full command descriptions to examples common def, set desc. defau…
MisterHW Jan 6, 2023
7d0c83d
clean-up
MisterHW Jan 7, 2023
c394eb9
propagate MODE to Makefile for cross-compiling
MisterHW Jan 7, 2023
1e1b594
provide more elaborate description depending on USE_HELP_FILTER
MisterHW Jan 14, 2023
f7c4cc4
Merge branch 'j123b567:master' into scpi_helpq_enhancement
MisterHW Jan 16, 2023
b3668be
Merge branch 'j123b567:master' into scpi_helpq_enhancement
MisterHW Jan 17, 2023
36ddafe
strncasestr, strncasestrn_s, pp_xstr clean-up and formatting
MisterHW Jan 17, 2023
9c66dcd
fix C89 issue (FALSE, for syntax)
MisterHW Jan 17, 2023
0e7c828
remove strcasestr
MisterHW Jan 17, 2023
5dfac2b
strncasecmp -> SCPIDEFINE_strncasecmp
MisterHW Jan 17, 2023
5153e03
C style comments
MisterHW Jan 17, 2023
8aa90a7
split off HELP? into help.h/.c
MisterHW Jan 17, 2023
31a3e44
add help.c, help.h to Makefile
MisterHW Jan 17, 2023
d8a5d24
redo delete SCPI_HelpQ
MisterHW Jan 17, 2023
63f5e88
Revert "propagate MODE to Makefile for cross-compiling"
MisterHW Jan 17, 2023
d803ffe
simply SCPI_CMD_LIST_END definition
MisterHW Jan 17, 2023
a44b9aa
add missing ,
MisterHW Jan 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean-up
* fixes some inaccuracies in scpi-def
* clean-up in utils.c
* add documentation to introduced functions
* correct CHAR_TO_LOWER
  • Loading branch information
MisterHW committed Jan 7, 2023
commit 7d0c83d7c5f7fdaf3ead0aae947a0c0b2823aeb5
30 changes: 15 additions & 15 deletions examples/common/scpi-def.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,38 +364,38 @@ const scpi_command_t scpi_commands[] = {
/* IEEE Mandated Commands (SCPI std V1999.0 4.1.1): *CLS *ESE *ESE? *ESR? *IDN? *OPC *OPC? *RST *SRE *SRE? *STB? *TST? *WAI */
{"*CLS", SCPI_CoreCls, SCPI_CMD_DESC("\t - clear all Event Status registers, errors, output queue") SCPI_CMD_TAG(0)},
// -- Standard Event Status Group [EVENT]-[ENABLE]
{"*ESE", SCPI_CoreEse, SCPI_CMD_DESC("<0..255> - set Standard Event Status Enable (event mask)") SCPI_CMD_TAG(0)},
{"*ESE", SCPI_CoreEse, SCPI_CMD_DESC("<0..255> - set Standard Event Status Enable / event mask") SCPI_CMD_TAG(0)},
{"*ESE?", SCPI_CoreEseQ, SCPI_CMD_DESC("\t - read ESE (0..255)") SCPI_CMD_TAG(0)},
{"*ESR?", SCPI_CoreEsrQ, SCPI_CMD_DESC("\t - read+clear Standard Event Status register") SCPI_CMD_TAG(0)},
{"*ESR?", SCPI_CoreEsrQ, SCPI_CMD_DESC("\t - read+clear Standard Event Status register (0..255)") SCPI_CMD_TAG(0)},
// -- IEEE Mandated Commands (continued ...)
{"*IDN?", SCPI_CoreIdnQ, SCPI_CMD_DESC("\t - read device identifier (multi-line string)") SCPI_CMD_TAG(0)},
{"*IDN?", SCPI_CoreIdnQ, SCPI_CMD_DESC("\t - read device identifier (str,str,str,str)") SCPI_CMD_TAG(0)},
{"*OPC", SCPI_CoreOpc, SCPI_CMD_DESC("\t - complete ops preceding Operation Complete Command, set ESR.OPC 1") SCPI_CMD_TAG(0)},
{"*OPC?", SCPI_CoreOpcQ, SCPI_CMD_DESC("\t - read ESR.OPC (0:ongoing ops, 1:done)") SCPI_CMD_TAG(0)},
{"*OPC?", SCPI_CoreOpcQ, SCPI_CMD_DESC("\t - read ESR.OPC (0:ongoing-ops 1:done)") SCPI_CMD_TAG(0)},
{"*RST", SCPI_CoreRst, SCPI_CMD_DESC("\t - reset instrument and interface") SCPI_CMD_TAG(0)},
{"*SRE", SCPI_CoreSre, SCPI_CMD_DESC("<0..255> - set Service Request Enable (event mask over STB)") SCPI_CMD_TAG(0)},
{"*SRE", SCPI_CoreSre, SCPI_CMD_DESC("<0..255> - set Service Request Enable / event mask over STB") SCPI_CMD_TAG(0)},
{"*SRE?", SCPI_CoreSreQ, SCPI_CMD_DESC("\t - read SRE (0..255)") SCPI_CMD_TAG(0)},
{"*STB?", SCPI_CoreStbQ, SCPI_CMD_DESC("\t - read STatus Byte (0..255)") SCPI_CMD_TAG(0)},
{"*TST?", My_CoreTstQ, SCPI_CMD_DESC("\t - read self-test result (0:no failures)") SCPI_CMD_TAG(0)},
{"*TST?", My_CoreTstQ, SCPI_CMD_DESC("\t - read self-test result (0:no-failures)") SCPI_CMD_TAG(0)},
{"*WAI", SCPI_CoreWai, SCPI_CMD_DESC("\t - halt cmd execution until pending operations complete") SCPI_CMD_TAG(0)},

/* Required SCPI commands (SCPI std V1999.0 4.2.1) : SYSTem:ERRor, STATus:OPERation, STATus:QUEStionable and STATus:PRESet */
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, SCPI_CMD_DESC("\t - get next error in queue (int error,string)") SCPI_CMD_TAG(0)},
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, SCPI_CMD_DESC("\t - get next error in queue (int-errno,str)") SCPI_CMD_TAG(0)},
{"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, SCPI_CMD_DESC("\t - queued error count (0.." SCPI_ERROR_QUEUE_SIZE_STR ")") SCPI_CMD_TAG(0)},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, SCPI_CMD_DESC("\t - query system version (version expr)") SCPI_CMD_TAG(0)},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, SCPI_CMD_DESC("\t - query system version (str)") SCPI_CMD_TAG(0)},
// -- Operation Status Group [CONDITION]-[EVENT]-[ENABLE]
{"STATus:OPERation:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation[:EVENt]?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle", SCPI_Stub, SCPI_CMD_DESC("\t - not implemented") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
// -- Questionable Status Group [CONDITION]-[EVENT]-[ENABLE]
{"STATus:QUEStionable:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented") SCPI_CMD_TAG(0)}, // "\t - read momentary Questionable Condition register (0..65535)"
{"STATus:QUEStionable:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)}, // "\t - read momentary Questionable Condition register (0..65535)"
{"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, SCPI_CMD_DESC("\t - read Questionable Event register (0..65535)") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, SCPI_CMD_DESC("<0..65535> - set Questionable Enable (event mask)") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, SCPI_CMD_DESC("<0..65535> - set Questionable Enable / event mask") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, SCPI_CMD_DESC("\t - Questionable Status Enable (0..65535)") SCPI_CMD_TAG(0)},
{"STATus:PRESet", SCPI_StatusPreset, SCPI_CMD_DESC("\t - load Status sub-system register defaults") SCPI_CMD_TAG(0)},

/* commands specific to DMM example with TEST sub-system */
{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, SCPI_CMD_DESC("\t - read TCPIP control port") SCPI_CMD_TAG(0)},
{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, SCPI_CMD_DESC("\t - read TCPIP control port (int)") SCPI_CMD_TAG(0)},
{"CONFigure:VOLTage:DC", DMM_ConfigureVoltageDc, SCPI_CMD_DESC("<float>[,<float>] - test command") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC?", DMM_MeasureVoltageDcQ, SCPI_CMD_DESC("[<float>[,<float>]] - test command (0)") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC:RATio?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
Expand All @@ -407,9 +407,9 @@ const scpi_command_t scpi_commands[] = {
{"MEASure:FREQuency?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:PERiod?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"TEST:BOOL", TEST_Bool, SCPI_CMD_DESC("<bool> - test command") SCPI_CMD_TAG(0)},
{"TEST:CHOice?", TEST_ChoiceQ, SCPI_CMD_DESC("<choice> - test command (\"BUS\":5,\"IMMediate\":6,\"EXTernal\",7)") SCPI_CMD_TAG(0)},
{"TEST#:NUMbers#", TEST_Numbers, SCPI_CMD_DESC("\t - test command with numbers - default 1") SCPI_CMD_TAG(0)},
{"TEST:TEXT", TEST_Text, SCPI_CMD_DESC("<param>[, ...] - debug print <param> as received") SCPI_CMD_TAG(0)},
{"TEST:CHOice?", TEST_ChoiceQ, SCPI_CMD_DESC("<choice> - test command (\"BUS\":5 \"IMMediate\":6 \"EXTernal\":7)") SCPI_CMD_TAG(0)},
{"TEST#:NUMbers#", TEST_Numbers, SCPI_CMD_DESC("\t - test command with optional numbers - default 1") SCPI_CMD_TAG(0)},
{"TEST:TEXT", TEST_Text, SCPI_CMD_DESC("<param>[, ...] - debug print param as received") SCPI_CMD_TAG(0)},
{"TEST:ARBitrary?", TEST_ArbQ, SCPI_CMD_DESC("<block data> - receive and return block data (block data)") SCPI_CMD_TAG(0)},
{"TEST:CHANnellist", TEST_Chanlst, SCPI_CMD_DESC("<channel_list> - test channel list parsing") SCPI_CMD_TAG(0)},

Expand Down
30 changes: 15 additions & 15 deletions examples/common/scpi-def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,38 +364,38 @@ const scpi_command_t scpi_commands[] = {
/* IEEE Mandated Commands (SCPI std V1999.0 4.1.1): *CLS *ESE *ESE? *ESR? *IDN? *OPC *OPC? *RST *SRE *SRE? *STB? *TST? *WAI */
{"*CLS", SCPI_CoreCls, SCPI_CMD_DESC("\t - clear all Event Status registers, errors, output queue") SCPI_CMD_TAG(0)},
MisterHW marked this conversation as resolved.
Show resolved Hide resolved
// -- Standard Event Status Group [EVENT]-[ENABLE]
{"*ESE", SCPI_CoreEse, SCPI_CMD_DESC("<0..255> - set Standard Event Status Enable (event mask)") SCPI_CMD_TAG(0)},
{"*ESE", SCPI_CoreEse, SCPI_CMD_DESC("<0..255> - set Standard Event Status Enable / event mask") SCPI_CMD_TAG(0)},
{"*ESE?", SCPI_CoreEseQ, SCPI_CMD_DESC("\t - read ESE (0..255)") SCPI_CMD_TAG(0)},
{"*ESR?", SCPI_CoreEsrQ, SCPI_CMD_DESC("\t - read+clear Standard Event Status register") SCPI_CMD_TAG(0)},
{"*ESR?", SCPI_CoreEsrQ, SCPI_CMD_DESC("\t - read+clear Standard Event Status register (0..255)") SCPI_CMD_TAG(0)},
// -- IEEE Mandated Commands (continued ...)
{"*IDN?", SCPI_CoreIdnQ, SCPI_CMD_DESC("\t - read device identifier (multi-line string)") SCPI_CMD_TAG(0)},
{"*IDN?", SCPI_CoreIdnQ, SCPI_CMD_DESC("\t - read device identifier (str,str,str,str)") SCPI_CMD_TAG(0)},
{"*OPC", SCPI_CoreOpc, SCPI_CMD_DESC("\t - complete ops preceding Operation Complete Command, set ESR.OPC 1") SCPI_CMD_TAG(0)},
{"*OPC?", SCPI_CoreOpcQ, SCPI_CMD_DESC("\t - read ESR.OPC (0:ongoing ops, 1:done)") SCPI_CMD_TAG(0)},
{"*OPC?", SCPI_CoreOpcQ, SCPI_CMD_DESC("\t - read ESR.OPC (0:ongoing-ops 1:done)") SCPI_CMD_TAG(0)},
{"*RST", SCPI_CoreRst, SCPI_CMD_DESC("\t - reset instrument and interface") SCPI_CMD_TAG(0)},
{"*SRE", SCPI_CoreSre, SCPI_CMD_DESC("<0..255> - set Service Request Enable (event mask over STB)") SCPI_CMD_TAG(0)},
{"*SRE", SCPI_CoreSre, SCPI_CMD_DESC("<0..255> - set Service Request Enable / event mask over STB") SCPI_CMD_TAG(0)},
{"*SRE?", SCPI_CoreSreQ, SCPI_CMD_DESC("\t - read SRE (0..255)") SCPI_CMD_TAG(0)},
{"*STB?", SCPI_CoreStbQ, SCPI_CMD_DESC("\t - read STatus Byte (0..255)") SCPI_CMD_TAG(0)},
{"*TST?", My_CoreTstQ, SCPI_CMD_DESC("\t - read self-test result (0:no failures)") SCPI_CMD_TAG(0)},
{"*TST?", My_CoreTstQ, SCPI_CMD_DESC("\t - read self-test result (0:no-failures)") SCPI_CMD_TAG(0)},
{"*WAI", SCPI_CoreWai, SCPI_CMD_DESC("\t - halt cmd execution until pending operations complete") SCPI_CMD_TAG(0)},

/* Required SCPI commands (SCPI std V1999.0 4.2.1) : SYSTem:ERRor, STATus:OPERation, STATus:QUEStionable and STATus:PRESet */
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, SCPI_CMD_DESC("\t - get next error in queue (int error,string)") SCPI_CMD_TAG(0)},
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, SCPI_CMD_DESC("\t - get next error in queue (int-errno,str)") SCPI_CMD_TAG(0)},
{"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, SCPI_CMD_DESC("\t - queued error count (0.." SCPI_ERROR_QUEUE_SIZE_STR ")") SCPI_CMD_TAG(0)},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, SCPI_CMD_DESC("\t - query system version (version expr)") SCPI_CMD_TAG(0)},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, SCPI_CMD_DESC("\t - query system version (str)") SCPI_CMD_TAG(0)},
// -- Operation Status Group [CONDITION]-[EVENT]-[ENABLE]
{"STATus:OPERation:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation[:EVENt]?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle", SCPI_Stub, SCPI_CMD_DESC("\t - not implemented") SCPI_CMD_TAG(0)},
{"STATus:OPERation:ENABle?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
// -- Questionable Status Group [CONDITION]-[EVENT]-[ENABLE]
{"STATus:QUEStionable:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented") SCPI_CMD_TAG(0)}, // "\t - read momentary Questionable Condition register (0..65535)"
{"STATus:QUEStionable:CONDition?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)}, // "\t - read momentary Questionable Condition register (0..65535)"
{"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, SCPI_CMD_DESC("\t - read Questionable Event register (0..65535)") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, SCPI_CMD_DESC("<0..65535> - set Questionable Enable (event mask)") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, SCPI_CMD_DESC("<0..65535> - set Questionable Enable / event mask") SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, SCPI_CMD_DESC("\t - Questionable Status Enable (0..65535)") SCPI_CMD_TAG(0)},
{"STATus:PRESet", SCPI_StatusPreset, SCPI_CMD_DESC("\t - load Status sub-system register defaults") SCPI_CMD_TAG(0)},

/* commands specific to DMM example with TEST sub-system */
{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, SCPI_CMD_DESC("\t - read TCPIP control port") SCPI_CMD_TAG(0)},
{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, SCPI_CMD_DESC("\t - read TCPIP control port (int)") SCPI_CMD_TAG(0)},
{"CONFigure:VOLTage:DC", DMM_ConfigureVoltageDc, SCPI_CMD_DESC("<float>[,<float>] - test command") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC?", DMM_MeasureVoltageDcQ, SCPI_CMD_DESC("[<float>[,<float>]] - test command (0)") SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC:RATio?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
Expand All @@ -407,9 +407,9 @@ const scpi_command_t scpi_commands[] = {
{"MEASure:FREQuency?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"MEASure:PERiod?", SCPI_StubQ, SCPI_CMD_DESC("\t - not implemented (0)") SCPI_CMD_TAG(0)},
{"TEST:BOOL", TEST_Bool, SCPI_CMD_DESC("<bool> - test command") SCPI_CMD_TAG(0)},
{"TEST:CHOice?", TEST_ChoiceQ, SCPI_CMD_DESC("<choice> - test command (\"BUS\":5,\"IMMediate\":6,\"EXTernal\",7)") SCPI_CMD_TAG(0)},
{"TEST#:NUMbers#", TEST_Numbers, SCPI_CMD_DESC("\t - test command with numbers - default 1") SCPI_CMD_TAG(0)},
{"TEST:TEXT", TEST_Text, SCPI_CMD_DESC("<param>[, ...] - debug print <param> as received") SCPI_CMD_TAG(0)},
{"TEST:CHOice?", TEST_ChoiceQ, SCPI_CMD_DESC("<choice> - test command (\"BUS\":5 \"IMMediate\":6 \"EXTernal\":7)") SCPI_CMD_TAG(0)},
{"TEST#:NUMbers#", TEST_Numbers, SCPI_CMD_DESC("\t - test command with optional numbers - default 1") SCPI_CMD_TAG(0)},
{"TEST:TEXT", TEST_Text, SCPI_CMD_DESC("<param>[, ...] - debug print param as received") SCPI_CMD_TAG(0)},
{"TEST:ARBitrary?", TEST_ArbQ, SCPI_CMD_DESC("<block data> - receive and return block data (block data)") SCPI_CMD_TAG(0)},
{"TEST:CHANnellist", TEST_Chanlst, SCPI_CMD_DESC("<channel_list> - test channel list parsing") SCPI_CMD_TAG(0)},

Expand Down
53 changes: 23 additions & 30 deletions libscpi/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,53 +1140,39 @@ uint64_t SCPI_Swap64(uint64_t val) {
((val & 0x00FF000000000000ull) >> 40) |
((val & 0xFF00000000000000ull) >> 56);
}


/* Cherokee: strncasestrn() and strncasestr()
*
* Authors:
* Alvaro Lopez Ortega <alvaro@alobbs.com>
*
* Copyright (C) 2001-2014 Alvaro Lopez Ortega
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

#define CHEROKEE_CHAR_TO_LOWER(_ch) ((_ch) | 32)
#define CHEROKEE_CHAR_TO_UPPER(_ch) ((_ch) & ~32)
#define CHAR_TO_UPPER(c) ((c)>96 && (c)<123 ? (char)((c) ^ 0x20) : (c))
#define CHAR_TO_LOWER(c) ((c)>64 && (c)< 91 ? (char)((c) | 0x20) : (c))

/**
* @brief Locate a binary substring within a binary string (case-insensitive `strnstrn`).
* @param[in] s binary string
* @param[in] slen length of binary string s
* @param[in] find binary substring
* @param[in] findlen length of binary substring find
* @return Pointer to first match in s if found, otherwise `NULL`.
* @author Alvaro Lopez Ortega <alvaro@alobbs.com>
*/
char * strncasestrn (const char *s, size_t slen, const char *find, size_t findlen)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide unit test in test_scpi_utils.c

{
char c;
char sc;
char first;
char cursor_chr;

if ((find == NULL) || (findlen == 0))
return (char *)s;

if ((*find == '\0'))
return (char *)s;

c = *find;
first = CHAR_TO_LOWER(*find);
find++;
findlen--;

do {
do {
if (slen-- < 1 || (sc = *s++) == '\0')
if (slen-- < 1 || (cursor_chr = *s++) == '\0')
return NULL;
} while (CHEROKEE_CHAR_TO_LOWER(sc) != CHEROKEE_CHAR_TO_LOWER(c));
} while (CHAR_TO_LOWER(cursor_chr) != first);
if (findlen > slen) {
return NULL;
}
Expand All @@ -1196,6 +1182,13 @@ char * strncasestrn (const char *s, size_t slen, const char *find, size_t findle
return (char *)s;
}

/**
* @brief Locate a substring in a binary string (case-insensitive `strnstr`).
* @param[in] s binary string
* @param[in] find substring (zero-terminated)
* @param[in] slen length of binary string s
* @return Pointer to first match in s if found, otherwise `NULL`.
*/
char * strncasestr (const char *s, const char *find, size_t slen)
MisterHW marked this conversation as resolved.
Show resolved Hide resolved
{
return strncasestrn (s, slen, find, strlen(find));
Expand Down