home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / OUT18.ZIP / OUTTREE.INC < prev   
Encoding:
Text File  |  1986-04-07  |  4.3 KB  |  155 lines

  1.  
  2. (*
  3.  * outline - a simple "outline" oriented document generator
  4.  *
  5.  * outtree.inc -  this module contains all of the procedures
  6.  *                for generating and formatting "trees".
  7.  *
  8.  * Author:  Samuel H. Smith, 11-Jan-86
  9.  *
  10.  *)
  11.  
  12. type
  13.    long_string = string[255];       {maximum length of an output line}
  14.  
  15. type
  16.    connector_codes =
  17.      (horizontal, tee, top, cross, middle, bottom, vertical, spaces, empty);
  18.  
  19. const
  20.    connector_strings: array [connector_codes] of string[3] =
  21.      ('───', '─┬─', ' ┌─', '─┼─', ' ├─', ' └─', ' │ ', '   ', '');
  22.  
  23.  
  24.  
  25.  
  26. function blanks (len: integer): long_string;
  27. var
  28.    str: long_string;
  29.  
  30. begin
  31.    str := '';
  32.  
  33.    while length (str) < len do
  34.       str := str + ' ';
  35.  
  36.    blanks := str;
  37. end;
  38.  
  39.  
  40.  
  41. function connector (code: connector_codes): long_string;
  42. begin
  43.    connector := connector_strings [code];
  44. end;
  45.  
  46.  
  47.  
  48. function subsec_count(sec: section_ptr): integer;
  49. var
  50.    i,j:  integer;
  51.    n:    integer;
  52.    t:    section_ptr;
  53.  
  54. begin
  55.    n := 0;
  56.  
  57.    with sec^ do
  58.       for i := 1 to max_subsects do
  59.       begin
  60.          if subsect[i] = nil then
  61.             for j := i to max_subsects-1 do
  62.                subsect[j] := subsect[j+1]
  63.          else
  64.  
  65.          if subsect[i]^.title = '' then
  66.             for j := i to max_subsects-1 do
  67.                subsect[j] := subsect[j+1];
  68.  
  69.          if subsect[i] <> nil then
  70.             if subsect[i]^.title <> '' then
  71.                n := n + 1;
  72.       end;
  73.  
  74.    subsec_count := n;
  75. end;
  76.  
  77.  
  78.  
  79. procedure print_section_tree
  80.                    (var fd:     textfile;          {output file}
  81.                     sec:        section_ptr;       {sec to output}
  82.                     beforetab:  long_string;       {tabs if before header}
  83.                     titletab:   long_string;       {tabs for header}
  84.                     aftertab:   long_string;       {tabs if after header}
  85.                     before:     connector_codes;   {next tab before header}
  86.                     header:     connector_codes;   {next tab for header}
  87.                     after:      connector_codes);  {next tab after header}
  88.  
  89. var
  90.    i:             integer;
  91.    titlesub:      integer;
  92.    count:         integer;
  93.  
  94. begin
  95.    if keypressed then
  96.       exit;
  97.  
  98.    with sec^ do
  99.    begin
  100.       beforetab := beforetab + connector (before) + blanks (length (title));
  101.       titletab  := titletab  + connector (header ) + title;
  102.       aftertab  := aftertab  + connector (after ) + blanks (length (title));
  103.  
  104.       count := subsec_count(sec);
  105.  
  106.       case count of
  107.          0:     {terminal sec with header only}
  108.             writeln (fd, titletab);
  109.  
  110.          1:     {sec with 1 subnode}
  111.             print_section_tree (fd, subsect[1], beforetab, titletab, aftertab,
  112.                                     spaces, horizontal, spaces);
  113.  
  114.          2:     {sec with 2 subnodes}
  115.             begin
  116.                print_section_tree (fd, subsect[1], beforetab, titletab, aftertab,
  117.                                        spaces, tee, vertical);
  118.  
  119.                print_section_tree (fd, subsect[2], aftertab, aftertab, aftertab,
  120.                                        vertical, bottom, spaces);
  121.             end;
  122.  
  123.          else   {sec with n subnodes}
  124.             begin
  125.                titlesub := (count+1) div 2;
  126.  
  127.                writeln (fd, beforetab);    {blank line before
  128.                                             new large section}
  129.  
  130.                print_section_tree (fd, subsect[1], beforetab, beforetab, beforetab,
  131.                                        spaces, top, vertical);
  132.  
  133.                for i := 2 to titlesub-1 do
  134.                   print_section_tree (fd, subsect[i], beforetab, beforetab, beforetab,
  135.                                           vertical, middle, vertical);
  136.  
  137.                print_section_tree (fd, subsect[titlesub], beforetab, titletab, aftertab,
  138.                                               vertical, cross, vertical);
  139.  
  140.                for i := titlesub+1 to count-1 do
  141.                   print_section_tree (fd, subsect[i], aftertab, aftertab, aftertab,
  142.                                           vertical, middle, vertical);
  143.  
  144.                print_section_tree (fd, subsect[count], aftertab, aftertab, aftertab,
  145.                                            vertical, bottom, spaces);
  146.             end;
  147.  
  148.        end;
  149.  
  150.    end;
  151.  
  152. end;
  153.  
  154.  
  155.