[GHC] #14145: I expect `hp2ps -cd` to work as `hp2ps -c -d` does.

GHC ghc-devs at haskell.org
Tue Aug 22 18:23:27 UTC 2017


#14145: I expect `hp2ps -cd` to work as `hp2ps -c -d` does.
-------------------------------------+-------------------------------------
        Reporter:  qbolec            |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Profiling         |              Version:  7.10.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by qbolec):

 I've run out of time, so I didn't figure out how to configure all the
 tools to make the pull request, and where and how to add tests for this
 file. But here is the minimal change I believe fixes the problem:
 {{{
 diff --git a/utils/hp2ps/Main.c b/utils/hp2ps/Main.c
 index a44e41c862..30dbc2992b 100644
 --- a/utils/hp2ps/Main.c
 +++ b/utils/hp2ps/Main.c
 @@ -81,7 +81,7 @@ int main(int argc, char *argv[])
                  goto nextarg;
             case 'd':
                 dflag++;
 -                goto nextarg;
 +                break;
             case 'i':
                 switch( *(*argv + 1) ) {
                   case '-':
 @@ -94,16 +94,16 @@ int main(int argc, char *argv[])
                  goto nextarg;
             case 'g':
                 gflag++;
 -               goto nextarg;
 +               break;
             case 'y':
                 yflag++;
 -               goto nextarg;
 +               break;
             case 'b':
                 bflag++;
 -               goto nextarg;
 +               break;
             case 's':
                 sflag++;
 -               goto nextarg;
 +               break;
             case 'm':
                 mflag++;
                 TWENTY = atoi(*argv + 1);
 @@ -122,7 +122,7 @@ int main(int argc, char *argv[])
                 goto nextarg;
             case 'c':
                 cflag++;
 -               goto nextarg;
 +               break;
             case '?':
             default:
                 Usage(*argv-1);
 }}}

 In particular it seems that the intent of the
 {{{
     while (argc && argv[0][0] == '-') {
         while (*++*argv)
             switch(**argv) {
 }}}
 loop was to loop through all characters within a single word, and in did
 this is how it works for "-p" option, but for all the others `goto
 nextarg;` is used instead `break;` which skips all the other letters.

 A better solution in my opinion would be to use
 [https://stackoverflow.com/questions/9642732/parsing-command-line-
 arguments some library] to parse the options because the current code (and
 code style) seems quite complicated to me.

 I had no time to investigate which of these libraries we could use in
 order to support MSYS2 etc. Nor the time to actually rewrite the code to
 use such a library.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14145#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list