/* Only allow setting three attributes, should be sufficient for testing. */ static VALUE struct_spec_struct_define_under(VALUE self, VALUE outer, VALUE name, VALUE attr1, VALUE attr2, VALUE attr3) { const char *nm = StringValuePtr(name); const char *a1 = StringValuePtr(attr1); const char *a2 = StringValuePtr(attr2); const char *a3 = StringValuePtr(attr3); return rb_struct_define_under(outer, nm, a1, a2, a3, NULL); }
void Init_attribute(VALUE m) { rb_cConsoleScreenBufferInfo = rb_struct_define_under(m, "ConsoleScreenBufferInfo", "size_x", "size_y", "cur_x", "cur_y", "attr", NULL); rb_define_method(rb_cIO, "console_info", console_info, 0); rb_define_method(rb_cIO, "console_attribute", console_set_attribute, 1); rb_define_const(m, "FOREGROUND_MASK", INT2FIX(FOREGROUND_MASK)); rb_define_const(m, "FOREGROUND_BLUE", INT2FIX(FOREGROUND_BLUE)); rb_define_const(m, "FOREGROUND_GREEN", INT2FIX(FOREGROUND_GREEN)); rb_define_const(m, "FOREGROUND_RED", INT2FIX(FOREGROUND_RED)); rb_define_const(m, "FOREGROUND_INTENSITY", INT2FIX(FOREGROUND_INTENSITY)); rb_define_const(m, "BACKGROUND_MASK", INT2FIX(BACKGROUND_MASK)); rb_define_const(m, "BACKGROUND_BLUE", INT2FIX(BACKGROUND_BLUE)); rb_define_const(m, "BACKGROUND_GREEN", INT2FIX(BACKGROUND_GREEN)); rb_define_const(m, "BACKGROUND_RED", INT2FIX(BACKGROUND_RED)); rb_define_const(m, "BACKGROUND_INTENSITY", INT2FIX(BACKGROUND_INTENSITY)); }
/* * The Etc module provides access to information typically stored in * files in the /etc directory on Unix systems. * * The information accessible consists of the information found in the * /etc/passwd and /etc/group files, plus information about the system's * temporary directory (/tmp) and configuration directory (/etc). * * The Etc module provides a more reliable way to access information about * the logged in user than environment variables such as +$USER+. * * == Example: * * require 'etc' * * login = Etc.getlogin * info = Etc.getpwnam(login) * username = info.gecos.split(/,/).first * puts "Hello #{username}, I see your login name is #{login}" * * Note that the methods provided by this module are not always secure. * It should be used for informational purposes, and not for security. * * All operations defined in this module are class methods, so that you can * include the Etc module into your class. */ void Init_etc(void) { VALUE mEtc; mEtc = rb_define_module("Etc"); rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0); rb_define_module_function(mEtc, "getpwuid", etc_getpwuid, -1); rb_define_module_function(mEtc, "getpwnam", etc_getpwnam, 1); rb_define_module_function(mEtc, "setpwent", etc_setpwent, 0); rb_define_module_function(mEtc, "endpwent", etc_endpwent, 0); rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0); rb_define_module_function(mEtc, "passwd", etc_passwd, 0); rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1); rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1); rb_define_module_function(mEtc, "group", etc_group, 0); rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0); rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0); rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0); rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0); rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0); sPasswd = rb_struct_define_under(mEtc, "Passwd", "name", #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD "passwd", #endif "uid", "gid", #ifdef HAVE_STRUCT_PASSWD_PW_GECOS "gecos", #endif "dir", "shell", #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE "change", #endif #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA "quota", #endif #ifdef HAVE_STRUCT_PASSWD_PW_AGE "age", #endif #ifdef HAVE_STRUCT_PASSWD_PW_CLASS "uclass", #endif #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT "comment", #endif #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE "expire", #endif NULL); #if 0 /* Define-const: Passwd * * Passwd is a Struct that contains the following members: * * name:: * contains the short login name of the user as a String. * passwd:: * contains the encrypted password of the user as a String. * an 'x' is returned if shadow passwords are in use. An '*' is returned * if the user cannot log in using a password. * uid:: * contains the integer user ID (uid) of the user. * gid:: * contains the integer group ID (gid) of the user's primary group. * dir:: * contains the path to the home directory of the user as a String. * shell:: * contains the path to the login shell of the user as a String. * * === The following members below are optional, and must be compiled with special flags: * * gecos:: * contains a longer String description of the user, such as * a full name. Some Unix systems provide structured information in the * gecos field, but this is system-dependent. * must be compiled with +HAVE_STRUCT_PASSWD_PW_GECOS+ * change:: * password change time(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_CHANGE+ * quota:: * quota value(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_QUOTA+ * age:: * password age(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_AGE+ * class:: * user access class(string) must be compiled with +HAVE_STRUCT_PASSWD_PW_CLASS+ * comment:: * comment(string) must be compiled with +HAVE_STRUCT_PASSWD_PW_COMMENT+ * expire:: * account expiration time(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_EXPIRE+ */ rb_define_const(mEtc, "Passwd", sPasswd); #endif rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */ rb_extend_object(sPasswd, rb_mEnumerable); rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0); #ifdef HAVE_GETGRENT sGroup = rb_struct_define_under(mEtc, "Group", "name", #ifdef HAVE_STRUCT_GROUP_GR_PASSWD "passwd", #endif "gid", "mem", NULL); #if 0 /* Define-const: Group * * Group is a Struct that is only available when compiled with +HAVE_GETGRENT+. * * The struct contains the following members: * * name:: * contains the name of the group as a String. * passwd:: * contains the encrypted password as a String. An 'x' is * returned if password access to the group is not available; an empty * string is returned if no password is needed to obtain membership of * the group. * * Must be compiled with +HAVE_STRUCT_GROUP_GR_PASSWD+. * gid:: * contains the group's numeric ID as an integer. * mem:: * is an Array of Strings containing the short login names of the * members of the group. */ rb_define_const(mEtc, "Group", sGroup); #endif rb_define_const(rb_cStruct, "Group", sGroup); /* deprecated name */ rb_extend_object(sGroup, rb_mEnumerable); rb_define_singleton_method(sGroup, "each", etc_each_group, 0); #endif }