00001 /* Copyright (C) 2000 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* Functions to handle typelib */ 00018 00019 #include "mysys_priv.h" 00020 #include <m_string.h> 00021 #include <m_ctype.h> 00022 00023 00024 /* 00025 Search after a string in a list of strings. Endspace in x is not compared. 00026 00027 SYNOPSIS 00028 find_type() 00029 x String to find 00030 lib TYPELIB (struct of pointer to values + count) 00031 full_name bitmap of what to do 00032 If & 1 accept only whole names 00033 If & 2 don't expand if half field 00034 If & 4 allow #number# as type 00035 00036 NOTES 00037 If part, uniq field is found and full_name == 0 then x is expanded 00038 to full field. 00039 00040 RETURN 00041 -1 Too many matching values 00042 0 No matching value 00043 >0 Offset+1 in typelib for matched string 00044 */ 00045 00046 int find_type(my_string x, TYPELIB *typelib, uint full_name) 00047 { 00048 int find,pos,findpos; 00049 reg1 my_string i; 00050 reg2 const char *j; 00051 DBUG_ENTER("find_type"); 00052 DBUG_PRINT("enter",("x: '%s' lib: 0x%lx",x,typelib)); 00053 00054 if (!typelib->count) 00055 { 00056 DBUG_PRINT("exit",("no count")); 00057 DBUG_RETURN(0); 00058 } 00059 LINT_INIT(findpos); 00060 find=0; 00061 for (pos=0 ; (j=typelib->type_names[pos]) ; pos++) 00062 { 00063 for (i=x ; 00064 *i && my_toupper(&my_charset_latin1,*i) == 00065 my_toupper(&my_charset_latin1,*j) ; i++, j++) ; 00066 if (! *j) 00067 { 00068 while (*i == ' ') 00069 i++; /* skip_end_space */ 00070 if (! *i) 00071 DBUG_RETURN(pos+1); 00072 } 00073 if (! *i && (!*j || !(full_name & 1))) 00074 { 00075 find++; 00076 findpos=pos; 00077 } 00078 } 00079 if (find == 0 && (full_name & 4) && x[0] == '#' && strend(x)[-1] == '#' && 00080 (findpos=atoi(x+1)-1) >= 0 && (uint) findpos < typelib->count) 00081 find=1; 00082 else if (find == 0 || ! x[0]) 00083 { 00084 DBUG_PRINT("exit",("Couldn't find type")); 00085 DBUG_RETURN(0); 00086 } 00087 else if (find != 1 || (full_name & 1)) 00088 { 00089 DBUG_PRINT("exit",("Too many possybilities")); 00090 DBUG_RETURN(-1); 00091 } 00092 if (!(full_name & 2)) 00093 (void) strmov(x,typelib->type_names[findpos]); 00094 DBUG_RETURN(findpos+1); 00095 } /* find_type */ 00096 00097 00098 /* Get name of type nr 'nr' */ 00099 /* Warning first type is 1, 0 = empty field */ 00100 00101 void make_type(register my_string to, register uint nr, 00102 register TYPELIB *typelib) 00103 { 00104 DBUG_ENTER("make_type"); 00105 if (!nr) 00106 to[0]=0; 00107 else 00108 (void) strmov(to,get_type(typelib,nr-1)); 00109 DBUG_VOID_RETURN; 00110 } /* make_type */ 00111 00112 00113 /* Get type */ 00114 /* Warning first type is 0 */ 00115 00116 const char *get_type(TYPELIB *typelib, uint nr) 00117 { 00118 if (nr < (uint) typelib->count && typelib->type_names) 00119 return(typelib->type_names[nr]); 00120 return "?"; 00121 }
1.4.7

