Reorganise and start working on the json parser

This commit is contained in:
Abdelrahman Said 2023-06-11 02:14:41 +01:00
parent 5ff93f61d7
commit c75e51aa3e
15 changed files with 69 additions and 10 deletions

View File

@ -1,3 +1,6 @@
.cache
compile_commands.json
count_and_distances count_and_distances
pairs.json pairs.json
main main
genhavr

View File

@ -1,10 +1,3 @@
#!/usr/bin/bash #!/bin/bash
CC=clang++ bear -- ./compile
CFLAGS="-g -Wall -Wextra"
SRC=*.cpp
OUT=main
set -x
$CC $CFLAGS $SRC -o $OUT

16
haversine_02/compile Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
CC=clang++
CFLAGS="-g -Wall -Wextra -Iinclude"
# generator
GENSRC="./src/argparser.cpp ./src/generator.cpp ./src/haversine.cpp ./src/point_types.cpp ./src/genmain.cpp"
GENOUT=genhavr
(set -x ; $CC $CFLAGS $GENSRC -o $GENOUT)
# json parser
JSONSRC="./src/jsonparse.cpp"
JSONOUT=jsonparse
(set -x ; $CC $CFLAGS $JSONSRC -o $JSONOUT)

BIN
haversine_02/jsonparse Normal file

Binary file not shown.

View File

@ -12,7 +12,7 @@ static argp parser = {};
static argp_option options[] = { static argp_option options[] = {
{.name = "seed", .key = 's', .arg = "SEED"}, {.name = "seed", .key = 's', .arg = "SEED"},
{.name = "cluster", .key = 'c'}, {.name = "cluster", .key = 'c'},
{0}, {0, 0, 0, 0, 0, 0},
}; };
GeneratorArgs parse_args(i32 argc, char *argv[]) { GeneratorArgs parse_args(i32 argc, char *argv[]) {

View File

@ -0,0 +1,47 @@
#include "aliases.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
i32 main(i32 argc, char *argv[]) {
if (argc < 2) {
printf("Missing filename\n");
return EXIT_FAILURE;
}
const char *filename = argv[1];
FILE *fp = fopen(filename, "r");
if (!fp) {
printf("Failed to open file: %s\n", filename);
return EXIT_FAILURE;
}
fseek(fp, 0, SEEK_END);
u64 length = ftell(fp);
fseek(fp, 0, SEEK_SET);
char text[length + 1];
memset(text, 0, length);
fread(text, sizeof(char), length, fp);
text[length] = '\0';
const char *delim = ", \t\n";
char *token = strtok(text, delim);
while (token) {
printf("TOKEN: %s\n", token);
token = strtok(NULL, delim);
}
fclose(fp);
return EXIT_SUCCESS;
}