Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/search.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH library - SEARCH (STRING) - Copyright 2003,2004 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

\ Load COMPARE when needed
[UNDEFINED] compare [IF]
[needs lib/compare.4th]
[THEN]

[UNDEFINED] search [IF]
: search
  swap >r >r over             ( a1 n1 a1)
  over r@ - r> swap           ( a1 n1 a1 n2 n3)
  begin
    dup -1 >                  ( a1 n1 a1 n2 n3 f)
    if                        ( a1 n1 a1 n2 n3)
      -rot 2dup               ( a1 n1 n3 a1 n2 a1 n2)
      r@ over                 ( a1 n1 n3 a1 n2 a1 n2 a2 n2)
      compare                 ( a1 n1 n3 a1 n2 f)
      if                      ( a1 n1 n3 a1 n2)
        swap char+ swap       ( a1 n1 n3 a1+1 n2)
        rot 1- false          ( a1 n1 a1+1 n2 n3 -f)
      else                    ( a1 n1 n3 a1 n2)
        rot +                 ( a1 n1 a1 n2+n3)
        2>r 2drop 2r>         ( a1 n2+n3)
        true dup              ( a1 n2+n3 f f)   
      then
    else                      ( a1 n1 a1 n2 n3)
      drop 2drop false true
    then                      ( a1 n1 -f f)
  until 
  r> drop
;
[THEN]


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].