file socket : invert in and out, and little adjustments

This commit is contained in:
Orian Latroupe 2024-10-04 22:11:47 +02:00
parent 6419f17b64
commit 75644f9cf2
3 changed files with 21 additions and 35 deletions

View file

@ -41,8 +41,8 @@ static const char *help_string =
" -w <SECONDS> Wait this many seconds for a calculator to connect\n" " -w <SECONDS> Wait this many seconds for a calculator to connect\n"
" -w Wait indefinitely for a calculator to connect\n" " -w Wait indefinitely for a calculator to connect\n"
" -f <FILTER> Filter which calculators we connect to (see below)\n" " -f <FILTER> Filter which calculators we connect to (see below)\n"
" --filein <FILE> Send received data to <FILE>" " --filein <FILE> Send data in <FILE> to calculator\n"
" --fileout <FILE> Send data in <FILE> to calculator\n" " --fileout <FILE> Send received data to <FILE>\n"
" --libusb-log=LEVEL libusb log level (NONE, ERROR, WARNING, INFO, DEBUG)\n" " --libusb-log=LEVEL libusb log level (NONE, ERROR, WARNING, INFO, DEBUG)\n"
"\n" "\n"
"Mode-specific options:\n" "Mode-specific options:\n"
@ -68,10 +68,6 @@ struct fxlink_options options;
char *file_in; char *file_in;
char *file_out; char *file_out;
/* Input/output socket filenames for -s option */
char *socket_in;
char *socket_out;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int rc=1, mode=0, error=0, option=0, loglevel=LIBUSB_LOG_LEVEL_WARNING; int rc=1, mode=0, error=0, option=0, loglevel=LIBUSB_LOG_LEVEL_WARNING;
@ -121,19 +117,14 @@ int main(int argc, char **argv)
case 'l': case 'l':
case 'b': case 'b':
case FILE_IN: case FILE_IN:
if(optarg)
{
options.file_in = true; options.file_in = true;
file_in = optarg; file_in = optarg;
}
break; break;
case FILE_OUT: case FILE_OUT:
if(optarg)
{
options.file_out = true; options.file_out = true;
file_out = optarg; file_out = optarg,"w";
}
break; break;
case 's':
case 'i': case 'i':
case 't': case 't':
case 'p': case 'p':

View file

@ -39,17 +39,14 @@ static void handle_new_message(struct fxlink_device *fdev,
} }
if(fxlink_message_is_fxlink_text(msg)) { if(fxlink_message_is_fxlink_text(msg)) {
char *str = msg->data; char const *str = msg->data;
str[msg->size] = '\0';
if(options.verbose) if(options.verbose)
printf("------------------\n"); printf("------------------\n");
if(options.file_in) if(options.file_out)
{ {
FILE *fPtr; FILE *out = fopen(file_out,"w");
fPtr = fopen(file_in, "a"); fwrite(str,1,msg->size, out);
fputs(str, fPtr); fclose(out);
fputs("\n\0",fPtr);
fclose(fPtr);
} }
fwrite(str, 1, msg->size, stdout); fwrite(str, 1, msg->size, stdout);
#if 0 #if 0
@ -132,13 +129,13 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay,
char c[100]; char c[100];
while(1) { 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); fscanf(fptr, "%[^\n]", c);
printf("%i",strlen(c)); printf("%i",strlen(c));
fxlink_device_start_bulk_OUT(fdev,"fxlink", "text", &c, strlen(c), false); 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) if(transferred <= 0)
continue; continue;
/* Either start a new message or continue an unfinished one */ /* Either start a new message or continue an unfinished one */
if(tr == NULL) if(tr == NULL)
tr = fxlink_transfer_make_IN(buffer, transferred); tr = fxlink_transfer_make_IN(buffer, transferred);