clips-sys 0.4.0

Bindgen generated wrapper for CLIPS (clipsrules.net)
Documentation
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
   /*******************************************************/
   /*      "C" Language Integrated Production System      */
   /*                                                     */
   /*            CLIPS Version 6.40  08/25/16             */
   /*                                                     */
   /*                    WATCH MODULE                     */
   /*******************************************************/


/*************************************************************/
/* Purpose: Support functions for the watch and unwatch      */
/*   commands.                                               */
/*                                                           */
/* Principal Programmer(s):                                  */
/*      Gary D. Riley                                        */
/*                                                           */
/* Contributing Programmer(s):                               */
/*      Brian Dantes                                         */
/*                                                           */
/* Revision History:                                         */
/*                                                           */
/*      6.23: Changed name of variable log to logName        */
/*            because of Unix compiler warnings of shadowed  */
/*            definitions.                                   */
/*                                                           */
/*      6.24: Renamed BOOLEAN macro type to intBool.         */
/*                                                           */
/*            Added EnvSetWatchItem function.                */
/*                                                           */
/*      6.30: Removed conditional code for unsupported       */
/*            compilers/operating systems (IBM_MCW,          */
/*            MAC_MCW, and IBM_TBC).                         */
/*                                                           */
/*            Added const qualifiers to remove C++           */
/*            deprecation warnings.                          */
/*                                                           */
/*            Converted API macros to function calls.        */
/*                                                           */
/*      6.40: Added Env prefix to GetEvaluationError and     */
/*            SetEvaluationError functions.                  */
/*                                                           */
/*            Pragma once and other inclusion changes.       */
/*                                                           */
/*            Added support for booleans with <stdbool.h>.   */
/*                                                           */
/*            Changed return values for router functions.    */
/*                                                           */
/*            Removed use of void pointers for specific      */
/*            data structures.                               */
/*                                                           */
/*            ALLOW_ENVIRONMENT_GLOBALS no longer supported. */
/*                                                           */
/*            UDF redesign.                                  */
/*                                                           */
/*************************************************************/

#include "setup.h"

#if DEBUGGING_FUNCTIONS

#include <stdio.h>
#include <string.h>

#include "argacces.h"
#include "constant.h"
#include "envrnmnt.h"
#include "extnfunc.h"
#include "memalloc.h"
#include "router.h"

#include "watch.h"

/***************************************/
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
/***************************************/

   static WatchItemRecord        *ValidWatchItem(Environment *,const char *,bool *);
   static void                    DeallocateWatchData(Environment *);

/**********************************************/
/* InitializeWatchData: Allocates environment */
/*    data for watch items.                   */
/**********************************************/
void InitializeWatchData(
  Environment *theEnv)
  {
   AllocateEnvironmentData(theEnv,WATCH_DATA,sizeof(struct watchData),DeallocateWatchData);
  }

/************************************************/
/* DeallocateWatchData: Deallocates environment */
/*    data for watch items.                     */
/************************************************/
static void DeallocateWatchData(
  Environment *theEnv)
  {
   WatchItemRecord *tmpPtr, *nextPtr;

   tmpPtr = WatchData(theEnv)->ListOfWatchItems;
   while (tmpPtr != NULL)
     {
      nextPtr = tmpPtr->next;
      rtn_struct(theEnv,watchItemRecord,tmpPtr);
      tmpPtr = nextPtr;
     }
  }

