-
Notifications
You must be signed in to change notification settings - Fork 0
/
userdevchange.c
65 lines (63 loc) · 1.37 KB
/
userdevchange.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
void editkeyboard(char change[2000]) {
char choice[2000];
char data[2000];
printf("New device will be: %s", change);
printf("Are you sure??? (y/n): ");
fgets(choice, 2000, stdin);
if ((choice[0] != 'y') && (choice[0] != 'Y')) {
printf("Cancelling...\n");
exit(0);
}
char swap[2000] = "#define KEYBOARDNAME \"";
strcat(swap, change);
swap[strlen(swap)-1] = '\"';
FILE *fp;
FILE *fp2;
fp = fopen("keyboard.c", "r");
fp2 = fopen("tempfile.c", "w+");
while (fgets(data, 2000, fp) != NULL) {
if (strstr(data, "#define")) {
fprintf(fp2, "%s\n", swap);
}
else {
fprintf(fp2, "%s", data);
}
}
fclose(fp);
fclose(fp2);
sleep(1);
system("mv tempfile.c keyboard.c");
sleep(1);
system("gcc keyboard.c -o keyboard");
printf("Changed!\n");
}
int main(int argc, char* argv[]) {
int i = 1;
char choice[2000];
char change[2000];
system("xinput -list");
printf("The current saved device is: ");
while (argv[i]) {
printf("%s ", argv[i]);
i++;
}
printf("\nIs this correct? (y/n): ");
fgets(choice, 2000, stdin);
if ((choice[0] == 'y') || (choice[0] == 'Y')) {
exit(0);
}
if ((choice[0] == 'n') || (choice[0] == 'N')) {
printf("New Device Name: ");
fgets(change, 2000, stdin);
}
else {
printf("Bad input, exiting...\n");
exit(1);
}
editkeyboard(change);
return 0;
}