diff options
Diffstat (limited to 'src/src_lyrics.c')
-rw-r--r-- | src/src_lyrics.c | 238 |
1 files changed, 114 insertions, 124 deletions
diff --git a/src/src_lyrics.c b/src/src_lyrics.c index 935fded16..ecacef250 100644 --- a/src/src_lyrics.c +++ b/src/src_lyrics.c @@ -28,72 +28,69 @@ int get_text_line(formed_text *text, int num, char *dest, int len) { - memset(dest, '\0', len*sizeof(char)); - if(num >= text->lines->len-1) return -1; - int linelen; - if(num == 0) - { - linelen = g_array_index(text->lines, int, num); - memcpy(dest, text->text->str, linelen*sizeof(char)); - } - else if(num == 1) - { //dont ask me why, but this is needed.... - linelen = g_array_index(text->lines, int, num) - - g_array_index(text->lines, int, num-1); - memcpy(dest, &text->text->str[g_array_index(text->lines, int, num-1)], - linelen*sizeof(char)); - } - else - { - linelen = g_array_index(text->lines, int, num+1) - - g_array_index(text->lines, int, num); - memcpy(dest, &text->text->str[g_array_index(text->lines, int, num)], - linelen*sizeof(char)); - } + memset(dest, '\0', len*sizeof(char)); + if (num >= text->lines->len - 1) + return -1; + int linelen; + if (num == 0) { + linelen = g_array_index(text->lines, int, num); + memcpy(dest, text->text->str, linelen*sizeof(char)); + } else if (num == 1) { //dont ask me why, but this is needed.... + linelen = g_array_index(text->lines, int, num) + - g_array_index(text->lines, int, num-1); + memcpy(dest, &text->text->str[g_array_index(text->lines, int, num-1)], + linelen*sizeof(char)); + } else { + linelen = g_array_index(text->lines, int, num+1) + - g_array_index(text->lines, int, num); + memcpy(dest, &text->text->str[g_array_index(text->lines, int, num)], + linelen*sizeof(char)); + } + dest[linelen] = '\n'; - dest[linelen+1] = '\0'; - - return 0; + dest[linelen + 1] = '\0'; + + return 0; } - + void add_text_line(formed_text *dest, const char *src, int len) { - // need this because g_array_append_val doesnt work with literals - // and expat sends "\n" as an extra line everytime - if(len == 0) - { - dest->val = strlen(src); - if(dest->lines->len > 0) dest->val += g_array_index(dest->lines, int, - dest->lines->len-1); - g_string_append(dest->text, src); - g_array_append_val(dest->lines, dest->val); - return; - } - if(len > 1 || dest->val == 0) - { - dest->val = len; - if(dest->lines->len > 0) dest->val += g_array_index(dest->lines, int, - dest->lines->len-1); - } - else if (len < 6 && dest->val != 0) dest->val = 0; - - if(dest->val > 0) - { - g_string_append_len(dest->text, src, len); - g_array_append_val(dest->lines, dest->val); - } + // need this because g_array_append_val doesnt work with literals + // and expat sends "\n" as an extra line everytime + if(len == 0) { + dest->val = strlen(src); + if(dest->lines->len > 0) dest->val += g_array_index(dest->lines, int, + dest->lines->len-1); + g_string_append(dest->text, src); + g_array_append_val(dest->lines, dest->val); + return; + } + + if(len > 1 || dest->val == 0) { + dest->val = len; + if(dest->lines->len > 0) dest->val += g_array_index(dest->lines, int, + dest->lines->len-1); + } else if (len < 6 && dest->val != 0) + dest->val = 0; + + if (dest->val > 0) { + g_string_append_len(dest->text, src, len); + g_array_append_val(dest->lines, dest->val); + } } void formed_text_init(formed_text *text) { - if(text->text != NULL) g_string_free(text->text, TRUE); - text->text = g_string_new(""); - - if(text->lines != NULL) g_array_free(text->lines, TRUE); - text->lines = g_array_new(FALSE, TRUE, 4); - - text->val = 0; + if (text->text != NULL) + g_string_free(text->text, TRUE); + text->text = g_string_new(""); + + if (text->lines != NULL) + g_array_free(text->lines, TRUE); + text->lines = g_array_new(FALSE, TRUE, 4); + + text->val = 0; } #ifdef ENABLE_LYRSRC_LEOSLYRICS @@ -108,98 +105,91 @@ int register_lyr_hd (src_lyr *source_descriptor); int src_lyr_stack_init () { - src_lyr_stack = g_array_new (TRUE, FALSE, sizeof (src_lyr*)); + src_lyr_stack = g_array_new (TRUE, FALSE, sizeof (src_lyr*)); #ifdef ENABLE_LYRSRC_HD - src_lyr *src_lyr_hd = malloc (sizeof (src_lyr)); - src_lyr_hd->register_src_lyr = register_lyr_hd; - g_array_append_val (src_lyr_stack, src_lyr_hd); + src_lyr *src_lyr_hd = malloc (sizeof (src_lyr)); + src_lyr_hd->register_src_lyr = register_lyr_hd; + g_array_append_val (src_lyr_stack, src_lyr_hd); #endif -#ifdef ENABLE_LYRSRC_LEOSLYRICS - src_lyr *src_lyr_leoslyrics = malloc (sizeof (src_lyr)); - src_lyr_leoslyrics->register_src_lyr = register_lyr_leoslyrics; - g_array_append_val (src_lyr_stack, src_lyr_leoslyrics); +#ifdef ENABLE_LYRSRC_LEOSLYRICS + src_lyr *src_lyr_leoslyrics = malloc (sizeof (src_lyr)); + src_lyr_leoslyrics->register_src_lyr = register_lyr_leoslyrics; + g_array_append_val (src_lyr_stack, src_lyr_leoslyrics); #endif #ifndef DISABLE_PLUGIN_SYSTEM - src_lyr_plugins_load (); + src_lyr_plugins_load (); #endif - } int src_lyr_init () { - src_lyr_stack_init (); - - int i = 0; - while (g_array_index (src_lyr_stack, src_lyr*, i) != NULL) - { - src_lyr *i_stack; - i_stack = g_array_index (src_lyr_stack, src_lyr*, i); - i_stack->register_src_lyr (i_stack); - i++; - } - return 0; + src_lyr_stack_init (); + + int i = 0; + while (g_array_index (src_lyr_stack, src_lyr*, i) != NULL) { + src_lyr *i_stack; + i_stack = g_array_index (src_lyr_stack, src_lyr*, i); + i_stack->register_src_lyr (i_stack); + i++; + } + return 0; } int get_lyr_by_src (int priority, char *artist, char *title) { - if(src_lyr_stack->len == 0) return -1; - g_array_index (src_lyr_stack, src_lyr*, priority)->get_lyr (artist, title); - return 0; + if(src_lyr_stack->len == 0) return -1; + g_array_index (src_lyr_stack, src_lyr*, priority)->get_lyr (artist, title); + return 0; } int src_lyr_load_plugin_file (const char *file) { - GString *path; - path = g_string_new (PLUGIN_DIR_SYSTEM); - g_string_append (path, "/"); - g_string_append (path, file); - - src_lyr_plugin_register register_func; - src_lyr *new_src = malloc (sizeof (src_lyr)); - new_src->module = g_module_open (path->str, G_MODULE_BIND_LAZY); - if (!g_module_symbol (new_src->module, "register_me", (gpointer*) ®ister_func)) - return -1; - new_src->register_src_lyr = register_func; - g_array_append_val (src_lyr_stack, new_src); - return 0; + GString *path; + path = g_string_new (PLUGIN_DIR_SYSTEM); + g_string_append (path, "/"); + g_string_append (path, file); + + src_lyr_plugin_register register_func; + src_lyr *new_src = malloc (sizeof (src_lyr)); + new_src->module = g_module_open (path->str, G_MODULE_BIND_LAZY); + if (!g_module_symbol (new_src->module, "register_me", (gpointer*) ®ister_func)) + return -1; + new_src->register_src_lyr = register_func; + g_array_append_val (src_lyr_stack, new_src); + return 0; } - + void src_lyr_plugins_load_from_dir (GDir *plugin_dir) { - const gchar *cur_file; - - for (;;) - { - cur_file = g_dir_read_name (plugin_dir); - if (cur_file == NULL) break; - src_lyr_load_plugin_file (cur_file); - } -} - + const gchar *cur_file; + for (;;) { + cur_file = g_dir_read_name (plugin_dir); + if (cur_file == NULL) break; + src_lyr_load_plugin_file (cur_file); + } +} int src_lyr_plugins_load () { - GDir *plugin_dir; - - plugin_dir = g_dir_open (PLUGIN_DIR_SYSTEM, 0, NULL); - if (plugin_dir == NULL) - return -1; - src_lyr_plugins_load_from_dir (plugin_dir); - - GString *user_dir_path; - user_dir_path = g_string_new (g_get_home_dir()); - g_string_append (user_dir_path, PLUGIN_DIR_USER); - - plugin_dir = g_dir_open (user_dir_path->str, 0, NULL); - if (plugin_dir == NULL) - return -1; - src_lyr_plugins_load_from_dir (plugin_dir); - - return 0; -} + GDir *plugin_dir; - + plugin_dir = g_dir_open (PLUGIN_DIR_SYSTEM, 0, NULL); + if (plugin_dir == NULL) + return -1; + src_lyr_plugins_load_from_dir (plugin_dir); + + GString *user_dir_path; + user_dir_path = g_string_new (g_get_home_dir()); + g_string_append (user_dir_path, PLUGIN_DIR_USER); + + plugin_dir = g_dir_open (user_dir_path->str, 0, NULL); + if (plugin_dir == NULL) + return -1; + src_lyr_plugins_load_from_dir (plugin_dir); + + return 0; +} |