diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ffd02c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ +Copyright (c) 2015-2020, Ivan Tham + 2023- , Nuño Sempere + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/config.h b/config.h deleted file mode 100644 index 7f2e0ba..0000000 --- a/config.h +++ /dev/null @@ -1,26 +0,0 @@ -typedef enum { - start_work, - start_small_break, - start_long_break -} pomodoro_period; - -static char *notify_start_work = ""; -static char *notify_start_small_break = ""; -static char *notify_start_long_break = ""; - -typedef struct { - unsigned int tmr; - pomodoro_period p; -} Timers; - -static Timers timers[] = { - /* timer(s) comment */ - { 1500, start_work}, - { 300, start_small_break}, - { 1500, start_work}, - { 300, start_small_break}, - { 1500, start_work}, - { 300, start_small_break}, - { 1500, start_work}, - { 900, start_long_break}, -}; diff --git a/spt.c b/spt.c new file mode 100644 index 0000000..1a6e94e --- /dev/null +++ b/spt.c @@ -0,0 +1,58 @@ +#include // for the "sleep" & exec functions +#include // snprintf +#include // exit + +#define MAX_MSG_LEN 100 +#define LEN(a) (sizeof(a) / sizeof(a[0])) + +typedef struct { + 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!" }, +}; + +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); + // printfn("spt: execvp %s\n", argv[0]); + perror(" failed"); + exit(0); + } +} + +void display_message_with_sent(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_ERROR_LENGTH explicitly. + printf("%s", sh_command); + char *spawn_args[] = { + "/bin/bash", + "-c", + sh_command, + NULL + }; + fprintf(stderr, "%s\n", msg); + spawn(spawn_args); +} + +int main(int argc, char *argv[]){ + for(int i=0; ; i = (i+1) % LEN(timers)){ + display_message_with_sent(timers[i].msg); + sleep(timers[i].t); + } +}