home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / dos / sbbs_src.exe / SBBS / DSTSEDIT / DSTSEDIT.C next >
Encoding:
C/C++ Source or Header  |  1997-04-13  |  5.5 KB  |  228 lines

  1. /* DSTSEDIT.C */
  2.  
  3. /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
  4.  
  5. #include <dos.h>
  6. #include <dir.h>
  7. #include <stdio.h>
  8. #include <io.h>
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11. #include <errno.h>
  12. #include <stdlib.h>
  13.  
  14. #include "..\sbbsdefs.h"
  15.  
  16. /****************************************************************************/
  17. /* Network open function. Opens all files DENYALL and retries LOOP_NOPEN    */
  18. /* number of times if the attempted file is already open or denying access  */
  19. /* for some other reason.    All files are opened in BINARY mode.            */
  20. /****************************************************************************/
  21. int nopen(char *str, int access)
  22. {
  23.     char logstr[256];
  24.     int file,share,count=0;
  25.  
  26. if(access==O_RDONLY) share=O_DENYWRITE;
  27.     else share=O_DENYALL;
  28. while(((file=open(str,O_BINARY|share|access,S_IWRITE))==-1)
  29.     && errno==EACCES && count++<LOOP_NOPEN)
  30. #ifndef __OS2__
  31.     if(count>10)
  32.         delay(50);
  33. #else
  34.     ;
  35. #endif
  36. if(file==-1 && errno==EACCES)
  37.     puts("\7\r\nNOPEN: ACCESS DENIED\r\n\7");
  38. return(file);
  39. }
  40.  
  41. /****************************************************************************/
  42. /* Converts a date string in format MM/DD/YY into unix time format            */
  43. /****************************************************************************/
  44. time_t dstrtounix(char *str)
  45. {
  46.     struct time curtime;
  47.     struct date date;
  48.  
  49. if(!strcmp(str,"00/00/00"))
  50.     return(0);
  51. curtime.ti_hour=curtime.ti_min=curtime.ti_sec=0;
  52. if(str[6]<7)
  53.     date.da_year=2000+((str[6]&0xf)*10)+(str[7]&0xf);
  54. else
  55.     date.da_year=1900+((str[6]&0xf)*10)+(str[7]&0xf);
  56. date.da_mon=((str[0]&0xf)*10)+(str[1]&0xf);
  57. date.da_day=((str[3]&0xf)*10)+(str[4]&0xf);
  58. return(dostounix(&date,&curtime));
  59. }
  60.  
  61. /****************************************************************************/
  62. /* Converts unix time format (long - time_t) into a char str MM/DD/YY        */
  63. /****************************************************************************/
  64. char *unixtodstr(time_t unix, char *str)
  65. {
  66.     struct time curtime;
  67.     struct date date;
  68.  
  69. if(!unix)
  70.     strcpy(str,"00/00/00");
  71. else {
  72.     unixtodos(unix,&date,&curtime);
  73.     if((unsigned)date.da_mon>12) {      /* DOS leap year bug */
  74.         date.da_mon=1;
  75.         date.da_year++; }
  76.     if((unsigned)date.da_day>31)
  77.         date.da_day=1;
  78.     sprintf(str,"%02u/%02u/%02u",date.da_mon,date.da_day
  79.         ,date.da_year>=2000 ? date.da_year-2000 : date.da_year-1900); }
  80. return(str);
  81. }
  82.  
  83.  
  84. int main(int argc, char **argv)
  85. {
  86.     char ch, str[512], path[256]
  87.         ,*lst="%c) %-25s: %13lu\n"
  88.         ,*nv="\nNew value: ";
  89.     int file;
  90.     stats_t stats;
  91.     time_t t;
  92.  
  93. if(argc>1)
  94.     strcpy(path,argv[1]);
  95. else
  96.     getcwd(path,MAXDIR);
  97. if(path[strlen(path)-1]!='\\')
  98.     strcat(path,"\\");
  99.  
  100. sprintf(str,"%sDSTS.DAB",path);
  101. if((file=nopen(str,O_RDONLY))==-1) {
  102.     printf("Can't open %s\r\n",str);
  103.     exit(1); }
  104. read(file,&t,4L);
  105. if(read(file,&stats,sizeof(stats_t))!=sizeof(stats_t)) {
  106.     close(file);
  107.     printf("Error reading %u bytes from %s\r\n",sizeof(stats_t),str);
  108.     exit(1); }
  109. close(file);
  110. while(1) {
  111.     clrscr();
  112.     printf("Synchronet Daily Statistics Editor v1.01\r\n\r\n");
  113.     printf("S) %-25s: %13s\n","Date Stamp",unixtodstr(t,str));
  114.     printf(lst,'L',"Total Logons",stats.logons);
  115.     printf(lst,'O',"Logons Today",stats.ltoday);
  116.     printf(lst,'T',"Total Time on",stats.timeon);
  117.     printf(lst,'I',"Time on Today",stats.ttoday);
  118.     printf(lst,'U',"Uploaded Files Today",stats.uls);
  119.     printf(lst,'B',"Uploaded Bytes Today",stats.ulb);
  120.     printf(lst,'D',"Downloaded Files Today",stats.dls);
  121.     printf(lst,'W',"Downloaded Bytes Today",stats.dlb);
  122.     printf(lst,'P',"Posts Today",stats.ptoday);
  123.     printf(lst,'E',"E-Mails Today",stats.etoday);
  124.     printf(lst,'F',"Feedback Today",stats.ftoday);
  125.     printf("%c) %-25s: %13u\r\n",'N',"New Users Today",stats.nusers);
  126.  
  127.     printf("Q) Quit and save changes\r\n");
  128.     printf("X) Quit and don't save changes\r\n");
  129.  
  130.     printf("\r\nWhich: ");
  131.  
  132.     ch=toupper(getch());
  133.     printf("%c\r\n",ch);
  134.  
  135.     switch(ch) {
  136.         case 'S':
  137.             printf("Date stamp (MM/DD/YY): ");
  138.             gets(str);
  139.             if(str[0])
  140.                 t=dstrtounix(str);
  141.             break;
  142.         case 'L':
  143.             printf(nv);
  144.             gets(str);
  145.             if(str[0])
  146.                 stats.logons=atol(str);
  147.             break;
  148.         case 'O':
  149.             printf(nv);
  150.             gets(str);
  151.             if(str[0])
  152.                 stats.ltoday=atol(str);
  153.             break;
  154.         case 'T':
  155.             printf(nv);
  156.             gets(str);
  157.             if(str[0])
  158.                 stats.timeon=atol(str);
  159.             break;
  160.         case 'I':
  161.             printf(nv);
  162.             gets(str);
  163.             if(str[0])
  164.                 stats.ttoday=atol(str);
  165.             break;
  166.         case 'U':
  167.             printf(nv);
  168.             gets(str);
  169.             if(str[0])
  170.                 stats.uls=atol(str);
  171.             break;
  172.         case 'B':
  173.             printf(nv);
  174.             gets(str);
  175.             if(str[0])
  176.                 stats.ulb=atol(str);
  177.             break;
  178.         case 'D':
  179.             printf(nv);
  180.             gets(str);
  181.             if(str[0])
  182.                 stats.dls=atol(str);
  183.             break;
  184.         case 'W':
  185.             printf(nv);
  186.             gets(str);
  187.             if(str[0])
  188.                 stats.dlb=atol(str);
  189.             break;
  190.         case 'P':
  191.             printf(nv);
  192.             gets(str);
  193.             if(str[0])
  194.                 stats.ptoday=atol(str);
  195.             break;
  196.         case 'E':
  197.             printf(nv);
  198.             gets(str);
  199.             if(str[0])
  200.                 stats.etoday=atol(str);
  201.             break;
  202.         case 'F':
  203.             printf(nv);
  204.             gets(str);
  205.             if(str[0])
  206.                 stats.ftoday=atol(str);
  207.             break;
  208.         case 'N':
  209.             printf(nv);
  210.             gets(str);
  211.             if(str[0])
  212.                 stats.nusers=atoi(str);
  213.             break;
  214.         case 'Q':
  215.             sprintf(str,"%sDSTS.DAB",path);
  216.             if((file=nopen(str,O_WRONLY))==-1) {
  217.                 printf("Error opening %s\r\n",str);
  218.                 exit(1); }
  219.             write(file,&t,4L);
  220.             write(file,&stats,sizeof(stats_t));
  221.             close(file);
  222.         case 'X':
  223.             exit(0);
  224.         default:
  225.             putchar(7);
  226.             break; } }
  227. }
  228.