Hello,
We work with programming language called UPC:
  http://en.wikipedia.org/wiki/Unified_Parallel_C
  http://gccupc.org/

Recently, one of our developers has added source code highlighting
support for UPC to both the GNU source code highlighter
(http://www.gnu.org/software/src-highlite/) and the
GeSHi source code highlighter (http://qbnz.com/highlighter/).
GeSHi is the source code highlighter used in MediaWiki
(http://www.mediawiki.org/wiki/MediaWiki).

Our motivation for extending the GNU source code highlighter
was mainly to support highlighting of UPC code in asciidoc
generated documents.

This proved to be more difficult/challenging than it at first seemed.
The asciidoc documentation provides the following source highlighting example:
http://www.methods.co.nz/asciidoc/source-highlight-filter.html
It states that for HTML output that the GNU source code highlighter
is used, but that for DocBook:

    AsciiDoc encloses the source code in a DocBook programlisting element and
    leaves source code highlighting to the DocBook toolchain

Further it states:

    dblatex has a particularly nice programlisting highlighter

Attached, is an example/test.  With this example, and our
newly tweaked GNU source highlighting tool, we had hoped to generate
meaningful multi-colored highlighted UPC source code.  This proved
not to be as easy as it first might seem.

Also attached, is 'upc-highlight.upc.html'.  This is the colorized
output from the enhanced version of source-highlight that understands UPC.
This is something like what we would like to see in the generated PDF file.

As the generated DocBook .xml file makes its way through the tool chain,
eventually pdflatex objects:

asciidoc-test-upc-highlight.tex:59: Package Listings Error: Couldn't load 
requested language.
asciidoc-test-upc-highlight.tex:59: leading text: 
...n{lstlisting}[language=UPC,firstnumber=1,]

In the log, pdflatex issues the following error:

    ! Package Listings Error: Couldn't load requested language.
    See the Listings package documentation for explanation.
    Type  H <return>  for immediate help.
     ...
    l.59 ...n{lstlisting}[language=UPC,firstnumber=1,]
    The following languages weren't loadable:
        ,upc$
    This may cause errors in the sequel.

Further analysis indicates that source highlighting for dblatex is handled
in /usr/share/dblatex/xsl/classsynopsis.xsl:

    <xsl:when test="$language='cpp'">
          <xsl:apply-templates select="." mode="cpp"/></xsl:when>

(Thus, it would seem that somewhere along the line that the
language "C" is mapped to "cpp".)

Given the current situation, it would seem that the default plan
of action would be to enhance classsynopsis.xsl to understand
language=UPC.

However, I'd prefer it if a separate tool like source-highlight
can be used to generate a file that can be used by either
the dblatex backend or the 'fop' backend to produce the
desired colorized output.  In other words, a mode of operation
that does not use dblatex's method of colorization and is
backend-independent.

Given the ability to invoke a filter program like source-highlight,
it would seem that this is perhaps do-able.  For example,
source-highlight can produce DocBook .xml (also attached).
Unfortunately, it seems that the information in the generated .xml 
file is not detailed enough to provide control over the final
colorization:

<programlisting>
  <emphasis role="strong">relaxed</emphasis>
  <emphasis role="strong">shared</emphasis> [5] int *
  <emphasis role="strong">shared</emphasis> shared_ptr_to_shared;

This is the way this looks in .html:

<pre><tt>
  <b><font color="#0000FF">relaxed</font></b>
  <b><font color="#0000FF">shared</font></b>
  <font color="#990000">[</font>
  <font color="#993399">5</font>
  <font color="#990000">]</font>
  <font color="#009900">int</font>
  <font color="#990000">*</font>
  <b><font color="#0000FF">shared</font></b>
  shared_ptr_to_shared
  <font color="#990000">;</font>

Summarizing, I'd like to find a way to generate a PDF file via
either dblatex or fop that uses an external program which performs
the colorization markup.  In our example, the external program is
'source-highlight' and it is aware of a particular "C" language
dialect, not currently recognized by the dblatex tool chain.

Is there a way to get there from here?

- Gary

-- 
You received this message because you are subscribed to the Google Groups 
"asciidoc" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/asciidoc?hl=en.

:doctype: article
:Author: Gary Funck
:Author Initials: GF

Test Highlighting of UPC Source File
====================================

This test case makes use of the newly added GNU source highlighter
capability which highlights UPC source code.  UPC (Unified Parallel C)
is an extension the "C" programming language which has features
that support parallel execution, and is typically used in
High Performance Computing (HPC) applications.

The following source code excerpt illustrates the highlighting
of various UPC constructs.

[source,UPC]
----
relaxed shared [5] int *shared shared_ptr_to_shared;
strict shared [5] int y[100 * THREADS];
strict shared [5] int z[100 * THREADS];
int x[100];
shared int shared_int;
int local_int = 99;
shared int *ptr_to_shared_int;

int
main ()
{
  int i;
  size_t size;
  upc_lock_t *lock;
  lock = upc_global_lock_alloc ();
  upc_barrier 1;
  upc_forall (i = 0; i < 100 * THREADS; ++i; &z[i])
    {
      int j;
      for (j = 0; j < 100; ++j)
        {
#pragma upc strict
          if (x[i] < x[j])
            {
              upc_lock (lock);
              z[i][j] = x[i] * y[j];
              upc_unlock (lock);
            }
          else
            {
              upc_fence;
              z[i][j] = -x[i] * y[j];
              upc_fence;
            }
        }
      upc_notify 10;
      upc_wait 10;
    }
  size = upc_blocksizeof (z);
  size = upc_localsizeof (z);
  size = upc_elemsizeof (z);
  upc_lock_free (lock);
}
----

NOTE: End of test.

relaxed shared [5] int *shared shared_ptr_to_shared;
strict shared [5] int y[100 * THREADS];
strict shared [5] int z[100 * THREADS];
int x[100];
shared int shared_int;
int local_int = 99;
shared int *ptr_to_shared_int;

int
main ()
{
  int i;
  size_t size;
  upc_lock_t *lock;
  lock = upc_global_lock_alloc ();
  upc_barrier 1;
  upc_forall (i = 0; i < 100 * THREADS; ++i; &z[i])
    {
      int j;
      for (j = 0; j < 100; ++j)
	{
#pragma upc strict
	  if (x[i] < x[j])
	    {
	      upc_lock (lock);
	      z[i][j] = x[i] * y[j];
	      upc_unlock (lock);
	    }
	  else
	    {
	      upc_fence;
	      z[i][j] = -x[i] * y[j];
	      upc_fence;
	    }
	}
      upc_notify 10;
      upc_wait 10;
    }
  size = upc_blocksizeof (z);
  size = upc_localsizeof (z);
  size = upc_elemsizeof (z);
  upc_lock_free (lock);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd";>
<?asciidoc-toc?>
<?asciidoc-numbered?>

<article lang="en">
<articleinfo>
    <title>Test Highlighting of UPC Source File</title>
    <author>
        <firstname>Gary</firstname>
        <surname>Funck</surname>
    </author>
    <authorinitials>GF</authorinitials>
</articleinfo>
<simpara>This test case makes use of the newly added GNU source highlighter
capability which highlights UPC source code.  UPC (Unified Parallel C)
is an extension the "C" programming language which has features
that support parallel execution, and is typically used in
High Performance Computing (HPC) applications.</simpara>
<simpara>The following source code excerpt illustrates the highlighting
of various UPC constructs.</simpara>
<programlisting language="UPC" linenumbering="unnumbered">relaxed shared [5] int *shared shared_ptr_to_shared;
strict shared [5] int y[100 * THREADS];
strict shared [5] int z[100 * THREADS];
int x[100];
shared int shared_int;
int local_int = 99;
shared int *ptr_to_shared_int;

int
main ()
{
  int i;
  size_t size;
  upc_lock_t *lock;
  lock = upc_global_lock_alloc ();
  upc_barrier 1;
  upc_forall (i = 0; i &lt; 100 * THREADS; ++i; &amp;z[i])
    {
      int j;
      for (j = 0; j &lt; 100; ++j)
        {
#pragma upc strict
          if (x[i] &lt; x[j])
            {
              upc_lock (lock);
              z[i][j] = x[i] * y[j];
              upc_unlock (lock);
            }
          else
            {
              upc_fence;
              z[i][j] = -x[i] * y[j];
              upc_fence;
            }
        }
      upc_notify 10;
      upc_wait 10;
    }
  size = upc_blocksizeof (z);
  size = upc_localsizeof (z);
  size = upc_elemsizeof (z);
  upc_lock_free (lock);
}</programlisting>
<note><simpara>End of test.</simpara></note>
</article>
<programlisting><emphasis role="strong">relaxed</emphasis> <emphasis role="strong">shared</emphasis> [5] int *<emphasis role="strong">shared</emphasis> shared_ptr_to_shared;
<emphasis role="strong">strict</emphasis> <emphasis role="strong">shared</emphasis> [5] int y[100 * THREADS];
<emphasis role="strong">strict</emphasis> <emphasis role="strong">shared</emphasis> [5] int z[100 * THREADS];
int x[100];
<emphasis role="strong">shared</emphasis> int shared_int;
int local_int = 99;
<emphasis role="strong">shared</emphasis> int *ptr_to_shared_int;

int
<emphasis role="strong">main</emphasis> ()
{
  int i;
  size_t size;
  upc_lock_t *lock;
  lock = <emphasis role="strong">upc_global_lock_alloc</emphasis> ();
  <emphasis role="strong">upc_barrier</emphasis> 1;
  <emphasis role="strong">upc_forall</emphasis> (i = 0; i &lt; 100 * THREADS; ++i; &amp;z[i])
    {
      int j;
      <emphasis role="strong">for</emphasis> (j = 0; j &lt; 100; ++j)
	{
<emphasis role="strong">#pragma</emphasis> upc <emphasis role="strong">strict</emphasis>
	  <emphasis role="strong">if</emphasis> (x[i] &lt; x[j])
	    {
	      <emphasis role="strong">upc_lock</emphasis> (lock);
	      z[i][j] = x[i] * y[j];
	      <emphasis role="strong">upc_unlock</emphasis> (lock);
	    }
	  <emphasis role="strong">else</emphasis>
	    {
	      <emphasis role="strong">upc_fence</emphasis>;
	      z[i][j] = -x[i] * y[j];
	      <emphasis role="strong">upc_fence</emphasis>;
	    }
	}
      <emphasis role="strong">upc_notify</emphasis> 10;
      <emphasis role="strong">upc_wait</emphasis> 10;
    }
  size = <emphasis role="strong">upc_blocksizeof</emphasis> (z);
  size = <emphasis role="strong">upc_localsizeof</emphasis> (z);
  size = <emphasis role="strong">upc_elemsizeof</emphasis> (z);
  <emphasis role="strong">upc_lock_free</emphasis> (lock);
}
</programlisting>

Reply via email to