/*************************************************************/
/* AddWatchItem: Adds an item to the list of watchable items */
/*   that can be set using the watch and unwatch commands.   */
/*   Returns false if the item is already in the list,       */
/*   otherwise returns true.                                 */
/*************************************************************/
bool AddWatchItem(
  Environment *theEnv,
  const char *name,
  int code,
  bool *flag,
  int priority,
  bool (*accessFunc)(Environment *,int,bool,struct expr *),
  bool (*printFunc)(Environment *,const char *,int,struct expr *))
  {
   WatchItemRecord *newPtr, *currentPtr, *lastPtr;

   /*================================================================*/
   /* Find the insertion point in the watchable items list to place  */
   /* the new item. If the item is already in the list return false. */
   /*================================================================*/

   for (currentPtr = WatchData(theEnv)->ListOfWatchItems, lastPtr = NULL;
        currentPtr != NULL;
        currentPtr = currentPtr->next)
     {
      if (strcmp(currentPtr->name,name) == 0) return false;
      if (priority < currentPtr->priority) lastPtr = currentPtr;
     }

   /*============================*/
   /* Create the new watch item. */
   /*============================*/

   newPtr = get_struct(theEnv,watchItemRecord);
   newPtr->name = name;
   newPtr->flag = flag;
   newPtr->code = code;
   newPtr->priority = priority;
   newPtr->accessFunc = accessFunc;
   newPtr->printFunc = printFunc;

   /*=================================================*/
   /* Insert the new item in the list of watch items. */
   /*=================================================*/

   if (lastPtr == NULL)
     {
      newPtr->next = WatchData(theEnv)->ListOfWatchItems;
      WatchData(theEnv)->ListOfWatchItems = newPtr;
     }
   else
     {
      newPtr->next = lastPtr->next;
      lastPtr->next = newPtr;
     }

   /*==================================================*/
   /* Return true to indicate the item has been added. */
   /*==================================================*/

   return true;
  }

/**************************************************/
/* Watch: C access routine for the watch command. */
/**************************************************/
void Watch(
  Environment *theEnv,
  WatchItem item)
  {
   switch (item)
     {
      case ALL:
        SetWatchItem(theEnv,"all",true,NULL);
        break;

      case FACTS:
        SetWatchItem(theEnv,"facts",true,NULL);
        break;
        
      case INSTANCES:
        SetWatchItem(theEnv,"instances",true,NULL);
        break;
        
      case SLOTS:
        SetWatchItem(theEnv,"slots",true,NULL);
        break;
        
      case RULES:
        SetWatchItem(theEnv,"rules",true,NULL);
        break;
        
      case ACTIVATIONS:
        SetWatchItem(theEnv,"activations",true,NULL);
        break;
        
      case MESSAGES:
        SetWatchItem(theEnv,"messages",true,NULL);
        break;
        
      case MESSAGE_HANDLERS:
        SetWatchItem(theEnv,"message-handlers",true,NULL);
        break;
        
      case GENERIC_FUNCTIONS:
        SetWatchItem(theEnv,"generic-functions",true,NULL);
        break;
        
      case METHODS:
        SetWatchItem(theEnv,"methods",true,NULL);
        break;
        
      case DEFFUNCTIONS:
        SetWatchItem(theEnv,"deffunctions",true,NULL);
        break;
        
      case COMPILATIONS:
        SetWatchItem(theEnv,"compilations",true,NULL);
        break;
        
      case STATISTICS:
        SetWatchItem(theEnv,"statistics",true,NULL);
        break;
        
      case GLOBALS:
        SetWatchItem(theEnv,"globals",true,NULL);
        break;
        
      case FOCUS:
        SetWatchItem(theEnv,"focus",true,NULL);
        break;
     }
  }

/****************************************************/
/* Unwatch: C access routine for the watch command. */
/****************************************************/
void Unwatch(
  Environment *theEnv,
  WatchItem item)
  {
   switch (item)
     {
      case ALL:
        SetWatchItem(theEnv,"all",false,NULL);
        break;

      case FACTS:
        SetWatchItem(theEnv,"facts",false,NULL);
        break;
        
      case INSTANCES:
        SetWatchItem(theEnv,"instances",false,NULL);
        break;
        
      case SLOTS:
        SetWatchItem(theEnv,"slots",false,NULL);
        break;
        
      case RULES:
        SetWatchItem(theEnv,"rules",false,NULL);
        break;
        
      case ACTIVATIONS:
        SetWatchItem(theEnv,"activations",false,NULL);
        break;
        
      case MESSAGES:
        SetWatchItem(theEnv,"messages",false,NULL);
        break;
        
      case MESSAGE_HANDLERS:
        SetWatchItem(theEnv,"message-handlers",false,NULL);
        break;
        
      case GENERIC_FUNCTIONS:
        SetWatchItem(theEnv,"generic-functions",false,NULL);
        break;
        
      case METHODS:
        SetWatchItem(theEnv,"methods",false,NULL);
        break;
        
      case DEFFUNCTIONS:
        SetWatchItem(theEnv,"deffunctions",false,NULL);
        break;
        
      case COMPILATIONS:
        SetWatchItem(theEnv,"compilations",false,NULL);
        break;
        
      case STATISTICS:
        SetWatchItem(theEnv,"statistics",false,NULL);
        break;
        
      case GLOBALS:
        SetWatchItem(theEnv,"globals",false,NULL);
        break;
        
      case FOCUS:
        SetWatchItem(theEnv,"focus",false,NULL);
        break;
     }
  }

