foreign predicate not working
Saurabh Bhatla <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
Hi I am using a foreign predicate from my logtalk object. I define that in a file receiver.lgt (attached). the definition of my predicate is in file file_ops.c (attached). I can compile the code in gprolog and am able to make an executable out of it too. The problem is that whenever i call the foreign predicate it returns false. I have some printf statements in my C code but none of them gets printed, which mean that the c code is not being called at all. I tried to trace the execution and the call to my foreign predicate simply fails without checking anything. My C program works fine when executed alone. Does anybody know whats going on here.. regards saurabh _______________________________________________ Users-prolog mailing list [email protected] http://lists.gnu.org/mailman/listinfo/users-prolog
file_ops.c
(text/x-c, 1.3 KB)
#include <stdio.h>
#include "gprolog.h"
void removenl(char*);
Bool
get_event_ob(char *name,char *ret_object)
//int main()
{
FILE *infile;
//char *name="threshold";
//char *ret_object;
char line[100];
char *object;
int lcount;
// int TRUE,FALSE=1;
char key[100];
int nchars;
int index;
char *p, *sp;
if((infile = fopen("objects.txt", "r")) == NULL)
{
printf("Objects file does not exists, Exiting......\n");
exit(1);
}
while( fgets(line, sizeof(line), infile) != NULL )
{
removenl(line);
sp = line;
index=0;
while(index<2)
{
index++;
if ((p = strchr(sp,'=')) == NULL)
p = sp + strlen(sp);
else
{
if(index==1)
{
nchars = p - sp;
strncpy(key,sp,nchars);
key[nchars]='\0';
}
sp = p+1;
}
if(index==2)
{
object=sp;
}
}
printf("key:%s\n",key);
printf("value:%s\n",object);
if(!strcmp(key,name))
{
ret_object=object;
printf("found it\n");
fclose(infile);
return TRUE;
}
}
fclose(infile); /* Close the file */
return FALSE;
}
void removenl(char *str)
{
while(strlen(str) && ( (str[strlen(str) - 1] == 13) || ( str[strlen(str) - 1] == 10 )))
{
str[strlen(str) - 1] = 0;
}
}
receiver.lgt
(text/plain, 400 B)
:- foreign(get_event_ob(+string,-string)).
:-object(receiver).
:-public(receive/1).
:-public(validate/1).
:-public(get_event_ob/2).
receive(Event).
validate(Event):-
self(Self),
Self::get_event_ob(Event,Object),
write(Object),
write('<-object found for event->'),
write(Event),nl.
validate(Event):-
write('No object found for event->'),
write(Event),nl.
:-end_object.