Skip to content
Snippets Groups Projects
Select Git revision
  • 2ca6cdb4bb56cb15fc784258b7669f9be95387c5
  • master default protected
  • 9.0
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

sed.pmod

Blame
  • sed.pmod 6.09 KiB
    #pike __REAL_VERSION__
    
    //! 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
    
    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[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]);
    
       if (flags["p"]) pr+=({t});
    
       s=(w||"")+t;
       if (flags["g"])
       {
          if (lastmod) 
          {
    	 array wa;
    	 wa=sedreplace(a[-1],re,with,whatin,first,lastmod,flags);