Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
print.h
Go to the documentation of this file.
1 /*************************************************************************
2  * PLEASE SEE THE FILE "license.txt" (INCLUDED WITH THIS SOFTWARE PACKAGE)
3  * FOR LICENSE AND COPYRIGHT INFORMATION.
4  *************************************************************************/
5 
6 /* ======================================================================
7 
8  print.h
9 
10  Printing with an Optional Log File and with Redirection to a File
11 
12  We want to print stuff not only to the screen but also to a log
13  file (if one is currently being used). The print_string(), print(),
14  print_with_symbols(), and print_spaces() routines do this.
15 
16  Start_log_file() and stop_log_file() open and close the current log
17  file. Print_string_to_log_file_only() is called by the lexer to
18  echo keyboard input to the log file (it's already on the screen, so
19  we don't want to print it there too).
20 
21  Print_string() and print_spaces() do the obvious things.
22  Print() is exactly like printf() in C, except it prints to both
23  the screen and log file (if there is one). Print_with_symbols()
24  is sort of like print, but only takes two kinds of escape sequences
25  in the format string:
26  %y -- print a symbol
27  %% -- print a "%" sign
28 
29  Sometimes we need to know the current output column so we can put
30  a line break in the right place. Get_printer_output_column() returns
31  the current column number (1 means the start of the line).
32  Tell_printer_that_output_column_has_been_reset () is called from the
33  lexer every time it reads a line from the keyboard--since after the
34  user types a line (and hits return) the output column is reset.
35 
36  We also support temporarily redirecting all printing output to
37  another file. This is done by calling start_redirection_to_file()
38  and stop_redirection_to_file(). In between these calls, all screen
39  and log file output is turned off, and printing is done only to the
40  redirection file.
41 ====================================================================== */
42 
43 #ifndef PRINT_H
44 #define PRINT_H
45 
46 #include <stdio.h> // Needed for FILE token below
47 
48 #ifdef __cplusplus
49 //extern "C"
50 //{
51 #endif
52 
53 typedef char Bool;
54 typedef char * test;
55 typedef char * rhs_value;
56 typedef unsigned char byte;
58 typedef struct wme_struct wme;
59 typedef struct agent_struct agent;
60 typedef struct action_struct action;
63 typedef struct condition_struct condition;
65 typedef union symbol_union Symbol;
66 
67 typedef struct wme_filter_struct {
71  bool adds;
72  bool removes;
73 } wme_filter;
74 
75 extern void start_log_file (agent* thisAgent, char *filename, Bool append);
76 extern void stop_log_file (agent* thisAgent);
77 extern void print_string_to_log_file_only (agent* thisAgent, char *string);
78 
79 extern int get_printer_output_column (agent* thisAgent);
81 
82 extern void start_redirection_to_file (agent* thisAgent, FILE *already_opened_file);
83 extern void stop_redirection_to_file (agent* thisAgent);
84 
85 extern void print_string (agent* thisAgent, const char *s);
86 extern void print_phase (agent* thisAgent, const char *s, bool end_phase);
87 
88 extern void print (agent* thisAgent, const char *format, ... );
89 extern void print_with_symbols (agent* thisAgent, const char *format, ...);
90 extern void snprintf_with_symbols (agent* thisAgent, char* dest, size_t count, const char *format, ...);
91 extern void print_spaces (agent* thisAgent, int n);
92 
93 extern void filtered_print_wme_remove(agent* thisAgent, wme *w);
94 extern void filtered_print_wme_add(agent* thisAgent, wme *w);
95 
96 
97 
98 /* ------------------------------------------------------------------------
99  String to Escaped String Conversion
100  {Symbol, Test, RHS Value} to String Conversion
101 
102  These routines produce strings. Each takes an optional parameter "dest"
103  which, if non-nil, points to the destination buffer for the result string.
104  If dest is nil, these routines use a global buffer, and return a pointer
105  to it. (Otherwise "dest" itself is returned.) Note that a single global
106  buffer is shared by all three routines, so callers should assume the
107  buffer will be destroyed by the next call to these routines with dest=NIL.
108 
109  String_to_escaped_string() takes a string and a first/last char,
110  and produces an "escaped string" representation of the string; i.e.,
111  a string that uses '\' escapes to include special characters.
112  For example, input 'ab"c' with first/last character '"' yields
113  '"ab\"c"'. This is used for printing quoted strings and for printing
114  symbols using |vbar| notation.
115 
116  Symbol_to_string() converts a symbol to a string. The "rereadable"
117  parameter indicates whether a rereadable representation is desired.
118  Normally symbols are printed rereadably, but for (write) and Text I/O,
119  we don't want this.
120 
121  Test_to_string() takes a test and produces a string representation.
122 
123  Rhs_value_to_string() takes an rhs_value and produces a string
124  representation. The rhs_value MUST NOT be a reteloc.
125 ----------------------------------------------------------------------- */
126 
127 extern char *string_to_escaped_string (agent* thisAgent, char *s, char first_and_last_char,
128  char *dest);
129 extern char const* symbol_to_typeString (agent* thisAgent, Symbol *sym);
130 extern char *symbol_to_string (agent* thisAgent, Symbol *sym, Bool rereadable, char *dest, size_t dest_size);
131 extern char *test_to_string (agent* thisAgent, test t, char *dest, size_t dest_size);
132 extern char *rhs_value_to_string (agent* thisAgent, rhs_value rv, char *dest, size_t dest_size);
133 
134 /* -----------------------------------------------------------------------
135  Print Condition List, Action List, Production
136 
137  Print_condition_list() prints a list of conditions. The "indent"
138  parameter tells how many spaces to indent each line other than the
139  first--the first line is not indented (the caller must handle this).
140  The last line is printed without a trailing linefeed. The "internal"
141  parameter, if TRUE, indicates that the condition list should be printed
142  in internal format--one condition per line, without grouping all the
143  conditions for the same id into one line.
144 
145  Print_action_list() is similar except it prints actions instead of
146  conditions. The actions MUST NOT contain any reteloc's.
147 
148  Print_production() prints a given production, optionally using internal
149  format.
150 ----------------------------------------------------------------------- */
151 
152 extern void print_condition_list (agent* thisAgent, condition *conds, int indent, Bool internal);
153 extern void print_action_list (agent* thisAgent, action *actions, int indent, Bool internal);
154 extern void print_production (agent* thisAgent, production *p, Bool internal);
155 
156 /* -----------------------------------------------------------------------
157  Other Printing Utilities
158 
159  Print_condition() prints a single condition. Print_action() prints
160  a single action (which MUST NOT contain any reteloc's).
161  Note that these routines work by calling print_condition_list() and
162  print_action_list(), respectively, so they print a linefeed if the
163  output would go past COLUMNS_PER_LINE.
164 
165  Preference_type_indicator() returns a character corresponding to
166  a given preference type (byte)--for example, given BEST_PREFERENCE_TYPE,
167  it returns '>'.
168 
169  Print_preference() prints a given preference. Print_wme() prints a
170  wme (including the timetag). Print_instantiation_with_wmes() prints
171  an instantiation's production name and the wmes it matched, using a
172  given wme_trace_type (e.g., TIMETAG_WME_TRACE). Action is printing,
173  firing or retracting -- added March 05 KJC.
174 ----------------------------------------------------------------------- */
175 
176 extern void print_condition (agent* thisAgent, condition *cond);
177 extern void print_action (agent* thisAgent, action *a);
178 extern char preference_type_indicator (agent* thisAgent, byte type);
179 extern void print_preference (agent* thisAgent, preference *pref);
180 extern void print_wme (agent* thisAgent, wme *w);
181 extern void print_wme_without_timetag (agent* thisAgent, wme *w);
182 extern void print_wme_for_tcl (wme *w);
183 extern void print_instantiation_with_wmes (agent* thisAgent,
184  instantiation *inst,
185  wme_trace_type wtt,
186  int action);
187 
188 extern void print_list_of_conditions(agent* thisAgent, condition *cond);
189 
190 #ifdef __cplusplus
191 //}
192 #endif
193 
194 #endif