/******************************************/
/* GetWatchState: Returns the watch state */
/*   for the specified watch item.        */
/******************************************/
bool GetWatchState(
  Environment *theEnv,
  WatchItem item)
  {
   switch (item)
     {
      case ALL:
        return false;

      case FACTS:
        return (GetWatchItem(theEnv,"facts") == 1);
        
      case INSTANCES:
        return (GetWatchItem(theEnv,"instances") == 1);
        
      case SLOTS:
        return (GetWatchItem(theEnv,"slots") == 1);
        
      case RULES:
        return (GetWatchItem(theEnv,"rules") == 1);
        
      case ACTIVATIONS:
        return (GetWatchItem(theEnv,"activations") == 1);
        
      case MESSAGES:
        return (GetWatchItem(theEnv,"messages") == 1);
        
      case MESSAGE_HANDLERS:
        return (GetWatchItem(theEnv,"message-handlers") == 1);
        
      case GENERIC_FUNCTIONS:
        return (GetWatchItem(theEnv,"generic-functions") == 1);
        
      case METHODS:
        return (GetWatchItem(theEnv,"methods") == 1);
        
      case DEFFUNCTIONS:
        return (GetWatchItem(theEnv,"deffunctions") == 1);
        
      case COMPILATIONS:
        return (GetWatchItem(theEnv,"compilations") == 1);
        
      case STATISTICS:
        return (GetWatchItem(theEnv,"statistics") == 1);
        
      case GLOBALS:
        return (GetWatchItem(theEnv,"globals") == 1);
        
      case FOCUS:
        return (GetWatchItem(theEnv,"focus") == 1);
     }
     
   return false;
  }

/******************************************/
/* SetWatchState: Returns the watch state */
/*   for the specified watch item.        */
/******************************************/
void SetWatchState(
  Environment *theEnv,
  WatchItem item,
  bool newState)
  {
   switch (item)
     {
      case ALL:
        SetWatchItem(theEnv,"all",newState,NULL);
        return;

      case FACTS:
        SetWatchItem(theEnv,"facts",newState,NULL);
        return;
        
      case INSTANCES:
        SetWatchItem(theEnv,"instances",newState,NULL);
        return;
        
      case SLOTS:
        SetWatchItem(theEnv,"slots",newState,NULL);
        return;
        
      case RULES:
        SetWatchItem(theEnv,"rules",newState,NULL);
        return;
        
      case ACTIVATIONS:
        SetWatchItem(theEnv,"activations",newState,NULL);
        return;
        
      case MESSAGES:
        SetWatchItem(theEnv,"messages",newState,NULL);
        return;
        
      case MESSAGE_HANDLERS:
        SetWatchItem(theEnv,"message-handlers",newState,NULL);
        return;
        
      case GENERIC_FUNCTIONS:
        SetWatchItem(theEnv,"generic-functions",newState,NULL);
        return;
        
      case METHODS:
        SetWatchItem(theEnv,"methods",newState,NULL);
        return;
        
      case DEFFUNCTIONS:
        SetWatchItem(theEnv,"deffunctions",newState,NULL);
        return;
        
      case COMPILATIONS:
        SetWatchItem(theEnv,"compilations",newState,NULL);
        return;
        
      case STATISTICS:
        SetWatchItem(theEnv,"statistics",newState,NULL);
        return;
        
      case GLOBALS:
        SetWatchItem(theEnv,"globals",newState,NULL);
        return;
        
      case FOCUS:
        SetWatchItem(theEnv,"focus",newState,NULL);
        return;
     }
  }

