Dunst
Lightweight notification daemon
Loading...
Searching...
No Matches
option_parser.c File Reference
#include "option_parser.h"
#include <glib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "dunst.h"
#include "log.h"
#include "utils.h"
#include "settings.h"
#include "rules.h"
#include "settings_data.h"
+ Include dependency graph for option_parser.c:

Go to the source code of this file.

Macros

#define STRING_PARSE_RET(string, value)
 
#define UINT_MAX_N(bits)
 

Functions

int string_parse_enum (const void *data, const char *s, void *ret)
 
int string_parse_enum_list (const void *data, char **s, void *ret_void)
 
int string_parse_enum_list_to_single (const void *data, char **s, int *ret)
 Parse a string list of enum values and return a single integer with the values bit-flipped into it.
 
int string_parse_corners (const void *data, const char *s, void *ret)
 
bool string_parse_int_list (char **s, int **ret, bool allow_empty)
 Parse a list of integers.
 
int string_parse_list (const void *data, const char *s, void *ret)
 
int string_parse_sepcolor (const void *data, const char *s, void *ret)
 
int string_parse_color (const char *s, struct color *ret)
 Parse a color string.
 
int string_parse_gradient (const char *s, struct gradient **ret)
 
int string_parse_bool (const void *data, const char *s, void *ret)
 
int string_parse_maybe_int (const void *data, const char *s, void *ret)
 Parse a string that may represent an integer value.
 
int get_setting_id (const char *key, const char *section)
 
int string_parse_length (void *ret_in, const char *s)
 
bool set_from_string (void *target, struct setting setting, const char *value)
 
bool set_setting (struct setting setting, char *value)
 
int set_rule_value (struct rule *r, struct setting setting, char *value)
 
bool set_rule (struct setting setting, char *value, char *section)
 
void set_defaults (void)
 
void save_settings (struct ini *ini)
 
void cmdline_load (int argc, char *argv[])
 
static int cmdline_find_option (const char *key, int start)
 
static const char * cmdline_get_value (const char *key, int start, int *found)
 
char * cmdline_get_string_offset (const char *key, const char *def, int start, int *found)
 
char * cmdline_get_string (const char *key, const char *def, const char *description)
 
char * cmdline_get_path (const char *key, const char *def, const char *description)
 
char ** cmdline_get_list (const char *key, const char *def, const char *description)
 
gint64 cmdline_get_time (const char *key, gint64 def, const char *description)
 
int cmdline_get_int (const char *key, int def, const char *description)
 
double cmdline_get_double (const char *key, double def, const char *description)
 
int cmdline_get_bool (const char *key, int def, const char *description)
 
bool cmdline_is_set (const char *key)
 
void cmdline_usage_append (const char *key, const char *type, const char *description)
 
const char * cmdline_create_usage (void)
 

Variables

static int cmdline_argc
 
static char ** cmdline_argv
 
static char * usage_str = NULL
 

Detailed Description

License
BSD-3-Clause

Definition in file option_parser.c.

Macro Definition Documentation

◆ STRING_PARSE_RET

#define STRING_PARSE_RET ( string,
value )
Value:
if (STR_EQ(s, string)) { *ret = value; return true; }
#define STR_EQ(a, b)
Test if string a and b contain the same chars.
Definition utils.h:26

Definition at line 29 of file option_parser.c.

◆ UINT_MAX_N

#define UINT_MAX_N ( bits)
Value:
((1 << bits) - 1)

Definition at line 203 of file option_parser.c.

Function Documentation

◆ cmdline_create_usage()

const char * cmdline_create_usage ( void )

Definition at line 738 of file option_parser.c.

◆ cmdline_find_option()

static int cmdline_find_option ( const char * key,
int start )
static

Definition at line 586 of file option_parser.c.

◆ cmdline_get_bool()

int cmdline_get_bool ( const char * key,
int def,
const char * description )

Definition at line 698 of file option_parser.c.

◆ cmdline_get_double()

double cmdline_get_double ( const char * key,
double def,
const char * description )

Definition at line 687 of file option_parser.c.

◆ cmdline_get_int()

int cmdline_get_int ( const char * key,
int def,
const char * description )

Definition at line 676 of file option_parser.c.

◆ cmdline_get_list()

char ** cmdline_get_list ( const char * key,
const char * def,
const char * description )

Definition at line 652 of file option_parser.c.

◆ cmdline_get_path()

char * cmdline_get_path ( const char * key,
const char * def,
const char * description )

Definition at line 641 of file option_parser.c.

◆ cmdline_get_string()

