#!/usr/local/bin/cz --
use main util io

cstr version = "1.0"

cstr description = "types - Sam Watkins, 2009"

cstr usage[] =
	"[--follow] < files.ls",
	"--help",
	NULL

cstr options[][3] =
	{ "V", "version",   "" },
	{ "f", "follow",    "follow symlinks" },
	{ NULL, NULL, NULL }

opts *O

Main()
	O = get_options(options)
	boolean follow = opt("follow") && 1
	decl(s, struct stat)
	Eachline(f)
		if follow ? Stat(f, s) : Lstat(f, s)
			let(m, s->st_mode)
			if S_ISREG(m)
				Print("file")
			eif S_ISDIR(m)
				Print("dir")
			eif S_ISCHR(m)
				Print("char")
			eif S_ISBLK(m)
				Print("block")
			eif S_ISFIFO(m)
				Print("fifo")
			eif S_ISLNK(m)
				Print("sym")
			eif S_ISSOCK(m)
				Print("sock")
			else
				Print("?")
		 else
			# the file ain't there
		tab()
		Print(f)
		nl()
