foreign predicate not working

"Saurabh Bhatla" <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <001801c46f2e$a982b1f0$6405a8c0@saurabh>


Hi 
   I am using a foreign predicate from my logtalk
 object. I define thatin a file receiver.lgt
 (attached). the definition of my predicate is infile
 file_ops.c (attached). I can compile the code in
 gprolog and amable to make an executable out of it
 too. The problem is that whenever icall the foreign
 predicate it returns false. I have some
 printfstatements in my C code but none of them gets
 printed, which mean thatthe c code is not being called
 at all.  
  I tried to trace the execution and the call to my
 foreign predicatesimply fails without checking
 anything. My C program works fine whenexecuted 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/plain, 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 (application/octet-stream, 400 B) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.