// KPM.bcpl -- test for KPMTemplate package
// Copyright Xerox Corporation 1979

external
[
SetupReadParam; ReadParam
MakeKPMTemplate; MatchKPMTemplate
Puts; Ws; Free

sysZone; dsp
]

structure String: [ length byte; char↑1,255 byte ]


//-----------------------------------------------------------------
let KPM() be
//-----------------------------------------------------------------
[
let pattern, string = vec 127, vec 127
SetupReadParam()
   [
   ReadParam($P, "Pattern: ", pattern)
   ReadParam($P, "String: ", string)
   let template = MakeKPMTemplate(pattern)
   let code = MatchKPMTemplate(string, template)
   test code eq 0
      ifso Ws("String matches pattern.*n")
      ifnot test code eq 1
         ifso Ws("String doesn't match pattern at all.*n")
         ifnot
            [
            Ws("String matches pattern only through *"")
            for i = 1 to code-1 do Puts(dsp, string>>String.char↑i)
            Ws("*"*n")
            ]
   Free(sysZone, template)
   ] repeat
]