Compare commits
2 Commits
5075fb8ad8
...
91265cc099
Author | SHA1 | Date | |
---|---|---|---|
91265cc099 | |||
eed97e91ba |
17
makefile
17
makefile
|
@ -1,8 +1,17 @@
|
||||||
build:
|
CC=gcc
|
||||||
gcc pomo.c -o pomo
|
SRC=pomo.c
|
||||||
|
OUT=pomo
|
||||||
|
STYLE_BLUEPRINT=webkit
|
||||||
|
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
||||||
|
|
||||||
|
build: $(SRC)
|
||||||
|
$(CC) $(SRC) -o $(OUT)
|
||||||
|
|
||||||
install:
|
install:
|
||||||
cp ./pomo /bin/pomo
|
cp ./$(OUT) /bin/pomo
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
clang-tidy pomo.c --
|
clang-tidy $(SRC) --
|
||||||
|
|
||||||
|
format:
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
89
pomo.c
89
pomo.c
|
@ -1,41 +1,43 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define MAX_MSG_LEN 100
|
#define MAX_MSG_LEN 100
|
||||||
#define LEN(a) (sizeof(a) / sizeof(a[0]))
|
#define LEN(a) (sizeof(a) / sizeof(a[0]))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int t;
|
unsigned int t;
|
||||||
char *msg;
|
char* msg;
|
||||||
} Timers;
|
} Timers;
|
||||||
|
|
||||||
static Timers timers[] = {
|
static Timers timers[] = {
|
||||||
/* timer(s) comment */
|
/* timer(s) comment */
|
||||||
{ 1500, "Time to start working!"},
|
{ 1500, "Time to start working!" },
|
||||||
{ 300, "Time to start resting!"},
|
{ 300, "Time to start resting!" },
|
||||||
{ 1500, "Time to start working!"},
|
{ 1500, "Time to start working!" },
|
||||||
{ 300, "Time to start resting!"},
|
{ 300, "Time to start resting!" },
|
||||||
{ 1500, "Time to start working!"},
|
{ 1500, "Time to start working!" },
|
||||||
{ 300, "Time to start resting!"},
|
{ 300, "Time to start resting!" },
|
||||||
{ 1500, "Time to start working!"},
|
{ 1500, "Time to start working!" },
|
||||||
{ 900, "Time to take a longer rest!" },
|
{ 900, "Time to take a longer rest!" },
|
||||||
};
|
};
|
||||||
|
|
||||||
void spawn(char *argv[]){
|
void spawn(char* argv[])
|
||||||
if (fork() == 0) {
|
{
|
||||||
// we need to fork the process so that
|
if (fork() == 0) {
|
||||||
// when we exit the sent screen
|
// we need to fork the process so that
|
||||||
// this program continues.
|
// when we exit the sent screen
|
||||||
setsid();
|
// this program continues.
|
||||||
execvp(argv[0], argv);
|
setsid();
|
||||||
perror(" failed");
|
execvp(argv[0], argv);
|
||||||
exit(0);
|
perror(" failed");
|
||||||
}
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_time_now(){
|
void print_time_now()
|
||||||
|
{
|
||||||
time_t timer;
|
time_t timer;
|
||||||
char buffer[26];
|
char buffer[26];
|
||||||
struct tm* tm_info;
|
struct tm* tm_info;
|
||||||
|
@ -45,27 +47,28 @@ void print_time_now(){
|
||||||
|
|
||||||
strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
|
strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
|
||||||
fprintf(stderr, "%s", buffer);
|
fprintf(stderr, "%s", buffer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_message(char *msg){
|
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.
|
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);
|
printf("%s", sh_command);
|
||||||
char *spawn_args[] = {
|
char* spawn_args[] = {
|
||||||
"/bin/sh",
|
"/bin/sh",
|
||||||
"-c",
|
"-c",
|
||||||
sh_command,
|
sh_command,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
spawn(spawn_args);
|
spawn(spawn_args);
|
||||||
print_time_now();
|
print_time_now();
|
||||||
fprintf(stderr, " | %s\n", msg);
|
fprintf(stderr, " | %s\n", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char* argv[])
|
||||||
for(int i=0; ; i = (i+1) % LEN(timers)){
|
{
|
||||||
display_message(timers[i].msg);
|
for (int i = 0;; i = (i + 1) % LEN(timers)) {
|
||||||
sleep(timers[i].t);
|
display_message(timers[i].msg);
|
||||||
}
|
sleep(timers[i].t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user