pike.git / lib / modules / Process.pmod

version» Context lines:

pike.git/lib/modules/Process.pmod:380:   {    // Remove initial white-space.    sscanf(s,"%*[ \n\t]%s",s);       // Prefix interesting characters with NUL,    // and split on NUL.    s=replace(s,    ({"\"", "'", "\\", " ", "\t", "\n", "\0"}),    ({"\0\"","\0'","\0\\","\0 ","\0\t","\0\n", "\0\0"}));    array(string) x=s/"\0"; -  array(string) ret=({x[0]}); +  array(string) ret = ({}); +  string last = x[0]; +  int always_keep_last;    -  + piece_loop:    for(int e=1;e<sizeof(x);e++)    {    string piece = x[e];    if (!sizeof(piece)) {    // Escaped NUL. -  ret[-1] += "\0"; +  last += "\0";    e++;    continue;    }    switch(piece[0])    {    case '"': -  ret[-1]+=piece[1..]; +  last+=piece[1..];    while(sizeof (x) > e + 1 && (piece = x[++e])[0]!='"')    {    if(sizeof(piece)==1 && piece[0]=='\\' && x[e+1][0]=='"')    piece = x[++e]; -  ret[-1]+=piece; +  last+=piece;    } -  ret[-1]+=piece[1..]; +  last+=piece[1..]; +  always_keep_last = 1;    break;       case '\'': -  ret[-1]+=piece[1..]; -  while(sizeof (x) > e + 1 && (piece = x[++e])[0]!='\'') ret[-1]+=piece; -  ret[-1]+=piece[1..]; +  last+=piece[1..]; +  while(sizeof (x) > e + 1 && (piece = x[++e])[0]!='\'') last+=piece; +  last+=piece[1..]; +  always_keep_last = 1;    break;       case '\\':    if(sizeof(piece)>1)    {    if (nt_mode) {    // On NT we only escape special characters with \;    // other \'s we keep verbatim. -  ret[-1]+=piece; +  last+=piece;    } else { -  ret[-1]+=piece[1..]; +  last+=piece[1..];    }    }else if (sizeof (x) > e + 1) {    // Escaped special character. -  ret[-1]+=x[++e]; +  last+=x[++e];    }    break;       case ' ':    case '\t':    case '\n':    while(sizeof(piece)==1)    {    if(e+1 < sizeof(x))    {    if((<' ','\t','\n'>) [x[e+1][0]])    piece = x[++e];    else    break;    }else{ -  return ret; +  break piece_loop;    }    } -  ret+=({piece[1..]}); +  if (sizeof (last) || always_keep_last) +  ret += ({last}); +  last = piece[1..];    break;       default: -  ret[-1]+="\0"+piece; +  last+="\0"+piece;    break;    }    } -  +  if (sizeof (last) || always_keep_last) +  ret += ({last});    return ret;   }      Process spawn(string command, void|Stdio.Stream stdin,    void|Stdio.Stream stdout, void|Stdio.Stream stderr,    // These aren't used. Seems to be part of something unfinished. /mast    //function|void cleanup, mixed ... args    )   //! Spawns a process that executes @[command] as a command shell   //! statement ("@expr{/bin/sh -c @[command]@}" for Unix, "@expr{cmd /c