USG_PG3/usr/source/cmd2/file.c

Compare this file to the similar file:
Show the results in this format:

int ibuf[260];
main(argc, argv)
char **argv;
{

	while(argc > 1) {
		printf("%s:	", argv[1]);
		type(argv[1]);
		argc--;
		argv++;
	}
}

type(file)
char *file;
{
	int mbuf[20];

	if(stat(file, mbuf) < 0) {
		printf("cannot stat\n");
		return;
	}
	switch(mbuf[2]&060000) {

	case 020000:
		printf("character");
		goto spcl;

	case 040000:
		printf("directory\n");
		return;

	case 060000:
		printf("block");

	spcl:
		printf(" special (%d/%d)\n",
			(mbuf[6]>>8)&0377,
			mbuf[6]&0377);
		return;
	}

	ibuf[0] = open(file, 0);
	if(ibuf[0] < 0) {
		printf("cannot open\n");
		return;
	}
	read(ibuf[0], mbuf, 2);
	switch(*mbuf) {

	case 0407:
		printf("old executable\n");
		goto out;

	case 0410:
		printf("new executable\n");
		goto out;

	case 0177555:
		printf("archive\n");
		goto out;
	}

	ibuf[1] = 0;
	ibuf[2] = 0;
	ibuf[3] = 0;
	digram();
out:
	close(ibuf[0]);
}
digram()
{
	printf("unknown\n");
}