Re: [hackers] [slock][PATCH] Improve option parsing routine

2016-10-29 Thread Ali H. Fardan

On 2016-10-29 21:35, Laslo Hunhold wrote:

The "problem" with dmenu is that it takes "long" flags, and given so
many scripts depend on it we just cannot change it that easily.


when did I suggest using arg.h for dmenu?

---
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments



Re: [hackers] [slock][PATCH] Improve option parsing routine

2016-10-29 Thread Laslo Hunhold
On Sat, 29 Oct 2016 13:11:27 +0300
"Ali H. Fardan"  wrote:

Hey Ali,

> uhm, like the dmenu one?[0]
> 
> [0]: http://git.suckless.org/dmenu/tree/dmenu.c#n649

this has already been discussed; I wrote a patch for that a long time
ago and we came to the conclusion that changing the flag-names just for
the sake of being able to use arg.h was not worth it.

The "problem" with dmenu is that it takes "long" flags, and given so
many scripts depend on it we just cannot change it that easily.

Cheers

Laslo

-- 
Laslo Hunhold 



Re: [hackers] [slock][PATCH] Improve option parsing routine

2016-10-29 Thread Hiltjo Posthuma
On Sat, Oct 29, 2016 at 12:11 PM, Ali H. Fardan  wrote:
> On 2016-10-29 12:40, Hiltjo Posthuma wrote:
>>
>> This is total bullshit: it is less readable and it makes no sense to
>> optimize this case. Please fix real bugs.
>
>
> uhm, like the dmenu one?[0]
>
> [0]: http://git.suckless.org/dmenu/tree/dmenu.c#n649
>

Not sure if you mean it sarcastically, but yes in dmenu it feelsgoodman.jpg.

My gripe is checking: if (argv[1][1] == 'v' && argv[1][2] == '\0' &&
instead of using strcmp. This path is not "performance-critical" in
any way, so it doesn't make sense.

If you have anything to say, please respond with arguments.



Re: [hackers] [slock][PATCH] Improve option parsing routine

2016-10-29 Thread Ali H. Fardan

On 2016-10-29 12:40, Hiltjo Posthuma wrote:

This is total bullshit: it is less readable and it makes no sense to
optimize this case. Please fix real bugs.


uhm, like the dmenu one?[0]

[0]: http://git.suckless.org/dmenu/tree/dmenu.c#n649

---
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments



Re: [hackers] [slock][PATCH] Improve option parsing routine

2016-10-29 Thread Hiltjo Posthuma
On Sat, Oct 29, 2016 at 12:32 AM, Klemens Nanni  wrote:
> This reduces the amount of strcmp() calls and comparisons in general to
> a minimum.
> ---
>  slock.c | 13 ++---
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/slock.c b/slock.c
> index 283b04e..e9b050a 100644
> --- a/slock.c
> +++ b/slock.c
> @@ -298,15 +298,14 @@ main(int argc, char *argv[]) {
> Display *dpy;
> int s, nlocks, nscreens;
>
> -   if (argc > 1 && !strncmp("-", argv[1], 1)) {
> -   if ((argc == 2 && !strcmp("-v", argv[1])) ||
> -   (argc == 3 && !strcmp("-v", argv[1]) && !strcmp("--", 
> argv[2]))) {
> +   if (argv[1] && argv[1][0] == '-') {
> +   if (argv[1][1] == 'v' && argv[1][2] == '\0' &&
> +   (argc == 2 || (argc == 3 && !strcmp(argv[2], "--" {
> fputs("slock-"VERSION"\n", stderr);
> return 0;
> -   } else if (!strcmp("--", argv[1])) {
> -   --argc;
> -   ++argv;
> -   } else
> +   } else if (argv[1][1] == '-' && argv[1][2] == '\0')
> +   --argc, ++argv;
> +   else
> die("usage: slock [-v] [cmd [arg ...]]\n");
> }
>
> --
> 2.8.3
>
>

This is total bullshit: it is less readable and it makes no sense to
optimize this case. Please fix real bugs.



[hackers] [slock][PATCH] Improve option parsing routine

2016-10-28 Thread Klemens Nanni
This reduces the amount of strcmp() calls and comparisons in general to
a minimum.
---
 slock.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/slock.c b/slock.c
index 283b04e..e9b050a 100644
--- a/slock.c
+++ b/slock.c
@@ -298,15 +298,14 @@ main(int argc, char *argv[]) {
Display *dpy;
int s, nlocks, nscreens;
 
-   if (argc > 1 && !strncmp("-", argv[1], 1)) {
-   if ((argc == 2 && !strcmp("-v", argv[1])) ||
-   (argc == 3 && !strcmp("-v", argv[1]) && !strcmp("--", 
argv[2]))) {
+   if (argv[1] && argv[1][0] == '-') {
+   if (argv[1][1] == 'v' && argv[1][2] == '\0' &&
+   (argc == 2 || (argc == 3 && !strcmp(argv[2], "--" {
fputs("slock-"VERSION"\n", stderr);
return 0;
-   } else if (!strcmp("--", argv[1])) {
-   --argc;
-   ++argv;
-   } else
+   } else if (argv[1][1] == '-' && argv[1][2] == '\0')
+   --argc, ++argv;
+   else
die("usage: slock [-v] [cmd [arg ...]]\n");
}
 
-- 
2.8.3