Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argparsing for output modules #34

Open
marenz2569 opened this issue Jun 4, 2018 · 7 comments
Open

Argparsing for output modules #34

marenz2569 opened this issue Jun 4, 2018 · 7 comments
Labels
enhancement Enhancement suggestions to the project.

Comments

@marenz2569
Copy link
Contributor

marenz2569 commented Jun 4, 2018

Arguments should be passed to output modules to get rid of the defines, i.e. in out_sdl2.
When simply just -[any character] would be enough then 20h's arg.h could be used.
I have some code ready to use if this adequate.

@orithena
Copy link
Collaborator

orithena commented Jun 4, 2018

I second that motion! (but @vifino still is the owner ^^)

@vifino
Copy link
Member

vifino commented Jun 4, 2018

But you already got arguments for output modules...?
-o udp:1.2.3.4:1234,16x8

@vifino
Copy link
Member

vifino commented Jun 4, 2018

out_sdl2 simply doesn't use those argstrings. It should, but it does not.

@marenz2569
Copy link
Contributor Author

marenz2569 commented Jun 4, 2018

@vifino I know about the argstrings. But it would be simpler to use int init(int argc, char **argv), than parsing those argstrings in every output module.

@vifino
Copy link
Member

vifino commented Jun 4, 2018

I see. While I get your point, for me, having a rather universal way to handle arguments is more important.

You'd have to pass the remaining arguments to the output module, which isn't that helpful.
It would also only make a difference if you'd plan to use spaces, which has it's whole other list of problems..

@marenz2569
Copy link
Contributor Author

marenz2569 commented Jun 5, 2018

Well I tought of a conversion from argstring to argc/argv and pass this to the modules and then have a loop in the module to get the arguments from the argc/argv. This can be done easily with arg.h from 20h. Code would look like this:

#include "arg.h"

static int width  = -1,
           height = -1;

static void usage(void) {
 eprintf("usage: -o \"sdl2:-w width -h height\"\n");
 abort();
}

init init(int argc, char **argv) {
 ARGBEGIN {
 case 'w':
  width = atoi(EARGF(usage());
  break;
 case 'h':
  height = atoi(EARGF(usage());
  break;
 default:
  usage();
  return 2;
 } ARGEND;

On error the parser will return: usage: -o "sdl2:-w width -h height"
Substituting width and height with integer values.

@vifino
Copy link
Member

vifino commented Jun 5, 2018

That's not too bad, but I think I still prefer something like -o sdl2:64x64, as it's shorter and doesn't require quoting.

@vifino vifino added the enhancement Enhancement suggestions to the project. label Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement suggestions to the project.
Projects
None yet
Development

No branches or pull requests

3 participants