Freeciv-3.2
Loading...
Searching...
No Matches
Macros | Functions | Variables
fc_cmdline.c File Reference
#include "fc_prehdrs.h"
#include <string.h>
#include "fciconv.h"
#include "fcintl.h"
#include "mem.h"
#include "support.h"
#include "fc_cmdline.h"
#include "speclist.h"

Go to the source code of this file.

Macros

#define SPECLIST_TAG   cmdline_value
 
#define SPECLIST_TYPE   char
 
#define cmdline_value_list_iterate(vallist, pvalue)    TYPED_LIST_ITERATE(char *, vallist, pvalue)
 
#define cmdline_value_list_iterate_end   LIST_ITERATE_END
 

Functions

charget_option_malloc (const char *option_name, char **argv, int *i, int argc, bool gc)
 
void cmdline_option_values_free (void)
 
bool is_option (const char *option_name, char *option)
 
static size_t fc_strcspn (const char *s, const char *reject)
 
int get_tokens (const char *str, char **tokens, size_t num_tokens, const char *delimiterset)
 
void free_tokens (char **tokens, size_t ntokens)
 

Variables

static struct cmdline_value_listcmdline_values = NULL
 

Macro Definition Documentation

◆ cmdline_value_list_iterate

#define cmdline_value_list_iterate (   vallist,
  pvalue 
)     TYPED_LIST_ITERATE(char *, vallist, pvalue)

Definition at line 35 of file fc_cmdline.c.

◆ cmdline_value_list_iterate_end

#define cmdline_value_list_iterate_end   LIST_ITERATE_END

Definition at line 37 of file fc_cmdline.c.

◆ SPECLIST_TAG

#define SPECLIST_TAG   cmdline_value

Definition at line 31 of file fc_cmdline.c.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   char

Definition at line 32 of file fc_cmdline.c.

Function Documentation

◆ cmdline_option_values_free()

void cmdline_option_values_free ( void  )

Free memory allocated for commandline option values.

Definition at line 97 of file fc_cmdline.c.

Referenced by client_exit(), main(), main(), rup_parse_cmdline(), and server_quit().

◆ fc_strcspn()

static size_t fc_strcspn ( const char s,
const char reject 
)
static

Like strcspn but also handles quotes, i.e. *reject chars are ignored if they are inside single or double quotes.

Definition at line 122 of file fc_cmdline.c.

Referenced by get_tokens().

◆ free_tokens()

void free_tokens ( char **  tokens,
size_t  ntokens 
)

◆ get_option_malloc()

char * get_option_malloc ( const char option_name,
char **  argv,
int i,
int  argc,
bool  gc 
)

Return a char* to the parameter of the option or NULL. i can be increased to get next string in the array argv[]. It is an error for the option to exist but be an empty string. This doesn't use log_*() because it is used before logging is set up.

The argv strings are assumed to be in the local encoding; the returned string is in the internal encoding.

Definition at line 50 of file fc_cmdline.c.

Referenced by client_main(), fcmp_parse_cmdline(), main(), main(), parse_options(), re_parse_cmdline(), and rup_parse_cmdline().

◆ get_tokens()

int get_tokens ( const char str,
char **  tokens,
size_t  num_tokens,
const char delimiterset 
)

Splits the string into tokens. The individual tokens are returned. The delimiterset can freely be chosen.

i.e. "34 abc 54 87" with a delimiterset of " " will yield tokens={"34", "abc", "54", "87"}

Part of the input string can be quoted (single or double) to embedded delimiter into tokens. For example, command 'a name' hard "1,2,3,4,5" 99 create 'Mack "The Knife"' will yield 5 and 2 tokens respectively using the delimiterset " ,".

Tokens which aren't used aren't modified (and memory is not allocated). If the string would yield more tokens only the first num_tokens are extracted.

The user has the responsibility to free the memory allocated by tokens using free_tokens().

Definition at line 166 of file fc_cmdline.c.

Referenced by aicmd_command(), cmdlevel_command(), create_command(), debug_command(), delegate_command(), detach_command(), fcdb_command(), lock_command(), lua_command(), mapimg_command(), mapimg_define(), mapimg_define_arg(), observe_command(), packet_handlers_get(), playercolor_command(), playernation_command(), property_filter_new(), set_command(), take_command(), team_command(), timeout_command(), unlock_command(), and vote_command().

◆ is_option()

bool is_option ( const char option_name,
char option 
)

Is option some form of option_name. option_name must be full length long version such as "--help"

Definition at line 112 of file fc_cmdline.c.

Referenced by client_main(), fcmp_parse_cmdline(), main(), main(), parse_options(), parse_options(), re_parse_cmdline(), and rup_parse_cmdline().

Variable Documentation

◆ cmdline_values

struct cmdline_value_list* cmdline_values = NULL
static

Definition at line 39 of file fc_cmdline.c.

Referenced by cmdline_option_values_free(), and get_option_malloc().