char * cmdline_get_string ( const char * key,
const char * def,
const char * description )

Definition at line 635 of file option_parser.c.

◆ cmdline_get_string_offset()

char * cmdline_get_string_offset ( const char * key,
const char * def,
int start,
int * found )

Definition at line 623 of file option_parser.c.

◆ cmdline_get_time()

gint64 cmdline_get_time ( const char * key,
gint64 def,
const char * description )

Definition at line 663 of file option_parser.c.

◆ cmdline_get_value()

static const char * cmdline_get_value ( const char * key,
int start,
int * found )
static

Definition at line 605 of file option_parser.c.

◆ cmdline_is_set()

bool cmdline_is_set ( const char * key)

Definition at line 709 of file option_parser.c.

◆ cmdline_load()

void cmdline_load ( int argc,
char * argv[] )

Definition at line 580 of file option_parser.c.

◆ cmdline_usage_append()

void cmdline_usage_append ( const char * key,
const char * type,
const char * description )

Definition at line 714 of file option_parser.c.

◆ get_setting_id()

int get_setting_id ( const char * key,
const char * section )

Definition at line 310 of file option_parser.c.

◆ save_settings()

void save_settings ( struct ini * ini)

Definition at line 525 of file option_parser.c.

◆ set_defaults()

void set_defaults ( void )

Definition at line 507 of file option_parser.c.

◆ set_from_string()

bool set_from_string ( void * target,
struct setting setting,
const char * value )

Definition at line 391 of file option_parser.c.

◆ set_rule()

bool set_rule ( struct setting setting,
char * value,
char * section )

Definition at line 498 of file option_parser.c.

◆ set_rule_value()

int set_rule_value ( struct rule * r,
struct setting setting,
char * value )

Definition at line 490 of file option_parser.c.

◆ set_setting()

bool set_setting ( struct setting setting,
char * value )

Definition at line 480 of file option_parser.c.

◆ string_parse_bool()

int string_parse_bool ( const void * data,
const char * s,
void * ret )

Definition at line 286 of file option_parser.c.

◆ string_parse_color()

int string_parse_color ( const char * s,
struct color * ret )

Parse a color string.

The format is:

#RRGGBB[AA] 

Definition at line 209 of file option_parser.c.

◆ string_parse_corners()

int string_parse_corners ( const void * data,
const char * s,
void * ret )

Definition at line 96 of file option_parser.c.

◆ string_parse_enum()

int string_parse_enum ( const void * data,
const char * s,
void * ret )

Definition at line 31 of file option_parser.c.

◆ string_parse_enum_list()

int string_parse_enum_list ( const void * data,
char ** s,
void * ret_void )

Definition at line 46 of file option_parser.c.

◆ string_parse_enum_list_to_single()

int string_parse_enum_list_to_single ( const void * data,
char ** s,
int * ret )

Parse a string list of enum values and return a single integer with the values bit-flipped into it.

This is only useful when the enum values all occupy different bits (for exampel 1<<0, 1<<1 and 1<<2) and the order doesn't matter.

Note
Only changes the return when succesful.
Returns
True for success, false otherwise.

Definition at line 78 of file option_parser.c.

◆ string_parse_gradient()

int string_parse_gradient ( const char * s,
struct gradient ** ret )

Definition at line 255 of file option_parser.c.

◆ string_parse_int_list()

bool string_parse_int_list ( char ** s,
int ** ret,
bool allow_empty )

Parse a list of integers.

Note
When allow empty is true, empty strings are interpreted as -1.

Definition at line 109 of file option_parser.c.

◆ string_parse_length()

int string_parse_length ( void * ret_in,
const char * s )
Warning
We do minimal checks in this function so the values should be sanitized somewhere else.

Definition at line 349 of file option_parser.c.

◆ string_parse_list()

int string_parse_list ( const void * data,
const char * s,
void * ret )
Note
Only changes the return when succesful

Definition at line 137 of file option_parser.c.

◆ string_parse_maybe_int()

int string_parse_maybe_int ( const void * data,
const char * s,
void * ret )

Parse a string that may represent an integer value.

Definition at line 298 of file option_parser.c.

◆ string_parse_sepcolor()

int string_parse_sepcolor ( const void * data,
const char * s,
void * ret )

Definition at line 177 of file option_parser.c.

Variable Documentation

◆ cmdline_argc

int cmdline_argc
static

Definition at line 25 of file option_parser.c.

◆ cmdline_argv

char** cmdline_argv
static

Definition at line 26 of file option_parser.c.

◆ usage_str

char* usage_str = NULL
static

Definition at line 27 of file option_parser.c.