segments
parent
5c0f3b9891
commit
83a92f8675
@ -0,0 +1,49 @@
|
||||
//this file to be compiled as a shared object
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
//linux
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
static void *addr;
|
||||
static pid_t pid;
|
||||
static long long value;
|
||||
struct iovec local[1];
|
||||
struct iovec remote[1];
|
||||
|
||||
void set_pid(pid_t p) {
|
||||
pid = p;
|
||||
}
|
||||
|
||||
//value to compare against
|
||||
void set_value(long long val) {
|
||||
value = val;
|
||||
}
|
||||
|
||||
bool scan(void *addr, size_t type) {
|
||||
long long values[1];
|
||||
local[0].iov_base = values;
|
||||
local[0].iov_len = sizeof(long long); //may or may not get extra values
|
||||
|
||||
remote[0].iov_base = addr;
|
||||
remote[0].iov_len = local[0].iov_len;
|
||||
|
||||
process_vm_readv(pid, local, 1, remote, 1, 0);
|
||||
|
||||
//write your comparison function here
|
||||
|
||||
//switch on type to trim possible garbage data
|
||||
switch(type) {
|
||||
case sizeof(char):
|
||||
if ((char)value == (char)values[0]) {return true;} break;
|
||||
if ((short)value == (short)values[0]) {return true;} break;
|
||||
if ((int)value == (int)values[0]) {return true;} break;
|
||||
if ((long)value == (long)values[0]) {return true;} break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
#include <dlfcn.h>
|
||||
|
||||
void load_module(const char *path) {
|
||||
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
#include "splits.h"
|
||||
#include "parser.h"
|
||||
#include "timer.h"
|
||||
|
||||
void print_segment(segment *seg) {
|
||||
printf("%s\n", seg->name);
|
||||
//printf("%ld.%ld\n", seg->realtime.tv_sec, seg->realtime.tv_nsec);
|
||||
}
|
||||
|
||||
struct timespec parse_time(char *str) {
|
||||
struct timespec time;
|
||||
|
||||
time_t hour_t;
|
||||
time_t min_t;
|
||||
time_t sec_t;
|
||||
time_t nsec_t;
|
||||
|
||||
sscanf(str, "%ld:%ld:%ld.%ld", &hour_t, &min_t, &sec_t, &nsec_t);
|
||||
|
||||
time.tv_sec = (hour_t * 3600) + (min_t * 60) + (sec_t);
|
||||
time.tv_nsec = nsec_t * 1e+7f;
|
||||
|
||||
//printf("%lf\n", timespec_to_double(time));
|
||||
//180.500_000_000
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
segment *read_segment(char *file, char *line) {
|
||||
segment *seg = calloc(1, sizeof(segment));
|
||||
|
||||
while (strcmp(line, "end")) {
|
||||
char *key = strip(cut_back(line, ':'), ' ');
|
||||
char *value = cut_front(strip(line, ' '), ' ');
|
||||
|
||||
|
||||
if (!strcmp(key, "name")) {
|
||||
seg->name = strdup(value);
|
||||
}
|
||||
|
||||
if (!strcmp(key, "gametime")) {
|
||||
seg->gametime = parse_time(value);
|
||||
}
|
||||
|
||||
if (!strcmp(key, "realtime")) {
|
||||
seg->realtime = parse_time(value);
|
||||
}
|
||||
|
||||
if (!strcmp(key, "best")) {
|
||||
seg->best = parse_time(value);
|
||||
}
|
||||
|
||||
free(key);
|
||||
line = get_next_line(file, 0);
|
||||
}
|
||||
|
||||
return seg;
|
||||
}
|
||||
|
||||
segment_list open_splits_file(const char *path) {
|
||||
char *file = load_file(path);
|
||||
int idx = 0;
|
||||
int cnt = 0;
|
||||
segment_list segments = {0};
|
||||
|
||||
char *line = get_next_line(file, 0);
|
||||
|
||||
//enumerate segments
|
||||
while (line != NULL) {
|
||||
if (!strcmp(line, "segment")) {
|
||||
segments.cnt++;
|
||||
}
|
||||
line = get_next_line(file, 0);
|
||||
}
|
||||
|
||||
//reset strtok_r and create fresh file since it modified it
|
||||
get_next_line(NULL, 1);
|
||||
free(file); file = load_file(path);
|
||||
|
||||
//make an extra one so the last segment->next == NULL;
|
||||
segments.list = calloc(cnt + 1, sizeof(segment *));
|
||||
|
||||
line = get_next_line(file, 0);
|
||||
|
||||
//create segments
|
||||
while (line != NULL) {
|
||||
if (!strcmp(line, "segment")) {
|
||||
segments.list[idx] = read_segment(file, line);
|
||||
idx++;
|
||||
}
|
||||
|
||||
line = get_next_line(file, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
segments.list[i]->next = segments.list[i+1];
|
||||
}
|
||||
|
||||
//check
|
||||
/*for (int i = 0; i < idx; i++) {
|
||||
printf("%p\n", segments[i]);
|
||||
}*/
|
||||
|
||||
//no leaky
|
||||
free(file);
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
//probably need a thing to free all the segments
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
game: The Game
|
||||
|
||||
segment
|
||||
name: Segment 1
|
||||
gametime: 00:01:00.50
|
||||
realtime: 00:02:00.00
|
||||
best: 00:01:00.00
|
||||
end
|
||||
|
||||
segment
|
||||
name: Segment 2
|
||||
gametime: 00:02:00.57
|
||||
realtime: 00:04:00.00
|
||||
best: 00:01:00.00
|
||||
end
|
||||
|
||||
segment
|
||||
name: Segment 3
|
||||
gametime: 00:03:00.50
|
||||
realtime: 00:06:00.00
|
||||
best: 00:01:00.00
|
||||
end
|
||||
Loading…
Reference in New Issue