options.c File Reference

Functions dealing with user settings. More...

#include <ctype.h>
#include <stdlib.h>
#include "global.h"
#include "log.h"
#include "interface.h"
#include "options.h"
#include "helper.h"
#include "warnings.h"
Include dependency graph for options.c:

Go to the source code of this file.

Data Structures

struct  opt___val_str_t
 A structure to associate a string with an integer. More...

Defines

#define ENV_PREFIX   "FSVS_"
#define BITMAP_CLEAR   (( (unsigned)INT_MIN) >> 1)
 We don't use the value INT_MIN directly, because then we couldn't use -1 for "everything.".
#define BITMAP_CLEAR_MASK   (BITMAP_CLEAR ^ (BITMAP_CLEAR >> 2))

Functions

int opt___debug_buffer (struct opt__list_t *ent, char *string, enum opt__prio_e prio UNUSED)
 Get the debugbuffer size, round and test for minimum size.
int opt___atoi (struct opt__list_t *ent, char *string, enum opt__prio_e prio UNUSED)
 Get an integer value directly.
int opt___find_string (const struct opt___val_str_t *list, const char *string, int *result)
 Find an integer value by comparing with predefined strings.
int opt___string2val (struct opt__list_t *ent, char *string, enum opt__prio_e prio UNUSED)
 Set an integer value by comparing with some strings.
int opt___strings2bitmap (struct opt__list_t *ent, char *string, enum opt__prio_e prio UNUSED)
 Convert a string into a list of words, and OR their associated values together.
int opt___strings2empty_bm (struct opt__list_t *ent, char *string, enum opt__prio_e prio)
 The same as opt___strings2bitmap(), but starting with a zero value on each parsed value.
int opt___store_string (struct opt__list_t *ent, char *string, enum opt__prio_e prio UNUSED)
 Simple store a copy of the string.
int opt___store_env_noempty (struct opt__list_t *ent, char *string, enum opt__prio_e prio)
 Store a string, or expand a (non-empty) environment variable.
int opt___parse_warnings (struct opt__list_t *ent, char *string, enum opt__prio_e prio)
 Parse warning settings.
int opt__parse_option (enum opt__settings_e which, enum opt__prio_e prio, char *string)
 -.
int opt__parse (char *key, char *value, enum opt__prio_e prio, int quiet_errors)
 -.
int opt__load_settings (char *path, char *name, enum opt__prio_e prio)
 -.
int opt__load_env (char **env)
 -.
int opt___normalized_path (struct opt__list_t *ent, char *string, enum opt__prio_e prio)
int opt__help (struct estat *root, int argc, char *argv[])
 -.
int opt__doesnt_say_off (const char *string)
 -.
char * opt__variable_from_option (enum opt__settings_e which)
 -.

Variables

struct opt___val_str_t opt___path_strings []
 Associate the path options with the enumerated value.
struct opt___val_str_t opt___log_output_strings []
 Log output strings and bits.
struct opt___val_str_t opt___yes_no []
 Strings for auto/yes/no settings.
struct opt___val_str_topt___no_words = opt___yes_no+3
struct opt___val_str_t opt___filter_strings []
 Filter strings and bits.
struct opt___val_str_t opt___chcheck_strings []
 Change detection strings.
struct opt___val_str_t opt___verbosity_strings []
 Verbosity strings Verbosity flags.
struct opt___val_str_t opt___delay_strings []
 Delay action names.
struct opt___val_str_t opt___conflict_strings []
 Conflict resolution options.
struct opt__list_t opt__list [OPT__COUNT]
 Must be visible, so that the inline function have direct accecss.
Predeclare some functions.



opt___parse_t opt___string2val
opt___parse_t opt___strings2bitmap
opt___parse_t opt___strings2empty_bm
opt___parse_t opt___store_string
opt___parse_t opt___store_env_noempty
opt___parse_t opt___normalized_path
opt___parse_t opt___parse_warnings
opt___parse_t opt___atoi
opt___parse_t opt___debug_buffer

Detailed Description

Functions dealing with user settings.

Definition in file options.c.


Define Documentation

#define BITMAP_CLEAR   (( (unsigned)INT_MIN) >> 1)

We don't use the value INT_MIN directly, because then we couldn't use -1 for "everything.".

Definition at line 52 of file options.c.

Referenced by opt___strings2bitmap().

