Annotation of sbbs/src/sbbs3/smbactiv.c, revision 1.1

1.1     ! root        1: /* SMBACTIV.C */
        !             2: 
        !             3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
        !             4: 
        !             5: #include "sbbs.h"
        !             6: 
        !             7: #define SMBACTIV_VER "1.01"
        !             8: 
        !             9: typedef struct {
        !            10:        ulong read;
        !            11:        ulong firstmsg;
        !            12: } sub_status_t;
        !            13: 
        !            14: smb_t smb;
        !            15: 
        !            16: ulong first_msg()
        !            17: {
        !            18:        smbmsg_t msg;
        !            19: 
        !            20: msg.offset=0;
        !            21: msg.hdr.number=0;
        !            22: if(smb_getmsgidx(&smb,&msg))                   /* Get first message index */
        !            23:        return(0);
        !            24: return(msg.idx.number);
        !            25: }
        !            26: 
        !            27: long lputs(char *str)
        !            28: {
        !            29:     char tmp[256];
        !            30:     int i,j,k;
        !            31: 
        !            32: j=strlen(str);
        !            33: for(i=k=0;i<j;i++)      /* remove CRs */
        !            34:     if(str[i]==CR && str[i+1]==LF)
        !            35:         continue;
        !            36:     else
        !            37:         tmp[k++]=str[i];
        !            38: tmp[k]=0;
        !            39: return(fputs(tmp,stderr));
        !            40: }
        !            41: 
        !            42: /****************************************************************************/
        !            43: /* Performs printf() through local assembly routines                        */
        !            44: /* Called from everywhere                                                   */
        !            45: /****************************************************************************/
        !            46: int lprintf(char *fmat, ...)
        !            47: {
        !            48:        va_list argptr;
        !            49:        char sbuf[256];
        !            50:        int chcount;
        !            51: 
        !            52: va_start(argptr,fmat);
        !            53: chcount=vsprintf(sbuf,fmat,argptr);
        !            54: va_end(argptr);
        !            55: lputs(sbuf);
        !            56: return(chcount);
        !            57: }
        !            58: 
        !            59: void bail(int code)
        !            60: {
        !            61: exit(code);
        !            62: }
        !            63: 
        !            64: int main(int argc, char **argv)
        !            65: {
        !            66:        char str[256],*p;
        !            67:        int i,j,file;
        !            68:        ulong l,length,max_users=0xffffffff;
        !            69:        sub_status_t *sub_status;
        !            70:        FILE *stream;
        !            71:        scfg_t  cfg;
        !            72:        glob_t  gl;
        !            73: 
        !            74: fprintf(stderr,"\nSMBACTIV Version %s (%s) - Synchronet Message Base Activity "
        !            75:        "Monitor\n", SMBACTIV_VER, PLATFORM_DESC);
        !            76: 
        !            77:        if(argc>1)
        !            78:                max_users=atol(argv[1]);
        !            79: 
        !            80:        if(!max_users) {
        !            81:                lprintf("\nusage: SMBACTIV [max_users]\n\n");
        !            82:                lprintf("max_users = limit output to subs read by this many users "
        !            83:                        "or less\n");
        !            84:                return(0); }
        !            85: 
        !            86:        p=getenv("SBBSCTRL");
        !            87:        if(p==NULL) {
        !            88:                printf("\nSBBSCTRL environment variable not set.\n");
        !            89: #ifdef __unix__
        !            90:                printf("\nExample: export SBBSCTRL=/sbbs/ctrl\n");
        !            91: #else
        !            92:                printf("\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
        !            93: #endif
        !            94:                return(1);
        !            95:        }
        !            96: 
        !            97:        memset(&cfg,0,sizeof(cfg));
        !            98:        cfg.size=sizeof(cfg);
        !            99:        SAFECOPY(cfg.ctrl_dir,p);
        !           100: 
        !           101:        if(!load_cfg(&cfg,NULL,TRUE,str)) {
        !           102:                fprintf(stderr,"!ERROR loading configuration files: %s\n",str);
        !           103:                return(1);
        !           104:        }
        !           105: 
        !           106:        chdir(cfg.ctrl_dir);
        !           107: 
        !           108:        if((sub_status=(sub_status_t *)MALLOC
        !           109:                (cfg.total_subs*sizeof(sub_status_t)))==NULL) {
        !           110:                printf("ERROR Allocating memory for sub_status\r\n");
        !           111:                return(1); }
        !           112: 
        !           113:        lprintf("\nReading sub-board ");
        !           114:        for(i=0;i<cfg.total_subs;i++) {
        !           115:                lprintf("%5d of %-5d\b\b\b\b\b\b\b\b\b\b\b\b\b\b",i+1,cfg.total_subs);
        !           116:                sprintf(smb.file,"%s%s",cfg.sub[i]->data_dir,cfg.sub[i]->code);
        !           117:                if((j=smb_open(&smb))!=0) {
        !           118:                        lprintf("Error %d opening %s\r\n",j,smb.file);
        !           119:                        sub_status[i].read=0;
        !           120:                        sub_status[i].firstmsg=0L;
        !           121:             continue; }
        !           122:                sub_status[i].read=0;
        !           123:                sub_status[i].firstmsg=first_msg();
        !           124:                smb_close(&smb); }
        !           125: 
        !           126:        sprintf(str,"%suser/ptrs/*.ixb",cfg.data_dir);
        !           127:        if(glob(str, GLOB_MARK, NULL, &gl)) {
        !           128:                lprintf("Unable to find any user pointer files.\n");
        !           129:                globfree(&gl);
        !           130:                free(sub_status);
        !           131:                return(1); }
        !           132: 
        !           133:        j=0;
        !           134:        lprintf("\nComparing user pointers ");
        !           135:        for(j=0; j<gl.gl_pathc; j++) {
        !           136:                lprintf("%-5d\b\b\b\b\b",j);
        !           137:                SAFECOPY(str,gl.gl_pathv[j]);
        !           138:                if((file=nopen(str,O_RDONLY|O_BINARY))==-1) {
        !           139:                        continue; }
        !           140:                length=filelength(file);
        !           141:                for(i=0;i<cfg.total_subs;i++) {
        !           142:                        if(sub_status[i].read>max_users)
        !           143:                                continue;
        !           144:                        if(length<(cfg.sub[i]->ptridx+1)*10L)
        !           145:                                continue;
        !           146:                        else {
        !           147:                                lseek(file,((long)cfg.sub[i]->ptridx*10L)+4L,SEEK_SET);
        !           148:                                read(file,&l,4); }
        !           149:                        if(l>sub_status[i].firstmsg)
        !           150:                                sub_status[i].read++; }
        !           151:                close(file); }
        !           152:        globfree(&gl);
        !           153: 
        !           154:        printf("NumUsers    Sub-board\n");
        !           155:        printf("--------    -------------------------------------------------"
        !           156:                "-----------\n");
        !           157:        for(i=0;i<cfg.total_subs;i++) {
        !           158:                if(sub_status[i].read>max_users)
        !           159:                        continue;
        !           160:                printf("%8lu    %-*s %-*s\n"
        !           161:                        ,sub_status[i].read
        !           162:                        ,LEN_GSNAME,cfg.grp[cfg.sub[i]->grp]->sname
        !           163:                        ,LEN_SLNAME,cfg.sub[i]->lname); }
        !           164: 
        !           165:        return(0);
        !           166: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.