Re: SetApplication Parsing

Brian Paul <[email protected]>
Newsgroups gmane.comp.graphics.chromium.devel
Message-ID <[email protected]>
Chris Johnson wrote:
> Hi.
> 
>    It seems that if I include superfluous spaces in the string I pass to the client node's SetApplication method, not all of them are parsed away as field separators.  For instance,
> 
>    client_node.SetApplication ('my_app  arg1')
>                                       ^^
> will load my_app with 3 arguments ('my_app', '', and 'arg1').  However, 
> 
>    client_node.SetApplication ('my_app arg1')
>                                       ^
> runs as expected.  This is in contrast to the AutoStart method, which uses Python's split function and handles multiple IFSes.
> 
>    Perhaps there is a reason SetApplication does not behave the same.  If so, please let me know.  For the time being, I've changed the following CRApplicationNode method in mothership.py.
> 
>    def SetApplication( self, app ):
>       """SetApplication(name)
>       Sets the name of the application that's run."""
>       self.Conf('application', string.join (string.split (app)))
> 
>    I think everyone else does parentheses different than me.
> 

Looks like the problem is in the crStrSplitn() function, or rather, 
how it's used in the crappfaker code.

crStrSplit("a b  c") returns the array of strings: ["a", "b", "", "c", 
NULL].

In Python, string.split('a b  c', ' ') returns ['a', 'b', '', 'c']
so crStrSplit() is consistant with that.

Interestingly though, string.split("a b  c") returns ['a', 'b', 'c'].

Try the attached patch to app_faker/app_faker.c.  It removes the empty 
strings from the argument vector.

-Brian
patch (text/plain, 1.5 KB)
? patch
Index: app_faker.c
===================================================================
RCS file: /cvsroot/chromium/cr/app_faker/app_faker.c,v
retrieving revision 1.29
diff -c -r1.29 app_faker.c
*** app_faker.c	5 Apr 2004 15:14:04 -0000	1.29
--- app_faker.c	1 Jul 2004 21:20:15 -0000
***************
*** 777,788 ****
  	if ( argc < 1 )
  	{
  		/* No command specified, contact the configuration server to 
! 		* ask what I should do. */
  
! 		faked_argv = crStrSplit( chain[1], " " );
  
  		crMothershipGetFakerParam( mothership_conn, response, "start_dir" );
- 
  		if (chdir( response ))
  		{
  			crError( "Couldn't change to the starting directory: %s", response );
--- 773,801 ----
  	if ( argc < 1 )
  	{
  		/* No command specified, contact the configuration server to 
! 		 * ask what I should do.
! 		 */
! 		char **c, **argvTemp = crStrSplit( chain[1], " " );
! 		int i, numArgs = 0;
! 		/* count number of non-empty args */
! 		for (c = argvTemp; *c; c++)
! 			if (c[0][0])
! 				numArgs++;
! 
! 		/* now, make faked_argv array of strings, skipping empty strings */
! 		faked_argv = (char **) crCalloc((numArgs + 1) * sizeof(char*));
! 		for (i = 0, c = argvTemp; *c; c++) {
! 			if (c[0][0])
! 				faked_argv[i++] = c[0];
! 			else
! 				crFree(c[0]); /* no longer needed */
! 		}
! 		faked_argv[i] = NULL;
  
! 		/* free the array, but not the strings */
! 		crFree(argvTemp);
  
  		crMothershipGetFakerParam( mothership_conn, response, "start_dir" );
  		if (chdir( response ))
  		{
  			crError( "Couldn't change to the starting directory: %s", response );
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.