match





Summary

#include <dataman/dataman.h>
     -or-
#include <dataman/sort.h>

val = match(text,template);

int val;
char *text, *template;

Description

This is a basic pattern matching routine. The text argument is the string to be matched. The template is the string the generic or approximate value to be matched. An asterisk (*) will match any one character. The procedure returns a zero (0) if the template matched the text up to the length of the template. If the template is shorter than the text string it is considered an approximate match. If the first differing character in the template (aside from the magic character) is less a negative number is returned, and if the template is longer than the string, or the first differing character in the template is greater a positive number is returned.

Example

    #include <dataman/dataman.h>

    main(int argc, char *argv[])
    {

        key k_buff;
        short int row,col;              /* row and column */

        row = 1;                        /* row of display */
        col = 10;                       /* col of display */
        move(k_buff,"HORT******KY",13); /* key to get */
        get(name_ix,k_buff) else
            error();                    /* didn't get key */
        while (1) {
            show(row++,col++,mfmt[1], ENDLIST); /* show line */
            get_next(name_ix) else        /* get next key */
                break;                    /* done with loop */
            if (match(KEY,k_buff))        /* do they match? */
                break;                    /* no, so done */
        }
    }

«previous  next»