tools: perf: prefer clarity in setup_pager
PATCH 1/1 tools: perf: prefer clarity in setup_pager
“!(pager || access(…))” is indeed pretty smart way to write “!pager && access(…) == 0” but other than being clever it gives no advantages and merely confuses the reader who needs to wonder what is actually going on.
As such, replace the checks with much cleaner ones.
Also, while at it, merge the lest “!pager” test with the next test that yields true after the “!pager” if's body is executed.
--- tools/perf/util/pager.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
tools/perf/util/pager.c +3 -5
@@ -57,13 +57,11 @@ void setup_pager(void) }if (!pager) pager =getenv ("PAGER" ); -if (!(pager ||access ("/usr/bin/pager" ,X_OK ))) +if (!pager &&access ("/usr/bin/pager" ,X_OK ) ==0 ) pager ="/usr/bin/pager" ; -if (!(pager ||access ("/usr/bin/less" ,X_OK ))) +if (!pager &&access ("/usr/bin/less" ,X_OK ) ==0 ) pager ="/usr/bin/less" ; -if (!pager) - pager ="cat" ; -if (!*pager || !strcmp (pager,"cat" )) +if (!pager || !*pager || !strcmp (pager,"cat" ))return ; spawned_pager =1 ;/* means we are emitting to terminal */
Signature · 1 line
2.0.0.526.g5318336
A message that is not in the archive (sent off-list or not yet received): CAB1dqC7BqsaDtXVYx24M5R9eaY7ZfpEtu3bxbJHXNHYhAbJETg@mail.gmail.com
Quoted 5 lines · Michael Lentine
Unless I'm missing something this removes defaulting the pager to cat if nothing is found which is very useful for devices/oses without less or pager.
I think you are correct Michael.
I don't quite understand the value of this patch.
But by oversimplifying, it should not change the logic of the code.
Quoted 41 lines
Quoted 38 lines · Michal Nazarewicz
“!(pager || access(…))” is indeed pretty smart way to write “!pager && access(…) == 0” but other than being clever it gives no advantages and merely confuses the reader who needs to wonder what is actually going on.
As such, replace the checks with much cleaner ones.
Also, while at it, merge the lest “!pager” test with the next test that yields true after the “!pager” if's body is executed.
--- tools/perf/util/pager.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)tools/perf/util/pager.c +3
-6@@ -57,13 +57,11 @@ void setup_pager(void) }if (!pager) pager =getenv ("PAGER" ); -if (!(pager ||access ("/usr/bin/pager" ,X_OK ))) +if (!pager &&access ("/usr/bin/pager" ,X_OK ) ==0 ) pager ="/usr/bin/pager" ; -if (!(pager ||access ("/usr/bin/less" ,X_OK ))) +if (!pager &&access ("/usr/bin/less" ,X_OK ) ==0 ) pager ="/usr/bin/less" ; -if (!pager) - pager ="cat" ; -if (!*pager || !strcmp (pager,"cat" )) +if (!pager || !*pager || !strcmp (pager,"cat" ))return ; spawned_pager =1 ;/* means we are emitting to terminal */ --2.0.0.526.g5318336
Quoted 3 lines · Michael Lentine
Unless I'm missing something this removes defaulting the pager to cat if nothing is found which is very useful for devices/oses without less or pager.
The last two conditions are merged together, i.e.
if (!pager)
pager = "cat";
if (!*pager || !strcmp(pager, "cat"))
return;becomes:
if (!pager || !*pager || !strcmp(pager, "cat"))
return;This also in my opinion simplifies the code since the original is a bit convoluted. If pager is NULL it first assigns "cat" to it and then in the very next condition compares pager to "cat". With this change, it's more obvious that if pager is NULL, the function will terminate.
Quoted 36 lines
Quoted 34 lines · Michal Nazarewicz
“!(pager || access(…))” is indeed pretty smart way to write “!pager && access(…) == 0” but other than being clever it gives no advantages and merely confuses the reader who needs to wonder what is actually going on.
As such, replace the checks with much cleaner ones.
Also, while at it, merge the lest “!pager” test with the next test that yields true after the “!pager” if's body is executed.
--- tools/perf/util/pager.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)tools/perf/util/pager.c +3
-5@@ -57,13 +57,11 @@ void setup_pager(void) }if (!pager) pager =getenv ("PAGER" ); -if (!(pager ||access ("/usr/bin/pager" ,X_OK ))) +if (!pager &&access ("/usr/bin/pager" ,X_OK ) ==0 ) pager ="/usr/bin/pager" ; -if (!(pager ||access ("/usr/bin/less" ,X_OK ))) +if (!pager &&access ("/usr/bin/less" ,X_OK ) ==0 ) pager ="/usr/bin/less" ; -if (!pager) - pager ="cat" ; -if (!*pager || !strcmp (pager,"cat" )) +if (!pager || !*pager || !strcmp (pager,"cat" ))return ; spawned_pager =1 ;/* means we are emitting to terminal */
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +--<[email protected]>--<xmpp:[email protected]>--ooO--(_)--Ooo--