From 75644f9cf2a7aea4f997aed241aeb4f0b10827e7 Mon Sep 17 00:00:00 2001 From: Orian Latroupe Date: Fri, 4 Oct 2024 22:11:47 +0200 Subject: [PATCH] file socket : invert in and out, and little adjustments --- fxlink/fxlink.h | 4 ++-- fxlink/main.c | 31 +++++++++++-------------------- fxlink/modes/interactive.c | 21 ++++++++------------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/fxlink/fxlink.h b/fxlink/fxlink.h index 4fd5e44..490dbfc 100644 --- a/fxlink/fxlink.h +++ b/fxlink/fxlink.h @@ -23,8 +23,8 @@ struct fxlink_options { extern struct fxlink_options options; /* Input/output socket filename in case of -s option */ -extern char* file_in; -extern char* file_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 e04b829..4cf8a7d 100644 --- a/fxlink/main.c +++ b/fxlink/main.c @@ -41,8 +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" -" --filein Send received data to " -" --fileout Send data in to calculator\n" +" --filein Send data in to calculator\n" +" --fileout Send received data to \n" " --libusb-log=LEVEL libusb log level (NONE, ERROR, WARNING, INFO, DEBUG)\n" "\n" "Mode-specific options:\n" @@ -65,12 +65,8 @@ static const char *help_string = 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; +char *file_in; +char *file_out; int main(int argc, char **argv) { @@ -104,8 +100,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 }, + { "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' }, @@ -121,19 +117,14 @@ int main(int argc, char **argv) case 'l': case 'b': case FILE_IN: - if(optarg) - { - options.file_in = true; - file_in = optarg; - } + options.file_in = true; + file_in = optarg; break; case FILE_OUT: - if(optarg) - { - options.file_out = true; - file_out = optarg; - } + options.file_out = true; + file_out = optarg,"w"; break; + case 's': case 'i': case 't': case 'p': diff --git a/fxlink/modes/interactive.c b/fxlink/modes/interactive.c index 6e2c050..066371a 100644 --- a/fxlink/modes/interactive.c +++ b/fxlink/modes/interactive.c @@ -39,17 +39,14 @@ static void handle_new_message(struct fxlink_device *fdev, } if(fxlink_message_is_fxlink_text(msg)) { - char *str = msg->data; - str[msg->size] = '\0'; + char const *str = msg->data; if(options.verbose) printf("------------------\n"); - if(options.file_in) + if(options.file_out) { - FILE *fPtr; - fPtr = fopen(file_in, "a"); - fputs(str, fPtr); - fputs("\n\0",fPtr); - fclose(fPtr); + FILE *out = fopen(file_out,"w"); + fwrite(str,1,msg->size, out); + fclose(out); } fwrite(str, 1, msg->size, stdout); #if 0 @@ -132,13 +129,13 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay, char c[100]; while(1) { - if(options.file_out) + if(options.file_in) { - if ((fptr = fopen(file_out, "r"))) { + if ((fptr = fopen(file_in, "r"))) { fscanf(fptr, "%[^\n]", c); printf("%i",strlen(c)); fxlink_device_start_bulk_OUT(fdev,"fxlink", "text", &c, strlen(c), false); - remove(file_out); + remove(file_in); } } @@ -161,8 +158,6 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay, if(transferred <= 0) continue; - - /* Either start a new message or continue an unfinished one */ if(tr == NULL) tr = fxlink_transfer_make_IN(buffer, transferred);