#!/usr/bin/awk -f
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2025 Robin Jarry

BEGIN {
	isatty = system("test -t 1") == "0"
	retcode = 0
}

function color(code, s) {
	if (isatty) {
		return "\033[" code "m" s "\033[0m"
	}
	return s
}
function red(s) { return color("31", s) }
function green(s) { return color("32", s) }
function yellow(s) { return color("33", s) }
function magenta(s) { return color("35", s) }
function cyan(s) { return color("36", s) }
function hl(s, pattern) {
	gsub(pattern, yellow("&"), s)
	# convert tab characters to 8 spaces to allow coloring
	gsub(/\t/, "        ", s)
	return s
}

/[\t ]*\/\// {
	retcode = 1
	print magenta(FILENAME) cyan(":") green(FNR) cyan(":") \
		hl($0, "[\\t ]*\\/\\/.*") red("<-- C99 line comment used")
}

END {
	exit retcode
}
