-
Notifications
You must be signed in to change notification settings - Fork 0
/
clapl.c
71 lines (54 loc) · 1.64 KB
/
clapl.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "clapl.h"
void load_config (configparser *cp)
{
// loading the configuration file
LOGGER_FILE = stdout;
chdir(getenv("HOME")); // goto the home directory
int ret = mkdir(".config/clapl", 0700); // create '.config/clapl/ if it does not exits
if (ret != 0 && ret != -1)
logcmd(LOG_MSG, "could not create local config directory");
struct stat sb;
ret = stat(".config/clapl/config", &sb); // check if config file exists
if (ret != 0)
{
fprintf(stderr, "could not load config file\ncheck ~/.config/clapl/config");
free(cp);
exit(1);
}
//initialize and load config file
configparser_init(cp, ".config/clapl/config", 5, '=');
configparser_load(cp);
}
int main (int argc, char **argv)
{
srand(time(NULL));
configparser *cp = malloc(sizeof(configparser));
load_config(cp);
LOGGER_PATH = configparser_get_string(cp, "log_file"); // set path for log file
LOGGER_FILE = fopen(LOGGER_PATH, "w");
playback_init(); // initialize libav and libao
sqlite3 *db = db_init();
ui_init(); // initialize userinterface
userinterface *ui = ui_create(db, cp);
ui->c->commands = load_commands();
audio *a = audio_create();
ui_print_info(ui, a);
ui_refresh(ui);
pthread_t thread;
char ch;
while (1)
{
ch = getch();
input(ui, ui->c, a, &thread, ch);
if (ch == 'q' || ch == 'Q')
break;
}
endwin(); // close ncurses
audio_free(&a);
configparser_free(&cp);
cache_close(ui->c);
free(ui);
db_close(db);
fclose(LOGGER_FILE);
return EXIT_SUCCESS;
}