/* Globbing for the Archimedes.
 */

#include <stdio.h>
#include <string.h>
#include "utils.h"

#define OPTIONS "?ns"

#define USAGE \
"Usage: Glob [options] pattern...\n" \
"\n" \
"Options:\n" \
"    -n     Separate values with newline instead of null\n" \
"    -s     Separate values with a space instead of null\n" \
"\n"

int main(int argc, char *argv[])
{
	char *name;
	int opt;
	char sep = 0;

	while ((opt = getopt(argc, argv, OPTIONS)) != EOF)
	{
		switch (opt)
		{
		case 'n':
			sep = '\n';
			break;
		case 's':
			sep = ' ';
			break;
		default:
			fputs(USAGE,stderr);
			return (opt != '?');
		}
	}


	for (; optind < argc; ++optind)
	{
		for (name = dirscan(argv[optind]); name; name = dirscan(0))
		{
			fputs(name, stdout);
			putchar(sep);
		}
	}

	return 0;
}
