GNU PROLOG with UTF8 support
linedit.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------*
2  * GNU Prolog *
3  * *
4  * Part : line-edit library *
5  * File : linedit.h *
6  * Descr.: line editor - 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 #include "../EnginePl/pl_wchar.h"
39 
40 /* Windows uses 2 codepages (which give the meaning of 0x80..0xFF chars):
41  * "OEM codepages" for console programs and "ANSI codepages" for GUI programs.
42  * For instance 'é' (\'e) is returned as 130 in OEM (with codepage 850) and
43  * as 233 in ANSI. The problem is that isalpha(130) is false...
44  * I use 2 Win32 functions: OemToChar() (when reading) and CharToOem()
45  * (when writing)... */
46 
47 #if 1
48 #define WIN32_CONVERT_OEM_ASCII
49 #endif
50 
51 /*---------------------------------*
52  * Constants *
53  *---------------------------------*/
54 
55 /*---------------------------------*
56  * Type Definitions *
57  *---------------------------------*/
58 
59 enum {
60  LE_MODE_DEACTIVATED = 0, /* linedit is deactivated */
61  LE_MODE_TTY, /* linedit runs in console mode */
62  LE_MODE_HOOK /* linedit runs via a hook (i.e. GUI) */
63 };
64 
65 
66 
67 
68 /*---------------------------------*
69  * Global Variables *
70  *---------------------------------*/
71 
72 /* overwritten if needed to customize linedit */
73 
74 void (*pl_le_hook_start) ();
75 
76  /* is it mandatory to define a hook ? */
77 void (*pl_le_hook_put_char) (); /* mandatory */
78 int (*pl_le_hook_get_char0) (); /* mandatory */
81 
82 void (*pl_le_hook_screen_size) (); /* mandatory */
83 int (*pl_le_hook_kbd_is_not_empty) (); /* mandatory */
84 
85 void (*pl_le_hook_backd) ();
86 void (*pl_le_hook_forwd) ();
87 void (*pl_le_hook_displ) ();
89 void (*pl_le_hook_erase) ();
90 
91  /* functions not used by linedit itself */
94 void (*pl_le_hook_flush) ();
98 
99 
100 #ifdef LE_DEFINE_HOOK_MACROS
101 
102 #define EMIT_BEEP ((*pl_le_hook_emit_beep)())
103 #define PUT_CHAR(c) ((*pl_le_hook_put_char)(c))
104 #define GET_CHAR0 ((*pl_le_hook_get_char0)())
105 #define INS_MODE(ins_mode) ((*pl_le_hook_ins_mode)(ins_mode))
106 
107 #define SCREEN_SIZE(r, c) ((*pl_le_hook_screen_size)(r, c))
108 #define KBD_IS_NOT_EMPTY ((*pl_le_hook_kbd_is_not_empty)())
109 
110 #define BACKD(n) ((*pl_le_hook_backd)(n))
111 #define FORWD(n, str) ((*pl_le_hook_forwd)(n, str))
112 #define DISPL(n, str) ((*pl_le_hook_displ)(n, str))
113 #define DISPL_STR(str) ((*pl_le_hook_displ_str)(str))
114 #define ERASE(n) ((*pl_le_hook_erase)(n))
115 
116 #endif
117 
118 
119 /*---------------------------------*
120  * Function Prototypes *
121  *---------------------------------*/
122 
123 int Pl_LE_Initialize(void);
124 
125 
126 char *Pl_LE_Gets(char *str);
127 
128 char *Pl_LE_FGets(char *str, int size, char *prompt, int display_prompt);
129 
130 
132 
133 #define LE_Interrupted_By_Ctrl_C(r) ((PlLong) r == (PlLong) -2)
134 
135 
136 int Pl_LE_Get_Prompt_Length(void);
137 
139 
140 void Pl_LE_Get_Current_Word(char *word);
141 
142 char *Pl_LE_Get_Separators(void);
143 
144 char *Pl_LE_Set_Separators(char *sep_str);
145 
146 
147 
148 char *Pl_LE_Compl_Add_Word(char *word, int word_length);
149 
150 char *Pl_LE_Compl_Del_Word(char *word);
151 
152 char *Pl_LE_Compl_Init_Match(char *prefix, int *nb_match, int *max_lg);
153 
154 char *Pl_LE_Compl_Find_Match(int *is_last);
155 
156 
157 CHAR32_T Pl_LE_Get_Key(int echo, int catch_ctrl_c);
158 
159 
160 int Pl_LE_Printf(char *format, ...);
161 
162 
163 
164 #ifdef TERMINAL_FILE
165 
167 
168 #else
169 
171 
172 #endif
#define CHAR32_T
Definition: pl_wchar.h:9
void Pl_LE_Get_Current_Word(char *word)
Definition: linedit.c:947
void(* pl_le_hook_start)()
Definition: linedit.h:74
int(* pl_le_hook_kbd_is_not_empty)()
Definition: linedit.h:83
char * format
Definition: hexfilter.c:78
int(* pl_le_initialize)()
Definition: linedit.h:170
intptr_t PlLong
Definition: gprolog.h:88
void(* pl_le_hook_message_box)()
Definition: linedit.h:96
char * Pl_LE_Compl_Del_Word(char *word)
Definition: linedit.c:1200
int(* pl_le_hook_get_char0)()
Definition: linedit.h:78
PlLong Pl_LE_Get_Ctrl_C_Return_Value(void)
Definition: linedit.c:1000
char * Pl_LE_Set_Separators(char *sep_str)
Definition: linedit.c:987
CHAR32_T Pl_LE_Get_Key(int echo, int catch_ctrl_c)
Definition: linedit.c:1485
void(* pl_le_hook_set_line_buffering)()
Definition: linedit.h:92
void(* pl_le_hook_put_char)()
Definition: linedit.h:77
void(* pl_le_hook_erase)()
Definition: linedit.h:89
char * Pl_LE_Gets(char *str)
Definition: linedit.c:245
void(* pl_le_hook_displ_str)()
Definition: linedit.h:88
int(* pl_le_hook_get_line_buffering)()
Definition: linedit.h:93
char * Pl_LE_Compl_Init_Match(char *prefix, int *nb_match, int *max_lg)
Definition: linedit.c:1231
void(* pl_le_hook_displ)()
Definition: linedit.h:87
void(* pl_le_hook_backd)()
Definition: linedit.h:85
char * Pl_LE_Get_Separators(void)
Definition: linedit.c:974
char * Pl_LE_Compl_Add_Word(char *word, int word_length)
Definition: linedit.c:1165
int Pl_LE_Printf(char *format,...)
Definition: linedit.c:1538
Definition: linedit.h:60
void(* pl_le_hook_forwd)()
Definition: linedit.h:86
void(* pl_le_hook_emit_beep)()
Definition: linedit.h:79
int Pl_LE_Get_Prompt_Length(void)
Definition: linedit.c:921
void(* pl_le_hook_screen_size)()
Definition: linedit.h:82
Definition: linedit.h:62
void(* pl_le_hook_flush)()
Definition: linedit.h:94
char * Pl_LE_FGets(char *str, int size, char *prompt, int display_prompt)
Definition: linedit.c:269
void(* pl_le_hook_ins_mode)()
Definition: linedit.h:80
void(* pl_le_hook_exit_process)()
Definition: linedit.h:97
int Pl_LE_Get_Current_Position(void)
Definition: linedit.c:934
int Pl_LE_Initialize(void)
Definition: terminal.c:176
Definition: linedit.h:61
char * Pl_LE_Compl_Find_Match(int *is_last)
Definition: linedit.c:1261
int(* pl_le_hook_confirm_box)()
Definition: linedit.h:95