/********************************************************/
/* WatchString: C access routine for the watch command. */
/********************************************************/
bool WatchString(
  Environment *theEnv,
  const char *itemName)
  {
   return SetWatchItem(theEnv,itemName,true,NULL);
  }

/************************************************************/
/* UnwatchString: C access routine for the unwatch command. */
/************************************************************/
bool UnwatchString(
  Environment *theEnv,
  const char *itemName)
  {
   return SetWatchItem(theEnv,itemName,false,NULL);
  }

/********************************************************************/
/* SetWatchItem: Sets the state of a specified watch item to either */
/*   on or off. Returns true if the item was set, otherwise false.  */
/********************************************************************/
bool SetWatchItem(
  Environment *theEnv,
  const char *itemName,
  bool newState,
  struct expr *argExprs)
  {
   WatchItemRecord *wPtr;

   /*===================================================*/
   /* If the name of the watch item to set is all, then */
   /* all watch items are set to the new state and true */
   /* is returned.                                      */
   /*===================================================*/

   if (strcmp(itemName,"all") == 0)
     {
      for (wPtr = WatchData(theEnv)->ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next)
        {
         /*==============================================*/
         /* If no specific arguments are specified, then */
         /* set the global flag for the watch item.      */
         /*==============================================*/

         if (argExprs == NULL) *(wPtr->flag) = newState;

         /*=======================================*/
         /* Set flags for individual watch items. */
         /*=======================================*/

         if ((wPtr->accessFunc == NULL) ? false :
             ((*wPtr->accessFunc)(theEnv,wPtr->code,newState,argExprs) == false))
           {
            SetEvaluationError(theEnv,true);
            return false;
           }
        }
      return true;
     }

   /*=================================================*/
   /* Search for the watch item to be set in the list */
   /* of watch items. If found, set the watch item to */
   /* its new state and return true.                  */
   /*=================================================*/

   for (wPtr = WatchData(theEnv)->ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next)
     {
      if (strcmp(itemName,wPtr->name) == 0)
        {
         /*==============================================*/
         /* If no specific arguments are specified, then */
         /* set the global flag for the watch item.      */
         /*==============================================*/

         if (argExprs == NULL) *(wPtr->flag) = newState;

         /*=======================================*/
         /* Set flags for individual watch items. */
         /*=======================================*/

         if ((wPtr->accessFunc == NULL) ? false :
             ((*wPtr->accessFunc)(theEnv,wPtr->code,newState,argExprs) == false))
           {
            SetEvaluationError(theEnv,true);
            return false;
           }

         return true;
        }
     }

   /*=================================================*/
   /* If the specified item was not found in the list */
   /* of watchable items then return false.           */
   /*=================================================*/

   return false;
  }

/****************************************************************/
/* GetWatchItem: Gets the current state of the specified watch  */
/*   item. Returns the state of the watch item (0 for off and 1 */
/*   for on) if the watch item is found in the list of watch    */
/*   items, otherwise -1 is returned.                           */
/****************************************************************/
int GetWatchItem(
  Environment *theEnv,
  const char *itemName)
  {
   WatchItemRecord *wPtr;

   for (wPtr = WatchData(theEnv)->ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next)
     {
      if (strcmp(itemName,wPtr->name) == 0)
        {
         if (*(wPtr->flag))
           { return 1; }
         else
           { return 0; }
        }
     }

   return -1;
  }

/***************************************************************/
/* ValidWatchItem: Returns true if the specified name is found */
/*   in the list of watch items, otherwise returns false.      */
/***************************************************************/
static WatchItemRecord *ValidWatchItem(
  Environment *theEnv,
  const char *itemName,
  bool *recognized)
  {
   WatchItemRecord *wPtr;

   *recognized = true;
   if (strcmp(itemName,"all") == 0)
     return NULL;

   for (wPtr = WatchData(theEnv)->ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next)
     { if (strcmp(itemName,wPtr->name) == 0) return(wPtr); }

   *recognized = false;
   return NULL;
  }

