Skip to content

Commit

Permalink
[sscanf] use rt_sscanf to replace sscanf
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterywolf committed Nov 26, 2024
1 parent d025072 commit 07d78e7
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions bsp/allwinner/libraries/libos/src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int32_t esCFG_GetGPIOSecKeyCount(char *GPIOSecName)
{
return hal_spi_gpio_cfg_count(GPIOSecName);
}
else if (sscanf(GPIOSecName, "twi%d", &id) == 1)
else if (rt_sscanf(GPIOSecName, "twi%d", &id) == 1)
{
return 2;
}
Expand Down Expand Up @@ -308,11 +308,11 @@ int32_t esCFG_GetGPIOSecData(char *GPIOSecName, void *pGPIOCfg, int32_t GPIONum)
gpio_cfg++;
}
}
else if (sscanf(GPIOSecName, "spi%d", &id) == 1)
else if (rt_sscanf(GPIOSecName, "spi%d", &id) == 1)
{
return hal_spi_gpio_cfg_load(gpio_cfg, GPIONum, id);
}
else if (sscanf(GPIOSecName, "twi%d", &id) == 1)
else if (rt_sscanf(GPIOSecName, "twi%d", &id) == 1)
{
extern int hal_i2c_gpio_cfg_load(user_gpio_set_t *gpio_cfg, int32_t GPIONum, int id);
return hal_i2c_gpio_cfg_load(gpio_cfg, GPIONum, id);
Expand Down
8 changes: 4 additions & 4 deletions bsp/nuvoton/libraries/m460/rtt_port/drv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ void devmem(int argc, char *argv[])

if (argc == 3)
{
if (sscanf(argv[2], "0x%x", &value) != 1)
if (rt_sscanf(argv[2], "0x%x", &value) != 1)
goto exit_devmem;
mode = 1; /*Write*/
}

if (sscanf(argv[1], "0x%x", &u32Addr) != 1)
if (rt_sscanf(argv[1], "0x%x", &u32Addr) != 1)
goto exit_devmem;
else if (!u32Addr || u32Addr & (4 - 1))
goto exit_devmem;
Expand Down Expand Up @@ -203,12 +203,12 @@ void devmem2(int argc, char *argv[])

if (argc == 3)
{
if (sscanf(argv[2], "%u", &value) != 1)
if (rt_sscanf(argv[2], "%u", &value) != 1)
goto exit_devmem;
word_count = value;
}

if (sscanf(argv[1], "0x%x", &u32Addr) != 1)
if (rt_sscanf(argv[1], "0x%x", &u32Addr) != 1)
goto exit_devmem;
else if (!u32Addr || u32Addr & (4 - 1))
goto exit_devmem;
Expand Down
4 changes: 2 additions & 2 deletions bsp/nuvoton/libraries/ma35/rtt_port/drv_disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static rt_err_t lcd_set_overlay_colkey(int argc, char **argv)

for (index = 0; index < (len - 1); index ++)
{
if (sscanf(argv[index + 1], "%x", &arg[index]) != 1)
if (rt_sscanf(argv[index + 1], "%x", &arg[index]) != 1)
return -1;
}
rt_kprintf("colkeylow:0x%08x colkeyhigh:0x%08x\n", arg[0], arg[1]);
Expand Down Expand Up @@ -459,7 +459,7 @@ static rt_err_t lcd_set_alphablend_opmode(int argc, char **argv)

for (index = 0; index < (len - 1); index ++)
{
if (sscanf(argv[index + 1], "%x", &arg[index]) != 1)
if (rt_sscanf(argv[index + 1], "%x", &arg[index]) != 1)
return -1;
}

Expand Down
8 changes: 4 additions & 4 deletions bsp/nuvoton/libraries/ma35/rtt_port/drv_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ void devmem(int argc, char *argv[])

if (argc == 3)
{
if (sscanf(argv[2], "0x%x", &value) != 1)
if (rt_sscanf(argv[2], "0x%x", &value) != 1)
goto exit_devmem;
mode = 1; //Write
}

if (sscanf(argv[1], "0x%x", &u32Addr) != 1)
if (rt_sscanf(argv[1], "0x%x", &u32Addr) != 1)
goto exit_devmem;
else if (u32Addr & (4 - 1))
goto exit_devmem;
Expand Down Expand Up @@ -343,12 +343,12 @@ void devmem2(int argc, char *argv[])

if (argc == 3)
{
if (sscanf(argv[2], "%d", &value) != 1)
if (rt_sscanf(argv[2], "%d", &value) != 1)
goto exit_devmem;
word_count = value;
}

if (sscanf(argv[1], "0x%x", &u32Addr) != 1)
if (rt_sscanf(argv[1], "0x%x", &u32Addr) != 1)
goto exit_devmem;
else if (u32Addr & (4 - 1))
goto exit_devmem;
Expand Down
4 changes: 2 additions & 2 deletions bsp/nuvoton/libraries/n9h30/rtt_port/drv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ void devmem(int argc, char *argv[])

if (argc == 3)
{
if (sscanf(argv[2], "0x%x", &value) != 1)
if (rt_sscanf(argv[2], "0x%x", &value) != 1)
goto exit_devmem;
mode = 1; //Write
}

if (sscanf(argv[1], "0x%x", &u32Addr) != 1)
if (rt_sscanf(argv[1], "0x%x", &u32Addr) != 1)
goto exit_devmem;
else if (!u32Addr || u32Addr & (4 - 1))
goto exit_devmem;
Expand Down
4 changes: 2 additions & 2 deletions bsp/nuvoton/libraries/nu_packages/Demo/wormhole_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ void whc_devmem(int argc, char *argv[])

if (argc == 3)
{
if (sscanf(argv[2], "0x%x", &value) != 1)
if (rt_sscanf(argv[2], "0x%x", &value) != 1)
goto exit_devmem;
mode = 1; //Write
}

if (sscanf(argv[1], "0x%x", &u32Addr) != 1)
if (rt_sscanf(argv[1], "0x%x", &u32Addr) != 1)
goto exit_devmem;
else if (u32Addr & (4 - 1))
goto exit_devmem;
Expand Down
2 changes: 1 addition & 1 deletion components/drivers/phy/ofw.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ rt_err_t rt_ofw_get_phyid(struct rt_ofw_node *np,rt_uint32_t *id)
if (ret)
return ret;

ret = sscanf(phy_id,"ethernet-phy-id%4x.%4x",&upper, &lower);
ret = rt_sscanf(phy_id,"ethernet-phy-id%4x.%4x",&upper, &lower);
if(ret != 2)
return -RT_ERROR;

Expand Down
4 changes: 2 additions & 2 deletions components/net/at/at_socket/at_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ static void at_connect_notice_cb(struct at_socket *sock, at_socket_evt_t event,
}
new_sock = at_get_socket(new_socket);
new_sock->state = AT_SOCKET_CONNECT;
sscanf(buff, "SOCKET:%d", &base_socket);
rt_sscanf(buff, "SOCKET:%d", &base_socket);
LOG_D("ACCEPT BASE SOCKET: %d", base_socket);
new_sock->user_data = (void *)base_socket;

Expand Down Expand Up @@ -985,7 +985,7 @@ int at_accept(int socket, struct sockaddr *name, socklen_t *namelen)
at_do_event_changes(sock, AT_EVENT_RECV, RT_FALSE);
}

