From 6419f17b6418f286c0d0f4da96b095feb5fa9910 Mon Sep 17 00:00:00 2001 From: harrypotter360 Date: Mon, 9 Sep 2024 23:21:32 +0200 Subject: [PATCH] Rename 'socket' to 'file' and split in/out file --- fxlink/fxlink.h | 7 ++++--- fxlink/main.c | 31 ++++++++++++++++++++++++------- fxlink/modes/interactive.c | 10 +++++----- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/fxlink/fxlink.h b/fxlink/fxlink.h index 650473a..4fd5e44 100644 --- a/fxlink/fxlink.h +++ b/fxlink/fxlink.h @@ -16,14 +16,15 @@ struct fxlink_options { FILE *log_file; /* Extra details (mainly interactive messages) */ bool verbose; - bool write_to_socket; + bool file_in; + bool file_out; }; extern struct fxlink_options options; /* Input/output socket filename in case of -s option */ -extern char* socket_in; -extern char* socket_out; +extern char* file_in; +extern char* file_out; /* Main function for -l */ int main_list(struct fxlink_filter *filter, delay_t *delay, diff --git a/fxlink/main.c b/fxlink/main.c index cd9b287..e04b829 100644 --- a/fxlink/main.c +++ b/fxlink/main.c @@ -41,7 +41,8 @@ static const char *help_string = " -w Wait this many seconds for a calculator to connect\n" " -w Wait indefinitely for a calculator to connect\n" " -f Filter which calculators we connect to (see below)\n" -" -s Send received data to IN file and send data in OUT file to calculator\n" +" --filein Send received data to " +" --fileout Send data in to calculator\n" " --libusb-log=LEVEL libusb log level (NONE, ERROR, WARNING, INFO, DEBUG)\n" "\n" "Mode-specific options:\n" @@ -63,6 +64,10 @@ static const char *help_string = /* Global options */ struct fxlink_options options; +/* In and out files */ +char* file_in; +char* file_out; + /* Input/output socket filenames for -s option */ char *socket_in; char *socket_out; @@ -77,14 +82,15 @@ int main(int argc, char **argv) options.log_file = NULL; options.verbose = false; - options.write_to_socket = false; + options.file_in = false; + options.file_out = false; setlocale(LC_ALL, ""); //--- // Command-line argument parsing //--- - enum { LIBUSB_LOG=1, LOG_TO_FILE=2, OUT_FOLDER=3 }; + enum { LIBUSB_LOG=1, LOG_TO_FILE=2, OUT_FOLDER=3 ,FILE_IN=4,FILE_OUT=5}; const struct option longs[] = { { "help", no_argument, NULL, 'h' }, { "list", no_argument, NULL, 'l' }, @@ -98,6 +104,8 @@ int main(int argc, char **argv) { "repeat", no_argument, NULL, 'r' }, { "verbose", no_argument, NULL, 'v' }, { "folder", required_argument, NULL, OUT_FOLDER }, + { "filein", required_argument, NULL, FILE_IN }, + { "fileout", required_argument, NULL, FILE_OUT }, /* Deprecated options ignored for compatibility: */ { "quiet", no_argument, NULL, 'q' }, { "unmount", no_argument, NULL, 'u' }, @@ -112,10 +120,19 @@ int main(int argc, char **argv) return 0; case 'l': case 'b': - case 's': - options.write_to_socket = true; - socket_in = argv[optind]; - socket_out = argv[optind+1]; + case FILE_IN: + if(optarg) + { + options.file_in = true; + file_in = optarg; + } + break; + case FILE_OUT: + if(optarg) + { + options.file_out = true; + file_out = optarg; + } break; case 'i': case 't': diff --git a/fxlink/modes/interactive.c b/fxlink/modes/interactive.c index 42dbd7c..6e2c050 100644 --- a/fxlink/modes/interactive.c +++ b/fxlink/modes/interactive.c @@ -43,10 +43,10 @@ static void handle_new_message(struct fxlink_device *fdev, str[msg->size] = '\0'; if(options.verbose) printf("------------------\n"); - if(options.write_to_socket) + if(options.file_in) { FILE *fPtr; - fPtr = fopen(socket_in, "a"); + fPtr = fopen(file_in, "a"); fputs(str, fPtr); fputs("\n\0",fPtr); fclose(fPtr); @@ -132,13 +132,13 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay, char c[100]; while(1) { - if(options.write_to_socket) + if(options.file_out) { - if ((fptr = fopen(socket_out, "r"))) { + if ((fptr = fopen(file_out, "r"))) { fscanf(fptr, "%[^\n]", c); printf("%i",strlen(c)); fxlink_device_start_bulk_OUT(fdev,"fxlink", "text", &c, strlen(c), false); - remove(socket_out); + remove(file_out); } }