mspack_rb 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/mspack_native/chm_decompressor.c +4 -7
- data/ext/mspack_native/io_system.c +29 -54
- data/ext/mspack_native/io_system.h +0 -4
- data/lib/mspack/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d95c98f63d77452303839ff28381a303748b7ef
|
4
|
+
data.tar.gz: be1332875b3b16279ef38f24d729afd113221362
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de94dacd83888f31544b2343b091996730ce4326020a200630c37eb651727f12c9c8101cb4a1b3c6c394b3fd2deac4342eefbbcf6996a2990e4a6648d8d02fe8
|
7
|
+
data.tar.gz: e768f570b844cd92a7793ba5d51f8a3e08a1181fa0e0d58a476cfcd57c1b337d3eeb643dbc2da873349c4a333a02b4abad0e5f8d8b82b66018e4fbe59a940c6d
|
@@ -146,13 +146,10 @@ VALUE chmd_extract_to_path(int argc, VALUE* argv, VALUE self) {
|
|
146
146
|
|
147
147
|
if (argc == 1) {
|
148
148
|
rb_need_block();
|
149
|
-
|
150
|
-
VALUE block;
|
151
|
-
|
152
|
-
|
153
|
-
VALUE blockName = rb_funcall(block, rb_intern("to_s"), 0);
|
154
|
-
pathStr = StringValueCStr(blockName);
|
155
|
-
add_block(&blockName, &block);
|
149
|
+
VALUE block = rb_block_proc();
|
150
|
+
VALUE block_name = rb_funcall(block, rb_intern("object_id"), 0);
|
151
|
+
VALUE block_name_str = rb_funcall(block_name, rb_intern("to_s"), 0);
|
152
|
+
pathStr = StringValueCStr(block_name_str);
|
156
153
|
}
|
157
154
|
else {
|
158
155
|
Check_Type(outputPath, T_STRING);
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#include "io_system.h"
|
2
2
|
#include "chm_decompressor.h"
|
3
3
|
|
4
|
+
#include <ruby.h>
|
5
|
+
|
4
6
|
#include <stdarg.h>
|
5
7
|
#include <stdio.h>
|
6
8
|
#include <string.h>
|
@@ -9,43 +11,21 @@
|
|
9
11
|
|
10
12
|
union io_file_value {
|
11
13
|
FILE *file;
|
12
|
-
VALUE
|
14
|
+
VALUE block;
|
13
15
|
};
|
14
16
|
|
15
17
|
struct io_file {
|
16
|
-
|
18
|
+
int is_block;
|
17
19
|
union io_file_value value;
|
18
20
|
};
|
19
21
|
|
20
|
-
struct io_file *blocks[IO_SYSTEM_MAX_BLOCKS];
|
21
|
-
|
22
|
-
inline struct io_file *pop_block(const char *name) {
|
23
|
-
for (int i = 0; i < IO_SYSTEM_MAX_BLOCKS - 1; ++i) {
|
24
|
-
struct io_file *block = blocks[i];
|
25
|
-
|
26
|
-
if (block) {
|
27
|
-
if (strcmp(name, block->name) == 0) {
|
28
|
-
blocks[i] = NULL;
|
29
|
-
return block;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
return NULL;
|
35
|
-
}
|
36
|
-
|
37
22
|
struct mspack_file *
|
38
23
|
io_open(struct mspack_system *self, const char *filename, int mode) {
|
39
|
-
|
40
|
-
|
41
|
-
if (mode != MSPACK_SYS_OPEN_READ) {
|
42
|
-
block = pop_block(filename);
|
24
|
+
if (strlen(filename) < 1) {
|
25
|
+
return NULL;
|
43
26
|
}
|
44
27
|
|
45
|
-
if (
|
46
|
-
return (struct mspack_file *)block;
|
47
|
-
}
|
48
|
-
else {
|
28
|
+
if (filename[0] == '/') {
|
49
29
|
const char *modeStr;
|
50
30
|
|
51
31
|
switch (mode) {
|
@@ -67,7 +47,7 @@ io_open(struct mspack_system *self, const char *filename, int mode) {
|
|
67
47
|
|
68
48
|
struct io_file *file = malloc(sizeof(struct io_file));
|
69
49
|
file->value.file = fopen(filename, modeStr);
|
70
|
-
file->
|
50
|
+
file->is_block = 0;
|
71
51
|
|
72
52
|
if (file->value.file) {
|
73
53
|
return (struct mspack_file *)file;
|
@@ -77,15 +57,29 @@ io_open(struct mspack_system *self, const char *filename, int mode) {
|
|
77
57
|
return NULL;
|
78
58
|
}
|
79
59
|
}
|
60
|
+
|
61
|
+
else {
|
62
|
+
VALUE block_id_str = rb_str_new_cstr(filename);
|
63
|
+
VALUE block_id = rb_funcall(block_id_str, rb_intern("to_i"), 0);
|
64
|
+
VALUE object_space = rb_const_get(rb_cModule, rb_intern("ObjectSpace"));
|
65
|
+
VALUE block = rb_funcall(object_space, rb_intern("_id2ref"), 1, block_id);
|
66
|
+
|
67
|
+
if (block == Qnil) {
|
68
|
+
return NULL;
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
struct io_file *file = malloc(sizeof(struct io_file));
|
72
|
+
file->value.block = block;
|
73
|
+
file->is_block = 1;
|
74
|
+
return (struct mspack_file *)file;
|
75
|
+
}
|
76
|
+
}
|
80
77
|
}
|
81
78
|
|
82
79
|
void io_close(struct mspack_file *file) {
|
83
|
-
if (!((struct io_file *)file)->
|
80
|
+
if (!((struct io_file *)file)->is_block) {
|
84
81
|
fclose(((struct io_file *)file)->value.file);
|
85
82
|
}
|
86
|
-
else {
|
87
|
-
free(((struct io_file *)file)->name);
|
88
|
-
}
|
89
83
|
|
90
84
|
free(file);
|
91
85
|
}
|
@@ -95,15 +89,13 @@ int io_read(struct mspack_file *file, void *buffer, int bytes) {
|
|
95
89
|
}
|
96
90
|
|
97
91
|
int io_write(struct mspack_file *file, void *buffer, int bytes) {
|
98
|
-
if (!((struct io_file *)file)->
|
92
|
+
if (!((struct io_file *)file)->is_block) {
|
99
93
|
return (int)fwrite(buffer, 1, bytes, ((struct io_file *)file)->value.file);
|
100
94
|
}
|
101
95
|
else {
|
102
96
|
VALUE data = rb_str_new((char *)buffer, bytes);
|
103
|
-
|
104
|
-
|
105
|
-
block = ((struct io_file *)file)->value.block;
|
106
|
-
rb_funcall(*block, rb_intern("yield"), 1, data);
|
97
|
+
VALUE block = ((struct io_file *)file)->value.block;
|
98
|
+
rb_funcall(block, rb_intern("yield"), 1, data);
|
107
99
|
return bytes;
|
108
100
|
}
|
109
101
|
}
|
@@ -150,20 +142,3 @@ struct mspack_system *io_system() {
|
|
150
142
|
system->null_ptr = NULL;
|
151
143
|
return system;
|
152
144
|
}
|
153
|
-
|
154
|
-
// TODO: chuck an error if we're full
|
155
|
-
void add_block(VALUE *name, VALUE *block) {
|
156
|
-
for (int i = 0; i < IO_SYSTEM_MAX_BLOCKS - 1; ++i) {
|
157
|
-
|
158
|
-
if (!blocks[i]) {
|
159
|
-
struct io_file *file = malloc(sizeof(struct io_file));
|
160
|
-
file->value.block = block;
|
161
|
-
|
162
|
-
const char *nameStr = StringValueCStr(*name);
|
163
|
-
file->name = malloc(sizeof(char) * strlen(nameStr) + 1);
|
164
|
-
strcpy(file->name, nameStr);
|
165
|
-
|
166
|
-
blocks[i] = file;
|
167
|
-
}
|
168
|
-
}
|
169
|
-
}
|
@@ -2,7 +2,6 @@
|
|
2
2
|
#define IO_SYSTEM_H
|
3
3
|
|
4
4
|
#include <mspack.h>
|
5
|
-
#include <ruby.h>
|
6
5
|
|
7
6
|
struct mspack_file *
|
8
7
|
io_open(struct mspack_system *self, const char *filename, int mode);
|
@@ -25,9 +24,6 @@ void io_free(void *ptr);
|
|
25
24
|
|
26
25
|
void io_copy(void *src, void *dest, size_t bytes);
|
27
26
|
|
28
|
-
|
29
27
|
struct mspack_system *io_system();
|
30
28
|
|
31
|
-
void add_block(VALUE *name, VALUE *block);
|
32
|
-
|
33
29
|
#endif
|
data/lib/mspack/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mspack_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|