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

Edit code, please! #1

Open
zhenyolka opened this issue Sep 14, 2017 · 2 comments
Open

Edit code, please! #1

zhenyolka opened this issue Sep 14, 2017 · 2 comments

Comments

@zhenyolka
Copy link

Sorry for my English.
Thank you! You make perfect keyboard, but i cant start it on my phone. I compile with makefile.
If i try run programm, it do nothing. it stop on forever loop.
please remove this
while((c = getopt(argc, argv, "d:f:h")) != -1) {
switch (c) {
case 'd':
device = optarg;
break;
case 'f':
font = optarg;
break;
case 'h':
printf("usage: %s [options]\npossible options are:\n -h: print this help\n -d: set path to inputdevice\n -f: set path to font\n", argv[0]);
exit(0);
break;
case '?':
fprintf(stderr, "unrecognized option -%c\n", optopt);
break;
}
}

and replace to it
c = getopt(argc, argv, "d:f:h")
switch (c) {
case 'd':
device = optarg;
break;
case 'f':
font = optarg;
break;
case 'h':
printf("usage: %s [options]\npossible options are:\n -h: print this help\n -d: set path to inputdevice\n -f: set path to font\n", argv[0]);
exit(0);
break;
case '?':
fprintf(stderr, "unrecognized option -%c\n", optopt);
break;
}
it works good and not do forever loop.

@julianwi
Copy link
Owner

Without the while loop, only one option can get parsed.
It would be nice if you could give some more info. Did you pass options while executing? "-d " or "-f "?
Would be nice if you could do a little test: Add a line like this:

   char c;
   while((c = getopt(argc, argv, "d:f:h")) != -1) {
+    printf("debug: c=%0x\n", c);
     switch (c) {
       case 'd':
         device = optarg;

then compile and run the program and see what it prints out.

@broukema
Copy link

@zhenyolka is right about the bug (GNU/Linux system: mobian pinephone = debian/bookworm + mobian/bookworm, gcc) , but you @julianwi are also right about how to debug. :)

I got an infinite loop printing

debug: c=ff
debug: c=ff

Changing from

char c

to

int c

solved this. :)

An 8-bit unsigned int is not the same as a signed integer...

Feel free to consider this commit to be a merge request - cross-git-repository-hosts merge requests don't yet work directly (forgefed - https://forgefed.peers.community - is still in its infancy, and Microsoft is unlikely to cooperate with the community anyway):

https://codeberg.org/boud/fbkeyboard/commit/6533c5fd871fe8adfae477c3141366d3a63865d9

craigcomstock pushed a commit to craigcomstock/fbkeyboard that referenced this issue Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants