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

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

unix.superglobalmegacorp.com

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