home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / s!x / topmail / TopMail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-21  |  4.9 KB  |  217 lines

  1. /************************************************/
  2.                                              /***/
  3. #define REVISION "V1.0"                         /***/
  4. #define REVDATE  "(17.02.96)"                 /***/
  5. #define PROGNAME "TopMail"                     /***/
  6. #define NAME     "TopMail"                     /***/
  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    mail_total=0;
  84.  
  85.     SendStrDataCmd(177,"TopMail V1.0",0);
  86.     SendStrDataCmd(DT_LINELENGTH,"",1);
  87.     lines=atoi(XIM_Msg->String);
  88.     strcpy(time,timenow());
  89.  
  90.  
  91.     ws("c",1);
  92.     ws(".---------------------------.",1);
  93.     ws("|TopMail V1.0 ©1996 Joe Cool|",1);
  94.     ws("+---------------------------+----------------------------.",1);
  95.     ws("|    Name                Group/Location           Mails  |",1);
  96.     ws("+--------------------------------------------------------+",1);
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.     fib=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL);
  106.     if (!fib) ShutDown();
  107.     
  108.     lock  = Lock( "bbs:User.Data",ACCESS_READ );
  109.     success = Examine( lock, fib);
  110.     users=(struct User *) malloc(fib->fib_Size);
  111.     if (!users) ShutDown();
  112.     fh = OpenFromLock(lock);
  113.     Read(fh, users, fib->fib_Size);
  114.     Close(fh);
  115.     number=fib->fib_Size/sizeof(struct User);
  116.     userpointer=users;
  117.  
  118.     for (counter=0;counter<number;counter++)
  119.     {
  120.         if (userpointer->Slot_Number) numberreal++;
  121.         userpointer++;
  122.         
  123.     }
  124.         
  125.     
  126.     sort_who=malloc(numberreal*sizeof(int));
  127.     sort_inh=malloc(numberreal*sizeof(ULONG));
  128.  
  129.     count=0;
  130.     userpointer=users;
  131.     for (counter=0;counter<number;counter++)
  132.     {
  133.         if (userpointer->Slot_Number)  
  134.         {
  135.             if (userpointer->Messages_Posted)
  136.             {
  137.                 sort_who[count]=userpointer->Slot_Number;
  138.                 sort_inh[count]=userpointer->Messages_Posted;
  139.                 count++;
  140.             }
  141.         mail_total+=(float)userpointer->Messages_Posted;
  142.  
  143.         }
  144.         userpointer++;
  145.     }
  146.     numberuse=count;
  147.  
  148.     for (counter=numberuse-1;counter>=0;counter--)
  149.     {
  150.         for (counter2=1;counter2<=counter;counter2++)
  151.             if (sort_inh[counter2-1]<sort_inh[counter2])
  152.             {
  153.                 temp_inh=sort_inh[counter2-1];
  154.                 sort_inh[counter2-1]=sort_inh[counter2];
  155.                 sort_inh[counter2]=temp_inh;
  156.                 temp_who=sort_who[counter2-1];
  157.                 sort_who[counter2-1]=sort_who[counter2];
  158.                 sort_who[counter2]=temp_who;
  159.             }
  160.     }
  161.  
  162.     if (numberuse<(lines-13)) max=numberuse; else max=(lines-13);
  163.     
  164.     for (counter=0;counter<max;counter++)
  165.     {
  166.         userpointer=users;
  167.         userpointer+=(sort_who[counter]-1);
  168.  
  169.         sprintf(buffer2, "|%2d) %-19.19s %-20.20s     %5d  |",counter+1,userpointer->Name,userpointer->Location,userpointer->Messages_Posted);
  170.         ws(buffer2,1);
  171.     }                
  172.     ws("+--------------------------------------------------------+",1);
  173.     sprintf(buffer,"| Time: %s                     Total Mails: %5.0f  |",time,mail_total);
  174.     ws (buffer,1); 
  175.     ws("`--------------------------------------------------------'",1);
  176.             
  177. }
  178. char *Nodes_get(void)
  179. {
  180.     SendStrDataCmd(ACTIVE_NODES,"",0);
  181.     return(XIM_Msg->String);
  182. }
  183. char *Mainline(void)
  184. {
  185.     SendStrDataCmd(BB_MAINLINE,"",0);
  186.     return(XIM_Msg->String);
  187. }
  188. char *timenow()
  189. {
  190. struct timerequest *TimerIO;
  191. struct MsgPort *TimerMP;
  192. struct Message *TimerMSG;
  193. LONG error;
  194. ULONG hrs,secs,mins;
  195. char buffer[50];
  196.  
  197. TimerMP = CreatePort(0,0);
  198. if(!TimerMP) return(NULL);
  199. TimerIO = (struct timerequest *)CreateExtIO(TimerMP,sizeof(struct timerequest));
  200. if (!TimerIO) return(NULL);
  201. error=OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)TimerIO,0L);
  202. if (error) return (NULL);
  203. TimerIO->tr_node.io_Command = TR_GETSYSTIME;
  204. DoIO((struct IORequest *) TimerIO);
  205. secs=TimerIO->tr_time.tv_secs;
  206. mins=secs/60;
  207. hrs=mins/60;
  208. secs=secs%60;
  209. mins=mins%60;
  210. hrs=hrs%24;
  211. CloseDevice((struct IORequest *) TimerIO);
  212. DeleteExtIO((struct IORequest *) TimerIO);
  213. DeletePort(TimerMP);
  214. sprintf(buffer,"%2.2d:%2.2d:%2.2d",hrs,mins,secs);
  215. return(buffer);
  216. }
  217.