Skip to content
Snippets Groups Projects
Commit 7a1aacdd authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

execl-cmdline: add -s features

parent b92bda30
No related branches found
No related tags found
No related merge requests found
......@@ -12,42 +12,85 @@
* except according to the terms contained in the LICENSE file./
*/
#include <oblibs/string.h>
#include <oblibs/stralist.h>
#include <oblibs/error2.h>
#include <skalibs/stralloc.h>
#include <skalibs/strerr2.h>
#include <skalibs/genalloc.h>
#include <skalibs/env.h>
#include <skalibs/djbunix.h>
#include <skalibs/sgetopt.h>
#include <execline/execline.h>
#define USAGE "execl-cmdline [ -s ] { command... }"
int main(int argc, char const **argv, char const *const *envp)
{
int r, argc1 ;
int r, argc1, split ;
PROG = "execl-cmdline" ;
stralloc tmodifs = STRALLOC_ZERO ;
stralloc modifs = STRALLOC_ZERO ;
genalloc ga = GENALLOC_ZERO ;
r = 0 ;
r = argc1 = split = 0 ;
argc1 = el_semicolon(++argv) ;
if (argc1 >= --argc) strerr_dief1x(100, "unterminated block") ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = subgetopt_r(argc, argv, "s", &l) ;
if (opt == -1) break ;
switch (opt)
{
case 's' : split = 1 ; break ;
default : exitusage() ;
}
}
argc -= l.ind ; argv += l.ind ;
}
argc1 = el_semicolon(argv) ;
if (argc1 >= argc) strerr_dief1x(100, "unterminated block") ;
argv[argc1] = 0 ;
char const **newargv = argv ;
for (int i = 0;i<argc1;i++, newargv++)
for (int i = 0; i < argc1 ; i++, newargv++)
{
if (!*newargv[0])
continue ;
stralloc_cats(&modifs,*newargv) ;
stralloc_0(&modifs) ;
if (!stralloc_cats(&tmodifs,*newargv)) retstralloc(111,"tmodifs") ;
if (split)
{
if (!stralloc_cats(&tmodifs," ")) retstralloc(111,"tmodifs") ;
}
else if (!stralloc_0(&tmodifs)) retstralloc(111,"tmodifs_0") ;
r++;
}
if (split)
{
if (!clean_val(&ga,tmodifs.s)) strerr_diefu2x(111,"clean val: ",tmodifs.s) ;
for (unsigned int i = 0 ; i < genalloc_len(stralist,&ga) ; i++)
{
stralloc_cats(&modifs,gaistr(&ga,i)) ;
stralloc_0(&modifs) ;
}
r = genalloc_len(stralist,&ga) ;
genalloc_deepfree(stralist,&ga,stra_free) ;
}
else if (!stralloc_copy(&modifs,&tmodifs)) retstralloc(111,"copy") ;
stralloc_free(&tmodifs) ;
char const *newarg[r + 1] ;
if (!env_make(newarg, r, modifs.s, modifs.len)) strerr_diefu1sys(111, "env_make") ;
newarg[r] = 0 ;
xpathexec_run(newarg[0],newarg,envp) ;
//el_execsequence(newarg, argv+argc1+1, envp) ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment