Debian Codegraph @

perl/redland-post.i

raw
1 /* -*- Mode: c; c-basic-offset: 2 -*-
2 *
3 * redland-post.i - Perl SWIG helper routines
4 *
5 * Copyright (C) 2000-2006, David Beckett http://www.dajobe.org/
6 * Copyright (C) 2000-2005, University of Bristol, UK http://www.bristol.ac.uk/
7 *
8 * This package is Free Software and part of Redland http://librdf.org/
9 *
10 * It is licensed under the following three licenses as alternatives:
11 * 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
12 * 2. GNU General Public License (GPL) V2 or any newer version
13 * 3. Apache License, V2.0 or any newer version
14 *
15 * You may not use this file except in compliance with at least one of
16 * the above three licenses.
17 *
18 * See LICENSE.html or LICENSE.txt at the top of this package for the
19 * full license terms.
20 *
21 */
22
23 void librdf_perl_world_init(librdf_world *world);
24 void librdf_perl_world_finish(void);
25
26
27 /*
28 * calls a perl subroutine defined as:
29 * RDF::Redland::World::message($$)
30 * where first argument is an integer, second is a (scalar) string
31 */
32 static int
33 librdf_call_perl_message(int code, int level, int facility,
34 const char *message,
35 int line, int column, int byte,
36 const char *file, const char *uri)
37 {
38 dSP;
39 int count;
40 int rc=0;
41
42 SAVETMPS;
43
44 PUSHMARK(SP) ;
45 XPUSHs(sv_2mortal(newSViv(code)));
46 XPUSHs(sv_2mortal(newSViv(level)));
47 XPUSHs(sv_2mortal(newSViv(facility)));
48 if(message != NULL)
49 XPUSHs(sv_2mortal(newSVpv(message, 0)));
50 else
51 XPUSHs((void*)0);
52 XPUSHs(sv_2mortal(newSViv(line)));
53 XPUSHs(sv_2mortal(newSViv(column)));
54 XPUSHs(sv_2mortal(newSViv(byte)));
55 if(file != NULL)
56 XPUSHs(sv_2mortal(newSVpv(file, 0)));
57 else
58 XPUSHs((void*)0);
59 if(uri != NULL)
60 XPUSHs(sv_2mortal(newSVpv(uri, 0)));
61 else
62 XPUSHs((void*)0);
63 PUTBACK;
64
65 count=call_pv("RDF::Redland::World::message", G_SCALAR);
66
67 SPAGAIN;
68 if(count == 1)
69 rc=POPi;
70 PUTBACK;
71
72 FREETMPS;
73
74 return rc;
75 }
76
77 static int
78 librdf_perl_logger_handler(void *user_data, librdf_log_message *log)
79 {
80 raptor_locator* locator = log->locator;
81 int line= -1;
82 int column= -1;
83 int byte= -1;
84 const char *uri=NULL;
85 const char *file=NULL;
86
87 if(locator) {
88 line=raptor_locator_line(locator);
89 column=raptor_locator_column(locator);
90 byte=raptor_locator_byte(locator);
91 file=raptor_locator_file(locator);
92 uri=raptor_locator_uri(locator);
93 }
94
95 return librdf_call_perl_message(log->code, log->level, log->facility,
96 log->message,
97 line, column, byte, file, uri);
98 }
99
100
101 static librdf_world* librdf_perl_world=NULL;
102
103 void
104 librdf_perl_world_init(librdf_world *world)
105 {
106 librdf_world_set_logger(world, NULL, librdf_perl_logger_handler);
107
108 librdf_perl_world=world;
109 }
110
111 void
112 librdf_perl_world_finish(void)
113 {
114 librdf_free_world(librdf_perl_world);
115 }