mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-28 04:23:37 +01:00
Rename 'socket' to 'file' and split in/out file
This commit is contained in:
parent
eeffbc46f2
commit
6419f17b64
3 changed files with 33 additions and 15 deletions
|
@ -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,
|
||||
|
|
|
@ -41,7 +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"
|
||||
" -s <IN> <OUT> Send received data to IN file and send data in OUT file to calculator\n"
|
||||
" --filein <FILE> Send received data to <FILE>"
|
||||
" --fileout <FILE> Send data in <FILE> 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':
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue