This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Looking for getopt(int, char * const [], const char *)

Hi to all,

I'm currently trying to develop a litte application on the Tiva uC platform. I would like to use the command line processor to control the software and would like to use the standart "C like" command line arguments like foo.exe -a foo -b foo ... I was looking for the getopt() function but couldn't find it. I would appreciate to get any advice.

Thanks you very much!

  • First you should note that there is no command line on these processors.

    You might be able to reinvent cp/m but that seems rather quixotic.

    Robert
  • Hi Robert,

    thank you for yout quick response. I might didn't express myself correct, sorry. My appliation is based on the qs-rgb application where they use the the virtual serial port to control the application witha command-line like approach. In this expample they used argc and argv to pass arguments inside the apprpriate command functions. I would like to pass parameters inside this functions with the common approach like -a fooa -b foob and so on. For that I was looking for a way to parse these parameters nicely and have like a big switch-case statement with all the options. I found that normaly the function getopt(int, char * const [], const char *) is used for taht but couln't find it inside the TivaWare folder. So my question is: Is there such a function to do what I'm trying to do or shall I rather try to write my own function to do that.

    Thanks!

  • AH, a command interpreter.

    You could use getopt for that,and there are open source versions, but I think there are better options
    First, SCPi. Especially if you plan on ever controlling from a computer. It's well defined and instrumentation was its focus. Labview supports it and you should find plenty of examples of controlling SCPI devices in multiple languages

    Second take a look at scripting languages. Small/Pawn others are out there.There's a popular one I'm forgetting.

    Third, take a more primitive approach. Use a command word/argument approach. Use the first word on the line as a lookup into a command table. You can either let the command parse further arguments or use, say, a linked list describing the format of the arguments. The advantage of this approach over getopt is that you can decide to limit your parsing/buffering to a single word or argument rather than an entire line simplifying overflow and memory considerations. You can further simplify by making all commands a fixed length.

    Robert
    All I've got is options lately
  • Lua, I knew I'd remember the language eventually. Made for embedding. Python and Ruby have been embedded in programs but I suspect the overhead is high.

    Pawn and Lua should have smaller resource requirements.

    Robert
  • Hello Mathias,

    Did you look into the sd_card example in DK-TM4C123. There is a command line interpreter implemented in TivaWare though it does not use getopt like structure,

    Regards
    Amit