/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 */

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: dofile.c 1.6 89/10/10 $@(#)sccs:lib/comobj/dofile.c	6.5"
#include	"../../hdr/defines.h"
#include	<sys/ufsinode.h>
#include	<sys/param.h>
#include	<sys/dir.h>
#include	<dirent.h>

#define EQ(x,y)	(strcmp(x,y)==0)

int	nfiles;
char	had_dir;
char	had_standinp;


do_file(p,func)
register char *p;
int (*func)();
{
	extern char *Ffile;
	register struct dirent *dp;
	char str[FILESIZE];
	char ibuf[FILESIZE];
	DIR *dir;

	if (p[0] == '-') {
		had_standinp = 1;
		while (gets(ibuf) != NULL) {
			if (exists(ibuf) && (Statbuf.st_mode & S_IFMT) == S_IFDIR) {
				had_dir = 1;
				Ffile = ibuf;
				if ((dir = opendir(ibuf)) == NULL)
					return;
				for (dp = readdir(dir); dp != NULL; dp = readdir(dir)) {
					if (dp->d_ino == 0)
						continue;
					if (dp->d_ino == -1)
						continue;
					if (EQ(dp->d_name, "."))   /* skip "." */
						continue;
					if (EQ(dp->d_name, ".."))  /* skip ".." */
						continue;
					sprintf(str,"%s/%s",ibuf,dp->d_name);
					if(sccsfile(str)) {
						Ffile = str;
						(*func)(str);
						nfiles++;
					}
				}
				closedir(dir);
			}
			else if (sccsfile(ibuf)) {
				Ffile = ibuf;
				(*func)(ibuf);
				nfiles++;
			}
		}
	}
	else if (exists(p) && (Statbuf.st_mode & S_IFMT) == S_IFDIR) {
		had_dir = 1;
		Ffile = p;
		if ((dir = opendir(p)) == NULL)
			return;
		for (dp = readdir(dir); dp != NULL; dp = readdir(dir)) {
			if (dp->d_ino == 0)
				continue;
			if (dp->d_ino == -1)
				continue;
			if (EQ(dp->d_name, "."))   /* skip "." */
				continue;
			if (EQ(dp->d_name, ".."))  /* skip ".." */
				continue;
			sprintf(str,"%s/%s",p,dp->d_name);
			if(sccsfile(str)) {
				Ffile = str;
				(*func)(str);
				nfiles++;
			}
		}
		closedir(dir);
	}
	else {
		Ffile = p;
		(*func)(p);
		nfiles++;
	}
}
