0 Glob (Pattern Matching)

This routine performs a primitive type of pattern matching. Its main use in the TI-83+/TI-84+ implementation of BBC BASIC (Z80) is filtering filenames when using the *DIR command.

A%=0:CALL&4083,result%,pattern$,input$

pattern$ defines the pattern to check input$ against. result% is the output of the routine and will equal TRUE if input$ matched pattern$, FALSE otherwise.

The pattern can contain one of two wildcard characters:

The pattern is case-insensitive. Here are some examples of patterns:

pattern$ input$ result%
test test TRUE
test TEST TRUE
cat dog FALSE
*og dog TRUE
*og frog TRUE
b??k bank TRUE
b??k book TRUE
b??k brick FALSE
b*k brick TRUE

pattern$ and input$ can be movable or fixed strings. They may not contain NUL or CR characters. result% can be a real or integer variable.

BASIC wrapper function

You can wrap up the routine as a standard BASIC function using the following snippet:

DEFFN_glob(pat$,in$)LOCALA%:A%=0:CALL&4083,A%,pat$,in$:=A%

You could then invoke it like this:

IF FN_glob("*ee*", "Sheep") PRINT "Matches." ELSE PRINT "Does not match."

which would output

Matches.