fixes for 98% of all the warnings/errors reported by OS X gcc on tiger
[ardour.git] / libs / evoral / src / libsmf / smf_load.c
index 857f3d485f28294362ebd42d9e7d46f1082192dc..90a22509b57f714354b9d4dcf95901d89f4a24eb 100644 (file)
@@ -206,8 +206,8 @@ parse_mthd_chunk(smf_t *smf)
  * Explanation of Variable Length Quantities is here: http://www.borg.com/~jglatt/tech/midifile/vari.htm
  * Returns 0 iff everything went OK, different value in case of error.
  */
-static int
-extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t *value, uint32_t *len)
+int
+smf_extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t *value, uint32_t *len)
 {
        uint32_t val = 0;
        const unsigned char *c = buf;
@@ -275,7 +275,8 @@ is_escape_byte(const unsigned char status)
 static int32_t
 expected_sysex_length(const unsigned char status, const unsigned char *second_byte, const size_t buffer_length, int32_t *consumed_bytes)
 {
-       uint32_t sysex_length, len;
+       uint32_t sysex_length = 0;
+       uint32_t len = 0;
 
        assert(status == 0xF0);
 
@@ -284,7 +285,7 @@ expected_sysex_length(const unsigned char status, const unsigned char *second_by
                return (-1);
        }
 
-       extract_vlq(second_byte, buffer_length, &sysex_length, &len);
+       smf_extract_vlq(second_byte, buffer_length, &sysex_length, &len);
 
        if (consumed_bytes != NULL)
                *consumed_bytes = len;
@@ -379,6 +380,8 @@ expected_message_length(unsigned char status, const unsigned char *second_byte,
 static int
 extract_sysex_event(const unsigned char *buf, const size_t buffer_length, smf_event_t *event, uint32_t *len, int last_status)
 {
+       (void) last_status;
+       
        int status;
        int32_t vlq_length, message_length;
        const unsigned char *c = buf;
@@ -419,8 +422,11 @@ extract_sysex_event(const unsigned char *buf, const size_t buffer_length, smf_ev
 static int
 extract_escaped_event(const unsigned char *buf, const size_t buffer_length, smf_event_t *event, uint32_t *len, int last_status)
 {
+       (void) last_status;
+       
        int status;
-       int32_t message_length, vlq_length;
+       int32_t message_length = 0;
+       int32_t vlq_length = 0;
        const unsigned char *c = buf;
 
        status = *buf;
@@ -554,7 +560,7 @@ parse_next_event(smf_track_t *track)
        assert(buffer_length > 0);
 
        /* First, extract time offset from previous event. */
-       if (extract_vlq(c, buffer_length, &time, &len))
+       if (smf_extract_vlq(c, buffer_length, &time, &len))
                goto error;
 
        c += len;
@@ -641,7 +647,8 @@ smf_event_is_textual(const smf_event_t *event)
 char *
 smf_event_extract_text(const smf_event_t *event)
 {
-       uint32_t string_length, length_length;
+       uint32_t string_length = 0;
+       uint32_t length_length = 0;
 
        if (!smf_event_is_textual(event))
                return (NULL);
@@ -651,7 +658,7 @@ smf_event_extract_text(const smf_event_t *event)
                return (NULL);
        }
 
-       extract_vlq((void *)&(event->midi_buffer[2]), event->midi_buffer_length - 2, &string_length, &length_length);
+       smf_extract_vlq((void *)&(event->midi_buffer[2]), event->midi_buffer_length - 2, &string_length, &length_length);
 
        if (string_length <= 0) {
                g_critical("smf_event_extract_text: truncated MIDI message.");
@@ -790,12 +797,11 @@ parse_mtrk_chunk(smf_track_t *track)
 }
 
 /**
- * Allocate buffer of proper size and read file contents into it.  Close file afterwards.
+ * Allocate buffer of proper size and read file contents into it.
  */
 static int
-load_file_into_buffer(void **file_buffer, size_t *file_buffer_length, const char *file_name)
+load_file_into_buffer(void **file_buffer, size_t *file_buffer_length, FILE* stream)
 {
-       FILE *stream = fopen(file_name, "r");
        long offset;
 
        if (stream == NULL) {
@@ -837,12 +843,6 @@ load_file_into_buffer(void **file_buffer, size_t *file_buffer_length, const char
                return (-6);
        }
        
-       if (fclose(stream)) {
-               g_critical("fclose(3) failed: %s", strerror(errno));
-
-               return (-7);
-       }
-
        return (0);
 }
 
@@ -899,17 +899,17 @@ smf_load_from_memory(const void *buffer, const size_t buffer_length)
 /**
  * Loads SMF file.
  *
- * \param file_name Path to the file.
+ * \param file Open file.
  * \return SMF or NULL, if loading failed.
  */
 smf_t *
-smf_load(const char *file_name)
+smf_load(FILE *file)
 {
        size_t file_buffer_length;
        void *file_buffer;
        smf_t *smf;
 
-       if (load_file_into_buffer(&file_buffer, &file_buffer_length, file_name))
+       if (load_file_into_buffer(&file_buffer, &file_buffer_length, file))
                return (NULL);
 
        smf = smf_load_from_memory(file_buffer, file_buffer_length);