Subject: CVS steve: * Two utility functions, particularly useful for writing modules:

From: CVS <[email-masked]>
Date: Sun, 6 Jun 1999 20:26:03 -0500 (CDT)

CVSROOT:	/home/cvs/fvwm
Module name:	fvwm
Changes by:	steve	99/06/06 20:26:02

Modified files:
	.              : ChangeLog 
	fvwm           : fvwm.h repeat.c virtual.c 
	libs           : Module.c Module.h Picture.c Picture.h Strings.c 
	                 Strings.h System.c fvwmlib.h 

Log message:
* Two utility functions, particularly useful for writing modules:

1. ParseModuleArgs - parse arguments that FVWM passes to a module,
extracting the file descriptors, window, optional alias, etc, etc.

2. StrHasPrefix - check if a string has a given prefix.

* Other (minor) cleanup.

--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Mon, 7 Jun 1999 11:14:25 -0600

> 2. StrHasPrefix - check if a string has a given prefix.

There is a similar function in libs/Parse.c already: GetModuleResource().
Perhaps it should be moved into libs/Module.c, but I don't think we need
the function twice.

Bye

Dominik ^_^

-- 
Dominik Vogt, Hewlett-Packard GmbH, Dept. BVS
Herrenberger Str.130, 71034 Boeblingen, Germany
phone: 07031/14-4596, fax: 07031/14-3883, [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Steve Robbins <[email-masked]>
Date: Mon, 7 Jun 1999 09:14:07 -0400 (EDT)

> Perhaps it should be moved into libs/Module.c, but I don't think we need

To me, GetModuleResource() doesn't look at all similar to either of the
two functions I added.  Please elaborate.

---

From: Dominik Vogt <[email-masked]>
Date: Mon, 7 Jun 1999 17:02:18 -0600

> two functions I added.  Please elaborate. 

OK, GetModuleResource() doesn't *check* if the string begins with
*ModuleName, but checks and then returns the string following
*ModuleName (without a blank). This is similar enough for me.

Bye

Dominik ^_^

---

From: Steve Robbins <[email-masked]>
Date: Mon, 7 Jun 1999 11:40:55 -0400 (EDT)

On Mon, 7 Jun 1999, Dominik Vogt wrote:

> *ModuleName (without a blank).

AND it does up to two malloc()s and one free()
AND it requires the prefix to begin with '*'.

GetModuleResource() is much more specialised than what I wrote --- which
is basically a strncasecmp() call. 

I wrote it because I saw a lot of

      }else if (strncasecmp(tline,CatString3("*",MyName,
      else if (strncasecmp(tline,"ImagePath",9)==0)
      else if (strncasecmp(tline,"ClickTime",9)==0)
      else if (strncasecmp(tline,"ColorLimit",10)==0) {

in the module code.

When I changed IconPath & PixmapPath to ImagePath, I missed updating a few
of the string lengths, which caused crashes.  I thought StrHasPrefix()
might spare someone this pain in future. 

But you're right to point out the similarities with GetModuleResource(),
since these strncasecmp()'s really are a parsing step.  The next
instruction is often something like 

	CopyString (&imagePath, &tline[9]);

in which case a routine that checks the prefix (without mandating an
asterisk) and returns the next token would be a win.  But does there need
to be all these mallocs and frees?

---

From: Dominik Vogt <[email-masked]>
Date: Mon, 7 Jun 1999 17:55:56 -0600

>       else if (strncasecmp(tline,"ColorLimit",10)==0) {

That bothers me too, but I'd prefer a different approach of cleaning
this up. Just call GetModuleResource() once to strip the *ModuleName
from 'tline' and then use StrEquals() to do the comparisons.

> might spare someone this pain in future. 

Using str*n*casecmp is stupid anyway. Reading the word after *ModuleName
and comparing against that seems to be the right way.

> to be all these mallocs and frees? 

No, of course not. We can as well have a PeekModuleResource function
like we have PeekToken vs. GetNextToken.

Hmm, your function is a good start. It can be used without large changes in
the modules and prevents some future (and perhaps present).

Bye

Dominik ^_^

---

From: Tim Phipps <[email-masked]>
Date: Mon, 07 Jun 1999 17:14:40 +0100

> from 'tline' and then use StrEquals() to do the comparisons.

This won't work.  "ColorLimit" is sent to each module not
*FvwmModuleColorLimit.  Fvwm send a bunch of global config things in
response to a send_config request from a module but since fvwm doesn't
know what name the module is looking for it can't prepend the module
name in front of the ColorLimit line.

Cheers,
Tim.

---

From: Dominik Vogt <[email-masked]>
Date: Mon, 7 Jun 1999 18:21:36 -0600

> name in front of the ColorLimit line.

... yes, but for the other 999 cases the prefixing is useful.

Bye

Dominik ^_^