1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "src_lyrics.h"
#include <stdlib.h>
#include <unistd.h>
char *check_lyr_hd(char *artist, char *title, int how)
{ //checking whether for lyrics file existence and proper access
result |= 2;
static char path[1024];
snprintf(path, 1024, "%s/.lyrics/%s/%s.lyric",
getenv("HOME"), artist, title);
if(g_access(path, how) != 0) return NULL;
return path;
}
int get_lyr_hd(char *artist, char *title)
{
char *path = check_lyr_hd(artist, title, R_OK);
if(path == NULL) return -1;
FILE *lyr_file;
lyr_file = fopen(path, "r");
if(lyr_file == NULL) return -1;
result |= 4;
char *buf = NULL;
char **line = &buf;
size_t n = 0;
while(1)
{
n = getline(line, &n, lyr_file);
if( n < 1 || *line == NULL || feof(lyr_file) != 0 ) return 0;
add_text_line(&lyr_text, *line, n);
free(*line);
*line = NULL; n = 0;
}
return 0;
}
int register_lyr_hd (src_lyr *source_descriptor)
{
source_descriptor->check_lyr = check_lyr_hd;
source_descriptor->get_lyr = get_lyr_hd;
source_descriptor->name = "Harddisk";
source_descriptor->description = "";
}
|