home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / foss10.zip / DEVELOP / UTILCOLL / TOPTEN.PAS < prev    next >
Pascal/Delphi Source File  |  1995-10-25  |  14KB  |  421 lines

  1. program TopTen;
  2. uses
  3.   TParam,
  4.   TFileIO,
  5.   TOSInt,
  6.   ApiInt,
  7.   Bits,
  8.   Types;
  9.  
  10. label
  11.   NextTopUser,
  12.   NextDown,
  13.   NextUp,
  14.   NextFDown,
  15.   NextFUp;
  16.  
  17. type
  18.   PTopTenBull      = ^TTopTenBull;
  19.   TTopTenBull      = object
  20.     Language       : Char;
  21.     SkipFile       : string;
  22.     AreaCode       : string;
  23.     BullPath       : string;
  24.  
  25.     constructor Init;
  26.     destructor Done;
  27.  
  28.     procedure ReadParams;
  29.     procedure CreateBull;
  30.   end;
  31.  
  32. var
  33.   TopTenBull       : PTopTenBull;
  34.  
  35. constructor TTopTenBull.Init;
  36. begin
  37.   dllInit( '', 0 );
  38. end; { contructor Init }
  39.  
  40. destructor TTopTenBull.Done;
  41. begin
  42. end; { destructor Done }
  43.  
  44. procedure TTopTenBull.ReadParams;
  45. begin
  46.   if Par^.SwAct['L'] then
  47.     case UpCh( Par^.SwStr['L', 1] ) of
  48.       'A': Language := 'A';
  49.       'E': Language := 'E';
  50.       'N': Language := 'N';
  51.     else
  52.       Language := 'A';
  53.     end
  54.   else Language := 'A';
  55.  
  56.   SkipFile := '';
  57.   if Par^.SwAct['S'] then
  58.     if FileExist( Par^.SwStr['S'] ) then
  59.       SkipFile := Par^.SwStr['S'];
  60.  
  61.   if Par^.SwAct['A'] then AreaCode := Par^.SwStr['A']
  62.   else AreaCode := 'MAIN';
  63.  
  64.   BullPath := Par^.Str[1];
  65. end; { procedure ReadParams }
  66.  
  67. procedure TTopTenBull.CreateBull;
  68. type
  69.   PTopTenData      = ^TTopTenData;
  70.   TTopTenData      = record
  71.     TotalTime,
  72.     TotalOn,
  73.     TotalDown,
  74.     TotalUp,
  75.     TotalFiles     : LongInt;
  76.     TotalMDown,
  77.     TotalMUp,
  78.     TotalMB        : Real;
  79.  
  80.     TopUserTime,
  81.     TopUserCnt,
  82.     Down,
  83.     Up             : array[1..10] of LocUsers;
  84.  
  85.     FDown,
  86.     FUp            : array[1..10] of TFileRec;
  87.   end;
  88.  
  89. const
  90.   TopLine          = '┌────────────────────────────────────┐  ┌────────────────────────────────────┐';
  91.   BottomLine       = '└────────────────────────────────────┘  └────────────────────────────────────┘'#13#10 +
  92.                      '                                                                              '#13#10'%!m%';
  93.  
  94. var
  95.   T10               : PTopTenData;
  96.   User              : LocUsers;
  97.   FPos              : LongInt;
  98.   L1, L2            : LongInt;
  99.   Area              : Area_Config_Record;
  100.   Dir               : TFileRec;
  101.   OutE,
  102.   OutN              : TFile;
  103.   Year              : Word;
  104.   Month, Day        : Byte;
  105.   TmpStr            : string;
  106.   TmpTime           : LongInt;
  107.  
  108. {}function  SkipUser( Name : string ) : Boolean;
  109.   var
  110.     SkFile         : TFile;
  111.     NameMask       : string;
  112.  
  113.   begin
  114.     if not ( Length( SkipFile ) = 0 ) then
  115.       with SkFile do
  116.       begin
  117.         Assign( SkipFile,
  118.                 fmReadOnly or fmDenyWrite,
  119.                 1,
  120.                 faNormalAccess,
  121.                 ftMaxTimeout );
  122.         Reset;
  123.  
  124.         while not Eof do
  125.         begin
  126.           ReadTextln( NameMask );
  127.           if LookInIf( Name, NameMask ) then
  128.           begin
  129.             Close;
  130.             SkipUser := TRUE;
  131.             exit;
  132.           end;
  133.         end;
  134.  
  135.         Close;
  136.       end;
  137.  
  138.     SkipUser := FALSE;
  139. {}end;
  140.  
  141. {}procedure PrintOut           ( Lang : Char; Txt : String );
  142.   begin
  143.     if ( Lang in ['A', 'E'] ) then OutE.WriteTextln( Txt );
  144.     if ( Lang in ['A', 'N'] ) then OutN.WriteTextln( Txt );
  145. {}end; { Procedure PrintOut }
  146.  
  147. begin
  148.   New( T10 );
  149.   FillChar( T10^, SizeOf( T10^ ), 0 );
  150.  
  151.   Write( '  - Scanning user: ' );
  152.   FPos := 0;
  153.   while fioReadLocalUsr( User, FPos ) do
  154.   begin
  155.     OS^.Sleep( 2 );
  156.     Inc( FPos );
  157.     if ( Killed in User.Flags ) then Continue;
  158.  
  159.     Write( Fill( User.UserName, High( User.UserName ), ' ' ) +
  160.            Fill( '', High( User.UserName ), #8 ));
  161.  
  162.     with T10^ do
  163.     begin
  164.       Inc( TotalTime, User.TimeTotal );
  165.       Inc( TotalOn, User.TimesOn );
  166.       Inc( TotalDown, User.Downloads );
  167.       TotalMDown := TotalMDown + User.DownloadKB / 1024;
  168.       Inc( TotalUp, User.Uploads );
  169.       TotalMUp := TotalMUp + User.UploadKB / 1024;
  170.  
  171.       if not SkipUser( User.UserName ) then
  172.       begin
  173.         for L1 := 1 to 10 do
  174.           if ( TopUserTime[L1].TimeTotal < User.TimeTotal ) then
  175.           begin
  176.             for L2 := 9 downto L1 do
  177.               TopUserTime[L2 + 1] := TopUserTime[L2];
  178.             TopUserTime[L1] := User;
  179.             Break;
  180.           end;
  181.  
  182.         for L1 := 1 to 10 do
  183.           if ( TopUserCnt[L1].TimesOn < User.TimesOn ) then
  184.           begin
  185.             for L2 := 9 downto L1 do
  186.               TopUserCnt[L2 + 1] := TopUserCnt[L2];
  187.             TopUserCnt[L1] := User;
  188.             Break;
  189.           end;
  190.  
  191.         for L1 := 1 to 10 do
  192.           if ( Down[L1].Downloads < User.Downloads ) then
  193.           begin
  194.             for L2 := 9 downto L1 do
  195.               Down[L2 + 1] := Down[L2];
  196.             Down[L1] := User;
  197.             Break;
  198.           end;
  199.  
  200.         for L1 := 1 to 10 do
  201.           if ( Up[L1].Uploads < User.Uploads) then
  202.           begin
  203.             for L2 := 9 downto L1 do
  204.               Up[L2 + 1] := Up[L2];
  205.             Up[L1] := User;
  206.             Break;
  207.           end;
  208.       end  { if SkipUser( User ) }
  209.       else
  210.       begin
  211.         Writeln( Fill( '', 19, #8 ) +
  212.                  '  - Skipped user: ' + User.UserName + '. ' );
  213.         Write( '  - Scanning user: ' );
  214.       end; { if SkipUser( User ) else }
  215.     end;
  216.   end;
  217.   Write( Fill( '', High( User.UserName ), ' ') +
  218.          Fill( '', 19 + High( User.UserName ), #8 ));
  219.  
  220.   fioFindAreaCode( Area, AreaCode,  0 );
  221.   Write( '  - Scanning file: ' );
  222.   FPos := 0;
  223.   while fioReadFileRec( Dir, Area, FPos ) do
  224.   begin
  225.     OS^.Sleep( 2 );
  226.     Inc( FPos );
  227.     if ( KilledFile in Dir.FileFlags ) then Continue;
  228.  
  229.     Write( Fill( Dir.FileName, High( Dir.FileName ), ' ' ) +
  230.            Fill( '', High( Dir.FileName ), #8 ));
  231.  
  232.     with T10^ do
  233.     begin
  234.       Inc( TotalFiles );
  235.       TotalMB := TotalMB + Dir.Size / 1048576;
  236.  
  237.       for L1 := 1 to 10 do
  238.         if (FDown[L1].Downloads<Dir.Downloads) then
  239.         begin
  240.           for L2 := 9 downto L1 do
  241.             FDown[L2+1] := FDown[L2];
  242.           FDown[L1] := Dir;
  243.           Break;
  244.         end;
  245.     end;
  246.   end;
  247.   Write( Fill( '', High( User.UserName ), ' ') +
  248.          Fill( '', 19 + High( User.UserName ), #8 ));
  249.  
  250.   if ( Language in ['A', 'E'] ) then
  251.   begin
  252.     with OutE do
  253.     begin
  254.       Assign( BullPath + '.E',
  255.               fmWriteOnly or fmExclusive,
  256.               1,
  257.               faNormalAccess,
  258.               ftMaxTimeout );
  259.       ReWrite;
  260.     end;
  261.   end;
  262.  
  263.   if ( Language in ['A', 'N'] ) then
  264.   begin
  265.     with OutN do
  266.     begin
  267.       Assign( BullPath + '.N',
  268.               fmWriteOnly or fmExclusive,
  269.               1,
  270.               faNormalAccess,
  271.               ftMaxTimeout );
  272.       ReWrite;
  273.     end;
  274.   end;
  275.  
  276.   with T10^ do
  277.   begin
  278.     Date( Year, Month, Day );
  279.     TmpTime := TimeNow;
  280.     PrintOut( 'E', '' + Fill( ' TopTen statistics', 39, ' ' ) +
  281.                    PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
  282.     PrintOut( 'N', '' + Fill( ' Ti på topp statistikk', 39, ' ' ) +
  283.                    PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
  284.     PrintOut( 'A', '' );
  285.     PrintOut( 'E', '' + Center( 'TOP-10 USERS', 78, ' ' ));
  286.     PrintOut( 'N', '' + Center( 'TI PÅ TOPP BRUKERE', 78, ' ' ));
  287.     PrintOut( 'A', '' );
  288.     PrintOut( 'E', Center( 'Total user time: ' + I2S( TotalTime, 0 ), 78, ' ' ));
  289.     PrintOut( 'N', Center( 'Total bruker tid: ' + I2S( TotalTime, 0 ) ,78, ' ' ));
  290.     PrintOut( 'E', Center( 'Total number of logons: ' + I2S( TotalOn, 0 ), 78, ' ' ));
  291.     PrintOut( 'N', Center( 'Antall pålogginger: ' + I2S( TotalOn, 0 ), 78, ' ' ));
  292.     PrintOut( 'A', '' );
  293.     PrintOut( 'E', ' Username                     Minutes    Username                      Logons ' );
  294.     PrintOut( 'N', ' Brukernavn                  Minutter    Pålogginger              Pålogginger ' );
  295.     PrintOut( 'A', TopLine );
  296.  
  297.     for L1 := 1 to 10 do
  298.     begin
  299.       if ( L1 = 1 ) then TmpStr := ''
  300.       else TmpStr := '';
  301.       PrintOut( 'A', '│' + TmpStr + Fill( TopUserTime[L1].UserName, 30 ,' ' ) +
  302.                      PreFill( I2S( TopUserTime[L1].TimeTotal, 0 ), 6, ' ' ) +
  303.                      '│' + I2S( L1, 2 ) +
  304.                      '│' + TmpStr + Fill( TopUserCnt[L1].UserName, 30, ' ' ) +
  305.                      PreFill( I2S( TopUserCnt[L1].TimesOn, 0 ), 6, ' ' ) + '│' );
  306.     end;
  307.     PrintOut( 'A', BottomLine );
  308.  
  309.     PrintOut( 'E', '' + Fill( ' TopTen statistics', 39, ' ' ) +
  310.                    PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
  311.     PrintOut( 'N', '' + Fill( ' Ti på topp statistikk', 39, ' ' ) +
  312.                    PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
  313.     PrintOut( 'A', '' );
  314.     PrintOut( 'E', '' + Center( 'TOP-10 DOWNLOADERS', 39, ' ' ) +
  315.                                Center( 'TOP-10 UPLOADERS', 39, ' ' ));
  316.     PrintOut( 'N', '' + Center( 'TI PÅ TOPP DOWNLOADERE', 39, ' ' ) +
  317.                                Center( 'TI PÅ TOPP UPLOADERE', 39, ' ' ));
  318.     PrintOut( 'A', '' );
  319.     PrintOut( 'E', Center( 'Total number of downloads: ' + I2S( TotalDown, 0 ), 39, ' ' ) +
  320.                    Center( 'Total number of uploads: ' + I2S( TotalUp, 0 ), 39, ' ' ));
  321.     PrintOut( 'N', Center( 'Antall downloads totalt: ' + I2S( TotalDown, 0 ), 39, ' ' ) +
  322.                    Center( 'Antall uploads totalt: ' + I2S( TotalUp, 0 ), 39, ' ' ));
  323.     PrintOut( 'E', Center( 'MB downloaded: ' + R2S( TotalMDown, 0, 1 ), 39, ' ' ) +
  324.                    Center( 'MB uploaded: ' + R2S( TotalMUp, 0, 1 ), 39, ' ' ));;
  325.     PrintOut( 'N', Center( 'MB downloadet: ' + R2S( TotalMDown, 0, 1 ), 39, ' ' ) +
  326.                    Center( 'MB uploadet: ' + R2S( TotalMUp, 0, 1 ), 39, ' ' ));
  327.     PrintOut( 'A', '' );
  328.     PrintOut( 'E', ' Username                   Downloads    Username                     Uploads ' );
  329.     PrintOut( 'N', ' Brukernavn                 Downloads    Brukernavn                   Uploads ' );
  330.     PrintOut( 'A', TopLine );
  331.  
  332.     for L1 := 1 to 10 do
  333.     begin
  334.       if ( L1 = 1 ) then TmpStr := ''
  335.       else TmpStr := '';
  336.       PrintOut( 'A',  '│' + TmpStr + Fill( Down[L1].UserName, 30, ' ' ) +
  337.                       PreFill( I2S( Down[L1].Downloads, 0 ), 6, ' ' ) +
  338.                       '│' + I2S( L1, 2 ) +
  339.                       '│' + TmpStr + Fill( Up[L1].UserName, 30, ' ' ) +
  340.                       PreFill( I2S( Up[L1].Uploads, 0 ), 6, ' ' ) + '│' );
  341.     end;
  342.     PrintOut( 'A', BottomLine );
  343.  
  344.     PrintOut( 'E', '' + Fill( ' TopTen statistics', 39, ' ' ) +
  345.                    PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
  346.     PrintOut( 'N', '' + Fill( ' Ti på topp statistikk', 39, ' ' ) +
  347.                    PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
  348.     PrintOut( 'A', '' );
  349.     PrintOut( 'E', '' + Center( 'TOP-10 DOWNLOADED FILES', 39, ' ' ) +
  350.                                Center( '', 39, ' ' ));
  351.     PrintOut( 'N', '' + Center( 'TI PÅ TOPP DOWNLOADEDE FILER', 39, ' ' ) +
  352.                                Center( '', 39, ' ' ));
  353.     PrintOut( 'A', '' );
  354.     PrintOut( 'E', Center( 'Total number of files: ' + I2S( TotalFiles, 0 ), 39, ' ' ));
  355.     PrintOut( 'N', Center( 'Antall filer totalt: ' + I2S( TotalFiles, 0 ), 39, ' ' ));
  356.     PrintOut( 'E', Center( 'Total number of MB: ' + R2S( TotalMB, 0, 2 ), 39, ' ' ));
  357.     PrintOut( 'N', Center( 'Antall MB totalt: ' + R2S( TotalMB, 0, 2 ), 39, ' ' ));
  358.     PrintOut( 'A',  '' );
  359.     PrintOut( 'E', '' + Fill( ' File name          Size   Dls Date', 78, ' ' ) + '' );
  360.     PrintOut( 'N', '' + Fill( ' Filnavn            Str.  Ant. Dato', 78, ' ' ) + '' );
  361.  
  362.     PrintOut( 'A', TopLine );
  363.  
  364.     for L1 := 1 to 10 do
  365.     begin
  366.       if ( L1 = 1 ) then TmpStr := ''
  367.       else TmpStr := '';
  368.       PrintOut( 'A', '│' + TmpStr + Fill( FDown[L1].FileName, 16, ' ' ) +
  369.                      PreFill( I2S( FDown[L1].Size div 1024, 0 ), 7, ' ' ) + ' ' +
  370.                      PreFill( I2S( FDown[L1].Downloads, 0 ), 5, ' ' ) +
  371.                      ' ' +
  372.                      I2S( FDown[L1].Date.Date.Day, 2 ) +
  373.                      I2S( FDown[L1].Date.Date.Month, 2 )+
  374.                      I2S( FDown[L1].Date.Date.Year - 1900, 2 ) +
  375.                      '│' + I2S( L1, 2 ) +
  376.                      '│' + TmpStr + Fill( '', 36, ' ' ) + '│' );
  377.     end;
  378.  
  379.     PrintOut( 'A', BottomLine );
  380.   end;
  381.  
  382.   if ( Language in ['A', 'E'] ) then
  383.   begin
  384.     OutE.Close;
  385.     Writeln( '  - English Top 10 bulletin written.' );
  386.   end;
  387.  
  388.   if ( Language in ['A', 'N'] ) then
  389.   begin
  390.     OutN.Close;
  391.     Writeln( '  - Norsk 10 på Topp bulletin skrevet.' );
  392.   end;
  393.  
  394.   Dispose( T10 );
  395. end; { procedure CreateBull }
  396.  
  397. begin
  398.   Writeln;
  399.   Writeln( 'TopTen v1.04 - Generate TopTen bulletins from FOSS system files' );
  400.   Writeln;
  401.  
  402.   if not ( Par^.Count = 1 ) then
  403.   begin
  404.     Writeln( 'Usage:' );
  405.     Writeln( '   TOPTEN {-L[A|E|N]} {-S[filename]} {-A[area]} [bullpath]' );
  406.     Writeln;
  407.     Writeln( '   -L           Requested bulletin language (All, English or Norwegian)' );
  408.     Writeln( '                (Default: All)' );
  409.     Writeln( '   -S           Path to list of user names to ignore' );
  410.     Writeln( '                (Default: Ignore none)' );
  411.     Writeln( '   -A           Area code of area to collect info from' );
  412.     Writeln( '                (Default: MAIN)' );
  413.     Writeln( '   bullpath     Path of file to write bulletin into (without extension)' );
  414.     Exit;
  415.   end;
  416.  
  417.   New( TopTenBull, Init );
  418.   TopTenBull^.ReadParams;
  419.   TopTenBull^.CreateBull;
  420.   Dispose( TopTenBull, Done );
  421. End. { Program TopTen }