Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

desdata.c

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    Process.pmod 5.85 KiB
    #pike __REAL_VERSION__
    
    #define error(X) throw( ({ (X), backtrace()[0..sizeof(backtrace())-2] }) )
    
    import Stdio;
    
    #if !constant(strerror)
    #define strerror(X) ("errno="+X)
    #endif
    
    program create_process = __builtin.create_process;
    
    int exec(string file,string ... foo)
    {
      if (sizeof(file)) {
        string path;
    
        if(search(file,"/") >= 0)
          return exece(combine_path(getcwd(),file),foo,getenv());
    
        path=getenv("PATH");
    
        foreach(path ? path/":" : ({}) , path)
          if(file_stat(path=combine_path(path,file)))
    	return exece(path, foo,getenv());
      }
      return 69;
    }
    
    string sh_quote(string s)
    {
      return replace(s,
    	({"\\", "'", "\"", " "}),
    	({"\\\\", "\\'", "\\\"","\\ "}));
    }
    
    array(string) split_quoted_string(string s)
    {
      sscanf(s,"%*[ \n\t]%s",s);
      s=replace(s,
    	    ({"\"",  "'",  "\\",  " ",  "\t",  "\n"}),
    	    ({"\0\"","\0'","\0\\","\0 ","\0\t","\0\n"}));
      array(string) x=s/"\0";
      array(string) ret=({x[0]});
    
      for(int e=1;e<sizeof(x);e++)
      {
        switch(x[e][0])
        {
          case '"':
          ret[-1]+=x[e][1..];
          while(x[++e][0]!='"')
          {
    	if(strlen(x[e])==1 && x[e][0]=='\\' && x[e+1][0]=='"') e++;
    	ret[-1]+=x[e];
          }
          ret[-1]+=x[e][1..];
          break;
    
          case '\'':
          ret[-1]+=x[e][1..];
          while(x[++e][0]!='\'') ret[-1]+=x[e][1..];
          ret[-1]+=x[e][1..];
          break;
          
          case '\\':
          if(strlen(x[e])>1)
          {
    	ret[-1]+=x[e][1..];
          }else{