diff options
| author | David M. Syzdek <syzdek@bindlebinaries.com> | 2017-07-06 18:15:35 -0800 |
|---|---|---|
| committer | David M. Syzdek <syzdek@bindlebinaries.com> | 2017-07-06 18:15:35 -0800 |
| commit | b30a6c380904feb0c8ab2f9f643e31e068767e7d (patch) | |
| tree | fbb735b0fc13829e56314faddcd34133e26f915d | |
| parent | c4b51f67a18a6f21c8f8cfadbe1f0361319b9c78 (diff) | |
| download | securecoreutils-b30a6c380904feb0c8ab2f9f643e31e068767e7d.tar.gz securecoreutils-b30a6c380904feb0c8ab2f9f643e31e068767e7d.tar.bz2 securecoreutils-b30a6c380904feb0c8ab2f9f643e31e068767e7d.tar.xz securecoreutils-b30a6c380904feb0c8ab2f9f643e31e068767e7d.zip | |
Adding native LZW compression support.
| -rw-r--r-- | Makefile.am | 3 | ||||
| -rw-r--r-- | acinclude.m4 | 5 | ||||
| -rw-r--r-- | configure.ac | 17 | ||||
| -rw-r--r-- | securecoreutilities.xcodeproj/project.pbxproj | 26 | ||||
| -rw-r--r-- | src/lzw/COPYING | 5 | ||||
| -rw-r--r-- | src/lzw/README.md | 32 | ||||
| -rw-r--r-- | src/lzw/UNLICENSE | 24 | ||||
| -rw-r--r-- | src/lzw/headers.h | 41 | ||||
| -rw-r--r-- | src/lzw/helpers.h | 24 | ||||
| -rw-r--r-- | src/lzw/lzw.c | 342 | ||||
| -rw-r--r-- | src/lzw/lzw.h | 61 | ||||
| -rw-r--r-- | src/lzw/lzw_internal.h | 16 | ||||
| -rw-r--r-- | src/widget-zcat.c | 52 | ||||
| -rw-r--r-- | src/widget-zcat.h | 2 |
14 files changed, 632 insertions, 18 deletions
diff --git a/Makefile.am b/Makefile.am index 52cf45d..52b81ee 100644 --- a/Makefile.am +++ b/Makefile.am | |||
| @@ -107,7 +107,8 @@ src_securecoreutils_SOURCES = $(include_HEADERS) \ | |||
| 107 | src/widget-tail.c \ | 107 | src/widget-tail.c \ |
| 108 | src/widget-tail.h \ | 108 | src/widget-tail.h \ |
| 109 | src/widget-zcat.c \ | 109 | src/widget-zcat.c \ |
| 110 | src/widget-zcat.h | 110 | src/widget-zcat.h \ |
| 111 | src/lzw/lzw.c | ||
| 111 | 112 | ||
| 112 | 113 | ||
| 113 | # Makefile includes | 114 | # Makefile includes |
diff --git a/acinclude.m4 b/acinclude.m4 index af7264a..38b1afe 100644 --- a/acinclude.m4 +++ b/acinclude.m4 | |||
| @@ -106,11 +106,6 @@ AC_DEFUN([AC_SCU_ZCAT_DEPS],[dnl | |||
| 106 | fi | 106 | fi |
| 107 | fi | 107 | fi |
| 108 | 108 | ||
| 109 | AC_CHECK_PROG([USE_Z], [uncompress], [yes], [no]) | ||
| 110 | if test "x${USE_Z}" = "xyes";then | ||
| 111 | AC_DEFINE_UNQUOTED(USE_Z, 1, [Use uncompress]) | ||
| 112 | fi | ||
| 113 | |||
| 114 | ])dnl | 109 | ])dnl |
| 115 | 110 | ||
| 116 | 111 | ||
diff --git a/configure.ac b/configure.ac index 4fbc532..5a97403 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -131,8 +131,23 @@ AC_CHECK_FUNCS([strdup], [], [AC_MSG_ERROR([missing required functions]) | |||
| 131 | AC_CHECK_FUNCS([strerror], [], [AC_MSG_ERROR([missing required functions])]) | 131 | AC_CHECK_FUNCS([strerror], [], [AC_MSG_ERROR([missing required functions])]) |
| 132 | 132 | ||
| 133 | # check for headers | 133 | # check for headers |
| 134 | AC_CHECK_HEADERS([assert.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 135 | AC_CHECK_HEADERS([ctype.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 136 | AC_CHECK_HEADERS([errno.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 134 | AC_CHECK_HEADERS([fcntl.h], [], [AC_MSG_ERROR([missing required headers])]) | 137 | AC_CHECK_HEADERS([fcntl.h], [], [AC_MSG_ERROR([missing required headers])]) |
| 138 | AC_CHECK_HEADERS([features.h], [], []) | ||
| 139 | AC_CHECK_HEADERS([inttypes.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 135 | AC_CHECK_HEADERS([limits.h], [], [AC_MSG_ERROR([missing required headers])]) | 140 | AC_CHECK_HEADERS([limits.h], [], [AC_MSG_ERROR([missing required headers])]) |
| 141 | AC_CHECK_HEADERS([stdarg.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 142 | AC_CHECK_HEADERS([stdint.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 143 | AC_CHECK_HEADERS([stdio.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 144 | AC_CHECK_HEADERS([stdlib.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 145 | AC_CHECK_HEADERS([string.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 146 | AC_CHECK_HEADERS([sys/cdefs.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 147 | AC_CHECK_HEADERS([sys/types.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 148 | AC_CHECK_HEADERS([sys/stat.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 149 | AC_CHECK_HEADERS([time.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 150 | AC_CHECK_HEADERS([unistd.h], [], [AC_MSG_ERROR([missing required headers])]) | ||
| 136 | 151 | ||
| 137 | # GNU Libtool Support | 152 | # GNU Libtool Support |
| 138 | LT_INIT(dlopen disable-fast-install win32-dll) | 153 | LT_INIT(dlopen disable-fast-install win32-dll) |
| @@ -168,7 +183,7 @@ AC_MSG_NOTICE([ Features:]) | |||
| 168 | AC_MSG_NOTICE([ zlib support: $USE_ZLIB]) | 183 | AC_MSG_NOTICE([ zlib support: $USE_ZLIB]) |
| 169 | AC_MSG_NOTICE([ bzip2 support: $USE_BZIP2]) | 184 | AC_MSG_NOTICE([ bzip2 support: $USE_BZIP2]) |
| 170 | AC_MSG_NOTICE([ lzma support: $USE_LZMA]) | 185 | AC_MSG_NOTICE([ lzma support: $USE_LZMA]) |
| 171 | AC_MSG_NOTICE([ Z support: $USE_Z]) | 186 | AC_MSG_NOTICE([ lzw support: yes]) |
| 172 | AC_MSG_NOTICE([ ]) | 187 | AC_MSG_NOTICE([ ]) |
| 173 | AC_MSG_NOTICE([ Please send suggestions to: $PACKAGE_BUGREPORT]) | 188 | AC_MSG_NOTICE([ Please send suggestions to: $PACKAGE_BUGREPORT]) |
| 174 | AC_MSG_NOTICE([ ]) | 189 | AC_MSG_NOTICE([ ]) |
diff --git a/securecoreutilities.xcodeproj/project.pbxproj b/securecoreutilities.xcodeproj/project.pbxproj index 5cbc1d6..e0f64f6 100644 --- a/securecoreutilities.xcodeproj/project.pbxproj +++ b/securecoreutilities.xcodeproj/project.pbxproj | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | A0446A2F1F0DFAEB000085C7 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A0446A2E1F0DFAEB000085C7 /* libz.tbd */; }; | 28 | A0446A2F1F0DFAEB000085C7 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A0446A2E1F0DFAEB000085C7 /* libz.tbd */; }; |
| 29 | A0446A311F0E1EAA000085C7 /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A0446A301F0E1EAA000085C7 /* libbz2.tbd */; }; | 29 | A0446A311F0E1EAA000085C7 /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A0446A301F0E1EAA000085C7 /* libbz2.tbd */; }; |
| 30 | A0446A351F0EF634000085C7 /* liblzma.5.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A0446A341F0EF634000085C7 /* liblzma.5.dylib */; }; | 30 | A0446A351F0EF634000085C7 /* liblzma.5.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A0446A341F0EF634000085C7 /* liblzma.5.dylib */; }; |
| 31 | A0446A401F0F12CE000085C7 /* lzw.c in Sources */ = {isa = PBXBuildFile; fileRef = A0446A3D1F0F12BA000085C7 /* lzw.c */; }; | ||
| 31 | A054C3DD1B0292930036591C /* securecoreutils.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3D71B0292930036591C /* securecoreutils.c */; }; | 32 | A054C3DD1B0292930036591C /* securecoreutils.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3D71B0292930036591C /* securecoreutils.c */; }; |
| 32 | A054C3DE1B0292930036591C /* widget-cat.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3D91B0292930036591C /* widget-cat.c */; }; | 33 | A054C3DE1B0292930036591C /* widget-cat.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3D91B0292930036591C /* widget-cat.c */; }; |
| 33 | A054C3DF1B0292930036591C /* widget-pathcheck.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3DB1B0292930036591C /* widget-pathcheck.c */; }; | 34 | A054C3DF1B0292930036591C /* widget-pathcheck.c in Sources */ = {isa = PBXBuildFile; fileRef = A054C3DB1B0292930036591C /* widget-pathcheck.c */; }; |
| @@ -70,6 +71,14 @@ | |||
| 70 | A0446A301F0E1EAA000085C7 /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; | 71 | A0446A301F0E1EAA000085C7 /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; |
| 71 | A0446A321F0EF50A000085C7 /* liblzma.5.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = liblzma.5.dylib; path = ../../../../../opt/local/lib/liblzma.5.dylib; sourceTree = "<group>"; }; | 72 | A0446A321F0EF50A000085C7 /* liblzma.5.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = liblzma.5.dylib; path = ../../../../../opt/local/lib/liblzma.5.dylib; sourceTree = "<group>"; }; |
| 72 | A0446A341F0EF634000085C7 /* liblzma.5.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = liblzma.5.dylib; path = ../../../../../opt/devel/lib/liblzma.5.dylib; sourceTree = "<group>"; }; | 73 | A0446A341F0EF634000085C7 /* liblzma.5.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = liblzma.5.dylib; path = ../../../../../opt/devel/lib/liblzma.5.dylib; sourceTree = "<group>"; }; |
| 74 | A0446A381F0F12BA000085C7 /* COPYING */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = COPYING; sourceTree = "<group>"; }; | ||
| 75 | A0446A391F0F12BA000085C7 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; }; | ||
| 76 | A0446A3A1F0F12BA000085C7 /* UNLICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = UNLICENSE; sourceTree = "<group>"; }; | ||
| 77 | A0446A3B1F0F12BA000085C7 /* headers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = headers.h; sourceTree = "<group>"; }; | ||
| 78 | A0446A3C1F0F12BA000085C7 /* helpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = helpers.h; sourceTree = "<group>"; }; | ||
| 79 | A0446A3D1F0F12BA000085C7 /* lzw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lzw.c; sourceTree = "<group>"; }; | ||
| 80 | A0446A3E1F0F12BA000085C7 /* lzw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lzw.h; sourceTree = "<group>"; }; | ||
| 81 | A0446A3F1F0F12BA000085C7 /* lzw_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lzw_internal.h; sourceTree = "<group>"; }; | ||
| 73 | A054C3A51B0292600036591C /* securecoreutilities */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = securecoreutilities; sourceTree = BUILT_PRODUCTS_DIR; }; | 82 | A054C3A51B0292600036591C /* securecoreutilities */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = securecoreutilities; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 74 | A054C3AD1B0292930036591C /* acinclude.m4 */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = acinclude.m4; sourceTree = "<group>"; }; | 83 | A054C3AD1B0292930036591C /* acinclude.m4 */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = acinclude.m4; sourceTree = "<group>"; }; |
| 75 | A054C3AE1B0292930036591C /* AUTHORS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AUTHORS; sourceTree = "<group>"; }; | 84 | A054C3AE1B0292930036591C /* AUTHORS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AUTHORS; sourceTree = "<group>"; }; |
| @@ -116,6 +125,21 @@ | |||
| 116 | name = Frameworks; | 125 | name = Frameworks; |
| 117 | sourceTree = "<group>"; | 126 | sourceTree = "<group>"; |
| 118 | }; | 127 | }; |
| 128 | A0446A371F0F12BA000085C7 /* lzw */ = { | ||
| 129 | isa = PBXGroup; | ||
| 130 | children = ( | ||
| 131 | A0446A381F0F12BA000085C7 /* COPYING */, | ||
| 132 | A0446A391F0F12BA000085C7 /* README.md */, | ||
| 133 | A0446A3A1F0F12BA000085C7 /* UNLICENSE */, | ||
| 134 | A0446A3B1F0F12BA000085C7 /* headers.h */, | ||
| 135 | A0446A3C1F0F12BA000085C7 /* helpers.h */, | ||
| 136 | A0446A3D1F0F12BA000085C7 /* lzw.c */, | ||
| 137 | A0446A3E1F0F12BA000085C7 /* lzw.h */, | ||
| 138 | A0446A3F1F0F12BA000085C7 /* lzw_internal.h */, | ||
| 139 | ); | ||
| 140 | path = lzw; | ||
| 141 | sourceTree = "<group>"; | ||
| 142 | }; | ||
| 119 | A054C3951B0291F50036591C = { | 143 | A054C3951B0291F50036591C = { |
| 120 | isa = PBXGroup; | 144 | isa = PBXGroup; |
| 121 | children = ( | 145 | children = ( |
| @@ -174,6 +198,7 @@ | |||
| 174 | A054C3D61B0292930036591C /* src */ = { | 198 | A054C3D61B0292930036591C /* src */ = { |
| 175 | isa = PBXGroup; | 199 | isa = PBXGroup; |
| 176 | children = ( | 200 | children = ( |
| 201 | A0446A371F0F12BA000085C7 /* lzw */, | ||
| 177 | A054C3D71B0292930036591C /* securecoreutils.c */, | 202 | A054C3D71B0292930036591C /* securecoreutils.c */, |
| 178 | A054C3D81B0292930036591C /* securecoreutils.h */, | 203 | A054C3D81B0292930036591C /* securecoreutils.h */, |
| 179 | A054C3D91B0292930036591C /* widget-cat.c */, | 204 | A054C3D91B0292930036591C /* widget-cat.c */, |
| @@ -272,6 +297,7 @@ | |||
| 272 | A0446A241F0DC853000085C7 /* widget-rmdir.c in Sources */, | 297 | A0446A241F0DC853000085C7 /* widget-rmdir.c in Sources */, |
| 273 | A054C3DE1B0292930036591C /* widget-cat.c in Sources */, | 298 | A054C3DE1B0292930036591C /* widget-cat.c in Sources */, |
| 274 | A005C1831EC8C6BD00A08403 /* widget-tail.c in Sources */, | 299 | A005C1831EC8C6BD00A08403 /* widget-tail.c in Sources */, |
| 300 | A0446A401F0F12CE000085C7 /* lzw.c in Sources */, | ||
| 275 | A0446A271F0DDF83000085C7 /* widget-zcat.c in Sources */, | 301 | A0446A271F0DDF83000085C7 /* widget-zcat.c in Sources */, |
| 276 | A054C3DF1B0292930036591C /* widget-pathcheck.c in Sources */, | 302 | A054C3DF1B0292930036591C /* widget-pathcheck.c in Sources */, |
| 277 | A054C3DD1B0292930036591C /* securecoreutils.c in Sources */, | 303 | A054C3DD1B0292930036591C /* securecoreutils.c in Sources */, |
diff --git a/src/lzw/COPYING b/src/lzw/COPYING new file mode 100644 index 0000000..0fae7e6 --- /dev/null +++ b/src/lzw/COPYING | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | Software is in the public domain. | ||
| 2 | |||
| 3 | See the UNLICENSE file for more details. | ||
| 4 | |||
| 5 | All I ask is you be nice and send bugfixes back. :) | ||
diff --git a/src/lzw/README.md b/src/lzw/README.md new file mode 100644 index 0000000..e911946 --- /dev/null +++ b/src/lzw/README.md | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | # Basics | ||
| 2 | |||
| 3 | * HOMEPAGE: https://github.com/vapier/liblzw | ||
| 4 | * BUGS: https://github.com/vapier/liblzw/issues | ||
| 5 | * AUTHOR: Mike Frysinger <vapier@gmail.com> | ||
| 6 | |||
| 7 | # About | ||
| 8 | |||
| 9 | liblzw is a small library that provides an API for reading | ||
| 10 | [LZW](http://en.wikipedia.org/wiki/LZW) compressed (.Z) files. The API is | ||
| 11 | similar to that of [zlib](http://www.zlib.net/) (for reading .gz files) and | ||
| 12 | [libbzip2](http://www.bzip.org/) (for reading .bz2 files) which themselves | ||
| 13 | are just like the classical UNIX functions for reading files | ||
| 14 | (e.g. open/read/fopen/fread/etc...). | ||
| 15 | |||
| 16 | The core compression code was taken from the canonical | ||
| 17 | [ncompress](https://github.com/vapier/ncompress) program. | ||
| 18 | |||
| 19 | # License | ||
| 20 | |||
| 21 | Since the compression algorithms were ripped out of the public-domain package | ||
| 22 | [ncompress](https://github.com/vapier/ncompress), liblzw has also been released | ||
| 23 | into the public-domain for people to do with as they will. Just please send me | ||
| 24 | bugfixes as you find them :). | ||
| 25 | |||
| 26 | See the [UNLICENSE](UNLICENSE) file for more details. | ||
| 27 | |||
| 28 | # Patents | ||
| 29 | |||
| 30 | All existing patents on the LZW algorithm have | ||
| 31 | [expired world-wide](http://en.wikipedia.org/wiki/LZW#Patent_issues). | ||
| 32 | So LZW is now patent free. | ||
diff --git a/src/lzw/UNLICENSE b/src/lzw/UNLICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/src/lzw/UNLICENSE | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | This is free and unencumbered software released into the public domain. | ||
| 2 | |||
| 3 | Anyone is free to copy, modify, publish, use, compile, sell, or | ||
| 4 | distribute this software, either in source code form or as a compiled | ||
| 5 | binary, for any purpose, commercial or non-commercial, and by any | ||
| 6 | means. | ||
| 7 | |||
| 8 | In jurisdictions that recognize copyright laws, the author or authors | ||
| 9 | of this software dedicate any and all copyright interest in the | ||
| 10 | software to the public domain. We make this dedication for the benefit | ||
| 11 | of the public at large and to the detriment of our heirs and | ||
| 12 | successors. We intend this dedication to be an overt act of | ||
| 13 | relinquishment in perpetuity of all present and future rights to this | ||
| 14 | software under copyright law. | ||
| 15 | |||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
| 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
| 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| 22 | OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | |||
| 24 | For more information, please refer to <http://unlicense.org/> | ||
diff --git a/src/lzw/headers.h b/src/lzw/headers.h new file mode 100644 index 0000000..213e2f5 --- /dev/null +++ b/src/lzw/headers.h | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | /* | ||
| 2 | * Written by Mike Frysinger <vapier@gmail.com> | ||
| 3 | * Released into the public domain | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef _LIBLZW_HEADERS_H | ||
| 7 | #define _LIBLZW_HEADERS_H | ||
| 8 | |||
| 9 | #ifdef HAVE_CONFIG_H | ||
| 10 | # include "config.h" | ||
| 11 | #endif | ||
| 12 | |||
| 13 | # include <stdint.h> | ||
| 14 | # include <inttypes.h> | ||
| 15 | # include <sys/types.h> | ||
| 16 | # include <sys/stat.h> | ||
| 17 | #if defined(HAVE_CTYPE_H) | ||
| 18 | # include <ctype.h> | ||
| 19 | #endif | ||
| 20 | # include <errno.h> | ||
| 21 | # include <unistd.h> | ||
| 22 | # include <fcntl.h> | ||
| 23 | # include <stdio.h> | ||
| 24 | # include <stdlib.h> | ||
| 25 | # include <time.h> | ||
| 26 | # include <string.h> | ||
| 27 | #if defined(HAVE_FEATURES_H) | ||
| 28 | # include <features.h> | ||
| 29 | #endif | ||
| 30 | # include <stdarg.h> | ||
| 31 | #if defined(HAVE_SYS_CDEFS_H) | ||
| 32 | # include <sys/cdefs.h> | ||
| 33 | #endif | ||
| 34 | # include <assert.h> | ||
| 35 | |||
| 36 | /* i'll see you in hell windows */ | ||
| 37 | #if !defined(O_BINARY) | ||
| 38 | # define O_BINARY 0x00 | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #endif /* _LIBLZW_HEADERS_H */ | ||
diff --git a/src/lzw/helpers.h b/src/lzw/helpers.h new file mode 100644 index 0000000..4ba45f7 --- /dev/null +++ b/src/lzw/helpers.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* | ||
| 2 | * Written by Mike Frysinger <vapier@gmail.com> | ||
| 3 | * Released into the public domain | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef _LIBLZW_HELPERS_H | ||
| 7 | #define _LIBLZW_HELPERS_H | ||
| 8 | |||
| 9 | #define _warn(fmt, args...) fprintf(stderr, fmt , ## args) | ||
| 10 | #define warn(fmt, args...) _warn("liblzw: " fmt "\n" , ## args) | ||
| 11 | #define warnf(fmt, args...) warn("%s(): " fmt, __FUNCTION__ , ## args) | ||
| 12 | #define warnp(fmt, args...) warn(fmt ": %s" , ## args , strerror(errno)) | ||
| 13 | #define warnfp(fmt, args...) warnp("%s(): " fmt, __FUNCTION__ , ## args) | ||
| 14 | |||
| 15 | #define dumphex(buf, cnt) \ | ||
| 16 | do { \ | ||
| 17 | size_t i = 0; \ | ||
| 18 | _warn("dumphex: "); \ | ||
| 19 | while (i < cnt) \ | ||
| 20 | _warn("%2.2X ", buf[i++]); \ | ||
| 21 | _warn("\n"); \ | ||
| 22 | } while (0) | ||
| 23 | |||
| 24 | #endif /* _LIBLZW_HELPERS_H */ | ||
diff --git a/src/lzw/lzw.c b/src/lzw/lzw.c new file mode 100644 index 0000000..e04bf81 --- /dev/null +++ b/src/lzw/lzw.c | |||
| @@ -0,0 +1,342 @@ | |||
| 1 | /* | ||
| 2 | * Original code was ripped from ncompress-4.2.4.tar.gz, | ||
| 3 | * and it is all public domain code, so have fun you wh0res. | ||
| 4 | * | ||
| 5 | * Librarification by Mike Frysinger <vapier@gmail.com> | ||
| 6 | * | ||
| 7 | * http://www.dogma.net/markn/articles/lzw/lzw.htm | ||
| 8 | * | ||
| 9 | * (N)compress42.c - File compression ala IEEE Computer, Mar 1992. | ||
| 10 | * | ||
| 11 | * Authors: | ||
| 12 | * Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas) | ||
| 13 | * Jim McKie (decvax!mcvax!jim) | ||
| 14 | * Steve Davies (decvax!vax135!petsd!peora!srd) | ||
| 15 | * Ken Turkowski (decvax!decwrl!turtlevax!ken) | ||
| 16 | * James A. Woods (decvax!ihnp4!ames!jaw) | ||
| 17 | * Joe Orost (decvax!vax135!petsd!joe) | ||
| 18 | * Dave Mack (csu@alembic.acs.com) | ||
| 19 | * Peter Jannesen, Network Communication Systems | ||
| 20 | * (peter@ncs.nl) | ||
| 21 | */ | ||
| 22 | |||
| 23 | #ifdef __IN_LIBSTDF | ||
| 24 | # include <libstdf.h> | ||
| 25 | # define hidden_in_another_lib stdf_attribute_hidden | ||
| 26 | #else | ||
| 27 | # include "lzw_internal.h" | ||
| 28 | # define hidden_in_another_lib | ||
| 29 | #endif | ||
| 30 | |||
| 31 | |||
| 32 | /* | ||
| 33 | * Misc common define cruft | ||
| 34 | */ | ||
| 35 | #define BUFSIZE 4 | ||
| 36 | #define IN_BUFSIZE (BUFSIZE + 64) | ||
| 37 | #define OUT_BUFSIZE (BUFSIZE + 2048) | ||
| 38 | #define BITS 16 | ||
| 39 | #define INIT_BITS 9 /* initial number of bits/code */ | ||
| 40 | #define MAXCODE(n) (1L << (n)) | ||
| 41 | #define FIRST 257 /* first free entry */ | ||
| 42 | #define CLEAR 256 /* table clear output code */ | ||
| 43 | |||
| 44 | |||
| 45 | /* | ||
| 46 | * Open LZW file | ||
| 47 | */ | ||
| 48 | hidden_in_another_lib | ||
| 49 | lzwFile *lzw_fdopen(int fd) | ||
| 50 | { | ||
| 51 | lzwFile *ret; | ||
| 52 | unsigned char buf[3]; | ||
| 53 | |||
| 54 | if (read(fd, buf, 3) != 3) | ||
| 55 | goto err_out; | ||
| 56 | |||
| 57 | if (buf[0] != LZW_MAGIC_1 || buf[1] != LZW_MAGIC_2 || buf[2] & 0x60) | ||
| 58 | goto err_out; | ||
| 59 | |||
| 60 | if ((ret = malloc(sizeof(*ret))) == NULL) | ||
| 61 | goto err_out; | ||
| 62 | |||
| 63 | memset(ret, 0x00, sizeof(*ret)); | ||
| 64 | ret->fd = fd; | ||
| 65 | ret->eof = 0; | ||
| 66 | ret->inbuf = malloc(sizeof(unsigned char) * IN_BUFSIZE); | ||
| 67 | ret->outbuf = malloc(sizeof(unsigned char) * OUT_BUFSIZE); | ||
| 68 | ret->stackp = NULL; | ||
| 69 | ret->insize = 3; /* we read three bytes above */ | ||
| 70 | ret->outpos = 0; | ||
| 71 | ret->rsize = 0; | ||
| 72 | |||
| 73 | ret->flags = buf[2]; | ||
| 74 | ret->maxbits = ret->flags & 0x1f; /* Mask for 'number of compresssion bits' */ | ||
| 75 | ret->block_mode = ret->flags & 0x80; | ||
| 76 | |||
| 77 | ret->n_bits = INIT_BITS; | ||
| 78 | ret->maxcode = MAXCODE(INIT_BITS) - 1; | ||
| 79 | ret->bitmask = (1<<INIT_BITS)-1; | ||
| 80 | ret->oldcode = -1; | ||
| 81 | ret->finchar = 0; | ||
| 82 | ret->posbits = 3<<3; | ||
| 83 | ret->free_ent = ((ret->block_mode) ? FIRST : 256); | ||
| 84 | |||
| 85 | /* initialize the first 256 entries in the table */ | ||
| 86 | memset(ret->codetab, 0x00, sizeof(ret->codetab)); | ||
| 87 | for (ret->code = 255; ret->code >= 0; --ret->code) | ||
| 88 | ret->htab[ret->code] = ret->code; | ||
| 89 | |||
| 90 | if (ret->inbuf == NULL || ret->outbuf == NULL) { | ||
| 91 | errno = ENOMEM; | ||
| 92 | goto err_out_free; | ||
| 93 | } | ||
| 94 | if (ret->maxbits > BITS) { | ||
| 95 | errno = EINVAL; | ||
| 96 | goto err_out_free; | ||
| 97 | } | ||
| 98 | |||
| 99 | return ret; | ||
| 100 | |||
| 101 | err_out: | ||
| 102 | errno = EINVAL; | ||
| 103 | return NULL; | ||
| 104 | |||
| 105 | err_out_free: | ||
| 106 | if (ret->inbuf) free(ret->inbuf); | ||
| 107 | if (ret->outbuf) free(ret->outbuf); | ||
| 108 | free(ret); | ||
| 109 | return NULL; | ||
| 110 | } | ||
| 111 | |||
| 112 | hidden_in_another_lib | ||
| 113 | lzwFile *lzw_open(const char *pathname, int flags) | ||
| 114 | { | ||
| 115 | int fd; | ||
| 116 | |||
| 117 | fd = open(pathname, flags); | ||
| 118 | if (fd == -1) | ||
| 119 | return NULL; | ||
| 120 | |||
| 121 | return lzw_fdopen(fd); | ||
| 122 | } | ||
| 123 | |||
| 124 | |||
| 125 | /* | ||
| 126 | * Close LZW file | ||
| 127 | */ | ||
| 128 | hidden_in_another_lib | ||
| 129 | int lzw_close(lzwFile *lzw) | ||
| 130 | { | ||
| 131 | int ret; | ||
| 132 | if (lzw == NULL) | ||
| 133 | return -1; | ||
| 134 | ret = close(lzw->fd); | ||
| 135 | free(lzw->inbuf); | ||
| 136 | free(lzw->outbuf); | ||
| 137 | free(lzw); | ||
| 138 | return ret; | ||
| 139 | } | ||
| 140 | |||
| 141 | |||
| 142 | /* | ||
| 143 | * Misc read-specific define cruft | ||
| 144 | */ | ||
| 145 | |||
| 146 | #ifndef NOALLIGN | ||
| 147 | # define NOALLIGN 0 | ||
| 148 | #endif | ||
| 149 | |||
| 150 | union bytes { | ||
| 151 | long word; | ||
| 152 | struct { | ||
| 153 | #ifdef WORDS_BIGENDIAN | ||
| 154 | unsigned char b1, b2, b3, b4; | ||
| 155 | #else | ||
| 156 | unsigned char b4, b3, b2, b1; | ||
| 157 | #endif | ||
| 158 | } bytes; | ||
| 159 | }; | ||
| 160 | |||
| 161 | #if defined(WORDS_BIGENDIAN) && NOALLIGN == 1 | ||
| 162 | # define input(b,o,c,n,m) \ | ||
| 163 | do { \ | ||
| 164 | (c) = (*(long *)(&(b)[(o)>>3])>>((o)&0x7))&(m); \ | ||
| 165 | (o) += (n); \ | ||
| 166 | } while (0) | ||
| 167 | #else | ||
| 168 | # define input(b,o,c,n,m) \ | ||
| 169 | do { \ | ||
| 170 | unsigned char *p = &(b)[(o)>>3]; \ | ||
| 171 | (c) = ((((long)(p[0]))|((long)(p[1])<<8)| \ | ||
| 172 | ((long)(p[2])<<16))>>((o)&0x7))&(m); \ | ||
| 173 | (o) += (n); \ | ||
| 174 | } while (0) | ||
| 175 | #endif | ||
| 176 | |||
| 177 | #define de_stack ((unsigned char *)&(lzw->htab[HSIZE-1])) | ||
| 178 | |||
| 179 | /* | ||
| 180 | * Read LZW file | ||
| 181 | */ | ||
| 182 | hidden_in_another_lib | ||
| 183 | ssize_t lzw_read(lzwFile *lzw, void *readbuf, size_t count) | ||
| 184 | { | ||
| 185 | size_t count_left = count; | ||
| 186 | unsigned char *inbuf = lzw->inbuf; | ||
| 187 | unsigned char *outbuf = lzw->outbuf; | ||
| 188 | |||
| 189 | long int maxmaxcode = MAXCODE(lzw->maxbits); | ||
| 190 | |||
| 191 | if (!count || lzw->eof) | ||
| 192 | return 0; | ||
| 193 | |||
| 194 | if (lzw->stackp != NULL) { | ||
| 195 | if (lzw->outpos) { | ||
| 196 | if (lzw->outpos >= count) { | ||
| 197 | outbuf = lzw->unreadbuf; | ||
| 198 | goto empty_existing_buffer; | ||
| 199 | } else /*if (lzw->outpos < count)*/ { | ||
| 200 | memcpy(readbuf, lzw->unreadbuf, lzw->outpos); | ||
| 201 | goto resume_partial_reading; | ||
| 202 | } | ||
| 203 | } | ||
| 204 | goto resume_reading; | ||
| 205 | } | ||
| 206 | |||
| 207 | do { | ||
| 208 | resetbuf: | ||
| 209 | { | ||
| 210 | size_t i, e, o; | ||
| 211 | o = lzw->posbits >> 3; | ||
| 212 | e = o <= lzw->insize ? lzw->insize - o : 0; | ||
| 213 | |||
| 214 | for (i = 0; i < e; ++i) | ||
| 215 | inbuf[i] = inbuf[i+o]; | ||
| 216 | |||
| 217 | lzw->insize = e; | ||
| 218 | lzw->posbits = 0; | ||
| 219 | } | ||
| 220 | |||
| 221 | if (lzw->insize < IN_BUFSIZE-BUFSIZE) { | ||
| 222 | if ((lzw->rsize = read(lzw->fd, inbuf+lzw->insize, BUFSIZE)) < 0) | ||
| 223 | return -1; | ||
| 224 | lzw->insize += lzw->rsize; | ||
| 225 | } | ||
| 226 | |||
| 227 | lzw->inbits = (int)((lzw->rsize > 0) ? (lzw->insize - lzw->insize%lzw->n_bits)<<3 : | ||
| 228 | (lzw->insize<<3) - (lzw->n_bits-1)); | ||
| 229 | |||
| 230 | while (lzw->inbits > lzw->posbits) { | ||
| 231 | if (lzw->free_ent > lzw->maxcode) { | ||
| 232 | lzw->posbits = ((lzw->posbits-1) + ((lzw->n_bits<<3) - | ||
| 233 | (lzw->posbits-1 + (lzw->n_bits<<3)) % (lzw->n_bits<<3))); | ||
| 234 | |||
| 235 | ++lzw->n_bits; | ||
| 236 | if (lzw->n_bits == lzw->maxbits) | ||
| 237 | lzw->maxcode = maxmaxcode; | ||
| 238 | else | ||
| 239 | lzw->maxcode = MAXCODE(lzw->n_bits)-1; | ||
| 240 | |||
| 241 | lzw->bitmask = (1 << lzw->n_bits) - 1; | ||
| 242 | goto resetbuf; | ||
| 243 | } | ||
| 244 | |||
| 245 | input(inbuf,lzw->posbits,lzw->code,lzw->n_bits,lzw->bitmask); | ||
| 246 | |||
| 247 | if (lzw->oldcode == -1) { | ||
| 248 | if (lzw->code >= 256) return -1; /* error("corrupt input."); */ | ||
| 249 | outbuf[lzw->outpos++] = lzw->finchar = lzw->oldcode = (int) lzw->code; | ||
| 250 | continue; | ||
| 251 | } | ||
| 252 | |||
| 253 | if (lzw->code == CLEAR && lzw->block_mode) { | ||
| 254 | memset(lzw->codetab, 0x00, sizeof(lzw->codetab)); | ||
| 255 | lzw->free_ent = FIRST - 1; | ||
| 256 | lzw->posbits = ((lzw->posbits-1) + ((lzw->n_bits<<3) - | ||
| 257 | (lzw->posbits-1 + (lzw->n_bits<<3)) % (lzw->n_bits<<3))); | ||
| 258 | lzw->maxcode = MAXCODE(lzw->n_bits = INIT_BITS)-1; | ||
| 259 | lzw->bitmask = (1 << lzw->n_bits) - 1; | ||
| 260 | goto resetbuf; | ||
| 261 | } | ||
| 262 | |||
| 263 | lzw->incode = lzw->code; | ||
| 264 | lzw->stackp = de_stack; | ||
| 265 | |||
| 266 | /* Special case for KwKwK string.*/ | ||
| 267 | if (lzw->code >= lzw->free_ent) { | ||
| 268 | if (lzw->code > lzw->free_ent) { | ||
| 269 | errno = EINVAL; | ||
| 270 | return -1; | ||
| 271 | } | ||
| 272 | |||
| 273 | *--lzw->stackp = lzw->finchar; | ||
| 274 | lzw->code = lzw->oldcode; | ||
| 275 | } | ||
| 276 | |||
| 277 | /* Generate output characters in reverse order */ | ||
| 278 | while (lzw->code >= 256) { | ||
| 279 | *--lzw->stackp = lzw->htab[lzw->code]; | ||
| 280 | lzw->code = lzw->codetab[lzw->code]; | ||
| 281 | } | ||
| 282 | |||
| 283 | *--lzw->stackp = (lzw->finchar = (int) lzw->htab[lzw->code]); | ||
| 284 | |||
| 285 | /* And put them out in forward order */ | ||
| 286 | { | ||
| 287 | lzw->stackp_diff = de_stack - lzw->stackp; | ||
| 288 | |||
| 289 | if (lzw->outpos+lzw->stackp_diff >= BUFSIZE) { | ||
| 290 | do { | ||
| 291 | if (lzw->stackp_diff > BUFSIZE-lzw->outpos) | ||
| 292 | lzw->stackp_diff = BUFSIZE-lzw->outpos; | ||
| 293 | |||
| 294 | if (lzw->stackp_diff > 0) { | ||
| 295 | memcpy(outbuf+lzw->outpos, lzw->stackp, lzw->stackp_diff); | ||
| 296 | lzw->outpos += lzw->stackp_diff; | ||
| 297 | } | ||
| 298 | |||
| 299 | if (lzw->outpos >= BUFSIZE) { | ||
| 300 | if (lzw->outpos < count_left) { | ||
| 301 | memcpy(readbuf, outbuf, lzw->outpos); | ||
| 302 | resume_partial_reading: | ||
| 303 | readbuf += lzw->outpos; | ||
| 304 | count_left -= lzw->outpos; | ||
| 305 | } else { | ||
| 306 | empty_existing_buffer: | ||
| 307 | lzw->outpos -= count_left; | ||
| 308 | memcpy(readbuf, outbuf, count_left); | ||
| 309 | lzw->unreadbuf = outbuf + count_left; | ||
| 310 | return count; | ||
| 311 | } | ||
| 312 | resume_reading: | ||
| 313 | lzw->outpos = 0; | ||
| 314 | } | ||
| 315 | lzw->stackp += lzw->stackp_diff; | ||
| 316 | } while ((lzw->stackp_diff = (de_stack-lzw->stackp)) > 0); | ||
| 317 | } else { | ||
| 318 | memcpy(outbuf+lzw->outpos, lzw->stackp, lzw->stackp_diff); | ||
| 319 | lzw->outpos += lzw->stackp_diff; | ||
| 320 | } | ||
| 321 | } | ||
| 322 | |||
| 323 | /* Generate the new entry. */ | ||
| 324 | if ((lzw->code = lzw->free_ent) < maxmaxcode) { | ||
| 325 | lzw->codetab[lzw->code] = lzw->oldcode; | ||
| 326 | lzw->htab[lzw->code] = lzw->finchar; | ||
| 327 | lzw->free_ent = lzw->code+1; | ||
| 328 | } | ||
| 329 | |||
| 330 | lzw->oldcode = lzw->incode; /* Remember previous code. */ | ||
| 331 | } | ||
| 332 | } while (lzw->rsize != 0); | ||
| 333 | |||
| 334 | if (lzw->outpos < count_left) { | ||
| 335 | lzw->eof = 1; | ||
| 336 | memcpy(readbuf, outbuf, lzw->outpos); | ||
| 337 | count_left -= lzw->outpos; | ||
| 338 | return (count - count_left); | ||
| 339 | } else { | ||
| 340 | goto empty_existing_buffer; | ||
| 341 | } | ||
| 342 | } | ||
diff --git a/src/lzw/lzw.h b/src/lzw/lzw.h new file mode 100644 index 0000000..a816386 --- /dev/null +++ b/src/lzw/lzw.h | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | /** | ||
| 2 | * @file lzw.h | ||
| 3 | * @brief LZW header file | ||
| 4 | * @internal | ||
| 5 | */ | ||
| 6 | /* | ||
| 7 | * Written by Mike Frysinger <vapier@gmail.com> | ||
| 8 | * Released into the public domain | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef _LZW_H | ||
| 12 | #define _LZW_H | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | extern "C" { | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #define LZW_MAGIC_1 0x1F | ||
| 19 | #define LZW_MAGIC_2 0x9D | ||
| 20 | #define LZW_MAGIC "\037\235" | ||
| 21 | |||
| 22 | #ifdef __IN_LIBLZW | ||
| 23 | # define HBITS 17 /* 50% occupancy */ | ||
| 24 | # define HSIZE (1<<HBITS) | ||
| 25 | # define HMASK (HSIZE-1) | ||
| 26 | # define HPRIME 9941 | ||
| 27 | |||
| 28 | typedef struct { | ||
| 29 | int fd; | ||
| 30 | int eof; | ||
| 31 | |||
| 32 | unsigned char *inbuf, *outbuf, *stackp; | ||
| 33 | unsigned char *unreadbuf; | ||
| 34 | size_t stackp_diff; | ||
| 35 | size_t insize, outpos; | ||
| 36 | ssize_t rsize; | ||
| 37 | |||
| 38 | unsigned char flags; | ||
| 39 | int maxbits, block_mode; | ||
| 40 | |||
| 41 | unsigned long int htab[HSIZE]; | ||
| 42 | unsigned short codetab[HSIZE]; | ||
| 43 | |||
| 44 | int n_bits, posbits, inbits, bitmask, finchar; | ||
| 45 | long int maxcode, oldcode, incode, code, free_ent; | ||
| 46 | } lzwFile; | ||
| 47 | |||
| 48 | #else | ||
| 49 | typedef void lzwFile; | ||
| 50 | #endif | ||
| 51 | |||
| 52 | extern lzwFile *lzw_open(const char*, int); | ||
| 53 | extern lzwFile* lzw_fdopen(int); | ||
| 54 | extern int lzw_close(lzwFile*); | ||
| 55 | extern ssize_t lzw_read(lzwFile*, void*, size_t); | ||
| 56 | |||
| 57 | #ifdef __cplusplus | ||
| 58 | } | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #endif /* _LZW_H */ | ||
diff --git a/src/lzw/lzw_internal.h b/src/lzw/lzw_internal.h new file mode 100644 index 0000000..14db19c --- /dev/null +++ b/src/lzw/lzw_internal.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* | ||
| 2 | * Written by Mike Frysinger <vapier@gmail.com> | ||
| 3 | * Released into the public domain | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef _LIBLZW_INTERNAL_H | ||
| 7 | #define _LIBLZW_INTERNAL_H | ||
| 8 | |||
| 9 | #include "headers.h" | ||
| 10 | |||
| 11 | #define __IN_LIBLZW | ||
| 12 | #include "lzw.h" | ||
| 13 | |||
| 14 | #include "helpers.h" | ||
| 15 | |||
| 16 | #endif /* _LIBLZW_INTERNAL_H */ | ||
diff --git a/src/widget-zcat.c b/src/widget-zcat.c index 3d92cf9..d2d3afd 100644 --- a/src/widget-zcat.c +++ b/src/widget-zcat.c | |||
| @@ -67,6 +67,8 @@ | |||
| 67 | #include <lzma.h> | 67 | #include <lzma.h> |
| 68 | #endif | 68 | #endif |
| 69 | 69 | ||
| 70 | #include "lzw/lzw.h" | ||
| 71 | |||
| 70 | 72 | ||
| 71 | ///////////////// | 73 | ///////////////// |
| 72 | // // | 74 | // // |
| @@ -229,12 +231,11 @@ int scu_widget_zcat(scu_config * cnf) | |||
| 229 | return(scu_widget_zcat_lzma(cnf)); | 231 | return(scu_widget_zcat_lzma(cnf)); |
| 230 | #endif | 232 | #endif |
| 231 | 233 | ||
| 232 | #ifdef USE_Z | ||
| 233 | if (!( memcmp(magic, scm_magic_z_lzw, sizeof(scm_magic_z_lzw)) )) | 234 | if (!( memcmp(magic, scm_magic_z_lzw, sizeof(scm_magic_z_lzw)) )) |
| 234 | return(scu_widget_zcat_prog(cnf, "/usr/bin/uncompress -c")); | 235 | return(scu_widget_zcat_lzw(cnf)); |
| 235 | if (!( memcmp(magic, scm_magic_z_lzh, sizeof(scm_magic_z_lzh)) )) | 236 | |
| 236 | return(scu_widget_zcat_prog(cnf, "/usr/bin/uncompress -c")); | 237 | // if (!( memcmp(magic, scm_magic_z_lzh, sizeof(scm_magic_z_lzh)) )) |
| 237 | #endif | 238 | // return(scu_widget_zcat_lzh(cnf)); |
| 238 | 239 | ||
| 239 | fprintf(stderr, "%s: %s: unable to determine compression algorithms\n", PROGRAM_NAME, cnf->widget->name); | 240 | fprintf(stderr, "%s: %s: unable to determine compression algorithms\n", PROGRAM_NAME, cnf->widget->name); |
| 240 | return(1); | 241 | return(1); |
| @@ -326,14 +327,45 @@ int scu_widget_zcat_gz(scu_config * cnf) | |||
| 326 | #endif | 327 | #endif |
| 327 | 328 | ||
| 328 | 329 | ||
| 329 | int scu_widget_zcat_prog(scu_config * cnf, const char * prog) | 330 | int scu_widget_zcat_lzw(scu_config * cnf) |
| 330 | { | 331 | { |
| 331 | char buff[2048]; | 332 | int fd; |
| 333 | lzwFile * lzw; | ||
| 334 | char buff[4096]; | ||
| 335 | ssize_t len; | ||
| 336 | |||
| 337 | if ((fd = open(cnf->argv[optind], O_RDONLY)) == -1) | ||
| 338 | { | ||
| 339 | fprintf(stderr, "%s: %s: %s\n", cnf->prog_name, cnf->widget->name, strerror(errno)); | ||
| 340 | return(1); | ||
| 341 | }; | ||
| 342 | |||
| 343 | if ((lzw = lzw_fdopen(fd)) == NULL) | ||
| 344 | { | ||
| 345 | fprintf(stderr, "%s: %s: %s\n", cnf->prog_name, cnf->widget->name, strerror(errno)); | ||
| 346 | close(fd); | ||
| 347 | return(1); | ||
| 348 | }; | ||
| 332 | 349 | ||
| 333 | bzero(buff, sizeof(buff)); | 350 | while((len = lzw_read(lzw, buff, sizeof(buff))) > 0) |
| 334 | snprintf(buff, sizeof(buff), "%s %s", prog, cnf->argv[optind]); | 351 | { |
| 352 | if ((len = write(STDOUT_FILENO, buff, len)) == -1) | ||
| 353 | { | ||
| 354 | fprintf(stderr, "%s: %s: %s\n", cnf->prog_name, cnf->widget->name, strerror(errno)); | ||
| 355 | lzw_close(lzw); | ||
| 356 | return(1); | ||
| 357 | }; | ||
| 358 | }; | ||
| 359 | if (len == -1) | ||
| 360 | { | ||
| 361 | fprintf(stderr, "%s: %s: %s\n", cnf->prog_name, cnf->widget->name, strerror(errno)); | ||
| 362 | lzw_close(lzw); | ||
| 363 | return(1); | ||
| 364 | }; | ||
| 365 | |||
| 366 | lzw_close(lzw); | ||
| 335 | 367 | ||
| 336 | return(system(buff)); | 368 | return(0); |
| 337 | } | 369 | } |
| 338 | 370 | ||
| 339 | 371 | ||
diff --git a/src/widget-zcat.h b/src/widget-zcat.h index 198b362..030b8e0 100644 --- a/src/widget-zcat.h +++ b/src/widget-zcat.h | |||
| @@ -63,8 +63,8 @@ | |||
| 63 | int scu_widget_zcat(scu_config * cnf); | 63 | int scu_widget_zcat(scu_config * cnf); |
| 64 | int scu_widget_zcat_bz2(scu_config * cnf); | 64 | int scu_widget_zcat_bz2(scu_config * cnf); |
| 65 | int scu_widget_zcat_gz(scu_config * cnf); | 65 | int scu_widget_zcat_gz(scu_config * cnf); |
| 66 | int scu_widget_zcat_prog(scu_config * cnf, const char * prog); | ||
| 67 | int scu_widget_zcat_lzma(scu_config * cnf); | 66 | int scu_widget_zcat_lzma(scu_config * cnf); |
| 67 | int scu_widget_zcat_lzw(scu_config * cnf); | ||
| 68 | 68 | ||
| 69 | void scu_widget_zcat_usage(scu_config * cnf); | 69 | void scu_widget_zcat_usage(scu_config * cnf); |
| 70 | 70 | ||