#define BITMAP_CLEAR_MASK   (BITMAP_CLEAR ^ (BITMAP_CLEAR >> 2))

Definition at line 53 of file options.c.

Referenced by opt___strings2bitmap().

#define ENV_PREFIX   "FSVS_"

Definition at line 22 of file options.c.

Referenced by opt__load_env(), and opt__variable_from_option().


Function Documentation

int opt___atoi ( struct opt__list_t ent,
char *  string,
enum opt__prio_e prio  UNUSED 
)

Get an integer value directly.

Definition at line 364 of file options.c.

References opt__list_t::i_val.

int opt___debug_buffer ( struct opt__list_t ent,
char *  string,
enum opt__prio_e prio  UNUSED 
)

Get the debugbuffer size, round and test for minimum size.

The value is in KB; we round up to a 4kB size, and make it at least 8k. A value of 0 means off.

Definition at line 329 of file options.c.

References opt__list_t::i_val, and STOPIF.

int opt___find_string ( const struct opt___val_str_t list,
const char *  string,
int *  result 
) [inline]

Find an integer value by comparing with predefined strings.

Definition at line 377 of file options.c.

References opt___val_str_t::string, and opt___val_str_t::val.

Referenced by opt___string2val(), opt___strings2bitmap(), and opt__doesnt_say_off().

Here is the caller graph for this function:

int opt___normalized_path ( struct opt__list_t ent,
char *  string,
enum opt__prio_e  prio 
)

Definition at line 696 of file options.c.

References hlp__pathcopy(), opt___store_string, and PATH_SEPARATOR.

Here is the call graph for this function:

int opt___parse_warnings ( struct opt__list_t ent,
char *  string,
enum opt__prio_e  prio 
)

Parse warning settings.

Definition at line 495 of file options.c.

References STOPIF, and wa__split_process().

Here is the call graph for this function:

int opt___store_env_noempty ( struct opt__list_t ent,
char *  string,
enum opt__prio_e  prio 
)

Store a string, or expand a (non-empty) environment variable.

Definition at line 480 of file options.c.

References opt___store_string.

int opt___store_string ( struct opt__list_t ent,
char *  string,
enum opt__prio_e prio  UNUSED 
)

Simple store a copy of the string.

Definition at line 463 of file options.c.

References opt__list_t::cp_val, hlp__strnalloc(), opt__list_t::i_val, and STOPIF.

Here is the call graph for this function:

int opt___string2val ( struct opt__list_t ent,
char *  string,
enum opt__prio_e prio  UNUSED 
)

Set an integer value by comparing with some strings.

Definition at line 395 of file options.c.

References opt__list_t::i_val, opt___find_string(), opt__list_t::parm, and STOPIF.

Here is the call graph for this function:

int opt___strings2bitmap ( struct opt__list_t ent,
char *  string,
enum opt__prio_e prio  UNUSED 
)

Convert a string into a list of words, and OR their associated values together.

With an association of 0, or if BITMAP_CLEAR is set, the value is resetted.

Definition at line 414 of file options.c.

References BITMAP_CLEAR, BITMAP_CLEAR_MASK, DEBUGP, opt__list_t::i_val, opt___find_string(), and opt__list_t::parm.

Here is the call graph for this function:

int opt___strings2empty_bm ( struct opt__list_t ent,
char *  string,
enum opt__prio_e  prio 
)

The same as opt___strings2bitmap(), but starting with a zero value on each parsed value.

Definition at line 454 of file options.c.

References opt__list_t::i_val, and opt___strings2bitmap.

int opt__doesnt_say_off ( const char *  string  ) 

-.

Returns 0 if the string is an off value (like off, false, or no).

Invalid values are handled by returning 1, ie. they don't say off.

Definition at line 723 of file options.c.

References opt___find_string(), and OPT__YES.

Referenced by df__work().

Here is the call graph for this function:

Here is the caller graph for this function:

int opt__help ( struct estat root,
int  argc,
char *  argv[] 
)

-.

Definition at line 715 of file options.c.

int opt__load_env ( char **  env  ) 

-.

Load options from the environment.

Looks for environment variables with the given ENV_PREFIX, and tries to parse them as options.

Invalid names are ignored, invalid values not.

Definition at line 652 of file options.c.

References DEBUGP, ENV_PREFIX, opt__parse(), PRIO_ENV, and STOPIF.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

