diff options
| -rw-r--r-- | src/config.def.c | 14 | ||||
| -rw-r--r-- | src/main.c | 23 |
2 files changed, 13 insertions, 24 deletions
diff --git a/src/config.def.c b/src/config.def.c index 90004de..6de4b4e 100644 --- a/src/config.def.c +++ b/src/config.def.c @@ -1,15 +1,11 @@ #ifndef config #define config -#define arr_size 3 //change this to how many messages you want to cycle through - char *title="title"; //change the title here -char *arr[arr_size]; - -void init_arr(){ - arr[0]="message 1"; //copy and paste this then change the number to the message your editing - arr[1]="message 2"; - arr[2]="message 3"; -} +char *arr[] = { + "message 1", + "message 2", + "message 3", +}; #endif @@ -2,8 +2,10 @@ #include <fcntl.h> #include <signal.h> #include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sys/select.h> #include <sys/wait.h> #include <unistd.h> @@ -52,15 +54,12 @@ void execlb(char* cmd, char* ret_buf) exit(-5); if (pid == 0) { - dup2(link[1], STDOUT_FILENO); close(link[0]); close(link[1]); execl("/bin/sh", "sh", "-c", cmd, (char*)0); exit(0); - } else { - close(link[1]); int nbytes = read(link[0], buf, sizeof(buf)); if (nbytes > 2047) @@ -86,40 +85,34 @@ int main() servaddr.sin_family = AF_INET; // IPv4 servaddr.sin_port = htons(port); // Server port servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); // Server IP - // register the SIGINT handler (Ctrl+C) + + // register the SIGINT handler (Ctrl+C) signal(SIGINT, &sigintHandler); char* dist = (char*)malloc(sizeof(char) * 2048); execlb("uname -r", dist); dist[strlen(dist) - 1] = '\0'; - init_arr(); - char* comb_string = (char*)malloc(sizeof(char) * 2048); char* song_title = (char*)malloc(sizeof(char) * 2048); - int i = 0; - + size_t i = 0; while (keepRunning) { execlb("src/title.sh", song_title); sprintf(comb_string, "%s\nLinux %s\n%s\n%s", title, dist, arr[i], song_title); - int len = 0; - len = tosc_writeMessage(wbuffer, sizeof(wbuffer), "/chatbox/input", "sTF", comb_string); + uint32_t len = tosc_writeMessage(wbuffer, sizeof(wbuffer), "/chatbox/input", "sTF", comb_string); sendto(socketfd, wbuffer, len, MSG_CONFIRM, (const struct sockaddr*)&servaddr, sizeof(servaddr)); sleep(3); - i = i + 1; - if (i >= arr_size) - i = 0; + i = (i + 1) % (sizeof arr / sizeof arr[0]); } // remove till end if you dont care about sending a clear to chat box when stopping the program. usleep(900000); // if 2 messages are sent to quickly. this one doesnt send. so this seems like a good delay on my machine. comment out if you dont care - int len = 0; - len = tosc_writeMessage(wbuffer, sizeof(wbuffer), "/chatbox/input", "sTF", ""); + uint32_t len = tosc_writeMessage(wbuffer, sizeof(wbuffer), "/chatbox/input", "sTF", ""); sendto(socketfd, wbuffer, len, MSG_CONFIRM, (const struct sockaddr*)&servaddr, sizeof(servaddr)); // end |
