1000	!====================================================================================================
	! title  : fix_ftp_save_sets.bas
	! author : Neil Rieck
	! created: 2001.01.11
	! purpose: Files FTP'd into OpenVMS always have a fixed record size of 512. However, OpenVMS save
	! sets (usually of the form "file.A", "file.B", etc.) require a fixed record size of 9216. This
	! program performs that conversion.
	! For an example of a downloadable saveset which requires conversion, check out the freeware area
	! at http://www.openvms.compaq.com/freeware/
	!
	! ver who when   what
	! --- --- ------ ------------------------------------------------------------------------------------
	! 100 NSR 010111 1. original progam (512 in - 9216 out)
	!         010112 2. added support for different output block sizes
	!====================================================================================================
	option type=explicit							! no kids stuff...
	set no prompt
	!
	map(map512)		string	my512buffer	= 512			! for our input file
	!
!~	map(map9216)		string	my9216buffer	= 9216			x 9216 = 512 x 18
!~	map(map9216)		string	my512array(17)	= 512			x 0-17 = items 18
	!
	declare string	fs1$					,&
			blk_multiple$				,&
		long	handler_error% 				,&
			read_count%				,&
			blk_multiple%
	!
	print "fix 'ftp induced' saveset corruption (101)"
	print "=========================================="
	input "input file ? (default=none) ";fs1$
	fs1$ = edit$(fs1$, 32%+2%)
	goto sortie if fs1$ = ""
	!
	get_blk_multiple:
	print "some example block sizes for output:"
	print "   1 x 512=  512 :standard saveset block size after FTP"
	print "  16 x 512= 8192 :TAPE standard saveset      (eg. FILENAME.BCK)"
	print "  18 x 512= 9216 :VMSINSTAL standard saveset (eg. FILENAME.A)"
	print "  63 x 512=32256 :DISK standard saveset      (eg. FILENAME.BCK)"
	print "512 block multiple ? (1-63, default=18) ";
	input blk_multiple$
	when error in
		blk_multiple% = integer(blk_multiple$)
		handler_error% = 0%
	use
		handler_error% = err
	end when
	select handler_error% 
	    case 0%
		select blk_multiple%
		    case 0%
			blk_multiple% = 18%
		    case <0%, >63%
			print "-e-range error"
			goto get_blk_multiple
		end select
	    case else
		print "-e-"; ert$(handler_error%)
		goto get_blk_multiple
	end select
	!
	declare string buffer$
	!
	!	open files and do it
	!
	when error in
		print "-i-opening input file : ";fs1$
		open fs1$ for input as #1								&
			,map map512									&
			,organization sequential fixed							&
			,recordtype none
		!
		print "-i-opening output file: yada.a w/recsiz: ";str$(blk_multiple% * 512%)
		open "yada.a" for output as #2								&
			,organization sequential fixed							&
			,recordtype none				! like binary switch in "c"	&
			,recordsize (blk_multiple% * 512%)		! need this cuz no MAP
		!
		print "-i-transfering data"
		read_count% = 0%
		buffer$ = ""
		while 1=1
			get #1
			buffer$ = buffer$ + my512buffer
			read_count% = read_count% + 1%
			if read_count% = blk_multiple% then
				move to #2, buffer$			! need MOVE cuz no MAP
				put #2					!
				buffer$ = ""
				read_count% = 0%
			end if
		next
	use
		handler_error% = err
	end when
	!
	if (handler_error%<>11%) or						! if not EOF	&
	   (read_count% <> 0%)							! or partial block of data
	then
		print "-e-error code      : "; str$(handler_error%)
		print "-e-error text      : "; ert$(handler_error%)
		print "-e-read block count: "; str$(read_count%); " (should be zero)"
	else
		print "-i-transfer complete"
		print "-i-use the following DCL command to test your results"
		print "   $back/list yada.a/save"
	end if
	!
	!	adios...
	!
	sortie:
	end	
