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

@ -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,

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"
@ -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':

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