int opt__load_settings ( char *  path,
char *  name,
enum opt__prio_e  prio 
)

-.

Load options from a file.

Ignores empty lines; comment lines are defined by an # as first non-whitespace character.

Definition at line 591 of file options.c.

References DEBUGP, hlp__string_from_filep(), opt__parse(), SFF_COMMENT, SFF_GET_LINENUM, SFF_RESET_LINENUM, SFF_WHITESPACE, and STOPIF.

Referenced by main(), and waa__find_common_base2().

Here is the call graph for this function:

Here is the caller graph for this function:

int opt__parse ( char *  key,
char *  value,
enum opt__prio_e  prio,
int  quiet_errors 
)

-.

Find the option, and parse the string.

If the value is NULL, try to split the key on a =. Then find the matching option, and set its value (depending on the given priority).

Definition at line 536 of file options.c.

References DEBUGP, hlp__skip_ws(), hlp__strncmp_uline_eq_dash(), opt__list_t::name, OPT__COUNT, opt__parse_option(), STOPIF, and STOPIF_CODE_ERR.

Referenced by main(), opt__load_env(), and opt__load_settings().

Here is the call graph for this function:

Here is the caller graph for this function:

int opt__parse_option ( enum opt__settings_e  which,
enum opt__prio_e  prio,
char *  string 
)

-.

Parse the string for the option.

If the given priority is at least equal to the current value, parse the strng and set the value.

Definition at line 509 of file options.c.

References hlp__skip_ws(), opt__list_t::name, opt__list_t::parse, opt__list_t::prio, and STOPIF.

Referenced by main(), and opt__parse().

Here is the call graph for this function:

Here is the caller graph for this function:

char* opt__variable_from_option ( enum opt__settings_e  which  ) 

-.

Return the variable name from an option.

Todo:
Maybe the variable reading should be changed to use this code, and loop via getenv() over all options?

Definition at line 737 of file options.c.

References ENV_PREFIX, and opt__list_t::name.

Referenced by waa__init().

Here is the caller graph for this function:


Variable Documentation

opt___parse_t opt___atoi

Definition at line 182 of file options.c.

Initial value:
 {
    { .val=0,                                                                   .string="none" },
    { .val=CHCHECK_FILE,                                            .string="file_mtime" },
    { .val=CHCHECK_DIRS,                                            .string="dir" },
    { .val=CHCHECK_ALLFILES,                                    .string="allfiles" },
    { .val=-1,                                                              .string="full" },
}

Change detection strings.

Change detection.

Definition at line 114 of file options.c.

Initial value:
 {
    { .val=CONFLICT_STOP,                   .string="stop" },
    { .val=CONFLICT_LOCAL,              .string="local" },
    { .val=CONFLICT_REMOTE,             .string="remote" }, 
    { .val=CONFLICT_BOTH,               .string="both" }, 
    { .val=CONFLICT_MERGE,              .string="merge" }, 
    { .string=NULL, }
}

Conflict resolution options.

See How to resolve conflicts on update.

Definition at line 162 of file options.c.

opt___parse_t opt___debug_buffer

Definition at line 183 of file options.c.

Initial value:
 {
    { .val=DELAY_COMMIT,                    .string="commit" },
    { .val=DELAY_UPDATE,                    .string="update" },
    { .val=DELAY_REVERT,                    .string="revert" }, 
    { .val=DELAY_CHECKOUT,              .string="checkout" }, 
    { .val=-1,                                      .string="yes" },
    { .val=0,                                       .string="no" },
    { .string=NULL, }
}

Delay action names.

See Waiting for a time change after working copy operations.

Definition at line 149 of file options.c.

Initial value:
 {
    { .val=FILTER__ALL,                                             .string="any" },
    { .val=FS_CHANGED | FS_NEW | FS_REMOVED,    .string="text" },
    { .val=FS_META_CHANGED,                                     .string="meta" }, 
    { .val=FS_META_MTIME,                                       .string="mtime" }, 
    { .val=FS_META_OWNER,                                       .string="owner" },
    { .val=FS_META_UMODE,                                           .string="mode" },
    { .val=FS_META_GROUP,                                       .string="group" },
    { .val=FS_NEW,                                                      .string="new" },
    { .val=FS_CHANGED,                                              .string="changed" },
    { .val=FS_REMOVED,                                              .string="deleted" },
    { .val=FS_REMOVED,                                              .string="removed" },
    { .val=FS__CHANGE_MASK,                                     .string="default" },
    { .val=FS__CHANGE_MASK,                                     .string="def" },
    { .val=0,                                                               .string="none" },
    { .string=NULL, }
}

