-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclips.c
executable file
·3169 lines (2294 loc) · 71.9 KB
/
clips.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "clipssrc/clips.h"
#include "clipssrc/tmpltutl.h"
#include "php_clips.h"
#define VERSION "0.5.1"
/* {{{ Function Entry - Register functions in PHP */
zend_function_entry clips_functions[] = {
PHP_FE(clips_function_call, NULL)
PHP_FE(clips_batch, NULL)
PHP_FE(clips_load, NULL)
PHP_FE(clips_bload, NULL)
PHP_FE(clips_bsave, NULL)
PHP_FE(clips_build, NULL)
PHP_FE(clips_eval, NULL)
PHP_FE(clips_save, NULL)
PHP_FE(clips_get_auto_float_dividend, NULL)
PHP_FE(clips_get_dynamic_constraint_checking, NULL)
PHP_FE(clips_get_static_constraint_checking, NULL)
PHP_FE(clips_get_sequence_operator_recognition, NULL)
PHP_FE(clips_set_auto_float_dividend, NULL)
PHP_FE(clips_set_dynamic_constraint_checking, NULL)
PHP_FE(clips_set_sequence_operator_recognition, NULL)
PHP_FE(clips_set_static_constraint_checking, NULL)
PHP_FE(clips_reset, NULL)
PHP_FE(clips_clear, NULL)
PHP_FE(clips_run, NULL)
PHP_FE(clips_dribble_active, NULL)
PHP_FE(clips_dribble_off, NULL)
PHP_FE(clips_dribble_on, NULL)
PHP_FE(clips_get_watch_item, NULL)
PHP_FE(clips_watch, NULL)
PHP_FE(clips_unwatch, NULL)
PHP_FE(clips_deftemplate_module, NULL)
PHP_FE(clips_get_deftemplate_list, NULL)
PHP_FE(clips_is_deftemplate_deletable, NULL)
PHP_FE(clips_undeftemplate, NULL)
PHP_FE(clips_get_fact_list, NULL)
PHP_FE(clips_assert, NULL)
PHP_FE(clips_get_fact_duplication, NULL)
PHP_FE(clips_get_fact_list_changed, NULL)
PHP_FE(clips_load_facts, NULL)
PHP_FE(clips_load_facts_from_string, NULL)
PHP_FE(clips_save_facts, NULL)
PHP_FE(clips_set_fact_duplication, NULL)
PHP_FE(clips_set_fact_list_changed, NULL)
PHP_FE(clips_deffacts_module, NULL)
PHP_FE(clips_get_deffacts_list, NULL)
PHP_FE(clips_is_deffacts_deletable, NULL)
PHP_FE(clips_undeffacts, NULL)
PHP_FE(clips_refresh, NULL)
PHP_FE(clips_remove_break, NULL)
PHP_FE(clips_set_break, NULL)
PHP_FE(clips_defrule_has_breakpoint, NULL)
PHP_FE(clips_defrule_module, NULL)
PHP_FE(clips_get_defrule_list, NULL)
PHP_FE(clips_get_incremental_reset, NULL)
PHP_FE(clips_set_incremental_reset, NULL)
PHP_FE(clips_is_defrule_deletable, NULL)
PHP_FE(clips_undefrule, NULL)
PHP_FE(clips_clear_focus_stack, NULL)
PHP_FE(clips_get_agenda_changed, NULL)
PHP_FE(clips_set_agenda_changed, NULL)
PHP_FE(clips_get_focus, NULL)
PHP_FE(clips_get_focus_stack, NULL)
PHP_FE(clips_get_salience_evaluation, NULL)
PHP_FE(clips_set_salience_evaluation, NULL)
PHP_FE(clips_set_strategy, NULL)
PHP_FE(clips_get_strategy, NULL)
PHP_FE(clips_pop_focus, NULL)
PHP_FE(clips_focus, NULL)
PHP_FE(clips_refresh_agenda, NULL)
PHP_FE(clips_reorder_agenda, NULL)
PHP_FE(clips_defglobal_module, NULL)
PHP_FE(clips_get_defglobal_value, NULL)
PHP_FE(clips_get_globals_changed, NULL)
PHP_FE(clips_get_reset_globals, NULL)
PHP_FE(clips_is_defglobal_deletable, NULL)
PHP_FE(clips_set_defglobal_value, NULL)
PHP_FE(clips_undefglobal, NULL)
PHP_FE(clips_deffunction_module, NULL)
PHP_FE(clips_get_deffunction_list, NULL)
PHP_FE(clips_is_deffunction_deletable, NULL)
PHP_FE(clips_undeffunction, NULL)
PHP_FE(clips_defgeneric_module, NULL)
PHP_FE(clips_get_defgeneric_list, NULL)
PHP_FE(clips_is_defgeneric_deletable, NULL)
PHP_FE(clips_undefgeneric, NULL)
PHP_FE(clips_class_abstract, NULL)
PHP_FE(clips_class_reactive, NULL)
PHP_FE(clips_class_slots, NULL)
PHP_FE(clips_class_subclasses, NULL)
PHP_FE(clips_class_superclasses, NULL)
PHP_FE(clips_defclass_module, NULL)
PHP_FE(clips_get_class_defaults_mode, NULL)
PHP_FE(clips_set_class_defaults_mode, NULL)
PHP_FE(clips_get_defclass_list, NULL)
PHP_FE(clips_is_defclass_deletable, NULL)
PHP_FE(clips_subclass, NULL)
PHP_FE(clips_superclass, NULL)
PHP_FE(clips_undefclass, NULL)
PHP_FE(clips_get_instances_changed, NULL)
PHP_FE(clips_set_instances_changed, NULL)
PHP_FE(clips_get_instance_list, NULL)
PHP_FE(clips_create_instance, NULL)
PHP_FE(clips_make_instance, NULL)
PHP_FE(clips_get_defmodule_list, NULL)
PHP_FE(clips_set_current_module, NULL)
{NULL, NULL, NULL}
};
/* }}} */
/* {{{ Module Entry - Register the extension in PHP */
zend_module_entry clips_module_entry = {
STANDARD_MODULE_HEADER,
"clips",
clips_functions,
PHP_MINIT(clips),
NULL,
PHP_RINIT(clips),
NULL,
PHP_MINFO(clips),
VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_CLIPS
ZEND_GET_MODULE(clips)
#endif
/* {{{ Module Initialization Function -
Is called when the webserver starts */
PHP_MINIT_FUNCTION(clips) {
/* Register CLIPS Constants */
/* Conflict Resolution Strategies */
REGISTER_LONG_CONSTANT("DEPTH_STRATEGY", DEPTH_STRATEGY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("BREADTH_STRATEGY", BREADTH_STRATEGY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LEX_STRATEGY", LEX_STRATEGY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("MEA_STRATEGY", MEA_STRATEGY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("COMPLEXITY_STRATEGY", COMPLEXITY_STRATEGY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SIMPLICITY_STRATEGY", SIMPLICITY_STRATEGY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RANDOM_STRATEGY", RANDOM_STRATEGY, CONST_CS | CONST_PERSISTENT);
/* Save Scopes */
REGISTER_LONG_CONSTANT("LOCAL_SAVE", LOCAL_SAVE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("VISIBLE_SAVE", VISIBLE_SAVE, CONST_CS | CONST_PERSISTENT);
/* Salience Evaluation Modes */
REGISTER_LONG_CONSTANT("WHEN_DEFINED", WHEN_DEFINED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("WHEN_ACTIVATED", WHEN_ACTIVATED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("EVERY_CYCLE", EVERY_CYCLE, CONST_CS | CONST_PERSISTENT);
/* Class Default Modes */
REGISTER_LONG_CONSTANT("CONVENIENCE_MODE", CONVENIENCE_MODE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CONSERVATION_MODE", CONSERVATION_MODE, CONST_CS | CONST_PERSISTENT);
return SUCCESS;
}
/* }}} */
/* {{{ Request Initialization Function -
Is called upon each page request */
PHP_RINIT_FUNCTION(clips) {
/* Initialize a CLIPS environment */
InitializeEnvironment();
Clear();
return SUCCESS;
}
/* }}} */
/* {{{ Module Info Function -
Defines information about the extension to be listed when
phpinfo() is called */
PHP_MINFO_FUNCTION(clips) {
php_info_print_table_start();
php_info_print_table_row(2, "CLIPS Support", "enabled");
php_info_print_table_row(2, "CLIPS Extension Version", VERSION);
php_info_print_table_row(2, "CLIPS Version", "6.2");
php_info_print_table_end();
}
/* }}} */
/* INTERNAL FUNCTIONS */
/* {{{ Convert a CLIPS DATA_OBJECT into a zval */
int dataobj_to_zval(DATA_OBJECT *obj, zval *var) {
return dataobj_or_facts_to_zval(obj, var, NULL);
}
int dataobj_or_facts_to_zval(DATA_OBJECT *obj, zval *var, void *fact_deftemplate) {
int i, i2, i3, end, end2, end3, is_ordered_fact;
void *multifield_ptr, *multifield_ptr2, *multifield_ptr3, *fact_ptr, *instance_ptr, *defclass_ptr, *fact_dt_ptr;
DATA_OBJECT slot_names, slot_value;
zval *fact, *instance, *multi_val, *multislot_val;
switch (GetpType(obj)) {
case FLOAT:
ZVAL_DOUBLE(var, DOPToDouble(obj));
return 1;
break;
case STRING: case SYMBOL: case INSTANCE_NAME:
ZVAL_STRING(var, DOPToString(obj), 1);
return 1;
break;
case INTEGER:
ZVAL_LONG(var, DOPToLong(obj));
return 1;
break;
case FACT_ADDRESS:
/*ptr = DOPToPointer(obj);*/
ZVAL_STRING(var, "fact-address", 1);
break;
case INSTANCE_ADDRESS:
/*ptr = DOPToPointer(obj);*/
ZVAL_STRING(var, "instance-address", 1);
break;
case EXTERNAL_ADDRESS:
/*ptr = DOPToPointer(obj);*/
ZVAL_STRING(var, "external-address", 1);
break;
case MULTIFIELD:
array_init(var);
end = GetpDOEnd(obj);
multifield_ptr = GetpValue(obj);
for (i = GetpDOBegin(obj); i <= end; i++)
{
switch (GetMFType(multifield_ptr, i))
{
case FLOAT: case INTEGER_OR_FLOAT:
add_next_index_double(var, ValueToDouble(GetMFValue(multifield_ptr, i)));
break;
case STRING: case SYMBOL: case SYMBOL_OR_STRING: case INSTANCE_NAME: case INSTANCE_OR_INSTANCE_NAME:
add_next_index_string(var, ValueToString(GetMFValue(multifield_ptr, i)), 1);
break;
case INTEGER:
add_next_index_long(var, ValueToLong(GetMFValue(multifield_ptr, i)));
break;
case FACT_ADDRESS:
is_ordered_fact = 0;
MAKE_STD_ZVAL(fact);
array_init(fact);
fact_ptr = GetMFValue(multifield_ptr, i);
fact_dt_ptr = FactDeftemplate(fact_ptr);
if (fact_deftemplate == NULL || fact_dt_ptr == fact_deftemplate) {
FactSlotNames(fact_ptr, &slot_names);
end2 = GetDOEnd(slot_names);
multifield_ptr2 = GetValue(slot_names);
/* Iterate through the fact slots and retrieve the values in each slot */
for (i2 = GetDOBegin(slot_names); i2 <= end2; i2++) {
/* Store the current slot value into a new DATA_OBJECT */
if (end2 == 1 && strcmp("implied", ValueToString(GetMFValue(multifield_ptr2, i2))) == 0) {
GetFactSlot(fact_ptr, NULL, &slot_value);
MAKE_STD_ZVAL(multi_val);
array_init(multi_val);
add_next_index_string(multi_val, GetDeftemplateName(fact_dt_ptr), 1);
end3 = GetDOEnd(slot_value);
multifield_ptr3 = GetValue(slot_value);
for (i3 = GetDOBegin(slot_value); i3 <= end3; i3++) {
switch (GetMFType(multifield_ptr3, i3)) {
case FLOAT: case INTEGER_OR_FLOAT:
add_next_index_double(multi_val, ValueToDouble(GetMFValue(multifield_ptr3, i3)));
break;
case STRING: case SYMBOL: case SYMBOL_OR_STRING: case INSTANCE_NAME: case INSTANCE_OR_INSTANCE_NAME:
add_next_index_string(multi_val, ValueToString(GetMFValue(multifield_ptr3, i3)), 1);
break;
case INTEGER:
add_next_index_long(multi_val, ValueToLong(GetMFValue(multifield_ptr3, i3)));
break;
case MULTIFIELD:
MAKE_STD_ZVAL(multislot_val);
dataobj_to_zval(&slot_value, multislot_val);
add_assoc_zval(fact, ValueToString(GetMFValue(multifield_ptr3, i3)), multislot_val);
break;
default:
add_next_index_string(multi_val, "(unknown value)", 1);
break;
}
}
add_next_index_zval(var, multi_val);
is_ordered_fact = 1;
}
else {
GetFactSlot(fact_ptr, ValueToString(GetMFValue(multifield_ptr2, i2)), &slot_value);
/* Convert the DATA_OBJECT into a PHP data type and append to the fact array */
switch (GetType(slot_value)) {
case FLOAT:
add_assoc_double(fact, ValueToString(GetMFValue(multifield_ptr2, i2)), DOToDouble(slot_value));
break;
case STRING: case SYMBOL: case INSTANCE_NAME:
add_assoc_string(fact, ValueToString(GetMFValue(multifield_ptr2, i2)), DOToString(slot_value), 1);
break;
case INTEGER:
add_assoc_long(fact, ValueToString(GetMFValue(multifield_ptr2, i2)), DOToLong(slot_value));
break;
case MULTIFIELD:
MAKE_STD_ZVAL(multislot_val);
dataobj_to_zval(&slot_value, multislot_val);
add_assoc_zval(fact, ValueToString(GetMFValue(multifield_ptr2, i2)), multislot_val);
break;
default:
add_assoc_string(fact, ValueToString(GetMFValue(multifield_ptr2, i2)), "(unknown value)", 1);
break;
}
}
}
/* Add the fact array to the var array */
if ( ! is_ordered_fact) {
add_next_index_zval(var, fact);
}
}
break;
case INSTANCE_ADDRESS:
MAKE_STD_ZVAL(instance);
array_init(instance);
instance_ptr = GetMFValue(multifield_ptr, i);
defclass_ptr = GetInstanceClass(instance_ptr);
/* Get the slot names of the defclass */
ClassSlots(defclass_ptr, &slot_names, 1);
end2 = GetDOEnd(slot_names);
multifield_ptr2 = GetValue(slot_names);
/* Iterate through the instance slots and retrieve the values in each slot */
for (i2 = GetDOBegin(slot_names); i2 <= end2; i2++) {
/* Store the current slot value into a new DATA_OBJECT */
DirectGetSlot(instance_ptr, ValueToString(GetMFValue(multifield_ptr2, i2)), &slot_value);
/* Convert the DATA_OBJECT into a PHP data type and append to the instance array */
switch (GetType(slot_value)) {
case FLOAT:
add_assoc_double(instance, ValueToString(GetMFValue(multifield_ptr2, i2)), DOToDouble(slot_value));
break;
case STRING: case SYMBOL: case INSTANCE_NAME:
add_assoc_string(instance, ValueToString(GetMFValue(multifield_ptr2, i2)), DOToString(slot_value), 1);
break;
case INTEGER:
add_assoc_long(instance, ValueToString(GetMFValue(multifield_ptr2, i2)), DOToLong(slot_value));
break;
}
}
/* Add the instance array to the var array */
add_next_index_zval(var, instance);
break;
case MULTIFIELD:
add_next_index_string(var, "(multifield)", 1);
break;
case EXTERNAL_ADDRESS:
add_next_index_string(var, "(external-address)", 1);
break;
default:
add_next_index_string(var, "(unknown-value)", 1);
break;
} /* End switch */
} /* End for */
return 1;
break;
default:
ZVAL_STRING(var, "(unknown-value)", 1);
break;
}
return 0;
}
/* }}} */
/* {{{ Convert a zval into a CLIPS DATA_OBJECT */
void zval_to_dataobj(zval *php_val, DATA_OBJECT *obj) {
void *tmp_val;
int arr_count = 0;
zval **val;
switch (Z_TYPE_P(php_val)) {
case IS_STRING:
SetpType(obj, STRING);
tmp_val = AddSymbol(Z_STRVAL_P(php_val));
SetpValue(obj, tmp_val);
break;
case IS_BOOL:
SetpType(obj, SYMBOL);
if (Z_LVAL_P(php_val)) {
tmp_val = AddSymbol("TRUE");
} else {
tmp_val = AddSymbol("FALSE");
}
SetpValue(obj, tmp_val);
break;
case IS_LONG:
SetpType(obj, INTEGER);
tmp_val = AddLong(Z_LVAL_P(php_val));
SetpValue(obj, tmp_val);
break;
case IS_DOUBLE:
SetpType(obj, FLOAT);
tmp_val = AddDouble(Z_DVAL_P(php_val));
SetpValue(obj, tmp_val);
break;
case IS_ARRAY:
while (zend_hash_get_current_data(Z_ARRVAL_P(php_val), (void **)&val) == SUCCESS) {
switch (Z_TYPE_PP(val)) {
case IS_STRING: case IS_LONG: case IS_DOUBLE:
arr_count++;
break;
}
zend_hash_move_forward(Z_ARRVAL_P(php_val));
}
tmp_val = CreateMultifield(arr_count);
arr_count = 1;
zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_val));
while (zend_hash_get_current_data(Z_ARRVAL_P(php_val), (void **)&val) == SUCCESS) {
SEPARATE_ZVAL(val);
switch (Z_TYPE_PP(val)) {
case IS_STRING:
SetMFType(tmp_val, arr_count, STRING);
SetMFValue(tmp_val, arr_count, AddSymbol(Z_STRVAL_PP(val)));
break;
case IS_LONG:
SetMFType(tmp_val, arr_count, INTEGER);
SetMFValue(tmp_val, arr_count, AddLong(Z_LVAL_PP(val)));
break;
case IS_DOUBLE:
SetMFType(tmp_val, arr_count, FLOAT);
SetMFValue(tmp_val, arr_count, AddDouble(Z_DVAL_PP(val)));
break;
default:
arr_count--;
break;
}
arr_count++;
zend_hash_move_forward(Z_ARRVAL_P(php_val));
}
SetpType(obj, MULTIFIELD);
SetpValue(obj, tmp_val);
SetpDOBegin(obj, 1);
SetpDOEnd(obj, (arr_count-1));
break;
default:
zend_error(E_WARNING, "Cannot convert objects or resources into a CLIPS data object");
break;
}
}
/* }}} */
/* ENVIRONMENT FUNCTIONS */
/* {{{ proto bool clips_function_call(string function_name [, string arguments])
Allows CLIPS system functions, deffunctions and generic functions to be called
from PHP */
PHP_FUNCTION(clips_function_call) {
char *function_name, *arguments;
int function_name_len, arguments_len;
DATA_OBJECT result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s|s",
&function_name,
&function_name_len,
&arguments,
&arguments_len) == FAILURE)
{
RETURN_FALSE;
}
if (ZEND_NUM_ARGS() > 1) {
FunctionCall(function_name, arguments, &result);
}
else {
FunctionCall(function_name, NULL, &result);
}
RETURN_DATA_OBJECT(result);
}
/* }}} */
/* {{{ bool clips_batch(string file)
Evaluate a series of commands stored in the specified file. Equivalent of the
CLIPS batch* command. */
PHP_FUNCTION(clips_batch) {
char *file;
int file_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
RETURN_FALSE;
}
if (BatchStar(file)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Failed to load CLIPS batch file '%s'", file);
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_load(string file);
Load a set of constructs into CLIPS from a file */
PHP_FUNCTION(clips_load) {
char *file;
int file_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
RETURN_FALSE;
}
if (Load(file)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "failed to load clips source file '%s'", file);
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_bload(string file);
Load a set of constructs into CLIPS from a binary CLIPS file */
PHP_FUNCTION(clips_bload) {
char *file;
int file_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
RETURN_FALSE;
}
if (Bload(file)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Failed to load clips binary file '%s'", file);
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_bsave(string file)
Save a binary image of constructs currently in the CLIPS environment. */
PHP_FUNCTION(clips_bsave) {
char *file;
int file_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
RETURN_FALSE;
}
if (Bsave(file)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Failed to save clips binary file '%s'", file);
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_build(string construct_string)
Allows a construct to be defined */
PHP_FUNCTION(clips_build) {
char *construct_str;
int construct_str_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &construct_str, &construct_str_len) == FAILURE) {
RETURN_FALSE;
}
if (Build(construct_str)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Failed to define CLIPS construct");
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_eval(string expression)
Allows an expression to be evaluated */
PHP_FUNCTION(clips_eval) {
char *expr;
int expr_len;
DATA_OBJECT result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &expr, &expr_len) == FAILURE) {
RETURN_FALSE;
}
if (Eval(expr, &result)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Failed to evaluate CLIPS expression");
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_save(string filename)
Saves a set of constructs to the specified file */
PHP_FUNCTION(clips_save) {
char* filename;
int filename_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
RETURN_FALSE;
}
if (Save(filename)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Failed to save CLIPS construct file '%s'", filename);
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_get_auto_float_dividend()
Get the current value of the auto-float dividend behavior. Equivalent of
the CLIPS get-auto-float-dividend command. */
PHP_FUNCTION(clips_get_auto_float_dividend) {
if (GetAutoFloatDividend()) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_get_dynamic_constraint_checking()
Get the current value of the dynamic constraint checking behavior. Equivalent of
the CLIPS get-dynamic-constraint-checking command. */
PHP_FUNCTION(clips_get_dynamic_constraint_checking) {
if (GetDynamicConstraintChecking()) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_get_static_constraint_checking()
Get the current value of the static constraint checking behavior. Equivalent of
the CLIPS get-static-constraint-checking command. */
PHP_FUNCTION(clips_get_static_constraint_checking) {
if (GetStaticConstraintChecking()) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_get_sequence_operator_recognition()
Get the current value of the sequence operator recognition behavior. Equivalent of
the CLIPS get-sequence-operator-recognition command. */
PHP_FUNCTION(clips_get_sequence_operator_recognition) {
if (GetSequenceOperatorRecognition()) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto void clips_set_auto_float_dividend(bool value)
Set the auto-float dividend behavior. Equivalent of
the CLIPS set-auto-float-dividend command. */
PHP_FUNCTION(clips_set_auto_float_dividend) {
int val;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) {
RETURN_FALSE;
}
SetAutoFloatDividend(val);
}
/* }}} */
/* {{{ proto void clips_set_dynamic_constraint_checking(bool value)
Set the dynamic constraint checking behavior. Equivalent of
the CLIPS set-dynamic-constraint-checking command. */
PHP_FUNCTION(clips_set_dynamic_constraint_checking) {
int val;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) {
RETURN_FALSE;
}
SetDynamicConstraintChecking(val);
}
/* }}} */
/* {{{ proto void clips_set_sequence_operator_recognition(bool value)
Set the sequence operator recognition behavior. Equivalent of
the CLIPS set-sequence-operator-recognition command. */
PHP_FUNCTION(clips_set_sequence_operator_recognition) {
int val;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) {
RETURN_FALSE;
}
SetSequenceOperatorRecognition(val);
}
/* }}} */
/* {{{ proto void clips_set_static_constraint_checking(bool value)
Set the static constraint checking behavior. Equivalent of
the CLIPS set-static-constraint-checking command. */
PHP_FUNCTION(clips_set_static_constraint_checking) {
int val;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) {
RETURN_FALSE;
}
SetStaticConstraintChecking(val);
}
/* }}} */
/* {{{ proto void clips_reset();
Reset the CLIPS environment */
PHP_FUNCTION(clips_reset) {
Reset();
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void clips_clear();
Clear the CLIPS environment */
PHP_FUNCTION(clips_clear) {
Clear();
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int clips_run([int run_limit]);
Execute rules in the agenda, returns the number of rules that were fired. */
PHP_FUNCTION(clips_run) {
int run_limit = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &run_limit) == FAILURE) {
RETURN_FALSE;
}
RETURN_LONG(Run(run_limit));
}
/* }}} */
/* DEBUGGING FUNCTIONS */
/* {{{ proto bool clips_dribble_active()
Determines if the storing of dribble information is active */
PHP_FUNCTION(clips_dribble_active) {
if (DribbleActive()) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_dribble_off()
Turns off the storing of dribble information */
PHP_FUNCTION(clips_dribble_off) {
if (DribbleOff()) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "An error occurred while attempting to close dribble file");
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_dribble_on(string filename)
Allows the dribble function of CLIPS to be turned on */
PHP_FUNCTION(clips_dribble_on) {
char *filename;
int filename_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
RETURN_FALSE;
}
if (DribbleOn(filename)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "An error occurred while attempting to open dribble file '%s'", filename);
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_get_watch_item(string item)
Tell whether or not the given item is being watched */
PHP_FUNCTION(clips_get_watch_item) {
char *item;
int item_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &item, &item_len) == FAILURE) {
RETURN_FALSE;
}
if (GetWatchItem(item)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_watch(string item)
Allows the tracing facilities of CLIPS to be activated */
PHP_FUNCTION(clips_watch) {
char *item;
int item_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &item, &item_len) == FAILURE) {
RETURN_FALSE;
}
if (Watch(item)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Failed to watch item '%s', valid items to watch are: (facts, rules, activations, focus, compilations, statistics, globals, instances, slots, messages, message-handlers, generic-functions, method, or deffunctions)", item);
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto bool clips_unwatch(string item)
Allows the tracing facilities of CLIPS to be deactivated */
PHP_FUNCTION(clips_unwatch) {
char *item;
int item_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &item, &item_len) == FAILURE) {
RETURN_FALSE;
}
if (Unwatch(item)) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Failed to deactivate watch on item '%s'", item);
RETURN_FALSE;
}
}
/* }}} */