This repository was archived by the owner on Mar 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeat.c
More file actions
131 lines (113 loc) · 2.64 KB
/
repeat.c
File metadata and controls
131 lines (113 loc) · 2.64 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <linux/input.h>
#include <linux/input-event-codes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <string.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/wait.h>
int msleep(long time)
{
struct timespec timeDet;
int res;
timeDet.tv_sec = time / 1000;
timeDet.tv_nsec = (time % 1000) * 1000000;
do
{
res = nanosleep(&timeDet, &timeDet);
}
while (res && errno == EINTR);
return res;
}
int callSound(char* path)
{
int child = fork();
if (child == 0)
{
char finalPath[60];
strcpy(finalPath, getenv("HOME"));
strcat(finalPath, "/.local/share/sounds/");
strcat(finalPath, path);
execlp("ffmpeg", "ffmpeg", "-loglevel", "error", "-i", finalPath, "-f", "alsa", "default", NULL);
}
else if (child < 0)
{
printf("Could not generate sound %s\n", path);
exit(5);
}
else
{
return child;
}
}
void callErrorSound(int code)
{
int returnCode = callSound("error.wav");
wait(NULL);
for (int i = 0; i < code; i++)
{
returnCode = callSound("bit.wav");
wait(NULL);
}
}
int main(int argc, char **argv)
{
const int BUFFER_LENGTH = 120;
const int ARG_LENGTH = 20;
const int MAX_ARGS = 20;
/*
* We need this command for when we trigger the app from the command line,
* because otherwise the upstroke on the enter key will kill the app.
*/
int waitEnter = 0;
char* ARGS[MAX_ARGS];
int numArgs = 0;
ARGS[numArgs++] = "play";
//ARGS[numArgs++] = "--directory=/home/markil3/.local/share/lollypop";
char* BUFFER = (char*) calloc(ARG_LENGTH, sizeof(char));
int index = 0;
BUFFER[index] = '\0';
FILE* fd;
int len;
fd = fopen("/tmp/play_args.txt", "r");
if (fd < 0)
{
callErrorSound(1);
exit(1);
}
do
{
len = fscanf(fd, "%s", BUFFER);
if (len < 0)
{
break;
}
ARGS[numArgs++] = BUFFER;
BUFFER = (char*) calloc(ARG_LENGTH, sizeof(char));
}
while (len >= 0);
fclose(fd);
ARGS[numArgs] = NULL;
if (index > 0)
{
/*
* If index was not reset, then we canceled.
*/
callSound("end.wav");
exit(0);
}
callSound("triggerDeactivate.wav");
printf("Running args: ");
for (int i = 0; i <= numArgs; i++)
{
printf("'%s' ", ARGS[i]);
}
printf("\n");
execvp(ARGS[0], ARGS);
}