:1#include "V.h"
#include "sys_stat.h"
/*
*	newer file1 file2 ...
*
* This program accepts a list of files, and returns 0 if each file is newer
* than the next in the list.  If two consecutive timestamps are the same or
* reversed, the exit status is the index of the second of the two files.
* If any file doesn't exist, a failure also occurs, returning the index of
* the missing file.  No file names at all produces success, of course.
*
* For files with equal modification times, the comparison is true (zero).
*/
struct stat s[2];

main(ac,av)
	char**av;
{	int a, i=0;

:1	ac = Vinit(ac,av);
:1	V3 "%d args.",ac D;
	if (ac < 2) {
:1		V3 "No files; success." D;
		exit(0);
	}
	if (stat(av[1],&s[1]) < 0) {
:1		V2 "File 1 doesn't exist." D;
		exit(1);
	}
	for (a=2; a<ac; a++) {
		if (stat(av[a],&s[i]) < 0) {
:1			V2 "File %d=%s doesn't exist.",a,av[a] D;
			exit(a);
		}
:1		V2 "a=%d s[%d]=%lu s[%d]=%lu",
			a,i,s[i].st_mtime,1-i,s[1-i].st_mtime D;
		if (s[1-i].st_mtime < s[i].st_mtime) {
:1			V2 "File %s < %s",av[a],av[a-1] D;
			exit(a);
		}
		i = 1 - i;
	}
:1	V3 "Everything in order." D;
	exit(0);
}
