From 0945cfd7a6836c6d7c6174286c842e934c4f6ddb Mon Sep 17 00:00:00 2001 From: cfif Date: Thu, 11 Sep 2025 10:12:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/main.c | 32 ++++++++++++++++++++++++-------- CMakeLists.txt | 11 +---------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/APP/main.c b/APP/main.c index 651a473..e668d5c 100644 --- a/APP/main.c +++ b/APP/main.c @@ -41,22 +41,24 @@ int main(int argc, char *argv[]) { if (argc != 3) { printf("Usage: conv fileIn fileOut\n"); + fflush(stdout); return 1; } FILE *input_file = fopen(argv[1], "r"); if (input_file == NULL) { printf("Error: Failed to open file %s\n", argv[1]); + fflush(stdout); return 1; } - #define BUFFER_SIZE 4096 +#define BUFFER_SIZE 4096 char json_string[BUFFER_SIZE] = {0}; size_t bytes_read = fread(json_string, 1, BUFFER_SIZE, input_file); - printf("Read %zu bytes:\n", bytes_read); - printf("%.*s\n", (int)bytes_read, json_string); + printf("Read from file: \"%s\", %zu bytes:\n", argv[1], bytes_read); + printf("%.*s\n", (int) bytes_read, json_string); fclose(input_file); @@ -72,6 +74,7 @@ int main(int argc, char *argv[]) { if (json == NULL) { printf("Error parsing JSON\n"); + fflush(stdout); return 1; } @@ -108,6 +111,7 @@ int main(int argc, char *argv[]) { } } else { printf("Parsing timestamp (UTC) error"); + fflush(stdout); return 1; } @@ -117,11 +121,13 @@ int main(int argc, char *argv[]) { } else { printf("Parsing timestamp error"); + fflush(stdout); return 1; } } else { printf("Parsing JSON timestamp error"); + fflush(stdout); return 1; } @@ -181,10 +187,12 @@ int main(int argc, char *argv[]) { } else { printf("Parsing coordinate error (1)"); + fflush(stdout); return 1; } } else { printf("Parsing JSON coordinate error"); + fflush(stdout); return 1; } @@ -192,6 +200,7 @@ int main(int argc, char *argv[]) { printf("phone (JSON): %s\n", phoneJS->valuestring); } else { printf("Parsing JSON phone error"); + fflush(stdout); return 1; } @@ -201,7 +210,7 @@ int main(int argc, char *argv[]) { char VIN[17] = {0}; memcpy(VIN, idJS->valuestring, 5); - memcpy(&VIN[5], "1111111111", 10); +// memcpy(&VIN[5], "1111111111", 10); EraGlonassMsdSetVIN(&msd, VIN, sizeof(VIN)); @@ -209,6 +218,7 @@ int main(int argc, char *argv[]) { } else { printf("Parsing JSON id error"); + fflush(stdout); return 1; } @@ -225,18 +235,24 @@ int main(int argc, char *argv[]) { FILE *output_file = fopen(argv[2], "w"); if (output_file == NULL) { - printf("Error: Failed to open file %s\n", argv[1]); + printf("Error: Failed to open file %s\n", argv[2]); + fflush(stdout); return 1; } size_t bytes_written = fwrite(egtsHexStr, 1, egtsHexStrLen, output_file); - printf("Write %zu bytes:\n", bytes_written); - printf("%.*s\n", (int)bytes_written, egtsHexStr); + if (bytes_written != egtsHexStrLen) { + printf("Error: Failed to write file %s\n", argv[2]); + fflush(stdout); + return 1; + } + + printf("Write to file: \"%s\" %zu bytes: %.*s\n", argv[2], bytes_written, (int) bytes_written, egtsHexStr); fclose(output_file); - + fflush(stdout); return 0; diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e75d61..33d333d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,16 +5,7 @@ set(CMAKE_CXX_STANDARD 17) include(modular.cmake) -#link_directories(/usr/local/opt/libpq/lib/) -#include_directories(/usr/local/opt/libpq/include) -#link_directories(/usr/lib/x86_64-linux-gnu/) -#include_directories(/usr/include/postgresql) - -#link_libraries(pq) -#link_libraries(tcp) -#link_libraries(pthread) - -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -funsigned-char -pipe -Wl,-O0 -std=gnu++2a -Wall -Wextra") +#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -funsigned-char -pipe -Wl,-O0 -std=gnu++2a -Wall -Wextra") add_executable(conv ${SOURCES}) target_link_libraries(conv PRIVATE m)