GNU Source-highlight 2.1

by Lorenzo Bettini

This program, given a source file, produces a document with syntax highlighting.

At the moment it generates output in these formats:

Since release 2.0 source-highlight reads source language specifications dynamically, thus it can now be easily extended (without recompiling the sources) for handling new languages.  The syntax for language specifications is quite easy (take a look at the manual).

NOTICE: now the name of the program is source-highlight: there are no two separate programs, namely java2html and cpp2html, anymore.  However there are two shell scripts with the same name in order to facilitate the migration (however their use is not advised).

GNU Source-highlight is free software. Please see the file COPYING for details. For documentation, please read this file.

GNU Source-highlight is a GNU program and its main home page is at GNU site:
http://www.gnu.org/software/src-highlite/source-highlight.html

For further information, please consult the manual.

On-line Manual

Download

You can download it from GNU's ftp site:
ftp://ftp.gnu.org/gnu/src-highlite/ or from one of its mirrors (see http://www.gnu.org/prep/ftp.html).

I do not distribute Windows binaries anymore; since, they can be easily built by using Cygnus C/C++ compiler, available at http://www.cygwin.com/. However, if you don't feel like downloading such compiler, you can request such binaries directly to me, by e-mail (find my e-mail at my home page) and I can send them to you.
An MS-Windows port of Source-highlight is available from http://gnuwin32.sourceforge.net/.

Anonymous CVS Access

This project's CVS repository can be checked out through anonymous (pserver) CVS with the following instruction set. When prompted for a password for anoncvs, simply press the Enter key.
cvs -d:pserver:anoncvs@subversions.gnu.org:/cvsroot/src-highlite login
cvs -z3 -d:pserver:anoncvs@subversions.gnu.org:/cvsroot/src-highlite co src-highlite
Further instructions can be found at the address: http://savannah.gnu.org/projects/src-highlite.

Please notice that this way you will get the latest development sources of Source-highlight, which may also be unstable. This solution is the best if you intend to correct/extend this program: you should send me patches against the latest cvs repository sources.

If, on the contrary, you want to get the sources of a given release, through cvs, say, e.g., version X.Y.Z, you must specify the tag rel_X_Y_Z when you run the cvs command or the cvs update command.

When you compile the sources that you get through the cvs repository, before running the configure and make commands, you should, at least the first time, run the command:

     sh reconf

This will run the autotools commands in the correct order, and also copy possibly missing files. You should have installed recent versions of automake and autoconf in order for this to succeed. You will also need flex and bison.

NOTICE: This convention holds since release 2.1.

Changes in this release

What you need to build source-highlight

Since version 2.0 Source-highlight relies on regular expressions as provided by boost (http://www.boost.org), so you need to install at least the regex library from boost.  Most GNU/Linux distributions provide this library already in a compiled form.

Usage and examples

source-highlight only does a lexical analysis of the source code, so the program source is assumed to be correct!

Finally, there is texinfo documentation.  It is also available as an html file, and it is also available on-line.

Here we only show some examples of generated files.

Here are some links to some of the C and C++ sources of source-highlight colored with source-highlight itself:

startapp.cc.html
generated with the following command
source-highlight -s cpp -f html --doc startapp.cc
Obviously it works with C files as well:
cmdline.c.html
Created with the command (notice that this one uses both CSS file and headers and footers):
source-highlight -s cpp -f html -i cmdline.c -o cmdline.c.html 
            --css="cpp2html.css"
            --header="./header.html" --footer="./footer.html"
And obviously it works with header file as well:
cmdline.h.html
created with the command:
source-highlight -s cpp -f html *.h --css="mono.css"
Here are some examples of Java files processed with source-highlight: Use Hello.java to make some test, if you want. Here's how Hello1.html, Hello2.html, Hello3.html, Hello4.html, Hello5.html, Hello_h_f.html, Hello_lines.html, Hello_xhtml.html, Hello_xhtml2.html were created:
source-highlight -s java -f html -i Hello.java -o Hello1.html
source-highlight -s java -f html --input Hello.java --output Hello2.html --doc
source-highlight -s java -f html -i Hello.java -o Hello3.html --title "Happy Java with java2html :-)" --tab 3
source-highlight -s java -f html < Hello.java > Hello4.html --title "and what about CSS :-)" --css "Hello.css"
source-highlight -s java -f html < Hello.java > Hello5.html --title "Wooo... this is quite dark ;-D" --css "mono-alt.css"
source-highlight -s java -f html --doc *.java
Processed Hello.java   (creates Hello.java.html)
source-highlight -s java -f html --doc -i Hello.java -o Hello_h_f.html --style-file="default.style" --header="header.html" --footer="footer.html"
source-highlight -s java -f html --line-number --doc -i Hello.java -o Hello_lines.html
source-highlight -s java -f xhtml --doc -i Hello.java -o Hello_xhtml.html --css xhtml.css
../src/source-highlight -s java -f xhtml --doc -i Hello.java -o Hello_xhtml2.html --style-file default.style
Here's the output of source-highlight applied to a Prolog program (through the option `source-highlight -s prolog`: test.pl.html.  This one is an highlighted Perl program (through the option `source-highlight -s prolog`): test.pm.html.  Here's an highlighted PHP3 program: test.php3.html. And here's a Python program: test.py.html.  This the flex scanner for flex files flex_scanner.ll.html. This is a Ruby program: test.rb.html. This is a Javascript program test.js.html.  This is a Lua test program test.lua.html.  This is a Caml test program test.ml.html and this is an Sml test program test.sml.html

Here are some log files formatted using the color file syslog.style:
Here's the html output of test.java.html formatted in html itself: test.htm.html.

Finally, here's the output of test.java.tex formatted in html: test.java.tex.html

Credits

See CREDITS for detailed contributions and THANKS  for a complete list of people that helped me with Source-highlight :-)

Feedback

Please tell me if you like this software :-)

Actually I want to extend it, so if you have some ideas...
The most import one will be to make source-highlight more customizable :-)

Please send all bug reports by electronic mail to:
bug-source-highlight at gnu dot org

TODO

Here's the list of TODO stuff, if you'd like to contribute :-)

Mailing Lists

The following mailing lists are available: if you want to subscribe to a mailing list just go to the URL and follow the instructions, or send me an e-mail and I'll subscribe you.

My home page is http://www.lorenzobettini.it

source-highlight is free software. See the file COPYING for copying conditions. Anyway I won't get offended if you send me a postcard :-)


Return to GNU's home page.

Please send FSF & GNU inquiries & questions to gnu@gnu.org. There are also other ways to contact the FSF.

Please send comments on these web pages to webmasters@gnu.org, send other questions to gnu@gnu.org.

Copyright (C) 2001 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

Updated:9 Jan 2001 mhw