home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DPSX / TOOL-PAS.ZIP / FPR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-11-03  |  8.2 KB  |  405 lines

  1.  
  2. (*
  3.  * fpr - print file with page formatting
  4.  *
  5.  * version 2
  6.  * shs 8/3/85
  7.  * removed blank pages, 24-jul-86 shs
  8.  * changed name, now uses getfiles.inc, 13-nov-86 shs
  9.  *
  10.  *)
  11.  
  12. {$r-,s-}
  13. {$m 20000,40000,40000}
  14.  
  15. uses dos, tools, bufio;
  16.  
  17. const
  18.    formfeed =     ^L;
  19.    return =       ^M;
  20.    linesperpage = 60;
  21.    titlelen =     65;
  22.  
  23. type
  24.    anystring =    string [128];
  25.    intext =       buffered_file;
  26.  
  27. var
  28.    pattern:       anystring;
  29.    defdir:        anystring;
  30.    rawtitle:      anystring;
  31.    outfile:       text;
  32.    outname:       anystring;
  33.    totpage:       integer;
  34.  
  35. (*
  36.  *
  37.  * return the string equivelant of an integer value
  38.  * with leading zeroes for a minimum width of 2
  39.  *
  40.  *)
  41.  
  42. function strval (int:           integer): anystring;
  43. var
  44.    tstr:          anystring;
  45.  
  46. begin
  47.    str(int, tstr);
  48.  
  49.    if length (tstr)= 1 then
  50.       strval := '0' + tstr
  51.    else
  52.       strval := tstr;
  53. end;
  54.  
  55.  
  56. (* *)
  57.  
  58. (*
  59.  *
  60.  * given a valid filename, returns modification date and time
  61.  *
  62.  *)
  63.  
  64. procedure filedate (filename:      anystring;
  65.                     var info:      anystring);
  66. const
  67.    month : array [1..12] of string[3]
  68.            = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
  69.               'Sep', 'Oct', 'Nov', 'Dec');
  70.  
  71. var
  72.    cf, b1, b2,
  73.    hr, mn,
  74.    m, d, y:       integer;
  75.    dta:           array [1..512] of byte;
  76.    sval:          string [2];
  77.    reg:           registers;
  78.  
  79. begin                       {set up disk transfer area}
  80.  
  81.    reg.ax := $1a00;
  82.    reg.ds := seg (dta [1]);
  83.    reg.dx := ofs (dta [1]);
  84.    msdos(reg);              {fill up dta}
  85.  
  86.    filename := filename + null;
  87.    reg.ax := $4e00;
  88.    reg.cx := 39;
  89.    reg.ds := seg (filename [1]);
  90.    reg.dx := ofs (filename [1]);
  91.    msdos(reg);
  92.    cf := reg.flags and 1;
  93.  
  94.    if cf = 1 then
  95.       info := '00-000-00 00:00'
  96.    else
  97.    begin
  98.       b1 := ord (dta [25]);
  99.       b2 := ord (dta [26]);
  100.       d := b1 and 31;
  101.       m :=(b1 shr 5)+ 8 *(b2 and 1);
  102.       y :=(b2 shr 1)+ 80;
  103.  
  104.       b1 := ord (dta [23]);
  105.       b2 := ord (dta [24]);
  106.       mn :=(b1 shr 5)+ 8 *(b2 and 7);
  107.       hr := b2 shr 3;
  108.       info := strval (d)+ '-' + month [m]+ '-' + strval (y)+ ' ' +
  109.               strval (hr)+ ':' + strval (mn);
  110.    end;
  111. end;
  112.  
  113.  
  114. (*
  115.  *
  116.  * converts ascii string to an integer value
  117.  *
  118.  *)
  119.  
  120. function atoi (asc:           anystring): integer;
  121. var
  122.    code:          integer;
  123.    value:         integer;
  124.  
  125. begin
  126.    val(asc, value, code);
  127.    atoi := value;
  128. end;
  129.  
  130.  
  131. (*
  132.  *
  133.  * centers a string around a given width
  134.  *
  135.  *)
  136.  
  137. procedure center (var str:       anystring;
  138.                   width:         integer);
  139. var
  140.    front:         integer;
  141.    back:          integer;
  142.  
  143. begin
  144.    
  145.    if length (str)> width then
  146.       str[0]:= chr (width);
  147.    
  148.    back := width - length (str);
  149.    front := back div 2;
  150.    back := back - front;
  151.  
  152.    while front > 0 do
  153.    begin
  154.       str := ' ' + str;
  155.       front := front - 1;
  156.    end;
  157.  
  158.    while back > 0 do
  159.    begin
  160.       str := str + ' ';
  161.       back := back - 1;
  162.    end;
  163. end;
  164.  
  165.  
  166. (*
  167.  *
  168.  * decode command line and get options and title
  169.  *
  170.  *)
  171.  
  172. procedure getoptions;
  173. var
  174.    param:         integer;
  175.  
  176. begin
  177.    rawtitle := '';
  178.    outname := 'prn';        {default output file name}
  179.    pattern := paramstr(1);  {file list pattern for input files}
  180.  
  181.    param := 2;
  182.  
  183.    while param <= paramcount do
  184.    begin                       {check for page number option}
  185.  
  186.       
  187.       if (paramstr (param)= '-O') or (paramstr (param)= '-o') then
  188.       begin                       {check for output file option}
  189.          
  190.          outname := paramstr (param + 1);
  191.          param := param + 1;
  192.       end
  193.       else                     {otherwise this is part of title}
  194.  
  195.          rawtitle := rawtitle + ' ' + paramstr (param);
  196.  
  197.       param := param + 1;
  198.    end;
  199. end;
  200.  
  201.  
  202. (*
  203.  *
  204.  * print a single file
  205.  * displays status on standard output while printing
  206.  *
  207.  *)
  208.  
  209.  
  210. procedure printfd (var infile:    intext;
  211.                    name:          anystring;
  212.                    date:          anystring);
  213. var
  214.    linecount:     integer;
  215.    linenum:       integer;
  216.    pageno:        integer;
  217.    line:          anystring;
  218.    title:         anystring;
  219.    i:             integer;
  220.    c:             char;
  221.  
  222. begin
  223.  
  224.    title := rawtitle;
  225.    center(title, titlelen - length (name) - length (date));
  226.    title := name + ' ' + title;
  227.  
  228.    if name <> '' then
  229.       name := name + ',  ';
  230.  
  231.    linenum := 0;
  232.    pageno := 0;
  233.    linecount := 0;
  234.  
  235.    while not berr do
  236.    begin
  237.  
  238.       if linenum = 0 then
  239.       begin
  240.          write(#13,name,linecount,' lines,  ',pageno,' pages');
  241.          pageno := pageno + 1;
  242.          flush(outfile);
  243.          write(outfile, title, ' ', date, ' Page ', pageno);
  244.  
  245.          if totpage >= 0 then
  246.          begin
  247.             totpage := totpage + 1;
  248.             write(outfile,' [',totpage,']');
  249.          end;
  250.          writeln(outfile);
  251.          writeln(outfile);
  252.          linenum := 2;
  253.       end;
  254.  
  255.       line := '';
  256.       bread(infile,c);
  257.       while (c <> #10) and (not berr) do
  258.       begin
  259.            if c <> #13 then
  260.               line := line + c;
  261.            bread(infile,c);
  262.       end;
  263.  
  264.       {readln(infile, line);}
  265.       writeln(outfile, line);
  266.       linenum := linenum + 1;
  267.       linecount := linecount + 1;
  268.  
  269.       for i := 1 to length(line) do
  270.          if line [i] = formfeed then
  271.             linenum := 0;
  272.             
  273.       if linenum >= linesperpage then
  274.       begin
  275.          writeln(outfile, formfeed);
  276.          linenum := 0;
  277.       end;
  278.  
  279.    end;
  280.  
  281.    if linenum > 0 then      {final formfeed}
  282.       writeln(outfile, formfeed);
  283.  
  284.    flush(outfile);
  285.    writeln(#13,name, linecount, ' lines,  ', pageno, ' pages');
  286. end;
  287.  
  288.  
  289. procedure printfile (name:          anystring);
  290. var
  291.    infile:        intext;
  292.    date:          anystring;
  293.  
  294. begin
  295. {
  296.    if name = '-F' then
  297.    begin
  298.       printfd(input,'','');
  299.       exit;
  300.    end;
  301. }
  302.  
  303.    bopen(infile, name,10000,1);
  304.    if berr then
  305.    begin
  306.       writeln('???? CANT RESET FILE: ',name);
  307.       halt;
  308.    end;
  309.  
  310.    filedate(name, date);
  311.    printfd(infile,name,date);
  312.    bclose(infile);
  313. end;
  314.  
  315.  
  316. (*
  317.  *
  318.  * if there are many files to print, outputs a banner page that
  319.  * summarizes the file names and modification dates
  320.  *
  321.  *)
  322.  
  323. procedure printfilelist;
  324. var
  325.    date:          anystring;
  326.    title:         anystring;
  327.    i:             integer;
  328.  
  329. begin
  330.  
  331.    if filecount > 2 then
  332.    begin
  333.       totpage := 0;
  334.  
  335.       writeln(outfile);
  336.       title := rawtitle;
  337.       center(title, titlelen);
  338.       writeln(outfile, title);
  339.  
  340.       writeln(outfile);
  341.       writeln(outfile);
  342.       writeln(outfile, ' ' : 10, '  Last Update         Path Name');
  343.       writeln(outfile, ' ' : 10, '===============    ===============');
  344.       writeln(outfile);
  345.  
  346.       for i := 1 to filecount do
  347.       begin
  348.          filedate(filetable [i]^, date);
  349.          writeln(outfile, ' ' : 10, date, '    ', filetable [i]^);
  350.  
  351.          if filecount < 20 then
  352.             writeln(outfile);
  353.       end;
  354.  
  355.       writeln(outfile, formfeed);
  356.    end
  357.    else
  358.       totpage := -1;
  359.  
  360. end;
  361.  
  362.  
  363. (*
  364.  *
  365.  * main program
  366.  *
  367.  *)
  368.  
  369. var
  370.    i: integer;
  371.  
  372. begin                       {main}
  373.  
  374.    if paramcount = 0 then
  375.    begin
  376.       writeln('usage:    fpr FILENAME-LIST [OPTIONS] [TITLE]');
  377.       writeln('options:  -o FILENAME  to specify alternate output');
  378.       writeln('          -f           to act as a filter on standard input');
  379.       writeln;
  380.       writeln('example:  fpr file.doc,*.pas,*.bat  System Source Files');
  381.       writeln('          fpr *.pas,*.inc -o files.prn');
  382.       writeln('          loc *.PAS proc | fpr -f');
  383.       halt;
  384.    end;
  385.  
  386.    getoptions;              {decode options and title from command line}
  387.  
  388.    getfiles(pattern, filetable, filecount);
  389.                             {get full list of files}
  390.  
  391.    assign(outfile, outname);
  392.    rewrite(outfile);        {setup output file}
  393.  
  394.    printfilelist;           {print a summary of files printed}
  395.  
  396.    for i := 1 to filecount do  {print each file}
  397.       printfile(filetable [i]^);
  398.  
  399.    flush(outfile);
  400.    close(outfile);          {finish output file}
  401.  
  402.    halt(0);                 {return to dos}
  403. end.
  404.  
  405.