.NAME # token

.DESCRIPTION
If the # token appears as the first token on a line, then it 
shall be immediately followed by a preprocessing token. 

.COMMENT V7.0

.SEVERITY Required

.COMMENT
Please refer to the MISRA C++:2008 document for further details (www.misra-cpp.com)

.COMMAND r_tcl_checker

.CODE

variable possibleDirectives
set possibleDirectives  {
if
define
line
ifndef
ifdef
else
elif
endif
include
error
undef
assert
}

# reading all file and looking for trigraphs
proc compute {standardName filename} {
	variable possibleDirectives
	set chan [open $filename]
	set numLine 0
	set pos 0
	while {[gets $chan line] >= 0} {
		incr numLine
		if { [regexp {^\s*#} $line] } {
			set ok 0
			if { [regexp {^\s*#\s*(\w*)} $line all str] } {
				if { [lsearch $possibleDirectives $str] >= 0 } {
					set ok 1
				}
			}
			if { !$ok } {
				Violation $filename $pos [expr $pos + [string length $line]] $numLine $standardName "$str: Unknown proprocessor directive"
			}
		}
		incr pos [string length $line]
		incr pos
	}
	close $chan
}
