pike.git / lib / modules / Tools.pmod / sed.pmod

version» Context lines:

pike.git/lib/modules/Tools.pmod/sed.pmod:1:   #pike __REAL_VERSION__    - // edit commands supported: - // <firstline>,<lastline><edit command> - // ^^ numeral (17) ^^ - // or relative (+17, -17) - // or a search regexp (/regexp/) - // or multiple (17/regexp//regexp/+2) - // - // D - delete first line in space - // G - insert hold space - // H - append current space to hold space - // P - print current data - // a<string> - insert - // c<string> - change current space - // d - delete current space - // h - copy current space to hold space - // i<string> - print string - // l - print current space - // p - print first line in data - // q - quit evaluating - // s/regexp/with/x - replace - // y/chars/chars/ - replace chars - // - // where line is numeral, first 'line'==0 + //! edit commands supported: + //! @pre{ + //! <firstline>,<lastline><edit command> + //! ^^ numeral (17) ^^ + //! or relative (+17, -17) + //! or a search regexp (/regexp/) + //! or multiple (17/regexp//regexp/+2) + //! @} + //! + //! @xml{ + //! <matrix> + //! <r><c><b>Command</b></c><c><b>Action</b></c></r> + //! <r><c>D</c><c>Delete first line in space</c></r> + //! <r><c>G</c><c>Insert hold space</c></r> + //! <r><c>H</c><c>Append current space to hold space</c></r> + //! <r><c>P</c><c>Print current data</c></r> + //! <r><c>a&lt;string&gt;</c><c>Insert</c></r> + //! <r><c>c&lt;string&gt;</c><c>Change current space</c></r> + //! <r><c>d</c><c>Delete current space</c></r> + //! <r><c>h</c><c>Copy current space to hold space</c></r> + //! <r><c>i&lt;string&gt;</c><c>Print string</c></r> + //! <r><c>l</c><c>Print current space</c></r> + //! <r><c>p</c><c>Print first line in data</c></r> + //! <r><c>q</c><c>Quit evaluating</c></r> + //! <r><c>s/regexp/with/x</c><c>Replace</c></r> + //! <r><c>y/chars/chars/</c><c>Replace chars</c></r> + //! </matrix> + //! @} + //! + //! where line is numeral, first 'line'==0    - static array sedreplace(string s,object re,string with, + protected array sedreplace(string s,object re,string with,    array whatin,int first,int lastmod,    multiset flags)   {    array a;    string w=0;    array pr=({});       if (!(a=re->split(s)))    return 0;       if (first)    {    array wa;    wa=sedreplace(a[0],re,with,whatin,first,lastmod,flags);    if (wa)    if (!flags["g"]) -  return ({wa[0],wa[1]+s[strlen(a[0])..]}); +  return ({wa[0],wa[1]+s[sizeof(a[0])..]});    else    pr=wa[0],w=wa[1];    else    w=a[0];    }       string t=    replace(with,whatin[..sizeof(a)-first+lastmod-1],    a[first..sizeof(a)+lastmod-1]);   
pike.git/lib/modules/Tools.pmod/sed.pmod:69:    else    s+=a[-1];    }    }    else    s+=a[-1];       return ({pr,s});   };    - static array scan_for_linenumber(string cmd, + protected array scan_for_linenumber(string cmd,    array(string) in,    int n)   {    int x;    string what;    object re;       while (cmd!="" && ((cmd[0]>='0' && cmd[0]<='9')    || cmd[0]=='/' || cmd[0]=='+' || cmd[0]=='-'))    {
pike.git/lib/modules/Tools.pmod/sed.pmod:110:    if (re->match(in[n])) break;    n++;    }    }    else break;    }    if (n<0) n=0; else if (n>=sizeof(in)) n=sizeof(in)-1;    return ({n,cmd});   }    + //!   string|array `()(string|array(string) commands,    string|array(string) data,    void|int suppress)   {    int start,stop;    string div,what,with,inflags;    multiset flags;    array whatin=({"\\1","\\2","\\3","\\4","\\5","\\6","\\7","\\8","\\9"});    array print=({});    array hold=({});
pike.git/lib/modules/Tools.pmod/sed.pmod:195:    }       break;       case 'y':    div=cmd[1..1];    if (div=="%") div="%%";    inflags="";    if (sscanf(cmd,"%*c"+div+"%s"+div+"%s"+div+"%s",    what,with,inflags)<3) continue; -  if (strlen(what)!=strlen(with)) +  if (sizeof(what)!=sizeof(with))    { -  what=what[0..strlen(with)-1]; -  with=with[0..strlen(what)-1]; +  what=what[0..sizeof(with)-1]; +  with=with[0..sizeof(what)-1];    }       a1=what/"",a2=with/"";       while (start<=stop)    {    in[start]=replace(in[start],a1,a2);    start++;    }    break;
pike.git/lib/modules/Tools.pmod/sed.pmod:272:    return (arrayp(data)?(print):(print*"\n"));       default:    // error? just ignore for now    }    }    if (!suppress)    return (arrayp(data)?(print+in):(print+in)*"\n");    return (arrayp(data)?(print):(print*"\n"));   } -  -  -  +