parser.h 4.83 KB
Newer Older
Per Cederqvist's avatar
.  
Per Cederqvist committed
1
/*
2 3
 * $Id: parser.h,v 0.14 2003/08/23 16:38:20 ceder Exp $
 * Copyright (C) 1990-1991, 1994-1995, 1998-1999, 2002-2003  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
Per Cederqvist's avatar
Per Cederqvist committed
23
 * Please report bugs at http://bugzilla.lysator.liu.se/. 
Linus Tolke Y's avatar
Linus Tolke Y committed
24 25
 */
/*
26
 * $Id: parser.h,v 0.14 2003/08/23 16:38:20 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
27
 *
Per Cederqvist's avatar
.  
Per Cederqvist committed
28 29 30
 *  client/parser.h  --  Header file for LysKOM command parsing routines
 *
 *
31
 *  Copyright (C) 1990-1991, 1994-1995, 1998-1999, 2002-2003	Lysator Computer Club,
Per Cederqvist's avatar
.  
Per Cederqvist committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
 *			Linkoping University,  Sweden
 *
 *  Everyone is granted permission to copy, modify and redistribute
 *  this code, provided the people they give it to can.
 *
 *
 *  Author:	Thomas Bellman
 *		Lysator Computer Club
 *		Linkoping University
 *		Sweden
 *
 *  e-mail:	Bellman@Lysator.LiU.SE
 */


#ifndef  PARSER_H_ALREADY_INCLUDED__
#define  PARSER_H_ALREADY_INCLUDED__


#include <misc-types.h>
#include <s-string.h>
#include <s-collat-tabs.h>



/*
 *  Information about one word.  If the field 'word' is
 *  EMPTY_STRING, then the struct is considered to be the last
 *  in an "array".		BUG: "array" is wrong word
 */
typedef	struct {
	String		word;
	String_size	start_in_string;
} Parse_token;


/*
 *  Information about one string to match against during parse().
 *  A list of these should be passed to parse() as the CMD_TABLE
 *  parameter.  The 'tokens' field is set by doing
 *	I.tokens = tokenize(I.name, Separators);
 */
typedef	struct matching_info {
David Byers's avatar
Server:  
David Byers committed
75 76 77
    Conf_no        conf_no;         /* Conference */
    String	   name;	    /* Name to match against */
    Parse_token	 * tokens;          /* Tokenized version of name */
Per Cederqvist's avatar
.  
Per Cederqvist committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
} Matching_info;



/*
 *  Remove paranthesized "expressions" from the string STR by
 *  replacing them with the character SEPARATOR.
 *  Superflous close paranthesis are disregarded.
 */
extern  void
remove_parenthesis (String	* str,
		    char	  separator);



/*
 *  Convert a String to a list of tokens (words).  This list is
 *  easier to parse than a string (since the string would have to
 *  be tokenized first anyway).
 *  Returns NULL if any error occured (couldn't allocate memory).
 */
extern  Parse_token *
tokenize (const String	  source,
	  const String	  separators);



/*
 *  Count the number of tokens (words) in TOKEN_LIST.  Used to
 *  set the NUMBER_OF_WORDS field in a 'Matching_info' object.
 */
extern  int
count_words (const Parse_token   * token_list);



/*
 *  Free the list of tokens (// and the strings they are pointing to //).
 *  Free:ing NULL is a no-op.
 */
extern  void
free_tokens (Parse_token   * token_list);



/*
 *  Returns the number of the first word of SOURCE that does
 *  not match PATTERN.  A word "foo" in SOURCE matches "foobar"
 *  in PATTERN, but not vice versa.
 */
extern  int
match (Parse_token	* source,
       Parse_token	* pattern,
131
       unsigned char      collat_tab[COLLAT_TAB_SIZE]);
Per Cederqvist's avatar
.  
Per Cederqvist committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165



/*
 *  Contains the result of a parse().
 */
typedef struct {
	int	  no_of_matches;	/* Number of found matches */
	int	* indexes;		/* List of indexes */
	String	  arguments;		/* The arguments... */
} Parse_info;


/*
 *  Searches for a matching string in the table 'match_table'.
 *  Some weird pattern matching is done.  The 'ARGUMENTS' field of
 *  the result is not a separate String, but points into
 *  SOURCE_STRING.
 *  If ALLOW_TRAILING_WORDS is false, then SOURCE_STRING may not
 *  contain any trailing words.
 *  If NUMBER_OF_WORDS_MUST_MATCH is true, then all the words
 *  in from the entry in MATCH_TABLE must be present (possibly
 *  abbrevated) in SOURCE_STRING.
 *  parse().no_of_matches is -1 if an error occured (out of
 *  memory).
 *  If SOURCE_STRING is empty, i e does not contain any words,
 *  the 'no_of_matches' field is 1, and indexes[0] is -1.
 *
 *  What?  You want a description of how it matches?  Forget it!  BUG!
 *  Try for yourself, and you'll find out!
 */

extern  Parse_info
parse (String		  source_string,
166
       Matching_info	* match_tbl,
Per Cederqvist's avatar
.  
Per Cederqvist committed
167 168 169
       Bool		  allow_trailing_words,
       Bool		  number_of_words_must_match,
       String		  separators,
170
       unsigned char      collat_tab[COLLAT_TAB_SIZE]);
Per Cederqvist's avatar
.  
Per Cederqvist committed
171 172 173


#endif	/*  PARSER_H_ALREADY_INCLUDED__  */