mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-29 13:03: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;
|
FILE *log_file;
|
||||||
/* Extra details (mainly interactive messages) */
|
/* Extra details (mainly interactive messages) */
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool write_to_socket;
|
bool file_in;
|
||||||
|
bool file_out;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct fxlink_options options;
|
extern struct fxlink_options options;
|
||||||
|
|
||||||
/* Input/output socket filename in case of -s option */
|
/* Input/output socket filename in case of -s option */
|
||||||
extern char* socket_in;
|
extern char* file_in;
|
||||||
extern char* socket_out;
|
extern char* file_out;
|
||||||
|
|
||||||
/* Main function for -l */
|
/* Main function for -l */
|
||||||
int main_list(struct fxlink_filter *filter, delay_t *delay,
|
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 <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"
|
||||||
" -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"
|
" --libusb-log=LEVEL libusb log level (NONE, ERROR, WARNING, INFO, DEBUG)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Mode-specific options:\n"
|
"Mode-specific options:\n"
|
||||||
|
@ -63,6 +64,10 @@ static const char *help_string =
|
||||||
/* Global options */
|
/* Global options */
|
||||||
struct fxlink_options options;
|
struct fxlink_options options;
|
||||||
|
|
||||||
|
/* In and out files */
|
||||||
|
char* file_in;
|
||||||
|
char* file_out;
|
||||||
|
|
||||||
/* Input/output socket filenames for -s option */
|
/* Input/output socket filenames for -s option */
|
||||||
char *socket_in;
|
char *socket_in;
|
||||||
char *socket_out;
|
char *socket_out;
|
||||||
|
@ -77,14 +82,15 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
options.log_file = NULL;
|
options.log_file = NULL;
|
||||||
options.verbose = false;
|
options.verbose = false;
|
||||||
options.write_to_socket = false;
|
options.file_in = false;
|
||||||
|
options.file_out = false;
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
//---
|
//---
|
||||||
// Command-line argument parsing
|
// 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[] = {
|
const struct option longs[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "list", no_argument, NULL, 'l' },
|
{ "list", no_argument, NULL, 'l' },
|
||||||
|
@ -98,6 +104,8 @@ int main(int argc, char **argv)
|
||||||
{ "repeat", no_argument, NULL, 'r' },
|
{ "repeat", no_argument, NULL, 'r' },
|
||||||
{ "verbose", no_argument, NULL, 'v' },
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
{ "folder", required_argument, NULL, OUT_FOLDER },
|
{ "folder", required_argument, NULL, OUT_FOLDER },
|
||||||
|
{ "filein", required_argument, NULL, FILE_IN },
|
||||||
|
{ "fileout", required_argument, NULL, FILE_OUT },
|
||||||
/* Deprecated options ignored for compatibility: */
|
/* Deprecated options ignored for compatibility: */
|
||||||
{ "quiet", no_argument, NULL, 'q' },
|
{ "quiet", no_argument, NULL, 'q' },
|
||||||
{ "unmount", no_argument, NULL, 'u' },
|
{ "unmount", no_argument, NULL, 'u' },
|
||||||
|
@ -112,10 +120,19 @@ int main(int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'b':
|
case 'b':
|
||||||
case 's':
|
case FILE_IN:
|
||||||
options.write_to_socket = true;
|
if(optarg)
|
||||||
socket_in = argv[optind];
|
{
|
||||||
socket_out = argv[optind+1];
|
options.file_in = true;
|
||||||
|
file_in = optarg;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FILE_OUT:
|
||||||
|
if(optarg)
|
||||||
|
{
|
||||||
|
options.file_out = true;
|
||||||
|
file_out = optarg;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
case 't':
|
case 't':
|
||||||
|
|
|
@ -43,10 +43,10 @@ static void handle_new_message(struct fxlink_device *fdev,
|
||||||
str[msg->size] = '\0';
|
str[msg->size] = '\0';
|
||||||
if(options.verbose)
|
if(options.verbose)
|
||||||
printf("------------------\n");
|
printf("------------------\n");
|
||||||
if(options.write_to_socket)
|
if(options.file_in)
|
||||||
{
|
{
|
||||||
FILE *fPtr;
|
FILE *fPtr;
|
||||||
fPtr = fopen(socket_in, "a");
|
fPtr = fopen(file_in, "a");
|
||||||
fputs(str, fPtr);
|
fputs(str, fPtr);
|
||||||
fputs("\n\0",fPtr);
|
fputs("\n\0",fPtr);
|
||||||
fclose(fPtr);
|
fclose(fPtr);
|
||||||
|
@ -132,13 +132,13 @@ int main_interactive(struct fxlink_filter *filter, delay_t *delay,
|
||||||
char c[100];
|
char c[100];
|
||||||
while(1) {
|
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);
|
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(socket_out);
|
remove(file_out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue