| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

isoneoftokens

#include "sflstr.h"
int
isoneoftokens (
    char **strbuf,
    char *strmat,
    char *strsep,
    int *iWasToken)

Synopsis

Eats strToEat from strBuff only if it begins with contents of strToEat, and returns a 0 or 1 to tell what it did. Returns 0 if nothing found, and >= 1 which is an index of the one found.

Examples

       char strBuff[] = { "select * from mytbl;" };
       int iWasToken;
       isoneoftokens (&strBuff, "INSERT|SELECT|DELETE", "|", &iWasToken);

       On return here iWasToken would == 1, and strBuff would be:
       " * from mytbl;" and the return value would be 2.

    If the token is not found, then strBuff will not be affected, and
    a 0 will be returned.
    Submitted by Scott Beasley <jscottb@infoave.com>

Source Code - (sflstr.c)

{
   int nstate = 0, cnt = 0, icmpres;
   int iLen;
   char *strtemp, cChar;

   ASSERT (strbuf);
   ASSERT (strmat);
   ASSERT (strsep);
   ASSERT (iWasToken);

   while (1)
     {
       iLen = getstrfldlen (strmat, cnt, 0, strsep);
       strtemp = (char *) malloc (iLen + 1);
       getstrfld (strmat, cnt, 0, strsep, strtemp);
       if (*strtemp)
         {
           trim (strtemp);
           icmpres = lexncmp (*strbuf, strtemp, strlen (strtemp));

           if (!icmpres)
             {
               cChar = *(*strbuf + strlen (strtemp));
               if (!isalpha ((int)cChar)&& cChar != '_')
                 {
                   *iWasToken = cnt + 1;
                   strcpy (*strbuf, (*strbuf + strlen (strtemp)));

                   nstate = cnt + 1;
                 }
               break;
             }

            else
              {
                if (!lexncmp (*strbuf, strtemp, strlen (strtemp)))
                  {
                    cChar = *(*strbuf + strlen (strtemp));
                    if (!isalpha ((int)cChar)&& cChar != '_')
                      {
                        *iWasToken = cnt + 1;
                        strcpy (*strbuf, (*strbuf + strlen (strtemp)));

                        nstate = cnt + 1;
                      }
                    break;
                  }
              }
         }

       else
         {
           *iWasToken = 0;
           nstate = 0;
           break;
         }

       cnt++;
       free (strtemp);
     }

   return nstate;
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation