From 95d485070bf2d5085bc3f97f513718131721661c Mon Sep 17 00:00:00 2001 From: Cyrille Meichel Date: Wed, 9 Feb 2022 11:48:40 +0100 Subject: [PATCH 1/2] allow to pass filename in autocmd parameter --- src/argparse.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/argparse.cpp b/src/argparse.cpp index ceb23c6..2ebda3c 100644 --- a/src/argparse.cpp +++ b/src/argparse.cpp @@ -94,6 +94,12 @@ std::string replaceCap32Keys(std::string command) return command; } +void inlineString(CapriceArgs& args, char* data) +{ + args.autocmd += replaceCap32Keys(data); + args.autocmd += "\n"; +} + void parseArguments(int argc, char **argv, std::vector& slot_list, CapriceArgs& args) { int option_index = 0; @@ -111,9 +117,29 @@ void parseArguments(int argc, char **argv, std::vector& slot_list, switch (c) { case 'a': + if (optarg[0] == '@') + { + /* Well, this is a file content we want to inject */ + std::ifstream inlineStream(&optarg[1], std::ifstream::in); + if(!inlineStream.is_open()) + { + /* The filename is not correct, it may be a string to inject */ + LOG_VERBOSE("Append to autocmd: " << optarg); + inlineString(args, optarg); + break; + } + /* Inject all lines from the file */ + LOG_VERBOSE("Append file content to autocmd: " << &optarg[1]); + while(inlineStream.good()) + { + char chLine[256]; + inlineStream.getline(chLine, 256); + inlineString(args, chLine); + } + break; + } LOG_VERBOSE("Append to autocmd: " << optarg); - args.autocmd += replaceCap32Keys(optarg); - args.autocmd += "\n"; + inlineString(args, optarg); break; case 'c': From c3482070be60cecc953526ebce357d3a5c0ee84e Mon Sep 17 00:00:00 2001 From: Cyrille Meichel Date: Wed, 9 Feb 2022 14:03:50 +0100 Subject: [PATCH 2/2] documentation --- doc/man.html | 6 +++++- doc/man6/cap32.6 | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/man.html b/doc/man.html index 945a207..9d1ffef 100644 --- a/doc/man.html +++ b/doc/man.html @@ -190,7 +190,7 @@

OPTIONS

-a, ---autocmd=COMMAND

+--autocmd=COMMAND | @FILENAME

pass command to execute to the emulator. The option can be repeated to pass multiple @@ -198,6 +198,10 @@

OPTIONS "Hello"’ -a ’print "World"’

+

with prefix "@", a +filename is specified. All commands in the file are passed. +For example: cap32 -a ’@/tmp/cmd.txt’

+

-c, --cfg_file=FILE

diff --git a/doc/man6/cap32.6 b/doc/man6/cap32.6 index f22c9ce..3de3c76 100644 --- a/doc/man6/cap32.6 +++ b/doc/man6/cap32.6 @@ -112,8 +112,11 @@ If the mapping file is not defined or not found, Caprice32 will default to a sta .SH OPTIONS .PP .TP -\fB\-a\fR, \fB\-\-autocmd\fR=\fICOMMAND\fR +\fB\-a\fR, \fB\-\-autocmd\fR=\fICOMMAND\fR | \fI@FILENAME\fR pass command to execute to the emulator. The option can be repeated to pass multiple commands. For example: cap32 -a 'print "Hello"' -a 'print "World"' +.RS +with prefix "@", a filename is specified. All commands in the file are passed. For example: cap32 -a '@/tmp/cmd.txt' +.RE .TP \fB\-c\fR, \fB\-\-cfg_file\fR=\fIFILE\fR use FILE as the emulator configuration file.