public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* Re: [RFC] syntax highlighting
@ 2005-08-04 17:35 Th.R.Klein
  0 siblings, 0 replies; 19+ messages in thread
From: Th.R.Klein @ 2005-08-04 17:35 UTC (permalink / raw)
  To: insight

Hi

Sorry to bore you with my attachments.
But there seems to be a bug in my current Mozilla Thunderbird version.
Sorry about that

  cheers
    Thomas

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
  2005-08-26 10:02     ` Dave Korn
@ 2005-08-26 20:22       ` Christopher Faylor
  0 siblings, 0 replies; 19+ messages in thread
From: Christopher Faylor @ 2005-08-26 20:22 UTC (permalink / raw)
  To: insight

On Fri, Aug 26, 2005 at 11:01:05AM +0100, Dave Korn wrote:
>----Original Message----
>>From: Steven Johnson
>>Sent: 25 August 2005 22:24
>
>>Which would support an on going position of all major changes be in
>>their own files, that are copyright assigned to the FSF, just like
>>normal GDB.  Then only trivial changes (hooks and the like) are in the
>>Redhat code.  Then (in the "dream of one day") that code wouldnt be a
>>problem for an assignment.  It would also be possible, that a specific
>>comment could be put in such a file stating that the hooks to this code
>>have also been assigned to the FSF, so that there is even less of a
>>problem.
>>
>>Also, it would mean if one day someone took the view or re-implementing
>>all the Redhat copyright code, they wouldnt have to re-implement the
>>contributed stuff.
>
>You know, it occurs to me to wonder whether new contributions could be
>assigned jointly to redhat and the fsf.

So, that would be double the amount of paperwork, then?

cgf

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [RFC] syntax highlighting
  2005-08-25 21:23   ` Steven Johnson
@ 2005-08-26 10:02     ` Dave Korn
  2005-08-26 20:22       ` Christopher Faylor
  0 siblings, 1 reply; 19+ messages in thread
From: Dave Korn @ 2005-08-26 10:02 UTC (permalink / raw)
  To: insight

----Original Message----
>From: Steven Johnson
>Sent: 25 August 2005 22:24


> Which would support an on going position of all major changes be in
> their own files, that are copyright assigned to the FSF, just like
> normal GDB.  Then only trivial changes (hooks and the like) are in the
> Redhat code.  Then (in the "dream of one day") that code wouldnt be a
> problem for an assignment.  It would also be possible, that a specific
> comment could be put in such a file stating that the hooks to this code
> have also been assigned to the FSF, so that there is even less of a
> problem. 
> 
> Also, it would mean if one day someone took the view or re-implementing
> all the Redhat copyright code, they wouldnt have to re-implement the
> contributed stuff.


  You know, it occurs to me to wonder whether new contributions could be
assigned jointly to redhat and the fsf.



    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
  2005-08-25 18:33 ` Keith Seitz
@ 2005-08-25 21:23   ` Steven Johnson
  2005-08-26 10:02     ` Dave Korn
  0 siblings, 1 reply; 19+ messages in thread
From: Steven Johnson @ 2005-08-25 21:23 UTC (permalink / raw)
  To: insight

Keith Seitz wrote:

> Jon Beniston wrote:
>
>>> Sorry but I do not understand where I've done something that 
>>> violates the existing copyright.
>>
>>  
>> You haven't.
>
>
> Correct -- you haven't done anything wrong in any way even remotely 
> imaginable.
>
[Snip]

>
>>
>> The only reason I can see why you need to assign copyright is so that 
>> Red
>> Hat can license Insight under a different (non-free) license. But 
>> maybe I'm
>> being a tad cynical.
>
>
> Well, I can't speak for that, because I'm pretty sure Red Hat is 
> finished with Insight (so much so that I can't even get 10 minutes 
> from an attorney to sign paperwork assigning Red Hat's copyrights to 
> the FSF).
>
> I am simply following the FSF's rules for development. If you make a 
> non-trivial change to the code (and I'm usually quite generous with 
> what I consider trivial), we need to have you (and your employer, if 
> necessary) assign copyright to us. [For a more official explanation of 
> why this is done, see 
> http://www.fsf.org/licensing/licenses/why-assign.html/view?searchterm=assignment 
>  .]
>
> In Insight's case, the compelling reason AFAIAC is specifically for 
> the dream of one day assigning all of insight over to the FSF. If the 
> FSF suspects for a moment that some chunk of code doesn't have 
> sufficient legal proof that we own the copyright, it will be rejected.

