/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/match_tok.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:39 $ * $Revision: 1.2 $ * ******************************************************************************* * * Change History * * $Log: match_tok.c,v $ * Revision 1.2 2002/10/07 09:37:39 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:36:57 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/match_tok.c,v 1.2 2002/10/07 09:37:39 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include /* ------------------------------------------------------------------ Defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Structure definitions ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Global variables ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Function prototypes ------------------------------------------------------------------ */ /* --------------------------------------------------------------------------- Function : match_string Summary : This function return whether the line parameter : contains the string in the match parameter : It will allow the match string to be bound to : the start of the line (ala grep) : It will also return a pointer to the first : non-blank token after the match (or the start : of the string Input Parameters : pointer line buffer : pointer to matching string Output Parameters : pointer to a character pointer for next token : return value Global Variables : None Return Value : 1 == found 0 == not found --------------------------------------------------------------------------*/ int match_string ( const char *line_ptr, const char *match_ptr, char ** next_tok ) { int rv = 0; char *cp2=NULL,*ttok; ttok = (char *)line_ptr; if (*match_ptr == '^') { match_ptr++; cp2 = strstr(line_ptr,match_ptr); if (cp2 == line_ptr) rv = 1; } else { cp2 = strstr(line_ptr,match_ptr); if (cp2 != NULL ) rv = 1; } if (next_tok) { if (rv) { /* skip past matched token and point to next token */ cp2 += strlen(match_ptr); while (*cp2 == ' ') cp2++; *next_tok = cp2; } else *next_tok = ttok; } return(rv); } /* --------------------------------------------------------------------------- Function : match_a_string Summary : This function return whether the line parameter : matches one of the parameters in the match_token : list : It will allow the match string to be bound to : the start of the line (ala grep) : It will also return a pointer to the first : non-blank token after the match (or the start : of the string Input Parameters : pointer line buffer : pointer to match token list : this is a pointer to an array of type match_token : the array is terminated by a entry with a NULL : m_ptr Output Parameters : pointer to a character pointer for next token : return value Global Variables : None Return Value : value specified in matched token or : value on the terminating token --------------------------------------------------------------------------*/ int match_a_string ( const char *line_ptr, struct match_token *match_ptr, char ** next_tok ) { int rv; if (next_tok) *next_tok=(char *)line_ptr; rv=match_ptr->m_val; while ( match_ptr->m_ptr && match_string( line_ptr, match_ptr->m_ptr, next_tok )==0 ) { match_ptr++; rv=match_ptr->m_val; }; return(rv); #if 0 int rv = matched = 0,sl; char *cp,*cp2=NULL,*ttok; ttok = (char *)line_ptr; do while ((cp = (char *)match_ptr->m_ptr) && rv == 0) { if (*cp == '^') { cp++; cp2 = strstr(line_ptr,cp); if (cp2 == line_ptr) { sl = strlen(cp); rv = match_ptr->m_val; } } else { cp2 = strstr(line_ptr,cp); if (cp2 != NULL ) { sl = strlen(cp); rv = match_ptr->m_val; } } #ifdef DEBUG /*if (rv)*/ /*printf("Found entry %d <%s> in <%s>\n",rv,cp,line_ptr);*/ #endif match_ptr++; } if (next_tok) if (cp2 && rv) { /* skip past matched token and point to next token */ cp2 += sl; while (*cp2 == ' ') cp2++; #ifdef DEBUG /*if (rv)*/ /*printf("moving to <%s>\n",cp2);*/ #endif *next_tok = cp2; } else *next_tok = ttok; return(rv); #endif } /* -- End of File -- */