generic classes for safe %macro substitution

Oswald Buddenhagen ossi at kde.org
Wed Jan 1 17:01:41 GMT 2003


moin!

as macro expansions (aka "expandos") are needed all over the place, i've
written some classes for this task. they handle four types of expandos
(with/without prefix * explicity/implicitly delimited) and two types of
substitution (plain-text (for display) and bourne-shell escaped (for
::system, kshellprocess, etc.)).
the shell-quote part needs some attention. the code contains a parser
that tracks quoting in all posix-constructs and some bash extensions.
i think i got the shell syntax right so far. however, bash has a bug
which makes using expandos within double-quoted substitutions inherently
insecure, so never use constructs like 'theprog "${foo:-%bar}"'. i also
considered refusing macro expansion in this case, but i think users
which use such complex constructs can be expected to know how their
shell works (and not everybody has a broken /bin/sh, so why should we
prevent them from using it the way they want). we should only put a
warning in the documentation.

the class names are somewhat scary. if you can think of equally
descriptive shorter names, then yell.

the derived classes got messier than expected, to be honest.
do you think it would make sense to remove the non-static versions of
the functions together with the set*() methods?

in case you're wondering about the "goto nohit" ... i looked at the asm
gcc generates for the complex expression i originally used and it was
not fun. so i helped it a bit ...

give it some hammering.
simply save the attachements, adopt the paths in Makefile and run
make && ./kmxtest.
some docu needs to be added before i can add it to kdelibs/kdecore,
obviuosly.

greetings

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmacroexpander.h
Type: text/x-chdr
Size: 4495 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030101/48ee6c40/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmacroexpander.cpp
Type: text/x-c++src
Size: 12048 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030101/48ee6c40/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmxtest.cpp
Type: text/x-c++src
Size: 1064 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030101/48ee6c40/attachment-0001.cpp>
-------------- next part --------------
CFLAGS := -O2 -march=$(shell uname -m) -g -W -Wall
CXXFLAGS := $(CFLAGS) -fno-exceptions

QTDIR := /usr/local/kde
#KMXDIR := $(HOME)/src/kde/3.x/kdelibs/kdecore
KMXDIR := .

kmxtest: kmxtest.o kmacroexpander.o
	$(CXX) -o $@ $^ -L$(QTDIR)/lib -lqt-mt

kmxtest.o: kmxtest.cpp $(KMXDIR)/kmacroexpander.h
	$(CXX) $(CXXFLAGS) -o $@ -c $< -I$(QTDIR)/include -I$(KMXDIR)

kmacroexpander.o: $(KMXDIR)/kmacroexpander.cpp $(KMXDIR)/kmacroexpander.h
	$(CXX) $(CXXFLAGS) -o $@ -c $< -I$(QTDIR)/include -I$(KMXDIR)

clean:
	rm -f *.o *.s kmxtest


More information about the kde-core-devel mailing list