public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
From: Steven Johnson <sjohnson@sakuraindustries.com>
To: "Th.R.Klein" <Th.R.Klein@web.de>
Cc: insight@sources.redhat.com
Subject: Re: [RFC] syntax highlighting
Date: Thu, 04 Aug 2005 06:13:00 -0000	[thread overview]
Message-ID: <42F2E7DF.2010303@sakuraindustries.com> (raw)
In-Reply-To: <42F134B1.8080805@web.de>

Hi,

With some work, i was able to apply the patch.

In future, could you prepare your patch on the whole GDB/Insight Tree, 
instead of the individual files.

something like
diff -Naur original_gdb modified_gdb

anyway, your changes work fine.  It did seem there was a little delay 
between selecting the file and it appearing in the window, but nothing 
that was objectionable for me. (Other peoples mileage may vary).  After 
this small delay, it seemed no slower for me than before. (I could have 
been imagining the delay).

I would really like to see it parameterised though.  It would be 
usefull.  Especially the global enable/disable.

Also, before it could be applied (and i cant give the ok for that) you 
would also need a changelog entry.

Steven Johnson

Th.R.Klein wrote:

> Hi
>
> I've ask Vineeth if the developing of the Patch already have started.
> Since Vineeth told me that this is not the case.
> So I'm sending here a patch, which should carefully reviewed.
> The method isn't the fastest but it seems OK for the moment.
>
>    cheers,
>       Thomas
>
> PS. 733 PATCH lines following
> #####################################################################
> --- srctextwin.ith.orig    Mon Aug  1 18:56:18 2005
> +++ srctextwin.ith    Mon Aug  1 18:59:16 2005
> @@ -134,6 +134,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 {}}}
>    }
> --- srctextwin.itb.orig    Mon Aug  1 18:56:17 2005
> +++ srctextwin.itb    Mon Aug  1 20:59:37 2005
> @@ -1247,6 +1247,680 @@
>    }
>  }
>
> +
> +# ------------------------------------------------------------------
> +#  METHOD:  scanAndTagTextWidget - for Syntax Highlight
> +# ------------------------------------------------------------------
> +itcl::body SrcTextWin::scanAndTagTextWidget {win name} {
> +  if {[regexp {(.+)(\.)([chCH])([+pP])*$} $name ignore]} {
> +    scanAndTagC $win
> +  } elseif {[regexp {(.+)(\.)(([sS])|([aA][sS][mM]))$} $name ignore]} {
> +    scanAndTagASM $win
> +  }
> +}
> +
> +# ------------------------------------------------------------------
> +#  METHOD:  scanAndTagASM - for Syntax Highlight
> +# ------------------------------------------------------------------
> +itcl::body SrcTextWin::scanAndTagASM {win} {
> +  set keyWords {(\.)([a-zA-Z0-9])+}
> +
> +  scan [$win index end] %d numLines
> +  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} {
> +  # 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\\\"\'\?]['`])}
> +
> +  scan [$win index end] %d numLines
> +  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
>  # ------------------------------------------------------------------
> @@ -1272,6 +1946,36 @@
>        UnLoadFromCache $w $oldpane $name "" $lib
>        return 0
>      }
> +    scanAndTagTextWidget $win $name
> +  }
> +  # higlight taged Keywords
> +  set tag_names [$win tag names]
> +  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"
>    }
>    set current(filename) $name
>    # Display all breaks/traces
>
>

  parent reply	other threads:[~2005-08-04  6:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-03 21:12 Th.R.Klein
2005-08-03 21:49 ` Steven Johnson
2005-08-04  6:13 ` Steven Johnson [this message]
2005-08-04 10:25   ` Dave Korn
2005-08-23 20:31 ` Keith Seitz
2005-08-23 22:12   ` Steven Johnson
2005-08-24  3:51     ` Christopher Faylor
2005-08-25 17:49   ` Th.R.Klein
2005-08-25 18:05     ` Jon Beniston
     [not found]     ` <20050825180548.A35334A8054@cgf.cx>
2005-08-25 18:34       ` Christopher Faylor
2005-08-25 19:06         ` Jon Beniston
     [not found]         ` <20050825190632.D45444A8059@cgf.cx>
2005-08-25 19:13           ` Christopher Faylor
2005-08-25 19:59             ` Jon Beniston
     [not found]             ` <20050825195933.041274A805F@cgf.cx>
2005-08-25 20:54               ` Christopher Faylor
2005-08-04 17:35 Th.R.Klein
     [not found] <200508251805.j7PI5q4A015633@mx1.redhat.com>
2005-08-25 18:33 ` Keith Seitz
2005-08-25 21:23   ` Steven Johnson
2005-08-26 10:02     ` Dave Korn
2005-08-26 20:22       ` Christopher Faylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42F2E7DF.2010303@sakuraindustries.com \
    --to=sjohnson@sakuraindustries.com \
    --cc=Th.R.Klein@web.de \
    --cc=insight@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).