/**
 * call-seq:
 *  put(first_track, sectors, offsets)
 * 
 * Set the TOC information directly instead of reading it from a device.
 * 
 * Use this instead of read if the TOC information was already read elsewhere
 * and you want to recalculate the ID.
 * Throws an _Exception_ if the CD's TOC can not be read.
 * 
 * <b>Parameters:</b>
 * [first_track] The number of the first track on the disc (usually 1).
 * [sectors] The total number of sectors on the disc.
 * [offsets] Array of all track offsets. The number of tracks must not exceed 99.
 *
 * Raises:: Exception
 */
static VALUE mb_discid_put(VALUE self, VALUE first_track, VALUE sectors,
                           VALUE offsets)
{
        DiscId *disc;                       /* Pointer to the disc struct */
        long length = RARRAY_LEN(offsets);  /* length of the offsets array */
        int cfirst  = NUM2INT(first_track); /* number of the first track */
        int clast   = length + 1 - cfirst;  /* number of the last track */
        int coffsets[100];                  /* C array to hold the offsets */
        int i = 1;                          /* Counter for iterating over coffsets*/
        
        Data_Get_Struct(self, DiscId, disc);
        
        /* Convert the Ruby array to an C array of integers. discid_puts expects
           always an offsets array with exactly 100 elements. */
        coffsets[0] = NUM2INT(sectors); /* 0 is always the leadout track */
        while (i <= length && i < 100)
        {
                coffsets[i] = NUM2INT(rb_ary_entry(offsets, i - 1));
                i++;
        }
        
        /* Mark the disc id as unread in case something goes wrong. */
        rb_iv_set(self, "@read", Qfalse);
        
        /* Read the discid */
        if (discid_put(disc, cfirst, clast, coffsets) == 0)
                rb_raise(rb_eException, "%s", discid_get_error_msg(disc));
        else /* Remember that we already read the ID. */
                rb_iv_set(self, "@read", Qtrue);
        
        return Qnil;
}