Changeset 2697eab
- Timestamp:
- 06/30/14 13:23:39 (7 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- b4b8e55
- Parents:
- d1cb537 (diff), d19ff50 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
configure.in
rabf01b6 r4b0cd2f 580 580 ) 581 581 582 AC_ARG_WITH([lzma], 583 AC_HELP_STRING([--with-lzma], [build with support for lzma compressed files])) 584 585 AS_IF([test "x$with_lzma" != "xno"], 586 [ 587 AC_CHECK_LIB(lzma, lzma_code, have_lzma=yes, have_lzma=no) 588 ], [have_lzma=no]) 589 590 AS_IF([test "x$have_lzma" = "xyes"], [ 591 if test "$ac_cv_lib_lzma_code" != "none required"; then 592 LIBWANDIO_LIBS="$LIBWANDIO_LIBS -llzma" 593 fi 594 AC_DEFINE(HAVE_LIBLZMA, 1, "Compiled with lzma support") 595 with_lzma=yes], 596 597 598 [AS_IF([test "x$with_lzma" = "xyes"], 599 [AC_MSG_ERROR([lzma requested but not found])]) 600 AC_DEFINE(HAVE_LIBLZMA, 0, "Compiled with lzma support") 601 with_lzma=no] 602 ) 582 603 583 604 # Define automake conditionals for use in our Makefile.am files … … 594 615 AM_CONDITIONAL([HAVE_ZLIB], [test "x$with_zlib" != "xno"]) 595 616 AM_CONDITIONAL([HAVE_LZO], [ test "x$with_lzo" != "xno"]) 617 AM_CONDITIONAL([HAVE_LZMA], [ test "x$with_lzma" != "xno"]) 596 618 597 619 # Check for miscellaneous programs … … 648 670 reportopt "Compiled with compressed trace (bz2) support" $with_bzip2 649 671 reportopt "Compiled with compressed trace (lzo write only) support" $with_lzo 672 reportopt "Compiled with compressed trace (lzma) support" $with_lzma 650 673 if test x"$libtrace_dag" = xtrue; then 651 674 if test "$libtrace_dag_version" = 24; then -
libwandio/Makefile.am
rbd119b3 r4b0cd2f 24 24 endif 25 25 26 if HAVE_LZMA 27 LIBTRACEIO_LZMA=ior-lzma.c iow-lzma.c 28 else 29 LIBTRACEIO_LZMA= 30 endif 31 26 32 libwandio_la_SOURCES=wandio.c ior-peek.c ior-stdio.c ior-thread.c \ 27 33 iow-stdio.c iow-thread.c wandio.h wandio_internal.h \ 28 $(LIBTRACEIO_ZLIB) $(LIBTRACEIO_BZLIB) $(LIBTRACEIO_LZO) 34 $(LIBTRACEIO_ZLIB) $(LIBTRACEIO_BZLIB) $(LIBTRACEIO_LZO) \ 35 $(LIBTRACEIO_LZMA) 29 36 30 37 AM_CPPFLAGS = @ADD_INCLS@ … … 32 39 libwandio_la_LDFLAGS=-version-info 1:0:0 @ADD_LDFLAGS@ 33 40 41 bin_PROGRAMS = wandiocat 42 wandiocat_SOURCES = wcat.c 43 wandiocat_CFLAGS = -I"$(top_srcdir)/libwandio" 44 wandiocat_CXXFLAGS = -I"$(top_srcdir)/libwandio" 45 wandiocat_LDFLAGS = -L"$(top_srcdir)/libwandio" -lwandio -
libwandio/wandio.c
r10f924c r4b0cd2f 46 46 */ 47 47 48 struct compression_type compression_type[] = { 49 { "GZ", "gz", WANDIO_COMPRESS_ZLIB }, 50 { "BZ2", "bz2", WANDIO_COMPRESS_BZ2 }, 51 { "LZO", "lzo", WANDIO_COMPRESS_LZO }, 48 struct wandio_compression_type compression_type[] = { 49 { "gzip", "gz", WANDIO_COMPRESS_ZLIB }, 50 { "bzip2", "bz2", WANDIO_COMPRESS_BZ2 }, 51 { "lzo", "lzo", WANDIO_COMPRESS_LZO }, 52 { "lzma", "xz", WANDIO_COMPRESS_LZMA }, 52 53 { "NONE", "", WANDIO_COMPRESS_NONE } 53 54 }; … … 141 142 DEBUG_PIPELINE("peek"); 142 143 io_t *io = peek_open(stdio_open(filename)); 143 char buffer[1024];144 unsigned char buffer[1024]; 144 145 int len; 145 146 if (!io) … … 151 152 152 153 if (autodetect) { 153 if (len>=3 && buffer[0] == '\037' && buffer[1] == '\213'&&154 if (len>=3 && buffer[0] == 0x1f && buffer[1] == 0x8b && 154 155 buffer[2] == 0x08) { 155 156 #if HAVE_LIBZ … … 162 163 } 163 164 /* Auto detect compress(1) compressed data (gzip can read this) */ 164 if (len>=2 && buffer[0] == '\037' && buffer[1] == '\235') {165 if (len>=2 && buffer[0] == 0x1f && buffer[1] == 0x9d) { 165 166 #if HAVE_LIBZ 166 167 DEBUG_PIPELINE("zlib"); … … 182 183 #endif 183 184 } 185 186 if (len >=5 && buffer[0] == 0xfd && buffer[1] == '7' && 187 buffer[2] == 'z' && buffer[3] == 'X' && 188 buffer[4] == 'Z') { 189 #if HAVE_LIBLZMA 190 DEBUG_PIPELINE("lzma"); 191 io = lzma_open(io); 192 #else 193 fprintf(stderr, "File %s is lzma compressed but libtrace has not been built with lzma support!\n", filename); 194 return NULL; 195 #endif 196 } 184 197 } 185 198 /* Now open a threaded, peekable reader using the appropriate module … … 193 206 DEBUG_PIPELINE("peek"); 194 207 return peek_open(io); 208 } 209 210 DLLEXPORT struct wandio_compression_type *wandio_lookup_compression_type( 211 const char *name) { 212 213 struct wandio_compression_type *wct = compression_type; 214 215 while (strcmp(wct->name, "NONE") != 0) { 216 if (strcmp(wct->name, name) == 0) 217 return wct; 218 wct++; 219 } 220 221 return NULL; 195 222 } 196 223 … … 291 318 } 292 319 #endif 320 #if HAVE_LIBLZMA 321 else if (compression_level != 0 && 322 compress_type == WANDIO_COMPRESS_LZMA) { 323 iow = lzma_wopen(iow,compression_level); 324 } 325 #endif 293 326 /* Open a threaded writer */ 294 327 if (use_threads) -
libwandio/wandio.h
rc7021d9 r4b0cd2f 66 66 67 67 /** Structure defining a supported compression method */ 68 struct compression_type {68 struct wandio_compression_type { 69 69 /** Name of the compression method */ 70 70 const char *name; … … 77 77 78 78 /** The list of supported compression methods */ 79 extern struct compression_type compression_type[];79 extern struct wandio_compression_type compression_type[]; 80 80 81 81 /** Structure defining a libtrace IO reader module */ … … 178 178 /** LZO compression */ 179 179 WANDIO_COMPRESS_LZO = 3, 180 /** LZMA compression */ 181 WANDIO_COMPRESS_LZMA = 4, 180 182 /** All supported methods - used as a bitmask */ 181 183 WANDIO_COMPRESS_MASK = 7 … … 193 195 io_t *zlib_open(io_t *parent); 194 196 io_t *thread_open(io_t *parent); 197 io_t *lzma_open(io_t *parent); 195 198 io_t *peek_open(io_t *parent); 196 199 io_t *stdio_open(const char *filename); … … 199 202 iow_t *bz_wopen(iow_t *child, int compress_level); 200 203 iow_t *lzo_wopen(iow_t *child, int compress_level); 204 iow_t *lzma_wopen(iow_t *child, int compress_level); 201 205 iow_t *thread_wopen(iow_t *child); 202 206 iow_t *stdio_wopen(const char *filename, int fileflags); … … 211 215 * 212 216 * @{ */ 217 218 /** Given a string describing the compression method, finds the internal 219 * data structure representing that method. This is mostly useful for 220 * nicely mapping a method name to the internal libwandio compression 221 * method enum when configuring an output file. 222 * 223 * @param name The compression method name as a string, e.g. "gzip", 224 * "bzip2", "lzo" or "lzma". 225 * @return A pointer to the compression_type structure representing the 226 * compression method or NULL if no match can be found. 227 * 228 */ 229 struct wandio_compression_type *wandio_lookup_compression_type(const char *name); 213 230 214 231 /** Creates a new libtrace IO reader and opens the provided file for reading. -
libwandio/wcat.c
r0e46fbc rd19ff50 6 6 #include <string.h> 7 7 8 static void printhelp() { 9 printf("wandiocat: concatenate files into a single compressed file\n"); 10 printf("\n"); 11 printf("Available options:\n\n"); 12 printf(" -z <level>\n"); 13 printf(" Sets a compression level for the output file, must be \n"); 14 printf(" between 0 (uncompressed) and 9 (max compression)\n"); 15 printf(" Default is 0.\n"); 16 printf(" -Z <method>\n"); 17 printf(" Set the compression method. Must be one of 'gzip', \n"); 18 printf(" 'bzip2', 'lzo' or 'lzma'. If not specified, no\n"); 19 printf(" compression is performed.\n"); 20 printf(" -o <file>\n"); 21 printf(" The name of the output file. If not specified, output\n"); 22 printf(" is written to standard output.\n"); 23 } 24 25 8 26 int main(int argc, char *argv[]) 9 27 { 10 int compress_level = 0; 11 int compress_type = WANDIO_COMPRESS_NONE; 12 char *output = "-"; 13 char c; 14 while ((c = getopt (argc, argv, "Z:z:o:")) != -1) { 15 switch (c) 16 { 17 case 'Z': 18 compress_type = wandio_lookup_compression_type(optarg) 19 ->compress_type; 20 break; 21 case 'z': 22 compress_level = atoi(optarg); 23 break; 24 case 'o': 25 output = optarg; 26 break; 27 case '?': 28 if (optopt == 'Z' || optopt == 'z' || optopt == 'o') 29 fprintf (stderr, "Option -%c requires an argument.\n", optopt); 30 else if (isprint (optopt)) 31 fprintf (stderr, "Unknown option `-%c'.\n", optopt); 32 else 33 fprintf (stderr, 34 "Unknown option character `\\x%x'.\n", 35 optopt); 36 return 1; 37 default: 38 abort (); 39 } 40 } 41 42 iow_t *iow = wandio_wcreate(output, compress_type, compress_level, 0); 43 /* stdout */ 44 int i; 45 for(i=optind; i<argc; ++i) { 46 char buffer[1024*1024]; 47 io_t *ior = wandio_create(argv[i]); 48 if (!ior) { 49 fprintf(stderr, "Failed to open %s\n", argv[i]); 50 continue; 28 int compress_level = 0; 29 int compress_type = WANDIO_COMPRESS_NONE; 30 char *output = "-"; 31 char c; 32 while ((c = getopt (argc, argv, "Z:z:o:h")) != -1) { 33 switch (c) 34 { 35 case 'Z': 36 compress_type = wandio_lookup_compression_type(optarg) 37 ->compress_type; 38 break; 39 case 'z': 40 compress_level = atoi(optarg); 41 break; 42 case 'o': 43 output = optarg; 44 break; 45 case 'h': 46 printhelp(); 47 return 0; 48 case '?': 49 if (optopt == 'Z' || optopt == 'z' || optopt == 'o') 50 fprintf (stderr, "Option -%c requires an argument.\n", optopt); 51 else if (isprint (optopt)) 52 fprintf (stderr, "Unknown option `-%c'.\n", optopt); 53 else 54 fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); 55 return 1; 56 default: 57 abort (); 58 } 51 59 } 52 60 53 off_t len; 54 do { 55 len = wandio_read(ior, buffer, sizeof(buffer)); 56 if (len > 0) 57 wandio_wwrite(iow, buffer, len); 58 } while(len > 0); 61 iow_t *iow = wandio_wcreate(output, compress_type, compress_level, 0); 62 /* stdout */ 63 int i; 64 for(i=optind; i<argc; ++i) { 65 char buffer[1024*1024]; 66 io_t *ior = wandio_create(argv[i]); 67 if (!ior) { 68 fprintf(stderr, "Failed to open %s\n", argv[i]); 69 continue; 70 } 59 71 60 wandio_destroy(ior); 61 } 62 wandio_wdestroy(iow); 63 return 0; 72 off_t len; 73 do { 74 len = wandio_read(ior, buffer, sizeof(buffer)); 75 if (len > 0) 76 wandio_wwrite(iow, buffer, len); 77 } while(len > 0); 78 79 wandio_destroy(ior); 80 } 81 wandio_wdestroy(iow); 82 return 0; 64 83 }
Note: See TracChangeset
for help on using the changeset viewer.