#! /usr/pkg/bin/perl
# -*- perl -*-
# Generated automatically from cim2latex.in by configure.

eval 'exec /usr/pkg/bin/perl -S $0 ${1+"$@"}'
    if 0;

# Copyright (C) 1996 Sverre Hvammen Johansen
# Department of Informatics, University of Oslo.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

$begin_listing=   "\\begin{alltt}\n\\raggedbottom{}";
					$end_listing=   "\\end{alltt}\n";
$begin_line=      "";			$end_line=      "\n";
$begin_keyword=   "\\textbf{";		$end_keyword=   "}";
$begin_symbol=    "";			$end_symbol=    "";
$begin_number=    "";			$end_number=    "";
$begin_identifier="";			$end_identifier="";
$begin_comment=   "\\textit{";		$end_comment=   "}";
$begin_string=    "";			$end_string=    "";
$begin_directive= "\\textit{\\textbf{";	$end_directive= "}}";

%threat_special= (
    '{',  '\\symbol{123}',
    '}',  '\\symbol{125}',
    '\\', '\\symbol{92}');

$case="prog";
print "$begin_listing";
while (<>) {
    print "$begin_line";
    $nl=chop($_);
    if ($nl ne "\n") { $_= $_ . $nl;}
    if (/^(% |# )/) { 
	print "$begin_comment";
	while(/(.)/g) { push(@words, $1);}
	while(@words) {
	    $word=shift(@words);
	    if ($threat_special{$word}) {
		print "$threat_special{$word}";
	    } else {
		print "$word";
	    } 
	}
	print "$end_comment";
    }
    elsif (/^(%|#)/) { 
	print "$begin_directive";
	while(/(.)/g) { push(@words, $1);}
	while(@words) {
	    $word=shift(@words);
	    if ($threat_special{$word}) {
		print "$threat_special{$word}";
	    } else {
		print "$word";
	    } 
	}
	print "$end_directive";
    } else {
	if ($case eq "comment" || $case eq "endcomment") {
	    print "$begin_comment";
	}
        while(/([a-z]\w*|2r[01][01_]*|4r[0-3][0-3_]*|8r[0-7][0-7_]*|16r[\da-f][\da-f_]*|((\d[\d_]*)?\.\d[\d_]*|\d[\d_])?&&?(\+|-)?\d[\d_]*|(\d[\d_]*)?\.\d[\d_]*|\d[\d_]*|\/\/|\*\*|&&|:=|:-|<=|>=|<>|==|=\/=|.)/ogi) {
#	while(/("|!|'|;|{|}|\\|[a-z]\w+|[0-9_]+(r[0-9a-f_]+)?|.)/ogi) {
            push(@words, $1);
        }
	while(@words) {
	    $word=shift(@words);
	    if ($threat_special{$word}) {
		print "$threat_special{$word}";
	    }
	    elsif ($case eq "prog") {
		if ($word eq "!") {
		    print "$begin_comment!";
		    $case="comment";
		}
		elsif ($word eq "\"") {
		    print "$begin_string\"";
		    $case="text";
		}
		elsif ($word eq "'") {
		    print "$begin_string\'";
		    $case="char";
		}
		elsif ($word=~/^(activate|after|and|array|at|before|begin|boolean|character|class|delay|do|else|eq|eqv|external|false|for|ge|go|goto|gt|hidden|if|imp|in|inner|inspect|integer|is|label|le|long|lt|name|ne|new|none|not|notext|or|otherwise|prior|procedure|protected|qua|reactivate|real|ref|short|step|switch|text|then|this|to|true|until|value|virtual|when|while)$/oi) {
		    print "$begin_keyword$word$end_keyword";
		}
		elsif ($word=~/^comment$/i) {
		    print "$begin_comment$begin_keyword$word$end_keyword";
		    $case="comment";
		}
		elsif ($word=~/^end$/i) {
		    print "$begin_keyword$word$end_keyword$begin_comment";
		    $case="endcomment";
		}
		elsif ($word=~/^[a-z]/i) {
		    print "$begin_identifier$word$end_identifier";
		}
		elsif ($word=~/[0-9]/i) {
		    print "$begin_number$word$end_number";
		}
		elsif ($word=~/\S/i) {
		    if ($word eq ";") {$par=0;}
		    elsif ($word eq "(") {$par=$par+1;}
		    elsif ($word eq ")") {$par=$par-1;}
		    if ($word eq ":-" && $par==1) {
			print "$begin_symbol:$end_symbol";
			print "$begin_symbol-$end_symbol";
		    } else {
			print "$begin_symbol$word$end_symbol";
		    }
		} else {
		    print "$word";
		}
	    }
	    elsif ($case eq "char") {
		print $word;
		if ($word eq "'") {
		    print "$end_string";
		    $case="prog";
		}
	    }
	    elsif ($case eq "text") {
		print $word;
		if ($word eq "\"") {
		    print "$end_string";
		    $case="prog";
		}
	    }
	    elsif ($case eq "comment") {
		if ($word eq ";") {
		    print ";$end_comment";
		    $case="prog";
		} else {
		    print $word;
		}
	    }
	    elsif ($case eq "endcomment") {
		if ($word eq ";") {
		    print "$end_comment;";
		    $case="prog";
		}
		elsif ($word=~/^end$/i) {
		    print "$end_comment$begin_keyword$word$end_keyword$begin_comment";
		}
		elsif ($word=~/^(else|when|otherwise)$/i) {
		    print "$end_comment$begin_keyword$word$end_keyword";
		    $case="prog";
		} else {
		    print $word;
		}
	    }
	}
	if ($case eq "comment" || $case eq "endcomment") {
	    print "$end_comment";
	}
    }
    print "$end_line";
    if ($case eq "char" || $case eq "text") {
	print "$end_string";
	$case="prog";
    }
}
if ($case eq "comment" || $case eq "endcomment") {
    print "$end_comment";
}
print "$end_listing";






