docopt / docopt.c

C-code generator for docopt language.
MIT License
320 stars 47 forks source link

Generate header file #39

Open kroq-gar78 opened 7 years ago

kroq-gar78 commented 7 years ago

I think this would be a little more convenient to use if it generated a header file with just DocoptArgs and docopt(). The use case for this would be a program that deals with parsed arguments in many places.

If the parsed arguments (DocoptArgs) are needed in different files that are eventually linked together, we can't just do #include "docopt.c" like in the main file, since we would be redefining various variables and functions. We would instead have to redefine just the struct in each file that the parsed arguments are needed.

kroq-gar78 commented 7 years ago

I wouldn't mind taking this on myself, if I knew what CLI options I should add.

I was thinking of -H <path> and --output-header <path> that would set the destination for the header. The question then would be the path that .c file uses to include the header (should it be relative? assume it's in the same directory?).

Another option would be that if -o (or --output-name) is used, then we swap the extension with .h for the header and let the .c file assume it's in the same directory.

This is more of a brainstorm, but any thoughts are appreciated.

kroq-gar78 commented 7 years ago

I decided to take the second option and put it in my fork. I'm not going to submit a PR because I think I didn't really follow the exiting code style.

See https://github.com/docopt/docopt.c/compare/master...kroq-gar78:master for my changes