summaryrefslogtreecommitdiff
path: root/channel.c
diff options
context:
space:
mode:
Diffstat (limited to 'channel.c')
-rw-r--r--channel.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/channel.c b/channel.c
index cab4612..065e606 100644
--- a/channel.c
+++ b/channel.c
@@ -22,45 +22,43 @@ struct channel_t *channel_add(const char *name) {
}
struct channel_t *channel = &channels[channel_count-1];
channel->name = strdup(name);
- channel->file_count = 0;
channel->files = NULL;
return channel;
}
-int channel_set_file_count(struct channel_t *channel, int count) {
- channel->files = malloc(count * sizeof(struct channel_file_t));
- if(!channel->files) {
- char *error = strerror(errno);
- fprintf(stderr, "Could not allocate memory for channel files (%s): %s\n", channel->name, error);
- return 0;
- }
- channel->file_count = count;
- return 1;
-}
-
-int channel_set_file(struct channel_t *channel, int index, const char *path, int rs_index) {
- struct channel_file_t *file;
- /* Make sure index is in range. */
- if(!(index < channel->file_count))
- return 0;
- file = &channel->files[index];
+struct channel_file_t *channel_file_add(struct channel_t *channel, const char *path, int rs_index) {
+ struct channel_file_t *file = malloc(sizeof(struct channel_file_t));
+ struct channel_file_t *last = channel->files;
+ if(last) {
+ while(last->next) last = last->next;
+ last->next = file;
+ } else
+ channel->files = file;
file->path = strdup(path);
file->rs = rs_get(rs_index);
- /* Fail if we don't get a regex set. */
+ file->next = NULL;
if(!file->rs)
- return 0;
- return 1;
+ return NULL;
+ return file;
+}
+
+int channel_get_count() {
+ return channel_count;
+}
+
+struct channel_t *channel_get(int index) {
+ return (index < channel_count ? &channels[index] : NULL);
}
void channel_free() {
for(int i = 0; i < channel_count; i++) {
free(channels[i].name);
- /* Free all file path strings. */
- for(int j = 0; j < channels[i].file_count; j++) {
- free(channels[i].files[j].path);
+ struct channel_file_t *file = channels[i].files;
+ while(file) {
+ struct channel_file_t *next = file->next;
+ free(file);
+ file = next;
}
- /* 'files' is a dynamically allocated array, must be freed. */
- free(channels[i].files);
}
free(channels);
channels = NULL;