Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SHARING] Base 64 Encoder

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SHARING] Base 64 Encoder
 Login/Join
 
Expert
posted
Here is something that I created, more as a challenge, rather than being usefile.

This is purely WebFOCUS code only.

It will encode a file available in an app directory as a Base64 encoded file.

Perhaps it will give someone a bit of a laugh...

-*******************************************************************************
-*  Report Title    : Base 64 Encoder
-*  Procedure Name  : BASE64
-*  Report Id       : N/A
-*  Author          : Warren Hinchliffe
-*  Date            : September 2009
-*******************************************************************************
-* Input Parms - See defaults below...
-*******************************************************************************
-* Comments
-*
-*******************************************************************************
-* Change History
-* DD/MM/YYYY - xx - CC  - Description (xx = Initials)
-*******************************************************************************
-SET &TMP_APP  = 'DEVFEX' ;
-SET &TMP_SRCE = 'testfile' ;
-SET &B64_OUT  = 'testfile.b64' ;

APP QUERY &TMP_APP HOLD

-RUN

TABLE   FILE FOCAPPQ
 PRINT  SIZE
 WHERE  FILENAME EQ '&TMP_SRCE'
 ON     TABLE SAVE AS SAV_SIZE
END

-RUN

-IF &LINES EQ 0 THEN GOTO NO_FILE ;

-READ SAV_SIZE &FILESIZE.A12.

-SET &Rem_Octets = IMOD(&FILESIZE,3,'I1') ;
-SET &Padding    = DECODE &Rem_Octets(1 '==' 2 '=' 0 '') ;

