sufreplace
Adriaan de Groot <adridg-FlD2LfDziEhmR6Xm/[email protected]>
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
I see that current CVS' sufreplace requires that the source and target suffix
begin with a ".". Why was this restriction introduced? It makes sufreplace()
useless for my purposes [1].
FWIW, here's a version of sufreplace() (based on AAP 1.006's sufreplace())
that uses var2dictlist for the dirty work (like my earlier suffixmangle). The
RE's become a little simpler, and attributes are preserved.
def sufreplace(suffrom, sufto, var):
"""Replace suffixes in "var" from "suffrom" to "sufto"."""
# TODO: make this more robust; don't change directory names
try:
r = var2dictlist(var)
for i in r:
t=i.get("name")
if t:
if not suffrom:
i["name"]=re.sub("\\.[^. \t/]+$", sufto, t)
else:
i["name"]=re.sub(string.replace(suffrom, ".", "\\.") +
"$",sufto, t)
return dictlist2str(r)
except StandardError, e:
recipe_error([], _('sufreplace() failed: ') + str(e))
return None # not reached
[1] My purposes involve those damn "fake sources" again. I have a file foo.h,
which really is a C++ header file. However, it contains some extra
annotations, and it can be converted through a series of tools to foo_skel.cc
or foo_stub.cc . The convention I've been using is to write somethng like
"SOURCES=foo.skel" (to indicate that I want "foo.h" to be used and converted
to "foo_skel.cc") and then doing
:program bar : `sufreplace(".skel","_skel.cc",SOURCES)`
which is still a lousy approach, but it worked. Not anymore, since I can't
start the replacement suffix with _ now.
I guess the only possibility left is to use {var_OBJSUF=_skel.o} now, as long
as src2obj() doesn't use sufreplace().
--
pub 1024D/FEA2A3FE 2002-06-18 Adriaan de Groot <[email protected]>
Key fingerprint = 934E 31AA 80A7 723F 54F9 50ED 76AC EE01 FEA2 A3FE
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01