本文整理汇总了C++中rb_hash_aref函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_hash_aref函数的具体用法?C++ rb_hash_aref怎么用?C++ rb_hash_aref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_hash_aref函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: event_callback
static void event_callback (struct em_event* e)
{
const unsigned long a1 = e->a1;
int a2 = e->a2;
const char *a3 = e->a3;
const unsigned long a4 = e->a4;
if (a2 == EM_CONNECTION_READ) {
VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
if (q == Qnil)
rb_raise (EM_eConnectionNotBound, "received %d bytes of data for unknown signature: %lu", a4, a1);
rb_funcall (q, Intern_receive_data, 1, rb_str_new (a3, a4));
}
else if (a2 == EM_CONNECTION_NOTIFY_READABLE) {
VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
if (q == Qnil)
rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
rb_funcall (q, Intern_notify_readable, 0);
}
else if (a2 == EM_CONNECTION_NOTIFY_WRITABLE) {
VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
if (q == Qnil)
rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
rb_funcall (q, Intern_notify_writable, 0);
}
else if (a2 == EM_LOOPBREAK_SIGNAL) {
rb_funcall (EmModule, Intern_run_deferred_callbacks, 0);
}
else if (a2 == EM_TIMER_FIRED) {
VALUE t = rb_ivar_get (EmModule, Intern_at_timers);
VALUE q = rb_funcall (t, Intern_delete, 1, ULONG2NUM (a4));
if (q == Qnil) {
rb_raise (EM_eUnknownTimerFired, "no such timer: %lu", a4);
} else if (q == Qfalse) {
/* Timer Canceled */
} else {
rb_funcall (q, Intern_call, 0);
}
}
#ifdef WITH_SSL
else if (a2 == EM_SSL_HANDSHAKE_COMPLETED) {
VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
if (q == Qnil)
rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
rb_funcall (q, Intern_ssl_handshake_completed, 0);
}
else if (a2 == EM_SSL_VERIFY) {
VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
if (q == Qnil)
rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
VALUE r = rb_funcall (q, Intern_ssl_verify_peer, 1, rb_str_new(a3, a4));
if (RTEST(r))
evma_accept_ssl_peer (a1);
}
#endif
else if (a2 == EM_PROXY_TARGET_UNBOUND) {
VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
if (q == Qnil)
rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
rb_funcall (q, Intern_proxy_target_unbound, 0);
}
else
rb_funcall (EmModule, Intern_event_callback, 3, ULONG2NUM(a1), INT2FIX(a2), a3 ? rb_str_new(a3,a4) : ULONG2NUM(a4));
}
开发者ID:bernd,项目名称:eventmachine,代码行数:70,代码来源:rubymain.cpp
示例2: make_graphcommand
void make_graphcommand(char *command, VALUE hash)
{
VALUE val;
if (TYPE(hash) == T_STRING) {
sprintf(command, "graph -T X -g 3 %s", STR2CSTR(hash));
return;
}
strcpy(command, "graph");
if (TYPE(hash) != T_HASH) rb_raise(rb_eTypeError,
"wrong argument type %s (Hash expected)",
rb_class2name(CLASS_OF(hash)));
if ((val = rb_hash_aref(hash, rb_str_new2("T"))) != Qnil)
sprintf(command, "%s -T %s", command, STR2CSTR(val));
else
sprintf(command, "%s -T X", command);
val = rb_hash_aref(hash, rb_str_new2("C"));
if (val == Qtrue)
sprintf(command, "%s -C", command);
if ((val = rb_hash_aref(hash, rb_str_new2("g"))) != Qnil)
sprintf(command, "%s -g %d", command, (int) FIX2INT(val));
else
sprintf(command, "%s -g 3", command);
if ((val = rb_hash_aref(hash, rb_str_new2("B"))) == Qtrue)
sprintf(command, "%s -B", command);
if ((val = rb_hash_aref(hash, rb_str_new2("E"))) != Qnil)
sprintf(command, "%s -E %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("f"))) != Qnil)
sprintf(command, "%s -f %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("F"))) != Qnil)
sprintf(command, "%s -F %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("h"))) != Qnil)
sprintf(command, "%s -h %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("k"))) != Qnil)
sprintf(command, "%s -k %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("K"))) != Qnil)
sprintf(command, "%s -K %d", command, (int) FIX2INT(val));
if ((val = rb_hash_aref(hash, rb_str_new2("l"))) != Qnil) {
if (str_tail_grep(STR2CSTR(val), "xy") || str_tail_grep(STR2CSTR(val), "x/y"))
sprintf(command, "%s -l x -l y", command);
else
sprintf(command, "%s -l %s", command, STR2CSTR(val));
}
if ((val = rb_hash_aref(hash, rb_str_new2("L"))) != Qnil)
sprintf(command, "%s -L \"%s\"", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("N"))) != Qnil)
sprintf(command, "%s -N %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("r"))) != Qnil)
sprintf(command, "%s -r %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("R"))) != Qnil)
sprintf(command, "%s -R %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("s"))) == Qtrue)
sprintf(command, "%s -s", command);
if ((val = rb_hash_aref(hash, rb_str_new2("t"))) == Qtrue)
sprintf(command, "%s -t", command);
if ((val = rb_hash_aref(hash, rb_str_new2("u"))) != Qnil)
sprintf(command, "%s -u %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("w"))) != Qnil)
sprintf(command, "%s -w %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("x"))) != Qnil)
sprintf(command, "%s -x %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("X"))) != Qnil)
sprintf(command, "%s -X \"%s\"", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("y"))) != Qnil)
sprintf(command, "%s -y %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("Y"))) != Qnil)
sprintf(command, "%s -Y \"%s\"", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("bg-color"))) != Qnil)
sprintf(command, "%s --bg-color %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("bitmap-size"))) != Qnil)
sprintf(command, "%s --bitmap-size %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("frame-color"))) != Qnil)
sprintf(command, "%s --frame-color %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("frame-line-width"))) != Qnil)
sprintf(command, "%s --frame-line-width %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("max-line-length"))) != Qnil)
sprintf(command, "%s --max-line-length %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("page-size"))) != Qnil)
sprintf(command, "%s --page-size %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("pen-colors"))) != Qnil)
sprintf(command, "%s --pen-colors %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("rotation"))) != Qnil)
sprintf(command, "%s --rotation %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("title-font-name"))) != Qnil)
sprintf(command, "%s --title-font-name %s", command, STR2CSTR(val));
if ((val = rb_hash_aref(hash, rb_str_new2("title-font-size"))) != Qnil)
sprintf(command, "%s --title-font-size %f", command, NUM2DBL(val));
if ((val = rb_hash_aref(hash, rb_str_new2("toggle-rotate-y-label"))) == Qtrue)
sprintf(command, "%s --toggle-rotate-y-label", command);
if ((val = rb_hash_aref(hash, rb_str_new2("m"))) != Qnil)
sprintf(command, "%s -m %d", command, (int) FIX2INT(val));
if ((val = rb_hash_aref(hash, rb_str_new2("S"))) != Qnil)
sprintf(command, "%s -S %d", command, (int) FIX2INT(val));
//.........这里部分代码省略.........
开发者ID:Zenexer,项目名称:rb-gsl,代码行数:101,代码来源:graph.c
示例3: param_hash_aref
static VALUE param_hash_aref(VALUE self, VALUE key) {
if (TYPE(key) == T_SYMBOL) {
key = rb_sym_to_s(key);
}
return rb_hash_aref(self, key);
}
开发者ID:fsword,项目名称:nyara,代码行数:6,代码来源:hashes.c
示例4: am_bootstrap_lift
/**
* call-seq:
* Amalgalite::Requires::Bootstrap.lift( 'dbfile' => "lib.db", 'table_name' => "bootload", 'rowid_column' => "id", 'filename_column' => "filename", 'content_column' => "contents" )
*
* *WARNING* *WARNING* *WARNING* *WARNING* *WARNING* *WARNING* *WARNING*
*
* This is a boostrap mechanism to eval all the code in a particular column in a
* specially formatted table in an sqlite database. It should only be used for
* a specific purpose, mainly loading the Amalgalite ruby code directly from an
* sqlite table.
*
* Amalgalite::Requires adds in the ability to _require_ code that is in an
* sqlite database. Since Amalgalite::Requires is itself ruby code, if
* Amalgalite::Requires was in an sqlite database, it could not _require_
* itself. Therefore this method is made available. It is a pure C extension
* method that directly calls the sqlite3 C functions directly and uses the ruby
* C api to eval the data in the table.
*
* This method attaches to an sqlite3 database (filename) and then does:
*
* SELECT filename_column_name, content_column_name
* FROM table_name
* ORDER BY rowid_column_name
*
* For each row returned it does an _eval_ on the code in the
* *content_column_name* and then updates _$LOADED_FEATURES_ directly with the value from
* *filename_column_name*.
*
* The database to be opened by _lift_ *must* be an sqlite3 UTF-8 database.
*
*/
VALUE am_bootstrap_lift( VALUE self, VALUE args )
{
sqlite3* db = NULL;
sqlite3_stmt* stmt = NULL;
int rc;
int last_row_good;
char raise_msg[BUFSIZ];
VALUE am_db_c = rb_const_get( cARB, rb_intern("DEFAULT_DB") );
VALUE am_tbl_c = rb_const_get( cARB, rb_intern("DEFAULT_BOOTSTRAP_TABLE") );
VALUE am_pk_c = rb_const_get( cARB, rb_intern("DEFAULT_ROWID_COLUMN") );
VALUE am_fname_c = rb_const_get( cARB, rb_intern("DEFAULT_FILENAME_COLUMN") );
VALUE am_content_c = rb_const_get( cARB, rb_intern("DEFAULT_CONTENTS_COLUMN") );
char* dbfile = NULL;
char* tbl_name = NULL;
char* pk_col = NULL;
char* fname_col = NULL;
char* content_col = NULL;
char sql[BUFSIZ];
const char* sql_tail = NULL;
int sql_bytes = 0;
const unsigned char* result_text = NULL;
int result_length = 0;
VALUE require_name = Qnil; /* ruby string of the file name for use in eval */
VALUE eval_this_code = Qnil; /* ruby string of the code to eval from the db */
VALUE toplevel_binding = rb_const_get( rb_cObject, rb_intern("TOPLEVEL_BINDING") ) ;
VALUE tmp = Qnil;
ID eval_id = rb_intern("eval");
if ( Qnil == args ) {
args = rb_hash_new();
} else {
args = rb_ary_shift( args );
}
Check_Type( args, T_HASH );
/* get the arguments */
dbfile = ( Qnil == (tmp = rb_hash_aref( args, rb_str_new2( "dbfile" ) ) ) ) ? StringValuePtr( am_db_c ) : StringValuePtr( tmp );
tbl_name = ( Qnil == (tmp = rb_hash_aref( args, rb_str_new2( "table_name" ) ) ) ) ? StringValuePtr( am_tbl_c ) : StringValuePtr( tmp );
pk_col = ( Qnil == (tmp = rb_hash_aref( args, rb_str_new2( "rowid_column" ) ) ) ) ? StringValuePtr( am_pk_c ) : StringValuePtr( tmp );
fname_col = ( Qnil == (tmp = rb_hash_aref( args, rb_str_new2( "filename_column" ) ) ) ) ? StringValuePtr( am_fname_c ) : StringValuePtr( tmp );
content_col = ( Qnil == (tmp = rb_hash_aref( args, rb_str_new2( "contents_column" ) ) ) ) ? StringValuePtr( am_content_c ) : StringValuePtr( tmp );
/* open the database */
rc = sqlite3_open_v2( dbfile , &db, SQLITE_OPEN_READONLY, NULL);
if ( SQLITE_OK != rc ) {
memset( raise_msg, 0, BUFSIZ );
snprintf(raise_msg, BUFSIZ, "Failure to open database %s for bootload: [SQLITE_ERROR %d] : %s", dbfile, rc, sqlite3_errmsg( db ) );
am_bootstrap_cleanup_and_raise( raise_msg, db, stmt );
}
/* prepare the db query */
memset( sql, 0, BUFSIZ );
sql_bytes = snprintf( sql, BUFSIZ, "SELECT %s, %s FROM %s ORDER BY %s", fname_col, content_col, tbl_name, pk_col );
rc = sqlite3_prepare_v2( db, sql, sql_bytes, &stmt, &sql_tail ) ;
if ( SQLITE_OK != rc) {
memset( raise_msg, 0, BUFSIZ );
snprintf( raise_msg, BUFSIZ,
"Failure to prepare bootload select statement table = '%s', rowid col = '%s', filename col ='%s', contents col = '%s' : [SQLITE_ERROR %d] %s\n",
tbl_name, pk_col, fname_col, content_col, rc, sqlite3_errmsg( db ));
am_bootstrap_cleanup_and_raise( raise_msg, db, stmt );
//.........这里部分代码省略.........
开发者ID:JEG2,项目名称:amalgalite,代码行数:101,代码来源:amalgalite3_requires_bootstrap.c
示例5: do_postgres_full_connect
//.........这里部分代码省略.........
const char *search_path = data_objects_get_uri_option(r_query, "search_path");
db = PQsetdbLogin(
host,
port,
NULL,
NULL,
database,
user,
password
);
if (PQstatus(db) == CONNECTION_BAD) {
rb_raise(eDO_ConnectionError, "%s", PQerrorMessage(db));
}
PGresult *result;
if (search_path) {
char *search_path_query;
if (!(search_path_query = calloc(256, sizeof(char)))) {
rb_memerror();
}
snprintf(search_path_query, 256, "set search_path to %s;", search_path);
r_query = rb_str_new2(search_path_query);
result = do_postgres_cCommand_execute(Qnil, self, db, r_query);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
free(search_path_query);
do_postgres_raise_error(self, result, r_query);
}
free(search_path_query);
}
const char *backslash_off = "SET backslash_quote = off";
const char *standard_strings_on = "SET standard_conforming_strings = on";
const char *warning_messages = "SET client_min_messages = warning";
const char *date_format = "SET datestyle = ISO";
VALUE r_options;
r_options = rb_str_new2(backslash_off);
result = do_postgres_cCommand_execute(Qnil, self, db, r_options);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
rb_warn("%s", PQresultErrorMessage(result));
}
r_options = rb_str_new2(standard_strings_on);
result = do_postgres_cCommand_execute(Qnil, self, db, r_options);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
rb_warn("%s", PQresultErrorMessage(result));
}
r_options = rb_str_new2(warning_messages);
result = do_postgres_cCommand_execute(Qnil, self, db, r_options);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
rb_warn("%s", PQresultErrorMessage(result));
}
r_options = rb_str_new2(date_format);
result = do_postgres_cCommand_execute(Qnil, self, db, r_options);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
rb_warn("%s", PQresultErrorMessage(result));
}
VALUE encoding = rb_iv_get(self, "@encoding");
#ifdef HAVE_PQSETCLIENTENCODING
VALUE pg_encoding = rb_hash_aref(data_objects_const_get(mDO_PostgresEncoding, "MAP"), encoding);
if (pg_encoding != Qnil) {
if (PQsetClientEncoding(db, rb_str_ptr_readonly(pg_encoding))) {
rb_raise(eDO_ConnectionError, "Couldn't set encoding: %s", rb_str_ptr_readonly(encoding));
}
else {
#ifdef HAVE_RUBY_ENCODING_H
rb_iv_set(self, "@encoding_id", INT2FIX(rb_enc_find_index(rb_str_ptr_readonly(encoding))));
#endif
rb_iv_set(self, "@pg_encoding", pg_encoding);
}
}
else {
rb_warn("Encoding %s is not a known Ruby encoding for PostgreSQL\n", rb_str_ptr_readonly(encoding));
rb_iv_set(self, "@encoding", rb_str_new2("UTF-8"));
#ifdef HAVE_RUBY_ENCODING_H
rb_iv_set(self, "@encoding_id", INT2FIX(rb_enc_find_index("UTF-8")));
#endif
rb_iv_set(self, "@pg_encoding", rb_str_new2("UTF8"));
}
#endif
rb_iv_set(self, "@connection", Data_Wrap_Struct(rb_cObject, 0, 0, db));
}
开发者ID:CompendiumSoftware,项目名称:do,代码行数:101,代码来源:do_postgres.c
示例6: rho_ruby_hash_aref
VALUE rho_ruby_hash_aref(VALUE hash, const char* key)
{
return rb_hash_aref( hash, rb_str_new2(key));
}
开发者ID:ariejan,项目名称:rhodes,代码行数:4,代码来源:rhoruby.c
示例7: cState_configure
/*
* call-seq: configure(opts)
*
* Configure this State instance with the Hash _opts_, and return
* itself.
*/
static VALUE cState_configure(VALUE self, VALUE opts)
{
VALUE tmp;
GET_STATE(self);
tmp = rb_check_convert_type(opts, T_HASH, "Hash", "to_hash");
if (NIL_P(tmp)) tmp = rb_convert_type(opts, T_HASH, "Hash", "to_h");
opts = tmp;
tmp = rb_hash_aref(opts, ID2SYM(i_indent));
if (RTEST(tmp)) {
unsigned long len;
Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp);
state->indent = fstrndup(RSTRING_PTR(tmp), len + 1);
state->indent_len = len;
}
tmp = rb_hash_aref(opts, ID2SYM(i_space));
if (RTEST(tmp)) {
unsigned long len;
Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp);
state->space = fstrndup(RSTRING_PTR(tmp), len + 1);
state->space_len = len;
}
tmp = rb_hash_aref(opts, ID2SYM(i_space_before));
if (RTEST(tmp)) {
unsigned long len;
Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp);
state->space_before = fstrndup(RSTRING_PTR(tmp), len + 1);
state->space_before_len = len;
}
tmp = rb_hash_aref(opts, ID2SYM(i_array_nl));
if (RTEST(tmp)) {
unsigned long len;
Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp);
state->array_nl = fstrndup(RSTRING_PTR(tmp), len + 1);
state->array_nl_len = len;
}
tmp = rb_hash_aref(opts, ID2SYM(i_object_nl));
if (RTEST(tmp)) {
unsigned long len;
Check_Type(tmp, T_STRING);
len = RSTRING_LEN(tmp);
state->object_nl = fstrndup(RSTRING_PTR(tmp), len + 1);
state->object_nl_len = len;
}
tmp = ID2SYM(i_max_nesting);
state->max_nesting = 100;
if (option_given_p(opts, tmp)) {
VALUE max_nesting = rb_hash_aref(opts, tmp);
if (RTEST(max_nesting)) {
Check_Type(max_nesting, T_FIXNUM);
state->max_nesting = FIX2LONG(max_nesting);
} else {
state->max_nesting = 0;
}
}
tmp = ID2SYM(i_depth);
state->depth = 0;
if (option_given_p(opts, tmp)) {
VALUE depth = rb_hash_aref(opts, tmp);
if (RTEST(depth)) {
Check_Type(depth, T_FIXNUM);
state->depth = FIX2LONG(depth);
} else {
state->depth = 0;
}
}
tmp = ID2SYM(i_buffer_initial_length);
if (option_given_p(opts, tmp)) {
VALUE buffer_initial_length = rb_hash_aref(opts, tmp);
if (RTEST(buffer_initial_length)) {
long initial_length;
Check_Type(buffer_initial_length, T_FIXNUM);
initial_length = FIX2LONG(buffer_initial_length);
if (initial_length > 0) state->buffer_initial_length = initial_length;
}
}
tmp = rb_hash_aref(opts, ID2SYM(i_allow_nan));
state->allow_nan = RTEST(tmp);
tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only));
state->ascii_only = RTEST(tmp);
tmp = rb_hash_aref(opts, ID2SYM(i_quirks_mode));
state->quirks_mode = RTEST(tmp);
return self;
}
开发者ID:brightbox,项目名称:deb-ruby2.3,代码行数:93,代码来源:generator.c
示例8: draw
/*
call-seq: draw(hash = nil) { ... }
Three keys are checked in the given hash : ":buffer" which is the buffer
on which manipulation are done (by default, the actual buffer is taken),
":painter", which tell us to yield a +Joyau::Painter+ instead of a
+Joyau::Buffer+ when true (false by default), and ":auto_update" which
tell us whether we should update the buffer (true by default).
It is mandatory to give a block to this function.
Examples:
Joyau.draw(:buffer => a_buffer, :painter => true)
Joyau.draw(:auto_update => false)
Joyau.draw(:painter => true)
Joyau.draw(:buffer => a_buffer)
*/
VALUE Joyau_draw(int argc, VALUE *argv, VALUE self) {
static bool can_draw = false;
VALUE hash, block;
rb_scan_args(argc, argv, "01&", &hash, &block);
OSL_IMAGE *oldBuffer = oslGetDrawBuffer();
Buffer *buffer = NULL;
VALUE rbPainter = Qnil;
bool painter = false;
bool auto_update = true;
bool ruby_buf = false;
bool could_draw = can_draw;
if (!NIL_P(hash)) {
if (TYPE(hash) != T_HASH)
rb_raise(rb_eTypeError, "Hash expected for Joyau::draw.");
VALUE rbBuffer = rb_hash_aref(hash, ID2SYM(rb_intern("buffer")));
if (rb_obj_is_kind_of(rbBuffer, getClass("Buffer")) == Qfalse) {
if (rbBuffer != Qnil)
rb_raise(rb_eTypeError, ":buffer should be a Buffer (or nil).");
}
else {
buffer = getPtr<Buffer>(rbBuffer);
ruby_buf = true;
}
if (!buffer)
buffer = new Buffer(oldBuffer);
if (rb_hash_aref(hash, ID2SYM(rb_intern("painter"))) == Qtrue) {
painter = true;
Painter painter(buffer);
rbPainter = createObject(getClass("Painter"), painter);
}
if (rb_hash_aref(hash, ID2SYM(rb_intern("auto_update"))) == Qfalse)
auto_update = false;
}
else {
if (!buffer)
buffer = new Buffer(oldBuffer);
}
if (buffer->isScreen() && !can_draw) {
can_draw = true;
Graphics_startDraw(Qnil);
}
if (!NIL_P(block)) {
buffer->setActual();
if (painter)
rb_yield(rbPainter);
else {
VALUE rbBuffer = createObject(getClass("Buffer"), *buffer, true);
rb_yield(rbBuffer);
}
if (buffer->isScreen() && !could_draw) {
can_draw = false;
Graphics_endDraw(Qnil);
}
if (auto_update && buffer->isScreen())
Graphics_sync(Qnil);
}
else
rb_raise(rb_eArgError, "Block expected.");
if (!ruby_buf) // We do not delete the buffer if it comes from Ruby.
delete buffer;
oslSetDrawBuffer(oldBuffer);
return Qnil;
}
开发者ID:Epictetus,项目名称:Joyau,代码行数:95,代码来源:Buffer.cpp
示例9: rb_git_commit_amend
/*
* call-seq:
* commit.amend(data = {}) -> oid
*
* Amend a commit object, with the given +data+
* arguments, passed as a +Hash+:
*
* - +:message+: a string with the full text for the commit's message
* - +:committer+ (optional): a hash with the signature for the committer,
* defaults to the signature from the configuration
* - +:author+ (optional): a hash with the signature for the author,
* defaults to the signature from the configuration
* - +:tree+: the tree for this amended commit, represented as a <tt>Rugged::Tree</tt>
* instance or an OID +String+.
* - +:update_ref+ (optional): a +String+ with the name of a reference in the
* repository which should be updated to point to this amended commit (e.g. "HEAD")
*
* When the amended commit is successfully written to disk, its +oid+ will be
* returned as a hex +String+.
*
* author = {:email=>"[email protected]", :time=>Time.now, :name=>"Vicent Mart\303\255"}
*
* commit.amend(
* :author => author,
* :message => "Updated Hello world\n\n",
* :committer => author,
* :tree => some_tree) #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
*/
static VALUE rb_git_commit_amend(VALUE self, VALUE rb_data)
{
VALUE rb_message, rb_tree, rb_ref, owner;
int error = 0;
git_commit *commit_to_amend;
char *message = NULL;
git_tree *tree = NULL;
git_signature *author = NULL, *committer = NULL;
git_oid commit_oid;
git_repository *repo;
const char *update_ref = NULL;
Check_Type(rb_data, T_HASH);
Data_Get_Struct(self, git_commit, commit_to_amend);
owner = rugged_owner(self);
Data_Get_Struct(owner, git_repository, repo);
rb_ref = rb_hash_aref(rb_data, CSTR2SYM("update_ref"));
if (!NIL_P(rb_ref)) {
Check_Type(rb_ref, T_STRING);
update_ref = StringValueCStr(rb_ref);
}
rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
if (!NIL_P(rb_message)) {
Check_Type(rb_message, T_STRING);
message = StringValueCStr(rb_message);
}
rb_tree = rb_hash_aref(rb_data, CSTR2SYM("tree"));
if (!NIL_P(rb_tree))
tree = (git_tree *)rugged_object_get(repo, rb_tree, GIT_OBJ_TREE);
if (!NIL_P(rb_hash_aref(rb_data, CSTR2SYM("committer")))) {
committer = rugged_signature_get(
rb_hash_aref(rb_data, CSTR2SYM("committer")), repo
);
}
if (!NIL_P(rb_hash_aref(rb_data, CSTR2SYM("author")))) {
author = rugged_signature_get(
rb_hash_aref(rb_data, CSTR2SYM("author")), repo
);
}
error = git_commit_amend(
&commit_oid,
commit_to_amend,
update_ref,
author,
committer,
NULL,
message,
tree);
git_signature_free(author);
git_signature_free(committer);
git_object_free((git_object *)tree);
rugged_exception_check(error);
return rugged_create_oid(&commit_oid);
}
开发者ID:jacobvosmaer,项目名称:rugged,代码行数:94,代码来源:rugged_commit.c
示例10: rcsv_raw_parse
/* An rb_rescue()-compatible Ruby pseudo-method that handles the actual parsing */
VALUE rcsv_raw_parse(VALUE ensure_container) {
/* Unpacking multiple variables from a single Ruby VALUE */
VALUE options = rb_ary_entry(ensure_container, 0);
VALUE csvio = rb_ary_entry(ensure_container, 1);
struct rcsv_metadata * meta = (struct rcsv_metadata *)NUM2LONG(rb_ary_entry(ensure_container, 2));
struct csv_parser * cp = (struct csv_parser *)NUM2LONG(rb_ary_entry(ensure_container, 3));
/* Helper temporary variables */
VALUE option, csvstr, buffer_size;
/* libcsv-related temporary variables */
char * csv_string;
size_t csv_string_len;
int error;
/* Generic iterator */
size_t i = 0;
/* IO buffer size can be controller via an option */
buffer_size = rb_hash_aref(options, ID2SYM(rb_intern("buffer_size")));
/* By default, parse as Array of Arrays */
option = rb_hash_aref(options, ID2SYM(rb_intern("row_as_hash")));
if (option && (option != Qnil)) {
meta->row_as_hash = true;
}
/* :col_sep sets the column separator, default is comma (,) */
option = rb_hash_aref(options, ID2SYM(rb_intern("col_sep")));
if (option != Qnil) {
csv_set_delim(cp, (unsigned char)*StringValuePtr(option));
}
/* :quote_char sets the character used for quoting data; default is double-quote (") */
option = rb_hash_aref(options, ID2SYM(rb_intern("quote_char")));
if (option != Qnil) {
csv_set_quote(cp, (unsigned char)*StringValuePtr(option));
}
/* Specify how many rows to skip from the beginning of CSV */
option = rb_hash_aref(options, ID2SYM(rb_intern("offset_rows")));
if (option != Qnil) {
meta->offset_rows = (size_t)NUM2INT(option);
}
/* Specify the character encoding of the input data */
option = rb_hash_aref(options, ID2SYM(rb_intern("output_encoding")));
if (option && (option != Qnil)) {
meta->encoding_index = RB_ENC_FIND_INDEX(StringValueCStr(option));
}
/* :only_rows is a list of values where row is only parsed
if its fields match those in the passed array.
[nil, nil, ["ABC", nil, 1]] skips all rows where 3rd column isn't equal to "ABC", nil or 1 */
option = rb_hash_aref(options, ID2SYM(rb_intern("only_rows")));
if (option != Qnil) {
meta->num_only_rows = (size_t)RARRAY_LEN(option);
meta->only_rows = (VALUE *)malloc(meta->num_only_rows * sizeof(VALUE));
for (i = 0; i < meta->num_only_rows; i++) {
VALUE only_row = rb_ary_entry(option, i);
meta->only_rows[i] = validate_filter_row("only_rows", only_row);
}
}
/* :except_rows is a list of values where row is only parsed
if its fields don't match those in the passed array.
[nil, nil, ["ABC", nil, 1]] skips all rows where 3rd column is equal to "ABC", nil or 1 */
option = rb_hash_aref(options, ID2SYM(rb_intern("except_rows")));
if (option != Qnil) {
meta->num_except_rows = (size_t)RARRAY_LEN(option);
meta->except_rows = (VALUE *)malloc(meta->num_except_rows * sizeof(VALUE));
for (i = 0; i < meta->num_except_rows; i++) {
VALUE except_row = rb_ary_entry(option, i);
meta->except_rows[i] = validate_filter_row("except_rows", except_row);
}
}
/* :row_defaults is an array of default values that are assigned to fields containing empty strings
according to matching field positions */
option = rb_hash_aref(options, ID2SYM(rb_intern("row_defaults")));
if (option != Qnil) {
meta->num_row_defaults = RARRAY_LEN(option);
meta->row_defaults = (VALUE*)malloc(meta->num_row_defaults * sizeof(VALUE*));
for (i = 0; i < meta->num_row_defaults; i++) {
VALUE row_default = rb_ary_entry(option, i);
meta->row_defaults[i] = row_default;
}
}
/* :row_conversions specifies Ruby types that CSV field values should be converted into.
Each char of row_conversions string represents Ruby type for CSV field with matching position. */
option = rb_hash_aref(options, ID2SYM(rb_intern("row_conversions")));
if (option != Qnil) {
meta->num_row_conversions = RSTRING_LEN(option);
meta->row_conversions = StringValuePtr(option);
}
//.........这里部分代码省略.........
开发者ID:fiksu,项目名称:rcsv,代码行数:101,代码来源:rcsv.c
示例11: rb_rcsv_raw_parse
/* The main method that handles parsing */
static VALUE rb_rcsv_raw_parse(int argc, VALUE * argv, VALUE self) {
struct rcsv_metadata meta;
VALUE csvio, options, option;
VALUE ensure_container = rb_ary_new(); /* [] */
struct csv_parser cp;
unsigned char csv_options = CSV_STRICT_FINI | CSV_APPEND_NULL;
/* Setting up some sane defaults */
meta.row_as_hash = false;
meta.empty_field_is_nil = false;
meta.skip_current_row = false;
meta.encoding_index = -1;
meta.num_columns = 0;
meta.current_col = 0;
meta.current_row = 0;
meta.offset_rows = 0;
meta.num_only_rows = 0;
meta.num_except_rows = 0;
meta.num_row_defaults = 0;
meta.num_row_conversions = 0;
meta.only_rows = NULL;
meta.except_rows = NULL;
meta.row_defaults = NULL;
meta.row_conversions = NULL;
meta.column_names = NULL;
meta.result = (VALUE[]){rb_ary_new()}; /* [] */
/* csvio is required, options is optional (pun intended) */
rb_scan_args(argc, argv, "11", &csvio, &options);
/* options ||= {} */
if (NIL_P(options)) {
options = rb_hash_new();
}
/* First of all, we parse libcsv-related params so that it fails early if something is wrong with them */
/* By default, parsing is strict */
option = rb_hash_aref(options, ID2SYM(rb_intern("nostrict")));
if (!option || (option == Qnil)) {
csv_options |= CSV_STRICT;
}
/* By default, empty strings are treated as Nils and quoted empty strings are treated as empty Ruby strings */
option = rb_hash_aref(options, ID2SYM(rb_intern("parse_empty_fields_as")));
if ((option == Qnil) || (option == ID2SYM(rb_intern("nil_or_string")))) {
csv_options |= CSV_EMPTY_IS_NULL;
} else if (option == ID2SYM(rb_intern("nil"))) {
meta.empty_field_is_nil = true;
} else if (option == ID2SYM(rb_intern("string"))) {
meta.empty_field_is_nil = false;
} else {
rb_raise(rcsv_parse_error, "The only valid options for :parse_empty_fields_as are :nil, :string and :nil_or_string, but %s was supplied.", RSTRING_PTR(rb_inspect(option)));
}
/* rb_ensure() only expects callback functions to accept and return VALUEs */
/* This ugly hack converts C pointers into Ruby Fixnums in order to pass them in Array */
rb_ary_push(ensure_container, options); /* [options] */
rb_ary_push(ensure_container, csvio); /* [options, csvio] */
rb_ary_push(ensure_container, LONG2NUM((long)&meta)); /* [options, csvio, &meta] */
rb_ary_push(ensure_container, LONG2NUM((long)&cp)); /* [options, csvio, &meta, &cp] */
/* Try to initialize libcsv */
if (csv_init(&cp, csv_options) == -1) {
rb_raise(rcsv_parse_error, "Couldn't initialize libcsv");
}
/* From now on, cp handles allocated data and should be free'd on exit or exception */
rb_ensure(rcsv_raw_parse, ensure_container, rcsv_free_memory, ensure_container);
/* Remove the last row if it's empty. That happens if CSV file ends with a newline. */
if (RARRAY_LEN(*(meta.result)) && /* meta.result.size != 0 */
RARRAY_LEN(rb_ary_entry(*(meta.result), -1)) == 0) {
rb_ary_pop(*(meta.result));
}
if (rb_block_given_p()) {
return Qnil; /* STREAMING */
} else {
return *(meta.result); /* Return accumulated result */
}
}
开发者ID:fiksu,项目名称:rcsv,代码行数:84,代码来源:rcsv.c
示例12: rb_tinytds_connect
static VALUE rb_tinytds_connect(VALUE self, VALUE opts) {
/* Parsing options hash to local vars. */
VALUE user, pass, dataserver, database, app, version, ltimeout, timeout, charset, azure;
user = rb_hash_aref(opts, sym_username);
pass = rb_hash_aref(opts, sym_password);
dataserver = rb_hash_aref(opts, sym_dataserver);
database = rb_hash_aref(opts, sym_database);
app = rb_hash_aref(opts, sym_appname);
version = rb_hash_aref(opts, sym_tds_version);
ltimeout = rb_hash_aref(opts, sym_login_timeout);
timeout = rb_hash_aref(opts, sym_timeout);
charset = rb_hash_aref(opts, sym_encoding);
azure = rb_hash_aref(opts, sym_azure);
/* Dealing with options. */
if (dbinit() == FAIL) {
rb_raise(cTinyTdsError, "failed dbinit() function");
return self;
}
dberrhandle(tinytds_err_handler);
dbmsghandle(tinytds_msg_handler);
GET_CLIENT_WRAPPER(self);
cwrap->login = dblogin();
if (!NIL_P(version))
dbsetlversion(cwrap->login, NUM2INT(version));
if (!NIL_P(user))
dbsetluser(cwrap->login, StringValuePtr(user));
if (!NIL_P(pass))
dbsetlpwd(cwrap->login, StringValuePtr(pass));
if (!NIL_P(app))
dbsetlapp(cwrap->login, StringValuePtr(app));
if (!NIL_P(ltimeout))
dbsetlogintime(NUM2INT(ltimeout));
if (!NIL_P(timeout))
dbsettime(NUM2INT(timeout));
if (!NIL_P(charset))
DBSETLCHARSET(cwrap->login, StringValuePtr(charset));
if (!NIL_P(database) && (azure == Qtrue)) {
#ifdef DBSETLDBNAME
DBSETLDBNAME(cwrap->login, StringValuePtr(database));
cwrap->userdata->continue_on_timeout = 0; // Send INT_CANCEL on timeout with Azure
#else
rb_warn("TinyTds: Azure connections not supported in this version of FreeTDS.\n");
#endif
}
cwrap->client = dbopen(cwrap->login, StringValuePtr(dataserver));
if (cwrap->client) {
cwrap->closed = 0;
cwrap->charset = charset;
if (!NIL_P(version))
dbsetversion(NUM2INT(version));
dbsetuserdata(cwrap->client, (BYTE*)cwrap->userdata);
cwrap->userdata->closed = 0;
if (!NIL_P(database) && (azure != Qtrue)) {
dbuse(cwrap->client, StringValuePtr(database));
}
VALUE transposed_encoding = rb_funcall(cTinyTdsClient, intern_transpose_iconv_encoding, 1, charset);
cwrap->encoding = rb_enc_find(StringValuePtr(transposed_encoding));
if (dbtds(cwrap->client) <= 7) {
cwrap->identity_insert_sql = "SELECT CAST(@@IDENTITY AS bigint) AS Ident";
} else {
cwrap->identity_insert_sql = "SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident";
}
}
return self;
}
开发者ID:pd40,项目名称:tiny_tds,代码行数:65,代码来源:client.c
示例13: Traverser_Clone2_traverse_item
VALUE Traverser_Clone2_traverse_item(VALUE self ) {
VALUE vals[0];
VALUE it ,__result=Qnil,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,_ar=Qnil,_it=Qnil,_autovar_4=Qnil;
VALUE bind2=bind_new2(2);
cstruct *ptr;
Data_Get_Struct(self,cstruct,ptr);
switch(FIX2LONG(rb_hash_aref(switchhash_Traverser_Clone2_1,rb_obj_class(ame_curobj2(ptr))))) {
case 0/*AmethystAST*/:
;
int oldpos1=ptr->pos;
int cut1=0;
alt1_1:
if(!ptr->branches)ptr->discard=ptr->pos;
ptr->branches+=3;
it=rb_funcall(self,sy_visit,0);
if (it==failobj) {
it=failobj;
goto revert1;
}
__result=it;;
;
goto accept2;
revert1:
;
goto alt1_2;
accept2:
;
;
ptr->branches-=3;
goto accept1;
alt1_2:
ptr->pos=oldpos1;
ptr->branches-=1;
it=ptr->ary[ptr->pos]; ;
ptr->pos++;
_autovar=it;;
cstruct oldpass1=*ptr;
ptr->pos=ptr->len=0;
ptr->ary=NULL;
ame_setsrc2(self,_autovar);
it=Traverser_Clone2_traverse(self );
if (it==failobj) {
it=failobj;
goto pass1;
}
_autovar_2=it;;
goto success1;
pass1:
*ptr=oldpass1;
if (1) {
it=failobj;
goto revert2;
}
success1:
*ptr=oldpass1;
it=_autovar_2;
__result=it;;
;
goto accept3;
revert2:
;
goto alt1_3;
accept3:
;
;
ptr->branches-=2;
goto accept1;
alt1_3:
ptr->pos=oldpos1;
ptr->branches-=1;
it=AmethystCore_anything(self );
if (it==failobj) {
it=failobj;
goto revert3;
}
__result=it;;
;
goto accept4;
revert3:
;
goto alt1_4;
accept4:
;
;
ptr->branches-=1;
goto accept1;
alt1_4:
ptr->pos=oldpos1;
ptr->branches-=1;
if (1) {
it=failobj;
goto fail;
};
//.........这里部分代码省略.........
开发者ID:neleai,项目名称:mthyst,代码行数:101,代码来源:Traverser_Clone2_c.c
示例14: rb_redcarpet_html_init
static VALUE rb_redcarpet_html_init(int argc, VALUE *argv, VALUE self)
{
struct rb_redcarpet_rndr *rndr;
unsigned int render_flags = 0;
VALUE hash, link_attr = Qnil;
Data_Get_Struct(self, struct rb_redcarpet_rndr, rndr);
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
Check_Type(hash, T_HASH);
/* escape_html */
if (rb_hash_aref(hash, CSTR2SYM("escape_html")) == Qtrue)
render_flags |= HTML_ESCAPE;
/* filter_html */
if (rb_hash_aref(hash, CSTR2SYM("filter_html")) == Qtrue)
render_flags |= HTML_SKIP_HTML;
/* no_image */
if (rb_hash_aref(hash, CSTR2SYM("no_images")) == Qtrue)
render_flags |= HTML_SKIP_IMAGES;
/* no_links */
if (rb_hash_aref(hash, CSTR2SYM("no_links")) == Qtrue)
render_flags |= HTML_SKIP_LINKS;
/* prettify */
if (rb_hash_aref(hash, CSTR2SYM("prettify")) == Qtrue)
render_flags |= HTML_PRETTIFY;
/* filter_style */
if (rb_hash_aref(hash, CSTR2SYM("no_styles")) == Qtrue)
render_flags |= HTML_SKIP_STYLE;
/* safelink */
if (rb_hash_aref(hash, CSTR2SYM("safe_links_only")) == Qtrue)
render_flags |= HTML_SAFELINK;
if (rb_hash_aref(hash, CSTR2SYM("with_toc_data")) == Qtrue)
render_flags |= HTML_TOC;
if (rb_hash_aref(hash, CSTR2SYM("hard_wrap")) == Qtrue)
render_flags |= HTML_HARD_WRAP;
if (rb_hash_aref(hash, CSTR2SYM("xhtml")) == Qtrue)
render_flags |= HTML_USE_XHTML;
link_attr = rb_hash_aref(hash, CSTR2SYM("link_attributes"));
}
sdhtml_renderer(&rndr->callbacks, (struct html_renderopt *)&rndr->options.html, render_flags);
rb_redcarpet__overload(self, rb_cRenderHTML);
if (!NIL_P(link_attr)) {
rndr->options.link_attributes = link_attr;
rndr->options.html.link_attributes = &rndr_link_attributes;
}
return Qnil;
}
开发者ID:SachaG,项目名称:redcarpet,代码行数:61,代码来源:rc_render.c
示例15: wsf_util_pack_attachments
void wsf_util_pack_attachments (
axutil_env_t *env,
axiom_node_t *node,
VALUE attach_ht,
int enable_mtom,
char *default_cnt_type)
{
axiom_element_t *node_element = NULL;
axiom_element_t *child_element = NULL;
axiom_child_element_iterator_t *child_element_ite = NULL;
axiom_node_t *child_node = NULL;
int attachment_done = 0;
axis2_char_t *element_localname = NULL;
axiom_namespace_t *element_namespace = NULL;
axis2_char_t *namespace_uri = NULL;
if (!node)
return;
if (axiom_node_get_node_type(node, env) == AXIOM_ELEMENT)
{
node_element = axiom_node_get_data_element(node, env);
if (node_element)
{
child_element_ite = axiom_element_get_child_elements(node_element, env, node);
if (child_element_ite)
{
child_node = axiom_child_element_iterator_next(child_element_ite, env);
attachment_done = 0;
while (child_node && !attachment_done)
{
child_element = axiom_node_get_data_element(child_node, env);
element_localname = axiom_element_get_localname(child_element, env);
if (element_localname && (axutil_strcmp(element_localname, AXIS2_ELEMENT_LN_INCLUDE) == 0))
{
element_namespace = axiom_element_get_namespace(child_element, env, child_node);
if (element_namespace)
{
namespace_uri = axiom_namespace_get_uri(element_namespace, env);
if (namespace_uri && (axutil_strcmp(namespace_uri, AXIS2_NAMESPACE_URI_INCLUDE) == 0))
{
axis2_char_t *cnt_type = NULL;
axis2_char_t *content_type = NULL;
axis2_char_t *href = NULL;
axis2_char_t* pos = NULL;
cnt_type = axiom_element_get_attribute_value_by_name(node_element, env, AXIS2_ELEMENT_ATTR_NAME_CONTENT_TYPE);
content_type = !cnt_type ? default_cnt_type : cnt_type;
href = axiom_element_get_attribute_value_by_name(child_element, env, AXIS2_ELEMENT_ATTR_NAME_HREF);
if ((axutil_strlen(href) > 4) && (pos = axutil_strstr (href, "cid:")))
{
axis2_char_t* cid = NULL;
VALUE content_tmp;
void* content = NULL;
unsigned int content_length = 0;
cid = href + 4;
content_tmp = rb_hash_aref(attach_ht, rb_str_new2(
|
请发表评论