Radix cross Linux Toolchains

Toolchains for all supported by Radix cross Linux devices

42 Commits   1 Branch   8 Tags
Index: .bs-svnignore
===================================================================
--- .bs-svnignore	(nonexistent)
+++ .bs-svnignore	(revision 5)
@@ -0,0 +1,16 @@
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/dialog/1.3-20210621/Makefile
===================================================================
--- 3pp/dialog/1.3-20210621/Makefile	(nonexistent)
+++ 3pp/dialog/1.3-20210621/Makefile	(revision 5)
@@ -0,0 +1,56 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_HOST)
+
+include ../../../../build-system/config.mk
+
+SOURCE_REQUIRES = build-system/3pp/sources/packages/dialog
+
+
+# ======= __END_OF_REQUIRES__ =======
+
+
+tar_gz_archive  = $(BUILDSYSTEM)/3pp/sources/packages/dialog/dialog-1.3-20210621.tgz
+src_dir         = dialog-1.3-20210621
+build_dir       = $(TARGET_BUILD_DIR)/built
+
+src_done        = $(TARGET_BUILD_DIR)/.source-done
+SRC_DIR         = $(TARGET_BUILD_DIR)/dialog-1.3-20210621
+SRC_ARCHIVE     = $(tar_gz_archive)
+
+DIALOGRC        = $(BUILDSYSTEM)/3pp/sources/packages/dialog/dialogrc
+
+PATCHES = PATCHES
+
+build_target    = $(TARGET_BUILD_DIR)/.built
+install_target  = $(TARGET_BUILD_DIR)/.installed
+
+environment     =
+extra_configure_switches  = --libdir=/usr/lib
+extra_configure_switches += --mandir=/usr/share/man
+extra_configure_switches += --without-shared
+extra_configure_switches += --with-ncursesw
+
+BUILD_TARGETS = $(install_target)
+
+include ../../../../build-system/core.mk
+
+$(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP)
+	$(UNPACK_SRC_ARCHIVE)
+	$(APPLY_PATCHES)
+	@touch $@
+
+$(build_target): $(src_done)
+	@mkdir -p $(build_dir)
+	@cd $(build_dir) && $(environment) ../$(src_dir)/configure \
+	  --prefix=/ \
+	  $(extra_configure_switches)
+	@$(environment) $(MAKE) -C $(build_dir) all
+	@touch $@
+
+$(install_target): $(build_target)
+	@echo -e "\n======= Installing DIALOG binary =======\n"
+	@mkdir -p $(BUILDSYSTEM)/{etc,sbin} && \
+	  cp -a $(DIALOGRC) $(BUILDSYSTEM)/etc && \
+	  cp -a $(build_dir)/dialog $(BUILDSYSTEM)/sbin && \
+	  echo "DIALOG := $(BUILDSYSTEM)/sbin/dialog" >> $(BUILDSYSTEM)/sbin/.config
+	@touch $@
Index: 3pp/dialog/1.3-20210621/PATCHES
===================================================================
--- 3pp/dialog/1.3-20210621/PATCHES	(nonexistent)
+++ 3pp/dialog/1.3-20210621/PATCHES	(revision 5)
@@ -0,0 +1,2 @@
+
+../../sources/packages/dialog/patches/dialog-1.3-20210621.patch -p0
Index: 3pp/dialog/1.3-20210621
===================================================================
--- 3pp/dialog/1.3-20210621	(nonexistent)
+++ 3pp/dialog/1.3-20210621	(revision 5)

Property changes on: 3pp/dialog/1.3-20210621
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/dialog
===================================================================
--- 3pp/dialog	(nonexistent)
+++ 3pp/dialog	(revision 5)

Property changes on: 3pp/dialog
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/gnattools/12.2.0/Makefile
===================================================================
--- 3pp/gnattools/12.2.0/Makefile	(nonexistent)
+++ 3pp/gnattools/12.2.0/Makefile	(revision 5)
@@ -0,0 +1,99 @@
+
+COMPONENT_TARGETS  = $(TOOLCHAIN_HOST)
+
+include ../../../../build-system/config.mk
+
+
+SOURCE_REQUIRES  = build-system/3pp/sources/GNU
+SOURCE_REQUIRES += build-system/3pp/sources/inria
+
+# ======= __END_OF_REQUIRES__ =======
+
+tar_xz_archive        = $(BUILDSYSTEM)/3pp/sources/GNU/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz
+tar_xz_archive_gmp    = $(BUILDSYSTEM)/3pp/sources/GNU/gmp/gmp-6.2.1.tar.xz
+tar_xz_archive_mpfr   = $(BUILDSYSTEM)/3pp/sources/GNU/mpfr/mpfr-4.1.0.tar.xz
+tar_gz_archive_mpc    = $(BUILDSYSTEM)/3pp/sources/GNU/mpc/mpc-1.2.1.tar.gz
+tar_xz_archive_isl    = $(BUILDSYSTEM)/3pp/sources/inria/isl/isl-0.25.tar.xz
+SRC_ARCHIVE           = $(tar_xz_archive)
+SRC_DIR               = $(TARGET_BUILD_DIR)/gcc-12.2.0
+src_dir_name          = gcc-12.2.0
+src_done              = $(TARGET_BUILD_DIR)/.source-done
+gmp_src_done          = $(TARGET_BUILD_DIR)/.gmp-source-done
+mpfr_src_done         = $(TARGET_BUILD_DIR)/.mpfr-source-done
+mpc_src_done          = $(TARGET_BUILD_DIR)/.mpc-source-done
+isl_src_done          = $(TARGET_BUILD_DIR)/.isl-source-done
+
+PATCHES        = PATCHES
+
+build_dir             = $(TARGET_BUILD_DIR)/build
+
+
+build_target   = $(TARGET_BUILD_DIR)/.built
+install_target = $(TARGET_BUILD_DIR)/.installed
+
+
+BUILD_TARGETS  = $(build_target)
+BUILD_TARGETS += $(install_target)
+
+
+include ../../../../build-system/core.mk
+
+
+JOBS = -j$(NUMPROCS)
+
+environment  = CC="$(CCACHE)/usr/bin/gcc"
+environment += CC_FOR_BUILD="$(CCACHE)/usr/bin/gcc"
+environment += CXX_FOR_BUILD="$(CCACHE)/usr/bin/g++"
+
+
+GNATTOOLS_DEST_DIR = $(BUILDSYSTEM)/gnattools/12.2.0/usr
+
+extra_configure_switches  = --disable-bootstrap
+extra_configure_switches += --enable-languages=c,c++,ada
+
+
+$(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP)
+	$(UNPACK_SRC_ARCHIVE)
+	$(APPLY_PATCHES)
+	@touch $@
+
+$(gmp_src_done): $(src_done)
+	@echo "Expanding $(tar_xz_archive_gmp)"
+	@tar xJf $(tar_xz_archive_gmp) -C $(TARGET_BUILD_DIR)
+	@cd $(SRC_DIR); ln -sf ../gmp-6.2.1 gmp
+	@touch $@
+
+$(mpfr_src_done): $(src_done)
+	@echo "Expanding $(tar_xz_archive_mpfr)"
+	@tar xJf $(tar_xz_archive_mpfr) -C $(TARGET_BUILD_DIR)
+	@cd $(SRC_DIR); ln -sf ../mpfr-4.1.0 mpfr
+	@touch $@
+
+$(mpc_src_done): $(src_done)
+	@echo "Expanding $(tar_gz_archive_mpc)"
+	@tar xzf $(tar_gz_archive_mpc) -C $(TARGET_BUILD_DIR)
+	@cd $(SRC_DIR); ln -sf ../mpc-1.2.1 mpc
+	@touch $@
+
+$(isl_src_done): $(src_done)
+	@echo "Expanding $(tar_xz_archive_isl)"
+	@tar xJf $(tar_xz_archive_isl) -C $(TARGET_BUILD_DIR)
+	@cd $(SRC_DIR); ln -sf ../isl-0.25 isl
+	@touch $@
+
+$(build_target): $(src_done) $(gmp_src_done) $(mpfr_src_done) $(mpc_src_done) $(isl_src_done)
+	@mkdir -p $(build_dir)
+	@cd $(build_dir) && $(environment) ../$(src_dir_name)/configure \
+	  --prefix=$(GNATTOOLS_DEST_DIR)                  \
+	  --build=$(shell $(BUILDSYSTEM)/canonical-build) \
+	  --datadir=$(GNATTOOLS_DEST_DIR)/share           \
+	  --infodir=$(GNATTOOLS_DEST_DIR)/share/info      \
+	  --mandir=$(GNATTOOLS_DEST_DIR)/share/man        \
+	  $(extra_configure_switches)
+	@cd $(build_dir) && make $(JOBS)
+	@touch $@
+
+$(install_target): $(build_target)
+	@cd $(build_dir) && make install
+	@rm -f $(GNATTOOLS_DEST_DIR)/share/info/dir
+	@touch $@
Index: 3pp/gnattools/12.2.0/PATCHES
===================================================================
Index: 3pp/gnattools/12.2.0
===================================================================
--- 3pp/gnattools/12.2.0	(nonexistent)
+++ 3pp/gnattools/12.2.0	(revision 5)

Property changes on: 3pp/gnattools/12.2.0
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/gnattools
===================================================================
--- 3pp/gnattools	(nonexistent)
+++ 3pp/gnattools	(revision 5)

Property changes on: 3pp/gnattools
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/GNU/Makefile
===================================================================
--- 3pp/sources/GNU/Makefile	(nonexistent)
+++ 3pp/sources/GNU/Makefile	(revision 5)
@@ -0,0 +1,14 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+SOURCE_REQUIRES += ALL_DIRS
+
+# ======= __END_OF_REQUIRES__ =======
+
+include ../../../../build-system/core.mk
+
+
+download_clean:
+	@true
+
+.PHONY: download_clean
Index: 3pp/sources/GNU/gcc/Makefile
===================================================================
--- 3pp/sources/GNU/gcc/Makefile	(nonexistent)
+++ 3pp/sources/GNU/gcc/Makefile	(revision 5)
@@ -0,0 +1,14 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+SOURCE_REQUIRES += ALL_DIRS
+
+# ======= __END_OF_REQUIRES__ =======
+
+include ../../../../../build-system/core.mk
+
+
+download_clean:
+	@true
+
+.PHONY: download_clean
Index: 3pp/sources/GNU/gcc/gcc-12.2.0/Makefile
===================================================================
--- 3pp/sources/GNU/gcc/gcc-12.2.0/Makefile	(nonexistent)
+++ 3pp/sources/GNU/gcc/gcc-12.2.0/Makefile	(revision 5)
@@ -0,0 +1,39 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+include ../../../../../../build-system/config.mk
+
+url         = $(DOWNLOAD_SERVER)/sources/GNU/gcc/gcc-$(version)
+
+version     = 12.2.0
+
+tarballs    = $(addsuffix .tar.xz, $(addprefix gcc-, $(version)))
+sha1s       = $(addsuffix .sha1sum, $(tarballs))
+
+BUILD_TARGETS = $(tarballs) $(sha1s)
+
+include ../../../../../../build-system/core.mk
+
+.PHONY: download_clean
+
+$(tarballs):
+	@echo -e "\n======= Downloading source tarballs =======" ; \
+	 for tarball in $(tarballs) ; do \
+	   echo "$(url)/$$tarball" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & \
+	 done ; wait
+
+$(sha1s): $(tarballs)
+	@for sha in $@ ; do \
+	   echo -e "\n======= Downloading '$$sha' signature =======\n" ; \
+	   echo "$(url)/$$sha" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & wait %1 ; \
+	   touch $$sha ; \
+	   echo -e "\n======= Check the '$$sha' sha1sum =======\n" ; \
+	   sha1sum --check $$sha ; ret="$$?" ; \
+	   if [ "$$ret" == "1" ]; then \
+	     echo -e "\n======= ERROR: Bad '$$sha' sha1sum =======\n" ; \
+	     exit 1 ; \
+	   fi ; \
+	 done
+
+download_clean:
+	@rm -f $(tarballs) $(sha1s)
Index: 3pp/sources/GNU/gcc/gcc-12.2.0
===================================================================
--- 3pp/sources/GNU/gcc/gcc-12.2.0	(nonexistent)
+++ 3pp/sources/GNU/gcc/gcc-12.2.0	(revision 5)

Property changes on: 3pp/sources/GNU/gcc/gcc-12.2.0
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/GNU/gcc
===================================================================
--- 3pp/sources/GNU/gcc	(nonexistent)
+++ 3pp/sources/GNU/gcc	(revision 5)

Property changes on: 3pp/sources/GNU/gcc
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/GNU/gmp/Makefile
===================================================================
--- 3pp/sources/GNU/gmp/Makefile	(nonexistent)
+++ 3pp/sources/GNU/gmp/Makefile	(revision 5)
@@ -0,0 +1,39 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+include ../../../../../build-system/config.mk
+
+url         = $(DOWNLOAD_SERVER)/sources/GNU/gmp
+
+versions    = 6.2.1
+
+tarballs    = $(addsuffix .tar.xz, $(addprefix gmp-, $(versions)))
+sha1s       = $(addsuffix .sha1sum, $(tarballs))
+
+BUILD_TARGETS = $(tarballs) $(sha1s)
+
+include ../../../../../build-system/core.mk
+
+.PHONY: download_clean
+
+$(tarballs):
+	@echo -e "\n======= Downloading source tarballs =======" ; \
+	 for tarball in $(tarballs) ; do \
+	   echo "$(url)/$$tarball" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & \
+	 done ; wait
+
+$(sha1s): $(tarballs)
+	@for sha in $@ ; do \
+	   echo -e "\n======= Downloading '$$sha' signature =======\n" ; \
+	   echo "$(url)/$$sha" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & wait %1 ; \
+	   touch $$sha ; \
+	   echo -e "\n======= Check the '$$sha' sha1sum =======\n" ; \
+	   sha1sum --check $$sha ; ret="$$?" ; \
+	   if [ "$$ret" == "1" ]; then \
+	     echo -e "\n======= ERROR: Bad '$$sha' sha1sum =======\n" ; \
+	     exit 1 ; \
+	   fi ; \
+	 done
+
+download_clean:
+	@rm -f $(tarballs) $(sha1s)
Index: 3pp/sources/GNU/gmp
===================================================================
--- 3pp/sources/GNU/gmp	(nonexistent)
+++ 3pp/sources/GNU/gmp	(revision 5)

Property changes on: 3pp/sources/GNU/gmp
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/GNU/mpc/Makefile
===================================================================
--- 3pp/sources/GNU/mpc/Makefile	(nonexistent)
+++ 3pp/sources/GNU/mpc/Makefile	(revision 5)
@@ -0,0 +1,39 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+include ../../../../../build-system/config.mk
+
+url         = $(DOWNLOAD_SERVER)/sources/GNU/mpc
+
+versions    = 1.2.1
+
+tarballs    = $(addsuffix .tar.gz, $(addprefix mpc-, $(versions)))
+sha1s       = $(addsuffix .sha1sum, $(tarballs))
+
+BUILD_TARGETS = $(tarballs) $(sha1s)
+
+include ../../../../../build-system/core.mk
+
+.PHONY: download_clean
+
+$(tarballs):
+	@echo -e "\n======= Downloading source tarballs =======" ; \
+	 for tarball in $(tarballs) ; do \
+	   echo "$(url)/$$tarball" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & \
+	 done ; wait
+
+$(sha1s): $(tarballs)
+	@for sha in $@ ; do \
+	   echo -e "\n======= Downloading '$$sha' signature =======\n" ; \
+	   echo "$(url)/$$sha" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & wait %1 ; \
+	   touch $$sha ; \
+	   echo -e "\n======= Check the '$$sha' sha1sum =======\n" ; \
+	   sha1sum --check $$sha ; ret="$$?" ; \
+	   if [ "$$ret" == "1" ]; then \
+	     echo -e "\n======= ERROR: Bad '$$sha' sha1sum =======\n" ; \
+	     exit 1 ; \
+	   fi ; \
+	 done
+
+download_clean:
+	@rm -f $(tarballs) $(sha1s)
Index: 3pp/sources/GNU/mpc
===================================================================
--- 3pp/sources/GNU/mpc	(nonexistent)
+++ 3pp/sources/GNU/mpc	(revision 5)

Property changes on: 3pp/sources/GNU/mpc
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/GNU/mpfr/Makefile
===================================================================
--- 3pp/sources/GNU/mpfr/Makefile	(nonexistent)
+++ 3pp/sources/GNU/mpfr/Makefile	(revision 5)
@@ -0,0 +1,39 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+include ../../../../../build-system/config.mk
+
+url         = $(DOWNLOAD_SERVER)/sources/GNU/mpfr
+
+versions    = 4.1.0
+
+tarballs    = $(addsuffix .tar.xz, $(addprefix mpfr-, $(versions)))
+sha1s       = $(addsuffix .sha1sum, $(tarballs))
+
+BUILD_TARGETS = $(tarballs) $(sha1s)
+
+include ../../../../../build-system/core.mk
+
+.PHONY: download_clean
+
+$(tarballs):
+	@echo -e "\n======= Downloading source tarballs =======" ; \
+	 for tarball in $(tarballs) ; do \
+	   echo "$(url)/$$tarball" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & \
+	 done ; wait
+
+$(sha1s): $(tarballs)
+	@for sha in $@ ; do \
+	   echo -e "\n======= Downloading '$$sha' signature =======\n" ; \
+	   echo "$(url)/$$sha" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & wait %1 ; \
+	   touch $$sha ; \
+	   echo -e "\n======= Check the '$$sha' sha1sum =======\n" ; \
+	   sha1sum --check $$sha ; ret="$$?" ; \
+	   if [ "$$ret" == "1" ]; then \
+	     echo -e "\n======= ERROR: Bad '$$sha' sha1sum =======\n" ; \
+	     exit 1 ; \
+	   fi ; \
+	 done
+
+download_clean:
+	@rm -f $(tarballs) $(sha1s)
Index: 3pp/sources/GNU/mpfr
===================================================================
--- 3pp/sources/GNU/mpfr	(nonexistent)
+++ 3pp/sources/GNU/mpfr	(revision 5)

Property changes on: 3pp/sources/GNU/mpfr
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/GNU
===================================================================
--- 3pp/sources/GNU	(nonexistent)
+++ 3pp/sources/GNU	(revision 5)

Property changes on: 3pp/sources/GNU
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/Makefile
===================================================================
--- 3pp/sources/Makefile	(nonexistent)
+++ 3pp/sources/Makefile	(revision 5)
@@ -0,0 +1,14 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+SOURCE_REQUIRES += ALL_DIRS
+
+# ======= __END_OF_REQUIRES__ =======
+
+include ../../../build-system/core.mk
+
+
+download_clean:
+	@true
+
+.PHONY: download_clean
Index: 3pp/sources/inria/Makefile
===================================================================
--- 3pp/sources/inria/Makefile	(nonexistent)
+++ 3pp/sources/inria/Makefile	(revision 5)
@@ -0,0 +1,14 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+SOURCE_REQUIRES += ALL_DIRS
+
+# ======= __END_OF_REQUIRES__ =======
+
+include ../../../../build-system/core.mk
+
+
+download_clean:
+	@true
+
+.PHONY: download_clean
Index: 3pp/sources/inria/isl/Makefile
===================================================================
--- 3pp/sources/inria/isl/Makefile	(nonexistent)
+++ 3pp/sources/inria/isl/Makefile	(revision 5)
@@ -0,0 +1,47 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+
+include ../../../../../build-system/config.mk
+
+
+url         = $(DOWNLOAD_SERVER)/sources/packages/l/isl
+
+versions    = 0.25
+pkg_name    = isl
+suffix      = tar.xz
+
+tarballs    = $(addsuffix .$(suffix), $(addprefix $(pkg_name)-, $(versions)))
+sha1s       = $(addsuffix .sha1sum, $(tarballs))
+
+
+BUILD_TARGETS = $(tarballs) $(sha1s)
+
+
+include ../../../../../build-system/core.mk
+
+
+.PHONY: download_clean
+
+
+$(tarballs):
+	@echo -e "\n======= Downloading source tarballs =======" ; \
+	 for tarball in $(tarballs) ; do \
+	   echo "$(url)/$$tarball" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & \
+	 done ; wait
+
+$(sha1s): $(tarballs)
+	@for sha in $@ ; do \
+	   echo -e "\n======= Downloading '$$sha' signature =======\n" ; \
+	   echo "$(url)/$$sha" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & wait %1 ; \
+	   touch $$sha ; \
+	   echo -e "\n======= Check the '$$sha' sha1sum =======\n" ; \
+	   sha1sum --check $$sha ; ret="$$?" ; \
+	   if [ "$$ret" == "1" ]; then \
+	     echo -e "\n======= ERROR: Bad '$$sha' sha1sum =======\n" ; \
+	     exit 1 ; \
+	   fi ; \
+	 done
+
+download_clean:
+	@rm -f $(tarballs) $(sha1s)
Index: 3pp/sources/inria/isl
===================================================================
--- 3pp/sources/inria/isl	(nonexistent)
+++ 3pp/sources/inria/isl	(revision 5)

Property changes on: 3pp/sources/inria/isl
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/inria
===================================================================
--- 3pp/sources/inria	(nonexistent)
+++ 3pp/sources/inria	(revision 5)

Property changes on: 3pp/sources/inria
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/packages/Makefile
===================================================================
--- 3pp/sources/packages/Makefile	(nonexistent)
+++ 3pp/sources/packages/Makefile	(revision 5)
@@ -0,0 +1,14 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+SOURCE_REQUIRES += ALL_DIRS
+
+# ======= __END_OF_REQUIRES__ =======
+
+include ../../../../build-system/core.mk
+
+
+download_clean:
+	@true
+
+.PHONY: download_clean
Index: 3pp/sources/packages/dialog/Makefile
===================================================================
--- 3pp/sources/packages/dialog/Makefile	(nonexistent)
+++ 3pp/sources/packages/dialog/Makefile	(revision 5)
@@ -0,0 +1,56 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_NOARCH)
+
+
+include ../../../../../build-system/config.mk
+
+
+url         = $(DOWNLOAD_SERVER)/sources/packages/a/dialog
+
+versions    = 1.3-20210621
+pkgname     = dialog
+suffix      = tgz
+
+tarballs    = $(addsuffix .$(suffix), $(addprefix $(pkgname)-, $(versions)))
+sha1s       = $(addsuffix .sha1sum, $(tarballs))
+
+patches     = $(CURDIR)/patches/dialog-1.3-20210621.patch
+
+.NOTPARALLEL: $(patches)
+
+
+BUILD_TARGETS = $(tarballs) $(sha1s) $(patches)
+
+
+include ../../../../../build-system/core.mk
+
+
+.PHONY: download_clean
+
+
+$(tarballs):
+	@echo -e "\n======= Downloading source tarballs =======" ; \
+	 for tarball in $(tarballs) ; do \
+	   echo "$(url)/$$tarball" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & \
+	 done ; wait
+
+$(sha1s): $(tarballs)
+	@for sha in $@ ; do \
+	   echo -e "\n======= Downloading '$$sha' signature =======\n" ; \
+	   echo "$(url)/$$sha" | xargs -n 1 -P 100 wget $(WGET_OPTIONS) - & wait %1 ; \
+	   touch $$sha ; \
+	   echo -e "\n======= Check the '$$sha' sha1sum =======\n" ; \
+	   sha1sum --check $$sha ; ret="$$?" ; \
+	   if [ "$$ret" == "1" ]; then \
+	     echo -e "\n======= ERROR: Bad '$$sha' sha1sum =======\n" ; \
+	     exit 1 ; \
+	   fi ; \
+	 done
+
+$(patches): $(sha1s)
+	@echo -e "\n======= Create Patches =======\n" ; \
+	 ( cd create-1.3-20210621-patch ; ./create.patch.sh ) ; \
+	 echo -e "\n"
+
+download_clean:
+	@rm -f $(tarballs) $(sha1s) $(patches)
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/create.patch.sh
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/create.patch.sh	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/create.patch.sh	(revision 5)
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+VERSION=1.3-20210621
+
+tar --files-from=file.list -xzvf ../dialog-$VERSION.tgz
+mv dialog-$VERSION dialog-$VERSION-orig
+
+cp -rf ./dialog-$VERSION-new ./dialog-$VERSION
+
+diff --unified -Nr  dialog-$VERSION-orig  dialog-$VERSION > dialog-$VERSION.patch
+
+mv dialog-$VERSION.patch ../patches
+
+rm -rf ./dialog-$VERSION
+rm -rf ./dialog-$VERSION-orig

Property changes on: 3pp/sources/packages/dialog/create-1.3-20210621-patch/create.patch.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/buildlist.c
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/buildlist.c	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/buildlist.c	(revision 5)
@@ -0,0 +1,1267 @@
+/*
+ *  $Id: buildlist.c,v 1.95 2021/03/05 00:51:16 tom Exp $
+ *
+ *  buildlist.c -- implements the buildlist dialog
+ *
+ *  Copyright 2012-2020,2021	Thomas E. Dickey
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License, version 2.1
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to
+ *	Free Software Foundation, Inc.
+ *	51 Franklin St., Fifth Floor
+ *	Boston, MA 02110, USA.
+ */
+
+#include <dlg_internals.h>
+#include <dlg_keys.h>
+
+/*
+ * Visually like menubox, but two columns.
+ */
+
+#define sLEFT         (-2)
+#define sRIGHT        (-1)
+
+#define KEY_LEFTCOL   '^'
+#define KEY_RIGHTCOL  '$'
+
+#define MIN_HIGH  (1 + (5 * MARGIN))
+
+typedef struct {
+    WINDOW *win;
+    int box_y;
+    int box_x;
+    int top_index;
+    int cur_index;
+    DIALOG_LISTITEM **ip;	/* pointers to items in this list */
+} MY_DATA;
+
+#if 0
+#define TRACE(p)    dlg_trace_msg p
+#else
+#define TRACE(p)		/* nothing */
+#endif
+
+#define okIndex(all,index) ((index) >= 0 && (index) < (all)->item_no)
+
+#define myItem(p,n) ((p)->ip)[n]
+#define mySide(n)   ((n)?"right":"left")
+
+typedef struct {
+    DIALOG_LISTITEM *items;	/* all items in the widget */
+    int base_y;			/* base for mouse coordinates */
+    int base_x;
+    int use_height;		/* actual size of column box */
+    int use_width;
+    int item_no;
+    int check_x;
+    int item_x;
+    MY_DATA list[2];
+} ALL_DATA;
+
+/*
+ * Translate a choice from items[] to a row-number in an unbounded column,
+ * starting at zero.
+ */
+static int
+index2row(ALL_DATA * all, int choice, int selected)
+{
+    MY_DATA *data = all->list + selected;
+    int result = -1;
+
+    if (okIndex(all, choice)) {
+	int row;
+
+	for (row = 0; row < all->item_no; ++row) {
+	    TRACE(("!... choice %d: %p vs row %d: %p\n",
+		   choice, all->items + choice,
+		   row, myItem(data, row)));
+	    if (myItem(data, row) == all->items + choice) {
+		result = row;
+		break;
+	    }
+	}
+    }
+    TRACE(("! index2row(choice %d, %s) = %d\n", choice, mySide(selected), result));
+    return result;
+}
+
+/*
+ * Convert a row-number back to an item number, i.e., index into items[].
+ */
+static int
+row2index(ALL_DATA * all, int row, int selected)
+{
+    MY_DATA *data = all->list + selected;
+    int result = -1;
+    int n;
+    for (n = 0; n < all->item_no; ++n) {
+	TRACE(("!... row %d: %p vs choice %d: %p\n",
+	       row, myItem(data, row),
+	       n, all->items + n));
+	if (myItem(data, row) == all->items + n) {
+	    result = n;
+	    break;
+	}
+    }
+    TRACE(("! row2index(row %d, %s) = %d\n", row, mySide(selected), result));
+    return result;
+}
+
+/*
+ * Print list item.  The 'selected' parameter is true if 'choice' is the
+ * current item.  That one is colored differently from the other items.
+ */
+static void
+print_item(ALL_DATA * all,
+	   WINDOW *win,
+	   DIALOG_LISTITEM * item,
+	   int row,
+	   int selected)
+{
+    chtype save = dlg_get_attrs(win);
+    int i;
+    bool both = (!dialog_vars.no_tags && !dialog_vars.no_items);
+    bool first = TRUE;
+    int climit = (all->item_x - all->check_x - 1);
+    const char *show = (dialog_vars.no_items
+			? item->name
+			: item->text);
+
+    /* Clear 'residue' of last item */
+    dlg_attrset(win, menubox_attr);
+    (void) wmove(win, row, 0);
+    for (i = 0; i < getmaxx(win); i++)
+	(void) waddch(win, ' ');
+
+    (void) wmove(win, row, all->check_x);
+    dlg_attrset(win, menubox_attr);
+
+    if (both) {
+	dlg_print_listitem(win, item->name, climit, first, selected);
+	(void) waddch(win, ' ');
+	first = FALSE;
+    }
+
+    (void) wmove(win, row, all->item_x);
+    climit = (getmaxx(win) - all->item_x + 1);
+    dlg_print_listitem(win, show, climit, first, selected);
+
+    if (selected) {
+	dlg_item_help(item->help);
+    }
+    dlg_attrset(win, save);
+}
+
+/*
+ * Prints either the left (unselected) or right (selected) list.
+ */
+static void
+print_1_list(ALL_DATA * all,
+	     int choice,
+	     int selected)
+{
+    MY_DATA *data = all->list + selected;
+    DIALOG_LISTITEM *target = (okIndex(all, choice)
+			       ? all->items + choice
+			       : 0);
+    WINDOW *win = data->win;
+    int i, j;
+    int last = 0;
+    int top_row = index2row(all, data->top_index, selected);
+    int max_rows = getmaxy(win);
+
+    TRACE(("! print_1_list %d %s, top %d\n", choice, mySide(selected), top_row));
+    for (i = j = 0; j < max_rows; i++) {
+	int ii = i + top_row;
+	if (ii < 0) {
+	    continue;
+	} else if (myItem(data, ii)) {
+	    print_item(all,
+		       win,
+		       myItem(data, ii),
+		       j, myItem(data, ii) == target);
+	    last = ++j;
+	} else {
+	    break;
+	}
+    }
+    if (wmove(win, last, 0) != ERR) {
+	while (waddch(win, ' ') != ERR) {
+	    ;
+	}
+    }
+    (void) wnoutrefresh(win);
+}
+
+/*
+ * Return the previous item from the list, staying in the same column.  If no
+ * further movement is possible, return the same choice as given.
+ */
+static int
+prev_item(ALL_DATA * all, int choice, int selected)
+{
+    int result = choice;
+    int row = index2row(all, choice, selected);
+    if (row > 0) {
+	row--;
+	result = row2index(all, row, selected);
+    }
+    TRACE(("! prev_item choice %d, %s = %d\n", choice, mySide(selected), result));
+    return result;
+}
+
+/*
+ * Return true if the given choice is on the first page in the current column.
+ */
+static bool
+stop_prev(ALL_DATA * all, int choice, int selected)
+{
+    return (prev_item(all, choice, selected) == choice);
+}
+
+static bool
+check_hotkey(DIALOG_LISTITEM * items, int choice, int selected)
+{
+    bool result = FALSE;
+
+    if ((items[choice].state != 0) == selected) {
+	if (dlg_match_char(dlg_last_getc(),
+			   (dialog_vars.no_tags
+			    ? items[choice].text
+			    : items[choice].name))) {
+	    result = TRUE;
+	}
+    }
+    return result;
+}
+
+/*
+ * Return the next item from the list, staying in the same column.  If no
+ * further movement is possible, return the same choice as given.
+ */
+static int
+next_item(ALL_DATA * all, int choice, int selected)
+{
+    MY_DATA *data = all->list + selected;
+    int result = choice;
+    int row = index2row(all, choice, selected);
+    TRACE(("! given item %d, testing next-item on row %d\n", choice, row + 1));
+    if (myItem(data, row + 1)) {
+	result = row2index(all, row + 1, selected);
+    }
+    TRACE(("! next_item(%d, %s) ->%d\n", choice, mySide(selected), result));
+    return result;
+}
+
+/*
+ * Return the first choice from items[] for the given column.
+ */
+static int
+first_item(ALL_DATA * all, int selected)
+{
+    MY_DATA *data = all->list + selected;
+    int result = -1;
+
+    if (myItem(data, 0) != 0) {
+	int n;
+
+	for (n = 0; n < all->item_no; ++n) {
+	    if (myItem(data, 0) == &all->items[n]) {
+		result = n;
+		break;
+	    }
+	}
+    }
+    TRACE(("! first_item %s = %d\n", mySide(selected), result));
+    return result;
+}
+
+/*
+ * Return the last choice from items[] for the given column.
+ */
+static int
+last_item(ALL_DATA * all, int selected)
+{
+    MY_DATA *data = all->list + selected;
+    int result = -1;
+    int n;
+
+    for (n = 0; myItem(data, n) != 0; ++n) {
+	result = n;
+    }
+    if (result >= 0) {
+	result = row2index(all, result, selected);
+    }
+    TRACE(("! last_item %s = %d\n", mySide(selected), result));
+    return result;
+}
+
+static int
+skip_rows(ALL_DATA * all, int row, int skip, int selected)
+{
+    MY_DATA *data = all->list + selected;
+    int result = row;
+
+    if (skip > 0) {
+	int n;
+
+	for (n = row + 1; (n < all->item_no) && (n <= row + skip); ++n) {
+	    if (myItem(data, n) == 0)
+		break;
+	    result = n;
+	}
+    } else if (skip < 0) {
+	result -= skip;
+	if (result < 0)
+	    result = 0;
+    }
+    TRACE(("! skip_rows row %d, skip %d, %s = %d\n",
+	   row, skip, mySide(selected), result));
+    return result;
+}
+
+/*
+ * Find the closest item in the given column starting with the given choice.
+ */
+static int
+closest_item(ALL_DATA * all, int choice, int selected)
+{
+    int prev = choice;
+    int next = choice;
+    int result = choice;
+    int n;
+
+    for (n = choice; n >= 0; --n) {
+	if ((all->items[n].state != 0) == selected) {
+	    prev = n;
+	    break;
+	}
+    }
+    for (n = choice; n < all->item_no; ++n) {
+	if ((all->items[n].state != 0) == selected) {
+	    next = n;
+	    break;
+	}
+    }
+    if (prev != choice) {
+	result = prev;
+	if (next != choice) {
+	    if ((choice - prev) > (next - choice)) {
+		result = next;
+	    }
+	}
+    } else if (next != choice) {
+	result = next;
+    }
+    TRACE(("! XXX closest item choice %d, %s = %d\n",
+	   choice, mySide(selected), result));
+    return result;
+}
+
+static void
+print_both(ALL_DATA * all,
+	   int choice)
+{
+    int selected;
+    int cur_y, cur_x;
+    WINDOW *dialog = wgetparent(all->list[0].win);
+
+    TRACE(("! print_both %d\n", choice));
+    getyx(dialog, cur_y, cur_x);
+    for (selected = 0; selected < 2; ++selected) {
+	MY_DATA *data = all->list + selected;
+	WINDOW *win = data->win;
+	int thumb_top = index2row(all, data->top_index, selected);
+	int thumb_max = index2row(all, -1, selected);
+	int thumb_end = thumb_top + getmaxy(win);
+
+	print_1_list(all, choice, selected);
+
+	dlg_mouse_setcode(selected * KEY_MAX);
+	dlg_draw_scrollbar(dialog,
+			   (long) (data->top_index),
+			   (long) (thumb_top),
+			   (long) MIN(thumb_end, thumb_max),
+			   (long) thumb_max,
+			   data->box_x + all->check_x,
+			   data->box_x + getmaxx(win),
+			   data->box_y,
+			   data->box_y + getmaxy(win) + 1,
+			   menubox_border2_attr,
+			   menubox_border_attr);
+    }
+    (void) wmove(dialog, cur_y, cur_x);
+    dlg_mouse_setcode(0);
+}
+
+static void
+set_top_item(ALL_DATA * all, int choice, int selected)
+{
+    if (choice != all->list[selected].top_index) {
+	DLG_TRACE(("# set top of %s column to %d\n",
+		   mySide(selected),
+		   choice));
+	all->list[selected].top_index = choice;
+    }
+}
+
+/*
+ * Adjust the top-index as needed to ensure that it and the given item are
+ * visible.
+ */
+static void
+fix_top_item(ALL_DATA * all, int cur_item, int selected)
+{
+    int top_item = all->list[selected].top_index;
+    int cur_row = index2row(all, cur_item, selected);
+    int top_row = index2row(all, top_item, selected);
+
+    if (cur_row < top_row) {
+	top_item = cur_item;
+    } else if ((cur_row - top_row) >= all->use_height) {
+	top_item = row2index(all, cur_row + 1 - all->use_height, selected);
+    }
+    if (cur_row < all->use_height) {
+	top_item = row2index(all, 0, selected);
+    }
+    DLG_TRACE(("# fix_top_item(cur_item %d, %s) ->top_item %d\n",
+	       cur_item, mySide(selected), top_item));
+    set_top_item(all, top_item, selected);
+}
+
+static void
+append_right_side(ALL_DATA * all, int choice)
+{
+    MY_DATA *data = &all->list[1];
+    int j;
+    for (j = 0; j < all->item_no; ++j) {
+	if (myItem(data, j) == 0) {
+	    myItem(data, j) = &all->items[choice];
+	    break;
+	}
+    }
+}
+
+static void
+amend_right_side(ALL_DATA * all, int choice)
+{
+    MY_DATA *data = &all->list[1];
+    int j, k;
+    for (j = 0; j < all->item_no; ++j) {
+	if (myItem(data, j) == &all->items[choice]) {
+	    for (k = j; k < all->item_no; ++k) {
+		if ((myItem(data, k) = myItem(data, k + 1)) == 0)
+		    break;
+	    }
+	    break;
+	}
+    }
+}
+
+static void
+fill_one_side(ALL_DATA * all, int selected)
+{
+    int i, j;
+    MY_DATA *data = all->list + selected;
+
+    for (i = j = 0; j < all->item_no; ++j) {
+	myItem(data, i) = 0;
+	if ((all->items[j].state != 0) == selected) {
+	    myItem(data, i) = all->items + j;
+	    TRACE(("! %s item[%d] %p = all[%d] %p\n",
+		   mySide(selected),
+		   i, myItem(data, i),
+		   j, all->items + j));
+	    ++i;
+	}
+    }
+    myItem(data, i) = 0;
+}
+
+static void
+fill_both_sides(ALL_DATA * all)
+{
+    int k;
+
+    for (k = 0; k < 2; ++k) {
+	fill_one_side(all, k);
+    }
+}
+
+/*
+ * This is an alternate interface to 'buildlist' which allows the application
+ * to read the list item states back directly without putting them in the
+ * output buffer.
+ */
+int
+dlg_buildlist(const char *title,
+	      const char *cprompt,
+	      int height,
+	      int width,
+	      int list_height,
+	      int item_no,
+	      DIALOG_LISTITEM * items,
+	      const char *states,
+	      int order_mode,
+	      int *current_item)
+{
+#define THIS_FUNC "dlg_buildlist"
+    /* *INDENT-OFF* */
+    static DLG_KEYS_BINDING binding[] = {
+	HELPKEY_BINDINGS,
+	ENTERKEY_BINDINGS,
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
+	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
+	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
+	DLG_KEYS_DATA( DLGK_ITEM_FIRST, KEY_HOME ),
+	DLG_KEYS_DATA( DLGK_ITEM_LAST,	KEY_END ),
+	DLG_KEYS_DATA( DLGK_ITEM_LAST,	KEY_LL ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	'+' ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	KEY_DOWN ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,  CHR_NEXT ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,	'-' ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,	KEY_UP ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,  CHR_PREVIOUS ),
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	KEY_NPAGE ),
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	DLGK_MOUSE(KEY_NPAGE) ),
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	DLGK_MOUSE(KEY_NPAGE+KEY_MAX) ),
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,	KEY_PPAGE ),
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,	DLGK_MOUSE(KEY_PPAGE) ),
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,	DLGK_MOUSE(KEY_PPAGE+KEY_MAX) ),
+	DLG_KEYS_DATA( DLGK_GRID_LEFT,	KEY_LEFTCOL ),
+	DLG_KEYS_DATA( DLGK_GRID_RIGHT,	KEY_RIGHTCOL ),
+	TOGGLEKEY_BINDINGS,
+	END_KEYS_BINDING
+    };
+    /* *INDENT-ON* */
+
+#ifdef KEY_RESIZE
+    int old_height = height;
+    int old_width = width;
+#endif
+    ALL_DATA all;
+    MY_DATA *data = all.list;
+    int i, j, k, key2, found, x, y, cur_x, cur_y;
+    int key, fkey;
+    bool save_visit = dialog_state.visit_items;
+    int button;
+    int cur_item;
+    int name_width, text_width, full_width, list_width;
+    int result = DLG_EXIT_UNKNOWN;
+    int num_states;
+    bool first = TRUE;
+    WINDOW *dialog;
+    char *prompt;
+    const char **buttons = dlg_ok_labels();
+    const char *widget_name = "buildlist";
+
+    dialog_state.plain_buttons = TRUE;
+
+    /*
+     * Unlike other uses of --visit-items, we have two windows to visit.
+     */
+    if (dialog_state.visit_cols)
+	dialog_state.visit_cols = 2;
+
+    memset(&all, 0, sizeof(all));
+    all.items = items;
+    all.item_no = item_no;
+    for (k = 0; k < 2; ++k) {
+	data[k].ip = dlg_calloc(DIALOG_LISTITEM *, (item_no + 2));
+    }
+    fill_both_sides(&all);
+
+    if (dialog_vars.default_item != 0) {
+	cur_item = dlg_default_listitem(items);
+    } else {
+	if ((cur_item = first_item(&all, 0)) < 0)
+	    cur_item = first_item(&all, 1);
+    }
+    button = (dialog_state.visit_items
+	      ? (items[cur_item].state ? sRIGHT : sLEFT)
+	      : dlg_default_button());
+
+    dlg_does_output();
+
+#ifdef KEY_RESIZE
+  retry:
+#endif
+
+    prompt = dlg_strclone(cprompt);
+    dlg_tab_correct_str(prompt);
+
+    all.use_height = list_height;
+    all.use_width = (2 * (dlg_calc_list_width(item_no, items)
+			  + 4
+			  + 2 * MARGIN)
+		     + 1);
+    all.use_width = MAX(26, all.use_width);
+    if (all.use_height == 0) {
+	/* calculate height without items (4) */
+	dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, all.use_width);
+	dlg_calc_listh(&height, &all.use_height, item_no);
+    } else {
+	dlg_auto_size(title, prompt,
+		      &height, &width,
+		      MIN_HIGH + all.use_height, all.use_width);
+    }
+    dlg_button_layout(buttons, &width);
+    dlg_print_size(height, width);
+    dlg_ctl_size(height, width);
+
+    /* we need at least two states */
+    if (states == 0 || strlen(states) < 2)
+	states = " *";
+    num_states = (int) strlen(states);
+
+    x = dlg_box_x_ordinate(width);
+    y = dlg_box_y_ordinate(height);
+
+    dialog = dlg_new_window(height, width, y, x);
+    dlg_register_window(dialog, widget_name, binding);
+    dlg_register_buttons(dialog, widget_name, buttons);
+
+    dlg_mouse_setbase(all.base_x = x, all.base_y = y);
+
+    dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
+    dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
+    dlg_draw_title(dialog, title);
+
+    dlg_attrset(dialog, dialog_attr);
+    dlg_print_autowrap(dialog, prompt, height, width);
+
+    list_width = (width - 6 * MARGIN - 2) / 2;
+    getyx(dialog, cur_y, cur_x);
+    data[0].box_y = cur_y + 1;
+    data[0].box_x = MARGIN + 1;
+    data[1].box_y = cur_y + 1;
+    data[1].box_x = data[0].box_x + 1 + 2 * MARGIN + list_width;
+
+    /*
+     * After displaying the prompt, we know how much space we really have.
+     * Limit the list to avoid overwriting the ok-button.
+     */
+    if (all.use_height + MIN_HIGH > height - cur_y)
+       all.use_height = height - MIN_HIGH - cur_y;
+    if (all.use_height <= 0)
+	all.use_height = 1;
+
+    for (k = 0; k < 2; ++k) {
+	/* create new window for the list */
+	data[k].win = dlg_sub_window(dialog, all.use_height, list_width,
+				     y + data[k].box_y + 1,
+				     x + data[k].box_x + 1);
+
+	/* draw a box around the list items */
+	dlg_draw_box(dialog, data[k].box_y, data[k].box_x,
+		     all.use_height + 2 * MARGIN,
+		     list_width + 2 * MARGIN,
+		     menubox_border_attr, menubox_border2_attr);
+    }
+
+    text_width = 0;
+    name_width = 0;
+    /* Find length of longest item to center buildlist */
+    for (i = 0; i < item_no; i++) {
+	text_width = MAX(text_width, dlg_count_columns(items[i].text));
+	name_width = MAX(name_width, dlg_count_columns(items[i].name));
+    }
+
+    /* If the name+text is wider than the list is allowed, then truncate
+     * one or both of them.  If the name is no wider than 1/4 of the list,
+     * leave it intact.
+     */
+    all.use_width = (list_width - 6 * MARGIN);
+    if (dialog_vars.no_tags && !dialog_vars.no_items) {
+	full_width = MIN(all.use_width, text_width);
+    } else if (dialog_vars.no_items) {
+	full_width = MIN(all.use_width, name_width);
+    } else {
+	if (text_width >= 0
+	    && name_width >= 0
+	    && all.use_width > 0
+	    && text_width + name_width > all.use_width) {
+	    int need = (int) (0.25 * all.use_width);
+	    if (name_width > need) {
+		int want = (int) (all.use_width * ((double) name_width) /
+				  (text_width + name_width));
+		name_width = (want > need) ? want : need;
+	    }
+	    text_width = all.use_width - name_width;
+	}
+	full_width = text_width + name_width;
+    }
+
+    all.check_x = (all.use_width - full_width) / 2;
+    all.item_x = ((dialog_vars.no_tags
+		   ? 0
+		   : (dialog_vars.no_items
+		      ? 0
+		      : (name_width + 2)))
+		  + all.check_x);
+
+    /* ensure we are scrolled to show the current choice */
+    j = MIN(all.use_height, item_no);
+    for (i = 0; i < 2; ++i) {
+	if ((items[cur_item].state != 0) == i) {
+	    int top_item = cur_item - j + 1;
+	    if (top_item < 0)
+		top_item = 0;
+	    while ((items[top_item].state != 0) != i)
+		++top_item;
+	    set_top_item(&all, top_item, i);
+	} else {
+	    set_top_item(&all, 0, i);
+	}
+    }
+
+    /* register the new window, along with its borders */
+    for (i = 0; i < 2; ++i) {
+	dlg_mouse_mkbigregion(data[i].box_y + 1,
+			      data[i].box_x,
+			      all.use_height,
+			      list_width + 2,
+			      2 * KEY_MAX + (i * (1 + all.use_height)),
+			      1, 1, 1 /* by lines */ );
+    }
+
+    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
+
+    while (result == DLG_EXIT_UNKNOWN) {
+	int which = (items[cur_item].state != 0);
+	MY_DATA *moi = data + which;
+	int at_top = index2row(&all, moi->top_index, which);
+	int at_end = index2row(&all, -1, which);
+	int at_bot = skip_rows(&all, at_top, all.use_height, which);
+	int was_mouse;
+
+	DLG_TRACE(("# ** state %d:%d top %d (%d:%d:%d) %s\n",
+		   cur_item, item_no - 1,
+		   moi->top_index,
+		   at_top, at_bot, at_end,
+		   mySide(which)));
+
+	if (first) {
+	    print_both(&all, cur_item);
+	    dlg_trace_win(dialog);
+	    first = FALSE;
+	}
+
+	if (button < 0) {	/* --visit-items */
+	    int cur_row = index2row(&all, cur_item, which);
+	    cur_y = (data[which].box_y
+		     + cur_row
+		     + 1);
+	    if (at_top > 0)
+		cur_y -= at_top;
+	    cur_x = (data[which].box_x
+		     + all.check_x + 1);
+	    DLG_TRACE(("# ...visit row %d (%d,%d)\n", cur_row, cur_y, cur_x));
+	    wmove(dialog, cur_y, cur_x);
+	}
+
+	key = dlg_mouse_wgetch(dialog, &fkey);
+	if (dlg_result_key(key, fkey, &result)) {
+	    if (!dlg_button_key(result, &button, &key, &fkey))
+		break;
+	}
+
+	was_mouse = (fkey && is_DLGK_MOUSE(key));
+	if (was_mouse)
+	    key -= M_EVENT;
+
+	if (!was_mouse) {
+	    ;
+	} else if (key >= 2 * KEY_MAX) {
+	    i = (key - 2 * KEY_MAX) % (1 + all.use_height);
+	    j = (key - 2 * KEY_MAX) / (1 + all.use_height);
+	    k = row2index(&all, i + at_top, j);
+	    DLG_TRACE(("# MOUSE column %d, row %d ->item %d\n", j, i, k));
+	    if (k >= 0 && j < 2) {
+		if (j != which) {
+		    /*
+		     * Mouse click was in the other column.
+		     */
+		    moi = data + j;
+		    fix_top_item(&all, k, j);
+		}
+		which = j;
+		at_top = index2row(&all, moi->top_index, which);
+		at_bot = skip_rows(&all, at_top, all.use_height, which);
+		cur_item = k;
+		print_both(&all, cur_item);
+		key = DLGK_TOGGLE;	/* force the selected item to toggle */
+	    } else {
+		beep();
+		continue;
+	    }
+	    fkey = FALSE;
+	} else if (key >= KEY_MIN) {
+	    if (key > KEY_MAX) {
+		if (which == 0) {
+		    key = KEY_RIGHTCOL;		/* switch to right-column */
+		    fkey = FALSE;
+		} else {
+		    key -= KEY_MAX;
+		}
+	    } else {
+		if (which == 1) {
+		    key = KEY_LEFTCOL;	/* switch to left-column */
+		    fkey = FALSE;
+		}
+	    }
+	    key = dlg_lookup_key(dialog, key, &fkey);
+	}
+
+	/*
+	 * A space toggles the item status.  Normally we put the cursor on
+	 * the next available item in the same column.  But if there are no
+	 * more items in the column, move the cursor to the other column.
+	 */
+	if (key == DLGK_TOGGLE) {
+	    int new_choice;
+	    int new_state = items[cur_item].state + 1;
+
+	    if ((new_choice = next_item(&all, cur_item, which)) == cur_item) {
+		new_choice = prev_item(&all, cur_item, which);
+	    }
+	    DLG_TRACE(("# cur_item %d, new_choice:%d\n", cur_item, new_choice));
+	    /* FIXME - how to test and handle multiple states? */
+	    if (new_state >= num_states)
+		new_state = 0;
+
+	    items[cur_item].state = new_state;
+	    if (order_mode) {
+		fill_one_side(&all, 0);
+		if (new_state) {
+		    append_right_side(&all, cur_item);
+		} else {
+		    amend_right_side(&all, cur_item);
+		}
+	    } else {
+		fill_both_sides(&all);
+	    }
+	    if (cur_item == moi->top_index) {
+		set_top_item(&all, new_choice, which);
+	    }
+
+	    if (new_choice >= 0) {
+		fix_top_item(&all, cur_item, !which);
+		cur_item = new_choice;
+	    }
+	    print_both(&all, cur_item);
+	    dlg_trace_win(dialog);
+	    continue;		/* wait for another key press */
+	}
+
+	/*
+	 * Check if key pressed matches first character of any item tag in
+	 * list.  If there is more than one match, we will cycle through
+	 * each one as the same key is pressed repeatedly.
+	 */
+	found = FALSE;
+	if (!fkey) {
+	    if (button < 0 || !dialog_state.visit_items) {
+		for (j = cur_item + 1; j < item_no; j++) {
+		    if (check_hotkey(items, j, which)) {
+			found = TRUE;
+			i = j;
+			break;
+		    }
+		}
+		if (!found) {
+		    for (j = 0; j <= cur_item; j++) {
+			if (check_hotkey(items, j, which)) {
+			    found = TRUE;
+			    i = j;
+			    break;
+			}
+		    }
+		}
+		if (found)
+		    dlg_flush_getc();
+	    } else if ((j = dlg_char_to_button(key, buttons)) >= 0) {
+		button = j;
+		ungetch('\n');
+		continue;
+	    }
+	}
+
+	/*
+	 * A single digit (1-9) positions the selection to that line in the
+	 * current screen.
+	 */
+	if (!found
+	    && (key <= '9')
+	    && (key > '0')
+	    && (key - '1' < at_bot)) {
+	    found = TRUE;
+	    i = key - '1';
+	}
+
+	if (!found && fkey) {
+	    switch (key) {
+	    case DLGK_FIELD_PREV:
+		if ((button == sRIGHT) && dialog_state.visit_items) {
+		    key = DLGK_GRID_LEFT;
+		    button = sLEFT;
+		} else {
+		    button = dlg_prev_button(buttons, button);
+		    dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
+				     FALSE, width);
+		    if (button == sRIGHT) {
+			key = DLGK_GRID_RIGHT;
+		    } else {
+			continue;
+		    }
+		}
+		break;
+	    case DLGK_FIELD_NEXT:
+		if ((button == sLEFT) && dialog_state.visit_items) {
+		    key = DLGK_GRID_RIGHT;
+		    button = sRIGHT;
+		} else {
+		    button = dlg_next_button(buttons, button);
+		    dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
+				     FALSE, width);
+		    if (button == sLEFT) {
+			key = DLGK_GRID_LEFT;
+		    } else {
+			continue;
+		    }
+		}
+		break;
+	    }
+
+	    i = cur_item;
+	    found = TRUE;
+	    switch (key) {
+	    case DLGK_GRID_LEFT:
+		i = closest_item(&all, cur_item, 0);
+		fix_top_item(&all, i, 0);
+		break;
+	    case DLGK_GRID_RIGHT:
+		if (order_mode) {
+		    i = last_item(&all, 1);
+		} else {
+		    i = closest_item(&all, cur_item, 1);
+		}
+		fix_top_item(&all, i, 1);
+		break;
+	    case DLGK_PAGE_PREV:
+		if (cur_item > moi->top_index) {
+		    i = moi->top_index;
+		} else if (moi->top_index != 0) {
+		    int temp = at_top;
+		    if ((temp -= all.use_height) < 0)
+			temp = 0;
+		    i = row2index(&all, temp, which);
+		}
+		break;
+	    case DLGK_PAGE_NEXT:
+		if ((at_end - at_bot) < all.use_height) {
+		    i = next_item(&all,
+				  row2index(&all, at_end, which),
+				  which);
+		} else {
+		    i = next_item(&all,
+				  row2index(&all, at_bot, which),
+				  which);
+		    at_top = at_bot;
+		    set_top_item(&all,
+				 next_item(&all,
+					   row2index(&all, at_top, which),
+					   which),
+				 which);
+		    at_bot = skip_rows(&all, at_top, all.use_height, which);
+		    at_bot = MIN(at_bot, at_end);
+		}
+		break;
+	    case DLGK_ITEM_FIRST:
+		i = first_item(&all, which);
+		break;
+	    case DLGK_ITEM_LAST:
+		i = last_item(&all, which);
+		break;
+	    case DLGK_ITEM_PREV:
+		i = prev_item(&all, cur_item, which);
+		if (stop_prev(&all, cur_item, which))
+		    continue;
+		break;
+	    case DLGK_ITEM_NEXT:
+		i = next_item(&all, cur_item, which);
+		break;
+	    default:
+		found = FALSE;
+		break;
+	    }
+	}
+
+	if (found) {
+	    if (i != cur_item) {
+		int now_at = index2row(&all, i, which);
+		int oops = item_no;
+		int old_item;
+
+		DLG_TRACE(("# <--CHOICE %d\n", i));
+		DLG_TRACE(("# <--topITM %d\n", moi->top_index));
+		DLG_TRACE(("# <--now_at %d\n", now_at));
+		DLG_TRACE(("# <--at_top %d\n", at_top));
+		DLG_TRACE(("# <--at_bot %d\n", at_bot));
+
+		if (now_at >= at_bot) {
+		    while (now_at >= at_bot) {
+			if ((at_bot - at_top) >= all.use_height) {
+			    set_top_item(&all,
+					 next_item(&all, moi->top_index, which),
+					 which);
+			}
+			at_top = index2row(&all, moi->top_index, which);
+			at_bot = skip_rows(&all, at_top, all.use_height, which);
+
+			DLG_TRACE(("# ...at_bot %d (now %d vs %d)\n",
+				   at_bot, now_at, at_end));
+			DLG_TRACE(("# ...topITM %d\n", moi->top_index));
+			DLG_TRACE(("# ...at_top %d (diff %d)\n", at_top,
+				   at_bot - at_top));
+
+			if (at_bot >= at_end) {
+			    /*
+			     * If we bumped into the end, move the top-item
+			     * down by one line so that we can display the
+			     * last item in the list.
+			     */
+			    if ((at_bot - at_top) > all.use_height) {
+				set_top_item(&all,
+					     next_item(&all, moi->top_index, which),
+					     which);
+			    } else if (at_top > 0 &&
+				       (at_bot - at_top) >= all.use_height) {
+				set_top_item(&all,
+					     next_item(&all, moi->top_index, which),
+					     which);
+			    }
+			    break;
+			}
+			if (--oops < 0) {
+			    DLG_TRACE(("# OOPS-forward\n"));
+			    break;
+			}
+		    }
+		} else if (now_at < at_top) {
+		    while (now_at < at_top) {
+			old_item = moi->top_index;
+			set_top_item(&all,
+				     prev_item(&all, moi->top_index, which),
+				     which);
+			at_top = index2row(&all, moi->top_index, which);
+
+			DLG_TRACE(("# ...at_top %d (now %d)\n", at_top, now_at));
+			DLG_TRACE(("# ...topITM %d\n", moi->top_index));
+
+			if (moi->top_index >= old_item)
+			    break;
+			if (at_top <= now_at)
+			    break;
+			if (--oops < 0) {
+			    DLG_TRACE(("# OOPS-backward\n"));
+			    break;
+			}
+		    }
+		}
+		DLG_TRACE(("# -->now_at %d\n", now_at));
+		cur_item = i;
+		print_both(&all, cur_item);
+	    }
+	    dlg_trace_win(dialog);
+	    continue;		/* wait for another key press */
+	}
+
+	if (fkey) {
+	    switch (key) {
+	    case DLGK_ENTER:
+		result = dlg_enter_buttoncode(button);
+		break;
+	    case DLGK_LEAVE:
+		result = dlg_ok_buttoncode(button);
+		break;
+#ifdef KEY_RESIZE
+	    case KEY_RESIZE:
+		dlg_will_resize(dialog);
+		/* reset data */
+		height = old_height;
+		width = old_width;
+		free(prompt);
+		_dlg_resize_cleanup(dialog);
+		/* repaint */
+		first = TRUE;
+		goto retry;
+#endif
+	    default:
+		if (was_mouse) {
+		    if ((key2 = dlg_ok_buttoncode(key)) >= 0) {
+			result = key2;
+			break;
+		    }
+		    beep();
+		}
+	    }
+	} else if (key > 0) {
+	    beep();
+	}
+    }
+
+    /*
+     * If told to re-order the list, update it to reflect the current display:
+     * a) The left-side will be at the beginning, without gaps.
+     * b) The right-side will follow, in display-order.
+     */
+    if (order_mode) {
+	DIALOG_LISTITEM *redo;
+	int row;
+	int choice;
+	int new_item = cur_item;
+
+	redo = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
+	assert_ptr(redo, THIS_FUNC);
+
+	j = 0;
+	for (k = 0; k < 2; ++k) {
+	    for (row = 0; row < item_no; ++row) {
+		if (myItem(all.list + k, row) == 0)
+		    break;
+		choice = row2index(&all, row, k);
+		if (choice == cur_item)
+		    new_item = j;
+		redo[j++] = items[choice];
+	    }
+	}
+
+	cur_item = new_item;
+	memcpy(items, redo, sizeof(DIALOG_LISTITEM) * (size_t) (item_no + 1));
+
+	free(redo);
+    }
+
+    for (k = 0; k < 2; ++k) {
+	free(data[k].ip);
+    }
+
+    dialog_state.visit_cols = save_visit;
+    dlg_del_window(dialog);
+    dlg_mouse_free_regions();
+    free(prompt);
+
+    *current_item = cur_item;
+    return result;
+#undef THIS_FUNC
+}
+
+/*
+ * Display a dialog box with a list of options that can be turned on or off
+ */
+int
+dialog_buildlist(const char *title,
+		 const char *cprompt,
+		 int height,
+		 int width,
+		 int list_height,
+		 int item_no,
+		 char **items,
+		 int order_mode)
+{
+#define THIS_FUNC "dialog_buildlist"
+    int result;
+    int i, j;
+    DIALOG_LISTITEM *listitems;
+    bool separate_output = dialog_vars.separate_output;
+    bool show_status = FALSE;
+    int current = 0;
+    char *help_result;
+
+    DLG_TRACE(("# buildlist args:\n"));
+    DLG_TRACE2S("title", title);
+    DLG_TRACE2S("message", cprompt);
+    DLG_TRACE2N("height", height);
+    DLG_TRACE2N("width", width);
+    DLG_TRACE2N("lheight", list_height);
+    DLG_TRACE2N("llength", item_no);
+    /* FIXME dump the items[][] too */
+    DLG_TRACE2N("order", order_mode != 0);
+
+    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
+    assert_ptr(listitems, THIS_FUNC);
+
+    for (i = j = 0; i < item_no; ++i) {
+	listitems[i].name = items[j++];
+	listitems[i].text = (dialog_vars.no_items
+			     ? dlg_strempty()
+			     : items[j++]);
+	listitems[i].state = !dlg_strcmp(items[j++], "on");
+	listitems[i].help = ((dialog_vars.item_help)
+			     ? items[j++]
+			     : dlg_strempty());
+    }
+    dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
+
+    result = dlg_buildlist(title,
+			   cprompt,
+			   height,
+			   width,
+			   list_height,
+			   item_no,
+			   listitems,
+			   NULL,
+			   order_mode,
+			   &current);
+
+    switch (result) {
+    case DLG_EXIT_OK:		/* FALLTHRU */
+    case DLG_EXIT_EXTRA:
+	show_status = TRUE;
+	break;
+    case DLG_EXIT_HELP:
+	dlg_add_help_listitem(&result, &help_result, &listitems[current]);
+	if ((show_status = dialog_vars.help_status)) {
+	    if (separate_output) {
+		dlg_add_string(help_result);
+	    } else {
+		dlg_add_quoted(help_result);
+	    }
+	} else {
+	    dlg_add_string(help_result);
+	}
+	break;
+    }
+
+    if (show_status) {
+	for (i = 0; i < item_no; i++) {
+	    if (listitems[i].state) {
+		if (dlg_need_separator())
+		    dlg_add_separator();
+		if (separate_output) {
+		    dlg_add_string(listitems[i].name);
+		} else {
+		    dlg_add_quoted(listitems[i].name);
+		}
+	    }
+	}
+	AddLastKey();
+    }
+
+    dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
+    free(listitems);
+    return result;
+#undef THIS_FUNC
+}
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/checklist.c
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/checklist.c	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/checklist.c	(revision 5)
@@ -0,0 +1,703 @@
+/*
+ *  $Id: checklist.c,v 1.167 2020/11/23 00:37:47 tom Exp $
+ *
+ *  checklist.c -- implements the checklist box
+ *
+ *  Copyright 2000-2019,2020	Thomas E. Dickey
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License, version 2.1
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to
+ *	Free Software Foundation, Inc.
+ *	51 Franklin St., Fifth Floor
+ *	Boston, MA 02110, USA.
+ *
+ *  An earlier version of this program lists as authors:
+ *	Savio Lam (lam836@cs.cuhk.hk)
+ *	Stuart Herbert - S.Herbert@sheffield.ac.uk: radiolist extension
+ *	Alessandro Rubini - rubini@ipvvis.unipv.it: merged the two
+ */
+
+#include <dialog.h>
+#include <dlg_keys.h>
+
+#define MIN_HIGH  4
+
+typedef struct {
+    /* the outer-window */
+    WINDOW *dialog;
+    int box_y;
+    int box_x;
+    int check_x;
+    int item_x;
+    int checkflag;
+    int use_height;
+    int use_width;
+    /* the inner-window */
+    WINDOW *list;
+    DIALOG_LISTITEM *items;
+    int item_no;
+    const char *states;
+} ALL_DATA;
+
+/*
+ * Print list item.  The 'selected' parameter is true if 'choice' is the
+ * current item.  That one is colored differently from the other items.
+ */
+static void
+print_item(ALL_DATA * data,
+	   WINDOW *win,
+	   DIALOG_LISTITEM * item,
+	   const char *states,
+	   int choice,
+	   int selected)
+{
+    chtype save = dlg_get_attrs(win);
+    int i;
+    bool both = (!dialog_vars.no_tags && !dialog_vars.no_items);
+    bool first = TRUE;
+    int climit = (getmaxx(win) - data->check_x + 1);
+    const char *show = (dialog_vars.no_items
+			? item->name
+			: item->text);
+
+    /* Clear 'residue' of last item */
+    dlg_attrset(win, menubox_attr);
+    (void) wmove(win, choice, 0);
+    for (i = 0; i < data->use_width; i++)
+	(void) waddch(win, ' ');
+
+    (void) wmove(win, choice, data->check_x);
+    dlg_attrset(win, selected ? check_selected_attr : check_attr);
+    (void) wprintw(win,
+		   (data->checkflag == FLAG_CHECK) ? "[%c]" : "(%c)",
+		   states[item->state]);
+    dlg_attrset(win, menubox_attr);
+    (void) waddch(win, ' ');
+
+    if (both) {
+	dlg_print_listitem(win, item->name, climit, first, selected);
+	first = FALSE;
+    }
+
+    (void) wmove(win, choice, data->item_x);
+    dlg_print_listitem(win, show, climit, first, selected);
+
+    if (selected) {
+	dlg_item_help(item->help);
+    }
+    dlg_attrset(win, save);
+}
+
+static void
+print_list(ALL_DATA * data, int choice, int scrollamt, int max_choice)
+{
+    int i;
+    int cur_y, cur_x;
+
+    getyx(data->dialog, cur_y, cur_x);
+    for (i = 0; i < max_choice; i++) {
+	print_item(data,
+		   data->list,
+		   &data->items[i + scrollamt],
+		   data->states,
+		   i, i == choice);
+    }
+    (void) wnoutrefresh(data->list);
+
+    dlg_draw_scrollbar(data->dialog,
+		       (long) (scrollamt),
+		       (long) (scrollamt),
+		       (long) (scrollamt + max_choice),
+		       (long) (data->item_no),
+		       data->box_x + data->check_x,
+		       data->box_x + data->use_width,
+		       data->box_y,
+		       data->box_y + data->use_height + 1,
+		       menubox_border2_attr,
+		       menubox_border_attr);
+
+    (void) wmove(data->dialog, cur_y, cur_x);
+}
+
+static bool
+check_hotkey(DIALOG_LISTITEM * items, int choice)
+{
+    bool result = FALSE;
+
+    if (dlg_match_char(dlg_last_getc(),
+		       (dialog_vars.no_tags
+			? items[choice].text
+			: items[choice].name))) {
+	result = TRUE;
+    }
+    return result;
+}
+
+/*
+ * This is an alternate interface to 'checklist' which allows the application
+ * to read the list item states back directly without putting them in the
+ * output buffer.  It also provides for more than two states over which the
+ * check/radio box can display.
+ */
+int
+dlg_checklist(const char *title,
+	      const char *cprompt,
+	      int height,
+	      int width,
+	      int list_height,
+	      int item_no,
+	      DIALOG_LISTITEM * items,
+	      const char *states,
+	      int flag,
+	      int *current_item)
+{
+    /* *INDENT-OFF* */
+    static DLG_KEYS_BINDING binding[] = {
+	HELPKEY_BINDINGS,
+	ENTERKEY_BINDINGS,
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
+	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
+	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
+	DLG_KEYS_DATA( DLGK_ITEM_FIRST, KEY_HOME ),
+	DLG_KEYS_DATA( DLGK_ITEM_LAST,	KEY_END ),
+	DLG_KEYS_DATA( DLGK_ITEM_LAST,	KEY_LL ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	'+' ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	KEY_DOWN ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,  CHR_NEXT ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,	'-' ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,	KEY_UP ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,  CHR_PREVIOUS ),
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	KEY_NPAGE ),
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	DLGK_MOUSE(KEY_NPAGE) ),
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,	KEY_PPAGE ),
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,	DLGK_MOUSE(KEY_PPAGE) ),
+	TOGGLEKEY_BINDINGS,
+	END_KEYS_BINDING
+    };
+    /* *INDENT-ON* */
+
+#ifdef KEY_RESIZE
+    int old_height = height;
+    int old_width = width;
+#endif
+    ALL_DATA all;
+    int i, j, key2, found, x, y, cur_x, cur_y;
+    int key, fkey;
+    int button = dialog_state.visit_items ? -1 : dlg_default_button();
+    int choice = dlg_default_listitem(items);
+    int scrollamt = 0;
+    int max_choice;
+    int use_width, list_width, name_width, text_width;
+    int result = DLG_EXIT_UNKNOWN;
+    int num_states;
+    WINDOW *dialog;
+    char *prompt;
+    const char **buttons = dlg_ok_labels();
+    const char *widget_name;
+
+    DLG_TRACE(("# %s args:\n", flag ? "checklist" : "radiolist"));
+    DLG_TRACE2S("title", title);
+    DLG_TRACE2S("message", cprompt);
+    DLG_TRACE2N("height", height);
+    DLG_TRACE2N("width", width);
+    DLG_TRACE2N("lheight", list_height);
+    DLG_TRACE2N("llength", item_no);
+    /* FIXME dump the items[][] too */
+    DLG_TRACE2S("states", states);
+    DLG_TRACE2N("flag", flag);
+    DLG_TRACE2N("current", *current_item);
+
+    dialog_state.plain_buttons = TRUE;
+
+    memset(&all, 0, sizeof(all));
+    all.items = items;
+    all.item_no = item_no;
+
+    dlg_does_output();
+
+    /*
+     * If this is a radiobutton list, ensure that no more than one item is
+     * selected initially.  Allow none to be selected, since some users may
+     * wish to provide this flavor.
+     */
+    if (flag == FLAG_RADIO) {
+	bool first = TRUE;
+
+	for (i = 0; i < item_no; i++) {
+	    if (items[i].state) {
+		if (first) {
+		    first = FALSE;
+		} else {
+		    items[i].state = 0;
+		}
+	    }
+	}
+	widget_name = "radiolist";
+    } else {
+	widget_name = "checklist";
+    }
+#ifdef KEY_RESIZE
+  retry:
+#endif
+
+    prompt = dlg_strclone(cprompt);
+    dlg_tab_correct_str(prompt);
+
+    all.use_height = list_height;
+    use_width = dlg_calc_list_width(item_no, items) + 10;
+    use_width = MAX(26, use_width);
+    if (all.use_height == 0) {
+	/* calculate height without items (4) */
+	dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, use_width);
+	dlg_calc_listh(&height, &all.use_height, item_no);
+    } else {
+	dlg_auto_size(title, prompt,
+		      &height, &width,
+		      MIN_HIGH + all.use_height, use_width);
+    }
+    dlg_button_layout(buttons, &width);
+    dlg_print_size(height, width);
+    dlg_ctl_size(height, width);
+
+    /* we need at least two states */
+    if (states == 0 || strlen(states) < 2)
+	states = " *";
+    num_states = (int) strlen(states);
+    all.states = states;
+
+    all.checkflag = flag;
+
+    x = dlg_box_x_ordinate(width);
+    y = dlg_box_y_ordinate(height);
+
+    dialog = dlg_new_window(height, width, y, x);
+    all.dialog = dialog;
+    dlg_register_window(dialog, widget_name, binding);
+    dlg_register_buttons(dialog, widget_name, buttons);
+
+    dlg_mouse_setbase(x, y);
+
+    dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
+    dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
+    dlg_draw_title(dialog, title);
+
+    dlg_attrset(dialog, dialog_attr);
+    dlg_print_autowrap(dialog, prompt, height, width);
+
+    all.use_width = width - 6;
+    getyx(dialog, cur_y, cur_x);
+    all.box_y = cur_y + 1;
+    all.box_x = (width - all.use_width) / 2 - 1;
+
+    /*
+     * After displaying the prompt, we know how much space we really have.
+     * Limit the list to avoid overwriting the ok-button.
+     */
+    if (all.use_height + MIN_HIGH > height - cur_y)
+       all.use_height = height - MIN_HIGH - cur_y;
+    if (all.use_height <= 0)
+	all.use_height = 1;
+
+    max_choice = MIN(all.use_height, item_no);
+    max_choice = MAX(max_choice, 1);
+
+    /* create new window for the list */
+    all.list = dlg_sub_window(dialog, all.use_height, all.use_width,
+			      y + all.box_y + 1, x + all.box_x + 1);
+
+    /* draw a box around the list items */
+    dlg_draw_box(dialog, all.box_y, all.box_x,
+		 all.use_height + 2 * MARGIN,
+		 all.use_width + 2 * MARGIN,
+		 menubox_border_attr, menubox_border2_attr);
+
+    text_width = 0;
+    name_width = 0;
+    /* Find length of longest item to center checklist */
+    for (i = 0; i < item_no; i++) {
+	text_width = MAX(text_width, dlg_count_columns(items[i].text));
+	name_width = MAX(name_width, dlg_count_columns(items[i].name));
+    }
+
+    /* If the name+text is wider than the list is allowed, then truncate
+     * one or both of them.  If the name is no wider than 1/4 of the list,
+     * leave it intact.
+     */
+    use_width = (all.use_width - 6);
+    if (dialog_vars.no_tags) {
+	list_width = MIN(all.use_width, text_width);
+    } else if (dialog_vars.no_items) {
+	list_width = MIN(all.use_width, name_width);
+    } else {
+	if (text_width >= 0
+	    && name_width >= 0
+	    && use_width > 0
+	    && text_width + name_width > use_width) {
+	    int need = (int) (0.25 * use_width);
+	    if (name_width > need) {
+		int want = (int) (use_width * ((double) name_width) /
+				  (text_width + name_width));
+		name_width = (want > need) ? want : need;
+	    }
+	    text_width = use_width - name_width;
+	}
+	list_width = (text_width + name_width);
+    }
+
+    all.check_x = (use_width - list_width) / 2;
+    all.item_x = ((dialog_vars.no_tags
+		   ? 0
+		   : (dialog_vars.no_items
+		      ? 0
+		      : (2 + name_width)))
+		  + all.check_x + 4);
+
+    /* ensure we are scrolled to show the current choice */
+    scrollamt = MIN(scrollamt, max_choice + item_no - 1);
+    if (choice >= (max_choice + scrollamt - 1)) {
+	scrollamt = MAX(0, choice - max_choice + 1);
+	choice = max_choice - 1;
+    }
+    print_list(&all, choice, scrollamt, max_choice);
+
+    /* register the new window, along with its borders */
+    dlg_mouse_mkbigregion(all.box_y + 1, all.box_x,
+			  all.use_height, all.use_width + 2,
+			  KEY_MAX, 1, 1, 1 /* by lines */ );
+
+    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
+
+    dlg_trace_win(dialog);
+
+    while (result == DLG_EXIT_UNKNOWN) {
+	int was_mouse;
+
+	if (button < 0)		/* --visit-items */
+	    wmove(dialog, all.box_y + choice + 1, all.box_x + all.check_x + 2);
+
+	key = dlg_mouse_wgetch(dialog, &fkey);
+	if (dlg_result_key(key, fkey, &result)) {
+	    if (!dlg_button_key(result, &button, &key, &fkey))
+		break;
+	}
+
+	was_mouse = (fkey && is_DLGK_MOUSE(key));
+	if (was_mouse)
+	    key -= M_EVENT;
+
+	if (was_mouse && (key >= KEY_MAX)) {
+	    getyx(dialog, cur_y, cur_x);
+	    i = (key - KEY_MAX);
+	    if (i < max_choice) {
+		choice = (key - KEY_MAX);
+		print_list(&all, choice, scrollamt, max_choice);
+
+		key = DLGK_TOGGLE;	/* force the selected item to toggle */
+	    } else {
+		beep();
+		continue;
+	    }
+	    fkey = FALSE;
+	} else if (was_mouse && key >= KEY_MIN) {
+	    key = dlg_lookup_key(dialog, key, &fkey);
+	}
+
+	/*
+	 * A space toggles the item status.  We handle either a checklist
+	 * (any number of items can be selected) or radio list (zero or one
+	 * items can be selected).
+	 */
+	if (key == DLGK_TOGGLE) {
+	    int current = scrollamt + choice;
+	    int next = items[current].state + 1;
+
+	    if (next >= num_states)
+		next = 0;
+
+	    if (flag == FLAG_CHECK) {	/* checklist? */
+		getyx(dialog, cur_y, cur_x);
+		items[current].state = next;
+		print_item(&all, all.list,
+			   &items[scrollamt + choice],
+			   states,
+			   choice, TRUE);
+		(void) wnoutrefresh(all.list);
+		(void) wmove(dialog, cur_y, cur_x);
+	    } else {		/* radiolist */
+		for (i = 0; i < item_no; i++) {
+		    if (i != current) {
+			items[i].state = 0;
+		    }
+		}
+		if (items[current].state) {
+		    getyx(dialog, cur_y, cur_x);
+		    items[current].state = next ? next : 1;
+		    print_item(&all, all.list,
+			       &items[current],
+			       states,
+			       choice, TRUE);
+		    (void) wnoutrefresh(all.list);
+		    (void) wmove(dialog, cur_y, cur_x);
+		} else {
+		    items[current].state = 1;
+		    print_list(&all, choice, scrollamt, max_choice);
+		}
+	    }
+	    continue;		/* wait for another key press */
+	}
+
+	/*
+	 * Check if key pressed matches first character of any item tag in
+	 * list.  If there is more than one match, we will cycle through
+	 * each one as the same key is pressed repeatedly.
+	 */
+	found = FALSE;
+	if (!fkey) {
+	    if (button < 0 || !dialog_state.visit_items) {
+		for (j = scrollamt + choice + 1; j < item_no; j++) {
+		    if (check_hotkey(items, j)) {
+			found = TRUE;
+			i = j - scrollamt;
+			break;
+		    }
+		}
+		if (!found) {
+		    for (j = 0; j <= scrollamt + choice; j++) {
+			if (check_hotkey(items, j)) {
+			    found = TRUE;
+			    i = j - scrollamt;
+			    break;
+			}
+		    }
+		}
+		if (found)
+		    dlg_flush_getc();
+	    } else if ((j = dlg_char_to_button(key, buttons)) >= 0) {
+		button = j;
+		ungetch('\n');
+		continue;
+	    }
+	}
+
+	/*
+	 * A single digit (1-9) positions the selection to that line in the
+	 * current screen.
+	 */
+	if (!found
+	    && (key <= '9')
+	    && (key > '0')
+	    && (key - '1' < max_choice)) {
+	    found = TRUE;
+	    i = key - '1';
+	}
+
+	if (!found) {
+	    if (fkey) {
+		found = TRUE;
+		switch (key) {
+		case DLGK_ITEM_FIRST:
+		    i = -scrollamt;
+		    break;
+		case DLGK_ITEM_LAST:
+		    i = item_no - 1 - scrollamt;
+		    break;
+		case DLGK_PAGE_PREV:
+		    if (choice)
+			i = 0;
+		    else if (scrollamt != 0)
+			i = -MIN(scrollamt, max_choice);
+		    else
+			continue;
+		    break;
+		case DLGK_PAGE_NEXT:
+		    i = MIN(choice + max_choice, item_no - scrollamt - 1);
+		    break;
+		case DLGK_ITEM_PREV:
+		    i = choice - 1;
+		    if (choice == 0 && scrollamt == 0)
+			continue;
+		    break;
+		case DLGK_ITEM_NEXT:
+		    i = choice + 1;
+		    if (scrollamt + choice >= item_no - 1)
+			continue;
+		    break;
+		default:
+		    found = FALSE;
+		    break;
+		}
+	    }
+	}
+
+	if (found) {
+	    if (i != choice) {
+		getyx(dialog, cur_y, cur_x);
+		if (i < 0 || i >= max_choice) {
+		    if (i < 0) {
+			scrollamt += i;
+			choice = 0;
+		    } else {
+			choice = max_choice - 1;
+			scrollamt += (i - max_choice + 1);
+		    }
+		    print_list(&all, choice, scrollamt, max_choice);
+		} else {
+		    choice = i;
+		    print_list(&all, choice, scrollamt, max_choice);
+		}
+	    }
+	    continue;		/* wait for another key press */
+	}
+
+	if (fkey) {
+	    switch (key) {
+	    case DLGK_ENTER:
+		result = dlg_enter_buttoncode(button);
+		break;
+	    case DLGK_LEAVE:
+		result = dlg_ok_buttoncode(button);
+		break;
+	    case DLGK_FIELD_PREV:
+		button = dlg_prev_button(buttons, button);
+		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
+				 FALSE, width);
+		break;
+	    case DLGK_FIELD_NEXT:
+		button = dlg_next_button(buttons, button);
+		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
+				 FALSE, width);
+		break;
+#ifdef KEY_RESIZE
+	    case KEY_RESIZE:
+		dlg_will_resize(dialog);
+		/* reset data */
+		height = old_height;
+		width = old_width;
+		free(prompt);
+		_dlg_resize_cleanup(dialog);
+		/* repaint */
+		goto retry;
+#endif
+	    default:
+		if (was_mouse) {
+		    if ((key2 = dlg_ok_buttoncode(key)) >= 0) {
+			result = key2;
+			break;
+		    }
+		    beep();
+		}
+	    }
+	} else if (key > 0) {
+	    beep();
+	}
+    }
+
+    dlg_del_window(dialog);
+    dlg_mouse_free_regions();
+    free(prompt);
+    *current_item = (scrollamt + choice);
+    return result;
+}
+
+/*
+ * Display a dialog box with a list of options that can be turned on or off
+ * The `flag' parameter is used to select between radiolist and checklist.
+ */
+int
+dialog_checklist(const char *title,
+		 const char *cprompt,
+		 int height,
+		 int width,
+		 int list_height,
+		 int item_no,
+		 char **items,
+		 int flag)
+{
+    int result;
+    int i, j;
+    DIALOG_LISTITEM *listitems;
+    bool separate_output = ((flag == FLAG_CHECK)
+			    && (dialog_vars.separate_output));
+    bool show_status = FALSE;
+    int current = 0;
+    char *help_result;
+
+    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
+    assert_ptr(listitems, "dialog_checklist");
+
+    for (i = j = 0; i < item_no; ++i) {
+	listitems[i].name = items[j++];
+	listitems[i].text = (dialog_vars.no_items
+			     ? dlg_strempty()
+			     : items[j++]);
+	listitems[i].state = !dlg_strcmp(items[j++], "on");
+	listitems[i].help = ((dialog_vars.item_help)
+			     ? items[j++]
+			     : dlg_strempty());
+    }
+    dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
+
+    result = dlg_checklist(title,
+			   cprompt,
+			   height,
+			   width,
+			   list_height,
+			   item_no,
+			   listitems,
+			   NULL,
+			   flag,
+			   &current);
+
+    switch (result) {
+    case DLG_EXIT_OK:		/* FALLTHRU */
+    case DLG_EXIT_EXTRA:
+	show_status = TRUE;
+	break;
+    case DLG_EXIT_HELP:
+	dlg_add_help_listitem(&result, &help_result, &listitems[current]);
+	if ((show_status = dialog_vars.help_status)) {
+	    if (separate_output) {
+		dlg_add_string(help_result);
+		dlg_add_separator();
+	    } else {
+		dlg_add_quoted(help_result);
+	    }
+	} else {
+	    dlg_add_string(help_result);
+	}
+	break;
+    }
+
+    if (show_status) {
+	for (i = 0; i < item_no; i++) {
+	    if (listitems[i].state) {
+		if (separate_output) {
+		    dlg_add_string(listitems[i].name);
+		    dlg_add_separator();
+		} else {
+		    if (dlg_need_separator())
+			dlg_add_separator();
+		    if (flag == FLAG_CHECK)
+			dlg_add_quoted(listitems[i].name);
+		    else
+			dlg_add_string(listitems[i].name);
+		}
+	    }
+	}
+	dlg_add_last_key(separate_output);
+    }
+
+    dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
+    free(listitems);
+    return result;
+}
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/dialog-config.in
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/dialog-config.in	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/dialog-config.in	(revision 5)
@@ -0,0 +1,265 @@
+#!@SHELL@
+# $Id: dialog-config.in,v 1.14 2021/03/05 23:48:36 tom Exp $
+##############################################################################
+# Copyright (c) 2007-2019,2021 Thomas E. Dickey                              #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "Software"), #
+# to deal in the Software without restriction, including without limitation  #
+# the rights to use, copy, modify, merge, publish, distribute, distribute    #
+# with modifications, sublicense, and/or sell copies of the Software, and to #
+# permit persons to whom the Software is furnished to do so, subject to the  #
+# following conditions:                                                      #
+#                                                                            #
+# The above copyright notice and this permission notice shall be included in #
+# all copies or substantial portions of the Software.                        #
+#                                                                            #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
+# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
+# DEALINGS IN THE SOFTWARE.                                                  #
+#                                                                            #
+# Except as contained in this notice, the name(s) of the above copyright     #
+# holders shall not be used in advertising or otherwise to promote the sale, #
+# use or other dealings in this Software without prior written               #
+# authorization.                                                             #
+##############################################################################
+
+prefix="@prefix@"
+exec_prefix="@exec_prefix@"
+datarootdir="@datarootdir@"
+
+same_prefix=yes
+same_exec_prefix=yes
+
+THIS="@PACKAGE@"
+
+test $# = 0 && exec @SHELL@ "$0" --error
+
+while test $# -gt 0; do
+
+	# (re)evaluate symbols that may depend upon $prefix
+	if [ "x$same_prefix" != "xyes" ]
+	then
+		eval exec_prefix='@exec_prefix@'
+		eval datarootdir='@datarootdir@'
+	elif [ "x$same_exec_prefix" != "xyes" ]
+	then
+		eval datarootdir='@datarootdir@'
+	fi
+
+	eval bindir='"@bindir@"'
+	eval includedir='"@includedir@"'
+	eval libdir='"@libdir@"'
+	eval datadir='"@datadir@"'
+	eval mandir='"@mandir@"'
+
+	[ -z "$includedir" ] && includedir="${prefix}/include" 
+
+	eval LDFLAGS='"@LDFLAGS@"'
+	eval LIBS='"@LIBS@"'
+	LIBS="-l${THIS} $LIBS"
+
+	# If the directory given by --libdir is not in the LDFLAGS+LIBS set,
+	# prepend it to LDFLAGS to help link this application's library.
+	found=no
+	for opt in $LDFLAGS $LIBS
+	do
+		if [ "x$-L${libdir}" = "x$opt" ]
+		then
+			found=yes
+			break
+		fi
+	done
+	if [ $found = no ]
+	then
+		[ -n "$LFLAGS" ] && LDFLAGS=" $LFDLAGS"
+		LDFLAGS="-L${libdir}$LDFLAGS"
+	fi
+	[ -z "$LDFLAGS" ] && LDFLAGS="-L${libdir}"
+
+	# Ignore -L options which do not correspond to an actual directory,
+	# or which are standard library directories (i.e., the linker is
+	# supposed to search those directories).
+	#
+	# There is no portable way to find the list of standard library
+	# directories.  Require a POSIX shell anyway, to keep this simple.
+	lib_flags=
+	for opt in $LDFLAGS $LIBS
+	do
+		case $opt in
+		-L*)
+			opt_lib=`echo "x$opt" | sed -e 's/^x-L//'`
+			[ -d "$opt_lib" ] || continue
+			case "$opt_lib" in
+			@LD_SEARCHPATH@) # skip standard libdir
+				continue
+				;;
+			*)
+				;;
+			esac
+			;;
+		esac
+		lib_flags="$lib_flags $opt"
+	done
+
+	case "$1" in
+	-*=*)
+		ARG=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
+		;;
+	*)
+		ARG=
+		;;
+	esac
+
+	case "$1" in
+	# basic configuration
+	--prefix=*)
+		prefix="$ARG"
+		test -z "$exec_prefix" && exec_prefix="$ARG"
+		same_prefix=no
+		;;
+	--prefix)
+		echo "$prefix"
+		;;
+	--exec-prefix=*)
+		exec_prefix="$ARG"
+		same_exec_prefix=no
+		;;
+	--exec-prefix)
+		echo "$exec_prefix"
+		;;
+	# compile/link
+	--cflags|--cflags-only-I)
+		INCS="-I$includedir"
+		sed -e 's,^[ ]*,,' -e 's, [ ]*, ,g' -e 's,[ ]*$,,' <<-ENDECHO
+			$INCS
+ENDECHO
+		;;
+	--cflags-only-other)
+		# no -D/-U options should be needed
+		echo
+		;;
+	--ldflags)
+		OPTS=
+		for opt in $LDFLAGS $LIBS
+		do
+			case "x$opt" in
+			x-[^l]*)
+				OPTS="$OPTS $opt"
+				;;
+			esac
+		done
+		printf "%s\n" "$OPTS"
+		;;
+	--libs)
+		OPTS=
+		for opt in $lib_flags
+		do
+			[ -n "$OPTS" ] && OPTS="$OPTS "
+			OPTS="${OPTS}${opt}"
+		done
+		printf "%s\n" "$OPTS"
+		;;
+	--libs-only-L)
+		OPTS=
+		for opt in $lib_flags
+		do
+			case "x$opt" in
+			x-L*)
+				[ -n "$OPTS" ] && OPTS="$OPTS "
+				OPTS="${OPTS}${opt}"
+				;;
+			esac
+		done
+		printf "%s\n" "$OPTS"
+		;;
+	--libs-only-l)
+		OPTS=
+		for opt in $lib_flags
+		do
+			case "x$opt" in
+			x-l*)
+				[ -n "$OPTS" ] && OPTS="$OPTS "
+				OPTS="${OPTS}${opt}"
+				;;
+			esac
+		done
+		printf "%s\n" "$OPTS"
+		;;
+	--libs-only-other)
+		OPTS=
+		for opt in $lib_flags
+		do
+			case "x$opt" in
+			x-[lL]*)
+				;;
+			*)
+				[ -n "$OPTS" ] && OPTS="$OPTS "
+				OPTS="${OPTS}${opt}"
+				;;
+			esac
+		done
+		printf "%s\n" "$OPTS"
+		;;
+	# identification
+	--version)
+		echo "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@"
+		;;
+	--abi-version)
+		echo "@VERSION@" | sed -e 's/:/./g'
+		;;
+	# locations
+	--bindir)
+		echo "${bindir}"
+		;;
+	--datadir)
+		echo "${datadir}"
+		;;
+	--libdir)
+		echo "${libdir}"
+		;;
+	--mandir)
+		echo "${mandir}"
+		;;
+	# general info
+	--help)
+		cat <<ENDHELP
+Usage: ${THIS}-config [options]
+
+Options:
+  --prefix           echos the package-prefix of ${THIS}
+  --prefix=ARG       sets the package-prefix of ${THIS}
+  --exec-prefix      echos the executable-prefix of ${THIS}
+  --exec-prefix=ARG  sets the executable-prefix of ${THIS}
+
+  --cflags           echos the C compiler flags needed to compile with ${THIS}
+  --ldflags          echos the linker flags needed to link with ${THIS}
+
+  --libs             echos the libraries needed to link with ${THIS}
+  --libs-only-L      echos -L linker options (search path) for ${THIS}
+  --libs-only-l      echos -l linker options (libraries) for ${THIS}
+  --libs-only-other  echos linker options other than -L/-l
+
+  --version          echos the release+patchdate version of ${THIS}
+  --abi-version      echos the ABI version of ${THIS}
+
+  --bindir           echos the directory containing ${THIS} programs
+  --datadir          echos the directory containing ${THIS} data
+  --libdir           echos the directory containing ${THIS} libraries
+  --mandir           echos the directory containing ${THIS} manual pages
+
+  --help             prints this message
+ENDHELP
+		;;
+	--error|*)
+		@SHELL@ "$0" --help 1>&2
+		exit 1
+		;;
+	esac
+	shift
+done
+# vile:shmode
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/dialog.m4
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/dialog.m4	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/dialog.m4	(revision 5)
@@ -0,0 +1,324 @@
+dnl #
+dnl # /usr/share/aclocal/dialog.m4
+dnl #
+dnl # Configure paths for dialog
+dnl # Andrew V.Kosteltsev
+
+dnl ============================================================
+dnl
+dnl  Synopsis:
+dnl     AC_CHECK_DIALOG([MIN-VERSION [,                  # minimum dialog version, e.g. 1.3-20190211
+dnl                           DEFAULT-WITH-DIALOG [,     # default value for --with-dialog option
+dnl                           DEFAULT-WITH-DIALOG-TEST [,# default value for --with-dialog-test option
+dnl                           EXTEND-VARS [,                  # whether CFLAGS/LDFLAGS/etc are extended
+dnl                           ACTION-IF-FOUND [,              # action to perform if dialog was found
+dnl                           ACTION-IF-NOT-FOUND             # action to perform if dialog was not found
+dnl                          ]]]]]])
+dnl  Examples:
+dnl     AC_CHECK_DIALOG(1.3-20210621)
+dnl     AC_CHECK_DIALOG(1.3-20210621,,,no,CFLAGS="$CFLAGS -DHAVE_DIALOG $DIALOG_CFLAGS")
+dnl     AC_CHECK_DIALOG(1.3-20210621,yes,yes,yes,CFLAGS="$CFLAGS -DHAVE_DIALOG")
+dnl
+dnl
+dnl  If you have to change prefix returned by dialog-config script or change
+dnl  location of dialog-config, you may set environment variable DIALOG_CONFIG,
+dnl  for example:
+dnl
+dnl  # export DIALOG_CONFIG="dialog-config --prefix=/usr/local"
+dnl  # export DIALOG_CONFIG="/usr/bin/dialog-config --prefix=/usr/local"
+dnl
+dnl ============================================================
+dnl
+dnl ============================================================
+dnl  auxilliary macros
+dnl ============================================================
+AC_DEFUN([_AC_DIALOG_ERROR], [dnl
+AC_MSG_RESULT([*FAILED*])
+cat <<EOT | sed -e 's/^[[ 	]]*/ | /' -e 's/>>/  /' 1>&2
+$1
+EOT
+exit 1
+])
+
+AC_DEFUN([_AC_DIALOG_VERBOSE], [dnl
+if test ".$verbose" = .yes; then
+    AC_MSG_RESULT([  $1])
+fi
+])
+
+dnl ============================================================
+dnl  the user macro
+dnl ============================================================
+AC_DEFUN([AC_CHECK_DIALOG], [dnl
+dnl
+dnl ============================================================
+dnl  prerequisites
+dnl ============================================================
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_PROG_CPP])dnl
+dnl
+dnl ============================================================
+dnl  set DIALOG_CONFIG variable
+dnl ============================================================
+if test -z "$DIALOG_CONFIG"; then
+  DIALOG_CONFIG='dialog-config'
+fi
+dnl
+DIALOG_CFLAGS=''
+DIALOG_LDFLAGS=''
+DIALOG_LIBS=''
+AC_SUBST(DIALOG_CFLAGS)
+AC_SUBST(DIALOG_LDFLAGS)
+AC_SUBST(DIALOG_LIBS)
+dnl
+dnl ============================================================
+dnl  command line options
+dnl ============================================================
+_AC_DIALOG_VERBOSE([])
+AC_ARG_WITH(dialog,dnl
+[  --with-dialog[=ARG]       Build with dialog Library  (default=]ifelse([$2],,yes,$2)[)],dnl
+,dnl
+with_dialog="ifelse([$2],,yes,$2)"
+)dnl
+AC_ARG_WITH(dialog-test,dnl
+[  --with-dialog-test      Perform dialog Sanity Test (default=]ifelse([$3],,yes,$3)[)],dnl
+,dnl
+with_dialog_test="ifelse([$3],,yes,$3)"
+)dnl
+_AC_DIALOG_VERBOSE([+ Command Line Options:])
+_AC_DIALOG_VERBOSE([    o --with-dialog=$with_dialog])
+_AC_DIALOG_VERBOSE([    o --with-dialog-test=$with_dialog_test])
+dnl
+dnl ============================================================
+dnl  configuration
+dnl ============================================================
+if test ".$with_dialog" != .no; then
+    dialog_subdir=no
+    dialog_subdir_opts=''
+    case "$with_dialog" in
+        subdir:* )
+            dialog_subdir=yes
+            changequote(, )dnl
+            dialog_subdir_opts=`echo $with_dialog | sed -e 's/^subdir:[^ 	]*[ 	]*//'`
+            with_dialog=`echo $with_dialog | sed -e 's/^subdir:\([^ 	]*\).*$/\1/'`
+            changequote([, ])dnl
+            ;;
+    esac
+    dialog_version=""
+    dialog_location=""
+    dialog_type=""
+    dialog_cflags=""
+    dialog_ldflags=""
+    dialog_libs=""
+    if test ".$with_dialog" = .yes; then
+        #   via config script in $PATH
+        changequote(, )dnl
+        dialog_version=`($DIALOG_CONFIG --version) 2>/dev/null |\
+                      sed -e 's/^.*\([0-9]\.[0-9]*[-][0-9]*\).*$/\1/'`
+        changequote([, ])dnl
+        if test ".$dialog_version" != .; then
+            dialog_location=`$DIALOG_CONFIG --prefix`
+            dialog_type='installed'
+            dialog_cflags=`$DIALOG_CONFIG --cflags`
+            dialog_ldflags=`$DIALOG_CONFIG --ldflags`
+            dialog_libs=`$DIALOG_CONFIG --libs`
+        fi
+    elif test -d "$with_dialog"; then
+        with_dialog=`echo $with_dialog | sed -e 's;/*$;;'`
+        dialog_found=no
+        #   via config script under a specified directory
+        #   (a standard installation, but not a source tree)
+        if test ".$dialog_found" = .no; then
+            for _dir in $with_dialog/bin $with_dialog; do
+                if test -f "$_dir/dialog-config"; then
+                    test -f "$_dir/dialog-config.in" && continue # dialog-config in source tree!
+                    changequote(, )dnl
+                    dialog_version=`($_dir/dialog-config --version) 2>/dev/null |\
+                                  sed -e 's/^.*\([0-9]\.[0-9]*[.][0-9]*\).*$/\1/'`
+                    changequote([, ])dnl
+                    if test ".$dialog_version" != .; then
+                        dialog_location=`$_dir/dialog-config --prefix`
+                        dialog_type="installed"
+                        dialog_cflags=`$_dir/dialog-config --cflags`
+                        dialog_ldflags=`$_dir/dialog-config --ldflags`
+                        dialog_libs=`$_dir/dialog-config --libs`
+                        dialog_found=yes
+                        break
+                    fi
+                fi
+            done
+        fi
+    fi
+    _AC_DIALOG_VERBOSE([+ Determined Location:])
+    _AC_DIALOG_VERBOSE([    o path: $dialog_location])
+    _AC_DIALOG_VERBOSE([    o type: $dialog_type])
+    if test ".$dialog_version" = .; then
+        if test ".$with_dialog" != .yes; then
+             _AC_DIALOG_ERROR([dnl
+             Unable to locate dialog under $with_dialog.
+             Please specify the correct path to either a dialog installation tree
+             (use --with-dialog=DIR if you used --prefix=DIR for installing dialog in
+             the past).])
+        else
+             _AC_DIALOG_ERROR([dnl
+             Unable to locate dialog in any system-wide location (see \$PATH).
+             Please specify the correct path to either a dialog installation tree
+             (use --with-dialog=DIR if you used --prefix=DIR for installing dialog in
+             the past, or set the DIALOG_CONFIG environment variable to the full path
+             to dialog-config).])
+        fi
+    fi
+    dnl ========================================================
+    dnl  Check whether the found version is sufficiently new
+    dnl ========================================================
+    _req_version="ifelse([$1],,1.0.0,$1)"
+    for _var in dialog_version _req_version; do
+        eval "_val=\"\$${_var}\""
+        _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[.]]\)\([[0-9]]*\)/\1/'`
+        _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[.]]\)\([[0-9]]*\)/\2/'`
+        _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[.]]\)\([[0-9]]*\)/\4/'`
+        _hex=`echo dummy | awk '{ printf("%d%02d%02d", major, minor, micro); }' \
+              "major=$_major" "minor=$_minor" "micro=$_micro"`
+        eval "${_var}_hex=\"\$_hex\""
+    done
+    _AC_DIALOG_VERBOSE([+ Determined Versions:])
+    _AC_DIALOG_VERBOSE([    o existing: $dialog_version -> 0x$dialog_version_hex])
+    _AC_DIALOG_VERBOSE([    o required: $_req_version -> 0x$_req_version_hex])
+    _ok=0
+    if test ".$dialog_version_hex" != .; then
+        if test ".$_req_version_hex" != .; then
+            if test $dialog_version_hex -ge $_req_version_hex; then
+                _ok=1
+            fi
+        fi
+    fi
+    if test ".$_ok" = .0; then
+        _AC_DIALOG_ERROR([dnl
+        Found dialog version $dialog_version, but required at least version $_req_version.
+        Upgrade dialog under $dialog_location to $_req_version or higher first, please.])
+    fi
+    dnl ========================================================
+    dnl  Perform dialog Sanity Compile Check
+    dnl ========================================================
+    if test ".$with_dialog_test" = .yes; then
+        _ac_save_CFLAGS="$CFLAGS"
+        _ac_save_LDFLAGS="$LDFLAGS"
+        _ac_save_LIBS="$LIBS"
+        CFLAGS="$CFLAGS $dialog_cflags"
+        LDFLAGS="$LDFLAGS $dialog_ldflags"
+        LIBS="$LIBS $dialog_libs"
+        _AC_DIALOG_VERBOSE([+ Test Build Environment:])
+        _AC_DIALOG_VERBOSE([    o CFLAGS="$CFLAGS"])
+        _AC_DIALOG_VERBOSE([    o LDFLAGS="$LDFLAGS"])
+        _AC_DIALOG_VERBOSE([    o LIBS="$LIBS"])
+        cross_compile=no
+        define([_code1], [
+#include <stdlib.h>
+#include <stdio.h>
+#include <strings.h>  /* index(3)    */
+
+#include <dialog.h>
+#include <dlg_colors.h>
+#include <dlg_keys.h>
+        ])
+        define([_code2], [
+  int status = 0;
+
+  bzero( (void *)&dialog_vars, sizeof(DIALOG_VARS) );
+
+  init_dialog(stdin, stdout);
+
+  dialog_vars.colors = 1;
+  dialog_vars.backtitle = "Test dialog Library";
+  dialog_vars.dlg_clear_screen = 1;
+  dialog_vars.sleep_secs = 1;
+
+
+  dlg_put_backtitle();
+
+  /*************************************************
+    Ruler: 68 characters + 2 spaces left and right:
+
+                           | ----handy-ruler----------------------------------------------------- | */
+  status = dialog_msgbox( " Dialog ==>libdialog<== [required] ",
+                          "\nPackage is installed and corect.\n",
+                          5, 72, 0 );
+
+  if( dialog_vars.sleep_secs )
+    (void)napms(dialog_vars.sleep_secs * 1000);
+
+  if( dialog_vars.dlg_clear_screen )
+  {
+    dlg_clear();
+    (void)refresh();
+  }
+  end_dialog();
+        ])
+        _AC_DIALOG_VERBOSE([+ Performing Sanity Checks:])
+        _AC_DIALOG_VERBOSE([    o pre-processor test])
+        AC_PREPROC_IFELSE([AC_LANG_PROGRAM([_code1], [_code2])], [_ok=yes], [_ok=no])
+        if test ".$_ok" != .yes; then
+            _AC_DIALOG_ERROR([dnl
+            Found dialog $dialog_version under $dialog_location, but
+            was unable to perform a sanity pre-processor check. This means
+            the dialog header dialog.h was not found.
+            We used the following build environment:
+            >> CPP="$CPP"
+            See config.log for possibly more details.])
+        fi
+        _AC_DIALOG_VERBOSE([    o link check])
+        AC_LINK_IFELSE([AC_LANG_PROGRAM([_code1], [_code2])], [_ok=yes], [_ok=no])
+        if test ".$_ok" != .yes; then
+            _AC_DIALOG_ERROR([dnl
+            Found dialog $dialog_version under $dialog_location, but
+            was unable to perform a sanity linker check. This means
+            the dialog library libdialog.a was not found.
+            We used the following build environment:
+            >> CC="$CC"
+            >> CFLAGS="$CFLAGS"
+            >> LDFLAGS="$LDFLAGS"
+            >> LIBS="$LIBS"
+            See config.log for possibly more details.])
+        fi
+        _extendvars="ifelse([$4],,yes,$4)"
+        if test ".$_extendvars" != .yes; then
+            CFLAGS="$_ac_save_CFLAGS"
+            LDFLAGS="$_ac_save_LDFLAGS"
+            LIBS="$_ac_save_LIBS"
+        fi
+    else
+        _extendvars="ifelse([$4],,yes,$4)"
+        if test ".$_extendvars" = .yes; then
+            if test ".$dialog_subdir" = .yes; then
+                CFLAGS="$CFLAGS $dialog_cflags"
+                LDFLAGS="$LDFLAGS $dialog_ldflags"
+                LIBS="$LIBS $dialog_libs"
+            fi
+        fi
+    fi
+    DIALOG_CFLAGS="$dialog_cflags"
+    DIALOG_LDFLAGS="$dialog_ldflags"
+    DIALOG_LIBS="$dialog_libs"
+    AC_SUBST(DIALOG_CFLAGS)
+    AC_SUBST(DIALOG_LDFLAGS)
+    AC_SUBST(DIALOG_LIBS)
+
+    AC_SUBST(HAVE_DIALOG, [1])
+
+    AC_CHECK_HEADERS(dialog.h dlg_colors.h dlg_keys.h)
+
+    _AC_DIALOG_VERBOSE([+ Final Results:])
+    _AC_DIALOG_VERBOSE([    o DIALOG_CFLAGS="$DIALOG_CFLAGS"])
+    _AC_DIALOG_VERBOSE([    o DIALOG_LDFLAGS="$DIALOG_LDFLAGS"])
+    _AC_DIALOG_VERBOSE([    o DIALOG_LIBS="$DIALOG_LIBS"])
+fi
+if test ".$with_dialog" != .no; then
+    AC_MSG_CHECKING(for libdialog)
+    AC_MSG_RESULT([version $dialog_version, $dialog_type under $dialog_location])
+    ifelse([$5], , :, [$5])
+else
+    AC_MSG_CHECKING(for libdialog)
+    AC_MSG_RESULT([no])
+    ifelse([$6], , :, [$6])
+fi
+])
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/fselect.c
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/fselect.c	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/fselect.c	(revision 5)
@@ -0,0 +1,971 @@
+/*
+ *  $Id: fselect.c,v 1.117 2021/06/21 19:50:35 tom Exp $
+ *
+ *  fselect.c -- implements the file-selector box
+ *
+ *  Copyright 2000-2020,2021	Thomas E. Dickey
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License, version 2.1
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to
+ *	Free Software Foundation, Inc.
+ *	51 Franklin St., Fifth Floor
+ *	Boston, MA 02110, USA.
+ */
+
+#include <dlg_internals.h>
+#include <dlg_keys.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
+
+# if defined(_FILE_OFFSET_BITS) && defined(HAVE_STRUCT_DIRENT64)
+#  if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
+#   define      DIRENT  struct dirent64
+#  else
+#   define      DIRENT  struct dirent
+#  endif
+# else
+#  define       DIRENT  struct dirent
+# endif
+
+#define EXT_WIDE 1
+#define HDR_HIGH 1
+#define BTN_HIGH (1 + 2 * MARGIN)	/* Ok/Cancel, also input-box */
+#define MIN_HIGH (HDR_HIGH - MARGIN + (BTN_HIGH * 2) + 4 * MARGIN)
+#define MIN_WIDE (2 * MAX(dlg_count_columns(d_label), dlg_count_columns(f_label)) + 6 * MARGIN + 2 * EXT_WIDE)
+
+#define MOUSE_D (KEY_MAX + 0)
+#define MOUSE_F (KEY_MAX + 10000)
+#define MOUSE_T (KEY_MAX + 20000)
+
+typedef enum {
+    sDIRS = -3
+    ,sFILES = -2
+    ,sTEXT = -1
+} STATES;
+
+typedef struct {
+    WINDOW *par;		/* parent window */
+    WINDOW *win;		/* this window */
+    int length;			/* length of the data[] array */
+    int offset;			/* index of first item on screen */
+    int choice;			/* index of the selection */
+    int mousex;			/* base of mouse-code return-values */
+    unsigned allocd;
+    char **data;
+} LIST;
+
+typedef struct {
+    int length;
+    char **data;
+} MATCH;
+
+static void
+init_list(LIST * list, WINDOW *par, WINDOW *win, int mousex)
+{
+    list->par = par;
+    list->win = win;
+    list->length = 0;
+    list->offset = 0;
+    list->choice = 0;
+    list->mousex = mousex;
+    list->allocd = 0;
+    list->data = 0;
+    dlg_mouse_mkbigregion(getbegy(win), getbegx(win),
+			  getmaxy(win), getmaxx(win),
+			  mousex, 1, 1, 1 /* by lines */ );
+}
+
+static char *
+leaf_of(char *path)
+{
+    char *leaf = strrchr(path, '/');
+    if (leaf != 0)
+	leaf++;
+    else
+	leaf = path;
+    return leaf;
+}
+
+static char *
+data_of(LIST * list)
+{
+    if (list != 0
+	&& list->data != 0)
+	return list->data[list->choice];
+    return 0;
+}
+
+static void
+free_list(LIST * list, int reinit)
+{
+    if (list->data != 0) {
+	int n;
+
+	for (n = 0; list->data[n] != 0; n++)
+	    free(list->data[n]);
+	free(list->data);
+	list->data = 0;
+    }
+    if (reinit)
+	init_list(list, list->par, list->win, list->mousex);
+}
+
+static void
+add_to_list(LIST * list, char *text)
+{
+    unsigned need;
+
+    need = (unsigned) (list->length + 1);
+    if (need + 1 > list->allocd) {
+	list->allocd = 2 * (need + 1);
+	if (list->data == 0) {
+	    list->data = dlg_malloc(char *, list->allocd);
+	} else {
+	    list->data = dlg_realloc(char *, list->allocd, list->data);
+	}
+	assert_ptr(list->data, "add_to_list");
+    }
+    list->data[list->length++] = dlg_strclone(text);
+    list->data[list->length] = 0;
+}
+
+static void
+keep_visible(LIST * list)
+{
+    int high = getmaxy(list->win);
+
+    if (list->choice < list->offset) {
+	list->offset = list->choice;
+    }
+    if (list->choice - list->offset >= high)
+	list->offset = list->choice - high + 1;
+}
+
+#define Value(c) (int)((c) & 0xff)
+
+static int
+find_choice(char *target, LIST * list)
+{
+    int choice = list->choice;
+
+    if (*target == 0) {
+	list->choice = 0;
+    } else {
+	int n;
+	int len_1, cmp_1;
+
+	/* find the match with the longest length.  If more than one has the
+	 * same length, choose the one with the closest match of the final
+	 * character.
+	 */
+	len_1 = 0;
+	cmp_1 = 256;
+	for (n = 0; n < list->length; n++) {
+	    char *a = target;
+	    char *b = list->data[n];
+	    int len_2, cmp_2;
+
+	    len_2 = 0;
+	    while ((*a != 0) && (*b != 0) && (*a == *b)) {
+		a++;
+		b++;
+		len_2++;
+	    }
+	    cmp_2 = Value(*a) - Value(*b);
+	    if (cmp_2 < 0)
+		cmp_2 = -cmp_2;
+	    if ((len_2 > len_1)
+		|| (len_1 == len_2 && cmp_2 < cmp_1)) {
+		len_1 = len_2;
+		cmp_1 = cmp_2;
+		list->choice = n;
+	    }
+	}
+    }
+    if (choice != list->choice) {
+	keep_visible(list);
+    }
+    return (choice != list->choice);
+}
+
+static void
+display_list(LIST * list)
+{
+    if (list->win != 0) {
+	int n;
+	int x;
+	int y;
+	int top;
+	int bottom;
+
+	dlg_attr_clear(list->win, getmaxy(list->win), getmaxx(list->win), item_attr);
+	for (n = list->offset; n < list->length && list->data[n]; n++) {
+	    y = n - list->offset;
+	    if (y >= getmaxy(list->win))
+		break;
+	    (void) wmove(list->win, y, 0);
+	    if (n == list->choice)
+		dlg_attrset(list->win, item_selected_attr);
+	    (void) waddstr(list->win, list->data[n]);
+	    dlg_attrset(list->win, item_attr);
+	}
+	dlg_attrset(list->win, item_attr);
+
+	getparyx(list->win, y, x);
+
+	top = y - 1;
+	bottom = y + getmaxy(list->win);
+	dlg_draw_scrollbar(list->par,
+			   (long) list->offset,
+			   (long) list->offset,
+			   (long) (list->offset + getmaxy(list->win)),
+			   (long) (list->length),
+			   x + 1,
+			   x + getmaxx(list->win),
+			   top,
+			   bottom,
+			   menubox_border2_attr,
+			   menubox_border_attr);
+
+	(void) wmove(list->win, list->choice - list->offset, 0);
+	(void) wnoutrefresh(list->win);
+    }
+}
+
+/* FIXME: see arrows.c
+ * This workaround is used to allow two lists to have scroll-tabs at the same
+ * time, by reassigning their return-values to be different.  Just for
+ * readability, we use the names of keys with similar connotations, though all
+ * that is really required is that they're distinct, so we can put them in a
+ * switch statement.
+ */
+#if USE_MOUSE
+static void
+fix_arrows(LIST * list)
+{
+    if (list->win != 0) {
+	int x;
+	int y;
+	int top;
+	int right;
+	int bottom;
+
+	getparyx(list->win, y, x);
+	top = y - 1;
+	right = getmaxx(list->win);
+	bottom = y + getmaxy(list->win);
+
+	mouse_mkbutton(top, x, right,
+		       ((list->mousex == MOUSE_D)
+			? KEY_PREVIOUS
+			: KEY_PPAGE));
+	mouse_mkbutton(bottom, x, right,
+		       ((list->mousex == MOUSE_D)
+			? KEY_NEXT
+			: KEY_NPAGE));
+    }
+}
+
+#else
+#define fix_arrows(list)	/* nothing */
+#endif
+
+static bool
+show_list(char *target, LIST * list, bool keep)
+{
+    bool changed = keep || find_choice(target, list);
+    display_list(list);
+    return changed;
+}
+
+/*
+ * Highlight the closest match to 'target' in the given list, setting offset
+ * to match.
+ */
+static bool
+show_both_lists(char *input, LIST * d_list, LIST * f_list, bool keep)
+{
+    char *leaf = leaf_of(input);
+
+    return show_list(leaf, d_list, keep) || show_list(leaf, f_list, keep);
+}
+
+/*
+ * Move up/down in the given list
+ */
+static bool
+change_list(int choice, LIST * list)
+{
+    if (data_of(list) != 0) {
+	int last = list->length - 1;
+
+	choice += list->choice;
+	if (choice < 0)
+	    choice = 0;
+	if (choice > last)
+	    choice = last;
+	list->choice = choice;
+	keep_visible(list);
+	display_list(list);
+	return TRUE;
+    }
+    return FALSE;
+}
+
+static void
+scroll_list(int direction, LIST * list)
+{
+    if (data_of(list) != 0) {
+	int length = getmaxy(list->win);
+	if (change_list(direction * length, list))
+	    return;
+    }
+    beep();
+}
+
+static int
+compar(const void *a, const void *b)
+{
+    return strcmp(*(const char *const *) a, *(const char *const *) b);
+}
+
+static void
+match(char *name, LIST * d_list, LIST * f_list, MATCH * match_list)
+{
+    char *test = leaf_of(name);
+    size_t test_len = strlen(test);
+    char **matches = dlg_malloc(char *, (size_t) (d_list->length + f_list->length));
+    size_t data_len = 0;
+
+    if (matches != 0) {
+	int i;
+	char **new_ptr;
+
+	for (i = 2; i < d_list->length; i++) {
+	    if (strncmp(test, d_list->data[i], test_len) == 0) {
+		matches[data_len++] = d_list->data[i];
+	    }
+	}
+	for (i = 0; i < f_list->length; i++) {
+	    if (strncmp(test, f_list->data[i], test_len) == 0) {
+		matches[data_len++] = f_list->data[i];
+	    }
+	}
+	if ((new_ptr = dlg_realloc(char *, data_len + 1, matches)) != 0) {
+	    matches = new_ptr;
+	} else {
+	    free(matches);
+	    matches = 0;
+	    data_len = 0;
+	}
+    }
+    match_list->data = matches;
+    match_list->length = (int) data_len;
+}
+
+static void
+free_match(MATCH * match_list)
+{
+    free(match_list->data);
+    match_list->length = 0;
+}
+
+static int
+complete(char *name, LIST * d_list, LIST * f_list, char **buff_ptr)
+{
+    MATCH match_list;
+    char *test;
+    size_t test_len;
+    size_t i;
+    char *buff;
+
+    match(name, d_list, f_list, &match_list);
+    if (match_list.length == 0) {
+	free(match_list.data);
+	*buff_ptr = NULL;
+	return 0;
+    }
+
+    test = match_list.data[0];
+    test_len = strlen(test);
+    buff = dlg_malloc(char, test_len + 2);
+    if (match_list.length == 1) {
+	strcpy(buff, test);
+	i = test_len;
+	if (test == data_of(d_list)) {
+	    buff[test_len] = '/';
+	    i++;
+	}
+    } else {
+	int j;
+	char *next;
+
+	for (i = 0; i < test_len; i++) {
+	    char test_char = test[i];
+	    if (test_char == '\0')
+		break;
+	    for (j = 0; j < match_list.length; j++) {
+		if (match_list.data[j][i] != test_char) {
+		    break;
+		}
+	    }
+	    if (j == match_list.length) {
+		(buff)[i] = test_char;
+	    } else
+		break;
+	}
+	next = dlg_realloc(char, i + 1, buff);
+	if (next == NULL) {
+	    free(buff);
+	    *buff_ptr = NULL;
+	    return 0;
+	}
+	buff = next;
+    }
+    free_match(&match_list);
+    buff[i] = '\0';
+    *buff_ptr = buff;
+    return (i != 0);
+}
+
+static bool
+fill_lists(char *current, char *input, LIST * d_list, LIST * f_list, bool keep)
+{
+    bool result = TRUE;
+    bool rescan = FALSE;
+    struct stat sb;
+    int n;
+    char path[MAX_LEN + 1];
+
+    /* check if we've updated the lists */
+    for (n = 0; current[n] && input[n]; n++) {
+	if (current[n] != input[n])
+	    break;
+    }
+
+    if (current[n] == input[n]) {
+	result = FALSE;
+	rescan = (n == 0 && d_list->length == 0);
+    } else if (strchr(current + n, '/') == 0
+	       && strchr(input + n, '/') == 0) {
+	result = show_both_lists(input, d_list, f_list, keep);
+    } else {
+	rescan = TRUE;
+    }
+
+    if (rescan) {
+	DIR *dp;
+	size_t have = strlen(input);
+	char *leaf;
+
+	if (have > MAX_LEN)
+	    have = MAX_LEN;
+	memcpy(current, input, have);
+	current[have] = '\0';
+
+	/* refill the lists */
+	free_list(d_list, TRUE);
+	free_list(f_list, TRUE);
+	memcpy(path, current, have);
+	path[have] = '\0';
+	if ((leaf = strrchr(path, '/')) != 0) {
+	    *++leaf = 0;
+	} else {
+	    strcpy(path, "./");
+	    leaf = path + strlen(path);
+	}
+	DLG_TRACE(("opendir '%s'\n", path));
+	if ((dp = opendir(path)) != 0) {
+	    DIRENT *de;
+
+	    while ((de = readdir(dp)) != 0) {
+		size_t len = NAMLEN(de);
+		if (len == 0 || (len + have + 2) >= MAX_LEN)
+		    continue;
+		memcpy(leaf, de->d_name, len);
+		leaf[len] = '\0';
+		if (stat(path, &sb) == 0) {
+		    if ((sb.st_mode & S_IFMT) == S_IFDIR)
+			add_to_list(d_list, leaf);
+		    else if (f_list->win)
+			add_to_list(f_list, leaf);
+		}
+	    }
+	    (void) closedir(dp);
+	    /* sort the lists */
+	    if (d_list->data != 0 && d_list->length > 1) {
+		qsort(d_list->data,
+		      (size_t) d_list->length,
+		      sizeof(d_list->data[0]),
+		      compar);
+	    }
+	    if (f_list->data != 0 && f_list->length > 1) {
+		qsort(f_list->data,
+		      (size_t) f_list->length,
+		      sizeof(f_list->data[0]),
+		      compar);
+	    }
+	}
+
+	(void) show_both_lists(input, d_list, f_list, FALSE);
+	d_list->offset = d_list->choice;
+	f_list->offset = f_list->choice;
+	result = TRUE;
+    }
+    return result;
+}
+
+static bool
+usable_state(int state, LIST * dirs, LIST * files)
+{
+    bool result;
+
+    switch (state) {
+    case sDIRS:
+	result = (dirs->win != 0) && (data_of(dirs) != 0);
+	break;
+    case sFILES:
+	result = (files->win != 0) && (data_of(files) != 0);
+	break;
+    default:
+	result = TRUE;
+	break;
+    }
+    return result;
+}
+
+#define which_list() ((state == sFILES) \
+			? &f_list \
+			: ((state == sDIRS) \
+			  ? &d_list \
+			  : 0))
+#define NAVIGATE_BINDINGS \
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ), \
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ), \
+	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ), \
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,  KEY_DOWN ), \
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,  CHR_NEXT ), \
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,  KEY_NEXT ), \
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,  CHR_PREVIOUS ), \
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,  KEY_UP ), \
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,  KEY_NPAGE ), \
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,  KEY_PPAGE )
+
+/*
+ * Display a dialog box for entering a filename
+ */
+static int
+dlg_fselect(const char *title, const char *path, int height, int width, int dselect)
+{
+    /* *INDENT-OFF* */
+    static DLG_KEYS_BINDING binding[] = {
+	HELPKEY_BINDINGS,
+	ENTERKEY_BINDINGS,
+	NAVIGATE_BINDINGS,
+	TOGGLEKEY_BINDINGS,
+	END_KEYS_BINDING
+    };
+    static DLG_KEYS_BINDING binding2[] = {
+	INPUTSTR_BINDINGS,
+	HELPKEY_BINDINGS,
+	ENTERKEY_BINDINGS,
+	NAVIGATE_BINDINGS,
+	TOGGLEKEY_BINDINGS,
+	END_KEYS_BINDING
+    };
+    /* *INDENT-ON* */
+
+#ifdef KEY_RESIZE
+    int old_height = height;
+    int old_width = width;
+    bool resized = FALSE;
+#endif
+    int tbox_y, tbox_x, tbox_width, tbox_height;
+    int dbox_y, dbox_x, dbox_width, dbox_height;
+    int fbox_y, fbox_x, fbox_width, fbox_height;
+    int show_buttons = TRUE;
+    int offset = 0;
+    int key = 0;
+    int fkey = FALSE;
+    int code;
+    int result = DLG_EXIT_UNKNOWN;
+    int state = dialog_vars.default_button >= 0 ? dlg_default_button() : sTEXT;
+    int button;
+    bool first = (state == sTEXT);
+    bool first_trace = TRUE;
+    char *input;
+    char *completed;
+    char current[MAX_LEN + 1];
+    WINDOW *dialog = 0;
+    WINDOW *w_text = 0;
+    WINDOW *w_work = 0;
+    const char **buttons = dlg_ok_labels();
+    const char *d_label = _("Directories");
+    const char *f_label = _("Files");
+    char *partial = 0;
+    int min_wide = MIN_WIDE;
+    int min_items = height ? 0 : 4;
+    LIST d_list, f_list;
+
+    DLG_TRACE(("# %s args:\n", dselect ? "dselect" : "fselect"));
+    DLG_TRACE2S("title", title);
+    DLG_TRACE2S("path", path);
+    DLG_TRACE2N("height", height);
+    DLG_TRACE2N("width", width);
+
+    dlg_does_output();
+
+    /* Set up the initial value */
+    input = dlg_set_result(path);
+    offset = (int) strlen(input);
+    *current = 0;
+
+    dlg_button_layout(buttons, &min_wide);
+
+#ifdef KEY_RESIZE
+  retry:
+#endif
+    if (height > 0)
+	height += MIN_HIGH;
+    dlg_auto_size(title, "", &height, &width, MIN_HIGH + min_items, min_wide);
+
+    dlg_print_size(height, width);
+    dlg_ctl_size(height, width);
+
+    dialog = dlg_new_window(height + 1, width,
+			    dlg_box_y_ordinate(height),
+			    dlg_box_x_ordinate(width));
+    dlg_register_window(dialog, "fselect", binding);
+    dlg_register_buttons(dialog, "fselect", buttons);
+
+    dlg_mouse_setbase(0, 0);
+
+    dlg_draw_box2(dialog, 0, 0, height + 1, width, dialog_attr, border_attr, border2_attr);
+    dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
+    dlg_draw_title(dialog, title);
+
+    dlg_attrset(dialog, dialog_attr);
+
+    /* Draw the input field box */
+    tbox_height = 1;
+    tbox_width = width - (4 * MARGIN + 2);
+    tbox_y = height - (BTN_HIGH * 2) + MARGIN + 1;
+    tbox_x = (width - tbox_width) / 2;
+
+    w_text = dlg_der_window(dialog, tbox_height, tbox_width, tbox_y, tbox_x);
+    if (w_text == 0) {
+	result = DLG_EXIT_ERROR;
+	goto finish;
+    }
+
+    dlg_draw_box(dialog, tbox_y - MARGIN, tbox_x - MARGIN,
+		 (2 * MARGIN + 1), tbox_width + (MARGIN + EXT_WIDE),
+		 menubox_border_attr, menubox_border2_attr);
+    dlg_mouse_mkbigregion(getbegy(dialog) + tbox_y - MARGIN,
+			  getbegx(dialog) + tbox_x - MARGIN,
+			  1 + (2 * MARGIN),
+			  tbox_width + (MARGIN + EXT_WIDE),
+			  MOUSE_T, 1, 1, 3 /* doesn't matter */ );
+
+    dlg_register_window(w_text, "fselect2", binding2);
+
+    /* Draw the directory listing box */
+    if (dselect)
+	dbox_width = (width - (6 * MARGIN));
+    else
+	dbox_width = (width - (6 * MARGIN + 2 * EXT_WIDE)) / 2;
+    dbox_height = height - MIN_HIGH;
+    dbox_y = (2 * MARGIN + 2);
+    dbox_x = tbox_x;
+
+    w_work = dlg_der_window(dialog, dbox_height, dbox_width, dbox_y, dbox_x);
+    if (w_work == 0) {
+	result = DLG_EXIT_ERROR;
+	goto finish;
+    }
+
+    (void) mvwaddstr(dialog, dbox_y - (MARGIN + 1), dbox_x - MARGIN, d_label);
+    dlg_draw_box(dialog,
+		 dbox_y - MARGIN, dbox_x - MARGIN,
+		 dbox_height + (MARGIN + 1), dbox_width + (MARGIN + 1),
+		 menubox_border_attr, menubox_border2_attr);
+    init_list(&d_list, dialog, w_work, MOUSE_D);
+
+    if (!dselect) {
+	/* Draw the filename listing box */
+	fbox_height = dbox_height;
+	fbox_width = dbox_width;
+	fbox_y = dbox_y;
+	fbox_x = tbox_x + dbox_width + (2 * MARGIN);
+
+	w_work = dlg_der_window(dialog, fbox_height, fbox_width, fbox_y, fbox_x);
+	if (w_work == 0) {
+	    result = DLG_EXIT_ERROR;
+	    goto finish;
+	}
+
+	(void) mvwaddstr(dialog, fbox_y - (MARGIN + 1), fbox_x - MARGIN, f_label);
+	dlg_draw_box(dialog,
+		     fbox_y - MARGIN, fbox_x - MARGIN,
+		     fbox_height + (MARGIN + 1), fbox_width + (MARGIN + 1),
+		     menubox_border_attr, menubox_border2_attr);
+	init_list(&f_list, dialog, w_work, MOUSE_F);
+    } else {
+	memset(&f_list, 0, sizeof(f_list));
+    }
+
+    while (result == DLG_EXIT_UNKNOWN) {
+
+	if (fill_lists(current, input, &d_list, &f_list, state < sTEXT))
+	    show_buttons = TRUE;
+
+#ifdef KEY_RESIZE
+	if (resized) {
+	    resized = FALSE;
+	    dlg_show_string(w_text, input, offset, inputbox_attr,
+			    0, 0, tbox_width, FALSE, first);
+	}
+#endif
+
+	/*
+	 * The last field drawn determines where the cursor is shown:
+	 */
+	if (show_buttons) {
+	    show_buttons = FALSE;
+	    button = (state < 0) ? 0 : state;
+	    dlg_draw_buttons(dialog, height - 1, 0, buttons, button, FALSE, width);
+	}
+
+	if (first_trace) {
+	    first_trace = FALSE;
+	    dlg_trace_win(dialog);
+	}
+
+	if (state < 0) {
+	    switch (state) {
+	    case sTEXT:
+		dlg_set_focus(dialog, w_text);
+		break;
+	    case sFILES:
+		dlg_set_focus(dialog, f_list.win);
+		break;
+	    case sDIRS:
+		dlg_set_focus(dialog, d_list.win);
+		break;
+	    }
+	}
+
+	if (first) {
+	    (void) wrefresh(dialog);
+	} else {
+	    fix_arrows(&d_list);
+	    fix_arrows(&f_list);
+	    key = dlg_mouse_wgetch((state == sTEXT) ? w_text : dialog, &fkey);
+	    if (dlg_result_key(key, fkey, &result)) {
+		if (!dlg_button_key(result, &button, &key, &fkey))
+		    break;
+	    }
+	}
+
+	if (key == DLGK_TOGGLE) {
+	    key = DLGK_SELECT;
+	    fkey = TRUE;
+	}
+
+	if (fkey) {
+	    switch (key) {
+	    case DLGK_MOUSE(KEY_PREVIOUS):
+		state = sDIRS;
+		scroll_list(-1, which_list());
+		continue;
+	    case DLGK_MOUSE(KEY_NEXT):
+		state = sDIRS;
+		scroll_list(1, which_list());
+		continue;
+	    case DLGK_MOUSE(KEY_PPAGE):
+		state = sFILES;
+		scroll_list(-1, which_list());
+		continue;
+	    case DLGK_MOUSE(KEY_NPAGE):
+		state = sFILES;
+		scroll_list(1, which_list());
+		continue;
+	    case DLGK_PAGE_PREV:
+		scroll_list(-1, which_list());
+		continue;
+	    case DLGK_PAGE_NEXT:
+		scroll_list(1, which_list());
+		continue;
+	    case DLGK_ITEM_PREV:
+		if (change_list(-1, which_list()))
+		    continue;
+		/* FALLTHRU */
+	    case DLGK_FIELD_PREV:
+		show_buttons = TRUE;
+		do {
+		    state = dlg_prev_ok_buttonindex(state, sDIRS);
+		} while (!usable_state(state, &d_list, &f_list));
+		continue;
+	    case DLGK_ITEM_NEXT:
+		if (change_list(1, which_list()))
+		    continue;
+		/* FALLTHRU */
+	    case DLGK_FIELD_NEXT:
+		show_buttons = TRUE;
+		do {
+		    state = dlg_next_ok_buttonindex(state, sDIRS);
+		} while (!usable_state(state, &d_list, &f_list));
+		continue;
+	    case DLGK_SELECT:
+		completed = 0;
+		if (partial != 0) {
+		    free(partial);
+		    partial = 0;
+		}
+		if (state == sFILES && !dselect) {
+		    completed = data_of(&f_list);
+		} else if (state == sDIRS) {
+		    completed = data_of(&d_list);
+		} else {
+		    if (complete(input, &d_list, &f_list, &partial)) {
+			completed = partial;
+		    }
+		}
+		if (completed != 0) {
+		    state = sTEXT;
+		    show_buttons = TRUE;
+		    strcpy(leaf_of(input), completed);
+		    offset = (int) strlen(input);
+		    dlg_show_string(w_text, input, offset, inputbox_attr,
+				    0, 0, tbox_width, 0, first);
+		    if (partial != NULL) {
+			free(partial);
+			partial = 0;
+		    }
+		    continue;
+		} else {	/* if (state < sTEXT) */
+		    (void) beep();
+		    continue;
+		}
+		/* FALLTHRU */
+	    case DLGK_ENTER:
+		result = (state > 0) ? dlg_enter_buttoncode(state) : DLG_EXIT_OK;
+		continue;
+	    case DLGK_LEAVE:
+		if (state >= 0)
+		    result = dlg_ok_buttoncode(state);
+		break;
+#ifdef KEY_RESIZE
+	    case KEY_RESIZE:
+		dlg_will_resize(dialog);
+		/* reset data */
+		height = old_height;
+		width = old_width;
+		show_buttons = TRUE;
+		*current = 0;
+		resized = TRUE;
+		/* repaint */
+		free_list(&d_list, FALSE);
+		free_list(&f_list, FALSE);
+		_dlg_resize_cleanup(dialog);
+		goto retry;
+#endif
+	    default:
+		if (key >= DLGK_MOUSE(MOUSE_T)) {
+		    state = sTEXT;
+		    continue;
+		} else if (key >= DLGK_MOUSE(MOUSE_F)) {
+		    if (f_list.win != 0) {
+			state = sFILES;
+			f_list.choice = (key - DLGK_MOUSE(MOUSE_F)) + f_list.offset;
+			display_list(&f_list);
+		    }
+		    continue;
+		} else if (key >= DLGK_MOUSE(MOUSE_D)) {
+		    if (d_list.win != 0) {
+			state = sDIRS;
+			d_list.choice = (key - DLGK_MOUSE(MOUSE_D)) + d_list.offset;
+			display_list(&d_list);
+		    }
+		    continue;
+		} else if (is_DLGK_MOUSE(key)
+			   && (code = dlg_ok_buttoncode(key - M_EVENT)) >= 0) {
+		    result = code;
+		    continue;
+		}
+		break;
+	    }
+	}
+
+	if (state < 0) {	/* Input box selected if we're editing */
+	    int edit = dlg_edit_string(input, &offset, key, fkey, first);
+
+	    if (edit) {
+		dlg_show_string(w_text, input, offset, inputbox_attr,
+				0, 0, tbox_width, 0, first);
+		first = FALSE;
+		state = sTEXT;
+	    }
+	} else if ((code = dlg_char_to_button(key, buttons)) >= 0) {
+	    result = dlg_ok_buttoncode(code);
+	    break;
+	}
+    }
+    AddLastKey();
+
+    dlg_unregister_window(w_text);
+    dlg_del_window(dialog);
+    dlg_mouse_free_regions();
+    free_list(&d_list, FALSE);
+    free_list(&f_list, FALSE);
+
+  finish:
+    if (partial != 0)
+	free(partial);
+    return result;
+}
+
+/*
+ * Display a dialog box for entering a filename
+ */
+int
+dialog_fselect(const char *title, const char *path, int height, int width)
+{
+    return dlg_fselect(title, path, height, width, FALSE);
+}
+
+/*
+ * Display a dialog box for entering a directory
+ */
+int
+dialog_dselect(const char *title, const char *path, int height, int width)
+{
+    return dlg_fselect(title, path, height, width, TRUE);
+}
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/menubox.c
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/menubox.c	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/menubox.c	(revision 5)
@@ -0,0 +1,815 @@
+/*
+ *  $Id: menubox.c,v 1.171 2020/11/23 21:03:11 tom Exp $
+ *
+ *  menubox.c -- implements the menu box
+ *
+ *  Copyright 2000-2019,2020	Thomas E. Dickey
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public Licens, version 2.1e
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to
+ *	Free Software Foundation, Inc.
+ *	51 Franklin St., Fifth Floor
+ *	Boston, MA 02110, USA.
+ *
+ *  An earlier version of this program lists as authors
+ *	Savio Lam (lam836@cs.cuhk.hk)
+ */
+
+#include <dlg_internals.h>
+#include <dlg_keys.h>
+
+typedef enum {
+    Unselected = 0,
+    Selected,
+    Editing
+} Mode;
+
+typedef struct {
+    /* the outer-window */
+    WINDOW *dialog;
+    int box_y;
+    int box_x;
+    int tag_x;
+    int item_x;
+    int menu_height;
+    int menu_width;
+    /* the inner-window */
+    WINDOW *menu;
+    DIALOG_LISTITEM *items;
+    int item_no;
+} ALL_DATA;
+
+#define MIN_HIGH  4
+
+#define INPUT_ROWS     3	/* rows per inputmenu entry */
+
+#define RowHeight(i) (is_inputmenu ? ((i) * INPUT_ROWS) : ((i) * 1))
+#define ItemToRow(i) (is_inputmenu ? ((i) * INPUT_ROWS + 1) : (i))
+#define RowToItem(i) (is_inputmenu ? ((i) / INPUT_ROWS + 0) : (i))
+
+/*
+ * Print menu item
+ */
+static void
+print_item(ALL_DATA * data,
+	   WINDOW *win,
+	   DIALOG_LISTITEM * item,
+	   int choice,
+	   Mode selected,
+	   bool is_inputmenu)
+{
+    chtype save = dlg_get_attrs(win);
+    int climit = (data->item_x - data->tag_x - GUTTER);
+    int my_width = data->menu_width;
+    int my_x = data->item_x;
+    int my_y = ItemToRow(choice);
+    bool both = (!dialog_vars.no_tags && !dialog_vars.no_items);
+    bool first = TRUE;
+    chtype bordchar;
+    const char *show = (dialog_vars.no_items
+			? item->name
+			: item->text);
+
+    switch (selected) {
+    default:
+    case Unselected:
+	bordchar = item_attr;
+	break;
+    case Selected:
+	bordchar = item_selected_attr;
+	break;
+    case Editing:
+	bordchar = dialog_attr;
+	break;
+    }
+
+    /* Clear 'residue' of last item and mark current current item */
+    if (is_inputmenu) {
+	int n;
+
+	dlg_attrset(win, (selected != Unselected) ? item_selected_attr : item_attr);
+	for (n = my_y - 1; n < my_y + INPUT_ROWS - 1; n++) {
+	    wmove(win, n, 0);
+	    wprintw(win, "%*s", my_width, " ");
+	}
+    } else {
+	dlg_attrset(win, menubox_attr);
+	wmove(win, my_y, 0);
+	wprintw(win, "%*s", my_width, " ");
+    }
+
+    /* highlight first char of the tag to be special */
+    if (both) {
+	(void) wmove(win, my_y, data->tag_x);
+	dlg_print_listitem(win, item->name, climit, first, selected);
+	first = FALSE;
+    }
+
+    /* Draw the input field box (only for inputmenu) */
+    (void) wmove(win, my_y, my_x);
+    if (is_inputmenu) {
+	my_width -= 1;
+	dlg_draw_box(win, my_y - 1, my_x, INPUT_ROWS, my_width - my_x - data->tag_x,
+		     bordchar,
+		     bordchar);
+	my_width -= 1;
+	++my_x;
+    }
+
+    /* print actual item */
+    wmove(win, my_y, my_x);
+    dlg_print_listitem(win, show, my_width - my_x, first, selected);
+
+    if (selected) {
+	dlg_item_help(item->help);
+    }
+    dlg_attrset(win, save);
+}
+
+/*
+ * Allow the user to edit the text of a menu entry.
+ */
+static int
+input_menu_edit(ALL_DATA * data,
+		DIALOG_LISTITEM * items,
+		int choice,
+		char **resultp)
+{
+    chtype save = dlg_get_attrs(data->menu);
+    char *result;
+    int offset = 0;
+    int key = 0, fkey = 0;
+    bool first = TRUE;
+    /* see above */
+    bool is_inputmenu = TRUE;
+    int y = ItemToRow(choice);
+    int code = TRUE;
+    int max_len = dlg_max_input(MAX((int) strlen(items->text) + 1, MAX_LEN));
+
+    result = dlg_malloc(char, (size_t) max_len);
+    assert_ptr(result, "input_menu_edit");
+
+    /* original item is used to initialize the input string. */
+    result[0] = '\0';
+    strcpy(result, items->text);
+
+    print_item(data, data->menu, items, choice, Editing, TRUE);
+
+    /* taken out of inputbox.c - but somewhat modified */
+    for (;;) {
+	if (!first) {
+	    int check = DLG_EXIT_UNKNOWN;
+	    key = dlg_mouse_wgetch(data->menu, &fkey);
+	    if (dlg_result_key(key, fkey, &check)) {
+		if (check == DLG_EXIT_CANCEL) {
+		    code = FALSE;
+		    break;
+		} else {
+		    flash();
+		}
+	    }
+	}
+	if (dlg_edit_string(result, &offset, key, fkey, first)) {
+	    dlg_show_string(data->menu, result, offset, inputbox_attr,
+			    y,
+			    data->item_x + 1,
+			    data->menu_width - data->item_x - 3,
+			    FALSE, first);
+	    first = FALSE;
+	} else if (key == ESC || key == TAB) {
+	    code = FALSE;
+	    break;
+	} else {
+	    break;
+	}
+    }
+    print_item(data, data->menu, items, choice, Selected, TRUE);
+    dlg_attrset(data->menu, save);
+
+    *resultp = result;
+    return code;
+}
+
+static int
+handle_button(int code, DIALOG_LISTITEM * items, int choice)
+{
+    char *help_result;
+
+    switch (code) {
+    case DLG_EXIT_OK:		/* FALLTHRU */
+    case DLG_EXIT_EXTRA:
+	dlg_add_string(items[choice].name);
+	break;
+    case DLG_EXIT_HELP:
+	dlg_add_help_listitem(&code, &help_result, &items[choice]);
+	dlg_add_string(help_result);
+	break;
+    }
+    AddLastKey();
+    return code;
+}
+
+int
+dlg_renamed_menutext(DIALOG_LISTITEM * items, int current, char *newtext)
+{
+    if (dialog_vars.input_result)
+	dialog_vars.input_result[0] = '\0';
+    dlg_add_result("RENAMED ");
+    dlg_add_string(items[current].name);
+    dlg_add_result(" ");
+    dlg_add_string(newtext);
+    AddLastKey();
+    return DLG_EXIT_EXTRA;
+}
+
+int
+dlg_dummy_menutext(DIALOG_LISTITEM * items, int current, char *newtext)
+{
+    (void) items;
+    (void) current;
+    (void) newtext;
+    return DLG_EXIT_ERROR;
+}
+
+static void
+print_menu(ALL_DATA * data, int choice, int scrollamt, int max_choice, bool is_inputmenu)
+{
+    int i;
+
+    for (i = 0; i < max_choice; i++) {
+	print_item(data,
+		   data->menu,
+		   &data->items[i + scrollamt],
+		   i,
+		   (i == choice) ? Selected : Unselected,
+		   is_inputmenu);
+    }
+
+    /* Clean bottom lines */
+    if (is_inputmenu) {
+	int spare_lines, x_count;
+	spare_lines = data->menu_height % INPUT_ROWS;
+	dlg_attrset(data->menu, menubox_attr);
+	for (; spare_lines; spare_lines--) {
+	    wmove(data->menu, data->menu_height - spare_lines, 0);
+	    for (x_count = 0; x_count < data->menu_width;
+		 x_count++) {
+		waddch(data->menu, ' ');
+	    }
+	}
+    }
+
+    (void) wnoutrefresh(data->menu);
+
+    dlg_draw_scrollbar(data->dialog,
+		       scrollamt,
+		       scrollamt,
+		       scrollamt + max_choice,
+		       data->item_no,
+		       data->box_x,
+		       data->box_x + data->menu_width,
+		       data->box_y,
+		       data->box_y + data->menu_height + 1,
+		       menubox_border2_attr,
+		       menubox_border_attr);
+}
+
+static bool
+check_hotkey(DIALOG_LISTITEM * items, int choice)
+{
+    bool result = FALSE;
+
+    if (dlg_match_char(dlg_last_getc(),
+		       (dialog_vars.no_tags
+			? items[choice].text
+			: items[choice].name))) {
+	result = TRUE;
+    }
+    return result;
+}
+
+/*
+ * This is an alternate interface to 'menu' which allows the application
+ * to read the list item states back directly without putting them in the
+ * output buffer.
+ */
+int
+dlg_menu(const char *title,
+	 const char *cprompt,
+	 int height,
+	 int width,
+	 int menu_height,
+	 int item_no,
+	 DIALOG_LISTITEM * items,
+	 int *current_item,
+	 DIALOG_INPUTMENU rename_menutext)
+{
+    /* *INDENT-OFF* */
+    static DLG_KEYS_BINDING binding[] = {
+	HELPKEY_BINDINGS,
+	ENTERKEY_BINDINGS,
+	TOGGLEKEY_BINDINGS,
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT,	KEY_RIGHT ),
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT,	TAB ),
+	DLG_KEYS_DATA( DLGK_FIELD_PREV,	KEY_BTAB ),
+	DLG_KEYS_DATA( DLGK_FIELD_PREV,	KEY_LEFT ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	'+' ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	KEY_DOWN ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,  CHR_NEXT ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,	'-' ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,	KEY_UP ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,  CHR_PREVIOUS ),
+	DLG_KEYS_DATA( DLGK_PAGE_FIRST,	KEY_HOME ),
+	DLG_KEYS_DATA( DLGK_PAGE_LAST,	KEY_END ),
+	DLG_KEYS_DATA( DLGK_PAGE_LAST,	KEY_LL ),
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	KEY_NPAGE ),
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,	KEY_PPAGE ),
+	END_KEYS_BINDING
+    };
+    static DLG_KEYS_BINDING binding2[] = {
+	INPUTSTR_BINDINGS,
+	HELPKEY_BINDINGS,
+	ENTERKEY_BINDINGS,
+	END_KEYS_BINDING
+    };
+    /* *INDENT-ON* */
+
+#ifdef KEY_RESIZE
+    int old_LINES = LINES;
+    int old_COLS = COLS;
+    int old_height = height;
+    int old_width = width;
+#endif
+    ALL_DATA all;
+    int i, j, x, y, cur_x, cur_y;
+    int fkey;
+    int button = dialog_state.visit_items ? -1 : dlg_default_button();
+    int choice = dlg_default_listitem(items);
+    int result = DLG_EXIT_UNKNOWN;
+    int scrollamt = 0;
+    int max_choice;
+    int use_width, name_width, text_width, list_width;
+    WINDOW *dialog, *menu;
+    char *prompt = 0;
+    const char **buttons = dlg_ok_labels();
+    bool is_inputmenu = ((rename_menutext != 0)
+			 && (rename_menutext != dlg_dummy_menutext));
+
+    DLG_TRACE(("# menubox args:\n"));
+    DLG_TRACE2S("title", title);
+    DLG_TRACE2S("message", cprompt);
+    DLG_TRACE2N("height", height);
+    DLG_TRACE2N("width", width);
+    DLG_TRACE2N("lheight", menu_height);
+    DLG_TRACE2N("llength", item_no);
+    /* FIXME dump the items[][] too */
+    DLG_TRACE2N("rename", rename_menutext != 0);
+
+    dialog_state.plain_buttons = TRUE;
+
+    all.items = items;
+    all.item_no = item_no;
+
+    dlg_does_output();
+
+#ifdef KEY_RESIZE
+  retry:
+#endif
+
+    prompt = dlg_strclone(cprompt);
+    dlg_tab_correct_str(prompt);
+
+    all.menu_height = menu_height;
+    use_width = dlg_calc_list_width(item_no, items) + 10;
+    use_width = MAX(26, use_width);
+    if (all.menu_height == 0) {
+	/* calculate height without items (4) */
+	dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, use_width);
+	dlg_calc_listh(&height, &all.menu_height, item_no);
+    } else {
+	dlg_auto_size(title, prompt,
+		      &height, &width,
+		      MIN_HIGH + all.menu_height, use_width);
+    }
+    dlg_button_layout(buttons, &width);
+    dlg_print_size(height, width);
+    dlg_ctl_size(height, width);
+
+    x = dlg_box_x_ordinate(width);
+    y = dlg_box_y_ordinate(height);
+
+    dialog = dlg_new_window(height, width, y, x);
+    all.dialog = dialog;
+
+    dlg_register_window(dialog, "menubox", binding);
+    dlg_register_buttons(dialog, "menubox", buttons);
+
+    dlg_mouse_setbase(x, y);
+
+    dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
+    dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
+    dlg_draw_title(dialog, title);
+
+    dlg_attrset(dialog, dialog_attr);
+    dlg_print_autowrap(dialog, prompt, height, width);
+
+    all.menu_width = width - 6;
+    getyx(dialog, cur_y, cur_x);
+    all.box_y = cur_y + 1;
+    all.box_x = (width - all.menu_width) / 2 - 1;
+
+    /*
+     * After displaying the prompt, we know how much space we really have.
+     * Limit the list to avoid overwriting the ok-button.
+     */
+    if (all.menu_height + MIN_HIGH > height - cur_y)
+       all.menu_height = height - MIN_HIGH - cur_y;
+    if (all.menu_height <= 0)
+	all.menu_height = 1;
+
+    /* Find out maximal number of displayable items at once. */
+    max_choice = MIN(all.menu_height,
+		     RowHeight(item_no));
+    if (is_inputmenu)
+	max_choice /= INPUT_ROWS;
+
+    /* create new window for the menu */
+    menu = dlg_sub_window(dialog, all.menu_height, all.menu_width,
+			  y + all.box_y + 1,
+			  x + all.box_x + 1);
+    all.menu = menu;
+
+    dlg_register_window(menu, "menu", binding2);
+    dlg_register_buttons(menu, "menu", buttons);
+
+    /* draw a box around the menu items */
+    dlg_draw_box(dialog,
+		 all.box_y, all.box_x,
+		 all.menu_height + 2, all.menu_width + 2,
+		 menubox_border_attr, menubox_border2_attr);
+
+    name_width = 0;
+    text_width = 0;
+
+    /* Find length of longest item to center menu  *
+     * only if --menu was given, using --inputmenu *
+     * won't be centered.                         */
+    for (i = 0; i < item_no; i++) {
+	name_width = MAX(name_width, dlg_count_columns(items[i].name));
+	text_width = MAX(text_width, dlg_count_columns(items[i].text));
+    }
+
+    /* If the name+text is wider than the list is allowed, then truncate
+     * one or both of them.  If the name is no wider than 30% of the list,
+     * leave it intact.
+     *
+     * FIXME: the gutter width and name/list ratio should be configurable.
+     */
+    use_width = (all.menu_width - GUTTER);
+    if (dialog_vars.no_tags) {
+	list_width = MIN(use_width, text_width);
+    } else if (dialog_vars.no_items) {
+	list_width = MIN(use_width, name_width);
+    } else {
+	if (text_width >= 0
+	    && name_width >= 0
+	    && use_width > 0
+	    && text_width + name_width > use_width) {
+	    int need = (int) (0.30 * use_width);
+	    if (name_width > need) {
+		int want = (int) (use_width
+				  * ((double) name_width)
+				  / (text_width + name_width));
+		name_width = (want > need) ? want : need;
+	    }
+	    text_width = use_width - name_width;
+	}
+	list_width = (text_width + name_width);
+    }
+
+    all.tag_x = (is_inputmenu
+		 ? 0
+		 : (use_width - list_width) / 2);
+    all.item_x = ((dialog_vars.no_tags
+		   ? 0
+		   : (dialog_vars.no_items
+		      ? 0
+		      : (GUTTER + name_width)))
+		  + all.tag_x);
+
+    if (choice - scrollamt >= max_choice) {
+	scrollamt = choice - (max_choice - 1);
+	choice = max_choice - 1;
+    }
+
+    print_menu(&all, choice, scrollamt, max_choice, is_inputmenu);
+
+    /* register the new window, along with its borders */
+    dlg_mouse_mkbigregion(all.box_y + 1, all.box_x,
+			  all.menu_height + 2, all.menu_width + 2,
+			  KEY_MAX, 1, 1, 1 /* by lines */ );
+
+    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
+
+    dlg_trace_win(dialog);
+
+    while (result == DLG_EXIT_UNKNOWN) {
+	int key, found;
+
+	if (button < 0)		/* --visit-items */
+	    wmove(dialog,
+		  all.box_y + ItemToRow(choice) + 1,
+		  all.box_x + all.tag_x + 1);
+
+	key = dlg_mouse_wgetch(dialog, &fkey);
+	if (dlg_result_key(key, fkey, &result)) {
+	    if (!dlg_button_key(result, &button, &key, &fkey))
+		break;
+	}
+
+	found = FALSE;
+	if (fkey) {
+	    /*
+	     * Allow a mouse-click on a box to switch selection to that box.
+	     * Handling a button click is a little more complicated, since we
+	     * push a KEY_ENTER back onto the input stream so we'll put the
+	     * cursor at the right place before handling the "keypress".
+	     */
+	    if (key >= DLGK_MOUSE(KEY_MAX)) {
+		key -= DLGK_MOUSE(KEY_MAX);
+		i = RowToItem(key);
+		if (i < max_choice) {
+		    found = TRUE;
+		} else {
+		    beep();
+		    continue;
+		}
+	    } else if (is_DLGK_MOUSE(key)
+		       && dlg_ok_buttoncode(key - M_EVENT) >= 0) {
+		button = (key - M_EVENT);
+		ungetch('\n');
+		continue;
+	    }
+	} else {
+	    /*
+	     * Check if key pressed matches first character of any item tag in
+	     * list.  If there is more than one match, we will cycle through
+	     * each one as the same key is pressed repeatedly.
+	     */
+	    if (button < 0 || !dialog_state.visit_items) {
+		for (j = scrollamt + choice + 1; j < item_no; j++) {
+		    if (check_hotkey(items, j)) {
+			found = TRUE;
+			i = j - scrollamt;
+			break;
+		    }
+		}
+		if (!found) {
+		    for (j = 0; j <= scrollamt + choice; j++) {
+			if (check_hotkey(items, j)) {
+			    found = TRUE;
+			    i = j - scrollamt;
+			    break;
+			}
+		    }
+		}
+		if (found)
+		    dlg_flush_getc();
+	    } else if ((j = dlg_char_to_button(key, buttons)) >= 0) {
+		button = j;
+		ungetch('\n');
+		continue;
+	    }
+
+	    /*
+	     * A single digit (1-9) positions the selection to that line in the
+	     * current screen.
+	     */
+	    if (!found
+		&& (key <= '9')
+		&& (key > '0')
+		&& (key - '1' < max_choice)) {
+		found = TRUE;
+		i = key - '1';
+	    }
+	}
+
+	if (!found && fkey) {
+	    found = TRUE;
+	    switch (key) {
+	    case DLGK_PAGE_FIRST:
+		i = -scrollamt;
+		break;
+	    case DLGK_PAGE_LAST:
+		i = item_no - 1 - scrollamt;
+		break;
+	    case DLGK_MOUSE(KEY_PPAGE):
+	    case DLGK_PAGE_PREV:
+		if (choice)
+		    i = 0;
+		else if (scrollamt != 0)
+		    i = -MIN(scrollamt, max_choice);
+		else
+		    continue;
+		break;
+	    case DLGK_MOUSE(KEY_NPAGE):
+	    case DLGK_PAGE_NEXT:
+		i = MIN(choice + max_choice, item_no - scrollamt - 1);
+		break;
+	    case DLGK_ITEM_PREV:
+		i = choice - 1;
+		if (choice == 0 && scrollamt == 0)
+		    continue;
+		break;
+	    case DLGK_ITEM_NEXT:
+		i = choice + 1;
+		if (scrollamt + choice >= item_no - 1)
+		    continue;
+		break;
+	    default:
+		found = FALSE;
+		break;
+	    }
+	}
+
+	if (found) {
+	    if (i != choice) {
+		getyx(dialog, cur_y, cur_x);
+		if (i < 0 || i >= max_choice) {
+		    if (i < 0) {
+			scrollamt += i;
+			choice = 0;
+		    } else {
+			choice = max_choice - 1;
+			scrollamt += (i - max_choice + 1);
+		    }
+		    print_menu(&all, choice, scrollamt, max_choice, is_inputmenu);
+		} else {
+		    choice = i;
+		    print_menu(&all, choice, scrollamt, max_choice, is_inputmenu);
+		    (void) wmove(dialog, cur_y, cur_x);
+		    wrefresh(dialog);
+		}
+	    }
+	    continue;		/* wait for another key press */
+	}
+
+	if (fkey) {
+	    switch (key) {
+	    case DLGK_FIELD_PREV:
+		button = dlg_prev_button(buttons, button);
+		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
+				 FALSE, width);
+		break;
+
+	    case DLGK_FIELD_NEXT:
+		button = dlg_next_button(buttons, button);
+		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
+				 FALSE, width);
+		break;
+
+	    case DLGK_TOGGLE:
+	    case DLGK_ENTER:
+	    case DLGK_LEAVE:
+		result = ((key == DLGK_LEAVE)
+			  ? dlg_ok_buttoncode(button)
+			  : dlg_enter_buttoncode(button));
+
+		/*
+		 * If dlg_menu() is called from dialog_menu(), we want to
+		 * capture the results into dialog_vars.input_result.
+		 */
+		if (result == DLG_EXIT_ERROR) {
+		    result = DLG_EXIT_UNKNOWN;
+		} else if (is_inputmenu
+			   || rename_menutext == dlg_dummy_menutext) {
+		    result = handle_button(result,
+					   items,
+					   scrollamt + choice);
+		}
+
+		/*
+		 * If we have a rename_menutext function, interpret the Extra
+		 * button as a request to rename the menu's text.  If that
+		 * function doesn't return "Unknown", we will exit from this
+		 * function.  Usually that is done for dialog_menu(), so the
+		 * shell script can use the updated value.  If it does return
+		 * "Unknown", update the list item only.  A direct caller of
+		 * dlg_menu() can free the renamed value - we cannot.
+		 */
+		if (is_inputmenu && result == DLG_EXIT_EXTRA) {
+		    char *tmp;
+
+		    if (input_menu_edit(&all,
+					&items[scrollamt + choice],
+					choice,
+					&tmp)) {
+			result = rename_menutext(items, scrollamt + choice, tmp);
+			if (result == DLG_EXIT_UNKNOWN) {
+			    items[scrollamt + choice].text = tmp;
+			} else {
+			    free(tmp);
+			}
+		    } else {
+			result = DLG_EXIT_UNKNOWN;
+			print_item(&all,
+				   menu,
+				   &items[scrollamt + choice],
+				   choice,
+				   Selected,
+				   is_inputmenu);
+			(void) wnoutrefresh(menu);
+			free(tmp);
+		    }
+
+		    if (result == DLG_EXIT_UNKNOWN) {
+			dlg_draw_buttons(dialog, height - 2, 0,
+					 buttons, button, FALSE, width);
+		    }
+		}
+		break;
+#ifdef KEY_RESIZE
+	    case KEY_RESIZE:
+		dlg_will_resize(dialog);
+		/* reset data */
+		resizeit(height, LINES);
+		resizeit(width, COLS);
+		free(prompt);
+		_dlg_resize_cleanup(dialog);
+		/* repaint */
+		goto retry;
+#endif
+	    default:
+		flash();
+		break;
+	    }
+	}
+    }
+
+    dlg_mouse_free_regions();
+    dlg_unregister_window(menu);
+    dlg_del_window(dialog);
+    free(prompt);
+
+    *current_item = scrollamt + choice;
+
+    DLG_TRACE2N("current", *current_item);
+    return result;
+}
+
+/*
+ * Display a menu for choosing among a number of options
+ */
+int
+dialog_menu(const char *title,
+	    const char *cprompt,
+	    int height,
+	    int width,
+	    int menu_height,
+	    int item_no,
+	    char **items)
+{
+    int result;
+    int choice;
+    int i, j;
+    DIALOG_LISTITEM *listitems;
+
+    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
+    assert_ptr(listitems, "dialog_menu");
+
+    for (i = j = 0; i < item_no; ++i) {
+	listitems[i].name = items[j++];
+	listitems[i].text = (dialog_vars.no_items
+			     ? dlg_strempty()
+			     : items[j++]);
+	listitems[i].help = ((dialog_vars.item_help)
+			     ? items[j++]
+			     : dlg_strempty());
+    }
+    dlg_align_columns(&listitems[0].text, sizeof(DIALOG_LISTITEM), item_no);
+
+    result = dlg_menu(title,
+		      cprompt,
+		      height,
+		      width,
+		      menu_height,
+		      item_no,
+		      listitems,
+		      &choice,
+		      (dialog_vars.input_menu
+		       ? dlg_renamed_menutext
+		       : dlg_dummy_menutext));
+
+    dlg_free_columns(&listitems[0].text, sizeof(DIALOG_LISTITEM), item_no);
+    free(listitems);
+    return result;
+}
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/treeview.c
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/treeview.c	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/treeview.c	(revision 5)
@@ -0,0 +1,675 @@
+/*
+ *  $Id: treeview.c,v 1.43 2020/11/23 00:38:31 tom Exp $
+ *
+ *  treeview.c -- implements the treeview dialog
+ *
+ *  Copyright 2012-2019,2020	Thomas E. Dickey
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License, version 2.1
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to
+ *	Free Software Foundation, Inc.
+ *	51 Franklin St., Fifth Floor
+ *	Boston, MA 02110, USA.
+ */
+
+#include <dlg_internals.h>
+#include <dlg_keys.h>
+
+#define INDENT 3
+#define MIN_HIGH  (1 + (5 * MARGIN))
+
+typedef struct {
+    /* the outer-window */
+    WINDOW *dialog;
+    bool is_check;
+    int box_y;
+    int box_x;
+    int check_x;
+    int item_x;
+    int use_height;
+    int use_width;
+    /* the inner-window */
+    WINDOW *list;
+    DIALOG_LISTITEM *items;
+    int item_no;
+    int *depths;
+    const char *states;
+} ALL_DATA;
+
+/*
+ * Print list item.  The 'selected' parameter is true if 'choice' is the
+ * current item.  That one is colored differently from the other items.
+ */
+static void
+print_item(ALL_DATA * data,
+	   DIALOG_LISTITEM * item,
+	   const char *states,
+	   int depths,
+	   int choice,
+	   int selected)
+{
+    WINDOW *win = data->list;
+    chtype save = dlg_get_attrs(win);
+    int i;
+    bool first = TRUE;
+    int climit = (getmaxx(win) - data->check_x + 1);
+    const char *show = (dialog_vars.no_items
+			? item->name
+			: item->text);
+
+    /* Clear 'residue' of last item */
+    dlg_attrset(win, menubox_attr);
+    (void) wmove(win, choice, 0);
+    for (i = 0; i < data->use_width; i++)
+	(void) waddch(win, ' ');
+
+    (void) wmove(win, choice, data->check_x);
+    dlg_attrset(win, selected ? check_selected_attr : check_attr);
+    (void) wprintw(win,
+		   data->is_check ? "[%c]" : "(%c)",
+		   states[item->state]);
+    dlg_attrset(win, menubox_attr);
+
+    dlg_attrset(win, selected ? item_selected_attr : item_attr);
+    for (i = 0; i < depths; ++i) {
+	int j;
+	(void) wmove(win, choice, data->item_x + INDENT * i);
+	(void) waddch(win, ACS_VLINE);
+	for (j = INDENT - 1; j > 0; --j)
+	    (void) waddch(win, ' ');
+    }
+    (void) wmove(win, choice, data->item_x + INDENT * depths);
+
+    dlg_print_listitem(win, show, climit, first, selected);
+
+    if (selected) {
+	dlg_item_help(item->help);
+    }
+    dlg_attrset(win, save);
+}
+
+static void
+print_list(ALL_DATA * data,
+	   int choice,
+	   int scrollamt,
+	   int max_choice)
+{
+    int i;
+    int cur_y, cur_x;
+
+    getyx(data->dialog, cur_y, cur_x);
+
+    for (i = 0; i < max_choice; i++) {
+	print_item(data,
+		   &data->items[scrollamt + i],
+		   data->states,
+		   data->depths[scrollamt + i],
+		   i, i == choice);
+    }
+    (void) wnoutrefresh(data->list);
+
+    dlg_draw_scrollbar(data->dialog,
+		       (long) (scrollamt),
+		       (long) (scrollamt),
+		       (long) (scrollamt + max_choice),
+		       (long) (data->item_no),
+		       data->box_x + data->check_x,
+		       data->box_x + data->use_width,
+		       data->box_y,
+		       data->box_y + data->use_height + 1,
+		       menubox_border2_attr,
+		       menubox_border_attr);
+
+    (void) wmove(data->dialog, cur_y, cur_x);
+}
+
+static bool
+check_hotkey(DIALOG_LISTITEM * items, int choice)
+{
+    bool result = FALSE;
+
+    if (dlg_match_char(dlg_last_getc(),
+		       (dialog_vars.no_tags
+			? items[choice].text
+			: items[choice].name))) {
+	result = TRUE;
+    }
+    return result;
+}
+
+/*
+ * This is an alternate interface to 'treeview' which allows the application
+ * to read the list item states back directly without putting them in the
+ * output buffer.
+ */
+int
+dlg_treeview(const char *title,
+	     const char *cprompt,
+	     int height,
+	     int width,
+	     int list_height,
+	     int item_no,
+	     DIALOG_LISTITEM * items,
+	     const char *states,
+	     int *depths,
+	     int flag,
+	     int *current_item)
+{
+    /* *INDENT-OFF* */
+    static DLG_KEYS_BINDING binding[] = {
+	HELPKEY_BINDINGS,
+	ENTERKEY_BINDINGS,
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
+	DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
+	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
+	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
+	DLG_KEYS_DATA( DLGK_ITEM_FIRST, KEY_HOME ),
+	DLG_KEYS_DATA( DLGK_ITEM_LAST,	KEY_END ),
+	DLG_KEYS_DATA( DLGK_ITEM_LAST,	KEY_LL ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	'+' ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	KEY_DOWN ),
+	DLG_KEYS_DATA( DLGK_ITEM_NEXT,  CHR_NEXT ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,	'-' ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,	KEY_UP ),
+	DLG_KEYS_DATA( DLGK_ITEM_PREV,  CHR_PREVIOUS ),
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	KEY_NPAGE ),
+	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	DLGK_MOUSE(KEY_NPAGE) ),
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,	KEY_PPAGE ),
+	DLG_KEYS_DATA( DLGK_PAGE_PREV,	DLGK_MOUSE(KEY_PPAGE) ),
+	TOGGLEKEY_BINDINGS,
+	END_KEYS_BINDING
+    };
+    /* *INDENT-ON* */
+
+#ifdef KEY_RESIZE
+    int old_height = height;
+    int old_width = width;
+#endif
+    ALL_DATA all;
+    int i, j, key2, found, x, y, cur_y, box_x, box_y;
+    int key, fkey;
+    int button = dialog_state.visit_items ? -1 : dlg_default_button();
+    int choice = dlg_default_listitem(items);
+    int scrollamt = 0;
+    int max_choice;
+    int use_height;
+    int use_width, name_width, text_width, tree_width;
+    int result = DLG_EXIT_UNKNOWN;
+    int num_states;
+    WINDOW *dialog, *list;
+    char *prompt = dlg_strclone(cprompt);
+    const char **buttons = dlg_ok_labels();
+    const char *widget_name;
+
+    /* we need at least two states */
+    if (states == 0 || strlen(states) < 2)
+	states = " *";
+    num_states = (int) strlen(states);
+
+    dialog_state.plain_buttons = TRUE;
+
+    memset(&all, 0, sizeof(all));
+    all.items = items;
+    all.item_no = item_no;
+    all.states = states;
+    all.depths = depths;
+
+    dlg_does_output();
+    dlg_tab_correct_str(prompt);
+
+    /*
+     * If this is a radiobutton list, ensure that no more than one item is
+     * selected initially.  Allow none to be selected, since some users may
+     * wish to provide this flavor.
+     */
+    if (flag == FLAG_RADIO) {
+	bool first = TRUE;
+
+	for (i = 0; i < item_no; i++) {
+	    if (items[i].state) {
+		if (first) {
+		    first = FALSE;
+		} else {
+		    items[i].state = 0;
+		}
+	    }
+	}
+    } else {
+	all.is_check = TRUE;
+    }
+    widget_name = "treeview";
+#ifdef KEY_RESIZE
+  retry:
+#endif
+
+    use_height = list_height;
+    use_width = dlg_calc_list_width(item_no, items) + 10;
+    use_width = MAX(26, use_width);
+    if (use_height == 0) {
+	/* calculate height without items (4) */
+	dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, use_width);
+	dlg_calc_listh(&height, &use_height, item_no);
+    } else {
+	dlg_auto_size(title, prompt, &height, &width, MIN_HIGH + use_height, use_width);
+    }
+    dlg_button_layout(buttons, &width);
+    dlg_print_size(height, width);
+    dlg_ctl_size(height, width);
+
+    x = dlg_box_x_ordinate(width);
+    y = dlg_box_y_ordinate(height);
+
+    dialog = dlg_new_window(height, width, y, x);
+    dlg_register_window(dialog, widget_name, binding);
+    dlg_register_buttons(dialog, widget_name, buttons);
+
+    dlg_mouse_setbase(x, y);
+
+    dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
+    dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
+    dlg_draw_title(dialog, title);
+
+    dlg_attrset(dialog, dialog_attr);
+    dlg_print_autowrap(dialog, prompt, height, width);
+
+    all.use_width = width - 4;
+    cur_y = getcury(dialog);
+    box_y = cur_y + 1;
+    box_x = (width - all.use_width) / 2 - 1;
+
+    /*
+     * After displaying the prompt, we know how much space we really have.
+     * Limit the list to avoid overwriting the ok-button.
+     */
+    if (use_height + MIN_HIGH > height - cur_y)
+        use_height = height - MIN_HIGH - cur_y;
+    if (use_height <= 0)
+	use_height = 1;
+
+    max_choice = MIN(use_height, item_no);
+
+    /* create new window for the list */
+    list = dlg_sub_window(dialog, use_height, all.use_width,
+			  y + box_y + 1, x + box_x + 1);
+
+    /* draw a box around the list items */
+    dlg_draw_box(dialog, box_y, box_x,
+		 use_height + 2 * MARGIN,
+		 all.use_width + 2 * MARGIN,
+		 menubox_border_attr, menubox_border2_attr);
+
+    text_width = 0;
+    name_width = 0;
+    tree_width = 0;
+    /* Find length of longest item to center treeview */
+    for (i = 0; i < item_no; i++) {
+	tree_width = MAX(tree_width, INDENT * depths[i]);
+	text_width = MAX(text_width, dlg_count_columns(items[i].text));
+	name_width = MAX(name_width, dlg_count_columns(items[i].name));
+    }
+    if (dialog_vars.no_tags && !dialog_vars.no_items) {
+	tree_width += text_width;
+    } else if (dialog_vars.no_items) {
+	tree_width += name_width;
+    } else {
+	tree_width += (text_width + name_width);
+    }
+
+    use_width = (all.use_width - 4);
+    tree_width = MIN(tree_width, all.use_width);
+
+    all.check_x = (use_width - tree_width) / 2;
+    all.item_x = ((dialog_vars.no_tags
+		   ? 0
+		   : (dialog_vars.no_items
+		      ? 0
+		      : (2 + name_width)))
+		  + all.check_x + 4);
+
+    /* ensure we are scrolled to show the current choice */
+    if (choice >= (max_choice + scrollamt)) {
+	scrollamt = choice - max_choice + 1;
+	choice = max_choice - 1;
+    }
+
+    /* register the new window, along with its borders */
+    dlg_mouse_mkbigregion(box_y + 1, box_x,
+			  use_height, all.use_width + 2,
+			  KEY_MAX, 1, 1, 1 /* by lines */ );
+
+    all.dialog = dialog;
+    all.box_x = box_x;
+    all.box_y = box_y;
+    all.use_height = use_height;
+    all.list = list;
+    print_list(&all, choice, scrollamt, max_choice);
+
+    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
+
+    dlg_trace_win(dialog);
+
+    while (result == DLG_EXIT_UNKNOWN) {
+	int was_mouse;
+
+	if (button < 0)		/* --visit-items */
+	    wmove(dialog, box_y + choice + 1, box_x + all.check_x + 2);
+
+	key = dlg_mouse_wgetch(dialog, &fkey);
+	if (dlg_result_key(key, fkey, &result)) {
+	    if (!dlg_button_key(result, &button, &key, &fkey))
+		break;
+	}
+
+	was_mouse = (fkey && is_DLGK_MOUSE(key));
+	if (was_mouse)
+	    key -= M_EVENT;
+
+	if (was_mouse && (key >= KEY_MAX)) {
+	    i = (key - KEY_MAX);
+	    if (i < max_choice) {
+		choice = (key - KEY_MAX);
+		print_list(&all, choice, scrollamt, max_choice);
+
+		key = DLGK_TOGGLE;	/* force the selected item to toggle */
+	    } else {
+		beep();
+		continue;
+	    }
+	    fkey = FALSE;
+	} else if (was_mouse && key >= KEY_MIN) {
+	    key = dlg_lookup_key(dialog, key, &fkey);
+	}
+
+	/*
+	 * A space toggles the item status.
+	 */
+	if (key == DLGK_TOGGLE) {
+	    int current = scrollamt + choice;
+	    int next = items[current].state + 1;
+
+	    if (next >= num_states)
+		next = 0;
+
+	    if (flag == FLAG_CHECK) {	/* checklist? */
+		items[current].state = next;
+	    } else {
+		for (i = 0; i < item_no; i++) {
+		    if (i != current) {
+			items[i].state = 0;
+		    }
+		}
+		if (items[current].state) {
+		    items[current].state = next ? next : 1;
+		} else {
+		    items[current].state = 1;
+		}
+	    }
+	    print_list(&all, choice, scrollamt, max_choice);
+	    continue;		/* wait for another key press */
+	}
+
+	/*
+	 * Check if key pressed matches first character of any item tag in
+	 * list.  If there is more than one match, we will cycle through
+	 * each one as the same key is pressed repeatedly.
+	 */
+	found = FALSE;
+	if (!fkey) {
+	    if (button < 0 || !dialog_state.visit_items) {
+		for (j = scrollamt + choice + 1; j < item_no; j++) {
+		    if (check_hotkey(items, j)) {
+			found = TRUE;
+			i = j - scrollamt;
+			break;
+		    }
+		}
+		if (!found) {
+		    for (j = 0; j <= scrollamt + choice; j++) {
+			if (check_hotkey(items, j)) {
+			    found = TRUE;
+			    i = j - scrollamt;
+			    break;
+			}
+		    }
+		}
+		if (found)
+		    dlg_flush_getc();
+	    } else if ((j = dlg_char_to_button(key, buttons)) >= 0) {
+		button = j;
+		ungetch('\n');
+		continue;
+	    }
+	}
+
+	/*
+	 * A single digit (1-9) positions the selection to that line in the
+	 * current screen.
+	 */
+	if (!found
+	    && (key <= '9')
+	    && (key > '0')
+	    && (key - '1' < max_choice)) {
+	    found = TRUE;
+	    i = key - '1';
+	}
+
+	if (!found) {
+	    if (fkey) {
+		found = TRUE;
+		switch (key) {
+		case DLGK_ITEM_FIRST:
+		    i = -scrollamt;
+		    break;
+		case DLGK_ITEM_LAST:
+		    i = item_no - 1 - scrollamt;
+		    break;
+		case DLGK_PAGE_PREV:
+		    if (choice)
+			i = 0;
+		    else if (scrollamt != 0)
+			i = -MIN(scrollamt, max_choice);
+		    else
+			continue;
+		    break;
+		case DLGK_PAGE_NEXT:
+		    i = MIN(choice + max_choice, item_no - scrollamt - 1);
+		    break;
+		case DLGK_ITEM_PREV:
+		    i = choice - 1;
+		    if (choice == 0 && scrollamt == 0)
+			continue;
+		    break;
+		case DLGK_ITEM_NEXT:
+		    i = choice + 1;
+		    if (scrollamt + choice >= item_no - 1)
+			continue;
+		    break;
+		default:
+		    found = FALSE;
+		    break;
+		}
+	    }
+	}
+
+	if (found) {
+	    if (i != choice) {
+		if (i < 0 || i >= max_choice) {
+		    if (i < 0) {
+			scrollamt += i;
+			choice = 0;
+		    } else {
+			choice = max_choice - 1;
+			scrollamt += (i - max_choice + 1);
+		    }
+		    print_list(&all, choice, scrollamt, max_choice);
+		} else {
+		    choice = i;
+		    print_list(&all, choice, scrollamt, max_choice);
+		}
+	    }
+	    continue;		/* wait for another key press */
+	}
+
+	if (fkey) {
+	    switch (key) {
+	    case DLGK_ENTER:
+		result = dlg_enter_buttoncode(button);
+		break;
+	    case DLGK_LEAVE:
+		result = dlg_ok_buttoncode(button);
+		break;
+	    case DLGK_FIELD_PREV:
+		button = dlg_prev_button(buttons, button);
+		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
+				 FALSE, width);
+		break;
+	    case DLGK_FIELD_NEXT:
+		button = dlg_next_button(buttons, button);
+		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
+				 FALSE, width);
+		break;
+#ifdef KEY_RESIZE
+	    case KEY_RESIZE:
+		dlg_will_resize(dialog);
+		/* reset data */
+		height = old_height;
+		width = old_width;
+		/* repaint */
+		_dlg_resize_cleanup(dialog);
+		goto retry;
+#endif
+	    default:
+		if (was_mouse) {
+		    if ((key2 = dlg_ok_buttoncode(key)) >= 0) {
+			result = key2;
+			break;
+		    }
+		    beep();
+		}
+	    }
+	} else if (key > 0) {
+	    beep();
+	}
+    }
+
+    dlg_del_window(dialog);
+    dlg_mouse_free_regions();
+    free(prompt);
+    *current_item = (scrollamt + choice);
+    return result;
+}
+
+/*
+ * Display a set of items as a tree.
+ */
+int
+dialog_treeview(const char *title,
+		const char *cprompt,
+		int height,
+		int width,
+		int list_height,
+		int item_no,
+		char **items,
+		int flag)
+{
+    int result;
+    int i, j;
+    DIALOG_LISTITEM *listitems;
+    int *depths;
+    bool show_status = FALSE;
+    int current = 0;
+    char *help_result;
+
+    DLG_TRACE(("# treeview args:\n"));
+    DLG_TRACE2S("title", title);
+    DLG_TRACE2S("message", cprompt);
+    DLG_TRACE2N("height", height);
+    DLG_TRACE2N("width", width);
+    DLG_TRACE2N("lheight", list_height);
+    DLG_TRACE2N("llength", item_no);
+    /* FIXME dump the items[][] too */
+    DLG_TRACE2N("flag", flag);
+
+    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
+    assert_ptr(listitems, "dialog_treeview");
+
+    depths = dlg_calloc(int, (size_t) item_no + 1);
+    assert_ptr(depths, "dialog_treeview");
+
+    for (i = j = 0; i < item_no; ++i) {
+	listitems[i].name = items[j++];
+	listitems[i].text = (dialog_vars.no_items
+			     ? dlg_strempty()
+			     : items[j++]);
+	listitems[i].state = !dlg_strcmp(items[j++], "on");
+	depths[i] = atoi(items[j++]);
+	listitems[i].help = ((dialog_vars.item_help)
+			     ? items[j++]
+			     : dlg_strempty());
+    }
+    dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
+
+    result = dlg_treeview(title,
+			  cprompt,
+			  height,
+			  width,
+			  list_height,
+			  item_no,
+			  listitems,
+			  NULL,
+			  depths,
+			  flag,
+			  &current);
+
+    switch (result) {
+    case DLG_EXIT_OK:		/* FALLTHRU */
+    case DLG_EXIT_EXTRA:
+	show_status = TRUE;
+	break;
+    case DLG_EXIT_HELP:
+	dlg_add_help_listitem(&result, &help_result, &listitems[current]);
+	if ((show_status = dialog_vars.help_status)) {
+	    if (dialog_vars.separate_output) {
+		dlg_add_string(help_result);
+		dlg_add_separator();
+	    } else {
+		dlg_add_quoted(help_result);
+	    }
+	} else {
+	    dlg_add_string(help_result);
+	}
+	break;
+    }
+
+    if (show_status) {
+	for (i = 0; i < item_no; i++) {
+	    if (listitems[i].state) {
+		if (dlg_need_separator())
+		    dlg_add_separator();
+		if (dialog_vars.separate_output) {
+		    dlg_add_string(listitems[i].name);
+		} else {
+		    if (flag == FLAG_CHECK)
+			dlg_add_quoted(listitems[i].name);
+		    else
+			dlg_add_string(listitems[i].name);
+		}
+	    }
+	}
+	AddLastKey();
+    }
+
+    dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
+    free(depths);
+    free(listitems);
+    return result;
+}
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/util.c
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/util.c	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new/util.c	(revision 5)
@@ -0,0 +1,3031 @@
+/*
+ *  $Id: util.c,v 1.303 2021/06/15 00:10:11 tom Exp $
+ *
+ *  util.c -- miscellaneous utilities for dialog
+ *
+ *  Copyright 2000-2020,2021	Thomas E. Dickey
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License, version 2.1
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to
+ *	Free Software Foundation, Inc.
+ *	51 Franklin St., Fifth Floor
+ *	Boston, MA 02110, USA.
+ *
+ *  An earlier version of this program lists as authors
+ *	Savio Lam (lam836@cs.cuhk.hk)
+ */
+
+#include <dialog.h>
+#include <dlg_keys.h>
+#include <dlg_internals.h>
+
+#include <sys/time.h>
+
+#ifdef HAVE_SETLOCALE
+#include <locale.h>
+#endif
+
+#ifdef NEED_WCHAR_H
+#include <wchar.h>
+#endif
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#if defined(NCURSES_VERSION)
+#define CAN_KEEP_TITE 1
+#elif defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 800000000)
+#define CAN_KEEP_TITE 1
+#else
+#define CAN_KEEP_TITE 0
+#endif
+
+#if CAN_KEEP_TITE
+#if defined(NCURSES_VERSION) && defined(HAVE_NCURSESW_TERM_H)
+#include <ncursesw/term.h>
+#elif defined(NCURSES_VERSION) && defined(HAVE_NCURSES_TERM_H)
+#include <ncurses/term.h>
+#else
+#include <term.h>
+#endif
+#endif
+
+#if defined(HAVE_WCHGAT)
+#  if defined(NCURSES_VERSION_PATCH)
+#    if NCURSES_VERSION_PATCH >= 20060715
+#      define USE_WCHGAT 1
+#    else
+#      define USE_WCHGAT 0
+#    endif
+#  else
+#    define USE_WCHGAT 1
+#  endif
+#else
+#  define USE_WCHGAT 0
+#endif
+
+/* globals */
+DIALOG_STATE dialog_state;
+DIALOG_VARS dialog_vars;
+
+#if !(defined(HAVE_WGETPARENT) && defined(HAVE_WINDOW__PARENT))
+#define NEED_WGETPARENT 1
+#else
+#undef NEED_WGETPARENT
+#endif
+
+#define concat(a,b) a##b
+
+#ifdef HAVE_RC_FILE
+#define RC_DATA(name,comment) , #name "_color", comment " color"
+#else
+#define RC_DATA(name,comment)	/*nothing */
+#endif
+
+#ifdef HAVE_COLOR
+#include <dlg_colors.h>
+#ifdef HAVE_RC_FILE2
+#define COLOR_DATA(upr) , \
+	concat(DLGC_FG_,upr), \
+	concat(DLGC_BG_,upr), \
+	concat(DLGC_HL_,upr), \
+	concat(DLGC_UL_,upr), \
+	concat(DLGC_RV_,upr)
+#else /* HAVE_RC_FILE2 */
+#define COLOR_DATA(upr) , \
+	concat(DLGC_FG_,upr), \
+	concat(DLGC_BG_,upr), \
+	concat(DLGC_HL_,upr)
+#endif /* HAVE_RC_FILE2 */
+#else /* HAVE_COLOR */
+#define COLOR_DATA(upr)		/*nothing */
+#endif /* HAVE_COLOR */
+
+#define UseShadow(dw) ((dw) != 0 && (dw)->normal != 0 && (dw)->shadow != 0)
+
+/*
+ * Table of color and attribute values, default is for mono display.
+ * The order matches the DIALOG_ATR() values.
+ */
+#define DATA(atr,upr,lwr,cmt) { atr COLOR_DATA(upr) RC_DATA(lwr,cmt) }
+/* *INDENT-OFF* */
+DIALOG_COLORS dlg_color_table[] =
+{
+    DATA(A_NORMAL,	SCREEN,			screen, "Screen"),
+    DATA(A_NORMAL,	SHADOW,			shadow, "Shadow"),
+    DATA(A_REVERSE,	DIALOG,			dialog, "Dialog box"),
+    DATA(A_REVERSE,	TITLE,			title, "Dialog box title"),
+    DATA(A_REVERSE,	BORDER,			border, "Dialog box border"),
+    DATA(A_BOLD,	BUTTON_ACTIVE,		button_active, "Active button"),
+    DATA(A_DIM,		BUTTON_INACTIVE,	button_inactive, "Inactive button"),
+    DATA(A_UNDERLINE,	BUTTON_KEY_ACTIVE,	button_key_active, "Active button key"),
+    DATA(A_UNDERLINE,	BUTTON_KEY_INACTIVE,	button_key_inactive, "Inactive button key"),
+    DATA(A_NORMAL,	BUTTON_LABEL_ACTIVE,	button_label_active, "Active button label"),
+    DATA(A_NORMAL,	BUTTON_LABEL_INACTIVE,	button_label_inactive, "Inactive button label"),
+    DATA(A_REVERSE,	INPUTBOX,		inputbox, "Input box"),
+    DATA(A_REVERSE,	INPUTBOX_BORDER,	inputbox_border, "Input box border"),
+    DATA(A_REVERSE,	SEARCHBOX,		searchbox, "Search box"),
+    DATA(A_REVERSE,	SEARCHBOX_TITLE,	searchbox_title, "Search box title"),
+    DATA(A_REVERSE,	SEARCHBOX_BORDER,	searchbox_border, "Search box border"),
+    DATA(A_REVERSE,	POSITION_INDICATOR,	position_indicator, "File position indicator"),
+    DATA(A_REVERSE,	MENUBOX,		menubox, "Menu box"),
+    DATA(A_REVERSE,	MENUBOX_BORDER,		menubox_border, "Menu box border"),
+    DATA(A_REVERSE,	ITEM,			item, "Item"),
+    DATA(A_NORMAL,	ITEM_SELECTED,		item_selected, "Selected item"),
+    DATA(A_REVERSE,	TAG,			tag, "Tag"),
+    DATA(A_REVERSE,	TAG_SELECTED,		tag_selected, "Selected tag"),
+    DATA(A_NORMAL,	TAG_KEY,		tag_key, "Tag key"),
+    DATA(A_BOLD,	TAG_KEY_SELECTED,	tag_key_selected, "Selected tag key"),
+    DATA(A_REVERSE,	CHECK,			check, "Check box"),
+    DATA(A_REVERSE,	CHECK_SELECTED,		check_selected, "Selected check box"),
+    DATA(A_REVERSE,	UARROW,			uarrow, "Up arrow"),
+    DATA(A_REVERSE,	DARROW,			darrow, "Down arrow"),
+    DATA(A_NORMAL,	ITEMHELP,		itemhelp, "Item help-text"),
+    DATA(A_BOLD,	FORM_ACTIVE_TEXT,	form_active_text, "Active form text"),
+    DATA(A_REVERSE,	FORM_TEXT,		form_text, "Form text"),
+    DATA(A_NORMAL,	FORM_ITEM_READONLY,	form_item_readonly, "Readonly form item"),
+    DATA(A_REVERSE,	GAUGE,			gauge, "Dialog box gauge"),
+    DATA(A_REVERSE,	BORDER2,		border2, "Dialog box border2"),
+    DATA(A_REVERSE,	INPUTBOX_BORDER2,	inputbox_border2, "Input box border2"),
+    DATA(A_REVERSE,	SEARCHBOX_BORDER2,	searchbox_border2, "Search box border2"),
+    DATA(A_REVERSE,	MENUBOX_BORDER2,	menubox_border2, "Menu box border2")
+};
+#undef DATA
+/* *INDENT-ON* */
+
+/*
+ * Maintain a list of subwindows so that we can delete them to cleanup.
+ * More important, this provides a fallback when wgetparent() is not available.
+ */
+static void
+add_subwindow(WINDOW *parent, WINDOW *child)
+{
+    DIALOG_WINDOWS *p = dlg_calloc(DIALOG_WINDOWS, 1);
+
+    if (p != 0) {
+	p->normal = parent;
+	p->shadow = child;
+	p->getc_timeout = WTIMEOUT_OFF;
+	p->next = dialog_state.all_subwindows;
+	dialog_state.all_subwindows = p;
+    }
+}
+
+static void
+del_subwindows(WINDOW *parent)
+{
+    DIALOG_WINDOWS *p = dialog_state.all_subwindows;
+    DIALOG_WINDOWS *q = 0;
+    DIALOG_WINDOWS *r;
+
+    while (p != 0) {
+	if (p->normal == parent) {
+	    delwin(p->shadow);
+	    r = p->next;
+	    if (q == 0) {
+		dialog_state.all_subwindows = r;
+	    } else {
+		q->next = r;
+	    }
+	    free(p);
+	    p = r;
+	} else {
+	    q = p;
+	    p = p->next;
+	}
+    }
+}
+
+/*
+ * Display background title if it exists ...
+ */
+void
+dlg_put_backtitle(void)
+{
+
+    if (dialog_vars.backtitle != NULL) {
+	chtype attr = A_NORMAL;
+	int backwidth = dlg_count_columns(dialog_vars.backtitle);
+	int i;
+
+	dlg_attrset(stdscr, screen_attr);
+	(void) wmove(stdscr, 0, 1);
+	dlg_print_text(stdscr, dialog_vars.backtitle, COLS - 2, &attr);
+	for (i = 0; i < COLS - backwidth; i++)
+	    (void) waddch(stdscr, ' ');
+	(void) wmove(stdscr, 1, 1);
+	for (i = 0; i < COLS - 2; i++)
+	    (void) waddch(stdscr, dlg_boxchar(ACS_HLINE));
+    }
+
+    (void) wnoutrefresh(stdscr);
+}
+
+/*
+ * Set window to attribute 'attr'.  There are more efficient ways to do this,
+ * but will not work on older/buggy ncurses versions.
+ */
+void
+dlg_attr_clear(WINDOW *win, int height, int width, chtype attr)
+{
+    int i, j;
+
+    dlg_attrset(win, attr);
+    for (i = 0; i < height; i++) {
+	(void) wmove(win, i, 0);
+	for (j = 0; j < width; j++)
+	    (void) waddch(win, ' ');
+    }
+    (void) touchwin(win);
+}
+
+void
+dlg_clear(void)
+{
+    dlg_attr_clear(stdscr, LINES, COLS, screen_attr);
+}
+
+#ifdef KEY_RESIZE
+void
+_dlg_resize_cleanup(WINDOW *w)
+{
+    dlg_clear();
+    dlg_put_backtitle();
+    dlg_del_window(w);
+    dlg_mouse_free_regions();
+}
+#endif /* KEY_RESIZE */
+
+#define isprivate(s) ((s) != 0 && strstr(s, "\033[?") != 0)
+
+#define TTY_DEVICE "/dev/tty"
+
+/*
+ * If $DIALOG_TTY exists, allow the program to try to open the terminal
+ * directly when stdout is redirected.  By default we require the "--stdout"
+ * option to be given, but some scripts were written making use of the
+ * behavior of dialog which tried opening the terminal anyway. 
+ */
+#define dialog_tty() (dlg_getenv_num("DIALOG_TTY", (int *)0) > 0)
+
+/*
+ * Open the terminal directly.  If one of stdin, stdout or stderr really points
+ * to a tty, use it.  Otherwise give up and open /dev/tty.
+ */
+static int
+open_terminal(char **result, int mode)
+{
+    const char *device = TTY_DEVICE;
+    if (!isatty(fileno(stderr))
+	|| (device = ttyname(fileno(stderr))) == 0) {
+	if (!isatty(fileno(stdout))
+	    || (device = ttyname(fileno(stdout))) == 0) {
+	    if (!isatty(fileno(stdin))
+		|| (device = ttyname(fileno(stdin))) == 0) {
+		device = TTY_DEVICE;
+	    }
+	}
+    }
+    *result = dlg_strclone(device);
+    return open(device, mode);
+}
+
+#if CAN_KEEP_TITE
+static int
+my_putc(int ch)
+{
+    char buffer[2];
+    int fd = fileno(dialog_state.screen_output);
+
+    buffer[0] = (char) ch;
+    return (int) write(fd, buffer, (size_t) 1);
+}
+#endif
+
+/*
+ * Do some initialization for dialog.
+ *
+ * 'input' is the real tty input of dialog.  Usually it is stdin, but if
+ * --input-fd option is used, it may be anything.
+ *
+ * 'output' is where dialog will send its result.  Usually it is stderr, but
+ * if --stdout or --output-fd is used, it may be anything.  We are concerned
+ * mainly with the case where it happens to be the same as stdout.
+ */
+void
+init_dialog(FILE *input, FILE *output)
+{
+    int fd1, fd2;
+    char *device = 0;
+
+    setlocale(LC_ALL, "");
+
+    dialog_state.output = output;
+    if (dialog_state.tab_len == 0)
+	dialog_state.tab_len = TAB_LEN;
+    if (dialog_state.aspect_ratio == 0)
+	dialog_state.aspect_ratio = DEFAULT_ASPECT_RATIO;
+#ifdef HAVE_COLOR
+    dialog_state.use_colors = USE_COLORS;	/* use colors by default? */
+    dialog_state.use_shadow = USE_SHADOW;	/* shadow dialog boxes by default? */
+#endif
+
+#ifdef HAVE_RC_FILE
+    if (dlg_parse_rc() == -1)	/* Read the configuration file */
+	dlg_exiterr("init_dialog: dlg_parse_rc");
+#endif
+
+    /*
+     * Some widgets (such as gauge) may read from the standard input.  Pipes
+     * only connect stdout/stdin, so there is not much choice.  But reading a
+     * pipe would get in the way of curses' normal reading stdin for getch.
+     *
+     * As in the --stdout (see below), reopening the terminal does not always
+     * work properly.  dialog provides a --pipe-fd option for this purpose.  We
+     * test that case first (differing fileno's for input/stdin).  If the
+     * fileno's are equal, but we're not reading from a tty, see if we can open
+     * /dev/tty.
+     */
+    dialog_state.pipe_input = stdin;
+    if (fileno(input) != fileno(stdin)) {
+	if ((fd1 = dup(fileno(input))) >= 0
+	    && (fd2 = dup(fileno(stdin))) >= 0) {
+	    (void) dup2(fileno(input), fileno(stdin));
+	    dialog_state.pipe_input = fdopen(fd2, "r");
+	    if (fileno(stdin) != 0)	/* some functions may read fd #0 */
+		(void) dup2(fileno(stdin), 0);
+	} else {
+	    dlg_exiterr("cannot open tty-input");
+	}
+	close(fd1);
+    } else if (!isatty(fileno(stdin))) {
+	if ((fd1 = open_terminal(&device, O_RDONLY)) >= 0) {
+	    if ((fd2 = dup(fileno(stdin))) >= 0) {
+		dialog_state.pipe_input = fdopen(fd2, "r");
+		if (freopen(device, "r", stdin) == 0)
+		    dlg_exiterr("cannot open tty-input");
+		if (fileno(stdin) != 0)		/* some functions may read fd #0 */
+		    (void) dup2(fileno(stdin), 0);
+	    }
+	    close(fd1);
+	}
+	free(device);
+    }
+
+    /*
+     * If stdout is not a tty and dialog is called with the --stdout option, we
+     * have to provide for a way to write to the screen.
+     *
+     * The curses library normally writes its output to stdout, leaving stderr
+     * free for scripting.  Scripts are simpler when stdout is redirected.  The
+     * newterm function is useful; it allows us to specify where the output
+     * goes.  Reopening the terminal is not portable since several
+     * configurations do not allow this to work properly:
+     *
+     * a) some getty implementations (and possibly broken tty drivers, e.g., on
+     *    HPUX 10 and 11) cause stdin to act as if it is still in cooked mode
+     *    even though results from ioctl's state that it is successfully
+     *    altered to raw mode.  Broken is the proper term.
+     *
+     * b) the user may not have permissions on the device, e.g., if one su's
+     *    from the login user to another non-privileged user.
+     */
+    if (!isatty(fileno(stdout))
+	&& (fileno(stdout) == fileno(output) || dialog_tty())) {
+	if ((fd1 = open_terminal(&device, O_WRONLY)) >= 0
+	    && (dialog_state.screen_output = fdopen(fd1, "w")) != 0) {
+	    if (newterm(NULL, dialog_state.screen_output, stdin) == 0) {
+		dlg_exiterr("cannot initialize curses");
+	    }
+	    free(device);
+	} else {
+	    dlg_exiterr("cannot open tty-output");
+	}
+    } else {
+	dialog_state.screen_output = stdout;
+	(void) initscr();
+    }
+    dlg_keep_tite(dialog_state.screen_output);
+#ifdef HAVE_FLUSHINP
+    (void) flushinp();
+#endif
+    (void) keypad(stdscr, TRUE);
+    (void) cbreak();
+    (void) noecho();
+
+    if (!dialog_state.no_mouse) {
+	mouse_open();
+    }
+
+    dialog_state.screen_initialized = TRUE;
+
+#ifdef HAVE_COLOR
+    if (dialog_state.use_colors || dialog_state.use_shadow)
+	dlg_color_setup();	/* Set up colors */
+#endif
+
+    /* Set screen to screen attribute */
+    dlg_clear();
+}
+
+void
+dlg_keep_tite(FILE *output)
+{
+    if (!dialog_vars.keep_tite) {
+#if CAN_KEEP_TITE
+	/*
+	 * Cancel xterm's alternate-screen mode.
+	 */
+	if ((fileno(output) != fileno(stdout)
+	     || isatty(fileno(output)))
+	    && key_mouse != 0	/* xterm and kindred */
+	    && isprivate(enter_ca_mode)
+	    && isprivate(exit_ca_mode)) {
+	    FILE *save = dialog_state.screen_output;
+
+	    /*
+	     * initscr() or newterm() already wrote enter_ca_mode as a side
+	     * effect of initializing the screen.  It would be nice to not even
+	     * do that, but we do not really have access to the correct copy of
+	     * the terminfo description until those functions have been
+	     * invoked.
+	     */
+	    (void) refresh();
+	    dialog_state.screen_output = output;
+	    (void) tputs(exit_ca_mode, 0, my_putc);
+	    (void) tputs(clear_screen, 0, my_putc);
+	    dialog_state.screen_output = save;
+
+	    /*
+	     * Prevent ncurses from switching "back" to the normal screen when
+	     * exiting from dialog.  That would move the cursor to the original
+	     * location saved in xterm.  Normally curses sets the cursor
+	     * position to the first line after the display, but the alternate
+	     * screen switching is done after that point.
+	     *
+	     * Cancelling the strings altogether also works around the buggy
+	     * implementation of alternate-screen in rxvt, etc., which clear
+	     * more of the display than they should.
+	     */
+	    enter_ca_mode = 0;
+	    exit_ca_mode = 0;
+	}
+#else
+	/*
+	 * For other implementations, there are no useful answers:
+	 * + SVr4 curses "could" support a similar approach, but the clue about
+	 *   xterm is absent from its terminal database.
+	 * + PDCurses does not provide terminfo.
+	 */
+	(void) output;
+#endif
+    }
+}
+
+#ifdef HAVE_COLOR
+static int defined_colors = 1;	/* pair-0 is reserved */
+/*
+ * Setup for color display
+ */
+void
+dlg_color_setup(void)
+{
+    if (has_colors()) {		/* Terminal supports color? */
+	unsigned i;
+
+	(void) start_color();
+
+#if defined(HAVE_USE_DEFAULT_COLORS)
+	use_default_colors();
+#endif
+
+#if defined(__NetBSD__) && defined(_CURSES_)
+#define C_ATTR(x,y) (((x) != 0 ? A_BOLD :  0) | COLOR_PAIR((y)))
+	/* work around bug in NetBSD curses */
+	for (i = 0; i < sizeof(dlg_color_table) /
+	     sizeof(dlg_color_table[0]); i++) {
+
+	    /* Initialize color pairs */
+	    (void) init_pair(i + 1,
+			     dlg_color_table[i].fg,
+			     dlg_color_table[i].bg);
+
+	    /* Setup color attributes */
+	    dlg_color_table[i].atr = C_ATTR(dlg_color_table[i].hilite, i + 1);
+	}
+	defined_colors = i + 1;
+#else
+	for (i = 0; i < sizeof(dlg_color_table) /
+	     sizeof(dlg_color_table[0]); i++) {
+
+	    /* Initialize color pairs */
+	    chtype atr = dlg_color_pair(dlg_color_table[i].fg,
+					dlg_color_table[i].bg);
+
+	    atr |= (dlg_color_table[i].hilite ? A_BOLD : 0);
+#ifdef HAVE_RC_FILE2
+	    atr |= (dlg_color_table[i].ul ? A_UNDERLINE : 0);
+	    atr |= (dlg_color_table[i].rv ? A_REVERSE : 0);
+#endif /* HAVE_RC_FILE2 */
+
+	    dlg_color_table[i].atr = atr;
+	}
+#endif
+    } else {
+	dialog_state.use_colors = FALSE;
+	dialog_state.use_shadow = FALSE;
+    }
+}
+
+int
+dlg_color_count(void)
+{
+    return TableSize(dlg_color_table);
+}
+
+/*
+ * Wrapper for getattrs(), or the more cumbersome X/Open wattr_get().
+ */
+chtype
+dlg_get_attrs(WINDOW *win)
+{
+    chtype result;
+#ifdef HAVE_GETATTRS
+    result = (chtype) getattrs(win);
+#else
+    attr_t my_result;
+    short my_pair;
+    wattr_get(win, &my_result, &my_pair, NULL);
+    result = my_result;
+#endif
+    return result;
+}
+
+/*
+ * Reuse color pairs (they are limited), returning a COLOR_PAIR() value if we
+ * have (or can) define a pair with the given color as foreground on the
+ * window's defined background.
+ */
+chtype
+dlg_color_pair(int foreground, int background)
+{
+    chtype result = 0;
+    int pair;
+    short fg, bg;
+    bool found = FALSE;
+
+    for (pair = 1; pair < defined_colors; ++pair) {
+	if (pair_content((short) pair, &fg, &bg) != ERR
+	    && fg == foreground
+	    && bg == background) {
+	    result = (chtype) COLOR_PAIR(pair);
+	    found = TRUE;
+	    break;
+	}
+    }
+    if (!found && (defined_colors + 1) < COLOR_PAIRS) {
+	pair = defined_colors++;
+	(void) init_pair((short) pair, (short) foreground, (short) background);
+	result = (chtype) COLOR_PAIR(pair);
+    }
+    return result;
+}
+
+/*
+ * Reuse color pairs (they are limited), returning a COLOR_PAIR() value if we
+ * have (or can) define a pair with the given color as foreground on the
+ * window's defined background.
+ */
+static chtype
+define_color(WINDOW *win, int foreground)
+{
+    short fg, bg, background;
+    if (dialog_state.text_only) {
+	background = COLOR_BLACK;
+    } else {
+	chtype attrs = dlg_get_attrs(win);
+	int pair;
+
+	if ((pair = PAIR_NUMBER(attrs)) != 0
+	    && pair_content((short) pair, &fg, &bg) != ERR) {
+	    background = bg;
+	} else {
+	    background = COLOR_BLACK;
+	}
+    }
+    return dlg_color_pair(foreground, background);
+}
+#endif
+
+/*
+ * End using dialog functions.
+ */
+void
+end_dialog(void)
+{
+    if (dialog_state.screen_initialized) {
+	dialog_state.screen_initialized = FALSE;
+	if (dialog_vars.erase_on_exit) {
+	    /*
+	     * Clear the screen to the native background color, and leave the
+	     * terminal cursor at the lower-left corner of the screen.
+	     */
+	    werase(stdscr);
+	    wrefresh(stdscr);
+	}
+	mouse_close();
+	(void) endwin();
+	(void) fflush(stdout);
+    }
+}
+
+#define ESCAPE_LEN 3
+#define isOurEscape(p) (((p)[0] == '\\') && ((p)[1] == 'Z') && ((p)[2] != 0))
+
+int
+dlg_count_real_columns(const char *text)
+{
+    int result = 0;
+    if (*text) {
+	result = dlg_count_columns(text);
+	if (result && dialog_vars.colors) {
+	    int hidden = 0;
+	    while (*text) {
+		if (isOurEscape(text)) {
+		    hidden += ESCAPE_LEN;
+		    text += ESCAPE_LEN;
+		} else {
+		    ++text;
+		}
+	    }
+	    result -= hidden;
+	}
+    }
+    return result;
+}
+
+static int
+centered(int width, const char *string)
+{
+    int need = dlg_count_real_columns(string);
+    int left;
+
+    left = (width - need) / 2 - 1;
+    if (left < 0)
+	left = 0;
+    return left;
+}
+
+#ifdef USE_WIDE_CURSES
+static bool
+is_combining(const char *txt, int *combined)
+{
+    bool result = FALSE;
+
+    if (*combined == 0) {
+	if (UCH(*txt) >= 128) {
+	    wchar_t wch;
+	    mbstate_t state;
+	    size_t given = strlen(txt);
+	    size_t len;
+
+	    memset(&state, 0, sizeof(state));
+	    len = mbrtowc(&wch, txt, given, &state);
+	    if ((int) len > 0 && wcwidth(wch) == 0) {
+		*combined = (int) len - 1;
+		result = TRUE;
+	    }
+	}
+    } else {
+	result = TRUE;
+	*combined -= 1;
+    }
+    return result;
+}
+#endif
+
+/*
+ * Print the name (tag) or text from a DIALOG_LISTITEM, highlighting the
+ * first character if selected.
+ */
+void
+dlg_print_listitem(WINDOW *win,
+		   const char *text,
+		   int climit,
+		   bool first,
+		   int selected)
+{
+    chtype attr = A_NORMAL;
+    int limit;
+    chtype attrs[4];
+
+    if (text == 0)
+	text = "";
+
+    if (first && !dialog_vars.no_hot_list) {
+	const int *indx = dlg_index_wchars(text);
+	attrs[3] = tag_key_selected_attr;
+	attrs[2] = tag_key_attr;
+	attrs[1] = tag_selected_attr;
+	attrs[0] = tag_attr;
+
+	dlg_attrset(win, selected ? attrs[3] : attrs[2]);
+	if (*text != '\0') {
+	    (void) waddnstr(win, text, indx[1]);
+
+	    if ((int) strlen(text) > indx[1]) {
+		limit = dlg_limit_columns(text, climit, 1);
+		if (limit > 1) {
+		    dlg_attrset(win, selected ? attrs[1] : attrs[0]);
+		    (void) waddnstr(win,
+				    text + indx[1],
+				    indx[limit] - indx[1]);
+		}
+	    }
+	}
+    } else {
+	const int *cols;
+
+	attrs[1] = item_selected_attr;
+	attrs[0] = item_attr;
+
+	cols = dlg_index_columns(text);
+	limit = dlg_limit_columns(text, climit, 0);
+
+	if (limit > 0) {
+	    dlg_attrset(win, selected ? attrs[1] : attrs[0]);
+	    dlg_print_text(win, text, cols[limit], &attr);
+	}
+    }
+}
+
+/*
+ * Print up to 'cols' columns from 'text', optionally rendering our escape
+ * sequence for attributes and color.
+ */
+void
+dlg_print_text(WINDOW *win, const char *txt, int cols, chtype *attr)
+{
+    int y_origin, x_origin;
+    int y_before, x_before = 0;
+    int y_after, x_after;
+    int tabbed = 0;
+    bool ended = FALSE;
+#ifdef USE_WIDE_CURSES
+    int combined = 0;
+#endif
+
+    if (dialog_state.text_only) {
+	y_origin = y_after = 0;
+	x_origin = x_after = 0;
+    } else {
+	y_after = 0;
+	x_after = 0;
+	getyx(win, y_origin, x_origin);
+    }
+    while (cols > 0 && (*txt != '\0')) {
+	bool thisTab;
+	chtype useattr;
+
+	if (dialog_vars.colors) {
+	    while (isOurEscape(txt)) {
+		int code;
+
+		txt += 2;
+		switch (code = CharOf(*txt)) {
+#ifdef HAVE_COLOR
+		case '0':
+		case '1':
+		case '2':
+		case '3':
+		case '4':
+		case '5':
+		case '6':
+		case '7':
+		    *attr &= ~A_COLOR;
+		    *attr |= define_color(win, code - '0');
+		    break;
+#endif
+		case 'B':
+		    *attr &= ~A_BOLD;
+		    break;
+		case 'b':
+		    *attr |= A_BOLD;
+		    break;
+		case 'R':
+		    *attr &= ~A_REVERSE;
+		    break;
+		case 'r':
+		    *attr |= A_REVERSE;
+		    break;
+		case 'U':
+		    *attr &= ~A_UNDERLINE;
+		    break;
+		case 'u':
+		    *attr |= A_UNDERLINE;
+		    break;
+		case 'n':
+		    *attr = A_NORMAL;
+		    break;
+		default:
+		    break;
+		}
+		++txt;
+	    }
+	}
+	if (ended || *txt == '\n' || *txt == '\0')
+	    break;
+	useattr = (*attr) & A_ATTRIBUTES;
+#ifdef HAVE_COLOR
+	/*
+	 * Prevent this from making text invisible when the foreground and
+	 * background colors happen to be the same, and there's no bold
+	 * attribute.
+	 */
+	if ((useattr & A_COLOR) != 0 && (useattr & A_BOLD) == 0) {
+	    short pair = (short) PAIR_NUMBER(useattr);
+	    short fg, bg;
+	    if (pair_content(pair, &fg, &bg) != ERR
+		&& fg == bg) {
+		useattr &= ~A_COLOR;
+		useattr |= dlg_color_pair(fg, ((bg == COLOR_BLACK)
+					       ? COLOR_WHITE
+					       : COLOR_BLACK));
+	    }
+	}
+#endif
+	/*
+	 * Write the character, using curses to tell exactly how wide it
+	 * is.  If it is a tab, discount that, since the caller thinks
+	 * tabs are nonprinting, and curses will expand tabs to one or
+	 * more blanks.
+	 */
+	thisTab = (CharOf(*txt) == TAB);
+	if (dialog_state.text_only) {
+	    x_before = x_after;
+	} else {
+	    if (thisTab) {
+		getyx(win, y_before, x_before);
+		(void) y_before;
+	    }
+	}
+	if (dialog_state.text_only) {
+	    int ch = CharOf(*txt++);
+	    if (thisTab) {
+		while ((x_after++) % 8) {
+		    fputc(' ', dialog_state.output);
+		}
+	    } else {
+		fputc(ch, dialog_state.output);
+		x_after++;	/* FIXME: handle meta per locale */
+	    }
+	} else {
+	    (void) waddch(win, CharOf(*txt++) | useattr);
+	    getyx(win, y_after, x_after);
+	}
+	if (thisTab && (y_after == y_origin))
+	    tabbed += (x_after - x_before);
+	if ((y_after != y_origin) ||
+	    (x_after >= (cols + tabbed + x_origin)
+#ifdef USE_WIDE_CURSES
+	     && !is_combining(txt, &combined)
+#endif
+	    )) {
+	    ended = TRUE;
+	}
+    }
+    if (dialog_state.text_only) {
+	fputc('\n', dialog_state.output);
+    }
+}
+
+/*
+ * Print one line of the prompt in the window within the limits of the
+ * specified right margin.  The line will end on a word boundary and a pointer
+ * to the start of the next line is returned, or a NULL pointer if the end of
+ * *prompt is reached.
+ */
+const char *
+dlg_print_line(WINDOW *win,
+	       chtype *attr,
+	       const char *prompt,
+	       int lm, int rm, int *x)
+{
+    const char *wrap_ptr;
+    const char *test_ptr;
+    const char *hide_ptr = 0;
+    const int *cols = dlg_index_columns(prompt);
+    const int *indx = dlg_index_wchars(prompt);
+    int wrap_inx = 0;
+    int test_inx = 0;
+    int cur_x = lm;
+    int hidden = 0;
+    int limit = dlg_count_wchars(prompt);
+    int n;
+    int tabbed = 0;
+
+    *x = 1;
+
+    /*
+     * Set *test_ptr to the end of the line or the right margin (rm), whichever
+     * is less, and set wrap_ptr to the end of the last word in the line.
+     */
+    for (n = 0; n < limit; ++n) {
+	int ch = *(test_ptr = prompt + indx[test_inx]);
+	if (ch == '\n' || ch == '\0' || cur_x >= (rm + hidden))
+	    break;
+	if (ch == TAB && n == 0) {
+	    tabbed = 8;		/* workaround for leading tabs */
+	} else if (isblank(UCH(ch))
+		   && n != 0
+		   && !isblank(UCH(prompt[indx[n - 1]]))) {
+	    wrap_inx = n;
+	    *x = cur_x;
+	} else if (dialog_vars.colors && isOurEscape(test_ptr)) {
+	    hide_ptr = test_ptr;
+	    hidden += ESCAPE_LEN;
+	    n += (ESCAPE_LEN - 1);
+	}
+	cur_x = lm + tabbed + cols[n + 1];
+	if (cur_x > (rm + hidden))
+	    break;
+	test_inx = n + 1;
+    }
+
+    /*
+     * If the line doesn't reach the right margin in the middle of a word, then
+     * we don't have to wrap it at the end of the previous word.
+     */
+    test_ptr = prompt + indx[test_inx];
+    if (*test_ptr == '\n' || isblank(UCH(*test_ptr)) || *test_ptr == '\0') {
+	wrap_inx = test_inx;
+	while (wrap_inx > 0 && isblank(UCH(prompt[indx[wrap_inx - 1]]))) {
+	    wrap_inx--;
+	}
+	*x = lm + indx[wrap_inx];
+    } else if (*x == 1 && cur_x >= rm) {
+	/*
+	 * If the line has no spaces, then wrap it anyway at the right margin
+	 */
+	*x = rm;
+	wrap_inx = test_inx;
+    }
+    wrap_ptr = prompt + indx[wrap_inx];
+#ifdef USE_WIDE_CURSES
+    if (UCH(*wrap_ptr) >= 128) {
+	int combined = 0;
+	while (is_combining(wrap_ptr, &combined)) {
+	    ++wrap_ptr;
+	}
+    }
+#endif
+
+    /*
+     * If we found hidden text past the last point that we will display,
+     * discount that from the displayed length.
+     */
+    if ((hide_ptr != 0) && (hide_ptr >= wrap_ptr)) {
+	hidden -= ESCAPE_LEN;
+	test_ptr = wrap_ptr;
+	while (test_ptr < wrap_ptr) {
+	    if (dialog_vars.colors && isOurEscape(test_ptr)) {
+		hidden -= ESCAPE_LEN;
+		test_ptr += ESCAPE_LEN;
+	    } else {
+		++test_ptr;
+	    }
+	}
+    }
+
+    /*
+     * Print the line if we have a window pointer.  Otherwise this routine
+     * is just being called for sizing the window.
+     */
+    if (dialog_state.text_only || win) {
+	dlg_print_text(win, prompt, (cols[wrap_inx] - hidden), attr);
+    }
+
+    /* *x tells the calling function how long the line was */
+    if (*x == 1) {
+	*x = rm;
+    }
+
+    *x -= hidden;
+
+    /* Find the start of the next line and return a pointer to it */
+    test_ptr = wrap_ptr;
+    while (isblank(UCH(*test_ptr)))
+	test_ptr++;
+    if (*test_ptr == '\n')
+	test_ptr++;
+    dlg_finish_string(prompt);
+    return (test_ptr);
+}
+
+static void
+justify_text(WINDOW *win,
+	     const char *prompt,
+	     int limit_y,
+	     int limit_x,
+	     int *high, int *wide)
+{
+    chtype attr = A_NORMAL;
+    int x;
+    int y = MARGIN;
+    int max_x = 2;
+    int lm = (2 * MARGIN);	/* left margin (box-border plus a space) */
+    int rm = limit_x;		/* right margin */
+    int bm = limit_y;		/* bottom margin */
+    int last_y = 0, last_x = 0;
+
+    dialog_state.text_height = 0;
+    dialog_state.text_width = 0;
+    if (dialog_state.text_only || win) {
+	rm -= (2 * MARGIN);
+	bm -= (2 * MARGIN);
+    }
+    if (prompt == 0)
+	prompt = "";
+
+    if (win != 0)
+	getyx(win, last_y, last_x);
+    while (y <= bm && *prompt) {
+	x = lm;
+
+	if (*prompt == '\n') {
+	    while (*prompt == '\n' && y < bm) {
+		if (*(prompt + 1) != '\0') {
+		    ++y;
+		    if (win != 0)
+			(void) wmove(win, y, lm);
+		}
+		prompt++;
+	    }
+	} else if (win != 0)
+	    (void) wmove(win, y, lm);
+
+	if (*prompt) {
+	    prompt = dlg_print_line(win, &attr, prompt, lm, rm, &x);
+	    if (win != 0)
+		getyx(win, last_y, last_x);
+	}
+	if (*prompt) {
+	    ++y;
+	    if (win != 0)
+		(void) wmove(win, y, lm);
+	}
+	max_x = MAX(max_x, x);
+    }
+    /* Move back to the last position after drawing prompt, for msgbox. */
+    if (win != 0)
+	(void) wmove(win, last_y, last_x);
+
+    /* Set the final height and width for the calling function */
+    if (high != 0)
+	*high = y;
+    if (wide != 0)
+	*wide = max_x;
+}
+
+/*
+ * Print a string of text in a window, automatically wrap around to the next
+ * line if the string is too long to fit on one line.  Note that the string may
+ * contain embedded newlines.
+ */
+void
+dlg_print_autowrap(WINDOW *win, const char *prompt, int height, int width)
+{
+    justify_text(win, prompt,
+		 height,
+		 width,
+		 (int *) 0, (int *) 0);
+}
+
+/*
+ * Display the message in a scrollable window.  Actually the way it works is
+ * that we create a "tall" window of the proper width, let the text wrap within
+ * that, and copy a slice of the result to the dialog.
+ *
+ * It works for ncurses.  Other curses implementations show only blanks (Tru64)
+ * or garbage (NetBSD).
+ */
+int
+dlg_print_scrolled(WINDOW *win,
+		   const char *prompt,
+		   int offset,
+		   int height,
+		   int width,
+		   int pauseopt)
+{
+    int oldy, oldx;
+    int last = 0;
+
+    (void) pauseopt;		/* used only for ncurses */
+
+    getyx(win, oldy, oldx);
+#ifdef NCURSES_VERSION
+    if (pauseopt) {
+	int wide = width - (2 * MARGIN);
+	int high = LINES;
+	int len;
+	WINDOW *dummy;
+
+#if defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH >= 20040417
+	/*
+	 * If we're not limited by the screensize, allow text to possibly be
+	 * one character per line.
+	 */
+	if ((len = dlg_count_columns(prompt)) > high)
+	    high = len;
+#endif
+	dummy = newwin(high, width, 0, 0);
+	if (dummy == 0) {
+	    dlg_attrset(win, dialog_attr);
+	    dlg_print_autowrap(win, prompt, height + 1 + (3 * MARGIN), width);
+	    last = 0;
+	} else {
+	    int y, x;
+
+	    wbkgdset(dummy, dialog_attr | ' ');
+	    dlg_attrset(dummy, dialog_attr);
+	    werase(dummy);
+	    dlg_print_autowrap(dummy, prompt, high, width);
+	    getyx(dummy, y, x);
+	    (void) x;
+
+	    copywin(dummy,	/* srcwin */
+		    win,	/* dstwin */
+		    offset + MARGIN,	/* sminrow */
+		    MARGIN,	/* smincol */
+		    MARGIN,	/* dminrow */
+		    MARGIN,	/* dmincol */
+		    height,	/* dmaxrow */
+		    wide,	/* dmaxcol */
+		    FALSE);
+
+	    delwin(dummy);
+
+	    /* if the text is incomplete, or we have scrolled, show the percentage */
+	    if (y > 0 && wide > 4) {
+		int percent = (int) ((height + offset) * 100.0 / y);
+
+		if (percent < 0)
+		    percent = 0;
+		if (percent > 100)
+		    percent = 100;
+
+		if (offset != 0 || percent != 100) {
+		    char buffer[5];
+
+		    dlg_attrset(win, position_indicator_attr);
+		    (void) wmove(win, MARGIN + height, wide - 4);
+		    (void) sprintf(buffer, "%d%%", percent);
+		    (void) waddstr(win, buffer);
+		    if ((len = (int) strlen(buffer)) < 4) {
+			dlg_attrset(win, border_attr);
+			whline(win, dlg_boxchar(ACS_HLINE), 4 - len);
+		    }
+		}
+	    }
+	    last = (y - height);
+	}
+    } else
+#endif
+    {
+	(void) offset;
+	dlg_attrset(win, dialog_attr);
+	dlg_print_autowrap(win, prompt, height + 1 + (3 * MARGIN), width);
+	last = 0;
+    }
+    wmove(win, oldy, oldx);
+    return last;
+}
+
+int
+dlg_check_scrolled(int key, int last, int page, bool * show, int *offset)
+{
+    int code = 0;
+
+    *show = FALSE;
+
+    switch (key) {
+    case DLGK_PAGE_FIRST:
+	if (*offset > 0) {
+	    *offset = 0;
+	    *show = TRUE;
+	}
+	break;
+    case DLGK_PAGE_LAST:
+	if (*offset < last) {
+	    *offset = last;
+	    *show = TRUE;
+	}
+	break;
+    case DLGK_GRID_UP:
+	if (*offset > 0) {
+	    --(*offset);
+	    *show = TRUE;
+	}
+	break;
+    case DLGK_GRID_DOWN:
+	if (*offset < last) {
+	    ++(*offset);
+	    *show = TRUE;
+	}
+	break;
+    case DLGK_PAGE_PREV:
+	if (*offset > 0) {
+	    *offset -= page;
+	    if (*offset < 0)
+		*offset = 0;
+	    *show = TRUE;
+	}
+	break;
+    case DLGK_PAGE_NEXT:
+	if (*offset < last) {
+	    *offset += page;
+	    if (*offset > last)
+		*offset = last;
+	    *show = TRUE;
+	}
+	break;
+    default:
+	code = -1;
+	break;
+    }
+    return code;
+}
+
+/*
+ * Calculate the window size for preformatted text.  This will calculate box
+ * dimensions that are at or close to the specified aspect ratio for the prompt
+ * string with all spaces and newlines preserved and additional newlines added
+ * as necessary.
+ */
+static void
+auto_size_preformatted(const char *prompt, int *height, int *width)
+{
+    int high = 0, wide = 0;
+    float car;			/* Calculated Aspect Ratio */
+    int max_y = SLINES - 1;
+    int max_x = SCOLS - 2;
+    int max_width = max_x;
+    int ar = dialog_state.aspect_ratio;
+
+    /* Get the initial dimensions */
+    justify_text((WINDOW *) 0, prompt, max_y, max_x, &high, &wide);
+    car = (float) (wide / high);
+
+    *height = high;
+    *width = wide;
+}
+
+/*
+ * Find the length of the longest "word" in the given string.  By setting the
+ * widget width at least this long, we can avoid splitting a word on the
+ * margin.
+ */
+static int
+longest_word(const char *string)
+{
+    int result = 0;
+
+    while (*string != '\0') {
+	int length = 0;
+	while (*string != '\0' && !isspace(UCH(*string))) {
+	    length++;
+	    string++;
+	}
+	result = MAX(result, length);
+	if (*string != '\0')
+	    string++;
+    }
+    return result;
+}
+
+/*
+ * if (height or width == -1) Maximize()
+ * if (height or width == 0), justify and return actual limits.
+ */
+static void
+real_auto_size(const char *title,
+	       const char *prompt,
+	       int *height, int *width,
+	       int boxlines, int mincols)
+{
+    int x = (dialog_vars.begin_set ? dialog_vars.begin_x : 2);
+    int y = (dialog_vars.begin_set ? dialog_vars.begin_y : 1);
+    int title_length = title ? dlg_count_columns(title) : 0;
+    int high;
+    int save_high = *height;
+    int save_wide = *width;
+    int max_high;
+    int max_wide;
+
+    if (prompt == 0) {
+	if (*height == 0)
+	    *height = -1;
+	if (*width == 0)
+	    *width = -1;
+    }
+
+    max_high = (*height < 0);
+    max_wide = (*width < 0);
+
+    if (*height > 0) {
+	high = *height;
+    } else {
+	high = SLINES - y;
+    }
+
+    if (*width <= 0) {
+	int wide;
+
+	if (prompt != 0) {
+	    wide = MAX(title_length, mincols);
+	    if (strchr(prompt, '\n') == 0) {
+		double val = (dialog_state.aspect_ratio *
+			      dlg_count_real_columns(prompt));
+		double xxx = sqrt(val);
+		int tmp = (int) xxx;
+		wide = MAX(wide, tmp);
+		wide = MAX(wide, longest_word(prompt));
+		justify_text((WINDOW *) 0, prompt, high, wide, height, width);
+	    } else {
+		auto_size_preformatted(prompt, height, width);
+	    }
+	} else {
+	    wide = SCOLS - x;
+	    justify_text((WINDOW *) 0, prompt, high, wide, height, width);
+	}
+    }
+
+    if (*width < title_length) {
+	justify_text((WINDOW *) 0, prompt, high, title_length, height, width);
+	*width = title_length;
+    }
+
+    dialog_state.text_height = *height;
+    dialog_state.text_width = *width;
+
+    if (*width < mincols && save_wide == 0)
+	*width = mincols;
+    if (prompt != 0) {
+	*width += ((2 * MARGIN) + SHADOW_COLS);
+	*height += boxlines + (2 * MARGIN);
+    }
+
+    if (save_high > 0)
+	*height = save_high;
+    if (save_wide > 0)
+	*width = save_wide;
+
+    if (max_high)
+	*height = SLINES - (dialog_vars.begin_set ? dialog_vars.begin_y : 0);
+    if (max_wide)
+	*width = SCOLS - (dialog_vars.begin_set ? dialog_vars.begin_x : 0);
+}
+
+/* End of real_auto_size() */
+
+void
+dlg_auto_size(const char *title,
+	      const char *prompt,
+	      int *height,
+	      int *width,
+	      int boxlines,
+	      int mincols)
+{
+    DLG_TRACE(("# dlg_auto_size(%d,%d) limits %d,%d\n",
+	       *height, *width,
+	       boxlines, mincols));
+
+    real_auto_size(title, prompt, height, width, boxlines, mincols);
+
+    if (*width > SCOLS) {
+	(*height)++;
+	*width = SCOLS;
+    }
+
+    if (*height > SLINES) {
+	*height = SLINES;
+    }
+    DLG_TRACE(("# ...dlg_auto_size(%d,%d) also %d,%d\n",
+	       *height, *width,
+	       dialog_state.text_height, dialog_state.text_width));
+}
+
+/*
+ * if (height or width == -1) Maximize()
+ * if (height or width == 0)
+ *    height=MIN(SLINES, num.lines in fd+n);
+ *    width=MIN(SCOLS, MAX(longer line+n, mincols));
+ */
+void
+dlg_auto_sizefile(const char *title,
+		  const char *file,
+		  int *height,
+		  int *width,
+		  int boxlines,
+		  int mincols)
+{
+    int count = 0;
+    int len = title ? dlg_count_columns(title) : 0;
+    int nc = 4;
+    int numlines = 2;
+    FILE *fd;
+
+    /* Open input file for reading */
+    if ((fd = fopen(file, "rb")) == NULL)
+	dlg_exiterr("dlg_auto_sizefile: Cannot open input file %s", file);
+
+    if ((*height == -1) || (*width == -1)) {
+	*height = SLINES - (dialog_vars.begin_set ? dialog_vars.begin_y : 0);
+	*width = SCOLS - (dialog_vars.begin_set ? dialog_vars.begin_x : 0);
+    }
+    if ((*height != 0) && (*width != 0)) {
+	(void) fclose(fd);
+	if (*width > SCOLS)
+	    *width = SCOLS;
+	if (*height > SLINES)
+	    *height = SLINES;
+	return;
+    }
+
+    while (!feof(fd)) {
+	int ch;
+	long offset;
+
+	if (ferror(fd))
+	    break;
+
+	offset = 0;
+	while (((ch = getc(fd)) != '\n') && !feof(fd)) {
+	    if ((ch == TAB) && (dialog_vars.tab_correct)) {
+		offset += dialog_state.tab_len - (offset % dialog_state.tab_len);
+	    } else {
+		offset++;
+	    }
+	}
+
+	if (offset > len)
+	    len = (int) offset;
+
+	count++;
+    }
+
+    /* now 'count' has the number of lines of fd and 'len' the max length */
+
+    *height = MIN(SLINES, count + numlines + boxlines);
+    *width = MIN(SCOLS, MAX((len + nc), mincols));
+    /* here width and height can be maximized if > SCOLS|SLINES because
+       textbox-like widgets don't put all <file> on the screen.
+       Msgbox-like widget instead have to put all <text> correctly. */
+
+    (void) fclose(fd);
+}
+
+/*
+ * Draw a rectangular box with line drawing characters.
+ *
+ * borderchar is used to color the upper/left edges.
+ *
+ * boxchar is used to color the right/lower edges.  It also is fill-color used
+ * for the box contents.
+ *
+ * Normally, if you are drawing a scrollable box, use menubox_border_attr for
+ * boxchar, and menubox_attr for borderchar since the scroll-arrows are drawn
+ * with menubox_attr at the top, and menubox_border_attr at the bottom.  That
+ * also (given the default color choices) produces a recessed effect.
+ *
+ * If you want a raised effect (and are not going to use the scroll-arrows),
+ * reverse this choice.
+ */
+void
+dlg_draw_box2(WINDOW *win, int y, int x, int height, int width,
+	      chtype boxchar, chtype borderchar, chtype borderchar2)
+{
+    int i, j;
+    chtype save = dlg_get_attrs(win);
+
+    dlg_attrset(win, 0);
+    for (i = 0; i < height; i++) {
+	(void) wmove(win, y + i, x);
+	for (j = 0; j < width; j++)
+	    if (!i && !j)
+		(void) waddch(win, borderchar | dlg_boxchar(ACS_ULCORNER));
+	    else if (i == height - 1 && !j)
+		(void) waddch(win, borderchar | dlg_boxchar(ACS_LLCORNER));
+	    else if (!i && j == width - 1)
+		(void) waddch(win, borderchar2 | dlg_boxchar(ACS_URCORNER));
+	    else if (i == height - 1 && j == width - 1)
+		(void) waddch(win, borderchar2 | dlg_boxchar(ACS_LRCORNER));
+	    else if (!i)
+		(void) waddch(win, borderchar | dlg_boxchar(ACS_HLINE));
+	    else if (i == height - 1)
+		(void) waddch(win, borderchar2 | dlg_boxchar(ACS_HLINE));
+	    else if (!j)
+		(void) waddch(win, borderchar | dlg_boxchar(ACS_VLINE));
+	    else if (j == width - 1)
+		(void) waddch(win, borderchar2 | dlg_boxchar(ACS_VLINE));
+	    else
+		(void) waddch(win, boxchar | ' ');
+    }
+    dlg_attrset(win, save);
+}
+
+void
+dlg_draw_box(WINDOW *win, int y, int x, int height, int width,
+	     chtype boxchar, chtype borderchar)
+{
+    dlg_draw_box2(win, y, x, height, width, boxchar, borderchar, boxchar);
+}
+
+/*
+ * Search the given 'list' for the given window 'win'.  Typically 'win' is an
+ * input-window, i.e., a window where we might use wgetch.
+ *
+ * The all-windows list has normal- and shadow-windows.  Since we never use the
+ * shadow as an input window, normally we just look for the normal-window.
+ *
+ * However, the all-subwindows list stores parent/child windows rather than
+ * normal/shadow windows.  When searching that list, we look for the child
+ * window (in the .shadow field).
+ */
+static DIALOG_WINDOWS *
+find_window(DIALOG_WINDOWS * list, WINDOW *win, bool normal)
+{
+    DIALOG_WINDOWS *result = 0;
+    DIALOG_WINDOWS *p;
+
+    for (p = list; p != 0; p = p->next) {
+	WINDOW *check = normal ? p->normal : p->shadow;
+	if (check == win) {
+	    result = p;
+	    break;
+	}
+    }
+    return result;
+}
+
+#define SearchTopWindows(win) find_window(dialog_state.all_windows, win, TRUE)
+#define SearchSubWindows(win) find_window(dialog_state.all_subwindows, win, FALSE)
+
+/*
+ * Check for the existence of a window, e.g., when used for input or updating
+ * the display.  This is used in dlg_getc() and related functions, to guard
+ * against an asynchronous window-deletion that might invalidate the input
+ * window used in dlg_getc().
+ */
+DIALOG_WINDOWS *
+_dlg_find_window(WINDOW *win)
+{
+    DIALOG_WINDOWS *result = 0;
+
+    if ((result = SearchTopWindows(win)) == NULL)
+	result = SearchSubWindows(win);
+    return result;
+}
+
+#ifdef HAVE_COLOR
+/*
+ * If we have wchgat(), use that for updating shadow attributes, to work with
+ * wide-character data.
+ */
+
+/*
+ * Check if the given point is "in" the given window.  If so, return the window
+ * pointer, otherwise null.
+ */
+static WINDOW *
+in_window(WINDOW *win, int y, int x)
+{
+    WINDOW *result = 0;
+    int y_base = getbegy(win);
+    int x_base = getbegx(win);
+    int y_last = getmaxy(win) + y_base;
+    int x_last = getmaxx(win) + x_base;
+
+    if (y >= y_base && y <= y_last && x >= x_base && x <= x_last)
+	result = win;
+    return result;
+}
+
+static WINDOW *
+window_at_cell(DIALOG_WINDOWS * dw, int y, int x)
+{
+    WINDOW *result = 0;
+    DIALOG_WINDOWS *p;
+    int y_want = y + getbegy(dw->shadow);
+    int x_want = x + getbegx(dw->shadow);
+
+    for (p = dialog_state.all_windows; p != 0; p = p->next) {
+	if (dw->normal != p->normal
+	    && dw->shadow != p->normal
+	    && (result = in_window(p->normal, y_want, x_want)) != 0) {
+	    break;
+	}
+    }
+    if (result == 0) {
+	result = stdscr;
+    }
+    return result;
+}
+
+static bool
+in_shadow(WINDOW *normal, WINDOW *shadow, int y, int x)
+{
+    bool result = FALSE;
+    int ybase = getbegy(normal);
+    int ylast = getmaxy(normal) + ybase;
+    int xbase = getbegx(normal);
+    int xlast = getmaxx(normal) + xbase;
+
+    y += getbegy(shadow);
+    x += getbegx(shadow);
+
+    if (y >= ybase + SHADOW_ROWS
+	&& y < ylast + SHADOW_ROWS
+	&& x >= xlast
+	&& x < xlast + SHADOW_COLS) {
+	/* in the right-side */
+	result = TRUE;
+    } else if (y >= ylast
+	       && y < ylast + SHADOW_ROWS
+	       && x >= ybase + SHADOW_COLS
+	       && x < ylast + SHADOW_COLS) {
+	/* check the bottom */
+	result = TRUE;
+    }
+
+    return result;
+}
+
+/*
+ * When erasing a shadow, check each cell to make sure that it is not part of
+ * another box's shadow.  This is a little complicated since most shadows are
+ * merged onto stdscr.
+ */
+static bool
+last_shadow(DIALOG_WINDOWS * dw, int y, int x)
+{
+    DIALOG_WINDOWS *p;
+    bool result = TRUE;
+
+    for (p = dialog_state.all_windows; p != 0; p = p->next) {
+	if (p->normal != dw->normal
+	    && in_shadow(p->normal, dw->shadow, y, x)) {
+	    result = FALSE;
+	    break;
+	}
+    }
+    return result;
+}
+
+static void
+repaint_cell(DIALOG_WINDOWS * dw, bool draw, int y, int x)
+{
+    WINDOW *win = dw->shadow;
+    WINDOW *cellwin;
+    int y2, x2;
+
+    if ((cellwin = window_at_cell(dw, y, x)) != 0
+	&& (draw || last_shadow(dw, y, x))
+	&& (y2 = (y + getbegy(win) - getbegy(cellwin))) >= 0
+	&& (x2 = (x + getbegx(win) - getbegx(cellwin))) >= 0
+	&& wmove(cellwin, y2, x2) != ERR) {
+	chtype the_cell = dlg_get_attrs(cellwin);
+	chtype the_attr = (draw ? shadow_attr : the_cell);
+
+	if (winch(cellwin) & A_ALTCHARSET) {
+	    the_attr |= A_ALTCHARSET;
+	}
+#if USE_WCHGAT
+	wchgat(cellwin, 1,
+	       the_attr & (chtype) (~A_COLOR),
+	       (short) PAIR_NUMBER(the_attr),
+	       NULL);
+#else
+	{
+	    chtype the_char = ((winch(cellwin) & A_CHARTEXT) | the_attr);
+	    (void) waddch(cellwin, the_char);
+	}
+#endif
+	wnoutrefresh(cellwin);
+    }
+}
+
+#define RepaintCell(dw, draw, y, x) repaint_cell(dw, draw, y, x)
+
+static void
+repaint_shadow(DIALOG_WINDOWS * dw, bool draw, int y, int x, int height, int width)
+{
+    if (UseShadow(dw)) {
+	int i, j;
+
+#if !USE_WCHGAT
+	chtype save = dlg_get_attrs(dw->shadow);
+	dlg_attrset(dw->shadow, draw ? shadow_attr : screen_attr);
+#endif
+	for (i = 0; i < SHADOW_ROWS; ++i) {
+	    for (j = 0; j < width; ++j) {
+		RepaintCell(dw, draw, i + y + height, j + x + SHADOW_COLS);
+	    }
+	}
+	for (i = 0; i < height; i++) {
+	    for (j = 0; j < SHADOW_COLS; ++j) {
+		RepaintCell(dw, draw, i + y + SHADOW_ROWS, j + x + width);
+	    }
+	}
+	(void) wnoutrefresh(dw->shadow);
+#if !USE_WCHGAT
+	dlg_attrset(dw->shadow, save);
+#endif
+    }
+}
+
+/*
+ * Draw a shadow on the parent window corresponding to the right- and
+ * bottom-edge of the child window, to give a 3-dimensional look.
+ */
+static void
+draw_childs_shadow(DIALOG_WINDOWS * dw)
+{
+    if (UseShadow(dw)) {
+	repaint_shadow(dw,
+		       TRUE,
+		       getbegy(dw->normal) - getbegy(dw->shadow),
+		       getbegx(dw->normal) - getbegx(dw->shadow),
+		       getmaxy(dw->normal),
+		       getmaxx(dw->normal));
+    }
+}
+
+/*
+ * Erase a shadow on the parent window corresponding to the right- and
+ * bottom-edge of the child window.
+ */
+static void
+erase_childs_shadow(DIALOG_WINDOWS * dw)
+{
+    if (UseShadow(dw)) {
+	repaint_shadow(dw,
+		       FALSE,
+		       getbegy(dw->normal) - getbegy(dw->shadow),
+		       getbegx(dw->normal) - getbegx(dw->shadow),
+		       getmaxy(dw->normal),
+		       getmaxx(dw->normal));
+    }
+}
+
+/*
+ * Draw shadows along the right and bottom edge to give a more 3D look
+ * to the boxes.
+ */
+void
+dlg_draw_shadow(WINDOW *win, int y, int x, int height, int width)
+{
+    repaint_shadow(SearchTopWindows(win), TRUE, y, x, height, width);
+}
+#endif /* HAVE_COLOR */
+
+/*
+ * Allow shell scripts to remap the exit codes so they can distinguish ESC
+ * from ERROR.
+ */
+void
+dlg_exit(int code)
+{
+    /* *INDENT-OFF* */
+    static const struct {
+	int code;
+	const char *name;
+    } table[] = {
+	{ DLG_EXIT_CANCEL, 	"DIALOG_CANCEL" },
+	{ DLG_EXIT_ERROR,  	"DIALOG_ERROR" },
+	{ DLG_EXIT_ESC,	   	"DIALOG_ESC" },
+	{ DLG_EXIT_EXTRA,  	"DIALOG_EXTRA" },
+	{ DLG_EXIT_HELP,   	"DIALOG_HELP" },
+	{ DLG_EXIT_OK,	   	"DIALOG_OK" },
+	{ DLG_EXIT_ITEM_HELP,	"DIALOG_ITEM_HELP" },
+	{ DLG_EXIT_TIMEOUT,	"DIALOG_TIMEOUT" },
+    };
+    /* *INDENT-ON* */
+
+    unsigned n;
+    bool overridden = FALSE;
+
+  retry:
+    for (n = 0; n < TableSize(table); n++) {
+	if (table[n].code == code) {
+	    if (dlg_getenv_num(table[n].name, &code)) {
+		overridden = TRUE;
+	    }
+	    break;
+	}
+    }
+
+    /*
+     * Prior to 2004/12/19, a widget using --item-help would exit with "OK"
+     * if the help button were selected.  Now we want to exit with "HELP",
+     * but allow the environment variable to override.
+     */
+    if (code == DLG_EXIT_ITEM_HELP && !overridden) {
+	code = DLG_EXIT_HELP;
+	goto retry;
+    }
+#ifdef HAVE_DLG_TRACE
+    dlg_trace((const char *) 0);	/* close it */
+#endif
+
+#ifdef NO_LEAKS
+    _dlg_inputstr_leaks();
+#if defined(NCURSES_VERSION) && (defined(HAVE_EXIT_CURSES) || defined(HAVE__NC_FREE_AND_EXIT))
+    exit_curses(code);
+#endif
+#endif
+
+    if (dialog_state.input == stdin) {
+	exit(code);
+    } else {
+	/*
+	 * Just in case of using --input-fd option, do not
+	 * call atexit functions of ncurses which may hang.
+	 */
+	if (dialog_state.input) {
+	    fclose(dialog_state.input);
+	    dialog_state.input = 0;
+	}
+	if (dialog_state.pipe_input) {
+	    if (dialog_state.pipe_input != stdin) {
+		fclose(dialog_state.pipe_input);
+		dialog_state.pipe_input = 0;
+	    }
+	}
+	_exit(code);
+    }
+}
+
+#define DATA(name) { DLG_EXIT_ ## name, #name }
+/* *INDENT-OFF* */
+static struct {
+    int code;
+    const char *name;
+} exit_codenames[] = {
+    DATA(ESC),
+    DATA(UNKNOWN),
+    DATA(ERROR),
+    DATA(OK),
+    DATA(CANCEL),
+    DATA(HELP),
+    DATA(EXTRA),
+    DATA(ITEM_HELP),
+};
+#undef DATA
+/* *INDENT-ON* */
+
+const char *
+dlg_exitcode2s(int code)
+{
+    const char *result = "?";
+    size_t n;
+
+    for (n = 0; n < TableSize(exit_codenames); ++n) {
+	if (exit_codenames[n].code == code) {
+	    result = exit_codenames[n].name;
+	    break;
+	}
+    }
+    return result;
+}
+
+int
+dlg_exitname2n(const char *name)
+{
+    int result = DLG_EXIT_UNKNOWN;
+    size_t n;
+
+    for (n = 0; n < TableSize(exit_codenames); ++n) {
+	if (!dlg_strcmp(exit_codenames[n].name, name)) {
+	    result = exit_codenames[n].code;
+	    break;
+	}
+    }
+    return result;
+}
+
+/* quit program killing all tailbg */
+void
+dlg_exiterr(const char *fmt, ...)
+{
+    int retval;
+    va_list ap;
+
+    end_dialog();
+
+    (void) fputc('\n', stderr);
+    va_start(ap, fmt);
+    (void) vfprintf(stderr, fmt, ap);
+    va_end(ap);
+    (void) fputc('\n', stderr);
+
+#ifdef HAVE_DLG_TRACE
+    va_start(ap, fmt);
+    dlg_trace_msg("## Error: ");
+    dlg_trace_va_msg(fmt, ap);
+    va_end(ap);
+#endif
+
+    dlg_killall_bg(&retval);
+
+    (void) fflush(stderr);
+    (void) fflush(stdout);
+    dlg_exit(strcmp(fmt, "timeout") == 0 ? DLG_EXIT_TIMEOUT : DLG_EXIT_ERROR);
+}
+
+/*
+ * Get a string from the environment, rejecting those which are entirely blank.
+ */
+char *
+dlg_getenv_str(const char *name)
+{
+    char *result = getenv(name);
+    if (result != NULL) {
+	while (*result != '\0' && isspace(UCH(*result)))
+	    ++result;
+	if (*result == '\0')
+	    result = NULL;
+    }
+    return result;
+}
+
+/*
+ * Get a number from the environment:
+ * + If the caller provides a pointer in the second parameter, return
+ *   success/failure for the function return, and the actual value via the
+ *   pointer.  Use this for decoding arbitrary numbers, e.g., negative or zero.
+ * + If the caller does not provide a pointer, return the decoded value for
+ *   the function-return.  Use this when only values greater than zero are
+ *   useful.
+ */
+int
+dlg_getenv_num(const char *name, int *value)
+{
+    int result = 0;
+    char *data = getenv(name);
+    if (data != NULL) {
+	char *temp = NULL;
+	long check = strtol(data, &temp, 0);
+	if (temp != 0 && temp != data && *temp == '\0') {
+	    result = (int) check;
+	    if (value != NULL) {
+		*value = result;
+		result = 1;
+	    }
+	}
+    }
+    return result;
+}
+
+void
+dlg_beeping(void)
+{
+    if (dialog_vars.beep_signal) {
+	(void) beep();
+	dialog_vars.beep_signal = 0;
+    }
+}
+
+void
+dlg_print_size(int height, int width)
+{
+    if (dialog_vars.print_siz) {
+	fprintf(dialog_state.output, "Size: %d, %d\n", height, width);
+	DLG_TRACE(("# print size: %dx%d\n", height, width));
+    }
+}
+
+void
+dlg_ctl_size(int height, int width)
+{
+    if (dialog_vars.size_err) {
+	if ((width > COLS) || (height > LINES)) {
+	    dlg_exiterr("Window too big. (height, width) = (%d, %d). Max allowed (%d, %d).",
+			height, width, LINES, COLS);
+	}
+#ifdef HAVE_COLOR
+	else if ((dialog_state.use_shadow)
+		 && ((width > SCOLS || height > SLINES))) {
+	    if ((width <= COLS) && (height <= LINES)) {
+		/* try again, without shadows */
+		dialog_state.use_shadow = 0;
+	    } else {
+		dlg_exiterr("Window+Shadow too big. (height, width) = (%d, %d). Max allowed (%d, %d).",
+			    height, width, SLINES, SCOLS);
+	    }
+	}
+#endif
+    }
+}
+
+/*
+ * If the --tab-correct was not selected, convert tabs to single spaces.
+ */
+void
+dlg_tab_correct_str(char *prompt)
+{
+    char *ptr;
+
+    if (dialog_vars.tab_correct) {
+	while ((ptr = strchr(prompt, TAB)) != NULL) {
+	    *ptr = ' ';
+	    prompt = ptr;
+	}
+    }
+}
+
+void
+dlg_calc_listh(int *height, int *list_height, int item_no)
+{
+    /* calculate new height and list_height */
+    int rows = SLINES - (dialog_vars.begin_set ? dialog_vars.begin_y : 0);
+    if (rows - (*height) > 0) {
+	if (rows - (*height) > item_no)
+	    *list_height = item_no;
+	else
+	    *list_height = rows - (*height);
+    }
+    (*height) += (*list_height);
+}
+
+/* obsolete */
+int
+dlg_calc_listw(int item_no, char **items, int group)
+{
+    int i, len1 = 0, len2 = 0;
+
+    for (i = 0; i < (item_no * group); i += group) {
+	int n;
+
+	if ((n = dlg_count_columns(items[i])) > len1)
+	    len1 = n;
+	if ((n = dlg_count_columns(items[i + 1])) > len2)
+	    len2 = n;
+    }
+    return len1 + len2;
+}
+
+int
+dlg_calc_list_width(int item_no, DIALOG_LISTITEM * items)
+{
+    int n, i, len1 = 0, len2 = 0;
+    int bits = ((dialog_vars.no_tags ? 1 : 0)
+		+ (dialog_vars.no_items ? 2 : 0));
+
+    for (i = 0; i < item_no; ++i) {
+	switch (bits) {
+	case 0:
+	    /* FALLTHRU */
+	case 1:
+	    if ((n = dlg_count_columns(items[i].name)) > len1)
+		len1 = n;
+	    if ((n = dlg_count_columns(items[i].text)) > len2)
+		len2 = n;
+	    break;
+	case 2:
+	    /* FALLTHRU */
+	case 3:
+	    if ((n = dlg_count_columns(items[i].name)) > len1)
+		len1 = n;
+	    break;
+	}
+    }
+    return len1 + len2;
+}
+
+char *
+dlg_strempty(void)
+{
+    static char empty[] = "";
+    return empty;
+}
+
+char *
+dlg_strclone(const char *cprompt)
+{
+    char *prompt = 0;
+    if (cprompt != 0) {
+	prompt = dlg_malloc(char, strlen(cprompt) + 1);
+	assert_ptr(prompt, "dlg_strclone");
+	strcpy(prompt, cprompt);
+    }
+    return prompt;
+}
+
+chtype
+dlg_asciibox(chtype ch)
+{
+    chtype result = 0;
+
+    if (ch == ACS_ULCORNER)
+	result = '+';
+    else if (ch == ACS_LLCORNER)
+	result = '+';
+    else if (ch == ACS_URCORNER)
+	result = '+';
+    else if (ch == ACS_LRCORNER)
+	result = '+';
+    else if (ch == ACS_HLINE)
+	result = '-';
+    else if (ch == ACS_VLINE)
+	result = '|';
+    else if (ch == ACS_LTEE)
+	result = '+';
+    else if (ch == ACS_RTEE)
+	result = '+';
+    else if (ch == ACS_UARROW)
+	result = '^';
+    else if (ch == ACS_DARROW)
+	result = 'v';
+
+    return result;
+}
+
+chtype
+dlg_boxchar(chtype ch)
+{
+    chtype result = dlg_asciibox(ch);
+
+    if (result != 0) {
+	if (dialog_vars.ascii_lines)
+	    ch = result;
+	else if (dialog_vars.no_lines)
+	    ch = ' ';
+    }
+    return ch;
+}
+
+int
+dlg_box_x_ordinate(int width)
+{
+    int x;
+
+    if (dialog_vars.begin_set == 1) {
+	x = dialog_vars.begin_x;
+    } else {
+	/* center dialog box on screen unless --begin-set */
+	x = (SCOLS - width) / 2;
+    }
+    return x;
+}
+
+int
+dlg_box_y_ordinate(int height)
+{
+    int y;
+
+    if (dialog_vars.begin_set == 1) {
+	y = dialog_vars.begin_y;
+    } else {
+	/* center dialog box on screen unless --begin-set */
+	y = (SLINES - height) / 2;
+    }
+    return y;
+}
+
+void
+dlg_draw_title(WINDOW *win, const char *title)
+{
+    if (title != NULL) {
+	chtype attr = A_NORMAL;
+	chtype save = dlg_get_attrs(win);
+	int x = centered(getmaxx(win), title);
+
+	dlg_attrset(win, title_attr);
+	wmove(win, 0, x);
+	dlg_print_text(win, title, getmaxx(win) - x, &attr);
+	dlg_attrset(win, save);
+	dlg_finish_string(title);
+    }
+}
+
+void
+dlg_draw_bottom_box2(WINDOW *win, chtype on_left, chtype on_right, chtype on_inside)
+{
+    int width = getmaxx(win);
+    int height = getmaxy(win);
+    int i;
+
+    dlg_attrset(win, on_left);
+    (void) wmove(win, height - 3, 0);
+    (void) waddch(win, dlg_boxchar(ACS_LTEE));
+    for (i = 0; i < width - 2; i++)
+	(void) waddch(win, dlg_boxchar(ACS_HLINE));
+    dlg_attrset(win, on_right);
+    (void) waddch(win, dlg_boxchar(ACS_RTEE));
+    dlg_attrset(win, on_inside);
+    (void) wmove(win, height - 2, 1);
+    for (i = 0; i < width - 2; i++)
+	(void) waddch(win, ' ');
+}
+
+void
+dlg_draw_bottom_box(WINDOW *win)
+{
+    dlg_draw_bottom_box2(win, border_attr, dialog_attr, dialog_attr);
+}
+
+/*
+ * Remove a window, repainting everything else.  This would be simpler if we
+ * used the panel library, but that is not _always_ available.
+ */
+void
+dlg_del_window(WINDOW *win)
+{
+    DIALOG_WINDOWS *p, *q, *r;
+
+    /*
+     * If --keep-window was set, do not delete/repaint the windows.
+     */
+    if (dialog_vars.keep_window)
+	return;
+
+    /* Leave the main window untouched if there are no background windows.
+     * We do this so the current window will not be cleared on exit, allowing
+     * things like the infobox demo to run without flicker.
+     */
+    if (dialog_state.getc_callbacks != 0) {
+	touchwin(stdscr);
+	wnoutrefresh(stdscr);
+    }
+
+    for (p = dialog_state.all_windows, q = r = 0; p != 0; r = p, p = p->next) {
+	if (p->normal == win) {
+	    q = p;		/* found a match - should be only one */
+	    if (r == 0) {
+		dialog_state.all_windows = p->next;
+	    } else {
+		r->next = p->next;
+	    }
+	} else {
+	    if (p->shadow != 0) {
+		touchwin(p->shadow);
+		wnoutrefresh(p->shadow);
+	    }
+	    touchwin(p->normal);
+	    wnoutrefresh(p->normal);
+	}
+    }
+
+    if (q) {
+	if (dialog_state.all_windows != 0)
+	    erase_childs_shadow(q);
+	del_subwindows(q->normal);
+	dlg_unregister_window(q->normal);
+	delwin(q->normal);
+	free(q);
+    }
+    doupdate();
+}
+
+/*
+ * Create a window, optionally with a shadow.
+ */
+WINDOW *
+dlg_new_window(int height, int width, int y, int x)
+{
+    return dlg_new_modal_window(stdscr, height, width, y, x);
+}
+
+/*
+ * "Modal" windows differ from normal ones by having a shadow in a window
+ * separate from the standard screen.
+ */
+WINDOW *
+dlg_new_modal_window(WINDOW *parent, int height, int width, int y, int x)
+{
+    WINDOW *win;
+    DIALOG_WINDOWS *p = dlg_calloc(DIALOG_WINDOWS, 1);
+
+    (void) parent;
+    if (p == 0
+	|| (win = newwin(height, width, y, x)) == 0) {
+	dlg_exiterr("Can't make new window at (%d,%d), size (%d,%d).\n",
+		    y, x, height, width);
+    }
+    p->next = dialog_state.all_windows;
+    p->normal = win;
+    p->getc_timeout = WTIMEOUT_OFF;
+    dialog_state.all_windows = p;
+#ifdef HAVE_COLOR
+    if (dialog_state.use_shadow) {
+	p->shadow = parent;
+	draw_childs_shadow(p);
+    }
+#endif
+
+    (void) keypad(win, TRUE);
+    return win;
+}
+
+/*
+ * dlg_getc() uses the return-value to determine how to handle an ERR return
+ * from a non-blocking read:
+ * a) if greater than zero, there was an expired timeout (blocking for a short
+ *    time), or
+ * b) if zero, it was a non-blocking read, or
+ * c) if negative, an error occurred on a blocking read.
+ */
+int
+dlg_set_timeout(WINDOW *win, bool will_getc)
+{
+    DIALOG_WINDOWS *p;
+    int result = 0;
+
+    if ((p = SearchTopWindows(win)) != NULL) {
+	int interval = (dialog_vars.timeout_secs * 1000);
+
+	if (will_getc || dialog_vars.pause_secs) {
+	    interval = WTIMEOUT_VAL;
+	} else {
+	    result = interval;
+	    if (interval <= 0) {
+		interval = WTIMEOUT_OFF;
+	    }
+	}
+	wtimeout(win, interval);
+	p->getc_timeout = interval;
+    }
+    return result;
+}
+
+void
+dlg_reset_timeout(WINDOW *win)
+{
+    DIALOG_WINDOWS *p;
+
+    if ((p = SearchTopWindows(win)) != NULL) {
+	wtimeout(win, p->getc_timeout);
+    } else {
+	wtimeout(win, WTIMEOUT_OFF);
+    }
+}
+
+/*
+ * Move/Resize a window, optionally with a shadow.
+ */
+#ifdef KEY_RESIZE
+void
+dlg_move_window(WINDOW *win, int height, int width, int y, int x)
+{
+    if (win != 0) {
+	DIALOG_WINDOWS *p;
+
+	dlg_ctl_size(height, width);
+
+	if ((p = SearchTopWindows(win)) != 0) {
+	    (void) wresize(win, height, width);
+	    (void) mvwin(win, y, x);
+#ifdef HAVE_COLOR
+	    if (p->shadow != 0) {
+		if (dialog_state.use_shadow) {
+		    (void) mvwin(p->shadow, y + SHADOW_ROWS, x + SHADOW_COLS);
+		} else {
+		    p->shadow = 0;
+		}
+	    }
+#endif
+	    (void) refresh();
+
+#ifdef HAVE_COLOR
+	    draw_childs_shadow(p);
+#endif
+	}
+    }
+}
+
+/*
+ * Having just received a KEY_RESIZE, wait a short time to ignore followup
+ * KEY_RESIZE events.
+ */
+void
+dlg_will_resize(WINDOW *win)
+{
+    int n, base;
+    int caught = 0;
+
+    dialog_state.had_resize = TRUE;
+    dlg_trace_win(win);
+    wtimeout(win, WTIMEOUT_VAL * 5);
+
+    for (n = base = 0; n < base + 10; ++n) {
+	int ch;
+
+	if ((ch = wgetch(win)) != ERR) {
+	    if (ch == KEY_RESIZE) {
+		base = n;
+		++caught;
+	    } else if (ch != ERR) {
+		ungetch(ch);
+		break;
+	    }
+	}
+    }
+    dlg_reset_timeout(win);
+    DLG_TRACE(("# caught %d KEY_RESIZE key%s\n",
+	       1 + caught,
+	       caught == 1 ? "" : "s"));
+}
+#endif /* KEY_RESIZE */
+
+WINDOW *
+dlg_der_window(WINDOW *parent, int height, int width, int y, int x)
+{
+    WINDOW *win;
+
+    /* existing uses of derwin are (almost) guaranteed to succeed, and the
+     * caller has to allow for failure.
+     */
+    if ((win = derwin(parent, height, width, y, x)) != 0) {
+	add_subwindow(parent, win);
+	(void) keypad(win, TRUE);
+    }
+    return win;
+}
+
+WINDOW *
+dlg_sub_window(WINDOW *parent, int height, int width, int y, int x)
+{
+    WINDOW *win;
+
+    if ((win = subwin(parent, height, width, y, x)) == 0) {
+	dlg_exiterr("Can't make sub-window at (%d,%d), size (%d,%d).\n",
+		    y, x, height, width);
+    }
+
+    add_subwindow(parent, win);
+    (void) keypad(win, TRUE);
+    return win;
+}
+
+/* obsolete */
+int
+dlg_default_item(char **items, int llen)
+{
+    int result = 0;
+
+    if (dialog_vars.default_item != 0) {
+	int count = 0;
+	while (*items != 0) {
+	    if (!strcmp(dialog_vars.default_item, *items)) {
+		result = count;
+		break;
+	    }
+	    items += llen;
+	    count++;
+	}
+    }
+    return result;
+}
+
+int
+dlg_default_listitem(DIALOG_LISTITEM * items)
+{
+    int result = 0;
+
+    if (dialog_vars.default_item != 0) {
+	int count = 0;
+	while (items->name != 0) {
+	    if (!strcmp(dialog_vars.default_item, items->name)) {
+		result = count;
+		break;
+	    }
+	    ++items;
+	    count++;
+	}
+    }
+    return result;
+}
+
+/*
+ * Draw the string for item_help
+ */
+void
+dlg_item_help(const char *txt)
+{
+    if (USE_ITEM_HELP(txt)) {
+	chtype attr = A_NORMAL;
+
+	dlg_attrset(stdscr, itemhelp_attr);
+	(void) wmove(stdscr, LINES - 1, 0);
+	(void) wclrtoeol(stdscr);
+	(void) addch(' ');
+	dlg_print_text(stdscr, txt, COLS - 1, &attr);
+
+	if (itemhelp_attr & A_COLOR) {
+	    int y, x;
+	    /* fill the remainder of the line with the window's attributes */
+	    getyx(stdscr, y, x);
+	    (void) y;
+	    while (x < COLS) {
+		(void) addch(' ');
+		++x;
+	    }
+	}
+	(void) wnoutrefresh(stdscr);
+    }
+}
+
+#ifndef HAVE_STRCASECMP
+int
+dlg_strcmp(const char *a, const char *b)
+{
+    int ac, bc, cmp;
+
+    for (;;) {
+	ac = UCH(*a++);
+	bc = UCH(*b++);
+	if (isalpha(ac) && islower(ac))
+	    ac = _toupper(ac);
+	if (isalpha(bc) && islower(bc))
+	    bc = _toupper(bc);
+	cmp = ac - bc;
+	if (ac == 0 || bc == 0 || cmp != 0)
+	    break;
+    }
+    return cmp;
+}
+#endif
+
+/*
+ * Returns true if 'dst' points to a blank which follows another blank which
+ * is not a leading blank on a line.
+ */
+static bool
+trim_blank(char *base, char *dst)
+{
+    int count = !!isblank(UCH(*dst));
+
+    while (dst-- != base) {
+	if (*dst == '\n') {
+	    break;
+	} else if (isblank(UCH(*dst))) {
+	    count++;
+	} else {
+	    break;
+	}
+    }
+    return (count > 1);
+}
+
+/*
+ * Change embedded "\n" substrings to '\n' characters and tabs to single
+ * spaces.  If there are no "\n"s, it will strip all extra spaces, for
+ * justification.  If it has "\n"'s, it will preserve extra spaces.  If cr_wrap
+ * is set, it will preserve '\n's.
+ */
+void
+dlg_trim_string(char *s)
+{
+    char *base = s;
+    char *p1;
+    char *p = s;
+    int has_newlines = !dialog_vars.no_nl_expand && (strstr(s, "\\n") != 0);
+
+    while (*p != '\0') {
+	if (*p == TAB && !dialog_vars.nocollapse)
+	    *p = ' ';
+
+	if (has_newlines) {	/* If prompt contains "\n" strings */
+	    if (*p == '\\' && *(p + 1) == 'n') {
+		*s++ = '\n';
+		p += 2;
+		p1 = p;
+		/*
+		 * Handle end of lines intelligently.  If '\n' follows "\n"
+		 * then ignore the '\n'.  This eliminates the need to escape
+		 * the '\n' character (no need to use "\n\").
+		 */
+		while (isblank(UCH(*p1)))
+		    p1++;
+		if (*p1 == '\n')
+		    p = p1 + 1;
+	    } else if (*p == '\n') {
+		if (dialog_vars.cr_wrap)
+		    *s++ = *p++;
+		else {
+		    /* Replace the '\n' with a space if cr_wrap is not set */
+		    if (!trim_blank(base, p))
+			*s++ = ' ';
+		    p++;
+		}
+	    } else		/* If *p != '\n' */
+		*s++ = *p++;
+	} else if (dialog_vars.trim_whitespace) {
+	    if (isblank(UCH(*p))) {
+		if (!isblank(UCH(*(s - 1)))) {
+		    *s++ = ' ';
+		    p++;
+		} else
+		    p++;
+	    } else if (*p == '\n') {
+		if (dialog_vars.cr_wrap)
+		    *s++ = *p++;
+		else if (!isblank(UCH(*(s - 1)))) {
+		    /* Strip '\n's if cr_wrap is not set. */
+		    *s++ = ' ';
+		    p++;
+		} else
+		    p++;
+	    } else
+		*s++ = *p++;
+	} else {		/* If there are no "\n" strings */
+	    if (isblank(UCH(*p)) && !dialog_vars.nocollapse) {
+		if (!trim_blank(base, p))
+		    *s++ = *p;
+		p++;
+	    } else
+		*s++ = *p++;
+	}
+    }
+
+    *s = '\0';
+}
+
+void
+dlg_set_focus(WINDOW *parent, WINDOW *win)
+{
+    if (win != 0) {
+	(void) wmove(parent,
+		     getpary(win) + getcury(win),
+		     getparx(win) + getcurx(win));
+	(void) wnoutrefresh(win);
+	(void) doupdate();
+    }
+}
+
+/*
+ * Returns the nominal maximum buffer size.
+ */
+int
+dlg_max_input(int max_len)
+{
+    if (dialog_vars.max_input != 0 && dialog_vars.max_input < MAX_LEN)
+	max_len = dialog_vars.max_input;
+
+    return max_len;
+}
+
+/*
+ * Free storage used for the result buffer.
+ */
+void
+dlg_clr_result(void)
+{
+    if (dialog_vars.input_length) {
+	dialog_vars.input_length = 0;
+	if (dialog_vars.input_result)
+	    free(dialog_vars.input_result);
+    }
+    dialog_vars.input_result = 0;
+}
+
+/*
+ * Setup a fixed-buffer for the result.
+ */
+char *
+dlg_set_result(const char *string)
+{
+    unsigned need = string ? (unsigned) strlen(string) + 1 : 0;
+
+    /* inputstr.c needs a fixed buffer */
+    if (need < MAX_LEN)
+	need = MAX_LEN;
+
+    /*
+     * If the buffer is not big enough, allocate a new one.
+     */
+    if (dialog_vars.input_length != 0
+	|| dialog_vars.input_result == 0
+	|| need > MAX_LEN) {
+
+	dlg_clr_result();
+
+	dialog_vars.input_length = need;
+	dialog_vars.input_result = dlg_malloc(char, need);
+	assert_ptr(dialog_vars.input_result, "dlg_set_result");
+    }
+
+    strcpy(dialog_vars.input_result, string ? string : "");
+
+    return dialog_vars.input_result;
+}
+
+/*
+ * Accumulate results in dynamically allocated buffer.
+ * If input_length is zero, it is a MAX_LEN buffer belonging to the caller.
+ */
+void
+dlg_add_result(const char *string)
+{
+    unsigned have = (dialog_vars.input_result
+		     ? (unsigned) strlen(dialog_vars.input_result)
+		     : 0);
+    unsigned want = (unsigned) strlen(string) + 1 + have;
+
+    if ((want >= MAX_LEN)
+	|| (dialog_vars.input_length != 0)
+	|| (dialog_vars.input_result == 0)) {
+
+	if (dialog_vars.input_length == 0
+	    || dialog_vars.input_result == 0) {
+
+	    char *save_result = dialog_vars.input_result;
+
+	    dialog_vars.input_length = want * 2;
+	    dialog_vars.input_result = dlg_malloc(char, dialog_vars.input_length);
+	    assert_ptr(dialog_vars.input_result, "dlg_add_result malloc");
+	    dialog_vars.input_result[0] = '\0';
+	    if (save_result != 0)
+		strcpy(dialog_vars.input_result, save_result);
+	} else if (want >= dialog_vars.input_length) {
+	    dialog_vars.input_length = want * 2;
+	    dialog_vars.input_result = dlg_realloc(char,
+						   dialog_vars.input_length,
+						   dialog_vars.input_result);
+	    assert_ptr(dialog_vars.input_result, "dlg_add_result realloc");
+	}
+    }
+    strcat(dialog_vars.input_result, string);
+}
+
+/*
+ * These are characters that (aside from the quote-delimiter) will have to
+ * be escaped in a single- or double-quoted string.
+ */
+#define FIX_SINGLE "\n\\"
+#define FIX_DOUBLE FIX_SINGLE "[]{}?*;`~#$^&()|<>"
+
+/*
+ * Returns the quote-delimiter.
+ */
+static const char *
+quote_delimiter(void)
+{
+    return dialog_vars.single_quoted ? "'" : "\"";
+}
+
+/*
+ * Returns true if we should quote the given string.
+ */
+static bool
+must_quote(char *string)
+{
+    bool code = FALSE;
+
+    if (*string != '\0') {
+	size_t len = strlen(string);
+	if (strcspn(string, quote_delimiter()) != len)
+	    code = TRUE;
+	else if (strcspn(string, "\n\t ") != len)
+	    code = TRUE;
+	else
+	    code = (strcspn(string, FIX_DOUBLE) != len);
+    } else {
+	code = TRUE;
+    }
+
+    return code;
+}
+
+/*
+ * Add a quoted string to the result buffer.
+ */
+void
+dlg_add_quoted(char *string)
+{
+    char temp[2];
+    const char *my_quote = quote_delimiter();
+    const char *must_fix = (dialog_vars.single_quoted
+			    ? FIX_SINGLE
+			    : FIX_DOUBLE);
+
+    if (must_quote(string)) {
+	temp[1] = '\0';
+	dlg_add_result(my_quote);
+	while (*string != '\0') {
+	    temp[0] = *string++;
+	    if ((strchr) (my_quote, *temp) || (strchr) (must_fix, *temp))
+		dlg_add_result("\\");
+	    dlg_add_result(temp);
+	}
+	dlg_add_result(my_quote);
+    } else {
+	dlg_add_result(string);
+    }
+}
+
+/*
+ * When adding a result, make that depend on whether "--quoted" is used.
+ */
+void
+dlg_add_string(char *string)
+{
+    if (dialog_vars.quoted) {
+	dlg_add_quoted(string);
+    } else {
+	dlg_add_result(string);
+    }
+}
+
+bool
+dlg_need_separator(void)
+{
+    bool result = FALSE;
+
+    if (dialog_vars.output_separator) {
+	result = TRUE;
+    } else if (dialog_vars.input_result && *(dialog_vars.input_result)) {
+	result = TRUE;
+    }
+    return result;
+}
+
+void
+dlg_add_separator(void)
+{
+    const char *separator = (dialog_vars.separate_output) ? "\n" : " ";
+
+    if (dialog_vars.output_separator)
+	separator = dialog_vars.output_separator;
+
+    dlg_add_result(separator);
+}
+
+#define HELP_PREFIX		"HELP "
+
+void
+dlg_add_help_listitem(int *result, char **tag, DIALOG_LISTITEM * item)
+{
+    dlg_add_result(HELP_PREFIX);
+    if (USE_ITEM_HELP(item->help)) {
+	*tag = dialog_vars.help_tags ? item->name : item->help;
+	*result = DLG_EXIT_ITEM_HELP;
+    } else {
+	*tag = item->name;
+    }
+}
+
+void
+dlg_add_help_formitem(int *result, char **tag, DIALOG_FORMITEM * item)
+{
+    dlg_add_result(HELP_PREFIX);
+    if (USE_ITEM_HELP(item->help)) {
+	*tag = dialog_vars.help_tags ? item->name : item->help;
+	*result = DLG_EXIT_ITEM_HELP;
+    } else {
+	*tag = item->name;
+    }
+}
+
+/*
+ * Some widgets support only one value of a given variable - save/restore the
+ * global dialog_vars so we can override it consistently.
+ */
+void
+dlg_save_vars(DIALOG_VARS * vars)
+{
+    *vars = dialog_vars;
+}
+
+/*
+ * Most of the data in DIALOG_VARS is normally set by command-line options.
+ * The input_result member is an exception; it is normally set by the dialog
+ * library to return result values.
+ */
+void
+dlg_restore_vars(DIALOG_VARS * vars)
+{
+    char *save_result = dialog_vars.input_result;
+    unsigned save_length = dialog_vars.input_length;
+
+    dialog_vars = *vars;
+    dialog_vars.input_result = save_result;
+    dialog_vars.input_length = save_length;
+}
+
+/*
+ * Called each time a widget is invoked which may do output, increment a count.
+ */
+void
+dlg_does_output(void)
+{
+    dialog_state.output_count += 1;
+}
+
+/*
+ * Compatibility for different versions of curses.
+ */
+#if !(defined(HAVE_GETBEGX) && defined(HAVE_GETBEGY))
+int
+dlg_getbegx(WINDOW *win)
+{
+    int y, x;
+    getbegyx(win, y, x);
+    (void) y;
+    return x;
+}
+int
+dlg_getbegy(WINDOW *win)
+{
+    int y, x;
+    getbegyx(win, y, x);
+    (void) x;
+    return y;
+}
+#endif
+
+#if !(defined(HAVE_GETCURX) && defined(HAVE_GETCURY))
+int
+dlg_getcurx(WINDOW *win)
+{
+    int y, x;
+    getyx(win, y, x);
+    (void) y;
+    return x;
+}
+int
+dlg_getcury(WINDOW *win)
+{
+    int y, x;
+    getyx(win, y, x);
+    (void) x;
+    return y;
+}
+#endif
+
+#if !(defined(HAVE_GETMAXX) && defined(HAVE_GETMAXY))
+int
+dlg_getmaxx(WINDOW *win)
+{
+    int y, x;
+    getmaxyx(win, y, x);
+    (void) y;
+    return x;
+}
+int
+dlg_getmaxy(WINDOW *win)
+{
+    int y, x;
+    getmaxyx(win, y, x);
+    (void) x;
+    return y;
+}
+#endif
+
+#if !(defined(HAVE_GETPARX) && defined(HAVE_GETPARY))
+int
+dlg_getparx(WINDOW *win)
+{
+    int y, x;
+    getparyx(win, y, x);
+    (void) y;
+    return x;
+}
+int
+dlg_getpary(WINDOW *win)
+{
+    int y, x;
+    getparyx(win, y, x);
+    (void) x;
+    return y;
+}
+#endif
+
+#ifdef NEED_WGETPARENT
+WINDOW *
+dlg_wgetparent(WINDOW *win)
+{
+#undef wgetparent
+    WINDOW *result = 0;
+    DIALOG_WINDOWS *p;
+
+    for (p = dialog_state.all_subwindows; p != 0; p = p->next) {
+	if (p->shadow == win) {
+	    result = p->normal;
+	    break;
+	}
+    }
+    return result;
+}
+#endif
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new	(revision 5)

Property changes on: 3pp/sources/packages/dialog/create-1.3-20210621-patch/dialog-1.3-20210621-new
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch/file.list
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch/file.list	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch/file.list	(revision 5)
@@ -0,0 +1,7 @@
+dialog-1.3-20210621/buildlist.c
+dialog-1.3-20210621/checklist.c
+dialog-1.3-20210621/dialog-config.in
+dialog-1.3-20210621/fselect.c
+dialog-1.3-20210621/menubox.c
+dialog-1.3-20210621/treeview.c
+dialog-1.3-20210621/util.c
Index: 3pp/sources/packages/dialog/create-1.3-20210621-patch
===================================================================
--- 3pp/sources/packages/dialog/create-1.3-20210621-patch	(nonexistent)
+++ 3pp/sources/packages/dialog/create-1.3-20210621-patch	(revision 5)

Property changes on: 3pp/sources/packages/dialog/create-1.3-20210621-patch
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/packages/dialog/dialogrc
===================================================================
--- 3pp/sources/packages/dialog/dialogrc	(nonexistent)
+++ 3pp/sources/packages/dialog/dialogrc	(revision 5)
@@ -0,0 +1,144 @@
+#
+# Run-time configuration file for dialog, matches Radix color scheme.
+#
+# Types of values:
+#
+# Number     -  <number>
+# String     -  "string"
+# Boolean    -  <ON|OFF>
+# Attribute  -  (foreground,background,highlight?)
+
+# Set aspect-ration.
+aspect = 0
+
+# Set separator (for multiple widgets output).
+separate_widget = ""
+
+# Set tab-length (for textbox tab-conversion).
+tab_len = 0
+
+# Make tab-traversal for checklist, etc., include the list.
+visit_items = OFF
+
+# Shadow dialog boxes? This also turns on color.
+use_shadow = ON
+
+# Turn color support ON or OFF
+use_colors = ON
+
+# Screen color
+screen_color = (WHITE,BLACK,ON)
+
+# Shadow color
+shadow_color = (BLACK,BLACK,OFF)
+
+# Dialog box color
+dialog_color = (BLACK,WHITE,OFF)
+
+# Dialog box title color
+title_color = (BLACK,WHITE,ON)
+
+# Dialog box border color
+border_color = (WHITE,WHITE,ON)
+
+
+# Active button color
+button_active_color = (WHITE,BLACK,ON)
+
+# Inactive button color
+button_inactive_color = (BLACK,WHITE,OFF)
+
+# Active button key color
+button_key_active_color = (YELLOW,BLACK,ON)
+
+# Inactive button key color
+button_key_inactive_color = (RED,WHITE,ON)
+
+# Active button label color
+button_label_active_color = (WHITE,BLACK,ON)
+
+# Inactive button label color
+button_label_inactive_color = (BLACK,WHITE,ON)
+
+# Input box color
+inputbox_color = (BLUE,WHITE,ON)
+
+# Input box border color
+inputbox_border_color = (WHITE,WHITE,ON)
+
+# Search box color
+searchbox_color = (YELLOW,WHITE,ON)
+
+# Search box title color
+searchbox_title_color = (WHITE,WHITE,ON)
+
+# Search box border color
+searchbox_border_color = (RED,WHITE,OFF)
+
+# File position indicator color
+position_indicator_color = (RED,WHITE,ON)
+
+# Menu box color
+menubox_color = dialog_color
+
+# Menu box border color
+menubox_border_color = border_color
+
+# Item color
+item_color = (BLACK,WHITE,ON)
+
+# Selected item color
+item_selected_color = (BLACK,WHITE,OFF)
+
+# Tag color
+tag_color = (BLACK,WHITE,ON)
+
+# Selected tag color
+tag_selected_color = (BLACK,WHITE,OFF)
+
+# Tag key color
+tag_key_color = (RED,WHITE,ON)
+
+# Selected tag key color
+tag_key_selected_color = (YELLOW,BLACK,ON)
+
+# Check box color
+check_color = dialog_color
+
+# Selected check box color
+check_selected_color = (RED,WHITE,ON)
+
+
+# Up arrow color
+uarrow_color = (RED,WHITE,OFF)
+
+# Down arrow color
+darrow_color = uarrow_color
+
+
+# Item help-text color
+itemhelp_color = shadow_color
+
+# Active form text color
+form_active_text_color = inputbox_color
+
+# Form text color
+form_text_color = (BLACK,WHITE,ON)
+
+# Readonly form item color
+form_item_readonly_color = (CYAN,WHITE,ON)
+
+# Dialog box gauge color
+gauge_color = (BLACK,WHITE,ON)
+
+# Dialog box border2 color
+border2_color = dialog_color
+
+# Input box border2 color
+inputbox_border2_color = border2_color
+
+# Search box border2 color
+searchbox_border2_color = border2_color
+
+# Menu box border2 color
+menubox_border2_color = border2_color
Index: 3pp/sources/packages/dialog/patches/README
===================================================================
--- 3pp/sources/packages/dialog/patches/README	(nonexistent)
+++ 3pp/sources/packages/dialog/patches/README	(revision 5)
@@ -0,0 +1,6 @@
+
+/* begin *
+
+   dialog-1.3-20210621.patch   - Some enhance the appearance of dialogs.
+
+ * end */
Index: 3pp/sources/packages/dialog/patches
===================================================================
--- 3pp/sources/packages/dialog/patches	(nonexistent)
+++ 3pp/sources/packages/dialog/patches	(revision 5)

Property changes on: 3pp/sources/packages/dialog/patches
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/packages/dialog
===================================================================
--- 3pp/sources/packages/dialog	(nonexistent)
+++ 3pp/sources/packages/dialog	(revision 5)

Property changes on: 3pp/sources/packages/dialog
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources/packages
===================================================================
--- 3pp/sources/packages	(nonexistent)
+++ 3pp/sources/packages	(revision 5)

Property changes on: 3pp/sources/packages
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp/sources
===================================================================
--- 3pp/sources	(nonexistent)
+++ 3pp/sources	(revision 5)

Property changes on: 3pp/sources
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: 3pp
===================================================================
--- 3pp	(nonexistent)
+++ 3pp	(revision 5)

Property changes on: 3pp
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend
Index: Makefile
===================================================================
--- Makefile	(nonexistent)
+++ Makefile	(revision 5)
@@ -0,0 +1,30 @@
+
+COMPONENT_TARGETS = $(TOOLCHAIN_HOST)
+
+
+include config.mk
+
+REQUIRES  = build-system/3pp/dialog/1.3-20210621
+REQUIRES += build-system/3pp/gnattools/12.2.0
+
+# ======= __END_OF_REQUIRES__ =======
+
+
+config_makefile = targets-config.mk
+
+BUILD_TARGETS = $(config_makefile)
+
+CLEANUP_FILES += $(config_makefile)
+CLEANUP_FILES += $(CURDIR)/gnattools
+CLEANUP_FILES += $(CURDIR)/sbin
+CLEANUP_FILES += $(CURDIR)/etc
+
+# CORE Makefile:
+
+include core.mk
+
+# Dependencies:
+
+$(config_makefile): $(config_makefile).template
+	@echo "Creating $(config_makefile) ..."
+	@cp $(config_makefile).template $@
Index: _kxLab.pm
===================================================================
--- _kxLab.pm	(nonexistent)
+++ _kxLab.pm	(revision 5)
@@ -0,0 +1,39 @@
+
+use strict;
+use warnings FATAL => 'all';
+
+package _kxLab;
+
+sub error
+{
+  my $message = shift;
+  my $func = shift;
+
+  print STDERR "Error: $message\n";
+  if( defined( $func ) )
+  {
+    &$func();
+  }
+  exit 1;
+}
+
+sub command_error
+{
+  my $command = shift;
+  my $context = shift;
+
+  error( "$command failed at @{$context}[1] line @{$context}[2]" );
+}
+
+sub system
+{
+  my $command = shift;
+
+  if( system( $command ) )
+  {
+    my @context = caller;
+    command_error($command, \@context);
+  }
+}
+
+1;
Index: apply_patches
===================================================================
--- apply_patches	(nonexistent)
+++ apply_patches	(revision 5)
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use FindBin;
+use lib $FindBin::Bin;
+
+use strict;
+use warnings FATAL => 'all';
+use _kxLab;
+
+my $filename = shift or die "Error: Need a patch file";
+my $arg2 = shift;
+my $depmode = 0;
+my $dir = ".";
+if( defined( $arg2 ) )
+{
+  if( $arg2 eq "-dep-" )
+  {
+    $depmode = 1;
+  }
+  else
+  {
+    $dir = $arg2;
+  }
+}
+
+open( PATCH, "<$filename" ) or die "Error: Could not open patch file: $filename: $!";
+while( <PATCH> )
+{
+  next if /^#/;
+  if (/(\S+)\s*(.*)/)
+  {
+    if( $depmode )
+    {
+      print "$1 ";
+    }
+    else
+    {
+      my $arg = $2 || "-p0";
+      print "=== Applying $1 ===\n";
+      _kxLab::system( "patch -d $dir $arg < $1" );
+    }
+  }
+}
+close PATCH;
+if( $depmode )
+{
+  print "$filename\n";
+}
+

Property changes on: apply_patches
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: build_requires
===================================================================
--- build_requires	(nonexistent)
+++ build_requires	(revision 5)
@@ -0,0 +1,305 @@
+#!/usr/bin/perl
+
+use FindBin;
+use lib $FindBin::Bin;
+
+use strict;
+use warnings FATAL => 'all';
+
+use IO::Handle;
+use File::Basename;
+use File::Temp;
+use Getopt::Long;
+
+use _kxLab;
+
+#
+# Generate .$(HARDWARE)_requires file for current directory
+#
+# usage:
+#   $0 [options] topdir toolchain flavour
+#
+# where:
+#      'topdir' - is a absolute path to the top directory of checked out branch
+#   'toolchain' - is a TOOLCHAIN name
+#     'flavour' - is a HARDWARE variant
+#
+
+# global variables
+my (%all_requires, $top_dir, $opt_max_depth, %requires_depend, $requires_file, %skip_dirs);
+
+my ($toolchain, $flavour, $target_build_dir);
+
+
+sub usage
+{
+  print <<EOF;
+
+Usage: build_requires [options] topdir toolchain flavour
+Options:
+   --max-depth=i - where 'i' is a maximal directory depth for finding requires;
+      --skip-dir - directory to be skipped (such as dist or TARGET_BUILD_DIR);
+          topdir - is a absolute path to the top of checked out branch;
+       toolchain - is a TOOLCHAIN name;
+         flavour - is a HARDWARE variant.
+
+EOF
+  exit;
+}
+
+
+sub requires_depend
+{
+  my $makefile = shift;
+
+  if( ! exists $requires_depend{$makefile} )
+  {
+    print REQUIRES_DEPEND_FILE "$requires_file: $makefile\n\n";
+    print REQUIRES_DEPEND_FILE "$makefile:\n\n";
+    $requires_depend{$makefile} = "";
+  }
+}
+
+sub read_requires
+{
+  my $makefile = shift;
+  my $flavour  = shift;
+
+  # Add a dependency to the Makefile
+  requires_depend( $makefile );
+
+  my $cdir = dirname( $makefile );
+
+  my %requires;
+
+  #
+  # We read the head of Makefile until '__END_OF_REQUIRES__' keyword.
+  # The 'build-system/constants.mk' should be included before requires.
+  #
+  my $shell_output = <<`SHELL`;
+cd $cdir
+head -n `cat Makefile | grep -n "__END_OF_REQUIRES__" | cut -f 1 -d ':'` Makefile | \
+  make TOOLCHAIN=$toolchain FLAVOUR=$flavour -f - -p __build_requires__ 2>/dev/null | grep "REQUIRES"
+exit 0
+SHELL
+
+  while( $shell_output =~ m/^REQUIRES(.+= +)(.+)/gm )
+  {
+    my @n = split( " ", $2 );
+    foreach my $req ( @n )
+    {
+      my ($d, $f);
+
+      $d = `echo $req | cut -f 1 -d '^'`;
+      $d =~ s/^\s+|\s+$//;
+      if( $req =~ m/\^/ )
+      {
+        $f = `echo $req | cut -f 2 -d '^'`;
+        $f =~ s/^\s+|\s+$//;
+      }
+      else
+      {
+        $f = "";
+      }
+
+      if( $d eq "ALL_DIRS" )
+      {
+        my $dirname = dirname( $makefile );
+
+        opendir( DIR, "$dirname" ) or
+          _kxLab::error( "build_requires: Could not open directory: $dirname: $!" );
+        my @dirs = grep { ! /^\./ && -d "$_" && -f "$_/Makefile" } readdir( DIR );
+        closedir DIR;
+
+        foreach my $dir (@dirs)
+        {
+          requires_depend( "$dirname/$dir/Makefile" );
+          "$dirname/$dir" =~ m!$top_dir/(.+)!;
+          $requires{$1} = "";
+        }
+      }
+      else
+      {
+        # Print a nice error message if the REQUIRES statement points to a missing directory
+        _kxLab::error( "build_requires: REQUIRES '$d' in $makefile not found. Exit" ) if( ! -d "$top_dir/$d" );
+
+        if( -f "$top_dir/$d/Makefile" )
+        {
+          if( $f eq "" ) { $requires{$d} = "";            }
+          else           { $requires{$d . "^" . $f} = ""; }
+        }
+      }
+    }
+  }
+  return %requires;
+}
+
+sub start_depend
+{
+  my $req = shift;
+
+  print REQUIRES_FILE "$req:";
+}
+
+sub depend
+{
+  my $req = shift;
+
+  print REQUIRES_FILE " $req";
+}
+
+sub end_depend
+{
+  print REQUIRES_FILE "\n\n";
+}
+
+sub make_sub_requires
+{
+  my $req = shift;
+
+  if( ! exists $all_requires{$req} )
+  {
+    $all_requires{$req} = "";
+
+    my ($d, $f);
+
+    $d = `echo $req | cut -f 1 -d '^'`;
+    $d =~ s/^\s+|\s+$//;
+    if( $req =~ m/\^/ )
+    {
+      $f = `echo $req | cut -f 2 -d '^'`;
+      $f =~ s/^\s+|\s+$//;
+    }
+    else
+    {
+      $f = "";
+    }
+
+    # Read sub requires
+    my $makefile = "$top_dir/$d/Makefile";
+    my %sub_requires = read_requires( $makefile, $f );
+    if( scalar(%sub_requires) )
+    {
+      my @sorted_sub_requires = sort(keys %sub_requires);
+
+      # Build dependencies for sub requires
+      if( $f eq "" ) { start_depend( $d );            }
+      else           { start_depend( $d . "^" . $f ); }
+      foreach my $sub_req ( @sorted_sub_requires )
+      {
+        depend( $sub_req );
+      }
+      end_depend();
+
+      # Make sub sub requires
+      foreach my $sub_req ( @sorted_sub_requires )
+      {
+        make_sub_requires( $sub_req );
+      }
+    }
+  }
+}
+
+
+#
+# Parse the command line options
+#
+$opt_max_depth = 10;
+my @opt_skip_dirs;
+GetOptions( "max-depth=i" => \$opt_max_depth, "skip-dir=s" => \@opt_skip_dirs );
+%skip_dirs = map { $_ => "" } @opt_skip_dirs;
+
+# Get the rest of the command line
+my $topdir = shift;
+$toolchain = shift;
+$flavour   = shift;
+
+
+my $makefile = "Makefile";
+
+if( ! defined $topdir    or $topdir eq "" )    { usage; }
+if( ! defined $toolchain or $toolchain eq "" ) { usage; }
+if( ! defined $flavour   or $flavour eq "" )
+{
+  $flavour = "";
+  $target_build_dir = "." . $toolchain ;
+}
+else
+{
+  $target_build_dir = "." . $toolchain . "/" . $flavour;
+}
+
+_kxLab::error( "build_requires: $topdir is not a directory" ) if( ! -d $topdir );
+_kxLab::error( "build_requires: Makefile missing: $makefile" ) if ( ! -f $makefile );
+
+# setup $top_build_dir
+$top_dir = $topdir;
+my $build_system = $top_dir . "/build-system";
+#my $build_system = "build-system";
+
+_kxLab::system( "mkdir -p $target_build_dir" );
+
+$requires_file = $target_build_dir . "/" . ".requires";
+my $requires_depend_file = $requires_file . "_depend";
+
+# open the output files
+open(REQUIRES_FILE, "> $requires_file") or
+  _kxLab::error( "build_requires: Could not open $requires_file file: $!" );
+open(REQUIRES_DEPEND_FILE, "> $requires_depend_file") or
+  _kxLab::error( "build_requires: Could not open $requires_depend_file file: $!" );
+
+
+# root component
+my $pwd = `pwd`;
+chomp $pwd;
+$pwd =~ m!$top_dir(.*)!;
+my $root;
+if( $1 eq "" )
+{
+  $root = "all";
+}
+else
+{
+  $1 =~ m!/(.+)!;
+  $root = $1;
+}
+
+print REQUIRES_FILE "# ROOT=$root\n\n";
+print REQUIRES_DEPEND_FILE "\n";
+
+
+# read the makefile
+my %requires = read_requires( "$pwd/$makefile", $flavour );
+
+# ignore the "build-system" dependency (if any), since this dependency is implicit
+delete $requires{"build-system"};
+
+my @sorted_requires = sort(keys %requires);
+
+# build the all: rule
+start_depend( "all" );
+foreach my $req ( @sorted_requires )
+{
+  depend( $req );
+}
+end_depend();
+
+# build sub dependencies
+foreach my $req ( @sorted_requires )
+{
+  make_sub_requires( $req );
+}
+
+# Finish by including tree.mk
+print REQUIRES_FILE "TREEDIRS = ", join(" ", sort(keys %all_requires)), "\n\n";
+if( $pwd =~ m/$build_system/ )
+{
+  print REQUIRES_FILE "include \$(BUILDSYSTEM)/tree-bs.mk\n";
+}
+else
+{
+  print REQUIRES_FILE "include \$(BUILDSYSTEM)/tree.mk\n";
+}
+
+close REQUIRES_FILE;
+close REQUIRES_DEPEND_FILE;

Property changes on: build_requires
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: build_src_requires
===================================================================
--- build_src_requires	(nonexistent)
+++ build_src_requires	(revision 5)
@@ -0,0 +1,299 @@
+#!/usr/bin/perl
+
+use FindBin;
+use lib $FindBin::Bin;
+
+use strict;
+use warnings FATAL => 'all';
+
+use IO::Handle;
+use File::Basename;
+use File::Temp;
+use Getopt::Long;
+
+use _kxLab;
+
+#
+# Generate .src_requires file for current directory
+#
+# usage:
+#   $0 [options] topdir
+#
+# where:
+#   'topdir' - is a absolute path to the top directory of checked out branch
+#
+
+
+# global variables
+my (%all_requires, $top_dir, $opt_max_depth, %requires_depend, $requires_file, %skip_dirs);
+
+my %all_src_requires;
+
+sub usage
+{
+  print <<EOF;
+
+Usage: build_src_requires [options] topdir
+Options:
+   --max-depth=i - where 'i' is a maximal directory depth for finding requires;
+      --skip-dir - directory to be skipped (such as dist or TARGET_BUILD_DIR);
+          topdir - is a absolute path to the top of checked out branch.
+
+EOF
+  exit;
+}
+
+
+sub requires_depend
+{
+  my $makefile = shift;
+
+  if( ! exists $requires_depend{$makefile} )
+  {
+    print REQUIRES_DEPEND_FILE "$requires_file: $makefile\n\n";
+    print REQUIRES_DEPEND_FILE "$makefile:\n\n";
+    $requires_depend{$makefile} = "";
+  }
+}
+
+sub read_src_requires
+{
+  my $makefile  = shift;
+
+  # add a dependency to the Makefile
+  requires_depend($makefile);
+
+  my %requires;
+
+  my $shell_output = `cat $makefile`;
+
+  while( $shell_output =~ m/^SOURCE_REQUIRES(.+= +)(.+)/gm )
+  {
+    my @n = split( " ", $2 );
+    foreach my $d ( @n )
+    {
+      if( $d eq "ALL_DIRS" )
+      {
+        my $dirname = dirname($makefile);
+
+        opendir( DIR, "$dirname" ) or
+          _kxLab::error( "build_src_requires: Could not open directory: $dirname: $!" );
+        my @dirs = grep { ! /^\./ && -d "$_" && -f "$_/Makefile" } readdir( DIR );
+        closedir DIR;
+
+        foreach my $dir (@dirs)
+        {
+          requires_depend("$dirname/$dir/Makefile");
+          "$dirname/$dir" =~ m!$top_dir/(.+)!;
+          $requires{$1} = "";
+        }
+      }
+      else
+      {
+        # Print a nice error message if the SOURCE_REQUIRES statement points to a missing directory
+        _kxLab::error( "build_src_requires: SOURCE_REQUIRES '$d' in $makefile not found. Exit" ) if( ! -d "$top_dir/$d" );
+
+        if( -f "$top_dir/$d/Makefile" )
+        {
+          $requires{$d} = "";
+          requires_depend("$top_dir/$d/Makefile");
+        }
+      }
+    }
+  }
+  return %requires;
+}
+
+sub read_requires
+{
+  my $makefile  = shift;
+
+  # add a dependency to the Makefile
+  requires_depend($makefile);
+
+  my %requires;
+
+  my $shell_output = `cat $makefile`;
+
+  while( $shell_output =~ m/^REQUIRES(.+= +)(.+)/gm )
+  {
+    my @n = split( " ", $2 );
+    foreach my $req ( @n )
+    {
+      my $d = `echo $req | cut -f 1 -d '^'`;
+      $d =~ s/^\s+|\s+$//;
+
+      if( $d eq "ALL_DIRS" )
+      {
+        my $dirname = dirname($makefile);
+
+        opendir( DIR, "$dirname" ) or
+          _kxLab::error( "build_src_requires: Could not open directory: $dirname: $!" );
+        my @dirs = grep { ! /^\./ && -d "$_" && -f "$_/Makefile" } readdir( DIR );
+        closedir DIR;
+
+        foreach my $dir (@dirs)
+        {
+          requires_depend( "$dirname/$dir/Makefile" );
+          "$dirname/$dir" =~ m!$top_dir/(.+)!;
+          $requires{$1} = "";
+
+          my %src_requires = read_src_requires( "$dirname/$dir/Makefile" );
+          my @sort_src_requires = sort(keys %src_requires);
+          foreach my $req ( @sort_src_requires )
+          {
+            $all_src_requires{$req} = "";
+          }
+        }
+      }
+      else
+      {
+        # Print a nice error message if the REQUIRES statement points to a missing directory
+        _kxLab::error( "build_src_requires: REQUIRES '$d' in $makefile not found. Exit" ) if( ! -d "$top_dir/$d" );
+
+        if( -f "$top_dir/$d/Makefile" )
+        {
+          $requires{$d} = "";
+
+          my %src_requires = read_src_requires( "$top_dir/$d/Makefile" );
+          my @sort_src_requires = sort(keys %src_requires);
+          foreach my $req ( @sort_src_requires )
+          {
+            $all_src_requires{$req} = "";
+          }
+        }
+      }
+    }
+  }
+  return %requires;
+}
+
+sub start_depend
+{
+  my $req = shift;
+
+  print REQUIRES_FILE "$req:";
+}
+
+sub depend
+{
+  my $req = shift;
+
+  print REQUIRES_FILE " $req";
+}
+
+sub end_depend
+{
+  print REQUIRES_FILE "\n\n";
+}
+
+sub make_sub_requires
+{
+  my $req = shift;
+
+  if( ! exists $all_requires{$req} )
+  {
+    $all_requires{$req} = "";
+
+    my $d = `echo $req | cut -f 1 -d '^'`;
+    $d =~ s/^\s+|\s+$//;
+
+    # Read sub requires
+    my $makefile = "$top_dir/$d/Makefile";
+    my %sub_requires = read_requires( $makefile );
+    if( scalar(%sub_requires) )
+    {
+      # Make sub sub requires
+      my @sorted_sub_requires = sort(keys %sub_requires);
+      foreach my $sub_req ( @sorted_sub_requires )
+      {
+        make_sub_requires( $sub_req );
+      }
+    }
+  }
+}
+
+
+#
+# Parse the command line options
+#
+$opt_max_depth = 10;
+my @opt_skip_dirs;
+GetOptions( "max-depth=i" => \$opt_max_depth, "skip-dir=s" => \@opt_skip_dirs );
+%skip_dirs = map { $_ => "" } @opt_skip_dirs;
+
+# get the rest of the command line
+my $topdir   = shift;
+my $makefile = "Makefile";
+
+if( ! defined $topdir or $topdir eq "" ) { usage; }
+
+_kxLab::error( "build_requires: $topdir is not a directory" ) if( ! -d $topdir );
+_kxLab::error( "build_requires: Makefile missing: $makefile" ) if ( ! -f $makefile );
+
+# setup $top_build_dir
+$top_dir = $topdir;
+
+$requires_file = ".src_requires";
+my $requires_depend_file = $requires_file . "_depend";
+
+
+# open the output files
+open(REQUIRES_FILE, "> $requires_file") or
+  _kxLab::error( "build_requires: Could not open $requires_file file: $!" );
+open(REQUIRES_DEPEND_FILE, "> $requires_depend_file") or
+  _kxLab::error( "build_requires: Could not open $requires_depend_file file: $!" );
+
+
+# root component
+my $pwd = `pwd`;
+chomp $pwd;
+$pwd =~ m!$top_dir(.*)!;
+my $root;
+if( $1 eq "" )
+{
+  $root = "all";
+}
+else
+{
+  $1 =~ m!/(.+)!;
+  $root = $1;
+}
+
+print REQUIRES_FILE "# ROOT=$root\n\n";
+print REQUIRES_DEPEND_FILE "\n";
+
+# read the makefile
+%all_src_requires = read_src_requires( "$pwd/$makefile" );
+my %requires = read_requires( "$pwd/$makefile" );
+
+
+# check the "build-system" sub dependencies implicitly (excluding sources directories)
+#$requires{"build-system"} = "";
+
+
+# build sub dependencies
+my @sorted_requires = sort(keys %requires);
+foreach my $req ( @sorted_requires )
+{
+  make_sub_requires( $req );
+}
+
+# build the all: rule
+start_depend( "all" );
+my @sorted_src_requires = sort(keys %all_src_requires);
+foreach my $req ( @sorted_src_requires )
+{
+  depend( $req );
+}
+end_depend();
+
+
+# Finish by including tree.mk
+print REQUIRES_FILE "TREEDIRS = ", join(" ", sort(keys %all_src_requires)), "\n\n";
+print REQUIRES_FILE "include \$(BUILDSYSTEM)/tree-src.mk\n";
+
+
+# close output files
+close REQUIRES_FILE;
+close REQUIRES_DEPEND_FILE;

Property changes on: build_src_requires
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: canonical-build
===================================================================
--- canonical-build	(nonexistent)
+++ canonical-build	(revision 5)
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+  i*:CYGWIN*:*)
+    echo ${UNAME_MACHINE}-pc-cygwin
+    exit ;;
+  *:MINGW*:*)
+    echo ${UNAME_MACHINE}-pc-mingw32
+    exit ;;
+  amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+    echo x86_64-unknown-cygwin
+    exit ;;
+  i*86:Linux:*:*)
+    if [ -f /etc/slackware-version ]; then
+      system=`cat /etc/slackware-version | cut -f 1 -d ' ' | tr 'S' 's'`
+      echo ${UNAME_MACHINE}-${system}-linux
+    else
+      echo ${UNAME_MACHINE}-unknown-linux-gnu
+    fi
+    exit ;;
+  x86_64:Linux:*:*)
+    if [ -f /etc/slamd64-version ]; then
+      system=`cat /etc/slamd64-version | cut -f 1 -d ' ' | tr 'S' 's'`
+      echo x86_64-${system}-linux
+    elif [ -f /etc/slackware-version ]; then
+      system=`cat /etc/slackware-version | cut -f 1 -d ' ' | tr 'S' 's'`
+      echo x86_64-${system}-linux
+    elif [ -f /etc/os-release ]; then
+      system=`cat /etc/os-release | grep -e '^ID=' | cut -f 2 -d '='`
+      echo x86_64-linux-gnu
+    else
+      echo x86_64-unknown-linux-gnu
+    fi
+    exit ;;
+esac
+
+####### echo "unknown-unknown-unknown-unknown"
+
+cat >&2 <<EOF
+
+`basename $0`: unable to reciognize build system type
+
+   MACHINE = '${UNAME_MACHINE}'
+   SYSTEM  = '${UNAME_SYSTEM}'
+   RELEASE = '${UNAME_RELEASE}'
+   VERSION = '${UNAME_VERSION}'
+
+EOF
+
+exit 1

Property changes on: canonical-build
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: config.mk
===================================================================
--- config.mk	(nonexistent)
+++ config.mk	(revision 5)
@@ -0,0 +1,411 @@
+# include once
+ifndef CONFIG_MK
+
+#######
+####### Constants:
+#######
+
+
+DOWNLOAD_SERVER      = https://ftp.radix.pro
+
+WGET_OPTIONS         = -q -N
+
+CACHED_CC_OUTPUT     = /opt/extra/ccache
+
+TOOLCHAINS_BASE_PATH = /opt/toolchains
+
+TOOLCHAINS_VERSION   = 1.0.0
+
+
+# Build machine architrcture:
+
+BUILD_ARCH = x86_64-pc-linux-gnu
+#
+# HOST and BUILD variables should be set up for each makefile.
+# NOTE: the HOST is equal to BUILD because our toolchains work on BUILD machine.
+#
+ HOST = $(BUILD_ARCH)
+BUILD = $(BUILD_ARCH)
+
+
+#######
+####### Standard Available Toolchains:
+#######
+
+#
+# NOTE:
+# ====
+#   Toolchain names defined by 'TOOLCHAIN_...' variables.
+#   Configuration variable names such as HOST_ARCH, HOST_DIR, HOST_PATH should have prefix
+#   which is equal to $(TOOLCHAIN_...) in upper case letters and symbol '-' should be replaced with '_'.
+#   In other words the PREFIX is equal to PREFIX = $(shell echo $(TOOLCHAIN_...) | tr '[a-z-]' '[A-Z_]').
+#
+
+# NOARCH
+TOOLCHAIN_NOARCH = noarch
+
+NOARCH_ARCH = noarch
+NOARCH_DIR  = noarch
+NOARCH_PATH = $(TOOLCHAINS_BASE_PATH)/noarch
+
+
+# HOST
+TOOLCHAIN_HOST = host
+
+HOST_ARCH = $(BUILD_ARCH)
+HOST_DIR  = $(word 1, $(subst -, ,$(BUILD_ARCH)))
+HOST_PATH = $(TOOLCHAINS_BASE_PATH)/$(HOST_DIR)
+
+
+#######
+####### Additional Available Toolchains:
+#######
+
+# All ARM 32-bit series with Newlib
+TOOLCHAIN_ARM32_NEWLIB = arm32-newlib
+
+ARM32_NEWLIB_ARCH = arm-none-eabi
+ARM32_NEWLIB_DIR  = arm-NONE-eabi-newlib
+ARM32_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(ARM32_NEWLIB_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+ARM32_NEWLIB_SPEC = All ARM 32-bit series newlib toolchain
+
+
+# AT91SAM7S
+TOOLCHAIN_AT91SAM7S_NEWLIB = at91sam7s-newlib
+
+AT91SAM7S_NEWLIB_ARCH = arm-at91sam7s-eabi
+AT91SAM7S_NEWLIB_DIR  = arm-AT91SAM7S-eabi-newlib
+AT91SAM7S_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(AT91SAM7S_NEWLIB_DIR)
+###                    |---Toolchain-spec-handy-ruler----------------|
+AT91SAM7S_NEWLIB_SPEC = Atmel AT91SAM7S newlib toolchain
+
+
+# IMX6-GLIBC
+TOOLCHAIN_IMX6_GLIBC = imx6-glibc
+
+IMX6_GLIBC_ARCH = arm-imx6-linux-gnueabihf
+IMX6_GLIBC_DIR  = arm-IMX6-linux-glibc
+IMX6_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(IMX6_GLIBC_DIR)
+###              |---Toolchain-spec-handy-ruler----------------|
+IMX6_GLIBC_SPEC = Freescale i.MX6 GNU Libc toolchain
+
+
+# IMX6ULL-GLIBC
+TOOLCHAIN_IMX6ULL_GLIBC = imx6ull-glibc
+
+IMX6ULL_GLIBC_ARCH = arm-imx6ull-linux-gnueabihf
+IMX6ULL_GLIBC_DIR  = arm-IMX6ULL-linux-glibc
+IMX6ULL_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(IMX6ULL_GLIBC_DIR)
+###                 |---Toolchain-spec-handy-ruler----------------|
+IMX6ULL_GLIBC_SPEC = NXP i.MX6ULL GNU Libc toolchain
+
+
+# OMAP543X-GLIBC
+TOOLCHAIN_OMAP543X_GLIBC = omap543x-glibc
+
+OMAP543X_GLIBC_ARCH = arm-omap543x-linux-gnueabihf
+OMAP543X_GLIBC_DIR  = arm-OMAP543X-linux-glibc
+OMAP543X_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(OMAP543X_GLIBC_DIR)
+###                  |---Toolchain-spec-handy-ruler----------------|
+OMAP543X_GLIBC_SPEC = Texas OMAP543x GNU Libc toolchain
+
+
+# AM335X-GLIBC
+TOOLCHAIN_AM335X_GLIBC = am335x-glibc
+
+AM335X_GLIBC_ARCH   = arm-am335x-linux-gnueabihf
+AM335X_GLIBC_DIR    = arm-AM335X-linux-glibc
+AM335X_GLIBC_PATH   = $(TOOLCHAINS_BASE_PATH)/$(AM335X_GLIBC_DIR)
+###                  |---Toolchain-spec-handy-ruler----------------|
+AM335X_GLIBC_SPEC   = Texas AM335x GNU Libc toolchain
+
+
+# AllWinner A10-GLIBC
+TOOLCHAIN_A1X_GLIBC = a1x-glibc
+
+A1X_GLIBC_ARCH = arm-a1x-linux-gnueabihf
+A1X_GLIBC_DIR  = arm-A1X-linux-glibc
+A1X_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(A1X_GLIBC_DIR)
+###             |---Toolchain-spec-handy-ruler----------------|
+A1X_GLIBC_SPEC = Allwinner A1x GNU Libc toolchain
+
+# AllWinner A20-GLIBC
+TOOLCHAIN_A2X_GLIBC = a2x-glibc
+
+A2X_GLIBC_ARCH = arm-a2x-linux-gnueabihf
+A2X_GLIBC_DIR  = arm-A2X-linux-glibc
+A2X_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(A2X_GLIBC_DIR)
+###             |---Toolchain-spec-handy-ruler----------------|
+A2X_GLIBC_SPEC = Allwinner A2x GNU Libc toolchain
+
+
+# AllWinner H3-GLIBC
+TOOLCHAIN_H3_GLIBC = h3-glibc
+
+H3_GLIBC_ARCH = arm-h3-linux-gnueabihf
+H3_GLIBC_DIR  = arm-H3-linux-glibc
+H3_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(H3_GLIBC_DIR)
+###            |---Toolchain-spec-handy-ruler----------------|
+H3_GLIBC_SPEC = Allwinner H3 GNU Libc toolchain
+
+
+# AllWinner H5-NEWLIB
+TOOLCHAIN_H5_NEWLIB = h5-newlib
+
+H5_NEWLIB_ARCH = aarch64-h5-elf
+H5_NEWLIB_DIR  = aarch64-H5-elf-newlib
+H5_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(H5_NEWLIB_DIR)
+###             |---Toolchain-spec-handy-ruler----------------|
+H5_NEWLIB_SPEC = Allwinner H5 newlib toolchain
+
+# AllWinner H5-GLIBC
+TOOLCHAIN_H5_GLIBC = h5-glibc
+
+H5_GLIBC_ARCH = aarch64-h5-linux-gnu
+H5_GLIBC_DIR  = aarch64-H5-linux-glibc
+H5_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(H5_GLIBC_DIR)
+###            |---Toolchain-spec-handy-ruler----------------|
+H5_GLIBC_SPEC = Allwinner H5 GNU Libc toolchain
+
+
+# Amlogic S8XX-GLIBC
+TOOLCHAIN_S8XX_GLIBC = s8xx-glibc
+
+S8XX_GLIBC_ARCH = arm-s8xx-linux-gnueabihf
+S8XX_GLIBC_DIR  = arm-S8XX-linux-glibc
+S8XX_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(S8XX_GLIBC_DIR)
+###              |---Toolchain-spec-handy-ruler----------------|
+S8XX_GLIBC_SPEC = Amlogic S8xx GNU Libc toolchain
+
+
+# Amlogic S9XX (especially for u-boot firmware)
+TOOLCHAIN_A9XX_NEWLIB = a9xx-newlib
+
+A9XX_NEWLIB_ARCH = arm-a9xx-eabi
+A9XX_NEWLIB_DIR  = arm-A9XX-eabi-newlib
+A9XX_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(A9XX_NEWLIB_DIR)
+###               |---Toolchain-spec-handy-ruler----------------|
+A9XX_NEWLIB_SPEC = Amlogic S9xx Cortex-m3 newlib toolchain
+
+# Amlogic S9XX
+TOOLCHAIN_S9XX_NEWLIB = s9xx-newlib
+
+S9XX_NEWLIB_ARCH = aarch64-s9xx-elf
+S9XX_NEWLIB_DIR  = aarch64-S9XX-elf-newlib
+S9XX_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(S9XX_NEWLIB_DIR)
+###               |---Toolchain-spec-handy-ruler----------------|
+S9XX_NEWLIB_SPEC = Amlogic S9xx newlib toolchain
+
+# Amlogic S9XX-GLIBC
+TOOLCHAIN_S9XX_GLIBC = s9xx-glibc
+
+S9XX_GLIBC_ARCH = aarch64-s9xx-linux-gnu
+S9XX_GLIBC_DIR  = aarch64-S9XX-linux-glibc
+S9XX_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(S9XX_GLIBC_DIR)
+###              |---Toolchain-spec-handy-ruler----------------|
+S9XX_GLIBC_SPEC = Amlogic S9xx GNU Libc toolchain
+
+# Amlogic A9XX-GLIBC
+TOOLCHAIN_A9XX_GLIBC = a9xx-glibc
+
+A9XX_GLIBC_ARCH = armv8l-a9xx-linux-gnueabihf
+A9XX_GLIBC_DIR  = armv8l-A9XX-linux-glibc
+A9XX_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(A9XX_GLIBC_DIR)
+###              |---Toolchain-spec-handy-ruler----------------|
+A9XX_GLIBC_SPEC = Amlogic S9xx armv8l GNU Libc toolchain
+
+# Amlogic A311X-GLIBC
+TOOLCHAIN_A311X_GLIBC = a311x-glibc
+
+A311X_GLIBC_ARCH = aarch64-a311x-linux-gnu
+A311X_GLIBC_DIR  = aarch64-A311X-linux-glibc
+A311X_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(A311X_GLIBC_DIR)
+###               |---Toolchain-spec-handy-ruler----------------|
+A311X_GLIBC_SPEC = Amlogic A311X GNU Libc toolchain
+
+
+# Rockchip A33XX-NEWLIB (ARMv6-M Cortex-m0)
+TOOLCHAIN_A33XX_NEWLIB = a33xx-newlib
+
+A33XX_NEWLIB_ARCH = arm-a33xx-eabi
+A33XX_NEWLIB_DIR  = arm-A33XX-eabi-newlib
+A33XX_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(A33XX_NEWLIB_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+A33XX_NEWLIB_SPEC = Rockchip RK33xx Cortex-m0 newlib toolchain
+
+# Rockchip RK33XX-NEWLIB
+TOOLCHAIN_RK33XX_NEWLIB = rk33xx-newlib
+
+RK33XX_NEWLIB_ARCH = aarch64-rk33xx-elf
+RK33XX_NEWLIB_DIR  = aarch64-RK33XX-elf-newlib
+RK33XX_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(RK33XX_NEWLIB_DIR)
+###                 |---Toolchain-spec-handy-ruler----------------|
+RK33XX_NEWLIB_SPEC = Rockchip RK33xx newlib toolchain
+
+# Rockchip RK33XX-GLIBC
+TOOLCHAIN_RK33XX_GLIBC = rk33xx-glibc
+
+RK33XX_GLIBC_ARCH = aarch64-rk33xx-linux-gnu
+RK33XX_GLIBC_DIR  = aarch64-RK33XX-linux-glibc
+RK33XX_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(RK33XX_GLIBC_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+RK33XX_GLIBC_SPEC = Rockchip RK33xx GNU Libc toolchain
+
+# Rockchip RK339X-GLIBC
+TOOLCHAIN_RK339X_GLIBC = rk339x-glibc
+
+RK339X_GLIBC_ARCH = aarch64-rk339x-linux-gnu
+RK339X_GLIBC_DIR  = aarch64-RK339X-linux-glibc
+RK339X_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(RK339X_GLIBC_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+RK339X_GLIBC_SPEC = Rockchip RK339x GNU Libc toolchain
+
+# Rockchip A33XX-GLIBC
+TOOLCHAIN_A33XX_GLIBC = a33xx-glibc
+
+A33XX_GLIBC_ARCH = armv8l-a33xx-linux-gnueabihf
+A33XX_GLIBC_DIR  = armv8l-A33XX-linux-glibc
+A33XX_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(A33XX_GLIBC_DIR)
+###               |---Toolchain-spec-handy-ruler----------------|
+A33XX_GLIBC_SPEC = Rockchip RK33xx armv8l GNU Libc toolchain
+
+
+# Rockchip RK328X-GLIBC
+TOOLCHAIN_RK328X_GLIBC = rk328x-glibc
+
+RK328X_GLIBC_ARCH = arm-rk328x-linux-gnueabihf
+RK328X_GLIBC_DIR  = arm-RK328X-linux-glibc
+RK328X_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(RK328X_GLIBC_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+RK328X_GLIBC_SPEC = Rockchip RK328x GNU Libc toolchain
+
+
+# JZ47XX-GLIBC
+TOOLCHAIN_JZ47XX_GLIBC = jz47xx-glibc
+
+JZ47XX_GLIBC_ARCH = mipsel-jz47xx-linux-gnu
+JZ47XX_GLIBC_DIR  = mipsel-JZ47XX-linux-glibc
+JZ47XX_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(JZ47XX_GLIBC_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+JZ47XX_GLIBC_SPEC = Ingenic MIPS jz47xx GNU Libc toolchain
+
+
+# P5600-GLIBC
+TOOLCHAIN_P5600_GLIBC = p5600-glibc
+
+P5600_GLIBC_ARCH = mipsel-p5600-linux-gnu
+P5600_GLIBC_DIR  = mipsel-P5600-linux-glibc
+P5600_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(P5600_GLIBC_DIR)
+###               |---Toolchain-spec-handy-ruler----------------|
+P5600_GLIBC_SPEC = Baikal MIPS p5600 core GNU Libc toolchain
+
+# BaikalElectronics M1000-NEWLIB
+TOOLCHAIN_M1000_NEWLIB = m1000-newlib
+
+M1000_NEWLIB_ARCH = aarch64-m1000-elf
+M1000_NEWLIB_DIR  = aarch64-M1000-elf-newlib
+M1000_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(M1000_NEWLIB_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+M1000_NEWLIB_SPEC = BaikalElectronics M1000 newlib toolchain
+
+# BaikalElectronics M1000-GLIBC
+TOOLCHAIN_M1000_GLIBC = m1000-glibc
+
+M1000_GLIBC_ARCH = aarch64-m1000-linux-gnu
+M1000_GLIBC_DIR  = aarch64-M1000-linux-glibc
+M1000_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(M1000_GLIBC_DIR)
+###               |---Toolchain-spec-handy-ruler----------------|
+M1000_GLIBC_SPEC = BaikalElectronics M1000 GNU Libc toolchain
+
+
+# POWER8-GLIBC
+TOOLCHAIN_POWER8_GLIBC = power8-glibc
+
+POWER8_GLIBC_ARCH = ppc64-power8-linux-gnu
+POWER8_GLIBC_DIR  = ppc64-POWER8-linux-glibc
+POWER8_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(POWER8_GLIBC_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+POWER8_GLIBC_SPEC = Openpower POWER8 MSB GNU Libc toolchain
+
+# POWER9-GLIBC
+TOOLCHAIN_POWER9_GLIBC = power9-glibc
+
+POWER9_GLIBC_ARCH = ppc64-power9-linux-gnu
+POWER9_GLIBC_DIR  = ppc64-POWER9-linux-glibc
+POWER9_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(POWER9_GLIBC_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+POWER9_GLIBC_SPEC = Openpower POWER9 MSB GNU Libc toolchain
+
+
+# POWER8LE-GLIBC
+TOOLCHAIN_POWER8LE_GLIBC = power8le-glibc
+
+POWER8LE_GLIBC_ARCH = ppc64le-power8-linux-gnu
+POWER8LE_GLIBC_DIR  = ppc64le-POWER8-linux-glibc
+POWER8LE_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(POWER8LE_GLIBC_DIR)
+###                  |---Toolchain-spec-handy-ruler----------------|
+POWER8LE_GLIBC_SPEC = Openpower POWER8 LSB GNU Libc toolchain
+
+# POWER9LE-GLIBC
+TOOLCHAIN_POWER9LE_GLIBC = power9le-glibc
+
+POWER9LE_GLIBC_ARCH = ppc64le-power9-linux-gnu
+POWER9LE_GLIBC_DIR  = ppc64le-POWER9-linux-glibc
+POWER9LE_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(POWER9LE_GLIBC_DIR)
+###                  |---Toolchain-spec-handy-ruler----------------|
+POWER9LE_GLIBC_SPEC = Openpower POWER9 LSB GNU Libc toolchain
+
+
+# All RISC-V 32,64-bit series with Newlib
+TOOLCHAIN_RISCV64_NEWLIB = riscv64-newlib
+
+RISCV64_NEWLIB_ARCH = riscv64-none-elf
+RISCV64_NEWLIB_DIR  = riscv64-NONE-elf-newlib
+RISCV64_NEWLIB_PATH = $(TOOLCHAINS_BASE_PATH)/$(RISCV64_NEWLIB_DIR)
+###                  |---Toolchain-spec-handy-ruler----------------|
+RISCV64_NEWLIB_SPEC = All RISC-V 32,64-bit series newlib toolchain
+
+# RISCV64-GLIBC
+TOOLCHAIN_RISCV64_GLIBC = riscv64-glibc
+
+RISCV64_GLIBC_ARCH = riscv64-rv64gc-linux-gnu
+RISCV64_GLIBC_DIR  = riscv64-RV64GC-linux-glibc
+RISCV64_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(RISCV64_GLIBC_DIR)
+###                 |---Toolchain-spec-handy-ruler----------------|
+RISCV64_GLIBC_SPEC = RISC-V 64-bit LSB GNU Libc toolchain
+
+
+# I586-GLIBC
+TOOLCHAIN_I586_GLIBC = i586-glibc
+
+I586_GLIBC_ARCH = i586-radix-linux-gnu
+I586_GLIBC_DIR  = i586-PC-linux-glibc
+I586_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(I586_GLIBC_DIR)
+###              |---Toolchain-spec-handy-ruler----------------|
+I586_GLIBC_SPEC = Intel i586 GNU Libc toolchain
+
+
+# I686-GLIBC
+TOOLCHAIN_I686_GLIBC = i686-glibc
+
+I686_GLIBC_ARCH = i686-radix-linux-gnu
+I686_GLIBC_DIR  = i686-PC-linux-glibc
+I686_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(I686_GLIBC_DIR)
+###              |---Toolchain-spec-handy-ruler----------------|
+I686_GLIBC_SPEC = Intel i686 GNU Libc toolchain
+
+
+# X86_64-GLIBC
+TOOLCHAIN_X86_64_GLIBC = x86_64-glibc
+
+X86_64_GLIBC_ARCH = x86_64-radix-linux-gnu
+X86_64_GLIBC_DIR  = x86_64-PC-linux-glibc
+X86_64_GLIBC_PATH = $(TOOLCHAINS_BASE_PATH)/$(X86_64_GLIBC_DIR)
+###                |---Toolchain-spec-handy-ruler----------------|
+X86_64_GLIBC_SPEC = Intel x86_64 GNU Libc toolchain
+
+
+
+CONFIG_MK=1
+endif
Index: configure-targets
===================================================================
--- configure-targets	(nonexistent)
+++ configure-targets	(revision 5)
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+CWD=`pwd`
+
+BUILDSYSTEM=${BUILDSYSTEM:-$CWD}
+
+CONFIG=${CONFIG:-targets-config.mk}
+CONSTANTS=${CONSTANTS:-config.mk}
+
+if [ ! -r $CONFIG ] ; then
+  echo "$0: ERROR: There is no $CONFIG file for configuring target HW."
+  echo ""
+  exit 1
+fi
+
+: ${DIALOG=$BUILDSYSTEM/sbin/dialog}
+: ${DIALOGRC=$BUILDSYSTEM/etc/dialogrc}
+
+export DIALOGRC
+
+: ${DIALOG_OK=0}
+: ${DIALOG_CANCEL=1}
+: ${DIALOG_HELP=2}
+: ${DIALOG_EXTRA=3}
+: ${DIALOG_ITEM_HELP=4}
+: ${DIALOG_ESC=255}
+
+: ${SIG_NONE=0}
+: ${SIG_HUP=1}
+: ${SIG_INT=2}
+: ${SIG_QUIT=3}
+: ${SIG_KILL=9}
+: ${SIG_TERM=15}
+
+
+umask 002
+if [ ! -z "$TMPDIR" ] ; then mkdir -p $TMPDIR ; fi
+TMP=$(mkdir -p /tmp/radix && mktemp -d -p /tmp/radix build-system.XXXXXXXX) || { echo "Cannot create '/tmp/...' directory" ; exit 92; }
+trap "rm -rf $TMP" 0 $SIG_NONE $SIG_HUP $SIG_INT $SIG_QUIT $SIG_TERM
+
+
+hwlist=`cat $CONFIG | grep "^BUILD_.*[ \t]*=.*" | sed "s,^BUILD_\(.*\)[ \t]*=.*,\1," | tr 'A-Z' 'a-z' | tr '\n' ' ' | sed 's/host//g' | tr -s ' ' | sed 's/^[ \t]//' | sed 's/[ \t]$//'`
+
+for hw in $hwlist ; do
+  hh=`echo $hw | tr 'a-z' 'A-Z'`
+  spec=`cat $CONSTANTS | grep "^${hh}_SPEC[ \t]*=.*" | sed "s,^${hh}_SPEC[ \t]*=[ \t]*\(.*\),\1," | sed "s,\\\\\,,g"`
+  enabled=`cat $CONFIG | grep "^BUILD_${hh}[ \t]*=.*" | sed "s,^BUILD_${hh}[ \t]*=[ \t]*\(.*\),\1,"`
+  if [ "$enabled" == "true" ] ; then
+    en="on"
+  else
+    en="off"
+  fi
+  echo "\"$hw\" \"$spec\" \"$en\"" >> $TMP/sel$$
+done
+
+$DIALOG --colors \
+        --backtitle "\Z7Build System\Zn" \
+        --title " \Z1SELECTING TOOLCHAINS TO BUILD\Zn " \
+        --clear \
+        --checklist "\n\
+\Zb\Z4Please confirm the toolchains you want to build\Zn\ZB.\n\n\
+Use the UP/DOWN keys to scroll through the list, and the SPACE key\n\
+to deselect any items you don't want to build.\n\n\
+Press ENTER when you are done." \
+21 72 8 \
+        --file $TMP/sel$$  2> $TMP/ret$$
+
+retval=$?
+
+case $retval in
+  $DIALOG_OK)
+    enabled="`cat $TMP/ret$$`"
+    for hw in $hwlist ; do
+      hh=`echo $hw | tr 'a-z' 'A-Z'`
+      sed -i "s,^\(BUILD_${hh}[ \t]*=[ \t]*\).*,\1false," $CONFIG
+    done
+    for hw in $enabled ; do
+      hh=`echo $hw | tr 'a-z' 'A-Z'`
+      sed -i "s,^\(BUILD_${hh}[ \t]*=[ \t]*\).*,\1true," $CONFIG
+    done
+    ;;
+esac

Property changes on: configure-targets
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: core.mk
===================================================================
--- core.mk	(nonexistent)
+++ core.mk	(revision 5)
@@ -0,0 +1,842 @@
+
+# include once
+ifndef CORE_MK
+
+#######
+####### helpful variables
+#######
+
+comma := ,
+empty :=
+space := $(empty) $(empty)
+
+
+#######
+####### Set up TOP_BUILD_DIR, TOP_BUILD_DIR_ABS and BUILDSYSTEM variables
+#######
+
+ifndef MAKEFILE_LIST
+
+# Work-around for GNU make pre-3.80, which lacks MAKEFILE_LIST and $(eval ...)
+
+TOP_BUILD_DIR := $(shell perl -e 'for ($$_ = "$(CURDIR)"; ! -d "$$_/build-system"; s!(.*)/(.*)!\1!) { $$q .= "../"; } chop $$q; print "$$q"')
+ifeq ($(TOP_BUILD_DIR),)
+TOP_BUILD_DIR=.
+endif
+export TOP_BUILD_DIR_ABS := $(shell perl -e 'for ($$_ = "$(CURDIR)"; ! -d "$$_/build-system"; s!(.*)/(.*)!\1!) { } print')
+export BUILDSYSTEM := $(TOP_BUILD_DIR_ABS)/build-system
+
+else
+
+# Normal operation for GNU make 3.80 and above
+
+__pop = $(patsubst %/,%,$(dir $(1)))
+__tmp := $(call __pop,$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
+# Special case for build-system/Makefile
+ifeq ($(__tmp),.)
+__tmp := ../$(notdir $(CURDIR))
+endif
+
+ifndef TOP_BUILD_DIR
+TOP_BUILD_DIR := $(call __pop,$(__tmp))
+endif
+
+ifndef TOP_BUILD_DIR_ABS
+TOP_BUILD_DIR_ABS := $(CURDIR)
+ifneq ($(TOP_BUILD_DIR),.)
+$(foreach ,$(subst /, ,$(TOP_BUILD_DIR)),$(eval TOP_BUILD_DIR_ABS := $(call __pop,$(TOP_BUILD_DIR_ABS))))
+endif
+export TOP_BUILD_DIR_ABS
+endif
+
+ifndef BUILDSYSTEM
+export BUILDSYSTEM := $(TOP_BUILD_DIR_ABS)/$(notdir $(__tmp))
+endif
+
+endif
+
+#######
+####### Set up SOURCE PACKAGE directory:
+#######
+
+export SRC_PACKAGE_DIR      := sources
+export SRC_PACKAGE_PATH     := $(TOP_BUILD_DIR)/$(SRC_PACKAGE_DIR)
+export SRC_PACKAGE_PATH_ABS := $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)
+
+
+
+#######
+####### Config:
+#######
+
+include $(BUILDSYSTEM)/config.mk
+
+TOOLCHAIN_ALL = $(strip $(foreach t, $(filter TOOLCHAIN_%,       \
+                                 $(filter-out TOOLCHAIN_ALL      \
+                                              TOOLCHAIN_NAMES    \
+                                              TOOLCHAIN_DIR      \
+                                              TOOLCHAIN_PATH     \
+                                              TOOLCHAIN_VERSION, \
+                                              $(.VARIABLES))), $($(t))))
+
+TOOLCHAIN_NAMES = $(filter-out $(TOOLCHAIN_NOARCH), $(TOOLCHAIN_ALL))
+
+COMPONENT_TOOLCHAINS = $(TOOLCHAIN_ALL)
+
+
+#######
+####### Set up targets etc
+#######
+
+ifneq ($(wildcard $(BUILDSYSTEM)/targets-config.mk),)
+include $(BUILDSYSTEM)/targets-config.mk
+else
+include $(BUILDSYSTEM)/targets-config.mk.template
+endif
+
+# Reading targets-config.mk:
+
+# BUILD_NOARCH always enabled:
+BUILD_NOARCH = true
+
+enabled = $(filter BUILD_%, $(filter-out BUILD_TARGETS BUILD_ARCH, $(.VARIABLES)))
+
+toolchain_filter = $(strip $(foreach t, \
+                     $(strip $(foreach b, \
+                       $(enabled), $(if $(filter true, $($(b))), \
+                         $(subst BUILD_, TOOLCHAIN_, $(b))))), $($(t))))
+
+
+# If no TOOLCHAIN set
+ifeq ($(TOOLCHAIN),)
+
+# COMPONENT_TARGETS must have a value specified in the Makefile
+ifeq ($(COMPONENT_TARGETS),)
+$(error Error: COMPONENT_TARGETS must have a value)
+endif
+
+# End if no TARGET set
+endif
+
+# Error ff TOOLCHAIN is invalid
+ifneq ($(TOOLCHAIN),)
+ifeq ($(filter $(TOOLCHAIN), $(TOOLCHAIN_ALL)),)
+$(error Error: TOOLCHAIN is invalid)
+endif
+endif
+
+
+#######
+####### Filter out disabled targets
+#######
+
+COMPONENT_TARGETS := $(filter $(toolchain_filter), $(COMPONENT_TARGETS))
+
+
+#######
+####### Targets setup:
+#######
+
+COMPONENT_TOOLCHAINS := $(filter $(COMPONENT_TARGETS),$(COMPONENT_TOOLCHAINS))
+
+
+#
+# TARGET, TOOLCHAIN_PATH variables should be set up for each makefile
+#
+
+# If toolchain version is not exported then we use default one 
+ifeq ($(TOOLCHAIN_VERSION),)
+TOOLCHAIN_VERSION = $(TOOLCHAINS_VERSION)
+endif
+
+#
+# Setup current toolchain variables
+#
+
+TOOLCHAIN_DIR  = $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_DIR)
+TOOLCHAIN_PATH = $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_PATH)/$(TOOLCHAIN_VERSION)
+TARGET         = $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_ARCH)
+
+
+#######
+####### Configuration:
+#######
+
+# Build environment:
+
+DEST_DIR_ABS           = $(TOP_BUILD_DIR_ABS)/dist
+
+ifeq ($(NEEDS_ABS_PATHS),)
+DEST_DIR               = $(TOP_BUILD_DIR)/dist
+else
+DEST_DIR               = $(DEST_DIR_ABS)
+endif
+
+TARGET_DEST_DIR        = $(DEST_DIR)/$(TOOLCHAIN)
+
+
+################################################################
+# Check the list of available targets for current Makefile
+#
+__available_targets =                                                                 \
+  $(foreach arch, $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'), \
+    $(if $(FLAVOURS),                                                                 \
+      $(foreach flavour, $(FLAVOURS),                                                 \
+        .target_$(arch)_$(flavour)                                                    \
+       ) .target_$(arch),                                                             \
+      .target_$(arch)                                                                 \
+     )                                                                                \
+   )
+
+__available_targets := $(strip $(__available_targets))
+__available_targets := $(sort $(__available_targets))
+#
+#
+################################################################
+
+
+
+#######
+####### Number of CPU cores:
+#######
+
+NUMPROCS := 1
+OS       := $(shell uname -s)
+
+ifeq ($(OS),Linux)
+NUMPROCS := $(shell grep -c ^processor /proc/cpuinfo)
+endif
+
+
+#######
+####### Parallel control:
+#######
+
+ifneq ($(NO_PARALLEL),)
+MAKEFLAGS += -j1
+.NOTPARALLEL:
+endif
+
+ifeq ($(VERBOSE),)
+guiet = @
+else
+quiet =
+endif
+
+
+
+#######
+####### Default PREFIX:
+#######
+
+PREFIX ?= $(DEST_DIR)
+
+
+#######
+####### Setup ccache:
+#######
+
+ifeq ($(NO_CCACHE),)
+CCACHE = /usr/bin/ccache$(space)
+
+ifeq ($(wildcard $(CCACHE)),)
+$(info )
+$(info #######)
+$(info ####### Please install 'ccache' package)
+$(info ####### or disable ccache with "NO_CCACHE=1 make ...")
+$(info #######)
+$(info )
+$(error Error: ccache not found)
+endif
+
+ifeq ($(wildcard $(CACHED_CC_OUTPUT)),)
+$(info )
+$(info #######)
+$(info ####### Please create directory $(CACHED_CC_OUTPUT) for cached compiler output)
+$(info ####### or disable ccache with "NO_CCACHE=1 make ...")
+$(info #######)
+$(info )
+$(error Error: cached compiler output directory doesn't exist)
+endif
+
+export CCACHE_BASEDIR = $(TOP_BUILD_DIR_ABS)
+export CCACHE_DIR     = $(CACHED_CC_OUTPUT)
+export CCACHE_UMASK   = 000
+
+unexport CCACHE_PREFIX
+else
+CCACHE =
+endif
+
+
+
+#######
+####### Cleanup files:
+#######
+
+CLEANUP_FILES += .dist.*
+CLEANUP_FILES += $(addprefix ., $(TOOLCHAIN))
+CLEANUP_FILES += .*requires*
+CLEANUP_FILES += $(SRC_DIR)
+CLEANUP_FILES += $(SRC_DIR).back.??????
+
+
+#######
+####### Build rules:
+#######
+
+all: BUILD_TREE := true
+export BUILD_TREE
+
+all:
+	@$(MAKE) local_all
+
+#
+# clean is equal to local_clean
+#
+clean:
+	@$(MAKE) local_clean
+
+
+__quick_targets := help configure_targets local_clean downloads_clean targets-config.mk $(HACK_TARGETS)
+
+
+#
+# GLOBAL setup targets:
+# ====================
+#   These targets are built before all targets. For example, source tarballs
+#   have to be downloaded before starting the build.
+#
+#   NOTE:
+#     BUILDSYSTEM is a setup target for other directories and the BUILDSYSTEM
+#     requires only '.sources' target as a setup target.
+#
+ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
+ifeq ($(shell pwd),$(BUILDSYSTEM))
+__setup_targets = .sources
+else
+__setup_targets = .sources .build_system
+endif
+endif
+
+
+
+.setup:
+ifeq ($(__final__),)
+.setup: $(__setup_targets)
+else
+.setup: .makefile
+endif
+
+
+# Check if Makefile has been changed:
+
+.makefile: Makefile
+ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
+ifneq ($(if $(MAKECMDGOALS),$(filter-out $(__quick_targets),$(MAKECMDGOALS)),true),)
+	@touch $@
+ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
+	@echo -e "\n======= New makefile ($(<F)), clean! ======="
+	@$(MAKE) dist_clean
+	@if $(MAKE) local_clean ; then true ; else rm -f $@ ; fi
+else
+	@if $(MAKE) download_clean ; then true ; else rm -f $@; fi
+endif
+endif
+endif
+
+
+
+#######
+####### Build directory dependencies into .src_requires  which
+####### is used as a Makefile for srource tarballs downloading
+#######
+
+.sources: .src_requires
+
+.src_requires_depend: .src_requires ;
+
+.src_requires: .makefile
+ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
+ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
+ifeq ($(__final__),)
+	@echo ""
+	@echo -e "################################################################"
+	@echo -e "#######"
+	@echo -e "####### Start of building source requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))':"
+	@echo -e "#######"
+	@$(BUILDSYSTEM)/build_src_requires $(TOP_BUILD_DIR_ABS)
+	@__final__= TREE_RULE=local_all $(MAKE) TOOLCHAIN=$(TOOLCHAIN_NOARCH) FLAVOUR= -f .src_requires
+	@echo -e "#######"
+	@echo -e "####### End of building source requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))'."
+	@echo -e "#######"
+	@echo -e "################################################################"
+	@echo ""
+	@touch $@
+	@touch .src_requires_depend
+endif
+endif
+endif
+
+
+
+.build_system:
+ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
+ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
+ifeq ($(shell pwd | grep $(BUILDSYSTEM)),)
+	@echo -e "################################################################"
+	@echo -e "#######"
+	@echo -e "####### Start to Check the BUILDSYSTEM is ready:"
+	@echo -e "#######"
+	@( cd $(BUILDSYSTEM) ; __final__= $(MAKE) TOOLCHAIN=$(TOOLCHAIN_HOST) FLAVOUR= all )
+	@echo -e "#######"
+	@echo -e "####### End of checking the BUILDSYSTEM."
+	@echo -e "#######"
+	@echo -e "################################################################"
+endif
+endif
+endif
+
+
+
+#######
+####### Clean up default rules (not depend of TOOLCHAIN):
+#######
+
+dist_clean:
+	@if [ -f .dist ]; then $(BUILDSYSTEM)/dist_clean $(DEST_DIR); rm .dist; fi
+
+
+# NOTE:
+# ====
+#   Do not create directories with names that match the names of architectures!!!
+#
+tree_clean: .tree_clean
+
+.tree_clean:
+	@echo "Tree Clean..."
+	@$(BUILDSYSTEM)/tree_clean $(addprefix ., $(TOOLCHAIN_NAMES)) $(TOP_BUILD_DIR_ABS)
+
+
+#######
+####### Clean all downloaded source tarballs
+#######
+
+downloads_clean: .downloads_clean
+
+.downloads_clean:
+	@echo ""
+	@echo -e "#######"
+	@echo -e "####### Cleaning Up all downloaded sources..."
+	@echo -e "#######"
+	@$(BUILDSYSTEM)/downloads_clean $(addprefix ., $(TOOLCHAIN_NOARCH)) $(BUILDSYSTEM)/3pp/sources
+ifneq ($(wildcard $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)),)
+	@$(BUILDSYSTEM)/downloads_clean $(addprefix ., $(TOOLCHAIN_NOARCH)) $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)
+endif
+
+help:
+	@echo ""
+	@echo -e "You can build and install software using command line such as follow:"
+	@echo ""
+	@echo -e "   $$ [TOOLCHAIN_VERSION=version] [TOOLCHAIN=toolchain] [FLAVOUR=flavour] make [goal]"
+	@echo ""
+	@echo -e "The following MAKE goals are available:"
+	@echo ""
+	@echo -e "   all                - perform make build and install software in the all"
+	@echo -e "                        required directories which defined by REQUIRES"
+	@echo -e "                        variable in the local Makefile;"
+	@echo -e "   local_all          - build and install software prepared onlu by local"
+	@echo -e "                        Makefile;"
+	@echo -e "   dist_clean,"
+	@echo -e "   local_dist_clean   - remove distribution packages from target directory"
+	@echo -e "                        defined by PRODUCTS_DEST_DIR variable. Note that"
+	@echo -e "                        is depends from targets defined by COMPONENT_TARGETS"
+	@echo -e "                        variable or command line;"
+	@echo -e "   clean,"
+	@echo -e "   local_clean        - clean up all built targets by this Makefile;"
+	@echo ""
+	@echo -e "   If the one from above goals has prefix 'local_' then this goal affects only"
+	@echo -e "   current directory.  Otherwise this goal will be performed for all required"
+	@echo -e "   directories which defined by REQUIRES variable."
+	@echo ""
+	@echo -e "   configure_targets  - select toolchains you want to built."
+	@echo -e "                        This command edits the targets-config.mk file;"
+	@echo ""
+	@echo -e "   tree_clean         - clean up whole sourses tree excluding downloaded"
+	@echo -e "                        source tarballs;"
+	@echo -e "   downloads_clean    - remove all sourse tarball from 'sourses' directory;"
+	@echo ""
+	@echo -e "Local Makefile is prepared for following target toolchains:"
+	@echo ""
+	@for toolchain in $(COMPONENT_TARGETS) ; do \
+	  echo -e "   $$toolchain"; \
+	 done
+	@echo ""
+	@echo -e "Enjoy."
+	@echo ""
+
+configure_targets: $(BUILDSYSTEM)/targets-config.mk
+	@BUILDSYSTEM=$(BUILDSYSTEM)              \
+	 CONFIG=$(BUILDSYSTEM)/targets-config.mk \
+	 CONSTANTS=$(BUILDSYSTEM)/config.mk \
+	 $(BUILDSYSTEM)/configure-targets
+
+
+#######
+####### Source archive and patch handling
+#######
+
+# Patch dependency:
+PATCHES_DEP = $(foreach patch,$(PATCHES),\
+	$(shell $(BUILDSYSTEM)/apply_patches $(patch) -dep-))
+
+SRC_DIR_BASE = $(dir $(SRC_DIR))
+
+# Unpack SRC_ARCHIVE in SRC_DIR and backup old SRC_DIR:
+UNPACK_SRC_ARCHIVE = \
+	@echo "Expanding $(SRC_ARCHIVE)"; \
+	if [ -d $(SRC_DIR) ]; then mv $(SRC_DIR) $$(mktemp -d $(SRC_DIR).bak.XXXXXX); fi; \
+	mkdir -p $(SRC_DIR_BASE); \
+	$(if $(findstring .rpm,$(SRC_ARCHIVE)), \
+	  cd $(SRC_DIR_BASE) && rpm2cpio $(SRC_ARCHIVE) | cpio -id --quiet, \
+	  $(if $(findstring .zip,$(SRC_ARCHIVE)), \
+	    unzip -q -d $(SRC_DIR_BASE) $(SRC_ARCHIVE), \
+	    tar $(if $(findstring .bz2,$(SRC_ARCHIVE)),-xjf, \
+	             $(if $(findstring .xz,$(SRC_ARCHIVE)),-xJf, \
+	             $(if $(findstring .txz,$(SRC_ARCHIVE)),-xJf,-xzf))) \
+	      $(SRC_ARCHIVE) -C $(SRC_DIR_BASE))); \
+	chmod -R u+w $(SRC_DIR)
+
+# Apply patches in PATCHES on SRC_DIR_BASE:
+APPLY_PATCHES = $(quiet)$(foreach patch,$(PATCHES),\
+	$(BUILDSYSTEM)/apply_patches $(patch) $(SRC_DIR_BASE) &&) true
+
+# Apply optional patches in OPT_PATCHES on SRC_DIR_BASE:
+APPLY_OPT_PATCHES = $(quiet)$(foreach patch,$(OPT_PATCHES),\
+	$(BUILDSYSTEM)/apply_patches $(patch) $(SRC_DIR_BASE) &&) true
+
+
+# Example rule:
+#
+# src_done = $(SRC_DIR)/.source-done
+#
+# $(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP)
+# 	$(UNPACK_SRC_ARCHIVE)
+# 	$(APPLY_PATCHES)
+# 	 <other stuff that needs to be done to the source,
+# 	   should be empty in most cases>
+# 	@touch $@
+
+
+################################################################
+#######
+####### Include files with references to BUILD-SYSTEM scripts:
+#######
+
+-include $(BUILDSYSTEM)/sbin/.config
+
+#######
+####### References to BUILD-SYSTEM scripts.
+#######
+################################################################
+
+
+
+
+################################################################
+#
+# No '__final__' target selected:
+# ==============================
+#
+# Parse TOOLCHAIN, HARDWARE, FLAVOUR selected in command line
+# and build the list of '__final__' targets.
+#
+ifeq ($(__final__),)
+
+#
+# The FLAVOUR can be defined in command line.
+# If command line defines empty flavour FLAVOUR= then
+# we define that variable is set but has no values.
+#
+__cmdline_flavour_defined = $(if $(filter FLAVOUR,$(.VARIABLES)),true,false)
+ifeq ($(__cmdline_flavour_defined),true)
+__cmdline_flavour_value = $(FLAVOUR)
+else
+__cmdline_flavour_value =
+endif
+
+
+##################################################
+# -----------+---------+-------------------+-----
+#  TOOLCHAIN | FLAVOUR | FLAVOUR has VALUE | REF
+# -----------+---------+-------------------+-----
+#    defined | defined |         no        | (0)
+#    defined | defined |         yes       | (1)
+#    defined |    ~    |         ~         | (2)
+#       ~    | defined |         no        | (3)
+#       ~    | defined |         yes       | (4)
+#       ~    |    ~    |         ~         | (5)
+# -----------+---------+-------------------+-----
+##################################################
+
+ifeq ($(TOOLCHAIN),)
+ifeq ($(__cmdline_flavour_defined),false)
+ifeq ($(FLAVOUR),)
+# (5) then we loop over all available flavours
+__target_args = $(__available_targets)
+endif
+else
+ifneq ($(FLAVOUR),)
+# (4) then we use only one defined flavour
+__target_args = $(foreach toolchain,                                                          \
+                    $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'),       \
+                    .target_$(toolchain)_$(FLAVOUR)                                           \
+                 )
+else
+# (3) then we define flavour as empty
+__target_args = $(foreach toolchain,                                                          \
+                    $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'),       \
+                    .target_$(toolchain)                                                      \
+                 )
+endif
+endif
+else
+ifeq ($(__cmdline_flavour_defined),false)
+ifeq ($(FLAVOUR),)
+# (2) then we loop over all available flavours
+__target_args = .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g') $(if $(FLAVOURS), $(foreach flavour, $(FLAVOURS), .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(flavour)),)
+endif
+else
+ifneq ($(FLAVOUR),)
+# (1) then we use only one defined flavour
+__target_args = .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(FLAVOUR)
+else
+# (0) then we define flavour as empty
+__target_args = .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')
+endif
+endif
+endif
+
+
+__target_args := $(strip $(__target_args))
+
+
+__targets = $(filter $(__target_args), $(__available_targets))
+
+# Now we have to sort targets for that the main targets should be built before flavours!
+__targets := $(sort $(__targets))
+
+
+ifeq ($(__targets),)
+$(error Error: Selected combination [TOOLCHAIN=$(TOOLCHAIN), FLAVOUR=$(FLAVOUR)] is invalid for this Makefile)
+endif
+
+
+$(__targets): .setup
+
+local_all: GOAL = local_all
+local_all: $(__targets)
+
+local_clean: GOAL = local_clean
+local_clean: $(__targets)
+
+
+.target_%: TOOLCHAIN = $(shell echo $(word 2, $(subst _, , $@)) | sed -e 's/x86-64/x86_64/g')
+.target_%: FLAVOUR = $(word 3, $(subst _, , $@))
+.target_%:
+	@echo ""
+	@echo "======="
+	@echo "======= TOOLCHAIN: $(TOOLCHAIN); FLAVOUR =$(if $(FLAVOUR), $(FLAVOUR));  ====="
+	@echo "======="
+	@__final__=true $(MAKE) TOOLCHAIN=$(TOOLCHAIN) FLAVOUR=$(FLAVOUR) $(GOAL)
+
+else
+#
+################################################################
+#
+# The '__final__' target is defined, run the build process.
+
+
+# Target is selected, build it
+
+ifneq ($(NO_CREATE_DIST_FILES),true)
+local_all: CREATE_DIST_FILES = 1
+endif
+
+ifneq ($(findstring $(TOOLCHAIN),$(TOOLCHAIN_NAMES)),)
+ifeq ($(shell pwd),$(BUILDSYSTEM))
+$(shell mkdir -p .$(TOOLCHAIN))
+else
+$(shell mkdir -p .$(TOOLCHAIN)$(if $(FLAVOUR),/$(FLAVOUR)))
+endif
+endif
+
+# TOOLCHAIN/FLAVOUR depended directories
+
+ifneq ($(TOOLCHAIN),$(TOOLCHAIN_NOARCH))
+ifeq ($(shell pwd),$(BUILDSYSTEM))
+targetflavour = .$(TOOLCHAIN)
+else
+targetflavour = .$(TOOLCHAIN)$(if $(FLAVOUR),/$(FLAVOUR))
+endif
+else
+targetflavour = $(CURDIR)
+endif
+
+TARGET_BUILD_DIR = $(targetflavour)
+
+
+
+ifeq ($(BUILD_TREE),true)
+_tree := .tree_all
+else
+_tree := .requires_tree
+endif
+
+
+local_all: $(_tree) install
+
+local_clean:
+
+
+.tree_all: $(TARGET_BUILD_DIR)/.requires
+ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
+ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
+	@echo -e "################################################################"
+	@echo -e "#######"
+ifeq ($(shell pwd),$(BUILDSYSTEM))
+	@echo -e "####### Start of building requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))':"
+else
+	@echo -e "####### Start of building requires for TOOLCHAIN=$(TOOLCHAIN) FLAVOUR=$(FLAVOUR) in '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))':"
+endif
+	@echo -e "#######"
+ifeq ($(shell pwd),$(BUILDSYSTEM))
+	@__final__=true TREE_RULE=local_all $(MAKE) TOOLCHAIN=$(TOOLCHAIN_HOST) FLAVOUR= -f $(TARGET_BUILD_DIR)/.requires
+else
+	@__final__=true TREE_RULE=local_all $(MAKE) TOOLCHAIN=$(TOOLCHAIN) FLAVOUR= -f $(TARGET_BUILD_DIR)/.requires
+endif
+	@echo -e "#######"
+	@echo -e "####### End of building requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))'."
+	@echo -e "#######"
+	@echo -e "################################################################"
+endif
+endif
+
+
+.requires_tree: $(TARGET_BUILD_DIR)/.requires
+
+#######
+####### Build directory dependencies into $(TARGET_BUILD_DIR)/.requires
+####### file which is used as a Makefile for tree builds.
+#######
+
+$(TARGET_BUILD_DIR)/.requires_depend: $(TARGET_BUILD_DIR)/.requires ;
+
+$(TARGET_BUILD_DIR)/.requires: .makefile
+ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
+ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
+ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
+ifeq ($(shell pwd),$(BUILDSYSTEM))
+	@$(BUILDSYSTEM)/build_requires $(TOP_BUILD_DIR_ABS) $(TOOLCHAIN_HOST) ; wait
+else
+	@$(BUILDSYSTEM)/build_requires $(TOP_BUILD_DIR_ABS) $(TOOLCHAIN) $(FLAVOUR) ; wait
+endif
+endif
+endif
+endif
+
+
+
+
+################################################################
+#######
+####### Waiting for build whole required tree:
+#######
+
+$(BUILD_TARGETS): | $(_tree)
+
+#######
+####### End of waiting for build whole required tree.
+#######
+################################################################
+
+$(PRODUCT_TARGETS) : | $(BUILD_TARGETS)
+
+
+#######
+####### Install:
+#######
+
+install: .install
+	@if [ "$$(echo .dist*)" != ".dist*" ]; then \
+	  sort -o .dist.tmp -u .dist* && mv .dist.tmp .dist; \
+	fi
+	@rm -f .dist.*
+
+
+.install: .install_builds .install_products
+
+
+
+
+.install_builds: $(BUILD_TARGETS)
+# Do nothing
+
+.install_products: DO_CREATE_DIST_FILES = $(CREATE_DIST_FILES)
+export DO_CREATE_DIST_FILES
+
+.install_products: $(PRODUCT_TARGETS)
+ifdef PRODUCT_TARGETS
+	@$(BUILDSYSTEM)/install_targets $^ $(PREFIX)/products
+endif
+
+
+
+
+#######
+####### Clean up default rules:
+#######
+
+clean: local_clean
+
+local_clean: .local_clean
+
+.local_clean:
+ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
+ifneq ($(wildcard .$(TOOLCHAIN)),)
+	@echo "Cleaning... $(TOOLCHAIN)"
+	@rm -rf $(CLEANUP_FILES)
+endif
+endif
+
+
+-include .src_requires_depend
+-include $(TARGET_BUILD_DIR)/.requires_depend
+
+
+endif
+#
+# end of ifeq ($(__final__),)
+#
+################################################################
+
+### Declare some targets as phony
+
+.PHONY: .target*
+.PHONY: .setup .sources .build_system .gnat_tools
+
+.PHONY: .tree_all .requites_tree
+
+.PHONY: all local_all .clean local_clean clean
+.PHONY: .install
+
+.PHONY: help
+.PHONY: downloads_clean
+.PHONY: .downloads_clean
+
+.SUFFIXES:
+
+
+
+CORE_MK = 1
+endif
Index: dist_clean
===================================================================
--- dist_clean	(nonexistent)
+++ dist_clean	(revision 5)
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+
+use File::Basename;
+
+$base = $ARGV[0];
+
+open( F, '<', '.dist' ) or die "Could not open .dist";
+
+while( <F> )
+{
+  chomp;
+  $f = "$base/$_";
+  unlink $f;
+  $dirs{dirname($f)}++;
+}
+
+foreach ( sort { length($b) <=> length($a) } keys %dirs )
+{
+  while( rmdir )
+  {
+    $_ = dirname( $_ );
+  }
+}

Property changes on: dist_clean
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: downloads_clean
===================================================================
--- downloads_clean	(nonexistent)
+++ downloads_clean	(revision 5)
@@ -0,0 +1,116 @@
+#!/usr/bin/perl
+
+use FindBin;
+use lib $FindBin::Bin;
+
+use strict;
+use warnings FATAL => 'all';
+
+use File::Find;
+use _kxLab;
+
+
+# Global variables
+my $header_printed = 0;
+
+my $top_dir;
+my @targets;
+my $verbose = $ENV{VERBOSE};
+
+my %seen;
+my ( @dist_clean_dirs, @clean_dirs, @dist_clean_dirs_all, @clean_dirs_all );
+my ( $dist_clean_count, $clean_count );
+
+sub do_clean
+{
+  unlink "$top_dir/.makefile";
+
+  foreach my $d ( @clean_dirs )
+  {
+    my $printed_d;
+
+    $printed_d = $d;
+    $printed_d =~ s/^$top_dir\///;
+
+    print "\n=======\n" if ( $verbose );
+    print "======= Cleaning in $printed_d...\n" if ( $verbose );
+    print "=======\n" if ( $verbose );
+    _kxLab::system( "make -C $d download_clean" );
+    unlink "$d/.makefile";
+    unlink <$d/.*_requires*>;
+  }
+}
+
+sub do_clean_list
+{
+  my $dir = shift;
+  my $cwd = `pwd`;
+
+  chomp $cwd;
+
+  # skip not our directories where we create patches
+  return if( $cwd =~ m/.*create\-.*\-patch.*/ );
+
+  return if( ! -f "$cwd/Makefile" );
+
+  # needs clean:
+  push @clean_dirs_all, $cwd;
+}
+
+sub process_clean
+{
+  return if( ! $File::Find::dir =~ m/$top_dir\/sources/ );
+
+  # add directory which contains 'Makefile' too.
+  if( $_ eq "Makefile" ) { do_clean_list( $File::Find::dir ); }
+
+  return if( ! -d $_ );
+
+  foreach my $d ( @targets )
+  {
+    if( $d eq $_ ) { do_clean_list( $File::Find::dir ); }
+  }
+}
+
+
+foreach ( @ARGV )
+{
+  push @targets, $_;
+}
+$top_dir = pop @targets;
+
+if( ! -d $top_dir )
+{
+  die "\nTop: $top_dir: is not a directory\n\n";
+}
+if( ! $top_dir =~ m/^\// )
+{
+  die "\nTop: $top_dir: is not absolute path\n\n";
+}
+
+find( \&process_clean, "$top_dir" );
+
+# get unique names:
+%seen = ();
+@clean_dirs = grep { ! $seen{ $_ }++ } @clean_dirs_all;
+@clean_dirs = reverse( keys %seen );
+
+$clean_count = @clean_dirs;
+
+if( $clean_count != 0 )
+{
+  if( !$header_printed )
+  {
+    print "\n======= Cleaning downloads tree =======\n\n" if ( $verbose );
+    $header_printed = 1;
+  }
+
+  do_clean();
+
+  print "\n";
+}
+else
+{
+  print "\nCleaning...   (nothing to be done).\n\n";
+}
+

Property changes on: downloads_clean
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: install_targets
===================================================================
--- install_targets	(nonexistent)
+++ install_targets	(revision 5)
@@ -0,0 +1,131 @@
+#!/usr/bin/perl
+
+use FindBin;
+use lib $FindBin::Bin;
+
+use strict;
+use warnings FATAL => 'all';
+
+use File::Basename;
+use File::Temp;
+use _kxLab;
+
+# Global variables
+my $header_printed = 0;
+
+my $cleanup = $ENV{DO_CREATE_DIST_FILES} ? 0 : 1;
+my ($tempfd, $tempname) = File::Temp::tempfile(".dist.XXXXXX", UNLINK => $cleanup);
+
+# cleanpath( path )
+sub cleanpath
+{
+  my $path = shift;
+  $path =~ s!/{2,}!/!g;
+  return $path;
+}
+
+# dist( file )
+sub dist
+{
+  my $file = cleanpath(shift);
+  $file =~ s!^.*dist/!!;
+  print $tempfd "$file\n";
+}
+
+# newer_than( file1, file2 )
+sub newer_than
+{
+  my $file1 = shift;
+  my $file2 = shift;
+  _kxLab::error( "install_targets: Source file missing: $file1" ) if ( ! -f $file1 );
+  return( ! -f $file2 or -M $file1 < -M $file2 );
+}
+
+# install_tree( install_dir, file, target, verbose )
+sub install_tree
+{
+  my $install_dir = cleanpath(shift);
+  my $file = shift;
+  my $target = shift;
+  my $verbose = shift;
+
+  opendir(DIR, "$target");
+  my @files = readdir(DIR);
+  closedir DIR;
+  foreach my $f ( @files )
+  {
+    next if ($f eq "." or $f eq "..");
+    if( -d "$target/$f" )
+    {
+      install_tree( "$install_dir/$f", "$file/$f", "$target/$f", $verbose );
+    }
+    elsif( newer_than( "$target/$f", "$install_dir/$f" ) )
+    {
+      if( !$header_printed )
+      {
+        print "\n======= Installing files =======\n";
+        $header_printed = 1;
+      }
+      print "Installing $f in $install_dir\n" if ( $verbose );
+      _kxLab::system( "mkdir -p $install_dir" );
+      _kxLab::system( "cp -fa $target/$f $install_dir" );
+      dist( "$install_dir/$f" );
+    }
+  }
+}
+
+# install( install_dir, preserve_source_dir, verbose, targets )
+sub install
+{
+  my $install_dir = cleanpath(shift);
+  my $preserve_source_dir = shift;
+  my $verbose = shift;
+  my $targets = shift;
+
+  foreach my $target ( @{$targets} )
+  {
+    my $file = basename($target);
+    my $path = "";
+    if( $preserve_source_dir eq "true" )
+    {
+      $path = dirname( $target );
+    }
+
+    if( -d $target )
+    {
+      install_tree( "$install_dir/$path/$file", "$file", "$target", $verbose );
+    }
+    elsif( newer_than( $target, "$install_dir/$path/$file" ) )
+    {
+      if( !$header_printed )
+      {
+        print "\n======= Installing files =======\n";
+        $header_printed = 1;
+      }
+      print "Installing $file in $install_dir/$path\n" if ( $verbose );
+      _kxLab::system( "mkdir -p $install_dir/$path" );
+      _kxLab::system( "cp -fa $target $install_dir/$path" );
+      dist( "$install_dir/$path/$file" );
+    }
+  }
+}
+
+my $preserve_source_dir = "";
+my $dest_dir;
+my @targets;
+my $verbose = $ENV{VERBOSE};
+
+foreach ( @ARGV )
+{
+  if( /--preserve-source-dir=(\S*)/ )
+  {
+    $preserve_source_dir = $1;
+  }
+  else
+  {
+    push @targets, $_;
+  }
+}
+$dest_dir = pop @targets;
+
+install( $dest_dir, $preserve_source_dir, $verbose, \@targets );

Property changes on: install_targets
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: targets-config.mk.template
===================================================================
--- targets-config.mk.template	(nonexistent)
+++ targets-config.mk.template	(revision 5)
@@ -0,0 +1,113 @@
+
+# host
+BUILD_HOST = true
+
+
+# arm-none-eabi-newlib:
+BUILD_ARM32_NEWLIB = true
+
+# a33xx-newlib:
+BUILD_A33XX_NEWLIB = true
+
+# a9xx-newlib:
+BUILD_A9XX_NEWLIB = true
+
+# h5-newlib:
+BUILD_H5_NEWLIB = true
+
+# s9xx-newlib:
+BUILD_S9XX_NEWLIB = true
+
+# rk33xx-newlib:
+BUILD_RK33XX_NEWLIB = true
+
+# m1000-newlib:
+BUILD_M1000_NEWLIB = true
+
+# at91sam7s-newlib:
+BUILD_AT91SAM7S_NEWLIB = true
+
+# riscv64-none-elf-newlib:
+BUILD_RISCV64_NEWLIB = true
+
+
+# a1x-glibc:
+BUILD_A1X_GLIBC = true
+
+# a2x-glibc:
+BUILD_A2X_GLIBC = true
+
+# h3-glibc:
+BUILD_H3_GLIBC = true
+
+# h5-glibc:
+BUILD_H5_GLIBC = true
+
+# imx6-glibc:
+BUILD_IMX6_GLIBC = true
+
+# imx6ull-glibc:
+BUILD_IMX6ULL_GLIBC = true
+
+# jz47xx-glibc:
+BUILD_JZ47XX_GLIBC = true
+
+# p5600-glibc:
+BUILD_P5600_GLIBC = true
+
+# m1000-glibc:
+BUILD_M1000_GLIBC = true
+
+# omap543x-glibc:
+BUILD_OMAP543X_GLIBC = true
+
+# am335x-glibc:
+BUILD_AM335X_GLIBC = true
+
+# rk328x-glibc:
+BUILD_RK328X_GLIBC = true
+
+# s8xx-glibc:
+BUILD_S8XX_GLIBC = true
+
+# s9xx-glibc:
+BUILD_S9XX_GLIBC = true
+
+# a9xx-glibc:
+BUILD_A9XX_GLIBC = true
+
+# a311x-glibc:
+BUILD_A311X_GLIBC = true
+
+# rk33xx-glibc:
+BUILD_RK33XX_GLIBC = true
+
+# rk339x-glibc:
+BUILD_RK339X_GLIBC = true
+
+# a33xx-glibc:
+BUILD_A33XX_GLIBC = true
+
+# power8-glibc:
+BUILD_POWER8_GLIBC = true
+
+# power9-glibc:
+BUILD_POWER9_GLIBC = true
+
+# power8le-glibc:
+BUILD_POWER8LE_GLIBC = true
+
+# power9le-glibc:
+BUILD_POWER9LE_GLIBC = true
+
+# riscv64-glibc
+BUILD_RISCV64_GLIBC = true
+
+# i586-glibc:
+BUILD_I586_GLIBC = true
+
+# i686-glibc:
+BUILD_I686_GLIBC = true
+
+# x86_64-glibc:
+BUILD_X86_64_GLIBC = true
Index: tree-bs.mk
===================================================================
--- tree-bs.mk	(nonexistent)
+++ tree-bs.mk	(revision 5)
@@ -0,0 +1,9 @@
+
+# Generic rule used for directories
+
+all $(TREEDIRS):
+
+$(TREEDIRS):
+	@$(MAKE) FLAVOUR= -C $(TOP_BUILD_DIR_ABS)/$@ $(TREE_RULE)
+
+.PHONY: all $(TREEDIRS)
Index: tree-src.mk
===================================================================
--- tree-src.mk	(nonexistent)
+++ tree-src.mk	(revision 5)
@@ -0,0 +1,9 @@
+
+# Generic rule used for source directories
+
+all $(TREEDIRS):
+
+$(TREEDIRS):
+	@$(MAKE) -C $(TOP_BUILD_DIR_ABS)/$@ $(TREE_RULE)
+
+.PHONY: all $(TREEDIRS)
Index: tree.mk
===================================================================
--- tree.mk	(nonexistent)
+++ tree.mk	(revision 5)
@@ -0,0 +1,11 @@
+
+# Generic rule used for directories
+
+all $(TREEDIRS):
+
+get-flavour = $(if $(shell echo $1 | grep "\^"),$(shell echo $1 | cut -f 2 -d '^'),)
+
+$(TREEDIRS):
+	@$(MAKE) FLAVOUR=$(call get-flavour,$@) -C $(TOP_BUILD_DIR_ABS)/$(shell echo $@ | cut -f 1 -d '^') $(TREE_RULE)
+
+.PHONY: all $(TREEDIRS)
Index: tree_clean
===================================================================
--- tree_clean	(nonexistent)
+++ tree_clean	(revision 5)
@@ -0,0 +1,152 @@
+#!/usr/bin/perl
+
+use FindBin;
+use lib $FindBin::Bin;
+
+use strict;
+use warnings FATAL => 'all';
+
+use File::Find;
+use _kxLab;
+
+
+# Global variables
+my $header_printed = 0;
+
+my $top_dir;
+my @targets;
+my $verbose = $ENV{VERBOSE};
+
+my %seen;
+my ( @dist_clean_dirs, @clean_dirs, @dist_clean_dirs_all, @clean_dirs_all );
+my ( $dist_clean_count, $clean_count );
+
+sub do_clean
+{
+  unlink "$top_dir/.makefile";
+
+  foreach my $d ( @dist_clean_dirs )
+  {
+    my $printed_d;
+
+    $printed_d = $d;
+    $printed_d =~ s/^$top_dir\///;
+
+    print "\n===\n" if ( $verbose );
+    print "=== Dist cleaning in $printed_d...\n" if ( $verbose );
+    print "===\n" if ( $verbose );
+    _kxLab::system( "make -C $d dist_clean" );
+  }
+
+  foreach my $d ( @clean_dirs )
+  {
+    my $printed_d;
+
+    $printed_d = $d;
+    $printed_d =~ s/^$top_dir\///;
+
+    print "\n===\n" if ( $verbose );
+    print "=== Cleaning in $printed_d...\n" if ( $verbose );
+    print "===\n" if ( $verbose );
+    _kxLab::system( "make -C $d local_clean" );
+    unlink "$d/.makefile";
+  }
+}
+
+sub do_clean_list
+{
+  my $dir = shift;
+  my $cwd = `pwd`;
+
+  chomp $cwd;
+
+  return if( ! -f "$cwd/Makefile" );
+  return if( $dir =~ m/sources/ );
+
+  # needs dist clean:
+  if( -f "$cwd/.dist" ) { push @dist_clean_dirs_all, $cwd; }
+
+  # needs clean:
+  push @clean_dirs_all, $cwd;
+}
+
+sub process_clean
+{
+  # add directory which contains '.makefile' too.
+  if( $_ eq ".makefile" ) { do_clean_list( $File::Find::dir ); }
+
+  return if( ! -d $_ );
+
+  return if( $File::Find::name =~ m/build-system/ );
+  return if( $File::Find::name =~ m/dist/ );
+  return if( $File::Find::name =~ m/sources/ );
+
+  foreach my $d ( @targets )
+  {
+    if( $d eq $_ ) { do_clean_list( $File::Find::dir ); }
+  }
+}
+
+
+foreach ( @ARGV )
+{
+  push @targets, $_;
+}
+$top_dir = pop @targets;
+
+if( ! -d $top_dir )
+{
+  die "\nTop: $top_dir: is not a directory\n\n";
+}
+if( ! $top_dir =~ m/^\// )
+{
+  die "\nTop: $top_dir: is not absolute path\n\n";
+}
+
+find( \&process_clean, "$top_dir" );
+
+# get unique names:
+%seen = ();
+@dist_clean_dirs = grep { ! $seen{ $_ }++ } @dist_clean_dirs_all;
+# delete subdirs which already contains TARGET name:
+foreach my $target ( @targets )
+{
+  my @match = ();
+  @match = grep { /$target/ } keys %seen;
+  foreach my $subdir ( @match ) { delete( $seen{"$subdir"} ); }
+}
+@dist_clean_dirs = reverse( keys %seen );
+
+# get unique names:
+%seen = ();
+@clean_dirs = grep { ! $seen{ $_ }++ } @clean_dirs_all;
+foreach my $target ( @targets )
+{
+  my @match = ();
+  @match = grep { /$target/ } keys %seen;
+  foreach my $subdir ( @match ) { delete( $seen{"$subdir"} ); }
+}
+@clean_dirs = reverse( keys %seen );
+
+push @clean_dirs, "$top_dir/build-system";
+
+$dist_clean_count = @dist_clean_dirs;
+$clean_count = @clean_dirs;
+
+if( $dist_clean_count != 0 || $clean_count != 0 )
+{
+  if( !$header_printed )
+  {
+    print "\n======= Cleaning build tree =======\n";
+    $header_printed = 1;
+  }
+
+  do_clean();
+
+  print "\n";
+}
+else
+{
+  print "Cleaning...   (nothing to be done).\n";
+}
+

Property changes on: tree_clean
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: .
===================================================================
--- .	(nonexistent)
+++ .	(revision 5)

Property changes on: .
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,16 ##
+
+# Target bin dirs
+etc
+gnattools
+sbin
+
+# Build system config files
+targets-config.mk
+
+# Target build dirs
+.host
+
+# Hidden files (each file)
+.makefile
+.src_requires
+.src_requires_depend