~alcinnz/rhapsode

ref: 43479697d9f8d1f7b28d65aa0cb2d77cd590ce9b rhapsode/src/main.c -rw-r--r-- 1.1 KiB
43479697 — Adrian Cochrane Output converted webpage. 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "HsFFI.h"

struct session;
struct session *c_newSession();
void c_freeSession(struct session*);

struct page;
struct page *c_initialReferer();
void *c_fetchURL(struct session*, char*, struct page*, char*);
//struct page **c_fetchURLs(struct session*, struct page*, char**); // FIXME segfaults.
void c_freePage(struct page*);

char *c_renderDoc(struct session*, struct page*);
char **c_extractLinks(struct page*);
char **c_docLinksAndRendering(struct session*, struct page*); // FIXME segfaults.

int main(int argc, char **argv) {
    hs_init(&argc, &argv);
    struct session *session = c_newSession();

    struct page *referer = c_initialReferer();
    struct page *page = c_fetchURL(session, "text/xml text/html text/plain", referer, argv[1]);
    char *ssml = c_renderDoc(session, page);
    char **links = c_extractLinks(page);

    printf("%s\n", ssml);
    for (int i = 0; strcmp(links[i], " ") != 0; i++) fprintf(stderr, "%s\n", links[i]);

    c_freePage(page);
    c_freePage(referer);
    c_freeSession(session);
    hs_exit();
}