I just decided. Braces on their own lines.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3668 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-10-10 21:51:38 +00:00
parent 470814f147
commit 843c53e15e
20 changed files with 2373 additions and 1110 deletions

View File

@ -29,7 +29,8 @@
_xopt_ctx = xopt_context((name), (options), ((flags) ^ XOPT_CTX_POSIXMEHARDER), (err_ptr)); \
if (*(err_ptr)) break; \
*extrac_ptr = xopt_parse(_xopt_ctx, (argc), (argv), (config_ptr), (extrav_ptr), (err_ptr)); \
if ((config_ptr)->help) { \
if ((config_ptr)->help) \
{ \
xoptAutohelpOptions __xopt_autohelp_opts; \
__xopt_autohelp_opts.usage = (autohelp_usage); \
__xopt_autohelp_opts.prefix = (autohelp_prefix); \
@ -91,24 +92,29 @@ void shedPrivileges()
// RLIMIT_SIGPENDING
// RLIMIT_STACK
if (setrlimit(RLIMIT_FSIZE, &zeroLimit) != 0) {
if (setrlimit(RLIMIT_FSIZE, &zeroLimit) != 0)
{
perror("setrlimit(RLIMIT_FSIZE, {0, 0})");
exit(-1);
}
if (setrlimit(RLIMIT_NOFILE, &zeroLimit) != 0) {
if (setrlimit(RLIMIT_NOFILE, &zeroLimit) != 0)
{
perror("setrlimit(RLIMIT_NOFILE, {0, 0})");
exit(-1);
}
if (setrlimit(RLIMIT_NPROC, &zeroLimit) != 0) {
if (setrlimit(RLIMIT_NPROC, &zeroLimit) != 0)
{
perror("setrlimit(RLIMIT_NPROC, {0, 0})");
exit(-1);
}
#if !defined (__MACH__)
if (setrlimit(RLIMIT_LOCKS, &zeroLimit) != 0) {
if (setrlimit(RLIMIT_LOCKS, &zeroLimit) != 0)
{
perror("setrlimit(RLIMIT_LOCKS, {0, 0})");
exit(-1);
}
if (setrlimit(RLIMIT_MSGQUEUE, &zeroLimit) != 0) {
if (setrlimit(RLIMIT_MSGQUEUE, &zeroLimit) != 0)
{
perror("setrlimit(RLIMIT_MSGQUEUE, {0, 0})");
exit(-1);
}
@ -134,10 +140,12 @@ static int _tf_command_test(const char* file, int argc, char* argv[])
int extra_count = 0;
const char *err = NULL;
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "test [options]", "options:", NULL, 15);
if (extras) {
if (extras)
{
free((void*)extras);
}
if (err) {
if (err)
{
fprintf(stderr, "Error: %s\n", err);
return 2;
}
@ -150,7 +158,8 @@ static int _tf_command_test(const char* file, int argc, char* argv[])
tf_tests(&test_options);
return 0;
xopt_help:
if (extras) {
if (extras)
{
free((void*)extras);
}
return 1;
@ -177,40 +186,50 @@ static int _tf_command_import(const char* file, int argc, char* argv[])
const char *err = NULL;
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "import [options] [paths] ...", "options:", NULL, 15);
if (err) {
if (err)
{
fprintf(stderr, "Error: %s\n", err);
if (extras) {
if (extras)
{
free((void*)extras);
}
return 2;
}
sqlite3* db = NULL;
if (args.db_path) {
if (args.db_path)
{
sqlite3_open(args.db_path, &db);
}
tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db, NULL);
if (extra_count) {
for (int i = 0; i < extra_count; i++) {
if (extra_count)
{
for (int i = 0; i < extra_count; i++)
{
printf("Importing %s...\n", extras[i]);
tf_ssb_import(ssb, args.user, extras[i]);
}
} else {
}
else
{
printf("Importing %s...\n", "apps");
tf_ssb_import(ssb, args.user, "apps");
}
tf_ssb_destroy(ssb);
if (db) {
if (db)
{
sqlite3_close(db);
}
if (extras) {
if (extras)
{
free((void*)extras);
}
return 0;
xopt_help:
if (extras) {
if (extras)
{
free((void*)extras);
}
return 1;
@ -233,38 +252,47 @@ static int _tf_command_export(const char* file, int argc, char* argv[])
const char *err = NULL;
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "export [options] [paths] ...", "options:", NULL, 15);
if (err) {
if (err)
{
fprintf(stderr, "Error: %s\n", err);
if (extras) {
if (extras)
{
free((void*)extras);
}
return 2;
}
tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, NULL, NULL);
if (extra_count) {
for (int i = 0; i < extra_count; i++) {
if (extra_count)
{
for (int i = 0; i < extra_count; i++)
{
printf("Exporting %s...\n", extras[i]);
tf_ssb_export(ssb, extras[i]);
}
} else {
}
else
{
const char* k_export[] = {
"/~cory/index",
"/~cory/docs",
};
for (int i = 0; i < _countof(k_export); i++) {
for (int i = 0; i < _countof(k_export); i++)
{
printf("Exporting %s...\n", k_export[i]);
tf_ssb_export(ssb, k_export[i]);
}
}
tf_ssb_destroy(ssb);
if (extras) {
if (extras)
{
free((void*)extras);
}
return 0;
xopt_help:
if (extras) {
if (extras)
{
free((void*)extras);
}
return 1;
@ -304,14 +332,17 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
const char *err = NULL;
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "run [options] [paths] ...", "options:", NULL, 15);
if (err) {
if (err)
{
fprintf(stderr, "Error: %s\n", err);
if (extras) {
if (extras)
{
free((void*)extras);
}
return 2;
}
if (extras) {
if (extras)
{
free((void*)extras);
}
@ -340,7 +371,8 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
return result;
xopt_help:
if (extras) {
if (extras)
{
free((void*)extras);
}
return 1;
@ -364,14 +396,17 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[])
const char *err = NULL;
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "sandbox [options]", "options:", NULL, 15);
if (err) {
if (err)
{
fprintf(stderr, "Error: %s\n", err);
if (extras) {
if (extras)
{
free((void*)extras);
}
return 2;
}
if (extras) {
if (extras)
{
free((void*)extras);
}
@ -387,7 +422,8 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[])
return 0;
xopt_help:
if (extras) {
if (extras)
{
free((void*)extras);
}
return 1;
@ -411,10 +447,12 @@ static int _tf_command_post(const char* file, int argc, char* argv[])
int extra_count = 0;
const char *err = NULL;
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "post [options]", "options:", NULL, 15);
if (extras) {
if (extras)
{
free((void*)extras);
}
if (err) {
if (err)
{
fprintf(stderr, "Error: %s\n", err);
return 2;
}
@ -426,7 +464,8 @@ static int _tf_command_post(const char* file, int argc, char* argv[])
return 0;
xopt_help:
if (extras) {
if (extras)
{
free((void*)extras);
}
return 1;
@ -436,7 +475,8 @@ static int _tf_command_usage(const char* file, int argc, char* argv[])
{
printf("Usage: %s command [command-options]\n", file);
printf("commands:\n");
for (int i = 0; i < _countof(k_commands); i++) {
for (int i = 0; i < _countof(k_commands); i++)
{
printf(" %s - %s\n", k_commands[i].name, k_commands[i].description);
}
return 0;
@ -449,15 +489,19 @@ int main(int argc, char* argv[])
tf_taskstub_startup();
#if !defined (_WIN32)
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
{
perror("signal");
}
#endif
if (argc >= 2) {
for (int i = 0; i < _countof(k_commands); i++) {
if (argc >= 2)
{
for (int i = 0; i < _countof(k_commands); i++)
{
const command_t* command = &k_commands[i];
if (strcmp(argv[1], command->name) == 0) {
if (strcmp(argv[1], command->name) == 0)
{
return command->callback(argv[0], argc - 2, argv + 2);
}
}