B: %b/manif/pmatch length = p.match(string,pcode,[offset,prevchar, optbits,strleng,morefunc); start = .null();
C: #include <pmatch.h> pm_match_result res; res = p_match(const char *string,const pm_code *pcode, [int offset, int prevchar, int optbits, int strleng, char *(*morefunc)(int *));
pm_code *pcode; p.compile(&pcode, "^abc$"); if (0 > p.match(string, pcode)) error("Pattern not found*n"); p.free(pcode);
The default value is "PM_Short_Match | PM_C_String" (zero).
P.MATCH scans a string and determines if the string contains a substring matching a particular pattern. Before you can use P.MATCH, you must compile the pattern using P.COMPILE.
You use the "optbits" parameter when you want to do more than the simple job of determining if a pattern appears in a string. For example, if you have the pattern "cdef|de" and the string "abcdefgh*n", a short match (PM_Short_Match) would match "de" because it is the first match successfully completed. A long match (PM_Long_Match) would find "cdef" because that started first in the line.
Normally, you call P.MATCH to search for a match within a regular string corresponding to a line of data. In this case, all the data is present and the total length of the string can be determined. However, you can also use P.MATCH to search an arbitrary stream of bytes by specifying PM_Random_String in "optbits". With this option, you don't have to have all the data directly present. Instead, P.MATCH examines the first chunk of data, then calls "morefunc" to obtain the next chunk of data. P.MATCH passes "morefunc" one argument: a C integer pointer (int *) telling where the length of the new chunk should be stored. "morefunc" should return a pointer to the new data as its value. "morefunc" should return a NULL value (0) to indicate the end of all data.
In order to use this type of "random string" matching, you must pass the PM_Random_String option to P.COMPILE when you compile the pattern, as well as passing PM_Random_String to P.MATCH when you actually search for the pattern. With random string matching, '*0' gets no special treatment (it's not taken as the end of the string), so you can match '*0' with a '\000' pattern. In addition, '$' only matches the end of data; it does not match the null string before a '*n' character. Since P.MATCH doesn't know the number of bytes in the string until all the data has been scanned, you cannot use the "@(-N)" pattern in random string matching.
Copyright © 1996, Thinkage Ltd.