/** * Copyright (c) 2005 Claudio Bustos * This code is hereby licensed for public consumption under the * GNU GPL v2. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Definici?n de funciones para CdIo */ #include "CdIo.h" VALUE rb_cdio_get_devices(int argc, VALUE * argv, VALUE module) { char **devices = NULL, **i; driver_id_t driver_id; VALUE driver; rb_scan_args(argc, argv, "01", &driver); FIXNUM_P(driver); driver_id = (driver == Qnil) ? DRIVER_DEVICE : FIX2INT(driver); devices = cdio_get_devices(driver_id); if (NULL != devices) { VALUE aDevices; aDevices = rb_ary_new(); for (i = devices; *i != NULL; i++) { rb_ary_push(aDevices, rb_str_new2(*i)); } cdio_free_device_list(devices); return aDevices; } else { return Qnil; } } VALUE rb_cdio_get_default_device(int argc, VALUE * argv, VALUE module) { driver_id_t driver_id; char *device; VALUE cd; rb_scan_args(argc, argv, "01", &cd); if (cd != Qnil && Qtrue != rb_obj_is_instance_of(cd, cCdIoCd)) { rb_raise(rb_eArgError, "Arg 1 must be a CdIo::Cd"); } if (cd == Qnil) { device = cdio_get_default_device(NULL); } else { GET_CDIO(cd, p_cdio); device = cdio_get_default_device(p_cdio); } if (NULL != device) { return rb_str_new2(device); } else { return Qnil; } } VALUE rb_cdio_get_drive_cap_dev(VALUE module, VALUE device) { cdio_drive_read_cap_t read_cap; cdio_drive_write_cap_t write_cap; cdio_drive_misc_cap_t misc_cap; Check_Type(device, T_STRING); SafeStringValue(device); cdio_get_drive_cap_dev(StringValuePtr(device), &read_cap, &write_cap, &misc_cap); // Error? return get_cap(&read_cap, &write_cap, &misc_cap); } VALUE rb_cdio_driver_describe(VALUE module, VALUE driver) { FIXNUM_P(driver); return rb_str_new2(cdio_driver_describe(FIX2INT(driver))); } VALUE rb_cdio_open(int argc, VALUE * argv, VALUE module) { VALUE source, driver, block; VALUE argv_2[2]; // def open(source=nil,driver=nil) &block rb_scan_args(argc, argv, "02&", &source, &driver, &block); if (Qnil != source) { Check_Type(source, T_STRING); } FIXNUM_P(driver); argv_2[0] = source; argv_2[1] = driver; VALUE cd = rb_cdio_cd_new(2, argv_2, cCdIoCd); if (Qnil == block) { return cd; } else { rb_gc_start(); rb_yield(cd); cd = Qnil; return Qnil; } } VALUE rb_cdio_track_format_describe(VALUE module, VALUE track_format) { FIXNUM_P(track_format); trackmode_t format_t = FIX2INT(track_format); return rb_str_new2(track_format2str[format_t]); } VALUE rb_cdio_discmode_describe(VALUE module, VALUE discmode) { FIXNUM_P(discmode); discmode_t discmode_i = FIX2INT(discmode); return rb_str_new2(discmode2str[discmode_i]); } VALUE rb_cdio_track_type_describe(VALUE module, VALUE track) { char desc[255]; if (Qtrue != rb_obj_is_kind_of(track, cCdIoTrack)) { rb_raise(rb_eArgError, "Arg 1 must be a CdIo::Track"); } VALUE cd = rb_iv_get(track, "@cd"); int i_track = FIX2INT(rb_iv_get(track, "@number")); GET_CDIO(cd, p_cdio); cdio_fs_anal_t fs; cdio_iso_analysis_t cdio_iso_analysis; fs = cdio_guess_cd_type(p_cdio, 0, i_track, &cdio_iso_analysis); switch (CDIO_FSTYPE(fs)) { case CDIO_FS_AUDIO: strcpy(desc, "Audio CD"); break; case CDIO_FS_ISO_9660: strcpy(desc, "CD-ROM with ISO 9660 filesystem"); if (fs & CDIO_FS_ANAL_JOLIET) { char desc2[50]; sprintf(desc2, " and joliet extension level %d", cdio_iso_analysis.joliet_level); strcat(desc, desc2); } if (fs & CDIO_FS_ANAL_ROCKRIDGE) strcat(desc, " and rockridge extensions"); break; case CDIO_FS_ISO_9660_INTERACTIVE: strcpy(desc, "CD-ROM with CD-RTOS and ISO 9660 filesystem"); break; case CDIO_FS_HIGH_SIERRA: strcpy(desc, "CD-ROM with High Sierra filesystem"); break; case CDIO_FS_INTERACTIVE: strcpy(desc, "CD-Interactive"); break; case CDIO_FS_HFS: strcpy(desc, "CD-ROM with Macintosh HFS"); break; case CDIO_FS_ISO_HFS: strcpy(desc, "CD-ROM with both Macintosh HFS and ISO 9660 filesystem"); break; case CDIO_FS_UFS: strcpy(desc, "CD-ROM with Unix UFS"); break; case CDIO_FS_EXT2: strcpy(desc, "CD-ROM with GNU/Linux EXT2 (native) filesystem"); break; case CDIO_FS_3DO: strcpy(desc, "CD-ROM with Panasonic 3DO filesystem"); break; case CDIO_FS_UDFX: strcpy(desc, "CD-ROM with UDFX filesystem"); break; case CDIO_FS_UNKNOWN: strcpy(desc, "CD-ROM with unknown filesystem"); break; case CDIO_FS_XISO: strcpy(desc, "CD-ROM with Microsoft X-BOX XISO filesystem"); break; } return rb_str_new2(desc); } static VALUE _is_file_bool(bool(*pf) (const char *n), VALUE name) { Check_Type(name, T_STRING); SafeStringValue(name); bool res = pf(StringValuePtr(name)); return res ? Qtrue : Qfalse; } static VALUE _is_file_char(char *(*pf) (const char *n), VALUE name) { Check_Type(name, T_STRING); SafeStringValue(name); char *bin = pf(StringValuePtr(name)); if (NULL == bin) { return Qnil; } else { return rb_str_new2(bin); } } VALUE rb_cdio_is_binfile(VALUE module, VALUE name) { return _is_file_char(&cdio_is_binfile, name); } VALUE rb_cdio_is_cuefile(VALUE module, VALUE name) { return _is_file_char(&cdio_is_cuefile, name); } VALUE rb_cdio_is_nrg(VALUE module, VALUE name) { return _is_file_bool(&cdio_is_nrg, name); } VALUE rb_cdio_is_tocfile(VALUE module, VALUE name) { return _is_file_bool(cdio_is_tocfile, name); } VALUE rb_cdio_is_device(int argc, VALUE * argv, VALUE module) { return Qnil; } VALUE rb_cdio_close_tray(VALUE module, VALUE name) { Check_Type(name, T_STRING); SafeStringValue(name); driver_return_code_t rc = cdio_close_tray(StringValuePtr(name), NULL); verify_return_code(rc); return Qtrue; }