home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * ut_xlate.c - translate functions.
- *
- * Purpose: This file contains table translate functions.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <string.h>
- #include "blackstr.h"
-
-
- /********
- *
- * ut_xlateb(byte,table) - translate byte in table
- *
- **/
-
- char ut_xlateb(char byte, char *table)
- {
- while(*table) {
- if(*table++==byte)
- return(*table);
- else table++;
- }
- return(byte);
- }
-
-
- /********
- *
- * ut_xtable(str,table) - look up string in table
- *
- **/
-
- int ut_xtable(char *str, char *table[])
- {
- int i=0;
-
- while(*table) {
- if(!strcmpi(str,*table))
- return(i);
- else ++i,++table;
- }
- return(ERROR);
- }
-
-
- /********
- *
- * ut_xlprox(str,table) - look up closest match in table
- *
- **/
-
- int ut_xlprox(char *str, char *table[])
- {
- int xv[255],tv,i;
-
- tv= 0;
- i=0;
- while(*table) {
- xv[i] = st_patmai(str,*table); /* # chars matched */
- ++i;
- ++table;
- }
- while(i--) {
- if(xv[i] > xv[tv]) /* find highest match value */
- tv = i;
- }
- return(xv[tv]>=0 ? tv: -1);
- }
-
-
- /********
- *
- * ut_xlstr(str,table) - translate string from table
- *
- **/
-
- char *ut_xlstr(char *str, char *table[])
- {
- int i;
-
- if((i=ut_xlprox(str,table)) != -1)
- strcpy(str,table[i]);
- else
- *str = NUL;
- return(str);
- }
-