//-----------------------------------------------------------------------------
// Copyright © 2003 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/string
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

__FMACRO_BEGIN__
//-----------------------------------------------------------------------------
// macro	str_cpy_sub
//
// purpose	Copy to the target string the contents of a substring of the
//		source string between two specified points in the source.  The
//		substring bounding points are specified as a count of number
//		of occurrences of a pattern string, with one count and pattern
//		to determine the first point, and another count and pattern to
//		determine the second point.  If the pattern strings are not
//		given, the counts are the number of characters.  A positive
//		count steps forward from the start of the source string.  A
//		negative count steps backwards from the end of the source
//		string with -1 being the end of the source string.  If the
//		first point ends up after the second point, the substring is
//		then an empty string and an empty string is copied.
//
//		The use of -1 to refer to the end of the source string means
//		that -2 ends the substring one character or pattern string
//		before the end.  To remove M characters or pattern strings
//		from the end of a string, code (-(M))-1 in argument 5.
//
//		If the resultant string will not fit the available space,
//		then rollback everything leaving the original target string.
//
// arguments	1 (char *) pointer to beginning of target string
//		2 (size_t) total maximum length of target string
//		3 (int) count of steps to determine the first substring point
//		4 (const char *) pattern string to find first substring point
//		5 (int) count of steps to determine the second substring point
//		6 (const char *) pattern string to find second substring point
//		7 (const char *) source string to select substring from
//
// returns	(size_t) final length of target string
//		(size_t) ~0 : error
//-----------------------------------------------------------------------------
#define str_cpy_sub(t,l,bc,bp,ec,ep,s) (str_empty((t)),str_app_sub((t),(l),(bc),(bp),(ec),(ep),(s)))

__FMACRO_END__

