Everhart, Glenn From: helbig@man.ac.uk Sent: Thursday, January 28, 1999 7:04 AM To: Info-VAX@Mvb.Saic.Com Subject: decode .rtf files on VMS Thanks to the source code below (got from someone in this newsgroup a while back) I can decode b64 encoded stuff. However, sometimes what is encoded is an RTF file, which I cannot read. I seem to remember that someone said there is a program for VMS which will convert RTF files to a readable format. (I just loaded this by-hand decoded file into WORD on an NT PC (shudder, shudder) and it looked OK and printed out fine.) Anyone know where I can get this? Will it do just text or graphics as well? -- Phillip Helbig Email ......... p.helbig@jb.man.ac.uk Nuffield Radio Astronomy Laboratories Tel. .... +44 1477 571 321 (ext. 297) Jodrell Bank Fax ................ +44 1477 571 618 Macclesfield Telex ................ 36149 JODREL G UK-Cheshire SK11 9DL Web ... http://www.jb.man.ac.uk/~pjh/ ---------8<-------------------------------------------------------------------- #include #include #include int decode_b64char( int ch ) { int sextet; if( ('A' <= ch) && (ch <= 'Z') ) sextet = ch - 'A'; else if( ('a' <= ch) && (ch <= 'z') ) sextet = (ch - 'a') + 26; else if( ('0' <= ch) && (ch <= '9') ) sextet = (ch - '0') + 52; else if( ch == '+' ) sextet = 62; else if( ch == '/' ) sextet = 63; else { fprintf( stderr, (isprint(ch) ? "Illegal base64 character '%c'\n" : "Illegal base64 character 0x%02x\n"), ch ); exit( EXIT_FAILURE ); } return( sextet ); } main( int argc, char *argv[] ) { FILE *fin; FILE *fout; int flushing = 0; int temp = 0; int bits = 0; int ch; if( argc < 2 ) { fprintf( stderr, "Usage: b64decode [outfile]\n" ); exit( EXIT_SUCCESS ); } fin = fopen( argv[1], "r" ); if( fin == NULL ) { perror( "openin" ); exit( EXIT_FAILURE ); } if( argc < 3 ) fout = stdout; else { fout = fopen( argv[2], "wb" ); if( fout == NULL ) { perror( "openout" ); fclose( fin ); exit( EXIT_FAILURE ); } } while( (ch = fgetc( fin )) != EOF ) { if( isspace(ch) ) continue; if( flushing ) { if( ch != '=' ) { fprintf( stderr, "Illegal character in EOF padding\n" ); exit( EXIT_FAILURE ); } } else { if( ch == '=' ) flushing = 1; else { temp <<= 6; temp |= decode_b64char( ch ); bits += 6; if( bits >= 8 ) { bits -= 8; fputc( (0xff & (temp >> bits)), fout ); } } } } fclose( fout ); fclose( fin ); } ---------8<--------------------------------------------------------------------