home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / dos / sbbs_src.exe / SBBS / SLOG / SLOG.C < prev   
Encoding:
C/C++ Source or Header  |  1997-04-13  |  3.9 KB  |  141 lines

  1. /* SLOG.C */
  2.  
  3. /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <fcntl.h>
  8. #include <sys\stat.h>
  9. #include <io.h>
  10. #include <dos.h>
  11. #include <alloc.h>
  12. #include <time.h>
  13. #include <errno.h>
  14.  
  15. #include "sbbsdefs.h"
  16.  
  17. /****************************************************************************/
  18. /* Network open function. Opens all files DENYALL and retries LOOP_NOPEN    */
  19. /* number of times if the attempted file is already open or denying access  */
  20. /* for some other reason.    All files are opened in BINARY mode.            */
  21. /****************************************************************************/
  22. int nopen(char *str, int access)
  23. {
  24.     char    logstr[256];
  25.     int     file,share,count=0;
  26.  
  27. if(access==O_RDONLY) share=O_DENYWRITE;
  28.     else share=O_DENYALL;
  29. while(((file=open(str,O_BINARY|share|access,S_IWRITE))==-1)
  30.     && errno==EACCES && count++<LOOP_NOPEN);
  31. if(count)
  32.     printf("NOPEN COLLISION - File: %s Count: %d"
  33.         ,str,count);
  34. if(file==-1 && errno==EACCES)
  35.     printf("\7\r\nNOPEN: ACCESS DENIED\r\n\7");
  36. return(file);
  37. }
  38.  
  39.  
  40. /****************************************************************************/
  41. /* Lists system statistics for everyday the bbs has been running.           */
  42. /* Either for the current node (node=1) or the system (node=0)              */
  43. /****************************************************************************/
  44. int main(int argc, char **argv)
  45. {
  46.     char str[256],dir[256]={""},*p;
  47.     uchar *buf;
  48.     int i,file,pause=0,lncntr=0;
  49.     time_t timestamp;
  50.     long l;
  51.     ulong   length,
  52.             logons,
  53.             timeon,
  54.             posts,
  55.             emails,
  56.             fbacks,
  57.             ulb,
  58.             uls,
  59.             dlb,
  60.             dls;
  61.      struct date date;
  62.      struct time curtime;
  63.  
  64.  
  65. printf("\nSynchronet System/Node Statistics Log Viewer v1.01\n\n");
  66.  
  67. for(i=1;i<argc;i++)
  68.     if(!stricmp(argv[i],"/P"))
  69.         pause=1;
  70.     else
  71.         strcpy(dir,argv[1]);
  72. if(!dir[0]) {
  73.     p=getenv("SBBSCTRL");
  74.     if(p!=NULL)
  75.         strcpy(dir,p); }
  76.  
  77. if(dir[0] && dir[strlen(dir)-1]!='\\')
  78.     strcat(dir,"\\");
  79.  
  80. sprintf(str,"%sCSTS.DAB",dir);
  81. if((file=nopen(str,O_RDONLY))==-1) {
  82.     printf("Error opening %s\r\n",str);
  83.     return(1); }
  84. length=filelength(file);
  85. if(length<40) {
  86.     close(file);
  87.     return(1); }
  88. if((buf=(char *)MALLOC(length))==0) {
  89.     close(file);
  90.     printf("error allocating %lu bytes\r\n",length);
  91.     return(1); }
  92. read(file,buf,length);
  93. close(file);
  94. l=length-4;
  95. while(l>-1L) {
  96.     fbacks=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  97.         |((long)buf[l+3]<<24);
  98.     l-=4;
  99.     emails=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  100.         |((long)buf[l+3]<<24);
  101.     l-=4;
  102.     posts=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  103.         |((long)buf[l+3]<<24);
  104.     l-=4;
  105.     dlb=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  106.         |((long)buf[l+3]<<24);
  107.     l-=4;
  108.     dls=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  109.         |((long)buf[l+3]<<24);
  110.     l-=4;
  111.     ulb=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  112.         |((long)buf[l+3]<<24);
  113.     l-=4;
  114.     uls=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  115.         |((long)buf[l+3]<<24);
  116.     l-=4;
  117.     timeon=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  118.         |((long)buf[l+3]<<24);
  119.     l-=4;
  120.     logons=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  121.         |((long)buf[l+3]<<24);
  122.     l-=4;
  123.     timestamp=buf[l]|((long)buf[l+1]<<8)|((long)buf[l+2]<<16)
  124.         |((long)buf[l+3]<<24);
  125.     l-=4;
  126.     unixtodos(timestamp-(24*60*60),&date,&curtime); /* 1 day less than stamp */
  127.     printf("%2.2d/%2.2d/%2.2d T:%5lu   L:%3lu   P:%3lu   "
  128.         "E:%3lu   F:%3lu   U:%6luk %3lu  D:%6luk %3lu\n"
  129.         ,date.da_mon,date.da_day,date.da_year-1900,timeon,logons,posts,emails
  130.         ,fbacks,ulb/1024,uls,dlb/1024,dls);
  131.     lncntr++;
  132.     if(pause && lncntr>=20) {
  133.         printf("[Hit a key]");
  134.         if(getch()==3)
  135.             break;
  136.         printf("\r");
  137.         lncntr=0; } }
  138. FREE(buf);
  139. return(0);
  140. }
  141.