Skip to content

Commit

Permalink
Toolbox: couple small comments in the code and doxygen comment update…
Browse files Browse the repository at this point in the history
…. SubGhz, Loader: fix strint usage.
  • Loading branch information
skotopes committed Sep 5, 2024
1 parent 2abec92 commit 2a4d840
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 35 deletions.
6 changes: 3 additions & 3 deletions applications/services/loader/loader_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ static void loader_cli_close(Loader* loader) {

static void loader_cli_signal(FuriString* args, Loader* loader) {
uint32_t signal;
void* arg = NULL;
uint32_t arg = 0;
StrintParseError parse_err = 0;
char* args_cstr = (char*)furi_string_get_cstr(args);
parse_err |= strint_to_uint32(args_cstr, &args_cstr, &signal, 10);
parse_err |= strint_to_uint32(args_cstr, &args_cstr, (uint32_t*)&arg, 16);
parse_err |= strint_to_uint32(args_cstr, &args_cstr, &arg, 16);

if(parse_err) {
printf("Signal must be a decimal number\r\n");
} else if(!loader_is_locked(loader)) {
printf("No application is running\r\n");
} else {
const bool is_handled = loader_signal(loader, signal, arg);
const bool is_handled = loader_signal(loader, signal, (void*)arg);
printf(
"Signal %lu with argument 0x%p was %s\r\n",
signal,
Expand Down
2 changes: 1 addition & 1 deletion lib/subghz/subghz_file_encoder_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool subghz_file_encoder_worker_data_parse(SubGhzFileEncoderWorker* instance, co

// Parse next element
int32_t duration;
while(strint_to_int32(str, (char**)&str, &duration, 10) == StrintParseNoError) {
while(strint_to_int32(str, &str, &duration, 10) == StrintParseNoError) {
subghz_file_encoder_worker_add_level_duration(instance, duration);
if(*str == ',') str++; // could also be `\0`
}
Expand Down
2 changes: 1 addition & 1 deletion lib/toolbox/strint.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ StrintParseError strint_to_uint64_internal(

if(abs_out) *abs_out = result;
if(negative_out) *negative_out = negative;
if(end) *end = (char*)str;
if(end) *end = (char*)str; // rabbit hole: https://c-faq.com/ansi/constmismatch.html
return StrintParseNoError;
}

Expand Down
48 changes: 18 additions & 30 deletions lib/toolbox/strint.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @file strint.h
*
* @brief Performs conversions between strings and integers.
* Performs conversions between strings and integers.
*/
#pragma once

Expand All @@ -13,68 +12,57 @@
extern "C" {
#endif

/**
* @brief String to integer conversion error
*/
/** String to integer conversion error */
typedef enum {
StrintParseNoError, //!< Conversion performed successfully
StrintParseSignError, //!< Multiple leading `+` or `-` characters, or leading `-` character if the type is unsigned
StrintParseAbsentError, //!< No valid digits after the leading whitespace, sign and prefix
StrintParseOverflowError, //!< Result does not fit in the requested type
} StrintParseError;

/**
* @brief See `strint_to_uint32`
*/
/** See `strint_to_uint32` */
StrintParseError strint_to_uint64(const char* str, char** end, uint64_t* out, uint8_t base);

/**
* @brief See `strint_to_uint32`
*/
/** See `strint_to_uint32` */
StrintParseError strint_to_int64(const char* str, char** end, int64_t* out, uint8_t base);

/**
* @brief Converts a string to a `uint32_t`
* @param [in] str Input string
* @param [out] end Pointer to first character after the number in input string
* @param [out] out Parse result
* @param [in] base Integer base
* @returns Parse error
*
/** Converts a string to a `uint32_t`
*
* @param[in] str Input string
* @param[out] end Pointer to first character after the number in input string
* @param[out] out Parse result
* @param[in] base Integer base
*
* @return Parse error
*
* Parses the number in the input string. The number may be surrounded by
* whitespace characters to the left and any non-digit characters to the right.
* What's considered a digit is determined by the input base in the following
* order: `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`. The number may be prefixed
* with either a `+` or a `-` to indicate its sign. The pointer to the first
* character after the leading whitespace, allowed prefixes and digits is
* assigned to `end`.
*
*
* If the input base is 0, the base is inferred from the leading characters of
* the number:
* - If it starts with `0x`, it's read in base 16;
* - If it starts with a `0`, it's read in base 8;
* - If it starts with `0b`, it's read in base 2.
* - Otherwise, it's read in base 10.
*
*
* For a description of the return codes, see `StrintParseError`. If the return
* code is something other than `StrintParseNoError`, the values at `end` and
* `out` are unaltered.
*/
StrintParseError strint_to_uint32(const char* str, char** end, uint32_t* out, uint8_t base);

/**
* @brief See `strint_to_uint32`
*/
/** See `strint_to_uint32` */
StrintParseError strint_to_int32(const char* str, char** end, int32_t* out, uint8_t base);

/**
* @brief See `strint_to_uint32`
*/
/** See `strint_to_uint32` */
StrintParseError strint_to_uint16(const char* str, char** end, uint16_t* out, uint8_t base);

/**
* @brief See `strint_to_uint32`
*/
/** See `strint_to_uint32` */
StrintParseError strint_to_int16(const char* str, char** end, int16_t* out, uint8_t base);

#ifdef __cplusplus
Expand Down

0 comments on commit 2a4d840

Please sign in to comment.