{"thread":{"id":"939","subject":"[COGITO PATCH] Optimized print_help()","startedAt":"2005-06-14T23:26:16Z","lastAt":"2005-06-15T21:14:59Z","messageCount":5,"participants":["Pavel Roskin","Jonas Fonseca","Rene Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4956","messageId":"1118791576.3890.4.camel@dv","threadId":"939","inReplyTo":null,"subject":"[COGITO PATCH] Optimized print_help()","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-06-14T23:26:16Z","receivedAt":"2005-06-14T23:26:16Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello!\n\nprint_help() in cg-Xlib should not be calling \"which\" 3 times.  It's an\nexternal command.  The patch caches the result in a local variable.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\ndiff --git a/cg-Xlib b/cg-Xlib\n--- a/cg-Xlib\n+++ b/cg-Xlib\n@@ -130,10 +130,11 @@ update_index () {\n \n \n print_help () {\n-\twhich \"cg-$1\" >/dev/null 2>&1 || exit 1\n-\tsed -n '/^USAGE=/,0s/.*\"\\(.*\\)\"/Usage: \\1/p' < $(which cg-$1) \n+\tlocal toolpath=$(which cg-$1 2>/dev/null)\n+\t[ -z \"$toolpath\" ] && exit 1\n+\tsed -n '/^USAGE=/,0s/.*\"\\(.*\\)\"/Usage: \\1/p' < $toolpath\n \techo\n-\tcat $(which cg-$1) | sed -n '3,/^$/s/^# *//p'\n+\tcat $toolpath | sed -n '3,/^$/s/^# *//p'\n \texit\n }\n \n\n-- \nRegards,\nPavel Roskin\n\n"},{"id":"4959","messageId":"20050615000001.GB17152@diku.dk","threadId":"939","inReplyTo":"1118791576.3890.4.camel@dv","subject":"Re: [COGITO PATCH] Optimized print_help()","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-06-15T00:00:01Z","receivedAt":"2005-06-15T00:00:01Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"Pavel Roskin <proski@gnu.org> wrote Tue, Jun 14, 2005:\n> Hello!\n> \n> print_help() in cg-Xlib should not be calling \"which\" 3 times.  It's an\n> external command.  The patch caches the result in a local variable.\n> \n> Signed-off-by: Pavel Roskin <proski@gnu.org>\n> \n> diff --git a/cg-Xlib b/cg-Xlib\n> --- a/cg-Xlib\n> +++ b/cg-Xlib\n> @@ -130,10 +130,11 @@ update_index () {\n>  \n>  \n>  print_help () {\n> -\twhich \"cg-$1\" >/dev/null 2>&1 || exit 1\n> -\tsed -n '/^USAGE=/,0s/.*\"\\(.*\\)\"/Usage: \\1/p' < $(which cg-$1) \n> +\tlocal toolpath=$(which cg-$1 2>/dev/null)\n> +\t[ -z \"$toolpath\" ] && exit 1\n> +\tsed -n '/^USAGE=/,0s/.*\"\\(.*\\)\"/Usage: \\1/p' < $toolpath\n\nShouldn't $toolpath be quoted here to make it safer? Although it seems\nthe make install don't handle irregular toolpaths at the moment.\n\n>  \techo\n> -\tcat $(which cg-$1) | sed -n '3,/^$/s/^# *//p'\n> +\tcat $toolpath | sed -n '3,/^$/s/^# *//p'\n\nWhat about also removing UUOC from this line ...\n\n\tsed -n '3,/^$/s/^# *//p' < \"$toolpath\"\n\n>  \texit\n>  }\n\n-- \nJonas Fonseca\n"},{"id":"4961","messageId":"1118795583.3890.27.camel@dv","threadId":"939","inReplyTo":"20050615000001.GB17152@diku.dk","subject":"Re: [COGITO PATCH] Optimized print_help()","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-06-15T00:33:03Z","receivedAt":"2005-06-15T00:33:03Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"On Wed, 2005-06-15 at 02:00 +0200, Jonas Fonseca wrote:\n> Shouldn't $toolpath be quoted here to make it safer? Although it seems\n> the make install don't handle irregular toolpaths at the moment.\n\nSure.\n\n> > +\tcat $toolpath | sed -n '3,/^$/s/^# *//p'\n> \n> What about also removing UUOC from this line ...\n\nUUOC?  I had too look it up :-)\n\nIt's not just \"useless use of cat\", but also useless use of redirection\nin both cases.  I guess sed can exit after it finishes processing the\nrange (I don't know if it actually does), so feeding it the whole file\nis not need.\n\nOK, here's an improved patch.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\ndiff --git a/cg-Xlib b/cg-Xlib\n--- a/cg-Xlib\n+++ b/cg-Xlib\n@@ -130,10 +130,11 @@ update_index () {\n \n \n print_help () {\n-\twhich \"cg-$1\" >/dev/null 2>&1 || exit 1\n-\tsed -n '/^USAGE=/,0s/.*\"\\(.*\\)\"/Usage: \\1/p' < $(which cg-$1) \n+\tlocal toolpath=$(which cg-$1 2>/dev/null)\n+\t[ -z \"$toolpath\" ] && exit 1\n+\tsed -n '/^USAGE=/,0s/.*\"\\(.*\\)\"/Usage: \\1/p' \"$toolpath\"\n \techo\n-\tcat $(which cg-$1) | sed -n '3,/^$/s/^# *//p'\n+\tsed -n '3,/^$/s/^# *//p' \"$toolpath\"\n \texit\n }\n \n\nP.S. Maybe we could use \"type\" rather than \"which\" because the former is\na shell built-in.  Or maybe we should hardcode the prefix on install.\nAnyway, it's out of scope of this patch.\n\nP.P.S. I hope that $toolpath doesn't start with \"-\".  I could add \"--\"\nto the sed command line, but I'm not sure if BSD sed would like it.\n\n-- \nRegards,\nPavel Roskin\n\n"},{"id":"4980","messageId":"42B07A6F.3000001@lsrfire.ath.cx","threadId":"939","inReplyTo":"1118795583.3890.27.camel@dv","subject":"Re: [COGITO PATCH] Optimized print_help()","fromName":"Rene Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2005-06-15T18:58:55Z","receivedAt":"2005-06-15T18:58:55Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Pavel Roskin schrieb:\n>>> +\tcat $toolpath | sed -n '3,/^$/s/^# *//p'\n>> \n>> What about also removing UUOC from this line ...\n> \n> \n> UUOC?  I had too look it up :-)\n> \n> It's not just \"useless use of cat\", but also useless use of\n> redirection in both cases.  I guess sed can exit after it finishes\n> processing the range (I don't know if it actually does), so feeding\n> it the whole file is not need.\n\nIt doesn't matter if the shell opens the file or if sed does it itself,\nsed's ability to close the file and quit when done doesn't depend on\nthat.  So this call is equivalent and has the advantage of being\nresistant against filenames starting with a \"-\":\n\n   sed -n '3,/^$/s/^# *//p' <\"$toolpath\"\n\nRene\n"},{"id":"4981","messageId":"1118870099.21882.16.camel@dv","threadId":"939","inReplyTo":"42B07A6F.3000001@lsrfire.ath.cx","subject":"Re: [COGITO PATCH] Optimized print_help()","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-06-15T21:14:59Z","receivedAt":"2005-06-15T21:14:59Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello, Rene!\n\nOn Wed, 2005-06-15 at 20:58 +0200, Rene Scharfe wrote:\n> It doesn't matter if the shell opens the file or if sed does it itself,\n> sed's ability to close the file and quit when done doesn't depend on\n> that.\n\nI checked sed 4.1.4 and found following:\n\n1) sed won't close stdin ever, but it will close files specified on the\ncommand line.\n\n2) sed will exit when told to do so by a command such as \"q\", and it\nwon't read the reminder of the file, whether it's stdin or not.\n\n3) sed has code that makes it exit after it has processed all address\nranges and the \"-n\" option is used.  However, this feature is buggy and\ndisabled by default (see EXPERIMENTAL_DASH_N_OPTIMIZATION). It may be\nenabled in the future versions.\n\nIn other words, you are correct (except the part about closing the\nfile).\n\n>   So this call is equivalent and has the advantage of being\n> resistant against filenames starting with a \"-\":\n> \n>    sed -n '3,/^$/s/^# *//p' <\"$toolpath\"\n\nOK.  Here's the third version of the patch.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\ndiff --git a/cg-Xlib b/cg-Xlib\n--- a/cg-Xlib\n+++ b/cg-Xlib\n@@ -130,10 +130,11 @@ update_index () {\n \n \n print_help () {\n-\twhich \"cg-$1\" >/dev/null 2>&1 || exit 1\n-\tsed -n '/^USAGE=/,0s/.*\"\\(.*\\)\"/Usage: \\1/p' < $(which cg-$1) \n+\tlocal toolpath=$(which cg-$1 2>/dev/null)\n+\t[ -z \"$toolpath\" ] && exit 1\n+\tsed -n '/^USAGE=/,0s/.*\"\\(.*\\)\"/Usage: \\1/p' <\"$toolpath\"\n \techo\n-\tcat $(which cg-$1) | sed -n '3,/^$/s/^# *//p'\n+\tsed -n '3,/^$/s/^# *//p' <\"$toolpath\"\n \texit\n }\n \n\n\n\n-- \nRegards,\nPavel Roskin\n\n"}]}