Annotation of sbbs/sbbs3/smbtxt.c, revision 1.1.1.1

1.1       root        1: /* smbtxt.c */
                      2: 
                      3: /* Synchronet message base (SMB) message text library routines */
                      4: 
                      5: /* $Id: smbtxt.c,v 1.1 2000/10/29 04:50:21 rswindell Exp $ */
                      6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
                     11:  * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html         *
                     12:  *                                                                                                                                                     *
                     13:  * This library is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU Lesser General Public License          *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU Lesser General Public License for more details: lgpl.txt or     *
                     18:  * http://www.fsf.org/copyleft/lesser.html                                                                     *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: /* ANSI */
                     39: #include <malloc.h>
                     40: 
                     41: /* SMB-specific */
                     42: #include "smblib.h"
                     43: 
                     44: char HUGE16*  SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode)
                     45: {
                     46:        char    HUGE16* buf=NULL,HUGE16* lzhbuf,HUGE16* p;
                     47:        ushort  xlat;
                     48:        int     i,lzh;
                     49:        long    l=0,lzhlen,length;
                     50: 
                     51:        for(i=0;i<msg->hdr.total_dfields;i++) {
                     52:                if(!(msg->dfield[i].type==TEXT_BODY
                     53:                        || (mode&GETMSGTXT_TAILS && msg->dfield[i].type==TEXT_TAIL))
                     54:                        || msg->dfield[i].length<=2L)
                     55:                        continue;
                     56:                fseek(smb->sdt_fp,msg->hdr.offset+msg->dfield[i].offset
                     57:                        ,SEEK_SET);
                     58:                fread(&xlat,2,1,smb->sdt_fp);
                     59:                lzh=0;
                     60:                if(xlat==XLAT_LZH) {
                     61:                        lzh=1;
                     62:                        fread(&xlat,2,1,smb->sdt_fp); 
                     63:                }
                     64:                if(xlat!=XLAT_NONE)     /* no other translations currently supported */
                     65:                        continue;
                     66: 
                     67:                length=msg->dfield[i].length-2L;
                     68:                if(lzh) {
                     69:                        length-=2;
                     70:                        if(length<1)
                     71:                                continue;
                     72:                        if((lzhbuf=LMALLOC(length))==NULL) {
                     73:                                sprintf(smb->last_error
                     74:                                        ,"malloc failure of %ld bytes for LZH buffer"
                     75:                                        ,length);
                     76:                                return(buf);
                     77:                        }
                     78:                        smb_fread(lzhbuf,length,smb->sdt_fp);
                     79:                        lzhlen=*(long*)lzhbuf;
                     80:                        if((p=REALLOC(buf,l+lzhlen+3L))==NULL) {
                     81:                                sprintf(smb->last_error
                     82:                                        ,"realloc failure of %ld bytes for text buffer"
                     83:                                        ,l+lzhlen+3L);
                     84:                                FREE(lzhbuf);
                     85:                                return(buf); 
                     86:                        }
                     87:                        buf=p;
                     88:                        lzh_decode((char*)lzhbuf,length,(char*)buf+l);
                     89:                        FREE(lzhbuf);
                     90:                        l+=lzhlen; 
                     91:                }
                     92:                else {
                     93:                        if((p=REALLOC(buf,l+length+3L))==NULL) {
                     94:                                sprintf(smb->last_error
                     95:                                        ,"realloc failure of %ld bytes for text buffer"
                     96:                                        ,l+length+3L);
                     97:                                return(buf);
                     98:                        }
                     99:                        buf=p;
                    100:                        p=buf+l;
                    101:                        l+=fread(p,1,length,smb->sdt_fp);
                    102:                }
                    103:                if(!l)
                    104:                        continue;
                    105:                l--;
                    106:                while(l && buf[l]==0) l--;
                    107:                l++;
                    108:                *(buf+l)=CR;
                    109:                l++;
                    110:                *(buf+l)=LF;
                    111:                l++;
                    112:                *(buf+l)=0; 
                    113:        }
                    114:        return(buf);
                    115: }
                    116: 
                    117: void SMBCALL smb_freemsgtxt(char HUGE16* buf)
                    118: {
                    119:        if(buf!=NULL)
                    120:                FREE(buf);
                    121: }

unix.superglobalmegacorp.com

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