mahoro 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/GNUmakefile +63 -0
- data/INSTALL +24 -2
- data/README +16 -0
- data/{extconf.rb → ext/mahoro/extconf.rb} +2 -0
- data/ext/mahoro/mahoro.c +565 -0
- data/ext/mahoro/nogvl_compat.h +54 -0
- data/lib/mahoro/thread_safe.rb +45 -0
- data/mahoro.gemspec +6 -5
- data/setup.rb +1586 -0
- data/{test.rb → test/test_mahoro.rb} +35 -9
- metadata +44 -42
- data/mahoro.c +0 -320
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8e34a0f3eb2e9f8f9cebd7e149fc91188fe75cd8
|
4
|
+
data.tar.gz: b47106cf51c0f7aedab8a471c292f90684a301e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d64e5576704b93552e4f89b2712ae9890862df5e3ed479ecd8d3d2906765e2db263e1ca7f2f85e563043550b4aacaad98013240498b60cf6d2f977ba8448b48b
|
7
|
+
data.tar.gz: d3a9f511611377d7561751d317a015a9ad964245731d15ea130453db0ac2143c90fe4db68a1652d0cb222b0d0a91927f6a7657fa0038e1c71341c9e5bd5a8aa4
|
data/.gitignore
ADDED
data/GNUmakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# maintainer jobs here, not needed for normal users
|
2
|
+
all::
|
3
|
+
|
4
|
+
.ri/created.rid: ext/mahoro/mahoro.c lib/mahoro/thread_safe.rb
|
5
|
+
rdoc --ri -o $(@D) $^
|
6
|
+
|
7
|
+
order =
|
8
|
+
order += Mahoro
|
9
|
+
order += Mahoro.new
|
10
|
+
order += Mahoro\#file
|
11
|
+
order += Mahoro\#buffer
|
12
|
+
order += Mahoro\#flags=
|
13
|
+
order += Mahoro\#valid?
|
14
|
+
order += Mahoro\#compile
|
15
|
+
order += Mahoro.compile
|
16
|
+
order += Mahoro::ThreadSafe
|
17
|
+
|
18
|
+
www/API: .ri/created.rid
|
19
|
+
( \
|
20
|
+
for i in $(order); \
|
21
|
+
do \
|
22
|
+
ri --no-standard-docs -T -d .ri -w 80 "$$i" \
|
23
|
+
| col -b \
|
24
|
+
| grep -vF $(CURDIR)/.ri; \
|
25
|
+
done \
|
26
|
+
) > $@
|
27
|
+
|
28
|
+
www/API.gz: www/API
|
29
|
+
gzip < $< > $@
|
30
|
+
touch -r $< $@
|
31
|
+
|
32
|
+
www/README.gz: README
|
33
|
+
install -p -m 644 README www/
|
34
|
+
gzip < $< > $@
|
35
|
+
touch -r $< $@
|
36
|
+
|
37
|
+
all:: www/API.gz www/README.gz
|
38
|
+
clean:
|
39
|
+
$(RM) www/*
|
40
|
+
|
41
|
+
ifneq ($(VERSION),)
|
42
|
+
gem := mahoro-$(VERSION).gem
|
43
|
+
$(gem): $(shell git ls-files)
|
44
|
+
VERSION=$(VERSION) gem build mahoro.gemspec
|
45
|
+
|
46
|
+
tgz := mahoro-$(VERSION).tar.gz
|
47
|
+
$(tgz): $(shell git ls-files)
|
48
|
+
git archive --format=tar --prefix=mahoro-$(VERSION)/ HEAD | \
|
49
|
+
gzip -9 > $@
|
50
|
+
else
|
51
|
+
gem tgz:
|
52
|
+
@echo >&2 error VERSION not defined
|
53
|
+
@false
|
54
|
+
endif
|
55
|
+
|
56
|
+
package: $(gem) $(tgz)
|
57
|
+
|
58
|
+
RSYNC = rsync
|
59
|
+
publish_doc: all
|
60
|
+
$(RSYNC) --delete --exclude .gitignore -av \
|
61
|
+
www/ dcvr:/srv/bogomips/mahoro/
|
62
|
+
|
63
|
+
.PHONY: publish_doc package
|
data/INSTALL
CHANGED
@@ -1,5 +1,27 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
libmagic installation
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Mahoro is a wrapper around libmagic[1], so it needs the libmagic
|
5
|
+
development headers and libraries to run. If your operating system
|
6
|
+
provides libmagic development libraries and headers, you will not need
|
7
|
+
the "--with-magic*" command-line options below.
|
8
|
+
|
9
|
+
For Debian-based systems: apt-get install libmagic-dev
|
10
|
+
For CentOS 6.x or similar RPM-based systems: yum install file-devel
|
11
|
+
For CentOS 5.x or similar RPM-based systems: yum install file
|
12
|
+
|
13
|
+
[1] - https://en.wikipedia.org/wiki/Libmagic
|
14
|
+
|
15
|
+
INSTALL (from RubyGems)
|
16
|
+
=======================
|
17
|
+
|
18
|
+
The installation is simple, install libmagic and type the following:
|
19
|
+
|
20
|
+
# gem install mahoro -- --with-magic-include=/path/to/include \
|
21
|
+
--with-magic-lib=/path/to/lib
|
22
|
+
|
23
|
+
INSTALL (from tarball)
|
24
|
+
======================
|
3
25
|
|
4
26
|
The installation is simple, install libmagic and type the following.
|
5
27
|
|
data/README
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Mahoro - a Ruby interface to libmagic
|
2
|
+
|
3
|
+
An interface to libmagic to determine file types using "magic" numbers.
|
4
|
+
This can be used in place of calling the file(1) command in Ruby scripts.
|
5
|
+
Shu-yu Guo is the original author but all maintenance is handled by
|
6
|
+
Eric Wong nowadays.
|
7
|
+
|
8
|
+
documentation: http://bogomips.org/mahoro/API
|
9
|
+
source: git clone git://bogomips.org/mahoro.git
|
10
|
+
cgit web viewer: http://bogomips.org/mahoro.git/
|
11
|
+
mailing list: mahoro@librelist.org (plain-text only, please)
|
12
|
+
maintainer: Eric Wong <normalperson@yhbt.net>
|
13
|
+
libmagic: https://en.wikipedia.org/wiki/Libmagic
|
14
|
+
|
15
|
+
Feel free to contact Eric Wong privately via plain-text email if you're not
|
16
|
+
comfortable with the public mailing list.
|
data/ext/mahoro/mahoro.c
ADDED
@@ -0,0 +1,565 @@
|
|
1
|
+
/*
|
2
|
+
* This file is Public Domain.
|
3
|
+
*
|
4
|
+
* Note: The current maintainer (Eric Wong) respects and preserves the
|
5
|
+
* original coding style of the original author (Shu-yu Guo) in case
|
6
|
+
* he ever chooses to return to this project.
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <ruby.h>
|
10
|
+
#include <magic.h>
|
11
|
+
#include "nogvl_compat.h"
|
12
|
+
|
13
|
+
#ifndef RSTRING_LEN
|
14
|
+
# define RSTRING_LEN(s)->len
|
15
|
+
#endif
|
16
|
+
#ifndef RSTRING_PTR
|
17
|
+
# define RSTRING_PTR(s)->ptr
|
18
|
+
#endif
|
19
|
+
|
20
|
+
static VALUE eMahoroError;
|
21
|
+
static ID id_to_path;
|
22
|
+
|
23
|
+
struct nogvl_args {
|
24
|
+
magic_t cookie;
|
25
|
+
union {
|
26
|
+
const char *path;
|
27
|
+
int fd;
|
28
|
+
} as;
|
29
|
+
};
|
30
|
+
|
31
|
+
/* :nodoc: called automatically by GC */
|
32
|
+
static void
|
33
|
+
mahoro_free(ptr)
|
34
|
+
void *ptr;
|
35
|
+
{
|
36
|
+
if (ptr)
|
37
|
+
magic_close((magic_t)ptr);
|
38
|
+
}
|
39
|
+
|
40
|
+
/* :nodoc: called automatically on Mahoro#initialize */
|
41
|
+
static VALUE
|
42
|
+
mahoro_allocate(klass)
|
43
|
+
VALUE klass;
|
44
|
+
{
|
45
|
+
return Data_Wrap_Struct(klass, 0, mahoro_free, 0);
|
46
|
+
}
|
47
|
+
|
48
|
+
static void *
|
49
|
+
nogvl_load(ptr)
|
50
|
+
void *ptr;
|
51
|
+
{
|
52
|
+
struct nogvl_args *args = ptr;
|
53
|
+
|
54
|
+
return magic_load(args->cookie, args->as.path) ? ptr : NULL;
|
55
|
+
}
|
56
|
+
|
57
|
+
/*
|
58
|
+
* call-seq:
|
59
|
+
* Mahoro.new(flags = Mahoro::NONE, path = nil) -> mahoro_obj
|
60
|
+
*
|
61
|
+
* Create and initialize a new Mahoro object.
|
62
|
+
* +flags+ may be one or more of any combination of the Mahoro:: constants
|
63
|
+
* supported by Mahoro#flags=.
|
64
|
+
* +path+ (if not nil) is a colon-separated list of database files, see
|
65
|
+
* Mahoro#load.
|
66
|
+
*
|
67
|
+
* If +path+ is not given (or nil), the default database is used.
|
68
|
+
* Consult your libmagic(3) documentation for the location of that file
|
69
|
+
* as it varies by installation.
|
70
|
+
*/
|
71
|
+
static VALUE
|
72
|
+
mahoro_initialize(argc, argv, self)
|
73
|
+
int argc;
|
74
|
+
VALUE *argv, self;
|
75
|
+
{
|
76
|
+
int flags = MAGIC_NONE;
|
77
|
+
struct nogvl_args args;
|
78
|
+
VALUE vpath, vflags;
|
79
|
+
|
80
|
+
args.as.path = NULL;
|
81
|
+
|
82
|
+
switch(rb_scan_args(argc, argv, "02", &vflags, &vpath)) {
|
83
|
+
case 2:
|
84
|
+
if(!NIL_P(vpath)) {
|
85
|
+
args.as.path = StringValueCStr(vpath);
|
86
|
+
}
|
87
|
+
/* fallthrough */
|
88
|
+
case 1:
|
89
|
+
flags = FIX2INT(vflags);
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
|
93
|
+
if(!(args.cookie = magic_open(flags))) {
|
94
|
+
rb_raise(eMahoroError, "failed to initialize magic cookie");
|
95
|
+
}
|
96
|
+
|
97
|
+
if(NOGVL(nogvl_load, &args, RUBY_UBF_IO, NULL)) {
|
98
|
+
rb_raise(eMahoroError, "failed to load database: %s",
|
99
|
+
magic_error(args.cookie));
|
100
|
+
}
|
101
|
+
|
102
|
+
DATA_PTR(self) = args.cookie;
|
103
|
+
|
104
|
+
return self;
|
105
|
+
}
|
106
|
+
|
107
|
+
static void *
|
108
|
+
nogvl_file(ptr)
|
109
|
+
void *ptr;
|
110
|
+
{
|
111
|
+
struct nogvl_args *args = ptr;
|
112
|
+
|
113
|
+
return (void *)magic_file(args->cookie, args->as.path);
|
114
|
+
}
|
115
|
+
|
116
|
+
/*
|
117
|
+
* call-seq:
|
118
|
+
* mahoro_obj.file(filename) -> String
|
119
|
+
*
|
120
|
+
* Returns a textual description of the contents of the +filename+ given.
|
121
|
+
* Use Mahoro#buffer instead of this method if the contents of your
|
122
|
+
* file is already in memory.
|
123
|
+
* Raises Mahoro::Error on failed lookups.
|
124
|
+
*/
|
125
|
+
static VALUE
|
126
|
+
mahoro_file(self, path)
|
127
|
+
VALUE self, path;
|
128
|
+
{
|
129
|
+
const char *msg;
|
130
|
+
struct nogvl_args args;
|
131
|
+
|
132
|
+
args.cookie = (magic_t)DATA_PTR(self);
|
133
|
+
|
134
|
+
/* Pathname objects may be transformed via #to_path */
|
135
|
+
if (rb_respond_to(path, id_to_path))
|
136
|
+
path = rb_funcall(path, id_to_path, 0);
|
137
|
+
|
138
|
+
args.as.path = StringValueCStr(path);
|
139
|
+
|
140
|
+
if(!(msg = NOGVL(nogvl_file, &args, RUBY_UBF_IO, NULL))) {
|
141
|
+
rb_raise(eMahoroError, "failed lookup: %s",
|
142
|
+
magic_error(args.cookie));
|
143
|
+
}
|
144
|
+
|
145
|
+
return rb_str_new2(msg);
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* call-seq:
|
150
|
+
* mahoro_obj.buffer(buffer) -> String
|
151
|
+
*
|
152
|
+
* Returns a textual description of the contents of the +buffer+ given.
|
153
|
+
* +buffer+ should be a String object.
|
154
|
+
* Use Mahoro#file instead of this method if the contents is not already
|
155
|
+
* in memory (and possibly too large to fit into memory).
|
156
|
+
* Raises Mahoro::Error on failed lookups.
|
157
|
+
*/
|
158
|
+
static VALUE
|
159
|
+
mahoro_buffer(self, input)
|
160
|
+
VALUE self, input;
|
161
|
+
{
|
162
|
+
const char *msg;
|
163
|
+
magic_t cookie = (magic_t)DATA_PTR(self);
|
164
|
+
|
165
|
+
StringValue(input);
|
166
|
+
|
167
|
+
if(!(msg = magic_buffer(cookie, RSTRING_PTR(input),
|
168
|
+
RSTRING_LEN(input)))) {
|
169
|
+
rb_raise(eMahoroError, "failed lookup: %s", magic_error(cookie));
|
170
|
+
}
|
171
|
+
|
172
|
+
return rb_str_new2(msg);
|
173
|
+
}
|
174
|
+
|
175
|
+
/*
|
176
|
+
* call-seq:
|
177
|
+
* mahoro_obj.flags = flags
|
178
|
+
*
|
179
|
+
* Change the behavior of an already-initialized Mahoro object. The
|
180
|
+
* behavior of a Mahoro object is specified at load time, but may be
|
181
|
+
* changed after-the-fact.
|
182
|
+
* +flags+ is a bitwise (OR) mask of one or more of the following constants
|
183
|
+
* in the Mahoro namespace:
|
184
|
+
*
|
185
|
+
* - APPLE
|
186
|
+
* - CHECK
|
187
|
+
* - COMPRESS
|
188
|
+
* - CONTINUE
|
189
|
+
* - DEBUG
|
190
|
+
* - DEVICES
|
191
|
+
* - ERROR
|
192
|
+
* - MIME
|
193
|
+
* - MIME_ENCODING
|
194
|
+
* - MIME_TYPE
|
195
|
+
* - NONE
|
196
|
+
* - NO_CHECK_APPTYPE
|
197
|
+
* - NO_CHECK_COMPRESS
|
198
|
+
* - NO_CHECK_ELF
|
199
|
+
* - NO_CHECK_ENCODING
|
200
|
+
* - NO_CHECK_SOFT
|
201
|
+
* - NO_CHECK_TAR
|
202
|
+
* - NO_CHECK_TEXT
|
203
|
+
* - NO_CHECK_TOKENS
|
204
|
+
* - PRESERVE_ATIME
|
205
|
+
* - RAW
|
206
|
+
* - SYMLINK
|
207
|
+
*/
|
208
|
+
static VALUE
|
209
|
+
mahoro_set_flags(self, flags)
|
210
|
+
VALUE self, flags;
|
211
|
+
{
|
212
|
+
magic_t cookie = (magic_t)DATA_PTR(self);
|
213
|
+
|
214
|
+
return INT2FIX(magic_setflags(cookie, FIX2INT(flags)));
|
215
|
+
}
|
216
|
+
|
217
|
+
static void *
|
218
|
+
nogvl_check(ptr)
|
219
|
+
void *ptr;
|
220
|
+
{
|
221
|
+
struct nogvl_args *args = ptr;
|
222
|
+
|
223
|
+
return magic_check(args->cookie, args->as.path) ? ptr : NULL;
|
224
|
+
}
|
225
|
+
|
226
|
+
/*
|
227
|
+
* call-seq:
|
228
|
+
* mahoro_obj.check(path = nil) -> true or false
|
229
|
+
*
|
230
|
+
* This is used to check the validity of entries in the colon separated
|
231
|
+
* database files passed in as +path+. If +path+ is not passed (or nil),
|
232
|
+
* this will check the default database.
|
233
|
+
*/
|
234
|
+
static VALUE
|
235
|
+
mahoro_check(argc, argv, self)
|
236
|
+
int argc;
|
237
|
+
VALUE *argv, self;
|
238
|
+
{
|
239
|
+
struct nogvl_args args;
|
240
|
+
VALUE vpath;
|
241
|
+
|
242
|
+
args.cookie = (magic_t)DATA_PTR(self);
|
243
|
+
args.as.path = NULL;
|
244
|
+
|
245
|
+
switch(rb_scan_args(argc, argv, "01", &vpath)) {
|
246
|
+
case 1:
|
247
|
+
if(!NIL_P(vpath)) {
|
248
|
+
args.as.path = StringValueCStr(vpath);
|
249
|
+
}
|
250
|
+
break;
|
251
|
+
}
|
252
|
+
|
253
|
+
if(!NOGVL(nogvl_check, &args, RUBY_UBF_IO, 0)) {
|
254
|
+
return Qtrue;
|
255
|
+
} else {
|
256
|
+
return Qfalse;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
static void *
|
261
|
+
nogvl_compile(ptr)
|
262
|
+
void *ptr;
|
263
|
+
{
|
264
|
+
struct nogvl_args *args = ptr;
|
265
|
+
|
266
|
+
return magic_compile(args->cookie, args->as.path) ? ptr : NULL;
|
267
|
+
}
|
268
|
+
|
269
|
+
/*
|
270
|
+
* call-seq:
|
271
|
+
* mahoro_obj.compile(path) -> true
|
272
|
+
*
|
273
|
+
* Compile the the colon separated list of database files passed in as +path+.
|
274
|
+
* It returns true on success and raises Mahoro::Error on failure.
|
275
|
+
* Compiled files created are named from the +File.basename+ of each file
|
276
|
+
* argument with ".mgc" appended to it.
|
277
|
+
*
|
278
|
+
* There is no need to use this function if you are using the default magic(5)
|
279
|
+
* database on your operating system. This is only needed if you require
|
280
|
+
* additional magic not in the default magic database.
|
281
|
+
*
|
282
|
+
* Users of this method are likely to need Mahoro#load (and vice-versa).
|
283
|
+
*/
|
284
|
+
static VALUE
|
285
|
+
mahoro_compile(self, path)
|
286
|
+
VALUE self, path;
|
287
|
+
{
|
288
|
+
struct nogvl_args args;
|
289
|
+
|
290
|
+
args.cookie = (magic_t)DATA_PTR(self);
|
291
|
+
args.as.path = StringValueCStr(path);
|
292
|
+
|
293
|
+
if(NOGVL(nogvl_compile, &args, RUBY_UBF_IO, NULL)) {
|
294
|
+
rb_raise(eMahoroError, "failed compile: %s",
|
295
|
+
magic_error(args.cookie));
|
296
|
+
}
|
297
|
+
|
298
|
+
return Qtrue;
|
299
|
+
}
|
300
|
+
|
301
|
+
/*
|
302
|
+
* call-seq:
|
303
|
+
* Mahoro.compile(path) -> true
|
304
|
+
*
|
305
|
+
* This is a wrapper around the Mahoro#compile instance method, but does not
|
306
|
+
* require an existing Mahoro object. Use the instance method unless you only
|
307
|
+
* need to test the validity of a magic(5) database.
|
308
|
+
*/
|
309
|
+
static VALUE
|
310
|
+
mahoro_s_compile(klass, path)
|
311
|
+
VALUE klass, path;
|
312
|
+
{
|
313
|
+
VALUE m = rb_funcall(klass, rb_intern("new"), 0, 0);
|
314
|
+
|
315
|
+
return mahoro_compile(m, path);
|
316
|
+
}
|
317
|
+
|
318
|
+
/*
|
319
|
+
* call-seq:
|
320
|
+
* mahoro_obj.load(path) -> mahoro_obj
|
321
|
+
*
|
322
|
+
* Used to load the the colon-separated list of database files (+path+).
|
323
|
+
* The ".mgc" suffix will be added to each filename where appropriate.
|
324
|
+
* This will raise Mahoro::Error on failure.
|
325
|
+
*
|
326
|
+
* There is no need to use this function if you are using the default magic(5)
|
327
|
+
* database on your operating system. This is only needed if you require
|
328
|
+
* additional magic not in the default magic database.
|
329
|
+
*
|
330
|
+
* The default database file is named by the MAGIC environment variable.
|
331
|
+
* Consult your libmagic installation documentation for the location of
|
332
|
+
* your default database file name.
|
333
|
+
*
|
334
|
+
* Users of this method are likely to need Mahoro#compile (and vice-versa).
|
335
|
+
*/
|
336
|
+
static VALUE
|
337
|
+
mahoro_load(self, path)
|
338
|
+
VALUE self, path;
|
339
|
+
{
|
340
|
+
struct nogvl_args args;
|
341
|
+
|
342
|
+
args.cookie = (magic_t)DATA_PTR(self);
|
343
|
+
args.as.path = StringValueCStr(path);
|
344
|
+
|
345
|
+
if(NOGVL(nogvl_load, &args, RUBY_UBF_IO, NULL)) {
|
346
|
+
rb_raise(eMahoroError, "failed load: %s",
|
347
|
+
magic_error(args.cookie));
|
348
|
+
}
|
349
|
+
|
350
|
+
return self;
|
351
|
+
}
|
352
|
+
|
353
|
+
void Init_mahoro(void)
|
354
|
+
{
|
355
|
+
VALUE cMahoro;
|
356
|
+
/*
|
357
|
+
* Mahoro is a simple interface to libmagic.
|
358
|
+
*
|
359
|
+
* Common use cases:
|
360
|
+
*
|
361
|
+
* # initialize a Mahoro object for reading MIME types
|
362
|
+
* mahoro_obj = Mahoro.new(Mahoro::MIME)
|
363
|
+
*
|
364
|
+
* # get the MIME type of a file on disk
|
365
|
+
* # This is ideal for large files which you do not need to
|
366
|
+
* # read in their entirety.
|
367
|
+
* mahoro_obj.file('/path/to/file.c') -> 'text/x-c'
|
368
|
+
*
|
369
|
+
* # get the MIME type of a string buffer
|
370
|
+
* # This is only ideal if you already have the buffer in
|
371
|
+
* # memory or intend to process it soon
|
372
|
+
* str = File.read('/path/to/file.c')
|
373
|
+
* mahoro_obj.buffer(str) -> 'text/x-c'
|
374
|
+
*
|
375
|
+
* # switch the Mahoro object to return an ASCII description
|
376
|
+
* mahoro_obj.flags = Mahoro::NONE
|
377
|
+
*
|
378
|
+
* # Similar to the above example, but the Mahoro object
|
379
|
+
* # now returns a textual description
|
380
|
+
* mahoro_obj.file('/path/to/file.c') -> 'ASCII C program text'
|
381
|
+
*
|
382
|
+
* # Similar to the above example, but the Mahoro object
|
383
|
+
* # now returns a textual description
|
384
|
+
* str = File.read('/path/to/file.c')
|
385
|
+
* mahoro_obj.buffer(str) -> 'ASCII C program text'
|
386
|
+
*
|
387
|
+
* Mahoro is not thread-safe by default, see Mahoro::ThreadSafe for
|
388
|
+
* making this module thread-safe.
|
389
|
+
*
|
390
|
+
* More information about libmagic:
|
391
|
+
* https://en.wikipedia.org/wiki/Libmagic
|
392
|
+
*
|
393
|
+
* Source code is available via git:
|
394
|
+
* git clone git://bogomips.org/mahoro.git
|
395
|
+
*
|
396
|
+
* And viewable with a web browser via cgit:
|
397
|
+
* http://bogomips.org/mahoro.git
|
398
|
+
*
|
399
|
+
* Eric Wong is the current maintainer of Mahoro.
|
400
|
+
* Plain-text comments, questions, bug reports, patches and
|
401
|
+
* pull requests are all highly welcome on the public mailing list:
|
402
|
+
* mahoro@librelist.org
|
403
|
+
*
|
404
|
+
* You may contact Eric privately at normalperson@yhbt.net
|
405
|
+
*
|
406
|
+
* Please generate patches using the "git format-patch" command.
|
407
|
+
* Use of "git send-email" to send a patch is recommended.
|
408
|
+
* For reviewed patches, you may also send a pull request formatted
|
409
|
+
* using the "git request-pull" command.
|
410
|
+
*
|
411
|
+
* Do not expect Eric to read HTML email under any circumstances.
|
412
|
+
*/
|
413
|
+
cMahoro = rb_define_class("Mahoro", rb_cObject);
|
414
|
+
eMahoroError = rb_define_class_under(cMahoro, "Error", rb_eStandardError);
|
415
|
+
|
416
|
+
/* No special handling, the default */
|
417
|
+
rb_define_const(cMahoro, "NONE", INT2FIX(MAGIC_NONE));
|
418
|
+
|
419
|
+
/* print debugging messages to stderr */
|
420
|
+
rb_define_const(cMahoro, "DEBUG", INT2FIX(MAGIC_DEBUG));
|
421
|
+
|
422
|
+
/* Follow symlinks */
|
423
|
+
rb_define_const(cMahoro, "SYMLINK", INT2FIX(MAGIC_SYMLINK));
|
424
|
+
|
425
|
+
/* Check inside compressed files */
|
426
|
+
rb_define_const(cMahoro, "COMPRESS", INT2FIX(MAGIC_COMPRESS));
|
427
|
+
|
428
|
+
/* Look at the contents of devices */
|
429
|
+
rb_define_const(cMahoro, "DEVICES", INT2FIX(MAGIC_DEVICES));
|
430
|
+
|
431
|
+
#ifdef MAGIC_MIME_TYPE
|
432
|
+
/*
|
433
|
+
* Return only the MIME type
|
434
|
+
* This constant may not be defined on older systems.
|
435
|
+
*/
|
436
|
+
rb_define_const(cMahoro, "MIME_TYPE", INT2FIX(MAGIC_MIME_TYPE));
|
437
|
+
#endif
|
438
|
+
|
439
|
+
/* Return all matches */
|
440
|
+
rb_define_const(cMahoro, "CONTINUE", INT2FIX(MAGIC_CONTINUE));
|
441
|
+
|
442
|
+
/*
|
443
|
+
* Check the magic database for consistency and
|
444
|
+
* print warnings to stderr
|
445
|
+
*/
|
446
|
+
rb_define_const(cMahoro, "CHECK", INT2FIX(MAGIC_CHECK));
|
447
|
+
|
448
|
+
/* preserve access time of files analyzed */
|
449
|
+
rb_define_const(cMahoro, "PRESERVE_ATIME",
|
450
|
+
INT2FIX(MAGIC_PRESERVE_ATIME));
|
451
|
+
|
452
|
+
/*
|
453
|
+
* Don't translate unprintable characters to a \\ooo octal
|
454
|
+
* representation
|
455
|
+
*/
|
456
|
+
rb_define_const(cMahoro, "RAW", INT2FIX(MAGIC_RAW));
|
457
|
+
|
458
|
+
/*
|
459
|
+
* Treat operating system errors while trying to open files
|
460
|
+
* and follow symlinks as real errors, instead of printing
|
461
|
+
* them in the magic buffer.
|
462
|
+
*/
|
463
|
+
rb_define_const(cMahoro, "ERROR", INT2FIX(MAGIC_ERROR));
|
464
|
+
|
465
|
+
#ifdef MAGIC_MIME_ENCODING
|
466
|
+
/*
|
467
|
+
* Return a MIME encoding, instead of a textual description.
|
468
|
+
* This constant may not be defined on older systems.
|
469
|
+
*/
|
470
|
+
rb_define_const(cMahoro, "MIME_ENCODING", INT2FIX(MAGIC_MIME_ENCODING));
|
471
|
+
#endif
|
472
|
+
|
473
|
+
/* return both MIME type and encoding */
|
474
|
+
rb_define_const(cMahoro, "MIME", INT2FIX(MAGIC_MIME));
|
475
|
+
|
476
|
+
#ifdef MAGIC_APPLE
|
477
|
+
/*
|
478
|
+
* Return both Apple creator and type.
|
479
|
+
* This constant may not be defined on older systems.
|
480
|
+
*/
|
481
|
+
rb_define_const(cMahoro, "APPLE", INT2FIX(MAGIC_APPLE));
|
482
|
+
#endif
|
483
|
+
|
484
|
+
#ifdef MAGIC_NO_CHECK_COMPRESS
|
485
|
+
/*
|
486
|
+
* Don't check for or inside compressed files.
|
487
|
+
* This constant may not be defined on older systems.
|
488
|
+
*/
|
489
|
+
rb_define_const(cMahoro, "NO_CHECK_COMPRESS",
|
490
|
+
INT2FIX(MAGIC_NO_CHECK_COMPRESS));
|
491
|
+
#endif
|
492
|
+
|
493
|
+
#ifdef MAGIC_NO_CHECK_TAR
|
494
|
+
/*
|
495
|
+
* Don't examine tar files.
|
496
|
+
* This constant may not be defined on older systems.
|
497
|
+
*/
|
498
|
+
rb_define_const(cMahoro, "NO_CHECK_TAR", INT2FIX(MAGIC_NO_CHECK_TAR));
|
499
|
+
#endif
|
500
|
+
|
501
|
+
#ifdef MAGIC_NO_CHECK_SOFT
|
502
|
+
/*
|
503
|
+
* Don't consult magic files.
|
504
|
+
* This constant may not be defined on older systems.
|
505
|
+
*/
|
506
|
+
rb_define_const(cMahoro, "NO_CHECK_SOFT", INT2FIX(MAGIC_NO_CHECK_SOFT));
|
507
|
+
#endif
|
508
|
+
|
509
|
+
#ifdef MAGIC_NO_CHECK_APPTYPE
|
510
|
+
/*
|
511
|
+
* Don't check application type (EMX only).
|
512
|
+
* This constant may not be defined on older systems.
|
513
|
+
*/
|
514
|
+
rb_define_const(cMahoro, "NO_CHECK_APPTYPE",
|
515
|
+
INT2FIX(MAGIC_NO_CHECK_APPTYPE));
|
516
|
+
#endif
|
517
|
+
|
518
|
+
#ifdef MAGIC_NO_CHECK_ELF
|
519
|
+
/*
|
520
|
+
* Don't check for ELF details.
|
521
|
+
* This constant may not be defined on older systems.
|
522
|
+
*/
|
523
|
+
rb_define_const(cMahoro, "NO_CHECK_ELF", INT2FIX(MAGIC_NO_CHECK_ELF));
|
524
|
+
#endif
|
525
|
+
|
526
|
+
#ifdef MAGIC_NO_CHECK_ASCII
|
527
|
+
/*
|
528
|
+
* Don't check for various types of ASCII text files.
|
529
|
+
* This constant may not be defined on older systems.
|
530
|
+
*/
|
531
|
+
rb_define_const(cMahoro, "NO_CHECK_TEXT",
|
532
|
+
INT2FIX(MAGIC_NO_CHECK_ASCII));
|
533
|
+
#endif
|
534
|
+
|
535
|
+
#ifdef MAGIC_NO_CHECK_TOKENS
|
536
|
+
/*
|
537
|
+
* Don't check for known tokens inside ASCII files.
|
538
|
+
* This constant may not be defined on older systems.
|
539
|
+
*/
|
540
|
+
rb_define_const(cMahoro, "NO_CHECK_TOKENS",
|
541
|
+
INT2FIX(MAGIC_NO_CHECK_TOKENS));
|
542
|
+
#endif
|
543
|
+
|
544
|
+
#ifdef MAGIC_NO_CHECK_ENCODING
|
545
|
+
/*
|
546
|
+
* Don't check for text encodings.
|
547
|
+
* This constant may not be defined on older systems.
|
548
|
+
*/
|
549
|
+
rb_define_const(cMahoro, "NO_CHECK_ENCODING",
|
550
|
+
INT2FIX(MAGIC_NO_CHECK_ENCODING));
|
551
|
+
#endif
|
552
|
+
|
553
|
+
rb_define_alloc_func(cMahoro, mahoro_allocate);
|
554
|
+
rb_define_method(cMahoro, "initialize", mahoro_initialize, -1);
|
555
|
+
rb_define_method(cMahoro, "file", mahoro_file, 1);
|
556
|
+
rb_define_method(cMahoro, "buffer", mahoro_buffer, 1);
|
557
|
+
rb_define_method(cMahoro, "flags=", mahoro_set_flags, 1);
|
558
|
+
rb_define_method(cMahoro, "valid?", mahoro_check, -1);
|
559
|
+
rb_define_singleton_method(cMahoro, "compile", mahoro_s_compile, 1);
|
560
|
+
rb_define_method(cMahoro, "compile", mahoro_compile, 1);
|
561
|
+
rb_define_method(cMahoro, "load", mahoro_load, 1);
|
562
|
+
id_to_path = rb_intern("to_path");
|
563
|
+
}
|
564
|
+
|
565
|
+
/* arch-tag: mahoro */
|