/*
- * $Id: ext.c 30 2005-04-12 18:38:31Z tilman $
+ * $Id: ext.c 31 2005-04-12 19:03:50Z tilman $
*
* Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
*
#include <ruby.h>
#define CHECK_KEY(key) \
- StringValue((key)); \
-\
if (rb_funcall (key, rb_intern ("include?"), \
1, INT2FIX (0)) == Qtrue) \
rb_raise (rb_eArgError, "key must not contain binary zeroes");
cfile = StringValuePtr (file);
if (!NIL_P (mode)) {
- StringValue (mode);
-
tmp = StringValuePtr (mode);
if (!strcmp (tmp, "r+"))
m = EET_FILE_MODE_READ_WRITE;
c_delete (VALUE self, VALUE key)
{
Eet_File **ef = NULL;
- char *tmp;
+ char *ckey;
Data_Get_Struct (self, Eet_File *, ef);
CHECK_CLOSED (ef);
+ ckey = StringValuePtr (key);
CHECK_KEY (key);
- tmp = StringValuePtr (key);
-
- if (!eet_delete (*ef, tmp))
- rb_raise (rb_eIOError, "cannot delete entry - %s", tmp);
+ if (!eet_delete (*ef, ckey))
+ rb_raise (rb_eIOError, "cannot delete entry - %s", ckey);
return self;
}
VALUE ret;
Eet_File **ef = NULL;
void *data;
+ char *ckey;
int size = 0;
Data_Get_Struct (self, Eet_File *, ef);
CHECK_CLOSED (ef);
+ ckey = StringValuePtr (key);
CHECK_KEY (key);
- data = eet_read (*ef, StringValuePtr (key), &size);
+ data = eet_read (*ef, ckey, &size);
if (!data)
- rb_raise (rb_eIOError, "cannot read entry - %s", key);
+ rb_raise (rb_eIOError, "cannot read entry - %s", ckey);
ret = rb_str_new (data, size);
{
VALUE key = Qnil, buf = Qnil, comp = Qnil;
Eet_File **ef = NULL;
+ char *ckey, *cbuf;
int n;
Data_Get_Struct (self, Eet_File *, ef);
if (NIL_P (comp))
comp = Qtrue;
+ ckey = StringValuePtr (key);
CHECK_KEY (key);
- StringValue (buf);
+ cbuf = StringValuePtr (buf);
- n = eet_write (*ef, StringValuePtr (key),
- StringValuePtr (buf), RSTRING (buf)->len,
+ n = eet_write (*ef, ckey,
+ cbuf, RSTRING (buf)->len,
comp == Qtrue);
if (!n)
rb_raise (rb_eIOError, "couldn't write to file");
VALUE ret, comp;
Eet_File **ef = NULL;
void *data;
+ char *ckey;
int w = 0, h = 0, has_alpha = 0, level = 0, quality = 0, lossy = 0;
Data_Get_Struct (self, Eet_File *, ef);
CHECK_CLOSED (ef);
+ ckey = StringValuePtr (key);
CHECK_KEY (key);
- data = eet_data_image_read (*ef, StringValuePtr (key), &w, &h,
+ data = eet_data_image_read (*ef, ckey, &w, &h,
&has_alpha, &level, &quality,
&lossy);
if (!data)
- rb_raise (rb_eIOError, "cannot read entry - %s", key);
+ rb_raise (rb_eIOError, "cannot read entry - %s", ckey);
comp = rb_hash_new ();
rb_hash_aset (comp, ID2SYM (rb_intern ("lossy")), INT2FIX (lossy));
VALUE key = Qnil, buf = Qnil, w = Qnil, h = Qnil, has_alpha = Qnil;
VALUE comp = Qnil, tmp;
Eet_File **ef = NULL;
+ char *ckey, *cbuf;
int n, lossy = 0, level = 9, quality = 100;
Data_Get_Struct (self, Eet_File *, ef);
if (NIL_P (has_alpha))
has_alpha = Qfalse;
+ ckey = StringValuePtr (key);
CHECK_KEY (key);
- StringValue (buf);
+ cbuf = StringValuePtr (buf);
Check_Type (w, T_FIXNUM);
Check_Type (h, T_FIXNUM);
if (!RSTRING (buf)->len)
return INT2FIX (0);
- n = eet_data_image_write (*ef, StringValuePtr (key),
- StringValuePtr (buf),
+ n = eet_data_image_write (*ef, ckey, cbuf,
FIX2INT (w), FIX2INT (h),
has_alpha == Qtrue,
level, quality, lossy);