Загрузить файлы в «/»

This commit is contained in:
8nlight 2023-09-15 00:36:33 +03:00
parent 9a7e416ae1
commit 3736860917
3 changed files with 115 additions and 1 deletions

9
Makefile Normal file
View File

@ -0,0 +1,9 @@
CC?=cc
CFLAGS?=-s -Wall -Wextra -pedantic -O0
LDFLAGS?=-lncurses
all:
$(CC) main.c -osm $(CFLAGS) $(LDFLAGS)
clean:
rm sm

View File

@ -1,2 +1,9 @@
# sm
quit - q
change cursor pos - w q
add - space

98
main.c Normal file
View File

@ -0,0 +1,98 @@
#include <ncurses.h>
#include <stdlib.h>
#include <time.h>
typedef struct {
clock_t sec;
clock_t msec;
} TIME;
TIME *timer;
size_t timer_size;
size_t cursor;
void die(char *msg) {
endwin();
puts(msg);
exit(1);
}
void add_value(clock_t sec, clock_t msec) {
timer_size += 1;
timer = realloc(timer, (1 + timer_size) * sizeof(TIME));
if (timer == NULL)
die("realloc returned NULL");
timer[timer_size].sec = sec;
timer[timer_size].msec = msec;
}
int main(void) {
/* Init array */
timer = malloc(sizeof(TIME));
if (timer == NULL)
die("malloc returned NULL");
initscr();
timeout(0);
curs_set(0);
while (1) {
/* Microsecond */
clock_t mcsec = clock();
if (mcsec == -1)
die("Yes");
clock_t sec = mcsec / 1000000;
clock_t msec = (mcsec / 100000) % 10;
mvprintw(1, 2, "%ld.%ld", sec, msec);
/* Print timer array */
if (timer_size > 0) {
/* Start y */
unsigned int j = 3;
mvprintw(j, 0, ">");
for (size_t i = cursor; i < cursor + 10; i++) {
if (i > timer_size)
break;
mvprintw(j++, 2, "(%ld) %ld.%ld", i, timer[i].sec, timer[i].msec);
}
}
refresh();
/* Functions */
switch (getch()) {
case ' ':
clear();
add_value(sec, mcsec / 10000);
cursor = timer_size;
break;
case 'w':
clear();
if (cursor + 1 <= timer_size)
cursor++;
break;
case 's':
clear();
if (cursor - 1 > 0)
cursor--;
break;
case 'q':
die("Succesfull exit");
default:
break;
}
}
}