Ave2HTML.exe

This utility converts Avenue scripts into nicely indented text with comments highlighted.  It has two principal uses: as a "pretty printer" that automatically indents Avenue scripts and as a means to communicate Avenue scripts on web pages.  Readers have also noted that it can be useful for reformatting unfamiliar scripts to enhance their readability.

Here is a side-by-side comparison of an input script and the output html:

Original Ave2HTML Output
'
' Small sample Avenue script.
'
theView = av.GetActiveDoc
theTheme = NIL ' Initialize theTheme
'
' Search for the first active feature theme.
'
for each t in theView.GetActiveThemes
if (t.Is(FTheme)) then ' Look only for FThemes
theTheme = t
break
end
end
'
' If a feature theme was found, report it.
'
if (theTheme <> NIL) then
MsgBox.Info(theTheme.GetName ++
"is the first active feature theme",
Script.The.GetName) ' Use the script's name as the title
end
' end of script
'
' Small sample Avenue script.
'

theView = av.GetActiveDoc
theTheme = NIL ' Initialize theTheme
'
' Search for the first active feature theme.
'

for each t in theView.GetActiveThemes
  if (t.Is(FTheme)) then ' Look only for FThemes
    theTheme = t
    break
  end
end
'
' If a feature theme was found, report it.
'

if (theTheme<>NIL) then
  MsgBox.Info(theTheme.GetName++"is the first active feature theme",Script.The.GetName) ' Use the script's name as the title
end
' end of script

Availability

Ave2HTML is free.  Download it from ESRI's ArcScripts pages.

Installation

Ave2HTML is a command-line utility.  Just download the file (an exe file) into any directory in your system path or into the directory where you want to use it.

Usage

At the command prompt type

ave2html {-font "#dddddd"} {-indent d} file1 {file2 ...} > output.htm

where

file1, file2, ... are names of input files.  (Only one file name is needed; all others are optional, as indicated by the curly brackets {}.)  Input files are text containing valid Avenue source.  They can be created with the Write Text File button in the ArcView Script Editor GUI.  (Invalid Avenue source will be detected, but output will end at the first error encountered.)  You can use wildcards in file names.

output.htm is the name of the output file.  Name it anything you want, but give it an htm or html extension.

-font and -indent are optional "flags" that modify the output slightly.  If either one appears, it must immediately be followed by a value.  In the case of the -font flag, the value should be a hexadecimal RGB string enclosed in double quotes.  For instance, "#ff0000" is bright red and "#006699", the default, is the cyan shown in the example above.  This will be the color given to comments.  In the case of the -indent flag, the value should be a positive whole number.  Quotes are not needed.  This determines the number of spaces put before each line to indent it.  The default is 2.

(There must be no space between the initial dash "-" and the font or indent keyword.  There must be at least one space between the keyword and the value that follows it.)

Examples

ave2html sample.ave > sample.htm

This creates a pretty html version of the contents of sample.ave.  The comments will be cyan and the indents will be two spaces.

ave2html -font "#c00000" -indent 4 sample.ave > test.htm

The output is named "test.htm".  The comment color is pale red (as in the example below) and the indents are four spaces.

ave2html sample.ave

The output will appear on the screen as html source text.

ave2html

The computer will sit and wait for you to type valid Avenue input at the keyboard.  Output will appear on the screen.

ave2html *.ave > all.htm

All files in the current directory with "ave" extensions will be processed.  The output will be concatenated into all.htm.

Interaction and Error Handling

Summary information will be displayed on the screen while the program is running, as in this example:

> ave2html *.ave -font #c00000 > test.htm

The screen output consists of the -font and -indent values used followed by the names of the files processed, one per line.  The number of tokens processed is a measure of total file size.

Any errors encountered will be listed on the screen as well:

test.ave.43 Expected ")" but got "then"
) then return true end
^

380 token(s) processed.

Here an error was encountered on line 43 of test.ave.  After issuing a description of the problem, the program emits the remaining portion of the line causing the error.  The caret symbol (^) points to the character being processed when the error was discovered.  All further processing stops, so only one error at a time can be discovered this way: there may still be more errors in the input files.

Limitations

Ave2HTML does not recognize long file names.  We apologize that limitations in the system used to create Ave2HTML prevent us from removing this inconvenience.

There are some work-arounds:.

  1.  Every file in the DOS/Windows file system has an equivalent short name: so just use the short name.  If you are using Ave2HTML interactively, then issue a DOS dir /X command to find the short versions of the long file names.  If you plan to use Ave2HTML automatically within ArcView (by writing scripts to temporary files for processing), use the DOS 8.3 naming convention when creating your temporary file names.
  2. Pipe the file to Ave2HTML.  Here are some examples:

type alongfilename.ave | ave2html - > alongfilename.htm

This command passes the contents of alongfilename.ave to Ave2HTML through a pipe.  The "-" following "ave2html" is a placeholder for the pipe.  The ">" directs the output to alongfilename.htm.

type alongfilename.ave | ave2html -indent 4 - > alongfilename.htm

This command does the same as the previous, but uses an indentation size of four spaces rather than the default of 2.

The examples given here were tested in the command window for Windows NT 4.0.  Other versions of Windows and DOS may have slightly different features (for instance, long file names will not be a problem on older versions of DOS) but the work-arounds described here will still be possible.

Ave2HTML provides little flexibility in formatting its HTML output

