Am 03.08.2011 16:05, schrieb Ladislav Slezak:
Dne 3.8.2011 14:56, [email protected] 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.
Thanks for the hint, I use String::StartsWith now (and also respect white spaces).

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.
I had a look at network.scr before but didn't succeed to use such a agent for FCoE config. I will have another look.

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: [email protected]
Lihovarská 1060/12                              tel: +420 284 028 960
190 00 Prague 9                                 fax: +420 284 028 951
Czech Republic                                  http://www.suse.cz/


--
Gabriele Mohr
SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg)
Maxfeldstr. 5                  Tel:    +49 911 740 53 362
90409 Nürnberg                 Email:  [email protected]
-----------------------------------------------------------------
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to