rtl433  UNKNOWN
RTL-433 utility
optparse.c File Reference

Option parsing functions to complement getopt. More...

Functions

int atobv (char *arg, int def)
 Convert string to bool with fallback default. More...
 
int atoiv (char *arg, int def)
 Convert string to int with fallback default. More...
 
char * arg_param (char *arg)
 Get the next colon or comma separated arg, NULL otherwise. More...
 
char * hostport_param (char *param, char **host, char **port)
 Parse param string to host and port. More...
 
uint32_t atouint32_metric (const char *str, const char *error_hint)
 Convert a string to an unsigned integer, uses strtod() and accepts metric suffixes of 'k', 'M', and 'G' (also 'K', 'm', and 'g'). More...
 
int atoi_time (const char *str, const char *error_hint)
 Convert a string to an integer, uses strtod() and accepts time suffixes of 'd', 'h', 'm', and 's' (also 'D', 'H', 'M', and 'S'), or the form hours:minutes[:seconds]. More...
 
char * asepc (char **stringp, char delim)
 Similar to strsep. More...
 
char * getkwargs (char **s, char **key, char **val)
 Parse a comma-separated list of key/value pairs into kwargs. More...
 
char * trim_ws (char *str)
 Trim left and right whitespace in string. More...
 
char * remove_ws (char *str)
 Remove all whitespace from string. More...
 
int main (int argc, char **argv)
 

Detailed Description

Option parsing functions to complement getopt.

Copyright (C) 2017 Christian Zuckschwerdt

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Function Documentation

◆ arg_param()

char* arg_param ( char *  arg)

Get the next colon or comma separated arg, NULL otherwise.

Returns string including comma if a comma is found first, otherwise string after colon if found, NULL otherwise.

Referenced by parse_conf_option(), and rtltcp_open().

◆ asepc()

char* asepc ( char **  stringp,
char  delim 
)

Similar to strsep.

Parameters
[in,out]stringp
delimthe delimiter character
Returns
the original value of *stringp

Referenced by getkwargs().

◆ atobv()

int atobv ( char *  arg,
int  def 
)

Convert string to bool with fallback default.

Parses "true", "yes", "on", "enable" (not case-sensitive) to 1, atoi() otherwise.

Referenced by data_output_mqtt_create(), and parse_conf_option().

◆ atoi_time()

int atoi_time ( const char *  str,
const char *  error_hint 
)

Convert a string to an integer, uses strtod() and accepts time suffixes of 'd', 'h', 'm', and 's' (also 'D', 'H', 'M', and 'S'), or the form hours:minutes[:seconds].

Parse errors will fprintf(stderr, ...) and exit(1).

Parameters
strcharacter string to parse
error_hintprepended to error output
Returns
parsed number value

Referenced by main(), and parse_conf_option().

◆ atoiv()

int atoiv ( char *  arg,
int  def 
)

Convert string to int with fallback default.

Referenced by parse_conf_option().

◆ atouint32_metric()

uint32_t atouint32_metric ( const char *  str,
const char *  error_hint 
)

Convert a string to an unsigned integer, uses strtod() and accepts metric suffixes of 'k', 'M', and 'G' (also 'K', 'm', and 'g').

Parse errors will fprintf(stderr, ...) and exit(1).

Parameters
strcharacter string to parse
error_hintprepended to error output
Returns
parsed number value

Referenced by main(), parse_conf_option(), and sdr_apply_settings().

◆ getkwargs()

char* getkwargs ( char **  s,
char **  key,
char **  val 
)

Parse a comma-separated list of key/value pairs into kwargs.

The input string will be modified and the pointer advanced. The key and val pointers will be into the original string.

Parameters
[in,out]sString of key=value pairs, separated by commas
[out]keykeyword argument if found, NULL otherwise
[out]valvalue if found, NULL otherwise
Returns
the original value of *stringp (the keyword found)

References asepc().

Referenced by data_output_mqtt_create(), flex_create_device(), and soapysdr_gain_str_set().

◆ hostport_param()

char* hostport_param ( char *  param,
char **  host,
char **  port 
)

Parse param string to host and port.

E.g. ":514", "localhost", "[::1]", "127.0.0.1:514", "[::1]:514", also "//localhost", "//localhost:514", "//:514". Host or port are terminated at a comma, if found.

Returns
the remaining options

Referenced by add_mqtt_output(), add_syslog_output(), and rtltcp_open().

◆ main()

int main ( int  argc,
char **  argv 
)

References atoi_time(), and atouint32_metric().

◆ remove_ws()

char* remove_ws ( char *  str)

Remove all whitespace from string.

Parameters
[in,out]str
Returns
the stripped value of str

Referenced by data_output_mqtt_create(), and flex_create_device().

◆ trim_ws()

char* trim_ws ( char *  str)

Trim left and right whitespace in string.

Parameters
[in,out]str
Returns
the trimmed value of str

Referenced by data_output_mqtt_create(), and flex_create_device().