Wild Life  2.30
 All Data Structures Files Functions Variables Typedefs Macros
Functions | Variables
lib.c File Reference

lib for calling wild_life from C More...

Go to the source code of this file.

Functions

char ** group_features (char **f, ptr_node n)
 group_features More...
 
void exit_if_true (long exitflag)
 exit_if_true More...
 
void init_io ()
 void init_io More...
 
void init_system ()
 init_system More...
 
void WFInit (long argc, char *argv[])
 WFInit. More...
 
int WFInput (char *query)
 WFInput. More...
 
PsiTerm WFGetVar (char *name)
 WFGetVar. More...
 
int WFfeature_count_loop (ptr_node n)
 WFfeature_count_loop. More...
 
int WFFeatureCount (ptr_psi_term psi)
 WFFeatureCount. More...
 
char * WFType (ptr_psi_term psi)
 WFType. More...
 
char ** WFFeatures (ptr_psi_term psi)
 WFFeatures. More...
 
double WFGetDouble (ptr_psi_term psi, int *ok)
 WFGetDouble. More...
 
char * WFGetString (ptr_psi_term psi, int *ok)
 WFGetString. More...
 
PsiTerm WFGetFeature (ptr_psi_term psi, char *feature)
 WFGetFeature. More...
 

Variables

long noisy =TRUE
 
long file_date =3
 
long types_done =FALSE
 
float garbage_time =0
 

Detailed Description

lib for calling wild_life from C

VERSION of Wild-LIFE for calling from C

Definition in file lib.c.

Function Documentation

void exit_if_true ( long  exitflag)

exit_if_true

Parameters
exitflag- long exitflag

Definition at line 55 of file lib.c.

56 {
57  if (exitflag) {
58  printf("\n\n*** Execution is not allowed to continue.\n");
59  /*exit_life(TRUE);*/
60  exit(EXIT_FAILURE);
61  }
62 }
char** group_features ( char **  f,
ptr_node  n 
)

group_features

Parameters
f- char **f
n- ptr_node n

Definition at line 34 of file lib.c.

References wl_node::key, wl_node::left, NULL, and wl_node::right.

35 {
36  *f=NULL;
37  if(n) {
38  if(n->left)
39  f=group_features(f,n->left);
40  *f=n->key;
41  f++;
42  if(n->right)
43  f=group_features(f,n->right);
44  }
45 
46  return f;
47 }
#define NULL
Definition: def_const.h:533
ptr_node left
Definition: def_struct.h:199
char * key
Definition: def_struct.h:198
char ** group_features(char **f, ptr_node n)
group_features
Definition: lib.c:34
ptr_node right
Definition: def_struct.h:200
void init_io ( )

void init_io

I/O initialization

Definition at line 69 of file lib.c.

References buffer, input_state, NULL, output_stream, stdin_state, stdin_terminal, and TRUE.

70 {
71 #ifdef DJD_PORT_FALSE
72  struct stat buffer_loc;
73 
74  fstat(fileno(stdin), &buffer_loc);
75  /* True iff stdin is from a terminal */
76  stdin_terminal=(S_IFCHR & buffer.st_mode)!=0;
79  output_stream=stdout;
80 #else
84  output_stream=stdout;
85 #endif
86 }
ptr_psi_term stdin_state
Definition: def_glob.h:839
long stdin_terminal
Definition: def_glob.h:827
#define NULL
Definition: def_const.h:533
ptr_psi_term input_state
Definition: def_glob.h:838
char * buffer
buffer used only in print.c - there is local with same name in xpred.c
Definition: def_glob.h:781
#define TRUE
Standard boolean.
Definition: def_const.h:268
FILE * output_stream
Definition: def_glob.h:999
void init_system ( )

init_system

Initial state of system to begin a query

Definition at line 94 of file lib.c.

References choice_stack, current_module, exit_if_true(), FALSE, goal_stack, init_global_vars(), mem_base, memory_check(), wl_module::module_name, NULL, PROMPT, prompt, PROMPT_BUFFER, prompt_buffer, resid_aim, stack_nil(), stack_pointer, undo_stack, user_module, var_tree, x_window_creation, and xevent_list.