FILEDEF TMP_SRCE DISK &TMP_APP/&TMP_SRCE (RECFM F LRECL 1
FILEDEF B64_OUT  DISK &B64_OUT

-RUN

-* Write out a master to read the TMP_SRCE file
EX -LINES 4 EDAPUT MASTER,TMP_SRCE,CV,FILE
FILENAME=TMP_SRCE, SUFFIX=FIX,$
SEGNAME=TMP_SRCE, $
  FIELD=CHAR ,ALIAS=  ,A1 ,A1 ,$

-RUN

DEFINE FUNCTION B64_CHAR/A1 (BIT1/I1,BIT2/I1,BIT3/I1,BIT4/I1,BIT5/I1,BIT6/I1)
 Num/I2     = (BIT6 *  1) + (BIT5 *  2) + (BIT4 *  4) + 
              (BIT3 *  8) + (BIT2 * 16) + (BIT1 * 32) + 1 ;
 BASE64/A64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ;
 B64_CHAR/A1= SUBSTR(64,BASE64,Num,Num,1,'A1') ;
END

DEFINE  FILE TMP_SRCE
 Cntr/I9     = LAST Cntr + 1 ;
 BytBit/I9   = IF LAST BytBit EQ 3 THEN 1 ELSE LAST BytBit + 1 ;
 HEXCHAR/A2  = UFMT(CHAR, 1, HEXCHAR) ;
 Bit1/I1     = BITSON (1, CHAR, Bit1) ;
 Bit2/I1     = BITSON (2, CHAR, Bit2) ;
 Bit3/I1     = BITSON (3, CHAR, Bit3) ;
 Bit4/I1     = BITSON (4, CHAR, Bit4) ;
 Bit5/I1     = BITSON (5, CHAR, Bit5) ;
 Bit6/I1     = BITSON (6, CHAR, Bit6) ;
 Bit7/I1     = BITSON (7, CHAR, Bit7) ;
 Bit8/I1     = BITSON (8, CHAR, Bit8) ;

 LstRec/I1   = IF Cntr EQ &FILESIZE THEN 1 ELSE 0 ;

 BIT1/I1     = IF BytBit EQ 1 THEN      Bit1 ELSE
               IF BytBit EQ 2 THEN LAST Bit7 ELSE
               IF BytBit EQ 3 THEN LAST Bit5 ELSE 0 ;
 BIT2/I1     = IF BytBit EQ 1 THEN      Bit2 ELSE
               IF BytBit EQ 2 THEN LAST Bit8 ELSE
               IF BytBit EQ 3 THEN LAST Bit6 ELSE 0 ;
 BIT3/I1     = IF BytBit EQ 1 THEN      Bit3 ELSE
               IF BytBit EQ 2 THEN      Bit1 ELSE
               IF BytBit EQ 3 THEN LAST Bit7 ELSE 0 ;
 BIT4/I1     = IF BytBit EQ 1 THEN      Bit4 ELSE
               IF BytBit EQ 2 THEN      Bit2 ELSE
               IF BytBit EQ 3 THEN LAST Bit8 ELSE 0 ;
 BIT5/I1     = IF BytBit EQ 1 THEN      Bit5 ELSE
               IF BytBit EQ 2 THEN      Bit3 ELSE
               IF BytBit EQ 3 THEN      Bit1 ELSE 0 ;
 BIT6/I1     = IF BytBit EQ 1 THEN      Bit6 ELSE
               IF BytBit EQ 2 THEN      Bit4 ELSE
               IF BytBit EQ 3 THEN      Bit2 ELSE 0 ;
 XBT1/I1     = IF BytBit EQ 1 AND LstRec EQ 1 THEN      Bit7 ELSE
               IF BytBit EQ 2 AND LstRec EQ 1 THEN      Bit5 ELSE
               IF BytBit EQ 3                 THEN      Bit3 ELSE 0 ;
 XBT2/I1     = IF BytBit EQ 1 AND LstRec EQ 1 THEN      Bit8 ELSE
               IF BytBit EQ 2 AND LstRec EQ 1 THEN      Bit6 ELSE
               IF BytBit EQ 3                 THEN      Bit4 ELSE 0 ;
 XBT3/I1     = IF BytBit EQ 2 AND LstRec EQ 1 THEN      Bit7 ELSE
               IF BytBit EQ 3                 THEN      Bit5 ELSE 0 ;
 XBT4/I1     = IF BytBit EQ 2 AND LstRec EQ 1 THEN      Bit8 ELSE
               IF BytBit EQ 3                 THEN      Bit6 ELSE 0 ;
 XBT5/I1     = IF BytBit EQ 3                 THEN      Bit7 ELSE 0 ;
 XBT6/I1     = IF BytBit EQ 3                 THEN      Bit8 ELSE 0 ;

 Char/A1     = B64_CHAR(BIT1,BIT2,BIT3,BIT4,BIT5,BIT6) ;
 XChar/A1    = IF (BytBit EQ 3) OR (Cntr EQ &FILESIZE) THEN B64_CHAR(XBT1,XBT2,XBT3,XBT4,XBT5,XBT6) ELSE ' ' ;

 NewChars/A4 = IF Cntr EQ &FILESIZE
               THEN Char || XChar || '&Padding'
               ELSE Char || XChar ;

 Line/A76    = IF ARGLEN(76,LAST Line,'I2') EQ 76
               THEN NewChars
               ELSE SUBSTR(80,LAST Line || NewChars,1,76,76,'A76') ;

 Put_Line/A1 = IF (ARGLEN(76,Line,'I2') EQ 76) OR (Cntr EQ &FILESIZE) THEN 'Y' ELSE 'N' ;

END

TABLE   FILE TMP_SRCE
 PRINT 
        COMPUTE
        RET_CODE/I1 = IF Put_Line EQ 'Y'
                      THEN PUTDDREC('B64_OUT',7,Line,ARGLEN(76,Line,'I2'), 'I1')
                      ELSE 0 ;

 WHERE  TOTAL Put_Line EQ 'Y'

 ON     TABLE HOLD AS TMP_B64

END

-RUN

-NO_FILE

This message has been edited. Last edited by: FP Mod Chuck,


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Master
posted Hide Post
By any chance do you have a base64 decoder.




Scott

 
Posts: 865 | Registered: May 24, 2004Report This Post
Expert
posted Hide Post
Um, Yes.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SHARING] Base 64 Encoder

Copyright © 1996-2020 Information Builders