conndefaults (PGconn)

    /*
     * call-seq:
     *    PGconn.conndefaults() -> Array
     *
     * Returns an array of hashes. Each hash has the keys:
     * * +:keyword+ - the name of the option
     * * +:envvar+ - the environment variable to fall back to
     * * +:compiled+ - the compiled in option as a secondary fallback
     * * +:val+ - the option's current value, or +nil+ if not known
     * * +:label+ - the label for the field
     * * +:dispchar+ - "" for normal, "D" for debug, and "*" for password
     * * +:dispsize+ - field size
     */
    static VALUE
    pgconn_s_conndefaults(VALUE self)
    {
            PQconninfoOption *options = PQconndefaults();
            VALUE ary = rb_ary_new();
            VALUE hash;
            int i = 0;

            for(i = 0; options[i].keyword != NULL; i++) {
                    hash = rb_hash_new();
                    if(options[i].keyword)
                            rb_hash_aset(hash, ID2SYM(rb_intern("keyword")),
                                    rb_str_new2(options[i].keyword));
                    if(options[i].envvar)
                            rb_hash_aset(hash, ID2SYM(rb_intern("envvar")),
                                    rb_str_new2(options[i].envvar));
                    if(options[i].compiled)
                            rb_hash_aset(hash, ID2SYM(rb_intern("compiled")),
                                    rb_str_new2(options[i].compiled));
                    if(options[i].val)
                            rb_hash_aset(hash, ID2SYM(rb_intern("val")),
                                    rb_str_new2(options[i].val));
                    if(options[i].label)
                            rb_hash_aset(hash, ID2SYM(rb_intern("label")),
                                    rb_str_new2(options[i].label));
                    if(options[i].dispchar)
                            rb_hash_aset(hash, ID2SYM(rb_intern("dispchar")),
                                    rb_str_new2(options[i].dispchar));
                    rb_hash_aset(hash, ID2SYM(rb_intern("dispsize")),
                            INT2NUM(options[i].dispsize));
                    rb_ary_push(ary, hash);
            }
            PQconninfoFree(options);
            return ary;
    }