#include "CdIo.h" #define CAP(val,prop,cap,mask) \ rb_hash_aset(val,rb_str_new2(prop),(*cap & mask) ? Qtrue:Qfalse); VALUE get_cap(cdio_drive_read_cap_t * read_cap, cdio_drive_write_cap_t * write_cap, cdio_drive_misc_cap_t * misc_cap) { if (*read_cap & CDIO_DRIVE_CAP_ERROR || *read_cap & CDIO_DRIVE_CAP_UNKNOWN) { rb_raise(rb_eException, "I can't read the caps!"); return Qnil; } VALUE read, write, misc, ret; read = rb_hash_new(); write = rb_hash_new(); misc = rb_hash_new(); ret = rb_hash_new(); rb_hash_aset(ret, rb_str_new2("read"), read); rb_hash_aset(ret, rb_str_new2("write"), write); rb_hash_aset(ret, rb_str_new2("misc"), misc); CAP(read, "audio", read_cap, CDIO_DRIVE_CAP_READ_AUDIO); CAP(read, "cd-da", read_cap, CDIO_DRIVE_CAP_READ_CD_DA); CAP(read, "cd+g", read_cap, CDIO_DRIVE_CAP_READ_CD_G); CAP(read, "cd-r", read_cap, CDIO_DRIVE_CAP_READ_CD_R); CAP(read, "cd-rw", read_cap, CDIO_DRIVE_CAP_READ_CD_RW); CAP(read, "dvd-r", read_cap, CDIO_DRIVE_CAP_READ_DVD_R); CAP(read, "dvr+r", read_cap, CDIO_DRIVE_CAP_READ_DVD_PR); CAP(read, "dvd-ram", read_cap, CDIO_DRIVE_CAP_READ_DVD_RAM); CAP(read, "dvd-rom", read_cap, CDIO_DRIVE_CAP_READ_DVD_ROM); CAP(read, "dvd-rw", read_cap, CDIO_DRIVE_CAP_READ_DVD_RW); CAP(read, "dvd+rw", read_cap, CDIO_DRIVE_CAP_READ_DVD_RPW); CAP(read, "c2_errs", read_cap, CDIO_DRIVE_CAP_READ_C2_ERRS); CAP(write, "cd-r", write_cap, CDIO_DRIVE_CAP_WRITE_CD_R); CAP(write, "cd-rw", write_cap, CDIO_DRIVE_CAP_WRITE_CD_RW); CAP(write, "dvd-r", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_R); CAP(write, "dvd+r", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_PR); CAP(write, "dvd-ram", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_RAM); CAP(write, "dvd-rw", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_RW); CAP(write, "dvd+rw", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_RPW); CAP(write, "mount_rainier", write_cap, CDIO_DRIVE_CAP_WRITE_MT_RAINIER); CAP(write, "burn_proof", write_cap, CDIO_DRIVE_CAP_WRITE_BURN_PROOF); CAP(write, "cd", write_cap, CDIO_DRIVE_CAP_WRITE_CD); CAP(write, "dvd", write_cap, CDIO_DRIVE_CAP_WRITE_DVD); CAP(misc, "close_tray", misc_cap, CDIO_DRIVE_CAP_MISC_CLOSE_TRAY); CAP(misc, "eject", misc_cap, CDIO_DRIVE_CAP_MISC_EJECT); CAP(misc, "lock", misc_cap, CDIO_DRIVE_CAP_MISC_LOCK); CAP(misc, "select_speed", misc_cap, CDIO_DRIVE_CAP_MISC_SELECT_SPEED); CAP(misc, "select_disk", misc_cap, CDIO_DRIVE_CAP_MISC_SELECT_DISC); CAP(misc, "multi_session", misc_cap, CDIO_DRIVE_CAP_MISC_MULTI_SESSION); CAP(misc, "media_changed", misc_cap, CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED); CAP(misc, "misc_reset", misc_cap, CDIO_DRIVE_CAP_MISC_RESET); CAP(misc, "mcn", misc_cap, CDIO_DRIVE_CAP_MCN); CAP(misc, "isrc", misc_cap, CDIO_DRIVE_CAP_ISRC); CAP(misc, "file", misc_cap, CDIO_DRIVE_CAP_MISC_FILE); return ret; } #undef CAP VALUE get_cdtext(const cdtext_t *cdtext) { if(NULL==cdtext) { return Qnil; } else { VALUE ret; ret=rb_hash_new(); int i; for (i=0;i < MAX_CDTEXT_FIELDS;i++) { if(cdtext->field[i]) { rb_hash_aset(ret,rb_str_new2(cdtext_field2str(i)), rb_str_new2(cdtext->field[i])); } } return ret; } }