home *** CD-ROM | disk | FTP | other *** search
/ Lighthouse Design Suite / LIGHTHOUSE.mdf / Quantrix_1.2 / Application / FilterServicer.service / imx2p1 < prev    next >
Text File  |  1995-03-30  |  20KB  |  868 lines

  1. #!/usr/local/gnu/perl
  2.  
  3. #$debug = 1;
  4.  
  5. open(IMXFILE,"cat \"$ARGV[0]\" | tr \'\\015\' \'\\012\' |") || die"$ARGV[0] not readable.";
  6.  
  7. $| = 1;        # Flush output buffers after each command
  8.  
  9.  
  10. $modelName = $ARGV[1] . "/modelFile";
  11. $interfaceName = $ARGV[1] . "/interfaceFile";
  12. $formatName = $ARGV[1] . "/formatFile";
  13.  
  14. if((-f "$modelName") || (-f "$interfaceName") || (-f "$formatName"))
  15. {
  16.     print "$ARGV[1] exists, overwriting\n";
  17. }
  18. elsif (!mkdir($ARGV[1], 0755))
  19. {
  20.     die "Couldn't create $ARGV[1]";
  21. }
  22.  
  23.  
  24. open (MODEL, ">$modelName") || die "Couldn't open $modelName";
  25. open (INTERFACE, ">$interfaceName") || die "Couldn't open $interfaceName";
  26. open (FORMAT, ">$formatName") || die "Couldn't open $formatName";
  27.  
  28.  
  29. #
  30. #  Write model, interface, and format with a single pass of IMX input
  31. #
  32.  
  33. while(<IMXFILE>){
  34.  
  35.     /^\s*Model/ && !$inModel && do {
  36.     $inModel = 1;
  37.     &debugOut("Found Model");
  38.     print MODEL "tables = (";
  39.     print INTERFACE "document = ";
  40.     print INTERFACE &startInterfaceObject;
  41.     print INTERFACE "dataDepictions = (";
  42.     print FORMAT "globalDefaultFont = {fontName = Helvetica; fontSize = 12;};\n";
  43.     $firstTable = 1;
  44.  
  45.     @cellFormats = ();    # One element for each view in the model.  Each
  46.                 # element is a newline-separated format list.
  47.     @cellFonts = ();    # One element for each view in the model.  Each
  48.                 # element is a newline-separated font list.
  49.     @tableViewCount = ();    # One element for each table.  Each element is
  50.                 # the number of views in the table.
  51.  
  52.     next;
  53.     };
  54.  
  55.     next if(!$inModel);
  56.  
  57.     /^\s*Table\s*\"(.+)\"/ && !$inTable && do {
  58.     $inTable = 1;
  59.     $inNamespace = 1;
  60.     if (!$firstTable) {
  61.         print MODEL ", ";
  62.         print INTERFACE ", ";
  63.     } else {
  64.         $firstTable = 0;
  65.     }
  66.     &debugOut("Found table:$1");
  67.     print "Reading table $1...\n\n";
  68.  
  69.     print MODEL &startModelObject();
  70.     print MODEL "name = \"$1\";";
  71.     print MODEL &returnModelIndent();
  72.     print MODEL "namespace = ";
  73.     print MODEL &startModelObject();
  74.     print MODEL "categories = (";
  75.     @categories = ();
  76.     $categoryIndex = 0;
  77.     %categoryIndices = ();
  78.     $firstCategory = 1;
  79.  
  80.     print INTERFACE &startInterfaceObject();
  81.     print INTERFACE "name = \"$1\";";
  82.     print INTERFACE &returnInterfaceIndent();
  83.     print INTERFACE "depictions = (";
  84.     @views = ();
  85.     $firstView = 1;
  86.  
  87.     push (@tableViewCount, 0);
  88.  
  89.     next;
  90.     };
  91.  
  92.     /^\s*Category\s*\"(.+)\"/ && !$inCategory && do {
  93.     $inCategory = 1;
  94.     &debugOut("Found Category: $1");
  95.     $categoryIndices{$1} = $categoryIndex;
  96.     $categoryIndex++;
  97.     $currentCategory = &startModelObject();
  98.     $currentCategory .= "name = \"$1\";";
  99.     $currentCategory .= &returnModelIndent();
  100.     $currentCategory .= "nodes = (";
  101.     $firstItem = 1;
  102.     $inGroup = 0;
  103.     next;
  104.     };
  105.  
  106.     /^\s*Group\s*\"(.+)\"/ && do {
  107.     $inGroup++;
  108.     $currentCategory .= ", " if !$firstItem;
  109.     &debugOut("Found Group: $1");
  110.     $currentCategory .= &startModelObject();
  111.     $currentCategory .= "name = \"$1\";";
  112.     $currentCategory .= &returnModelIndent();
  113.     $currentCategory .= "children = (";
  114.     $firstItem = 1;
  115.     next;
  116.     };
  117.  
  118.     /^\s*\"(.+)\"/ && $inCategory && do {
  119.     $currentCategory .= ", " if !$firstItem;
  120.     $firstItem = 0;
  121.     $currentCategory .= &startModelObject();
  122.     $currentCategory .= "name = \"$1\";";
  123.     $currentCategory .= &endModelObject();
  124.     next;
  125.     };
  126.  
  127.     /^\s*End/ && $inGroup && do {
  128.     &debugOut("End Group");
  129.     $currentCategory .= ");";
  130.     $currentCategory .= &endModelObject();
  131.     $inGroup--;
  132.     next;
  133.     };
  134.  
  135.     /^\t\tEnd/ && $inCategory && do {
  136.     &debugOut("End Category");
  137.     $currentCategory .= ");";
  138.     $currentCategory .= &endModelObject();
  139.     push(@categories, $currentCategory);
  140.     $inCategory = 0;
  141.     next;
  142.     };
  143.  
  144.     /^\s*View\s*\"(.+)\"/ && !$inView && do {
  145.     push (@cellFormats, "");
  146.     push (@cellFonts, "");
  147.     if($inNamespace){
  148.         &doCategories();
  149.         &fixCategoryIndices;
  150.         print MODEL ");";
  151.         $inNamespace = 0;
  152.         print MODEL &endModelObject();
  153.         print MODEL ";";
  154.     }
  155.     if($firstView) {
  156.         $inDepictions = 1;
  157.         $firstView = 0;
  158.     }
  159.     $inView = 1;
  160.     &debugOut("Found View: $1");
  161.     print "Reading view $1.\n\n";
  162.     $tableViewCount[$#tableViewCount] += 1;
  163.     $currentView = &startInterfaceObject;    # Start depictions element
  164.     $currentView .= "name = \"$1\";";
  165.     $currentView .= &returnInterfaceIndent;
  166.     $currentView .= "worksheetView = ";
  167.     $currentView .= &startInterfaceObject;    # Start worksheetView
  168.     next;
  169.     };
  170.  
  171.     /^\t\t\tRows/ && $inView && do {
  172.     $inRows = 1;
  173.     &debugOut("Found Rows");
  174.     next;
  175.     };
  176.  
  177.     /^\s*\".+\"/ && $inRows && do {
  178.     chop;
  179.     $_ = "\" $_ \"";
  180.     @rows = split (/\"\s+\"/);
  181.     shift @rows;
  182.     foreach $row (@rows) {
  183.         &debugOut("Found Row: $row") if (length($row) > 0);
  184.     }
  185.     $currentView .= "yCategories = (";
  186.     $currentView .= "$categoryIndices{$rows[0]}";
  187.     $currentView .= ", $categoryIndices{$rows[1]}" if (length ($rows[1]) > 0);
  188.     $currentView .= ", $categoryIndices{$rows[2]}" if (length ($rows[2]) > 0);
  189.     $currentView .= ", $categoryIndices{$rows[3]}" if (length ($rows[3]) > 0);
  190.     $currentView .= ");";
  191.     $currentView .= &returnInterfaceIndent;
  192.     next;
  193.     };
  194.  
  195.     /^\t\t\tEnd/ && $inRows && do {
  196.     $inRows = 0;
  197.     &debugOut("End Rows");
  198.     next;
  199.     };
  200.  
  201.     /^\t\t\tColumns/ && $inView && do {
  202.     $inColumns = 1;
  203.     &debugOut("Found Columns");
  204.     next;
  205.     };
  206.  
  207.     /^\s*\".+\"/ && $inColumns && do {
  208.     chop;
  209.     $_ = "\" $_ \"";
  210.     @columns = split (/\"\s+\"/);
  211.     shift @columns;
  212.     foreach $column (@columns) {
  213.         &debugOut("Found Column: $column") if (length($column) > 0);
  214.     }
  215.     $currentView .= "xCategories = (";
  216.     $currentView .= "$categoryIndices{$columns[0]}";
  217.     $currentView .= ", $categoryIndices{$columns[1]}" if (length ($columns[1]) > 0);
  218.     $currentView .= ", $categoryIndices{$columns[2]}" if (length ($columns[2]) > 0);
  219.     $currentView .= ", $categoryIndices{$columns[3]}" if (length ($columns[3]) > 0);
  220.     $currentView .= ");";
  221.     $currentView .= &returnInterfaceIndent;
  222.     next;
  223.     };
  224.  
  225.     /^\t\t\tEnd/ && $inColumns && do {
  226.     $inColumns = 0;
  227.     &debugOut("End Columns");
  228.     next;
  229.     };
  230.  
  231.     /^\t\t\tPerspective/ && $inView && do {
  232.     $inPerspective = 1;
  233.     &debugOut("Found Perspective");
  234.     next;
  235.     };
  236.  
  237.     /^\s*\".+\"/ && $inPerspective && do {
  238.     chop;
  239.     $_ = "\" $_ \"";
  240.     @perspective = split (/\"\s+\"/);
  241.     shift @perspective;
  242.     foreach $zcat (@perspective) {
  243.         &debugOut("Found Perpsective: $zcat") if (length($zcat) > 0);
  244.     }
  245.     $currentView .= "zCategories = (";
  246.     $currentView .= "$categoryIndices{$perspective[0]}";
  247.     $currentView .= ", $categoryIndices{$perspective[1]}" if (length ($perspective[1]) > 0);
  248.     $currentView .= ", $categoryIndices{$perspective[2]}" if (length ($perspective[2]) > 0);
  249.     $currentView .= ", $categoryIndices{$perspective[3]}" if (length ($perspective[3]) > 0);
  250.     $currentView .= ");";
  251.     next;
  252.     };
  253.  
  254.     /^\t\t\tEnd/ && $inPerspective && do {
  255.     $inPerspective = 0;
  256.     &debugOut("End Perspective");
  257.     next;
  258.     };
  259.  
  260.     /^\t\t\tFormats/ && $inView && do {
  261.     $inFormats = 1;
  262.     &debugOut("Found Formats");
  263.     $currentView .= &returnInterfaceIndent;
  264.  
  265.     # Set the default cell format to resemble Improv's
  266.     $currentView .= "defaultCellFormat={textFont={fontName=Helvetica;fontSize=12;};useStringDefault=NO;formatString=0;};";
  267.  
  268.     $currentView .= &endInterfaceObject();    # End worksheetView
  269.     $currentView .= ";";
  270.     next;
  271.     };
  272.  
  273.     /^\t\t\t\tDefault/ && $inFormats && do {
  274.     chop;
  275.     s/^\t*Default\s*//;
  276.     s/\s*$//;
  277.     $defaultCellFormat = $_;
  278.     next;
  279.     };
  280.  
  281.     /^\t\t\t\tData/ && $inFormats && do {
  282.     $inFormatsData = 1;
  283.     $formatsConcat = "";
  284.     &debugOut("Found Formats Data");
  285.     next;
  286.     };
  287.  
  288.     /^\t\t\t\tEnd/ && $inFormatsData && do {
  289.     $inFormatsData = 0;
  290.     &debugOut("End Formats Data");
  291.     foreach $format (&splitCommaList ($formatsConcat)) {
  292.         if (length($format) > 0) {
  293.         $cellFormats[$#cellFormats] .= $format . "\n";
  294.         } else {
  295.         $cellFormats[$#cellFormats] .= $defaultCellFormat . "\n";
  296.         }
  297.     }
  298.     local (@debugCellFormats) = split (/\n/, $cellFormats[$#cellFormats]);
  299.     &debugOut ("Number of formats minus 1: $#debugCellFormats");
  300.     next;
  301.     };
  302.  
  303.     /^\t\t\tEnd/ && $inFormats && do {
  304.     $inFormats = 0;
  305.     &debugOut("End Formats");
  306.     next;
  307.     };
  308.  
  309.     $inFormatsData && do {
  310.     chop;
  311.     $formatsConcat .= $_;
  312.     next;
  313.     };
  314.  
  315.     next if $inFormats;
  316.  
  317.     /^\t\t\tFonts/ && $inView && do {
  318.     &debugOut("Found Fonts");
  319.     $inFonts = 1;
  320.     next;
  321.     };
  322.  
  323.     /^\t\t\t\tDefault/ && $inFonts && do {
  324.     chop;
  325.     s/^\t*Default\s*//;
  326.     s/\s*$//;
  327.     $defaultCellFont = &convertFont($_);
  328.     next;
  329.     };
  330.  
  331.     /^\t\t\t\tData/ && $inFonts && do {
  332.     $fontsConcat = "";
  333.     $inFontsData = 1;
  334.     &debugOut("Found Fonts Data");
  335.     next;
  336.     };
  337.  
  338.     /^\t\t\t\tEnd/ && $inFontsData && do {
  339.     $inFontsData = 0;
  340.     &debugOut("End Fonts Data");
  341.     foreach $font (&splitCommaList ($fontsConcat)) {
  342.         if (length($font) > 0) {
  343.         $font = &convertFont($font);
  344.         $cellFonts[$#cellFonts] .= $font . "\n";
  345.         } else {
  346.         $cellFonts[$#cellFonts] .= $defaultCellFont . "\n";
  347.         }
  348.     }
  349.     local (@debugCellFonts) = split (/\n/, $cellFonts[$#cellFonts]);
  350.     &debugOut ("Number of fonts minus 1: $#debugCellFonts");
  351.     next;
  352.     };
  353.  
  354.     $inFontsData && do {
  355.     chop;
  356.     $fontsConcat .= $_;
  357.     next;
  358.     };
  359.  
  360.     /^\t\t\tEnd/ && $inFonts && do {
  361.     &debugOut("End Fonts");
  362.     $inFonts = 0;
  363.     @formats = split (/\n/, $cellFormats[$#cellFormats]);
  364.     @fonts = split (/\n/, $cellFonts[$#cellFormats]);
  365.     local ($i);
  366.     for ($i = $#formats - $#fonts; $i > 0; $i--) {
  367.         $cellFonts[$#cellFonts] .= $defaultCellFont . "\n";
  368.     }
  369.     next;
  370.     };
  371.  
  372.     next if $inFonts;
  373.  
  374.     /^\t\tEnd/ && $inView && do {
  375.     &debugOut("End View");
  376.     $currentView .= &endInterfaceObject();    # End depictions element
  377.     push(@views, $currentView);
  378.     $inView = 0;
  379.     next;
  380.     };
  381.  
  382.     next if $inView;
  383.  
  384.     /^\s*Data/ && !$inData && do { 
  385.     if($inDepictions){
  386.         &doViews();
  387.         $inDepictions = 0;
  388.         print INTERFACE ");";        # End of depictions list
  389.         print INTERFACE &endInterfaceObject;# End dataDepictions element
  390.     }
  391.     $inData = 1;
  392.     &debugOut("Found Data");
  393.     print "Reading data.\n\n";
  394.     print MODEL &returnModelIndent();
  395.     print MODEL "dataspace = (";
  396.     next;
  397.     };
  398.  
  399.     /^\t\tEnd$/ && $inData && do {
  400.     &debugOut("End Data");
  401.     $inData = 0;
  402.     print MODEL ");";
  403.     next;
  404.     };
  405.  
  406.     /^\t*(.*)$/ && $inData && do {
  407.     print MODEL $1;
  408.     };
  409.  
  410.     /^\tEnd/ && $inTable && do {
  411.     &debugOut("End Table");
  412.     $inTable = 0;
  413.     print MODEL &endModelObject();
  414.  
  415.     next;
  416.     };
  417.  
  418.     /\s*Formulas/ && !$inFormulas && do {
  419.     $inFormulas = 1;
  420.     &debugOut("Found Formulae");
  421.     print MODEL &returnModelIndent();
  422.     print MODEL "formulaspace = ";
  423.     print MODEL &startModelObject();
  424.     print MODEL "formulae = (";
  425.     $firstFormula = 1;
  426.     };
  427.  
  428.     /\t\t\t\"(.*)\"$/ && $inFormulas && do {
  429.     print MODEL ", " if !$firstFormula;
  430.     $firstFormula = 0;
  431.     print MODEL &startModelObject();
  432.     $filtered = &filterFunction($1);
  433.     print MODEL "formula = \"$filtered\";";
  434.     print MODEL &endModelObject();
  435.     };
  436.  
  437.     /\t\tEnd/ && $inFormulas && do {
  438.     &debugOut("End Formulae");
  439.     $inFormulas = 0;
  440.     print MODEL ");";
  441.     print MODEL &endModelObject();
  442.     print MODEL ";";
  443.     };
  444.  
  445.     /^End/ && do {
  446.     $inModel = 0;
  447.     print "Done.\n\n";
  448.     print MODEL ");\n";
  449.     print INTERFACE ");";
  450.     print INTERFACE &endInterfaceObject;    # End document
  451.     print INTERFACE ";\n";
  452.  
  453.     &doFormats;
  454.  
  455.     break;                    # Assume one model per imx file
  456.     };
  457. }
  458.  
  459. close(MODEL);
  460. close(INTERFACE);
  461. close(FORMAT);
  462.  
  463.  
  464. sub startModelObject {
  465.     local($retString) = "";
  466.  
  467.     $retString = "{";
  468.     $modelLevel++;
  469.     $retString .= &returnModelIndent;
  470.     return $retString;
  471. }
  472.  
  473. sub startInterfaceObject {
  474.     local($retString) = "";
  475.  
  476.     $retString = "{";
  477.     $interfaceLevel++;
  478.     $retString .= &returnInterfaceIndent;
  479.     return $retString;
  480. }
  481.  
  482. sub startFormatObject {
  483.     local($retString) = "";
  484.  
  485.     $retString = "{";
  486.     $formatLevel++;
  487.     $retString .= &returnFormatIndent;
  488.     return $retString;
  489. }
  490.  
  491. sub endModelObject {
  492.     local($retString);
  493.  
  494.     $modelLevel--;
  495.     $retString = &returnModelIndent;
  496.     $retString .= "}";
  497.     return $retString;
  498. }
  499.  
  500. sub endInterfaceObject {
  501.     local($retString);
  502.  
  503.     $interfaceLevel--;
  504.     $retString = &returnInterfaceIndent;
  505.     $retString .= "}";
  506.     return $retString;
  507. }
  508.  
  509. sub endFormatObject {
  510.     local($retString);
  511.  
  512.     $formatLevel--;
  513.     $retString = &returnFormatIndent;
  514.     $retString .= "}";
  515.     return $retString;
  516. }
  517.  
  518. sub returnModelIndent {
  519.     return &returnIndent($modelLevel);
  520. }
  521.  
  522. sub returnInterfaceIndent {
  523.     return &returnIndent($interfaceLevel);
  524. }
  525.  
  526. sub returnFormatIndent {
  527.     return &returnIndent($formatLevel);
  528. }
  529.  
  530. sub returnIndent {
  531.     local ($level) = @_;
  532.     local($retString);
  533.     local($ct) = $level;
  534.  
  535.     return if $level < 0;
  536.     $retString = "\n";
  537.     while($ct--){
  538.     $retString .= "    ";
  539.     }
  540.     return $retString;
  541. }
  542.  
  543. sub doCategories {
  544.     local($category);
  545.  
  546.     $category = pop(@categories);
  547.     print MODEL $category;
  548.     while($category = pop(@categories)){
  549.     print MODEL ", $category";
  550.     }
  551. }
  552.  
  553. sub fixCategoryIndices {
  554.     local (@keys) = keys %categoryIndices;
  555.     for $key (keys %categoryIndices) {
  556.     $categoryIndices{$key} = $#keys - $categoryIndices{$key};
  557.     }
  558. }
  559.  
  560.  
  561. sub doViews {
  562.     local($view);
  563.  
  564.     $view = pop(@views);
  565.     print INTERFACE $view;
  566.     while($view = pop(@views)){
  567.     print INTERFACE ", $view";
  568.     }
  569. }
  570.  
  571.  
  572. sub doFormats {
  573.     local ($firstTable);
  574.     print FORMAT "depictionFormats = (";
  575.  
  576.  
  577.     # Build cell formats hash table
  578.  
  579.     local ($i);
  580.     local (%formatIdTable);
  581.     local (@formats);
  582.     local (@fonts);
  583.     for ($i = 0; $i <= $#cellFormats; $i++) {
  584.  
  585.     @formats = split (/\n/, $cellFormats[$i]);
  586.     @fonts = split (/\n/, $cellFonts[$i]);
  587.  
  588.     while ($#formats >= 0) {
  589.         $string = pop(@formats) . "\n". pop(@fonts);
  590.         if (!$formatIdTable{$string}) {
  591.         local ($id);
  592.         local (@keys) = keys (%formatIdTable);
  593.         $id = $#keys + 2;
  594.         $formatIdTable{$string} = $id;
  595.         }
  596.     }
  597.     }
  598.  
  599.  
  600.  
  601.     # Build cell format lists hash table
  602.  
  603.     local (%formatListIdTable);
  604.     local (@formats);
  605.     local (@fonts);
  606.     $i = 0;
  607.  
  608.     # For each table...
  609.     for ($tableIndex = 0; $tableIndex <= $#tableViewCount; $tableIndex++) {
  610.     $viewCount = $tableViewCount[$tableIndex];
  611.  
  612.     print FORMAT &startFormatObject;
  613.     print FORMAT "cellFormats = (";
  614.  
  615.     local ($count);
  616.     local (@formatLists);
  617.  
  618.     # For each view in the table...
  619.     for ($count = 0; $count < $viewCount; $count++) {
  620.         @formats = split (/\n/, $cellFormats[$i]);
  621.         @fonts = split (/\n/, $cellFonts[$i]);
  622.  
  623.         # For each cell in the table...
  624.         while ($#formats >= 0) {
  625.         $formatLists[$#formats] .= pop(@formats)."\n".pop(@fonts)."\r";
  626.         }
  627.         $i++;
  628.     }
  629.  
  630.     while ($#formatLists >= 0) {
  631.         $formatList = shift(@formatLists);
  632.         if (!$formatListIdTable{$formatList}) {
  633.         local ($id);
  634.         local (@keys) = keys (%formatListIdTable);
  635.         $id = $#keys + 2;
  636.         $formatListIdTable{$formatList} = $id;
  637.         }
  638.         print FORMAT $formatListIdTable{$formatList};
  639.         print FORMAT ", " if $#formatLists >= 0;
  640.     }
  641.     print FORMAT ");";
  642.     #! itemFormats and categoryFormats here
  643.     print FORMAT &endFormatObject;
  644.     print FORMAT ", " if $tableIndex < $#tableViewCount;
  645.     }
  646.  
  647.     print FORMAT ");", &returnFormatIndent;
  648.  
  649.     local (@listKeys) = keys (%formatListIdTable);
  650.     local ($numberOfLists) = $#listKeys + 1;
  651.  
  652.     print FORMAT "cellFormatLists = (";
  653.  
  654.     for ($i = 0; $i <= $#listKeys; $i++) {
  655.     print FORMAT &startFormatObject;
  656.     print FORMAT "id = $formatListIdTable{$listKeys[$i]};";
  657.     print FORMAT &returnFormatIndent;
  658.     print FORMAT "formats = (";
  659.  
  660.     local (@splitList) = split (/\r/, $listKeys[$i]);
  661.     while ($#splitList >= 0) {
  662.         print FORMAT $formatIdTable{pop(@splitList)} + $numberOfLists;
  663.         print FORMAT ", " if $#splitList >= 0;
  664.     }
  665.     print FORMAT ");";
  666.     print FORMAT &endFormatObject;
  667.     print FORMAT ", " if $i < $#listKeys;
  668.     }
  669.     print FORMAT ");", &returnFormatIndent;
  670.  
  671.  
  672.     local (@formatKeys) = keys (%formatIdTable);
  673.  
  674.     print FORMAT "cellFormats = (";
  675.  
  676.     for ($i = 0; $i <= $#formatKeys; $i++) {
  677.     print FORMAT &startFormatObject;
  678.     print FORMAT "id = ", $formatIdTable{$formatKeys[$i]} + $numberOfLists;
  679.     print FORMAT ";", &returnFormatIndent;
  680.     local ($format, $font) = split (/\n/, $formatKeys[$i]);
  681.     if ($format ne "\"G\"") {
  682.         if ($format =~ /^"*DT/) {
  683.         print FORMAT "stringType = date;", &returnFormatIndent;
  684.         }
  685.         &debugOut ("Convert Improv format $format");
  686.         $format = &convertFormat ($format);
  687.         &debugOut ("to Quantrix format $format");
  688.         print FORMAT "useStringDefault = NO;", &returnFormatIndent;
  689.         print FORMAT "formatString = $format;", &returnFormatIndent;
  690.     }
  691.     print FORMAT "useFontDefault = NO;", &returnFormatIndent;
  692.     print FORMAT "textFont = {",$font,"};";
  693.     print FORMAT &endFormatObject;
  694.     print FORMAT ", " if $i < $#formatKeys;
  695.     }
  696.     print FORMAT ");", &returnFormatIndent;
  697. }
  698.  
  699.  
  700. sub convertFont {
  701.     local ($improvFont) = $_[0];
  702.     local ($fontName, $fontSize);
  703.  
  704.     $improvFont =~ s/^"(.*)"$/$1/;
  705.     $fontSize = $improvFont;
  706.     $fontSize =~ s/^[^0-9]*//;
  707.  
  708.     $_ = $improvFont;
  709.  
  710.   table: {
  711.       $fontName = "Courier-BoldOblique",    last table if /^CBO/;
  712.       $fontName = "Courier-Oblique",        last table if /^CO/;
  713.       $fontName = "Courier-Bold",        last table if /^CB/;
  714.       $fontName = "Courier",            last table if /^C/;
  715.       $fontName = "Helvetica-BoldOblique",    last table if /^HBO/;
  716.       $fontName = "Helvetica-Oblique",        last table if /^HO/;
  717.       $fontName = "Helvetica-Bold",        last table if /^HB/;
  718.       $fontName = "Helvetica",            last table if /^H/;
  719.       $fontName = "Ohlfs",            last table if /^O/;
  720.       $fontName = "Symbol",            last table if /^S/;
  721.       $fontName = "Times-BoldItalic",        last table if /^TBI/;
  722.       $fontName = "Times-Italic",        last table if /^TI/;
  723.       $fontName = "Times-Bold",            last table if /^TB/;
  724.       $fontName = "Times-Roman",        last table if /^TR/;
  725.       $fontName = "GothicBBBHelvetica-BoldOblique",    last table if /^GBBBHBO/;
  726.       $fontName = "GothicBBBHelvetica-Oblique",    last table if /^GBBBHO/;
  727.       $fontName = "GothicBBBHelvetica-Bold",    last table if /^GBBBHB/;
  728.       $fontName = "GothicBBBHelvetica",        last table if /^GBBBH/;
  729.       $fontName = "RyuuminTimes-BoldOblique",    last table if /^RTBO/;
  730.       $fontName = "RyuuminTimes-Bold",        last table if /^RTB/;
  731.       $fontName = "RyuuminTimes-LightOblique",    last table if /^RTLO/;
  732.       $fontName = "RyuuminTimes-Light",        last table if /^RTL/;
  733.       $fontName = "";
  734.   }
  735.  
  736.     if (length ($fontName) > 0) {
  737.     return "fontName = \"$fontName\"; fontSize = $fontSize;";
  738.     } else {
  739.     return $defaultCellFont;
  740.     }
  741. }
  742.  
  743. sub convertFormat {
  744.     local ($improvFormat) = $_[0];
  745.  
  746.     $improvFormat =~ s/^"(.*)"$/\1/;
  747.  
  748.     if ($improvFormat =~ /^DT/) {
  749.     $improvFormat =~ s/^DT//;
  750.     return &convertDateFormat ($improvFormat);
  751.  
  752.     } elsif ($improvFormat =~ /^N/) {
  753.     $improvFormat =~ s/^N//;
  754.     return &convertNumberFormat ($improvFormat);
  755.  
  756.     } elsif ($improvFormat =~ /^CN/) {
  757.     $improvFormat =~ s/^CN//;
  758.     return &convertCustomNumberFormat ($improvFormat);
  759.     }
  760. }
  761.  
  762.  
  763. sub convertDateFormat {
  764.     local ($improvFormat) = $_[0];
  765.     local ($newFormat);
  766.  
  767.     $newFormat = $improvFormat;
  768.     return '"'.$improvFormat.'"';
  769. }
  770.  
  771.  
  772. sub convertNumberFormat {
  773.     local ($improvFormat) = $_[0];
  774.     local ($newFormat);
  775.     local ($digits);
  776.     local ($i);
  777.  
  778.     $digits = $improvFormat;
  779.     $digits =~ s/^(\d*)\D.*/$1/;
  780.  
  781.     if ($digits > 0) {
  782.     $newFormat = "0.";
  783.     } else {
  784.     $newFormat = "9";
  785.     }
  786.     for ($i = 1; $i <= $digits; $i++) {
  787.     $newFormat .= "0";
  788.     }
  789.  
  790.     if ($improvFormat =~ /e/) {
  791.     $newFormat .= "E+00";
  792.     }
  793.  
  794.     if ($improvFormat =~ /\%/) {
  795.     $newFormat .= "%";
  796.     }
  797.  
  798.     if ($improvFormat =~ /,/) {
  799.     $newFormat = "," . $newFormat;
  800.     }
  801.  
  802.     if ($improvFormat =~ /\$/) {
  803.     $newFormat = "$" . $newFormat;
  804.     }
  805.  
  806.     if (!($improvFormat =~ /-/)) {
  807.     $newFormat = $newFormat . ";(" . $newFormat . ")";
  808.     }
  809.  
  810.     return '"'.$newFormat.'"';
  811. }
  812.  
  813.  
  814. sub convertCustomNumberFormat {
  815.     local ($improvFormat) = $_[0];
  816.     local ($newFormat);
  817.  
  818.     $newFormat = $improvFormat;
  819.     $newFormat =~ s/;N/;/g;
  820.  
  821.     return '"'.$newFormat.'"';
  822. }
  823.  
  824.  
  825. sub splitCommaList {
  826.     local ($input) = $_[0];
  827.     local (@elements);
  828.     local ($letter);
  829.     local ($string);
  830.     local ($inString) = 0;
  831.  
  832.     foreach $letter (split (/ */, $input)) {
  833.     if ($letter eq '"') {
  834.         $inString = !$inString;
  835.         $string .= $letter;
  836.  
  837.     } elsif ($inString) {
  838.         $string .= $letter;
  839.     }
  840.  
  841.     if (!$inString && ($letter eq ',')) {
  842.         push (@elements, $string);
  843.         $string = '';
  844.     }
  845.     }
  846.  
  847.     if ((length($string) > 0) || ($input =~ /, *$/)) {
  848.     push (@elements, $string);
  849.     }
  850.  
  851.     return @elements;
  852. }
  853.  
  854.  
  855. sub filterFunction {
  856.     local($string) = $_[0];
  857.     
  858.     $string =~ s/select([a-z]+)\(([^\)]*)\)/$1\(select\($2\)\)/iog;
  859.     $string =~ s/\@ +/@/g;
  860.  
  861.     return $string;
  862. }
  863.  
  864. sub debugOut {
  865.     print stderr @_, "\n" if $debug;
  866. }
  867.  
  868.