From 10014d6cfa477a1374cda27cddc4ae0490e9dd2c Mon Sep 17 00:00:00 2001 From: Jacob Garby Date: Thu, 3 Oct 2024 10:45:58 +0200 Subject: [PATCH] Consistent code formatting --- c/.clang-format | 1 + c/client/arg.c | 23 ++++++++++++----------- c/client/client.c | 34 ++++++++++++---------------------- c/common/common.c | 22 ++++++++++------------ c/include/client.h | 14 +++++++------- c/include/resman.h | 4 ++-- c/server/server.c | 22 ++++++++++------------ 7 files changed, 54 insertions(+), 66 deletions(-) diff --git a/c/.clang-format b/c/.clang-format index 81dd40c..cfcebd7 100644 --- a/c/.clang-format +++ b/c/.clang-format @@ -1,3 +1,4 @@ --- BasedOnStyle: Google IndentWidth: 4 +AlignArrayOfStructures: Left diff --git a/c/client/arg.c b/c/client/arg.c index eb448f5..4b318a1 100644 --- a/c/client/arg.c +++ b/c/client/arg.c @@ -1,15 +1,16 @@ // vim: fdm=marker -#include "client.h" #include #include #include -void print_subcmds(char *prog) {/*{{{*/ +#include "client.h" + +void print_subcmds(char *prog) { /*{{{*/ fprintf(stderr, "Usage: %s [subcommand] \n", prog); fprintf(stderr, "Valid subcommands: [r]un, [t]ime, [q]ueue\n"); -}/*}}}*/ +} /*}}}*/ -static unsigned int parse_duration(const char *s) {/*{{{*/ +static unsigned int parse_duration(const char *s) { /*{{{*/ unsigned int secs = 0; unsigned long acc; char *endptr; @@ -53,9 +54,9 @@ static unsigned int parse_duration(const char *s) {/*{{{*/ } return secs; -}/*}}}*/ +} /*}}}*/ -error_t parser_run(int key, char *arg, struct argp_state *state){/*{{{*/ +error_t parser_run(int key, char *arg, struct argp_state *state) { /*{{{*/ struct args_run *args = (struct args_run *)state->input; switch (key) { @@ -85,9 +86,9 @@ error_t parser_run(int key, char *arg, struct argp_state *state){/*{{{*/ } return 0; -}/*}}}*/ +} /*}}}*/ -error_t parser_time(int key, char *arg, struct argp_state *state){/*{{{*/ +error_t parser_time(int key, char *arg, struct argp_state *state) { /*{{{*/ struct args_time *args = (struct args_time *)state->input; switch (key) { @@ -117,8 +118,8 @@ error_t parser_time(int key, char *arg, struct argp_state *state){/*{{{*/ } return 0; -}/*}}}*/ +} /*}}}*/ -error_t parser_queue(int key, char *arg, struct argp_state *state){/*{{{*/ +error_t parser_queue(int key, char *arg, struct argp_state *state) { /*{{{*/ return 0; -}/*}}}*/ +} /*}}}*/ diff --git a/c/client/client.c b/c/client/client.c index f2708b4..12d4d00 100644 --- a/c/client/client.c +++ b/c/client/client.c @@ -1,47 +1,38 @@ // vim: fdm=marker #include "client.h" +#include #include +#include #include #include #include #include -#include #include -#include -int main(int argc, char **argv) {/*{{{*/ +int main(int argc, char **argv) { /*{{{*/ if (argc < 2) { print_subcmds(argv[0]); return EXIT_FAILURE; } - if (!strcmp(argv[1], "run") || !strcmp(argv[1], "r")) - { + if (!strcmp(argv[1], "run") || !strcmp(argv[1], "r")) { return subcmd_run(argc, argv); - } - else if (!strcmp(argv[1], "time") || !strcmp(argv[1], "t")) - { + } else if (!strcmp(argv[1], "time") || !strcmp(argv[1], "t")) { return subcmd_time(argc, argv); - } - else if (!strcmp(argv[1], "queue") || !strcmp(argv[1], "q")) - { + } else if (!strcmp(argv[1], "queue") || !strcmp(argv[1], "q")) { return subcmd_queue(argc, argv); - } - else if (!strcmp(argv[1], "version") || !strcmp(argv[1], "v")) - { - printf("Resman client version "CLIENT_VER_STRING".\n"); - } - else - { + } else if (!strcmp(argv[1], "version") || !strcmp(argv[1], "v")) { + printf("Resman client version " CLIENT_VER_STRING ".\n"); + } else { print_subcmds(argv[0]); return EXIT_FAILURE; } return 0; -}/*}}}*/ +} /*}}}*/ -int connect_to_server(const char *addr) {/*{{{*/ +int connect_to_server(const char *addr) { /*{{{*/ int soc; struct sockaddr_un sa_server; unsigned int sa_len; @@ -59,5 +50,4 @@ int connect_to_server(const char *addr) {/*{{{*/ } return soc; -}/*}}}*/ - +} /*}}}*/ diff --git a/c/common/common.c b/c/common/common.c index 13d95a6..c020192 100644 --- a/c/common/common.c +++ b/c/common/common.c @@ -1,15 +1,13 @@ -#include "resman.h" - -#include -#include #include #include +#include +#include + +#include "resman.h" const char *socket_addr = "/tmp/resman.sock"; -void free_job_descriptor(job_descriptor *job) { - free(job->msg); -} +void free_job_descriptor(job_descriptor *job) { free(job->msg); } int ser32(char *b, uint32_t x) { for (int j = 3; j >= 0; j--) { @@ -92,14 +90,14 @@ int deserialise_job(const char *buf, size_t len, job_descriptor *job) { job->req_type = (enum job_type)buf[i++]; i += deser32(&buf[i], &job->uid); - i += deser64(&buf[i], (uint64_t*)&job->t_submitted); - i += deser64(&buf[i], (uint64_t*)&job->t_started); - i += deser64(&buf[i], (uint64_t*)&job->t_ended); + i += deser64(&buf[i], (uint64_t *)&job->t_submitted); + i += deser64(&buf[i], (uint64_t *)&job->t_started); + i += deser64(&buf[i], (uint64_t *)&job->t_ended); if (job->req_type == JOB_CMD) { - i += deser32(&buf[i], (uint32_t*)&job->cmd.pid); + i += deser32(&buf[i], (uint32_t *)&job->cmd.pid); } else if (job->req_type == JOB_TIMESLOT) { - i += deser32(&buf[i], (uint32_t*)&job->timeslot.secs); + i += deser32(&buf[i], (uint32_t *)&job->timeslot.secs); } else { return -1; } diff --git a/c/include/client.h b/c/include/client.h index feb0bef..cb98823 100644 --- a/c/include/client.h +++ b/c/include/client.h @@ -38,24 +38,24 @@ struct args_queue { static struct argp_option options_run[] = { {"msg", 'm', "MESSAGE", 0, "Description of your job.", 0}, {"verbose", 'V', 0, 0, "Give verbose output.", 0}, - {0}, + {0, 0, 0, 0, 0, 0}, }; static struct argp argp_run = { options_run, &parser_run, "COMMAND", "Submits a job to resmand.", - NULL, NULL, NULL -}; + NULL, NULL, NULL}; static struct argp_option options_time[] = { {"msg", 'm', "MESSAGE", 0, "Explanation for your reservation.", 0}, {"verbose", 'V', 0, 0, "Give verbose output.", 0}, - {0}, + {0, 0, 0, 0, 0, 0}, }; static struct argp argp_time = { - options_time, &parser_time, "DURATION", "Reserves the server for some time.", - NULL, NULL, NULL -}; + options_time, &parser_time, + "DURATION", "Reserves the server for some time.", + NULL, NULL, + NULL}; /*}}}*/ diff --git a/c/include/resman.h b/c/include/resman.h index f6b9865..c082120 100644 --- a/c/include/resman.h +++ b/c/include/resman.h @@ -2,9 +2,9 @@ #ifndef RESMAN_H #define RESMAN_H +#include /* fopen(), printf() */ #include /* uid_t, pid_t */ -#include /* time() */ -#include /* fopen(), printf() */ +#include /* time() */ #define UNUSED __attribute__((unused)) diff --git a/c/server/server.c b/c/server/server.c index 6934c27..708d453 100644 --- a/c/server/server.c +++ b/c/server/server.c @@ -1,24 +1,22 @@ // vim: fdm=marker -#include "resman.h" - +#include /* signal() */ +#include +#include #include #include #include - #include -#include -#include -#include /* signal() */ +#include "resman.h" #define LISTEN_QUEUE 8 -void sigint_handler(int sig UNUSED) {/*{{{*/ +void sigint_handler(int sig UNUSED) { /*{{{*/ printf("Caught SIGINT: exiting.\n"); exit(EXIT_SUCCESS); -}/*}}}*/ +} /*}}}*/ -int main(void) {/*{{{*/ +int main(void) { /*{{{*/ int soc_listen, soc_client; struct sockaddr_un sa_local = {0}; struct sockaddr_un sa_client = {0}; @@ -61,8 +59,8 @@ int main(void) {/*{{{*/ printf("[info] Client connected.\n"); int bytes_read; - if ((bytes_read = recv(soc_client, read_buf, - JOB_SER_MAXLEN, 0)) == -1) { + if ((bytes_read = recv(soc_client, read_buf, JOB_SER_MAXLEN, 0)) == + -1) { fprintf(stderr, "Failed to read from client.\n"); } @@ -70,4 +68,4 @@ int main(void) {/*{{{*/ close(soc_client); } -}/*}}}*/ +} /*}}}*/