aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Kbuild.include10
-rw-r--r--scripts/Makefile.build17
-rw-r--r--scripts/Makefile.host23
-rw-r--r--scripts/basic/.gitignore3
-rw-r--r--scripts/basic/docproc.c15
-rw-r--r--scripts/basic/fixdep.c67
-rw-r--r--scripts/basic/split-include.c24
-rwxr-xr-xscripts/bloat-o-meter25
-rwxr-xr-xscripts/embedded_scripts6
-rw-r--r--scripts/kconfig/.gitignore1
-rw-r--r--scripts/kconfig/Makefile14
-rw-r--r--scripts/kconfig/conf.c15
-rw-r--r--scripts/kconfig/confdata.c9
-rw-r--r--scripts/kconfig/libcurses/Kbuild.src51
-rw-r--r--scripts/kconfig/libcurses/README.md20
-rw-r--r--scripts/kconfig/libcurses/acs437.h35
-rw-r--r--scripts/kconfig/libcurses/acsuni.h35
-rw-r--r--scripts/kconfig/libcurses/addch.c410
-rw-r--r--scripts/kconfig/libcurses/addstr.c241
-rw-r--r--scripts/kconfig/libcurses/attr.c411
-rw-r--r--scripts/kconfig/libcurses/beep.c76
-rw-r--r--scripts/kconfig/libcurses/bkgd.c228
-rw-r--r--scripts/kconfig/libcurses/border.c418
-rw-r--r--scripts/kconfig/libcurses/clear.c161
-rw-r--r--scripts/kconfig/libcurses/color.c364
-rw-r--r--scripts/kconfig/libcurses/curses.h1441
-rw-r--r--scripts/kconfig/libcurses/curspriv.h133
-rw-r--r--scripts/kconfig/libcurses/getch.c591
-rw-r--r--scripts/kconfig/libcurses/getyx.c144
-rw-r--r--scripts/kconfig/libcurses/inch.c128
-rw-r--r--scripts/kconfig/libcurses/initscr.c433
-rw-r--r--scripts/kconfig/libcurses/inopts.c410
-rw-r--r--scripts/kconfig/libcurses/kernel.c299
-rw-r--r--scripts/kconfig/libcurses/move.c79
-rw-r--r--scripts/kconfig/libcurses/outopts.c262
-rw-r--r--scripts/kconfig/libcurses/overlay.c216
-rw-r--r--scripts/kconfig/libcurses/pad.c276
-rw-r--r--scripts/kconfig/libcurses/pdcclip.c155
-rw-r--r--scripts/kconfig/libcurses/pdcdisp.c329
-rw-r--r--scripts/kconfig/libcurses/pdcgetsc.c42
-rw-r--r--scripts/kconfig/libcurses/pdckbd.c693
-rw-r--r--scripts/kconfig/libcurses/pdcscrn.c686
-rw-r--r--scripts/kconfig/libcurses/pdcsetsc.c133
-rw-r--r--scripts/kconfig/libcurses/pdcutil.c26
-rw-r--r--scripts/kconfig/libcurses/pdcwin.h27
-rw-r--r--scripts/kconfig/libcurses/printw.c131
-rw-r--r--scripts/kconfig/libcurses/refresh.c289
-rw-r--r--scripts/kconfig/libcurses/scroll.c103
-rw-r--r--scripts/kconfig/libcurses/slk.c673
-rw-r--r--scripts/kconfig/libcurses/touch.c210
-rw-r--r--scripts/kconfig/libcurses/window.c639
-rw-r--r--scripts/kconfig/lkc.h6
-rwxr-xr-xscripts/kconfig/lxdialog/check-lxdialog.sh8
-rw-r--r--scripts/kconfig/lxdialog/dialog.h1
-rw-r--r--scripts/kconfig/lxdialog/util.c3
-rw-r--r--scripts/kconfig/mconf.c242
-rw-r--r--scripts/kconfig/symbol.c31
-rw-r--r--scripts/kconfig/zconf.hash.c_shipped60
-rw-r--r--scripts/kconfig/zconf.tab.c_shipped1
-rwxr-xr-xscripts/mk_mingw64u_defconfig39
-rwxr-xr-xscripts/mkconfigs4
-rwxr-xr-xscripts/mkwcwidth169
-rwxr-xr-xscripts/trylink8
63 files changed, 11744 insertions, 55 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 5b4db5c2c..b61ff8b42 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -52,25 +52,25 @@ endef
52# as-option 52# as-option
53# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,) 53# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,)
54 54
55as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \ 55as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o - \
56 -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; \ 56 -xassembler - </dev/null > /dev/null 2>&1; then echo "$(1)"; \
57 else echo "$(2)"; fi ;) 57 else echo "$(2)"; fi ;)
58 58
59# cc-option 59# cc-option
60# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586) 60# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
61 61
62cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ 62cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o - -xc - </dev/null \
63 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) 63 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
64 64
65# hostcc-option 65# hostcc-option
66# Usage: hostcflags-y += $(call hostcc-option, -march=winchip-c6, -march=i586) 66# Usage: hostcflags-y += $(call hostcc-option, -march=winchip-c6, -march=i586)
67 67
68hostcc-option = $(shell if $(HOSTCC) $(HOSTCFLAGS) $(1) -S -o /dev/null -xc /dev/null \ 68hostcc-option = $(shell if $(HOSTCC) $(HOSTCFLAGS) $(1) -S -o - -xc - </dev/null \
69 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) 69 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
70 70
71# cc-option-yn 71# cc-option-yn
72# Usage: flag := $(call cc-option-yn, -march=winchip-c6) 72# Usage: flag := $(call cc-option-yn, -march=winchip-c6)
73cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ 73cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o - -xc - </dev/null \
74 > /dev/null 2>&1; then echo "y"; else echo "n"; fi;) 74 > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
75 75
76# cc-option-align 76# cc-option-align
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 5eac45f91..cd5592b34 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -254,11 +254,28 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ;
254# 254#
255ifdef builtin-target 255ifdef builtin-target
256quiet_cmd_link_o_target = LD $@ 256quiet_cmd_link_o_target = LD $@
257ifeq ($(CONFIG_PLATFORM_POSIX),y)
257# If the list of objects to link is empty, just create an empty built-in.o 258# If the list of objects to link is empty, just create an empty built-in.o
258# -nostdlib is added to make "make LD=gcc ..." work (some people use that) 259# -nostdlib is added to make "make LD=gcc ..." work (some people use that)
259cmd_link_o_target = $(if $(strip $(obj-y)),\ 260cmd_link_o_target = $(if $(strip $(obj-y)),\
260 $(LD) -nostdlib $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\ 261 $(LD) -nostdlib $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
261 rm -f $@; $(AR) rcs $@) 262 rm -f $@; $(AR) rcs $@)
263else
264# In default builds of busybox-w32 all builtin targets have either
265# zero or one object files. In the latter case copy the object to
266# the target. This avoids the need to use the linker: the llvm
267# linker doesn't support the -r option.
268ifeq ($(words $(obj-y)),0)
269cmd_link_o_target = rm -f $@; $(AR) rcs $@
270else
271ifeq ($(words $(obj-y)),1)
272cmd_link_o_target = cp $(obj-y) $@
273else
274cmd_link_o_target = \
275 $(LD) -nostdlib $(ld_flags) -r -o $@ $(filter $(obj-y), $^))
276endif
277endif
278endif
262 279
263$(builtin-target): $(obj-y) FORCE 280$(builtin-target): $(obj-y) FORCE
264 $(call if_changed,link_o_target) 281 $(call if_changed,link_o_target)
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index 2e628508d..7b380460a 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -92,13 +92,32 @@ endif
92hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags) 92hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags)
93hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags) 93hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags)
94 94
95# Programs built for use on the host are defined without a suffix
96# (usually '.exe' on Windows). Rather than adjust all the makefiles
97# force a suffix of '.' if the host platform is mingw32. This will
98# result in binaries with no suffix.
99#
100# It's not a big deal if this doesn't work. MSYS2 doesn't need it
101# and the downside is just that the programs will be rebuilt more
102# often than really needed.
103#
104host_target := $(shell $(HOSTCC) -v 2>&1 | grep ^Target:)
105host_platform := $(word 4,$(subst -, ,$(host_target)))
106dot :=
107ifeq ($(host_platform),mingw32)
108dot := .
109endif
110ifeq ($(host_platform),windows)
111dot := .
112endif
113
95##### 114#####
96# Compile programs on the host 115# Compile programs on the host
97 116
98# Create executable from a single .c file 117# Create executable from a single .c file
99# host-csingle -> Executable 118# host-csingle -> Executable
100quiet_cmd_host-csingle = HOSTCC $@ 119quiet_cmd_host-csingle = HOSTCC $@
101 cmd_host-csingle = $(HOSTCC) $(hostc_flags) -o $@ $< \ 120 cmd_host-csingle = $(HOSTCC) $(hostc_flags) -o $@$(dot) $< \
102 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) 121 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
103$(host-csingle): %: %.c FORCE 122$(host-csingle): %: %.c FORCE
104 $(call if_changed_dep,host-csingle) 123 $(call if_changed_dep,host-csingle)
@@ -106,7 +125,7 @@ $(host-csingle): %: %.c FORCE
106# Link an executable based on list of .o files, all plain c 125# Link an executable based on list of .o files, all plain c
107# host-cmulti -> executable 126# host-cmulti -> executable
108quiet_cmd_host-cmulti = HOSTLD $@ 127quiet_cmd_host-cmulti = HOSTLD $@
109 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \ 128 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@$(dot) \
110 $(addprefix $(obj)/,$($(@F)-objs)) \ 129 $(addprefix $(obj)/,$($(@F)-objs)) \
111 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) 130 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
112$(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE 131$(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE
diff --git a/scripts/basic/.gitignore b/scripts/basic/.gitignore
index d91e941a4..3d20e4f15 100644
--- a/scripts/basic/.gitignore
+++ b/scripts/basic/.gitignore
@@ -2,3 +2,6 @@ hash
2fixdep 2fixdep
3docproc 3docproc
4split-include 4split-include
5/docproc.exe
6/fixdep.exe
7/split-include.exe
diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c
index 8828901a1..c488cd53e 100644
--- a/scripts/basic/docproc.c
+++ b/scripts/basic/docproc.c
@@ -38,7 +38,9 @@
38#include <unistd.h> 38#include <unistd.h>
39#include <limits.h> 39#include <limits.h>
40#include <sys/types.h> 40#include <sys/types.h>
41#ifndef __MINGW32__
41#include <sys/wait.h> 42#include <sys/wait.h>
43#endif
42//bbox disabled: #include <alloca.h> 44//bbox disabled: #include <alloca.h>
43 45
44/* exitstatus is used to keep track of any failing calls to kernel-doc, 46/* exitstatus is used to keep track of any failing calls to kernel-doc,
@@ -78,12 +80,24 @@ void usage (void)
78 */ 80 */
79void exec_kernel_doc(char **svec) 81void exec_kernel_doc(char **svec)
80{ 82{
83#ifndef __MINGW32__
81 pid_t pid; 84 pid_t pid;
82 int ret; 85 int ret;
86#endif
83 char *real_filename; 87 char *real_filename;
84 int rflen; 88 int rflen;
85 89
86 /* Make sure output generated so far are flushed */ 90 /* Make sure output generated so far are flushed */
91#ifdef __MINGW32__
92 fflush(stdout);
93 rflen = strlen(getenv("SRCTREE"));
94 rflen += strlen(KERNELDOCPATH KERNELDOC);
95 real_filename = alloca(rflen + 1);
96 strcpy(real_filename, getenv("SRCTREE"));
97 strcat(real_filename, KERNELDOCPATH KERNELDOC);
98 fprintf(stderr, "NOTIMPL: exec %s\n", real_filename);
99 exit(1);
100#else
87 fflush(stdout); 101 fflush(stdout);
88 switch(pid=fork()) { 102 switch(pid=fork()) {
89 case -1: 103 case -1:
@@ -106,6 +120,7 @@ void exec_kernel_doc(char **svec)
106 exitstatus |= WEXITSTATUS(ret); 120 exitstatus |= WEXITSTATUS(ret);
107 else 121 else
108 exitstatus = 0xff; 122 exitstatus = 0xff;
123#endif
109} 124}
110 125
111/* Types used to create list of all exported symbols in a number of files */ 126/* Types used to create list of all exported symbols in a number of files */
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 071c3b407..47a0cee07 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -104,7 +104,9 @@
104 104
105#include <sys/types.h> 105#include <sys/types.h>
106#include <sys/stat.h> 106#include <sys/stat.h>
107#ifndef __MINGW32__
107#include <sys/mman.h> 108#include <sys/mman.h>
109#endif
108#include <errno.h> 110#include <errno.h>
109#include <unistd.h> 111#include <unistd.h>
110#include <fcntl.h> 112#include <fcntl.h>
@@ -113,7 +115,9 @@
113#include <stdio.h> 115#include <stdio.h>
114#include <limits.h> 116#include <limits.h>
115#include <ctype.h> 117#include <ctype.h>
118#ifndef __MINGW32__
116#include <arpa/inet.h> 119#include <arpa/inet.h>
120#endif
117//bbox disabled: #include <alloca.h> 121//bbox disabled: #include <alloca.h>
118 122
119/* bbox: not needed 123/* bbox: not needed
@@ -123,6 +127,57 @@
123#define INT_FIG_ ntohl(0x4649475f) 127#define INT_FIG_ ntohl(0x4649475f)
124*/ 128*/
125 129
130#ifndef O_BINARY
131#define O_BINARY 0
132#endif
133
134#ifdef __MINGW32__
135#define UNUSED __attribute__ ((__unused__))
136
137/* Workaround specifically for fixdep */
138#define PROT_READ 0
139#define MAP_PRIVATE 0
140void *mmap(void *start UNUSED, size_t size, int prot UNUSED,
141 int flags UNUSED, int fd, off_t offset UNUSED)
142{
143 void *p;
144 void *curP;
145 ssize_t readB;
146
147 p = malloc(size);
148 if (!p)
149 return (void*)((long)-1);
150
151 curP = p;
152
153 while (size > 0)
154 {
155 readB = read(fd, curP, size);
156
157 if (readB == 0)
158 {
159 /* EOF reached */
160 break;
161 }
162 else if (readB < 0)
163 {
164 perror("fixdep: read config");
165 free(p);
166 return (void*)((long)-1);
167 }
168
169 size -= readB;
170 curP += readB;
171 }
172
173 return p;
174}
175void munmap(void *p, size_t size UNUSED)
176{
177 free(p);
178}
179#endif
180
126char *target; 181char *target;
127char *depfile; 182char *depfile;
128char *cmdline; 183char *cmdline;
@@ -287,7 +342,7 @@ void do_config_file(char *filename)
287 int fd; 342 int fd;
288 void *map; 343 void *map;
289 344
290 fd = open(filename, O_RDONLY); 345 fd = open(filename, O_RDONLY | O_BINARY);
291 if (fd < 0) { 346 if (fd < 0) {
292 fprintf(stderr, "fixdep: "); 347 fprintf(stderr, "fixdep: ");
293 perror(filename); 348 perror(filename);
@@ -302,7 +357,7 @@ void do_config_file(char *filename)
302 return; 357 return;
303 } 358 }
304 map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 359 map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
305 if ((long) map == -1) { 360 if ((intptr_t) map == -1) {
306 perror("fixdep: mmap"); 361 perror("fixdep: mmap");
307 close(fd); 362 close(fd);
308 return; 363 return;
@@ -338,8 +393,9 @@ void parse_dep_file(void *map, size_t len)
338 m++; 393 m++;
339 p = m; 394 p = m;
340 while (p < end && *p != ' ') p++; 395 while (p < end && *p != ' ') p++;
396 if (p == m) break;
341 if (p == end) { 397 if (p == end) {
342 do p--; while (!isalnum((unsigned char)*p)); 398 do p--; while (p != m && !isalnum((unsigned char)*p));
343 p++; 399 p++;
344 } 400 }
345 if (p < m) { 401 if (p < m) {
@@ -354,6 +410,7 @@ void parse_dep_file(void *map, size_t len)
354 printf(" %s \\\n", s); 410 printf(" %s \\\n", s);
355 do_config_file(s); 411 do_config_file(s);
356 } 412 }
413 if (p == end) break;
357 m = p + 1; 414 m = p + 1;
358 } 415 }
359 printf("\n%s: $(deps_%s)\n\n", target, target); 416 printf("\n%s: $(deps_%s)\n\n", target, target);
@@ -366,7 +423,7 @@ void print_deps(void)
366 int fd; 423 int fd;
367 void *map; 424 void *map;
368 425
369 fd = open(depfile, O_RDONLY); 426 fd = open(depfile, O_RDONLY | O_BINARY);
370 if (fd < 0) { 427 if (fd < 0) {
371 fprintf(stderr, "fixdep: "); 428 fprintf(stderr, "fixdep: ");
372 perror(depfile); 429 perror(depfile);
@@ -382,7 +439,7 @@ void print_deps(void)
382 return; 439 return;
383 } 440 }
384 map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 441 map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
385 if ((long) map == -1) { 442 if ((intptr_t) map == -1) {
386 perror("fixdep: mmap"); 443 perror("fixdep: mmap");
387 close(fd); 444 close(fd);
388 return; 445 return;
diff --git a/scripts/basic/split-include.c b/scripts/basic/split-include.c
index 6ef29195e..a85ede8ef 100644
--- a/scripts/basic/split-include.c
+++ b/scripts/basic/split-include.c
@@ -39,8 +39,6 @@
39 exit(1); \ 39 exit(1); \
40 } 40 }
41 41
42
43
44int main(int argc, const char * argv []) 42int main(int argc, const char * argv [])
45{ 43{
46 const char * str_my_name; 44 const char * str_my_name;
@@ -89,7 +87,11 @@ int main(int argc, const char * argv [])
89 /* Make output directory if needed. */ 87 /* Make output directory if needed. */
90 if (stat(str_dir_config, &stat_buf) != 0) 88 if (stat(str_dir_config, &stat_buf) != 0)
91 { 89 {
90#ifdef __MINGW32__
91 if (mkdir(str_dir_config) != 0)
92#else
92 if (mkdir(str_dir_config, 0755) != 0) 93 if (mkdir(str_dir_config, 0755) != 0)
94#endif
93 ERROR_EXIT(str_dir_config); 95 ERROR_EXIT(str_dir_config);
94 } 96 }
95 97
@@ -149,7 +151,12 @@ int main(int argc, const char * argv [])
149 { 151 {
150 ptarget[islash] = '\0'; 152 ptarget[islash] = '\0';
151 if (stat(ptarget, &stat_buf) != 0 153 if (stat(ptarget, &stat_buf) != 0
152 && mkdir(ptarget, 0755) != 0) 154#ifdef __MINGW32__
155 && mkdir(ptarget) != 0
156#else
157 && mkdir(ptarget, 0755) != 0
158#endif
159 )
153 ERROR_EXIT( ptarget ); 160 ERROR_EXIT( ptarget );
154 ptarget[islash] = '/'; 161 ptarget[islash] = '/';
155 } 162 }
@@ -190,13 +197,21 @@ int main(int argc, const char * argv [])
190 * So by having an initial \n, strstr will find exact matches. 197 * So by having an initial \n, strstr will find exact matches.
191 */ 198 */
192 199
200#ifdef __MINGW32__
201 fp_find = popen("find . -type f -name \"*.h\" -print", "r");
202#else
193 fp_find = popen("find * -type f -name \"*.h\" -print", "r"); 203 fp_find = popen("find * -type f -name \"*.h\" -print", "r");
204#endif
194 if (fp_find == 0) 205 if (fp_find == 0)
195 ERROR_EXIT( "find" ); 206 ERROR_EXIT( "find" );
196 207
197 line[0] = '\n'; 208 line[0] = '\n';
198 while (fgets(line+1, buffer_size, fp_find)) 209 while (fgets(line+1, buffer_size, fp_find))
199 { 210 {
211#ifdef __MINGW32__
212 line[2] = '\n';
213# define line (line + 2)
214#endif
200 if (strstr(list_target, line) == NULL) 215 if (strstr(list_target, line) == NULL)
201 { 216 {
202 /* 217 /*
@@ -219,6 +234,9 @@ int main(int argc, const char * argv [])
219 ERROR_EXIT(line); 234 ERROR_EXIT(line);
220 } 235 }
221 } 236 }
237#ifdef __MINGW32__
238# undef line
239#endif
222 } 240 }
223 241
224 if (pclose(fp_find) != 0) 242 if (pclose(fp_find) != 0)
diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter
index b4a1d2811..26474595f 100755
--- a/scripts/bloat-o-meter
+++ b/scripts/bloat-o-meter
@@ -43,6 +43,8 @@ if f1 is None or f2 is None:
43 43
44sym_args = " ".join(sys.argv[3 + flag_timing + dashes:]) 44sym_args = " ".join(sys.argv[3 + flag_timing + dashes:])
45def getsizes(file): 45def getsizes(file):
46 if file.endswith(".exe"):
47 return getsizes_pe(file)
46 sym, alias, lut, section = {}, {}, {}, {} 48 sym, alias, lut, section = {}, {}, {}, {}
47 for l in os.popen("readelf -W -S " + file).readlines(): 49 for l in os.popen("readelf -W -S " + file).readlines():
48 x = l.replace("[ ", "[", 1).split() 50 x = l.replace("[ ", "[", 1).split()
@@ -80,6 +82,29 @@ def getsizes(file):
80 sym[alias[(addr, sz)]["name"]] = {"addr" : addr, "size": sz} 82 sym[alias[(addr, sz)]["name"]] = {"addr" : addr, "size": sz}
81 return sym 83 return sym
82 84
85def getsizes_pe(file):
86 sym, sections = {}, {}
87 prefix = os.getenv("CROSS_COMPILE", "")
88 for l in os.popen(prefix + "objdump -h " + file).readlines():
89 x = l.split()
90 if len(x) != 7: continue
91 sections[x[1]] = 1
92 if x[1] not in [".rdata"]: continue
93 sym[x[1]] = {"addr" : int(x[3], 16), "size" : int(x[2], 16)}
94 for l in os.popen(prefix + "nm -S --size-sort %s %s" % (sym_args, file)).readlines():
95 if len(l.split()) != 4: continue
96 value, size, typ, name = l.split()
97 if typ in ["N"]: continue # skip debug symbols
98 if name in sections: continue # bare reference to section
99 value = int(value, 16)
100 size = int(size, 16)
101 if "$" in name:
102 section, name = name.split("$")
103 if section in sym:
104 sym[section]["size"] -= size
105 sym[name] = {"addr" : value, "size": size}
106 return sym
107
83if flag_timing: 108if flag_timing:
84 start_t1 = int(time.time() * 1e9) 109 start_t1 = int(time.time() * 1e9)
85old = getsizes(f1) 110old = getsizes(f1)
diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts
index 205ac591a..88c3a13cb 100755
--- a/scripts/embedded_scripts
+++ b/scripts/embedded_scripts
@@ -23,8 +23,8 @@ if test $? != 0; then
23 exit 1 23 exit 1
24fi 24fi
25 25
26bzip2 </dev/null >/dev/null 26bzip2 </dev/null >/dev/null 2>&1
27if test $? != 0; then 27if test $? = 127; then
28 echo 'bzip2 is not installed' 28 echo 'bzip2 is not installed'
29 exit 1 29 exit 1
30fi 30fi
@@ -90,6 +90,7 @@ concatenate_scripts() {
90 done 90 done
91} 91}
92 92
93(
93exec >"$target.$$" 94exec >"$target.$$"
94 95
95if [ $n -ne 0 ] 96if [ $n -ne 0 ]
@@ -127,5 +128,6 @@ then
127 -e 's/$/ \\/' 128 -e 's/$/ \\/'
128 printf '\n' 129 printf '\n'
129fi 130fi
131)
130 132
131mv -- "$target.$$" "$target" 133mv -- "$target.$$" "$target"
diff --git a/scripts/kconfig/.gitignore b/scripts/kconfig/.gitignore
index b49584c93..aa9c7d637 100644
--- a/scripts/kconfig/.gitignore
+++ b/scripts/kconfig/.gitignore
@@ -17,3 +17,4 @@ mconf
17qconf 17qconf
18gconf 18gconf
19kxgettext 19kxgettext
20/conf.exe
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 38bae809a..ed07c4c62 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -2,6 +2,17 @@
2# Kernel configuration targets 2# Kernel configuration targets
3# These targets are used from top-level makefile 3# These targets are used from top-level makefile
4 4
5# If w64devkit isn't run via w64devkit.exe W64DEVKIT won't be
6# defined. If HOSTCC targets the mingw32 platform set W64DEVKIT.
7ifndef W64DEVKIT
8 host_target := $(shell $(HOSTCC) -v 2>&1 | grep ^Target:)
9 host_platform := $(lastword $(subst -, ,$(host_target)))
10 ifeq ($(host_platform),mingw32)
11 W64DEVKIT := 1
12 export W64DEVKIT
13 endif
14endif
15
5PHONY += oldconfig xconfig gconfig menuconfig config silentoldconfig update-po-config 16PHONY += oldconfig xconfig gconfig menuconfig config silentoldconfig update-po-config
6 17
7xconfig: $(obj)/qconf 18xconfig: $(obj)/qconf
@@ -11,6 +22,9 @@ gconfig: $(obj)/gconf
11 $< Config.in 22 $< Config.in
12 23
13menuconfig: $(obj)/mconf 24menuconfig: $(obj)/mconf
25ifdef W64DEVKIT
26 $(Q)$(MAKE) $(build)=scripts/kconfig/libcurses
27endif
14 $(Q)$(MAKE) $(build)=scripts/kconfig/lxdialog 28 $(Q)$(MAKE) $(build)=scripts/kconfig/lxdialog
15 $< Config.in 29 $< Config.in
16 30
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 39ec1cdb6..4680932d7 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -193,9 +193,14 @@ static void conf_askvalue(struct symbol *sym, const char *def)
193 break; 193 break;
194 } 194 }
195 case set_random: 195 case set_random:
196#ifdef __MINGW32__
197 fprintf(stderr, "set_random not supported\n");
198 exit(1);
199#else
196 do { 200 do {
197 val = (tristate)(random() % 3); 201 val = (tristate)(random() % 3);
198 } while (!sym_tristate_within_range(sym, val)); 202 } while (!sym_tristate_within_range(sym, val));
203#endif
199 switch (val) { 204 switch (val) {
200 case no: line[0] = 'n'; break; 205 case no: line[0] = 'n'; break;
201 case mod: line[0] = 'm'; break; 206 case mod: line[0] = 'm'; break;
@@ -407,7 +412,12 @@ static int conf_choice(struct menu *menu)
407 continue; 412 continue;
408 break; 413 break;
409 case set_random: 414 case set_random:
415#ifdef __MINGW32__
416 fprintf(stderr, "set_random not supported\n");
417 exit(1);
418#else
410 def = (random() % cnt) + 1; 419 def = (random() % cnt) + 1;
420#endif
411 case set_default: 421 case set_default:
412 case set_yes: 422 case set_yes:
413 case set_mod: 423 case set_mod:
@@ -563,8 +573,13 @@ int main(int ac, char **av)
563 input_mode = set_yes; 573 input_mode = set_yes;
564 break; 574 break;
565 case 'r': 575 case 'r':
576#ifdef __MINGW32__
577 fprintf(stderr, "set_random not supported\n");
578 exit(1);
579#else
566 input_mode = set_random; 580 input_mode = set_random;
567 srandom(time(NULL)); 581 srandom(time(NULL));
582#endif
568 break; 583 break;
569 case 'h': 584 case 'h':
570 case '?': 585 case '?':
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 249a3195e..2f7fa6618 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -584,15 +584,24 @@ int conf_write(const char *name)
584 fclose(out); 584 fclose(out);
585 if (out_h) { 585 if (out_h) {
586 fclose(out_h); 586 fclose(out_h);
587#ifdef __MINGW32__
588 unlink("include/autoconf.h");
589#endif
587 rename(".tmpconfig.h", "include/autoconf.h"); 590 rename(".tmpconfig.h", "include/autoconf.h");
588 } 591 }
589 if (!name || basename != conf_def_filename) { 592 if (!name || basename != conf_def_filename) {
590 if (!name) 593 if (!name)
591 name = conf_def_filename; 594 name = conf_def_filename;
592 sprintf(tmpname, "%s.old", name); 595 sprintf(tmpname, "%s.old", name);
596#ifdef __MINGW32__
597 unlink(tmpname);
598#endif
593 rename(name, tmpname); 599 rename(name, tmpname);
594 } 600 }
595 sprintf(tmpname, "%s%s", dirname, basename); 601 sprintf(tmpname, "%s%s", dirname, basename);
602#ifdef __MINGW32__
603 unlink(tmpname);
604#endif
596 if (rename(newname, tmpname)) 605 if (rename(newname, tmpname))
597 return 1; 606 return 1;
598 607
diff --git a/scripts/kconfig/libcurses/Kbuild.src b/scripts/kconfig/libcurses/Kbuild.src
new file mode 100644
index 000000000..d04da63bb
--- /dev/null
+++ b/scripts/kconfig/libcurses/Kbuild.src
@@ -0,0 +1,51 @@
1lib-y :=
2
3INSERT
4
5lib-y +=addch.o
6lib-n +=addchstr.o
7lib-y +=addstr.o
8lib-y +=attr.o
9lib-y +=beep.o
10lib-y +=bkgd.o
11lib-y +=border.o
12lib-y +=clear.o
13lib-y +=color.o
14lib-n +=debug.o
15lib-n +=delch.o
16lib-n +=deleteln.o
17lib-y +=getch.o
18lib-n +=getstr.o
19lib-y +=getyx.o
20lib-y +=inch.o
21lib-n +=inchstr.o
22lib-y +=initscr.o
23lib-y +=inopts.o
24lib-n +=insch.o
25lib-n +=insstr.o
26lib-n +=instr.o
27lib-y +=kernel.o
28lib-n +=keyname.o
29lib-n +=mouse.o
30lib-y +=move.o
31lib-y +=outopts.o
32lib-y +=overlay.o
33lib-y +=pad.o
34lib-n +=panel.o
35lib-y +=pdcclip.o
36lib-y +=pdcdisp.o
37lib-y +=pdcgetsc.o
38lib-y +=pdckbd.o
39lib-y +=pdcscrn.o
40lib-y +=pdcsetsc.o
41lib-y +=pdcutil.o
42lib-y +=printw.o
43lib-y +=refresh.o
44lib-n +=scanw.o
45lib-n +=scr_dump.o
46lib-y +=scroll.o
47lib-y +=slk.o
48lib-n +=termattr.o
49lib-y +=touch.o
50lib-n +=util.o
51lib-y +=window.o
diff --git a/scripts/kconfig/libcurses/README.md b/scripts/kconfig/libcurses/README.md
new file mode 100644
index 000000000..81f5b2cbe
--- /dev/null
+++ b/scripts/kconfig/libcurses/README.md
@@ -0,0 +1,20 @@
1PDCurses for Windows console
2============================
3
4This directory contains PDCurses source code files specific to the
5Microsoft Windows console. Although historically called "Win32", this
6port can just as easily be built for 64-bit systems. Windows 95 through
7Windows 10 are covered. (Some features require later versions.)
8
9
10Acknowledgements
11----------------
12
13Windows console port was originally provided by Chris Szurgot
14<szurgot@itribe.net>
15
16
17Distribution Status
18-------------------
19
20The files in this directory are released to the public domain.
diff --git a/scripts/kconfig/libcurses/acs437.h b/scripts/kconfig/libcurses/acs437.h
new file mode 100644
index 000000000..24cbd7854
--- /dev/null
+++ b/scripts/kconfig/libcurses/acs437.h
@@ -0,0 +1,35 @@
1/* ACS definitions originally by jshumate@wrdis01.robins.af.mil -- these
2 match code page 437 and compatible pages (CP850, CP852, etc.) */
3
4chtype acs_map[128] =
5{
6 PDC_ACS(0), PDC_ACS(1), PDC_ACS(2), PDC_ACS(3), PDC_ACS(4),
7 PDC_ACS(5), PDC_ACS(6), PDC_ACS(7), PDC_ACS(8), PDC_ACS(9),
8 PDC_ACS(10), PDC_ACS(11), PDC_ACS(12), PDC_ACS(13), PDC_ACS(14),
9 PDC_ACS(15), PDC_ACS(16), PDC_ACS(17), PDC_ACS(18), PDC_ACS(19),
10 PDC_ACS(20), PDC_ACS(21), PDC_ACS(22), PDC_ACS(23), PDC_ACS(24),
11 PDC_ACS(25), PDC_ACS(26), PDC_ACS(27), PDC_ACS(28), PDC_ACS(29),
12 PDC_ACS(30), PDC_ACS(31), ' ', '!', '"', '#', '$', '%', '&', '\'',
13 '(', ')', '*',
14
15 PDC_ACS(0x1a), PDC_ACS(0x1b), PDC_ACS(0x18), PDC_ACS(0x19),
16
17 '/',
18
19 0xdb,
20
21 '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
22 '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
23 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
24 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
25
26 PDC_ACS(0x04), 0xb1,
27
28 'b', 'c', 'd', 'e',
29
30 0xf8, 0xf1, 0xb0, PDC_ACS(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d,
31 0x2d, 0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3, 0xf2,
32 0xe3, 0xd8, 0x9c, 0xf9,
33
34 PDC_ACS(127)
35};
diff --git a/scripts/kconfig/libcurses/acsuni.h b/scripts/kconfig/libcurses/acsuni.h
new file mode 100644
index 000000000..2fdad8a1c
--- /dev/null
+++ b/scripts/kconfig/libcurses/acsuni.h
@@ -0,0 +1,35 @@
1/* ACS Unicode mapping */
2
3chtype acs_map[128] =
4{
5 PDC_ACS(0), PDC_ACS(1), PDC_ACS(2), PDC_ACS(3), PDC_ACS(4),
6 PDC_ACS(5), PDC_ACS(6), PDC_ACS(7), PDC_ACS(8), PDC_ACS(9),
7 PDC_ACS(10), PDC_ACS(11), PDC_ACS(12), PDC_ACS(13), PDC_ACS(14),
8 PDC_ACS(15), PDC_ACS(16), PDC_ACS(17), PDC_ACS(18), PDC_ACS(19),
9 PDC_ACS(20), PDC_ACS(21), PDC_ACS(22), PDC_ACS(23), PDC_ACS(24),
10 PDC_ACS(25), PDC_ACS(26), PDC_ACS(27), PDC_ACS(28), PDC_ACS(29),
11 PDC_ACS(30), PDC_ACS(31), ' ', '!', '"', '#', '$', '%', '&', '\'',
12 '(', ')', '*',
13
14 0x2192, 0x2190, 0x2191, 0x2193,
15
16 '/',
17
18 0x2588,
19
20 '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
21 '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
22 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
23 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
24
25 0x2666, 0x2592,
26
27 'b', 'c', 'd', 'e',
28
29 0x00b0, 0x00b1, 0x2591, 0x00a4, 0x2518, 0x2510, 0x250c, 0x2514,
30 0x253c, 0x23ba, 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524,
31 0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3,
32 0x00b7,
33
34 PDC_ACS(127)
35};
diff --git a/scripts/kconfig/libcurses/addch.c b/scripts/kconfig/libcurses/addch.c
new file mode 100644
index 000000000..3d1f9c04b
--- /dev/null
+++ b/scripts/kconfig/libcurses/addch.c
@@ -0,0 +1,410 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7addch
8-----
9
10### Synopsis
11
12 int addch(const chtype ch);
13 int waddch(WINDOW *win, const chtype ch);
14 int mvaddch(int y, int x, const chtype ch);
15 int mvwaddch(WINDOW *win, int y, int x, const chtype ch);
16 int echochar(const chtype ch);
17 int wechochar(WINDOW *win, const chtype ch);
18
19 int addrawch(chtype ch);
20 int waddrawch(WINDOW *win, chtype ch);
21 int mvaddrawch(int y, int x, chtype ch);
22 int mvwaddrawch(WINDOW *win, int y, int x, chtype ch);
23
24 int add_wch(const cchar_t *wch);
25 int wadd_wch(WINDOW *win, const cchar_t *wch);
26 int mvadd_wch(int y, int x, const cchar_t *wch);
27 int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch);
28 int echo_wchar(const cchar_t *wch);
29 int wecho_wchar(WINDOW *win, const cchar_t *wch);
30
31### Description
32
33 addch() adds the chtype ch to the default window (stdscr) at the
34 current cursor position, and advances the cursor. Note that chtypes
35 can convey both text (a single character) and attributes, including a
36 color pair. add_wch() is the wide-character version of this function,
37 taking a pointer to a cchar_t instead of a chtype.
38
39 waddch() is like addch(), but also lets you specify the window. (This
40 is in fact the core output routine.) wadd_wch() is the wide version.
41
42 mvaddch() moves the cursor to the specified (y, x) position, and adds
43 ch to stdscr. mvadd_wch() is the wide version.
44
45 mvwaddch() moves the cursor to the specified position and adds ch to
46 the specified window. mvwadd_wch() is the wide version.
47
48 echochar() adds ch to stdscr at the current cursor position and calls
49 refresh(). echo_wchar() is the wide version.
50
51 wechochar() adds ch to the specified window and calls wrefresh().
52 wecho_wchar() is the wide version.
53
54 addrawch(), waddrawch(), mvaddrawch() and mvwaddrawch() are PDCurses-
55 specific wrappers for addch() etc. that disable the translation of
56 control characters.
57
58 The following applies to all these functions:
59
60 If the cursor moves on to the right margin, an automatic newline is
61 performed. If scrollok is enabled, and a character is added to the
62 bottom right corner of the window, the scrolling region will be
63 scrolled up one line. If scrolling is not allowed, ERR will be
64 returned.
65
66 If ch is a tab, newline, or backspace, the cursor will be moved
67 appropriately within the window. If ch is a newline, the clrtoeol
68 routine is called before the cursor is moved to the beginning of the
69 next line. If newline mapping is off, the cursor will be moved to
70 the next line, but the x coordinate will be unchanged. If ch is a
71 tab the cursor is moved to the next tab position within the window.
72 If ch is another control character, it will be drawn in the ^X
73 notation. Calling the inch() routine after adding a control
74 character returns the representation of the control character, not
75 the control character.
76
77 Video attributes can be combined with a character by ORing them into
78 the parameter. Text, including attributes, can be copied from one
79 place to another by using inch() and addch().
80
81 Note that in PDCurses, for now, a cchar_t and a chtype are the same.
82 The text field is 16 bits wide, and is treated as Unicode (UCS-2)
83 when PDCurses is built with wide-character support (define PDC_WIDE).
84 So, in functions that take a chtype, like addch(), both the wide and
85 narrow versions will handle Unicode. But for portability, you should
86 use the wide functions.
87
88### Return Value
89
90 All functions return OK on success and ERR on error.
91
92### Portability
93
94 Function | X/Open | ncurses | NetBSD
95 :---------------------|:------:|:-------:|:------:
96 addch | Y | Y | Y
97 waddch | Y | Y | Y
98 mvaddch | Y | Y | Y
99 mvwaddch | Y | Y | Y
100 echochar | Y | Y | Y
101 wechochar | Y | Y | Y
102 add_wch | Y | Y | Y
103 wadd_wch | Y | Y | Y
104 mvadd_wch | Y | Y | Y
105 mvwadd_wch | Y | Y | Y
106 echo_wchar | Y | Y | Y
107 wecho_wchar | Y | Y | Y
108 addrawch | - | - | -
109 waddrawch | - | - | -
110 mvaddrawch | - | - | -
111 mvwaddrawch | - | - | -
112
113**man-end****************************************************************/
114
115int waddch(WINDOW *win, const chtype ch)
116{
117 int x, y;
118 chtype text, attr;
119 bool xlat;
120
121 PDC_LOG(("waddch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
122 win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
123
124 if (!win || !SP)
125 return ERR;
126
127 x = win->_curx;
128 y = win->_cury;
129
130 if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)
131 return ERR;
132
133 xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
134 text = ch & A_CHARTEXT;
135 attr = ch & A_ATTRIBUTES;
136
137 if (xlat && (text < ' ' || text == 0x7f))
138 {
139 int x2;
140
141 switch (text)
142 {
143 case '\t':
144 for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++)
145 {
146 if (waddch(win, attr | ' ') == ERR)
147 return ERR;
148
149 /* if tab to next line, exit the loop */
150
151 if (!win->_curx)
152 break;
153 }
154 return OK;
155
156 case '\n':
157 /* if lf -> crlf */
158
159 if (!SP->raw_out)
160 x = 0;
161
162 wclrtoeol(win);
163
164 if (++y > win->_bmarg)
165 {
166 y--;
167
168 if (wscrl(win, 1) == ERR)
169 return ERR;
170 }
171
172 break;
173
174 case '\b':
175 /* don't back over left margin */
176
177 if (--x < 0)
178 case '\r':
179 x = 0;
180
181 break;
182
183 case 0x7f:
184 if (waddch(win, attr | '^') == ERR)
185 return ERR;
186
187 return waddch(win, attr | '?');
188
189 default:
190 /* handle control chars */
191
192 if (waddch(win, attr | '^') == ERR)
193 return ERR;
194
195 return waddch(win, ch + '@');
196 }
197 }
198 else
199 {
200 /* If the incoming character doesn't have its own attribute,
201 then use the current attributes for the window. If it has
202 attributes but not a color component, OR the attributes to
203 the current attributes for the window. If it has a color
204 component, use the attributes solely from the incoming
205 character. */
206
207 if (!(attr & A_COLOR))
208 attr |= win->_attrs;
209
210 /* wrs (4/10/93): Apply the same sort of logic for the window
211 background, in that it only takes precedence if other color
212 attributes are not there and that the background character
213 will only print if the printing character is blank. */
214
215 if (!(attr & A_COLOR))
216 attr |= win->_bkgd & A_ATTRIBUTES;
217 else
218 attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
219
220 if (text == ' ')
221 text = win->_bkgd & A_CHARTEXT;
222
223 /* Add the attribute back into the character. */
224
225 text |= attr;
226
227 /* Only change _firstch/_lastch if the character to be added is
228 different from the character/attribute that is already in
229 that position in the window. */
230
231 if (win->_y[y][x] != text)
232 {
233 if (win->_firstch[y] == _NO_CHANGE)
234 win->_firstch[y] = win->_lastch[y] = x;
235 else
236 if (x < win->_firstch[y])
237 win->_firstch[y] = x;
238 else
239 if (x > win->_lastch[y])
240 win->_lastch[y] = x;
241
242 win->_y[y][x] = text;
243 }
244
245 if (++x >= win->_maxx)
246 {
247 /* wrap around test */
248
249 x = 0;
250
251 if (++y > win->_bmarg)
252 {
253 y--;
254
255 if (wscrl(win, 1) == ERR)
256 {
257 PDC_sync(win);
258 return ERR;
259 }
260 }
261 }
262 }
263
264 win->_curx = x;
265 win->_cury = y;
266
267 if (win->_immed)
268 wrefresh(win);
269 if (win->_sync)
270 wsyncup(win);
271
272 return OK;
273}
274
275int addch(const chtype ch)
276{
277 PDC_LOG(("addch() - called: ch=%x\n", ch));
278
279 return waddch(stdscr, ch);
280}
281
282int mvaddch(int y, int x, const chtype ch)
283{
284 PDC_LOG(("mvaddch() - called: y=%d x=%d ch=%x\n", y, x, ch));
285
286 if (move(y,x) == ERR)
287 return ERR;
288
289 return waddch(stdscr, ch);
290}
291
292int mvwaddch(WINDOW *win, int y, int x, const chtype ch)
293{
294 PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d ch=%d\n", win, y, x, ch));
295
296 if (wmove(win, y, x) == ERR)
297 return ERR;
298
299 return waddch(win, ch);
300}
301
302int echochar(const chtype ch)
303{
304 PDC_LOG(("echochar() - called: ch=%x\n", ch));
305
306 return wechochar(stdscr, ch);
307}
308
309int wechochar(WINDOW *win, const chtype ch)
310{
311 PDC_LOG(("wechochar() - called: win=%p ch=%x\n", win, ch));
312
313 if (waddch(win, ch) == ERR)
314 return ERR;
315
316 return wrefresh(win);
317}
318
319int waddrawch(WINDOW *win, chtype ch)
320{
321 PDC_LOG(("waddrawch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
322 win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
323
324 if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f)
325 ch |= A_ALTCHARSET;
326
327 return waddch(win, ch);
328}
329
330int addrawch(chtype ch)
331{
332 PDC_LOG(("addrawch() - called: ch=%x\n", ch));
333
334 return waddrawch(stdscr, ch);
335}
336
337int mvaddrawch(int y, int x, chtype ch)
338{
339 PDC_LOG(("mvaddrawch() - called: y=%d x=%d ch=%d\n", y, x, ch));
340
341 if (move(y, x) == ERR)
342 return ERR;
343
344 return waddrawch(stdscr, ch);
345}
346
347int mvwaddrawch(WINDOW *win, int y, int x, chtype ch)
348{
349 PDC_LOG(("mvwaddrawch() - called: win=%p y=%d x=%d ch=%d\n",
350 win, y, x, ch));
351
352 if (wmove(win, y, x) == ERR)
353 return ERR;
354
355 return waddrawch(win, ch);
356}
357
358#ifdef PDC_WIDE
359int wadd_wch(WINDOW *win, const cchar_t *wch)
360{
361 PDC_LOG(("wadd_wch() - called: win=%p wch=%x\n", win, *wch));
362
363 return wch ? waddch(win, *wch) : ERR;
364}
365
366int add_wch(const cchar_t *wch)
367{
368 PDC_LOG(("add_wch() - called: wch=%x\n", *wch));
369
370 return wadd_wch(stdscr, wch);
371}
372
373int mvadd_wch(int y, int x, const cchar_t *wch)
374{
375 PDC_LOG(("mvaddch() - called: y=%d x=%d wch=%x\n", y, x, *wch));
376
377 if (move(y,x) == ERR)
378 return ERR;
379
380 return wadd_wch(stdscr, wch);
381}
382
383int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch)
384{
385 PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d wch=%d\n",
386 win, y, x, *wch));
387
388 if (wmove(win, y, x) == ERR)
389 return ERR;
390
391 return wadd_wch(win, wch);
392}
393
394int echo_wchar(const cchar_t *wch)
395{
396 PDC_LOG(("echo_wchar() - called: wch=%x\n", *wch));
397
398 return wecho_wchar(stdscr, wch);
399}
400
401int wecho_wchar(WINDOW *win, const cchar_t *wch)
402{
403 PDC_LOG(("wecho_wchar() - called: win=%p wch=%x\n", win, *wch));
404
405 if (!wch || (wadd_wch(win, wch) == ERR))
406 return ERR;
407
408 return wrefresh(win);
409}
410#endif
diff --git a/scripts/kconfig/libcurses/addstr.c b/scripts/kconfig/libcurses/addstr.c
new file mode 100644
index 000000000..bc286d4b5
--- /dev/null
+++ b/scripts/kconfig/libcurses/addstr.c
@@ -0,0 +1,241 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7addstr
8------
9
10### Synopsis
11
12 int addstr(const char *str);
13 int addnstr(const char *str, int n);
14 int waddstr(WINDOW *win, const char *str);
15 int waddnstr(WINDOW *win, const char *str, int n);
16 int mvaddstr(int y, int x, const char *str);
17 int mvaddnstr(int y, int x, const char *str, int n);
18 int mvwaddstr(WINDOW *win, int y, int x, const char *str);
19 int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);
20
21 int addwstr(const wchar_t *wstr);
22 int addnwstr(const wchar_t *wstr, int n);
23 int waddwstr(WINDOW *win, const wchar_t *wstr);
24 int waddnwstr(WINDOW *win, const wchar_t *wstr, int n);
25 int mvaddwstr(int y, int x, const wchar_t *wstr);
26 int mvaddnwstr(int y, int x, const wchar_t *wstr, int n);
27 int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr);
28 int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);
29
30### Description
31
32 These routines write all the characters of the null-terminated string
33 str or wide-character string wstr to the given window. The
34 functionality is similar to calling waddch() once for each character
35 in the string; except that, when PDCurses is built with wide-
36 character support enabled, the narrow-character functions treat the
37 string as a multibyte string in the current locale, and convert it.
38 The routines with n as the last argument write at most n characters;
39 if n is negative, then the entire string will be added.
40
41### Return Value
42
43 All functions return OK or ERR.
44
45### Portability
46
47 Function | X/Open | ncurses | NetBSD
48 :---------------------|:------:|:-------:|:------:
49 addstr | Y | Y | Y
50 waddstr | Y | Y | Y
51 mvaddstr | Y | Y | Y
52 mvwaddstr | Y | Y | Y
53 addnstr | Y | Y | Y
54 waddnstr | Y | Y | Y
55 mvaddnstr | Y | Y | Y
56 mvwaddnstr | Y | Y | Y
57 addwstr | Y | Y | Y
58 waddwstr | Y | Y | Y
59 mvaddwstr | Y | Y | Y
60 mvwaddwstr | Y | Y | Y
61 addnwstr | Y | Y | Y
62 waddnwstr | Y | Y | Y
63 mvaddnwstr | Y | Y | Y
64 mvwaddnwstr | Y | Y | Y
65
66**man-end****************************************************************/
67
68int waddnstr(WINDOW *win, const char *str, int n)
69{
70 int i = 0;
71
72 PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n));
73
74 if (!win || !str)
75 return ERR;
76
77 while (str[i] && (i < n || n < 0))
78 {
79#ifdef PDC_WIDE
80 wchar_t wch;
81 int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6);
82
83 if (retval <= 0)
84 return OK;
85
86 i += retval;
87#else
88 chtype wch = (unsigned char)(str[i++]);
89#endif
90 if (waddch(win, wch) == ERR)
91 return ERR;
92 }
93
94 return OK;
95}
96
97int addstr(const char *str)
98{
99 PDC_LOG(("addstr() - called: string=\"%s\"\n", str));
100
101 return waddnstr(stdscr, str, -1);
102}
103
104int addnstr(const char *str, int n)
105{
106 PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n));
107
108 return waddnstr(stdscr, str, n);
109}
110
111int waddstr(WINDOW *win, const char *str)
112{
113 PDC_LOG(("waddstr() - called: string=\"%s\"\n", str));
114
115 return waddnstr(win, str, -1);
116}
117
118int mvaddstr(int y, int x, const char *str)
119{
120 PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str));
121
122 if (move(y, x) == ERR)
123 return ERR;
124
125 return waddnstr(stdscr, str, -1);
126}
127
128int mvaddnstr(int y, int x, const char *str, int n)
129{
130 PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
131 y, x, str, n));
132
133 if (move(y, x) == ERR)
134 return ERR;
135
136 return waddnstr(stdscr, str, n);
137}
138
139int mvwaddstr(WINDOW *win, int y, int x, const char *str)
140{
141 PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str));
142
143 if (wmove(win, y, x) == ERR)
144 return ERR;
145
146 return waddnstr(win, str, -1);
147}
148
149int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n)
150{
151 PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
152 y, x, str, n));
153
154 if (wmove(win, y, x) == ERR)
155 return ERR;
156
157 return waddnstr(win, str, n);
158}
159
160#ifdef PDC_WIDE
161int waddnwstr(WINDOW *win, const wchar_t *wstr, int n)
162{
163 int i = 0;
164
165 PDC_LOG(("waddnwstr() - called\n"));
166
167 if (!win || !wstr)
168 return ERR;
169
170 while (wstr[i] && (i < n || n < 0))
171 {
172 chtype wch = wstr[i++];
173
174 if (waddch(win, wch) == ERR)
175 return ERR;
176 }
177
178 return OK;
179}
180
181int addwstr(const wchar_t *wstr)
182{
183 PDC_LOG(("addwstr() - called\n"));
184
185 return waddnwstr(stdscr, wstr, -1);
186}
187
188int addnwstr(const wchar_t *wstr, int n)
189{
190 PDC_LOG(("addnwstr() - called\n"));
191
192 return waddnwstr(stdscr, wstr, n);
193}
194
195int waddwstr(WINDOW *win, const wchar_t *wstr)
196{
197 PDC_LOG(("waddwstr() - called\n"));
198
199 return waddnwstr(win, wstr, -1);
200}
201
202int mvaddwstr(int y, int x, const wchar_t *wstr)
203{
204 PDC_LOG(("mvaddstr() - called\n"));
205
206 if (move(y, x) == ERR)
207 return ERR;
208
209 return waddnwstr(stdscr, wstr, -1);
210}
211
212int mvaddnwstr(int y, int x, const wchar_t *wstr, int n)
213{
214 PDC_LOG(("mvaddnstr() - called\n"));
215
216 if (move(y, x) == ERR)
217 return ERR;
218
219 return waddnwstr(stdscr, wstr, n);
220}
221
222int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr)
223{
224 PDC_LOG(("mvwaddstr() - called\n"));
225
226 if (wmove(win, y, x) == ERR)
227 return ERR;
228
229 return waddnwstr(win, wstr, -1);
230}
231
232int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n)
233{
234 PDC_LOG(("mvwaddnstr() - called\n"));
235
236 if (wmove(win, y, x) == ERR)
237 return ERR;
238
239 return waddnwstr(win, wstr, n);
240}
241#endif
diff --git a/scripts/kconfig/libcurses/attr.c b/scripts/kconfig/libcurses/attr.c
new file mode 100644
index 000000000..d7bc36c73
--- /dev/null
+++ b/scripts/kconfig/libcurses/attr.c
@@ -0,0 +1,411 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7attr
8----
9
10### Synopsis
11
12 int attroff(chtype attrs);
13 int wattroff(WINDOW *win, chtype attrs);
14 int attron(chtype attrs);
15 int wattron(WINDOW *win, chtype attrs);
16 int attrset(chtype attrs);
17 int wattrset(WINDOW *win, chtype attrs);
18 int standend(void);
19 int wstandend(WINDOW *win);
20 int standout(void);
21 int wstandout(WINDOW *win);
22
23 int color_set(short color_pair, void *opts);
24 int wcolor_set(WINDOW *win, short color_pair, void *opts);
25
26 int attr_get(attr_t *attrs, short *color_pair, void *opts);
27 int attr_off(attr_t attrs, void *opts);
28 int attr_on(attr_t attrs, void *opts);
29 int attr_set(attr_t attrs, short color_pair, void *opts);
30 int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair,
31 void *opts);
32 int wattr_off(WINDOW *win, attr_t attrs, void *opts);
33 int wattr_on(WINDOW *win, attr_t attrs, void *opts);
34 int wattr_set(WINDOW *win, attr_t attrs, short color_pair,
35 void *opts);
36
37 int chgat(int n, attr_t attr, short color, const void *opts);
38 int mvchgat(int y, int x, int n, attr_t attr, short color,
39 const void *opts);
40 int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr,
41 short color, const void *opts);
42 int wchgat(WINDOW *win, int n, attr_t attr, short color,
43 const void *opts);
44
45 chtype getattrs(WINDOW *win);
46
47 int underend(void);
48 int wunderend(WINDOW *win);
49 int underscore(void);
50 int wunderscore(WINDOW *win);
51
52### Description
53
54 These functions manipulate the current attributes and/or colors of
55 the named window. These attributes can be any combination of
56 A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE. These
57 constants are defined in "curses.h" and can be combined with the
58 bitwise-OR operator (|).
59
60 The current attributes of a window are applied to all chtypes that
61 are written into the window with waddch(). Attributes are a property
62 of the chtype, and move with the character through any scrolling or
63 insert/delete operations.
64
65 wattrset() sets the current attributes of the given window to attrs.
66 attrset() is the stdscr version.
67
68 wattroff() turns off the named attributes without affecting any other
69 attributes; wattron() turns them on.
70
71 wcolor_set() sets the window color to the value of color_pair. opts
72 is unused.
73
74 standout() is the same as attron(A_STANDOUT). standend() is the same
75 as attrset(A_NORMAL); that is, it turns off all attributes.
76
77 The attr_* and wattr_* functions are intended for use with the WA_*
78 attributes. In PDCurses, these are the same as A_*, and there is no
79 difference in bevahior from the chtype-based functions. In all cases,
80 opts is unused.
81
82 wattr_get() retrieves the attributes and color pair for the specified
83 window.
84
85 wchgat() sets the color pair and attributes for the next n cells on
86 the current line of a given window, without changing the existing
87 text, or alterting the window's attributes. An n of -1 extends the
88 change to the edge of the window. The changes take effect
89 immediately. opts is unused.
90
91 wunderscore() turns on the A_UNDERLINE attribute; wunderend() turns
92 it off. underscore() and underend() are the stdscr versions.
93
94### Return Value
95
96 All functions return OK on success and ERR on error.
97
98### Portability
99
100 Function | X/Open | ncurses | NetBSD
101 :---------------------|:------:|:-------:|:------:
102 attroff | Y | Y | Y
103 wattroff | Y | Y | Y
104 attron | Y | Y | Y
105 wattron | Y | Y | Y
106 attrset | Y | Y | Y
107 wattrset | Y | Y | Y
108 standend | Y | Y | Y
109 wstandend | Y | Y | Y
110 standout | Y | Y | Y
111 wstandout | Y | Y | Y
112 color_set | Y | Y | Y
113 wcolor_set | Y | Y | Y
114 attr_get | Y | Y | Y
115 wattr_get | Y | Y | Y
116 attr_on | Y | Y | Y
117 wattr_on | Y | Y | Y
118 attr_off | Y | Y | Y
119 wattr_off | Y | Y | Y
120 attr_set | Y | Y | Y
121 wattr_set | Y | Y | Y
122 chgat | Y | Y | Y
123 wchgat | Y | Y | Y
124 mvchgat | Y | Y | Y
125 mvwchgat | Y | Y | Y
126 getattrs | - | Y | Y
127 underend | - | - | Y
128 wunderend | - | - | Y
129 underscore | - | - | Y
130 wunderscore | - | - | Y
131
132**man-end****************************************************************/
133
134int wattroff(WINDOW *win, chtype attrs)
135{
136 PDC_LOG(("wattroff() - called\n"));
137
138 if (!win)
139 return ERR;
140
141 win->_attrs &= (~attrs & A_ATTRIBUTES);
142
143 return OK;
144}
145
146int attroff(chtype attrs)
147{
148 PDC_LOG(("attroff() - called\n"));
149
150 return wattroff(stdscr, attrs);
151}
152
153int wattron(WINDOW *win, chtype attrs)
154{
155 chtype newcolr, oldcolr, newattr, oldattr;
156
157 PDC_LOG(("wattron() - called\n"));
158
159 if (!win)
160 return ERR;
161
162 if ((win->_attrs & A_COLOR) && (attrs & A_COLOR))
163 {
164 oldcolr = win->_attrs & A_COLOR;
165 oldattr = win->_attrs ^ oldcolr;
166 newcolr = attrs & A_COLOR;
167 newattr = (attrs & A_ATTRIBUTES) ^ newcolr;
168 newattr |= oldattr;
169 win->_attrs = newattr | newcolr;
170 }
171 else
172 win->_attrs |= (attrs & A_ATTRIBUTES);
173
174 return OK;
175}
176
177int attron(chtype attrs)
178{
179 PDC_LOG(("attron() - called\n"));
180
181 return wattron(stdscr, attrs);
182}
183
184int wattrset(WINDOW *win, chtype attrs)
185{
186 PDC_LOG(("wattrset() - called\n"));
187
188 if (!win)
189 return ERR;
190
191 win->_attrs = attrs & A_ATTRIBUTES;
192
193 return OK;
194}
195
196int attrset(chtype attrs)
197{
198 PDC_LOG(("attrset() - called\n"));
199
200 return wattrset(stdscr, attrs);
201}
202
203int standend(void)
204{
205 PDC_LOG(("standend() - called\n"));
206
207 return wattrset(stdscr, A_NORMAL);
208}
209
210int standout(void)
211{
212 PDC_LOG(("standout() - called\n"));
213
214 return wattrset(stdscr, A_STANDOUT);
215}
216
217int wstandend(WINDOW *win)
218{
219 PDC_LOG(("wstandend() - called\n"));
220
221 return wattrset(win, A_NORMAL);
222}
223
224int wstandout(WINDOW *win)
225{
226 PDC_LOG(("wstandout() - called\n"));
227
228 return wattrset(win, A_STANDOUT);
229}
230
231chtype getattrs(WINDOW *win)
232{
233 return win ? win->_attrs : 0;
234}
235
236int wcolor_set(WINDOW *win, short color_pair, void *opts)
237{
238 PDC_LOG(("wcolor_set() - called\n"));
239
240 if (!win)
241 return ERR;
242
243 win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair);
244
245 return OK;
246}
247
248int color_set(short color_pair, void *opts)
249{
250 PDC_LOG(("color_set() - called\n"));
251
252 return wcolor_set(stdscr, color_pair, opts);
253}
254
255int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts)
256{
257 PDC_LOG(("wattr_get() - called\n"));
258
259 if (!win)
260 return ERR;
261
262 if (attrs)
263 *attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR);
264
265 if (color_pair)
266 *color_pair = PAIR_NUMBER(win->_attrs);
267
268 return OK;
269}
270
271int attr_get(attr_t *attrs, short *color_pair, void *opts)
272{
273 PDC_LOG(("attr_get() - called\n"));
274
275 return wattr_get(stdscr, attrs, color_pair, opts);
276}
277
278int wattr_off(WINDOW *win, attr_t attrs, void *opts)
279{
280 PDC_LOG(("wattr_off() - called\n"));
281
282 return wattroff(win, attrs);
283}
284
285int attr_off(attr_t attrs, void *opts)
286{
287 PDC_LOG(("attr_off() - called\n"));
288
289 return wattroff(stdscr, attrs);
290}
291
292int wattr_on(WINDOW *win, attr_t attrs, void *opts)
293{
294 PDC_LOG(("wattr_off() - called\n"));
295
296 return wattron(win, attrs);
297}
298
299int attr_on(attr_t attrs, void *opts)
300{
301 PDC_LOG(("attr_on() - called\n"));
302
303 return wattron(stdscr, attrs);
304}
305
306int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts)
307{
308 PDC_LOG(("wattr_set() - called\n"));
309
310 if (!win)
311 return ERR;
312
313 win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair);
314
315 return OK;
316}
317
318int attr_set(attr_t attrs, short color_pair, void *opts)
319{
320 PDC_LOG(("attr_get() - called\n"));
321
322 return wattr_set(stdscr, attrs, color_pair, opts);
323}
324
325int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
326{
327 chtype *dest, newattr;
328 int startpos, endpos;
329
330 PDC_LOG(("wchgat() - called\n"));
331
332 if (!win)
333 return ERR;
334
335 newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color);
336
337 startpos = win->_curx;
338 endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1;
339 dest = win->_y[win->_cury];
340
341 for (n = startpos; n <= endpos; n++)
342 dest[n] = (dest[n] & A_CHARTEXT) | newattr;
343
344 n = win->_cury;
345
346 if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
347 win->_firstch[n] = startpos;
348
349 if (endpos > win->_lastch[n])
350 win->_lastch[n] = endpos;
351
352 PDC_sync(win);
353
354 return OK;
355}
356
357int chgat(int n, attr_t attr, short color, const void *opts)
358{
359 PDC_LOG(("chgat() - called\n"));
360
361 return wchgat(stdscr, n, attr, color, opts);
362}
363
364int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts)
365{
366 PDC_LOG(("mvchgat() - called\n"));
367
368 if (move(y, x) == ERR)
369 return ERR;
370
371 return wchgat(stdscr, n, attr, color, opts);
372}
373
374int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color,
375 const void *opts)
376{
377 PDC_LOG(("mvwchgat() - called\n"));
378
379 if (wmove(win, y, x) == ERR)
380 return ERR;
381
382 return wchgat(win, n, attr, color, opts);
383}
384
385int underend(void)
386{
387 PDC_LOG(("underend() - called\n"));
388
389 return wattroff(stdscr, A_UNDERLINE);
390}
391
392int wunderend(WINDOW *win)
393{
394 PDC_LOG(("wunderend() - called\n"));
395
396 return wattroff(win, A_UNDERLINE);
397}
398
399int underscore(void)
400{
401 PDC_LOG(("underscore() - called\n"));
402
403 return wattron(stdscr, A_UNDERLINE);
404}
405
406int wunderscore(WINDOW *win)
407{
408 PDC_LOG(("wunderscore() - called\n"));
409
410 return wattron(win, A_UNDERLINE);
411}
diff --git a/scripts/kconfig/libcurses/beep.c b/scripts/kconfig/libcurses/beep.c
new file mode 100644
index 000000000..b679eed3c
--- /dev/null
+++ b/scripts/kconfig/libcurses/beep.c
@@ -0,0 +1,76 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7beep
8----
9
10### Synopsis
11
12 int beep(void);
13 int flash(void);
14
15### Description
16
17 beep() sounds the audible bell on the terminal, if possible; if not,
18 it calls flash().
19
20 flash() "flashes" the screen, by inverting the foreground and
21 background of every cell, pausing, and then restoring the original
22 attributes.
23
24### Return Value
25
26 These functions return ERR if called before initscr(), otherwise OK.
27
28### Portability
29
30 Function | X/Open | ncurses | NetBSD
31 :---------------------|:------:|:-------:|:------:
32 beep | Y | Y | Y
33 flash | Y | Y | Y
34
35**man-end****************************************************************/
36
37int beep(void)
38{
39 PDC_LOG(("beep() - called\n"));
40
41 if (!SP)
42 return ERR;
43
44 if (SP->audible)
45 PDC_beep();
46 else
47 flash();
48
49 return OK;
50}
51
52int flash(void)
53{
54 int z, y, x;
55
56 PDC_LOG(("flash() - called\n"));
57
58 if (!curscr)
59 return ERR;
60
61 /* Reverse each cell; wait; restore the screen */
62
63 for (z = 0; z < 2; z++)
64 {
65 for (y = 0; y < LINES; y++)
66 for (x = 0; x < COLS; x++)
67 curscr->_y[y][x] ^= A_REVERSE;
68
69 wrefresh(curscr);
70
71 if (!z)
72 napms(50);
73 }
74
75 return OK;
76}
diff --git a/scripts/kconfig/libcurses/bkgd.c b/scripts/kconfig/libcurses/bkgd.c
new file mode 100644
index 000000000..c92df28be
--- /dev/null
+++ b/scripts/kconfig/libcurses/bkgd.c
@@ -0,0 +1,228 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7bkgd
8----
9
10### Synopsis
11
12 int bkgd(chtype ch);
13 void bkgdset(chtype ch);
14 chtype getbkgd(WINDOW *win);
15 int wbkgd(WINDOW *win, chtype ch);
16 void wbkgdset(WINDOW *win, chtype ch);
17
18 int bkgrnd(const cchar_t *wch);
19 void bkgrndset(const cchar_t *wch);
20 int getbkgrnd(cchar_t *wch);
21 int wbkgrnd(WINDOW *win, const cchar_t *wch);
22 void wbkgrndset(WINDOW *win, const cchar_t *wch);
23 int wgetbkgrnd(WINDOW *win, cchar_t *wch);
24
25### Description
26
27 bkgdset() and wbkgdset() manipulate the background of a window. The
28 background is a chtype consisting of any combination of attributes
29 and a character; it is combined with each chtype added or inserted to
30 the window by waddch() or winsch(). Only the attribute part is used
31 to set the background of non-blank characters, while both character
32 and attributes are used for blank positions.
33
34 bkgd() and wbkgd() not only change the background, but apply it
35 immediately to every cell in the window.
36
37 wbkgrnd(), wbkgrndset() and wgetbkgrnd() are the "wide-character"
38 versions of these functions, taking a pointer to a cchar_t instead of
39 a chtype. However, in PDCurses, cchar_t and chtype are the same.
40
41 The attributes that are defined with the attrset()/attron() set of
42 functions take precedence over the background attributes if there is
43 a conflict (e.g., different color pairs).
44
45### Return Value
46
47 bkgd() and wbkgd() return OK, unless the window is NULL, in which
48 case they return ERR.
49
50### Portability
51
52 Function | X/Open | ncurses | NetBSD
53 :---------------------|:------:|:-------:|:------:
54 bkgd | Y | Y | Y
55 bkgdset | Y | Y | Y
56 getbkgd | Y | Y | Y
57 wbkgd | Y | Y | Y
58 wbkgdset | Y | Y | Y
59 bkgrnd | Y | Y | Y
60 bkgrndset | Y | Y | Y
61 getbkgrnd | Y | Y | Y
62 wbkgrnd | Y | Y | Y
63 wbkgrndset | Y | Y | Y
64 wgetbkgrnd | Y | Y | Y
65
66**man-end****************************************************************/
67
68int wbkgd(WINDOW *win, chtype ch)
69{
70 int x, y;
71 chtype oldcolr, oldch, newcolr, newch, colr, attr;
72 chtype oldattr = 0, newattr = 0;
73 chtype *winptr;
74
75 PDC_LOG(("wbkgd() - called\n"));
76
77 if (!win)
78 return ERR;
79
80 if (win->_bkgd == ch)
81 return OK;
82
83 oldcolr = win->_bkgd & A_COLOR;
84 if (oldcolr)
85 oldattr = (win->_bkgd & A_ATTRIBUTES) ^ oldcolr;
86
87 oldch = win->_bkgd & A_CHARTEXT;
88
89 wbkgdset(win, ch);
90
91 newcolr = win->_bkgd & A_COLOR;
92 if (newcolr)
93 newattr = (win->_bkgd & A_ATTRIBUTES) ^ newcolr;
94
95 newch = win->_bkgd & A_CHARTEXT;
96
97 /* what follows is what seems to occur in the System V
98 implementation of this routine */
99
100 for (y = 0; y < win->_maxy; y++)
101 {
102 for (x = 0; x < win->_maxx; x++)
103 {
104 winptr = win->_y[y] + x;
105
106 ch = *winptr;
107
108 /* determine the colors and attributes of the character read
109 from the window */
110
111 colr = ch & A_COLOR;
112 attr = ch & (A_ATTRIBUTES ^ A_COLOR);
113
114 /* if the color is the same as the old background color,
115 then make it the new background color, otherwise leave it */
116
117 if (colr == oldcolr)
118 colr = newcolr;
119
120 /* remove any attributes (non color) from the character that
121 were part of the old background, then combine the
122 remaining ones with the new background */
123
124 attr ^= oldattr;
125 attr |= newattr;
126
127 /* change character if it is there because it was the old
128 background character */
129
130 ch &= A_CHARTEXT;
131 if (ch == oldch)
132 ch = newch;
133
134 ch |= (attr | colr);
135
136 *winptr = ch;
137
138 }
139 }
140
141 touchwin(win);
142 PDC_sync(win);
143 return OK;
144}
145
146int bkgd(chtype ch)
147{
148 PDC_LOG(("bkgd() - called\n"));
149
150 return wbkgd(stdscr, ch);
151}
152
153void wbkgdset(WINDOW *win, chtype ch)
154{
155 PDC_LOG(("wbkgdset() - called\n"));
156
157 if (win)
158 {
159 if (!(ch & A_CHARTEXT))
160 ch |= ' ';
161
162 win->_bkgd = ch;
163 }
164}
165
166void bkgdset(chtype ch)
167{
168 PDC_LOG(("bkgdset() - called\n"));
169
170 wbkgdset(stdscr, ch);
171}
172
173chtype getbkgd(WINDOW *win)
174{
175 PDC_LOG(("getbkgd() - called\n"));
176
177 return win ? win->_bkgd : (chtype)ERR;
178}
179
180#ifdef PDC_WIDE
181int wbkgrnd(WINDOW *win, const cchar_t *wch)
182{
183 PDC_LOG(("wbkgrnd() - called\n"));
184
185 return wch ? wbkgd(win, *wch) : ERR;
186}
187
188int bkgrnd(const cchar_t *wch)
189{
190 PDC_LOG(("bkgrnd() - called\n"));
191
192 return wbkgrnd(stdscr, wch);
193}
194
195void wbkgrndset(WINDOW *win, const cchar_t *wch)
196{
197 PDC_LOG(("wbkgdset() - called\n"));
198
199 if (wch)
200 wbkgdset(win, *wch);
201}
202
203void bkgrndset(const cchar_t *wch)
204{
205 PDC_LOG(("bkgrndset() - called\n"));
206
207 wbkgrndset(stdscr, wch);
208}
209
210int wgetbkgrnd(WINDOW *win, cchar_t *wch)
211{
212 PDC_LOG(("wgetbkgrnd() - called\n"));
213
214 if (!win || !wch)
215 return ERR;
216
217 *wch = win->_bkgd;
218
219 return OK;
220}
221
222int getbkgrnd(cchar_t *wch)
223{
224 PDC_LOG(("getbkgrnd() - called\n"));
225
226 return wgetbkgrnd(stdscr, wch);
227}
228#endif
diff --git a/scripts/kconfig/libcurses/border.c b/scripts/kconfig/libcurses/border.c
new file mode 100644
index 000000000..409f2351a
--- /dev/null
+++ b/scripts/kconfig/libcurses/border.c
@@ -0,0 +1,418 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7border
8------
9
10### Synopsis
11
12 int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
13 chtype tr, chtype bl, chtype br);
14 int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,
15 chtype bs, chtype tl, chtype tr, chtype bl, chtype br);
16 int box(WINDOW *win, chtype verch, chtype horch);
17 int hline(chtype ch, int n);
18 int vline(chtype ch, int n);
19 int whline(WINDOW *win, chtype ch, int n);
20 int wvline(WINDOW *win, chtype ch, int n);
21 int mvhline(int y, int x, chtype ch, int n);
22 int mvvline(int y, int x, chtype ch, int n);
23 int mvwhline(WINDOW *win, int y, int x, chtype ch, int n);
24 int mvwvline(WINDOW *win, int y, int x, chtype ch, int n);
25
26 int border_set(const cchar_t *ls, const cchar_t *rs,
27 const cchar_t *ts, const cchar_t *bs,
28 const cchar_t *tl, const cchar_t *tr,
29 const cchar_t *bl, const cchar_t *br);
30 int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
31 const cchar_t *ts, const cchar_t *bs,
32 const cchar_t *tl, const cchar_t *tr,
33 const cchar_t *bl, const cchar_t *br);
34 int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch);
35 int hline_set(const cchar_t *wch, int n);
36 int vline_set(const cchar_t *wch, int n);
37 int whline_set(WINDOW *win, const cchar_t *wch, int n);
38 int wvline_set(WINDOW *win, const cchar_t *wch, int n);
39 int mvhline_set(int y, int x, const cchar_t *wch, int n);
40 int mvvline_set(int y, int x, const cchar_t *wch, int n);
41 int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
42 int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
43
44### Description
45
46 border(), wborder(), and box() draw a border around the edge of the
47 window. If any argument is zero, an appropriate default is used:
48
49 Name | Element | Default
50 :----|:------------------------------|:------------
51 ls | left side of border | ACS_VLINE
52 rs | right side of border | ACS_VLINE
53 ts | top side of border | ACS_HLINE
54 bs | bottom side of border | ACS_HLINE
55 tl | top left corner of border | ACS_ULCORNER
56 tr | top right corner of border | ACS_URCORNER
57 bl | bottom left corner of border | ACS_LLCORNER
58 br | bottom right corner of border | ACS_LRCORNER
59
60 hline() and whline() draw a horizontal line, using ch, starting from
61 the current cursor position. The cursor position does not change. The
62 line is at most n characters long, or as many as will fit in the
63 window.
64
65 vline() and wvline() draw a vertical line, using ch, starting from
66 the current cursor position. The cursor position does not change. The
67 line is at most n characters long, or as many as will fit in the
68 window.
69
70 The *_set functions are the "wide-character" versions, taking
71 pointers to cchar_t instead of chtype. Note that in PDCurses, chtype
72 and cchar_t are the same.
73
74### Return Value
75
76 These functions return OK on success and ERR on error.
77
78### Portability
79
80 Function | X/Open | ncurses | NetBSD
81 :---------------------|:------:|:-------:|:------:
82 border | Y | Y | Y
83 wborder | Y | Y | Y
84 box | Y | Y | Y
85 hline | Y | Y | Y
86 vline | Y | Y | Y
87 whline | Y | Y | Y
88 wvline | Y | Y | Y
89 mvhline | Y | Y | Y
90 mvvline | Y | Y | Y
91 mvwhline | Y | Y | Y
92 mvwvline | Y | Y | Y
93 border_set | Y | Y | Y
94 wborder_set | Y | Y | Y
95 box_set | Y | Y | Y
96 hline_set | Y | Y | Y
97 vline_set | Y | Y | Y
98 whline_set | Y | Y | Y
99 wvline_set | Y | Y | Y
100 mvhline_set | Y | Y | Y
101 mvvline_set | Y | Y | Y
102 mvwhline_set | Y | Y | Y
103 mvwvline_set | Y | Y | Y
104
105**man-end****************************************************************/
106
107/* _attr_passthru() -- Takes a single chtype 'ch' and checks if the
108 current attribute of window 'win', as set by wattrset(), and/or the
109 current background of win, as set by wbkgd(), should by combined with
110 it. Attributes set explicitly in ch take precedence. */
111
112static chtype _attr_passthru(WINDOW *win, chtype ch)
113{
114 chtype attr;
115
116 /* If the incoming character doesn't have its own attribute, then
117 use the current attributes for the window. If the incoming
118 character has attributes, but not a color component, OR the
119 attributes to the current attributes for the window. If the
120 incoming character has a color component, use only the attributes
121 from the incoming character. */
122
123 attr = ch & A_ATTRIBUTES;
124 if (!(attr & A_COLOR))
125 attr |= win->_attrs;
126
127 /* wrs (4/10/93) -- Apply the same sort of logic for the window
128 background, in that it only takes precedence if other color
129 attributes are not there. */
130
131 if (!(attr & A_COLOR))
132 attr |= win->_bkgd & A_ATTRIBUTES;
133 else
134 attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
135
136 ch = (ch & A_CHARTEXT) | attr;
137
138 return ch;
139}
140
141int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
142 chtype tl, chtype tr, chtype bl, chtype br)
143{
144 int i, ymax, xmax;
145
146 PDC_LOG(("wborder() - called\n"));
147
148 if (!win)
149 return ERR;
150
151 ymax = win->_maxy - 1;
152 xmax = win->_maxx - 1;
153
154 ls = _attr_passthru(win, ls ? ls : ACS_VLINE);
155 rs = _attr_passthru(win, rs ? rs : ACS_VLINE);
156 ts = _attr_passthru(win, ts ? ts : ACS_HLINE);
157 bs = _attr_passthru(win, bs ? bs : ACS_HLINE);
158 tl = _attr_passthru(win, tl ? tl : ACS_ULCORNER);
159 tr = _attr_passthru(win, tr ? tr : ACS_URCORNER);
160 bl = _attr_passthru(win, bl ? bl : ACS_LLCORNER);
161 br = _attr_passthru(win, br ? br : ACS_LRCORNER);
162
163 for (i = 1; i < xmax; i++)
164 {
165 win->_y[0][i] = ts;
166 win->_y[ymax][i] = bs;
167 }
168
169 for (i = 1; i < ymax; i++)
170 {
171 win->_y[i][0] = ls;
172 win->_y[i][xmax] = rs;
173 }
174
175 win->_y[0][0] = tl;
176 win->_y[0][xmax] = tr;
177 win->_y[ymax][0] = bl;
178 win->_y[ymax][xmax] = br;
179
180 for (i = 0; i <= ymax; i++)
181 {
182 win->_firstch[i] = 0;
183 win->_lastch[i] = xmax;
184 }
185
186 PDC_sync(win);
187
188 return OK;
189}
190
191int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
192 chtype tr, chtype bl, chtype br)
193{
194 PDC_LOG(("border() - called\n"));
195
196 return wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
197}
198
199int box(WINDOW *win, chtype verch, chtype horch)
200{
201 PDC_LOG(("box() - called\n"));
202
203 return wborder(win, verch, verch, horch, horch, 0, 0, 0, 0);
204}
205
206int whline(WINDOW *win, chtype ch, int n)
207{
208 chtype *dest;
209 int startpos, endpos;
210
211 PDC_LOG(("whline() - called\n"));
212
213 if (!win || n < 1)
214 return ERR;
215
216 startpos = win->_curx;
217 endpos = min(startpos + n, win->_maxx) - 1;
218 dest = win->_y[win->_cury];
219 ch = _attr_passthru(win, ch ? ch : ACS_HLINE);
220
221 for (n = startpos; n <= endpos; n++)
222 dest[n] = ch;
223
224 n = win->_cury;
225
226 if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
227 win->_firstch[n] = startpos;
228
229 if (endpos > win->_lastch[n])
230 win->_lastch[n] = endpos;
231
232 PDC_sync(win);
233
234 return OK;
235}
236
237int hline(chtype ch, int n)
238{
239 PDC_LOG(("hline() - called\n"));
240
241 return whline(stdscr, ch, n);
242}
243
244int mvhline(int y, int x, chtype ch, int n)
245{
246 PDC_LOG(("mvhline() - called\n"));
247
248 if (move(y, x) == ERR)
249 return ERR;
250
251 return whline(stdscr, ch, n);
252}
253
254int mvwhline(WINDOW *win, int y, int x, chtype ch, int n)
255{
256 PDC_LOG(("mvwhline() - called\n"));
257
258 if (wmove(win, y, x) == ERR)
259 return ERR;
260
261 return whline(win, ch, n);
262}
263
264int wvline(WINDOW *win, chtype ch, int n)
265{
266 int endpos, x;
267
268 PDC_LOG(("wvline() - called\n"));
269
270 if (!win || n < 1)
271 return ERR;
272
273 endpos = min(win->_cury + n, win->_maxy);
274 x = win->_curx;
275
276 ch = _attr_passthru(win, ch ? ch : ACS_VLINE);
277
278 for (n = win->_cury; n < endpos; n++)
279 {
280 win->_y[n][x] = ch;
281
282 if (x < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
283 win->_firstch[n] = x;
284
285 if (x > win->_lastch[n])
286 win->_lastch[n] = x;
287 }
288
289 PDC_sync(win);
290
291 return OK;
292}
293
294int vline(chtype ch, int n)
295{
296 PDC_LOG(("vline() - called\n"));
297
298 return wvline(stdscr, ch, n);
299}
300
301int mvvline(int y, int x, chtype ch, int n)
302{
303 PDC_LOG(("mvvline() - called\n"));
304
305 if (move(y, x) == ERR)
306 return ERR;
307
308 return wvline(stdscr, ch, n);
309}
310
311int mvwvline(WINDOW *win, int y, int x, chtype ch, int n)
312{
313 PDC_LOG(("mvwvline() - called\n"));
314
315 if (wmove(win, y, x) == ERR)
316 return ERR;
317
318 return wvline(win, ch, n);
319}
320
321#ifdef PDC_WIDE
322int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
323 const cchar_t *ts, const cchar_t *bs, const cchar_t *tl,
324 const cchar_t *tr, const cchar_t *bl, const cchar_t *br)
325{
326 PDC_LOG(("wborder_set() - called\n"));
327
328 return wborder(win, ls ? *ls : 0, rs ? *rs : 0, ts ? *ts : 0,
329 bs ? *bs : 0, tl ? *tl : 0, tr ? *tr : 0,
330 bl ? *bl : 0, br ? *br : 0);
331}
332
333int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts,
334 const cchar_t *bs, const cchar_t *tl, const cchar_t *tr,
335 const cchar_t *bl, const cchar_t *br)
336{
337 PDC_LOG(("border_set() - called\n"));
338
339 return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
340}
341
342int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch)
343{
344 PDC_LOG(("box_set() - called\n"));
345
346 return wborder_set(win, verch, verch, horch, horch,
347 (const cchar_t *)NULL, (const cchar_t *)NULL,
348 (const cchar_t *)NULL, (const cchar_t *)NULL);
349}
350
351int whline_set(WINDOW *win, const cchar_t *wch, int n)
352{
353 PDC_LOG(("whline_set() - called\n"));
354
355 return wch ? whline(win, *wch, n) : ERR;
356}
357
358int hline_set(const cchar_t *wch, int n)
359{
360 PDC_LOG(("hline_set() - called\n"));
361
362 return whline_set(stdscr, wch, n);
363}
364
365int mvhline_set(int y, int x, const cchar_t *wch, int n)
366{
367 PDC_LOG(("mvhline_set() - called\n"));
368
369 if (move(y, x) == ERR)
370 return ERR;
371
372 return whline_set(stdscr, wch, n);
373}
374
375int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
376{
377 PDC_LOG(("mvwhline_set() - called\n"));
378
379 if (wmove(win, y, x) == ERR)
380 return ERR;
381
382 return whline_set(win, wch, n);
383}
384
385int wvline_set(WINDOW *win, const cchar_t *wch, int n)
386{
387 PDC_LOG(("wvline_set() - called\n"));
388
389 return wch ? wvline(win, *wch, n) : ERR;
390}
391
392int vline_set(const cchar_t *wch, int n)
393{
394 PDC_LOG(("vline_set() - called\n"));
395
396 return wvline_set(stdscr, wch, n);
397}
398
399int mvvline_set(int y, int x, const cchar_t *wch, int n)
400{
401 PDC_LOG(("mvvline_set() - called\n"));
402
403 if (move(y, x) == ERR)
404 return ERR;
405
406 return wvline_set(stdscr, wch, n);
407}
408
409int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
410{
411 PDC_LOG(("mvwvline_set() - called\n"));
412
413 if (wmove(win, y, x) == ERR)
414 return ERR;
415
416 return wvline_set(win, wch, n);
417}
418#endif
diff --git a/scripts/kconfig/libcurses/clear.c b/scripts/kconfig/libcurses/clear.c
new file mode 100644
index 000000000..e10b321c3
--- /dev/null
+++ b/scripts/kconfig/libcurses/clear.c
@@ -0,0 +1,161 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7clear
8-----
9
10### Synopsis
11
12 int clear(void);
13 int wclear(WINDOW *win);
14 int erase(void);
15 int werase(WINDOW *win);
16 int clrtobot(void);
17 int wclrtobot(WINDOW *win);
18 int clrtoeol(void);
19 int wclrtoeol(WINDOW *win);
20
21### Description
22
23 erase() and werase() copy blanks (i.e. the background chtype) to
24 every cell of the window.
25
26 clear() and wclear() are similar to erase() and werase(), but they
27 also call clearok() to ensure that the the window is cleared on the
28 next wrefresh().
29
30 clrtobot() and wclrtobot() clear the window from the current cursor
31 position to the end of the window.
32
33 clrtoeol() and wclrtoeol() clear the window from the current cursor
34 position to the end of the current line.
35
36### Return Value
37
38 All functions return OK on success and ERR on error.
39
40### Portability
41
42 Function | X/Open | ncurses | NetBSD
43 :---------------------|:------:|:-------:|:------:
44 clear | Y | Y | Y
45 wclear | Y | Y | Y
46 erase | Y | Y | Y
47 werase | Y | Y | Y
48 clrtobot | Y | Y | Y
49 wclrtobot | Y | Y | Y
50 clrtoeol | Y | Y | Y
51 wclrtoeol | Y | Y | Y
52
53**man-end****************************************************************/
54
55int wclrtoeol(WINDOW *win)
56{
57 int x, y, minx;
58 chtype blank, *ptr;
59
60 PDC_LOG(("wclrtoeol() - called: Row: %d Col: %d\n",
61 win->_cury, win->_curx));
62
63 if (!win)
64 return ERR;
65
66 y = win->_cury;
67 x = win->_curx;
68
69 /* wrs (4/10/93) account for window background */
70
71 blank = win->_bkgd;
72
73 for (minx = x, ptr = &win->_y[y][x]; minx < win->_maxx; minx++, ptr++)
74 *ptr = blank;
75
76 if (x < win->_firstch[y] || win->_firstch[y] == _NO_CHANGE)
77 win->_firstch[y] = x;
78
79 win->_lastch[y] = win->_maxx - 1;
80
81 PDC_sync(win);
82 return OK;
83}
84
85int clrtoeol(void)
86{
87 PDC_LOG(("clrtoeol() - called\n"));
88
89 return wclrtoeol(stdscr);
90}
91
92int wclrtobot(WINDOW *win)
93{
94 int savey, savex;
95
96 PDC_LOG(("wclrtobot() - called\n"));
97
98 if (!win)
99 return ERR;
100
101 savey = win->_cury;
102 savex = win->_curx;
103
104 /* should this involve scrolling region somehow ? */
105
106 if (win->_cury + 1 < win->_maxy)
107 {
108 win->_curx = 0;
109 win->_cury++;
110 for (; win->_maxy > win->_cury; win->_cury++)
111 wclrtoeol(win);
112 win->_cury = savey;
113 win->_curx = savex;
114 }
115 wclrtoeol(win);
116
117 PDC_sync(win);
118 return OK;
119}
120
121int clrtobot(void)
122{
123 PDC_LOG(("clrtobot() - called\n"));
124
125 return wclrtobot(stdscr);
126}
127
128int werase(WINDOW *win)
129{
130 PDC_LOG(("werase() - called\n"));
131
132 if (wmove(win, 0, 0) == ERR)
133 return ERR;
134
135 return wclrtobot(win);
136}
137
138int erase(void)
139{
140 PDC_LOG(("erase() - called\n"));
141
142 return werase(stdscr);
143}
144
145int wclear(WINDOW *win)
146{
147 PDC_LOG(("wclear() - called\n"));
148
149 if (!win)
150 return ERR;
151
152 win->_clear = TRUE;
153 return werase(win);
154}
155
156int clear(void)
157{
158 PDC_LOG(("clear() - called\n"));
159
160 return wclear(stdscr);
161}
diff --git a/scripts/kconfig/libcurses/color.c b/scripts/kconfig/libcurses/color.c
new file mode 100644
index 000000000..372dad948
--- /dev/null
+++ b/scripts/kconfig/libcurses/color.c
@@ -0,0 +1,364 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7color
8-----
9
10### Synopsis
11
12 bool has_colors(void);
13 int start_color(void);
14 int init_pair(short pair, short fg, short bg);
15 int pair_content(short pair, short *fg, short *bg);
16 bool can_change_color(void);
17 int init_color(short color, short red, short green, short blue);
18 int color_content(short color, short *red, short *green, short *blue);
19
20 int alloc_pair(int fg, int bg);
21 int assume_default_colors(int f, int b);
22 int find_pair(int fg, int bg);
23 int free_pair(int pair);
24 int use_default_colors(void);
25
26 int PDC_set_line_color(short color);
27
28### Description
29
30 To use these routines, first, call start_color(). Colors are always
31 used in pairs, referred to as color-pairs. A color-pair is created by
32 init_pair(), and consists of a foreground color and a background
33 color. After initialization, COLOR_PAIR(n) can be used like any other
34 video attribute.
35
36 has_colors() reports whether the terminal supports color.
37
38 start_color() initializes eight basic colors (black, red, green,
39 yellow, blue, magenta, cyan, and white), and two global variables:
40 COLORS and COLOR_PAIRS (respectively defining the maximum number of
41 colors and color-pairs the terminal is capable of displaying).
42
43 init_pair() changes the definition of a color-pair. It takes three
44 arguments: the number of the color-pair to be redefined, and the new
45 values of the foreground and background colors. The pair number must
46 be between 0 and COLOR_PAIRS - 1, inclusive. The foreground and
47 background must be between 0 and COLORS - 1, inclusive. If the color
48 pair was previously initialized, the screen is refreshed, and all
49 occurrences of that color-pair are changed to the new definition.
50
51 pair_content() is used to determine what the colors of a given color-
52 pair consist of.
53
54 can_change_color() indicates if the terminal has the capability to
55 change the definition of its colors.
56
57 init_color() is used to redefine a color, if possible. Each of the
58 components -- red, green, and blue -- is specified in a range from 0
59 to 1000, inclusive.
60
61 color_content() reports the current definition of a color in the same
62 format as used by init_color().
63
64 assume_default_colors() and use_default_colors() emulate the ncurses
65 extensions of the same names. assume_default_colors(f, b) is
66 essentially the same as init_pair(0, f, b) (which isn't allowed); it
67 redefines the default colors. use_default_colors() allows the use of
68 -1 as a foreground or background color with init_pair(), and calls
69 assume_default_colors(-1, -1); -1 represents the foreground or
70 background color that the terminal had at startup. If the environment
71 variable PDC_ORIGINAL_COLORS is set at the time start_color() is
72 called, that's equivalent to calling use_default_colors().
73
74 alloc_pair(), find_pair() and free_pair() are also from ncurses.
75 free_pair() marks a pair as unused; find_pair() returns an existing
76 pair with the specified foreground and background colors, if one
77 exists. And alloc_pair() returns such a pair whether or not it was
78 previously set, overwriting the oldest initialized pair if there are
79 no free pairs.
80
81 PDC_set_line_color() is used to set the color, globally, for the
82 color of the lines drawn for the attributes: A_UNDERLINE, A_LEFT and
83 A_RIGHT. A value of -1 (the default) indicates that the current
84 foreground color should be used.
85
86 NOTE: COLOR_PAIR() and PAIR_NUMBER() are implemented as macros.
87
88### Return Value
89
90 Most functions return OK on success and ERR on error. has_colors()
91 and can_change_colors() return TRUE or FALSE. alloc_pair() and
92 find_pair() return a pair number, or -1 on error.
93
94### Portability
95
96 Function | X/Open | ncurses | NetBSD
97 :---------------------|:------:|:-------:|:------:
98 has_colors | Y | Y | Y
99 start_color | Y | Y | Y
100 init_pair | Y | Y | Y
101 pair_content | Y | Y | Y
102 can_change_color | Y | Y | Y
103 init_color | Y | Y | Y
104 color_content | Y | Y | Y
105 alloc_pair | - | Y | -
106 assume_default_colors | - | Y | Y
107 find_pair | - | Y | -
108 free_pair | - | Y | -
109 use_default_colors | - | Y | Y
110 PDC_set_line_color | - | - | -
111
112**man-end****************************************************************/
113
114#include <stdlib.h>
115#include <string.h>
116
117int COLORS = 0;
118int COLOR_PAIRS = PDC_COLOR_PAIRS;
119
120static bool default_colors = FALSE;
121static short first_col = 0;
122static int allocnum = 0;
123
124int start_color(void)
125{
126 PDC_LOG(("start_color() - called\n"));
127
128 if (!SP || SP->mono)
129 return ERR;
130
131 SP->color_started = TRUE;
132
133 PDC_set_blink(FALSE); /* Also sets COLORS */
134
135 if (!default_colors && SP->orig_attr && getenv("PDC_ORIGINAL_COLORS"))
136 default_colors = TRUE;
137
138 PDC_init_atrtab();
139
140 return OK;
141}
142
143static void _normalize(short *fg, short *bg)
144{
145 if (*fg == -1)
146 *fg = SP->orig_attr ? SP->orig_fore : COLOR_WHITE;
147
148 if (*bg == -1)
149 *bg = SP->orig_attr ? SP->orig_back : COLOR_BLACK;
150}
151
152static void _init_pair_core(short pair, short fg, short bg)
153{
154 PDC_PAIR *p = SP->atrtab + pair;
155
156 _normalize(&fg, &bg);
157
158 /* To allow the PDC_PRESERVE_SCREEN option to work, we only reset
159 curscr if this call to init_pair() alters a color pair created by
160 the user. */
161
162 if (p->set)
163 {
164 if (p->f != fg || p->b != bg)
165 curscr->_clear = TRUE;
166 }
167
168 p->f = fg;
169 p->b = bg;
170 p->count = allocnum++;
171 p->set = TRUE;
172}
173
174int init_pair(short pair, short fg, short bg)
175{
176 PDC_LOG(("init_pair() - called: pair %d fg %d bg %d\n", pair, fg, bg));
177
178 if (!SP || !SP->color_started || pair < 1 || pair >= COLOR_PAIRS ||
179 fg < first_col || fg >= COLORS || bg < first_col || bg >= COLORS)
180 return ERR;
181
182 _init_pair_core(pair, fg, bg);
183
184 return OK;
185}
186
187bool has_colors(void)
188{
189 PDC_LOG(("has_colors() - called\n"));
190
191 return SP ? !(SP->mono) : FALSE;
192}
193
194int init_color(short color, short red, short green, short blue)
195{
196 PDC_LOG(("init_color() - called\n"));
197
198 if (!SP || color < 0 || color >= COLORS || !PDC_can_change_color() ||
199 red < -1 || red > 1000 || green < -1 || green > 1000 ||
200 blue < -1 || blue > 1000)
201 return ERR;
202
203 SP->dirty = TRUE;
204
205 return PDC_init_color(color, red, green, blue);
206}
207
208int color_content(short color, short *red, short *green, short *blue)
209{
210 PDC_LOG(("color_content() - called\n"));
211
212 if (color < 0 || color >= COLORS || !red || !green || !blue)
213 return ERR;
214
215 if (PDC_can_change_color())
216 return PDC_color_content(color, red, green, blue);
217 else
218 {
219 /* Simulated values for platforms that don't support palette
220 changing */
221
222 short maxval = (color & 8) ? 1000 : 680;
223
224 *red = (color & COLOR_RED) ? maxval : 0;
225 *green = (color & COLOR_GREEN) ? maxval : 0;
226 *blue = (color & COLOR_BLUE) ? maxval : 0;
227
228 return OK;
229 }
230}
231
232bool can_change_color(void)
233{
234 PDC_LOG(("can_change_color() - called\n"));
235
236 return PDC_can_change_color();
237}
238
239int pair_content(short pair, short *fg, short *bg)
240{
241 PDC_LOG(("pair_content() - called\n"));
242
243 if (pair < 0 || pair >= COLOR_PAIRS || !fg || !bg)
244 return ERR;
245
246 *fg = SP->atrtab[pair].f;
247 *bg = SP->atrtab[pair].b;
248
249 return OK;
250}
251
252int assume_default_colors(int f, int b)
253{
254 PDC_LOG(("assume_default_colors() - called: f %d b %d\n", f, b));
255
256 if (f < -1 || f >= COLORS || b < -1 || b >= COLORS)
257 return ERR;
258
259 if (SP->color_started)
260 _init_pair_core(0, f, b);
261
262 return OK;
263}
264
265int use_default_colors(void)
266{
267 PDC_LOG(("use_default_colors() - called\n"));
268
269 default_colors = TRUE;
270 first_col = -1;
271
272 return assume_default_colors(-1, -1);
273}
274
275int PDC_set_line_color(short color)
276{
277 PDC_LOG(("PDC_set_line_color() - called: %d\n", color));
278
279 if (!SP || color < -1 || color >= COLORS)
280 return ERR;
281
282 SP->line_color = color;
283
284 return OK;
285}
286
287void PDC_init_atrtab(void)
288{
289 PDC_PAIR *p = SP->atrtab;
290 short i, fg, bg;
291
292 if (SP->color_started && !default_colors)
293 {
294 fg = COLOR_WHITE;
295 bg = COLOR_BLACK;
296 }
297 else
298 fg = bg = -1;
299
300 _normalize(&fg, &bg);
301
302 for (i = 0; i < PDC_COLOR_PAIRS; i++)
303 {
304 p[i].f = fg;
305 p[i].b = bg;
306 p[i].set = FALSE;
307 }
308}
309
310int free_pair(int pair)
311{
312 if (pair < 1 || pair >= PDC_COLOR_PAIRS || !(SP->atrtab[pair].set))
313 return ERR;
314
315 SP->atrtab[pair].set = FALSE;
316 return OK;
317}
318
319int find_pair(int fg, int bg)
320{
321 int i;
322 PDC_PAIR *p = SP->atrtab;
323
324 for (i = 0; i < PDC_COLOR_PAIRS; i++)
325 if (p[i].set && p[i].f == fg && p[i].b == bg)
326 return i;
327
328 return -1;
329}
330
331static int _find_oldest()
332{
333 int i, lowind = 0, lowval = 0;
334 PDC_PAIR *p = SP->atrtab;
335
336 for (i = 1; i < PDC_COLOR_PAIRS; i++)
337 {
338 if (!p[i].set)
339 return i;
340
341 if (!lowval || (p[i].count < lowval))
342 {
343 lowind = i;
344 lowval = p[i].count;
345 }
346 }
347
348 return lowind;
349}
350
351int alloc_pair(int fg, int bg)
352{
353 int i = find_pair(fg, bg);
354
355 if (-1 == i)
356 {
357 i = _find_oldest();
358
359 if (ERR == init_pair(i, fg, bg))
360 return -1;
361 }
362
363 return i;
364}
diff --git a/scripts/kconfig/libcurses/curses.h b/scripts/kconfig/libcurses/curses.h
new file mode 100644
index 000000000..f58fe66df
--- /dev/null
+++ b/scripts/kconfig/libcurses/curses.h
@@ -0,0 +1,1441 @@
1/*----------------------------------------------------------------------*
2 * PDCurses *
3 *----------------------------------------------------------------------*/
4
5#ifndef __PDCURSES__
6#define __PDCURSES__ 1
7
8/*man-start**************************************************************
9
10Define before inclusion (only those needed):
11
12 Macro | Meaning / value
13 :-------------|-------------------------------------------------
14 XCURSES | if building / built for X11
15 PDC_RGB | RGB color (Red = 1, Green = 2, Blue = 4) vs. BGR
16 PDC_WIDE | if building / built with wide-character support
17 PDC_DLL_BUILD | if building / built as a Windows DLL
18 PDC_NCMOUSE | use ncurses mouse API vs. traditional PDCurses
19
20Defined by this header:
21
22 Macro | Meaning / value
23 :-------------|-------------------------------------------------
24 PDCURSES | PDCurses-only features are available
25 PDC_BUILD | API build version
26 PDC_VER_MAJOR | major version number
27 PDC_VER_MINOR | minor version number
28 PDC_VERDOT | version string
29
30**man-end****************************************************************/
31
32#define PDCURSES 1
33#define PDC_BUILD 3908
34#define PDC_VER_MAJOR 3
35#define PDC_VER_MINOR 9
36#define PDC_VERDOT "3.9"
37
38#define CHTYPE_LONG 1 /* chtype >= 32 bits */
39
40#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
41# define PDC_99 1
42#endif
43
44#if defined(__cplusplus) && __cplusplus >= 199711L
45# define PDC_PP98 1
46#endif
47
48/*----------------------------------------------------------------------*/
49
50#include <stdarg.h>
51#include <stddef.h>
52#include <stdio.h>
53
54#ifdef PDC_WIDE
55# include <wchar.h>
56#endif
57
58#if defined(PDC_99) && !defined(__bool_true_false_are_defined)
59# include <stdbool.h>
60#endif
61
62#ifdef __cplusplus
63extern "C"
64{
65# ifndef PDC_PP98
66# define bool _bool
67# endif
68#endif
69
70/*----------------------------------------------------------------------
71 *
72 * Constants and Types
73 *
74 */
75
76#undef FALSE
77#define FALSE 0
78
79#undef TRUE
80#define TRUE 1
81
82#undef ERR
83#define ERR (-1)
84
85#undef OK
86#define OK 0
87
88#if !defined(PDC_PP98) && !defined(__bool_true_false_are_defined)
89typedef unsigned char bool;
90#endif
91
92#if _LP64
93typedef unsigned int chtype;
94#else
95typedef unsigned long chtype; /* 16-bit attr + 16-bit char */
96#endif
97
98#ifdef PDC_WIDE
99typedef chtype cchar_t;
100#endif
101
102typedef chtype attr_t;
103
104/*----------------------------------------------------------------------
105 *
106 * Version Info
107 *
108 */
109
110/* Use this structure with PDC_get_version() for run-time info about the
111 way the library was built, in case it doesn't match the header. */
112
113typedef struct
114{
115 short flags; /* flags OR'd together (see below) */
116 short build; /* PDC_BUILD at compile time */
117 unsigned char major; /* PDC_VER_MAJOR */
118 unsigned char minor; /* PDC_VER_MINOR */
119 unsigned char csize; /* sizeof chtype */
120 unsigned char bsize; /* sizeof bool */
121} PDC_VERSION;
122
123enum
124{
125 PDC_VFLAG_DEBUG = 1, /* set if built with -DPDCDEBUG */
126 PDC_VFLAG_WIDE = 2, /* -DPDC_WIDE */
127 PDC_VFLAG_UTF8 = 4, /* -DPDC_FORCE_UTF8 */
128 PDC_VFLAG_DLL = 8, /* -DPDC_DLL_BUILD */
129 PDC_VFLAG_RGB = 16 /* -DPDC_RGB */
130};
131
132/*----------------------------------------------------------------------
133 *
134 * Mouse Interface
135 *
136 */
137
138#if _LP64
139typedef unsigned int mmask_t;
140#else
141typedef unsigned long mmask_t;
142#endif
143
144typedef struct
145{
146 int x; /* absolute column, 0 based, measured in characters */
147 int y; /* absolute row, 0 based, measured in characters */
148 short button[3]; /* state of each button */
149 int changes; /* flags indicating what has changed with the mouse */
150} MOUSE_STATUS;
151
152#define BUTTON_RELEASED 0x0000
153#define BUTTON_PRESSED 0x0001
154#define BUTTON_CLICKED 0x0002
155#define BUTTON_DOUBLE_CLICKED 0x0003
156#define BUTTON_TRIPLE_CLICKED 0x0004
157#define BUTTON_MOVED 0x0005 /* PDCurses */
158#define WHEEL_SCROLLED 0x0006 /* PDCurses */
159#define BUTTON_ACTION_MASK 0x0007 /* PDCurses */
160
161#define PDC_BUTTON_SHIFT 0x0008 /* PDCurses */
162#define PDC_BUTTON_CONTROL 0x0010 /* PDCurses */
163#define PDC_BUTTON_ALT 0x0020 /* PDCurses */
164#define BUTTON_MODIFIER_MASK 0x0038 /* PDCurses */
165
166#define MOUSE_X_POS (Mouse_status.x)
167#define MOUSE_Y_POS (Mouse_status.y)
168
169/*
170 * Bits associated with the .changes field:
171 * 3 2 1 0
172 * 210987654321098765432109876543210
173 * 1 <- button 1 has changed
174 * 10 <- button 2 has changed
175 * 100 <- button 3 has changed
176 * 1000 <- mouse has moved
177 * 10000 <- mouse position report
178 * 100000 <- mouse wheel up
179 * 1000000 <- mouse wheel down
180 * 10000000 <- mouse wheel left
181 * 100000000 <- mouse wheel right
182 */
183
184#define PDC_MOUSE_MOVED 0x0008
185#define PDC_MOUSE_POSITION 0x0010
186#define PDC_MOUSE_WHEEL_UP 0x0020
187#define PDC_MOUSE_WHEEL_DOWN 0x0040
188#define PDC_MOUSE_WHEEL_LEFT 0x0080
189#define PDC_MOUSE_WHEEL_RIGHT 0x0100
190
191#define A_BUTTON_CHANGED (Mouse_status.changes & 7)
192#define MOUSE_MOVED (Mouse_status.changes & PDC_MOUSE_MOVED)
193#define MOUSE_POS_REPORT (Mouse_status.changes & PDC_MOUSE_POSITION)
194#define BUTTON_CHANGED(x) (Mouse_status.changes & (1 << ((x) - 1)))
195#define BUTTON_STATUS(x) (Mouse_status.button[(x) - 1])
196#define MOUSE_WHEEL_UP (Mouse_status.changes & PDC_MOUSE_WHEEL_UP)
197#define MOUSE_WHEEL_DOWN (Mouse_status.changes & PDC_MOUSE_WHEEL_DOWN)
198#define MOUSE_WHEEL_LEFT (Mouse_status.changes & PDC_MOUSE_WHEEL_LEFT)
199#define MOUSE_WHEEL_RIGHT (Mouse_status.changes & PDC_MOUSE_WHEEL_RIGHT)
200
201/* mouse bit-masks */
202
203#define BUTTON1_RELEASED 0x00000001L
204#define BUTTON1_PRESSED 0x00000002L
205#define BUTTON1_CLICKED 0x00000004L
206#define BUTTON1_DOUBLE_CLICKED 0x00000008L
207#define BUTTON1_TRIPLE_CLICKED 0x00000010L
208#define BUTTON1_MOVED 0x00000010L /* PDCurses */
209
210#define BUTTON2_RELEASED 0x00000020L
211#define BUTTON2_PRESSED 0x00000040L
212#define BUTTON2_CLICKED 0x00000080L
213#define BUTTON2_DOUBLE_CLICKED 0x00000100L
214#define BUTTON2_TRIPLE_CLICKED 0x00000200L
215#define BUTTON2_MOVED 0x00000200L /* PDCurses */
216
217#define BUTTON3_RELEASED 0x00000400L
218#define BUTTON3_PRESSED 0x00000800L
219#define BUTTON3_CLICKED 0x00001000L
220#define BUTTON3_DOUBLE_CLICKED 0x00002000L
221#define BUTTON3_TRIPLE_CLICKED 0x00004000L
222#define BUTTON3_MOVED 0x00004000L /* PDCurses */
223
224/* For the ncurses-compatible functions only, BUTTON4_PRESSED and
225 BUTTON5_PRESSED are returned for mouse scroll wheel up and down;
226 otherwise PDCurses doesn't support buttons 4 and 5 */
227
228#define BUTTON4_RELEASED 0x00008000L
229#define BUTTON4_PRESSED 0x00010000L
230#define BUTTON4_CLICKED 0x00020000L
231#define BUTTON4_DOUBLE_CLICKED 0x00040000L
232#define BUTTON4_TRIPLE_CLICKED 0x00080000L
233
234#define BUTTON5_RELEASED 0x00100000L
235#define BUTTON5_PRESSED 0x00200000L
236#define BUTTON5_CLICKED 0x00400000L
237#define BUTTON5_DOUBLE_CLICKED 0x00800000L
238#define BUTTON5_TRIPLE_CLICKED 0x01000000L
239
240#define MOUSE_WHEEL_SCROLL 0x02000000L /* PDCurses */
241#define BUTTON_MODIFIER_SHIFT 0x04000000L /* PDCurses */
242#define BUTTON_MODIFIER_CONTROL 0x08000000L /* PDCurses */
243#define BUTTON_MODIFIER_ALT 0x10000000L /* PDCurses */
244
245#define ALL_MOUSE_EVENTS 0x1fffffffL
246#define REPORT_MOUSE_POSITION 0x20000000L
247
248/* ncurses mouse interface */
249
250typedef struct
251{
252 short id; /* unused, always 0 */
253 int x, y, z; /* x, y same as MOUSE_STATUS; z unused */
254 mmask_t bstate; /* equivalent to changes + button[], but
255 in the same format as used for mousemask() */
256} MEVENT;
257
258#if defined(PDC_NCMOUSE) && !defined(NCURSES_MOUSE_VERSION)
259# define NCURSES_MOUSE_VERSION 2
260#endif
261
262#ifdef NCURSES_MOUSE_VERSION
263# define BUTTON_SHIFT BUTTON_MODIFIER_SHIFT
264# define BUTTON_CONTROL BUTTON_MODIFIER_CONTROL
265# define BUTTON_CTRL BUTTON_MODIFIER_CONTROL
266# define BUTTON_ALT BUTTON_MODIFIER_ALT
267#else
268# define BUTTON_SHIFT PDC_BUTTON_SHIFT
269# define BUTTON_CONTROL PDC_BUTTON_CONTROL
270# define BUTTON_ALT PDC_BUTTON_ALT
271#endif
272
273/*----------------------------------------------------------------------
274 *
275 * Window and Screen Structures
276 *
277 */
278
279typedef struct _win /* definition of a window */
280{
281 int _cury; /* current pseudo-cursor */
282 int _curx;
283 int _maxy; /* max window coordinates */
284 int _maxx;
285 int _begy; /* origin on screen */
286 int _begx;
287 int _flags; /* window properties */
288 chtype _attrs; /* standard attributes and colors */
289 chtype _bkgd; /* background, normally blank */
290 bool _clear; /* causes clear at next refresh */
291 bool _leaveit; /* leaves cursor where it is */
292 bool _scroll; /* allows window scrolling */
293 bool _nodelay; /* input character wait flag */
294 bool _immed; /* immediate update flag */
295 bool _sync; /* synchronise window ancestors */
296 bool _use_keypad; /* flags keypad key mode active */
297 chtype **_y; /* pointer to line pointer array */
298 int *_firstch; /* first changed character in line */
299 int *_lastch; /* last changed character in line */
300 int _tmarg; /* top of scrolling region */
301 int _bmarg; /* bottom of scrolling region */
302 int _delayms; /* milliseconds of delay for getch() */
303 int _parx, _pary; /* coords relative to parent (0,0) */
304 struct _win *_parent; /* subwin's pointer to parent win */
305
306 /* these are used only if this is a pad */
307 struct pdat
308 {
309 int _pad_y;
310 int _pad_x;
311 int _pad_top;
312 int _pad_left;
313 int _pad_bottom;
314 int _pad_right;
315 } _pad; /* Pad-properties structure */
316} WINDOW;
317
318/* Color pair structure */
319
320typedef struct
321{
322 short f; /* foreground color */
323 short b; /* background color */
324 int count; /* allocation order */
325 bool set; /* pair has been set */
326} PDC_PAIR;
327
328/* Avoid using the SCREEN struct directly -- use the corresponding
329 functions if possible. This struct may eventually be made private. */
330
331typedef struct
332{
333 bool alive; /* if initscr() called, and not endwin() */
334 bool autocr; /* if cr -> lf */
335 bool cbreak; /* if terminal unbuffered */
336 bool echo; /* if terminal echo */
337 bool raw_inp; /* raw input mode (v. cooked input) */
338 bool raw_out; /* raw output mode (7 v. 8 bits) */
339 bool audible; /* FALSE if the bell is visual */
340 bool mono; /* TRUE if current screen is mono */
341 bool resized; /* TRUE if TERM has been resized */
342 bool orig_attr; /* TRUE if we have the original colors */
343 short orig_fore; /* original screen foreground color */
344 short orig_back; /* original screen foreground color */
345 int cursrow; /* position of physical cursor */
346 int curscol; /* position of physical cursor */
347 int visibility; /* visibility of cursor */
348 int orig_cursor; /* original cursor size */
349 int lines; /* new value for LINES */
350 int cols; /* new value for COLS */
351 mmask_t _trap_mbe; /* trap these mouse button events */
352 int mouse_wait; /* time to wait (in ms) for a
353 button release after a press, in
354 order to count it as a click */
355 int slklines; /* lines in use by slk_init() */
356 WINDOW *slk_winptr; /* window for slk */
357 int linesrippedoff; /* lines ripped off via ripoffline() */
358 int linesrippedoffontop; /* lines ripped off on
359 top via ripoffline() */
360 int delaytenths; /* 1/10ths second to wait block
361 getch() for */
362 bool _preserve; /* TRUE if screen background
363 to be preserved */
364 int _restore; /* specifies if screen background
365 to be restored, and how */
366 unsigned long key_modifiers; /* key modifiers (SHIFT, CONTROL, etc.)
367 on last key press */
368 bool return_key_modifiers; /* TRUE if modifier keys are
369 returned as "real" keys */
370 bool key_code; /* TRUE if last key is a special key;
371 used internally by get_wch() */
372 MOUSE_STATUS mouse_status; /* last returned mouse status */
373 short line_color; /* color of line attributes - default -1 */
374 attr_t termattrs; /* attribute capabilities */
375 WINDOW *lastscr; /* the last screen image */
376 FILE *dbfp; /* debug trace file pointer */
377 bool color_started; /* TRUE after start_color() */
378 bool dirty; /* redraw on napms() after init_color() */
379 int sel_start; /* start of selection (y * COLS + x) */
380 int sel_end; /* end of selection */
381 int *c_buffer; /* character buffer */
382 int c_pindex; /* putter index */
383 int c_gindex; /* getter index */
384 int *c_ungch; /* array of ungotten chars */
385 int c_ungind; /* ungetch() push index */
386 int c_ungmax; /* allocated size of ungetch() buffer */
387 PDC_PAIR *atrtab; /* table of color pairs */
388} SCREEN;
389
390/*----------------------------------------------------------------------
391 *
392 * External Variables
393 *
394 */
395
396#ifdef PDC_DLL_BUILD
397# ifdef CURSES_LIBRARY
398# define PDCEX __declspec(dllexport) extern
399# else
400# define PDCEX __declspec(dllimport)
401# endif
402#else
403# define PDCEX extern
404#endif
405
406PDCEX int LINES; /* terminal height */
407PDCEX int COLS; /* terminal width */
408PDCEX WINDOW *stdscr; /* the default screen window */
409PDCEX WINDOW *curscr; /* the current screen image */
410PDCEX SCREEN *SP; /* curses variables */
411PDCEX MOUSE_STATUS Mouse_status;
412PDCEX int COLORS;
413PDCEX int COLOR_PAIRS;
414PDCEX int TABSIZE;
415PDCEX chtype acs_map[]; /* alternate character set map */
416PDCEX char ttytype[]; /* terminal name/description */
417
418/*man-start**************************************************************
419
420Text Attributes
421===============
422
423PDCurses uses a 32-bit integer for its chtype:
424
425 color pair | modifiers | character eg 'a'
426 -----------------------|-----------------------|--------------------
427 31 30 29 28 27 26 25 24|23 22 21 20 19 18 17 16|15 14 13 .. 2 1 0
428
429There are 256 color pairs (8 bits), 8 bits for modifiers, and 16 bits
430for character data. The modifiers are bold, underline, right-line,
431left-line, italic, reverse and blink, plus the alternate character set
432indicator.
433
434**man-end****************************************************************/
435
436/*** Video attribute macros ***/
437
438#define A_NORMAL (chtype)0
439
440#define A_ALTCHARSET (chtype)0x00010000
441#define A_RIGHT (chtype)0x00020000
442#define A_LEFT (chtype)0x00040000
443#define A_ITALIC (chtype)0x00080000
444#define A_UNDERLINE (chtype)0x00100000
445#define A_REVERSE (chtype)0x00200000
446#define A_BLINK (chtype)0x00400000
447#define A_BOLD (chtype)0x00800000
448
449#define A_ATTRIBUTES (chtype)0xffff0000
450#define A_CHARTEXT (chtype)0x0000ffff
451#define A_COLOR (chtype)0xff000000
452
453#define PDC_COLOR_SHIFT 24
454
455#define A_LEFTLINE A_LEFT
456#define A_RIGHTLINE A_RIGHT
457#define A_STANDOUT (A_REVERSE | A_BOLD) /* X/Open */
458
459#define A_DIM A_NORMAL
460#define A_INVIS A_NORMAL
461#define A_PROTECT A_NORMAL
462
463#define A_HORIZONTAL A_NORMAL
464#define A_LOW A_NORMAL
465#define A_TOP A_NORMAL
466#define A_VERTICAL A_NORMAL
467
468#define CHR_MSK A_CHARTEXT /* Obsolete */
469#define ATR_MSK A_ATTRIBUTES /* Obsolete */
470#define ATR_NRM A_NORMAL /* Obsolete */
471
472/* For use with attr_t -- X/Open says, "these shall be distinct", so
473 this is a non-conforming implementation. */
474
475#define WA_NORMAL A_NORMAL
476
477#define WA_ALTCHARSET A_ALTCHARSET
478#define WA_BLINK A_BLINK
479#define WA_BOLD A_BOLD
480#define WA_DIM A_DIM
481#define WA_INVIS A_INVIS
482#define WA_ITALIC A_ITALIC
483#define WA_LEFT A_LEFT
484#define WA_PROTECT A_PROTECT
485#define WA_REVERSE A_REVERSE
486#define WA_RIGHT A_RIGHT
487#define WA_STANDOUT A_STANDOUT
488#define WA_UNDERLINE A_UNDERLINE
489
490#define WA_HORIZONTAL A_HORIZONTAL
491#define WA_LOW A_LOW
492#define WA_TOP A_TOP
493#define WA_VERTICAL A_VERTICAL
494
495#define WA_ATTRIBUTES A_ATTRIBUTES
496
497/*** Alternate character set macros ***/
498
499#define PDC_ACS(w) ((chtype)w | A_ALTCHARSET)
500
501/* VT100-compatible symbols -- box chars */
502
503#define ACS_ULCORNER PDC_ACS('l')
504#define ACS_LLCORNER PDC_ACS('m')
505#define ACS_URCORNER PDC_ACS('k')
506#define ACS_LRCORNER PDC_ACS('j')
507#define ACS_RTEE PDC_ACS('u')
508#define ACS_LTEE PDC_ACS('t')
509#define ACS_BTEE PDC_ACS('v')
510#define ACS_TTEE PDC_ACS('w')
511#define ACS_HLINE PDC_ACS('q')
512#define ACS_VLINE PDC_ACS('x')
513#define ACS_PLUS PDC_ACS('n')
514
515/* VT100-compatible symbols -- other */
516
517#define ACS_S1 PDC_ACS('o')
518#define ACS_S9 PDC_ACS('s')
519#define ACS_DIAMOND PDC_ACS('`')
520#define ACS_CKBOARD PDC_ACS('a')
521#define ACS_DEGREE PDC_ACS('f')
522#define ACS_PLMINUS PDC_ACS('g')
523#define ACS_BULLET PDC_ACS('~')
524
525/* Teletype 5410v1 symbols -- these are defined in SysV curses, but
526 are not well-supported by most terminals. Stick to VT100 characters
527 for optimum portability. */
528
529#define ACS_LARROW PDC_ACS(',')
530#define ACS_RARROW PDC_ACS('+')
531#define ACS_DARROW PDC_ACS('.')
532#define ACS_UARROW PDC_ACS('-')
533#define ACS_BOARD PDC_ACS('h')
534#define ACS_LANTERN PDC_ACS('i')
535#define ACS_BLOCK PDC_ACS('0')
536
537/* That goes double for these -- undocumented SysV symbols. Don't use
538 them. */
539
540#define ACS_S3 PDC_ACS('p')
541#define ACS_S7 PDC_ACS('r')
542#define ACS_LEQUAL PDC_ACS('y')
543#define ACS_GEQUAL PDC_ACS('z')
544#define ACS_PI PDC_ACS('{')
545#define ACS_NEQUAL PDC_ACS('|')
546#define ACS_STERLING PDC_ACS('}')
547
548/* Box char aliases */
549
550#define ACS_BSSB ACS_ULCORNER
551#define ACS_SSBB ACS_LLCORNER
552#define ACS_BBSS ACS_URCORNER
553#define ACS_SBBS ACS_LRCORNER
554#define ACS_SBSS ACS_RTEE
555#define ACS_SSSB ACS_LTEE
556#define ACS_SSBS ACS_BTEE
557#define ACS_BSSS ACS_TTEE
558#define ACS_BSBS ACS_HLINE
559#define ACS_SBSB ACS_VLINE
560#define ACS_SSSS ACS_PLUS
561
562/* cchar_t aliases */
563
564#ifdef PDC_WIDE
565# define WACS_ULCORNER (&(acs_map['l']))
566# define WACS_LLCORNER (&(acs_map['m']))
567# define WACS_URCORNER (&(acs_map['k']))
568# define WACS_LRCORNER (&(acs_map['j']))
569# define WACS_RTEE (&(acs_map['u']))
570# define WACS_LTEE (&(acs_map['t']))
571# define WACS_BTEE (&(acs_map['v']))
572# define WACS_TTEE (&(acs_map['w']))
573# define WACS_HLINE (&(acs_map['q']))
574# define WACS_VLINE (&(acs_map['x']))
575# define WACS_PLUS (&(acs_map['n']))
576
577# define WACS_S1 (&(acs_map['o']))
578# define WACS_S9 (&(acs_map['s']))
579# define WACS_DIAMOND (&(acs_map['`']))
580# define WACS_CKBOARD (&(acs_map['a']))
581# define WACS_DEGREE (&(acs_map['f']))
582# define WACS_PLMINUS (&(acs_map['g']))
583# define WACS_BULLET (&(acs_map['~']))
584
585# define WACS_LARROW (&(acs_map[',']))
586# define WACS_RARROW (&(acs_map['+']))
587# define WACS_DARROW (&(acs_map['.']))
588# define WACS_UARROW (&(acs_map['-']))
589# define WACS_BOARD (&(acs_map['h']))
590# define WACS_LANTERN (&(acs_map['i']))
591# define WACS_BLOCK (&(acs_map['0']))
592
593# define WACS_S3 (&(acs_map['p']))
594# define WACS_S7 (&(acs_map['r']))
595# define WACS_LEQUAL (&(acs_map['y']))
596# define WACS_GEQUAL (&(acs_map['z']))
597# define WACS_PI (&(acs_map['{']))
598# define WACS_NEQUAL (&(acs_map['|']))
599# define WACS_STERLING (&(acs_map['}']))
600
601# define WACS_BSSB WACS_ULCORNER
602# define WACS_SSBB WACS_LLCORNER
603# define WACS_BBSS WACS_URCORNER
604# define WACS_SBBS WACS_LRCORNER
605# define WACS_SBSS WACS_RTEE
606# define WACS_SSSB WACS_LTEE
607# define WACS_SSBS WACS_BTEE
608# define WACS_BSSS WACS_TTEE
609# define WACS_BSBS WACS_HLINE
610# define WACS_SBSB WACS_VLINE
611# define WACS_SSSS WACS_PLUS
612#endif
613
614/*** Color macros ***/
615
616#define COLOR_BLACK 0
617
618#ifdef PDC_RGB /* RGB */
619# define COLOR_RED 1
620# define COLOR_GREEN 2
621# define COLOR_BLUE 4
622#else /* BGR */
623# define COLOR_BLUE 1
624# define COLOR_GREEN 2
625# define COLOR_RED 4
626#endif
627
628#define COLOR_CYAN (COLOR_BLUE | COLOR_GREEN)
629#define COLOR_MAGENTA (COLOR_RED | COLOR_BLUE)
630#define COLOR_YELLOW (COLOR_RED | COLOR_GREEN)
631
632#define COLOR_WHITE 7
633
634/*----------------------------------------------------------------------
635 *
636 * Function and Keypad Key Definitions
637 * Many are just for compatibility
638 *
639 */
640
641#define KEY_CODE_YES 0x100 /* If get_wch() gives a key code */
642
643#define KEY_BREAK 0x101 /* Not on PC KBD */
644#define KEY_DOWN 0x102 /* Down arrow key */
645#define KEY_UP 0x103 /* Up arrow key */
646#define KEY_LEFT 0x104 /* Left arrow key */
647#define KEY_RIGHT 0x105 /* Right arrow key */
648#define KEY_HOME 0x106 /* home key */
649#define KEY_BACKSPACE 0x107 /* not on pc */
650#define KEY_F0 0x108 /* function keys; 64 reserved */
651
652#define KEY_DL 0x148 /* delete line */
653#define KEY_IL 0x149 /* insert line */
654#define KEY_DC 0x14a /* delete character */
655#define KEY_IC 0x14b /* insert char or enter ins mode */
656#define KEY_EIC 0x14c /* exit insert char mode */
657#define KEY_CLEAR 0x14d /* clear screen */
658#define KEY_EOS 0x14e /* clear to end of screen */
659#define KEY_EOL 0x14f /* clear to end of line */
660#define KEY_SF 0x150 /* scroll 1 line forward */
661#define KEY_SR 0x151 /* scroll 1 line back (reverse) */
662#define KEY_NPAGE 0x152 /* next page */
663#define KEY_PPAGE 0x153 /* previous page */
664#define KEY_STAB 0x154 /* set tab */
665#define KEY_CTAB 0x155 /* clear tab */
666#define KEY_CATAB 0x156 /* clear all tabs */
667#define KEY_ENTER 0x157 /* enter or send (unreliable) */
668#define KEY_SRESET 0x158 /* soft/reset (partial/unreliable) */
669#define KEY_RESET 0x159 /* reset/hard reset (unreliable) */
670#define KEY_PRINT 0x15a /* print/copy */
671#define KEY_LL 0x15b /* home down/bottom (lower left) */
672#define KEY_ABORT 0x15c /* abort/terminate key (any) */
673#define KEY_SHELP 0x15d /* short help */
674#define KEY_LHELP 0x15e /* long help */
675#define KEY_BTAB 0x15f /* Back tab key */
676#define KEY_BEG 0x160 /* beg(inning) key */
677#define KEY_CANCEL 0x161 /* cancel key */
678#define KEY_CLOSE 0x162 /* close key */
679#define KEY_COMMAND 0x163 /* cmd (command) key */
680#define KEY_COPY 0x164 /* copy key */
681#define KEY_CREATE 0x165 /* create key */
682#define KEY_END 0x166 /* end key */
683#define KEY_EXIT 0x167 /* exit key */
684#define KEY_FIND 0x168 /* find key */
685#define KEY_HELP 0x169 /* help key */
686#define KEY_MARK 0x16a /* mark key */
687#define KEY_MESSAGE 0x16b /* message key */
688#define KEY_MOVE 0x16c /* move key */
689#define KEY_NEXT 0x16d /* next object key */
690#define KEY_OPEN 0x16e /* open key */
691#define KEY_OPTIONS 0x16f /* options key */
692#define KEY_PREVIOUS 0x170 /* previous object key */
693#define KEY_REDO 0x171 /* redo key */
694#define KEY_REFERENCE 0x172 /* ref(erence) key */
695#define KEY_REFRESH 0x173 /* refresh key */
696#define KEY_REPLACE 0x174 /* replace key */
697#define KEY_RESTART 0x175 /* restart key */
698#define KEY_RESUME 0x176 /* resume key */
699#define KEY_SAVE 0x177 /* save key */
700#define KEY_SBEG 0x178 /* shifted beginning key */
701#define KEY_SCANCEL 0x179 /* shifted cancel key */
702#define KEY_SCOMMAND 0x17a /* shifted command key */
703#define KEY_SCOPY 0x17b /* shifted copy key */
704#define KEY_SCREATE 0x17c /* shifted create key */
705#define KEY_SDC 0x17d /* shifted delete char key */
706#define KEY_SDL 0x17e /* shifted delete line key */
707#define KEY_SELECT 0x17f /* select key */
708#define KEY_SEND 0x180 /* shifted end key */
709#define KEY_SEOL 0x181 /* shifted clear line key */
710#define KEY_SEXIT 0x182 /* shifted exit key */
711#define KEY_SFIND 0x183 /* shifted find key */
712#define KEY_SHOME 0x184 /* shifted home key */
713#define KEY_SIC 0x185 /* shifted input key */
714
715#define KEY_SLEFT 0x187 /* shifted left arrow key */
716#define KEY_SMESSAGE 0x188 /* shifted message key */
717#define KEY_SMOVE 0x189 /* shifted move key */
718#define KEY_SNEXT 0x18a /* shifted next key */
719#define KEY_SOPTIONS 0x18b /* shifted options key */
720#define KEY_SPREVIOUS 0x18c /* shifted prev key */
721#define KEY_SPRINT 0x18d /* shifted print key */
722#define KEY_SREDO 0x18e /* shifted redo key */
723#define KEY_SREPLACE 0x18f /* shifted replace key */
724#define KEY_SRIGHT 0x190 /* shifted right arrow */
725#define KEY_SRSUME 0x191 /* shifted resume key */
726#define KEY_SSAVE 0x192 /* shifted save key */
727#define KEY_SSUSPEND 0x193 /* shifted suspend key */
728#define KEY_SUNDO 0x194 /* shifted undo key */
729#define KEY_SUSPEND 0x195 /* suspend key */
730#define KEY_UNDO 0x196 /* undo key */
731
732/* PDCurses-specific key definitions -- PC only */
733
734#define ALT_0 0x197
735#define ALT_1 0x198
736#define ALT_2 0x199
737#define ALT_3 0x19a
738#define ALT_4 0x19b
739#define ALT_5 0x19c
740#define ALT_6 0x19d
741#define ALT_7 0x19e
742#define ALT_8 0x19f
743#define ALT_9 0x1a0
744#define ALT_A 0x1a1
745#define ALT_B 0x1a2
746#define ALT_C 0x1a3
747#define ALT_D 0x1a4
748#define ALT_E 0x1a5
749#define ALT_F 0x1a6
750#define ALT_G 0x1a7
751#define ALT_H 0x1a8
752#define ALT_I 0x1a9
753#define ALT_J 0x1aa
754#define ALT_K 0x1ab
755#define ALT_L 0x1ac
756#define ALT_M 0x1ad
757#define ALT_N 0x1ae
758#define ALT_O 0x1af
759#define ALT_P 0x1b0
760#define ALT_Q 0x1b1
761#define ALT_R 0x1b2
762#define ALT_S 0x1b3
763#define ALT_T 0x1b4
764#define ALT_U 0x1b5
765#define ALT_V 0x1b6
766#define ALT_W 0x1b7
767#define ALT_X 0x1b8
768#define ALT_Y 0x1b9
769#define ALT_Z 0x1ba
770
771#define CTL_LEFT 0x1bb /* Control-Left-Arrow */
772#define CTL_RIGHT 0x1bc
773#define CTL_PGUP 0x1bd
774#define CTL_PGDN 0x1be
775#define CTL_HOME 0x1bf
776#define CTL_END 0x1c0
777
778#define KEY_A1 0x1c1 /* upper left on Virtual keypad */
779#define KEY_A2 0x1c2 /* upper middle on Virt. keypad */
780#define KEY_A3 0x1c3 /* upper right on Vir. keypad */
781#define KEY_B1 0x1c4 /* middle left on Virt. keypad */
782#define KEY_B2 0x1c5 /* center on Virt. keypad */
783#define KEY_B3 0x1c6 /* middle right on Vir. keypad */
784#define KEY_C1 0x1c7 /* lower left on Virt. keypad */
785#define KEY_C2 0x1c8 /* lower middle on Virt. keypad */
786#define KEY_C3 0x1c9 /* lower right on Vir. keypad */
787
788#define PADSLASH 0x1ca /* slash on keypad */
789#define PADENTER 0x1cb /* enter on keypad */
790#define CTL_PADENTER 0x1cc /* ctl-enter on keypad */
791#define ALT_PADENTER 0x1cd /* alt-enter on keypad */
792#define PADSTOP 0x1ce /* stop on keypad */
793#define PADSTAR 0x1cf /* star on keypad */
794#define PADMINUS 0x1d0 /* minus on keypad */
795#define PADPLUS 0x1d1 /* plus on keypad */
796#define CTL_PADSTOP 0x1d2 /* ctl-stop on keypad */
797#define CTL_PADCENTER 0x1d3 /* ctl-enter on keypad */
798#define CTL_PADPLUS 0x1d4 /* ctl-plus on keypad */
799#define CTL_PADMINUS 0x1d5 /* ctl-minus on keypad */
800#define CTL_PADSLASH 0x1d6 /* ctl-slash on keypad */
801#define CTL_PADSTAR 0x1d7 /* ctl-star on keypad */
802#define ALT_PADPLUS 0x1d8 /* alt-plus on keypad */
803#define ALT_PADMINUS 0x1d9 /* alt-minus on keypad */
804#define ALT_PADSLASH 0x1da /* alt-slash on keypad */
805#define ALT_PADSTAR 0x1db /* alt-star on keypad */
806#define ALT_PADSTOP 0x1dc /* alt-stop on keypad */
807#define CTL_INS 0x1dd /* ctl-insert */
808#define ALT_DEL 0x1de /* alt-delete */
809#define ALT_INS 0x1df /* alt-insert */
810#define CTL_UP 0x1e0 /* ctl-up arrow */
811#define CTL_DOWN 0x1e1 /* ctl-down arrow */
812#define CTL_TAB 0x1e2 /* ctl-tab */
813#define ALT_TAB 0x1e3
814#define ALT_MINUS 0x1e4
815#define ALT_EQUAL 0x1e5
816#define ALT_HOME 0x1e6
817#define ALT_PGUP 0x1e7
818#define ALT_PGDN 0x1e8
819#define ALT_END 0x1e9
820#define ALT_UP 0x1ea /* alt-up arrow */
821#define ALT_DOWN 0x1eb /* alt-down arrow */
822#define ALT_RIGHT 0x1ec /* alt-right arrow */
823#define ALT_LEFT 0x1ed /* alt-left arrow */
824#define ALT_ENTER 0x1ee /* alt-enter */
825#define ALT_ESC 0x1ef /* alt-escape */
826#define ALT_BQUOTE 0x1f0 /* alt-back quote */
827#define ALT_LBRACKET 0x1f1 /* alt-left bracket */
828#define ALT_RBRACKET 0x1f2 /* alt-right bracket */
829#define ALT_SEMICOLON 0x1f3 /* alt-semi-colon */
830#define ALT_FQUOTE 0x1f4 /* alt-forward quote */
831#define ALT_COMMA 0x1f5 /* alt-comma */
832#define ALT_STOP 0x1f6 /* alt-stop */
833#define ALT_FSLASH 0x1f7 /* alt-forward slash */
834#define ALT_BKSP 0x1f8 /* alt-backspace */
835#define CTL_BKSP 0x1f9 /* ctl-backspace */
836#define PAD0 0x1fa /* keypad 0 */
837
838#define CTL_PAD0 0x1fb /* ctl-keypad 0 */
839#define CTL_PAD1 0x1fc
840#define CTL_PAD2 0x1fd
841#define CTL_PAD3 0x1fe
842#define CTL_PAD4 0x1ff
843#define CTL_PAD5 0x200
844#define CTL_PAD6 0x201
845#define CTL_PAD7 0x202
846#define CTL_PAD8 0x203
847#define CTL_PAD9 0x204
848
849#define ALT_PAD0 0x205 /* alt-keypad 0 */
850#define ALT_PAD1 0x206
851#define ALT_PAD2 0x207
852#define ALT_PAD3 0x208
853#define ALT_PAD4 0x209
854#define ALT_PAD5 0x20a
855#define ALT_PAD6 0x20b
856#define ALT_PAD7 0x20c
857#define ALT_PAD8 0x20d
858#define ALT_PAD9 0x20e
859
860#define CTL_DEL 0x20f /* clt-delete */
861#define ALT_BSLASH 0x210 /* alt-back slash */
862#define CTL_ENTER 0x211 /* ctl-enter */
863
864#define SHF_PADENTER 0x212 /* shift-enter on keypad */
865#define SHF_PADSLASH 0x213 /* shift-slash on keypad */
866#define SHF_PADSTAR 0x214 /* shift-star on keypad */
867#define SHF_PADPLUS 0x215 /* shift-plus on keypad */
868#define SHF_PADMINUS 0x216 /* shift-minus on keypad */
869#define SHF_UP 0x217 /* shift-up on keypad */
870#define SHF_DOWN 0x218 /* shift-down on keypad */
871#define SHF_IC 0x219 /* shift-insert on keypad */
872#define SHF_DC 0x21a /* shift-delete on keypad */
873
874#define KEY_MOUSE 0x21b /* "mouse" key */
875#define KEY_SHIFT_L 0x21c /* Left-shift */
876#define KEY_SHIFT_R 0x21d /* Right-shift */
877#define KEY_CONTROL_L 0x21e /* Left-control */
878#define KEY_CONTROL_R 0x21f /* Right-control */
879#define KEY_ALT_L 0x220 /* Left-alt */
880#define KEY_ALT_R 0x221 /* Right-alt */
881#define KEY_RESIZE 0x222 /* Window resize */
882#define KEY_SUP 0x223 /* Shifted up arrow */
883#define KEY_SDOWN 0x224 /* Shifted down arrow */
884
885#define KEY_MIN KEY_BREAK /* Minimum curses key value */
886#define KEY_MAX KEY_SDOWN /* Maximum curses key */
887
888#define KEY_F(n) (KEY_F0 + (n))
889
890/*----------------------------------------------------------------------
891 *
892 * Functions
893 *
894 */
895
896/* Standard */
897
898PDCEX int addch(const chtype);
899PDCEX int addchnstr(const chtype *, int);
900PDCEX int addchstr(const chtype *);
901PDCEX int addnstr(const char *, int);
902PDCEX int addstr(const char *);
903PDCEX int attroff(chtype);
904PDCEX int attron(chtype);
905PDCEX int attrset(chtype);
906PDCEX int attr_get(attr_t *, short *, void *);
907PDCEX int attr_off(attr_t, void *);
908PDCEX int attr_on(attr_t, void *);
909PDCEX int attr_set(attr_t, short, void *);
910PDCEX int baudrate(void);
911PDCEX int beep(void);
912PDCEX int bkgd(chtype);
913PDCEX void bkgdset(chtype);
914PDCEX int border(chtype, chtype, chtype, chtype,
915 chtype, chtype, chtype, chtype);
916PDCEX int box(WINDOW *, chtype, chtype);
917PDCEX bool can_change_color(void);
918PDCEX int cbreak(void);
919PDCEX int chgat(int, attr_t, short, const void *);
920PDCEX int clearok(WINDOW *, bool);
921PDCEX int clear(void);
922PDCEX int clrtobot(void);
923PDCEX int clrtoeol(void);
924PDCEX int color_content(short, short *, short *, short *);
925PDCEX int color_set(short, void *);
926PDCEX int copywin(const WINDOW *, WINDOW *, int, int, int,
927 int, int, int, int);
928PDCEX int curs_set(int);
929PDCEX int def_prog_mode(void);
930PDCEX int def_shell_mode(void);
931PDCEX int delay_output(int);
932PDCEX int delch(void);
933PDCEX int deleteln(void);
934PDCEX void delscreen(SCREEN *);
935PDCEX int delwin(WINDOW *);
936PDCEX WINDOW *derwin(WINDOW *, int, int, int, int);
937PDCEX int doupdate(void);
938PDCEX WINDOW *dupwin(WINDOW *);
939PDCEX int echochar(const chtype);
940PDCEX int echo(void);
941PDCEX int endwin(void);
942PDCEX char erasechar(void);
943PDCEX int erase(void);
944PDCEX void filter(void);
945PDCEX int flash(void);
946PDCEX int flushinp(void);
947PDCEX chtype getbkgd(WINDOW *);
948PDCEX int getnstr(char *, int);
949PDCEX int getstr(char *);
950PDCEX WINDOW *getwin(FILE *);
951PDCEX int halfdelay(int);
952PDCEX bool has_colors(void);
953PDCEX bool has_ic(void);
954PDCEX bool has_il(void);
955PDCEX int hline(chtype, int);
956PDCEX void idcok(WINDOW *, bool);
957PDCEX int idlok(WINDOW *, bool);
958PDCEX void immedok(WINDOW *, bool);
959PDCEX int inchnstr(chtype *, int);
960PDCEX int inchstr(chtype *);
961PDCEX chtype inch(void);
962PDCEX int init_color(short, short, short, short);
963PDCEX int init_pair(short, short, short);
964PDCEX WINDOW *initscr(void);
965PDCEX int innstr(char *, int);
966PDCEX int insch(chtype);
967PDCEX int insdelln(int);
968PDCEX int insertln(void);
969PDCEX int insnstr(const char *, int);
970PDCEX int insstr(const char *);
971PDCEX int instr(char *);
972PDCEX int intrflush(WINDOW *, bool);
973PDCEX bool isendwin(void);
974PDCEX bool is_linetouched(WINDOW *, int);
975PDCEX bool is_wintouched(WINDOW *);
976PDCEX char *keyname(int);
977PDCEX int keypad(WINDOW *, bool);
978PDCEX char killchar(void);
979PDCEX int leaveok(WINDOW *, bool);
980PDCEX char *longname(void);
981PDCEX int meta(WINDOW *, bool);
982PDCEX int move(int, int);
983PDCEX int mvaddch(int, int, const chtype);
984PDCEX int mvaddchnstr(int, int, const chtype *, int);
985PDCEX int mvaddchstr(int, int, const chtype *);
986PDCEX int mvaddnstr(int, int, const char *, int);
987PDCEX int mvaddstr(int, int, const char *);
988PDCEX int mvchgat(int, int, int, attr_t, short, const void *);
989PDCEX int mvcur(int, int, int, int);
990PDCEX int mvdelch(int, int);
991PDCEX int mvderwin(WINDOW *, int, int);
992PDCEX int mvgetch(int, int);
993PDCEX int mvgetnstr(int, int, char *, int);
994PDCEX int mvgetstr(int, int, char *);
995PDCEX int mvhline(int, int, chtype, int);
996PDCEX chtype mvinch(int, int);
997PDCEX int mvinchnstr(int, int, chtype *, int);
998PDCEX int mvinchstr(int, int, chtype *);
999PDCEX int mvinnstr(int, int, char *, int);
1000PDCEX int mvinsch(int, int, chtype);
1001PDCEX int mvinsnstr(int, int, const char *, int);
1002PDCEX int mvinsstr(int, int, const char *);
1003PDCEX int mvinstr(int, int, char *);
1004PDCEX int mvprintw(int, int, const char *, ...);
1005PDCEX int mvscanw(int, int, const char *, ...);
1006PDCEX int mvvline(int, int, chtype, int);
1007PDCEX int mvwaddchnstr(WINDOW *, int, int, const chtype *, int);
1008PDCEX int mvwaddchstr(WINDOW *, int, int, const chtype *);
1009PDCEX int mvwaddch(WINDOW *, int, int, const chtype);
1010PDCEX int mvwaddnstr(WINDOW *, int, int, const char *, int);
1011PDCEX int mvwaddstr(WINDOW *, int, int, const char *);
1012PDCEX int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *);
1013PDCEX int mvwdelch(WINDOW *, int, int);
1014PDCEX int mvwgetch(WINDOW *, int, int);
1015PDCEX int mvwgetnstr(WINDOW *, int, int, char *, int);
1016PDCEX int mvwgetstr(WINDOW *, int, int, char *);
1017PDCEX int mvwhline(WINDOW *, int, int, chtype, int);
1018PDCEX int mvwinchnstr(WINDOW *, int, int, chtype *, int);
1019PDCEX int mvwinchstr(WINDOW *, int, int, chtype *);
1020PDCEX chtype mvwinch(WINDOW *, int, int);
1021PDCEX int mvwinnstr(WINDOW *, int, int, char *, int);
1022PDCEX int mvwinsch(WINDOW *, int, int, chtype);
1023PDCEX int mvwinsnstr(WINDOW *, int, int, const char *, int);
1024PDCEX int mvwinsstr(WINDOW *, int, int, const char *);
1025PDCEX int mvwinstr(WINDOW *, int, int, char *);
1026PDCEX int mvwin(WINDOW *, int, int);
1027PDCEX int mvwprintw(WINDOW *, int, int, const char *, ...);
1028PDCEX int mvwscanw(WINDOW *, int, int, const char *, ...);
1029PDCEX int mvwvline(WINDOW *, int, int, chtype, int);
1030PDCEX int napms(int);
1031PDCEX WINDOW *newpad(int, int);
1032PDCEX SCREEN *newterm(const char *, FILE *, FILE *);
1033PDCEX WINDOW *newwin(int, int, int, int);
1034PDCEX int nl(void);
1035PDCEX int nocbreak(void);
1036PDCEX int nodelay(WINDOW *, bool);
1037PDCEX int noecho(void);
1038PDCEX int nonl(void);
1039PDCEX void noqiflush(void);
1040PDCEX int noraw(void);
1041PDCEX int notimeout(WINDOW *, bool);
1042PDCEX int overlay(const WINDOW *, WINDOW *);
1043PDCEX int overwrite(const WINDOW *, WINDOW *);
1044PDCEX int pair_content(short, short *, short *);
1045PDCEX int pechochar(WINDOW *, chtype);
1046PDCEX int pnoutrefresh(WINDOW *, int, int, int, int, int, int);
1047PDCEX int prefresh(WINDOW *, int, int, int, int, int, int);
1048PDCEX int printw(const char *, ...);
1049PDCEX int putwin(WINDOW *, FILE *);
1050PDCEX void qiflush(void);
1051PDCEX int raw(void);
1052PDCEX int redrawwin(WINDOW *);
1053PDCEX int refresh(void);
1054PDCEX int reset_prog_mode(void);
1055PDCEX int reset_shell_mode(void);
1056PDCEX int resetty(void);
1057PDCEX int ripoffline(int, int (*)(WINDOW *, int));
1058PDCEX int savetty(void);
1059PDCEX int scanw(const char *, ...);
1060PDCEX int scr_dump(const char *);
1061PDCEX int scr_init(const char *);
1062PDCEX int scr_restore(const char *);
1063PDCEX int scr_set(const char *);
1064PDCEX int scrl(int);
1065PDCEX int scroll(WINDOW *);
1066PDCEX int scrollok(WINDOW *, bool);
1067PDCEX SCREEN *set_term(SCREEN *);
1068PDCEX int setscrreg(int, int);
1069PDCEX int slk_attroff(const chtype);
1070PDCEX int slk_attr_off(const attr_t, void *);
1071PDCEX int slk_attron(const chtype);
1072PDCEX int slk_attr_on(const attr_t, void *);
1073PDCEX int slk_attrset(const chtype);
1074PDCEX int slk_attr_set(const attr_t, short, void *);
1075PDCEX int slk_clear(void);
1076PDCEX int slk_color(short);
1077PDCEX int slk_init(int);
1078PDCEX char *slk_label(int);
1079PDCEX int slk_noutrefresh(void);
1080PDCEX int slk_refresh(void);
1081PDCEX int slk_restore(void);
1082PDCEX int slk_set(int, const char *, int);
1083PDCEX int slk_touch(void);
1084PDCEX int standend(void);
1085PDCEX int standout(void);
1086PDCEX int start_color(void);
1087PDCEX WINDOW *subpad(WINDOW *, int, int, int, int);
1088PDCEX WINDOW *subwin(WINDOW *, int, int, int, int);
1089PDCEX int syncok(WINDOW *, bool);
1090PDCEX chtype termattrs(void);
1091PDCEX attr_t term_attrs(void);
1092PDCEX char *termname(void);
1093PDCEX void timeout(int);
1094PDCEX int touchline(WINDOW *, int, int);
1095PDCEX int touchwin(WINDOW *);
1096PDCEX int typeahead(int);
1097PDCEX int untouchwin(WINDOW *);
1098PDCEX void use_env(bool);
1099PDCEX int vidattr(chtype);
1100PDCEX int vid_attr(attr_t, short, void *);
1101PDCEX int vidputs(chtype, int (*)(int));
1102PDCEX int vid_puts(attr_t, short, void *, int (*)(int));
1103PDCEX int vline(chtype, int);
1104PDCEX int vw_printw(WINDOW *, const char *, va_list);
1105PDCEX int vwprintw(WINDOW *, const char *, va_list);
1106PDCEX int vw_scanw(WINDOW *, const char *, va_list);
1107PDCEX int vwscanw(WINDOW *, const char *, va_list);
1108PDCEX int waddchnstr(WINDOW *, const chtype *, int);
1109PDCEX int waddchstr(WINDOW *, const chtype *);
1110PDCEX int waddch(WINDOW *, const chtype);
1111PDCEX int waddnstr(WINDOW *, const char *, int);
1112PDCEX int waddstr(WINDOW *, const char *);
1113PDCEX int wattroff(WINDOW *, chtype);
1114PDCEX int wattron(WINDOW *, chtype);
1115PDCEX int wattrset(WINDOW *, chtype);
1116PDCEX int wattr_get(WINDOW *, attr_t *, short *, void *);
1117PDCEX int wattr_off(WINDOW *, attr_t, void *);
1118PDCEX int wattr_on(WINDOW *, attr_t, void *);
1119PDCEX int wattr_set(WINDOW *, attr_t, short, void *);
1120PDCEX void wbkgdset(WINDOW *, chtype);
1121PDCEX int wbkgd(WINDOW *, chtype);
1122PDCEX int wborder(WINDOW *, chtype, chtype, chtype, chtype,
1123 chtype, chtype, chtype, chtype);
1124PDCEX int wchgat(WINDOW *, int, attr_t, short, const void *);
1125PDCEX int wclear(WINDOW *);
1126PDCEX int wclrtobot(WINDOW *);
1127PDCEX int wclrtoeol(WINDOW *);
1128PDCEX int wcolor_set(WINDOW *, short, void *);
1129PDCEX void wcursyncup(WINDOW *);
1130PDCEX int wdelch(WINDOW *);
1131PDCEX int wdeleteln(WINDOW *);
1132PDCEX int wechochar(WINDOW *, const chtype);
1133PDCEX int werase(WINDOW *);
1134PDCEX int wgetch(WINDOW *);
1135PDCEX int wgetnstr(WINDOW *, char *, int);
1136PDCEX int wgetstr(WINDOW *, char *);
1137PDCEX int whline(WINDOW *, chtype, int);
1138PDCEX int winchnstr(WINDOW *, chtype *, int);
1139PDCEX int winchstr(WINDOW *, chtype *);
1140PDCEX chtype winch(WINDOW *);
1141PDCEX int winnstr(WINDOW *, char *, int);
1142PDCEX int winsch(WINDOW *, chtype);
1143PDCEX int winsdelln(WINDOW *, int);
1144PDCEX int winsertln(WINDOW *);
1145PDCEX int winsnstr(WINDOW *, const char *, int);
1146PDCEX int winsstr(WINDOW *, const char *);
1147PDCEX int winstr(WINDOW *, char *);
1148PDCEX int wmove(WINDOW *, int, int);
1149PDCEX int wnoutrefresh(WINDOW *);
1150PDCEX int wprintw(WINDOW *, const char *, ...);
1151PDCEX int wredrawln(WINDOW *, int, int);
1152PDCEX int wrefresh(WINDOW *);
1153PDCEX int wscanw(WINDOW *, const char *, ...);
1154PDCEX int wscrl(WINDOW *, int);
1155PDCEX int wsetscrreg(WINDOW *, int, int);
1156PDCEX int wstandend(WINDOW *);
1157PDCEX int wstandout(WINDOW *);
1158PDCEX void wsyncdown(WINDOW *);
1159PDCEX void wsyncup(WINDOW *);
1160PDCEX void wtimeout(WINDOW *, int);
1161PDCEX int wtouchln(WINDOW *, int, int, int);
1162PDCEX int wvline(WINDOW *, chtype, int);
1163
1164/* Wide-character functions */
1165
1166#ifdef PDC_WIDE
1167PDCEX int addnwstr(const wchar_t *, int);
1168PDCEX int addwstr(const wchar_t *);
1169PDCEX int add_wch(const cchar_t *);
1170PDCEX int add_wchnstr(const cchar_t *, int);
1171PDCEX int add_wchstr(const cchar_t *);
1172PDCEX int bkgrnd(const cchar_t *);
1173PDCEX void bkgrndset(const cchar_t *);
1174PDCEX int border_set(const cchar_t *, const cchar_t *, const cchar_t *,
1175 const cchar_t *, const cchar_t *, const cchar_t *,
1176 const cchar_t *, const cchar_t *);
1177PDCEX int box_set(WINDOW *, const cchar_t *, const cchar_t *);
1178PDCEX int echo_wchar(const cchar_t *);
1179PDCEX int erasewchar(wchar_t *);
1180PDCEX int getbkgrnd(cchar_t *);
1181PDCEX int getcchar(const cchar_t *, wchar_t *, attr_t *, short *, void *);
1182PDCEX int getn_wstr(wint_t *, int);
1183PDCEX int get_wch(wint_t *);
1184PDCEX int get_wstr(wint_t *);
1185PDCEX int hline_set(const cchar_t *, int);
1186PDCEX int innwstr(wchar_t *, int);
1187PDCEX int ins_nwstr(const wchar_t *, int);
1188PDCEX int ins_wch(const cchar_t *);
1189PDCEX int ins_wstr(const wchar_t *);
1190PDCEX int inwstr(wchar_t *);
1191PDCEX int in_wch(cchar_t *);
1192PDCEX int in_wchnstr(cchar_t *, int);
1193PDCEX int in_wchstr(cchar_t *);
1194PDCEX char *key_name(wchar_t);
1195PDCEX int killwchar(wchar_t *);
1196PDCEX int mvaddnwstr(int, int, const wchar_t *, int);
1197PDCEX int mvaddwstr(int, int, const wchar_t *);
1198PDCEX int mvadd_wch(int, int, const cchar_t *);
1199PDCEX int mvadd_wchnstr(int, int, const cchar_t *, int);
1200PDCEX int mvadd_wchstr(int, int, const cchar_t *);
1201PDCEX int mvgetn_wstr(int, int, wint_t *, int);
1202PDCEX int mvget_wch(int, int, wint_t *);
1203PDCEX int mvget_wstr(int, int, wint_t *);
1204PDCEX int mvhline_set(int, int, const cchar_t *, int);
1205PDCEX int mvinnwstr(int, int, wchar_t *, int);
1206PDCEX int mvins_nwstr(int, int, const wchar_t *, int);
1207PDCEX int mvins_wch(int, int, const cchar_t *);
1208PDCEX int mvins_wstr(int, int, const wchar_t *);
1209PDCEX int mvinwstr(int, int, wchar_t *);
1210PDCEX int mvin_wch(int, int, cchar_t *);
1211PDCEX int mvin_wchnstr(int, int, cchar_t *, int);
1212PDCEX int mvin_wchstr(int, int, cchar_t *);
1213PDCEX int mvvline_set(int, int, const cchar_t *, int);
1214PDCEX int mvwaddnwstr(WINDOW *, int, int, const wchar_t *, int);
1215PDCEX int mvwaddwstr(WINDOW *, int, int, const wchar_t *);
1216PDCEX int mvwadd_wch(WINDOW *, int, int, const cchar_t *);
1217PDCEX int mvwadd_wchnstr(WINDOW *, int, int, const cchar_t *, int);
1218PDCEX int mvwadd_wchstr(WINDOW *, int, int, const cchar_t *);
1219PDCEX int mvwgetn_wstr(WINDOW *, int, int, wint_t *, int);
1220PDCEX int mvwget_wch(WINDOW *, int, int, wint_t *);
1221PDCEX int mvwget_wstr(WINDOW *, int, int, wint_t *);
1222PDCEX int mvwhline_set(WINDOW *, int, int, const cchar_t *, int);
1223PDCEX int mvwinnwstr(WINDOW *, int, int, wchar_t *, int);
1224PDCEX int mvwins_nwstr(WINDOW *, int, int, const wchar_t *, int);
1225PDCEX int mvwins_wch(WINDOW *, int, int, const cchar_t *);
1226PDCEX int mvwins_wstr(WINDOW *, int, int, const wchar_t *);
1227PDCEX int mvwin_wch(WINDOW *, int, int, cchar_t *);
1228PDCEX int mvwin_wchnstr(WINDOW *, int, int, cchar_t *, int);
1229PDCEX int mvwin_wchstr(WINDOW *, int, int, cchar_t *);
1230PDCEX int mvwinwstr(WINDOW *, int, int, wchar_t *);
1231PDCEX int mvwvline_set(WINDOW *, int, int, const cchar_t *, int);
1232PDCEX int pecho_wchar(WINDOW *, const cchar_t*);
1233PDCEX int setcchar(cchar_t*, const wchar_t*, const attr_t,
1234 short, const void*);
1235PDCEX int slk_wset(int, const wchar_t *, int);
1236PDCEX int unget_wch(const wchar_t);
1237PDCEX int vline_set(const cchar_t *, int);
1238PDCEX int waddnwstr(WINDOW *, const wchar_t *, int);
1239PDCEX int waddwstr(WINDOW *, const wchar_t *);
1240PDCEX int wadd_wch(WINDOW *, const cchar_t *);
1241PDCEX int wadd_wchnstr(WINDOW *, const cchar_t *, int);
1242PDCEX int wadd_wchstr(WINDOW *, const cchar_t *);
1243PDCEX int wbkgrnd(WINDOW *, const cchar_t *);
1244PDCEX void wbkgrndset(WINDOW *, const cchar_t *);
1245PDCEX int wborder_set(WINDOW *, const cchar_t *, const cchar_t *,
1246 const cchar_t *, const cchar_t *, const cchar_t *,
1247 const cchar_t *, const cchar_t *, const cchar_t *);
1248PDCEX int wecho_wchar(WINDOW *, const cchar_t *);
1249PDCEX int wgetbkgrnd(WINDOW *, cchar_t *);
1250PDCEX int wgetn_wstr(WINDOW *, wint_t *, int);
1251PDCEX int wget_wch(WINDOW *, wint_t *);
1252PDCEX int wget_wstr(WINDOW *, wint_t *);
1253PDCEX int whline_set(WINDOW *, const cchar_t *, int);
1254PDCEX int winnwstr(WINDOW *, wchar_t *, int);
1255PDCEX int wins_nwstr(WINDOW *, const wchar_t *, int);
1256PDCEX int wins_wch(WINDOW *, const cchar_t *);
1257PDCEX int wins_wstr(WINDOW *, const wchar_t *);
1258PDCEX int winwstr(WINDOW *, wchar_t *);
1259PDCEX int win_wch(WINDOW *, cchar_t *);
1260PDCEX int win_wchnstr(WINDOW *, cchar_t *, int);
1261PDCEX int win_wchstr(WINDOW *, cchar_t *);
1262PDCEX wchar_t *wunctrl(cchar_t *);
1263PDCEX int wvline_set(WINDOW *, const cchar_t *, int);
1264#endif
1265
1266/* Quasi-standard */
1267
1268PDCEX chtype getattrs(WINDOW *);
1269PDCEX int getbegx(WINDOW *);
1270PDCEX int getbegy(WINDOW *);
1271PDCEX int getmaxx(WINDOW *);
1272PDCEX int getmaxy(WINDOW *);
1273PDCEX int getparx(WINDOW *);
1274PDCEX int getpary(WINDOW *);
1275PDCEX int getcurx(WINDOW *);
1276PDCEX int getcury(WINDOW *);
1277PDCEX void traceoff(void);
1278PDCEX void traceon(void);
1279PDCEX char *unctrl(chtype);
1280
1281PDCEX int crmode(void);
1282PDCEX int nocrmode(void);
1283PDCEX int draino(int);
1284PDCEX int resetterm(void);
1285PDCEX int fixterm(void);
1286PDCEX int saveterm(void);
1287PDCEX void setsyx(int, int);
1288
1289PDCEX int mouse_set(mmask_t);
1290PDCEX int mouse_on(mmask_t);
1291PDCEX int mouse_off(mmask_t);
1292PDCEX int request_mouse_pos(void);
1293PDCEX void wmouse_position(WINDOW *, int *, int *);
1294PDCEX mmask_t getmouse(void);
1295
1296/* ncurses */
1297
1298PDCEX int alloc_pair(int, int);
1299PDCEX int assume_default_colors(int, int);
1300PDCEX const char *curses_version(void);
1301PDCEX int find_pair(int, int);
1302PDCEX int free_pair(int);
1303PDCEX bool has_key(int);
1304PDCEX bool is_cleared(const WINDOW *);
1305PDCEX bool is_idcok(const WINDOW *);
1306PDCEX bool is_idlok(const WINDOW *);
1307PDCEX bool is_immedok(const WINDOW *);
1308PDCEX bool is_keypad(const WINDOW *);
1309PDCEX bool is_leaveok(const WINDOW *);
1310PDCEX bool is_nodelay(const WINDOW *);
1311PDCEX bool is_notimeout(const WINDOW *);
1312PDCEX bool is_pad(const WINDOW *);
1313PDCEX bool is_scrollok(const WINDOW *);
1314PDCEX bool is_subwin(const WINDOW *);
1315PDCEX bool is_syncok(const WINDOW *);
1316PDCEX int set_tabsize(int);
1317PDCEX int use_default_colors(void);
1318PDCEX int wgetdelay(const WINDOW *);
1319PDCEX WINDOW *wgetparent(const WINDOW *);
1320PDCEX int wgetscrreg(const WINDOW *, int *, int *);
1321PDCEX int wresize(WINDOW *, int, int);
1322
1323PDCEX bool has_mouse(void);
1324PDCEX int mouseinterval(int);
1325PDCEX mmask_t mousemask(mmask_t, mmask_t *);
1326PDCEX bool mouse_trafo(int *, int *, bool);
1327PDCEX int nc_getmouse(MEVENT *);
1328PDCEX int ungetmouse(MEVENT *);
1329PDCEX bool wenclose(const WINDOW *, int, int);
1330PDCEX bool wmouse_trafo(const WINDOW *, int *, int *, bool);
1331
1332/* PDCurses */
1333
1334PDCEX int addrawch(chtype);
1335PDCEX int insrawch(chtype);
1336PDCEX bool is_termresized(void);
1337PDCEX int mvaddrawch(int, int, chtype);
1338PDCEX int mvdeleteln(int, int);
1339PDCEX int mvinsertln(int, int);
1340PDCEX int mvinsrawch(int, int, chtype);
1341PDCEX int mvwaddrawch(WINDOW *, int, int, chtype);
1342PDCEX int mvwdeleteln(WINDOW *, int, int);
1343PDCEX int mvwinsertln(WINDOW *, int, int);
1344PDCEX int mvwinsrawch(WINDOW *, int, int, chtype);
1345PDCEX int raw_output(bool);
1346PDCEX int resize_term(int, int);
1347PDCEX WINDOW *resize_window(WINDOW *, int, int);
1348PDCEX int waddrawch(WINDOW *, chtype);
1349PDCEX int winsrawch(WINDOW *, chtype);
1350PDCEX char wordchar(void);
1351
1352#ifdef PDC_WIDE
1353PDCEX wchar_t *slk_wlabel(int);
1354#endif
1355
1356PDCEX void PDC_debug(const char *, ...);
1357PDCEX void PDC_get_version(PDC_VERSION *);
1358PDCEX int PDC_ungetch(int);
1359PDCEX int PDC_set_blink(bool);
1360PDCEX int PDC_set_bold(bool);
1361PDCEX int PDC_set_line_color(short);
1362PDCEX void PDC_set_title(const char *);
1363
1364PDCEX int PDC_clearclipboard(void);
1365PDCEX int PDC_freeclipboard(char *);
1366PDCEX int PDC_getclipboard(char **, long *);
1367PDCEX int PDC_setclipboard(const char *, long);
1368
1369PDCEX unsigned long PDC_get_key_modifiers(void);
1370PDCEX int PDC_return_key_modifiers(bool);
1371
1372#ifdef XCURSES
1373PDCEX WINDOW *Xinitscr(int, char **);
1374PDCEX void XCursesExit(void);
1375PDCEX int sb_init(void);
1376PDCEX int sb_set_horz(int, int, int);
1377PDCEX int sb_set_vert(int, int, int);
1378PDCEX int sb_get_horz(int *, int *, int *);
1379PDCEX int sb_get_vert(int *, int *, int *);
1380PDCEX int sb_refresh(void);
1381#endif
1382
1383/* NetBSD */
1384
1385PDCEX int touchoverlap(const WINDOW *, WINDOW *);
1386PDCEX int underend(void);
1387PDCEX int underscore(void);
1388PDCEX int wunderend(WINDOW *);
1389PDCEX int wunderscore(WINDOW *);
1390
1391/*** Functions defined as macros ***/
1392
1393/* getch() and ungetch() conflict with some DOS libraries */
1394
1395#define getch() wgetch(stdscr)
1396#define ungetch(ch) PDC_ungetch(ch)
1397
1398#define COLOR_PAIR(n) (((chtype)(n) << PDC_COLOR_SHIFT) & A_COLOR)
1399#define PAIR_NUMBER(n) (((n) & A_COLOR) >> PDC_COLOR_SHIFT)
1400
1401/* These will _only_ work as macros */
1402
1403#define getbegyx(w, y, x) (y = getbegy(w), x = getbegx(w))
1404#define getmaxyx(w, y, x) (y = getmaxy(w), x = getmaxx(w))
1405#define getparyx(w, y, x) (y = getpary(w), x = getparx(w))
1406#define getyx(w, y, x) (y = getcury(w), x = getcurx(w))
1407
1408#define getsyx(y, x) { if (curscr->_leaveit) (y)=(x)=-1; \
1409 else getyx(curscr,(y),(x)); }
1410
1411#ifdef NCURSES_MOUSE_VERSION
1412# define getmouse(x) nc_getmouse(x)
1413#endif
1414
1415/* Deprecated */
1416
1417#define PDC_save_key_modifiers(x) (OK)
1418#define PDC_get_input_fd() 0
1419
1420/* return codes from PDC_getclipboard() and PDC_setclipboard() calls */
1421
1422#define PDC_CLIP_SUCCESS 0
1423#define PDC_CLIP_ACCESS_ERROR 1
1424#define PDC_CLIP_EMPTY 2
1425#define PDC_CLIP_MEMORY_ERROR 3
1426
1427/* PDCurses key modifier masks */
1428
1429#define PDC_KEY_MODIFIER_SHIFT 1
1430#define PDC_KEY_MODIFIER_CONTROL 2
1431#define PDC_KEY_MODIFIER_ALT 4
1432#define PDC_KEY_MODIFIER_NUMLOCK 8
1433
1434#ifdef __cplusplus
1435# ifndef PDC_PP98
1436# undef bool
1437# endif
1438}
1439#endif
1440
1441#endif /* __PDCURSES__ */
diff --git a/scripts/kconfig/libcurses/curspriv.h b/scripts/kconfig/libcurses/curspriv.h
new file mode 100644
index 000000000..5a6ec1550
--- /dev/null
+++ b/scripts/kconfig/libcurses/curspriv.h
@@ -0,0 +1,133 @@
1/* Private definitions and declarations for use within PDCurses.
2 These should generally not be referenced by applications. */
3
4#ifndef __CURSES_INTERNALS__
5#define __CURSES_INTERNALS__ 1
6
7#define CURSES_LIBRARY
8#include "curses.h"
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#if defined(__TURBOC__) || defined(__EMX__) || defined(__DJGPP__) || \
15 defined(PDC_99) || defined(__WATCOMC__)
16# ifndef HAVE_VSSCANF
17# define HAVE_VSSCANF 1 /* have vsscanf() */
18# endif
19#endif
20
21#if defined(PDC_99) || defined(__WATCOMC__)
22# ifndef HAVE_SNPRINTF
23# define HAVE_SNPRINTF 1 /* have snprintf() */
24# endif
25# ifndef HAVE_VSNPRINTF
26# define HAVE_VSNPRINTF 1 /* have vsnprintf() */
27# endif
28#endif
29
30/*----------------------------------------------------------------------*/
31
32typedef struct /* structure for ripped off lines */
33{
34 int line;
35 int (*init)(WINDOW *, int);
36} RIPPEDOFFLINE;
37
38/* Window properties */
39
40#define _SUBWIN 0x01 /* window is a subwindow */
41#define _PAD 0x10 /* X/Open Pad. */
42#define _SUBPAD 0x20 /* X/Open subpad. */
43
44/* Miscellaneous */
45
46#define _NO_CHANGE -1 /* flags line edge unchanged */
47
48#define _ECHAR 0x08 /* Erase char (^H) */
49#define _DWCHAR 0x17 /* Delete Word char (^W) */
50#define _DLCHAR 0x15 /* Delete Line char (^U) */
51
52/*----------------------------------------------------------------------*/
53
54/* Platform implementation functions */
55
56void PDC_beep(void);
57bool PDC_can_change_color(void);
58int PDC_color_content(short, short *, short *, short *);
59bool PDC_check_key(void);
60int PDC_curs_set(int);
61void PDC_doupdate(void);
62void PDC_flushinp(void);
63int PDC_get_columns(void);
64int PDC_get_cursor_mode(void);
65int PDC_get_key(void);
66int PDC_get_rows(void);
67void PDC_gotoyx(int, int);
68bool PDC_has_mouse(void);
69int PDC_init_color(short, short, short, short);
70int PDC_modifiers_set(void);
71int PDC_mouse_set(void);
72void PDC_napms(int);
73void PDC_reset_prog_mode(void);
74void PDC_reset_shell_mode(void);
75int PDC_resize_screen(int, int);
76void PDC_restore_screen_mode(int);
77void PDC_save_screen_mode(int);
78#ifdef XCURSES
79void PDC_set_args(int, char **);
80#endif
81void PDC_scr_close(void);
82void PDC_scr_free(void);
83int PDC_scr_open(void);
84void PDC_set_keyboard_binary(bool);
85void PDC_transform_line(int, int, int, const chtype *);
86const char *PDC_sysname(void);
87
88/* Internal cross-module functions */
89
90void PDC_init_atrtab(void);
91WINDOW *PDC_makelines(WINDOW *);
92WINDOW *PDC_makenew(int, int, int, int);
93int PDC_mouse_in_slk(int, int);
94void PDC_slk_free(void);
95void PDC_slk_initialize(void);
96void PDC_sync(WINDOW *);
97
98#ifdef PDC_WIDE
99int PDC_mbtowc(wchar_t *, const char *, size_t);
100size_t PDC_mbstowcs(wchar_t *, const char *, size_t);
101size_t PDC_wcstombs(char *, const wchar_t *, size_t);
102#endif
103
104#ifdef PDCDEBUG
105# define PDC_LOG(x) if (SP && SP->dbfp) PDC_debug x
106#else
107# define PDC_LOG(x)
108#endif
109
110/* Internal macros for attributes */
111
112#ifndef max
113# define max(a,b) (((a) > (b)) ? (a) : (b))
114#endif
115#ifndef min
116# define min(a,b) (((a) < (b)) ? (a) : (b))
117#endif
118
119#define DIVROUND(num, divisor) ((num) + ((divisor) >> 1)) / (divisor)
120
121#define PDC_CLICK_PERIOD 150 /* time to wait for a click, if
122 not set by mouseinterval() */
123#define PDC_COLOR_PAIRS 256
124#define PDC_MAXCOL 768 /* maximum possible COLORS; may be less */
125
126#define _INBUFSIZ 512 /* size of terminal input buffer */
127#define NUNGETCH 256 /* max # chars to ungetch() */
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* __CURSES_INTERNALS__ */
diff --git a/scripts/kconfig/libcurses/getch.c b/scripts/kconfig/libcurses/getch.c
new file mode 100644
index 000000000..9d771ec0e
--- /dev/null
+++ b/scripts/kconfig/libcurses/getch.c
@@ -0,0 +1,591 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7getch
8-----
9
10### Synopsis
11
12 int getch(void);
13 int wgetch(WINDOW *win);
14 int mvgetch(int y, int x);
15 int mvwgetch(WINDOW *win, int y, int x);
16 int ungetch(int ch);
17 int flushinp(void);
18
19 int get_wch(wint_t *wch);
20 int wget_wch(WINDOW *win, wint_t *wch);
21 int mvget_wch(int y, int x, wint_t *wch);
22 int mvwget_wch(WINDOW *win, int y, int x, wint_t *wch);
23 int unget_wch(const wchar_t wch);
24
25 unsigned long PDC_get_key_modifiers(void);
26 int PDC_return_key_modifiers(bool flag);
27
28### Description
29
30 With the getch(), wgetch(), mvgetch(), and mvwgetch() functions, a
31 character is read from the terminal associated with the window. In
32 nodelay mode, if there is no input waiting, the value ERR is
33 returned. In delay mode, the program will hang until the system
34 passes text through to the program. Depending on the setting of
35 cbreak(), this will be after one character or after the first
36 newline. Unless noecho() has been set, the character will also be
37 echoed into the designated window.
38
39 If keypad() is TRUE, and a function key is pressed, the token for
40 that function key will be returned instead of the raw characters.
41 Possible function keys are defined in "curses.h" with integers
42 beginning with 0401, whose names begin with KEY_.
43
44 If nodelay(win, TRUE) has been called on the window and no input is
45 waiting, the value ERR is returned.
46
47 ungetch() places ch back onto the input queue to be returned by the
48 next call to wgetch().
49
50 flushinp() throws away any type-ahead that has been typed by the user
51 and has not yet been read by the program.
52
53 wget_wch() is the wide-character version of wgetch(), available when
54 PDCurses is built with the PDC_WIDE option. It takes a pointer to a
55 wint_t rather than returning the key as an int, and instead returns
56 KEY_CODE_YES if the key is a function key. Otherwise, it returns OK
57 or ERR. It's important to check for KEY_CODE_YES, since regular wide
58 characters can have the same values as function key codes.
59
60 unget_wch() puts a wide character on the input queue.
61
62 PDC_get_key_modifiers() returns the keyboard modifiers (shift,
63 control, alt, numlock) effective at the time of the last getch()
64 call. Use the macros PDC_KEY_MODIFIER_* to determine which
65 modifier(s) were set. PDC_return_key_modifiers() tells getch() to
66 return modifier keys pressed alone as keystrokes (KEY_ALT_L, etc.).
67 These may not work on all platforms.
68
69 NOTE: getch() and ungetch() are implemented as macros, to avoid
70 conflict with many DOS compiler's runtime libraries.
71
72### Return Value
73
74 These functions return ERR or the value of the character, meta
75 character or function key token.
76
77### Portability
78
79 Function | X/Open | ncurses | NetBSD
80 :---------------------|:------:|:-------:|:------:
81 getch | Y | Y | Y
82 wgetch | Y | Y | Y
83 mvgetch | Y | Y | Y
84 mvwgetch | Y | Y | Y
85 ungetch | Y | Y | Y
86 flushinp | Y | Y | Y
87 get_wch | Y | Y | Y
88 wget_wch | Y | Y | Y
89 mvget_wch | Y | Y | Y
90 mvwget_wch | Y | Y | Y
91 unget_wch | Y | Y | Y
92 PDC_get_key_modifiers | - | - | -
93
94**man-end****************************************************************/
95
96#include <stdlib.h>
97
98static int _get_box(int *y_start, int *y_end, int *x_start, int *x_end)
99{
100 int start, end;
101
102 if (SP->sel_start < SP->sel_end)
103 {
104 start = SP->sel_start;
105 end = SP->sel_end;
106 }
107 else
108 {
109 start = SP->sel_end;
110 end = SP->sel_start;
111 }
112
113 *y_start = start / COLS;
114 *x_start = start % COLS;
115
116 *y_end = end / COLS;
117 *x_end = end % COLS;
118
119 return (end - start) + (*y_end - *y_start);
120}
121
122static void _highlight(void)
123{
124 int i, j, y_start, y_end, x_start, x_end;
125
126 if (-1 == SP->sel_start)
127 return;
128
129 _get_box(&y_start, &y_end, &x_start, &x_end);
130
131 for (j = y_start; j <= y_end; j++)
132 for (i = (j == y_start ? x_start : 0);
133 i < (j == y_end ? x_end : COLS); i++)
134 curscr->_y[j][i] ^= A_REVERSE;
135
136 wrefresh(curscr);
137}
138
139static void _copy(void)
140{
141#ifdef PDC_WIDE
142 wchar_t *wtmp;
143# define TMP wtmp
144# define MASK A_CHARTEXT
145#else
146# define TMP tmp
147# define MASK 0xff
148#endif
149 char *tmp;
150 long pos;
151 int i, j, y_start, y_end, x_start, x_end, len;
152
153 if (-1 == SP->sel_start)
154 return;
155
156 len = _get_box(&y_start, &y_end, &x_start, &x_end);
157
158 if (!len)
159 return;
160
161#ifdef PDC_WIDE
162 wtmp = malloc((len + 1) * sizeof(wchar_t));
163 len *= 4;
164#endif
165 tmp = malloc(len + 1);
166
167 for (j = y_start, pos = 0; j <= y_end; j++)
168 {
169 for (i = (j == y_start ? x_start : 0);
170 i < (j == y_end ? x_end : COLS); i++)
171 TMP[pos++] = curscr->_y[j][i] & MASK;
172
173 while (y_start != y_end && pos > 0 && TMP[pos - 1] == 32)
174 pos--;
175
176 if (j < y_end)
177 TMP[pos++] = 10;
178 }
179 TMP[pos] = 0;
180
181#ifdef PDC_WIDE
182 pos = PDC_wcstombs(tmp, wtmp, len);
183#endif
184
185 PDC_setclipboard(tmp, pos);
186 free(tmp);
187#ifdef PDC_WIDE
188 free(wtmp);
189#endif
190}
191
192static int _paste(void)
193{
194#ifdef PDC_WIDE
195 wchar_t *wpaste;
196# define PASTE wpaste
197#else
198# define PASTE paste
199#endif
200 char *paste;
201 long len, newmax;
202 int key;
203
204 key = PDC_getclipboard(&paste, &len);
205 if (PDC_CLIP_SUCCESS != key || !len)
206 return -1;
207
208#ifdef PDC_WIDE
209 wpaste = malloc(len * sizeof(wchar_t));
210 len = PDC_mbstowcs(wpaste, paste, len);
211#endif
212 newmax = len + SP->c_ungind;
213 if (newmax > SP->c_ungmax)
214 {
215 SP->c_ungch = realloc(SP->c_ungch, newmax * sizeof(int));
216 if (!SP->c_ungch)
217 return -1;
218 SP->c_ungmax = newmax;
219 }
220 while (len > 1)
221 PDC_ungetch(PASTE[--len]);
222 key = *PASTE;
223#ifdef PDC_WIDE
224 free(wpaste);
225#endif
226 PDC_freeclipboard(paste);
227 SP->key_modifiers = 0;
228
229 return key;
230}
231
232static int _mouse_key(void)
233{
234 int i, key = KEY_MOUSE, changes = SP->mouse_status.changes;
235 unsigned long mbe = SP->_trap_mbe;
236
237 /* Selection highlighting? */
238
239 if ((!mbe || SP->mouse_status.button[0] & BUTTON_SHIFT) && changes & 1)
240 {
241 i = SP->mouse_status.y * COLS + SP->mouse_status.x;
242 switch (SP->mouse_status.button[0] & BUTTON_ACTION_MASK)
243 {
244 case BUTTON_PRESSED:
245 _highlight();
246 SP->sel_start = SP->sel_end = i;
247 return -1;
248 case BUTTON_MOVED:
249 _highlight();
250 SP->sel_end = i;
251 _highlight();
252 return -1;
253 case BUTTON_RELEASED:
254 _copy();
255 return -1;
256 }
257 }
258 else if ((!mbe || SP->mouse_status.button[1] & BUTTON_SHIFT) &&
259 changes & 2 && (SP->mouse_status.button[1] &
260 BUTTON_ACTION_MASK) == BUTTON_CLICKED)
261 {
262 SP->key_code = FALSE;
263 return _paste();
264 }
265
266 /* Filter unwanted mouse events */
267
268 for (i = 0; i < 3; i++)
269 {
270 if (changes & (1 << i))
271 {
272 int shf = i * 5;
273 short button = SP->mouse_status.button[i] & BUTTON_ACTION_MASK;
274
275 if ( (!(mbe & (BUTTON1_PRESSED << shf)) &&
276 (button == BUTTON_PRESSED))
277
278 || (!(mbe & (BUTTON1_CLICKED << shf)) &&
279 (button == BUTTON_CLICKED))
280
281 || (!(mbe & (BUTTON1_DOUBLE_CLICKED << shf)) &&
282 (button == BUTTON_DOUBLE_CLICKED))
283
284 || (!(mbe & (BUTTON1_MOVED << shf)) &&
285 (button == BUTTON_MOVED))
286
287 || (!(mbe & (BUTTON1_RELEASED << shf)) &&
288 (button == BUTTON_RELEASED))
289 )
290 SP->mouse_status.changes ^= (1 << i);
291 }
292 }
293
294 if (changes & PDC_MOUSE_MOVED)
295 {
296 if (!(mbe & (BUTTON1_MOVED|BUTTON2_MOVED|BUTTON3_MOVED)))
297 SP->mouse_status.changes ^= PDC_MOUSE_MOVED;
298 }
299
300 if (changes & (PDC_MOUSE_WHEEL_UP|PDC_MOUSE_WHEEL_DOWN))
301 {
302 if (!(mbe & MOUSE_WHEEL_SCROLL))
303 SP->mouse_status.changes &=
304 ~(PDC_MOUSE_WHEEL_UP|PDC_MOUSE_WHEEL_DOWN);
305 }
306
307 if (!changes)
308 return -1;
309
310 /* Check for click in slk area */
311
312 i = PDC_mouse_in_slk(SP->mouse_status.y, SP->mouse_status.x);
313
314 if (i)
315 {
316 if (SP->mouse_status.button[0] & (BUTTON_PRESSED|BUTTON_CLICKED))
317 key = KEY_F(i);
318 else
319 key = -1;
320 }
321
322 return key;
323}
324
325int wgetch(WINDOW *win)
326{
327 int key, waitcount;
328
329 PDC_LOG(("wgetch() - called\n"));
330
331 if (!win || !SP)
332 return ERR;
333
334 waitcount = 0;
335
336 /* set the number of 1/20th second napms() calls */
337
338 if (SP->delaytenths)
339 waitcount = 2 * SP->delaytenths;
340 else
341 if (win->_delayms)
342 {
343 /* Can't really do millisecond intervals, so delay in
344 1/20ths of a second (50ms) */
345
346 waitcount = win->_delayms / 50;
347 if (!waitcount)
348 waitcount = 1;
349 }
350
351 /* refresh window when wgetch is called if there have been changes
352 to it and it is not a pad */
353
354 if (!(win->_flags & _PAD) && ((!win->_leaveit &&
355 (win->_begx + win->_curx != SP->curscol ||
356 win->_begy + win->_cury != SP->cursrow)) || is_wintouched(win)))
357 wrefresh(win);
358
359 /* if ungotten char exists, remove and return it */
360
361 if (SP->c_ungind)
362 return SP->c_ungch[--(SP->c_ungind)];
363
364 /* if normal and data in buffer */
365
366 if ((!SP->raw_inp && !SP->cbreak) && (SP->c_gindex < SP->c_pindex))
367 return SP->c_buffer[SP->c_gindex++];
368
369 /* prepare to buffer data */
370
371 SP->c_pindex = 0;
372 SP->c_gindex = 0;
373
374 /* to get here, no keys are buffered. go and get one. */
375
376 for (;;) /* loop for any buffering */
377 {
378 /* is there a keystroke ready? */
379
380 if (!PDC_check_key())
381 {
382 /* if not, handle timeout() and halfdelay() */
383
384 if (SP->delaytenths || win->_delayms)
385 {
386 if (!waitcount)
387 return ERR;
388
389 waitcount--;
390 }
391 else
392 if (win->_nodelay)
393 return ERR;
394
395 napms(50); /* sleep for 1/20th second */
396 continue; /* then check again */
397 }
398
399 /* if there is, fetch it */
400
401 key = PDC_get_key();
402
403 /* copy or paste? */
404
405 if (SP->key_modifiers & PDC_KEY_MODIFIER_SHIFT)
406 {
407 if (0x03 == key)
408 {
409 _copy();
410 continue;
411 }
412 else if (0x16 == key)
413 key = _paste();
414 }
415
416 /* filter mouse events; translate mouse clicks in the slk
417 area to function keys */
418
419 if (SP->key_code && key == KEY_MOUSE)
420 key = _mouse_key();
421
422 /* filter special keys if not in keypad mode */
423
424 if (SP->key_code && !win->_use_keypad)
425 key = -1;
426
427 /* unwanted key? loop back */
428
429 if (key == -1)
430 continue;
431
432 _highlight();
433 SP->sel_start = SP->sel_end = -1;
434
435 /* translate CR */
436
437 if (key == '\r' && SP->autocr && !SP->raw_inp)
438 key = '\n';
439
440 /* if echo is enabled */
441
442 if (SP->echo && !SP->key_code)
443 {
444 waddch(win, key);
445 wrefresh(win);
446 }
447
448 /* if no buffering */
449
450 if (SP->raw_inp || SP->cbreak)
451 return key;
452
453 /* if no overflow, put data in buffer */
454
455 if (key == '\b')
456 {
457 if (SP->c_pindex > SP->c_gindex)
458 SP->c_pindex--;
459 }
460 else
461 if (SP->c_pindex < _INBUFSIZ - 2)
462 SP->c_buffer[SP->c_pindex++] = key;
463
464 /* if we got a line */
465
466 if (key == '\n' || key == '\r')
467 return SP->c_buffer[SP->c_gindex++];
468 }
469}
470
471int mvgetch(int y, int x)
472{
473 PDC_LOG(("mvgetch() - called\n"));
474
475 if (move(y, x) == ERR)
476 return ERR;
477
478 return wgetch(stdscr);
479}
480
481int mvwgetch(WINDOW *win, int y, int x)
482{
483 PDC_LOG(("mvwgetch() - called\n"));
484
485 if (wmove(win, y, x) == ERR)
486 return ERR;
487
488 return wgetch(win);
489}
490
491int PDC_ungetch(int ch)
492{
493 PDC_LOG(("ungetch() - called\n"));
494
495 if (SP->c_ungind >= SP->c_ungmax) /* pushback stack full */
496 return ERR;
497
498 SP->c_ungch[SP->c_ungind++] = ch;
499
500 return OK;
501}
502
503int flushinp(void)
504{
505 PDC_LOG(("flushinp() - called\n"));
506
507 if (!SP)
508 return ERR;
509
510 PDC_flushinp();
511
512 SP->c_gindex = 1; /* set indices to kill buffer */
513 SP->c_pindex = 0;
514 SP->c_ungind = 0; /* clear SP->c_ungch array */
515
516 return OK;
517}
518
519unsigned long PDC_get_key_modifiers(void)
520{
521 PDC_LOG(("PDC_get_key_modifiers() - called\n"));
522
523 if (!SP)
524 return ERR;
525
526 return SP->key_modifiers;
527}
528
529int PDC_return_key_modifiers(bool flag)
530{
531 PDC_LOG(("PDC_return_key_modifiers() - called\n"));
532
533 if (!SP)
534 return ERR;
535
536 SP->return_key_modifiers = flag;
537 return PDC_modifiers_set();
538}
539
540#ifdef PDC_WIDE
541int wget_wch(WINDOW *win, wint_t *wch)
542{
543 int key;
544
545 PDC_LOG(("wget_wch() - called\n"));
546
547 if (!wch)
548 return ERR;
549
550 key = wgetch(win);
551
552 if (key == ERR)
553 return ERR;
554
555 *wch = key;
556
557 return SP->key_code ? KEY_CODE_YES : OK;
558}
559
560int get_wch(wint_t *wch)
561{
562 PDC_LOG(("get_wch() - called\n"));
563
564 return wget_wch(stdscr, wch);
565}
566
567int mvget_wch(int y, int x, wint_t *wch)
568{
569 PDC_LOG(("mvget_wch() - called\n"));
570
571 if (move(y, x) == ERR)
572 return ERR;
573
574 return wget_wch(stdscr, wch);
575}
576
577int mvwget_wch(WINDOW *win, int y, int x, wint_t *wch)
578{
579 PDC_LOG(("mvwget_wch() - called\n"));
580
581 if (wmove(win, y, x) == ERR)
582 return ERR;
583
584 return wget_wch(win, wch);
585}
586
587int unget_wch(const wchar_t wch)
588{
589 return PDC_ungetch(wch);
590}
591#endif
diff --git a/scripts/kconfig/libcurses/getyx.c b/scripts/kconfig/libcurses/getyx.c
new file mode 100644
index 000000000..6aa894ed0
--- /dev/null
+++ b/scripts/kconfig/libcurses/getyx.c
@@ -0,0 +1,144 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7getyx
8-----
9
10### Synopsis
11
12 void getyx(WINDOW *win, int y, int x);
13 void getparyx(WINDOW *win, int y, int x);
14 void getbegyx(WINDOW *win, int y, int x);
15 void getmaxyx(WINDOW *win, int y, int x);
16
17 void getsyx(int y, int x);
18 void setsyx(int y, int x);
19
20 int getbegy(WINDOW *win);
21 int getbegx(WINDOW *win);
22 int getcury(WINDOW *win);
23 int getcurx(WINDOW *win);
24 int getpary(WINDOW *win);
25 int getparx(WINDOW *win);
26 int getmaxy(WINDOW *win);
27 int getmaxx(WINDOW *win);
28
29### Description
30
31 The getyx() macro (defined in curses.h -- the prototypes here are
32 merely illustrative) puts the current cursor position of the
33 specified window into y and x. getbegyx() and getmaxyx() return the
34 starting coordinates and size of the specified window, respectively.
35 getparyx() returns the starting coordinates of the parent's window,
36 if the specified window is a subwindow; otherwise it sets y and x to
37 -1. These are all macros.
38
39 getsyx() gets the coordinates of the virtual screen cursor, and
40 stores them in y and x. If leaveok() is TRUE, it returns -1, -1. If
41 lines have been removed with ripoffline(), then getsyx() includes
42 these lines in its count; so, the returned y and x values should only
43 be used with setsyx().
44
45 setsyx() sets the virtual screen cursor to the y, x coordinates. If
46 either y or x is -1, leaveok() is set TRUE, else it's set FALSE.
47
48 getsyx() and setsyx() are meant to be used by a library routine that
49 manipulates curses windows without altering the position of the
50 cursor. Note that getsyx() is defined only as a macro.
51
52 getbegy(), getbegx(), getcurx(), getcury(), getmaxy(), getmaxx(),
53 getpary(), and getparx() return the appropriate coordinate or size
54 values, or ERR in the case of a NULL window.
55
56### Portability
57
58 Function | X/Open | ncurses | NetBSD
59 :---------------------|:------:|:-------:|:------:
60 getyx | Y | Y | Y
61 getparyx | Y | Y | Y
62 getbegyx | Y | Y | Y
63 getmaxyx | Y | Y | Y
64 getsyx | - | Y | Y
65 setsyx | - | Y | Y
66 getbegy | - | Y | Y
67 getbegx | - | Y | Y
68 getcury | - | Y | Y
69 getcurx | - | Y | Y
70 getpary | - | Y | Y
71 getparx | - | Y | Y
72 getmaxy | - | Y | Y
73 getmaxx | - | Y | Y
74
75**man-end****************************************************************/
76
77int getbegy(WINDOW *win)
78{
79 PDC_LOG(("getbegy() - called\n"));
80
81 return win ? win->_begy : ERR;
82}
83
84int getbegx(WINDOW *win)
85{
86 PDC_LOG(("getbegx() - called\n"));
87
88 return win ? win->_begx : ERR;
89}
90
91int getcury(WINDOW *win)
92{
93 PDC_LOG(("getcury() - called\n"));
94
95 return win ? win->_cury : ERR;
96}
97
98int getcurx(WINDOW *win)
99{
100 PDC_LOG(("getcurx() - called\n"));
101
102 return win ? win->_curx : ERR;
103}
104
105int getpary(WINDOW *win)
106{
107 PDC_LOG(("getpary() - called\n"));
108
109 return win ? win->_pary : ERR;
110}
111
112int getparx(WINDOW *win)
113{
114 PDC_LOG(("getparx() - called\n"));
115
116 return win ? win->_parx : ERR;
117}
118
119int getmaxy(WINDOW *win)
120{
121 PDC_LOG(("getmaxy() - called\n"));
122
123 return win ? win->_maxy : ERR;
124}
125
126int getmaxx(WINDOW *win)
127{
128 PDC_LOG(("getmaxx() - called\n"));
129
130 return win ? win->_maxx : ERR;
131}
132
133void setsyx(int y, int x)
134{
135 PDC_LOG(("setsyx() - called\n"));
136
137 if (curscr)
138 {
139 curscr->_leaveit = y == -1 || x == -1;
140
141 if (!curscr->_leaveit)
142 wmove(curscr, y, x);
143 }
144}
diff --git a/scripts/kconfig/libcurses/inch.c b/scripts/kconfig/libcurses/inch.c
new file mode 100644
index 000000000..28b57e222
--- /dev/null
+++ b/scripts/kconfig/libcurses/inch.c
@@ -0,0 +1,128 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7inch
8----
9
10### Synopsis
11
12 chtype inch(void);
13 chtype winch(WINDOW *win);
14 chtype mvinch(int y, int x);
15 chtype mvwinch(WINDOW *win, int y, int x);
16
17 int in_wch(cchar_t *wcval);
18 int win_wch(WINDOW *win, cchar_t *wcval);
19 int mvin_wch(int y, int x, cchar_t *wcval);
20 int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval);
21
22### Description
23
24 The inch() functions retrieve the character and attribute from the
25 current or specified window position, in the form of a chtype. If a
26 NULL window is specified, (chtype)ERR is returned.
27
28 The in_wch() functions are the wide-character versions; instead of
29 returning a chtype, they store a cchar_t at the address specified by
30 wcval, and return OK or ERR. (No value is stored when ERR is
31 returned.) Note that in PDCurses, chtype and cchar_t are the same.
32
33### Portability
34
35 Function | X/Open | ncurses | NetBSD
36 :---------------------|:------:|:-------:|:------:
37 inch | Y | Y | Y
38 winch | Y | Y | Y
39 mvinch | Y | Y | Y
40 mvwinch | Y | Y | Y
41 in_wch | Y | Y | Y
42 win_wch | Y | Y | Y
43 mvin_wch | Y | Y | Y
44 mvwin_wch | Y | Y | Y
45
46**man-end****************************************************************/
47
48chtype winch(WINDOW *win)
49{
50 PDC_LOG(("winch() - called\n"));
51
52 if (!win)
53 return (chtype)ERR;
54
55 return win->_y[win->_cury][win->_curx];
56}
57
58chtype inch(void)
59{
60 PDC_LOG(("inch() - called\n"));
61
62 return winch(stdscr);
63}
64
65chtype mvinch(int y, int x)
66{
67 PDC_LOG(("mvinch() - called\n"));
68
69 if (move(y, x) == ERR)
70 return (chtype)ERR;
71
72 return stdscr->_y[stdscr->_cury][stdscr->_curx];
73}
74
75chtype mvwinch(WINDOW *win, int y, int x)
76{
77 PDC_LOG(("mvwinch() - called\n"));
78
79 if (wmove(win, y, x) == ERR)
80 return (chtype)ERR;
81
82 return win->_y[win->_cury][win->_curx];
83}
84
85#ifdef PDC_WIDE
86int win_wch(WINDOW *win, cchar_t *wcval)
87{
88 PDC_LOG(("win_wch() - called\n"));
89
90 if (!win || !wcval)
91 return ERR;
92
93 *wcval = win->_y[win->_cury][win->_curx];
94
95 return OK;
96}
97
98int in_wch(cchar_t *wcval)
99{
100 PDC_LOG(("in_wch() - called\n"));
101
102 return win_wch(stdscr, wcval);
103}
104
105int mvin_wch(int y, int x, cchar_t *wcval)
106{
107 PDC_LOG(("mvin_wch() - called\n"));
108
109 if (!wcval || (move(y, x) == ERR))
110 return ERR;
111
112 *wcval = stdscr->_y[stdscr->_cury][stdscr->_curx];
113
114 return OK;
115}
116
117int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval)
118{
119 PDC_LOG(("mvwin_wch() - called\n"));
120
121 if (!wcval || (wmove(win, y, x) == ERR))
122 return ERR;
123
124 *wcval = win->_y[win->_cury][win->_curx];
125
126 return OK;
127}
128#endif
diff --git a/scripts/kconfig/libcurses/initscr.c b/scripts/kconfig/libcurses/initscr.c
new file mode 100644
index 000000000..a4208642a
--- /dev/null
+++ b/scripts/kconfig/libcurses/initscr.c
@@ -0,0 +1,433 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7initscr
8-------
9
10### Synopsis
11
12 WINDOW *initscr(void);
13 WINDOW *Xinitscr(int argc, char **argv);
14 int endwin(void);
15 bool isendwin(void);
16 SCREEN *newterm(const char *type, FILE *outfd, FILE *infd);
17 SCREEN *set_term(SCREEN *new);
18 void delscreen(SCREEN *sp);
19
20 int resize_term(int nlines, int ncols);
21 bool is_termresized(void);
22 const char *curses_version(void);
23 void PDC_get_version(PDC_VERSION *ver);
24
25 int set_tabsize(int tabsize);
26
27### Description
28
29 initscr() should be the first curses routine called. It will
30 initialize all curses data structures, and arrange that the first
31 call to refresh() will clear the screen. In case of error, initscr()
32 will write a message to standard error and end the program.
33
34 endwin() should be called before exiting or escaping from curses mode
35 temporarily. It will restore tty modes, move the cursor to the lower
36 left corner of the screen and reset the terminal into the proper
37 non-visual mode. To resume curses after a temporary escape, call
38 refresh() or doupdate().
39
40 isendwin() returns TRUE if endwin() has been called without a
41 subsequent refresh, unless SP is NULL.
42
43 In some implementations of curses, newterm() allows the use of
44 multiple terminals. Here, it's just an alternative interface for
45 initscr(). It always returns SP, or NULL.
46
47 delscreen() frees the memory allocated by newterm() or initscr(),
48 since it's not freed by endwin(). This function is usually not
49 needed. In PDCurses, the parameter must be the value of SP, and
50 delscreen() sets SP to NULL.
51
52 set_term() does nothing meaningful in PDCurses, but is included for
53 compatibility with other curses implementations.
54
55 resize_term() is effectively two functions: When called with nonzero
56 values for nlines and ncols, it attempts to resize the screen to the
57 given size. When called with (0, 0), it merely adjusts the internal
58 structures to match the current size after the screen is resized by
59 the user. On the currently supported platforms, SDL, Windows console,
60 and X11 allow user resizing, while DOS, OS/2, SDL and Windows console
61 allow programmatic resizing. If you want to support user resizing,
62 you should check for getch() returning KEY_RESIZE, and/or call
63 is_termresized() at appropriate times; if either condition occurs,
64 call resize_term(0, 0). Then, with either user or programmatic
65 resizing, you'll have to resize any windows you've created, as
66 appropriate; resize_term() only handles stdscr and curscr.
67
68 is_termresized() returns TRUE if the curses screen has been resized
69 by the user, and a call to resize_term() is needed. Checking for
70 KEY_RESIZE is generally preferable, unless you're not handling the
71 keyboard.
72
73 curses_version() returns a string describing the version of PDCurses.
74
75 PDC_get_version() fills a PDC_VERSION structure provided by the user
76 with more detailed version info (see curses.h).
77
78 set_tabsize() sets the tab interval, stored in TABSIZE.
79
80### Return Value
81
82 All functions return NULL on error, except endwin(), which always
83 returns OK, and resize_term(), which returns either OK or ERR.
84
85### Portability
86
87 Function | X/Open | ncurses | NetBSD
88 :---------------------|:------:|:-------:|:------:
89 initscr | Y | Y | Y
90 endwin | Y | Y | Y
91 isendwin | Y | Y | Y
92 newterm | Y | Y | Y
93 set_term | Y | Y | Y
94 delscreen | Y | Y | Y
95 resize_term | - | Y | Y
96 set_tabsize | - | Y | Y
97 curses_version | - | Y | -
98 is_termresized | - | - | -
99
100**man-end****************************************************************/
101
102#include <stdlib.h>
103
104char ttytype[128];
105
106const char *_curses_notice = "PDCurses " PDC_VERDOT " - " __DATE__;
107
108SCREEN *SP = (SCREEN*)NULL; /* curses variables */
109WINDOW *curscr = (WINDOW *)NULL; /* the current screen image */
110WINDOW *stdscr = (WINDOW *)NULL; /* the default screen window */
111
112int LINES = 0; /* current terminal height */
113int COLS = 0; /* current terminal width */
114int TABSIZE = 8;
115
116MOUSE_STATUS Mouse_status;
117
118extern RIPPEDOFFLINE linesripped[5];
119extern char linesrippedoff;
120
121WINDOW *initscr(void)
122{
123 int i;
124
125 PDC_LOG(("initscr() - called\n"));
126
127 if (SP && SP->alive)
128 return NULL;
129
130 SP = calloc(1, sizeof(SCREEN));
131 if (!SP)
132 return NULL;
133
134 if (PDC_scr_open() == ERR)
135 {
136 fprintf(stderr, "initscr(): Unable to create SP\n");
137 exit(8);
138 }
139
140 SP->autocr = TRUE; /* cr -> lf by default */
141 SP->raw_out = FALSE; /* tty I/O modes */
142 SP->raw_inp = FALSE; /* tty I/O modes */
143 SP->cbreak = TRUE;
144 SP->key_modifiers = 0L;
145 SP->return_key_modifiers = FALSE;
146 SP->echo = TRUE;
147 SP->visibility = 1;
148 SP->resized = FALSE;
149 SP->_trap_mbe = 0L;
150 SP->linesrippedoff = 0;
151 SP->linesrippedoffontop = 0;
152 SP->delaytenths = 0;
153 SP->line_color = -1;
154 SP->lastscr = (WINDOW *)NULL;
155 SP->dbfp = NULL;
156 SP->color_started = FALSE;
157 SP->dirty = FALSE;
158 SP->sel_start = -1;
159 SP->sel_end = -1;
160
161 SP->orig_cursor = PDC_get_cursor_mode();
162
163 LINES = SP->lines = PDC_get_rows();
164 COLS = SP->cols = PDC_get_columns();
165
166 if (LINES < 2 || COLS < 2)
167 {
168 fprintf(stderr, "initscr(): LINES=%d COLS=%d: too small.\n",
169 LINES, COLS);
170 exit(4);
171 }
172
173 curscr = newwin(LINES, COLS, 0, 0);
174 if (!curscr)
175 {
176 fprintf(stderr, "initscr(): Unable to create curscr.\n");
177 exit(2);
178 }
179
180 SP->lastscr = newwin(LINES, COLS, 0, 0);
181 if (!SP->lastscr)
182 {
183 fprintf(stderr, "initscr(): Unable to create SP->lastscr.\n");
184 exit(2);
185 }
186
187 wattrset(SP->lastscr, (chtype)(-1));
188 werase(SP->lastscr);
189
190 PDC_slk_initialize();
191 LINES -= SP->slklines;
192
193 /* We have to sort out ripped off lines here, and reduce the height
194 of stdscr by the number of lines ripped off */
195
196 for (i = 0; i < linesrippedoff; i++)
197 {
198 if (linesripped[i].line < 0)
199 (*linesripped[i].init)(newwin(1, COLS, LINES - 1, 0), COLS);
200 else
201 (*linesripped[i].init)(newwin(1, COLS,
202 SP->linesrippedoffontop++, 0), COLS);
203
204 SP->linesrippedoff++;
205 LINES--;
206 }
207
208 linesrippedoff = 0;
209
210 stdscr = newwin(LINES, COLS, SP->linesrippedoffontop, 0);
211 if (!stdscr)
212 {
213 fprintf(stderr, "initscr(): Unable to create stdscr.\n");
214 exit(1);
215 }
216
217 wclrtobot(stdscr);
218
219 /* If preserving the existing screen, don't allow a screen clear */
220
221 if (SP->_preserve)
222 {
223 untouchwin(curscr);
224 untouchwin(stdscr);
225 stdscr->_clear = FALSE;
226 curscr->_clear = FALSE;
227 }
228 else
229 curscr->_clear = TRUE;
230
231 SP->atrtab = calloc(PDC_COLOR_PAIRS, sizeof(PDC_PAIR));
232 if (!SP->atrtab)
233 return NULL;
234 PDC_init_atrtab(); /* set up default colors */
235
236 MOUSE_X_POS = MOUSE_Y_POS = -1;
237 BUTTON_STATUS(1) = BUTTON_RELEASED;
238 BUTTON_STATUS(2) = BUTTON_RELEASED;
239 BUTTON_STATUS(3) = BUTTON_RELEASED;
240 Mouse_status.changes = 0;
241
242 SP->alive = TRUE;
243
244 def_shell_mode();
245
246 sprintf(ttytype, "pdcurses|PDCurses for %s", PDC_sysname());
247
248 SP->c_buffer = malloc(_INBUFSIZ * sizeof(int));
249 if (!SP->c_buffer)
250 return NULL;
251 SP->c_pindex = 0;
252 SP->c_gindex = 1;
253
254 SP->c_ungch = malloc(NUNGETCH * sizeof(int));
255 if (!SP->c_ungch)
256 return NULL;
257 SP->c_ungind = 0;
258 SP->c_ungmax = NUNGETCH;
259
260 return stdscr;
261}
262
263#ifdef XCURSES
264WINDOW *Xinitscr(int argc, char **argv)
265{
266 PDC_LOG(("Xinitscr() - called\n"));
267
268 PDC_set_args(argc, argv);
269 return initscr();
270}
271#endif
272
273int endwin(void)
274{
275 PDC_LOG(("endwin() - called\n"));
276
277 /* Allow temporary exit from curses using endwin() */
278
279 def_prog_mode();
280 PDC_scr_close();
281
282 SP->alive = FALSE;
283
284 return OK;
285}
286
287bool isendwin(void)
288{
289 PDC_LOG(("isendwin() - called\n"));
290
291 return SP ? !(SP->alive) : FALSE;
292}
293
294SCREEN *newterm(const char *type, FILE *outfd, FILE *infd)
295{
296 PDC_LOG(("newterm() - called\n"));
297
298 return initscr() ? SP : NULL;
299}
300
301SCREEN *set_term(SCREEN *new)
302{
303 PDC_LOG(("set_term() - called\n"));
304
305 /* We only support one screen */
306
307 return (new == SP) ? SP : NULL;
308}
309
310void delscreen(SCREEN *sp)
311{
312 PDC_LOG(("delscreen() - called\n"));
313
314 if (!SP || sp != SP)
315 return;
316
317 free(SP->c_ungch);
318 free(SP->c_buffer);
319 free(SP->atrtab);
320
321 PDC_slk_free(); /* free the soft label keys, if needed */
322
323 delwin(stdscr);
324 delwin(curscr);
325 delwin(SP->lastscr);
326 stdscr = (WINDOW *)NULL;
327 curscr = (WINDOW *)NULL;
328 SP->lastscr = (WINDOW *)NULL;
329
330 SP->alive = FALSE;
331
332 PDC_scr_free();
333
334 free(SP);
335 SP = (SCREEN *)NULL;
336}
337
338int resize_term(int nlines, int ncols)
339{
340 PDC_LOG(("resize_term() - called: nlines %d\n", nlines));
341
342 if (!stdscr || PDC_resize_screen(nlines, ncols) == ERR)
343 return ERR;
344
345 SP->resized = FALSE;
346
347 SP->lines = PDC_get_rows();
348 LINES = SP->lines - SP->linesrippedoff - SP->slklines;
349 SP->cols = COLS = PDC_get_columns();
350
351 if (SP->cursrow >= SP->lines)
352 SP->cursrow = SP->lines - 1;
353 if (SP->curscol >= SP->cols)
354 SP->curscol = SP->cols - 1;
355
356 if (wresize(curscr, SP->lines, SP->cols) == ERR ||
357 wresize(stdscr, LINES, COLS) == ERR ||
358 wresize(SP->lastscr, SP->lines, SP->cols) == ERR)
359 return ERR;
360
361 werase(SP->lastscr);
362 curscr->_clear = TRUE;
363
364 if (SP->slk_winptr)
365 {
366 if (wresize(SP->slk_winptr, SP->slklines, COLS) == ERR)
367 return ERR;
368
369 wmove(SP->slk_winptr, 0, 0);
370 wclrtobot(SP->slk_winptr);
371 PDC_slk_initialize();
372 slk_noutrefresh();
373 }
374
375 touchwin(stdscr);
376 wnoutrefresh(stdscr);
377
378 return OK;
379}
380
381bool is_termresized(void)
382{
383 PDC_LOG(("is_termresized() - called\n"));
384
385 return SP->resized;
386}
387
388const char *curses_version(void)
389{
390 return _curses_notice;
391}
392
393void PDC_get_version(PDC_VERSION *ver)
394{
395 if (!ver)
396 return;
397
398 ver->flags = 0
399#ifdef PDCDEBUG
400 | PDC_VFLAG_DEBUG
401#endif
402#ifdef PDC_WIDE
403 | PDC_VFLAG_WIDE
404#endif
405#ifdef PDC_FORCE_UTF8
406 | PDC_VFLAG_UTF8
407#endif
408#ifdef PDC_DLL_BUILD
409 | PDC_VFLAG_DLL
410#endif
411#ifdef PDC_RGB
412 | PDC_VFLAG_RGB
413#endif
414 ;
415
416 ver->build = PDC_BUILD;
417 ver->major = PDC_VER_MAJOR;
418 ver->minor = PDC_VER_MINOR;
419 ver->csize = sizeof(chtype);
420 ver->bsize = sizeof(bool);
421}
422
423int set_tabsize(int tabsize)
424{
425 PDC_LOG(("set_tabsize() - called: tabsize %d\n", tabsize));
426
427 if (tabsize < 1)
428 return ERR;
429
430 TABSIZE = tabsize;
431
432 return OK;
433}
diff --git a/scripts/kconfig/libcurses/inopts.c b/scripts/kconfig/libcurses/inopts.c
new file mode 100644
index 000000000..a1c4b49f8
--- /dev/null
+++ b/scripts/kconfig/libcurses/inopts.c
@@ -0,0 +1,410 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7inopts
8------
9
10### Synopsis
11
12 int cbreak(void);
13 int nocbreak(void);
14 int echo(void);
15 int noecho(void);
16 int halfdelay(int tenths);
17 int intrflush(WINDOW *win, bool bf);
18 int keypad(WINDOW *win, bool bf);
19 int meta(WINDOW *win, bool bf);
20 int nl(void);
21 int nonl(void);
22 int nodelay(WINDOW *win, bool bf);
23 int notimeout(WINDOW *win, bool bf);
24 int raw(void);
25 int noraw(void);
26 void noqiflush(void);
27 void qiflush(void);
28 void timeout(int delay);
29 void wtimeout(WINDOW *win, int delay);
30 int wgetdelay(const WINDOW *win);
31 int typeahead(int fildes);
32
33 int crmode(void);
34 int nocrmode(void);
35
36 bool is_keypad(const WINDOW *win);
37 bool is_nodelay(const WINDOW *win);
38 bool is_notimeout(const WINDOW *win);
39
40### Description
41
42 cbreak() and nocbreak() toggle cbreak mode. In cbreak mode,
43 characters typed by the user are made available immediately, and
44 erase/kill character processing is not performed. In nocbreak mode,
45 typed characters are buffered until a newline or carriage return.
46 Interrupt and flow control characters are unaffected by this mode.
47 PDCurses always starts in cbreak mode.
48
49 echo() and noecho() control whether typed characters are echoed by
50 the input routine. Initially, input characters are echoed. Subsequent
51 calls to echo() and noecho() do not flush type-ahead.
52
53 halfdelay() is similar to cbreak(), but allows for a time limit to be
54 specified, in tenths of a second. This causes getch() to block for
55 that period before returning ERR if no key has been received. tenths
56 must be between 1 and 255.
57
58 keypad() controls whether getch() returns function/special keys as
59 single key codes (e.g., the left arrow key as KEY_LEFT). Per X/Open,
60 the default for keypad mode is OFF. You'll probably want it on. With
61 keypad mode off, if a special key is pressed, getch() does nothing or
62 returns ERR.
63
64 nodelay() controls whether wgetch() is a non-blocking call. If the
65 option is enabled, and no input is ready, wgetch() will return ERR.
66 If disabled, wgetch() will hang until input is ready.
67
68 nl() enables the translation of a carriage return into a newline on
69 input. nonl() disables this. Initially, the translation does occur.
70
71 raw() and noraw() toggle raw mode. Raw mode is similar to cbreak
72 mode, in that characters typed are immediately passed through to the
73 user program. The difference is that in raw mode, the INTR, QUIT,
74 SUSP, and STOP characters are passed through without being
75 interpreted, and without generating a signal.
76
77 In PDCurses, the meta() function sets raw mode on or off.
78
79 timeout() and wtimeout() set blocking or non-blocking reads for the
80 specified window. If the delay is negative, a blocking read is used;
81 if zero, then non-blocking reads are done -- if no input is waiting,
82 ERR is returned immediately. If the delay is positive, the read
83 blocks for the delay period; if the period expires, ERR is returned.
84 The delay is given in milliseconds, but this is rounded down to 50ms
85 (1/20th sec) intervals, with a minimum of one interval if a postive
86 delay is given; i.e., 1-99 will wait 50ms, 100-149 will wait 100ms,
87 etc.
88
89 wgetdelay() returns the delay timeout as set in wtimeout().
90
91 intrflush(), notimeout(), noqiflush(), qiflush() and typeahead() do
92 nothing in PDCurses, but are included for compatibility with other
93 curses implementations.
94
95 crmode() and nocrmode() are archaic equivalents to cbreak() and
96 nocbreak(), respectively.
97
98 is_keypad() reports whether the specified window is in keypad mode.
99
100 is_nodelay() reports whether the specified window is in nodelay mode.
101
102### Return Value
103
104 is_keypad() and is_nodelay() return TRUE or FALSE. is_notimeout() is
105 provided for compatibility with other curses implementations, and
106 always returns FALSE. All others return OK on success and ERR on error.
107
108### Portability
109
110 Function | X/Open | ncurses | NetBSD
111 :---------------------|:------:|:-------:|:------:
112 cbreak | Y | Y | Y
113 nocbreak | Y | Y | Y
114 echo | Y | Y | Y
115 noecho | Y | Y | Y
116 halfdelay | Y | Y | Y
117 intrflush | Y | Y | Y
118 keypad | Y | Y | Y
119 meta | Y | Y | Y
120 nl | Y | Y | Y
121 nonl | Y | Y | Y
122 nodelay | Y | Y | Y
123 notimeout | Y | Y | Y
124 raw | Y | Y | Y
125 noraw | Y | Y | Y
126 noqiflush | Y | Y | Y
127 qiflush | Y | Y | Y
128 timeout | Y | Y | Y
129 wtimeout | Y | Y | Y
130 wgetdelay | - | Y | -
131 typeahead | Y | Y | Y
132 crmode | Y | Y | Y
133 nocrmode | Y | Y | Y
134 is_keypad | - | Y | Y
135 is_nodelay | - | Y | -
136 is_notimeout | - | Y | -
137
138**man-end****************************************************************/
139
140int cbreak(void)
141{
142 PDC_LOG(("cbreak() - called\n"));
143
144 if (!SP)
145 return ERR;
146
147 SP->cbreak = TRUE;
148
149 return OK;
150}
151
152int nocbreak(void)
153{
154 PDC_LOG(("nocbreak() - called\n"));
155
156 if (!SP)
157 return ERR;
158
159 SP->cbreak = FALSE;
160 SP->delaytenths = 0;
161
162 return OK;
163}
164
165int echo(void)
166{
167 PDC_LOG(("echo() - called\n"));
168
169 if (!SP)
170 return ERR;
171
172 SP->echo = TRUE;
173
174 return OK;
175}
176
177int noecho(void)
178{
179 PDC_LOG(("noecho() - called\n"));
180
181 if (!SP)
182 return ERR;
183
184 SP->echo = FALSE;
185
186 return OK;
187}
188
189int halfdelay(int tenths)
190{
191 PDC_LOG(("halfdelay() - called\n"));
192
193 if (!SP || tenths < 1 || tenths > 255)
194 return ERR;
195
196 SP->delaytenths = tenths;
197
198 return OK;
199}
200
201int intrflush(WINDOW *win, bool bf)
202{
203 PDC_LOG(("intrflush() - called\n"));
204
205 return OK;
206}
207
208int keypad(WINDOW *win, bool bf)
209{
210 PDC_LOG(("keypad() - called\n"));
211
212 if (!win)
213 return ERR;
214
215 win->_use_keypad = bf;
216
217 return OK;
218}
219
220int meta(WINDOW *win, bool bf)
221{
222 PDC_LOG(("meta() - called\n"));
223
224 if (!SP)
225 return ERR;
226
227 SP->raw_inp = bf;
228
229 return OK;
230}
231
232int nl(void)
233{
234 PDC_LOG(("nl() - called\n"));
235
236 if (!SP)
237 return ERR;
238
239 SP->autocr = TRUE;
240
241 return OK;
242}
243
244int nonl(void)
245{
246 PDC_LOG(("nonl() - called\n"));
247
248 if (!SP)
249 return ERR;
250
251 SP->autocr = FALSE;
252
253 return OK;
254}
255
256int nodelay(WINDOW *win, bool flag)
257{
258 PDC_LOG(("nodelay() - called\n"));
259
260 if (!win)
261 return ERR;
262
263 win->_nodelay = flag;
264
265 return OK;
266}
267
268int notimeout(WINDOW *win, bool flag)
269{
270 PDC_LOG(("notimeout() - called\n"));
271
272 return OK;
273}
274
275int raw(void)
276{
277 PDC_LOG(("raw() - called\n"));
278
279 if (!SP)
280 return ERR;
281
282 PDC_set_keyboard_binary(TRUE);
283 SP->raw_inp = TRUE;
284
285 return OK;
286}
287
288int noraw(void)
289{
290 PDC_LOG(("noraw() - called\n"));
291
292 if (!SP)
293 return ERR;
294
295 PDC_set_keyboard_binary(FALSE);
296 SP->raw_inp = FALSE;
297
298 return OK;
299}
300
301void noqiflush(void)
302{
303 PDC_LOG(("noqiflush() - called\n"));
304}
305
306void qiflush(void)
307{
308 PDC_LOG(("qiflush() - called\n"));
309}
310
311void timeout(int delay)
312{
313 PDC_LOG(("timeout() - called\n"));
314
315 wtimeout(stdscr, delay);
316}
317
318void wtimeout(WINDOW *win, int delay)
319{
320 PDC_LOG(("wtimeout() - called\n"));
321
322 if (!win)
323 return;
324
325 if (delay < 0)
326 {
327 /* This causes a blocking read on the window, so turn on delay
328 mode */
329
330 win->_nodelay = FALSE;
331 win->_delayms = 0;
332 }
333 else if (!delay)
334 {
335 /* This causes a non-blocking read on the window, so turn off
336 delay mode */
337
338 win->_nodelay = TRUE;
339 win->_delayms = 0;
340 }
341 else
342 {
343 /* This causes the read on the window to delay for the number of
344 milliseconds. Also forces the window into non-blocking read
345 mode */
346
347 /*win->_nodelay = TRUE;*/
348 win->_delayms = delay;
349 }
350}
351
352int wgetdelay(const WINDOW *win)
353{
354 PDC_LOG(("wgetdelay() - called\n"));
355
356 if (!win)
357 return 0;
358
359 return win->_delayms;
360}
361
362int typeahead(int fildes)
363{
364 PDC_LOG(("typeahead() - called\n"));
365
366 return OK;
367}
368
369int crmode(void)
370{
371 PDC_LOG(("crmode() - called\n"));
372
373 return cbreak();
374}
375
376int nocrmode(void)
377{
378 PDC_LOG(("nocrmode() - called\n"));
379
380 return nocbreak();
381}
382
383bool is_keypad(const WINDOW *win)
384{
385 PDC_LOG(("is_keypad() - called\n"));
386
387 if (!win)
388 return FALSE;
389
390 return win->_use_keypad;
391}
392
393bool is_nodelay(const WINDOW *win)
394{
395 PDC_LOG(("is_nodelay() - called\n"));
396
397 if (!win)
398 return FALSE;
399
400 return win->_nodelay;
401}
402
403bool is_notimeout(const WINDOW *win)
404{
405 (void) win;
406
407 PDC_LOG(("is_notimeout() - called - returning FALSE...\n"));
408
409 return FALSE;
410}
diff --git a/scripts/kconfig/libcurses/kernel.c b/scripts/kconfig/libcurses/kernel.c
new file mode 100644
index 000000000..0f5a73c21
--- /dev/null
+++ b/scripts/kconfig/libcurses/kernel.c
@@ -0,0 +1,299 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7kernel
8------
9
10### Synopsis
11
12 int def_prog_mode(void);
13 int def_shell_mode(void);
14 int reset_prog_mode(void);
15 int reset_shell_mode(void);
16 int resetty(void);
17 int savetty(void);
18 int ripoffline(int line, int (*init)(WINDOW *, int));
19 int curs_set(int visibility);
20 int napms(int ms);
21
22 int draino(int ms);
23 int resetterm(void);
24 int fixterm(void);
25 int saveterm(void);
26
27### Description
28
29 def_prog_mode() and def_shell_mode() save the current terminal modes
30 as the "program" (in curses) or "shell" (not in curses) state for use
31 by the reset_prog_mode() and reset_shell_mode() functions. This is
32 done automatically by initscr().
33
34 reset_prog_mode() and reset_shell_mode() restore the terminal to
35 "program" (in curses) or "shell" (not in curses) state. These are
36 done automatically by endwin() and doupdate() after an endwin(), so
37 they would normally not be called before these functions.
38
39 savetty() and resetty() save and restore the state of the terminal
40 modes. savetty() saves the current state in a buffer, and resetty()
41 restores the state to what it was at the last call to savetty().
42
43 curs_set() alters the appearance of the cursor. A visibility of 0
44 makes it disappear; 1 makes it appear "normal" (usually an underline)
45 and 2 makes it "highly visible" (usually a block).
46
47 ripoffline() reduces the size of stdscr by one line. If the "line"
48 parameter is positive, the line is removed from the top of the
49 screen; if negative, from the bottom. Up to 5 lines can be ripped off
50 stdscr by calling ripoffline() repeatedly. The function argument,
51 init, is called from within initscr() or newterm(), so ripoffline()
52 must be called before either of these functions. The init function
53 receives a pointer to a one-line WINDOW, and the width of the window.
54 Calling ripoffline() with a NULL init function pointer is an error.
55
56 napms() suspends the program for the specified number of
57 milliseconds. draino() is an archaic equivalent. Note that since
58 napms() attempts to give up a time slice and yield control back to
59 the OS, all times are approximate. (In DOS, the delay is actually
60 rounded down to 50ms (1/20th sec) intervals, with a minimum of one
61 interval; i.e., 1-99 will wait 50ms, 100-149 will wait 100ms, etc.)
62 0 returns immediately.
63
64 resetterm(), fixterm() and saveterm() are archaic equivalents for
65 reset_shell_mode(), reset_prog_mode() and def_prog_mode(),
66 respectively.
67
68### Return Value
69
70 All functions return OK on success and ERR on error, except
71 curs_set(), which returns the previous visibility.
72
73### Portability
74
75 Function | X/Open | ncurses | NetBSD
76 :---------------------|:------:|:-------:|:------:
77 def_prog_mode | Y | Y | Y
78 def_shell_mode | Y | Y | Y
79 reset_prog_mode | Y | Y | Y
80 reset_shell_mode | Y | Y | Y
81 resetty | Y | Y | Y
82 savetty | Y | Y | Y
83 ripoffline | Y | Y | Y
84 curs_set | Y | Y | Y
85 napms | Y | Y | Y
86 fixterm | - | Y | -
87 resetterm | - | Y | -
88 saveterm | - | Y | -
89 draino | - | - | -
90
91**man-end****************************************************************/
92
93#include <string.h>
94
95RIPPEDOFFLINE linesripped[5];
96char linesrippedoff = 0;
97
98static struct cttyset
99{
100 bool been_set;
101 SCREEN saved;
102} ctty[3];
103
104enum { PDC_SH_TTY, PDC_PR_TTY, PDC_SAVE_TTY };
105
106static void _save_mode(int i)
107{
108 ctty[i].been_set = TRUE;
109
110 memcpy(&(ctty[i].saved), SP, sizeof(SCREEN));
111
112 PDC_save_screen_mode(i);
113}
114
115static int _restore_mode(int i)
116{
117 if (ctty[i].been_set == TRUE)
118 {
119 memcpy(SP, &(ctty[i].saved), sizeof(SCREEN));
120
121 if (ctty[i].saved.raw_out)
122 raw();
123
124 PDC_restore_screen_mode(i);
125
126 if ((LINES != ctty[i].saved.lines) ||
127 (COLS != ctty[i].saved.cols))
128 resize_term(ctty[i].saved.lines, ctty[i].saved.cols);
129
130 PDC_curs_set(ctty[i].saved.visibility);
131
132 PDC_gotoyx(ctty[i].saved.cursrow, ctty[i].saved.curscol);
133 }
134
135 return ctty[i].been_set ? OK : ERR;
136}
137
138int def_prog_mode(void)
139{
140 PDC_LOG(("def_prog_mode() - called\n"));
141
142 if (!SP)
143 return ERR;
144
145 _save_mode(PDC_PR_TTY);
146
147 return OK;
148}
149
150int def_shell_mode(void)
151{
152 PDC_LOG(("def_shell_mode() - called\n"));
153
154 if (!SP)
155 return ERR;
156
157 _save_mode(PDC_SH_TTY);
158
159 return OK;
160}
161
162int reset_prog_mode(void)
163{
164 PDC_LOG(("reset_prog_mode() - called\n"));
165
166 if (!SP)
167 return ERR;
168
169 _restore_mode(PDC_PR_TTY);
170 PDC_reset_prog_mode();
171
172 return OK;
173}
174
175int reset_shell_mode(void)
176{
177 PDC_LOG(("reset_shell_mode() - called\n"));
178
179 if (!SP)
180 return ERR;
181
182 _restore_mode(PDC_SH_TTY);
183 PDC_reset_shell_mode();
184
185 return OK;
186}
187
188int resetty(void)
189{
190 PDC_LOG(("resetty() - called\n"));
191
192 if (!SP)
193 return ERR;
194
195 return _restore_mode(PDC_SAVE_TTY);
196}
197
198int savetty(void)
199{
200 PDC_LOG(("savetty() - called\n"));
201
202 if (!SP)
203 return ERR;
204
205 _save_mode(PDC_SAVE_TTY);
206
207 return OK;
208}
209
210int curs_set(int visibility)
211{
212 int ret_vis;
213
214 PDC_LOG(("curs_set() - called: visibility=%d\n", visibility));
215
216 if (!SP || visibility < 0 || visibility > 2)
217 return ERR;
218
219 ret_vis = PDC_curs_set(visibility);
220
221 /* If the cursor is changing from invisible to visible, update
222 its position */
223
224 if (visibility && !ret_vis)
225 PDC_gotoyx(SP->cursrow, SP->curscol);
226
227 return ret_vis;
228}
229
230int napms(int ms)
231{
232 PDC_LOG(("napms() - called: ms=%d\n", ms));
233
234 if (!SP)
235 return ERR;
236
237 if (SP->dirty)
238 {
239 int curs_state = SP->visibility;
240 bool leave_state = is_leaveok(curscr);
241
242 SP->dirty = FALSE;
243
244 leaveok(curscr, TRUE);
245
246 wrefresh(curscr);
247
248 leaveok(curscr, leave_state);
249 curs_set(curs_state);
250 }
251
252 if (ms)
253 PDC_napms(ms);
254
255 return OK;
256}
257
258int ripoffline(int line, int (*init)(WINDOW *, int))
259{
260 PDC_LOG(("ripoffline() - called: line=%d\n", line));
261
262 if (linesrippedoff < 5 && line && init)
263 {
264 linesripped[(int)linesrippedoff].line = line;
265 linesripped[(int)linesrippedoff++].init = init;
266
267 return OK;
268 }
269
270 return ERR;
271}
272
273int draino(int ms)
274{
275 PDC_LOG(("draino() - called\n"));
276
277 return napms(ms);
278}
279
280int resetterm(void)
281{
282 PDC_LOG(("resetterm() - called\n"));
283
284 return reset_shell_mode();
285}
286
287int fixterm(void)
288{
289 PDC_LOG(("fixterm() - called\n"));
290
291 return reset_prog_mode();
292}
293
294int saveterm(void)
295{
296 PDC_LOG(("saveterm() - called\n"));
297
298 return def_prog_mode();
299}
diff --git a/scripts/kconfig/libcurses/move.c b/scripts/kconfig/libcurses/move.c
new file mode 100644
index 000000000..38db1d19a
--- /dev/null
+++ b/scripts/kconfig/libcurses/move.c
@@ -0,0 +1,79 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7move
8----
9
10### Synopsis
11
12 int move(int y, int x);
13 int mvcur(int oldrow, int oldcol, int newrow, int newcol);
14 int wmove(WINDOW *win, int y, int x);
15
16### Description
17
18 move() and wmove() move the cursor associated with the window to the
19 given location. This does not move the physical cursor of the
20 terminal until refresh() is called. The position specified is
21 relative to the upper left corner of the window, which is (0,0).
22
23 mvcur() moves the physical cursor without updating any window cursor
24 positions.
25
26### Return Value
27
28 All functions return OK on success and ERR on error.
29
30### Portability
31
32 Function | X/Open | ncurses | NetBSD
33 :---------------------|:------:|:-------:|:------:
34 move | Y | Y | Y
35 mvcur | Y | Y | Y
36 wmove | Y | Y | Y
37
38**man-end****************************************************************/
39
40int move(int y, int x)
41{
42 PDC_LOG(("move() - called: y=%d x=%d\n", y, x));
43
44 if (!stdscr || x < 0 || y < 0 || x >= stdscr->_maxx || y >= stdscr->_maxy)
45 return ERR;
46
47 stdscr->_curx = x;
48 stdscr->_cury = y;
49
50 return OK;
51}
52
53int mvcur(int oldrow, int oldcol, int newrow, int newcol)
54{
55 PDC_LOG(("mvcur() - called: oldrow %d oldcol %d newrow %d newcol %d\n",
56 oldrow, oldcol, newrow, newcol));
57
58 if (!SP || newrow < 0 || newrow >= LINES || newcol < 0 || newcol >= COLS)
59 return ERR;
60
61 PDC_gotoyx(newrow, newcol);
62 SP->cursrow = newrow;
63 SP->curscol = newcol;
64
65 return OK;
66}
67
68int wmove(WINDOW *win, int y, int x)
69{
70 PDC_LOG(("wmove() - called: y=%d x=%d\n", y, x));
71
72 if (!win || x < 0 || y < 0 || x >= win->_maxx || y >= win->_maxy)
73 return ERR;
74
75 win->_curx = x;
76 win->_cury = y;
77
78 return OK;
79}
diff --git a/scripts/kconfig/libcurses/outopts.c b/scripts/kconfig/libcurses/outopts.c
new file mode 100644
index 000000000..4c8950959
--- /dev/null
+++ b/scripts/kconfig/libcurses/outopts.c
@@ -0,0 +1,262 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7outopts
8-------
9
10### Synopsis
11
12 int clearok(WINDOW *win, bool bf);
13 int idlok(WINDOW *win, bool bf);
14 void idcok(WINDOW *win, bool bf);
15 void immedok(WINDOW *win, bool bf);
16 int leaveok(WINDOW *win, bool bf);
17 int setscrreg(int top, int bot);
18 int wsetscrreg(WINDOW *win, int top, int bot);
19 int wgetscrreg(const WINDOW *win, int *top, int *bot);
20 int scrollok(WINDOW *win, bool bf);
21
22 int raw_output(bool bf);
23
24 bool is_cleared(const WINDOW *win);
25 bool is_idlok(const WINDOW *win);
26 bool is_idcok(const WINDOW *win);
27 bool is_immedok(const WINDOW *win);
28 bool is_leaveok(const WINDOW *win);
29 bool is_scrollok(const WINDOW *win);
30
31### Description
32
33 With clearok(), if bf is TRUE, the next call to wrefresh() with this
34 window will clear the screen completely and redraw the entire screen.
35
36 immedok(), called with a second argument of TRUE, causes an automatic
37 wrefresh() every time a change is made to the specified window.
38
39 Normally, the hardware cursor is left at the location of the window
40 being refreshed. leaveok() allows the cursor to be left wherever the
41 update happens to leave it. It's useful for applications where the
42 cursor is not used, since it reduces the need for cursor motions. If
43 possible, the cursor is made invisible when this option is enabled.
44
45 wsetscrreg() sets a scrolling region in a window; "top" and "bot" are
46 the line numbers for the top and bottom margins. If this option and
47 scrollok() are enabled, any attempt to move off the bottom margin
48 will cause all lines in the scrolling region to scroll up one line.
49 setscrreg() is the stdscr version.
50
51 wgetscrreg() gets the top and bottom margins as set in wsetscrreg().
52
53 idlok() and idcok() do nothing in PDCurses, but are provided for
54 compatibility with other curses implementations, likewise is_idlok()
55 and is_idcok().
56
57 raw_output() enables the output of raw characters using the standard
58 *add* and *ins* curses functions (that is, it disables translation of
59 control characters).
60
61 is_cleared() reports whether the specified window causes clear at next
62 refresh.
63
64 is_immedok() reports whether the specified window is in immedok mode.
65
66 is_leaveok() reports whether the specified window is in leaveok mode.
67
68 is_scrollok() reports whether the specified window allows scrolling.
69
70### Return Value
71
72 is_cleared(), is_immedok(), is_leaveok() and is_scrollok() return TRUE
73 or FALSE. is_idlok() and is_idcok() are provided for compatibility with
74 other curses implementations, and always return FALSE. All others
75 return OK on success and ERR on error.
76
77### Portability
78
79 Function | X/Open | ncurses | NetBSD
80 :---------------------|:------:|:-------:|:------:
81 clearok | Y | Y | Y
82 idlok | Y | Y | Y
83 idcok | Y | Y | Y
84 immedok | Y | Y | Y
85 leaveok | Y | Y | Y
86 setscrreg | Y | Y | Y
87 wsetscrreg | Y | Y | Y
88 wgetscrreg | - | Y | -
89 scrollok | Y | Y | Y
90 is_cleared | - | Y | -
91 is_idlok | - | Y | -
92 is_idcok | - | Y | -
93 is_immedok | - | Y | -
94 is_leaveok | - | Y | Y
95 is_scrollok | - | Y | -
96 raw_output | - | - | -
97
98**man-end****************************************************************/
99
100int clearok(WINDOW *win, bool bf)
101{
102 PDC_LOG(("clearok() - called\n"));
103
104 if (!win)
105 return ERR;
106
107 win->_clear = bf;
108
109 return OK;
110}
111
112int idlok(WINDOW *win, bool bf)
113{
114 PDC_LOG(("idlok() - called\n"));
115
116 return OK;
117}
118
119void idcok(WINDOW *win, bool bf)
120{
121 PDC_LOG(("idcok() - called\n"));
122}
123
124void immedok(WINDOW *win, bool bf)
125{
126 PDC_LOG(("immedok() - called\n"));
127
128 if (win)
129 win->_immed = bf;
130}
131
132int leaveok(WINDOW *win, bool bf)
133{
134 PDC_LOG(("leaveok() - called\n"));
135
136 if (!win)
137 return ERR;
138
139 win->_leaveit = bf;
140
141 curs_set(!bf);
142
143 return OK;
144}
145
146int setscrreg(int top, int bottom)
147{
148 PDC_LOG(("setscrreg() - called: top %d bottom %d\n", top, bottom));
149
150 return wsetscrreg(stdscr, top, bottom);
151}
152
153int wsetscrreg(WINDOW *win, int top, int bottom)
154{
155 PDC_LOG(("wsetscrreg() - called: top %d bottom %d\n", top, bottom));
156
157 if (win && 0 <= top && top <= win->_cury &&
158 win->_cury <= bottom && bottom < win->_maxy)
159 {
160 win->_tmarg = top;
161 win->_bmarg = bottom;
162
163 return OK;
164 }
165 else
166 return ERR;
167}
168
169int wgetscrreg(const WINDOW *win, int *top, int *bot)
170{
171 PDC_LOG(("wgetscrreg() - called\n"));
172
173 if (!win || !top || !bot)
174 return ERR;
175
176 *top = win->_tmarg;
177 *bot = win->_bmarg;
178
179 return OK;
180}
181
182int scrollok(WINDOW *win, bool bf)
183{
184 PDC_LOG(("scrollok() - called\n"));
185
186 if (!win)
187 return ERR;
188
189 win->_scroll = bf;
190
191 return OK;
192}
193
194int raw_output(bool bf)
195{
196 PDC_LOG(("raw_output() - called\n"));
197
198 if (!SP)
199 return ERR;
200
201 SP->raw_out = bf;
202
203 return OK;
204}
205
206bool is_cleared(const WINDOW *win)
207{
208 PDC_LOG(("is_cleared() - called\n"));
209
210 if (!win)
211 return FALSE;
212
213 return win->_clear;
214}
215
216bool is_idlok(const WINDOW *win)
217{
218 (void) win;
219
220 PDC_LOG(("is_idlok() - called\n"));
221
222 return FALSE;
223}
224
225bool is_idcok(const WINDOW *win)
226{
227 (void) win;
228
229 PDC_LOG(("is_idcok() - called\n"));
230
231 return FALSE;
232}
233
234bool is_immedok(const WINDOW *win)
235{
236 PDC_LOG(("is_immedok() - called\n"));
237
238 if (!win)
239 return FALSE;
240
241 return win->_immed;
242}
243
244bool is_leaveok(const WINDOW *win)
245{
246 PDC_LOG(("is_leaveok() - called\n"));
247
248 if (!win)
249 return FALSE;
250
251 return win->_leaveit;
252}
253
254bool is_scrollok(const WINDOW *win)
255{
256 PDC_LOG(("is_scrollok() - called\n"));
257
258 if (!win)
259 return FALSE;
260
261 return win->_scroll;
262}
diff --git a/scripts/kconfig/libcurses/overlay.c b/scripts/kconfig/libcurses/overlay.c
new file mode 100644
index 000000000..75a93d83c
--- /dev/null
+++ b/scripts/kconfig/libcurses/overlay.c
@@ -0,0 +1,216 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7overlay
8-------
9
10### Synopsis
11
12 int overlay(const WINDOW *src_w, WINDOW *dst_w)
13 int overwrite(const WINDOW *src_w, WINDOW *dst_w)
14 int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr,
15 int src_tc, int dst_tr, int dst_tc, int dst_br,
16 int dst_bc, int _overlay)
17
18### Description
19
20 overlay() and overwrite() copy all the text from src_w into dst_w.
21 The windows need not be the same size. Those characters in the source
22 window that intersect with the destination window are copied, so that
23 the characters appear in the same physical position on the screen.
24 The difference between the two functions is that overlay() is non-
25 destructive (blanks are not copied) while overwrite() is destructive
26 (blanks are copied).
27
28 copywin() is similar, but doesn't require that the two windows
29 overlap. The arguments src_tc and src_tr specify the top left corner
30 of the region to be copied. dst_tc, dst_tr, dst_br, and dst_bc
31 specify the region within the destination window to copy to. The
32 argument "overlay", if TRUE, indicates that the copy is done non-
33 destructively (as in overlay()); blanks in the source window are not
34 copied to the destination window. When overlay is FALSE, blanks are
35 copied.
36
37### Return Value
38
39 All functions return OK on success and ERR on error.
40
41### Portability
42
43 Function | X/Open | ncurses | NetBSD
44 :---------------------|:------:|:-------:|:------:
45 overlay | Y | Y | Y
46 overwrite | Y | Y | Y
47 copywin | Y | Y | Y
48
49**man-end****************************************************************/
50
51/* Thanks to Andreas Otte <venn@@uni-paderborn.de> for the
52 corrected overlay()/overwrite() behavior. */
53
54static int _copy_win(const WINDOW *src_w, WINDOW *dst_w, int src_tr,
55 int src_tc, int src_br, int src_bc, int dst_tr,
56 int dst_tc, bool _overlay)
57{
58 int col, line, y1, fc, *minchng, *maxchng;
59 chtype *w1ptr, *w2ptr;
60
61 int lc = 0;
62 int xdiff = src_bc - src_tc;
63 int ydiff = src_br - src_tr;
64
65 if (!src_w || !dst_w)
66 return ERR;
67
68 minchng = dst_w->_firstch;
69 maxchng = dst_w->_lastch;
70
71 for (y1 = 0; y1 < dst_tr; y1++)
72 {
73 minchng++;
74 maxchng++;
75 }
76
77 for (line = 0; line < ydiff; line++)
78 {
79 w1ptr = src_w->_y[line + src_tr] + src_tc;
80 w2ptr = dst_w->_y[line + dst_tr] + dst_tc;
81
82 fc = _NO_CHANGE;
83
84 for (col = 0; col < xdiff; col++)
85 {
86 if ((*w1ptr) != (*w2ptr) &&
87 !((*w1ptr & A_CHARTEXT) == ' ' && _overlay))
88 {
89 *w2ptr = *w1ptr;
90
91 if (fc == _NO_CHANGE)
92 fc = col + dst_tc;
93
94 lc = col + dst_tc;
95 }
96
97 w1ptr++;
98 w2ptr++;
99 }
100
101 if (*minchng == _NO_CHANGE)
102 {
103 *minchng = fc;
104 *maxchng = lc;
105 }
106 else if (fc != _NO_CHANGE)
107 {
108 if (fc < *minchng)
109 *minchng = fc;
110 if (lc > *maxchng)
111 *maxchng = lc;
112 }
113
114 minchng++;
115 maxchng++;
116 }
117
118 return OK;
119}
120
121int _copy_overlap(const WINDOW *src_w, WINDOW *dst_w, bool overlay)
122{
123 int first_line, first_col, last_line, last_col;
124 int src_start_x, src_start_y, dst_start_x, dst_start_y;
125 int xdiff, ydiff;
126
127 if (!src_w || !dst_w)
128 return ERR;
129
130 first_col = max(dst_w->_begx, src_w->_begx);
131 first_line = max(dst_w->_begy, src_w->_begy);
132
133 last_col = min(src_w->_begx + src_w->_maxx, dst_w->_begx + dst_w->_maxx);
134 last_line = min(src_w->_begy + src_w->_maxy, dst_w->_begy + dst_w->_maxy);
135
136 /* determine the overlapping region of the two windows in real
137 coordinates */
138
139 /* if no overlapping region, do nothing */
140
141 if ((last_col < first_col) || (last_line < first_line))
142 return OK;
143
144 /* size of overlapping region */
145
146 xdiff = last_col - first_col;
147 ydiff = last_line - first_line;
148
149 if (src_w->_begx <= dst_w->_begx)
150 {
151 src_start_x = dst_w->_begx - src_w->_begx;
152 dst_start_x = 0;
153 }
154 else
155 {
156 dst_start_x = src_w->_begx - dst_w->_begx;
157 src_start_x = 0;
158 }
159
160 if (src_w->_begy <= dst_w->_begy)
161 {
162 src_start_y = dst_w->_begy - src_w->_begy;
163 dst_start_y = 0;
164 }
165 else
166 {
167 dst_start_y = src_w->_begy - dst_w->_begy;
168 src_start_y = 0;
169 }
170
171 return _copy_win(src_w, dst_w, src_start_y, src_start_x,
172 src_start_y + ydiff, src_start_x + xdiff,
173 dst_start_y, dst_start_x, overlay);
174}
175
176int overlay(const WINDOW *src_w, WINDOW *dst_w)
177{
178 PDC_LOG(("overlay() - called\n"));
179
180 return _copy_overlap(src_w, dst_w, TRUE);
181}
182
183int overwrite(const WINDOW *src_w, WINDOW *dst_w)
184{
185 PDC_LOG(("overwrite() - called\n"));
186
187 return _copy_overlap(src_w, dst_w, FALSE);
188}
189
190int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr, int src_tc,
191 int dst_tr, int dst_tc, int dst_br, int dst_bc, int _overlay)
192{
193 int src_end_x, src_end_y;
194 int src_rows, src_cols, dst_rows, dst_cols;
195 int min_rows, min_cols;
196
197 PDC_LOG(("copywin() - called\n"));
198
199 if (!src_w || !dst_w || dst_w == curscr || dst_br >= dst_w->_maxy
200 || dst_bc >= dst_w->_maxx || dst_tr < 0 || dst_tc < 0)
201 return ERR;
202
203 src_rows = src_w->_maxy - src_tr;
204 src_cols = src_w->_maxx - src_tc;
205 dst_rows = dst_br - dst_tr + 1;
206 dst_cols = dst_bc - dst_tc + 1;
207
208 min_rows = min(src_rows, dst_rows);
209 min_cols = min(src_cols, dst_cols);
210
211 src_end_y = src_tr + min_rows;
212 src_end_x = src_tc + min_cols;
213
214 return _copy_win(src_w, dst_w, src_tr, src_tc, src_end_y, src_end_x,
215 dst_tr, dst_tc, _overlay);
216}
diff --git a/scripts/kconfig/libcurses/pad.c b/scripts/kconfig/libcurses/pad.c
new file mode 100644
index 000000000..8b44dabd4
--- /dev/null
+++ b/scripts/kconfig/libcurses/pad.c
@@ -0,0 +1,276 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7pad
8---
9
10### Synopsis
11
12 WINDOW *newpad(int nlines, int ncols);
13 WINDOW *subpad(WINDOW *orig, int nlines, int ncols,
14 int begy, int begx);
15 int prefresh(WINDOW *win, int py, int px, int sy1, int sx1,
16 int sy2, int sx2);
17 int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1,
18 int sy2, int sx2);
19 int pechochar(WINDOW *pad, chtype ch);
20 int pecho_wchar(WINDOW *pad, const cchar_t *wch);
21
22 bool is_pad(const WINDOW *pad);
23
24### Description
25
26 A pad is a special kind of window, which is not restricted by the
27 screen size, and is not necessarily associated with a particular part
28 of the screen. You can use a pad when you need a large window, and
29 only a part of the window will be on the screen at one time. Pads are
30 not refreshed automatically (e.g., from scrolling or echoing of
31 input). You can't call wrefresh() with a pad as an argument; use
32 prefresh() or pnoutrefresh() instead. Note that these routines
33 require additional parameters to specify the part of the pad to be
34 displayed, and the location to use on the screen.
35
36 newpad() creates a new pad data structure.
37
38 subpad() creates a new sub-pad within a pad, at position (begy,
39 begx), with dimensions of nlines lines and ncols columns. This
40 position is relative to the pad, and not to the screen as with
41 subwin. Changes to either the parent pad or sub-pad will affect both.
42 When using sub-pads, you may need to call touchwin() before calling
43 prefresh().
44
45 pnoutrefresh() copies the specified pad to the virtual screen.
46
47 prefresh() calls pnoutrefresh(), followed by doupdate().
48
49 These routines are analogous to wnoutrefresh() and wrefresh(). (py,
50 px) specifies the upper left corner of the part of the pad to be
51 displayed; (sy1, sx1) and (sy2, sx2) describe the screen rectangle
52 that will contain the selected part of the pad.
53
54 pechochar() is functionally equivalent to addch() followed by a call
55 to prefresh(), with the last-used coordinates and dimensions.
56 pecho_wchar() is the wide-character version.
57
58 is_pad() reports whether the specified window is a pad.
59
60### Return Value
61
62 All functions except is_pad() return OK on success and ERR on error.
63
64### Portability
65
66 Function | X/Open | ncurses | NetBSD
67 :---------------------|:------:|:-------:|:------:
68 newpad | Y | Y | Y
69 subpad | Y | Y | Y
70 prefresh | Y | Y | Y
71 pnoutrefresh | Y | Y | Y
72 pechochar | Y | Y | Y
73 pecho_wchar | Y | Y | Y
74 is_pad | - | Y | Y
75
76**man-end****************************************************************/
77
78#include <string.h>
79
80WINDOW *newpad(int nlines, int ncols)
81{
82 WINDOW *win;
83
84 PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols));
85
86 win = PDC_makenew(nlines, ncols, 0, 0);
87 if (win)
88 win = PDC_makelines(win);
89
90 if (!win)
91 return (WINDOW *)NULL;
92
93 werase(win);
94
95 win->_flags = _PAD;
96 win->_pad._pad_y = 0;
97 win->_pad._pad_x = 0;
98 win->_pad._pad_top = 0;
99 win->_pad._pad_left = 0;
100 win->_pad._pad_bottom = min(LINES, nlines) - 1;
101 win->_pad._pad_right = min(COLS, ncols) - 1;
102
103 return win;
104}
105
106WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx)
107{
108 WINDOW *win;
109 int i;
110
111 PDC_LOG(("subpad() - called: lines=%d cols=%d begy=%d begx=%d\n",
112 nlines, ncols, begy, begx));
113
114 if (!orig || !(orig->_flags & _PAD))
115 return (WINDOW *)NULL;
116
117 /* make sure window fits inside the original one */
118
119 if (begy < 0 || begx < 0 ||
120 (begy + nlines) > orig->_maxy ||
121 (begx + ncols) > orig->_maxx)
122 return (WINDOW *)NULL;
123
124 if (!nlines)
125 nlines = orig->_maxy - begy;
126
127 if (!ncols)
128 ncols = orig->_maxx - begx;
129
130 win = PDC_makenew(nlines, ncols, begy, begx);
131 if (!win)
132 return (WINDOW *)NULL;
133
134 /* initialize window variables */
135
136 win->_attrs = orig->_attrs;
137 win->_leaveit = orig->_leaveit;
138 win->_scroll = orig->_scroll;
139 win->_nodelay = orig->_nodelay;
140 win->_use_keypad = orig->_use_keypad;
141 win->_parent = orig;
142
143 for (i = 0; i < nlines; i++)
144 win->_y[i] = orig->_y[begy + i] + begx;
145
146 win->_flags = _SUBPAD;
147 win->_pad._pad_y = 0;
148 win->_pad._pad_x = 0;
149 win->_pad._pad_top = 0;
150 win->_pad._pad_left = 0;
151 win->_pad._pad_bottom = min(LINES, nlines) - 1;
152 win->_pad._pad_right = min(COLS, ncols) - 1;
153
154 return win;
155}
156
157int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2)
158{
159 PDC_LOG(("prefresh() - called\n"));
160
161 if (pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2) == ERR)
162 return ERR;
163
164 doupdate();
165 return OK;
166}
167
168int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, int sx2)
169{
170 int num_cols;
171 int sline;
172 int pline;
173
174 PDC_LOG(("pnoutrefresh() - called\n"));
175
176 if (py < 0)
177 py = 0;
178 if (px < 0)
179 px = 0;
180 if (sy1 < 0)
181 sy1 = 0;
182 if (sx1 < 0)
183 sx1 = 0;
184
185 if ((!w || !(w->_flags & (_PAD|_SUBPAD)) ||
186 (sy2 >= LINES) || (sx2 >= COLS)) ||
187 (sy2 < sy1) || (sx2 < sx1))
188 return ERR;
189
190 sline = sy1;
191 pline = py;
192
193 num_cols = min((sx2 - sx1 + 1), (w->_maxx - px));
194
195 while (sline <= sy2)
196 {
197 if (pline < w->_maxy)
198 {
199 memcpy(curscr->_y[sline] + sx1, w->_y[pline] + px,
200 num_cols * sizeof(chtype));
201
202 if ((curscr->_firstch[sline] == _NO_CHANGE)
203 || (curscr->_firstch[sline] > sx1))
204 curscr->_firstch[sline] = sx1;
205
206 if (sx2 > curscr->_lastch[sline])
207 curscr->_lastch[sline] = sx2;
208
209 w->_firstch[pline] = _NO_CHANGE; /* updated now */
210 w->_lastch[pline] = _NO_CHANGE; /* updated now */
211 }
212
213 sline++;
214 pline++;
215 }
216
217 if (w->_clear)
218 {
219 w->_clear = FALSE;
220 curscr->_clear = TRUE;
221 }
222
223 /* position the cursor to the pad's current position if possible --
224 is the pad current position going to end up displayed? if not,
225 then don't move the cursor; if so, move it to the correct place */
226
227 if (!w->_leaveit && w->_cury >= py && w->_curx >= px &&
228 w->_cury <= py + (sy2 - sy1) && w->_curx <= px + (sx2 - sx1))
229 {
230 curscr->_cury = (w->_cury - py) + sy1;
231 curscr->_curx = (w->_curx - px) + sx1;
232 }
233
234 w->_pad._pad_y = py;
235 w->_pad._pad_x = px;
236 w->_pad._pad_top = sy1;
237 w->_pad._pad_left = sx1;
238 w->_pad._pad_bottom = sy2;
239 w->_pad._pad_right = sx2;
240
241 return OK;
242}
243
244int pechochar(WINDOW *pad, chtype ch)
245{
246 PDC_LOG(("pechochar() - called\n"));
247
248 if (waddch(pad, ch) == ERR)
249 return ERR;
250
251 return prefresh(pad, pad->_pad._pad_y, pad->_pad._pad_x, pad->_pad._pad_top,
252 pad->_pad._pad_left, pad->_pad._pad_bottom, pad->_pad._pad_right);
253}
254
255#ifdef PDC_WIDE
256int pecho_wchar(WINDOW *pad, const cchar_t *wch)
257{
258 PDC_LOG(("pecho_wchar() - called\n"));
259
260 if (!wch || (waddch(pad, *wch) == ERR))
261 return ERR;
262
263 return prefresh(pad, pad->_pad._pad_y, pad->_pad._pad_x, pad->_pad._pad_top,
264 pad->_pad._pad_left, pad->_pad._pad_bottom, pad->_pad._pad_right);
265}
266#endif
267
268bool is_pad(const WINDOW *pad)
269{
270 PDC_LOG(("is_pad() - called\n"));
271
272 if (!pad)
273 return FALSE;
274
275 return (pad->_flags & _PAD) ? TRUE : FALSE;
276}
diff --git a/scripts/kconfig/libcurses/pdcclip.c b/scripts/kconfig/libcurses/pdcclip.c
new file mode 100644
index 000000000..6184ad2d9
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdcclip.c
@@ -0,0 +1,155 @@
1/* PDCurses */
2
3#include "pdcwin.h"
4
5#include <string.h>
6
7/*man-start**************************************************************
8
9clipboard
10---------
11
12### Synopsis
13
14 int PDC_getclipboard(char **contents, long *length);
15 int PDC_setclipboard(const char *contents, long length);
16 int PDC_freeclipboard(char *contents);
17 int PDC_clearclipboard(void);
18
19### Description
20
21 PDC_getclipboard() gets the textual contents of the system's
22 clipboard. This function returns the contents of the clipboard in the
23 contents argument. It is the responsibility of the caller to free the
24 memory returned, via PDC_freeclipboard(). The length of the clipboard
25 contents is returned in the length argument.
26
27 PDC_setclipboard() copies the supplied text into the system's
28 clipboard, emptying the clipboard prior to the copy.
29
30 PDC_clearclipboard() clears the internal clipboard.
31
32### Return Values
33
34 PDC_CLIP_SUCCESS the call was successful
35 PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
36 the clipboard contents
37 PDC_CLIP_EMPTY the clipboard contains no text
38 PDC_CLIP_ACCESS_ERROR no clipboard support
39
40### Portability
41
42 Function | X/Open | ncurses | NetBSD
43 :---------------------|:------:|:-------:|:------:
44 PDC_getclipboard | - | - | -
45 PDC_setclipboard | - | - | -
46 PDC_freeclipboard | - | - | -
47 PDC_clearclipboard | - | - | -
48
49**man-end****************************************************************/
50
51#ifdef PDC_WIDE
52# define PDC_TEXT CF_UNICODETEXT
53#else
54# define PDC_TEXT CF_OEMTEXT
55#endif
56
57int PDC_getclipboard(char **contents, long *length)
58{
59 HANDLE handle;
60 long len;
61
62 PDC_LOG(("PDC_getclipboard() - called\n"));
63
64 if (!OpenClipboard(NULL))
65 return PDC_CLIP_ACCESS_ERROR;
66
67 if ((handle = GetClipboardData(PDC_TEXT)) == NULL)
68 {
69 CloseClipboard();
70 return PDC_CLIP_EMPTY;
71 }
72
73#ifdef PDC_WIDE
74 len = wcslen((wchar_t *)handle) * 3;
75#else
76 len = strlen((char *)handle);
77#endif
78 *contents = (char *)GlobalAlloc(GMEM_FIXED, len + 1);
79
80 if (!*contents)
81 {
82 CloseClipboard();
83 return PDC_CLIP_MEMORY_ERROR;
84 }
85
86#ifdef PDC_WIDE
87 len = PDC_wcstombs((char *)*contents, (wchar_t *)handle, len);
88#else
89 strcpy((char *)*contents, (char *)handle);
90#endif
91 *length = len;
92 CloseClipboard();
93
94 return PDC_CLIP_SUCCESS;
95}
96
97int PDC_setclipboard(const char *contents, long length)
98{
99 HGLOBAL ptr1;
100 LPTSTR ptr2;
101
102 PDC_LOG(("PDC_setclipboard() - called\n"));
103
104 if (!OpenClipboard(NULL))
105 return PDC_CLIP_ACCESS_ERROR;
106
107 ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
108 (length + 1) * sizeof(TCHAR));
109
110 if (!ptr1)
111 return PDC_CLIP_MEMORY_ERROR;
112
113 ptr2 = GlobalLock(ptr1);
114
115#ifdef PDC_WIDE
116 PDC_mbstowcs((wchar_t *)ptr2, contents, length);
117#else
118 memcpy((char *)ptr2, contents, length + 1);
119#endif
120 GlobalUnlock(ptr1);
121 EmptyClipboard();
122
123 if (!SetClipboardData(PDC_TEXT, ptr1))
124 {
125 GlobalFree(ptr1);
126 return PDC_CLIP_ACCESS_ERROR;
127 }
128
129 CloseClipboard();
130 GlobalFree(ptr1);
131
132 return PDC_CLIP_SUCCESS;
133}
134
135int PDC_freeclipboard(char *contents)
136{
137 PDC_LOG(("PDC_freeclipboard() - called\n"));
138
139 GlobalFree(contents);
140 return PDC_CLIP_SUCCESS;
141}
142
143int PDC_clearclipboard(void)
144{
145 PDC_LOG(("PDC_clearclipboard() - called\n"));
146
147 if (OpenClipboard(NULL))
148 if (EmptyClipboard())
149 {
150 CloseClipboard();
151 return PDC_CLIP_SUCCESS;
152 }
153
154 return PDC_CLIP_ACCESS_ERROR;
155}
diff --git a/scripts/kconfig/libcurses/pdcdisp.c b/scripts/kconfig/libcurses/pdcdisp.c
new file mode 100644
index 000000000..f6115ecb0
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdcdisp.c
@@ -0,0 +1,329 @@
1/* PDCurses */
2
3#include "pdcwin.h"
4
5#include <stdlib.h>
6#include <string.h>
7
8#ifdef PDC_WIDE
9# include "acsuni.h"
10#else
11# include "acs437.h"
12#endif
13
14DWORD pdc_last_blink;
15static bool blinked_off = FALSE;
16static bool in_italic = FALSE;
17
18/* position hardware cursor at (y, x) */
19
20void PDC_gotoyx(int row, int col)
21{
22 COORD coord;
23
24 PDC_LOG(("PDC_gotoyx() - called: row %d col %d from row %d col %d\n",
25 row, col, SP->cursrow, SP->curscol));
26
27 coord.X = col;
28 coord.Y = row;
29
30 SetConsoleCursorPosition(pdc_con_out, coord);
31}
32
33void _set_ansi_color(short f, short b, attr_t attr)
34{
35 char esc[64], *p;
36 short tmp, underline;
37 bool italic;
38
39 if (f < 16 && !pdc_color[f].mapped)
40 f = pdc_curstoansi[f];
41
42 if (b < 16 && !pdc_color[b].mapped)
43 b = pdc_curstoansi[b];
44
45 if (attr & A_REVERSE)
46 {
47 tmp = f;
48 f = b;
49 b = tmp;
50 }
51 attr &= SP->termattrs;
52 italic = !!(attr & A_ITALIC);
53 underline = !!(attr & A_UNDERLINE);
54
55 p = esc + sprintf(esc, "\x1b[");
56
57 if (f != pdc_oldf)
58 {
59 if (f < 8 && !pdc_color[f].mapped)
60 p += sprintf(p, "%d", f + 30);
61 else if (f < 16 && !pdc_color[f].mapped)
62 p += sprintf(p, "%d", f + 82);
63 else if (f < 256 && !pdc_color[f].mapped)
64 p += sprintf(p, "38;5;%d", f);
65 else
66 {
67 short red = DIVROUND(pdc_color[f].r * 255, 1000);
68 short green = DIVROUND(pdc_color[f].g * 255, 1000);
69 short blue = DIVROUND(pdc_color[f].b * 255, 1000);
70
71 p += sprintf(p, "38;2;%d;%d;%d", red, green, blue);
72 }
73
74 pdc_oldf = f;
75 }
76
77 if (b != pdc_oldb)
78 {
79 if (strlen(esc) > 2)
80 p += sprintf(p, ";");
81
82 if (b < 8 && !pdc_color[b].mapped)
83 p += sprintf(p, "%d", b + 40);
84 else if (b < 16 && !pdc_color[b].mapped)
85 p += sprintf(p, "%d", b + 92);
86 else if (b < 256 && !pdc_color[b].mapped)
87 p += sprintf(p, "48;5;%d", b);
88 else
89 {
90 short red = DIVROUND(pdc_color[b].r * 255, 1000);
91 short green = DIVROUND(pdc_color[b].g * 255, 1000);
92 short blue = DIVROUND(pdc_color[b].b * 255, 1000);
93
94 p += sprintf(p, "48;2;%d;%d;%d", red, green, blue);
95 }
96
97 pdc_oldb = b;
98 }
99
100 if (italic != in_italic)
101 {
102 if (strlen(esc) > 2)
103 p += sprintf(p, ";");
104
105 if (italic)
106 p += sprintf(p, "3");
107 else
108 p += sprintf(p, "23");
109
110 in_italic = italic;
111 }
112
113 if (underline != pdc_oldu)
114 {
115 if (strlen(esc) > 2)
116 p += sprintf(p, ";");
117
118 if (underline)
119 p += sprintf(p, "4");
120 else
121 p += sprintf(p, "24");
122
123 pdc_oldu = underline;
124 }
125
126 if (strlen(esc) > 2)
127 {
128 sprintf(p, "m");
129 if (!pdc_conemu)
130 SetConsoleMode(pdc_con_out, 0x0015);
131
132 WriteConsoleA(pdc_con_out, esc, strlen(esc), NULL, NULL);
133
134 if (!pdc_conemu)
135 SetConsoleMode(pdc_con_out, 0x0010);
136 }
137}
138
139void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp)
140{
141 int j;
142 short fore, back;
143 bool blink, ansi;
144
145 if (pdc_ansi && (lineno == (SP->lines - 1)) && ((x + len) == SP->cols))
146 {
147 len--;
148 if (len)
149 _new_packet(attr, lineno, x, len, srcp);
150 pdc_ansi = FALSE;
151 _new_packet(attr, lineno, x + len, 1, srcp + len);
152 pdc_ansi = TRUE;
153 return;
154 }
155
156 pair_content(PAIR_NUMBER(attr), &fore, &back);
157 ansi = pdc_ansi || (fore >= 16 || back >= 16);
158 blink = (SP->termattrs & A_BLINK) && (attr & A_BLINK);
159
160 if (blink)
161 {
162 attr &= ~A_BLINK;
163 if (blinked_off)
164 attr &= ~(A_UNDERLINE | A_RIGHT | A_LEFT);
165 }
166
167 if (attr & A_BOLD)
168 fore |= 8;
169 if (attr & A_BLINK)
170 back |= 8;
171
172 if (ansi)
173 {
174#ifdef PDC_WIDE
175 WCHAR buffer[512];
176#else
177 char buffer[512];
178#endif
179 for (j = 0; j < len; j++)
180 {
181 chtype ch = srcp[j];
182
183 if (ch & A_ALTCHARSET && !(ch & 0xff80))
184 {
185 ch = acs_map[ch & 0x7f];
186
187 if (pdc_wt && (ch & A_CHARTEXT) < ' ')
188 goto NONANSI;
189 }
190
191 if (blink && blinked_off)
192 ch = ' ';
193
194 buffer[j] = ch & A_CHARTEXT;
195 }
196
197 PDC_gotoyx(lineno, x);
198 _set_ansi_color(fore, back, attr);
199#ifdef PDC_WIDE
200 WriteConsoleW(pdc_con_out, buffer, len, NULL, NULL);
201#else
202 WriteConsoleA(pdc_con_out, buffer, len, NULL, NULL);
203#endif
204 }
205 else
206NONANSI:
207 {
208 CHAR_INFO buffer[512];
209 COORD bufSize, bufPos;
210 SMALL_RECT sr;
211 WORD mapped_attr;
212
213 fore = pdc_curstoreal[fore];
214 back = pdc_curstoreal[back];
215
216 if (attr & A_REVERSE)
217 mapped_attr = back | (fore << 4);
218 else
219 mapped_attr = fore | (back << 4);
220
221 if (attr & A_UNDERLINE)
222 mapped_attr |= 0x8000; /* COMMON_LVB_UNDERSCORE */
223 if (attr & A_LEFT)
224 mapped_attr |= 0x0800; /* COMMON_LVB_GRID_LVERTICAL */
225 if (attr & A_RIGHT)
226 mapped_attr |= 0x1000; /* COMMON_LVB_GRID_RVERTICAL */
227
228 for (j = 0; j < len; j++)
229 {
230 chtype ch = srcp[j];
231
232 if (ch & A_ALTCHARSET && !(ch & 0xff80))
233 ch = acs_map[ch & 0x7f];
234
235 if (blink && blinked_off)
236 ch = ' ';
237
238 buffer[j].Attributes = mapped_attr;
239 buffer[j].Char.UnicodeChar = ch & A_CHARTEXT;
240 }
241
242 bufPos.X = bufPos.Y = 0;
243 bufSize.X = len;
244 bufSize.Y = 1;
245
246 sr.Top = sr.Bottom = lineno;
247 sr.Left = x;
248 sr.Right = x + len - 1;
249
250 WriteConsoleOutput(pdc_con_out, buffer, bufSize, bufPos, &sr);
251 }
252}
253
254/* update the given physical line to look like the corresponding line in
255 curscr */
256
257void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
258{
259 attr_t old_attr, attr;
260 int i, j;
261
262 PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno));
263
264 old_attr = *srcp & (A_ATTRIBUTES ^ A_ALTCHARSET);
265
266 for (i = 1, j = 1; j < len; i++, j++)
267 {
268 attr = srcp[i] & (A_ATTRIBUTES ^ A_ALTCHARSET);
269
270 if (attr != old_attr)
271 {
272 _new_packet(old_attr, lineno, x, i, srcp);
273 old_attr = attr;
274 srcp += i;
275 x += i;
276 i = 0;
277 }
278 }
279
280 _new_packet(old_attr, lineno, x, i, srcp);
281}
282
283void PDC_blink_text(void)
284{
285 CONSOLE_CURSOR_INFO cci;
286 int i, j, k;
287 bool oldvis;
288
289 GetConsoleCursorInfo(pdc_con_out, &cci);
290 oldvis = cci.bVisible;
291 if (oldvis)
292 {
293 cci.bVisible = FALSE;
294 SetConsoleCursorInfo(pdc_con_out, &cci);
295 }
296
297 if (!(SP->termattrs & A_BLINK))
298 blinked_off = FALSE;
299 else
300 blinked_off = !blinked_off;
301
302 for (i = 0; i < SP->lines; i++)
303 {
304 const chtype *srcp = curscr->_y[i];
305
306 for (j = 0; j < SP->cols; j++)
307 if (srcp[j] & A_BLINK)
308 {
309 k = j;
310 while (k < SP->cols && (srcp[k] & A_BLINK))
311 k++;
312 PDC_transform_line(i, j, k - j, srcp + j);
313 j = k;
314 }
315 }
316
317 PDC_gotoyx(SP->cursrow, SP->curscol);
318 if (oldvis)
319 {
320 cci.bVisible = TRUE;
321 SetConsoleCursorInfo(pdc_con_out, &cci);
322 }
323
324 pdc_last_blink = GetTickCount();
325}
326
327void PDC_doupdate(void)
328{
329}
diff --git a/scripts/kconfig/libcurses/pdcgetsc.c b/scripts/kconfig/libcurses/pdcgetsc.c
new file mode 100644
index 000000000..a8323ebc1
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdcgetsc.c
@@ -0,0 +1,42 @@
1/* PDCurses */
2
3#include "pdcwin.h"
4
5/* get the cursor size/shape */
6
7int PDC_get_cursor_mode(void)
8{
9 CONSOLE_CURSOR_INFO ci;
10
11 PDC_LOG(("PDC_get_cursor_mode() - called\n"));
12
13 GetConsoleCursorInfo(pdc_con_out, &ci);
14
15 return ci.dwSize;
16}
17
18/* return number of screen rows */
19
20int PDC_get_rows(void)
21{
22 CONSOLE_SCREEN_BUFFER_INFO scr;
23
24 PDC_LOG(("PDC_get_rows() - called\n"));
25
26 GetConsoleScreenBufferInfo(pdc_con_out, &scr);
27
28 return scr.srWindow.Bottom - scr.srWindow.Top + 1;
29}
30
31/* return width of screen/viewport */
32
33int PDC_get_columns(void)
34{
35 CONSOLE_SCREEN_BUFFER_INFO scr;
36
37 PDC_LOG(("PDC_get_columns() - called\n"));
38
39 GetConsoleScreenBufferInfo(pdc_con_out, &scr);
40
41 return scr.srWindow.Right - scr.srWindow.Left + 1;
42}
diff --git a/scripts/kconfig/libcurses/pdckbd.c b/scripts/kconfig/libcurses/pdckbd.c
new file mode 100644
index 000000000..cbab60d63
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdckbd.c
@@ -0,0 +1,693 @@
1/* PDCurses */
2
3#include "pdcwin.h"
4
5/* These variables are used to store information about the next
6 Input Event. */
7
8static INPUT_RECORD save_ip;
9static MOUSE_STATUS old_mouse_status;
10static DWORD event_count = 0;
11static SHORT left_key;
12static int key_count = 0;
13static int save_press = 0;
14
15#define KEV save_ip.Event.KeyEvent
16#define MEV save_ip.Event.MouseEvent
17#define REV save_ip.Event.WindowBufferSizeEvent
18
19/************************************************************************
20 * Table for key code translation of function keys in keypad mode *
21 * These values are for strict IBM keyboard compatibles only *
22 ************************************************************************/
23
24typedef struct
25{
26 unsigned short normal;
27 unsigned short shift;
28 unsigned short control;
29 unsigned short alt;
30 unsigned short extended;
31} KPTAB;
32
33static KPTAB kptab[] =
34{
35 {0, 0, 0, 0, 0 }, /* 0 */
36 {0, 0, 0, 0, 0 }, /* 1 VK_LBUTTON */
37 {0, 0, 0, 0, 0 }, /* 2 VK_RBUTTON */
38 {0, 0, 0, 0, 0 }, /* 3 VK_CANCEL */
39 {0, 0, 0, 0, 0 }, /* 4 VK_MBUTTON */
40 {0, 0, 0, 0, 0 }, /* 5 */
41 {0, 0, 0, 0, 0 }, /* 6 */
42 {0, 0, 0, 0, 0 }, /* 7 */
43 {0x08, 0x08, 0x7F, ALT_BKSP, 0 }, /* 8 VK_BACK */
44 {0x09, KEY_BTAB, CTL_TAB, ALT_TAB, 999 }, /* 9 VK_TAB */
45 {0, 0, 0, 0, 0 }, /* 10 */
46 {0, 0, 0, 0, 0 }, /* 11 */
47 {KEY_B2, 0x35, CTL_PAD5, ALT_PAD5, 0 }, /* 12 VK_CLEAR */
48 {0x0D, 0x0D, CTL_ENTER, ALT_ENTER, 1 }, /* 13 VK_RETURN */
49 {0, 0, 0, 0, 0 }, /* 14 */
50 {0, 0, 0, 0, 0 }, /* 15 */
51 {0, 0, 0, 0, 0 }, /* 16 VK_SHIFT HANDLED SEPARATELY */
52 {0, 0, 0, 0, 0 }, /* 17 VK_CONTROL HANDLED SEPARATELY */
53 {0, 0, 0, 0, 0 }, /* 18 VK_MENU HANDLED SEPARATELY */
54 {0, 0, 0, 0, 0 }, /* 19 VK_PAUSE */
55 {0, 0, 0, 0, 0 }, /* 20 VK_CAPITAL HANDLED SEPARATELY */
56 {0, 0, 0, 0, 0 }, /* 21 VK_HANGUL */
57 {0, 0, 0, 0, 0 }, /* 22 */
58 {0, 0, 0, 0, 0 }, /* 23 VK_JUNJA */
59 {0, 0, 0, 0, 0 }, /* 24 VK_FINAL */
60 {0, 0, 0, 0, 0 }, /* 25 VK_HANJA */
61 {0, 0, 0, 0, 0 }, /* 26 */
62 {0x1B, 0x1B, 0x1B, ALT_ESC, 0 }, /* 27 VK_ESCAPE */
63 {0, 0, 0, 0, 0 }, /* 28 VK_CONVERT */
64 {0, 0, 0, 0, 0 }, /* 29 VK_NONCONVERT */
65 {0, 0, 0, 0, 0 }, /* 30 VK_ACCEPT */
66 {0, 0, 0, 0, 0 }, /* 31 VK_MODECHANGE */
67 {0x20, 0x20, 0x20, 0x20, 0 }, /* 32 VK_SPACE */
68 {KEY_A3, 0x39, CTL_PAD9, ALT_PAD9, 3 }, /* 33 VK_PRIOR */
69 {KEY_C3, 0x33, CTL_PAD3, ALT_PAD3, 4 }, /* 34 VK_NEXT */
70 {KEY_C1, 0x31, CTL_PAD1, ALT_PAD1, 5 }, /* 35 VK_END */
71 {KEY_A1, 0x37, CTL_PAD7, ALT_PAD7, 6 }, /* 36 VK_HOME */
72 {KEY_B1, 0x34, CTL_PAD4, ALT_PAD4, 7 }, /* 37 VK_LEFT */
73 {KEY_A2, 0x38, CTL_PAD8, ALT_PAD8, 8 }, /* 38 VK_UP */
74 {KEY_B3, 0x36, CTL_PAD6, ALT_PAD6, 9 }, /* 39 VK_RIGHT */
75 {KEY_C2, 0x32, CTL_PAD2, ALT_PAD2, 10 }, /* 40 VK_DOWN */
76 {0, 0, 0, 0, 0 }, /* 41 VK_SELECT */
77 {0, 0, 0, 0, 0 }, /* 42 VK_PRINT */
78 {0, 0, 0, 0, 0 }, /* 43 VK_EXECUTE */
79 {0, 0, 0, 0, 0 }, /* 44 VK_SNAPSHOT*/
80 {PAD0, 0x30, CTL_PAD0, ALT_PAD0, 11 }, /* 45 VK_INSERT */
81 {PADSTOP, 0x2E, CTL_PADSTOP, ALT_PADSTOP,12 }, /* 46 VK_DELETE */
82 {0, 0, 0, 0, 0 }, /* 47 VK_HELP */
83 {0x30, 0x29, 0, ALT_0, 0 }, /* 48 */
84 {0x31, 0x21, 0, ALT_1, 0 }, /* 49 */
85 {0x32, 0x40, 0, ALT_2, 0 }, /* 50 */
86 {0x33, 0x23, 0, ALT_3, 0 }, /* 51 */
87 {0x34, 0x24, 0, ALT_4, 0 }, /* 52 */
88 {0x35, 0x25, 0, ALT_5, 0 }, /* 53 */
89 {0x36, 0x5E, 0, ALT_6, 0 }, /* 54 */
90 {0x37, 0x26, 0, ALT_7, 0 }, /* 55 */
91 {0x38, 0x2A, 0, ALT_8, 0 }, /* 56 */
92 {0x39, 0x28, 0, ALT_9, 0 }, /* 57 */
93 {0, 0, 0, 0, 0 }, /* 58 */
94 {0, 0, 0, 0, 0 }, /* 59 */
95 {0, 0, 0, 0, 0 }, /* 60 */
96 {0, 0, 0, 0, 0 }, /* 61 */
97 {0, 0, 0, 0, 0 }, /* 62 */
98 {0, 0, 0, 0, 0 }, /* 63 */
99 {0, 0, 0, 0, 0 }, /* 64 */
100 {0x61, 0x41, 0x01, ALT_A, 0 }, /* 65 */
101 {0x62, 0x42, 0x02, ALT_B, 0 }, /* 66 */
102 {0x63, 0x43, 0x03, ALT_C, 0 }, /* 67 */
103 {0x64, 0x44, 0x04, ALT_D, 0 }, /* 68 */
104 {0x65, 0x45, 0x05, ALT_E, 0 }, /* 69 */
105 {0x66, 0x46, 0x06, ALT_F, 0 }, /* 70 */
106 {0x67, 0x47, 0x07, ALT_G, 0 }, /* 71 */
107 {0x68, 0x48, 0x08, ALT_H, 0 }, /* 72 */
108 {0x69, 0x49, 0x09, ALT_I, 0 }, /* 73 */
109 {0x6A, 0x4A, 0x0A, ALT_J, 0 }, /* 74 */
110 {0x6B, 0x4B, 0x0B, ALT_K, 0 }, /* 75 */
111 {0x6C, 0x4C, 0x0C, ALT_L, 0 }, /* 76 */
112 {0x6D, 0x4D, 0x0D, ALT_M, 0 }, /* 77 */
113 {0x6E, 0x4E, 0x0E, ALT_N, 0 }, /* 78 */
114 {0x6F, 0x4F, 0x0F, ALT_O, 0 }, /* 79 */
115 {0x70, 0x50, 0x10, ALT_P, 0 }, /* 80 */
116 {0x71, 0x51, 0x11, ALT_Q, 0 }, /* 81 */
117 {0x72, 0x52, 0x12, ALT_R, 0 }, /* 82 */
118 {0x73, 0x53, 0x13, ALT_S, 0 }, /* 83 */
119 {0x74, 0x54, 0x14, ALT_T, 0 }, /* 84 */
120 {0x75, 0x55, 0x15, ALT_U, 0 }, /* 85 */
121 {0x76, 0x56, 0x16, ALT_V, 0 }, /* 86 */
122 {0x77, 0x57, 0x17, ALT_W, 0 }, /* 87 */
123 {0x78, 0x58, 0x18, ALT_X, 0 }, /* 88 */
124 {0x79, 0x59, 0x19, ALT_Y, 0 }, /* 89 */
125 {0x7A, 0x5A, 0x1A, ALT_Z, 0 }, /* 90 */
126 {0, 0, 0, 0, 0 }, /* 91 VK_LWIN */
127 {0, 0, 0, 0, 0 }, /* 92 VK_RWIN */
128 {0, 0, 0, 0, 0 }, /* 93 VK_APPS */
129 {0, 0, 0, 0, 0 }, /* 94 */
130 {0, 0, 0, 0, 0 }, /* 95 */
131 {0x30, 0, CTL_PAD0, ALT_PAD0, 0 }, /* 96 VK_NUMPAD0 */
132 {0x31, 0, CTL_PAD1, ALT_PAD1, 0 }, /* 97 VK_NUMPAD1 */
133 {0x32, 0, CTL_PAD2, ALT_PAD2, 0 }, /* 98 VK_NUMPAD2 */
134 {0x33, 0, CTL_PAD3, ALT_PAD3, 0 }, /* 99 VK_NUMPAD3 */
135 {0x34, 0, CTL_PAD4, ALT_PAD4, 0 }, /* 100 VK_NUMPAD4 */
136 {0x35, 0, CTL_PAD5, ALT_PAD5, 0 }, /* 101 VK_NUMPAD5 */
137 {0x36, 0, CTL_PAD6, ALT_PAD6, 0 }, /* 102 VK_NUMPAD6 */
138 {0x37, 0, CTL_PAD7, ALT_PAD7, 0 }, /* 103 VK_NUMPAD7 */
139 {0x38, 0, CTL_PAD8, ALT_PAD8, 0 }, /* 104 VK_NUMPAD8 */
140 {0x39, 0, CTL_PAD9, ALT_PAD9, 0 }, /* 105 VK_NUMPAD9 */
141 {PADSTAR, SHF_PADSTAR,CTL_PADSTAR, ALT_PADSTAR,999 }, /* 106 VK_MULTIPLY*/
142 {PADPLUS, SHF_PADPLUS,CTL_PADPLUS, ALT_PADPLUS,999 }, /* 107 VK_ADD */
143 {0, 0, 0, 0, 0 }, /* 108 VK_SEPARATOR */
144 {PADMINUS, SHF_PADMINUS,CTL_PADMINUS,ALT_PADMINUS,999}, /* 109 VK_SUBTRACT*/
145 {0x2E, 0, CTL_PADSTOP, ALT_PADSTOP,0 }, /* 110 VK_DECIMAL */
146 {PADSLASH, SHF_PADSLASH,CTL_PADSLASH,ALT_PADSLASH,2 }, /* 111 VK_DIVIDE */
147 {KEY_F(1), KEY_F(13), KEY_F(25), KEY_F(37), 0 }, /* 112 VK_F1 */
148 {KEY_F(2), KEY_F(14), KEY_F(26), KEY_F(38), 0 }, /* 113 VK_F2 */
149 {KEY_F(3), KEY_F(15), KEY_F(27), KEY_F(39), 0 }, /* 114 VK_F3 */
150 {KEY_F(4), KEY_F(16), KEY_F(28), KEY_F(40), 0 }, /* 115 VK_F4 */
151 {KEY_F(5), KEY_F(17), KEY_F(29), KEY_F(41), 0 }, /* 116 VK_F5 */
152 {KEY_F(6), KEY_F(18), KEY_F(30), KEY_F(42), 0 }, /* 117 VK_F6 */
153 {KEY_F(7), KEY_F(19), KEY_F(31), KEY_F(43), 0 }, /* 118 VK_F7 */
154 {KEY_F(8), KEY_F(20), KEY_F(32), KEY_F(44), 0 }, /* 119 VK_F8 */
155 {KEY_F(9), KEY_F(21), KEY_F(33), KEY_F(45), 0 }, /* 120 VK_F9 */
156 {KEY_F(10), KEY_F(22), KEY_F(34), KEY_F(46), 0 }, /* 121 VK_F10 */
157 {KEY_F(11), KEY_F(23), KEY_F(35), KEY_F(47), 0 }, /* 122 VK_F11 */
158 {KEY_F(12), KEY_F(24), KEY_F(36), KEY_F(48), 0 }, /* 123 VK_F12 */
159
160 /* 124 through 218 */
161
162 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
163 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
164 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
165 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
166 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
167 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
168 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
169 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
170 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
171 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
172 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
173 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
174 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
175 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
176 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
177 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
178 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
179 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
180 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
181 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
182 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
183 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
184 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
185 {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
186
187 {0x5B, 0x7B, 0x1B, ALT_LBRACKET,0 }, /* 219 */
188 {0x5C, 0x7C, 0x1C, ALT_BSLASH, 0 }, /* 220 */
189 {0x5D, 0x7D, 0x1D, ALT_RBRACKET,0 }, /* 221 */
190 {0, 0, 0x27, ALT_FQUOTE, 0 }, /* 222 */
191 {0, 0, 0, 0, 0 }, /* 223 */
192 {0, 0, 0, 0, 0 }, /* 224 */
193 {0, 0, 0, 0, 0 }, /* 225 */
194 {0, 0, 0, 0, 0 }, /* 226 */
195 {0, 0, 0, 0, 0 }, /* 227 */
196 {0, 0, 0, 0, 0 }, /* 228 */
197 {0, 0, 0, 0, 0 }, /* 229 */
198 {0, 0, 0, 0, 0 }, /* 230 */
199 {0, 0, 0, 0, 0 }, /* 231 */
200 {0, 0, 0, 0, 0 }, /* 232 */
201 {0, 0, 0, 0, 0 }, /* 233 */
202 {0, 0, 0, 0, 0 }, /* 234 */
203 {0, 0, 0, 0, 0 }, /* 235 */
204 {0, 0, 0, 0, 0 }, /* 236 */
205 {0, 0, 0, 0, 0 }, /* 237 */
206 {0, 0, 0, 0, 0 }, /* 238 */
207 {0, 0, 0, 0, 0 }, /* 239 */
208 {0, 0, 0, 0, 0 }, /* 240 */
209 {0, 0, 0, 0, 0 }, /* 241 */
210 {0, 0, 0, 0, 0 }, /* 242 */
211 {0, 0, 0, 0, 0 }, /* 243 */
212 {0, 0, 0, 0, 0 }, /* 244 */
213 {0, 0, 0, 0, 0 }, /* 245 */
214 {0, 0, 0, 0, 0 }, /* 246 */
215 {0, 0, 0, 0, 0 }, /* 247 */
216 {0, 0, 0, 0, 0 }, /* 248 */
217 {0, 0, 0, 0, 0 }, /* 249 */
218 {0, 0, 0, 0, 0 }, /* 250 */
219 {0, 0, 0, 0, 0 }, /* 251 */
220 {0, 0, 0, 0, 0 }, /* 252 */
221 {0, 0, 0, 0, 0 }, /* 253 */
222 {0, 0, 0, 0, 0 }, /* 254 */
223 {0, 0, 0, 0, 0 } /* 255 */
224};
225
226static KPTAB ext_kptab[] =
227{
228 {0, 0, 0, 0, }, /* MUST BE EMPTY */
229 {PADENTER, SHF_PADENTER, CTL_PADENTER, ALT_PADENTER}, /* 13 */
230 {PADSLASH, SHF_PADSLASH, CTL_PADSLASH, ALT_PADSLASH}, /* 111 */
231 {KEY_PPAGE, KEY_SPREVIOUS, CTL_PGUP, ALT_PGUP }, /* 33 */
232 {KEY_NPAGE, KEY_SNEXT, CTL_PGDN, ALT_PGDN }, /* 34 */
233 {KEY_END, KEY_SEND, CTL_END, ALT_END }, /* 35 */
234 {KEY_HOME, KEY_SHOME, CTL_HOME, ALT_HOME }, /* 36 */
235 {KEY_LEFT, KEY_SLEFT, CTL_LEFT, ALT_LEFT }, /* 37 */
236 {KEY_UP, KEY_SUP, CTL_UP, ALT_UP }, /* 38 */
237 {KEY_RIGHT, KEY_SRIGHT, CTL_RIGHT, ALT_RIGHT }, /* 39 */
238 {KEY_DOWN, KEY_SDOWN, CTL_DOWN, ALT_DOWN }, /* 40 */
239 {KEY_IC, KEY_SIC, CTL_INS, ALT_INS }, /* 45 */
240 {KEY_DC, KEY_SDC, CTL_DEL, ALT_DEL }, /* 46 */
241 {PADSLASH, SHF_PADSLASH, CTL_PADSLASH, ALT_PADSLASH}, /* 191 */
242};
243
244/* End of kptab[] */
245
246void PDC_set_keyboard_binary(bool on)
247{
248 DWORD mode;
249
250 PDC_LOG(("PDC_set_keyboard_binary() - called\n"));
251
252 GetConsoleMode(pdc_con_in, &mode);
253 SetConsoleMode(pdc_con_in, !on ? (mode | ENABLE_PROCESSED_INPUT) :
254 (mode & ~ENABLE_PROCESSED_INPUT));
255}
256
257/* check if a key or mouse event is waiting */
258
259bool PDC_check_key(void)
260{
261 if (key_count > 0)
262 return TRUE;
263
264 GetNumberOfConsoleInputEvents(pdc_con_in, &event_count);
265
266 return (event_count != 0);
267}
268
269/* _get_key_count returns 0 if save_ip doesn't contain an event which
270 should be passed back to the user. This function filters "useless"
271 events.
272
273 The function returns the number of keys waiting. This may be > 1
274 if the repetition of real keys pressed so far are > 1.
275
276 Returns 0 on NUMLOCK, CAPSLOCK, SCROLLLOCK.
277
278 Returns 1 for SHIFT, ALT, CTRL only if no other key has been pressed
279 in between, and SP->return_key_modifiers is set; these are returned
280 on keyup.
281
282 Normal keys are returned on keydown only. The number of repetitions
283 are returned. Dead keys (diacritics) are omitted. See below for a
284 description.
285*/
286
287static int _get_key_count(void)
288{
289 int num_keys = 0, vk;
290
291 PDC_LOG(("_get_key_count() - called\n"));
292
293 vk = KEV.wVirtualKeyCode;
294
295 if (KEV.bKeyDown)
296 {
297 /* key down */
298
299 save_press = 0;
300
301 if (vk == VK_CAPITAL || vk == VK_NUMLOCK || vk == VK_SCROLL)
302 {
303 /* throw away these modifiers */
304 }
305 else if (vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU)
306 {
307 /* These keys are returned on keyup only. */
308
309 save_press = vk;
310 switch (vk)
311 {
312 case VK_SHIFT:
313 left_key = GetKeyState(VK_LSHIFT);
314 break;
315 case VK_CONTROL:
316 left_key = GetKeyState(VK_LCONTROL);
317 break;
318 case VK_MENU:
319 left_key = GetKeyState(VK_LMENU);
320 }
321 }
322 else
323 {
324 /* Check for diacritics. These are dead keys. Some locales
325 have modified characters like umlaut-a, which is an "a"
326 with two dots on it. In some locales you have to press a
327 special key (the dead key) immediately followed by the
328 "a" to get a composed umlaut-a. The special key may have
329 a normal meaning with different modifiers. */
330
331 if (KEV.uChar.UnicodeChar || !(MapVirtualKey(vk, 2) & 0x80000000))
332 num_keys = KEV.wRepeatCount;
333 }
334 }
335 else
336 {
337 /* key up */
338
339 /* Only modifier keys or the results of ALT-numpad entry are
340 returned on keyup */
341
342 if ((vk == VK_MENU && KEV.uChar.UnicodeChar) ||
343 ((vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) &&
344 vk == save_press))
345 {
346 save_press = 0;
347 num_keys = 1;
348 }
349 }
350
351 PDC_LOG(("_get_key_count() - returning: num_keys %d\n", num_keys));
352
353 return num_keys;
354}
355
356/* _process_key_event returns -1 if the key in save_ip should be
357 ignored. Otherwise it returns the keycode which should be returned
358 by PDC_get_key(). save_ip must be a key event.
359
360 CTRL-ALT support has been disabled, when is it emitted plainly? */
361
362static int _process_key_event(void)
363{
364 int key =
365#ifdef PDC_WIDE
366 KEV.uChar.UnicodeChar;
367#else
368 KEV.uChar.AsciiChar;
369#endif
370 WORD vk = KEV.wVirtualKeyCode;
371 DWORD state = KEV.dwControlKeyState;
372
373 int idx;
374 BOOL enhanced;
375
376 SP->key_code = TRUE;
377
378 /* Save the key modifiers. Do this first to allow to detect e.g. a
379 pressed CTRL key after a hit of NUMLOCK. */
380
381 if (state & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))
382 SP->key_modifiers |= PDC_KEY_MODIFIER_ALT;
383
384 if (state & SHIFT_PRESSED)
385 SP->key_modifiers |= PDC_KEY_MODIFIER_SHIFT;
386
387 if (state & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
388 SP->key_modifiers |= PDC_KEY_MODIFIER_CONTROL;
389
390 if (state & NUMLOCK_ON)
391 SP->key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK;
392
393 /* Handle modifier keys hit by themselves */
394
395 switch (vk)
396 {
397 case VK_SHIFT: /* shift */
398 if (!SP->return_key_modifiers)
399 return -1;
400
401 return (left_key & 0x8000) ? KEY_SHIFT_L : KEY_SHIFT_R;
402
403 case VK_CONTROL: /* control */
404 if (!SP->return_key_modifiers)
405 return -1;
406
407 return (left_key & 0x8000) ? KEY_CONTROL_L : KEY_CONTROL_R;
408
409 case VK_MENU: /* alt */
410 if (!key)
411 {
412 if (!SP->return_key_modifiers)
413 return -1;
414
415 return (left_key & 0x8000) ? KEY_ALT_L : KEY_ALT_R;
416 }
417 }
418
419 /* The system may emit Ascii or Unicode characters depending on
420 whether ReadConsoleInputA or ReadConsoleInputW is used.
421
422 Normally, if key != 0 then the system did the translation
423 successfully. But this is not true for LEFT_ALT (different to
424 RIGHT_ALT). In case of LEFT_ALT we can get key != 0. So
425 check for this first. */
426
427 if (key && ( !(state & LEFT_ALT_PRESSED) ||
428 (state & RIGHT_ALT_PRESSED) ))
429 {
430 /* This code should catch all keys returning a printable
431 character. Characters above 0x7F should be returned as
432 positive codes. */
433
434 if (kptab[vk].extended == 0)
435 {
436 SP->key_code = FALSE;
437 return key;
438 }
439 }
440
441 /* This case happens if a functional key has been entered. */
442
443 if ((state & ENHANCED_KEY) && (kptab[vk].extended != 999))
444 {
445 enhanced = TRUE;
446 idx = kptab[vk].extended;
447 }
448 else
449 {
450 enhanced = FALSE;
451 idx = vk;
452 }
453
454 if (state & SHIFT_PRESSED)
455 key = enhanced ? ext_kptab[idx].shift : kptab[idx].shift;
456
457 else if (state & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
458 key = enhanced ? ext_kptab[idx].control : kptab[idx].control;
459
460 else if (state & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))
461 key = enhanced ? ext_kptab[idx].alt : kptab[idx].alt;
462
463 else
464 key = enhanced ? ext_kptab[idx].normal : kptab[idx].normal;
465
466 if (key < KEY_CODE_YES)
467 SP->key_code = FALSE;
468
469 return key;
470}
471
472static int _process_mouse_event(void)
473{
474 static const DWORD button_mask[] = {1, 4, 2};
475 short action, shift_flags = 0;
476 int i;
477
478 save_press = 0;
479 SP->key_code = TRUE;
480
481 memset(&SP->mouse_status, 0, sizeof(MOUSE_STATUS));
482
483 SP->mouse_status.x = MEV.dwMousePosition.X;
484 SP->mouse_status.y = MEV.dwMousePosition.Y;
485
486 /* Handle scroll wheel */
487
488 if (MEV.dwEventFlags == 4)
489 {
490 SP->mouse_status.changes = (MEV.dwButtonState & 0xFF000000) ?
491 PDC_MOUSE_WHEEL_DOWN : PDC_MOUSE_WHEEL_UP;
492
493 memset(&old_mouse_status, 0, sizeof(old_mouse_status));
494
495 return KEY_MOUSE;
496 }
497
498 if (MEV.dwEventFlags == 8)
499 {
500 SP->mouse_status.changes = (MEV.dwButtonState & 0xFF000000) ?
501 PDC_MOUSE_WHEEL_RIGHT : PDC_MOUSE_WHEEL_LEFT;
502
503 memset(&old_mouse_status, 0, sizeof(old_mouse_status));
504
505 return KEY_MOUSE;
506 }
507
508 action = (MEV.dwEventFlags == 2) ? BUTTON_DOUBLE_CLICKED :
509 ((MEV.dwEventFlags == 1) ? BUTTON_MOVED : BUTTON_PRESSED);
510
511 for (i = 0; i < 3; i++)
512 SP->mouse_status.button[i] =
513 (MEV.dwButtonState & button_mask[i]) ? action : 0;
514
515 if (action == BUTTON_PRESSED && MEV.dwButtonState & 7 && SP->mouse_wait)
516 {
517 /* Check for a click -- a PRESS followed immediately by a release */
518
519 if (!event_count)
520 {
521 napms(SP->mouse_wait);
522
523 GetNumberOfConsoleInputEvents(pdc_con_in, &event_count);
524 }
525
526 if (event_count)
527 {
528 INPUT_RECORD ip;
529 DWORD count;
530 bool have_click = FALSE;
531
532 PeekConsoleInput(pdc_con_in, &ip, 1, &count);
533
534 for (i = 0; i < 3; i++)
535 {
536 if (SP->mouse_status.button[i] == BUTTON_PRESSED &&
537 !(ip.Event.MouseEvent.dwButtonState & button_mask[i]))
538 {
539 SP->mouse_status.button[i] = BUTTON_CLICKED;
540 have_click = TRUE;
541 }
542 }
543
544 /* If a click was found, throw out the event */
545
546 if (have_click)
547 ReadConsoleInput(pdc_con_in, &ip, 1, &count);
548 }
549 }
550
551 SP->mouse_status.changes = 0;
552
553 for (i = 0; i < 3; i++)
554 {
555 if (old_mouse_status.button[i] != SP->mouse_status.button[i])
556 SP->mouse_status.changes |= (1 << i);
557
558 if (SP->mouse_status.button[i] == BUTTON_MOVED)
559 {
560 /* Discard non-moved "moves" */
561
562 if (SP->mouse_status.x == old_mouse_status.x &&
563 SP->mouse_status.y == old_mouse_status.y)
564 return -1;
565
566 /* Motion events always flag the button as changed */
567
568 SP->mouse_status.changes |= (1 << i);
569 SP->mouse_status.changes |= PDC_MOUSE_MOVED;
570 break;
571 }
572 }
573
574 old_mouse_status = SP->mouse_status;
575
576 /* Treat click events as release events for comparison purposes */
577
578 for (i = 0; i < 3; i++)
579 {
580 if (old_mouse_status.button[i] == BUTTON_CLICKED ||
581 old_mouse_status.button[i] == BUTTON_DOUBLE_CLICKED)
582 old_mouse_status.button[i] = BUTTON_RELEASED;
583 }
584
585 /* Check for SHIFT/CONTROL/ALT */
586
587 if (MEV.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))
588 shift_flags |= BUTTON_ALT;
589
590 if (MEV.dwControlKeyState & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
591 shift_flags |= BUTTON_CONTROL;
592
593 if (MEV.dwControlKeyState & SHIFT_PRESSED)
594 shift_flags |= BUTTON_SHIFT;
595
596 if (shift_flags)
597 {
598 for (i = 0; i < 3; i++)
599 {
600 if (SP->mouse_status.changes & (1 << i))
601 SP->mouse_status.button[i] |= shift_flags;
602 }
603 }
604
605 return KEY_MOUSE;
606}
607
608/* return the next available key or mouse event */
609
610int PDC_get_key(void)
611{
612 SP->key_modifiers = 0L;
613
614 if (!key_count)
615 {
616 DWORD count;
617
618 ReadConsoleInput(pdc_con_in, &save_ip, 1, &count);
619 event_count--;
620
621 if (save_ip.EventType == MOUSE_EVENT ||
622 save_ip.EventType == WINDOW_BUFFER_SIZE_EVENT)
623 key_count = 1;
624 else if (save_ip.EventType == KEY_EVENT)
625 key_count = _get_key_count();
626 }
627
628 if (key_count)
629 {
630 key_count--;
631
632 switch (save_ip.EventType)
633 {
634 case KEY_EVENT:
635 return _process_key_event();
636
637 case MOUSE_EVENT:
638 return _process_mouse_event();
639
640 case WINDOW_BUFFER_SIZE_EVENT:
641 if (REV.dwSize.Y != LINES || REV.dwSize.X != COLS)
642 {
643 if (!SP->resized)
644 {
645 SP->resized = TRUE;
646 SP->key_code = TRUE;
647 return KEY_RESIZE;
648 }
649 }
650 }
651 }
652
653 return -1;
654}
655
656/* discard any pending keyboard or mouse input -- this is the core
657 routine for flushinp() */
658
659void PDC_flushinp(void)
660{
661 PDC_LOG(("PDC_flushinp() - called\n"));
662
663 FlushConsoleInputBuffer(pdc_con_in);
664}
665
666bool PDC_has_mouse(void)
667{
668 return TRUE;
669}
670
671int PDC_mouse_set(void)
672{
673 DWORD mode;
674
675 /* If turning on mouse input: Set ENABLE_MOUSE_INPUT, and clear
676 all other flags, except processed input mode;
677 If turning off the mouse: Set QuickEdit Mode to the status it
678 had on startup, and clear all other flags, except etc. */
679
680 GetConsoleMode(pdc_con_in, &mode);
681 mode = (mode & 1) | 0x0088;
682 SetConsoleMode(pdc_con_in, mode | (SP->_trap_mbe ?
683 ENABLE_MOUSE_INPUT : pdc_quick_edit));
684
685 memset(&old_mouse_status, 0, sizeof(old_mouse_status));
686
687 return OK;
688}
689
690int PDC_modifiers_set(void)
691{
692 return OK;
693}
diff --git a/scripts/kconfig/libcurses/pdcscrn.c b/scripts/kconfig/libcurses/pdcscrn.c
new file mode 100644
index 000000000..e2f4ddd90
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdcscrn.c
@@ -0,0 +1,686 @@
1/* PDCurses */
2
3#include "pdcwin.h"
4
5#include <stdlib.h>
6
7/* Color component table */
8
9PDCCOLOR pdc_color[PDC_MAXCOL];
10
11HANDLE std_con_out = INVALID_HANDLE_VALUE;
12HANDLE pdc_con_out = INVALID_HANDLE_VALUE;
13HANDLE pdc_con_in = INVALID_HANDLE_VALUE;
14
15DWORD pdc_quick_edit;
16
17static short realtocurs[16] =
18{
19 COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, COLOR_RED,
20 COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE, COLOR_BLACK + 8,
21 COLOR_BLUE + 8, COLOR_GREEN + 8, COLOR_CYAN + 8, COLOR_RED + 8,
22 COLOR_MAGENTA + 8, COLOR_YELLOW + 8, COLOR_WHITE + 8
23};
24
25static short ansitocurs[16] =
26{
27 COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE,
28 COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE, COLOR_BLACK + 8,
29 COLOR_RED + 8, COLOR_GREEN + 8, COLOR_YELLOW + 8, COLOR_BLUE + 8,
30 COLOR_MAGENTA + 8, COLOR_CYAN + 8, COLOR_WHITE + 8
31};
32
33short pdc_curstoreal[16], pdc_curstoansi[16];
34short pdc_oldf, pdc_oldb, pdc_oldu;
35bool pdc_conemu, pdc_wt, pdc_ansi;
36
37enum { PDC_RESTORE_NONE, PDC_RESTORE_BUFFER };
38
39/* Struct for storing console registry keys, and for use with the
40 undocumented WM_SETCONSOLEINFO message. Originally by James Brown,
41 www.catch22.net. */
42
43static struct
44{
45 ULONG Length;
46 COORD ScreenBufferSize;
47 COORD WindowSize;
48 ULONG WindowPosX;
49 ULONG WindowPosY;
50
51 COORD FontSize;
52 ULONG FontFamily;
53 ULONG FontWeight;
54 WCHAR FaceName[32];
55
56 ULONG CursorSize;
57 ULONG FullScreen;
58 ULONG QuickEdit;
59 ULONG AutoPosition;
60 ULONG InsertMode;
61
62 USHORT ScreenColors;
63 USHORT PopupColors;
64 ULONG HistoryNoDup;
65 ULONG HistoryBufferSize;
66 ULONG NumberOfHistoryBuffers;
67
68 COLORREF ColorTable[16];
69
70 ULONG CodePage;
71 HWND Hwnd;
72
73 WCHAR ConsoleTitle[0x100];
74} console_info;
75
76#ifdef HAVE_NO_INFOEX
77/* Console screen buffer information (extended version) */
78typedef struct _CONSOLE_SCREEN_BUFFER_INFOEX {
79 ULONG cbSize;
80 COORD dwSize;
81 COORD dwCursorPosition;
82 WORD wAttributes;
83 SMALL_RECT srWindow;
84 COORD dwMaximumWindowSize;
85 WORD wPopupAttributes;
86 BOOL bFullscreenSupported;
87 COLORREF ColorTable[16];
88} CONSOLE_SCREEN_BUFFER_INFOEX;
89typedef CONSOLE_SCREEN_BUFFER_INFOEX *PCONSOLE_SCREEN_BUFFER_INFOEX;
90#endif
91
92typedef BOOL (WINAPI *SetConsoleScreenBufferInfoExFn)(HANDLE hConsoleOutput,
93 PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx);
94typedef BOOL (WINAPI *GetConsoleScreenBufferInfoExFn)(HANDLE hConsoleOutput,
95 PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx);
96
97static SetConsoleScreenBufferInfoExFn pSetConsoleScreenBufferInfoEx = NULL;
98static GetConsoleScreenBufferInfoExFn pGetConsoleScreenBufferInfoEx = NULL;
99
100static CONSOLE_SCREEN_BUFFER_INFO orig_scr;
101static CONSOLE_SCREEN_BUFFER_INFOEX console_infoex;
102
103static LPTOP_LEVEL_EXCEPTION_FILTER xcpt_filter;
104
105static DWORD old_console_mode = 0;
106
107static bool is_nt;
108
109static void _reset_old_colors(void)
110{
111 pdc_oldf = -1;
112 pdc_oldb = -1;
113 pdc_oldu = 0;
114}
115
116static HWND _find_console_handle(void)
117{
118 TCHAR orgtitle[1024], temptitle[1024];
119 HWND wnd;
120
121 GetConsoleTitle(orgtitle, 1024);
122
123 wsprintf(temptitle, TEXT("%d/%d"), GetTickCount(), GetCurrentProcessId());
124 SetConsoleTitle(temptitle);
125
126 Sleep(40);
127
128 wnd = FindWindow(NULL, temptitle);
129
130 SetConsoleTitle(orgtitle);
131
132 return wnd;
133}
134
135/* Undocumented console message */
136
137#define WM_SETCONSOLEINFO (WM_USER + 201)
138
139/* Wrapper around WM_SETCONSOLEINFO. We need to create the necessary
140 section (file-mapping) object in the context of the process which
141 owns the console, before posting the message. Originally by JB. */
142
143static void _set_console_info(void)
144{
145 CONSOLE_SCREEN_BUFFER_INFO csbi;
146 CONSOLE_CURSOR_INFO cci;
147 DWORD dwConsoleOwnerPid;
148 HANDLE hProcess;
149 HANDLE hSection, hDupSection;
150 PVOID ptrView;
151
152 /* Each-time initialization for console_info */
153
154 GetConsoleCursorInfo(pdc_con_out, &cci);
155 console_info.CursorSize = cci.dwSize;
156
157 GetConsoleScreenBufferInfo(pdc_con_out, &csbi);
158 console_info.ScreenBufferSize = csbi.dwSize;
159
160 console_info.WindowSize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1;
161 console_info.WindowSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
162
163 console_info.WindowPosX = csbi.srWindow.Left;
164 console_info.WindowPosY = csbi.srWindow.Top;
165
166 /* Open the process which "owns" the console */
167
168 GetWindowThreadProcessId(console_info.Hwnd, &dwConsoleOwnerPid);
169
170 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwConsoleOwnerPid);
171
172 /* Create a SECTION object backed by page-file, then map a view of
173 this section into the owner process so we can write the contents
174 of the CONSOLE_INFO buffer into it */
175
176 hSection = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE,
177 0, sizeof(console_info), 0);
178
179 /* Copy our console structure into the section-object */
180
181 ptrView = MapViewOfFile(hSection, FILE_MAP_WRITE|FILE_MAP_READ,
182 0, 0, sizeof(console_info));
183
184 memcpy(ptrView, &console_info, sizeof(console_info));
185
186 UnmapViewOfFile(ptrView);
187
188 /* Map the memory into owner process */
189
190 DuplicateHandle(GetCurrentProcess(), hSection, hProcess, &hDupSection,
191 0, FALSE, DUPLICATE_SAME_ACCESS);
192
193 /* Send console window the "update" message */
194
195 SendMessage(console_info.Hwnd, WM_SETCONSOLEINFO, (WPARAM)hDupSection, 0);
196
197 CloseHandle(hSection);
198 CloseHandle(hProcess);
199}
200
201static int _set_console_infoex(void)
202{
203 if (!pSetConsoleScreenBufferInfoEx(pdc_con_out, &console_infoex))
204 return ERR;
205
206 return OK;
207}
208
209static int _set_colors(void)
210{
211 SetConsoleTextAttribute(pdc_con_out, 7);
212 _reset_old_colors();
213
214 if (pSetConsoleScreenBufferInfoEx)
215 return _set_console_infoex();
216 else
217 {
218 _set_console_info();
219 return OK;
220 }
221}
222
223/* One-time initialization for console_info -- color table and font info
224 from the registry; other values from functions. */
225
226static void _init_console_info(void)
227{
228 DWORD scrnmode, len;
229 HKEY reghnd;
230 int i;
231
232 console_info.Hwnd = _find_console_handle();
233 console_info.Length = sizeof(console_info);
234
235 GetConsoleMode(pdc_con_in, &scrnmode);
236 console_info.QuickEdit = !!(scrnmode & 0x0040);
237 console_info.InsertMode = !!(scrnmode & 0x0020);
238
239 console_info.FullScreen = FALSE;
240 console_info.AutoPosition = 0x10000;
241 console_info.ScreenColors = SP->orig_back << 4 | SP->orig_fore;
242 console_info.PopupColors = 0xf5;
243
244 console_info.HistoryNoDup = FALSE;
245 console_info.HistoryBufferSize = 50;
246 console_info.NumberOfHistoryBuffers = 4;
247
248 console_info.CodePage = GetConsoleOutputCP();
249
250 RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Console"), 0,
251 KEY_QUERY_VALUE, &reghnd);
252
253 len = sizeof(DWORD);
254
255 /* Default color table */
256
257 for (i = 0; i < 16; i++)
258 {
259 char tname[13];
260
261 sprintf(tname, "ColorTable%02d", i);
262 RegQueryValueExA(reghnd, tname, NULL, NULL,
263 (LPBYTE)(&(console_info.ColorTable[i])), &len);
264 }
265
266 /* Font info */
267
268 RegQueryValueEx(reghnd, TEXT("FontSize"), NULL, NULL,
269 (LPBYTE)(&console_info.FontSize), &len);
270 RegQueryValueEx(reghnd, TEXT("FontFamily"), NULL, NULL,
271 (LPBYTE)(&console_info.FontFamily), &len);
272 RegQueryValueEx(reghnd, TEXT("FontWeight"), NULL, NULL,
273 (LPBYTE)(&console_info.FontWeight), &len);
274
275 len = sizeof(WCHAR) * 32;
276 RegQueryValueExW(reghnd, L"FaceName", NULL, NULL,
277 (LPBYTE)(console_info.FaceName), &len);
278
279 RegCloseKey(reghnd);
280}
281
282static int _init_console_infoex(void)
283{
284 console_infoex.cbSize = sizeof(console_infoex);
285
286 if (!pGetConsoleScreenBufferInfoEx(pdc_con_out, &console_infoex))
287 return ERR;
288
289 console_infoex.srWindow.Right++;
290 console_infoex.srWindow.Bottom++;
291
292 return OK;
293}
294
295static COLORREF *_get_colors(void)
296{
297 if (pGetConsoleScreenBufferInfoEx)
298 {
299 int status = OK;
300 if (!console_infoex.cbSize)
301 status = _init_console_infoex();
302 return (status == ERR) ? NULL :
303 (COLORREF *)(&(console_infoex.ColorTable));
304 }
305 else
306 {
307 if (!console_info.Hwnd)
308 _init_console_info();
309 return (COLORREF *)(&(console_info.ColorTable));
310 }
311}
312
313/* restore the original console buffer in the event of a crash */
314
315static LONG WINAPI _restore_console(LPEXCEPTION_POINTERS ep)
316{
317 PDC_scr_close();
318
319 return EXCEPTION_CONTINUE_SEARCH;
320}
321
322/* restore the original console buffer on Ctrl+Break (or Ctrl+C,
323 if it gets re-enabled) */
324
325static BOOL WINAPI _ctrl_break(DWORD dwCtrlType)
326{
327 if (dwCtrlType == CTRL_BREAK_EVENT || dwCtrlType == CTRL_C_EVENT)
328 PDC_scr_close();
329
330 return FALSE;
331}
332
333/* close the physical screen -- may restore the screen to its state
334 before PDC_scr_open(); miscellaneous cleanup */
335
336void PDC_scr_close(void)
337{
338 PDC_LOG(("PDC_scr_close() - called\n"));
339
340 if (SP->visibility != 1)
341 curs_set(1);
342
343 PDC_reset_shell_mode();
344
345 /* Position cursor to the bottom left of the screen. */
346
347 if (SP->_restore == PDC_RESTORE_NONE)
348 {
349 SMALL_RECT win;
350
351 win.Left = orig_scr.srWindow.Left;
352 win.Right = orig_scr.srWindow.Right;
353 win.Top = 0;
354 win.Bottom = orig_scr.srWindow.Bottom - orig_scr.srWindow.Top;
355 SetConsoleWindowInfo(pdc_con_out, TRUE, &win);
356 PDC_gotoyx(win.Bottom, 0);
357 }
358}
359
360void PDC_scr_free(void)
361{
362 if (pdc_con_out != std_con_out)
363 {
364 CloseHandle(pdc_con_out);
365 pdc_con_out = std_con_out;
366 }
367
368 SetUnhandledExceptionFilter(xcpt_filter);
369 SetConsoleCtrlHandler(_ctrl_break, FALSE);
370}
371
372/* open the physical screen -- miscellaneous initialization, may save
373 the existing screen for later restoration */
374
375int PDC_scr_open(void)
376{
377 const char *str;
378 CONSOLE_SCREEN_BUFFER_INFO csbi;
379 HMODULE h_kernel;
380 BOOL result;
381 int i;
382
383 PDC_LOG(("PDC_scr_open() - called\n"));
384
385 for (i = 0; i < 16; i++)
386 {
387 pdc_curstoreal[realtocurs[i]] = i;
388 pdc_curstoansi[ansitocurs[i]] = i;
389 }
390 _reset_old_colors();
391
392 std_con_out =
393 pdc_con_out = GetStdHandle(STD_OUTPUT_HANDLE);
394 pdc_con_in = GetStdHandle(STD_INPUT_HANDLE);
395
396 if (GetFileType(pdc_con_in) != FILE_TYPE_CHAR)
397 {
398 fprintf(stderr, "\nRedirection is not supported.\n");
399 exit(1);
400 }
401
402 is_nt = !(GetVersion() & 0x80000000);
403
404 pdc_wt = !!getenv("WT_SESSION");
405 str = pdc_wt ? NULL : getenv("ConEmuANSI");
406 pdc_conemu = !!str;
407 pdc_ansi = pdc_wt ? TRUE : pdc_conemu ? !strcmp(str, "ON") : FALSE;
408
409 GetConsoleScreenBufferInfo(pdc_con_out, &csbi);
410 GetConsoleScreenBufferInfo(pdc_con_out, &orig_scr);
411 GetConsoleMode(pdc_con_in, &old_console_mode);
412
413 /* preserve QuickEdit Mode setting for use in PDC_mouse_set() when
414 the mouse is not enabled -- other console input settings are
415 cleared */
416
417 pdc_quick_edit = old_console_mode & 0x0040;
418
419 SP->mouse_wait = PDC_CLICK_PERIOD;
420 SP->audible = TRUE;
421
422 SP->termattrs = A_COLOR | A_REVERSE;
423 if (pdc_ansi)
424 SP->termattrs |= A_UNDERLINE | A_ITALIC;
425
426 SP->orig_fore = csbi.wAttributes & 0x0f;
427 SP->orig_back = (csbi.wAttributes & 0xf0) >> 4;
428
429 SP->orig_attr = TRUE;
430
431 SP->_restore = PDC_RESTORE_NONE;
432
433 if ((str = getenv("PDC_RESTORE_SCREEN")) == NULL || *str != '0')
434 {
435 /* Create a new console buffer */
436
437 pdc_con_out =
438 CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
439 FILE_SHARE_READ | FILE_SHARE_WRITE,
440 NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
441
442 if (pdc_con_out == INVALID_HANDLE_VALUE)
443 {
444 PDC_LOG(("PDC_scr_open() - screen buffer failure\n"));
445
446 pdc_con_out = std_con_out;
447 }
448 else
449 SP->_restore = PDC_RESTORE_BUFFER;
450 }
451
452 xcpt_filter = SetUnhandledExceptionFilter(_restore_console);
453 SetConsoleCtrlHandler(_ctrl_break, TRUE);
454
455 SP->_preserve = (getenv("PDC_PRESERVE_SCREEN") != NULL);
456
457 /* ENABLE_LVB_GRID_WORLDWIDE */
458 result = SetConsoleMode(pdc_con_out, 0x0010);
459 if (result)
460 SP->termattrs |= A_UNDERLINE | A_LEFT | A_RIGHT;
461
462 PDC_reset_prog_mode();
463
464 SP->mono = FALSE;
465
466 h_kernel = GetModuleHandleA("kernel32.dll");
467 pGetConsoleScreenBufferInfoEx =
468 (GetConsoleScreenBufferInfoExFn)GetProcAddress(h_kernel,
469 "GetConsoleScreenBufferInfoEx");
470 pSetConsoleScreenBufferInfoEx =
471 (SetConsoleScreenBufferInfoExFn)GetProcAddress(h_kernel,
472 "SetConsoleScreenBufferInfoEx");
473
474 return OK;
475}
476
477 /* Calls SetConsoleWindowInfo with the given parameters, but fits them
478 if a scoll bar shrinks the maximum possible value. The rectangle
479 must at least fit in a half-sized window. */
480
481static BOOL _fit_console_window(HANDLE con_out, CONST SMALL_RECT *rect)
482{
483 SMALL_RECT run;
484 SHORT mx, my;
485
486 if (SetConsoleWindowInfo(con_out, TRUE, rect))
487 return TRUE;
488
489 run = *rect;
490 run.Right /= 2;
491 run.Bottom /= 2;
492
493 mx = run.Right;
494 my = run.Bottom;
495
496 if (!SetConsoleWindowInfo(con_out, TRUE, &run))
497 return FALSE;
498
499 for (run.Right = rect->Right; run.Right >= mx; run.Right--)
500 if (SetConsoleWindowInfo(con_out, TRUE, &run))
501 break;
502
503 if (run.Right < mx)
504 return FALSE;
505
506 for (run.Bottom = rect->Bottom; run.Bottom >= my; run.Bottom--)
507 if (SetConsoleWindowInfo(con_out, TRUE, &run))
508 return TRUE;
509
510 return FALSE;
511}
512
513/* the core of resize_term() */
514
515int PDC_resize_screen(int nlines, int ncols)
516{
517 SMALL_RECT rect;
518 COORD size, max;
519
520 bool prog_resize = nlines || ncols;
521
522 if (!prog_resize)
523 {
524 nlines = PDC_get_rows();
525 ncols = PDC_get_columns();
526 }
527
528 if (nlines < 2 || ncols < 2)
529 return ERR;
530
531 max = GetLargestConsoleWindowSize(pdc_con_out);
532
533 rect.Left = rect.Top = 0;
534 rect.Right = ncols - 1;
535
536 if (rect.Right > max.X)
537 rect.Right = max.X;
538
539 rect.Bottom = nlines - 1;
540
541 if (rect.Bottom > max.Y)
542 rect.Bottom = max.Y;
543
544 size.X = rect.Right + 1;
545 size.Y = rect.Bottom + 1;
546
547 _fit_console_window(pdc_con_out, &rect);
548 SetConsoleScreenBufferSize(pdc_con_out, size);
549
550 if (prog_resize)
551 {
552 _fit_console_window(pdc_con_out, &rect);
553 SetConsoleScreenBufferSize(pdc_con_out, size);
554 }
555 SetConsoleActiveScreenBuffer(pdc_con_out);
556
557 PDC_flushinp();
558
559 return OK;
560}
561
562void PDC_reset_prog_mode(void)
563{
564 PDC_LOG(("PDC_reset_prog_mode() - called.\n"));
565
566 if (pdc_con_out != std_con_out)
567 SetConsoleActiveScreenBuffer(pdc_con_out);
568 else if (is_nt)
569 {
570 COORD bufsize;
571 SMALL_RECT rect;
572
573 bufsize.X = orig_scr.srWindow.Right - orig_scr.srWindow.Left + 1;
574 bufsize.Y = orig_scr.srWindow.Bottom - orig_scr.srWindow.Top + 1;
575
576 rect.Top = rect.Left = 0;
577 rect.Bottom = bufsize.Y - 1;
578 rect.Right = bufsize.X - 1;
579
580 SetConsoleScreenBufferSize(pdc_con_out, bufsize);
581 SetConsoleWindowInfo(pdc_con_out, TRUE, &rect);
582 SetConsoleScreenBufferSize(pdc_con_out, bufsize);
583 SetConsoleActiveScreenBuffer(pdc_con_out);
584 }
585
586 PDC_mouse_set();
587}
588
589void PDC_reset_shell_mode(void)
590{
591 PDC_LOG(("PDC_reset_shell_mode() - called.\n"));
592
593 if (pdc_con_out != std_con_out)
594 SetConsoleActiveScreenBuffer(std_con_out);
595 else if (is_nt)
596 {
597 SetConsoleScreenBufferSize(pdc_con_out, orig_scr.dwSize);
598 SetConsoleWindowInfo(pdc_con_out, TRUE, &orig_scr.srWindow);
599 SetConsoleScreenBufferSize(pdc_con_out, orig_scr.dwSize);
600 SetConsoleWindowInfo(pdc_con_out, TRUE, &orig_scr.srWindow);
601 SetConsoleActiveScreenBuffer(pdc_con_out);
602 }
603
604 SetConsoleMode(pdc_con_in, old_console_mode | 0x0080);
605}
606
607void PDC_restore_screen_mode(int i)
608{
609}
610
611void PDC_save_screen_mode(int i)
612{
613}
614
615bool PDC_can_change_color(void)
616{
617 return is_nt;
618}
619
620int PDC_color_content(short color, short *red, short *green, short *blue)
621{
622 if (color < 16 && !(pdc_conemu || pdc_wt))
623 {
624 COLORREF *color_table = _get_colors();
625
626 if (color_table)
627 {
628 DWORD col = color_table[pdc_curstoreal[color]];
629
630 *red = DIVROUND(GetRValue(col) * 1000, 255);
631 *green = DIVROUND(GetGValue(col) * 1000, 255);
632 *blue = DIVROUND(GetBValue(col) * 1000, 255);
633 }
634 else
635 return ERR;
636 }
637 else
638 {
639 if (!pdc_color[color].mapped)
640 {
641 *red = *green = *blue = -1;
642 return ERR;
643 }
644
645 *red = pdc_color[color].r;
646 *green = pdc_color[color].g;
647 *blue = pdc_color[color].b;
648 }
649
650 return OK;
651}
652
653int PDC_init_color(short color, short red, short green, short blue)
654{
655 if (red == -1 && green == -1 && blue == -1)
656 {
657 pdc_color[color].mapped = FALSE;
658 return OK;
659 }
660
661 if (color < 16 && !(pdc_conemu || pdc_wt))
662 {
663 COLORREF *color_table = _get_colors();
664
665 if (color_table)
666 {
667 color_table[pdc_curstoreal[color]] =
668 RGB(DIVROUND(red * 255, 1000),
669 DIVROUND(green * 255, 1000),
670 DIVROUND(blue * 255, 1000));
671
672 return _set_colors();
673 }
674
675 return ERR;
676 }
677 else
678 {
679 pdc_color[color].r = red;
680 pdc_color[color].g = green;
681 pdc_color[color].b = blue;
682 pdc_color[color].mapped = TRUE;
683 }
684
685 return OK;
686}
diff --git a/scripts/kconfig/libcurses/pdcsetsc.c b/scripts/kconfig/libcurses/pdcsetsc.c
new file mode 100644
index 000000000..1e9fc9b0d
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdcsetsc.c
@@ -0,0 +1,133 @@
1/* PDCurses */
2
3#include "pdcwin.h"
4
5/*man-start**************************************************************
6
7pdcsetsc
8--------
9
10### Synopsis
11
12 int PDC_set_blink(bool blinkon);
13 int PDC_set_bold(bool boldon);
14 void PDC_set_title(const char *title);
15
16### Description
17
18 PDC_set_blink() toggles whether the A_BLINK attribute sets an actual
19 blink mode (TRUE), or sets the background color to high intensity
20 (FALSE). The default is platform-dependent (FALSE in most cases). It
21 returns OK if it could set the state to match the given parameter,
22 ERR otherwise.
23
24 PDC_set_bold() toggles whether the A_BOLD attribute selects an actual
25 bold font (TRUE), or sets the foreground color to high intensity
26 (FALSE). It returns OK if it could set the state to match the given
27 parameter, ERR otherwise.
28
29 PDC_set_title() sets the title of the window in which the curses
30 program is running. This function may not do anything on some
31 platforms.
32
33### Portability
34
35 Function | X/Open | ncurses | NetBSD
36 :---------------------|:------:|:-------:|:------:
37 PDC_set_blink | - | - | -
38 PDC_set_bold | - | - | -
39 PDC_set_title | - | - | -
40
41**man-end****************************************************************/
42
43int PDC_curs_set(int visibility)
44{
45 CONSOLE_CURSOR_INFO cci;
46 int ret_vis;
47
48 PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility));
49
50 ret_vis = SP->visibility;
51
52 if (GetConsoleCursorInfo(pdc_con_out, &cci) == FALSE)
53 return ERR;
54
55 switch(visibility)
56 {
57 case 0: /* invisible */
58 cci.bVisible = FALSE;
59 break;
60 case 2: /* highly visible */
61 cci.bVisible = TRUE;
62 cci.dwSize = 95;
63 break;
64 default: /* normal visibility */
65 cci.bVisible = TRUE;
66 cci.dwSize = SP->orig_cursor;
67 break;
68 }
69
70 if (SetConsoleCursorInfo(pdc_con_out, &cci) == FALSE)
71 return ERR;
72
73 SP->visibility = visibility;
74 return ret_vis;
75}
76
77void PDC_set_title(const char *title)
78{
79#ifdef PDC_WIDE
80 wchar_t wtitle[512];
81#endif
82 PDC_LOG(("PDC_set_title() - called:<%s>\n", title));
83
84#ifdef PDC_WIDE
85 PDC_mbstowcs(wtitle, title, 511);
86 SetConsoleTitleW(wtitle);
87#else
88 SetConsoleTitleA(title);
89#endif
90}
91
92int PDC_set_blink(bool blinkon)
93{
94 if (!SP)
95 return ERR;
96
97 if (SP->color_started)
98 {
99 COLORS = 16;
100 if (PDC_can_change_color()) /* is_nt */
101 {
102 if (pdc_conemu || SetConsoleMode(pdc_con_out, 0x0004)) /* VT */
103 COLORS = PDC_MAXCOL;
104
105 if (!pdc_conemu)
106 SetConsoleMode(pdc_con_out, 0x0010); /* LVB */
107 }
108 }
109
110 if (blinkon)
111 {
112 if (!(SP->termattrs & A_BLINK))
113 {
114 SP->termattrs |= A_BLINK;
115 pdc_last_blink = GetTickCount();
116 }
117 }
118 else
119 {
120 if (SP->termattrs & A_BLINK)
121 {
122 SP->termattrs &= ~A_BLINK;
123 PDC_blink_text();
124 }
125 }
126
127 return OK;
128}
129
130int PDC_set_bold(bool boldon)
131{
132 return boldon ? ERR : OK;
133}
diff --git a/scripts/kconfig/libcurses/pdcutil.c b/scripts/kconfig/libcurses/pdcutil.c
new file mode 100644
index 000000000..a40cf4518
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdcutil.c
@@ -0,0 +1,26 @@
1/* PDCurses */
2
3#include "pdcwin.h"
4
5void PDC_beep(void)
6{
7 PDC_LOG(("PDC_beep() - called\n"));
8
9/* MessageBeep(MB_OK); */
10 MessageBeep(0XFFFFFFFF);
11}
12
13void PDC_napms(int ms)
14{
15 PDC_LOG(("PDC_napms() - called: ms=%d\n", ms));
16
17 if ((SP->termattrs & A_BLINK) && (GetTickCount() >= pdc_last_blink + 500))
18 PDC_blink_text();
19
20 Sleep(ms);
21}
22
23const char *PDC_sysname(void)
24{
25 return "Windows";
26}
diff --git a/scripts/kconfig/libcurses/pdcwin.h b/scripts/kconfig/libcurses/pdcwin.h
new file mode 100644
index 000000000..cee76931b
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdcwin.h
@@ -0,0 +1,27 @@
1/* PDCurses */
2
3#if defined(PDC_WIDE) && !defined(UNICODE)
4# define UNICODE
5#endif
6
7#define WIN32_LEAN_AND_MEAN
8#include <windows.h>
9#undef MOUSE_MOVED
10#include "curspriv.h"
11
12#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
13# define _CRT_SECURE_NO_DEPRECATE 1 /* kill nonsense warnings */
14#endif
15
16typedef struct {short r, g, b; bool mapped;} PDCCOLOR;
17
18extern PDCCOLOR pdc_color[PDC_MAXCOL];
19
20extern HANDLE pdc_con_out, pdc_con_in;
21extern DWORD pdc_quick_edit;
22extern DWORD pdc_last_blink;
23extern short pdc_curstoreal[16], pdc_curstoansi[16];
24extern short pdc_oldf, pdc_oldb, pdc_oldu;
25extern bool pdc_conemu, pdc_wt, pdc_ansi;
26
27extern void PDC_blink_text(void);
diff --git a/scripts/kconfig/libcurses/printw.c b/scripts/kconfig/libcurses/printw.c
new file mode 100644
index 000000000..a753638a5
--- /dev/null
+++ b/scripts/kconfig/libcurses/printw.c
@@ -0,0 +1,131 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7printw
8------
9
10### Synopsis
11
12 int printw(const char *fmt, ...);
13 int wprintw(WINDOW *win, const char *fmt, ...);
14 int mvprintw(int y, int x, const char *fmt, ...);
15 int mvwprintw(WINDOW *win, int y, int x, const char *fmt,...);
16 int vwprintw(WINDOW *win, const char *fmt, va_list varglist);
17 int vw_printw(WINDOW *win, const char *fmt, va_list varglist);
18
19### Description
20
21 The printw() functions add a formatted string to the window at the
22 current or specified cursor position. The format strings are the same
23 as used in the standard C library's printf(). (printw() can be used
24 as a drop-in replacement for printf().)
25
26 The duplication between vwprintw() and vw_printw() is for historic
27 reasons. In PDCurses, they're the same.
28
29### Return Value
30
31 All functions return the number of characters printed, or ERR on
32 error.
33
34### Portability
35
36 Function | X/Open | ncurses | NetBSD
37 :---------------------|:------:|:-------:|:------:
38 printw | Y | Y | Y
39 wprintw | Y | Y | Y
40 mvprintw | Y | Y | Y
41 mvwprintw | Y | Y | Y
42 vwprintw | Y | Y | Y
43 vw_printw | Y | Y | Y
44
45**man-end****************************************************************/
46
47#include <string.h>
48
49int vwprintw(WINDOW *win, const char *fmt, va_list varglist)
50{
51 char printbuf[513];
52 int len;
53
54 PDC_LOG(("vwprintw() - called\n"));
55
56#ifdef HAVE_VSNPRINTF
57 len = vsnprintf(printbuf, 512, fmt, varglist);
58#else
59 len = vsprintf(printbuf, fmt, varglist);
60#endif
61 return (waddstr(win, printbuf) == ERR) ? ERR : len;
62}
63
64int printw(const char *fmt, ...)
65{
66 va_list args;
67 int retval;
68
69 PDC_LOG(("printw() - called\n"));
70
71 va_start(args, fmt);
72 retval = vwprintw(stdscr, fmt, args);
73 va_end(args);
74
75 return retval;
76}
77
78int wprintw(WINDOW *win, const char *fmt, ...)
79{
80 va_list args;
81 int retval;
82
83 PDC_LOG(("wprintw() - called\n"));
84
85 va_start(args, fmt);
86 retval = vwprintw(win, fmt, args);
87 va_end(args);
88
89 return retval;
90}
91
92int mvprintw(int y, int x, const char *fmt, ...)
93{
94 va_list args;
95 int retval;
96
97 PDC_LOG(("mvprintw() - called\n"));
98
99 if (move(y, x) == ERR)
100 return ERR;
101
102 va_start(args, fmt);
103 retval = vwprintw(stdscr, fmt, args);
104 va_end(args);
105
106 return retval;
107}
108
109int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
110{
111 va_list args;
112 int retval;
113
114 PDC_LOG(("mvwprintw() - called\n"));
115
116 if (wmove(win, y, x) == ERR)
117 return ERR;
118
119 va_start(args, fmt);
120 retval = vwprintw(win, fmt, args);
121 va_end(args);
122
123 return retval;
124}
125
126int vw_printw(WINDOW *win, const char *fmt, va_list varglist)
127{
128 PDC_LOG(("vw_printw() - called\n"));
129
130 return vwprintw(win, fmt, varglist);
131}
diff --git a/scripts/kconfig/libcurses/refresh.c b/scripts/kconfig/libcurses/refresh.c
new file mode 100644
index 000000000..1dce414e5
--- /dev/null
+++ b/scripts/kconfig/libcurses/refresh.c
@@ -0,0 +1,289 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7refresh
8-------
9
10### Synopsis
11
12 int refresh(void);
13 int wrefresh(WINDOW *win);
14 int wnoutrefresh(WINDOW *win);
15 int doupdate(void);
16 int redrawwin(WINDOW *win);
17 int wredrawln(WINDOW *win, int beg_line, int num_lines);
18
19### Description
20
21 wrefresh() copies the named window to the physical terminal screen,
22 taking into account what is already there in order to optimize cursor
23 movement. refresh() does the same, using stdscr. These routines must
24 be called to get any output on the terminal, as other routines only
25 manipulate data structures. Unless leaveok() has been enabled, the
26 physical cursor of the terminal is left at the location of the
27 window's cursor.
28
29 wnoutrefresh() and doupdate() allow multiple updates with more
30 efficiency than wrefresh() alone. wrefresh() works by first calling
31 wnoutrefresh(), which copies the named window to the virtual screen.
32 It then calls doupdate(), which compares the virtual screen to the
33 physical screen and does the actual update. A series of calls to
34 wrefresh() will result in alternating calls to wnoutrefresh() and
35 doupdate(), causing several bursts of output to the screen. By first
36 calling wnoutrefresh() for each window, it is then possible to call
37 doupdate() only once.
38
39 In PDCurses, redrawwin() is equivalent to touchwin(), and wredrawln()
40 is the same as touchline(). In some other curses implementations,
41 there's a subtle distinction, but it has no meaning in PDCurses.
42
43### Return Value
44
45 All functions return OK on success and ERR on error.
46
47### Portability
48
49 Function | X/Open | ncurses | NetBSD
50 :---------------------|:------:|:-------:|:------:
51 refresh | Y | Y | Y
52 wrefresh | Y | Y | Y
53 wnoutrefresh | Y | Y | Y
54 doupdate | Y | Y | Y
55 redrawwin | Y | Y | Y
56 wredrawln | Y | Y | Y
57
58**man-end****************************************************************/
59
60#include <string.h>
61
62int wnoutrefresh(WINDOW *win)
63{
64 int begy, begx; /* window's place on screen */
65 int i, j;
66
67 PDC_LOG(("wnoutrefresh() - called: win=%p\n", win));
68
69 if (!win)
70 return ERR;
71 if (is_pad(win))
72 return pnoutrefresh(win,
73 win->_pad._pad_y,
74 win->_pad._pad_x,
75 win->_pad._pad_top,
76 win->_pad._pad_left,
77 win->_pad._pad_bottom,
78 win->_pad._pad_right);
79
80 begy = win->_begy;
81 begx = win->_begx;
82
83 for (i = 0, j = begy; i < win->_maxy; i++, j++)
84 {
85 if (win->_firstch[i] != _NO_CHANGE)
86 {
87 chtype *src = win->_y[i];
88 chtype *dest = curscr->_y[j] + begx;
89
90 int first = win->_firstch[i]; /* first changed */
91 int last = win->_lastch[i]; /* last changed */
92
93 /* ignore areas on the outside that are marked as changed,
94 but really aren't */
95
96 while (first <= last && src[first] == dest[first])
97 first++;
98
99 while (last >= first && src[last] == dest[last])
100 last--;
101
102 /* if any have really changed... */
103
104 if (first <= last)
105 {
106 memcpy(dest + first, src + first,
107 (last - first + 1) * sizeof(chtype));
108
109 first += begx;
110 last += begx;
111
112 if (first < curscr->_firstch[j] ||
113 curscr->_firstch[j] == _NO_CHANGE)
114 curscr->_firstch[j] = first;
115
116 if (last > curscr->_lastch[j])
117 curscr->_lastch[j] = last;
118 }
119
120 win->_firstch[i] = _NO_CHANGE; /* updated now */
121 }
122
123 win->_lastch[i] = _NO_CHANGE; /* updated now */
124 }
125
126 if (win->_clear)
127 win->_clear = FALSE;
128
129 if (!win->_leaveit)
130 {
131 curscr->_cury = win->_cury + begy;
132 curscr->_curx = win->_curx + begx;
133 }
134
135 return OK;
136}
137
138int doupdate(void)
139{
140 int y;
141 bool clearall;
142
143 PDC_LOG(("doupdate() - called\n"));
144
145 if (!SP || !curscr)
146 return ERR;
147
148 if (isendwin()) /* coming back after endwin() called */
149 {
150 reset_prog_mode();
151 clearall = TRUE;
152 SP->alive = TRUE; /* so isendwin() result is correct */
153 }
154 else
155 clearall = curscr->_clear;
156
157 for (y = 0; y < SP->lines; y++)
158 {
159 PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n",
160 y, SP->lines, (curscr->_firstch[y] != _NO_CHANGE) ?
161 "Yes" : "No"));
162
163 if (clearall || curscr->_firstch[y] != _NO_CHANGE)
164 {
165 int first, last;
166
167 chtype *src = curscr->_y[y];
168 chtype *dest = SP->lastscr->_y[y];
169
170 if (clearall)
171 {
172 first = 0;
173 last = COLS - 1;
174 }
175 else
176 {
177 first = curscr->_firstch[y];
178 last = curscr->_lastch[y];
179 }
180
181 while (first <= last)
182 {
183 int len = 0;
184
185 /* build up a run of changed cells; if two runs are
186 separated by a single unchanged cell, ignore the
187 break */
188
189 if (clearall)
190 len = last - first + 1;
191 else
192 while (first + len <= last &&
193 (src[first + len] != dest[first + len] ||
194 (len && first + len < last &&
195 src[first + len + 1] != dest[first + len + 1])
196 )
197 )
198 len++;
199
200 /* update the screen, and SP->lastscr */
201
202 if (len)
203 {
204 PDC_transform_line(y, first, len, src + first);
205 memcpy(dest + first, src + first, len * sizeof(chtype));
206 first += len;
207 }
208
209 /* skip over runs of unchanged cells */
210
211 while (first <= last && src[first] == dest[first])
212 first++;
213 }
214
215 curscr->_firstch[y] = _NO_CHANGE;
216 curscr->_lastch[y] = _NO_CHANGE;
217 }
218 }
219
220 curscr->_clear = FALSE;
221
222 if (SP->visibility)
223 PDC_gotoyx(curscr->_cury, curscr->_curx);
224
225 SP->cursrow = curscr->_cury;
226 SP->curscol = curscr->_curx;
227
228 PDC_doupdate();
229
230 return OK;
231}
232
233int wrefresh(WINDOW *win)
234{
235 bool save_clear;
236
237 PDC_LOG(("wrefresh() - called\n"));
238
239 if ( !win || (win->_flags & (_PAD|_SUBPAD)) )
240 return ERR;
241
242 save_clear = win->_clear;
243
244 if (win == curscr)
245 curscr->_clear = TRUE;
246 else
247 wnoutrefresh(win);
248
249 if (save_clear && win->_maxy == SP->lines && win->_maxx == SP->cols)
250 curscr->_clear = TRUE;
251
252 return doupdate();
253}
254
255int refresh(void)
256{
257 PDC_LOG(("refresh() - called\n"));
258
259 return wrefresh(stdscr);
260}
261
262int wredrawln(WINDOW *win, int start, int num)
263{
264 int i;
265
266 PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n",
267 win, start, num));
268
269 if (!win || start > win->_maxy || start + num > win->_maxy)
270 return ERR;
271
272 for (i = start; i < start + num; i++)
273 {
274 win->_firstch[i] = 0;
275 win->_lastch[i] = win->_maxx - 1;
276 }
277
278 return OK;
279}
280
281int redrawwin(WINDOW *win)
282{
283 PDC_LOG(("redrawwin() - called: win=%p\n", win));
284
285 if (!win)
286 return ERR;
287
288 return wredrawln(win, 0, win->_maxy);
289}
diff --git a/scripts/kconfig/libcurses/scroll.c b/scripts/kconfig/libcurses/scroll.c
new file mode 100644
index 000000000..a53d71bad
--- /dev/null
+++ b/scripts/kconfig/libcurses/scroll.c
@@ -0,0 +1,103 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7scroll
8------
9
10### Synopsis
11
12 int scroll(WINDOW *win);
13 int scrl(int n);
14 int wscrl(WINDOW *win, int n);
15
16### Description
17
18 scroll() causes the window to scroll up one line. This involves
19 moving the lines in the window data strcture.
20
21 With a positive n, scrl() and wscrl() scroll the window up n lines
22 (line i + n becomes i); otherwise they scroll the window down n
23 lines.
24
25 For these functions to work, scrolling must be enabled via
26 scrollok(). Note also that scrolling is not allowed if the supplied
27 window is a pad.
28
29### Return Value
30
31 All functions return OK on success and ERR on error.
32
33### Portability
34
35 Function | X/Open | ncurses | NetBSD
36 :---------------------|:------:|:-------:|:------:
37 scroll | Y | Y | Y
38 scrl | Y | Y | Y
39 wscrl | Y | Y | Y
40
41**man-end****************************************************************/
42
43int wscrl(WINDOW *win, int n)
44{
45 int i, l, dir, start, end;
46 chtype blank, *temp;
47
48 /* Check if window scrolls. Valid for window AND pad */
49
50 if (!win || !win->_scroll || !n)
51 return ERR;
52
53 blank = win->_bkgd;
54
55 if (n > 0)
56 {
57 start = win->_tmarg;
58 end = win->_bmarg;
59 dir = 1;
60 }
61 else
62 {
63 start = win->_bmarg;
64 end = win->_tmarg;
65 dir = -1;
66 }
67
68 for (l = 0; l < (n * dir); l++)
69 {
70 temp = win->_y[start];
71
72 /* re-arrange line pointers */
73
74 for (i = start; i != end; i += dir)
75 win->_y[i] = win->_y[i + dir];
76
77 win->_y[end] = temp;
78
79 /* make a blank line */
80
81 for (i = 0; i < win->_maxx; i++)
82 *temp++ = blank;
83 }
84
85 touchline(win, win->_tmarg, win->_bmarg - win->_tmarg + 1);
86
87 PDC_sync(win);
88 return OK;
89}
90
91int scrl(int n)
92{
93 PDC_LOG(("scrl() - called\n"));
94
95 return wscrl(stdscr, n);
96}
97
98int scroll(WINDOW *win)
99{
100 PDC_LOG(("scroll() - called\n"));
101
102 return wscrl(win, 1);
103}
diff --git a/scripts/kconfig/libcurses/slk.c b/scripts/kconfig/libcurses/slk.c
new file mode 100644
index 000000000..e8dde752c
--- /dev/null
+++ b/scripts/kconfig/libcurses/slk.c
@@ -0,0 +1,673 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7slk
8---
9
10### Synopsis
11
12 int slk_init(int fmt);
13 int slk_set(int labnum, const char *label, int justify);
14 int slk_refresh(void);
15 int slk_noutrefresh(void);
16 char *slk_label(int labnum);
17 int slk_clear(void);
18 int slk_restore(void);
19 int slk_touch(void);
20 int slk_attron(const chtype attrs);
21 int slk_attr_on(const attr_t attrs, void *opts);
22 int slk_attrset(const chtype attrs);
23 int slk_attr_set(const attr_t attrs, short color_pair, void *opts);
24 int slk_attroff(const chtype attrs);
25 int slk_attr_off(const attr_t attrs, void *opts);
26 int slk_color(short color_pair);
27
28 int slk_wset(int labnum, const wchar_t *label, int justify);
29
30 int PDC_mouse_in_slk(int y, int x);
31 void PDC_slk_free(void);
32 void PDC_slk_initialize(void);
33
34 wchar_t *slk_wlabel(int labnum)
35
36### Description
37
38 These functions manipulate a window that contain Soft Label Keys
39 (SLK). To use the SLK functions, a call to slk_init() must be made
40 BEFORE initscr() or newterm(). slk_init() removes 1 or 2 lines from
41 the useable screen, depending on the format selected.
42
43 The line(s) removed from the screen are used as a separate window, in
44 which SLKs are displayed.
45
46 slk_init() requires a single parameter which describes the format of
47 the SLKs as follows:
48
49 0 3-2-3 format
50 1 4-4 format
51 2 4-4-4 format (ncurses extension)
52 3 4-4-4 format with index line (ncurses extension)
53 2 lines used
54 55 5-5 format (pdcurses format)
55
56 slk_refresh(), slk_noutrefresh() and slk_touch() are analogous to
57 refresh(), noutrefresh() and touch().
58
59### Return Value
60
61 All functions return OK on success and ERR on error.
62
63### Portability
64
65 Function | X/Open | ncurses | NetBSD
66 :---------------------|:------:|:-------:|:------:
67 slk_init | Y | Y | Y
68 slk_set | Y | Y | Y
69 slk_refresh | Y | Y | Y
70 slk_noutrefresh | Y | Y | Y
71 slk_label | Y | Y | Y
72 slk_clear | Y | Y | Y
73 slk_restore | Y | Y | Y
74 slk_touch | Y | Y | Y
75 slk_attron | Y | Y | Y
76 slk_attrset | Y | Y | Y
77 slk_attroff | Y | Y | Y
78 slk_attr_on | Y | Y | Y
79 slk_attr_set | Y | Y | Y
80 slk_attr_off | Y | Y | Y
81 slk_wset | Y | Y | Y
82 PDC_mouse_in_slk | - | - | -
83 PDC_slk_free | - | - | -
84 PDC_slk_initialize | - | - | -
85 slk_wlabel | - | - | -
86
87**man-end****************************************************************/
88
89#include <stdlib.h>
90
91enum { LABEL_NORMAL = 8, LABEL_EXTENDED = 10, LABEL_NCURSES_EXTENDED = 12 };
92
93static int label_length = 0;
94static int labels = 0;
95static int label_fmt = 0;
96static int label_line = 0;
97static bool hidden = FALSE;
98
99static struct SLK {
100 chtype label[32];
101 int len;
102 int format;
103 int start_col;
104} *slk = (struct SLK *)NULL;
105
106/* slk_init() is the slk initialization routine.
107 This must be called before initscr().
108
109 label_fmt = 0, 1 or 55.
110 0 = 3-2-3 format
111 1 = 4 - 4 format
112 2 = 4-4-4 format (ncurses extension for PC 12 function keys)
113 3 = 4-4-4 format (ncurses extension for PC 12 function keys -
114 with index line)
115 55 = 5 - 5 format (extended for PC, 10 function keys) */
116
117int slk_init(int fmt)
118{
119 PDC_LOG(("slk_init() - called\n"));
120
121 if (SP)
122 return ERR;
123
124 switch (fmt)
125 {
126 case 0: /* 3 - 2 - 3 */
127 labels = LABEL_NORMAL;
128 break;
129
130 case 1: /* 4 - 4 */
131 labels = LABEL_NORMAL;
132 break;
133
134 case 2: /* 4 4 4 */
135 labels = LABEL_NCURSES_EXTENDED;
136 break;
137
138 case 3: /* 4 4 4 with index */
139 labels = LABEL_NCURSES_EXTENDED;
140 break;
141
142 case 55: /* 5 - 5 */
143 labels = LABEL_EXTENDED;
144 break;
145
146 default:
147 return ERR;
148 }
149
150 label_fmt = fmt;
151
152 slk = calloc(labels, sizeof(struct SLK));
153
154 if (!slk)
155 labels = 0;
156
157 return slk ? OK : ERR;
158}
159
160/* draw a single button */
161
162static void _drawone(int num)
163{
164 int i, col, slen;
165
166 if (hidden)
167 return;
168
169 slen = slk[num].len;
170
171 switch (slk[num].format)
172 {
173 case 0: /* LEFT */
174 col = 0;
175 break;
176
177 case 1: /* CENTER */
178 col = (label_length - slen) / 2;
179
180 if (col + slen > label_length)
181 --col;
182 break;
183
184 default: /* RIGHT */
185 col = label_length - slen;
186 }
187
188 wmove(SP->slk_winptr, label_line, slk[num].start_col);
189
190 for (i = 0; i < label_length; ++i)
191 waddch(SP->slk_winptr, (i >= col && i < (col + slen)) ?
192 slk[num].label[i - col] : ' ');
193}
194
195/* redraw each button */
196
197static void _redraw(void)
198{
199 int i;
200
201 for (i = 0; i < labels; ++i)
202 _drawone(i);
203}
204
205/* slk_set() Used to set a slk label to a string.
206
207 labnum = 1 - 8 (or 10) (number of the label)
208 label = string (8 or 7 bytes total), or NULL
209 justify = 0 : left, 1 : center, 2 : right */
210
211int slk_set(int labnum, const char *label, int justify)
212{
213#ifdef PDC_WIDE
214 wchar_t wlabel[32];
215
216 PDC_mbstowcs(wlabel, label, 31);
217 return slk_wset(labnum, wlabel, justify);
218#else
219 PDC_LOG(("slk_set() - called\n"));
220
221 if (labnum < 1 || labnum > labels || justify < 0 || justify > 2)
222 return ERR;
223
224 labnum--;
225
226 if (!label || !(*label))
227 {
228 /* Clear the label */
229
230 *slk[labnum].label = 0;
231 slk[labnum].format = 0;
232 slk[labnum].len = 0;
233 }
234 else
235 {
236 int i, j = 0;
237
238 /* Skip leading spaces */
239
240 while (label[j] == ' ')
241 j++;
242
243 /* Copy it */
244
245 for (i = 0; i < label_length; i++)
246 {
247 chtype ch = label[i + j];
248
249 slk[labnum].label[i] = ch;
250
251 if (!ch)
252 break;
253 }
254
255 /* Drop trailing spaces */
256
257 while ((i + j) && (label[i + j - 1] == ' '))
258 i--;
259
260 slk[labnum].label[i] = 0;
261 slk[labnum].format = justify;
262 slk[labnum].len = i;
263 }
264
265 _drawone(labnum);
266
267 return OK;
268#endif
269}
270
271int slk_refresh(void)
272{
273 PDC_LOG(("slk_refresh() - called\n"));
274
275 return (slk_noutrefresh() == ERR) ? ERR : doupdate();
276}
277
278int slk_noutrefresh(void)
279{
280 PDC_LOG(("slk_noutrefresh() - called\n"));
281
282 if (!SP)
283 return ERR;
284
285 return wnoutrefresh(SP->slk_winptr);
286}
287
288char *slk_label(int labnum)
289{
290 static char temp[33];
291#ifdef PDC_WIDE
292 wchar_t *wtemp = slk_wlabel(labnum);
293
294 PDC_wcstombs(temp, wtemp, 32);
295#else
296 chtype *p;
297 int i;
298
299 PDC_LOG(("slk_label() - called\n"));
300
301 if (labnum < 1 || labnum > labels)
302 return (char *)0;
303
304 for (i = 0, p = slk[labnum - 1].label; *p; i++)
305 temp[i] = *p++;
306
307 temp[i] = '\0';
308#endif
309 return temp;
310}
311
312int slk_clear(void)
313{
314 PDC_LOG(("slk_clear() - called\n"));
315
316 if (!SP)
317 return ERR;
318
319 hidden = TRUE;
320 werase(SP->slk_winptr);
321 return wrefresh(SP->slk_winptr);
322}
323
324int slk_restore(void)
325{
326 PDC_LOG(("slk_restore() - called\n"));
327
328 if (!SP)
329 return ERR;
330
331 hidden = FALSE;
332 _redraw();
333 return wrefresh(SP->slk_winptr);
334}
335
336int slk_touch(void)
337{
338 PDC_LOG(("slk_touch() - called\n"));
339
340 if (!SP)
341 return ERR;
342
343 return touchwin(SP->slk_winptr);
344}
345
346int slk_attron(const chtype attrs)
347{
348 int rc;
349
350 PDC_LOG(("slk_attron() - called\n"));
351
352 if (!SP)
353 return ERR;
354
355 rc = wattron(SP->slk_winptr, attrs);
356 _redraw();
357
358 return rc;
359}
360
361int slk_attr_on(const attr_t attrs, void *opts)
362{
363 PDC_LOG(("slk_attr_on() - called\n"));
364
365 return slk_attron(attrs);
366}
367
368int slk_attroff(const chtype attrs)
369{
370 int rc;
371
372 PDC_LOG(("slk_attroff() - called\n"));
373
374 if (!SP)
375 return ERR;
376
377 rc = wattroff(SP->slk_winptr, attrs);
378 _redraw();
379
380 return rc;
381}
382
383int slk_attr_off(const attr_t attrs, void *opts)
384{
385 PDC_LOG(("slk_attr_off() - called\n"));
386
387 return slk_attroff(attrs);
388}
389
390int slk_attrset(const chtype attrs)
391{
392 int rc;
393
394 PDC_LOG(("slk_attrset() - called\n"));
395
396 if (!SP)
397 return ERR;
398
399 rc = wattrset(SP->slk_winptr, attrs);
400 _redraw();
401
402 return rc;
403}
404
405int slk_color(short color_pair)
406{
407 int rc;
408
409 PDC_LOG(("slk_color() - called\n"));
410
411 if (!SP)
412 return ERR;
413
414 rc = wcolor_set(SP->slk_winptr, color_pair, NULL);
415 _redraw();
416
417 return rc;
418}
419
420int slk_attr_set(const attr_t attrs, short color_pair, void *opts)
421{
422 PDC_LOG(("slk_attr_set() - called\n"));
423
424 return slk_attrset(attrs | COLOR_PAIR(color_pair));
425}
426
427static void _slk_calc(void)
428{
429 int i, center, col = 0;
430 label_length = COLS / labels;
431
432 if (label_length > 31)
433 label_length = 31;
434
435 switch (label_fmt)
436 {
437 case 0: /* 3 - 2 - 3 F-Key layout */
438
439 --label_length;
440
441 slk[0].start_col = col;
442 slk[1].start_col = (col += label_length);
443 slk[2].start_col = (col += label_length);
444
445 center = COLS / 2;
446
447 slk[3].start_col = center - label_length + 1;
448 slk[4].start_col = center + 1;
449
450 col = COLS - (label_length * 3) + 1;
451
452 slk[5].start_col = col;
453 slk[6].start_col = (col += label_length);
454 slk[7].start_col = (col += label_length);
455 break;
456
457 case 1: /* 4 - 4 F-Key layout */
458
459 for (i = 0; i < 8; i++)
460 {
461 slk[i].start_col = col;
462 col += label_length;
463
464 if (i == 3)
465 col = COLS - (label_length * 4) + 1;
466 }
467
468 break;
469
470 case 2: /* 4 4 4 F-Key layout */
471 case 3: /* 4 4 4 F-Key layout with index */
472
473 for (i = 0; i < 4; i++)
474 {
475 slk[i].start_col = col;
476 col += label_length;
477 }
478
479 center = COLS / 2;
480
481 slk[4].start_col = center - (label_length * 2) + 1;
482 slk[5].start_col = center - label_length + 1;
483 slk[6].start_col = center + 1;
484 slk[7].start_col = center + label_length + 1;
485
486 col = COLS - (label_length * 4) + 1;
487
488 for (i = 8; i < 12; i++)
489 {
490 slk[i].start_col = col;
491 col += label_length;
492 }
493
494 break;
495
496 default: /* 5 - 5 F-Key layout */
497
498 for (i = 0; i < 10; i++)
499 {
500 slk[i].start_col = col;
501 col += label_length;
502
503 if (i == 4)
504 col = COLS - (label_length * 5) + 1;
505 }
506 }
507
508 --label_length;
509
510 /* make sure labels are all in window */
511
512 _redraw();
513}
514
515void PDC_slk_initialize(void)
516{
517 if (slk)
518 {
519 if (label_fmt == 3)
520 {
521 SP->slklines = 2;
522 label_line = 1;
523 }
524 else
525 SP->slklines = 1;
526
527 if (!SP->slk_winptr)
528 {
529 SP->slk_winptr = newwin(SP->slklines, COLS,
530 LINES - SP->slklines, 0);
531 if (!SP->slk_winptr)
532 return;
533
534 wattrset(SP->slk_winptr, A_REVERSE);
535 }
536
537 _slk_calc();
538
539 /* if we have an index line, display it now */
540
541 if (label_fmt == 3)
542 {
543 chtype save_attr;
544 int i;
545
546 save_attr = SP->slk_winptr->_attrs;
547 wattrset(SP->slk_winptr, A_NORMAL);
548 wmove(SP->slk_winptr, 0, 0);
549 whline(SP->slk_winptr, 0, COLS);
550
551 for (i = 0; i < labels; i++)
552 mvwprintw(SP->slk_winptr, 0, slk[i].start_col, "F%d", i + 1);
553
554 SP->slk_winptr->_attrs = save_attr;
555 }
556
557 touchwin(SP->slk_winptr);
558 }
559}
560
561void PDC_slk_free(void)
562{
563 if (slk)
564 {
565 if (SP->slk_winptr)
566 {
567 delwin(SP->slk_winptr);
568 SP->slk_winptr = (WINDOW *)NULL;
569 }
570
571 free(slk);
572 slk = (struct SLK *)NULL;
573
574 label_length = 0;
575 labels = 0;
576 label_fmt = 0;
577 label_line = 0;
578 hidden = FALSE;
579 }
580}
581
582int PDC_mouse_in_slk(int y, int x)
583{
584 int i;
585
586 PDC_LOG(("PDC_mouse_in_slk() - called: y->%d x->%d\n", y, x));
587
588 /* If the line on which the mouse was clicked is NOT the last line
589 of the screen, we are not interested in it. */
590
591 if (!slk || !SP->slk_winptr || (y != SP->slk_winptr->_begy + label_line))
592 return 0;
593
594 for (i = 0; i < labels; i++)
595 if (x >= slk[i].start_col && x < (slk[i].start_col + label_length))
596 return i + 1;
597
598 return 0;
599}
600
601#ifdef PDC_WIDE
602int slk_wset(int labnum, const wchar_t *label, int justify)
603{
604 PDC_LOG(("slk_wset() - called\n"));
605
606 if (labnum < 1 || labnum > labels || justify < 0 || justify > 2)
607 return ERR;
608
609 labnum--;
610
611 if (!label || !(*label))
612 {
613 /* Clear the label */
614
615 *slk[labnum].label = 0;
616 slk[labnum].format = 0;
617 slk[labnum].len = 0;
618 }
619 else
620 {
621 int i, j = 0;
622
623 /* Skip leading spaces */
624
625 while (label[j] == L' ')
626 j++;
627
628 /* Copy it */
629
630 for (i = 0; i < label_length; i++)
631 {
632 chtype ch = label[i + j];
633
634 slk[labnum].label[i] = ch;
635
636 if (!ch)
637 break;
638 }
639
640 /* Drop trailing spaces */
641
642 while ((i + j) && (label[i + j - 1] == L' '))
643 i--;
644
645 slk[labnum].label[i] = 0;
646 slk[labnum].format = justify;
647 slk[labnum].len = i;
648 }
649
650 _drawone(labnum);
651
652 return OK;
653}
654
655wchar_t *slk_wlabel(int labnum)
656{
657 static wchar_t temp[33];
658 chtype *p;
659 int i;
660
661 PDC_LOG(("slk_wlabel() - called\n"));
662
663 if (labnum < 1 || labnum > labels)
664 return (wchar_t *)0;
665
666 for (i = 0, p = slk[labnum - 1].label; *p; i++)
667 temp[i] = *p++;
668
669 temp[i] = '\0';
670
671 return temp;
672}
673#endif
diff --git a/scripts/kconfig/libcurses/touch.c b/scripts/kconfig/libcurses/touch.c
new file mode 100644
index 000000000..7ea0b64b2
--- /dev/null
+++ b/scripts/kconfig/libcurses/touch.c
@@ -0,0 +1,210 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7touch
8-----
9
10### Synopsis
11
12 int touchwin(WINDOW *win);
13 int touchline(WINDOW *win, int start, int count);
14 int untouchwin(WINDOW *win);
15 int wtouchln(WINDOW *win, int y, int n, int changed);
16 bool is_linetouched(WINDOW *win, int line);
17 bool is_wintouched(WINDOW *win);
18
19 int touchoverlap(const WINDOW *win1, WINDOW *win2);
20
21### Description
22
23 touchwin() and touchline() throw away all information about which
24 parts of the window have been touched, pretending that the entire
25 window has been drawn on. This is sometimes necessary when using
26 overlapping windows, since a change to one window will affect the
27 other window, but the records of which lines have been changed in the
28 other window will not reflect the change.
29
30 untouchwin() marks all lines in the window as unchanged since the
31 last call to wrefresh().
32
33 wtouchln() makes n lines in the window, starting at line y, look as
34 if they have (changed == 1) or have not (changed == 0) been changed
35 since the last call to wrefresh().
36
37 is_linetouched() returns TRUE if the specified line in the specified
38 window has been changed since the last call to wrefresh().
39
40 is_wintouched() returns TRUE if the specified window has been changed
41 since the last call to wrefresh().
42
43 touchoverlap(win1, win2) marks the portion of win2 which overlaps
44 with win1 as modified.
45
46### Return Value
47
48 All functions return OK on success and ERR on error except
49 is_wintouched() and is_linetouched().
50
51### Portability
52
53 Function | X/Open | ncurses | NetBSD
54 :---------------------|:------:|:-------:|:------:
55 touchwin | Y | Y | Y
56 touchline | Y | Y | Y
57 untouchwin | Y | Y | Y
58 wtouchln | Y | Y | Y
59 is_linetouched | Y | Y | Y
60 is_wintouched | Y | Y | Y
61 touchoverlap | - | - | Y
62
63**man-end****************************************************************/
64
65int touchwin(WINDOW *win)
66{
67 int i;
68
69 PDC_LOG(("touchwin() - called: Win=%x\n", win));
70
71 if (!win)
72 return ERR;
73
74 for (i = 0; i < win->_maxy; i++)
75 {
76 win->_firstch[i] = 0;
77 win->_lastch[i] = win->_maxx - 1;
78 }
79
80 return OK;
81}
82
83int touchline(WINDOW *win, int start, int count)
84{
85 int i;
86
87 PDC_LOG(("touchline() - called: win=%p start %d count %d\n",
88 win, start, count));
89
90 if (!win || start > win->_maxy || start + count > win->_maxy)
91 return ERR;
92
93 for (i = start; i < start + count; i++)
94 {
95 win->_firstch[i] = 0;
96 win->_lastch[i] = win->_maxx - 1;
97 }
98
99 return OK;
100}
101
102int untouchwin(WINDOW *win)
103{
104 int i;
105
106 PDC_LOG(("untouchwin() - called: win=%p", win));
107
108 if (!win)
109 return ERR;
110
111 for (i = 0; i < win->_maxy; i++)
112 {
113 win->_firstch[i] = _NO_CHANGE;
114 win->_lastch[i] = _NO_CHANGE;
115 }
116
117 return OK;
118}
119
120int wtouchln(WINDOW *win, int y, int n, int changed)
121{
122 int i;
123
124 PDC_LOG(("wtouchln() - called: win=%p y=%d n=%d changed=%d\n",
125 win, y, n, changed));
126
127 if (!win || y > win->_maxy || y + n > win->_maxy)
128 return ERR;
129
130 for (i = y; i < y + n; i++)
131 {
132 if (changed)
133 {
134 win->_firstch[i] = 0;
135 win->_lastch[i] = win->_maxx - 1;
136 }
137 else
138 {
139 win->_firstch[i] = _NO_CHANGE;
140 win->_lastch[i] = _NO_CHANGE;
141 }
142 }
143
144 return OK;
145}
146
147bool is_linetouched(WINDOW *win, int line)
148{
149 PDC_LOG(("is_linetouched() - called: win=%p line=%d\n", win, line));
150
151 if (!win || line > win->_maxy || line < 0)
152 return FALSE;
153
154 return (win->_firstch[line] != _NO_CHANGE) ? TRUE : FALSE;
155}
156
157bool is_wintouched(WINDOW *win)
158{
159 int i;
160
161 PDC_LOG(("is_wintouched() - called: win=%p\n", win));
162
163 if (win)
164 for (i = 0; i < win->_maxy; i++)
165 if (win->_firstch[i] != _NO_CHANGE)
166 return TRUE;
167
168 return FALSE;
169}
170
171int touchoverlap(const WINDOW *win1, WINDOW *win2)
172{
173 int y, endy, endx, starty, startx, begy1, begx1, begy2, begx2;
174
175 PDC_LOG(("touchoverlap() - called: win1=%p win2=%p\n", win1, win2));
176
177 if (!win1 || !win2)
178 return ERR;
179
180 begy1 = win1->_begy;
181 begx1 = win1->_begx;
182 begy2 = win2->_begy;
183 begx2 = win2->_begy;
184
185 starty = max(begy1, begy2);
186 startx = max(begx1, begx2);
187 endy = min(win1->_maxy + begy1, win2->_maxy + begy2);
188 endx = min(win1->_maxx + begx1, win2->_maxx + begx2);
189
190 if (starty >= endy || startx >= endx)
191 return OK;
192
193 starty -= begy2;
194 startx -= begx2;
195 endy -= begy2;
196 endx -= begx2;
197 endx -= 1;
198
199 for (y = starty; y < endy; y++)
200 {
201 int first = win2->_firstch[y];
202
203 if (first == _NO_CHANGE || win2->_lastch[y] < endx)
204 win2->_lastch[y] = endx;
205 if (first == _NO_CHANGE || first > startx)
206 win2->_firstch[y] = startx;
207 }
208
209 return OK;
210}
diff --git a/scripts/kconfig/libcurses/window.c b/scripts/kconfig/libcurses/window.c
new file mode 100644
index 000000000..891d0c05b
--- /dev/null
+++ b/scripts/kconfig/libcurses/window.c
@@ -0,0 +1,639 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7window
8------
9
10### Synopsis
11
12 WINDOW *newwin(int nlines, int ncols, int begy, int begx);
13 WINDOW *derwin(WINDOW* orig, int nlines, int ncols,
14 int begy, int begx);
15 WINDOW *subwin(WINDOW* orig, int nlines, int ncols,
16 int begy, int begx);
17 WINDOW *dupwin(WINDOW *win);
18 WINDOW *wgetparent(const WINDOW *win);
19 int delwin(WINDOW *win);
20 int mvwin(WINDOW *win, int y, int x);
21 int mvderwin(WINDOW *win, int pary, int parx);
22 int syncok(WINDOW *win, bool bf);
23 bool is_subwin(const WINDOW *win);
24 bool is_syncok(const WINDOW *win);
25 void wsyncup(WINDOW *win);
26 void wcursyncup(WINDOW *win);
27 void wsyncdown(WINDOW *win);
28
29 WINDOW *resize_window(WINDOW *win, int nlines, int ncols);
30 int wresize(WINDOW *win, int nlines, int ncols);
31 WINDOW *PDC_makelines(WINDOW *win);
32 WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx);
33 void PDC_sync(WINDOW *win);
34
35### Description
36
37 newwin() creates a new window with the given number of lines, nlines
38 and columns, ncols. The upper left corner of the window is at line
39 begy, column begx. If nlines is zero, it defaults to LINES - begy;
40 ncols to COLS - begx. Create a new full-screen window by calling
41 newwin(0, 0, 0, 0).
42
43 delwin() deletes the named window, freeing all associated memory. In
44 the case of overlapping windows, subwindows should be deleted before
45 the main window.
46
47 mvwin() moves the window so that the upper left-hand corner is at
48 position (y,x). If the move would cause the window to be off the
49 screen, it is an error and the window is not moved. Moving subwindows
50 is allowed.
51
52 subwin() creates a new subwindow within a window. The dimensions of
53 the subwindow are nlines lines and ncols columns. The subwindow is at
54 position (begy, begx) on the screen. This position is relative to the
55 screen, and not to the window orig. Changes made to either window
56 will affect both. When using this routine, you will often need to
57 call touchwin() before calling wrefresh().
58
59 derwin() is the same as subwin(), except that begy and begx are
60 relative to the origin of the window orig rather than the screen.
61 There is no difference between subwindows and derived windows.
62
63 mvderwin() moves a derived window (or subwindow) inside its parent
64 window. The screen-relative parameters of the window are not changed.
65 This routine is used to display different parts of the parent window
66 at the same physical position on the screen.
67
68 dupwin() creates an exact duplicate of the window win.
69
70 wgetparent() returns the parent WINDOW pointer for subwindows, or NULL
71 for windows having no parent.
72
73 wsyncup() causes a touchwin() of all of the window's parents.
74
75 If syncok() is called with a second argument of TRUE, this causes a
76 wsyncup() to be called every time the window is changed.
77
78 is_subwin() reports whether the specified window is a subwindow,
79 created by subwin() or derwin().
80
81 is_syncok() reports whether the specified window is in syncok mode.
82
83 wcursyncup() causes the current cursor position of all of a window's
84 ancestors to reflect the current cursor position of the current
85 window.
86
87 wsyncdown() causes a touchwin() of the current window if any of its
88 parent's windows have been touched.
89
90 resize_window() allows the user to resize an existing window. It
91 returns the pointer to the new window, or NULL on failure.
92
93 wresize() is an ncurses-compatible wrapper for resize_window(). Note
94 that, unlike ncurses, it will NOT process any subwindows of the
95 window. (However, you still can call it _on_ subwindows.) It returns
96 OK or ERR.
97
98 PDC_makenew() allocates all data for a new WINDOW * except the actual
99 lines themselves. If it's unable to allocate memory for the window
100 structure, it will free all allocated memory and return a NULL
101 pointer.
102
103 PDC_makelines() allocates the memory for the lines.
104
105 PDC_sync() handles wrefresh() and wsyncup() calls when a window is
106 changed.
107
108### Return Value
109
110 newwin(), subwin(), derwin() and dupwin() return a pointer to the new
111 window, or NULL on failure. delwin(), mvwin(), mvderwin() and
112 syncok() return OK or ERR. wsyncup(), wcursyncup() and wsyncdown()
113 return nothing.
114
115 is_subwin() and is_syncok() returns TRUE or FALSE.
116
117### Errors
118
119 It is an error to call resize_window() before calling initscr().
120 Also, an error will be generated if we fail to create a newly sized
121 replacement window for curscr, or stdscr. This could happen when
122 increasing the window size. NOTE: If this happens, the previously
123 successfully allocated windows are left alone; i.e., the resize is
124 NOT cancelled for those windows.
125
126### Portability
127
128 Function | X/Open | ncurses | NetBSD
129 :---------------------|:------:|:-------:|:------:
130 newwin | Y | Y | Y
131 delwin | Y | Y | Y
132 mvwin | Y | Y | Y
133 subwin | Y | Y | Y
134 derwin | Y | Y | Y
135 mvderwin | Y | Y | Y
136 dupwin | Y | Y | Y
137 wgetparent | - | Y | -
138 wsyncup | Y | Y | Y
139 syncok | Y | Y | Y
140 is_subwin | - | Y | -
141 is_syncok | - | Y | -
142 wcursyncup | Y | Y | Y
143 wsyncdown | Y | Y | Y
144 wresize | - | Y | Y
145 resize_window | - | - | -
146 PDC_makelines | - | - | -
147 PDC_makenew | - | - | -
148 PDC_sync | - | - | -
149
150**man-end****************************************************************/
151
152#include <stdlib.h>
153
154WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx)
155{
156 WINDOW *win;
157
158 PDC_LOG(("PDC_makenew() - called: lines %d cols %d begy %d begx %d\n",
159 nlines, ncols, begy, begx));
160
161 /* allocate the window structure itself */
162
163 win = calloc(1, sizeof(WINDOW));
164 if (!win)
165 return win;
166
167 /* allocate the line pointer array */
168
169 win->_y = malloc(nlines * sizeof(chtype *));
170 if (!win->_y)
171 {
172 free(win);
173 return (WINDOW *)NULL;
174 }
175
176 /* allocate the minchng and maxchng arrays */
177
178 win->_firstch = malloc(nlines * sizeof(int));
179 if (!win->_firstch)
180 {
181 free(win->_y);
182 free(win);
183 return (WINDOW *)NULL;
184 }
185
186 win->_lastch = malloc(nlines * sizeof(int));
187 if (!win->_lastch)
188 {
189 free(win->_firstch);
190 free(win->_y);
191 free(win);
192 return (WINDOW *)NULL;
193 }
194
195 /* initialize window variables */
196
197 win->_maxy = nlines; /* real max screen size */
198 win->_maxx = ncols; /* real max screen size */
199 win->_begy = begy;
200 win->_begx = begx;
201 win->_bkgd = ' '; /* wrs 4/10/93 -- initialize background to blank */
202 win->_clear = (bool) ((nlines == LINES) && (ncols == COLS));
203 win->_bmarg = nlines - 1;
204 win->_parx = win->_pary = -1;
205
206 /* initialize pad variables*/
207
208 win->_pad._pad_y = -1;
209 win->_pad._pad_x = -1;
210 win->_pad._pad_top = -1;
211 win->_pad._pad_left = -1;
212 win->_pad._pad_bottom = -1;
213 win->_pad._pad_right = -1;
214
215 /* init to say window all changed */
216
217 touchwin(win);
218
219 return win;
220}
221
222WINDOW *PDC_makelines(WINDOW *win)
223{
224 int i, j, nlines, ncols;
225
226 PDC_LOG(("PDC_makelines() - called\n"));
227
228 if (!win)
229 return (WINDOW *)NULL;
230
231 nlines = win->_maxy;
232 ncols = win->_maxx;
233
234 for (i = 0; i < nlines; i++)
235 {
236 win->_y[i] = malloc(ncols * sizeof(chtype));
237 if (!win->_y[i])
238 {
239 /* if error, free all the data */
240
241 for (j = 0; j < i; j++)
242 free(win->_y[j]);
243
244 free(win->_firstch);
245 free(win->_lastch);
246 free(win->_y);
247 free(win);
248
249 return (WINDOW *)NULL;
250 }
251 }
252
253 return win;
254}
255
256void PDC_sync(WINDOW *win)
257{
258 PDC_LOG(("PDC_sync() - called:\n"));
259
260 if (win->_immed)
261 wrefresh(win);
262 if (win->_sync)
263 wsyncup(win);
264}
265
266WINDOW *newwin(int nlines, int ncols, int begy, int begx)
267{
268 WINDOW *win;
269
270 PDC_LOG(("newwin() - called:lines=%d cols=%d begy=%d begx=%d\n",
271 nlines, ncols, begy, begx));
272
273 if (!nlines)
274 nlines = LINES - begy;
275 if (!ncols)
276 ncols = COLS - begx;
277
278 if (!SP || begy + nlines > SP->lines || begx + ncols > SP->cols)
279 return (WINDOW *)NULL;
280
281 win = PDC_makenew(nlines, ncols, begy, begx);
282 if (win)
283 win = PDC_makelines(win);
284
285 if (win)
286 werase(win);
287
288 return win;
289}
290
291int delwin(WINDOW *win)
292{
293 int i;
294
295 PDC_LOG(("delwin() - called\n"));
296
297 if (!win)
298 return ERR;
299
300 /* subwindows use parents' lines */
301
302 if (!(win->_flags & (_SUBWIN|_SUBPAD)))
303 for (i = 0; i < win->_maxy && win->_y[i]; i++)
304 if (win->_y[i])
305 free(win->_y[i]);
306
307 free(win->_firstch);
308 free(win->_lastch);
309 free(win->_y);
310 free(win);
311
312 return OK;
313}
314
315int mvwin(WINDOW *win, int y, int x)
316{
317 PDC_LOG(("mvwin() - called\n"));
318
319 if (!win || (y + win->_maxy > LINES || y < 0)
320 || (x + win->_maxx > COLS || x < 0))
321 return ERR;
322
323 win->_begy = y;
324 win->_begx = x;
325 touchwin(win);
326
327 return OK;
328}
329
330WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx)
331{
332 WINDOW *win;
333 int i, j, k;
334
335 PDC_LOG(("subwin() - called: lines %d cols %d begy %d begx %d\n",
336 nlines, ncols, begy, begx));
337
338 /* make sure window fits inside the original one */
339
340 if (!orig || (begy < orig->_begy) || (begx < orig->_begx) ||
341 (begy + nlines) > (orig->_begy + orig->_maxy) ||
342 (begx + ncols) > (orig->_begx + orig->_maxx))
343 return (WINDOW *)NULL;
344
345 j = begy - orig->_begy;
346 k = begx - orig->_begx;
347
348 if (!nlines)
349 nlines = orig->_maxy - j;
350 if (!ncols)
351 ncols = orig->_maxx - k;
352
353 win = PDC_makenew(nlines, ncols, begy, begx);
354 if (!win)
355 return (WINDOW *)NULL;
356
357 /* initialize window variables */
358
359 win->_attrs = orig->_attrs;
360 win->_bkgd = orig->_bkgd;
361 win->_leaveit = orig->_leaveit;
362 win->_scroll = orig->_scroll;
363 win->_nodelay = orig->_nodelay;
364 win->_delayms = orig->_delayms;
365 win->_use_keypad = orig->_use_keypad;
366 win->_immed = orig->_immed;
367 win->_sync = orig->_sync;
368 win->_pary = j;
369 win->_parx = k;
370 win->_parent = orig;
371
372 for (i = 0; i < nlines; i++, j++)
373 win->_y[i] = orig->_y[j] + k;
374
375 win->_flags |= _SUBWIN;
376
377 return win;
378}
379
380WINDOW *derwin(WINDOW *orig, int nlines, int ncols, int begy, int begx)
381{
382 return subwin(orig, nlines, ncols, begy + orig->_begy, begx + orig->_begx);
383}
384
385int mvderwin(WINDOW *win, int pary, int parx)
386{
387 int i, j;
388 WINDOW *mypar;
389
390 if (!win || !(win->_parent))
391 return ERR;
392
393 mypar = win->_parent;
394
395 if (pary < 0 || parx < 0 || (pary + win->_maxy) > mypar->_maxy ||
396 (parx + win->_maxx) > mypar->_maxx)
397 return ERR;
398
399 j = pary;
400
401 for (i = 0; i < win->_maxy; i++)
402 win->_y[i] = (mypar->_y[j++]) + parx;
403
404 win->_pary = pary;
405 win->_parx = parx;
406
407 return OK;
408}
409
410WINDOW *dupwin(WINDOW *win)
411{
412 WINDOW *new;
413 chtype *ptr, *ptr1;
414 int nlines, ncols, begy, begx, i;
415
416 if (!win)
417 return (WINDOW *)NULL;
418
419 nlines = win->_maxy;
420 ncols = win->_maxx;
421 begy = win->_begy;
422 begx = win->_begx;
423
424 new = PDC_makenew(nlines, ncols, begy, begx);
425 if (new)
426 new = PDC_makelines(new);
427
428 if (!new)
429 return (WINDOW *)NULL;
430
431 /* copy the contents of win into new */
432
433 for (i = 0; i < nlines; i++)
434 {
435 for (ptr = new->_y[i], ptr1 = win->_y[i];
436 ptr < new->_y[i] + ncols; ptr++, ptr1++)
437 *ptr = *ptr1;
438
439 new->_firstch[i] = 0;
440 new->_lastch[i] = ncols - 1;
441 }
442
443 new->_curx = win->_curx;
444 new->_cury = win->_cury;
445 new->_maxy = win->_maxy;
446 new->_maxx = win->_maxx;
447 new->_begy = win->_begy;
448 new->_begx = win->_begx;
449 new->_flags = win->_flags;
450 new->_attrs = win->_attrs;
451 new->_clear = win->_clear;
452 new->_leaveit = win->_leaveit;
453 new->_scroll = win->_scroll;
454 new->_nodelay = win->_nodelay;
455 new->_delayms = win->_delayms;
456 new->_use_keypad = win->_use_keypad;
457 new->_tmarg = win->_tmarg;
458 new->_bmarg = win->_bmarg;
459 new->_parx = win->_parx;
460 new->_pary = win->_pary;
461 new->_parent = win->_parent;
462 new->_bkgd = win->_bkgd;
463 new->_flags = win->_flags;
464
465 return new;
466}
467
468WINDOW *wgetparent(const WINDOW *win)
469{
470 PDC_LOG(("wgetparent() - called\n"));
471
472 if (!win || !win->_parent)
473 return NULL;
474
475 return win->_parent;
476}
477
478WINDOW *resize_window(WINDOW *win, int nlines, int ncols)
479{
480 WINDOW *new;
481 int i, save_cury, save_curx, new_begy, new_begx;
482
483 PDC_LOG(("resize_window() - called: nlines %d ncols %d\n",
484 nlines, ncols));
485
486 if (!win || !SP)
487 return (WINDOW *)NULL;
488
489 if (win->_flags & _SUBPAD)
490 {
491 new = subpad(win->_parent, nlines, ncols, win->_begy, win->_begx);
492 if (!new)
493 return (WINDOW *)NULL;
494 }
495 else if (win->_flags & _SUBWIN)
496 {
497 new = subwin(win->_parent, nlines, ncols, win->_begy, win->_begx);
498 if (!new)
499 return (WINDOW *)NULL;
500 }
501 else
502 {
503 if (win == SP->slk_winptr)
504 {
505 new_begy = SP->lines - SP->slklines;
506 new_begx = 0;
507 }
508 else
509 {
510 new_begy = win->_begy;
511 new_begx = win->_begx;
512 }
513
514 new = PDC_makenew(nlines, ncols, new_begy, new_begx);
515 if (!new)
516 return (WINDOW *)NULL;
517 }
518
519 save_curx = min(win->_curx, (new->_maxx - 1));
520 save_cury = min(win->_cury, (new->_maxy - 1));
521
522 if (!(win->_flags & (_SUBPAD|_SUBWIN)))
523 {
524 new = PDC_makelines(new);
525 if (!new)
526 return (WINDOW *)NULL;
527
528 new->_bkgd = win->_bkgd;
529 werase(new);
530
531 copywin(win, new, 0, 0, 0, 0, min(win->_maxy, new->_maxy) - 1,
532 min(win->_maxx, new->_maxx) - 1, FALSE);
533
534 for (i = 0; i < win->_maxy && win->_y[i]; i++)
535 if (win->_y[i])
536 free(win->_y[i]);
537 }
538
539 new->_flags = win->_flags;
540 new->_attrs = win->_attrs;
541 new->_clear = win->_clear;
542 new->_leaveit = win->_leaveit;
543 new->_scroll = win->_scroll;
544 new->_nodelay = win->_nodelay;
545 new->_delayms = win->_delayms;
546 new->_use_keypad = win->_use_keypad;
547 new->_tmarg = (win->_tmarg > new->_maxy - 1) ? 0 : win->_tmarg;
548 new->_bmarg = (win->_bmarg == win->_maxy - 1) ?
549 new->_maxy - 1 : min(win->_bmarg, (new->_maxy - 1));
550 new->_parent = win->_parent;
551 new->_immed = win->_immed;
552 new->_sync = win->_sync;
553 new->_bkgd = win->_bkgd;
554
555 new->_curx = save_curx;
556 new->_cury = save_cury;
557
558 free(win->_firstch);
559 free(win->_lastch);
560 free(win->_y);
561
562 *win = *new;
563 free(new);
564
565 return win;
566}
567
568int wresize(WINDOW *win, int nlines, int ncols)
569{
570 return (resize_window(win, nlines, ncols) ? OK : ERR);
571}
572
573void wsyncup(WINDOW *win)
574{
575 WINDOW *tmp;
576
577 PDC_LOG(("wsyncup() - called\n"));
578
579 for (tmp = win; tmp; tmp = tmp->_parent)
580 touchwin(tmp);
581}
582
583int syncok(WINDOW *win, bool bf)
584{
585 PDC_LOG(("syncok() - called\n"));
586
587 if (!win)
588 return ERR;
589
590 win->_sync = bf;
591
592 return OK;
593}
594
595bool is_subwin(const WINDOW *win)
596{
597 PDC_LOG(("is_subwin() - called\n"));
598
599 if (!win)
600 return FALSE;
601
602 return ((win->_flags & _SUBWIN) ? TRUE : FALSE);
603}
604
605bool is_syncok(const WINDOW *win)
606{
607 PDC_LOG(("is_syncok() - called\n"));
608
609 if (!win)
610 return FALSE;
611
612 return win->_sync;
613}
614
615void wcursyncup(WINDOW *win)
616{
617 WINDOW *tmp;
618
619 PDC_LOG(("wcursyncup() - called\n"));
620
621 for (tmp = win; tmp && tmp->_parent; tmp = tmp->_parent)
622 wmove(tmp->_parent, tmp->_pary + tmp->_cury, tmp->_parx + tmp->_curx);
623}
624
625void wsyncdown(WINDOW *win)
626{
627 WINDOW *tmp;
628
629 PDC_LOG(("wsyncdown() - called\n"));
630
631 for (tmp = win; tmp; tmp = tmp->_parent)
632 {
633 if (is_wintouched(tmp))
634 {
635 touchwin(win);
636 break;
637 }
638 }
639}
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 527f60c99..b88b89d2d 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -11,9 +11,9 @@
11#ifndef KBUILD_NO_NLS 11#ifndef KBUILD_NO_NLS
12# include <libintl.h> 12# include <libintl.h>
13#else 13#else
14# define gettext(Msgid) ((const char *) (Msgid)) 14static inline const char *gettext(const char *txt) { return txt; }
15# define textdomain(Domainname) ((const char *) (Domainname)) 15static inline void textdomain(const char *domainname) {}
16# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) 16static inline void bindtextdomain(const char *name, const char *dir) {}
17#endif 17#endif
18 18
19#ifdef __cplusplus 19#ifdef __cplusplus
diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh
index 5075ebf2d..885586865 100755
--- a/scripts/kconfig/lxdialog/check-lxdialog.sh
+++ b/scripts/kconfig/lxdialog/check-lxdialog.sh
@@ -6,6 +6,10 @@ ldflags()
6{ 6{
7 pkg-config --libs ncursesw 2>/dev/null && exit 7 pkg-config --libs ncursesw 2>/dev/null && exit
8 pkg-config --libs ncurses 2>/dev/null && exit 8 pkg-config --libs ncurses 2>/dev/null && exit
9 if [ -n "$W64DEVKIT" ]
10 then
11 echo "./scripts/kconfig/libcurses/lib.a" && exit
12 fi
9 for ext in so a dll.a dylib ; do 13 for ext in so a dll.a dylib ; do
10 for lib in ncursesw ncurses curses ; do 14 for lib in ncursesw ncurses curses ; do
11 $cc -print-file-name=lib${lib}.${ext} | grep -q / 15 $cc -print-file-name=lib${lib}.${ext} | grep -q /
@@ -34,6 +38,8 @@ ccflags()
34 echo '-I/usr/include/ncurses -DCURSES_LOC="<curses.h>"' 38 echo '-I/usr/include/ncurses -DCURSES_LOC="<curses.h>"'
35 elif [ -f /usr/include/ncurses.h ]; then 39 elif [ -f /usr/include/ncurses.h ]; then
36 echo '-DCURSES_LOC="<ncurses.h>"' 40 echo '-DCURSES_LOC="<ncurses.h>"'
41 elif [ -n "$W64DEVKIT" ]; then
42 echo '-I./scripts/kconfig/libcurses -DCURSES_LOC="<curses.h>"'
37 else 43 else
38 echo '-DCURSES_LOC="<curses.h>"' 44 echo '-DCURSES_LOC="<curses.h>"'
39 fi 45 fi
@@ -47,7 +53,7 @@ trap "rm -f $tmp" 0 1 2 3 15
47check() { 53check() {
48 $cc -x c - -o $tmp 2>/dev/null <<'EOF' 54 $cc -x c - -o $tmp 2>/dev/null <<'EOF'
49#include CURSES_LOC 55#include CURSES_LOC
50main() {} 56int main() { return 0; }
51EOF 57EOF
52 if [ $? != 0 ]; then 58 if [ $? != 0 ]; then
53 echo " *** Unable to find the ncurses libraries or the" 1>&2 59 echo " *** Unable to find the ncurses libraries or the" 1>&2
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index af3cf716e..10a3292e1 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -24,6 +24,7 @@
24#include <ctype.h> 24#include <ctype.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <string.h> 26#include <string.h>
27#include <strings.h>
27 28
28#ifdef __sun__ 29#ifdef __sun__
29#define CURS_MACROS 30#define CURS_MACROS
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index 072d3eecc..ea3ee4a95 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -138,6 +138,9 @@ void dialog_clear(void)
138 */ 138 */
139void init_dialog(void) 139void init_dialog(void)
140{ 140{
141 char *colors = getenv("COLORS");
142 use_colors = !(colors && *colors == '0');
143
141 initscr(); /* Init curses */ 144 initscr(); /* Init curses */
142 keypad(stdscr, TRUE); 145 keypad(stdscr, TRUE);
143 cbreak(); 146 cbreak();
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index aaf82820e..62baa82b0 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -12,8 +12,12 @@
12/* On Darwin, this may be needed to get SIGWINCH: */ 12/* On Darwin, this may be needed to get SIGWINCH: */
13#define _DARWIN_C_SOURCE 1 13#define _DARWIN_C_SOURCE 1
14 14
15#ifndef __MINGW32__
15#include <sys/ioctl.h> 16#include <sys/ioctl.h>
16#include <sys/wait.h> 17#include <sys/wait.h>
18#else
19#include <windows.h>
20#endif
17#include <ctype.h> 21#include <ctype.h>
18#include <errno.h> 22#include <errno.h>
19#include <fcntl.h> 23#include <fcntl.h>
@@ -23,13 +27,17 @@
23#include <stdlib.h> 27#include <stdlib.h>
24#include <string.h> 28#include <string.h>
25#include <strings.h> /* for strcasecmp */ 29#include <strings.h> /* for strcasecmp */
30#ifndef __MINGW32__
26#include <termios.h> 31#include <termios.h>
32#endif
27#include <unistd.h> 33#include <unistd.h>
28#include <locale.h> 34#include <locale.h>
29 35
36#ifndef __MINGW32__
30#ifndef SIGWINCH 37#ifndef SIGWINCH
31#define SIGWINCH 28 38#define SIGWINCH 28
32#endif 39#endif
40#endif
33 41
34#define LKC_DIRECT_LINK 42#define LKC_DIRECT_LINK
35#include "lkc.h" 43#include "lkc.h"
@@ -270,11 +278,15 @@ static char input_buf[4096];
270static const char filename[] = ".config"; 278static const char filename[] = ".config";
271static char *args[1024], **argptr = args; 279static char *args[1024], **argptr = args;
272static int indent; 280static int indent;
281#ifndef __MINGW32__
273static struct termios ios_org; 282static struct termios ios_org;
283#endif
274static int rows = 0, cols = 0; 284static int rows = 0, cols = 0;
275static struct menu *current_menu; 285static struct menu *current_menu;
276static int child_count; 286static int child_count;
287#ifndef __MINGW32__
277static int do_resize; 288static int do_resize;
289#endif
278static int single_menu_mode; 290static int single_menu_mode;
279 291
280static void conf(struct menu *menu); 292static void conf(struct menu *menu);
@@ -292,12 +304,45 @@ static int cprint1(const char *fmt, ...);
292static void cprint_done(void); 304static void cprint_done(void);
293static int cprint(const char *fmt, ...); 305static int cprint(const char *fmt, ...);
294 306
307#ifdef __MINGW32__
308struct winsize {
309 unsigned short ws_row, ws_col;
310 unsigned short ws_xpixel, ws_ypixel;
311};
312
313static int mingw_get_terminal_width_height(struct winsize *win)
314{
315 int fd;
316 HANDLE handle;
317 CONSOLE_SCREEN_BUFFER_INFO sbi;
318
319 win->ws_row = 0;
320 win->ws_col = 0;
321
322 for (fd=STDOUT_FILENO; fd<=STDERR_FILENO; ++fd) {
323 handle = (HANDLE)_get_osfhandle(fd);
324 if (handle != INVALID_HANDLE_VALUE &&
325 GetConsoleScreenBufferInfo(handle, &sbi) != 0) {
326 win->ws_row = sbi.srWindow.Bottom - sbi.srWindow.Top + 1;
327 win->ws_col = sbi.srWindow.Right - sbi.srWindow.Left + 1;
328 return 0;
329 }
330 }
331
332 return -1;
333}
334#endif
335
295static void init_wsize(void) 336static void init_wsize(void)
296{ 337{
297 struct winsize ws; 338 struct winsize ws;
298 char *env; 339 char *env;
299 340
341#ifndef __MINGW32__
300 if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) { 342 if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) {
343#else
344 if (mingw_get_terminal_width_height(&ws) == 0) {
345#endif
301 rows = ws.ws_row; 346 rows = ws.ws_row;
302 cols = ws.ws_col; 347 cols = ws.ws_col;
303 } 348 }
@@ -459,8 +504,198 @@ static void winch_handler(int sig)
459} 504}
460#endif 505#endif
461 506
507#ifdef __MINGW32__
508static char *
509quote_arg(const char *arg)
510{
511 int len = 0, n = 0;
512 int force_quotes = 0;
513 char *q, *d;
514 const char *p = arg;
515
516 /* empty arguments must be quoted */
517 if (!*p) {
518 force_quotes = 1;
519 }
520
521 while (*p) {
522 if (isspace(*p)) {
523 /* arguments containing whitespace must be quoted */
524 force_quotes = 1;
525 }
526 else if (*p == '"') {
527 /* double quotes in arguments need to be escaped */
528 n++;
529 }
530 else if (*p == '\\') {
531 /* count contiguous backslashes */
532 int count = 0;
533 while (*p == '\\') {
534 count++;
535 p++;
536 len++;
537 }
538
539 /*
540 * Only escape backslashes before explicit double quotes or
541 * or where the backslashes are at the end of an argument
542 * that is scheduled to be quoted.
543 */
544 if (*p == '"' || (force_quotes && *p == '\0')) {
545 n += count*2 + 1;
546 }
547
548 if (*p == '\0') {
549 break;
550 }
551 continue;
552 }
553 len++;
554 p++;
555 }
556
557 if (!force_quotes && n == 0) {
558 return (char*)strdup(arg);
559 }
560
561 /* insert double quotes and backslashes where necessary */
562 d = q = malloc(len+n+3);
563 if (q == NULL)
564 return NULL;
565 if (force_quotes) {
566 *d++ = '"';
567 }
568
569 while (*arg) {
570 if (*arg == '"') {
571 *d++ = '\\';
572 }
573 else if (*arg == '\\') {
574 int count = 0;
575 while (*arg == '\\') {
576 count++;
577 *d++ = *arg++;
578 }
579
580 if (*arg == '"' || (force_quotes && *arg == '\0')) {
581 while (count-- > 0) {
582 *d++ = '\\';
583 }
584 if (*arg == '"') {
585 *d++ = '\\';
586 }
587 }
588 }
589 if (*arg != '\0') {
590 *d++ = *arg++;
591 }
592 }
593 if (force_quotes) {
594 *d++ = '"';
595 }
596 *d = '\0';
597
598 return q;
599}
600
601static int mingw_pipe(HANDLE *pipe)
602{
603 SECURITY_ATTRIBUTES sa;
604
605 sa.nLength = sizeof(sa); /* Length in bytes */
606 sa.bInheritHandle = 1; /* the child must inherit these handles */
607 sa.lpSecurityDescriptor = NULL;
608
609 /* pipe[0] is the read handle, pipe[i] the write handle */
610 if ( !CreatePipe (&pipe[0], &pipe[1], &sa, 1 << 13) ) {
611 return -1;
612 }
613
614 return (pipe[0] == INVALID_HANDLE_VALUE ||
615 pipe[1] == INVALID_HANDLE_VALUE) ? -1 : 0;
616}
617#endif
618
462static int exec_conf(void) 619static int exec_conf(void)
463{ 620{
621#ifdef __MINGW32__
622 char **a, *cmd;
623 int fd, size, len = 0;
624 STARTUPINFO siStartInfo;
625 PROCESS_INFORMATION piProcInfo;
626 HANDLE hPipe[2];
627 DWORD stat = 0;
628
629 // Quote each argument if necessary
630 *argptr++ = NULL;
631 for (a = args; *a; a++) {
632 *a = quote_arg(*a);
633 if (*a == NULL)
634 _exit(EXIT_FAILURE);
635 len += strlen(*a) + 1;
636 }
637
638 // Make a command line from the arguments
639 cmd = malloc(len + 1);
640 if (cmd == NULL)
641 _exit(EXIT_FAILURE);
642 for (a = args; *a; a++) {
643 if (a == args) {
644 strcpy(cmd, *a);
645 } else {
646 strcat(cmd, " ");
647 strcat(cmd, *a);
648 }
649 free(*a);
650 }
651
652 // Create a pipe to communicate with the dialog
653 if (mingw_pipe(hPipe) == -1)
654 _exit(EXIT_FAILURE);
655
656 // Make the parent end of the pipe non-inheritable
657 SetHandleInformation(hPipe[0], HANDLE_FLAG_INHERIT, 0);
658
659 ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
660 siStartInfo.cb = sizeof(STARTUPINFO);
661 siStartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
662 siStartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
663 siStartInfo.hStdError = hPipe[1];
664 siStartInfo.dwFlags = STARTF_USESTDHANDLES;
665 CreateProcess(NULL, (LPSTR)cmd, NULL, NULL, TRUE, 0, NULL, NULL,
666 &siStartInfo, &piProcInfo);
667 free(cmd);
668
669 // Close child end of pipe
670 CloseHandle(hPipe[1]);
671 hPipe[1] = INVALID_HANDLE_VALUE;
672
673 fd = _open_osfhandle((intptr_t)hPipe[0], _O_RDONLY | _O_BINARY);
674 if (fd == -1)
675 _exit(EXIT_FAILURE);
676
677 bufptr = input_buf;
678 while (1) {
679 size = input_buf + sizeof(input_buf) - bufptr;
680 size = _read(fd, bufptr, size);
681 if (size <= 0) {
682 if (size < 0) {
683 if (errno == EINTR || errno == EAGAIN)
684 continue;
685 perror("read");
686 }
687 break;
688 }
689 bufptr += size;
690 }
691 *bufptr++ = 0;
692 close(fd);
693
694 WaitForSingleObject(piProcInfo.hProcess, INFINITE);
695 GetExitCodeProcess(piProcInfo.hProcess, &stat);
696
697 return (int)(stat &0xff);
698#else
464 int pipefd[2], stat, size; 699 int pipefd[2], stat, size;
465 sigset_t sset, osset; 700 sigset_t sset, osset;
466 701
@@ -535,6 +770,7 @@ static int exec_conf(void)
535 sigprocmask(SIG_SETMASK, &osset, NULL); 770 sigprocmask(SIG_SETMASK, &osset, NULL);
536 771
537 return WEXITSTATUS(stat); 772 return WEXITSTATUS(stat);
773#endif
538} 774}
539 775
540static void search_conf(void) 776static void search_conf(void)
@@ -788,7 +1024,7 @@ static void conf(struct menu *menu)
788 switch (type) { 1024 switch (type) {
789 case 'm': 1025 case 'm':
790 if (single_menu_mode) 1026 if (single_menu_mode)
791 submenu->data = (void *) (long) !submenu->data; 1027 submenu->data = (void *) (intptr_t) !submenu->data;
792 else 1028 else
793 conf(submenu); 1029 conf(submenu);
794 break; 1030 break;
@@ -1051,7 +1287,9 @@ static void conf_save(void)
1051 1287
1052static void conf_cleanup(void) 1288static void conf_cleanup(void)
1053{ 1289{
1290#ifndef __MINGW32__
1054 tcsetattr(1, TCSAFLUSH, &ios_org); 1291 tcsetattr(1, TCSAFLUSH, &ios_org);
1292#endif
1055 unlink(".help.tmp"); 1293 unlink(".help.tmp");
1056 unlink("lxdialog.scrltmp"); 1294 unlink("lxdialog.scrltmp");
1057} 1295}
@@ -1080,7 +1318,9 @@ int main(int ac, char **av)
1080 single_menu_mode = 1; 1318 single_menu_mode = 1;
1081 } 1319 }
1082 1320
1321#ifndef __MINGW32__
1083 tcgetattr(1, &ios_org); 1322 tcgetattr(1, &ios_org);
1323#endif
1084 atexit(conf_cleanup); 1324 atexit(conf_cleanup);
1085 init_wsize(); 1325 init_wsize();
1086 conf(&rootmenu); 1326 conf(&rootmenu);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 3d7877afc..31d5fbbfc 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -6,8 +6,10 @@
6#include <ctype.h> 6#include <ctype.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <string.h> 8#include <string.h>
9#ifndef __MINGW32__
9#include <regex.h> 10#include <regex.h>
10#include <sys/utsname.h> 11#include <sys/utsname.h>
12#endif
11 13
12#define LKC_DIRECT_LINK 14#define LKC_DIRECT_LINK
13#include "lkc.h" 15#include "lkc.h"
@@ -44,7 +46,9 @@ void sym_add_default(struct symbol *sym, const char *def)
44void sym_init(void) 46void sym_init(void)
45{ 47{
46 struct symbol *sym; 48 struct symbol *sym;
49#ifndef __MINGW32__
47 struct utsname uts; 50 struct utsname uts;
51#endif
48 char *p; 52 char *p;
49 static bool inited = false; 53 static bool inited = false;
50 54
@@ -52,7 +56,9 @@ void sym_init(void)
52 return; 56 return;
53 inited = true; 57 inited = true;
54 58
59#ifndef __MINGW32__
55 uname(&uts); 60 uname(&uts);
61#endif
56 62
57 sym = sym_lookup("ARCH", 0); 63 sym = sym_lookup("ARCH", 0);
58 sym->type = S_STRING; 64 sym->type = S_STRING;
@@ -71,7 +77,11 @@ void sym_init(void)
71 sym = sym_lookup("UNAME_RELEASE", 0); 77 sym = sym_lookup("UNAME_RELEASE", 0);
72 sym->type = S_STRING; 78 sym->type = S_STRING;
73 sym->flags |= SYMBOL_AUTO; 79 sym->flags |= SYMBOL_AUTO;
80#ifdef __MINGW32__
81 sym_add_default(sym, "UNKNOWN");
82#else
74 sym_add_default(sym, uts.release); 83 sym_add_default(sym, uts.release);
84#endif
75} 85}
76 86
77enum symbol_type sym_get_type(struct symbol *sym) 87enum symbol_type sym_get_type(struct symbol *sym)
@@ -718,24 +728,43 @@ struct symbol *sym_find(const char *name)
718 return symbol; 728 return symbol;
719} 729}
720 730
731#if !defined HAVE_RE && !defined __MINGW32__
732#define HAVE_RE 1
733#endif
734
721struct symbol **sym_re_search(const char *pattern) 735struct symbol **sym_re_search(const char *pattern)
722{ 736{
723 struct symbol *sym, **sym_arr = NULL; 737 struct symbol *sym, **sym_arr = NULL;
724 int i, cnt, size; 738 int i, cnt, size;
739#if HAVE_RE
725 regex_t re; 740 regex_t re;
741#else
742 /* without re support use: strstr(sym->name, upper(pattern)) */
743 /* sym->name is a config, e.g. "SHELL_ASH" or "FEATURE_UTMP" */
744 char upat[256] = {0};
745 for (i = 0; i < 255 && pattern[i]; ++i)
746 upat[i] = toupper(pattern[i]);
747#endif
726 748
727 cnt = size = 0; 749 cnt = size = 0;
728 /* Skip if empty */ 750 /* Skip if empty */
729 if (strlen(pattern) == 0) 751 if (strlen(pattern) == 0)
730 return NULL; 752 return NULL;
753#if HAVE_RE
731 if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE)) 754 if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE))
732 return NULL; 755 return NULL;
756#endif
733 757
734 for_all_symbols(i, sym) { 758 for_all_symbols(i, sym) {
735 if (sym->flags & SYMBOL_CONST || !sym->name) 759 if (sym->flags & SYMBOL_CONST || !sym->name)
736 continue; 760 continue;
761#if HAVE_RE
737 if (regexec(&re, sym->name, 0, NULL, 0)) 762 if (regexec(&re, sym->name, 0, NULL, 0))
738 continue; 763 continue;
764#else
765 if (!strstr(sym->name, upat))
766 continue;
767#endif
739 if (cnt + 1 >= size) { 768 if (cnt + 1 >= size) {
740 void *tmp = sym_arr; 769 void *tmp = sym_arr;
741 size += 16; 770 size += 16;
@@ -749,7 +778,9 @@ struct symbol **sym_re_search(const char *pattern)
749 } 778 }
750 if (sym_arr) 779 if (sym_arr)
751 sym_arr[cnt] = NULL; 780 sym_arr[cnt] = NULL;
781#if HAVE_RE
752 regfree(&re); 782 regfree(&re);
783#endif
753 784
754 return sym_arr; 785 return sym_arr;
755} 786}
diff --git a/scripts/kconfig/zconf.hash.c_shipped b/scripts/kconfig/zconf.hash.c_shipped
index 29d9cf6cc..6996aba7f 100644
--- a/scripts/kconfig/zconf.hash.c_shipped
+++ b/scripts/kconfig/zconf.hash.c_shipped
@@ -161,43 +161,43 @@ kconf_id_lookup (register const char *str, register unsigned int len)
161 static struct kconf_id wordlist[] = 161 static struct kconf_id wordlist[] =
162 { 162 {
163 {-1}, {-1}, 163 {-1}, {-1},
164 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str2, T_IF, TF_COMMAND|TF_PARAM}, 164 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str2, T_IF, TF_COMMAND|TF_PARAM},
165 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str3, T_TYPE, TF_COMMAND, S_INT}, 165 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str3, T_TYPE, TF_COMMAND, S_INT},
166 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str4, T_HELP, TF_COMMAND}, 166 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str4, T_HELP, TF_COMMAND},
167 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str5, T_ENDIF, TF_COMMAND}, 167 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str5, T_ENDIF, TF_COMMAND},
168 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str6, T_SELECT, TF_COMMAND}, 168 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str6, T_SELECT, TF_COMMAND},
169 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str7, T_ENDMENU, TF_COMMAND}, 169 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str7, T_ENDMENU, TF_COMMAND},
170 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str8, T_TYPE, TF_COMMAND, S_TRISTATE}, 170 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str8, T_TYPE, TF_COMMAND, S_TRISTATE},
171 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str9, T_ENDCHOICE, TF_COMMAND}, 171 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str9, T_ENDCHOICE, TF_COMMAND},
172 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str10, T_RANGE, TF_COMMAND}, 172 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str10, T_RANGE, TF_COMMAND},
173 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str11, T_TYPE, TF_COMMAND, S_STRING}, 173 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str11, T_TYPE, TF_COMMAND, S_STRING},
174 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str12, T_DEFAULT, TF_COMMAND, S_UNKNOWN}, 174 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str12, T_DEFAULT, TF_COMMAND, S_UNKNOWN},
175 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str13, T_DEFAULT, TF_COMMAND, S_BOOLEAN}, 175 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str13, T_DEFAULT, TF_COMMAND, S_BOOLEAN},
176 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str14, T_MENU, TF_COMMAND}, 176 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str14, T_MENU, TF_COMMAND},
177 {-1}, 177 {-1},
178 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str16, T_DEFAULT, TF_COMMAND, S_BOOLEAN}, 178 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str16, T_DEFAULT, TF_COMMAND, S_BOOLEAN},
179 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str17, T_DEFAULT, TF_COMMAND, S_TRISTATE}, 179 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str17, T_DEFAULT, TF_COMMAND, S_TRISTATE},
180 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str18, T_MAINMENU, TF_COMMAND}, 180 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str18, T_MAINMENU, TF_COMMAND},
181 {-1}, 181 {-1},
182 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str20, T_MENUCONFIG, TF_COMMAND}, 182 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str20, T_MENUCONFIG, TF_COMMAND},
183 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str21, T_CONFIG, TF_COMMAND}, 183 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str21, T_CONFIG, TF_COMMAND},
184 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str22, T_ON, TF_PARAM}, 184 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str22, T_ON, TF_PARAM},
185 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str23, T_TYPE, TF_COMMAND, S_HEX}, 185 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str23, T_TYPE, TF_COMMAND, S_HEX},
186 {-1}, {-1}, 186 {-1}, {-1},
187 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str26, T_SOURCE, TF_COMMAND}, 187 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str26, T_SOURCE, TF_COMMAND},
188 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str27, T_DEPENDS, TF_COMMAND}, 188 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str27, T_DEPENDS, TF_COMMAND},
189 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str28, T_OPTIONAL, TF_COMMAND}, 189 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str28, T_OPTIONAL, TF_COMMAND},
190 {-1}, {-1}, 190 {-1}, {-1},
191 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str31, T_SELECT, TF_COMMAND}, 191 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str31, T_SELECT, TF_COMMAND},
192 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str32, T_COMMENT, TF_COMMAND}, 192 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str32, T_COMMENT, TF_COMMAND},
193 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str33, T_REQUIRES, TF_COMMAND}, 193 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str33, T_REQUIRES, TF_COMMAND},
194 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str34, T_TYPE, TF_COMMAND, S_BOOLEAN}, 194 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str34, T_TYPE, TF_COMMAND, S_BOOLEAN},
195 {-1}, {-1}, 195 {-1}, {-1},
196 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str37, T_TYPE, TF_COMMAND, S_BOOLEAN}, 196 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str37, T_TYPE, TF_COMMAND, S_BOOLEAN},
197 {-1}, {-1}, {-1}, 197 {-1}, {-1}, {-1},
198 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str41, T_CHOICE, TF_COMMAND}, 198 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str41, T_CHOICE, TF_COMMAND},
199 {-1}, {-1}, {-1}, {-1}, 199 {-1}, {-1}, {-1}, {-1},
200 {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str46, T_PROMPT, TF_COMMAND} 200 {(int)(intptr_t)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str46, T_PROMPT, TF_COMMAND}
201 }; 201 };
202 202
203 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) 203 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
diff --git a/scripts/kconfig/zconf.tab.c_shipped b/scripts/kconfig/zconf.tab.c_shipped
index a27d256d6..863f375be 100644
--- a/scripts/kconfig/zconf.tab.c_shipped
+++ b/scripts/kconfig/zconf.tab.c_shipped
@@ -143,6 +143,7 @@
143#include <stdarg.h> 143#include <stdarg.h>
144#include <stdio.h> 144#include <stdio.h>
145#include <stdlib.h> 145#include <stdlib.h>
146#include <stdint.h>
146#include <string.h> 147#include <string.h>
147#include <stdbool.h> 148#include <stdbool.h>
148 149
diff --git a/scripts/mk_mingw64u_defconfig b/scripts/mk_mingw64u_defconfig
new file mode 100755
index 000000000..5561a0900
--- /dev/null
+++ b/scripts/mk_mingw64u_defconfig
@@ -0,0 +1,39 @@
1#!/bin/sh
2
3configs=$(dirname -- "$0")/../configs
4
5# replace each FOO=bar argument with -e 's/.*FOO.*/FOO=bar/', then sed "$@"
6set_build_opts() {
7 for v; do
8 set -- "$@" -e "s/.*${v%%=*}.*/$v/"
9 shift
10 done
11 sed "$@"
12}
13
14
15# Create unicode configs/mingw64u_defconfig from configs/mingw64_defconfig
16# by flipping some build options to enable:
17# - UTF8 manifest to support unicode on win 10 (filenames, etc).
18# - UTF8 terminal input (shell prompt, read).
19# - UTF8 editing - codepoint awareness (prompt, read):
20# - Builtin libc unicode functions (mbstowcs etc - no UNICODE_USING_LOCALE).
21# - Dynamic unicode based on ANSI codepage and ENV (CHECK_UNICODE_IN_ENV).
22# - Screen-width awareness (COMBINING_WCHARS, WIDE_WCHARS)
23# - Full unicode range (U+10FFFF - LAST_SUPPORTED_WCHAR=1114111)
24
25set_build_opts \
26 CONFIG_FEATURE_UTF8_MANIFEST=y \
27 CONFIG_FEATURE_UTF8_INPUT=y \
28 CONFIG_FEATURE_UTF8_OUTPUT=y \
29 CONFIG_UNICODE_SUPPORT=y \
30 CONFIG_FEATURE_CHECK_UNICODE_IN_ENV=y \
31 CONFIG_SUBST_WCHAR=63 \
32 CONFIG_LAST_SUPPORTED_WCHAR=1114111 \
33 CONFIG_UNICODE_COMBINING_WCHARS=y \
34 CONFIG_UNICODE_WIDE_WCHARS=y \
35 CONFIG_FEATURE_USE_CNG_API=y \
36 < "$configs"/mingw64_defconfig \
37 > "$configs"/mingw64u_defconfig
38
39sed -i 's/CONFIG_FEATURE_APP_MANIFEST=y/# CONFIG_FEATURE_APP_MANIFEST is not set/' "$configs"/mingw64u_defconfig
diff --git a/scripts/mkconfigs b/scripts/mkconfigs
index 1bbf10c3a..9e4be6199 100755
--- a/scripts/mkconfigs
+++ b/scripts/mkconfigs
@@ -33,8 +33,8 @@ if test $? != 0; then
33 echo 'od tool is not installed or cannot accept "-v -b" options' 33 echo 'od tool is not installed or cannot accept "-v -b" options'
34 exit 1 34 exit 1
35fi 35fi
36bzip2 </dev/null >/dev/null 36bzip2 </dev/null >/dev/null 2>&1
37if test $? != 0; then 37if test $? = 127; then
38 echo 'bzip2 is not installed' 38 echo 'bzip2 is not installed'
39 exit 1 39 exit 1
40fi 40fi
diff --git a/scripts/mkwcwidth b/scripts/mkwcwidth
new file mode 100755
index 000000000..792045a29
--- /dev/null
+++ b/scripts/mkwcwidth
@@ -0,0 +1,169 @@
1#!/bin/sh
2#
3# Generate a C implementation of wcwidth, with latest unicode data
4# from a local clone of https://github.com/jquast/wcwidth
5#
6# The MIT License (MIT)
7#
8# Copyright (C) 2024 Avi Halachmi <avihpit at yahoo.com>
9#
10# Permission is hereby granted, free of charge, to any person obtaining a copy
11# of this software and associated documentation files (the "Software"), to deal
12# in the Software without restriction, including without limitation the rights
13# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14# copies of the Software, and to permit persons to whom the Software is
15# furnished to do so, subject to the following conditions:
16#
17# The above copyright notice and this permission notice shall be included in all
18# copies or substantial portions of the Software.
19#
20# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26# SOFTWARE.
27
28export LC_ALL=C
29self=${0##*/}
30
31# c-types (bigger types work but waste memory. uintN_t need <stdint.h>)
32u32=uint32_t # "unsigned" is also typically 32 bit
33u16=uint16_t # "unsigned short" is also typically 16 bits
34FUNC_ATTR=FAST_FUNC # delete this line if not generating a busybox function
35
36
37err() { >&2 printf %s\\n "$self: $*"; exit 1; }
38
39case ${1-} in -h | --help)
40 echo "Usage: $self [path/to/python-wcwidth] (default path is '.')"
41 echo "Prints a wcwidth C implementation, with latest Unicode data"
42 echo "imported from a local https://github.com/jquast/wcwidth repo."
43 echo "Assumptions about table_zero.py and table_wide.py at the repo:"
44 echo "- Each range is in one Unicode plane (a>>16 == b>>16) (enforced)."
45 echo "- Commit 04d6d90c (2023-10-30) or later, where table_zero.py"
46 echo " includes zero-width Cf chars (else need to add manual tests)."
47esac
48
49[ "${1-}" != -- ] || shift
50
51pwc_root=${1:-.}
52pwc_git() { git -C "$pwc_root" "$@"; }
53
54zerowidth_py=$pwc_root/wcwidth/table_zero.py
55widewidth_py=$pwc_root/wcwidth/table_wide.py
56
57[ -r "$zerowidth_py" ] && [ -r "$widewidth_py" ] \
58 || err "missing $zerowidth_py or $widewidth_py. abort."
59
60# latest unicode version from table_wide.py (e.g. from " '10.0.0': (")
61ver=$(grep "^\s*'[0-9]" < "$widewidth_py" | tail -n1 | sed "s/.*'\(.*\)'.*/\1/")
62
63# stdin -> stdout: extract the data of the last table (latest spec) from
64# wcwidth/table_{wide,zero}.py (from https://github.com/jquast/wcwidth)
65last_table() {
66 awk "/^\s*'[0-9]/ { i=0 } # new table -> reset
67 /^\s*\(0x/ { arr[++i] = \$0 } # range (first, last)
68 END { for (j=1; j <= i; ++j) print arr[j] }"
69}
70
71# stdin -> stdout, $1 is the range's (wc)width (0 or 2), e.g.
72# from: (0x0123a, 0x0123c,), # comment
73# to : R(0x00123a, 0x00123c, 2), /* comment */
74# ranges bigger than half-plane (32769+ codepoints) are split to two.
75py_data_to_c() {
76 sed -e 's/[(),]/ /g' -e 's|#\(.*\)|/*\1 */|' | while read a b c; do
77 # to support cross-plane ranges, we'd need to split them here,
78 # but unlikely required, as all planes end in non-characters.
79 [ $(($a>>16)) = $(($b>>16)) ] || err "not same plane -- $a $b"
80
81 a=$(($a)) b=$(($b)) # some shells want decimal vars in $(())
82 if [ "$((b-a))" -ge 32768 ]; then # split to 15 bit ranges
83 printf "R(0x%06x, 0x%06x, $1), %s\n" $a $((a+32767)) "$c"
84 a=$((a+32768)) c="/* (continued...) */"
85 fi
86 printf "R(0x%06x, 0x%06x, $1), %s\n" $a $b "$c"
87 done
88}
89
90data=$(last_table < "$zerowidth_py" | py_data_to_c 0 &&
91 last_table < "$widewidth_py" | py_data_to_c 2) || err abort
92data=$(printf %s\\n "$data" | sort) # lexicographic here is also numeric
93
94# sorted hex ranges and their (wc)width: R(first, last, {0|2}),[ /* ... */]
95data() { printf %s\\n "$data"; }
96
97repeat() { R=$2; while [ "$R" -gt 0 ]; do printf %s "$1"; R=$((R-1)); done; }
98
99# data -> stdout: array such that a[p], a[p+1] are [from, to) of plane p data
100mkplanes() {
101 i=0 lastp=-1
102 while read a b c; do
103 p=$((${b%?} >> 16)) # plane (last >> 16)
104 repeat "$i, " $((p-lastp))
105 i=$((i+1)) lastp=$p
106 done
107 repeat "$i, " $((17-lastp))
108}
109
110indent() { sed -e 's/^/\t\t/' -e 's/\s*$//'; } # also trim trailing spaces
111
112cat << CFUNCTION
113/* wcwidth - Unicode $ver, generated by $0.
114 * Copyright (C) 2024 Avi Halachmi <avihpit at yahoo.com>
115 * License: MIT
116 *
117 * Data imported on $(date -u -I) from https://github.com/jquast/wcwidth
118 * commit $(pwc_git describe --tags) ($(pwc_git show --no-patch --format=%ci))
119 */
120int ${FUNC_ATTR-} wcwidth($u32 ucs)
121{
122 /* sorted ranges, "first" is clipped to 16 bit, and its high bits
123 * (plane) are deduced from the "planes" array below.
124 * (imported from ${zerowidth_py##*/} and ${widewidth_py##*/})
125 */
126 static const struct range {
127 uint16_t first;
128 uint16_t iswide: 1; /* bitfield order empirically faster */
129 uint16_t difflast: 15;
130 } ranges[] = {
131 #define R(first, last, width) {first & 0xffff, width/2, last-first}
132$(data | indent)
133 #undef R
134 };
135
136 /* planes[p], planes[p+1] are [from, to) at "ranges" for plane p */
137 static const $u16 planes[/* 18 */] = {
138$(data | mkplanes | fold -s -w 60 | indent)
139 };
140
141 /******* END OF STATIC DATA *******/
142
143 $u32 p, bot, top;
144
145 /* 0:0, 1..31:-1 (C0), 32..126:1 (isprint), 127..159:-1 (DEL, C1) */
146 if (ucs < 160)
147 return ((ucs + 1) & 127) > 32 ? 1 : ucs ? -1 : 0;
148
149 /* out of range for "planes" (and non-unicode), non-characters. */
150 /* (some also test surrogate halves, but not required by POSIX) */
151 if (ucs > 0x10ffff || (ucs & 0xfffe) == 0xfffe)
152 return -1;
153
154 p = ucs >> 16;
155 ucs &= 0xffff;
156
157 for (bot = planes[p], top = planes[p+1]; bot < top; ) {
158 $u32 mid = (bot + top) / 2;
159 if (ucs < ranges[mid].first)
160 top = mid;
161 else if (ucs > ranges[mid].first + ranges[mid].difflast)
162 bot = mid + 1;
163 else
164 return 2 * ranges[mid].iswide;
165 }
166
167 return 1;
168} /* wcwidth - Unicode $ver */
169CFUNCTION
diff --git a/scripts/trylink b/scripts/trylink
index 2255deee7..2456252a3 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -93,10 +93,16 @@ if ! check_cc "-Wl,--sort-section,alignment"; then
93 SORT_SECTION="" 93 SORT_SECTION=""
94fi 94fi
95 95
96WARN_COMMON="-Wl,--warn-common"
97if ! check_cc "-Wl,--warn-common"; then
98 echo "Your linker does not support --warn-common"
99 WARN_COMMON=""
100fi
101
96START_GROUP="-Wl,--start-group" 102START_GROUP="-Wl,--start-group"
97END_GROUP="-Wl,--end-group" 103END_GROUP="-Wl,--end-group"
98INFO_OPTS() { 104INFO_OPTS() {
99 echo "-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" 105 echo "$WARN_COMMON -Wl,-Map,$EXE.map -Wl,--verbose"
100} 106}
101 107
102# gold may not support --sort-common (yet) 108# gold may not support --sort-common (yet)