.NAME character sequence within C-style comment

.DESCRIPTION
The character sequence /* shall not be used within a C-style comment. 

.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

proc howManyLines { str } {
	set l [string length $str]
	set nb 1
	for { set i 0 } { $i < $l } { incr i } {
		if { "[string range $str $i $i]" == "\n" } {
			incr nb
		}
	}
	return $nb
}

# reading all file and looking for comments
proc compute {standardName filename} {

	set chan [open $filename]
	set content [read $chan]
	close $chan
	set l [string length $content]
	set state Nothing
	for { set i 0 } { $i < $l } { incr i } {
		switch $state {
			WaitEndOfLine {
				set char [string range $content $i $i]
				if { "$char" == "\n" } {
					set state Nothing
				}
			}
			Nothing {
				set doubleChar [string range $content $i [expr $i + 1]]
				switch -- $doubleChar {
					// {
						set state WaitEndOfLine
					}
					/* {
						incr i 2
						set idx2 [string first "*/" $content $i]
						if { $idx2 >= 0 } {
							set idx3 [string first "/*" [string range $content $i $idx2]]
							if { $idx3 >= 0 } {
								set firstChar [expr $i + $idx3]
								set numLine [howManyLines [string range $content 0 $firstChar]]
								Violation $filename $firstChar [expr $firstChar + 1] $numLine $standardName "Embedded comments not allowed"
							}
							set i [expr $idx2 + 1]
						}
					}
				}
			}
		}
	}
}
