uploaded code to gitea
This commit is contained in:
68
cli_interface.c
Normal file
68
cli_interface.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("INFO: interface\n");
|
||||
|
||||
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
|
||||
struct sockaddr_un addr = {0};
|
||||
addr.sun_family = AF_UNIX;
|
||||
strcpy(addr.sun_path, "/tmp/my_wallpaper.sock");
|
||||
|
||||
connect(fd, (struct sockaddr*)&addr, sizeof(addr));
|
||||
|
||||
if(argc < 2) {
|
||||
printf("command required\n");
|
||||
printf("usage %s command [options]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(strcmp(argv[1], "pause") == 0){
|
||||
char command = 'p';
|
||||
write(fd, &command, 1);
|
||||
} else if(strcmp(argv[1], "next") == 0){
|
||||
char command = 'n';
|
||||
write(fd, &command, 1);
|
||||
} else if(strcmp(argv[1], "back") == 0){
|
||||
char command = 'b';
|
||||
write(fd, &command, 1);
|
||||
} else if(strcmp(argv[1], "interval") == 0){
|
||||
char command = 't';
|
||||
write(fd, &command, 1);
|
||||
if(argc < 3) {
|
||||
printf("interval requires time as argument\n");
|
||||
printf("usage %s interval time\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
char *endptr;
|
||||
long number = strtol(argv[2], &endptr, 10);
|
||||
|
||||
if (*endptr != '\0') {
|
||||
printf("Conversion failed: %s is not a valid number.\n", argv[2]);
|
||||
return 1;
|
||||
}
|
||||
char value1 = number >> 8;
|
||||
char value2 = number;
|
||||
write(fd, &value1, 1);
|
||||
write(fd, &value2, 1);
|
||||
} else if(strcmp(argv[1], "info") == 0){
|
||||
char command = 'i';
|
||||
write(fd, &command, 1);
|
||||
} else if(strcmp(argv[1], "static") == 0){
|
||||
char command = 'c';
|
||||
write(fd, &command, 1);
|
||||
} else {
|
||||
printf("unknown command\n");
|
||||
printf("available commands [pause, next, back, interval, info, static]");
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user