Switch to POSIXLY_CORRECT mode for getopt_long()

This  makes the  first non-option  argument end  getopt_long() parsing
stop rather  than shuffling non-option  arguments to the end.  This is
necessary  so that  rig/rotator command  language arguments  can start
with a  '-' character and  also it enables  the '-' pseudo  command to
switch to reading commands from stdin work correctly.

The change  also make checking for  the '-', switch to  stdin, command
stricter in that it must be where a command is expected and it must be
a word containing exactly a single '-' character.

Overall this allows the following styles of use:

$ rigctl R -

$ rigctl - <<EOF
>R -
>EOF

R -

$ echo "R -" | rigctl -

R -
$ rigctl -m 1 M CW -1

$ rigctl F 434000000 - <<EOF
>M FM 15000
>f m
>EOF

M FM 15000
f 145000000

m FM
15000

$

as well  as the command  line interpreter operation where  no commands
nor '-' are provided:

$ rigctl

Rig command: R -

Rig command: r
Rptr Shift: -

Rig command: f
Frequency: 145000000

Rig command: m
Mode: FM
Passband: 15000

Rig command: F 434000000

Rig command: f
Frequency: 434000000

Rig command: q

$
Hamlib-3.1
Bill Somerville 2016-04-19 21:31:48 +01:00 zatwierdzone przez Nate Bargmann
rodzic 22218fed79
commit fcb93b98fa
4 zmienionych plików z 4 dodań i 4 usunięć

Wyświetl plik

@ -87,7 +87,7 @@ void usage(void);
* NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:t:lC:LuonvhV"
#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhV"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},

Wyświetl plik

@ -452,7 +452,7 @@ static int next_word (char *buffer, int argc, char *argv[], int newline)
if (!reading_stdin)
{
if (optind >= argc) return EOF;
else if ('-' == argv[optind][0])
else if (newline && '-' == argv[optind][0] && 1 == strlen (argv[optind]))
{
++optind;
reading_stdin = 1;

Wyświetl plik

@ -82,7 +82,7 @@ void usage();
* NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "m:r:s:C:t:LvhVlu"
#define SHORT_OPTIONS "+m:r:s:C:t:LvhVlu"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},

Wyświetl plik

@ -354,7 +354,7 @@ static int next_word (char *buffer, int argc, char *argv[], int newline)
if (!reading_stdin)
{
if (optind >= argc) return EOF;
else if ('-' == argv[optind][0])
else if (newline && '-' == argv[optind][0] && 1 == strlen (argv[optind]))
{
++optind;
reading_stdin = 1;