home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / OUT18.ZIP / OUTSECT.INC < prev    next >
Encoding:
Text File  |  1986-11-25  |  5.4 KB  |  193 lines

  1.  
  2.  
  3. (*
  4.  * outline - a simple "outline" oriented document generator
  5.  *
  6.  * outsect.inc - this module contains the procedures
  7.  *               for printing document sections in detail,
  8.  *               contents and outline formats.
  9.  *
  10.  * Author:  Samuel H. Smith, 11-Jan-86
  11.  *
  12.  *)
  13.  
  14.  
  15. function lines_in_section(var sec: section_ptr;
  16.                           indent:  integer;
  17.                           format:  print_formats): integer;
  18.                                        {determine the number of
  19.                                         lines needed to output
  20.                                         a section to the printer.
  21.                                         this is used to decide
  22.                                         when to generate a formfeed}
  23. var
  24.    i:       integer;
  25.    lines:   integer;
  26.    subcnt:  integer;
  27.    txtcnt:  integer;
  28.  
  29. begin
  30.  
  31.    with sec^ do
  32.    begin
  33.       subcnt := 0;
  34.       for i := 1 to max_subsects do    {count the defined subsections}
  35.          if subsect[i] <> nil then
  36.             if subsect[i]^.title <> '' then
  37.                subcnt := subcnt + 1;
  38.  
  39.       txtcnt := 0;
  40.       for i := 1 to max_text do        {count the lines with text}
  41.          if text^[i] <> '' then
  42.             txtcnt := txtcnt + 1;
  43.  
  44.       if format = detail_format then
  45.       begin
  46.          if (txtcnt > 0) or (subcnt > 0) then
  47.             lines := 3
  48.          else
  49.             lines := 2;
  50.  
  51.          print_text_lines(sec, nullfd, indent+indentation, format, lines);
  52.       end
  53.  
  54.       else
  55.          lines := 2;
  56.  
  57.  
  58.       for i := 1 to max_subsects do
  59.          if (lines < pagelen) and (subsect[i] <> nil) then
  60.             if subsect[i]^.title <> '' then
  61.                lines := lines + lines_in_section(subsect[i], indent+5, format);
  62.  
  63.    end;
  64.  
  65.    lines_in_section := lines;
  66. end;
  67.  
  68.  
  69.  
  70. procedure print_section(var sec: section_ptr;
  71.                         var fd:  textfile;
  72.                         indent:  integer;
  73.                         format:  print_formats;
  74.                         dewey:   anystring);   {write a section of the
  75.                                                 outline to an output file;
  76.                                                 recursively calls itself
  77.                                                 for subsections.  keeps
  78.                                                 track of formfeeds on
  79.                                                 printer output}
  80. var
  81.    i:       integer;
  82.    subcnt:  integer;
  83.    txtcnt:  integer;
  84.    len:     integer;
  85.  
  86. begin
  87.  
  88.    if keypressed then
  89.       exit;
  90.  
  91.    if section_numbering = false then
  92.       dewey := '';
  93.  
  94.    if format <> index_format then
  95.    begin
  96.       if break_into_pages and (prnline > minlines) then
  97.          if (prnline + lines_in_section(sec, indent, format)) > pagelen then
  98.          begin
  99.             write(fd, ^L);      {generate a formfeed if this section will
  100.                                  not fit completely on the current page}
  101.             prnline := 1;
  102.             pflush(fd);
  103.          end;
  104.  
  105.       check_page_header(fd,format,sec);
  106.  
  107.       writeln(fd);
  108.       prnline := prnline + 1;
  109.       pflush(fd);
  110.    end;
  111.  
  112.    with sec^ do
  113.    begin
  114.       subcnt := 0;
  115.       for i := 1 to max_subsects do    {count the defined subsections}
  116.          if subsect[i] <> nil then
  117.             if subsect[i]^.title <> '' then
  118.                subcnt := subcnt + 1;
  119.  
  120.       txtcnt := 0;
  121.       for i := 1 to max_text do        {count the lines with text}
  122.          if text^[i] <> '' then
  123.             txtcnt := txtcnt + 1;
  124.  
  125.       if format = detail_format then
  126.       begin
  127.          if (txtcnt > 0) or (subcnt > 0) then
  128.             write(fd, '':indent,
  129.                    start_underline,
  130.                    dewey,' ',title,
  131.                    stop_underline)        {output the title}
  132.          else
  133.             write(fd,'':indent,dewey,' ',title);
  134.  
  135.          if estimate <> 0 then
  136.             write(fd,'  (',estimate:0:1,')');
  137.          writeln(fd);
  138.  
  139.          pflush(fd);
  140.          onpage := page_number;
  141.          prnline := prnline + 1;
  142.  
  143.          print_text_lines(sec, fd, indent+indentation, format, prnline);
  144.       end
  145.       else
  146.  
  147.       if format = index_format then
  148.          index_text_lines(sec)
  149.  
  150.       else         {else not detail mode}
  151.  
  152.       begin
  153.          write(fd, '':indent, dewey,' ',title);      {output only the title
  154.                                                      if not in detail mode}
  155.          len := length(title)+indent;
  156.  
  157.          if estimate <> 0 then
  158.          begin
  159.             write(fd,'  (',estimate:4:1,')');
  160.             len := len + 8;
  161.          end;
  162.  
  163.          if (format = contents_format) and (onpage <> 0) then
  164.          begin
  165.             while len < (right_margin-4-length(dewey)) do
  166.             begin
  167.                if odd(len) then
  168.                   write(fd,' ')
  169.                else
  170.                   write(fd,'.');
  171.                len := len + 1;
  172.             end;
  173.             write(fd,onpage:3);
  174.          end;
  175.  
  176.          writeln(fd);
  177.          pflush(fd);
  178.          prnline := prnline + 1;
  179.       end;
  180.  
  181.  
  182.       for i := 1 to max_subsects do    {recursively output all subsections
  183.                                         with some extra indentation}
  184.          if subsect[i] <> nil then
  185.             if subsect[i]^.title <> '' then
  186.                print_section(subsect[i], fd,
  187.                              indent+indentation, format,
  188.                              dewey + itoa(i) + '.');
  189.  
  190.    end;
  191. end;
  192.  
  193.