print time when changing period

This commit is contained in:
NunoSempere 2023-08-20 13:32:54 +02:00
parent 168b4f092c
commit 312bd09739
2 changed files with 16 additions and 1 deletions

BIN
pomo Executable file

Binary file not shown.

17
pomo.c
View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <time.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]))
@ -34,6 +35,19 @@ void spawn(char *argv[]){
} }
} }
void print_time_now(){
time_t timer;
char buffer[26];
struct tm* tm_info;
timer = time(NULL);
tm_info = localtime(&timer);
strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
fprintf(stderr, "%s", buffer);
}
void display_message(char *msg){ void display_message(char *msg){
char sh_command[MAX_MSG_LEN]; 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. snprintf(sh_command, MAX_MSG_LEN, "echo '%s' | sent", msg); // NOLINT: We are being carefull here by considering MAX_MSG_LEN explicitly.
@ -45,7 +59,8 @@ void display_message(char *msg){
NULL NULL
}; };
spawn(spawn_args); spawn(spawn_args);
// fprintf(stderr, "%s\n", msg); print_time_now();
fprintf(stderr, " | %s\n", msg);
} }
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){