build system: "make hosttools" doesn't exist, remove it from "make help"
[oweals/busybox.git] / archival / lzop.c
index f4419910f177248796975590c85e5cb0b36153a9..5062d9300c45f2f5975ddde9ec348e780b070b43 100644 (file)
@@ -14,7 +14,7 @@
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    "Minimalized" for busybox by Alain Knaff
 */
 
+//config:config LZOP
+//config:      bool "lzop"
+//config:      default y
+//config:      help
+//config:        Lzop compression/decompresion.
+//config:
+//config:config LZOP_COMPR_HIGH
+//config:      bool "lzop compression levels 7,8,9 (not very useful)"
+//config:      default n
+//config:      depends on LZOP
+//config:      help
+//config:        High levels (7,8,9) of lzop compression. These levels
+//config:        are actually slower than gzip at equivalent compression ratios
+//config:        and take up 3.2K of code.
+
+//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
+//applet:IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
+//applet:IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
+//kbuild:lib-$(CONFIG_LZOP) += lzop.o
+
 //usage:#define lzop_trivial_usage
 //usage:       "[-cfvd123456789CF] [FILE]..."
 //usage:#define lzop_full_usage "\n\n"
-//usage:       "Options:"
-//usage:     "\n       -1..9   Compression level"
+//usage:       "       -1..9   Compression level"
 //usage:     "\n       -d      Decompress"
 //usage:     "\n       -c      Write to stdout"
 //usage:     "\n       -f      Force"
 //usage:#define unlzop_trivial_usage
 //usage:       "[-cfvCF] [FILE]..."
 //usage:#define unlzop_full_usage "\n\n"
-//usage:       "Options:"
-//usage:     "\n       -c      Write to stdout"
+//usage:       "       -c      Write to stdout"
 //usage:     "\n       -f      Force"
 //usage:     "\n       -v      Verbose"
 //usage:     "\n       -F      Don't store or verify checksum"
 
 #include "libbb.h"
-#include "archive.h"
+#include "bb_archive.h"
 #include "liblzo_interface.h"
 
 /* lzo-2.03/src/lzo_ptr.h */
@@ -118,7 +136,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
        unsigned nl;
        unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0;
 
-//       LZO_UNUSED(wrkmem);
+//     LZO_UNUSED(wrkmem);
 
        *out_len = 0;
 
@@ -203,7 +221,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
                                        /* remove short run */
                                        *litp &= ~3;
                                        /* copy over the 2 literals that replace the match */
-                                       copy2(ip-3+1,m_pos,pd(op,m_pos));
+                                       copy2(ip-3+1, m_pos, pd(op, m_pos));
                                        /* move literals 1 byte ahead */
                                        litp += 2;
                                        if (lit > 0)
@@ -213,7 +231,8 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
                                        *litp = (unsigned char)(lit - 3);
 
                                        o_m1_b++;
-                                       *op++ = *m_pos++; *op++ = *m_pos++;
+                                       *op++ = *m_pos++;
+                                       *op++ = *m_pos++;
                                        goto copy_literal_run;
                                }
  copy_m1:
@@ -242,7 +261,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
                                        ) {
                                                t = *ip++;
                                                /* copy over the 3 literals that replace the match */
-                                               copy3(ip-1-2,m_pos,pd(op,m_pos));
+                                               copy3(ip-1-2, m_pos, pd(op, m_pos));
                                                /* set new length of previous literal run */
                                                lit += 3 + t + 3;
                                                *litp = (unsigned char)(lit - 3);
@@ -291,7 +310,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
                                                lit += 3;
                                                *litp = (unsigned char)((*litp & ~3) | lit);
                                                /* copy over the 3 literals that replace the match */
-                                               copy3(ip-3,m_pos,pd(op,m_pos));
+                                               copy3(ip-3, m_pos, pd(op, m_pos));
                                                o_m3_a++;
                                        }
                                        /* test if a literal run follows */
@@ -302,7 +321,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
                                                /* remove short run */
                                                *litp &= ~3;
                                                /* copy over the 3 literals that replace the match */
-                                               copy3(ip-4+1,m_pos,pd(op,m_pos));
+                                               copy3(ip-4+1, m_pos, pd(op, m_pos));
                                                /* move literals 1 byte ahead */
                                                litp += 2;
                                                if (lit > 0)
@@ -347,11 +366,11 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
        return LZO_E_EOF_NOT_FOUND;
 
  eof_found:
-//       LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2);
-//       LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b);
+//     LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2);
+//     LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b);
        *out_len = pd(op, out);
        return (ip == ip_end ? LZO_E_OK :
-                  (ip < ip_end  ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
+               (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
 }
 
 /**********************************************************************/
@@ -437,25 +456,27 @@ struct globals {
 //#define LZOP_VERSION_STRING     "1.01"
 //#define LZOP_VERSION_DATE       "Apr 27th 2003"
 
-#define OPTION_STRING "cfvdt123456789CF"
+#define OPTION_STRING "cfvqdt123456789CF"
 
+/* Note: must be kept in sync with archival/bbunzip.c */
 enum {
        OPT_STDOUT      = (1 << 0),
        OPT_FORCE       = (1 << 1),
        OPT_VERBOSE     = (1 << 2),
-       OPT_DECOMPRESS  = (1 << 3),
-       OPT_TEST        = (1 << 4),
-       OPT_1           = (1 << 5),
-       OPT_2           = (1 << 6),
-       OPT_3           = (1 << 7),
-       OPT_4           = (1 << 8),
-       OPT_5           = (1 << 9),
-       OPT_6           = (1 << 10),
-       OPT_789         = (7 << 11),
-       OPT_7           = (1 << 11),
-       OPT_8           = (1 << 12),
-       OPT_C           = (1 << 14),
-       OPT_F           = (1 << 15),
+       OPT_QUIET       = (1 << 3),
+       OPT_DECOMPRESS  = (1 << 4),
+       OPT_TEST        = (1 << 5),
+       OPT_1           = (1 << 6),
+       OPT_2           = (1 << 7),
+       OPT_3           = (1 << 8),
+       OPT_4           = (1 << 9),
+       OPT_5           = (1 << 10),
+       OPT_6           = (1 << 11),
+       OPT_789         = (7 << 12),
+       OPT_7           = (1 << 13),
+       OPT_8           = (1 << 14),
+       OPT_C           = (1 << 15),
+       OPT_F           = (1 << 16),
 };
 
 /**********************************************************************/
@@ -1078,7 +1099,7 @@ static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_e
        return xasprintf("%s.lzo", filename);
 }
 
-static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(unpack_info_t *info UNUSED_PARAM)
+static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
 {
        if (option_mask32 & OPT_DECOMPRESS)
                return do_lzo_decompress();
@@ -1094,7 +1115,7 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
        if (applet_name[4] == 'c')
                option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS);
        /* unlzop? */
-       if (applet_name[0] == 'u')
+       if (applet_name[4] == 'o')
                option_mask32 |= OPT_DECOMPRESS;
 
        global_crc32_table = crc32_filltable(NULL, 0);