2010-08-14 21:59:25 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2010-07-21 04:57:35 +04:00
/***
This file is part of systemd .
Copyright 2010 Lennart Poettering
systemd is free software ; you can redistribute it and / or modify it
2012-04-12 02:20:58 +04:00
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation ; either version 2.1 of the License , or
2010-07-21 04:57:35 +04:00
( at your option ) any later version .
systemd is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
2012-04-12 02:20:58 +04:00
Lesser General Public License for more details .
2010-07-21 04:57:35 +04:00
2012-04-12 02:20:58 +04:00
You should have received a copy of the GNU Lesser General Public License
2010-07-21 04:57:35 +04:00
along with systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
# include <unistd.h>
# include <string.h>
# include "util.h"
# include "log.h"
# include "strv.h"
int main ( int argc , char * argv [ ] ) {
const char * env [ ] = {
" FOO=BAR BAR " ,
" BAR=waldo " ,
NULL
} ;
const char * line [ ] = {
" FOO$FOO " ,
" FOO$FOOFOO " ,
" FOO${FOO}$FOO " ,
" FOO${FOO} " ,
" ${FOO} " ,
" $FOO " ,
" $FOO$FOO " ,
" ${FOO}${BAR} " ,
" ${FOO " ,
NULL
} ;
2011-01-06 22:38:02 +03:00
char * * i , * * r , * t , * * a , * * b ;
2011-02-23 03:12:07 +03:00
const char nulstr [ ] = " fuck \0 fuck2 \0 fuck3 \0 \0 fuck5 \0 \0 xxx " ;
a = strv_parse_nulstr ( nulstr , sizeof ( nulstr ) - 1 ) ;
STRV_FOREACH ( i , a )
printf ( " nulstr--%s \n " , * i ) ;
strv_free ( a ) ;
2010-07-21 04:57:35 +04:00
r = replace_env_argv ( ( char * * ) line , ( char * * ) env ) ;
STRV_FOREACH ( i , r )
printf ( " %s \n " , * i ) ;
strv_free ( r ) ;
2011-01-05 18:06:35 +03:00
t = normalize_env_assignment ( " foo=bar " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " =bar " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " foo= " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " = " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " a= \" waldo \" " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " a= \" waldo " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " a=waldo \" " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " a= \' " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " a= \' \' " ) ;
printf ( " %s \n " , t ) ;
free ( t ) ;
2012-09-20 00:01:31 +04:00
t = normalize_env_assignment ( " xyz " ) ;
printf ( " <%s> \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " xyz = bar " ) ;
printf ( " <%s> \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " xyz = 'bar ' " ) ;
printf ( " <%s> \n " , t ) ;
free ( t ) ;
t = normalize_env_assignment ( " ' xyz' = 'bar ' " ) ;
printf ( " <%s> \n " , t ) ;
free ( t ) ;
2011-01-06 22:38:02 +03:00
a = strv_new ( " FOO=BAR " , " WALDO=WALDO " , " WALDO= " , " PIEP " , " SCHLUMPF=SMURF " , NULL ) ;
b = strv_new ( " FOO=KKK " , " FOO= " , " PIEP= " , " SCHLUMPF=SMURFF " , " NANANANA=YES " , NULL ) ;
r = strv_env_merge ( 2 , a , b ) ;
strv_free ( a ) ;
strv_free ( b ) ;
STRV_FOREACH ( i , r )
printf ( " %s \n " , * i ) ;
printf ( " CLEANED UP: \n " ) ;
r = strv_env_clean ( r ) ;
STRV_FOREACH ( i , r )
printf ( " %s \n " , * i ) ;
strv_free ( r ) ;
2011-01-05 18:06:35 +03:00
return 0 ;
2010-07-21 04:57:35 +04:00
}