Uncrustify maxscale

See script directory for method. The script to run in the top level
MaxScale directory is called maxscale-uncrustify.sh, which uses
another script, list-src, from the same directory (so you need to set
your PATH). The uncrustify version was 0.66.
This commit is contained in:
Niclas Antti
2018-09-09 22:26:19 +03:00
parent fa7ec95069
commit c447e5cf15
849 changed files with 35002 additions and 27238 deletions

View File

@ -40,11 +40,17 @@ bool INIReader::GetBoolean(string section, string name, bool default_value)
// Convert to lower case to make string comparisons case-insensitive
std::transform(valstr.begin(), valstr.end(), valstr.begin(), ::tolower);
if (valstr == "true" || valstr == "yes" || valstr == "on" || valstr == "1")
{
return true;
}
else if (valstr == "false" || valstr == "no" || valstr == "off" || valstr == "0")
{
return false;
}
else
{
return default_value;
}
}
string INIReader::MakeKey(string section, string name)
@ -55,13 +61,17 @@ string INIReader::MakeKey(string section, string name)
return key;
}
int INIReader::ValueHandler(void* user, const char* section, const char* name,
int INIReader::ValueHandler(void* user,
const char* section,
const char* name,
const char* value)
{
INIReader* reader = (INIReader*)user;
string key = MakeKey(section, name);
if (reader->_values[key].size() > 0)
{
reader->_values[key] += "\n";
}
reader->_values[key] += value;
return 1;
}

View File

@ -25,7 +25,8 @@ public:
int ParseError();
// Get a string value from INI file, returning default_value if not found.
std::string Get(std::string section, std::string name,
std::string Get(std::string section,
std::string name,
std::string default_value);
// Get an integer (long) value from INI file, returning default_value if
@ -38,11 +39,13 @@ public:
bool GetBoolean(std::string section, std::string name, bool default_value);
private:
int _error;
int _error;
std::map<std::string, std::string> _values;
static std::string MakeKey(std::string section, std::string name);
static int ValueHandler(void* user, const char* section, const char* name,
const char* value);
static int ValueHandler(void* user,
const char* section,
const char* name,
const char* value);
};
#endif // __INIREADER_H__

View File

@ -7,7 +7,8 @@ int main()
{
INIReader reader("../examples/test.ini");
if (reader.ParseError() < 0) {
if (reader.ParseError() < 0)
{
std::cout << "Can't load 'test.ini'\n";
return 1;
}

View File

@ -4,12 +4,15 @@
#include <string.h>
#include "../ini.h"
static int dumper(void* user, const char* section, const char* name,
static int dumper(void* user,
const char* section,
const char* name,
const char* value)
{
static char prev_section[50] = "";
if (strcmp(section, prev_section)) {
if (strcmp(section, prev_section))
{
printf("%s[%s]\n", (prev_section[0] ? "\n" : ""), section);
strncpy(prev_section, section, sizeof(prev_section));
prev_section[sizeof(prev_section) - 1] = '\0';
@ -22,17 +25,20 @@ int main(int argc, char* argv[])
{
int error;
if (argc <= 1) {
if (argc <= 1)
{
printf("Usage: ini_dump filename.ini\n");
return 1;
}
error = ini_parse(argv[1], dumper, NULL);
if (error < 0) {
if (error < 0)
{
printf("Can't read '%s'!\n", argv[1]);
return 2;
}
else if (error) {
else if (error)
{
printf("Bad config file (first error on line %d)!\n", error);
return 3;
}

View File

@ -7,25 +7,34 @@
typedef struct
{
int version;
int version;
const char* name;
const char* email;
} configuration;
static int handler(void* user, const char* section, const char* name,
static int handler(void* user,
const char* section,
const char* name,
const char* value)
{
configuration* pconfig = (configuration*)user;
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
if (MATCH("protocol", "version")) {
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
if (MATCH("protocol", "version"))
{
pconfig->version = atoi(value);
} else if (MATCH("user", "name")) {
}
else if (MATCH("user", "name"))
{
pconfig->name = strdup(value);
} else if (MATCH("user", "email")) {
}
else if (MATCH("user", "email"))
{
pconfig->email = strdup(value);
} else {
return 0; /* unknown section/name, error */
}
else
{
return 0; /* unknown section/name, error */
}
return 1;
}
@ -34,11 +43,14 @@ int main(int argc, char* argv[])
{
configuration config;
if (ini_parse("test.ini", handler, &config) < 0) {
if (ini_parse("test.ini", handler, &config) < 0)
{
printf("Can't load 'test.ini'\n");
return 1;
}
printf("Config loaded from 'test.ini': version=%d, name=%s, email=%s\n",
config.version, config.name, config.email);
config.version,
config.name,
config.email);
return 0;
}

View File

@ -5,42 +5,50 @@
#include "../ini.h"
/* define the config struct type */
typedef struct {
#define CFG(s, n, default) char *s##_##n;
#include "config.def"
typedef struct
{
#define CFG(s, n, default) char* s##_##n;
#include "config.def"
} config;
/* create one and fill in its default values */
config Config = {
#define CFG(s, n, default) default,
#include "config.def"
#define CFG(s, n, default) default,
#include "config.def"
};
/* process a line of the INI file, storing valid values into config struct */
int handler(void *user, const char *section, const char *name,
const char *value)
int handler(void* user,
const char* section,
const char* name,
const char* value)
{
config *cfg = (config *)user;
config* cfg = (config*)user;
if (0) ;
#define CFG(s, n, default) else if (strcmp(section, #s)==0 && \
strcmp(name, #n)==0) cfg->s##_##n = strdup(value);
#include "config.def"
if (0)
{
}
#define CFG(s, n, default) \
else if (strcmp(section, #s) == 0 \
&& strcmp(name, #n) == 0) {cfg->s##_##n = strdup(value);}
#include "config.def"
return 1;
}
/* print all the variables in the config, one per line */
void dump_config(config *cfg)
void dump_config(config* cfg)
{
#define CFG(s, n, default) printf("%s_%s = %s\n", #s, #n, cfg->s##_##n);
#include "config.def"
#define CFG(s, n, default) printf("%s_%s = %s\n", #s, #n, cfg->s##_##n);
#include "config.def"
}
int main(int argc, char* argv[])
{
if (ini_parse("test.ini", handler, &Config) < 0)
{
printf("Can't load 'test.ini', using defaults\n");
}
dump_config(&Config);
return 0;
}

View File

@ -1,11 +1,11 @@
/* inih -- simple .INI file parser
inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info:
http://code.google.com/p/inih/
*/
*
* inih is released under the New BSD license (see LICENSE.txt). Go to the project
* home page for more info:
*
* http://code.google.com/p/inih/
*
*/
#include <stdio.h>
#include <ctype.h>
@ -18,14 +18,16 @@ http://code.google.com/p/inih/
#endif
#define MAX_SECTION 1024
#define MAX_NAME 1024
#define MAX_NAME 1024
/* Strip whitespace chars off end of given string, in place. Return s. */
static char* rstrip(char* s)
{
char* p = s + strlen(s);
while (p > s && isspace((unsigned char)(*--p)))
{
*p = '\0';
}
return s;
}
@ -33,17 +35,20 @@ static char* rstrip(char* s)
static char* lskip(const char* s)
{
while (*s && isspace((unsigned char)(*s)))
{
s++;
}
return (char*)s;
}
/* Return pointer to first char c or ';' comment in given string, or pointer to
null at end of string if neither found. ';' must be prefixed by a whitespace
character to register as a comment. */
* null at end of string if neither found. ';' must be prefixed by a whitespace
* character to register as a comment. */
static char* find_char_or_comment(const char* s, char c)
{
int was_whitespace = 0;
while (*s && *s != c && !(was_whitespace && *s == ';')) {
while (*s && *s != c && !(was_whitespace && *s == ';'))
{
was_whitespace = isspace((unsigned char)(*s));
s++;
}
@ -60,8 +65,10 @@ static char* strncpy0(char* dest, const char* src, size_t size)
/* See documentation in header file. */
int ini_parse_file(FILE* file,
int (*handler)(void*, const char*, const char*,
const char*),
int (* handler)(void*,
const char*,
const char*,
const char*),
void* user)
{
/* Uses a fair bit of stack (use heap instead if you need to) */
@ -82,70 +89,88 @@ int ini_parse_file(FILE* file,
#if !INI_USE_STACK
line = (char*)malloc(INI_MAX_LINE);
if (!line) {
if (!line)
{
return -2;
}
#endif
/* Scan through file line by line */
while (fgets(line, INI_MAX_LINE, file) != NULL) {
while (fgets(line, INI_MAX_LINE, file) != NULL)
{
lineno++;
start = line;
#if INI_ALLOW_BOM
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
(unsigned char)start[1] == 0xBB &&
(unsigned char)start[2] == 0xBF) {
if (lineno == 1 && (unsigned char)start[0] == 0xEF
&& (unsigned char)start[1] == 0xBB
&& (unsigned char)start[2] == 0xBF)
{
start += 3;
}
#endif
start = lskip(rstrip(start));
if (*start == ';' || *start == '#') {
if (*start == ';' || *start == '#')
{
/* Per Python ConfigParser, allow '#' comments at start of line */
}
#if INI_ALLOW_MULTILINE
else if (*prev_name && *start && start > line) {
else if (*prev_name && *start && start > line)
{
/* Non-black line with leading whitespace, treat as continuation
of previous name's value (as per Python ConfigParser). */
* of previous name's value (as per Python ConfigParser). */
if (!handler(user, section, prev_name, start) && !error)
{
error = lineno;
}
}
#endif
else if (*start == '[') {
else if (*start == '[')
{
/* A "[section]" line */
end = find_char_or_comment(start + 1, ']');
if (*end == ']') {
if (*end == ']')
{
*end = '\0';
strncpy0(section, start + 1, sizeof(section) - 1);
*prev_name = '\0';
}
else if (!error) {
else if (!error)
{
/* No ']' found on section line */
error = lineno;
}
}
else if (*start && *start != ';') {
else if (*start && *start != ';')
{
/* Not a comment, must be a name[=:]value pair */
end = find_char_or_comment(start, '=');
if (*end != '=') {
if (*end != '=')
{
end = find_char_or_comment(start, ':');
}
if (*end == '=' || *end == ':') {
if (*end == '=' || *end == ':')
{
*end = '\0';
name = rstrip(start);
value = lskip(end + 1);
end = find_char_or_comment(value, '\0');
if (*end == ';')
{
*end = '\0';
}
rstrip(value);
/* Valid name[=:]value pair found, call handler */
strncpy0(prev_name, name, sizeof(prev_name) - 1);
if (!handler(user, section, name, value) && !error)
{
error = lineno;
}
}
else if (!error) {
else if (!error)
{
/* No '=' or ':' found on name[=:]value line */
error = lineno;
}
@ -161,7 +186,7 @@ int ini_parse_file(FILE* file,
/* See documentation in header file. */
int ini_parse(const char* filename,
int (*handler)(void*, const char*, const char*, const char*),
int (* handler)(void*, const char*, const char*, const char*),
void* user)
{
FILE* file;
@ -169,7 +194,9 @@ int ini_parse(const char* filename,
file = fopen(filename, "r");
if (!file)
{
return -1;
}
error = ini_parse_file(file, handler, user);
fclose(file);
return error;

View File

@ -1,11 +1,11 @@
/* inih -- simple .INI file parser
inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info:
http://code.google.com/p/inih/
*/
*
* inih is released under the New BSD license (see LICENSE.txt). Go to the project
* home page for more info:
*
* http://code.google.com/p/inih/
*
*/
#ifndef __INI_H__
#define __INI_H__
@ -18,39 +18,43 @@ extern "C" {
#include <stdio.h>
/* Parse given INI-style file. May have [section]s, name=value pairs
(whitespace stripped), and comments starting with ';' (semicolon). Section
is "" if name=value pair parsed before any section heading. name:value
pairs are also supported as a concession to Python's ConfigParser.
For each name=value pair parsed, call handler function with given user
pointer as well as section, name, and value (data only valid for duration
of handler call). Handler should return nonzero on success, zero on error.
Returns 0 on success, line number of first error on parse error (doesn't
stop on first error), -1 on file open error, or -2 on memory allocation
error (only when INI_USE_STACK is zero).
*/
* (whitespace stripped), and comments starting with ';' (semicolon). Section
* is "" if name=value pair parsed before any section heading. name:value
* pairs are also supported as a concession to Python's ConfigParser.
*
* For each name=value pair parsed, call handler function with given user
* pointer as well as section, name, and value (data only valid for duration
* of handler call). Handler should return nonzero on success, zero on error.
*
* Returns 0 on success, line number of first error on parse error (doesn't
* stop on first error), -1 on file open error, or -2 on memory allocation
* error (only when INI_USE_STACK is zero).
*/
int ini_parse(const char* filename,
int (*handler)(void* user, const char* section,
const char* name, const char* value),
int (* handler)(void* user,
const char* section,
const char* name,
const char* value),
void* user);
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
close the file when it's finished -- the caller must do that. */
* close the file when it's finished -- the caller must do that. */
int ini_parse_file(FILE* file,
int (*handler)(void* user, const char* section,
const char* name, const char* value),
int (* handler)(void* user,
const char* section,
const char* name,
const char* value),
void* user);
/* Nonzero to allow multi-line value parsing, in the style of Python's
ConfigParser. If allowed, ini_parse() will call the handler with the same
name for each subsequent line parsed. */
* ConfigParser. If allowed, ini_parse() will call the handler with the same
* name for each subsequent line parsed. */
#ifndef INI_ALLOW_MULTILINE
#define INI_ALLOW_MULTILINE 1
#endif
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
the file. See http://code.google.com/p/inih/issues/detail?id=21 */
* the file. See http://code.google.com/p/inih/issues/detail?id=21 */
#ifndef INI_ALLOW_BOM
#define INI_ALLOW_BOM 1
#endif

View File

@ -1,16 +1,16 @@
/* inih -- unit tests
This works simply by dumping a bunch of info to standard output, which is
redirected to an output file (baseline_*.txt) and checked into the Subversion
repository. This baseline file is the test output, so the idea is to check it
once, and if it changes -- look at the diff and see which tests failed.
Here's how I produced the two baseline files (with Tiny C Compiler):
tcc -DINI_ALLOW_MULTILINE=1 ../ini.c -run unittest.c > baseline_multi.txt
tcc -DINI_ALLOW_MULTILINE=0 ../ini.c -run unittest.c > baseline_single.txt
*/
*
* This works simply by dumping a bunch of info to standard output, which is
* redirected to an output file (baseline_*.txt) and checked into the Subversion
* repository. This baseline file is the test output, so the idea is to check it
* once, and if it changes -- look at the diff and see which tests failed.
*
* Here's how I produced the two baseline files (with Tiny C Compiler):
*
* tcc -DINI_ALLOW_MULTILINE=1 ../ini.c -run unittest.c > baseline_multi.txt
* tcc -DINI_ALLOW_MULTILINE=0 ../ini.c -run unittest.c > baseline_single.txt
*
*/
#include <stdio.h>
#include <stdlib.h>
@ -20,21 +20,25 @@ tcc -DINI_ALLOW_MULTILINE=0 ../ini.c -run unittest.c > baseline_single.txt
int User;
char Prev_section[50];
int dumper(void* user, const char* section, const char* name,
int dumper(void* user,
const char* section,
const char* name,
const char* value)
{
User = (int)user;
if (strcmp(section, Prev_section)) {
if (strcmp(section, Prev_section))
{
printf("... [%s]\n", section);
strncpy(Prev_section, section, sizeof(Prev_section));
Prev_section[sizeof(Prev_section) - 1] = '\0';
}
printf("... %s=%s;\n", name, value);
return strcmp(name, "user")==0 && strcmp(value, "parse_error")==0 ? 0 : 1;
return strcmp(name, "user") == 0 && strcmp(value, "parse_error") == 0 ? 0 : 1;
}
void parse(const char* fname) {
void parse(const char* fname)
{
static int u = 100;
int e;