Filter strings and bits.

-f -- filter entries.

Definition at line 93 of file options.c.

Initial value:
 {
    { .val=LOG__OPT_COLOR,                      .string="color" },
    { .val=LOG__OPT_INDENT,                     .string="indent" },
    { .val=0,                                               .string="normal" },
    { .string=NULL, }
}

Log output strings and bits.

Definition at line 67 of file options.c.

Definition at line 88 of file options.c.

opt___parse_t opt___normalized_path

Definition at line 180 of file options.c.

opt___parse_t opt___parse_warnings

Definition at line 181 of file options.c.

Initial value:
 {
    { .val=PATH_PARMRELATIVE,       .string="parameter"},
    { .val=PATH_ABSOLUTE,               .string="absolute"},
    { .val=PATH_WCRELATIVE,         .string="wcroot"},
    { .val=PATH_CACHEDENVIRON,  .string="environment"},
    { .val=PATH_FULLENVIRON,        .string="full-environment"},
    { .string=NULL, }
}

Associate the path options with the enumerated value.

See also Displaying paths

Definition at line 57 of file options.c.

opt___parse_t opt___store_env_noempty

Definition at line 179 of file options.c.

opt___parse_t opt___store_string

Definition at line 178 of file options.c.

Referenced by opt___normalized_path(), and opt___store_env_noempty().

opt___parse_t opt___string2val

Definition at line 175 of file options.c.

opt___parse_t opt___strings2bitmap

Definition at line 176 of file options.c.

Referenced by opt___strings2empty_bm().

opt___parse_t opt___strings2empty_bm

Definition at line 177 of file options.c.

Initial value:
 {
    { .val=VERBOSITY_VERYQUIET | BITMAP_CLEAR,          .string="none" },
    { .val=VERBOSITY_VERYQUIET | BITMAP_CLEAR,          .string="veryquiet" },
    { .val=VERBOSITY_QUIET       | BITMAP_CLEAR,            .string="quiet" },
    { .val=VERBOSITY_SHOWCHG,                                               .string="changes" }, 
    { .val=VERBOSITY_SHOWCHG,                                               .string="status" }, 
    { .val=VERBOSITY_SHOWSIZE,                                          .string="size" },
    { .val=VERBOSITY_SHOWNAME,                                          .string="path" },
    { .val=VERBOSITY_SHOWNAME,                                          .string="name" },
    { .val=VERBOSITY_SHOWTIME,                                          .string="time" },
    { .val=VERBOSITY_DEFAULT,                                               .string="default" },
    { .val=VERBOSITY_TOP_URL,                                               .string="url" },
    { .val=VERBOSITY_ALL_URLS | VERBOSITY_TOP_URL,  .string="urls" },
    { .val=VERBOSITY_COPYFROM,                                          .string="copyfrom" },
    { .val=VERBOSITY_GROUP,                                                 .string="group" },
    { .val=VERBOSITY_STACKTRACE,                                        .string="stack" },
    { .val=VERBOSITY_STACKTRACE,                                        .string="backtrace" },
    { .val=VERBOSITY_STACKTRACE,                                        .string="stacktrace" },
    { .val=-1,                                                                          .string="all" },
}

Verbosity strings Verbosity flags.

Definition at line 125 of file options.c.

Initial value:
 {
    { .val=OPT__YES,                                    .string="yes" },
    { .val=OPT__YES,                                    .string="true" },
    { .val=OPT__YES,                                    .string="on" },
    { .val=OPT__NO,                                     .string="no" },
    { .val=OPT__NO,                                     .string="off" },
    { .val=OPT__NO,                                     .string="false" },
    { .string=NULL, }
}

Strings for auto/yes/no settings.

Don't change the order without changing all users!

Definition at line 77 of file options.c.

struct opt__list_t opt__list[OPT__COUNT]

Must be visible, so that the inline function have direct accecss.

The list of all options.

As delimiter should '_' be used; as the comparision is done via hlp__strncmp_uline_eq_dash(), the user can also use '-'.

Definition at line 192 of file options.c.

Referenced by __attribute__(), opt__set_int(), and opt__set_string().


Generated for fsvs by  doxygen 1.6.1