00001 /* Eliot */ 00002 /* Copyright (C) 1999 Antoine Fraboulet */ 00003 /* */ 00004 /* This file is part of Eliot. */ 00005 /* */ 00006 /* Eliot is free software; you can redistribute it and/or modify */ 00007 /* it under the terms of the GNU General Public License as published by */ 00008 /* the Free Software Foundation; either version 2 of the License, or */ 00009 /* (at your option) any later version. */ 00010 /* */ 00011 /* Eliot is distributed in the hope that it will be useful, */ 00012 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00013 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 00014 /* GNU General Public License for more details. */ 00015 /* */ 00016 /* You should have received a copy of the GNU General Public License */ 00017 /* along with this program; if not, write to the Free Software */ 00018 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00019 00020 /** 00021 * \file dic.h 00022 * \brief Dawg dictionary 00023 * \author Antoine Fraboulet 00024 * \date 2002 00025 */ 00026 00027 #ifndef _DIC_H_ 00028 #define _DIC_H_ 00029 #if defined(__cplusplus) 00030 extern "C" 00031 { 00032 #endif 00033 00034 /** 00035 * different letters in the dictionary 00036 */ 00037 #define DIC_LETTERS 27 00038 00039 /** 00040 * max length of words (including last \0) 00041 */ 00042 #define DIC_WORD_MAX 16 00043 00044 typedef struct _Dictionary* Dictionary; 00045 typedef unsigned int dic_elt_t; 00046 00047 /** 00048 * Dictionary creation and loading from a file 00049 * @param dic : pointer to a dictionary 00050 * @param path : compressed dictionary path 00051 * @return 0 ok, 1 error 00052 */ 00053 int Dic_load (Dictionary* dic,const char* path); 00054 00055 /** 00056 * Destroy a dictionary 00057 */ 00058 int Dic_destroy(Dictionary dic); 00059 00060 /** 00061 * Dic_chr returns the character associated with an element 00062 * (in the range ['A'-'Z']), or the null character ('\0'). 00063 * @returns ASCII code for the character 00064 */ 00065 char Dic_chr (Dictionary dic, dic_elt_t elt); 00066 00067 /** 00068 * Returns a boolean to show if there is another available 00069 * character in the current depth (a neighbor in the tree) 00070 * @returns 0 or 1 (true) 00071 */ 00072 int Dic_last(Dictionary dic, dic_elt_t elt); 00073 00074 /** 00075 * Returns a boolean to show if we are at the end of a word 00076 * (see Dic_next) 00077 * @returns 0 or 1 (true) 00078 */ 00079 int Dic_word(Dictionary dic, dic_elt_t elt); 00080 00081 /** 00082 * Returns the root of the dictionary 00083 * @returns root element 00084 */ 00085 dic_elt_t Dic_root(Dictionary dic); 00086 00087 /** 00088 * Returns the next available neighbor (see Dic_last) 00089 * @returns next dictionary element at the same depth 00090 */ 00091 dic_elt_t Dic_next(Dictionary dic, dic_elt_t elt); 00092 00093 /** 00094 * Returns the first element available at the next depth 00095 * in the dictionary 00096 * @params dic : dictionary 00097 * @params elt : current dictionary element 00098 * @returns next element (successor) 00099 */ 00100 dic_elt_t Dic_succ(Dictionary dic, dic_elt_t elt); 00101 00102 /** 00103 * Find the dictionary element matching the pattern starting 00104 * from the given root node by walking the dictionary tree 00105 * @params dic : valid dictionary 00106 * @params root : starting dictionary node for the search 00107 * @params pattern : string made of uppercase characters in the range 00108 * ['A'-'Z']. The pattern must be null ('\0') terminated 00109 * @returns 0 if the string cannot be matched otherwise returns the 00110 * element that results from walking the dictionary according to the 00111 * pattern 00112 */ 00113 unsigned int Dic_lookup(Dictionary dic, dic_elt_t root, char* pattern); 00114 00115 #if defined(__cplusplus) 00116 } 00117 #endif 00118 #endif /* _DIC_H_ */