Minor changes and addition of License

This commit is contained in:
2022-01-16 02:23:13 +11:00
parent 67426fac09
commit aab5682965
9 changed files with 865 additions and 160 deletions

View File

@ -4,7 +4,7 @@
int maxrows = INT_MAX;
int maxcols = INT_MAX;
int colwidth = 10;
int in = 0;
int in;
struct termios base;

View File

@ -5,6 +5,8 @@ char buf;
int pipefd[2];
struct keymap km;
char *keystrings[2] = {"a", "b"};
bool logger_proc(unsigned int level, const char *format, ...) {
return 0;
}

View File

@ -1,7 +1,7 @@
#ifndef KEYS_H
#define KEYS_H
#include <uiohook.h>
#include "uiohook.h"
#include <unistd.h>
#include "timer.h"
#include "display.h"

145
src/splitsio.c Normal file
View File

@ -0,0 +1,145 @@
#include "splitsio.h"
//Splits.io data
const char *schemaver = "v1.0.1";
const char *timersname = "quest";
const char *timerlname = "Quinn's Utterly Elegant Speedrun Timer";
const char *timerver = "v0.5.1";
const char *timerlink = "https://github.com/SilentFungus/quest";
//Imports game/catagory names and segment names
void importSplitsIO(cJSON *splitfile)
{
cJSON *p = NULL;
cJSON *game = NULL;
cJSON *cate = NULL;
cJSON *segs = NULL;
game = cJSON_GetItem(splitfile, "game");
cate = cJSON_GetItem(splitfile, "category");
segs = cJSON_GetItem(splitfile, "segments");
if (game) {
cJSON *title = cJSON_GetItem(game, "longname");
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
gameTitle = malloc(strlen(title->valuestring));
strcpy(gameTitle, title->valuestring);
}
}
if (cate) {
cJSON *title = cJSON_GetItem(cate, "longname");
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
categoryTitle = malloc(strlen(title->valuestring));
strcpy(categoryTitle, title->valuestring);
}
}
if (segs) {
segCount = cJSON_GetArraySize(segs);
segments = calloc(segCount, sizeof(struct segment));
pbrun = calloc(segCount, sizeof(struct segment));
wrrun = calloc(segCount, sizeof(struct segment));
bestsegs = calloc(segCount, sizeof(struct segment));
cJSON *segname = NULL;
int it = 0;
cJSON *iterator = NULL;
cJSON_ArrayForEach(iterator, segs) {
segname = cJSON_GetItem(iterator, "name");
if (cJSON_IsString(segname) && (segname->valuestring != NULL)) {
segments[it].name = malloc(strlen(segname->valuestring));
strcpy(segments[it].name, segname->valuestring);
}
it++;
}
}
cJSON_Delete(splitfile);
}
void exportSplitsIO()
{
//cJSON root node
cJSON *export = NULL;
//Schema version
cJSON *schema = NULL;
//Links
cJSON *links_root = NULL;
cJSON *speedruncom_id = NULL;
cJSON *splitsio_id = NULL;
//Timer
cJSON *timer_root = NULL;
cJSON *timer_shortname = NULL;
cJSON *timer_longname = NULL;
cJSON *timer_version = NULL;
cJSON *timer_website = NULL;
//Attempts
cJSON *attempts_root = NULL;
cJSON *attempts_total = NULL;
cJSON *histories = NULL;
cJSON *history_root = NULL;
cJSON *history_attmpt = NULL;
cJSON *history_dur = NULL;
cJSON *history_dur_rms = NULL;
cJSON *history_dur_gms = NULL;
//Supplementary data
cJSON *image_url = NULL;
cJSON *video_url = NULL;
//Time
cJSON *started_at = NULL;
cJSON *ended_at = NULL;
//Pauses
cJSON *pauses_root = NULL;
cJSON *pause_started = NULL;
cJSON *pause_ended = NULL;
//Game
cJSON *game_root = NULL;
cJSON *game_longname = NULL;
cJSON *game_shortname = NULL;
cJSON *game_links = NULL;
cJSON *game_srcom_id = NULL;
cJSON *game_splits_id = NULL;
//Catagory
cJSON *cate_root = NULL;
cJSON *cate_longname = NULL;
cJSON *cate_shortname = NULL;
cJSON *cate_links = NULL;
cJSON *cate_splits_id = NULL;
cJSON *cate_spdrun_id = NULL;
//Runners
cJSON *runner_root = NULL;
cJSON *runner_longname = NULL;
cJSON *runner_shrtname = NULL;
cJSON *runner_links = NULL;
cJSON *runner_twitch = NULL;
cJSON *runner_spltsio = NULL;
cJSON *runner_spdrun = NULL;
cJSON *runner_twitter = NULL;
//Segments
cJSON *seg_root = NULL;
cJSON *seg_name = NULL;
cJSON *seg_ended = NULL;
cJSON *seg_ended_rms = NULL;
cJSON *seg_ended_gms = NULL;
cJSON *seg_best = NULL;
cJSON *seg_best_rms = NULL;
cJSON *seg_best_gms = NULL;
cJSON *seg_is_skipped = NULL;
cJSON *seg_is_reset = NULL;
cJSON *seg_histories = NULL;
cJSON *seg_hst_attmp = NULL;
cJSON *seg_hst_end = NULL;
cJSON *seg_hst_end_rms = NULL;
cJSON *seg_hst_end_gms = NULL;
cJSON *seg_hst_skp = NULL;
cJSON *seg_hst_rst = NULL;
}

