Files
harbour-core/contrib/hbtip/tests/base64.prg
Viktor Szakats 1938dd0a70 2017-04-14 13:22 UTC+0200 Aleksander Czajczynski (hb fki.pl)
* contrib/hbtip/ccgi.prg
  * contrib/hbtip/client.prg
  * contrib/hbtip/encb64.prg
  * contrib/hbtip/encoder.prg
  * contrib/hbtip/encqp.prg
  * contrib/hbtip/encurl.prg
  * contrib/hbtip/ftpcli.prg
  * contrib/hbtip/hbtip.hbp
  * contrib/hbtip/hbtip.hbx
  * contrib/hbtip/httpcli.prg
  * contrib/hbtip/log.prg
  * contrib/hbtip/mail.prg
  * contrib/hbtip/mime.c
  * contrib/hbtip/misc.c
  * contrib/hbtip/popcli.prg
  * contrib/hbtip/sessid.prg
  * contrib/hbtip/smtpcli.prg
  * contrib/hbtip/thtml.ch
  * contrib/hbtip/thtml.prg
  * contrib/hbtip/tip.ch
  * contrib/hbtip/url.prg
  + contrib/hbtip/base64u.prg
  + contrib/hbtip/mailassy.prg
  * contrib/hbtip/sendmail.prg -> [...]/mailsend.prg
  + contrib/hbtip/WARNING.txt
  * contrib/hbtip/tests/base64.prg
  * contrib/hbtip/tests/dbtohtml.prg
  * contrib/hbtip/tests/dnldftp.prg -> [...]/ftp_dl.prg
  * contrib/hbtip/tests/ftpadv.prg -> [...]/ftp_adv.prg
  + contrib/hbtip/tests/email.prg
  + contrib/hbtip/tests/ftp_ul.prg
  - contrib/hbtip/tests/gmail.hbp
  - contrib/hbtip/tests/gmail.prg
  * contrib/hbtip/tests/hbmk.hbm
  * contrib/hbtip/tests/httpadv.prg -> [...]/http_adv.prg
  * contrib/hbtip/tests/httpcli.prg -> [...]/http_cli.prg
  + contrib/hbtip/tests/http_qry.prg
  - contrib/hbtip/tests/loadhtml.prg
  + contrib/hbtip/tests/test.prg
  + contrib/hbtip/tests/url.prg
    * synced with 3.4 fork by Viktor Szakats
    ; the only difference is slightly edited WARNING.txt

  - contrib/hbtip/credent.prg
    % deleted TIPCredentials() class that was never implemented

  ; changes above come from vast number of commits in 3.4 repository - many
    thanks to Viktor Szakats for maintaining
2017-04-14 13:22:09 +02:00

91 lines
2.3 KiB
Plaintext

/* TIP Base64 (and other) encoding
*
* This test writes data to standard output, and is
* compiled only under GTCGI. This allow to test the
* input/output file against other OS encoded/decoded data
*/
#require "hbtip"
#include "fileio.ch"
PROCEDURE Main( ... )
LOCAL oEncoder, cEncoder := "base64"
LOCAL lDecode := .F., lHelp := .F.
LOCAL cData, nLen, cBuffer
LOCAL hFileInput, nFileInput := hb_GetStdIn()
LOCAL hFileOutput, nFileOutput := hb_GetStdOut()
/* Parameter parsing */
FOR EACH cData IN hb_AParams()
SWITCH Lower( cData )
CASE "-h"
lHelp := .T.
EXIT
CASE "-d"
lDecode := .T.
EXIT
CASE "-q"
cEncoder := "quoted-printable"
EXIT
CASE "-u"
cEncoder := "url"
EXIT
OTHERWISE
IF hb_vfExists( cData ) .AND. nFileInput == hb_GetStdIn()
IF ( hFileInput := hb_vfOpen( cData, FO_READ ) ) != NIL
nFileInput := hb_vfHandle( hFileInput )
ENDIF
ELSEIF nFileOutput == hb_GetStdOut()
IF ( hFileOutput := hb_vfOpen( cData, FO_CREAT + FO_TRUNC + FO_WRITE ) ) != NIL
nFileOutput := hb_vfHandle( hFileOutput )
ENDIF
ELSE
? "Wrong parameter", cData
?
lHelp := .T.
ENDIF
ENDSWITCH
NEXT
/* Providing help */
IF lHelp
? "Usage:"
? "base64 [<] file-to-encode [>] encoded-file"
? "base64 -d [<] encoded-file [>] file-to-decode"
? "base64 -q [-d] to use quoted printable encoding/decoding"
? "base64 -u [-d] to use URL encoding/decoding."
? "input/output redirection is optional"
?
RETURN
ENDIF
/* Reading input stream */
cData := ""
cBuffer := Space( 1024 )
DO WHILE ( nLen := FRead( nFileInput, @cBuffer, hb_BLen( cBuffer ) ) ) > 0
cData += hb_BLeft( cBuffer, nLen )
ENDDO
IF hFileInput != NIL
hb_vfClose( hFileInput )
ENDIF
/* Encoding/decoding */
oEncoder := TIPEncoder():New( cEncoder )
IF lDecode
cData := oEncoder:Decode( cData )
ELSE
cData := oEncoder:Encode( cData )
ENDIF
/* Writing stream */
FWrite( nFileOutput, cData )
IF hFileOutput != NIL
hb_vfClose( hFileOutput )
ENDIF
RETURN