-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
95 lines (77 loc) · 1.57 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* See LICENSE file for copyright and license details. */
#include "main.h"
static void checklocale(void);
static void dochecks(struct info *);
static struct info *info_create(void);
static void info_free(struct info *);
static void
checklocale(void)
{
char *locale;
locale = setlocale(LC_ALL, "");
if (locale == NULL ||
(strstr(locale, "UTF-8") == NULL &&
strstr(locale, "utf-8") == NULL &&
strstr(locale, "UTF8") == NULL &&
strstr(locale, "utf8") == NULL))
errx(1, "UTF-8 locale expected");
}
static void
dochecks(struct info *data)
{
if (data->state == PLAY) {
/* Tracks need to be reported if they are playing
* for more than 30 seconds.
*/
if (play_isoverthirtymark(data) == TRUE)
report(data);
if (play_ended(data) == TRUE)
play_next(data);
}
}
static struct info *
info_create(void)
{
struct info *data;
data = malloc(sizeof(struct info));
if (data == NULL)
err(1, NULL);
/* Initialize data */
data->quit = FALSE;
data->state = START;
data->playtoken = NULL;
data->m = NULL;
data->mlist = NULL;
data->search_str = NULL;
data->slist_head = NULL;
data->scroll = 0;
return data;
}
static void
info_free(struct info *data)
{
free(data->playtoken);
mix_free(data->m);
free(data->search_str);
searchstr_clear(data);
free(data);
}
int
main(void)
{
struct info *data;
/* Initialize */
checklocale();
data = info_create();
draw_init();
play_init(data);
while (data->quit != TRUE) {
dochecks(data);
draw_redraw(data);
key_handle(data);
}
play_exit(data);
info_free(data);
draw_exit();
return 0;
}