commit 91265cc0990ac44347b78e0960a8faace24e6bcb
parent eed97e91baa1f64580828fc38fcaf4699b514987
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Mon, 21 Aug 2023 11:11:07 +0200
run formatting pass.
Diffstat:
| M | pomo.c | | | 89 | +++++++++++++++++++++++++++++++++++++++++-------------------------------------- |
1 file changed, 46 insertions(+), 43 deletions(-)
diff --git a/pomo.c b/pomo.c
@@ -1,41 +1,43 @@
-#include <stdio.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <time.h>
+#include <unistd.h>
#define MAX_MSG_LEN 100
-#define LEN(a) (sizeof(a) / sizeof(a[0]))
+#define LEN(a) (sizeof(a) / sizeof(a[0]))
typedef struct {
- unsigned int t;
- char *msg;
+ unsigned int t;
+ char* msg;
} Timers;
static Timers timers[] = {
- /* timer(s) comment */
- { 1500, "Time to start working!"},
- { 300, "Time to start resting!"},
- { 1500, "Time to start working!"},
- { 300, "Time to start resting!"},
- { 1500, "Time to start working!"},
- { 300, "Time to start resting!"},
- { 1500, "Time to start working!"},
- { 900, "Time to take a longer rest!" },
+ /* timer(s) comment */
+ { 1500, "Time to start working!" },
+ { 300, "Time to start resting!" },
+ { 1500, "Time to start working!" },
+ { 300, "Time to start resting!" },
+ { 1500, "Time to start working!" },
+ { 300, "Time to start resting!" },
+ { 1500, "Time to start working!" },
+ { 900, "Time to take a longer rest!" },
};
-void spawn(char *argv[]){
- if (fork() == 0) {
- // we need to fork the process so that
- // when we exit the sent screen
- // this program continues.
- setsid();
- execvp(argv[0], argv);
- perror(" failed");
- exit(0);
- }
+void spawn(char* argv[])
+{
+ if (fork() == 0) {
+ // we need to fork the process so that
+ // when we exit the sent screen
+ // this program continues.
+ setsid();
+ execvp(argv[0], argv);
+ perror(" failed");
+ exit(0);
+ }
}
-void print_time_now(){
+void print_time_now()
+{
time_t timer;
char buffer[26];
struct tm* tm_info;
@@ -45,27 +47,28 @@ void print_time_now(){
strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
fprintf(stderr, "%s", buffer);
-
}
-void display_message(char *msg){
- char sh_command[MAX_MSG_LEN];
- snprintf(sh_command, MAX_MSG_LEN, "echo '%s' | sent", msg); // NOLINT: We are being carefull here by considering MAX_MSG_LEN explicitly.
+void display_message(char* msg)
+{
+ char sh_command[MAX_MSG_LEN];
+ snprintf(sh_command, MAX_MSG_LEN, "echo '%s' | sent", msg); // NOLINT: We are being carefull here by considering MAX_MSG_LEN explicitly.
printf("%s", sh_command);
- char *spawn_args[] = {
- "/bin/sh",
- "-c",
- sh_command,
- NULL
- };
- spawn(spawn_args);
- print_time_now();
- fprintf(stderr, " | %s\n", msg);
+ char* spawn_args[] = {
+ "/bin/sh",
+ "-c",
+ sh_command,
+ NULL
+ };
+ spawn(spawn_args);
+ print_time_now();
+ fprintf(stderr, " | %s\n", msg);
}
-int main(int argc, char *argv[]){
- for(int i=0; ; i = (i+1) % LEN(timers)){
- display_message(timers[i].msg);
- sleep(timers[i].t);
- }
+int main(int argc, char* argv[])
+{
+ for (int i = 0;; i = (i + 1) % LEN(timers)) {
+ display_message(timers[i].msg);
+ sleep(timers[i].t);
+ }
}