Changeset 28994

Show
Ignore:
Timestamp:
01/25/09 12:02:21 (4 years ago)
Author:
winebarrel
Message:

外部プログラムでの圧縮を一応サポート。
Windowsは未対応。。。

Location:
lang/ruby/libarchive/trunk/ext
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/libarchive/trunk/ext/libarchive_reader.c

    r28539 r28994  
    2121} 
    2222 
    23 static VALUE rb_libarchive_reader_s_open0(int (*archive_open)(struct rb_libarchive_archive_container *, void *), void *arg, int compression, int format) { 
     23static VALUE rb_libarchive_reader_s_open0(int (*archive_open)(struct rb_libarchive_archive_container *, void *), void *arg, int compression, int format, const char *cmd) { 
    2424  VALUE reader; 
    2525  struct rb_libarchive_archive_container *p; 
     
    3232  } 
    3333 
    34   if (compression != -1) { 
     34  if (cmd != NULL) { 
     35    r = archive_read_support_compression_program(p->ar, cmd); 
     36  } else if (compression != -1) { 
    3537    r = archive_read_support_compression(p->ar, compression); 
    3638  } else { 
     
    101103  const char *filename = NULL; 
    102104  int compression = -1, format = -1; 
     105  const char *cmd; 
    103106  rb_scan_args(argc, argv, "12", &v_filename, &v_compression, &v_format); 
    104107  Check_Type(v_filename, T_STRING); 
    105108  filename = RSTRING_PTR(v_filename); 
    106109 
    107   if (!NIL_P(v_compression)) { 
     110  if (T_STRING == TYPE(v_compression)) { 
     111    compression = -1; 
     112    cmd = RSTRING_PTR(v_compression); 
     113  } else if (!NIL_P(v_compression)) { 
    108114    compression = NUM2INT(v_compression); 
    109115  } 
     
    113119  } 
    114120 
    115   return rb_libarchive_reader_s_open0(rb_libarchive_reader_s_open_filename0, (void *) filename, compression, format); 
     121  return rb_libarchive_reader_s_open0(rb_libarchive_reader_s_open_filename0, (void *) filename, compression, format, cmd); 
    116122} 
    117123 
     
    125131  VALUE v_memory, v_compression, v_format; 
    126132  int compression = -1, format = -1; 
     133  const char *cmd; 
    127134  rb_scan_args(argc, argv, "12", &v_memory, &v_compression, &v_format); 
    128135  Check_Type(v_memory, T_STRING); 
    129136 
    130   if (!NIL_P(v_compression)) { 
     137  if (T_STRING == TYPE(v_compression)) { 
     138    compression = -1; 
     139    cmd = RSTRING_PTR(v_compression); 
     140  } else if (!NIL_P(v_compression)) { 
    131141    compression = NUM2INT(v_compression); 
    132142  } 
     
    136146  } 
    137147 
    138   return rb_libarchive_reader_s_open0(rb_libarchive_reader_s_open_memory0, (void *) v_memory, compression, format); 
     148  return rb_libarchive_reader_s_open0(rb_libarchive_reader_s_open_memory0, (void *) v_memory, compression, format, cmd); 
    139149} 
    140150 
  • lang/ruby/libarchive/trunk/ext/libarchive_writer.c

    r28542 r28994  
    2121} 
    2222 
    23 static VALUE rb_libarchive_writer_s_open0(int (*archive_open)(struct rb_libarchive_archive_container *, void *), void *arg, int compression, int format) { 
     23static VALUE rb_libarchive_writer_s_open0(int (*archive_open)(struct rb_libarchive_archive_container *, void *), void *arg, int compression, int format, const char *cmd) { 
    2424  VALUE writer; 
    2525  struct rb_libarchive_archive_container *p; 
     26  int r; 
    2627  writer = rb_funcall(rb_cArchiveWriter, rb_intern("new"), 0); 
    2728  Data_Get_Struct(writer, struct rb_libarchive_archive_container, p); 
     
    3132  } 
    3233 
    33   if (archive_write_set_compression(p->ar, compression) != ARCHIVE_OK) { 
     34  if (cmd != NULL) { 
     35    r = archive_write_set_compression_program(p->ar,  cmd); 
     36  } else { 
     37    r = archive_write_set_compression(p->ar, compression); 
     38  } 
     39 
     40  if (r != ARCHIVE_OK) { 
    3441    char error_string[BUFSIZ]; 
    3542    archive_copy_error_string(p->ar, error_string, BUFSIZ); 
     
    7784  const char *filename = NULL; 
    7885  int compression, format; 
     86  const char *cmd = NULL; 
    7987  Check_Type(v_filename, T_STRING); 
    8088 
     
    8492 
    8593  filename = RSTRING_PTR(v_filename); 
    86   compression = NUM2INT(v_compression); 
     94 
     95  if (T_STRING == TYPE(v_compression)) { 
     96    compression = -1; 
     97    cmd = RSTRING_PTR(v_compression); 
     98  } else { 
     99    compression = NUM2INT(v_compression); 
     100  } 
     101 
     102 
    87103  format = NUM2INT(v_format); 
    88   return rb_libarchive_writer_s_open0(rb_libarchive_writer_s_open_filename0, (void *) filename, compression, format); 
     104  return rb_libarchive_writer_s_open0(rb_libarchive_writer_s_open_filename0, (void *) filename, compression, format, cmd); 
    89105} 
    90106 
     
    98114static VALUE rb_libarchive_writer_s_open_memory(VALUE self, VALUE v_memory, VALUE v_compression, VALUE v_format) { 
    99115  int compression, format; 
     116  const char *cmd = NULL; 
    100117  Check_Type(v_memory, T_STRING); 
    101   compression = NUM2INT(v_compression); 
     118 
     119  if (T_STRING == TYPE(v_compression)) { 
     120    compression = -1; 
     121    cmd = RSTRING_PTR(v_compression); 
     122  } else { 
     123    compression = NUM2INT(v_compression); 
     124  } 
     125 
    102126  format = NUM2INT(v_format); 
    103   return rb_libarchive_writer_s_open0(rb_libarchive_writer_s_open_memory0, (void *) v_memory, compression, format); 
     127  return rb_libarchive_writer_s_open0(rb_libarchive_writer_s_open_memory0, (void *) v_memory, compression, format, cmd); 
    104128} 
    105129