diff --git a/main.c b/main.c index 11cdb5f..0a14663 100644 --- a/main.c +++ b/main.c @@ -14,10 +14,21 @@ size_t cursor; void die(char *msg) { endwin(); - printf("%s: %s\n", msg, strerror(errno)); + printf("%s: %s\n", strerror(errno), msg); exit(1); } +void export(void) { + FILE *fp = fopen("export", "a"); + if (fp == NULL) + die(""); + + for (size_t i = 0; i < timer_size; i++) + fprintf(fp, "%ld%ld,", timer[i].sec, timer[i].msec / 10); + + fclose(fp); +} + void add_value(clock_t sec, clock_t msec) { timer_size++; @@ -57,6 +68,11 @@ void keyboard(clock_t sec, clock_t mcsec) { clear(); break; + case 'e': + endwin(); + export(); + exit(0); + case 'q': endwin(); exit(0); @@ -106,7 +122,7 @@ int main(void) { clock_t sec = mcsec / 1000000; clock_t msec = (mcsec / 100000) % 10; - mvprintw(1, 2, "[q - quit] [' ' - add mark] [w/s - control] [p - pause]"); + mvprintw(1, 2, "[q quit] [e export] [' ' add mark] [w/s control] [p pause]"); mvprintw(3, 2, "%ld.%ld", sec, msec); print_timer();