[submodule "gnulib"]
- path = gnulib
- url = git://git.sv.gnu.org/gnulib.git
+ path = gnulib
+ url = git://git.sv.gnu.org/gnulib.git
See the files THANKS and ChangeLog for more details.
- Note about zip vs. gzip:
+ Note about zip vs. gzip:
The name 'gzip' was a very unfortunate choice, because zip and gzip
are two really different programs, although the actual compression and
this package from CVS. The next step is to get other files needed to
build, which are extracted from other source packages:
- $ ./bootstrap
+ $ ./bootstrap
And there you are! Just
- $ ./configure
- $ make
- $ make check
+ $ ./configure
+ $ make
+ $ make check
At this point, there should be no difference between your local copy,
and the CVS master copy:
- $ cvs diff
+ $ cvs diff
should output no difference.
MAX_DIST equ WSIZE-MAX_MATCH-MIN_MATCH-1
- xref _max_chain_length
- xref _prev_length
- xref _prev
- xref _window
- xref _strstart
- xref _good_match
- xref _match_start
- xref _nice_match
+ xref _max_chain_length
+ xref _prev_length
+ xref _prev
+ xref _window
+ xref _strstart
+ xref _good_match
+ xref _match_start
+ xref _nice_match
- section match,code
+ section match,code
- xdef _match_init
- xdef @match_init
- xdef _longest_match
- xdef @longest_match
+ xdef _match_init
+ xdef @match_init
+ xdef _longest_match
+ xdef @longest_match
_match_init:
@match_init:
- rts
+ rts
_longest_match:
- move.l 4(sp),Cur_Match
+ move.l 4(sp),Cur_Match
@longest_match:
- ifd UNALIGNED_OK
- movem.l d2-d6/a2-a4,-(sp)
- else
- movem.l d2-d7/a2-a4,-(sp)
- endc
- move.l _max_chain_length,Chain_Length
- move.l _prev_length,Best_Len
- lea _prev,Prev_Address
- lea _window+MIN_MATCH,Match_Ini
- move.l _strstart,Limit
- move.l Match_Ini,Scan_Ini
- add.l Limit,Scan_Ini
- subi.w #MAX_DIST,Limit
- bhi.b limit_ok
- moveq #0,Limit
+ ifd UNALIGNED_OK
+ movem.l d2-d6/a2-a4,-(sp)
+ else
+ movem.l d2-d7/a2-a4,-(sp)
+ endc
+ move.l _max_chain_length,Chain_Length
+ move.l _prev_length,Best_Len
+ lea _prev,Prev_Address
+ lea _window+MIN_MATCH,Match_Ini
+ move.l _strstart,Limit
+ move.l Match_Ini,Scan_Ini
+ add.l Limit,Scan_Ini
+ subi.w #MAX_DIST,Limit
+ bhi.b limit_ok
+ moveq #0,Limit
limit_ok:
- cmp.l _good_match,Best_Len
- bcs.b length_ok
- lsr.l #2,Chain_Length
+ cmp.l _good_match,Best_Len
+ bcs.b length_ok
+ lsr.l #2,Chain_Length
length_ok:
- subq.l #1,Chain_Length
+ subq.l #1,Chain_Length
- ifd UNALIGNED_OK
+ ifd UNALIGNED_OK
- move.w -MIN_MATCH(Scan_Ini),Scan_Start
- move.w -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
+ move.w -MIN_MATCH(Scan_Ini),Scan_Start
+ move.w -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
- else
+ else
- move.b -MIN_MATCH(Scan_Ini),Scan_Start
- lsl.w #8,Scan_Start
- move.b -MIN_MATCH+1(Scan_Ini),Scan_Start
- move.b -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
- lsl.w #8,Scan_End
- move.b -MIN_MATCH(Scan_Ini,Best_Len),Scan_End
+ move.b -MIN_MATCH(Scan_Ini),Scan_Start
+ lsl.w #8,Scan_Start
+ move.b -MIN_MATCH+1(Scan_Ini),Scan_Start
+ move.b -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
+ lsl.w #8,Scan_End
+ move.b -MIN_MATCH(Scan_Ini,Best_Len),Scan_End
- endc
+ endc
- bra.b do_scan
+ bra.b do_scan
long_loop:
- ifd UNALIGNED_OK
+ ifd UNALIGNED_OK
- move.w -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
+ move.w -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
- else
+ else
- move.b -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
- lsl.w #8,Scan_End
- move.b -MIN_MATCH(Scan_Ini,Best_Len),Scan_End
+ move.b -MIN_MATCH-1(Scan_Ini,Best_Len),Scan_End
+ lsl.w #8,Scan_End
+ move.b -MIN_MATCH(Scan_Ini,Best_Len),Scan_End
- endc
+ endc
short_loop:
- lsl.w #1,Cur_Match
- move.w 0(Prev_Address,Cur_Match),Cur_Match
- cmp.w Limit,Cur_Match
- dbls Chain_Length,do_scan
- bra.b return
+ lsl.w #1,Cur_Match
+ move.w 0(Prev_Address,Cur_Match),Cur_Match
+ cmp.w Limit,Cur_Match
+ dbls Chain_Length,do_scan
+ bra.b return
do_scan:
- move.l Match_Ini,Match
- add.l Cur_Match,Match
+ move.l Match_Ini,Match
+ add.l Cur_Match,Match
- ifd UNALIGNED_OK
+ ifd UNALIGNED_OK
- cmp.w -MIN_MATCH-1(Match,Best_Len),Scan_End
- bne.b short_loop
- cmp.w -MIN_MATCH(Match),Scan_Start
- bne.b short_loop
+ cmp.w -MIN_MATCH-1(Match,Best_Len),Scan_End
+ bne.b short_loop
+ cmp.w -MIN_MATCH(Match),Scan_Start
+ bne.b short_loop
- else
+ else
- move.b -MIN_MATCH-1(Match,Best_Len),Scan_Test
- lsl.w #8,Scan_Test
- move.b -MIN_MATCH(Match,Best_Len),Scan_Test
- cmp.w Scan_Test,Scan_End
- bne.b short_loop
- move.b -MIN_MATCH(Match),Scan_Test
- lsl.w #8,Scan_Test
- move.b -MIN_MATCH+1(Match),Scan_Test
- cmp.w Scan_Test,Scan_Start
- bne.b short_loop
+ move.b -MIN_MATCH-1(Match,Best_Len),Scan_Test
+ lsl.w #8,Scan_Test
+ move.b -MIN_MATCH(Match,Best_Len),Scan_Test
+ cmp.w Scan_Test,Scan_End
+ bne.b short_loop
+ move.b -MIN_MATCH(Match),Scan_Test
+ lsl.w #8,Scan_Test
+ move.b -MIN_MATCH+1(Match),Scan_Test
+ cmp.w Scan_Test,Scan_Start
+ bne.b short_loop
- endc
+ endc
- move.w #(MAX_MATCH-MIN_MATCH),Loop_Counter
- move.l Scan_Ini,Scan
+ move.w #(MAX_MATCH-MIN_MATCH),Loop_Counter
+ move.l Scan_Ini,Scan
scan_loop:
- cmpm.b (Match)+,(Scan)+
- dbne Loop_Counter,scan_loop
-
- sub.l Scan_Ini,Scan
- addq.l #(MIN_MATCH-1),Scan
- cmp.l Best_Len,Scan
- bls.b short_loop
- move.l Scan,Best_Len
- move.l Cur_Match,_match_start
- cmp.l _nice_match,Best_Len
- bcs.b long_loop
+ cmpm.b (Match)+,(Scan)+
+ dbne Loop_Counter,scan_loop
+
+ sub.l Scan_Ini,Scan
+ addq.l #(MIN_MATCH-1),Scan
+ cmp.l Best_Len,Scan
+ bls.b short_loop
+ move.l Scan,Best_Len
+ move.l Cur_Match,_match_start
+ cmp.l _nice_match,Best_Len
+ bcs.b long_loop
return:
- move.l Best_Len,d0
- ifd UNALIGNED_OK
- movem.l (sp)+,d2-d6/a2-a4
- else
- movem.l (sp)+,d2-d7/a2-a4
- endc
- rts
-
- end
+ move.l Best_Len,d0
+ ifd UNALIGNED_OK
+ movem.l (sp)+,d2-d6/a2-a4
+ else
+ movem.l (sp)+,d2-d7/a2-a4
+ endc
+ rts
+
+ end
* for in-memory compression.
*/
if (zfile != NO_FILE) {
- read_buf = file_read;
+ read_buf = file_read;
}
}
while (len--) {
#ifdef CRYPT
int t;
- if (key) zencode(*buf, t);
+ if (key) zencode(*buf, t);
#endif
- put_byte(*buf++);
+ put_byte(*buf++);
}
}
AC_PREREQ([2.60])
AC_INIT([gzip],
- m4_esyscmd([build-aux/git-version-gen .tarball-version]),
- [bug-gzip@gnu.org])
+ m4_esyscmd([build-aux/git-version-gen .tarball-version]),
+ [bug-gzip@gnu.org])
AC_CONFIG_SRCDIR(gzip.c)
AC_CONFIG_AUX_DIR(build-aux)
[gzip_cv_underline=yes
AC_TRY_COMPILE([int foo() {return 0;}], [],
[$NM conftest.$OBJEXT | grep _foo >/dev/null 2>&1 ||
- gzip_cv_underline=no])])
+ gzip_cv_underline=no])])
ASCPPFLAGS=
if test $gzip_cv_underline = no; then
ASCPPFLAGS='-DNO_UNDERLINE'
*' NO_ASM '*) ;;
*)
if cp $srcdir/lib/match.c _match.S &&
- eval "$CPP $CPPFLAGS $ASCPPFLAGS _match.S > _match.i" 2>/dev/null &&
- eval "$ASCPPPOST < _match.i > match_.s" 2>/dev/null; then
+ eval "$CPP $CPPFLAGS $ASCPPFLAGS _match.S > _match.i" 2>/dev/null &&
+ eval "$ASCPPPOST < _match.i > match_.s" 2>/dev/null; then
if test ! -s match_.s || grep error < match_.s > /dev/null; then
- :
+ :
elif eval "$CC $CPPFLAGS $CFLAGS -c match_.s >/dev/null 2>&1" &&
- test -f match_.$OBJEXT; then
- rm -f match_.$OBJEXT
- gzip_cv_assembler=yes
- if echo 'void foo (void) {}' > conftest.c &&
- eval "$CC $CPPFLAGS $CFLAGS -S conftest.c >/dev/null 2>&1" &&
- grep '\.note\.GNU-stack' conftest.s >/dev/null 2>&1 &&
- eval "$CC $CPPFLAGS $CFLAGS -c -Wa,--noexecstack match_.s >/dev/null 2>&1" &&
- test -f match_.$OBJEXT; then
- gzip_cv_assembler='yes, with -Wa,--noexecstack'
- fi
+ test -f match_.$OBJEXT; then
+ rm -f match_.$OBJEXT
+ gzip_cv_assembler=yes
+ if echo 'void foo (void) {}' > conftest.c &&
+ eval "$CC $CPPFLAGS $CFLAGS -S conftest.c >/dev/null 2>&1" &&
+ grep '\.note\.GNU-stack' conftest.s >/dev/null 2>&1 &&
+ eval "$CC $CPPFLAGS $CFLAGS -c -Wa,--noexecstack match_.s >/dev/null 2>&1" &&
+ test -f match_.$OBJEXT; then
+ gzip_cv_assembler='yes, with -Wa,--noexecstack'
+ fi
fi
fi
rm -f conftest* _match.i _match.S match_.s match_.$OBJEXT;;
#endif
lookahead = read_buf((char*)window,
- sizeof(int) <= 2 ? (unsigned)WSIZE : 2*WSIZE);
+ sizeof(int) <= 2 ? (unsigned)WSIZE : 2*WSIZE);
if (lookahead == 0 || lookahead == (unsigned)EOF) {
eofile = 1, lookahead = 0;
#endif
}
} while ((cur_match = prev[cur_match & WMASK]) > limit
- && --chain_length != 0);
+ && --chain_length != 0);
return best_len;
}
* At this point we have always match_length < MIN_MATCH
*/
if (hash_head != NIL && strstart - hash_head <= MAX_DIST
- && strstart <= window_size - MIN_LOOKAHEAD) {
+ && strstart <= window_size - MIN_LOOKAHEAD) {
/* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file).
lookahead -= match_length;
- /* Insert new strings in the hash table only if the match length
+ /* Insert new strings in the hash table only if the match length
* is not too large. This saves time but degrades compression.
*/
if (match_length <= max_insert_length) {
* the next lookahead bytes will be emitted as literals.
*/
} while (--match_length != 0);
- strstart++;
+ strstart++;
} else {
- strstart += match_length;
- match_length = 0;
- ins_h = window[strstart];
- UPDATE_HASH(ins_h, window[strstart+1]);
+ strstart += match_length;
+ match_length = 0;
+ ins_h = window[strstart];
+ UPDATE_HASH(ins_h, window[strstart+1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
Tracevv((stderr,"%c",window[strstart]));
flush = ct_tally (0, window[strstart]);
lookahead--;
- strstart++;
+ strstart++;
}
if (flush) FLUSH_BLOCK(0), block_start = strstart;
#include "ignore-value.h"
#include "stat-time.h"
- /* configuration */
+ /* configuration */
#include <fcntl.h>
#include <limits.h>
# define PART_SEP "."
#endif
- /* global buffers */
+ /* global buffers */
DECLARE(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
DECLARE(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
DECLARE(ush, tab_prefix1, 1L<<(BITS-1));
#endif
- /* local variables */
+ /* local variables */
int ascii = 0; /* convert end-of-lines to local OS conventions */
int to_stdout = 0; /* output to stdout (-c) */
try_help ()
{
fprintf (stderr, "Try `%s --help' for more information.\n",
- program_name);
+ program_name);
do_exit (ERROR);
}
* Ignore an .exe extension for MSDOS, OS/2 and VMS.
*/
if (strncmp (program_name, "un", 2) == 0 /* ungzip, uncompress */
- || strncmp (program_name, "gun", 3) == 0) /* gunzip */
- decompress = 1;
+ || strncmp (program_name, "gun", 3) == 0) /* gunzip */
+ decompress = 1;
else if (strequ (program_name + 1, "cat") /* zcat, pcat, gcat */
- || strequ (program_name, "gzcat")) /* gzcat */
- decompress = to_stdout = 1;
+ || strequ (program_name, "gzcat")) /* gzcat */
+ decompress = to_stdout = 1;
#endif
z_suffix = Z_SUFFIX;
z_len = strlen(z_suffix);
while ((optc = getopt_long (argc, argv, "ab:cdfhH?lLmMnNqrS:tvVZ123456789",
- longopts, (int *)0)) != -1) {
- switch (optc) {
+ longopts, (int *)0)) != -1) {
+ switch (optc) {
case 'a':
ascii = 1; break;
- case 'b':
- maxbits = atoi(optarg);
- for (; *optarg; optarg++)
- if (! ('0' <= *optarg && *optarg <= '9'))
- {
- fprintf (stderr, "%s: -b operand is not an integer\n",
- program_name);
- try_help ();
- }
- break;
- case 'c':
- to_stdout = 1; break;
- case 'd':
- decompress = 1; break;
- case 'f':
- force++; break;
- case 'h': case 'H':
- help(); do_exit(OK); break;
- case 'l':
- list = decompress = to_stdout = 1; break;
- case 'L':
- license(); do_exit(OK); break;
- case 'm': /* undocumented, may change later */
- no_time = 1; break;
- case 'M': /* undocumented, may change later */
- no_time = 0; break;
- case 'n':
- no_name = no_time = 1; break;
- case 'N':
- no_name = no_time = 0; break;
- case 'q':
- quiet = 1; verbose = 0; break;
- case 'r':
+ case 'b':
+ maxbits = atoi(optarg);
+ for (; *optarg; optarg++)
+ if (! ('0' <= *optarg && *optarg <= '9'))
+ {
+ fprintf (stderr, "%s: -b operand is not an integer\n",
+ program_name);
+ try_help ();
+ }
+ break;
+ case 'c':
+ to_stdout = 1; break;
+ case 'd':
+ decompress = 1; break;
+ case 'f':
+ force++; break;
+ case 'h': case 'H':
+ help(); do_exit(OK); break;
+ case 'l':
+ list = decompress = to_stdout = 1; break;
+ case 'L':
+ license(); do_exit(OK); break;
+ case 'm': /* undocumented, may change later */
+ no_time = 1; break;
+ case 'M': /* undocumented, may change later */
+ no_time = 0; break;
+ case 'n':
+ no_name = no_time = 1; break;
+ case 'N':
+ no_name = no_time = 0; break;
+ case 'q':
+ quiet = 1; verbose = 0; break;
+ case 'r':
#if NO_DIR
- fprintf (stderr, "%s: -r not supported on this system\n",
- program_name);
- try_help ();
+ fprintf (stderr, "%s: -r not supported on this system\n",
+ program_name);
+ try_help ();
#else
- recursive = 1;
+ recursive = 1;
#endif
- break;
- case 'S':
+ break;
+ case 'S':
#ifdef NO_MULTIPLE_DOTS
if (*optarg == '.') optarg++;
#endif
z_len = strlen(optarg);
- z_suffix = optarg;
+ z_suffix = optarg;
+ break;
+ case 't':
+ test = decompress = to_stdout = 1;
break;
- case 't':
- test = decompress = to_stdout = 1;
- break;
- case 'v':
- verbose++; quiet = 0; break;
- case 'V':
- version(); do_exit(OK); break;
- case 'Z':
+ case 'v':
+ verbose++; quiet = 0; break;
+ case 'V':
+ version(); do_exit(OK); break;
+ case 'Z':
#ifdef LZW
- do_lzw = 1; break;
+ do_lzw = 1; break;
#else
- fprintf(stderr, "%s: -Z not supported in this version\n",
- program_name);
- try_help ();
- break;
+ fprintf(stderr, "%s: -Z not supported in this version\n",
+ program_name);
+ try_help ();
+ break;
#endif
- case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- level = optc - '0';
- break;
- default:
- /* Error message already emitted by getopt_long. */
- try_help ();
- }
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ level = optc - '0';
+ break;
+ default:
+ /* Error message already emitted by getopt_long. */
+ try_help ();
+ }
} /* loop on all arguments */
/* By default, save name and timestamp on compression but do not
#if O_BINARY
#else
if (ascii && !quiet) {
- fprintf(stderr, "%s: option --ascii ignored on this system\n",
- program_name);
+ fprintf(stderr, "%s: option --ascii ignored on this system\n",
+ program_name);
}
#endif
if ((z_len == 0 && !decompress) || z_len > MAX_SUFFIX) {
/* And get to work */
if (file_count != 0) {
- if (to_stdout && !test && !list && (!decompress || !ascii)) {
- SET_BINARY_MODE(fileno(stdout));
- }
+ if (to_stdout && !test && !list && (!decompress || !ascii)) {
+ SET_BINARY_MODE(fileno(stdout));
+ }
while (optind < argc) {
- treat_file(argv[optind++]);
- }
+ treat_file(argv[optind++]);
+ }
} else { /* Standard input */
- treat_stdin();
+ treat_stdin();
}
if (list && !quiet && file_count > 1) {
- do_list(-1, -1); /* print totals */
+ do_list(-1, -1); /* print totals */
}
do_exit(exit_code);
return exit_code; /* just to avoid lint warning */
if (inptr == insize)
{
if (insize != INBUFSIZ || fill_inbuf (1) == EOF)
- return 1;
+ return 1;
/* Unget the char that fill_inbuf got. */
inptr = 0;
local void treat_stdin()
{
if (!force && !list &&
- isatty(fileno((FILE *)(decompress ? stdin : stdout)))) {
- /* Do not send compressed data to the terminal or read it from
- * the terminal. We get here when user invoked the program
- * without parameters, so be helpful. According to the GNU standards:
- *
- * If there is one behavior you think is most useful when the output
- * is to a terminal, and another that you think is most useful when
- * the output is a file or a pipe, then it is usually best to make
- * the default behavior the one that is useful with output to a
- * terminal, and have an option for the other behavior.
- *
- * Here we use the --force option to get the other behavior.
- */
- fprintf(stderr,
+ isatty(fileno((FILE *)(decompress ? stdin : stdout)))) {
+ /* Do not send compressed data to the terminal or read it from
+ * the terminal. We get here when user invoked the program
+ * without parameters, so be helpful. According to the GNU standards:
+ *
+ * If there is one behavior you think is most useful when the output
+ * is to a terminal, and another that you think is most useful when
+ * the output is a file or a pipe, then it is usually best to make
+ * the default behavior the one that is useful with output to a
+ * terminal, and have an option for the other behavior.
+ *
+ * Here we use the --force option to get the other behavior.
+ */
+ fprintf(stderr,
"%s: compressed data not %s a terminal. Use -f to force %scompression.\n",
- program_name, decompress ? "read from" : "written to",
- decompress ? "de" : "");
- fprintf (stderr, "For help, type: %s -h\n", program_name);
- do_exit(ERROR);
+ program_name, decompress ? "read from" : "written to",
+ decompress ? "de" : "");
+ fprintf (stderr, "For help, type: %s -h\n", program_name);
+ do_exit(ERROR);
}
if (decompress || !ascii) {
- SET_BINARY_MODE(fileno(stdin));
+ SET_BINARY_MODE(fileno(stdin));
}
if (!test && !list && (!decompress || !ascii)) {
- SET_BINARY_MODE(fileno(stdout));
+ SET_BINARY_MODE(fileno(stdout));
}
strcpy(ifname, "stdin");
strcpy(ofname, "stdout");
/* Get the file's time stamp and size. */
if (fstat (fileno (stdin), &istat) != 0)
{
- progerror ("standard input");
- do_exit (ERROR);
+ progerror ("standard input");
+ do_exit (ERROR);
}
ifile_size = S_ISREG (istat.st_mode) ? istat.st_size : -1;
time_stamp.tv_nsec = -1;
ifd = fileno(stdin);
if (decompress) {
- method = get_method(ifd);
- if (method < 0) {
- do_exit(exit_code); /* error message already emitted */
- }
+ method = get_method(ifd);
+ if (method < 0) {
+ do_exit(exit_code); /* error message already emitted */
+ }
}
if (list) {
do_list(ifd, method);
/* Actually do the compression/decompression. Loop over zipped members.
*/
for (;;) {
- if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
+ if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
- if (input_eof ())
- break;
+ if (input_eof ())
+ break;
- method = get_method(ifd);
- if (method < 0) return; /* error message already emitted */
- bytes_out = 0; /* required for length check */
+ method = get_method(ifd);
+ if (method < 0) return; /* error message already emitted */
+ bytes_out = 0; /* required for length check */
}
if (verbose) {
- if (test) {
- fprintf(stderr, " OK\n");
+ if (test) {
+ fprintf(stderr, " OK\n");
- } else if (!decompress) {
- display_ratio(bytes_in-(bytes_out-header_bytes), bytes_in, stderr);
- fprintf(stderr, "\n");
+ } else if (!decompress) {
+ display_ratio(bytes_in-(bytes_out-header_bytes), bytes_in, stderr);
+ fprintf(stderr, "\n");
#ifdef DISPLAY_STDIN_RATIO
- } else {
- display_ratio(bytes_out-(bytes_in-header_bytes), bytes_out,stderr);
- fprintf(stderr, "\n");
+ } else {
+ display_ratio(bytes_out-(bytes_in-header_bytes), bytes_out,stderr);
+ fprintf(stderr, "\n");
#endif
- }
+ }
}
}
{
/* Accept "-" as synonym for stdin */
if (strequ(iname, "-")) {
- int cflag = to_stdout;
- treat_stdin();
- to_stdout = cflag;
- return;
+ int cflag = to_stdout;
+ treat_stdin();
+ to_stdout = cflag;
+ return;
}
/* Check if the input file is present, set ifname and istat: */
/* If the input name is that of a directory, recurse or ignore: */
if (S_ISDIR(istat.st_mode)) {
#if ! NO_DIR
- if (recursive) {
- treat_dir (ifd, iname);
- /* Warning: ifname is now garbage */
- return;
- }
+ if (recursive) {
+ treat_dir (ifd, iname);
+ /* Warning: ifname is now garbage */
+ return;
+ }
#endif
- close (ifd);
- WARN ((stderr, "%s: %s is a directory -- ignored\n",
- program_name, ifname));
- return;
+ close (ifd);
+ WARN ((stderr, "%s: %s is a directory -- ignored\n",
+ program_name, ifname));
+ return;
}
if (! to_stdout)
{
- if (! S_ISREG (istat.st_mode))
- {
- WARN ((stderr,
- "%s: %s is not a directory or a regular file - ignored\n",
- program_name, ifname));
- close (ifd);
- return;
- }
- if (istat.st_mode & S_ISUID)
- {
- WARN ((stderr, "%s: %s is set-user-ID on execution - ignored\n",
- program_name, ifname));
- close (ifd);
- return;
- }
- if (istat.st_mode & S_ISGID)
- {
- WARN ((stderr, "%s: %s is set-group-ID on execution - ignored\n",
- program_name, ifname));
- close (ifd);
- return;
- }
-
- if (! force)
- {
- if (istat.st_mode & S_ISVTX)
- {
- WARN ((stderr,
- "%s: %s has the sticky bit set - file ignored\n",
- program_name, ifname));
- close (ifd);
- return;
- }
- if (2 <= istat.st_nlink)
- {
- WARN ((stderr, "%s: %s has %lu other link%c -- unchanged\n",
- program_name, ifname,
- (unsigned long int) istat.st_nlink - 1,
- istat.st_nlink == 2 ? ' ' : 's'));
- close (ifd);
- return;
- }
- }
+ if (! S_ISREG (istat.st_mode))
+ {
+ WARN ((stderr,
+ "%s: %s is not a directory or a regular file - ignored\n",
+ program_name, ifname));
+ close (ifd);
+ return;
+ }
+ if (istat.st_mode & S_ISUID)
+ {
+ WARN ((stderr, "%s: %s is set-user-ID on execution - ignored\n",
+ program_name, ifname));
+ close (ifd);
+ return;
+ }
+ if (istat.st_mode & S_ISGID)
+ {
+ WARN ((stderr, "%s: %s is set-group-ID on execution - ignored\n",
+ program_name, ifname));
+ close (ifd);
+ return;
+ }
+
+ if (! force)
+ {
+ if (istat.st_mode & S_ISVTX)
+ {
+ WARN ((stderr,
+ "%s: %s has the sticky bit set - file ignored\n",
+ program_name, ifname));
+ close (ifd);
+ return;
+ }
+ if (2 <= istat.st_nlink)
+ {
+ WARN ((stderr, "%s: %s has %lu other link%c -- unchanged\n",
+ program_name, ifname,
+ (unsigned long int) istat.st_nlink - 1,
+ istat.st_nlink == 2 ? ' ' : 's'));
+ close (ifd);
+ return;
+ }
+ }
}
ifile_size = S_ISREG (istat.st_mode) ? istat.st_size : -1;
* without a valid gzip suffix (check done in make_ofname).
*/
if (to_stdout && !list && !test) {
- strcpy(ofname, "stdout");
+ strcpy(ofname, "stdout");
} else if (make_ofname() != OK) {
- close (ifd);
- return;
+ close (ifd);
+ return;
}
clear_bufs(); /* clear input and output buffers */
part_nb = 0;
if (decompress) {
- method = get_method(ifd); /* updates ofname if original given */
- if (method < 0) {
- close(ifd);
- return; /* error message already emitted */
- }
+ method = get_method(ifd); /* updates ofname if original given */
+ if (method < 0) {
+ close(ifd);
+ return; /* error message already emitted */
+ }
}
if (list) {
do_list(ifd, method);
if (close (ifd) != 0)
- read_error ();
+ read_error ();
return;
}
* a new ofname and save the original name in the compressed file.
*/
if (to_stdout) {
- ofd = fileno(stdout);
- /* Keep remove_ofname_fd negative. */
+ ofd = fileno(stdout);
+ /* Keep remove_ofname_fd negative. */
} else {
- if (create_outfile() != OK) return;
+ if (create_outfile() != OK) return;
- if (!decompress && save_orig_name && !verbose && !quiet) {
- fprintf(stderr, "%s: %s compressed to %s\n",
- program_name, ifname, ofname);
- }
+ if (!decompress && save_orig_name && !verbose && !quiet) {
+ fprintf(stderr, "%s: %s compressed to %s\n",
+ program_name, ifname, ofname);
+ }
}
/* Keep the name even if not truncated except with --no-name: */
if (!save_orig_name) save_orig_name = !no_name;
if (verbose) {
- fprintf(stderr, "%s:\t", ifname);
+ fprintf(stderr, "%s:\t", ifname);
}
/* Actually do the compression/decompression. Loop over zipped members.
*/
for (;;) {
- if ((*work)(ifd, ofd) != OK) {
- method = -1; /* force cleanup */
- break;
- }
+ if ((*work)(ifd, ofd) != OK) {
+ method = -1; /* force cleanup */
+ break;
+ }
- if (input_eof ())
- break;
+ if (input_eof ())
+ break;
- method = get_method(ifd);
- if (method < 0) break; /* error message already emitted */
- bytes_out = 0; /* required for length check */
+ method = get_method(ifd);
+ if (method < 0) break; /* error message already emitted */
+ bytes_out = 0; /* required for length check */
}
if (close (ifd) != 0)
if (!to_stdout)
{
- sigset_t oldset;
- int unlink_errno;
-
- copy_stat (&istat);
- if (close (ofd) != 0)
- write_error ();
-
- sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
- remove_ofname_fd = -1;
- unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
- sigprocmask (SIG_SETMASK, &oldset, NULL);
-
- if (unlink_errno)
- {
- WARN ((stderr, "%s: ", program_name));
- if (!quiet)
- {
- errno = unlink_errno;
- perror (ifname);
- }
- }
+ sigset_t oldset;
+ int unlink_errno;
+
+ copy_stat (&istat);
+ if (close (ofd) != 0)
+ write_error ();
+
+ sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
+ remove_ofname_fd = -1;
+ unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
+ sigprocmask (SIG_SETMASK, &oldset, NULL);
+
+ if (unlink_errno)
+ {
+ WARN ((stderr, "%s: ", program_name));
+ if (!quiet)
+ {
+ errno = unlink_errno;
+ perror (ifname);
+ }
+ }
}
if (method == -1) {
- if (!to_stdout)
- remove_output_file ();
- return;
+ if (!to_stdout)
+ remove_output_file ();
+ return;
}
/* Display statistics */
if(verbose) {
- if (test) {
- fprintf(stderr, " OK");
- } else if (decompress) {
- display_ratio(bytes_out-(bytes_in-header_bytes), bytes_out,stderr);
- } else {
- display_ratio(bytes_in-(bytes_out-header_bytes), bytes_in, stderr);
- }
- if (!test && !to_stdout) {
- fprintf(stderr, " -- replaced with %s", ofname);
- }
- fprintf(stderr, "\n");
+ if (test) {
+ fprintf(stderr, " OK");
+ } else if (decompress) {
+ display_ratio(bytes_out-(bytes_in-header_bytes), bytes_out,stderr);
+ } else {
+ display_ratio(bytes_in-(bytes_out-header_bytes), bytes_in, stderr);
+ }
+ if (!test && !to_stdout) {
+ fprintf(stderr, " -- replaced with %s", ofname);
+ }
+ fprintf(stderr, "\n");
}
}
{
int name_shortened = 0;
int flags = (O_WRONLY | O_CREAT | O_EXCL
- | (ascii && decompress ? 0 : O_BINARY));
+ | (ascii && decompress ? 0 : O_BINARY));
for (;;)
{
sigprocmask (SIG_SETMASK, &oldset, NULL);
if (0 <= ofd)
- break;
+ break;
switch (open_errno)
- {
+ {
#ifdef ENAMETOOLONG
- case ENAMETOOLONG:
- shorten_name (ofname);
- name_shortened = 1;
- break;
+ case ENAMETOOLONG:
+ shorten_name (ofname);
+ name_shortened = 1;
+ break;
#endif
- case EEXIST:
- if (check_ofname () != OK)
- {
- close (ifd);
- return ERROR;
- }
- break;
-
- default:
- progerror (ofname);
- close (ifd);
- return ERROR;
- }
+ case EEXIST:
+ if (check_ofname () != OK)
+ {
+ close (ifd);
+ return ERROR;
+ }
+ break;
+
+ default:
+ progerror (ofname);
+ close (ifd);
+ return ERROR;
+ }
}
if (name_shortened && decompress)
{
/* name might be too long if an original name was saved */
WARN ((stderr, "%s: %s: warning, name truncated\n",
- program_name, ofname));
+ program_name, ofname));
}
return OK;
#ifdef SUFFIX_SEP
/* strip a version number from the file name */
{
- char *v = strrchr(name, SUFFIX_SEP);
- if (v != NULL) *v = '\0';
+ char *v = strrchr(name, SUFFIX_SEP);
+ if (v != NULL) *v = '\0';
}
#endif
nlen = strlen(name);
if (!to_stdout && !force)
{
if (HAVE_WORKING_O_NOFOLLOW)
- flags |= O_NOFOLLOW;
+ flags |= O_NOFOLLOW;
else
- {
+ {
#if HAVE_LSTAT || defined lstat
- if (lstat (name, st) != 0)
- return -1;
- else if (S_ISLNK (st->st_mode))
- {
- errno = ELOOP;
- return -1;
- }
+ if (lstat (name, st) != 0)
+ return -1;
+ else if (S_ISLNK (st->st_mode))
+ {
+ errno = ELOOP;
+ return -1;
+ }
#endif
- }
+ }
}
fd = OPEN (name, flags, mode);
#endif
int fd;
int open_flags = (O_RDONLY | O_NONBLOCK | O_NOCTTY
- | (ascii && !decompress ? 0 : O_BINARY));
+ | (ascii && !decompress ? 0 : O_BINARY));
*suf = z_suffix;
if (sizeof ifname - 1 <= strlen (iname))
- goto name_too_long;
+ goto name_too_long;
strcpy(ifname, iname);
return fd;
if (!decompress || errno != ENOENT) {
- progerror(ifname);
- return -1;
+ progerror(ifname);
+ return -1;
}
/* file.ext doesn't exist, try adding a suffix (after removing any
* version number for VMS).
*/
s = get_suffix(ifname);
if (s != NULL) {
- progerror(ifname); /* ifname already has z suffix and does not exist */
- return -1;
+ progerror(ifname); /* ifname already has z suffix and does not exist */
+ return -1;
}
#ifdef NO_MULTIPLE_DOTS
dot = strrchr(ifname, '.');
if (*dot == '\0') strcpy (dot, ".");
#endif
#ifdef MAX_EXT_CHARS
- if (MAX_EXT_CHARS < strlen (s) + strlen (dot + 1))
- dot[MAX_EXT_CHARS + 1 - strlen (s)] = '\0';
+ if (MAX_EXT_CHARS < strlen (s) + strlen (dot + 1))
+ dot[MAX_EXT_CHARS + 1 - strlen (s)] = '\0';
#endif
- if (sizeof ifname <= ilen + strlen (s))
- goto name_too_long;
+ if (sizeof ifname <= ilen + strlen (s))
+ goto name_too_long;
strcat(ifname, s);
- fd = open_and_stat (ifname, open_flags, RW_USER, sbuf);
- if (0 <= fd)
- return fd;
- if (errno != ENOENT)
- {
- progerror (ifname);
- return -1;
- }
- if (strequ (s0, z_suffix))
- z_suffix_errno = errno;
+ fd = open_and_stat (ifname, open_flags, RW_USER, sbuf);
+ if (0 <= fd)
+ return fd;
+ if (errno != ENOENT)
+ {
+ progerror (ifname);
+ return -1;
+ }
+ if (strequ (s0, z_suffix))
+ z_suffix_errno = errno;
} while (*++suf != NULL);
/* No suffix found, complain using z_suffix: */
suff = get_suffix(ofname);
if (decompress) {
- if (suff == NULL) {
- /* With -t or -l, try all files (even without .gz suffix)
- * except with -r (behave as with just -dr).
+ if (suff == NULL) {
+ /* With -t or -l, try all files (even without .gz suffix)
+ * except with -r (behave as with just -dr).
*/
if (!recursive && (list || test)) return OK;
- /* Avoid annoying messages with -r */
- if (verbose || (!recursive && !quiet)) {
- WARN((stderr,"%s: %s: unknown suffix -- ignored\n",
- program_name, ifname));
- }
- return WARNING;
- }
- /* Make a special case for .tgz and .taz: */
- strlwr(suff);
- if (strequ(suff, ".tgz") || strequ(suff, ".taz")) {
- strcpy(suff, ".tar");
- } else {
- *suff = '\0'; /* strip the z suffix */
- }
+ /* Avoid annoying messages with -r */
+ if (verbose || (!recursive && !quiet)) {
+ WARN((stderr,"%s: %s: unknown suffix -- ignored\n",
+ program_name, ifname));
+ }
+ return WARNING;
+ }
+ /* Make a special case for .tgz and .taz: */
+ strlwr(suff);
+ if (strequ(suff, ".tgz") || strequ(suff, ".taz")) {
+ strcpy(suff, ".tar");
+ } else {
+ *suff = '\0'; /* strip the z suffix */
+ }
/* ofname might be changed later if infile contains an original name */
} else if (suff && ! force) {
- /* Avoid annoying messages with -r (see treat_dir()) */
- if (verbose || (!recursive && !quiet)) {
- /* Don't use WARN, as it affects exit status. */
- fprintf (stderr, "%s: %s already has %s suffix -- unchanged\n",
- program_name, ifname, suff);
- }
- return WARNING;
+ /* Avoid annoying messages with -r (see treat_dir()) */
+ if (verbose || (!recursive && !quiet)) {
+ /* Don't use WARN, as it affects exit status. */
+ fprintf (stderr, "%s: %s already has %s suffix -- unchanged\n",
+ program_name, ifname, suff);
+ }
+ return WARNING;
} else {
save_orig_name = 0;
#ifdef NO_MULTIPLE_DOTS
- suff = strrchr(ofname, '.');
- if (suff == NULL) {
- if (sizeof ofname <= strlen (ofname) + 1)
- goto name_too_long;
+ suff = strrchr(ofname, '.');
+ if (suff == NULL) {
+ if (sizeof ofname <= strlen (ofname) + 1)
+ goto name_too_long;
strcat(ofname, ".");
# ifdef MAX_EXT_CHARS
- if (strequ(z_suffix, "z")) {
- if (sizeof ofname <= strlen (ofname) + 2)
- goto name_too_long;
- strcat(ofname, "gz"); /* enough room */
- return OK;
- }
+ if (strequ(z_suffix, "z")) {
+ if (sizeof ofname <= strlen (ofname) + 2)
+ goto name_too_long;
+ strcat(ofname, "gz"); /* enough room */
+ return OK;
+ }
/* On the Atari and some versions of MSDOS,
* ENAMETOOLONG does not work correctly. So we
* must truncate here.
# endif
}
#endif /* NO_MULTIPLE_DOTS */
- if (sizeof ofname <= strlen (ofname) + z_len)
- goto name_too_long;
- strcat(ofname, z_suffix);
+ if (sizeof ofname <= strlen (ofname) + z_len)
+ goto name_too_long;
+ strcat(ofname, z_suffix);
} /* decompress ? */
return OK;
* premature end of file: use try_byte instead of get_byte.
*/
if (force && to_stdout) {
- magic[0] = (char)try_byte();
- imagic1 = try_byte ();
- magic[1] = (char) imagic1;
- /* If try_byte returned EOF, magic[1] == (char) EOF. */
+ magic[0] = (char)try_byte();
+ imagic1 = try_byte ();
+ magic[1] = (char) imagic1;
+ /* If try_byte returned EOF, magic[1] == (char) EOF. */
} else {
- magic[0] = (char)get_byte();
- if (magic[0]) {
- magic[1] = (char)get_byte();
- imagic1 = 0; /* avoid lint warning */
- } else {
- imagic1 = try_byte ();
- magic[1] = (char) imagic1;
- }
+ magic[0] = (char)get_byte();
+ if (magic[0]) {
+ magic[1] = (char)get_byte();
+ imagic1 = 0; /* avoid lint warning */
+ } else {
+ imagic1 = try_byte ();
+ magic[1] = (char) imagic1;
+ }
}
method = -1; /* unknown yet */
part_nb++; /* number of parts in gzip file */
if (memcmp(magic, GZIP_MAGIC, 2) == 0
|| memcmp(magic, OLD_GZIP_MAGIC, 2) == 0) {
- method = (int)get_byte();
- if (method != DEFLATED) {
- fprintf(stderr,
- "%s: %s: unknown method %d -- not supported\n",
- program_name, ifname, method);
- exit_code = ERROR;
- return -1;
- }
- work = unzip;
- flags = (uch)get_byte();
-
- if ((flags & ENCRYPTED) != 0) {
- fprintf(stderr,
- "%s: %s is encrypted -- not supported\n",
- program_name, ifname);
- exit_code = ERROR;
- return -1;
- }
- if ((flags & CONTINUATION) != 0) {
- fprintf(stderr,
- "%s: %s is a multi-part gzip file -- not supported\n",
- program_name, ifname);
- exit_code = ERROR;
- if (force <= 1) return -1;
- }
- if ((flags & RESERVED) != 0) {
- fprintf(stderr,
- "%s: %s has flags 0x%x -- not supported\n",
- program_name, ifname, flags);
- exit_code = ERROR;
- if (force <= 1) return -1;
- }
- stamp = (ulg)get_byte();
- stamp |= ((ulg)get_byte()) << 8;
- stamp |= ((ulg)get_byte()) << 16;
- stamp |= ((ulg)get_byte()) << 24;
- if (stamp != 0 && !no_time)
- {
- time_stamp.tv_sec = stamp;
- time_stamp.tv_nsec = 0;
- }
-
- (void)get_byte(); /* Ignore extra flags for the moment */
- (void)get_byte(); /* Ignore OS type for the moment */
-
- if ((flags & CONTINUATION) != 0) {
- unsigned part = (unsigned)get_byte();
- part |= ((unsigned)get_byte())<<8;
- if (verbose) {
- fprintf(stderr,"%s: %s: part number %u\n",
- program_name, ifname, part);
- }
- }
- if ((flags & EXTRA_FIELD) != 0) {
- unsigned len = (unsigned)get_byte();
- len |= ((unsigned)get_byte())<<8;
- if (verbose) {
- fprintf(stderr,"%s: %s: extra field of %u bytes ignored\n",
- program_name, ifname, len);
- }
- while (len--) (void)get_byte();
- }
-
- /* Get original file name if it was truncated */
- if ((flags & ORIG_NAME) != 0) {
- if (no_name || (to_stdout && !list) || part_nb > 1) {
- /* Discard the old name */
- char c; /* dummy used for NeXTstep 3.0 cc optimizer bug */
- do {c=get_byte();} while (c != 0);
- } else {
- /* Copy the base name. Keep a directory prefix intact. */
+ method = (int)get_byte();
+ if (method != DEFLATED) {
+ fprintf(stderr,
+ "%s: %s: unknown method %d -- not supported\n",
+ program_name, ifname, method);
+ exit_code = ERROR;
+ return -1;
+ }
+ work = unzip;
+ flags = (uch)get_byte();
+
+ if ((flags & ENCRYPTED) != 0) {
+ fprintf(stderr,
+ "%s: %s is encrypted -- not supported\n",
+ program_name, ifname);
+ exit_code = ERROR;
+ return -1;
+ }
+ if ((flags & CONTINUATION) != 0) {
+ fprintf(stderr,
+ "%s: %s is a multi-part gzip file -- not supported\n",
+ program_name, ifname);
+ exit_code = ERROR;
+ if (force <= 1) return -1;
+ }
+ if ((flags & RESERVED) != 0) {
+ fprintf(stderr,
+ "%s: %s has flags 0x%x -- not supported\n",
+ program_name, ifname, flags);
+ exit_code = ERROR;
+ if (force <= 1) return -1;
+ }
+ stamp = (ulg)get_byte();
+ stamp |= ((ulg)get_byte()) << 8;
+ stamp |= ((ulg)get_byte()) << 16;
+ stamp |= ((ulg)get_byte()) << 24;
+ if (stamp != 0 && !no_time)
+ {
+ time_stamp.tv_sec = stamp;
+ time_stamp.tv_nsec = 0;
+ }
+
+ (void)get_byte(); /* Ignore extra flags for the moment */
+ (void)get_byte(); /* Ignore OS type for the moment */
+
+ if ((flags & CONTINUATION) != 0) {
+ unsigned part = (unsigned)get_byte();
+ part |= ((unsigned)get_byte())<<8;
+ if (verbose) {
+ fprintf(stderr,"%s: %s: part number %u\n",
+ program_name, ifname, part);
+ }
+ }
+ if ((flags & EXTRA_FIELD) != 0) {
+ unsigned len = (unsigned)get_byte();
+ len |= ((unsigned)get_byte())<<8;
+ if (verbose) {
+ fprintf(stderr,"%s: %s: extra field of %u bytes ignored\n",
+ program_name, ifname, len);
+ }
+ while (len--) (void)get_byte();
+ }
+
+ /* Get original file name if it was truncated */
+ if ((flags & ORIG_NAME) != 0) {
+ if (no_name || (to_stdout && !list) || part_nb > 1) {
+ /* Discard the old name */
+ char c; /* dummy used for NeXTstep 3.0 cc optimizer bug */
+ do {c=get_byte();} while (c != 0);
+ } else {
+ /* Copy the base name. Keep a directory prefix intact. */
char *p = gzip_base_name (ofname);
char *base = p;
- for (;;) {
- *p = (char)get_char();
- if (*p++ == '\0') break;
- if (p >= ofname+sizeof(ofname)) {
- gzip_error ("corrupted input -- file name too large");
- }
- }
- p = gzip_base_name (base);
- memmove (base, p, strlen (p) + 1);
+ for (;;) {
+ *p = (char)get_char();
+ if (*p++ == '\0') break;
+ if (p >= ofname+sizeof(ofname)) {
+ gzip_error ("corrupted input -- file name too large");
+ }
+ }
+ p = gzip_base_name (base);
+ memmove (base, p, strlen (p) + 1);
/* If necessary, adapt the name to local OS conventions: */
if (!list) {
MAKE_LEGAL_NAME(base);
- if (base) list=0; /* avoid warning about unused variable */
+ if (base) list=0; /* avoid warning about unused variable */
}
- } /* no_name || to_stdout */
- } /* ORIG_NAME */
+ } /* no_name || to_stdout */
+ } /* ORIG_NAME */
- /* Discard file comment if any */
- if ((flags & COMMENT) != 0) {
- while (get_char() != 0) /* null */ ;
- }
- if (part_nb == 1) {
- header_bytes = inptr + 2*sizeof(long); /* include crc and size */
- }
+ /* Discard file comment if any */
+ if ((flags & COMMENT) != 0) {
+ while (get_char() != 0) /* null */ ;
+ }
+ if (part_nb == 1) {
+ header_bytes = inptr + 2*sizeof(long); /* include crc and size */
+ }
} else if (memcmp(magic, PKZIP_MAGIC, 2) == 0 && inptr == 2
- && memcmp((char*)inbuf, PKZIP_MAGIC, 4) == 0) {
- /* To simplify the code, we support a zip file when alone only.
+ && memcmp((char*)inbuf, PKZIP_MAGIC, 4) == 0) {
+ /* To simplify the code, we support a zip file when alone only.
* We are thus guaranteed that the entire local header fits in inbuf.
*/
inptr = 0;
- work = unzip;
- if (check_zipfile(in) != OK) return -1;
- /* check_zipfile may get ofname from the local header */
- last_member = 1;
+ work = unzip;
+ if (check_zipfile(in) != OK) return -1;
+ /* check_zipfile may get ofname from the local header */
+ last_member = 1;
} else if (memcmp(magic, PACK_MAGIC, 2) == 0) {
- work = unpack;
- method = PACKED;
+ work = unpack;
+ method = PACKED;
} else if (memcmp(magic, LZW_MAGIC, 2) == 0) {
- work = unlzw;
- method = COMPRESSED;
- last_member = 1;
+ work = unlzw;
+ method = COMPRESSED;
+ last_member = 1;
} else if (memcmp(magic, LZH_MAGIC, 2) == 0) {
- work = unlzh;
- method = LZHED;
- last_member = 1;
+ work = unlzh;
+ method = LZHED;
+ last_member = 1;
} else if (force && to_stdout && !list) { /* pass input unchanged */
- method = STORED;
- work = copy;
+ method = STORED;
+ work = copy;
inptr = 0;
- last_member = 1;
+ last_member = 1;
}
if (method >= 0) return method;
if (part_nb == 1) {
- fprintf (stderr, "\n%s: %s: not in gzip format\n",
- program_name, ifname);
- exit_code = ERROR;
- return -1;
+ fprintf (stderr, "\n%s: %s: not in gzip format\n",
+ program_name, ifname);
+ exit_code = ERROR;
+ return -1;
} else {
- if (magic[0] == 0)
- {
- int inbyte;
- for (inbyte = imagic1; inbyte == 0; inbyte = try_byte ())
- continue;
- if (inbyte == EOF)
- {
- if (verbose)
- WARN ((stderr, "\n%s: %s: decompression OK, trailing zero bytes ignored\n",
- program_name, ifname));
- return -3;
- }
- }
-
- WARN((stderr, "\n%s: %s: decompression OK, trailing garbage ignored\n",
- program_name, ifname));
- return -2;
+ if (magic[0] == 0)
+ {
+ int inbyte;
+ for (inbyte = imagic1; inbyte == 0; inbyte = try_byte ())
+ continue;
+ if (inbyte == EOF)
+ {
+ if (verbose)
+ WARN ((stderr, "\n%s: %s: decompression OK, trailing zero bytes ignored\n",
+ program_name, ifname));
+ return -3;
+ }
+ }
+
+ WARN((stderr, "\n%s: %s: decompression OK, trailing garbage ignored\n",
+ program_name, ifname));
+ return -2;
}
}
off_t o;
for (o = OFF_T_MAX; 9 < o; o /= 10) {
- positive_off_t_width++;
+ positive_off_t_width++;
}
if (first_time && method >= 0) {
- first_time = 0;
- if (verbose) {
- printf("method crc date time ");
- }
- if (!quiet) {
- printf("%*.*s %*.*s ratio uncompressed_name\n",
- positive_off_t_width, positive_off_t_width, "compressed",
- positive_off_t_width, positive_off_t_width, "uncompressed");
- }
+ first_time = 0;
+ if (verbose) {
+ printf("method crc date time ");
+ }
+ if (!quiet) {
+ printf("%*.*s %*.*s ratio uncompressed_name\n",
+ positive_off_t_width, positive_off_t_width, "compressed",
+ positive_off_t_width, positive_off_t_width, "uncompressed");
+ }
} else if (method < 0) {
- if (total_in <= 0 || total_out <= 0) return;
- if (verbose) {
- printf(" ");
- }
- if (verbose || !quiet) {
- fprint_off(stdout, total_in, positive_off_t_width);
- printf(" ");
- fprint_off(stdout, total_out, positive_off_t_width);
- printf(" ");
- }
- display_ratio(total_out-(total_in-header_bytes), total_out, stdout);
- /* header_bytes is not meaningful but used to ensure the same
- * ratio if there is a single file.
- */
- printf(" (totals)\n");
- return;
+ if (total_in <= 0 || total_out <= 0) return;
+ if (verbose) {
+ printf(" ");
+ }
+ if (verbose || !quiet) {
+ fprint_off(stdout, total_in, positive_off_t_width);
+ printf(" ");
+ fprint_off(stdout, total_out, positive_off_t_width);
+ printf(" ");
+ }
+ display_ratio(total_out-(total_in-header_bytes), total_out, stdout);
+ /* header_bytes is not meaningful but used to ensure the same
+ * ratio if there is a single file.
+ */
+ printf(" (totals)\n");
+ return;
}
crc = (ulg)~0; /* unknown */
bytes_out = -1L;
read_error();
}
crc = LG(buf);
- bytes_out = LG(buf+4);
- }
+ bytes_out = LG(buf+4);
+ }
}
#endif /* RECORD_IO */
if (verbose)
{
- struct tm *tm = localtime (&time_stamp.tv_sec);
- printf ("%5s %08lx ", methods[method], crc);
- if (tm)
- printf ("%s%3d %02d:%02d ",
- ("Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0Sep\0Oct\0Nov\0Dec"
- + 4 * tm->tm_mon),
- tm->tm_mday, tm->tm_hour, tm->tm_min);
- else
- printf ("??? ?? ??:?? ");
+ struct tm *tm = localtime (&time_stamp.tv_sec);
+ printf ("%5s %08lx ", methods[method], crc);
+ if (tm)
+ printf ("%s%3d %02d:%02d ",
+ ("Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0Sep\0Oct\0Nov\0Dec"
+ + 4 * tm->tm_mon),
+ tm->tm_mday, tm->tm_hour, tm->tm_min);
+ else
+ printf ("??? ?? ??:?? ");
}
fprint_off(stdout, bytes_in, positive_off_t_width);
printf(" ");
fprint_off(stdout, bytes_out, positive_off_t_width);
printf(" ");
if (bytes_in == -1L) {
- total_in = -1L;
- bytes_in = bytes_out = header_bytes = 0;
+ total_in = -1L;
+ bytes_in = bytes_out = header_bytes = 0;
} else if (total_in >= 0) {
- total_in += bytes_in;
+ total_in += bytes_in;
}
if (bytes_out == -1L) {
- total_out = -1L;
- bytes_in = bytes_out = header_bytes = 0;
+ total_out = -1L;
+ bytes_in = bytes_out = header_bytes = 0;
} else if (total_out >= 0) {
- total_out += bytes_out;
+ total_out += bytes_out;
}
display_ratio(bytes_out-(bytes_in-header_bytes), bytes_out, stdout);
printf(" %s\n", ofname);
len = strlen(name);
if (decompress) {
- if (len <= 1)
- gzip_error ("name too short");
- name[len-1] = '\0';
- return;
+ if (len <= 1)
+ gzip_error ("name too short");
+ name[len-1] = '\0';
+ return;
}
p = get_suffix(name);
if (! p)
/* compress 1234567890.tar to 1234567890.tgz */
if (len > 4 && strequ(p-4, ".tar")) {
- strcpy(p-4, ".tgz");
- return;
+ strcpy(p-4, ".tgz");
+ return;
}
/* Try keeping short extensions intact:
* 1234.678.012.gz -> 123.678.012.gz
*/
do {
- p = strrchr(name, PATH_SEP);
- p = p ? p+1 : name;
- while (*p) {
- plen = strcspn(p, PART_SEP);
- p += plen;
- if (plen > min_part) trunc = p-1;
- if (*p) p++;
- }
+ p = strrchr(name, PATH_SEP);
+ p = p ? p+1 : name;
+ while (*p) {
+ plen = strcspn(p, PART_SEP);
+ p += plen;
+ if (plen > min_part) trunc = p-1;
+ if (*p) p++;
+ }
} while (trunc == NULL && --min_part != 0);
if (trunc != NULL) {
- do {
- trunc[0] = trunc[1];
- } while (*trunc++);
- trunc--;
+ do {
+ trunc[0] = trunc[1];
+ } while (*trunc++);
+ trunc--;
} else {
- trunc = strrchr(name, PART_SEP[0]);
- if (!trunc)
- gzip_error ("internal error in shorten_name");
- if (trunc[1] == '\0') trunc--; /* force truncation */
+ trunc = strrchr(name, PART_SEP[0]);
+ if (!trunc)
+ gzip_error ("internal error in shorten_name");
+ if (trunc[1] == '\0') trunc--; /* force truncation */
}
strcpy(trunc, z_suffix);
}
{
/* Ask permission to overwrite the existing file */
if (!force) {
- int ok = 0;
- fprintf (stderr, "%s: %s already exists;", program_name, ofname);
- if (foreground && isatty(fileno(stdin))) {
- fprintf(stderr, " do you wish to overwrite (y or n)? ");
- fflush(stderr);
- ok = yesno();
- }
- if (!ok) {
- fprintf(stderr, "\tnot overwritten\n");
- if (exit_code == OK) exit_code = WARNING;
- return ERROR;
- }
+ int ok = 0;
+ fprintf (stderr, "%s: %s already exists;", program_name, ofname);
+ if (foreground && isatty(fileno(stdin))) {
+ fprintf(stderr, " do you wish to overwrite (y or n)? ");
+ fflush(stderr);
+ ok = yesno();
+ }
+ if (!ok) {
+ fprintf(stderr, "\tnot overwritten\n");
+ if (exit_code == OK) exit_code = WARNING;
+ return ERROR;
+ }
}
if (xunlink (ofname)) {
- progerror(ofname);
- return ERROR;
+ progerror(ofname);
+ return ERROR;
}
return OK;
}
timespec[1] = get_stat_mtime (ifstat);
if (decompress && 0 <= time_stamp.tv_nsec
- && ! (timespec[1].tv_sec == time_stamp.tv_sec
- && timespec[1].tv_nsec == time_stamp.tv_nsec))
+ && ! (timespec[1].tv_sec == time_stamp.tv_sec
+ && timespec[1].tv_nsec == time_stamp.tv_nsec))
{
- timespec[1] = time_stamp;
- if (verbose > 1) {
- fprintf(stderr, "%s: time stamp restored\n", ofname);
- }
+ timespec[1] = time_stamp;
+ if (verbose > 1) {
+ fprintf(stderr, "%s: time stamp restored\n", ofname);
+ }
}
if (gl_futimens (ofd, ofname, timespec) != 0)
{
- int e = errno;
- WARN ((stderr, "%s: ", program_name));
- if (!quiet)
- {
- errno = e;
- perror (ofname);
- }
+ int e = errno;
+ WARN ((stderr, "%s: ", program_name));
+ if (!quiet)
+ {
+ errno = e;
+ perror (ofname);
+ }
}
#endif
r = chmod (ofname, mode);
#endif
if (r != 0) {
- int e = errno;
- WARN ((stderr, "%s: ", program_name));
- if (!quiet) {
- errno = e;
- perror(ofname);
- }
+ int e = errno;
+ WARN ((stderr, "%s: ", program_name));
+ if (!quiet) {
+ errno = e;
+ perror(ofname);
+ }
}
}
dirp = fdopendir (fd);
if (dirp == NULL) {
- progerror(dir);
- close (fd);
- return ;
+ progerror(dir);
+ close (fd);
+ return ;
}
/*
** WARNING: the following algorithm could occasionally cause
while ((errno = 0, dp = readdir(dirp)) != NULL) {
- if (strequ(dp->d_name,".") || strequ(dp->d_name,"..")) {
- continue;
- }
- len = strlen(dir);
- if (len + _D_EXACT_NAMLEN (dp) + 1 < MAX_PATH_LEN - 1) {
- strcpy(nbuf,dir);
- if (len != 0 /* dir = "" means current dir on Amiga */
+ if (strequ(dp->d_name,".") || strequ(dp->d_name,"..")) {
+ continue;
+ }
+ len = strlen(dir);
+ if (len + _D_EXACT_NAMLEN (dp) + 1 < MAX_PATH_LEN - 1) {
+ strcpy(nbuf,dir);
+ if (len != 0 /* dir = "" means current dir on Amiga */
#ifdef PATH_SEP2
- && dir[len-1] != PATH_SEP2
+ && dir[len-1] != PATH_SEP2
#endif
#ifdef PATH_SEP3
- && dir[len-1] != PATH_SEP3
+ && dir[len-1] != PATH_SEP3
#endif
- ) {
- nbuf[len++] = PATH_SEP;
- }
- strcpy(nbuf+len, dp->d_name);
- treat_file(nbuf);
- } else {
- fprintf(stderr,"%s: %s/%s: pathname too long\n",
- program_name, dir, dp->d_name);
- exit_code = ERROR;
- }
+ ) {
+ nbuf[len++] = PATH_SEP;
+ }
+ strcpy(nbuf+len, dp->d_name);
+ treat_file(nbuf);
+ } else {
+ fprintf(stderr,"%s: %s/%s: pathname too long\n",
+ program_name, dir, dp->d_name);
+ exit_code = ERROR;
+ }
}
if (errno != 0)
- progerror(dir);
+ progerror(dir);
if (CLOSEDIR(dirp) != 0)
- progerror(dir);
+ progerror(dir);
}
#endif /* ! NO_DIR */
{
sigaction (handled_sig[i], NULL, &act);
if (act.sa_handler != SIG_IGN)
- sigaddset (&caught_signals, handled_sig[i]);
+ sigaddset (&caught_signals, handled_sig[i]);
}
act.sa_handler = abort_gzip_signal;
for (i = 0; i < nsigs; i++)
if (sigismember (&caught_signals, handled_sig[i]))
{
- if (i == 0)
- foreground = 1;
- sigaction (handled_sig[i], &act, NULL);
+ if (i == 0)
+ foreground = 1;
+ sigaction (handled_sig[i], &act, NULL);
}
#else
for (i = 0; i < nsigs; i++)
if (signal (handled_sig[i], SIG_IGN) != SIG_IGN)
{
- if (i == 0)
- foreground = 1;
- signal (handled_sig[i], abort_gzip_signal);
- siginterrupt (handled_sig[i], 1);
+ if (i == 0)
+ foreground = 1;
+ signal (handled_sig[i], abort_gzip_signal);
+ siginterrupt (handled_sig[i], 1);
}
#endif
}
#endif
#define WARN(msg) {if (!quiet) fprintf msg ; \
- if (exit_code == OK) exit_code = WARNING;}
+ if (exit_code == OK) exit_code = WARNING;}
- /* in zip.c: */
+ /* in zip.c: */
extern int zip OF((int in, int out));
extern int file_read OF((char *buf, unsigned size));
- /* in unzip.c */
+ /* in unzip.c */
extern int unzip OF((int in, int out));
extern int check_zipfile OF((int in));
- /* in unpack.c */
+ /* in unpack.c */
extern int unpack OF((int in, int out));
- /* in unlzh.c */
+ /* in unlzh.c */
extern int unlzh OF((int in, int out));
- /* in gzip.c */
+ /* in gzip.c */
void abort_gzip OF((void)) ATTRIBUTE_NORETURN;
/* in deflate.c */
void copy_block OF((char *buf, unsigned len, int header));
extern int (*read_buf) OF((char *buf, unsigned size));
- /* in util.c: */
+ /* in util.c: */
extern int copy OF((int in, int out));
extern ulg updcrc OF((uch *s, unsigned n));
extern void clear_bufs OF((void));
extern void display_ratio OF((off_t num, off_t den, FILE *file));
extern void fprint_off OF((FILE *, off_t, int));
- /* in inflate.c */
+ /* in inflate.c */
extern int inflate OF((void));
- /* in yesno.c */
+ /* in yesno.c */
extern int yesno OF((void));
p = b; i = n;
do {
Tracecv(*p, (stderr, (n-i >= ' ' && n-i <= '~' ? "%c %d\n" : "0x%x %d\n"),
- n-i, *p));
+ n-i, *p));
c[*p]++; /* assume all entries <= BMAX */
p++; /* Can't combine with above line (Solaris bug) */
} while (--i);
{ /* too few codes for k-w bit table */
f -= a + 1; /* deduct codes from patterns left */
xp = c + k;
- if (j < z)
- while (++j < z) /* try smaller tables up to z bits */
- {
- if ((f <<= 1) <= *++xp)
- break; /* enough codes to use up j bits */
- f -= *xp; /* else deduct codes from patterns */
- }
+ if (j < z)
+ while (++j < z) /* try smaller tables up to z bits */
+ {
+ if ((f <<= 1) <= *++xp)
+ break; /* enough codes to use up j bits */
+ f -= *xp; /* else deduct codes from patterns */
+ }
}
z = 1 << j; /* table entries for j-bit table */
{
r.e = (uch)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
r.v.n = (ush)(*p); /* simple code is just the value */
- p++; /* one compiler does not like *p++ */
+ p++; /* one compiler does not like *p++ */
}
else
{
#endif /* !NOMEMCPY */
do {
slide[w++] = slide[d++];
- Tracevv((stderr, "%c", slide[w-1]));
+ Tracevv((stderr, "%c", slide[w-1]));
} while (--e);
if (w == WSIZE)
{
}
if (tl == NULL) /* Grrrhhh */
- return 2;
+ return 2;
/* read in literal and distance code lengths */
n = nl + nd;
* This version assumes static allocation of the arrays (-DDYN_ALLOC not used).
*/
- .file "match.S"
+ .file "match.S"
#define MAX_MATCH 258
#define MAX_MATCH2 $128 /* MAX_MATCH/2-1 */
#define WSIZE $32768
#define MAX_DIST WSIZE - MAX_MATCH - MIN_MATCH - 1
- .globl _match_init
- .globl _longest_match
+ .globl _match_init
+ .globl _longest_match
- .text
+ .text
_match_init:
- ret
+ ret
/*-----------------------------------------------------------------------
* Set match_start to the longest match starting at the given string and
/* return address */ /* esp+16 */
push %ebp /* esp+12 */
push %edi /* esp+8 */
- push %esi /* esp+4 */
- push %ebx /* esp */
+ push %esi /* esp+4 */
+ push %ebx /* esp */
/*
* match equ esi
* best_len equ ebx
* limit equ edx
*/
- mov cur_match,%esi
+ mov cur_match,%esi
mov _max_chain_length,%ebp /* chain_length = max_chain_length */
- mov _strstart,%edi
- mov %edi,%edx
- sub MAX_DIST,%edx /* limit = strstart-MAX_DIST */
- jae limit_ok
- sub %edx,%edx /* limit = NIL */
+ mov _strstart,%edi
+ mov %edi,%edx
+ sub MAX_DIST,%edx /* limit = strstart-MAX_DIST */
+ jae limit_ok
+ sub %edx,%edx /* limit = NIL */
limit_ok:
add $2+_window,%edi /* edi = offset(window+strstart+2) */
mov _prev_length,%ebx /* best_len = prev_length */
movw -3(%ebx,%edi),%ax /* ax = scan[best_len-1..best_len] */
movw -2(%edi),%cx /* cx = scan[0..1] */
- cmp _good_match,%ebx /* do we have a good match already? */
+ cmp _good_match,%ebx /* do we have a good match already? */
jb do_scan
- shr $2,%ebp /* chain_length >>= 2 */
+ shr $2,%ebp /* chain_length >>= 2 */
jmp do_scan
.align 4
subb -2(%esi),%cl /* cl = 0 if first bytes equal */
xchg %edi,%eax /* edi = scan+2, eax = end of scan */
sub %edi,%eax /* eax = len */
- sub %eax,%esi /* esi = cur_match + 2 + offset(window) */
- sub $2+_window,%esi /* esi = cur_match */
+ sub %eax,%esi /* esi = cur_match + 2 + offset(window) */
+ sub $2+_window,%esi /* esi = cur_match */
subb $1,%cl /* set carry if cl == 0 (cannot use DEC) */
adc $0,%eax /* eax = carry ? len+1 : len */
cmp %ebx,%eax /* len > best_len ? */
jl long_loop
the_end:
mov %ebx,%eax /* result = eax = best_len */
- pop %ebx
+ pop %ebx
pop %esi
pop %edi
pop %ebp
#define WSIZE 32768
#define MAX_DIST (WSIZE - MAX_MATCH - MIN_MATCH - 1)
- GLOBAL (_match_init)
- GLOBAL (_longest_match)
+ GLOBAL (_match_init)
+ GLOBAL (_longest_match)
- TEXT
+ TEXT
- FILE ("match.S")
+ FILE ("match.S")
_match_init:
- rts
+ rts
/*-----------------------------------------------------------------------
* Set match_start to the longest match starting at the given string and
#endif
_longest_match:
- movel IndBase(4,Stack_Pointer),Cur_Match
- moveml imm(pushreg),predec(Stack_Pointer)
- movel _max_chain_length,Chain_Length
- movel _prev_length,Best_Len
- movel imm(_prev),Prev_Address
- movel imm(_window+MIN_MATCH),Match_Ini
- movel _strstart,Limit
- movel Match_Ini,Scan_Ini
- addl Limit,Scan_Ini
- subw imm(MAX_DIST),Limit
- bhis L__limit_ok
- clrl Limit
+ movel IndBase(4,Stack_Pointer),Cur_Match
+ moveml imm(pushreg),predec(Stack_Pointer)
+ movel _max_chain_length,Chain_Length
+ movel _prev_length,Best_Len
+ movel imm(_prev),Prev_Address
+ movel imm(_window+MIN_MATCH),Match_Ini
+ movel _strstart,Limit
+ movel Match_Ini,Scan_Ini
+ addl Limit,Scan_Ini
+ subw imm(MAX_DIST),Limit
+ bhis L__limit_ok
+ clrl Limit
L__limit_ok:
- cmpl invert_maybe(_good_match,Best_Len)
- blos L__length_ok
- lsrl imm(2),Chain_Length
+ cmpl invert_maybe(_good_match,Best_Len)
+ blos L__length_ok
+ lsrl imm(2),Chain_Length
L__length_ok:
- subql imm(1),Chain_Length
+ subql imm(1),Chain_Length
#ifdef UNALIGNED_OK
- movew IndBase(-MIN_MATCH,Scan_Ini),Scan_Start
- movew IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
+ movew IndBase(-MIN_MATCH,Scan_Ini),Scan_Start
+ movew IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
#else
- moveb IndBase(-MIN_MATCH,Scan_Ini),Scan_Start
- lslw imm(8),Scan_Start
- moveb IndBase(-MIN_MATCH+1,Scan_Ini),Scan_Start
- moveb IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
- lslw imm(8),Scan_End
- moveb IndBaseNdxw(-MIN_MATCH,Scan_Ini,Best_Len),Scan_End
+ moveb IndBase(-MIN_MATCH,Scan_Ini),Scan_Start
+ lslw imm(8),Scan_Start
+ moveb IndBase(-MIN_MATCH+1,Scan_Ini),Scan_Start
+ moveb IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
+ lslw imm(8),Scan_End
+ moveb IndBaseNdxw(-MIN_MATCH,Scan_Ini,Best_Len),Scan_End
#endif
- bras L__do_scan
+ bras L__do_scan
L__long_loop:
#ifdef UNALIGNED_OK
- movew IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
+ movew IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
#else
- moveb IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
- lslw imm(8),Scan_End
- moveb IndBaseNdxw(-MIN_MATCH,Scan_Ini,Best_Len),Scan_End
+ moveb IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
+ lslw imm(8),Scan_End
+ moveb IndBaseNdxw(-MIN_MATCH,Scan_Ini,Best_Len),Scan_End
#endif
L__short_loop:
- lslw imm(1),Cur_Match
- movew IndBaseNdxl(0,Prev_Address,Cur_Match),Cur_Match
- cmpw invert_maybe(Limit,Cur_Match)
- dbls Chain_Length,L__do_scan
- bras L__return
+ lslw imm(1),Cur_Match
+ movew IndBaseNdxl(0,Prev_Address,Cur_Match),Cur_Match
+ cmpw invert_maybe(Limit,Cur_Match)
+ dbls Chain_Length,L__do_scan
+ bras L__return
L__do_scan:
- movel Match_Ini,Match
- addl Cur_Match,Match
+ movel Match_Ini,Match
+ addl Cur_Match,Match
#ifdef UNALIGNED_OK
- cmpw invert_maybe(IndBaseNdxw(-MIN_MATCH-1,Match,Best_Len),Scan_End)
- bne L__short_loop
- cmpw invert_maybe(IndBase(-MIN_MATCH,Match),Scan_Start)
- bne L__short_loop
+ cmpw invert_maybe(IndBaseNdxw(-MIN_MATCH-1,Match,Best_Len),Scan_End)
+ bne L__short_loop
+ cmpw invert_maybe(IndBase(-MIN_MATCH,Match),Scan_Start)
+ bne L__short_loop
#else
- moveb IndBaseNdxw(-MIN_MATCH-1,Match,Best_Len),Scan_Test
- lslw imm(8),Scan_Test
- moveb IndBaseNdxw(-MIN_MATCH,Match,Best_Len),Scan_Test
- cmpw invert_maybe(Scan_Test,Scan_End)
- bne L__short_loop
- moveb IndBase(-MIN_MATCH,Match),Scan_Test
- lslw imm(8),Scan_Test
- moveb IndBase(-MIN_MATCH+1,Match),Scan_Test
- cmpw invert_maybe(Scan_Test,Scan_Start)
- bne L__short_loop
+ moveb IndBaseNdxw(-MIN_MATCH-1,Match,Best_Len),Scan_Test
+ lslw imm(8),Scan_Test
+ moveb IndBaseNdxw(-MIN_MATCH,Match,Best_Len),Scan_Test
+ cmpw invert_maybe(Scan_Test,Scan_End)
+ bne L__short_loop
+ moveb IndBase(-MIN_MATCH,Match),Scan_Test
+ lslw imm(8),Scan_Test
+ moveb IndBase(-MIN_MATCH+1,Match),Scan_Test
+ cmpw invert_maybe(Scan_Test,Scan_Start)
+ bne L__short_loop
#endif
- movew imm((MAX_MATCH-MIN_MATCH+1)-1),Loop_Counter
- movel Scan_Ini,Scan
+ movew imm((MAX_MATCH-MIN_MATCH+1)-1),Loop_Counter
+ movel Scan_Ini,Scan
L__scan_loop:
- cmpmb postinc(Match),postinc(Scan)
- dbne Loop_Counter,L__scan_loop
-
- subl Scan_Ini,Scan
- addql imm(MIN_MATCH-1),Scan
- cmpl invert_maybe(Best_Len,Scan)
- bls L__short_loop
- movel Scan,Best_Len
- movel Cur_Match,_match_start
- cmpl invert_maybe(_nice_match,Best_Len)
- blos L__long_loop
+ cmpmb postinc(Match),postinc(Scan)
+ dbne Loop_Counter,L__scan_loop
+
+ subl Scan_Ini,Scan
+ addql imm(MIN_MATCH-1),Scan
+ cmpl invert_maybe(Best_Len,Scan)
+ bls L__short_loop
+ movel Scan,Best_Len
+ movel Cur_Match,_match_start
+ cmpl invert_maybe(_nice_match,Best_Len)
+ blos L__long_loop
L__return:
- moveml postinc(Stack_Pointer),imm(popreg)
- rts
+ moveml postinc(Stack_Pointer),imm(popreg)
+ rts
#else
#define cgeu cmp.ge.unc
#define cneu cmp.ne.unc
- .global longest_match
- .proc longest_match
- .align 32
+ .global longest_match
+ .proc longest_match
+ .align 32
longest_match:
// -- Cycle: 0
- .prologue
+ .prologue
{.mmi
- alloc r2=ar.pfs,R_INPUT,R_LOCAL,R_OUTPUT,R_ROTATING
- .rotr scan[MLAT+2], match[MLAT+2], shscan0[SHLAT+1], \
- shscan1[SHLAT+1], shmatch0[SHLAT+1], shmatch1[SHLAT+1]
- .rotp lc[MLAT+SHLAT+2]
- mova s_vspec_cmatch=in0 // cur_match from input register
- add s_tm1=@gprel(strstart),gp // a(a(strstart))
+ alloc r2=ar.pfs,R_INPUT,R_LOCAL,R_OUTPUT,R_ROTATING
+ .rotr scan[MLAT+2], match[MLAT+2], shscan0[SHLAT+1], \
+ shscan1[SHLAT+1], shmatch0[SHLAT+1], shmatch1[SHLAT+1]
+ .rotp lc[MLAT+SHLAT+2]
+ mova s_vspec_cmatch=in0 // cur_match from input register
+ add s_tm1=@gprel(strstart),gp // a(a(strstart))
}{.mmi
- add s_tm3=@gprel(prev_length),gp // a(a(prev_length))
- add s_tm5=@ltoff(window),gp // a(a(window))
- add s_tm6=@ltoff(prev),gp // a(a(prev))
- ;;
+ add s_tm3=@gprel(prev_length),gp // a(a(prev_length))
+ add s_tm5=@ltoff(window),gp // a(a(window))
+ add s_tm6=@ltoff(prev),gp // a(a(prev))
+ ;;
}{.mmb // Cycle: 1
- ld4 s_vstrstart=[s_tm1] // strstart
- ld4 s_vbestlen=[s_tm3] // best_len = prev_length
- brp.loop.imp .cmploop,.cmploop+48
+ ld4 s_vstrstart=[s_tm1] // strstart
+ ld4 s_vbestlen=[s_tm3] // best_len = prev_length
+ brp.loop.imp .cmploop,.cmploop+48
}{.mli
- add s_tm2=@gprel(max_chain_length),gp // a(a(max_chain_length))
- movl s_wmask=WSIZE-1
- ;;
+ add s_tm2=@gprel(max_chain_length),gp // a(a(max_chain_length))
+ movl s_wmask=WSIZE-1
+ ;;
}{.mmi // Cycle: 2
- ld8 s_aprev=[s_tm6] // a(prev)
- ld8 s_awindow=[s_tm5] // a(window)
- .save pr, s_prsave
- movi0 s_prsave=pr // save predicates
+ ld8 s_aprev=[s_tm6] // a(prev)
+ ld8 s_awindow=[s_tm5] // a(window)
+ .save pr, s_prsave
+ movi0 s_prsave=pr // save predicates
}{.mmi
- add s_tm4=@gprel(good_match),gp // a(a(good_match))
- add s_tm7=@ltoff(nice_match),gp // a(a(nice_match))
- add s_tm8=@ltoff(match_start),gp // a(match_start)
- ;;
+ add s_tm4=@gprel(good_match),gp // a(a(good_match))
+ add s_tm7=@ltoff(nice_match),gp // a(a(nice_match))
+ add s_tm8=@ltoff(match_start),gp // a(match_start)
+ ;;
}{.mmi // Cycle: 3
- ld8 s_anicematch=[s_tm7] // a(nice_match)
- ld8 s_amatchstart=[s_tm8] // a(match_start)
- .save ar.lc, s_lcsave
- movi0 s_lcsave=ar.lc // save loop count register
+ ld8 s_anicematch=[s_tm7] // a(nice_match)
+ ld8 s_amatchstart=[s_tm8] // a(match_start)
+ .save ar.lc, s_lcsave
+ movi0 s_lcsave=ar.lc // save loop count register
}{.mmi
- .body
- add s_tm1=-(MAX_MATCH + MIN_MATCH),s_wmask // maxdist
- cmp.eq p_ll,p0=r0,r0 // parallel compare initialized as 'true'
- mova s_vcurmatch=s_vspec_cmatch
- ;;
+ .body
+ add s_tm1=-(MAX_MATCH + MIN_MATCH),s_wmask // maxdist
+ cmp.eq p_ll,p0=r0,r0 // parallel compare initialized as 'true'
+ mova s_vcurmatch=s_vspec_cmatch
+ ;;
}{.mmi // Cycle: 4
- ld4 s_vchainlen=[s_tm2] // chain_length=max_chain_length
- ld4 s_tm4=[s_tm4] // v(good_match)
- add s_ascan=s_awindow,s_vstrstart // scan=window + strstart
+ ld4 s_vchainlen=[s_tm2] // chain_length=max_chain_length
+ ld4 s_tm4=[s_tm4] // v(good_match)
+ add s_ascan=s_awindow,s_vstrstart // scan=window + strstart
}{.mmi
- sub s_vlimit=s_vstrstart, s_tm1 // limit=strstart - MAX_DIST
- add s_amatch=s_awindow,s_vspec_cmatch // match=window + cur_match
- and s_vspec_cmatch =s_vspec_cmatch,s_wmask
- ;;
+ sub s_vlimit=s_vstrstart, s_tm1 // limit=strstart - MAX_DIST
+ add s_amatch=s_awindow,s_vspec_cmatch // match=window + cur_match
+ and s_vspec_cmatch =s_vspec_cmatch,s_wmask
+ ;;
}{.mmi // Cycle: 5
- add s_amatblen=s_amatch,s_vbestlen //
- cneu p_bn2,p0=2,s_vbestlen // set if bestlen != 2
- add s_ascanend=s_ascan,s_vbestlen // compute a(scan) + best_len
+ add s_amatblen=s_amatch,s_vbestlen //
+ cneu p_bn2,p0=2,s_vbestlen // set if bestlen != 2
+ add s_ascanend=s_ascan,s_vbestlen // compute a(scan) + best_len
}{.mmi
- ld1 s_vscan0=[s_ascan],1 // NB: s_ascan++
- ld1 s_vmatch0=[s_amatch],1
- cgtu p0,p_no=s_vlimit,r0 // is result positive ?
- ;;
+ ld1 s_vscan0=[s_ascan],1 // NB: s_ascan++
+ ld1 s_vmatch0=[s_amatch],1
+ cgtu p0,p_no=s_vlimit,r0 // is result positive ?
+ ;;
}{.mmi // Cycle: 6
- ld1.nt1 s_vscan1=[s_ascan],2 // NB: s_ascan+3 in total
- ld1.nt1 s_vmatch1=[s_amatch],2
- add s_awinbest=s_awindow,s_vbestlen //
- ;;
+ ld1.nt1 s_vscan1=[s_ascan],2 // NB: s_ascan+3 in total
+ ld1.nt1 s_vmatch1=[s_amatch],2
+ add s_awinbest=s_awindow,s_vbestlen //
+ ;;
}{.mmi // Cycle: 7
- ld1.nt1 s_vscanend=[s_ascanend],-1 // scan_end=scan[best_len]
- ld1.nt1 s_vmatbst=[s_amatblen],-1
+ ld1.nt1 s_vscanend=[s_ascanend],-1 // scan_end=scan[best_len]
+ ld1.nt1 s_vmatbst=[s_amatblen],-1
(p_no) mova s_vlimit=r0
- ;;
+ ;;
}{.mmi // Cycle: 8
(p_bn2) ld1.nt1 s_vscanend1=[s_ascanend],1 // scan_end1=scan[best_len-1]
(p_bn2) ld1.nt1 s_vmatbst1=[s_amatblen]
- shladd s_vspec_cmatch =s_vspec_cmatch,1,s_aprev
+ shladd s_vspec_cmatch =s_vspec_cmatch,1,s_aprev
}{.mmi
- cgeu p_shf,p0=s_vbestlen,s_tm4 // is (prev_length >= good_match) ?
- ;;
+ cgeu p_shf,p0=s_vbestlen,s_tm4 // is (prev_length >= good_match) ?
+ ;;
}{.mmi // Cycle: 9
- ld1.nt1 s_vscan3=[s_ascan]
- ld2.nt1 s_vspec_cmatch=[s_vspec_cmatch]
- mova s_vlen=3
+ ld1.nt1 s_vscan3=[s_ascan]
+ ld2.nt1 s_vspec_cmatch=[s_vspec_cmatch]
+ mova s_vlen=3
}{.mmi
(p_shf) shr.u s_vchainlen=s_vchainlen,2 // (cur_len) >> 2
- ;;
+ ;;
}{.mmi // Cycle: 10
- ld1.nt1 s_vmatch3=[s_amatch]
- // p_ll switched on as soon as we get a mismatch:
- cmp.eq.and p_ll,p0=s_vmatch0,s_vscan0
- cmp.eq.and p_ll,p0=s_vmatbst,s_vscanend
+ ld1.nt1 s_vmatch3=[s_amatch]
+ // p_ll switched on as soon as we get a mismatch:
+ cmp.eq.and p_ll,p0=s_vmatch0,s_vscan0
+ cmp.eq.and p_ll,p0=s_vmatbst,s_vscanend
}{.mib
- cmp.eq.and p_ll,p0=s_vmatch1,s_vscan1
+ cmp.eq.and p_ll,p0=s_vmatch1,s_vscan1
(p_bn2) cmp.eq.and p_ll,p0=s_vmatbst1,s_vscanend1
(p_ll) br.cond.dpnt.many .test_more
- ;;
+ ;;
}
.next_iter:
{.mmi // Cycle 0
- add s_amatch=s_awindow,s_vspec_cmatch // match=window + cur_match
- mov s_vcurmatch=s_vspec_cmatch // current value
- add s_vchainlen=-1,s_vchainlen // --chain_length
+ add s_amatch=s_awindow,s_vspec_cmatch // match=window + cur_match
+ mov s_vcurmatch=s_vspec_cmatch // current value
+ add s_vchainlen=-1,s_vchainlen // --chain_length
}{.mib
- cmp.le.unc p_end,p0=s_vspec_cmatch,s_vlimit
- and s_vspec_cmatch=s_vspec_cmatch,s_wmask
+ cmp.le.unc p_end,p0=s_vspec_cmatch,s_vlimit
+ and s_vspec_cmatch=s_vspec_cmatch,s_wmask
(p_end) br.cond.dptk.many .terminate
- ;;
+ ;;
}{.mmi // Cycle 1
- ld1 s_vmatch0=[s_amatch],1 // load match[0]
- // compute prev[cur_match]:
- shladd s_vspec_cmatch=s_vspec_cmatch,1,s_aprev
- cmp.eq.unc p_end,p0=s_vchainlen,r0
+ ld1 s_vmatch0=[s_amatch],1 // load match[0]
+ // compute prev[cur_match]:
+ shladd s_vspec_cmatch=s_vspec_cmatch,1,s_aprev
+ cmp.eq.unc p_end,p0=s_vchainlen,r0
} {.mib
- nop.m 0
- add s_amatblen=s_awinbest,s_vcurmatch // match=window + cur_match
+ nop.m 0
+ add s_amatblen=s_awinbest,s_vcurmatch // match=window + cur_match
(p_end) br.cond.dptk.many .terminate
- ;;
+ ;;
}{.mmi // Cycle 2 (short)
- ld2.nt1 s_vspec_cmatch=[s_vspec_cmatch] // get next cur_match
- ;;
+ ld2.nt1 s_vspec_cmatch=[s_vspec_cmatch] // get next cur_match
+ ;;
}{.mmi // Cycle 3 (short)
- ld1.nt1 s_vmatbst=[s_amatblen],-1 // load match[best_len]
- cmp.ne.unc p_ll,p0=r0,r0 // parallel compare initialized as 'false'
- ;;
+ ld1.nt1 s_vmatbst=[s_amatblen],-1 // load match[best_len]
+ cmp.ne.unc p_ll,p0=r0,r0 // parallel compare initialized as 'false'
+ ;;
}{.mmi // Cycle 4 (short)
- // load match[1] - - note: match += 3 (in total):
- ld1.nt1 s_vmatch1=[s_amatch],2
- ;;
- // Cycle 5 (short)
+ // load match[1] - - note: match += 3 (in total):
+ ld1.nt1 s_vmatch1=[s_amatch],2
+ ;;
+ // Cycle 5 (short)
(p_bn2) ld1.nt1 s_vmatbst1=[s_amatblen] // load match[best_len-1]
}{.mib // Here we (MOST LIKELY) pay a L2-fetch stall
- // p_ll switched on as soon as we get a mismatch:
- cmp.ne.or p_ll,p0=s_vmatch0,s_vscan0
- cmp.ne.or p_ll,p0=s_vmatbst,s_vscanend
+ // p_ll switched on as soon as we get a mismatch:
+ cmp.ne.or p_ll,p0=s_vmatch0,s_vscan0
+ cmp.ne.or p_ll,p0=s_vmatbst,s_vscanend
(p_ll) br.cond.dptk.many .next_iter
- ;;
+ ;;
}{.mmi // Cycle 6
- ld1.nt1 s_vmatch3=[s_amatch]
- mova s_vlen=3
- nop.i 0
+ ld1.nt1 s_vmatch3=[s_amatch]
+ mova s_vlen=3
+ nop.i 0
}{.mib
- cmp.ne.or p_ll,p0=s_vmatch1,s_vscan1
+ cmp.ne.or p_ll,p0=s_vmatch1,s_vscan1
(p_bn2) cmp.ne.or p_ll,p0=s_vmatbst1,s_vscanend1
(p_ll) br.cond.dptk.many .next_iter
- ;;
+ ;;
}
// We have passed the first hurdle - Are there additional matches ???
.test_more:
{.mmi // Cycle 0
- and s_tm3=7,s_ascan // get byte offset
- and s_tm4=7,s_amatch // get byte offset
- movi0 ar.ec=MLAT+SHLAT+2 // NB: One trip more than usual
+ and s_tm3=7,s_ascan // get byte offset
+ and s_tm4=7,s_amatch // get byte offset
+ movi0 ar.ec=MLAT+SHLAT+2 // NB: One trip more than usual
}{.mib
- cmp.ne.unc p_no,p0=s_vscan3,s_vmatch3 // does not next one differ?
+ cmp.ne.unc p_no,p0=s_vscan3,s_vmatch3 // does not next one differ?
(p_no) br.cond.dptk.many .only3
- ;;
+ ;;
}{.mmi // Cycle 1
- and s_tm1=-8,s_ascan // get aligned address
- shladd s_tm3=s_tm3,3,r0
- movi0 ar.lc=31 // 32 times around the loop (8B at a time)
+ and s_tm1=-8,s_ascan // get aligned address
+ shladd s_tm3=s_tm3,3,r0
+ movi0 ar.lc=31 // 32 times around the loop (8B at a time)
}{.mib
- and s_tm2=-8,s_amatch // get aligned address
- shladd s_tm4=s_tm4,3,r0
- nop.b 0
- ;;
+ and s_tm2=-8,s_amatch // get aligned address
+ shladd s_tm4=s_tm4,3,r0
+ nop.b 0
+ ;;
}{.mmi // Cycle 2
- ld8.nt1 scan[1]=[s_tm1],8 // load first chunk
- sub s_tm5=64,s_tm3 // 64 - amount
- movi0 pr.rot=1<<16
+ ld8.nt1 scan[1]=[s_tm1],8 // load first chunk
+ sub s_tm5=64,s_tm3 // 64 - amount
+ movi0 pr.rot=1<<16
}{.mmi
- ld8.nt1 match[1]=[s_tm2],8 // load first chunk
- sub s_tm6=64,s_tm4 // 64 - amount
- add s_vlen=-8,s_vlen // will be updated at least once
- ;;
+ ld8.nt1 match[1]=[s_tm2],8 // load first chunk
+ sub s_tm6=64,s_tm4 // 64 - amount
+ add s_vlen=-8,s_vlen // will be updated at least once
+ ;;
}
- .align 32
+ .align 32
.cmploop:
{.mmi // Cycle 0
(lc[0]) ld8 scan[0]=[s_tm1],8 // next scan chunk
(lc[MLAT+SHLAT+1]) cmp.ne.unc p_no,p0=s_tm7,s_tm8 // break search if !=
(lc[MLAT]) first shmatch0[0]=match[MLAT+1],s_tm4
(p_no) br.cond.dpnt.many .mismatch
- ;;
+ ;;
}{.mii // Cycle 1
(lc[0]) ld8 match[0]=[s_tm2],8
- // shift left(le) or right(be):
+ // shift left(le) or right(be):
(lc[MLAT]) second shscan1[0]=scan[MLAT],s_tm5
(lc[MLAT]) second shmatch1[0]=match[MLAT],s_tm6
}{.mmb
(lc[MLAT+SHLAT]) or s_tm7=shscan0[SHLAT],shscan1[SHLAT]
(lc[MLAT+SHLAT]) or s_tm8=shmatch0[SHLAT],shmatch1[SHLAT]
- br.ctop.dptk.many .cmploop
- ;;
+ br.ctop.dptk.many .cmploop
+ ;;
}{.mfi
- mov s_vlen=258
- nop.f 0
+ mov s_vlen=258
+ nop.f 0
}{.mfi
- nop.f 0 // realign
- ;;
+ nop.f 0 // realign
+ ;;
}
.mismatch:
{.mii // Cycle 0 (short)
(p_no) pcmp1.eq s_tm2=s_tm7,s_tm8 // find first non-matching character
- nop.i 0
- ;;
- // Cycle 1 (short)
+ nop.i 0
+ ;;
+ // Cycle 1 (short)
(p_no) count s_tm1=s_tm2
- ;;
+ ;;
}{.mib // Cycle 2 (short)
(p_no) add s_vlen=s_vlen,s_tm1 // effective length
- nop.i 0
- clrrrb
- ;;
+ nop.i 0
+ clrrrb
+ ;;
}
.only3:
{.mib // Cycle 0 (short)
- cmp.gt.unc p0,p_nbs=s_vlen,s_vbestlen // (len > best_len) ?
+ cmp.gt.unc p0,p_nbs=s_vlen,s_vbestlen // (len > best_len) ?
(p_nbs) br.cond.dpnt.many .next_iter // if not, re-iternate
- ;;
+ ;;
}{.mmi // Cycle 1 (short)
- ld4 s_tm7=[s_anicematch] // nice_match
- st4 [s_amatchstart]= s_vcurmatch
- add s_ascanend=s_ascan,s_vlen // reset with best_len
- ;;
+ ld4 s_tm7=[s_anicematch] // nice_match
+ st4 [s_amatchstart]= s_vcurmatch
+ add s_ascanend=s_ascan,s_vlen // reset with best_len
+ ;;
}{.mmi // Cycle 2 (short)
- mova s_vbestlen=s_vlen
- add s_ascanend=-3,s_ascanend // remember extra offset
- ;;
+ mova s_vbestlen=s_vlen
+ add s_ascanend=-3,s_ascanend // remember extra offset
+ ;;
}{.mmi // Cycle 3 (short)
- ld1 s_vscanend=[s_ascanend],-1 // scan_end=scan[best_len]
- add s_awinbest=s_awindow,s_vbestlen // update with new best_len
- cmp.ne.unc p_bn2,p0=2,s_vbestlen // set if bestlen != 2
- ;;
+ ld1 s_vscanend=[s_ascanend],-1 // scan_end=scan[best_len]
+ add s_awinbest=s_awindow,s_vbestlen // update with new best_len
+ cmp.ne.unc p_bn2,p0=2,s_vbestlen // set if bestlen != 2
+ ;;
}{.mib // Cycle 4 (short)
- // scan_end1=scan[best_len-1] NB: s_ascanend reset:
- ld1.nt1 s_vscanend1=[s_ascanend],1
- cmp.lt.unc p_nnc,p0=s_vlen,s_tm7 // compare with nice_match
+ // scan_end1=scan[best_len-1] NB: s_ascanend reset:
+ ld1.nt1 s_vscanend1=[s_ascanend],1
+ cmp.lt.unc p_nnc,p0=s_vlen,s_tm7 // compare with nice_match
(p_nnc) br.cond.dptk.many .next_iter
- ;;
+ ;;
}
.terminate:
{.mii // Cycle 0/1
- nop.m 0
- movi0 ar.lc=s_lcsave
- movi0 pr=s_prsave,-1
+ nop.m 0
+ movi0 ar.lc=s_lcsave
+ movi0 pr=s_prsave,-1
}{.mbb
- nop.m 0
- nop.b 0
- br.ret.sptk.many rp // ret0 is identical to best_len
- ;;
+ nop.m 0
+ nop.b 0
+ br.ret.sptk.many rp // ret0 is identical to best_len
+ ;;
}
- .endp
+ .endp
- .global match_init
- .proc match_init
+ .global match_init
+ .proc match_init
match_init:
- sub ret0=ret0,ret0
- br.ret.sptk.many rp
- .endp
+ sub ret0=ret0,ret0
+ br.ret.sptk.many rp
+ .endp
# else
error: this asm version is for 386 or 680x0 or ia64 only
[AC_MSG_CHECKING([for a POSIX-compliant shell])
AC_CACHE_VAL(ac_cv_path_shell,
[ac_command='
- # Test the noclobber option, using the portable POSIX.2 syntax.
- set -C
- rm -f conftest.c
- >conftest.c || exit
- >|conftest.c || exit
- !>conftest.c || exit
- # Test that $(...) works.
- test "$(expr 3 + 4)" -eq 7 || exit
+ # Test the noclobber option, using the portable POSIX.2 syntax.
+ set -C
+ rm -f conftest.c
+ >conftest.c || exit
+ >|conftest.c || exit
+ !>conftest.c || exit
+ # Test that $(...) works.
+ test "$(expr 3 + 4)" -eq 7 || exit
'
ac_cv_path_shell=no
case $SHELL in
(/*)
- rm -f conftest.c
- if ("$SHELL" -c "$ac_command") 2>/dev/null; then
- ac_cv_path_shell=$SHELL
- fi
+ rm -f conftest.c
+ if ("$SHELL" -c "$ac_command") 2>/dev/null; then
+ ac_cv_path_shell=$SHELL
+ fi
esac
case $ac_cv_path_shell in
(no)
- # Prefer shells that are more likely to be installed in the
- # same place on all hosts of this platform. Therefore, prefer
- # shells in /bin and /usr/bin to shells in the installer's
- # PATH. Also, loop through PATH first and then through
- # shells, since less-"nice" shells in /bin and /usr/bin are
- # more likely to be installed than "nicer" shells elsewhere.
- as_save_IFS=$IFS; IFS=:
- for as_dir in /bin /usr/bin $PATH
- do
- IFS=$as_save_IFS
- case $as_dir in
- (/*)
- for ac_base in sh bash ksh sh5; do
- rm -f conftest.c
- if ("$as_dir/$ac_base" -c "$ac_command") 2>/dev/null; then
- ac_cv_path_shell=$as_dir/$ac_base
- break
- fi
- done
- case $ac_cv_path_shell in
- (/*) break
- esac
- esac
- done
- rm -f conftest.c
+ # Prefer shells that are more likely to be installed in the
+ # same place on all hosts of this platform. Therefore, prefer
+ # shells in /bin and /usr/bin to shells in the installer's
+ # PATH. Also, loop through PATH first and then through
+ # shells, since less-"nice" shells in /bin and /usr/bin are
+ # more likely to be installed than "nicer" shells elsewhere.
+ as_save_IFS=$IFS; IFS=:
+ for as_dir in /bin /usr/bin $PATH
+ do
+ IFS=$as_save_IFS
+ case $as_dir in
+ (/*)
+ for ac_base in sh bash ksh sh5; do
+ rm -f conftest.c
+ if ("$as_dir/$ac_base" -c "$ac_command") 2>/dev/null; then
+ ac_cv_path_shell=$as_dir/$ac_base
+ break
+ fi
+ done
+ case $ac_cv_path_shell in
+ (/*) break
+ esac
+ esac
+ done
+ rm -f conftest.c
esac])
AC_MSG_RESULT($ac_cv_path_shell)
SHELL=$ac_cv_path_shell
prev equ 0 ; offset forced to zero
window equ 0
window_seg equ _window[2]
- window_off equ 0
+ window_off equ 0
else
- wseg dw seg _window
+ wseg dw seg _window
window_seg equ wseg
- window_off equ offset _window
+ window_off equ offset _window
endif
_DATA ends
_TEXT segment word public 'CODE'
assume cs: _TEXT, ds: DGROUP
- public _match_init
+ public _match_init
public _longest_match
- MIN_MATCH equ 3
+ MIN_MATCH equ 3
MAX_MATCH equ 258
- WSIZE equ 32768 ; keep in sync with zip.h !
- MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1)
- MAX_DIST equ (WSIZE-MIN_LOOKAHEAD)
+ WSIZE equ 32768 ; keep in sync with zip.h !
+ MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1)
+ MAX_DIST equ (WSIZE-MIN_LOOKAHEAD)
prev_ptr dw seg _prev ; pointer to the prev array
ifdef SS_NEQ_DS
ifdef SS_NEQ_DS
ma_start equ cs:match_start ; does not work on OS/2
nice equ cs:nice_match
- mov ax,_nice_match
- mov cs:nice_match,ax ; ugly write to code, crash on OS/2
+ mov ax,_nice_match
+ mov cs:nice_match,ax ; ugly write to code, crash on OS/2
else
- assume ss: DGROUP
+ assume ss: DGROUP
ma_start equ ss:_match_start
nice equ ss:_nice_match
mov ax,ds
jne error
endif
ifdef DYN_ALLOC
- cmp _prev[0],0 ; verify zero offset
- jne error
- cmp _window[0],0
- jne error
+ cmp _prev[0],0 ; verify zero offset
+ jne error
+ cmp _window[0],0
+ jne error
ifdef SS_NEQ_DS
- mov ax,_prev[2] ; segment value
- mov cs:prev_ptr,ax ; ugly write to code, crash on OS/2
+ mov ax,_prev[2] ; segment value
+ mov cs:prev_ptr,ax ; ugly write to code, crash on OS/2
prev_seg equ cs:prev_ptr
else
prev_seg equ ss:_prev[2] ; works on OS/2 if SS == DS
else
prev_seg equ cs:prev_ptr
endif
- ret
+ ret
ifdef __LARGE__
- extrn _exit : far ; 'far' for large model
+ extrn _exit : far ; 'far' for large model
else
- extrn _exit : near ; 'near' for compact model
+ extrn _exit : near ; 'near' for compact model
endif
error: call _exit
push bp
mov bp,sp
push di
- push si
- push ds
+ push si
+ push ds
ifdef __LARGE__
cur_match equ word ptr [bp+6] ; [bp+6] for large model
; best_len equ bx
; limit equ dx
- mov si,cur_match ; use bp before it is destroyed
+ mov si,cur_match ; use bp before it is destroyed
mov bp,_max_chain_length ; chain_length = max_chain_length
- mov di,_strstart
- mov dx,di
- sub dx,MAX_DIST ; limit = strstart-MAX_DIST
- jae limit_ok
- sub dx,dx ; limit = NIL
+ mov di,_strstart
+ mov dx,di
+ sub dx,MAX_DIST ; limit = strstart-MAX_DIST
+ jae limit_ok
+ sub dx,dx ; limit = NIL
limit_ok:
add di,2+window_off ; di = offset(window + strstart + 2)
mov bx,_prev_length ; best_len = prev_length
- mov es,window_seg
+ mov es,window_seg
mov ax,es:[bx+di-3] ; ax = scan[best_len-1..best_len]
mov cx,es:[di-2] ; cx = scan[0..1]
- cmp bx,_good_match ; do we have a good match already?
+ cmp bx,_good_match ; do we have a good match already?
mov ds,prev_seg ; (does not destroy the flags)
assume ds: nothing
jb do_scan ; good match?
- shr bp,1 ; chain_length >>= 2
- shr bp,1
+ shr bp,1 ; chain_length >>= 2
+ shr bp,1
jmp short do_scan
even ; align destination of branch
sub cl,[si-2] ; cl = 0 if first bytes equal
xchg ax,di ; di = scan+2, ax = end of scan
sub ax,di ; ax = len
- sub si,ax ; si = cur_match + 2 + offset(window)
- sub si,2+window_off ; si = cur_match
+ sub si,ax ; si = cur_match + 2 + offset(window)
+ sub si,2+window_off ; si = cur_match
sub cl,1 ; set carry if cl == 0 (can't use DEC)
adc ax,0 ; ax = carry ? len+1 : len
cmp ax,bx ; len > best_len ?
cmp ax,nice ; len >= nice_match ?
jl long_loop
the_end:
- pop ds
+ pop ds
assume ds: DGROUP
ifdef SS_NEQ_DS
- mov ax,ma_start ; garbage if no match found
- mov ds:_match_start,ax
+ mov ax,ma_start ; garbage if no match found
+ mov ds:_match_start,ax
endif
pop si
pop di
if (buf == NULL) return NULL;
/* Normalize the pointer to seg:0 */
if (ptr_offset == 0) {
- ptr_offset = (ush)((uch*)buf-0);
+ ptr_offset = (ush)((uch*)buf-0);
} else if (ptr_offset != (ush)((uch*)buf-0)) {
- error("inconsistent ptr_offset");
+ error("inconsistent ptr_offset");
}
*((ush*)&buf+1) += (ptr_offset + 15) >> 4;
*(ush*)&buf = 0;
struct stat {
/* First some PRIMOS standard entries */
- off_t st_size;
- time_t st_mtime;
- short st_type; /* Primos file type */
- short st_rwlock; /* Primos read/write lock */
+ off_t st_size;
+ time_t st_mtime;
+ short st_type; /* Primos file type */
+ short st_rwlock; /* Primos read/write lock */
- /* Begin Unix compatibility - don't believe these entries! */
- dev_t st_dev;
- ino_t st_ino;
- mode_t st_mode;
- short st_nlink;
- uid_t st_uid;
- gid_t st_gid;
- dev_t st_rdev;
- time_t st_atime;
- time_t st_ctime;
- long st_blksize;
- long st_blocks;
+ /* Begin Unix compatibility - don't believe these entries! */
+ dev_t st_dev;
+ ino_t st_ino;
+ mode_t st_mode;
+ short st_nlink;
+ uid_t st_uid;
+ gid_t st_gid;
+ dev_t st_rdev;
+ time_t st_atime;
+ time_t st_ctime;
+ long st_blksize;
+ long st_blocks;
};
#define _IFMT 0170000 /* type of file */
int n;
if (argc < 1 || argc > 2) {
- fprintf(stderr, "usage: %s [file[.gz]]\n", argv[0]);
- exit(EXIT_FAILURE);
+ fprintf(stderr, "usage: %s [file[.gz]]\n", argv[0]);
+ exit(EXIT_FAILURE);
}
strcpy(cmd, "gzip -dc "); /* use "gzip -c" for zwrite */
if (argc == 2) {
- strncat(cmd, argv[1], sizeof(cmd)-strlen(cmd));
+ strncat(cmd, argv[1], sizeof(cmd)-strlen(cmd));
}
infile = popen(cmd, "r"); /* use "w" for zwrite */
if (infile == NULL) {
- fprintf(stderr, "%s: popen('%s', 'r') failed\n", argv[0], cmd);
- exit(EXIT_FAILURE);
+ fprintf(stderr, "%s: popen('%s', 'r') failed\n", argv[0], cmd);
+ exit(EXIT_FAILURE);
}
/* Read one byte using getc: */
n = getc(infile);
if (n == EOF) {
- pclose(infile);
- exit(EXIT_SUCCESS);
+ pclose(infile);
+ exit(EXIT_SUCCESS);
}
putchar(n);
/* Read the rest using fread: */
for (;;) {
- n = fread(buf, 1, BUFSIZ, infile);
- if (n <= 0) break;
- fwrite(buf, 1, n, stdout);
+ n = fread(buf, 1, BUFSIZ, infile);
+ if (n <= 0) break;
+ fwrite(buf, 1, n, stdout);
}
if (pclose(infile) != 0) {
- fprintf(stderr, "%s: pclose failed\n", argv[0]);
- exit(EXIT_FAILURE);
+ fprintf(stderr, "%s: pclose failed\n", argv[0]);
+ exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
return 0; /* just to make compiler happy */
read (FILE, $_, 8);
($magic, $method, $flags, $time) = unpack ("A2C2V", $_);
if ($magic eq "\037\213") {
- utime ($time, $time, $file);
+ utime ($time, $time, $file);
}
else {
- warn "$file is not compressed with gzip!\n";
+ warn "$file is not compressed with gzip!\n";
}
}
#endif
- /* Common defaults */
+ /* Common defaults */
#ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */
if (stored_len <= opt_lenb && eof && compressed_len == 0L && seekable()) {
#endif
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
- if (!buf)
- gzip_error ("block vanished");
+ if (!buf)
+ gzip_error ("block vanished");
copy_block(buf, (unsigned)stored_len, 0); /* without header */
compressed_len = stored_len << 3;
/* maketbl.c */
local void make_table OF((int nchar, uch bitlen[],
- int tablebits, ush table[]));
+ int tablebits, ush table[]));
#define DICBIT 13 /* 12(-lh4-) or 13(-lh5-) */
/* huf.c */
#define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
- /* alphabet = {0, 1, 2, ..., NC - 1} */
+ /* alphabet = {0, 1, 2, ..., NC - 1} */
#define CBIT 9 /* $\lfloor \log_2 NC \rfloor + 1$ */
#define CODE_BIT 16 /* codeword length */
{
bitbuf <<= n;
while (n > bitcount) {
- bitbuf |= subbitbuf << (n -= bitcount);
- subbitbuf = (unsigned)try_byte();
- if ((int)subbitbuf == EOF) subbitbuf = 0;
- bitcount = CHAR_BIT;
+ bitbuf |= subbitbuf << (n -= bitcount);
+ subbitbuf = (unsigned)try_byte();
+ if ((int)subbitbuf == EOF) subbitbuf = 0;
+ bitcount = CHAR_BIT;
}
bitbuf |= subbitbuf >> (bitcount -= n);
}
}
/***********************************************************
- maketbl.c -- make table for decoding
+ maketbl.c -- make table for decoding
***********************************************************/
local void make_table(nchar, bitlen, tablebits, table)
start[1] = 0;
for (i = 1; i <= 16; i++)
- start[i + 1] = start[i] + (count[i] << (16 - i));
+ start[i + 1] = start[i] + (count[i] << (16 - i));
if ((start[17] & 0xffff) != 0)
gzip_error ("Bad table\n");
jutbits = 16 - tablebits;
for (i = 1; i <= (unsigned)tablebits; i++) {
- start[i] >>= jutbits;
- weight[i] = (unsigned) 1 << (tablebits - i);
+ start[i] >>= jutbits;
+ weight[i] = (unsigned) 1 << (tablebits - i);
}
while (i <= 16) {
- weight[i] = (unsigned) 1 << (16 - i);
- i++;
+ weight[i] = (unsigned) 1 << (16 - i);
+ i++;
}
i = start[tablebits + 1] >> jutbits;
if (i != 0) {
- k = 1 << tablebits;
- while (i != k) table[i++] = 0;
+ k = 1 << tablebits;
+ while (i != k) table[i++] = 0;
}
avail = nchar;
mask = (unsigned) 1 << (15 - tablebits);
for (ch = 0; ch < (unsigned)nchar; ch++) {
- if ((len = bitlen[ch]) == 0) continue;
- nextcode = start[len] + weight[len];
- if (len <= (unsigned)tablebits) {
- if ((unsigned) 1 << tablebits < nextcode)
- gzip_error ("Bad table\n");
- for (i = start[len]; i < nextcode; i++) table[i] = ch;
- } else {
- k = start[len];
- p = &table[k >> jutbits];
- i = len - tablebits;
- while (i != 0) {
- if (*p == 0) {
- right[avail] = left[avail] = 0;
- *p = avail++;
- }
- if (k & mask) p = &right[*p];
- else p = &left[*p];
- k <<= 1; i--;
- }
- *p = ch;
- }
- start[len] = nextcode;
+ if ((len = bitlen[ch]) == 0) continue;
+ nextcode = start[len] + weight[len];
+ if (len <= (unsigned)tablebits) {
+ if ((unsigned) 1 << tablebits < nextcode)
+ gzip_error ("Bad table\n");
+ for (i = start[len]; i < nextcode; i++) table[i] = ch;
+ } else {
+ k = start[len];
+ p = &table[k >> jutbits];
+ i = len - tablebits;
+ while (i != 0) {
+ if (*p == 0) {
+ right[avail] = left[avail] = 0;
+ *p = avail++;
+ }
+ if (k & mask) p = &right[*p];
+ else p = &left[*p];
+ k <<= 1; i--;
+ }
+ *p = ch;
+ }
+ start[len] = nextcode;
}
}
n = getbits(nbit);
if (n == 0) {
- c = getbits(nbit);
- for (i = 0; i < nn; i++) pt_len[i] = 0;
- for (i = 0; i < 256; i++) pt_table[i] = c;
+ c = getbits(nbit);
+ for (i = 0; i < nn; i++) pt_len[i] = 0;
+ for (i = 0; i < 256; i++) pt_table[i] = c;
} else {
- i = 0;
- while (i < n) {
- c = bitbuf >> (BITBUFSIZ - 3);
- if (c == 7) {
- mask = (unsigned) 1 << (BITBUFSIZ - 1 - 3);
- while (mask & bitbuf) { mask >>= 1; c++; }
- if (16 < c)
- gzip_error ("Bad table\n");
- }
- fillbuf((c < 7) ? 3 : c - 3);
- pt_len[i++] = c;
- if (i == i_special) {
- c = getbits(2);
- while (--c >= 0) pt_len[i++] = 0;
- }
- }
- while (i < nn) pt_len[i++] = 0;
- make_table(nn, pt_len, 8, pt_table);
+ i = 0;
+ while (i < n) {
+ c = bitbuf >> (BITBUFSIZ - 3);
+ if (c == 7) {
+ mask = (unsigned) 1 << (BITBUFSIZ - 1 - 3);
+ while (mask & bitbuf) { mask >>= 1; c++; }
+ if (16 < c)
+ gzip_error ("Bad table\n");
+ }
+ fillbuf((c < 7) ? 3 : c - 3);
+ pt_len[i++] = c;
+ if (i == i_special) {
+ c = getbits(2);
+ while (--c >= 0) pt_len[i++] = 0;
+ }
+ }
+ while (i < nn) pt_len[i++] = 0;
+ make_table(nn, pt_len, 8, pt_table);
}
}
n = getbits(CBIT);
if (n == 0) {
- c = getbits(CBIT);
- for (i = 0; i < NC; i++) c_len[i] = 0;
- for (i = 0; i < 4096; i++) c_table[i] = c;
+ c = getbits(CBIT);
+ for (i = 0; i < NC; i++) c_len[i] = 0;
+ for (i = 0; i < 4096; i++) c_table[i] = c;
} else {
- i = 0;
- while (i < n) {
- c = pt_table[bitbuf >> (BITBUFSIZ - 8)];
- if (c >= NT) {
- mask = (unsigned) 1 << (BITBUFSIZ - 1 - 8);
- do {
- if (bitbuf & mask) c = right[c];
- else c = left [c];
- mask >>= 1;
- } while (c >= NT);
- }
- fillbuf((int) pt_len[c]);
- if (c <= 2) {
- if (c == 0) c = 1;
- else if (c == 1) c = getbits(4) + 3;
- else c = getbits(CBIT) + 20;
- while (--c >= 0) c_len[i++] = 0;
- } else c_len[i++] = c - 2;
- }
- while (i < NC) c_len[i++] = 0;
- make_table(NC, c_len, 12, c_table);
+ i = 0;
+ while (i < n) {
+ c = pt_table[bitbuf >> (BITBUFSIZ - 8)];
+ if (c >= NT) {
+ mask = (unsigned) 1 << (BITBUFSIZ - 1 - 8);
+ do {
+ if (bitbuf & mask) c = right[c];
+ else c = left [c];
+ mask >>= 1;
+ } while (c >= NT);
+ }
+ fillbuf((int) pt_len[c]);
+ if (c <= 2) {
+ if (c == 0) c = 1;
+ else if (c == 1) c = getbits(4) + 3;
+ else c = getbits(CBIT) + 20;
+ while (--c >= 0) c_len[i++] = 0;
+ } else c_len[i++] = c - 2;
+ }
+ while (i < NC) c_len[i++] = 0;
+ make_table(NC, c_len, 12, c_table);
}
}
unsigned j, mask;
if (blocksize == 0) {
- blocksize = getbits(16);
- if (blocksize == 0) {
- return NC; /* end of file */
- }
- read_pt_len(NT, TBIT, 3);
- read_c_len();
- read_pt_len(NP, PBIT, -1);
+ blocksize = getbits(16);
+ if (blocksize == 0) {
+ return NC; /* end of file */
+ }
+ read_pt_len(NT, TBIT, 3);
+ read_c_len();
+ read_pt_len(NP, PBIT, -1);
}
blocksize--;
j = c_table[bitbuf >> (BITBUFSIZ - 12)];
if (j >= NC) {
- mask = (unsigned) 1 << (BITBUFSIZ - 1 - 12);
- do {
- if (bitbuf & mask) j = right[j];
- else j = left [j];
- mask >>= 1;
- } while (j >= NC);
+ mask = (unsigned) 1 << (BITBUFSIZ - 1 - 12);
+ do {
+ if (bitbuf & mask) j = right[j];
+ else j = left [j];
+ mask >>= 1;
+ } while (j >= NC);
}
fillbuf((int) c_len[j]);
return j;
j = pt_table[bitbuf >> (BITBUFSIZ - 8)];
if (j >= NP) {
- mask = (unsigned) 1 << (BITBUFSIZ - 1 - 8);
- do {
- if (bitbuf & mask) j = right[j];
- else j = left [j];
- mask >>= 1;
- } while (j >= NP);
+ mask = (unsigned) 1 << (BITBUFSIZ - 1 - 8);
+ do {
+ if (bitbuf & mask) j = right[j];
+ else j = left [j];
+ mask >>= 1;
+ } while (j >= NP);
}
fillbuf((int) pt_len[j]);
if (j != 0) j = ((unsigned) 1 << (j - 1)) + getbits((int) (j - 1));
r = 0;
while (--j >= 0) {
- buffer[r] = buffer[i];
- i = (i + 1) & (DICSIZ - 1);
- if (++r == count) return r;
+ buffer[r] = buffer[i];
+ i = (i + 1) & (DICSIZ - 1);
+ if (++r == count) return r;
}
for ( ; ; ) {
- c = decode_c();
- if (c == NC) {
- done = 1;
- return r;
- }
- if (c <= UCHAR_MAX) {
- buffer[r] = c;
- if (++r == count) return r;
- } else {
- j = c - (UCHAR_MAX + 1 - THRESHOLD);
- i = (r - decode_p() - 1) & (DICSIZ - 1);
- while (--j >= 0) {
- buffer[r] = buffer[i];
- i = (i + 1) & (DICSIZ - 1);
- if (++r == count) return r;
- }
- }
+ c = decode_c();
+ if (c == NC) {
+ done = 1;
+ return r;
+ }
+ if (c <= UCHAR_MAX) {
+ buffer[r] = c;
+ if (++r == count) return r;
+ } else {
+ j = c - (UCHAR_MAX + 1 - THRESHOLD);
+ i = (r - decode_p() - 1) & (DICSIZ - 1);
+ while (--j >= 0) {
+ buffer[r] = buffer[i];
+ i = (i + 1) & (DICSIZ - 1);
+ if (++r == count) return r;
+ }
+ }
}
}
decode_start();
while (!done) {
- n = decode((unsigned) DICSIZ, window);
- if (!test && n > 0) {
- write_buf(out, (char*)window, n);
- }
+ n = decode((unsigned) DICSIZ, window);
+ if (!test && n > 0) {
+ write_buf(out, (char*)window, n);
+ }
}
return OK;
}
long word;
struct {
#if BYTEORDER == 4321
- char_type b1;
- char_type b2;
- char_type b3;
- char_type b4;
+ char_type b1;
+ char_type b2;
+ char_type b3;
+ char_type b4;
#else
#if BYTEORDER == 1234
- char_type b4;
- char_type b3;
- char_type b2;
- char_type b1;
+ char_type b4;
+ char_type b3;
+ char_type b2;
+ char_type b1;
#else
# undef BYTEORDER
- int dummy;
+ int dummy;
#endif
#endif
} bytes;
maxbits = get_byte();
block_mode = maxbits & BLOCK_MODE;
if ((maxbits & LZW_RESERVED) != 0) {
- WARN((stderr, "\n%s: %s: warning, unknown flags 0x%x\n",
- program_name, ifname, maxbits & LZW_RESERVED));
+ WARN((stderr, "\n%s: %s: warning, unknown flags 0x%x\n",
+ program_name, ifname, maxbits & LZW_RESERVED));
}
maxbits &= BIT_MASK;
maxmaxcode = MAXCODE(maxbits);
if (maxbits > BITS) {
- fprintf(stderr,
- "\n%s: %s: compressed with %d bits, can only handle %d bits\n",
- program_name, ifname, maxbits, BITS);
- exit_code = ERROR;
- return ERROR;
+ fprintf(stderr,
+ "\n%s: %s: compressed with %d bits, can only handle %d bits\n",
+ program_name, ifname, maxbits, BITS);
+ exit_code = ERROR;
+ return ERROR;
}
rsize = insize;
maxcode = MAXCODE(n_bits = INIT_BITS)-1;
clear_tab_prefixof(); /* Initialize the first 256 entries in the table. */
for (code = 255 ; code >= 0 ; --code) {
- tab_suffixof(code) = (char_type)code;
+ tab_suffixof(code) = (char_type)code;
}
do {
- REG1 int i;
- int e;
- int o;
+ REG1 int i;
+ int e;
+ int o;
resetbuf:
- o = posbits >> 3;
- e = o <= insize ? insize - o : 0;
-
- for (i = 0 ; i < e ; ++i) {
- inbuf[i] = inbuf[i+o];
- }
- insize = e;
- posbits = 0;
-
- if (insize < INBUF_EXTRA) {
- rsize = read_buffer (in, (char *) inbuf + insize, INBUFSIZ);
- if (rsize == -1) {
- read_error();
- }
- insize += rsize;
- bytes_in += (off_t)rsize;
- }
- inbits = ((rsize != 0) ? ((long)insize - insize%n_bits)<<3 :
- ((long)insize<<3)-(n_bits-1));
-
- while (inbits > posbits) {
- if (free_ent > maxcode) {
- posbits = ((posbits-1) +
- ((n_bits<<3)-(posbits-1+(n_bits<<3))%(n_bits<<3)));
- ++n_bits;
- if (n_bits == maxbits) {
- maxcode = maxmaxcode;
- } else {
- maxcode = MAXCODE(n_bits)-1;
- }
- bitmask = (1<<n_bits)-1;
- goto resetbuf;
- }
- input(inbuf,posbits,code,n_bits,bitmask);
- Tracev((stderr, "%d ", code));
-
- if (oldcode == -1) {
- if (256 <= code)
- gzip_error ("corrupt input.");
- outbuf[outpos++] = (char_type)(finchar = (int)(oldcode=code));
- continue;
- }
- if (code == CLEAR && block_mode) {
- clear_tab_prefixof();
- free_ent = FIRST - 1;
- posbits = ((posbits-1) +
- ((n_bits<<3)-(posbits-1+(n_bits<<3))%(n_bits<<3)));
- maxcode = MAXCODE(n_bits = INIT_BITS)-1;
- bitmask = (1<<n_bits)-1;
- goto resetbuf;
- }
- incode = code;
- stackp = de_stack;
-
- if (code >= free_ent) { /* Special case for KwKwK string. */
- if (code > free_ent) {
+ o = posbits >> 3;
+ e = o <= insize ? insize - o : 0;
+
+ for (i = 0 ; i < e ; ++i) {
+ inbuf[i] = inbuf[i+o];
+ }
+ insize = e;
+ posbits = 0;
+
+ if (insize < INBUF_EXTRA) {
+ rsize = read_buffer (in, (char *) inbuf + insize, INBUFSIZ);
+ if (rsize == -1) {
+ read_error();
+ }
+ insize += rsize;
+ bytes_in += (off_t)rsize;
+ }
+ inbits = ((rsize != 0) ? ((long)insize - insize%n_bits)<<3 :
+ ((long)insize<<3)-(n_bits-1));
+
+ while (inbits > posbits) {
+ if (free_ent > maxcode) {
+ posbits = ((posbits-1) +
+ ((n_bits<<3)-(posbits-1+(n_bits<<3))%(n_bits<<3)));
+ ++n_bits;
+ if (n_bits == maxbits) {
+ maxcode = maxmaxcode;
+ } else {
+ maxcode = MAXCODE(n_bits)-1;
+ }
+ bitmask = (1<<n_bits)-1;
+ goto resetbuf;
+ }
+ input(inbuf,posbits,code,n_bits,bitmask);
+ Tracev((stderr, "%d ", code));
+
+ if (oldcode == -1) {
+ if (256 <= code)
+ gzip_error ("corrupt input.");
+ outbuf[outpos++] = (char_type)(finchar = (int)(oldcode=code));
+ continue;
+ }
+ if (code == CLEAR && block_mode) {
+ clear_tab_prefixof();
+ free_ent = FIRST - 1;
+ posbits = ((posbits-1) +
+ ((n_bits<<3)-(posbits-1+(n_bits<<3))%(n_bits<<3)));
+ maxcode = MAXCODE(n_bits = INIT_BITS)-1;
+ bitmask = (1<<n_bits)-1;
+ goto resetbuf;
+ }
+ incode = code;
+ stackp = de_stack;
+
+ if (code >= free_ent) { /* Special case for KwKwK string. */
+ if (code > free_ent) {
#ifdef DEBUG
- char_type *p;
-
- posbits -= n_bits;
- p = &inbuf[posbits>>3];
- fprintf(stderr,
- "code:%ld free_ent:%ld n_bits:%d insize:%u\n",
- code, free_ent, n_bits, insize);
- fprintf(stderr,
- "posbits:%ld inbuf:%02X %02X %02X %02X %02X\n",
- posbits, p[-1],p[0],p[1],p[2],p[3]);
+ char_type *p;
+
+ posbits -= n_bits;
+ p = &inbuf[posbits>>3];
+ fprintf(stderr,
+ "code:%ld free_ent:%ld n_bits:%d insize:%u\n",
+ code, free_ent, n_bits, insize);
+ fprintf(stderr,
+ "posbits:%ld inbuf:%02X %02X %02X %02X %02X\n",
+ posbits, p[-1],p[0],p[1],p[2],p[3]);
#endif
- if (!test && outpos > 0) {
- write_buf(out, (char*)outbuf, outpos);
- bytes_out += (off_t)outpos;
- }
- gzip_error (to_stdout
- ? "corrupt input."
- : "corrupt input. Use zcat to recover some data.");
- }
- *--stackp = (char_type)finchar;
- code = oldcode;
- }
-
- while ((cmp_code_int)code >= (cmp_code_int)256) {
- /* Generate output characters in reverse order */
- *--stackp = tab_suffixof(code);
- code = tab_prefixof(code);
- }
- *--stackp = (char_type)(finchar = tab_suffixof(code));
-
- /* And put them out in forward order */
- {
- REG1 int i;
-
- if (outpos+(i = (de_stack-stackp)) >= OUTBUFSIZ) {
- do {
- if (i > OUTBUFSIZ-outpos) i = OUTBUFSIZ-outpos;
-
- if (i > 0) {
- memcpy(outbuf+outpos, stackp, i);
- outpos += i;
- }
- if (outpos >= OUTBUFSIZ) {
- if (!test) {
- write_buf(out, (char*)outbuf, outpos);
- bytes_out += (off_t)outpos;
- }
- outpos = 0;
- }
- stackp+= i;
- } while ((i = (de_stack-stackp)) > 0);
- } else {
- memcpy(outbuf+outpos, stackp, i);
- outpos += i;
- }
- }
-
- if ((code = free_ent) < maxmaxcode) { /* Generate the new entry. */
-
- tab_prefixof(code) = (unsigned short)oldcode;
- tab_suffixof(code) = (char_type)finchar;
- free_ent = code+1;
- }
- oldcode = incode; /* Remember previous code. */
- }
+ if (!test && outpos > 0) {
+ write_buf(out, (char*)outbuf, outpos);
+ bytes_out += (off_t)outpos;
+ }
+ gzip_error (to_stdout
+ ? "corrupt input."
+ : "corrupt input. Use zcat to recover some data.");
+ }
+ *--stackp = (char_type)finchar;
+ code = oldcode;
+ }
+
+ while ((cmp_code_int)code >= (cmp_code_int)256) {
+ /* Generate output characters in reverse order */
+ *--stackp = tab_suffixof(code);
+ code = tab_prefixof(code);
+ }
+ *--stackp = (char_type)(finchar = tab_suffixof(code));
+
+ /* And put them out in forward order */
+ {
+ REG1 int i;
+
+ if (outpos+(i = (de_stack-stackp)) >= OUTBUFSIZ) {
+ do {
+ if (i > OUTBUFSIZ-outpos) i = OUTBUFSIZ-outpos;
+
+ if (i > 0) {
+ memcpy(outbuf+outpos, stackp, i);
+ outpos += i;
+ }
+ if (outpos >= OUTBUFSIZ) {
+ if (!test) {
+ write_buf(out, (char*)outbuf, outpos);
+ bytes_out += (off_t)outpos;
+ }
+ outpos = 0;
+ }
+ stackp+= i;
+ } while ((i = (de_stack-stackp)) > 0);
+ } else {
+ memcpy(outbuf+outpos, stackp, i);
+ outpos += i;
+ }
+ }
+
+ if ((code = free_ent) < maxmaxcode) { /* Generate the new entry. */
+
+ tab_prefixof(code) = (unsigned short)oldcode;
+ tab_suffixof(code) = (char_type)finchar;
+ free_ent = code+1;
+ }
+ oldcode = incode; /* Remember previous code. */
+ }
} while (rsize != 0);
if (!test && outpos > 0) {
- write_buf(out, (char*)outbuf, outpos);
- bytes_out += (off_t)outpos;
+ write_buf(out, (char*)outbuf, outpos);
+ bytes_out += (off_t)outpos;
}
return OK;
}
max_len = (int)get_byte(); /* maximum bit length of Huffman codes */
if (max_len > MAX_BITLEN) {
- gzip_error ("invalid compressed data -- Huffman code > 32 bits");
+ gzip_error ("invalid compressed data -- Huffman code > 32 bits");
}
/* Get the number of leaves at each bit length */
n = 0;
for (len = 1; len <= max_len; len++) {
- leaves[len] = (int)get_byte();
- if (max_leaves - (len == max_len) < leaves[len])
- gzip_error ("too many leaves in Huffman tree");
- max_leaves = (max_leaves - leaves[len] + 1) * 2 - 1;
- n += leaves[len];
+ leaves[len] = (int)get_byte();
+ if (max_leaves - (len == max_len) < leaves[len])
+ gzip_error ("too many leaves in Huffman tree");
+ max_leaves = (max_leaves - leaves[len] + 1) * 2 - 1;
+ n += leaves[len];
}
if (LITERALS <= n) {
- gzip_error ("too many leaves in Huffman tree");
+ gzip_error ("too many leaves in Huffman tree");
}
Trace((stderr, "orig_len %lu, max_len %d, leaves %d\n",
- orig_len, max_len, n));
+ orig_len, max_len, n));
/* There are at least 2 and at most 256 leaves of length max_len.
* (Pack arbitrarily rejects empty files and files consisting of
* a single byte even repeated.) To fit the last leaf count in a
/* Now read the leaves themselves */
base = 0;
for (len = 1; len <= max_len; len++) {
- /* Remember where the literals of this length start in literal[] : */
- lit_base[len] = base;
- /* And read the literals: */
- for (n = leaves[len]; n > 0; n--) {
- literal[base++] = (uch)get_byte();
- }
+ /* Remember where the literals of this length start in literal[] : */
+ lit_base[len] = base;
+ /* And read the literals: */
+ for (n = leaves[len]; n > 0; n--) {
+ literal[base++] = (uch)get_byte();
+ }
}
leaves[max_len]++; /* Now include the EOB code in the Huffman tree */
}
uch *prefixp; /* pointer in prefix_len */
for (len = max_len; len >= 1; len--) {
- /* The number of parent nodes at this level is half the total
- * number of nodes at parent level:
- */
- nodes >>= 1;
- parents[len] = nodes;
- /* Update lit_base by the appropriate bias to skip the parent nodes
- * (which are not represented in the literal array):
- */
- lit_base[len] -= nodes;
- /* Restore nodes to be parents+leaves: */
- nodes += leaves[len];
+ /* The number of parent nodes at this level is half the total
+ * number of nodes at parent level:
+ */
+ nodes >>= 1;
+ parents[len] = nodes;
+ /* Update lit_base by the appropriate bias to skip the parent nodes
+ * (which are not represented in the literal array):
+ */
+ lit_base[len] -= nodes;
+ /* Restore nodes to be parents+leaves: */
+ nodes += leaves[len];
}
/* Construct the prefix table, from shortest leaves to longest ones.
* The shortest code is all ones, so we start at the end of the table.
peek_bits = MIN(max_len, MAX_PEEK);
prefixp = &prefix_len[1<<peek_bits];
for (len = 1; len <= peek_bits; len++) {
- int prefixes = leaves[len] << (peek_bits-len); /* may be 0 */
- while (prefixes--) *--prefixp = (uch)len;
+ int prefixes = leaves[len] << (peek_bits-len); /* may be 0 */
+ while (prefixes--) *--prefixp = (uch)len;
}
/* The length of all other codes is unknown: */
while (prefixp > prefix_len) *--prefixp = 0;
/* Decode the input data: */
for (;;) {
- /* Since eob is the longest code and not shorter than max_len,
+ /* Since eob is the longest code and not shorter than max_len,
* we can peek at max_len bits without having the risk of reading
* beyond the end of file.
- */
- look_bits(peek, peek_bits, peek_mask);
- len = prefix_len[peek];
- if (len > 0) {
- peek >>= peek_bits - len; /* discard the extra bits */
- } else {
- /* Code of more than peek_bits bits, we must traverse the tree */
- ulg mask = peek_mask;
- len = peek_bits;
- do {
+ */
+ look_bits(peek, peek_bits, peek_mask);
+ len = prefix_len[peek];
+ if (len > 0) {
+ peek >>= peek_bits - len; /* discard the extra bits */
+ } else {
+ /* Code of more than peek_bits bits, we must traverse the tree */
+ ulg mask = peek_mask;
+ len = peek_bits;
+ do {
len++, mask = (mask<<1)+1;
- look_bits(peek, len, mask);
- } while (peek < (unsigned)parents[len]);
- /* loop as long as peek is a parent node */
- }
- /* At this point, peek is the next complete code, of len bits */
- if (peek == eob && len == max_len) break; /* end of file? */
- put_ubyte(literal[peek+lit_base[len]]);
- Tracev((stderr,"%02d %04x %c\n", len, peek,
- literal[peek+lit_base[len]]));
- skip_bits(len);
+ look_bits(peek, len, mask);
+ } while (peek < (unsigned)parents[len]);
+ /* loop as long as peek is a parent node */
+ }
+ /* At this point, peek is the next complete code, of len bits */
+ if (peek == eob && len == max_len) break; /* end of file? */
+ put_ubyte(literal[peek+lit_base[len]]);
+ Tracev((stderr,"%02d %04x %c\n", len, peek,
+ literal[peek+lit_base[len]]));
+ skip_bits(len);
} /* for (;;) */
flush_window();
if (orig_len != (ulg)(bytes_out & 0xffffffff)) {
- gzip_error ("invalid compressed data--length error");
+ gzip_error ("invalid compressed data--length error");
}
return OK;
}
inptr += LOCHDR + SH(h + LOCFIL) + SH(h + LOCEXT);
if (inptr > insize || LG(h) != LOCSIG) {
- fprintf(stderr, "\n%s: %s: not a valid zip file\n",
- program_name, ifname);
- exit_code = ERROR;
- return ERROR;
+ fprintf(stderr, "\n%s: %s: not a valid zip file\n",
+ program_name, ifname);
+ exit_code = ERROR;
+ return ERROR;
}
method = h[LOCHOW];
if (method != STORED && method != DEFLATED) {
- fprintf(stderr,
- "\n%s: %s: first entry not deflated or stored -- use unzip\n",
- program_name, ifname);
- exit_code = ERROR;
- return ERROR;
+ fprintf(stderr,
+ "\n%s: %s: first entry not deflated or stored -- use unzip\n",
+ program_name, ifname);
+ exit_code = ERROR;
+ return ERROR;
}
/* If entry encrypted, decrypt and validate encryption header */
if ((decrypt = h[LOCFLG] & CRPFLG) != 0) {
- fprintf(stderr, "\n%s: %s: encrypted file -- use unzip\n",
- program_name, ifname);
- exit_code = ERROR;
- return ERROR;
+ fprintf(stderr, "\n%s: %s: encrypted file -- use unzip\n",
+ program_name, ifname);
+ exit_code = ERROR;
+ return ERROR;
}
/* Save flags for unzip() */
updcrc(NULL, 0); /* initialize crc */
if (pkzip && !ext_header) { /* crc and length at the end otherwise */
- orig_crc = LG(inbuf + LOCCRC);
- orig_len = LG(inbuf + LOCLEN);
+ orig_crc = LG(inbuf + LOCCRC);
+ orig_len = LG(inbuf + LOCLEN);
}
/* Decompress */
if (method == DEFLATED) {
- int res = inflate();
+ int res = inflate();
- if (res == 3) {
- xalloc_die ();
- } else if (res != 0) {
- gzip_error ("invalid compressed data--format violated");
- }
+ if (res == 3) {
+ xalloc_die ();
+ } else if (res != 0) {
+ gzip_error ("invalid compressed data--format violated");
+ }
} else if (pkzip && method == STORED) {
- register ulg n = LG(inbuf + LOCLEN);
+ register ulg n = LG(inbuf + LOCLEN);
- if (n != LG(inbuf + LOCSIZ) - (decrypt ? RAND_HEAD_LEN : 0)) {
+ if (n != LG(inbuf + LOCSIZ) - (decrypt ? RAND_HEAD_LEN : 0)) {
- fprintf(stderr, "len %ld, siz %ld\n", n, LG(inbuf + LOCSIZ));
- gzip_error ("invalid compressed data--length mismatch");
- }
- while (n--) {
- uch c = (uch)get_byte();
- put_ubyte(c);
- }
- flush_window();
+ fprintf(stderr, "len %ld, siz %ld\n", n, LG(inbuf + LOCSIZ));
+ gzip_error ("invalid compressed data--length mismatch");
+ }
+ while (n--) {
+ uch c = (uch)get_byte();
+ put_ubyte(c);
+ }
+ flush_window();
} else {
- gzip_error ("internal error, invalid method");
+ gzip_error ("internal error, invalid method");
}
/* Get the crc and original length */
if (!pkzip) {
/* crc32 (see algorithm.doc)
- * uncompressed input size modulo 2^32
+ * uncompressed input size modulo 2^32
*/
- for (n = 0; n < 8; n++) {
- buf[n] = (uch)get_byte(); /* may cause an error if EOF */
- }
- orig_crc = LG(buf);
- orig_len = LG(buf+4);
+ for (n = 0; n < 8; n++) {
+ buf[n] = (uch)get_byte(); /* may cause an error if EOF */
+ }
+ orig_crc = LG(buf);
+ orig_len = LG(buf+4);
} else if (ext_header) { /* If extended header, check it */
- /* signature - 4bytes: 0x50 0x4b 0x07 0x08
- * CRC-32 value
+ /* signature - 4bytes: 0x50 0x4b 0x07 0x08
+ * CRC-32 value
* compressed size 4-bytes
* uncompressed size 4-bytes
- */
- for (n = 0; n < EXTHDR; n++) {
- buf[n] = (uch)get_byte(); /* may cause an error if EOF */
- }
- orig_crc = LG(buf+4);
- orig_len = LG(buf+12);
+ */
+ for (n = 0; n < EXTHDR; n++) {
+ buf[n] = (uch)get_byte(); /* may cause an error if EOF */
+ }
+ orig_crc = LG(buf+4);
+ orig_len = LG(buf+12);
}
/* Validate decompression */
if (orig_crc != updcrc(outbuf, 0)) {
- fprintf(stderr, "\n%s: %s: invalid compressed data--crc error\n",
- program_name, ifname);
- err = ERROR;
+ fprintf(stderr, "\n%s: %s: invalid compressed data--crc error\n",
+ program_name, ifname);
+ err = ERROR;
}
if (orig_len != (ulg)(bytes_out & 0xffffffff)) {
- fprintf(stderr, "\n%s: %s: invalid compressed data--length error\n",
- program_name, ifname);
- err = ERROR;
+ fprintf(stderr, "\n%s: %s: invalid compressed data--length error\n",
+ program_name, ifname);
+ err = ERROR;
}
/* Check if there are more entries in a pkzip file */
if (pkzip && inptr + 4 < insize && LG(inbuf+inptr) == LOCSIG) {
- if (to_stdout) {
- WARN((stderr,
- "%s: %s has more than one entry--rest ignored\n",
- program_name, ifname));
- } else {
- /* Don't destroy the input zip file */
- fprintf(stderr,
- "%s: %s has more than one entry -- unchanged\n",
- program_name, ifname);
- err = ERROR;
- }
+ if (to_stdout) {
+ WARN((stderr,
+ "%s: %s has more than one entry--rest ignored\n",
+ program_name, ifname));
+ } else {
+ /* Don't destroy the input zip file */
+ fprintf(stderr,
+ "%s: %s has more than one entry -- unchanged\n",
+ program_name, ifname);
+ err = ERROR;
+ }
}
ext_header = pkzip = 0; /* for next file */
if (err == OK) return OK;
{
errno = 0;
while (insize != 0 && (int)insize != -1) {
- write_buf(out, (char*)inbuf, insize);
- bytes_out += insize;
- insize = read_buffer (in, (char *) inbuf, INBUFSIZ);
+ write_buf(out, (char*)inbuf, insize);
+ bytes_out += insize;
+ insize = read_buffer (in, (char *) inbuf, INBUFSIZ);
}
if ((int)insize == -1) {
- read_error();
+ read_error();
}
bytes_in = bytes_out;
return OK;
static ulg crc = (ulg)0xffffffffL; /* shift register contents */
if (s == NULL) {
- c = 0xffffffffL;
+ c = 0xffffffffL;
} else {
- c = crc;
+ c = crc;
if (n) do {
c = crc_32_tab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
} while (--n);
/* Read as much as possible */
insize = 0;
do {
- len = read_buffer (ifd, (char *) inbuf + insize, INBUFSIZ - insize);
- if (len == 0) break;
- if (len == -1) {
- read_error();
- break;
- }
- insize += len;
+ len = read_buffer (ifd, (char *) inbuf + insize, INBUFSIZ - insize);
+ if (len == 0) break;
+ if (len == -1) {
+ read_error();
+ break;
+ }
+ insize += len;
} while (insize < INBUFSIZ);
if (insize == 0) {
- if (eof_ok) return EOF;
- flush_window();
- errno = 0;
- read_error();
+ if (eof_ok) return EOF;
+ flush_window();
+ errno = 0;
+ read_error();
}
bytes_in += (off_t)insize;
inptr = 1;
updcrc(window, outcnt);
if (!test) {
- write_buf(ofd, (char *)window, outcnt);
+ write_buf(ofd, (char *)window, outcnt);
}
bytes_out += (off_t)outcnt;
outcnt = 0;
unsigned n;
while ((n = write_buffer (fd, buf, cnt)) != cnt) {
- if (n == (unsigned)(-1)) {
- write_error();
- }
- cnt -= n;
- buf = (voidp)((char*)buf+n);
+ if (n == (unsigned)(-1)) {
+ write_error();
+ }
+ cnt -= n;
+ buf = (voidp)((char*)buf+n);
}
}
{
int e = errno;
if (chmod (filename, S_IWUSR) != 0)
- {
- errno = e;
- return -1;
- }
+ {
+ errno = e;
+ return -1;
+ }
r = unlink (filename);
}
env_val = xstrdup (env_val);
for (p = env_val; *p; nargc++ ) { /* move through env_val */
- p += strspn(p, SEPARATOR); /* skip leading separators */
- if (*p == '\0') break;
+ p += strspn(p, SEPARATOR); /* skip leading separators */
+ if (*p == '\0') break;
- p += strcspn(p, SEPARATOR); /* find end of word */
- if (*p) *p++ = '\0'; /* mark it */
+ p += strcspn(p, SEPARATOR); /* find end of word */
+ if (*p) *p++ = '\0'; /* mark it */
}
if (nargc == 0) {
- free(env_val);
- return NULL;
+ free(env_val);
+ return NULL;
}
*argcp += nargc;
/* Allocate the new argv array, with an extra element just in case
/* Then copy the environment args */
for (p = env_val; nargc > 0; nargc--) {
- p += strspn(p, SEPARATOR); /* skip separators */
- *(nargv++) = p; /* store start */
- while (*p++) ; /* skip over word */
+ p += strspn(p, SEPARATOR); /* skip separators */
+ *(nargv++) = p; /* store start */
+ while (*p++) ; /* skip over word */
}
/* Finally copy the old args and add a NULL (usual convention) */
int e = errno;
fprintf (stderr, "\n%s: ", program_name);
if (e != 0) {
- errno = e;
- perror(ifname);
+ errno = e;
+ perror(ifname);
} else {
- fprintf(stderr, "%s: unexpected end of file\n", ifname);
+ fprintf(stderr, "%s: unexpected end of file\n", ifname);
}
abort_gzip();
}
/* Don't negate offset here; it might overflow. */
if (offset < 0) {
- do
- *--p = '0' - offset % 10;
- while ((offset /= 10) != 0);
+ do
+ *--p = '0' - offset % 10;
+ while ((offset /= 10) != 0);
- *--p = '-';
+ *--p = '-';
} else {
- do
- *--p = '0' + offset % 10;
- while ((offset /= 10) != 0);
+ do
+ *--p = '0' + offset % 10;
+ while ((offset /= 10) != 0);
}
width -= buf + sizeof buf - p;
while (0 < width--) {
- putc (' ', file);
+ putc (' ', file);
}
for (; p < buf + sizeof buf; p++)
- putc (*p, file);
+ putc (*p, file);
}
/* ========================================================================
won't find the source-files.
Using gcc saves disk-space, but needs longer to compile
- VAXC gzip.exe 95/96 Blocks
- gcc2.3.3 gzip.exe 86/87 Blocks
+ VAXC gzip.exe 95/96 Blocks
+ gcc2.3.3 gzip.exe 86/87 Blocks
To install gzip one has to perform the following steps:
1. compile sources (*.c, [.vms]*.c)
5. Setting up Symbols for the executables:
Place the following lines in Your login.com
Change "disk:[directory]" as appropriate.
- $ gzip == "$disk:[directory]gzip.exe"
- $ gunzip == "$disk:[directory]gunzip.exe"
- $ zcat == "$disk:[directory]zcat.exe"
+ $ gzip == "$disk:[directory]gzip.exe"
+ $ gunzip == "$disk:[directory]gunzip.exe"
+ $ zcat == "$disk:[directory]zcat.exe"
6. insert help-file gzip.hlp in any Help-library,
for example in sys$help:helplib.
this can be done by $lib sys$help:helplib/help gzip
Usage:
- change to the Source-Directory
- copy vms.c
- $copy [.vms]vms.c []
+ $copy [.vms]vms.c []
- start compiling, linking, entries
- $@[.vms]makegzip
+ $@[.vms]makegzip
if everything is OK. then you get gzip.exe, gunzip.exe, zcat.exe
continue at Step 4.
recompile several times, for example after editing the sources.
- change to the Source-Directory
- copy vms.c
- $copy [.vms]vms.c []
+ $copy [.vms]vms.c []
- start compiling, linking, entries
- $make /input=[.vms]makefile.vms
+ $make /input=[.vms]makefile.vms
if everything is OK. then you get gzip.exe, gunzip.exe, zcat.exe
Continue at Step 4.
uncompressed_name: name of the uncompressed file
The uncompressed size is given as -1 on VMS because it
- it is not possible to seek reliably to the end of the
+ it is not possible to seek reliably to the end of the
compressed file, where this size is stored.
In combination with the --verbose option, the following
crc is given as ffffffff on VMS for the reason given
above about the uncompressed size.
- With --name, the uncompressed name, date and time are
- those stored within the compress file if present.
+ With --name, the uncompressed name, date and time are
+ those stored within the compress file if present.
With --verbose, the size totals and compression ratio
for all files is also displayed, unless some sizes are
vms_argv[new_argc++] = **argv;
for (i=1; i < *old_argc; i++) {
- if (*argv[0][i] == '-') { /* switches */
- if (new_argc < max_files) {
- vms_argv[new_argc++] = argv[0][i];
- }
- } else { /* Files */
- context = 0;
- if (find_file_c(argv[0][i], buf, sizeof(buf), &context) & 1 != 1) {
- /*
- * Wrong file ?
- * forward it to gzip
- */
- if (new_argc < max_files) {
- vms_argv[new_argc++] = argv[0][i];
- }
- } else {
- p = xmalloc(strlen(buf)+1);
- strcpy(p, buf);
- if (new_argc < max_files) {
- vms_argv[new_argc++] = p;
- }
- while (find_file_c(argv[0][i], buf,
- sizeof(buf), &context) & 1 == 1) {
- p = xmalloc(strlen(buf)+1);
- strcpy(p, buf);
- if (new_argc < max_files) {
- vms_argv[new_argc++] = p;
- }
- }
- }
- }
+ if (*argv[0][i] == '-') { /* switches */
+ if (new_argc < max_files) {
+ vms_argv[new_argc++] = argv[0][i];
+ }
+ } else { /* Files */
+ context = 0;
+ if (find_file_c(argv[0][i], buf, sizeof(buf), &context) & 1 != 1) {
+ /*
+ * Wrong file ?
+ * forward it to gzip
+ */
+ if (new_argc < max_files) {
+ vms_argv[new_argc++] = argv[0][i];
+ }
+ } else {
+ p = xmalloc(strlen(buf)+1);
+ strcpy(p, buf);
+ if (new_argc < max_files) {
+ vms_argv[new_argc++] = p;
+ }
+ while (find_file_c(argv[0][i], buf,
+ sizeof(buf), &context) & 1 == 1) {
+ p = xmalloc(strlen(buf)+1);
+ strcpy(p, buf);
+ if (new_argc < max_files) {
+ vms_argv[new_argc++] = p;
+ }
+ }
+ }
+ }
}
if (new_argc <= max_files) {
- *old_argc = new_argc;
- vms_argv[new_argc] = NULL;
- *argv = vms_argv;
+ *old_argc = new_argc;
+ vms_argv[new_argc] = NULL;
+ *argv = vms_argv;
} else {
- free(vms_argv); /* the expanded file names should also be freed ... */
- vms_argv = NULL;
- max_files = new_argc + 1;
- vms_expand_args(old_argc, argv);
+ free(vms_argv); /* the expanded file names should also be freed ... */
+ vms_argv = NULL;
+ max_files = new_argc + 1;
+ vms_expand_args(old_argc, argv);
}
}
p = out_desc.addr;
while(*p != ' ') {
- p++;
+ p++;
}
*p = 0;
case $1 in
--__cmp) shift
- prog=cmp; cmp='${CMP-cmp}' ;;
+ prog=cmp; cmp='${CMP-cmp}' ;;
*) prog=diff; cmp='${DIFF-diff}';;
esac
exit 2;;
esac
elif test $# -eq 2; then
- case "$1" in
- *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
+ case "$1" in
+ *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
case "$2" in
- *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
- if test "$1$2" = --; then
- gzip_status=$(
- exec 4>&1
- (gzip -cdfq - 4>&-; echo $? >&4) 3>&- |
- eval "$cmp" - - >&3
- )
- elif
- # Reject Solaris 8's buggy /bin/bash 2.03.
- echo X |
- (echo X | eval "$cmp" /dev/fd/5 - >/dev/null 2>&1) \
- 5<&0
- then
- gzip_status=$(
- exec 4>&1
- (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
- ( (gzip -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- 5<&- </dev/null |
- eval "$cmp" /dev/fd/5 - >&3) 5<&0
- )
- cmp_status=$?
- case $gzip_status in
- *[1-9]*) gzip_status=1;;
- *) gzip_status=0;;
- esac
- (exit $cmp_status)
- else
- F=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F=$prog
- tmp=
- trap '
- test -n "$tmp" && rm -f "$tmp"
- (exit 2); exit 2
- ' HUP INT PIPE TERM 0
- if type mktemp >/dev/null 2>&1; then
- tmp=`mktemp -t -- "$F.XXXXXX"` || exit 2
- else
- set -C
- tmp=${TMPDIR-/tmp}/$F.$$
- fi
- gzip -cdfq -- "$2" > "$tmp" || exit 2
- gzip_status=$(
- exec 4>&1
- (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
- eval "$cmp" - '"$tmp"' >&3
- )
+ *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
+ if test "$1$2" = --; then
+ gzip_status=$(
+ exec 4>&1
+ (gzip -cdfq - 4>&-; echo $? >&4) 3>&- |
+ eval "$cmp" - - >&3
+ )
+ elif
+ # Reject Solaris 8's buggy /bin/bash 2.03.
+ echo X |
+ (echo X | eval "$cmp" /dev/fd/5 - >/dev/null 2>&1) \
+ 5<&0
+ then
+ gzip_status=$(
+ exec 4>&1
+ (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
+ ( (gzip -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- 5<&- </dev/null |
+ eval "$cmp" /dev/fd/5 - >&3) 5<&0
+ )
cmp_status=$?
- rm -f "$tmp" || gzip_status=$?
- trap - HUP INT PIPE TERM 0
- (exit $cmp_status)
- fi;;
- *)
- gzip_status=$(
- exec 4>&1
- (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
- eval "$cmp" - '"$2"' >&3
- );;
+ case $gzip_status in
+ *[1-9]*) gzip_status=1;;
+ *) gzip_status=0;;
+ esac
+ (exit $cmp_status)
+ else
+ F=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F=$prog
+ tmp=
+ trap '
+ test -n "$tmp" && rm -f "$tmp"
+ (exit 2); exit 2
+ ' HUP INT PIPE TERM 0
+ if type mktemp >/dev/null 2>&1; then
+ tmp=`mktemp -t -- "$F.XXXXXX"` || exit 2
+ else
+ set -C
+ tmp=${TMPDIR-/tmp}/$F.$$
+ fi
+ gzip -cdfq -- "$2" > "$tmp" || exit 2
+ gzip_status=$(
+ exec 4>&1
+ (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
+ eval "$cmp" - '"$tmp"' >&3
+ )
+ cmp_status=$?
+ rm -f "$tmp" || gzip_status=$?
+ trap - HUP INT PIPE TERM 0
+ (exit $cmp_status)
+ fi;;
+ *)
+ gzip_status=$(
+ exec 4>&1
+ (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
+ eval "$cmp" - '"$2"' >&3
+ );;
esac;;
*) case "$2" in
- *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
- gzip_status=$(
- exec 4>&1
- (gzip -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- |
- eval "$cmp" '"$1"' - >&3
- );;
- *) eval "$cmp" '"$1"' '"$2"';;
+ *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
+ gzip_status=$(
+ exec 4>&1
+ (gzip -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- |
+ eval "$cmp" '"$1"' - >&3
+ );;
+ *) eval "$cmp" '"$1"' '"$2"';;
esac;;
- esac
+ esac
else
- echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
- exit 2
+ echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
+ exit 2
fi
cmp_status=$?
eval "$grep" >/dev/null && { printf '%s\n' "$i" || exit 2; }
elif test $files_without_matches -eq 1; then
eval "$grep" >/dev/null || {
- r=$?
- if test $r -eq 1; then
- printf '%s\n' "$i" || r=2
- fi
- exit $r
+ r=$?
+ if test $r -eq 1; then
+ printf '%s\n' "$i" || r=2
+ fi
+ exit $r
}
elif test $with_filename -eq 0 &&
- { test $# -eq 1 || test $no_filename -eq 1; }; then
+ { test $# -eq 1 || test $no_filename -eq 1; }; then
eval "$grep"
else
case $i in
(*'
'* | *'&'* | *'\'* | *'|'*)
i=$(printf '%s\n' "$i" |
- sed '
- $!N
- $s/[&\|]/\\&/g
- $s/\n/\\n/g
- ');;
+ sed '
+ $!N
+ $s/[&\|]/\\&/g
+ $s/\n/\\n/g
+ ');;
esac
sed_script="s|^|$i:|"
# Fail if grep or sed fails.
r=$(
- exec 4>&1
- (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&-
+ exec 4>&1
+ (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&-
) || r=2
exit $r
fi >&3 5>&-
put_byte(DEFLATED); /* compression method */
if (save_orig_name) {
- flags |= ORIG_NAME;
+ flags |= ORIG_NAME;
}
put_byte(flags); /* general flags */
stamp = (0 <= time_stamp.tv_sec && time_stamp.tv_sec <= 0xffffffff
- ? (ulg) time_stamp.tv_sec
- : (ulg) 0);
+ ? (ulg) time_stamp.tv_sec
+ : (ulg) 0);
put_long (stamp);
/* Write deflated file to zip file */
put_byte(OS_CODE); /* OS identifier */
if (save_orig_name) {
- char *p = gzip_base_name (ifname); /* Don't save the directory part. */
- do {
- put_char(*p);
- } while (*p++);
+ char *p = gzip_base_name (ifname); /* Don't save the directory part. */
+ do {
+ put_char(*p);
+ } while (*p++);
}
header_bytes = (off_t)outcnt;
* and not on MSDOS -- diet in TSR mode reports an incorrect file size)
*/
if (ifile_size != -1L && bytes_in != ifile_size) {
- fprintf(stderr, "%s: %s: file size changed while zipping\n",
- program_name, ifname);
+ fprintf(stderr, "%s: %s: file size changed while zipping\n",
+ program_name, ifname);
}
#endif
len = read_buffer (ifd, buf, size);
if (len == 0) return (int)len;
if (len == (unsigned)-1) {
- read_error();
- return EOF;
+ read_error();
+ return EOF;
}
crc = updcrc((uch*)buf, len);
if test $# = 0; then
if test -t 0; then
- echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
+ echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
else
- gzip -cdfq | eval ${PAGER-more}
+ gzip -cdfq | eval ${PAGER-more}
fi
else
FIRST=1
for FILE
do
- case $FILE in
- --h*) exec echo "$usage";;
- --v*) exec echo "$version";;
- esac
+ case $FILE in
+ --h*) exec echo "$usage";;
+ --v*) exec echo "$version";;
+ esac
- < "$FILE" || continue
- if test $FIRST -eq 0; then
- echo $n1 "--More--(Next file: $FILE)$n2"
- stty $cb -echo 2>/dev/null
- ANS=`dd bs=1 count=1 2>/dev/null`
- stty $ncb echo 2>/dev/null
- echo " "
- case "$ANS" in
- [eq]) exit;;
- esac
- fi
- if test "$ANS" != 's'; then
- echo "------> $FILE <------"
- gzip -cdfq -- "$FILE" | eval ${PAGER-more}
- fi
- if test -t 1; then
- FIRST=0
- fi
+ < "$FILE" || continue
+ if test $FIRST -eq 0; then
+ echo $n1 "--More--(Next file: $FILE)$n2"
+ stty $cb -echo 2>/dev/null
+ ANS=`dd bs=1 count=1 2>/dev/null`
+ stty $ncb echo 2>/dev/null
+ echo " "
+ case "$ANS" in
+ [eq]) exit;;
+ esac
+ fi
+ if test "$ANS" != 's'; then
+ echo "------> $FILE <------"
+ gzip -cdfq -- "$FILE" | eval ${PAGER-more}
+ fi
+ if test -t 1; then
+ FIRST=0
+ fi
done
fi
else
if test $check -eq 1; then
if cp -p "$n.Z" "$n.$$" 2> /dev/null || cp "$n.Z" "$n.$$"; then
- :
+ :
else
- echo cannot backup "$n.Z"
+ echo cannot backup "$n.Z"
res=1; continue
fi
fi
:
else
if test $check -eq 1; then
- mv "$n.$$" "$n.Z" && rm -f "$n"
+ mv "$n.$$" "$n.Z" && rm -f "$n"
echo error while recompressing $n
else
- # compress $n (might be dangerous if disk full)
+ # compress $n (might be dangerous if disk full)
echo error while recompressing $n, left uncompressed
fi
res=1; continue
fi
test $keep -eq 1 && new=`wc -c < "$n$ext"`
if test $keep -eq 1 && test `expr \( $old + $block - 1 \) / $block` -lt \
- `expr \( $new + $block - 1 \) / $block`; then
+ `expr \( $new + $block - 1 \) / $block`; then
if test $pipe -eq 1; then
rm -f "$n$ext"
else