//-----------------------------------------------------------------------------
// Copyright © 2006 - 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/ftr
// 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.
//-----------------------------------------------------------------------------

#define _GNU_SOURCE

#include "ftr_lib.h"

#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <libh/io.h>

__FMACRO_BEGIN__
//-----------------------------------------------------------------------------
// function	ftr_new_va
//
// purpose	Create a new instance of file tree recursion for a specified
//		list of filesystem object names (usually directories) given in
//		a variable argument list.
//
// arguments	1..N (const char *) filesystem object names
//
// returns	(FTR) pointer to new instance
//-----------------------------------------------------------------------------
#define ftr_new_va(n,a...) (ftr_new_va)((n),a,(const char*)(NULL))

__FMACRO_END__

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	ftr_new_va
//
// purpose	Create a new instance of file tree recursion for a specified
//		list of filesystem object names (usually directories) given in
//		a variable argument list.
//
// arguments	1..N (const char *) filesystem object names
//
// returns	(FTR) pointer to new instance
//-----------------------------------------------------------------------------
FTR
(ftr_new_va) (
    const char *	arg_name
    ,
    ...
)
__PROTO_END__
{
    FTR				first_ftr	;
    FTR				last_ftr	;
    FTR				this_ftr	;
    va_list			name_list	;
    const char *		this_name	;


    if ( ! arg_name ) return NULL;

    first_ftr = ftr_new( arg_name );
    if ( ! first_ftr ) return NULL;

    last_ftr = first_ftr;

    va_start( name_list, arg_name );
    while ( ( this_name = va_arg( name_list, const char * ) ) ) {
	this_ftr = ftr_new( this_name );
	if ( ! this_ftr ) goto ftr_new_va_error;
	last_ftr->next_ftr = this_ftr;
	last_ftr = this_ftr;
    }

    return first_ftr;

 ftr_new_va_error:
    ftr_end( first_ftr );
    return NULL;
}

