Change show_statuses to take an array of pointers to statuses instead an array of statuses, start implementing timeline model
parent
99cf9a4abb
commit
16f4e1911e
@ -1 +1 @@
|
||||
Subproject commit ec58393b08f85ae9b73f76e8d0aa73d309e2a629
|
||||
Subproject commit b779f4b44fc35c54e9f77913e65af72b3d783b29
|
@ -0,0 +1,77 @@
|
||||
#include "timeline.h"
|
||||
|
||||
#include "json/json.h"
|
||||
#include "json/layout.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static struct json_object_field timeline_block_layout[] = {
|
||||
{ "status_ids", offsetof( struct timeline, status_ids ), true, &json_field_array_of, &json_field_integer },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
struct timeline* timeline_load_block( int id, unsigned int head, unsigned int block )
|
||||
{
|
||||
struct timeline* tl = NULL;
|
||||
char filename[512];
|
||||
FILE* f = NULL;
|
||||
struct json_pull_parser* jpp = NULL;
|
||||
|
||||
printf( "timeline_load_block( %d, %u, %u )\n", id, head, block );
|
||||
|
||||
snprintf( filename, 512, "data/timelines/%d/%u.json", id, block );
|
||||
f = fopen(filename,"r");
|
||||
if( !f ) { goto failed; }
|
||||
|
||||
tl = malloc(sizeof(struct timeline));
|
||||
tl->id = id;
|
||||
tl->block = head;
|
||||
tl->head = head;
|
||||
tl->status_ids.items = NULL;
|
||||
tl->status_ids.count = 0;
|
||||
|
||||
jpp = json_pull_parser_new( f );
|
||||
if( !jpp ) { goto failed; }
|
||||
|
||||
if( !json_read_object_layout( jpp, timeline_block_layout, tl ) ) { goto failed; }
|
||||
|
||||
for( int i = 0; i < tl->status_ids.count; ++i ) {
|
||||
printf( "tl->status_ids[%d] = %d\n", i, tl->status_ids.items[i] );
|
||||
}
|
||||
|
||||
cleanup:
|
||||
json_pull_parser_release(jpp);
|
||||
fclose(f);
|
||||
return tl;
|
||||
failed:
|
||||
timeline_free(tl);
|
||||
tl = NULL;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
struct timeline* timeline_from_id( int id )
|
||||
{
|
||||
char filename[512];
|
||||
snprintf( filename, 512, "data/timelines/%d/HEAD", id );
|
||||
FILE* f = fopen(filename,"r");
|
||||
|
||||
unsigned int head = 0;
|
||||
if( f ) {
|
||||
fscanf( f, "%u", &head );
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
return timeline_load_block( id, head, head );
|
||||
}
|
||||
struct timeline* timeline_new()
|
||||
{
|
||||
}
|
||||
void timeline_free( struct timeline* tl )
|
||||
{
|
||||
if( !tl ) { return; }
|
||||
|
||||
free(tl->status_ids.items);
|
||||
free(tl);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
struct timeline_block_ref
|
||||
{
|
||||
int starting_offset;
|
||||
int block_id;
|
||||
};
|
||||
|
||||
struct timeline
|
||||
{
|
||||
int id;
|
||||
unsigned int block;
|
||||
unsigned int head;
|
||||
|
||||
struct {
|
||||
int* items;
|
||||
int count;
|
||||
} status_ids;
|
||||
};
|
||||
|
||||
struct timeline* timeline_from_id( int id );
|
||||
struct timeline* timeline_new();
|
||||
void timeline_free( struct timeline* tl );
|
||||
|
Loading…
Reference in new issue