From 04a7687cdd71badb173ab60c0f42a9c0ad4e2203 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Wed, 24 Dec 2025 22:26:54 +0100 Subject: [PATCH] whoops --- src/fs.c | 9 --------- src/fs.h | 1 - src/lua_rds.c | 21 +++++++++------------ src/lua_rds.h | 2 +- src/rds.c | 4 ++-- src/rds_groups.c | 7 ++++--- src/udp_server.c | 8 ++------ 7 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/fs.c b/src/fs.c index 8b1363e..36ea495 100644 --- a/src/fs.c +++ b/src/fs.c @@ -65,15 +65,6 @@ int encoder_loadFromFile(RDSEncoder *enc) { return 0; } -int encoder_saved() { - char encoderPath[128]; - snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME")); - FILE *file = fopen(encoderPath, "rb"); - if(!file) return 0; - fclose(file); - return 1; -} - void Modulator_saveToFile(RDSModulatorParameters *emp) { char modulatorPath[128]; snprintf(modulatorPath, sizeof(modulatorPath), "%s/.rdsModulator", getenv("HOME")); diff --git a/src/fs.h b/src/fs.h index 23bc7ff..c334700 100644 --- a/src/fs.h +++ b/src/fs.h @@ -6,7 +6,6 @@ void encoder_saveToFile(RDSEncoder *emp); int encoder_loadFromFile(RDSEncoder *emp); -int encoder_saved(); void Modulator_saveToFile(RDSModulatorParameters *emp); void Modulator_loadFromFile(RDSModulatorParameters *emp); diff --git a/src/lua_rds.c b/src/lua_rds.c index 99be54c..401a27b 100644 --- a/src/lua_rds.c +++ b/src/lua_rds.c @@ -586,7 +586,7 @@ void run_lua(char *str, char *cmd_output) { pthread_mutex_unlock(&lua_mutex); } -void lua_group(RDSGroup* group) { +int lua_group(RDSGroup* group) { pthread_mutex_lock(&lua_mutex); lua_getglobal(L, "group"); @@ -595,31 +595,28 @@ void lua_group(RDSGroup* group) { lua_pushinteger(L, group->b); lua_pushinteger(L, group->c); lua_pushinteger(L, group->d); - if (lua_pcall(L, 3, 3, 0) == LUA_OK) { + if (lua_pcall(L, 4, 3, 0) == LUA_OK) { if (!lua_isinteger(L, -1)) { pthread_mutex_unlock(&lua_mutex); - return; + return 0; } if (!lua_isinteger(L, -2)) { pthread_mutex_unlock(&lua_mutex); - return; + return 0; } if (!lua_isinteger(L, -3)) { pthread_mutex_unlock(&lua_mutex); - return; + return 0; } group->d = luaL_checkinteger(L, -1); group->c = luaL_checkinteger(L, -2); group->b = luaL_checkinteger(L, -3); - lua_pop(L, 3); - } else { - fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1)); - lua_pop(L, 1); - } - } else { + lua_pop(L, 2); + } else fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1)); lua_pop(L, 1); - } + } else lua_pop(L, 1); pthread_mutex_unlock(&lua_mutex); + return 1; } void lua_group_ref(RDSGroup* group, int ref) { diff --git a/src/lua_rds.h b/src/lua_rds.h index c2ef2ba..48a08be 100644 --- a/src/lua_rds.h +++ b/src/lua_rds.h @@ -8,7 +8,7 @@ void init_lua(RDSModulator* rds_mod); void run_lua(char *str, char *cmd_output); -void lua_group(RDSGroup* group); +int lua_group(RDSGroup* group); void lua_call_function(const char* function); void lua_group_ref(RDSGroup* group, int ref); void destroy_lua(); \ No newline at end of file diff --git a/src/rds.c b/src/rds.c index 76bbdcc..280f0bd 100644 --- a/src/rds.c +++ b/src/rds.c @@ -28,7 +28,7 @@ void get_rds_eon_group(RDSEncoder* enc, RDSGroup *group); void get_rds_ert_group(RDSEncoder* enc, RDSGroup *group); uint8_t get_rds_custom_groups(RDSEncoder* enc, RDSGroup *group); uint8_t get_rds_custom_groups2(RDSEncoder* enc, RDSGroup *group); -void get_rdsp_lua_group(RDSGroup *group); +int get_rdsp_lua_group(RDSGroup *group); void get_rds_user_oda_group(RDSEncoder* enc, RDSGroup *group); int get_rds_user_oda_group_content(RDSEncoder* enc, RDSGroup *group); @@ -112,7 +112,7 @@ static void get_rds_sequence_group(RDSEncoder* enc, RDSGroup *group, char* grp, get_rds_fasttuning_group(enc, group); break; case 'L': - get_rdsp_lua_group(group); + if(get_rdsp_lua_group(group) == 0) get_rds_ps_group(enc, group); break; case 'O': get_rds_user_oda_group(enc, group); diff --git a/src/rds_groups.c b/src/rds_groups.c index 01d915b..e05fc8e 100644 --- a/src/rds_groups.c +++ b/src/rds_groups.c @@ -366,9 +366,10 @@ uint8_t get_rds_custom_groups2(RDSEncoder* enc, RDSGroup *group) { } return 0; } -void get_rdsp_lua_group(RDSGroup *group) { - lua_group(group); - group->is_type_b = (IS_TYPE_B(group->b) != 0); +int get_rdsp_lua_group(RDSGroup *group) { + int generated = lua_group(group); + if(generated) group->is_type_b = (IS_TYPE_B(group->b) != 0); + return generated; } void get_rds_user_oda_group(RDSEncoder* enc, RDSGroup *group) { diff --git a/src/udp_server.c b/src/udp_server.c index 3abeb9a..03c2e56 100644 --- a/src/udp_server.c +++ b/src/udp_server.c @@ -39,14 +39,13 @@ void poll_udp_server() { static char buf[BUF_SIZE]; static char cmd_buf[BUF_SIZE]; static char cmd_output[BUF_SIZE]; - ssize_t bytes_read; if (poll(&poller, 1, UDP_READ_TIMEOUT_MS) <= 0) return; if (!(poller.revents & POLLIN)) return; memset(buf, 0, BUF_SIZE); client_len = sizeof(client_addr); - bytes_read = recvfrom(sockfd, buf, BUF_SIZE - 1, 0, (struct sockaddr *)&client_addr, &client_len); + ssize_t bytes_read = recvfrom(sockfd, buf, BUF_SIZE - 1, 0, (struct sockaddr *)&client_addr, &client_len); if (bytes_read <= 0) return; buf[bytes_read] = '\0'; @@ -62,10 +61,7 @@ void poll_udp_server() { run_lua(cmd_buf, cmd_output); size_t out_len = strlen(cmd_output); - if (out_len > 0) { - ssize_t sent = sendto(sockfd, cmd_output, out_len, 0, (struct sockaddr *)&client_addr, client_len); - if (sent == -1) perror("sendto"); - } + if (out_len > 0 && sendto(sockfd, cmd_output, out_len, 0, (struct sockaddr *)&client_addr, client_len) == -1) perror("sendto"); // no walrus } token = strtok(NULL, "\r\n"); }