src/config.c


Log

Author Commit Date CI Message
Carlos Martín Nieto 631752aa 2011-04-11T17:49:47 Fix number suffix detection Allow a number not to have a suffix. This broke when adding the suffixes. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto b075b991 2011-04-07T16:54:10 Add getting and setting of long int variables long int is a safer type than int unless the user knows that the variable is going to be quite small. The code has been reworked to use strtol instead of the more complicated sscanf. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 7a4dfd60 2011-04-07T11:30:02 Simplify error path in config_set Many error paths freed their local data althought it is freed later on when the end of the function notices that there was an error. This can cause double frees and invalid memory access. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 493384e3 2011-04-07T11:24:16 config: make cvar_free behave more like other free functions Make cvar_free return void instad of the next element, as it was mostly a hack to make cvar_list_free shorter but it's now using the list macros. Also check if the input is NULL and return immediately in that case. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 6b45cb8a 2011-04-06T18:27:31 config: use and implement list macros Use list macros instead of manually changing the head and/or tail of the variable list.
Carlos Martín Nieto 0d280ea4 2011-04-06T16:31:06 config: use snprintf instead of sprintf Due to the preconditions, there should never be an error, but it pays to be paranoid. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 956ad0ed 2011-04-06T15:51:10 config: free the file buffer earlier There is no need to keep config file in memory until the the configuration is freed. Free the buffer immediately after the configuration has been parsed. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto acab3bc4 2011-04-06T15:31:42 config: move str(n)tolower to the git__ namespace Non-static functions in a library should always have a prefix namespace. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto aa793424 2011-04-06T15:27:12 config: coding style fixes
Carlos Martín Nieto 6776fd51 2011-04-06T15:17:06 config: really compare the variable name case-insensitively Make cvar_name_match really compare the last part of the variable ignoring the case. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 2470be13 2011-04-04T17:06:31 config: variable name on its own means true If a variable name appears on its own in a line, it's assumed the value is true. Store the variable name as NULL in that case. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 9b7a6a99 2011-04-04T16:17:39 config: check for EOF before newline If a line ends at EOF there is no need to check for the newline character and doing so will cause us to read memory beyond the allocatd memory as we check for the Windows-style new-line, which is two bytes long. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 72946881 2011-04-04T15:26:43 config: support multiline values If a variable value has the traditional continuation character (\) as the last non-space character in the line, then we continue reading the value on the next line. Using more than two lines is also supported. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 2454ce78 2011-04-04T11:25:55 config: don't mix buffer reading methods Make header and variable parse functions use their own buffers instead of giving them the line they need to read as a parameter which they mostly ignore. This is in preparation for multiline configuration variables. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 9f1b54d6 2011-04-04T15:07:47 config: also free the file buffer on error On error, the buffer containing the file contents also needs to be freed. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto fe116e26 2011-04-04T15:33:14 config: Fix typo and remove debug statement Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 11d0e705 2011-03-31T10:50:11 Add support for subsections A variable name is stored internally with its section the way it appeared in the configuration file in order to have the information about what parts are case-sensitive inline. Really implement parse_section_header_ext and move the assignment of variables to config_parse. The variable name matching is now done in a case-away way by cvar_name_match and cvar_section_match. Before the user sees it, it's normalized to the two- or three-dot version. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 6482929b 2011-03-30T18:51:02 move build_varname above parse_section
Carlos Martín Nieto d7354d70 2011-03-30T16:22:31 build_varname: lowercase the variable name Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 0bbaf9aa 2011-03-30T16:11:55 config_parse: no need to check if current_section is non-null Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 923fe455 2011-03-30T16:02:57 Add strtolower and strntolower functions As parts of variable names are case-sensitive, we need these functions. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto df22949a 2011-03-31T12:51:17 config_set: really replace the value on overwrite Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 8ecc5ae5 2011-03-30T16:48:14 git_config_set_int: use the right buffer Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto dadc0158 2011-03-30T15:05:15 config: use a singly-linked list instead of a hash table Such a list preserves the order the variables were first read in which will be useful later for merging different data-sets. Furthermore, reading and writing out the same configuration should not reorganize the variables, which could happen when iterating through all the items in a hash table. A hash table is overkill for this small a data-set anyway. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto d28830c2 2011-03-30T13:40:19 Store the parsed variables Store the key-value pair as strings. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 934fcf78 2011-03-30T11:32:08 Initialise the config reader in config_parse git_config_open shouldn't have to initialise variables that are only used inside config_parse and its callees. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 2974aa94 2011-03-30T11:30:40 Determine variable type at runtime Config variables should be interpreted at run-time, as we don't know if a zero means false or zero, or if yes means true or "yes". As a variable has no intrinsic type, git_cvtype is gone and the public API takes care of enforcing a few rules. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 2e445cac 2011-03-30T11:07:09 build_varname: allocate memory Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 9a3c5e55 2011-03-29T17:44:10 Expose config API for setters, getters and foreach These functions can be used to query or modify the variables in a given configuration. No sanity checking is done on the variable names. This is mostly meant as an API preview. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 26faa366 2011-03-29T17:59:13 Add build_varname to make a full var name Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto e15afc8e 2011-03-29T17:37:03 cvar_free: also free the config var's name Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 3d23b74a 2011-03-29T13:50:37 Free the config var hash contents in git_config_free Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 9f7f4122 2011-03-29T12:19:53 Don't leak if config parsing fails Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 4e02504f 2011-03-29T12:10:30 Move config to support the new hash code The hashes have been copied from the references code Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 3b4835c2 2011-03-28T18:07:22 Correctly parse the section header If cfg_readline consumes the line, then parse_section_header will read past it and if we read a character, parse_variable won't have the full name. This solution is a bit hackish, but it's the simplest way to get the code to parse correctly. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 908afb77 2011-03-28T17:53:04 parse_section_header: save the name where it belongs Save the location of the name in section_out instead of returning it as an int. Use the return code to signal success or failure. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto e4c796f1 2011-03-28T17:51:18 Read and parse the confguration when openingt the config file Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto a69053c7 2011-03-28T17:12:53 Convert config.c to LF Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 5d4cd003 2011-03-28T17:02:45 Move the struct declaration outside config.c Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Vicent Marti a3002d56 2011-01-29T01:58:55 First version - WIP Signed-off-by: Vicent Marti <tanoku@gmail.com>