//&& HEADER FILE --------------------------------------------------------------
// File Name: mime64.c
// Description: Mime Based Encoding/Decoding.
// Author: Jim Gale
// Date created: 8/28/97 Date updated: þ5/1/98
// Copyright: 1998 by Gale-Force. All Rights Reserved.
// Email: jg5@gale-force.com
//-----------------------------------------------------------------------------
#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>
static char cMime[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
unsigned int at(char c1, char *c2);
CLIPPER CMIMEDEC( PARAMS )
{
int x, nIn, nLen, nOut;
unsigned short int n2, n3, n1, n4;
char far *cIn, *cOut;
cIn = _parc(1);
nIn = _parclen(1);
nLen = ((nIn+3)*3/4)+1;
cOut = ( char * ) _xgrab(nLen);
nOut = -1;
for(x=0;x<nIn;x+=4)
{
n1 = at((char) cIn[x] ,cMime);
n2 = at((char) cIn[x+1],cMime);
if ( (n3 = at((char) cIn[x+2],cMime))==64 ) {
cOut[++nOut] = (( ( n1 << 2) & 252 ) | ((n2 >> 4) & 3) );
break;
}
if ( (n4 = at((char) cIn[x+3],cMime))==64 ) {
cOut[++nOut] = (( ( n1 << 2) & 252 ) | ((n2 >> 4) & 3) );
cOut[++nOut] = (( ( n2 << 4) & 240 ) | ( (n3 >> 2) & 15) );
break;
}
cOut[++nOut] = (( ( n1 << 2) & 252 ) | ((n2 >> 4) & 3) );
cOut[++nOut] = (( ( n2 << 4) & 240 ) | ( (n3 >> 2) & 15) );
cOut[++nOut] = (( ( n3 << 6) & 192 ) | ( n4 & 63) );
}
_retclen( cOut, nOut+1 );
_xfree( cOut );
}
unsigned int at(char c1, char *c2)
{
int x=-1,nLen;
nLen = 65; //sizeof(c2);
while(++x<nLen)
{
if( (char) c1 == (char) c2[x] )
return x;
}
return 0;
}
CLIPPER CMIMEENC( PARAMS )
{
int x, nIn, nLen, nOut;
unsigned short int n2, n3, n1, n4, nA1, nA2, nA3;
char far *cIn, *cOut;
cIn = _parc(1);
nIn = _parclen(1);
nLen = ((nIn+2)*4/3)+1;
cOut = ( char * ) _xgrab(nLen);
nOut = -1;
for(x=0;x<nIn;x+=3)
{
switch ( nIn-x )
{
case 1 :
nA1 = ((char) (cIn[x ]));
n1 = ( ( nA1 >> 2) & 63 );
n2 = ( ( nA1 << 4) & 48 );
cOut[++nOut] = (char) cMime[n1];
cOut[++nOut] = (char) cMime[n2];
cOut[++nOut] = '=';
cOut[++nOut] = '=';
break;
case 2 :
nA1 = ((char) (cIn[x ]));
nA2 = ((char) (cIn[x+1]));
n1 = ( ( nA1 >> 2) & 63 );
n2 = ( ( ( nA1 << 4) & 48 ) | ( ( nA2 & 240 ) >> 4 ) );
n3 = ( ( ( nA2 << 4) & 240 ) >> 2 );
cOut[++nOut] = (char) cMime[n1];
cOut[++nOut] = (char) cMime[n2];
cOut[++nOut] = (char) cMime[n3];
cOut[++nOut] = '=';
break;
default:
nA1 = ((char) (cIn[x ]));
nA2 = ((char) (cIn[x+1]));
nA3 = ((char) (cIn[x+2]));
n1 = ( ( nA1 >> 2) & 63 );
n2 = ( ( ( nA1 << 4) & 48 ) | ( ( nA2 & 240 ) >> 4 ) );
n3 = ( ( ( ( nA2 << 4) & 240 ) >> 2 ) | ( ( nA3 >> 6 ) & 3 ) );
n4 = ( nA3 & 63 );
cOut[++nOut] = (char) cMime[n1];
cOut[++nOut] = (char) cMime[n2];
cOut[++nOut] = (char) cMime[n3];
cOut[++nOut] = (char) cMime[n4];
}
}
cOut[nOut+1] = 0;
_retclen( cOut, nOut+1 );
_xfree( cOut );
}
Return to FiveWin para CA-Clipper
Users browsing this forum: No registered users and 5 guests