static sound_file *check_write_date(const char *name, sound_file *sf) { if (sf) { time_t date; date = local_file_write_date(name); if (date == sf->write_date) return(sf); if ((sf->header_type == MUS_RAW) && (mus_header_no_header(name))) { int chan; mus_long_t data_size; /* sound has changed since we last read it, but it has no header, so * the only sensible thing to check is the new length (i.e. caller * has set other fields by hand) */ sf->write_date = date; chan = mus_file_open_read(name); data_size = lseek(chan, 0L, SEEK_END); sf->true_file_length = data_size; sf->samples = mus_bytes_to_samples(sf->data_format, data_size); CLOSE(chan, name); return(sf); } /* otherwise our data base is out-of-date, so clear it out */ free_sound_file(sf); } return(NULL); }
int mus_sound_prune(void) { int i, pruned = 0; for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (!(mus_file_probe(sound_table[i]->file_name)))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; pruned++; } return(pruned); }
int mus_sound_forget(const char *name) { int i, len, len2, short_len = 0; bool free_name = false; char *short_name = NULL; if (name == NULL) return(MUS_ERROR); len = strlen(name); if (len > 6) len2 = len - 6; else len2 = len / 2; if (name[0] == '/') { for (i = 0; i < len; i++) if (name[i] == '/') short_name = (char *)(name + i + 1); } else { short_name = mus_expand_filename(name); free_name = true; } if (short_name) short_len = strlen(short_name); if (name) { for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (((sound_table[i]->file_name_length == len) && (sound_table[i]->file_name[len2] == name[len2]) && (strcmp(name, sound_table[i]->file_name) == 0)) || ((short_name) && (sound_table[i]->file_name_length == short_len) && (strcmp(short_name, sound_table[i]->file_name) == 0)))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; } } if (free_name) free(short_name); return(MUS_NO_ERROR); }
int mus_sound_prune(void) { int j, pruned = 0; for (j = 0; j < NUM_SOUND_TABLES; j++) { int i, sound_table_size; sound_file **sound_table; sound_table = sound_tables[j]; sound_table_size = sound_table_sizes[j]; for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (!(mus_file_probe(sound_table[i]->file_name)))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; pruned++; } } return(pruned); }
int mus_sound_forget(const char *name) { /* apparently here we want to forget either name or the expanded or contracted forms of name -- as many as we find! */ int i, len, len2, short_len = 0; bool free_name = false; char *short_name = NULL; sound_file **sound_table; int sound_table_size, index; char c; if (name == NULL) return(MUS_ERROR); len = strlen(name); if (len > 6) len2 = len - 6; else len2 = len / 2; c = name[len2]; if (name[0] == '/') { for (i = 0; i < len; i++) if (name[i] == '/') short_name = (char *)(name + i + 1); } else { short_name = mus_expand_filename(name); free_name = true; } if (short_name) short_len = strlen(short_name); index = sound_file_hash_index(name, len); sound_table = sound_tables[index]; sound_table_size = sound_table_sizes[index]; for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (sound_table[i]->file_name_length == len) && (sound_table[i]->file_name[len2] == c) && (mus_strcmp(name, sound_table[i]->file_name))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; } if (short_name) { if (short_len > 6) len2 = short_len - 6; else len2 = short_len / 2; c = short_name[len2]; index = sound_file_hash_index(short_name, short_len); sound_table = sound_tables[index]; sound_table_size = sound_table_sizes[index]; for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (sound_table[i]->file_name_length == short_len) && (sound_table[i]->file_name[len2] == c) && (mus_strcmp(short_name, sound_table[i]->file_name))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; } } if (free_name) free(short_name); return(MUS_NO_ERROR); }