Next Previous Contents

7. Searching Functions

The S-Lang library incorporates two types of searches: Regular expression pattern matching and ordinary searching.

7.1 Regular Expressions

!!! No documentation available yet !!!

7.2 Simple Searches

The routines for ordinary searching are defined in the slsearch.c file. To use these routines, simply include "slang.h" in your program and simply call the appropriate routines.

The searches can go in either a forward or backward direction and can either be case or case insensitive. The region that is searched may contain null characters (ASCII 0) however, the search string cannot in the current implementation. In addition the length of the string to be found is currently limited to 256 characters.

Before searching, the function SLsearch_init must first be called to `preprocess' the search string.

7.3 Initialization

The function SLsearch_init must be called before a search can take place. Its prototype is:

    int SLsearch_init (char *key, int dir, int case_sens, SLsearch_Type *st);
Here key is the string to be searched for. dir specifies the direction of the search: a value greater than zero is used for searching forward and a value less than zero is used for searching backward. The parameter case_sens specifies whether the search is case sensitive or not. A non-zero value indicates that case is important. st is a pointer to a structure of type SLsearch_Type defined in "slang.h". This structure is initialized by this routine and must be passed to SLsearch when the search is actually performed.

This routine returns the length of the string to be searched for.

7.4 SLsearch

      Prototype: unsigned char *SLsearch (unsigned char *pmin, 
                                          unsigned char *pmax, 
                                          SLsearch_Type *st);

This function performs the search defined by a previous call to SLsearch_init over a region specified by the pointers pmin and pmax.

It returns a pointer to the start of the match if successful or it will return NULL if a match was not found.

Next Previous Contents