├── README.md ├── archive ├── NMakefile-pcre2-10.40 ├── RunGrepTest-pcre2-10.40.bat ├── config-pcre2-10.40.h ├── grep-3.3-build-VS17-x64.patch ├── grep-3.3-build-VS17-x64.txt ├── grep-3.3-build-patch-howto.txt ├── grep-3.3-src.patch ├── grep-3.3-unistd.patch ├── grep-3.3-win-headers.patch ├── grep-3.3-x64.exe ├── grep-3.6-build-VS19-x64.patch ├── grep-3.6-build-VS19-x64.txt ├── grep-3.6-build-patch-howto.txt ├── grep-3.6-mbtowc-lock.patch ├── grep-3.6-src.patch ├── grep-3.6-unistd.patch ├── grep-3.6-win-headers.patch ├── grep-3.6-x64.exe ├── grep-3.7-build-VS22-x64.patch ├── grep-3.7-build-VS22-x64.txt ├── grep-3.7-build-VS9-x86.patch ├── grep-3.7-build-VS9-x86.txt ├── grep-3.7-build-patch-howto.txt ├── grep-3.7-src-non-c99.patch ├── grep-3.7-src.patch ├── grep-3.7-x64.exe ├── grep-3.7-x86.exe ├── grep-3.8-build-VS22-x64.patch ├── grep-3.8-build-VS22-x86.patch ├── grep-3.8-build-patch-howto.txt ├── grep-3.8-build.txt ├── grep-3.8-src.patch ├── grep-3.8-unistd.patch ├── grep-3.8-win-headers.patch ├── grep-3.8-x64.exe ├── grep-3.8-x86.exe ├── pcre2grep-10.40-x64.exe └── pcre2grep-10.40-x86.exe ├── egrep.bat ├── fgrep.bat ├── grep-3.11-build-VS22-x64.patch ├── grep-3.11-build-VS22-x86.patch ├── grep-3.11-build-patch-howto.txt ├── grep-3.11-build.txt ├── grep-3.11-src.patch ├── grep-3.11-unistd.patch ├── grep-3.11-utf16.patch ├── grep-3.11-x64.exe ├── grep-3.11-x86.exe ├── grep-3.8-mbtowc-lock.patch ├── pcre2 ├── NMakefile-pcre2-10.44 ├── RunGrepTest-pcre2-10.44.bat ├── RunTest-pcre2-10.44.bat ├── config-pcre2-10.44.h ├── pcre2-10.44-build.txt ├── pcre2-pcre2-10.44.patch └── testrepl.c ├── pcre2grep-10.44-x64.exe └── pcre2grep-10.44-x86.exe /README.md: -------------------------------------------------------------------------------- 1 | # grep-windows 2 | Instructions for building [Gnu Grep](https://www.gnu.org/software/grep) and [pcre2grep](https://github.com/PCRE2Project/pcre2) as native windows applications 3 | 4 | All patches under the same license as sources of [Gnu Grep](https://www.gnu.org/software/grep): [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) or later 5 | 6 | Author of the patches: Michael M. Builov (mbuilov@yandex.ru) 7 | 8 | ## Changes since windows build of Gnu grep-3.3 9 | - fixed support for colorizing output of grep in Windows console (enabled via '--color' option; tip: use "color" command to reset console colors) 10 | 11 | ## Changes since windows build of Gnu grep-3.7 12 | - now support for Perl regular expressions is statically complied in the grep executable 13 | 14 | ## Changes since windows build of Gnu grep-3.8 15 | - search in sub-directories (grep -r ...) is now working 16 | 17 | ## Changes since windows build of Gnu grep-3.11 18 | - added experimental support for inline UTF16->UTF8 transcoding 19 | - added support for wildcard expansion of grep arguments 20 | 21 | ## Pre-built executables: 22 | - [`grep-3.11-x64.exe`](/grep-3.11-x64.exe) - grep 3.11 built for Windows10 x64 23 | - [`grep-3.11-x86.exe`](/grep-3.11-x86.exe) - grep 3.11 built for WindowsXP x86 24 | - [`pcre2grep-10.44-x64.exe`](/pcre2grep-10.44-x64.exe) - pcre2grep 10.44 built for Windows10 x64 25 | - [`pcre2grep-10.44-x86.exe`](/pcre2grep-10.44-x86.exe) - pcre2grep 10.44 built for WindowsXP x86 26 | 27 | ## Instructions how to build pcre2grep 28 | - [`pcre2-10.44-build.txt`](/pcre2/pcre2-10.44-build.txt) 29 | 30 | ## Instructions how to create build patch 31 | - [`grep-3.11-build-patch-howto.txt`](/grep-3.11-build-patch-howto.txt) 32 | 33 | ## Instructions how to apply build patch to compile Gnu grep using native tools only 34 | - [`grep-3.11-build.txt`](/grep-3.11-build.txt) 35 | 36 | ## Prepared build patches 37 | For x64/Windows10/VS22: 38 | - [`grep-3.11-build-VS22-x64.patch`](/grep-3.11-build-VS22-x64.patch) 39 | 40 | For x86/WindowsXP/VS22: 41 | - [`grep-3.11-build-VS22-x86.patch`](/grep-3.11-build-VS22-x86.patch) 42 | -------------------------------------------------------------------------------- /archive/NMakefile-pcre2-10.40: -------------------------------------------------------------------------------- 1 | LIBPCRE2 = pcre2.a 2 | LIBPCRE2POSIX = pcre2posix.a 3 | PCRE2GREP = pcre2grep.exe 4 | 5 | CC = cl 6 | CFLAGS = /Wall /wd4820 /DNDEBUG /I. /Ox /GF /Gy /GS- /GL /EHsc /DHAVE_CONFIG_H /DPCRE2_CODE_UNIT_WIDTH=8 /nologo 7 | SUBSYSTEM = /SUBSYSTEM:CONSOLE 8 | 9 | !IF "$(PLATFORM)" == "x86" 10 | CFLAGS = $(CFLAGS) /D_WIN32_WINNT=0x501 11 | SUBSYSTEM = $(SUBSYSTEM),5.01 12 | !ELSE 13 | !IF "$(PLATFORM)" != "x64" 14 | !ERROR Unknown Platform: "$(PLATFORM)"! 15 | !ENDIF 16 | !ENDIF 17 | 18 | CCFLAGS = $(CFLAGS) /c /Fo 19 | 20 | AR = lib.exe /LTCG 21 | ARFLAGS = /out: 22 | 23 | TEST = pcre2test.exe 24 | TEST_FLAGS = 25 | TLINK = $(CFLAGS) $(TEST_FLAGS) /wd4996 /Fe$(TEST) /link /LTCG $(SUBSYSTEM) 26 | 27 | PCRE2_TEST_RUN = cmd /c RunTest.bat 28 | PCRE2GREP_TEST_RUN = cmd /c RunGrepTest.bat 29 | TEST_OK = echo.All OK 30 | 31 | PCRE2GREP_LINK = $(CFLAGS) /wd4996 /Fe$(PCRE2GREP) /link /LTCG $(SUBSYSTEM) 32 | 33 | CLEAN = del /q src\*.obj $(LIBPCRE2) $(LIBPCRE2POSIX) $(PCRE2GREP) $(TEST) *.obj *.ilk *.pdb 2>NUL 34 | 35 | all: $(LIBPCRE2) $(LIBPCRE2POSIX) $(PCRE2GREP) 36 | 37 | src\pcre2_auto_possess.obj : src\pcre2_auto_possess.c 38 | $(CC) src\pcre2_auto_possess.c $(CCFLAGS)src\pcre2_auto_possess.obj 39 | src\pcre2_chartables.obj : src\pcre2_chartables.c 40 | $(CC) src\pcre2_chartables.c $(CCFLAGS)src\pcre2_chartables.obj 41 | src\pcre2_compile.obj : src\pcre2_compile.c 42 | $(CC) src\pcre2_compile.c $(CCFLAGS)src\pcre2_compile.obj 43 | src\pcre2_config.obj : src\pcre2_config.c 44 | $(CC) src\pcre2_config.c $(CCFLAGS)src\pcre2_config.obj 45 | src\pcre2_context.obj : src\pcre2_context.c 46 | $(CC) src\pcre2_context.c $(CCFLAGS)src\pcre2_context.obj 47 | src\pcre2_convert.obj : src\pcre2_convert.c 48 | $(CC) src\pcre2_convert.c $(CCFLAGS)src\pcre2_convert.obj 49 | src\pcre2_dfa_match.obj : src\pcre2_dfa_match.c 50 | $(CC) src\pcre2_dfa_match.c $(CCFLAGS)src\pcre2_dfa_match.obj 51 | src\pcre2_error.obj : src\pcre2_error.c 52 | $(CC) src\pcre2_error.c $(CCFLAGS)src\pcre2_error.obj 53 | src\pcre2_extuni.obj : src\pcre2_extuni.c 54 | $(CC) src\pcre2_extuni.c $(CCFLAGS)src\pcre2_extuni.obj 55 | src\pcre2_find_bracket.obj : src\pcre2_find_bracket.c 56 | $(CC) src\pcre2_find_bracket.c $(CCFLAGS)src\pcre2_find_bracket.obj 57 | src\pcre2_jit_compile.obj : src\pcre2_jit_compile.c 58 | $(CC) src\pcre2_jit_compile.c $(CCFLAGS)src\pcre2_jit_compile.obj 59 | src\pcre2_maketables.obj : src\pcre2_maketables.c 60 | $(CC) src\pcre2_maketables.c $(CCFLAGS)src\pcre2_maketables.obj 61 | src\pcre2_match.obj : src\pcre2_match.c 62 | $(CC) src\pcre2_match.c $(CCFLAGS)src\pcre2_match.obj 63 | src\pcre2_match_data.obj : src\pcre2_match_data.c 64 | $(CC) src\pcre2_match_data.c $(CCFLAGS)src\pcre2_match_data.obj 65 | src\pcre2_newline.obj : src\pcre2_newline.c 66 | $(CC) src\pcre2_newline.c $(CCFLAGS)src\pcre2_newline.obj 67 | src\pcre2_ord2utf.obj : src\pcre2_ord2utf.c 68 | $(CC) src\pcre2_ord2utf.c $(CCFLAGS)src\pcre2_ord2utf.obj 69 | src\pcre2_pattern_info.obj : src\pcre2_pattern_info.c 70 | $(CC) src\pcre2_pattern_info.c $(CCFLAGS)src\pcre2_pattern_info.obj 71 | src\pcre2_script_run.obj : src\pcre2_script_run.c 72 | $(CC) src\pcre2_script_run.c $(CCFLAGS)src\pcre2_script_run.obj 73 | src\pcre2_serialize.obj : src\pcre2_serialize.c 74 | $(CC) src\pcre2_serialize.c $(CCFLAGS)src\pcre2_serialize.obj 75 | src\pcre2_string_utils.obj : src\pcre2_string_utils.c 76 | $(CC) src\pcre2_string_utils.c $(CCFLAGS)src\pcre2_string_utils.obj 77 | src\pcre2_study.obj : src\pcre2_study.c 78 | $(CC) src\pcre2_study.c $(CCFLAGS)src\pcre2_study.obj 79 | src\pcre2_substitute.obj : src\pcre2_substitute.c 80 | $(CC) src\pcre2_substitute.c $(CCFLAGS)src\pcre2_substitute.obj 81 | src\pcre2_substring.obj : src\pcre2_substring.c 82 | $(CC) src\pcre2_substring.c $(CCFLAGS)src\pcre2_substring.obj 83 | src\pcre2_tables.obj : src\pcre2_tables.c 84 | $(CC) src\pcre2_tables.c $(CCFLAGS)src\pcre2_tables.obj 85 | src\pcre2_ucd.obj : src\pcre2_ucd.c 86 | $(CC) src\pcre2_ucd.c $(CCFLAGS)src\pcre2_ucd.obj 87 | src\pcre2_valid_utf.obj : src\pcre2_valid_utf.c 88 | $(CC) src\pcre2_valid_utf.c $(CCFLAGS)src\pcre2_valid_utf.obj 89 | src\pcre2_xclass.obj : src\pcre2_xclass.c 90 | $(CC) src\pcre2_xclass.c $(CCFLAGS)src\pcre2_xclass.obj 91 | src\pcre2posix.obj : src\pcre2posix.c 92 | $(CC) src\pcre2posix.c $(CCFLAGS)src\pcre2posix.obj 93 | 94 | OBJS = \ 95 | src\pcre2_auto_possess.obj \ 96 | src\pcre2_chartables.obj \ 97 | src\pcre2_compile.obj \ 98 | src\pcre2_config.obj \ 99 | src\pcre2_context.obj \ 100 | src\pcre2_convert.obj \ 101 | src\pcre2_dfa_match.obj \ 102 | src\pcre2_error.obj \ 103 | src\pcre2_extuni.obj \ 104 | src\pcre2_find_bracket.obj \ 105 | src\pcre2_jit_compile.obj \ 106 | src\pcre2_maketables.obj \ 107 | src\pcre2_match.obj \ 108 | src\pcre2_match_data.obj \ 109 | src\pcre2_newline.obj \ 110 | src\pcre2_ord2utf.obj \ 111 | src\pcre2_pattern_info.obj \ 112 | src\pcre2_script_run.obj \ 113 | src\pcre2_serialize.obj \ 114 | src\pcre2_string_utils.obj \ 115 | src\pcre2_study.obj \ 116 | src\pcre2_substitute.obj \ 117 | src\pcre2_substring.obj \ 118 | src\pcre2_tables.obj \ 119 | src\pcre2_ucd.obj \ 120 | src\pcre2_valid_utf.obj \ 121 | src\pcre2_xclass.obj 122 | 123 | $(LIBPCRE2): $(OBJS) 124 | $(AR) $(ARFLAGS)$(LIBPCRE2) $(OBJS) 125 | 126 | $(LIBPCRE2POSIX): src\pcre2posix.obj 127 | $(AR) $(ARFLAGS)$(LIBPCRE2POSIX) src\pcre2posix.obj 128 | 129 | $(PCRE2GREP): src\pcre2grep.c $(LIBPCRE2) 130 | $(CC) src\pcre2grep.c $(PCRE2GREP_LINK) $(LIBPCRE2) 131 | 132 | $(TEST): src\pcre2test.c $(LIBPCRE2POSIX) $(LIBPCRE2) 133 | $(CC) src\pcre2test.c $(TLINK) $(LIBPCRE2POSIX) $(LIBPCRE2) 134 | 135 | check: $(TEST) $(PCRE2GREP) 136 | $(PCRE2_TEST_RUN) 137 | $(PCRE2GREP_TEST_RUN) 138 | $(TEST_OK) 139 | 140 | clean: 141 | $(CLEAN) 142 | -------------------------------------------------------------------------------- /archive/RunGrepTest-pcre2-10.40.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/RunGrepTest-pcre2-10.40.bat -------------------------------------------------------------------------------- /archive/config-pcre2-10.40.h: -------------------------------------------------------------------------------- 1 | /* src/config.h. Generated from config.h.in by configure. */ 2 | /* src/config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* PCRE2 is written in Standard C, but there are a few non-standard things it 5 | can cope with, allowing it to run on SunOS4 and other "close to standard" 6 | systems. 7 | 8 | In environments that support the GNU autotools, config.h.in is converted into 9 | config.h by the "configure" script. In environments that use CMake, 10 | config-cmake.in is converted into config.h. If you are going to build PCRE2 "by 11 | hand" without using "configure" or CMake, you should copy the distributed 12 | config.h.generic to config.h, and edit the macro definitions to be the way you 13 | need them. You must then add -DHAVE_CONFIG_H to all of your compile commands, 14 | so that config.h is included at the start of every source. 15 | 16 | Alternatively, you can avoid editing by using -D on the compiler command line 17 | to set the macro values. In this case, you do not have to set -DHAVE_CONFIG_H, 18 | but if you do, default values will be taken from config.h for non-boolean 19 | macros that are not defined on the command line. 20 | 21 | Boolean macros such as HAVE_STDLIB_H and SUPPORT_PCRE2_8 should either be 22 | defined (conventionally to 1) for TRUE, and not defined at all for FALSE. All 23 | such macros are listed as a commented #undef in config.h.generic. Macros such 24 | as MATCH_LIMIT, whose actual value is relevant, have defaults defined, but are 25 | surrounded by #ifndef/#endif lines so that the value can be overridden by -D. 26 | 27 | PCRE2 uses memmove() if HAVE_MEMMOVE is defined; otherwise it uses bcopy() if 28 | HAVE_BCOPY is defined. If your system has neither bcopy() nor memmove(), make 29 | sure both macros are undefined; an emulation function will then be used. */ 30 | 31 | /* By default, the \R escape sequence matches any Unicode line ending 32 | character or sequence of characters. If BSR_ANYCRLF is defined (to any 33 | value), this is changed so that backslash-R matches only CR, LF, or CRLF. 34 | The build-time default can be overridden by the user of PCRE2 at runtime. 35 | */ 36 | /* #undef BSR_ANYCRLF */ 37 | 38 | /* Define to any value to disable the use of the z and t modifiers in 39 | formatting settings such as %zu or %td (this is rarely needed). */ 40 | /* #undef DISABLE_PERCENT_ZT */ 41 | 42 | /* If you are compiling for a system that uses EBCDIC instead of ASCII 43 | character codes, define this macro to any value. When EBCDIC is set, PCRE2 44 | assumes that all input strings are in EBCDIC. If you do not define this 45 | macro, PCRE2 will assume input strings are ASCII or UTF-8/16/32 Unicode. It 46 | is not possible to build a version of PCRE2 that supports both EBCDIC and 47 | UTF-8/16/32. */ 48 | /* #undef EBCDIC */ 49 | 50 | /* In an EBCDIC environment, define this macro to any value to arrange for the 51 | NL character to be 0x25 instead of the default 0x15. NL plays the role that 52 | LF does in an ASCII/Unicode environment. */ 53 | /* #undef EBCDIC_NL25 */ 54 | 55 | /* Define this if your compiler supports __attribute__((uninitialized)) */ 56 | /* #undef HAVE_ATTRIBUTE_UNINITIALIZED */ 57 | 58 | /* Define to 1 if you have the `bcopy' function. */ 59 | /* #undef HAVE_BCOPY */ 60 | 61 | /* Define to 1 if you have the header file. */ 62 | /* #undef HAVE_BZLIB_H */ 63 | 64 | /* Define to 1 if you have the header file. */ 65 | /* #undef HAVE_DIRENT_H */ 66 | 67 | /* Define to 1 if you have the header file. */ 68 | /* #undef HAVE_DLFCN_H */ 69 | 70 | /* Define to 1 if you have the header file. */ 71 | /* #undef HAVE_EDITLINE_READLINE_H */ 72 | 73 | /* Define to 1 if you have the header file. */ 74 | /* #undef HAVE_EDIT_READLINE_READLINE_H */ 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_INTTYPES_H 1 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_LIMITS_H 1 81 | 82 | /* Define to 1 if you have the `memfd_create' function. */ 83 | /* #undef HAVE_MEMFD_CREATE */ 84 | 85 | /* Define to 1 if you have the `memmove' function. */ 86 | #define HAVE_MEMMOVE 1 87 | 88 | /* Define to 1 if you have the header file. */ 89 | /* #undef HAVE_MINIX_CONFIG_H */ 90 | 91 | /* Define to 1 if you have the `mkostemp' function. */ 92 | /* #undef HAVE_MKOSTEMP */ 93 | 94 | /* Define if you have POSIX threads libraries and header files. */ 95 | /* #undef HAVE_PTHREAD */ 96 | 97 | /* Have PTHREAD_PRIO_INHERIT. */ 98 | /* #undef HAVE_PTHREAD_PRIO_INHERIT */ 99 | 100 | /* Define to 1 if you have the header file. */ 101 | /* #undef HAVE_READLINE_H */ 102 | 103 | /* Define to 1 if you have the header file. */ 104 | /* #undef HAVE_READLINE_HISTORY_H */ 105 | 106 | /* Define to 1 if you have the header file. */ 107 | /* #undef HAVE_READLINE_READLINE_H */ 108 | 109 | /* Define to 1 if you have the `realpath' function. */ 110 | /* #undef HAVE_REALPATH */ 111 | 112 | /* Define to 1 if you have the `secure_getenv' function. */ 113 | /* #undef HAVE_SECURE_GETENV */ 114 | 115 | /* Define to 1 if you have the header file. */ 116 | #define HAVE_STDINT_H 1 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #define HAVE_STDIO_H 1 120 | 121 | /* Define to 1 if you have the header file. */ 122 | #define HAVE_STDLIB_H 1 123 | 124 | /* Define to 1 if you have the `strerror' function. */ 125 | #define HAVE_STRERROR 1 126 | 127 | /* Define to 1 if you have the header file. */ 128 | /* #undef HAVE_STRINGS_H */ 129 | 130 | /* Define to 1 if you have the header file. */ 131 | #define HAVE_STRING_H 1 132 | 133 | /* Define to 1 if you have the header file. */ 134 | #define HAVE_SYS_STAT_H 1 135 | 136 | /* Define to 1 if you have the header file. */ 137 | #define HAVE_SYS_TYPES_H 1 138 | 139 | /* Define to 1 if you have the header file. */ 140 | /* #undef HAVE_SYS_WAIT_H */ 141 | 142 | /* Define to 1 if you have the header file. */ 143 | /* #undef HAVE_UNISTD_H */ 144 | 145 | /* Define to 1 if the compiler supports simple visibility declarations. */ 146 | /* #undef HAVE_VISIBILITY */ 147 | 148 | /* Define to 1 if you have the header file. */ 149 | #define HAVE_WCHAR_H 1 150 | 151 | /* Define to 1 if you have the header file. */ 152 | #define HAVE_WINDOWS_H 1 153 | 154 | /* Define to 1 if you have the header file. */ 155 | /* #undef HAVE_ZLIB_H */ 156 | 157 | /* This limits the amount of memory that may be used while matching a pattern. 158 | It applies to both pcre2_match() and pcre2_dfa_match(). It does not apply 159 | to JIT matching. The value is in kibibytes (units of 1024 bytes). */ 160 | #ifndef HEAP_LIMIT 161 | #define HEAP_LIMIT 20000000 162 | #endif 163 | 164 | /* The value of LINK_SIZE determines the number of bytes used to store links 165 | as offsets within the compiled regex. The default is 2, which allows for 166 | compiled patterns up to 65535 code units long. This covers the vast 167 | majority of cases. However, PCRE2 can also be compiled to use 3 or 4 bytes 168 | instead. This allows for longer patterns in extreme cases. */ 169 | #ifndef LINK_SIZE 170 | #define LINK_SIZE 2 171 | #endif 172 | 173 | /* Define to the sub-directory where libtool stores uninstalled libraries. */ 174 | /* This is ignored unless you are using libtool. */ 175 | #ifndef LT_OBJDIR 176 | #define LT_OBJDIR ".libs/" 177 | #endif 178 | 179 | /* The value of MATCH_LIMIT determines the default number of times the 180 | pcre2_match() function can record a backtrack position during a single 181 | matching attempt. The value is also used to limit a loop counter in 182 | pcre2_dfa_match(). There is a runtime interface for setting a different 183 | limit. The limit exists in order to catch runaway regular expressions that 184 | take for ever to determine that they do not match. The default is set very 185 | large so that it does not accidentally catch legitimate cases. */ 186 | #ifndef MATCH_LIMIT 187 | #define MATCH_LIMIT 10000000 188 | #endif 189 | 190 | /* The above limit applies to all backtracks, whether or not they are nested. 191 | In some environments it is desirable to limit the nesting of backtracking 192 | (that is, the depth of tree that is searched) more strictly, in order to 193 | restrict the maximum amount of heap memory that is used. The value of 194 | MATCH_LIMIT_DEPTH provides this facility. To have any useful effect, it 195 | must be less than the value of MATCH_LIMIT. The default is to use the same 196 | value as MATCH_LIMIT. There is a runtime method for setting a different 197 | limit. In the case of pcre2_dfa_match(), this limit controls the depth of 198 | the internal nested function calls that are used for pattern recursions, 199 | lookarounds, and atomic groups. */ 200 | #ifndef MATCH_LIMIT_DEPTH 201 | #define MATCH_LIMIT_DEPTH MATCH_LIMIT 202 | #endif 203 | 204 | /* This limit is parameterized just in case anybody ever wants to change it. 205 | Care must be taken if it is increased, because it guards against integer 206 | overflow caused by enormously large patterns. */ 207 | #ifndef MAX_NAME_COUNT 208 | #define MAX_NAME_COUNT 10000 209 | #endif 210 | 211 | /* This limit is parameterized just in case anybody ever wants to change it. 212 | Care must be taken if it is increased, because it guards against integer 213 | overflow caused by enormously large patterns. */ 214 | #ifndef MAX_NAME_SIZE 215 | #define MAX_NAME_SIZE 32 216 | #endif 217 | 218 | /* Defining NEVER_BACKSLASH_C locks out the use of \C in all patterns. */ 219 | /* #undef NEVER_BACKSLASH_C */ 220 | 221 | /* The value of NEWLINE_DEFAULT determines the default newline character 222 | sequence. PCRE2 client programs can override this by selecting other values 223 | at run time. The valid values are 1 (CR), 2 (LF), 3 (CRLF), 4 (ANY), 5 224 | (ANYCRLF), and 6 (NUL). */ 225 | #ifndef NEWLINE_DEFAULT 226 | #define NEWLINE_DEFAULT 2 227 | #endif 228 | 229 | /* Name of package */ 230 | #define PACKAGE "pcre2" 231 | 232 | /* Define to the address where bug reports for this package should be sent. */ 233 | #define PACKAGE_BUGREPORT "" 234 | 235 | /* Define to the full name of this package. */ 236 | #define PACKAGE_NAME "PCRE2" 237 | 238 | /* Define to the full name and version of this package. */ 239 | #define PACKAGE_STRING "PCRE2 10.40" 240 | 241 | /* Define to the one symbol short name of this package. */ 242 | #define PACKAGE_TARNAME "pcre2" 243 | 244 | /* Define to the home page for this package. */ 245 | #define PACKAGE_URL "" 246 | 247 | /* Define to the version of this package. */ 248 | #define PACKAGE_VERSION "10.40" 249 | 250 | /* The value of PARENS_NEST_LIMIT specifies the maximum depth of nested 251 | parentheses (of any kind) in a pattern. This limits the amount of system 252 | stack that is used while compiling a pattern. */ 253 | #ifndef PARENS_NEST_LIMIT 254 | #define PARENS_NEST_LIMIT 250 255 | #endif 256 | 257 | /* The value of PCRE2GREP_BUFSIZE is the starting size of the buffer used by 258 | pcre2grep to hold parts of the file it is searching. The buffer will be 259 | expanded up to PCRE2GREP_MAX_BUFSIZE if necessary, for files containing 260 | very long lines. The actual amount of memory used by pcre2grep is three 261 | times this number, because it allows for the buffering of "before" and 262 | "after" lines. */ 263 | #ifndef PCRE2GREP_BUFSIZE 264 | #define PCRE2GREP_BUFSIZE 20480 265 | #endif 266 | 267 | /* The value of PCRE2GREP_MAX_BUFSIZE specifies the maximum size of the buffer 268 | used by pcre2grep to hold parts of the file it is searching. The actual 269 | amount of memory used by pcre2grep is three times this number, because it 270 | allows for the buffering of "before" and "after" lines. */ 271 | #ifndef PCRE2GREP_MAX_BUFSIZE 272 | #define PCRE2GREP_MAX_BUFSIZE 1048576 273 | #endif 274 | 275 | /* Define to any value to include debugging code. */ 276 | /* #undef PCRE2_DEBUG */ 277 | 278 | /* If you are compiling for a system other than a Unix-like system or 279 | Win32, and it needs some magic to be inserted before the definition 280 | of a function that is exported by the library, define this macro to 281 | contain the relevant magic. If you do not define this macro, a suitable 282 | __declspec value is used for Windows systems; in other environments 283 | "extern" is used for a C compiler and "extern C" for a C++ compiler. 284 | This macro apears at the start of every exported function that is part 285 | of the external API. It does not appear on functions that are "external" 286 | in the C sense, but which are internal to the library. */ 287 | /* #undef PCRE2_EXP_DEFN */ 288 | 289 | /* Define to any value if linking statically (TODO: make nice with Libtool) */ 290 | #define PCRE2_STATIC 1 291 | 292 | /* Define to necessary symbol if this constant uses a non-standard name on 293 | your system. */ 294 | /* #undef PTHREAD_CREATE_JOINABLE */ 295 | 296 | /* Define to any non-zero number to enable support for SELinux compatible 297 | executable memory allocator in JIT. Note that this will have no effect 298 | unless SUPPORT_JIT is also defined. */ 299 | /* #undef SLJIT_PROT_EXECUTABLE_ALLOCATOR */ 300 | 301 | /* Define to 1 if all of the C90 standard headers exist (not just the ones 302 | required in a freestanding environment). This macro is provided for 303 | backward compatibility; new code need not use it. */ 304 | #define STDC_HEADERS 1 305 | 306 | /* Define to any value to enable support for Just-In-Time compiling. */ 307 | #define SUPPORT_JIT 1 308 | 309 | /* Define to any value to allow pcre2grep to be linked with libbz2, so that it 310 | is able to handle .bz2 files. */ 311 | /* #undef SUPPORT_LIBBZ2 */ 312 | 313 | /* Define to any value to allow pcre2test to be linked with libedit. */ 314 | /* #undef SUPPORT_LIBEDIT */ 315 | 316 | /* Define to any value to allow pcre2test to be linked with libreadline. */ 317 | /* #undef SUPPORT_LIBREADLINE */ 318 | 319 | /* Define to any value to allow pcre2grep to be linked with libz, so that it 320 | is able to handle .gz files. */ 321 | /* #undef SUPPORT_LIBZ */ 322 | 323 | /* Define to any value to enable callout script support in pcre2grep. */ 324 | #define SUPPORT_PCRE2GREP_CALLOUT 1 325 | 326 | /* Define to any value to enable fork support in pcre2grep callout scripts. 327 | This will have no effect unless SUPPORT_PCRE2GREP_CALLOUT is also defined. 328 | */ 329 | #define SUPPORT_PCRE2GREP_CALLOUT_FORK 1 330 | 331 | /* Define to any value to enable JIT support in pcre2grep. Note that this will 332 | have no effect unless SUPPORT_JIT is also defined. */ 333 | #define SUPPORT_PCRE2GREP_JIT 1 334 | 335 | /* Define to any value to enable the 16 bit PCRE2 library. */ 336 | /* #undef SUPPORT_PCRE2_16 */ 337 | 338 | /* Define to any value to enable the 32 bit PCRE2 library. */ 339 | /* #undef SUPPORT_PCRE2_32 */ 340 | 341 | /* Define to any value to enable the 8 bit PCRE2 library. */ 342 | #define SUPPORT_PCRE2_8 1 343 | 344 | /* Define to any value to enable support for Unicode and UTF encoding. This 345 | will work even in an EBCDIC environment, but it is incompatible with the 346 | EBCDIC macro. That is, PCRE2 can support *either* EBCDIC code *or* 347 | ASCII/Unicode, but not both at once. */ 348 | #define SUPPORT_UNICODE 1 349 | 350 | /* Define to any value for valgrind support to find invalid memory reads. */ 351 | /* #undef SUPPORT_VALGRIND */ 352 | 353 | /* Enable extensions on AIX 3, Interix. */ 354 | #ifndef _ALL_SOURCE 355 | # define _ALL_SOURCE 1 356 | #endif 357 | /* Enable general extensions on macOS. */ 358 | #ifndef _DARWIN_C_SOURCE 359 | # define _DARWIN_C_SOURCE 1 360 | #endif 361 | /* Enable general extensions on Solaris. */ 362 | #ifndef __EXTENSIONS__ 363 | # define __EXTENSIONS__ 1 364 | #endif 365 | /* Enable GNU extensions on systems that have them. */ 366 | #ifndef _GNU_SOURCE 367 | # define _GNU_SOURCE 1 368 | #endif 369 | /* Enable X/Open compliant socket functions that do not require linking 370 | with -lxnet on HP-UX 11.11. */ 371 | #ifndef _HPUX_ALT_XOPEN_SOCKET_API 372 | # define _HPUX_ALT_XOPEN_SOCKET_API 1 373 | #endif 374 | /* Identify the host operating system as Minix. 375 | This macro does not affect the system headers' behavior. 376 | A future release of Autoconf may stop defining this macro. */ 377 | #ifndef _MINIX 378 | /* # undef _MINIX */ 379 | #endif 380 | /* Enable general extensions on NetBSD. 381 | Enable NetBSD compatibility extensions on Minix. */ 382 | #ifndef _NETBSD_SOURCE 383 | # define _NETBSD_SOURCE 1 384 | #endif 385 | /* Enable OpenBSD compatibility extensions on NetBSD. 386 | Oddly enough, this does nothing on OpenBSD. */ 387 | #ifndef _OPENBSD_SOURCE 388 | # define _OPENBSD_SOURCE 1 389 | #endif 390 | /* Define to 1 if needed for POSIX-compatible behavior. */ 391 | #ifndef _POSIX_SOURCE 392 | /* # undef _POSIX_SOURCE */ 393 | #endif 394 | /* Define to 2 if needed for POSIX-compatible behavior. */ 395 | #ifndef _POSIX_1_SOURCE 396 | /* # undef _POSIX_1_SOURCE */ 397 | #endif 398 | /* Enable POSIX-compatible threading on Solaris. */ 399 | #ifndef _POSIX_PTHREAD_SEMANTICS 400 | # define _POSIX_PTHREAD_SEMANTICS 1 401 | #endif 402 | /* Enable extensions specified by ISO/IEC TS 18661-5:2014. */ 403 | #ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 404 | # define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1 405 | #endif 406 | /* Enable extensions specified by ISO/IEC TS 18661-1:2014. */ 407 | #ifndef __STDC_WANT_IEC_60559_BFP_EXT__ 408 | # define __STDC_WANT_IEC_60559_BFP_EXT__ 1 409 | #endif 410 | /* Enable extensions specified by ISO/IEC TS 18661-2:2015. */ 411 | #ifndef __STDC_WANT_IEC_60559_DFP_EXT__ 412 | # define __STDC_WANT_IEC_60559_DFP_EXT__ 1 413 | #endif 414 | /* Enable extensions specified by ISO/IEC TS 18661-4:2015. */ 415 | #ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__ 416 | # define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1 417 | #endif 418 | /* Enable extensions specified by ISO/IEC TS 18661-3:2015. */ 419 | #ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ 420 | # define __STDC_WANT_IEC_60559_TYPES_EXT__ 1 421 | #endif 422 | /* Enable extensions specified by ISO/IEC TR 24731-2:2010. */ 423 | #ifndef __STDC_WANT_LIB_EXT2__ 424 | # define __STDC_WANT_LIB_EXT2__ 1 425 | #endif 426 | /* Enable extensions specified by ISO/IEC 24747:2009. */ 427 | #ifndef __STDC_WANT_MATH_SPEC_FUNCS__ 428 | # define __STDC_WANT_MATH_SPEC_FUNCS__ 1 429 | #endif 430 | /* Enable extensions on HP NonStop. */ 431 | #ifndef _TANDEM_SOURCE 432 | # define _TANDEM_SOURCE 1 433 | #endif 434 | /* Enable X/Open extensions. Define to 500 only if necessary 435 | to make mbstate_t available. */ 436 | #ifndef _XOPEN_SOURCE 437 | /* # undef _XOPEN_SOURCE */ 438 | #endif 439 | 440 | /* Version number of package */ 441 | #define VERSION "10.40" 442 | 443 | /* Define to empty if `const' does not conform to ANSI C. */ 444 | /* #undef const */ 445 | 446 | /* Define to the type of a signed integer type of width exactly 64 bits if 447 | such a type exists and the standard includes do not define it. */ 448 | /* #undef int64_t */ 449 | 450 | /* Define to `unsigned int' if does not define. */ 451 | /* #undef size_t */ 452 | -------------------------------------------------------------------------------- /archive/grep-3.3-build-VS17-x64.txt: -------------------------------------------------------------------------------- 1 | How to build native win64 grep.exe with Visual Studio 2017 and WDK10 2 | 3 | From cygwin or other unix shell: 4 | 5 | 1) get grep archive: wget https://ftp.gnu.org/gnu/grep/grep-3.3.tar.xz 6 | 2) unpack sed archive: tar xf grep-3.3.tar.xz 7 | 3) go to sed sources: cd grep-3.3 8 | 9 | 4) fix grep-3.3-build-VS17-x64.patch - change paths to locations of Visual Studio 2017 and WDK10 10 | 11 | sed -i '/Visual Studio/s@.:.*include@D:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include@' grep-3.3-build-VS17-x64.patch 12 | sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt@' grep-3.3-build-VS17-x64.patch 13 | 14 | 5) patch grep: patch -Np1 -i grep-3.3-build-VS17-x64.patch 15 | 6) run dos prompt: cmd.exe /c "start cmd.exe" 16 | 7) setup compiler: "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 17 | 8) do compile: make.bat 18 | 9) check build result: grep.exe --version 19 | -------------------------------------------------------------------------------- /archive/grep-3.3-build-patch-howto.txt: -------------------------------------------------------------------------------- 1 | Instructions how to build native grep.exe with Microsoft Visual Studio from CYGWIN shell. 2 | 3 | While building, it is possible to save build log and create a patch - for compiling grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 4 | 5 | This is how grep-3.3-build-VS17-x64.patch was created. 6 | 7 | (grep-3.3-build-VS9-x86.patch was created analogously in Microsoft Visual Studio 2008 environment) 8 | 9 | 10 | From CYGWIN shell: 11 | 12 | 1) get archive: 13 | wget https://ftp.gnu.org/gnu/grep/grep-3.3.tar.xz 14 | 15 | 2) unpack archive: 16 | tar xf grep-3.3.tar.xz 17 | 18 | 3) go to grep sources: 19 | cd grep-3.3 20 | 21 | 4) fix sources for windows: 22 | patch -Np1 -i grep-3.3-src.patch 23 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.3-src.patch) 24 | 25 | ;5) to build with old non-c99 compiler (such as Microsoft Visual Studio 2008) apply one more patch: 26 | ; patch -Np1 -i grep-3.3-src-non-c99.patch 27 | ; (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.3-src-non-c99.patch) 28 | 29 | 6) now start dos prompt: 30 | cmd.exe /c "start cmd.exe" 31 | 32 | 7) setup compiler: 33 | "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 34 | (if Microsoft Visual Studio 2017 is installed in "D:\Program Files (x86)") 35 | 36 | ; --tip: for Visual Studio 2008: 37 | ; "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 38 | 39 | 8) run bash from dos prompt (with environment prepared for compiling with Microsoft Visual Studio): 40 | bash 41 | 42 | 9) check Gnu Make is installed in CYGWIN and it is working: 43 | make --version 44 | 45 | 10) configure grep: 46 | CFLAGS= CC=cl CPP="cl -E" LD=lib ARFLAGS="/OUT:" ./configure --enable-threads=windows --disable-dependency-tracking --disable-silent-rules --disable-nls 47 | 48 | 11) configure script is not fully functional to create correct Makefiles - they are need to be fixed manually: 49 | sed -i 's/^SUBDIRS = .*/SUBDIRS = lib src/' ./Makefile 50 | sed -i '/^NEXT/s/=.*/=""/' ./Makefile ./lib/Makefile ./src/Makefile 51 | sed -i 's/^RECURSIVE_TARGETS = /&gen /' ./Makefile 52 | sed -i 's/$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1/:/' ./Makefile 53 | sed -i 's/-c -o /-c -nologo -Fo/' ./lib/Makefile ./src/Makefile 54 | sed -i 's@^AR = .*@AR = lib /nologo@' ./lib/Makefile 55 | sed -i '/libgreputils_a_AR/s/ lib/lib/' ./lib/Makefile 56 | sed -i 's%^am_libgreputils_a_OBJECTS = %&getpagesize.$(OBJEXT) stat-w32.$(OBJEXT) %' ./lib/Makefile 57 | sed -i 's%^LINK = .*%LINK = link /nologo /DEFAULTLIB:LIBCPMT.lib /OUT:$@%' ./src/Makefile 58 | 59 | 12) add gen target: 60 | echo 'gen:' >> ./Makefile 61 | echo 'gen:' >> ./src/Makefile 62 | echo 'gen: $(BUILT_SOURCES)' >> ./lib/Makefile 63 | 64 | 13) execute Makefile to generate grep headers: 65 | make gen 66 | 67 | 14) some references to system header files are missing in generated headers - they need to be fixed manually. 68 | 69 | a) set paths to locations of Visual Studio 2017 and WDK10 in grep-3.3-win-headers.patch (assume it was copied to the current directory): 70 | for example, if Visual Studio 2017 is installed in "D:\Program Files (x86)" and WDK10 installed in "C:\Program Files (x86)" 71 | 72 | sed -i '/Visual Studio/s@.:.*include@D:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include@' ./grep-3.3-win-headers.patch 73 | sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt@' ./grep-3.3-win-headers.patch 74 | 75 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.3-win-headers.patch) 76 | 77 | ; --tip: for Visual Studio 2008: 78 | ; sed -i '/Visual Studio/s@.:.*include@C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include@' ./grep-3.3-win-headers.patch 79 | ; sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include@' ./grep-3.3-win-headers.patch 80 | 81 | b) now patch generated headers with updated patch-file: 82 | patch -Np1 -i grep-3.3-win-headers.patch 83 | 84 | c) header file lib/unistd.h is generated erroneously, fix it: 85 | patch -Np1 -i grep-3.3-unistd.patch 86 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.3-unistd.patch) 87 | 88 | 15) do compile grep: 89 | make > make.bat 90 | 91 | 16) check build result: 92 | ./src/grep.exe --version 93 | 94 | (should print grep version, e.g.: (GNU grep) 3.3) 95 | 96 | compilation should be ok, native (unoptimized) ./grep/grep.exe should be created. 97 | 98 | 99 | Now it is possible to create a patch file - for compiling optimized grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 100 | 101 | 1) create directory for unpatched grep: 102 | mkdir ../orig 103 | 104 | 2) unpack grep: 105 | tar xf ../grep-3.3.tar.xz -C ../orig/ 106 | 107 | 3) diff current directory with original just unpacked grep-3.3.tar.xz in '../orig' directory 108 | diff -rql . ../orig/grep-3.3 109 | 110 | 4) remove unneeded built files in the current directory (object files, libs, etc...) 111 | 112 | rm -r \ 113 | ./Makefile \ 114 | ./stamp-h1 \ 115 | ./grep-3.3-win-headers.patch \ 116 | ./src/*.obj \ 117 | ./lib/*.obj \ 118 | ./lib/glthread/*.obj \ 119 | ./lib/glthread/.deps \ 120 | ./lib/glthread/.dirstamp \ 121 | ./lib/unistr/*.obj \ 122 | ./lib/unistr/.deps \ 123 | ./lib/unistr/.dirstamp \ 124 | ./lib/uniwidth/*.obj \ 125 | ./lib/uniwidth/.deps \ 126 | ./lib/uniwidth/.dirstamp \ 127 | ./lib/libgreputils.a \ 128 | ./src/grep.exe \ 129 | ./src/egrep \ 130 | ./src/fgrep \ 131 | ./src/Makefile \ 132 | ./lib/Makefile \ 133 | ./doc/Makefile \ 134 | ./tests/Makefile \ 135 | ./gnulib-tests/Makefile \ 136 | ./po/Makefile \ 137 | ./po/Makefile.in \ 138 | ./po/POTFILES \ 139 | ./config.log \ 140 | ./config.status 141 | 142 | 5) after this, diff should show something like: 143 | 144 | diff -rql . ../orig/grep-3.3 145 | Only in .: config.h 146 | Only in ./lib: alloca.h 147 | Only in ./lib: colorize.c 148 | Only in ./lib: configmake.h 149 | Only in ./lib: ctype.h 150 | Only in ./lib: dirent.h 151 | Only in ./lib: errno.h 152 | Only in ./lib: fcntl.h 153 | Only in ./lib: fnmatch.h 154 | Files ./lib/fts.c and ../orig/grep-3.3/lib/fts.c differ 155 | Only in ./lib: getopt.h 156 | Only in ./lib: getopt-cdefs.h 157 | Only in ./lib: inttypes.h 158 | Only in ./lib: langinfo.h 159 | Only in ./lib: limits.h 160 | Only in ./lib: locale.h 161 | Only in ./lib: signal.h 162 | Only in ./lib: stdalign.h 163 | Only in ./lib: stddef.h 164 | Only in ./lib: stdint.h 165 | Only in ./lib: stdio.h 166 | Only in ./lib: stdlib.h 167 | Only in ./lib: string.h 168 | Only in ./lib: sys 169 | Only in ./lib: time.h 170 | Only in ./lib: unistd.h 171 | Only in ./lib: unistr.h 172 | Only in ./lib: unitypes.h 173 | Only in ./lib: uniwidth.h 174 | Only in ./lib: wchar.h 175 | Only in ./lib: wctype.h 176 | Only in .: make.bat 177 | Files ./src/grep.c and ../orig/grep-3.3/src/grep.c differ 178 | 179 | ;If patch grep-3.3-src-non-c99.patch was applied, diff will show additional differences: 180 | ; 181 | 182 | 6) edit make.bat 183 | 184 | cp make.bat make.bat.old 185 | sed -i -n '/^cl /p;/^lib /p;/^link /p' make.bat 186 | sed -i '/.nologo /s@/@\\@g' make.bat 187 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@-Fo@&lib\\@' make.bat 188 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@.cygpath -w .@lib\\@' make.bat 189 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib -c/s@-Fo@&src\\@' make.bat 190 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib -c/s@.cygpath -w .@src\\@' make.bat 191 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. -I..\\lib -I..\\lib .* -c@/I. /I.\\lib /I.\\src -c@' make.bat 192 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. .* -c@/I. /I.\\lib -c@' make.bat 193 | sed -i 's@-c -nologo -Fo@/Ox /GF /Gy /GS- /GL /EHsc /DHAVE_CONFIG_H /c /nologo /Fo@' make.bat 194 | sed -i 's@.`@@' make.bat 195 | sed -i '/^lib/s@ .nologo .OUT:@@;/^lib/s@ *$@@g;/^lib/s@ @ .\\lib\\@g;s@^lib@lib /LTCG /nologo /OUT:@' make.bat 196 | sed -i '/^link/s@..\\lib\\libgreputils.a@@g' make.bat 197 | sed -i '/^link/s@ .nologo .DEFAULTLIB:LIBCPMT.lib .OUT:@@;/^link/s@ *$@@g;/^link/s@ @ .\\src\\@g' make.bat 198 | sed -i 's@^link@link /LTCG /nologo /DEFAULTLIB:LIBCPMT.lib .\\libgreputils.a /OUT:@' make.bat 199 | rm make.bat.old 200 | 201 | 7) finally, create a patch: 202 | diff -Naur ../orig/grep-3.3 . > ../grep-3.3-build-VS17-x64.patch 203 | 204 | ; or, for Visual Studio 2008: 205 | ; diff -Naur ../orig/grep-3.3 . > ../grep-3.3-build-VS9-x86.patch 206 | -------------------------------------------------------------------------------- /archive/grep-3.3-src.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.3-t1/lib/fts.c grep-3.3/lib/fts.c 2 | --- grep-3.3-t1/lib/fts.c 2018-12-21 05:51:47.000000000 +0300 3 | +++ grep-3.3/lib/fts.c 2018-12-24 12:40:33.473025900 +0300 4 | @@ -120,6 +120,9 @@ 5 | #ifndef S_IFSOCK 6 | # define S_IFSOCK 0 7 | #endif 8 | +#ifndef S_IFBLK 9 | +# define S_IFBLK 0 10 | +#endif 11 | 12 | enum 13 | { 14 | @@ -1874,7 +1877,7 @@ 15 | FTSENT *dummy; 16 | int (*compare) (void const *, void const *) = 17 | ((sizeof &dummy == sizeof (void *) 18 | - && (long int) &dummy == (long int) (void *) &dummy) 19 | + && (long long int) &dummy == (long long int) (void *) &dummy) 20 | ? (int (*) (void const *, void const *)) sp->fts_compar 21 | : fts_compar); 22 | 23 | diff -Naur grep-3.3-t1/src/grep.c grep-3.3/src/grep.c 24 | --- grep-3.3-t1/src/grep.c 2018-12-21 06:31:11.000000000 +0300 25 | +++ grep-3.3/src/grep.c 2018-12-24 12:59:27.698614000 +0300 26 | @@ -52,6 +52,10 @@ 27 | #include "xbinary-io.h" 28 | #include "xstrtol.h" 29 | 30 | +#if defined _WIN32 && ! defined __CYGWIN__ 31 | +#define strcasecmp(s1,s2) _stricmp(s1,s2) 32 | +#endif 33 | + 34 | enum { SEP_CHAR_SELECTED = ':' }; 35 | enum { SEP_CHAR_REJECTED = '-' }; 36 | static char const SEP_STR_GROUP[] = "--"; 37 | @@ -2769,6 +2773,8 @@ 38 | (char *) NULL); 39 | puts (_("Written by Mike Haertel and others; see\n" 40 | ".")); 41 | + puts (_("Patched by: Michael M. Builov .\n")); 42 | + 43 | return EXIT_SUCCESS; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /archive/grep-3.3-unistd.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.3-t1/lib/unistd.h grep-3.3/lib/unistd.h 2 | --- grep-3.3-t1/lib/unistd.h 2018-12-24 14:14:09.607890500 +0300 3 | +++ grep-3.3/lib/unistd.h 2018-12-24 13:20:08.164352000 +0300 4 | @@ -1327,7 +1327,7 @@ 5 | #endif 6 | 7 | 8 | -#if 1 9 | +#if 0 10 | # if 0 11 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 12 | # define getpagesize rpl_getpagesize 13 | @@ -1407,6 +1407,7 @@ 14 | "use gnulib module getpagesize for portability"); 15 | # endif 16 | #endif 17 | +int getpagesize(void); 18 | 19 | 20 | #if 0 21 | -------------------------------------------------------------------------------- /archive/grep-3.3-win-headers.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.3-t1/lib/ctype.h grep-3.3/lib/ctype.h 2 | --- grep-3.3-t1/lib/ctype.h 2018-12-24 14:14:04.087882800 +0300 3 | +++ grep-3.3/lib/ctype.h 2018-12-24 12:32:27.110344900 +0300 4 | @@ -32,7 +32,7 @@ 5 | 6 | /* Include the original . */ 7 | /* The include_next requires a split double-inclusion guard. */ 8 | -#include "" 9 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\ctype.h" 10 | 11 | #ifndef _GL_CTYPE_H 12 | #define _GL_CTYPE_H 13 | diff -Naur grep-3.3-t1/lib/errno.h grep-3.3/lib/errno.h 14 | --- grep-3.3-t1/lib/errno.h 2018-12-24 14:14:04.477883300 +0300 15 | +++ grep-3.3/lib/errno.h 2018-12-24 12:27:51.059958400 +0300 16 | @@ -24,7 +24,7 @@ 17 | 18 | 19 | /* The include_next requires a split double-inclusion guard. */ 20 | -#include "" 21 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\errno.h" 22 | 23 | #ifndef _GL_ERRNO_H 24 | #define _GL_ERRNO_H 25 | diff -Naur grep-3.3-t1/lib/fcntl.h grep-3.3/lib/fcntl.h 26 | --- grep-3.3-t1/lib/fcntl.h 2018-12-24 14:14:04.657883600 +0300 27 | +++ grep-3.3/lib/fcntl.h 2018-12-24 14:21:08.302478000 +0300 28 | @@ -38,7 +38,7 @@ 29 | #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))) 30 | # include 31 | #endif 32 | -#include "" 33 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\fcntl.h" 34 | 35 | #else 36 | /* Normal invocation convention. */ 37 | @@ -58,7 +58,7 @@ 38 | # include 39 | #endif 40 | /* The include_next requires a split double-inclusion guard. */ 41 | -#include "" 42 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\fcntl.h" 43 | 44 | #ifndef _GL_FCNTL_H 45 | #define _GL_FCNTL_H 46 | diff -Naur grep-3.3-t1/lib/inttypes.h grep-3.3/lib/inttypes.h 47 | --- grep-3.3-t1/lib/inttypes.h 2018-12-24 14:14:05.267884400 +0300 48 | +++ grep-3.3/lib/inttypes.h 2018-12-24 12:34:32.071519900 +0300 49 | @@ -38,7 +38,7 @@ 50 | # define __STDC_FORMAT_MACROS 1 51 | # endif 52 | 53 | -# include "" 54 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\inttypes.h" 55 | # endif 56 | #endif 57 | 58 | diff -Naur grep-3.3-t1/lib/limits.h grep-3.3/lib/limits.h 59 | --- grep-3.3-t1/lib/limits.h 2018-12-24 14:14:05.557884800 +0300 60 | +++ grep-3.3/lib/limits.h 2018-12-24 12:26:44.369865000 +0300 61 | @@ -24,7 +24,7 @@ 62 | 63 | 64 | /* The include_next requires a split double-inclusion guard. */ 65 | -#include "" 66 | +#include "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\limits.h" 67 | 68 | #ifndef _GL_LIMITS_H 69 | #define _GL_LIMITS_H 70 | diff -Naur grep-3.3-t1/lib/locale.h grep-3.3/lib/locale.h 71 | --- grep-3.3-t1/lib/locale.h 2018-12-24 14:14:05.767885100 +0300 72 | +++ grep-3.3/lib/locale.h 2018-12-24 12:32:52.780380800 +0300 73 | @@ -38,7 +38,7 @@ 74 | #define _GL_ALREADY_INCLUDING_LOCALE_H 75 | 76 | /* The include_next requires a split double-inclusion guard. */ 77 | -#include "" 78 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\locale.h" 79 | 80 | #undef _GL_ALREADY_INCLUDING_LOCALE_H 81 | 82 | diff -Naur grep-3.3-t1/lib/signal.h grep-3.3/lib/signal.h 83 | --- grep-3.3-t1/lib/signal.h 2018-12-24 14:14:05.967885400 +0300 84 | +++ grep-3.3/lib/signal.h 2018-12-24 12:32:00.180307100 +0300 85 | @@ -49,7 +49,7 @@ 86 | #include 87 | 88 | /* The include_next requires a split double-inclusion guard. */ 89 | -#include "" 90 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\signal.h" 91 | 92 | #undef _GL_ALREADY_INCLUDING_SIGNAL_H 93 | 94 | diff -Naur grep-3.3-t1/lib/stddef.h grep-3.3/lib/stddef.h 95 | --- grep-3.3-t1/lib/stddef.h 2018-12-24 14:14:06.177885700 +0300 96 | +++ grep-3.3/lib/stddef.h 2018-12-24 12:23:48.009618100 +0300 97 | @@ -52,7 +52,7 @@ 98 | 99 | /* The include_next requires a split double-inclusion guard. */ 100 | 101 | -# include "" 102 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\stddef.h" 103 | 104 | /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ 105 | # if (0 \ 106 | diff -Naur grep-3.3-t1/lib/stdint.h grep-3.3/lib/stdint.h 107 | --- grep-3.3-t1/lib/stdint.h 2018-12-24 14:14:06.417886000 +0300 108 | +++ grep-3.3/lib/stdint.h 2018-12-24 12:30:40.220195200 +0300 109 | @@ -74,7 +74,7 @@ 110 | in would reinclude us, skipping our contents because 111 | _GL_STDINT_H is defined. 112 | The include_next requires a split double-inclusion guard. */ 113 | -# include "" 114 | +# include "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\stdint.h" 115 | #endif 116 | 117 | #if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H 118 | diff -Naur grep-3.3-t1/lib/stdio.h grep-3.3/lib/stdio.h 119 | --- grep-3.3-t1/lib/stdio.h 2018-12-24 14:14:07.027886900 +0300 120 | +++ grep-3.3/lib/stdio.h 2018-12-24 12:24:17.729659700 +0300 121 | @@ -40,7 +40,7 @@ 122 | #define _GL_ALREADY_INCLUDING_STDIO_H 123 | 124 | /* The include_next requires a split double-inclusion guard. */ 125 | -#include "" 126 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\stdio.h" 127 | 128 | #undef _GL_ALREADY_INCLUDING_STDIO_H 129 | 130 | diff -Naur grep-3.3-t1/lib/stdlib.h grep-3.3/lib/stdlib.h 131 | --- grep-3.3-t1/lib/stdlib.h 2018-12-24 14:14:07.567887700 +0300 132 | +++ grep-3.3/lib/stdlib.h 2018-12-24 12:25:57.029798700 +0300 133 | @@ -25,7 +25,7 @@ 134 | /* Special invocation conventions inside some gnulib header files, 135 | and inside some glibc header files, respectively. */ 136 | 137 | -#include "" 138 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\stdlib.h" 139 | 140 | #else 141 | /* Normal invocation convention. */ 142 | @@ -33,7 +33,7 @@ 143 | #ifndef _GL_STDLIB_H 144 | 145 | /* The include_next requires a split double-inclusion guard. */ 146 | -#include "" 147 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\stdlib.h" 148 | 149 | #ifndef _GL_STDLIB_H 150 | #define _GL_STDLIB_H 151 | diff -Naur grep-3.3-t1/lib/string.h grep-3.3/lib/string.h 152 | --- grep-3.3-t1/lib/string.h 2018-12-24 14:14:08.077888400 +0300 153 | +++ grep-3.3/lib/string.h 2018-12-24 12:27:33.559933900 +0300 154 | @@ -38,7 +38,7 @@ 155 | #define _GL_ALREADY_INCLUDING_STRING_H 156 | 157 | /* The include_next requires a split double-inclusion guard. */ 158 | -#include "" 159 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\string.h" 160 | 161 | #undef _GL_ALREADY_INCLUDING_STRING_H 162 | 163 | diff -Naur grep-3.3-t1/lib/sys/stat.h grep-3.3/lib/sys/stat.h 164 | --- grep-3.3-t1/lib/sys/stat.h 2018-12-24 14:14:08.407888800 +0300 165 | +++ grep-3.3/lib/sys/stat.h 2018-12-24 12:29:53.760130200 +0300 166 | @@ -29,7 +29,7 @@ 167 | #if defined __need_system_sys_stat_h 168 | /* Special invocation convention. */ 169 | 170 | -#include "" 171 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\sys\stat.h" 172 | 173 | #else 174 | /* Normal invocation convention. */ 175 | @@ -44,7 +44,7 @@ 176 | #include 177 | 178 | /* The include_next requires a split double-inclusion guard. */ 179 | -#include "" 180 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\sys\stat.h" 181 | 182 | #ifndef _GL_SYS_STAT_H 183 | #define _GL_SYS_STAT_H 184 | diff -Naur grep-3.3-t1/lib/sys/types.h grep-3.3/lib/sys/types.h 185 | --- grep-3.3-t1/lib/sys/types.h 2018-12-24 14:14:08.547889000 +0300 186 | +++ grep-3.3/lib/sys/types.h 2018-12-24 12:25:10.509733600 +0300 187 | @@ -36,7 +36,7 @@ 188 | 189 | /* The include_next requires a split double-inclusion guard. */ 190 | # define _GL_INCLUDING_SYS_TYPES_H 191 | -#include "" 192 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\sys\types.h" 193 | # undef _GL_INCLUDING_SYS_TYPES_H 194 | 195 | #ifndef _GL_SYS_TYPES_H 196 | diff -Naur grep-3.3-t1/lib/time.h grep-3.3/lib/time.h 197 | --- grep-3.3-t1/lib/time.h 2018-12-24 14:14:08.817889400 +0300 198 | +++ grep-3.3/lib/time.h 2018-12-24 12:28:35.700020900 +0300 199 | @@ -32,13 +32,13 @@ 200 | && !defined __MINGW32__) \ 201 | || defined _GL_TIME_H) 202 | 203 | -# include "" 204 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\time.h" 205 | 206 | #else 207 | 208 | # define _GL_TIME_H 209 | 210 | -# include "" 211 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\time.h" 212 | 213 | /* NetBSD 5.0 mis-defines NULL. */ 214 | # include 215 | diff -Naur grep-3.3-t1/lib/wchar.h grep-3.3/lib/wchar.h 216 | --- grep-3.3-t1/lib/wchar.h 2018-12-24 14:14:10.477891700 +0300 217 | +++ grep-3.3/lib/wchar.h 2018-12-24 12:33:17.800415800 +0300 218 | @@ -84,7 +84,7 @@ 219 | Some builds of uClibc lack it. */ 220 | /* The include_next requires a split double-inclusion guard. */ 221 | #if 1 222 | -# include "" 223 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\wchar.h" 224 | #endif 225 | 226 | #undef _GL_ALREADY_INCLUDING_WCHAR_H 227 | diff -Naur grep-3.3-t1/lib/wctype.h grep-3.3/lib/wctype.h 228 | --- grep-3.3-t1/lib/wctype.h 2018-12-24 14:14:10.687892000 +0300 229 | +++ grep-3.3/lib/wctype.h 2018-12-24 12:33:41.190448600 +0300 230 | @@ -70,7 +70,7 @@ 231 | BeOS 5 has the functions but no . */ 232 | /* The include_next requires a split double-inclusion guard. */ 233 | #if 1 234 | -# include "" 235 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\wctype.h" 236 | #endif 237 | 238 | #ifndef _GL_WCTYPE_H 239 | -------------------------------------------------------------------------------- /archive/grep-3.3-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/grep-3.3-x64.exe -------------------------------------------------------------------------------- /archive/grep-3.6-build-VS19-x64.txt: -------------------------------------------------------------------------------- 1 | How to build native win64 grep.exe with Visual Studio 2019 and WDK10 2 | 3 | From cygwin or other unix shell: 4 | 5 | 1) get grep archive: wget https://ftp.gnu.org/gnu/grep/grep-3.6.tar.xz 6 | 2) unpack sed archive: tar xf grep-3.6.tar.xz 7 | 3) go to sed sources: cd grep-3.6 8 | 9 | 4) fix grep-3.6-build-VS19-x64.patch - change paths to locations of Visual Studio 2019 and WDK10 10 | 11 | sed -i '/Visual Studio/s@.:.*include@C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\include@' grep-3.6-build-VS19-x64.patch 12 | sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt@' grep-3.6-build-VS19-x64.patch 13 | 14 | 5) patch grep: patch -Np1 -i grep-3.6-build-VS19-x64.patch 15 | 6) run dos prompt: cmd.exe /c "start cmd.exe" 16 | 7) setup compiler: "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 17 | 8) do compile: make.bat 18 | 9) check build result: grep.exe --version 19 | -------------------------------------------------------------------------------- /archive/grep-3.6-build-patch-howto.txt: -------------------------------------------------------------------------------- 1 | Instructions how to build native grep.exe with Microsoft Visual Studio (or Build Tools for Visual Studio) from CYGWIN shell. 2 | 3 | While building, it is possible to save build log and create a patch - for compiling grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 4 | 5 | This is how grep-3.6-build-VS19-x64.patch was created. 6 | 7 | ;(grep-3.6-build-VS9-x86.patch was created analogously in Microsoft Visual Studio 2008 environment) 8 | 9 | 10 | From CYGWIN shell: 11 | 12 | 1) get archive: 13 | wget https://ftp.gnu.org/gnu/grep/grep-3.6.tar.xz 14 | 15 | 2) unpack archive: 16 | tar xf grep-3.6.tar.xz 17 | 18 | 3) go to grep sources: 19 | cd grep-3.6 20 | 21 | 4) fix sources for windows: 22 | patch -Np1 -i grep-3.6-src.patch 23 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.6-src.patch) 24 | 25 | ;5) to build with old non-c99 compiler (such as Microsoft Visual Studio 2008) apply one more patch: 26 | ; patch -Np1 -i grep-3.6-src-non-c99.patch 27 | ; (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.6-src-non-c99.patch) 28 | 29 | 6) now start dos prompt: 30 | cmd.exe /c "start cmd.exe" 31 | 32 | 7) setup compiler: 33 | "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 34 | (if Microsoft Build Tools for Visual Studio 2019 is installed in "C:\Program Files (x86)") 35 | 36 | ; --tip: for Visual Studio 2008: 37 | ; "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 38 | 39 | 8) run bash from dos prompt (with environment prepared for compiling with Microsoft Build Tools for Visual Studio 2019): 40 | bash 41 | 42 | 9) check that Gnu Make is installed in CYGWIN and it is working (Gnu Make is required for the build): 43 | make --version 44 | 45 | 10) configure grep: 46 | CFLAGS= CC=cl CPP="cl -E" LD=lib ARFLAGS="/OUT:" ./configure --enable-threads=windows --disable-dependency-tracking --disable-silent-rules --disable-nls gl_cv_sys_struct_lconv_ok=yes 47 | 48 | 11) configure script is not fully functional to create correct Makefiles - they are need to be fixed manually: 49 | sed -i 's/^SUBDIRS = .*/SUBDIRS = lib src/' ./Makefile 50 | sed -i 's/^RECURSIVE_TARGETS = /&gen /' ./Makefile 51 | sed -i 's/-c -o /-c -nologo -Fo/' ./lib/Makefile ./src/Makefile 52 | sed -i 's@^AR = .*@AR = lib /nologo@' ./lib/Makefile 53 | sed -i '/$(libgreputils_a_AR)/s/ lib/lib/' ./lib/Makefile 54 | sed -i 's%^am_libgreputils_a_OBJECTS = %&getpagesize.$(OBJEXT) stat-w32.$(OBJEXT) %' ./lib/Makefile 55 | sed -i 's%^LINK = .*%LINK = link /nologo /OUT:$@%' ./src/Makefile 56 | sed -i 's/^COLORIZE_SOURCE = .*/COLORIZE_SOURCE = colorize-w32.c/' ./lib/Makefile 57 | 58 | 12) add gen target: 59 | echo 'gen:' >> ./Makefile 60 | echo 'gen:' >> ./src/Makefile 61 | echo 'gen: $(BUILT_SOURCES)' >> ./lib/Makefile 62 | echo 'gen-am:' >> ./Makefile 63 | 64 | 13) execute Makefile to generate grep headers: 65 | make gen 66 | 67 | 14) some references to system header files are missing in generated headers - they need to be fixed manually. 68 | 69 | a) set paths to locations of Build Tools for Visual Studio 2019 and WDK10 in grep-3.6-win-headers.patch (assume it was copied to the current directory): 70 | for example, if Microsoft Build Tools for Visual Studio 2019 is installed in "C:\Program Files (x86)" and WDK10 installed in "C:\Program Files (x86)" 71 | 72 | sed -i '/Visual Studio/s@.:.*include@C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\include@' ./grep-3.6-win-headers.patch 73 | sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt@' ./grep-3.6-win-headers.patch 74 | 75 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.6-win-headers.patch) 76 | 77 | ; --tip: for Visual Studio 2008: 78 | ; sed -i '/Visual Studio/s@.:.*include@C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include@' ./grep-3.6-win-headers.patch 79 | ; sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include@' ./grep-3.6-win-headers.patch 80 | 81 | b) now patch the previously generated headers with updated patch-file: 82 | patch -Np1 -i ./grep-3.6-win-headers.patch 83 | 84 | c) header file lib/unistd.h is generated erroneously, fix it: 85 | patch -Np1 -i grep-3.6-unistd.patch 86 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.6-unistd.patch) 87 | 88 | d) fix build for the native Windows platform: 89 | patch -Np1 -i grep-3.6-mbtowc-lock.patch 90 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.6-mbtowc-lock.patch) 91 | 92 | 15) do compile grep: 93 | make > make.bat 94 | 95 | 16) check build result: 96 | ./src/grep.exe --version 97 | 98 | (should print grep version, e.g.: (GNU grep) 3.6) 99 | 100 | compilation should be ok, native (unoptimized) ./grep/grep.exe should be created. 101 | 102 | 103 | Now it is possible to create a patch file - for compiling optimized grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 104 | 105 | 1) create directory for unpatched grep: 106 | mkdir ../orig 107 | 108 | 2) unpack grep: 109 | tar xf ../grep-3.6.tar.xz -C ../orig/ 110 | 111 | 3) diff current directory with original just unpacked grep-3.6.tar.xz in '../orig' directory 112 | diff -rql . ../orig/grep-3.6 113 | 114 | 4) remove unneeded built files in the current directory (object files, libs, etc...) 115 | 116 | rm -rv \ 117 | ./Makefile \ 118 | ./stamp-h1 \ 119 | ./grep-3.6-win-headers.patch \ 120 | ./src/*.obj \ 121 | ./lib/*.obj \ 122 | ./lib/glthread/*.obj \ 123 | ./lib/glthread/.deps \ 124 | ./lib/glthread/.dirstamp \ 125 | ./lib/unistr/*.obj \ 126 | ./lib/unistr/.deps \ 127 | ./lib/unistr/.dirstamp \ 128 | ./lib/uniwidth/*.obj \ 129 | ./lib/uniwidth/.deps \ 130 | ./lib/uniwidth/.dirstamp \ 131 | ./lib/libgreputils.a \ 132 | ./src/grep.exe \ 133 | ./src/egrep \ 134 | ./src/fgrep \ 135 | ./src/Makefile \ 136 | ./lib/Makefile \ 137 | ./doc/Makefile \ 138 | ./tests/Makefile \ 139 | ./gnulib-tests/Makefile \ 140 | ./po/Makefile \ 141 | ./po/Makefile.in \ 142 | ./po/POTFILES \ 143 | ./config.log \ 144 | ./config.status 145 | 146 | 5) after this, diff should print something like: 147 | 148 | diff -rql . ../orig/grep-3.6 149 | Only in .: config.h 150 | Only in ./lib: alloca.h 151 | Only in ./lib: colorize.c 152 | Only in ./lib: configmake.h 153 | Only in ./lib: ctype.h 154 | Only in ./lib: dirent.h 155 | Only in ./lib: errno.h 156 | Only in ./lib: fcntl.h 157 | Only in ./lib: fnmatch.h 158 | Files ./lib/fts.c and ../orig/grep-3.6/lib/fts.c differ 159 | Only in ./lib: getopt-cdefs.h 160 | Only in ./lib: getopt.h 161 | Only in ./lib: inttypes.h 162 | Only in ./lib: langinfo.h 163 | Only in ./lib: limits.h 164 | Only in ./lib: locale.h 165 | Files ./lib/mbtowc-lock.c and ../orig/grep-3.6/lib/mbtowc-lock.c differ 166 | Files ./lib/mbtowc-lock.h and ../orig/grep-3.6/lib/mbtowc-lock.h differ 167 | Only in ./lib: signal.h 168 | Only in ./lib: stdalign.h 169 | Only in ./lib: stddef.h 170 | Only in ./lib: stdint.h 171 | Only in ./lib: stdio.h 172 | Only in ./lib: stdlib.h 173 | Only in ./lib: string.h 174 | Only in ./lib: sys 175 | Only in ./lib: time.h 176 | Only in ./lib: unistd.h 177 | Only in ./lib: unistr.h 178 | Only in ./lib: unitypes.h 179 | Only in ./lib: uniwidth.h 180 | Only in ./lib: wchar.h 181 | Only in ./lib: wctype.h 182 | Only in .: make.bat 183 | Files ./src/grep.c and ../orig/grep-3.6/src/grep.c differ 184 | 185 | ;If patch grep-3.6-src-non-c99.patch was applied, diff will print additional differences: 186 | ; 187 | 188 | 6) edit make.bat 189 | 190 | cp make.bat make.bat.old 191 | sed -i -n '/^cl /p;/^lib /p;/^link /p' make.bat 192 | sed -i '/.nologo /s@/@\\@g' make.bat 193 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@-Fo@&lib\\@' make.bat 194 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@.cygpath -w .@lib\\@' make.bat 195 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib -c/s@-Fo@&src\\@' make.bat 196 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib -c/s@.cygpath -w .@src\\@' make.bat 197 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. -I..\\lib -I..\\lib .* -c@/I. /I.\\lib /I.\\src -c@' make.bat 198 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. .* -c@/I. /I.\\lib -c@' make.bat 199 | sed -i 's@-c -nologo -Fo@/Ox /GF /Gy /GS- /GL /EHsc /DHAVE_CONFIG_H /c /nologo /Fo@' make.bat 200 | sed -i 's@.`@@' make.bat 201 | sed -i '/^lib/s@ .nologo .OUT:@@;/^lib/s@ *$@@g;/^lib/s@ @ .\\lib\\@g;s@^lib@lib /LTCG /nologo /OUT:@' make.bat 202 | sed -i '/^link/s@..\\lib\\libgreputils.a@@g' make.bat 203 | sed -i '/^link/s@ .nologo .OUT:@@;/^link/s@ *$@@g;/^link/s@ @ .\\src\\@g' make.bat 204 | sed -i 's@^link@link /LTCG /nologo .\\libgreputils.a /OUT:@' make.bat 205 | rm make.bat.old 206 | 207 | 7) finally, create a patch: 208 | diff -Naur ../orig/grep-3.6 . > ../grep-3.6-build-VS19-x64.patch 209 | 210 | ; or, for Visual Studio 2008: 211 | ; diff -Naur ../orig/grep-3.6 . > ../grep-3.6-build-VS9-x86.patch 212 | -------------------------------------------------------------------------------- /archive/grep-3.6-mbtowc-lock.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.6/lib/mbtowc-lock.h grep-3.6-3/lib/mbtowc-lock.h 2 | --- grep-3.6/lib/mbtowc-lock.h 2020-08-23 12:36:33.000000000 +0300 3 | +++ grep-3.6-3/lib/mbtowc-lock.h 2021-06-30 18:09:59.893281700 +0300 4 | @@ -34,7 +34,7 @@ 5 | 6 | #if defined _WIN32 && !defined __CYGWIN__ 7 | 8 | -extern __declspec(dllimport) CRITICAL_SECTION *gl_get_mbtowc_lock (void); 9 | +extern /*__declspec(dllimport)*/ CRITICAL_SECTION *gl_get_mbtowc_lock (void); 10 | 11 | static int 12 | mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m) 13 | --- grep-3.6-3/lib/mbtowc-lock.c 2020-08-23 12:36:33.000000000 +0300 14 | +++ grep-3.6/lib/mbtowc-lock.c 2021-06-30 19:41:50.612081700 +0300 15 | @@ -59,7 +59,7 @@ 16 | because the latter is not guaranteed to be a stable ABI in the future. */ 17 | 18 | /* Make sure the function gets exported from DLLs. */ 19 | -DLL_EXPORTED CRITICAL_SECTION *gl_get_mbtowc_lock (void); 20 | +/*DLL_EXPORTED*/ CRITICAL_SECTION *gl_get_mbtowc_lock (void); 21 | 22 | static glwthread_initguard_t guard = GLWTHREAD_INITGUARD_INIT; 23 | static CRITICAL_SECTION lock; 24 | -------------------------------------------------------------------------------- /archive/grep-3.6-src.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.6/lib/fts.c grep-3.6-3/lib/fts.c 2 | --- grep-3.6/lib/fts.c 2020-08-23 12:36:33.000000000 +0300 3 | +++ grep-3.6-3/lib/fts.c 2021-06-30 17:52:35.486185800 +0300 4 | @@ -121,6 +121,9 @@ 5 | #ifndef S_IFSOCK 6 | # define S_IFSOCK 0 7 | #endif 8 | +#ifndef S_IFBLK 9 | +# define S_IFBLK 0 10 | +#endif 11 | 12 | enum 13 | { 14 | @@ -1835,7 +1838,7 @@ 15 | FTSENT *dummy; 16 | int (*compare) (void const *, void const *) = 17 | ((sizeof &dummy == sizeof (void *) 18 | - && (long int) &dummy == (long int) (void *) &dummy) 19 | + && (long long int) &dummy == (long long int) (void *) &dummy) 20 | ? (int (*) (void const *, void const *)) sp->fts_compar 21 | : fts_compar); 22 | 23 | --- grep-3.6-3/src/grep.c 2020-11-03 23:37:02.000000000 +0300 24 | +++ grep-3.6/src/grep.c 2021-06-30 19:15:55.115925300 +0300 25 | @@ -2831,6 +2831,7 @@ 26 | (char *) NULL); 27 | puts (_("Written by Mike Haertel and others; see\n" 28 | ".")); 29 | + puts (_("Patched by: Michael M. Builov .\n")); 30 | return EXIT_SUCCESS; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /archive/grep-3.6-unistd.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.6/lib/unistd.h grep-3.6-3/lib/unistd.h 2 | --- grep-3.6/lib/unistd.h 2021-06-30 18:40:50.936409700 +0300 3 | +++ grep-3.6-3/lib/unistd.h 2021-06-30 17:48:29.007217900 +0300 4 | @@ -1513,7 +1513,7 @@ 5 | #endif 6 | 7 | 8 | -#if 1 9 | +#if 0 10 | # if 0 11 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 12 | # define getpagesize rpl_getpagesize 13 | @@ -1598,6 +1598,7 @@ 14 | "use gnulib module getpagesize for portability"); 15 | # endif 16 | #endif 17 | +int getpagesize(void); 18 | 19 | 20 | #if 0 21 | -------------------------------------------------------------------------------- /archive/grep-3.6-win-headers.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.6/lib/ctype.h grep-3.6-3/lib/ctype.h 2 | --- grep-3.6/lib/ctype.h 2021-06-30 18:40:38.566791200 +0300 3 | +++ grep-3.6-3/lib/ctype.h 2021-06-30 17:42:17.274854200 +0300 4 | @@ -32,7 +32,7 @@ 5 | 6 | /* Include the original . */ 7 | /* The include_next requires a split double-inclusion guard. */ 8 | -#include "" 9 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\ctype.h" 10 | 11 | #ifndef _GL_CTYPE_H 12 | #define _GL_CTYPE_H 13 | diff -Naur grep-3.6/lib/errno.h grep-3.6-3/lib/errno.h 14 | --- grep-3.6/lib/errno.h 2021-06-30 18:40:39.469665900 +0300 15 | +++ grep-3.6-3/lib/errno.h 2021-06-30 17:42:35.253822900 +0300 16 | @@ -24,7 +24,7 @@ 17 | 18 | 19 | /* The include_next requires a split double-inclusion guard. */ 20 | -#include "" 21 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\errno.h" 22 | 23 | #ifndef _GL_ERRNO_H 24 | #define _GL_ERRNO_H 25 | diff -Naur grep-3.6/lib/fcntl.h grep-3.6-3/lib/fcntl.h 26 | --- grep-3.6/lib/fcntl.h 2021-06-30 18:40:39.848748300 +0300 27 | +++ grep-3.6-3/lib/fcntl.h 2021-06-30 17:42:55.903979900 +0300 28 | @@ -38,7 +38,7 @@ 29 | #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))) 30 | # include 31 | #endif 32 | -#include "" 33 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\fcntl.h" 34 | 35 | /* Native Windows platforms declare open(), creat() in . */ 36 | #if (0 || 1 || defined GNULIB_POSIXCHECK) \ 37 | @@ -64,7 +64,7 @@ 38 | # include 39 | #endif 40 | /* The include_next requires a split double-inclusion guard. */ 41 | -#include "" 42 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\fcntl.h" 43 | 44 | /* Native Windows platforms declare open(), creat() in . */ 45 | #if (0 || 1 || defined GNULIB_POSIXCHECK) \ 46 | diff -Naur grep-3.6/lib/inttypes.h grep-3.6-3/lib/inttypes.h 47 | --- grep-3.6/lib/inttypes.h 2021-06-30 18:40:41.137069000 +0300 48 | +++ grep-3.6-3/lib/inttypes.h 2021-06-30 17:53:19.688332100 +0300 49 | @@ -38,7 +38,7 @@ 50 | # define __STDC_FORMAT_MACROS 1 51 | # endif 52 | 53 | -# include "" 54 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\inttypes.h" 55 | 56 | # define _GL_FINISHED_INCLUDING_SYSTEM_INTTYPES_H 57 | # endif 58 | diff -Naur grep-3.6/lib/limits.h grep-3.6-3/lib/limits.h 59 | --- grep-3.6/lib/limits.h 2021-06-30 18:40:41.654230000 +0300 60 | +++ grep-3.6-3/lib/limits.h 2021-06-30 17:53:44.460184300 +0300 61 | @@ -38,7 +38,7 @@ 62 | # define _GL_ALREADY_INCLUDING_LIMITS_H 63 | 64 | /* The include_next requires a split double-inclusion guard. */ 65 | -# include "" 66 | +# include "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include\limits.h" 67 | 68 | # undef _GL_ALREADY_INCLUDING_LIMITS_H 69 | 70 | diff -Naur grep-3.6/lib/locale.h grep-3.6-3/lib/locale.h 71 | --- grep-3.6/lib/locale.h 2021-06-30 18:40:42.362942200 +0300 72 | +++ grep-3.6-3/lib/locale.h 2021-06-30 17:54:26.561627200 +0300 73 | @@ -38,7 +38,7 @@ 74 | #define _GL_ALREADY_INCLUDING_LOCALE_H 75 | 76 | /* The include_next requires a split double-inclusion guard. */ 77 | -#include "" 78 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\locale.h" 79 | 80 | #undef _GL_ALREADY_INCLUDING_LOCALE_H 81 | 82 | diff -Naur grep-3.6/lib/signal.h grep-3.6-3/lib/signal.h 83 | --- grep-3.6/lib/signal.h 2021-06-30 18:40:42.795425800 +0300 84 | +++ grep-3.6-3/lib/signal.h 2021-06-30 17:58:04.360409700 +0300 85 | @@ -49,7 +49,7 @@ 86 | #include 87 | 88 | /* The include_next requires a split double-inclusion guard. */ 89 | -#include "" 90 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\signal.h" 91 | 92 | #undef _GL_ALREADY_INCLUDING_SIGNAL_H 93 | 94 | diff -Naur grep-3.6/lib/stddef.h grep-3.6-3/lib/stddef.h 95 | --- grep-3.6/lib/stddef.h 2021-06-30 18:40:43.312526500 +0300 96 | +++ grep-3.6-3/lib/stddef.h 2021-06-30 17:54:41.359903800 +0300 97 | @@ -52,7 +52,7 @@ 98 | 99 | /* The include_next requires a split double-inclusion guard. */ 100 | 101 | -# include "" 102 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stddef.h" 103 | 104 | /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ 105 | # if (0 \ 106 | diff -Naur grep-3.6/lib/stdint.h grep-3.6-3/lib/stdint.h 107 | --- grep-3.6/lib/stdint.h 2021-06-30 18:40:43.814042200 +0300 108 | +++ grep-3.6-3/lib/stdint.h 2021-06-30 17:54:51.047193400 +0300 109 | @@ -74,7 +74,7 @@ 110 | in would reinclude us, skipping our contents because 111 | _GL_STDINT_H is defined. 112 | The include_next requires a split double-inclusion guard. */ 113 | -# include "" 114 | +# include "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include\stdint.h" 115 | #endif 116 | 117 | #if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H 118 | diff -Naur grep-3.6/lib/stdio.h grep-3.6-3/lib/stdio.h 119 | --- grep-3.6/lib/stdio.h 2021-06-30 18:40:45.118020400 +0300 120 | +++ grep-3.6-3/lib/stdio.h 2021-06-30 17:55:11.295377400 +0300 121 | @@ -30,7 +30,7 @@ 122 | In this situation, the functions are not yet declared, therefore we cannot 123 | provide the C++ aliases. */ 124 | 125 | -#include "" 126 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdio.h" 127 | 128 | #else 129 | /* Normal invocation convention. */ 130 | @@ -40,7 +40,7 @@ 131 | #define _GL_ALREADY_INCLUDING_STDIO_H 132 | 133 | /* The include_next requires a split double-inclusion guard. */ 134 | -#include "" 135 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdio.h" 136 | 137 | #undef _GL_ALREADY_INCLUDING_STDIO_H 138 | 139 | diff -Naur grep-3.6/lib/stdlib.h grep-3.6-3/lib/stdlib.h 140 | --- grep-3.6/lib/stdlib.h 2021-06-30 18:40:46.321695400 +0300 141 | +++ grep-3.6-3/lib/stdlib.h 2021-06-30 17:55:34.847370600 +0300 142 | @@ -25,7 +25,7 @@ 143 | /* Special invocation conventions inside some gnulib header files, 144 | and inside some glibc header files, respectively. */ 145 | 146 | -#include "" 147 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdlib.h" 148 | 149 | #else 150 | /* Normal invocation convention. */ 151 | @@ -33,7 +33,7 @@ 152 | #ifndef _GL_STDLIB_H 153 | 154 | /* The include_next requires a split double-inclusion guard. */ 155 | -#include "" 156 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdlib.h" 157 | 158 | #ifndef _GL_STDLIB_H 159 | #define _GL_STDLIB_H 160 | diff -Naur grep-3.6/lib/string.h grep-3.6-3/lib/string.h 161 | --- grep-3.6/lib/string.h 2021-06-30 18:40:46.823353300 +0300 162 | +++ grep-3.6-3/lib/string.h 2021-06-30 17:55:48.346601400 +0300 163 | @@ -38,7 +38,7 @@ 164 | #define _GL_ALREADY_INCLUDING_STRING_H 165 | 166 | /* The include_next requires a split double-inclusion guard. */ 167 | -#include "" 168 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\string.h" 169 | 170 | #undef _GL_ALREADY_INCLUDING_STRING_H 171 | 172 | diff -Naur grep-3.6/lib/sys/stat.h grep-3.6-3/lib/sys/stat.h 173 | --- grep-3.6/lib/sys/stat.h 2021-06-30 18:40:47.895575200 +0300 174 | +++ grep-3.6-3/lib/sys/stat.h 2021-06-30 17:57:43.514441500 +0300 175 | @@ -29,7 +29,7 @@ 176 | #if defined __need_system_sys_stat_h 177 | /* Special invocation convention. */ 178 | 179 | -#include "" 180 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\sys\stat.h" 181 | 182 | #else 183 | /* Normal invocation convention. */ 184 | @@ -44,7 +44,7 @@ 185 | #include 186 | 187 | /* The include_next requires a split double-inclusion guard. */ 188 | -#include "" 189 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\sys\stat.h" 190 | 191 | #ifndef _GL_SYS_STAT_H 192 | #define _GL_SYS_STAT_H 193 | diff -Naur grep-3.6/lib/sys/types.h grep-3.6-3/lib/sys/types.h 194 | --- grep-3.6/lib/sys/types.h 2021-06-30 18:40:48.196470800 +0300 195 | +++ grep-3.6-3/lib/sys/types.h 2021-06-30 17:57:19.104768200 +0300 196 | @@ -36,7 +36,7 @@ 197 | 198 | /* The include_next requires a split double-inclusion guard. */ 199 | # define _GL_INCLUDING_SYS_TYPES_H 200 | -#include "" 201 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\sys\types.h" 202 | # undef _GL_INCLUDING_SYS_TYPES_H 203 | 204 | #ifndef _GL_SYS_TYPES_H 205 | diff -Naur grep-3.6/lib/time.h grep-3.6-3/lib/time.h 206 | --- grep-3.6/lib/time.h 2021-06-30 18:40:49.030332500 +0300 207 | +++ grep-3.6-3/lib/time.h 2021-06-30 17:56:06.432227300 +0300 208 | @@ -32,7 +32,7 @@ 209 | && !defined __MINGW32__) \ 210 | || defined _GL_TIME_H) 211 | 212 | -# include "" 213 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\time.h" 214 | 215 | #else 216 | 217 | @@ -44,7 +44,7 @@ 218 | # include 219 | # endif 220 | 221 | -# include "" 222 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\time.h" 223 | 224 | /* NetBSD 5.0 mis-defines NULL. */ 225 | # include 226 | diff -Naur grep-3.6/lib/wchar.h grep-3.6-3/lib/wchar.h 227 | --- grep-3.6/lib/wchar.h 2021-06-30 18:40:53.143267900 +0300 228 | +++ grep-3.6-3/lib/wchar.h 2021-06-30 17:56:32.289845000 +0300 229 | @@ -85,7 +85,7 @@ 230 | Some builds of uClibc lack it. */ 231 | /* The include_next requires a split double-inclusion guard. */ 232 | #if 1 233 | -# include "" 234 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\wchar.h" 235 | #endif 236 | 237 | #undef _GL_ALREADY_INCLUDING_WCHAR_H 238 | diff -Naur grep-3.6/lib/wctype.h grep-3.6-3/lib/wctype.h 239 | --- grep-3.6/lib/wctype.h 2021-06-30 18:40:53.444198100 +0300 240 | +++ grep-3.6-3/lib/wctype.h 2021-06-30 17:56:48.159662700 +0300 241 | @@ -70,7 +70,7 @@ 242 | BeOS 5 has the functions but no . */ 243 | /* The include_next requires a split double-inclusion guard. */ 244 | #if 1 245 | -# include "" 246 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\wctype.h" 247 | #endif 248 | 249 | #ifndef _GL_WCTYPE_H 250 | -------------------------------------------------------------------------------- /archive/grep-3.6-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/grep-3.6-x64.exe -------------------------------------------------------------------------------- /archive/grep-3.7-build-VS22-x64.txt: -------------------------------------------------------------------------------- 1 | How to build native win64 grep.exe with Visual Studio 2022 and WDK10 2 | 3 | From cygwin or other unix shell: 4 | 5 | 1) get grep archive: wget https://ftp.gnu.org/gnu/grep/grep-3.7.tar.xz 6 | 2) unpack sed archive: tar xf grep-3.7.tar.xz 7 | 3) go to sed sources: cd grep-3.7 8 | 9 | 4) fix grep-3.7-build-VS22-x64.patch - change paths to locations of Visual Studio 2019 and WDK10 10 | 11 | sed -i '/Visual Studio/s@.:.*include@C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.30.30705\\include@' grep-3.7-build-VS22-x64.patch 12 | sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22000.0\\ucrt@' grep-3.7-build-VS22-x64.patch 13 | 14 | 5) patch grep: patch -Np1 -i grep-3.7-build-VS22-x64.patch 15 | 6) run dos prompt: cmd.exe /c "start cmd.exe" 16 | 7) setup compiler: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 17 | 8) do compile: make.bat 18 | 9) check build result: grep.exe --version 19 | -------------------------------------------------------------------------------- /archive/grep-3.7-build-VS9-x86.txt: -------------------------------------------------------------------------------- 1 | How to build native win32 grep.exe with Visual Studio 2008 2 | 3 | From cygwin or other unix shell: 4 | 5 | 1) get grep archive: wget https://ftp.gnu.org/gnu/grep/grep-3.7.tar.xz 6 | 2) unpack sed archive: tar xf grep-3.7.tar.xz 7 | 3) go to sed sources: cd grep-3.7 8 | 9 | 4) fix grep-3.7-build-VS9-x86.patch - change paths to location of Visual Studio 2008 10 | 11 | sed -i '/Visual Studio/s@.:.*include@C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include@' ./grep-3.7-build-VS9-x86.patch 12 | 13 | 5) patch grep: patch -Np1 -i grep-3.7-build-VS9-x86.patch 14 | 6) run dos prompt: cmd.exe /c "start cmd.exe" 15 | 7) setup compiler: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 16 | 8) do compile: make.bat 17 | 9) check build result: grep.exe --version 18 | -------------------------------------------------------------------------------- /archive/grep-3.7-build-patch-howto.txt: -------------------------------------------------------------------------------- 1 | Instructions how to build native grep.exe with Microsoft Visual Studio (or Build Tools for Visual Studio) from CYGWIN shell. 2 | 3 | While building, it is possible to save build log and create a patch - for compiling grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 4 | 5 | This is how grep-3.7-build-VS22-x64.patch was created. 6 | 7 | (grep-3.7-build-VS9-x86.patch was created analogously in Microsoft Visual Studio 2008 environment) 8 | 9 | 10 | From CYGWIN shell: 11 | 12 | 1) get archive: 13 | wget https://ftp.gnu.org/gnu/grep/grep-3.7.tar.xz 14 | 15 | 2) unpack archive: 16 | tar xf grep-3.7.tar.xz 17 | 18 | 3) go to grep sources: 19 | cd grep-3.7 20 | 21 | 4) fix sources for windows: 22 | patch -Np1 -i grep-3.7-src.patch 23 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.7-src.patch) 24 | 25 | 5) to build with old non-c99 compiler (such as Microsoft Visual Studio 2008) apply one more patch: 26 | patch -Np1 -i grep-3.7-src-non-c99.patch 27 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.7-src-non-c99.patch) 28 | 29 | 6) now start dos prompt: 30 | cmd.exe /c "start cmd.exe" 31 | 32 | 7) setup compiler: 33 | "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 34 | (if Microsoft Build Tools for Visual Studio 2022 is installed in "C:\Program Files (x86)") 35 | 36 | --tip: for Visual Studio 2008: 37 | "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 38 | 39 | 8) run bash from dos prompt (with environment prepared for compiling with Microsoft Build Tools for Visual Studio 2022): 40 | bash 41 | 42 | 9) check that Gnu Make is installed in CYGWIN and it is working (Gnu Make is required for the build): 43 | make --version 44 | 45 | 10) configure grep: 46 | CFLAGS= CC=cl CPP="cl -E" LD=lib ARFLAGS="/OUT:" ./configure --enable-threads=windows --disable-dependency-tracking --disable-silent-rules --disable-nls gl_cv_sys_struct_lconv_ok=yes 47 | 48 | --tip: for Visual Studio 2008: 49 | CFLAGS= CC="cl -D_WIN32_WINNT=0x501" CPP="cl -D_WIN32_WINNT=0x501 -E" LD=lib ARFLAGS="/OUT:" ./configure --enable-threads=windows --disable-dependency-tracking --disable-silent-rules --disable-nls gl_cv_sys_struct_lconv_ok=yes 50 | 51 | 11) configure script is not fully functional to create correct Makefiles - they are need to be fixed manually: 52 | sed -i 's/^SUBDIRS = .*/SUBDIRS = lib src/' ./Makefile 53 | sed -i 's/^RECURSIVE_TARGETS = /&gen /' ./Makefile 54 | sed -i 's/-c -o /-c -nologo -Fo/' ./lib/Makefile ./src/Makefile 55 | sed -i 's@^AR = .*@AR = lib /nologo@' ./lib/Makefile 56 | sed -i '/$(libgreputils_a_AR)/s/ lib/lib/' ./lib/Makefile 57 | sed -i 's%^am_libgreputils_a_OBJECTS = %&getpagesize.$(OBJEXT) stat-w32.$(OBJEXT) %' ./lib/Makefile 58 | sed -i 's%^LINK = .*%LINK = link /nologo /OUT:$@%' ./src/Makefile 59 | sed -i 's/^COLORIZE_SOURCE = .*/COLORIZE_SOURCE = colorize-w32.c/' ./lib/Makefile 60 | 61 | 12) if building with Microsoft Visual Studio 2008, to avoid linker error, add libcpmt.lib to the link command: 62 | sed -i 's%^LINK = .*%& libcpmt.lib%' ./src/Makefile 63 | 64 | 13) add gen target: 65 | echo 'gen:' >> ./Makefile 66 | echo 'gen:' >> ./src/Makefile 67 | echo 'gen: $(BUILT_SOURCES)' >> ./lib/Makefile 68 | echo 'gen-am:' >> ./Makefile 69 | 70 | 14) execute Makefile to generate grep headers: 71 | make gen 72 | 73 | 15) some references to system header files are missing in generated headers - they need to be fixed manually. 74 | 75 | a) set paths to locations of Build Tools for Visual Studio 2022 and WDK10 in grep-3.6-win-headers.patch (assume it was copied to the current directory): 76 | for example, if Microsoft Build Tools for Visual Studio 2022 is installed in "C:\Program Files (x86)" and WDK10 installed in "C:\Program Files (x86)" 77 | 78 | sed -i '/Visual Studio/s@.:.*include@C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.30.30705\\include@' ./grep-3.6-win-headers.patch 79 | sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22000.0\\ucrt@' ./grep-3.6-win-headers.patch 80 | 81 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.6-win-headers.patch) 82 | 83 | --tip: for Visual Studio 2008: 84 | sed -i '/Visual Studio/s@.:.*include@C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include@' ./grep-3.6-win-headers.patch 85 | sed -i '/Windows Kits/s@.:.*ucrt@C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\include@' ./grep-3.6-win-headers.patch 86 | 87 | b) now patch the previously generated headers with updated patch-file: 88 | patch -Np1 -i ./grep-3.6-win-headers.patch 89 | 90 | --note: for Visual Studio 2008, patching of "lib/inttypes.h" and "lib/stdint.h" is not needed, so next errors may be safely ignored: 91 | 1 out of 1 hunk FAILED -- saving rejects to file lib/inttypes.h.rej 92 | 1 out of 1 hunk FAILED -- saving rejects to file lib/stdint.h.rej 93 | 94 | c) header file lib/unistd.h is generated erroneously, fix it: 95 | patch -Np1 -i grep-3.6-unistd.patch 96 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.6-unistd.patch) 97 | 98 | d) fix build for the native Windows platform: 99 | patch -Np1 -i grep-3.6-mbtowc-lock.patch 100 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.6-mbtowc-lock.patch) 101 | 102 | 16) do compile grep: 103 | make > make.bat 104 | 105 | 17) check build result: 106 | ./src/grep.exe --version 107 | 108 | (should print grep version, e.g.: (GNU grep) 3.7) 109 | 110 | compilation should be ok, native (unoptimized) ./grep/grep.exe should be created. 111 | 112 | 113 | Now it is possible to create a patch file - for compiling optimized grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 114 | 115 | 1) create directory for unpatched grep: 116 | mkdir ../orig 117 | 118 | 2) unpack grep: 119 | tar xf ../grep-3.7.tar.xz -C ../orig/ 120 | 121 | 3) diff current directory with original just unpacked grep-3.7.tar.xz in '../orig' directory 122 | diff -rql . ../orig/grep-3.7 123 | 124 | 4) remove unneeded built files in the current directory (object files, libs, etc...) 125 | 126 | rm -rv \ 127 | ./Makefile \ 128 | ./stamp-h1 \ 129 | ./grep-3.6-win-headers.patch \ 130 | ./src/*.obj \ 131 | ./lib/*.obj \ 132 | ./lib/*.h.orig \ 133 | ./lib/glthread/*.obj \ 134 | ./lib/glthread/.deps \ 135 | ./lib/glthread/.dirstamp \ 136 | ./lib/unistr/*.obj \ 137 | ./lib/unistr/.deps \ 138 | ./lib/unistr/.dirstamp \ 139 | ./lib/uniwidth/*.obj \ 140 | ./lib/uniwidth/.deps \ 141 | ./lib/uniwidth/.dirstamp \ 142 | ./lib/malloc/*.obj \ 143 | ./lib/malloc/.deps \ 144 | ./lib/malloc/.dirstamp \ 145 | ./lib/libgreputils.a \ 146 | ./src/grep.exe \ 147 | ./src/egrep \ 148 | ./src/fgrep \ 149 | ./src/Makefile \ 150 | ./lib/Makefile \ 151 | ./doc/Makefile \ 152 | ./tests/Makefile \ 153 | ./gnulib-tests/Makefile \ 154 | ./po/Makefile \ 155 | ./po/Makefile.in \ 156 | ./po/POTFILES \ 157 | ./config.log \ 158 | ./config.status 159 | 160 | If building with Microsoft Visual Studio 2008, remove patch-rejected files: 161 | rm -v \ 162 | ./lib/inttypes.h.rej \ 163 | ./lib/stdint.h.rej 164 | 165 | 5) after this, diff should print something like: 166 | 167 | diff -rql . ../orig/grep-3.7 168 | Only in .: config.h 169 | Only in ./lib: alloca.h 170 | * Files ./lib/calloc.c and ../orig/grep-3.7/lib/calloc.c differ 171 | Only in ./lib: colorize.c 172 | Only in ./lib: configmake.h 173 | Only in ./lib: ctype.h 174 | * Files ./lib/dfa.c and ../orig/grep-3.7/lib/dfa.c differ 175 | Only in ./lib: dirent.h 176 | Only in ./lib: errno.h 177 | * Files ./lib/exclude.c and ../orig/grep-3.7/lib/exclude.c differ 178 | Only in ./lib: fcntl.h 179 | * Files ./lib/filenamecat-lgpl.c and ../orig/grep-3.7/lib/filenamecat-lgpl.c differ 180 | * Files ./lib/fnmatch.c and ../orig/grep-3.7/lib/fnmatch.c differ 181 | Only in ./lib: fnmatch.h 182 | * Files ./lib/fnmatch_loop.c and ../orig/grep-3.7/lib/fnmatch_loop.c differ 183 | * Files ./lib/fstat.c and ../orig/grep-3.7/lib/fstat.c differ 184 | Files ./lib/fts.c and ../orig/grep-3.7/lib/fts.c differ 185 | Only in ./lib: getopt-cdefs.h 186 | Only in ./lib: getopt.h 187 | Only in ./lib: inttypes.h 188 | Only in ./lib: langinfo.h 189 | Only in ./lib: limits.h 190 | Only in ./lib: locale.h 191 | * Files ./lib/localeinfo.c and ../orig/grep-3.7/lib/localeinfo.c differ 192 | Only in ./lib/malloc: dynarray-skeleton.gl.h 193 | Only in ./lib/malloc: dynarray.gl.h 194 | * Files ./lib/malloc/dynarray_emplace_enlarge.c and ../orig/grep-3.7/lib/malloc/dynarray_emplace_enlarge.c differ 195 | * Files ./lib/malloc/dynarray_finalize.c and ../orig/grep-3.7/lib/malloc/dynarray_finalize.c differ 196 | * Files ./lib/malloc/dynarray_resize.c and ../orig/grep-3.7/lib/malloc/dynarray_resize.c differ 197 | * Files ./lib/malloc/dynarray_resize_clear.c and ../orig/grep-3.7/lib/malloc/dynarray_resize_clear.c differ 198 | * Files ./lib/malloc.c and ../orig/grep-3.7/lib/malloc.c differ 199 | * Files ./lib/malloca.c and ../orig/grep-3.7/lib/malloca.c differ 200 | Files ./lib/mbtowc-lock.c and ../orig/grep-3.7/lib/mbtowc-lock.c differ 201 | Files ./lib/mbtowc-lock.h and ../orig/grep-3.7/lib/mbtowc-lock.h differ 202 | * Files ./lib/opendirat.c and ../orig/grep-3.7/lib/opendirat.c differ 203 | * Files ./lib/realloc.c and ../orig/grep-3.7/lib/realloc.c differ 204 | * Files ./lib/regcomp.c and ../orig/grep-3.7/lib/regcomp.c differ 205 | * Files ./lib/regexec.c and ../orig/grep-3.7/lib/regexec.c differ 206 | Only in ./lib: signal.h 207 | Only in ./lib: sigsegv.h 208 | * Files ./lib/stat-w32.c and ../orig/grep-3.7/lib/stat-w32.c differ 209 | Only in ./lib: stdalign.h 210 | ? Only in ./lib: stdbool.h 211 | Only in ./lib: stddef.h 212 | Only in ./lib: stdint.h 213 | Only in ./lib: stdio.h 214 | Only in ./lib: stdlib.h 215 | Only in ./lib: string.h 216 | Only in ./lib: sys 217 | Only in ./lib: time.h 218 | Only in ./lib: unistd.h 219 | Only in ./lib: unistr.h 220 | Only in ./lib: unitypes.h 221 | Only in ./lib: uniwidth.h 222 | Only in ./lib: wchar.h 223 | Only in ./lib: wctype.h 224 | * Files ./lib/xmalloc.c and ../orig/grep-3.7/lib/xmalloc.c differ 225 | Only in .: make.bat 226 | * Files ./src/dfasearch.c and ../orig/grep-3.7/src/dfasearch.c differ 227 | Files ./src/grep.c and ../orig/grep-3.7/src/grep.c differ 228 | * Files ./src/kwsearch.c and ../orig/grep-3.7/src/kwsearch.c differ 229 | * Files ./src/kwset.c and ../orig/grep-3.7/src/kwset.c differ 230 | * Files ./src/searchutils.c and ../orig/grep-3.7/src/searchutils.c differ 231 | 232 | * -- if grep-3.7-src-non-c99.patch was applied 233 | ? -- if configured under Visual Studio 2008 234 | 235 | 6) edit make.bat 236 | 237 | cp make.bat make.bat.old 238 | sed -i -n 's/^.* cl /cl /p;/^lib /p;/^link /p' make.bat 239 | sed -i '/.nologo /s@/@\\@g' make.bat 240 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@-Fo@&lib\\@' make.bat 241 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@.cygpath -w .@lib\\@' make.bat 242 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib -c/s@-Fo@&src\\@' make.bat 243 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib -c/s@.cygpath -w .@src\\@' make.bat 244 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. -I..\\lib -I..\\lib .* -c@/I. /I.\\lib /I.\\src -c@' make.bat 245 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. .* -c@/I. /I.\\lib -c@' make.bat 246 | sed -i 's@-c -nologo -Fo@/Ox /GF /Gy /GS- /GL /EHsc /DHAVE_CONFIG_H /c /nologo /Fo@' make.bat 247 | sed -i 's@.`@@' make.bat 248 | sed -i '/^lib/s@ .nologo .OUT:@@;/^lib/s@ *$@@g;/^lib/s@ @ .\\lib\\@g;s@^lib@lib /LTCG /nologo /OUT:@' make.bat 249 | sed -i '/^link/s@..\\lib\\libgreputils.a@@g' make.bat 250 | sed -i '/^link/s@ .nologo .OUT:@@;/^link/s@ *$@@g;/^link/s@\([^ ]*.obj\)@.\\src\\&@g' make.bat 251 | sed -i 's@^link@link /LTCG /nologo .\\libgreputils.a /OUT:@' make.bat 252 | sed -i 's@.*@& || exit /b 1@' make.bat 253 | rm make.bat.old 254 | 255 | 7) finally, create a patch: 256 | diff -Naur ../orig/grep-3.7 . > ../grep-3.7-build-VS22-x64.patch 257 | 258 | or, for Visual Studio 2008: 259 | diff -Naur ../orig/grep-3.7 . > ../grep-3.7-build-VS9-x86.patch 260 | -------------------------------------------------------------------------------- /archive/grep-3.7-src.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.7/lib/fts.c grep-3.7-patched/lib/fts.c 2 | --- grep-3.7/lib/fts.c 2021-06-07 18:02:20.000000000 +0300 3 | +++ grep-3.7-patched/lib/fts.c 2022-03-14 09:33:23.189685000 +0300 4 | @@ -121,6 +121,9 @@ 5 | #ifndef S_IFSOCK 6 | # define S_IFSOCK 0 7 | #endif 8 | +#ifndef S_IFBLK 9 | +# define S_IFBLK 0 10 | +#endif 11 | 12 | enum 13 | { 14 | @@ -1835,7 +1838,7 @@ 15 | FTSENT *dummy; 16 | int (*compare) (void const *, void const *) = 17 | ((sizeof &dummy == sizeof (void *) 18 | - && (long int) &dummy == (long int) (void *) &dummy) 19 | + && (long long int) &dummy == (long long int) (void *) &dummy) 20 | ? (int (*) (void const *, void const *)) sp->fts_compar 21 | : fts_compar); 22 | 23 | diff -Naur grep-3.7/src/grep.c grep-3.7-patched/src/grep.c 24 | --- grep-3.7/src/grep.c 2021-08-09 21:35:50.000000000 +0300 25 | +++ grep-3.7-patched/src/grep.c 2022-03-14 09:33:23.189685000 +0300 26 | @@ -2828,6 +2828,7 @@ 27 | (char *) NULL); 28 | puts (_("Written by Mike Haertel and others; see\n" 29 | ".")); 30 | + puts (_("Patched by: Michael M. Builov .\n")); 31 | return EXIT_SUCCESS; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /archive/grep-3.7-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/grep-3.7-x64.exe -------------------------------------------------------------------------------- /archive/grep-3.7-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/grep-3.7-x86.exe -------------------------------------------------------------------------------- /archive/grep-3.8-build-patch-howto.txt: -------------------------------------------------------------------------------- 1 | Instructions how to build native grep.exe with Microsoft Visual Studio (or Build Tools for Visual Studio) from CYGWIN shell. 2 | 3 | While building, it is possible to save build log and create a patch - for compiling grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 4 | 5 | This is how grep-3.8-build-VS22-x64.patch and grep-3.8-build-VS22-x86.patch were created. 6 | 7 | 8 | ---------------------------------------------------------------------------- 9 | First, build pcre2.a and pcre2posix.a libraries (and pcre2grep.exe utility). 10 | 11 | From CYGWIN shell, in the working directory: 12 | 13 | 1) get archive: 14 | wget https://github.com/PCRE2Project/pcre2/archive/refs/tags/pcre2-10.40.tar.gz 15 | 16 | 2) unpack archive: 17 | tar xf pcre2-10.40.tar.gz 18 | 19 | 3) go to PCRE2 sources: 20 | cd pcre2-pcre2-10.40 21 | 22 | 4) copy makefile, config.h, pcre2.h, RunGrepTest.bat and pcre2_chartables.c 23 | cp ../NMakefile-pcre2-10.40 ./NMakefile 24 | cp ../config-pcre2-10.40.h ./src/config.h 25 | cp ../RunGrepTest-pcre2-10.40.bat ./RunGrepTest.bat 26 | cp ./src/pcre2.h.generic ./src/pcre2.h 27 | cp ./src/pcre2_chartables.c.dist ./src/pcre2_chartables.c 28 | 29 | 5) now start dos prompt: 30 | cmd /c "start cmd.exe" 31 | 32 | In the dos window: 33 | 34 | 7) setup compiler: 35 | "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 36 | (if Microsoft Build Tools for Visual Studio 2022 is installed in "C:\Program Files (x86)") 37 | 38 | --tip: to build 32-bit version of PCRE2 library and pcre2grep.exe utility, specify "x86" instead of "amd64" 39 | 40 | 8) build pcre2.a, pcre2posix.a and pcre2grep.exe, run tests: 41 | nmake -f NMakefile check 42 | 43 | 44 | ---------------------------------------------------------------------------- 45 | Second, build Gnu Grep with PCRE support. 46 | 47 | From CYGWIN shell, in the same working directory which was used for the PCRE2 library build: 48 | 49 | 1) get archive: 50 | wget https://ftp.gnu.org/gnu/grep/grep-3.8.tar.xz 51 | 52 | 2) unpack archive: 53 | tar xf grep-3.8.tar.xz 54 | 55 | 3) go to grep sources: 56 | cd grep-3.8 57 | 58 | 4) fix sources for windows: 59 | patch -Np1 -i grep-3.8-src.patch 60 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.8-src.patch) 61 | 62 | 5) now start dos prompt: 63 | cmd /c "start cmd.exe" 64 | 65 | 6) setup compiler: 66 | "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 67 | (if Microsoft Build Tools for Visual Studio 2022 is installed in "C:\Program Files (x86)") 68 | 69 | --tip: to build 32-bit version of the Gnu Grep utility, specify "x86" instead of "amd64" 70 | 71 | 7) run bash from dos prompt (with environment prepared for compiling with Microsoft Build Tools for Visual Studio 2022): 72 | bash 73 | 74 | 8) check that Gnu Make is installed in CYGWIN and it is working (Gnu Make is required for the build): 75 | make --version 76 | 77 | 9) configure grep (assuming pcre2 library was built at ../pcre2-pcre2-10.40): 78 | CFLAGS= CC=cl CPP="cl /E" LD=lib ARFLAGS="/OUT:" PCRE_CFLAGS="/DPCRE2_STATIC /I../../pcre2-pcre2-10.40/src" PCRE_LIBS=../../pcre2-pcre2-10.40/pcre2.a ./configure --enable-threads=windows --disable-dependency-tracking --disable-silent-rules --disable-nls gl_cv_sys_struct_lconv_ok=yes pcre_cv_have_pcre2_compile=yes 79 | 80 | --tip: when building 32-bit version of the Gnu Grep utility, add "/D_WIN32_WINNT=0x501" compiler switch: 81 | CFLAGS= CC="cl /D_WIN32_WINNT=0x501" CPP="cl /D_WIN32_WINNT=0x501 /E" LD=lib ARFLAGS="/OUT:" PCRE_CFLAGS="/DPCRE2_STATIC /I../../pcre2-pcre2-10.40/src" PCRE_LIBS=../../pcre2-pcre2-10.40/pcre2.a ./configure --enable-threads=windows --disable-dependency-tracking --disable-silent-rules --disable-nls gl_cv_sys_struct_lconv_ok=yes pcre_cv_have_pcre2_compile=yes 82 | 83 | 10) configure script is not fully functional to create correct Makefiles - they are need to be fixed manually: 84 | sed -i 's/^SUBDIRS = .*/SUBDIRS = lib src/' ./Makefile 85 | sed -i 's/^RECURSIVE_TARGETS = /&gen /' ./Makefile 86 | sed -i 's/-c -o /-c -nologo -Fo/' ./lib/Makefile ./src/Makefile 87 | sed -i 's@^AR = .*@AR = lib /nologo@' ./lib/Makefile 88 | sed -i '/$(libgreputils_a_AR)/s/ lib/lib/' ./lib/Makefile 89 | sed -i 's%^am_libgreputils_a_OBJECTS = %&getpagesize.$(OBJEXT) stat-w32.$(OBJEXT) %' ./lib/Makefile 90 | sed -i 's/^COLORIZE_SOURCE = .*/COLORIZE_SOURCE = colorize-w32.c/' ./lib/Makefile 91 | 92 | 11) fix linker command: 93 | sed -i 's%^LINK = .*%LINK = link /nologo /SUBSYSTEM:CONSOLE /OUT:$@%' ./src/Makefile 94 | 95 | --tip: when building 32-bit version of the Gnu Grep utility, specify "/SUBSYSTEM:CONSOLE,5.01" linker switch: 96 | sed -i 's%^LINK = .*%LINK = link /nologo /SUBSYSTEM:CONSOLE,5.01 /OUT:$@%' ./src/Makefile 97 | 98 | 12) add gen target: 99 | echo 'gen:' >> ./Makefile 100 | echo 'gen:' >> ./src/Makefile 101 | echo 'gen: $(BUILT_SOURCES)' >> ./lib/Makefile 102 | echo 'gen-am:' >> ./Makefile 103 | 104 | 13) execute Makefile to generate grep headers: 105 | make gen 106 | 107 | 14) some references to system header files are missing in generated headers - they need to be fixed manually. 108 | 109 | a) set paths to locations of Build Tools for Visual Studio 2022 and WDK10 in grep-3.8-win-headers.patch (assume it was copied to the current directory): 110 | 111 | sed -i '/Visual Studio/s@.:.*include@'"$(env | sed -n 's@\\@\\\\@g;/^INCLUDE/s@.*[=;]\([^=;]*\\\\VC\\\\[^=;]*[0-9]\\\\include\).*$@\1@p')"'@' ./grep-3.8-win-headers.patch 112 | sed -i '/Windows Kits/s@.:.*ucrt@'"$(env | sed -n 's@\\@\\\\@g;/^INCLUDE/s@.*[=;]\([^=;]*\\\\ucrt\).*$@\1@p')"'@' ./grep-3.8-win-headers.patch 113 | 114 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.8-win-headers.patch) 115 | 116 | note: sub-command 117 | env | sed -n 's@\\@\\\\@g;/^INCLUDE/s@.*[=;]\([^=;]*\\\\VC\\\\[^=;]*[0-9]\\\\include\).*$@\1@p' 118 | should extract path to MSVC headers, like: 119 | C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.30.30705\\include 120 | 121 | and sub-command 122 | env | sed -n 's@\\@\\\\@g;/^INCLUDE/s@.*[=;]\([^=;]*\\\\ucrt\).*$@\1@p' 123 | should extract path to WDK headers, like: 124 | C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22000.0\\ucrt 125 | 126 | b) now patch the previously generated headers with updated patch-file: 127 | patch -Np1 -i ./grep-3.8-win-headers.patch 128 | 129 | c) header file lib/unistd.h is generated erroneously, fix it: 130 | patch -Np1 -i grep-3.8-unistd.patch 131 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.8-unistd.patch) 132 | 133 | d) fix build for the native Windows platform: 134 | patch -Np1 -i grep-3.8-mbtowc-lock.patch 135 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.8-mbtowc-lock.patch) 136 | 137 | 15) do compile grep: 138 | make > make.bat 139 | 140 | 16) check build result: 141 | ./src/grep.exe --version 142 | 143 | (should print grep version, e.g.: (GNU grep) 3.8) 144 | 145 | compilation should be ok, native (unoptimized) ./grep/grep.exe should be created. 146 | 147 | 148 | Now it is possible to create a patch file - for compiling optimized grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 149 | 150 | 1) create directory for unpatched grep: 151 | mkdir ../orig 152 | 153 | 2) unpack grep: 154 | tar xf ../grep-3.8.tar.xz -C ../orig/ 155 | 156 | 3) diff current directory with original just unpacked grep-3.8.tar.xz in the '../orig' directory 157 | diff -rql . ../orig/grep-3.8 158 | 159 | 4) remove unneeded built files in the current directory (object files, libs, etc...) 160 | 161 | rm -rv \ 162 | ./Makefile \ 163 | ./stamp-h1 \ 164 | ./grep-3.8-win-headers.patch \ 165 | ./src/*.obj \ 166 | ./lib/*.obj \ 167 | ./lib/glthread/*.obj \ 168 | ./lib/glthread/.deps \ 169 | ./lib/glthread/.dirstamp \ 170 | ./lib/unistr/*.obj \ 171 | ./lib/unistr/.deps \ 172 | ./lib/unistr/.dirstamp \ 173 | ./lib/uniwidth/*.obj \ 174 | ./lib/uniwidth/.deps \ 175 | ./lib/uniwidth/.dirstamp \ 176 | ./lib/malloc/*.obj \ 177 | ./lib/malloc/.deps \ 178 | ./lib/malloc/.dirstamp \ 179 | ./lib/libgreputils.a \ 180 | ./src/grep.exe \ 181 | ./src/egrep \ 182 | ./src/fgrep \ 183 | ./src/Makefile \ 184 | ./lib/Makefile \ 185 | ./doc/Makefile \ 186 | ./tests/Makefile \ 187 | ./gnulib-tests/Makefile \ 188 | ./po/Makefile \ 189 | ./po/Makefile.in \ 190 | ./po/POTFILES \ 191 | ./config.log \ 192 | ./config.status 193 | 194 | 5) after this, diff should print: 195 | 196 | diff -rql . ../orig/grep-3.8 197 | Only in .: config.h 198 | Only in ./lib: alloca.h 199 | Only in ./lib: colorize.c 200 | Only in ./lib: configmake.h 201 | Only in ./lib: ctype.h 202 | Only in ./lib: dirent.h 203 | Only in ./lib: errno.h 204 | Only in ./lib: fcntl.h 205 | Only in ./lib: fnmatch.h 206 | Files ./lib/fts.c and ../orig/grep-3.8/lib/fts.c differ 207 | Only in ./lib: getopt-cdefs.h 208 | Only in ./lib: getopt.h 209 | Only in ./lib: inttypes.h 210 | Only in ./lib: langinfo.h 211 | Only in ./lib: limits.h 212 | Only in ./lib: locale.h 213 | Only in ./lib/malloc: dynarray-skeleton.gl.h 214 | Only in ./lib/malloc: dynarray.gl.h 215 | Files ./lib/mbtowc-lock.c and ../orig/grep-3.8/lib/mbtowc-lock.c differ 216 | Files ./lib/mbtowc-lock.h and ../orig/grep-3.8/lib/mbtowc-lock.h differ 217 | Only in ./lib: signal.h 218 | Only in ./lib: sigsegv.h 219 | Only in ./lib: stdalign.h 220 | Only in ./lib: stddef.h 221 | Only in ./lib: stdint.h 222 | Only in ./lib: stdio.h 223 | Only in ./lib: stdlib.h 224 | Only in ./lib: string.h 225 | Only in ./lib: sys 226 | Only in ./lib: time.h 227 | Only in ./lib: unistd.h 228 | Only in ./lib: unistr.h 229 | Only in ./lib: unitypes.h 230 | Only in ./lib: uniwidth.h 231 | Only in ./lib: wchar.h 232 | Only in ./lib: wctype.h 233 | Only in .: make.bat 234 | Files ./src/grep.c and ../orig/grep-3.8/src/grep.c differ 235 | 236 | 6) edit make.bat 237 | 238 | cp make.bat make.bat.old 239 | sed -i -n 's/^.* cl /cl /p;/^lib /p;/^link /p' make.bat 240 | sed -i '/.nologo /s@/lib@\\lib@g' make.bat 241 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@-Fo@&lib\\@' make.bat 242 | sed -i '/-DHAVE_CONFIG_H -I. -I.. /s@.cygpath -w .@lib\\@' make.bat 243 | sed -i '/-DHAVE_CONFIG_H -I. -I.. /s@.if test -f.*\./@lib\\@' make.bat 244 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I/s@.cygpath -w .@src\\@' make.bat 245 | sed -i 's@.; fi`@@;s@.`@@' make.bat 246 | sed -i 's@malloc/@malloc\\@;s@glthread/@glthread\\@;s@unistr/@unistr\\@;s@uniwidth/@uniwidth\\@' make.bat 247 | sed -i '/libgreputils_a/s@-Fo@&lib\\@' make.bat 248 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib /s@-Fo@&src\\@' make.bat 249 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib /s@\([^ ]\)/@\1\\@g' make.bat 250 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. -I..\\lib -I..\\lib @/I. /I.\\lib @' make.bat 251 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. .* -c@/I. /I.\\lib -c@' make.bat 252 | sed -i 's@/I..\\..\\@/I..\\@' make.bat 253 | sed -i 's@-c -nologo -Fo@/Ox /GF /Gy /GS- /GL /EHsc /DHAVE_CONFIG_H /c /nologo /Fo@' make.bat 254 | sed -i '/^lib/s@ .nologo .OUT:@@;/^lib/s@ *$@@g;/^lib/s@[^ ]*.obj@.\\lib\\&@g;s@^lib@lib /LTCG /nologo /OUT:@' make.bat 255 | sed -i '/^link/s@..\\lib\\libgreputils.a@*@g;/^link/s@\*.*\*@*@;/^link/s@\*@.\\libgreputils.a@' make.bat 256 | sed -i '/^link/s@\.\./\.\./@..\\@;s@\([^ ]\)/@\1\\@g' make.bat 257 | sed -i '/^link/s@ .OUT:@ /LTCG&@;/^link/s@ *$@@g;/^link/s@[^ ]*.obj@.\\src\\&@g' make.bat 258 | sed -i 's@.*@& || exit /b 1@' make.bat 259 | rm make.bat.old 260 | 261 | 7) finally, create a patch: 262 | diff -Naur ../orig/grep-3.8 . > ../grep-3.8-build-VS22-x64.patch 263 | 264 | --tip: for the 32-bit build, use different patch name: 265 | diff -Naur ../orig/grep-3.8 . > ../grep-3.8-build-VS22-x86.patch 266 | -------------------------------------------------------------------------------- /archive/grep-3.8-build.txt: -------------------------------------------------------------------------------- 1 | How to build native 32/64-bit Gnu grep.exe with Visual Studio 2022 and WDK10 2 | 3 | ---------------------------------------------------------------------------- 4 | First, build pcre2.a and pcre2posix.a libraries (and pcre2grep.exe utility). 5 | 6 | From CYGWIN or other unix shell, in the working directory: 7 | 8 | 1) get archive: wget https://github.com/PCRE2Project/pcre2/archive/refs/tags/pcre2-10.40.tar.gz 9 | 2) unpack archive: tar xf pcre2-10.40.tar.gz 10 | 3) go to PCRE2 sources: cd pcre2-pcre2-10.40 11 | 4) copy files: 12 | cp ../NMakefile-pcre2-10.40 ./NMakefile 13 | cp ../config-pcre2-10.40.h ./src/config.h 14 | cp ../RunGrepTest-pcre2-10.40.bat ./RunGrepTest.bat 15 | cp ./src/pcre2.h.generic ./src/pcre2.h 16 | cp ./src/pcre2_chartables.c.dist ./src/pcre2_chartables.c 17 | 5) run dos prompt: cmd /c "start cmd.exe" 18 | 6) setup compiler: 19 | for 64-bit build: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 20 | for 32-bit build: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86 21 | 7) compile and check: nmake -f NMakefile check 22 | 23 | ---------------------------------------------------------------------------- 24 | Second, build Gnu Grep with PCRE support. 25 | 26 | From CYGWIN or other unix shell, in the same working directory which was used for the PCRE2 library build: 27 | 28 | 1) get grep archive: wget https://ftp.gnu.org/gnu/grep/grep-3.8.tar.xz 29 | 2) unpack sed archive: tar xf grep-3.8.tar.xz 30 | 3) go to grep sources: cd grep-3.8 31 | 4) run dos prompt: cmd /c "start cmd.exe" 32 | 5) setup compiler: 33 | for 64-bit build: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 34 | for 32-bit build: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86 35 | 6) temporary run sh: sh 36 | 7) copy build patch: 37 | for 64-bit build: cp ../grep-3.8-build-VS22-x64.patch ./build.patch 38 | for 32-bit build: cp ../grep-3.8-build-VS22-x86.patch ./build.patch 39 | 8) fix build patch - change paths to locations of Visual Studio 2022 and WDK10: 40 | sed -i '/Visual Studio/s@.:.*include@'"$(env | sed -n 's@\\@\\\\@g;/^INCLUDE/s@.*[=;]\([^=;]*\\\\VC\\\\[^=;]*[0-9]\\\\include\).*$@\1@p')"'@' ./build.patch 41 | sed -i '/Windows Kits/s@.:.*ucrt@'"$(env | sed -n 's@\\@\\\\@g;/^INCLUDE/s@.*[=;]\([^=;]*\\\\ucrt\).*$@\1@p')"'@' ./build.patch 42 | 9) patch grep: patch -Np1 -i ./build.patch 43 | 10) exit sh: exit 44 | 11) do compile: make.bat 45 | 12) check build result: grep.exe --version 46 | -------------------------------------------------------------------------------- /archive/grep-3.8-src.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.8/lib/fts.c grep-3.8/lib/fts.c 2 | --- grep-3.8/lib/fts.c 2022-03-21 04:40:05.000000000 +0300 3 | +++ grep-3.8/lib/fts.c 2022-11-13 20:27:45.266764700 +0300 4 | @@ -121,6 +121,9 @@ 5 | #ifndef S_IFSOCK 6 | # define S_IFSOCK 0 7 | #endif 8 | +#ifndef S_IFBLK 9 | +# define S_IFBLK 0 10 | +#endif 11 | 12 | enum 13 | { 14 | @@ -1835,7 +1838,7 @@ 15 | FTSENT *dummy; 16 | int (*compare) (void const *, void const *) = 17 | ((sizeof &dummy == sizeof (void *) 18 | - && (long int) &dummy == (long int) (void *) &dummy) 19 | + && (long long int) &dummy == (long long int) (void *) &dummy) 20 | ? (int (*) (void const *, void const *)) sp->fts_compar 21 | : fts_compar); 22 | 23 | diff -Naur grep-3.8/src/grep.c grep-3.8/src/grep.c 24 | --- grep-3.8/src/grep.c 2022-06-08 22:07:18.000000000 +0300 25 | +++ grep-3.8/src/grep.c 2022-11-13 20:27:45.282409800 +0300 26 | @@ -2830,6 +2830,7 @@ 27 | (char *) NULL); 28 | puts (_("Written by Mike Haertel and others; see\n" 29 | ".")); 30 | + puts (_("Patched by: Michael M. Builov .\n")); 31 | return EXIT_SUCCESS; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /archive/grep-3.8-unistd.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.6/lib/unistd.h grep-3.6-3/lib/unistd.h 2 | --- grep-3.6/lib/unistd.h 2021-06-30 18:40:50.936409700 +0300 3 | +++ grep-3.6-3/lib/unistd.h 2021-06-30 17:48:29.007217900 +0300 4 | @@ -1838,7 +1838,7 @@ 5 | #endif 6 | 7 | 8 | -#if 1 9 | +#if 0 10 | # if 0 11 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 12 | # define getpagesize rpl_getpagesize 13 | @@ -1923,6 +1923,7 @@ 14 | "use gnulib module getpagesize for portability"); 15 | # endif 16 | #endif 17 | +int getpagesize(void); 18 | 19 | 20 | #if 0 21 | -------------------------------------------------------------------------------- /archive/grep-3.8-win-headers.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.8x/lib/ctype.h grep-3.8/lib/ctype.h 2 | --- grep-3.8x/lib/ctype.h 2022-11-13 20:57:42.137790400 +0300 3 | +++ grep-3.8/lib/ctype.h 2022-11-13 21:04:51.654924900 +0300 4 | @@ -32,7 +32,7 @@ 5 | 6 | /* Include the original . */ 7 | /* The include_next requires a split double-inclusion guard. */ 8 | -#include "" 9 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\ctype.h" 10 | 11 | #ifndef _GL_CTYPE_H 12 | #define _GL_CTYPE_H 13 | diff -Naur grep-3.8x/lib/errno.h grep-3.8/lib/errno.h 14 | --- grep-3.8x/lib/errno.h 2022-11-13 20:57:42.755088500 +0300 15 | +++ grep-3.8/lib/errno.h 2022-11-13 21:04:51.654924900 +0300 16 | @@ -24,7 +24,7 @@ 17 | 18 | 19 | /* The include_next requires a split double-inclusion guard. */ 20 | -#include "" 21 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\errno.h" 22 | 23 | #ifndef _GL_ERRNO_H 24 | #define _GL_ERRNO_H 25 | diff -Naur grep-3.8x/lib/fcntl.h grep-3.8/lib/fcntl.h 26 | --- grep-3.8x/lib/fcntl.h 2022-11-13 20:57:42.893155200 +0300 27 | +++ grep-3.8/lib/fcntl.h 2022-11-13 21:04:51.670544400 +0300 28 | @@ -38,7 +38,7 @@ 29 | #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))) 30 | # include 31 | #endif 32 | -#include "" 33 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\fcntl.h" 34 | 35 | /* Native Windows platforms declare open(), creat() in . */ 36 | #if (0 || 1 || defined GNULIB_POSIXCHECK) \ 37 | @@ -64,7 +64,7 @@ 38 | # include 39 | #endif 40 | /* The include_next requires a split double-inclusion guard. */ 41 | -#include "" 42 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\fcntl.h" 43 | 44 | /* Native Windows platforms declare open(), creat() in . */ 45 | #if (0 || 1 || defined GNULIB_POSIXCHECK) \ 46 | diff -Naur grep-3.8x/lib/inttypes.h grep-3.8/lib/inttypes.h 47 | --- grep-3.8x/lib/inttypes.h 2022-11-13 20:57:43.472678300 +0300 48 | +++ grep-3.8/lib/inttypes.h 2022-11-13 21:04:51.670544400 +0300 49 | @@ -38,7 +38,7 @@ 50 | # define __STDC_FORMAT_MACROS 1 51 | # endif 52 | 53 | -# include "" 54 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\inttypes.h" 55 | 56 | # define _GL_FINISHED_INCLUDING_SYSTEM_INTTYPES_H 57 | # endif 58 | diff -Naur grep-3.8x/lib/limits.h grep-3.8/lib/limits.h 59 | --- grep-3.8x/lib/limits.h 2022-11-13 20:57:43.742273500 +0300 60 | +++ grep-3.8/lib/limits.h 2022-11-13 21:04:51.686170300 +0300 61 | @@ -38,7 +38,7 @@ 62 | # define _GL_ALREADY_INCLUDING_LIMITS_H 63 | 64 | /* The include_next requires a split double-inclusion guard. */ 65 | -# include "" 66 | +# include "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\limits.h" 67 | 68 | # undef _GL_ALREADY_INCLUDING_LIMITS_H 69 | 70 | diff -Naur grep-3.8x/lib/locale.h grep-3.8/lib/locale.h 71 | --- grep-3.8x/lib/locale.h 2022-11-13 20:57:43.911594600 +0300 72 | +++ grep-3.8/lib/locale.h 2022-11-13 21:04:51.686170300 +0300 73 | @@ -38,7 +38,7 @@ 74 | #define _GL_ALREADY_INCLUDING_LOCALE_H 75 | 76 | /* The include_next requires a split double-inclusion guard. */ 77 | -#include "" 78 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\locale.h" 79 | 80 | #undef _GL_ALREADY_INCLUDING_LOCALE_H 81 | 82 | diff -Naur grep-3.8x/lib/signal.h grep-3.8/lib/signal.h 83 | --- grep-3.8x/lib/signal.h 2022-11-13 20:57:44.058756800 +0300 84 | +++ grep-3.8/lib/signal.h 2022-11-13 21:04:51.701794600 +0300 85 | @@ -49,7 +49,7 @@ 86 | #include 87 | 88 | /* The include_next requires a split double-inclusion guard. */ 89 | -#include "" 90 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\signal.h" 91 | 92 | #undef _GL_ALREADY_INCLUDING_SIGNAL_H 93 | 94 | diff -Naur grep-3.8x/lib/stddef.h grep-3.8/lib/stddef.h 95 | --- grep-3.8x/lib/stddef.h 2022-11-13 20:57:44.381729600 +0300 96 | +++ grep-3.8/lib/stddef.h 2022-11-13 21:04:51.708304300 +0300 97 | @@ -76,7 +76,7 @@ 98 | 99 | /* The include_next requires a split double-inclusion guard. */ 100 | 101 | -# include "" 102 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stddef.h" 103 | 104 | /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ 105 | # if (0 \ 106 | diff -Naur grep-3.8x/lib/stdint.h grep-3.8/lib/stdint.h 107 | --- grep-3.8x/lib/stdint.h 2022-11-13 20:57:44.544520800 +0300 108 | +++ grep-3.8/lib/stdint.h 2022-11-13 21:04:51.723944600 +0300 109 | @@ -74,7 +74,7 @@ 110 | in would reinclude us, skipping our contents because 111 | _GL_STDINT_H is defined. 112 | The include_next requires a split double-inclusion guard. */ 113 | -# include "" 114 | +# include "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\stdint.h" 115 | #endif 116 | 117 | #if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H 118 | diff -Naur grep-3.8x/lib/stdio.h grep-3.8/lib/stdio.h 119 | --- grep-3.8x/lib/stdio.h 2022-11-13 20:57:44.905739800 +0300 120 | +++ grep-3.8/lib/stdio.h 2022-11-13 21:04:51.723944600 +0300 121 | @@ -30,7 +30,7 @@ 122 | In this situation, the functions are not yet declared, therefore we cannot 123 | provide the C++ aliases. */ 124 | 125 | -#include "" 126 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stdio.h" 127 | 128 | #else 129 | /* Normal invocation convention. */ 130 | @@ -40,7 +40,7 @@ 131 | #define _GL_ALREADY_INCLUDING_STDIO_H 132 | 133 | /* The include_next requires a split double-inclusion guard. */ 134 | -#include "" 135 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stdio.h" 136 | 137 | #undef _GL_ALREADY_INCLUDING_STDIO_H 138 | 139 | diff -Naur grep-3.8x/lib/stdlib.h grep-3.8/lib/stdlib.h 140 | --- grep-3.8x/lib/stdlib.h 2022-11-13 20:57:45.275637000 +0300 141 | +++ grep-3.8/lib/stdlib.h 2022-11-13 21:04:51.739569800 +0300 142 | @@ -25,7 +25,7 @@ 143 | /* Special invocation conventions inside some gnulib header files, 144 | and inside some glibc header files, respectively. */ 145 | 146 | -#include "" 147 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stdlib.h" 148 | 149 | #else 150 | /* Normal invocation convention. */ 151 | @@ -33,7 +33,7 @@ 152 | #ifndef _GL_STDLIB_H 153 | 154 | /* The include_next requires a split double-inclusion guard. */ 155 | -#include "" 156 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stdlib.h" 157 | 158 | #ifndef _GL_STDLIB_H 159 | #define _GL_STDLIB_H 160 | diff -Naur grep-3.8x/lib/string.h grep-3.8/lib/string.h 161 | --- grep-3.8x/lib/string.h 2022-11-13 20:57:45.597634700 +0300 162 | +++ grep-3.8/lib/string.h 2022-11-13 21:04:51.755195300 +0300 163 | @@ -38,7 +38,7 @@ 164 | #define _GL_ALREADY_INCLUDING_STRING_H 165 | 166 | /* The include_next requires a split double-inclusion guard. */ 167 | -#include "" 168 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\string.h" 169 | 170 | #undef _GL_ALREADY_INCLUDING_STRING_H 171 | 172 | diff -Naur grep-3.8x/lib/sys/stat.h grep-3.8/lib/sys/stat.h 173 | --- grep-3.8x/lib/sys/stat.h 2022-11-13 20:57:45.834455800 +0300 174 | +++ grep-3.8/lib/sys/stat.h 2022-11-13 21:04:51.755195300 +0300 175 | @@ -29,7 +29,7 @@ 176 | #if defined __need_system_sys_stat_h 177 | /* Special invocation convention. */ 178 | 179 | -#include "" 180 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\sys\stat.h" 181 | 182 | #else 183 | /* Normal invocation convention. */ 184 | @@ -44,7 +44,7 @@ 185 | #include 186 | 187 | /* The include_next requires a split double-inclusion guard. */ 188 | -#include "" 189 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\sys\stat.h" 190 | 191 | #ifndef _GL_SYS_STAT_H 192 | #define _GL_SYS_STAT_H 193 | diff -Naur grep-3.8x/lib/sys/types.h grep-3.8/lib/sys/types.h 194 | --- grep-3.8x/lib/sys/types.h 2022-11-13 20:57:45.988144200 +0300 195 | +++ grep-3.8/lib/sys/types.h 2022-11-13 21:04:51.770820500 +0300 196 | @@ -36,7 +36,7 @@ 197 | 198 | /* The include_next requires a split double-inclusion guard. */ 199 | # define _GL_INCLUDING_SYS_TYPES_H 200 | -#include "" 201 | +#include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\sys\types.h" 202 | # undef _GL_INCLUDING_SYS_TYPES_H 203 | 204 | #ifndef _GL_SYS_TYPES_H 205 | diff -Naur grep-3.8x/lib/time.h grep-3.8/lib/time.h 206 | --- grep-3.8x/lib/time.h 2022-11-13 20:57:46.173106100 +0300 207 | +++ grep-3.8/lib/time.h 2022-11-13 21:04:51.770820500 +0300 208 | @@ -32,7 +32,7 @@ 209 | && !defined __MINGW32__) \ 210 | || defined _GL_TIME_H) 211 | 212 | -# include "" 213 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\time.h" 214 | 215 | #else 216 | 217 | @@ -44,7 +44,7 @@ 218 | # include 219 | # endif 220 | 221 | -# include "" 222 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\time.h" 223 | 224 | /* NetBSD 5.0 mis-defines NULL. */ 225 | # include 226 | diff -Naur grep-3.8x/lib/wchar.h grep-3.8/lib/wchar.h 227 | --- grep-3.8x/lib/wchar.h 2022-11-13 20:57:47.098291000 +0300 228 | +++ grep-3.8/lib/wchar.h 2022-11-13 21:04:51.786445700 +0300 229 | @@ -77,7 +77,7 @@ 230 | Some builds of uClibc lack it. */ 231 | /* The include_next requires a split double-inclusion guard. */ 232 | #if 1 233 | -# include "" 234 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\wchar.h" 235 | #endif 236 | 237 | #undef _GL_ALREADY_INCLUDING_WCHAR_H 238 | diff -Naur grep-3.8x/lib/wctype.h grep-3.8/lib/wctype.h 239 | --- grep-3.8x/lib/wctype.h 2022-11-13 20:57:47.251972600 +0300 240 | +++ grep-3.8/lib/wctype.h 2022-11-13 21:04:51.808605400 +0300 241 | @@ -63,7 +63,7 @@ 242 | BeOS 5 has the functions but no . */ 243 | /* The include_next requires a split double-inclusion guard. */ 244 | #if 1 245 | -# include "" 246 | +# include "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\wctype.h" 247 | #endif 248 | 249 | #ifndef _GL_WCTYPE_H 250 | -------------------------------------------------------------------------------- /archive/grep-3.8-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/grep-3.8-x64.exe -------------------------------------------------------------------------------- /archive/grep-3.8-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/grep-3.8-x86.exe -------------------------------------------------------------------------------- /archive/pcre2grep-10.40-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/pcre2grep-10.40-x64.exe -------------------------------------------------------------------------------- /archive/pcre2grep-10.40-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/archive/pcre2grep-10.40-x86.exe -------------------------------------------------------------------------------- /egrep.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | grep.exe -E %* 3 | -------------------------------------------------------------------------------- /fgrep.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | grep.exe -F %* 3 | -------------------------------------------------------------------------------- /grep-3.11-build-patch-howto.txt: -------------------------------------------------------------------------------- 1 | Instructions how to build native Gnu grep.exe with Microsoft Visual Studio (or Build Tools for Visual Studio) from CYGWIN shell. 2 | 3 | While building, it is possible to save build log and create a patch - for compiling Gnu grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 4 | 5 | This is how grep-3.11-build-VS22-x64.patch and grep-3.11-build-VS22-x86.patch were created. 6 | 7 | 8 | First, build pcre2.a and pcre2posix.a libraries - see pcre2/pcre2-10.42-build.txt 9 | 10 | Second, in the directory containing ./pcre2-pcre2-10.42, build Gnu Grep with PCRE support. 11 | 12 | From CYGWIN shell: 13 | 14 | 1) get archive: 15 | wget https://ftp.gnu.org/gnu/grep/grep-3.11.tar.xz 16 | 17 | 2) unpack archive: 18 | tar xf grep-3.11.tar.xz 19 | 20 | 3) go to grep sources: 21 | cd grep-3.11 22 | 23 | 4) fix sources for windows: 24 | patch -Np1 -i grep-3.11-src.patch 25 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.11-src.patch) 26 | 27 | 5) now start dos prompt: 28 | cmd.exe /c start cmd.exe 29 | 30 | 6) setup compiler: 31 | "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 32 | (if Microsoft Build Tools for Visual Studio 2022 is installed in "C:\Program Files (x86)") 33 | 34 | --tip: to build 32-bit version of the Gnu Grep utility, specify "x86" instead of "amd64" 35 | 36 | 7) run bash from dos prompt (with environment prepared for compiling with Microsoft Build Tools for Visual Studio 2022): 37 | bash 38 | 39 | 8) check that Gnu Make is installed in CYGWIN and it is working (Gnu Make is required for the build): 40 | make --version 41 | 42 | 9) configure grep (assuming pcre2 library was built at ../pcre2-pcre2-10.42): 43 | CFLAGS= CC=cl CPP="cl /E" LD=lib ARFLAGS="/OUT:" PCRE_CFLAGS="/DPCRE2_STATIC /I../../pcre2-pcre2-10.42/src" PCRE_LIBS=../../pcre2-pcre2-10.42/pcre2.a ./configure --host=mingw64 --disable-dependency-tracking --disable-silent-rules --disable-nls pcre_cv_have_pcre2_compile=yes 44 | 45 | --tip: when building 32-bit version of the Gnu Grep utility, add "/D_WIN32_WINNT=0x501" compiler switch: 46 | CFLAGS= CC="cl /D_WIN32_WINNT=0x501" CPP="cl /D_WIN32_WINNT=0x501 /E" LD=lib ARFLAGS="/OUT:" PCRE_CFLAGS="/DPCRE2_STATIC /I../../pcre2-pcre2-10.42/src" PCRE_LIBS=../../pcre2-pcre2-10.42/pcre2.a ./configure --host=mingw32 --disable-dependency-tracking --disable-silent-rules --disable-nls pcre_cv_have_pcre2_compile=yes 47 | 48 | 10) configure script is not fully functional to create correct Makefiles for Visual Studio - they are need to be fixed manually: 49 | sed -i 's/^SUBDIRS = .*/SUBDIRS = lib src/' ./Makefile 50 | sed -i 's/^RECURSIVE_TARGETS = /&gen /' ./Makefile 51 | sed -i 's/-c -o /-c -nologo -Fo/' ./lib/Makefile ./src/Makefile 52 | sed -i 's@^AR = .*@AR = lib /nologo@' ./lib/Makefile 53 | sed -i '/$(libgreputils_a_AR)/s/ lib/lib/' ./lib/Makefile 54 | 55 | 11) fix linker command: 56 | sed -i 's%^LINK = .*%LINK = link /nologo /SUBSYSTEM:CONSOLE /OUT:$@%' ./src/Makefile 57 | 58 | --tip: when building 32-bit version of the Gnu Grep utility, specify "/SUBSYSTEM:CONSOLE,5.01" linker switch: 59 | sed -i 's%^LINK = .*%LINK = link /nologo /SUBSYSTEM:CONSOLE,5.01 /OUT:$@%' ./src/Makefile 60 | 61 | 12) add gen target: 62 | echo 'gen:' >> ./Makefile 63 | echo 'gen:' >> ./src/Makefile 64 | echo 'gen: $(BUILT_SOURCES)' >> ./lib/Makefile 65 | echo 'gen-am:' >> ./Makefile 66 | 67 | 13) execute Makefile to generate grep headers: 68 | make gen 69 | 70 | 14) fix generated headers: 71 | 72 | a) header file lib/unistd.h is generated erroneously, fix it: 73 | patch -Np1 -i grep-3.11-unistd.patch 74 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.11-unistd.patch) 75 | 76 | b) fix build for the native Windows platform: 77 | patch -Np1 -i grep-3.8-mbtowc-lock.patch 78 | (patch location: https://raw.githubusercontent.com/mbuilov/grep-windows/master/grep-3.8-mbtowc-lock.patch) 79 | 80 | 15) do compile grep: 81 | make > make.bat 82 | 83 | 16) check build result: 84 | ./src/grep.exe --version 85 | 86 | (should print grep version, e.g.: (GNU grep) 3.11) 87 | 88 | compilation should be ok, native (unoptimized) ./src/grep.exe should be created. 89 | 90 | 91 | Now it is possible to create a patch file - for compiling optimized grep.exe using only Microsoft Visual Studio tools, without need for CYGWIN. 92 | 93 | 1) create directory for unpatched grep: 94 | mkdir ../orig 95 | 96 | 2) unpack grep: 97 | tar xf ../grep-3.11.tar.xz -C ../orig/ 98 | 99 | 3) diff current directory with original just unpacked grep-3.11.tar.xz in the '../orig' directory 100 | diff -rql . ../orig/grep-3.11 101 | 102 | 4) remove unneeded built files in the current directory (object files, libs, etc...) 103 | 104 | rm -rv \ 105 | ./Makefile \ 106 | ./stamp-h1 \ 107 | ./src/*.obj \ 108 | ./lib/*.obj \ 109 | ./lib/glthread/*.obj \ 110 | ./lib/glthread/.deps \ 111 | ./lib/glthread/.dirstamp \ 112 | ./lib/unistr/*.obj \ 113 | ./lib/unistr/.deps \ 114 | ./lib/unistr/.dirstamp \ 115 | ./lib/uniwidth/*.obj \ 116 | ./lib/uniwidth/.deps \ 117 | ./lib/uniwidth/.dirstamp \ 118 | ./lib/malloc/*.obj \ 119 | ./lib/malloc/.deps \ 120 | ./lib/malloc/.dirstamp \ 121 | ./lib/libgreputils.a \ 122 | ./src/grep.exe \ 123 | ./src/egrep \ 124 | ./src/fgrep \ 125 | ./src/Makefile \ 126 | ./lib/Makefile \ 127 | ./doc/Makefile \ 128 | ./tests/Makefile \ 129 | ./gnulib-tests/Makefile \ 130 | ./po/Makefile \ 131 | ./po/Makefile.in \ 132 | ./po/POTFILES \ 133 | ./config.log \ 134 | ./config.status 135 | 136 | 5) after this, diff should print: 137 | 138 | diff -rql . ../orig/grep-3.11 139 | Only in .: config.h 140 | Only in ./lib: alloca.h 141 | Only in ./lib: colorize.c 142 | Only in ./lib: configmake.h 143 | Only in ./lib: ctype.h 144 | Only in ./lib: dirent.h 145 | Only in ./lib: errno.h 146 | Only in ./lib: error.h 147 | Only in ./lib: fcntl.h 148 | Only in ./lib: fnmatch.h 149 | Files ./lib/fts.c and ../orig/grep-3.11/lib/fts.c differ 150 | Only in ./lib: getopt-cdefs.h 151 | Only in ./lib: getopt.h 152 | Only in ./lib: inttypes.h 153 | Only in ./lib: langinfo.h 154 | Only in ./lib: limits.h 155 | Only in ./lib: locale.h 156 | Only in ./lib/malloc: dynarray-skeleton.gl.h 157 | Only in ./lib/malloc: dynarray.gl.h 158 | Files ./lib/mbtowc-lock.c and ../orig/grep-3.11/lib/mbtowc-lock.c differ 159 | Files ./lib/mbtowc-lock.h and ../orig/grep-3.11/lib/mbtowc-lock.h differ 160 | Only in ./lib: signal.h 161 | Only in ./lib: sigsegv.h 162 | Only in ./lib: stdckdint.h 163 | Only in ./lib: stddef.h 164 | Only in ./lib: stdint.h 165 | Only in ./lib: stdio.h 166 | Only in ./lib: stdlib.h 167 | Only in ./lib: string.h 168 | Only in ./lib: sys 169 | Only in ./lib: time.h 170 | Only in ./lib: unistd.h 171 | Only in ./lib: unistr.h 172 | Only in ./lib: unitypes.h 173 | Only in ./lib: uniwidth.h 174 | Only in ./lib: wchar.h 175 | Only in ./lib: wctype.h 176 | Only in .: make.bat 177 | Files ./src/grep.c and ../orig/grep-3.11/src/grep.c differ 178 | 179 | 6) edit make.bat 180 | 181 | cp make.bat make.bat.old 182 | sed -i -n 's/^.* cl /cl /p;/^lib /p;/^link /p' make.bat 183 | sed -i '/.nologo /s@/lib@\\lib@g' make.bat 184 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -c/s@-Fo@&lib\\@' make.bat 185 | sed -i '/-DHAVE_CONFIG_H -I. -I.. /s@.cygpath -w .@lib\\@' make.bat 186 | sed -i '/-DHAVE_CONFIG_H -I. -I.. /s@.if test -f.*\./@lib\\@' make.bat 187 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I/s@.cygpath -w .@src\\@' make.bat 188 | sed -i 's@.; fi`@@;s@.`@@' make.bat 189 | sed -i 's@malloc/@malloc\\@;s@glthread/@glthread\\@;s@unistr/@unistr\\@;s@uniwidth/@uniwidth\\@' make.bat 190 | sed -i '/libgreputils_a/s@-Fo@&lib\\@' make.bat 191 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib /s@-Fo@&src\\@' make.bat 192 | sed -i '/-DHAVE_CONFIG_H -I. -I.. -I...lib -I...lib /s@\([^ ]\)/@\1\\@g' make.bat 193 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. -I..\\lib -I..\\lib @/I. /I.\\lib @' make.bat 194 | sed -i 's@-DHAVE_CONFIG_H -I. -I.. .* -c@/I. /I.\\lib -c@' make.bat 195 | sed -i 's@/I..\\..\\@/I..\\@' make.bat 196 | sed -i 's@-c -nologo -Fo@/Ox /GF /Gy /GS- /GL /EHsc /DHAVE_CONFIG_H /c /nologo /Fo@' make.bat 197 | sed -i '/^lib/s@ .nologo .OUT:@@;/^lib/s@ *$@@g;/^lib/s@[^ ]*.obj@.\\lib\\&@g;s@^lib@lib /LTCG /nologo /OUT:@' make.bat 198 | sed -i '/^link/s@..\\lib\\libgreputils.a@*@g;/^link/s@\*.*\*@*@;/^link/s@\*@.\\libgreputils.a@' make.bat 199 | sed -i '/^link/s@\.\./\.\./@..\\@;s@\([^ ]\)/@\1\\@g' make.bat 200 | sed -i '/^link/s@ .OUT:@ /LTCG&@;/^link/s@ *$@@g;/^link/s@[^ ]*.obj@.\\src\\&@g' make.bat 201 | sed -i 's@.*@& || exit /b 1@' make.bat 202 | rm make.bat.old 203 | 204 | 7) finally, create a patch: 205 | diff -Naur ../orig/grep-3.11 . > ../grep-3.11-build-VS22-x64.patch 206 | 207 | --tip: for the 32-bit build, use different patch name: 208 | diff -Naur ../orig/grep-3.11 . > ../grep-3.11-build-VS22-x86.patch 209 | -------------------------------------------------------------------------------- /grep-3.11-build.txt: -------------------------------------------------------------------------------- 1 | How to build native 32/64-bit Gnu grep.exe with Visual Studio 2022 and WDK10 2 | 3 | First, build pcre2.a and pcre2posix.a libraries - see pcre2/pcre2-10.44-build.txt 4 | 5 | Second, in the directory containing ./pcre2-pcre2-10.44, build Gnu Grep with PCRE support. 6 | 7 | From CYGWIN shell or other unix-like shell: 8 | 9 | 1) get grep archive: wget https://ftp.gnu.org/gnu/grep/grep-3.11.tar.xz 10 | 2) unpack sed archive: tar xf grep-3.11.tar.xz 11 | 3) go to grep sources: cd grep-3.11 12 | 4) now start dos prompt with minimal environment (inherit TMP variable value): 13 | env -i TMP="$(cmd.exe /c set TMP | sed 's/.*=//;s/\x0d//')" $(which cmd.exe) /c start cmd.exe 14 | 15 | In the dos window: 16 | 17 | 5) prepare environment, change console code page to ACP (Ansi Code Page): 18 | set "PATH=C:\Windows\System32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0" 19 | set LC_CTYPE= 20 | chcp 1251 21 | set VSCMD_SKIP_SENDTELEMETRY=1 22 | 23 | (ACP value can be queried by the command: "reg query HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage /v ACP") 24 | 25 | 6) setup compiler: 26 | for 64-bit build: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 27 | for 32-bit build: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86 28 | 29 | 7) get value of INCLUDE environment variable set by vcvarsall.bat 30 | set INCLUDE >include.txt 31 | 32 | In the unix-like shell: 33 | 34 | 8) copy build patch: 35 | for 64-bit build: cp ../grep-3.11-build-VS22-x64.patch ./build.patch 36 | for 32-bit build: cp ../grep-3.11-build-VS22-x86.patch ./build.patch 37 | 38 | 9) fix build patch - change paths to locations of Visual Studio 2022 and WDK10: 39 | sed -i '/Visual Studio/s@.:.*include@'"$(utf8 transcoding: 45 | patch -Np1 -i ../grep-3.11-utf16.patch 46 | 47 | 12) update path to PCRE2 library: 48 | sed -i 's@\\pcre2-pcre2-10.[^\\]*@\\pcre2-pcre2-10.44@g' ./make.bat 49 | 50 | 13) add support for wildcard expansion in program arguments: 51 | sed -i 's@pcre2.a@& wsetargv.obj@' ./make.bat 52 | 53 | Again in the dos window: 54 | 55 | 14) do compile: make.bat 56 | 15) check build result: grep.exe --version 57 | -------------------------------------------------------------------------------- /grep-3.11-src.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.11/lib/fts.c grep-3.11/lib/fts-patched.c 2 | --- grep-3.11/lib/fts.c 2023-04-07 07:10:29.000000000 +0300 3 | +++ grep-3.11/lib/fts-patched.c 2023-07-13 13:21:27.884403300 +0300 4 | @@ -1867,7 +1867,7 @@ 5 | FTSENT *dummy; 6 | int (*compare) (void const *, void const *) = 7 | ((sizeof &dummy == sizeof (void *) 8 | - && (long int) &dummy == (long int) (void *) &dummy) 9 | + && (long long int) &dummy == (long long int) (void *) &dummy) 10 | ? (int (*) (void const *, void const *)) sp->fts_compar 11 | : fts_compar); 12 | 13 | diff -Naur grep-3.11/src/grep.c grep-3.11/src/grep-patched.c 14 | --- grep-3.11/src/grep.c 2023-04-11 03:20:47.000000000 +0300 15 | +++ grep-3.11/src/grep-patched.c 2023-07-13 13:24:46.525058300 +0300 16 | @@ -2830,6 +2830,7 @@ 17 | (char *) NULL); 18 | puts (_("Written by Mike Haertel and others; see\n" 19 | ".")); 20 | + puts (_("Patched by: Michael M. Builov .")); 21 | #if HAVE_LIBPCRE 22 | Pprint_version (); 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /grep-3.11-unistd.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.11x/lib/unistd.h grep-3.11/lib/unistd.h 2 | --- grep-3.11x/lib/unistd.h 2023-07-13 15:37:41.850773000 +0300 3 | +++ grep-3.11/lib/unistd.h 2023-07-13 16:05:12.444512600 +0300 4 | @@ -1902,7 +1902,7 @@ 5 | #endif 6 | 7 | 8 | -#if 1 9 | +#if 0 10 | # if 1 11 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) 12 | # define getpagesize rpl_getpagesize 13 | @@ -1987,6 +1987,7 @@ 14 | "use gnulib module getpagesize for portability"); 15 | # endif 16 | #endif 17 | +int getpagesize(void); 18 | 19 | 20 | #if 0 21 | -------------------------------------------------------------------------------- /grep-3.11-utf16.patch: -------------------------------------------------------------------------------- 1 | --- grep-3.11/src/grep.c 2023-11-03 15:48:03.330501300 +0300 2 | +++ grep-3.11/src/grep.c 2023-11-03 15:48:02.897786300 +0300 3 | @@ -479,6 +479,15 @@ 4 | stdout_errno = errno; 5 | } 6 | 7 | +#if defined _WIN32 && ! defined __CYGWIN__ 8 | + 9 | +#define READ_UTF16_AUTO 1 10 | +#define READ_UTF16_BE 2 11 | +#define READ_UTF16_LE 3 12 | +static int read_utf16 = 0; 13 | + 14 | +#endif 15 | + 16 | static struct exclude *excluded_patterns[2]; 17 | static struct exclude *excluded_directory_patterns[2]; 18 | /* Short options. */ 19 | @@ -551,6 +560,11 @@ 20 | {"text", no_argument, NULL, 'a'}, 21 | {"binary", no_argument, NULL, 'U'}, 22 | {"unix-byte-offsets", no_argument, NULL, 'u'}, 23 | +#if defined _WIN32 && ! defined __CYGWIN__ 24 | + {"utf16", no_argument, &read_utf16, READ_UTF16_AUTO}, 25 | + {"utf16-be", no_argument, &read_utf16, READ_UTF16_BE}, 26 | + {"utf16-le", no_argument, &read_utf16, READ_UTF16_LE}, 27 | +#endif 28 | {"version", no_argument, NULL, 'V'}, 29 | {"with-filename", no_argument, NULL, 'H'}, 30 | {"word-regexp", no_argument, NULL, 'w'}, 31 | @@ -793,7 +807,7 @@ 32 | file_must_have_nulls (idx_t size, int fd, struct stat const *st) 33 | { 34 | /* If the file has holes, it must contain a null byte somewhere. */ 35 | - if (SEEK_HOLE != SEEK_SET && !seek_failed 36 | + if (fd != -333 && SEEK_HOLE != SEEK_SET && !seek_failed 37 | && usable_st_size (st) && size < st->st_size) 38 | { 39 | off_t cur = size; 40 | @@ -921,7 +935,7 @@ 41 | bufbeg = buflim = ALIGN_TO (buffer + 1, pagesize); 42 | bufbeg[-1] = eolbyte; 43 | bufdesc = fd; 44 | - bufoffset = fd == STDIN_FILENO ? lseek (fd, 0, SEEK_CUR) : 0; 45 | + bufoffset = fd != -333 && fd == STDIN_FILENO ? lseek (fd, 0, SEEK_CUR) : 0; 46 | seek_failed = bufoffset < 0; 47 | 48 | /* Assume SEEK_DATA fails if SEEK_CUR does. */ 49 | @@ -939,6 +953,10 @@ 50 | return true; 51 | } 52 | 53 | +#if defined _WIN32 && ! defined __CYGWIN__ 54 | +static size_t utf16_to_utf8 (void *buf, size_t count); 55 | +#endif 56 | + 57 | /* Read new stuff into the buffer, saving the specified 58 | amount of old stuff. When we're done, 'bufbeg' points 59 | to the beginning of the buffer contents, and 'buflim' 60 | @@ -977,7 +995,7 @@ 61 | heuristic if we've already read past the file end, as most 62 | likely the file is growing. */ 63 | ptrdiff_t alloc_max = -1; 64 | - if (usable_st_size (st)) 65 | + if (bufdesc != -333 && usable_st_size (st)) 66 | { 67 | off_t to_be_read = st->st_size - bufoffset; 68 | ptrdiff_t a; 69 | @@ -1011,7 +1029,11 @@ 70 | 71 | while (true) 72 | { 73 | - fillsize = safe_read (bufdesc, readbuf, readsize); 74 | + fillsize = 75 | +#if defined _WIN32 && ! defined __CYGWIN__ 76 | + bufdesc == -333 ? utf16_to_utf8 (readbuf, readsize) : 77 | +#endif 78 | + safe_read (bufdesc, readbuf, readsize); 79 | if (fillsize == SAFE_READ_ERROR) 80 | { 81 | fillsize = 0; 82 | @@ -1023,7 +1045,7 @@ 83 | break; 84 | totalnl = add_count (totalnl, fillsize); 85 | 86 | - if (SEEK_DATA != SEEK_SET && !seek_data_failed) 87 | + if (bufdesc != -333 && SEEK_DATA != SEEK_SET && !seek_data_failed) 88 | { 89 | /* Solaris SEEK_DATA fails with errno == ENXIO in a hole at EOF. */ 90 | off_t data_start = lseek (bufdesc, bufoffset, SEEK_DATA); 91 | @@ -1542,7 +1564,7 @@ 92 | if (align_tabs) 93 | { 94 | /* Width is log of maximum number. Line numbers are origin-1. */ 95 | - intmax_t num = usable_st_size (st) ? st->st_size : INTMAX_MAX; 96 | + intmax_t num = fd != -333 && usable_st_size (st) ? st->st_size : INTMAX_MAX; 97 | num += out_line && num < INTMAX_MAX; 98 | do 99 | offset_width++; 100 | @@ -1748,20 +1770,393 @@ 101 | return false; 102 | } 103 | 104 | +#if defined _WIN32 && ! defined __CYGWIN__ 105 | + 106 | +static HANDLE h_file = NULL; 107 | +static HANDLE h_mapping = NULL; 108 | +static const void *mapped_addr = NULL; 109 | +static const void *mapped_end = NULL; 110 | + 111 | +static int try_map_file (const char *filename) 112 | +{ 113 | + if (INVALID_HANDLE_VALUE != (h_file = CreateFile ( 114 | + /*lpFileName:*/filename, 115 | + /*dwDesiredAccess:*/GENERIC_READ, 116 | + /*dwShareMode:*/FILE_SHARE_READ, 117 | + /*lpSecurityAttributes:*/NULL, 118 | + /*dwCreationDisposition:*/OPEN_EXISTING, 119 | + /*dwFlagsAndAttributes:*/FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 120 | + /*hTemplateFile:*/NULL))) 121 | + { 122 | + LARGE_INTEGER sz; 123 | + const DWORD type = GetFileType (h_file); 124 | + if (FILE_TYPE_DISK == type && GetFileSizeEx (h_file, &sz)) 125 | + { 126 | + if (0 == sz.QuadPart) 127 | + { 128 | + CloseHandle (h_file); 129 | + mapped_addr = mapped_end = ""; 130 | + return 0; /* ok, empty file */ 131 | + } 132 | + if ((unsigned long long) sz.QuadPart - 1 >= (size_t) -1) 133 | + { 134 | + CloseHandle (h_file); 135 | + return -2; /* too big file */ 136 | + } 137 | + if (NULL != (h_mapping = CreateFileMapping ( 138 | + /*hFile:*/h_file, 139 | + /*lpAttributes:*/NULL, 140 | + /*flProtect:*/PAGE_READONLY, 141 | + /*dwMaximumSizeHigh:*/0/*map whole file*/, 142 | + /*dwMaximumSizeLow:*/0/*map whole file*/, 143 | + /*lpName:*/NULL/*do not name the mapping*/))) 144 | + { 145 | + if (NULL != (mapped_addr = MapViewOfFile ( 146 | + /*hFileMappingObject:*/h_mapping, 147 | + /*dwDesiredAccess:*/FILE_MAP_READ, 148 | + /*dwFileOffsetHigh:*/0/*read from the beginning*/, 149 | + /*dwFileOffsetLow:*/0/*read from the beginning*/, 150 | + /*dwNumberOfBytesToMap:*/0/*use whole mapping*/))) 151 | + { 152 | + mapped_end = (const char*) mapped_addr + 153 | + (size_t) (unsigned long long) sz.QuadPart; 154 | + return 0; /* success */ 155 | + } 156 | + CloseHandle (h_mapping); 157 | + } 158 | + } 159 | + CloseHandle (h_file); 160 | + } 161 | + return -1; /* failure */ 162 | +} 163 | + 164 | +static void close_mapping (void) 165 | +{ 166 | + if (mapped_addr != mapped_end) 167 | + { 168 | + CloseHandle (h_mapping); 169 | + CloseHandle (h_file); 170 | + } 171 | + mapped_addr = NULL; 172 | + mapped_end = NULL; 173 | +} 174 | + 175 | +static int check_utf16_bom (const unsigned char s[2]) 176 | +{ 177 | + if (0xFE == s[0] && 0xFF == s[1]) 178 | + { 179 | + if (READ_UTF16_LE == read_utf16) 180 | + return -1; 181 | + return READ_UTF16_BE; 182 | + } 183 | + if (0xFF == s[0] && 0xFE == s[1]) 184 | + { 185 | + if (READ_UTF16_BE == read_utf16) 186 | + return -1; 187 | + return READ_UTF16_LE; 188 | + } 189 | + return 0; 190 | +} 191 | + 192 | +#define UTF8_MAX_LEN 4 193 | +typedef unsigned char utf8_char_t; 194 | +typedef unsigned short utf16_char_t; 195 | +typedef unsigned int uint32_least_t; 196 | + 197 | +static unsigned utf16_to_utf8_one (utf8_char_t d[UTF8_MAX_LEN], 198 | + const utf16_char_t w, const utf16_char_t *const s, 199 | + const utf16_char_t *const se) 200 | +{ 201 | + uint32_least_t n, c = w; 202 | + if (c >= 0x80) 203 | + { 204 | + if (c >= 0x800) 205 | + { 206 | + if (0xD800 == (c & 0xFC00)) 207 | + { 208 | + if (s == se) 209 | + return 0; 210 | + n = *s; 211 | + if (0xDC00 != (n & 0xFC00)) 212 | + return 0; 213 | + c = (n << 10) + c - 0x20DC00 + 0x800000 + 0x10000; 214 | + n = 4; 215 | + d[n - 4] = (utf8_char_t) (c >> 18); 216 | + c = (c & 0x3FFFF) + 0x80000; 217 | + } 218 | + else 219 | + { 220 | + n = 3; 221 | + c += 0xE0000; 222 | + } 223 | + d[n - 3] = (utf8_char_t) (c >> 12); 224 | + c = (c & 0xFFF) + 0x2000; 225 | + } 226 | + else 227 | + { 228 | + n = 2; 229 | + c += 0x3000; 230 | + } 231 | + d[n - 2] = (utf8_char_t) (c >> 6); 232 | + c = (c & 0x3F) + 0x80; 233 | + } 234 | + else 235 | + n = 1; 236 | + d[n - 1] = (utf8_char_t) c; 237 | + return (unsigned) n; 238 | +} 239 | + 240 | +static utf16_char_t utf16_revert (utf16_char_t w) 241 | +{ 242 | + return (utf16_char_t) (0xFFFF & ((w << 8) | (w >> 8))); 243 | +} 244 | + 245 | +static unsigned xutf16_to_utf8_one (utf8_char_t d[UTF8_MAX_LEN], 246 | + const utf16_char_t w, const utf16_char_t *const s, 247 | + const utf16_char_t *const se) 248 | +{ 249 | + uint32_least_t n, c = w; 250 | + if (c >= 0x80) 251 | + { 252 | + if (c >= 0x800) 253 | + { 254 | + if (0xD800 == (c & 0xFC00)) 255 | + { 256 | + if (s == se) 257 | + return 0; 258 | + n = utf16_revert (*s); 259 | + if (0xDC00 != (n & 0xFC00)) 260 | + return 0; 261 | + c = (n << 10) + c - 0x20DC00 + 0x800000 + 0x10000; 262 | + n = 4; 263 | + d[n - 4] = (utf8_char_t) (c >> 18); 264 | + c = (c & 0x3FFFF) + 0x80000; 265 | + } 266 | + else 267 | + { 268 | + n = 3; 269 | + c += 0xE0000; 270 | + } 271 | + d[n - 3] = (utf8_char_t) (c >> 12); 272 | + c = (c & 0xFFF) + 0x2000; 273 | + } 274 | + else 275 | + { 276 | + n = 2; 277 | + c += 0x3000; 278 | + } 279 | + d[n - 2] = (utf8_char_t) (c >> 6); 280 | + c = (c & 0x3F) + 0x80; 281 | + } 282 | + else 283 | + n = 1; 284 | + d[n - 1] = (utf8_char_t) c; 285 | + return (unsigned) n; 286 | +} 287 | + 288 | +static size_t utf16_pos = 0; 289 | + 290 | +static utf8_char_t utf8_buf[UTF8_MAX_LEN]; 291 | +static unsigned utf8_offset = 0; 292 | +static unsigned utf8_filled = 0; 293 | + 294 | +static size_t utf16_to_utf8 (void *buf, size_t count) 295 | +{ 296 | + utf8_char_t *d = (utf8_char_t*) buf; 297 | + utf8_char_t *const de = d + count/sizeof(*d); 298 | + 299 | + if (de == d) 300 | + return 0; 301 | + 302 | + if (utf8_offset < utf8_filled) 303 | + { 304 | + const unsigned sz = utf8_filled - utf8_offset; 305 | + const size_t space = (size_t) (de - d); 306 | + const unsigned copy = sz <= space ? sz : (unsigned) space; 307 | + memcpy (d, &utf8_buf[utf8_offset], copy*sizeof (utf8_buf[0])); 308 | + utf8_offset += copy; 309 | + if ((d += copy) == de) 310 | + return (size_t) ((char*) d - (char*) buf); /* full buf is filled */ 311 | + } 312 | + 313 | + const utf16_char_t *s = (const utf16_char_t*) mapped_addr + utf16_pos; 314 | + 315 | + for (;;) 316 | + { 317 | + 318 | + if (read_utf16 == 1) 319 | + { 320 | + while (s < (const utf16_char_t*) mapped_end) 321 | + { 322 | + const utf16_char_t x = *s++; 323 | + 324 | + if (0xFEFF == x) 325 | + continue; /* skip BOM */ 326 | + 327 | + if (0xFFFE == x) 328 | + { 329 | + read_utf16 = 2; /* from now, revert bytes */ 330 | + break; /* skip BOM */ 331 | + } 332 | + 333 | + if (0x0D == x && s < (const utf16_char_t*) mapped_end && 0x0A == *s) 334 | + continue; /* skip CR of CRLF */ 335 | + 336 | + utf8_char_t *const dst = ((size_t) (de - d) >= UTF8_MAX_LEN) ? d : utf8_buf; 337 | + const unsigned sz = utf16_to_utf8_one (dst, x, s, (const utf16_char_t*) mapped_end); 338 | + if (!sz) 339 | + return SAFE_READ_ERROR; /* (size_t)-1 */ 340 | + 341 | + if (UTF8_MAX_LEN == sz) 342 | + s++; 343 | + 344 | + if (dst != d) 345 | + { 346 | + const size_t space = (size_t) (de - d); 347 | + const unsigned copy = sz <= space ? sz : (unsigned) space; 348 | + memcpy (d, utf8_buf, copy*sizeof (utf8_buf[0])); 349 | + if ((d += copy) == de) 350 | + { 351 | + utf8_filled = sz; 352 | + utf8_offset = copy; 353 | + break; 354 | + } 355 | + } 356 | + else if ((d += sz) == de) 357 | + break; 358 | + } 359 | + if (read_utf16 == 1) 360 | + break; 361 | + } 362 | + 363 | + if (read_utf16 != 1) 364 | + { 365 | + while (s < (const utf16_char_t*) mapped_end) 366 | + { 367 | + const utf16_char_t x = utf16_revert (*s++); 368 | + 369 | + if (0xFEFF == x) 370 | + continue; /* skip BOM */ 371 | + 372 | + if (0xFFFE == x) 373 | + { 374 | + read_utf16 = 1; /* from now, do not revert bytes */ 375 | + break; /* skip BOM */ 376 | + } 377 | + 378 | + if (0x0D == x && s < (const utf16_char_t*) mapped_end && 0x0A == utf16_revert (*s)) 379 | + continue; /* skip CR of CRLF */ 380 | + 381 | + utf8_char_t *const dst = ((size_t) (de - d) >= UTF8_MAX_LEN) ? d : utf8_buf; 382 | + const unsigned sz = xutf16_to_utf8_one (dst, x, s, (const utf16_char_t*) mapped_end); 383 | + if (!sz) 384 | + return SAFE_READ_ERROR; /* (size_t)-1 */ 385 | + 386 | + if (UTF8_MAX_LEN == sz) 387 | + s++; 388 | + 389 | + if (dst != d) 390 | + { 391 | + const size_t space = (size_t) (de - d); 392 | + const unsigned copy = sz <= space ? sz : (unsigned) space; 393 | + memcpy (d, utf8_buf, copy*sizeof (utf8_buf[0])); 394 | + if ((d += copy) == de) 395 | + { 396 | + utf8_filled = sz; 397 | + utf8_offset = copy; 398 | + break; 399 | + } 400 | + } 401 | + else if ((d += sz) == de) 402 | + break; 403 | + } 404 | + if (read_utf16 != 1) 405 | + break; 406 | + } 407 | + } 408 | + 409 | + utf16_pos = (size_t) (s - (const utf16_char_t*) mapped_addr); 410 | + 411 | + return (size_t) ((char*) d - (char*) buf); 412 | +} 413 | + 414 | +#endif 415 | + 416 | static bool 417 | grepfile (int dirdesc, char const *name, bool follow, bool command_line) 418 | { 419 | - int oflag = (O_RDONLY | O_NOCTTY 420 | - | (IGNORE_DUPLICATE_BRANCH_WARNING 421 | - (binary ? O_BINARY : 0)) 422 | - | (follow ? 0 : O_NOFOLLOW) 423 | - | (skip_devices (command_line) ? O_NONBLOCK : 0)); 424 | - int desc = openat_safer (dirdesc, name, oflag); 425 | - if (desc < 0) 426 | + int desc; 427 | + 428 | +#if defined _WIN32 && ! defined __CYGWIN__ 429 | + 430 | + /* try to memory-map file */ 431 | + if (read_utf16) 432 | { 433 | - if (follow || ! open_symlink_nofollow_error (errno)) 434 | - suppressible_error (errno); 435 | - return true; 436 | + if (mapped_addr) 437 | + { 438 | + error (0, 0, _("%s: error: cannot create one more mapping"), filename); 439 | + errseen = true; 440 | + return true; 441 | + } 442 | + if (try_map_file (name)) 443 | + { 444 | + error (0, 0, _("%s: error: cannot create mapping, possibly input file is too big"), filename); 445 | + errseen = true; 446 | + return true; 447 | + } 448 | + if ((unsigned long long) ((const char*) mapped_end - (const char*) mapped_addr) & 1) 449 | + { 450 | + error (0, 0, _("%s: error: size of utf16-encoded file is not even: %llu"), 451 | + filename, 452 | + (unsigned long long) ((const char*) mapped_end - (const char*) mapped_addr)); 453 | + errseen = true; 454 | + close_mapping (); 455 | + return true; 456 | + } 457 | + if (mapped_end != mapped_addr) 458 | + { 459 | + const unsigned le = 1; 460 | + const int host_byte_order = 461 | + *(const unsigned char*)&le ? READ_UTF16_LE : READ_UTF16_BE; 462 | + const int file_byte_order = 463 | + check_utf16_bom ((const unsigned char*) mapped_addr); 464 | + 465 | + if (-1 == file_byte_order) 466 | + { 467 | + const char *const file_byte_order_name = 468 | + READ_UTF16_LE == read_utf16 ? "UTF16-BE" : "UTF16-LE"; 469 | + error (0, 0, _("%s: error: file byte order: %s"), filename, 470 | + file_byte_order_name); 471 | + errseen = true; 472 | + close_mapping (); 473 | + return true; 474 | + } 475 | + 476 | + if (READ_UTF16_AUTO == read_utf16) 477 | + read_utf16 = file_byte_order ? file_byte_order : host_byte_order; 478 | + 479 | + read_utf16 = read_utf16 == host_byte_order ? 1 : 2; 480 | + 481 | + if (file_byte_order) 482 | + mapped_addr = (const char*) mapped_addr + 2; /* skip BOM */ 483 | + } 484 | + desc = -333; 485 | + } 486 | + else 487 | +#endif 488 | + { 489 | + int oflag = (O_RDONLY | O_NOCTTY 490 | + | (IGNORE_DUPLICATE_BRANCH_WARNING 491 | + (binary ? O_BINARY : 0)) 492 | + | (follow ? 0 : O_NOFOLLOW) 493 | + | (skip_devices (command_line) ? O_NONBLOCK : 0)); 494 | + desc = openat_safer (dirdesc, name, oflag); 495 | + if (desc < 0) 496 | + { 497 | + if (follow || ! open_symlink_nofollow_error (errno)) 498 | + suppressible_error (errno); 499 | + return true; 500 | + } 501 | } 502 | return grepdesc (desc, command_line); 503 | } 504 | @@ -1801,7 +2196,7 @@ 505 | static void 506 | finalize_input (int fd, struct stat const *st, bool ineof) 507 | { 508 | - if (fd == STDIN_FILENO 509 | + if (fd != -333 && fd == STDIN_FILENO 510 | && (outleft 511 | ? (!ineof 512 | && (seek_failed 513 | @@ -1828,25 +2223,25 @@ 514 | example, normally DESC is a directory only at the top level, but 515 | there is an exception if some other process substitutes a 516 | directory for a non-directory while 'grep' is running. */ 517 | - if (fstat (desc, &st) != 0) 518 | + if (desc != -333 ? fstat (desc, &st) != 0 : stat (filename, &st) != 0) 519 | { 520 | suppressible_error (errno); 521 | goto closeout; 522 | } 523 | 524 | - if (desc != STDIN_FILENO && skip_devices (command_line) 525 | + if (desc != -333 && desc != STDIN_FILENO && skip_devices (command_line) 526 | && is_device_mode (st.st_mode)) 527 | goto closeout; 528 | 529 | if (desc != STDIN_FILENO && command_line 530 | - && skipped_file (filename, true, S_ISDIR (st.st_mode) != 0)) 531 | + && skipped_file (filename, true, desc != -333 && S_ISDIR (st.st_mode) != 0)) 532 | goto closeout; 533 | 534 | /* Don't output file names if invoked as 'grep -r PATTERN NONDIRECTORY'. */ 535 | if (out_file < 0) 536 | - out_file = !!S_ISDIR (st.st_mode); 537 | + out_file = desc != -333 && !!S_ISDIR (st.st_mode); 538 | 539 | - if (desc != STDIN_FILENO 540 | + if (desc != -333 && desc != STDIN_FILENO 541 | && directories == RECURSE_DIRECTORIES && S_ISDIR (st.st_mode)) 542 | { 543 | /* Traverse the directory starting with its full name, because 544 | @@ -1877,7 +2272,7 @@ 545 | suppressible_error (errno); 546 | return status; 547 | } 548 | - if (desc != STDIN_FILENO 549 | + if (desc != -333 && desc != STDIN_FILENO 550 | && ((directories == SKIP_DIRECTORIES && S_ISDIR (st.st_mode)) 551 | || ((devices == SKIP_DEVICES 552 | || (devices == READ_COMMAND_LINE_DEVICES && !command_line)) 553 | @@ -1940,9 +2335,16 @@ 554 | } 555 | 556 | closeout: 557 | - if (desc != STDIN_FILENO && close (desc) != 0) 558 | - suppressible_error (errno); 559 | - return status; 560 | +#if defined _WIN32 && ! defined __CYGWIN__ 561 | + if (desc == -333) 562 | + close_mapping (); 563 | + else 564 | +#endif 565 | + { 566 | + if (desc != STDIN_FILENO && close (desc) != 0) 567 | + suppressible_error (errno); 568 | + return status; 569 | + } 570 | } 571 | 572 | static bool 573 | @@ -2058,6 +2460,17 @@ 574 | --colour[=WHEN] use markers to highlight the matching strings;\n\ 575 | WHEN is 'always', 'never', or 'auto'\n\ 576 | -U, --binary do not strip CR characters at EOL (MSDOS/Windows)\n\ 577 | +")); 578 | +#if defined _WIN32 && ! defined __CYGWIN__ 579 | + printf (_("\ 580 | + --utf16 transcode input file UTF16 -> UTF8, determine file\n\ 581 | + byte order using ByteOrderMark (BOM), if no BOM is\n\ 582 | + present, use host byte order\n\ 583 | + --utf16-be transcode input file UTF16-BE -> UTF8\n\ 584 | + --utf16-le transcode input file UTF16-LE -> UTF8\n\ 585 | +")); 586 | +#endif 587 | + printf (_("\ 588 | \n")); 589 | printf (_("\ 590 | When FILE is '-', read standard input. With no FILE, read '.' if\n\ 591 | -------------------------------------------------------------------------------- /grep-3.11-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/grep-3.11-x64.exe -------------------------------------------------------------------------------- /grep-3.11-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/grep-3.11-x86.exe -------------------------------------------------------------------------------- /grep-3.8-mbtowc-lock.patch: -------------------------------------------------------------------------------- 1 | diff -Naur grep-3.6/lib/mbtowc-lock.h grep-3.6-3/lib/mbtowc-lock.h 2 | --- grep-3.6/lib/mbtowc-lock.h 2020-08-23 12:36:33.000000000 +0300 3 | +++ grep-3.6-3/lib/mbtowc-lock.h 2021-06-30 18:09:59.893281700 +0300 4 | @@ -44,7 +44,7 @@ 5 | 6 | #elif defined _WIN32 && !defined __CYGWIN__ 7 | 8 | -extern __declspec(dllimport) CRITICAL_SECTION *gl_get_mbtowc_lock (void); 9 | +extern /*__declspec(dllimport)*/ CRITICAL_SECTION *gl_get_mbtowc_lock (void); 10 | 11 | static int 12 | mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m) 13 | --- grep-3.6-3/lib/mbtowc-lock.c 2020-08-23 12:36:33.000000000 +0300 14 | +++ grep-3.6/lib/mbtowc-lock.c 2021-06-30 19:41:50.612081700 +0300 15 | @@ -59,7 +59,7 @@ 16 | because the latter is not guaranteed to be a stable ABI in the future. */ 17 | 18 | /* Make sure the function gets exported from DLLs. */ 19 | -DLL_EXPORTED CRITICAL_SECTION *gl_get_mbtowc_lock (void); 20 | +/*DLL_EXPORTED*/ CRITICAL_SECTION *gl_get_mbtowc_lock (void); 21 | 22 | static glwthread_initguard_t guard = GLWTHREAD_INITGUARD_INIT; 23 | static CRITICAL_SECTION lock; 24 | -------------------------------------------------------------------------------- /pcre2/NMakefile-pcre2-10.44: -------------------------------------------------------------------------------- 1 | LIBPCRE2 = pcre2.a 2 | LIBPCRE2POSIX = pcre2posix.a 3 | PCRE2GREP = pcre2grep.exe 4 | 5 | CC = cl 6 | CFLAGS = /Wall /wd4820 /wd4711 /wd4710 /wd5045 /DNDEBUG /I. /Ox /GF /Gy /GS- /GL /EHsc /DHAVE_CONFIG_H /DPCRE2_CODE_UNIT_WIDTH=8 /nologo 7 | SUBSYSTEM = /SUBSYSTEM:CONSOLE 8 | 9 | !IF "$(PLATFORM)" == "x86" 10 | CFLAGS = $(CFLAGS) /D_WIN32_WINNT=0x501 11 | SUBSYSTEM = $(SUBSYSTEM),5.01 12 | !ELSE 13 | !IF "$(PLATFORM)" != "x64" 14 | !ERROR Unknown Platform: "$(PLATFORM)"! 15 | !ENDIF 16 | !ENDIF 17 | 18 | CCFLAGS = $(CFLAGS) /c /Fo 19 | 20 | AR = lib.exe /LTCG 21 | ARFLAGS = /out: 22 | 23 | TEST1 = pcre2test.exe 24 | TEST2 = pcre2_jit_test.exe 25 | TEST3 = pcre2posix_test.exe 26 | TLINK1 = $(CFLAGS) /wd4996 /Fe$(TEST1) /link /LTCG $(SUBSYSTEM) 27 | TLINK2 = $(CFLAGS) /wd4996 /Fe$(TEST2) /link /LTCG $(SUBSYSTEM) 28 | TLINK3 = $(CFLAGS) /wd4996 /Fe$(TEST3) /link /LTCG $(SUBSYSTEM) 29 | 30 | UTIL = testrepl.exe 31 | ULINK = $(CFLAGS) /Fe$(UTIL) /link /LTCG $(SUBSYSTEM) 32 | 33 | PCRE2_TEST_RUN = cmd /c RunTest.bat 34 | PCRE2GREP_TEST_RUN = cmd /c RunGrepTest.bat 35 | TEST_OK = echo.All OK 36 | 37 | PCRE2GREP_LINK = $(CFLAGS) /wd4996 /Fe$(PCRE2GREP) /link /LTCG $(SUBSYSTEM) 38 | 39 | CLEAN = del /q src\*.obj $(LIBPCRE2) $(LIBPCRE2POSIX) $(PCRE2GREP) $(TEST1) $(TEST2) $(TEST3) $(UTIL) *.obj *.ilk *.pdb 2>NUL 40 | 41 | all: $(LIBPCRE2) $(LIBPCRE2POSIX) $(PCRE2GREP) 42 | 43 | src\pcre2_auto_possess.obj : src\pcre2_auto_possess.c 44 | $(CC) src\pcre2_auto_possess.c $(CCFLAGS)src\pcre2_auto_possess.obj 45 | src\pcre2_chartables.obj : src\pcre2_chartables.c 46 | $(CC) src\pcre2_chartables.c $(CCFLAGS)src\pcre2_chartables.obj 47 | src\pcre2_compile.obj : src\pcre2_compile.c 48 | $(CC) src\pcre2_compile.c $(CCFLAGS)src\pcre2_compile.obj 49 | src\pcre2_config.obj : src\pcre2_config.c 50 | $(CC) src\pcre2_config.c $(CCFLAGS)src\pcre2_config.obj 51 | src\pcre2_context.obj : src\pcre2_context.c 52 | $(CC) src\pcre2_context.c $(CCFLAGS)src\pcre2_context.obj 53 | src\pcre2_convert.obj : src\pcre2_convert.c 54 | $(CC) src\pcre2_convert.c $(CCFLAGS)src\pcre2_convert.obj 55 | src\pcre2_dfa_match.obj : src\pcre2_dfa_match.c 56 | $(CC) src\pcre2_dfa_match.c $(CCFLAGS)src\pcre2_dfa_match.obj 57 | src\pcre2_error.obj : src\pcre2_error.c 58 | $(CC) src\pcre2_error.c $(CCFLAGS)src\pcre2_error.obj 59 | src\pcre2_extuni.obj : src\pcre2_extuni.c 60 | $(CC) src\pcre2_extuni.c $(CCFLAGS)src\pcre2_extuni.obj 61 | src\pcre2_find_bracket.obj : src\pcre2_find_bracket.c 62 | $(CC) src\pcre2_find_bracket.c $(CCFLAGS)src\pcre2_find_bracket.obj 63 | src\pcre2_jit_compile.obj : src\pcre2_jit_compile.c 64 | $(CC) src\pcre2_jit_compile.c $(CCFLAGS)src\pcre2_jit_compile.obj 65 | src\pcre2_maketables.obj : src\pcre2_maketables.c 66 | $(CC) src\pcre2_maketables.c $(CCFLAGS)src\pcre2_maketables.obj 67 | src\pcre2_match.obj : src\pcre2_match.c 68 | $(CC) src\pcre2_match.c $(CCFLAGS)src\pcre2_match.obj 69 | src\pcre2_match_data.obj : src\pcre2_match_data.c 70 | $(CC) src\pcre2_match_data.c $(CCFLAGS)src\pcre2_match_data.obj 71 | src\pcre2_newline.obj : src\pcre2_newline.c 72 | $(CC) src\pcre2_newline.c $(CCFLAGS)src\pcre2_newline.obj 73 | src\pcre2_ord2utf.obj : src\pcre2_ord2utf.c 74 | $(CC) src\pcre2_ord2utf.c $(CCFLAGS)src\pcre2_ord2utf.obj 75 | src\pcre2_pattern_info.obj : src\pcre2_pattern_info.c 76 | $(CC) src\pcre2_pattern_info.c $(CCFLAGS)src\pcre2_pattern_info.obj 77 | src\pcre2_script_run.obj : src\pcre2_script_run.c 78 | $(CC) src\pcre2_script_run.c $(CCFLAGS)src\pcre2_script_run.obj 79 | src\pcre2_serialize.obj : src\pcre2_serialize.c 80 | $(CC) src\pcre2_serialize.c $(CCFLAGS)src\pcre2_serialize.obj 81 | src\pcre2_string_utils.obj : src\pcre2_string_utils.c 82 | $(CC) src\pcre2_string_utils.c $(CCFLAGS)src\pcre2_string_utils.obj 83 | src\pcre2_study.obj : src\pcre2_study.c 84 | $(CC) src\pcre2_study.c $(CCFLAGS)src\pcre2_study.obj 85 | src\pcre2_substitute.obj : src\pcre2_substitute.c 86 | $(CC) src\pcre2_substitute.c $(CCFLAGS)src\pcre2_substitute.obj 87 | src\pcre2_substring.obj : src\pcre2_substring.c 88 | $(CC) src\pcre2_substring.c $(CCFLAGS)src\pcre2_substring.obj 89 | src\pcre2_tables.obj : src\pcre2_tables.c 90 | $(CC) src\pcre2_tables.c $(CCFLAGS)src\pcre2_tables.obj 91 | src\pcre2_ucd.obj : src\pcre2_ucd.c 92 | $(CC) src\pcre2_ucd.c $(CCFLAGS)src\pcre2_ucd.obj 93 | src\pcre2_valid_utf.obj : src\pcre2_valid_utf.c 94 | $(CC) src\pcre2_valid_utf.c $(CCFLAGS)src\pcre2_valid_utf.obj 95 | src\pcre2_xclass.obj : src\pcre2_xclass.c 96 | $(CC) src\pcre2_xclass.c $(CCFLAGS)src\pcre2_xclass.obj 97 | src\pcre2_chkdint.obj : src\pcre2_chkdint.c 98 | $(CC) src\pcre2_chkdint.c $(CCFLAGS)src\pcre2_chkdint.obj 99 | src\pcre2posix.obj : src\pcre2posix.c 100 | $(CC) src\pcre2posix.c $(CCFLAGS)src\pcre2posix.obj 101 | 102 | OBJS = \ 103 | src\pcre2_auto_possess.obj \ 104 | src\pcre2_chartables.obj \ 105 | src\pcre2_compile.obj \ 106 | src\pcre2_config.obj \ 107 | src\pcre2_context.obj \ 108 | src\pcre2_convert.obj \ 109 | src\pcre2_dfa_match.obj \ 110 | src\pcre2_error.obj \ 111 | src\pcre2_extuni.obj \ 112 | src\pcre2_find_bracket.obj \ 113 | src\pcre2_jit_compile.obj \ 114 | src\pcre2_maketables.obj \ 115 | src\pcre2_match.obj \ 116 | src\pcre2_match_data.obj \ 117 | src\pcre2_newline.obj \ 118 | src\pcre2_ord2utf.obj \ 119 | src\pcre2_pattern_info.obj \ 120 | src\pcre2_script_run.obj \ 121 | src\pcre2_serialize.obj \ 122 | src\pcre2_string_utils.obj \ 123 | src\pcre2_study.obj \ 124 | src\pcre2_substitute.obj \ 125 | src\pcre2_substring.obj \ 126 | src\pcre2_tables.obj \ 127 | src\pcre2_ucd.obj \ 128 | src\pcre2_valid_utf.obj \ 129 | src\pcre2_xclass.obj \ 130 | src\pcre2_chkdint.obj 131 | 132 | $(LIBPCRE2): $(OBJS) 133 | $(AR) $(ARFLAGS)$(LIBPCRE2) $(OBJS) 134 | 135 | $(LIBPCRE2POSIX): src\pcre2posix.obj 136 | $(AR) $(ARFLAGS)$(LIBPCRE2POSIX) src\pcre2posix.obj 137 | 138 | $(PCRE2GREP): src\pcre2grep.c $(LIBPCRE2) 139 | $(CC) src\pcre2grep.c $(PCRE2GREP_LINK) $(LIBPCRE2) 140 | 141 | $(TEST1): src\pcre2test.c $(LIBPCRE2POSIX) $(LIBPCRE2) 142 | $(CC) src\pcre2test.c $(TLINK1) $(LIBPCRE2POSIX) $(LIBPCRE2) 143 | 144 | $(TEST2): src\pcre2_jit_test.c $(LIBPCRE2POSIX) $(LIBPCRE2) 145 | $(CC) src\pcre2_jit_test.c $(TLINK2) $(LIBPCRE2POSIX) $(LIBPCRE2) 146 | 147 | $(TEST3): src\pcre2posix_test.c $(LIBPCRE2POSIX) $(LIBPCRE2) 148 | $(CC) /DPCRE2_STATIC /Isrc src\pcre2posix_test.c $(TLINK3) $(LIBPCRE2POSIX) $(LIBPCRE2) 149 | 150 | $(UTIL): testrepl.c 151 | $(CC) testrepl.c $(ULINK) 152 | 153 | check: $(TEST1) $(TEST2) $(TEST3) $(UTIL) $(PCRE2GREP) 154 | $(PCRE2_TEST_RUN) 155 | $(PCRE2GREP_TEST_RUN) 156 | $(TEST_OK) 157 | 158 | clean: 159 | $(CLEAN) 160 | -------------------------------------------------------------------------------- /pcre2/RunGrepTest-pcre2-10.44.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/pcre2/RunGrepTest-pcre2-10.44.bat -------------------------------------------------------------------------------- /pcre2/RunTest-pcre2-10.44.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | @rem 3 | @rem MS Windows batch file to run pcre2test on testfiles with the correct 4 | @rem options. This file must use CRLF linebreaks to function properly, 5 | @rem and requires both pcre2test and pcre2grep. 6 | @rem 7 | @rem ------------------------ HISTORY ---------------------------------- 8 | @rem This file was originally contributed to PCRE1 by Ralf Junker, and touched 9 | @rem up by Daniel Richard G. Tests 10-12 added by Philip H. 10 | @rem Philip H also changed test 3 to use "wintest" files. 11 | @rem 12 | @rem Updated by Tom Fortmann to support explicit test numbers on the command 13 | @rem line. Added argument validation and added error reporting. 14 | @rem 15 | @rem Sheri Pierce added logic to skip feature dependent tests 16 | @rem tests 4 5 7 10 12 14 19 and 22 require Unicode support 17 | @rem 8 requires Unicode and link size 2 18 | @rem 16 requires absence of jit support 19 | @rem 17 requires presence of jit support 20 | @rem Sheri P also added override tests for study and jit testing 21 | @rem Zoltan Herczeg added libpcre16 support 22 | @rem Zoltan Herczeg added libpcre32 support 23 | @rem ------------------------------------------------------------------- 24 | @rem 25 | @rem The file was converted for PCRE2 by PH, February 2015. 26 | @rem Updated for new test 14 (moving others up a number), August 2015. 27 | @rem Tidied and updated for new tests 21, 22, 23 by PH, October 2015. 28 | @rem PH added missing "set type" for test 22, April 2016. 29 | @rem PH added copy command for new testbtables file, November 2020 30 | 31 | 32 | setlocal enabledelayedexpansion 33 | if [%srcdir%]==[] ( 34 | if exist testdata\ set srcdir=.) 35 | if [%srcdir%]==[] ( 36 | if exist ..\testdata\ set srcdir=..) 37 | if [%srcdir%]==[] ( 38 | if exist ..\..\testdata\ set srcdir=..\..) 39 | if NOT exist %srcdir%\testdata\ ( 40 | Error: echo distribution testdata folder not found! 41 | call :conferror 42 | exit /b 1 43 | goto :eof 44 | ) 45 | 46 | if [%pcre2test%]==[] set pcre2test=.\pcre2test.exe 47 | 48 | echo source dir is %srcdir% 49 | echo pcre2test=%pcre2test% 50 | 51 | if NOT exist %pcre2test% ( 52 | echo Error: %pcre2test% not found! 53 | echo. 54 | call :conferror 55 | exit /b 1 56 | ) 57 | 58 | %pcre2test% -C linksize >NUL 59 | set link_size=%ERRORLEVEL% 60 | %pcre2test% -C pcre2-8 >NUL 61 | set support8=%ERRORLEVEL% 62 | %pcre2test% -C pcre2-16 >NUL 63 | set support16=%ERRORLEVEL% 64 | %pcre2test% -C pcre2-32 >NUL 65 | set support32=%ERRORLEVEL% 66 | %pcre2test% -C unicode >NUL 67 | set unicode=%ERRORLEVEL% 68 | %pcre2test% -C jit >NUL 69 | set jit=%ERRORLEVEL% 70 | %pcre2test% -C backslash-C >NUL 71 | set supportBSC=%ERRORLEVEL% 72 | 73 | if %support8% EQU 1 ( 74 | if not exist testout8 md testout8 75 | if not exist testoutjit8 md testoutjit8 76 | ) 77 | 78 | if %support16% EQU 1 ( 79 | if not exist testout16 md testout16 80 | if not exist testoutjit16 md testoutjit16 81 | ) 82 | 83 | if %support16% EQU 1 ( 84 | if not exist testout32 md testout32 85 | if not exist testoutjit32 md testoutjit32 86 | ) 87 | 88 | set do1=no 89 | set do2=no 90 | set do3=no 91 | set do4=no 92 | set do5=no 93 | set do6=no 94 | set do7=no 95 | set do8=no 96 | set do9=no 97 | set do10=no 98 | set do11=no 99 | set do12=no 100 | set do13=no 101 | set do14=no 102 | set do15=no 103 | set do16=no 104 | set do17=no 105 | set do18=no 106 | set do19=no 107 | set do20=no 108 | set do21=no 109 | set do22=no 110 | set do23=no 111 | set do24=no 112 | set do25=no 113 | set do26=no 114 | set all=yes 115 | 116 | for %%a in (%*) do ( 117 | set valid=no 118 | for %%v in (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26) do if %%v == %%a set valid=yes 119 | if "!valid!" == "yes" ( 120 | set do%%a=yes 121 | set all=no 122 | ) else ( 123 | echo Invalid test number - %%a! 124 | echo Usage %0 [ test_number ] ... 125 | echo Where test_number is one or more optional test numbers 1 through 23, default is all tests. 126 | exit /b 1 127 | ) 128 | ) 129 | set failed="no" 130 | 131 | if "%all%" == "yes" ( 132 | set do1=yes 133 | set do2=yes 134 | set do3=yes 135 | set do4=yes 136 | set do5=yes 137 | set do6=yes 138 | set do7=yes 139 | set do8=yes 140 | set do9=yes 141 | set do10=no 142 | set do11=yes 143 | set do12=no 144 | set do13=yes 145 | set do14=yes 146 | set do15=yes 147 | set do16=yes 148 | set do17=yes 149 | set do18=yes 150 | set do19=yes 151 | set do20=yes 152 | set do21=yes 153 | set do22=yes 154 | set do23=yes 155 | set do24=yes 156 | set do25=yes 157 | set do26=yes 158 | ) 159 | 160 | @echo RunTest.bat's pcre2test output is written to newly created subfolders 161 | @echo named testout{8,16,32} and testoutjit{8,16,32}. 162 | @echo. 163 | 164 | set mode= 165 | set bits=8 166 | 167 | :nextMode 168 | if "%mode%" == "" ( 169 | if %support8% EQU 0 goto modeSkip 170 | echo. 171 | echo ---- Testing 8-bit library ---- 172 | echo. 173 | ) 174 | if "%mode%" == "-16" ( 175 | if %support16% EQU 0 goto modeSkip 176 | echo. 177 | echo ---- Testing 16-bit library ---- 178 | echo. 179 | ) 180 | if "%mode%" == "-32" ( 181 | if %support32% EQU 0 goto modeSkip 182 | echo. 183 | echo ---- Testing 32-bit library ---- 184 | echo. 185 | ) 186 | if "%do1%" == "yes" call :do1 187 | if "%do2%" == "yes" call :do2 188 | if "%do3%" == "yes" call :do3 189 | if "%do4%" == "yes" call :do4 190 | if "%do5%" == "yes" call :do5 191 | if "%do6%" == "yes" call :do6 192 | if "%do7%" == "yes" call :do7 193 | if "%do8%" == "yes" call :do8 194 | if "%do9%" == "yes" call :do9 195 | if "%do10%" == "yes" call :do10 196 | if "%do11%" == "yes" call :do11 197 | if "%do12%" == "yes" call :do12 198 | if "%do13%" == "yes" call :do13 199 | if "%do14%" == "yes" call :do14 200 | if "%do15%" == "yes" call :do15 201 | if "%do16%" == "yes" call :do16 202 | if "%do17%" == "yes" call :do17 203 | if "%do18%" == "yes" call :do18 204 | if "%do19%" == "yes" call :do19 205 | if "%do20%" == "yes" call :do20 206 | if "%do21%" == "yes" call :do21 207 | if "%do22%" == "yes" call :do22 208 | if "%do23%" == "yes" call :do23 209 | if "%do24%" == "yes" call :do24 210 | if "%do25%" == "yes" call :do25 211 | if "%do26%" == "yes" call :do26 212 | :modeSkip 213 | if "%mode%" == "" ( 214 | set mode=-16 215 | set bits=16 216 | goto nextMode 217 | ) 218 | if "%mode%" == "-16" ( 219 | set mode=-32 220 | set bits=32 221 | goto nextMode 222 | ) 223 | 224 | @rem If mode is -32, testing is finished 225 | if %failed% == "yes" ( 226 | echo In above output, one or more of the various tests failed! 227 | exit /b 1 228 | ) 229 | echo All OK 230 | goto :eof 231 | 232 | :runsub 233 | @rem Function to execute pcre2test and compare the output 234 | @rem Arguments are as follows: 235 | @rem 236 | @rem 1 = test number 237 | @rem 2 = outputdir 238 | @rem 3 = test name use double quotes 239 | @rem 4 - 9 = pcre2test options 240 | 241 | if [%1] == [] ( 242 | echo Missing test number argument! 243 | exit /b 1 244 | ) 245 | 246 | if [%2] == [] ( 247 | echo Missing outputdir! 248 | exit /b 1 249 | ) 250 | 251 | if [%3] == [] ( 252 | echo Missing test name argument! 253 | exit /b 1 254 | ) 255 | 256 | if %1 == 8 ( 257 | set outnum=8-%bits%-%link_size% 258 | ) else ( 259 | set outnum=%1 260 | ) 261 | set testinput=testinput%1 262 | set testoutput=testoutput%outnum% 263 | if exist %srcdir%\testdata\win%testinput% ( 264 | set testinput=wintestinput%1 265 | set testoutput=wintestoutput%outnum% 266 | ) 267 | 268 | echo Test %1: %3 269 | %pcre2test% %mode% %4 %5 %6 %7 %8 %9 %srcdir%\testdata\%testinput% >%2%bits%\%testoutput% 270 | if errorlevel 1 ( 271 | echo. failed executing command-line: 272 | echo. %pcre2test% %mode% %4 %5 %6 %7 %8 %9 %srcdir%\testdata\%testinput% ^>%2%bits%\%testoutput% 273 | set failed="yes" 274 | goto :eof 275 | ) else if [%1]==[2] ( 276 | %pcre2test% %mode% %4 %5 %6 %7 %8 %9 -error -70,-62,-2,-1,0,100,101,191,300 >>%2%bits%\%testoutput% 277 | ) 278 | 279 | @rem test etalon data is good for 64-bit pcre2test executable but it is wrong for 32-bit pcre2test 280 | @rem - due to smaller inner structures (pointers are 32-bit, size_t is also 34-bit) 281 | @rem don't touch test etalon data, but fix test output instead (increase reported sizes) 282 | if %1 == 8 ( 283 | find "Memory allocation - compiled block : 119" %2%bits%\%testoutput% >NUL && ( 284 | <%2%bits%\%testoutput% .\testrepl.exe +590 35 ^ 285 | | .\testrepl.exe +591 33 ^ 286 | | .\testrepl.exe +894 36 ^ 287 | | .\testrepl.exe +895 31 ^ 288 | | .\testrepl.exe +1245 35 ^ 289 | | .\testrepl.exe +1246 39 ^ 290 | | .\testrepl.exe +1594 37 ^ 291 | | .\testrepl.exe +1595 37 ^ 292 | | .\testrepl.exe +1882 34 ^ 293 | | .\testrepl.exe +1883 33 ^ 294 | | .\testrepl.exe +2236 34 ^ 295 | | .\testrepl.exe +2237 35 ^ 296 | | .\testrepl.exe +2598 34 ^ 297 | | .\testrepl.exe +2599 35 ^ 298 | | .\testrepl.exe +2867 34 ^ 299 | | .\testrepl.exe +2868 35 ^ 300 | | .\testrepl.exe +3140 34 ^ 301 | | .\testrepl.exe +3141 39 ^ 302 | | .\testrepl.exe +3426 35 ^ 303 | | .\testrepl.exe +3427 34 ^ 304 | | .\testrepl.exe +3779 35 ^ 305 | | .\testrepl.exe +3780 36 ^ 306 | | .\testrepl.exe +4764 36 ^ 307 | | .\testrepl.exe +4765 32 ^ 308 | | .\testrepl.exe +5975 35 ^ 309 | | .\testrepl.exe +5976 32 ^ 310 | | .\testrepl.exe +6663 35 ^ 311 | | .\testrepl.exe +6664 38 ^ 312 | | .\testrepl.exe +6990 36 ^ 313 | | .\testrepl.exe +6991 34 ^ 314 | | .\testrepl.exe +7370 32 ^ 315 | | .\testrepl.exe +7371 30 ^ 316 | | .\testrepl.exe +7372 30 ^ 317 | | .\testrepl.exe +7771 39 ^ 318 | | .\testrepl.exe +7772 33 ^ 319 | | .\testrepl.exe +8198 37 ^ 320 | | .\testrepl.exe +8199 34 ^ 321 | | .\testrepl.exe +8592 36 ^ 322 | | .\testrepl.exe +8593 37 ^ 323 | | .\testrepl.exe +8945 38 ^ 324 | | .\testrepl.exe +8946 39 ^ 325 | | .\testrepl.exe +9404 34 ^ 326 | | .\testrepl.exe +9405 36 ^ 327 | | .\testrepl.exe +9686 34 ^ 328 | | .\testrepl.exe +9687 37 ^ 329 | | .\testrepl.exe +9970 34 ^ 330 | | .\testrepl.exe +9971 38 ^ 331 | | .\testrepl.exe +10256 34 ^ 332 | | .\testrepl.exe +10257 38 ^ 333 | | .\testrepl.exe +10543 34 ^ 334 | | .\testrepl.exe +10544 38 ^ 335 | | .\testrepl.exe +10932 34 ^ 336 | | .\testrepl.exe +10933 36 ^ 337 | | .\testrepl.exe +11214 34 ^ 338 | | .\testrepl.exe +11215 36 ^ 339 | | .\testrepl.exe +11492 34 ^ 340 | | .\testrepl.exe +11493 36 ^ 341 | | .\testrepl.exe +11769 34 ^ 342 | | .\testrepl.exe +11770 36 ^ 343 | | .\testrepl.exe +12076 35 ^ 344 | | .\testrepl.exe +12077 34 ^ 345 | | .\testrepl.exe +12497 35 ^ 346 | | .\testrepl.exe +12498 35 ^ 347 | | .\testrepl.exe +12927 35 ^ 348 | | .\testrepl.exe +12928 35 ^ 349 | | .\testrepl.exe +13340 34 ^ 350 | | .\testrepl.exe +13341 36 ^ 351 | | .\testrepl.exe +13624 38 ^ 352 | | .\testrepl.exe +13625 33 ^ 353 | | .\testrepl.exe +13925 35 ^ 354 | | .\testrepl.exe +13926 34 ^ 355 | | .\testrepl.exe +14235 35 ^ 356 | | .\testrepl.exe +14236 34 ^ 357 | | .\testrepl.exe +14629 35 ^ 358 | | .\testrepl.exe +14630 31 ^ 359 | | .\testrepl.exe +14908 35 ^ 360 | | .\testrepl.exe +14909 31 ^ 361 | | .\testrepl.exe +15186 35 ^ 362 | | .\testrepl.exe +15187 31 ^ 363 | | .\testrepl.exe +15465 35 ^ 364 | | .\testrepl.exe +15466 31 ^ 365 | | .\testrepl.exe +15757 38 ^ 366 | | .\testrepl.exe +15758 36 ^ 367 | | .\testrepl.exe +16049 35 ^ 368 | | .\testrepl.exe +16050 31 ^ 369 | | .\testrepl.exe +16335 38 ^ 370 | | .\testrepl.exe +16336 34 ^ 371 | | .\testrepl.exe +16650 36 ^ 372 | | .\testrepl.exe +16651 31 ^ 373 | | .\testrepl.exe +16983 36 ^ 374 | | .\testrepl.exe +16984 31 ^ 375 | | .\testrepl.exe +17302 35 ^ 376 | | .\testrepl.exe +17303 33 ^ 377 | | .\testrepl.exe +17603 37 ^ 378 | | .\testrepl.exe +17604 34 ^ 379 | | .\testrepl.exe +18014 36 ^ 380 | | .\testrepl.exe +18015 36 ^ 381 | | .\testrepl.exe +18384 34 ^ 382 | | .\testrepl.exe +18385 35 ^ 383 | | .\testrepl.exe +18654 34 ^ 384 | | .\testrepl.exe +18655 35 ^ 385 | | .\testrepl.exe +18924 34 ^ 386 | | .\testrepl.exe +18925 35 ^ 387 | | .\testrepl.exe +19202 34 ^ 388 | | .\testrepl.exe +19203 36 ^ 389 | | .\testrepl.exe +19476 34 ^ 390 | | .\testrepl.exe +19477 35 ^ 391 | | .\testrepl.exe +19750 34 ^ 392 | | .\testrepl.exe +19751 35 ^ 393 | | .\testrepl.exe +20024 34 ^ 394 | | .\testrepl.exe +20025 35 ^ 395 | | .\testrepl.exe +20306 34 ^ 396 | | .\testrepl.exe +20307 36 ^ 397 | >%2%bits%\%testoutput%.x 398 | del /q %2%bits%\%testoutput% 399 | ren %2%bits%\%testoutput%.x %testoutput% 400 | ) 401 | ) 402 | 403 | set type= 404 | if [%1]==[11] ( 405 | set type=-%bits% 406 | ) 407 | if [%1]==[12] ( 408 | set type=-%bits% 409 | ) 410 | if [%1]==[14] ( 411 | set type=-%bits% 412 | ) 413 | if [%1]==[22] ( 414 | set type=-%bits% 415 | ) 416 | 417 | fc /n %srcdir%\testdata\%testoutput%%type% %2%bits%\%testoutput% >NUL 418 | 419 | if errorlevel 1 ( 420 | echo. failed comparison: fc /n %srcdir%\testdata\%testoutput% %2%bits%\%testoutput% 421 | if [%1]==[3] ( 422 | echo. 423 | echo ** Test 3 failure usually means french locale is not 424 | echo ** available on the system, rather than a bug or problem with PCRE2. 425 | echo. 426 | goto :eof 427 | ) 428 | 429 | set failed="yes" 430 | goto :eof 431 | ) 432 | 433 | echo. Passed. 434 | goto :eof 435 | 436 | :do1 437 | call :runsub 1 testout "Main non-UTF, non-UCP functionality (Compatible with Perl >= 5.10)" -q 438 | if %jit% EQU 1 call :runsub 1 testoutjit "Test with JIT Override" -q -jit 439 | goto :eof 440 | 441 | :do2 442 | copy /y %srcdir%\testdata\testbtables testbtables 443 | call :runsub 2 testout "API, errors, internals, and non-Perl stuff" -q 444 | if %jit% EQU 1 call :runsub 2 testoutjit "Test with JIT Override" -q -jit 445 | goto :eof 446 | 447 | :do3 448 | call :runsub 3 testout "Locale-specific features" -q 449 | if %jit% EQU 1 call :runsub 3 testoutjit "Test with JIT Override" -q -jit 450 | goto :eof 451 | 452 | :do4 453 | if %unicode% EQU 0 ( 454 | echo Test 4 Skipped due to absence of Unicode support. 455 | goto :eof 456 | ) 457 | call :runsub 4 testout "UTF-%bits% and Unicode property support - (Compatible with Perl >= 5.10)" -q 458 | if %jit% EQU 1 call :runsub 4 testoutjit "Test with JIT Override" -q -jit 459 | goto :eof 460 | 461 | :do5 462 | if %unicode% EQU 0 ( 463 | echo Test 5 Skipped due to absence of Unicode support. 464 | goto :eof 465 | ) 466 | call :runsub 5 testout "API, internals, and non-Perl stuff for UTF-%bits% and UCP" -q 467 | if %jit% EQU 1 call :runsub 5 testoutjit "Test with JIT Override" -q -jit 468 | goto :eof 469 | 470 | :do6 471 | call :runsub 6 testout "DFA matching main non-UTF, non-UCP functionality" -q 472 | goto :eof 473 | 474 | :do7 475 | if %unicode% EQU 0 ( 476 | echo Test 7 Skipped due to absence of Unicode support. 477 | goto :eof 478 | ) 479 | call :runsub 7 testout "DFA matching with UTF-%bits% and Unicode property support" -q 480 | goto :eof 481 | 482 | :do8 483 | if NOT %link_size% EQU 2 ( 484 | echo Test 8 Skipped because link size is not 2. 485 | goto :eof 486 | ) 487 | if %unicode% EQU 0 ( 488 | echo Test 8 Skipped due to absence of Unicode support. 489 | goto :eof 490 | ) 491 | call :runsub 8 testout "Internal offsets and code size tests" -q 492 | goto :eof 493 | 494 | :do9 495 | if NOT %bits% EQU 8 ( 496 | echo Test 9 Skipped when running 16/32-bit tests. 497 | goto :eof 498 | ) 499 | call :runsub 9 testout "Specials for the basic 8-bit library" -q 500 | if %jit% EQU 1 call :runsub 9 testoutjit "Test with JIT Override" -q -jit 501 | goto :eof 502 | 503 | :do10 504 | if NOT %bits% EQU 8 ( 505 | echo Test 10 Skipped when running 16/32-bit tests. 506 | goto :eof 507 | ) 508 | if %unicode% EQU 0 ( 509 | echo Test 10 Skipped due to absence of Unicode support. 510 | goto :eof 511 | ) 512 | call :runsub 10 testout "Specials for the 8-bit library with Unicode support" -q 513 | if %jit% EQU 1 call :runsub 10 testoutjit "Test with JIT Override" -q -jit 514 | goto :eof 515 | 516 | :do11 517 | if %bits% EQU 8 ( 518 | echo Test 11 Skipped when running 8-bit tests. 519 | goto :eof 520 | ) 521 | call :runsub 11 testout "Specials for the basic 16/32-bit library" -q 522 | if %jit% EQU 1 call :runsub 11 testoutjit "Test with JIT Override" -q -jit 523 | goto :eof 524 | 525 | :do12 526 | if %bits% EQU 8 ( 527 | echo Test 12 Skipped when running 8-bit tests. 528 | goto :eof 529 | ) 530 | if %unicode% EQU 0 ( 531 | echo Test 12 Skipped due to absence of Unicode support. 532 | goto :eof 533 | ) 534 | call :runsub 12 testout "Specials for the 16/32-bit library with Unicode support" -q 535 | if %jit% EQU 1 call :runsub 12 testoutjit "Test with JIT Override" -q -jit 536 | goto :eof 537 | 538 | :do13 539 | if %bits% EQU 8 ( 540 | echo Test 13 Skipped when running 8-bit tests. 541 | goto :eof 542 | ) 543 | call :runsub 13 testout "DFA specials for the basic 16/32-bit library" -q 544 | goto :eof 545 | 546 | :do14 547 | if %unicode% EQU 0 ( 548 | echo Test 14 Skipped due to absence of Unicode support. 549 | goto :eof 550 | ) 551 | call :runsub 14 testout "DFA specials for UTF and UCP support" -q 552 | goto :eof 553 | 554 | :do15 555 | call :runsub 15 testout "Non-JIT limits and other non_JIT tests" -q 556 | goto :eof 557 | 558 | :do16 559 | if %jit% EQU 1 ( 560 | echo Test 16 Skipped due to presence of JIT support. 561 | goto :eof 562 | ) 563 | call :runsub 16 testout "JIT-specific features when JIT is not available" -q 564 | goto :eof 565 | 566 | :do17 567 | if %jit% EQU 0 ( 568 | echo Test 17 Skipped due to absence of JIT support. 569 | goto :eof 570 | ) 571 | call :runsub 17 testout "JIT-specific features when JIT is available" -q 572 | goto :eof 573 | 574 | :do18 575 | if %bits% EQU 16 ( 576 | echo Test 18 Skipped when running 16-bit tests. 577 | goto :eof 578 | ) 579 | if %bits% EQU 32 ( 580 | echo Test 18 Skipped when running 32-bit tests. 581 | goto :eof 582 | ) 583 | call :runsub 18 testout "POSIX interface, excluding UTF-8 and UCP" -q 584 | goto :eof 585 | 586 | :do19 587 | if %bits% EQU 16 ( 588 | echo Test 19 Skipped when running 16-bit tests. 589 | goto :eof 590 | ) 591 | if %bits% EQU 32 ( 592 | echo Test 19 Skipped when running 32-bit tests. 593 | goto :eof 594 | ) 595 | if %unicode% EQU 0 ( 596 | echo Test 19 Skipped due to absence of Unicode support. 597 | goto :eof 598 | ) 599 | call :runsub 19 testout "POSIX interface with UTF-8 and UCP" -q 600 | goto :eof 601 | 602 | :do20 603 | call :runsub 20 testout "Serialization tests" -q 604 | goto :eof 605 | 606 | :do21 607 | if %supportBSC% EQU 0 ( 608 | echo Test 21 Skipped due to absence of backslash-C support. 609 | goto :eof 610 | ) 611 | call :runsub 21 testout "Backslash-C tests without UTF" -q 612 | call :runsub 21 testout "Backslash-C tests without UTF (DFA)" -q -dfa 613 | if %jit% EQU 1 call :runsub 21 testoutjit "Test with JIT Override" -q -jit 614 | goto :eof 615 | 616 | :do22 617 | if %supportBSC% EQU 0 ( 618 | echo Test 22 Skipped due to absence of backslash-C support. 619 | goto :eof 620 | ) 621 | if %unicode% EQU 0 ( 622 | echo Test 22 Skipped due to absence of Unicode support. 623 | goto :eof 624 | ) 625 | call :runsub 22 testout "Backslash-C tests with UTF" -q 626 | if %jit% EQU 1 call :runsub 22 testoutjit "Test with JIT Override" -q -jit 627 | goto :eof 628 | 629 | :do23 630 | if %supportBSC% EQU 1 ( 631 | echo Test 23 Skipped due to presence of backslash-C support. 632 | goto :eof 633 | ) 634 | call :runsub 23 testout "Backslash-C disabled test" -q 635 | goto :eof 636 | 637 | :do24 638 | call :runsub 24 testout "Non-UTF pattern conversion tests" -q 639 | goto :eof 640 | 641 | :do25 642 | if %unicode% EQU 0 ( 643 | echo Test 25 Skipped due to absence of Unicode support. 644 | goto :eof 645 | ) 646 | call :runsub 25 testout "UTF pattern conversion tests" -q 647 | goto :eof 648 | 649 | :do26 650 | if %unicode% EQU 0 ( 651 | echo Test 26 Skipped due to absence of Unicode support. 652 | goto :eof 653 | ) 654 | call :runsub 26 testout "Auto-generated unicode property tests" -q 655 | if %jit% EQU 1 call :runsub 26 testoutjit "Test with JIT Override" -q -jit 656 | goto :eof 657 | 658 | :conferror 659 | @echo. 660 | @echo Either your build is incomplete or you have a configuration error. 661 | @echo. 662 | @echo If configured with cmake and executed via "make test" or the MSVC "RUN_TESTS" 663 | @echo project, pcre2_test.bat defines variables and automatically calls RunTest.bat. 664 | @echo For manual testing of all available features, after configuring with cmake 665 | @echo and building, you can run the built pcre2_test.bat. For best results with 666 | @echo cmake builds and tests avoid directories with full path names that include 667 | @echo spaces for source or build. 668 | @echo. 669 | @echo Otherwise, if the build dir is in a subdir of the source dir, testdata needed 670 | @echo for input and verification should be found automatically when (from the 671 | @echo location of the the built exes) you call RunTest.bat. By default RunTest.bat 672 | @echo runs all tests compatible with the linked pcre2 library but it can be given 673 | @echo a test number as an argument. 674 | @echo. 675 | @echo If the build dir is not under the source dir you can either copy your exes 676 | @echo to the source folder or copy RunTest.bat and the testdata folder to the 677 | @echo location of your built exes and then run RunTest.bat. 678 | @echo. 679 | goto :eof 680 | -------------------------------------------------------------------------------- /pcre2/config-pcre2-10.44.h: -------------------------------------------------------------------------------- 1 | /* src/config.h. Generated from config.h.in by configure. */ 2 | /* src/config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* PCRE2 is written in Standard C, but there are a few non-standard things it 5 | can cope with, allowing it to run on SunOS4 and other "close to standard" 6 | systems. 7 | 8 | In environments that support the GNU autotools, config.h.in is converted into 9 | config.h by the "configure" script. In environments that use CMake, 10 | config-cmake.in is converted into config.h. If you are going to build PCRE2 "by 11 | hand" without using "configure" or CMake, you should copy the distributed 12 | config.h.generic to config.h, and edit the macro definitions to be the way you 13 | need them. You must then add -DHAVE_CONFIG_H to all of your compile commands, 14 | so that config.h is included at the start of every source. 15 | 16 | Alternatively, you can avoid editing by using -D on the compiler command line 17 | to set the macro values. In this case, you do not have to set -DHAVE_CONFIG_H, 18 | but if you do, default values will be taken from config.h for non-boolean 19 | macros that are not defined on the command line. 20 | 21 | Boolean macros such as HAVE_STDLIB_H and SUPPORT_PCRE2_8 should either be 22 | defined (conventionally to 1) for TRUE, and not defined at all for FALSE. All 23 | such macros are listed as a commented #undef in config.h.generic. Macros such 24 | as MATCH_LIMIT, whose actual value is relevant, have defaults defined, but are 25 | surrounded by #ifndef/#endif lines so that the value can be overridden by -D. 26 | 27 | PCRE2 uses memmove() if HAVE_MEMMOVE is defined; otherwise it uses bcopy() if 28 | HAVE_BCOPY is defined. If your system has neither bcopy() nor memmove(), make 29 | sure both macros are undefined; an emulation function will then be used. */ 30 | 31 | /* By default, the \R escape sequence matches any Unicode line ending 32 | character or sequence of characters. If BSR_ANYCRLF is defined (to any 33 | value), this is changed so that backslash-R matches only CR, LF, or CRLF. 34 | The build-time default can be overridden by the user of PCRE2 at runtime. 35 | */ 36 | /* #undef BSR_ANYCRLF */ 37 | 38 | /* Define to any value to disable the use of the z and t modifiers in 39 | formatting settings such as %zu or %td (this is rarely needed). */ 40 | /* #undef DISABLE_PERCENT_ZT */ 41 | 42 | /* If you are compiling for a system that uses EBCDIC instead of ASCII 43 | character codes, define this macro to any value. When EBCDIC is set, PCRE2 44 | assumes that all input strings are in EBCDIC. If you do not define this 45 | macro, PCRE2 will assume input strings are ASCII or UTF-8/16/32 Unicode. It 46 | is not possible to build a version of PCRE2 that supports both EBCDIC and 47 | UTF-8/16/32. */ 48 | /* #undef EBCDIC */ 49 | 50 | /* In an EBCDIC environment, define this macro to any value to arrange for the 51 | NL character to be 0x25 instead of the default 0x15. NL plays the role that 52 | LF does in an ASCII/Unicode environment. */ 53 | /* #undef EBCDIC_NL25 */ 54 | 55 | /* Define this if your compiler supports __attribute__((uninitialized)) */ 56 | /* #undef HAVE_ATTRIBUTE_UNINITIALIZED */ 57 | 58 | /* Define to 1 if you have the 'bcopy' function. */ 59 | /* #undef HAVE_BCOPY */ 60 | 61 | /* Define this if your compiler provides __builtin_mul_overflow() */ 62 | /* #undef HAVE_BUILTIN_MUL_OVERFLOW */ 63 | 64 | /* Define to 1 if you have the header file. */ 65 | /* #undef HAVE_BZLIB_H */ 66 | 67 | /* Define to 1 if you have the header file. */ 68 | /* #undef HAVE_DIRENT_H */ 69 | 70 | /* Define to 1 if you have the header file. */ 71 | /* #undef HAVE_DLFCN_H */ 72 | 73 | /* Define to 1 if you have the header file. */ 74 | /* #undef HAVE_EDITLINE_READLINE_H */ 75 | 76 | /* Define to 1 if you have the header file. */ 77 | /* #undef HAVE_EDIT_READLINE_READLINE_H */ 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_INTTYPES_H 1 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_LIMITS_H 1 84 | 85 | /* Define to 1 if you have the 'memfd_create' function. */ 86 | /* #undef HAVE_MEMFD_CREATE */ 87 | 88 | /* Define to 1 if you have the 'memmove' function. */ 89 | #define HAVE_MEMMOVE 1 90 | 91 | /* Define to 1 if you have the header file. */ 92 | /* #undef HAVE_MINIX_CONFIG_H */ 93 | 94 | /* Define to 1 if you have the 'mkostemp' function. */ 95 | /* #undef HAVE_MKOSTEMP */ 96 | 97 | /* Define if you have POSIX threads libraries and header files. */ 98 | /* #undef HAVE_PTHREAD */ 99 | 100 | /* Have PTHREAD_PRIO_INHERIT. */ 101 | /* #undef HAVE_PTHREAD_PRIO_INHERIT */ 102 | 103 | /* Define to 1 if you have the header file. */ 104 | /* #undef HAVE_READLINE_H */ 105 | 106 | /* Define to 1 if you have the header file. */ 107 | /* #undef HAVE_READLINE_HISTORY_H */ 108 | 109 | /* Define to 1 if you have the header file. */ 110 | /* #undef HAVE_READLINE_READLINE_H */ 111 | 112 | /* Define to 1 if you have the `realpath' function. */ 113 | /* #undef HAVE_REALPATH */ 114 | 115 | /* Define to 1 if you have the 'secure_getenv' function. */ 116 | /* #undef HAVE_SECURE_GETENV */ 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #define HAVE_STDINT_H 1 120 | 121 | /* Define to 1 if you have the header file. */ 122 | #define HAVE_STDIO_H 1 123 | 124 | /* Define to 1 if you have the header file. */ 125 | #define HAVE_STDLIB_H 1 126 | 127 | /* Define to 1 if you have the 'strerror' function. */ 128 | #define HAVE_STRERROR 1 129 | 130 | /* Define to 1 if you have the header file. */ 131 | /* #undef HAVE_STRINGS_H */ 132 | 133 | /* Define to 1 if you have the header file. */ 134 | #define HAVE_STRING_H 1 135 | 136 | /* Define to 1 if you have the header file. */ 137 | #define HAVE_SYS_STAT_H 1 138 | 139 | /* Define to 1 if you have the header file. */ 140 | #define HAVE_SYS_TYPES_H 1 141 | 142 | /* Define to 1 if you have the header file. */ 143 | /* #undef HAVE_SYS_WAIT_H */ 144 | 145 | /* Define to 1 if you have the header file. */ 146 | /* #undef HAVE_UNISTD_H */ 147 | 148 | /* Define to 1 if the compiler supports simple visibility declarations. */ 149 | /* #undef HAVE_VISIBILITY */ 150 | 151 | /* Define to 1 if you have the header file. */ 152 | #define HAVE_WCHAR_H 1 153 | 154 | /* Define to 1 if you have the header file. */ 155 | #define HAVE_WINDOWS_H 1 156 | 157 | /* Define to 1 if you have the header file. */ 158 | /* #undef HAVE_ZLIB_H */ 159 | 160 | /* This limits the amount of memory that may be used while matching a pattern. 161 | It applies to both pcre2_match() and pcre2_dfa_match(). It does not apply 162 | to JIT matching. The value is in kibibytes (units of 1024 bytes). */ 163 | #ifndef HEAP_LIMIT 164 | #define HEAP_LIMIT 20000000 165 | #endif 166 | 167 | /* The value of LINK_SIZE determines the number of bytes used to store links 168 | as offsets within the compiled regex. The default is 2, which allows for 169 | compiled patterns up to 65535 code units long. This covers the vast 170 | majority of cases. However, PCRE2 can also be compiled to use 3 or 4 bytes 171 | instead. This allows for longer patterns in extreme cases. */ 172 | #ifndef LINK_SIZE 173 | #define LINK_SIZE 2 174 | #endif 175 | 176 | /* Define to the sub-directory where libtool stores uninstalled libraries. */ 177 | /* This is ignored unless you are using libtool. */ 178 | #ifndef LT_OBJDIR 179 | #define LT_OBJDIR ".libs/" 180 | #endif 181 | 182 | /* The value of MATCH_LIMIT determines the default number of times the 183 | pcre2_match() function can record a backtrack position during a single 184 | matching attempt. The value is also used to limit a loop counter in 185 | pcre2_dfa_match(). There is a runtime interface for setting a different 186 | limit. The limit exists in order to catch runaway regular expressions that 187 | take forever to determine that they do not match. The default is set very 188 | large so that it does not accidentally catch legitimate cases. */ 189 | #ifndef MATCH_LIMIT 190 | #define MATCH_LIMIT 10000000 191 | #endif 192 | 193 | /* The above limit applies to all backtracks, whether or not they are nested. 194 | In some environments it is desirable to limit the nesting of backtracking 195 | (that is, the depth of tree that is searched) more strictly, in order to 196 | restrict the maximum amount of heap memory that is used. The value of 197 | MATCH_LIMIT_DEPTH provides this facility. To have any useful effect, it 198 | must be less than the value of MATCH_LIMIT. The default is to use the same 199 | value as MATCH_LIMIT. There is a runtime method for setting a different 200 | limit. In the case of pcre2_dfa_match(), this limit controls the depth of 201 | the internal nested function calls that are used for pattern recursions, 202 | lookarounds, and atomic groups. */ 203 | #ifndef MATCH_LIMIT_DEPTH 204 | #define MATCH_LIMIT_DEPTH MATCH_LIMIT 205 | #endif 206 | 207 | /* This limit is parameterized just in case anybody ever wants to change it. 208 | Care must be taken if it is increased, because it guards against integer 209 | overflow caused by enormously large patterns. */ 210 | #ifndef MAX_NAME_COUNT 211 | #define MAX_NAME_COUNT 10000 212 | #endif 213 | 214 | /* This limit is parameterized just in case anybody ever wants to change it. 215 | Care must be taken if it is increased, because it guards against integer 216 | overflow caused by enormously large patterns. */ 217 | #ifndef MAX_NAME_SIZE 218 | #define MAX_NAME_SIZE 128 219 | #endif 220 | 221 | /* The value of MAX_VARLOOKBEHIND specifies the default maximum length, in 222 | characters, for a variable-length lookbehind assertion. */ 223 | #ifndef MAX_VARLOOKBEHIND 224 | #define MAX_VARLOOKBEHIND 255 225 | #endif 226 | 227 | /* Defining NEVER_BACKSLASH_C locks out the use of \C in all patterns. */ 228 | /* #undef NEVER_BACKSLASH_C */ 229 | 230 | /* The value of NEWLINE_DEFAULT determines the default newline character 231 | sequence. PCRE2 client programs can override this by selecting other values 232 | at run time. The valid values are 1 (CR), 2 (LF), 3 (CRLF), 4 (ANY), 5 233 | (ANYCRLF), and 6 (NUL). */ 234 | #ifndef NEWLINE_DEFAULT 235 | #define NEWLINE_DEFAULT 2 236 | #endif 237 | 238 | /* Name of package */ 239 | #define PACKAGE "pcre2" 240 | 241 | /* Define to the address where bug reports for this package should be sent. */ 242 | #define PACKAGE_BUGREPORT "" 243 | 244 | /* Define to the full name of this package. */ 245 | #define PACKAGE_NAME "PCRE2" 246 | 247 | /* Define to the full name and version of this package. */ 248 | #define PACKAGE_STRING "PCRE2 10.44" 249 | 250 | /* Define to the one symbol short name of this package. */ 251 | #define PACKAGE_TARNAME "pcre2" 252 | 253 | /* Define to the home page for this package. */ 254 | #define PACKAGE_URL "" 255 | 256 | /* Define to the version of this package. */ 257 | #define PACKAGE_VERSION "10.44" 258 | 259 | /* The value of PARENS_NEST_LIMIT specifies the maximum depth of nested 260 | parentheses (of any kind) in a pattern. This limits the amount of system 261 | stack that is used while compiling a pattern. */ 262 | #ifndef PARENS_NEST_LIMIT 263 | #define PARENS_NEST_LIMIT 250 264 | #endif 265 | 266 | /* The value of PCRE2GREP_BUFSIZE is the starting size of the buffer used by 267 | pcre2grep to hold parts of the file it is searching. The buffer will be 268 | expanded up to PCRE2GREP_MAX_BUFSIZE if necessary, for files containing 269 | very long lines. The actual amount of memory used by pcre2grep is three 270 | times this number, because it allows for the buffering of "before" and 271 | "after" lines. */ 272 | #ifndef PCRE2GREP_BUFSIZE 273 | #define PCRE2GREP_BUFSIZE 20480 274 | #endif 275 | 276 | /* The value of PCRE2GREP_MAX_BUFSIZE specifies the maximum size of the buffer 277 | used by pcre2grep to hold parts of the file it is searching. The actual 278 | amount of memory used by pcre2grep is three times this number, because it 279 | allows for the buffering of "before" and "after" lines. */ 280 | #ifndef PCRE2GREP_MAX_BUFSIZE 281 | #define PCRE2GREP_MAX_BUFSIZE 1048576 282 | #endif 283 | 284 | /* Define to any value to include debugging code. */ 285 | /* #undef PCRE2_DEBUG */ 286 | 287 | /* to make a symbol visible */ 288 | #define PCRE2_EXPORT 289 | 290 | /* If you are compiling for a system other than a Unix-like system or 291 | Win32, and it needs some magic to be inserted before the definition 292 | of a function that is exported by the library, define this macro to 293 | contain the relevant magic. If you do not define this macro, a suitable 294 | __declspec value is used for Windows systems; in other environments 295 | a compiler relevant "extern" is used with any "visibility" related 296 | attributes from PCRE2_EXPORT included. 297 | This macro apears at the start of every exported function that is part 298 | of the external API. It does not appear on functions that are "external" 299 | in the C sense, but which are internal to the library. */ 300 | /* #undef PCRE2_EXP_DEFN */ 301 | 302 | /* Define to any value if linking statically (TODO: make nice with Libtool) */ 303 | #define PCRE2_STATIC 1 304 | 305 | /* Define to necessary symbol if this constant uses a non-standard name on 306 | your system. */ 307 | /* #undef PTHREAD_CREATE_JOINABLE */ 308 | 309 | /* Define to any non-zero number to enable support for SELinux compatible 310 | executable memory allocator in JIT. Note that this will have no effect 311 | unless SUPPORT_JIT is also defined. */ 312 | /* #undef SLJIT_PROT_EXECUTABLE_ALLOCATOR */ 313 | 314 | /* Define to 1 if all of the C89 standard headers exist (not just the ones 315 | required in a freestanding environment). This macro is provided for 316 | backward compatibility; new code need not use it. */ 317 | #define STDC_HEADERS 1 318 | 319 | /* Define to any value to enable differential fuzzing support. */ 320 | /* #undef SUPPORT_DIFF_FUZZ */ 321 | 322 | /* Define to any value to enable support for Just-In-Time compiling. */ 323 | #define SUPPORT_JIT 1 324 | 325 | /* Define to any value to allow pcre2grep to be linked with libbz2, so that it 326 | is able to handle .bz2 files. */ 327 | /* #undef SUPPORT_LIBBZ2 */ 328 | 329 | /* Define to any value to allow pcre2test to be linked with libedit. */ 330 | /* #undef SUPPORT_LIBEDIT */ 331 | 332 | /* Define to any value to allow pcre2test to be linked with libreadline. */ 333 | /* #undef SUPPORT_LIBREADLINE */ 334 | 335 | /* Define to any value to allow pcre2grep to be linked with libz, so that it 336 | is able to handle .gz files. */ 337 | /* #undef SUPPORT_LIBZ */ 338 | 339 | /* Define to any value to enable callout script support in pcre2grep. */ 340 | #define SUPPORT_PCRE2GREP_CALLOUT 1 341 | 342 | /* Define to any value to enable fork support in pcre2grep callout scripts. 343 | This will have no effect unless SUPPORT_PCRE2GREP_CALLOUT is also defined. 344 | */ 345 | #define SUPPORT_PCRE2GREP_CALLOUT_FORK 1 346 | 347 | /* Define to any value to enable JIT support in pcre2grep. Note that this will 348 | have no effect unless SUPPORT_JIT is also defined. */ 349 | #define SUPPORT_PCRE2GREP_JIT 1 350 | 351 | /* Define to any value to enable the 16 bit PCRE2 library. */ 352 | /* #undef SUPPORT_PCRE2_16 */ 353 | 354 | /* Define to any value to enable the 32 bit PCRE2 library. */ 355 | /* #undef SUPPORT_PCRE2_32 */ 356 | 357 | /* Define to any value to enable the 8 bit PCRE2 library. */ 358 | #define SUPPORT_PCRE2_8 1 359 | 360 | /* Define to any value to enable support for Unicode and UTF encoding. This 361 | will work even in an EBCDIC environment, but it is incompatible with the 362 | EBCDIC macro. That is, PCRE2 can support *either* EBCDIC code *or* 363 | ASCII/Unicode, but not both at once. */ 364 | #define SUPPORT_UNICODE 1 365 | 366 | /* Define to any value for valgrind support to find invalid memory reads. */ 367 | /* #undef SUPPORT_VALGRIND */ 368 | 369 | /* Enable extensions on AIX, Interix, z/OS. */ 370 | #ifndef _ALL_SOURCE 371 | # define _ALL_SOURCE 1 372 | #endif 373 | /* Enable general extensions on macOS. */ 374 | #ifndef _DARWIN_C_SOURCE 375 | # define _DARWIN_C_SOURCE 1 376 | #endif 377 | /* Enable general extensions on Solaris. */ 378 | #ifndef __EXTENSIONS__ 379 | # define __EXTENSIONS__ 1 380 | #endif 381 | /* Enable GNU extensions on systems that have them. */ 382 | #ifndef _GNU_SOURCE 383 | # define _GNU_SOURCE 1 384 | #endif 385 | /* Enable X/Open compliant socket functions that do not require linking 386 | with -lxnet on HP-UX 11.11. */ 387 | #ifndef _HPUX_ALT_XOPEN_SOCKET_API 388 | # define _HPUX_ALT_XOPEN_SOCKET_API 1 389 | #endif 390 | /* Identify the host operating system as Minix. 391 | This macro does not affect the system headers' behavior. 392 | A future release of Autoconf may stop defining this macro. */ 393 | #ifndef _MINIX 394 | /* # undef _MINIX */ 395 | #endif 396 | /* Enable general extensions on NetBSD. 397 | Enable NetBSD compatibility extensions on Minix. */ 398 | #ifndef _NETBSD_SOURCE 399 | # define _NETBSD_SOURCE 1 400 | #endif 401 | /* Enable OpenBSD compatibility extensions on NetBSD. 402 | Oddly enough, this does nothing on OpenBSD. */ 403 | #ifndef _OPENBSD_SOURCE 404 | # define _OPENBSD_SOURCE 1 405 | #endif 406 | /* Define to 1 if needed for POSIX-compatible behavior. */ 407 | #ifndef _POSIX_SOURCE 408 | /* # undef _POSIX_SOURCE */ 409 | #endif 410 | /* Define to 2 if needed for POSIX-compatible behavior. */ 411 | #ifndef _POSIX_1_SOURCE 412 | /* # undef _POSIX_1_SOURCE */ 413 | #endif 414 | /* Enable POSIX-compatible threading on Solaris. */ 415 | #ifndef _POSIX_PTHREAD_SEMANTICS 416 | # define _POSIX_PTHREAD_SEMANTICS 1 417 | #endif 418 | /* Enable extensions specified by ISO/IEC TS 18661-5:2014. */ 419 | #ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 420 | # define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1 421 | #endif 422 | /* Enable extensions specified by ISO/IEC TS 18661-1:2014. */ 423 | #ifndef __STDC_WANT_IEC_60559_BFP_EXT__ 424 | # define __STDC_WANT_IEC_60559_BFP_EXT__ 1 425 | #endif 426 | /* Enable extensions specified by ISO/IEC TS 18661-2:2015. */ 427 | #ifndef __STDC_WANT_IEC_60559_DFP_EXT__ 428 | # define __STDC_WANT_IEC_60559_DFP_EXT__ 1 429 | #endif 430 | /* Enable extensions specified by C23 Annex F. */ 431 | #ifndef __STDC_WANT_IEC_60559_EXT__ 432 | # define __STDC_WANT_IEC_60559_EXT__ 1 433 | #endif 434 | /* Enable extensions specified by ISO/IEC TS 18661-4:2015. */ 435 | #ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__ 436 | # define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1 437 | #endif 438 | /* Enable extensions specified by C23 Annex H and ISO/IEC TS 18661-3:2015. */ 439 | #ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ 440 | # define __STDC_WANT_IEC_60559_TYPES_EXT__ 1 441 | #endif 442 | /* Enable extensions specified by ISO/IEC TR 24731-2:2010. */ 443 | #ifndef __STDC_WANT_LIB_EXT2__ 444 | # define __STDC_WANT_LIB_EXT2__ 1 445 | #endif 446 | /* Enable extensions specified by ISO/IEC 24747:2009. */ 447 | #ifndef __STDC_WANT_MATH_SPEC_FUNCS__ 448 | # define __STDC_WANT_MATH_SPEC_FUNCS__ 1 449 | #endif 450 | /* Enable extensions on HP NonStop. */ 451 | #ifndef _TANDEM_SOURCE 452 | # define _TANDEM_SOURCE 1 453 | #endif 454 | /* Enable X/Open extensions. Define to 500 only if necessary 455 | to make mbstate_t available. */ 456 | #ifndef _XOPEN_SOURCE 457 | /* # undef _XOPEN_SOURCE */ 458 | #endif 459 | 460 | /* Version number of package */ 461 | #define VERSION "10.44" 462 | 463 | /* Number of bits in a file offset, on hosts where this is settable. */ 464 | /* #undef _FILE_OFFSET_BITS */ 465 | 466 | /* Define to 1 on platforms where this makes off_t a 64-bit type. */ 467 | /* #undef _LARGE_FILES */ 468 | 469 | /* Number of bits in time_t, on hosts where this is settable. */ 470 | /* #undef _TIME_BITS */ 471 | 472 | /* Define to 1 on platforms where this makes time_t a 64-bit type. */ 473 | /* #undef __MINGW_USE_VC2005_COMPAT */ 474 | 475 | /* Define to empty if 'const' does not conform to ANSI C. */ 476 | /* #undef const */ 477 | 478 | /* Define to the type of a signed integer type of width exactly 64 bits if 479 | such a type exists and the standard includes do not define it. */ 480 | /* #undef int64_t */ 481 | 482 | /* Define as 'unsigned int' if doesn't define. */ 483 | /* #undef size_t */ 484 | -------------------------------------------------------------------------------- /pcre2/pcre2-10.44-build.txt: -------------------------------------------------------------------------------- 1 | Instructions how to build native pcre2 libraries and pcre2grep.exe utility with Microsoft Visual Studio (or Build Tools for Visual Studio) and WDK10. 2 | 3 | From CYGWIN shell: 4 | 5 | 1) get archive: 6 | wget https://github.com/PCRE2Project/pcre2/archive/refs/tags/pcre2-10.44.tar.gz 7 | 8 | 2) unpack archive: 9 | tar xf pcre2-10.44.tar.gz 10 | 11 | 3) go to PCRE2 sources: 12 | cd pcre2-pcre2-10.44 13 | 14 | 4) copy files 15 | cp ../pcre2/NMakefile-pcre2-10.44 ./NMakefile 16 | cp ../pcre2/config-pcre2-10.44.h ./src/config.h 17 | cp ../pcre2/RunGrepTest-pcre2-10.44.bat ./RunGrepTest.bat 18 | cp ../pcre2/RunTest-pcre2-10.44.bat ./RunTest.bat 19 | cp ../pcre2/testrepl.c ./testrepl.c 20 | cp ./src/pcre2.h.generic ./src/pcre2.h 21 | cp ./src/pcre2_chartables.c.dist ./src/pcre2_chartables.c 22 | 23 | --tip: ../pcre2/config-pcre2-10.44.h was copied from ./src/config.h.generic, then fixed by hand 24 | 25 | 5) patch the sources 26 | patch -Np1 -i ../pcre2/pcre2-pcre2-10.44.patch 27 | 28 | 6) now start dos prompt with minimal environment (inherit TMP variable value): 29 | env -i TMP="$(cmd.exe /c set TMP | sed 's/.*=//;s/\x0d//')" $(which cmd.exe) /c start cmd.exe 30 | 31 | In the dos window: 32 | 33 | 7) prepare environment, change console code page to ACP (Ansi Code Page): 34 | set "PATH=C:\Windows\System32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0" 35 | set LC_CTYPE= 36 | chcp 1251 37 | set VSCMD_SKIP_SENDTELEMETRY=1 38 | 39 | (ACP value can be queried by the command: "reg query HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage /v ACP") 40 | 41 | 8) setup compiler: 42 | "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64 43 | (if Microsoft Build Tools for Visual Studio 2022 is installed in "C:\Program Files (x86)") 44 | 45 | --tip: to build 32-bit version of PCRE2 library and pcre2grep.exe utility, specify "x86" instead of "amd64" 46 | 47 | 9) build pcre2.a, pcre2posix.a and pcre2grep.exe, run tests: 48 | nmake -f NMakefile check 49 | -------------------------------------------------------------------------------- /pcre2/pcre2-pcre2-10.44.patch: -------------------------------------------------------------------------------- 1 | --- orig/src/pcre2grep.c 2022-12-12 20:16:53.000000000 +0300 2 | +++ fixed/src/pcre2grep.c 2023-07-11 13:00:13.463800300 +0300 3 | @@ -2480,7 +2480,11 @@ 4 | necessary, otherwise assume fork(). */ 5 | 6 | #ifdef WIN32 7 | +fflush(stdout); 8 | +fflush(stderr); 9 | result = _spawnvp(_P_WAIT, argsvector[0], (const char * const *)argsvector); 10 | +fflush(stdout); 11 | +fflush(stderr); 12 | 13 | #elif defined __VMS 14 | { 15 | -------------------------------------------------------------------------------- /pcre2/testrepl.c: -------------------------------------------------------------------------------- 1 | /* public domain */ 2 | 3 | /* compile as: 4 | gcc testrepl.c -o testrepl 5 | or 6 | cl.exe testrepl.c /Fetestrepl.exe 7 | */ 8 | 9 | #ifdef _WIN32 10 | #define WIN32_LEAN_AND_MEAN 11 | #include 12 | #else /* !_WIN32 */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #define HANDLE int 18 | #endif /* !_WIN32 */ 19 | 20 | #define STACK_BUF_SIZE 128 21 | 22 | static int write_(HANDLE file, const void *const buf, const size_t len) 23 | { 24 | size_t to_write = len; 25 | if (to_write > (unsigned)-1/2) 26 | to_write = (unsigned)-1/2; 27 | #ifdef _WIN32 28 | if (to_write > (DWORD)-1) 29 | to_write = (DWORD)-1; 30 | { 31 | DWORD written = 0; 32 | if (!WriteFile(file, buf, (DWORD)to_write, &written, NULL)) 33 | return -1; 34 | return (int)written; 35 | } 36 | #else 37 | const ssize_t s = write(file, buf, to_write); 38 | if (s < 0) 39 | return -1; 40 | return (int)s; 41 | #endif 42 | } 43 | 44 | static int read_(HANDLE file, void *const buf, const size_t len) 45 | { 46 | size_t to_read = len; 47 | if (to_read > (unsigned)-1/2) 48 | to_read = (unsigned)-1/2; 49 | #ifdef _WIN32 50 | if (to_read > (DWORD)-1) 51 | to_read = (DWORD)-1; 52 | { 53 | DWORD filled = 0; 54 | if (!ReadFile(file, buf, (DWORD)to_read, &filled, NULL)) { 55 | if (ERROR_BROKEN_PIPE == GetLastError()) 56 | return 0; 57 | return -1; 58 | } 59 | return (int)filled; 60 | } 61 | #else 62 | const ssize_t s = read(file, buf, to_read); 63 | if (s < 0) 64 | return -1; 65 | return (int)s; 66 | #endif 67 | } 68 | 69 | static int write_buf(HANDLE file, const void *const buf, const size_t len) 70 | { 71 | size_t written = 0; 72 | while (written < len) { 73 | const int r = write_(file, (const unsigned char*)buf + written, len - written); 74 | if (r <= 0) 75 | return -1; 76 | written += (unsigned)r; 77 | } 78 | return 0; 79 | } 80 | 81 | static int read_buf(HANDLE file, void *const buf, const size_t len/*<=(unsigned)-1/2*/) 82 | { 83 | size_t filled = 0; 84 | while (filled < len) { 85 | const int r = read_(file, (unsigned char*)buf + filled, len - filled); 86 | if (r < 0) 87 | return -1; 88 | if (r == 0) 89 | break; 90 | filled += (unsigned)r; 91 | } 92 | return (int)filled; 93 | } 94 | 95 | static HANDLE get_stderr_handle(void) 96 | { 97 | #ifdef _WIN32 98 | HANDLE h = GetStdHandle(STD_ERROR_HANDLE); 99 | #else 100 | int h = fileno(stderr); 101 | #endif 102 | return h; 103 | } 104 | 105 | static int print_usage(const char *prog) 106 | { 107 | HANDLE h = get_stderr_handle(); 108 | const size_t len = strlen(prog); 109 | write_buf(h, prog, len); 110 | #define STR1 ": read standard input and write to standard output translating bytes b1 -> b2 or deleting bytes b1\nusage:\n" 111 | write_buf(h, STR1, sizeof(STR1) - 1); 112 | write_buf(h, prog, len); 113 | #define STR2 " b1 b2\nwhere: b1/b2 - bytes to translate from/to, specified as hexadecimal numbers, e.g.: 1F B\n" 114 | write_buf(h, STR2, sizeof(STR2) - 1); 115 | #define STR3 "or\n" 116 | write_buf(h, STR3, sizeof(STR3) - 1); 117 | write_buf(h, prog, len); 118 | #define STR4 " b\nwhere: b - bytes to delete, e.g.: 0d\n" 119 | write_buf(h, STR4, sizeof(STR4) - 1); 120 | write_buf(h, STR3, sizeof(STR3) - 1); 121 | write_buf(h, prog, len); 122 | #define STR5 " +offset b\nwhere: offset - offset (non-negative decimal number) from the input beginning where to replace source byte with b\n" 123 | write_buf(h, STR5, sizeof(STR5) - 1); 124 | write_buf(h, STR3, sizeof(STR3) - 1); 125 | write_buf(h, prog, len); 126 | #define STR6 " +offset\nwhere: offset - offset (non-negative decimal number) from the input beginning where to delete source byte\n" 127 | write_buf(h, STR6, sizeof(STR6) - 1); 128 | return 1; 129 | } 130 | 131 | static char *print_num(char *end, unsigned n) 132 | { 133 | do { 134 | *--end = (n % 10) + '0'; 135 | n = n/10; 136 | } while (n); 137 | return end; 138 | } 139 | 140 | #ifndef _WIN32 141 | static char *print_inum(char *end, int i) 142 | { 143 | const unsigned n = i >= 0 ? (unsigned)i : (unsigned)-(i + 1) + 1; 144 | end = print_num(end, n); 145 | if (i < 0) 146 | *--end = '-'; 147 | return end; 148 | } 149 | #endif 150 | 151 | #ifdef _WIN32 152 | static void write_num(HANDLE h, const unsigned n) 153 | { 154 | char num_buf[64]; 155 | char *const num = print_num(&num_buf[sizeof(num_buf)], n); 156 | write_buf(h, num, (size_t)(&num_buf[sizeof(num_buf)] - num)); 157 | } 158 | #endif 159 | 160 | #ifndef _WIN32 161 | static void write_inum(HANDLE h, const int i) 162 | { 163 | char num_buf[64]; 164 | char *const num = print_inum(&num_buf[sizeof(num_buf)], i); 165 | write_buf(h, num, (size_t)(&num_buf[sizeof(num_buf)] - num)); 166 | } 167 | #endif 168 | 169 | static int read_error(void) 170 | { 171 | #ifdef _WIN32 172 | const DWORD err = GetLastError(); 173 | #else 174 | const int err = errno; 175 | #endif 176 | HANDLE h = get_stderr_handle(); 177 | #define READ_ERR "failed to read from standard input stream, error: " 178 | write_buf(h, READ_ERR, sizeof(READ_ERR) - 1); 179 | #ifdef _WIN32 180 | write_num(h, err); 181 | #else 182 | write_inum(h, err); 183 | #endif 184 | write_buf(h, "\n", 1); 185 | return 3; 186 | } 187 | 188 | static int write_error(void) 189 | { 190 | #ifdef _WIN32 191 | const DWORD err = GetLastError(); 192 | #else 193 | const int err = errno; 194 | #endif 195 | HANDLE h = get_stderr_handle(); 196 | #define WRITE_ERR "failed to write to standard output stream, error: " 197 | write_buf(h, WRITE_ERR, sizeof(WRITE_ERR) - 1); 198 | #ifdef _WIN32 199 | write_num(h, err); 200 | #else 201 | write_inum(h, err); 202 | #endif 203 | write_buf(h, "\n", 1); 204 | return 4; 205 | } 206 | 207 | static int translate(const unsigned long long offs, const int repl, const unsigned char b1, const unsigned char b2) 208 | { 209 | #ifdef _WIN32 210 | HANDLE rh = GetStdHandle(STD_INPUT_HANDLE); 211 | HANDLE wh = GetStdHandle(STD_OUTPUT_HANDLE); 212 | #else 213 | int rh = fileno(stdin); 214 | int wh = fileno(stdout); 215 | #endif 216 | unsigned char buf[STACK_BUF_SIZE]; 217 | unsigned long long pos = 0; 218 | for (;;) { 219 | int r = read_buf(rh, buf, sizeof(buf)); 220 | if (r < 0) 221 | return read_error(); 222 | if (r == 0) 223 | return 0; 224 | if ((unsigned long long)-1 == offs) { 225 | if (repl) { 226 | int i = 0; 227 | do { 228 | if (b1 == buf[i]) 229 | buf[i] = b2; 230 | } while (++i != r); 231 | } 232 | else { 233 | int i = 0, at = 0; 234 | do { 235 | if (b1 != buf[i]) { 236 | if (at != i) 237 | buf[at] = buf[i]; 238 | at++; 239 | } 240 | } while (++i != r); 241 | r = at; 242 | } 243 | } 244 | else { 245 | const unsigned len = (unsigned)r; 246 | if (pos <= offs && len > offs - pos) { 247 | if (repl) 248 | buf[offs - pos] = b2; 249 | else { 250 | unsigned i = (unsigned)(offs - pos); 251 | while (++i < len) 252 | buf[i - 1] = buf[i]; 253 | r--; 254 | } 255 | } 256 | if (len <= (unsigned long long)-1 - pos) 257 | pos += len; 258 | else 259 | pos = (unsigned long long)-1; 260 | } 261 | if (write_buf(wh, buf, (unsigned)r) < 0) 262 | return write_error(); 263 | } 264 | } 265 | 266 | static int decode_hex_char(const char c) 267 | { 268 | if ('0' <= c && c <= '9') 269 | return (int)(c - '0'); 270 | if ('a' <= c && c <= 'f') 271 | return (int)(c - 'a') + 10; 272 | if ('A' <= c && c <= 'F') 273 | return (int)(c - 'A') + 10; 274 | return -1; 275 | } 276 | 277 | static int parse_byte(const char *const a) 278 | { 279 | const int x = decode_hex_char(a[0]); 280 | if (x >= 0) { 281 | if (!a[1]) 282 | return x; 283 | { 284 | const int y = decode_hex_char(a[1]); 285 | if (!a[2]) 286 | return x*16 + y; 287 | } 288 | } 289 | { 290 | HANDLE h = get_stderr_handle(); 291 | const size_t byte_len = strlen(a); 292 | #define PARSE_ERR1 "failed to parse byte: \"" 293 | write_buf(h, PARSE_ERR1, sizeof(PARSE_ERR1) - 1); 294 | write_buf(h, a, byte_len); 295 | #define PARSE_ERR2 "\", expecting hexadecimal number, e.g.: F or 1A\n" 296 | write_buf(h, PARSE_ERR2, sizeof(PARSE_ERR2) - 1); 297 | } 298 | return -1; 299 | } 300 | 301 | static unsigned long long parse_offs(const char *const a) 302 | { 303 | if ('0' <= *a && *a <= '9') { 304 | unsigned long long offs = (unsigned)(*a - '0'); 305 | const char *c = a; 306 | for (;;) { 307 | if (!*++c) 308 | return offs; 309 | if (*c < '0' || '9' < *c) 310 | break; 311 | if (offs > (unsigned long long)-1/10 || 312 | (unsigned)(*c - '0') >= (unsigned long long)-1 - offs*10) 313 | { 314 | HANDLE h = get_stderr_handle(); 315 | const size_t byte_len = strlen(a); 316 | #define PARSE_ERR3 "too big offset: \"" 317 | write_buf(h, PARSE_ERR3, sizeof(PARSE_ERR3) - 1); 318 | write_buf(h, a, byte_len); 319 | #define PARSE_ERR4 "\"\n" 320 | write_buf(h, PARSE_ERR4, sizeof(PARSE_ERR4) - 1); 321 | return (unsigned long long)-1; 322 | } 323 | offs = offs*10 + (unsigned)(*c - '0'); 324 | } 325 | } 326 | { 327 | HANDLE h = get_stderr_handle(); 328 | if (!*a) { 329 | #define PARSE_ERR5 "empty offset\n" 330 | write_buf(h, PARSE_ERR5, sizeof(PARSE_ERR5) - 1); 331 | } 332 | else { 333 | const size_t byte_len = strlen(a); 334 | #define PARSE_ERR6 "failed to parse offset: \"" 335 | write_buf(h, PARSE_ERR6, sizeof(PARSE_ERR6) - 1); 336 | write_buf(h, a, byte_len); 337 | #define PARSE_ERR7 "\", expecting non-negative decimal number, e.g.: 012345678\n" 338 | write_buf(h, PARSE_ERR7, sizeof(PARSE_ERR7) - 1); 339 | } 340 | } 341 | return (unsigned long long)-1; 342 | } 343 | 344 | int main(int argc, char *argv[]) 345 | { 346 | int b1 = 0, b2 = 0; 347 | unsigned long long offs = (unsigned long long)-1; 348 | if (argc != 2 && argc != 3) 349 | return print_usage(argv[0]); 350 | if ((('+' == argv[1][0]) ? 351 | ((unsigned long long)-1 == (offs = parse_offs(&argv[1][1]))) : 352 | ((b1 = parse_byte(argv[1])) < 0)) || 353 | (3 == argc && (b2 = parse_byte(argv[2])) < 0)) 354 | { 355 | return 2; 356 | } 357 | return translate(offs, 3 == argc, (unsigned char)b1, (unsigned char)b2); 358 | } 359 | -------------------------------------------------------------------------------- /pcre2grep-10.44-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/pcre2grep-10.44-x64.exe -------------------------------------------------------------------------------- /pcre2grep-10.44-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbuilov/grep-windows/494d25f424b9b73ad595ab370aac57b907617404/pcre2grep-10.44-x86.exe --------------------------------------------------------------------------------