95 {
96 #ifdef X11
98 #endif
102  undo_stack=NULL; /* 7.8 */
103  var_tree=NULL;
104 
105  /* RM: Oct 13 1993 */
107  prompt=PROMPT;
108  else {
111  }
112 
113  resid_aim=NULL;
115 
116 #ifdef X11
117  /* RM: Dec 15 1992 */
119 #endif
120 
121  init_global_vars(); /* RM: Feb 15 1993 */
122 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
ptr_module user_module
Default module for user input.
Definition: def_glob.h:694
ptr_goal goal_stack
Definition: def_glob.h:1007
char prompt_buffer[PROMPT_BUFFER]
Definition: def_glob.h:860
ptr_psi_term xevent_list
Definition: def_glob.h:1019
ptr_module current_module
The current module for the tokenizer.
Definition: def_glob.h:729
#define NULL
Definition: def_const.h:533
ptr_node var_tree
Definition: def_glob.h:987
#define PROMPT
Head of prompt.
Definition: def_const.h:218
ptr_goal resid_aim
Definition: def_glob.h:847
long x_window_creation
Definition: def_glob.h:1028
ptr_stack undo_stack
Definition: def_glob.h:1009
void exit_if_true(long exitflag)
exit_if_true
Definition: lib.c:55
void init_global_vars()
init_global_vars
Definition: lefun.c:1484
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_psi_term stack_nil()
stack_nil
Definition: built_ins.c:26
char * module_name
Definition: def_struct.h:106
#define PROMPT_BUFFER
Size of prompt buffer.
Definition: def_const.h:225
char * prompt
Definition: def_glob.h:1000
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
long memory_check()
memory_check
Definition: memory.c:1723
ptr_choice_point choice_stack
Definition: def_glob.h:1008
int WFfeature_count_loop ( ptr_node  n)

WFfeature_count_loop.

Parameters
n- ptr_node n

Definition at line 336 of file lib.c.

References wl_node::left, and wl_node::right.

337 {
338  int result=0;
339 
340  if(n) {
341  if(n->left)
342  result+=WFfeature_count_loop(n->left);
343  result++;
344  if(n->right)
345  result+=WFfeature_count_loop(n->right);
346  }
347 
348  return result;
349 }
ptr_node left
Definition: def_struct.h:199
int WFfeature_count_loop(ptr_node n)
WFfeature_count_loop.
Definition: lib.c:336
ptr_node right
Definition: def_struct.h:200
int WFFeatureCount ( ptr_psi_term  psi)

WFFeatureCount.

Parameters
psi- ptr_psi_term psi

Definition at line 357 of file lib.c.

References wl_psi_term::attr_list, deref_ptr, and WFfeature_count_loop().

358 {
359  int result=0;
360 
361  if(psi) {
362  deref_ptr(psi);
363  result=WFfeature_count_loop(psi->attr_list);
364  }
365 
366  return result;
367 }
#define deref_ptr(P)
Definition: def_macro.h:100
int WFfeature_count_loop(ptr_node n)
WFfeature_count_loop.
Definition: lib.c:336
ptr_node attr_list
Definition: def_struct.h:187
char** WFFeatures ( ptr_psi_term  psi)

WFFeatures.

Parameters
psi- ptr_psi_term psi

Definition at line 391 of file lib.c.

References wl_psi_term::attr_list, deref_ptr, group_features(), NULL, and WFfeature_count_loop().

392 {
393  char **features_loc=NULL;
394  int n;
395 
396  if(psi) {
397  deref_ptr(psi);
398 
400  if(n) {
401  features_loc=(char **)malloc((n+1)*sizeof(char *));
402  (void)group_features(features_loc,psi->attr_list);
403  }
404  }
405 
406  return features_loc;
407 }
#define NULL
Definition: def_const.h:533
#define deref_ptr(P)
Definition: def_macro.h:100
char ** group_features(char **f, ptr_node n)
group_features
Definition: lib.c:34
int WFfeature_count_loop(ptr_node n)
WFfeature_count_loop.
Definition: lib.c:336
ptr_node attr_list
Definition: def_struct.h:187
double WFGetDouble ( ptr_psi_term  psi,
int *  ok 
)

WFGetDouble.

Parameters
psi- ptr_psi_term psi
ok- int *ok

Definition at line 416 of file lib.c.

References deref_ptr, FALSE, real, sub_type(), TRUE, wl_psi_term::type, and wl_psi_term::value_3.

417 {
418  double value=0.0;
419 
420  if(ok)
421  *ok=FALSE;
422 
423  if(psi) {
424  deref_ptr(psi);
425 
426  if(sub_type(psi->type,real) && psi->value_3) {
427  value= *((double *)psi->value_3);
428  if(ok)
429  *ok=TRUE;
430  }
431  }
432  return value;
433 }
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
PsiTerm WFGetFeature ( ptr_psi_term  psi,
char *  feature 
)

WFGetFeature.

Parameters
psi- ptr_psi_term psi
feature- char *feature

Definition at line 468 of file lib.c.

References wl_psi_term::attr_list, wl_node::data, deref_ptr, FEATCMP, find(), and NULL.

469 {
470  ptr_psi_term result=NULL;
471  ptr_node n;
472 
473  if(psi && feature) {
474  deref_ptr(psi);
475  n=find(FEATCMP,feature,psi->attr_list);
476  if(n)
477  result=(PsiTerm)n->data;
478  }
479 
480  return result;
481 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
void * PsiTerm
Type for psi-terms, hidden from users.
Definition: def_struct.h:21
#define deref_ptr(P)
Definition: def_macro.h:100
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
ptr_node attr_list
Definition: def_struct.h:187
char* WFGetString ( ptr_psi_term  psi,
int *  ok 
)

WFGetString.

Parameters
psi- ptr_psi_term psi
ok- int *ok

Definition at line 442 of file lib.c.

References deref_ptr, FALSE, NULL, quoted_string, sub_type(), TRUE, wl_psi_term::type, and wl_psi_term::value_3.

443 {
444  char *value=NULL;
445 
446  if(ok)
447  *ok=FALSE;
448 
449  if(psi) {
450  deref_ptr(psi);
451 
452  if(sub_type(psi->type,quoted_string) && psi->value_3) {
453  value=(char *)psi->value_3;
454  if(ok)
455  *ok=TRUE;
456  }
457  }
458  return value;
459 }
#define NULL
Definition: def_const.h:533
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
PsiTerm WFGetVar ( char *  name)

WFGetVar.

Parameters
name- char *name

Definition at line 315 of file lib.c.

References wl_node::data, deref_ptr, find(), NULL, STRCMP, and var_tree.

316 {
317  ptr_psi_term result=NULL;
318  ptr_node n;
319 
321  if(n) {
322  result=(ptr_psi_term)n->data;
323  if(result)
324  deref_ptr(result);
325  }
326 
327  return result;
328 }
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
ptr_node var_tree
Definition: def_glob.h:987
#define deref_ptr(P)
Definition: def_macro.h:100
char * name
Definition: def_glob.h:948
#define STRCMP
indicates to use strcmp for comparison (c function)
Definition: def_const.h:963
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
void WFInit ( long  argc,
char *  argv[] 
)

WFInit.

Parameters
argc- long argc
argv- char *argv[]

WFINIT(argc,argv) This routine contains the Read-Solve-Print loop.

Definition at line 133 of file lib.c.

References arg_c, arg_v, assert, begin_terminal_io(), c_query_level, env, Errorline(), exit_if_true(), FALSE, file_date, heap_copy_string(), init_built_in_types(), init_copy(), init_interrupt(), init_io(), init_memory(), init_modules(), init_print(), init_system(), init_trace(), input_state, life_start, load, main_prove(), mem_base, noisy, open_input_file(), other_base, push_goal(), quietflag, rand_array, set_current_module(), stack_pointer, stdin_cleareof(), title(), TRUE, undo_stack, user_module, and var_occurred.

134 {
135  ptr_stack save_undo_stack;
136 
137  int i;
138 #ifdef SOLARIS
139  for(i=0;i<256;i++)
140  rand_array[i]=rand_r(&libseed);
141 #else
142  for(i=0;i<256;i++)
143  rand_array[i]=random();
144 #endif
145 
146  if (argc < 10)
147  {
148  arg_c=argc;
149  for (i = 0; i < argc; i++) {
150  arg_v[i]=argv[i];
151  }
152  }
153  else
154  {
155  Errorline("Too many command line arguments\n");
156  }
157 
158  quietflag = TRUE; /* RM: Mar 31 1993 */
159 
160  init_io();
161  init_memory();
163  assert(stack_pointer==mem_base); /* 8.10 */
164  init_copy();
165  assert(stack_pointer==mem_base); /* 8.10 */
166  init_print();
167  assert(stack_pointer==mem_base); /* 8.10 */
168 
169  /* Timekeeping initialization */
170  tzset();
171  (void)times(&life_start);
172  assert(stack_pointer==mem_base); /* 8.10 */
173 
174  init_modules(); /* RM: Jan 8 1993 */
175 
177  assert(stack_pointer==mem_base); /* 8.10 */
178 #ifdef X11
179  x_setup_builtins();
180  assert(stack_pointer==mem_base); /* 8.10 */
181 #endif
182  init_interrupt();
183  assert(stack_pointer==mem_base); /* 8.10 */
184  title();
185  assert(stack_pointer==mem_base); /* 8.10 */
186  init_trace();
187  noisy=FALSE;
188 
189  assert(stack_pointer==mem_base); /* 8.10 */
190 
191 
192  (void)set_current_module(user_module); /* RM: Jan 27 1993 */
193 
194  /* Read in the .set_up file */
195  init_system();
196 
197 #ifdef ARITY /* RM: Mar 29 1993 */
198  arity_init();
199 #endif
200 
201 
202  (void)open_input_file("+SETUP+");
204  file_date+=2;
205  main_prove();
206 
207 
208  (void)setjmp(env);
209  /* printf("%ld\n",(long)(stack_pointer-mem_base)); */ /* 8.10 */
210  init_system();
211  init_trace();
214  save_undo_stack=undo_stack;
215  stdin_cleareof();
216 
217  c_query_level=0;
218 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
void init_trace()
init_trace
Definition: error.c:651
ptr_module user_module
Default module for user input.
Definition: def_glob.h:694
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_goal
Definition: login.c:600
void init_system()
init_system
Definition: lib.c:94
void init_io()
void init_io
Definition: lib.c:69
long quietflag
Definition: def_glob.h:894
ptr_psi_term input_state
Definition: def_glob.h:838
struct tms life_start
time life started - seconds
Definition: def_glob.h:83
ptr_stack undo_stack
Definition: def_glob.h:1009
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
void begin_terminal_io()
begin_terminal_io
Definition: token.c:493
int arg_c
set from argc in either life.c or lib.c
Definition: def_glob.h:20
#define TRUE
Standard boolean.
Definition: def_const.h:268
GENERIC other_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:98
void exit_if_true(long exitflag)
exit_if_true
Definition: lib.c:55
#define FALSE
Standard boolean.
Definition: def_const.h:275
void init_print()
init_print
Definition: print.c:52
long var_occurred
Definition: def_glob.h:828
void init_memory()
init_memory ()
Definition: memory.c:1671
long file_date
Definition: lib.c:22
char * arg_v[ARGNN]
set from argv in either life.c or lib.c
Definition: def_glob.h:27
#define load
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1156
long rand_array[256]
Definition: def_glob.h:902
jmp_buf env
Definition: def_glob.h:859
void main_prove()
main_prove
Definition: login.c:2333
void init_built_in_types()
init_built_in_types
Definition: built_ins.c:6155
long c_query_level
Definition: def_glob.h:912
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
long noisy
Definition: lib.c:21
void init_modules()
init_modules
Definition: modules.c:34
void stdin_cleareof()
stdin_cleareof
Definition: token.c:51
void title()
TITLE.
Definition: info.c:39
void init_copy()
init_copy
Definition: copy.c:32
long open_input_file(char *file)
open_input_file
Definition: token.c:594
ptr_module set_current_module(ptr_module module)
set_current_module
Definition: modules.c:100
void init_interrupt()
INIT_INTERRUPT.
Definition: interrupt.c:36
#define assert(N)
Definition: memory.c:114
int WFInput ( char *  query)

WFInput.

Parameters
query- char *query

Definition at line 226 of file lib.c.

References wl_goal::aaaa_1, assert_clause(), assert_first, assert_ok, c_query_level, c_what_next, choice_stack, DEFRULES, encode_types(), FACT, fail, FALSE, goal_count, goal_stack, ignore_eff, init_parse_state(), main_prove(), wl_goal::next, NULL, parse(), prove, push_choice_point(), push_goal(), QUERY, reset_stacks(), save_parse_state(), stack_copy_psi_term(), start_chrono(), stringinput, stringparse, TRUE, wl_goal::type, undo(), undo_stack, var_occurred, WFmore, WFno, and WFyes.

227 {
228  ptr_psi_term t;
229  long sort;
230  parse_block pb;
231  int result=WFno;
232  ptr_stack save_undo_stack;
233  ptr_choice_point old_choice;
234 
235 
236  save_undo_stack=undo_stack;
237  old_choice=choice_stack;
238 
239 
240  if(!strcmp(query,".")) {
241  reset_stacks();
242  result=WFyes;
243  c_query_level=0;
244  }
245  else {
246  if(!strcmp(query,";")) {
247  sort=QUERY;
249  }
250  else {
251  /* Parse the string in its own state */
252  save_parse_state(&pb);
255  stringinput=query;
256 
257  /* old_var_occurred=var_occurred; */
259  t=stack_copy_psi_term(parse(&sort));
260 
261  /* Main loop of interpreter */
262  if(sort==QUERY) {
264  goal_count=0;
265 
267  c_query_level++;
270  /* reset_step(); */
271  }
272  else if (sort==FACT) {
274  assert_clause(t);
275  if(assert_ok)
276  result=WFyes;
277  undo(save_undo_stack);
279  encode_types();
280  }
281  }
282 
283  if(sort==QUERY) {
284  start_chrono();
285  main_prove();
286 
288 
289  if((long)(goal_stack->aaaa_1)==c_query_level)
290  if(choice_stack==old_choice) {
291  result=WFyes;
292  c_query_level--;
293  }
294  else
295  result=WFmore;
296  else {
297  result=WFno;
298  c_query_level--;
299  }
300 
302  }
303  }
304  }
305 
306  return result;
307 }
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void undo(ptr_stack limit)
undo
Definition: login.c:691
long assert_first
Definition: def_glob.h:1014
ptr_goal goal_stack
Definition: def_glob.h:1007
void push_choice_point(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_choice_point
Definition: login.c:638
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_goal
Definition: login.c:600
psi_term parse(long *q)
parse
Definition: parser.c:907
void save_parse_state(ptr_parse_block pb)
save_parse_state
Definition: token.c:425
#define DEFRULES
Must be different from NULL, a built-in index, and a pointer Used to indicate that the rules of the d...
Definition: def_const.h:302
#define WFmore
Input succeeded with possibly more answers.
Definition: def_const.h:47
#define FACT
Fact Kind of user input.
Definition: def_const.h:338
#define NULL
Definition: def_const.h:533
#define WFno
Input failed.
Definition: def_const.h:34
long ignore_eff
Definition: def_glob.h:677
#define QUERY
Query Kind of user input.
Definition: def_const.h:345
#define WFyes
Input succeeded.
Definition: def_const.h:41
#define c_what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1163
long assert_ok
Definition: def_glob.h:1015
ptr_stack undo_stack
Definition: def_glob.h:1009
long goal_count
Definition: def_glob.h:678
goals type
Definition: def_struct.h:238
#define TRUE
Standard boolean.
Definition: def_const.h:268
void start_chrono()
start_chrono
Definition: login.c:349
#define FALSE
Standard boolean.
Definition: def_const.h:275
long var_occurred
Definition: def_glob.h:828
#define fail
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1044
void init_parse_state()
init_parse_state
Definition: token.c:464
void reset_stacks()
reset_stacks
Definition: login.c:2047
ptr_psi_term stack_copy_psi_term(psi_term t)
stack_copy_psi_term
Definition: parser.c:205
void encode_types()
encode_types
Definition: types.c:1091
void main_prove()
main_prove
Definition: login.c:2333
long c_query_level
Definition: def_glob.h:912
long stringparse
Definition: def_glob.h:841
char * stringinput
Definition: def_glob.h:842
void assert_clause(ptr_psi_term t)
assert_clause
Definition: login.c:287
ptr_choice_point choice_stack
Definition: def_glob.h:1008
ptr_goal next
Definition: def_struct.h:242
char* WFType ( ptr_psi_term  psi)

WFType.

Parameters
psi- ptr_psi_term psi

Definition at line 375 of file lib.c.

References wl_keyword::combined_name, deref_ptr, wl_definition::keyword, NULL, and wl_psi_term::type.

376 {
377  char *result=NULL;
378  if(psi) {
379  deref_ptr(psi);
380  result=psi->type->keyword->combined_name;
381  }
382  return result;
383 }
char * combined_name
Definition: def_struct.h:119
ptr_keyword keyword
Definition: def_struct.h:147
#define NULL
Definition: def_const.h:533
#define deref_ptr(P)
Definition: def_macro.h:100
ptr_definition type
Definition: def_struct.h:181

Variable Documentation

long file_date =3

Definition at line 22 of file lib.c.

float garbage_time =0

Definition at line 25 of file lib.c.

long noisy =TRUE

Definition at line 21 of file lib.c.

long types_done =FALSE

Definition at line 23 of file lib.c.