C: getopt with list of acceptable optarg. What is the best practise ?
Posted
by Xavier Maillard
on Stack Overflow
See other posts from Stack Overflow
or by Xavier Maillard
Published on 2010-06-01T19:14:21Z
Indexed on
2010/06/01
19:33 UTC
Read the original article
Hit count: 261
Hi,
I am writing a C program which is a frontend to a myriad tools. This fronted will be launched like this:
my-frontend --action <AN ACTION>
As all the tools have the same prefix, let say for this example this prefix is "foo". I want to concatenate "AN ACTION" to this prefix and exec this (if the tool exists).
I have written something but my implementation uses strcmp to test that "AN ACTION" is a valid action. Even if this works, I do not like it. So I am looking for a nicer solution that would do the same. The list of possibilities is pretty small (less than 10) and static (the list is "hardcoded") but I am sure there is a more "C-ish" way to do this (using a struct or something like that). As I am not a C expert, I am asking for your help.
Regards
© Stack Overflow or respective owner