home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / s!x / TopUL / TopUl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-09  |  5.7 KB  |  241 lines

  1. /************************************************/
  2.                                              /***/
  3. #define REVISION "V1.0"                         /***/
  4. #define REVDATE  "(17.02.96)"                     /***/
  5. #define PROGNAME "TopUL"                     /***/
  6. #define NAME     "Announce"                     /***/
  7. #define AUTHOR   "Joe Cool"                     /***/
  8.                                              /***/
  9. /************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/ports.h>
  13. #include <exec/memory.h>
  14. #include <dos/dos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/alib_protos.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #include "aedoor.h"
  23. #include "express.h"
  24. static const char VersionTag[] = "\0$VER: "PROGNAME" "REVISION" "REVDATE"";
  25. #define ws WriteStr
  26.  
  27. void Start(int node);
  28. char *Nodes_get(void);
  29. char *Mainline(void);
  30. char *handleget(void);
  31. char *timenow (VOID);
  32.  
  33. void main(int argc, char *argv[])
  34. {
  35.     int    Node=0;
  36.     char buffer[200];
  37. if(argc<2)
  38. {
  39.     printf("Sorry, %s must be called from S!X or /X\n",argv[0]);
  40.     exit(0);
  41. }
  42.  
  43. Node=atoi(argv[1]);
  44. Register(Node);
  45.  
  46. XIM_Msg->Command=140;                    
  47. CheckMessage();
  48. SetTaskPri(FindTask(0),atol(XIM_Msg->String));
  49.  
  50. Start(Node);
  51. ShutDown();
  52.  
  53. }
  54.  
  55.  
  56.  
  57.  
  58. void Start(Node)
  59. {
  60.     char    buffer[255],
  61.             buffer2[255],
  62.             time[10],
  63.             *pointer=NULL;
  64.     long    counter=0,
  65.             counter2=0,
  66.             count=0,
  67.             number=0,
  68.             numberreal=0,
  69.             numberuse=0;
  70.     BPTR    fh=NULL,
  71.             lock=NULL;
  72.     BOOL    success=FALSE;
  73.     struct FileInfoBlock *fib=NULL;
  74.     struct    User    *users=NULL,
  75.                     *userpointer=NULL;
  76.     int        *sort_who=NULL,
  77.             temp_who,
  78.             max,
  79.             lines;
  80.     ULONG    *sort_inh=NULL,
  81.             temp_inh,
  82.             gig,meg,kb,b;
  83.     float    up_total=0,
  84.             files_total=0,
  85.             calls_total=0;
  86.  
  87.     SendStrDataCmd(177,"TopUl V1.0",0);
  88.     SendStrDataCmd(DT_LINELENGTH,"",1);
  89.     lines=atoi(XIM_Msg->String);
  90.     strcpy(time,timenow());
  91.  
  92.  
  93.     ws("c",1);
  94.     ws(".-------------------------.",1);
  95.     ws("|TopUl V1.0 ©1996 Joe Cool|",1);
  96.     ws("+-------------------------+-------------------------------------------------.",1);
  97.     ws("|    Name                Group/Location           Upload-Bytes  Files  Call |",1);
  98.     ws("+---------------------------------------------------------------------------+",1);
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.     fib=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL);
  108.     if (!fib) ShutDown();
  109.     
  110.     lock  = Lock( "bbs:User.Data",ACCESS_READ );
  111.     success = Examine( lock, fib);
  112.     users=(struct User *) malloc(fib->fib_Size);
  113.     if (!users) ShutDown();
  114.     fh = OpenFromLock(lock);
  115.     Read(fh, users, fib->fib_Size);
  116.     Close(fh);
  117.     number=fib->fib_Size/sizeof(struct User);
  118.     userpointer=users;
  119.  
  120.     for (counter=0;counter<number;counter++)
  121.     {
  122.         if (userpointer->Slot_Number && userpointer->Slot_Number!=1 ) numberreal++;
  123.         userpointer++;
  124.         
  125.     }
  126.         
  127.     
  128.     sort_who=malloc(numberreal*sizeof(int));
  129.     sort_inh=malloc(numberreal*sizeof(ULONG));
  130.  
  131.     count=0;
  132.     userpointer=users;
  133.     for (counter=0;counter<number;counter++)
  134.     {
  135.         if (userpointer->Slot_Number && userpointer->Slot_Number!=1)  
  136.         {
  137.             if (userpointer->Bytes_Upload)
  138.             {
  139.                 sort_who[count]=userpointer->Slot_Number;
  140.                 sort_inh[count]=userpointer->Bytes_Upload;
  141.                 count++;
  142.             }
  143.         up_total+=(float)userpointer->Bytes_Upload;
  144.         files_total+=(float)userpointer->Uploads;
  145.         calls_total+=(float)userpointer->Times_Called;
  146.  
  147.         }
  148.         userpointer++;
  149.     }
  150.     numberuse=count;
  151.  
  152.     for (counter=numberuse-1;counter>=0;counter--)
  153.     {
  154.         for (counter2=1;counter2<=counter;counter2++)
  155.             if (sort_inh[counter2-1]<sort_inh[counter2])
  156.             {
  157.                 temp_inh=sort_inh[counter2-1];
  158.                 sort_inh[counter2-1]=sort_inh[counter2];
  159.                 sort_inh[counter2]=temp_inh;
  160.                 temp_who=sort_who[counter2-1];
  161.                 sort_who[counter2-1]=sort_who[counter2];
  162.                 sort_who[counter2]=temp_who;
  163.             }
  164.     }
  165.  
  166.     if (numberuse<(lines-13)) max=numberuse; else max=(lines-13);
  167.     
  168.     for (counter=0;counter<max;counter++)
  169.     {
  170.         userpointer=users;
  171.         userpointer+=(sort_who[counter]-1);
  172.         b  =sort_inh[counter];
  173.         kb =b/1000;
  174.         meg=kb/1000;
  175.         gig=meg/1000;
  176.  
  177.         gig=gig%1000;
  178.         meg=meg%1000;
  179.         kb = kb%1000;
  180.         b  =  b%1000;
  181.  
  182.         if (gig) sprintf(buffer, "%2d.%3.3d.%3.3d.%3.3d",gig,meg,kb,b);
  183.         else
  184.             if (meg) sprintf(buffer, "   %3d.%3.3d.%3.3d",meg,kb,b);
  185.             else
  186.                 if (kb) sprintf(buffer, "       %3d.%3.3d",kb,b);
  187.                 else
  188.                     if (b) sprintf(buffer, "           %3d",b);
  189.  
  190.         
  191.  
  192.  
  193.         sprintf(buffer2, "|%2d) %-19.19s %-20.20s  %s   %4d   %4d |",counter+1,userpointer->Name,userpointer->Location,buffer,userpointer->Uploads,userpointer->Times_Called);
  194.         ws(buffer2,1);
  195.     }                
  196.     ws("+---------------------------------------------------------------------------+",1);
  197.     sprintf(buffer,"| Time: %s       Total Up  kBytes: %5.0f   Files: %5.0f  Calls: %5.0f |",time,up_total/(1024*1024),files_total,calls_total);
  198.     ws (buffer,1); 
  199.     ws("`---------------------------------------------------------------------------'",1);
  200.             
  201. }
  202. char *Nodes_get(void)
  203. {
  204.     SendStrDataCmd(ACTIVE_NODES,"",0);
  205.     return(XIM_Msg->String);
  206. }
  207. char *Mainline(void)
  208. {
  209.     SendStrDataCmd(BB_MAINLINE,"",0);
  210.     return(XIM_Msg->String);
  211. }
  212. char *timenow()
  213. {
  214. struct timerequest *TimerIO;
  215. struct MsgPort *TimerMP;
  216. struct Message *TimerMSG;
  217. LONG error;
  218. ULONG hrs,secs,mins;
  219. char buffer[50];
  220.  
  221. TimerMP = CreatePort(0,0);
  222. if(!TimerMP) return(NULL);
  223. TimerIO = (struct timerequest *)CreateExtIO(TimerMP,sizeof(struct timerequest));
  224. if (!TimerIO) return(NULL);
  225. error=OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)TimerIO,0L);
  226. if (error) return (NULL);
  227. TimerIO->tr_node.io_Command = TR_GETSYSTIME;
  228. DoIO((struct IORequest *) TimerIO);
  229. secs=TimerIO->tr_time.tv_secs;
  230. mins=secs/60;
  231. hrs=mins/60;
  232. secs=secs%60;
  233. mins=mins%60;
  234. hrs=hrs%24;
  235. CloseDevice((struct IORequest *) TimerIO);
  236. DeleteExtIO((struct IORequest *) TimerIO);
  237. DeletePort(TimerMP);
  238. sprintf(buffer,"%2.2d:%2.2d:%2.2d",hrs,mins,secs);
  239. return(buffer);
  240. }
  241.