-o/--output commandline option is broken in 2.10, 2.11

Asked by ironstorm

Binary package hint: source-highlight

source-highlight --out-format=esc --output=STDOUT midiscriptengine.cpp
Processing midiscriptengine.cpp ... created midiscriptengine.cpp.txt

The flag --output used to spit ANSI highlighted source code to the console with source-highlight 2.4 (hardy), in version 2.10 (Intrepid) and 2.11 (Jaunty) this is no longer the case as you can see above. Rather a txt file is created, and if you provide a different arg then STDOUT it is supposed to save to that filename, that doesn't work either.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu source-highlight Edit question
Assignee:
No assignee Edit question
Solved by:
ironstorm
Solved:
Last query:
Last reply:
Revision history for this message
Lorenzo Bettini (bettini) said :
#1

Hi, I'm the developer of GNU Source-highlight.
The command line option --output works ONLY when --input command line option is specified (which is not the case in the above command): it works if you specify

--input midiscriptengine.cpp

Indeed Source-highlight can handle also arguments without command option, as in the example above where midiscriptengine.cpp is NOT the argument of ANY command line option; this way source-highlight can also handle more than one input file, and also, by relying on the underlying shell, regular expressions, e.g.,

source-highlight --out-format=html *.cpp *.h *.c

when operating in this mode the --output command line option is ignored (since this works only for one input file), and the output file is created automatically by appending the corresponding output format file extension, e.g., .html in my example, and .txt in your example.

Actually in previous versions (since 2.4) if it worked as you said, it was not consistent, so that was actually a bug ;-)

I hope this clarifies the problem.

If you have suggestions on how to further document this behavior, please let me know.
Probably source-highlight should issue and error when --input is not specified, but this would not be consistent with the fact that the input file can be specified also with stdin redirection.

Lorenzo

Revision history for this message
Cesare Tirabassi (norsetto) said :
#2

Thanks Lorenzo,

there is no bug here, just a support request so I'm transforming this into a question.

Revision history for this message
ironstorm (ironstorm-gmail) said :
#3

Thanks for the clarification Lorenzo...

I've gotten it to work, but I must admit I still find it a little confusing

Usage: source-highlight [OPTIONS]... [FILES]...
...
  -i, --input=filename input file. default std input
  -o, --output=filename output file. default std output. If STDOUT is
                                  specified, the output is directed to standard
                                  output

I assumed that specifying [FILES] was the equivalent of specifying the --input option for each file... and that std output was always the default. I now see that is not the case.

source-highlight --out-format=esc enginerealsearch.cpp # saves to .cpp.txt

source-highlight --out-format=esc --output=STDOUT enginerealsearch.cpp # saves to .cpp.txt in 2.10+, prints to stdout in < 2.4

source-highlight --out-format=esc --input=enginerealsearch.cpp # prints to stdout

cat enginerealsearch.cpp | source-highlight --out-format=esc --lang-def=cpp.lang # prints to stdout

source-highlight --out-format=esc --input=midiobject.cpp --input=midiobjectnull.cpp
source-highlight: `--input' (`-i') option given more than once

source-highlight --out-format=esc --input="*.cpp"
source-highlight: cannot open input file *.cpp

I'll update my scripts to use the --input option...

Cheers,
-G

Revision history for this message
Lorenzo Bettini (bettini) said :
#4

Thank you for pointing this out: I admit that was badly documented :-)

I've just released 2.11.1 which documents this:

GNU source-highlight 2.11.1

Highlight the syntax of a source file (e.g. Java) into a specific format (e.g.
HTML)

Usage: source-highlight [OPTIONS]... < input_file > output_file
       source-highlight [OPTIONS]... -i input_file -o output_file
       source-highlight [OPTIONS]... [FILES]...

  -h, --help Print help and exit
      --detailed-help Print help, including all details and hidden
                                  options, and exit
...

Moreover, the program now checks whether a user mixes the two invocation modes, e.g., now with your original command line, you get this error

Please, use one of the two syntaxes for invocation:
     source-highlight [OPTIONS]... -i input_file -o output_file
     source-highlight [OPTIONS]... [FILES]...

and it is also documented:

http://www.gnu.org/software/src-highlite/source-highlight.html#Simple-Usage

Thanks again for your feedback!

Lorenzo

Revision history for this message
ironstorm (ironstorm-gmail) said :
#5

That's great, thanks again!