/* * field_validation */ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) { VALUE rb_fieldtype, arg3, arg4, arg5; FIELD* field = get_field(rb_field); FIELDTYPE* ftype = NULL; rb_scan_args(argc, argv, "13", &rb_fieldtype, &arg3, &arg4, &arg5); ftype = get_fieldtype(rb_fieldtype); if (ftype == TYPE_ALNUM || ftype == TYPE_ALPHA) { if (argc != 2) rb_raise(rb_eArgError, "TYPE_ALNUM and TYPE_ALPHA require one additional argument"); return INT2NUM(set_field_type(field, ftype, NUM2INT(arg3))); } if (ftype == TYPE_ENUM) { if (argc != 4) { rb_raise(rb_eArgError, "TYPE_ENUM requires three additional arguments"); } else { int n = (int) rbncurs_array_length(arg3); /* Will ncurses free this array of strings in free_field()? */ char** list = ALLOC_N(char*, n+1); int i; for (i = 0; i < n; i++) { list[i] = STR2CSTR(rb_ary_entry(arg3, (long)i)); } list[n] = NULL; return INT2NUM(set_field_type(field, ftype, list, RTEST(arg4), RTEST(arg5))); } } else if (ftype == TYPE_INTEGER) {
/* * Menu creation/destruction functions - menu_new(3X) man page */ static VALUE rbncurs_m_new_menu(VALUE dummy, VALUE rb_item_array) { long n = rbncurs_array_length(rb_item_array); /* Will ncurses free this array? If not, must do it after calling free_menu(). */ ITEM **items = ALLOC_N(ITEM*, (n+1)); long i; for (i=0; i<n; i++) items[i] = get_item(rb_ary_entry(rb_item_array, i)); items[n] = NULL; return wrap_menu(new_menu(items)); }
/* * Form creation/destruction functions */ static VALUE rbncurs_m_new_form(VALUE dummy, VALUE rb_field_array) { long n = rbncurs_array_length(rb_field_array); /* Will ncurses free this array? If not, must do it after calling free_form(). */ FIELD** fields = ALLOC_N(FIELD*, (n+1)); long i; for (i=0; i<n; i++){ fields[i] = get_field(rb_ary_entry(rb_field_array, i)); } fields[n] = NULL; return wrap_form(new_form(fields)); }
/* * Item-menu connection make/break functions - menu_items(3X) man page */ static VALUE rbncurs_c_set_menu_items(VALUE rb_menu, VALUE rb_item_array) { long n = rbncurs_array_length(rb_item_array); /* If ncurses does not free memory used by the previous array of strings, */ /* we will have to do it now. */ ITEM **items = ALLOC_N(ITEM*, (n+1)); long i; MENU *menu = NULL; for (i=0; i<n; i++) items[i] = get_item(rb_ary_entry(rb_item_array, i)); items[n] = NULL; menu = get_menu(rb_menu); return INT2NUM(set_menu_items(menu, items)); }