home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Lighthouse Design Suite
/
LIGHTHOUSE.mdf
/
TaskMaster_1.8
/
Application
/
FilterServicer.service
/
imx2p1
< prev
next >
Wrap
Text File
|
1995-03-30
|
20KB
|
868 lines
#!/usr/local/gnu/perl
#$debug = 1;
open(IMXFILE,"cat \"$ARGV[0]\" | tr \'\\015\' \'\\012\' |") || die"$ARGV[0] not readable.";
$| = 1; # Flush output buffers after each command
$modelName = $ARGV[1] . "/modelFile";
$interfaceName = $ARGV[1] . "/interfaceFile";
$formatName = $ARGV[1] . "/formatFile";
if((-f "$modelName") || (-f "$interfaceName") || (-f "$formatName"))
{
print "$ARGV[1] exists, overwriting\n";
}
elsif (!mkdir($ARGV[1], 0755))
{
die "Couldn't create $ARGV[1]";
}
open (MODEL, ">$modelName") || die "Couldn't open $modelName";
open (INTERFACE, ">$interfaceName") || die "Couldn't open $interfaceName";
open (FORMAT, ">$formatName") || die "Couldn't open $formatName";
#
# Write model, interface, and format with a single pass of IMX input
#
while(<IMXFILE>){
/^\s*Model/ && !$inModel && do {
$inModel = 1;
&debugOut("Found Model");
print MODEL "tables = (";
print INTERFACE "document = ";
print INTERFACE &startInterfaceObject;
print INTERFACE "dataDepictions = (";
print FORMAT "globalDefaultFont = {fontName = Helvetica; fontSize = 12;};\n";
$firstTable = 1;
@cellFormats = (); # One element for each view in the model. Each
# element is a newline-separated format list.
@cellFonts = (); # One element for each view in the model. Each
# element is a newline-separated font list.
@tableViewCount = (); # One element for each table. Each element is
# the number of views in the table.
next;
};
next if(!$inModel);
/^\s*Table\s*\"(.+)\"/ && !$inTable && do {
$inTable = 1;
$inNamespace = 1;
if (!$firstTable) {
print MODEL ", ";
print INTERFACE ", ";
} else {
$firstTable = 0;
}
&debugOut("Found table:$1");
print "Reading table $1...\n\n";
print MODEL &startModelObject();
print MODEL "name = \"$1\";";
print MODEL &returnModelIndent();
print MODEL "namespace = ";
print MODEL &startModelObject();
print MODEL "categories = (";
@categories = ();
$categoryIndex = 0;
%categoryIndices = ();
$firstCategory = 1;
print INTERFACE &startInterfaceObject();
print INTERFACE "name = \"$1\";";
print INTERFACE &returnInterfaceIndent();
print INTERFACE "depictions = (";
@views = ();
$firstView = 1;
push (@tableViewCount, 0);
next;
};
/^\s*Category\s*\"(.+)\"/ && !$inCategory && do {
$inCategory = 1;
&debugOut("Found Category: $1");
$categoryIndices{$1} = $categoryIndex;
$categoryIndex++;
$currentCategory = &startModelObject();
$currentCategory .= "name = \"$1\";";
$currentCategory .= &returnModelIndent();
$currentCategory .= "nodes = (";
$firstItem = 1;
$inGroup = 0;
next;
};
/^\s*Group\s*\"(.+)\"/ && do {
$inGroup++;
$currentCategory .= ", " if !$firstItem;
&debugOut("Found Group: $1");
$currentCategory .= &startModelObject();
$currentCategory .= "name = \"$1\";";
$currentCategory .= &returnModelIndent();
$currentCategory .= "children = (";
$firstItem = 1;
next;
};
/^\s*\"(.+)\"/ && $inCategory && do {
$currentCategory .= ", " if !$firstItem;
$firstItem = 0;
$currentCategory .= &startModelObject();
$currentCategory .= "name = \"$1\";";
$currentCategory .= &endModelObject();
next;
};
/^\s*End/ && $inGroup && do {
&debugOut("End Group");
$currentCategory .= ");";
$currentCategory .= &endModelObject();
$inGroup--;
next;
};
/^\t\tEnd/ && $inCategory && do {
&debugOut("End Category");
$currentCategory .= ");";
$currentCategory .= &endModelObject();
push(@categories, $currentCategory);
$inCategory = 0;
next;
};
/^\s*View\s*\"(.+)\"/ && !$inView && do {
push (@cellFormats, "");
push (@cellFonts, "");
if($inNamespace){
&doCategories();
&fixCategoryIndices;
print MODEL ");";
$inNamespace = 0;
print MODEL &endModelObject();
print MODEL ";";
}
if($firstView) {
$inDepictions = 1;
$firstView = 0;
}
$inView = 1;
&debugOut("Found View: $1");
print "Reading view $1.\n\n";
$tableViewCount[$#tableViewCount] += 1;
$currentView = &startInterfaceObject; # Start depictions element
$currentView .= "name = \"$1\";";
$currentView .= &returnInterfaceIndent;
$currentView .= "worksheetView = ";
$currentView .= &startInterfaceObject; # Start worksheetView
next;
};
/^\t\t\tRows/ && $inView && do {
$inRows = 1;
&debugOut("Found Rows");
next;
};
/^\s*\".+\"/ && $inRows && do {
chop;
$_ = "\" $_ \"";
@rows = split (/\"\s+\"/);
shift @rows;
foreach $row (@rows) {
&debugOut("Found Row: $row") if (length($row) > 0);
}
$currentView .= "yCategories = (";
$currentView .= "$categoryIndices{$rows[0]}";
$currentView .= ", $categoryIndices{$rows[1]}" if (length ($rows[1]) > 0);
$currentView .= ", $categoryIndices{$rows[2]}" if (length ($rows[2]) > 0);
$currentView .= ", $categoryIndices{$rows[3]}" if (length ($rows[3]) > 0);
$currentView .= ");";
$currentView .= &returnInterfaceIndent;
next;
};
/^\t\t\tEnd/ && $inRows && do {
$inRows = 0;
&debugOut("End Rows");
next;
};
/^\t\t\tColumns/ && $inView && do {
$inColumns = 1;
&debugOut("Found Columns");
next;
};
/^\s*\".+\"/ && $inColumns && do {
chop;
$_ = "\" $_ \"";
@columns = split (/\"\s+\"/);
shift @columns;
foreach $column (@columns) {
&debugOut("Found Column: $column") if (length($column) > 0);
}
$currentView .= "xCategories = (";
$currentView .= "$categoryIndices{$columns[0]}";
$currentView .= ", $categoryIndices{$columns[1]}" if (length ($columns[1]) > 0);
$currentView .= ", $categoryIndices{$columns[2]}" if (length ($columns[2]) > 0);
$currentView .= ", $categoryIndices{$columns[3]}" if (length ($columns[3]) > 0);
$currentView .= ");";
$currentView .= &returnInterfaceIndent;
next;
};
/^\t\t\tEnd/ && $inColumns && do {
$inColumns = 0;
&debugOut("End Columns");
next;
};
/^\t\t\tPerspective/ && $inView && do {
$inPerspective = 1;
&debugOut("Found Perspective");
next;
};
/^\s*\".+\"/ && $inPerspective && do {
chop;
$_ = "\" $_ \"";
@perspective = split (/\"\s+\"/);
shift @perspective;
foreach $zcat (@perspective) {
&debugOut("Found Perpsective: $zcat") if (length($zcat) > 0);
}
$currentView .= "zCategories = (";
$currentView .= "$categoryIndices{$perspective[0]}";
$currentView .= ", $categoryIndices{$perspective[1]}" if (length ($perspective[1]) > 0);
$currentView .= ", $categoryIndices{$perspective[2]}" if (length ($perspective[2]) > 0);
$currentView .= ", $categoryIndices{$perspective[3]}" if (length ($perspective[3]) > 0);
$currentView .= ");";
next;
};
/^\t\t\tEnd/ && $inPerspective && do {
$inPerspective = 0;
&debugOut("End Perspective");
next;
};
/^\t\t\tFormats/ && $inView && do {
$inFormats = 1;
&debugOut("Found Formats");
$currentView .= &returnInterfaceIndent;
# Set the default cell format to resemble Improv's
$currentView .= "defaultCellFormat={textFont={fontName=Helvetica;fontSize=12;};useStringDefault=NO;formatString=0;};";
$currentView .= &endInterfaceObject(); # End worksheetView
$currentView .= ";";
next;
};
/^\t\t\t\tDefault/ && $inFormats && do {
chop;
s/^\t*Default\s*//;
s/\s*$//;
$defaultCellFormat = $_;
next;
};
/^\t\t\t\tData/ && $inFormats && do {
$inFormatsData = 1;
$formatsConcat = "";
&debugOut("Found Formats Data");
next;
};
/^\t\t\t\tEnd/ && $inFormatsData && do {
$inFormatsData = 0;
&debugOut("End Formats Data");
foreach $format (&splitCommaList ($formatsConcat)) {
if (length($format) > 0) {
$cellFormats[$#cellFormats] .= $format . "\n";
} else {
$cellFormats[$#cellFormats] .= $defaultCellFormat . "\n";
}
}
local (@debugCellFormats) = split (/\n/, $cellFormats[$#cellFormats]);
&debugOut ("Number of formats minus 1: $#debugCellFormats");
next;
};
/^\t\t\tEnd/ && $inFormats && do {
$inFormats = 0;
&debugOut("End Formats");
next;
};
$inFormatsData && do {
chop;
$formatsConcat .= $_;
next;
};
next if $inFormats;
/^\t\t\tFonts/ && $inView && do {
&debugOut("Found Fonts");
$inFonts = 1;
next;
};
/^\t\t\t\tDefault/ && $inFonts && do {
chop;
s/^\t*Default\s*//;
s/\s*$//;
$defaultCellFont = &convertFont($_);
next;
};
/^\t\t\t\tData/ && $inFonts && do {
$fontsConcat = "";
$inFontsData = 1;
&debugOut("Found Fonts Data");
next;
};
/^\t\t\t\tEnd/ && $inFontsData && do {
$inFontsData = 0;
&debugOut("End Fonts Data");
foreach $font (&splitCommaList ($fontsConcat)) {
if (length($font) > 0) {
$font = &convertFont($font);
$cellFonts[$#cellFonts] .= $font . "\n";
} else {
$cellFonts[$#cellFonts] .= $defaultCellFont . "\n";
}
}
local (@debugCellFonts) = split (/\n/, $cellFonts[$#cellFonts]);
&debugOut ("Number of fonts minus 1: $#debugCellFonts");
next;
};
$inFontsData && do {
chop;
$fontsConcat .= $_;
next;
};
/^\t\t\tEnd/ && $inFonts && do {
&debugOut("End Fonts");
$inFonts = 0;
@formats = split (/\n/, $cellFormats[$#cellFormats]);
@fonts = split (/\n/, $cellFonts[$#cellFormats]);
local ($i);
for ($i = $#formats - $#fonts; $i > 0; $i--) {
$cellFonts[$#cellFonts] .= $defaultCellFont . "\n";
}
next;
};
next if $inFonts;
/^\t\tEnd/ && $inView && do {
&debugOut("End View");
$currentView .= &endInterfaceObject(); # End depictions element
push(@views, $currentView);
$inView = 0;
next;
};
next if $inView;
/^\s*Data/ && !$inData && do {
if($inDepictions){
&doViews();
$inDepictions = 0;
print INTERFACE ");"; # End of depictions list
print INTERFACE &endInterfaceObject;# End dataDepictions element
}
$inData = 1;
&debugOut("Found Data");
print "Reading data.\n\n";
print MODEL &returnModelIndent();
print MODEL "dataspace = (";
next;
};
/^\t\tEnd$/ && $inData && do {
&debugOut("End Data");
$inData = 0;
print MODEL ");";
next;
};
/^\t*(.*)$/ && $inData && do {
print MODEL $1;
};
/^\tEnd/ && $inTable && do {
&debugOut("End Table");
$inTable = 0;
print MODEL &endModelObject();
next;
};
/\s*Formulas/ && !$inFormulas && do {
$inFormulas = 1;
&debugOut("Found Formulae");
print MODEL &returnModelIndent();
print MODEL "formulaspace = ";
print MODEL &startModelObject();
print MODEL "formulae = (";
$firstFormula = 1;
};
/\t\t\t\"(.*)\"$/ && $inFormulas && do {
print MODEL ", " if !$firstFormula;
$firstFormula = 0;
print MODEL &startModelObject();
$filtered = &filterFunction($1);
print MODEL "formula = \"$filtered\";";
print MODEL &endModelObject();
};
/\t\tEnd/ && $inFormulas && do {
&debugOut("End Formulae");
$inFormulas = 0;
print MODEL ");";
print MODEL &endModelObject();
print MODEL ";";
};
/^End/ && do {
$inModel = 0;
print "Done.\n\n";
print MODEL ");\n";
print INTERFACE ");";
print INTERFACE &endInterfaceObject; # End document
print INTERFACE ";\n";
&doFormats;
break; # Assume one model per imx file
};
}
close(MODEL);
close(INTERFACE);
close(FORMAT);
sub startModelObject {
local($retString) = "";
$retString = "{";
$modelLevel++;
$retString .= &returnModelIndent;
return $retString;
}
sub startInterfaceObject {
local($retString) = "";
$retString = "{";
$interfaceLevel++;
$retString .= &returnInterfaceIndent;
return $retString;
}
sub startFormatObject {
local($retString) = "";
$retString = "{";
$formatLevel++;
$retString .= &returnFormatIndent;
return $retString;
}
sub endModelObject {
local($retString);
$modelLevel--;
$retString = &returnModelIndent;
$retString .= "}";
return $retString;
}
sub endInterfaceObject {
local($retString);
$interfaceLevel--;
$retString = &returnInterfaceIndent;
$retString .= "}";
return $retString;
}
sub endFormatObject {
local($retString);
$formatLevel--;
$retString = &returnFormatIndent;
$retString .= "}";
return $retString;
}
sub returnModelIndent {
return &returnIndent($modelLevel);
}
sub returnInterfaceIndent {
return &returnIndent($interfaceLevel);
}
sub returnFormatIndent {
return &returnIndent($formatLevel);
}
sub returnIndent {
local ($level) = @_;
local($retString);
local($ct) = $level;
return if $level < 0;
$retString = "\n";
while($ct--){
$retString .= " ";
}
return $retString;
}
sub doCategories {
local($category);
$category = pop(@categories);
print MODEL $category;
while($category = pop(@categories)){
print MODEL ", $category";
}
}
sub fixCategoryIndices {
local (@keys) = keys %categoryIndices;
for $key (keys %categoryIndices) {
$categoryIndices{$key} = $#keys - $categoryIndices{$key};
}
}
sub doViews {
local($view);
$view = pop(@views);
print INTERFACE $view;
while($view = pop(@views)){
print INTERFACE ", $view";
}
}
sub doFormats {
local ($firstTable);
print FORMAT "depictionFormats = (";
# Build cell formats hash table
local ($i);
local (%formatIdTable);
local (@formats);
local (@fonts);
for ($i = 0; $i <= $#cellFormats; $i++) {
@formats = split (/\n/, $cellFormats[$i]);
@fonts = split (/\n/, $cellFonts[$i]);
while ($#formats >= 0) {
$string = pop(@formats) . "\n". pop(@fonts);
if (!$formatIdTable{$string}) {
local ($id);
local (@keys) = keys (%formatIdTable);
$id = $#keys + 2;
$formatIdTable{$string} = $id;
}
}
}
# Build cell format lists hash table
local (%formatListIdTable);
local (@formats);
local (@fonts);
$i = 0;
# For each table...
for ($tableIndex = 0; $tableIndex <= $#tableViewCount; $tableIndex++) {
$viewCount = $tableViewCount[$tableIndex];
print FORMAT &startFormatObject;
print FORMAT "cellFormats = (";
local ($count);
local (@formatLists);
# For each view in the table...
for ($count = 0; $count < $viewCount; $count++) {
@formats = split (/\n/, $cellFormats[$i]);
@fonts = split (/\n/, $cellFonts[$i]);
# For each cell in the table...
while ($#formats >= 0) {
$formatLists[$#formats] .= pop(@formats)."\n".pop(@fonts)."\r";
}
$i++;
}
while ($#formatLists >= 0) {
$formatList = shift(@formatLists);
if (!$formatListIdTable{$formatList}) {
local ($id);
local (@keys) = keys (%formatListIdTable);
$id = $#keys + 2;
$formatListIdTable{$formatList} = $id;
}
print FORMAT $formatListIdTable{$formatList};
print FORMAT ", " if $#formatLists >= 0;
}
print FORMAT ");";
#! itemFormats and categoryFormats here
print FORMAT &endFormatObject;
print FORMAT ", " if $tableIndex < $#tableViewCount;
}
print FORMAT ");", &returnFormatIndent;
local (@listKeys) = keys (%formatListIdTable);
local ($numberOfLists) = $#listKeys + 1;
print FORMAT "cellFormatLists = (";
for ($i = 0; $i <= $#listKeys; $i++) {
print FORMAT &startFormatObject;
print FORMAT "id = $formatListIdTable{$listKeys[$i]};";
print FORMAT &returnFormatIndent;
print FORMAT "formats = (";
local (@splitList) = split (/\r/, $listKeys[$i]);
while ($#splitList >= 0) {
print FORMAT $formatIdTable{pop(@splitList)} + $numberOfLists;
print FORMAT ", " if $#splitList >= 0;
}
print FORMAT ");";
print FORMAT &endFormatObject;
print FORMAT ", " if $i < $#listKeys;
}
print FORMAT ");", &returnFormatIndent;
local (@formatKeys) = keys (%formatIdTable);
print FORMAT "cellFormats = (";
for ($i = 0; $i <= $#formatKeys; $i++) {
print FORMAT &startFormatObject;
print FORMAT "id = ", $formatIdTable{$formatKeys[$i]} + $numberOfLists;
print FORMAT ";", &returnFormatIndent;
local ($format, $font) = split (/\n/, $formatKeys[$i]);
if ($format ne "\"G\"") {
if ($format =~ /^"*DT/) {
print FORMAT "stringType = date;", &returnFormatIndent;
}
&debugOut ("Convert Improv format $format");
$format = &convertFormat ($format);
&debugOut ("to Quantrix format $format");
print FORMAT "useStringDefault = NO;", &returnFormatIndent;
print FORMAT "formatString = $format;", &returnFormatIndent;
}
print FORMAT "useFontDefault = NO;", &returnFormatIndent;
print FORMAT "textFont = {",$font,"};";
print FORMAT &endFormatObject;
print FORMAT ", " if $i < $#formatKeys;
}
print FORMAT ");", &returnFormatIndent;
}
sub convertFont {
local ($improvFont) = $_[0];
local ($fontName, $fontSize);
$improvFont =~ s/^"(.*)"$/$1/;
$fontSize = $improvFont;
$fontSize =~ s/^[^0-9]*//;
$_ = $improvFont;
table: {
$fontName = "Courier-BoldOblique", last table if /^CBO/;
$fontName = "Courier-Oblique", last table if /^CO/;
$fontName = "Courier-Bold", last table if /^CB/;
$fontName = "Courier", last table if /^C/;
$fontName = "Helvetica-BoldOblique", last table if /^HBO/;
$fontName = "Helvetica-Oblique", last table if /^HO/;
$fontName = "Helvetica-Bold", last table if /^HB/;
$fontName = "Helvetica", last table if /^H/;
$fontName = "Ohlfs", last table if /^O/;
$fontName = "Symbol", last table if /^S/;
$fontName = "Times-BoldItalic", last table if /^TBI/;
$fontName = "Times-Italic", last table if /^TI/;
$fontName = "Times-Bold", last table if /^TB/;
$fontName = "Times-Roman", last table if /^TR/;
$fontName = "GothicBBBHelvetica-BoldOblique", last table if /^GBBBHBO/;
$fontName = "GothicBBBHelvetica-Oblique", last table if /^GBBBHO/;
$fontName = "GothicBBBHelvetica-Bold", last table if /^GBBBHB/;
$fontName = "GothicBBBHelvetica", last table if /^GBBBH/;
$fontName = "RyuuminTimes-BoldOblique", last table if /^RTBO/;
$fontName = "RyuuminTimes-Bold", last table if /^RTB/;
$fontName = "RyuuminTimes-LightOblique", last table if /^RTLO/;
$fontName = "RyuuminTimes-Light", last table if /^RTL/;
$fontName = "";
}
if (length ($fontName) > 0) {
return "fontName = \"$fontName\"; fontSize = $fontSize;";
} else {
return $defaultCellFont;
}
}
sub convertFormat {
local ($improvFormat) = $_[0];
$improvFormat =~ s/^"(.*)"$/\1/;
if ($improvFormat =~ /^DT/) {
$improvFormat =~ s/^DT//;
return &convertDateFormat ($improvFormat);
} elsif ($improvFormat =~ /^N/) {
$improvFormat =~ s/^N//;
return &convertNumberFormat ($improvFormat);
} elsif ($improvFormat =~ /^CN/) {
$improvFormat =~ s/^CN//;
return &convertCustomNumberFormat ($improvFormat);
}
}
sub convertDateFormat {
local ($improvFormat) = $_[0];
local ($newFormat);
$newFormat = $improvFormat;
return '"'.$improvFormat.'"';
}
sub convertNumberFormat {
local ($improvFormat) = $_[0];
local ($newFormat);
local ($digits);
local ($i);
$digits = $improvFormat;
$digits =~ s/^(\d*)\D.*/$1/;
if ($digits > 0) {
$newFormat = "0.";
} else {
$newFormat = "9";
}
for ($i = 1; $i <= $digits; $i++) {
$newFormat .= "0";
}
if ($improvFormat =~ /e/) {
$newFormat .= "E+00";
}
if ($improvFormat =~ /\%/) {
$newFormat .= "%";
}
if ($improvFormat =~ /,/) {
$newFormat = "," . $newFormat;
}
if ($improvFormat =~ /\$/) {
$newFormat = "$" . $newFormat;
}
if (!($improvFormat =~ /-/)) {
$newFormat = $newFormat . ";(" . $newFormat . ")";
}
return '"'.$newFormat.'"';
}
sub convertCustomNumberFormat {
local ($improvFormat) = $_[0];
local ($newFormat);
$newFormat = $improvFormat;
$newFormat =~ s/;N/;/g;
return '"'.$newFormat.'"';
}
sub splitCommaList {
local ($input) = $_[0];
local (@elements);
local ($letter);
local ($string);
local ($inString) = 0;
foreach $letter (split (/ */, $input)) {
if ($letter eq '"') {
$inString = !$inString;
$string .= $letter;
} elsif ($inString) {
$string .= $letter;
}
if (!$inString && ($letter eq ',')) {
push (@elements, $string);
$string = '';
}
}
if ((length($string) > 0) || ($input =~ /, *$/)) {
push (@elements, $string);
}
return @elements;
}
sub filterFunction {
local($string) = $_[0];
$string =~ s/select([a-z]+)\(([^\)]*)\)/$1\(select\($2\)\)/iog;
$string =~ s/\@ +/@/g;
return $string;
}
sub debugOut {
print stderr @_, "\n" if $debug;
}