Which would support an on going position of all major changes be in
their own files, that are copyright assigned to the FSF, just like
normal GDB.  Then only trivial changes (hooks and the like) are in the
Redhat code.  Then (in the "dream of one day") that code wouldnt be a
problem for an assignment.  It would also be possible, that a specific
comment could be put in such a file stating that the hooks to this code
have also been assigned to the FSF, so that there is even less of a problem.

Also, it would mean if one day someone took the view or re-implementing
all the Redhat copyright code, they wouldnt have to re-implement the
contributed stuff.

(Digressing from this point)

Redhat might think Insight is dead, but in the last couple of days, ive
seen a large number of embedded tools vendors web sites, peddling GNU
Tools where the included debugger is Insight/GDB.  So for some people,
they just dont see it as dead, or see any viable alternatives.  Maybe
what should happen is these companies that make money off of Insight
should pool their resources, and get together with Redhat, and pay them
to release the code to the FSF, for the good of all. I suspect those
vendors would be subscribed to this list, so yes, im talking to you.

It also seems, if Redhat arent interested enough to fill out a standard
FSF Assignment document, then they probably wont be interested in
providing an assignment document for Insight to major contributors
either (seems about the same amount of work).  Which means maybe a fork
is the only way forward for those who want to continue to see Insight
prosper.  Then the fork can work on the job of removing the Redhat
code.  For a dream of one day brining the sanitized fork back into the
mainline.  But weve had similar discussions like this before.

Steven

PS.  Nothing in this is intended as a flame or other derogatory
statement of anybody or company, i dont want to see this turn into a
flame war, as that is hardly productive for anybody.  Im just proposing
alternatives, and im not particularly wed to any proposition ive made,



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
       [not found]             ` <20050825195933.041274A805F@cgf.cx>
@ 2005-08-25 20:54               ` Christopher Faylor
  0 siblings, 0 replies; 19+ messages in thread
From: Christopher Faylor @ 2005-08-25 20:54 UTC (permalink / raw)
  To: insight, Jon Beniston

On Thu, Aug 25, 2005 at 08:58:44PM +0100, Jon Beniston wrote:
>>>Good point.  That is true for Cygwin though, isn't it?
>>
>>No, cygwin doesn't incorporate GPLed code owned by other sources.
>
>I meant the fact that RedHat offer a non-free license, which is why
>copyright has to be assigned.  Anyway, just to be clear, I'm cool with
>that.  Nothing wrong with making money from your hard work.  It's much
>appreciated.

Oh.  Sorry!  Yes, Red Hat offers a non-free license for Cygwin and makes
$$$ from it every year.

I don't work for Red Hat anymore, though, so I'm sure they greatly
appreciate my efforts.  :-)

Red Hat does (or used to) sell Insight but it's sold like any other
GPLed product that they provide.  In that case Red Hat benefits from
Keith's non-paid activities since he only works on insight as a "hobby",
like me.

cgf

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [RFC] syntax highlighting
  2005-08-25 19:13           ` Christopher Faylor
@ 2005-08-25 19:59             ` Jon Beniston
       [not found]             ` <20050825195933.041274A805F@cgf.cx>
  1 sibling, 0 replies; 19+ messages in thread
From: Jon Beniston @ 2005-08-25 19:59 UTC (permalink / raw)
  To: insight


> >Good point.  That is true for Cygwin though, isn't it?
> 
> No, cygwin doesn't incorporate GPLed code owned by other sources.

I meant the fact that RedHat offer a non-free license, which is why
copyright has to be assigned. Anyway, just to be clear, I'm cool with that.
Nothing wrong with making money from your hard work. It's much appreciated.

Cheers,
Jon

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
       [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>
  0 siblings, 2 replies; 19+ messages in thread
From: Christopher Faylor @ 2005-08-25 19:13 UTC (permalink / raw)
  To: insight, Jon Beniston

On Thu, Aug 25, 2005 at 08:06:09PM +0100, Jon Beniston wrote:
>> >The only reason I can see why you need to assign copyright 
>>Additionally, since insight intertwines itself with gdb, I don't
>>believe you could sell it as non-free anyway since gdb's GPL would
>>trump any other license.
>
>Good point.  That is true for Cygwin though, isn't it?

No, cygwin doesn't incorporate GPLed code owned by other sources.

cgf
--
Christopher Faylor			spammer? ->	aaaspam@sourceware.org
Cygwin Co-Project Leader				aaaspam@duffek.com
TimeSys, Inc.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [RFC] syntax highlighting
  2005-08-25 18:34       ` Christopher Faylor
