[GRASS5] Re: Vector symbols & g.region

Glynn Clements glynn at gclements.plus.com
Sun Dec 12 04:46:13 EST 2004


Michael Barton wrote:

> I'm not sure if this helps or not, but issuing a find command that is
> redirected to a text file or variable could create such a list that could
> then be grep'ed to get the part of the path name needed by a simple loop in
> d.vect and vector.tcl.
> 
> E.g:
> 
>  find -f $GISBASE/etc/symbol/ > symbolpath

Don't use "find". For a start, it might not be installed on Cygwin (or
the native find.exe might come first in the path); I don't know about
OSX.

Writing directory scanning code isn't particularly complex. In C, the
basic logic is essentially:

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

void scan_directory(const char *directory)
{
	DIR *dir = opendir(directory);
	if (!dir)
		return;

	for (;;)
	{
		char path[PATH_MAX];
		struct stat st;
		struct dirent *d;

		/* get next directory entry */
		d = readdir(dir);
		if (!d)
			break;

		/* skip hidden files/directories */
		if (d->d_name[0] == '.')
			continue;

		/* convert filename to absolute path */
		sprintf(path, "%s/%s", directory, d->d_name);

		/* get type (file/dir/symlink/etc) */
		if (lstat(path, &st) < 0)
			continue;

		if (S_ISDIR(st.st_mode))
			/* recurse into subdirectory */
			scan_directory(path);
		else if (S_ISREG(st.st_mode))
			/* process regular file */
			do_something_with_file(path);
	}

	closedir(dir);
}

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list