This is the mail archive of the insight@sourceware.org mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re [RFC] syntax highlighting


Hi

Here is a version with enable/disable of the syntax highlighting.
I've tried the highlighting with "gcc - debugging" to use it with real big files (about 9000 lines per file).
At the first time the file is scanned it takes a while.
So I'm using gdbtk_busy on entry (to show that something happens),
and gdbtk_idle after the scan succeeds (hopping those function can be used for this).
Change between some already scanned source files is quite fast.
If we are switching from enable to disable of a already tagged file, this file can remain as it is and only the color is switched off.
The other case (switching from disable to enable) is more ugly part.
So the file has to be reloaded (but only from the cache) and scanned if necessary. (I hope this did not mess up anything else.)


As you can see the Assemble highlighter isn't the best.
It only highlights C comment, C-Preprocessor directives, label and any words beginning with a dot.
The C highlighter is a little bit better but it is still not a C/C++ Parser.
And it is also not nice, doing this the hard coded way. I know that.


I think this is only a intermediate solution that's bring up little color into the source code.
Maybe somebody else is willing to implement a lex/yacc alike back end to handle this in a better and faster parsing/tagging solution.


Meanwhile we might live with this intermediate solution.

Now I've used
  diff -rubB original_src modified_src
and it is attached.

 cheers
  Thomas




diff -rubB original_src/gdb/gdbtk/library/ehandler.itb modified_src/gdb/gdbtk/library/ehandler.itb
--- original_src/gdb/gdbtk/library/ehandler.itb	Thu Aug  4 12:07:49 2005
+++ modified_src/gdb/gdbtk/library/ehandler.itb	Wed Aug  3 11:16:15 2005
@@ -29,3 +29,48 @@
     }
   }
 }
+
+# ------------------------------------------------------------------
+#  METHOD:  idle - is idle, so do what ?
+# ------------------------------------------------------------------
+itcl::body GDBEventHandler::idle {event} {
+}
+
+# ------------------------------------------------------------------
+#  METHOD: busy - BusyEvent handler
+# ------------------------------------------------------------------
+itcl::body GDBEventHandler::busy {event} {
+}
+
+# ------------------------------------------------------------------
+#  METHOD: update - UpdateEvent handler
+# ------------------------------------------------------------------
+itcl::body GDBEventHandler::update {event} {
+}
+
+# ------------------------------------------------------------------
+#  METHOD: arch_changed - Event handler
+# ------------------------------------------------------------------
+itcl::body GDBEventHandler::arch_changed {event} {
+}
+
+# ------------------------------------------------------------------
+#  METHOD: set_variable - Event handler
+# ------------------------------------------------------------------
+itcl::body GDBEventHandler::set_variable {event} {
+}
+
+# ------------------------------------------------------------------
+#  METHOD: breakpoint - Event handler
+# ------------------------------------------------------------------
+itcl::body GDBEventHandler::breakpoint {event} {
+}
+
+# ------------------------------------------------------------------
+#  METHOD: tracepoint - Event handler
+# ------------------------------------------------------------------
+itcl::body GDBEventHandler::tracepoint {event} {
+}
+
+
+
diff -rubB original_src/gdb/gdbtk/library/prefs.tcl modified_src/gdb/gdbtk/library/prefs.tcl
--- original_src/gdb/gdbtk/library/prefs.tcl	Thu Aug  4 12:07:49 2005
+++ modified_src/gdb/gdbtk/library/prefs.tcl	Thu Aug  4 12:56:12 2005
@@ -352,6 +352,8 @@
   pref define gdb/src/linenums		  1
   pref define gdb/src/thread_fg           pink
   pref define gdb/src/top_control	  1;	# 1 srctextwin controls on top, 0 bottom
+  pref define gdb/src/syntax_highlight_c  1
+  pref define gdb/src/syntax_highlight_gas 0
 
   # Define the run button's functions. These are defined here in case
   # we do a "run" with an exec target (which never causes target.tcl to 
diff -rubB original_src/gdb/gdbtk/library/srcpref.itb modified_src/gdb/gdbtk/library/srcpref.itb
--- original_src/gdb/gdbtk/library/srcpref.itb	Thu Aug  4 12:07:49 2005
+++ modified_src/gdb/gdbtk/library/srcpref.itb	Thu Aug  4 13:39:54 2005
@@ -29,6 +29,7 @@
     gdb/src/run_attach gdb/src/run_load gdb/src/run_run
     gdb/src/run_cont gdb/src/bp_fg gdb/src/temp_bp_fg 
     gdb/src/trace_fg gdb/src/thread_fg gdb/src/variableBalloons
+    gdb/src/syntax_highlight_c gdb/src/syntax_highlight_gas
     gdb/src/source2_fg gdb/src/tab_size gdb/mode gdb/editor
     gdb/B1_behavior}
 
@@ -124,12 +125,31 @@
   radiobutton $w.var_on -text "On " -variable [scope $var] -value 1
   radiobutton $w.var_off -text "Off" -variable [scope $var] -value 0
   pack $w.var_on $w.var_off -side top