sscanf(&receive_buff[0], "SOCKET:%d", &new_socket);
rt_sscanf(&receive_buff[0], "SOCKET:%d", &new_socket);
new_sock = at_get_socket(new_socket);
ip4_addr_set_any(&remote_addr);
ipaddr_port_to_socketaddr(name, &remote_addr, &remote_port);
Expand Down
8 changes: 4 additions & 4 deletions documentation/at/at.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ int at_req_parse_args(const char *req_args, const char *req_expr, ...);
Among the four functions of an AT command, only the setting function has an input parameter, and the input parameter is to remove the rest of the AT command. For example, for a given command input `"AT+TEST=1,2,3,4"`, set the input parameter of the function to the parameter string `"=1,2,3,4"`.
The command parsing function is mainly used in the AT function setting function, which is used to parse the incoming string parameter and obtain corresponding multiple input parameters for performing the following operations. The standard `sscanf` parsing grammar used in parsing grammar here will also be described in detail later in the AT Client parameter parsing function.
The command parsing function is mainly used in the AT function setting function, which is used to parse the incoming string parameter and obtain corresponding multiple input parameters for performing the following operations. The standard `rt_sscanf` parsing grammar used in parsing grammar here will also be described in detail later in the AT Client parameter parsing function.
| **Parameter** | **Description** |
|---------|-----------------------------------------------|
Expand Down Expand Up @@ -537,7 +537,7 @@ The implementation principle of sending and receiving data is relatively simple.
### AT Client Data Parsing Method ###
After the data is normally acquired, the response data needs to be parsed, which is one of the important functions of the AT Client. Parsing of data in the AT Client provides a parsed form of a custom parsing expression whose parsing syntax uses the standard `sscanf` parsing syntax. Developers can use the custom data parsing expression to respond to useful information in the data, provided that the developer needs to review the relevant manual in advance to understand the basic format of the AT Server device response data that the AT Client connects to. The following is a simple AT Client data parsing method through several functions and routines.
After the data is normally acquired, the response data needs to be parsed, which is one of the important functions of the AT Client. Parsing of data in the AT Client provides a parsed form of a custom parsing expression whose parsing syntax uses the standard `rt_sscanf` parsing syntax. Developers can use the custom data parsing expression to respond to useful information in the data, provided that the developer needs to review the relevant manual in advance to understand the basic format of the AT Server device response data that the AT Client connects to. The following is a simple AT Client data parsing method through several functions and routines.
#### Get Response Data for the Specified Line Number
Expand Down Expand Up @@ -609,7 +609,7 @@ int at_resp_parse_line_args_by_kw(at_response_t resp, const char *keyword, const
This function is used to get a row of data containing a keyword in the AT Server response data and parse the parameters in the row data.
The data parsing syntax uses the standard `sscanf` syntax, the content of the syntax is more, developers can search their parsing syntax, here two procedures are used to introduce the simple use method.
The data parsing syntax uses the standard `rt_sscanf` syntax, the content of the syntax is more, developers can search their parsing syntax, here two procedures are used to introduce the simple use method.
#### Serial Port Configuration Information Analysis Example
Expand Down Expand Up @@ -676,7 +676,7 @@ printf("IP=%s, MAC=%s\n", ip, mac);
at_delete_resp(resp);
```
The key to parsing data is to correctly define the expression. Because the response data of the different device manufacturers is not unique to the response data of the AT device, only the form of the custom parsing expression can be obtained to obtain the required information. The design of the `at_resp_parse_line_args` parsing parameter function is based on the `sscanf` data parsing method. Before using it, the developer needs to understand the basic parsing syntax and then design the appropriate parsing syntax in combination with the response data. If the developer does not need to parse the specific parameters, you can use the `at_resp_get_line` function to get the specific data of a row.
The key to parsing data is to correctly define the expression. Because the response data of the different device manufacturers is not unique to the response data of the AT device, only the form of the custom parsing expression can be obtained to obtain the required information. The design of the `at_resp_parse_line_args` parsing parameter function is based on the `rt_sscanf` data parsing method. Before using it, the developer needs to understand the basic parsing syntax and then design the appropriate parsing syntax in combination with the response data. If the developer does not need to parse the specific parameters, you can use the `at_resp_get_line` function to get the specific data of a row.
### AT Client URC Data Processing ###
Expand Down
2 changes: 1 addition & 1 deletion examples/test/avl.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ int main(int argc, char *argv[])
{
if (argc == 2)
{
sscanf(argv[1], "%d", &loop_count);
rt_sscanf(argv[1], "%d", &loop_count);
}
else
{
Expand Down

0 comments on commit 07d78e7

Please sign in to comment.