GNU PROLOG with UTF8 support
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
flag_supp.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------*
2  * GNU Prolog *
3  * *
4  * Part : Prolog buit-in predicates *
5  * File : flag_supp.h *
6  * Descr.: Prolog flag and system variable support - header file *
7  * Author: Daniel Diaz *
8  * *
9  * Copyright (C) 1999-2015 Daniel Diaz *
10  * *
11  * This file is part of GNU Prolog *
12  * *
13  * GNU Prolog is free software: you can redistribute it and/or *
14  * modify it under the terms of either: *
15  * *
16  * - the GNU Lesser General Public License as published by the Free *
17  * Software Foundation; either version 3 of the License, or (at your *
18  * option) any later version. *
19  * *
20  * or *
21  * *
22  * - the GNU General Public License as published by the Free *
23  * Software Foundation; either version 2 of the License, or (at your *
24  * option) any later version. *
25  * *
26  * or both in parallel, as here. *
27  * *
28  * GNU Prolog is distributed in the hope that it will be useful, *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
31  * General Public License for more details. *
32  * *
33  * You should have received copies of the GNU General Public License and *
34  * the GNU Lesser General Public License along with this program. If *
35  * not, see http://www.gnu.org/licenses/. *
36  *-------------------------------------------------------------------------*/
37 
38 
39 /*---------------------------------*
40  * Constants *
41  *---------------------------------*/
42 
43  /* values for integer_rounding_function */
44 #define PF_ROUND_ZERO 0
45 #define PF_ROUND_DOWN 1
46 
47  /* values for unknown, syntax_error, os_error */
48 #define PF_ERR_ERROR 0 /* same order as in read.pl */
49 #define PF_ERR_WARNING 1
50 #define PF_ERR_FAIL 2
51 
52 
53  /* values for double_quotes and back_quotes */
54 #define PF_QUOT_AS_CODES 0 /* bit 2 is set if no_escape */
55 #define PF_QUOT_AS_CHARS 1
56 #define PF_QUOT_AS_ATOM 2
57 #define PF_QUOT_NO_ESCAPE_BIT 2
58 #define PF_QUOT_AS_PART_MASK ((1 << PF_QUOT_NO_ESCAPE_BIT) - 1)
59 #define PF_QUOT_NO_ESCAPE_MASK ((1 << PF_QUOT_NO_ESCAPE_BIT))
60 
61 
62 
63 
64 /*---------------------------------*
65  * Type Definitions *
66  *---------------------------------*/
67 
68 typedef struct flag_inf *FlagInfP;
69 
70 typedef WamWord (*FlagFctGet)(FlagInfP flag);
71 typedef Bool (*FlagFctChk)(FlagInfP flag, WamWord tag_mask, WamWord value_word);
72 typedef Bool (*FlagFctSet)(FlagInfP flag, WamWord value_word);
73 
74 
75 typedef enum
76 {
77  PF_TYPE_INTEGER, /* an integer (value = int) */
78  PF_TYPE_ATOM, /* an atom (value = int of atom) */
79  PF_TYPE_ROUND, /* toward_zero/down (see PF_ROUND_)*/
80  PF_TYPE_BOOL, /* false/true */
81  PF_TYPE_ON_OFF, /* off/on (value = 0/1) */
82  PF_TYPE_ERR, /* error,warning,fail (see PF_ERR_)*/
83  PF_TYPE_QUOTES, /* chars,... (see PF_QUOTES_) */
84  PF_TYPE_ANY /* other (value = user handled) */
85 }FlagType;
86 
87 
88 
89 typedef struct flag_inf /* flag information */
90 { /* ------------------------------- */
91  int atom_name; /* atom of the flag name */
92  Bool modifiable; /* is it modifiable ? */
93  FlagType type; /* type see PF_TYPE_xxx */
94  PlLong value; /* flag value (generic value) */
95  FlagFctGet fct_get; /* value -> term (curr prolog flag)*/
96  FlagFctChk fct_chk; /* check term (for set prolog flag)*/
97  FlagFctSet fct_set; /* term -> value (set prolog flag)*/
98 }FlagInf;
99 
100 
101 
102 
103 /*---------------------------------*
104  * Global Variables *
105  *---------------------------------*/
106 
107 
108 /*---------------------------------*
109  * Function Prototypes *
110  *---------------------------------*/
111 
114 
115 
116 /* macros to create flags of predefined types.
117  * modifiable flags give rise to global variable pl_flag_xxx
118  */
119 
120 #define NEW_FLAG_INTEGER(f, v) Pl_New_Prolog_Flag(#f, FALSE, PF_TYPE_INTEGER, v, NULL, NULL, NULL)
121 
122 #define NEW_FLAG_ATOM_A(f, v) Pl_New_Prolog_Flag(#f, FALSE, PF_TYPE_ATOM, v, NULL, NULL, NULL)
123 
124 #define NEW_FLAG_ATOM(f, v) Pl_New_Prolog_Flag(#f, FALSE, PF_TYPE_ATOM, Pl_Create_Atom(v), NULL, NULL, NULL)
125 
126 #define NEW_FLAG_ROUND(f, v) Pl_New_Prolog_Flag(#f, FALSE, PF_TYPE_ROUND, v, NULL, NULL, NULL)
127 
128 #define NEW_FLAG_BOOL(f, v) Pl_New_Prolog_Flag(#f, FALSE, PF_TYPE_BOOL, v, NULL, NULL, NULL)
129 
130 #define NEW_FLAG_ON_OFF(f, v) pl_flag_##f = Pl_New_Prolog_Flag(#f, TRUE, PF_TYPE_ON_OFF, v, NULL, NULL, NULL)
131 
132 #define NEW_FLAG_ERR(f, v) pl_flag_##f = Pl_New_Prolog_Flag(#f, TRUE, PF_TYPE_ERR, v, NULL, NULL, NULL)
133 
134 #define NEW_FLAG_QUOTES(f, v) pl_flag_##f = Pl_New_Prolog_Flag(#f, TRUE, PF_TYPE_QUOTES, v, NULL, NULL, NULL)
135 
136 
137 
138 
139 #define Flag_Value(f) ((pl_flag_##f)->value)
140 
141 
142 
143 
144 /*-------------------------------------------------------------------------*
145  * Things related to flag_c.c: *
146  * - concrete implementation of flags (e.g. variables pl_flag_xxx) *
147  * - system variables management (sys_var) *
148  * All of this should be better in another .h file but here for simplicity *
149  *-------------------------------------------------------------------------*/
150 
151 
152 #define Char_Conversion(c) ((Flag_Value(char_conversion) && \
153  Is_Valid_Code(c)) ? pl_char_conv[c] : (c))
154 
155 
156 #define SYS_VAR_OPTION_MASK (pl_sys_var[0])
157 
158 #define SYS_VAR_WRITE_DEPTH (pl_sys_var[1])
159 #define SYS_VAR_SYNTAX_ERROR_ACTON (pl_sys_var[1])
160 
161 #define SYS_VAR_WRITE_PREC (pl_sys_var[2])
162 
163 #define SYS_VAR_WRITE_ABOVE (pl_sys_var[3])
164 
165 #define SYS_VAR_FD_BCKTS (pl_sys_var[4])
166 
167 #define SYS_VAR_TOP_LEVEL (pl_sys_var[10])
168 #define SYS_VAR_LINEDIT (pl_sys_var[12])
169 #define SYS_VAR_DEBUGGER (pl_sys_var[13])
170 
171 #define SYS_VAR_SAY_GETC (pl_sys_var[20])
172 #define CHAR_TO_EMIT_WHEN_CHAR '\1'
173 
174 
175 
176 
177 #ifdef FLAG_C_FILE
178 
180 
192 
193 #else
194 
195 extern PlLong pl_sys_var[];
196 
199 extern FlagInf *pl_flag_debug;
202 extern FlagInf *pl_flag_os_error;
207 extern FlagInf *pl_flag_unknown;
208 
209 #endif
210 
211 
212 
213 
215 
217 
218 
219 /*-------------------------------------------------------------------------*
220  * System variables (C and Prolog) - bank description *
221  * *
222  * 0: temporary (e.g. masks for option lists (open/read/write)). *
223  * 1: temporary (e.g. depth in write). *
224  * 2: temporary (e.g. reorder in FD labeling). *
225  * 3: temporary (e.g. write '$above' limit). *
226  * 4: temporary (e.g. backtracks counter in FD labeling). *
227  * *
228  * 7: permanent catch handler. *
229  * 8: permanent catch ball. *
230  * *
231  * 10: permanent top level depth (for top-level and stop/abort). *
232  * 11: permanent top level handler (B level) for abort and stop. *
233  * 12: permanent: is linedit present ? *
234  * 13: permanent: is the debugger present ? *
235  * *
236  * 20: permanent: should stream fcts emit a char before calling fgetc ? *
237  * *
238  * 100..: free for users (who know pl_sys_var[] exists !) *
239  *-------------------------------------------------------------------------*/
static char name[32]
Definition: test_oc_defs.h:8
Bool modifiable
Definition: flag_supp.h:92
Definition: flag_supp.h:89
FlagInf * pl_flag_singleton_warning
FlagInf * pl_flag_debug
Definition: flag_supp.h:80
FlagFctChk fct_chk
Definition: flag_supp.h:96
FlagInf * pl_flag_syntax_error
Bool(* FlagFctChk)(FlagInfP flag, WamWord tag_mask, WamWord value_word)
Definition: flag_supp.h:71
#define MAX_SYS_VARS
Definition: b_params.h:43
Definition: flag_supp.h:78
FlagFctSet fct_set
Definition: flag_supp.h:97
Bool Pl_Write_Pl_State_File(WamWord file_word)
Definition: flag_c.c:522
intptr_t PlLong
Definition: gprolog.h:88
FlagType
Definition: flag_supp.h:75
FlagInf * pl_flag_back_quotes
Definition: flag_supp.h:81
Bool(* FlagFctSet)(FlagInfP flag, WamWord value_word)
Definition: flag_supp.h:72
FlagInf * pl_flag_char_conversion
FlagFctGet fct_get
Definition: flag_supp.h:95
WamWord(* FlagFctGet)(FlagInfP flag)
Definition: flag_supp.h:70
int atom_name
Definition: flag_supp.h:91
PlLong pl_sys_var[]
Definition: flag_supp.h:84
Definition: flag_supp.h:83
Definition: flag_supp.h:77
FlagType type
Definition: flag_supp.h:93
FlagInf * pl_flag_unknown
FlagInf * pl_flag_os_error
PlLong value
Definition: flag_supp.h:94
FlagInf * pl_flag_suspicious_warning
FlagInf * pl_flag_multifile_warning
FlagInf * Pl_New_Prolog_Flag(char *name, Bool modifiable, FlagType type, PlLong value, FlagFctGet fct_get, FlagFctChk fct_chk, FlagFctSet fct_set)
Definition: flag_supp.c:411
long WamWord
Definition: LINUX_SIGSEGV.c:4
struct flag_inf FlagInf
Definition: flag_supp.h:82
Bool Pl_Read_Pl_State_File(WamWord file_word)
Definition: flag_c.c:605
int Bool
Definition: bool.h:65
FlagInf * pl_flag_double_quotes
Definition: flag_supp.h:79
struct flag_inf * FlagInfP
Definition: flag_supp.h:68
FlagInf * pl_flag_strict_iso