/*************************************************************/
/* GetNthWatchName: Returns the name associated with the nth */
/*   item in the list of watchable items. If the nth item    */
/*   does not exist, then NULL is returned.                  */
/*************************************************************/
const char *GetNthWatchName(
  Environment *theEnv,
  int whichItem)
  {
   int i;
   WatchItemRecord *wPtr;

   for (wPtr = WatchData(theEnv)->ListOfWatchItems, i = 1;
        wPtr != NULL;
        wPtr = wPtr->next, i++)
     { if (i == whichItem) return(wPtr->name); }

   return NULL;
  }

/***************************************************************/
/* GetNthWatchValue: Returns the current state associated with */
/*   the nth item in the list of watchable items. If the nth   */
/*   item does not exist, then -1 is returned.                 */
/***************************************************************/
int GetNthWatchValue(
  Environment *theEnv,
  int whichItem)
  {
   int i;
   WatchItemRecord *wPtr;

   for (wPtr = WatchData(theEnv)->ListOfWatchItems, i = 1;
        wPtr != NULL;
        wPtr = wPtr->next, i++)
     { if (i == whichItem) return((int) *(wPtr->flag)); }

   return(-1);
  }

/**************************************/
/* WatchCommand: H/L access routine   */
/*   for the watch command.           */
/**************************************/
void WatchCommand(
  Environment *theEnv,
  UDFContext *context,
  UDFValue *returnValue)
  {
   UDFValue theValue;
   const char *argument;
   bool recognized;
   WatchItemRecord *wPtr;

   /*========================================*/
   /* Determine which item is to be watched. */
   /*========================================*/

   if (! UDFFirstArgument(context,SYMBOL_BIT,&theValue)) return;

   argument = theValue.lexemeValue->contents;
   wPtr = ValidWatchItem(theEnv,argument,&recognized);
   if (recognized == false)
     {
      SetEvaluationError(theEnv,true);
      UDFInvalidArgumentMessage(context,"watchable symbol");
      return;
     }

   /*=================================================*/
   /* Check to make sure extra arguments are allowed. */
   /*=================================================*/

   if (GetNextArgument(GetFirstArgument()) != NULL)
     {
      if ((wPtr == NULL) ? true : (wPtr->accessFunc == NULL))
        {
         SetEvaluationError(theEnv,true);
         ExpectedCountError(theEnv,"watch",EXACTLY,1);
         return;
        }
     }

   /*=====================*/
   /* Set the watch item. */
   /*=====================*/

   SetWatchItem(theEnv,argument,true,GetNextArgument(GetFirstArgument()));
  }

/****************************************/
/* UnwatchCommand: H/L access routine   */
/*   for the unwatch command.           */
/****************************************/
void UnwatchCommand(
  Environment *theEnv,
  UDFContext *context,
  UDFValue *returnValue)
  {
   UDFValue theValue;
   const char *argument;
   bool recognized;
   WatchItemRecord *wPtr;

   /*==========================================*/
   /* Determine which item is to be unwatched. */
   /*==========================================*/

   if (! UDFFirstArgument(context,SYMBOL_BIT,&theValue)) return;

   argument = theValue.lexemeValue->contents;
   wPtr = ValidWatchItem(theEnv,argument,&recognized);
   if (recognized == false)
     {
      SetEvaluationError(theEnv,true);
      UDFInvalidArgumentMessage(context,"watchable symbol");
      return;
     }

   /*=================================================*/
   /* Check to make sure extra arguments are allowed. */
   /*=================================================*/

   if (GetNextArgument(GetFirstArgument()) != NULL)
     {
      if ((wPtr == NULL) ? true : (wPtr->accessFunc == NULL))
        {
         SetEvaluationError(theEnv,true);
         ExpectedCountError(theEnv,"unwatch",EXACTLY,1);
         return;
        }
     }

   /*=====================*/
   /* Set the watch item. */
   /*=====================*/

   SetWatchItem(theEnv,argument,false,GetNextArgument(GetFirstArgument()));
  }

