Reorganise and start working on the json parser
This commit is contained in:
parent
5ff93f61d7
commit
c75e51aa3e
3
haversine_02/.gitignore
vendored
3
haversine_02/.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
.cache
|
||||
compile_commands.json
|
||||
count_and_distances
|
||||
pairs.json
|
||||
main
|
||||
genhavr
|
||||
|
@ -1,10 +1,3 @@
|
||||
#!/usr/bin/bash
|
||||
#!/bin/bash
|
||||
|
||||
CC=clang++
|
||||
CFLAGS="-g -Wall -Wextra"
|
||||
SRC=*.cpp
|
||||
OUT=main
|
||||
|
||||
set -x
|
||||
|
||||
$CC $CFLAGS $SRC -o $OUT
|
||||
bear -- ./compile
|
||||
|
16
haversine_02/compile
Normal file
16
haversine_02/compile
Normal 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
BIN
haversine_02/jsonparse
Normal file
Binary file not shown.
@ -12,7 +12,7 @@ static argp parser = {};
|
||||
static argp_option options[] = {
|
||||
{.name = "seed", .key = 's', .arg = "SEED"},
|
||||
{.name = "cluster", .key = 'c'},
|
||||
{0},
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
GeneratorArgs parse_args(i32 argc, char *argv[]) {
|
47
haversine_02/src/jsonparse.cpp
Normal file
47
haversine_02/src/jsonparse.cpp
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user