home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / OUT18.ZIP / OUTPRINT.INC < prev    next >
Encoding:
Text File  |  1986-10-03  |  5.3 KB  |  236 lines

  1.  
  2.  
  3. (*
  4.  * outline - a simple "outline" oriented document generator
  5.  *
  6.  * outprint.inc - this module contains the procedures
  7.  *                for the printing user interface.
  8.  *
  9.  * Author:  Samuel H. Smith, 11-Jan-86
  10.  *
  11.  *)
  12.  
  13.  
  14.  
  15. function select_print_format: print_formats;
  16.                               {select the format for the printout
  17.                                and return it as a format code}
  18. var
  19.    format: char;
  20.  
  21. begin
  22.    clrscr;  normvideo;
  23.    displn(version);
  24.    writeln;
  25.    writeln;
  26.    writeln;
  27.    writeln; lowvideo;
  28.    displn('            Key                 Action');
  29.    displn('           ═════    ═════════════════════════════');
  30.    writeln;
  31.    displn('             F1     Print full details of the document');
  32.    writeln;
  33.    displn('             F2     Print an outline of the document');
  34.    writeln;
  35.    displn('             F3     Print a table of contents for the document');
  36.    writeln;
  37.    displn('             F4     Print a section tree for the document');
  38.    writeln;
  39.    displn('             F5     Print a keyword index for the document');
  40.    writeln;
  41.    displn('             ESC    Cancel printout');
  42.    writeln;
  43.  
  44.    gotoxy(74,25);
  45.    write(maxavail shr 6,'k');
  46.  
  47.    normvideo;
  48.    gotoxy(1,24);
  49.    write  ('        Select print format: ');
  50.  
  51.    repeat
  52.       format := getkey;
  53.       if not (format in [F1..F5,ESC]) then
  54.          write(^G);
  55.    until format in [F1..F5,ESC];
  56.  
  57.    case format of
  58.       F1:   select_print_format := detail_format;
  59.       F2:   select_print_format := outline_format;
  60.       F3:   select_print_format := contents_format;
  61.       F4:   select_print_format := tree_format;
  62.       F5:   select_print_format := index_format;
  63.       ESC:  select_print_format := no_format;
  64.    end;
  65.  
  66. end;
  67.  
  68.  
  69.  
  70. function select_print_file: char;      {select the print output file name;
  71.                                         and leave it in prnfile.   returns
  72.                                         status character: abort print if ESC,
  73.                                         otherwise ok to print}
  74. var
  75.    fd:      textfile;
  76.    key:     char;
  77.    prompt:  linestring;
  78.  
  79. begin
  80.    normvideo;
  81.    gotoxy(1,24);
  82.    write  ('     Output to Printer, Console or File (P/C/F): ');
  83.  
  84.    repeat
  85.       key := upcase(getkey);
  86.       if not (key in ['C','F','P',ESC]) then
  87.          write(^G);
  88.    until key in ['C','F','P',ESC];
  89.  
  90.    select_print_file := key;
  91.  
  92.    case key of
  93.       'P':   begin
  94.                 prnfile := 'PRN';
  95.                 exit;
  96.              end;
  97.  
  98.       'C':   begin
  99.                 prnfile := 'CON';
  100.                 exit;
  101.              end;
  102.    end;
  103.  
  104.  
  105.    prnfile := '';
  106.    prompt := 'Print document '+docfile+' to a file or device';
  107.    select_file('*.PRN,*.SUM,*.INX', prompt, prnfile, key);
  108.  
  109.    if (key <> NEWLINE) or (prnfile = '') then
  110.    begin
  111.       select_print_file := ESC;
  112.       exit;
  113.    end;
  114.  
  115.    if pos('.', prnfile) = 0 then
  116.       prnfile := prnfile + '.PRN';
  117.  
  118.    if file_exists(prnfile) then
  119.    begin
  120.       writeln;
  121.       writeln('WARNING:  The file ', prnfile, ' already exists!  ');
  122.       disp('Overwrite it? (Y/N) ');
  123.  
  124.       if upcase(getkey) <> 'Y' then
  125.       begin
  126.          select_print_file := ESC;
  127.          exit;
  128.       end;
  129.  
  130.       writeln('Yes');
  131.    end;
  132.  
  133.    select_print_file := 'Y';
  134. end;
  135.  
  136.  
  137.  
  138. procedure print_document(var sec:   section_ptr;
  139.                          firstpage: integer;
  140.                          dewey:     anystring); {user interface to output
  141.                                                  a section report
  142.                                                  to a file or printer}
  143. var
  144.    fd:      textfile;
  145.    prompt:  linestring;
  146.    key:     char;
  147.    format:  print_formats;
  148.  
  149. begin
  150.  
  151.    format := select_print_format;
  152.    if format = no_format then
  153.       exit;
  154.  
  155.    if select_print_file = ESC then
  156.       exit;
  157.  
  158.    clrscr;  normvideo;
  159.    displn(version);
  160.    writeln;
  161.    writeln;
  162.    writeln;
  163.    writeln;
  164.    writeln; lowvideo;
  165.    displn('               Printing '+docfile+' to '+prnfile+' ...');
  166.    writeln;
  167.    writeln;
  168.    writeln; normvideo;
  169.    displn('               Press any key to abort printing.');
  170.    writeln;
  171.    writeln;
  172.    writeln;
  173.    writeln;
  174.    writeln;
  175.    writeln;
  176.    writeln; lowvideo;
  177.  
  178.    assign(fd, prnfile);
  179.    rewrite(fd);
  180.  
  181.    page_number := firstpage-1;
  182.    prnline := 1;
  183.    lineout := '';
  184.    word_count := 0;
  185.  
  186.    case format of
  187.       detail_format,
  188.       outline_format,
  189.       contents_format:
  190.          print_section (sec, fd, 1, format, dewey);
  191.  
  192.       index_format:
  193.          begin
  194.             disp('Building index.');
  195.             init_index;
  196.             print_section (sec, fd, 1, format, dewey);
  197.  
  198.             writeln;
  199.             displn('Printing index...');
  200.             output_index (fd);
  201.             flush(fd);
  202.  
  203.             writeln;
  204.             displn('Release index memory...');
  205.             dispose_index;
  206.             writeln;
  207.          end;
  208.  
  209.       tree_format:
  210.          print_section_tree (fd, sec, '', '', '', empty, empty, empty);
  211.    end;
  212.  
  213.    write(fd, ^L);
  214.    close(fd);
  215.    writeln;
  216.  
  217.    if keypressed then
  218.    begin
  219.       if getkey = '?' then ;
  220.       writeln('*** Print Aborted **');
  221.    end;
  222.  
  223.    if prnfile = 'CON' then
  224.    begin
  225.       disp('Press ENTER to continue: ');
  226.  
  227.       repeat
  228.       until getkey = NEWLINE;
  229.    end;
  230.  
  231.  
  232.    clrscr;
  233. end;
  234.  
  235.  
  236.