diff --git a/.cvsignore b/.cvsignore index 5f4ab297..0c030d64 100644 --- a/.cvsignore +++ b/.cvsignore @@ -7,6 +7,7 @@ objects.* lib.* bin.* macros +macros.x64 help .makelib _grstate @@ -21,4 +22,4 @@ Makefile *.obj *.cm *.bak -.#* \ No newline at end of file +.#* diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a3336ac4..325a98dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,66 +2,104 @@ name: build on: [push] jobs: build: - runs-on: ${{ matrix.os }} + name: ${{ matrix.config.name }} + runs-on: ${{ matrix.config.os }} strategy: fail-fast: false matrix: - os: [windows-latest, ubuntu-latest] + config: + - { + name: "Windows Latest MSVC", + os: windows-latest, + toolchain: vc2022, + toolversion: vs170 + } + - { + name: "Windows Latest MinGW", + os: windows-latest, + toolchain: mingw64, + toolversion: mingw64 + } + - { + name: "Windows Latest OWC", + os: windows-latest, + toolchain: owc20, + toolversion: owc20 + } + - { + name: "Ubuntu Latest GCC", + os: ubuntu-latest, + toolchain: gcc, + toolversion: gcc + } + steps: - - uses: actions/checkout@v2 - - uses: ilammy/msvc-dev-cmd@v1 - if: runner.os == 'Windows' + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Checkout submodules + run: | + git submodule update --init --recursive + + - name: MSVC setup + uses: ilammy/msvc-dev-cmd@v1 + if: startsWith(matrix.config.name, 'Windows Latest MSVC') with: arch: x86 - - uses: msys2/setup-msys2@v2 - if: runner.os == 'Windows' + - name: MinGW64 setup + if: startsWith(matrix.config.name, 'Windows Latest MinGW') + shell: cmd + run: | + c:\msys64\usr\bin\pacman --noconfirm -S base-devel + c:\msys64\usr\bin\pacman --noconfirm -S mingw-w64-x86_64-gcc + c:\msys64\usr\bin\pacman --noconfirm -S mingw-w64-i686-gcc + + - name: OpenWatcom setup + uses: open-watcom/setup-watcom@v0 + if: startsWith(matrix.config.name, 'Windows Latest OWC') with: - release: false - update: true - install: >- - bison + version: "2.0" + location: "C:\\Watcom" - - name: Windows, generating Makefiles - if: runner.os == 'Windows' + - name: Windows, generate + if: startsWith(matrix.config.name, 'Windows Latest') shell: cmd run: | + @if "${{ matrix.config.toolchain }}"=="mingw32" set PATH=c:\msys64\mingw32\bin;%PATH% + @if "${{ matrix.config.toolchain }}"=="mingw64" set PATH=c:\msys64\mingw64\bin;%PATH% + @if "${{ matrix.config.toolchain }}"=="owc20" call .\support\owc20setenv.bat C:\Watcom + @if NOT "${{ matrix.config.toolchain }}"=="mingw64" c:\msys64\usr\bin\pacman --noconfirm -S bison @set PERL=c:/Strawberry/perl/bin/perl - c:/Strawberry/perl/bin/perl makelib.pl --perlpath=c:/Strawberry/perl/bin --busybox=./win32/busybox --wget=./win32/wget --bison=c:/msys64/usr/bin/bison --flex=./bin/flex --verbose vc2022 - @rem dir c:\tools - @rem dir c:\msys64 - @rem dir c:\msys64\usr\bin + c:/Strawberry/perl/bin/perl makelib.pl --perlpath=c:/Strawberry/perl/bin --busybox=./win32/busybox --wget=./win32/wget --bison=c:/msys64/usr/bin/bison --flex=./bin/flex --verbose "${{ matrix.config.toolchain }}" - - name: Windows, compiling - if: runner.os == 'Windows' + - name: Windows, compile + if: startsWith(matrix.config.name, 'Windows Latest') shell: cmd run: | + @if "${{ matrix.config.toolchain }}"=="mingw32" set PATH=c:\msys64\mingw32\bin;%PATH% + @if "${{ matrix.config.toolchain }}"=="mingw64" set PATH=c:\msys64\mingw64\bin;%PATH% + @if "${{ matrix.config.toolchain }}"=="owc20" call .\support\owc20setenv.bat C:\Watcom @set PERL=c:/Strawberry/perl/bin/perl .\win32\gmake-42 release contrib .\win32\gmake-42 release - - name: Windows, package - if: runner.os == 'Windows' - uses: actions/upload-artifact@v2 - with: - name: package-win32 - path: ./bin.vs170/debug/* - - - name: Linux, generating Makefiles - if: runner.os == 'Linux' + - name: Ubuntu, generate + if: startsWith(matrix.config.name, 'Ubuntu Latest') shell: bash run: | ./support/config_withncurses - - name: Linux, compiling - if: runner.os == 'Linux' + + - name: Ubuntu, compile + if: startsWith(matrix.config.name, 'Ubuntu Latest') shell: bash run: | make release - - name: Linux, package - if: runner.os == 'Linux' + + - name: Package uses: actions/upload-artifact@v2 with: - name: package-linux - path: ./bin.gcc/debug/* + name: package-${{ matrix.config.toolchain }} + path: ./bin.${{ matrix.config.toolversion }}/release/* diff --git a/.gitignore b/.gitignore index d4e2ff67..c21cde2f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ bin.*/ lib.*/ objects*/ macros/ +macros.x64 help/ Makefile GIT_Notes.txt diff --git a/Changes b/Changes index 6e0accfd..951f3c8d 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,22 @@ -*- encoding: utf-8; -*- +Sat May 28 16:52:13 2022 adamy + + * hunspell-1.7.0 + +Fri May 27 20:46:49 2022 adamy + + * libarchive-3.6.1 + + * mingw - alpha + + o mingw toolchain, makelib and libtool. + o gcc build and warnings. + +Thu Mar 24 13:36:07 2022 adamy + + * mandoc-1.14.6 + Tue Mar 22 18:46:50 2022 adamy * BUILD 21, version: 3.2.2 diff --git a/Makefile.in b/Makefile.in index 244aba42..b8ab6dc5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; -*- -# $Id: Makefile.in,v 1.52 2022/03/22 10:50:24 cvsuser Exp $ +# $Id: Makefile.in,v 1.59 2022/06/11 05:01:42 cvsuser Exp $ # GRIEF - top level makefile. # # Copyright (c) 1998 - 2022, Adam Young. @@ -112,7 +112,7 @@ XCLEAN= $(D_BIN)/*.map # Configuration -ifneq "" "$(filter win32,@build_os@)" +ifeq ("win32","@build_os@") BUSYBOX= @BUSYBOX@ ifeq ($(BUSYBOX),busybox) BUSYBOX= $(shell which busybox 2>/dev/null) @@ -132,7 +132,8 @@ ifneq ("$(word 1,$(MAKECMDGOALS))","release") |\n\ | make [release or debug] target \n\ |\n\ - | Build one or more of the following targets recursively within each sub-directory. \n\ + | Build one or more of the following targets recursively within each sub-directory\n\ + | for the toolchain @TOOLCHAIN@. \n\ |\n\ | Targets: \n\ |\n\ @@ -192,11 +193,13 @@ PACKAGEINFO= include/edpackageinfo.h CC= @CC@ CXX= @CXX@ AR= @AR@ +RANLIB= @RANLIB@ RM= @RM@ RMDIR= @RMDIR@ CP= @CP@ RC= @RC@ PERL= @PERL@ +LIBTOOL= @LIBTOOL@ TAR= @TAR@ LEX= @LEX@ YACC= @YACC@ @@ -206,7 +209,7 @@ INSTALL= @INSTALL@ INSTALL_PROGRAM=@INSTALL_PROGRAM@ INSTALL_DATA= @INSTALL_DATA@ -ifneq "" "$(filter mingw32 win32,@build_os@)" +ifeq ("win32","@build_os@") INNO= @INNO@ ifeq ($(INNO),) # Inno5: allowing legacy XP installations INNO= "C:/Program Files (x86)/Inno Setup 5/Compil32" @@ -256,9 +259,18 @@ CLBRNAME= clbr19 MT7RNAME= mt7r19 PLBRNAME= plbr19 endif + + # As path format is dependent on which variant, + # firstly resolve using WATCOM envvar, otherwise fallback to which. +LIBCLBRPATH= $(subst \,/,$(wildcard $(WATCOM)/binnt/$(CLBRNAME).dll)) +ifeq ("","$(LIBCLBRPATH)") LIBCLBRPATH= $(shell which $(CLBRNAME).dll) LIBMT7RPATH= $(shell which $(MT7RNAME).dll) LIBPLBRPATH= $(shell which $(PLBRNAME).dll) +else +LIBMT7RPATH= $(subst \,/,$(wildcard $(WATCOM)/binnt/$(MT7RNAME).dll)) +LIBPLBRPATH= $(subst \,/,$(wildcard $(WATCOM)/binnt/$(PLBRNAME).dll)) +endif endif IMPORT= @@ -268,6 +280,15 @@ IMPORT+=\ $(D_BIN)/$(MT7RNAME).dll \ $(D_BIN)/$(PLBRNAME).dll endif + +GRUPDATER= no +ifeq (vs,$(findstring vs,"@TOOLCHAIN@")) +GRUPDATER= yes +else ifeq ("@TOOLCHAIN@","owc20") +GRUPDATER= yes +else ifeq ("@TOOLCHAIN@","owc19") +GRUPDATER= yes +endif BINS=\ $(D_BIN)/gr$(E) \ @@ -275,12 +296,15 @@ BINS=\ $(D_BIN)/grcpp$(E) \ $(D_BIN)/grmandoc$(E) \ $(D_BIN)/grunch$(E) -ifneq "" "$(filter mingw32 win32,@build_os@)" +ifneq "" "$(filter win32,@build_os@)" BINS+= $(D_BIN)/grwc$(E) endif - +ifeq ("yes","$(GRUPDATER)") +BINS+= $(D_BIN)/grupdater$(E) +endif + LIBS= -ifneq "" "$(filter mingw32 win32,@build_os@)" +ifneq "" "$(filter win32,@build_os@)" LIBS+= $(LW)win32 endif LIBS+=\ @@ -321,7 +345,8 @@ help: |\n\ | make [release or debug] target \n\ |\n\ - | Build one or more of the following targets recursively within each sub-directory. \n\ + | Build one or more of the following targets recursively within each sub-directory\n\ + | for the toolchain @TOOLCHAIN@. \n\ |\n\ | Targets: \n\ |\n\ @@ -330,7 +355,7 @@ help: | clean - delete everything which can be remade. \n\ | help - command line usage. \n\ " - + .PHONY: release release: $(MAKE) BUILD_TYPE=release $(filter-out release, $(MAKECMDGOALS)) @@ -340,7 +365,7 @@ debug: $(MAKE) BUILD_TYPE=debug $(filter-out debug, $(MAKECMDGOALS)) .PHONY: -ifneq "" "$(filter mingw32 win32,@build_os@)" +ifneq "" "$(filter win32,@build_os@)" contrib: directories buildinfo $(LW)win32 $(LW)misc $(MAKE) -C contrib else @@ -382,6 +407,7 @@ package: import packageinfo $(INNO) ./win32/gr-inno-setup.iss -$(RM) $(PACKAGEINFO) + ######################################################################################### # Applications @@ -451,9 +477,13 @@ $(D_BIN)/grmandoc$(E): $(D_BIN)/.created libs $(D_BIN)/grunch$(E): $(D_BIN)/.created libs $(MAKE) -C $(D_GRUNCH) - + $(D_BIN)/grwc$(E): $(D_BIN)/.created libs $(MAKE) -C util + +$(D_BIN)/grupdater$(E): $(D_BIN)/.created libs + $(MAKE) -C win32/AutoUpdater + ######################################################################################### # Rules @@ -496,7 +526,7 @@ install: build clean: @echo $(BUILD_TYPE) clean $(MAKE) -C libmisc clean -ifneq "" "$(filter mingw32 win32,@build_os@)" +ifneq "" "$(filter win32,@build_os@)" $(MAKE) -C libw32 endif $(MAKE) -C libmalloc clean diff --git a/README.md b/README.md index 3a95f2fa..f41fbb33 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ -[![Website](https://img.shields.io/badge/View-Website-blue)](https://sourceforge.net/projects/grief/) [![GitHub release](https://img.shields.io/github/release/Naereen/StrapDown.js.svg)](https://GitHub.com/adamyg/grief/releases/) +[![Website](https://img.shields.io/badge/View-Website-blue)](https://sourceforge.net/projects/grief/) +[![GitHub release](https://img.shields.io/github/release/Naereen/StrapDown.js.svg)](https://GitHub.com/adamyg/grief/releases/) +[![Workflow](https://github.com/adamyg/grief/actions/workflows/build.yml/badge.svg)](https://github.com/adamyg/grief/actions) -[![Build status](https://ci.appveyor.com/api/projects/status/3tx1vwwclydfp1t6?svg=true&passingText=Ubuntu%20Passing&failingText=Ubuntu%20Failing&pendingText=Ubuntu%20Pending)](https://ci.appveyor.com/project/adamyg/grief-ubuntu) [![Build status](https://ci.appveyor.com/api/projects/status/3tx1vwwclydfp1t6?svg=true&passingText=MacOS%20Passing&failingText=MacOS%20Failing&pendingText=MacOS%20Pending)](https://ci.appveyor.com/project/adamyg/grief-macos) [![Build status](https://ci.appveyor.com/api/projects/status/3tx1vwwclydfp1t6?svg=true&passingText=Win32%20Passing&failingText=Win32%20Failing&pendingText=Win32%20Pending)](https://ci.appveyor.com/project/adamyg/grief-win32) [![Build status](https://ci.appveyor.com/api/projects/status/3tx1vwwclydfp1t6?svg=true&passingText=Cygwin32%20Passing&failingText=Cygwin32%20Failing&pendingText=Cygwin32%20Pending)](https://ci.appveyor.com/project/adamyg/grief-cygwin32) +[![Build status](https://ci.appveyor.com/api/projects/status/3tx1vwwclydfp1t6?svg=true&passingText=Ubuntu%20Passing&failingText=Ubuntu%20Failing&pendingText=Ubuntu%20Pending)](https://ci.appveyor.com/project/adamyg/grief-ubuntu) +[![Build status](https://ci.appveyor.com/api/projects/status/k63ggto1v8t1c28d?svg=true&passingText=MacOS%20Passing&failingText=MacOS%20Failing&pendingText=MacOS%20Pending)](https://ci.appveyor.com/project/adamyg/grief-macos) +[![Build status](https://ci.appveyor.com/api/projects/status/77myicx6ab5d6g1a?svg=true&passingText=Win32%20Passing&failingText=Win32%20Failing&pendingText=Win32%20Pending)](https://ci.appveyor.com/project/adamyg/grief-win32) +[![Build status](https://ci.appveyor.com/api/projects/status/3h8sweuo36r8q28t?svg=true&passingText=Cygwin32%20Passing&failingText=Cygwin32%20Failing&pendingText=Cygwin32%20Pending)](https://ci.appveyor.com/project/adamyg/grief-cygwin32) +[![Build status](https://ci.appveyor.com/api/projects/status/8jk4qx55d4bql3l1?svg=true&passingText=MinGW32%20Passing&failingText=MinGW32%20Failing&pendingText=MinGW32%20Pending)](https://ci.appveyor.com/project/adamyg/grief-mingw) GRIEF - BRIEF clone ======================================================= @@ -24,10 +30,13 @@ Facility, was a popular programmer's text editor in the 1980s and early 1990s. * Supported operating systems * Linux - * Microsoft Windows (native/cygwin/mingw) - * AIX - * HP-UX + * Microsoft Windows (native/cygwin) * Mac OS/X + + * Other operating systems; working may be required + + * HP-UX + * AIX * Solaris (SPARC and x86) Examples @@ -96,6 +105,6 @@ can be found at the following. * -last update: May/2020 +last update: May/2022 -end- diff --git a/contrib/Makefile.in b/contrib/Makefile.in index fd7f59fe..db5b6efa 100644 --- a/contrib/Makefile.in +++ b/contrib/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; -*- -# $Id: Makefile.in,v 1.14 2020/06/18 20:35:15 cvsuser Exp $ +# $Id: Makefile.in,v 1.17 2022/06/01 14:21:18 cvsuser Exp $ # External packages. # # -# Copyright (c) 1998 - 2020, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -79,7 +79,7 @@ define contrib-clean $(MAKE) -C libarchive clean $(MAKE) -C hunspell clean endef -ifeq ("win32","@build_os@") +ifneq "" "$(filter win32,@build_os@)" define contrib-cleanx $(MAKE) -C libcitrus clean $(MAKE) -C libintl clean diff --git a/contrib/README.txt b/contrib/README.txt index 1c5b769e..38c1861a 100644 --- a/contrib/README.txt +++ b/contrib/README.txt @@ -59,52 +59,50 @@ flex/ - Version 2.5.10 released 2002-7-24 + Version 2.5.10 released 2002-7-24 - Flex carries the copyright used for BSD software, slightly modified - because it originated at the Lawrence Berkeley (not Livermore!) Laboratory, - which operates under a contract with the Department of Energy: + Flex carries the copyright used for BSD software, slightly modified + because it originated at the Lawrence Berkeley (not Livermore!) Laboratory, + which operates under a contract with the Department of Energy: - Copyright (c) 2001 by W. L. Estes + Copyright (c) 2001 by W. L. Estes - Copyright (c) 1990, 1997 The Regents of the University of California. - All rights reserved. - - This code is derived from software contributed to Berkeley by - Vern Paxson. - - The United States Government has rights in this work pursuant - to contract no. DE-AC03-76SF00098 between the United States - Department of Energy and the University of California. + Copyright (c) 1990, 1997 The Regents of the University of California. + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: + This code is derived from software contributed to Berkeley by + Vern Paxson. - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + The United States Government has rights in this work pursuant + to contract no. DE-AC03-76SF00098 between the United States + Department of Energy and the University of California. - Neither the name of the University nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: - THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE. + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - This basically says "do whatever you please with this software except - remove this notice or take advantage of the University's (or the flex - authors') name". + Neither the name of the University nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. - Note that the "flex.skl" scanner skeleton carries no copyright notice. - You are free to do whatever you please with scanners generated using flex; - for them, you are not even bound by the above copyright. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE. + This basically says "do whatever you please with this software except + remove this notice or take advantage of the University's (or the flex + authors') name". + Note that the "flex.skl" scanner skeleton carries no copyright notice. + You are free to do whatever you please with scanners generated using flex; + for them, you are not even bound by the above copyright. libregex/ @@ -186,7 +184,7 @@ libbzip2/ - o bzip2 1.0.6 + o bzip2 1.0.8 The bzip2 file compression program was developed by Julian Seward and launched on the 18th of July in 1996. It has remained an open source @@ -206,7 +204,7 @@ Copyright notice: This program, "bzip2", the associated library "libbzip2", and all - documentation, are copyright (C) 1996-2010 Julian R Seward. All + documentation, are copyright (C) 1996-2019 Julian R Seward. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -214,19 +212,19 @@ are met: 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. + not be misrepresented as being the original software. 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. + products derived from this software without specific prior written + permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -240,8 +238,8 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - Julian Seward, jseward@bzip.org - bzip2/libbzip2 version 1.0.6 of 6 September 2010 + Julian Seward, jseward@acm.org + bzip2/libbzip2 version 1.0.8 of 13 July 2019 liblzma/ @@ -407,7 +405,7 @@ hunspell/ - o hunspell 1.3.2 + o hunspell 1.3.3 and 1.7.0 Author of Hunspell: László Németh (nemethl (at) gyorsposta.hu) @@ -433,7 +431,7 @@ libarchive/ - o libarchive 3.0.4 + o libarchive 3.6.1 Copyright (c) 2003-2009 All rights reserved. diff --git a/contrib/contrib_config.h b/contrib/contrib_config.h index 9c5fda2f..e754daec 100644 --- a/contrib/contrib_config.h +++ b/contrib/contrib_config.h @@ -1,10 +1,10 @@ #ifndef CONTRIB_CONFIG_H_INCLUDED #define CONTRIB_CONFIG_H_INCLUDED -/* $Id: contrib_config.h,v 1.14 2020/06/18 20:35:15 cvsuser Exp $ +/* $Id: contrib_config.h,v 1.16 2022/05/27 02:33:05 cvsuser Exp $ * contrib ... * * - * Copyright (c) 1998 - 2018, Adam Young. + * Copyright (c) 1998 - 2022, Adam Young. * All rights reserved. * * This file is part of the GRIEF Editor. @@ -38,7 +38,7 @@ #define APPLICATIONDIR "Grief" /* FIXME, edconfig.h */ -#if defined(__MINGW32__) || defined(unix) +#if defined(unix) #include "../../include/config.h" #else #include "../../libw32/config.h" @@ -106,16 +106,11 @@ typedef unsigned long long uintmax_t; #define HAVE_DECL_INT64_MAX 1 #define HAVE_DECL_INT64_MIN 1 #endif -#if defined(_MSC_VER) -typedef int ssize_t; -#endif #else /*!HAVE_STDINT_H*/ #define INTMAX_MIN LLONG_MAX #define INTMAX_MAX LLONG_MIN #define UINTMAX_MAX ULLONG_MAX -#if defined(_MSC_VER) -typedef int ssize_t; typedef signed char int8_t; typedef unsigned char uint8_t; typedef signed short int16_t; @@ -127,6 +122,11 @@ typedef unsigned long long uint64_t; #endif #endif /*HAVE_STDINT_H*/ +#if defined(_MSC_VER) +#if !defined(ssize_t) && !defined(SSIZE_T) +typedef int ssize_t; +#endif + #if !defined(HAVE_U_INT32_T) #if !defined(__WATCOMC__) typedef unsigned int u_int32_t; diff --git a/contrib/flex/Makefile.in b/contrib/flex/Makefile.in index 73bbf0f5..3b322e31 100644 --- a/contrib/flex/Makefile.in +++ b/contrib/flex/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.3 2020/06/18 20:35:15 cvsuser Exp $ +# $Id: Makefile.in,v 1.4 2022/05/31 17:16:01 cvsuser Exp $ # flex 2.5.10 makefile. # # -# Copyright (c) 2020, Adam Young. +# Copyright (c) 2020 - 2022, Adam Young. # All rights reserved. # # The applications are free software: you can redistribute it @@ -52,6 +52,7 @@ CP= @CP@ HAVE_BISON= 1 YACC= @YACC@ LEX= @LEX@ +LIBTOOL= @LIBTOOL@ # Configuration @@ -143,7 +144,7 @@ debug: $(D_BIN)/flex$(E): MAPFILE=$(basename $@).map $(D_BIN)/flex$(E): $(FLEX_OBJS) - $(CC) $(LDFLAGS) -o $@ $(FLEX_OBJS) $(LDLIBS) @LDMAPFILE@ + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(FLEX_OBJS) $(LDLIBS) @LDMAPFILE@ parse.h: parse.c diff --git a/contrib/hunspell/.cvsignore b/contrib/hunspell/.cvsignore index ae9b9137..0e1ef5e2 100644 --- a/contrib/hunspell/.cvsignore +++ b/contrib/hunspell/.cvsignore @@ -1,3 +1,7 @@ +hunspell-1.3.3 +hunspell-1.7.0 Makefile *.err .unpacked.* +version.h + diff --git a/contrib/hunspell/.gitignore b/contrib/hunspell/.gitignore index f5361c41..0ef87f27 100644 --- a/contrib/hunspell/.gitignore +++ b/contrib/hunspell/.gitignore @@ -1 +1,4 @@ -hunspell-1.3.*/ \ No newline at end of file +hunspell-1.3.*/ +hunspell-1.7.*/ +version.h + diff --git a/contrib/hunspell/Changes b/contrib/hunspell/Changes new file mode 100644 index 00000000..868f0f1a --- /dev/null +++ b/contrib/hunspell/Changes @@ -0,0 +1,40 @@ +Sat May 28 16:54:55 2022 adamy + + * hunspell-1.7.0 + + - MINGW/MSVC + - version.pl + + * hunspell-1.3.3 + + - OWC + + src/hunvisapi.h: + + - #elif defined(_MSC_VER) + + #elif defined(_MSC_VER) || defined(__WATCOMC__) + + src/relocatable.h: + + - #elif defined _MSC_VER && BUILDING_DLL + + #elif (defined(_MSC_VER) || defined(__WATCOMC__)) && BUILDING_DLL + + src/csutil.hxx: + + + #include + #include + + src/replist.hxx/.cxx: + + - int near(const char * word); + + int isnear(const char * word); + + src/parsers/xmlparser.cxx + src/parsers/odfparser.cxx + + - static const char * __PATTERN2__[][2] = { + - }; + - #define __PATTERN_LEN2__ (sizeof(__PATTERN2__) / (sizeof(char *) * 2)) + + + #define __PATTERN2__ NULL + + #define __PATTERN_LEN2__ 0 diff --git a/contrib/hunspell/Makefile.in b/contrib/hunspell/Makefile.in index 9152bf72..f714f7f7 100644 --- a/contrib/hunspell/Makefile.in +++ b/contrib/hunspell/Makefile.in @@ -1,6 +1,6 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.18 2020/06/18 20:35:15 cvsuser Exp $ -# libhunspell, hunspell, hzip and hunzip makefile +# $Id: Makefile.in,v 1.25 2022/06/15 13:25:04 cvsuser Exp $ +# libhunspell, hunspell, hzip and hunzip makefile. # # # @@ -29,6 +29,7 @@ RANLIB= @RANLIB@ RM= @RM@ PERL= @PERL@ LIBTOOL= @LIBTOOL@ +RC= @RC@ # Configuration @@ -55,6 +56,11 @@ CWARN= @CWARN@ CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ CXXFLAGS= @CXXFLAGS@ +CXXWARN= @CXXWARN@ +ifeq ("gcc","@CC@") +CXXWARN= -Wno-conversion-null -Wno-deprecated-declarations +endif + CXXDEBUG= @CXXDEBUG@ ifeq ("$(CXXDEBUG)","") CXXDEBUG= $(CDEBUG) @@ -67,7 +73,7 @@ endif LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ -CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ +CINCLUDE= -I. -I./win32 -I$(D_INC) CEXTRA= @DEFS@ ifeq ("yes","@ISWIN32@") CEXTRA+= -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE @@ -75,14 +81,14 @@ endif ifeq ("$(BUILD_TYPE)","release") CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXRELEASE) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXRELEASE) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDRELEASE) @LDFLAGS@ else CFLAGS+= $(CDEBUG) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXDEBUG) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXDEBUG) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif -LDLIBS= -L$(D_LIB) @LIBS@ @EXTRALIBS@ +LDLIBS= -L$(D_LIB) $(filter-out libw32.%, @LIBS@ @EXTRALIBS@) YFLAGS= -d ARFLAGS= rcv @@ -96,14 +102,55 @@ RMDFLAGS= -rf HUNSPELLLIB= $(D_LIB)/$(LP)hunspell_static$(A) HUNSPELLDLL= $(D_LIB)/$(LP)hunspell.la +HUNSPELLVER=1.7.0 +ifeq ("@TOOLCHAIN@","owc20") +HUNSPELLVER=1.3.3 +else ifeq ("@TOOLCHAIN@","owc19") +HUNSPELLVER=1.3.3 +else ifeq ("@TOOLCHAIN@","vs170") +else ifeq ("@TOOLCHAIN@","vs160") +else ifeq ("@TOOLCHAIN@","vs150") +else ifeq ("@TOOLCHAIN@","vs140") +else ifeq ("@TOOLCHAIN@","vs120") +else ifeq ("@TOOLCHAIN@","vs110") +else ifeq ("@TOOLCHAIN@","vs100") +HUNSPELLVER=1.3.3 +else ifeq ("@TOOLCHAIN@","vs90") +HUNSPELLVER=1.3.3 +else ifeq ("@TOOLCHAIN@","mingw") +else ifeq ("@TOOLCHAIN@","mingw32") +else ifeq ("@TOOLCHAIN@","mingw64") +endif + +ifeq ("1.7.0","$(HUNSPELLVER)") +VERSION= 1.7.0 +VERSIONSPEC= $(subst .,:,$(VERSION)) +PACKED= hunspell-$(VERSION).tgz +else VERSION= 1.3.3 VERSIONSPEC= $(subst .,:,$(VERSION)) PACKED= hunspell-$(VERSION).patched.tgz +endif HUNSPELLSRC= ./hunspell-$(VERSION)/src/hunspell PARSERSSRC= ./hunspell-$(VERSION)/src/parsers TOOLSSRC= ./hunspell-$(VERSION)/src/tools +ifeq ("1.7.0","$(VERSION)") +LIBOBJS=\ + $(D_OBJ)/lib_affentry$(O) \ + $(D_OBJ)/lib_affixmgr$(O) \ + $(D_OBJ)/lib_csutil$(O) \ + $(D_OBJ)/lib_filemgr$(O) \ + $(D_OBJ)/lib_hashmgr$(O) \ + $(D_OBJ)/lib_hunspell$(O) \ + $(D_OBJ)/lib_hunzip$(O) \ + $(D_OBJ)/lib_phonet$(O) \ + $(D_OBJ)/lib_replist$(O) \ + $(D_OBJ)/lib_suggestmgr$(O) \ + \ + $(D_OBJ)/hunspell_mktemp$(O) +else LIBOBJS=\ $(D_OBJ)/lib_affentry$(O) \ $(D_OBJ)/lib_affixmgr$(O) \ @@ -116,13 +163,21 @@ LIBOBJS=\ $(D_OBJ)/lib_phonet$(O) \ $(D_OBJ)/lib_replist$(O) \ $(D_OBJ)/lib_suggestmgr$(O) +endif DLLOBJS=\ $(D_OBJ)/hunspell_dllmain.lo \ $(D_OBJ)/hunspell_dllc.lo \ - $(D_OBJ)/hunspell_dlls.lo \ $(subst $(O),.lo,$(LIBOBJS)) +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) +DLLOBJS+= $(D_OBJ)/libhunspell_res.o +else +DLLOBJS+= $(D_OBJ)/libhunspell.res +endif +endif + HUNSPELLOBJS=\ $(D_OBJ)/hunspell$(O) \ $(D_OBJ)/firstparser$(O) \ @@ -131,23 +186,22 @@ HUNSPELLOBJS=\ $(D_OBJ)/manparser$(O) \ $(D_OBJ)/textparser$(O) -ifeq ("1.3.3","$(VERSION)") +#1.3.3 HUNSPELLOBJS+=\ $(D_OBJ)/xmlparser$(O) \ $(D_OBJ)/odfparser$(O) -endif OBJS= $(LIBOBJS) $(DLLOBJS) LIBS= $(HUNSPELLLIB) $(HUNSPELLDLL) TSKS= $(D_BIN)/hunspell$(E) $(D_BIN)/hzip$(E) $(D_BIN)/hunzip$(E) - +INSTALLED= ######################################################################################### # Rules .PHONY: build release debug all: source unpacked -unpacked: object $(LIBS) $(TSKS) $(HUNSPELLDB) installinc +unpacked: version.h object $(LIBS) $(TSKS) $(HUNSPELLDB) installinc release: $(MAKE) BUILD_TYPE=release $(filter-out release, $(MAKECMDGOALS)) @@ -161,6 +215,7 @@ $(HUNSPELLLIB): $(LIBOBJS) $(RANLIB) $@ #note build as static, only exported are via hunspell_dlls./c modules +INSTALLED+= $(D_BIN)/libhunspell.$(VERSION).dll $(HUNSPELLDLL): CEXTRA += -I$(HUNSPELLSRC) -DHUNSPELL_STATIC $(HUNSPELLDLL): $(DLLOBJS) $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ -version-number $(VERSIONSPEC) \ @@ -168,15 +223,15 @@ $(HUNSPELLDLL): $(DLLOBJS) $(D_BIN)/hunspell$(E): CEXTRA += -I$(TOOLSSRC) -I$(PARSERSSRC) -I$(HUNSPELLSRC) -DHUNSPELL_STATIC $(D_BIN)/hunspell$(E): $(HUNSPELLOBJS) - $(CXX) $(LDFLAGS) -o $@ $^ $(D_LIB)/libhunspell_static$(A) $(LDLIBS) + $(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $^ $(D_LIB)/libhunspell_static$(A) $(LDLIBS) $(D_BIN)/hzip$(E): CEXTRA += -I$(TOOLSSRC) -I$(HUNSPELLSRC) -DHUNSPELL_STATIC $(D_BIN)/hzip$(E): $(D_OBJ)/hzip$(O) - $(CXX) $(LDFLAGS) -o $@ $^ $(D_LIB)/libhunspell_static$(A) $(LDLIBS) + $(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $^ $(D_LIB)/libhunspell_static$(A) $(LDLIBS) $(D_BIN)/hunzip$(E): CEXTRA += -I$(TOOLSSRC) -I$(HUNSPELLSRC) -DHUNSPELL_STATIC $(D_BIN)/hunzip$(E): $(D_OBJ)/hunzip$(O) - $(CXX) $(LDFLAGS) -o $@ $^ $(D_LIB)/libhunspell_static$(A) $(LDLIBS) + $(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $^ $(D_LIB)/libhunspell_static$(A) $(LDLIBS) source: .unpacked.$(VERSION) $(MAKE) unpacked @@ -190,20 +245,24 @@ source: .unpacked.$(VERSION) object: $(D_OBJ)/.created .PHONY: installinc +INSTALLED+= ../include/hunspell.h ../include/hunspell.hxx ../include/hunvisapi.h installinc: ../include/.created @echo publishing headers ... -cp $(HUNSPELLSRC)/hunspell.h ../include -cp $(HUNSPELLSRC)/hunspell.hxx ../include -cp $(HUNSPELLSRC)/hunvisapi.h ../include +version.h: Makefile + $(PERL) ./version.pl --version "$(VERSION)" + %/.created: -@mkdir $(@D) @echo "do not delete, managed directory" > $@ clean: @echo $(BUILD_TYPE) clean - -@$(RM) $(RMFLAGS) $(TSKS) $(LIBS) $(CLEAN) $(XCLEAN) >/dev/null 2>&1 -@$(LIBTOOL) --mode=clean $(RM) $(DLLOBJS) >/dev/null 2>&1 + -@$(RM) $(RMFLAGS) $(TSKS) $(INSTALLED) $(LIBS) $(CLEAN) $(XCLEAN) >/dev/null 2>&1 -@$(RM) $(LIBOBJS) >/dev/null 2>&1 # XXX: open-watcom debug breaks due to the module size, must filter out -hw @@ -217,6 +276,9 @@ $(D_OBJ)/lib_%.lo: $(HUNSPELLSRC)/%.cxx $(D_OBJ)/%.lo: %.cxx $(LIBTOOL) --mode=compile $(CXX) $(filter-out -hw,$(CXXFLAGS)) -o $@ -c $< +$(D_OBJ)/%.lo: %.c + $(LIBTOOL) --mode=compile $(CC) $(filter-out -hw,$(CFLAGS)) -o $@ -c $< + $(D_OBJ)/%$(O): $(TOOLSSRC)/%.cxx $(CXX) $(filter-out -hw,$(CXXFLAGS)) -o $@ -c $< @@ -226,4 +288,13 @@ $(D_OBJ)/%$(O): $(PARSERSSRC)/%.cxx $(D_OBJ)/%$(O): $(TOOLSSRC)/%.c $(CC) $(filter-out -hw,$(CFLAGS)) -o $@ -c $< +$(D_OBJ)/%$(O): %.c + $(CC) $(filter-out -hw,$(CFLAGS)) -o $@ -c $< + +$(D_OBJ)/%.res: %.rc + $(RC) -fo $@ $< + +$(D_OBJ)/%_res.o: %.rc + $(RC) -o $@ $< + #end diff --git a/contrib/hunspell/config.h b/contrib/hunspell/config.h index 2735888f..e6db933a 100644 --- a/contrib/hunspell/config.h +++ b/contrib/hunspell/config.h @@ -1,52 +1,26 @@ -#ifndef CONFIG_H_INCLUDED -#define CONFIG_H_INCLUDED +#ifndef HUNSPELL_CONFIG_H_INCLUDED +#define HUNSPELL_CONFIG_H_INCLUDED /* * libhunspell */ - -#define VERSION "1.3.3" - -#include "../contrib_config.h" - + #if defined(_MSC_VER) #if !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS #endif -#endif +#endif //_MSC_VER #if defined(__WATCOMC__) -/* - * patches required: - * src/hunvisapi.h: - * - * - #elif defined(_MSC_VER) - * + #elif defined(_MSC_VER) || defined(__WATCOMC__) - * - * src/relocatable.h: - * - * - #elif defined _MSC_VER && BUILDING_DLL - * + #elif (defined(_MSC_VER) || defined(__WATCOMC__)) && BUILDING_DLL - * - * src/csutil.hxx: - * - * + #include - * #include - * - * src/replist.hxx/.cxx: - * - * - int near(const char * word); - * + int isnear(const char * word); - * - * src/parsers/xmlparser.cxx - * src/parsers/odfparser.cxx - * - * - static const char * __PATTERN2__[][2] = { - * - }; - * - #define __PATTERN_LEN2__ (sizeof(__PATTERN2__) / (sizeof(char *) * 2)) - * - * + #define __PATTERN2__ NULL - * + #define __PATTERN_LEN2__ 0 - */ -#endif /*__WATCOMC__*/ +#pragma disable_message(391) // assignment found in boolean expression +#include + namespace std { + namespace ios_base { + typedef ios::openmode openmode; + }; + }; +#endif //__WATCOMC__ + +#include "version.h" +#include -#endif /*CONFIG_H_INCLUDED*/ +#endif /*HUNSPELL_CONFIG_H_INCLUDED*/ diff --git a/contrib/hunspell/hunspell-1.7.0.tgz b/contrib/hunspell/hunspell-1.7.0.tgz new file mode 100644 index 00000000..fb9b5ee4 Binary files /dev/null and b/contrib/hunspell/hunspell-1.7.0.tgz differ diff --git a/contrib/hunspell/hunspell_mktemp.c b/contrib/hunspell/hunspell_mktemp.c new file mode 100644 index 00000000..87808aa0 --- /dev/null +++ b/contrib/hunspell/hunspell_mktemp.c @@ -0,0 +1,507 @@ +/* -*- mode: c; indent-width: 4; -*- */ +/* + * hunspell mkstemp/mkdtemp implementation + */ + +#include +#include +#include +#include +#include +#include +#include + +#if defined(_MSC_VER) +#include +#endif +#include +#include + +#include + +#include "hunspell_mktemp.h" +#undef mkstemp +#undef mkdtemp + +static int tmpdir(const char *path, char *t_path, unsigned tmpsiz); +static int gettempfile(char *path, int *fildes); +static int gettempdir(char *path); + +#define MKSUCCESS 0 +#define MKERROR -1 + +#if defined(__MINGW32__) +static __thread char x_templ[MAX_PATH]; +#else +__declspec(thread) static char x_templ[MAX_PATH]; +#endif + + +FILE * +hunspell_fdopen(int fd, const char *mode) +{ + return _fdopen(fd, mode); +} + + +/* +// NAME +// mkstemp - make a unique filename +// +// SYNOPSIS +// #include +// +// int mkstemp(char *template); +// +// DESCRIPTION +// +// The mkstemp() function shall replace the contents of the string pointed to by +// template by a unique filename, and return a file descriptor for the file open for +// reading and writing. The function thus prevents any possible race condition between +// testing whether the file exists and opening it for use. +// +// Each successful call to mkstemp modifies template. In each subsequent call from the same +// process or thread with the same template argument, mkstemp checks for filenames that +// match names returned by mkstemp in previous calls. If no file exists for a given name, +// mkstemp returns that name. If files exist for all previously returned names, mkstemp +// creates a new name by replacing the alphabetic character it used in the previously +// returned name with the next available lowercase letter, in order, from 'a' through 'z'. +// +// RETURN VALUE +// +// Upon successful completion, mkstemp() shall return an open file descriptor. +// Otherwise, -1 shall be returned if no suitable file could be created. +// +// ERRORS +// No errors are defined. +*/ + +int +hunspell_mkstemp(char *templ) +{ + int fd = -1, ret; + + ret = tmpdir(templ, x_templ, sizeof(x_templ)); + if (ret) { + if (ret > 0) { + if (MKSUCCESS == gettempfile(x_templ, &fd)) { + return fd; + } + } + return -1; + } + return (MKSUCCESS == gettempfile(templ, &fd) ? fd : -1); +} + + +/* +// NAME +// mkdtemp - create a unique temporary directory. +// +// SYNOPSIS +// #include +// +// char *mkdtemp(char *template); +// +// DESCRIPTION +// The mkdtemp() function shall create a directory with a unique name derived from +// template. The application shall ensure that the string provided in template is a +// pathname ending with at least six trailing 'X' characters. The mkdtemp() function +// shall modify the contents of template by replacing six or more 'X' characters at +// the end of the pathname with the same number of characters from the portable +// filename character set. The characters shall be chosen such that the resulting +// pathname does not duplicate the name of an existing file at the time of the call +// to mkdtemp(). The mkdtemp() function shall use the resulting pathname to create +// the new directory as if by a call to: +// +// mkdir(pathname, S_IRWXU) +// +// The mkstemp() function shall create a regular file with a unique name derived from +// template and return a file descriptor for the file open for reading and writing. +// The application shall ensure that the string provided in template is a pathname +// ending with at least six trailing 'X' characters. The mkstemp() function shall +// modify the contents of template by replacing six or more 'X' characters at the +// end of the pathname with the same number of characters from the portable filename +// character set. The characters shall be chosen such that the resulting pathname +// does not duplicate the name of an existing file at the time of the call to mkstemp(). +// The mkstemp() function shall use the resulting pathname to create the file, and +// obtain a file descriptor for it, as if by a call to: +// +// open(pathname, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR) +// +// By behaving as if the O_EXCL flag for open() is set, the function prevents any possible +// race condition between testing whether the file exists and opening it for use. +// +// RETURN VALUE +// Upon successful completion, the mkdtemp() function shall return the value of template. +// Otherwise, it shall return a null pointer and shall set errno to indicate the error. +*/ + +char * +hunspell_mkdtemp(char *templ) +{ + int ret; + + ret = tmpdir(templ, x_templ, sizeof(x_templ)); + if (ret) { + if (ret > 0) { + if (MKSUCCESS == gettempdir(x_templ)) { + return x_templ; + } + } + return NULL; + } + return (MKSUCCESS == gettempdir(templ) ? templ : NULL); +} + + +static int +tmpdir(const char *templ, char *t_templ, unsigned tmpsiz) +{ + /* + * "/tmp/", reference system temporary path + */ + if (templ && 0 == memcmp(templ, "/tmp/", 5)) { + unsigned pathlen = strlen(templ + 5), + tmplen = (int)GetTempPathA(tmpsiz, t_templ); + // TMP, TEMP, USERPROFILE environment variables, default windows directory. + + if (pathlen && tmplen) { + if ((pathlen + tmplen) >= tmpsiz) { + errno = ENAMETOOLONG; + return -1; + + } else { + char *p; + + if (t_templ[tmplen - 1] != '\\') { + t_templ[tmplen - 1] = '\\', ++tmplen; + } + memcpy(t_templ + tmplen, templ + 5, pathlen + 1 /*nul*/); + for (p = t_templ; NULL != (p = strchr(p, '/'));) { + *p++ = '\\'; /* convert */ + } + return 1; + } + } + } + return 0; +} + + +static unsigned +generate_seed(void) +{ + static unsigned seed; + if (0 == seed) seed = (_getpid() * GetTickCount()); + seed = (1103515245 * seed + 12345); + return seed; +} + + +static int +gettempfile(char *path, int *fd) +{ + char *start, *trv, *end, c; + unsigned seed; + int rc; + + for (trv = path; *trv; ++trv); + if ((trv - path) >= MAX_PATH) { + errno = ENAMETOOLONG; + return MKERROR; + } + + end = trv; + if ((end - path) <= 6 || strcmp(end - 6, "XXXXXX")) { + /* too short or missing 'XXXXXX' */ + errno = EINVAL; + return MKERROR; + } + + seed = generate_seed(); + while (--trv >= path && *trv == 'X') { + *trv = (char)((seed % 10) + '0'); + seed /= 10; /* extra X's get set to 0's */ + } + + if ((trv + 1) == end) { /* missing template? */ + errno = EINVAL; + return MKERROR; + } + + /* + * check the target directory; if you have six X's and it + * doesn't exist this runs for a *very* long time. + */ + for (start = trv + 1;; --trv) { + if (trv <= path) { + break; + } + + if ((c = *trv) == '/' || c == '\\') { + struct _stat sb = {0}; + + if (trv[-1] == ':') { + break; + } + *trv = '\0'; + rc = _stat(path, &sb); /* exists? */ + *trv = c; + if (rc) { + return MKERROR; + } + if (!(sb.st_mode & S_IFDIR)) { + errno = ENOTDIR; + return MKERROR; + } + break; + } + } + + for (;;) { + errno = 0; + +#define O_MODE (O_CREAT|O_EXCL|O_RDWR|O_BINARY) + + if ((*fd = _open(path, O_MODE, 0600)) >= 0) { + return MKSUCCESS; + } + if (EEXIST != errno) { + return MKERROR; + } + + /* next is sequence */ + for (trv = start;;) { + if (trv == end) { /* EOS */ + return MKERROR; + } + + if ('z' == *trv) { /* 0..9a..z */ + *trv++ = 'a'; + } else { + if (isdigit(*trv)) { + *trv = 'a'; + } else { + ++*trv; + } + break; + } + } + } + /*NOTREACHED*/ +} + + +static int +gettempdir(char *path) +{ + char *start, *trv, *end, c; + unsigned seed; + int rc; + + for (trv = path; *trv; ++trv); + if ((trv - path) >= MAX_PATH) { + errno = ENAMETOOLONG; + return MKERROR; + } + + end = trv; + if ((end - path) <= 6 || strcmp(end - 6, "XXXXXX")) { + /* too short or missing 'XXXXXX' */ + errno = EINVAL; + return MKERROR; + } + + seed = generate_seed(); + while (--trv >= path && *trv == 'X') { + *trv = (char)((seed % 10) + '0'); + seed /= 10; /* extra X's get set to 0's */ + } + + if ((trv + 1) == end) { /* missing template? */ + errno = EINVAL; + return MKERROR; + } + + /* + * check the target directory; if you have six X's and it + * doesn't exist this runs for a *very* long time. + */ + for (start = trv + 1;; --trv) { + if (trv <= path) { + break; + } + + if ((c = *trv) == '/' || c == '\\') { + struct _stat sb = {0}; + + if (trv[-1] == ':') { + break; + } + *trv = '\0'; + rc = _stat(path, &sb); /* exists? */ + *trv = c; + if (rc) { + return MKERROR; + } + if (!(sb.st_mode & S_IFDIR)) { + errno = ENOTDIR; + return MKERROR; + } + break; + } + } + + for (;;) { + errno = 0; +#if defined(__MINGW64_VERSION_MAJOR) + if (0 == mkdir(path)) { +#else + if (0 == _mkdir(path)) { +#endif + return MKSUCCESS; + } + if (EEXIST != errno) { + return MKERROR; + } + + /* next is sequence */ + for (trv = start;;) { + if (trv == end) { /* EOS */ + return MKERROR; + } + + if ('z' == *trv) { /* 0..9a..z */ + *trv++ = 'a'; + } else { + if (isdigit(*trv)) { + *trv = 'a'; + } else { + ++*trv; + } + break; + } + } + } + /*NOTREACHED*/ +} + + +#if defined(LOCAL_MAIN) +#define false 0 +#define true 1 + +static int +test(char *templ, int expect_success) +{ + char *rv = hunspell_mkdtemp(templ); + + if (NULL == rv) { + int errsv = errno; + printf("%s: mkdtemp failed: %s\n", __FUNCTION__, strerror(errsv)); + return (false == expect_success); + } else { + printf("%s: mkdtemp created: %s\n", __FUNCTION__, rv); + if (0 != _rmdir(rv)) { + int errsv = errno; + printf("%s: rmdir failed: %s\n", __FUNCTION__, strerror(errsv)); + } + return (true == expect_success); + } +} + + +static void +test_mkdtemp() +{ + + int success = 0, failure = 0; + + // Normal: should pass + { char templ1[] = "/tmp/asdf.XXXXXX"; + if (test(templ1, true)) { + printf("*** Test case 1: PASS\n"); + ++success; + } else { + printf("*** Test case 1: FAIL\n"); + ++failure; + } + } + + // Too short: should fail + { char templ2[] = "XXXXXX"; + if (test(templ2, false)) { + printf("*** Test case 2: PASS\n"); + ++success; + } else { + printf("*** Test case 2: FAIL\n"); + ++failure; + } + } + + // Not enough replacement Xs: should fail + { char templ3[] = "/tmp/asdf.XXXXX"; + if (test(templ3, false)) { + printf("*** Test case 3: PASS\n"); + ++success; + } else { + printf("*** Test case 3: FAIL\n"); + ++failure; + } + } + + // Make sure it only replaces the end: should pass + { char templ4[] = "/tmp/asdfXXXXXX.XXXXXX"; + if (test(templ4, true)) { + printf("*** Test case 4: PASS\n"); + ++success; + } else { + printf("*** Test case 4: FAIL\n"); + ++failure; + } + } + + // Really long: should fail + { char templ5[] = + "/tmp/asdfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaXXXXXX"; + if (test(templ5, false)) { + printf("*** Test case 5: PASS\n"); + ++success; + } else { + printf("*** Test case 5: FAIL\n"); + ++failure; + } + } + + // Unwriteable path: should fail + { char templ6[] = "/asdfkjavblkjadv/asdf.XXXX"; + if (test(templ6, false)) { + printf("*** Test case 6: PASS\n"); + ++success; + } else { + printf("*** Test case 6: FAIL\n"); + ++failure; + } + } + + printf("TEST SUMMARY: Success=%d, Failure=%d\n", success, failure); + return failure; +} + +int +main() +{ + test_mkdtemp(); +} +#endif + +/*end*/ + diff --git a/contrib/hunspell/hunspell_mktemp.h b/contrib/hunspell/hunspell_mktemp.h new file mode 100644 index 00000000..86f6a180 --- /dev/null +++ b/contrib/hunspell/hunspell_mktemp.h @@ -0,0 +1,36 @@ +/* + * hunspell mkdtemp/mkstemp implementation + */ + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +FILE *hunspell_fdopen(int fd, const char *mode); +int hunspell_mkstemp(char *templ); +char *hunspell_mkdtemp(char *templ); + +#if defined(__MINGW32__) +#define fdopen(__a,__b) hunspell_fdopen(__a,__b) +#else +#if !defined(WIN32) +#define WIN32 +#endif +#define fdopen(__a,__b) _fdopen(__a,__b) +#endif + +#if !defined(__WATCOMC__) +#define mkstemp(__templ) hunspell_mkstemp(__templ) +#endif + +#define mkdtemp(__templ) hunspell_mkdtemp(__templ) + +#if defined(__cplusplus) +} +#endif + +/*end*/ + + diff --git a/contrib/hunspell/libhunspell.rc b/contrib/hunspell/libhunspell.rc new file mode 100644 index 00000000..c195e73c --- /dev/null +++ b/contrib/hunspell/libhunspell.rc @@ -0,0 +1,59 @@ +/* + * hunspell library resource. + */ + +#include + +#include "version.h" + +#ifdef GCC_WINDRES +VS_VERSION_INFO VERSIONINFO +#else +VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE +#endif + FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0 + PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS 1 +#else + FILEFLAGS 0 +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0 // not used +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + //language ID = U.S. English, char set = Windows, Multilingual + BEGIN + VALUE "FileDescription", + "Hunspell spell checker and morphological analyzer library\0" + + VALUE "FileVersion", VERSION "\0" + + VALUE "InternalName", "libhunspell.dll\0" + + VALUE "LegalCopyright", + "License under the GNU Lesser General Public License v2.1, " + "Author Laszlo Nemeth\0" + + VALUE "OriginalFilename", + "Duktape." VERSION ".dll\0" + + VALUE "ProductName", + "Duktape\0" + + VALUE "ProductVersion", + VERSION "\0" + + VALUE "Comments", + "For more information visit https://github.com/hunspell/hunspell\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END diff --git a/contrib/hunspell/version.pl b/contrib/hunspell/version.pl new file mode 100644 index 00000000..1f1d804b --- /dev/null +++ b/contrib/hunspell/version.pl @@ -0,0 +1,84 @@ +#!/usr/bin/perl -w +# -*- mode: perl; -*- +# $Id: version.pl,v 1.1 2022/06/11 14:44:04 cvsuser Exp $ +# hunspell version +# +# Copyright Adam Young 2022 +# All rights reserved. +# + +use strict; +use warnings 'all'; +use Getopt::Long; +use POSIX qw(strftime asctime); + +my $output = "version.h"; +my $prefix = ""; +my $version = undef; +my $builddate = undef; +my $help = 0; + +Usage() if (0 == GetOptions( + 'output=s' => \$output, + 'prefix=s' => \$prefix, + 'version=s' => \$version, + 'date=i' => \$builddate, + 'help' => \$help) + || $help); + +die "missing version number\n" + if (! $version); + +$builddate = strftime('%Y%m%d', localtime) + if (! $builddate); + +Generate(); + +sub +Generate #() +{ + open(FILE, ">${output}") or + die "cannot create <${output}> : $!\n"; + + my ($version1, $version2, $version3, $version4) = + split(/\./, $version); + + my $timestamp = asctime(localtime); + chomp($timestamp); + + $version2 = 0 if (! $version2); + $version3 = 0 if (! $version3); + + print FILE <<"EOT"; +// Auto-generated by Makefile ${timestamp} +#define ${prefix}VERSION "${version}" +#define ${prefix}VERSION_MAJOR ${version1} +#define ${prefix}VERSION_MINOR ${version2} +#define ${prefix}VERSION_REVISION ${version3} +#define ${prefix}BUILD_DATE "${builddate}" +EOT + close(FILE); +} + + +sub +Usage # ([message]) +{ + print "\nversion.pl @_\n\n" if (@_); + print < Package version. + --prefix Identifier prefix (optional). + --date Build date (optionaL). + +EOU + exit 3; +} + +1; + +#end + diff --git a/contrib/hunspell/win32/unistd.h b/contrib/hunspell/win32/unistd.h new file mode 100644 index 00000000..15357299 --- /dev/null +++ b/contrib/hunspell/win32/unistd.h @@ -0,0 +1,47 @@ +/* + * MSVC/OWC/MINGW/MINGW64 - + */ +#include +#include +#include + +#if defined(__WATCOMC__) +#if defined(__cplusplus) +#pragma disable_message(7) +#pragma disable_message(88) +#pragma disable_message(391) +#else +#pragma disable_message(392) +#endif +#endif + +#if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW64_VERSION_MAJOR) +#include +#endif +#include +#include + +#include "../hunspell_mktemp.h" + +#if defined(_MSC_VER) || defined(__WATCOMC__) +#if !defined(mode_t) +#define mode_t unsigned short +#endif +#endif + +#if defined(__MINGW32__) +#if !defined(__MINGW64_VERSION_MAJOR) +#define S_IRWXG 0 +#define S_IRWXO 0 +#endif +#endif + +#if defined(_MSC_VER) +#define S_IWUSR S_IWRITE +#define S_IRUSR S_IREAD +#define S_IXUSR 0 +#define S_IRWXG 0 +#define S_IRWXO 0 +#endif + +/*end*/ diff --git a/contrib/libarchive/.cvsignore b/contrib/libarchive/.cvsignore index 8a4ee951..acf64640 100644 --- a/contrib/libarchive/.cvsignore +++ b/contrib/libarchive/.cvsignore @@ -1,3 +1,4 @@ +libarchive-3.* Makefile *.err .unpacked.* diff --git a/contrib/libarchive/.gitignore b/contrib/libarchive/.gitignore index 0dec269b..c7991143 100644 --- a/contrib/libarchive/.gitignore +++ b/contrib/libarchive/.gitignore @@ -1 +1,3 @@ -libarchive-3.*/ \ No newline at end of file +libarchive-3.*/ +sdk/ + diff --git a/contrib/libarchive/Changes b/contrib/libarchive/Changes new file mode 100644 index 00000000..0d0f9c71 --- /dev/null +++ b/contrib/libarchive/Changes @@ -0,0 +1,70 @@ +Tue May 31 19:15:55 2022 adamy + + * MinGW-w64, include + +Fri May 27 20:51:20 2022 adamy + + * libarchive 3.6,1 + + - additional + + archive_write_set_format_cpio_binary.c + archive_write_set_format_cpio_odc.c + archive_read_support_format_rar5.c + archive_blake2sp_ref.c + archive_blake2s_ref.c + archive_ppmd8.c + + - mingw + + o libarchive/archive_read_disk_windows.c: + + Optional _REPARSE_DATA_BUFFER definition, (_WIN32_WINNT < 0x0601) + + - open-watcomc + + o archive_platform.c(78) + + #if defined(__WATCOMC__) + #define __LA_LIBC_CC __watcall + #else + #define __LA_LIBC_CC __cdecl + #endif + + o libarchive/archive_read_disk_windows.c: + + #if !defined(MAXIMUM_REPARSE_DATA_BUFFER_SIZE) + #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE (16 * 1024) + #endif + + o archive_read_support_format_7zip.c(812) + o archive_read_support_format_lha.c(1304) + o archive_read_support_format_rar.c(1990) + o archive_read_support_format_zip.c(1194) + o archive_write_add_filter_zstd.c(215) + o archive_write_set_format_warc.c(199) + o archive_read_support_format_rar5.c(1025, 1047, 1471) + + relocated variable definition. + + o archive_blake2.h(106), BLAKE2_PACKED + + + #elif defined(__WATCOMC__) + #define BLAKE2_PACKED(x) x + + + #if defined(__WATCOMC__) + + #pragma pack( __push, 1 ) + + #endif + + + #if defined(__WATCOMC__) + + #pragma pack( __pop ) + + #endif + +/* + * Local Variables: *** + * mode: changelog *** + * End: *** + */ + + + diff --git a/contrib/libarchive/Makefile.in b/contrib/libarchive/Makefile.in index f5110607..f9f56df5 100644 --- a/contrib/libarchive/Makefile.in +++ b/contrib/libarchive/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.15 2020/06/18 20:35:15 cvsuser Exp $ +# $Id: Makefile.in,v 1.17 2022/06/15 12:00:52 cvsuser Exp $ # libarchive makefile # # @@ -61,9 +61,6 @@ CEXTRA= @DEFS@ ifeq ("yes","@ISWIN32@") CEXTRA+= -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE endif -ifeq ("mingw32","@build_os@") -CEXTRA+= -D__USE_MINGW_ANSI_STDIO -endif ifeq ("$(BUILD_TYPE)","release") CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) @@ -84,7 +81,11 @@ RMFLAGS= -f ARCHIVELIB= $(D_LIB)/$(LP)archive_static$(A) ARCHIVEDLL= $(D_LIB)/$(LP)archive.la +ifeq ("vs90","@TOOLCHAIN@") VERSION= 3.3.3 +else +VERSION= 3.6.1 +endif VERSIONSPEC= $(subst .,:,$(VERSION)) PACKED= libarchive-$(VERSION).gr.tgz ARCHIVESRC= ./libarchive-$(VERSION)/libarchive @@ -211,6 +212,17 @@ LIBOBJS+=\ $(D_OBJ)/archive_write_set_passphrase$(O) \ $(D_OBJ)/xxhash$(O) +#3.6.1 +ifeq ("$(VERSION)","3.6.1") +LIBOBJS+=\ + $(D_OBJ)/archive_write_set_format_cpio_binary$(O) \ + $(D_OBJ)/archive_write_set_format_cpio_odc$(O) \ + $(D_OBJ)/archive_read_support_format_rar5$(O) \ + $(D_OBJ)/archive_blake2sp_ref$(O) \ + $(D_OBJ)/archive_blake2s_ref$(O) \ + $(D_OBJ)/archive_ppmd8$(O) +endif + ifeq ("yes","@ISWIN32@") LIBOBJS+=\ $(D_OBJ)/archive_windows$(O) \ diff --git a/contrib/libarchive/Makefile.in.3.3.3 b/contrib/libarchive/Makefile.in.3.3.3 new file mode 100644 index 00000000..7a27eaa1 --- /dev/null +++ b/contrib/libarchive/Makefile.in.3.3.3 @@ -0,0 +1,315 @@ +# -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- +# $Id: Makefile.in.3.3.3,v 1.1 2022/05/27 17:45:55 cvsuser Exp $ +# libarchive makefile +# +# +# + +@SET_MAKE@ +ROOT= @abs_top_builddir@ +top_builddir= @top_builddir@ + +# File extensions + +E= +O= .o +A= .a +LP= lib + +CLEAN= *.bak *~ *.BAK *.swp *.tmp core *.core a.out +XCLEAN= + +# Compilers, programs + +CC= @CC@ +AR= @AR@ +RANLIB= @RANLIB@ +RM= @RM@ +PERL= @PERL@ +LIBTOOL= @LIBTOOL@ + +# Configuration + +ifeq ("$(BUILD_TYPE)","") #default +BUILD_TYPE= debug +MAKEFLAGS+= BUILD_TYPE=debug +endif +ifneq ("$(BUILD_TYPE)","release") +RTSUFFIX=d +endif + +# Directories + +D_INC= $(ROOT)/include +D_BIN= $(ROOT)/bin@TOOLCHAINEXT@/$(BUILD_TYPE) +D_OBJ= $(ROOT)/objects@TOOLCHAINEXT@/$(BUILD_TYPE)/libarchive +D_LIB= $(ROOT)/lib@TOOLCHAINEXT@/$(BUILD_TYPE) + +# Common flags + +XFLAGS= + +CFLAGS= @CFLAGS@ +CWARN= @CWARN@ +CDEBUG= @CDEBUG@ +CRELEASE= @CRELEASE@ +LDDEBUG= @LDDEBUG@ +LDRELEASE= @LDRELEASE@ + +CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ +CEXTRA= @DEFS@ +ifeq ("yes","@ISWIN32@") +CEXTRA+= -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE +endif +ifeq ("mingw32","@build_os@") +CEXTRA+= -D__USE_MINGW_ANSI_STDIO +endif + +ifeq ("$(BUILD_TYPE)","release") +CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) +LDFLAGS= $(LDRELEASE) @LDFLAGS@ +else +CFLAGS+= $(CDEBUG) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) +LDFLAGS= $(LDDEBUG) @LDFLAGS@ +endif +LDLIBS= -L$(D_LIB) @LIBLZMA@ @LIBS@ @EXTRALIBS@ + +ARFLAGS= rcv +RMFLAGS= -f + + +######################################################################################### +# Targets + +ARCHIVELIB= $(D_LIB)/$(LP)archive_static$(A) +ARCHIVEDLL= $(D_LIB)/$(LP)archive.la + +VERSION= 3.3.3 +VERSIONSPEC= $(subst .,:,$(VERSION)) +PACKED= libarchive-$(VERSION).gr.tgz +ARCHIVESRC= ./libarchive-$(VERSION)/libarchive +VPATH= $(ARCHIVESRC) + +LIBOBJS=\ + $(D_OBJ)/archive_acl$(O) \ + $(D_OBJ)/archive_check_magic$(O) \ + $(D_OBJ)/archive_cryptor$(O) \ + $(D_OBJ)/archive_entry$(O) \ + $(D_OBJ)/archive_entry_copy_bhfi$(O) \ + $(D_OBJ)/archive_entry_copy_stat$(O) \ + $(D_OBJ)/archive_entry_link_resolver$(O) \ + $(D_OBJ)/archive_entry_sparse$(O) \ + $(D_OBJ)/archive_entry_stat$(O) \ + $(D_OBJ)/archive_entry_strmode$(O) \ + $(D_OBJ)/archive_entry_xattr$(O) \ + $(D_OBJ)/archive_getdate$(O) \ + $(D_OBJ)/archive_match$(O) \ + $(D_OBJ)/archive_options$(O) \ + $(D_OBJ)/archive_pathmatch$(O) \ + $(D_OBJ)/archive_ppmd7$(O) \ + $(D_OBJ)/archive_rb$(O) \ + $(D_OBJ)/archive_read$(O) \ + $(D_OBJ)/archive_read_data_into_fd$(O) \ + $(D_OBJ)/archive_read_disk_set_standard_lookup$(O) \ + $(D_OBJ)/archive_read_disk_windows$(O) \ + $(D_OBJ)/archive_read_extract$(O) \ + $(D_OBJ)/archive_read_open_fd$(O) \ + $(D_OBJ)/archive_read_open_file$(O) \ + $(D_OBJ)/archive_read_open_filename$(O) \ + $(D_OBJ)/archive_read_open_memory$(O) \ + $(D_OBJ)/archive_read_set_options$(O) \ + $(D_OBJ)/archive_read_support_filter_all$(O) \ + $(D_OBJ)/archive_read_support_filter_bzip2$(O) \ + $(D_OBJ)/archive_read_support_filter_compress$(O) \ + $(D_OBJ)/archive_read_support_filter_gzip$(O) \ + $(D_OBJ)/archive_read_support_filter_none$(O) \ + $(D_OBJ)/archive_read_support_filter_program$(O) \ + $(D_OBJ)/archive_read_support_filter_rpm$(O) \ + $(D_OBJ)/archive_read_support_filter_uu$(O) \ + $(D_OBJ)/archive_read_support_filter_xz$(O) \ + $(D_OBJ)/archive_read_support_format_7zip$(O) \ + $(D_OBJ)/archive_read_support_format_all$(O) \ + $(D_OBJ)/archive_read_support_format_ar$(O) \ + $(D_OBJ)/archive_read_support_format_by_code$(O) \ + $(D_OBJ)/archive_read_support_format_cab$(O) \ + $(D_OBJ)/archive_read_support_format_cpio$(O) \ + $(D_OBJ)/archive_read_support_format_empty$(O) \ + $(D_OBJ)/archive_read_support_format_iso9660$(O) \ + $(D_OBJ)/archive_read_support_format_lha$(O) \ + $(D_OBJ)/archive_read_support_format_mtree$(O) \ + $(D_OBJ)/archive_read_support_format_rar$(O) \ + $(D_OBJ)/archive_read_support_format_raw$(O) \ + $(D_OBJ)/archive_read_support_format_tar$(O) \ + $(D_OBJ)/archive_read_support_format_xar$(O) \ + $(D_OBJ)/archive_read_support_format_zip$(O) \ + $(D_OBJ)/archive_string$(O) \ + $(D_OBJ)/archive_string_sprintf$(O) \ + $(D_OBJ)/archive_util$(O) \ + $(D_OBJ)/archive_virtual$(O) \ + $(D_OBJ)/archive_write$(O) \ + $(D_OBJ)/archive_write_add_filter$(O) \ + $(D_OBJ)/archive_write_add_filter_bzip2$(O) \ + $(D_OBJ)/archive_write_add_filter_compress$(O) \ + $(D_OBJ)/archive_write_add_filter_gzip$(O) \ + $(D_OBJ)/archive_write_add_filter_none$(O) \ + $(D_OBJ)/archive_write_add_filter_program$(O) \ + $(D_OBJ)/archive_write_add_filter_xz$(O) \ + $(D_OBJ)/archive_write_disk_set_standard_lookup$(O) \ + $(D_OBJ)/archive_write_disk_windows$(O) \ + $(D_OBJ)/archive_write_open_fd$(O) \ + $(D_OBJ)/archive_write_open_file$(O) \ + $(D_OBJ)/archive_write_open_filename$(O) \ + $(D_OBJ)/archive_write_open_memory$(O) \ + $(D_OBJ)/archive_write_set_format$(O) \ + $(D_OBJ)/archive_write_set_format_7zip$(O) \ + $(D_OBJ)/archive_write_set_format_ar$(O) \ + $(D_OBJ)/archive_write_set_format_by_name$(O) \ + $(D_OBJ)/archive_write_set_format_cpio$(O) \ + $(D_OBJ)/archive_write_set_format_cpio_newc$(O) \ + $(D_OBJ)/archive_write_set_format_gnutar$(O) \ + $(D_OBJ)/archive_write_set_format_iso9660$(O) \ + $(D_OBJ)/archive_write_set_format_mtree$(O) \ + $(D_OBJ)/archive_write_set_format_pax$(O) \ + $(D_OBJ)/archive_write_set_format_shar$(O) \ + $(D_OBJ)/archive_write_set_format_ustar$(O) \ + $(D_OBJ)/archive_write_set_format_xar$(O) \ + $(D_OBJ)/archive_write_set_format_zip$(O) \ + $(D_OBJ)/archive_write_set_options$(O) + +#3.1.2 +LIBOBJS+=\ + $(D_OBJ)/archive_read_support_filter_lrzip$(O) \ + $(D_OBJ)/archive_read_support_filter_lzop$(O) \ + $(D_OBJ)/archive_read_support_filter_grzip$(O) \ + $(D_OBJ)/archive_write_add_filter_grzip$(O) \ + $(D_OBJ)/archive_write_add_filter_lrzip$(O) \ + $(D_OBJ)/archive_write_add_filter_uuencode$(O) \ + $(D_OBJ)/archive_write_set_format_v7tar$(O) \ + $(D_OBJ)/archive_cmdline$(O) + +#3.3.3 +LIBOBJS+=\ + $(D_OBJ)/archive_digest$(O) \ + $(D_OBJ)/archive_disk_acl_darwin$(O) \ + $(D_OBJ)/archive_disk_acl_freebsd$(O) \ + $(D_OBJ)/archive_disk_acl_linux$(O) \ + $(D_OBJ)/archive_disk_acl_sunos$(O) \ + $(D_OBJ)/archive_hmac$(O) \ + $(D_OBJ)/archive_pack_dev$(O) \ + $(D_OBJ)/archive_random$(O) \ + $(D_OBJ)/archive_read_add_passphrase$(O) \ + $(D_OBJ)/archive_read_extract2$(O) \ + $(D_OBJ)/archive_read_support_filter_lz4$(O) \ + $(D_OBJ)/archive_read_support_filter_zstd$(O) \ + $(D_OBJ)/archive_read_support_format_warc$(O) \ + $(D_OBJ)/archive_version_details$(O) \ + $(D_OBJ)/archive_write_add_filter_lz4$(O) \ + $(D_OBJ)/archive_write_add_filter_zstd$(O) \ + $(D_OBJ)/archive_write_set_format_filter_by_ext$(O) \ + $(D_OBJ)/archive_write_set_format_raw$(O) \ + $(D_OBJ)/archive_write_set_format_warc$(O) \ + $(D_OBJ)/archive_write_set_passphrase$(O) \ + $(D_OBJ)/xxhash$(O) + +ifeq ("yes","@ISWIN32@") +LIBOBJS+=\ + $(D_OBJ)/archive_windows$(O) \ + $(D_OBJ)/filter_fork_windows$(O) + +#special 3.3.3 +# XXX: crypt32.dll dynamic loader ... +LIBOBJS+=\ + $(D_OBJ)/w32_crypto$(O) +else +LIBOBJS+=\ + $(D_OBJ)/archive_read_disk_posix$(O) \ + $(D_OBJ)/archive_write_disk_posix$(O) \ + $(D_OBJ)/archive_read_disk_entry_from_file$(O) \ + $(D_OBJ)/filter_fork_posix$(O) +endif + +DLLOBJS= \ + $(subst $(O),.lo,$(LIBOBJS)) + +OBJS= $(LIBOBJS) $(DLLOBJS) +LIBS= $(ARCHIVELIB) $(ARCHIVEDLL) +TSKS= + + +######################################################################################### +# Rules + +.PHONY: build release debug +build: checkversion source unpacked +unpacked: object $(LIBS) $(TSKS) installinc + +release: + $(MAKE) BUILD_TYPE=release $(filter-out release, $(MAKECMDGOALS)) +debug: + $(MAKE) BUILD_TYPE=debug $(filter-out debug, $(MAKECMDGOALS)) + +# gmake 4.0; file operator required +verneeded := 4.0 +verreported := $(filter $(verneeded),$(firstword $(sort $(MAKE_VERSION) $(verneeded)))) + +.PHONY: checkversion +checkversion: +ifeq ($(verreported),) + $(error Unsupported Make version. \ + The build system does not work properly with GNU Make $(MAKE_VERSION), GNU Make ${verneeded} or above required.) +endif + +$(ARCHIVELIB): CEXTRA += -I$(ARCHIVESRC) -DLIBARCHIVE_STATIC +$(ARCHIVELIB): $(LIBOBJS) + $(RM) $(RMFLAGS) $@ >/dev/null 2>&1 + $(file >libtool.cmd) $(foreach O,$^,$(file >>libtool.cmd, $O)) + $(AR) $(ARFLAGS) $@ @libtool.cmd + @$(RM) libtool.cmd + $(RANLIB) $@ + +$(ARCHIVEDLL): CEXTRA += -I$(ARCHIVESRC) -D__LIBARCHIVE_BUILD -DZLIB_DLL +$(ARCHIVEDLL): $(DLLOBJS) + $(file >libtool.cmd) $(foreach O,$^,$(file >>libtool.cmd, $O)) + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ -version-number $(VERSIONSPEC) \ + -rpath $(D_LIB) -bindir $(D_BIN) @libtool.cmd libz$(A) libbz2$(A) $(LDLIBS) + @$(RM) libtool.cmd + +source: .unpacked.$(VERSION) + $(MAKE) unpacked + +.unpacked.$(VERSION): $(PACKED) + @echo "do not delete, managed file" > $@ + @echo "unpacking source $(PACKED)" + @gzip -c -d $(PACKED) | tar -xvf - + +.PHONY: object +object: $(D_OBJ)/.created + +.PHONY: installinc +installinc: ../include/.created + @echo publishing headers ... + -cp $(ARCHIVESRC)/archive.h ../include + -cp $(ARCHIVESRC)/archive_entry.h ../include + +%/.created: + -@mkdir $(@D) + @echo "do not delete, managed directory" > $@ + +clean: + -@$(RM) $(RMFLAGS) $(TSKS) $(LIBS) $(CLEAN) $(XCLEAN) >/dev/null 2>&1 + -@$(LIBTOOL) --mode=clean $(RM) $(DLLOBJS) >/dev/null 2>&1 + -@$(RM) $(LIBOBJS) >/dev/null 2>&1 + +$(D_OBJ)/%$(O): %.c + $(CC) $(CFLAGS) -o $@ -c $< + +$(D_OBJ)/%$(O): %.cpp + $(CXX) $(CXXFLAGS) -o $@ -c $< + +$(D_OBJ)/%.lo: %.c + $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -o $@ -c $< + +$(D_OBJ)/%.lo: %.cpp + $(LIBTOOL) --mode=compile $(CXX) $(CXXFLAGS) -o $@ -c $< + +#end diff --git a/contrib/libarchive/config.h b/contrib/libarchive/config.h index 752151b0..dad2e4c1 100644 --- a/contrib/libarchive/config.h +++ b/contrib/libarchive/config.h @@ -1,9 +1,9 @@ -#ifndef CONFIG_H_INCLUDED -#define CONFIG_H_INCLUDED +#ifndef __LIBARCHIVE_CONFIG_H_INCLUDED +#define __LIBARCHIVE_CONFIG_H_INCLUDED /* * libarchive ... */ - + #define PACKAGE_NAME "libarchive" #define PACKAGE_TARNAME "libarchive" #define PACKAGE_BUGREPORT "" @@ -20,22 +20,38 @@ // #define LIBARCHIVE_VERSION_STRING "3.1.2" // #define LIBARCHIVE_VERSION_NUMBER "3001002" -#define PACKAGE_VERSION "3.3.3" -#define PACKAGE_STRING "libarchive 3.3.3" -#define LIBARCHIVE_VERSION_STRING "3.3.3" -#define LIBARCHIVE_VERSION_NUMBER "3003003" +// #define PACKAGE_VERSION "3.3.3" +// #define PACKAGE_STRING "libarchive 3.3.3" +// #define LIBARCHIVE_VERSION_STRING "3.3.3" +// #define LIBARCHIVE_VERSION_NUMBER "3003003" + +#define PACKAGE_VERSION "3.6.1" +#define PACKAGE_STRING "libarchive 3.6.1" +#define LIBARCHIVE_VERSION_STRING "3.6.1" +#define LIBARCHIVE_VERSION_NUMBER "3006001" #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0601 // Windows 7; bcrypt requirement +#define _WIN32_WINNT 0x0601 // Windows 7; bcrypt requirement #endif +#undef WINVER +#define WINVER _WIN32_WINNT // MingW #include "../contrib_config.h" +#if !defined(HAVE_CTYPE_H) +#define HAVE_CTYPE_H 1 // TODO: makelib.pl +#endif +#define USE_NATIVE_DIRECT // libw32 + +#include + #if !defined(HAVE_BCRYPT_H) +#if !defined(__MINGW32__) #error missing ... #endif +#endif -#if defined(_MSC_VER) && (_MSC_VER <= 1500) //2008; missing Win7 SDK components +#if defined(_MSC_VER) && (_MSC_VER <= 1500) // 2008; missing Win7 SDK components #include #include #ifndef NT_SUCCESS @@ -59,30 +75,20 @@ NTSTATUS WINAPI BCryptDeriveKeyPBKDF2(BCRYPT_ALG_HANDLE hPrf, PUCHAR pbPassword, * archive_entry.h: * * - #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) - * # define __LA_MODE_T unsigned short + * # define __LA_MODE_T unsigned short * * + #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) && !defined(__WATCOMC__) - * # define __LA_MODE_T unsigned short + * # define __LA_MODE_T unsigned short */ + #define HAVE_DECL_SIZE_MAX 1 #define HAVE_WCSCPY 1 #define HAVE_WCSLEN 1 #define _SSIZE_T_DEFINED 1 #undef S_ISLNK +#define S_ISLNK(m) (0) #undef S_ISSOCK -#undef S_ISUID -#undef S_ISGID -#undef S_ISVTX -#undef S_IRWXG - -#undef S_IXGRP -#undef S_IWGRP -#undef S_IRGRP -#undef S_IRWXO -#undef S_IXOTH -#undef S_IWOTH -#undef S_IROTH #if (__WATCOMC__ >= 1300) #undef _S_IXGRP @@ -96,8 +102,37 @@ NTSTATUS WINAPI BCryptDeriveKeyPBKDF2(BCRYPT_ALG_HANDLE hPrf, PUCHAR pbPassword, #undef _S_IFLNK #undef _S_IFSOCK #endif - #endif /*__WATCOMC__*/ -#endif /*CONFIG_H_INCLUDED*/ +#if defined(_MSC_VER) +#undef S_ISLNK +#undef S_ISSOCK +#undef S_ISUID +#undef S_ISGID +#undef S_ISVTX +#undef S_IRWXG + +#undef S_IXGRP +#undef S_IWGRP +#undef S_IRGRP +#endif + +#if defined(__MINGW32__) +#if defined(__MINGW64_VERSION_MAJOR) +#include +#endif + +#undef S_ISLNK +#undef S_ISSOCK +#undef S_ISUID +#undef S_ISGID +#undef S_ISVTX +#undef S_IRWXG + +#undef S_IXGRP +#undef S_IWGRP +#undef S_IRGRP +#endif /*__MINGW32__*/ + +#endif /*__LIBARCHIVE_CONFIG_H_INCLUDED*/ diff --git a/contrib/libarchive/libarchive-3.6.1.gr.tgz b/contrib/libarchive/libarchive-3.6.1.gr.tgz new file mode 100644 index 00000000..bda331b8 Binary files /dev/null and b/contrib/libarchive/libarchive-3.6.1.gr.tgz differ diff --git a/contrib/libarchive/mingw_bcrypt.h b/contrib/libarchive/mingw_bcrypt.h new file mode 100644 index 00000000..9e95a9e8 --- /dev/null +++ b/contrib/libarchive/mingw_bcrypt.h @@ -0,0 +1,618 @@ +/** + * This file is part of the mingw-w64 runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ + + //#include +#define WINAPI_FAMILY_PARTITION(__x) (1) + +#ifndef __BCRYPT_H__ +#define __BCRYPT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) || _WIN32_WINNT >= 0x0A00 + +#ifndef WINAPI +#if defined(_ARM_) +#define WINAPI +#else +#define WINAPI __stdcall +#endif +#endif + +#if !defined (_NTDEF_) && !defined (_NTSTATUS_PSDK) +#define _NTSTATUS_PSDK +typedef LONG NTSTATUS,*PNTSTATUS; +#endif + +#ifndef BCRYPT_SUCCESS +#define BCRYPT_SUCCESS(Status) (((NTSTATUS) (Status)) >= 0) +#endif + +#ifndef CONST +#define CONST const +#endif +#ifndef _NO_W32_PSEUDO_MODIFIERS +#ifndef IN +#define IN +#endif +#ifndef OUT +#define OUT +#endif +#ifndef OPTIONAL +#define OPTIONAL +#endif +#endif + +#define BCRYPT_OBJECT_ALIGNMENT 16 + +#define BCRYPT_STRUCT_ALIGNMENT + +#define BCRYPT_KDF_HASH L"HASH" +#define BCRYPT_KDF_HMAC L"HMAC" +#define BCRYPT_KDF_TLS_PRF L"TLS_PRF" +#define BCRYPT_KDF_SP80056A_CONCAT L"SP800_56A_CONCAT" + +#define KDF_HASH_ALGORITHM 0x0 +#define KDF_SECRET_PREPEND 0x1 +#define KDF_SECRET_APPEND 0x2 +#define KDF_HMAC_KEY 0x3 +#define KDF_TLS_PRF_LABEL 0x4 +#define KDF_TLS_PRF_SEED 0x5 +#define KDF_SECRET_HANDLE 0x6 +#define KDF_TLS_PRF_PROTOCOL 0x7 +#define KDF_ALGORITHMID 0x8 +#define KDF_PARTYUINFO 0x9 +#define KDF_PARTYVINFO 0xa +#define KDF_SUPPPUBINFO 0xb +#define KDF_SUPPPRIVINFO 0xc +#define KDF_LABEL 0xd +#define KDF_CONTEXT 0xe +#define KDF_SALT 0xf +#define KDF_ITERATION_COUNT 0x10 +#define KDF_GENERIC_PARAMETER 0x11 +#define KDF_KEYBITLENGTH 0x12 + +#define KDF_USE_SECRET_AS_HMAC_KEY_FLAG 1 + +#define BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION 1 + +#define BCRYPT_AUTH_MODE_CHAIN_CALLS_FLAG 0x00000001 +#define BCRYPT_AUTH_MODE_IN_PROGRESS_FLAG 0x00000002 + +#define BCRYPT_INIT_AUTH_MODE_INFO(_AUTH_INFO_STRUCT_) \ + RtlZeroMemory ((&_AUTH_INFO_STRUCT_), sizeof (BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO)); \ + (_AUTH_INFO_STRUCT_).cbSize = sizeof (BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO); \ + (_AUTH_INFO_STRUCT_).dwInfoVersion = BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_VERSION; + +#define BCRYPT_OPAQUE_KEY_BLOB L"OpaqueKeyBlob" +#define BCRYPT_KEY_DATA_BLOB L"KeyDataBlob" +#define BCRYPT_AES_WRAP_KEY_BLOB L"Rfc3565KeyWrapBlob" + +#define BCRYPT_ALGORITHM_NAME L"AlgorithmName" +#define BCRYPT_AUTH_TAG_LENGTH L"AuthTagLength" +#define BCRYPT_BLOCK_LENGTH L"BlockLength" +#define BCRYPT_BLOCK_SIZE_LIST L"BlockSizeList" +#define BCRYPT_CHAINING_MODE L"ChainingMode" +#define BCRYPT_CHAIN_MODE_CBC L"ChainingModeCBC" +#define BCRYPT_CHAIN_MODE_CCM L"ChainingModeCCM" +#define BCRYPT_CHAIN_MODE_CFB L"ChainingModeCFB" +#define BCRYPT_CHAIN_MODE_ECB L"ChainingModeECB" +#define BCRYPT_CHAIN_MODE_GCM L"ChainingModeGCM" +#define BCRYPT_CHAIN_MODE_NA L"ChainingModeN/A" +#define BCRYPT_EFFECTIVE_KEY_LENGTH L"EffectiveKeyLength" +#define BCRYPT_HASH_BLOCK_LENGTH L"HashBlockLength" +#define BCRYPT_HASH_LENGTH L"HashDigestLength" +#define BCRYPT_HASH_OID_LIST L"HashOIDList" +#define BCRYPT_INITIALIZATION_VECTOR L"IV" +#define BCRYPT_IS_KEYED_HASH L"IsKeyedHash" +#define BCRYPT_IS_REUSABLE_HASH L"IsReusableHash" +#define BCRYPT_KEY_LENGTH L"KeyLength" +#define BCRYPT_KEY_LENGTHS L"KeyLengths" +#define BCRYPT_KEY_OBJECT_LENGTH L"KeyObjectLength" +#define BCRYPT_KEY_STRENGTH L"KeyStrength" +#define BCRYPT_MESSAGE_BLOCK_LENGTH L"MessageBlockLength" +#define BCRYPT_OBJECT_LENGTH L"ObjectLength" +#define BCRYPT_PADDING_SCHEMES L"PaddingSchemes" +#define BCRYPT_PCP_PLATFORM_TYPE_PROPERTY L"PCP_PLATFORM_TYPE" +#define BCRYPT_PCP_PROVIDER_VERSION_PROPERTY L"PCP_PROVIDER_VERSION" +#define BCRYPT_PRIMITIVE_TYPE L"PrimitiveType" +#define BCRYPT_PROVIDER_HANDLE L"ProviderHandle" +#define BCRYPT_SIGNATURE_LENGTH L"SignatureLength" + +#define BCRYPT_SUPPORTED_PAD_ROUTER 0x00000001 +#define BCRYPT_SUPPORTED_PAD_PKCS1_ENC 0x00000002 +#define BCRYPT_SUPPORTED_PAD_PKCS1_SIG 0x00000004 +#define BCRYPT_SUPPORTED_PAD_OAEP 0x00000008 +#define BCRYPT_SUPPORTED_PAD_PSS 0x00000010 + +#define BCRYPT_PROV_DISPATCH 0x00000001 + +#define BCRYPT_BLOCK_PADDING 0x00000001 + +#define BCRYPT_PAD_NONE 0x00000001 +#define BCRYPT_PAD_PKCS1 0x00000002 +#define BCRYPT_PAD_OAEP 0x00000004 +#define BCRYPT_PAD_PSS 0x00000008 + +#define BCRYPTBUFFER_VERSION 0 + + typedef struct __BCRYPT_KEY_LENGTHS_STRUCT { + ULONG dwMinLength; + ULONG dwMaxLength; + ULONG dwIncrement; + } BCRYPT_KEY_LENGTHS_STRUCT; + + typedef BCRYPT_KEY_LENGTHS_STRUCT BCRYPT_AUTH_TAG_LENGTHS_STRUCT; + + typedef struct _BCRYPT_OID { + ULONG cbOID; + PUCHAR pbOID; + } BCRYPT_OID; + + typedef struct _BCRYPT_OID_LIST { + ULONG dwOIDCount; + BCRYPT_OID *pOIDs; + } BCRYPT_OID_LIST; + + typedef struct _BCRYPT_PKCS1_PADDING_INFO { + LPCWSTR pszAlgId; + } BCRYPT_PKCS1_PADDING_INFO; + + typedef struct _BCRYPT_PSS_PADDING_INFO { + LPCWSTR pszAlgId; + ULONG cbSalt; + } BCRYPT_PSS_PADDING_INFO; + + typedef struct _BCRYPT_OAEP_PADDING_INFO { + LPCWSTR pszAlgId; + PUCHAR pbLabel; + ULONG cbLabel; + } BCRYPT_OAEP_PADDING_INFO; + + typedef struct _BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO { + ULONG cbSize; + ULONG dwInfoVersion; + PUCHAR pbNonce; + ULONG cbNonce; + PUCHAR pbAuthData; + ULONG cbAuthData; + PUCHAR pbTag; + ULONG cbTag; + PUCHAR pbMacContext; + ULONG cbMacContext; + ULONG cbAAD; + ULONGLONG cbData; + ULONG dwFlags; + } BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO,*PBCRYPT_AUTHENTICATED_CIPHER_MODE_INFO; +#endif + +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_APP) || _WIN32_WINNT >= 0x0A00 + typedef struct _BCryptBuffer { + ULONG cbBuffer; + ULONG BufferType; + PVOID pvBuffer; + } BCryptBuffer,*PBCryptBuffer; + + typedef struct _BCryptBufferDesc { + ULONG ulVersion; + ULONG cBuffers; + PBCryptBuffer pBuffers; + } BCryptBufferDesc,*PBCryptBufferDesc; +#endif + +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) || _WIN32_WINNT >= 0x0A00 + +#define BCRYPT_PUBLIC_KEY_BLOB L"PUBLICBLOB" +#define BCRYPT_PRIVATE_KEY_BLOB L"PRIVATEBLOB" + +#define BCRYPT_RSAPUBLIC_BLOB L"RSAPUBLICBLOB" +#define BCRYPT_RSAPRIVATE_BLOB L"RSAPRIVATEBLOB" +#define LEGACY_RSAPUBLIC_BLOB L"CAPIPUBLICBLOB" +#define LEGACY_RSAPRIVATE_BLOB L"CAPIPRIVATEBLOB" + +#define BCRYPT_RSAPUBLIC_MAGIC 0x31415352 +#define BCRYPT_RSAPRIVATE_MAGIC 0x32415352 + +#define BCRYPT_RSAFULLPRIVATE_BLOB L"RSAFULLPRIVATEBLOB" + +#define BCRYPT_RSAFULLPRIVATE_MAGIC 0x33415352 + +#define BCRYPT_GLOBAL_PARAMETERS L"SecretAgreementParam" +#define BCRYPT_PRIVATE_KEY L"PrivKeyVal" + +#define BCRYPT_ECCPUBLIC_BLOB L"ECCPUBLICBLOB" +#define BCRYPT_ECCPRIVATE_BLOB L"ECCPRIVATEBLOB" + +#define BCRYPT_ECDH_PUBLIC_P256_MAGIC 0x314b4345 +#define BCRYPT_ECDH_PRIVATE_P256_MAGIC 0x324b4345 +#define BCRYPT_ECDH_PUBLIC_P384_MAGIC 0x334b4345 +#define BCRYPT_ECDH_PRIVATE_P384_MAGIC 0x344b4345 +#define BCRYPT_ECDH_PUBLIC_P521_MAGIC 0x354b4345 +#define BCRYPT_ECDH_PRIVATE_P521_MAGIC 0x364b4345 + +#define BCRYPT_ECDSA_PUBLIC_P256_MAGIC 0x31534345 +#define BCRYPT_ECDSA_PRIVATE_P256_MAGIC 0x32534345 +#define BCRYPT_ECDSA_PUBLIC_P384_MAGIC 0x33534345 +#define BCRYPT_ECDSA_PRIVATE_P384_MAGIC 0x34534345 +#define BCRYPT_ECDSA_PUBLIC_P521_MAGIC 0x35534345 +#define BCRYPT_ECDSA_PRIVATE_P521_MAGIC 0x36534345 + +#define BCRYPT_DH_PUBLIC_BLOB L"DHPUBLICBLOB" +#define BCRYPT_DH_PRIVATE_BLOB L"DHPRIVATEBLOB" +#define LEGACY_DH_PUBLIC_BLOB L"CAPIDHPUBLICBLOB" +#define LEGACY_DH_PRIVATE_BLOB L"CAPIDHPRIVATEBLOB" + +#define BCRYPT_DH_PUBLIC_MAGIC 0x42504844 +#define BCRYPT_DH_PRIVATE_MAGIC 0x56504844 + +#define BCRYPT_DH_PARAMETERS L"DHParameters" +#define BCRYPT_DH_PARAMETERS_MAGIC 0x4d504844 + +#define BCRYPT_DSA_PUBLIC_BLOB L"DSAPUBLICBLOB" +#define BCRYPT_DSA_PRIVATE_BLOB L"DSAPRIVATEBLOB" +#define LEGACY_DSA_PUBLIC_BLOB L"CAPIDSAPUBLICBLOB" +#define LEGACY_DSA_PRIVATE_BLOB L"CAPIDSAPRIVATEBLOB" +#define LEGACY_DSA_V2_PUBLIC_BLOB L"V2CAPIDSAPUBLICBLOB" +#define LEGACY_DSA_V2_PRIVATE_BLOB L"V2CAPIDSAPRIVATEBLOB" + +#define BCRYPT_DSA_PUBLIC_MAGIC 0x42505344 +#define BCRYPT_DSA_PRIVATE_MAGIC 0x56505344 +#define BCRYPT_DSA_PUBLIC_MAGIC_V2 0x32425044 +#define BCRYPT_DSA_PRIVATE_MAGIC_V2 0x32565044 + +#define BCRYPT_KEY_DATA_BLOB_MAGIC 0x4d42444b +#define BCRYPT_KEY_DATA_BLOB_VERSION1 0x1 + +#define BCRYPT_DSA_PARAMETERS L"DSAParameters" +#define BCRYPT_DSA_PARAMETERS_MAGIC 0x4d505344 +#define BCRYPT_DSA_PARAMETERS_MAGIC_V2 0x324d5044 + +#define MS_PRIMITIVE_PROVIDER L"Microsoft Primitive Provider" +#define MS_PLATFORM_CRYPTO_PROVIDER L"Microsoft Platform Crypto Provider" + +#define BCRYPT_RSA_ALGORITHM L"RSA" +#define BCRYPT_RSA_SIGN_ALGORITHM L"RSA_SIGN" +#define BCRYPT_DH_ALGORITHM L"DH" +#define BCRYPT_DSA_ALGORITHM L"DSA" +#define BCRYPT_RC2_ALGORITHM L"RC2" +#define BCRYPT_RC4_ALGORITHM L"RC4" +#define BCRYPT_AES_ALGORITHM L"AES" +#define BCRYPT_DES_ALGORITHM L"DES" +#define BCRYPT_DESX_ALGORITHM L"DESX" +#define BCRYPT_3DES_ALGORITHM L"3DES" +#define BCRYPT_3DES_112_ALGORITHM L"3DES_112" +#define BCRYPT_MD2_ALGORITHM L"MD2" +#define BCRYPT_MD4_ALGORITHM L"MD4" +#define BCRYPT_MD5_ALGORITHM L"MD5" +#define BCRYPT_SHA1_ALGORITHM L"SHA1" +#define BCRYPT_SHA256_ALGORITHM L"SHA256" +#define BCRYPT_SHA384_ALGORITHM L"SHA384" +#define BCRYPT_SHA512_ALGORITHM L"SHA512" +#define BCRYPT_AES_GMAC_ALGORITHM L"AES-GMAC" +#define BCRYPT_AES_CMAC_ALGORITHM L"AES-CMAC" +#define BCRYPT_ECDSA_P256_ALGORITHM L"ECDSA_P256" +#define BCRYPT_ECDSA_P384_ALGORITHM L"ECDSA_P384" +#define BCRYPT_ECDSA_P521_ALGORITHM L"ECDSA_P521" +#define BCRYPT_ECDH_P256_ALGORITHM L"ECDH_P256" +#define BCRYPT_ECDH_P384_ALGORITHM L"ECDH_P384" +#define BCRYPT_ECDH_P521_ALGORITHM L"ECDH_P521" +#define BCRYPT_RNG_ALGORITHM L"RNG" +#define BCRYPT_RNG_FIPS186_DSA_ALGORITHM L"FIPS186DSARNG" +#define BCRYPT_RNG_DUAL_EC_ALGORITHM L"DUALECRNG" +#define BCRYPT_SP800108_CTR_HMAC_ALGORITHM L"SP800_108_CTR_HMAC" +#define BCRYPT_SP80056A_CONCAT_ALGORITHM L"SP800_56A_CONCAT" +#define BCRYPT_PBKDF2_ALGORITHM L"PBKDF2" +#define BCRYPT_CAPI_KDF_ALGORITHM L"CAPI_KDF" + +#define BCRYPT_CIPHER_INTERFACE 0x00000001 +#define BCRYPT_HASH_INTERFACE 0x00000002 +#define BCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE 0x00000003 +#define BCRYPT_SECRET_AGREEMENT_INTERFACE 0x00000004 +#define BCRYPT_SIGNATURE_INTERFACE 0x00000005 +#define BCRYPT_RNG_INTERFACE 0x00000006 +#define BCRYPT_KEY_DERIVATION_INTERFACE 0x00000007 + +#define BCRYPT_ALG_HANDLE_HMAC_FLAG 0x00000008 +#define BCRYPT_CAPI_AES_FLAG 0x00000010 +#define BCRYPT_HASH_REUSABLE_FLAG 0x00000020 + +#define BCRYPT_BUFFERS_LOCKED_FLAG 0x00000040 + +#define BCRYPT_CIPHER_OPERATION 0x00000001 +#define BCRYPT_HASH_OPERATION 0x00000002 +#define BCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION 0x00000004 +#define BCRYPT_SECRET_AGREEMENT_OPERATION 0x00000008 +#define BCRYPT_SIGNATURE_OPERATION 0x00000010 +#define BCRYPT_RNG_OPERATION 0x00000020 +#define BCRYPT_KEY_DERIVATION_OPERATION 0x00000040 + +#define BCRYPT_PUBLIC_KEY_FLAG 0x00000001 +#define BCRYPT_PRIVATE_KEY_FLAG 0x00000002 + +#define BCRYPT_NO_KEY_VALIDATION 0x00000008 + +#define BCRYPT_RNG_USE_ENTROPY_IN_BUFFER 0x00000001 +#define BCRYPT_USE_SYSTEM_PREFERRED_RNG 0x00000002 + +#define BCRYPT_MAKE_INTERFACE_VERSION(major, minor) { (USHORT)major,(USHORT)minor} +#define BCRYPT_IS_INTERFACE_VERSION_COMPATIBLE(loader, provider) ((loader).MajorVersion <= (provider).MajorVersion) + +#define BCRYPT_CIPHER_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION (1, 0) +#define BCRYPT_HASH_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION (1, 0) +#define BCRYPT_ASYMMETRIC_ENCRYPTION_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION (1, 0) +#define BCRYPT_SECRET_AGREEMENT_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION (1, 0) +#define BCRYPT_SIGNATURE_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION (1, 0) +#define BCRYPT_RNG_INTERFACE_VERSION_1 BCRYPT_MAKE_INTERFACE_VERSION (1, 0) + +#define CRYPT_MIN_DEPENDENCIES (0x00000001) +#define CRYPT_PROCESS_ISOLATE (0x00010000) + +#define CRYPT_UM (0x00000001) +#define CRYPT_KM (0x00000002) +#define CRYPT_MM (0x00000003) +#define CRYPT_ANY (0x00000004) + +#define CRYPT_OVERWRITE (0x00000001) + +#define CRYPT_LOCAL (0x00000001) +#define CRYPT_DOMAIN (0x00000002) + +#define CRYPT_EXCLUSIVE (0x00000001) +#define CRYPT_OVERRIDE (0x00010000) + +#define CRYPT_ALL_FUNCTIONS (0x00000001) +#define CRYPT_ALL_PROVIDERS (0x00000002) + +#define CRYPT_PRIORITY_TOP (0x00000000) +#define CRYPT_PRIORITY_BOTTOM (0xffffffff) + +#define CRYPT_DEFAULT_CONTEXT L"Default" + +typedef PVOID BCRYPT_HANDLE; + typedef PVOID BCRYPT_ALG_HANDLE; + typedef PVOID BCRYPT_KEY_HANDLE; + typedef PVOID BCRYPT_HASH_HANDLE; + typedef PVOID BCRYPT_SECRET_HANDLE; + + typedef struct _BCRYPT_KEY_BLOB { + ULONG Magic; + } BCRYPT_KEY_BLOB; + + typedef struct _BCRYPT_RSAKEY_BLOB { + ULONG Magic; + ULONG BitLength; + ULONG cbPublicExp; + ULONG cbModulus; + ULONG cbPrime1; + ULONG cbPrime2; + } BCRYPT_RSAKEY_BLOB; + + typedef struct _BCRYPT_ECCKEY_BLOB { + ULONG dwMagic; + ULONG cbKey; + } BCRYPT_ECCKEY_BLOB,*PBCRYPT_ECCKEY_BLOB; + + typedef struct _BCRYPT_DH_KEY_BLOB { + ULONG dwMagic; + ULONG cbKey; + } BCRYPT_DH_KEY_BLOB,*PBCRYPT_DH_KEY_BLOB; + + typedef struct _BCRYPT_DH_PARAMETER_HEADER { + ULONG cbLength; + ULONG dwMagic; + ULONG cbKeyLength; + } BCRYPT_DH_PARAMETER_HEADER; + + typedef struct _BCRYPT_DSA_KEY_BLOB { + ULONG dwMagic; + ULONG cbKey; + UCHAR Count[4]; + UCHAR Seed[20]; + UCHAR q[20]; + } BCRYPT_DSA_KEY_BLOB,*PBCRYPT_DSA_KEY_BLOB; + + typedef enum { + DSA_HASH_ALGORITHM_SHA1, + DSA_HASH_ALGORITHM_SHA256, + DSA_HASH_ALGORITHM_SHA512 + } HASHALGORITHM_ENUM; + + typedef enum { + DSA_FIPS186_2, + DSA_FIPS186_3 + } DSAFIPSVERSION_ENUM; + typedef struct _BCRYPT_DSA_KEY_BLOB_V2 { + ULONG dwMagic; + ULONG cbKey; + HASHALGORITHM_ENUM hashAlgorithm; + DSAFIPSVERSION_ENUM standardVersion; + ULONG cbSeedLength; + ULONG cbGroupSize; + UCHAR Count[4]; + } BCRYPT_DSA_KEY_BLOB_V2,*PBCRYPT_DSA_KEY_BLOB_V2; + + typedef struct _BCRYPT_KEY_DATA_BLOB_HEADER { + ULONG dwMagic; + ULONG dwVersion; + ULONG cbKeyData; + } BCRYPT_KEY_DATA_BLOB_HEADER,*PBCRYPT_KEY_DATA_BLOB_HEADER; + + typedef struct _BCRYPT_DSA_PARAMETER_HEADER { + ULONG cbLength; + ULONG dwMagic; + ULONG cbKeyLength; + UCHAR Count[4]; + UCHAR Seed[20]; + UCHAR q[20]; + } BCRYPT_DSA_PARAMETER_HEADER; + + typedef struct _BCRYPT_DSA_PARAMETER_HEADER_V2 { + ULONG cbLength; + ULONG dwMagic; + ULONG cbKeyLength; + HASHALGORITHM_ENUM hashAlgorithm; + DSAFIPSVERSION_ENUM standardVersion; + ULONG cbSeedLength; + ULONG cbGroupSize; + UCHAR Count[4]; + } BCRYPT_DSA_PARAMETER_HEADER_V2; + + typedef struct _BCRYPT_ALGORITHM_IDENTIFIER { + LPWSTR pszName; + ULONG dwClass; + ULONG dwFlags; + } BCRYPT_ALGORITHM_IDENTIFIER; + + typedef struct _BCRYPT_PROVIDER_NAME { + LPWSTR pszProviderName; + } BCRYPT_PROVIDER_NAME; + + typedef struct _BCRYPT_INTERFACE_VERSION { + USHORT MajorVersion; + USHORT MinorVersion; + } BCRYPT_INTERFACE_VERSION,*PBCRYPT_INTERFACE_VERSION; + + typedef struct _CRYPT_INTERFACE_REG { + ULONG dwInterface; + ULONG dwFlags; + ULONG cFunctions; + PWSTR *rgpszFunctions; + } CRYPT_INTERFACE_REG,*PCRYPT_INTERFACE_REG; + + typedef struct _CRYPT_IMAGE_REG { + PWSTR pszImage; + ULONG cInterfaces; + PCRYPT_INTERFACE_REG *rgpInterfaces; + } CRYPT_IMAGE_REG,*PCRYPT_IMAGE_REG; + + typedef struct _CRYPT_PROVIDER_REG { + ULONG cAliases; + PWSTR *rgpszAliases; + PCRYPT_IMAGE_REG pUM; + PCRYPT_IMAGE_REG pKM; + } CRYPT_PROVIDER_REG,*PCRYPT_PROVIDER_REG; + + typedef struct _CRYPT_PROVIDERS { + ULONG cProviders; + PWSTR *rgpszProviders; + } CRYPT_PROVIDERS,*PCRYPT_PROVIDERS; + + typedef struct _CRYPT_CONTEXT_CONFIG { + ULONG dwFlags; + ULONG dwReserved; + } CRYPT_CONTEXT_CONFIG,*PCRYPT_CONTEXT_CONFIG; + + typedef struct _CRYPT_CONTEXT_FUNCTION_CONFIG { + ULONG dwFlags; + ULONG dwReserved; + } CRYPT_CONTEXT_FUNCTION_CONFIG,*PCRYPT_CONTEXT_FUNCTION_CONFIG; + + typedef struct _CRYPT_CONTEXTS { + ULONG cContexts; + PWSTR *rgpszContexts; + } CRYPT_CONTEXTS,*PCRYPT_CONTEXTS; + + typedef struct _CRYPT_CONTEXT_FUNCTIONS { + ULONG cFunctions; + PWSTR *rgpszFunctions; + } CRYPT_CONTEXT_FUNCTIONS,*PCRYPT_CONTEXT_FUNCTIONS; + + typedef struct _CRYPT_CONTEXT_FUNCTION_PROVIDERS { + ULONG cProviders; + PWSTR *rgpszProviders; + } CRYPT_CONTEXT_FUNCTION_PROVIDERS,*PCRYPT_CONTEXT_FUNCTION_PROVIDERS; + + typedef struct _CRYPT_PROPERTY_REF { + PWSTR pszProperty; + ULONG cbValue; + PUCHAR pbValue; + } CRYPT_PROPERTY_REF,*PCRYPT_PROPERTY_REF; + + typedef struct _CRYPT_IMAGE_REF { + PWSTR pszImage; + ULONG dwFlags; + } CRYPT_IMAGE_REF,*PCRYPT_IMAGE_REF; + + typedef struct _CRYPT_PROVIDER_REF { + ULONG dwInterface; + PWSTR pszFunction; + PWSTR pszProvider; + ULONG cProperties; + PCRYPT_PROPERTY_REF *rgpProperties; + PCRYPT_IMAGE_REF pUM; + PCRYPT_IMAGE_REF pKM; + } CRYPT_PROVIDER_REF,*PCRYPT_PROVIDER_REF; + + typedef struct _CRYPT_PROVIDER_REFS { + ULONG cProviders; + PCRYPT_PROVIDER_REF *rgpProviders; + } CRYPT_PROVIDER_REFS,*PCRYPT_PROVIDER_REFS; + + NTSTATUS WINAPI BCryptOpenAlgorithmProvider (BCRYPT_ALG_HANDLE *phAlgorithm, LPCWSTR pszAlgId, LPCWSTR pszImplementation, ULONG dwFlags); + NTSTATUS WINAPI BCryptEnumAlgorithms (ULONG dwAlgOperations, ULONG *pAlgCount, BCRYPT_ALGORITHM_IDENTIFIER **ppAlgList, ULONG dwFlags); + NTSTATUS WINAPI BCryptEnumProviders (LPCWSTR pszAlgId, ULONG *pImplCount, BCRYPT_PROVIDER_NAME **ppImplList, ULONG dwFlags); + NTSTATUS WINAPI BCryptGetProperty (BCRYPT_HANDLE hObject, LPCWSTR pszProperty, PUCHAR pbOutput, ULONG cbOutput, ULONG *pcbResult, ULONG dwFlags); + NTSTATUS WINAPI BCryptSetProperty (BCRYPT_HANDLE hObject, LPCWSTR pszProperty, PUCHAR pbInput, ULONG cbInput, ULONG dwFlags); + NTSTATUS WINAPI BCryptCloseAlgorithmProvider (BCRYPT_ALG_HANDLE hAlgorithm, ULONG dwFlags); + VOID WINAPI BCryptFreeBuffer (PVOID pvBuffer); + NTSTATUS WINAPI BCryptGenerateSymmetricKey (BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE *phKey, PUCHAR pbKeyObject, ULONG cbKeyObject, PUCHAR pbSecret, ULONG cbSecret, ULONG dwFlags); + NTSTATUS WINAPI BCryptGenerateKeyPair (BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE *phKey, ULONG dwLength, ULONG dwFlags); + NTSTATUS WINAPI BCryptEncrypt (BCRYPT_KEY_HANDLE hKey, PUCHAR pbInput, ULONG cbInput, VOID *pPaddingInfo, PUCHAR pbIV, ULONG cbIV, PUCHAR pbOutput, ULONG cbOutput, ULONG *pcbResult, ULONG dwFlags); + NTSTATUS WINAPI BCryptDecrypt (BCRYPT_KEY_HANDLE hKey, PUCHAR pbInput, ULONG cbInput, VOID *pPaddingInfo, PUCHAR pbIV, ULONG cbIV, PUCHAR pbOutput, ULONG cbOutput, ULONG *pcbResult, ULONG dwFlags); + NTSTATUS WINAPI BCryptExportKey (BCRYPT_KEY_HANDLE hKey, BCRYPT_KEY_HANDLE hExportKey, LPCWSTR pszBlobType, PUCHAR pbOutput, ULONG cbOutput, ULONG *pcbResult, ULONG dwFlags); + NTSTATUS WINAPI BCryptImportKey (BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE hImportKey, LPCWSTR pszBlobType, BCRYPT_KEY_HANDLE *phKey, PUCHAR pbKeyObject, ULONG cbKeyObject, PUCHAR pbInput, ULONG cbInput, ULONG dwFlags); + NTSTATUS WINAPI BCryptImportKeyPair (BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_KEY_HANDLE hImportKey, LPCWSTR pszBlobType, BCRYPT_KEY_HANDLE *phKey, PUCHAR pbInput, ULONG cbInput, ULONG dwFlags); + NTSTATUS WINAPI BCryptDuplicateKey (BCRYPT_KEY_HANDLE hKey, BCRYPT_KEY_HANDLE *phNewKey, PUCHAR pbKeyObject, ULONG cbKeyObject, ULONG dwFlags); + NTSTATUS WINAPI BCryptFinalizeKeyPair (BCRYPT_KEY_HANDLE hKey, ULONG dwFlags); + NTSTATUS WINAPI BCryptDestroyKey (BCRYPT_KEY_HANDLE hKey); + NTSTATUS WINAPI BCryptDestroySecret (BCRYPT_SECRET_HANDLE hSecret); + NTSTATUS WINAPI BCryptSignHash (BCRYPT_KEY_HANDLE hKey, VOID *pPaddingInfo, PUCHAR pbInput, ULONG cbInput, PUCHAR pbOutput, ULONG cbOutput, ULONG *pcbResult, ULONG dwFlags); + NTSTATUS WINAPI BCryptVerifySignature (BCRYPT_KEY_HANDLE hKey, VOID *pPaddingInfo, PUCHAR pbHash, ULONG cbHash, PUCHAR pbSignature, ULONG cbSignature, ULONG dwFlags); + NTSTATUS WINAPI BCryptSecretAgreement (BCRYPT_KEY_HANDLE hPrivKey, BCRYPT_KEY_HANDLE hPubKey, BCRYPT_SECRET_HANDLE *phAgreedSecret, ULONG dwFlags); + NTSTATUS WINAPI BCryptDeriveKey (BCRYPT_SECRET_HANDLE hSharedSecret, LPCWSTR pwszKDF, BCryptBufferDesc *pParameterList, PUCHAR pbDerivedKey, ULONG cbDerivedKey, ULONG *pcbResult, ULONG dwFlags); + NTSTATUS WINAPI BCryptKeyDerivation (BCRYPT_KEY_HANDLE hKey, BCryptBufferDesc *pParameterList, PUCHAR pbDerivedKey, ULONG cbDerivedKey, ULONG *pcbResult, ULONG dwFlags); + NTSTATUS WINAPI BCryptCreateHash (BCRYPT_ALG_HANDLE hAlgorithm, BCRYPT_HASH_HANDLE *phHash, PUCHAR pbHashObject, ULONG cbHashObject, PUCHAR pbSecret, ULONG cbSecret, ULONG dwFlags); + NTSTATUS WINAPI BCryptHashData (BCRYPT_HASH_HANDLE hHash, PUCHAR pbInput, ULONG cbInput, ULONG dwFlags); + NTSTATUS WINAPI BCryptFinishHash (BCRYPT_HASH_HANDLE hHash, PUCHAR pbOutput, ULONG cbOutput, ULONG dwFlags); + NTSTATUS WINAPI BCryptDuplicateHash (BCRYPT_HASH_HANDLE hHash, BCRYPT_HASH_HANDLE *phNewHash, PUCHAR pbHashObject, ULONG cbHashObject, ULONG dwFlags); + NTSTATUS WINAPI BCryptDestroyHash (BCRYPT_HASH_HANDLE hHash); + NTSTATUS WINAPI BCryptGenRandom (BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer, ULONG cbBuffer, ULONG dwFlags); + NTSTATUS WINAPI BCryptDeriveKeyCapi (BCRYPT_HASH_HANDLE hHash, BCRYPT_ALG_HANDLE hTargetAlg, PUCHAR pbDerivedKey, ULONG cbDerivedKey, ULONG dwFlags); + NTSTATUS WINAPI BCryptDeriveKeyPBKDF2 (BCRYPT_ALG_HANDLE hPrf, PUCHAR pbPassword, ULONG cbPassword, PUCHAR pbSalt, ULONG cbSalt, ULONGLONG cIterations, PUCHAR pbDerivedKey, ULONG cbDerivedKey, ULONG dwFlags); + NTSTATUS WINAPI BCryptResolveProviders (LPCWSTR pszContext, ULONG dwInterface, LPCWSTR pszFunction, LPCWSTR pszProvider, ULONG dwMode, ULONG dwFlags, ULONG *pcbBuffer, PCRYPT_PROVIDER_REFS *ppBuffer); + NTSTATUS WINAPI BCryptGetFipsAlgorithmMode (BOOLEAN *pfEnabled); +#endif +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) +#ifndef KERNEL_MODE_CNG + NTSTATUS WINAPI BCryptQueryProviderRegistration (LPCWSTR pszProvider, ULONG dwMode, ULONG dwInterface, ULONG *pcbBuffer, PCRYPT_PROVIDER_REG *ppBuffer); + NTSTATUS WINAPI BCryptEnumRegisteredProviders (ULONG *pcbBuffer, PCRYPT_PROVIDERS *ppBuffer); + NTSTATUS WINAPI BCryptCreateContext (ULONG dwTable, LPCWSTR pszContext, PCRYPT_CONTEXT_CONFIG pConfig); + NTSTATUS WINAPI BCryptDeleteContext (ULONG dwTable, LPCWSTR pszContext); + NTSTATUS WINAPI BCryptEnumContexts (ULONG dwTable, ULONG *pcbBuffer, PCRYPT_CONTEXTS *ppBuffer); + NTSTATUS WINAPI BCryptConfigureContext (ULONG dwTable, LPCWSTR pszContext, PCRYPT_CONTEXT_CONFIG pConfig); + NTSTATUS WINAPI BCryptQueryContextConfiguration (ULONG dwTable, LPCWSTR pszContext, ULONG *pcbBuffer, PCRYPT_CONTEXT_CONFIG *ppBuffer); + NTSTATUS WINAPI BCryptAddContextFunction (ULONG dwTable, LPCWSTR pszContext, ULONG dwInterface, LPCWSTR pszFunction, ULONG dwPosition); + NTSTATUS WINAPI BCryptRemoveContextFunction (ULONG dwTable, LPCWSTR pszContext, ULONG dwInterface, LPCWSTR pszFunction); + NTSTATUS WINAPI BCryptEnumContextFunctions (ULONG dwTable, LPCWSTR pszContext, ULONG dwInterface, ULONG *pcbBuffer, PCRYPT_CONTEXT_FUNCTIONS *ppBuffer); + NTSTATUS WINAPI BCryptConfigureContextFunction (ULONG dwTable, LPCWSTR pszContext, ULONG dwInterface, LPCWSTR pszFunction, PCRYPT_CONTEXT_FUNCTION_CONFIG pConfig); + NTSTATUS WINAPI BCryptQueryContextFunctionConfiguration (ULONG dwTable, LPCWSTR pszContext, ULONG dwInterface, LPCWSTR pszFunction, ULONG *pcbBuffer, PCRYPT_CONTEXT_FUNCTION_CONFIG *ppBuffer); + NTSTATUS WINAPI BCryptEnumContextFunctionProviders (ULONG dwTable, LPCWSTR pszContext, ULONG dwInterface, LPCWSTR pszFunction, ULONG *pcbBuffer, PCRYPT_CONTEXT_FUNCTION_PROVIDERS *ppBuffer); + NTSTATUS WINAPI BCryptSetContextFunctionProperty (ULONG dwTable, LPCWSTR pszContext, ULONG dwInterface, LPCWSTR pszFunction, LPCWSTR pszProperty, ULONG cbValue, PUCHAR pbValue); + NTSTATUS WINAPI BCryptQueryContextFunctionProperty (ULONG dwTable, LPCWSTR pszContext, ULONG dwInterface, LPCWSTR pszFunction, LPCWSTR pszProperty, ULONG *pcbValue, PUCHAR *ppbValue); + NTSTATUS WINAPI BCryptRegisterConfigChangeNotify (HANDLE *phEvent); + NTSTATUS WINAPI BCryptUnregisterConfigChangeNotify (HANDLE hEvent); +#else + NTSTATUS WINAPI BCryptRegisterConfigChangeNotify (PRKEVENT pEvent); + NTSTATUS WINAPI BCryptUnregisterConfigChangeNotify (PRKEVENT pEvent); + NTSTATUS WINAPI BCryptUnregisterConfigChangeNotify (HANDLE hEvent); +#endif +#endif + +#ifdef __cplusplus +} +#endif +#endif diff --git a/contrib/libarchive/w32_crypto.c b/contrib/libarchive/w32_crypto.c index 3ea2a1b7..6b14408d 100644 --- a/contrib/libarchive/w32_crypto.c +++ b/contrib/libarchive/w32_crypto.c @@ -1,11 +1,11 @@ #include -__CIDENT_RCSID(gr_w32_crypto_c,"$Id: w32_crypto.c,v 1.4 2020/05/04 20:17:24 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_crypto_c,"$Id: w32_crypto.c,v 1.6 2022/05/31 15:21:53 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* * crypt32.dll dynamic loader ... * - * Copyright (c) 2017 - 2020, Adam Young. + * Copyright (c) 2017 - 2022, Adam Young. * All rights reserved. * * This file is part of the GRIEF Editor. @@ -41,7 +41,11 @@ __CIDENT_RCSID(gr_w32_crypto_c,"$Id: w32_crypto.c,v 1.4 2020/05/04 20:17:24 cvsu #include #include +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#include "mingw_bcrypt.h" +#else #include +#endif typedef NTSTATUS (WINAPI * BCryptOpenAlgorithmProvider_t)(BCRYPT_ALG_HANDLE *phAlgorithm, LPCWSTR pszAlgId, LPCWSTR pszImplementation, ULONG dwFlags); typedef NTSTATUS (WINAPI * BCryptEnumAlgorithms_t)(ULONG dwAlgOperations, ULONG *pAlgCount, BCRYPT_ALGORITHM_IDENTIFIER **ppAlgList, ULONG dwFlags); @@ -161,7 +165,8 @@ static HMODULE x_Crypt32dll; static void -load_error() { +load_error() +{ const DWORD rc = GetLastError(); char error[256] = {0}; char message[512] = {0}; @@ -177,7 +182,8 @@ load_error() { static int -load_library() { +load_library() +{ if (0 == x_Crypt32dll) { if (0 != (x_Crypt32dll = LoadLibraryA("crypt32.dll"))) { x_Crypt32dll = (HMODULE)-1; @@ -191,17 +197,23 @@ load_library() { static NTSTATUS WINAPI -BCrypt_STATUS_NOT_SUPPORTED() { +BCrypt_STATUS_NOT_SUPPORTED() +{ return STATUS_NOT_SUPPORTED; } static VOID WINAPI -BCrypt_VOID() { +BCrypt_VOID() +{ return; } +#if defined(__MINGW32__) +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif + #define RESOLVE_CRYPT32_API(__name) \ if (0 == x_pfn##__name) { \ if (load_library()) { \ @@ -255,8 +267,8 @@ NTSTATUS WINAPI BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE hAlgorithm, ULONG (hAlgorithm, dwFlags); } -VOID WINAPI BCryptFreeBuffer(PVOID pvBuffer) { - RESOLVE_CRYPT32_API_VOID(BCryptFreeBuffer); +VOID WINAPI BCryptFreeBuffer(PVOID pvBuffer) { + RESOLVE_CRYPT32_API_VOID(BCryptFreeBuffer) (pvBuffer); } @@ -473,6 +485,5 @@ NTSTATUS WINAPI BCryptGetFipsAlgorithmMode(BOOLEAN *pfEnabled ) { #endif //_WIN32 - /*end*/ diff --git a/contrib/libbzip2/.cvsignore b/contrib/libbzip2/.cvsignore index 8a4ee951..a9deeb00 100644 --- a/contrib/libbzip2/.cvsignore +++ b/contrib/libbzip2/.cvsignore @@ -1,3 +1,5 @@ +bzip2-1.0.6 +bzip2-1.0.8 Makefile *.err .unpacked.* diff --git a/contrib/libbzip2/.gitignore b/contrib/libbzip2/.gitignore index a173a12f..a32143cc 100644 --- a/contrib/libbzip2/.gitignore +++ b/contrib/libbzip2/.gitignore @@ -1 +1,3 @@ -bzip2-1.0.6/ \ No newline at end of file +bzip2-1.0.6/ +bzip2-1.0.8/ + diff --git a/contrib/libbzip2/ChangeLog b/contrib/libbzip2/ChangeLog index f4178c80..cbeb4c0f 100644 --- a/contrib/libbzip2/ChangeLog +++ b/contrib/libbzip2/ChangeLog @@ -1,21 +1,31 @@ -*- encoding: utf-8; -*- +Sun May 29 15:36:41 2022 adamy + + * imported 1.0.8 + + - bzip2.h modifications + + - #if defined(_WIN32) + + #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)) \ + && !defined(LIBBZIP2_STATIC) + Fri Jan 27 16:48:25 2017 adamy * imported 1.0.6 - bzip2.h modifications - #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && !defined(LIBBZIP2_STATIC) - : - : - # ifdef __LIBBZIP2_BUILD - # define BZ_API(func) WINAPI func - # define BZ_EXTERN __declspec(dllexport) - # else - # define BZ_API(func) WINAPI func - # define BZ_EXTERN __declspec(dllimport) - # endif + #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && !defined(LIBBZIP2_STATIC) + : + : + # ifdef __LIBBZIP2_BUILD + # define BZ_API(func) WINAPI func + # define BZ_EXTERN __declspec(dllexport) + # else + # define BZ_API(func) WINAPI func + # define BZ_EXTERN __declspec(dllimport) + # endif /* * Local Variables: *** diff --git a/contrib/libbzip2/Makefile.in b/contrib/libbzip2/Makefile.in index 4ea0120b..d5f7a1b4 100644 --- a/contrib/libbzip2/Makefile.in +++ b/contrib/libbzip2/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.9 2020/06/18 20:35:15 cvsuser Exp $ +# $Id: Makefile.in,v 1.13 2022/06/01 14:21:18 cvsuser Exp $ # libbz2 makefile # # @@ -50,7 +50,11 @@ D_LIB= $(ROOT)/lib@TOOLCHAINEXT@/$(BUILD_TYPE) XFLAGS= CFLAGS= @CFLAGS@ +ifeq ("gcc","@CC@") +CWARN= $(filter-out -Wshadow -Wmissing-prototypes -Wsign-compare -Wimplicit-fallthrough, @CWARN@) -Wno-sign-compare -Wno-implicit-fallthrough -Wno-unused-parameter +else CWARN= @CWARN@ +endif CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ LDDEBUG= @LDDEBUG@ @@ -83,10 +87,11 @@ RMDFLAGS= -rf BZ2LIB= $(D_LIB)/$(LP)bz2_static$(A) BZ2DLL= $(D_LIB)/$(LP)bz2.la -VERSION= 1.0.6 +VERSION= 1.0.8 VERSIONSPEC= $(subst .,:,$(VERSION)) -BZ2PACKED= bzip2-1.0.6.gr.tgz -BZ2SRC= ./bzip2-1.0.6 +BZ2PACKED= bzip2-$(VERSION).gr.tgz +BZ2SRC= ./bzip2-$(VERSION) + VPATH= $(BZ2SRC) LIBOBJS=\ @@ -103,8 +108,8 @@ LIBOBJS=\ DLLOBJS=\ $(subst $(O),.lo,$(LIBOBJS)) -ifeq ("yes","@ISWIN32@") -ifeq ("mingw32","@build_os@") +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) DLLOBJS+= $(D_OBJ)/libbz2_res.o else DLLOBJS+= $(D_OBJ)/libbz2.res diff --git a/contrib/libbzip2/bzip2-1.0.8.gr.tgz b/contrib/libbzip2/bzip2-1.0.8.gr.tgz new file mode 100644 index 00000000..7eb25041 Binary files /dev/null and b/contrib/libbzip2/bzip2-1.0.8.gr.tgz differ diff --git a/contrib/libbzip2/libbz2.rc b/contrib/libbzip2/libbz2.rc index 121e22b4..f1072e1c 100644 --- a/contrib/libbzip2/libbz2.rc +++ b/contrib/libbzip2/libbz2.rc @@ -1,5 +1,5 @@ // -// libbz2 resource +// libbz2 resource // #include @@ -7,8 +7,8 @@ #define IDR_VERSION1 1 IDR_VERSION1 VERSIONINFO //MOVEABLE IMPURE LOADONCALL DISCARDABLE - FILEVERSION 1,0,6,0 - PRODUCTVERSION 1,0,6,0 + FILEVERSION 1,0,8,0 + PRODUCTVERSION 1,0,8,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS 0 FILEOS VOS_DOS_WINDOWS32 @@ -21,12 +21,12 @@ BEGIN BEGIN VALUE "FileDescription", "libbzip2: library for data compression\0" - VALUE "FileVersion", "1.0.6\0" + VALUE "FileVersion", "1.0.8\0" VALUE "InternalName", "libbzip2\0" VALUE "OriginalFilename", "libbz.dll\0" VALUE "ProductName", "libbz.dll\0" VALUE "Comments", "\0" - VALUE "LegalCopyright", "(C) 1996-2010 Julian R Seward, BSD style license\0" + VALUE "LegalCopyright", "(C) 1996-2019 Julian R Seward, BSD style license\0" END END BLOCK "VarFileInfo" diff --git a/contrib/libbzip2/libbzip2.c b/contrib/libbzip2/libbzip2.c index d821760a..f63db00b 100644 --- a/contrib/libbzip2/libbzip2.c +++ b/contrib/libbzip2/libbzip2.c @@ -2,7 +2,7 @@ /* * libbzip2 dllmain implementation * - * Copyright (c) 2012-2018 Adam Young. + * Copyright (c) 2012-2022 Adam Young. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,6 +30,7 @@ #include +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved); BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) { diff --git a/contrib/libguess/dllmain.c b/contrib/libguess/dllmain.c index 047407f8..7ef072c9 100644 --- a/contrib/libguess/dllmain.c +++ b/contrib/libguess/dllmain.c @@ -1,9 +1,9 @@ /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: dllmain.c,v 1.3 2015/03/01 02:46:47 cvsuser Exp $ +/* $Id: dllmain.c,v 1.4 2022/06/02 04:00:55 cvsuser Exp $ * * libguess - dllmain * - * Copyright (c) 2012-2015 Adam Young. + * Copyright (c) 2012-2022 Adam Young. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ #include #include +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved); BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) { @@ -51,6 +52,7 @@ DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) } +extern void trace_log(const char *fmt, ...); void trace_log(const char *fmt, ...) { diff --git a/contrib/libiconv/Makefile.in b/contrib/libiconv/Makefile.in index 0bf01b35..6f6e3f1a 100644 --- a/contrib/libiconv/Makefile.in +++ b/contrib/libiconv/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.11 2020/06/18 20:35:15 cvsuser Exp $ +# $Id: Makefile.in,v 1.12 2022/06/02 04:00:10 cvsuser Exp $ # libiconv/iconv makefile # # @@ -132,7 +132,7 @@ $(ICONVDLL): CEXTRA += -D__LIBICONV_BUILD -D_WIN32 -D_WIN32_WINNT=0X601 $(ICONVDLL): MAPFILE=$(basename $@).map $(ICONVDLL): $(DLLOBJS) $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $^ -version-number $(VERSIONSPEC) \ - -rpath $(D_LIB) -bindir $(D_BIN) $(LDLIBS) libcitrus$(A) @LDMAPFILE@ + -rpath $(D_LIB) -bindir $(D_BIN) libcitrus$(A) $(LDLIBS) @LDMAPFILE@ .PHONY: installinc installcfg installinc: ../include/.created diff --git a/contrib/libiconv/dllmain.c b/contrib/libiconv/dllmain.c index ea30aea4..9fdc379f 100644 --- a/contrib/libiconv/dllmain.c +++ b/contrib/libiconv/dllmain.c @@ -1,9 +1,9 @@ /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: dllmain.c,v 1.4 2015/03/01 02:58:51 cvsuser Exp $ +/* $Id: dllmain.c,v 1.5 2022/06/02 03:59:51 cvsuser Exp $ * * win32 - dllmain * - * Copyright (c) 2012-2015 Adam Young. + * Copyright (c) 2012-2022 Adam Young. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +35,7 @@ #include #include +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved); BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) { @@ -52,6 +53,7 @@ DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) } +extern void trace_log(const char *fmt, ...); void trace_log(const char *fmt, ...) { diff --git a/contrib/libiconv/iconv/iconv.c b/contrib/libiconv/iconv/iconv.c index 6f931a8a..b9e81168 100644 --- a/contrib/libiconv/iconv/iconv.c +++ b/contrib/libiconv/iconv/iconv.c @@ -70,6 +70,7 @@ usage(void) exit(1); } + /* * qsort() helper function */ @@ -84,6 +85,9 @@ scmp(const void *v1, const void *v2) #if defined(WIN32) /*DLL binding*/ +static const char * local_nl_langinfo(int elm); +#define nl_langinfo(__a) local_nl_langinfo(__a) + #define __ICONV_ERRNO() errno = iconv_errno(); #else #define __ICONV_ERRNO() @@ -226,6 +230,7 @@ main(int argc, char **argv) #if defined(WIN32) case 'h': help(); + break; #endif default: usage(); @@ -264,8 +269,8 @@ main(int argc, char **argv) #if defined(WIN32) -const char * -nl_langinfo(int elm) +static const char * +local_nl_langinfo(int elm) { if (CODESET == elm) return "UTF-8"; /*TODO*/ diff --git a/contrib/libiconv/namespace.h b/contrib/libiconv/namespace.h index b32602e5..5e9a6e90 100644 --- a/contrib/libiconv/namespace.h +++ b/contrib/libiconv/namespace.h @@ -1,8 +1,8 @@ -/* $Id: namespace.h,v 1.5 2017/01/23 00:22:37 cvsuser Exp $ +/* $Id: namespace.h,v 1.7 2022/06/02 11:11:25 cvsuser Exp $ * * libiconv * - * Copyright (c) 2012-2015 Adam Young. + * Copyright (c) 2012-2022 Adam Young. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -70,8 +70,10 @@ #define strdup _strdup #endif -#if defined(_MSC_VER) -#define LC_MESSAGES (LC_MAX + 1) +#if defined(_MSC_VER) || \ + defined(__MINGW32__) +#define LC_MESSAGES (LC_MAX + 1) /*XXX*/ #endif /*end*/ + diff --git a/contrib/libintl/libintl.c b/contrib/libintl/libintl.c index b4a882bf..6d4e9ec3 100644 --- a/contrib/libintl/libintl.c +++ b/contrib/libintl/libintl.c @@ -2,7 +2,7 @@ /* * libintl dllmain implementation * - * Copyright (c) 2012-2015 Adam Young. + * Copyright (c) 2012-2022 Adam Young. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ #include #include +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved); BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) { diff --git a/contrib/libintl/namespace.h b/contrib/libintl/namespace.h index fe4b6629..b360dbd0 100644 --- a/contrib/libintl/namespace.h +++ b/contrib/libintl/namespace.h @@ -48,10 +48,10 @@ extern char * libintl_strsep(char **stringp, const char *delim); #define strsep(__a,__b) libintl_strsep(__a,__b) #endif -#if defined(_MSC_VER) -#define LC_MESSAGES (LC_MAX + 1) +#if defined(_MSC_VER) || \ + defined(__MINGW32__) +#define LC_MESSAGES (LC_MAX + 1) /*XXX*/ #endif /*end*/ - diff --git a/contrib/liblzma/ChangeLog b/contrib/liblzma/ChangeLog index ea34c92a..c9734b6e 100644 --- a/contrib/liblzma/ChangeLog +++ b/contrib/liblzma/ChangeLog @@ -1,11 +1,17 @@ -*- encoding: utf-8; -*- +Fri May 27 10:00:20 2022 adamy + + * xz-5.2.3 + + * sysdefs.h - __USE_MINGW_ANSI_STDIO removed (defunct) + Thu Jun 3 23:41:44 2020 adamy * xz-5.2.3 - mytime.c, gettimeofday() local implementation under win32 - + /* * Local Variables: *** * mode: changelog *** diff --git a/contrib/liblzma/Makefile.in b/contrib/liblzma/Makefile.in index 3ffd04e1..c29990ee 100644 --- a/contrib/liblzma/Makefile.in +++ b/contrib/liblzma/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.9 2022/03/22 04:10:50 cvsuser Exp $ +# $Id: Makefile.in,v 1.12 2022/06/02 07:40:16 cvsuser Exp $ # liblzma makefile and grxz # # @@ -51,7 +51,12 @@ D_LIB= $(ROOT)/lib@TOOLCHAINEXT@/$(BUILD_TYPE) XFLAGS= CFLAGS= @CFLAGS@ +ifeq ("gcc","@CC@") +CWARN= $(filter-out -Wshadow -Wmissing-prototypes -Wsign-compare -Wimplicit-fallthrough, @CWARN@) +CWARN+= -Wno-sign-compare -Wno-implicit-fallthrough -Wno-type-limits -Wno-unused-but-set-variable -Wno-implicit-function-declaration +else CWARN= @CWARN@ +endif CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ LDDEBUG= @LDDEBUG@ @@ -86,8 +91,13 @@ LZMALIB= $(D_LIB)/$(LP)lzma_static$(A) LZMADLL= $(D_LIB)/$(LP)lzma.la LZMAUTIL= $(D_BIN)/grxz$(E) +#ifeq ("gcc","@CC@") +#VERSION= 5.2.5 +#LZMAPACKED= xz-$(VERSION).tgz +#else VERSION= 5.2.3 LZMAPACKED= xz-$(VERSION).gr.tgz +#endif LZMASRC= ./xz-$(VERSION)/src LIBLZMASRC= ./xz-$(VERSION)/src/liblzma LIBINC= \ @@ -242,6 +252,8 @@ else ifeq ("@TOOLCHAIN@","vs150") LZMA=yes else ifeq ("@TOOLCHAIN@","vs140") LZMA=yes +else ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) +LZMA=yes endif .PHONY: build release debug @@ -272,7 +284,7 @@ $(LZMADLL): $(DLLOBJS) liblzma.sym -rpath $(D_LIB) -bindir $(D_BIN) -export-symbols=liblzma.sym $(LDLIBS) @LDMAPFILE@ $(LZMAUTIL): $(UTILOBJS) - $(CC) $(LDFLAGS) $^ -o $@ $(D_LIB)/liblzma$(A) $(LDLIBS) + $(LIBTOOL) --mode=link $(CC) $(CC) $(LDFLAGS) $^ -o $@ $(D_LIB)/liblzma$(A) $(LDLIBS) source: .unpacked.$(VERSION) $(MAKE) unpacked diff --git a/contrib/liblzma/config.h b/contrib/liblzma/config.h index 71af24f0..d6ac2b55 100644 --- a/contrib/liblzma/config.h +++ b/contrib/liblzma/config.h @@ -1,5 +1,5 @@ -#ifndef CONFIG_H_INCLUDED -#define CONFIG_H_INCLUDED +#ifndef XZ_CONFIG_H_INCLUDED +#define XZ_CONFIG_H_INCLUDED /* * liblzma ... */ @@ -15,37 +15,38 @@ #include <../contrib_config.h> #if !defined(WINDOWS_MEAN_AND_LEAN) -#define WINDOWS_MEAN_AND_LEAN +#define WINDOWS_MEAN_AND_LEAN #endif #include -#undef HAVE_UTIME_H -#undef HAVE_SYS_UTIME_H +#undef HAVE_UTIME_H +#undef HAVE_SYS_UTIME_H #if (defined(_WIN32) || defined(WIN32)) && defined(__MINGW32__) -#undef HAVE_GETOPT_H +#undef HAVE_GETOPT_H #endif #if defined(_MSC_VER) #include #include #define inline __inline -# if (_MSC_VER >= _MSC_VER_2013) -# define restrict __restrict -# else -# define restrict -# endif +# if (_MSC_VER >= _MSC_VER_2013) +# define restrict __restrict +# else +# define restrict +# endif #elif defined(__WATCOMC__) -#define restrict __restrict -#endif +# define restrict __restrict #endif #include #ifndef SSIZE_MAX #define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) +#endif -#define ASSUME_RAM 1000 //1GB +/* How many MiB of RAM to assume if the real amount cannot be determined. */ +#define ASSUME_RAM 1000 /*1GB*/ #define HAVE_ENCODERS #define HAVE_ENCODER_LZMA1 @@ -69,5 +70,4 @@ #define HAVE_DECODER_SPARC #define HAVE_DECODER_DELTA -#endif /*CONFIG_H_INCLUDED*/ - +#endif /*XZ_CONFIG_H_INCLUDED*/ diff --git a/contrib/liblzma/makelib.def b/contrib/liblzma/makelib.def index d9dcb147..50dde44e 100644 --- a/contrib/liblzma/makelib.def +++ b/contrib/liblzma/makelib.def @@ -1,7 +1,7 @@ -# $Id: makelib.def,v 1.3 2020/06/20 01:56:46 cvsuser Exp $ +# $Id: makelib.def,v 1.4 2022/06/02 04:01:18 cvsuser Exp $ # win32 makelib configuration # -toolchain=vc1900 +toolchain=mingw,vc1900 inc=../include lbl=LIBLZMA lib=liblzma.lib diff --git a/contrib/liblzma/xz-5.2.3.gr.tgz b/contrib/liblzma/xz-5.2.3.gr.tgz index 2870c367..4c6aa5e1 100644 Binary files a/contrib/liblzma/xz-5.2.3.gr.tgz and b/contrib/liblzma/xz-5.2.3.gr.tgz differ diff --git a/contrib/libmagic/Makefile.in b/contrib/libmagic/Makefile.in index 5e5c65c3..e7598388 100644 --- a/contrib/libmagic/Makefile.in +++ b/contrib/libmagic/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.16 2020/06/18 20:35:16 cvsuser Exp $ +# $Id: Makefile.in,v 1.18 2022/06/01 14:21:18 cvsuser Exp $ # libmagic makefile # # @@ -59,12 +59,9 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../include -I../../libw32 -##endif CEXTRA= @DEFS@ -ifeq ("yes","@ISWIN32@") +ifeq ("win32","@build_os@") CEXTRA+= -DWIN32 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE endif @@ -77,9 +74,6 @@ LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif LDLIBS= -L$(D_LIB) $(D_LIB)/$(LP)regex$(A) @LIBS@ @LIBM@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif ARFLAGS= rcv RMFLAGS= -f @@ -179,7 +173,7 @@ $(MAGICDLL): $(DLLOBJS) -rpath $(D_LIB) -bindir $(D_BIN) $^ $(LDLIBS) @LDMAPFILE@ $(MAGICUTIL): $(UTILOBJS) - $(CC) $(LDFLAGS) $^ -o $@ $(D_LIB)/libmagic$(A) $(LDLIBS) + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) $^ -o $@ $(D_LIB)/libmagic$(A) $(LDLIBS) $(MAGICDB): magic.mgc @echo publishing magicdb $(MAGICDB) ... diff --git a/contrib/libssh2/Makefile.in b/contrib/libssh2/Makefile.in index e84448cb..25837dce 100644 --- a/contrib/libssh2/Makefile.in +++ b/contrib/libssh2/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.1 2020/06/18 19:57:47 cvsuser Exp $ +# $Id: Makefile.in,v 1.3 2022/06/13 14:07:52 cvsuser Exp $ # libssh2 makefile. # # -# Copyright (c) 2015 - 2020, Adam Young. +# Copyright (c) 2015 - 2022, Adam Young. # All rights reserved. # # ==end== @@ -64,10 +64,6 @@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ CEXTRA= @DEFS@ -ifeq ("yes","@ISWIN32@") -CEXTRA+= -DWIN32 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -endif - ifeq ("$(BUILD_TYPE)","release") CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDRELEASE) @LDFLAGS@ @@ -88,7 +84,7 @@ RMFLAGS= -f SSH2LIB= $(D_LIB)/$(LP)ssh2_static$(A) SSH2DLL= $(D_LIB)/$(LP)ssh2.la -VERSION= 1.9.0 +VERSION= 1.10.0 VERSIONSPEC= $(subst .,:,$(VERSION)) VERPACKED= libssh2-$(VERSION).gr.tgz @@ -128,20 +124,28 @@ CSOURCES=\ CSOURCES+=\ blowfish.c bcrypt_pbkdf.c +#+1.10.0 +CSOURCES+=\ + agent_win.c + LIBOBJS=\ $(addprefix $(D_OBJ)/,$(subst .c,$(O),$(CSOURCES))) DLLOBJS=\ $(subst $(O),.lo,$(LIBOBJS)) -ifeq ("mingw32","@build_os@") + +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) DLLOBJS+= $(D_OBJ)/libssh2_res.o -else ifeq ("win32","@build_os@") +else DLLOBJS+= $(D_OBJ)/libssh2.res endif +endif LIBS= $(SSH2LIB) DLLS= $(SSH2DLL) TSKS= +INSTALLED= ######################################################################################### # Rules @@ -158,6 +162,7 @@ debug: ifdef SSH2DEBUG # enable LIBSSH2 run-time diagnostics CEXTRA += -DLIBSSH2DEBUG endif +CEXTRA += -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE $(SSH2LIB): CEXTRA += -DLIBSSH2_STATIC $(SSH2LIB): $(LIBOBJS) @@ -165,6 +170,7 @@ $(SSH2LIB): $(LIBOBJS) $(AR) $(ARFLAGS) $@ $^ $(RANLIB) $@ +INSTALLED+= $(D_BIN)/libssh2.$(VERSION).dll $(SSH2DLL): CEXTRA += -DLIBSSH2_DYANMIC -D_WINDLL $(SSH2DLL): $(DLLOBJS) $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ -version-number $(VERSIONSPEC) \ @@ -195,9 +201,9 @@ installinc: ../include/.created clean: @echo $(BUILD_TYPE) clean -@$(LIBTOOL) --mode=clean $(RM) $(DLLS) $(DLLOBJS) >/dev/null 2>&1 - -@$(RM) $(RMFLAGS) $(BAK) $(TSKS) $(LIBS) $(CLEAN) $(XCLEAN) >/dev/null 2>&1 + -@$(RM) $(RMFLAGS) $(BAK) $(TSKS) $(INSTALLED) $(LIBS) $(CLEAN) $(XCLEAN) >/dev/null 2>&1 -@$(RM) $(LIBOBJS) >/dev/null 2>&1 - -@$(RM) ../include/libssh2*.h >/dev/null 2>&1 + -@$(RM) ../include/libssh2/*.h >/dev/null 2>&1 $(D_OBJ)/%$(O): %.c $(CC) $(CFLAGS) -o $@ -c $< diff --git a/contrib/libssh2/libssh2-1.10.0.gr.tgz b/contrib/libssh2/libssh2-1.10.0.gr.tgz new file mode 100644 index 00000000..8dece8c3 Binary files /dev/null and b/contrib/libssh2/libssh2-1.10.0.gr.tgz differ diff --git a/contrib/libssh2/readme_1_10_0.txt b/contrib/libssh2/readme_1_10_0.txt new file mode 100644 index 00000000..859af3cc --- /dev/null +++ b/contrib/libssh2/readme_1_10_0.txt @@ -0,0 +1,32 @@ + + Source: libssh2 1.10.0, code changes + + Makefile.in: + + + agent_win$(O) + + + src\libssh2_priv.h: + + #include + + #include //UINT_MAX + + + src\misc.c: + + #ifdef WIN32 + + #if defined(__WATCOMC__) + + static void *safememset(void *a, int b, size_t c) { + + return memset(a, b, c); + + } + + static void * (__watcall * const volatile memset_libssh)(void *, int, size_t) = + + safememset; + + #else + static void * (__cdecl * const volatile memset_libssh)(void *, int, size_t) = + memset; + + #endif + #else + static void * (* const volatile memset_libssh)(void *, int, size_t) = memset; + #endif + + --------- diff --git a/contrib/libz/Makefile.in b/contrib/libz/Makefile.in index b8e39b85..5d41df48 100644 --- a/contrib/libz/Makefile.in +++ b/contrib/libz/Makefile.in @@ -1,6 +1,6 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.17 2020/06/20 01:58:03 cvsuser Exp $ -# libarchive makefile +# $Id: Makefile.in,v 1.20 2022/06/13 12:58:06 cvsuser Exp $ +# libz makefile # # # @@ -51,7 +51,11 @@ D_OBJ= $(ROOT)/objects@TOOLCHAINEXT@/$(BUILD_TYPE)/libz XFLAGS= CFLAGS= @CFLAGS@ +ifeq ("gcc","@CC@") +CWARN= $(filter-out -Wshadow -Wmissing-prototypes -Wsign-compare -Wimplicit-fallthrough, @CWARN@) -Wno-sign-compare -Wno-implicit-fallthrough +else CWARN= @CWARN@ +endif CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ CXXFLAGS= @CXXFLAGS@ @@ -124,16 +128,19 @@ LIBOBJS=\ DLLOBJS=\ $(subst $(O),.lo,$(LIBOBJS)) -ifeq ("mingw32","@build_os@") + +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) DLLOBJS+= $(D_OBJ)/zlib_res.o -else ifeq ("win32","@build_os@") +else DLLOBJS+= $(D_OBJ)/zlib.res endif +endif OBJS= $(LIBOBJS) $(DLLOBJS) LIBS= $(ZLIB) $(ZDLL) TSKS= - +INSTALLED= ######################################################################################### # Rules @@ -155,6 +162,7 @@ $(ZLIB): $(LIBOBJS) $(AR) $(ARFLAGS) $@ $^ $(RANLIB) $@ +INSTALLED+= $(D_BIN)/libz.$(VERSION).dll $(ZDLL): CEXTRA += -DZLIB_DLL ifeq ("yes","@ISWIN32@") $(ZDLL): ZDEF = -export-symbols $(ZSRC)/win32/zlib.def --export-fastcall @@ -188,7 +196,7 @@ installinc: ../include/.created clean: @echo $(BUILD_TYPE) clean -@$(LIBTOOL) --mode=clean $(RM) $(ZDLL) $(DLLOBJS) >/dev/null 2>&1 - -@$(RM) $(RMFLAGS) $(BAK) $(TSKS) $(LIBS) $(CLEAN) $(XCLEAN) >/dev/null 2>&1 + -@$(RM) $(RMFLAGS) $(BAK) $(TSKS) $(INSTALLED) $(LIBS) $(CLEAN) $(XCLEAN) >/dev/null 2>&1 -@$(RM) $(LIBOBJS) >/dev/null 2>&1 $(D_OBJ)/%$(O): %.c diff --git a/contrib/makedepend/Makefile.in b/contrib/makedepend/Makefile.in index c410bb4a..d3350e67 100644 --- a/contrib/makedepend/Makefile.in +++ b/contrib/makedepend/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.9 2022/03/21 17:12:44 cvsuser Exp $ +# $Id: Makefile.in,v 1.10 2022/03/24 02:59:45 cvsuser Exp $ # makedepend makefile # # @@ -26,7 +26,8 @@ CC= @CC@ AR= @AR@ RANLIB= @RANLIB@ RM= @RM@ - +PERL= @PERL@ +LIBTOOL= @LIBTOOL@ # Configuration @@ -114,7 +115,7 @@ object: $(D_OBJ)/.created $(D_BIN)/makedepend$(E): MAPFILE=$(basename $@).map $(D_BIN)/makedepend$(E): $(MAKEDEPENDOBJS) - $(CC) $(LDFLAGS) -o $@ $(MAKEDEPENDOBJS) $(LDLIBS) @LDMAPFILE@ + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(MAKEDEPENDOBJS) $(LDLIBS) @LDMAPFILE@ %/.created: -@mkdir $(@D) @@ -128,4 +129,3 @@ $(D_OBJ)/%$(O): %.c $(CC) $(CFLAGS) -o $@ -c $< #end - diff --git a/contrib/makedepend/makedepend-1.0.5/README b/contrib/makedepend/makedepend-1.0.5/README index 4376dcd0..78948f3e 100644 --- a/contrib/makedepend/makedepend-1.0.5/README +++ b/contrib/makedepend/makedepend-1.0.5/README @@ -12,7 +12,8 @@ Please submit bug reports to the Xorg bugzilla: The master development code repository can be found at: git://anongit.freedesktop.org/git/xorg/util/makedepend - + + https://gitlab.freedesktop.org/xorg/util/makedepend [2022] http://cgit.freedesktop.org/xorg/util/makedepend For patch submission instructions, see: diff --git a/contrib/makedepend/makedepend-1.0.5/def.h b/contrib/makedepend/makedepend-1.0.5/def.h index 1e155114..824b3ab9 100644 --- a/contrib/makedepend/makedepend-1.0.5/def.h +++ b/contrib/makedepend/makedepend-1.0.5/def.h @@ -1,7 +1,7 @@ /* Copyright (c) 1993, 1994, 1998 The Open Group. -Copyright (c) 2012-2018, Adam Young +Copyright (c) 2012-2022, Adam Young Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that diff --git a/contrib/makedepend/makedepend-1.0.5/ifparser.c b/contrib/makedepend/makedepend-1.0.5/ifparser.c index 212044b3..a67ef6eb 100644 --- a/contrib/makedepend/makedepend-1.0.5/ifparser.c +++ b/contrib/makedepend/makedepend-1.0.5/ifparser.c @@ -296,10 +296,10 @@ parse_product (IfParser *g, const char *cp, long *valp) case '/': DO (cp = parse_product (g, cp + 1, &rightval)); - if (rightval) + if (rightval) *valp = (*valp / rightval); - else - *valp = LONG_MAX; + else + *valp = LONG_MAX; break; case '%': diff --git a/contrib/makedepend/makedepend-1.0.5/main.c b/contrib/makedepend/makedepend-1.0.5/main.c index 232b70a4..00cf5c2a 100644 --- a/contrib/makedepend/makedepend-1.0.5/main.c +++ b/contrib/makedepend/makedepend-1.0.5/main.c @@ -1,7 +1,7 @@ /* Copyright (c) 1993, 1994, 1998 The Open Group -Copyright (c) 2012-2018, Adam Young. +Copyright (c) 2012-2022, Adam Young. Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that @@ -273,7 +273,7 @@ main(int argc, char *argv[]) argc = 1; for (p = args; argc < nargc; p += strlen(p) + 1) if (*p) nargv[argc++] = p; - argv = nargv; + argv = nargv; } for(argc--, argv++; argc; argc--, argv++) { @@ -688,15 +688,15 @@ main(int argc, char *argv[]) /* * normalize slashes */ - { register char **pp, *p; + { register char **pp; for (pp = (char **)includedirs; *pp; ++pp) { - p = *pp; + char *d = *pp; do { - if ((p = strchr(p, '\\')) != NULL) { - *p = '/'; + if ((d = strchr(d, '\\')) != NULL) { + *d = '/'; } - } while (p && *p); + } while (d && *d); } } @@ -705,17 +705,17 @@ main(int argc, char *argv[]) * simple -MM detection. */ if (MFLAG_NOSYSTEM & mflags) { - register char **pp, *p; + register char **pp; register int len; for (pp = (char **)systemdirs; *pp; ++pp) { len = strlen(*pp); - if ( (*pp)[ len-1 ] != '/' ) { - p = malloc(len+2); - (void) strcpy(p, (const char *)*pp); - p[ len ] = '/', p[ len+1 ] = '\0'; - debug(1, ("conv -Y%s\n", p)); - *pp = p; + if ((*pp)[ len-1 ] != '/' ) { + char *d = malloc(len + 2); + (void) strcpy(d, (const char *)*pp); + d[ len ] = '/', d[ len+1 ] = '\0'; + debug(1, ("conv -Y%s\n", d)); + *pp = d; } } } @@ -809,13 +809,13 @@ main(int argc, char *argv[]) static void /*APY*/ -profile(const char *name) +profile(const char *profilename) { char buf[ BUFSIZ ]; FILE *fdin; - if (NULL == (fdin = fopen(name, "r"))) { - fatalerr("cannot open \"%s\"\n", name); + if (NULL == (fdin = fopen(profilename, "r"))) { + fatalerr("cannot open \"%s\"\n", profilename); } while (fgets(buf, BUFSIZ, fdin)) { @@ -1165,7 +1165,7 @@ redirect(const char *line, const char *makefile) if (verbose) warning("Creating dependencies file \"%s\"", makefile); st.st_mode = 0666; - goto create; /* APY, autogenerate */ + goto create; /* autogenerate */ } fatalerr("\"%s\" is not present\n", makefile); } @@ -1493,11 +1493,11 @@ static void /*APY*/ copyright(void) { static const char *copytext[] = { - "makedepend-1.0.5 (modified)", + "makedepend-1.0.6 (modified)", "", "", " Copyright (c) 1993, 1994, 1998 The Open Group", - " Copyright (c) 2012 - 2018, Adam Young.", + " Copyright (c) 2012 - 2022, Adam Young.", "", " Permission to use, copy, modify, distribute, and sell this software and its", " documentation for any purpose is hereby granted without fee, provided that", diff --git a/contrib/makedepend/makedepend-1.0.5/parse.c b/contrib/makedepend/makedepend-1.0.5/parse.c index 2ead966f..743a459e 100644 --- a/contrib/makedepend/makedepend-1.0.5/parse.c +++ b/contrib/makedepend/makedepend-1.0.5/parse.c @@ -263,8 +263,10 @@ fdefined(const char *symbol, struct inclist *file, struct inclist **srcfile) debug(2,("Looking for %s in %s\n", symbol, file->i_file)); file->i_flags |= DEFCHECKED; if ((val = slookup(symbol, file))) + { debug(1,("%s defined in %s as %s\n", symbol, file->i_file, (*val)->s_value)); + } if (val == NULL && file->i_list) { for (ip = file->i_list, i=0; i < file->i_listlen; i++, ip++) @@ -542,7 +544,7 @@ int find_includes(struct filepointer *filep, struct inclist *file, struct inclist *file_red, int recursion, boolean failOK) { - struct inclist *inclistp; + struct inclist *t_inclistp; const char **includedirsp; register char *line; register int type; @@ -614,9 +616,11 @@ find_includes(struct filepointer *filep, struct inclist *file, case ELIF: if (!recursion) gobble(filep, file, file_red); + /*FALLTHRU*/ case ENDIF: if (recursion) return(type); + /*FALLTHRU*/ case DEFINE: define(line, file); break; @@ -635,12 +639,12 @@ find_includes(struct filepointer *filep, struct inclist *file, case INCLUDEDOT: case INCLUDENEXT: case INCLUDENEXTDOT: - inclistp = inclistnext; + t_inclistp = inclistnext; includedirsp = includedirsnext; debug(2,("%s, reading %s, includes %s\n", file_red->i_file, file->i_file, line)); add_include(filep, file, file_red, line, type, failOK); - inclistnext = inclistp; + inclistnext = t_inclistp; includedirsnext = includedirsp; break; case ERROR: diff --git a/contrib/makedepend/makedepend-1.0.5/pr.c b/contrib/makedepend/makedepend-1.0.5/pr.c index a011d4c1..0029781e 100644 --- a/contrib/makedepend/makedepend-1.0.5/pr.c +++ b/contrib/makedepend/makedepend-1.0.5/pr.c @@ -1,7 +1,7 @@ /* Copyright (c) 1993, 1994, 1998 The Open Group -Copyright (c) 2012-2018, Adam Young +Copyright (c) 2012-2022, Adam Young Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that @@ -115,7 +115,7 @@ pr(struct inclist *ip, const char *file, const char *base) char ch; for (i_file = ip->i_file; 0 != (ch = *i_file); ++i_file) { - if (olen < (sizeof(buf) - 2)) { + if (olen < (int)(sizeof(buf) - 2)) { if (ch == ' ') buf[olen++] = '\\'; buf[olen++] = ch; } diff --git a/gr/Makefile.in b/gr/Makefile.in index 1bd0324e..9f4a4080 100644 --- a/gr/Makefile.in +++ b/gr/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.80 2021/07/05 15:01:26 cvsuser Exp $ +# $Id: Makefile.in,v 1.84 2022/06/01 16:08:15 cvsuser Exp $ # GRIEF editor makefile. # # -# Copyright (c) 1998 - 2021, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -43,6 +43,7 @@ XCLEAN= CC= @CC@ CXX= @CXX@ RM= @RM@ +RC= @RC@ PERL= @PERL@ LIBTOOL= @LIBTOOL@ @@ -71,16 +72,19 @@ D_OBJDEP= $(D_OBJ)/$(D_DEP) CCDEPEND= @echo "\#no depend" > $(D_OBJDEP)/$<.Po ifeq ("win32","@build_os@") + +ifeq (vs,$(findstring vs,"@TOOLCHAIN@")) CCPROFILE=msvc.profile -ifeq ("wcl386","@CC@") -CCPROFILE=wc.profile -endif -ifeq ("owcc","@CC@") +else ifeq ("@TOOLCHAIN@","owc20") +CCPROFILE=wc20.profile +else ifeq ("@TOOLCHAIN@","owc19") CCPROFILE=wc.profile +#TODO +#else ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) +#CCPROFILE=mingw.profile endif -ifeq ("gcc","@CC@") -CCPROFILE=mingw.profile -endif + +ifdef CCPROFILE CCDEPEND= @$(D_BIN)/makedepend \ -MM -MC $(ROOT)/win32/$(CCPROFILE) -MG -MP -D__MAKEDEPEND__ \ -f$(D_OBJDEP)/$(basename $(&1 >/dev/null endif endif #CCDEPEND +endif #!win32 CXXDEPEND?= $(CCDEPEND) @@ -162,9 +169,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ @LIBCURL_CPPFLAGS@ -DLIBTRE_DLL ifdef PURIFY @@ -177,11 +181,11 @@ CDEPFLAGS= $(CEXTRA) $(CINCLUDE) ifeq ("$(BUILD_TYPE)","release") CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXRELEASE) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXRELEASE) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDRELEASE) @LDFLAGS@ else CFLAGS+= $(CDEBUG) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXDEBUG) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXDEBUG) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif ifeq (gcc,$(findstring gcc,$(CC))) @@ -194,9 +198,7 @@ LDLIBS= -L$(D_LIB) -lbsddb -lbsdfetch -lbsdio -lwidechar -lchartable -lvfs -lsp LDLIBS+= @LDLIBS@ @LIBS@ LDLIBS+= @LIBENCA@ @LIBSPELL@ @LIBICU@ @LIBICONV@ @LIBCURL@ @LIBOPENSSL@ @LIBARCHIVE@ @LIBMAGIC@ LDLIBS+= @LIBM@ @EXTRALIBS@ -ifeq ("mingw32","@build_os@") -LDLIBS+= -lw32 -lshlwapi -lshell32 -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -else ifneq ("win32","@build_os@") +ifneq ("win32","@build_os@") LDLIBS+= @TERMLIB@ @LIBX11@ endif LDLIBS+= @LIBMALLOC@ @LIBTHREAD@ @@ -361,9 +363,20 @@ CSRC=\ sys_vms.c \ sys_win32.c +RESOURCES=\ + gr.rc + OBJS= $(addprefix $(D_OBJ)/,$(patsubst %.c,%$(O),$(CSRC))) OBJS+= $(addprefix $(D_OBJ)/,$(patsubst %.cpp,%$(O),$(CPPSRC))) +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) +OBJS+= $(addprefix $(D_OBJ)/,$(subst .rc,_res.o,$(RESOURCES))) +else +OBJS+= $(addprefix $(D_OBJ)/,$(subst .rc,.res,$(RESOURCES))) +endif +endif #build_os + ######################################################################################### # Rules @@ -403,4 +416,11 @@ $(D_OBJ)/%$(O): %.cpp $(CXX) $(CXXFLAGS) -o $@ -c $< $(CXXDEPEND) +$(D_OBJ)/%.res: %.rc + $(RC) -fo $@ $< + +$(D_OBJ)/%_res.o: %.rc + $(RC) -o $@ $< + #end + diff --git a/gr/accum.c b/gr/accum.c index 1824fec9..31412a14 100644 --- a/gr/accum.c +++ b/gr/accum.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_accum_c,"$Id: accum.c,v 1.36 2020/04/21 00:01:54 cvsuser Exp $") +__CIDENT_RCSID(gr_accum_c,"$Id: accum.c,v 1.37 2022/05/26 16:33:10 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: accum.c,v 1.36 2020/04/21 00:01:54 cvsuser Exp $ +/* $Id: accum.c,v 1.37 2022/05/26 16:33:10 cvsuser Exp $ * Accumulator manipulating. * * @@ -64,8 +64,8 @@ typedef struct accumulator { } ac; } accumulator_t; -static void __CINLINE acc_zap(void); -static void __CINLINE acc_size(int len); +static __CINLINE void acc_zap(void); +static __CINLINE void acc_size(int len); static accumulator_t __CCACHEALIGN accum = { /* global accumulator */ F_INT @@ -103,7 +103,7 @@ acc_expand(int len) * acc_size --- * Size the accumulator to accomdate 'len' bytes. */ -static void __CINLINE +static __CINLINE void acc_size(int len) { assert(len >= 0); @@ -141,7 +141,7 @@ acc_size(int len) * acc_zap --- * Release any external accumulator references. */ -static void __CINLINE +static __CINLINE void acc_zap(void) { switch (accum.ac_type) { @@ -566,4 +566,4 @@ acc_trace(void) } } -/*end*/ \ No newline at end of file +/*end*/ diff --git a/gr/builtin.c b/gr/builtin.c index 037d1232..a3211600 100644 --- a/gr/builtin.c +++ b/gr/builtin.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_builtin_c,"$Id: builtin.c,v 1.63 2021/10/18 13:21:23 cvsuser Exp $") +__CIDENT_RCSID(gr_builtin_c,"$Id: builtin.c,v 1.66 2022/06/16 10:19:31 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: builtin.c,v 1.63 2021/10/18 13:21:23 cvsuser Exp $ +/* $Id: builtin.c,v 1.66 2022/06/16 10:19:31 cvsuser Exp $ * Builtin expresssion evaluation. * * @@ -57,8 +57,8 @@ struct SAVED { /* Save argument references */ static void execute_event(int event); static void execute_builtin(const BUILTIN *bp, const LIST *lp); -static void __CINLINE arg_error(const BUILTIN *bp, enum ARGERRORS msg, struct SAVED *saved_str, struct SAVED *ssp, int arg); -static void __CINLINE arg_free(struct SAVED *saved_str, struct SAVED *ssp); +static __CINLINE void arg_error(const BUILTIN *bp, enum ARGERRORS msg, struct SAVED *saved_str, struct SAVED *ssp, int arg); +static __CINLINE void arg_free(struct SAVED *saved_str, struct SAVED *ssp); static int arg_expand(const BUILTIN *bp, int varargs, int largc, LISTV **largv, LISTV **lap, struct SAVED **lsaved, struct SAVED **ssp); @@ -74,7 +74,6 @@ static unsigned x_evtno = 0; static unsigned x_evttail = 0; static unsigned x_evthead = 0; static unsigned x_evtactive = FALSE; -static unsigned x_evtctrlc = 0; /* SIGINT count */ static unsigned x_evtqueue[REGEVTNUM]; /* Event queue */ static LISTV x_margv[MAX_ARGC]; /* Initial stack frame */ @@ -191,7 +190,11 @@ execute_str(const char *str) accint_t ival; int ret, len = 0; +#if (CM_ATOMSIZE == SIZEOF_LONG_LONG && CM_ATOMSIZE != SIZEOF_LONG) + ret = str_numparsel((const char *)cp, &fval, &ival, &len); +#else ret = str_numparse((const char *)cp, &fval, &ival, &len); +#endif switch (ret) { case NUMPARSE_INTEGER: /* integer-constant */ case NUMPARSE_FLOAT: /* float-constant */ diff --git a/gr/cmain.c b/gr/cmain.c index 3942dbb7..6cd82a56 100644 --- a/gr/cmain.c +++ b/gr/cmain.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_cmain_c,"$Id: cmain.c,v 1.41 2021/10/24 16:46:45 cvsuser Exp $") +__CIDENT_RCSID(gr_cmain_c,"$Id: cmain.c,v 1.43 2022/05/31 16:18:21 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: cmain.c,v 1.41 2021/10/24 16:46:45 cvsuser Exp $ +/* $Id: cmain.c,v 1.43 2022/05/31 16:18:21 cvsuser Exp $ * Main body, startup and command-line processing. * * @@ -390,7 +390,6 @@ extern void /* must be extern linkage; other cpp_linkage(const char *str); - /* Function: cmain * Entry point. * @@ -470,7 +469,7 @@ cmain(int argc, char **argv) if (argc < 0) cpp_linkage(""); x_umask = (mode_t)fileio_umask(0); /* our umask */ - if ((int)x_umask < 0) x_umask = 0; + //if ((int)x_umask < 0) x_umask = 0; fileio_umask(x_umask); x_progname = argv[0]; @@ -1041,6 +1040,7 @@ argv_process(int doerr, int argc, const char **argv) break; case 5: case 6: nflags |= DB_MEMORY; + /*FALLTHRU*/ case 7: /*see cmain.cpp*/ case 8: /*see cmain.cpp*/ ++vm_dflag; @@ -1564,7 +1564,7 @@ env_define(const char *cp) if (F_STR == type) { trace_log("-D%s=%s (string)\n", name, svalue); } else { - trace_log("-D%s=%ld (integer)\n", name, ivalue); + trace_log("-D%s=%" ACCINT_FMT " (integer)\n", name, ivalue); } if (svalue) { svalue[-1] = '='; /* restore */ diff --git a/gr/echo.c b/gr/echo.c index 56d94cb7..41607142 100644 --- a/gr/echo.c +++ b/gr/echo.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_echo_c,"$Id: echo.c,v 1.72 2021/08/01 14:34:04 cvsuser Exp $") +__CIDENT_RCSID(gr_echo_c,"$Id: echo.c,v 1.74 2022/05/31 16:18:21 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: echo.c,v 1.72 2021/08/01 14:34:04 cvsuser Exp $ +/* $Id: echo.c,v 1.74 2022/05/31 16:18:21 cvsuser Exp $ * Command/echo line implementation/interface. * * @@ -608,7 +608,7 @@ elineedit(const char *prompt, const char *defstr, char *result, int bufsiz, int KEY c = 0; assert(bufsiz >= 2 /*&& bufsiz <= EBUFSIZ*/); - if (bufsiz > _countof(buf)) bufsiz = _countof(buf); + if (bufsiz > (int)_countof(buf)) bufsiz = _countof(buf); memset(buf, 0, sizeof(buf)); memset(ndefstr, 0, sizeof(ndefstr)); @@ -3080,7 +3080,7 @@ ef_percent(WChar_t *cp, const struct _estate *s) if (perc >= 100) { strcpy(t_buffer, "END"); } else { - sprintf(t_buffer, "%2lu%%", perc); + sprintf(t_buffer, "%2u%%", (unsigned)perc); } return ef_buffer(cp, t_buffer, s); } diff --git a/gr/eval.c b/gr/eval.c index 3dca1f2f..eb333d4d 100644 --- a/gr/eval.c +++ b/gr/eval.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_eval_c,"$Id: eval.c,v 1.38 2020/06/05 13:06:21 cvsuser Exp $") +__CIDENT_RCSID(gr_eval_c,"$Id: eval.c,v 1.39 2022/06/16 10:19:32 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: eval.c,v 1.38 2020/06/05 13:06:21 cvsuser Exp $ +/* $Id: eval.c,v 1.39 2022/06/16 10:19:32 cvsuser Exp $ * Evaluator. * * @@ -546,7 +546,11 @@ do_cvt_to_object(void) /* (string value, [string length]) */ accint_t ival; int len; +#if (CM_ATOMSIZE == SIZEOF_LONG_LONG && CM_ATOMSIZE != SIZEOF_LONG) + switch (str_numparsel(cursor, &dval, &ival, &len)) { +#else switch (str_numparse(cursor, &dval, &ival, &len)) { +#endif case NUMPARSE_INTEGER: acc_assign_int(ival); cursor += len; diff --git a/gr/file.c b/gr/file.c index 27490dbd..b09d32c5 100644 --- a/gr/file.c +++ b/gr/file.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_file_c,"$Id: file.c,v 1.90 2021/10/18 13:19:59 cvsuser Exp $") +__CIDENT_RCSID(gr_file_c,"$Id: file.c,v 1.93 2022/06/15 12:16:32 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: file.c,v 1.90 2021/10/18 13:19:59 cvsuser Exp $ +/* $Id: file.c,v 1.93 2022/06/15 12:16:32 cvsuser Exp $ * File-buffer primitives and support. * * @@ -33,6 +33,9 @@ __CIDENT_RCSID(gr_file_c,"$Id: file.c,v 1.90 2021/10/18 13:19:59 cvsuser Exp $") #if defined(WIN32) #include <../libw32/win32_io.h> +#if defined(_MSC_VER) && (_MSC_VER <= 1600 /*2010*/) +#define snprintf _snprintf +#endif #endif #include "accum.h" /* acc_...() */ @@ -3011,7 +3014,7 @@ percentage( m = 'G'; } } - sxprintf(iobuf, sizeof(iobuf), "[%s %%s%%s: %ld%%%%/%d%c done]", str, pc, (int)sz, m); + sxprintf(iobuf, sizeof(iobuf), "[%s %%s%%s: %" ACCINT_FMT "%%%%/%d%c done]", str, pc, (int)sz, m); infof_truncated(iobuf, str1); cache_pc = pc; } @@ -3703,6 +3706,17 @@ file_modedesc(mode_t mode, const char *source, int format, char *buffer, int len __CUNUSED(source) +#if !defined(S_IWGRP) /* MINGW32 etc */ +#define S_IRGRP S_IRUSR +#define S_IWGRP S_IWUSR +#define S_IXGRP S_IXUSR +#endif +#if !defined(S_IROTH) +#define S_IROTH S_IRUSR +#define S_IWOTH S_IWUSR +#define S_IXOTH S_IXUSR +#endif + /* type */ if (S_ISDIR(mode)) { t_buffer[0] = (format ? '/' : 'd'); /* directory */ @@ -3769,16 +3783,6 @@ file_modedesc(mode_t mode, const char *source, int format, char *buffer, int len } /* permissions */ -#if !defined(S_IWGRP) /* MINGW32 etc */ -#define S_IRGRP S_IRUSR -#define S_IWGRP S_IWUSR -#define S_IXGRP S_IXUSR -#endif -#if !defined(S_IROTH) -#define S_IROTH S_IRUSR -#define S_IWOTH S_IWUSR -#define S_IXOTH S_IXUSR -#endif t_buffer[1] = (mode & S_IRUSR ? 'r' : '-'); /* read permission: owner */ t_buffer[2] = (mode & S_IWUSR ? 'w' : '-'); /* write permission: owner */ t_buffer[3] = (mode & S_IXUSR ? 'x' : '-'); /* execute permission: owner */ diff --git a/gr/gr.rc b/gr/gr.rc new file mode 100644 index 00000000..8c9f09b4 --- /dev/null +++ b/gr/gr.rc @@ -0,0 +1,116 @@ +/* -*- mode: c; indent-width: 4; -*- + * + * windows resource file + * + * This file is part of the GRIEF Editor. + * + * The GRIEF Editor is free software: you can redistribute it + * and/or modify it under the terms of the GRIEF Editor License. + * + * Redistributions of source code must retain the above copyright + * notice, and must be distributed with the license document above. + * + * Redistributions in binary form must reproduce the above copyright + * notice, and must include the license document above in + * the documentation and/or other materials provided with the + * distribution. + * + * The GRIEF Editor 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 + * License for more details. + * ==end== + */ + +#include "../include/edbuildinfo.h" + +#define RC_PRODUCTVERSION GR_VERSION_1 , GR_VERSION_2 , GR_VERSION_3 , GR_VERSION_4 +#define RC_FILEVERSION GR_VERSION_1 , GR_VERSION_2 , GR_VERSION_3 , GR_VERSION_4 + +#ifndef WINDRES +#include "windows.h" +#include "winver.h" +#endif + +/* + * English (U.S.) resources + */ + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) + +#ifdef _WIN32 +#ifndef WINDRES +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#endif +#pragma code_page(1252) +#endif /* _WIN32 */ + +VS_VERSION_INFO VERSIONINFO + FILEVERSION RC_FILEVERSION + PRODUCTVERSION RC_PRODUCTVERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS (VS_FF_SPECIALBUILD|VS_FF_DEBUG) +#else + FILEFLAGS (VS_FF_SPECIALBUILD) +#endif + FILEOS VOS_NT_WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE VFT2_UNKNOWN + BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + // VALUE "CompanyName", "" + + VALUE "FileDescription", "The GRIEF Editor" + + VALUE "FileVersion", GR_VERSION ", Build:" GR_BUILD_DATE "-" GR_BUILD_NUMBER + + VALUE "InternalName", "GRIEFEdit" + + VALUE "LegalCopyright", + "Copyright (C) 1998 - 2022, Adam Young. All rights reserved. \n" + "Derived from crisp2.2, Paul Fox, 1991. \n" + "Copyright (C) 1990, 1993, The Regents of the University of California. \n" + + VALUE "LegalTrademarks", "see the GRIEF License" + + VALUE "Maintainers", "https://github.com/adamyg/grief\n" + + VALUE "OriginalFilename", "gr.exe" + + VALUE "ProductName", "GRIEF Edit" + + VALUE "ProductVersion", GR_VERSION "-win32" + + VALUE "SpecialBuild", "gr-win32-native" + END + END + + /* The following line should only be modified for localized versions. */ + /* It consists of any number of WORD,WORD pairs, with each pair */ + /* describing a language,codepage combination supported by the file. */ + /* */ + /* For example, a file might have values "0x409,1252" indicating that it */ + /* supports English language (0x409) in the Windows ANSI codepage (1252). */ + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END + END + +/* + * Icons + * +0 ICON DISCARDABLE "art/grnew.ico" +1 ICON DISCARDABLE "art/grlogo.ico" +2 ICON DISCARDABLE "art/grold.ico" + * + */ + +#endif /* English (U.S.) resources */ + + diff --git a/gr/keyboard.c b/gr/keyboard.c index 16e146ec..10e2ef05 100644 --- a/gr/keyboard.c +++ b/gr/keyboard.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_keyboard_c,"$Id: keyboard.c,v 1.66 2021/07/18 23:03:19 cvsuser Exp $") +__CIDENT_RCSID(gr_keyboard_c,"$Id: keyboard.c,v 1.67 2022/05/26 16:35:06 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: keyboard.c,v 1.66 2021/07/18 23:03:19 cvsuser Exp $ +/* $Id: keyboard.c,v 1.67 2022/05/26 16:35:06 cvsuser Exp $ * Manipulate key maps and bindings. * * @@ -346,8 +346,23 @@ static const struct w32key { // { VK_OEM_6, // ']}' for US // { VK_OEM_7, // ''"' for US +#ifndef VK_OEM_NEC_EQUAL +#define VK_OEM_NEC_EQUAL 0x92 +#endif +#ifndef VK_ICO_CLEAR +#define VK_ICO_CLEAR 0xE6 +#endif +#ifndef VK_ICO_HELP +#define VK_ICO_HELP 0xE3 +#endif +#ifndef VK_OEM_CLEAR +#define VK_OEM_CLEAR 0xFE +#endif + { VK_OEM_NEC_EQUAL, VKMOD_ANY, "Keypad-Equal", KEYPAD_EQUAL }, +// { VK_ICO_CLEAR, VKMOD_ANY, "Clear", KEYPAD_CLEAR }, { VK_ICO_HELP, VKMOD_ANY, "Help", KEY_HELP }, +// { VK_OEM_CLEAR, VKMOD_ANY, "Clear", KEYPAD_CLEAR }, }; #endif /*WIN32 || __CYGWIN__*/ diff --git a/gr/language.c b/gr/language.c index a81c39e0..44d08af5 100644 --- a/gr/language.c +++ b/gr/language.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_language_c,"$Id: language.c,v 1.48 2020/04/21 21:23:03 cvsuser Exp $") +__CIDENT_RCSID(gr_language_c,"$Id: language.c,v 1.51 2022/06/16 10:19:31 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: language.c,v 1.48 2020/04/21 21:23:03 cvsuser Exp $ +/* $Id: language.c,v 1.51 2022/06/16 10:19:31 cvsuser Exp $ * Module loader and inline compiler for lisp source. * * @@ -713,7 +713,7 @@ gr_lexer(void) if ((_chars_[fppeek()] & _XXDIGIT) == 0) { goto alpha; } - + /*FALLTHRU*/ case '0': case '1': case '2': @@ -1224,7 +1224,11 @@ gr_number(int ch) int ret; parse_unget(NULL, ch); +#if (CM_ATOMSIZE == SIZEOF_LONG_LONG && CM_ATOMSIZE != SIZEOF_LONG) + if ((ret = str_numparsexl(parse_get, parse_unget, NULL, &yyfloat, &yyint, NULL)) > 0) { +#else if ((ret = str_numparsex(parse_get, parse_unget, NULL, &yyfloat, &yyint, NULL)) > 0) { +#endif switch (ret) { case NUMPARSE_INTEGER: return yytoken = TOKEN_INT; diff --git a/gr/lisp.c b/gr/lisp.c index a6787190..e434e730 100644 --- a/gr/lisp.c +++ b/gr/lisp.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_lisp_c,"$Id: lisp.c,v 1.45 2021/07/05 15:01:27 cvsuser Exp $") +__CIDENT_RCSID(gr_lisp_c,"$Id: lisp.c,v 1.46 2022/05/26 16:36:12 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: lisp.c,v 1.45 2021/07/05 15:01:27 cvsuser Exp $ +/* $Id: lisp.c,v 1.46 2022/05/26 16:36:12 cvsuser Exp $ * List primitives. * * @@ -325,7 +325,7 @@ atom_next(const LIST *lp) const LIST * -atom_next_nonnull(const register LIST *lp) +atom_next_nonnull(register const LIST *lp) { assert(lp && *lp < F_MAX); switch (*lp) { @@ -600,6 +600,8 @@ atom_assign_acc(const LIST *lp) // case F_STR: default: panic("atom_assign_acc: Unexpected type (0x%x/%d)", *lp, *lp); + /*NOTREACHED*/ + break; case F_HALT: acc_assign_null(); return -1; @@ -658,6 +660,8 @@ atom_assign_sym(const LIST *lp, SYMBOL *sp) // case F_REG: default: panic("atom_assign_sym: Unexpected type (0x%x/%d)", *lp, *lp); + /*NOTREACHED*/ + break; case F_HALT: return -1; } @@ -843,7 +847,7 @@ argv_size(const LISTV *lvp) * int - size of list element in bytes. */ int -argv_copy(LIST *lp, const register LISTV *lvp) +argv_copy(LIST *lp, register const LISTV *lvp) { LIST atom = lvp->l_flags; @@ -2564,6 +2568,8 @@ do_is_type(int type) /* int (declare symbol, [int | string type]) */ case F_NULL: ret = 1; break; + default: + break; } } else { ret = (sp->s_type == type); /* symbol type */ diff --git a/gr/m_feature.c b/gr/m_feature.c index caa2943b..a62dd334 100644 --- a/gr/m_feature.c +++ b/gr/m_feature.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_m_feature_c,"$Id: m_feature.c,v 1.25 2020/06/21 00:21:31 cvsuser Exp $") +__CIDENT_RCSID(gr_m_feature_c,"$Id: m_feature.c,v 1.26 2022/05/26 16:35:41 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: m_feature.c,v 1.25 2020/06/21 00:21:31 cvsuser Exp $ +/* $Id: m_feature.c,v 1.26 2022/05/26 16:35:41 cvsuser Exp $ * Features. * * @@ -89,6 +89,7 @@ struct ft_map { int xf_fsync = FALSE; //TODO int x_history_depth = -1; //TODO +#if (TODO) static struct ft_map ft_features[] = { #define FT_MKSTR(__x) FT_STR, (void *)&__x #define FT_MKINT(__x) FT_INT, (void *)&__x @@ -124,6 +125,8 @@ static struct ft_map ft_features[] = { #undef FT_MKINT #undef FT_MKFLG }; +#endif /*TODO*/ + /* * Build features diff --git a/gr/m_ftp.c b/gr/m_ftp.c index ae83cafc..c6bb05f1 100644 --- a/gr/m_ftp.c +++ b/gr/m_ftp.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_m_ftp_c,"$Id: m_ftp.c,v 1.16 2020/06/03 16:22:15 cvsuser Exp $") +__CIDENT_RCSID(gr_m_ftp_c,"$Id: m_ftp.c,v 1.17 2022/05/26 16:36:19 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: m_ftp.c,v 1.16 2020/06/03 16:22:15 cvsuser Exp $ +/* $Id: m_ftp.c,v 1.17 2022/05/26 16:36:19 cvsuser Exp $ * FTP/HTTP connection primitives -- beta/undocumented. * * @@ -628,7 +628,7 @@ do_ftp_directory(void) /* int (int id, [string pattern], list &file } } - if (atoms >= 0) { + if (atoms > 0) { const int llen = (atoms * sizeof_atoms[F_RSTR]) + sizeof_atoms[F_HALT]; LIST *newlp; @@ -884,7 +884,7 @@ do_ftp_remove(void) /* int (int id, string name) */ } } } - acc_assign_int(-1); + acc_assign_int(ret); } @@ -941,7 +941,7 @@ do_ftp_rename(void) /* int (int id, string oldname, string newna } } } - acc_assign_int(-1); + acc_assign_int(ret); } diff --git a/gr/m_ftp.h b/gr/m_ftp.h index afff349c..30c0d547 100644 --- a/gr/m_ftp.h +++ b/gr/m_ftp.h @@ -1,11 +1,11 @@ #ifndef GR_M_FTP_H_INCLUDED #define GR_M_FTP_H_INCLUDED #include -__CIDENT_RCSID(gr_m_ftp_h,"$Id: m_ftp.h,v 1.6 2014/11/16 17:28:40 ayoung Exp $") +__CIDENT_RCSID(gr_m_ftp_h,"$Id: m_ftp.h,v 1.7 2022/05/26 16:36:19 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: m_ftp.h,v 1.6 2014/11/16 17:28:40 ayoung Exp $ +/* $Id: m_ftp.h,v 1.7 2022/05/26 16:36:19 cvsuser Exp $ * FTP primitives -- beta/undocumented. * * @@ -69,6 +69,7 @@ void do_ftp_register(void); void do_ftp_remove(void); void do_ftp_rename(void); void do_ftp_set_options(void); +void do_ftp_get_options(void); void do_ftp_sitename(void); void do_ftp_stat(void); void do_ftp_timeout(void); diff --git a/gr/m_region.c b/gr/m_region.c index 7b3bd62e..f94ffdf0 100644 --- a/gr/m_region.c +++ b/gr/m_region.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_m_region_c,"$Id: m_region.c,v 1.10 2014/10/22 02:33:06 ayoung Exp $") +__CIDENT_RCSID(gr_m_region_c,"$Id: m_region.c,v 1.11 2022/05/31 16:18:21 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: m_region.c,v 1.10 2014/10/22 02:33:06 ayoung Exp $ +/* $Id: m_region.c,v 1.11 2022/05/31 16:18:21 cvsuser Exp $ * Block primitives. * * @@ -216,7 +216,7 @@ do_write_block(void) /* int ([string fname], [int append = FALSE], [i */ if ('|' == *fname) { /* PIPE */ pipe_open = TRUE; - fp = popen(fname + 1, open_mode); + fp = sys_popen(fname + 1, open_mode); if (fp != NULL && pipe_msg) { /* allow user to view exec */ proc_prep_stop(TRUE); } @@ -237,7 +237,7 @@ do_write_block(void) /* int ([string fname], [int append = FALSE], [i region_write(fp, pipe_open ? (const char *)NULL : "Writing", &r); if (pipe_open) { - pclose(fp); + sys_pclose(fp); if (pipe_msg) { static const char contmsg[] = "Press any to continue: "; diff --git a/gr/m_scan.c b/gr/m_scan.c index ebaab6e1..25c76ff3 100644 --- a/gr/m_scan.c +++ b/gr/m_scan.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_m_scan_c,"$Id: m_scan.c,v 1.24 2018/10/11 22:37:23 cvsuser Exp $") +__CIDENT_RCSID(gr_m_scan_c,"$Id: m_scan.c,v 1.25 2022/05/26 16:42:10 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: m_scan.c,v 1.24 2018/10/11 22:37:23 cvsuser Exp $ +/* $Id: m_scan.c,v 1.25 2022/05/26 16:42:10 cvsuser Exp $ * scanf implementation. * * @@ -256,12 +256,14 @@ literal:; if ((c = ioget(io)) < 0) { case 'S': /* long string */ flags |= F_LONG; + /*FALLTHRU*/ case 's': /* string */ conv = D_STRING; break; case 'C': /* long character */ flags |= F_LONG; + /*FALLTHRU*/ case 'c': /* character */ flags |= F_WANTWHITE; conv = D_CHARACTER; diff --git a/gr/m_string.c b/gr/m_string.c index d396237a..a34f8b79 100644 --- a/gr/m_string.c +++ b/gr/m_string.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_m_string_c,"$Id: m_string.c,v 1.45 2021/07/12 15:55:01 cvsuser Exp $") +__CIDENT_RCSID(gr_m_string_c,"$Id: m_string.c,v 1.46 2022/05/26 16:36:46 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: m_string.c,v 1.45 2021/07/12 15:55:01 cvsuser Exp $ +/* $Id: m_string.c,v 1.46 2022/05/26 16:36:46 cvsuser Exp $ * String primitives. * * @@ -1900,6 +1900,7 @@ do_isgold(void) /* int (string str|int character) */ } } } + acc_assign_int(ret); } diff --git a/gr/m_symbol.c b/gr/m_symbol.c index edec33ac..0490fea5 100644 --- a/gr/m_symbol.c +++ b/gr/m_symbol.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_m_symbol_c,"$Id: m_symbol.c,v 1.43 2020/06/18 14:40:37 cvsuser Exp $") +__CIDENT_RCSID(gr_m_symbol_c,"$Id: m_symbol.c,v 1.44 2022/05/26 16:37:06 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: m_symbol.c,v 1.43 2020/06/18 14:40:37 cvsuser Exp $ +/* $Id: m_symbol.c,v 1.44 2022/05/26 16:37:06 cvsuser Exp $ * Symbol primitives. * * @@ -207,7 +207,7 @@ static const struct { /* integer constant's */ #define S_IFLNK 0 #endif #if !defined(S_IFSOCK) -#define S_ISOCK 0 +#define S_IFSOCK 0 #endif { "S_IFMT", S_IFMT }, @@ -219,6 +219,24 @@ static const struct { /* integer constant's */ { "S_IFSOCK", S_IFSOCK }, /* permissions */ +#if !defined(S_IRGRP) +#define S_IRGRP 0 +#endif +#if !defined(S_IWGRP) +#define S_IWGRP 0 +#endif +#if !defined(S_IXGRP) +#define S_IXGRP 0 +#endif +#if !defined(S_IROTH) +#define S_IROTH 0 +#endif +#if !defined(S_IWOTH) +#define S_IWOTH 0 +#endif +#if !defined(S_IXOTH) +#define S_IXOTH 0 +#endif #if !defined(S_ISUID) #define S_ISUID 0 #endif @@ -1416,7 +1434,7 @@ do_static(void) /* (name ...) */ * Pull arguments, unless from command line then just exit */ if (mac_sd <= 0) { - return; + return; } function = mac_sp->name; mp = macro_symbols(mac_sp->module); @@ -1467,14 +1485,14 @@ do_static(void) /* (name ...) */ const sym1, sym2 ...; Macro Description: - The 'const' qualifier explicitly declares a locally scoped data object as + The 'const' qualifier explicitly declares a locally scoped data object as something that cannot be changed. Its an immutable variable can only be set - during initialization. - + during initialization. + You cannot use const data objects in expressions requiring a modifiable lvalue. If you try to give it a new value, it will return you an error. - - For example, a const data object cannot appear on the lefthand side + + For example, a const data object cannot appear on the lefthand side of an assignment statement. Macro Returns: @@ -1550,7 +1568,7 @@ do_const(void) /* (name ...) */ Macro Description: The 'register' qualifier explicitly declares a locally scoped data object - as something that should be cached against the given index. + as something that should be cached against the given index. Registers are function scoped, being unique to each macro and are is visible only within the function. @@ -1584,7 +1602,7 @@ do_register(void) /* (index name ...) */ if (! atom_xint(lp, &idx)) { continue; } - lp = nextlp; + lp = nextlp; if ((nextlp = atom_next(lp)) == lp) { break; /* eos */ } else if (NULL == (symname = atom_xstr(lp))) { @@ -2458,7 +2476,7 @@ do_arg_list(void) /* ([int eval], [int start = 0], [int end = -1]) if (doeval) { /* * evaluate the parameter, - * must remove the local frame and reinitialise, + * must remove the local frame and reinitialise, * this is required to setup the callers context to resolve any symbol/function references. */ struct mac_stack lmacstack; @@ -2581,7 +2599,7 @@ do_ref_parm(void) /* (int argument, string local_symbol, [int opti assert(x_nest_level >= 2); assert(mac_sd > 1); - --x_nest_level; + --x_nest_level; --mac_sd; --mac_sp; sp = sym_elookup(LGET_PTR2(const char, lp)); ++mac_sd; ++mac_sp; @@ -2599,4 +2617,4 @@ do_ref_parm(void) /* (int argument, string local_symbol, [int opti } } -/*end*/ \ No newline at end of file +/*end*/ diff --git a/gr/m_sysinfo.c b/gr/m_sysinfo.c index a4aa7f38..c4280996 100644 --- a/gr/m_sysinfo.c +++ b/gr/m_sysinfo.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_m_sysinfo_c,"$Id: m_sysinfo.c,v 1.9 2014/10/22 02:33:09 ayoung Exp $") +__CIDENT_RCSID(gr_m_sysinfo_c,"$Id: m_sysinfo.c,v 1.10 2022/06/16 10:11:14 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: m_sysinfo.c,v 1.9 2014/10/22 02:33:09 ayoung Exp $ +/* $Id: m_sysinfo.c,v 1.10 2022/06/16 10:11:14 cvsuser Exp $ * System information primitives. * * @@ -22,11 +22,9 @@ __CIDENT_RCSID(gr_m_sysinfo_c,"$Id: m_sysinfo.c,v 1.9 2014/10/22 02:33:09 ayoung #if defined(unix) || defined(_AIX) || defined(linux) || \ defined(WIN32) || defined(__APPLE__) -#if !defined(__MINGW32__) /* FIXME/MINGW */ -#define HAVE_UTSNAME +#define HAVE_UTSNAME #include #endif -#endif #include "m_sysinfo.h" @@ -276,7 +274,7 @@ do_uname(void) /* int ([string &sysname], [string &nodename], [ return; } #endif -#endif +#endif /*HAVE_UTSNAME*/ acc_assign_int(-1); } /*end*/ diff --git a/gr/macrolib.c b/gr/macrolib.c index 01e0f663..cf8060a9 100644 --- a/gr/macrolib.c +++ b/gr/macrolib.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_macrolib_c,"$Id: macrolib.c,v 1.18 2015/02/19 00:16:52 ayoung Exp $") +__CIDENT_RCSID(gr_macrolib_c,"$Id: macrolib.c,v 1.19 2022/05/31 16:18:21 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: macrolib.c,v 1.18 2015/02/19 00:16:52 ayoung Exp $ +/* $Id: macrolib.c,v 1.19 2022/05/31 16:18:21 cvsuser Exp $ * Macro library support - experimental. * * @@ -354,7 +354,7 @@ libarc_index(const char *lpath) continue; /* not a macro extension */ } - if (fsize < sizeof(CM_t) || + if (fsize < (off_t)sizeof(CM_t) || (rcode = (size_t) archive_read_data(a, cm, sizeof(cmbuf))) < sizeof(CM_t)) { if (0 == rcode) { err = archive_error_string(a); diff --git a/gr/main.cpp b/gr/main.cpp index 82f8c40a..9fb6a984 100644 --- a/gr/main.cpp +++ b/gr/main.cpp @@ -1,23 +1,14 @@ #include -__CIDENT_RCSID(gr_main_cpp,"$Id: main.cpp,v 1.15 2020/06/18 12:45:13 cvsuser Exp $") +__CIDENT_RCSID(gr_main_cpp,"$Id: main.cpp,v 1.17 2022/06/13 13:14:07 cvsuser Exp $") /* -*- mode: cpp; indent-width: 4; -*- */ -/* $Id: main.cpp,v 1.15 2020/06/18 12:45:13 cvsuser Exp $ +/* $Id: main.cpp,v 1.17 2022/06/13 13:14:07 cvsuser Exp $ * main(), address c/c++ linkage for several environments. * Regardless of configuration force binding to the C++ runtime library. * * */ -#if (defined(_WIN32) || defined(WIN32)) && \ - !defined(WINDOWS_MEAN_AND_LEAN) -#define WINDOWS_MEAN_AND_LEAN -#endif - -#include -#include -#include "signals.h" - #if defined(_CRT_NO_POSIX_ERROR_CODES) #if (_MSC_VER >= 1900) || defined(__MAKEDEPEND__) #undef _CRT_NO_POSIX_ERROR_CODES /* is incompatible with _CRT_NO_POSIX_ERROR_CODES */ @@ -25,12 +16,25 @@ __CIDENT_RCSID(gr_main_cpp,"$Id: main.cpp,v 1.15 2020/06/18 12:45:13 cvsuser Exp #endif //_MSC_VER #endif //_CRT_NO_POSIX_ERROR_CODES +#if defined(__MINGW32__) && !defined(__MINGW32_VERSION_MAJOR) +#include /* before C++ headers, ELOOP/EOVERFLOW redef */ +#endif + #include #include - // XXX: avoid std::string, open-watcom linker issues resulting in debug symbol issues. + // XXX: avoid std::string, open-watcom linker issues resulting in debug symbol issues, -hw mode. + +#if (defined(_WIN32) || defined(WIN32)) && \ + !defined(WINDOWS_MEAN_AND_LEAN) +#define WINDOWS_MEAN_AND_LEAN +#endif +#include +#include +#include "signals.h" -extern "C" { +extern "C" +{ int cmain(int argc, char **argv); /* cmain.c */ void cpp_linkage(const char *str); } diff --git a/gr/maths.c b/gr/maths.c index 21ba6550..10e25c9d 100644 --- a/gr/maths.c +++ b/gr/maths.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_math_c,"$Id: maths.c,v 1.34 2020/06/18 14:40:37 cvsuser Exp $") +__CIDENT_RCSID(gr_math_c,"$Id: maths.c,v 1.35 2022/05/26 16:38:25 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: maths.c,v 1.34 2020/06/18 14:40:37 cvsuser Exp $ +/* $Id: maths.c,v 1.35 2022/05/26 16:38:25 cvsuser Exp $ * Math operators/primitives. * * @@ -1501,6 +1501,7 @@ xfloat: switch (op) { break; case MOP_NE: /* (!=) not-equals */ val = (float1 != float2); + break; case MOP_LT: /* (<) less-than */ val = (float1 < float2); break; diff --git a/gr/mchar_guess.c b/gr/mchar_guess.c index a6c152fc..d1c5b3cb 100644 --- a/gr/mchar_guess.c +++ b/gr/mchar_guess.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_mchar_guess_c,"$Id: mchar_guess.c,v 1.29 2021/07/05 15:01:27 cvsuser Exp $") +__CIDENT_RCSID(gr_mchar_guess_c,"$Id: mchar_guess.c,v 1.30 2022/05/26 16:38:47 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: mchar_guess.c,v 1.29 2021/07/05 15:01:27 cvsuser Exp $ +/* $Id: mchar_guess.c,v 1.30 2022/05/26 16:38:47 cvsuser Exp $ * Character-set conversion/file type guess logic. * * @@ -223,6 +223,7 @@ static const struct guessdecoder { /* * Encoding line terminator modifies */ +#if (0) #define X_LINESPEC (sizeof(x_linespec)/sizeof(x_linespec[0])) static const struct linespec { @@ -238,6 +239,7 @@ static const struct linespec { { NAME("nel"), LTERM_NEL }, { NAME("ucsnl"), LTERM_UCSNL }, }; +#endif /* @@ -334,6 +336,7 @@ x_charflags[256] = /* Character attribute flags, as above */ }; +#if (0) static const uint8_t x_ebcdic2ascii[256] = /* CP037 - EBCDIC to ASCII mapping (see also Unicode Tech Reqport #16) */ { @@ -381,7 +384,7 @@ x_ebcdic2ascii[256] = /* CP037 - EBCDIC to ASCII mapping (see also Unicode Tec 0x5c,0xf7,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0xb2,0xd4,0xd6,0xd2,0xd3,0xd5, /* 0xeX */ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0xb3,0xdb,0xdc,0xd9,0xda,0x9f /* 0xfX */ }; - +#endif #if defined(HAVE_MAGIC_H) && defined(HAVE_LIBMAGIC) static int x_magicopen = 0; diff --git a/gr/mchar_iconv.c b/gr/mchar_iconv.c index d06a7c99..8652edea 100644 --- a/gr/mchar_iconv.c +++ b/gr/mchar_iconv.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_mchar_iconv_c,"$Id: mchar_iconv.c,v 1.24 2021/06/19 09:41:55 cvsuser Exp $") +__CIDENT_RCSID(gr_mchar_iconv_c,"$Id: mchar_iconv.c,v 1.25 2022/06/16 05:24:30 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: mchar_iconv.c,v 1.24 2021/06/19 09:41:55 cvsuser Exp $ +/* $Id: mchar_iconv.c,v 1.25 2022/06/16 05:24:30 cvsuser Exp $ * Character-set conversion/mapping interface and adapters. * * @@ -942,14 +942,14 @@ static mchar_iconv_t * icnv_open(const char *encoding) { iconv_t ihandle = ICONV_NULL, ohandle = ICONV_NULL; - const size_t encodinglen = (encoding ? strlen(encoding) + 1 : 0); + const size_t encodinglen = (encoding ? strlen(encoding) : 0); char toencoding[128] = {0}; mchar_iconv_t *ic; if (encoding) strxcpy(toencoding, encoding, sizeof(toencoding)); strxcat(toencoding, "//TRANSLIT", sizeof(toencoding)); - if (NULL == (ic = chk_alloc(sizeof(mchar_iconv_t) + encodinglen)) || + if (NULL == (ic = chk_alloc(sizeof(mchar_iconv_t) + encodinglen + 1)) || ICONV_NULL == (ihandle = my_iconv_open("utf-8//TRANSLIT", encoding)) || /*IGNORE or TRANSLIT?*/ ICONV_NULL == (ohandle = my_iconv_open(toencoding, "utf-8"))) { if (ic) { @@ -960,8 +960,9 @@ icnv_open(const char *encoding) } return NULL; } + (void) memset(ic, 0, sizeof(mchar_iconv_t)); - (void) memcpy((void *)(ic + 1), encoding, encodinglen); + memcpy((void *)(ic + 1), encodinglen ? encoding : "", encodinglen + 1); ic->ic_magic = MCHAR_ICONV_MAGIC; ic->ic_encoding = (const char *)(ic + 1); ic->ic_unit = 1; diff --git a/gr/prntf.c b/gr/prntf.c index 8a57160d..b9885ad4 100644 --- a/gr/prntf.c +++ b/gr/prntf.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_prntf_c,"$Id: prntf.c,v 1.16 2021/07/05 15:01:27 cvsuser Exp $") +__CIDENT_RCSID(gr_prntf_c,"$Id: prntf.c,v 1.18 2022/06/16 05:23:29 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: prntf.c,v 1.16 2021/07/05 15:01:27 cvsuser Exp $ +/* $Id: prntf.c,v 1.18 2022/06/16 05:23:29 cvsuser Exp $ * Print formatter. * * @@ -761,6 +761,7 @@ outl(io_t *io, int radix, accint_t lval) switch (radix) { case 2: TSTORE(io, 'B'); + break; case 8: TSTORE(io, '0'); break; @@ -896,7 +897,7 @@ outr(io_t *io, const char *s, int length) assert(length >= 0); if (io->width > 0) { padding = io->width - length; /* width specifies output columns */ - assert(padding >= 0); + if (padding < 0) padding = 0; /* wont truncate */ } OCHECK(io, padding + length); diff --git a/gr/sh_unix.c b/gr/sh_unix.c index ce32459d..7588f925 100644 --- a/gr/sh_unix.c +++ b/gr/sh_unix.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_sh_unix_c,"$Id: sh_unix.c,v 1.18 2014/10/22 02:33:19 ayoung Exp $") +__CIDENT_RCSID(gr_sh_unix_c,"$Id: sh_unix.c,v 1.19 2022/05/31 16:18:21 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: sh_unix.c,v 1.18 2014/10/22 02:33:19 ayoung Exp $ +/* $Id: sh_unix.c,v 1.19 2022/05/31 16:18:21 cvsuser Exp $ * * Linux * Sun Solaris @@ -384,4 +384,26 @@ sys_waitpid(int pid, int *statusp, int options) return ret; } + +/* + * sys_popen --- + * Pipe open implementation for Unix/Linux. + */ +FILE * +sys_popen(const char *cmd, const char *mode) +{ + return popen(cmd, mode); +} + + +/* + * sys_pclose --- + * Pipe close implementation for Unix/Linux. + */ +int +sys_pclose(FILE *file) +{ + return pclose(file); +} + #endif /*unix*/ diff --git a/gr/sh_win32.c b/gr/sh_win32.c index b72accda..f93c92e9 100644 --- a/gr/sh_win32.c +++ b/gr/sh_win32.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_sh_win32_c,"$Id: sh_win32.c,v 1.26 2022/03/21 15:39:39 cvsuser Exp $") +__CIDENT_RCSID(gr_sh_win32_c,"$Id: sh_win32.c,v 1.28 2022/05/31 16:18:21 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: sh_win32.c,v 1.26 2022/03/21 15:39:39 cvsuser Exp $ +/* $Id: sh_win32.c,v 1.28 2022/05/31 16:18:21 cvsuser Exp $ * * * This file is part of the GRIEF Editor. @@ -406,13 +406,13 @@ EnumWindowsProc(HWND hwnd, LPARAM lParam) * return TRUE; to stop enumeration, it must return FALSE. */ struct _enum_win_info *info = (struct _enum_win_info *)lParam; - DWORD thread, pid, status; + DWORD pid, status; - thread = GetWindowThreadProcessId(hwnd, &pid); + (void) GetWindowThreadProcessId(hwnd, &pid); return pid != info->dwProcessId || - GetExitCodeProcess(info->hProcess, &status) && - status == STILL_ACTIVE && // value = 259 - PostMessage(hwnd, WM_CLOSE, 0, 0); + (GetExitCodeProcess(info->hProcess, &status) && + status == STILL_ACTIVE && // value = 259 + PostMessage(hwnd, WM_CLOSE, 0, 0)); } @@ -434,24 +434,25 @@ SendCloseMessage(HANDLE hProc) /* - * popen --- + * sys_popen --- * Pipe open implementation for WIN32. */ FILE * -popen(const char *cmd, const char *mode) +sys_popen(const char *cmd, const char *mode) { return w32_popen(cmd, mode); } /* - * pclose --- + * sys_pclose --- * Pipe close implementation for WIN32. */ int -pclose(FILE *file) +sys_pclose(FILE *file) { return w32_pclose(file); } #endif /*WIN32*/ + diff --git a/gr/symbol.c b/gr/symbol.c index 3a6fbb2a..2e342384 100644 --- a/gr/symbol.c +++ b/gr/symbol.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_symbol_c,"$Id: symbol.c,v 1.42 2020/06/03 16:22:15 cvsuser Exp $") +__CIDENT_RCSID(gr_symbol_c,"$Id: symbol.c,v 1.43 2022/05/26 16:40:02 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: symbol.c,v 1.42 2020/06/03 16:22:15 cvsuser Exp $ +/* $Id: symbol.c,v 1.43 2022/05/26 16:40:02 cvsuser Exp $ * Symbol management. * * @@ -42,7 +42,7 @@ accint_t * x_errno_ptr = NULL; /* errno reference */ SPTREE * x_gsym_tbl = NULL; /* global symbol table */ SPTREE * x_lsym_tbl[MAX_SYMSTACK+1] = {0}; /* local symbol tables */ -static void __CINLINE sym_clear(SYMBOL *sp); +static __CINLINE void sym_clear(SYMBOL *sp); /* Function: sym_init diff --git a/gr/sys_win32.c b/gr/sys_win32.c index 51c242f4..e6f1edcd 100644 --- a/gr/sys_win32.c +++ b/gr/sys_win32.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_sys_win32_c,"$Id: sys_win32.c,v 1.63 2021/07/12 15:55:01 cvsuser Exp $") +__CIDENT_RCSID(gr_sys_win32_c,"$Id: sys_win32.c,v 1.69 2022/06/16 09:03:07 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: sys_win32.c,v 1.63 2021/07/12 15:55:01 cvsuser Exp $ +/* $Id: sys_win32.c,v 1.69 2022/06/16 09:03:07 cvsuser Exp $ * WIN32 system support. * * @@ -18,11 +18,12 @@ __CIDENT_RCSID(gr_sys_win32_c,"$Id: sys_win32.c,v 1.63 2021/07/12 15:55:01 cvsus * ==end== */ -#ifdef WIN32 +#ifdef WIN32 #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0601 #endif -#define WINVER 0x0601 +#undef WINVER +#define WINVER _WIN32_WINNT #endif #include @@ -54,14 +55,18 @@ static DWORD dwVersion, dwMajorVersion, dwMinorVersion, dwBuild; static DWORD consoleMode = (DWORD)-1; static BOOL CtrlHandler(DWORD fdwCtrlType); -static void CALLBACK HandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, +static void CALLBACK HandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime); static int Resize(int winch); static int ResizeCheck(unsigned *checks); #if defined(__WATCOMC__) -extern char volatile __WD_Present; +#if (__WATCOMC__ >= 1300) /*XXX, still supported?*/ +volatile char __WD_Present = 0; +#else +extern volatile char __WD_Present; +#endif #if defined(_M_IX86) extern void EnterDebugger(void); #pragma aux EnterDebugger = "int 3" @@ -287,41 +292,52 @@ DiffTicks(DWORD stick) /* start tick */ static int Resize(int winch) { - static int orows, ocols; - static char ofont[80]; - static RECT orect; + static int orows = 0, ocols = 0; + static char ofont[80] = {0}; + static RECT orect = {0}; VIOMODEINFO mi = { sizeof(VIOMODEINFO) }; - int nrows, ncols, nfont = -1; - char font[sizeof(ofont)]; - RECT rect; + int nrows, ncols, resize = 0; VioGetMode(&mi, 0); ncols = (int)mi.col; nrows = (int)mi.row; - font[0] = 0; if (2 == winch) { /* possible font change */ - VioGetFont(font, sizeof(font)); - nfont = (ofont[0] && (0 != memcmp(font, ofont, sizeof(ofont)))); + RECT rect; + + if (ofont[0]) { + char nfont[sizeof(ofont)] = {0}; + VioGetFont(nfont, sizeof(nfont)); + resize = (0 != memcmp(nfont, ofont, sizeof(ofont))); + if (resize) { + trace_log("resize: font change <%s to %s>\n", ofont, nfont); + memcpy(ofont, (const char *)nfont, sizeof(ofont)); + } + } else { + VioGetFont(ofont, sizeof(ofont)); + } + GetWindowRect(GetConsoleWindow(), &rect); if ((orect.right - orect.left) != (rect.right - rect.left) || (orect.bottom - orect.top) != (rect.bottom - rect.top)) { - if (orect.bottom) { - nfont = 1; + if (orect.bottom) { /* previous? */ + trace_log("resize: frame change <%u by %u>\n", + (unsigned)(rect.right - rect.left), (unsigned)(rect.bottom - rect.top)); + resize = 1; } } + orect = rect; } - if (orows != nrows || ocols != ncols || 1 == nfont) { + if (orows != nrows || ocols != ncols) { + trace_log("resize: size change <%d/%d to %d/%d>\n", orows, ocols, nrows, ncols); orows = nrows; /* change; cache current */ ocols = ncols; - if (-1 == nfont) { - VioGetFont(font, sizeof(font)); - GetWindowRect(GetConsoleWindow(), &rect); - } - memcpy(ofont, font, sizeof(ofont)); - orect = rect; + resize = 1; + } + + if (resize) { if (winch) { ++tty_needresize; } @@ -393,20 +409,20 @@ MouseEvent(const DWORD dwEventFlags, const DWORD dwButtonState) // Alt+ event handler // -// Alt+KeyCode works and behaves well when character only input is required, by simply -// reporting any down or up key events which populate the 'UnicodeChar' value. Whereas +// Alt+KeyCode works and behaves well when character only input is required, by simply +// reporting any down or up key events which populate the 'UnicodeChar' value. Whereas // when extended keystroke handling is required, for example arrow and numpad keys, // additional effort is needed. // // Alt+Keycodes are only reported within the 'UnicodeChar' value of up event on a "ALT" key -// post the valid entry of one-or-more hex characters. During KeyCode entry the API unfortunately -// does not publiciy indicate this state plus continues to return the associated virtual keys, +// post the valid entry of one-or-more hex characters. During KeyCode entry the API unfortunately +// does not publiciy indicate this state plus continues to return the associated virtual keys, // including the leading 'keypad-plus' and any associated key-code elements, wherefore we need -// to filter. Furthermore, if during the key-code entry an invalid non-hex key combination is +// to filter. Furthermore, if during the key-code entry an invalid non-hex key combination is // given, the key-code is invalidated and UnicodeChar=0 is returned on the ALT release. // -// Notes: -// o To enable requires the registry REG_SZ value "EnableHexNumpad" under +// Notes: +// o To enable requires the registry REG_SZ value "EnableHexNumpad" under // "HKEY_Current_User/Control Panel/Input Method" to be "1". // // o Hex-value overflow goes unreported, limiting input to a 16-bit unicode result. @@ -471,7 +487,7 @@ AltPlusEvent(const KEY_EVENT_RECORD *ke, struct IOEvent *evt) evt->type = EVT_KEYDOWN; evt->code = KEYPAD_PLUS; evt->modifiers = MOD_ALT; - alt_code = 0; + alt_code = 0; return 0; } @@ -618,7 +634,7 @@ sys_getevent(struct IOEvent *evt, int tmo) * font changes wont be reported, *unless* the window/buffer size is modified as a result, * as such force font checks for the number of input iterations. */ - checks = 10; + checks = 10; break; default: @@ -1192,11 +1208,9 @@ sys_signal(int sig, signal_handler_t func) int sys_running(int pid) { -// DWORD rc; if (GetProcessVersion((DWORD)pid) != 0) { return 1; } -// rc = GetLastError(); return 0; } #endif /*WIN32*/ diff --git a/gr/sysinfo.c b/gr/sysinfo.c index 094ab077..a2d31d0f 100644 --- a/gr/sysinfo.c +++ b/gr/sysinfo.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_sysinfo_c,"$Id: sysinfo.c,v 1.51 2021/06/02 15:29:09 cvsuser Exp $") +__CIDENT_RCSID(gr_sysinfo_c,"$Id: sysinfo.c,v 1.52 2022/05/31 16:18:21 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: sysinfo.c,v 1.51 2021/06/02 15:29:09 cvsuser Exp $ +/* $Id: sysinfo.c,v 1.52 2022/05/31 16:18:21 cvsuser Exp $ * System information services. * * @@ -374,7 +374,7 @@ resolve_execname(const char *name) #if defined(WIN32) || defined(__CYGWIN__) namelen = GetModuleFileNameA(NULL, t_name, sizeof(t_name)-1); - trace_log("exename: <%s/%d>\n", t_name, namelen); + trace_log("exename: <%s/%u>\n", t_name, (unsigned)namelen); t_name[namelen] = 0; #if defined(__CYGWIN__) diff --git a/gr/system.h b/gr/system.h index 7546f4cb..24cbe969 100644 --- a/gr/system.h +++ b/gr/system.h @@ -1,11 +1,11 @@ #ifndef GR_SYSTEM_H_INCLUDED #define GR_SYSTEM_H_INCLUDED #include -__CIDENT_RCSID(gr_system_h,"$Id: system.h,v 1.38 2021/06/02 15:29:27 cvsuser Exp $") +__CIDENT_RCSID(gr_system_h,"$Id: system.h,v 1.39 2022/05/31 16:18:22 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: system.h,v 1.38 2021/06/02 15:29:27 cvsuser Exp $ +/* $Id: system.h,v 1.39 2022/05/31 16:18:22 cvsuser Exp $ * System interface. * * @@ -83,6 +83,9 @@ extern int sys_getpid(void); extern int sys_core(const char *msg, const char *path, const char *fname); extern void sys_abort(void); +FILE * sys_popen(const char *cmd, const char *mode); +int sys_pclose(FILE *file); + typedef void (*signal_handler_t)(int); extern signal_handler_t sys_signal(int sig, signal_handler_t func); @@ -96,8 +99,6 @@ extern int sys_drive_set(int); #if (defined(_WIN32) || defined(WIN32)) && !defined(__CYGWIN__) #define mkdir(__p,__m) _mkdir(__p) /* name mangling */ -FILE * popen(const char *cmd, const char *mode); -int pclose(FILE *file); #endif /*WIN32*/ #if defined(_WIN32) || defined(WIN32) diff --git a/gr/termemu_vio.c b/gr/termemu_vio.c index a6cb1c4f..836614e5 100644 --- a/gr/termemu_vio.c +++ b/gr/termemu_vio.c @@ -27,21 +27,23 @@ #include "w32config.h" #endif +#if !defined(WINDOWS_MEAN_AND_LEAN) #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x601 -#else -#if(_WIN32_WINNT < 0x601) -#undef _WIN32_WINNT +#elif (_WIN32_WINNT < 0x601) +#undef _WIN32_WINNT #define _WIN32_WINNT 0x601 #endif -#endif +#undef WINVER +#define WINVER _WIN32_WINNT -#define PSAPI_VERSION 1 // EnumProcessModules and psapi.dll #if !defined(WINDOWS_MEAN_AND_LEAN) -#define WINDOWS_MEAN_AND_LEAN +#define WINDOWS_MEAN_AND_LEAN +#define PSAPI_VERSION 1 // EnumProcessModules and psapi.dll #include #endif #include +#endif #include #include @@ -92,7 +94,7 @@ static void vio_trace(const char *, ...); #define ISACS 0x1000000 /* ACS mapped character */ -#if ((defined(_MSC_VER) && (_MSC_VER < 1500)) || defined(__MINGW32__)) && \ +#if (defined(_MSC_VER) && (_MSC_VER < 1500)) && \ !defined(CONSOLE_OVERSTRIKE) #pragma pack(push, 1) @@ -211,6 +213,7 @@ static __inline void WCHAR_BUILD(const uint32_t ch, const struct WCHAR_COLORI static __inline BOOL WCHAR_COMPARE(const WCHAR_INFO *c1, const WCHAR_INFO *c2); static __inline unsigned WCHAR_UPDATE(WCHAR_INFO *cursor, const uint32_t ch, const struct WCHAR_COLORINFO *color); +struct attrmap; static int parse_color(const char *color, const char *defname, const struct attrmap *map, int *attr); static int parse_true_color(const char *color, COLORREF *rgb, int *attr); static int parse_attributes(const char *attr); @@ -550,8 +553,8 @@ vio_init(void) RECT rect = {0}; int ret = 0; - assert(WIN_COLOR_FOREGROUND == VT_COLOR_FOREGROUND); - assert(WIN_COLOR_BACKGROUND == VT_COLOR_BACKGROUND); + assert((int)WIN_COLOR_FOREGROUND == (int)VT_COLOR_FOREGROUND); + assert((int)WIN_COLOR_BACKGROUND == (int)VT_COLOR_BACKGROUND); // Console handle, // when stdout has been redirected, create a local console. @@ -1005,19 +1008,29 @@ w32_GetParentProcessId() } -#if defined(__WATCOMC__) +#if defined(__MINGW32__) typedef struct _OSVERSIONINFOW RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW; +typedef DWORD (WINAPI *fnRtlGetVersion_t)(PRTL_OSVERSIONINFOW); + +#elif defined(__WATCOMC__) +typedef struct _OSVERSIONINFOW RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW; +#endif + +#if !defined(__MINGW32__) +typedef NTSTATUS (WINAPI *fnRtlGetVersion_t)(PRTL_OSVERSIONINFOW); #endif +DWORD WINAPI GetModuleFileNameExA(HANDLE hProcess,HMODULE hModule,LPSTR lpFilename,DWORD nSize); +BOOL WINAPI EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded); + static BOOL w32_RtlGetVersion(RTL_OSVERSIONINFOW *rovi) { - typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); -#define STATUS_SUCCESS (0x00000000) +#define STATUS_SUCCESS (0x00000000) HMODULE hMod = GetModuleHandleA("ntdll.dll"); if (hMod) { - RtlGetVersionPtr cb = (RtlGetVersionPtr)GetProcAddress(hMod, "RtlGetVersion"); + fnRtlGetVersion_t cb = (fnRtlGetVersion_t)GetProcAddress(hMod, "RtlGetVersion"); if (cb) { rovi->dwOSVersionInfoSize = sizeof(*rovi); if (STATUS_SUCCESS == cb(rovi)) { @@ -1702,7 +1715,7 @@ SameAttributesBG(const WCHAR_INFO *cell, const struct WCHAR_COLORINFO *info, con * nothing. **/ static void -CopyOutEx(copyoutctx_t *ctx, size_t pos, size_t cnt, unsigned flags) +CopyOutEx(copyoutctx_t *ctx, unsigned pos, unsigned cnt, unsigned flags) { const WCHAR_INFO *cursor = vio.image + pos, *end = cursor + cnt; const int rows = vio.rows, cols = vio.cols; @@ -2038,7 +2051,7 @@ CopyOutEx2(copyoutctx_t *ctx, size_t pos, size_t cnt, unsigned flags) * nothing. **/ static void -UnderOutEx(copyoutctx_t *ctx, size_t pos, size_t cnt) +UnderOutEx(copyoutctx_t *ctx, unsigned pos, unsigned cnt) { const WCHAR_INFO *cursor = vio.image + pos, *end = cursor + cnt; const int rows = vio.rows, cols = vio.cols; @@ -2109,7 +2122,7 @@ UnderOutEx(copyoutctx_t *ctx, size_t pos, size_t cnt) * nothing. **/ static void -StrikeOutEx(copyoutctx_t *ctx, size_t pos, size_t cnt) +StrikeOutEx(copyoutctx_t *ctx, unsigned pos, unsigned cnt) { const WCHAR_INFO *cursor = vio.image + pos, *end = cursor + cnt; const int rows = vio.rows, cols = vio.cols; @@ -2548,7 +2561,7 @@ consolefontcreate(int height, int width, int weight, int italic, const char *fac } -static void __inline +static __inline void WCHAR_BUILD(const uint32_t ch, const struct WCHAR_COLORINFO *info, WCHAR_INFO *ci) { ci->Info = *info; @@ -2626,7 +2639,8 @@ parse_color(const char *color, const char *defname, const struct attrmap *map, i const int len = (int)(a - color); strncpy(t_name, color, sizeof(t_name)-1);// remove attribute component. - if (len < sizeof(t_name)) t_name[len] = 0; + if (len < (int)sizeof(t_name)) + t_name[len] = 0; color = t_name; *attr = parse_attributes(a); @@ -3771,4 +3785,4 @@ vio_putc(unsigned ch, unsigned cnt, int move) } } -/*end*/ \ No newline at end of file +/*end*/ diff --git a/gr/termemu_vio.h b/gr/termemu_vio.h index fc86f421..405e4d87 100644 --- a/gr/termemu_vio.h +++ b/gr/termemu_vio.h @@ -1,14 +1,14 @@ #ifndef TERMEMU_VIO_H_INCLUDED #define TERMEMU_VIO_H_INCLUDED #include -__CIDENT_RCSID(termemu_vio_h,"$Id: termemu_vio.h,v 1.4 2021/06/10 06:13:02 cvsuser Exp $") +__CIDENT_RCSID(termemu_vio_h,"$Id: termemu_vio.h,v 1.5 2022/05/26 16:41:38 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ /* * libtermemu console driver * - * Copyright (c) 2007, 2012 - 2020 Adam Young. + * Copyright (c) 2007, 2012 - 2022 Adam Young. * * This file is part of the GRIEF Editor. * @@ -123,6 +123,7 @@ LIBVIO_API int vio_screenbuffersize(void); LIBVIO_API int vio_open(int *rows, int *cols); LIBVIO_API void vio_close(void); +LIBVIO_API void vio_config_truecolor(int truecolor); LIBVIO_API int vio_winch(int *rows, int *cols); LIBVIO_API void vio_get_size(int *rows, int *cols); LIBVIO_API int vio_toggle_size(int *rows, int *cols); diff --git a/gr/ttyterm.c.001 b/gr/ttyterm.c.001 deleted file mode 100644 index 8242a42c..00000000 --- a/gr/ttyterm.c.001 +++ /dev/null @@ -1,5219 +0,0 @@ -#include -__CIDENT_RCSID(gr_ttyterm_c,"$Id: ttyterm.c,v 1.110 2021/04/05 08:04:31 cvsuser Exp $") - -/* -*- mode: c; indent-width: 4; -*- */ -/* $Id: ttyterm.c,v 1.110 2021/04/05 08:04:31 cvsuser Exp $ - * TTY driver termcap/terminfo based. - * - * - * This file is part of the GRIEF Editor. - * - * The GRIEF Editor is free software: you can redistribute it - * and/or modify it under the terms of the GRIEF Editor License. - * - * The GRIEF Editor 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 - * License for more details. - * ==end== - */ - -// #define ED_LEVEL 2 - -#include - -#if !defined(USE_VIO_BUFFER) && !defined(DJGPP) - -#if defined(__CYGWIN__) -#include /* GetConsoleOutputCP() */ -#include /* uname */ -#endif - -#include -#include /* gputenvv(), ggetenv() */ - - -#if defined(_VMS) -#include -#include -#include -#include -#include -#include -#endif - -#if defined(HAVE_LIBNCURSESW) -#if defined(HAVE_NCURSESW_CURSESW_H) -#include -#include -#include -#elif defined(HAVE_NCURSESW_CURSES_H) -#include -#include -#include -#elif defined(HAVE_NCURSESW_H) -#include -#if defined(HAVE_TERMCAP_H) -#include -#endif -#if defined(HAVE_TERM_H) -#include -#endif -#else /*!HAVE_NCURSESW_CURSES_H || HAVE_NCURSESW_H*/ -#error "HAVE_LIBNCURSEW defined yet missing headers, check config" -#endif - -#elif defined(HAVE_LIBNCURSES) -#if defined(HAVE_NCURSES_NCURSES_H) -#include -#include -#include -#elif defined(HAVE_NCURSES_CURSES_H) -#include -#include -#include -#elif defined(HAVE_NCURSES_H) -#include -#if defined(HAVE_TERMCAP_H) -#include -#endif -#if defined(HAVE_TERM_H) -#include -#endif -#else /*!HAVE_NCURSES_CURSES_H || HAVE_NCURSES_H*/ -#error "HAVE_LIBNCURSE defined yet missing headers, check config" -#endif - -#elif defined(HAVE_LIBCURSES) -#if defined(HAVE_CURSES_H) -#include -#if defined(HAVE_TERMCAP_H) -#include -#endif -#if defined(HAVE_TERM_H) -#if defined(HAVE_TERMIO_H) -#include /* solaris (SGTTY definition) */ -#endif -#include -#else /* missing prototypes */ -extern char * tgetstr(char *, char **); -extern char * tgoto(const char * , int a, int b); -extern char * tparm(const char *, ...); -#endif -#else /*!HAVE_CURSES_H*/ -#error "HAVE_LIBCURSES defined yet missing headers, check config" -#endif - -#elif defined(HAVE_LIBTERMCAP) -#if defined(HAVE_TERMCAP_H) -#include -#else /*HAVE_TERMCAP_H*/ -#error "HAVE_LIBTERMCAP defined yet missing headers, check config" -#endif - -#elif defined(HAVE_LIBTERMLIB) -#include -#define HAVE_TERMCAP - -#else -#include "edtermcap.h" /* use local implementation -- BAD */ -#endif - -#if defined(HAVE_TERMINFO) && defined(HAVE_TERMCAP) -#define XF_TERMCAP if (xf_termcap) /* dynamic selection */ -#define XF_TERMINFO if (! xf_termcap) -#else -#if !defined(HAVE_TERMINFO) && !defined(HAVE_TERMCAP) -#error "no terminal interface style defined (TERMINFO nor TERMCAP), check cofig" -#endif -#define XF_TERMCAP -#define XF_TERMINFO -#endif - -#if !defined(HAVE_OSPEED) && !defined(__CYGWIN__) && !defined(sun) && \ - defined(OSPEED_EXTERN) /* ospeed available? (diag only) */ -#define HAVE_OSPEED -extern int ospeed; -#endif - -#if defined(HAVE_OUTFUNTYPE) /* tputs() interface */ -#define TPUTS_OUTFUNC (outfuntype) -#define TPUTS_OUTTYPE int -#elif defined(TPUTS_TAKES_CHAR) -#define TPUTS_OUTFUNC (int (*)(char)) -#define TPUTS_OUTTYPE char -#else -#define TPUTS_OUTFUNC (int (*)(int)) -#define TPUTS_OUTTYPE int -#endif - -#include /* needs to be after [n]curses.h */ -#include /* str_...()/sxprintf() */ - -#include "accum.h" /* acc_ ... */ -#include "asciidefs.h" -#include "cmap.h" /* cmap ... */ -#include "color.h" /* color ... */ -#include "debug.h" /* trace ... */ -#include "display.h" -#include "echo.h" -#include "eval.h" /* get_str() ... */ -#include "getkey.h" /* io_... */ -#include "keyboard.h" -#include "line.h" -#include "main.h" -#include "map.h" -#include "mchar.h" /* mchar_...() */ -#include "mouse.h" -#include "playback.h" -#include "procspawn.h" -#include "system.h" -#include "tty.h" -#include "undo.h" -#include "window.h" - -#define ANSI_COLORS 16 -#define XTERM_COLORS 16 -#define NOCOLOR 0x7fff - -typedef struct { - const char * termcapname; /* termcap name */ - const char * terminfoname; /* terminfo name */ - const char * comment; /* comment string */ - void * token; /* optional user token */ -#define TC_DESC(__desc) __desc -#define TC_TOKEN(__token) (void *)(__token) - - union { - const char *i_str; - int i_val; - } value; /* value */ -} Term_t; - -static void term_open(scrprofile_t *profile); -static void term_ready(int repaint, scrprofile_t *profile); -static void term_feature(int ident, scrprofile_t *profile); -static void term_display(void); -static int term_control(int action, int param, ...); -static void term_close(void); -static int hasfeature(const char *term, const char *what); - -static const char * ttisetup(void); -static const char * ttiname(const Term_t *ti); -static const char * ttigetstr(const Term_t *ti); -static int ttigetnum(const Term_t *ti); -static int ttigetflag(const Term_t *ti); - -static int term_xtermlike(const char *term); - -static void acs_dump(const char *bp); -static const char * acs_box_characters(const char *bp); -static int acs_locale_breaks(void); - -static void term_tidy(void); -static void term_move(int row, int col); -static int term_cursor(int visible, int imode, int virtual_space); -static int term_names(const char *title, const char *icon); -static void term_beep(int freq, int duration); - -static void term_colors(void); -static void term_fgbg(void); -static const char * fgbg_value(const char *src, int *result); -static unsigned fgbg_import(unsigned edefault, int udefault); - -static void xterm_colors(const char *value); -static int xterm_colors_get(char *buffer, int length); -static int xterm_colors_set(const char *value); - -static int term_isutf8(void); -static int term_identification(void); -static int term_read(char *buf, int blen, accint_t tmo); - -static __CINLINE void term_graphic_enter(void); -static __CINLINE void term_graphic_exit(void); - -static void term_clear(void); -static void term_zero(int restore); -static void term_flush(void); -static void term_sizeget(int *nrow, int *ncol); - -static void term_putc(vbyte_t c); -static int term_eeol(void); -static int term_ce(void); -static int term_lastsafe(void); -static void term_eeop(int restore); -static void term_repeat(int cnt, vbyte_t fill, int where); -static int term_insl(int row, int bot, int nlines, vbyte_t fillcolor); -static int term_dell(int row, int bot, int nlines, vbyte_t fillcolor); -static void term_scrollset(int top, int bot); -static void term_scrollreset(void); -static void term_attr(vbyte_t color); -static void term_styleon(unsigned mode); -static void term_styleoff(void); -static void term_colorreset(void); -static int term_cost(const char *s); - -static void ttputpad(const char *str); -static void ttputctl(const char *str, int a); -static void ttputctl2(const char *str, int a, int b); -static void ttprintf(const char *str, ...); -static void ttprintf2(const char *str, ...); - -static void ega_switch(int flag); - -/* - * This is the output buffer. NOBUF is how many bytes we can put in the buffer. We - * leave a lot of room for expansion because a single character may cause us to - * output multiple characters (e.g. printing top bit or graphics characters). - */ -#define NOOVFLOW 100 -#define NOBUF ((8 * 1024) - NOOVFLOW) - -static unsigned t_count; -static unsigned char t_buffer[NOBUF + NOOVFLOW]; - -/* - * Termcap buffer - */ -#define TC_SLEN (1024 * 32) /* 32k - tgetent wants >= 16k */ - -#if defined(HAVE_TERMCAP) -static char * tcapcursor; -static char tcapbuffer[TC_SLEN]; /* termcap buffer */ -static char tcapstrings[TC_SLEN]; /* termcap local storage */ -#endif - -/* - * Terminate attributes - */ -#define TA_XTERM 0x0001 -#define TA_VT100LIKE 0x0002 -#define TA_XTERMLIKE 0x0004 - -#define TA_LINUX 0x0010 -#define TA_CYGWIN 0x0020 -#define TA_KONSOLE 0x0040 -#define TA_SCREEN 0x0080 -#define TA_MINTTY 0x0100 - -#define TA_DARK 0x1000 /* generally dark background */ -#define TA_LIGHT 0x2000 /* light */ -#define TA_MONO 0x4000 /* mono terminal */ - -static unsigned t_attributes; /* attributes */ -static int t_charout; /* number of characters output. */ -static unsigned t_insdel; /* do we have both insert & delete line? */ -static int t_padchar = -1; /* pad character (if any) */ -static int t_acs_locale_breaks; - -/* - * Terminate status - */ -static unsigned t_gmode; /* graphics character set active */ -static int t_cost; /* terminal costing accumulator */ -static unsigned t_specials; /* special bits */ - -/* - * Color control - */ -static char t_colorsorg[XTERM_COLORS * 32]; -static char t_colorsuser[XTERM_COLORS * 32]; - - -/* - * Cached termap controls - * - * References: - * ANSI Standard X3.64-1979. - * X/Open System Interface Definitions, Issue 4, Version 2. - * - * http://www.xfree86.org/current/ctlseqs.html - * - * http://dickey.his.com/xterm/xterm.faq.html - * - * http://frexx.de/xterm-256-notes - * - * http://en.wikipedia.org/wiki/ANSI_escape_code - */ -static int - tf_gn, /* generic terminal. */ - tf_hc, /* hard-copy terminal. */ - tf_npc, /* no pad character. */ - tf_xonoff, /* xon/xoff required. */ - tf_am, /* has auto-margins. */ - tf_xn, /* the cursor wraps in a strange way. */ - tf_hz, /* no hazel line support. */ - tf_km, /* meta key sets msb */ - tf_LP, /* last column safe. */ - tf_NL, /* move down using \n. */ - tf_bs, /* move left using ^H. */ - tf_Colors, /* max colors */ - tf_Pairs, /* max color-pairs */ - tf_ut, /* screen erased with background color. */ - tf_be, /* back color erase (xterm). */ - tf_xs, tf_xt, /* attribute clear mode */ - tf_ms; /* save to move cursor whilst standout/underlined */ - -static int - tn_sg, /* number of glitches, 0 for invisable, -1 for none */ - tn_li, tn_co, /* lines/columns */ - tn_NC; /* attributes which dont mix with colors */ - -static const char - *tc_ti, /* Term init -- start using cursor motion. */ - *tc_te, /* Term end --- end using cursor motion. */ - *tc_ke, /* Enter keypad mode. */ - *tc_ks, /* Exit keypad mode. */ - *tc_rs, /* Reset sequence. */ - *tc_am_on, /* Turn on automatic margins. */ - *tc_bl, /* Bell. */ - - *tc_cm, /* Cursor motion. */ - *tc_ho, /* Home cursor. */ - *tc_ll, /* Left-end cursor. */ - *tc_cr, /* Cursor newline. */ - *tc_up, /* Cursor up on line. */ - *tc_pUP, /* Cursor up on line - parameterised. */ - *tc_do, /* Cursor down. */ - *tc_pDO, /* Cursor down - parameterised. */ - *tc_le, /* Cursor left (new style). */ - *tc_bc, /* Cursor left (old style). */ - *tc_pBC, /* Cursor left - parameterised. */ - *tc_nd, /* Cursor right. */ - *tc_pRI, /* Cursor right - parameterised. */ - *tc_cv, /* Cursor vertical movement. */ - *tc_ch, /* Cursor horz movement. */ - - *tc_vs, /* Enhance the cursor. */ - *tc_ve, /* Normal cursor. */ - *tc_vb, /* Visual bell. */ - *tc_vi, /* Hide cursor. */ - - *tc_cs, /* Set scroll region. */ - *tc_cS, /* Set scroll region, alt form (see Emacs). */ - *tc_sf, /* Forward index (used with scroll region). */ - *tc_sr, /* Back index (used with scroll region). */ - *tc_pSF, /* Forward index */ - *tc_pSR, /* Back index */ - - *tc_al, /* Add line */ - *tc_dl, /* Delete line */ - *tc_pAL, /* Parameterized add line. */ - *tc_pDL, /* Parameterized delete line. */ - - *tc_pc, /* Padding character */ - *tc_dc, /* Delete a character. */ - *tc_pDC, /* Parameterized character delete. */ - *tc_ic, /* Insert a single space. */ - *tc_cb, /* Clear to beginning of line. */ - *tc_cd, /* Clear to end of display. */ - *tc_ce, /* Clear to end of line. */ - *tc_cl, /* Clear screen. */ - *tc_rp, /* repeat #1 #2 times */ - *tc_ech, /* erase #1 characters */ - *tc_im, /* Insert mode. */ - *tc_ei, /* End insert mode. */ - - *tc_oc, *tc_op, /* Reset colors. */ - *tc_me, /* Turn off all attributes. */ - *tc_mm, *tc_mo, /* Turn on/off meta mode (8th-bit on). */ - *tc_so, *tc_se, /* Start/end standout mode. */ - *tc_us, *tc_ue, /* Turn on/off underline mode. */ - *tc_mb, /* Turn on blinking. */ - *tc_md, /* Make bold. */ - *tc_ZH, *tc_ZR, /* Italic (on/off). */ - *tc_mr, *tc_ZX, /* Reverse (on/off). */ - *tc_sa; /* Attribute set. */ - -static const char - *tc_acs_start, /* as */ - *tc_acs_end, /* ae */ - *tc_acs_enable; /* enable ACS */ - -static unsigned char /* ac */ - tc_acs_map[129]; - -static const char tc_graphic_default[] = - "a:j+k+l+m+q-t+u+v+w+x|n+`+f\\g#~o,<+>.v-^h#0#"; - -static const char - *tc_graphic_pairs, - *tc_box_characters; - -static const char - *tc_ANSI_Color_Fg, *tc_Color_Fg, /* color selection */ - *tc_ANSI_Color_Bg, *tc_Color_Bg; - -typedef struct { - char ident; /* internal identifier */ - const char * name; /* desc */ -} GraphicChars_t; - -enum { - /* - * ACC mappings, includes ncurse's extensions - */ - TACS_STERLING = '}', - TACS_DARROW = '.', - TACS_LARROW = ',', - TACS_RARROW = '+', - TACS_UARROW = '-', - TACS_BOARD = 'h', - TACS_BULLET = '~', - TACS_CKBOARD = 'a', - TACS_DEGREE = 'f', - TACS_DIAMOND = '`', - TACS_GEQUAL = 'z', - TACS_PI = '{', - TACS_HLINE = 'q', - TACS_LANTERN = 'i', - TACS_PLUS = 'n', - TACS_LEQUAL = 'y', - TACS_LLCORNER = 'm', - TACS_LRCORNER = 'j', - TACS_NEQUAL = '|', - TACS_PLMINUS = 'g', - TACS_S1 = 'o', - TACS_S3 = 'p', - TACS_S7 = 'r', - TACS_S9 = 's', - TACS_BLOCK = '0', - TACS_TTEE = 'w', - TACS_RTEE = 'u', - TACS_LTEE = 't', - TACS_BTEE = 'v', - TACS_ULCORNER = 'l', - TACS_URCORNER = 'k', - TACS_VLINE = 'x' - }; - -static GraphicChars_t term_characters[] = { /* graphic characters */ - { TACS_STERLING, TC_DESC("UK pound sign") }, - { TACS_DARROW, TC_DESC("arrow pointing down") }, - { TACS_LARROW, TC_DESC("arrow pointing left") }, - { TACS_RARROW, TC_DESC("arrow pointing right") }, - { TACS_UARROW, TC_DESC("arrow pointing up") }, - { TACS_BOARD, TC_DESC("board of squares") }, - { TACS_BULLET, TC_DESC("bullet") }, - { TACS_CKBOARD, TC_DESC("checker board (stipple)") }, - { TACS_DEGREE, TC_DESC("degree symbol") }, - { TACS_DIAMOND, TC_DESC("diamond") }, - { TACS_GEQUAL, TC_DESC("greater-than-or-equal-to") }, - { TACS_PI, TC_DESC("greek pi") }, - { TACS_HLINE, TC_DESC("horizontal line") }, - { TACS_LANTERN, TC_DESC("lantern symbol") }, - { TACS_PLUS, TC_DESC("large plus or crossover") }, - { TACS_LEQUAL, TC_DESC("less-than-or-equal-to") }, - { TACS_LLCORNER, TC_DESC("lower left corner") }, - { TACS_LRCORNER, TC_DESC("lower right corner") }, - { TACS_NEQUAL, TC_DESC("not-equal") }, - { TACS_PLMINUS, TC_DESC("plus/minus") }, - { TACS_S1, TC_DESC("scan line 1") }, - { TACS_S3, TC_DESC("scan line 3") }, - { TACS_S7, TC_DESC("scan line 7") }, - { TACS_S9, TC_DESC("scan line 9") }, - { TACS_BLOCK, TC_DESC("solid square block") }, - { TACS_TTEE, TC_DESC("tee pointing down") }, - { TACS_RTEE, TC_DESC("tee pointing left") }, - { TACS_LTEE, TC_DESC("tee pointing right") }, - { TACS_BTEE, TC_DESC("tee pointing up") }, - { TACS_ULCORNER, TC_DESC("upper left corner") }, - { TACS_URCORNER, TC_DESC("upper right corner") }, - { TACS_VLINE, TC_DESC("vertical line") } - }; - -static Term_t term_strings[] = { /* strings - termcap/terminfo elements */ - { "ac", "acsc", TC_DESC("acs characters"), &tc_graphic_pairs }, - { "bt", "cbt", TC_DESC("back tab")}, - { "bl", "bel", TC_DESC("audible signal (bell)"), &tc_bl }, - { "cr", "cr", TC_DESC("carriage return"), &tc_cr }, - { "ZA", "cpi", TC_DESC("change number of characters per inch") }, - { "ZB", "lpi", TC_DESC("change number of lines per inch") }, - { "ZC", "chr", TC_DESC("change horizontal resolution") }, - { "ZD", "cvr", TC_DESC("change vertical resolution") }, - { "cs", "csr", TC_DESC("change region to line #1 to line #2"), &tc_cs }, - { "rP", "rmp", TC_DESC("like ip but when in insert mode") }, - { "ct", "tbc", TC_DESC("clear all tab stops") }, - { "MC", "mgc", TC_DESC("clear right and left soft margins") }, - { "cl", "clear", TC_DESC("clear screen and home cursor"), &tc_cl }, - { "cb", "el1", TC_DESC("clear to beginning of line"), &tc_cb }, - { "ce", "el", TC_DESC("clr eol"), &tc_ce }, - { "cd", "ed", TC_DESC("clear to end of screen"), &tc_cd }, - { "ch", "hpa", TC_DESC("horizontal position #1, absolute"), &tc_ch }, - { "CC", "cmdch", TC_DESC("terminal settable cmd character in prototype !?") }, - { "CW", "cwin", TC_DESC("define a window #1 from #2, #3 to #4, #5") }, - { "cm", "cup", TC_DESC("move to row #1 columns #2"), &tc_cm }, - { "do", "cud1", TC_DESC("down one line"), &tc_do }, - { "ho", "home", TC_DESC("home cursor (if no cup)"), &tc_ho }, - { "vi", "civis", TC_DESC("make cursor invisible"), &tc_vi }, - { "le", "cub1", TC_DESC("move left one space"), &tc_le }, - { "CM", "mrcup", TC_DESC("memory relative cursor addressing") }, - { "ve", "cnorm", TC_DESC("make cursor appear normal (undo civis/cvvis)"), &tc_ve }, - { "nd", "cuf1", TC_DESC("move right one space"), &tc_nd }, - { "ll", "ll", TC_DESC("last line, first column (if no cup)"), &tc_ll }, - { "up", "cuu1", TC_DESC("up one line"), &tc_up }, - { "vs", "cvvis", TC_DESC("make cursor very visible"), &tc_vs }, - { "ZE", "defc", TC_DESC("define a character") }, - { "dc", "dch1", TC_DESC("delete character"), &tc_dc }, - { "dl", "dl1", TC_DESC("delete line"), &tc_dl }, - { "DI", "dial", TC_DESC("dial number #1") }, - { "ds", "dsl", TC_DESC("disable status line") }, - { "DK", "dclk", TC_DESC("display clock at (#1,#2)") }, - { "hd", "hd", TC_DESC("half a line down") }, - { "eA", "enacs", TC_DESC("enable alternate char set"), &tc_acs_enable }, - { "as", "smacs", TC_DESC("enter alt charset mode"), &tc_acs_start }, - { "SA", "smam", TC_DESC("turn on automatic margins"), &tc_am_on }, - { "mb", "blink", TC_DESC("turn on blinking"), &tc_mb }, - { "md", "bold", TC_DESC("turn on bold (extra bright) mode"), &tc_md }, - { "ti", "smcup", TC_DESC("string to start programs using cup"), &tc_ti }, - { "dm", "smdc", TC_DESC("enter delete mode") }, - { "mh", "dim", TC_DESC("turn on half-bright mode") }, - { "ZF", "swidm", TC_DESC("enter double-wide mode") }, - { "ZG", "sdrfq", TC_DESC("enter draft-quality mode") }, - { "im", "smir", TC_DESC("enter insert mode"), &tc_im }, - { "ZH", "sitm", TC_DESC("enter italic mode"), &tc_ZH }, - { "ZI", "slm", TC_DESC("start leftward carriage motion") }, - { "ZJ", "smicm", TC_DESC("start micro-motion mode") }, - { "ZK", "snlq", TC_DESC("enter NLQ mode") }, - { "ZL", "snrmq", TC_DESC("enter normal-quality mode") }, - { "mp", "prot", TC_DESC("turn on protected mode") }, - { "mr", "rev", TC_DESC("turn on reverse video mode"), &tc_mr }, - { "mk", "invis", TC_DESC("turn on blank mode (characters invisible)") }, - { "ZM", "sshm", TC_DESC("enter shadow-print mode") }, - { "so", "smso", TC_DESC("begin standout mode"), &tc_so }, - { "ZN", "ssubm", TC_DESC("enter subscript mode") }, - { "ZO", "ssupm", TC_DESC("enter superscript mode") }, - { "us", "smul", TC_DESC("begin underline mode"), &tc_us }, - { "ZP", "sum", TC_DESC("start upward carriage motion") }, - { "SX", "smxon", TC_DESC("turn on xon/xoff handshaking") }, - { "ec", "ech", TC_DESC("erase #1 characters"), &tc_ech }, - { "ae", "rmacs", TC_DESC("exit alt charset mode"), &tc_acs_end }, - { "RA", "rmam", TC_DESC("turn off automatic margins") }, - { "me", "sgr0", TC_DESC("turn off all attributes"), &tc_me }, - { "te", "rmcup", TC_DESC("strings to end programs using cup"), &tc_te }, - { "ed", "rmdc", TC_DESC("end delete mode") }, - { "ZQ", "rwidm", TC_DESC("end double-wide mode") }, - { "ei", "rmir", TC_DESC("exit insert mode"), &tc_ei }, - { "ZR", "ritm", TC_DESC("end italic mode"), &tc_ZR }, - { "ZS", "rlm", TC_DESC("end left-motion mode") }, - { "ZU", "rmicm", TC_DESC("end shadow-print mode") }, - { "ZT", "rshm", TC_DESC("end micro-motion mode") }, - { "se", "rmso", TC_DESC("exit standout mode"), &tc_se }, - { "ZV", "rsubm", TC_DESC("exit_subscript_mode") }, - { "ZW", "rsupm", TC_DESC("end superscript mode") }, - { "ue", "rmul", TC_DESC("exit underline mode"), &tc_ue }, - { "ZX", "rum", TC_DESC("end reverse character motion"), &tc_ZX }, - { "RX", "rmxon", TC_DESC("turn off xon/xoff handshaking") }, - { "PA", "pause", TC_DESC("pause for 2-3 seconds") }, - { "fh", "hook", TC_DESC("flash switch hook") }, - { "vb", "flash", TC_DESC("visible bell (may not move cursor)"), &tc_vb }, - { "ff", "ff", TC_DESC("hardcopy terminal page eject") }, - { "fs", "fsl", TC_DESC("return from status line") }, - { "WG", "wingo", TC_DESC("go to window #1") }, - { "HU", "hup", TC_DESC("hang-up phone") }, - { "i1", "is1", TC_DESC("initialization string") }, - { "is", "is2", TC_DESC("initialization string") }, - { "i2", NULL, TC_DESC("secondary initialization string") }, - { "i3", "is3", TC_DESC("initialization string") }, - { "if", "if", TC_DESC("name of initialization file") }, - { "iP", "iprog", TC_DESC("path name of program for initialization") }, - { "Ic", "initc", TC_DESC("initialize color #1 to (#2,#3,#4)") }, - { "Ip", "initp", TC_DESC("initialize color pair #1 to fg=(#2,#3,#4), bg=(#5,#6,#7)") }, - { "ic", "ich1", TC_DESC("insert character"), &tc_ic }, - { "al", "il1", TC_DESC("insert line"), &tc_al }, - { "ip", "ip", TC_DESC("insert padding after inserted character") }, - { "ke", "rmkx", TC_DESC("leave 'keyboard_transmit' mode"), &tc_ke }, - { "ks", "smkx", TC_DESC("enter 'keyboard_transmit' mode"), &tc_ks }, - { "l0", "lf0", TC_DESC("label on function key f0 if not f0") }, - { "l1", "lf1", TC_DESC("label on function key f1 if not f1") }, - { "l2", "lf10", TC_DESC("label on function key f2 if not f2") }, - { "l3", "lf2", TC_DESC("label on function key f3 if not f3") }, - { "l4", "lf3", TC_DESC("label on function key f4 if not f4") }, - { "l5", "lf4", TC_DESC("label on function key f5 if not f5") }, - { "l6", "lf5", TC_DESC("label on function key f6 if not f6") }, - { "l7", "lf6", TC_DESC("label on function key f7 if not f7") }, - { "l8", "lf7", TC_DESC("label on function key f8 if not f8") }, - { "l9", "lf8", TC_DESC("label on function key f9 if not f9") }, - { "la", "lf9", TC_DESC("label on function key f10 if not f10") }, - { "Lf", "fln", TC_DESC("label format") }, - { "LF", "rmln", TC_DESC("turn off soft labels") }, - { "LO", "smln", TC_DESC("turn on soft labels") }, - { "mo", "rmm", TC_DESC("turn off meta mode"), &tc_mo }, - { "mm", "smm", TC_DESC("turn on meta mode (8th-bit on)"), &tc_mm }, - { "ZY", "mhpa", TC_DESC("like column_address in micro mode") }, - { "ZZ", "mcud1", TC_DESC("like cursor_down in micro mode") }, - { "Za", "mcub1", TC_DESC("like cursor_left in micro mode") }, - { "Zb", "mcuf1", TC_DESC("like cursor_right in micro mode") }, - { "Zc", "mvpa", TC_DESC("like row_address in micro mode") }, - { "Zd", "mcuu1", TC_DESC("like cursor_up in micro mode") }, - { "nw", "nel", TC_DESC("newline (behave like cr followed by lf)") }, - { "Ze", "porder", TC_DESC("match software bits to print-head pins") }, - { "oc", "oc", TC_DESC("set all color pairs to the original ones"), &tc_oc }, - { "op", "op", TC_DESC("set default pair to its original value"), &tc_op }, - { "pc", "pad", TC_DESC("padding char (instead of null)"), &tc_pc }, - { "DC", "dch", TC_DESC("delete #1 chars"), &tc_pDC }, - { "DL", "dl", TC_DESC("parm_delete_line"), &tc_pDL }, - { "DO", "cud", TC_DESC("down #1 lines"), &tc_pDO }, - { "Zf", "mcud", TC_DESC("like parm down cursor in micro mode") }, - { "IC", "ich", TC_DESC("insert #1 chars") }, - { "SF", "indn", TC_DESC("scroll forward #1 lines"), &tc_pSF }, - { "AL", "il", TC_DESC("parm insert line"), &tc_pAL }, - { "LE", "cub", TC_DESC("move #1 chars to the left"), &tc_pBC }, - { "Zg", "mcub", TC_DESC("Like parm left cursor in micro mode") }, - { "RI", "cuf", TC_DESC("parm right cursor"), &tc_pRI }, - { "Zh", "mcuf", TC_DESC("Like parm right cursor in micro mode") }, - { "SR", "rin", TC_DESC("scroll back #1 lines"), &tc_pSR }, - { "UP", "cuu", TC_DESC("up #1 lines"), &tc_pUP }, - { "Zi", "mcuu", TC_DESC("Like parm_up_cursor in micro mode") }, - { "pk", "pfkey", TC_DESC("program function key #1 to type string #2") }, - { "pl", "pfloc", TC_DESC("program function key #1 to execute string #2") }, - { "px", "pfx", TC_DESC("program function key #1 to transmit string #2") }, - { "pn", "pln", TC_DESC("program label #1 to show string #2") }, - { "ps", "mc0", TC_DESC("print contents of screen") }, - { "pO", "mc5p", TC_DESC("turn on printer for #1 bytes") }, - { "pf", "mc4", TC_DESC("turn off printer") }, - { "po", "mc5", TC_DESC("turn on printer") }, - { "PU", "pulse", TC_DESC("select pulse dialling") }, - { "QD", "qdial", TC_DESC("dial number #1 without checking") }, - { "RC", "rmclk", TC_DESC("remove clock") }, - { "rp", "rep", TC_DESC("repeat char #1 #2 times"), &tc_rp}, - { "RF", "rfi", TC_DESC("send next input char (for ptys)") }, - { "rs", NULL, TC_DESC("terminal reset string"), &tc_rs}, - { "r1", "rs1", TC_DESC("reset string") }, - { "r2", "rs2", TC_DESC("reset string") }, - { "r3", "rs3", TC_DESC("reset string") }, - { "rf", "rf", TC_DESC("name of reset file") }, - { "rc", "rc", TC_DESC("restore cursor to last position of sc") }, - { "cv", "vpa", TC_DESC("vertical position #1 absolute"), &tc_cv }, - { "sc", "sc", TC_DESC("save current cursor position") }, - { "sf", "ind", TC_DESC("scroll text up"), &tc_sf }, - { "sr", "ri", TC_DESC("scroll text down"), &tc_sr }, - { "Zj", "scs", TC_DESC("select character set") }, - { "sa", "sgr", TC_DESC("define video attributes #1-#9 (PG9)"), &tc_sa }, - { "Sb", "setb", TC_DESC("set background (color)"), &tc_Color_Bg }, - { "Zk", "smgb", TC_DESC("set bottom margin at current line") }, - { "Zl", "smgbp", TC_DESC("set bottom margin at line #1 or #2 lines from bottom") }, - { "SC", "sclk", TC_DESC("set clock, #1 hrs #2 mins #3 secs") }, - { "sp", "scp", TC_DESC("set current color pair to #1") }, - { "Sf", "setf", TC_DESC("set foreground (color)"), &tc_Color_Fg }, - { "ML", "smgl", TC_DESC("set left soft margin") }, - { "Zm", "smglp", TC_DESC("set left (right) margin at column #1 (#2)") }, - { "MR", "smgr", TC_DESC("set right soft margin") }, - { "Zn", "smgrp", TC_DESC("set right margin at column #1") }, - { "st", "hts", TC_DESC("set a tab in every row, current columns") }, - { "Zo", "smgt", TC_DESC("set top margin at current line") }, - { "Zq", "smgtp", TC_DESC("start printing bit image braphics") }, - { "wi", "wind", TC_DESC("current window is lines #1-#2 cols #3-#4") }, - { "Zq", "sbim", TC_DESC("start bit image") }, - { "Zr", "scsd", TC_DESC("start character set definition") }, - { "Zs", "rbim", TC_DESC("stop printing bit image graphics") }, - { "Zt", "rcsd", TC_DESC("end definition of character aet") }, - { "Zu", "subcs", TC_DESC("list of subscriptable characters") }, - { "Zv", "supcs", TC_DESC("list of superscriptable characters") }, - { "ta", "ht", TC_DESC("tab to next 8-space hardware tab stop") }, - { "Zw", "docr", TC_DESC("printing any of these chars causes CR") }, - { "ts", "tsl", TC_DESC("move to status line") }, - { "TO", "tone", TC_DESC("select touch tone dialing") }, - { "uc", "uc", TC_DESC("underline char and move past it") }, - { "hu", "hu", TC_DESC("half a line up") }, - { "u0", "u0", TC_DESC("user string #0") }, - { "u1", "u1", TC_DESC("user string #1") }, - { "u2", "u2", TC_DESC("user string #2") }, - { "u3", "u3", TC_DESC("user string #3") }, - { "u4", "u4", TC_DESC("user string #4") }, - { "u5", "u5", TC_DESC("user string #5") }, - { "u6", "u6", TC_DESC("user string #6") }, - { "u7", "u7", TC_DESC("user string #7") }, - { "u8", "u8", TC_DESC("user string #8") }, - { "u9", "u9", TC_DESC("user string #9") }, - { "WA", "wait", TC_DESC("wait for dial-tone") }, - { "XF", "xoffc", TC_DESC("XOFF character") }, - { "XN", "xonc", TC_DESC("XON character") }, - { "Zx", "zerom", TC_DESC("no motion for subsequent character") }, - - /* - * The following string capabilities are present in the SVr4.0 term - * structure, but were originally not documented in the man page. - */ - { "S8", "scesa", TC_DESC("alternate escape for scancode emulation") }, - { "Yv", "bicr", TC_DESC("move to beginning of same row") }, - { "Zz", "binel", TC_DESC("move to next row of the bit image") }, - { "Xy", "birep", TC_DESC("repeat bit image cell #1 #2 times") }, - { "Zy", "csnm", TC_DESC("list of character set names") }, - { "ci", "csin", TC_DESC("init sequence for multiple codesets") }, - { "Yw", "colornm", TC_DESC("give name for color #1") }, - { "Yx", "defbi", TC_DESC("define rectangualar bit image region") }, - { "dv", "devt", TC_DESC("indicate language/codeset support") }, - { "S1", "dispc", TC_DESC("display PC character") }, - { "Yy", "endbi", TC_DESC("end a bit-image region") }, - { "S2", "smpch", TC_DESC("enter PC character display mode") }, - { "S4", "smsc", TC_DESC("enter PC scancode mode") }, - { "S3", "rmpch", TC_DESC("exit PC character display mode") }, - { "S5", "rmsc", TC_DESC("exit PC scancode mode") }, - { "Gm", "getm", TC_DESC("curses should get button events") }, - { "Km", "kmous", TC_DESC("mouse event has occurred") }, - { "Mi", "minfo", TC_DESC("mouse status information") }, - { "S6", "pctrm", TC_DESC("PC terminal options") }, - { "xl", "pfxl", TC_DESC("program function key #1 to type string #2 and show string #3") }, - { "RQ", "reqmp", TC_DESC("request mouse position") }, - { "S7", "scesc", TC_DESC("escape for scancode emulation") }, - { "s0", "s0ds", TC_DESC("shift to code set 0 (EUC set 0, ASCII)") }, - { "s1", "s1ds", TC_DESC("shift to code set 1") }, - { "s2", "s2ds", TC_DESC("shift to code set 2") }, - { "s3", "s3ds", TC_DESC("shift to code set 3") }, - { "AB", "setab", TC_DESC("set ANSI color background"), &tc_ANSI_Color_Bg }, - { "AF", "setaf", TC_DESC("set ANSI color foreground"), &tc_ANSI_Color_Fg }, - { "Yz", "setcolor", TC_DESC("change to ribbon color #1") }, - { "ML", "smglr", TC_DESC("set both left and right margins to #1, #2") }, - { "YZ", "slines", TC_DESC("set page length to #1 lines") }, - { "MT", "smgtb", TC_DESC("sets both top and bottom margins to #1, #2") }, - - /* - * The XSI Curses standard added these. They are some post-4.1 versions - * of System V curses, e.g., Solaris 2.5 and IRIX 6.x. The ncurses term- - * cap names for them are invented; according to the XSI Curses standard, - * they have no termcap names. If your compiled terminfo entries use - * these, they may not be binary-compatible with System V terminfo - * entries after SVr4.1; beware! - */ - { "Xh", "ehhlm", TC_DESC("enter horizontal highlight mode") }, - { "Xl", "elhlm", TC_DESC("enter left highlight mode") }, - { "Xo", "elohlm", TC_DESC("enter low highlight mode") }, - { "Xr", "erhlm", TC_DESC("enter right highlight mode") }, - { "Xt", "ethlm", TC_DESC("enter top highlight mode") }, - { "Xv", "evhlm", TC_DESC("enter vertical highlight mode") }, - - /* - * Characters, Note: have only seen 'bx' under AIX, which must be ordered - * after "ac" for correct selection. - */ - { "G1", NULL, TC_DESC("single upper right") }, - { "G2", NULL, TC_DESC("single upper left") }, - { "G3", NULL, TC_DESC("single lower left") }, - { "G4", NULL, TC_DESC("single lower right") }, - { "GC", NULL, TC_DESC("single intersection") }, - { "GD", NULL, TC_DESC("tee pointing down") }, - { "GH", NULL, TC_DESC("single horizontal line") }, - { "GL", NULL, TC_DESC("tee pointing left") }, - { "GR", NULL, TC_DESC("tee pointing right") }, - { "GU", NULL, TC_DESC("tee pointing up") }, - { "GV", NULL, TC_DESC("single vertical line") }, - { "bx", NULL, TC_DESC("box chars primary set"), &tc_box_characters }, - - /* - * Others - */ - { "cS", NULL, TC_DESC("change region to line #1 to line #2, alt form"), &tc_cS}, - { "bc", NULL, TC_DESC("move left, if not ^H (old-style)"), &tc_bc}, - { "nl", NULL, TC_DESC("use to move down") }, - /* { "ko", NULL, TC_DESC("list of self-mapped keycaps") }, */ - /* { "ma", NULL, TC_DESC("map arrow keys rogue(1) motion keys") }, */ - { "ml", NULL, TC_DESC("memory lock above") }, - { "mu", NULL, TC_DESC("memory unlock") } - }; - -#if (XXX_KO) -/* - ko capability, consists of a comma-separated capability list. - For each capability, it should be assumed there is a keycap - that sends the string which is the value of that capability. - - String listing the other function keys the terminal has. - - This is a very obsolete way of describing the same - information found in the `kH' ... `kT' keys. - - The string contains a list of two-character termcap - capability names, separated by commas. The meaning is that - for each capability name listed, the terminal has a key which - sends the string which is the value of that capability. - - For example, the value `:ko=cl, ll, sf, sr:' says that the - terminal has four function keys which mean "clear screen", - "home down", "scroll forward" and "scroll reverse - */ -static const struct { - const char *from; - const char *to; -} ko_xlate[] = { - { "al", "kil1" }, /* insert line key */ - { "bt", "kcbt" }, /* back tab */ - { "cd", "ked" }, /* clear-to-eos key */ - { "ce", "kel" }, /* clear-to-eol key */ - { "cl", "kclr" }, /* clear key */ - { "ct", "tbc" }, /* clear all tabs */ - { "dc", "kdch1" }, /* delete char */ - { "dl", "kdl1" }, /* delete line */ - { "do", "kcud1" }, /* down key */ - { "ei", "krmir" }, /* exit insert key */ - { "ho", "khome" }, /* home key */ - { "ic", "kich1" }, /* insert char key */ - { "im", "kIC" }, /* insert-mode key */ - { "le", "kcub1" }, /* le key */ - { "nd", "kcuf1" }, /* nd key */ - { "nl", "kent" }, /* new line key */ - { "st", "khts" }, /* set-tab key */ - { "ta", "kcan" }, /* cancel */ - { "up", "kcuu1" }, /* up-arrow key */ - }; -#endif /*XXX_KO*/ - - -static Term_t term_numbers[] = { /* numeric - termcap/terminfo elements */ - /* - * standard - */ - { "MW", "wnum", TC_DESC("max number of defineable windows") }, - { "co", "cols", TC_DESC("number of columns"), &tn_co }, - { "it", "it", TC_DESC("tabs initially every # spaces") }, - { "Nl", "nlab", TC_DESC("number of labels") }, - { "lh", "lh", TC_DESC("rows in each label") }, - { "li", "lines", TC_DESC("number of lines on screen or page"), &tn_li }, - { "lm", "lm", TC_DESC("lines of memory if > line, 0 means varies") }, - { "lw", "lw", TC_DESC("columns in each label") }, - { "ma", "ma", TC_DESC("max combined attributes") }, - { "pb", "pb", TC_DESC("lowest baud rate needing padding") }, - { "sg", "xmc", TC_DESC("number of blank chars left by smso or rmso"), &tn_sg }, - { "vt", "vt", TC_DESC("virtual terminal number") }, - { "ws", "wsl", TC_DESC("number of columns within status line") }, - - /* - * SRV 4.0 color - */ - { "Co", "colors", TC_DESC("max color"), &tf_Colors }, - { "pa", "pairs", TC_DESC("max of color-pairs"), &tf_Pairs }, - { "NC", "ncv", TC_DESC("video attributes that cannot be used with colors"), &tn_NC }, - - /* - * The following numeric capabilities are present in the SVr4.0 term structure, - * but are not yet documented in the man page. They came in with SVr4's printer support. - */ - { "BT", NULL, TC_DESC("number of buttons on the mouse") }, - - /* - * Padding times - */ - { "dC", NULL, TC_DESC("msec of padding for carriage-return character") }, - { "dN", NULL, TC_DESC("msec of padding for newline (linefeed) character") }, - { "dB", NULL, TC_DESC("msec of padding for backspace character") }, - { "dF", NULL, TC_DESC("msec of padding for formfeed character") }, - { "dT", NULL, TC_DESC("msec of padding for tab character") } - }; - - -static Term_t term_keys[] = { /* keys - termcap/terminfo elements */ - { "!1", "kSAV", TC_DESC("shifted save key") }, - { "!2", "kSPD", TC_DESC("shifted suspend key") }, - { "!3", "kUND", TC_DESC("shifted undo key"), TC_TOKEN(KEY_REDO) }, - { "#1", "kHLP", TC_DESC("shifted help key") }, /* KEY_HELP */ - { "#2", "kHOM", TC_DESC("shifted home key"), TC_TOKEN(MOD_SHIFT|KEY_HOME) }, - { "#3", "kIC", TC_DESC("shifted insert-character key") }, - { "#4", "kLFT", TC_DESC("shifted left-arrow key") }, - { "%0", "krdo", TC_DESC("redo key"), TC_TOKEN(KEY_REDO) }, - { "%1", "khlp", TC_DESC("help key"), TC_TOKEN(KEY_HELP) }, - { "%2", "kmrk", TC_DESC("mark key") }, /* KEY_MARK */ - { "%3", "kmsg", TC_DESC("message key") }, - { "%4", "kmov", TC_DESC("move key") }, - { "%5", "knxt", TC_DESC("next key"), TC_TOKEN(KEY_NEXT) }, - { "%6", "kopn", TC_DESC("open key"), TC_TOKEN(KEY_OPEN) }, - { "%7", "kopt", TC_DESC("options key"), TC_TOKEN(KEY_MENU) }, - { "%8", "kprv", TC_DESC("previous key"), TC_TOKEN(KEY_PREV) }, - { "%9", "kprt", TC_DESC("print key") }, /* KEY_PRINT */ - { "%a", "kMSG", TC_DESC("shifted message key") }, - { "%b", "kMOV", TC_DESC("shifted move key") }, - { "%c", "kNXT", TC_DESC("shifted next key") }, - { "%d", "kOPT", TC_DESC("shifted options key") }, - { "%e", "kPRV", TC_DESC("shifted previous key") }, - { "%f", "kPRT", TC_DESC("shifted print key") }, - { "%g", "kRDO", TC_DESC("shifted redo key") }, - { "%h", "kRPL", TC_DESC("shifted replace key") }, - { "%i", "kRIT", TC_DESC("shifted right-arrow key") }, - { "%j", "kRES", TC_DESC("shifted resume key") }, - { "&0", "kCAN", TC_DESC("shifted cancel key") }, - { "&1", "kref", TC_DESC("reference key") }, - { "&2", "krfr", TC_DESC("refresh key") }, /* KEY_REFRESH */ - { "&3", "krpl", TC_DESC("replace key"), TC_TOKEN(KEY_REPLACE) }, - { "&4", "krst", TC_DESC("restart key") }, - { "&5", "kres", TC_DESC("resume key") }, - { "&6", "ksav", TC_DESC("save key"), TC_TOKEN(KEY_SAVE) }, - { "&7", "kspd", TC_DESC("suspend key") }, - { "&8", "kund", TC_DESC("undo key"), TC_TOKEN(KEY_UNDO_CMD) }, - { "&9", "kBEG", TC_DESC("shifted begin key") }, - { "*0", "kFND", TC_DESC("shifted find key") }, - { "*1", "kCMD", TC_DESC("shifted command key") }, - { "*2", "kCPY", TC_DESC("shifted copy key") }, - { "*3", "kCRT", TC_DESC("shifted create key") }, - { "*4", "kDC", TC_DESC("shifted delete-char") }, - { "*5", "kDL", TC_DESC("shifted delete-line key") }, - { "*6", "kslt", TC_DESC("select key") }, - { "*7", "kEND", TC_DESC("shifted end key"), TC_TOKEN(MOD_SHIFT|KEY_END) }, - { "*8", "kEOL", TC_DESC("shifted clear-to-end-of-line key") }, - { "*9", "kEXT", TC_DESC("shifted exit key") }, - { "@0", "kfnd", TC_DESC("find key"), TC_TOKEN(KEY_SEARCH) }, - { "@1", "kbeg", TC_DESC("begin key") }, - { "@2", "kcan", TC_DESC("cancel key"), TC_TOKEN(KEY_CANCEL) }, - { "@3", "kclo", TC_DESC("close key") }, - { "@4", "kcmd", TC_DESC("command key"), TC_TOKEN(KEY_COMMAND) }, - { "@5", "kcpy", TC_DESC("copy key"), TC_TOKEN(KEY_COPY_CMD) }, - { "@6", "kcrt", TC_DESC("create key") }, - { "@7", "kend", TC_DESC("end key"), TC_TOKEN(KEY_END) }, - { "@8", "kent", TC_DESC("enter/send key") }, - { "@9", "kext", TC_DESC("exit key"), TC_TOKEN(KEY_EXIT) }, - { "F1", "kf11", TC_DESC("F11 function key"), TC_TOKEN(F(11)) }, - { "F2", "kf12", TC_DESC("F12 function key"), TC_TOKEN(F(12)) }, - { "F3", "kf13", TC_DESC("F13 function key") /*, TC_TOKEN(F(13))*/ }, - { "F4", "kf14", TC_DESC("F14 function key") /*, TC_TOKEN(F(14))*/ }, - { "F5", "kf15", TC_DESC("F15 function key") /*, TC_TOKEN(F(15))*/ }, - { "F6", "kf16", TC_DESC("F16 function key") /*, TC_TOKEN(F(16))*/ }, - { "F7", "kf17", TC_DESC("F17 function key") /*, TC_TOKEN(F(17))*/ }, - { "F8", "kf18", TC_DESC("F18 function key") /*, TC_TOKEN(F(18))*/ }, - { "F9", "kf19", TC_DESC("F19 function key") /*, TC_TOKEN(F(19))*/ }, - { "FA", "kf20", TC_DESC("F20 function key") /*, TC_TOKEN(F(20))*/ }, - { "FB", "kf21", TC_DESC("F21 function key") }, - { "FC", "kf22", TC_DESC("F22 function key") }, - { "FD", "kf23", TC_DESC("F23 function key") }, - { "FE", "kf24", TC_DESC("F24 function key") }, - { "FF", "kf25", TC_DESC("F25 function key") }, - { "FG", "kf26", TC_DESC("F26 function key") }, - { "FH", "kf27", TC_DESC("F27 function key") }, - { "FI", "kf28", TC_DESC("F28 function key") }, - { "FJ", "kf29", TC_DESC("F29 function key") }, - { "FK", "kf30", TC_DESC("F30 function key") }, - { "FL", "kf31", TC_DESC("F31 function key") }, - { "FM", "kf32", TC_DESC("F32 function key") }, - { "FN", "kf33", TC_DESC("F33 function key") }, - { "FO", "kf34", TC_DESC("F34 function key") }, - { "FP", "kf35", TC_DESC("F35 function key") }, - { "FQ", "kf36", TC_DESC("F36 function key") }, - { "FR", "kf37", TC_DESC("F37 function key") }, - { "FS", "kf38", TC_DESC("F38 function key") }, - { "FT", "kf39", TC_DESC("F39 function key") }, - { "FU", "kf40", TC_DESC("F40 function key") }, - { "FV", "kf41", TC_DESC("F41 function key") }, - { "FW", "kf42", TC_DESC("F42 function key") }, - { "FX", "kf43", TC_DESC("F43 function key") }, - { "FY", "kf44", TC_DESC("F44 function key") }, - { "FZ", "kf45", TC_DESC("F45 function key") }, - { "Fa", "kf46", TC_DESC("F46 function key") }, - { "Fb", "kf47", TC_DESC("F47 function key") }, - { "Fc", "kf48", TC_DESC("F48 function key") }, - { "Fd", "kf49", TC_DESC("F49 function key") }, - { "Fe", "kf50", TC_DESC("F50 function key") }, - { "Ff", "kf51", TC_DESC("F51 function key") }, - { "Fg", "kf52", TC_DESC("F52 function key") }, - { "Fh", "kf53", TC_DESC("F53 function key") }, - { "Fi", "kf54", TC_DESC("F54 function key") }, - { "Fj", "kf55", TC_DESC("F55 function key") }, - { "Fk", "kf56", TC_DESC("F56 function key") }, - { "Fl", "kf57", TC_DESC("F57 function key") }, - { "Fm", "kf58", TC_DESC("F58 function key") }, - { "Fn", "kf59", TC_DESC("F59 function key") }, - { "Fo", "kf60", TC_DESC("F60 function key") }, - { "Fp", "kf61", TC_DESC("F61 function key") }, - { "Fq", "kf62", TC_DESC("F62 function key") }, - { "Fr", "kf63", TC_DESC("F63 function key") }, - { "K1", "ka1", TC_DESC("upper left of keypad"), TC_TOKEN(KEYPAD_7) }, - { "K2", "kb2", TC_DESC("center of keypad"), TC_TOKEN(KEYPAD_9) }, - { "K3", "ka3", TC_DESC("upper right of key-pad"), TC_TOKEN(KEYPAD_5) }, - { "K4", "kc1", TC_DESC("lower left of keypad"), TC_TOKEN(KEYPAD_1) }, - { "K5", "kc3", TC_DESC("lower right of key-pad"), TC_TOKEN(KEYPAD_3) }, - { "k0", "kf0", TC_DESC("F0 function key"), TC_TOKEN(F(10)) }, - { "k1", "kf1", TC_DESC("F1 function key"), TC_TOKEN(F(1)) }, - { "k2", "kf2", TC_DESC("F2 function key"), TC_TOKEN(F(2)) }, - { "k3", "kf3", TC_DESC("F3 function key"), TC_TOKEN(F(3)) }, - { "k4", "kf4", TC_DESC("F4 function key"), TC_TOKEN(F(4)) }, - { "k5", "kf5", TC_DESC("F5 function key"), TC_TOKEN(F(5)) }, - { "k6", "kf6", TC_DESC("F6 function key"), TC_TOKEN(F(6)) }, - { "k7", "kf7", TC_DESC("F7 function key"), TC_TOKEN(F(7)) }, - { "k8", "kf8", TC_DESC("F8 function key"), TC_TOKEN(F(8)) }, - { "k9", "kf9", TC_DESC("F9 function key"), TC_TOKEN(F(9)) }, - { "k;", "kf10", TC_DESC("F10 function key"), TC_TOKEN(F(10)) }, - { "kA", "kil1", TC_DESC("insert-line key") }, - { "kB", "kcbt", TC_DESC("back-tab key"), TC_TOKEN(BACK_TAB) }, - { "kC", "kclr", TC_DESC("clear-screen or erase key") }, - { "kD", "kdch1", TC_DESC("delete-character key"), TC_TOKEN(KEY_DEL) }, - { "kE", "kel", TC_DESC("clear-to-end-of-line key") }, - { "kF", "kind", TC_DESC("scroll-forward key") }, - { "kH", "kll", TC_DESC("lower-left key (home down)"), TC_TOKEN(KEY_END) }, - { "kI", "kich1", TC_DESC("insert-character key"), TC_TOKEN(KEY_INS) }, - { "kL", "kdl1", TC_DESC("delete-line key") }, - { "kM", "krmir", TC_DESC("sent by rmir or smi rin insert mode") }, - { "kN", "knp", TC_DESC("next-page key"), TC_TOKEN(KEY_PAGEDOWN) }, - { "kP", "kpp", TC_DESC("previous-page key"), TC_TOKEN(KEY_PAGEUP) }, - { "kR", "kri", TC_DESC("scroll-backward key") }, - { "kS", "ked", TC_DESC("clear-to-end-of-screen key") }, - { "kT", "khts", TC_DESC("set-tab key") }, - { "ka", "ktbc", TC_DESC("clear-all-tabs key") }, - { "kb", "kbs", TC_DESC("backspace key"), TC_TOKEN(CTRL_H) }, - { "kd", "kcud1", TC_DESC("down-arrow key"), TC_TOKEN(KEY_DOWN) }, - { "kh", "khome", TC_DESC("home key"), TC_TOKEN(KEY_HOME) }, - { "kl", "kcub1", TC_DESC("left-arrow key"), TC_TOKEN(KEY_LEFT) }, - { "kr", "kcuf1", TC_DESC("right-arrow key"), TC_TOKEN(KEY_RIGHT) }, - { "kt", "kctab", TC_DESC("clear-tab key") }, - { "ku", "kcuu1", TC_DESC("up-arrow key"), TC_TOKEN(KEY_UP) }, - }; - -static Term_t term_flags[] = { /* boolean - termcap/terminfo elements */ - { "5i", "mc5i", TC_DESC("printer won't echo on screen") }, - { "HC", "chts", TC_DESC("cursor is hard to see") }, - { "LP", NULL, TC_DESC("last column of last line will not scroll"), TC_TOKEN(&tf_LP) }, - { "MT", NULL, TC_DESC("has meta key") }, /* TODO */ - { "ND", "ndscr", TC_DESC("scrolling region is non-destructive") }, - { "NL", NULL, TC_DESC("move down with \\n"), TC_TOKEN(&tf_NL) }, - { "NP", "npc", TC_DESC("pad character does not exist"), TC_TOKEN(&tf_npc) }, - { "NR", "nrrmc", TC_DESC("smcup does not reverse rmcup") }, - { "YA", "xhpa", TC_DESC("only positive motion for hpa/mhpa caps") }, - { "YB", "crxm", TC_DESC("using cr turns off micro mode") }, - { "YC", "daisy", TC_DESC("printer needs operator to change character set") }, - { "YD", "xvpa", TC_DESC("only positive motion for vpa/mvpa caps") }, - { "YE", "sam", TC_DESC("printing in last column causes cr") }, - { "YF", "cpix", TC_DESC("changing character pitch changes resolution") }, - { "YG", "lpix", TC_DESC("changing line pitch changes resolution") }, - { "am", "am", TC_DESC("terminal has automatic margins"), TC_TOKEN(&tf_am) }, - { "be", NULL, TC_DESC("back color erase"), TC_TOKEN(&tf_be) }, - { "bs", NULL, TC_DESC("uses ^H to move left"), TC_TOKEN(&tf_bs) }, - { "bw", "bw", TC_DESC("cub1 wraps from column 0 to last column") }, - { "cc", "ccc", TC_DESC("terminal can re-define existing colors") }, - { "da", "da", TC_DESC("display may be retained above the screen") }, - { "db", "db", TC_DESC("display may be retained below the screen") }, - { "eo", "eo", TC_DESC("can erase overstrikes with a blank") }, - { "es", "eslok", TC_DESC("escape can be used on the status line") }, - { "gn", "gn", TC_DESC("generic line type"), TC_TOKEN(&tf_gn) }, - { "hc", "hc", TC_DESC("hardcopy terminal"), TC_TOKEN(&tf_hc) }, - { "hl", "hls", TC_DESC("terminal uses only HLS color notation (tektronix)") }, - { "hs", "hs", TC_DESC("has extra status line") }, - { "hz", "hz", TC_DESC("can't print ~'s (hazeltine)"), TC_TOKEN(&tf_hz) }, - { "in", "in", TC_DESC("insert mode distinguishes nulls") }, - { "km", "km", TC_DESC("Has a meta key, sets msb high"), TC_TOKEN(&tf_km) }, - { "mi", "mir", TC_DESC("safe to move while in insert mode") }, - { "ms", "msgr", TC_DESC("safe to move while in standout/underline mode"), TC_TOKEN(&tf_ms) }, - { "nc", NULL, TC_DESC("no way to go to start of line") }, - { "ns", NULL, TC_DESC("crt cannot scroll") }, - { "nx", "nxon", TC_DESC("padding won't work, xon/xoff required"), TC_TOKEN(&tf_xonoff) }, - { "os", "os", TC_DESC("terminal can overstrike") }, - { "pt", NULL, TC_DESC("has 8-char tabs invoked with ^I") }, - { "ul", "ul", TC_DESC("underline character overstrikes") }, - { "ut", "bce", TC_DESC("screen erased with background color"), TC_TOKEN(&tf_ut) }, - { "xb", "xsb", TC_DESC("beehive (f1=escape, f2=ctrl C)") }, - { "xn", "xenl", TC_DESC("newline ignored after 80 cols (concept)"), TC_TOKEN(&tf_xn) }, - { "xo", NULL, TC_DESC("terminal uses xon/xoff handshaking"), TC_TOKEN(&tf_xonoff) }, - { "xr", "xon", TC_DESC("return clears the line") }, - { "xs", "xhp", TC_DESC("standout not erased by overwriting (hp)"), TC_TOKEN(&tf_xs) }, - { "xt", "xt", TC_DESC("tabs destructive, magic so char (Telray 1061)"), TC_TOKEN(&tf_xt) } - }; - - -static const unsigned ansicolor_map[] = { /* BRIEF -> ANSI color map */ -/* BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, WHITE */ - 0, 4, 2, 6, 1, 5, 3, 7, - 8, 12, 10, 14, 9, 13, 11, 15 - }; - - -static const struct colormap { /* BRIEF -> XTERM color map */ - int ident; - int c8; - int c16; - int c16_pc; - int c88_compat; /* 8/16 color compat */ - int c256_compat; /* 8/16 color compat */ - int c88; - int c256; - -} color_map[] = { - /* Ident 8 16 16/PC 88/C 256/C 88 256 */ - { BLACK, 0, 0, 0, 0, 0, 0, 0 }, - { BLUE, 4, 4, 1, 1, 4, 12, 12 }, - { GREEN, 2, 2, 2, 2, 2, 10, 10 }, - { CYAN, 6, 6, 3, 3, 6, 14, 14 }, - { RED, 1, 1, 4, 4, 1, 9, 9 }, - { MAGENTA, 5, 5, 5, 5, 5, 13, 13 }, - { BROWN, 3, 3, 6, 6, 130, 32, 130 }, - { WHITE, 7, 7, 7, 7, 7, 84, 248 }, - - { GREY, 0, 8, 8, 8, 8, 7, 7 }, - { LTBLUE, 4, 12, 9, 12, 12, 43, 81 }, - { LTGREEN, 2, 10, 10, 10, 10, 61, 121 }, - { LTCYAN, 6, 14, 11, 14, 14, 63, 159 }, - { LTRED , 1, 9, 12, 9, 9, 74, 224 }, - { LTMAGENTA, 5, 13, 13, 13, 13, 75, 225 }, - { YELLOW , 3, 11, 14, 11, 11, 11, 11 }, - { LTWHITE, 7, 15, 15, 15, 15, 1, 15 }, - - { DKGREY, 0, 0, 0, 0, 0, 82, 242 }, - { DKBLUE, 4, 4, 1, 1, 4, 4, 4 }, - { DKGREEN, 2, 2, 2, 2, 2, 2, 2 }, - { DKCYAN, 6, 6, 3, 3, 6, 6, 6 }, - { DKRED, 1, 1, 4, 4, 1, 1, 1 }, - { DKMAGENTA, 5, 5, 5, 5, 5, 5, 5 }, - { DKYELLOW, 3, 3, 6, 6, 130, 72, 130 }, - { LTYELLOW, 3, 11, 14, 11, 11, 78, 229 }, - - { COLOR_NONE, -1, -1, -1, -1, -1, -1, -1 } - }; - -/* - * Scroll window - */ -static int tt_top = -1; /* Top of scroll region. */ -static int tt_bot = -1; /* Bottom of scroll region. */ - -/* - * Color information - */ -static int tt_colors = 8; /* color depth (-1 unknown) */ - -static int tt_defaultfg = NOCOLOR; -static int tt_defaultbg = NOCOLOR; - -static int tt_fg = NOCOLOR; /* foreground color */ -static int tt_bg = NOCOLOR; /* background color */ -static int tt_style; /* text standout/underline mode */ - -static int tt_active = 0; /* display status */ -static int tt_cursor = 0; /* cursor status */ - -static vbyte_t tt_hue = 0; /* current attribute */ - - /* BRIEF -> TERM-COLORS */ -static int tt_colormap[COLOR_NONE + 1]; - - -/* Function: ttinit - * Initialize the terminal when the editor gets started up. - * - * Calling Sequence: - *> ttinit - *> -> term_init - *> ttopen - *> -> term_open - *> ttready - *> -> term_ready - *> macro tty/ - *> [ttfeature] - *> ttdisplay - *> -> term_display - *> [ttfeature] - * - *> ttfeature - *> ttprocess - *> -> term_control - *> ttwinch - *> -> term_control - * - *> ttclose - *> -> term_close - * - * Parameters: - * none. - * - * Configuration: - * - * Terminal identification. - * - * o TERM - - * General terminal identification. - * o KONSOLE_DCOP or KONSOLE_DBUS_SESSION - - * kconsole identification. - * o XTERM_VERSION - - * xterm version. - * o LINES/COLUMNS - - * Terminal size. - * - * Terminal capabilities. - * - * o COLORTERM_BCE - - * Assume BCE capabilities. - * o COLORTERM - - * slang style color terminal configuration, if set color assumed. - * o NCURSES_NO_UTF8_ACS - - * When running in a UTF-8 locale several terminals (including Linux console and GNU screen) - * ignore alternative character selection. If set use unicode box drawing characters in all - * cases. - * o NCURSES_ASSUMED_COLORS - - * Foreground and background colors. - * o COLORFGBG - - * rxvt/mrxvt terminal default color specification. - * o DEFAULT_COLORS - - * Default colors. - * - * Returns: - * nothing. - */ -void -ttinit(void) -{ - const char *term; - - trace_log("ttinit()\n"); - - /* - * profile - */ - x_scrfn.scr_open = term_open; - x_scrfn.scr_ready = term_ready; - x_scrfn.scr_feature = term_feature; - x_scrfn.scr_display = term_display; - x_scrfn.scr_control = term_control; - x_scrfn.scr_close = term_close; - - x_scrfn.scr_move = term_move; - x_scrfn.scr_cursor = term_cursor; - x_scrfn.scr_winch = term_sizeget; - - x_scrfn.scr_names = term_names; - x_scrfn.scr_beep = term_beep; - - x_scrfn.scr_clear = term_clear; - x_scrfn.scr_print = NULL; - x_scrfn.scr_putc = term_putc; - x_scrfn.scr_flush = term_flush; - - x_scrfn.scr_insl = term_insl; - x_scrfn.scr_dell = term_dell; - x_scrfn.scr_eeol = term_eeol; - x_scrfn.scr_repeat = term_repeat; - - term = ttisetup(); - - /* - * build attributes - */ - if (0 == strncmp(term, "linux", 5)) { /* linux console */ - t_attributes = TA_LINUX | TA_DARK; - - } else if (0 == strncmp(term, "cygwin", 5)) { - const char *cygwin = ggetenv("CYGWIN"); - - if (cygwin) { - trace_log("\tCYGWIN:%s\n", cygwin); - - if (strstr(cygwin, "codepage:oem")) { - if (xf_disptype < 0) { /* 8bit terminal */ - xf_disptype = DISPTYPE_8BIT; - } - x_pt.pt_codepage = 850; - - } else if (strstr(cygwin, "codepage:utf8")) { - if (xf_disptype < 0) { /* UTF8 enabled */ - xf_disptype = DISPTYPE_UTF8; - } - } - } - t_attributes = TA_CYGWIN|TA_XTERMLIKE|TA_DARK; - -#if defined(linux) - } else if (0 == strncmp(term, "con", 3)) { /* console, con80x25 etc */ - t_attributes = TA_LINUX|TA_DARK; -#endif - - } else if (0 == strncmp(term, "konsole", 7) || - getenv("KONSOLE_DCOP") || getenv("KONSOLE_DBUS_SESSION")) { - t_attributes = TA_KONSOLE | TA_XTERMLIKE; - - } else if (0 == strncmp(term, "screen", 6)) { - t_attributes = TA_SCREEN; - if (0 == strcmp(term, "screen.linux")) { - t_attributes |= TA_DARK; - } - - } else if (0 == strcmp(term, "putty")) { - t_attributes |= TA_DARK; - - } else if (strcmp(term, "vt52") != 0 && /* vt100+ */ - term[0] == 'v' && term[1] == 't' && term[2] >= '1' && term[2] <= '9') { - t_attributes = TA_VT100LIKE; - - } else if (term_xtermlike(term)) { /* eg. xterm-color */ - t_attributes = TA_XTERM | TA_XTERMLIKE; -#if defined(__CYGWIN__) - if (ggetenv("COMSPEC")) { - t_attributes |= TA_DARK; /* assume cmd/mintty */ - } -#endif /*__CYGWIN__*/ - } - - if (hasfeature(term, "rv")) { - t_attributes |= TA_LIGHT; /* rv = reverse video (black on white) */ - - } else if (hasfeature(term, "m") || hasfeature(term, "mono")) { - t_attributes |= TA_MONO; /* m = monochrome, suppress color support */ - } - - trace_log("terminal: %s (%s%s%s%s%s%s%s%s)\n", term, - (t_attributes & TA_LINUX ? "linux," : ""), - (t_attributes & TA_CYGWIN ? "cygwin," : ""), - (t_attributes & TA_VT100LIKE ? "vt100like," : ""), - (t_attributes & TA_XTERM ? "xterm," : ""), - (t_attributes & TA_XTERMLIKE ? "xtermlike," : ""), - (t_attributes & TA_LIGHT ? "light," : ""), - (t_attributes & TA_DARK ? "dark," : ""), - (t_attributes & TA_MONO ? "mono," : "")); - - /* - * Load termcap values. - */ - { - unsigned i, fkeys = 0; - const char *cp; - - trace_log("termcap:\n"); - - trace_log(" General:\n"); - for (i = 0; i < (sizeof(term_strings)/sizeof(term_strings[0])); i++) { - /* - * string values - */ - const Term_t *ti = term_strings + i; - const char *name = ttiname(ti); - - if (name && NULL != (cp = ttigetstr(ti))) { - const char **token = term_strings[i].token; - - term_strings[i].value.i_str = cp; - if (token) { - *token = cp; - } - trace_log("\t%-50s%c %-5s : %s\n", term_strings[i].comment, - (token ? '*' : ' '), name, c_string(cp)); - - if (token == &tc_graphic_pairs) { - acs_dump(cp); - x_pt.pt_attributes |= TF_AGRAPHICCHARACTERS; - - } else if (token == &tc_box_characters) { - const char *t_acs; - - if (NULL == tc_graphic_pairs && - (NULL != (t_acs = acs_box_characters(cp)))) { - acs_dump(t_acs); - tc_graphic_pairs = t_acs; - x_pt.pt_attributes |= TF_AGRAPHICCHARACTERS; - } - } - } - } - - fkeys = 0; - trace_log(" Keys:\n"); - for (i = 0; i < (sizeof(term_keys)/sizeof(term_keys[0])); ++i) { - /* - * keys - */ - const Term_t *ti = term_keys + i; - const char *name = ttiname(ti); - - if (name && NULL != (cp = ttigetstr(ti))) { - const size_t kcode = (size_t)term_keys[i].token; - - term_keys[i].value.i_str = cp; /* loaded later by ttkeys() */ - - trace_log("\t%-50s%c %-5s : %s\n", term_keys[i].comment, - (kcode ? '*' : ' '), name, c_string(cp)); - - if (kcode >= F(1) && kcode <= F(10)) { - ++fkeys; - } - } - } - - if (fkeys >= 10) { /* have all 10 function keys */ - x_pt.pt_attributes |= TF_AFUNCTIONKEYS; - } - - trace_log(" Numeric:\n"); - for (i = 0; i < (sizeof(term_numbers)/sizeof(term_numbers[0])); ++i) { - /* - * numbers - */ - const Term_t *ti = term_numbers + i; - const char *name = ttiname(ti); - - if (name) { - term_numbers[i].value.i_val = ttigetnum(ti); - if (term_numbers[i].token) { - *((int *)term_numbers[i].token) = term_numbers[i].value.i_val; - } - trace_log("\t%-50s%c %-5s : %d\n", term_numbers[i].comment, - (term_numbers[i].token ? '*' : ' '), name, term_numbers[i].value.i_val); - } - } - - trace_log(" Boolean/Flags:\n"); - for (i = 0; i < (sizeof(term_flags)/sizeof(term_flags[0])); ++i) { - /* - * flags - */ - const Term_t *ti = term_flags + i; - const char *name = ttiname(ti); - - if (name) { - term_flags[i].value.i_val = ttigetflag(ti); - if (term_flags[i].token) { - *((int *)term_flags[i].token) = term_flags[i].value.i_val; - } - trace_log("\t%-50s%c %-5s : %d\n", term_flags[i].comment, - (term_flags[i].token ? '*' : ' '), name, term_flags[i].value.i_val); - } - } - } - - /* color */ - term_fgbg(); - - if (NULL != ggetenv("COLORTERM_BCE")) { - tf_be = 1; /* slang compat override */ - } - - if (NULL == tc_Color_Fg || NULL == tc_Color_Fg) { - if (tc_ANSI_Color_Fg && tc_ANSI_Color_Bg) { - tc_Color_Fg = tc_ANSI_Color_Fg; - tc_Color_Bg = tc_ANSI_Color_Bg; - } - } - - /* fixup defective termcap/terminfo databases */ - if (NULL == tc_graphic_pairs && - (t_attributes & TA_VT100LIKE)) { /* VT1xx */ - tc_acs_start = "\016"; - tc_acs_end = "\017"; - tc_acs_enable = "\033)0"; - } - - if (NULL == tc_graphic_pairs && - strncmp(term, "aixterm", 7) == 0) { /* aixterm (VT102) */ - tc_acs_start = "\016"; - tc_acs_end = "\017"; - tc_acs_enable = "\033(B\033)0"; - } - - if (tc_graphic_pairs && NULL == tc_acs_start) { - tc_acs_start = "\016"; - tc_acs_end = "\017"; - } - /* VT2xx+ */ - if (((t_attributes & TA_VT100LIKE) && term[2] != '1') || - (t_attributes & (TA_LINUX|TA_XTERMLIKE)) ) { - if (NULL == tc_pDL) tc_pDL = "\033[%dM"; - if (NULL == tc_pAL) tc_pAL = "\033[%dL"; - if (NULL == tc_cm) tc_cm = "\033[%i%d;%dH"; - } - - if (t_attributes & (TA_LINUX|TA_XTERM)) { /* VT2xx */ - if (NULL == tc_cb) tc_cb = "\033[1K"; - if (NULL == tc_ce) tc_ce = "\033[K"; - } - - /* stand-out mode equiv checks */ - if (tc_se) { - if (tc_ZH && 0 == strcmp(tc_ZH, tc_se)) { - tc_ZH = tc_se; - - } else if (NULL == tc_ZH) { - tc_mr = NULL; /* ignore or assume same as 'se' */ - } - - if (tc_ue && 0 == strcmp(tc_us, tc_se)) { - tc_ue = tc_se; - } - - if (tc_ZR && 0 == strcmp(tc_ZR, tc_se)) { - tc_ZR = tc_se; - } - } - - if (NULL == tc_do && tf_NL) { - tc_do = "\n"; - } else if (tc_do && tc_do[0] == '\n' && !tf_NL) { - tc_do = NULL; - } - - if (NULL == tc_le && NULL == tc_bc && - (tf_bs || (t_attributes & TA_XTERMLIKE))) { - tc_bc = "\b"; - } - - /* - * Verify min requirements - */ - if (tf_gn) { - fprintf(stderr, "Generic terminal '%s', you have not specified your real terminal type.\n", term); - exit(1); - - } else if (tf_hc) { - fprintf(stderr, "Hard copy terminal '%s', not supported.\n", term); - exit(1); - - } else if (tf_xonoff) { - fprintf(stderr, "Terminal '%s' requires xon/xoff, not supported (try --curses).\n", term); - exit(1); - - } else if (tn_sg >= 1) { - fprintf(stderr, "Terminal '%s' using magic-cookie's, not supported (try --curses).\n", term); - exit(1); - - } else if (NULL == tc_cm && (NULL == tc_cv || NULL == tc_ch)) { - fprintf(stderr, "Terminal '%s' missing cursor move capabilities, not supported.\n", term); - exit(1); - - } else if (tf_xs >= 1 || tf_xt >= 1) { - fprintf(stderr, "Terminal '%s' requires old-style attribute handling, not supported.\n", term); - exit(1); - } - -#if defined(__CYGWIN__) - /* - * o retrieve display code page - * o plus enable tf_xn as the terminal cursor wrap misbehaves - * then in full screen mode resulting in screen corruption. - */ - if (-1 == x_pt.pt_codepage) { - x_pt.pt_codepage = GetConsoleOutputCP(); - trace_log("\tcodepage: %d\n", x_pt.pt_codepage); - } - if (TA_CYGWIN & t_attributes) { - x_pt.pt_attributes |= TF_ACYGWIN; /* Cygwin terminal */ - tf_xn = 1; - } -#endif /*__CYGWIN__*/ - - if (tf_km) { - x_pt.pt_attributes |= TF_AMETAKEY; - } - - if (0 == x_pt.pt_codepage) { - x_pt.pt_codepage = 437; /* default */ - } -} - - -static int -hasfeature(const char *term, const char *what) -{ - const char *p = strstr(term, what); - - if (p > term) { /* -rv[-] */ - const unsigned len = strlen(what); - - if ('-' == p[-1] && ('-' == p[len] || 0 == p[len])) { - return 1; - } - } - return 0; -} - - -/* Function: ttdefaultscheme - * Retrieve the derived/guessed default background color based on the either - * the published terminal background or the terminal type. - * - * Parameters: - * none. - * - * Returns: - * Name of default color scheme dark or light. - */ -const char * -ttdefaultscheme(void) -{ - int isdark = 0; - - if (x_pt.pt_schemedark >= 0) { /* explicit configuration */ - isdark = x_pt.pt_schemedark; - - } else if (0 == (TA_LIGHT & t_attributes)) { - if (tt_defaultbg != NOCOLOR) { /* 0-6 or 8 */ - if (tt_defaultbg <= 6 || 8 == tt_defaultbg) { - isdark = 1; - } - } else { /* generally dark */ - if (TA_DARK & t_attributes) { - isdark = 1; - } - } - } - - x_pt.pt_schemedark = isdark; - trace_log("ttdefaultscheme=%s\n", (isdark ? "dark" : "light")); - return (isdark ? "dark" : "light"); -} - - -/* Function: term_open - * Open the console. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_open(scrprofile_t *profile) -{ - io_device_add(TTY_INFD); /* stream registration */ - sys_initialise(); - term_identification(); /* terminal identification */ - term_sizeget(&profile->sp_rows, &profile->sp_cols); - profile->sp_colors = tt_colors; -} - - -/* Function: term_close - * Close the console. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_close(void) -{ - term_tidy(); - sys_shutdown(); - tty_egaflag = -1; -} - - -/* Function: term_ready - * Run-time initialisation. - * - * Parameters: - * repaint - *true* if the screen should be repainted. - * profile - console profile. - * - * Returns: - * nothing. - */ -static void -term_ready(int repaint, scrprofile_t *profile) -{ - static unsigned once; - - trace_log("term_ready(%d)\n", repaint); - - /* - * dump configuration - */ - if (! once) { - const char *o_CS = tc_cs; - - if (! xf_scrollregions) { - tc_cs = tc_cS = NULL; /* disable scrolling region */ - } - - if (! tc_ce) { /* erasing a line */ - tty_tceeol = ttcols(); - } else { - tty_tceeol = term_cost(tc_ce); - } - - if (tc_cs && tc_sr) { /* inserting a line */ - tty_tcinsl = term_cost(tc_cs) * 2 + term_cost(tc_sr); - } else if (tc_pAL) { - tty_tcinsl = term_cost(tc_pAL); - } else if (tc_al) { - tty_tcinsl = term_cost(tc_al); - } else { - tty_tcinsl = 0xffff; - } - - if (tc_cs) { /* delete a line */ - tty_tcdell = term_cost(tc_cs) * 2 + 1; - } else if (tc_pDL) { - tty_tcdell = term_cost(tc_pDL); - } else if (tc_dl) { - tty_tcdell = term_cost(tc_dl); - } else { - tty_tcdell = 0xffff; - } - /* we can ins/del lines */ - t_insdel = (tc_al || tc_pAL) && (tc_dl || tc_pDL); - t_padchar = (tf_npc ? -1 : (tc_pc ? *tc_pc : 0)); - t_acs_locale_breaks = acs_locale_breaks(); - - trace_log("TTY summary:\n"); - - if (-1 == t_padchar) { - trace_log("\tNo padding character\n"); - } else { -#if defined(HAVE_OSPEED) - trace_log("\tPadding character %d, at ospeed %d\n", t_padchar, ospeed); -#else - trace_log("\tPadding character %d, at baud %d\n", t_padchar, baudrate()); -#endif - } - - if (t_insdel) { - trace_log("\tInsert/delete scrolling available.\n"); - } - - if (o_CS) { - trace_log("\tScroll regions available.\n"); - } - - if (! xf_graph) { - trace_log("\tAlternative character support disabled.\n"); - } else if (tc_acs_enable || x_pt.pt_graphics_mode[0]) { - trace_log("\tAlternative character support available.\n"); - } - if (t_acs_locale_breaks) { - trace_log("\tlocale breaks alternative character support.\n"); - } - - if (xf_noinit) { - trace_log("\ttermcap init/reinit disabled.\n"); - } - - if (xf_nokeypad) { - trace_log("\ttermcap keypad init/reinit disabled.\n"); - } - - trace_log("\tDeleting lines using %s\n", - ((tc_cs) ? "scrolling regions" : t_insdel ? "line del/ins" : "hard refresh")); - trace_log("\tInserting lines using %s\n", - ((tc_cs && tc_sr) ? "scrolling regions" : t_insdel ? "line del/ins" : "hard refresh")); - trace_log("\t%-55s : %d\n", "Erase line cost", tty_tceeol); - trace_log("\t%-55s : %d\n", "Insert line cost", tty_tcinsl); - trace_log("\t%-55s : %d\n", "Delete line cost", tty_tcdell); - trace_log("\t%-55s : %d\n", "Colors", tt_colors); - trace_log("\t%-55s : %d\n", " Default fg", tt_defaultfg); - trace_log("\t%-55s : %d\n", " Default bg", tt_defaultbg); - ++once; - } - - /* - * configure terminal - */ - term_colorreset(); - - if (repaint) { - if (x_pt.pt_init[0]) /* terminal specific init */ - ttputctl2(x_pt.pt_init, 0, 0); - xterm_colors(t_colorsuser); - if (! xf_noinit) - ttputpad(tc_ti); /* enable cup (cursor addressing) */ - if (! xf_nokeypad) - ttputpad(tc_ks); /* put terminal in ``keypad-transmit'' */ - if (xf_graph) - ttputpad(tc_acs_enable); /* enable alt character set */ - ttputpad(tc_vs ? tc_vs : tc_ve); /* enable enhanced cursor */ - if (tf_am) - ttputpad(tc_am_on); /* enable automatic margins */ - ttputpad(tc_mm); /* enable meta key-codes */ - } - - /* - * terminal specific specials - */ - if (t_attributes & TA_CYGWIN) { - if (xf_cygwinkb) { - ttpush("\033[?2000h"); /* enable RAW mode (gives us WIN32 scancodes) */ - } - - } else if (t_attributes & TA_MINTTY) { - if (xf_mouse) { /* mouse enabled? */ - ttpush("\033[?7786h"); /* mouse-wheel reports only */ - } - - } else if (t_attributes & TA_VT100LIKE) { - ttpush("\033=\033[?1]"); /* enable cursor keys */ - } - - if (profile) { - profile->sp_lastsafe = term_lastsafe(); - profile->sp_colors = tt_colors; - } - - tt_style = 0; - tt_cursor = 1; - tt_active = 1; - term_flush(); -} - - -/* Function: term_feature - * Signal a terminal feature change. - * - * Parameters: - * ident - Feature identifier. - * - * Returns: - * nothing. - */ -static void -term_feature(int ident, scrprofile_t *profile) -{ - trace_log("term_feature(%d)\n", ident); - - switch (ident) { - case TF_INIT: - if (tty_open && x_pt.pt_init[0]) { - ttputctl2(x_pt.pt_init, 0, 0); - } - break; - - case TF_COLORDEPTH: - case TF_DEFAULT_FG: - case TF_DEFAULT_BG: - case TF_XTERM_PALETTE: - if (tty_open) { - term_colors(); - profile->sp_colors = tt_colors; - } - break; - - case TF_COLORMAP: /* terminal color palette */ - if (x_pt.pt_colormap[0]) { - strxcpy(t_colorsuser, x_pt.pt_colormap, sizeof(t_colorsuser)); - if (tty_open) { - xterm_colors(t_colorsuser); - } - } - break; - - case TF_COLORPALETTE: { /* user defined palette */ - const char *cursor = x_pt.pt_colorpalette; - unsigned col = 0; - - for (col = 0; col < (sizeof(tt_colormap)/sizeof(tt_colormap[0])); ++col) { - if (cursor && *cursor) { - if (isdigit(*cursor)) { - int val; - - if ((val = atoi(cursor)) >= 0) { - tt_colormap[col] = val; - } - } - if (NULL != (cursor = strchr(cursor, ','))) { - ++cursor; - } - } - } - x_pt.pt_xtpalette = -2; - } - break; - - case TF_ENCODING: - break; - case TF_UNICODE_VERSION: - if (x_pt.pt_unicode_version[0]) { - ucs_width_set(x_pt.pt_unicode_version); - } - break; - } -} - - -/* Function: term_display - * Invoked upon the display being enabled. - * - * This interface is hooked into the display_windows() primitive which (by default) is - * post execution of any terminal specific macros, for example - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_display(void) -{ - trace_log("term_display()\n"); - - if (term_isutf8()) { /* auto-detect UTF8 term support */ - x_pt.pt_attributes |= TF_AUTF8ENCODING; /* publish UTF8 */ - if (0 == x_pt.pt_encoding[0]) { - strcpy(x_pt.pt_encoding, "UTF-8"); - } - if (xf_disptype < 0) { - xf_disptype = DISPTYPE_UTF8; - } - x_display_ctrl |= DC_UNICODE; - - } else { - if (xf_disptype < 0) { /* default disp-type */ - if (vtis8bit()) { - if (0 == x_pt.pt_encoding[0]) { - strcpy(x_pt.pt_encoding, "latin1"); - } - xf_disptype = DISPTYPE_8BIT; - } else { - if (0 == x_pt.pt_encoding[0]) { - strcpy(x_pt.pt_encoding, "us-ascii"); - } - xf_disptype = DISPTYPE_7BIT; - } - } - } - - if (! xf_graph) { /* no graphic */ - ttboxcharacters(TRUE); - } -} - - -static int -term_control(int action, int param, ...) -{ - switch (action) { - case SCR_CTRL_NORMAL: /* normal color */ - if (tty_open) { - term_colorreset(); - } - break; - - case SCR_CTRL_SAVE: - if (tty_open) { - ttmove(ttrows()-1, 0); - if (param) { - term_tidy(); - } else { - term_colorreset(); - term_styleoff(); - tteeol(); - } - } - break; - - case SCR_CTRL_RESTORE: - if (! tty_open) { - ttopen(); - } - term_ready(TRUE, NULL); - break; - - case SCR_CTRL_COLORS: /* color change */ - break; - - default: - return -1; - } - return 0; -} - - -/* Function: ttisetup - * TERMINFO/TERMCAP setup. - * - * Parameters: - * none. - * - * Returns: - * Terminal name on success, otherwise the interface exits. - */ -static const char * -ttisetup(void) -{ - const char *term; - - if (NULL == (term = ggetenv("TERM"))) { - fprintf(stderr, "Environment variable TERM not defined!\n"); - exit(1); - } - -#if defined(HAVE_TERMINFO) - XF_TERMINFO { - trace_log("TERMINFO(%s) open\n", term); - if (setupterm((char *)term, fileno(stdout), NULL) != 0) { - fprintf(stderr, "Terminal type '%s' not found in terminfo database.\n", term); - exit(1); - } - } -#endif -#if defined(HAVE_TERMCAP) - XF_TERMCAP { - tcapcursor = tcapstrings; - memset(tcapstrings, 0, sizeof(tcapstrings)); - - trace_log("TERMCAP(%s) open\n", term); - if (tgetent(tcapbuffer, (char *)term) != 1) { - fprintf(stderr, "Terminal type '%s' not found in termcap.\n", term); - exit(1); - } - } -#endif - - return term; -} - - -/* Function: ttiname - * Retrieve the attribute name. - * - * Parameters: - * ti - Attribute specification. - * - * Returns: - * Attribute name. - */ -static const char * -ttiname(const Term_t *ti) -{ - const char *name = NULL; - -#if defined(HAVE_TERMINFO) - XF_TERMINFO name = ti->terminfoname; -#endif -#if defined(HAVE_TERMCAP) - XF_TERMCAP name = ti->termcapname; -#endif - return name; -} - - -/* Function: ttigetstr - * t[i]getstr() interface. - * - * Parameters: - * ti - Attribute specification. - * - * Returns: - * Sequence buffer address, otherwis NULL. - */ -static const char * -ttigetstr(const Term_t *ti) -{ - char *s = NULL; - -#if defined(HAVE_TERMINFO) - XF_TERMINFO { - const char *name = ti->terminfoname; - - s = tigetstr((char *) name); - if ((char *)-1 == s) { /* 'name' is not a string capability */ - trace_log("\ttgetstr(%s) = unknown\n", name); - s = NULL; - } - } -#endif -#if defined(HAVE_TERMCAP) - XF_TERMCAP { - /* - * Under normal conditions tgetstr() should perform as descripted but doesn't on - * all systems so workout known issues. - * - * "The tgetstr routine returns the string entry for id, or zero if it is not - * available. Use tputs to output the returned string. The return value will also - * be copied to the buffer pointed to by area, and the area value will be updated - * to point past the null ending this value." - * - * Note, only seen under an older curses implementation. - */ - const char *name = ti->termcapname; - char *ocursor = tcapcursor; /* current storage addr */ - - if (NULL != (s = tgetstr((char *) name, &tcapcursor)) && *s) { - const int slen = strlen(s); - - if (ocursor == tcapcursor) { /* broken tgetstr() */ - strcpy(ocursor, s); - tcapcursor = ocursor + slen + 1; - } - s = ocursor; /* lookup result */ - if (tcapcursor >= tcapstrings + TC_SLEN) { - fprintf(stderr, "Terminal description too large (>%dk)\n", (TC_SLEN/1024) + 1); - exit(1); - } - assert(tcapcursor == ocursor + slen + 1); - } else { - s = NULL; /* not found, zero length */ - } - } -#endif - return s; -} - - -/* Function: ttigetnum - * t[i]getnum() interface. - * - * Parameters: - * ti - Attribute specification. - * - * Returns: - * Attribute value, otherwise -1. - */ -static int -ttigetnum(const Term_t *ti) -{ - const char *name = "n/a"; - int num = -1; - -#if defined(HAVE_TERMINFO) - XF_TERMINFO { - name = ti->terminfoname; - num = tigetnum((char *) name); - } -#endif -#if defined(HAVE_TERMCAP) - XF_TERMCAP { - name = ti->termcapname; - num = tgetnum((char *) name); - } -#endif - if (num < -1) { - trace_log("\ttgetnum(%s) = error (%d)\n", name, num); - } - return (num >= -1 ? num : -1); /* -1 or greater */ -} - - -/* Function: ttigetflag - * t[i]getflag() interface. - * - * Parameters: - * ti - Attribute specification. - * - * Returns: - * Attribute value of either 0 or 1. - */ -static int -ttigetflag(const Term_t *ti) -{ - const char *name = "n/a"; - int flag = -1; - -#if defined(HAVE_TERMINFO) - XF_TERMINFO { - name = ti->terminfoname; - flag = tigetflag((char *) name); - } -#endif -#if defined(HAVE_TERMCAP) - XF_TERMCAP { - name = ti->termcapname; - flag = tgetflag((char *) name); - } -#endif - if (flag < 0) { - trace_log("\ttgetflag(%s) = error (%d)\n", name, flag); - } - return (flag >= 0 ? flag : 0); /* 0 or 1 */ -} - - -int -ttisetstr(const char *tag, int taglen, const char *value) -{ - __CUNUSED(tag) __CUNUSED(taglen) __CUNUSED(value) - return -1; -} - - -int -ttisetnum(const char *tag, int taglen, const char *value) -{ - __CUNUSED(tag) __CUNUSED(taglen) __CUNUSED(value) - return -1; -} - - -int -ttisetflag(const char *tag, int taglen, const char *value) -{ - __CUNUSED(tag) __CUNUSED(taglen) __CUNUSED(value) - return -1; -} - - -/* Function: acs_dump - * Alternative character dump. - * - * Parameters: - * bp - Buffer object address. - * - * Returns: - * nothing. - */ -static void -acs_dump(const char *bp) -{ - const unsigned char *p = (unsigned char *)bp; - unsigned char ident, ch; - unsigned i; - - while (*p) { - const char *desc = "unknown"; - - ident = *p++; - if (! isprint(ident)) { - continue; /* unsure, yet needed for rxvt-cygwin */ - } - ch = *p++; - - for (i = 0; i < (sizeof(term_characters)/sizeof(term_characters[0])); ++i) - if (term_characters[i].ident == ident) { - desc = term_characters[i].name; - break; - } - - trace_log("\t\t%-30s %c/0x%x : %u/0x%x\n", desc, ident, ident, ch, ch); - } -} - - -/* Function: acs_boxcharacters - * Alternative character box character import. - * - * Parameters: - * bx - Box character spec. - * - * Returns: - * Converted box characters into an acs specification. - */ -static const char * -acs_box_characters(const char *bx) -{ - char acs[32], *t_acs = acs; - -#define acs_push_bx(_i, _c) *t_acs++ = _i, *t_acs++ = _c - - acs_push_bx(TACS_ULCORNER, bx[0]); /* 'l' */ - acs_push_bx(TACS_HLINE, bx[1]); /* 'q' */ - acs_push_bx(TACS_URCORNER, bx[2]); /* 'k' */ - acs_push_bx(TACS_VLINE, bx[3]); /* 'x' */ - acs_push_bx(TACS_LRCORNER, bx[4]); /* 'j' */ - acs_push_bx(TACS_LLCORNER, bx[5]); /* 'm' */ - acs_push_bx(TACS_TTEE, bx[6]); /* 'w' */ - acs_push_bx(TACS_RTEE, bx[7]); /* 'u' */ - acs_push_bx(TACS_BTEE, bx[8]); /* 'v' */ - acs_push_bx(TACS_LTEE, bx[9]); /* 't' */ - acs_push_bx(TACS_PLUS, bx[10]); /* 'n' */ - -#undef acs_push_bx - *t_acs = 0; - - return chk_salloc(acs); -} - - -/* Function: acs_locale_breaks - * Check for known cases where a UTF-8 locale breaks the alternate character set. - * - * Parameters: - * none. - * - * Returns: - * TRUE or FALSE. - */ -static int -acs_locale_breaks(void) -{ - const char *env; - - if ((env = ggetenv("NCURSES_NO_UTF8_ACS")) != 0) { - return atoi(env); /* ncurses compatibility */ - - } else if ((env = ggetenv("TERM")) != 0) { - if (strstr(env, "linux")) { - return TRUE; - } - - if (strstr(env, "screen") && - ((env = ggetenv("TERMCAP")) != 0 && strstr(env, "screen") != 0) && - strstr(env, "hhII00") != 0) { - -#define IS_CTRLN(s) ((s) != 0 && strstr(s, "\016") != 0) -#define IS_CTRLO(s) ((s) != 0 && strstr(s, "\017") != 0) - - if (IS_CTRLN(tc_acs_start) || IS_CTRLO(tc_acs_start) || - IS_CTRLN(set_attributes) || IS_CTRLO(set_attributes)) { - return TRUE; - } - -#undef IS_CTRLN -#undef IS_CTRLO - } - } - return FALSE; -} - - -/* Function: term_xtermlike - * Determine the current terminal is an xterm style. - * - * Parameters: - * term - Terminate name. - * - * Returns: - * nothing. - */ -static int -term_xtermlike(const char *term) -{ - static const struct { - const char *desc; - unsigned len; - } xtermlike[] = { -#define XTERMLIKE(x) { x, sizeof(x)-1 } - XTERMLIKE("xterm"), /* generic */ - XTERMLIKE("aixterm"), /* AIX */ - XTERMLIKE("mintty"), /* non-standard. normally "xterm-256color" */ - XTERMLIKE("rxvt"), - XTERMLIKE("urxvt"), /* Unicode rxvt */ - XTERMLIKE("Eterm"), - XTERMLIKE("gnome"), /* gnome-terminal */ - XTERMLIKE("dtterm"), /* CDE terminal */ - XTERMLIKE("cygwin") /* Cygwin console */ - }; -#undef XTERMLIKE - int ret = 0; - - if (term) { - unsigned i; - - if (x_pt.pt_xtcompat >= 0) { - ret = x_pt.pt_xtcompat; /* feature override */ - } else { - for (i = 0; i < (unsigned)(sizeof(xtermlike)/sizeof(xtermlike[0])); ++i) - if (0 == strncmp(term, xtermlike[i].desc, xtermlike[i].len) && - ('\0' == term[xtermlike[i].len] || '-' == term[xtermlike[i].len])) { - /* - * for example, - * xterm-color - */ - ret = 1; - break; - } - } - } - trace_log("\txtermlike(%s) : %d\n", (term ? term : ""), ret); - x_pt.pt_xtcompat = ret; - return ret; -} - - -/* Function: ttkeys - * Map keys from termcap database to our keys. These are often overridden by the term - * macros, but at least we can set up some sensible default that are likely to work. - * - * Parameters: - * repaint - *true* if the screen should be repainted. - * - * Returns: - * nothing. - */ -void -ttkeys(void) -{ - unsigned i; - - trace_log("ttkeys()\n"); - - /* - * Keys - */ - for (i = 0; i < (sizeof(term_keys)/sizeof(term_keys[0])); ++i) - if (term_keys[i].value.i_str && term_keys[i].token) { - key_define_key_seq((int)term_keys[i].token, term_keys[i].value.i_str); - } - - /* - * Color - */ - if (tf_Colors > 2 /*user specification*/ || - (tc_Color_Fg && tc_Color_Bg) || (tc_ANSI_Color_Fg && tc_ANSI_Color_Bg) || - ggetenv("COLORTERM") /*override*/) { - x_pt.pt_color = TRUE; - } - - term_colors(); - - /* - * Graphic (alt) characters - */ - for (i = 0; i < sizeof(tc_acs_map); ++i) { /* one-to-one */ - tc_acs_map[i] = (unsigned char)(i < 32 ? ' ' : i); - } - - if (tc_acs_start && xf_graph /*-1 or 1*/) { - const char *p; - - if (NULL == (p = tc_graphic_pairs)) { /* build character map */ - p = tc_graphic_default; - } - - while (*p) { - i = *p++; - if (! isprint(i)) { - continue; /* unsure, yet needed for rxvt-cygwin */ - } - tc_acs_map[i & 0x7f] = *p++; - } - - x_pt.pt_tty_graphicsbox = TRUE; - x_pt.pt_top_left[0] = tc_acs_map[TACS_ULCORNER]; - x_pt.pt_top_right[0] = tc_acs_map[TACS_URCORNER]; - x_pt.pt_bot_left[0] = tc_acs_map[TACS_LLCORNER]; - x_pt.pt_bot_right[0] = tc_acs_map[TACS_LRCORNER]; - x_pt.pt_vertical[0] = tc_acs_map[TACS_VLINE]; - x_pt.pt_horizontal[0] = tc_acs_map[TACS_HLINE]; - x_pt.pt_top_join[0] = tc_acs_map[TACS_TTEE]; - x_pt.pt_bot_join[0] = tc_acs_map[TACS_BTEE]; - x_pt.pt_cross[0] = tc_acs_map[TACS_PLUS]; - x_pt.pt_left_join[0] = tc_acs_map[TACS_RTEE]; - x_pt.pt_right_join[0] = tc_acs_map[TACS_LTEE]; - - trace_ilog("ACS mapping\n"); - trace_ilog(" top %d/0x%x\n", x_pt.pt_top_right[0], x_pt.pt_top_right[0]); - trace_ilog(" bot %d/0x%x\n", x_pt.pt_bot_left[0], x_pt.pt_bot_left[0]); - trace_ilog(" bot %d/0x%x\n", x_pt.pt_bot_right[0], x_pt.pt_bot_right[0]); - trace_ilog(" verti %d/0x%x\n", x_pt.pt_vertical[0], x_pt.pt_vertical[0]); - trace_ilog(" horiz %d/0x%x\n", x_pt.pt_horizontal[0], x_pt.pt_horizontal[0]); - trace_ilog(" top %d/0x%x\n", x_pt.pt_top_join[0], x_pt.pt_top_join[0]); - trace_ilog(" bot %d/0x%x\n", x_pt.pt_bot_join[0], x_pt.pt_bot_join[0]); - trace_ilog(" cross %d/0x%x\n", x_pt.pt_cross[0], x_pt.pt_cross[0]); - trace_ilog(" left %d/0x%x\n", x_pt.pt_left_join[0], x_pt.pt_left_join[0]); - trace_ilog(" right %d/0x%x\n", x_pt.pt_right_join[0], x_pt.pt_right_join[0]); - } -} - - -/* Function: term_colors - * Load the given color specification. - * - * Parameters: - * value - Color scheme. - * - * Returns: - * nothing. - */ -static void -term_colors(void) -{ /* save user color specification */ - int col, source = 0; - - /* configure color depth */ - if (xf_color > 1) { - tt_colors = xf_color; /* command line override */ - source = 2; - - } else if (TA_MONO & t_attributes) { - tt_colors = 2; /* mono feature (xterm-mono) */ - source = 3; - - } else if (x_pt.pt_colordepth > 1) { - tt_colors = x_pt.pt_colordepth; /* set_term_feature() */ - source = 1; - - } else if (x_pt.pt_color /*-1 or 1*/) { - if (t_attributes & TA_XTERMLIKE) { - tt_colors = ANSI_COLORS; - - } else if (0 == (tt_colors = tf_Colors)) { - if (tc_ANSI_Color_Fg && tc_ANSI_Color_Bg) { - tt_colors = 16; - } else if (tc_Color_Fg && tc_Color_Bg) { - tt_colors = 8; - } else { - tt_colors = 0; - } - } - } - - /* configure colors */ - assert((COLOR_NONE + 1) == (sizeof(tt_colormap)/sizeof(tt_colormap[0]))); - assert((COLOR_NONE + 1) == (sizeof(color_map)/sizeof(color_map[0]))); - - trace_ilog("ttcolormap:\n"); - for (col = 0; col <= COLOR_NONE; ++col) { - int color = -1; - - if (-2 == x_pt.pt_xtpalette) { /* user defined palette */ - if ((color = tt_colormap[col]) <= 0) { - color = -1; - } - } - - if (color < 0) { - if (tt_colors >= 256) { - if (0 == x_pt.pt_xtpalette) { /* compat-16 mode */ - color = color_map[col].c256_compat; - } else { - color = color_map[col].c256; - } - - } else if (tt_colors >= 88) { - if (0 == x_pt.pt_xtpalette) { /* compat-16 mode */ - color = color_map[col].c88_compat; - } else { - color = color_map[col].c88; - } - - } else if (tt_colors >= 16) { - color = color_map[col].c16; - - } else { - color = color_map[col].c8; - } - } - - tt_colormap[col] = color; - trace_ilog("\t%16s [%2d] = %d\n", color_name(col, "unknown"), col, tt_colormap[col]); - assert(color_map[col].ident == col); - } - - trace_ilog("term_colors(source=%d,depth=%d)\n", source, tt_colors); - x_pt.pt_colordepth = tt_colors; /* derived depth */ - - if (tt_colors > 2) { - x_display_ctrl |= DC_SHADOW_SHOWTHRU; - } - term_fgbg(); -} - - -/* Function: term_fgbg - * Load the environment settings (if any) which define the default colors configurations. - * - * The supported configurations are NCURSES_ASSUMED_COLORS, COLORFGBG (rxvt/mrxvt) - * and DEFAULT_COLORS. - * - * The following are examples of their settings; - * - * NCURSES_ASSUMED_COLORS='0;15' - * - * COLORFGBG='0;default;15' - * - * DEFAULT_COLORS='0;15' - * - * Notes: - * The format of the COLORFGBG variable is not documented as such and there two - * known formats. The two formats correspond to whether the xpm library is used or - * not. - * - * If rxvt is compiled with xpm support, the variable has three fields. In either - * case, the background color is the last field. - * - * Parameters: - * src - Buffer cursor. - * result - Storage for decoded result. - * - * Returns: - * Final cursor position. - */ -static void -term_fgbg(void) -{ - const char *env; - - tt_defaultfg = tt_defaultbg = NOCOLOR; /* unknown */ - - if (NULL != (env = ggetenv("NCURSES_ASSUMED_COLORS"))) { - int count, fg = NOCOLOR, bg = NOCOLOR; - char sep; - - if ((count = sscanf(env, "%d%c%d%c", &fg, &sep, &bg, &sep)) >= 1) { - if (fg >= 0 && fg <= 255) tt_defaultfg = fg; - if (count >= 3) { - if (bg >= 0 && bg <= 255) tt_defaultbg = bg; - } - } - - } else { - if (NULL != (env = ggetenv("COLORFGBG")) || - NULL != (env = ggetenv("DEFAULT_COLORS"))) { - env = fgbg_value(env, &tt_defaultfg); - env = fgbg_value(env, &tt_defaultbg); - if (*env) { /* XPM support, last field is background */ - fgbg_value(env, &tt_defaultbg); - } - } - } - /* apply color */ - tt_defaultfg = fgbg_import(tt_defaultfg, x_pt.pt_defaultfg); - tt_defaultbg = fgbg_import(tt_defaultbg, x_pt.pt_defaultbg); -} - - -/* Function: fgbg_value - * Decode a COLORFGBG or DEFAULT_COLORS color specification. - * - * Parameters: - * src - Buffer cursor. - * result - Storage for decoded result. - * - * Returns: - * Final cursor position. - */ -static const char * -fgbg_value(const char *src, int *result) -{ - const char *end = NULL; - - if (0 == strncmp(src, "default", 7)) { - end = src + 7; /* special case */ - } else { - char *endp = 0; - int value = (int) strtol(src, &endp, 0); - - if (0 == endp) { - end = src; - } else if (value >= 0 && value <= 255) { - *result = (unsigned) value; - end = endp; - } - while (*end && *end != ';') { - ++end; - } - } - - if (*end == ';') { - ++end; - } - return end; -} - - -static unsigned -fgbg_import(unsigned edefault, int udefault) -{ - if (NOCOLOR == edefault) { - if (udefault >= 0) { - return udefault; - } - return NOCOLOR; - } - if (edefault < ANSI_COLORS) { - return ansicolor_map[ edefault ]; - } - return edefault; -} - - -/* Function: xterm_colors - * Manage the xterm color pairs - * - * Parameters: - * value - Specification. - * - * Notes: - * ESC]4; c; spec ? - * - * Change Color Number c to the color specified by spec, i.e., a name or RGB - * specification as per XParseColor. Any number of c name pairs may be given. - * - * The color numbers correspond to the ANSI colors 0-7, their bright versions 8-15, - * and if supported, the remainder of the 88-color or 256-color table. Each successive - * parameter changes the next color in the list. The value of Ps tells the starting - * point in the list. The colors are specified by name or RGB specification as per - * XParseColor. - * - * If a "?" is given rather than a name or RGB specification, xterm replies with a - * control sequence of the same form which can be used to set the corresponding color. - * Because more than one pair of color number and specification can be given in one - * control sequence, xterm can make more than one reply. - * - * Returns: - * nothing. - */ -static void -xterm_colors(const char *value) -{ - if (0 == (t_attributes & TA_XTERMLIKE)) /* xterm specific */ - return; - - if (NULL == value || 0 == value[0]) - return; - - trace_ilog("xterm_colors(%s)\n", value); - - if (value != t_colorsorg) { - if (0 == t_colorsorg[0]) { /* retrieve and save existing */ - xterm_colors_get(t_colorsorg, sizeof(t_colorsorg)); - } - } - - if (0 != t_colorsorg[0]) { /* set new value (if save was possible) */ - xterm_colors_set(value); - } -} - - -static int -xterm_colors_get(char *buffer, int length) -{ - int color, len; - - if (0 == (t_attributes & TA_XTERM)) { /* xterm specific */ - return -1; - } - - term_flush(); /* clear existing obuf */ - - for (len = 0, color = 0; color < XTERM_COLORS; ++color) { - /* - * foreach(color) - */ - int cnt = sprintf((char *)t_buffer, "\033]4;%d;?\007", color); - - if (cnt != sys_write(1, t_buffer, cnt) || - (cnt = term_read((char *)t_buffer, sizeof(t_buffer), 5 * 1000)) <= 0 || - sscanf((char *)t_buffer, "%*[^;];%*[^;];%s", buffer + len + (len ? 1 : 0)) != 1) { - /* - * Note, 'rxvt' and the 'linux console' only support set. - * - * rxvt shall report (on stderr)/ - * rxvt: can't determine colour: ? - */ - trace_ilog("\terr[%d] (%*s)\n", color, cnt, t_buffer); - break; - } - - trace_ilog("\tget[%d]=%s\n", color, buffer + len + (len ? 1 : 0)); - - if (len) { - buffer[len] = ','; /* separator */ - } - len += strlen(buffer + len); - assert(len < length-1); - - if ('\007' == buffer[len-1]) { /* strip terminator */ - buffer[len-1] = '\0', --len; - } - } - return 0; -} - - -static int -xterm_colors_set(const char *value) -{ - const char *term; - int color, len, cnt; - - if (0 == (t_attributes & TA_XTERMLIKE)) { /* xterm specific */ - return -1; - } - - term_flush(); /* clear existing obuf */ - - cnt = sprintf((char *)t_buffer, "\033]4"); /* dynamic color command */ - - for (color = 0; color < XTERM_COLORS; ++color) { - - if ((const char *)NULL == (term = strchr(value, ','))) { - len = strlen(value); - } else { - len = term - value; - } - - trace_ilog("\tset[%d]=%.*s\n", color, len, value ); - if (len) { - cnt += sprintf((char *)(t_buffer + cnt), ";%d;%.*s", color, len, value); - } - - assert(cnt < (int)sizeof(t_buffer)); - if (NULL == term) { - break; - } - - value = term + 1; /* next field */ - } - - cnt += sprintf((char *)(t_buffer + cnt), "\007"); - sys_write(1, t_buffer, cnt); /* terminator */ - return 0; -} - - -/* Function: term_identification - * Request the terminal (VT100 and xterm style) to echo the "Device Attributes" - * report containing terminal type and version. - * - * Parameters: - * none. - * - * Returns: - * Length of the buffer retrieved. - */ -static int -term_identification(void) -{ -#define XTERM_DEVICE_ATTR (sizeof(xterm_device_attr)-1) - static char xterm_device_attr[] = "\033[>c"; - int ret = -1; - -#if defined(__CYGWIN__) - if (TA_CYGWIN & t_attributes) { - /* - * CYGWIN - */ - struct utsname u = {0}; - int r1 = 0, r2 = 0; - - ret = -3; - if (uname(&u) >= 0) { - if (2 == sscanf(u.release, "%d.%d", &r1, &r2)) { - x_pt.pt_vtdatype = -3; /* source: xterm_cygwin */ - x_pt.pt_vtdaversion = (r1 * 100) + (r2 > 99 ? 99 : r2); - } - trace_ilog("\tcygwin_uname(%s) = %d.%d\n", u.release, r1, r2); - } - return ret; - } -#endif /*__CYGWIN__*/ - - if ((TA_VT100LIKE|TA_XTERM|TA_XTERMLIKE) & t_attributes) { - /* - * xterm and compatible terminals - */ - const char *vstring; - - /* - * XTERM_VERSION/ - * Xterm(256) ==> 256 - */ - if (NULL != (vstring = ggetenv("XTERM_VERSION"))) { - char vname[32] = {0}; - int vnumber = 0; - /* decode and return patch/version number */ - if (2 == sscanf(vstring, "%32[^(](%u)", vname, &vnumber)) - if (vnumber > 0) { - x_pt.pt_vtdatype = -2; /* source: xterm_version */ - x_pt.pt_vtdaversion = vnumber; - ret = 0; - } - trace_ilog("XTERM_VERSION(%s) = %d (%s)\n", vstring, vnumber, vname); - } - - /* - * device attribute - */ - if (-1 == ret) { - char buffer[32] = {0}; - int len = 0; - - term_flush(); - if (XTERM_DEVICE_ATTR == sys_write(1, xterm_device_attr, XTERM_DEVICE_ATTR) && - (len = term_read(buffer, sizeof(buffer), -2)) > 1) { - /* - * Example/ - * \033[>82;20710;0c - * ^type - * ^version - * - * Known terminal types/ - * xterm (0) 0;256;0c - * mintty (77) 77;10003;0c - * screen (83) - * old rxvt (82) - * rxvt unicode (85) - */ - trace_ilog("device_attr(%d, %s)\n", len, buffer); - - if ('\033' == buffer[0] && '[' == buffer[1] && - ('>' == buffer[2] || '?' == buffer[2])) { - int datype, daversion; - - if (2 == sscanf(buffer + 3, "%d;%d", &datype, &daversion)) { - trace_ilog("==> type:%d, version:%d\n", datype, daversion); - x_pt.pt_vtdatype = datype; - x_pt.pt_vtdaversion = daversion; - if (77 == datype) { - t_attributes |= TA_MINTTY; - ++tf_xn; - } - ret = 0; - } - } - } - } - } - - return ret; -} - - -/* Function: term_isutf8 - * Determine whether the terminal supports UTF8 character encoding. - * - * Where possible limit terminal interaction, as such test *all* - * configuration/environment setting prior. - * - * Parameters: - * none. - * - * Returns: - * *true* if UTF8, otherwise *false*. - */ -static int -term_isutf8(void) -{ - int ret = 0; - - if (DISPTYPE_UTF8 == xf_disptype) { /* explicitly enabled -- command line */ - ret = 1; - - } else if (DISPTYPE_7BIT == xf_disptype || DISPTYPE_8BIT == xf_disptype) { - ret = 0; /* explicitly disabled -- command line */ - - } else if (TA_LINUX & t_attributes) { /* linux console, not supported */ - ret = -2; - - } else if (TA_CYGWIN & t_attributes) { /* cygwin version (1.7+) */ - if (-3 == x_pt.pt_vtdatype) { - const int r1 = x_pt.pt_vtdaversion / 100; - const int r2 = x_pt.pt_vtdaversion % 100; - - if (2 <= r1 || (1 == r1 && 7 <= r2)) { - ret = 3; - } - } - - } else if (x_pt.pt_encoding[0]) { /* terminal encoding/locale */ - ret = (mchar_locale_utf8(x_pt.pt_encoding) ? 2 : -1); - - } else if (sys_unicode_locale(TRUE)) { /* BTERM_LOCAL or LOCALE */ - ret = 4; - - } else if (TA_XTERM & t_attributes) { - /* - * Write a single utf8 character and check resulting cursor position. - * - * Source: ICU27 and general discussions - */ -#define XTERM_UTF8_TEST1 (sizeof(xterm_utf8_test1)-1) -#define XTERM_UTF8_CLEAN1 (sizeof(xterm_utf8_clean1)-1) - - static unsigned char xterm_utf8_test1[] = "\r" "\xc3\xb6" "\033[6n"; - static unsigned char xterm_utf8_clean1[] = "\r \r"; - - ret = -5; - term_flush(); - if (XTERM_UTF8_TEST1 == sys_write(1, (void *)xterm_utf8_test1, XTERM_UTF8_TEST1)) { - int row = -1, col = -1; - char buffer[32] = {0}; - int len; - - if ((len = term_read(buffer, sizeof(buffer), -2)) >= 4 && - 2 == sscanf(buffer, "\033[%d;%dR", &row, &col)) { - if (2 == col) { - ret = 5; /* cursor in second column */ - } - } - trace_ilog("\tisutf8A(%d) = col:%d\n", len, col); - sys_write(1, (void *)xterm_utf8_clean1, XTERM_UTF8_CLEAN1); - } - - } - - trace_ilog("UTF8 support=%d\n", ret); - return (ret >= 1 ? 1 : 0); -} - - -#if (XXX_MCHAR_DETECT) -static void -term_utf8_features(void) -{ -#define XTERM_UTF8_TEST2 (sizeof(xterm_utf8_test2)-1) - - static unsigned char xterm_utf8_test2[] = { - '\r', /* UTF* features */ - 0xa5, - 0xc3, 0x84, 0xd9, - 0xa7, - 0xd8, 0xb8, 0xe0, 0xe0, - 0xa9, - 0xa9, - 0xb8, 0x88, 0xe5, 0xe5, 0x88, - 0xa2, 0xa2, - 0x1b, '[', '6', 'n', /* cursor position */ - 0x00 /* NUL */ - }; - - term_flush(); - - if (XTERM_UTF8_TEST2 == sys_write(1, xterm_utf8_test2, XTERM_UTF8_TEST2)) { - int row = -1, col = -1; - char buffer[32] = {0}; - int len; - - /* - * check cursor column after test string, determine screen mode - * - * 6 -> UTF-8, no double-width, with LAM/ALEF ligature joining - * 7 -> UTF-8, no double-width, no LAM/ALEF ligature joining - * 8 -> UTF-8, double-width, with LAM/ALEF ligature joining - * 9 -> UTF-8, double-width, no LAM/ALEF ligature joining - * 11,16 -> CJK terminal (with luit) - * 10,15 -> 8 bit terminal or CJK terminal - * 13 -> Poderosa terminal emulator, UTF-8, or TIS620 terminal - * 14,17 -> CJK terminal - * 16 -> Poderosa, ISO Latin-1 - * (17) -> Poderosa, (JIS) - * 18 -> CJK terminal (or 8 bit terminal, e.g. Linux console) - */ - if ((len = term_read(buffer, sizeof(buffer), -2)) >= 4) { - sscanf(buffer, "\033[%d;%dR", &row, &col); - } - - trace_ilog("\tisutf8B(%d) = col:%d\n", len, col); - } -} -#endif /*XXX_MCHAR_DETECT*/ - - -/* Function: term_read - * Determine if the terminal supports UTF8 character encoding. - * - * Parameters: - * buf - Buffer. - * len - Length of the buffer, in bytes. - * tmo - Timeout is milliseconds. - * - * Returns: - * Number of bytes read. - */ -static int -term_read(char *buf, int len, accint_t tmo) -{ - int ch, cnt = 0; - - if (-2 == tmo) { - tmo = io_escdelay(); - } - - assert(buf); - assert(len); - assert(tmo >= -1); - - --len; - if ((ch = io_get_raw(tmo)) > 0) { - do { /* secondary characters */ - buf[cnt++] = (char) ch; - } while ((ch = io_get_raw(50)) > 0 && cnt < len); - } - buf[cnt] = '\0'; - return cnt; -} - - -/* Function: term_tidy - * Cleanup/restore the state of the console. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_tidy(void) -{ - if (0 == tt_active) - return; - - term_flush(); - - if (t_attributes & TA_CYGWIN) { - if (xf_cygwinkb) { - ttpush("\033[?2000l"); /* disable RAW mode */ - } - } else if (t_attributes & TA_MINTTY) { -//TODO if (! xf_mouse) { - ttpush("\033[?7786l"); /* disable mouse-wheel reports */ -// } - } - - term_graphic_exit(); /* graphic mode */ - - term_colorreset(); - term_styleoff(); - xterm_colors_set(t_colorsorg); - - /* ttputpad(tc_mo); -* restore meta key-codes */ - - ttputpad(tc_ve); /* restore normal cursor */ - - if (! xf_nokeypad) { - ttputpad(tc_ke); /* out of ``keypad-transmit'' mode */ - } - - if ((NULL == tc_rs && 0 == x_pt.pt_reset[0]) || x_pt.pt_noaltscreen) { - term_zero(TRUE); /* remove image */ - ttmove(ttrows() - 1, 0); - } else { - term_scrollreset(); /* scroll window */ - } - - ttputpad(tc_rs); /* set the term back to normal mode */ - - if (x_pt.pt_reset[0]) { /* terminal specific reset */ - ttputctl2(x_pt.pt_reset, 0, 0); - } - term_flush(); - - if (! xf_noinit) { - ttputpad(tc_te); /* disable cup (cursor addressing) */ - } - term_flush(); - - trace_log("term_tidy(0x%0x)\n", t_specials); - - tt_cursor = 0; - tt_active = 0; -} - - -/* Function: term_cursor - * Set the cursor status. - * - * Parameters: - * visible - Visible status. - * imode - Insert mode. - * virtual_space - Virtual space mode. - * - * Returns: - * returns the current visible status, otherwise -1 on error. - */ -static int -term_cursor(int visible, int imode, int virtual_space) -{ - if (visible >= 0) { - if (visible != tt_cursor) - if (tc_vi && (tc_vs || tc_ve)) { - if (visible) { /* enable cursor, enhanced if available */ - ttputpad(tc_vs ? tc_vs : tc_ve); - } else { - ttputpad(tc_vi); /* hide cursor */ - } - } - tt_cursor = visible; - } - - if (tt_cursor && imode >= 0) { - if (imode) { /* insert mode */ - if (x_pt.pt_vicursor[0]) { - ttprintf(virtual_space ? x_pt.pt_vicursor : x_pt.pt_icursor); - - } else if (x_pt.pt_xtcursor >= 1 || - (-1 == x_pt.pt_xtcursor && (t_attributes & TA_XTERMLIKE))) { -#if defined(DO_SPECIALS) - if (0 == (t_specials & 0x0010)) - t_specials |= 0x0010, trace_log("SPECIAL(ttcursor) 'imode'\n"); - ttprintf("\033]12;%s\007", "Black"); -#endif - } - } else { /* overstrike/overtype mode */ - if (x_pt.pt_vocursor[0]) { - ttputpad(virtual_space ? x_pt.pt_vocursor : x_pt.pt_ocursor); - - } else if (x_pt.pt_xtcursor >= 1 || - (-1 == x_pt.pt_xtcursor && (t_attributes & TA_XTERMLIKE))) { -#if defined(DO_SPECIALS) - if (0 == (t_specials & 0x0020)) { - t_specials |= 0x0020, trace_log("SPECIALS(ttcursor) 'omode'\n"); - } - ttprintf("\033]12;%s\007", "RoyalBlue1"); -#endif - } - } - } - - return (tt_cursor ? 1 : 0); -} - - -/* Function: ttmove - * Move the cursor to the specified origin 0 row and column position. Try to - * optimize out extra moves; redisplay may have left the cursor in the right - * location last time! - * - * Parameters: - * row - Screen row (0 .. rows - 1). - * col - Column (0 .. rows - 1). - * - * Returns: - * nothing. - */ -static void -term_move(int row, int col) -{ - const int rows = ttrows() - 1, cols = ttcols() - 1, - ttrow = ttatrow(), ttcol = ttatcol(); - - assert(row >= 0); - assert(row <= rows); - assert(col >= 0); - assert(col <= cols); - - if (ttrow == row && ttcol == col) { - ED_TERM(("ttmove(%d,%d->%d,%d)\n", ttrow, ttcol, row, col)) - return; - } - ED_TERM(("ttmove(%d,%d->%d,%d)", ttrow, ttcol, row, col)) - - /* - * Moving cursor, check ms flag. - * the 'ms' flag whose presence means that it is safe to move the cursor - * while the appearance modes are not in the normal state. If this flag - * is absent, programs should always turn off underlining/standout - * before moving the cursor. - */ - if (1 != tf_ms) - if (tt_style) { - term_styleoff(); - tt_hue = -1; - } - - if (tc_ho && 0 == col && 0 == row) { /* */ - ED_TERM(("->putpad(ho)\n")) - ttputpad(tc_ho); - - } else { - /* - * optimise based on current position (if known) - */ - int done = TRUE; - - if (ttcol < 0 || ttrow < 0) { - /* - * invalid existing position. - */ - done = FALSE; - - } else if (tc_ll && row == rows && 0 == col) { - ED_TERM(("->putpad(ll)\n")) /* */ - ttputpad(tc_ll); - - } else { - /* - * If within column zero avoid using UP and DO under XTERM (others??) - * otherwise we shall find ourselves in the last column of the - * previous line; believe related to terminal automatic-margin - * support. - * - * Note: this is generally only a visible problem when running borderless mode. - */ -#define COLUMNOK() (col > 0 || 0 == (t_attributes & TA_XTERM)) - -#define PCOST 4 /* parameterised version cost */ - - if (col == ttcol) { /* row changes */ - - /* cursor up - one line (ignore first column) */ - if (tc_up && COLUMNOK() && row == ttrow - 1) { - ED_TERM(("->putpad(UP)\n")) - ttputpad(tc_up); - - /* cursor up - parameterized (ignore first column) */ - } else if (tc_pUP && COLUMNOK() && row < ttrow /*-PCOST*/) { - const int p1 = (int)(ttrow - row); - - ED_TERM(("->putctl(pUP,%d)\n", p1)) - ttputctl(tc_pUP, p1); - - /* cursor down - one line (ignore bottom left corner) */ - } else if (tc_do && COLUMNOK() && row == ttrow + 1 && (row < rows || col < (cols - 1))) { - ED_TERM(("->putpad(DO)\n")) - ttputpad(tc_do); - - /* cursor down - parameterized */ - } else if (tc_pDO && COLUMNOK() && row > ttrow /*+PCOST*/) { - const int p1 = (int)(row - ttrow); - - ED_TERM(("->putctl(pDO,%d)\n", p1)) - ttputctl(tc_pDO, p1); - - /* cursor vertical movement */ - } else if (tc_cv) { - ED_TERM(("->putctl(cv,%d)\n", row)) - ttputctl(tc_cv, row); - - } else { - done = FALSE; - } - - } else if (row == ttrow) { /* column changes */ - - /* cursor left */ - if (tc_cr && 0 == col) { - ED_TERM(("->putpad(cr)\n")) - ttputpad(tc_cr); - - /* cursor left - one column */ - } else if (tc_le && col < ttcol && col >= (ttcol - 3)) { - int p1 = (int)(ttcol - col); - - ED_TERM(("->putpad(le,%d)\n", p1)) - while (p1--) ttputpad(tc_le); - - /* cursor back */ - } else if (tc_bc && col < ttcol && col >= (ttcol - 3)) { - int p1 = (int)(ttcol - col); - - ED_TERM(("->putpad(bc,%d)\n", p1)) - while (p1-- > 0) ttputpad(tc_bc); - - /* cursor left - parameterised */ - } else if (tc_pBC && col < (ttcol - 2)) { - const int p1 = (int)(ttcol - col); - - ED_TERM(("->putctl(pBC,%d)\n", p1)) - ttputctl(tc_pBC, p1); - - /* cursor right - one column */ - } else if (tc_nd && col == ttcol + 1) { - ED_TERM(("->putpad(ND)\n")) - ttputpad(tc_nd); - - /* cursor right - parameterised */ - } else if (tc_pRI && col > ttcol && col > 1 && col < cols) { - const int p1 = (int)(col - ttcol); - - ED_TERM(("->putctl(pRI,%d)\n", p1)) - ttputctl(tc_pRI, p1); - - /* cursor right - parameterised */ - } else if (x_pt.pt_cursor_right[0] && col > ttcol /*+PCOST*/) { - const int p1 = (int)(col - ttcol); - - ED_TERM(("->putctl(pCR,%d)\n", p1)) - ttprintf(x_pt.pt_cursor_right, p1); - - /* cursor horz movement */ - } else if (tc_ch) { - ED_TERM(("->putctl(ch,%d)\n", col)) - ttputctl(tc_ch, col); - - } else { - done = FALSE; - } - - } else { - done = FALSE; /* do by hand */ - } - } - -#undef PCOST - - /* absolute cursor movement */ - if (! done) { - if (tc_cm) { - ED_TERM(("->cm(%d, %d)\n", col, row)) - ttputctl2(tc_cm, col, row); - } else { /* use vertical/horiz movement */ - ED_TERM(("->cvch(%d, d)\n", col, row)) - ttputctl(tc_cv, row); - ttputctl(tc_ch, col); - } - } - } - - ttposset(row, col); -} - - -/* Function: term_names - * Set the console title. - * - * Parameters: - * title - Title buffer. - * - * Returns: - * nothing. - */ -static int -term_names(const char *title, const char *icon) -{ - __CUNUSED(icon) - - if (x_pt.pt_xttitle >= 1 || - (-1 == x_pt.pt_xttitle && (t_attributes & TA_XTERMLIKE))) { - - const unsigned char *t = (const unsigned char *) title; - const size_t len = 16 + strlen(title); - char *c; - - if (NULL != (c = chk_alloc(len))) { - unsigned char *p = - (unsigned char *)(c + sprintf(c, "\033]0;")); - - do { - *p++ = (unsigned char)(*t < 32 || *t > 127 ? '?' : *t); - } while (*++t); - *p++ = '\007'; - *p = '\0'; - - ttpush(c); - chk_free(c); - } - } - return 0; -} - - -/* Function: term_beep - * Make a noise. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_beep(int freq, int duration) -{ - __CUNUSED(freq) __CUNUSED(duration) - - if (xf_visbell && tc_vb) { /* visual bell */ - ttputpad(tc_vb); - } else if (tc_bl) { - ttputpad(tc_bl); - } else { - static const char bel[] = {ASCIIDEF_BEL, 0}; - ttpush(bel); - } - term_flush(); -} - - -/* Function: normalbg - * Determine whether the current background is the terminals - * default/normal background color. - * - * One of the following conditions are confirmed, checking the current - * hues ground against, - * - * o Background is the terminal default (see COLORFGBG and tt_defaultfg). - * - * o Background is NONE. - * - * Parameters: - * bg - Storage returned with the cooked color enumeration. - * - * Returns: - * *true* or *false* - */ -static int -normalbg(int *bg) -{ - colattr_t ca; - - *bg = -1; - color_definition(tt_hue, &ca); - return (COLORSOURCE_SYMBOLIC == ca.bg.source && - (tt_defaultbg == (*bg = (int)tt_colormap[ca.bg.color]) || COLOR_NONE == ca.bg.color)); -} - - -/* Function: clearbg - * Determine whether a terminal clear command will (hopefully) function correctly with - * the current background color, otherwise the operation shall fail resulting in the - * cleared region being an incorrect background color; hence should be avoided. - * - * One of the following conditions are confirmed, - * - * o BE or UT, if BE (Back color erase - xterm) or UT (Screen erased with background - * color) are true the terminal clears using the current hue. - * - * o Current hue is the terminals default/normal background. - * - * o Terminal feature clrisblack is enabled and background is BLACK. - * - * o No color mode and the hue is NORMAL. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static int -clearbg(void) -{ - int bg; - - if (tf_be || tf_ut) - return TRUE; /* erase in current color */ - if (normalbg(&bg)) - return TRUE; /* current background is normal/default */ - if (x_pt.pt_clrisblack && BLACK == bg) { - return TRUE; - } - if (!vtiscolor() && ATTR_NORMAL == tt_hue) { - return TRUE; - } - return FALSE; -} - - -/* Function: term_clear - * Clear the terminal. - * - * Parameters: - * restore - *true* if the screen image should be restored. - * - * Returns: - * nothing. - */ -static void -term_clear(void) -{ - ED_TERM(("term_clear()\n")) - term_zero(FALSE); -} - - -/* Function: term_zero - * Zero the terminal image. - * - * Parameters: - * restore - *true* if the screen image should be restored. - * - * Returns: - * nothing. - */ -static void -term_zero(int restore) -{ - ED_TERM(("term_zero(%d)\n", restore)) - term_scrollreset(); - ttmove(0, 0); - term_attr(VBYTE_ATTR(ATTR_NORMAL)); - if (tc_cl && (restore || clearbg())) { /* clear screen command (and home cursor) */ - ED_TERM(("->putpad(CL)\n")) - ttputpad(tc_cl); - } else { /* erase to end of page */ - ED_TERM(("->eeop()\n")) - term_eeop(restore); - } - term_colorreset(); - term_flush(); -} - - -/* Function: term_eeol - * Erase to end of line in the 'current' color. - * - * Parameters: - * none. - * - * Returns: - * *true* if eeol successful, otherwise *false*. - */ -static int -term_eeol(void) -{ - const int rows = ttrows() - 1, cols = ttcols() - 1, - row = ttatrow(), col = ttatcol(); - - ED_TERM(("term_eeol(%d, %d)\n", row, col)) - - assert(row <= rows); - assert(col <= cols); - - if (col < cols) { - /* - * Clear to end of line. - */ - if (term_ce() && clearbg()) { - ED_TERM(("->putpad(CE)\n")) - ttputpad(tc_ce); - - /* - * Character based - * Avoid writing to the lower right corner; as the terminal does not have CE, - * then it probably does not have what it takes not to scroll upon hitting - * the bottom-right corner. - */ - } else { - int cnt = cols - col; /* column count to end-of-line */ - - if (row >= rows) { - --cnt; /* ignore last column */ - } - term_repeat(cnt, ' ' | VBYTE_ATTR(tt_hue), WHERE_START); - } - } - return TRUE; -} - - -/* Function: term_ce - * Is clear to end of line (CE) available. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static int -term_ce(void) -{ - return (tc_ce && tc_ce[0]); -} - - -/* Function: term_lastsafe - * Return whether it is safe to write to the last character within the bottom column. - * - * Parameters: - * none. - * - * Returns: - * TRUE or FALSE. - */ -static int -term_lastsafe(void) -{ - if (TA_CYGWIN & t_attributes) { - return FALSE; /* needs further investigations */ - } - return (term_ce() || tf_LP > 0 ? TRUE : FALSE); -} - - -/* Function: term_eeop - * Erase to end of page. - * - * Parameters: - * restore - Executed during a restore operation. - * - * Returns: - * nothing. - */ -static void -term_eeop(int restore) -{ - const int rows = ttrows() - 1, cols = ttcols() - 1; - int row = ttatrow(), col = ttatcol(); - - ED_TERM(("term_eeop(%d, %d)\n", row, col)) - - assert(row <= rows); - assert(col <= cols); - - if (tc_cd && (restore || clearbg())) { /* clear to end of display (cursor unchanged). */ - ED_TERM(("->putpad(CD)\n")) - ttputpad(tc_cd); - - } else { /* long-hand */ - int done = FALSE; - - if (col > 0) { - term_eeol(); /* remove remaining of line */ - ++row; - } - - if (row <= rows) { - if (t_insdel && !x_pt.pt_noinsdel && (restore || clearbg())) { - done = term_dell(row, rows, rows - row, 0 /*current*/); - if (done) { - ED_TERM(("->ttdell()\n")) - } - } - - if (! done) { /* do it by hand. */ - ED_TERM(("->line-by-line()\n")) - for (; row <= rows; ++row) { - ttmove(row, 0); - term_eeol(); - } - } - } - } -} - - -/* Function: term_repeat - * Function to repeat a character from the current location. - * - * 'where' says whether we want the cursor to stick at the starting point or stick - * at the end of the region. If set to 2 then this is a don't care -- i.e. leave - * cursor as it is. - * - * Parameters: - * cnt - Character count. - * fill - Fill character. - * where - Where to leave the cursor (0=end, 1=start, 2=dontcare). - * - * Returns: - * nothing. - */ -static void -term_repeat(int cnt, vbyte_t fill, int where) -{ - const int orow = ttatrow(), ocol = ttatcol(); - - ED_TERM(("term_repeat(%d,'%c')\n", cnt, VBYTE_CHAR_GET(fill))) - - if (cnt <= 0) return; - - term_attr(fill & VBYTE_ATTR_MASK); - - if (cnt >= (4 + (WHERE_DONTCARE == where ? 0 : 4))) { - const int ch = (int) VBYTE_CHAR_GET(fill); - int bg = 0; - /* erase #1 characters (no cursor move) */ - if (tc_ech && ' ' == ch && normalbg(&bg)) { - - if (0 == (t_specials & 0x0001)) - t_specials |= 0x0001, trace_log("SPECIAL(erase-repeat,%s,%d)\n", tc_ech, cnt); - - ttputctl(tc_ech, cnt); - ttposinvalid(); - if (WHERE_END == where) { - ttmove(orow, ocol + cnt); - } else if (WHERE_START == where) { - ttmove(orow, ocol); - } - cnt = 0; - /* repeat character (cursor move) */ - } else if (tc_rp && (orow < (ttrows() - 1))) { - - if (0 == (t_specials & 0x0002)) - t_specials |= 0x0002, trace_log("SPECIAL(repeat-char,%s,%d)\n", tc_rp, cnt); - - ttputctl2(tc_rp, cnt, ch); - ttposinvalid(); - if (WHERE_END == where) { - ttmove(orow, ocol + cnt); - } else if (WHERE_START == where) { - ttmove(orow, ocol); - } - cnt = 0; - /* erase #1 characters (no cursor move) */ - } else if (x_pt.pt_repeat_space[0] && ' ' == ch && normalbg(&bg)) { - - if (0 == (t_specials & 0x0004)) - t_specials |= 0x0004, trace_log("SPECIAL(erase-repeat,%s)\n", x_pt.pt_repeat_space); - - ttprintf(x_pt.pt_repeat_space, cnt); - ttposinvalid(); - if (WHERE_END == where) { - ttmove(orow, ocol + cnt); - } else if (WHERE_START == where) { - ttmove(orow, ocol); - } - cnt = 0; - - } else if (x_pt.pt_repeat_last[0] && /* repeat last (cursor move *not* assumed) */ - (orow < (ttrows() - 1)) && normalbg(&bg)) { - - if (0 == (t_specials & 0x0008)) - t_specials |= 0x0008, trace_log("SPECIAL(repeat-last,%s,%d)\n", x_pt.pt_repeat_last, cnt); - - term_putc(fill); - ttprintf(x_pt.pt_repeat_last, cnt - 1); - ttposinvalid(); - if (WHERE_END == where) { - ttmove(orow, ocol + cnt); - } else if (WHERE_START == where) { - ttmove(orow, ocol); - } - cnt = 0; - } - } - - if (cnt > 0) { /* by-hand */ - ED_TERM(("->byhand()\n")) - while (cnt-- > 0) { - term_putc(fill); - } - if (WHERE_START == where) { - ttmove(orow, ocol); - } - } -} - - -/* Function: term_insl - * Insert the specified number of blank lines 'lines' onto the screen using the region - * 'row' and 'bot', scrolling the last line within the region off the screen. - * - * Use the scrolling region commands if possible for a smoother display, otherwise - * when no scrolling region, use a set of insert and delete line sequences. - * - * Parameters: - * row - Top row of region. - * bot - Bottom of region. - * nlines - Number of lines to be inserted. - * fillcolor - Fill attribute. - * - * Returns: - * TRUE if the operation could be performed, otherwise FALSE. - */ -static int -term_insl(int row, int bot, int nlines, vbyte_t fillcolor) -{ - int i; - - trace_log("term_insl(row:%d, bot:%d, nlines:%d)\n", row, bot, nlines); - - assert(row >= 0); - assert(bot >= 0); - assert(row < ttrows()); - assert(bot < ttrows()); - assert(bot >= row); - assert(nlines > 0); - assert(nlines <= (bot - row)); - - term_attr(fillcolor); - - if (row == bot) { /* one line, simple optimisation */ - ttmove(row, 0); - term_eeol(); - return TRUE; - } - /* scroll region and back index */ - if (tc_cs && tc_sr && !x_pt.pt_scroll_disable) { - term_scrollset(row, bot); - ttmove(row, 0); - if (nlines > 1 && tc_pSR) { - ttputctl(tc_pSR, nlines); - } else { - for (i = 0; i < nlines; ++i) { - ttputpad(tc_sr), term_eeol(); - } - } - term_scrollreset(); - ttmove(row, 0); - return TRUE; - } - - if (t_insdel && !x_pt.pt_noinsdel) { /* line ins/del */ - ttmove(1 + bot - nlines, 0); - if (nlines > 1 && tc_pDL) { - ttputctl(tc_pDL, nlines); - } else { - for (i = 0; i < nlines; ++i) { - ttputpad(tc_dl); - } - } - - ttmove(row, 0); - if (nlines > 1 && tc_pAL) { - ttputctl(tc_pAL, nlines); - } else { - for (i = 0; i < nlines; ++i) { - ttputpad(tc_al); - } - } - - if (!tf_be || !tf_ut) /* must erase line for correct colouring */ - for (i = 0; i < nlines; ++i) { - ttmove(row + i, 0); - term_eeol(); - } - - ttposinvalid(); - return TRUE; - } - return FALSE; -} - - -/* Function: term_dell - * Delete the specified number of blank lines 'nlines' onto the screen using the region - * 'row' and 'bot', replacing the last line within a blank line. - * - * Use the scrolling region commands if possible for a smoother display, otherwise - * when no scrolling region, use a set of insert and delete line sequences. - * - * Knownledge that the echo-line shall always be presence, removes the end-of-screeen - * boundary condition. - * - * Parameters: - * row - Top row of region. - * bot - Bottom of region. - * nlines - Number of lines to be deleted. - * fillcolor - Fill attribute. - * - * Returns: - * TRUE if the operation could be performed, otherwise FALSE. - */ -static int -term_dell(int row, int bot, int nlines, vbyte_t fillcolor) -{ - int i; - - trace_log("term_dell(row:%d, bot:%d, nlines:%d)\n", row, bot, nlines); - - assert(row >= 0); - assert(bot >= 0); - assert(row < ttrows()); - assert(bot < ttrows()); - assert(bot >= row); - assert(nlines > 0); - assert(nlines <= (bot - row)); - - term_attr(fillcolor); - - if (row == bot) { /* one line special case */ - ttmove(row, 0); - term_eeol(); - return TRUE; - } - - if (tc_cs && !x_pt.pt_scroll_disable && /* scrolling region and within limits */ - (x_pt.pt_scroll_max <= 2 || (bot - row) <= x_pt.pt_scroll_max)) { - term_scrollset(row, bot); - ttmove(bot, 0); - if (nlines > 1 && tc_pSF) { - ttputctl(tc_pSF, nlines); /* 24/11/08 */ - } else { - for (i = 0; i < nlines; ++i) { - ttputpad(tc_sf ? tc_sf : "\n"), term_eeol(); - } - } - term_scrollreset(); - ttmove(bot, 0); - return TRUE; - } - /* ins/del, unless disabled or fast */ - if (t_insdel && !x_pt.pt_noinsdel && x_pt.pt_tty_fast <= 0) { - ttmove(row, 0); - if (nlines > 1 && tc_pDL) { - ttputctl(tc_pDL, nlines); - } else { - for (i = 0; i < nlines; ++i) { - ttputpad(tc_dl); - } - } - ttmove(1 + bot - nlines, 0); - if (nlines > 1 && tc_pAL) { - ttputctl(tc_pAL, nlines); - } else { - for (i = 0; i < nlines; ++i) { - ttputpad(tc_al); - } - } - ttposinvalid(); - return TRUE; - } - return FALSE; -} - - -/* Function: term_scrollset - * Setup the display scrolling window. - * - * Note: - * Setting a scroll region invalidates the cursor position. As such the cursor - * position is also invalidated to ensure that the next call to "ttmove" does - * not turn into a no-op (the window adjustment moves the cursor). - * - * Parameters: - * top - Top row of the scroll region. - * bot - Bottom row. - * - * Returns: - * nothing. - */ -static void -term_scrollset(int top, int bot) -{ - assert(top >= 0); - assert(top < ttrows()); - assert(bot >= 0); - assert(bot < ttrows()); - assert(-1 == top || top != bot); /* one line, should be avoided */ - assert(top < bot); - assert(tc_cs); /* should always be the case */ - - if (tc_cs) { /* scroll region avail ? */ - if (-1 == top || -1 == bot) { - top = 0, bot = ttrows() - 1; /* reset */ - } - - if (tt_top != top || tt_bot != bot) { /* update */ - ttputctl2(tc_cs, tt_bot = bot, tt_top = top); - ttposinvalid(); - } - } -} - - -/* Function: term_scrollreset - * Reset the current scroll region. - * - * Note: - * Setting a scroll region invalidates the cursor position. As such the cursor - * position is also invalidated to ensure that the next call to "ttmove" does - * not turn into a no-op (the window adjustment moves the cursor). - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_scrollreset(void) -{ - if (tc_cs) { - ttputctl2(tc_cs, tt_bot = ttrows() - 1, tt_top = 0); - ttposinvalid(); - } -} - - -/* Function: term_attr - * Set the current attribute color to the specified color. - * - * The following function optimises based on the required color change and the - * current known state (if any). - * - * Parameters: - * color - Required color attribute. - * - * Returns: - * nothing. - */ -static void -term_attr(vbyte_t color) -{ - vbyte_t attr = VBYTE_ATTR_GET(color); /* encode attribute */ - - if (tt_hue == attr) { - return; - } - tt_hue = attr; - - ED_TERM(("ttattr(%d/0x%x)", attr, attr)) - - if (! vtiscolor()) { - /* - * black-wbite/no-color mode - * \033[0m Normal. - * \033[1m Bold (extra bright). - * \033[4m Underline. - * \033[5m Blink (appears as Bold on Xterm etc). - * \033[7m Inverse (hilight). - * - * optional: - * \033[22m Normal (neither bold nor faint). - * \033[24m End underline. - */ - const int nstyle = ttbandw(attr, tc_us?1:0, tc_ZH?1:0, tc_mb?1:0); - - if (tt_style != nstyle) { - term_styleoff(); - term_styleon(nstyle); - } - - } else { - colattr_t ca = {0}; - int fg, bg, sf; - - color_definition(attr, &ca); - fg = ca.fg.color; - bg = ca.bg.color; - sf = ca.sf; - - ED_TERM((", curr(fg:%d, bg:%d, sf:%d), attr(fg:%d, bg:%d, sf:%d)", tt_fg, tt_bg, tt_style, fg, bg, sf)) - - if (tt_colors >= 88 /*88 or 256*/) { - /* 256 color mode - * - * \033[0m Set normal (foreground, background and styles) - * \033[39m Normal foreground color. - * \033[49m Normal background color. - * \033[38;5;#m Set the foreground color to index # - * \033[48;5;#m Set the background color to index # - */ - if (COLORSOURCE_SYMBOLIC == ca.fg.source) fg = tt_colormap[fg]; - if (COLORSOURCE_SYMBOLIC == ca.bg.source) bg = tt_colormap[bg]; - - ED_TERM(("->map(fg:%d, bg:%d)", fg, bg)) - - if (fg != tt_fg || bg != tt_bg || sf != tt_style) { - char ebuf[64]; - - if (tt_style) term_styleoff(); - - if (fg >= 0 && bg >= 0) { /* foreground,background */ - // if (x_pt.pt_colorsetfgbg[0]) { - // sxprintf(ebuf, sizeof(ebuf), x_pt.pt_colorsetfgbg, 0xff & fg, 0xff & bg); - // - // } else if (x_pt.pt_colorsetfg[0] && x_pt.pt_colorsetbg[0]) { - // int len = sxprintf(ebuf, sizeof(ebuf), x_pt.pt_colorsetfg, 0xff & fg); - // sxprintf(ebuf + len, sizeof(ebuf) - len, x_pt.pt_colorsetbg, 0xff & bg); - // - // } else { - sxprintf(ebuf, sizeof(ebuf), "\033[38;5;%u;48;5;%um", 0xff & fg, 0xff & bg); - // } - ttputpad(ebuf); - - } else if (fg >= 0) { /* foreground,normal */ - // if (x_pt.pt_colorsetfgbg[0]) { - // sxprintf(ebuf, sizeof(ebuf), x_pt.pt_colorsetfgbg, 0xff & fg, 0); - // - // } else if (x_pt.pt_colorsetfg[0] && x_pt.pt_colorsetbg[0]) { - // int len = sxprintf(ebuf, sizeof(ebuf), x_pt.pt_colorsetfg, 0xff & fg); - // sxprintf(ebuf + len, sizeof(ebuf) - len, x_pt.pt_colorsetbg, 0); - // - // } else { - sxprintf(ebuf, sizeof(ebuf), "\033[49;38;5;%um", 0xff & fg); - // } - ttputpad(ebuf); - - } else if (bg >= 0) { /* normal,background */ - // if (x_pt.pt_colorsetfgbg[0]) { - // sxprintf(ebuf, sizeof(ebuf), x_pt.pt_colorsetfgbg, 0, 0xff & bg); - // - // } else if (x_pt.pt_colorsetfg[0] && x_pt.pt_colorsetbg[0]) { - // int len = sxprintf(ebuf, sizeof(ebuf), x_pt.pt_colorsetfg, 0); - // sxprintf(ebuf + len, sizeof(ebuf) - len, x_pt.pt_colorsetbg, 0xff & bg); - // - // } else { - sxprintf(ebuf, sizeof(ebuf), "\033[39;48;5;%um", 0xff & bg); - // } - ttputpad(ebuf); - - } else { /* normal */ - sxprintf(ebuf, sizeof(ebuf), "\033[0m"); - ttputpad(tc_me ? tc_me : "\033[0m"); - } - - if (sf) term_styleon(sf); - } - - } else if (tt_colors > 8 || NULL == tc_Color_Bg || NULL == tc_Color_Fg) { - /* 16 color mode (standard - ANSI) - * - * \033[0m Set normal (foreground and background) - * - * \033[30m Set foreground color to Black - * \033[31m Set foreground color to Red - * \033[32m Set foreground color to Green - * \033[33m Set foreground color to Yellow - * \033[34m Set foreground color to Blue - * \033[35m Set foreground color to Magenta - * \033[36m Set foreground color to Cyan - * \033[37m Set foreground color to White - * \033[1;%dm Set foreground color (bright, 30 .. 37) - * - * \033[40m Set background color to Black - * \033[41m Set background color to Red - * \033[42m Set background color to Green - * \033[43m Set background color to Yellow - * \033[44m Set background color to Blue - * \033[45m Set background color to Magenta - * \033[46m Set background color to Cyan - * \033[47m Set background color to White - * \033[5;%dm Set background color (bright, 40 -- 47) - * - */ - char ebuf[48] = "\033["; /* leading */ - int l = 2; - - if (COLORSOURCE_SYMBOLIC == ca.fg.source) fg = tt_colormap[fg]; - if (COLORSOURCE_SYMBOLIC == ca.bg.source) bg = tt_colormap[bg]; - if (fg == bg && bg >= 0) { - if (TA_DARK & t_attributes) { - fg = tt_colormap[WHITE]; - bg = tt_colormap[BLACK]; - } else { - fg = tt_colormap[BLACK]; - bg = tt_colormap[WHITE]; - } - } - - /* do we need/can reset to normal */ - if (fg < 0 || bg < 0) { - strcpy(ebuf+l, "0;"); /* normal */ - tt_fg = (fg < 0 ? fg : NOCOLOR); - tt_bg = (bg < 0 ? bg : NOCOLOR); - tt_style = 0; - l += 2; - - } else { - if ((NOCOLOR == tt_fg) || - (!(bg & 0x8) && (tt_bg & 0x8)) || (!(fg & 0x8) && (tt_fg & 0x8)) || - (tt_defaultfg == fg && fg != tt_fg) || (tt_defaultbg == bg && bg != tt_bg)) { - strcpy(ebuf+l, "0;"); /* normal */ - tt_fg = (tt_defaultfg == fg ? fg : NOCOLOR); - tt_bg = (tt_defaultbg == bg ? bg : NOCOLOR); - tt_style = 0; - l += 2; - } - } - - if (tt_style != sf && tt_style) { - term_styleoff(); - } - - /* color selection */ - if (fg != tt_fg) { /* foreground 30 - 37 */ - l += sprintf(ebuf+l, (fg & 8) ? "1;%u" : "%u", 30 + (fg & 7)); - } - - if (bg != tt_bg) { /* background 40 - 47 */ - if (l > 2) { - ebuf[l++] = ';'; - } - l += sprintf(ebuf+l, (bg & 8) ? "5;%u" : "%u", 40 + (bg & 7)); - } - - if (l > 2) { /* flush result */ - ebuf[l++] = 'm'; - ebuf[l++] = 0; - assert(l < (int)sizeof(ebuf)); - ttputpad(ebuf); - } - - if (tt_style != sf) { - term_styleon(sf); /* style changes */ - } - - } else if (tc_Color_Fg == tc_ANSI_Color_Fg) { - /* - * ANSI - 16+8 color mode - */ - if (COLORSOURCE_SYMBOLIC == ca.fg.source) fg = color_map[fg].c16; - if (COLORSOURCE_SYMBOLIC == ca.bg.source) bg = color_map[bg].c16; - if (fg == bg && bg >= 0) { - if (TA_DARK & t_attributes) { - fg = color_map[WHITE].c16; - bg = color_map[BLACK].c16; - } else { - fg = color_map[BLACK].c16; - bg = color_map[WHITE].c16; - } - } - - if (fg < 0 || bg < 0) { - ttputpad(tc_me ? tc_me : "\033[0m"); - tt_fg = (fg < 0 ? fg : NOCOLOR); - tt_bg = (bg < 0 ? bg : NOCOLOR); - tt_style = 0; - } - - if (tt_style != sf && tt_style) { - term_styleoff(); - } - - if (fg != tt_fg) { - ttputpad((fg & 0x8) ? tc_md : tc_se); - ttputctl(tc_Color_Fg, (fg & 7)); - } - - if (bg != tt_bg) { - ttputctl(tc_Color_Bg, (bg & 7)); - } - - if (tt_style != sf) { - term_styleon(sf); /* style changes */ - } - - } else { - /* - * PC - 16+8 color mode - */ - if (COLORSOURCE_SYMBOLIC == ca.fg.source) fg = color_map[fg].c16_pc; - if (COLORSOURCE_SYMBOLIC == ca.bg.source) bg = color_map[bg].c16_pc; - if (fg == bg && bg >= 0) { - if (TA_DARK & t_attributes) { - fg = color_map[WHITE].c16_pc; - bg = color_map[BLACK].c16_pc; - } else { - fg = color_map[BLACK].c16_pc; - bg = color_map[WHITE].c16_pc; - } - } - - if (fg < 0 || bg < 0) { - ttputpad(tc_me ? tc_me : "\033[0m"); - tt_fg = (fg < 0 ? fg : NOCOLOR); - tt_bg = (bg < 0 ? bg : NOCOLOR); - tt_style = 0; - } - - if (tt_style != sf && tt_style) { - term_styleoff(); - } - - if (fg != tt_fg) { - ttputpad((fg & 0x8) ? tc_md : tc_se); - ttputctl(tc_Color_Fg, fg & 7); - } - - if (bg != tt_bg) { - ttputctl(tc_Color_Bg, bg & 7); - } - - if (tt_style != sf) { - term_styleon(sf); /* style changes */ - } - } - - tt_fg = fg; - tt_bg = bg; - } - - ED_TERM(("\n")) -} - - -/* Function: term_styleon - * Enable the states styles. - * - * Parameters: - * ntype - New style bitmap. - * - * Returns: - * nothing. - */ -static void -term_styleon(unsigned nstyle) -{ - if (vtiscolor() && tn_NC > 0) { - return; /* XXX - color/attributes dont mix, should mask */ - } - -#if defined(HAVE_TERMINFO) - if (tc_sa && !vtiscolor()) { - ttputpad(tparm((char *)tc_sa, /* attribute set, mono only */ - /*STANDOUT*/ (nstyle & (COLORSTYLE_STANDOUT|COLORSTYLE_INVERSE)) != 0, - /*UNDERLINE*/ (nstyle & COLORSTYLE_UNDERLINE) != 0, - /*REVERSE*/ (nstyle & COLORSTYLE_REVERSE) != 0, - /*BLINK*/ (nstyle & COLORSTYLE_BLINK) != 0, - /*DIM*/ (nstyle & COLORSTYLE_DIM) != 0, - /*BOLD*/ (nstyle & COLORSTYLE_BOLD) != 0, - /*INVISIBLE*/ 0, - /*PROTECT*/ 0, - /*ALTCHAR*/ (t_gmode ? 1 : 0))); - tt_style |= nstyle; - return; - } -#endif /*HAVE_TERMINFO*/ - -#define ACTIVATE_STYLE(x) \ - ((nstyle & (x)) && 0 == (tt_style & (x))) - - if (ACTIVATE_STYLE(COLORSTYLE_STANDOUT)) { - ttputpad(tc_so); /* standout mode. */ - } else if (ACTIVATE_STYLE(COLORSTYLE_INVERSE)) { - ttputpad(tc_so); - } - - if (ACTIVATE_STYLE(COLORSTYLE_REVERSE)) { - ttputpad(tc_mr ? tc_mr : tc_so); /* reverse */ - } - - if (ACTIVATE_STYLE(COLORSTYLE_UNDERLINE)) { - ttputpad(tc_us); /* underline */ - } - - if (ACTIVATE_STYLE(COLORSTYLE_BOLD)) { - ttputpad(tc_md); /* bold */ - } - - if (ACTIVATE_STYLE(COLORSTYLE_BLINK)) { - ttputpad(tc_mb); /* blink */ - } - - if (ACTIVATE_STYLE(COLORSTYLE_ITALIC)) { - ttputpad(tc_ZH); /* italic */ - } - - tt_style |= nstyle; -} - - -/* Function: term_styleoff - * Disable any current styles. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_styleoff(void) -{ - if (tt_style && tc_me) { /* simple */ - ttputpad(tc_me); - - } else { /* case-by-case */ - if (tt_style & (COLORSTYLE_STANDOUT|COLORSTYLE_INVERSE|COLORSTYLE_BOLD|COLORSTYLE_BLINK)) { - /* - * end standout mode - */ - if (tc_se == tc_ZH) tt_style &= (unsigned)(~COLORSTYLE_REVERSE); - if (tc_se == tc_ue) tt_style &= (unsigned)(~COLORSTYLE_UNDERLINE); - if (tc_se == tc_ZR) tt_style &= (unsigned)(~COLORSTYLE_ITALIC); - ttputpad(tc_se); /* inverse, bold ... */ - } - - if (tt_style & COLORSTYLE_REVERSE) { - ttputpad(tc_ZX); /* reverse */ - } - - if (tt_style & COLORSTYLE_UNDERLINE) { /* underline */ - ttputpad(tc_ue); - } - - if (tt_style & COLORSTYLE_ITALIC) { /* italic */ - ttputpad(tc_ZR); - } - } - tt_style = 0; -} - - -/* Function: term_colorreset - * Reset the terminal color to the system default. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_colorreset(void) -{ - ttputpad(tc_me ? tc_me : "\033[0m"); - tt_fg = tt_bg = NOCOLOR; - tt_hue = 0; -} - - -/* Function: putfakech - * Fake character output support callback for term_cost(). - * - * Parameters: - * c - Character value. - * - * Returns: - * Always zero. - */ -static int -putfakech(TPUTS_OUTTYPE c) -{ - (void)c; - ++t_cost; - return 0; -} - - -/* Function: term_cost - * Calculate the cost of displaying the specified string 'str'. - * - * Parameters: - * str - Control sequence. - * - * Returns: - * cost in characters. - */ -static int -term_cost(const char *str) -{ - t_cost = 0; - tputs((char *)str, ttrows(), TPUTS_OUTFUNC putfakech); - return t_cost; -} - - -/* Function: putpadch - * termcap ttputpad() callback. - * - * Parameters: - * ch - Character value. - * - * Returns: - * Always zero, - */ -static int -putpadch(TPUTS_OUTTYPE ch) -{ - if (ch == t_padchar && x_pt.pt_tty_fast > 0) { - return 0; /* consume padding characters */ - } - if (t_count >= sizeof(t_buffer)) { - panic("ttputpad buffer overflow."); - } - t_buffer[ t_count++ ] = (unsigned char)ch; - return 0; -} - - -/* Function: ttputpad - * termcap/terminfo output primitive. - * - * Parameters: - * str - Control sequence. - * - * Returns: - * nothing. - */ -static void -ttputpad(const char *str) -{ - if (str && str[0]) { - if (t_count + strlen(str) >= NOBUF) { - term_flush(); - } - ED_TRACE3(("ttputpad(\"%s\")\n", str)) - tputs((char *)str, 1, TPUTS_OUTFUNC putpadch); - } -} - - -/* Function: ttputctl - * termcap/terminfo print output primitive. - * - * Parameters: - * str - Control sequence. - * p1 - Argument. - * - * Returns: - * nothing. - */ -static void -ttputctl(const char *str, int p1) -{ - if (str && str[0]) { -#if defined(HAVE_TERMINFO) - ttputpad(tparm((char *)str, p1, 0)); -#else - ttputpad(tgoto((char *)str, 0, p1)); -#endif - } -} - - -/* Function: ttputctl2 - * termcap/terminfo print output primitive. - * - * Parameters: - * str - Control sequence. - * p2 - Second parameter. - * p1 - First parameter. - * - * Returns: - * nothing. - */ -static void -ttputctl2(const char *str, int p2, int p1) -{ - if (str && str[0]) { -#if defined(HAVE_TERMINFO) - ttputpad(tparm((char *)str, p1, p2, 0)); -#else - ttputpad(tgoto((char *)str, p2, p1)); -#endif - } -} - - -/* Function: ttprintf - * Non-termcap print output primitive. - * - * Parameters: - * str - Format specification. - * ... - optional argument. - * - * Returns: - * nothing. - */ -static void -ttprintf(const char *str, ...) -{ - va_list ap; - char buf[512]; - - va_start(ap, str); - vsxprintf(buf, sizeof(buf), str, ap); - ttputpad(buf); - va_end(ap); -} - - -/* Function: ttpush - * Push characters into the output buffer. - * - * Parameters: - * cp - Character buffer. - * - * Returns: - * nothing. - */ -void -ttpush(const char *cp) -{ - const int len = strlen(cp); - - if ((t_count + len) > sizeof(t_buffer)) { - panic("ttpush buffer overflow."); - } - memcpy(t_buffer + t_count, cp, len); - t_count += len; -} - - -/* Function: ttputc - * Write character to the display. - * - * Characters are buffered up, to make things a little bit more efficient. - * - * Parameters: - * c - Character value. - * - * Returns: - * nothing. - */ -static void -term_putc(vbyte_t c) -{ - const int rows = ttrows() - 1, cols = ttcols() - 1; - int ttrow = ttatrow(), ttcol = ttatcol(); - int width = 1; - - assert(ttrow <= rows); - assert(ttcol <= cols); - - if (t_count >= (NOBUF - (MCHAR_MAX_LENGTH * 2))) { - term_flush(); - } - - /* - * colorize - */ - term_attr(c & VBYTE_ATTR_MASK); - c &= VBYTE_CHAR_MASK; - if (0 == c) { /* color-change only */ - return; - } - - /* - * UNICODE and special characters - */ - if (c >= 0x80) { - const int isutf8 = vtisutf8(); - - /* - * internal characters - */ - if (c >= CH_MIN && c <= CH_MAX) { - const int unicode = (xf_graph && isutf8 && - (t_acs_locale_breaks || 0 == (DC_ASCIIONLY & x_display_ctrl))); - int uch; - - ED_TRACE3(("graphic(isutf8:%d, char:%d/0x%x)\n", isutf8, c, c)) - if (unicode && (uch = cmap_specunicode(c)) > 0) { - if (CH_PADDING == (c = uch)) { - ED_TRACE3(("ttputc_pad(row:%d, col:%d\n", ttrow, ttcol)) - return; - } - } else { - const char *cp; - - if (NULL != (cp = ttspecchar(c))) { - ED_TRACE3(("ttputc_spec(row:%d, col:%d, char:%d/0x%x, cp:%s)\n",\ - ttrow, ttcol, c, c, cp)) - if (x_pt.pt_tty_graphicsbox) { - term_graphic_enter(); - } - ttpush(cp); - goto complete; - } - ED_TRACE3(("--> no mapping\n")) - } - } - - /* - * width character enabled displays - */ - if (isutf8 && MCHAR_ISUTF8(c)) { /* MCHAR */ - if ((width = ucs_width(c)) >= 0) { - ED_TRACE3(("ttputc_utf8(row:%d, col:%d, char:%d/0x%x, width:%d)\n",\ - ttrow, ttcol, c, c, width)) - term_graphic_exit(); - t_count += charset_utf8_encode(c, (char *)(t_buffer + t_count)); - goto complete; - } - width = 1; /* control */ - } - } - - /* - * others - */ - ED_TRACE3(("ttputc_norm(row:%d, col:%d, char:%d/0x%x/%c)\n",\ - ttrow, ttcol, c, c, (c >= 32 && c < 0x7f ? c : '.'))) - - term_graphic_exit(); - if (ASCIIDEF_ESC == c && x_pt.pt_escape[0]) { - ttpush(x_pt.pt_escape); - goto complete; - - } else if (c >= 0x80) { - if (c >= 0xa0 || 0 == x_pt.pt_character[0]) { - goto hell; - } - - ED_TERM(("ttchar(ch:0x%2x/?, wid:%d, pos:%2d/%2d, cnt:%d)\n",\ - c, width, ttrow, ttcol, t_count)) - t_count += sprintf((char *)(t_buffer + t_count), x_pt.pt_character, (int)c); - goto complete; - } - - if ('~' == c && tf_hz) { /* no hazel support (rare) - remap */ - c = '^'; - } - -hell:; - ED_TERM(("ttchar(ch:0x%2x/%c, attr:0x%2x, wid:%d, pos:%2d/%2d, cnt:%d)\n", \ - c, (c <= 0x79 ? c : ' '), width, ttrow, ttcol, t_count)) - - t_buffer[t_count++] = (unsigned char)(c); - assert(c >= ' '); - - if ('\b' == c) { /* backspace */ - if (ttcol) { - ED_TRACE3(("ttmove(%d,%d->back\n", ttrow, ttcol)) - ttposset(ttrow, ttcol - 1); - } else { - ttposinvalid(); - } - return; - - } else if ('\n' == c) { /* new-line */ - if (ttrow < rows) { - ED_TRACE3(("ttmove(%d,%d->newline\n", ttrow, ttcol)) - ttposset(ttrow + 1, ttcol); - } else { - ttposinvalid(); - } - return; - - } else if ('\r' == c) { /* return */ - ED_TRACE3(("ttmove(%d,%d->return\n", ttrow, ttcol)) - ttposset(ttrow, 0); - return; - - } else if (ASCIIDEF_BEL == c) { /* bell (noisy) */ - ED_TRACE3(("ttmove(%d,%d)->bell\n", ttrow, ttcol)) - return; - } - -complete:; - ttcol += width; - - ED_TRACE3(("ttmove(%d,%d)-", ttrow, ttcol)) - - if (ttcol > cols) { /* cursor wrap */ - /* - * Source: http://www.gnu.org/software/termutils/manual/ - */ - if (tf_xn && (cols >= 80 || ttrow == rows)) { - /* - * undefined/strange eol cursor rules/NL ignore after 80th column - */ - ED_TRACE3(("xn-(-1,-1)\n")) - ttposinvalid(); - return; - - } else if (tf_am) { - /* - * obeys margins - */ - ED_TRACE3(("wrap(%d,%d)", tt_top, tt_bot)) - if (tt_bot >= 0) { - if (++ttrow > tt_bot) { - ttrow = tt_bot; /* scroll region active */ - } - } else if (++ttrow > rows) { - ttrow = rows; /* otherwise physical screen */ - } - ttcol = 0; - - } else { - /* - * nowrap/ignored - */ - ED_TRACE3(("->nowrap", ttrow, ttcol)) - --ttcol; - } - } - - ED_TRACE3(("-(%d,%d)\n", ttrow, ttcol)) - ttposset(ttrow, ttcol); -} - - -/* Function: term_graphic_enter - * Switch terminal into graphics/altnative character set mode. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static __CINLINE void -term_graphic_enter(void) -{ - if (xf_graph) { - if (FALSE == t_gmode) { - const char *cmd = x_pt.pt_graphics_mode; - - if (0 == cmd[0]) { - cmd = tc_acs_start; /* default */ - } - if (cmd[0]) { - ttputpad(cmd); - t_gmode = TRUE; - } - ED_TRACE3(("term_graphic_enter(%d)\n", t_gmode)) - } - } -} - - -/* Function: term_graphic_exit - * Switch terminal out of graphics/alternative character set mode. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static __CINLINE void -term_graphic_exit(void) -{ - if (t_gmode) { - const char *cmd = x_pt.pt_text_mode; - - if (0 == cmd[0]) { - cmd = tc_acs_end; /* default */ - } - if (cmd[0]) { - ttputpad(cmd); - } - t_gmode = FALSE; - ED_TRACE3(("term_graphic_exit()\n")) - } -} - - -/* Function: term_flush - * Flush the tty buffer. - * - * Parameters: - * none. - * - * Returns: - * nothing. - */ -static void -term_flush(void) -{ - if (t_count > sizeof(t_buffer)) { - panic("ttbuffer overflow."); - } - - if (t_count > 0) { - t_charout += t_count; - if (FALSE == x_background) { - if (!xf_compat) { /* TRUE=normal i/o otherwise optimised */ - sys_tty_delay(TTY_OUTFD, 1); - } - ED_TERM(("term_flush(length:%d)\n", t_count)) -#if defined(ED_LEVEL) && (ED_LEVEL >= 1) - if (DB_TERMINAL & x_dflags) { - trace_data(t_buffer, t_count, "\n"); - } -#endif - sys_write(TTY_OUTFD, t_buffer, t_count); - } - t_count = 0; - } -} - - -/* Function: term_sizeget - * Retrieve the display screen. - * - * Parameters: - * nrow - Storage for row number. - * ncol - Number of columns. - * - * Returns: - * void - */ -static void -term_sizeget(int *nrow, int *ncol) -{ - const char *env; -#if defined(TIOCGWINSZ) - struct winsize ws = {0}; - - do { - if ((ioctl(1, TIOCGWINSZ, (char *) &ws) == 0) || - (ioctl(0, TIOCGWINSZ, (char *) &ws) == 0) || - (ioctl(2, TIOCGWINSZ, (char *) &ws) == 0)) { - if (ws.ws_row > 0 && ws.ws_col > 0) { - *nrow = ws.ws_row; - *ncol = ws.ws_col; - trace_ilog("term_size1(%d, %d)\n", *nrow, *ncol); - return; - } - } - } while (errno == EINTR); - -#elif defined(TIOCGSIZE) - struct ttysize ts = {0}; /* SUN */ - - do { - if ((ioctl(1, TIOCGSIZE, (char *) &ts) == 0) || - (ioctl(0, TIOCGSIZE, (char *) &ts) == 0) || - (ioctl(2, TIOCGSIZE, (char *) &ts) == 0)) { - if (ts.ts_lines > 0 && ts.ts_linesncol > 0) { - *nrow = ts.ts_lines; - *ncol = ts.ts_cols; - trace_ilog("term_size2(%d, %d)\n", *nrow, *ncol); - return; - } - } - } while (errno == EINTR); -#endif - -#if defined(_VMS) - { /* UNTESTED/OLD */ - unsigned short chan; - - $DESCRIPTOR(dev_dsc, "SYS$INPUT:"); - if (sys$assign(&dev_dsc, &chan, 0, 0, 0) & 1) { - int status_col, status_row, code; - - code = DVI$_DEVBUFSIZ; - status_col = lib$getdvi(&code, &chan, 0, ncol, 0, 0); - code = DVI$_TT_PAGE; - status_row = lib$getdvi(&code, &chan, 0, nrow, 0, 0); - sys$dassgn(chan); - if ((status_col & 1) && (status_row & 1)) { - return; - } - } - } -#endif - - if (tn_li > 0 && tn_co > 0) { /* terminal */ - *nrow = tn_li; - *ncol = tn_co; - } else { - *nrow = 24; - *ncol = 80; - } - /* old school */ - if (NULL != (env = ggetenv("LINES")) && *env) { - *nrow = atoi(env); - tf_am = FALSE; - } - - if (NULL != (env = ggetenv("COLUMNS")) && *env) { - *ncol = atoi(env); - tf_am = FALSE; - } -} - - -#if (NOTUSED) -/* Function: term_sizeset - * Attempt to set the current window size. - * - * Parameters: - * row - Screen rows. - * col - Columns. - * - * Returns: - * On success 0, otherwise -1. - */ -static int -term_sizeset(int rows, int cols) -{ - if (x_pt.pt_winsetsize[0]) { - ttprintf(x_pt.pt_winsetsize, rows, cols); - return 0; - } - return -1; -} -#endif - - -/* Function: ega_switch - * EGA/VGA console mode switch support - * - * Parameters: - * flag - EGA mode. - * - * Returns: - * nothing. - */ -static void -ega_switch(int flag) -{ - const int orows = ttrows(); - - if (tty_egaflag == flag) { - return; - } - - switch (flag) { -#if defined(SW_VGA_C80x60) - case 60: /* 60 line mode */ - ioctl(1, SW_VGA_C80x60, 1); - ttrows() = 60; - break; -#endif - -#if defined(SW_VGA_C80x50) - case 50: /* 50 line mode */ - ioctl(1, SW_VGA_C80x50, 1); - ttrows() = 50; - break; -#endif - -#if defined(SW_ENH_C80x43) - case 43: /* 43 line mode */ - if (ioctl(1, SW_ENH_C80x43, 1) == 0) { - ttrows() = 43; - } - break; -#endif - -#if defined(SW_VGA_C80x25) || defined(SW_ENH_C80x25) - case 25: /* 25 line mode */ -#if defined(SW_VGA_C80x25) - ioctl(1, SW_VGA_C80x25, 1); -#endif -#if defined(SW_ENH_C80x25) - ioctl(1, SW_ENH_C80x25, 1); -#endif - ttrows() = 25; - break -#endif - - default: - acc_assign_int(-1); - return; - } - - tty_egaflag = xf_ega43 = flag; - vtwinch(ttcols(), orows); - term_colorreset(); -} - - -/* Function: do_ega - * ega primitive. - * - * Parameters: - * none. - * - * Returns: - * nothing. - * - *<> - Macro: ega - Terminal line display. - - int - ega(int lines) - - Macro Description: - The 'ega()' primitive attempts to configure the console size - to the specified number of 'lines' with an implied width of - 80 columns on supporting terminals. - - Possible screen dimensions include. - - o 60 x 80 - o 50 x 80 - o 43 x 80 - o 25 x 80 - - Macro Parameters: - lines - Optional integer specifing the required number of - console lines. Under WIN32 if -1 the console size shall toggled - bewteen minimized and maximised. If omitted, then only the - current state is returned. - - Notes!: - When running within a windows console, before Windows 7 one could press - to run the application in full screen. As of Windows 7 this - functionality is no longer available resulting in the following. - -> This system does not support full screen mode - - The ega() primitive can be used to emulate this functionality, using - the special -1 flag, which shall toggle between a minimized or maximised - sized console. - -> ega(-1) - - Macro Returns: - The 'ega()' primitive returns the previous status, otherwise -1 upon - an error. - - Macro Portability: - A Grief extension. - - Macro See Also: - set_term_feature - */ -void -do_ega(void) /* int (int mode) */ -{ - acc_assign_int((accint_t) xf_ega43); - if (isa_integer(1)) { /* (mode < 80 sets rows), otherwise (mode >= 80 sets columns). */ - const int flag = get_xinteger(1, 0); - if (flag >= 0) { - ega_switch(flag); - } - } -} - - -/* Function: do_copy_screen - * copy_screen primitive, defunct. - * - * Parameters: - * none. - * - * Returns: - * nothing. - * - *<> - Macro: copy_screen - Copy the current screen. - - void - copy_screen() - - Macro Description: - The 'copy_screen()' primitive exports an image of the - current editor windows to the current buffer. - - Macro Parameters: - none - - Macro Returns: - nothing - - Macro Portability: - A Grief extension; this primitive is subject for removal, - and has been removed from recent CrispEdit(tm) releases. - - Macro See Also: - transfer - */ -void -do_copy_screen(void) /* void () */ -{ -} - -#endif /*!USE_VIO_BUFFER && !DJGPP */ diff --git a/gr/ttyvio.c b/gr/ttyvio.c index 2b416ddd..011a5403 100644 --- a/gr/ttyvio.c +++ b/gr/ttyvio.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_ttyvio_c,"$Id: ttyvio.c,v 1.72 2021/07/05 15:01:27 cvsuser Exp $") +__CIDENT_RCSID(gr_ttyvio_c,"$Id: ttyvio.c,v 1.73 2022/05/26 16:41:38 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: ttyvio.c,v 1.72 2021/07/05 15:01:27 cvsuser Exp $ +/* $Id: ttyvio.c,v 1.73 2022/05/26 16:41:38 cvsuser Exp $ * TTY VIO implementation. * * @@ -25,18 +25,23 @@ __CIDENT_RCSID(gr_ttyvio_c,"$Id: ttyvio.c,v 1.72 2021/07/05 15:01:27 cvsuser Exp #include #include /* gputenvv(), ggetenv() */ #include + #include "../libchartable/libchartable.h" #include "../libwidechar/widechar.h" #if defined(WIN32) + #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0601 -#endif -#ifndef WINVER -#define WINVER 0x0601 +#define _WIN32_WINNT 0x601 +#elif (_WIN32_WINNT < 0x601) +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x601 #endif +#undef WINVER +#define WINVER _WIN32_WINNT + #if !defined(WINDOWS_MEAN_AND_LEAN) -#define WINDOWS_MEAN_AND_LEAN +#define WINDOWS_MEAN_AND_LEAN #include #endif #pragma comment(lib, "gdi32.lib") @@ -1257,12 +1262,10 @@ term_colvalue(const colvalue_t ca, unsigned def) static void term_attr(int fg, int bg) { - if (fg <= COLOR_NONE && - (fg = tt_colormap[fg].c16) < 0 || fg >= tt_colors) { + if ((fg <= COLOR_NONE && (fg = tt_colormap[fg].c16) < 0) || fg >= tt_colors) { fg = tt_defaultfg; } - if (fg <= COLOR_NONE && - (bg = tt_colormap[bg].c16) < 0 || bg >= tt_colors) { + if ((fg <= COLOR_NONE && (bg = tt_colormap[bg].c16) < 0) || bg >= tt_colors) { bg = tt_defaultbg; } term_hue(fg, bg); diff --git a/gr/ttywin32.c b/gr/ttywin32.c index 661369c6..bb05c395 100644 --- a/gr/ttywin32.c +++ b/gr/ttywin32.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_ttywin32_c,"$Id: ttywin32.c,v 1.52 2021/07/11 08:24:15 cvsuser Exp $") +__CIDENT_RCSID(gr_ttywin32_c,"$Id: ttywin32.c,v 1.53 2022/05/26 16:41:12 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: ttywin32.c,v 1.52 2021/07/11 08:24:15 cvsuser Exp $ +/* $Id: ttywin32.c,v 1.53 2022/05/26 16:41:12 cvsuser Exp $ * WIN32 VIO driver. * see: http://www.edm2.com/index.php/Category:Vio * @@ -21,9 +21,13 @@ __CIDENT_RCSID(gr_ttywin32_c,"$Id: ttywin32.c,v 1.52 2021/07/11 08:24:15 cvsuser #if defined(WIN32) #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0601 +#define _WIN32_WINNT 0x601 +#elif (_WIN32_WINNT < 0x601) +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x601 #endif -#define WINVER 0x0601 +#undef WINVER +#define WINVER _WIN32_WINNT #include @@ -33,7 +37,8 @@ __CIDENT_RCSID(gr_ttywin32_c,"$Id: ttywin32.c,v 1.52 2021/07/11 08:24:15 cvsuser #include #if !defined(WINDOWS_MEAN_AND_LEAN) -#define WINDOWS_MEAN_AND_LEAN +#define WINDOWS_MEAN_AND_LEAN +#define PSAPI_VERSION 1 // EnumProcessModules and psapi.dll #include #include #endif //WINDOWS_MEAN_AND_LEAN @@ -53,7 +58,6 @@ static void VioInitialise(void); static void VioEncoding(void); - /*private*/ // Function: VioInitialise // Runtime initialisation. diff --git a/gr/vio.h b/gr/vio.h index 697ec25d..f6d2e9ad 100644 --- a/gr/vio.h +++ b/gr/vio.h @@ -1,11 +1,11 @@ #ifndef GR_VIO_H_INCLUDED #define GR_VIO_H_INCLUDED #include -__CIDENT_RCSID(gr_vio_h,"$Id: vio.h,v 1.30 2020/06/18 12:48:04 cvsuser Exp $") +__CIDENT_RCSID(gr_vio_h,"$Id: vio.h,v 1.31 2022/05/26 16:40:27 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: vio.h,v 1.30 2020/06/18 12:48:04 cvsuser Exp $ +/* $Id: vio.h,v 1.31 2022/05/26 16:40:27 cvsuser Exp $ * Video I/O interface header. * * @@ -305,14 +305,22 @@ __CPRAGMA_ONCE typedef WCHAR_COLORINFO VIOHUE; typedef WCHAR_INFO VIOCELL; -__inline WCHAR_COLORINFO -VIO_FGBG(int fg, int bg) { +#if defined(__MINGW32__) +#define __VIO_INLINE static __inline +#else +#define __VIO_INLINE __inline +#endif + +__VIO_INLINE WCHAR_COLORINFO +VIO_FGBG(int fg, int bg) +{ WCHAR_COLORINFO info = {VIO_FNORMAL, 0, (short)fg, (short)bg, 0, 0}; return info; } -__inline WCHAR_INFO -VIO_INIT(const WCHAR_COLORINFO i, unsigned c) { +__VIO_INLINE WCHAR_INFO +VIO_INIT(const WCHAR_COLORINFO i, unsigned c) +{ WCHAR_INFO wchar = {0}; wchar.Info = i; wchar.Char.UnicodeChar = c; diff --git a/gr/word.h b/gr/word.h index 25797cf3..a0178fc6 100644 --- a/gr/word.h +++ b/gr/word.h @@ -1,11 +1,11 @@ #ifndef GR_WORD_H_INCLUDED #define GR_WORD_H_INCLUDED #include -__CIDENT_RCSID(gr_word_h,"$Id: word.h,v 1.19 2020/04/21 21:24:37 cvsuser Exp $") +__CIDENT_RCSID(gr_word_h,"$Id: word.h,v 1.20 2022/05/31 16:18:22 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: word.h,v 1.19 2020/04/21 21:24:37 cvsuser Exp $ +/* $Id: word.h,v 1.20 2022/05/31 16:18:22 cvsuser Exp $ * External data representation. * * @@ -22,15 +22,12 @@ __CPRAGMA_ONCE */ #include +#include __CBEGIN_DECLS struct CM; -#define CM_ATOMSIZE SIZEOF_LONG -#if (CM_ATOMSIZE != SIZEOF_VOID_P) -#error Unable to determine atom size. -#endif #define CM_ATOM_LIST_SZ (1+2) /* OP + LEN16 */ extern const unsigned sizeof_atoms[]; @@ -74,14 +71,14 @@ extern double LGET_FLOAT(const LIST *lp); #define LPUT_ID(lp, i) LPUT16((lp), (i)) #define LGET_ID(lp) LGET16(lp) -#if (SIZEOF_LONG == 8) +#if (CM_ATOMSIZE == 8) #define LPUT_INT(lp, n) LPUT64((lp), (int64_t)(n)) #define LGET_INT(lp) LGET64(lp) -#elif (SIZEOF_LONG == 4) +#elif (CM_ATOMSIZE == 4) #define LPUT_INT(lp, n) LPUT32((lp), (int32_t)(n)) #define LGET_INT(lp) LGET32(lp) #else -#error unsupported SIZEOF_LONG szie +#error unsupported CM_ATOMSIZE szie #endif #define LGET_PTR2(type, lp) ((type *)LGET_PTR(lp)) diff --git a/gr/wordimpl.h b/gr/wordimpl.h index 4b76b2c4..c7f004b0 100644 --- a/gr/wordimpl.h +++ b/gr/wordimpl.h @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_wordimpl_inc,"$Id: wordimpl.h,v 1.2 2020/04/21 21:24:37 cvsuser Exp $") +__CIDENT_RCSID(gr_wordimpl_inc,"$Id: wordimpl.h,v 1.3 2022/05/31 16:18:22 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: wordimpl.h,v 1.2 2020/04/21 21:24:37 cvsuser Exp $ +/* $Id: wordimpl.h,v 1.3 2022/05/31 16:18:22 cvsuser Exp $ * Portable mappings to and from internal word and byte order. * * @@ -32,9 +32,9 @@ __CIDENT_RCSID(gr_wordimpl_inc,"$Id: wordimpl.h,v 1.2 2020/04/21 21:24:37 cvsuse #if (SIZEOF_VOID_P != 4 && SIZEOF_VOID_P != 8) #error unsupported sizeof(void *) #endif -#if (SIZEOF_LONG != SIZEOF_VOID_P) -#error unsupported sizeof(long) -#endif + // #if (SIZEOF_LONG != SIZEOF_VOID_P) + // #error unsupported sizeof(long) + // #endif #if (SIZEOF_DOUBLE != 8) #error unsupported sizeof(double) #endif diff --git a/grcpp/.cvsignore b/grcpp/.cvsignore index 8c40b219..95e33762 100644 --- a/grcpp/.cvsignore +++ b/grcpp/.cvsignore @@ -1,2 +1,4 @@ +ucpp_license.h Makefile *.err + diff --git a/grcpp/LICENSE b/grcpp/LICENSE new file mode 100644 index 00000000..83de2c62 --- /dev/null +++ b/grcpp/LICENSE @@ -0,0 +1,28 @@ + + ucpp-1.3.2 - (c) Thomas Pornin 1999 - 2002 + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 4. The name of the authors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + --------------- diff --git a/grcpp/Makefile.in b/grcpp/Makefile.in index d287b63d..4185f079 100644 --- a/grcpp/Makefile.in +++ b/grcpp/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.11 2020/06/20 02:17:37 cvsuser Exp $ +# $Id: Makefile.in,v 1.13 2022/06/01 14:21:19 cvsuser Exp $ # GRIEF preprocessor makefile. # # -# Copyright (c) 1998 - 2020, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -32,30 +32,25 @@ top_builddir= @top_builddir@ # File extensions +C= .c E= O= .o -C= .c H= .h -Y= .y CLEAN= *.bak *~ *.BAK *.swp *.tmp core *.core a.out XCLEAN= # Compilers, programs -ifdef PURIFY -CC= purify @CC@ -else CC= @CC@ +CXX= @CXX@ +ifeq ("$(CXX)","") +CXX= $(CC) endif -HAVE_BISON= 1 -YACC= @YACC@ -GREP= @GREP@ RM= @RM@ +RC= @RC@ PERL= @PERL@ LIBTOOL= @LIBTOOL@ -LANG=C -export LANG #RH 8 has a LANG=en_US.UTF-8 # Configuration @@ -109,23 +104,34 @@ CFLAGS= @CFLAGS@ CWARN= @CWARN@ $(CWALL) CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ +CXXFLAGS= @CXXFLAGS@ +CXXDEBUG= @CXXDEBUG@ +ifeq ("$(CXXDEBUG)","") +CXXDEBUG= $(CDEBUG) +endif +CXXRELEASE= @CXXRELEASE@ +ifeq ("$(CXXRELEASE)","") +CXXRELEASE= $(CRELEASE) +endif LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I$(D_INC) @CINCLUDE@ -CEXTRA= @DEFS@ +CEXTRA= -DUCPP_CONFIG @DEFS@ ifeq ("$(BUILD_TYPE)","release") CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXRELEASE) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDRELEASE) @LDFLAGS@ else CFLAGS+= $(CDEBUG) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXDEBUG) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif -LDLIBS+= -L$(D_LIB) -lsplay -lllist -lmisc @LDLIBS@ @LIBS@ @LIBMALLOC@ @EXTRALIBS@ +LDLIBS= -L$(D_LIB) $(LINKLIBS) @LIBS@ @EXTRALIBS@ -YFLAGS= -d ARFLAGS= rcv +YFLAGS= -d RMFLAGS= -f RMDFLAGS= -rf @@ -135,32 +141,53 @@ RMDFLAGS= -rf TARGET= grcpp$(E) -OBJS= $(D_OBJ)/cpp$(O) \ - $(D_OBJ)/mem$(O) \ - $(D_OBJ)/nhash$(O) \ - $(D_OBJ)/lexer$(O) \ - $(D_OBJ)/assert$(O) \ - $(D_OBJ)/macro$(O) \ - $(D_OBJ)/eval$(O) \ - \ - $(D_OBJ)/cppmain$(O) +CSOURCES=\ + assert.c \ + cpp.c \ + eval.c \ + lexer.c \ + macro.c \ + mem.c \ + nhash.c \ + \ + cppmain.c + +RESOURCES=\ + grcpp.rc + +OBJS+= $(addprefix $(D_OBJ)/,$(subst .cpp,$(O),$(CPPSOURCES))) +OBJS+= $(addprefix $(D_OBJ)/,$(subst .c,$(O),$(CSOURCES))) + +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) +OBJS+= $(addprefix $(D_OBJ)/,$(subst .rc,_res.o,$(RESOURCES))) +else +OBJS+= $(addprefix $(D_OBJ)/,$(subst .rc,.res,$(RESOURCES))) +endif +endif #build_os -XFLAGS+= -DUCPP_CONFIG -DGRUNCH +XCLEAN= uccp_license.h ######################################################################################### # Rules -.PHONY: build release debug -build: $(D_BIN)/$(TARGET) +.PHONY: build resources release debug +build: resources $(D_BIN)/$(TARGET) release: $(MAKE) BUILD_TYPE=release $(filter-out release, $(MAKECMDGOALS)) debug: $(MAKE) BUILD_TYPE=debug $(filter-out debug, $(MAKECMDGOALS)) +resources: ucpp_license.h + +ucpp_license.h: LICENSE ../util/mklicense.pl + @$(PERL) ../util/mklicense.pl $< $@ ucpp_license + $(D_BIN)/$(TARGET): MAPFILE=$(basename $@).map -$(D_BIN)/$(TARGET): $(D_OBJ)/.created $(OBJS) +$(D_BIN)/$(TARGET): LINKLIBS=-lmisc +$(D_BIN)/$(TARGET): $(D_OBJ)/.created $(OBJS) $(RESOURCES) $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) @LDMAPFILE@ $(D_OBJ)/.created: @@ -173,4 +200,13 @@ clean: $(D_OBJ)/%$(O): %$(C) $(CC) $(CFLAGS) -o $@ -c $< +$(D_OBJ)/%$(O): %.cpp + $(CXX) $(CXXFLAGS) -o $@ -c $< + +$(D_OBJ)/%.res: %.rc + $(RC) -fo $@ $< + +$(D_OBJ)/%_res.o: %.rc + $(RC) -o $@ $< + #end diff --git a/grcpp/README b/grcpp/README index ee200d28..ef4fb74e 100644 --- a/grcpp/README +++ b/grcpp/README @@ -20,15 +20,6 @@ compliant to the ISO standard 9899:1999, also known as C99. ucpp can be compiled stand-alone program, or linked to some other code; in the latter case, ucpp will output tokens, one at a time, on demand, as an integrated lexer. -A C preprocessor is a part of a C compiler responsible for macro replacement, conditional -compilation and inclusion of header files. It is often found as a stand-alone program on -Unix systems. - -ucpp is such a preprocessor; it is designed to be quick and light, but anyway fully -compliant to the ISO standard 9899:1999, also known as C99. ucpp can be compiled as a -stand-alone program, or linked to some other code; in the latter case, ucpp will output -tokens, one at a time, on demand, as an integrated lexer. - ucpp operates in two modes: -- lexer mode: ucpp is linked to some other code and outputs a stream of tokens (each call to the lex() function will yield one token) -- non-lexer mode: ucpp preprocesses text and outputs the resulting text to a file descriptor; if linked to diff --git a/grcpp/config.h b/grcpp/config.h index b51b5c0a..c0c1a9e2 100644 --- a/grcpp/config.h +++ b/grcpp/config.h @@ -28,6 +28,12 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ + +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif /* ====================================================================== */ /* diff --git a/grcpp/cpp.c b/grcpp/cpp.c index d652401c..d6bea713 100644 --- a/grcpp/cpp.c +++ b/grcpp/cpp.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(libucpp_cpp_c,"$Id: cpp.c,v 1.3 2012/04/12 00:14:32 ayoung Exp $") +__CIDENT_RCSID(libucpp_cpp_c,"$Id: cpp.c,v 1.4 2022/05/31 16:18:22 cvsuser Exp $") /* -*- mode: c; indent-width: 8; -*- */ /* @@ -61,12 +61,13 @@ __CIDENT_RCSID(libucpp_cpp_c,"$Id: cpp.c,v 1.3 2012/04/12 00:14:32 ayoung Exp $" static char **include_path; static size_t include_path_nb = 0; -int no_special_macros = 0; -int emit_dependencies = 0, emit_defines = 0, emit_assertions = 0; -FILE * emit_output; +int no_special_macros = 0; +int emit_dependencies = 0, emit_defines = 0, emit_assertions = 0; +FILE *emit_output; -char * current_filename = 0, *current_long_filename = 0; -static int current_incdir = -1; + +char *current_filename = 0, *current_long_filename = 0; +static int current_incdir = -1; #ifndef NO_UCPP_ERROR_FUNCTIONS /* @@ -1289,7 +1290,8 @@ static int handle_include(struct lexer_state *ls, unsigned long flags, int nex) t.line = l; if (S_TOKEN(alt_ls.ctok->type)) { t.name = sdup(alt_ls.ctok->name); - throw_away(alt_ls.gf, t.name); } + throw_away(alt_ls.gf, t.name); + } aol(tf.t, tf.nt, t, TOKEN_LIST_MEMG); } } diff --git a/grcpp/cpp.h b/grcpp/cpp.h index bc20e7bb..4b206212 100644 --- a/grcpp/cpp.h +++ b/grcpp/cpp.h @@ -13,15 +13,15 @@ * products derived from this software without specific prior written * permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * diff --git a/grcpp/cppmain.c b/grcpp/cppmain.c index 17f50f5c..ab7b81ca 100644 --- a/grcpp/cppmain.c +++ b/grcpp/cppmain.c @@ -1,9 +1,9 @@ #include -__CIDENT_RCSID(cppmain_c,"$Id: cppmain.c,v 1.4 2014/11/04 17:07:20 ayoung Exp $") +__CIDENT_RCSID(cppmain_c,"$Id: cppmain.c,v 1.5 2022/05/31 16:18:22 cvsuser Exp $") /* -*- mode: c; indent-width: 8; -*- */ /* - * GRIEF grcpp 1.0.1, (c) A.Young 2010 - 2014 + * GRIEF grcpp 1.0.1, (c) A.Young 2010 - 2022 * * Original Code is the 'C and T preprocessor, and integrated lexer (ucpp 1.3)' * @@ -68,7 +68,7 @@ static char * system_assertions_def[] = { STD_ASSERT, 0 }; /* * print some help */ -static void +static void usage(char *command_name) { fprintf(stderr, @@ -116,63 +116,44 @@ usage(char *command_name) "\n" "misc options:\n" " -v print version number and settings\n" - " -notice display copyright/author informmation\n" + " -notice/--license display copyright/author informmation\n" " -h, --help show this help\n" "\n", command_name); } +#include "ucpp_license.h" + static void print_copyright(void) { static const char *copyright[] = { "\n", - " " GRCPP_LABEL " " GRCPP_VERSION ", (c) A Young 2010 - 2014\n" - " All Rights Reserved\n", - "\n", - " Original Code is the 'C and T preprocessor, and integrated lexer (ucpp 1.3)'\n", - "\n", - " The initial Developer of the Original Code is Thomas Pornin\n", - " Portions created by Thomas Pornin are Copyright (C) Thomas Pornin 1999 - 2002\n", - " under the Revised BSD license.\n", - "\n", - " Redistribution and use in source and binary forms, with or without\n", - " modification, are permitted provided that the following conditions\n", - " are met:\n", - " 1. Redistributions of source code must retain the above copyright\n", - " notice, this list of conditions and the following disclaimer.\n", - " 2. Redistributions in binary form must reproduce the above copyright\n", - " notice, this list of conditions and the following disclaimer in the\n", - " documentation and/or other materials provided with the distribution.\n", - " 4. The name of the authors may not be used to endorse or promote\n", - " products derived from this software without specific prior written\n", - " permission.\n", - "\n", - " THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR\n", - " IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n", - " WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n", - " ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE\n", - " LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n", - " CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\n", - " OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n", - " BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n", - " WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n", - " OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n", - " EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n", - "\n", + " " GRCPP_LABEL " " GRCPP_VERSION ", (c) A Young 2010 - 2022" + " All Rights Reserved", + "", + " Original Code is the 'C and T preprocessor, and integrated lexer (ucpp 1.3)'", + " Developed by Thomas Pornin under the Revised BSD license, see below.", + "", + " ---------------" + "", NULL }; unsigned i; for (i = 0; copyright[i]; ++i) { - fputs(copyright[i], stderr); + fprintf(stderr, "%s\n", copyright[i]); + } + for (i = 0; i < (sizeof(ucpp_license)/sizeof(ucpp_license[0])); ++i) { + fprintf(stderr, "%s\n", ucpp_license[i]); } + fprintf(stderr, "\n"); } /* * parse_opt() initializes many things according to the command-line options. - * + * * Return values: * 0 on success * 1 on semantic error (redefinition of a special macro, for instance) @@ -220,7 +201,7 @@ parse_opt(int argc, char *argv[], struct lexer_state *ls) ls->flags |= HANDLE_ASSERTIONS; ls->flags |= UTF8_SOURCE; system_macros = 1; - + } else if (!strcmp(argv[i], "-c90")) { ls->flags &= ~MACRO_VAARG; ls->flags &= ~CPLUSPLUS_COMMENTS; @@ -304,14 +285,14 @@ parse_opt(int argc, char *argv[], struct lexer_state *ls) } else if (!strcmp(argv[i], "-v")) { print_version = 1; - } else if (!strcmp(argv[i], "-notice")) { + } else if (!strcmp(argv[i], "-notice") || !strcmp(argv[i], "--license")) { print_version = 2; } else if (argv[i][1] != 'I' && argv[i][1] != 'J' && argv[i][1] != 'D' && argv[i][1] != 'U' && argv[i][1] != 'A' && argv[i][1] != 'B') { warning(-1, "unknown option '%s'", argv[i]); - } + } } else { if (filename != 0) { diff --git a/grcpp/grcpp.rc b/grcpp/grcpp.rc new file mode 100644 index 00000000..23571181 --- /dev/null +++ b/grcpp/grcpp.rc @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2020 - 2022 Adam Young. + * All rights reserved. + * + * This file is part of oncrpc4-win32. + * + * The applications are free software: you can redistribute it + * and/or modify it under the terms of the oncrpc4-win32 License. + * + * Redistributions of source code must retain the above copyright + * notice, and must be distributed with the license document above. + * + * Redistributions in binary form must reproduce the above copyright + * notice, and must include the license document above in + * the documentation and/or other materials provided with the + * distribution. + * + * This project 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 Licence for details. + * ==end== + */ + +#include +#include "../include/edbuildinfo.h" + +#ifdef GCC_WINDRES +VS_VERSION_INFO VERSIONINFO +#else +VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE +#endif + FILEVERSION GR_VERSION_1,GR_VERSION_2,GR_VERSION_3,GR_VERSION_4 + PRODUCTVERSION GR_VERSION_1,GR_VERSION_2,GR_VERSION_3,GR_VERSION_4 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS 1 +#else + FILEFLAGS 0 +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0 // not used +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + //language ID = U.S. English, char set = Windows, Multilingual + BEGIN + VALUE "FileDescription", "Grief grucpp utility, based on ucpp-1.3.2\0" + + VALUE "FileVersion", GR_VERSION "\0" + + VALUE "InternalName", "rpccpp.exe\0" + + VALUE "LegalCopyright", + "Copyright (c) 2022 Adam Young, \n" + "Copyright (c) Thomas Pornin 1999 - 2002, \n" + "See --license for details. \n\0" + + VALUE "OriginalFilename", + "grcpp.exe\0" + + VALUE "ProductName", + "grcpp (ucpp-1.3.2)\0" + + VALUE "ProductVersion", + GR_VERSION "\0" + + VALUE "Comments", + "https://github/adamyg/grief\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END diff --git a/grcpp/lexer.c b/grcpp/lexer.c index 33a25376..0cde344e 100644 --- a/grcpp/lexer.c +++ b/grcpp/lexer.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(libucpp_lexer_c,"$Id: lexer.c,v 1.2 2012/03/18 16:59:25 ayoung Exp $") +__CIDENT_RCSID(libucpp_lexer_c,"$Id: lexer.c,v 1.3 2022/05/31 16:18:22 cvsuser Exp $") /* -*- mode: c; indent-width: 8; -*- */ /* @@ -37,6 +37,7 @@ __CIDENT_RCSID(libucpp_lexer_c,"$Id: lexer.c,v 1.2 2012/03/18 16:59:25 ayoung Ex #include #include #include +#include #include "ucppi.h" #include "mem.h" #ifdef UCPP_MMAP @@ -688,7 +689,7 @@ static int utf8_to_string(unsigned char buf[], unsigned long utf8) val = x4 | (x3 << 6) | (x2 << 12) | (x1 << 16); } else val = utf8; if (val < 128) { - buf[0] = val; + buf[0] = (unsigned char)val; buf[1] = 0; return 1; } else if (val < 0xffffUL) { @@ -954,6 +955,8 @@ static inline int read_token(struct lexer_state *ls) put_char(ls, outc); outc = 0; } + //if (c != '\n' && !comment /*HOW*/?) + // TODO: stop dup newline .. put_char(ls, c); } } @@ -962,6 +965,10 @@ static inline int read_token(struct lexer_state *ls) /* this is a hack: we need to dump a pending slash */ put_char(ls, outc); outc = 0; + } else if (outc == '%' && !(ls->flags & LEXER) && ls->condcomp) { + /* XXX: flush pending % */ + put_char(ls, '%'); + outc = 0; } if (ttPUT(nstat)) { if (cstat == S_NAME_BS) { diff --git a/grcpp/mem.h b/grcpp/mem.h index 1e27f30f..bb8dca1e 100644 --- a/grcpp/mem.h +++ b/grcpp/mem.h @@ -41,7 +41,7 @@ #define report_leaks ucpp_report_leaks #define dup_debug ucpp_dup_debug -void die(void); +void die(void); #if defined AUDIT || defined MEM_CHECK || defined MEM_DEBUG void *getmem(size_t); @@ -50,33 +50,32 @@ void *getmem(size_t); #endif #if defined MEM_DEBUG -void * getmem_debug(size_t, char *, int); +void *getmem_debug(size_t, char *, int); #undef getmem #define getmem(x) getmem_debug(x, __FILE__, __LINE__) #endif #if defined AUDIT || defined MEM_DEBUG -void freemem(void *); +void freemem(void *); #else #define freemem free #endif #if defined MEM_DEBUG -void freemem_debug(void *, char *, int); +void freemem_debug(void *, char *, int); #undef freemem #define freemem(x) freemem_debug(x, __FILE__, __LINE__) #endif -void * incmem(void *, size_t, size_t); -char * sdup(char *); +void *incmem(void *, size_t, size_t); +char *sdup(char *); #if defined MEM_DEBUG void *incmem_debug(void *, size_t, size_t, char *, int); #undef incmem -#define incmem(x, y, z) \ - incmem_debug(x, y, z, __FILE__, __LINE__) -void report_leaks(void); -char *s sdup_debug(char *, char *, int); +#define incmem(x, y, z) incmem_debug(x, y, z, __FILE__, __LINE__) +void report_leaks(void); +char *sdup_debug(char *, char *, int); #define sdup(x) sdup_debug(x, __FILE__, __LINE__) #endif @@ -84,11 +83,11 @@ char *s sdup_debug(char *, char *, int); #define mmv ucpp_mmv #define mmvwo ucpp_mmvwo -void * mmv(void *, void *, size_t); -void * mmvwo(void *, void *, size_t); +void *mmv(void *, void *, size_t); +void *mmvwo(void *, void *, size_t); #else -#define mmv memcpy -#define mmvwo memmove +#define mmv memcpy +#define mmvwo memmove #endif /* diff --git a/grcpp/ucppi.h b/grcpp/ucppi.h index 4cd161e5..b56e69f5 100644 --- a/grcpp/ucppi.h +++ b/grcpp/ucppi.h @@ -65,19 +65,19 @@ struct comp_token_fifo { /* * from lexer.c */ -#define init_cppm ucpp_init_cppm -#define put_char ucpp_put_char -#define discard_char ucpp_discard_char -#define next_token ucpp_next_token -#define grap_char ucpp_grap_char -#define space_char ucpp_space_char - -void init_cppm(void); -void put_char(struct lexer_state *, unsigned char); -void discard_char(struct lexer_state *); -int next_token(struct lexer_state *); -int grap_char(struct lexer_state *); -int space_char(int); +#define init_cppm ucpp_init_cppm +#define put_char ucpp_put_char +#define discard_char ucpp_discard_char +#define next_token ucpp_next_token +#define grap_char ucpp_grap_char +#define space_char ucpp_space_char + +void init_cppm(void); +void put_char(struct lexer_state *, unsigned char); +void discard_char(struct lexer_state *); +int next_token(struct lexer_state *); +int grap_char(struct lexer_state *); +int space_char(int); /* * from assert.c @@ -94,11 +94,11 @@ struct assert { #define get_assertion ucpp_get_assertion #define wipe_assertions ucpp_wipe_assertions -int cmp_token_list(struct token_fifo *, struct token_fifo *); -int handle_assert(struct lexer_state *); -int handle_unassert(struct lexer_state *); -struct assert * get_assertion(char *); -void wipe_assertions(void); +int cmp_token_list(struct token_fifo *, struct token_fifo *); +int handle_assert(struct lexer_state *); +int handle_unassert(struct lexer_state *); +struct assert *get_assertion(char *); +void wipe_assertions(void); /* * from macro.c @@ -131,18 +131,18 @@ struct macro { #define tokenize_lexer ucpp_tokenize_lexer #endif -void print_token(struct lexer_state *, struct token *, long); -int handle_define(struct lexer_state *); -int handle_undef(struct lexer_state *); -int handle_ifdef(struct lexer_state *); -int handle_ifndef(struct lexer_state *); -int substitute_macro(struct lexer_state *, struct macro *, - struct token_fifo *, int, int, long); -struct macro * get_macro(char *); -void wipe_macros(void); +void print_token(struct lexer_state *, struct token *, long); +int handle_define(struct lexer_state *); +int handle_undef(struct lexer_state *); +int handle_ifdef(struct lexer_state *); +int handle_ifndef(struct lexer_state *); +int substitute_macro(struct lexer_state *, struct macro *, + struct token_fifo *, int, int, long); +struct macro *get_macro(char *); +void wipe_macros(void); extern struct lexer_state dsharp_lexer; -extern char compile_time[], compile_date[]; +extern char compile_time[], compile_date[]; #ifdef PRAGMA_TOKENIZE extern struct lexer_state tokenize_lexer; #endif @@ -154,9 +154,9 @@ extern struct lexer_state tokenize_lexer; #define eval_expr ucpp_eval_expr #define eval_line ucpp_eval_line -unsigned long strtoconst(char *); -unsigned long eval_expr(struct token_fifo *, int *, int); -extern long eval_line; +unsigned long strtoconst(char *); +unsigned long eval_expr(struct token_fifo *, int *, int); +extern long eval_line; #define eval_exception ucpp_eval_exception @@ -182,12 +182,12 @@ extern JMP_BUF eval_exception; #define compress_token_list ucpp_compress_token_list #endif -const char * token_name(struct token *); -void throw_away(struct garbage_fifo *, char *); -void garbage_collect(struct garbage_fifo *); -void init_buf_lexer_state(struct lexer_state *, int); +const char *token_name(struct token *); +void throw_away(struct garbage_fifo *, char *); +void garbage_collect(struct garbage_fifo *); +void init_buf_lexer_state(struct lexer_state *, int); #ifdef PRAGMA_TOKENIZE -struct comp_token_fifo compress_token_list(struct token_fifo *); +struct comp_token_fifo compress_token_list(struct token_fifo *); #endif #define ouch ucpp_ouch diff --git a/grmandoc/.gitignore b/grmandoc/.gitignore index 3ec04542..fddc8e4e 100644 --- a/grmandoc/.gitignore +++ b/grmandoc/.gitignore @@ -2,6 +2,5 @@ mdocml-1.12.*/ mdocml-1.13.*/ mandoc-1.14.*/ mdocversion.h -Makefile .unpacked* diff --git a/grmandoc/Changes b/grmandoc/Changes new file mode 100644 index 00000000..8c1b1ccd --- /dev/null +++ b/grmandoc/Changes @@ -0,0 +1,72 @@ +Thu Mar 24 12:06:16 2022 adamy + + * 1.14.6 port + + o Makefile, + + - version + - added, compat_mkstemps.c + - added, tag_term.c + + o config.h, + + - OSENUM=MANDOC_OS_OTHER (TODO) + + o main.c WIN32, + + - termios.h. + - winsize usage omitted. + - startdir omitted, fchdir() etc. + - run_pager, specialisation. + + o deman.c, + + - optind, removed extern definition. + + o cgi.c, + + - conditional ITIMER_VIRTUAL definition. + + o mansearch.c, + + - mergeman, missing returN NULL. + - mergeman_term, restructur case to if/else, const expr issues. + + o tag.c, + + - tag support disabled (TODO). + + o tag_term.c, + + - tag support disabled (TODO). + + o term_ps.c, + + - MAXCHAR, redefined as PSMAXCHAR + + o dbm.c, + + - #ifndef EFTYPE, use EBADF + + o dbm_map.c, + + - #ifndef EFTYPE, use EBADF + + o compat_fts.h, + + - fts_compare, __cdecl calling convention + + o compat_xxx.c, + + - #ifdef HAVE_XXX checks + + o compat_strcasestr.c, + + - optional __UNCONST definition + +/* + * Local Variables: *** + * mode: changelog *** + * End: *** + */ + diff --git a/grmandoc/Makefile.in b/grmandoc/Makefile.in index 162d8e9a..5d4adee4 100644 --- a/grmandoc/Makefile.in +++ b/grmandoc/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.27 2022/03/22 11:00:41 cvsuser Exp $ +# $Id: Makefile.in,v 1.31 2022/06/01 14:21:19 cvsuser Exp $ # libbsdmdoc and grmanddoc # # @@ -73,7 +73,12 @@ D_LIB= $(ROOT)/lib@TOOLCHAINEXT@/$(BUILD_TYPE) XFLAGS= CFLAGS= @CFLAGS@ -CWARN= @CWARN@ +ifeq ("gcc","@CC@") +CWARN= $(filter-out -Wshadow -Wmissing-prototypes -Wsign-compare, @CWARN@ $(CWALL)) +CWARN+= -Wno-sign-compare -Wno-unused-variable -Wno-implicit-fallthrough -Wno-implicit-function-declaration +else +CWARN= @CWARN@ $(CWALL) +endif CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ LDDEBUG= @LDDEBUG@ @@ -81,7 +86,7 @@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ CEXTRA= @DEFS@ -ifeq "win32" "@build_os@" +ifeq ("win32","@build_os@") CEXTRA+= -DWIN32 endif @@ -99,9 +104,6 @@ endif endif LDLIBS= -L$(D_LIB) -lbsdmdoc -lmisc @LIBZ@ @LIBREGEX@ @LDLIBS@ @LIBS@ @LIBM@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif LDLIBS+= @LIBMALLOC@ @LIBTHREAD@ YFLAGS= -d @@ -113,8 +115,8 @@ RMDFLAGS= -rf ######################################################################################### # Targets -VERSION= 1.14.5.gr -RELDATE= 10 March 2019 +VERSION= 1.14.6.gr +RELDATE= 23 Sept 2021 PACKED= mandoc-$(VERSION).tgz VPATH= ./mandoc-$(VERSION) ./sqlite3 @@ -127,6 +129,7 @@ COMPAT_OBJS=\ $(D_OBJ)/compat_getline$(O) \ $(D_OBJ)/compat_getsubopt$(O) \ $(D_OBJ)/compat_mkdtemp$(O) \ + $(D_OBJ)/compat_mkstemps$(O) \ $(D_OBJ)/compat_ohash$(O) \ $(D_OBJ)/compat_progname$(O) \ $(D_OBJ)/compat_reallocarray$(O) \ @@ -205,6 +208,7 @@ MANDOC_TERM_OBJS=\ $(D_OBJ)/term_ascii$(O) \ $(D_OBJ)/term_ps$(O) \ $(D_OBJ)/term_tab$(O) \ + $(D_OBJ)/term_tag$(O) \ $(D_OBJ)/tbl_term$(O) MANDOC_SEARCH_OBJS=\ @@ -242,6 +246,7 @@ CGI_OBJS=\ $(D_OBJ)/cgi$(O) \ $(D_OBJ)/mansearch$(O) \ $(D_OBJ)/out$(O) \ + $(D_OBJ)/tag$(O) \ $(MANDOC_DB_OBJS) CGI= $(D_BIN)/grman.cgi$(E) @@ -249,7 +254,8 @@ CGI= $(D_BIN)/grman.cgi$(E) #--------------------------------------------------- DEMANDOC_OBJS=\ - $(D_OBJ)/demandoc$(O) + $(D_OBJ)/demandoc$(O) \ + $(D_OBJ)/tag$(O) DEMANDOC= $(D_BIN)/grdemandoc$(E) diff --git a/grmandoc/Makefile.in.1.14.5 b/grmandoc/Makefile.in.1.14.5 new file mode 100644 index 00000000..d18375f3 --- /dev/null +++ b/grmandoc/Makefile.in.1.14.5 @@ -0,0 +1,362 @@ +# -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- +# $Id: Makefile.in.1.14.5,v 1.1 2022/03/24 05:46:20 cvsuser Exp $ +# libbsdmdoc and grmanddoc +# +# +# Copyright (c) 2014 - 2022, Adam Young. +# All rights reserved. +# +# This file is part of the GRIEF Editor. +# +# The GRIEF Editor is free software: you can redistribute it +# and/or modify it under the terms of the GRIEF Editor License. +# +# Redistributions of source code must retain the above copyright +# notice, and must be distributed with the license document above. +# +# Redistributions in binary form must reproduce the above copyright +# notice, and must include the license document above in +# the documentation and/or other materials provided with the +# distribution. +# +# The GRIEF Editor 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 +# License for more details. +# ==end== +# + +@SET_MAKE@ +ROOT= @abs_top_builddir@ +top_builddir= @top_builddir@ + +# File extensions + +E= +C= .c +O= .o +H= .h +A= .a +LP= lib + +CLEAN= *.bak *~ *.BAK *.swp *.tmp core *.core a.out +XCLEAN= + +# Compilers, programs + +CC= @CC@ +CXX= @CXX@ +AR= @AR@ +RANLIB= @RANLIB@ +LIBTOOL= @LIBTOOL@ +PERL= @PERL@ +RM= @RM@ + +# Configuration + +ifeq ("$(BUILD_TYPE)","") #default +BUILD_TYPE= debug +MAKEFLAGS+= BUILD_TYPE=debug +endif +ifneq ("$(BUILD_TYPE)","release") +RTSUFFIX=d +endif + +# Directories + +D_INC= $(ROOT)/include +D_BIN= $(ROOT)/bin@TOOLCHAINEXT@/$(BUILD_TYPE) +D_OBJ= $(ROOT)/objects@TOOLCHAINEXT@/$(BUILD_TYPE)/grmandoc +D_LIB= $(ROOT)/lib@TOOLCHAINEXT@/$(BUILD_TYPE) + +# Common flags + +XFLAGS= +CFLAGS= @CFLAGS@ +CWARN= @CWARN@ +CDEBUG= @CDEBUG@ +CRELEASE= @CRELEASE@ +LDDEBUG= @LDDEBUG@ +LDRELEASE= @LDRELEASE@ + +CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ +CEXTRA= @DEFS@ +ifeq "win32" "@build_os@" +CEXTRA+= -DWIN32 +endif + +ifeq ("$(BUILD_TYPE)","release") +CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) +LDFLAGS= $(LDRELEASE) @LDFLAGS@ +else +CFLAGS+= $(CDEBUG) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) +LDFLAGS= $(LDDEBUG) @LDFLAGS@ +endif +ifeq (gcc,$(findstring gcc,$(CC))) +ifeq ("linux","@build_os@") +LDFLAGS+= -rdynamic +endif +endif + +LDLIBS= -L$(D_LIB) -lbsdmdoc -lmisc @LIBZ@ @LIBREGEX@ @LDLIBS@ @LIBS@ @LIBM@ @EXTRALIBS@ +##ifeq ("mingw32","@build_os@") +##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 +##endif +LDLIBS+= @LIBMALLOC@ @LIBTHREAD@ + +YFLAGS= -d +ARFLAGS= rcv +RMFLAGS= -f +RMDFLAGS= -rf + + +######################################################################################### +# Targets + +VERSION= 1.14.5.gr +RELDATE= 10 March 2019 + +PACKED= mandoc-$(VERSION).tgz +VPATH= ./mandoc-$(VERSION) ./sqlite3 + + #--------------------------------------------------- + +COMPAT_OBJS=\ + $(D_OBJ)/compat_err$(O) \ + $(D_OBJ)/compat_fts$(O) \ + $(D_OBJ)/compat_getline$(O) \ + $(D_OBJ)/compat_getsubopt$(O) \ + $(D_OBJ)/compat_mkdtemp$(O) \ + $(D_OBJ)/compat_ohash$(O) \ + $(D_OBJ)/compat_progname$(O) \ + $(D_OBJ)/compat_reallocarray$(O) \ + $(D_OBJ)/compat_recallocarray$(O) \ + $(D_OBJ)/compat_strcasestr$(O) \ + $(D_OBJ)/compat_stringlist$(O) \ + $(D_OBJ)/compat_strlcat$(O) \ + $(D_OBJ)/compat_strlcpy$(O) \ + $(D_OBJ)/compat_strndup$(O) \ + $(D_OBJ)/compat_strsep$(O) \ + $(D_OBJ)/compat_strtonum$(O) \ + $(D_OBJ)/libsupport$(O) + +LIBMAN_OBJS=\ + $(D_OBJ)/man$(O) \ + $(D_OBJ)/man_macro$(O) \ + $(D_OBJ)/man_validate$(O) + +LIBMDOC_OBJS=\ + $(D_OBJ)/arch$(O) \ + $(D_OBJ)/att$(O) \ + $(D_OBJ)/lib$(O) \ + $(D_OBJ)/mdoc$(O) \ + $(D_OBJ)/mdoc_argv$(O) \ + $(D_OBJ)/mdoc_macro$(O) \ + $(D_OBJ)/mdoc_state$(O) \ + $(D_OBJ)/mdoc_validate$(O) \ + $(D_OBJ)/mdoc_markdown$(O) \ + $(D_OBJ)/st$(O) + +LIBROFF_OBJS=\ + $(D_OBJ)/eqn$(O) \ + $(D_OBJ)/roff$(O) \ + $(D_OBJ)/roff_term$(O) \ + $(D_OBJ)/roff_validate$(O) \ + $(D_OBJ)/tbl$(O) \ + $(D_OBJ)/tbl_data$(O) \ + $(D_OBJ)/tbl_layout$(O) \ + $(D_OBJ)/tbl_opts$(O) + +LIBMANDOC_OBJS=\ + $(LIBMAN_OBJS) \ + $(LIBMDOC_OBJS) \ + $(LIBROFF_OBJS) \ + $(COMPAT_OBJS) \ + $(D_OBJ)/chars$(O) \ + $(D_OBJ)/mandoc$(O) \ + $(D_OBJ)/mandoc_aux$(O) \ + $(D_OBJ)/mandoc_msg$(O) \ + $(D_OBJ)/mandoc_ohash$(O) \ + $(D_OBJ)/mandoc_xr$(O) \ + $(D_OBJ)/msec$(O) \ + $(D_OBJ)/read$(O) \ + $(D_OBJ)/preconv$(O) + +LIBMANDOC= $(D_LIB)/$(LP)bsdmdoc$(A) + + #--------------------------------------------------- + +MANDOC_HTML_OBJS=\ + $(D_OBJ)/eqn_html$(O) \ + $(D_OBJ)/html$(O) \ + $(D_OBJ)/man_html$(O) \ + $(D_OBJ)/mdoc_html$(O) \ + $(D_OBJ)/roff_html$(O) \ + $(D_OBJ)/tbl_html$(O) + +MANDOC_MAN_OBJS=\ + $(D_OBJ)/mdoc_man$(O) + +MANDOC_TERM_OBJS=\ + $(D_OBJ)/eqn_term$(O) \ + $(D_OBJ)/man_term$(O) \ + $(D_OBJ)/mdoc_term$(O) \ + $(D_OBJ)/term$(O) \ + $(D_OBJ)/term_ascii$(O) \ + $(D_OBJ)/term_ps$(O) \ + $(D_OBJ)/term_tab$(O) \ + $(D_OBJ)/tbl_term$(O) + +MANDOC_SEARCH_OBJS=\ + $(D_OBJ)/mandocdb$(O) \ + $(D_OBJ)/mansearch$(O) + +MANDOC_DB_OBJS=\ + $(D_OBJ)/sqlite3$(O) \ + $(D_OBJ)/dba$(O) \ + $(D_OBJ)/dba_read$(O) \ + $(D_OBJ)/dba_write$(O) \ + $(D_OBJ)/dba_array$(O) \ + $(D_OBJ)/dbm$(O) \ + $(D_OBJ)/dbm_map$(O) + +MANDOC_OBJS=\ + $(MANDOC_HTML_OBJS) \ + $(MANDOC_MAN_OBJS) \ + $(MANDOC_TERM_OBJS) \ + $(D_OBJ)/main$(O) \ + $(D_OBJ)/manpath$(O) \ + $(D_OBJ)/out$(O) \ + $(D_OBJ)/tag$(O) \ + $(D_OBJ)/tree$(O) \ + $(D_OBJ)/mandocdb$(O) \ + $(D_OBJ)/mansearch$(O) \ + $(MANDOC_DB_OBJS) + +MANDOC= $(D_BIN)/grmandoc$(E) + + #--------------------------------------------------- + +CGI_OBJS=\ + $(MANDOC_HTML_OBJS) \ + $(D_OBJ)/cgi$(O) \ + $(D_OBJ)/mansearch$(O) \ + $(D_OBJ)/out$(O) \ + $(MANDOC_DB_OBJS) + +CGI= $(D_BIN)/grman.cgi$(E) + + #--------------------------------------------------- + +DEMANDOC_OBJS=\ + $(D_OBJ)/demandoc$(O) + +DEMANDOC= $(D_BIN)/grdemandoc$(E) + + #--------------------------------------------------- + +SOELIM_OBJS=\ + $(D_OBJ)/soelim$(O) \ + $(D_OBJ)/compat_err$(O) \ + $(D_OBJ)/compat_getline$(O) \ + $(D_OBJ)/compat_progname$(O) \ + $(D_OBJ)/compat_reallocarray$(O) \ + $(D_OBJ)/compat_stringlist$(O) \ + $(D_OBJ)/sqlite3$(O) + +SOELIM= $(D_BIN)/grsoelim$(E) + + #--------------------------------------------------- + +OBJS=\ + $(LIBMANDOC_OBJS) \ + $(MANDOC_OBJS) \ + $(DEMANDOC_OBJS) \ + $(SOELIM_OBJS) + +LIBRARIES= $(LIBMANDOC) + +CLEANFILES= mdocversion.h + + +######################################################################################### +# Rules + +ifeq ("cygwin","@build_os@") +LDLIBS:= $(filter-out -liberty, $(LDLIBS)) +endif + +.PHONY: build release debug +build: source unpacked +unpacked: mdocversion.h $(LIBRARIES) $(MANDOC) $(CGI) $(DEMANDOC) $(SOELIM) + +release: + $(MAKE) BUILD_TYPE=release $(filter-out release, $(MAKECMDGOALS)) +debug: + $(MAKE) BUILD_TYPE=debug $(filter-out debug, $(MAKECMDGOALS)) + +regress-exec: .unpacked.$(VERSION).regress + cd ./mandoc-$(VERSION)/regress && $(PERL) ./regress.pl --path=$(D_BIN)/grmandoc . + +.unpacked.$(VERSION).regress: ./mandoc-$(VERSION)/regress/regress.tgz + @echo "do not delete, managed file" > $@ + cd ./mandoc-$(VERSION)/regress && gzip -c -d regress.tgz | tar -xvf - + +regress-clean: + cd ./mandoc-$(VERSION)/regress && $(PERL) ./regress.pl . clean + +$(MANDOC): MAPFILE=$(basename $@).map +$(MANDOC): $(MANDOC_OBJS) + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(MANDOC_OBJS) $(LDLIBS) @LDMAPFILE@ + +$(CGI): MAPFILE=$(basename $@).map +$(CGI): $(CGI_OBJS) + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(CGI_OBJS) $(LDLIBS) @LDMAPFILE@ + +$(DEMANDOC): MAPFILE=$(basename $@).map +$(DEMANDOC): $(DEMANDOC_OBJS) + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(DEMANDOC_OBJS) $(LDLIBS) @LDMAPFILE@ + +$(SOELIM): MAPFILE=$(basename $@).map +$(SOELIM): $(SOELIM_OBJS) + $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(SOELIM_OBJS) $(LDLIBS) @LDMAPFILE@ + +$(LIBMANDOC): $(D_OBJ)/.created $(LIBMANDOC_OBJS) + $(RM) $(RMFLAGS) $@ + $(AR) $(ARFLAGS) $@ $(LIBMANDOC_OBJS) + $(RANLIB) $@ + +mdocversion.h: Makefile + @$(PERL) ./mdocversion.pl -o $@ -v "$(VERSION)" -r "$(RELDATE)" + +source: .unpacked.$(VERSION) + $(MAKE) unpacked + +ifeq ($(PACKED),) +.unpacked.$(VERSION): +else +.unpacked.$(VERSION): $(PACKED) + @echo "do not delete, managed file" > $@ + @echo "unpacking source $(PACKED)" + @gzip -c -d $(PACKED) | tar -xvf - +endif + +CLEAN += + +$(D_OBJ)/.created: + -@mkdir $(D_OBJ) + @echo "do not create" > $@ + +clean: + @echo $(BUILD_TYPE) clean + -@$(RM) $(RMFLAGS) $(BAK) $(LIBRARIES) $(CLEAN) $(XCLEAN) >/dev/null 2>&1 + -@$(RM) $(RMFLAGS) $(LIBOBJS) $(OBJS) $(CLEANFILES) >/dev/null 2>&1 + +$(D_OBJ)/sqlite3$(O): CFLAGS := $(filter-out -gw -hw,$(CFLAGS)) + # open-watcom debug breaks due to the module size + +$(D_OBJ)/%$(O): %$(C) + $(CC) $(CFLAGS) -o $@ -I ./sqlite3 -DHAVE_SQLITE3 -c $< + +#end + diff --git a/grmandoc/README.txt b/grmandoc/README.txt index fcea327e..f1e6b054 100644 --- a/grmandoc/README.txt +++ b/grmandoc/README.txt @@ -3,7 +3,8 @@ The mandoc UNIX manpage compiler toolset (http://mdocml.bsd.lv/) - Current version 1.14.5 (March 10, 2019) using sqlite3 (version 3.25.2) + Current version 1.14.6 (23 Sept 2021) using sqlite3 (version 3.25.2) + Version 1.14.5 (March 10, 2019) using sqlite3 (version 3.25.2) Version 1.14.4 (August 8, 2018) using sqlite3 (version 3.25.2) Version 1.13.4 (July 10, 2016) using sqlite3 (version 3.16.2) Version 1.12.3 (December 31, 2013) @@ -31,14 +32,15 @@ mandoc toolkit is protected by the Copyright of the following developers: Copyright (c) 2008-2012, 2014 Kristaps Dzonsons - Copyright (c) 2010-2018 Ingo Schwarze + Copyright (c) 2010-2021 Ingo Schwarze Copyright (c) 1999, 2004, 2017 Marc Espie Copyright (c) 2009, 2010, 2011, 2012 Joerg Sonnenberger Copyright (c) 2013 Franco Fichtner Copyright (c) 2014 Baptiste Daroussin Copyright (c) 2016 Ed Maste Copyright (c) 2017 Michael Stapelberg - Copyright (c) 1998, 2004, 2010 Todd C. Miller + Copyright (c) 2017 Anthony Bentley + Copyright (c) 1998, 2004, 2010, 2015 Todd C. Miller Copyright (c) 2008, 2017 Otto Moerbeek Copyright (c) 2004 Ted Unangst Copyright (c) 1994 Christos Zoulas @@ -63,7 +65,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - The following files included from outside sources are protected by other people's Copyright and are distributed under various 2-clause and 3-clause BSD licenses; see these individual files for details. diff --git a/grmandoc/config.h b/grmandoc/config.h index 4fb118eb..6d4d04c2 100644 --- a/grmandoc/config.h +++ b/grmandoc/config.h @@ -1,10 +1,10 @@ #ifndef MANDOC_CONFIG_H_INCLUDED #define MANDOC_CONFIG_H_INCLUDED /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: config.h,v 1.19 2020/06/18 12:50:24 cvsuser Exp $ +/* $Id: config.h,v 1.23 2022/05/31 16:44:23 cvsuser Exp $ * mandoc config.h * - * Copyright (c) 2014 - 2020, Adam Young. + * Copyright (c) 2014 - 2022, Adam Young. * All rights reserved. * * Permission to use, copy, modify, and distribute this software for any @@ -25,7 +25,7 @@ /* */ -#if (defined(_WIN32) || defined(WIN32)) && !defined(__MINGW32__) +#if defined(_WIN32) || defined(WIN32) #include "../libw32/config.h" @@ -60,7 +60,11 @@ #ifndef lstat #define lstat w32_lstat #endif -#define inline _inline + +#if !defined(__MINGW32__) +#define inline _inline +#endif + #include "../libw32/win32_child.h" #else /*!WIN32*/ @@ -69,6 +73,8 @@ /*FIXME: edbuildinfo.h*/ #define OSNAME "GRIEF Edit 3.2" +#define OSENUM MANDOC_OS_OTHER +#define BINM_PAGER "less" #include "mdocversion.h" /*VERSION and binary names*/ @@ -213,4 +219,3 @@ extern int isblank(int ch); #endif /*MANDOC_CONFIG_H_INCLUDED*/ /*end*/ - diff --git a/grmandoc/mandoc-1.14.6.gr.tgz b/grmandoc/mandoc-1.14.6.gr.tgz new file mode 100644 index 00000000..39a89ef1 Binary files /dev/null and b/grmandoc/mandoc-1.14.6.gr.tgz differ diff --git a/grunch/Makefile.in b/grunch/Makefile.in index 0d4a71ee..b85ada1d 100644 --- a/grunch/Makefile.in +++ b/grunch/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.28 2021/04/03 18:06:33 cvsuser Exp $ +# $Id: Makefile.in,v 1.29 2022/05/27 03:13:12 cvsuser Exp $ # GRIEF macro compiler. # # -# Copyright (c) 1998 - 2020, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -108,7 +108,12 @@ endif XFLAGS= CFLAGS= @CFLAGS@ +ifeq ("gcc","@CC@") +CWARN= $(filter-out -Wshadow -Wmissing-prototypes -Wsign-compare -Wimplicit-fallthrough, @CWARN@ $(CWALL)) +CWARN+= -Wno-sign-compare -Wno-implicit-fallthrough +else CWARN= @CWARN@ $(CWALL) +endif CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ LDDEBUG= @LDDEBUG@ diff --git a/grunch/crbin.c b/grunch/crbin.c index 61d7165c..c8b78815 100644 --- a/grunch/crbin.c +++ b/grunch/crbin.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_crbin_c,"$Id: crbin.c,v 1.24 2021/04/05 09:09:48 cvsuser Exp $") +__CIDENT_RCSID(gr_crbin_c,"$Id: crbin.c,v 1.25 2022/05/31 16:18:22 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: crbin.c,v 1.24 2021/04/05 09:09:48 cvsuser Exp $ +/* $Id: crbin.c,v 1.25 2022/05/31 16:18:22 cvsuser Exp $ * Binary backend code generator. * * @@ -447,7 +447,8 @@ push_int(accint_t ival) LIST t_buf[sizeof(accint_t)+1]; unsigned i; - assert(SIZEOF_LONG == sizeof(accint_t)); /* verify env */ +// assert(SIZEOF_LONG == sizeof(accint_t)); /* verify env */ + assert(CM_ATOMSIZE == sizeof(accint_t)); /* verify env */ LPUT_INT(t_buf, ival); for (i = 1; i < sizeof(t_buf); ++i) { push_byte(t_buf[i]); diff --git a/grunch/crdebug.c b/grunch/crdebug.c index 9c4e3db3..6efa5b89 100644 --- a/grunch/crdebug.c +++ b/grunch/crdebug.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_crdebug_c,"$Id: crdebug.c,v 1.16 2020/04/23 12:35:50 cvsuser Exp $") +__CIDENT_RCSID(gr_crdebug_c,"$Id: crdebug.c,v 1.17 2022/05/31 16:18:22 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: crdebug.c,v 1.16 2020/04/23 12:35:50 cvsuser Exp $ +/* $Id: crdebug.c,v 1.17 2022/05/31 16:18:22 cvsuser Exp $ * Debug/diagnostics support. * * @@ -237,7 +237,7 @@ ntp(const node_t *np, int size, FILE *out, int depth) switch (np->type) { case node_integer: if (! xf_struct) { - fprintf(out, " %ld", np->atom.ival); + fprintf(out, " %" ACCINT_FMT, np->atom.ival); } return size; @@ -316,7 +316,7 @@ ntp(const node_t *np, int size, FILE *out, int depth) } } else if (np->right->type == node_integer) { if (! xf_struct) { - fprintf(out, "[%ld]", np->right->atom.ival); + fprintf(out, "[%" ACCINT_FMT "]", np->right->atom.ival); } return size * np->right->atom.ival; } diff --git a/grunch/crgen.c b/grunch/crgen.c index e8b3e4eb..e7cb0789 100644 --- a/grunch/crgen.c +++ b/grunch/crgen.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_crgen_c,"$Id: crgen.c,v 1.37 2020/04/23 12:35:50 cvsuser Exp $") +__CIDENT_RCSID(gr_crgen_c,"$Id: crgen.c,v 1.38 2022/05/27 03:13:33 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: crgen.c,v 1.37 2020/04/23 12:35:50 cvsuser Exp $ +/* $Id: crgen.c,v 1.38 2022/05/27 03:13:33 cvsuser Exp $ * generic code generator routines. * * @@ -264,7 +264,7 @@ compile_func(symtype_t type, const char *function, Head_p arglist, node_t *stmts if (0 == strcmp(function, "_init")) { do_end = ((has_args = globals_compile(has_stmts)) && has_stmts); } else { - do_end = ((has_args = compile_arglist(arglist, has_stmts)) && has_stmts); + do_end = ((has_args = compile_arglist(function, arglist, has_stmts)) && has_stmts); } /* @@ -576,7 +576,7 @@ globals_cleanup(void) * actual argument can be accessed by calling the get_parm() primitive. */ int -compile_arglist(Head_p arglist, int flag) +compile_arglist(const char *function, Head_p arglist, int flag) { /* 17/08/08 */ register List_p lp; register node_t *np; @@ -591,6 +591,10 @@ compile_arglist(Head_p arglist, int flag) np = (node_t *) ll_elem(lp); if (NULL == np) { + if (dots_seen) { + crwarnx(RC_VARARG_MULTIPLE, /* 27/05/22 */ + "multiple '...' operators for function '%s'", function); + } dots_seen = TRUE; /* ... */ } else { diff --git a/grunch/crmain.c b/grunch/crmain.c index 143330ca..3c4ddb0e 100644 --- a/grunch/crmain.c +++ b/grunch/crmain.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_crmain_c,"$Id: crmain.c,v 1.56 2020/06/20 02:18:22 cvsuser Exp $") +__CIDENT_RCSID(gr_crmain_c,"$Id: crmain.c,v 1.57 2022/05/31 16:18:22 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: crmain.c,v 1.56 2020/06/20 02:18:22 cvsuser Exp $ +/* $Id: crmain.c,v 1.57 2022/05/31 16:18:22 cvsuser Exp $ * grunch command line. * * @@ -1099,7 +1099,7 @@ resolve_self(const char *name) (void)name; /* optional usage */ - len = GetModuleFileName(NULL, gr_path, sizeof(gr_path)); + len = GetModuleFileNameA(NULL, gr_path, sizeof(gr_path)); if (len && len < sizeof(gr_path)) { gr_path[len] = 0; if (-1 != stat(gr_path, &sb)) { /* env */ diff --git a/grunch/crmsg.h b/grunch/crmsg.h index db896218..d9abeb62 100644 --- a/grunch/crmsg.h +++ b/grunch/crmsg.h @@ -1,11 +1,11 @@ #ifndef GR_CRMSG_H_INCLUDED #define GR_CRMSG_H_INCLUDED #include -__CIDENT_RCSID(gr_crmsg_h,"$Id: crmsg.h,v 1.8 2014/10/22 02:33:28 ayoung Exp $") +__CIDENT_RCSID(gr_crmsg_h,"$Id: crmsg.h,v 1.9 2022/05/27 03:13:33 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: crmsg.h,v 1.8 2014/10/22 02:33:28 ayoung Exp $ +/* $Id: crmsg.h,v 1.9 2022/05/27 03:13:33 cvsuser Exp $ * Compiler messages. * * @@ -67,6 +67,8 @@ enum { RC_REPLACING_BUILTIN, // "implicit replacement of the builtin function '' RC_REPLACING_MACRO, // "replacing non-builtin macro " + + RC_VARARG_MULTIPLE, // "multiple '...' operators for function " RC_UNSUPPORTED_POINTER, RC_UNSUPPORTED_REFGLOBOL, diff --git a/grunch/crsubs.c b/grunch/crsubs.c index 85ba1623..40441ee0 100644 --- a/grunch/crsubs.c +++ b/grunch/crsubs.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_crsubs_c,"$Id: crsubs.c,v 1.29 2021/08/14 17:09:30 cvsuser Exp $") +__CIDENT_RCSID(gr_crsubs_c,"$Id: crsubs.c,v 1.30 2022/05/31 16:18:22 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: crsubs.c,v 1.29 2021/08/14 17:09:30 cvsuser Exp $ +/* $Id: crsubs.c,v 1.30 2022/05/31 16:18:22 cvsuser Exp $ * Parser ultities. * * @@ -1148,7 +1148,7 @@ enum_ivalue(accint_t ivalue) x_enum_type = ENUM_INTEGER; x_enum_value = ivalue + 1; } - xprintf("enum ivalue(%ld) : %s\n", ivalue, (ret ? "TRUE" : "FALSE")); + xprintf("enum ivalue(%" ACCINT_FMT ") : %s\n", ivalue, (ret ? "TRUE" : "FALSE")); return ret; } @@ -1179,7 +1179,7 @@ enum_implicited(accint_t *ivalue) x_enum_type = ENUM_INTEGER; *ivalue = x_enum_value++; } - xprintf("enum implicited(%ld) : %s\n", *ivalue, (ret ? "TRUE" : "FALSE")); + xprintf("enum implicited(%" ACCINT_FMT ") : %s\n", *ivalue, (ret ? "TRUE" : "FALSE")); return ret; } @@ -1195,7 +1195,7 @@ enum_add(node_t *np) assert(right && (node_integer == right->type || node_string == right->type)); if (node_integer == right->type) { - xprintf("enum name(%s) = %ld\n", name, right->atom.ival); + xprintf("enum name(%s) = %" ACCINT_FMT "\n", name, right->atom.ival); } else { xprintf("enum name(%s) = %s\n", name, right->atom.sval); diff --git a/grunch/grunch.h b/grunch/grunch.h index beb58161..5d68ee6a 100644 --- a/grunch/grunch.h +++ b/grunch/grunch.h @@ -1,11 +1,11 @@ #ifndef GR_GRUNCH_H_INCLUDED #define GR_GRUNCH_H_INCLUDED #include -__CIDENT_RCSID(gr_grunch_h,"$Id: grunch.h,v 1.35 2020/06/03 17:18:19 cvsuser Exp $") +__CIDENT_RCSID(gr_grunch_h,"$Id: grunch.h,v 1.36 2022/05/27 03:13:33 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: grunch.h,v 1.35 2020/06/03 17:18:19 cvsuser Exp $ +/* $Id: grunch.h,v 1.36 2022/05/27 03:13:33 cvsuser Exp $ * grunch language compiler, structures etc * * @@ -520,7 +520,7 @@ extern void list_free(Head_p *hd); extern const char * yymap(int); -extern int compile_arglist(Head_p, int flag); +extern int compile_arglist(const char *function, Head_p, int flag); extern void compile_func(symtype_t type, const char *function, Head_p arglist, node_t *np); extern void compile_list(Head_p, int level, int flag, int sepstmt); extern void compile_main(node_t *np); diff --git a/grunch/symtab.c b/grunch/symtab.c index 5e821c90..2384142b 100644 --- a/grunch/symtab.c +++ b/grunch/symtab.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_symtab_c,"$Id: symtab.c,v 1.30 2020/04/23 12:35:50 cvsuser Exp $") +__CIDENT_RCSID(gr_symtab_c,"$Id: symtab.c,v 1.31 2022/05/27 03:13:33 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: symtab.c,v 1.30 2020/04/23 12:35:50 cvsuser Exp $ +/* $Id: symtab.c,v 1.31 2022/05/27 03:13:33 cvsuser Exp $ * Symbol table. * * @@ -574,13 +574,13 @@ sym_push(Head_p *hd, int order, const char *name, node_t *np, symtype_t type, sy for (lp = ll_first(*hd); lp; lp = ll_next(lp)) { unsigned symerr = 0; - symtype_t t_ty, t_sc, t_istag; + symtype_t /*t_sc, t_ty,*/ t_istag; sp = (symbol_t *) ll_elem(lp); D_SYMBOL_MAGIC(assert(sp->magic == SYMBOL_MAGIC);) - t_sc = (sp->s_type & SC_MASK) >> SC_SHIFT; - t_ty = sp->s_type & TY_MASK; + // t_sc = (sp->s_type & SC_MASK) >> SC_SHIFT; + // t_ty = sp->s_type & TY_MASK; t_istag = symtype_istag(sp->s_type); if (sp->s_level > 1) { /* non-parameter */ diff --git a/include/config.hin b/include/config.hin index 5d972ca7..8741d719 100644 --- a/include/config.hin +++ b/include/config.hin @@ -1,11 +1,11 @@ #ifndef CR_CONFIG_H_INCLUDED #define CR_CONFIG_H_INCLUDED #include -__CIDENT_RCSID(config_h, "$Id: config.hin,v 1.57 2021/08/02 16:10:31 cvsuser Exp $") +__CIDENT_RCSID(config_h, "$Id: config.hin,v 1.58 2022/06/16 10:18:58 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; set-indent: 4; -*- */ -/* $Id: config.hin,v 1.57 2021/08/02 16:10:31 cvsuser Exp $ +/* $Id: config.hin,v 1.58 2022/06/16 10:18:58 cvsuser Exp $ * Machine configuration. * * @@ -256,7 +256,7 @@ __CPRAGMA_ONCE #undef SIZEOF_FLOAT #undef SIZEOF_DOUBLE 8 #undef SIZEOF_LONG 4 -#undef SIZEOF_LONG_LONG 4 +#undef SIZEOF_LONG_LONG 8 #undef SIZEOF_VOID_P 4 #define SIZEOF_VOIDP SIZEOF_VOID_P #undef SIZEOF_WCHAR_T diff --git a/include/edatom.h b/include/edatom.h new file mode 100644 index 00000000..c4d4930f --- /dev/null +++ b/include/edatom.h @@ -0,0 +1,49 @@ +#ifndef GR_EDATOM_H_INCLUDED +#define GR_EDATOM_H_INCLUDED +#include +__CIDENT_RCSID(edatom_h,"$Id: edatom.h,v 1.1 2022/05/31 16:18:22 cvsuser Exp $") +__CPRAGMA_ONCE + +/* -*- mode: c; indent-width: 4; -*- */ +/* $Id: edatom.h,v 1.1 2022/05/31 16:18:22 cvsuser Exp $ + * Atom representation. + * + * + * This file is part of the GRIEF Editor. + * + * The GRIEF Editor is free software: you can redistribute it + * and/or modify it under the terms of the GRIEF Editor License. + * + * The GRIEF Editor 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 + * License for more details. + * ==end== + */ + +#if !defined(HAVE_CONFIG_H) +#error HAVE_CONFIG_H expected to be defined ... +#endif +#include + +#if (SIZEOF_LONG == SIZEOF_VOID_P) +#define CM_ATOMSIZE SIZEOF_LONG +typedef long accint_t; +typedef long unsigned accuint_t; + +#elif (SIZEOF_LONG_LONG == SIZEOF_VOID_P) +#define CM_ATOMSIZE SIZEOF_LONG_LONG +typedef long long accint_t; +typedef long long unsigned accuint_t; + +#else +#error unable to determine atom size. +#endif + +typedef double accfloat_t; + +#endif /*GR_EDATOM_H_INCLUDED*/ + + + + diff --git a/include/edthreads.h b/include/edthreads.h index ff1349ea..0709ad14 100644 --- a/include/edthreads.h +++ b/include/edthreads.h @@ -1,11 +1,11 @@ #ifndef GR_EDTHREADS_H_INCLUDED #define GR_EDTHREADS_H_INCLUDED #include -__CIDENT_RCSID(gr_edthreads_h,"$Id: edthreads.h,v 1.17 2022/03/21 14:55:27 cvsuser Exp $") +__CIDENT_RCSID(gr_edthreads_h,"$Id: edthreads.h,v 1.19 2022/06/13 12:47:14 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: edthreads.h,v 1.17 2022/03/21 14:55:27 cvsuser Exp $ +/* $Id: edthreads.h,v 1.19 2022/06/13 12:47:14 cvsuser Exp $ * Threads interface * ISO/IEC 9899:201x Committee Draft * April 12, 2011 N1570 @@ -39,8 +39,8 @@ __CPRAGMA_ONCE #include #endif -#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(HAVE_PTHREAD_H) -#define __STDC_NO_THREADS__ /*PTHREADS*/ +#if defined(__MINGW32__) || (defined(__CYGWIN__) && defined(HAVE_PTHREAD_H)) +#define __STDC_NO_THREADS__ /*PTHREADS or WIN32*/ #endif #include @@ -114,11 +114,6 @@ extern void tss_delete(tss_t key); extern void * tss_get(tss_t key); extern int tss_set(tss_t key, void *val); -#if defined(__MINGW32__) -extern int usleep(/*usecond_t*/ const unsigned useconds); -extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp /*notused*/); -#endif - __CEND_DECLS #endif /*NON-NATIVE*/ diff --git a/include/edthreads_win32.h b/include/edthreads_win32.h index c26e269d..b0d3cb40 100644 --- a/include/edthreads_win32.h +++ b/include/edthreads_win32.h @@ -1,11 +1,11 @@ #ifndef GR_EDTHREADS_WIN32_H_INCLUDED #define GR_EDTHREADS_WIN32_H_INCLUDED #include -__CIDENT_RCSID(gr_edthreads_win32_h,"$Id: edthreads_win32.h,v 1.17 2022/03/21 14:55:28 cvsuser Exp $") +__CIDENT_RCSID(gr_edthreads_win32_h,"$Id: edthreads_win32.h,v 1.18 2022/05/26 16:02:26 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: edthreads_win32.h,v 1.17 2022/03/21 14:55:28 cvsuser Exp $ +/* $Id: edthreads_win32.h,v 1.18 2022/05/26 16:02:26 cvsuser Exp $ * Threads interface * ISO/IEC 9899:201x Committee Draft * April 12, 2011 N1570 @@ -120,11 +120,10 @@ __CPRAGMA_ONCE #include //Mutex and conditional time specificiation - //TODO: #include #if !defined(HAVE_TIMESPEC) #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || \ (defined(__WATCOMC__) && (__WATCOMC__ < 1300)) || \ - (!defined(__WATCOMC__) && !defined(_MSC_VER)) + (!defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__MINGW32__)) struct timespec { time_t tv_sec; long tv_nsec; @@ -137,7 +136,7 @@ struct timespec { time_t tv_sec; long tv_nsec; }; -#endif //_TIMESPEC_DEFINED +#endif #endif #endif /*TODO - HAVE_TIMESPEC*/ diff --git a/include/edtypes.h b/include/edtypes.h index 44cade2e..2b719db1 100644 --- a/include/edtypes.h +++ b/include/edtypes.h @@ -1,11 +1,11 @@ #ifndef GR_EDTYPES_H_INCLUDED #define GR_EDTYPES_H_INCLUDED #include -__CIDENT_RCSID(gr_edtypes_h,"$Id: edtypes.h,v 1.39 2022/03/21 14:55:28 cvsuser Exp $") +__CIDENT_RCSID(gr_edtypes_h,"$Id: edtypes.h,v 1.40 2022/05/31 16:18:22 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: edtypes.h,v 1.39 2022/03/21 14:55:28 cvsuser Exp $ +/* $Id: edtypes.h,v 1.40 2022/05/31 16:18:22 cvsuser Exp $ * Editor base types. * * @@ -64,6 +64,8 @@ __CPRAGMA_ONCE #include #endif +#include + #if defined(_BSD_SOURCE) #if !defined(_BSDTYPES_DEFINED) #if !defined(u_char) @@ -423,7 +425,9 @@ typedef unsigned char LINEATTR; /* line attribute management */ /* * accumulator base types */ -#define ACCINT_SIZEOF SIZEOF_LONG +#define ACCINT_SIZEOF CM_ATOMSIZE + +#if (CM_ATOMSIZE == SIZEOF_LONG) #define ACCINT_FMT "ld" #if defined(LONG_MIN) #define ACCINT_MIN LONG_MIN @@ -432,6 +436,13 @@ typedef unsigned char LINEATTR; /* line attribute management */ #define ACCINT_MIN MAXLONG #define ACCINT_MAX MINLONG #endif +#elif (SIZEOF_LONG_LONG == SIZEOF_VOID_P) +#define ACCINT_FMT "lld" +#define ACCINT_MIN LLONG_MIN +#define ACCINT_MAX LLONG_MAX +#else +#error unable to determine atom size format/range. +#endif #define ACCFLOAT_SIZEOF SIZEOF_DOUBLE #define ACCFLOAT_FMT "g" /* dynamic 'e' or 'f' */ @@ -452,11 +463,7 @@ typedef unsigned char LINEATTR; /* line attribute management */ #define ACCFLOAT_MIN -HUGE #define ACCFLOAT_MAX HUGE #endif - -typedef long accint_t; -typedef long unsigned accuint_t; -typedef double accfloat_t; - + #define accstrtoi(_a, _b, _c) strtol(_a, _b, _c) #define accstrtou(_a, _b, _c) strtoul(_a, _b, _c) diff --git a/include/libstr.h b/include/libstr.h index a7ea913b..c0aa64d4 100644 --- a/include/libstr.h +++ b/include/libstr.h @@ -1,11 +1,11 @@ #ifndef GR_LIBSTR_H_INCLUDED #define GR_LIBSTR_H_INCLUDED #include -__CIDENT_RCSID(gr_str_h,"$Id: libstr.h,v 1.23 2022/03/21 14:55:28 cvsuser Exp $") +__CIDENT_RCSID(gr_str_h,"$Id: libstr.h,v 1.24 2022/06/16 10:16:26 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: libstr.h,v 1.23 2022/03/21 14:55:28 cvsuser Exp $ +/* $Id: libstr.h,v 1.24 2022/06/16 10:16:26 cvsuser Exp $ * libstr - String utility library. * * @@ -79,8 +79,11 @@ extern int str_ntok(char *result, size_t retlen, char *buf, con extern const char * str_numerror(int ret); extern int str_numparse(const char *str, double *dp, long *lp, int *len); +extern int str_numparsel(const char *str, double *dp, long long *lp, int *len); extern int str_numparsex(int (*get)(void *), int (*unget)(void *, int ch), void *parm, double *dp, long *lp, int *len); +extern int str_numparsexl(int (*get)(void *), int (*unget)(void *, int ch), void *parm, + double *dp, long long *lp, int *len); __CEND_DECLS diff --git a/libbsddb/Makefile.in b/libbsddb/Makefile.in index b67b315a..47b9dcf0 100644 --- a/libbsddb/Makefile.in +++ b/libbsddb/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.8 2020/06/18 20:35:17 cvsuser Exp $ +# $Id: Makefile.in,v 1.11 2022/06/01 14:21:19 cvsuser Exp $ # libbsddb makefile. # # -# Copyright (c) 1998 - 2020, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -70,15 +70,15 @@ D_LIB= $(ROOT)/lib@TOOLCHAINEXT@/$(BUILD_TYPE) XFLAGS= CFLAGS= @CFLAGS@ CWARN= @CWARN@ +ifeq (gcc,$(findstring gcc,$(CC))) +CWARN+= -Wno-unused-result +endif CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ CEXTRA+= -D__DBINTERFACE_PRIVATE -DHAVE_NBTOOL_CONFIG_H -DDEBUG -DSTATISTICS @@ -96,9 +96,6 @@ endif endif LDLIBS= -L$(D_LIB) @LIBS@ -lmisc @LIBMALLOC@ @LIBTHREAD@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv diff --git a/libbsddb/libpaths.c b/libbsddb/libpaths.c index 0b6d62d5..8c9b4219 100644 --- a/libbsddb/libpaths.c +++ b/libbsddb/libpaths.c @@ -1,5 +1,5 @@ /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: libpaths.c,v 1.7 2020/06/18 12:54:52 cvsuser Exp $ +/* $Id: libpaths.c,v 1.9 2022/05/26 13:36:07 cvsuser Exp $ * * libbsddb * @@ -50,8 +50,9 @@ #endif #endif /*WIN32*/ +#include "paths.h" -#if !defined(_PATH_TMP) +#if defined(NEED_libbsddb_PATH_TMP) #if defined(_WIN32) || defined(WIN32) #define access(__p,__m) _access(__p,__m) diff --git a/libbsddb/namespace.h b/libbsddb/namespace.h index 7f08c9aa..566f9657 100644 --- a/libbsddb/namespace.h +++ b/libbsddb/namespace.h @@ -1,10 +1,10 @@ #ifndef DBHASH_NAMESPACE_H_INCLUDED #define DBHASH_NAMESPACE_H_INCLUDED -/* $Id: namespace.h,v 1.10 2020/06/18 12:54:27 cvsuser Exp $ +/* $Id: namespace.h,v 1.12 2022/05/28 12:11:30 cvsuser Exp $ * * libbsdb * - * Copyright (c) 2012-2020 Adam Young. + * Copyright (c) 2012-2022 Adam Young. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,7 +35,7 @@ #endif #if defined(__linux__) /* _BSD_SOURCE has been deprecated, glibc >= 2.2 */ #if defined(_BSD_SOURCE) -#define _DEFAULT_SOURCE +#define _DEFAULT_SOURCE 1 #endif #endif @@ -103,7 +103,7 @@ #ifndef __CONCAT #if defined(__STDC__) || defined(_MSC_VER) || defined(__WATCOMC__) || \ - defined(__cplusplus) + defined(__MINGW32__) || defined(__cplusplus) #define __CONCAT(x,y) x ## y #else #define __CONCAT(x,y) x/**/y @@ -135,7 +135,11 @@ #endif /*WIN32*/ #ifndef EFTYPE +#if defined(EPROTONOSUPPORT) #define EFTYPE EPROTONOSUPPORT +#else +#define EFTYPE ENODEV +#endif #endif #endif /*DBHASH_NAMESPACE_H_INCLUDED*/ diff --git a/libbsddb/paths.h b/libbsddb/paths.h index aaf1ff7a..2b8fe47d 100644 --- a/libbsddb/paths.h +++ b/libbsddb/paths.h @@ -1,6 +1,6 @@ #ifndef LIBDBHASH_PATHS_H_INCLUDED #define LIBDBHASH_PATHS_H_INCLUDED -/* $Id: paths.h,v 1.3 2015/02/19 00:17:01 ayoung Exp $ +/* $Id: paths.h,v 1.4 2022/05/26 13:36:07 cvsuser Exp $ * * libbsddb * @@ -37,6 +37,7 @@ #endif #if !defined(_PATH_TMP) +#define NEED_libbsddb_PATH_TMP #define _PATH_TMP libbsddb_PATH_TMP() __CBEGIN_DECLS diff --git a/libbsdfetch/Makefile.in b/libbsdfetch/Makefile.in index 3264eeab..f57739a4 100644 --- a/libbsdfetch/Makefile.in +++ b/libbsdfetch/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.13 2020/06/18 20:35:17 cvsuser Exp $ +# $Id: Makefile.in,v 1.14 2022/06/01 14:21:19 cvsuser Exp $ # libbsdfetch makefile. # # @@ -76,9 +76,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ CEXTRA+= -DFTP_COMBINE_CWDS -DWITH_SSL -DWIN32_SOCKET_MAP_NATIVE @@ -96,9 +93,6 @@ endif endif LDLIBS= -L$(D_LIB) @LIBS@ -lmisc @LIBMALLOC@ @LIBTHREAD@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv diff --git a/libbsdio/Makefile.in b/libbsdio/Makefile.in index af2b897a..c6891a6c 100644 --- a/libbsdio/Makefile.in +++ b/libbsdio/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.7 2020/06/20 02:20:28 cvsuser Exp $ +# $Id: Makefile.in,v 1.9 2022/05/28 10:11:35 cvsuser Exp $ # libbsdio makefile. # # @@ -80,9 +80,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ CEXTRA+= -D__POSIX_VISIBLE=199506 -D__BSTDIO_INTERNAL -DFLOATING_POINT @@ -100,9 +97,6 @@ endif endif LDLIBS= -L$(D_LIB) $(LINKLIBS) @LIBS@ @LIBMALLOC@ @LIBTHREAD@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv diff --git a/libbsdio/bstdio.h b/libbsdio/bstdio.h index ae1c581b..6ef45b0f 100644 --- a/libbsdio/bstdio.h +++ b/libbsdio/bstdio.h @@ -271,9 +271,15 @@ int bsetvbuf(BFILE *, char *, int, size_t); int bsprintf(char *, const char *, ...) __ATTRIBUTE_FORMAT__ ((printf, 2, 3)) __ATTRIBUTE_NONNULL__ ((2)); +int bvsprintf(char *, const char *, __va_list ap) + __ATTRIBUTE_FORMAT__ ((printf, 2, 0)) + __ATTRIBUTE_NONNULL__ ((2)); int bsscanf(const char *, const char *, ...) __ATTRIBUTE_FORMAT__ ((scanf, 2, 3)) __ATTRIBUTE_NONNULL__ ((2)); +int bvsscanf(const char *, const char *, __va_list ap) + __ATTRIBUTE_FORMAT__ ((scanf, 2, 0)) + __ATTRIBUTE_NONNULL__ ((2)); BFILE *btmpfile(void); int bungetc(int, BFILE *); int bvfprintf(BFILE *, const char *, __va_list) diff --git a/libbsdio/findfp.c b/libbsdio/findfp.c index 65497bfd..50c2efb0 100644 --- a/libbsdio/findfp.c +++ b/libbsdio/findfp.c @@ -185,7 +185,7 @@ void __sinit(void) { // _THREAD_PRIVATE_MUTEX(__sinit_mutex); - int i; + unsigned i; // _THREAD_PRIVATE_MUTEX_LOCK(__sinit_mutex); if (__sdidinit) diff --git a/libbsdio/vfprintf.c b/libbsdio/vfprintf.c index ac1ae85e..9d8aff63 100644 --- a/libbsdio/vfprintf.c +++ b/libbsdio/vfprintf.c @@ -1282,7 +1282,9 @@ reswitch: switch (ch) { static int __grow_type_table(unsigned char **typetable, int *tablesize) { +#if defined(USE_MMAP) unsigned char *oldtable = *typetable; +#endif int newsize = *tablesize * 2; #if defined(USE_MMAP) diff --git a/libchartable/Makefile.in b/libchartable/Makefile.in index cbe8db6f..073c2f8e 100644 --- a/libchartable/Makefile.in +++ b/libchartable/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.29 2022/03/21 15:11:49 cvsuser Exp $ +# $Id: Makefile.in,v 1.31 2022/06/01 14:21:19 cvsuser Exp $ # libchartable makefile. # # @@ -85,9 +85,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ ifeq ("$(BUILD_TYPE)","release") @@ -99,9 +96,6 @@ LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif LDLIBS= -L$(D_LIB) @LIBS@ -lmisc @LIBMALLOC@ @LIBTHREAD@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv @@ -183,8 +177,7 @@ modules: $(D_BINCTBL)/.created \ data/.import: data/.created \ data/MAPPINGS/.import \ data/Unihan.zip \ - data/UCD.zip \ - data/uniset.tar.gz + data/UCD.zip @echo "++ do not delete, managed content ++" > $@ data/MAPPINGS/.import: data/MAPPINGS/.created diff --git a/libchartable/charsetalias.c b/libchartable/charsetalias.c index 3d4704a5..6a561848 100644 --- a/libchartable/charsetalias.c +++ b/libchartable/charsetalias.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_charsetalias_c,"$Id: charsetalias.c,v 1.14 2022/03/21 14:59:57 cvsuser Exp $") +__CIDENT_RCSID(gr_charsetalias_c,"$Id: charsetalias.c,v 1.15 2022/05/26 01:58:44 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* Locale/multibyte character information. @@ -129,7 +129,7 @@ charset_alias_open(int mode, int paths, const char **dirs, const char *aliasset) char *path = NULL; int pathlen = 0, p; - for (p = 0; -1 == ret && (paths >= 0 && p < paths) || (paths < 0 && dirs[p]); ++p) { + for (p = 0; -1 == ret && ((paths >= 0 && p < paths) || (paths < 0 && dirs[p])); ++p) { const char *dir; if (NULL != (dir = dirs[p]) && ('/' == *dir || '\\' == *dir)) { @@ -218,7 +218,7 @@ const char * charset_alias_lookup(const char *name, int namelen) { if (name) { - return charset_lookup(&x_charsetmap, name, (namelen > 0 ? namelen : strlen(name))); + return charset_lookup(&x_charsetmap, name, (namelen > 0 ? namelen : (int)strlen(name))); } return NULL; } @@ -280,7 +280,6 @@ charset_load(struct charsetmap *map, int mode, const char *aliasset) case ':': case '[': /* section */ if (CHARSET_MODE_INI == mode) { /* :primary or [primary] */ const char delimiter = *cursor; - char name[201]; cs = NULL; if (1 == sscanf(cursor + 1, "%64[^ \t\n\r]", name)) { diff --git a/libchartable/charseticonv.c b/libchartable/charseticonv.c index 0ceee410..aebe03b2 100644 --- a/libchartable/charseticonv.c +++ b/libchartable/charseticonv.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_charseticonv_c,"$Id: charseticonv.c,v 1.22 2022/03/21 14:59:57 cvsuser Exp $") +__CIDENT_RCSID(gr_charseticonv_c,"$Id: charseticonv.c,v 1.23 2022/05/26 01:57:30 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* Conversion tables loader/interface. @@ -240,7 +240,7 @@ charset_iconv_open(const char *name, int flags) char canon_buffer[64]; const char *charset; int charsetlen = 0; - unsigned i; + unsigned c; if (NULL != (charset = charset_canonicalize(name, namelen, canon_buffer, sizeof(canon_buffer))) || NULL != (charset = charset_alias_lookup(name, namelen))) { @@ -255,7 +255,7 @@ charset_iconv_open(const char *name, int flags) return iconv_alloc(dlmod, flags); /* pre-existing */ } - for (i = 0, ct = charsettables; i < (sizeof(charsettables)/sizeof(charsettables[0])); ++i, ++ct) { + for (c = 0, ct = charsettables; c < (sizeof(charsettables)/sizeof(charsettables[0])); ++ct, ++c) { if (NULL == ct->module && ct->container) { /* dynamic binding */ @@ -601,7 +601,7 @@ dlmod_open(const char *module, int flag, const char *path, struct dlmodule ** re if (CHARTABLE_PACKAGE_MAGIC == pkg->cp_magic) { const struct chartable_module * const *modules = pkg->cp_modules; uint32_t count = pkg->cp_count; - int t_ret, cnt = 0, ret = 0; + int t_ret, cnt = 0; while (*modules && count-- > 0) { if (0 == (t_ret = dlmod_push(*modules, handle, module, path, &dlmod))) { diff --git a/libchartable/charsetlocale.c b/libchartable/charsetlocale.c index 838022bd..51be9e9c 100644 --- a/libchartable/charsetlocale.c +++ b/libchartable/charsetlocale.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_charsetlocale_c,"$Id: charsetlocale.c,v 1.11 2022/03/21 14:59:57 cvsuser Exp $") +__CIDENT_RCSID(gr_charsetlocale_c,"$Id: charsetlocale.c,v 1.12 2022/05/26 01:56:12 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* libcharset locale map. @@ -35,6 +35,10 @@ __CIDENT_RCSID(gr_charsetlocale_c,"$Id: charsetlocale.c,v 1.11 2022/03/21 14:59: #include "libchartable.h" #include "charsetlocales.h" +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wunused-const-variable" +#endif + static const char ISO8859_1[] = "iso8859-1"; static const char ISO8859_2[] = "iso8859-2"; static const char ISO8859_3[] = "iso8859-3"; diff --git a/libchartable/charsetstream.c b/libchartable/charsetstream.c index 5546085e..5b40ca9c 100644 --- a/libchartable/charsetstream.c +++ b/libchartable/charsetstream.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_charsetstream_c,"$Id: charsetstream.c,v 1.12 2022/03/21 14:59:57 cvsuser Exp $") +__CIDENT_RCSID(gr_charsetstream_c,"$Id: charsetstream.c,v 1.13 2022/05/26 01:55:57 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* conversion stream support. @@ -87,7 +87,7 @@ stream_write(iconv_stream_t *s, const void *buf, size_t insize) ssize_t cnt; /* flush converted text */ outbuf = s->s_iobuf; - while ((cnt = s->s_write(s->s_handle, outbuf, outsize, &t_errno)) < outsize) { + while ((cnt = s->s_write(s->s_handle, outbuf, outsize, &t_errno)) < (ssize_t)outsize) { if (cnt <= 0) { if (EINTR == t_errno) { continue; @@ -213,7 +213,7 @@ iconv_stream_write(iconv_stream_t *s, const void *buf, size_t insize) */ if (s->s_buffer && s->s_buflen) { char *buffer = s->s_buffer; - size_t left, buflen; + ssize_t left, buflen; if ((buflen = s->s_buflen) >= ICONVSTREAMBUFSZ) { errno = E2BIG; @@ -221,7 +221,7 @@ iconv_stream_write(iconv_stream_t *s, const void *buf, size_t insize) } do { /* concat previous and new data */ - assert(buflen < ICONVSTREAMBUFSZ); + assert(buflen > 0 && buflen < ICONVSTREAMBUFSZ); if ((left = (ICONVSTREAMBUFSZ - buflen)) > size) { left = size; } diff --git a/libchartable/charsettable.c b/libchartable/charsettable.c index 3da277aa..b01990b8 100644 --- a/libchartable/charsettable.c +++ b/libchartable/charsettable.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_charsettable_c,"$Id: charsettable.c,v 1.16 2022/03/21 14:59:57 cvsuser Exp $") +__CIDENT_RCSID(gr_charsettable_c,"$Id: charsettable.c,v 1.17 2022/05/26 01:55:12 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* conversion tables. @@ -138,7 +138,7 @@ charset_description(int32_t unicode, char *buffer, int buflen) desc = utf8_decode(desc, &idx); if ((idx -= 0x60) >= 0 && - idx < (sizeof(x_charsetdesc_words)/sizeof(x_charsetdesc_words[0]))) { + idx < (int32_t)(sizeof(x_charsetdesc_words)/sizeof(x_charsetdesc_words[0]))) { const char *word = x_charsetdesc_words[idx]; diff --git a/libchartable/charsetutil.c b/libchartable/charsetutil.c index eef37aca..c29706bd 100644 --- a/libchartable/charsetutil.c +++ b/libchartable/charsetutil.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_charsetutil_c,"$Id: charsetutil.c,v 1.12 2022/03/21 14:59:58 cvsuser Exp $") +__CIDENT_RCSID(gr_charsetutil_c,"$Id: charsetutil.c,v 1.13 2022/05/26 01:54:57 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* utility functions. @@ -194,7 +194,7 @@ const char * charset_canonicalize(const char *name, int namelen, char *buffer, int bufsiz) { char t_name[CS_NAMELEN+1]; - const char *end = name + (namelen > 0 ? namelen : strlen(name)); + const char *end = name + (namelen > 0 ? namelen : (int)strlen(name)); int t_namelen = 0; assert(bufsiz >= 16); diff --git a/libcharudet/Makefile.in b/libcharudet/Makefile.in index dc4addce..aac880dc 100644 --- a/libcharudet/Makefile.in +++ b/libcharudet/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.11 2020/06/18 20:35:17 cvsuser Exp $ +# $Id: Makefile.in,v 1.12 2022/05/26 13:00:39 cvsuser Exp $ # libcharudet makefile # # -# Copyright (c) 1998 - 2020, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -87,19 +87,16 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I./src -I./tab -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ ifeq ("$(BUILD_TYPE)","release") CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXRELEASE) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXRELEASE) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDRELEASE) @LDFLAGS@ else CFLAGS+= $(CDEBUG) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXDEBUG) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXDEBUG) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif ifeq (gcc,$(findstring gcc,$(CC))) @@ -109,9 +106,6 @@ endif endif LDLIBS= -L$(D_LIB) @LDLIBS@ @LIBS@ @LIBMALLOC@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lshell32 -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv diff --git a/libduktape/Makefile.in b/libduktape/Makefile.in index 6c64bcfb..9e11bef4 100644 --- a/libduktape/Makefile.in +++ b/libduktape/Makefile.in @@ -1,8 +1,8 @@ -# $Id: Makefile.in,v 1.9 2021/04/11 15:15:58 cvsuser Exp $ +# $Id: Makefile.in,v 1.11 2022/06/01 14:21:19 cvsuser Exp $ # libduktape makefile. # # -# Copyright (c) 2018 - 2021, Adam Young. +# Copyright (c) 2018 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -87,9 +87,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ @@ -109,9 +106,6 @@ endif endif LDLIBS= -L$(D_LIB) @LDLIBS@ @LIBS@ @LIBM@ @LIBMALLOC@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lshell32 -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv @@ -146,10 +140,13 @@ LIBOBJS=\ DLLOBJS=\ $(subst $(O),.lo,$(LIBOBJS)) -ifeq ("mingw32","@build_os@") -DLLOBJS+= $(D_OBJ)/duktape_res.o -else ifeq ("duktape","@build_os@") -DLLOBJS+= $(D_OBJ)/duktape.res + +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) +DLLOBJS+= $(D_OBJ)/libduktape_res.o +else +DLLOBJS+= $(D_OBJ)/libduktape.res +endif endif DUKOBJS=\ @@ -192,14 +189,8 @@ $(DUK): Makefile $(DUKOBJS) $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(DUKOBJS) $(DUKTAPEDLL) $(LDLIBS) @LDMAPFILE@ version.h: Makefile - @sh -c '\ -echo // Auto-generated by Makefile >$@; \ -echo \#define DUKTAPE_VERSION \\\"$(VERSION)\\\" >>$@; \ -echo \#define DUKTAPE_VER_MAJOR $(VERSION_1) >>$@; \ -echo \#define DUKTAPE_VER_MINOR $(VERSION_2) >>$@; \ -echo \#define DUKTAPE_VER_REVISION $(VERSION_3) >>$@; \ -' - + $(PERL) ./version.pl "$(VERSION)" + $(D_OBJ)/.created: -@mkdir $(D_OBJ) @echo "do not create" > $@ diff --git a/libduktape/version.pl b/libduktape/version.pl new file mode 100644 index 00000000..0dbd996f --- /dev/null +++ b/libduktape/version.pl @@ -0,0 +1,104 @@ +#!/usr/bin/perl -w +# -*- mode: perl; -*- +# $Id: version.pl,v 1.1 2022/05/26 13:00:12 cvsuser Exp $ +# duktape version +# +# Copyright Adam Young 2022 +# All rights reserved. +# +# The applications are free software: you can redistribute it +# and/or modify it under the terms of the GRIEF license. +# +# Redistributions of source code must retain the above copyright +# notice, and must be distributed with the license document above. +# +# Redistributions in binary form must reproduce the above copyright +# notice, and must include the license document above in +# the documentation and/or other materials provided with the +# distribution. +# +# The applications are 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# ==end== +# + +use strict; +use warnings 'all'; +use Getopt::Long; +use POSIX qw(strftime asctime); + +my $output = "version.h"; +my $prefix = "DUKTAPE_"; +my $version = "0.0.1"; +my $builddate = undef; +my $help = 0; + +Usage() if (0 == GetOptions( + 'output=s' => \$output, + 'prefix=s' => \$prefix, + 'version=s' => \$version, + 'date=i' => \$builddate, + 'help' => \$help) + || $help); + +$version = "0.0.1" + if (! $version); + +$builddate = strftime('%Y%m%d', localtime) + if (! $builddate); + +Generate(); + +sub +Generate #() +{ + open(FILE, ">${output}") or + die "cannot create <${output}> : $!\n"; + + my ($version1, $version2, $version3, $version4) = + split(/\./, $version); + + my $timestamp = asctime(localtime); + chomp($timestamp); + + $version2 = 0 if (! $version2); + $version3 = 0 if (! $version3); + + print FILE <<"EOT"; +// Auto-generated by Makefile ${timestamp} +#define ${prefix}VERSION "${version}" +#define ${prefix}VER_MAJOR ${version1} +#define ${prefix}VER_MINOR ${version2} +#define ${prefix}VER_REVISION ${version3} +#define ${prefix}BUILD_DATE "${builddate}" +EOT + close(FILE); +} + + +sub +Usage # ([message]) +{ + print "\nversion.pl @_\n\n" if (@_); + print < Package version. + --prefix Identifier prefix (optional). + --date Build date (optionaL). + +EOU + exit 3; +} + +1; + +#end + diff --git a/libllist/Makefile.in b/libllist/Makefile.in index f2172fe4..3ca7e5ba 100644 --- a/libllist/Makefile.in +++ b/libllist/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.16 2022/03/21 15:13:03 cvsuser Exp $ +# $Id: Makefile.in,v 1.17 2022/06/01 14:21:19 cvsuser Exp $ # libllist makefile. # # @@ -76,9 +76,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ ifeq ("$(BUILD_TYPE)","release") @@ -95,9 +92,6 @@ endif endif LDLIBS= -L$(D_LIB) @LIBS@ -lmisc @LIBMALLOC@ @LIBTHREAD@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv diff --git a/libmalloc/Makefile.in b/libmalloc/Makefile.in index 372d2341..3d727581 100644 --- a/libmalloc/Makefile.in +++ b/libmalloc/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.14 2020/06/18 20:35:17 cvsuser Exp $ +# $Id: Makefile.in,v 1.16 2022/06/01 14:21:19 cvsuser Exp $ # libdlmalloc makefile. # # -# Copyright (c) 1998 - 2020, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -85,9 +85,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ ifeq ("win32","@build_os@") @@ -96,11 +93,11 @@ endif ifeq ("$(BUILD_TYPE)","release") CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXRELEASE) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXRELEASE) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDRELEASE) @LDFLAGS@ else CFLAGS+= $(CDEBUG) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXDEBUG) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXDEBUG) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif ifeq (gcc,$(findstring gcc,$(CC))) @@ -110,9 +107,6 @@ endif endif LDLIBS= -L$(D_LIB) @LDLIBS@ @LIBS@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lshell32 -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv diff --git a/libmalloc/malloc-2.8.6.c b/libmalloc/malloc-2.8.6.c index 29cd73d4..21e50860 100644 --- a/libmalloc/malloc-2.8.6.c +++ b/libmalloc/malloc-2.8.6.c @@ -782,6 +782,10 @@ struct mallinfo { inlining are defined as macros, so these aren't used for them. */ +#if defined(__MINGW64_VERSION_MAJOR) +#undef FORCEINLINE +#endif + #ifndef FORCEINLINE #if defined(__GNUC__) #define FORCEINLINE __inline __attribute__ ((always_inline)) @@ -997,7 +1001,7 @@ DLMALLOC_EXPORT size_t dlmalloc_max_footprint(void); guarantee that this number of bytes can actually be obtained from the system. */ -DLMALLOC_EXPORT size_t dlmalloc_footprint_limit(); +DLMALLOC_EXPORT size_t dlmalloc_footprint_limit(void); /* malloc_set_footprint_limit(); diff --git a/libmisc/Makefile.in b/libmisc/Makefile.in index dfcf519f..291596a9 100644 --- a/libmisc/Makefile.in +++ b/libmisc/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.42 2020/06/18 20:35:17 cvsuser Exp $ +# $Id: Makefile.in,v 1.43 2022/06/01 14:21:19 cvsuser Exp $ # libmisc makefile. # # @@ -85,9 +85,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ ifeq ("win32","@build_os@") @@ -110,9 +107,6 @@ endif endif LDLIBS= -L$(D_LIB) @LDLIBS@ @LIBS@ @LIBMALLOC@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lshell32 -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv diff --git a/libmisc/bsd_qsort.c b/libmisc/bsd_qsort.c index f485d1ff..a96255dc 100644 --- a/libmisc/bsd_qsort.c +++ b/libmisc/bsd_qsort.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_bsd_qsort_c,"$Id: bsd_qsort.c,v 1.7 2020/04/11 21:37:12 cvsuser Exp $") +__CIDENT_RCSID(gr_bsd_qsort_c,"$Id: bsd_qsort.c,v 1.8 2022/05/25 15:44:02 cvsuser Exp $") /*- -*- indent-width: 4; tabs: 8; -*- * Copyright (c) 1992, 1993 @@ -37,6 +37,10 @@ __CIDENT_RCSID(gr_bsd_qsort_c,"$Id: bsd_qsort.c,v 1.7 2020/04/11 21:37:12 cvsuse #include +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wsign-compare" +#endif + #ifdef I_AM_QSORT_R #define cmp_t sortcmpr_t #define CMP(t, x, y) (cmp((t), (x), (y))) diff --git a/libmisc/bsd_radixsort.c b/libmisc/bsd_radixsort.c index 3e14f238..32e6fa2b 100644 --- a/libmisc/bsd_radixsort.c +++ b/libmisc/bsd_radixsort.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_bsd_radixsort_c,"$Id: bsd_radixsort.c,v 1.9 2020/06/05 23:29:50 cvsuser Exp $") +__CIDENT_RCSID(gr_bsd_radixsort_c,"$Id: bsd_radixsort.c,v 1.10 2022/05/25 15:44:02 cvsuser Exp $") /*- -*- indent-width: 8; tabs: 8; -*- * Copyright (c) 1990, 1993 @@ -65,6 +65,10 @@ typedef struct { int sn, si; } stack; +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wsign-compare" +#endif + static __CINLINE void simplesort(const u_char **, int, int, const u_char *, u_int); static void r_sort_a(const u_char **, int, int, const u_char *, u_int); static void r_sort_b(const u_char **, const u_char **, int, int, const u_char *, u_int); diff --git a/libmisc/crc32.c b/libmisc/crc32.c index 0e6be32c..9a554999 100644 --- a/libmisc/crc32.c +++ b/libmisc/crc32.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_crc32_c,"$Id: crc32.c,v 1.10 2017/01/29 04:33:31 cvsuser Exp $") +__CIDENT_RCSID(gr_crc32_c,"$Id: crc32.c,v 1.11 2022/05/25 15:44:02 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: crc32.c,v 1.10 2017/01/29 04:33:31 cvsuser Exp $ +/* $Id: crc32.c,v 1.11 2022/05/25 15:44:02 cvsuser Exp $ * * The CRC32 employs the reverse-polynomial calculation method on the * polynomial 0xEDB88320 used as the frame check sequence in ADCCP (ANSI @@ -149,6 +149,10 @@ crc32_EDB88320(const void *data, size_t size, uint32_t crc32) #define HASH crc = crc32_table[(*p++ ^ (unsigned char)crc)] ^ (crc >> 8) +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#endif + loop = (size + 8 - 1) >> 3; switch (size & (8 - 1)) { case 0: diff --git a/libmisc/edbt_win32.c b/libmisc/edbt_win32.c index 428ffd9d..845be71d 100644 --- a/libmisc/edbt_win32.c +++ b/libmisc/edbt_win32.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_edbt_win32_c,"$Id: edbt_win32.c,v 1.22 2020/06/18 13:15:07 cvsuser Exp $") +__CIDENT_RCSID(gr_edbt_win32_c,"$Id: edbt_win32.c,v 1.23 2022/05/25 15:44:58 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: edbt_win32.c,v 1.22 2020/06/18 13:15:07 cvsuser Exp $ +/* $Id: edbt_win32.c,v 1.23 2022/05/25 15:44:58 cvsuser Exp $ * win32 (include cygwin) backtrace implementation. * * @@ -46,6 +46,10 @@ __CIDENT_RCSID(gr_edbt_win32_c,"$Id: edbt_win32.c,v 1.22 2020/06/18 13:15:07 cvs #undef u_char #include +#if defined(__MINGW32__) /* Kernel32 */ +VOID NTAPI RtlCaptureContext(PCONTEXT ContextRecord); +#endif + #if defined(__WATCOMC__) || defined(__CYGWIN__) || defined(__MINGW32__) /* WATCOMC 1.9, 64bit issues */ /* CYGWIN 1.7, no 64 support */ diff --git a/libmisc/edthreads_pthread.c b/libmisc/edthreads_pthread.c index 77e5b356..47a29914 100644 --- a/libmisc/edthreads_pthread.c +++ b/libmisc/edthreads_pthread.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_edthreads_pthread_c,"$Id: edthreads_pthread.c,v 1.10 2017/01/29 04:33:31 cvsuser Exp $") +__CIDENT_RCSID(gr_edthreads_pthread_c,"$Id: edthreads_pthread.c,v 1.11 2022/05/25 15:45:19 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: edthreads_pthread.c,v 1.10 2017/01/29 04:33:31 cvsuser Exp $ +/* $Id: edthreads_pthread.c,v 1.11 2022/05/25 15:45:19 cvsuser Exp $ * C11 threads implementation, for/using pthreads * based on ISO/IEC 9899:201x Committee Draft, April 12, 2011 * @@ -777,6 +777,7 @@ tss_set(tss_t key, void *val) #else +extern void edthreads_pthreads_notimplemented(void); void edthreads_pthreads_notimplemented(void) { diff --git a/libmisc/edthreads_win32.c b/libmisc/edthreads_win32.c index 8b6ef9b5..0130e3bd 100644 --- a/libmisc/edthreads_win32.c +++ b/libmisc/edthreads_win32.c @@ -1,14 +1,14 @@ #include -__CIDENT_RCSID(gr_edthreads_win32_c,"$Id: edthreads_win32.c,v 1.18 2020/06/21 01:36:17 cvsuser Exp $") +__CIDENT_RCSID(gr_edthreads_win32_c,"$Id: edthreads_win32.c,v 1.21 2022/06/13 12:47:44 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: edthreads_win32.c,v 1.18 2020/06/21 01:36:17 cvsuser Exp $ +/* $Id: edthreads_win32.c,v 1.21 2022/06/13 12:47:44 cvsuser Exp $ * C11 threads implementation, for windows * based on ISO/IEC 9899:201x Committee Draft, April 12, 2011 N1570 * * * - * Copyright (c) 1998 - 2020, Adam Young. + * Copyright (c) 1998 - 2022, Adam Young. * All rights reserved. * * This file is part of the GRIEF Editor. @@ -58,47 +58,19 @@ edthreads_win32_native(void) // with the following 'other' POSIX realtime functions missing. // #if !defined(HAVE_PTHREAD_H) -#error pthreads expected under mingw32 +#define WIN32_NATIVE_MUTEX +#pragma message "pthreads expected under mingw32; enabling local implementation" #endif -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN +#elif defined(_WIN32) || defined(WIN32) +#define WIN32_NATIVE_MUTEX #endif -#undef u_char -#include -#include -#include - - -int -usleep(/*usecond_t*/ const unsigned useconds) -{ - HANDLE timer = 0; - LARGE_INTEGER due = {0}; - - due.QuadPart = -(10 * (__int64)useconds); - SetWaitableTimer(timer, &due, 0, NULL, NULL, 0); - WaitForSingleObject(timer, INFINITE); - CloseHandle(timer); - return 0; -} - - -int -nanosleep(const struct timespec *rqtp, struct timespec *rmtp /*notused*/) -{ - if (!rqtp || rqtp->tv_nsec > 999999999) { - errno = EINVAL; - return -1; - } - return usleep(rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000); -} - -#elif defined(_WIN32) || defined(WIN32) // -// Native Win threading +// Native Windows threading // +#if defined(WIN32_NATIVE_MUTEX) + #if defined(__CYGWIN__) #error incorrect target, win32 only #endif @@ -107,8 +79,6 @@ nanosleep(const struct timespec *rqtp, struct timespec *rmtp /*notused*/) #include #include - - #define MTX_MAGIC MKMAGIC('W','M','t','x') #define SIGNAL 0 @@ -900,6 +870,7 @@ timespec_get(struct timespec *ts, int __unused_based) #endif /*FIXME - HAVE_TIMESPEC_GET*/ +// typedef VOID (NTAPI *PIMAGE_TLS_CALLBACK) (PVOID DllHandle, DWORD Reason, PVOID Reserved); static void WINAPI __tss_callback(void *image, DWORD reason, void *pv) { @@ -963,6 +934,7 @@ __tss_init(void) * XCL library inits * XCU user inits * + * Runtime hooks: * XCA/XCZ C++ initializers * XIA/XIZ C initializers * XPA/XPZ C pre-terminators @@ -975,6 +947,16 @@ __declspec(allocate(".CRT$XLC")) void *__edthr_xlc = __tss_callback; #pragma section(".CRT$XIU",long,read) __declspec(allocate(".CRT$XIU")) void *__edthr_xiu = __tss_init; +#elif defined(__MINGW32__) +#pragma data_seg(".CRT$XLC","DATA") +void *__edthr_xlc = __tss_callback; + +__attribute__((constructor)) +static void tss_constructor() { + // objdump -x edthreads_win32.o | grep ctors + __tss_init(); +} + #else #pragma data_seg(".CRT$XLC","DATA") void *__edthr_xlc = __tss_callback; diff --git a/libmisc/env.c b/libmisc/env.c index 05269e0e..607f5703 100644 --- a/libmisc/env.c +++ b/libmisc/env.c @@ -1,13 +1,13 @@ #include -__CIDENT_RCSID(cr_env_c,"$Id: env.c,v 1.29 2020/06/18 13:13:01 cvsuser Exp $") +__CIDENT_RCSID(cr_env_c,"$Id: env.c,v 1.30 2022/05/31 16:18:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: env.c,v 1.29 2020/06/18 13:13:01 cvsuser Exp $ +/* $Id: env.c,v 1.30 2022/05/31 16:18:23 cvsuser Exp $ * Environment related functions. * * * - * Copyright (c) 1998 - 2017, Adam Young. + * Copyright (c) 1998 - 2022, Adam Young. * All rights reserved. * * This file is part of the GRIEF Editor. @@ -34,22 +34,40 @@ __CIDENT_RCSID(cr_env_c,"$Id: env.c,v 1.29 2020/06/18 13:13:01 cvsuser Exp $") #include #include +#include + +#ifndef MKMAGIC +#define MKMAGIC(a,b,c,d) (((unsigned long)(a))<<24|((unsigned long)(b))<<16|(c)<<8|(d)) +#endif + +#define MAGIC_ELEMENT MKMAGIC('E','n','v','N') + #if defined(_VMS) || !defined(HAVE_SETENV) #define NEED_SETENV_CACHE #endif #if defined(NEED_SETENV_CACHE) -static Head_p hd_env = NULL; +typedef TAILQ_HEAD(_EnvList, EnvElement) + ENVLIST_t; -static List_p glookup(const char *); -static void greplace(char *arg); +struct EnvElement { + unsigned long magic; + TAILQ_ENTRY(EnvElement) node; + const char *value; +}; + +static ENVLIST_t x_envtq; + +static struct EnvElement * gelement(const char *); +static const char * glookup(const char *); +static void greplace(const char *arg); void env_init(void) { - if (NULL == hd_env) { - hd_env = ll_init(); + if (NULL == x_envtq.tqh_last) { + TAILQ_INIT(&x_envtq); } } @@ -57,30 +75,32 @@ env_init(void) void env_shutdown(void) { - if (hd_env) { - ll_clear2(hd_env, free); - ll_free(hd_env); - hd_env = NULL; + if (x_envtq.tqh_last) { + struct EnvElement *mp; + while (NULL != (mp = TAILQ_FIRST(&x_envtq))) { + assert(mp->magic == MAGIC_ELEMENT); + TAILQ_REMOVE(&x_envtq, mp, node); + free(mp); + } } } -static List_p -glookup(const char *name) +static struct EnvElement * +gelement(const char *name) { - int len; - List_p lp; + if (x_envtq.tqh_last) { + struct EnvElement *mp; + int len; - if (hd_env) { for (len = 0; name[len] != '=' && name[len];) { ++len; } - for (lp = ll_first(hd_env); lp; lp = ll_next(lp)) { - const char *lname = (const char *) ll_elem(lp); - - if (0 == strncmp(name, lname, len) && '=' == lname[len]) { - return lp; + TAILQ_FOREACH(mp, &x_envtq, node) { + assert(mp->magic == MAGIC_ELEMENT); + if (0 == strncmp(name, mp->value, len) && '=' == mp->value[len]) { + return mp; } } } @@ -88,31 +108,39 @@ glookup(const char *name) } -static void -greplace(char *arg) +static const char * +glookup(const char *name) { - if (NULL == hd_env) { - env_init(); + struct EnvElement *mp = gelement(name); + if (mp) { + return mp->value; } + return NULL; +} - if (arg && hd_env) { - List_p lp; - if (NULL != (lp = glookup(arg))) { - free(ll_elem(lp)); - ll_delete(lp); - } +static void +greplace(const char *name) +{ + if (name && *name) { + struct EnvElement *mp; - if (NULL == hd_env) { - env_init(); - } + env_init(); + if (NULL != (mp = gelement(name))) { + mp->value = name; - ll_append(hd_env, arg); + } else { + if (NULL != (mp = (struct EnvElement *)calloc(1, sizeof(struct EnvElement)))) { + mp->magic = MAGIC_ELEMENT; + mp->value = name; + TAILQ_INSERT_TAIL(&x_envtq, mp, node); + } + } } } -#else /*NEED_SETENV_CACHE*/ +#else /*NEED_SETENV_CACHE*/ void env_init(void) { @@ -188,18 +216,16 @@ ggetenv(const char * name) #if !defined(_VMS) return getenv(name); -#else /*_VMS*/ - List_p lp = glookup(name); - const char *cp; - - if (NULL == lp) { - return getenv(name); - } +#else /*_VMS*/ + const char *cp = glookup(name); - for (cp = (char *) ll_elem(lp); *cp != '=' && *cp;) { - ++cp; + if (NULL != cp) { + while (*cp != '=' && *cp) { + ++cp; + } + return (*cp == '=' ? cp + 1 : cp); } - return *cp == '=' ? cp + 1 : cp; + return getenv(name); #endif } diff --git a/libmisc/getopt_common.c b/libmisc/getopt_common.c index 176b6337..ee61edd9 100644 --- a/libmisc/getopt_common.c +++ b/libmisc/getopt_common.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_getopt_common_c,"$Id: getopt_common.c,v 1.9 2020/06/18 13:16:22 cvsuser Exp $") +__CIDENT_RCSID(gr_getopt_common_c,"$Id: getopt_common.c,v 1.10 2022/05/25 15:44:02 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: getopt_common.c,v 1.9 2020/06/18 13:16:22 cvsuser Exp $ +/* $Id: getopt_common.c,v 1.10 2022/05/25 15:44:02 cvsuser Exp $ * common globals getopt/bsd_getopt. * * @@ -36,6 +36,7 @@ __CIDENT_RCSID(gr_getopt_common_c,"$Id: getopt_common.c,v 1.9 2020/06/18 13:16:2 #include #elif defined(__MINGW32__) +#include #elif defined(_WIN32) || defined(WIN32) @@ -47,10 +48,10 @@ int optreset = 0; /* reset getopt */ #endif -extern void __getopt_common(void); - +extern void __getopt_common_dummy(void); void -__getopt_common_dummy() { +__getopt_common_dummy() +{ } /*end*/ diff --git a/libmisc/strparse.c b/libmisc/strparse.c index 539c93fd..49bdb164 100644 --- a/libmisc/strparse.c +++ b/libmisc/strparse.c @@ -1,13 +1,13 @@ #include -__CIDENT_RCSID(gr_strparse_c,"$Id: strparse.c,v 1.13 2020/05/03 21:09:06 cvsuser Exp $") +__CIDENT_RCSID(gr_strparse_c,"$Id: strparse.c,v 1.16 2022/06/16 10:54:00 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: strparse.c,v 1.13 2020/05/03 21:09:06 cvsuser Exp $ +/* $Id: strparse.c,v 1.16 2022/06/16 10:54:00 cvsuser Exp $ * libstr - String to numeric (float/integer) parser. * * * - * Copyright (c) 1998 - 2020, Adam Young. + * Copyright (c) 1998 - 2022, Adam Young. * All rights reserved. * * This file is part of the GRIEF Editor. @@ -66,6 +66,7 @@ struct parse { int (*p_get)(void *); int (*p_unget)(void *, int ch); long * p_long; + long long * p_llong; double * p_double; void * p_parm; char * p_cursor; @@ -397,18 +398,51 @@ chparse(struct parse *p) * An integer number, either decimal, hex, octal or binary. */ char *ep; - long lret; - errno = 0; lret = strtol(num, &ep, base); - if (ERANGE == errno) { - DDEBUG((" OVER/UNDERFLOW\n")) - return (lret == LONG_MIN ? NUMPARSE_ERR_OVERFLOW : NUMPARSE_ERR_UNDERFLOW); - } - if (!*ep) { - *p->p_long = lret; - DDEBUG((" INTEGER(%d)\n", lret)) - return NUMPARSE_INTEGER; +#if (SIZEOF_LONG_LONG > SIZEOF_LONG) && \ + (defined(HAVE_STRTOLL) || defined(_MSC_VER)) +#define LLSTRPARSE + if (p->p_llong) { + long long lret; + + errno = 0; +#if defined(HAVE_STRTOLL) + lret = strtoll(num, &ep, base); +#else + lret = (long long)_strtoi64(num, &ep, base); +#endif + if (ERANGE == errno) { + DDEBUG((" OVER/UNDERFLOW\n")) + return (lret == LLONG_MIN ? NUMPARSE_ERR_OVERFLOW : NUMPARSE_ERR_UNDERFLOW); + } + if (!*ep) { + *p->p_llong = lret; + DDEBUG((" INTEGER(%lld)\n", lret)) + return NUMPARSE_INTEGER; + } + } else { +#endif + long lret; + + errno = 0; + lret = strtol(num, &ep, base); + if (ERANGE == errno) { + DDEBUG((" OVER/UNDERFLOW\n")) + return (lret == LONG_MIN ? NUMPARSE_ERR_OVERFLOW : NUMPARSE_ERR_UNDERFLOW); + } + + if (!*ep) { + if (p->p_llong) { + *p->p_llong = lret; + } else { + *p->p_long = lret; + } + DDEBUG((" INTEGER(%ld)\n", lret)) + return NUMPARSE_INTEGER; + } +#if defined(LLSTRPARSE) } +#endif } } @@ -423,9 +457,13 @@ static void chinit(struct parse *p) { *p->p_double = 0; - *p->p_long = 0; - p->p_cursor = p->p_buffer; - p->p_end = p->p_buffer + sizeof(p->p_buffer); + if (p->p_llong) { + *p->p_llong = 0; + } else { + *p->p_long = 0; + } + p->p_cursor = p->p_buffer; + p->p_end = p->p_buffer + sizeof(p->p_buffer); } @@ -448,7 +486,7 @@ chxmatch(struct parse *p, const char *s) if (ch != match) { /* same case */ break; } - assert(count < sizeof(stack)); + assert(count < (int)sizeof(stack)); stack[count++] = ch; ch = -1; } @@ -478,7 +516,7 @@ chmatch(struct parse *p, const char *s) if (tolower(ch) != tolower(match)) {/* case insensitive */ break; } - assert(count < sizeof(stack)); + assert(count < (int)sizeof(stack)); stack[count++] = ch; ch = -1; } @@ -631,6 +669,31 @@ str_numparse(const char *str, double *dp, long *lp, int *len) } +int +str_numparsel(const char *str, double *dp, long long *lp, int *len) +{ + struct parse p = {0}; + int ret; + + p.p_double = dp; + p.p_llong = lp; + p.p_get = sget; + p.p_unget = sunget; + p.p_parm = (void *)&p; + p.p_data = (unsigned char *)str; + + if ((ret = chparse(&p)) > NUMPARSE_ERROR) { + if (len) { + *len = (p.p_cursor - p.p_buffer); + } + if (ret == NUMPARSE_FLOAT) { + *lp = (long) *dp; + } + } + return ret; +} + + static int sget(void *parm) { @@ -674,6 +737,30 @@ str_numparsex(int (*get)(void *), int (*unget)(void *, int ch), void *parm, doub } +int +str_numparsexl(int (*get)(void *), int (*unget)(void *, int ch), void *parm, double *dp, long long *lp, int *len) +{ + struct parse p = {0}; + int ret; + + p.p_double = dp; + p.p_llong = lp; + p.p_get = get; + p.p_unget = unget; + p.p_parm = parm; + + if ((ret = chparse(&p)) > NUMPARSE_ERROR) { + if (len) { + *len = (p.p_cursor - p.p_buffer); + } + if (ret == NUMPARSE_FLOAT) { + *lp = (long) *dp; + } + } + return ret; +} + + #if defined(LOCAL_MAIN) static const char * Double(double d) @@ -852,4 +939,4 @@ main(void) } #endif /*LOCAL_MAIN*/ -/*end*/ \ No newline at end of file +/*end*/ diff --git a/libmisc/win32wsa.h b/libmisc/win32wsa.h index 2a2640e8..d0d735c9 100644 --- a/libmisc/win32wsa.h +++ b/libmisc/win32wsa.h @@ -1,7 +1,7 @@ #ifndef GR_WIN32WSA_H_INCLUDED #define GR_WIN32WSA_H_INCLUDED /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: win32wsa.h,v 1.9 2017/01/29 04:33:32 cvsuser Exp $ +/* $Id: win32wsa.h,v 1.10 2022/05/25 15:45:31 cvsuser Exp $ * WSA Error Codes * Reproduced from a number of sources. * @@ -176,9 +176,11 @@ { ETIMEDOUT, // 138 "Connection timed out (POSIX.1)" }, +#if defined(ETXTBSY) { ETXTBSY, // 139 "Text file busy (POSIX.1)" }, +#endif { EWOULDBLOCK, // 140 "Operation would block (POSIX.1)" }, diff --git a/libonigrx/Makefile.in b/libonigrx/Makefile.in index 47e0f454..50ca6c3f 100644 --- a/libonigrx/Makefile.in +++ b/libonigrx/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.11 2021/04/12 14:48:51 cvsuser Exp $ +# $Id: Makefile.in,v 1.13 2022/05/27 03:14:34 cvsuser Exp $ # libonigrx - regular expression makefile. # # -# Copyright (c) 1998 - 2021, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -70,7 +70,12 @@ D_LIB= $(ROOT)/lib@TOOLCHAINEXT@/$(BUILD_TYPE) XFLAGS= CFLAGS= @CFLAGS@ +ifeq ("gcc","@CC@") +CWARN= $(filter-out -Wshadow -Wmissing-prototypes -Wsign-compare -Wimplicit-fallthrough, @CWARN@ $(CWALL)) +CWARN+= -Wno-sign-compare -Wno-implicit-fallthrough +else CWARN= @CWARN@ $(CWALL) +endif CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ LDDEBUG= @LDDEBUG@ @@ -97,9 +102,6 @@ endif endif LDLIBS= -L$(D_LIB) @LIBS@ @LIBMALLOC@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv diff --git a/libonigrx/dllmain.c b/libonigrx/dllmain.c index 37a153fd..9bcf7335 100644 --- a/libonigrx/dllmain.c +++ b/libonigrx/dllmain.c @@ -1,9 +1,9 @@ /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: dllmain.c,v 1.1 2013/06/30 17:02:59 ayoung Exp $ +/* $Id: dllmain.c,v 1.2 2022/05/26 02:11:55 cvsuser Exp $ * * libonigrx - dllmain * - * Copyright (c) 2012-2013 Adam Young. + * Copyright (c) 2012-2022 Adam Young. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,6 +36,7 @@ #include #include +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved); BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) { diff --git a/libteken/teken_subr.h b/libteken/teken_subr.h index d49455fa..278eceaa 100644 --- a/libteken/teken_subr.h +++ b/libteken/teken_subr.h @@ -328,11 +328,11 @@ teken_subr_cursor_position(teken_t *t, unsigned int row, unsigned int col) row = (row - 1) + t->t_originreg.ts_begin; t->t_cursor.tp_row = row < t->t_originreg.ts_end ? - row : t->t_originreg.ts_end - 1; + row : t->t_originreg.ts_end - 1U; col--; t->t_cursor.tp_col = col < t->t_winsize.tp_col ? - col : t->t_winsize.tp_col - 1; + col : t->t_winsize.tp_col - 1U; t->t_stateflags &= ~TS_WRAPPED; teken_funcs_cursor(t); @@ -608,7 +608,7 @@ teken_subr_horizontal_position_absolute(teken_t *t, unsigned int col) col--; t->t_cursor.tp_col = col < t->t_winsize.tp_col ? - col : t->t_winsize.tp_col - 1; + col : t->t_winsize.tp_col - 1U; t->t_stateflags &= ~TS_WRAPPED; teken_funcs_cursor(t); @@ -1327,7 +1327,7 @@ teken_subr_vertical_position_absolute(teken_t *t, unsigned int row) row = (row - 1) + t->t_originreg.ts_begin; t->t_cursor.tp_row = row < t->t_originreg.ts_end ? - row : t->t_originreg.ts_end - 1; + row : t->t_originreg.ts_end - 1U; t->t_stateflags &= ~TS_WRAPPED; teken_funcs_cursor(t); diff --git a/libterm/termcap.c b/libterm/termcap.c index 6720ae53..3f3d9d6b 100644 --- a/libterm/termcap.c +++ b/libterm/termcap.c @@ -39,7 +39,7 @@ * #include */ -#if defined(__linux__) || defined(__CYGWIN32__) +#if defined(__linux__) || defined(__CYGWIN32__) || defined(__MINGW32__) #define _GNU_SOURCE /* XXX: asprintf */ #endif diff --git a/libterm/termcap_private.h b/libterm/termcap_private.h index c6ea9fab..8edafc56 100644 --- a/libterm/termcap_private.h +++ b/libterm/termcap_private.h @@ -71,6 +71,9 @@ int cgetclose(void); int cgetstr(char *buf, const char *cap, char **str); int cgetustr(char *buf, const char *cap, char **str); int cgetnum(char *buf, const char *cap, long *num); + +int t_putws(struct tinfo *info, const wchar_t *cp, int affcnt, void (*outc)(wchar_t, void *), void *args); + /*__END_DECLS*/ #ifndef strlcpy /*__APPLE__*/ diff --git a/libterm/tgetcap.c b/libterm/tgetcap.c index 8748b88a..1ed6bda8 100644 --- a/libterm/tgetcap.c +++ b/libterm/tgetcap.c @@ -232,12 +232,12 @@ getent(char **cap, size_t *len, const char * const *db_array, int fd, * Check if we have a top record from cgetset(). */ if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) { - size_t len = topreclen + BFRAG; - if ((record = malloc (len)) == NULL) { + size_t t_len = topreclen + BFRAG; + if ((record = malloc (t_len)) == NULL) { errno = ENOMEM; return (-2); } - (void)strlcpy(record, toprec, len); + (void)strlcpy(record, toprec, t_len); db_p = db_array; rp = record + topreclen + 1; r_end = rp + BFRAG; diff --git a/libtre/Makefile.in b/libtre/Makefile.in index c66fe89f..4ff0fa9a 100644 --- a/libtre/Makefile.in +++ b/libtre/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.9 2020/06/18 20:35:17 cvsuser Exp $ +# $Id: Makefile.in,v 1.11 2022/06/01 14:21:19 cvsuser Exp $ # libtre - regular expression library makefile. # # -# Copyright (c) 1998 - 2020, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -71,7 +71,11 @@ D_LIB= $(ROOT)/lib@TOOLCHAINEXT@/$(BUILD_TYPE) XFLAGS= CFLAGS= @CFLAGS@ +ifeq ("gcc","@CC@") +CWARN= $(filter-out -Wshadow -Wmissing-prototypes -Wsign-compare -Wno-unused-value, @CWARN@ $(CWALL)) -Wno-sign-compare -Wno-unused-value +else CWARN= @CWARN@ $(CWALL) +endif CDEBUG= @CDEBUG@ CRELEASE= @CRELEASE@ LDDEBUG= @LDDEBUG@ @@ -131,15 +135,18 @@ LIBOBJS=\ DLLOBJS=\ $(subst $(O),.lo,$(LIBOBJS)) -ifeq ("yes","@ISWIN32@") +ifeq ("win32","@build_os@") DLLOBJS+=\ $(D_OBJ)/dllmain.lo endif -ifeq ("mingw32","@build_os@") + +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) DLLOBJS+= $(D_OBJ)/tre_res.o else DLLOBJS+= $(D_OBJ)/tre.res endif +endif OBJS= $(LIBOBJS) $(DLLOBJS) LIBS= $(RELIB) @@ -221,14 +228,11 @@ $(D_OBJ)/%.lo: %.c $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -I$(RESRC) -o $@ -c $< ## -ifeq ("mingw32","@build_os@") $(D_OBJ)/%_res.o: %.rc $(RC) -o $@ $< -else + $(D_OBJ)/%.res: %.rc $(RC) -fo $@ $< -endif - #end diff --git a/libtre/config.h b/libtre/config.h index 80f75aeb..eeaa2c5e 100644 --- a/libtre/config.h +++ b/libtre/config.h @@ -1,18 +1,21 @@ #ifndef LIBTRE_CONFIG_H_INCLUDED #define LIBTRE_CONFIG_H_INCLUDED /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: config.h,v 1.4 2020/06/18 13:16:58 cvsuser Exp $ +/* $Id: config.h,v 1.5 2022/05/26 02:13:06 cvsuser Exp $ * libtre config.h * * */ -#if (defined(_WIN32) || defined(WIN32)) && !defined(__MINGW32__) +#if defined(_WIN32) || defined(WIN32) #include "../libw32/config.h" #include +#if defined(_MSC_VER) || defined(__WATCOMC__) #define inline _inline +#endif + #if defined(_MSC_VER) #define alloca _alloca #if (_MSC_VER < 1900) @@ -26,3 +29,4 @@ #endif /*LIBTRE_CONFIG_H_INCLUDED*/ /*end*/ + diff --git a/libtre/dllmain.c b/libtre/dllmain.c index 8b97b3cb..d4ffa810 100644 --- a/libtre/dllmain.c +++ b/libtre/dllmain.c @@ -1,5 +1,5 @@ /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: dllmain.c,v 1.1 2014/07/08 22:50:18 ayoung Exp $ +/* $Id: dllmain.c,v 1.2 2022/05/26 02:12:21 cvsuser Exp $ * * libtre - dllmain * @@ -36,6 +36,7 @@ #include #include +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved); BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) { diff --git a/libvfs/vfs_archive.c b/libvfs/vfs_archive.c index cf4ac2a2..9d80ecf3 100644 --- a/libvfs/vfs_archive.c +++ b/libvfs/vfs_archive.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_vfs_archive_c,"$Id: vfs_archive.c,v 1.21 2022/03/21 14:27:22 cvsuser Exp $") +__CIDENT_RCSID(gr_vfs_archive_c,"$Id: vfs_archive.c,v 1.22 2022/05/27 18:49:42 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: vfs_archive.c,v 1.21 2022/03/21 14:27:22 cvsuser Exp $ +/* $Id: vfs_archive.c,v 1.22 2022/05/27 18:49:42 cvsuser Exp $ * Virtual file system interface - libarchive driver. * * @@ -102,7 +102,7 @@ vfsarc_mount(struct vfs_mount *vmount, const char *argument) struct archive *a; struct archive_entry *entry; char path[VFS_MAXPATH+1]; - const char *err = NULL; +// const char *err = NULL; int rcode = -1; VFS_TRACE(("vfsarc_mount(%s, %s)\n", vmount->mt_mount, (argument ? argument : ""))) @@ -138,7 +138,7 @@ vfsarc_mount(struct vfs_mount *vmount, const char *argument) } if (ARCHIVE_OK != rcode) { - err = archive_error_string(a); +// err = archive_error_string(a); rcode = -1; break; } @@ -179,7 +179,7 @@ vfsarc_mount(struct vfs_mount *vmount, const char *argument) vfs_tree_destroy(vmount->mt_tree); vmount->mt_tree = NULL; - } else { + } else { /* * configure * RDONLY, implied with current implementation diff --git a/libvfs/vfs_base.c b/libvfs/vfs_base.c index 8babc740..6b2c15c8 100644 --- a/libvfs/vfs_base.c +++ b/libvfs/vfs_base.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_vfs_base_c,"$Id: vfs_base.c,v 1.25 2022/03/21 14:27:22 cvsuser Exp $") +__CIDENT_RCSID(gr_vfs_base_c,"$Id: vfs_base.c,v 1.26 2022/05/26 16:31:34 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: vfs_base.c,v 1.25 2022/03/21 14:27:22 cvsuser Exp $ +/* $Id: vfs_base.c,v 1.26 2022/05/26 16:31:34 cvsuser Exp $ * Virtual file system interface - base implementation. * * @@ -362,7 +362,7 @@ vfsbase_readdir(struct vfs_handle *vhandle) vfsbase_dir_t *dir = (vfsbase_dir_t *)(vhandle + 1); vfs_dirent_t *vdirent = NULL; struct dirent *dent = NULL; - unsigned ismountpoint = 0; /* mountpoint, 0=no, 1=real, 2=virtual*/ +// unsigned ismountpoint = 0; /* mountpoint, 0=no, 1=real, 2=virtual*/ const char *name = NULL; unsigned namlen = 0; @@ -402,7 +402,7 @@ vfsbase_readdir(struct vfs_handle *vhandle) dir->d_cached = dent; /* cache entry for next readdir() */ name = vmount->mt_name; /* mount point name */ namlen = vmount->mt_namlen; - ismountpoint = 1; +// ismountpoint = 1; } } if (name) { diff --git a/libvfs/vfs_stream.c b/libvfs/vfs_stream.c index 515c8dc9..88c09b6d 100644 --- a/libvfs/vfs_stream.c +++ b/libvfs/vfs_stream.c @@ -1,8 +1,8 @@ #include -__CIDENT_RCSID(gr_vfs_stream_c,"$Id: vfs_stream.c,v 1.14 2022/03/21 14:27:23 cvsuser Exp $") +__CIDENT_RCSID(gr_vfs_stream_c,"$Id: vfs_stream.c,v 1.15 2022/05/26 16:31:34 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: vfs_stream.c,v 1.14 2022/03/21 14:27:23 cvsuser Exp $ +/* $Id: vfs_stream.c,v 1.15 2022/05/26 16:31:34 cvsuser Exp $ * Virtual file system interface - streams. * * @@ -137,7 +137,7 @@ vfs_fwrite(vfs_file_t *file, const void *buffer, unsigned size) /* flush cache */ VFS_TRACE2((" flush")) - if ((ret = vfs_write(handle, file->f_buffer, bsize)) != bsize) { + if ((ret = vfs_write(handle, file->f_buffer, bsize)) != (int)bsize) { size = ret; goto done; } @@ -147,7 +147,7 @@ vfs_fwrite(vfs_file_t *file, const void *buffer, unsigned size) /* write extra buffer(s) */ while (t_size > bsize) { VFS_TRACE2((" write(%u/%u)", bsize, t_size)) - if ((ret = vfs_write(handle, t_buffer, bsize)) != bsize) { + if ((ret = vfs_write(handle, t_buffer, bsize)) != (int)bsize) { size = total; goto done; } @@ -205,7 +205,7 @@ vfs_fclose(vfs_file_t *file) if (final) { VFS_TRACE2((" flush")) - if (vfs_write(file->f_handle, file->f_buffer, final) != final) { + if (vfs_write(file->f_handle, file->f_buffer, final) != (int)final) { ret = -1; } } diff --git a/libvfs/vfs_tree.h b/libvfs/vfs_tree.h index 6ab8b23d..b720db09 100644 --- a/libvfs/vfs_tree.h +++ b/libvfs/vfs_tree.h @@ -1,11 +1,11 @@ #ifndef GR_VFS_TREE_H_INCLUDED #define GR_VFS_TREE_H_INCLUDED #include -__CIDENT_RCSID(gr_vfs_tree_h,"$Id: vfs_tree.h,v 1.11 2022/03/21 14:27:23 cvsuser Exp $") +__CIDENT_RCSID(gr_vfs_tree_h,"$Id: vfs_tree.h,v 1.12 2022/05/27 18:49:42 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: vfs_tree.h,v 1.11 2022/03/21 14:27:23 cvsuser Exp $ +/* $Id: vfs_tree.h,v 1.12 2022/05/27 18:49:42 cvsuser Exp $ * Virtual File System Interface -- node tree definitions. * * @@ -81,7 +81,7 @@ struct vfs_treevops { int (* vop_localput)(struct vfs_tree *tree, struct vfs_node *node, int changed); }; -typedef void (* vfs_treevfunc_t)(); /* generic callback interface */ +typedef int (* vfs_treevfunc_t)(); /* generic callback interface */ /* diff --git a/libw32/Makefile.in b/libw32/Makefile.in index 9fe4f4ab..09c5335f 100644 --- a/libw32/Makefile.in +++ b/libw32/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.27 2022/03/21 14:29:39 cvsuser Exp $ +# $Id: Makefile.in,v 1.32 2022/06/11 03:58:36 cvsuser Exp $ # libwin32 makefile. # # @@ -92,11 +92,11 @@ CEXTRA= -DUTF8FILENAMES=1 @DEFS@ ifeq ("$(BUILD_TYPE)","release") CFLAGS+= $(CRELEASE) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXRELEASE) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXRELEASE) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDRELEASE) @LDFLAGS@ else CFLAGS+= $(CDEBUG) $(CWARN) $(CINCLUDE) $(CEXTRA) $(XFLAGS) -CXXFLAGS+= $(CXXDEBUG) $(CWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) +CXXFLAGS+= $(CXXDEBUG) $(CXXWARN) $(CINCLUDE) @CXXINCLUDE@ $(CEXTRA) $(XFLAGS) LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif @@ -139,6 +139,7 @@ CSOURCES=\ w32_gethostname.c \ w32_getopt.c \ w32_getopt_long.c \ + w32_getrlimit.c \ w32_getrusage.c \ w32_getsubopt.c \ w32_getlocale.c \ @@ -156,8 +157,10 @@ CSOURCES=\ w32_mkstemp.c \ w32_mmap.c \ w32_neterr.c \ + w32_pipe.c \ w32_poll.c \ w32_popen.c \ + w32_proctitle.c \ w32_progname.c \ w32_pwd.c \ w32_read.c \ @@ -166,6 +169,7 @@ CSOURCES=\ w32_rename.c \ w32_reparse.c \ w32_rwlock.c \ + w32_setrlimit.c \ w32_select.c \ w32_shell.c \ w32_signal.c \ @@ -199,11 +203,14 @@ LIBOBJS=\ DLLOBJS=\ $(subst $(O),.lo,$(LIBOBJS)) -ifeq ("mingw32","@build_os@") + +ifeq ("win32","@build_os@") +ifeq (mingw,$(findstring mingw,"@TOOLCHAIN@")) DLLOBJS+= $(D_OBJ)/libw32_res.o -else ifeq ("win32","@build_os@") +else DLLOBJS+= $(D_OBJ)/libw32.res endif +endif OBJS= $(LIBOBJS) $(DLLOBJS) LIBS= $(W32LIB) $(W32DLL) diff --git a/libw32/arpa/inet.h b/libw32/arpa/inet.h index 6fdf9404..9491778a 100644 --- a/libw32/arpa/inet.h +++ b/libw32/arpa/inet.h @@ -1,7 +1,7 @@ -#ifndef GR_INET_H_INCLUDED -#define GR_INET_H_INCLUDED +#ifndef LIBW32_ARPA_INET_H_INCLUDED +#define LIBW32_ARPA_INET_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_arpa_inet_h,"$Id: inet.h,v 1.6 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_arpa_inet_h,"$Id: inet.h,v 1.7 2022/05/26 12:18:35 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -34,4 +34,4 @@ __CPRAGMA_ONCE * uint16_t ntohs(uint16_t); */ -#endif /*GR_INET_H_INCLUDED*/ +#endif /*LIBW32_ARPA_INET_H_INCLUDED*/ diff --git a/libw32/err.h b/libw32/err.h index b4f657e0..14075fa3 100644 --- a/libw32/err.h +++ b/libw32/err.h @@ -1,7 +1,7 @@ #ifndef LIBW32_ERR_H_INCLUDED #define LIBW32_ERR_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_err_h,"$Id: err.h,v 1.3 2022/03/21 14:29:39 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_err_h,"$Id: err.h,v 1.4 2022/05/26 12:09:03 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -53,4 +53,4 @@ LIBW32_API void verrx(int eval, const char *fmt, va_list ap); __END_DECLS -#endif /*WIN32_ERR_H_INCLUDED*/ +#endif /*LIBW32_ERR_H_INCLUDED*/ diff --git a/libw32/getopt.h b/libw32/getopt.h index ae1bd780..ce8896ef 100644 --- a/libw32/getopt.h +++ b/libw32/getopt.h @@ -1,7 +1,7 @@ #ifndef LIBW32_GETOPT_H_INCLUDED #define LIBW32_GETOPT_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_getopt_h,"$Id: getopt.h,v 1.9 2022/03/21 14:29:39 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_getopt_h,"$Id: getopt.h,v 1.10 2022/06/11 04:01:44 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -35,11 +35,11 @@ __CPRAGMA_ONCE __BEGIN_DECLS -LIBW32_API extern int opterr; /* if error message should be printed */ -LIBW32_API extern int optind; /* index into parent argv vector */ -LIBW32_API extern int optopt; /* character checked for validity */ -LIBW32_API extern int optreset; /* reset getopt */ -LIBW32_API extern char *optarg; +LIBW32_VAR int opterr; /* if error message should be printed */ +LIBW32_VAR int optind; /* index into parent argv vector */ +LIBW32_VAR int optopt; /* character checked for validity */ +LIBW32_VAR int optreset; /* reset getopt */ +LIBW32_VAR char *optarg; /* * GNU like getopt_long() and BSD4.4 getsubopt()/optreset extensions. diff --git a/libw32/glob.h b/libw32/glob.h index e3188cb9..ef92f510 100644 --- a/libw32/glob.h +++ b/libw32/glob.h @@ -1,7 +1,7 @@ #ifndef GR_GLOB_H_INCLUDED #define GR_GLOB_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_glob_h,"$Id: glob.h,v 1.4 2022/03/21 14:29:39 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_glob_h,"$Id: glob.h,v 1.5 2022/05/26 12:02:41 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -132,6 +132,8 @@ __BEGIN_DECLS LIBW32_API int glob (const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob); LIBW32_API void globfree (glob_t *pglob); +LIBW32_API int glob_pattern_p(const char *pattern, int quote); + __END_DECLS #endif /*GR_GLOB_H_INCLUDED*/ diff --git a/libw32/libw32.h b/libw32/libw32.h index 3dd8a2fe..ec04612b 100644 --- a/libw32/libw32.h +++ b/libw32/libw32.h @@ -35,4 +35,4 @@ #include #include -#endif /*LIBW32_WIN32_H_INCLUDED*/ +#endif /*LIBW32_LIBW32_H_INCLUDED*/ diff --git a/libw32/libw32.rc b/libw32/libw32.rc index d5c47c07..af57230f 100644 --- a/libw32/libw32.rc +++ b/libw32/libw32.rc @@ -66,7 +66,7 @@ BEGIN LIBW32_VERSION "\0" VALUE "Comments", - "For more information visit https://sourceforge.net/p/grief/\0" + "For more information visit https://github.com/adamyg/grief\0" END END BLOCK "VarFileInfo" diff --git a/libw32/msvc/inttypes.h b/libw32/msvc/inttypes.h index 59165ec2..3cc964cc 100644 --- a/libw32/msvc/inttypes.h +++ b/libw32/msvc/inttypes.h @@ -1,5 +1,5 @@ -#ifndef GR_LIBW32_MSVC_INTTYPES_H_INCLUDED -#define GR_LIBW32_MSVC_INTTYPES_H_INCLUDED +#ifndef LIBW32_MSVC_INTTYPES_H_INCLUDED +#define LIBW32_MSVC_INTTYPES_H_INCLUDED /* -*- mode: c; indent-width: 4; -*- */ // ISO C9x compliant inttypes.h for Microsoft Visual Studio @@ -303,4 +303,4 @@ imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) #define wcstoimax _wcstoi64 #define wcstoumax _wcstoui64 -#endif /*GR_LIBW32_MSVC_INTTYPES_H_INCLUDED*/ +#endif /*LIBW32_MSVC_INTTYPES_H_INCLUDED*/ diff --git a/libw32/msvc/stdbool.h b/libw32/msvc/stdbool.h index 8dcdbfef..2622199c 100644 --- a/libw32/msvc/stdbool.h +++ b/libw32/msvc/stdbool.h @@ -1,5 +1,5 @@ -#ifndef GR_LIBW32_MSVC_STDBOOL_H_INCLUDED -#define GR_LIBW32_MSVC_STDBOOL_H_INCLUDED +#ifndef LIBW32_MSVC_STDBOOL_H_INCLUDED +#define LIBW32_MSVC_STDBOOL_H_INCLUDED /* -*- mode: c; indent-width: 4; -*- */ // ISO C9x compliant inttypes.h for Microsoft Visual Studio @@ -32,4 +32,4 @@ typedef int _Bool; #define false 0 #endif -#endif /*GR_LIBW32_MSVC_STDBOOL_H_INCLUDED*/ +#endif /*LIBW32_MSVC_STDBOOL_H_INCLUDED*/ diff --git a/libw32/netinet/in.h b/libw32/netinet/in.h index d2869e24..12aaece4 100644 --- a/libw32/netinet/in.h +++ b/libw32/netinet/in.h @@ -1,7 +1,7 @@ -#ifndef LIBW32_SYS_IN_H_INCLUDED -#define LIBW32_SYS_IN_H_INCLUDED +#ifndef LIBW32_NETINET_IN_H_INCLUDED +#define LIBW32_NETINET_IN_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_netinet_in_h,"$Id: in.h,v 1.8 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_netinet_in_h,"$Id: in.h,v 1.9 2022/05/26 12:18:19 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -26,5 +26,4 @@ __CPRAGMA_ONCE #include #include /* winsock and windows.h guard */ -#endif /*LIBW32_SYS_IN_H_INCLUDED*/ - +#endif /*LIBW32_NETINET_IN_H_INCLUDED*/ diff --git a/libw32/netinet/tcp.h b/libw32/netinet/tcp.h index 077fd37c..ad050dff 100644 --- a/libw32/netinet/tcp.h +++ b/libw32/netinet/tcp.h @@ -1,7 +1,7 @@ -#ifndef LIBW32_SYS_TCP_H_INCLUDED -#define LIBW32_SYS_TCP_H_INCLUDED +#ifndef LIBW32_NETINET_TCP_H_INCLUDED +#define LIBW32_NETINET_TCP_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_netinet_tcp_h,"$Id: tcp.h,v 1.7 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_netinet_tcp_h,"$Id: tcp.h,v 1.8 2022/05/26 12:18:19 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -26,4 +26,4 @@ __CPRAGMA_ONCE #include #include /* winsock and windows.h guard */ -#endif /*LIBW32_SYS_TCP_H_INCLUDED*/ +#endif /*LIBW32_NETINET_TCP_H_INCLUDED*/ diff --git a/libw32/poll.h b/libw32/poll.h index 18c12674..106928cd 100644 --- a/libw32/poll.h +++ b/libw32/poll.h @@ -1,7 +1,7 @@ #ifndef LIBW32_POLL_H_INCLUDED #define LIBW32_POLL_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_poll_h,"$Id: poll.h,v 1.11 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_poll_h,"$Id: poll.h,v 1.16 2022/06/11 04:01:44 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -47,7 +47,8 @@ struct w32_pollfd { #if !defined(POLLIN) #if (defined(_MSC_VER) && (_MSC_VER >= 1400)) || \ - defined(__MINGW32__) || defined(__WATCOMC__) + defined(__WATCOMC__) || \ + (defined(__MINGW32__) && (_WIN32_WINNT < 0x600 || !defined(__MINGW64_VERSION_MAJOR))) /* * POLLRDNORM Data on priority band 0 may be read. * POLLRDBAND Data on priority bands greater than 0 may be read. @@ -62,11 +63,11 @@ struct w32_pollfd { * POLLHUP Device has been disconnected (revents only). * POLLNVAL Invalid fd member (revents only). */ -struct pollfd { - SOCKET fd; - SHORT events; - SHORT revents; -}; +typedef struct pollfd { + SOCKET fd; + SHORT events; + SHORT revents; +} WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD; #define POLLRDNORM 0x0100 #define POLLRDBAND 0x0200 @@ -78,7 +79,14 @@ struct pollfd { #define POLLERR 0x0001 #define POLLHUP 0x0002 #define POLLNVAL 0x0004 -#endif /*_MSC_VER || __MINGW32__ || __WATCOMC__ */ + +#if defined(__MINGW32__) /* missing definitions */ +__BEGIN_DECLS +int WSAAPI WSAPoll(LPWSAPOLLFD fdArray, ULONG fds, INT timeout); +__END_DECLS +#endif + +#endif /*_MSC_VER || ___WATCOMC__ || _MINGW32__*/ #endif /*POLLING*/ __BEGIN_DECLS @@ -86,12 +94,12 @@ __BEGIN_DECLS LIBW32_API int w32_poll_fd(struct pollfd *fds, int cnt, int timeout); LIBW32_API int w32_poll_native(struct pollfd *fds, int cnt, int timeout); -#if defined(WIN32_SOCKET_MAP_FD) +#if defined(LIBW32_SOCKET_MAP_FD) || defined(WIN32_SOCKET_MAP_FD) #if !defined(WIN32_SOCKET_H_INCLUDED) #define poll(a,b,c) w32_poll_fd(a,b,c) #endif -#elif defined(WIN32_SOCKET_MAP_NATIVE) +#elif defined(LIBW32_SOCKET_MAP_NATIVE) || defined(WIN32_SOCKET_MAP_NATIVE) #if !defined(WIN32_SOCKET_H_INCLUDED) #define poll(a,b,c) w32_poll_native(a,b,c) #endif diff --git a/libw32/sys/cdefs.h b/libw32/sys/cdefs.h index 57ec008b..2f063e2f 100644 --- a/libw32/sys/cdefs.h +++ b/libw32/sys/cdefs.h @@ -1,7 +1,7 @@ #ifndef LIBW32_SYS_CDEFS_H_INCLUDED #define LIBW32_SYS_CDEFS_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_sys_cdefs_h,"$Id: cdefs.h,v 1.16 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_sys_cdefs_h,"$Id: cdefs.h,v 1.19 2022/06/13 06:51:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- @@ -34,31 +34,50 @@ __CPRAGMA_ONCE #pragma warning(disable:4115) /* forward reference of struct * */ #endif -/* +/* * Library binding. */ #if !defined(LIBW32_API) +#if defined(LIBW32_DYNAMIC) && defined(LIBW32_STATIC) +#error LIBW32_DYNAMIC and LIBW32_STATIC are mutually exclusive +#endif + #if defined(LIBW32_DYNAMIC) #if defined(LIBW32_LIBRARY) /* library source */ - #define LIBW32_API __declspec(dllexport) + #ifdef __GNUC__ + #define LIBW32_API __attribute__((dllexport)) extern + #elif defined(__WATCOMC__) + #define LIBW32_API extern __declspec(dllexport) + #else + #define LIBW32_API __declspec(dllexport) + #endif #else - #define LIBW32_API __declspec(dllimport) + #ifdef __GNUC__ + #define LIBW32_API __attribute__((dllimport)) extern + #elif defined(__WATCOMC__) + #define LIBW32_API extern __declspec(dllimport) + #else + #define LIBW32_API __declspec(dllimport) + #endif #endif #else /*static*/ #if defined(LIBW32_LIBRARY) /* library source */ #ifndef LIBW32_STATIC /* verify STATIC/DYNAMIC configuration */ - #error LIBW32 static library yet LIB32_STATIC not defined. + #error LIBW32 static library yet LIB32_STATIC not defined. #endif #ifdef _WINDLL /*verify target configuration */ - #error LIBW32 static library yet _WINDLL defined. + #error LIBW32 static library yet _WINDLL defined. #endif #endif #endif #ifndef LIBW32_API #define LIBW32_API +#define LIBW32_VAR extern +#else +#define LIBW32_VAR LIBW32_API #endif #endif //!LIBW32_API @@ -122,7 +141,7 @@ __CPRAGMA_ONCE * remove const cast-away warnings */ #ifndef __DECONST -#define __DECONST(__t,__a) ((__t *)(const void *)(__a)) +#define __DECONST(__t,__a) ((__t)(const void *)(__a)) #endif #ifndef __UNCONST #define __UNCONST(__a) ((void *)(const void *)(__a)) @@ -277,7 +296,7 @@ __CPRAGMA_ONCE #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) #define __unused -#elif __GNUC__ == 2 && __GNUC_MINOR__ >= 7 +#elif __GNUC__ >= 2 || (_GNUC__ == 2 && __GNUC_MINOR__ >= 7) #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) #define __unused __attribute__((__unused__)) diff --git a/libw32/sys/fd_set.h b/libw32/sys/fd_set.h new file mode 100644 index 00000000..a6c908c4 --- /dev/null +++ b/libw32/sys/fd_set.h @@ -0,0 +1,23 @@ +#pragma once + +/* + * + * + * Copyright (c) 2022, Adam Young. + * All rights reserved. + * + * This file is part of the GRIEF Editor. + * + * The GRIEF Editor is free software: you can redistribute it + * and/or modify it under the terms of the GRIEF Editor License. + * + * The GRIEF Editor 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 + * License for more details. + * ==end== + */ + +#include + +/*end*/ diff --git a/libw32/sys/poll.h b/libw32/sys/poll.h index 66f3b304..8c603ecc 100644 --- a/libw32/sys/poll.h +++ b/libw32/sys/poll.h @@ -1,7 +1,7 @@ #ifndef LIBW32_SYS_POLL_H_INCLUDED #define LIBW32_SYS_POLL_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_sys_poll_h,"$Id: poll.h,v 1.2 2022/03/21 14:29:43 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_sys_poll_h,"$Id: poll.h,v 1.3 2022/05/31 16:18:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -21,6 +21,8 @@ __CPRAGMA_ONCE * ==end== */ +#include +#include #include #endif /*LIBW32_SYS_POLL_H_INCLUDED*/ diff --git a/libw32/sys/resource.h b/libw32/sys/resource.h index 71fd70a1..74f11666 100644 --- a/libw32/sys/resource.h +++ b/libw32/sys/resource.h @@ -25,47 +25,94 @@ __CPRAGMA_ONCE #include /* timeval */ -/* getpriority() and setpriority() */ -#define PRIO_PROCESS 1 /* Identifies the who argument as a process ID. */ -#define PRIO_PGRP 2 /* Identifies the who argument as a process group ID. */ -#define PRIO_USER 3 /* Identifies the who argument as a user ID. */ - -/* getrusage() */ -#define RUSAGE_SELF 0 /* Returns information about the current process. */ -#define RUSAGE_CHILDREN 1 /* Returns information about children of the current process. */ +/* + * Priority + */ +#define PRIO_MIN -20 +#define PRIO_MAX 20 + +#define PRIO_PROCESS 1 /* Identifies the who argument as a process ID. */ +#define PRIO_PGRP 2 /* Identifies the who argument as a process group ID. */ +#define PRIO_USER 3 /* Identifies the who argument as a user ID. */ + +/* + * Resource usage + */ +#define RUSAGE_SELF 0 /* Returns information about the current process. */ +#define RUSAGE_CHILDREN 1 /* Returns information about children of the current process. */ #define RUSAGE_THREAD RUSAGE_CHILDREN /* mirror children */ + +/* + * Resource limits + */ +#define RLIMIT_CPU 0 /* cpu time in milliseconds */ +#define RLIMIT_FSIZE 1 /* maximum file size */ +#define RLIMIT_DATA 2 /* data size */ +#define RLIMIT_STACK 3 /* stack size */ +#define RLIMIT_CORE 4 /* core file size */ +#define RLIMIT_RSS 5 /* resident set size */ +#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */ +#define RLIMIT_NPROC 7 /* number of processes */ +#define RLIMIT_NOFILE 8 /* number of open files */ +#define RLIMIT_SBSIZE 9 /* maximum size of all socket buffers */ +#define RLIMIT_AS 10 /* virtual process size (inclusive of mmap) */ +#define RLIMIT_VMEM RLIMIT_AS /* common alias */ +#define RLIMIT_NTHR 11 /* number of threads */ + +__BEGIN_DECLS + struct rusage { - struct timeval ru_utime; /* user CPU time used */ - struct timeval ru_stime; /* system CPU time used */ - long ru_maxrss; /* maximum resident set size */ - long ru_ixrss; /* integral shared memory size */ - long ru_idrss; /* integral unshared data size */ - long ru_isrss; /* integral unshared stack size */ - long ru_minflt; /* page reclaims (soft page faults) */ - long ru_majflt; /* page faults (hard page faults) */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* IPC messages sent */ - long ru_msgrcv; /* IPC messages received */ - long ru_nsignals; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary context switches */ + struct timeval ru_utime; /* user CPU time used */ + struct timeval ru_stime; /* system CPU time used */ + long ru_maxrss; /* maximum resident set size */ + long ru_ixrss; /* integral shared memory size */ + long ru_idrss; /* integral unshared data size */ + long ru_isrss; /* integral unshared stack size */ + long ru_minflt; /* page reclaims (soft page faults) */ + long ru_majflt; /* page faults (hard page faults) */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* IPC messages sent */ + long ru_msgrcv; /* IPC messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary context switches */ +}; + + +#if !defined(HAVE_RLIM_T) +#if defined(_WIN64) +typedef unsigned long long rlim_t; +#define RLIM_INFINITY (rlim_t)-1LL /* no limit */ +#else +typedef unsigned long rlim_t; +#define RLIM_INFINITY (rlim_t)-1L /* no limit */ +#endif +#define RLIM_SAVED_MAX RLIM_INFINITY /* unrepresentable hard limit */ +#define RLIM_SAVED_CURRLIM_INFINITY /* unrepresentable soft limit */ +#define HAVE_RLIM_T +#endif + +struct rlimit { + rlim_t rlim_cur; /* current (soft) limit */ + rlim_t rlim_max; /* maximum value for rlim_cur */ }; + /* Not all fields are completed; unmaintained fields are set to zero. The unmaintained fields are provided for compatibility with other systems, and because they may one day be supported. */ -__BEGIN_DECLS - // LIBW32_API int getpriority(int, id_t); -// LIBW32_API int getrlimit(int, struct rlimit *); -LIBW32_API int getrusage(int, struct rusage *); // LIBW32_API int setpriority(int, id_t, int); -// LIBW32_API int setrlimit(int, const struct rlimit *); + +LIBW32_API int getrlimit(int, struct rlimit *); +LIBW32_API int setrlimit(int, const struct rlimit *); + +LIBW32_API int getrusage(int, struct rusage *); __END_DECLS -#endif /*LIBW32_SYS_RESOURCE_H_INCLUDED*/ +#endif /*LIBW32_SYS_RESOURCE_H_INCLUDED*/ diff --git a/libw32/sys/rwlock.h b/libw32/sys/rwlock.h index a27485ff..47cef7af 100644 --- a/libw32/sys/rwlock.h +++ b/libw32/sys/rwlock.h @@ -1,7 +1,7 @@ #ifndef GR_SYS_RWLOCK_H_INCLUDED #define GR_SYS_RWLOCK_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_sys_rwlock_h,"$Id: rwlock.h,v 1.9 2022/03/21 14:29:43 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_sys_rwlock_h,"$Id: rwlock.h,v 1.12 2022/06/11 04:00:16 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -39,9 +39,10 @@ LIBW32_API void rwlock_rdlock(struct rwlock *rw); LIBW32_API void rwlock_wrlock(struct rwlock *rw); LIBW32_API void rwlock_rdunlock(struct rwlock *rw); LIBW32_API void rwlock_wrunlock(struct rwlock *rw); +LIBW32_API void rwlock_unlock(struct rwlock *rw); +LIBW32_API int rwlock_status(struct rwlock *rw); __END_DECLS #endif /*GR_SYS_RWLOCK_H_INCLUDED*/ - diff --git a/libw32/sys/select.h b/libw32/sys/select.h index 542bd978..f5e62d16 100644 --- a/libw32/sys/select.h +++ b/libw32/sys/select.h @@ -1,7 +1,7 @@ #ifndef LIBW32_SYS_SELECT_H_INCLUDED #define LIBW32_SYS_SELECT_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_sys_select_h,"$Id: select.h,v 1.8 2022/03/21 14:29:43 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_sys_select_h,"$Id: select.h,v 1.9 2022/06/11 04:00:16 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -21,6 +21,8 @@ __CPRAGMA_ONCE * ==end== */ -#include /* winsock etc */ +#if !defined(_WINSOCK2_H) /* MINGW32 guard */ +#include /* winsock and windows.h guard */ +#endif #endif /*LIBW32_SYS_SELECT_H_INCLUDED*/ diff --git a/libw32/sys/socket.h b/libw32/sys/socket.h index 2faaa474..c61094f7 100644 --- a/libw32/sys/socket.h +++ b/libw32/sys/socket.h @@ -1,7 +1,7 @@ #ifndef LIBW32_SYS_SOCKET_H_INCLUDED #define LIBW32_SYS_SOCKET_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_sys_socket_h,"$Id: socket.h,v 1.15 2022/03/21 14:29:43 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_sys_socket_h,"$Id: socket.h,v 1.23 2022/06/15 12:11:07 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -23,14 +23,17 @@ __CPRAGMA_ONCE * ==end== */ +#if !defined(_WINSOCK2_H) /* MINGW32 guard */ #include /* winsock and windows.h guard */ +#endif #include #include +#include __BEGIN_DECLS -LIBW32_API extern int w32_h_errno; +LIBW32_VAR int w32_h_errno; struct pollfd; @@ -87,8 +90,13 @@ LIBW32_API int w32_recvfrom_fd(int fd, char *buf, int len, int flags, s LIBW32_API int w32_recvfrom_native(int fd, char *buf, int len, int flags, struct sockaddr *from_addr, int *fromlen); LIBW32_API int w32_shutdown_fd(int fd, int flags); LIBW32_API int w32_shutdown_native(int fd, int flags); -LIBW32_API int w32_sockblockingmode_fd(int fd, int enabled); -LIBW32_API int w32_sockblockingmode_native(int fd, int enabled); + +LIBW32_API int w32_socknonblockingio_fd(int fd, int enabled); +LIBW32_API int w32_socknonblockingio_native(int fd, int enabled); + +LIBW32_API int w32_sockinheritable_fd(int fd, int enabled); +LIBW32_API int w32_sockinheritable_native(int fd, int enabled); + LIBW32_API int w32_sockwrite_fd(int fd, const void *buffer, unsigned int cnt); LIBW32_API int w32_sockwrite_native(int fd, const void *buffer, unsigned int cnt); LIBW32_API int w32_sockread_fd(int fd, void *buf, unsigned int nbyte); @@ -173,7 +181,7 @@ LIBW32_API int w32_poll_native(struct pollfd *fds, int cnt, int timeout #define accept(a,b,c) w32_accept_fd(a,b,c) #define poll(a,b,c) w32_poll_fd(a,b,c) #define send(a,b,c,d) w32_send_fd(a,b,c,d) -#define sendto(a,b,c,d,e) w32_sendto_fd(a,b,c,d,e) +#define sendto(a,b,c,d,e,f w32_sendto_fd(a,b,c,d,e,f) #define sendmsg(a,b,c) w32_sendmsg_fd(a,b,c) #define recv(a,b,c,d) w32_recv_fd(a,b,c,d) #define recvfrom(a,b,c,d,e,f) w32_recvfrom_fd(a,b,c,d,e,f) @@ -182,7 +190,8 @@ LIBW32_API int w32_poll_native(struct pollfd *fds, int cnt, int timeout #define poll(a,b,c) w32_poll_fd(a,b,c) #endif -#define sockblockingmode(a,b) w32_sockblockingmode_fd(a,b) +#define socknonblockingio(a,b) w32_socknonblockingio_fd(a,b) +#define sockinheritable(a,b) w32_sockinheritable_fd(a,b) #define sockread(a,b,c) w32_sockread_fd(a,b,c) #define sockwrite(a,b,c) w32_sockwrite_fd(a,b,c) #define sockclose(a) w32_sockclose_fd(a) @@ -205,7 +214,7 @@ LIBW32_API int w32_poll_native(struct pollfd *fds, int cnt, int timeout #define accept(a,b,c) w32_accept_native(a,b,c) #define poll(a,b,c) w32_poll_native(a,b,c) #define send(a,b,c,d) w32_send_native(a,b,c,d) -#define sendto(a,b,c,d,e) w32_sendto_native(a,b,c,d,e) +#define sendto(a,b,c,d,e,f) w32_sendto_native(a,b,c,d,e,f) #define sendmsg(a,b,c) w32_sendmsg_native(a,b,c) #define recv(a,b,c,d) w32_recv_native(a,b,c,d) #define recvfrom(a,b,c,d,e,f) w32_recvfrom_native(a,b,c,d,e,f) @@ -214,7 +223,8 @@ LIBW32_API int w32_poll_native(struct pollfd *fds, int cnt, int timeout #define poll(a,b,c) w32_poll_native(a,b,c) #endif /*SOCKET_MAPCALLS*/ -#define sockblockingmode(a,b) w32_sockblockingmode_native(a,b) +#define socknonblockingio(a,b) w32_socknonblockingio_native(a,b) +#define sockinheritable(a,b) w32_sockinheritable_native(a,b) #define sockread(a,b,c) w32_sockread_native(a,b,c) #define sockwrite(a,b,c) w32_sockwrite_native(a,b,c) #define sockclose(a) w32_sockclose_native(a) @@ -222,8 +232,46 @@ LIBW32_API int w32_poll_native(struct pollfd *fds, int cnt, int timeout #define socketpair(a,b,c,d) w32_socketpair_native(a,b,c,d) #endif /*WIN32_SOCKET_MAP_FD|NATIVE*/ - + +LIBW32_API int w32_select(int, fd_set *, fd_set *, fd_set *, const struct timeval *timeout); + __END_DECLS + +/* missing definitions */ -#endif /*LIBW32_SYS_SOCKET_H_INCLUDED*/ +#if defined(_MSC_VER) || \ + defined(__MINGW64_VERSION_MAJOR) /* MingGW-w64/32 */ +#include /* if_nametoindex() */ +#endif + +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +INT WSAAPI inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf); +PCSTR WSAAPI inet_ntop(INT Family, const VOID *pAddr, PSTR pStringBuf, size_t StringBufSize); + +ULONG WINAPI if_nametoindex(PCSTR InterfaceName); +typedef struct addrinfo ADDRINFOA, *PADDRINFOA; + //see: w32_sockbase.c + //INT WSAAPI getaddrinfo(PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA *pHints, PADDRINFOA *ppResult); +VOID WSAAPI freeaddrinfo(PADDRINFOA pAddrInfo); +#endif + +#if defined(__WATCOMC__) || \ + (defined(_MSC_VER) && (_MSC_VER <= 1600 /*2010*/)) +#if !defined(HAVE_TIMESPEC) /* missing definitions */ +#define HAVE_TIMESPEC +#endif +#if !defined(_TIMESPEC_DEFINED) && (__WATCOMC__ < 1300) +#define _TIMESPEC_DEFINED /* OWC1.9=1290, OWC2.0=1300 */ +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#else +#include +#endif /*TIMESPEC_STRUCT_T*/ + +ULONG WINAPI if_nametoindex(PCSTR InterfaceName); +#endif + +#endif /*LIBW32_SYS_SOCKET_H_INCLUDED*/ diff --git a/libw32/sys/time.h b/libw32/sys/time.h index 37c781d9..1bad7983 100644 --- a/libw32/sys/time.h +++ b/libw32/sys/time.h @@ -1,7 +1,7 @@ -#ifndef LIBW32_SYS_TIME_H -#define LIBW32_SYS_TIME_H +#ifndef LIBW32_SYS_TIME_H_INCLUDED +#define LIBW32_SYS_TIME_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_sys_time_h,"$Id: time.h,v 1.14 2022/03/21 14:29:43 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_sys_time_h,"$Id: time.h,v 1.20 2022/06/01 12:46:55 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -24,11 +24,15 @@ __CPRAGMA_ONCE */ #include +#if defined(__MINGW32__) +#include_next /* struct timeval */ +#else +#include /* struct timeval */ +#endif #include /* suseconds_t */ -#include #include -#if defined(NEED_TIMEVAL) +#if defined(NEED_TIMEVAL) /*|| defined(__MINGW64_VERSION_MAJOR)*/ #if !defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_) // // The header shall define the timeval structure that includes at @@ -39,12 +43,15 @@ __CPRAGMA_ONCE // // yet current winsock definitions are as follows. // +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED struct timeval { long tv_sec; /* seconds */ long tv_usec; /* and microseconds */ }; -#endif -#endif +#endif //_TIMEVAL_DEFINED +#endif //_WINSOCK2API_ +#endif //NEED_TIMEVAL struct w32_timeval { time_t tv_sec; /* seconds */ @@ -56,13 +63,6 @@ struct itimerval { struct timeval it_value; /* current value */ }; -/* - - struct timezone { - - int tz_minuteswest; // minutes west of Greenwich - - int tz_dsttime; // type of dst correction - - }; - */ - #if !defined(TIMEVAL_TO_TIMESPEC) #define TIMEVAL_TO_TIMESPEC(tv, ts) { \ (ts)->tv_sec = (tv)->tv_sec; \ @@ -122,8 +122,8 @@ LIBW32_API int getitimer(int which, struct itimerval *value); LIBW32_API int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue); #if defined(_WINSOCKAPI_) || defined(_WINSOCK2API_) -LIBW32_API int w32_gettimeofday(struct timeval *, /*struct timezone*/ void *); -LIBW32_API int w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *timeout); +LIBW32_API int w32_gettimeofday(struct timeval *tv, struct timezone *tz); +LIBW32_API int w32_select(int, fd_set *, fd_set *, fd_set *, const struct timeval *timeout); #endif #if defined(NEED_TIMEVAL) || \ @@ -146,5 +146,4 @@ LIBW32_API struct tm * gmtime_r(const time_t *ctm, struct tm *res); __END_DECLS -#endif /*LIBW32_SYS_TIME_H*/ - +#endif /*LIBW32_SYS_TIME_H_INCLUDED*/ diff --git a/libw32/sys/tree.h b/libw32/sys/tree.h new file mode 100644 index 00000000..0d25ac0f --- /dev/null +++ b/libw32/sys/tree.h @@ -0,0 +1,1026 @@ +/* $OpenBSD: tree.h,v 1.30 2020/10/10 18:03:41 otto Exp $ */ +/* + * Copyright 2002 Niels Provos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_TREE_H_ +#define _SYS_TREE_H_ + +#include + //#include + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define SPLAY_INITIALIZER(root) \ + { NULL } + +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (0) + +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) + +/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (0) + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (0) + +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (0) + +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (0) + +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (0) + +/* Generates prototypes and inline functions */ + +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __unused __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __unused __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __unused __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root))) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 + +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) + +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define RB_INITIALIZER(root) \ + { NULL } + +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (0) + +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) + +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ +} while (0) + +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ +} while (0) + +#ifndef RB_AUGMENT +#define RB_AUGMENT(x) do {} while (0) +#endif + +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field))) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (0) + +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field))) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (0) + +#undef __RB_CONST +#if defined(__cplusplus) +#define __RB_CONST const +#else +#define __RB_CONST +#endif + +/* Generates prototypes and inline functions */ +#define RB_PROTOTYPE(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp,,__RB_CONST) + +#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, /*__attribute__((__unused__))*/ static,) + +#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr, attr2) \ +attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ +attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ +attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ +attr struct type *name##_RB_INSERT(struct name *, struct type *); \ +attr struct type *name##_RB_FIND(struct name *, struct type *) attr2; \ +attr struct type *name##_RB_NFIND(struct name *, struct type *) attr2; \ +attr struct type *name##_RB_NEXT(struct type *); \ +attr struct type *name##_RB_PREV(struct type *); \ +attr struct type *name##_RB_MINMAX(struct name *, int); \ + \ + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define RB_GENERATE(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp,,__RB_CONST) + +#define RB_GENERATE_STATIC(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp, /*__attribute__((__unused__))*/ static,) + +#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr, attr2) \ +attr void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} \ + \ +attr void \ +name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)))\ + RB_COLOR(oleft, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)))\ + RB_COLOR(oright, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} \ + \ +attr struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field))) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old)\ + RB_LEFT(RB_PARENT(old, field), field) = elm;\ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm;\ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field))); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} \ + \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_RB_FIND(attr2 struct name *head, struct type *elm) attr2 \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} \ + \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_RB_NFIND(attr2 struct name *head, struct type *elm) attr2 \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = RB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_PREV(struct type *elm) \ +{ \ + if (RB_LEFT(elm, field)) { \ + elm = RB_LEFT(elm, field); \ + while (RB_RIGHT(elm, field)) \ + elm = RB_RIGHT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +attr struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define RB_NEGINF -1 +#define RB_INF 1 + +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_PREV(name, x, y) name##_RB_PREV(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) + +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#define RB_FOREACH_SAFE(x, name, head, y) \ + for ((x) = RB_MIN(name, head); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) + +#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = RB_MAX(name, head); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \ + (x) = (y)) + + +/* + * Copyright (c) 2016 David Gwynne + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +struct rb_type { + int (*t_compare)(const void *, const void *); + void (*t_augment)(void *); + unsigned int t_offset; /* offset of rb_entry in type */ +}; + +struct rb_tree { + struct rb_entry *rbt_root; +}; + +struct rb_entry { + struct rb_entry *rbt_parent; + struct rb_entry *rbt_left; + struct rb_entry *rbt_right; + unsigned int rbt_color; +}; + +#define RBT_HEAD(_name, _type) \ +struct _name { \ + struct rb_tree rbh_root; \ +} + +#define RBT_ENTRY(_type) struct rb_entry + +static inline void +_rb_init(struct rb_tree *rbt) +{ +#if defined(__cplusplus) + rbt->rbt_root = nullptr; +#else + rbt->rbt_root = NULL; +#endif +} + +static inline int +_rb_empty(struct rb_tree *rbt) +{ +#if defined(__cplusplus) + return (rbt->rbt_root == nullptr); +#else + return (rbt->rbt_root == NULL); +#endif +} + +void *_rb_insert(const struct rb_type *, struct rb_tree *, void *); +void *_rb_remove(const struct rb_type *, struct rb_tree *, void *); +void *_rb_find(const struct rb_type *, struct rb_tree *, const void *); +void *_rb_nfind(const struct rb_type *, struct rb_tree *, const void *); +void *_rb_root(const struct rb_type *, struct rb_tree *); +void *_rb_min(const struct rb_type *, struct rb_tree *); +void *_rb_max(const struct rb_type *, struct rb_tree *); +void *_rb_next(const struct rb_type *, void *); +void *_rb_prev(const struct rb_type *, void *); +void *_rb_left(const struct rb_type *, void *); +void *_rb_right(const struct rb_type *, void *); +void *_rb_parent(const struct rb_type *, void *); +void _rb_set_left(const struct rb_type *, void *, void *); +void _rb_set_right(const struct rb_type *, void *, void *); +void _rb_set_parent(const struct rb_type *, void *, void *); +void _rb_poison(const struct rb_type *, void *, unsigned long); +int _rb_check(const struct rb_type *, void *, unsigned long); + +#define RBT_INITIALIZER(_head) { { NULL } } + +#define RBT_PROTOTYPE(_name, _type, _field, _cmp) \ +extern const struct rb_type *const _name##_RBT_TYPE; \ + \ +__unused static inline void \ +_name##_RBT_INIT(struct _name *head) \ +{ \ + _rb_init(&head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_INSERT(struct _name *head, struct _type *elm) \ +{ \ + return _rb_insert(_name##_RBT_TYPE, &head->rbh_root, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_REMOVE(struct _name *head, struct _type *elm) \ +{ \ + return _rb_remove(_name##_RBT_TYPE, &head->rbh_root, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_FIND(struct _name *head, const struct _type *key) \ +{ \ + return _rb_find(_name##_RBT_TYPE, &head->rbh_root, key); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_NFIND(struct _name *head, const struct _type *key) \ +{ \ + return _rb_nfind(_name##_RBT_TYPE, &head->rbh_root, key); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_ROOT(struct _name *head) \ +{ \ + return _rb_root(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline int \ +_name##_RBT_EMPTY(struct _name *head) \ +{ \ + return _rb_empty(&head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_MIN(struct _name *head) \ +{ \ + return _rb_min(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_MAX(struct _name *head) \ +{ \ + return _rb_max(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_NEXT(struct _type *elm) \ +{ \ + return _rb_next(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_PREV(struct _type *elm) \ +{ \ + return _rb_prev(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_LEFT(struct _type *elm) \ +{ \ + return _rb_left(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_RIGHT(struct _type *elm) \ +{ \ + return _rb_right(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_PARENT(struct _type *elm) \ +{ \ + return _rb_parent(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_LEFT(struct _type *elm, struct _type *left) \ +{ \ + _rb_set_left(_name##_RBT_TYPE, elm, left); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_RIGHT(struct _type *elm, struct _type *right) \ +{ \ + _rb_set_right(_name##_RBT_TYPE, elm, right); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_PARENT(struct _type *elm, struct _type *parent) \ +{ \ + _rb_set_parent(_name##_RBT_TYPE, elm, parent); \ +} \ + \ +__unused static inline void \ +_name##_RBT_POISON(struct _type *elm, unsigned long poison) \ +{ \ + _rb_poison(_name##_RBT_TYPE, elm, poison); \ +} \ + \ +__unused static inline int \ +_name##_RBT_CHECK(struct _type *elm, unsigned long poison) \ +{ \ + return _rb_check(_name##_RBT_TYPE, elm, poison); \ +} + +#define RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _aug) \ +static int \ +_name##_RBT_COMPARE(const void *lptr, const void *rptr) \ +{ \ + const struct _type *l = lptr, *r = rptr; \ + return _cmp(l, r); \ +} \ +static const struct rb_type _name##_RBT_INFO = { \ + _name##_RBT_COMPARE, \ + _aug, \ + offsetof(struct _type, _field), \ +}; \ +const struct rb_type *const _name##_RBT_TYPE = &_name##_RBT_INFO + +#define RBT_GENERATE_AUGMENT(_name, _type, _field, _cmp, _aug) \ +static void \ +_name##_RBT_AUGMENT(void *ptr) \ +{ \ + struct _type *p = ptr; \ + return _aug(p); \ +} \ +RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _name##_RBT_AUGMENT) + +#define RBT_GENERATE(_name, _type, _field, _cmp) \ + RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, NULL) + +#define RBT_INIT(_name, _head) _name##_RBT_INIT(_head) +#define RBT_INSERT(_name, _head, _elm) _name##_RBT_INSERT(_head, _elm) +#define RBT_REMOVE(_name, _head, _elm) _name##_RBT_REMOVE(_head, _elm) +#define RBT_FIND(_name, _head, _key) _name##_RBT_FIND(_head, _key) +#define RBT_NFIND(_name, _head, _key) _name##_RBT_NFIND(_head, _key) +#define RBT_ROOT(_name, _head) _name##_RBT_ROOT(_head) +#define RBT_EMPTY(_name, _head) _name##_RBT_EMPTY(_head) +#define RBT_MIN(_name, _head) _name##_RBT_MIN(_head) +#define RBT_MAX(_name, _head) _name##_RBT_MAX(_head) +#define RBT_NEXT(_name, _elm) _name##_RBT_NEXT(_elm) +#define RBT_PREV(_name, _elm) _name##_RBT_PREV(_elm) +#define RBT_LEFT(_name, _elm) _name##_RBT_LEFT(_elm) +#define RBT_RIGHT(_name, _elm) _name##_RBT_RIGHT(_elm) +#define RBT_PARENT(_name, _elm) _name##_RBT_PARENT(_elm) +#define RBT_SET_LEFT(_name, _elm, _l) _name##_RBT_SET_LEFT(_elm, _l) +#define RBT_SET_RIGHT(_name, _elm, _r) _name##_RBT_SET_RIGHT(_elm, _r) +#define RBT_SET_PARENT(_name, _elm, _p) _name##_RBT_SET_PARENT(_elm, _p) +#define RBT_POISON(_name, _elm, _p) _name##_RBT_POISON(_elm, _p) +#define RBT_CHECK(_name, _elm, _p) _name##_RBT_CHECK(_elm, _p) + +#define RBT_FOREACH(_e, _name, _head) \ + for ((_e) = RBT_MIN(_name, (_head)); \ + (_e) != NULL; \ + (_e) = RBT_NEXT(_name, (_e))) + +#define RBT_FOREACH_SAFE(_e, _name, _head, _n) \ + for ((_e) = RBT_MIN(_name, (_head)); \ + (_e) != NULL && ((_n) = RBT_NEXT(_name, (_e)), 1); \ + (_e) = (_n)) + +#define RBT_FOREACH_REVERSE(_e, _name, _head) \ + for ((_e) = RBT_MAX(_name, (_head)); \ + (_e) != NULL; \ + (_e) = RBT_PREV(_name, (_e))) + +#define RBT_FOREACH_REVERSE_SAFE(_e, _name, _head, _n) \ + for ((_e) = RBT_MAX(_name, (_head)); \ + (_e) != NULL && ((_n) = RBT_PREV(_name, (_e)), 1); \ + (_e) = (_n)) + +#endif /* _SYS_TREE_H_ */ diff --git a/libw32/sys/uio.h b/libw32/sys/uio.h index 99d0a63a..08214e2d 100644 --- a/libw32/sys/uio.h +++ b/libw32/sys/uio.h @@ -1,12 +1,12 @@ #ifndef LIBW32_SYS_UIO_H_INCLUDED #define LIBW32_SYS_UIO_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_sys_uio_h,"$Id: uio.h,v 1.10 2022/03/21 14:29:43 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_sys_uio_h,"$Id: uio.h,v 1.13 2022/05/31 16:18:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ /* - * win32 sys/uio.h + * win32 * * Copyright (c) 1998 - 2022, Adam Young. * All rights reserved. @@ -29,7 +29,11 @@ __CPRAGMA_ONCE #include /* INT_MAX */ #define IOV_MAX 64 +#if !defined(__MINGW32__) +#if !defined(SSIZE_MAX) #define SSIZE_MAX INT_MAX +#endif +#endif __BEGIN_DECLS @@ -45,6 +49,7 @@ LIBW32_API int /*ssize_t*/ writev(int, const struct iovec *, int); // LIBW32_API ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset); // LIBW32_API ssize_t preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); // LIBW32_API ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); + __END_DECLS -#endif /*LIBW32_SYS_UIO_H_INCLUDED */ +#endif /*LIBW32_SYS_UIO_H_INCLUDED*/ diff --git a/libw32/sys/utypes.h b/libw32/sys/utypes.h index a2fa4e27..bf701323 100644 --- a/libw32/sys/utypes.h +++ b/libw32/sys/utypes.h @@ -1,7 +1,7 @@ #ifndef LIBW32_SYS_UTYPES_H_INCLUDED #define LIBW32_SYS_UTYPES_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_sys_utypes_h,"$Id: utypes.h,v 1.30 2022/03/21 14:29:43 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_sys_utypes_h,"$Id: utypes.h,v 1.37 2022/06/13 06:51:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -45,17 +45,17 @@ __CPRAGMA_ONCE #define _UNIXTYPES_T_DEFINED #if defined(_BSD_SOURCE) #if !defined(_BSDTYPES_DEFINED) -typedef unsigned char u_char; /* BSD compatibility */ -typedef unsigned short u_short; -typedef unsigned int u_int; -typedef unsigned long u_long; +typedef unsigned char u_char; /* BSD compatibility */ +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; #define _BSDTYPES_DEFINED /* winsock[2].h and others */ #endif /*_BSDTYPES_DEFINED*/ #endif /*_BSD_SOURCE*/ -typedef unsigned char uchar; /* Sys V compatibility */ -typedef unsigned short ushort; -typedef unsigned int uint; -typedef unsigned long ulong; +typedef unsigned char uchar; /* Sys V compatibility */ +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong; #endif /* [u]int8_t, [u]int16_t, [u]int32_t optional [u]int64_t */ @@ -110,19 +110,43 @@ typedef unsigned long fixpt_t; /* fixed point number */ #endif /*BSD_SOURCE*/ /* system identifiers */ +/* Note: MSDN - Interprocess Communication Between 32-bit and 64-bit Applications + * 64-bit versions of Windows use 32-bit handles for interoperability. + * When sharing a handle between 32-bit and 64-bit applications, only the lower 32 bits are significant, + * so it is safe to truncate the handle (when passing it from 64-bit to 32-bit) or sign-extend the handle (when passing it from 32-bit to 64-bit). + * Handles that can be shared include handles to user objects such as windows (HWND), handles to GDI objects such as pens and brushes (HBRUSH and HPEN), + * and handles to named objects such as mutexes, semaphores, and file handles. + */ #if !defined(HAVE_PID_T) -#if !defined(__WATCOMC__) || \ - (defined(__WATCOMC__) && (__WATCOMC__ < 1300 /*owc20*/)) +#if defined(_MSC_VER) || \ + (defined(__WATCOMC__) && (__WATCOMC__ < 1300 /*owc20*/)) || \ + (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) typedef int pid_t; /* process identifier */ #endif -#define HAVE_PID_T +#define HAVE_PID_T 1 +#endif + +#if !defined(__MINGW32__) || \ + (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) +#if !defined(USECONDS_T) +#define USECONDS_T 1 +#ifdef _WIN64 +typedef unsigned long long useconds_t; +#else +typedef unsigned long useconds_t; #endif +#endif /*USECONDS_T*/ +#endif /*__MINHW32__*/ -typedef long suseconds_t; /* sys/types.h */ +#ifdef _WIN64 +typedef long long suseconds_t; +#else +typedef long suseconds_t; +#endif #if defined(_MSC_VER) && \ - !defined(__WATCOMC__) - /* check for !WATCOMC, at times we masquerade WC as MSVC */ + !defined(__WATCOMC__) + /* check for !WATCOMC, at times we masquerade WC as MSVC */ #if !defined(uid_t) && !defined(gid_t) typedef int uid_t; typedef int gid_t; @@ -130,10 +154,17 @@ typedef int gid_t; #if !defined(id_t) typedef int id_t; /* used as a general identifier; can contain least a pid_t, uid_t, or gid_t. */ #endif -#if !defined(ssize_t) -typedef int ssize_t; -#define ssize_t ssize_t /* see libssh */ + +#if !defined(ssize_t) && !defined(_SSIZE_T_DEFINED) +#define _SSIZE_T_DEFINED_ 1 +#ifdef _WIN64 +typedef __int64 ssize_t; +#else +typedef signed ssize_t; #endif +#define ssize_t ssize_t +#endif + #if !defined(mode_t) typedef unsigned short mode_t; #define mode_t mode_t @@ -144,8 +175,12 @@ typedef unsigned short mode_t; typedef int uid_t; typedef int gid_t; #endif +#if !defined(id_t) +typedef int id_t; /* used as a general identifier; can contain least a pid_t, uid_t, or gid_t. */ #endif +#endif /*_MSC_VER || __MINGW32__*/ + #if !defined(HAVE_NLINK_T) #if !defined(__WATCOMC__) || \ (defined(__WATCOMC__) && (__WATCOMC__ < 1300 /*owc20*/)) @@ -166,3 +201,4 @@ typedef unsigned nlink_t; /* link count */ #endif #endif /*LIBW32_SYS_UTYPES_H_INCLUDED*/ + diff --git a/libw32/sysexits.h b/libw32/sysexits.h new file mode 100644 index 00000000..c9e26fe8 --- /dev/null +++ b/libw32/sysexits.h @@ -0,0 +1,109 @@ +/* + * ==noguard== + * Copyright (c) 1987, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)sysexits.h 8.1 (Berkeley) 6/2/93 + */ +#ifndef _SYSEXITS_H +#define _SYSEXITS_H 1 +/* + * SYSEXITS.H -- Exit status codes for system programs. + * + * This include file attempts to categorize possible error + * exit statuses for system programs, notably delivermail + * and the Berkeley network. + * + * Error numbers begin at EX__BASE to reduce the possibility of + * clashing with other exit statuses that random programs may + * already return. The meaning of the codes is approximately + * as follows: + * + * EX_USAGE -- The command was used incorrectly, e.g., with + * the wrong number of arguments, a bad flag, a bad + * syntax in a parameter, or whatever. + * EX_DATAERR -- The input data was incorrect in some way. + * This should only be used for user's data & not + * system files. + * EX_NOINPUT -- An input file (not a system file) did not + * exist or was not readable. This could also include + * errors like "No message" to a mailer (if it cared + * to catch it). + * EX_NOUSER -- The user specified did not exist. This might + * be used for mail addresses or remote logins. + * EX_NOHOST -- The host specified did not exist. This is used + * in mail addresses or network requests. + * EX_UNAVAILABLE -- A service is unavailable. This can occur + * if a support program or file does not exist. This + * can also be used as a catchall message when something + * you wanted to do doesn't work, but you don't know + * why. + * EX_SOFTWARE -- An internal software error has been detected. + * This should be limited to non-operating system related + * errors as possible. + * EX_OSERR -- An operating system error has been detected. + * This is intended to be used for such things as "cannot + * fork", "cannot create pipe", or the like. It includes + * things like getuid returning a user that does not + * exist in the passwd file. + * EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp, + * etc.) does not exist, cannot be opened, or has some + * sort of error (e.g., syntax error). + * EX_CANTCREAT -- A (user specified) output file cannot be + * created. + * EX_IOERR -- An error occurred while doing I/O on some file. + * EX_TEMPFAIL -- temporary failure, indicating something that + * is not really an error. In sendmail, this means + * that a mailer (e.g.) could not create a connection, + * and the request should be reattempted later. + * EX_PROTOCOL -- the remote system returned something that + * was "not possible" during a protocol exchange. + * EX_NOPERM -- You did not have sufficient permission to + * perform the operation. This is not intended for + * file system problems, which should use NOINPUT or + * CANTCREAT, but rather for higher level permissions. + */ +#define EX_OK 0 /* successful termination */ +#define EX__BASE 64 /* base value for error messages */ +#define EX_USAGE 64 /* command line usage error */ +#define EX_DATAERR 65 /* data format error */ +#define EX_NOINPUT 66 /* cannot open input */ +#define EX_NOUSER 67 /* addressee unknown */ +#define EX_NOHOST 68 /* host name unknown */ +#define EX_UNAVAILABLE 69 /* service unavailable */ +#define EX_SOFTWARE 70 /* internal software error */ +#define EX_OSERR 71 /* system error (e.g., can't fork) */ +#define EX_OSFILE 72 /* critical OS file missing */ +#define EX_CANTCREAT 73 /* can't create (user) output file */ +#define EX_IOERR 74 /* input/output error */ +#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ +#define EX_PROTOCOL 76 /* remote error in protocol */ +#define EX_NOPERM 77 /* permission denied */ +#define EX_CONFIG 78 /* configuration error */ +#define EX__MAX 78 /* maximum listed value */ + +#endif /* sysexits.h */ diff --git a/libw32/unistd.h b/libw32/unistd.h index 42705158..3e39de44 100644 --- a/libw32/unistd.h +++ b/libw32/unistd.h @@ -1,7 +1,7 @@ #ifndef LIBW32_UNISTD_H_INCLUDED #define LIBW32_UNISTD_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_unistd_h,"$Id: unistd.h,v 1.55 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_unistd_h,"$Id: unistd.h,v 1.66 2022/06/13 16:03:00 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -32,7 +32,7 @@ __CPRAGMA_ONCE */ #if defined(_MSC_VER) -#ifndef __MAKEDEPEND__ +#if !defined(__MAKEDEPEND__) #if (_MSC_VER != 1200) /* MSVC 6 */ #if (_MSC_VER != 1400) /* MSVC 8/2005 */ #if (_MSC_VER != 1500) /* MSVC 9/2008 */ @@ -40,8 +40,8 @@ __CPRAGMA_ONCE #if (_MSC_VER != 1900) /* MSVC 19/2015 */ #if (_MSC_VER < 1910 || _MSC_VER > 1916) /* MSVC 2017: 19.10 .. 16 */ #if (_MSC_VER > 1929) /* MSVC 2019: 19.20 .. 29 */ -#if (_MSC_VER > 1931) /* MSVC 2022: 19.30 .. 31 */ -#error unistd.h: untested MSVC Version (2005 -- 2019.31) +#if (_MSC_VER > 1932) /* MSVC 2022: 19.30 .. 32 */ +#error unistd.h: untested MSVC Version (2005 -- 2019.32) //see: https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B #endif //2022 #endif //2019 @@ -50,8 +50,8 @@ __CPRAGMA_ONCE #endif //2010 #endif //2008 #endif //2005 +#endif //MS6 #endif //__MAKEDEPEND__ -#endif //_MSC_VER #pragma warning(disable:4115) @@ -106,15 +106,24 @@ __CPRAGMA_ONCE * which among others includes */ #include +#include #include /* __BEGIN_DECLS, __PDECL */ #include #include -// #include +#if defined(HAVE_SYS_STATFS_H) +#include +#endif +#if defined(HAVE_SYS_UTIME_H) +#include +#endif #include /* required to replace strfime() */ -// #include #include /* offsetof() */ +#if defined(USE_NATIVE_DIRECT) +#include +#else #include /* MAXPATHLENGTH, MAXNAMELENGTH */ +#endif #include /* _MAX_PATH */ #include /* getpid, _beginthread */ @@ -136,6 +145,10 @@ __CPRAGMA_ONCE #define _countof(__type) (sizeof(__type)/sizeof(__type[0])) #endif +#if defined(LIBW32_UNISTD_MAP) && !defined(WIN32_UNISTD_MAP) +#define WIN32_UNISTD_MAP 1 +#endif + __BEGIN_DECLS /*limits*/ @@ -396,7 +409,7 @@ __BEGIN_DECLS #define SIGWINCH -102 #define SIGPIPE -103 -#if !defined(__MINGW32__) +#if !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR) typedef struct { unsigned junk; } sigset_t; @@ -440,41 +453,46 @@ LIBW32_API int WIFSTOPPED(int status); #endif /* */ +LIBW32_VAR char *suboptarg; + LIBW32_API int getsubopt (char **optionp, char * const *tokens, char **valuep); /* */ +//#if (0) //libcompat #if defined(_MSC_VER) || defined(__WATCOMC__) +#define NEED_STRCASECMP /*see: w32_string.c*/ +#endif +#if defined(NEED_STRCASECMP) LIBW32_API int strcasecmp(const char *s1, const char *s2); LIBW32_API int strncasecmp(const char *s1, const char *s2, size_t len); -#endif /*_MSC_VER*/ +#endif /*NEED_STRCASECMP*/ #if (defined(_MSC_VER) && (_MSC_VER < 1400)) || \ - defined(__MINGW32__) || defined(__WATCOMC__) + defined(__WATCOMC__) || \ + defined(__MINGW32__) #define NEED_STRNLEN /*see: w32_string.c*/ #endif #if defined(NEED_STRNLEN) LIBW32_API size_t strnlen(const char *s, size_t maxlen); #endif /*NEED_STRNLEN*/ +//#endif //libcompat -/* */ -LIBW32_API int gettimeofday (struct timeval *tv, struct timezone *tz); - -LIBW32_API int w32_utime (const char *path, const struct utimbuf *times); -LIBW32_API int w32_utimeA (const char *path, const struct utimbuf *times); -LIBW32_API int w32_utimeW (const wchar_t *path, const struct utimbuf *times); +LIBW32_API int w32_gethostname (char *name, size_t namelen); +LIBW32_API int w32_getdomainname (char *name, size_t namelen); #if defined(WIN32_UNISTD_MAP) -#if !defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_) +#if (defined(_WINSOCKAPI_) || defined(_WINSOCK2API_)) +#if !defined(gethostname) #define gethostname(__name,__namelen) \ - w32_gethostname (__name, __namelen) -#endif + w32_gethostname(__name,__namelen) +#endif //gethostname +#if !defined(getdomainname) #define getdomainname(__name,__namelen) \ - w32_getdomainname (__name, __namelen) + w32_getdomainname(__name,__namelen) +#endif //getdomainname +#endif #endif /*WIN32_UNISTD_MAP*/ -LIBW32_API int w32_gethostname (char *name, size_t namelen); -LIBW32_API int w32_getdomainname (char *name, size_t namelen); - LIBW32_API const char * getlogin (void); LIBW32_API int getlogin_r (char *name, size_t namesize); @@ -501,6 +519,7 @@ LIBW32_API int w32_getgpid (void); #endif /*WIN32_UNISTD_MAP*/ LIBW32_API int getgroups (int gidsetsize, gid_t grouplist[]); +LIBW32_API int setgroups (size_t size, const gid_t *gidset); /* time.h */ LIBW32_API unsigned int sleep (unsigned int secs); @@ -551,6 +570,8 @@ LIBW32_API int w32_renameW (const wchar_t *ofile, const wchar_t *nfile) LIBW32_API ssize_t pread (int fildes, void *buf, size_t nbyte, off_t offset); LIBW32_API ssize_t pwrite (int fildes, const void *buf, size_t nbyte, off_t offset); +LIBW32_API int w32_pipe(int fildes[2]); + #if defined(WIN32_UNISTD_MAP) #define open w32_open #define stat(a,b) w32_stat(a, b) @@ -563,10 +584,12 @@ LIBW32_API ssize_t pwrite (int fildes, const void *buf, size_t nbyte, off_t #define unlink(p) w32_unlink(p) #define access(p,m) w32_access(p, m) #define rename(a,b) w32_rename(a,b) +#define pipe(__f) w32_pipe(__f) #endif /*WIN32_UNISTD_MAP*/ #if defined(WIN32_UNISTD_MAP) || \ - defined(WIN32_SOCKET_MAP_FD) || defined(WIN32_SOCKET_MAP_NATIVE) + defined(LIBW32_SOCKET_MAP_FD) || defined(WIN32_SOCKET_MAP_FD) || \ + defined(LIBW32_SOCKET_MAP_NATIVE) || defined(WIN32_SOCKET_MAP_NATIVE) #define strerror(a) w32_strerror(a) //#define g_strerror(a) w32_strerror(a) /* must also replace libglib version */ #endif @@ -598,7 +621,7 @@ LIBW32_API wchar_t * w32_getcwddW (char drive, wchar_t *path, int size); #define getcwd(d,s) w32_getcwd(d,s) #define utime(p,t) w32_utime(p,t) -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (_MSC_VER < 1900) #ifndef vsnprintf #define vsnprintf _vsnprintf #endif @@ -670,9 +693,9 @@ LIBW32_API int mknod (const char *path, int mode, int dev); LIBW32_API int mknodA (const char *path, int mode, int dev); LIBW32_API int mknodW (const wchar_t *path, int mode, int dev); -#if !defined(F_GETFL) -#define F_GETFL 1 -#define F_SETFL 2 +#if !defined(F_GETFL) /* match linux definitions */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ #endif #if !defined(fcntl) @@ -682,16 +705,29 @@ LIBW32_API int w32_fcntl (int fd, int ctrl, int); LIBW32_API int w32_fsync (int fildes); /*string.h*/ +//#if (0) //libcompat LIBW32_API char * strsep (char **stringp, const char *delim); -#if defined(_MSC_VER) +#if !defined(HAVE_STRSEP) +#define HAVE_STRSEP 1 +#endif +#if defined(_MSC_VER) || defined(__MINGW32__) +#if !defined(HAVE_STRLCAT) +#define HAVE_STRLCAT 1 +#define HAVE_STRLCPY 1 +#endif LIBW32_API size_t strlcat (char *dst, const char *src, size_t siz); LIBW32_API size_t strlcpy (char *dst, const char *src, size_t siz); +//#endif //libcompat + #if (_MSC_VER <= 1600) LIBW32_API unsigned long long strtoull (const char * nptr, char ** endptr, int base); -LIBW32_API long long strtoll(const char * nptr, char ** endptr, int base); +LIBW32_API long long strtoll (const char * nptr, char ** endptr, int base); #endif #endif /*_MSC_VER*/ +LIBW32_API void setproctitle(const char *fmt, ...); +LIBW32_API void setproctitle_fast(const char *fmt, ...); + __END_DECLS #endif /*LIBW32_UNISTD_H_INCLUDED*/ diff --git a/libw32/w32_check.c b/libw32/w32_check.c index 507dd4dd..bfda28fa 100644 --- a/libw32/w32_check.c +++ b/libw32/w32_check.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_check_c,"$Id: w32_check.c,v 1.20 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_check_c,"$Id: w32_check.c,v 1.21 2022/05/31 16:18:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -49,7 +49,7 @@ __CIDENT_RCSID(gr_w32_check_c,"$Id: w32_check.c,v 1.20 2022/03/21 14:29:40 cvsus #include #include -#if defined(HAVE_SYS_SOCKET_H) || defined(__MINGW32__) +#if defined(HAVE_SYS_SOCKET_H) #include #else #error missing @@ -77,6 +77,7 @@ __CIDENT_RCSID(gr_w32_check_c,"$Id: w32_check.c,v 1.20 2022/03/21 14:29:40 cvsus #include #else #error missing + // TODO: sizeof(useconds_t) == sizeof(suseconds_t) #endif #ifdef HAVE_PWD_H @@ -95,19 +96,19 @@ __CIDENT_RCSID(gr_w32_check_c,"$Id: w32_check.c,v 1.20 2022/03/21 14:29:40 cvsus #include #include -#if defined(HAVE_INTTYPES_H) || defined(__MINGW32__) +#if defined(HAVE_INTTYPES_H) #include #else #error missing #endif -#if defined(HAVE_STDINT_H) || defined(__MINGW32__) +#if defined(HAVE_STDINT_H) #include #else #include missing #endif #include -#ifdef HAVE_UNISTD_H +#if defined(HAVE_UNISTD_H) #include #else #error missing diff --git a/libw32/w32_child.c b/libw32/w32_child.c index eff9ff0c..d8beaf2b 100644 --- a/libw32/w32_child.c +++ b/libw32/w32_child.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_child_c,"$Id: w32_child.c,v 1.16 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_child_c,"$Id: w32_child.c,v 1.19 2022/06/13 06:51:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -314,7 +314,7 @@ w32_waitpid(int pid, int *status, int options) /* * wait for the child whose process ID is equal to the value of pid. */ - if (w32_child_wait((HANDLE)pid, status, options & WNOHANG)) { + if (w32_child_wait(w32_ITOH(pid), status, options & WNOHANG)) { ret = pid; } } @@ -442,7 +442,7 @@ LIBW32_API int w32_kill(int pid, int value) { if (pid > 0) { - HANDLE hProc = (HANDLE)pid; + HANDLE hProc = w32_ITOH(pid); /* Still running ?? */ if (WaitForSingleObject(hProc, 0) != WAIT_TIMEOUT) { @@ -504,9 +504,9 @@ EnumWindowsProc(HWND hwnd, LPARAM lParam) (void) GetWindowThreadProcessId(hwnd, &pid); return pid != info->dwProcessId - || GetExitCodeProcess(info->hProcess, &status) - && status == STILL_ACTIVE // value = 259 - && PostMessage(hwnd, WM_CLOSE, 0, 0); + || (GetExitCodeProcess(info->hProcess, &status) + && status == STILL_ACTIVE // value = 259 + && PostMessage(hwnd, WM_CLOSE, 0, 0)); } @@ -653,9 +653,11 @@ w32_child_execA( si.hStdOutput = hStdOut; si.hStdError = hStdErr; +#if !defined(NDEBUG) if (hStdIn) { DWORD flags; assert(GetHandleInformation(hStdIn, &flags) && (HANDLE_FLAG_INHERIT & flags)); } if (hStdOut) { DWORD flags; assert(GetHandleInformation(hStdOut, &flags) && (HANDLE_FLAG_INHERIT & flags)); } if (hStdErr) { DWORD flags; assert(GetHandleInformation(hStdErr, &flags) && (HANDLE_FLAG_INHERIT & flags)); } +#endif si.dwFlags = STARTF_USESTDHANDLES; si.dwFlags |= STARTF_USESHOWWINDOW; @@ -774,9 +776,11 @@ w32_child_execW( si.hStdOutput = hStdOut; si.hStdError = hStdErr; +#if !defined(NDEBUG) if (hStdIn) { DWORD flags; assert(GetHandleInformation(hStdIn, &flags) && (HANDLE_FLAG_INHERIT & flags)); } if (hStdOut) { DWORD flags; assert(GetHandleInformation(hStdOut, &flags) && (HANDLE_FLAG_INHERIT & flags)); } if (hStdErr) { DWORD flags; assert(GetHandleInformation(hStdErr, &flags) && (HANDLE_FLAG_INHERIT & flags)); } +#endif si.dwFlags = STARTF_USESTDHANDLES; si.dwFlags |= STARTF_USESHOWWINDOW; @@ -1044,7 +1048,7 @@ BuildArgA(const char *cmd, const char **argv) /**/; } - if (len > (32 * 1024 * sizeof(char))) { + if (len > (int)(32 * 1024 * sizeof(char))) { errno = E2BIG; // command line too long >32k. return NULL; } @@ -1147,7 +1151,6 @@ BuildEnvA(const char **envv) * null, "_wenviron" is used instead. File handle info is passed in the environment * if _fileinfo is !0. */ - static int BuildVectorsW(win32_spawnw_t *args, wchar_t **argblk, wchar_t **envblk) { @@ -1188,7 +1191,7 @@ BuildArgW(const wchar_t *cmd, const wchar_t **argv) /**/; } - if (len > (32 * 1024 * sizeof(wchar_t))) { + if (len > (int)(32 * 1024 * sizeof(wchar_t))) { errno = E2BIG; // command line too long >32k. return NULL; } diff --git a/libw32/w32_dirent.c b/libw32/w32_dirent.c index 4cc0191b..7b0c152b 100644 --- a/libw32/w32_dirent.c +++ b/libw32/w32_dirent.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_dirent_c,"$Id: w32_dirent.c,v 1.32 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_dirent_c,"$Id: w32_dirent.c,v 1.33 2022/06/11 04:01:44 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -1224,7 +1224,7 @@ d_Wow64DisableWow64FsRedirection(PVOID *OldValue) // XP+ x_Wow64DisableWow64FsRedirection = my_Wow64DisableWow64FsRedirection; x_Wow64RevertWow64FsRedirection = NULL; - FreeLibrary(hinst); + if (hInst) FreeLibrary(hinst); } #else x_Wow64DisableWow64FsRedirection = my_Wow64DisableWow64FsRedirection; diff --git a/libw32/w32_direntunc.c b/libw32/w32_direntunc.c index 0fc7dabe..175d3eb1 100644 --- a/libw32/w32_direntunc.c +++ b/libw32/w32_direntunc.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_direntunc_c,"$Id: w32_direntunc.c,v 1.2 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_direntunc_c,"$Id: w32_direntunc.c,v 1.4 2022/06/13 06:51:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -88,13 +88,14 @@ w32_unc_iterateW(const wchar_t *servername, unc_push_t push, void *data) assert(NULL != push); assert(NULL != data); do { - DWORD entries = (DWORD)-1, tr = 0, resume = 0; + DWORD entries = (DWORD)-1, tr = 0; + DWORD resume_handle = 0; if (servername && !*servername) { // DNS or NetBIOS name servername = NULL; // NULL == localserver } - res = NetShareEnum((wchar_t *)servername, 502, (LPBYTE *)&buffer, MAX_PREFERRED_LENGTH, &entries, &tr, &resume); + res = NetShareEnum((wchar_t *)servername, 502, (LPBYTE *)&buffer, MAX_PREFERRED_LENGTH, &entries, &tr, &resume_handle); if (ERROR_SUCCESS == res || ERROR_MORE_DATA == res) { const SHARE_INFO_502 *ent; unsigned count = 0; @@ -225,7 +226,8 @@ w32_unc_readdirA(DIR *dp) struct dirent *dpent = (struct dirent *)dp->dd_buf; int namlen = strlen(cursor); - if (namlen >= sizeof(dpent->d_name)) namlen = sizeof(dpent->d_name) - 1; + if (namlen >= (int)sizeof(dpent->d_name)) + namlen = sizeof(dpent->d_name) - 1; dpent->d_namlen = namlen; memcpy(dpent->d_name, cursor, namlen + 1 /*nul*/); dpent->d_reclen = sizeof(struct dirent); @@ -314,7 +316,7 @@ w32_unc_validA(const char *path) if (NULL == (scan = strpbrk(path, "*?|<>\"\\/")) || IS_PATH_SEP(scan[0])) { const size_t namelen = // servername length - (scan ? (scan - path) : strlen(path)); + (scan ? (size_t)(scan - path) : strlen(path)); if (namelen > 0) { return namelen; @@ -335,7 +337,7 @@ w32_unc_validW(const wchar_t *path) if (NULL == (scan = wcspbrk(path, L"*?|<>\"\\/")) || IS_PATH_SEP(scan[0])) { const size_t namelen = // servername length - (scan ? (scan - path) : wcslen(path)); + (scan ? (size_t)(scan - path) : wcslen(path)); if (namelen > 0) { return namelen; @@ -366,7 +368,7 @@ w32_unc_rootA(const char *path, int *length) if (length) *length = namelen; if (GetComputerNameA(computerName, &computerSz)) { - if (namelen == computerSz && + if ((DWORD)namelen == computerSz && 0 == _strnicmp(path + 2, computerName, namelen)) { return 2; // local server } @@ -394,7 +396,7 @@ w32_unc_rootW(const wchar_t *path, int *length) if (length) *length = namelen; if (GetComputerNameW(computerName, &computerSz)) { - if (namelen == computerSz && + if ((DWORD)namelen == computerSz && 0 == _wcsnicmp(path + 2, computerName, namelen)) { return 2; // local server } diff --git a/libw32/w32_dlfcn.c b/libw32/w32_dlfcn.c index 6a534c37..234d89af 100644 --- a/libw32/w32_dlfcn.c +++ b/libw32/w32_dlfcn.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_dlfcn_c,"$Id: w32_dlfcn.c,v 1.14 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_dlfcn_c,"$Id: w32_dlfcn.c,v 1.16 2022/05/26 12:15:51 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -41,7 +41,7 @@ __CIDENT_RCSID(gr_w32_dlfcn_c,"$Id: w32_dlfcn.c,v 1.14 2022/03/21 14:29:40 cvsus #include -#include +#include #define DLERROR_LEN 1024 /* error buffer size */ @@ -56,7 +56,11 @@ typedef struct globallib { char g_name[1]; } globallib_t; -__declspec(thread) static char x_dlerror[DLERROR_LEN]; +#if defined(__MINGW32__) +static __thread char x_dlerror[DLERROR_LEN]; +#else +__declspec(thread) static char x_dlerror[DLERROR_LEN]; +#endif static unsigned x_dlopen; static CRITICAL_SECTION x_guard; diff --git a/libw32/w32_err.c b/libw32/w32_err.c index a91860d6..3addbd15 100644 --- a/libw32/w32_err.c +++ b/libw32/w32_err.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_err_c,"$Id: w32_err.c,v 1.4 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_err_c,"$Id: w32_err.c,v 1.5 2022/05/26 11:13:28 cvsuser Exp $") /* * Copyright (c) 1993 @@ -32,6 +32,7 @@ __CIDENT_RCSID(gr_w32_err_c,"$Id: w32_err.c,v 1.4 2022/03/21 14:29:40 cvsuser Ex #include "win32_internal.h" #include +#include #include #include diff --git a/libw32/w32_errno.c b/libw32/w32_errno.c index 7e4a21ed..8c7bc00f 100644 --- a/libw32/w32_errno.c +++ b/libw32/w32_errno.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_errno_c,"$Id: w32_errno.c,v 1.22 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_errno_c,"$Id: w32_errno.c,v 1.24 2022/05/31 16:18:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -421,6 +421,9 @@ w32_errno_cnv(unsigned rc) t_errno = EPIPE; break; case ERROR_PIPE_LISTENING: /* 536 - Waiting for a process to open the other end of the pipe. */ t_errno = EPIPE; break; +#if defined(__MINGW32__) || !defined(ERROR_CANT_WAIT) +#define ERROR_CANT_WAIT 554 +#endif case ERROR_CANT_WAIT: /* 554 (0x22A) - Used to indicate that an operation cannot continue without blocking for I/O. */ t_errno = EAGAIN; break; case ERROR_OPERATION_ABORTED: /* 995 - The I/O operation has been aborted because of either a thread exit or an application request. */ @@ -770,7 +773,9 @@ w32_strerror(int errnum) // case EPROTOTYPE: /*136*/ err = "Protype error"; break; case ETIME: /*137*/ err = "Stream ioctl timeout"; break; // case ETIMEDOUT: /*138*/ err = "Connection timed out"; break; +#if defined(ETXTBSY) case ETXTBSY: /*139*/ err = "Text file busy"; break; +#endif // case EWOULDBLOCK: /*140*/ err = "Operation would block"; break; /* BSD/SysV messages */ @@ -866,7 +871,7 @@ w32_strerror(int errnum) #endif default: - _snprintf(errbuffer, sizeof(errbuffer), + _snprintf(errbuffer, sizeof(errbuffer), "%s [%d]", (errnum >= WSABASEERR ? "unknown winsock error" : "unknown error"), errnum); err = errbuffer; break; diff --git a/libw32/w32_getcwd.c b/libw32/w32_getcwd.c index 8f4bc4b0..34005593 100644 --- a/libw32/w32_getcwd.c +++ b/libw32/w32_getcwd.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_getcwd_c,"$Id: w32_getcwd.c,v 1.14 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_getcwd_c,"$Id: w32_getcwd.c,v 1.15 2022/05/26 11:53:40 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -36,6 +36,8 @@ __CIDENT_RCSID(gr_w32_getcwd_c,"$Id: w32_getcwd.c,v 1.14 2022/03/21 14:29:40 cvs */ #include "win32_internal.h" +#include "win32_io.h" + #include #include diff --git a/libw32/w32_gethostname.c b/libw32/w32_gethostname.c index 33d7ec76..8e045dbf 100644 --- a/libw32/w32_gethostname.c +++ b/libw32/w32_gethostname.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_gethostname_c,"$Id: w32_gethostname.c,v 1.17 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_gethostname_c,"$Id: w32_gethostname.c,v 1.19 2022/06/13 06:59:04 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -47,7 +47,7 @@ __CIDENT_RCSID(gr_w32_gethostname_c,"$Id: w32_gethostname.c,v 1.17 2022/03/21 14 #endif #include -#if defined(__WATCOMC__) && (__WATCOMC__ <= 1900) +#if defined(__WATCOMC__) && (__WATCOMC__ <= 1300 /*OWC2*/) typedef enum _COMPUTER_NAME_FORMAT { ComputerNameNetBIOS, ComputerNameDnsHostname, diff --git a/libw32/w32_getopt.c b/libw32/w32_getopt.c index 90500ce5..f43b9cf7 100644 --- a/libw32/w32_getopt.c +++ b/libw32/w32_getopt.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_getopt_c,"$Id: w32_getopt.c,v 1.9 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_getopt_c,"$Id: w32_getopt.c,v 1.13 2022/06/13 06:51:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -31,20 +31,24 @@ __CIDENT_RCSID(gr_w32_getopt_c,"$Id: w32_getopt.c,v 1.9 2022/03/21 14:29:40 cvsu * SUCH DAMAGE. */ +#if !defined(__MINGW32__) + #include #include #include #include -LIBW32_API int opterr = 1, /* if error message should be printed */ +#include "getopt.h" + +/*LIBW32_VAR*/ int opterr = 1, /* if error message should be printed */ optind = 1, /* index into parent argv vector */ optopt = '?', /* character checked for validity */ optreset = 0; /* reset getopt */ -LIBW32_API char * optarg = NULL; /* argument associated with option */ +/*LIBW32_VAR*/ char *optarg = NULL; /* argument associated with option */ -static const char *__progname = ""; +static const char *__progname = ""; /* derived progname */ #define BADCH (int)'?' #define BADARG (int)':' @@ -64,7 +68,7 @@ getopt(int nargc, char * const *nargv, const char *ostr) #if defined(_WIN32) || defined(WIN32) if (optind == 1 && (__progname == NULL || __progname[0] == '\0')) - __progname = nargv[0]; /* MSVC special */ + __progname = nargv[0]; /* WIN32 special */ #endif if (optreset || !*place) { /* update scanning pointer */ @@ -122,5 +126,7 @@ getopt(int nargc, char * const *nargv, const char *ostr) return (optopt); /* dump back option letter */ } +#endif /*!__MINGW32__*/ + /*end*/ diff --git a/libw32/w32_getopt_long.c b/libw32/w32_getopt_long.c index 02e2ab3b..3ca5b748 100644 --- a/libw32/w32_getopt_long.c +++ b/libw32/w32_getopt_long.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_getopt_c,"$Id: w32_getopt_long.c,v 1.2 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_getopt_c,"$Id: w32_getopt_long.c,v 1.5 2022/06/11 04:01:44 cvsuser Exp $") /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -32,19 +32,19 @@ __CIDENT_RCSID(gr_w32_getopt_c,"$Id: w32_getopt_long.c,v 1.2 2022/03/21 14:29:40 * $NetBSD: getopt_long.c,v 1.21.4.1 2008/01/09 01:34:14 matt Exp $ */ +#if !defined(__MINGW32__) + #include #include #include -// #if defined(HAVE_GETOPT_H) && defined(HAVE_STRUCT_OPTION) #include -// #endif #include #include #include -//#define REPLACE_GETOPT + //#define REPLACE_GETOPT #ifndef _DIAGASSERT #define _DIAGASSERT assert @@ -336,6 +336,7 @@ getopt_internal(int nargc, char **nargv, const char *options, char *buf, int buf #endif //REPLACE_GETOPT +extern int __import_getopt(int nargc, char * const *nargv, const char *ostr); int __import_getopt(int nargc, char * const *nargv, const char *ostr) { @@ -492,4 +493,6 @@ getopt_long2(int nargc, char * const *nargv, const char *options, const struct o #undef IDENTICAL_INTERPRETATION } +#endif /*!__MINGW32__*/ + //end diff --git a/libw32/w32_getrlimit.c b/libw32/w32_getrlimit.c new file mode 100644 index 00000000..99d8df12 --- /dev/null +++ b/libw32/w32_getrlimit.c @@ -0,0 +1,169 @@ +#include +__CIDENT_RCSID(gr_w32_getrlimit_c,"$Id: w32_getrlimit.c,v 1.2 2022/05/26 13:17:34 cvsuser Exp $") + +/* -*- mode: c; indent-width: 4; -*- */ +/* + * win32 getrlimit() system calls + * + * Copyright (c) 2020, Adam Young. + * All rights reserved. + * + * This file is part of the GRIEF Editor. + * + * The GRIEF Editor is free software: you can redistribute it + * and/or modify it under the terms of the GRIEF Editor License. + * + * Redistributions of source code must retain the above copyright + * notice, and must be distributed with the license document above. + * + * Redistributions in binary form must reproduce the above copyright + * notice, and must include the license document above in + * the documentation and/or other materials provided with the + * distribution. + * + * This project 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 + * license for more details. + * ==end== + * + * Notice: Portions of this text are reprinted and reproduced in electronic form. from + * IEEE Portable Operating System Interface (POSIX), for reference only. Copyright (C) + * 2001-2003 by the Institute of. Electrical and Electronics Engineers, Inc and The Open + * Group. Copyright remains with the authors and the original Standard can be obtained + * online at http://www.opengroup.org/unix/online.html. + * ==extra== + */ + +#include +#include +#include + + +/* +NAME + getrlimit, setrlimit - control maximum resource consumption + +SYNOPSIS + #include + + int getrlimit(int resource, struct rlimit *rlp); + int setrlimit(int resource, const struct rlimit *rlp); [Option End] + +DESCRIPTION + The getrlimit() function shall get, and the setrlimit() function shall set, limits on the consumption of a variety of resources. + + Each call to either getrlimit() or setrlimit() identifies a specific resource to be operated upon as well as a resource limit. + A resource limit is represented by an rlimit structure. The rlim_cur member specifies the current or soft limit and the rlim_max + member specifies the maximum or hard limit. Soft limits may be changed by a process to any value that is less than or equal to + the hard limit. A process may (irreversibly) lower its hard limit to any value that is greater than or equal to the soft limit. + Only a process with appropriate privileges can raise a hard limit. Both hard and soft limits can be changed in a single + call to setrlimit() subject to the constraints described above. + + The value RLIM_INFINITY, defined in , shall be considered to be larger than any other limit value. + If a call to getrlimit() returns RLIM_INFINITY for a resource, it means the implementation shall not enforce limits on that resource. + Specifying RLIM_INFINITY as any resource limit value on a successful call to setrlimit() shall inhibit enforcement of that resource limit. + + The following resources are defined: + + RLIMIT_CORE + This is the maximum size of a core file, in bytes, that may be created by a process. + A limit of 0 shall prevent the creation of a core file. If this limit is exceeded, the writing of a core file shall terminate at this size. + + RLIMIT_CPU + This is the maximum amount of CPU time, in seconds, used by a process. + If this limit is exceeded, SIGXCPU shall be generated for the process. + If the process is catching or ignoring SIGXCPU, or all threads belonging to that process are blocking SIGXCPU, the behavior is unspecified. + + RLIMIT_DATA + This is the maximum size of a data segment of the process, in bytes. + If this limit is exceeded, the malloc() function shall fail with errno set to [ENOMEM]. + + RLIMIT_FSIZE + This is the maximum size of a file, in bytes, that may be created by a process. + If a write or truncate operation would cause this limit to be exceeded, SIGXFSZ shall be generated for the thread. + If the thread is blocking, or the process is catching or ignoring SIGXFSZ, continued attempts to increase the size + of a file from end-of-file to beyond the limit shall fail with errno set to [EFBIG]. + + RLIMIT_NOFILE + This is a number one greater than the maximum value that the system may assign to a newly-created descriptor. + If this limit is exceeded, functions that allocate a file descriptor shall fail with errno set to [EMFILE]. + This limit constrains the number of file descriptors that a process may allocate. + + RLIMIT_STACK + This is the maximum size of the initial thread's stack, in bytes. + The implementation does not automatically grow the stack beyond this limit. + If this limit is exceeded, SIGSEGV shall be generated for the thread. + If the thread is blocking SIGSEGV, or the process is ignoring or catching SIGSEGV and has not made arrangements + to use an alternate stack, the disposition of SIGSEGV shall be set to SIG_DFL before it is generated. + + RLIMIT_AS + This is the maximum size of total available memory of the process, in bytes. + If this limit is exceeded, the malloc() and mmap() functions shall fail with errno set to [ENOMEM]. + In addition, the automatic stack growth fails with the effects outlined above. + + When using the getrlimit() function, if a resource limit can be represented correctly in an object of type rlim_t, + then its representation is returned; otherwise, if the value of the resource limit is equal to that of the corresponding + saved hard limit, the value returned shall be RLIM_SAVED_MAX; otherwise, the value returned shall be RLIM_SAVED_CUR. + + When using the setrlimit() function, if the requested new limit is RLIM_INFINITY, the new limit shall be "no limit''; otherwise, + if the requested new limit is RLIM_SAVED_MAX, the new limit shall be the corresponding saved hard limit; otherwise, if the + requested new limit is RLIM_SAVED_CUR, the new limit shall be the corresponding saved soft limit; otherwise, the new limit + shall be the requested value. In addition, if the corresponding saved limit can be represented correctly in an object + of type rlim_t then it shall be overwritten with the new limit. + + The result of setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is unspecified unless a previous call to getrlimit() + returned that value as the soft or hard limit for the corresponding resource limit. + + The determination of whether a limit can be correctly represented in an object of type rlim_t is implementation-defined. + For example, some implementations permit a limit whose value is greater than RLIM_INFINITY and others do not. + + The exec family of functions shall cause resource limits to be saved. + +RETURN VALUE + Upon successful completion, getrlimit() and setrlimit() shall return 0. Otherwise, these functions shall return -1 and set errno to indicate the error. + +ERRORS + The getrlimit() and setrlimit() functions shall fail if: + + [EINVAL] + An invalid resource was specified; or in a setrlimit() call, the new rlim_cur exceeds the new rlim_max. + [EPERM] + The limit specified to setrlimit() would have raised the maximum limit value, and the calling process does not have appropriate privileges. + + The setrlimit() function may fail if: + + [EINVAL] + The limit specified cannot be lowered because current usage is already higher than the limit. +*/ + +int +getrlimit(int resource, struct rlimit *rlp) +{ + if (NULL == rlp) { + errno = EINVAL; + } else { + switch (resource) { + case RLIMIT_NOFILE: +#if defined(__WATCOMC__) + rlp->rlim_cur = _grow_handles(_NFILES); + rlp->rlim_max = 2048; /*assumed limit*/ +#else + rlp->rlim_cur = _getmaxstdio(); +#if defined(_MSC_VER) && (_MSC_VER >= 1920) + rlp->rlim_max = 8192; /*2019, documented limit*/ +#else + rlp->rlim_max = 2048; /*documented limit*/ +#endif +#endif + if (rlp->rlim_cur > rlp->rlim_max) { + rlp->rlim_max = rlp->rlim_cur; + } + return 0; + } + errno = ENOSYS; + } + return -1; +} + +/*end*/ diff --git a/libw32/w32_getsubopt.c b/libw32/w32_getsubopt.c index 938e1b33..e0d1d65f 100644 --- a/libw32/w32_getsubopt.c +++ b/libw32/w32_getsubopt.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_getsubopt_c,"$Id: w32_getsubopt.c,v 1.8 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_getsubopt_c,"$Id: w32_getsubopt.c,v 1.9 2022/06/11 04:01:45 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /*- @@ -45,7 +45,7 @@ __CIDENT_RCSID(gr_w32_getsubopt_c,"$Id: w32_getsubopt.c,v 1.8 2022/03/21 14:29:4 * tricky... The extern variable suboptarg is a pointer to the token * which didn't match. */ -LIBW32_API char *suboptarg = NULL; +/*LIBW32_VAR*/ char *suboptarg = NULL; LIBW32_API int getsubopt(char **optionp, char * const *tokens, char **valuep) diff --git a/libw32/w32_glob.c b/libw32/w32_glob.c index 0582566b..61878cca 100644 --- a/libw32/w32_glob.c +++ b/libw32/w32_glob.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_glob_c,"$Id: w32_glob.c,v 1.6 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_glob_c,"$Id: w32_glob.c,v 1.7 2022/05/26 12:02:41 cvsuser Exp $") /* * win @@ -1068,7 +1068,7 @@ globfree(glob_t *pglob) } #ifndef __LIBC12_SOURCE__ -int +LIBW32_API int glob_pattern_p(const char *pattern, int quote) { int range = 0; diff --git a/libw32/w32_grp.c b/libw32/w32_grp.c index a9fe3032..d0084863 100644 --- a/libw32/w32_grp.c +++ b/libw32/w32_grp.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_grp_c,"$Id: w32_grp.c,v 1.13 2022/03/21 14:29:40 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_grp_c,"$Id: w32_grp.c,v 1.14 2022/06/13 06:51:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -477,7 +477,7 @@ setgroups(size_t size, const gid_t *gidset) static void fill_groups(void) { - DWORD resume_handle = 0; + DWORD_PTR resume_handle = 0; NET_API_STATUS nStatus; unsigned cbufsz = 0; char name[MAX_PATH]; diff --git a/libw32/w32_iconv.c b/libw32/w32_iconv.c index 3a2cac38..68427fd0 100644 --- a/libw32/w32_iconv.c +++ b/libw32/w32_iconv.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_iconv_c,"$Id: w32_iconv.c,v 1.20 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_iconv_c,"$Id: w32_iconv.c,v 1.21 2022/06/16 05:17:58 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -50,11 +50,8 @@ __CIDENT_RCSID(gr_w32_iconv_c,"$Id: w32_iconv.c,v 1.20 2022/03/21 14:29:41 cvsus #define DO_TRACE_LOG // trace_log() #endif -#if defined(HAVE_LIBICONV_DLL) #define DLLLINKAGE __cdecl -#else -#define DLLLINKAGE /**/ -#endif + typedef void * (DLLLINKAGE * iconvopenfn_t)(const char *to, const char *from); typedef void (DLLLINKAGE * iconvclosefn_t)(void *fd); typedef int (DLLLINKAGE * iconvfn_t)(void *fd, const char **from, size_t *fromlen, char **to, size_t *tolen); diff --git a/libw32/w32_iconv_native.c b/libw32/w32_iconv_native.c index d4c39439..16bffeec 100644 --- a/libw32/w32_iconv_native.c +++ b/libw32/w32_iconv_native.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_iconv_native_c,"$Id: w32_iconv_native.c,v 1.6 2018/10/12 00:30:31 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_iconv_native_c,"$Id: w32_iconv_native.c,v 1.9 2022/05/26 13:28:37 cvsuser Exp $") /* * iconv implementation using Win32 API to convert. @@ -14,12 +14,8 @@ __CIDENT_RCSID(gr_w32_iconv_native_c,"$Id: w32_iconv_native.c,v 1.6 2018/10/12 0 * ==nonotice== */ -#ifndef WINVER -# define WINVER 0x0500 /* for WC_NO_BEST_FIT_CHARS */ -#endif +#include -#define STRICT -#include #include #include #include @@ -1644,7 +1640,7 @@ iso2022jp_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int return seterror(EILSEQ); /* reset the mode for informal sequence */ - if (cv->mode != ISO2022_MODE(cs, shift)) + if ((int)cv->mode != ISO2022_MODE(cs, shift)) cv->mode = ISO2022_MODE(cs, shift); return len; @@ -1715,7 +1711,7 @@ iso2022jp_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsi else if (tmpsize < esc_len + len) return seterror(EILSEQ); - if (cv->mode == ISO2022_MODE(cs, shift)) + if ((int)cv->mode == ISO2022_MODE(cs, shift)) { /* remove escape sequence */ if (esc_len != 0) diff --git a/libw32/w32_io.c b/libw32/w32_io.c index 39f7fc3c..ce8f1221 100644 --- a/libw32/w32_io.c +++ b/libw32/w32_io.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_io_c,"$Id: w32_io.c,v 1.39 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_io_c,"$Id: w32_io.c,v 1.45 2022/06/15 12:11:30 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -38,7 +38,11 @@ __CIDENT_RCSID(gr_w32_io_c,"$Id: w32_io.c,v 1.39 2022/03/21 14:29:41 cvsuser Exp */ #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 /* enable xp+ features */ +#define _WIN32_WINNT 0x0501 /* enable xp+ features */ +#endif +#if defined(__MINGW32__) +#undef _WIN32_VER +#define _WIN32_VER _WIN32_WINNT #endif #include @@ -197,6 +201,62 @@ w32_utf8filenames_state (void) } +/* +// NAME +// handle conversion +// +// SYNOPSIS +// int w32_HTOI(HANDLE handle) +// HANDLE w32_ITOH(int fd) +// +// NOTES: +// +// MSDN - Interprocess Communication Between 32-bit and 64-bit Applications +// +// 64-bit versions of Windows use 32-bit handles for interoperability. +// When sharing a handle between 32-bit and 64-bit applications, only the lower 32 bits are significant, +// so it is safe to truncate the handle (when passing it from 64-bit to 32-bit) or sign-extend the handle (when passing it from 32-bit to 64-bit). +// Handles that can be shared include handles to user objects such as windows (HWND), handles to GDI objects such as pens and brushes (HBRUSH and HPEN), +// and handles to named objects such as mutexes, semaphores, and file handles. +// +// RETURN VALUE +// Converted handle. +*/ + +int +w32_HTOI(HANDLE handle) +{ +#if defined(__MINGW32__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpointer-to-int-cast" +#endif +#if defined(_WIN32) && \ + (!defined(_MSC_VER) || (_MSC_VER >= 1600 /*2010*/)) + assert((0xffffffff00000000LLU & (uint64_t)handle) == 0 || handle == INVALID_HANDLE_VALUE); +#endif + if (INVALID_HANDLE_VALUE == handle) return -1; + return (int)handle; +#if defined(__MINGW64__) +#pragma GCC diagnostic pop +#endif +} + + +HANDLE +w32_ITOH(int fd) +{ +#if defined(__MINGW32__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#endif + if (-1 == fd) return INVALID_HANDLE_VALUE; + return (HANDLE)fd; +#if defined(__MINGW64__) +#pragma GCC diagnostic pop +#endif +} + + /* // NAME // stat - get file status @@ -609,7 +669,7 @@ w32_fstatW(int fd, struct stat *sb) } else if ((handle = ((HANDLE) _get_osfhandle(fd))) == INVALID_HANDLE_VALUE) { // socket, a named pipe, or an anonymous pipe. - if (fd > WIN32_FILDES_MAX && FILE_TYPE_PIPE == GetFileType((HANDLE) fd)) { + if (fd > WIN32_FILDES_MAX && FILE_TYPE_PIPE == GetFileType(w32_ITOH(fd))) { sb->st_mode |= S_IRUSR | S_IRGRP | S_IROTH; sb->st_mode |= S_IFIFO; sb->st_dev = sb->st_rdev = 1; @@ -683,7 +743,7 @@ my_GetFinalPathNameByHandleW(HANDLE handle, LPWSTR path, int length) (GetFinalPathNameByHandleW_t)GetProcAddress(hinst, "GetFinalPathNameByHandleW"))) { // XP+ x_GetFinalPathNameByHandleW = my_GetFinalPathNameByHandleWImp; - (void)FreeLibrary(hinst); + if (hinst) FreeLibrary(hinst); } } @@ -782,7 +842,7 @@ w32_fstatA(int fd, struct stat *sb) } else if ((handle = ((HANDLE) _get_osfhandle(fd))) == INVALID_HANDLE_VALUE) { // socket, a named pipe, or an anonymous pipe. - if (fd > WIN32_FILDES_MAX && FILE_TYPE_PIPE == GetFileType((HANDLE) fd)) { + if (fd > WIN32_FILDES_MAX && FILE_TYPE_PIPE == GetFileType(w32_ITOH(fd))) { sb->st_mode |= S_IRUSR | S_IRGRP | S_IROTH; sb->st_mode |= S_IFIFO; sb->st_dev = sb->st_rdev = 1; @@ -856,7 +916,7 @@ my_GetFinalPathNameByHandleA(HANDLE handle, char *path, int length) (GetFinalPathNameByHandleA_t)GetProcAddress(hinst, "GetFinalPathNameByHandleA"))) { // XP+ x_GetFinalPathNameByHandleA = my_GetFinalPathNameByHandleAImp; - (void)FreeLibrary(hinst); + if (hinst) FreeLibrary(hinst); } } @@ -1214,7 +1274,7 @@ my_CreateSymbolicLinkW(LPCWSTR lpSymlinkFileName, LPCWSTR lpTargetFileName, DWOR (CreateSymbolicLinkW_t)GetProcAddress(hinst, "CreateSymbolicLinkW"))) { // XP+ x_CreateSymbolicLinkW = my_CreateSymbolicLinkWImp; - (void) FreeLibrary(hinst); + if (hinst) FreeLibrary(hinst); } } return x_CreateSymbolicLinkW(lpSymlinkFileName, lpTargetFileName, dwFlags); @@ -1246,7 +1306,7 @@ my_CreateSymbolicLinkA(const char *lpSymlinkFileName, const char *lpTargetFileNa (CreateSymbolicLinkA_t)GetProcAddress(hinst, "CreateSymbolicLinkA"))) { // XP+ x_CreateSymbolicLinkA = my_CreateSymbolicLinkAImp; - (void) FreeLibrary(hinst); + if (hinst) FreeLibrary(hinst); } } return x_CreateSymbolicLinkA(lpSymlinkFileName, lpTargetFileName, dwFlags); @@ -2944,7 +3004,9 @@ StatW(const wchar_t *name, struct stat *sb) { wchar_t fullname[WIN32_PATH_MAX] = {0}, *pfname = NULL; int flength, ret = -1; +#if defined(DO_FILEMAGIC) BOOL domagic = 0; +#endif if (name == NULL || sb == NULL) { ret = -EFAULT; /* basic checks */ diff --git a/libw32/w32_itimer.c b/libw32/w32_itimer.c index 905c61f3..de733147 100644 --- a/libw32/w32_itimer.c +++ b/libw32/w32_itimer.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_itimer_c,"$Id: w32_itimer.c,v 1.4 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_itimer_c,"$Id: w32_itimer.c,v 1.5 2022/06/11 04:01:45 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -166,7 +166,7 @@ timer_thread(LPVOID param) waitms = INFINITE; } else { - assert(false); //debug trap + assert(0); //debug trap } } return 0; diff --git a/libw32/w32_link.c b/libw32/w32_link.c index 06643f13..45edb830 100644 --- a/libw32/w32_link.c +++ b/libw32/w32_link.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_link_c,"$Id: w32_link.c,v 1.17 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_link_c,"$Id: w32_link.c,v 1.18 2022/06/11 04:01:45 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -259,7 +259,7 @@ my_CreateHardLinkW(LPCWSTR lpFileName, LPCWSTR lpExistingFileName) (CreateHardLinkW_t)GetProcAddress(hinst, "CreateHardLinkW"))) { // XP+ x_CreateHardLinkW = my_CreateHardLinkImpW; - (void)FreeLibrary(hinst); + if (hinst) FreeLibrary(hinst); } } return x_CreateHardLinkW(lpFileName, lpExistingFileName, NULL); @@ -325,7 +325,7 @@ my_CreateHardLinkA(LPCSTR lpFileName, LPCSTR lpExistingFileName) (CreateHardLinkA_t)GetProcAddress(hinst, "CreateHardLinkA"))) { // XP+ x_CreateHardLinkA = my_CreateHardLinkImpA; - (void)FreeLibrary(hinst); + if (hinst) FreeLibrary(hinst); } } return x_CreateHardLinkA(lpFileName, lpExistingFileName, NULL); diff --git a/libw32/w32_mkstemp.c b/libw32/w32_mkstemp.c index 1b65379d..42a379c8 100644 --- a/libw32/w32_mkstemp.c +++ b/libw32/w32_mkstemp.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_mkstemp_c,"$Id: w32_mkstemp.c,v 1.17 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_mkstemp_c,"$Id: w32_mkstemp.c,v 1.18 2022/05/26 13:28:37 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -387,7 +387,7 @@ gettempA_tmp(char *result, const char *path, int suffixlen, int *fildes, unsigne // TMP, TEMP, USERPROFILE environment variables, default windows directory. if (pathlen && tmplen) { - if ((pathlen + tmplen) >= _countof(t_path)) { + if ((pathlen + tmplen) >= (int)_countof(t_path)) { errno = ENAMETOOLONG; } else { @@ -562,7 +562,7 @@ gettempW_tmp(wchar_t *result, const wchar_t *path, int suffixlen, int *fildes, u // TMP, TEMP, USERPROFILE environment variables, default windows directory. if (pathlen && tmplen) { - if ((pathlen + tmplen) >= (_countof(t_path) + 1)) { + if ((pathlen + tmplen) >= (int)(_countof(t_path) + 1)) { errno = ENAMETOOLONG; } else { diff --git a/libw32/w32_pipe.c b/libw32/w32_pipe.c new file mode 100644 index 00000000..b8804c37 --- /dev/null +++ b/libw32/w32_pipe.c @@ -0,0 +1,69 @@ +#include +__CIDENT_RCSID(gr_w32_pipe_c,"$Id: w32_pipe.c,v 1.2 2022/06/13 06:51:23 cvsuser Exp $") + +/* -*- mode: c; indent-width: 4; -*- */ +/* + * win32 pipe() system calls, + * + * Copyright (c) 2018 - 2022, Adam Young. + * All rights reserved. + * + * This file is part of the GRIEF Editor. + * + * The GRIEF Editor is free software: you can redistribute it + * and/or modify it under the terms of the GRIEF Editor License. + * + * Redistributions of source code must retain the above copyright + * notice, and must be distributed with the license document above. + * + * Redistributions in binary form must reproduce the above copyright + * notice, and must include the license document above in + * the documentation and/or other materials provided with the + * distribution. + * + * This project 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 + * license for more details. + * ==end== + * + * Notice: Portions of this text are reprinted and reproduced in electronic form. from + * IEEE Portable Operating System Interface (POSIX), for reference only. Copyright (C) + * 2001-2003 by the Institute of. Electrical and Electronics Engineers, Inc and The Open + * Group. Copyright remains with the authors and the original Standard can be obtained + * online at http://www.opengroup.org/unix/online.html. + * ==extra== + */ + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 /* enable xp+ features */ +#endif + +#include "win32_internal.h" +#include "win32_misc.h" +#include + +LIBW32_API int +w32_pipe(int fildes[2]) +{ + HANDLE hReadPipe = 0, hWritePipe = 0; + const BOOL ret = CreatePipe(&hReadPipe, &hWritePipe, NULL, 0); + + if (ret) { + fildes[0] = _open_osfhandle((OSFHANDLE)hReadPipe, O_NOINHERIT); + if (fildes[0] < 0) { + CloseHandle(hReadPipe), CloseHandle(hWritePipe); + return -1; + } + fildes[1] = _open_osfhandle((OSFHANDLE)hWritePipe, O_NOINHERIT); + if (fildes[1] < 0) { + _close(fildes[0]), CloseHandle(hWritePipe); + return -1; + } + return 0; + } + w32_errno_set(); + return -1; +} + +/*end*/ diff --git a/libw32/w32_poll.c b/libw32/w32_poll.c index 915e7642..1049f644 100644 --- a/libw32/w32_poll.c +++ b/libw32/w32_poll.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_poll_c,"$Id: w32_poll.c,v 1.8 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_poll_c,"$Id: w32_poll.c,v 1.9 2022/06/11 04:01:45 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -60,7 +60,16 @@ __CIDENT_RCSID(gr_w32_poll_c,"$Id: w32_poll.c,v 1.8 2022/03/21 14:29:41 cvsuser #pragma comment(lib, "Ws2_32.lib") -static int w32_poll(int native, struct pollfd *fds, int cnt, int timeout); +typedef int (*PollIf_t)(int native, struct pollfd *fds, int cnt, int timeout); +typedef int (WINAPI *WSAPoll_t)(LPWSAPOLLFD fdArray, ULONG fds, INT timeout); + +static int w32_poll(int native, struct pollfd *fds, int cnt, int timeout); +static int WSAPollIf(int native, struct pollfd *fds, int cnt, int timeout); +static int WSASelectIf(int native, struct pollfd *fds, int cnt, int timeout); + +static PollIf_t x_PollIf; +static WSAPoll_t x_WSAPoll; + /* // NAME @@ -205,41 +214,86 @@ w32_poll_native(struct pollfd *fds, int cnt, int timeout) static int w32_poll(int native, struct pollfd *fds, int cnt, int timeout) { - // TODO -- dynamically load - // WINSOCK_API_LINKAGE int WSAAPI WSAPoll(LPWSAPOLLFD, ULONG, INT); - // ==> source: ws2_32.lib - // + if (NULL == x_PollIf) { + HMODULE hinst; + + if (0 == (hinst = GetModuleHandleA("ws2_32")) || + 0 == (x_WSAPoll = (WSAPoll_t) GetProcAddress(hinst, "WSAPoll"))) { + x_PollIf = WSASelectIf; + if (hinst) FreeLibrary(hinst); + } else { + x_PollIf = WSAPollIf; + } + } + + if (NULL == fds || cnt <= 0 || cnt > FD_SETSIZE) { + errno = EINVAL; + return -1; + } + + return (x_PollIf)(native, fds, cnt, timeout); +} + + +static int +WSAPollIf(int native, struct pollfd *fds, int cnt, int timeout) +{ + WSAPOLLFD t_fds[FD_SETSIZE]; + int i, ret = 0; + + memset(t_fds, 0, sizeof(WSAPOLLFD) * cnt); + + for (i = 0; i < cnt; ++i) { + fds[i].revents = 0; + if (native) { + t_fds[i].fd = fds[i].fd; + + } else { + t_fds[i].fd = w32_sockhandle((int) fds[i].fd); + if (t_fds[i].fd == (SOCKET) INVALID_SOCKET) { + fds[i].revents = POLLNVAL; + ++ret; + } + } + t_fds[i].events = fds[i].events; + } + + if (0 == ret) { + if ((ret = x_WSAPoll(t_fds, cnt, timeout)) > 0) { + for (i = 0; i < cnt; ++i) { + fds[i].revents = t_fds[i].revents; + } + } + } + return ret; +} + + +static int +WSASelectIf(int native, struct pollfd *fds, int cnt, int timeout) +{ struct timeval tmval = {0}; struct fd_set rfds; struct fd_set wfds; struct fd_set efds; SOCKET s[ FD_SETSIZE ]; - int badcnt, wcnt, ret; - int i; + int i, wcnt = 0, ret = 0; - if (cnt <= 0 || cnt > FD_SETSIZE) { - errno = EINVAL; - return -1; - } - - /* Build fd set */ FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&efds); - for (i = 0; i < cnt; ++i) - fds[i].revents = 0; - - for (i = 0, badcnt = 0, wcnt = 0; i < cnt; ++i) { + for (i = 0; i < cnt; ++i) { SOCKET osf; + fds[i].revents = 0; if (native) { osf = fds[i].fd; } else { osf = w32_sockhandle((int)fds[i].fd); if (osf == (SOCKET)INVALID_SOCKET) { fds[i].revents = POLLNVAL; - ++badcnt; + ++ret; } } s[i] = osf; @@ -251,7 +305,8 @@ w32_poll(int native, struct pollfd *fds, int cnt, int timeout) FD_SET(s[i], &efds); } - if (badcnt) return badcnt; + if (ret) + return ret; /* Select */ if (timeout >= 0) { @@ -270,14 +325,6 @@ w32_poll(int native, struct pollfd *fds, int cnt, int timeout) ret = -1; switch(nerr) { - case WSANOTINITIALISED: /* stack not initialisated; should not occurr */ - break; - case WSAEFAULT: /* invalid address */ - break; - case WSAENETDOWN: /* network shutdown */ - break; - case WSAEINTR: /* interrupted system call */ - break; case WSAENOTSOCK: { /* invalid socket(s) */ int len, type; @@ -294,7 +341,10 @@ w32_poll(int native, struct pollfd *fds, int cnt, int timeout) } } break; - + case WSANOTINITIALISED: /* stack not initialisated; should not occurr */ + case WSAEFAULT: /* invalid address */ + case WSAENETDOWN: /* network shutdown */ + case WSAEINTR: /* interrupted system call */ case WSAEINPROGRESS: /* shouldn't happen */ case WSAEINVAL: default: /* misc */ diff --git a/libw32/w32_popen.c b/libw32/w32_popen.c index fb28d7e1..66ced244 100644 --- a/libw32/w32_popen.c +++ b/libw32/w32_popen.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_popen_c,"$Id: w32_popen.c,v 1.14 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_popen_c,"$Id: w32_popen.c,v 1.17 2022/06/13 06:51:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -249,7 +249,7 @@ PipeA(const char *cmd, const char *mode) argv[2] = cmd; } else { argv[2] = cmd2 = WIN32_STRDUP(cmd); - strncpy(strstr("2>&1", cmd2), " ", 4); + memcpy(strstr("2>&1", cmd2), " ", 4); redirect_error = TRUE; } argv[3] = NULL; @@ -279,7 +279,7 @@ PipeA(const char *cmd, const char *mode) if ('r' == p->readOrWrite) { if (NULL == (p->file = _fdopen( // readable end of the pipe - _open_osfhandle((long)out_read, + _open_osfhandle((OSFHANDLE)out_read, _O_NOINHERIT | ('b' == textOrBinary ? _O_BINARY : _O_TEXT)), 'b' == textOrBinary ? "rb" : "rt"))) { goto pipe_error; @@ -288,7 +288,7 @@ PipeA(const char *cmd, const char *mode) } else { if (NULL == (p->file = _fdopen( // writeable end of the pipe - _open_osfhandle((long)in_write, + _open_osfhandle((OSFHANDLE)in_write, _O_NOINHERIT | ('b' == textOrBinary ? _O_BINARY : _O_TEXT)), 'b' == textOrBinary ? "wb" : "wt"))) { goto pipe_error; @@ -432,7 +432,7 @@ PipeW(const wchar_t *cmd, const char *mode) if ('r' == p->readOrWrite) { if (NULL == (p->file = _fdopen( // readable end of the pipe - _open_osfhandle((long)out_read, + _open_osfhandle((OSFHANDLE)out_read, _O_NOINHERIT | ('b' == textOrBinary ? _O_BINARY : _O_TEXT)), 'b' == textOrBinary ? "rb" : "rt"))) { goto pipe_error; @@ -441,7 +441,7 @@ PipeW(const wchar_t *cmd, const char *mode) } else { if (NULL == (p->file = _fdopen( // writeable end of the pipe - _open_osfhandle((long)in_write, + _open_osfhandle((OSFHANDLE)in_write, _O_NOINHERIT | ('b' == textOrBinary ? _O_BINARY : _O_TEXT)), 'b' == textOrBinary ? "wb" : "wt"))) { goto pipe_error; @@ -619,8 +619,10 @@ w32_pclose(FILE *file) if (pipe) { int status = 0, ret = 0; - if ('w' == pipe->readOrWrite) fclose(file); Close2(pipe->hIn, "pclose/stdin"); - if ('r' == pipe->readOrWrite) fclose(file); Close2(pipe->hOut, "pclose/stdout"); + if ('w' == pipe->readOrWrite) fclose(file); + Close2(pipe->hIn, "pclose/stdin"); + if ('r' == pipe->readOrWrite) fclose(file); + Close2(pipe->hOut, "pclose/stdout"); Close2(pipe->hErr, "pclose/stderr"); if (! w32_child_wait(pipe->handle, &status, FALSE /*block*/)) { ret = -1; @@ -743,7 +745,7 @@ DisplayErrorA( int len; len = _snprintf(buffer, sizeof(buffer), - "Internal Error: %s = %d (%s).\n", msg, rc, rcmsg); + "Internal Error: %s = %u (%s).\n", msg, (unsigned)rc, rcmsg); WriteConsoleA(hOutput, buffer, len, NULL, NULL); } diff --git a/libw32/w32_proctitle.c b/libw32/w32_proctitle.c new file mode 100644 index 00000000..0f14f12a --- /dev/null +++ b/libw32/w32_proctitle.c @@ -0,0 +1,201 @@ +#include +__CIDENT_RCSID(gr_w32_proctitle_c,"$Id: w32_proctitle.c,v 1.2 2022/05/26 13:28:37 cvsuser Exp $") + +/* -*- mode: c; indent-width: 4; -*- */ +/* + * win32 setproctitle + * + * Copyright (c) 2020 - 2022, Adam Young. + * All rights reserved. + * + * This file is part of the GRIEF Editor. + * + * The GRIEF Editor is free software: you can redistribute it + * and/or modify it under the terms of the GRIEF Editor License. + * + * Redistributions of source code must retain the above copyright + * notice, and must be distributed with the license document above. + * + * Redistributions in binary form must reproduce the above copyright + * notice, and must include the license document above in + * the documentation and/or other materials provided with the + * distribution. + * + * This project 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 + * license for more details. + * ==end== + * + * Notice: Portions of this text are reprinted and reproduced in electronic form. from + * IEEE Portable Operating System Interface (POSIX), for reference only. Copyright (C) + * 2001-2003 by the Institute of. Electrical and Electronics Engineers, Inc and The Open + * Group. Copyright remains with the authors and the original Standard can be obtained + * online at http://www.opengroup.org/unix/online.html. + * ==extra== + */ + +#include "win32_internal.h" + +#include +#include + +static void setproctitle_impl(const char *fmt, va_list ap); + + +/* + NAME + setproctitle -- set process title + + SYNOPSIS + #include + #include + + void + setproctitle(const char *fmt, ...); + + void + setproctitle_fast(const char *fmt, ...); + + DESCRIPTION + The setproctitle() library routine sets the process title that appears on + the ps(1) command. The setproctitle_fast() variant is optimized for high + frequency updates, but may make the ps(1) command slightly slower by not + updating the kernel cache of the program arguments. + + The title is set from the executable's name, followed by the result of a + printf(3) style expansion of the arguments as specified by the fmt argument. + If the fmt argument begins with a "-" character, the executable's + name is skipped. + + If fmt is NULL, the process title is restored. + + EXAMPLES + To set the title on a daemon to indicate its activity: + + setproctitle("talking to %s", inet_ntoa(addr)); + + SEE ALSO + ps(1), w(1), kvm(3), kvm_getargv(3), printf(3) + + STANDARDS + The setproctitle() function is implicitly non-standard. Other methods of + causing the ps(1) command line to change, including copying over the + argv[0] string are also implicitly non-portable. It is preferable to use + an operating system supplied setproctitle() if present. + + Unfortunately, it is possible that there are other calling conventions to + other versions of setproctitle(), although none have been found by the + author as yet. This is believed to be the predominant convention. + + It is thought that the implementation is compatible with other systems, + including NetBSD and BSD/OS. + + HISTORY + The setproctitle() function first appeared in FreeBSD 2.2. The + setproctitle_fast() function first appeared in FreeBSD 12. Other operat- + ing systems have similar functions. + + AUTHORS + Peter Wemm stole the idea from the Sendmail 8.7.3 + source code by Eric Allman . + + BUGS + Never pass a string with user-supplied data as a format without using + `%s'. An attacker can put format specifiers in the string to mangle your + stack, leading to a possible security hole. This holds true even if the + string was built using a function like snprintf(), as the resulting + string may still contain user-supplied conversion specifiers for later + interpolation by setproctitle(). + + Always use the proper secure idiom: + + setproctitle("%s", string); + +*/ + +LIBW32_API void +setproctitle(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + setproctitle_impl(fmt, ap); + va_end(ap); +} + + +LIBW32_API void +setproctitle_fast(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + setproctitle_impl(fmt, ap); + va_end(ap); +} + + +static void +setproctitle_impl(const char *fmt, va_list ap) +{ + static WCHAR *saved_console_title, + *saved_window_title; + + if (NULL == fmt) { + if (saved_console_title) { //restore console + SetConsoleTitleW(saved_console_title); + } else if (saved_window_title) { //restore window + HWND hWnd = GetActiveWindow(); + if (hWnd) { + SetWindowTextW(hWnd, saved_window_title); + } + } + + } else { + char n_title[2 * 1024]; + + if (vsnprintf(n_title, _countof(n_title), fmt, ap) > 0) { + HWND hWnd = 0; + + if (! saved_console_title && ! saved_window_title) { //original titles + WCHAR t_title[2 * 1024]; + DWORD ret; + + //console + if (0 != (ret = GetConsoleTitleW(t_title, _countof(t_title)))) { + const size_t sz = (ret + 1) * sizeof(WCHAR); + //If the function succeeds, the return value is the length of the console window's title, in characters. + //Buffer receives a null-terminated string containing the title. + //If the buffer is too small to store the title, the function stores as many characters of the title as will fit in the buffer, ending with a null terminator. + // + if (NULL != (saved_console_title = (WCHAR *)malloc(sz))) { + memcpy(saved_console_title, t_title, sz); + } + } + + // window + if (0 != (hWnd = GetActiveWindow())) { + if (0 != (ret = GetWindowTextLength(hWnd))) { + const size_t sz = (ret + 1) * sizeof(WCHAR); + if (NULL != (saved_window_title = (WCHAR *)calloc(sz, 1))) { + if (! GetWindowTextW(hWnd, saved_window_title, sz)) { + free(saved_window_title); + saved_window_title = NULL; + } + } + } + } + } + + if (! SetConsoleTitleA(n_title)) { + if (!hWnd) hWnd = GetActiveWindow(); + if (hWnd) { + SetWindowTextA(hWnd, n_title); + } + } + } + } +} + +/*end*/ diff --git a/libw32/w32_pwd.c b/libw32/w32_pwd.c index 988abdf1..3f681457 100644 --- a/libw32/w32_pwd.c +++ b/libw32/w32_pwd.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_pwd_c,"$Id: w32_pwd.c,v 1.15 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_pwd_c,"$Id: w32_pwd.c,v 1.17 2022/05/31 16:18:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -50,6 +50,8 @@ __CIDENT_RCSID(gr_w32_pwd_c,"$Id: w32_pwd.c,v 1.15 2022/03/21 14:29:41 cvsuser E #pragma comment(lib, "Netapi32.lib") +struct WellKnownSID; + static void fill_passwds(void); static int fill_builtin(const struct WellKnownSID *wksid, struct passwd *pwd, char *name, size_t namlen); static unsigned RID(PSID sid); @@ -456,6 +458,12 @@ static struct WellKnownSID { DWORD SubAuth[2]; } well_known_sids[] = { +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#define SECURITY_THIS_ORGANIZATION_RID 15 +#define SECURITY_LOCAL_SERVICE_RID 19 +#define SECURITY_NETWORK_SERVICE_RID 20 +#endif + // See: "wmic sysaccount get name,sid" {"S-1-5-1", SECURITY_NT_AUTHORITY, 1, {SECURITY_DIALUP_RID}}, {"S-1 5-2", SECURITY_NT_AUTHORITY, 1, {SECURITY_NETWORK_RID}}, @@ -638,7 +646,7 @@ fill_builtin(const struct WellKnownSID *wksid, pSID = NULL; } } else { - if (! ConvertStringSidToSidA(wksid->name, &pSID)) { + if (! ConvertStringSidToSidA((char *)wksid->name, &pSID)) { pSID = NULL; } } diff --git a/libw32/w32_reparse.c b/libw32/w32_reparse.c index 8abfe60b..764c7c8e 100644 --- a/libw32/w32_reparse.c +++ b/libw32/w32_reparse.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_reparse_c,"$Id: w32_reparse.c,v 1.8 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_reparse_c,"$Id: w32_reparse.c,v 1.9 2022/05/26 11:53:27 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -40,6 +40,7 @@ __CIDENT_RCSID(gr_w32_reparse_c,"$Id: w32_reparse.c,v 1.8 2022/03/21 14:29:41 cv #include #include #include +#include #ifdef HAVE_WCHAR_H #include #endif diff --git a/libw32/w32_rwlock.c b/libw32/w32_rwlock.c index 48fadbb1..112b6614 100644 --- a/libw32/w32_rwlock.c +++ b/libw32/w32_rwlock.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_rwlock_c,"$Id: w32_rwlock.c,v 1.12 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_rwlock_c,"$Id: w32_rwlock.c,v 1.16 2022/06/02 12:16:36 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -35,14 +35,16 @@ __CIDENT_RCSID(gr_w32_rwlock_c,"$Id: w32_rwlock.c,v 1.12 2022/03/21 14:29:41 cvs * ==extra== */ +#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x601) +#undef _WIN32_WINNT +#endif #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0601 /* enable vista features */ #endif #include -#define WINDOWS_MEAN_AND_LEAN -#include +#include "win32_include.h" #include typedef void (WINAPI *InitializeSRWLock_t)(PSRWLOCK); @@ -59,7 +61,8 @@ typedef struct { } xpsrwlock_t; typedef struct { - unsigned magic; + LONG magic; + LONG status; #define RW_MAGIC 0x57333272 /* W32r */ union { SRWLOCK srw; /* Slim Reader/Writer (SRW) Locks (vista+) */ @@ -134,6 +137,17 @@ rwlock_init(struct rwlock *rwlock) } +LIBW32_API void +rwlock_destroy(struct rwlock *rwlock) +{ + rwlock_imp_t *rw = (rwlock_imp_t *)rwlock; + + assert(RW_MAGIC == rw->magic); + assert(0 == rw->status); + rw->magic = 0; +} + + LIBW32_API void rwlock_rdlock(struct rwlock *rwlock) { @@ -141,6 +155,8 @@ rwlock_rdlock(struct rwlock *rwlock) assert(RW_MAGIC == rw->magic); acquire_srw_lock_shared(&rw->srw); + assert(-1 != rw->status); + InterlockedIncrement(&(rw)->status); } @@ -150,7 +166,9 @@ rwlock_wrlock(struct rwlock *rwlock) rwlock_imp_t *rw = (rwlock_imp_t *)rwlock; assert(RW_MAGIC == rw->magic); - acquire_srw_lock_exclusive (&rw->srw); + acquire_srw_lock_exclusive(&rw->srw); + assert(0 == rw->status); + rw->status = -1; } @@ -160,6 +178,8 @@ rwlock_rdunlock(struct rwlock *rwlock) rwlock_imp_t *rw = (rwlock_imp_t *)rwlock; assert(RW_MAGIC == rw->magic); + assert(rw->status > 0); + InterlockedDecrement(&(rw)->status); release_srw_lock_shared(&rw->srw); } @@ -170,10 +190,43 @@ rwlock_wrunlock(struct rwlock *rwlock) rwlock_imp_t *rw = (rwlock_imp_t *)rwlock; assert(RW_MAGIC == rw->magic); + assert(-1 == rw->status); + rw->status = 0; release_srw_lock_exclusive(&rw->srw); } +LIBW32_API void +rwlock_unlock(struct rwlock *rwlock) +{ + rwlock_imp_t *rw = (rwlock_imp_t *)rwlock; + + assert(0 != rw->status); + if (rw->status < 0) { + rwlock_wrunlock(rwlock); + } else { + rwlock_rdunlock(rwlock); + } +} + + +// extension +LIBW32_API int +rwlock_status(struct rwlock *rwlock) +{ + rwlock_imp_t *rw = (rwlock_imp_t *)rwlock; + + // + // -2 = invalid + // 0 = unlocked. + // -1 = locked exclusive. + // >0 = reader count. + // + if (NULL == rw || RW_MAGIC != rw->magic) return -2; + return (int) rw->status; +} + + ///////////////////////////////////////////////////////////////////////////////// // SRW emulation // diff --git a/libw32/w32_select.c b/libw32/w32_select.c index e6df35be..7aedb151 100644 --- a/libw32/w32_select.c +++ b/libw32/w32_select.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_select_c,"$Id: w32_select.c,v 1.14 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_select_c,"$Id: w32_select.c,v 1.16 2022/05/26 13:28:37 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -41,7 +41,7 @@ __CIDENT_RCSID(gr_w32_select_c,"$Id: w32_select.c,v 1.14 2022/03/21 14:29:41 cvs #include #include #define WIN32_SOCKET_H_CLEAN // disable mapping -#ifdef HAVE_SYS_SOCKET_H +#ifdef HAVE_SYS_SOCKET_H #include #endif #include @@ -85,7 +85,7 @@ static void sel_unknown( Select_t *selfd ); /* * select() system call */ -int +LIBW32_API int w32_select( int nfs, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *tm) { @@ -207,12 +207,11 @@ sel_build( static int -sel_wait( u_int cnt, Select_t *selfds, DWORD timeout ) +sel_wait(u_int cnt, Select_t *selfds, DWORD timeout) { - DWORD stick; + DWORD stick, ret; HANDLE waitfor[MAXIMUM_WAIT_OBJECTS]; // system limit u_int i = 0; - int ret; if (cnt > sizeof(waitfor)/sizeof(waitfor[0])) return -EINVAL; @@ -222,20 +221,22 @@ sel_wait( u_int cnt, Select_t *selfds, DWORD timeout ) i++; } + assert(0 == WAIT_OBJECT_0); stick = GetTickCount(); // start tick + for (;;) { - // Wait for event/timeout + // wait for event/timeout if ((ret = WaitForMultipleObjects (cnt, waitfor, FALSE, timeout)) == WAIT_FAILED) { return -EIO; } - // Timeout + // timeout if (ret == WAIT_TIMEOUT) { break; } - // Who caused this ?? - if (ret >= WAIT_OBJECT_0 && ret <= (int)(WAIT_OBJECT_0 + cnt + 1)) { + // event + if (ret <= (DWORD)(WAIT_OBJECT_0 + cnt + 1)) { i = ret - WAIT_OBJECT_0; assert(waitfor[i] == selfds[i].s_handle); (selfds[i].s_poll)( selfds+i ); @@ -243,14 +244,14 @@ sel_wait( u_int cnt, Select_t *selfds, DWORD timeout ) return i+1; } - // Calculate next timeout frame... - if (timeout != INFINITE) - { + // calculate next timeout frame... + if (timeout != INFINITE) { DWORD ctick, ttick; // current and total ticks ctick = GetTickCount(); - if ((ttick = sel_ticks( stick, ctick )) > timeout) + if ((ttick = sel_ticks( stick, ctick )) > timeout) { break; + } timeout -= ttick; stick = ctick; } diff --git a/libw32/w32_setrlimit.c b/libw32/w32_setrlimit.c new file mode 100644 index 00000000..33ecfa16 --- /dev/null +++ b/libw32/w32_setrlimit.c @@ -0,0 +1,74 @@ +#include +__CIDENT_RCSID(gr_w32_setrlimit_c,"$Id: w32_setrlimit.c,v 1.2 2022/05/26 13:17:35 cvsuser Exp $") + +/* -*- mode: c; indent-width: 4; -*- */ +/* + * win32 setrlimit() system calls + * + * Copyright (c) 2020 - 2022, Adam Young. + * All rights reserved. + * + * This file is part of the GRIEF Editor. + * + * The GRIEF Editor is free software: you can redistribute it + * and/or modify it under the terms of the GRIEF Editor License. + * + * Redistributions of source code must retain the above copyright + * notice, and must be distributed with the license document above. + * + * Redistributions in binary form must reproduce the above copyright + * notice, and must include the license document above in + * the documentation and/or other materials provided with the + * distribution. + * + * This project 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 + * license for more details. + * ==end== + * + * Notice: Portions of this text are reprinted and reproduced in electronic form. from + * IEEE Portable Operating System Interface (POSIX), for reference only. Copyright (C) + * 2001-2003 by the Institute of. Electrical and Electronics Engineers, Inc and The Open + * Group. Copyright remains with the authors and the original Standard can be obtained + * online at http://www.opengroup.org/unix/online.html. + * ==extra== + */ + +#include "win32_internal.h" + +#include +#include +#include + +int +setrlimit(int resource, const struct rlimit *rlp) +{ + if (NULL == rlp) { + errno = EINVAL; + } else if (rlp->rlim_cur > rlp->rlim_max) { + errno = EINVAL; + } else { + switch (resource) { + case RLIMIT_NOFILE: { + int newmax, ret = 0; + if (rlp->rlim_max > WIN32_FILDES_DEF) { +#if defined(__WATCOMC__) + if (_grow_handles(rlp->rlim_max) < rlp->rlim_max) { +#else + if (-1 == (newmax = _setmaxstdio(rlp->rlim_max))) { +#endif + errno = EINVAL; + ret = -1; + } + w32_sockfd_limit(rlp->rlim_max); + } + return ret; + } + } + errno = ENOSYS; + } + return -1; +} + +/*end*/ diff --git a/libw32/w32_shell.c b/libw32/w32_shell.c index 1218a1eb..8c795deb 100644 --- a/libw32/w32_shell.c +++ b/libw32/w32_shell.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_shell_c,"$Id: w32_shell.c,v 1.14 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_shell_c,"$Id: w32_shell.c,v 1.16 2022/06/13 06:51:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -275,7 +275,7 @@ ShellA(const char *shell, const char *cmd, } else { ShellCleanup((void *)&pd); - (void) w32_waitpid((int) hProc, &status, 0); + (void) w32_waitpid(w32_HTOI(hProc), &status, 0); } free(shname); @@ -417,7 +417,7 @@ ShellW(const wchar_t *shell, const wchar_t *cmd, } else { ShellCleanup((void *)&pd); - (void) w32_waitpid((int) hProc, &status, 0); + (void) w32_waitpid(w32_HTOI(hProc), &status, 0); } free(shname); @@ -602,11 +602,11 @@ w32_spawnA2( // Open LIBC compatible handles (if required) and launch child process // if ((*Stdin >= 0 || - (in = _open_osfhandle((long)hInputWrite, _O_NOINHERIT)) >= 0) && + (in = _open_osfhandle((OSFHANDLE)hInputWrite, _O_NOINHERIT)) >= 0) && (*Stdout >= 0 || - (out = _open_osfhandle((long)hOutputRead, _O_NOINHERIT)) >= 0) && + (out = _open_osfhandle((OSFHANDLE)hOutputRead, _O_NOINHERIT)) >= 0) && (Stderr == NULL || *Stderr >= 0 || - (err = _open_osfhandle((long)hErrorRead, _O_NOINHERIT)) >= 0)) { + (err = _open_osfhandle((OSFHANDLE)hErrorRead, _O_NOINHERIT)) >= 0)) { hProc = w32_child_execA(args, hInputRead, hOutputWrite, hErrorWrite); } @@ -658,7 +658,7 @@ w32_spawnA2( Close(hErrorRead); } } - return (int)(hProc); + return w32_HTOI(hProc); } @@ -745,11 +745,11 @@ w32_spawnW2( // Open LIBC compatible handles (if required) and launch child process // if ((*Stdin >= 0 || - (in = _open_osfhandle((long)hInputWrite, _O_NOINHERIT)) >= 0) && + (in = _open_osfhandle((OSFHANDLE)hInputWrite, _O_NOINHERIT)) >= 0) && (*Stdout >= 0 || - (out = _open_osfhandle((long)hOutputRead, _O_NOINHERIT)) >= 0) && + (out = _open_osfhandle((OSFHANDLE)hOutputRead, _O_NOINHERIT)) >= 0) && (Stderr == NULL || *Stderr >= 0 || - (err = _open_osfhandle((long)hErrorRead, _O_NOINHERIT)) >= 0)) { + (err = _open_osfhandle((OSFHANDLE)hErrorRead, _O_NOINHERIT)) >= 0)) { hProc = w32_child_execW(args, hInputRead, hOutputWrite, hErrorWrite); } @@ -801,7 +801,7 @@ w32_spawnW2( Close(hErrorRead); } } - return (int)(hProc); + return w32_HTOI(hProc); } @@ -1060,7 +1060,7 @@ w32_execA(win32_exec_t *args) args->hInput = hInputWrite; args->hOutput = hOutputRead; args->hError = hErrorRead; - return (int)args->hProc; + return w32_HTOI(args->hProc); einval:; Close(hOutputReadTmp); Close(hInputWriteTmp); Close(hErrorReadTmp); @@ -1118,7 +1118,7 @@ w32_execW(win32_execw_t *args) args->hInput = hInputWrite; args->hOutput = hOutputRead; args->hError = hErrorRead; - return (int)args->hProc; + return w32_HTOI(args->hProc); einval:; Close(hOutputReadTmp); Close(hInputWriteTmp); Close(hErrorReadTmp); @@ -1275,7 +1275,7 @@ DisplayErrorA( int len; len = _snprintf(buffer, sizeof(buffer), - "Internal Error: %s = %d (%s).\n", msg, rc, rcmsg); + "Internal Error: %s = %u (%s).\n", msg, (unsigned)rc, rcmsg); WriteConsoleA(hOutput, buffer, len, NULL, NULL); } @@ -1290,7 +1290,7 @@ DisplayErrorW( int len; len = _snwprintf(buffer, _countof(buffer), - L"Internal Error: %s = %d (%s).\n", msg, rc, rcmsg); + L"Internal Error: %s = %u (%s).\n", msg, (unsigned)rc, rcmsg); WriteConsoleW(hOutput, buffer, len, NULL, NULL); } diff --git a/libw32/w32_signal.c b/libw32/w32_signal.c index a90b36e0..d4b833e6 100644 --- a/libw32/w32_signal.c +++ b/libw32/w32_signal.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_signal_c,"$Id: w32_signal.c,v 1.15 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_signal_c,"$Id: w32_signal.c,v 1.19 2022/06/13 16:05:42 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -39,7 +39,7 @@ __CIDENT_RCSID(gr_w32_signal_c,"$Id: w32_signal.c,v 1.15 2022/03/21 14:29:41 cvs #include #include -#if !defined(__MINGW32__) +#if !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR) /* // NAME // sigemptyset - initialize and empty a signal set @@ -62,9 +62,10 @@ __CIDENT_RCSID(gr_w32_signal_c,"$Id: w32_signal.c,v 1.15 2022/03/21 14:29:41 cvs LIBW32_API int sigemptyset(sigset_t *ss) { -// if (ss) { -// memset(ss, 0, sizeof(*ss)); -// } + if (ss) { + memset(ss, 0, sizeof(*ss)); + return 0; + } errno = EINVAL; return -1; } @@ -73,6 +74,11 @@ sigemptyset(sigset_t *ss) LIBW32_API int sigaction(int sig, struct sigaction *sa, struct sigaction *osa) { + switch (sig) { + case SIGPIPE: + return 0; + } + // if (sa) { // if (osa) { // osa->sa_handler = signal(sig, (void (__cdecl *)(int))sa->sa_handler); @@ -81,7 +87,6 @@ sigaction(int sig, struct sigaction *sa, struct sigaction *osa) // signal(sig, (void (__cdecl *)(int))sa->sa_handler); // } // } - errno = EINVAL; return -1; } diff --git a/libw32/w32_sockbase.c b/libw32/w32_sockbase.c index 12a567c7..2b339466 100644 --- a/libw32/w32_sockbase.c +++ b/libw32/w32_sockbase.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_sockbase_c,"$Id: w32_sockbase.c,v 1.7 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_sockbase_c,"$Id: w32_sockbase.c,v 1.9 2022/06/11 04:01:45 cvsuser Exp $") /* * win32 socket () system calls @@ -56,7 +56,12 @@ __CIDENT_RCSID(gr_w32_sockbase_c,"$Id: w32_sockbase.c,v 1.7 2022/03/21 14:29:41 #pragma comment(lib, "Ws2_32.lib") static int x_sockinit = 0; /* initialisation status */ -LIBW32_API int w32_h_errno = 0; /* lookup error */ +/*LIBW32_API*/ int w32_h_errno = 0; /* lookup error */ + +#undef getaddrinfo +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +INT WSAAPI getaddrinfo(PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA *pHints, PADDRINFOA *ppResult); +#endif /* @@ -90,7 +95,6 @@ w32_getaddrinfo(const char *nodename, const char *servname, { int done = 0, ret; -#undef getaddrinfo retry:; if (0 != (ret = getaddrinfo(nodename, servname, hints, res))) { if (0 == done++) { diff --git a/libw32/w32_socket.c b/libw32/w32_socket.c index 26fca78d..23043198 100644 --- a/libw32/w32_socket.c +++ b/libw32/w32_socket.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_socket_c,"$Id: w32_socket.c,v 1.19 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_socket_c,"$Id: w32_socket.c,v 1.22 2022/06/15 04:43:20 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -76,7 +76,7 @@ retry:; w32_sockerror(); ret = -1; } else if ((ret = (int)s) < WIN32_FILDES_MAX && - (ret = _open_osfhandle((long)s, 0)) == -1) { + (ret = _open_osfhandle((OSFHANDLE)s, 0)) == -1) { closesocket(s); errno = EMFILE; } else { @@ -207,7 +207,7 @@ w32_accept_fd(int fd, struct sockaddr *addr, int *addrlen) w32_sockerror(); ret = -1; } else if ((ret = (int)s) < WIN32_FILDES_MAX && - (ret = _open_osfhandle((long)s, 0)) == -1) { + (ret = _open_osfhandle((OSFHANDLE)s, 0)) == -1) { (void) closesocket(s); errno = EMFILE; } else { @@ -364,17 +364,22 @@ w32_recvfrom_fd(int fd, char *buf, int len, int flags, /* - * socksetblockingmode() + * socknonblockingio() */ LIBW32_API int -w32_sockblockingmode_fd(int fd, int enabled) +w32_socknonblockingio_fd(int fd, int enabled) { SOCKET osf; - int ret; + int ret = 0; if ((osf = w32_sockhandle(fd)) == (SOCKET)INVALID_SOCKET) { ret = -1; } else { + /* FIONBIO --- + * enables or disables the blocking mode for the socket based on the numerical value of iMode. + * If mode = 0, blocking is enabled; + * If mode != 0, non-blocking mode is enabled. + */ u_long mode = (long)enabled; if ((ret = ioctlsocket(osf, FIONBIO, &mode)) == -1 /*SOCKET_ERROR*/) { w32_sockerror(); @@ -384,6 +389,27 @@ w32_sockblockingmode_fd(int fd, int enabled) } +/* + * sockinheritable + */ +LIBW32_API int +w32_sockinheritable_fd(int fd, int enabled) +{ + SOCKET osf; + int ret = 0; + + if ((osf = w32_sockhandle(fd)) == (SOCKET)INVALID_SOCKET) { + ret = -1; + } else { + if (! SetHandleInformation((HANDLE)osf, HANDLE_FLAG_INHERIT, enabled ? 1 : 0)) { + w32_sockerror(); + ret = -1; + } + } + return ret; +} + + /* * sockwrite() system call; aka write() for sockets. */ diff --git a/libw32/w32_socket2.c b/libw32/w32_socket2.c index 166b4a20..43933c0e 100644 --- a/libw32/w32_socket2.c +++ b/libw32/w32_socket2.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_socket2_c,"$Id: w32_socket2.c,v 1.9 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_socket2_c,"$Id: w32_socket2.c,v 1.12 2022/06/15 04:43:20 cvsuser Exp $") /* * win32 socket () system calls @@ -25,6 +25,13 @@ __CIDENT_RCSID(gr_w32_socket2_c,"$Id: w32_socket2.c,v 1.9 2022/03/21 14:29:41 cv * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * license for more details. * ==end== + * + * Notice: Portions of this text are reprinted and reproduced in electronic form. from + * IEEE Portable Operating System Interface (POSIX), for reference only. Copyright (C) + * 2001-2003 by the Institute of. Electrical and Electronics Engineers, Inc and The Open + * Group. Copyright remains with the authors and the original Standard can be obtained + * online at http://www.opengroup.org/unix/online.html. + * ==extra== */ #ifndef _WIN32_WINNT @@ -61,6 +68,7 @@ nativehandle(int fd) { if (fd >= 0) return (SOCKET)fd; + errno = EBADF; /* sockfd is not a valid open file descriptor */ return INVALID_SOCKET; } @@ -71,7 +79,7 @@ nativehandle(int fd) LIBW32_API int w32_socket_native(int af, int type, int protocol) { - int done = 0, ret; + int done = 0; SOCKET s; #undef socket @@ -83,7 +91,6 @@ retry:; } } w32_sockerror(); - ret = -1; } else { SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); assert((int)s < 0x7fffffff); @@ -185,7 +192,7 @@ w32_listen_native(int fd, int num) #undef listen if ((osf = nativehandle(fd)) == (SOCKET)INVALID_SOCKET) { ret = -1; - } else if (listen((SOCKET)osf, num) != 0) { + } else if (listen((SOCKET)osf, (-1 == num ? SOMAXCONN : num)) != 0) { w32_sockerror(); ret = -1; } @@ -336,7 +343,7 @@ w32_sendmsg_native(int fd, const struct msghdr *message, int flags) int ret = -1; if (NULL == message || NULL == message->msg_iov || - message->msg_iovlen < 0 || message->msg_iovlen > IOV_MAX) { + /*message->msg_iovlen < 0 ||*/ message->msg_iovlen > IOV_MAX) { errno = EINVAL; /* invalid argument */ } else if (0 == message->msg_iovlen) { @@ -417,19 +424,23 @@ w32_recvfrom_native(int fd, char *buf, int len, int flags, } - /* - * sockblockingmode + * socknonblockingio */ LIBW32_API int -w32_sockblockingmode_native(int fd, int enabled) +w32_socknonblockingio_native(int fd, int enabled) { SOCKET osf; - int ret; + int ret = 0; if ((osf = nativehandle(fd)) == (SOCKET)INVALID_SOCKET) { ret = -1; } else { + /* FIONBIO --- + * enables or disables the blocking mode for the socket based on the numerical value of iMode. + * If mode = 0, blocking is enabled; + * If mode != 0, non-blocking mode is enabled. + */ u_long mode = (long)enabled; if ((ret = ioctlsocket(osf, FIONBIO, &mode)) == -1 /*SOCKET_ERROR*/) { w32_sockerror(); @@ -439,6 +450,27 @@ w32_sockblockingmode_native(int fd, int enabled) } +/* + * sockinheritable + */ +LIBW32_API int +w32_sockinheritable_native(int fd, int enabled) +{ + SOCKET osf; + int ret = 0; + + if ((osf = nativehandle(fd)) == (SOCKET)INVALID_SOCKET) { + ret = -1; + } else { + if (! SetHandleInformation((HANDLE)osf, HANDLE_FLAG_INHERIT, enabled ? 1 : 0)) { + w32_sockerror(); + ret = -1; + } + } + return ret; +} + + /* * sockwrite() system call; aka write() for sockets. */ @@ -511,7 +543,7 @@ w32_shutdown_native(int fd, int how) #undef shutdown if ((osf = nativehandle(fd)) == (SOCKET)INVALID_SOCKET) { ret = -1; - } else if ((ret = shutdown((SOCKET)osf, how)) == -1) { + } else if ((ret = shutdown((SOCKET)osf, how)) == -1 /*SOCKET_ERROR*/) { w32_sockerror(); } return ret; diff --git a/libw32/w32_sockfd.c b/libw32/w32_sockfd.c index b329ace8..112ed8e9 100644 --- a/libw32/w32_sockfd.c +++ b/libw32/w32_sockfd.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_sockfd_c,"$Id: w32_sockfd.c,v 1.7 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_sockfd_c,"$Id: w32_sockfd.c,v 1.10 2022/06/13 06:51:23 cvsuser Exp $") /* * win32 socket file-descriptor support @@ -24,6 +24,13 @@ __CIDENT_RCSID(gr_w32_sockfd_c,"$Id: w32_sockfd.c,v 1.7 2022/03/21 14:29:41 cvsu * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * license for more details. * ==end== + * + * Notice: Portions of this text are reprinted and reproduced in electronic form. from + * IEEE Portable Operating System Interface (POSIX), for reference only. Copyright (C) + * 2001-2003 by the Institute of. Electrical and Electronics Engineers, Inc and The Open + * Group. Copyright remains with the authors and the original Standard can be obtained + * online at http://www.opengroup.org/unix/online.html. + * ==extra== */ #ifndef _WIN32_WINNT @@ -32,6 +39,7 @@ __CIDENT_RCSID(gr_w32_sockfd_c,"$Id: w32_sockfd.c,v 1.7 2022/03/21 14:29:41 cvsu #include "win32_include.h" #include "win32_internal.h" +#include "win32_misc.h" #include #include @@ -45,8 +53,8 @@ __CIDENT_RCSID(gr_w32_sockfd_c,"$Id: w32_sockfd.c,v 1.7 2022/03/21 14:29:41 cvsu #include #include -static int x_fdinit; /* hard limit */ -static int x_fdlimit = 128; /* soft limit */ +static int x_fdhard; /* hard limit */ +static int x_fdlimit = WIN32_FILDES_DEF; /* soft limit */ static SOCKET * x_fdsockets; @@ -56,14 +64,14 @@ static SOCKET * x_fdsockets; LIBW32_API void w32_sockfd_init(void) { - if (!x_fdinit) { + if (0 == x_fdhard) { unsigned s; if (NULL != (x_fdsockets = calloc(sizeof(SOCKET), WIN32_FILDES_MAX))) { for (s = 0; s < WIN32_FILDES_MAX; ++s) { x_fdsockets[s] = INVALID_SOCKET; } - x_fdinit = WIN32_FILDES_MAX; + x_fdhard = WIN32_FILDES_MAX; } } } @@ -76,9 +84,10 @@ LIBW32_API int w32_sockfd_limit(int fd) { assert(fd >= -1 /*error*/ && fd < WIN32_FILDES_MAX); - if (fd > x_fdlimit) { - x_fdlimit = fd; + if ((x_fdlimit = fd) > WIN32_FILDES_MAX) { + x_fdlimit = WIN32_FILDES_MAX; /* cap */ + } } return fd; } @@ -95,7 +104,7 @@ w32_sockfd_open(int fd, SOCKET s) w32_sockfd_init(); w32_sockfd_limit(fd); - if (x_fdsockets && fd >= 0 && fd < x_fdinit) { + if (x_fdsockets && fd >= 0 && fd < x_fdhard) { assert(s != INVALID_SOCKET); x_fdsockets[fd] = s; } @@ -111,7 +120,7 @@ w32_sockfd_get(int fd) if (fd >= WIN32_FILDES_MAX) { /* not an osf handle; hard limit */ return fd; - } else if (fd >= 0 && fd < x_fdinit) { + } else if (fd >= 0 && fd < x_fdhard) { if (x_fdsockets) { /* local socket mapping */ return x_fdsockets[fd]; @@ -135,7 +144,7 @@ w32_sockfd_get(int fd) LIBW32_API void w32_sockfd_close(int fd, SOCKET s) { - if (fd >= 0 && fd < x_fdinit) { + if (fd >= 0 && fd < x_fdhard) { if (s == INVALID_SOCKET || x_fdsockets[fd] == s) { x_fdsockets[fd] = INVALID_SOCKET; } @@ -180,18 +189,18 @@ w32_issockfd(int fd, SOCKET *s) */ t_s = (SOCKET)fd; - } else if (fd >= x_fdinit || /* local socket mapping */ + } else if (fd >= x_fdhard || /* local socket mapping */ (t_s = x_fdsockets[fd]) == INVALID_SOCKET) { /* * MSVC 2015+ no longer suitable; asserts when out-of-range. * Unfortunately socket handles can be small numeric values yet so are file descriptors. */ - if (fd >= 0x80 && 0 == (fd & 0x3) && IsSocket((HANDLE)fd)) { + if (fd >= 0x80 && 0 == (fd & 0x3) && IsSocket(w32_ITOH(fd))) { t_s = (SOCKET)fd; } else if (fd >= x_fdlimit || - _get_osfhandle(fd) == (SOCKET)INVALID_HANDLE_VALUE) { + _get_osfhandle(fd) == (OSFHANDLE)INVALID_HANDLE_VALUE) { t_s = (SOCKET)fd; /* invalid assume socket; otherwise file */ } } diff --git a/libw32/w32_sockpair.c b/libw32/w32_sockpair.c index cecb0eb7..a5063b1b 100644 --- a/libw32/w32_sockpair.c +++ b/libw32/w32_sockpair.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_sockpair_c,"$Id: w32_sockpair.c,v 1.9 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_sockpair_c,"$Id: w32_sockpair.c,v 1.12 2022/06/13 06:51:23 cvsuser Exp $") /* * win32 socket file-descriptor support @@ -24,6 +24,13 @@ __CIDENT_RCSID(gr_w32_sockpair_c,"$Id: w32_sockpair.c,v 1.9 2022/03/21 14:29:41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * license for more details. * ==end== + * + * Notice: Portions of this text are reprinted and reproduced in electronic form. from + * IEEE Portable Operating System Interface (POSIX), for reference only. Copyright (C) + * 2001-2003 by the Institute of. Electrical and Electronics Engineers, Inc and The Open + * Group. Copyright remains with the authors and the original Standard can be obtained + * online at http://www.opengroup.org/unix/online.html. + * ==notice== */ #ifndef _WIN32_WINNT @@ -167,9 +174,9 @@ w32_socketpair_fd(int af, int type, int proto, int sock[2]) int s0 = -1, s1 = -1; if (sock[0] < WIN32_FILDES_MAX || - (s0 = _open_osfhandle((long)sock[0], 0)) == -1 || + (s0 = _open_osfhandle((OSFHANDLE)sock[0], 0)) == -1 || sock[1] < WIN32_FILDES_MAX || - (s1 = _open_osfhandle((long)sock[1], 0)) == -1) { + (s1 = _open_osfhandle((OSFHANDLE)sock[1], 0)) == -1) { closesocket((SOCKET)sock[1]); if (s0 >= 0) _close(s0); @@ -202,8 +209,8 @@ w32_socketpair_native(int af, int type, int proto, int sock[2]) int addr2_len = sizeof (addr2); int nerr; - sock[0] = INVALID_SOCKET; - sock[1] = INVALID_SOCKET; + sock[0] = -1; + sock[1] = -1; assert(af == AF_INET && type == SOCK_STREAM && (0 == proto || IPPROTO_IP == proto || IPPROTO_TCP == proto)); @@ -213,7 +220,11 @@ w32_socketpair_native(int af, int type, int proto, int sock[2]) goto error; memset((void*)&addr1, 0, sizeof(addr1)); +#if defined(__MINGW32__) + addr1.sin_family = (short)af; +#else addr1.sin_family = (ADDRESS_FAMILY)af; +#endif addr1.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr1.sin_port = 0; @@ -229,7 +240,7 @@ w32_socketpair_native(int af, int type, int proto, int sock[2]) if (listen(listen_sock, 1)) goto error; - if ((sock[0] = socket(af, type, proto)) == INVALID_SOCKET) + if ((sock[0] = socket(af, type, proto)) == (int)INVALID_SOCKET) goto error; #undef connect @@ -237,7 +248,7 @@ w32_socketpair_native(int af, int type, int proto, int sock[2]) goto error; #undef accept - if ((sock[1] = accept(listen_sock, 0, 0)) == INVALID_SOCKET) + if ((sock[1] = accept(listen_sock, 0, 0)) == (int)INVALID_SOCKET) goto error; #undef getpeername @@ -264,10 +275,10 @@ w32_socketpair_native(int af, int type, int proto, int sock[2]) if (listen_sock != INVALID_SOCKET) closesocket(listen_sock); - if (sock[0] != INVALID_SOCKET) + if (sock[0] != (int)INVALID_SOCKET) closesocket(sock[0]); - if (sock[1] != INVALID_SOCKET) + if (sock[1] != (int)INVALID_SOCKET) closesocket(sock[1]); WSASetLastError(nerr); diff --git a/libw32/w32_statfs.c b/libw32/w32_statfs.c index 7d9d2f1b..45bf84e3 100644 --- a/libw32/w32_statfs.c +++ b/libw32/w32_statfs.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_statfs_c,"$Id: w32_statfs.c,v 1.19 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_statfs_c,"$Id: w32_statfs.c,v 1.20 2022/05/26 11:19:24 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -429,7 +429,7 @@ enum_volumes(struct statfs *result, long resultsize, int *mnts) errno = 0; - if (INVALID_HANDLE_VALUE != (handle = FindFirstVolumeW(volume, ARRAYSIZE(volume)))) { + if (INVALID_HANDLE_VALUE != (handle = FindFirstVolumeW(volume, _countof(volume)))) { do { // // query volume(s). @@ -478,7 +478,7 @@ enum_volumes(struct statfs *result, long resultsize, int *mnts) // // next volume. - ret = FindNextVolumeW(handle, volume, ARRAYSIZE(volume)); + ret = FindNextVolumeW(handle, volume, _countof(volume)); if (! ret) { const DWORD lasterr = GetLastError(); if (lasterr != ERROR_NO_MORE_FILES) { diff --git a/libw32/w32_string.c b/libw32/w32_string.c index 218ab555..310a08ea 100644 --- a/libw32/w32_string.c +++ b/libw32/w32_string.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_string_c,"$Id: w32_string.c,v 1.14 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_string_c,"$Id: w32_string.c,v 1.15 2022/05/31 16:18:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -36,11 +36,13 @@ __CIDENT_RCSID(gr_w32_string_c,"$Id: w32_string.c,v 1.14 2022/03/21 14:29:41 cvs */ #include "win32_internal.h" + #include #include #include +#if defined(NEED_STRCASECMP) LIBW32_API int strcasecmp(const char *s1, const char *s2) { @@ -50,9 +52,10 @@ strcasecmp(const char *s1, const char *s2) return stricmp(s1, s2); #endif } +#endif - +#if defined(NEED_STRCASECMP) LIBW32_API int strncasecmp(const char *s1, const char *s2, size_t len) { @@ -62,6 +65,7 @@ strncasecmp(const char *s1, const char *s2, size_t len) return strnicmp(s1, s2, len); #endif } +#endif #if defined(NEED_STRNLEN) diff --git a/libw32/w32_strlcat.c b/libw32/w32_strlcat.c index 9c85a5f4..269fa001 100644 --- a/libw32/w32_strlcat.c +++ b/libw32/w32_strlcat.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_strlcat_c,"$Id: w32_strlcat.c,v 1.14 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_strlcat_c,"$Id: w32_strlcat.c,v 1.15 2022/05/26 11:13:56 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -150,7 +150,7 @@ __CIDENT_RCSID(gr_w32_strlcat_c,"$Id: w32_strlcat.c,v 1.14 2022/03/21 14:29:41 c // . /*/ -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) #include #include diff --git a/libw32/w32_strlcpy.c b/libw32/w32_strlcpy.c index 17f33f3a..b280a576 100644 --- a/libw32/w32_strlcpy.c +++ b/libw32/w32_strlcpy.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_strlcpy_c,"$Id: w32_strlcpy.c,v 1.14 2022/03/21 14:29:41 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_strlcpy_c,"$Id: w32_strlcpy.c,v 1.15 2022/05/26 11:13:56 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -150,9 +150,8 @@ __CIDENT_RCSID(gr_w32_strlcpy_c,"$Id: w32_strlcpy.c,v 1.14 2022/03/21 14:29:41 c // . */ -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) -#include #include #include diff --git a/libw32/w32_strptime.c b/libw32/w32_strptime.c index 81fb511c..0f048db0 100644 --- a/libw32/w32_strptime.c +++ b/libw32/w32_strptime.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_strptime_c,"$Id: w32_strptime.c,v 1.4 2018/10/12 00:23:31 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_strptime_c,"$Id: w32_strptime.c,v 1.6 2022/06/15 04:37:58 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -37,12 +37,12 @@ __CIDENT_RCSID(gr_w32_strptime_c,"$Id: w32_strptime.c,v 1.4 2018/10/12 00:23:31 #include #include -// #include #include #include #include #include +#include "win32_internal.h" #include "tzfile.h" /* @@ -586,7 +586,7 @@ again: switch (c = *fmt++) { break; case 'Z': - tzset(); + WIN32_TZSET(); if (strncmp((const char *)bp, gmt, 3) == 0) { tm->tm_isdst = 0; #ifdef TM_GMTOFF diff --git a/libw32/w32_time.c b/libw32/w32_time.c index d404ef71..9b532f80 100644 --- a/libw32/w32_time.c +++ b/libw32/w32_time.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_time_c,"$Id: w32_time.c,v 1.20 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_time_c,"$Id: w32_time.c,v 1.26 2022/06/15 12:11:30 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -56,7 +56,7 @@ __CIDENT_RCSID(gr_w32_time_c,"$Id: w32_time.c,v 1.20 2022/03/21 14:29:42 cvsuser #include #include #include - +#include /* // NAME @@ -124,6 +124,50 @@ w32_sleep (unsigned int secs) } +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" /*useconds_t*/ +#endif + +static void +sleepticks(__int64 ticks) +{ + HANDLE timer = 0; + LARGE_INTEGER due = {0}; + + if (ticks <= 0) return; + due.QuadPart = -ticks; // 100 nanosecond intervals, negative indicate relative time. + timer = CreateWaitableTimer(NULL, FALSE, NULL); + SetWaitableTimer(timer, &due, 0, NULL, NULL, FALSE); +#if !defined(NDEBUG) + assert(0 == WaitForSingleObject(timer, INFINITE)); +#else + WaitForSingleObject(timer, INFINITE); +#endif + CloseHandle(timer); +} + + +int +usleep(useconds_t useconds) +{ + sleepticks(((__int64)useconds) * 10); // usec to 100-nanosecond interval. + return 0; +} + + +int +nanosleep(const struct timespec *rqtp, struct timespec *rmtp /*notused*/) +{ + if (!rqtp || rqtp->tv_nsec > 999999999) { + errno = EINVAL; + return -1; + } + // 100 nanosecond intervals. + sleepticks((rqtp->tv_sec * 1000000 * 10) + (rqtp->tv_nsec / 100)); + return 0; +} + + /* // NAME // @@ -137,50 +181,54 @@ w32_sleep (unsigned int secs) // // DESCRIPTION // -// The gettimeofday() function shall obtain the current time, -// expressed as seconds and microseconds since the Epoch, and -// store it in the timeval structure pointed to by tp. The -// resolution of the system clock is unspecified. +// The gettimeofday() function shall obtain the current time, expressed aa seconds and +// microseconds since the Epoch, and store it in the timeval structure pointed to by tp. +// The resolution of the system clock is unspecified. // // If tzp is not a null pointer, the behavior is unspecified. // // RETURN VALUE -// // The gettimeofday() function shall return 0 and no value shall // be reserved to indicate an error. // // ERRORS -// // No errors are defined. // */ +#if defined(__MINGW32__) +#if !defined(__MINGW64_VERSION_MAJOR) +extern int gettimeofday (struct timeval *p, void *z); +#endif + +#else +static __inline long long +filetime_to_hsec(const FILETIME *ft) +{ + // Returns the 100-nanoseconds ("hecto-nanoseconds") since the epoch. + const long long hsecs = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime; + return hsecs - 116444736000000000LL; // delta 01/01/1970 and 01/01/1601 +} +#endif + + LIBW32_API int -w32_gettimeofday( - struct timeval *tv, /*struct timezone*/ void *tz) +w32_gettimeofday(struct timeval *tv, struct timezone *tz) { __CUNUSED(tz) if (tv) { -#if defined(_MSC_VER) || defined(__WATCOMC__) - struct _timeb lt; - - _ftime(<); - tv->tv_sec = (long)(lt.time + lt.timezone); - tv->tv_usec = lt.millitm * 1000; - assert(4 == sizeof(tv->tv_sec)); - -#elif defined(__MINGW32__) +#if defined(__MINGW32__) #undef gettimeofday - return gettimeofday(tv, tz) + return gettimeofday(tv, tz); #else //DEFAULT FILETIME ft; - long long hnsec; + long long hsec; - (void) GetSystemTimeAsFileTime(&ft); - hnsec = filetime_to_hnsec(&ft); - tv->tv_sec = hnsec / 10000000; - tv->tv_usec = (hnsec % 10000000) / 10; + (void) GetSystemTimeAsFileTime(&ft); //UTC + hsec = filetime_to_hsec(&ft); + tv->tv_sec = (long)(hsec / 10000000); + tv->tv_usec = (hsec % 10000000) / 10; #endif return 0; } @@ -191,8 +239,7 @@ w32_gettimeofday( #if !defined(__MINGW32__) LIBW32_API int -gettimeofday( - struct timeval *tv, struct timezone *tz) +gettimeofday(struct timeval *tv, struct timezone *tz) { return w32_gettimeofday(tv, tz); } @@ -317,24 +364,14 @@ w32_utime(const char *path, const struct utimbuf *times) LIBW32_API int w32_utimeA(const char *path, const struct utimbuf *times) { -#if defined(__MINGW32__) -#undef utime - return utime(path, (struct utimbuf *)times); -#else return _utime(path, (struct _utimbuf *)times); -#endif } LIBW32_API int w32_utimeW(const wchar_t *path, const struct utimbuf *times) { -#if defined(__MINGW32__) -#undef utime - return wutime(path, (struct utimbuf *)times); -#else return _wutime(path, (struct _utimbuf *)times); -#endif } /*end*/ diff --git a/libw32/w32_user.c b/libw32/w32_user.c index e98c9871..79ad2114 100644 --- a/libw32/w32_user.c +++ b/libw32/w32_user.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_user_c,"$Id: w32_user.c,v 1.18 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_user_c,"$Id: w32_user.c,v 1.21 2022/05/31 16:18:23 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -41,6 +41,8 @@ __CIDENT_RCSID(gr_w32_user_c,"$Id: w32_user.c,v 1.18 2022/03/21 14:29:42 cvsuser #include "win32_internal.h" #include "win32_child.h" +#include "win32_misc.h" + #include #include #include @@ -477,7 +479,8 @@ RID(PSID sid) } -#if defined(_MSC_VER) && (_MSC_VER < 1500) +#if (defined(_MSC_VER) && (_MSC_VER < 1500)) || \ + (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) #define TokenElevation 20 typedef struct _TOKEN_ELEVATION { DWORD TokenIsElevated; diff --git a/libw32/w32_util.c b/libw32/w32_util.c index c047b1e1..c32ae514 100644 --- a/libw32/w32_util.c +++ b/libw32/w32_util.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_util_c,"$Id: w32_util.c,v 1.20 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_util_c,"$Id: w32_util.c,v 1.21 2022/05/26 11:56:49 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -256,7 +256,7 @@ w32_utf2wc(const char *src, wchar_t *dest, size_t maxlen) dest[0] = 0; if ((ret = MultiByteToWideChar(CP_UTF8, 0, src, -1, dest, maxlen)) > 0) { assert(ret <= (int)maxlen); - if (ret == maxlen) + if (ret == (int)maxlen) dest[maxlen - 1] = 0; } else { @@ -355,7 +355,7 @@ w32_wc2utf(const wchar_t *src, char *dest, size_t maxlen) dest[0] = 0; if ((ret = WideCharToMultiByte(CP_UTF8, 0, src, -1, dest, maxlen, NULL, NULL)) > 0) { assert(ret <= (int)maxlen); - if (ret == maxlen) { + if (ret == (int)maxlen) { dest[maxlen - 1] = 0; --ret; } @@ -629,7 +629,7 @@ w32_vsyserrorA(DWORD dwError, char *buf, int buflen, ...) if (0 == ret) { // error, overflow etc int len; - if ((len = buflen) > sizeof("unknown error")) { + if ((len = buflen) > (int)sizeof("unknown error")) { len = sizeof("unknown error"); } memcpy(buf, "unknown error", len * sizeof(char)); @@ -699,7 +699,7 @@ w32_vsyserrorW(DWORD dwError, wchar_t *buf, int buflen, ...) if (0 == ret) { // error, overflow etc int len; - if ((len = buflen) > sizeof("unknown error")) { + if ((len = buflen) > (int)sizeof("unknown error")) { len = sizeof("unknown error"); } memcpy(buf, L"unknown error", len * sizeof(wchar_t)); diff --git a/libw32/w32_wdirent.c b/libw32/w32_wdirent.c index 979f5699..d143cc0b 100644 --- a/libw32/w32_wdirent.c +++ b/libw32/w32_wdirent.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_wdirent_c,"$Id: w32_wdirent.c,v 1.1 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_wdirent_c,"$Id: w32_wdirent.c,v 1.2 2022/06/11 04:01:45 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -734,7 +734,7 @@ d_Wow64DisableWow64FsRedirection(PVOID *OldValue) // XP+ x_Wow64DisableWow64FsRedirection = my_Wow64DisableWow64FsRedirection; x_Wow64RevertWow64FsRedirection = NULL; - FreeLibrary(hinst); + if (hinst) FreeLibrary(hinst); } #else x_Wow64DisableWow64FsRedirection = my_Wow64DisableWow64FsRedirection; diff --git a/libw32/w32_write.c b/libw32/w32_write.c index 45ca4460..d4f7a7eb 100644 --- a/libw32/w32_write.c +++ b/libw32/w32_write.c @@ -1,5 +1,5 @@ #include -__CIDENT_RCSID(gr_w32_write_c,"$Id: w32_write.c,v 1.18 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_w32_write_c,"$Id: w32_write.c,v 1.19 2022/05/26 12:11:06 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ /* @@ -388,3 +388,5 @@ pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) return ret; #endif } + +/*end*/ diff --git a/libw32/w32config.hin b/libw32/w32config.hin index ad76fdcf..a6c98ab3 100644 --- a/libw32/w32config.hin +++ b/libw32/w32config.hin @@ -1,10 +1,10 @@ #ifndef WIN32_CONFIG_H_INCLUDED #define WIN32_CONFIG_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_w32config_h, "$Id: w32config.hin,v 1.19 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_w32config_h, "$Id: w32config.hin,v 1.24 2022/06/16 05:18:13 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; set-indent: 4; -*- */ -/* $Id: w32config.hin,v 1.19 2022/03/21 14:29:42 cvsuser Exp $ +/* $Id: w32config.hin,v 1.24 2022/06/16 05:18:13 cvsuser Exp $ * Machine configuration. * * System dependent configuration template, @@ -31,9 +31,11 @@ __CPRAGMA_ONCE #if !defined(_MSC_VER) #if !defined(__WATCOMC__) +#if !defined(__MINGW32__) #error config.h: MSVC or WATCOMC targets only ... #endif -#endif /*MSC || WATCOM*/ +#endif +#endif /*MSC || WATCOM || MINGW */ #undef MAKELIB_CC_COMPILER #undef MAKELIB_CC_VERSION @@ -46,19 +48,17 @@ __CPRAGMA_ONCE #pragma warning (disable : 4706) // assignment within conditional expression #pragma warning (disable : 4996) -#if !defined(__cplusplus) - /* - * is incompatible with _CRT_NO_POSIX_ERROR_CODES. - */ -#if !defined(_CRT_NO_POSIX_ERROR_CODES) -#define _CRT_NO_POSIX_ERROR_CODES // disable POSIX error number, see -#endif +#if defined(_CRT_NO_POSIX_ERROR_CODES) +#pragma message(" is incompatible with _CRT_NO_POSIX_ERROR_CODES.") #endif #elif defined(__WATCOMC__) #if !defined(__cplusplus) #pragma disable_message(136) // comparison equivalent to 'unsigned == 0' #pragma disable_message(138) // no newline at end of file +#if (__WATCOMC__ >= 1300) // owc2.0 +#pragma disable_message(303) // parameter 'xxx' has been defined, but not referenced. +#endif #endif #pragma disable_message(201) // unreachable code #pragma disable_message(202) // symbol 'xxx' has been defined, but not referenced @@ -157,6 +157,7 @@ __CPRAGMA_ONCE #undef HAVE_SYS_STATVFS_H #undef HAVE_SYS_VFS_H #undef HAVE_SYS_MMAN_H +#undef HAVE_SYS_TIMEB_H #undef HAVE_WAIT_H #undef HAVE_POLL_H #undef HAVE_SYS_PRCTL_H @@ -171,6 +172,7 @@ __CPRAGMA_ONCE #undef HAVE_STDATOMIC_H #undef HAVE_THREADS_H #undef HAVE_XTHREADS_H +#undef HAVE_LIBPTHREAD #undef HAVE_THREAD_H #undef HAVE_PTHREAD_H @@ -411,7 +413,7 @@ __CPRAGMA_ONCE */ /* environ support */ - + #undef HAVE_ENVIRON #undef HAVE__ENVIRON #undef HAVE___ENVIRON @@ -482,9 +484,11 @@ __CPRAGMA_ONCE #undef HAVE_STRCASECMP #undef HAVE_STRNCASECMP #undef HAVE___STRCASECMP +#undef HAVE___STRNCASECMP #undef HAVE_STRCHR #undef HAVE_STRERROR #undef HAVE_STRICMP +#undef HAVE_STRNICMP #undef HAVE_STRRCHR #undef HAVE_STRDUP #undef HAVE_STRFTIME @@ -504,6 +508,7 @@ __CPRAGMA_ONCE #undef HAVE_STRCASESTR #undef HAVE_STRCASESTR_L #undef HAVE_STRTONUM +#undef HAVE_STRTOK_R #undef HAVE_ISASCII #undef HAVE___ISASCII @@ -517,7 +522,6 @@ __CPRAGMA_ONCE #undef HAVE_SETPGRP #undef HAVE_SETSID -#undef HAVE_STRTOK_R #undef HAVE_STRERROR_L #undef HAVE_STRERROR_R diff --git a/libw32/win32_errno.h b/libw32/win32_errno.h index ed5971aa..47c57394 100644 --- a/libw32/win32_errno.h +++ b/libw32/win32_errno.h @@ -1,7 +1,7 @@ #ifndef LIBW32_WIN32_ERRNO_H_INCLUDED #define LIBW32_WIN32_ERRNO_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_win32_errno_h,"$Id: win32_errno.h,v 1.10 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_win32_errno_h,"$Id: win32_errno.h,v 1.14 2022/06/13 06:51:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -30,46 +30,44 @@ __CPRAGMA_ONCE * ==end== */ - /* - * Verify that MSVC POSIX errno number are not active; if the case warn and undef clashing constants - * Generally is included before as such the following should not occur. - */ +/* + * Verify that MSVC POSIX errno number are not active; if the case warn and undef clashing constants + * Generally is included before as such the following should not occur. + */ #if !defined(__MAKEDEPEND__) #if defined(EADDRINUSE) && (EADDRINUSE != 10048) -#if defined(_MSC_VER) + +#if defined(_MSC_VER) || \ + (defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)) #if (EADDRINUSE == 100) -#if !defined(_CRT_NO_POSIX_ERROR_CODES) -#pragma message("_CRT_NO_POSIX_ERROR_CODES should be defined: EADDRINUSE (and others) are inconsistent with WinSock aliases; redefining") -#else -#pragma message("_CRT_NO_POSIX_ERROR_CODES is defined: yet EADDRINUSE (and others) are inconsistent with WinSock aliases as include order is incorrect; redefining") +#if defined(_CRT_NO_POSIX_ERROR_CODES) +#pragma message is incompatible with _CRT_NO_POSIX_ERROR_CODES. #endif + /* + * RETHINK, as the following are assumed by the MinGW pthread package: + * + * #define ETIMEDOUT 138 + * #define ENOTSUP 129 + * #define EWOULDBLOCK 140 + */ +#include "msvc_errno.h" /* undef error codes */ #else #error unexpected EADDRINUSE value #endif #endif //_MSC_VER + #endif //EADDRINUSE != 10048 #endif //__MAKEDEPEND__ - /* Check for (MSVC && !WATCOMC), at times we masquerade WC as MSVC */ -#if (defined(_MSC_VER) && !defined(__WATCOMC__)) || \ - defined(__MAKEDEPEND__) -#include "msvc_errno.h" -#endif //EADDRINUSE - /* - * System + * import */ -#if defined(_MSC_VER) && (_MSC_VER > 1600) && \ - !defined(_CRT_NO_POSIX_ERROR_CODES) -#define _CRT_NO_POSIX_ERROR_CODES /* disable POSIX error number, see (MSVC 2010+) */ -#endif //_MSC_VER - +#if !defined(_CRT_NO_POSIX_ERROR_CODES) +#define _CRT_NO_POSIX_ERROR_CODES /* disable extended POSIX errno's */ +#include +#undef _CRT_NO_POSIX_ERROR_CODES +#else #include - -#if defined(EWOULDBLOCK) /* _CRT_NO_POSIX_ERROR_CODES not available */ -#if (_MSC_VER == 1600) && !defined(__WATCOMC__) -#include "msvc_errno.h" -#endif #endif /* @@ -80,8 +78,8 @@ __CPRAGMA_ONCE * General use error codes, * which utilise their defined value under MSVC POSIX definition, see * - * MSVC: Their definitions are disabled using _CRT_NO_POSIX_ERROR_CODES, - * as many conflict with the WinSock aliases below, + * MSVC: Their definitions can be disabled using _CRT_NO_POSIX_ERROR_CODES, as many conflict with the + * WinSock aliases below, but this generates complication errors within C++ code elements. */ #define EBADMSG 104 /* Bad message. */ #define ECANCELED 105 /* Operation canceled. */ @@ -111,7 +109,7 @@ __CPRAGMA_ONCE * WinSock errors are aliased to their BSD/POSIX counter part. * * Note: This works for *most* errors, yet the following result in conflicts and are - * explicity remapped during i/o operations. + * explicitly remapped during i/o operations: see w32_neterrno_map() * #define EINTR WSAEINTR // 10004 "Interrupted system call" #define EBADF WSAEBADF // 10009 "Bad file number" @@ -360,34 +358,105 @@ __CPRAGMA_ONCE * Map not socket specific errors. */ +#if defined(EWOULDBLOCK) && (EWOULDBLOCK != 10045) + #if (EWOULDBLOCK == 140) /* MSVC/MINGW64 extra */ + #undef EWOULDBLOCK + #else + #error Inconsistent EWOULDBLOCK definition .... + #endif +#endif #if !defined(EWOULDBLOCK) #define EWOULDBLOCK 10035 /* 10035 "Operation would block" */ #endif +#if defined(EALREADY) && (EALREADY != 10037) + #if (EALREADY == 103) /* MSVC/MINGW64 extra */ + #undef EALREADY + #else + #error Inconsistent EALREADY definition .... + #endif +#endif #if !defined(EALREADY) #define EALREADY 10037 /* 10037 "Operation already in progress" */ #endif +#if defined(EMSGSIZE) && (EMSGSIZE != 10040) + #if (EMSGSIZE == 115) /* MSVC/MINGW64 extra */ + #undef EMSGSIZE + #else + #error Inconsistent EMSGSIZE definition .... + #endif +#endif #if !defined(EMSGSIZE) #define EMSGSIZE 10040 /* 10040 "Message too long" */ #endif +#if defined(EOPNOTSUPP) && (EOPNOTSUPP != 10045) + #if (EOPNOTSUPP == 130) /* MSVC/MINGW64 extra */ + #undef EOPNOTSUPP + #else + #error Inconsistent EOPNOTSUPP definition .... + #endif +#endif #if !defined(EOPNOTSUPP) #define EOPNOTSUPP 10045 /* 10045 "Operation not supported on socket" */ #endif +#if defined(ENETUNREACH) && (ENETUNREACH != 10051) + #if (ENETUNREACH == 118) + #undef ENETUNREACH /* MSVC/MINGW64 */ + #else + #error Inconsistent ENETUNREACH definition .... + #endif +#endif +#if !defined(ENETUNREACH) +#define ENETUNREACH 10051 /* 10051 "Network is unreachable" */ +#endif + +#if defined(ECONNRESET) && (ECONNRESET != 10054) + #if (ECONNRESET == 108) /* MSVC/MINGW64 */ + #undef ECONNRESET + #else + #error Inconsistent ECONNRESET definition .... + #endif +#endif +#if !defined(ECONNRESET) +#define ECONNRESET 10054 /* 10054 "Connection reset by peer" */ +#endif + +#if defined(ENOBUFS) && (ENOBUFS != 10055) + #if (ENOBUFS == 119) /* MSVC/MINGW64 */ + #undef ENOBUFS + #else + #error Inconsistent ENOBUFS definition .... + #endif +#endif #if !defined(ENOBUFS) #define ENOBUFS 10055 /* 10055 "No buffer space available" */ #endif +#if defined(ETIMEDOUT) && (ETIMEDOUT != 10060) +# if (ETIMEDOUT == 138) /* MSVC/MINGW64 */ +# undef ETIMEDOUT +# else +# error Inconsistent ETIMEDOUT definition .... +# endif +#endif #if !defined(ETIMEDOUT) #define ETIMEDOUT 10060 /* 10060 "Connection timed out" */ #endif +#if defined(ELOOP) && (ELOOP != 10062) +# if (ELOOP == 114) /* MSVC/MINGW64 */ +# undef ELOOP +# else +# error Inconsistent ELOOP definition .... +# endif +#endif #if !defined(ELOOP) #define ELOOP 10062 /* 10062 "Too many levels of symbolic links" */ #endif -#endif //!LIBW32_ERRNO_WINSOCK +#endif /*LIBW32_WIN32_ERRNO_H_INCLUDED*/ /*end*/ diff --git a/libw32/win32_hunspell.h b/libw32/win32_hunspell.h index 9aa72859..0b3df2f7 100644 --- a/libw32/win32_hunspell.h +++ b/libw32/win32_hunspell.h @@ -1,14 +1,14 @@ #ifndef GR_WIN32_HUNSPELL_H_INCLUDED #define GR_WIN32_HUNSPELL_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_win32_hunspell_h,"$Id: win32_hunspell.h,v 1.10 2019/03/15 23:12:22 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_win32_hunspell_h,"$Id: win32_hunspell.h,v 1.11 2022/06/11 04:36:25 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ /* * win32 hunspell dynamic loader. * - * Copyright (c) 1998 - 2019, Adam Young. + * Copyright (c) 1998 - 2022, Adam Young. * All rights reserved. * * This file is part of the GRIEF Editor. @@ -37,7 +37,7 @@ __CPRAGMA_ONCE __CBEGIN_DECLS LIBW32_API int w32_hunspell_connect(int verbose); -LIBW32_API extern void w32_hunspell_shutdown(void); +LIBW32_API void w32_hunspell_shutdown(void); LIBW32_API void * w32_hunspell_initialise(const char *aff, const char *dic); LIBW32_API void * w32_hunspell_initialise_key(const char *aff, const char *dic, const char *key); diff --git a/libw32/win32_include.h b/libw32/win32_include.h index bc0fb9ab..fb6828cd 100644 --- a/libw32/win32_include.h +++ b/libw32/win32_include.h @@ -1,7 +1,7 @@ #ifndef LIBW32_WIN32_INCLUDE_H_INCLUDED #define LIBW32_WIN32_INCLUDE_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_win32_include_h,"$Id: win32_include.h,v 1.10 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_win32_include_h,"$Id: win32_include.h,v 1.16 2022/06/13 06:51:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -31,24 +31,57 @@ __CPRAGMA_ONCE * ==end== */ +/* + * WinSock/Windows definitions + */ + +#if defined(_MSC_VER) #if !defined(_CRT_SECURE_NO_DEPRECATE) #define _CRT_SECURE_NO_DEPRECATE /* disable deprecate warnings */ #endif -#if !defined(_CRT_NO_POSIX_ERROR_CODES) -#define _CRT_NO_POSIX_ERROR_CODES /* disable POSIX error number, see */ -#endif + //#if !defined(_CRT_NO_POSIX_ERROR_CODES) + //#define _CRT_NO_POSIX_ERROR_CODES /* disable POSIX error number, see */ + //#endif +#endif /*_MSC_VER*/ + + //#if defined(__WATCOMC__) && (__WATCOMC__ < 1300) + //#if !defined(NTDDI_VERSION) + //#define NTDDI_VERSION 0x06000000 /* iphlpapi.h requirement, inet_ntop .. */ + //#endif + //#endif + +/* winsock and friends */ #if !defined(HAVE_WINSOCK2_H_INCLUDED) #define HAVE_WINSOCK2_H_INCLUDED +#if !defined(_WINSOCK2_H) /* MINGW32 guard */ + #undef gethostname /* unistd.h name mangling */ #if defined(u_char) #undef u_char /* namespace issues (_BSD_SOURCE) */ #endif + +#if defined(__MINGW32__) && defined(SLIST_ENTRY) +#pragma push_macro("SLIST_ENTRY") /* */ +#undef SLIST_ENTRY +#include +#pragma pop_macro("SLIST_ENTRY") +#else #include +#if defined(__MINGW32__) +#undef SLIST_ENTRY +#endif +#endif + #include /* getaddrinfo() */ +#include /* IOCP */ + +#endif /*_WINSOCK2_H*/ #endif /*HAVE_WINSOCK2_H_INCLUDED*/ +/* windows.h*/ + #if !defined(HAVE_WINDOWS_H_INCLUDED) #define HAVE_WINDOWS_H_INCLUDED #ifndef WINDOWS_NOT_MEAN_AND_LEAN diff --git a/libw32/win32_internal.h b/libw32/win32_internal.h index f5793c03..86e88c3c 100644 --- a/libw32/win32_internal.h +++ b/libw32/win32_internal.h @@ -1,7 +1,7 @@ #ifndef LIBW32_WIN32_INTERNAL_H_INCLUDED #define LIBW32_WIN32_INTERNAL_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_win32_internal_h,"$Id: win32_internal.h,v 1.13 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_win32_internal_h,"$Id: win32_internal.h,v 1.16 2022/06/13 06:51:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -41,7 +41,8 @@ __CPRAGMA_ONCE #include #if defined(_MSC_VER) && (_MSC_VER >= 1400) || \ - defined(__WATCOMC__) + defined(__WATCOMC__) || \ + defined(__MINGW32__) #define WIN32_OPEN _open #define WIN32_WOPEN _wopen #define WIN32_CLOSE _close @@ -54,7 +55,6 @@ __CPRAGMA_ONCE #define WIN32_STRNICMP _strnicmp #define WIN32_STRDUP _strdup #define WIN32_STRDUPW _wcsdup -#define WIN32_TZSET _tzset #else #define WIN32_OPEN open #define WIN32_WOPEN wopen @@ -68,9 +68,22 @@ __CPRAGMA_ONCE #define WIN32_STRNICMP strnicmp #define WIN32_STRDUP strdup #define WIN32_STRDUPW wcsdup +#endif + +#if (defined(_MSC_VER) && _MSC_VER >= 1400) || \ + defined(__MINGW32__) +#define WIN32_TZSET _tzset +#else #define WIN32_TZSET tzset #endif +#if (defined(_MSC_VER) && defined(_WIN64)) || \ + defined(__MINGW64__) +#define OSFHANDLE intptr_t +#else +#define OSFHANDLE long +#endif + #if defined(_MSC_VER) && (_MSC_VER >= 1400) #define WIN32_GETPID _getpid #else diff --git a/libw32/win32_io.h b/libw32/win32_io.h index e998a001..ef21a303 100644 --- a/libw32/win32_io.h +++ b/libw32/win32_io.h @@ -1,7 +1,7 @@ #ifndef LIBW32_WIN32_IO_H_INCLUDED #define LIBW32_WIN32_IO_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_win32_io_h,"$Id: win32_io.h,v 1.36 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_win32_io_h,"$Id: win32_io.h,v 1.37 2022/05/27 18:43:34 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -48,7 +48,7 @@ __CPRAGMA_ONCE #if !defined(_WIN32_WINCE) /* require winsock2.h */ #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x601 /* latest features */ +#define _WIN32_WINNT 0x601 /* latest features */ #elif (_WIN32_WINNT) < 0x400 #pragma message("unistd: _WIN32_WINNT < 0400") #endif @@ -61,9 +61,9 @@ __CPRAGMA_ONCE __BEGIN_DECLS /*fcntl.h*/ -#if !defined(F_GETTL) -#define F_GETFL 1 -#define F_SETFL 2 +#if !defined(F_GETFL) /* match linux definitions */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ #endif LIBW32_API int fcntl (int fildes, int ctrl, int); diff --git a/libw32/win32_ioctl.h b/libw32/win32_ioctl.h index 4dfdd1f6..044a9140 100644 --- a/libw32/win32_ioctl.h +++ b/libw32/win32_ioctl.h @@ -1,14 +1,14 @@ #ifndef LIBW32_WIN32_IOCTL_H_INCLUDED #define LIBW32_WIN32_IOCTL_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_win32_ioctl_h,"$Id: win32_ioctl.h,v 1.3 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_win32_ioctl_h,"$Id: win32_ioctl.h,v 1.4 2022/05/31 16:18:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ /* * win32 ioctl support. * - * Copyright (c) 2018, Adam Young. + * Copyright (c) 2018 - 2022, Adam Young. * All rights reserved. * * This file is part of the GRIEF Editor. @@ -38,14 +38,16 @@ __CPRAGMA_ONCE #if !defined(__WATCOMC__) #undef DEFINE_GUIDS #include /* DeviceIoControls */ -#endif +#endif -#if defined(HAVE_NTIFS_H) +#if defined(HAVE_NTIFS_H) #include +#elif defined(__MINGW64_VERSION_MAJOR) +#include #endif #if !defined(HAVE_NTIFS_H) && !defined(__MINGW32__) - typedef struct _REPARSE_DATA_BUFFER { +typedef struct _REPARSE_DATA_BUFFER { ULONG ReparseTag; USHORT ReparseDataLength; USHORT Reserved; @@ -74,7 +76,7 @@ __CPRAGMA_ONCE #define MAX_REPARSE_SIZE (512+(16*1024)) /* Header + 16k */ -#ifdef __WATCOMC__ /* WC19 SDK has incorrect definitions */ +#if defined(__WATCOMC__) /* WC19 SDK has incorrect definitions */ #undef IsReparseTagMicrosoft #undef IO_REPARSE_TAG_SYMLINK #undef IO_REPARSE_TAG_MOUNT_POINT diff --git a/libw32/win32_misc.h b/libw32/win32_misc.h index ecfdc186..a6441230 100644 --- a/libw32/win32_misc.h +++ b/libw32/win32_misc.h @@ -1,7 +1,7 @@ #ifndef LIBW32_WIN32_MISC_H_INCLUDED #define LIBW32_WIN32_MISC_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_win32_misc_h,"$Id: win32_misc.h,v 1.13 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_win32_misc_h,"$Id: win32_misc.h,v 1.15 2022/06/13 06:51:23 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -31,6 +31,7 @@ __CPRAGMA_ONCE * ==end== */ +#include "win32_include.h" #include __BEGIN_DECLS @@ -53,6 +54,9 @@ enum w32ostype { /* generalised machine types, ignoring server */ #define WIN32_PATH_MAX 1024 /* 255, unless UNC names are used */ #define WIN32_LINK_DEPTH 8 +int w32_HTOI(HANDLE handle); +HANDLE w32_ITOH(int pid); + LIBW32_API enum w32ostype w32_ostype(void); LIBW32_API int w32_getexedir(char *buf, int maxlen); diff --git a/libw32/win32_time.h b/libw32/win32_time.h index a5e3ed95..adb46e83 100644 --- a/libw32/win32_time.h +++ b/libw32/win32_time.h @@ -1,7 +1,7 @@ #ifndef LIBW32_WIN32_TIME_H_INCLUDED #define LIBW32_WIN32_TIME_H_INCLUDED #include -__CIDENT_RCSID(gr_libw32_win32_time_h,"$Id: win32_time.h,v 1.13 2022/03/21 14:29:42 cvsuser Exp $") +__CIDENT_RCSID(gr_libw32_win32_time_h,"$Id: win32_time.h,v 1.20 2022/06/13 13:13:00 cvsuser Exp $") __CPRAGMA_ONCE /* -*- mode: c; indent-width: 4; -*- */ @@ -32,23 +32,63 @@ __CPRAGMA_ONCE */ #include +#include +#include __BEGIN_DECLS +#if !defined(USECONDS_T) +#define USECONDS_T 1 +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +typedef unsigned long useconds_t __MINGW_ATTRIB_DEPRECATED; + +#elif !defined(__MINGW32__) +#ifdef _WIN64 +typedef unsigned long long useconds_t; +#else +typedef unsigned long useconds_t; +#endif +#endif /*__MINGW32__*/ +#endif /*USECONDS_T*/ + LIBW32_API unsigned int sleep(unsigned int); +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" /*useconds_t, POSIX.1-2008*/ +#endif +LIBW32_API int usleep(useconds_t useconds); +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#pragma GCC diagnostic pop +#endif + +struct timespec; +LIBW32_API int nanosleep(const struct timespec *rqtp, struct timespec *rmtp /*notused*/); + struct timeval; struct timezone; +LIBW32_API int w32_gettimeofday(struct timeval *tv, struct timezone *tz); +#if !defined(HAVE_GETTIMEOFDAY) +#define HAVE_GETTIMEOFDAY +#if !defined(__MINGW32__) LIBW32_API int gettimeofday(struct timeval *tv, struct timezone *tz); +#endif +#endif struct utimbuf; LIBW32_API int w32_utime(const char *path, const struct utimbuf *times); +LIBW32_API int w32_utimeA(const char *path, const struct utimbuf *times); +LIBW32_API int w32_utimeW(const wchar_t *path, const struct utimbuf *times); +#if (0) //libcompat #if defined(_MSC_VER) || defined(__WATCOMC__) LIBW32_API time_t timegm(struct tm *tm); #endif +#endif //libcompat + +LIBW32_API char * w32_strptime(const char *buf, const char *fmt, struct tm *tm); __END_DECLS diff --git a/libwidechar/Makefile.in b/libwidechar/Makefile.in index ecaca3b2..9f4e0261 100644 --- a/libwidechar/Makefile.in +++ b/libwidechar/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.3 2021/08/01 15:40:21 cvsuser Exp $ +# $Id: Makefile.in,v 1.5 2022/06/01 14:21:19 cvsuser Exp $ # libwidechar makefile. # # -# Copyright (c) 2021, Adam Young. +# Copyright (c) 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -85,9 +85,6 @@ LDDEBUG= @LDDEBUG@ LDRELEASE= @LDRELEASE@ CINCLUDE= -I. -I$(D_INC) @CINCLUDE@ -##ifeq ("mingw32","@build_os@") -##CINCLUDE+= -I../libw32 -##endif CEXTRA= @DEFS@ ifeq ("$(BUILD_TYPE)","release") @@ -99,9 +96,6 @@ LDFLAGS= $(LDDEBUG) @LDFLAGS@ endif LDLIBS= -L$(D_LIB) @LIBS@ -lmisc @LIBMALLOC@ @LIBTHREAD@ @EXTRALIBS@ -##ifeq ("mingw32","@build_os@") -##LDLIBS+= -lw32 -lshlwapi -lpsapi -lole32 -luuid -lgdi32 -luserenv -lnetapi32 -ladvapi32 -lWs2_32 -##endif YFLAGS= -d ARFLAGS= rcv @@ -135,6 +129,7 @@ WIDECHAROBJS=\ $(D_OBJ)/wcstod$(O) \ $(D_OBJ)/wcstok$(O) \ $(D_OBJ)/wcswcs$(O) \ + $(D_OBJ)/wcswcs$(O) \ $(D_OBJ)/wcswidth$(O) \ $(D_OBJ)/wcwidth$(O) \ $(D_OBJ)/wmemchr$(O) \ diff --git a/libwidechar/wcswcs.c b/libwidechar/wcswcs.c index 9c451eff..d7ab2f91 100644 --- a/libwidechar/wcswcs.c +++ b/libwidechar/wcswcs.c @@ -1,5 +1,34 @@ -/* $OpenBSD: wcswcs.c,v 1.1 2005/04/13 16:35:58 espie Exp $ */ -/* $NetBSD: wcswcs.c,v 1.1 2003/03/05 20:18:17 tshiozak Exp $ */ +/* $OpenBSD: wcsstr.c,v 1.5 2015/10/01 02:32:07 guenther Exp $ */ +/* $NetBSD: wcsstr.c,v 1.3 2003/03/05 20:18:17 tshiozak Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ #define WCSWCS #include "wcsstr.c" + + + diff --git a/libwidechar/widechar.h b/libwidechar/widechar.h index 3a4867d4..f546b54c 100644 --- a/libwidechar/widechar.h +++ b/libwidechar/widechar.h @@ -39,6 +39,9 @@ WChar_t * Wcspbrk(const WChar_t *s, const WChar_t *set); WChar_t * Wcsrchr(const WChar_t *s, WChar_t c); WChar_t * Wcstok(WChar_t * s, const WChar_t * delim, WChar_t ** last); +WChar_t * Wcsstr(const WChar_t *big, const WChar_t *little); +WChar_t * Wcswcs(const WChar_t *big, const WChar_t *little); + int Wcscasecmp(const WChar_t *s1, const WChar_t *s2); int Wcsncasecmp(const WChar_t *s1, const WChar_t *s2, size_t n); @@ -63,6 +66,8 @@ int Wcstoutf8(const WChar_t *str, char *buf, int buflen); int Wcwidth(WChar_t ucs); int Wcswidth(const WChar_t *s, size_t n); + +int Wvasprintf(WChar_t **ret, const char *format, va_list ap); int Wvsnprintf(WChar_t *str, size_t size, const char *format, va_list args); int Wsnprintf(WChar_t *str, size_t size, const char *format, ...); diff --git a/libwidechar/wsnprintf.c b/libwidechar/wsnprintf.c index 6a6aaf8a..dc09ecbc 100644 --- a/libwidechar/wsnprintf.c +++ b/libwidechar/wsnprintf.c @@ -594,14 +594,14 @@ do { \ (len)++; \ } while (/* CONSTCOND */ 0) -static const WChar_t nil[6] = {'(', 'n', 'i', 'l', ')', 0}; -static const WChar_t null[7] = {'(', 'n', 'u', 'l', 'l', ')', 0}; -static const WChar_t NAN[4] = {'N', 'A', 'N', 0}; -static const WChar_t nan[4] = {'n', 'a', 'n', 0}; -static const WChar_t INF[4] = {'I', 'N', 'F', 0}; -static const WChar_t inf[4] = {'i', 'n', 'f', 0}; -static const WChar_t HEX[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 0}; -static const WChar_t hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 0}; +static const WChar_t nil[6] = {'(', 'n', 'i', 'l', ')', 0}; +static const WChar_t null[7] = {'(', 'n', 'u', 'l', 'l', ')', 0}; +static const WChar_t WNAN[4] = {'N', 'A', 'N', 0}; +static const WChar_t wnan[4] = {'n', 'a', 'n', 0}; +static const WChar_t WINF[4] = {'I', 'N', 'F', 0}; +static const WChar_t winf[4] = {'i', 'n', 'f', 0}; +static const WChar_t HEX[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 0}; +static const WChar_t hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 0}; static void fmtstrw(WChar_t *, size_t *, size_t, const WChar_t *, int, int, int); static void fmtstrW(WChar_t *, size_t *, size_t, const wchar_t *, int, int, int); @@ -911,6 +911,7 @@ Wvsnprintf(WChar_t *str, size_t size, const char *format, va_list args) fmtstr(str, &len, size, va_arg(args, char *), width, precision, flags); break; } + break; case 'S': fmtstrw(str, &len, size, va_arg(args, WChar_t *), width, precision, flags); break; @@ -1251,9 +1252,9 @@ fmtflt(WChar_t *str, size_t *len, size_t size, LDOUBLE fvalue, int width, int pr sign = ' '; if (ISNAN(fvalue)) - infnan = (flags & PRINT_F_UP) ? NAN : nan; + infnan = (flags & PRINT_F_UP) ? WNAN : wnan; else if (ISINF(fvalue)) - infnan = (flags & PRINT_F_UP) ? INF : inf; + infnan = (flags & PRINT_F_UP) ? WINF : winf; if (infnan != NULL) { if (sign != 0) diff --git a/macsrc/.cvsignore b/macsrc/.cvsignore new file mode 100644 index 00000000..70998cad --- /dev/null +++ b/macsrc/.cvsignore @@ -0,0 +1,4 @@ +Makefile +autoload.inc +*.err + diff --git a/macsrc/Makefile.in b/macsrc/Makefile.in index 2d4b7fc4..e788bfd6 100644 --- a/macsrc/Makefile.in +++ b/macsrc/Makefile.in @@ -1,9 +1,9 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.21 2021/04/23 12:16:03 cvsuser Exp $ +# $Id: Makefile.in,v 1.24 2022/06/16 08:43:59 cvsuser Exp $ # GRIEF macro library makefile. # # -# Copyright (c) 1998 - 2021, Adam Young. +# Copyright (c) 1998 - 2022, Adam Young. # All rights reserved. # # This file is part of the GRIEF Editor. @@ -47,16 +47,28 @@ D_BIN= $(ROOT)/bin@TOOLCHAINEXT@/$(BUILD_TYPE) GRUNCH= $(D_BIN)/grunch -M= $(ROOT)/macros -MKBD= $(M)/kbd -MTTY= $(M)/tty -MDEMOS= $(M)/demos -MBENCHMARKS= $(M)/benchmarks -MMODES= $(M)/modes -MPROFILES= $(M)/profiles -MCOLORS= $(M)/colors -MACRODIRS= $(M) $(MKBD) $(MTTY) $(MDEMOS) $(MBENCHMARKS) $(MMODES) $(MPROFILES) $(MCOLORS) +ifeq ("@ISWIN64@","yes") +MACROS= $(ROOT)/macros.x64 +else +MACROS= $(ROOT)/macros +endif +MKBD= $(MACROS)/kbd +MTTY= $(MACROS)/tty +MDEMOS= $(MACROS)/demos +MBENCHMARKS= $(MACROS)/benchmarks +MMODES= $(MACROS)/modes +MPROFILES= $(MACROS)/profiles +MCOLORS= $(MACROS)/colors +MACRODIRS= $(MACROS) $(MKBD) $(MTTY) $(MDEMOS) $(MBENCHMARKS) $(MMODES) $(MPROFILES) $(MCOLORS) + +# Compilers, programs +RM= @RM@ +RMDIR= @RMDIR@ +PERL= @PERL@ + +RMFLAGS= -f +RMDFLAGS= -rf ######################################################################################### # Rules @@ -70,47 +82,51 @@ debug: $(MAKE) BUILD_TYPE=debug $(filter-out debug, $(MAKECMDGOALS)) SOURCE= $(wildcard *.cr kbd/*.cr tty/*.cr demos/*.cr benchmarks/*.cr modes/*.cr profiles/*.cr colors/*.cr) -OBJECTS= $(wildcard $(M)/*.cm $(MKBD)/*.cm $(MTTY)/*.cm $(MDEMOS)/*.cm $(MBENCHMARKS)/*.cm $(MMODES)/*.cm $(MPROFILES)/*.cm $(MCOLORS)/*.cm) +OBJECTS= $(wildcard $(MACROS)/*.cm $(MACROS)/*.m $(MKBD)/*.cm $(MTTY)/*.cm $(MDEMOS)/*.cm $(MBENCHMARKS)/*.cm $(MMODES)/*.cm $(MPROFILES)/*.cm $(MCOLORS)/*.cm) macros: $(MACRODIRS) - $(GRUNCH) -w -m -A autoload.inc -o $M $(SOURCE) + $(GRUNCH) -w -m -A autoload.inc -o $(MACROS) $(SOURCE) force: $(MACRODIRS) - ${GRUNCH} -w -A autoload.inc -o $M $(SOURCE) + ${GRUNCH} -w -A autoload.inc -o $(MACROS) $(SOURCE) withdebug: $(MACRODIRS) - $(GRUNCH) -w -g -A autoload.inc -o $M $(SOURCE) - ${GRUNCH} -w $M grief.cr debug.cr + $(GRUNCH) -w -g -A autoload.inc -o $(MACROS) $(SOURCE) + ${GRUNCH} -w $(MACROS) grief.cr debug.cr + +$(MACROS): $(MACROS)/.created -$M: - -mkdir $M +$(MKBD): $(MKBD)/.created -$(MKBD): - -mkdir $(MKBD) +$(MTTY): $(MTTY)/.created -$(MTTY): - -mkdir $(MTTY) +$(MDEMOS): $(MDEMOS)/.created -$(MDEMOS): - -mkdir $(MDEMOS) +$(MBENCHMARKS): $(MBENCHMARKS)/.created -$(MBENCHMARKS): - -mkdir $(MBENCHMARKS) +$(MMODES): $(MMODES)/.created -$(MMODES): - -mkdir $(MMODES) +$(MPROFILES): $(MPROFILES)/.created -$(MPROFILES): - -mkdir $(MPROFILES) +$(MCOLORS): $(MCOLORS)/.created -$(MCOLORS): - -mkdir $(MCOLORS) +%/.created: + -@$(PERL) ../win32/mkdir_p.pl $(@D) + @echo "++ do not delete, grief edit managed content ++" > $@ + +reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1)) +RMACRODIRS = $(call reverse, $(MACRODIRS)) + +vclean: clean + -$(RM) $(RMDFLAGS) $(addsuffix /.created, $(RMACRODIRS)) + -$(RMDIR) $(RMACRODIRS) clean: @echo $(BUILD_TYPE) clean - -rm -f a.out mon.out crisp.log core - -rm -f $(OBJECTS) - -rm -f *.m */*.m + -$(RM) $(RMFLAGS) a.out mon.out crisp.log core +ifneq ("$(OBJECTS)","") + -$(RM) $(RMFLAGS) $(OBJECTS) +endif #end diff --git a/macsrc/demos/regress.cr b/macsrc/demos/regress.cr index 5faa430f..15240dd7 100644 --- a/macsrc/demos/regress.cr +++ b/macsrc/demos/regress.cr @@ -1,5 +1,5 @@ /* -*- mode: cr; indent-width: 4; -*- */ -/* $Id: regress.cr,v 1.38 2021/08/14 17:08:33 cvsuser Exp $ +/* $Id: regress.cr,v 1.39 2022/06/16 05:17:29 cvsuser Exp $ * * This set of macros are used when debugging and fixing CRISP to aid in regression testing and * catching bugs introduced inadvertently. These tests dont attempt an exhaustive test, yet @@ -1963,43 +1963,57 @@ test_sprintf(void) string s1; int i; + // numeric padding + TEST(484, format("%4d", 12) == " 12"); // padded + TEST(485, format("%-4d", 12) == "12 "); // padded, left justify + TEST(486, format("%-4d", 12345) == "12345"); // untruncated + + // string padding + TEST(487, format("%4s", "12") == " 12"); // padded + TEST(488, format("%-4s", "12") == "12 "); // padded, left justify + TEST(489, format("%-4s", "12345") == "12345"); // untruncated + + // string truncation + TEST(490, format("%.4s", "12") == "12"); // padded + TEST(491, format("%.4s", "12345") == "1234"); // truncated + // enhanced features - TEST(484, sprintf(s1, "Hello world") == 11); - TEST(485, sprintf(s1, "%*s", 20, "") == 20); - TEST(486, sprintf(s1, "%b", 0xf3) == 8 && s1 == "11110011"); - TEST(487, sprintf(s1, "val=%B", 3, "\10\2BITTWO\1BITONE") == 20 && + TEST(492, sprintf(s1, "Hello world") == 11); + TEST(493, sprintf(s1, "%*s", 20, "") == 20); + TEST(494, sprintf(s1, "%b", 0xf3) == 8 && s1 == "11110011"); + TEST(495, sprintf(s1, "val=%B", 3, "\10\2BITTWO\1BITONE") == 20 && s1 == "val=3"); - TEST(488, sprintf(s1, "12345%n6", "i") == 6 && i == 5); + TEST(496, sprintf(s1, "12345%n6", "i") == 6 && i == 5); // error cases - TEST(489, sprintf(s1, "%s", NULL) && s1 == ""); - TEST(490, sprintf(s1, "%s") && s1 == ""); - TEST(491, sprintf(s1, "%d", NULL) && s1 == "0"); - TEST(492, sprintf(s1, "%c", NULL) && s1 == " "); - TEST(493, sprintf(s1, "%.2f", NULL) && s1 == "0.00"); - TEST(494, sprintf(s1, "%y") && s1 == "y"); + TEST(497, sprintf(s1, "%s", NULL) && s1 == ""); + TEST(498, sprintf(s1, "%s") && s1 == ""); + TEST(499, sprintf(s1, "%d", NULL) && s1 == "0"); + TEST(500, sprintf(s1, "%c", NULL) && s1 == " "); + TEST(501, sprintf(s1, "%.2f", NULL) && s1 == "0.00"); + TEST(502, sprintf(s1, "%y") && s1 == "y"); // format - TEST(495, format("Hello World") == "Hello World"); - TEST(496, format("%b", 0xf3) == "11110011"); + TEST(503, format("Hello World") == "Hello World"); + TEST(504, format("%b", 0xf3) == "11110011"); // large argument list - TEST(497, format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", + TEST(505, format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.") == "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16."); - TEST(498, format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", + TEST(506, format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.") == "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16."); - TEST(499, format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", + TEST(507, format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.") == "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16."); - TEST(500, format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", + TEST(508, format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10.", "11.", "12.", "13.", "14.", "15.", "16.", @@ -2027,35 +2041,35 @@ __regress_replacement(int x, // return original 2th parameter // ret = __regress_replacement(2, a, b, c, d); - TEST(501, ret == a); + TEST(509, ret == a); break; case 2: // return original 2th parameter // ret = __regress_replacement(2, NULL, b, c, d); - TEST(502, ret == a); + TEST(510, ret == a); break; case 3: // return override 2th parameter // ret = __regress_replacement(2, 999, b, c, d); - TEST(503, ret == 999); + TEST(511, ret == 999); break; case 4: // return original 6th parameter // ret = __regress_replacement(6, a, b, c, d); - TEST(504, ret == e); + TEST(512, ret == e); break; case 5: // return original 6th parameter // ret = __regress_replacement(6, a, b, c, d, NULL); - TEST(505, ret == e); + TEST(513, ret == e); } return 42; } @@ -2073,7 +2087,7 @@ test_replacement(void) ret = __regress_replacement(3, 1, "2", l3, 4, 5, "6", l7, 8); ret = __regress_replacement(4, 1, "2", l3, 4, 5, "6", l7, 8); ret = __regress_replacement(5, 1, "2", l3, 4, 5, "6", l7, 8); - TEST(506, ret == 42); + TEST(514, ret == 42); } @@ -2084,21 +2098,21 @@ test_replacement(void) static void test_isa(void) { - TEST(507, isalpha('A')); - TEST(508, isascii('A')); - TEST(509, iscntrl(0x01)); - TEST(510, iscsym('_')); - TEST(511, isgraph('A')); - TEST(512, isprint('A')); - TEST(513, ispunct('!')); + TEST(515, isalpha('A')); + TEST(516, isascii('A')); + TEST(517, iscntrl(0x01)); + TEST(518, iscsym('_')); + TEST(519, isgraph('A')); + TEST(520, isprint('A')); + TEST(521, ispunct('!')); - TEST(514, isdigit('1') && isdigit(0x30) && isdigit("a1a", 2)); - TEST(515, isdigit("1a1") && isdigit("a1a", 2) && !isdigit("a1a", -1) && !isdigit("", 1)); - TEST(516, islower('a') && !islower('A')); - TEST(517, isupper('A') && !isupper('a')); - TEST(518, isalnum('Z') && !isalnum('*')); - TEST(519, isxdigit('f') && isxdigit('F') && isxdigit('1')); - TEST(520, isspace(' ') && isspace('\t') && isspace('\n') && !isspace('a')); + TEST(522, isdigit('1') && isdigit(0x30) && isdigit("a1a", 2)); + TEST(523, isdigit("1a1") && isdigit("a1a", 2) && !isdigit("a1a", -1) && !isdigit("", 1)); + TEST(524, islower('a') && !islower('A')); + TEST(525, isupper('A') && !isupper('a')); + TEST(526, isalnum('Z') && !isalnum('*')); + TEST(527, isxdigit('f') && isxdigit('F') && isxdigit('1')); + TEST(528, isspace(' ') && isspace('\t') && isspace('\n') && !isspace('a')); } @@ -2109,23 +2123,23 @@ test_isa(void) static void test_basedir(void) { - TEST(521, basename("dir/file") == "file"); - TEST(522, basename("dir/file.c", ".c") == "file"); - TEST(523, basename("", "") == ""); - TEST(524, basename("//", "") == "/"); - TEST(525, basename("dir/file/") == "file"); - TEST(526, basename("dir\\file/") == "file"); - TEST(527, basename("/x/") == "x"); - TEST(528, basename("x/") == "x"); - TEST(529, basename("/x") == "x"); + TEST(529, basename("dir/file") == "file"); + TEST(530, basename("dir/file.c", ".c") == "file"); + TEST(531, basename("", "") == ""); + TEST(532, basename("//", "") == "/"); + TEST(533, basename("dir/file/") == "file"); + TEST(534, basename("dir\\file/") == "file"); + TEST(535, basename("/x/") == "x"); + TEST(536, basename("x/") == "x"); + TEST(537, basename("/x") == "x"); - TEST(530, dirname(".") == "."); - TEST(531, dirname("/") == "/"); - TEST(532, dirname("//") == "/"); - TEST(533, dirname("/xx") == "/"); - TEST(534, dirname("//xx") == "/"); - TEST(535, dirname("aaa/bbb") == "aaa"); - TEST(536, dirname("aaaa//bbb/cccc///") == "aaaa//bbb" ); + TEST(538, dirname(".") == "."); + TEST(539, dirname("/") == "/"); + TEST(540, dirname("//") == "/"); + TEST(541, dirname("/xx") == "/"); + TEST(542, dirname("//xx") == "/"); + TEST(543, dirname("aaa/bbb") == "aaa"); + TEST(544, dirname("aaaa//bbb/cccc///") == "aaaa//bbb" ); } @@ -2137,21 +2151,21 @@ static void test_env(void) { putenv("GRREGRESS", "home"); - TEST(537, getenv("GRREGRESS") == "home"); - TEST(538, expandpath("$$/filename", 0x3) == "$/filename"); - TEST(539, expandpath("$GRREGRESS", 0x3) == "home"); - TEST(540, expandpath("$GRREGRESS/", 0x3) == "home/"); - TEST(541, expandpath("${GRREGRESS}xxx/", 0x3) == "homexxx/"); - TEST(542, expandpath("$(GRREGRESS)xxx/", 0x3) == "homexxx/"); + TEST(545, getenv("GRREGRESS") == "home"); + TEST(546, expandpath("$$/filename", 0x3) == "$/filename"); + TEST(547, expandpath("$GRREGRESS", 0x3) == "home"); + TEST(548, expandpath("$GRREGRESS/", 0x3) == "home/"); + TEST(549, expandpath("${GRREGRESS}xxx/", 0x3) == "homexxx/"); + TEST(550, expandpath("$(GRREGRESS)xxx/", 0x3) == "homexxx/"); /*invalid*/ - TEST(543, expandpath("${GRREGRESSxxx/", 0x3) == "${GRREGRESSxxx/"); - TEST(544, expandpath("$(GRREGRESSxxx/", 0x3) == "$(GRREGRESSxxx/"); - TEST(545, expandpath("${GRREGRESSxxx", 0x3) == "${GRREGRESSxxx"); - TEST(546, expandpath("$(GRREGRESSxxx", 0x3) == "$(GRREGRESSxxx"); - TEST(547, expandpath("$UNKNOWN/", 0x3) == "/"); - TEST(548, expandpath("$(UNKNOWN)xxx/", 0x3) == "xxx/"); - TEST(549, expandpath("${UNKNOWN}xxx/", 0x3) == "xxx/"); + TEST(551, expandpath("${GRREGRESSxxx/", 0x3) == "${GRREGRESSxxx/"); + TEST(552, expandpath("$(GRREGRESSxxx/", 0x3) == "$(GRREGRESSxxx/"); + TEST(553, expandpath("${GRREGRESSxxx", 0x3) == "${GRREGRESSxxx"); + TEST(554, expandpath("$(GRREGRESSxxx", 0x3) == "$(GRREGRESSxxx"); + TEST(555, expandpath("$UNKNOWN/", 0x3) == "/"); + TEST(556, expandpath("$(UNKNOWN)xxx/", 0x3) == "xxx/"); + TEST(557, expandpath("${UNKNOWN}xxx/", 0x3) == "xxx/"); } @@ -2166,22 +2180,22 @@ test_register(void) register_macro(REG_REGRESS, "__regress_event"); call_registered_macro(REG_REGRESS); - TEST(550, 1 == event); + TEST(558, 1 == event); event = 0; register_macro(REG_REGRESS, "__regress_event"); reregister_macro(REG_REGRESS, "__regress_event"); call_registered_macro(REG_REGRESS); - TEST(551, 2 == event); + TEST(559, 2 == event); event = 0; unregister_macro(REG_REGRESS, "__regress_event"); call_registered_macro(REG_REGRESS); - TEST(552, 1 == event); + TEST(560, 1 == event); event = 0; unregister_macro(REG_REGRESS, "__regress_event"); - TEST(553, 0 == event); + TEST(561, 0 == event); } @@ -2204,13 +2218,13 @@ test_buffer(void) if ((buf = create_buffer("-regress-buffer-", NULL, TRUE)) == -1) { return; } - TEST(554, curbuf == inq_buffer()); - TEST(555, curbuf == set_buffer(buf)); - TEST(556, buf == inq_buffer()); - TEST(557, 0 != inq_system()); - TEST(558, (inq_buffer_flags(buf) & BF_SYSBUF) == BF_SYSBUF); - TEST(559, 0 != inq_buffer_flags(NULL, "sysbuf")); - TEST(560, 0 == inq_modified()); + TEST(562, curbuf == inq_buffer()); + TEST(563, curbuf == set_buffer(buf)); + TEST(564, buf == inq_buffer()); + TEST(565, 0 != inq_system()); + TEST(566, (inq_buffer_flags(buf) & BF_SYSBUF) == BF_SYSBUF); + TEST(567, 0 != inq_buffer_flags(NULL, "sysbuf")); + TEST(568, 0 == inq_modified()); //TODO // set_attribute() // inq_attribute() @@ -2226,40 +2240,40 @@ test_buffer(void) top_of_buffer(); count = insert(sval); - TEST(561, slen == count); - TEST(562, slen == inq_line_length()); + TEST(569, slen == count); + TEST(570, slen == inq_line_length()); top_of_buffer(); line = read(NULL, status); - TEST(563, status == 1); /* EOF */ - TEST(564, line == sval); + TEST(571, status == 1); /* EOF */ + TEST(572, line == sval); line = read(slen, status); - TEST(565, status == 1); /* EOF */ - TEST(566, line == sval); + TEST(573, status == 1); /* EOF */ + TEST(574, line == sval); line = read(1, status); - TEST(567, status == 0); /* partial */ - TEST(568, line == "1"); + TEST(575, status == 0); /* partial */ + TEST(576, line == "1"); line = read(9, status); - TEST(569, status == 0); /* partial */ - TEST(570, line == "123456789"); + TEST(577, status == 0); /* partial */ + TEST(578, line == "123456789"); top_of_buffer(); count = insertf("%s\n", "abcdefg1234567890"); - TEST(571, 18 == count); - TEST(572, slen == inq_line_length()); + TEST(579, 18 == count); + TEST(580, slen == inq_line_length()); top_of_buffer(); line = read(NULL, status); - TEST(573, status == 1); /* EOF */ - TEST(574, line == "abcdefg1234567890\n"); + TEST(581, status == 1); /* EOF */ + TEST(582, line == "abcdefg1234567890\n"); } restore_position(2); - TEST(575, curbuf == inq_buffer()); - TEST(576, curwin == inq_window()); + TEST(583, curbuf == inq_buffer()); + TEST(584, curwin == inq_window()); delete_buffer(buf); } @@ -2267,7 +2281,7 @@ test_buffer(void) static void test_key(void) { - TEST(577, int_to_key(key_to_int("")) == ""); + TEST(585, int_to_key(key_to_int("")) == ""); } @@ -2277,11 +2291,11 @@ test_debug(void) list l1; l1 = debug_support(DBG_INQ_VARS, 0); - TEST(578, is_list(l1)); + TEST(586, is_list(l1)); l1 = debug_support(DBG_STACK_TRACE, NULL, ""); - TEST(579, is_list(l1)); + TEST(587, is_list(l1)); l1 = debug_support(DBG_INQ_VAR_INFO, 0, "l1"); - TEST(580, is_list(l1)); + TEST(588, is_list(l1)); } @@ -2291,27 +2305,27 @@ test_strtol(void) int ret, endp; ret = strtol("xxx"); /* basic */ - TEST(581, ret == 0); + TEST(589, ret == 0); ret = strtol("1"); /* dec */ - TEST(582, ret == 1); + TEST(590, ret == 1); ret = strtol("01"); /* oct */ - TEST(583, ret == 1); + TEST(591, ret == 1); ret = strtol("0x1"); /* hex */ - TEST(584, ret == 1); + TEST(592, ret == 1); ret = strtol("g", NULL, 36); /* base 36 (0123456789abc...) */ - TEST(585, ret == 16); + TEST(593, ret == 16); ret = strtol("xxx", endp); /* invalid */ - TEST(586, ret == 0); - TEST(587, endp == 0); + TEST(594, ret == 0); + TEST(595, endp == 0); ret = strtol("12", endp); - TEST(588, ret == 12); - TEST(589, endp == 3); + TEST(596, ret == 12); + TEST(597, endp == 3); } @@ -2322,24 +2336,24 @@ test_strtof(void) int endp; ret = strtof("0.0"); /* dec */ - TEST(590, ret == 0.0); + TEST(598, ret == 0.0); ret = strtof("1.0"); /* dec */ - TEST(591, ret == 1.0); + TEST(599, ret == 1.0); ret = strtof("xxx", endp); /* invalid */ - TEST(592, ret == 0); - TEST(593, endp == 0); + TEST(600, ret == 0); + TEST(601, endp == 0); ret = strtof("0.0"); /* dec */ - TEST(594, ret == 0.0); + TEST(602, ret == 0.0); ret = strtof("1.0"); /* dec */ - TEST(595, ret == 1.0); + TEST(603, ret == 1.0); ret = strtof("xxx", endp); /* invalid */ - TEST(596, ret == 0); - TEST(597, endp == 0); + TEST(604, ret == 0); + TEST(605, endp == 0); } @@ -2350,45 +2364,45 @@ test_strtod(void) int endp; ret = strtod("0.0"); /* dec */ - TEST(598, ret == 0.0); + TEST(606, ret == 0.0); ret = strtod("1.0"); /* dec */ - TEST(599, ret == 1.0); + TEST(607, ret == 1.0); ret = strtod("xxx", endp); /* invalid */ - TEST(600, ret == 0); - TEST(601, endp == 0); + TEST(608, ret == 0); + TEST(609, endp == 0); ret = strtod("0.0"); /* dec */ - TEST(602, ret == 0.0); + TEST(610, ret == 0.0); ret = strtod("1.0"); /* dec */ - TEST(603, ret == 1.0); + TEST(611, ret == 1.0); ret = strtod("xxx", endp); /* invalid */ - TEST(604, ret == 0); - TEST(605, endp == 0); + TEST(612, ret == 0); + TEST(613, endp == 0); } static void test_defaults1(int value = 666) { - TEST(606, value == 666); + TEST(614, value == 666); } static void test_defaults2(string value = "666") { - TEST(607, value == "666"); + TEST(615, value == "666"); } static void test_defaults3(string value = 1.1) { - TEST(608, value == 1.1); + TEST(616, value == 1.1); } @@ -2430,11 +2444,11 @@ test_reference(void) float fvalue = 1; test_reference1(ivalue); - TEST(609, ivalue == 2); + TEST(617, ivalue == 2); test_reference2(svalue); - TEST(610, svalue == "two"); + TEST(618, svalue == "two"); test_reference3(fvalue); - TEST(611, fvalue == 2); + TEST(619, fvalue == 2); } @@ -2454,7 +2468,7 @@ test_pushpop(void) sprintf(msg, "work%04d", i); push(l, msg); } - TEST(612, length_of_list(l) == 1000); + TEST(620, length_of_list(l) == 1000); for (i = i-1; i >= 0; --i) { sprintf(msg, "work%04d", i); @@ -2463,13 +2477,13 @@ test_pushpop(void) break; } } - TEST(613, success); + TEST(621, success); - TEST(614, length_of_list(l) == 0); + TEST(622, length_of_list(l) == 0); pause_on_error(0, FALSE); r = pop(l); pause_on_error(1, FALSE); - TEST(615, is_null(r)); /* FIXME/XXX - is_null(pop(l)) broken/limitation of LVAL's */ + TEST(623, is_null(r)); /* FIXME/XXX - is_null(pop(l)) broken/limitation of LVAL's */ } @@ -2478,12 +2492,12 @@ test_globals(void) { int line, col; - TEST(616, inq_window() == current_window); - TEST(617, inq_buffer() == current_buffer); + TEST(624, inq_window() == current_window); + TEST(625, inq_buffer() == current_buffer); inq_position(line, col); - TEST(618, line == current_line); + TEST(626, line == current_line); inq_position(line, col); - TEST(619, col == current_col); + TEST(627, col == current_col); } @@ -2494,7 +2508,7 @@ test_globals(void) static void test_search(void) { - TEST(620, quote_regexp("<>") == "\\<\\>"); + TEST(628, quote_regexp("<>") == "\\<\\>"); // search string // search buffer } @@ -2512,17 +2526,17 @@ test_search(void) static void test_called(void) { - TEST(621, "test_called" == caller()); + TEST(629, "test_called" == caller()); set_calling_name(""); - TEST(622, "" == caller()); + TEST(630, "" == caller()); set_calling_name("test_called"); - TEST(623, "test_called" == caller()); + TEST(631, "test_called" == caller()); set_calling_name("hello_world"); - TEST(624, "hello_world" == caller()); + TEST(632, "hello_world" == caller()); set_calling_name(inq_called()); - TEST(625, "regress" == caller()); + TEST(633, "regress" == caller()); set_calling_name(NULL); /* extension, reset/clear */ - TEST(626, "test_called" == caller()); + TEST(634, "test_called" == caller()); } @@ -2543,16 +2557,16 @@ test_macro(void) int ret; ret = inq_macro("regress"); /* defined */ - TEST(627, ret == 1); + TEST(635, ret == 1); ret = inq_macro("list_of_dictionaries"); /* builtin */ - TEST(628, ret == 0); + TEST(636, ret == 0); ret = inq_macro("cut"); /* replacement */ - TEST(629, ret == 2); + TEST(637, ret == 2); ret = inq_macro("this_should_not_be_undefined"); - TEST(630, ret == -1); /* undefined */ + TEST(638, ret == -1); /* undefined */ } @@ -2568,12 +2582,12 @@ test_undef(void) // // control how 'undefines' are handled?? // try { if (1) { - TEST(631, inq_symbol("undefined_ival") == 0); - TEST(632, inq_symbol("undefined_fval") == 0); - TEST(633, inq_symbol("undefined_sval") == 0); - TEST(634, undefined_ival == 0); /* wont be executed! */ - TEST(635, undefined_fval == 0); /* wont be executed! */ - TEST(636, undefined_sval == ""); /* wont be executed! */ + TEST(639, inq_symbol("undefined_ival") == 0); + TEST(640, inq_symbol("undefined_fval") == 0); + TEST(641, inq_symbol("undefined_sval") == 0); + TEST(642, undefined_ival == 0); /* wont be executed! */ + TEST(643, undefined_fval == 0); /* wont be executed! */ + TEST(644, undefined_sval == ""); /* wont be executed! */ } // } catch { // } finally { @@ -2592,12 +2606,12 @@ test_history(void) const string top = inq_macro_history(0); /* or from features */ - TEST(637, top == "execute_macro" || top == "sel_list"); - TEST(638, inq_command() == inq_macro_history()); + TEST(645, top == "execute_macro" || top == "sel_list"); + TEST(646, inq_command() == inq_macro_history()); set_macro_history(0, "function1"); set_macro_history(1, "function2"); - TEST(639, "function1" == inq_macro_history()); - TEST(640, "function2" == inq_macro_history(1)); + TEST(647, "function1" == inq_macro_history()); + TEST(648, "function2" == inq_macro_history(1)); } @@ -2609,24 +2623,24 @@ static void test_scope(void) { if (first_time()) { /* can only be run once */ - TEST(641, 1 == scope_1()); - TEST(642, 2 == scope_1()); - TEST(643, 3 == scope_1()); + TEST(649, 1 == scope_1()); + TEST(650, 2 == scope_1()); + TEST(651, 3 == scope_1()); - TEST(644, 1 == scope_2()); - TEST(645, 2 == scope_2()); - TEST(646, 3 == scope_2()); + TEST(652, 1 == scope_2()); + TEST(653, 2 == scope_2()); + TEST(654, 3 == scope_2()); - TEST(647, 1 == scope_3()); - TEST(648, 2 == scope_3()); - TEST(649, 3 == scope_3()); + TEST(655, 1 == scope_3()); + TEST(656, 2 == scope_3()); + TEST(657, 3 == scope_3()); } else { /* emulate */ extern int num_passed; num_passed += 9; } - TESTASYNC(650, 0 == inq_symbol("x_extern_dontexist")); - TEST(651, 0 != inq_symbol("x_static")); + TESTASYNC(658, 0 == inq_symbol("x_extern_dontexist")); + TEST(659, 0 != inq_symbol("x_static")); } @@ -2682,38 +2696,38 @@ test_dict(void) /* create dictionaries */ dict = create_dictionary(); - TEST(652, dict); + TEST(660, dict); dict2 = create_dictionary("namedict"); - TEST(653, dict2); + TEST(661, dict2); /* basic set/get primitives */ set_property(dict, "property", 1234); var = get_property(dict, "property"); - TEST(654, 1234 == var); + TEST(662, 1234 == var); set_property(dict, "property", "hello world"); var = get_property(dict, "property"); - TEST(655, "hello world" == var); + TEST(663, "hello world" == var); /* indirection operators */ dict.value = "value1"; /* FIXME/XXX - compiler issues yet resolved */ - TEST(656, "value1" == dict.value); + TEST(664, "value1" == dict.value); dict2.value = "value2"; dict.indirect = dict2; /* FIXME/XXX - reference count issues */ - TEST(657, "value2" == dict.indirect.value); + TEST(665, "value2" == dict.indirect.value); ret = dict_exists(dict, "property"); - TEST(658, ret); + TEST(666, ret); l1 = dict_list(dict); - TEST(659, is_list(l1)); - TEST(660, 3 == length_of_list(l1)); + TEST(667, is_list(l1)); + TEST(668, 3 == length_of_list(l1)); set_property(dict, "property2", 1234); set_property(dict, "property3", 5678); l1 = dict_list(dict); - TEST(661, 5 == length_of_list(l1)); + TEST(669, 5 == length_of_list(l1)); // FIXME/XXX -- // compiler bug, allows declare when string expected. @@ -2726,36 +2740,36 @@ test_dict(void) while ((idx = dict_each(dict, key, value)) >= 0) { switch(key) { case "property": - TESTASYNC(662, "hello world" == value); + TESTASYNC(670, "hello world" == value); ++count; break; case "property2": - TESTASYNC(663, 1234 == value); + TESTASYNC(671, 1234 == value); ++count; break; case "property3": - TESTASYNC(664, 5678 == value); + TESTASYNC(672, 5678 == value); ++count; break; } } - TESTASYNC(665, 3 == count); + TESTASYNC(673, 3 == count); ret = dict_delete(dict, "property"); - TEST(666, 0 == ret); + TEST(674, 0 == ret); l1 = dict_list(dict); - TEST(667, is_list(l1)); - TEST(668, 4 == length_of_list(l1)); + TEST(675, is_list(l1)); + TEST(676, 4 == length_of_list(l1)); l1 = list_of_dictionaries(); - TEST(669, is_list(l1)); - TEST(670, length_of_list(l1) >= 2); /* all dictionaries */ + TEST(677, is_list(l1)); + TEST(678, length_of_list(l1) >= 2); /* all dictionaries */ ret = delete_dictionary(dict); - TEST(671, 0 == ret); + TEST(679, 0 == ret); ret = delete_dictionary(dict2); - TEST(672, 0 == ret); + TEST(680, 0 == ret); } @@ -2767,7 +2781,7 @@ test_dict(void) static int test_leaks(void) { - TEST(673, leak_1(1000) == 1000); /* list are limited 2^16 atoms */ + TEST(681, leak_1(1000) == 1000); /* list are limited 2^16 atoms */ } @@ -2872,8 +2886,8 @@ regress_renumber(void) while (re_search(0, "TES[A-Z]+([0-9]+,") > 0) { /* * examples: - * TEST(674, - * TESTASYNC(675, + * TEST(682, + * TESTASYNC(683, */ line = read(18); delete_char(index(line, ",")); diff --git a/makeconfig.pm b/makeconfig.pm index 644b7a6c..d8bcd046 100644 --- a/makeconfig.pm +++ b/makeconfig.pm @@ -1,10 +1,10 @@ -# $Id: makeconfig.pm,v 1.3 2022/03/22 08:02:55 cvsuser Exp $ +# $Id: makeconfig.pm,v 1.6 2022/06/11 03:58:10 cvsuser Exp $ # Makefile generation under Win32. # -*- perl; tabs: 8; indent-width: 4; -*- # Automake emulation for non-unix environments. # # -# Copyright (c) 2020, Adam Young. +# Copyright (c) 2020 - 2022, Adam Young. # All rights reserved. # # This file is part of GRIEF @@ -62,11 +62,15 @@ our @MAKEFILES = (); # local makefiles; build order our @LIBRARIES = (); # local libraries -l lib.lib our @LIBRARIES2 = (); # local libraries -l xxx.lib +our @TESTLIBRARIES = (); # external libraries, tested whether linkable our @OPTLIBRARIES = (); # optional libraries my $CC = ''; +my $CCVER = ''; my $CXX = ''; +my $CXXVER = ''; my $RTLIBRARY = ''; +my $WINSDKLIB = ''; my %DEFS = (); my %CDEFS = (); @@ -100,7 +104,8 @@ my @__target_configurations = (ALL, RELEASE, DEBUG); # Function: # Constructor -sub New() { +sub New() +{ my ($class) = shift; my $self = {}; bless $self, $class; @@ -114,7 +119,8 @@ sub New() { # Returns: # nothing # -sub LoadProfile($$) { +sub LoadProfile($$) +{ my ($self, $makelib) = @_; print "loading: ${makelib}\n"; @@ -131,12 +137,14 @@ sub LoadProfile($$) { # Returns: # nothing # -sub LoadConfigure($$$$$) { +sub LoadConfigure($$$$$$) +{ my ($self, $makelib, $type_, $env_, $tokens_, $verbose_) = @_; $x_env = $env_; $x_tokens = $tokens_; $o_verbose = $verbose_; + $self->__ImportConfigurations($makelib); print "loading: ${makelib}, <${TOOLCHAIN}>\n"; @@ -160,7 +168,8 @@ sub LoadConfigure($$$$$) { } -sub __ImportConfigurations { +sub __ImportConfigurations +{ my ($self, $makelib) = @_; $TOOLCHAIN = $$x_tokens{TOOLCHAIN}; @@ -169,12 +178,21 @@ sub __ImportConfigurations { $CC = $$x_tokens{CC} # Program for compiling C programs. if (defined $$x_tokens{CC}); + $CCVER = $$x_tokens{CCVER} # C standard + if (defined $$x_tokens{CCVER}); + $CXX = $$x_tokens{CXX} # Program for compiling C++ programs. if (defined $$x_tokens{CXX}); + $CXXVER = $$x_tokens{CXXVER} # C++ standard + if (defined $$x_tokens{CXXVER}); + $RTLIBRARY = $$x_tokens{RTLIBRARY} # Default Run-Time library. if (defined $$x_tokens{RTLIBRARY}); + $WINSDKLIB = $$x_tokens{WINSDKLIB} # SDK library path. + if (defined $$x_tokens{WINSDKLIB}); + push @{$DEFS{ALL}}, split(/ /, $$x_tokens{DEFS}) # Common definitions if (defined $$x_tokens{DEFS}); @@ -267,7 +285,8 @@ sub __ImportConfigurations { } -sub __ExportConfigurations { +sub __ExportConfigurations +{ my ($self) = shift; if ($o_verbose >= 3) { @@ -300,6 +319,7 @@ sub __ExportConfigurations { $self->{MAKEFILES} = \@MAKEFILES; $self->{LIBRARIES} = \@LIBRARIES; $self->{LIBRARIES2} = \@LIBRARIES2; + $self->{TESTLIBRARIES} = \@TESTLIBRARIES; $self->{OPTLIBRARIES} = \@OPTLIBRARIES; $$x_tokens{PACKAGE_VERSION} = $PACKAGE_VERSION; @@ -309,8 +329,11 @@ sub __ExportConfigurations { $$x_tokens{PACKAGE_TARNAME} = $PACKAGE_TARNAME; $$x_tokens{CC} = $CC; + $$x_tokens{CCVER} = $CCVER; $$x_tokens{CXX} = $CXX; + $$x_tokens{CXXVER} = $CXXVER; $$x_tokens{RTLIBRARY} = $RTLIBRARY; + $$x_tokens{WINSDKLIB} = $WINSDKLIB; $$x_tokens{INCLUDE} = __PrintArrayX('', ';', \@INCLUDE); $$x_tokens{XINCLUDE} = __PrintArrayX('', ';', \@XINCLUDE); @@ -347,6 +370,7 @@ sub __ExportConfigurations { print "\n"; print " DEFS $$x_tokens{DEFS}\n"; print " RTLIBRARY ${RTLIBRARY}\n" if ($RTLIBRARY); + print " WINSDKLIB ${WINSDKLIB}\n" if ($WINSDKLIB); print " CFLAGS $$x_tokens{CFLAGS}\n"; print " CRELEASE $$x_tokens{CRELEASE}\n"; print " CDEBUG $$x_tokens{CDEBUG}\n"; @@ -368,7 +392,8 @@ sub __ExportConfigurations { } -sub __PrintArray { +sub __PrintArray +{ my $s = ''; for (my $i = 0; $i < scalar @_; ++$i) { my $value = $_[$i]; @@ -385,7 +410,8 @@ sub __PrintArray { } -sub __PrintArrayX { +sub __PrintArrayX +{ my $prefix = shift || ''; my $suffix = shift || ''; my $s = ''; @@ -405,6 +431,52 @@ sub __PrintArrayX { } +# Function: +# set_c_standard +# Parameters: +# standard - C standad, 90, 99, 11, 17, 23 +# +sub +set_c_standard($) +{ + my ($standard) = @_; + my $version = int($standard); + + ($version == 98 || $version == 99 || $version == 11 || $version == 17) or + die "set_C_standard: invalid standard <${standard}>\n"; + + if ('gcc' eq $CC || 'g++' eq $CC) { + $CCVER = "-std=c${version}"; + + } else { + die "set_c_standard: unsupport toolchain <${CC}>\n"; + } +} + + +# Function: +# set_cxx_standard +# Parameters: +# standard - C++ standad, 98, 11, 14, or 17. +# +sub +set_cxx_standard($) +{ + my ($standard) = @_; + my $version = int($standard); + + ($version == 98 || $version == 11 || $version == 14 || $version == 17) or + die "set_CXX_standard: invalid standard <${standard}>\n"; + + if ('gcc' eq $CC || 'g++' eq $CC) { + $CXXVER = "-std=c++${version}"; + + } else { + die "set_cxx_standard: unsupport toolchain <${CC}>\n"; + } +} + + # Function: # set_msvc_runtime - Set the default MSVC run-time library. # Parameters: @@ -434,7 +506,8 @@ sub __PrintArrayX { # into the .obj file so that the linker will use LIBCMTD.lib to resolve external symbols. # sub -set_msvc_runtime($;$) { +set_msvc_runtime($;$) +{ my ($type, $suffix) = @_; $suffix = '$(BUILD_TYPE)' @@ -491,6 +564,24 @@ set_msvc_runtime($;$) { } +# Function: +# set_winsdk - Windows SDK configuration. +# Parameters: +# lib - library path. +# Returns: +# nothing +sub +set_winsdk($;$) +{ + my ($lib, $inc) = @_; + + $WINSDKLIB = $lib + if (defined $lib); + + verbose("set_winsdk: <${WINSDKLIB}>"); +} + + # Function: # remove_define - Remove the matching definition. # Parameters: @@ -499,7 +590,8 @@ set_msvc_runtime($;$) { # 1 if matched, otherwise 0. # sub -remove_define($;$) { +remove_define($;$) +{ my ($def, $type) = @_; my ($var, $val) = split(/=/, $def); @@ -527,7 +619,8 @@ remove_define($;$) { # nothing # sub -add_define($;$) { +add_define($;$) +{ my ($def, $type) = @_; my ($var, $val) = split(/=/, $def); @@ -552,7 +645,8 @@ add_define($;$) { sub -add_cdefine($;$) { +add_cdefine($;$) +{ my ($def, $type) = @_; my ($var, $val) = split(/=/, $def); @@ -576,7 +670,8 @@ add_cdefine($;$) { sub -add_cxxdefine($;$) { +add_cxxdefine($;$) +{ my ($def, $type) = @_; my ($var, $val) = split(/=/, $def); @@ -608,7 +703,8 @@ add_cxxdefine($;$) { # nothing # sub -add_cflag($;$) { +add_cflag($;$) +{ my ($flag,$type) = @_; $type = ALL if (! $type); verbose("add_cflag:\t <${flag},${type}>"); @@ -625,7 +721,8 @@ add_cflag($;$) { # nothing # sub -add_cxxflag($;$) { +add_cxxflag($;$) +{ my ($flag,$type) = @_; $type = ALL if (! $type); verbose("add_cxxflag:\t <${flag},${type}>"); @@ -642,7 +739,8 @@ add_cxxflag($;$) { # nothing # sub -add_ldflag($;$) { +add_ldflag($;$) +{ my ($flag,$type) = @_; $type = ALL if (! $type); verbose("add_ldflag:\t <${flag},${type}>"); @@ -658,7 +756,8 @@ add_ldflag($;$) { # nothing # sub -add_include($) { +add_include($) +{ my ($inc) = shift; verbose("add_include:\t <${inc}>"); @@ -667,7 +766,8 @@ add_include($) { sub -add_cinclude($) { +add_cinclude($) +{ my ($inc) = shift; verbose("add_cinclude:\t <${inc}>"); @@ -676,7 +776,8 @@ add_cinclude($) { sub -add_xinclude($) { +add_xinclude($) +{ my ($inc) = shift; verbose("add_xinclude:\t <${inc}>"); @@ -686,7 +787,8 @@ add_xinclude($) { sub -add_cxxinclude($) { +add_cxxinclude($) +{ my ($inc) = shift; verbose("add_cxxinclude:\t <${inc}>"); @@ -702,7 +804,8 @@ add_cxxinclude($) { # nothing # sub -add_application_library($) { +add_application_library($) +{ my ($lib) = shift; verbose("add_application_library:\t <${lib}>"); @@ -718,7 +821,8 @@ add_application_library($) { # nothing # sub -add_system_library($) { +add_system_library($) +{ my ($lib) = shift; verbose("add_system_library:\t <${lib}>"); @@ -752,3 +856,4 @@ verbose { } 1; + diff --git a/makelib.in b/makelib.in index 21f87691..a7fb3058 100644 --- a/makelib.in +++ b/makelib.in @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: makelib.in,v 1.8 2021/07/05 17:18:41 cvsuser Exp $ +# $Id: makelib.in,v 1.14 2022/06/13 14:33:05 cvsuser Exp $ # -*- mode: perl; tabs: 8; indent-width: 4; -*- # makelib configuration # @@ -26,7 +26,11 @@ ## Package $PACKAGE = 'grief'; +$PACKAGE_NAME = 'GRIEF - BRIEF clone'; $PACKAGE_NAME = 'GriefEdit'; + +$PACKAGE_URL = 'https://github.com/adamyg/grief'; + $PACKAGE_PATH = 'include'; $PACKAGE_FILE = 'edpackage.h'; @@ -62,6 +66,7 @@ $PACKAGE_FILE = 'edpackage.h'; # 'libz_static', ); +@TESTLIBRARIES = (); # library test @OPTLIBRARIES = ( # optional libraries 'aspell', 'iconv', @@ -125,11 +130,57 @@ $PACKAGE_FILE = 'edpackage.h'; ## Toolchain +sub +ResolveWINKITx86() +{ + my $ProgramFiles = $ENV{"ProgramFiles(x86)"}; + $ProgramFiles =~ s/\\/\//g; + + my @WINKIT = ( # Vista+ + # https://en.wikipedia.org/wiki/Microsoft_Windows_SDK + "${ProgramFiles}/Windows Kits/8.0/Lib/win8/um/x86", + "${ProgramFiles}/Windows Kits/8.1/Lib/winv6.3/um/x86", + "${ProgramFiles}/Windows Kits/10", + "${ProgramFiles}/Windows Kits/11" + ); + + my @sdks; + foreach (@WINKIT) { + my $sdk = $_; + next if (! -d $sdk); + + if (/\/1[01]$/) { # "Lib/10.0.xxxxx.0/um/x86" + my @winsdk10 = glob("'${sdk}/Lib/*/um/x86'"); + foreach (@winsdk10) { + next if (! -f "$_/Kernel32.lib"); + push @sdks, $_; + } + + } else { + next if (! -f "${sdk}/Kernel32.lib"); + push @sdks, $sdk; + } + } + + die "cannot locate any suitable winsdks\n" + if (! scalar @sdks); + + foreach (@sdks) { + print "WINKIT: $_\n"; + } + + set_winsdk($sdks[0]); +} + + sub Configure() { - # Visual studio ################################################################################ + # Common + + ################################################################################ + # Visual studio if ($TOOLCHAIN =~ /^vs/) { @@ -138,15 +189,15 @@ Configure() remove_define('WIN32'); add_define('HAVE_CONFIG_H'); add_define('WIN32_WINNT=0x501'); + add_define('_CRT_SECURE_NO_WARNINGS'); + add_define('_CRT_SECURE_NO_DEPRECATE'); + add_define('_CRT_NONSTDC_NO_DEPRECATE'); - # Extra includes; C and compiler tests. add_xinclude('$(ROOT)/libw32'); add_xinclude('$(ROOT)/libw32/msvc'); # MSVC specials - add_application_library('libw32.lib'); } - ################################################################################ # OpenWatcom @@ -155,12 +206,43 @@ Configure() remove_define('WIN32'); add_define('HAVE_CONFIG_H'); add_define('WIN32_WINNT=0x501'); + add_define('__STDC_WANT_LIB_EXT1__'); - # Extra includes; C and compiler tests. add_xinclude('$(ROOT)/libw32'); - add_application_library('libw32.lib'); } + + ################################################################################ + # MingGW + + if ($TOOLCHAIN =~ /^mingw/) { + + remove_define('WIN32'); + add_define('HAVE_CONFIG_H'); + add_define('_WIN32_WINNT=0x501'); # Windows SDK + add_define('_WIN32_VER=0x501'); + + add_xinclude('$(ROOT)/libw32'); + add_application_library('libw32.a'); + + if ($TOOLCHAIN =~ /^mingw(64|32)/) { # newer libraries + add_system_library('-lDbghelp'); + add_system_library('-lBcrypt'); + add_system_library('-lNcrypt'); + } + + add_system_library('-lComctl32'); # updater, common controls + add_system_library('-lOleAut32'); + + add_system_library('-lMswsock'); + add_system_library('-lCrypt32'); + add_system_library('-lRpcrt4'); + add_system_library('-lWinmm'); + add_system_library('-lIphlpapi'); + add_system_library('-lVersion'); + + push @TESTLIBRARIES, "pthread|LIBTHREAD"; + } } @@ -212,4 +294,3 @@ Configure() # 1; - diff --git a/makelib.pl b/makelib.pl index 4c7a14da..5acc5a8c 100644 --- a/makelib.pl +++ b/makelib.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: makelib.pl,v 1.123 2022/03/22 08:07:31 cvsuser Exp $ +# $Id: makelib.pl,v 1.134 2022/06/16 08:46:20 cvsuser Exp $ # Makefile generation under WIN32 (MSVC/WATCOMC/MINGW) and DJGPP. # -*- perl; tabs: 8; indent-width: 4; -*- # Automake emulation for non-unix environments. @@ -28,6 +28,17 @@ # GNU General Public License for more details. # ==end== # +# MSYS/MINGW install +# +# Download and install: msys2-x86_64-YYYYMMDD.exe, then +# +# pacman -S base-devel +# +# pacman -S mingw-w64-x86_64-gcc [64-bit] +# or pacman -S mingw-w64-x86_64-toolchain +# +# pacman -S mingw-w64-i686-gcc [32-bit] +# use strict; use warnings; @@ -78,31 +89,94 @@ BEGIN CWARN => '-W -Wall -Wshadow -Wmissing-prototypes', }, - 'mingw' => { # MingW - build_os => 'mingw32', + 'mingw' => { # MingW32 or MingW64 (default os) TOOLCHAIN => 'mingw', TOOLCHAINEXT => '.mingw', CC => 'gcc', CXX => 'g++', + VSWITCH => '--version', + VPATTERN => 'gcc \([^)]*\) ([0-9\.]+)', + OSWITCH => '', + LSWITCH => '-l', + XSWITCH => '-o', + AR => 'ar', + RC => 'windres -DGCC_WINDRES', + DEFS => '-DHAVE_CONFIG_H', + CINCLUDE => '', + CFLAGS => '@CCVER@ -fno-strength-reduce', + CCVER => '-std=gnu11', + CXXFLAGS => '@CXXVER@ -fno-strength-reduce', + CXXVER => '-std=c++11', + CDEBUG => '-g', + CWARN => '-W -Wall -Wshadow -Wmissing-prototypes', + CXXWARN => '-W -Wall -Wshadow', + LDFLAGS => '', + LDDEBUG => '-g', + LDRELEASE => '', + LDMAPFILE => '-Xlinker -Map=$(MAPFILE)', + EXTRALIBS => '-lshlwapi -lpsapi -lole32 -luuid -lgdi32 '. + '-luserenv -lnetapi32 -ladvapi32 -lshell32 -lmpr -lWs2_32', + LIBMALLOC => '-ldlmalloc', + }, + + 'mingw32' => { # MingW64 (32-bit mode) + TOOLCHAIN => 'mingw32', + TOOLCHAINEXT => '.mingw32', + CC => 'gcc', + CXX => 'g++', + VSWITCH => '--version', + VPATTERN => 'gcc \([^)]*\) ([0-9\.]+)', + OSWITCH => '', + LSWITCH => '-l', + XSWITCH => '-o', + AR => 'ar', + RC => 'windres -DGCC_WINDRES', + DEFS => '-DHAVE_CONFIG_H', + CINCLUDE => '', + CFLAGS => '-m32 @CCVER@ -fno-strength-reduce', + CCVER => '-std=gnu11', + CXXFLAGS => '-m32 @CXXVER@ -fno-strength-reduce', + CXXVER => '-std=c++11', + CDEBUG => '-g', + CWARN => '-W -Wall -Wshadow -Wmissing-prototypes', + CXXWARN => '-W -Wall -Wshadow', + LDFLAGS => '', + LDDEBUG => '-g', + LDRELEASE => '', + LDMAPFILE => '-Xlinker -Map=$(MAPFILE)', + EXTRALIBS => '-lshlwapi -lpsapi -lole32 -luuid -lgdi32 '. + '-luserenv -lnetapi32 -ladvapi32 -lshell32 -lmpr -lWs2_32', + LIBMALLOC => '-ldlmalloc', + }, + + 'mingw64' => { # MingW64 (64-bit mode) + ISWIN64 => 'yes', + TOOLCHAIN => 'mingw64', + TOOLCHAINEXT => '.mingw64', + CC => 'gcc', + CXX => 'g++', + VSWITCH => '--version', + VPATTERN => 'gcc \([^)]*\) ([0-9\.]+)', OSWITCH => '', LSWITCH => '-l', XSWITCH => '-o', AR => 'ar', RC => 'windres -DGCC_WINDRES', - DEFS => '-DHAVE_CONFIG_H -D_WIN32_WINNT=0x501', + DEFS => '-DHAVE_CONFIG_H', CINCLUDE => '', - CFLAGS => '-std=gnu11 -fno-strength-reduce', - CXXFLAGS => '-std=c++11 -fno-strength-reduce', + CFLAGS => '-m64 @CCVER@ -fno-strength-reduce', + CCVER => '-std=gnu11', + CXXFLAGS => '-m64 @CXXVER@ -fno-strength-reduce', + CXXVER => '-std=c++11', CDEBUG => '-g', CWARN => '-W -Wall -Wshadow -Wmissing-prototypes', CXXWARN => '-W -Wall -Wshadow', LDFLAGS => '', - LDDEBUG => '', + LDDEBUG => '-g', LDRELEASE => '', LDMAPFILE => '-Xlinker -Map=$(MAPFILE)', EXTRALIBS => '-lshlwapi -lpsapi -lole32 -luuid -lgdi32 '. - '-luserenv -lnetapi32 -ladvapi32 -lshell32 -lWs2_32', - LIBTHREAD => '-lpthread', + '-luserenv -lnetapi32 -ladvapi32 -lshell32 -lmpr -lWs2_32', LIBMALLOC => '-ldlmalloc', }, @@ -172,9 +246,10 @@ BEGIN LSWITCH => '', XSWITCH => '-Fe', AR => 'lib', + RC => 'rc', # no, /nologo option CINCLUDE => '', RTLIBRARY => '-MDd', - CFLAGS => '-nologo @RTLIBRARY@', + CFLAGS => '-nologo @RTLIBRARY@ -Dinline=__inline', CXXFLAGS => '-nologo @RTLIBRARY@ -EHsc', CDEBUG => '-Zi -RTC1 -Od', CRELEASE => '-O2 -DNDEBUG', @@ -363,7 +438,7 @@ BEGIN CINCLUDE => '', RTLIBRARY => '-MDd', CFLAGS => '-nologo @RTLIBRARY@ -fp:precise', - CXXFLAGS => '-nologo @RTLIBRARY@ -EHsc -fp:precise', + CXXFLAGS => '-nologo @RTLIBRARY@ -EHsc -fp:precise -Zc:offsetof-', CDEBUG => '-Zi -RTC1 -Od', CRELEASE => '-O2 -GL -Gy -DNDEBUG', CWARN => '-W3', @@ -401,7 +476,7 @@ BEGIN CINCLUDE => '', RTLIBRARY => '-MDd', CFLAGS => '-nologo @RTLIBRARY@ -fp:precise', - CXXFLAGS => '-nologo @RTLIBRARY@ -EHsc -fp:precise', + CXXFLAGS => '-nologo @RTLIBRARY@ -EHsc -fp:precise -Zc:offsetof-', CDEBUG => '-Zi -RTC1 -Od', CRELEASE => '-O2 -GL -Gy -DNDEBUG', CWARN => '-W3', @@ -470,6 +545,7 @@ BEGIN # -d2i C++ only; d2 and debug inlines. # -hc Generate Codeview debugging information. # or -hw Generate Watcomc debugging information. + # or -hd Dwarf debugging information (perferred format). # -db Generate browsing information (.mbr). # -o.. Optimization(s) # f -> generate traceable stack frames as needed @@ -503,20 +579,20 @@ BEGIN # CFLAGS => '-q -6r -j -ei -db -zlf -bt=nt -bm -br -aa -sg', CXXFLAGS => '-q -6r -j -ei -db -zlf -bt=nt -bm -br -cc++ -xs -xr', - CDEBUG => '-d2 -hw -of+ ', - CXXDEBUG => '-d1 -hw -od', #d2/d3 under hw generates invalid symbols + CDEBUG => '-d2 -hd -of+ ', + CXXDEBUG => '-d2 -hd -od', #d2/d3 under hw generates invalid symbols CRELEASE => '-ox -DNDEBUG', CWARN => '-W3', CXXWARN => '-W3', LDFLAGS => '-q -6r -db -bt=nt -bm -br', - LDDEBUG => '-d2 -hw', + LDDEBUG => '-d2 -hd', LDRELEASE => '', LDMAPFILE => '-fm=$(MAPFILE)', # 7600.16385.1: Windows Driver Kit Version 7.1.0 # ==> http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=11800 MFCDIR => '/tools/WinDDK/7600.16385.1', - MFCCFLAGS => '-q -j -ei -6r -d2 -hw -db -ofr -zlf -bt=nt -bm -br -aa', + MFCCFLAGS => '-q -j -ei -6r -d2 -hd -db -ofr -zlf -bt=nt -bm -br -aa', MFCCXXFLAGS => '-q -j -ei -6r -d2i -db -ofr -zlf -bt=nt -bm -br -xs -xr -cc++', MFCCOPT => '', MFCCXXOPT => '', @@ -570,7 +646,7 @@ BEGIN LDMAPFILE => '-fm=$(MAPFILE)', MFCDIR => '/tools/WinDDK/7600.16385.1', - MFCCOPT => '-q -j -ei -6r -d2 -hw -db -ofr -zlf -bt=nt -bm -br -aa', #TODO + MFCCOPT => '-q -j -ei -6r -d2 -hd -db -ofr -zlf -bt=nt -bm -br -aa', #TODO MFCCXXOPT => '-q -j -ei -6r -d2i -db -ofr -zlf -bt=nt -bm -br -xs -xr -cc++', #TODO MFCCINCLUDE => '-I$(MFCDIR)/inc/atl71 -I$(MFCDIR)/inc/mfc42', MFCLIBS => '/LIBPATH:$(MFCDIR)\lib\atl\i386 /LIBPATH:$(MFCDIR)\lib\mfc\i386' @@ -601,6 +677,7 @@ BEGIN # -d2i C++ only; d2 and debug inlines. # -hc Generate Codeview debugging information. # or -hw Generate Watcomc debugging information. + # or -hd Dwarf debugging information. # -db Generate browsing information (.mbr). # -o.. Optimization(s) # f -> generate traceable stack frames as needed @@ -633,20 +710,22 @@ BEGIN # CFLAGS => '-q -6r -j -ei -db -zlf -bt=nt -bm -br -aa -sg', CXXFLAGS => '-q -6r -j -ei -db -zlf -bt=nt -bm -br -cc++ -xs -xr', - CDEBUG => '-d2 -hw -of+ ', - CXXDEBUG => '-d2i -hw -od', + CDEBUG => '-d2 -hd -of+', + ## CXXDEBUG => '-d2i -hd -od', + CXXDEBUG => '-d2 -hd -od', CRELEASE => '-ox -DNDEBUG', CWARN => '-W3', CXXWARN => '-W3', LDFLAGS => '-q -6r -db -bt=nt -bm -br', - LDDEBUG => '-d2 -hw', + LDDEBUG => '-d2 -hd', LDRELEASE => '', LDMAPFILE => '-fm=$(MAPFILE)', # not-supported MFCDIR => '/tools/WinDDK/7600.16385.1', - MFCCOPT => '-q -j -ei -6r -d2 -hw -db -ofr -zlf -bt=nt -bm -br -aa', - MFCCXXOPT => '-q -j -ei -6r -d2i -db -ofr -zlf -bt=nt -bm -br -xs -xr -cc++', + MFCCOPT => '-q -j -ei -6r -d2 -hd -db -ofr -zlf -bt=nt -bm -br -aa', + ## MFCCXXOPT => '-q -j -ei -6r -d2i -db -ofr -zlf -bt=nt -bm -br -xs -xr -cc++', + MFCCXXOPT => '-q -j -ei -6r -d2 -db -ofr -zlf -bt=nt -bm -br -xs -xr -cc++', MFCCINCLUDE => '-I$(MFCDIR)/inc/atl71 -I$(MFCDIR)/inc/mfc42', MFCLIBS => '/LIBPATH:$(MFCDIR)\lib\atl\i386 /LIBPATH:$(MFCDIR)\lib\mfc\i386' } @@ -662,6 +741,7 @@ BEGIN RMDIR => '@BINPATH@rmdir.exe', ISWIN32 => 'yes', + ISWIN64 => 'no', PATHSEP => ';', DEFS => '-DHAVE_CONFIG_H -DWIN32=0x501', @@ -679,7 +759,7 @@ BEGIN LIBTOOL => '@PERLPATH@perl '.'$', CPPDEP => '', LT_OBJDIR => '.libs/', - RC => 'rc', + RC => 'rc /nologo', LIBS => '', EXTRALIBS => 'advapi32.lib gdi32.lib'. @@ -847,6 +927,7 @@ BEGIN 'sys/wait.h', 'sys/mman.h', 'sys/utime.h', + 'sys/timeb.h', 'sys/mount.h', 'sys/stat.h', 'sys/statfs.h', @@ -894,10 +975,24 @@ BEGIN ); my @x_headers2 = ( #headers; check only - 'xthreads.h', # MSVC +2017, almost C11 + 'thr/xthreads.h', # MSVC +2017, almost C11 + 'xthreads.h', 'windows.h', 'wincrypt.h', - 'bcrypt.h' + 'bcrypt.h', + 'intrin.h', + 'afunix.h' # AF_UNIX + ); + +my @x_predefines = ( + '_MSC_VER|_MSC_FULL_VER', + '__WATCOMC__', + '__GNUC__|__GNUC_MINOR__', + '__MINGW32__|__MINGW64__|__MINGW64_VERSION_MAJOR|__MINGW64_VERSION_MINOR', + '__STDC__|__STDC_VERSION__', + 'cpp=__cplusplus', + 'cpp=__STDC_HOSTED__', + 'cpp=__STDC_NO_ATOMICS__', ); my @x_decls = ( #stdint/intypes.h @@ -922,7 +1017,7 @@ BEGIN 'WCHAR_MAX', 'INTMAX_MIN', 'INTMAX_MAX', - 'UINTMAX_MAX', + 'UINTMAX_MAX' ); my @x_types = ( #stdint/inttypes/types.h @@ -985,6 +1080,7 @@ BEGIN 'memccpy', '_memccpy', # bsd/msvc 'index', 'rindex', # bsd 'strcasecmp', '__strcasecmp', 'stricmp', + 'strncasecmp', '__strncasecmp', 'strnicmp', 'strtoul', 'strnlen', 'strerror', @@ -993,6 +1089,8 @@ BEGIN 'strlcpy', 'strlcat', # bsd/linux 'strsep', 'strnstr', 'strcasestr', 'strcasestr_l', 'strtonum', 'strtof', 'strtold', 'strtoll', + 'strtok_r', + 'sprintf_s', 'wsprintf_s', 'strverscmp', '__strverscmp', 'mkdtemp', # bsd/linux 'getw', 'putw', @@ -1065,9 +1163,11 @@ BEGIN our @HEADERS = (); our @EXTHEADERS = (); our %DECLS = (); +our %DECLSVALUE = (); our %TYPES = (); our %SIZES = (); our %FUNCTIONS = (); +our %LIBRARIES = (); my @INCLUDES = (); my @LIBS = (); @@ -1079,12 +1179,14 @@ BEGIN my $x_compiler = ''; my $x_version = ''; my @x_include = (); +my @x_sysinclude = (); my $x_command = ''; my $x_signature = undef; my $o_makelib = './makelib.in'; my $o_keep = 0; my $o_verbose = 0; +my $o_summary = 1; my $o_version = undef; my $o_gnuwin32 = 'auto'; my $o_contrib = 1; @@ -1105,13 +1207,13 @@ BEGIN sub LoadContrib($$$$$); sub CheckCompiler($$); sub CheckHeader($$); -sub CheckDecl($$); +sub CheckDecl($$$); sub CheckType($$); sub CheckSize($$); -sub CheckFunction($$); +sub CheckFunction($$;$); sub CheckICUFunction($); -sub CheckCommand($$;$); -sub CheckExec($$;$); +sub CheckCommand($$;$$); +sub CheckExec($$;$$); sub ExpandENV($); sub System($); sub systemrcode($); @@ -1187,6 +1289,9 @@ BEGIN elsif ('vc1930' eq $cmd) { $o_version = 1930; $cmd = 'vc' } elsif ('vc2022' eq $cmd) { $o_version = 1930; $cmd = 'vc' } elsif ('owc19' eq $cmd) { $o_version = 1900; $cmd = 'owc' } elsif ('owc20' eq $cmd) { $o_version = 2000; $cmd = 'owc' } + elsif ('mingw' eq $cmd) { $o_version = 0; $cmd = 'mingw' } + elsif ('mingw32' eq $cmd) { $o_version = 32; $cmd = 'mingw' } + elsif ('mingw64' eq $cmd) { $o_version = 64; $cmd = 'mingw' } if (! $o_version) { # default versions if ($cmd eq 'vc') { $o_version = 1400; } # review??? @@ -1210,7 +1315,6 @@ BEGIN #build Configure($cmd, $o_version); - foreach (@{$config->{MAKEFILES}}) { Makefile($cmd, $_, 'Makefile'); } @@ -1227,9 +1331,11 @@ BEGIN print CACHE Data::Dumper->Dump([\@EXTHEADERS], [qw(*XXEXTHEADERS)]); print CACHE Data::Dumper->Dump([\%CONFIG_H], [qw(*CONFIG_H)]); print CACHE Data::Dumper->Dump([\%DECLS], [qw(*DECLS)]); + print CACHE Data::Dumper->Dump([\%DECLSVALUE], [qw(*DECLSVALUE)]); print CACHE Data::Dumper->Dump([\%TYPES], [qw(*TYPES)]); print CACHE Data::Dumper->Dump([\%SIZES], [qw(*SIZES)]); print CACHE Data::Dumper->Dump([\%FUNCTIONS], [qw(*FUNCTIONS)]); + print CACHE Data::Dumper->Dump([\%LIBRARIES], [qw(*LIBRARIES)]); print CACHE "1;\n"; close CACHE; @@ -1420,8 +1526,6 @@ BEGIN } # makelib configuration - $x_tokens{"INCLUDE"} = $ENV{"INCLUDE"}; - foreach my $entry (keys %$env) { # target profile $x_tokens{$entry} = $$env{$entry}; } @@ -1479,8 +1583,9 @@ BEGIN # header my @INCLUDE = (); - push @INCLUDE, split(/;/, $x_tokens{INCLUDE}); push @INCLUDE, @x_include; # additional search directories + push @INCLUDE, split(/;/, $x_tokens{INCLUDE}); # environment INCLUDE + push @INCLUDE, @x_sysinclude; # toolchain etc print "Scanning: @INCLUDE\n" if ($o_verbose); @@ -1534,32 +1639,54 @@ BEGIN } } - # decls - foreach my $declspec (@x_decls) { - my $name = $declspec; - my $define = uc($declspec); - $define =~ s/ /_/g; - if ($declspec =~ /^(.+):(.+)$/) { - $name = $1; - $define = $2; # optional explicit #define + # predefines/decls + foreach my $t_declspec (@x_predefines, @x_decls) { + my $cpp = 0; + + if ($t_declspec =~ /^cpp=(.+)$/) { # cpp prefix + $t_declspec = $1; + $cpp = 1; } - my $cached = (exists $DECLS{$name}); - my $status = ($cached ? $DECLS{$name} : -1); + my @predefines = split('\|', $t_declspec); + foreach my $declspec (@predefines) { + my $name = $declspec; + my $define = uc($declspec); - print "decl: ${name} ..."; - print " " x (28 - length($name)); + $define =~ s/ /_/g; + if ($declspec =~ /^(.+):(.+)$/) { + $name = $1; + $define = $2; # optional explicit #define + } - if (1 == $status || - (-1 == $status && 0 == CheckDecl($type, $name))) { - $DECLS{$name} = 1; - $CONFIG_H{"HAVE_DECL_${define}"} = 1; - print ($cached ? "[yes, cached]" : "[yes]"); - } else { - $DECLS{$name} = 0; - print ($cached ? "[no, cached]" : "[no]"); + my $cached = (exists $DECLS{$name}); + my $status = ($cached ? $DECLS{$name} : -1); + my $value = ($cached ? $DECLSVALUE{$name} : ""); + + print "decl: ${name} ..."; + print " " x (28 - length($name)); + + if (-1 == $status) { + $value = CheckDecl($type, $name, $cpp); + $status = 1 + if ($value ne ""); + } + + if (1 == $status) { + $DECLS{$name} = 1; + $CONFIG_H{"HAVE_DECL_${define}"} = 1; + if ($cached) { + print "${define}=${value} [yes, cached]"; + } else { + $DECLSVALUE{$name} = $value; + print "[yes]"; + } + } else { + $DECLS{$name} = 0; + print ($cached ? "[no, cached]" : "[no]"); + } + print "\n"; } - print "\n"; } # types @@ -1631,8 +1758,35 @@ BEGIN print "\n"; } + # libraries + if (exists $config->{TESTLIBRARIES}) { + foreach my $lib (@{$config->{TESTLIBRARIES}}) { + my ($libname, @options) = split('\|', $lib); + my $cached = (exists $LIBRARIES{$libname}); + my $status = ($cached ? $LIBRARIES{$libname} : -1); + + print "library: ${libname} ..."; + print " " x (28 - length($libname)); + if (1 == $status || + (-1 == $status && 0 == CheckFunction($type, undef, $libname))) { + $LIBRARIES{$libname} = 1; + $libname = uc($libname); + $CONFIG_H{"HAVE_LIB${libname}"} = 1; + if (scalar @options >= 1) { #eg. LIBTHREAD=pthread + $x_tokens{$options[0]} = $libname; + } + print ($cached ? "[yes, cached]" : "[yes]"); + } else { + $LIBRARIES{$libname} = 0; + print ($cached ? "[no, cached]" : "[no]"); + } + print "\n"; + } + } + # compiler/environment - if ($type eq 'vc' || $type eq 'wc' || $type eq 'owc') { + # TODO: move to sub-module .... extension of TESTLIBRARIES + if ($type eq 'vc' || $type eq 'wc' || $type eq 'owc' || $type eq 'mingw') { my $gnuwin32lib = undef; my $gnuwin32inc = undef; @@ -2008,7 +2162,7 @@ BEGIN { my ($type, $env) = @_; - if ($$env{COMPILERPATH} eq '') { + if (!defined $$env{COMPILERPATH} || $$env{COMPILERPATH} eq '') { if (exists $$env{COMPILERPATHS}) { my @PATHS = split(/\|/, $$env{COMPILERPATHS}); foreach (@PATHS) { @@ -2062,6 +2216,42 @@ BEGIN } } + if ($x_compiler eq 'gcc') { + # #include <...> search starts here: + # c:\mingw\bin\../lib/gcc/mingw32/9.2.0/include + # c:\mingw\bin\../lib/gcc/mingw32/9.2.0/../../../../include + # c:\mingw\bin\../lib/gcc/mingw32/9.2.0/include-fixed + # End of search list. + (-1 != System("gcc -E -Wp,-v - ${x_tmpdir}/gcc.out 2>&1")) or + die "makelib: unable to access compiler \n"; + + open(GCC, "${x_tmpdir}/gcc.out") or + die "makelib: cannot open <${x_tmpdir}/gcc.out> : $!"; + my $line; + while (defined($line = )) { + if ($line =~ /^#include )) { + last if ($line =~ /^End of/i); + $line =~ s/^\s+|\s+$//g; + my $path = realpath($line); + print "gccinc: <$path>\n"; + push @x_sysinclude, $path + if ($path); + } + last; + } + } + + if (exists $ENV{"C_INCLUDE_PATH"}) { + $x_tokens{INCLUDE} = $ENV{"C_INCLUDE_PATH"}; + } elsif (exists $ENV{"CPATH"}) { + $x_tokens{INCLUDE} = $ENV{"CPATH"}; + } + + } else { + $x_tokens{INCLUDE} = $ENV{"INCLUDE"}; + } + my $INCLUDES = ''; $INCLUDES .= # , required?? (exists $$env{ISWITCH} ? $$env{ISWITCH} : '-I')."${CWD}/include "; @@ -2087,6 +2277,8 @@ BEGIN print "Compiler: ${x_compiler}\n"; print "Version: ${x_version}\n"; print "Command: ${x_command}\n"; + print "Includes: @{x_include}\n"; + print "SysInc: @{x_sysinclude}\n"; # build final command $x_command .= "__FLAGS__ "; @@ -2107,15 +2299,15 @@ BEGIN # Determine whether of the stated 'devl' exists. # sub -CheckDecl($$) # (type, name) +CheckDecl($$$) # (type, name, cpp) { - my ($type, $name) = @_; + my ($type, $name, $cpp) = @_; my $t_name = $name; $t_name =~ s/ /_/g; my $BASE = "${type}_${t_name}"; - my $SOURCE = "${BASE}.c"; + my $SOURCE = ($cpp ? "${BASE}.cpp" : "${BASE}.c"); my ($cmd, $cmdparts) = CheckCommand($BASE, $SOURCE); my $config = CheckConfig(); @@ -2140,13 +2332,18 @@ BEGIN #define __STRIZE(__x) #__x #define STRIZE(__x) __STRIZE(__x) const int ret = strlen(STRIZE($name)); + FILE *out = fopen("${BASE}.value", "w+"); + fprintf(out, "%s", STRIZE($name)); printf("${name}=%s : ", STRIZE($name)); return ret ? 0 : 1; } EOT close TMP; - return CheckExec($BASE, $cmd, 1); + my $result = "${BASE}.value"; + return $result + if (0 == CheckExec($BASE, $cmd, 1, \$result)); + return ""; } @@ -2283,19 +2480,19 @@ BEGIN # Function: CheckFunction -# Check that the function exists +# Check that the function and/or library exists. # Returns: # 0 on success, otherwise non-zero. # sub -CheckFunction($$) # (type, name) +CheckFunction($$;$) # (type, name, [libname]) { - my ($type, $name) = @_; + my ($type, $name, $libname) = @_; - my $BASE = "${type}_${name}"; + my $BASE = ($name ? "${type}_${name}" : "${type}_lib${libname}"); my $SOURCE = "${BASE}.c"; my ($cmd, $cmdparts) - = CheckCommand($BASE, $SOURCE); + = CheckCommand($BASE, $SOURCE, undef, $libname); my $config = CheckConfig(); my $tmpsource = "${x_tmpdir}/$SOURCE"; @@ -2316,10 +2513,22 @@ BEGIN $headers .= "#include <$header>\n"; } + ############################################################################## + # library check only + # + if (!defined $name) { + print TMP<; + close $file; + } else { + $$refRead = ""; + } + } + if (! $o_keep) { opendir(DIR, '.') or die "error opening dir <${x_tmpdir}> : $!\n"; @@ -2829,6 +3055,8 @@ BEGIN } else { if ($type eq 'vc' || $type eq 'wc') { if (! /LIBTOOL/) { # not LIBTOOL command lines + + # option conversion s/(\$\(CFLAGS\).*) -o \$\@/$1 -Fo\$@ -Fd\$(\@D)\//; s/(\$\(CXXFLAGS\).*) -o \$\@/$1 -Fo\$@ -Fd\$(\@D)\//; @@ -2846,6 +3074,8 @@ BEGIN } elsif ($type eq 'owc') { if (! /LIBTOOL/) { # not LIBTOOL command lines + + # option and directory slash conversion if ('-o' ne $x_tokens{OSWITCH}) { s/(\$\(CFLAGS\).*) -o \$\@/$1 -Fo=\$(subst \/,\\,\$@)/; s/(\$\(CXXFLAGS\).*) -o \$\@/$1 -Fo=\$(subst \/,\\,\$@)/; @@ -2865,6 +3095,18 @@ BEGIN # -Wl, } + if ('-i=' eq $x_tokens{ISWITCH}) { + # s/-I([^\s]+)/-i="$1"/g; + # s/-I ([^\s]+)/-i="$1"/g; + # gnuwin32 (gmake 3.x) quotes would be retained; + # this can not be guaranteed under an alt instance, for example gmake (4.x). + s/-I([^\s]+)/-i=\$(subst \/,\\,$1)/g; + s/-I ([^\s]+)/-i=\$(subst \/,\\,$1)/g; + } + + s/\$ -__CIDENT_RCSID(grtags_c,"$Id: grtags.c,v 1.6 2014/12/15 19:38:59 ayoung Exp $") +__CIDENT_RCSID(grtags_c,"$Id: grtags.c,v 1.7 2022/05/27 03:33:16 cvsuser Exp $") /* -*- mode: c; indent-width: 4; -*- */ -/* $Id: grtags.c,v 1.6 2014/12/15 19:38:59 ayoung Exp $ +/* $Id: grtags.c,v 1.7 2022/05/27 03:33:16 cvsuser Exp $ * tags command line util. * * @@ -165,21 +165,21 @@ tag_find(const char *const name) exit(1); } else { - int options = 0; + int opts = 0; if (o_sort >= 0) { extagsSetSortType(file, o_sort); } if (o_partial) { - options |= TAG_FPARTIALMATCH; + opts |= TAG_FPARTIALMATCH; } if (o_icase) { - options |= TAG_FIGNORECASE; + opts |= TAG_FIGNORECASE; } - if (extagsFind(file, &entry, name, options) == TagSuccess) { + if (extagsFind(file, &entry, name, opts) == TagSuccess) { do { exprint(&entry); } while (extagsFindNext(file, &entry) == TagSuccess); diff --git a/util/mklicense.pl b/util/mklicense.pl new file mode 100644 index 00000000..c1dcbc64 --- /dev/null +++ b/util/mklicense.pl @@ -0,0 +1,74 @@ +#!/usr/bin/perl -w +# -*- mode: perl; -*- +# $Id: mklicense.pl,v 1.1 2022/05/31 15:23:10 cvsuser Exp $ +# +# Copyright (c) 2020 - 2022, Adam Young. +# All rights reserved. +# +# The applications are free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, version 3. +# +# Redistributions of source code must retain the above copyright +# notice, and must be distributed with the license document above. +# +# Redistributions in binary form must reproduce the above copyright +# notice, and must include the license document above in +# the documentation and/or other materials provided with the +# distribution. +# +# The applications are 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# ==end== +# + +use strict; +use warnings 'all'; + +my $in = shift @ARGV; +my $out = shift @ARGV; +my $lbl = 'license'; + +$lbl = shift @ARGV + if (scalar @ARGV); + +die "usage: mklicense [label=license]\n\n" + if (!$in or !$out); + +open (INPUT, $in) or + die "can't open <${in}>: $!"; + +open (OUTPUT, '>', $out) or + die "can't create <${out}>: $!"; + +print OUTPUT + "/* File created from ${in} via mklicense.pl */\n". + "const char *${lbl}[] = {\n"; + +my $lines = 0; +while () { + chomp; + print OUTPUT ",\n" + if ($lines++); + s/\"/\\\"/g; + print OUTPUT "\t\"$_\""; + last if (/END OF TERMS AND CONDITIONS/); + } + +print OUTPUT + "\n};\n". + "/*end*/\n"; + +close(INPUT) or + die "can't close <${in}>: $!"; + +close(OUTPUT) or + die "can't close <${out}>: $!"; + +#end + diff --git a/util/w32keytest.c b/util/w32keytest.c index 22cc8c4a..422de5c2 100644 --- a/util/w32keytest.c +++ b/util/w32keytest.c @@ -2,7 +2,6 @@ * win32 console key-test */ -#define _WIN32_WINNT 0x0601 #include #include #include @@ -11,12 +10,16 @@ #define CTRL_PRESSED (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED) #define APP_PRESSED 0x0200 /* APPS enabled, extension */ -#if defined(__WATCOMC__) +#if defined(__WATCOMC__) || defined(__MINGW32__) #if !defined(_countof) -#define _countof(array) (sizeof(array) / sizeof(array[0])) +#define _countof(array) (sizeof(array) / (unsigned)sizeof(array[0])) #endif #endif +#if defined(__MINGW32__) +#define swprintf _swprintf +#endif + #define CTRLSTATUSMASK (LEFT_ALT_PRESSED|LEFT_CTRL_PRESSED|RIGHT_ALT_PRESSED|RIGHT_CTRL_PRESSED|SHIFT_PRESSED|APP_PRESSED) static const struct w32key { @@ -61,7 +64,9 @@ static const struct w32key { { VK_DELETE, VKMOD_ANY, L"Delete" }, { VK_HELP, VKMOD_ANY, L"Help" }, +#if defined(VK_ICO_HELP) { VK_ICO_HELP, VKMOD_ANY, L"Help" }, +#endif { VK_PRIOR, VKMOD_NOTENHANCED, L"Keypad-PgUp" }, { VK_NEXT, VKMOD_NOTENHANCED, L"Keypad-PgDn" }, @@ -629,13 +634,17 @@ virtual_description(WORD wVirtualKeyCode) case VK_NUMLOCK : /*0x90*/ return L"NUMLOCK"; case VK_SCROLL : /*0x91*/ return L"SCROLL"; +#if defined(VK_OEM_NEC_EQUAL) case VK_OEM_NEC_EQUAL : /*0x92*/ return L"OEM_NEC_EQUAL"; +#endif +#if defined(VK_OEM_FJ_MASSHOU) // case VK_OEM_FJ_JISHO : /*0x92*/ return L"OEM_FJ_JISHO"; case VK_OEM_FJ_MASSHOU : /*0x93*/ return L"OEM_FJ_MASSHOU"; case VK_OEM_FJ_TOUROKU : /*0x94*/ return L"OEM_FJ_TOUROKU"; case VK_OEM_FJ_LOYA : /*0x95*/ return L"OEM_FJ_LOYA"; case VK_OEM_FJ_ROYA : /*0x96*/ return L"OEM_FJ_ROYA"; +#endif case VK_LSHIFT : /*0xA0*/ return L"LSHIFT"; case VK_RSHIFT : /*0xA1*/ return L"RSHIFT"; @@ -664,6 +673,7 @@ virtual_description(WORD wVirtualKeyCode) case VK_LAUNCH_APP1 : /*0xB6*/ return L"LAUNCH_APP1"; case VK_LAUNCH_APP2 : /*0xB7*/ return L"LAUNCH_APP2"; +#if defined(VK_OEM_1) case VK_OEM_1 : /*0xBA*/ return L"OEM_1"; case VK_OEM_PLUS : /*0xBB*/ return L"OEM_PLUS"; case VK_OEM_COMMA : /*0xBC*/ return L"OEM_COMMA"; @@ -671,24 +681,32 @@ virtual_description(WORD wVirtualKeyCode) case VK_OEM_PERIOD : /*0xBE*/ return L"OEM_PERIOD"; case VK_OEM_2 : /*0xBF*/ return L"OEM_2"; case VK_OEM_3 : /*0xC0*/ return L"OEM_3"; +#endif +#if defined(VK_OEM_4) case VK_OEM_4 : /*0xDB*/ return L"OEM_4"; case VK_OEM_5 : /*0xDC*/ return L"OEM_5"; case VK_OEM_6 : /*0xDD*/ return L"OEM_6"; case VK_OEM_7 : /*0xDE*/ return L"OEM_7"; case VK_OEM_8 : /*0xDF*/ return L"OEM_8"; +#endif +#if defined(VK_OEM_AX) case VK_OEM_AX : /*0xE1*/ return L"OEM_AX"; case VK_OEM_102 : /*0xE2*/ return L"OEM_102"; case VK_ICO_HELP : /*0xE3*/ return L"ICO_HELP"; case VK_ICO_00 : /*0xE4*/ return L"ICO_00"; +#endif case VK_PROCESSKEY : /*0xE5*/ return L"PROCESSKEY"; +#if defined(VK_ICO_CLEAR) case VK_ICO_CLEAR : /*0xE6*/ return L"ICO_CLEAR"; +#endif case VK_PACKET : /*0xE7*/ return L"PACKET"; +#if defined(VK_OEM_RESET) case VK_OEM_RESET : /*0xE9*/ return L"OEM_RESET"; case VK_OEM_JUMP : /*0xEA*/ return L"OEM_JUMP"; case VK_OEM_PA1 : /*0xEB*/ return L"OEM_PA1"; @@ -702,7 +720,8 @@ virtual_description(WORD wVirtualKeyCode) case VK_OEM_AUTO : /*0xF3*/ return L"OEM_AUTO"; case VK_OEM_ENLW : /*0xF4*/ return L"OEM_ENLW"; case VK_OEM_BACKTAB : /*0xF5*/ return L"OEM_BACKTAB"; - +#endif + case VK_ATTN : /*0xF6*/ return L"ATTN"; case VK_CRSEL : /*0xF7*/ return L"CRSEL"; case VK_EXSEL : /*0xF8*/ return L"EXSEL"; diff --git a/win32/.gitignore b/win32/.gitignore index 4fa37469..ef4382fc 100644 --- a/win32/.gitignore +++ b/win32/.gitignore @@ -1,2 +1,4 @@ -grief.manifest +grief.manifest* +*.bat + diff --git a/win32/AutoUpdater/Makefile.in b/win32/AutoUpdater/Makefile.in index b7a6aaab..79ceab20 100644 --- a/win32/AutoUpdater/Makefile.in +++ b/win32/AutoUpdater/Makefile.in @@ -1,5 +1,5 @@ # -*- mode: mak; indent-tabs-mode: t; tab-width: 8 -*- -# $Id: Makefile.in,v 1.16 2021/10/19 15:50:56 cvsuser Exp $ +# $Id: Makefile.in,v 1.17 2022/03/24 08:52:21 cvsuser Exp $ # libautoupdater and utils makefile # # @@ -115,7 +115,7 @@ DLLOBJS=\ $(D_OBJ)/AutoConfig.lo \ $(D_OBJ)/AutoConsole.lo \ $(D_OBJ)/AutoDialog.lo \ - $(D_OBJ)/AutoDownload.lo \ + $(D_OBJ)/AutoDownLoad.lo \ $(D_OBJ)/AutoError.lo \ $(D_OBJ)/AutoLogger.lo \ $(D_OBJ)/AutoManifest.lo \ diff --git a/win32/AutoUpdater/grupdater.rc b/win32/AutoUpdater/grupdater.rc index 43106e03..bb4f01c7 100644 --- a/win32/AutoUpdater/grupdater.rc +++ b/win32/AutoUpdater/grupdater.rc @@ -70,7 +70,7 @@ VS_VERSION_INFO VERSIONINFO #endif VALUE "InternalName", "GRIEF" VALUE "Copyright", - "Copyright (C) 2012 - 2021, Adam Young. All rights reserved. " + "Copyright (C) 2012 - 2022, Adam Young. All rights reserved. " "Licensed under the Grief License. " "This is free software; see the source for copying conditions. " "There is NO warranty; not even for MERCHANTABILITY " diff --git a/win32/AutoUpdater/sign/upgetopt.cpp b/win32/AutoUpdater/sign/upgetopt.cpp index a2eb91c3..97ed75e3 100644 --- a/win32/AutoUpdater/sign/upgetopt.cpp +++ b/win32/AutoUpdater/sign/upgetopt.cpp @@ -1,4 +1,4 @@ -// $Id: upgetopt.cpp,v 1.2 2021/08/12 14:48:38 cvsuser Exp $ +// $Id: upgetopt.cpp,v 1.4 2022/06/01 14:21:19 cvsuser Exp $ // // getopt() implementation // diff --git a/win32/gr-inno-setup.iss b/win32/gr-inno-setup.iss index 349ac6a1..185bfa5c 100644 --- a/win32/gr-inno-setup.iss +++ b/win32/gr-inno-setup.iss @@ -90,6 +90,7 @@ Source: "..\{#BinDir}\grcpp.exe"; DestDir: "{app}\bin"; Flags: ignoreversion Source: "..\{#BinDir}\grunch.exe"; DestDir: "{app}\bin"; Flags: ignoreversion Source: "..\{#BinDir}\grmandoc.exe"; DestDir: "{app}\bin"; Flags: ignoreversion Source: "..\{#BinDir}\grwc.exe"; DestDir: "{app}\bin"; Flags: ignoreversion +Source: "..\{#BinDir}\grupdater.exe"; DestDir: "{app}\bin"; Flags: ignoreversion Source: "..\{#BinDir}\*.dll"; DestDir: "{app}\bin"; Flags: ignoreversion Source: "..\{#BinDir}\ctbl\*"; DestDir: "{app}\bin\ctbl"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "..\{#BinDir}\i18n\*"; DestDir: "{app}\bin\i81n"; Flags: ignoreversion recursesubdirs createallsubdirs diff --git a/win32/libappupdater b/win32/libappupdater index a9dd5314..cedfde21 160000 --- a/win32/libappupdater +++ b/win32/libappupdater @@ -1 +1 @@ -Subproject commit a9dd531499cc87046347d9710574b459e5d541f3 +Subproject commit cedfde216b7a69b5431154f3df30ccc6afb301ed diff --git a/win32/libtool_win32.pl b/win32/libtool_win32.pl index 237aef5b..d56ecd13 100644 --- a/win32/libtool_win32.pl +++ b/win32/libtool_win32.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -*- mode: perl; -*- -# $Id: libtool_win32.pl,v 1.36 2022/03/21 14:31:25 cvsuser Exp $ +# $Id: libtool_win32.pl,v 1.42 2022/06/11 04:02:17 cvsuser Exp $ # libtool emulation for WIN32 builds. # # **Warning** @@ -21,7 +21,27 @@ # Copyright Adam Young 2012-2022 # All rights reserved. # -# This file is part of the GRIEF Editor. +# The applications are free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# Redistributions of source code must retain the above copyright +# notice, and must be distributed with the license document above. +# +# Redistributions in binary form must reproduce the above copyright +# notice, and must include the license document above in +# the documentation and/or other materials provided with the +# distribution. +# +# The applications are 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# ==end== # use strict; @@ -51,7 +71,7 @@ sub Compile(); sub Link(); sub true_object($); -sub true_library($); +sub true_library($;$); sub unix2dos($); sub dos2unix($); sub Help; @@ -146,7 +166,8 @@ # Compile a library object. # sub -Compile() { +Compile() +{ my $cc = shift @ARGV; my $object; my $source; @@ -191,7 +212,7 @@ push @INCLUDES, shift @ARGV; } elsif (/^-d(.*)$/) { # -d - if ('wcl386' eq $cc && (/^-d[1-3][ist]$/ || /^-db$/)) { + if ('wcl386' eq $cc && (/^-d[0-9]/ || /^-db$/)) { push @STUFF, $_; } else { push @DEFINES, ($1 ? $1 : shift @ARGV); @@ -239,7 +260,7 @@ $source = shift @ARGV; Error("compile: unsupported compiler <$cc>") - if (!('cl' eq $cc || 'wcl386' eq $cc || 'owcc' eq $cc || 'gcc' eq $cc)); + if (!('cl' eq $cc || 'wcl386' eq $cc || 'owcc' eq $cc || 'gcc' eq $cc || 'g++' eq $cc)); Error("compile: unable to determine object") if (!$object); Error("compile: object file suffix not <.lo>") @@ -253,6 +274,7 @@ my $true_object = ${true_path}.basename($object, 'lo')."obj"; Verbose "cc: ${cc}"; + Verbose "extra: @STUFF"; Verbose "defines:"; foreach(@DEFINES) { Verbose "\t$_"; } Verbose "includes:"; @@ -260,7 +282,6 @@ Verbose "object: ${object}"; Verbose " true: ${true_object}"; Verbose "source: ${source}"; - Verbose "...: @STUFF"; my $cmd = ''; @@ -278,18 +299,18 @@ $cmd .= " -bd"; # DLL builds foreach (@DEFINES) { $cmd .= " -d$_"; } foreach (@INCLUDES) { $cmd .= " -I=\"$_\""; } - $cmd .= " -Fo=\"$true_object\""; - $cmd .= " -c $source"; + $cmd .= " -Fo=\"".unix2dos($true_object)."\""; + $cmd .= " -c ".unix2dos($source); } elsif ('owcc' eq $cc) { # OpenWatcom, posix driver. $cmd = "$cc @STUFF -DDLL=1"; $cmd .= " -shared"; # DLL builds foreach (@DEFINES) { $cmd .= " -D$_"; } foreach (@INCLUDES) { $cmd .= " -I \"$_\""; } - $cmd .= " -o \"$true_object\""; - $cmd .= " -c $source"; + $cmd .= " -o \"".unix2dos($true_object)."\""; + $cmd .= " -c ".unix2dos($source); - } elsif ('gcc' eq $cc) { + } elsif ('gcc' eq $cc || 'g++' eq $cc) { $cmd = "$cc @STUFF -D DLL=1 -shared"; foreach (@DEFINES) { $cmd .= " -D $_"; } foreach (@INCLUDES) { $cmd .= " -I \"$_\""; } @@ -306,8 +327,8 @@ if (0 != ($ret = System($cmd))); # generate lo artifact - open(LO, ">${object}") or - die "cannot create <$object> : $!\n"; + open(LO, ">", $object) or + die "cannot create <".$object."> : $!\n"; print LO "#libtool win32 generated, do not modify\n"; print LO "mode=dll\n"; print LO "cc=$cc\n"; @@ -324,7 +345,8 @@ # Link a library object. # sub -Link() { +Link() +{ my $cc = shift @ARGV; my ($output, $dlbase, $rpath, $bindir, $module, $mapfile); @@ -334,6 +356,7 @@ my $linktype = 'dll'; my $cl_ltcg = 0; my $cl_debug = undef; + my $gcc_debugger = 0; my @OBJECTS; my @RESOURCES; my @EXPORTS; @@ -342,6 +365,7 @@ my @LIBPATHS; my @STUFF; + $cc = 'gcc' if ('g++' eq $cc); # alises while (scalar @ARGV) { $_ = shift @ARGV; @@ -400,11 +424,26 @@ } elsif (/^(.*)\.rc$/) { Error("link: $_ not supported\n"); - } elsif (/^(.*)\.la$/ || /^(.*)\.a$/ || /^(.*)\.lib$/i) { + } elsif (/^(.*)\.a$/ || /^(.*)\.lib$/i) { + my $libname = $_; + $libname =~ s/^lib// # libxxxx[.a] => xxxx[.a] + if ('gcc' eq $cc); + push @LIBRARIES, $libname; + + } elsif (/^(.*)\.la$/) { push @LIBRARIES, $_; } elsif (/^-l(.*)$/) { - push @LIBRARIES, $1; + my $libname = $1; + if ('gcc' ne $cc) { + if ($libname !~ /^lib/) { # xxxx => libxxxx.lib + if ($libname !~ /\.lib$/) { + $libname = "lib${libname}.lib"; + #XXX: maybe need to resolve + } + } + } + push @LIBRARIES, $libname; } elsif (/^[-\/]LIBPATH[:]?\s*(.+)/) { # -LIBPATH[:] push @LIBPATHS, $1; @@ -534,7 +573,16 @@ Error("link: $_ not supported\n"); } elsif (/^-Xlinker(.*)$/) { - Error("link: $_ not supported\n"); + my $opt = ($1 ? $1 : shift @ARGV); + + if ($opt =~ /^-Map=(.+)$/) { + my $val = $1; + Error("link: multiple mapfile specified <$mapfile> and <$val>") + if ($mapfile); + $mapfile = $val; + } else { + Error("link: -Xlinker ${opt} opt supported\n"); + } } elsif (/^-XCClinker(.*)$/) { Error("link: $_ not supported\n"); @@ -553,9 +601,15 @@ next; # Debugger + } elsif (/^[-\/]Z([7iI])$/) { # /Z7, /Zi /ZI, enable debug + $cl_debug = "/DEBUG" + if (!defined $cl_debug); + $cl_ltcg = 0; + } elsif (/^[-\/]DEBUG$/ || /^[-\/]DEBUG:(.+_)$/) { $cl_debug = $_; # explicit /DEBUG:NONE, /DEBUG:FULL and /DEBUG:FASTLINK $cl_debug =~ s/^-/\//; + $cl_ltcg = 0; next; } @@ -601,7 +655,7 @@ # Debugger support: # -h[wcd] Watcom,Codeview,Dwarf # - } elsif (/^-h([wc])$/) { + } elsif (/^-h([wcd])$/) { $wc_debugger = $1; } @@ -634,6 +688,11 @@ } elsif (/^-g([wcd])$/) { # -g[wcd] Watcom,Codeview,Dwarf $wc_debugger = $1; } + + } elsif ('gcc' eq $cc) { # process + if (/^-g$/) { # -g + $gcc_debugger = 1; + } } push @STUFF, $_; @@ -650,6 +709,7 @@ } Verbose "cc: $cc"; + Verbose "extra: @STUFF"; Verbose "output: $output"; Verbose "objects:"; foreach(@OBJECTS) { @@ -657,7 +717,6 @@ } Verbose "libraries:"; foreach(@LIBRARIES) { Verbose "\t$_"; } - Verbose "...: @STUFF"; my ($dll_version, $dll_major, $dll_minor) = ('', 0, 0); if ($version_number) { @@ -774,6 +833,9 @@ print CMD "/OUT:${output}\n"; } + print CMD "/MANIFEST\n"; + print CMD "/NXCOMPAT\n"; + print CMD "/DYNAMICBASE\n"; print CMD "/MAP:${mappath}\n"; print CMD "/MAPINFO:EXPORTS\n"; print CMD "/VERSION:${dll_version}\n" @@ -781,8 +843,11 @@ print CMD "/NOLOGO\n" if ($o_quiet || $o_silent); print CMD "/OPT:REF\n"; - print CMD (defined $cl_debug ? $cl_debug : "/DEBUG") . "\n"; - print CMD "/INCREMENTAL:NO\n"; # after /DEBUG + if (defined $cl_debug) { + print CMD ($cl_debug ? $cl_debug : "/DEBUG") . "\n"; + print CMD "/ASSEMBLYDEBUG\n"; + } + print CMD "/INCREMENTAL:NO\n"; # after /DEBUG print CMD "/LTCG\n" if ($cl_ltcg); foreach(@OBJECTS) { @@ -812,6 +877,7 @@ open(CMD, ">${cmdfile}") or die "cannot create <${$cmdfile}>: $!\n"; + if ($linktype eq 'dll') { print CMD "system nt_dll initinstance terminstance\n"; # @@ -874,7 +940,12 @@ print CMD "export ".WatcomExportDef($_, $wc_fastcall)."\n"; } foreach(@LIBPATHS) { - print CMD "libpath ".unix2dos($_)."\n"; + my $u2d = unix2dos($_); + if ($u2d =~ / /) { + print CMD "libpath '${u2d}'\n"; + } else { + print CMD "libpath ${u2d}\n"; + } } foreach(@LIBRARIES) { print CMD "library ".unix2dos(true_library($_))."\n"; @@ -894,21 +965,36 @@ open(CMD, ">${cmdfile}") or die "cannot create <${cmdfile}>: $!\n"; - print CMD "-o ".dos2unix($dllpath)."\n"; - print CMD "-shared\n"; + if ($linktype eq 'dll') { + print CMD "-o ".dos2unix($dllpath)."\n"; + print CMD "-shared\n"; + print CMD "-Wl,--subsystem,windows\n"; + print CMD "-Wl,--out-implib,".dos2unix("${basepath}.a")."\n"; + } else { + print CMD "-o ".dos2unix($output)."\n"; + print CMD "-Wl,--subsystem,console\n"; + } + print CMD "-g\n" + if ($gcc_debugger); + foreach(@OBJECTS) { print CMD dos2unix(true_object($_))."\n"; } print "warning: resources ignored @RESOURCES\n" if (scalar @RESOURCES); - print CMD "-Wl,--subsystem,windows\n"; - print CMD "-Wl,--out-implib,".dos2unix("${basepath}.a")."\n"; print CMD "-Xlinker -Map=".dos2unix($mappath)."\n"; foreach(@LIBPATHS) { print CMD "-L ".dos2unix($_)."\n"; } foreach(@LIBRARIES) { - print CMD "-l".dos2unix($_)."\n"; + my $d2u = dos2unix(true_library($_, 1)); + if ($d2u =~ /\//) { # path ? + print CMD "${d2u}\n"; + } else { + $d2u =~ s/\.lib$//; # xxxx.lib => xxxx + $d2u =~ s/\.a$//; # xxxx.a => xxxx + print CMD "-l${d2u}\n"; + } } if (scalar @EXPORTS) { @@ -974,7 +1060,7 @@ close(LA); } - if ('gcc' eq $cc) { + if ('gcc' eq $cc && "${basepath}.a" ne $libpath) { copy("${basepath}.a", $libpath) or die "link: unable to copy <${basepath}.a> to <${libpath}> : $!\n"; } @@ -993,12 +1079,13 @@ sub -OpenCommandFile($) { +OpenCommandFile($) +{ my ($file) = @_; my @NARGV; - open(CMD, "<${file}") or - die "cannot open command line <$file> : $!\n"; + open(CMD, "<", $file) or + die "cannot open command line <".$file."> : $!\n"; while () { s/\s*([\n\r]+|$)//; s/^\s+//; @@ -1032,12 +1119,13 @@ # STUB:filename # sub -ParseDefFile($$$) { +ParseDefFile($$$) +{ my ($file, $EXPORTSRef, $DESCRIPTIONRef) = @_; my $mode = 0; - open(DEF, "<${file}") or - die "cannot open <$file> : $!\n"; + open(DEF, "<", $file) or + die "cannot open <".$file."> : $!\n"; while () { s/\s*([\n\r]+|$)//; s/^\s+//; @@ -1095,7 +1183,8 @@ # --> /EXPORT:entryname[,@ordinal][,NONAME][,DATA] # sub -MSVCExportDef($) { +MSVCExportDef($) +{ my ($def) = @_; my @parts = split(/ /, $def); my $name = $parts[0]; @@ -1125,7 +1214,8 @@ # --> entryname[.ordinal]=internalname [PRIVATE] # sub -WatcomExportDef($$) { +WatcomExportDef($$) +{ my ($def, $fastcall) = @_; my @parts = split(/ /, $def); my $name = $parts[0]; @@ -1138,7 +1228,7 @@ } if ((scalar @parts >= 2 && $parts[1] eq 'DATA') || - (scalar @parts >= 3 && $parts[2] eq 'DATA')) { + (scalar @parts >= 3 && $parts[2] eq 'DATA')) { Warning("link: export ($def), Ordinal ignored on DATA element\n") if ($ordinal); if ($name =~ /^(.+)=(.+)$/) { @@ -1160,7 +1250,7 @@ } if ((scalar @parts >= 2 && $parts[1] eq 'PRIVATE') || - (scalar @parts >= 3 && $parts[2] eq 'PRIVATE')) { + (scalar @parts >= 3 && $parts[2] eq 'PRIVATE')) { $ret .= " PRIVATE"; # otherwise RESIDENT } @@ -1170,12 +1260,13 @@ sub -ParseSymFile($$) { +ParseSymFile($$) +{ my ($file, $EXPORTSRef) = @_; my $mode = 0; - open(SYM, "<${file}") or - die "cannot open symbol file <$file> : $!\n"; + open(SYM, "<", $file) or + die "cannot open symbol file <".$file."> : $!\n"; while () { s/\s*([\n\r]+|$)//; s/^\s+//; @@ -1190,7 +1281,8 @@ # Cleanup library object. # sub -Clean() { +Clean() +{ my $rm = shift @ARGV; my @OBJECTS; @@ -1218,8 +1310,8 @@ foreach(@LIBRARIES) { my $lib = $_; if ($lib =~ /\.la$/ && -f $lib) { # library artifact - open(LA, "<${lib}") or - die "cannot open library artifact <${lib}> : $!\n"; + open(LA, "<", $lib) or + die "cannot open library artifact <".$lib."> : $!\n"; while () { s/\s*([\n\r]+|$)//; if (/^(lib|dll|map|sym|pdb|exp|manifest)=(.*)$/) { @@ -1267,8 +1359,8 @@ return $lo if ($lo !~ /.lo$/); - open(LO, "<${lo}") or - die "cannot open object image <$lo> : $!\n"; + open(LO, "<", $lo) or + die "cannot open object image <".$lo."> : $!\n"; while () { s/\s*([\n\r]+|$)//; next if (!$_ || /^\s#/); @@ -1287,15 +1379,15 @@ # Retrieve the true object name for the specified 'la' image. # sub -true_library($) #(la) +true_library($;$) #(la [,striplib]) { - my ($la) = @_; + my ($la,$striplib) = @_; my $true_library; return $la if ($la !~ /.la$/); - open(LA, "<${la}") or - die "cannot open library image <$la> : $!\n"; + open(LA, "<", $la) or + die "cannot open library image <".$la."> : $!\n"; while () { s/\s*([\n\r]+|$)//; next if (!$_ || /^\s#/); @@ -1306,6 +1398,8 @@ } close(LA); die "internal: la truename missing <$la>" if (!$true_library); + $true_library =~ s/^lib// # libxxxx.a => xxxx.a + if (defined $striplib && $striplib); return $true_library; } diff --git a/win32/wc.profile b/win32/wc.profile index 20d98d06..f94ebe7c 100644 --- a/win32/wc.profile +++ b/win32/wc.profile @@ -1,8 +1,8 @@ # -*- mode: sh; -*- -# $Id: wc.profile,v 1.5 2018/10/18 01:54:41 cvsuser Exp $ +# $Id: wc.profile,v 1.6 2022/06/02 12:42:28 cvsuser Exp $ # makedepend Open Watcom C/C++ profile # -__WATCOMC__=1300 +__WATCOMC__=1290 # __WATCOMC__ = 1290 /* 1.9 */ # __WATCOMC__ = 1300 /* 2.0 */ diff --git a/win32/wc20.profile b/win32/wc20.profile new file mode 100644 index 00000000..ff90b6de --- /dev/null +++ b/win32/wc20.profile @@ -0,0 +1,61 @@ +# -*- mode: sh; -*- +# $Id: wc20.profile,v 1.1 2022/06/02 12:42:28 cvsuser Exp $ +# makedepend Open Watcom C/C++ 2.0 profile +# +__WATCOMC__=1300 +# __WATCOMC__ = 1290 /* 1.9 */ +# __WATCOMC__ = 1300 /* 2.0 */ + +WIN32_LEAN_AND_MEAN=1 +WIN32=0x601 +_WIN32=0x601 +_M_IX86 +-Y@INCLUDE + +# aliases, example +# pragma include_alias(,) +# see windows SDK +# +-Ad3d9types.h =d3d9type.h +-Adevpropdef.h =devprdef.h +-Adriverspecs.h =drvspecs.h +-Aknownfolders.h =knownfld.h +-Aobjectarray.h =objarray.h +-Apropkeydef.h =propkdef.h +-Aschemadef.h =schemdef.h +-Asdkddkver.h =sdkddkve.h +-Aspecstrings.h =specstr.h +-Astructuredquery.h =strquery.h +-Astructuredquerycondition.h=strqcond.h +-Atcpestats.h =tcpestat.h +-Awlantypes.h =wlantype.h +-Awinsdkver.h =wsdkver.h +-Aexception =exceptio + +# C++ aliases +# see: _preincl.h +-Aalgorithm =algorith +-Acinttypes =cinttype +-Acondition_variable =conditio +-Aexception =exceptio +-Aexception.h =exceptio.h +-Aforward_list =forward_ +-Afunctional =function +-Ainitializer_list =initiali +-Asemaphore.h =semaphor.h +-Astdexcept =stdexcep +-Astdexcept.h =stdexcep.h +-Astreambuf =streambu +-Astreambuf.h =streambu.h +-Astrstream =strstrea +-Astrstream.h =strstrea.h +-Asystem_error =system_e +-Atypeindex =typeinde +-Atype_traits =type_tra +-Aunordered_map =unorderm +-Aunordered_set =unorders + +-Astdnoreturn.h =stdnoret.h + + +