Annotation of sbbs/sbbs2/smb/121a/fixsmb.c, revision 1.1.1.1

1.1       root        1: /* FIXSMB.C */
                      2: 
                      3: /* Re-generates an SMB message base based on SHD and SDT files */
                      4: 
                      5: #include "smblib.h"
                      6: 
                      7: char *usage="usage: fixsmb [/opts] <smb_file>\n"
                      8:                        "\n"
                      9:                        " opts:\n"
                     10:                        "       m - force mail format instead of sub-board format\n"
                     11:                        "\n"
                     12:                        "   ex: FIXSMB /M MAIL\n"
                     13:                        "   or: FIXSMB DEBATE\n";
                     14: 
                     15: void remove_re(char *str)
                     16: {
                     17: while(!strnicmp(str,"RE:",3)) {
                     18:        strcpy(str,str+3);
                     19:        while(str[0]==SP)
                     20:                strcpy(str,str+1); }
                     21: }
                     22: 
                     23: /****************************************************************************/
                     24: /* Updates 16-bit "rcrc" with character 'ch'                                */
                     25: /****************************************************************************/
                     26: void ucrc16(uchar ch, ushort *rcrc) {
                     27:        ushort i, cy;
                     28:     uchar nch=ch;
                     29:  
                     30: for (i=0; i<8; i++) {
                     31:     cy=*rcrc & 0x8000;
                     32:     *rcrc<<=1;
                     33:     if (nch & 0x80) *rcrc |= 1;
                     34:     nch<<=1;
                     35:     if (cy) *rcrc ^= 0x1021; }
                     36: }
                     37: 
                     38: /****************************************************************************/
                     39: /* Returns 16-crc of string (not counting terminating NULL)                            */
                     40: /****************************************************************************/
                     41: ushort crc16(char *str)
                     42: {
                     43:        int     i=0;
                     44:        ushort  crc=0;
                     45: 
                     46: ucrc16(0,&crc);
                     47: while(str[i])
                     48:        ucrc16(str[i++],&crc);
                     49: ucrc16(0,&crc);
                     50: ucrc16(0,&crc);
                     51: return(crc);
                     52: }
                     53: 
                     54: #define MAIL (1<<0)
                     55: 
                     56: int main(int argc, char **argv)
                     57: {
                     58:        char            str[128],c;
                     59:        int             i,w,mode=0;
                     60:        ulong           l,length,size,n,m;
                     61:        smbmsg_t        msg;
                     62:        smbstatus_t status;
                     63: 
                     64: printf("\nFIXSMB v1.22 � Rebuild Synchronet Message Base � Copyright 1995 "
                     65:        "Digital Dynamics\n");
                     66: 
                     67: smb_file[0]=0;
                     68: for(i=1;i<argc;i++)
                     69:        if(argv[i][0]=='/')
                     70:                switch(toupper(argv[i][1])) {
                     71:                        case 'M':
                     72:                                mode|=MAIL;
                     73:                                break;
                     74:                        default:
                     75:                                printf(usage);
                     76:                                exit(1); }
                     77:        else
                     78:                strcpy(smb_file,argv[i]);
                     79: 
                     80: if(!smb_file[0]) {
                     81:        printf(usage);
                     82:        exit(1); }
                     83: 
                     84: strupr(smb_file);
                     85: 
                     86: if((i=smb_open(10))!=0) {
                     87:        printf("smb_open returned %d\n",i);
                     88:        exit(1); }
                     89: 
                     90: if((i=smb_locksmbhdr(10))!=0) {
                     91:        smb_close();
                     92:        printf("smb_locksmbhdr returned %d\n",i);
                     93:        exit(1); }
                     94: 
                     95: if((i=smb_getstatus(&status))!=0) {
                     96:        smb_unlocksmbhdr();
                     97:        smb_close();
                     98:        printf("smb_getstatus returned %d\n",i);
                     99:        exit(1); }
                    100: 
                    101: if(mode&MAIL && !(status.attr&SMB_EMAIL)) {
                    102:        status.attr|=SMB_EMAIL;
                    103:        if((i=smb_putstatus(status))!=0) {
                    104:                smb_unlocksmbhdr();
                    105:                smb_close();
                    106:                printf("smb_putstatus returned %d\n",i);
                    107:                exit(1); } }
                    108: 
                    109: if(!(status.attr&SMB_HYPERALLOC)) {
                    110: 
                    111:        if((i=smb_open_ha(10))!=0) {
                    112:                smb_close();
                    113:                printf("smb_open_ha returned %d\n",i);
                    114:                exit(1); }
                    115: 
                    116:        if((i=smb_open_da(10))!=0) {
                    117:                smb_close();
                    118:                printf("smb_open_da returned %d\n",i);
                    119:                exit(1); }
                    120: 
                    121:        rewind(sha_fp);
                    122:        chsize(fileno(sha_fp),0L);                      /* Truncate the header allocation file */
                    123:        rewind(sda_fp);
                    124:        chsize(fileno(sda_fp),0L);                      /* Truncate the data allocation file */
                    125:        }
                    126: 
                    127: rewind(sid_fp);
                    128: chsize(fileno(sid_fp),0L);                     /* Truncate the index */
                    129: 
                    130: 
                    131: if(!(status.attr&SMB_HYPERALLOC)) {
                    132:        length=filelength(fileno(sdt_fp));
                    133:        w=0;
                    134:        for(l=0;l<length;l+=SDT_BLOCK_LEN)      /* Init .SDA file to NULL */
                    135:                fwrite(&w,2,1,sda_fp);
                    136: 
                    137:        length=filelength(fileno(shd_fp));
                    138:        c=0;
                    139:        for(l=0;l<length;l+=SHD_BLOCK_LEN)      /* Init .SHD file to NULL */
                    140:                fwrite(&c,1,1,sha_fp); }
                    141: else
                    142:        length=filelength(fileno(shd_fp));
                    143: 
                    144: n=1;   /* messsage number */
                    145: for(l=status.header_offset;l<length;l+=size) {
                    146:        printf("\r%2u%%  ",(long)(100.0/((float)length/l)));
                    147:        msg.idx.offset=l;
                    148:        if((i=smb_lockmsghdr(msg,10))!=0) {
                    149:                printf("\n(%06lX) smb_lockmsghdr returned %d\n",l,i);
                    150:                continue; }
                    151:        if((i=smb_getmsghdr(&msg))!=0) {
                    152:                smb_unlockmsghdr(msg);
                    153:                printf("\n(%06lX) smb_getmsghdr returned %d\n",l,i);
                    154:                size=SHD_BLOCK_LEN;
                    155:                continue; }
                    156:        smb_unlockmsghdr(msg);
                    157:        printf("#%-5lu (%06lX) %-25.25s ",msg.hdr.number,l,msg.from);
                    158:        if(!(msg.hdr.attr&MSG_DELETE)) {   /* Don't index deleted messages */
                    159:                msg.offset=n-1;
                    160:                msg.hdr.number=n;
                    161:                msg.idx.number=n;
                    162:                msg.idx.attr=msg.hdr.attr;
                    163:                msg.idx.time=msg.hdr.when_imported.time;
                    164:                strcpy(str,msg.subj);
                    165:                strlwr(str);
                    166:                remove_re(str);
                    167:                msg.idx.subj=crc16(str);
                    168:                if(status.attr&SMB_EMAIL) {
                    169:                        if(msg.to_ext)
                    170:                                msg.idx.to=atoi(msg.to_ext);
                    171:                        else
                    172:                                msg.idx.to=0;
                    173:                        if(msg.from_ext)
                    174:                                msg.idx.from=atoi(msg.from_ext);
                    175:                        else
                    176:                                msg.idx.from=0; }
                    177:                else {
                    178:                        strcpy(str,msg.to);
                    179:                        strlwr(str);
                    180:                        msg.idx.to=crc16(str);
                    181:                        strcpy(str,msg.from);
                    182:                        strlwr(str);
                    183:                        msg.idx.from=crc16(str); }
                    184:                if((i=smb_putmsg(msg))!=0) {
                    185:                        printf("\nsmb_putmsg returned %d\n",i);
                    186:                        continue; }
                    187:                n++; }
                    188:        else
                    189:                printf("Not indexing deleted message\n");
                    190:        size=smb_getmsghdrlen(msg);
                    191:        while(size%SHD_BLOCK_LEN)
                    192:                size++;
                    193: 
                    194:        if(!(status.attr&SMB_HYPERALLOC)) {
                    195:                /**************************/
                    196:                /* Allocate header blocks */
                    197:                /**************************/
                    198:                fseek(sha_fp,(l-status.header_offset)/SHD_BLOCK_LEN,SEEK_SET);
                    199:                if(msg.hdr.attr&MSG_DELETE) c=0;                /* mark as free */
                    200:                else c=1;                                                               /* or allocated */
                    201: 
                    202:                for(i=0;i<size/SHD_BLOCK_LEN;i++)
                    203:                        fputc(c,sha_fp);
                    204: 
                    205:                /************************/
                    206:                /* Allocate data blocks */
                    207:                /************************/
                    208: 
                    209:                if(!(msg.hdr.attr&MSG_DELETE))
                    210:                        smb_incdat(msg.hdr.offset,smb_getmsgdatlen(msg),1);
                    211:                }
                    212: 
                    213:        smb_freemsgmem(msg); }
                    214: printf("\nDone.\n");
                    215: status.total_msgs=status.last_msg=n-1;
                    216: if((i=smb_putstatus(status))!=0)
                    217:        printf("\nsmb_putstatus returned %d\n",i);
                    218: smb_unlocksmbhdr();
                    219: smb_close();
                    220: return(0);
                    221: }

unix.superglobalmegacorp.com

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