Solution: It is simple to edit the output.  The output has been structured to make it easy to extract groups of lines, to add additional font and background information, and so on.  The -indent and -font options spare you from having to do global search-and-replace operations. 

Special Features and Uses

If all you want is the reformatted text, without the HTML markup, then run Ave2HTML, point your browser at it, and copy it from your browser into an ArcView Script Editor document.

Ave2HTML executes rapidly: it can process tens to hundreds of input files per second.

It is not fooled by strange or complex scripts.  If you have a script for doing any kind of processing of Avenue scripts and it can handle the original below without error, then you can be proud.

Original Ave2HTML Output
'
' This is a valid executable Avenue script.
' Its variables are 'i', 'j', 's', 't', and strQuery.
' There is a public variable at the end, too.
'
'................................................'
'
' Nested loops: i and t are variables.
'
for each j in 0..1 ' Comments are placed after each line to fool parsers
for each t in 1..0 by -1 while (j <> t and (j=0)) ' Innermost loop
if (j+1=t) then if (j+2=t) then else j=-5 end ' The first clause is empty
elseif(j+3=t)then t=-1 elseif(j=(t-4))then ' Here is where i is defined
i=t-3 end end end end
'
' 's' should be recognized as a variable
'
if (av.GetActiveDoc.Is(View).Not) then exit end
for each s in av.GetActiveDoc.GetThemes
MsgBox.Info(s.GetName, "The theme = ")
end
'................................................'
'
' The following comments should not create 'variables'!
' SELF = a list
' The zeroth element is a string, = null if not used.
' In the case SELF=0 we use a different algorithm.
'................................................'
'
' Lack of line breaks can fool some parsers. The following
' may cause j to be overlooked as a variable.
'
if (13=15) then return false else j = 13 end
'................................................'
'
' Line breaks can fool parsers. The following may cause
' '0' to look like a variable.
'
if (
0 = i
or (1 = i) or (-2 = i) or (3<>-i) or
(7<> - i) or (13 <>- i) or (i<>-15) or (i <> -17)
) then return true end
'
' Lots of line breaks!
'
if
(
i
<>
0
)
then
return
nil
end
'
' This statement should not produce a 'variable'.
'
while ("garbage" ++ "=" <> "")
'
' Neither should this one.
'
break ' Always exit the loop when t = ""
end
'
' This statement should produce a variable strQuery, but
' NOT a variable [Id]
'
strQuery =
"[Id] = ""This is such a very long string that it is natural to break the assignment across lines."""
'
' This statement should not produce a 'variable'.
'
return (3=4) ' Return a boolean expression
'
' Public variables.
'
_thePublicVar = NIL
'
' Comments.
'
s = """' This is not a comment, it's a quoted string."
s = ""' This is a comment."
' end of script
'
' This is a valid executable Avenue script.
' Its variables are 'i', 'j', 's', 't', and strQuery.
' There is a public variable at the end, too.
'
'................................................'
'
' Nested loops: i and t are variables.
'

for each j in 0..1  ' Comments are placed after each line to fool parsers
  for each t in 1..0 by -1
    while (j<>t and (j=0)) ' Innermost loop
      if (j+1=t) then
        if (j+2=t) then
        else
          j = -5
        end  ' The first clause is empty
      elseif (j+3=t) then
        t = -1
      elseif (j=(t-4)) then  ' Here is where i is defined
        i = t-3
      end
    end
  end
end
'
' 's' should be recognized as a variable
'

if (av.GetActiveDoc.Is(View).Not) then
  exit
end
for each s in av.GetActiveDoc.GetThemes
  MsgBox.Info(s.GetName,"The theme = ")
end
'................................................'
'
' The following comments should not create 'variables'!
' SELF = a list
' The zeroth element is a string, = null if not used.
' In the case SELF=0 we use a different algorithm.
'................................................'
'
' Lack of line breaks can fool some parsers.  The following
' may cause j to be overlooked as a variable.
'

if (13=15) then
  return false
else
  j = 13
end
'................................................'
'
' Line breaks can fool parsers.  The following may cause
' '0' to look like a variable.
'

if ( 0=i or (1=i) or (-2=i) or (3<>-i) or (7<>-i) or (13<>-i) or (i<>-15) or (i<>-17)) then
  return true
end
'
' Lots of line breaks!
'

if (i<>0) then
  return nil
end
'
' This statement should not produce a 'variable'.
'

while ("garbage"++"="<>"")
  '
  ' Neither should this one.
  '

  break ' Always exit the loop when t = ""
end
'
' This statement should produce a variable strQuery, but
' NOT a variable [Id]
'

strQuery = "[Id] = ""This is such a very long string that it is natural to break the assignment across lines."""
'
' This statement should not produce a 'variable'.
'

return (3=4) ' Return a boolean expression
'
' Public variables.
'

_thePublicVar = NIL
'
' Comments.
'

s = """' This is not a comment, it's a quoted string."
s = ""' This is a comment."
' end of script

Modification History

28 January 2002:    The "Limitations" section was added in response to useful comments forwarded by Scott Kutz.

25 January 2002:    This page was created.

Google
ColorRamp, Memorized Calculations, Rotate, Sample, and Tissot  are  trademarks of Quantitative Decisions.  All other products mentioned are registered trademarks or trademarks of their respective companies.
Questions or problems regarding this web site should be directed to [email protected].
Copyright © 2000-2001 Quantitative Decisions.  All rights reserved.
Last modified: Monday January 28, 2002.