/************************************************************************
 *									*
 * PineAB2YAM.rexx	written April 16, 1998 by Graham Waddell	*
 *									*
 * This program creates a YAM .addressbook file out of a Pine ADDRBK.TXT*
 * file. See Limitations for more info.					*
 *									*
 * Limitations (aka To Do): Pine address GROUPS/LISTS, and future	*
 *  revisions will be able to open and edit the existing YAM addressbook*
 *  Also, this can't yet handle long comments (2nd line in addrbk.txt)	*
 *  so a LITTLE manual editing is often required ('till next version)	*
 *									*
 *									*
 * Revision History:							*
 * v0.1	16-Apr-1998	First release!					*
 *									*
 ************************************************************************
 *									*
 * Usage:								*
 *									*
 * "rx PineAB2YAM.rexx [infile (Pine)] [outfile (YAM)]"			*
 *									*
 ************************************************************************/

OPTIONS results

Version = "$VER: PineAB2YAM.rexx v0.1 (04.16.1998)"

ARG InFilename ' ' OutFilename	/* Assign variables from CLI input	*/

/** Main Control Routine begins here **/
	Call Init_Rtn
	DO While ~EOF('InFile')
		Call Process_Record_Rtn
	END
	Call Termination_Rtn

/** End of Main Control Routine **/


/** Initialization Routine begins here **/
Init_Rtn:

IF ~SHOW('L',"rexxsupport.library") THEN DO
	IF ADDLIB('rexxsupport.library',0,-30,0) THEN NOP
	ELSE DO
		SAY "rexxsupport.library not available, exiting"
		EXIT 10
	END
END

InLine = ''
Name = ''
ALias = ''
Address = ''
Remark = ''

YAMHeader = 'YAB2 - YAM Addressbook V2'
YAMUserStart = '@USER '
YAMUserEnd = '@ENDUSER'

IF ( ( InFilename = '') | ( OutFilename = '') ) Then DO
	Say "rx PineAB2YAM.rexx [infile (Pine)] [outfile (YAM)]"
	Exit 15
END	/* IF InFilename = ''...	*/

IF Exists( InFilename ) Then Do
	Open( 'InFile', InFilename, 'R' )
END
Else DO
	Say "Cannot find File [" || InFilename || "]!!"
	Exit 20
END		/* If Exists( InFilename ) */

	Open( 'OutFile', OutFilename, 'W' )

	InLine = ReadLn('InFile')

	WriteLn( 'OutFile', YAMHeader)

Return 0
/** End of Initialization Routine **/


/** Process Record Routine begins here **/
Process_Record_Rtn:

	Call ParseUser
	Call WriteUser

	InLine = ReadLn('InFile')

Return 0
/** End of Process Record Routine **/


/** Termination Routine begins here **/
Termination_Rtn:

	Close('InFile')
	Close('OutFile')

	Exit 0	/* finished cleanly	*/

Return 0
/** End of Termination Routine **/


/***	Procedures follow	***/
ParseUser:
	PARSE VAR InLine Alias '	' Name '	' Address '		' Remark
/*	Say 'Alias: ['||Alias||']  Name: ['||Name||']  Addr: ['||Address||']'*/

Return 0

WriteUser:
	WriteLn( 'OutFile', YAMUserStart||Alias)
	WriteLn( 'OutFile', Address)
	WriteLn( 'OutFile', Name)
	WriteLn( 'OutFile', Remark)
	WriteLn( 'OutFile', YAMUserEnd)

	Alias = ''
	Address = ''
	Name = ''
	Remark = ''

Return 0

