| 1 | /* |
|---|
| 2 | * Copyright 2008 Digital Bazaar, Inc. |
|---|
| 3 | * |
|---|
| 4 | * This file is part of librdfa. |
|---|
| 5 | * |
|---|
| 6 | * librdfa is Free Software, and can be licensed under any of the |
|---|
| 7 | * following three licenses: |
|---|
| 8 | * |
|---|
| 9 | * 1. GNU Lesser General Public License (LGPL) V2.1 or any |
|---|
| 10 | * newer version |
|---|
| 11 | * 2. GNU General Public License (GPL) V2 or any newer version |
|---|
| 12 | * 3. Apache License, V2.0 or any newer version |
|---|
| 13 | * |
|---|
| 14 | * You may not use this file except in compliance with at least one of |
|---|
| 15 | * the above three licenses. |
|---|
| 16 | * |
|---|
| 17 | * See LICENSE-* at the top of this software distribution for more |
|---|
| 18 | * information regarding the details of each license. |
|---|
| 19 | * |
|---|
| 20 | * You should have received a copy of the GNU Lesser General Public |
|---|
| 21 | * License along with librdfa. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 22 | */ |
|---|
| 23 | #include <stdio.h> |
|---|
| 24 | #include <string.h> |
|---|
| 25 | #include <rdfa.h> |
|---|
| 26 | #include <rdfa_utils.h> |
|---|
| 27 | |
|---|
| 28 | #define BASE_URI \ |
|---|
| 29 | "http://rdfa.digitalbazaar.com/test-suite/tests-cases/" |
|---|
| 30 | |
|---|
| 31 | void process_triple(rdftriple* triple, void* callback_data) |
|---|
| 32 | { |
|---|
| 33 | rdfa_print_triple(triple); |
|---|
| 34 | rdfa_free_triple(triple); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | size_t fill_buffer(char* buffer, size_t buffer_length, void* callback_data) |
|---|
| 38 | { |
|---|
| 39 | FILE* xhtml_file = (FILE*)callback_data; |
|---|
| 40 | size_t rval = fread(buffer, sizeof(char), buffer_length, xhtml_file); |
|---|
| 41 | return rval; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | int main(int argc, char** argv) |
|---|
| 45 | { |
|---|
| 46 | if(argc < 2) |
|---|
| 47 | { |
|---|
| 48 | printf("%s usage:\n\n" |
|---|
| 49 | "%s <input.xhtml>\n", argv[0], argv[0]); |
|---|
| 50 | } |
|---|
| 51 | else |
|---|
| 52 | { |
|---|
| 53 | FILE* xhtml_file = fopen(argv[1], "r"); |
|---|
| 54 | char* filename = rindex(argv[1], '/'); |
|---|
| 55 | filename++; |
|---|
| 56 | |
|---|
| 57 | if(xhtml_file != NULL) |
|---|
| 58 | { |
|---|
| 59 | char* base_uri = rdfa_join_string(BASE_URI, filename); |
|---|
| 60 | rdfacontext* context = rdfa_create_context(base_uri); |
|---|
| 61 | context->callback_data = xhtml_file; |
|---|
| 62 | |
|---|
| 63 | rdfa_set_default_graph_triple_handler(context, &process_triple); |
|---|
| 64 | rdfa_set_buffer_filler(context, &fill_buffer); |
|---|
| 65 | rdfa_parse(context); |
|---|
| 66 | rdfa_free_context(context); |
|---|
| 67 | |
|---|
| 68 | fclose(xhtml_file); |
|---|
| 69 | free(base_uri); |
|---|
| 70 | } |
|---|
| 71 | else |
|---|
| 72 | { |
|---|
| 73 | perror("failed to open file:"); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | return 0; |
|---|
| 78 | } |
|---|