home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / DIRCNT16.ZIP / DIRSUM.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  4KB  |  208 lines

  1.  
  2. (*
  3.  * dirsum - read multiple outputs of DIRCOUNT and produce a summary report
  4.  *
  5.  *)
  6.  
  7. (* --------------------------------------------------------- *)
  8. function remove_commas(s: string): string;
  9. var
  10.    i: integer;
  11.    t: string;
  12. begin
  13.    t := '';
  14.    for i := 1 to length(s) do
  15.       case s[i] of
  16.          '0'..'9':
  17.             t := t + s[i];
  18.       end;
  19.    remove_commas := t;
  20. end;
  21.  
  22.  
  23. (* --------------------------------------------------------- *)
  24. function atoi(s: string): longint;
  25. var
  26.    i: integer;
  27.    l: longint;
  28. begin
  29.    s := remove_commas(s);
  30.    val(s,l,i);
  31.    atoi := l;
  32. end;
  33.  
  34.  
  35. (* --------------------------------------------------------- *)
  36. function insert_commas(s: string): string;
  37. var
  38.    i: integer;
  39. begin
  40.    i := length(s);
  41.    while i > 3 do
  42.    begin
  43.       dec(i,3);
  44.       insert(',',s,i+1);
  45.    end;
  46.  
  47.    insert_commas := s;
  48. end;
  49.  
  50.  
  51. (* --------------------------------------------------------- *)
  52. function itoa (n: longint): string;
  53. var
  54.    tstr:          string;
  55.  
  56. begin
  57.    str(n, tstr);
  58.    itoa := insert_commas(tstr);
  59. end;
  60.  
  61.  
  62. (* --------------------------------------------------------- *)
  63. function itoan(n: longint; width: integer): string;
  64. var
  65.    s: string;
  66. begin
  67.    s := itoa(n);
  68.    while length(s) < width do
  69.       s := ' ' + s;
  70.    itoan := s;
  71. end;
  72.  
  73.  
  74. (* --------------------------------------------------------- *)
  75. function ljust(s: string; width: integer): string;
  76. begin
  77.    s := copy(s,1,width);
  78.    while length(s) < width do
  79.       s := s + ' ';
  80.    ljust := s;
  81. end;
  82.  
  83.  
  84. (* --------------------------------------------------------- *)
  85. function center(s: string; width: integer): string;
  86. var
  87.    i: integer;
  88. begin
  89.    s := copy(s,1,width);
  90.    i := (width - length(s)) div 2;
  91.    while i > 0 do
  92.    begin
  93.       s := ' ' + s;
  94.       dec(i);
  95.    end;
  96.    center := s;
  97. end;
  98.  
  99.  
  100. (* --------------------------------------------------------- *)
  101. function cjust(s: string; width: integer): string;
  102. var
  103.    i: integer;
  104. begin
  105.    s := copy(s,1,width);
  106.    i := (width - length(s)) div 2;
  107.    while i > 0 do
  108.    begin
  109.       s := ' ' + s;
  110.       dec(i);
  111.    end;
  112.    while length(s) < width do
  113.       s := s + ' ';
  114.    cjust := s;
  115. end;
  116.  
  117.  
  118. var
  119.    boardname:  string;
  120.    confname:   string;
  121.    line:       string;
  122.    tconfs:     integer;
  123.    areas:      longint;
  124.    tareas:     longint;
  125.    files:      longint;
  126.    tfiles:     longint;
  127.    sizes:      longint;
  128.    tsizes:     longint;
  129.    fd:         text;
  130.    i,j,k:      integer;
  131.    temp:       longint;
  132.  
  133. begin
  134.    if paramcount < 1 then
  135.    begin
  136.       writeln('usage: DIRSUM file1 file2 ... >outfile');
  137.       writeln('summarizes report files generated by DIRCOUNT');
  138.       halt;
  139.    end;
  140.  
  141.    tconfs := 0;
  142.    tareas := 0;
  143.    tfiles := 0;
  144.    tsizes := 0;
  145.  
  146.    for i := 1 to paramcount do
  147.    begin
  148.       assign(fd,paramstr(i));
  149.       reset(fd);
  150.  
  151.       readln(fd);
  152.       readln(fd,boardname);
  153.  
  154.       readln(fd,confname);
  155.       while copy(confname,1,1) = ' ' do
  156.          delete(confname,1,1);
  157.       if confname[1] = '[' then
  158.       begin
  159.          delete(confname,1,1);
  160.          dec(confname[0]);
  161.       end;
  162.       while length(confname) < 40 do
  163.          confname := confname + ' ';
  164.  
  165.       inc(tconfs);
  166.       readln(fd);
  167.       readln(fd);
  168.       readln(fd);
  169.       areas := -2;
  170.  
  171.       repeat
  172.          readln(fd,line);
  173.          inc(areas);
  174.       until eof(fd) or (pos(' Overall Totals ',line) > 0);
  175.       close(fd);
  176.  
  177.       tareas := tareas + areas;
  178.  
  179.       files := atoi(copy(line,50,7));
  180.       tfiles := tfiles + files;
  181.  
  182.       sizes := atoi(copy(line,60,14));
  183.       tsizes := tsizes + sizes;
  184.  
  185.       if tconfs = 1 then
  186.       begin
  187.          writeln;
  188.          writeln(boardname);
  189.          writeln(center('Overall Summary of Available Files',79));
  190.          writeln;
  191.          writeln('                Conference                  Areas     Files      File Sizes  ');
  192.          writeln('  --------------------------------------   -------  --------  ----------------');
  193.       end;
  194.  
  195.       writeln('  ',confname,
  196.                itoan(areas,7),
  197.                itoan(files,10),
  198.                itoan(sizes,18));
  199.    end;
  200.  
  201.    writeln('                                           -------  --------  ----------------');
  202.    writeln('                          Overall Totals  ',
  203.             itoan(tareas,7),
  204.             itoan(tfiles,10),
  205.             itoan(tsizes,18));
  206. end.
  207.  
  208.