16
src/splitsio.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef SPLITSIO
#define SPLITSIO
#include "cJSON.h"
#include "timer.h"
const char *schemaver;
const char *timersname;
const char *timerlname;
const char *timerver;
const char *timerlink;
void importSplitsIO(cJSON *splitfile);
void exportSplitsIO();
#endif

View File

@ -6,7 +6,7 @@
struct timespec timestart, finish, notif;
int currentMS = 0;
int timeSave = 0;
bool timerActive;
bool timerActive = false;
//UI
struct color bg = { 47, 53, 66};
@ -19,13 +19,6 @@ int h, w;
bool compact = false;
bool dirty = false;
//Splits.io data
const char *schemaver = "v1.0.1";
const char *timersname = "quest";
const char *timerlname = "Quinn's Utterly Elegant Speedrun Timer";
const char *timerver = "v0.5.1";
const char *timerlink = "https://github.com/SilentFungus/quest";
//Run data
char *filepath;
char *gameTitle = "title not loaded";
@ -453,22 +446,23 @@ void calculateBestSegs()
}
}
void loadConfig()
{
char path[256];
strcat(strcpy(path, getenv("HOME")), "/.config/quest");
mkdir(path, 0777);
strcat(strcpy(path, getenv("HOME")), "/.config/quest/keymaps");
mkdir(path, 0777);
strcat(strcpy(path, getenv("HOME")), "/.config/quest/keymaps/default");
FILE* fp = fopen(path, "r");
fclose(fp);
}
//TODO: it'll be more efficent if all the segments pointers point at the same
//instance of the segments name, instead of copying the contents over
void loadFile()
{
//char path[256];
//strcat(strcpy(path, getenv("HOME")), "/.config/qtimer");
//mkdir(path, 0777);
//strcat(strcpy(path, getenv("HOME")), "/.config/qtimer/keymaps");
//mkdir(path, 0777);
//strcat(strcpy(path, getenv("HOME")), "/.config/qtimer/keymaps/default");
//FILE* fp = fopen(path, "r");
// READING THE FILE TO A BUFFER
//fclose(fp);
char *buffer = NULL;
long length;
FILE *f = fopen(filepath, "rb");
@ -578,141 +572,6 @@ void loadFile()
calculateBestSegs();
}
//Imports game/catagory names and segment names
void importSplitsIO(cJSON *splitfile)
{
cJSON *game = NULL;
cJSON *cate = NULL;
cJSON *segs = NULL;
game = cJSON_GetItem(splitfile, "game");
cate = cJSON_GetItem(splitfile, "category");
segs = cJSON_GetItem(splitfile, "segments");
if (game) {
cJSON *title = cJSON_GetItem(game, "longname");
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
gameTitle = malloc(strlen(title->valuestring));
strcpy(gameTitle, title->valuestring);
}
}
if (cate) {
cJSON *title = cJSON_GetItem(cate, "longname");
if (cJSON_IsString(title) && (title->valuestring != NULL)) {
categoryTitle = malloc(strlen(title->valuestring));
strcpy(categoryTitle, title->valuestring);
}
}
if (segs) {
segCount = cJSON_GetArraySize(segs);
segments = calloc(segCount, sizeof(struct segment));
pbrun = calloc(segCount, sizeof(struct segment));
wrrun = calloc(segCount, sizeof(struct segment));
bestsegs = calloc(segCount, sizeof(struct segment));
cJSON *segname = NULL;
int it = 0;
cJSON *iterator = NULL;
cJSON_ArrayForEach(iterator, segs) {
segname = cJSON_GetItem(iterator, "name");
if (cJSON_IsString(segname) && (segname->valuestring != NULL)) {
segments[it].name = malloc(strlen(segname->valuestring));
strcpy(segments[it].name, segname->valuestring);
}
it++;
}
}
cJSON_Delete(splitfile);
}
void exportSplitsIO()
{
//cJSON root node
cJSON *export = NULL;
//Schema version
cJSON *schema = NULL;
//Links
cJSON *links_root = NULL;
cJSON *speedruncom_id = NULL;
cJSON *splitsio_id = NULL;
//Timer
cJSON *timer_root = NULL;
cJSON *timer_shortname = NULL;
cJSON *timer_longname = NULL;
cJSON *timer_version = NULL;
cJSON *timer_website = NULL;
//Attempts
cJSON *attempts_root = NULL;
cJSON *attempts_total = NULL;
cJSON *histories = NULL;
cJSON *history_root = NULL;
cJSON *history_attmpt = NULL;
cJSON *history_dur = NULL;
cJSON *history_dur_rms = NULL;
cJSON *history_dur_gms = NULL;
//Supplementary data
cJSON *image_url = NULL;
cJSON *video_url = NULL;
//Time
cJSON *started_at = NULL;
cJSON *ended_at = NULL;
//Pauses
cJSON *pauses_root = NULL;
cJSON *pause_started = NULL;
cJSON *pause_ended = NULL;
//Game
cJSON *game_root = NULL;
cJSON *game_longname = NULL;
cJSON *game_shortname = NULL;
cJSON *game_links = NULL;
cJSON *game_srcom_id = NULL;
cJSON *game_splits_id = NULL;
//Catagory
cJSON *cate_root = NULL;
cJSON *cate_longname = NULL;
cJSON *cate_shortname = NULL;
cJSON *cate_links = NULL;
cJSON *cate_splits_id = NULL;
cJSON *cate_spdrun_id = NULL;
//Runners
cJSON *runner_root = NULL;
cJSON *runner_longname = NULL;
cJSON *runner_shrtname = NULL;
cJSON *runner_links = NULL;
cJSON *runner_twitch = NULL;
cJSON *runner_spltsio = NULL;
cJSON *runner_spdrun = NULL;
cJSON *runner_twitter = NULL;
//Segments
cJSON *seg_root = NULL;
cJSON *seg_name = NULL;
cJSON *seg_ended = NULL;
cJSON *seg_ended_rms = NULL;
cJSON *seg_ended_gms = NULL;
cJSON *seg_best = NULL;
cJSON *seg_best_rms = NULL;
cJSON *seg_best_gms = NULL;
cJSON *seg_is_skipped = NULL;
cJSON *seg_is_reset = NULL;
cJSON *seg_histories = NULL;
cJSON *seg_hst_attmp = NULL;
cJSON *seg_hst_end = NULL;
cJSON *seg_hst_end_rms = NULL;
cJSON *seg_hst_end_gms = NULL;
cJSON *seg_hst_skp = NULL;
cJSON *seg_hst_rst = NULL;
}
void saveFile()
{
@ -783,7 +642,6 @@ void saveFile()
int main(int argc, char **argv)
{
timerActive = false;
filepath = argv[1];
hook_set_logger_proc(&logger_proc);
hook_set_dispatch_proc(&dispatch_proc);

View File

@ -36,6 +36,14 @@ struct pastseg
bool isReset;
};
extern char *gameTitle;
extern char *categoryTitle;
extern int segCount;
extern struct segment *pbrun;
extern struct segment *bestsegs;
extern struct segment *wrrun;
extern struct segment *segments;
void sub_timespec(struct timespec t1, struct timespec t2, struct timespec* td);
void add_timespec(struct timespec t1, struct timespec t2, struct timespec* td);
void start();