Annotation of sbbs/sbbs2/msgtoqwk.c, revision 1.1

1.1     ! root        1: #line 1 "MSGTOQWK.C"
        !             2: 
        !             3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
        !             4: 
        !             5: #include "sbbs.h"
        !             6: #include "qwk.h"
        !             7: #include "etext.h"
        !             8: 
        !             9: /****************************************************************************/
        !            10: /* Converts message 'msg' to QWK format, writing to file 'qwk_fp'.          */
        !            11: /* mode determines how to handle Ctrl-A codes                                                          */
        !            12: /****************************************************************************/
        !            13: ulong msgtoqwk(smbmsg_t msg, FILE *qwk_fp, int mode, int subnum
        !            14:        , int conf)
        !            15: {
        !            16:        uchar   str[512],from[512],to[512],ch,tear=0,tearwatch=0,HUGE16 *buf,*p;
        !            17:        ushort  xlat;
        !            18:        long    l,size=0,offset;
        !            19:        int     i;
        !            20: 
        !            21: offset=ftell(qwk_fp);
        !            22: memset(str,SP,128);
        !            23: fwrite(str,128,1,qwk_fp);              /* Init header to space */
        !            24: 
        !            25: if(msg.from_net.addr && (uint)subnum==INVALID_SUB) {
        !            26:        if(mode&TO_QNET)
        !            27:                sprintf(from,"%.128s",msg.from);
        !            28:        else if(msg.from_net.type==NET_FIDO)
        !            29:                sprintf(from,"%.128s@%.128s"
        !            30:                        ,msg.from,faddrtoa(*(faddr_t *)msg.from_net.addr));
        !            31:        else if(msg.from_net.type==NET_INTERNET)
        !            32:                sprintf(from,"%.128s",msg.from_net.addr);
        !            33:        else
        !            34:                sprintf(from,"%.128s@%.128s",msg.from,msg.from_net.addr);
        !            35:        if(strlen(from)>25) {
        !            36:                sprintf(str,"From: %.128s\xe3\xe3",from);
        !            37:                fwrite(str,strlen(str),1,qwk_fp);
        !            38:                size+=strlen(str);
        !            39:                sprintf(from,"%.128s",msg.from); } }
        !            40: else {
        !            41:        sprintf(from,"%.128s",msg.from);
        !            42:        if(msg.hdr.attr&MSG_ANONYMOUS && !SYSOP)           /* from user */
        !            43:                strcpy(from,text[Anonymous]); }
        !            44: 
        !            45: if(msg.to_net.addr && (uint)subnum==INVALID_SUB) {
        !            46:        if(msg.to_net.type==NET_FIDO)
        !            47:                sprintf(to,"%.128s@%s",msg.to,faddrtoa(*(faddr_t *)msg.to_net.addr));
        !            48:        else if(msg.to_net.type==NET_INTERNET)
        !            49:                sprintf(to,"%.128s",msg.to_net.addr);
        !            50:        else if(msg.to_net.type==NET_QWK) {
        !            51:                if(mode&TO_QNET) {
        !            52:                        p=strchr(msg.to_net.addr,'/');
        !            53:                        if(p) {         /* Another hop */
        !            54:                                p++;
        !            55:                                strcpy(to,"NETMAIL");
        !            56:                                sprintf(str,"%.128s@%.128s\xe3",msg.to,p);
        !            57:                                fwrite(str,strlen(str),1,qwk_fp);
        !            58:                                size+=strlen(str); }
        !            59:                        else
        !            60:                                sprintf(to,"%.128s",msg.to); }
        !            61:                else
        !            62:                        sprintf(to,"%.128s@%.128s",msg.to,msg.to_net.addr); }
        !            63:        else
        !            64:                sprintf(to,"%.128s@%.128s",msg.to,msg.to_net.addr);
        !            65:        if(strlen(to)>25) {
        !            66:                sprintf(str,"To: %.128s\xe3\xe3",to);
        !            67:                fwrite(str,strlen(str),1,qwk_fp);
        !            68:                size+=strlen(str);
        !            69:                if(msg.to_net.type==NET_QWK)
        !            70:                        strcpy(to,"NETMAIL");
        !            71:                else
        !            72:                        sprintf(to,"%.128s",msg.to); } }
        !            73: else
        !            74:        sprintf(to,"%.128s",msg.to);
        !            75: 
        !            76: if(msg.from_net.type==NET_QWK && mode&VIA && !msg.forwarded) {
        !            77:        sprintf(str,"@VIA:%.128s\xe3",msg.from_net.addr);
        !            78:        fwrite(str,strlen(str),1,qwk_fp);
        !            79:        size+=strlen(str); }
        !            80: 
        !            81: if(msg.hdr.when_written.zone && mode&TZ) {
        !            82:        sprintf(str,"@TZ:%04x\xe3",msg.hdr.when_written.zone);
        !            83:        fwrite(str,strlen(str),1,qwk_fp);
        !            84:        size+=strlen(str); }
        !            85: 
        !            86: p=0;
        !            87: for(i=0;i<msg.total_hfields;i++) {
        !            88:        if(msg.hfield[i].type==SENDER)
        !            89:                p=msg.hfield_dat[i];
        !            90:        if(msg.hfield[i].type==FORWARDED && p) {
        !            91:                sprintf(str,"Forwarded from %s on %s\xe3",p
        !            92:                        ,timestr((time_t *)msg.hfield_dat[i]));
        !            93:                fwrite(str,strlen(str),1,qwk_fp);
        !            94:                size+=strlen(str); } }
        !            95: 
        !            96: buf=smb_getmsgtxt(&smb,&msg,1);
        !            97: if(!buf)
        !            98:        return(0);
        !            99: 
        !           100: for(l=0;buf[l];l++) {
        !           101:        ch=buf[l];
        !           102: 
        !           103:        if(ch==LF) {
        !           104:                if(tear)
        !           105:                        tear++;                                 /* Count LFs after tearline */
        !           106:                if(tear>3)                                      /* more than two LFs after the tear */
        !           107:                        tear=0;
        !           108:                if(tearwatch==4) {                      /* watch for LF---LF */
        !           109:                        tear=1;
        !           110:                        tearwatch=0; }
        !           111:                else if(!tearwatch)
        !           112:                        tearwatch=1;
        !           113:                else
        !           114:                        tearwatch=0;
        !           115:                ch=0xe3;
        !           116:                fputc(ch,qwk_fp);                 /* Replace LF with funky char */
        !           117:                size++;
        !           118:                continue; }
        !           119: 
        !           120:        if(ch==CR) {                                    /* Ignore CRs */
        !           121:                if(tearwatch<4)                         /* LF---CRLF is okay */
        !           122:                        tearwatch=0;                    /* LF-CR- is not okay */
        !           123:                continue; }
        !           124: 
        !           125:        if(ch==SP && tearwatch==4) {    /* watch for "LF--- " */
        !           126:                tear=1;
        !           127:                tearwatch=0; }
        !           128: 
        !           129:        if(ch=='-') {                   /* watch for "LF---" */
        !           130:                if(l==0 || (tearwatch && tearwatch<4))
        !           131:                        tearwatch++;
        !           132:                else
        !           133:                        tearwatch=0; }
        !           134:        else
        !           135:                tearwatch=0;
        !           136: 
        !           137:        if((uint)subnum!=INVALID_SUB && sub[subnum]->misc&SUB_ASCII) {
        !           138:                if(ch<SP && ch!=1)
        !           139:                        ch='.';
        !           140:                else if(ch>0x7f)
        !           141:                        ch='*'; }
        !           142: 
        !           143:        if(ch==0xE3)                                    /* funky char */
        !           144:                ch='*';
        !           145: 
        !           146:        if(ch==1) {  /* ctrl-a */
        !           147:                ch=buf[++l];
        !           148:                if(!ch)
        !           149:                        break;
        !           150:                if(mode&A_EXPAND) {
        !           151:                        str[0]=0;
        !           152:                        switch(toupper(ch)) {           /* non-color codes */
        !           153:                                case 'L':
        !           154:                                        strcpy(str,"\x1b[2J");
        !           155:                                        break;
        !           156:                                case 'W':
        !           157:                                        strcpy(str,ansi(LIGHTGRAY));
        !           158:                                        break;
        !           159:                                case 'K':
        !           160:                                        strcpy(str,ansi(BLACK));
        !           161:                                        break;
        !           162:                                case 'H':
        !           163:                                        strcpy(str,ansi(HIGH));
        !           164:                                        break;
        !           165:                                case 'I':
        !           166:                                        strcpy(str,ansi(BLINK));
        !           167:                                        break;
        !           168:                                case 'N':   /* Normal */
        !           169:                                        strcpy(str,"\x1b[0m");
        !           170:                                        break;
        !           171:                                case '0':
        !           172:                                        strcpy(str,"\x1b[40m");
        !           173:                                        break;
        !           174:                                case '7':
        !           175:                                        strcpy(str,ansi(LIGHTGRAY<<4));
        !           176:                                        break;
        !           177:                                case 'R':                               /* Color codes */
        !           178:                                        strcpy(str,ansi(RED));
        !           179:                                        break;
        !           180:                                case 'G':
        !           181:                                        strcpy(str,ansi(GREEN));
        !           182:                                        break;
        !           183:                                case 'B':
        !           184:                                        strcpy(str,ansi(BLUE));
        !           185:                                        break;
        !           186:                                case 'C':
        !           187:                                        strcpy(str,ansi(CYAN));
        !           188:                                        break;
        !           189:                                case 'M':
        !           190:                                        strcpy(str,ansi(MAGENTA));
        !           191:                                        break;
        !           192:                                case 'Y':   /* Yellow */
        !           193:                                        strcpy(str,ansi(BROWN));
        !           194:                                        break;
        !           195:                                case '1':
        !           196:                                        strcpy(str,ansi(RED<<4));
        !           197:                                        break;
        !           198:                                case '2':
        !           199:                                        strcpy(str,ansi(GREEN<<4));
        !           200:                                        break;
        !           201:                                case '3':
        !           202:                                        strcpy(str,ansi(BROWN<<4));
        !           203:                                        break;
        !           204:                                case '4':
        !           205:                                        strcpy(str,ansi(BLUE<<4));
        !           206:                                        break;
        !           207:                                case '5':
        !           208:                                        strcpy(str,ansi(MAGENTA<<4));
        !           209:                                        break;
        !           210:                                case '6':
        !           211:                                        strcpy(str,ansi(CYAN<<4));
        !           212:                                        break; }
        !           213:                        if(str[0]) {
        !           214:                                fwrite(str,strlen(str),1,qwk_fp);
        !           215:                                size+=strlen(str); }
        !           216:                        continue; }                                             /* End Expand */
        !           217: 
        !           218:                if(mode&A_LEAVE) {
        !           219:                        fputc(1,qwk_fp);
        !           220:                        fputc(ch,qwk_fp);
        !           221:                        size+=2L; }
        !           222:                else                                                                    /* Strip */
        !           223:                        if(toupper(ch)=='L') {
        !           224:                                fputc(FF,qwk_fp);
        !           225:                                size++; }
        !           226:                continue; }                                                     /* End of Ctrl-A shit */
        !           227:        fputc(ch,qwk_fp);
        !           228:        size++; }
        !           229: 
        !           230: LFREE(buf);
        !           231: if(ch!=0xE3) {
        !           232:        fputc(0xE3,qwk_fp);             /* make sure it ends in CRLF */
        !           233:        size++; }
        !           234: 
        !           235: if(mode&TAGLINE && !(sub[subnum]->misc&SUB_NOTAG)) {
        !           236:        if(!tear)                                                                               /* no tear line */
        !           237:                strcpy(str,"\1n---\xe3");                   /* so add one */
        !           238:     else
        !           239:                strcpy(str,"\1n");
        !           240:        if(sub[subnum]->misc&SUB_ASCII) ch='*';
        !           241:        else ch='�';
        !           242:        sprintf(tmp," %c \1g%s\1n %c %.127s\xe3"
        !           243:                ,ch,decrypt(Synchronet,0),ch,sub[subnum]->tagline);
        !           244:        strcat(str,tmp);
        !           245:        if(!(mode&A_LEAVE))
        !           246:                remove_ctrl_a(str);
        !           247:        fwrite(str,strlen(str),1,qwk_fp);
        !           248:        size+=strlen(str); }
        !           249: 
        !           250: while(size%128L) {                              /* Pad with spaces */
        !           251:        size++;
        !           252:        fputc(SP,qwk_fp); }
        !           253: 
        !           254: unixtodos(msg.hdr.when_written.time,&date,&curtime);
        !           255: 
        !           256: sprintf(tmp,"%02u-%02u-%02u%02u:%02u"
        !           257:     ,date.da_mon,date.da_day,date.da_year-1900
        !           258:     ,curtime.ti_hour,curtime.ti_min);
        !           259: 
        !           260: if(msg.hdr.attr&MSG_PRIVATE) {
        !           261:     if(msg.hdr.attr&MSG_READ)
        !           262:         ch='*'; /* private, read */
        !           263:     else
        !           264:         ch='+'; /* private, unread */ }
        !           265: else {
        !           266:     if(msg.hdr.attr&MSG_READ)
        !           267:         ch='-'; /* public, read */
        !           268:     else
        !           269:         ch=' '; /* public, unread */ }
        !           270: 
        !           271: 
        !           272: sprintf(str,"%c%-7lu%-13.13s%-25.25s"
        !           273:        "%-25.25s%-25.25s%12s%-8lu%-6lu\xe1%c%c%c%c%c"
        !           274:     ,ch                     /* message status flag */
        !           275:        ,mode&REP ? (ulong)conf /* conference or */
        !           276:                : msg.hdr.number        /* message number */
        !           277:        ,tmp                                    /* date and time */
        !           278:        ,to                                     /* To: */
        !           279:        ,from                                   /* From: */
        !           280:     ,msg.subj               /* Subject */
        !           281:     ,nulstr                 /* Password */
        !           282:     ,msg.hdr.thread_orig    /* Message Re: Number */
        !           283:        ,(size/128L)+1                  /* Number of 128byte blocks */
        !           284:     ,(char)conf&0xff        /* Conference number lo byte */
        !           285:        ,(ushort)conf>>8                /*                                       hi byte */
        !           286:     ,SP                     /* not used */
        !           287:     ,SP                     /* not used */
        !           288:     ,useron.rest&FLAG('Q') ? '*' : SP     /* Net tag line */
        !           289:     );
        !           290: 
        !           291: fseek(qwk_fp,offset,SEEK_SET);
        !           292: fwrite(str,128,1,qwk_fp);
        !           293: fseek(qwk_fp,size,SEEK_CUR);
        !           294: 
        !           295: return(size);
        !           296: }

unix.superglobalmegacorp.com

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