#!/bin/rc

# invoked from the mkfile with
#	$1 = ALLGOFILES
# 	$2 = NOGOFILES
#	$3 = $DECLFILES
# correctly defined and sorted.

# outputs the expected contents of $GOFILES.

fn strcmp {
	awk -v 'vs='^$1 -v 'vd='^$2 'BEGIN {
		if (vs == vd) {
			print 0
		} else if (vs > vd) {
			print 1
		} else {
			print -1
		}
	}'
}

y = 1
for (v in $ALLGOFILES) {
	if (test $y -gt $#NOGOFILES) {
		echo $v
	}
	if not {
		r = `{strcmp $v $NOGOFILES($y)}
		#echo >[1=2] 'strcmp '^$v^' '$NOGOFILES($y)^' -> '^$r
		while (~ $r 1) {
			echo $DECLFILES($y)
			y = `{echo $y + 1 | hoc}
			r = `{strcmp $v $NOGOFILES($y)}
			#echo >[1=2] 'strcmp '^$v^' '$NOGOFILES($y)^' -> '^$r
		}
		if (~ $r -1) {
			echo $v
		}
		if not {
			echo $DECLFILES($y)
			y = `{echo $y + 1 | hoc}
		}
	}
}
