Mailinglist Archive: yast-devel (57 mails)

< Previous Next >
[yast-devel] Re: [yast-commit] r65171 - in /branches/SuSE-Code-11-SP2-Branch/fcoe-client/src: FcoeClient.ycp complex.ycp dialogs.ycp
Dne 3.8.2011 14:56, gs@xxxxxxxxxxxxxxxxx napsal(a):
+ foreach( string line, (list<string>)lines, {
+ if ( regexpmatch( line, "^FCOE_ENABLE" ) )
+ {
+ status_map = add( status_map, "FCOE_ENABLE",
deletechars( substring(line, 12), "\"") );
+ }
+ if ( regexpmatch( line, "^DCB_REQUIRED" ) )
+ {
+ status_map = add( status_map, "DCB_REQUIRED",
deletechars( substring( line, 13 ),"\"") );
+ }
+ if ( regexpmatch( line, "^AUTO_VLAN" ) )
+ {
+ status_map = add( status_map, "AUTO_VLAN", deletechars(
substring( line, 10 ),"\"") );
+ }
+ });


Using a string literal and a constant with it's length is pretty vulnerable to
mistakes. Moreover the stucture is repeated and there is a nice
String::StartsWith()
function instead of the regexp.

This code allows easy adding of new variables:

foreach( string line, (list<string>)lines, {
foreach(string var, ["FCOE_ENABLE", "DCB_REQUIRED", "AUTO_VLAN"], {
if (String::StartsWith(line, var))
{
status_map = add( status_map, var, deletechars( substring(line,
size(var) +
1), "\"") );
}
});
});



Actually you don't have to manually parse /etc/fcoe/cfg-eth* files at all, it
seems
that these files are standard sysconfig files. The ini-agent support multiple
files
via * wildcard.

See e.g. yast2/library/network/agents/network.scr agent definition for reading
/etc/sysconfig/network/ifcfg-* files.

Your simple parser will wrongly parse lines like AUTO_VLAN = "foo"
(note the spaces around '=') and other valid definitions (comments after value
etc).


--

Best Regards

Ladislav Slezák
Yast Developer
------------------------------------------------------------------------
SUSE LINUX, s.r.o. e-mail: lslezak@xxxxxxx
Lihovarská 1060/12 tel: +420 284 028 960
190 00 Prague 9 fax: +420 284 028 951
Czech Republic http://www.suse.cz/
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups