Menu

#7 Issues with parsing of command line options

v0.32
open
None
Next_Release
1
2018-01-15
2016-06-16
No

The following command line should error out because of the bad option '--b' as only the '-b' or '--baud' option should be valid, but does not error out: /usr/sbin/ttylog --b 2400 -d /dev/ttyS0.

In the code parsing the '-d|--device' parameter, an if/else stanza is used to set the modem_device variable if a device is actually listed, also taking care of the issue for if the device name is too long; but the else clause is there but empty. Is the else clause actually needed? The first step after the parameter passing and just a few lines later is checking the length of the modem_device name and failing out if "no device is set". Move that length check to the else clause?. Also; is that "!strcmp" enough? There are actually three not two possible results to that comparision.

These issues could be resolved by changing to use getopts long or one of the other commandline parsing libraries. Reference also:
http://www.gnu.org/software/libc/manual/html_node/Parsing-Program-Arguments.html
http://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Option-Example.html

Discussion

  • Robert James Clay

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,7 +2,7 @@
    
     In the code parsing the '-d|--device' parameter, an if/else stanza is used to set the modem_device variable if a device is actually listed, also taking care of the issue for if the device name is too long; but the else clause is there but empty.  Is the else clause actually needed?  The first step after the parameter passing and just a few lines later is checking the length of the modem_device name and failing out if "no device is set".  Move that length check to the else clause?. Also; is that "!strcmp" enough?  There are actually three not two   possible results to that comparision.
    
    -These  issues could be resolved by changing to use getopts long or one of the other commandline parsing libraries. Referencse also:
    +These  issues could be resolved by changing to use getopts long or one of the other commandline parsing libraries. Reference also:
     http://www.gnu.org/software/libc/manual/html_node/Parsing-Program-Arguments.html
     http://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Option-Example.html
    
     
  • Robert James Clay

    • Milestone: v0.30 --> Develop
     
  • Robert James Clay

    • Milestone: Develop --> v0.32
     

Log in to post a comment.