home *** CD-ROM | disk | FTP | other *** search
-
- // TOPUSER.SCR -- Maximus Top User Report Generator -- Version 1.00
- //
- // Script program for MUL - the Maximus User Language
- // MUL is (C) Copyright 1990-93 by CodeLand Australia
-
- // TOPUSER scans the Maximus USER.BBS file, and writes an 'avatar'
- // *.BBS file for online display. It lists the top ~15 callers, uploaders
- // downloaders, and displays totals. There are no command line parameters,
- // edit the following entries to suit your system.
-
- char *rfile = "TOPUSER.BBS"; // Path & name of report file
- char *ufile = "USER.BBS"; // Path & name of Maximus user file
- //char *ufile = "C:\\BBS\\USER.BBS"; // Path & name of Maximus user file
- int rnum=15; // Report number
-
- // AVAILABLE COLOUR CONSTANTS
- // Foreground & Background:
- // BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LGREY
- // Foreground ONLY:
- // DGREY, LBLUE, LGREEN, LCYAN, LRED, LMAGENTA, YELLOW, WHITE
-
- char COLOURHEAD = WHITE; // Report headline colour
- char COLOURHUND = LRED; // Report underline colour
- char COLOURBOXB = CYAN; // Report box colour
- char COLOURLABL = LCYAN; // Report box label colour
- char COLOURLABB = BLUE; // Report box label bg colour
- char COLOUROPT1 = YELLOW; // Highlight colour one
- char COLOUROPT2 = LGREEN; // Highlight colour two
- char COLOUROPT3 = LRED; // Highlight colour three
- char COLOURDATA = LGREY; // Report data colour
-
- char *banner = "TOPUSER v1.00"; // Script banner
- char *desc = "Top User Reporter"; // Description
- char MCLS=0x0C; // Avatar 'clear screen'
- char MENTER=0x01; // Maximus 'press enter'
- char MMOREOFF=0x0B; // Maximus 'more off'
-
- long ctotal=0; // Report calls total
- long utotal=0; // Report uploads total
- long dtotal=0; // Report dnloads total
-
- int cidx[rnum]; // Top caller array
- int uidx[rnum]; // Top uploader array
- int didx[rnum]; // Top dnloader array
-
- long fp; // Report file handle
-
- main () // Main program
- {
- printf ("\n%s - %s\n\n",banner,desc); // Announce
-
- if (!BaseOpenR (ufile)) {
- printf ("ERROR opening user file %s\n",ufile);
- saybibi (); exit ();
- }
-
- if (scanufile ()) writereport (); // Process the user file
-
- BaseClose (); // Close the user base
- saybibi (); // Was it good for you too?
- }
-
- // Collect sort indexes and scan for totals
- scanufile ()
- {
- int i;
-
- printf ("Collecting the %d top Callers ",rnum);
-
- // Collect calls index
- BaseSort (IDX_CALLS); // Sort the base by calls
- for(i=2;i<=rnum+1;i++) { // For 'rnum' records
- if(i>BaseCount ()) break; // Abort if out of records
- cidx[i-2]=BaseIdx (i); // Save the record number
- }
-
- printf ("\nCollecting the %d top Uploaders ",rnum);
-
- // Collect upload index
- BaseSort (IDX_UPLD); // Sort the base by uploads
- for(i=2;i<=rnum+1;i++) { // For 'rnum' records
- if(i>BaseCount ()) break; // Abort if out of records
- uidx[i-2]=BaseIdx (i); // Save the record number
- }
-
- printf ("\nCollecting the %d top Dnloaders ",rnum);
-
- // Collect dnload index
- BaseSort (IDX_DNLD); // Sort the base by dnloads
- for(i=2;i<=rnum+1;i++) { // For 'rnum' records
- if(i>BaseCount ()) break; // Abort if out of records
- didx[i-2]=BaseIdx (i); // Save the record number
- }
-
- BaseSort (IDX_DEFAULT); // Return to default index
-
- printf ("\nScanning for totals - 1");
-
- for(i=2;i<=BaseCount ();i++) { // Ignore first sysop record
- if (!BaseRead (i)) {
- printf ("\nERROR reading user file\n");
- return 0;
- }
-
- ctotal=ctotal+USRcalls; // Update the calls total
- utotal=utotal+USRupld; // Update the uploads total
- dtotal=dtotal+USRdnld; // Update the dnloads total
-
- if (!(i%50)) printf("%c%c%c%c%4d",8,8,8,8,i);
- }
-
- printf("%c%c%c%c%4d records\n",8,8,8,8,i-1); // End notify
- return 1;
- }
-
- readerror () // Report a user base read problem
- {
- printf ("\nERROR reading user file\n");
- fclose (fp); return;
- }
-
- writereport () // Write the .BBS report file
- {
- int i;
- char colourhead[5], colourhund[5], colourboxb[5], colourdata[5];
- char colouropt1[5], colouropt2[5], colouropt3[5], colourlabl[5];
- char *head=" - TOP USER REPORT - ";
- char *line=" ──────────────────────────────────────\n";
- char *b1 = "┌─────────────────────────┬─────────────";
- char *b2 = "────────────┬─────────────────────────┐\n";
- char *c1 = "├─────────────────────────┼─────────────";
- char *c2 = "────────────┼─────────────────────────┤\n";
- char *d1 = "└─────────────────────────┴─────────────";
- char *d2 = "────────────┴─────────────────────────┘\n";
-
- fp=fopen (rfile,"wb"); // Open report file
- if (fp==NULL) return;
-
- printf ("Writing report file \"%s\" ",rfile);
-
- // The Avt() function returns a pointer to a static character array
- // containing the requested avatar characters. The following strcpy's
- // save the requested strings for later use. This IS specifically
- // required to allow more than one colour sequence as an (f)printf
- // parameter. The unseen trap that this avoids, is that all function
- // call parameter data is interpreted at _function call_ time. The
- // result of multiple avt() references in a (f)printf parameter list
- // is that the data from the _last_ avt() call would be used for all
- // references <grumble>.
-
- // Get avatar colour strings
- strcpy (colourhead,Avt (COLOURHEAD)); strcpy (colourhund,Avt (COLOURHUND));
- strcpy (colourboxb,Avt (COLOURBOXB)); strcpy (colourdata,Avt (COLOURDATA));
- strcpy (colouropt1,Avt (COLOUROPT1)); strcpy (colouropt2,Avt (COLOUROPT2));
- strcpy (colouropt3,Avt (COLOUROPT3));
- strcpy (colourlabl,Avt (COLOURLABL,COLOURLABB));
-
- // Output CLS, MoreOff, heading and underline
- fputc (MCLS,fp); fputc (MMOREOFF,fp);
- fprintf (fp,"%s MUL v%s%s%s\n",
- colourhead,VERSN,head,DateToStr (SysDate ()));
- fprintf (fp,"%s%s",colourhund,line);
-
- fprintf (fp,"%s%s%s",colourboxb,b1,b2); // Output box top
-
- // Output box heading
- fprintf (fp,"│%s TOP CALLER (Calls) %s",colourlabl,colourboxb);
- fprintf (fp,"│%s TOP UPLOADER (Kb) %s",colourlabl,colourboxb);
- fprintf (fp,"│%s TOP DOWNLOADER (Kb) %s│",colourlabl,colourboxb);
-
- fprintf(fp,"\n%s%s",c1,c2); // Output box divider
-
- // Output first data line
- fprintf (fp,"│ %s",colouropt1);
- if (cidx[0]) {
- if (!BaseRead (cidx[0])) { readerror(); return; } // Find record
- fprintf (fp,"%-17s %5lu %s│ %s",USRname,USRcalls,colourboxb,colouropt2);
- }
- else fprintf (fp," %s│ %s",colourboxb,colouropt2);
-
- if (uidx[0]) {
- if (!BaseRead (uidx[0])) { readerror(); return; } // Find record
- fprintf (fp,"%-17s %5lu %s│ %s",USRname,USRupld,colourboxb,colouropt3);
- }
- else fprintf (fp," %s│ %s",colourboxb,colouropt3);
-
- if (didx[0]) {
- if (!BaseRead (didx[0])) { readerror(); return; } // Find record
- fprintf (fp,"%-16s %6lu %s│\n",USRname,USRdnld,colourboxb);
- }
- else fprintf (fp," %s│\n",colourboxb);
-
- // Output the remaining data
- for (i=1;i<rnum;i++) {
- fprintf (fp,"│ %s",colourdata);
- if (cidx[i]) {
- if (!BaseRead (cidx[i])) { readerror(); return; } // Find record
- fprintf (fp,"%-17s %5lu %s│ %s",
- USRname,USRcalls,colourboxb,colourdata);
- }
- else fprintf (fp," %s│ %s",
- colourboxb,colourdata);
-
- if (uidx[i]) {
- if (!BaseRead (uidx[i])) { readerror(); return; } // Find record
- fprintf (fp,"%-17s %5lu %s│ %s",
- USRname,USRupld,colourboxb,colourdata);
- }
- else fprintf (fp," %s│ %s",
- colourboxb,colourdata);
-
- if (didx[i]) {
- if (!BaseRead (didx[i])) { readerror(); return; } // Find record
- fprintf (fp,"%-16s %6lu %s│\n",USRname,USRdnld,colourboxb);
- }
- else fprintf (fp," %s│\n",colourboxb);
- }
-
- fprintf(fp,"%s%s",c1,c2); // Output box divider
-
- // Totals
- fprintf (fp,"│ %s",colourhead);
- fprintf (fp,"Total Calls %s%9lu %s│ %s",
- colouropt1,ctotal,colourboxb,colourhead);
- fprintf (fp,"Total Uploads %s%9lu %s│ %s",
- colouropt2,utotal,colourboxb,colourhead);
- fprintf (fp,"Total Dnloads %s%9lu %s│\n",
- colouropt3,dtotal,colourboxb);
-
- // Output lower box border
- fprintf (fp,"%s%s%s",colourboxb,d1,d2);
-
- // Press Enter prompt and CLS
- fprintf (fp,"%s%c",Avt (WHITE,BLACK),MENTER);
- fprintf (fp,"%s%c",Avt (LGREY,BLACK),MCLS);
-
- fclose (fp); // Close report file
- putch ('\n'); // End notify
- }
-
- // Byebye
- saybibi ()
- {
- puts ("\nTopUser done!\n");
- }
-
- // End of script
-
-