Skip to content

Commit

Permalink
*Sad JSON noises*
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Aug 29, 2020
1 parent 0d90160 commit c14cd02
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# main: main.c
# gcc -lcurl main.c
cc=gcc

main: main.c util.c
gcc -o octodashcurses -lcurl main.c util.c -I.
octo: build/main.o build/util.o
gcc -o $@ -lcurl $^ -I.

build/%.o: src/%.c
@mkdir -p $(@D)
@printf " CC $(*).c\n"
$(PREFIX)$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
Binary file added build/main.o
Binary file not shown.
Binary file added build/util.o
Binary file not shown.
1 change: 1 addition & 0 deletions jsmn.h → src/jsmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
jsmntok_t *tokens, const unsigned int num_tokens);

#ifndef JSMN_HEADER
#define JSMN_HEADER
/**
* Allocates a fresh unused token from the token pool.
*/
Expand Down
2 changes: 1 addition & 1 deletion main.c → src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #include <string.h>
// #include <ncurses.h> // TODO :)
// #include "jsmn.h"
#include "util.h"
Expand Down
13 changes: 2 additions & 11 deletions util.c → src/util.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#include <curl/curl.h>
#include <stdlib.h>
#include <string.h>
#include "jsmn.h"
#include "util.h"

/* STRING STUFF */

// Boneless string, becaue I don't feel like figuring out how long these
// strings are.
struct string {
char *ptr;
size_t len;
};

void init_string(struct string *s) {
s->len = 0;
s->ptr = malloc(s->len+1);
Expand All @@ -23,8 +15,7 @@ void init_string(struct string *s) {
}

// Function to dump curl responses into strings.
size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s)
{
size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s) {
size_t new_len = s->len + size*nmemb;
s->ptr = realloc(s->ptr, new_len+1);
if (s->ptr == NULL) {
Expand Down
14 changes: 12 additions & 2 deletions util.h → src/util.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#ifndef UTIL_H
#define UTIL_H

typedef struct string_t {
#include <string.h>
#include "jsmn.h"

// typedef struct string_t {
// char *ptr;
// size_t len;
// } string;

// Boneless string, becaue I don't feel like figuring out how long these
// strings are.
struct string {
char *ptr;
size_t len;
} string;
};

void init_string(struct string *s);

Expand Down

0 comments on commit c14cd02

Please sign in to comment.