+
+  # syntax highlight
+  Labelledframe $f.rmv.synhlbehavior -anchor nw -text "Syntax Highlight Behavior"
+  set w [$f.rmv.synhlbehavior get_frame]
+  set var_syntax_highlight_c _new(gdb/src/syntax_highlight_c)
+  set var_syntax_highlight_gas _new(gdb/src/syntax_highlight_gas)
+  checkbutton $w.var_syntax_highlight_c \
+              -text "C" \
+	      -variable [scope $var_syntax_highlight_c] \
+	      -anchor w
+  checkbutton $w.var_syntax_highlight_gas \
+              -text "GNU Asm (gas) - simlpe mode" \
+	      -variable [scope $var_syntax_highlight_gas] \
+	      -anchor w
+  pack $w.var_syntax_highlight_c $w.var_syntax_highlight_gas -side top -fill x
+
+  
   grid $f.rmv.mode -sticky nsew -pady 5 -row 0 -column 0
   grid $f.rmv.var -sticky nsew -pady 5 -row 0 -column 2
+  grid $f.rmv.synhlbehavior -sticky new -pady 5 -row 1 -column 0 -columnspan 3
   grid columnconfigure $f.rmv 0 -weight 1
   grid columnconfigure $f.rmv 1 -minsize 4
   grid columnconfigure $f.rmv 2 -weight 1
   grid rowconfigure $f.rmv 0 -weight 1
+  grid rowconfigure $f.rmv 1 -weight 1
 
 
   frame $f.x
diff -rubB original_src/gdb/gdbtk/library/srctextwin.itb modified_src/gdb/gdbtk/library/srctextwin.itb
--- original_src/gdb/gdbtk/library/srctextwin.itb	Thu Aug  4 12:07:49 2005
+++ modified_src/gdb/gdbtk/library/srctextwin.itb	Thu Aug  4 17:14:16 2005
@@ -319,6 +319,10 @@
   set twin [$twinp component text]
   pack $twinp -fill both -expand yes
   pack $itk_interior.p -fill both -expand yes
+
+  set withSynHl_C [pref get gdb/src/syntax_highlight_c]
+  set withSynHl_GAS [pref get gdb/src/syntax_highlight_gas]
+
   config_win $twin
 }
 
