projects
/
blerg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reorder libs in Makefile.PL so it will link properly
[blerg.git]
/
tools
/
blerglatest.c
diff --git
a/tools/blerglatest.c
b/tools/blerglatest.c
index
727eb18
..
ba12eae
100644
(file)
--- a/
tools/blerglatest.c
+++ b/
tools/blerglatest.c
@@
-1,3
+1,6
@@
+/* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
+ * BSD-style license. Please see the COPYING file for details.
+ */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@
-9,6
+12,7
@@
#include "database.h"
#include "json.h"
#include "config.h"
#include "database.h"
#include "json.h"
#include "config.h"
+#include "configuration.h"
yajl_gen_config yajl_config = {0, 0};
yajl_gen_config yajl_config = {0, 0};
@@
-29,6
+33,7
@@
struct things * things_alloc() {
things->len = 0;
things->size = 65536;
things->arr = malloc(sizeof(struct thing) * things->size);
things->len = 0;
things->size = 65536;
things->arr = malloc(sizeof(struct thing) * things->size);
+ return things;
}
void things_free(struct things *things) {
}
void things_free(struct things *things) {
@@
-70,17
+75,22
@@
void things_sort(struct things *things) {
qsort(things->arr, things->len, sizeof(struct thing), thing_compare);
}
qsort(things->arr, things->len, sizeof(struct thing), thing_compare);
}
-struct things * latest_things(const char *path, const char *file) {
+struct things * latest_things(const char *path, const char *file
, int minlen
) {
DIR* d;
struct dirent *f;
struct things * things = things_alloc();
char filename[512];
struct stat st;
DIR* d;
struct dirent *f;
struct things * things = things_alloc();
char filename[512];
struct stat st;
- int i;
d = opendir(path);
d = opendir(path);
- while (f = readdir(d)) {
+ if (d == NULL) {
+ fprintf(stderr, "Could not open %s: ", path);
+ perror("");
+ exit(1);
+ }
+ while ((f = readdir(d)) != NULL) {
if (f->d_name[0] == '.') continue;
if (f->d_name[0] == '.') continue;
+ if (minlen > 0 && strlen(f->d_name) < minlen) continue;
if (file) {
snprintf(filename, 512, "%s/%s/%s", path, f->d_name, file);
} else {
if (file) {
snprintf(filename, 512, "%s/%s/%s", path, f->d_name, file);
} else {
@@
-98,12
+108,12
@@
struct things * latest_things(const char *path, const char *file) {
void latest_tags(yajl_gen g) {
int i;
void latest_tags(yajl_gen g) {
int i;
- struct things * things = latest_things(
HASH_TAGS_PATH, NULL
);
+ struct things * things = latest_things(
blergconf.hash_tags_path, NULL, 3
);
unsigned int count = (things->len >= 50 ? 50 : things->len);
yajl_gen_array_open(g);
for (i = 0; i < count; i++) {
unsigned int count = (things->len >= 50 ? 50 : things->len);
yajl_gen_array_open(g);
for (i = 0; i < count; i++) {
- yajl_gen_string(g, things->arr[i].name, things->arr[i].len);
+ yajl_gen_string(g,
(unsigned char *)
things->arr[i].name, things->arr[i].len);
}
yajl_gen_array_close(g);
}
yajl_gen_array_close(g);
@@
-112,7
+122,7
@@
void latest_tags(yajl_gen g) {
void latest_records(yajl_gen g) {
int i;
void latest_records(yajl_gen g) {
int i;
- struct things * things = latest_things(
DATA_PATH, "meta"
);
+ struct things * things = latest_things(
blergconf.data_path, "meta", 0
);
unsigned int count = (things->len >= 50 ? 50 : things->len);
yajl_gen_array_open(g);
unsigned int count = (things->len >= 50 ? 50 : things->len);
yajl_gen_array_open(g);
@@
-135,10
+145,13
@@
int main(int argc, char *argv[]) {
const unsigned char *buf;
unsigned int len;
const unsigned char *buf;
unsigned int len;
+ if (!blerg_init())
+ exit(1);
+
yajl_gen g = yajl_gen_alloc(&yajl_config, NULL);
yajl_gen_map_open(g);
yajl_gen g = yajl_gen_alloc(&yajl_config, NULL);
yajl_gen_map_open(g);
- yajl_gen_string(g, "tags", 4);
+ yajl_gen_string(g,
(unsigned char *)
"tags", 4);
latest_tags(g);
latest_tags(g);
@@
-146,7
+159,7
@@
int main(int argc, char *argv[]) {
fwrite(buf, len, 1, stdout);
yajl_gen_clear(g);
fwrite(buf, len, 1, stdout);
yajl_gen_clear(g);
- yajl_gen_string(g, "records", 7);
+ yajl_gen_string(g,
(unsigned char *)
"records", 7);
latest_records(g);
latest_records(g);
@@
-155,4
+168,6
@@
int main(int argc, char *argv[]) {
fwrite(buf, len, 1, stdout);
yajl_gen_free(g);
fwrite(buf, len, 1, stdout);
yajl_gen_free(g);
+
+ return 0;
}
}