script_params_ini_val_get()
Description
Helper function which searches the supplied script parameters buffer for a specific key in an INI-style format (key = value) and copies the value associated with that key into the output array. The search uses a word-boundary aware match to avoid false hits on keys that are substrings of other keys (for example, finding "id" inside "can_id").
The returned value is trimmed of leading spaces and tabs after the '=' sign and terminates at the first newline or end-of-string.
Syntax
script_params_ini_val_get(script_settings[], key[], bool:case_sensitive, store_value[]);
Parameters
Variable | Input |
script_settings[] | Input buffer containing the raw script parameters string (typically populated by script_params_read()). |
key[] | Null-terminated string with the name of the key to look up (e.g. "can_id"). |
case_sensitive | Match mode for the key lookup. true performs a case-sensitive search, false ignores case. |
store_value[] | Output array where the extracted value will be copied. Should be large enough to hold the value string. |
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | Success. The value for the requested key has been copied to store_value. |
-1 | Failed. The key was not found in script_settings, or no '=' separator was found after the key. |
Function call example
Reading a single key from script parameters
#include <io>
#include <read>
#include <float>
#include <string>
#include <core>
#include <write>
#include <define>
#include <socket>
#include <debug>
#include <script_parameters>
#define INI_FILE_SIZE 500
#define RS232_SPEED 115200
#define WORD_LENGTH WORDLENGTH_8
#define STOP_BITS STOPBITS_1
#define PARITY PARITY_NONE
new ini_file[INI_FILE_SIZE];
main()
{
new ret_val;
Init(RS232, RS232_SPEED, WORD_LENGTH, STOP_BITS, PARITY);
debug_init(RS232);
write_buf(RS232, 16, "Script started\r\n");
ret_val = script_params_read(ini_file);
if (ret_val != SCRIPT_OPERATION_SUCCESS)
{
debug_print("Failed to read script parameters\r\n");
return;
}
new value[32];
ret_val = script_params_ini_val_get(ini_file, "can_id", true, value);
if (ret_val == SCRIPT_OPERATION_SUCCESS)
{
debug_print("can_id = ");
debug_print(value);
debug_print("\r\n");
}
else
{
debug_print("Key not found\r\n");
}
for(;;)
{
Delay(1000);
}
}Notes and Warnings
The function expects INI-style content of the form key = value separated by newlines (\n). Each entry must reside on its own line.
Whitespace (spaces and tabs) immediately after the '=' is skipped. The value ends at the first '\n' or null terminator — trailing whitespace before the newline is preserved.
The key match is word-boundary aware: it only succeeds when no printable character (> 0x20) sits directly before or after the key, except for '=' on the right side. This prevents partial-key collisions, for example searching for "id" will not match "can_id".
If multiple lines define the same key, the first one in the buffer wins.
Make sure store_value is large enough — values longer than the buffer will be truncated.
#include <script_parameters> must be added in order to use this function.