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 Wait indefinitely for a calculator to connect\n"
" -f <FILTER> Filter which calculators we connect to (see below)\n"
" --filein <FILE> Send received data to <FILE>"
" --fileout <FILE> Send data in <FILE> to calculator\n"
" --filein <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"
"\n"
"Mode-specific options:\n"
@ -68,10 +68,6 @@ struct fxlink_options options;
char *file_in;
char *file_out;
/* Input/output socket filenames for -s option */
char *socket_in;
char *socket_out;
int main(int argc, char **argv)
{
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 'b':
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;
}
file_out = optarg,"w";
break;
case 's':
case 'i':
case 't':
case 'p':

View file

@ -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);