@@ -752,6 +756,7 @@
 itcl::body SrcTextWin::reconfig {} {
 #  debug
   
+  #debug "enter reconfig"
   # Make sure we redo the break images when we reconfigure
   set size [font measure [pref get gdb/src/font] "W"]
   makeBreakDot $size [pref get gdb/src/bp_fg] $break_images(bp)
@@ -767,9 +772,23 @@
   $twin tag configure PC_TAG -background [pref get gdb/src/PC_TAG]
   $twin tag configure STACK_TAG -background [pref get gdb/src/STACK_TAG]
   $twin tag configure BROWSE_TAG -background [pref get gdb/src/BROWSE_TAG]
+  
+  set prev_withSynHl_C $withSynHl_C
+  set prev_withSynHl_GAS $withSynHl_GAS
+  set withSynHl_C [pref get gdb/src/syntax_highlight_c]
+  set withSynHl_GAS [pref get gdb/src/syntax_highlight_gas]
+  
   switch $current(mode) {
     SOURCE {
       setTabs $twin
+      if { ($withSynHl_GAS != $prev_withSynHl_GAS)
+         ||($withSynHl_C != $prev_withSynHl_C) } {
+	 #FIXME: did I miss anything ???
+	 if {$current(filename) != ""} {
+    	    set mtime [_mtime_changed $current(filename)]
+            LoadFile t $current(filename) $current(lib) $mtime
+	 }
+      }
     }
     SRC+ASM {
       setTabs $twin 
@@ -1247,6 +1266,715 @@
   }
 }
 
+
+# ------------------------------------------------------------------
+#  METHOD:  scanAndTagTextWidget - for Syntax Highlight
+# ------------------------------------------------------------------
+itcl::body SrcTextWin::scanAndTagTextWidget {win name} {
+  # check if we should make the scan for syntax highlighting
+  set tag_names [$win tag names]
+
+  #what kind of file is it ?
+  if {[regexp {(.+)(\.)([chCH])([+pP])*$} $name ignore]} {
+     # its a kind of C file should we scan it ?
+     if {$withSynHl_C} {
+  	# have we already scanned
+  	if {[regexp hl_language_c $tag_names] == 0} {
+	   gdbtk_busy
+	   scanAndTagC $win
+	   gdbtk_idle
+	}
+     }
+  } elseif {[regexp {(.+)(\.)(([sS])|([aA][sS][mM]))$} $name ignore]} {
+     # looks more like asm file; should we scan it ?
+     if {$withSynHl_GAS} {
+  	# have we already scanned
+  	if {[regexp hl_language_gas $tag_names] == 0} {
+	   gdbtk_busy
+	   scanAndTagASM $win
+	   gdbtk_idle
+	}
+     }
+  }
+}
+
+# ------------------------------------------------------------------
+#  METHOD:  scanAndTagASM - for Syntax Highlight
+# ------------------------------------------------------------------
+itcl::body SrcTextWin::scanAndTagASM {win} {
+  scan [$win index end] %d numLines
+  
+  if {$numLines == {} || $numLines < 1} {
+    return
+  }
+  # tag language at first position
+  $win tag add hl_language_gas 1.0 1.end
+  
+  # define oure simple keyword set ".?*"
+  set keyWords {(\.)([a-zA-Z0-9])+}
+
+  set multiLineComment	0
+  set multiLinePreProc	0
+  set multiLineString	0
+  
+  for {set i 1} {$i <= $numLines} {incr i} {
+    # skip first (' ' or '-') char, the TAB and the number
+    if {$Linenums} {
+    	$win mark set last $i.2
+	set strLine [$win get last "last + 12 chars"]
+	if {[regexp -indices {([0-9])+} $strLine indices]} {
+		set idx_lo [lindex $indices 0]
+		set idx_hi [lindex $indices 1]
+		$win mark set first "last + $idx_lo chars"
+		$win mark set last  "last + $idx_hi chars + 1 chars"
+		$win tag add hl_linenum first last
+		set k [expr [lindex $indices 1] + 3]
+	}
+    } else {
+	# skip first ' ' or '-' char
+	set k 1
+    }
+    # tag commends and strings
+    $win mark set last $i.$k 
+    while { 1 } {
+    	set strLine [$win get last "last lineend"]
+	if {$strLine == {}} break
+	if { ($multiLineComment == 0) && ($multiLineString == 0) } {
+		# searching /* or "
+		if {[regexp -indices {(/\*)|(//)|(\")} $strLine indices]} {
+			set idx_lo [lindex $indices 0]
+			set idx_hi [lindex $indices 1]
+			$win mark set first "last + $idx_lo chars"
+			# is it /*,// or " 
+			if { [string index $strLine $idx_lo] != "/" } {
+				# it's quote " ;make sure it's not \"
+				if { $idx_lo == 0 || ($idx_lo > 0 && [string index $strLine [expr $idx_lo - 1]] != "\\") } {
+					$win mark set last  "last + $idx_hi chars + 1 chars"
+					set strLine [$win get last "last lineend"]
+					# is there a closing " too
+					set found_quote_end 0
+					while {[regexp -indices {(\")} $strLine indices]} {
+						set idx_hi [lindex $indices 1]
+						# also without make sure it's not \"
+						if { $idx_hi == 0 || ($idx_hi > 0 && [string index $strLine [expr $idx_hi - 1]] != "\\") } {
+							$win mark set last "last + 1 chars + $idx_hi chars"
+							$win tag add hl_lineString first last
+							set found_quote_end 1
+							break
+						}
+						$win mark set last "last + 1 chars + $idx_hi chars"
+    						set strLine [$win get last "last lineend"]
+					}
+					if {$found_quote_end == 0} {
+						# there is no quoting end in this line; seach for end of line
+						if {[regexp -indices {(.)$} $strLine indices]} {
+							set multiLineString 1
+							set idx_hi [lindex $indices 0]
+							$win mark set last "last + 1 chars + $idx_hi chars"
+							$win tag add hl_lineString first last
+							break
+						} else {
+							# something goes wrong
+							debug "missing lineend "
+							break
+						}
+					}
+				} else {
+					$win mark set last  "last + $idx_hi chars + 1 chars"
+				}
+			} elseif { [string index $strLine [expr $idx_lo + 1]] == "/" } {
+				# it's line comment //
+				if {[regexp -indices {(.)$} $strLine indices]} {
+					set idx_hi [lindex $indices 0]
+				} else {
+					debug "missing lineend"
+					set idx_hi [lindex $indices 1]
+				}
+				$win mark set first "last + $idx_lo chars"
+				$win mark set last "last + 1 chars + $idx_hi chars"
+				$win tag add hl_comment first last
+				break		
+			} else {
+				# it's a comment /*
+				$win mark set last  "last + $idx_hi chars"
+				set strLine [$win get last "last lineend"]
+				# is there a closing */ too
+				if {[regexp -indices {(\*/)} $strLine indices]} {
+					set idx_hi [lindex $indices 1]
+					$win mark set last "last + 1 chars + $idx_hi chars"
+					$win tag add hl_comment first last
+				} elseif {[regexp -indices {(.)$} $strLine indices]} {
+					set multiLineComment 1
+					set idx_hi [lindex $indices 0]
+					$win mark set last "last + 1 chars + $idx_hi chars"
+					$win tag add hl_comment first last
+					break
+				} else {
+					# something goes wrong
+					debug "missing lineend "
+					break
+				}
+			}
+		} else {
+			# no more // or /*
+			break
+		}
+		
+	} elseif { $multiLineComment == 0 } {
+		# multi line String
+		$win mark set first "last"
+		if {[regexp -indices {(\")} $strLine indices]} {
+			# it's quote " ;make sure it's not \"
+			set idx_hi [lindex $indices 1]
+			if { $idx_hi == 0 || ($idx_hi > 0 && [string index $strLine [expr $idx_hi - 1]] != "\\") } {
+				set multiLineString 0
+				$win mark set last "last + 1 chars + $idx_hi chars"
+				$win tag add hl_lineString first last
+			} else {
+				$win mark set last "last + 1 chars + $idx_hi chars"
+			}
+		} elseif {[regexp -indices {(.)$} $strLine indices]} {
+			set idx_hi [lindex $indices 0]
+			$win mark set last "last + 1 chars + $idx_hi chars"
+			$win tag add hl_lineString first last
+			break
+		} else {
+			# something goes wrong
+			debug "missing lineend "
+			break
+		}		
+	} else {
+		# multi line comments
+		$win mark set first "last"
+		if {[regexp -indices {(\*/)} $strLine indices]} {
+			set multiLineComment 0
+			set idx_hi [lindex $indices 1]
+			$win mark set last "last + 1 chars + $idx_hi chars"
+			$win tag add hl_comment first last
+		} elseif {[regexp -indices {(.)$} $strLine indices]} {
+			set idx_hi [lindex $indices 0]
+			$win mark set last "last + 1 chars + $idx_hi chars"
+			$win tag add hl_comment first last
+			break
+		} else {
+			# something goes wrong
+			debug "missing lineend "
+			break
+		}
+	}
+    }
+    # tag prepocessor directives
+    $win mark set last $i.$k
+    while (1) {
+    	set strLine [$win get last "last lineend"]
+	if { $multiLinePreProc == 0 } {
+		# search for a beginning #
+		if {[regexp -indices {(^([ \t])*#)} $strLine indices]} {
+			set idx_lo [lindex $indices 0]
+			set idx_hi [lindex $indices 1]
+			$win mark set first "last + $idx_lo chars"
+			$win mark set last  "last + $idx_hi chars"
+			set strLine [$win get first "first lineend"]
+			set strEndPos  [expr [string length $strLine] - 1]
+			# is there a reapet \
+			if {$strEndPos > 0} {
+				$win mark set last "last + 1 chars + $strEndPos chars"
+				$win tag add hl_preproc first last
+				if { [string index $strLine $strEndPos] == "\\" } {
+					set multiLinePreProc 1
+				} else {
+					# is there a <..> within this line
+					if {[regexp -indices {<([a-zA-Z0-9/\\\.]+)>} $strLine indices]} {
+						set idx_lo [lindex $indices 0]
+						set idx_hi [lindex $indices 1]
+						$win mark set last  "first + 1 chars + $idx_hi chars"
+						$win mark set first "first + $idx_lo chars"
+						$win tag add hl_lineString first last
+					}
+				}
+				break
+			} 
+		} 
+	} else {
+		# multi line directives
+		$win mark set first "last"
+		set strLine [$win get first "first lineend"]
+		set strEndPos  [expr [string length $strLine] - 1]
+		if {$strEndPos > 0} {
+			$win mark set last "last + 1 chars + $strEndPos chars"
+			$win tag add hl_preproc first last
+			if { [string index $strLine $strEndPos] != "\\" } {
+				set multiLinePreProc 0
+			}
+			break
+		} 
+	}
+	break
+    }
+    # search for keywords and give those a tag
+    $win mark set last $i.$k 
+    set strLine [$win get last "last lineend"]
+    while {[regexp -indices $keyWords $strLine indices]} {
+	set idx_lo [lindex $indices 0]
+	set idx_hi [lindex $indices 1]
+	$win mark set first "last + $idx_lo chars"
+	$win mark set last "last + 1 chars + $idx_hi chars"
+	set tag_names [$win tag names first]
+	if {[regexp {(hl_comment)|(hl_preproc)|(hl_lineString)} $tag_names] == 0} {
+		# only if it't not a comment
+		set cmpStr [string index $strLine [expr $idx_lo - 1]]
+		if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] } {
+		} else {
+			set cmpStr [string index $strLine [expr $idx_hi + 1]]
+			if {[regexp {^[0-9]|^[a-z]|^[A-Z]|^[_\-\.\:]} $cmpStr] == 0} {
+				$win tag add hl_keyword first last
+			}
+		}
+	}
+	set strLine [$win get last "last lineend"]
+    }     
+    # search for labels and give those a tag
+    $win mark set last $i.$k 
+    set strLine [$win get last "last lineend"]
+    if {[regexp -indices {^([ \t]*)([a-zA-Z0-9_\\\.])+:} $strLine indices]} {
+    	# skip leading space chars
+	regexp -indices {([a-zA-Z0-9_\\\.])+:} $strLine indices
+	set idx_lo [lindex $indices 0]
+	set idx_hi [lindex $indices 1]
+	$win mark set first "last + $idx_lo chars"
+	$win mark set last "last + 1 chars + $idx_hi chars"
+	set tag_names [$win tag names first]
+	if {[regexp {(hl_comment)|(hl_lineString)|(hl_keyword)} $tag_names] == 0} {
+		$win tag add hl_label first last
+	}
+    }
+    #next line
+  }
+
+}
+
+# ------------------------------------------------------------------
+#  METHOD:  scanAndTagC - for Syntax Highlight
+# ------------------------------------------------------------------
+itcl::body SrcTextWin::scanAndTagC {win} {
+  scan [$win index end] %d numLines
+
+  if {$numLines == {} || $numLines < 1} {
+    return
+  }
+  # tag language at first position
+  $win tag add hl_language_c 1.0 1.end
+  
+  # tagKeyword
+  #debug "tag Keyword $win $Linenums"
+  set keyWords [join { 
+  		(if) (then) (elif) (else) (do) (while) (for) 
+		(break) (continue) (next) (goto)
+		(switch) (case) (default)
+		(return)
+		(sizeof)
+		(namespace) (using)
+		(try) (catch) (throw)
+		(new) (delete)
+		(template) (public:) (protected:) (private:)
+		(public) (protected) (private)
+		(operator) (friend) (this)
+		} | ]
+
+  set typeWords [join { 
+		(__asm__) (__volatile__) (__attribute__) 
+		(__inline__) (__label__) 
+		(__complex__) (__real__) (__imag__)
+		(__typeof__) (__restrict__)
+		(inline) (virtual) (explicit)
+		(static) (extern) (auto) (register)
+		(typedef) (typeof) (typename)
+		(struct) (union) (enum) (class)
+		(const)	(volatile) (restrict)
+		(void) (char) (short) (int) (long)
+		(signed) (unsigned)
+		(float) (double)
+		(asm)
+		(size_t) (ssize_t) 
+		(wchar_t) 
+		(clock_t) (time_t) 
+		(va_list) (jmp_buf) 
+		(FILE) (DIR) 
+		(div_t) (ldiv_t)
+		(bool) (complex)
+		(int8_t) (int16_t) (int32_t) (int64_t)
+		(uint8_t) (uint16_t) (uint32_t) (uint64_t)
+		} | ]
+		
+  set constWords [join { 
+  		(__GNUC__) (__FUNCTION__) (__PRETTY_FUNCTION__)
+		(__LINE__) (__FILE__) (__DATE__) (__TIME__) (__STDC__)
+		(__STDC_VERSION__) (__ELF__)
+		(UCHAR_MAX) (UINT_MAX) (ULONG_MAX) (USHRT_MAX)
+		(CHAR_MIN) (INT_MIN) (LONG_MIN) (SHRT_MIN)
+		(CHAR_MAX) (INT_MAX) (LONG_MAX) (SHRT_MAX)
+		(SCHAR_MIN) (SINT_MIN) (SLONG_MIN) (SSHRT_MIN)
+		(SCHAR_MAX) (SINT_MAX) (SLONG_MAX) (SSHRT_MAX)
+		(LLONG_MAX) (ULLONG_MAX)
+		(INT8_MIN) (INT16_MIN) (INT32_MIN) (INT64_MIN)
+		(INT8_MAX) (INT16_MAX) (INT32_MAX) (INT64_MAX)
+		(UINT8_MAX) (UINT16_MAX) (UINT32_MAX) (UINT64_MAX)
+		(SIZE_MAX) (WCHAR_MIN) (WCHAR_MAX) (WINT_MIN) (WINT_MAX)
+		(LC_ALL) (LC_COLLATE) (LC_CTYPE) (LC_MONETARY) (LC_NUMERIC) (LC_TIME)
+		(SIG_ATOMIC_MIN) (SIG_ATOMIC_MAX)
+		(SIG_DFL) (SIG_ERR) (SIG_IGN)
+		(SIGABRT) (SIGFPE) (SIGILL) (SIGHUP) (SIGINT) (SIGSEGV) (SIGTERM)
+		(SIGABRT) (SIGALRM) (SIGCHLD) (SIGCONT) (SIGFPE) (SIGHUP)
+		(SIGILL) (SIGINT) (SIGKILL) (SIGPIPE) (SIGQUIT) (SIGSEGV)
+		(SIGSTOP) (SIGTERM) (SIGTRAP) (SIGTSTP) (SIGTTIN) (SIGTTOU)
+		(SIGUSR1) (SIGUSR2)
+		(_IOFBF) (_IOLBF) (_IONBF) (BUFSIZ) (EOF) (WEOF)
+		(FOPEN_MAX) (FILENAME_MAX) 
+		(SEEK_CUR) (SEEK_END) (SEEK_SET)
+		(stderr) (stdin) (stdout)
+		(E2BIG) (EACCES) (EAGAIN) (EBADF) (EBADMSG) (EBUSY)
+		(ECANCELED) (ECHILD) (EDEADLK) (EDOM) (EEXIST) (EFAULT)
+		(EFBIG) (EILSEQ) (EINPROGRESS) (EINTR) (EINVAL) (EIO) (EISDIR)
+		(EMFILE) (EMLINK) (EMSGSIZE) (ENAMETOOLONG) (ENFILE) (ENODEV)
+		(ENOENT) (ENOEXEC) (ENOLCK) (ENOMEM) (ENOSPC) (ENOSYS)
+		(ENOTDIR) (ENOTEMPTY) (ENOTSUP) (ENOTTY) (ENXIO) (EPERM)
+		(EPIPE) (ERANGE) (EROFS) (ESPIPE) (ESRCH) (ETIMEDOUT) (EXDEV)
+		(true) (false)
+		(TRUE) (FALSE)
+		} | ]
+  
+  set charWords {(['`].['`])|(['`]\\[abfnrv\\\"\'\?]['`])}
+  
+  set multiLineComment	0
+  set multiLinePreProc	0
+  set multiLineString	0
+  #
+  for {set i 1} {$i < $numLines} {incr i} {
+    # skip first (' ' or '-') char, the TAB and the number
+    if {$Linenums} {
+    	$win mark set last $i.2
+	set strLine [$win get last "last + 12 chars"]
+	if {[regexp -indices {([0-9])+} $strLine indices]} {
+		set idx_lo [lindex $indices 0]
+		set idx_hi [lindex $indices 1]
+		$win mark set first "last + $idx_lo chars"
+		$win mark set last  "last + $idx_hi chars + 1 chars"
+		$win tag add hl_linenum first last
+		set k [expr [lindex $indices 1] + 3]
+	}
+    } else {
+	# skip first ' ' or '-' char
+	set k 1
+    }
+    # tag commends and strings
+    $win mark set last $i.$k 
+    while { 1 } {
+    	set strLine [$win get last "last lineend"]
+	if {$strLine == {}} break
+	if { ($multiLineComment == 0) && ($multiLineString == 0) } {
+		# searching /* or "
+		if {[regexp -indices {(/\*)|(//)|(\")} $strLine indices]} {
+			set idx_lo [lindex $indices 0]
+			set idx_hi [lindex $indices 1]
+			$win mark set first "last + $idx_lo chars"
+			# is it /*,// or " 
+			if { [string index $strLine $idx_lo] != "/" } {
+				# it's quote " ;make sure it's not \"
+				if { $idx_lo == 0 || ($idx_lo > 0 && [string index $strLine [expr $idx_lo - 1]] != "\\") } {
+					$win mark set last  "last + $idx_hi chars + 1 chars"
+					set strLine [$win get last "last lineend"]
+					# is there a closing " too
+					set found_quote_end 0
+					while {[regexp -indices {(\")} $strLine indices]} {
+						set idx_hi [lindex $indices 1]
+						# also without make sure it's not \"
+						if { $idx_hi == 0 || ($idx_hi > 0 && [string index $strLine [expr $idx_hi - 1]] != "\\") } {
+							$win mark set last "last + 1 chars + $idx_hi chars"
+							$win tag add hl_lineString first last
+							set found_quote_end 1
+							break
+						}
+						$win mark set last "last + 1 chars + $idx_hi chars"
+    						set strLine [$win get last "last lineend"]
+					}
+					if {$found_quote_end == 0} {
+						# there is no quoting end in this line; seach for end of line
+						if {[regexp -indices {(.)$} $strLine indices]} {
+							set multiLineString 1
+							set idx_hi [lindex $indices 0]
+							$win mark set last "last + 1 chars + $idx_hi chars"
+							$win tag add hl_lineString first last
+							break
+						} else {
+							# something goes wrong
+							debug "missing lineend "
+							break
+						}
+					}
+				} else {
+					$win mark set last  "last + $idx_hi chars + 1 chars"
+				}
+			} elseif { [string index $strLine [expr $idx_lo + 1]] == "/" } {
+				# it's line comment //
+				if {[regexp -indices {(.)$} $strLine indices]} {
+					set idx_hi [lindex $indices 0]
+				} else {
+					debug "missing lineend"
+					set idx_hi [lindex $indices 1]
+				}
+				$win mark set first "last + $idx_lo chars"
+				$win mark set last "last + 1 chars + $idx_hi chars"
+				$win tag add hl_comment first last
+				break		
+			} else {
+				# it's a comment /*
+				$win mark set last  "last + $idx_hi chars"
+				set strLine [$win get last "last lineend"]
+				# is there a closing */ too
+				if {[regexp -indices {(\*/)} $strLine indices]} {
+					set idx_hi [lindex $indices 1]
+					$win mark set last "last + 1 chars + $idx_hi chars"
+					$win tag add hl_comment first last
+				} elseif {[regexp -indices {(.)$} $strLine indices]} {
+					set multiLineComment 1
+					set idx_hi [lindex $indices 0]
+					$win mark set last "last + 1 chars + $idx_hi chars"
+					$win tag add hl_comment first last
+					break
+				} else {
+					# something goes wrong
+					debug "missing lineend "
+					break
+				}
+			}
+		} else {
+			# no more // or /*
+			break
+		}
+		
+	} elseif { $multiLineComment == 0 } {
+		# multi line String
+		$win mark set first "last"
+		if {[regexp -indices {(\")} $strLine indices]} {
+			# it's quote " ;make sure it's not \"
+			set idx_hi [lindex $indices 1]
+			if { $idx_hi == 0 || ($idx_hi > 0 && [string index $strLine [expr $idx_hi - 1]] != "\\") } {
+				set multiLineString 0
+				$win mark set last "last + 1 chars + $idx_hi chars"
+				$win tag add hl_lineString first last
+			} else {
+				$win mark set last "last + 1 chars + $idx_hi chars"
+			}
+		} elseif {[regexp -indices {(.)$} $strLine indices]} {
+			set idx_hi [lindex $indices 0]
+			$win mark set last "last + 1 chars + $idx_hi chars"
+			$win tag add hl_lineString first last
+			break
+		} else {
+			# something goes wrong
+			debug "missing lineend "
+			break
+		}		
+	} else {
+		# multi line comments
+		$win mark set first "last"
+		if {[regexp -indices {(\*/)} $strLine indices]} {
+			set multiLineComment 0
+			set idx_hi [lindex $indices 1]
+			$win mark set last "last + 1 chars + $idx_hi chars"
+			$win tag add hl_comment first last
+		} elseif {[regexp -indices {(.)$} $strLine indices]} {
+			set idx_hi [lindex $indices 0]
+			$win mark set last "last + 1 chars + $idx_hi chars"
+			$win tag add hl_comment first last
+			break
+		} else {
+			# something goes wrong
+			debug "missing lineend "
+			break
+		}
+	}
+    }
+    # search for single chars and give those a tag
+    $win mark set last $i.$k 
+    set strLine [$win get last "last lineend"]
+    while {[regexp -indices $charWords $strLine indices]} {
+	set idx_lo [lindex $indices 0]
+	set idx_hi [lindex $indices 1]
+	$win mark set first "last + $idx_lo chars"
+	$win mark set last "last + 1 chars + $idx_hi chars"
+	set tag_names [$win tag names first]]
+	if {[regexp {(hl_comment)|(hl_lineString)} $tag_names] == 0} {
+		# only if it't not a comment
+		set cmpStr [string index $strLine [expr $idx_lo - 1]]
+		if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_]} $cmpStr] } {
+		} else {
+			set cmpStr [string index $strLine [expr $idx_hi + 1]]
+			if [regexp {^[0-9]|^[a-z]|^[A-Z]|^(_)} $cmpStr] {
+			} else {
+				$win tag add hl_charword first last
+			}
+		}
+	}
+	set strLine [$win get last "last lineend"]
+    }
+    # tag prepocessor directives
+    $win mark set last $i.$k
+    while (1) {
+    	set strLine [$win get last "last lineend"]
+	if { $multiLinePreProc == 0 } {
+		# search for a beginning #
+		if {[regexp -indices {(^([ \t])*#)} $strLine indices]} {
+			set idx_lo [lindex $indices 0]
+			set idx_hi [lindex $indices 1]
+			$win mark set first "last + $idx_lo chars"
+			$win mark set last  "last + $idx_hi chars"
+			set strLine [$win get first "first lineend"]
+			set strEndPos  [expr [string length $strLine] - 1]
+			# is there a reapet \
+			if {$strEndPos > 0} {
+				$win mark set last "last + 1 chars + $strEndPos chars"
+				$win tag add hl_preproc first last
+				if { [string index $strLine $strEndPos] == "\\" } {
+					set multiLinePreProc 1
+				} else {
+					# is there a <..> within this line
+					if {[regexp -indices {<([a-zA-Z0-9/\\\.]+)>} $strLine indices]} {
+						set idx_lo [lindex $indices 0]
+						set idx_hi [lindex $indices 1]
+						$win mark set last  "first + 1 chars + $idx_hi chars"
+						$win mark set first "first + $idx_lo chars"
+						$win tag add hl_lineString first last
+					}
+				}
+				break
+			} 
+		} 
+	} else {
+		# multi line derictives
+		$win mark set first "last"
+		set strLine [$win get first "first lineend"]
+		set strEndPos  [expr [string length $strLine] - 1]
+		if {$strEndPos > 0} {
+			$win mark set last "last + 1 chars + $strEndPos chars"
+			$win tag add hl_preproc first last
+			if { [string index $strLine $strEndPos] != "\\" } {
+				set multiLinePreProc 0
+			}
+			break
+		} 
+	}
+	break
+    }
+    # search for keywords and give those a tag
+    $win mark set last $i.$k 
+    set strLine [$win get last "last lineend"]
+    while {[regexp -indices $keyWords $strLine indices]} {
+	set idx_lo [lindex $indices 0]
+	set idx_hi [lindex $indices 1]
+	$win mark set first "last + $idx_lo chars"
+	$win mark set last "last + 1 chars + $idx_hi chars"
+	set tag_names [$win tag names first]
+	if {[regexp {(hl_comment)|(hl_preproc)|(hl_lineString)} $tag_names] == 0} {
+		# only if it't not a comment
+		set cmpStr [string index $strLine [expr $idx_lo - 1]]
+		if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] } {
+		} else {
+			set cmpStr [string index $strLine [expr $idx_hi + 1]]
+			if {[regexp {^[0-9]|^[a-z]|^[A-Z]|^[_\-\.]} $cmpStr] == 0} {
+				$win tag add hl_keyword first last
+			}
+		}
+	}
+	set strLine [$win get last "last lineend"]
+    }
+    # search for typewords and give those a tag
+    $win mark set last $i.$k 
+    set strLine [$win get last "last lineend"]
+    while {[regexp -indices $typeWords $strLine indices]} {
+	set idx_lo [lindex $indices 0]
+	set idx_hi [lindex $indices 1]
+	$win mark set first "last + $idx_lo chars"
+	$win mark set last "last + 1 chars + $idx_hi chars"
+	set tag_names [$win tag names first]
+	if {[regexp {(hl_comment)|(hl_preproc)|(hl_lineString)} $tag_names] == 0} {
+		# only if it't not a comment
+		set cmpStr [string index $strLine [expr $idx_lo - 1]]
+		if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] } {
+		} else {
+			set cmpStr [string index $strLine [expr $idx_hi + 1]]
+			if {[regexp {^[0-9]|^[a-z]|^[A-Z]|^[_\-\.]} $cmpStr] == 0} {
+				$win tag add hl_varword first last
+			}
+		}
+	}
+	set strLine [$win get last "last lineend"]
+    }	
+    # search for constWords and give those a tag
+    $win mark set last $i.$k 
+    set strLine [$win get last "last lineend"]
+    while {[regexp -indices $constWords $strLine indices]} {
+	set idx_lo [lindex $indices 0]
+	set idx_hi [lindex $indices 1]
+	$win mark set first "last + $idx_lo chars"
+	$win mark set last "last + 1 chars + $idx_hi chars"
+	set tag_names [$win tag names first]
+	if {[regexp {(hl_comment)|(hl_lineString)} $tag_names] == 0} {
+		# only if it't not a comment
+		set cmpStr [string index $strLine [expr $idx_lo - 1]]
+		if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] == 0} {
+			set cmpStr [string index $strLine [expr $idx_hi + 1]]
+			if {[regexp {^[0-9]|^[a-z]|^[A-Z]|^[_\.]} $cmpStr] == 0} {
+				$win tag add hl_constword first last
+			}
+		}
+	}
+	set strLine [$win get last "last lineend"]
+    }
+    # search for labels and give those a tag
+    $win mark set last $i.$k 
+    set strLine [$win get last "last lineend"]
+    if {[regexp -indices {^([ \t]*)([a-zA-Z_])([a-zA-Z0-9_])*:} $strLine indices]} {
+    	# skip leading space chars
+	regexp -indices {([a-zA-Z_])([a-zA-Z0-9_])*:} $strLine indices
+	set idx_lo [lindex $indices 0]
+	set idx_hi [lindex $indices 1]
+	$win mark set first "last + $idx_lo chars"
+	$win mark set last "last + 1 chars + $idx_hi chars"
+	set tag_names [$win tag names first]
+	if {[regexp {(hl_comment)|(hl_lineString)|(hl_keyword)|(hl_varword)|(hl_constword)} $tag_names] == 0} {
+		# only if it't not a comment and not c++ :: stuff
+		set strEndPos  [expr $idx_hi + 1]
+		if { [string index $strLine $strEndPos] != ":" } {
+			$win tag add hl_label first last
+		}
+	}
+    }
+    # search label branch
+    while {[regexp -indices {(goto)([ \t]+)([a-zA-Z_])([a-zA-Z0-9_])*} $strLine indices]} {
+	set idx_lo [lindex $indices 0]
+	set idx_hi [lindex $indices 1]
+	$win mark set first "last + 5 chars + $idx_lo chars"
+	$win mark set last "last + 1 chars + $idx_hi chars"
+	set tag_names [$win tag names first]
+	if {[regexp {(hl_comment)|(hl_lineString)} $tag_names] == 0} {
+		# only if it't not a comment
+		set cmpStr [string index $strLine [expr $idx_lo - 1]]
+		if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] == 0} {
+			set cmpStr [string index $strLine [expr $idx_hi + 1]]
+			if {[regexp {^[#:\-\.]} $cmpStr] == 0} {
+				$win tag add hl_label first last
+			}
+		}
+	}
+	set strLine [$win get last "last lineend"]
+    }    
+    #next line
+  }
+
+}
+
+
 # ------------------------------------------------------------------
 #  METHOD:  LoadFile - loads in a new source file
 # ------------------------------------------------------------------
@@ -1271,6 +1999,73 @@
       #}
       UnLoadFromCache $w $oldpane $name "" $lib
       return 0
+    }
+  }
+  
+  # do the scan if requested
+  scanAndTagTextWidget $win $name
+
+  # recheck if we still have to highlight the syntax
+  set tag_names [$win tag names]
+
+  if {  ($withSynHl_C == 1 && [regexp hl_language_c $tag_names])
+     || ($withSynHl_GAS == 1 && [regexp hl_language_gas $tag_names])} {
+    # highlight taged Keywords
+    if {[regexp hl_comment $tag_names]} {
+	$win tag configure hl_comment -foreground Blue
+    }
+    if {[regexp hl_preproc $tag_names]} {
+	$win tag configure hl_preproc -foreground purple
+    }
+    if {[regexp hl_keyword $tag_names]} {
+	$win tag configure hl_keyword -foreground Red
+    }
+    if {[regexp hl_varword $tag_names]} {
+	$win tag configure hl_varword -foreground DarkGreen
+    }
+    if {[regexp hl_linenum $tag_names]} {
+	$win tag configure hl_linenum -foreground DarkGray
+    }
+    if {[regexp hl_lineString $tag_names]} {
+	$win tag configure hl_lineString -foreground DarkOrange4
+    }
+    if {[regexp hl_constword $tag_names]} {
+	$win tag configure hl_constword -foreground "dark salmon"
+    }
+    if {[regexp hl_charword $tag_names]} {
+	$win tag configure hl_charword -foreground "dark cyan"
+    }
+    if {[regexp hl_label $tag_names]} {
+	$win tag configure hl_label -foreground "dark cyan"
+    }
+  } else {
+    # dis-highlight taged Keywords
+    if {[regexp hl_comment $tag_names]} {
+	$win tag configure hl_comment -foreground black
+    }
+    if {[regexp hl_preproc $tag_names]} {
+	$win tag configure hl_preproc -foreground black
+    }
+    if {[regexp hl_keyword $tag_names]} {
+	$win tag configure hl_keyword -foreground black
+    }
+    if {[regexp hl_varword $tag_names]} {
+	$win tag configure hl_varword -foreground black
+    }
+    if {[regexp hl_linenum $tag_names]} {
+	$win tag configure hl_linenum -foreground black
+    }
+    if {[regexp hl_lineString $tag_names]} {
+	$win tag configure hl_lineString -foreground black
+    }
+    if {[regexp hl_constword $tag_names]} {
+	$win tag configure hl_constword -foreground black
+    }
+    if {[regexp hl_charword $tag_names]} {
+	$win tag configure hl_charword -foreground black
+    }
+    if {[regexp hl_label $tag_names]} {
+	$win tag configure hl_label -foreground black
     }
   }
   set current(filename) $name
diff -rubB original_src/gdb/gdbtk/library/srctextwin.ith modified_src/gdb/gdbtk/library/srctextwin.ith
--- original_src/gdb/gdbtk/library/srctextwin.ith	Thu Aug  4 12:07:49 2005
+++ modified_src/gdb/gdbtk/library/srctextwin.ith	Thu Aug  4 15:51:58 2005
@@ -108,6 +108,8 @@
     
     variable timeoutID {} ;# The timeout ID for the variable balloon help
     variable UseVariableBalloons
+    variable withSynHl_C
+    variable withSynHl_GAS
     
     variable mode_changed 0
     variable current	;# our current state
@@ -134,6 +136,9 @@
     method _initialize_srctextwin {}
     method _clear_cache {}
     method _highlightAsmLine {win addr pc_addr tagname filename funcname} {}
+    method scanAndTagTextWidget {win name} {}
+    method scanAndTagC {win} {}
+    method scanAndTagASM {win} {}
 
     proc makeBreakDot {size colorList {image {}}}
   }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]