@ 2005-08-25 19:06         ` Jon Beniston
       [not found]         ` <20050825190632.D45444A8059@cgf.cx>
  1 sibling, 0 replies; 19+ messages in thread
From: Jon Beniston @ 2005-08-25 19:06 UTC (permalink / raw)
  To: insight


> >The only reason I can see why you need to assign copyright 
> is so that 
> >Red Hat can license Insight under a different (non-free) 
> license.  But 
> >maybe I'm being a tad cynical.
> 
> Yes, just a tad.
> Additionally, since insight intertwines itself with gdb, I 
> don't believe you could sell it as non-free anyway since 
> gdb's GPL would trump any other license.

Good point. That is true for Cygwin though, isn't it?

Cheers,
Jon

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
       [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>
  0 siblings, 2 replies; 19+ messages in thread
From: Christopher Faylor @ 2005-08-25 18:34 UTC (permalink / raw)
  To: 'Th.R.Klein', insight, Jon Beniston

On Thu, Aug 25, 2005 at 07:05:20PM +0100, Jon Beniston wrote:
>On Thu, Aug 25, 2005 at 07:56:33PM +0200, Th.R.Klein wrote:
>>Sorry but I do not understand where I've done something that violates
>>the existing copyright.
>
>You haven't.
>
>>As far as I'm interpreting this, I'm allowed to modify the source e.g.
>>by adding the syntax highlighting stuff to it.
>
>You are.  If you want to take all the source and start your own fork
>that's fine.
>
>>Red Hat itself might have a set of rules which kind of modification
>>they accept and which they will reject.
>
>The only reason I can see why you need to assign copyright is so that
>Red Hat can license Insight under a different (non-free) license.  But
>maybe I'm being a tad cynical.

Yes, just a tad.

The FSF requires similar license transferrals for gdb and no one ever
accused them of trying to provide things under a non-free license.

In the Insight case, I believe that Red Hat wants to make sure that all
of the code ownership is clear so that there will be no claims where a
company insists that they own some snippet of code added by an employee.
I believe that this is the same reason that the FSF requires similar
transfer of ownership for major changes to gdb, gcc, binutils, etc.

Additionally, since insight intertwines itself with gdb, I don't believe
you could sell it as non-free anyway since gdb's GPL would trump any
other license.

cgf

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
       [not found] <200508251805.j7PI5q4A015633@mx1.redhat.com>
@ 2005-08-25 18:33 ` Keith Seitz
  2005-08-25 21:23   ` Steven Johnson
  0 siblings, 1 reply; 19+ messages in thread
From: Keith Seitz @ 2005-08-25 18:33 UTC (permalink / raw)
  To: 'Th.R.Klein'; +Cc: Jon Beniston, insight

Jon Beniston wrote:
>>Sorry but I do not understand where I've done something that 
>>violates the existing copyright.
>  
> You haven't.

Correct -- you haven't done anything wrong in any way even remotely 
imaginable.

>>As far as I'm interpreting this, I'm allowed to modify the 
>>source e.g. 
>>by adding the syntax highlighting stuff to it. 
> 
> You are. If you want to take all the source and start your own fork that's
> fine.

Absolutely correct.

>>Red Hat itself might have a set of rules which kind of 
>>modification they accept and which they will reject.
> 
> The only reason I can see why you need to assign copyright is so that Red
> Hat can license Insight under a different (non-free) license. But maybe I'm
> being a tad cynical.

Well, I can't speak for that, because I'm pretty sure Red Hat is 
finished with Insight (so much so that I can't even get 10 minutes from 
an attorney to sign paperwork assigning Red Hat's copyrights to the FSF).

I am simply following the FSF's rules for development. If you make a 
non-trivial change to the code (and I'm usually quite generous with what 
I consider trivial), we need to have you (and your employer, if 
necessary) assign copyright to us. [For a more official explanation of 
why this is done, see 
http://www.fsf.org/licensing/licenses/why-assign.html/view?searchterm=assignment 
  .]

In Insight's case, the compelling reason AFAIAC is specifically for the 
dream of one day assigning all of insight over to the FSF. If the FSF 
suspects for a moment that some chunk of code doesn't have sufficient 
legal proof that we own the copyright, it will be rejected.

Keith

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [RFC] syntax highlighting
  2005-08-25 17:49   ` Th.R.Klein
@ 2005-08-25 18:05     ` Jon Beniston
       [not found]     ` <20050825180548.A35334A8054@cgf.cx>
  1 sibling, 0 replies; 19+ messages in thread
From: Jon Beniston @ 2005-08-25 18:05 UTC (permalink / raw)
  To: 'Th.R.Klein'; +Cc: insight

> Sorry but I do not understand where I've done something that 
> violates the existing copyright.

You haven't.

> As far as I'm interpreting this, I'm allowed to modify the 
> source e.g. 
> by adding the syntax highlighting stuff to it. 

You are. If you want to take all the source and start your own fork that's
fine.

> Red Hat itself might have a set of rules which kind of 
> modification they accept and which they will reject.

The only reason I can see why you need to assign copyright is so that Red
Hat can license Insight under a different (non-free) license. But maybe I'm
being a tad cynical.

Cheers,
Jon

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
  2005-08-23 20:31 ` Keith Seitz
  2005-08-23 22:12   ` Steven Johnson
@ 2005-08-25 17:49   ` Th.R.Klein
  2005-08-25 18:05     ` Jon Beniston
       [not found]     ` <20050825180548.A35334A8054@cgf.cx>
  1 sibling, 2 replies; 19+ messages in thread
From: Th.R.Klein @ 2005-08-25 17:49 UTC (permalink / raw)
  To: Keith Seitz; +Cc: insight

Hi,

Keith Seitz wrote:
> Barring that, there is one more hurdle to overcome: copyright. Unlike 
> most of the patches that I see here, this patch definitely is not even 
> remotely trivial. So we need to get you (and your company if involved) 
> to sign an assignment. The problem is, that assignment is to Red Hat, 
> not the FSF, since Insight is officially owned (albeit carelessly) by 
> Red Hat.

Sorry but I do not understand where I've done something that violates 
the existing copyright.
The file header includes something like this:
...
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License (GPL) as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
...

As far as I'm interpreting this, I'm allowed to modify the source e.g. 
by adding the syntax highlighting stuff to it. The copyright remains as 
it was before.
If like that other people can use this modification too, I have either 
to redistribute it myself or I have to ask an existing distributer to do so.
Since Red Hat is the major distributer of Insight it would be great to 
find it there.
Red Hat itself might have a set of rules which kind of modification they 
accept and which they will reject.
If so, it would be nice to this available. So we can produce patches 
that fit.
Maybe Red Hat isn't interested in any kind off patches.
So it would be nice to know this, too.

Again, I haven't understand everything correctly, so it is likely that 
I've got it wrong.

At the current stage I'm a little bit frustrated.

Regards
   Thomas

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
  2005-08-23 22:12   ` Steven Johnson
@ 2005-08-24  3:51     ` Christopher Faylor
  0 siblings, 0 replies; 19+ messages in thread
From: Christopher Faylor @ 2005-08-24  3:51 UTC (permalink / raw)
  To: insight

On Wed, Aug 24, 2005 at 09:11:44AM +1100, Steven Johnson wrote:
>I dont think there is any rule that says a whole file needs to be
>Copyright to a single entity.

Sorry but there is a rule.  Red Hat (like the FSF) wants to maintain the
copyright to the entire work.  That's why Keith raised this issue.

There is no way around this other than to either get an official waiver
from Red Hat or to just decide that they really don't care and do it
anyway.

cgf

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
  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
  1 sibling, 1 reply; 19+ messages in thread
From: Steven Johnson @ 2005-08-23 22:12 UTC (permalink / raw)
  To: Keith Seitz; +Cc: insight, Th.R.Klein

Keith Seitz wrote:

> 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.
>
>
> I apologize for the long delay, but I'm really conflicted on this patch.
>
> As much as I would like to see syntax highlighting, I'm not entirely 
> sure that I like the approach that has been taken. I would prefer, of 
> course, a real parser for these things. Gdb contains parsers for 
> C/C++, Java, ADA, and whatever else is supported.

Whats the story with those?  I thought it was only for expression 
passing, so you could enter expressions like the language you are 
debugging? 

>
> On the other hand, we have nothing today. Zippo. Nadda. That's a 
> compelling reason to take what you've kindly offered.
>
> So I guess the best compromise for me is to accept your patch, BUT, I 
> would like to see it a bit more modular, so that the parsing engine 
> can be replaced with something more efficient. I think the actual 
> parsing or regexp'ing should be done in a separate class.

I agree that it being more modular would be good.  But what is being 
offered is better than nothing, especially as it can be enabled/disabled 
as the user feels.

>
> Barring that, there is one more hurdle to overcome: copyright. Unlike 
> most of the patches that I see here, this patch definitely is not even 
> remotely trivial. So we need to get you (and your company if involved) 
> to sign an assignment. The problem is, that assignment is to Red Hat, 
> not the FSF, since Insight is officially owned (albeit carelessly) by 
> Red Hat.


I dont think there is any rule that says a whole file needs to be 
Copyright to a single entity.  Parts of a file can have different 
Copyright status. How you manage that efficiently and unambiguously in 
an open source project, I dont know. What I have seen in the past, in 
open source projects that use modified code from different sources, is 
headers that say things like (as an example):

# Original file Copyright Redhat (c) 2000,2001,2002,2003,2004,2005
# Portions Copyright FSF (c) 2005

Whether that is appropriate in this case is unknown.

As the whole file is distributed under the GPL, there is no impediment 
to modifying the file and having those modifications have any copyright 
you like, provided you obey the GPL.  Which is what this project does, 
so no problem.  The only reason I think the FSF insists on copyright 
assignment is so it can keep better control of its core projects, and 
litigate on infringements if required.  Otherwise it isnt required given 
the words of the GPL.  There are certainly lots of GPL projects that 
dont worry about assignment of copyright, and instead just rely on the 
words of the GPL to cover the modifications contributed by various others.

It would obviously be cleaner to separate the substantial parts out into 
separate files, and then there would be no impediment to assigning those 
files to the FSF.  Then the "hooks" in the original code would belong to 
the "insubstantial" category of change.

Steven

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
  2005-08-03 21:12 Th.R.Klein
  2005-08-03 21:49 ` Steven Johnson
  2005-08-04  6:13 ` Steven Johnson
@ 2005-08-23 20:31 ` Keith Seitz
  2005-08-23 22:12   ` Steven Johnson
  2005-08-25 17:49   ` Th.R.Klein
  2 siblings, 2 replies; 19+ messages in thread
From: Keith Seitz @ 2005-08-23 20:31 UTC (permalink / raw)
  To: Th.R.Klein; +Cc: insight

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.

I apologize for the long delay, but I'm really conflicted on this patch.

As much as I would like to see syntax highlighting, I'm not entirely 
sure that I like the approach that has been taken. I would prefer, of 
course, a real parser for these things. Gdb contains parsers for C/C++, 
Java, ADA, and whatever else is supported.

On the other hand, we have nothing today. Zippo. Nadda. That's a 
compelling reason to take what you've kindly offered.

So I guess the best compromise for me is to accept your patch, BUT, I 
would like to see it a bit more modular, so that the parsing engine can 
be replaced with something more efficient. I think the actual parsing or 
regexp'ing should be done in a separate class.

Barring that, there is one more hurdle to overcome: copyright. Unlike 
most of the patches that I see here, this patch definitely is not even 
remotely trivial. So we need to get you (and your company if involved) 
to sign an assignment. The problem is, that assignment is to Red Hat, 
not the FSF, since Insight is officially owned (albeit carelessly) by 
Red Hat.

I haven't a clue how complicated this will be, but I know that Cygwin is 
in a similar position.

I will ask the Cygwin maintainers for advice, and I'll get back to you 
off-list.

Please don't despair -- I haven't forgotten about anybody or his 
patches. [Although a gentle reminder works wonders every once in a 
while! :-)]

Keith

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [RFC] syntax highlighting
  2005-08-04  6:13 ` Steven Johnson
@ 2005-08-04 10:25   ` Dave Korn
  0 siblings, 0 replies; 19+ messages in thread
From: Dave Korn @ 2005-08-04 10:25 UTC (permalink / raw)
  To: 'Steven Johnson', 'Th.R.Klein'; +Cc: insight

----Original Message----
>From: Steven Johnson
>Sent: 05 August 2005 05:15

> 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.

  And can I also ask you send it as an attachment, rather than inline with
your text please?  I had to manually unwrap a bunch of lines, and the
version in the web archive has lost all its indentation; it's always better
to send patches as attachments to prevent them being processed.

  Anyway, I'll give this patch a go as well.  I agree with Steven's points;
it needs to be en/dis-ableable, and it need to be parameterized to tie in
with gdb's notion of source language in some way.  I wonder if there isn't
some existing language-agnostic open-source syntax highlighting component we
could plug in in some way?  I'll have a bit of a browse on the web over the
weekend.

  Thomas and Vineeth, thank you both for your efforts.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
  2005-08-03 21:12 Th.R.Klein
  2005-08-03 21:49 ` Steven Johnson
@ 2005-08-04  6:13 ` Steven Johnson
  2005-08-04 10:25   ` Dave Korn
  2005-08-23 20:31 ` Keith Seitz
  2 siblings, 1 reply; 19+ messages in thread
From: Steven Johnson @ 2005-08-04  6:13 UTC (permalink / raw)
  To: Th.R.Klein; +Cc: insight

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
>
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC] syntax highlighting
  2005-08-03 21:12 Th.R.Klein
@ 2005-08-03 21:49 ` Steven Johnson
  2005-08-04  6:13 ` Steven Johnson
  2005-08-23 20:31 ` Keith Seitz
  2 siblings, 0 replies; 19+ messages in thread
From: Steven Johnson @ 2005-08-03 21:49 UTC (permalink / raw)
  To: Th.R.Klein; +Cc: insight

This is a good idea. Im not sure of anyone else doing this, so the work 
is very appreciated.

My comments are as follows:
1. What variant of Assembler are you syntax highlighting here?  There 
are many varients, using different comment characters, asm directives, 
opcode directives, etc. 

2. It would be useful, if your comment block for the 2 "hard coded" 
highlighters (the asm one especially) defined the types of things you 
are scanning for and highlighting. (what are the keywords, comments, 
etc.) it would make understanding the code easier.

3. It would be useful if the extensions that used one or other of the 
hard-coded highlighters could be set by the user in a configuration 
option. Or maybe even dynamically from the test widget (im thinking a 
little drop down that lets you select, for a window, highlight "asm" 
"c/c++" "none".  While auto choosing is good, sometimes it isnt what you 
want.  Some people dont like syntax highlighting, so there should be an 
option to turn it off.

4. Also, GDB can debug other languages.  It would be great if there was 
a parameterised "soft coded" syntax highlighter. So the user could (say, 
for a given extension) set what the end of line comments are, keywords, 
etc and get any file to syntax highlight. Looking at it, it seems all of 
the languages youve got already, "asm" and "c" could be done with a 
common "Tager" that was parameterised, rather than hard coded. 

5. Colors, you should be able to select from the config what colors you 
want to use to highlight.  Ideally, you would want to be able to set 
differnet colors for different highlighters. 

6. Regarding the comment "The method isn't the fastest but it seems OK 
for the moment. "  It seems OK, from a code complexity perspective to 
me, if it might be slow on some PC's, then a global enable option, which 
bypasses all of this, and just does what Insight does now would be a 
good option, then a user could say "bugger this its just too slow for 
me" and revert to the existing behaviour, that would have negligible 
performance impact.

Ill try and test it this week also.  If you can add a parameter to 
globally "enable"/"disable" this to the config page, and it works as 
expected, then i would be advocating its checking in to the source tree, 
so its in future snapshots.  Then further work like paramterising, 
refining etc, can be worked on.  I wouldnt want to see this added to the 
source tree if it forced everyone to use it (which is why i suggest the 
"global enable" option).

Good work though.
Steven


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

[snip patch]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [RFC] syntax highlighting
@ 2005-08-03 21:12 Th.R.Klein
  2005-08-03 21:49 ` Steven Johnson
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Th.R.Klein @ 2005-08-03 21:12 UTC (permalink / raw)
  To: insight

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2005-08-26 20:22 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-04 17:35 [RFC] syntax highlighting 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
  -- strict thread matches above, loose matches on Subject: below --
2005-08-03 21:12 Th.R.Klein
2005-08-03 21:49 ` Steven Johnson
2005-08-04  6:13 ` Steven Johnson
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

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).