/************************************************/
/* ListWatchItemsCommand: H/L access routines   */
/*   for the list-watch-items command.          */
/************************************************/
void ListWatchItemsCommand(
  Environment *theEnv,
  UDFContext *context,
  UDFValue *returnValue)
  {
   WatchItemRecord *wPtr;
   UDFValue theValue;
   bool recognized;

   /*=======================*/
   /* List the watch items. */
   /*=======================*/

   if (GetFirstArgument() == NULL)
     {
      for (wPtr = WatchData(theEnv)->ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next)
        {
         WriteString(theEnv,STDOUT,wPtr->name);
         if (*(wPtr->flag)) WriteString(theEnv,STDOUT," = on\n");
         else WriteString(theEnv,STDOUT," = off\n");
        }
      return;
     }

   /*=======================================*/
   /* Determine which item is to be listed. */
   /*=======================================*/

   if (! UDFFirstArgument(context,SYMBOL_BIT,&theValue)) return;
   wPtr = ValidWatchItem(theEnv,theValue.lexemeValue->contents,&recognized);
   if ((recognized == false) || (wPtr == NULL))
     {
      SetEvaluationError(theEnv,true);
      ExpectedTypeError1(theEnv,"list-watch-items",1,"'watchable symbol'");
      return;
     }

   /*=================================================*/
   /* Check to make sure extra arguments are allowed. */
   /*=================================================*/

   if ((wPtr->printFunc == NULL) &&
       (GetNextArgument(GetFirstArgument()) != NULL))
     {
      SetEvaluationError(theEnv,true);
      ExpectedCountError(theEnv,"list-watch-items",EXACTLY,1);
      return;
     }

   /*====================================*/
   /* List the status of the watch item. */
   /*====================================*/

   WriteString(theEnv,STDOUT,wPtr->name);
   if (*(wPtr->flag)) WriteString(theEnv,STDOUT," = on\n");
   else WriteString(theEnv,STDOUT," = off\n");

   /*============================================*/
   /* List the status of individual watch items. */
   /*============================================*/

   if (wPtr->printFunc != NULL)
     {
      if ((*wPtr->printFunc)(theEnv,STDOUT,wPtr->code,
                             GetNextArgument(GetFirstArgument())) == false)
        { SetEvaluationError(theEnv,true); }
     }
  }

/*******************************************/
/* GetWatchItemCommand: H/L access routine */
/*   for the get-watch-item command.       */
/*******************************************/
void GetWatchItemCommand(
  Environment *theEnv,
  UDFContext *context,
  UDFValue *returnValue)
  {
   UDFValue theValue;
   const char *argument;
   bool recognized;

   /*========================================*/
   /* Determine which item is to be watched. */
   /*========================================*/

   if (! UDFFirstArgument(context,SYMBOL_BIT,&theValue))
     { return; }

   argument = theValue.lexemeValue->contents;
   ValidWatchItem(theEnv,argument,&recognized);
   if (recognized == false)
     {
      SetEvaluationError(theEnv,true);
      ExpectedTypeError1(theEnv,"get-watch-item",1,"'watchable symbol'");
      returnValue->lexemeValue = FalseSymbol(theEnv);
      return;
     }

   /*===========================*/
   /* Get the watch item value. */
   /*===========================*/

   if (GetWatchItem(theEnv,argument) == 1)
     { returnValue->lexemeValue = TrueSymbol(theEnv); }
   else
     { returnValue->lexemeValue = FalseSymbol(theEnv); }
  }

/*************************************************************/
/* WatchFunctionDefinitions: Initializes the watch commands. */
/*************************************************************/
void WatchFunctionDefinitions(
  Environment *theEnv)
  {
#if ! RUN_TIME
   AddUDF(theEnv,"watch","v",1,UNBOUNDED,"*;y",WatchCommand,"WatchCommand",NULL);
   AddUDF(theEnv,"unwatch","v",1,UNBOUNDED,"*;y",UnwatchCommand,"UnwatchCommand",NULL);
   AddUDF(theEnv,"get-watch-item","b",1,1,"y",GetWatchItemCommand,"GetWatchItemCommand",NULL);
   AddUDF(theEnv,"list-watch-items","v",0,UNBOUNDED,"*;y",ListWatchItemsCommand,"ListWatchItemsCommand",NULL);
#endif
  }

#endif /* DEBUGGING_FUNCTIONS */