FW: Phonetic searching algorithms
Posted in 1995
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Migration, Import/Export & Data Conversion, Internationalization & Character Sets
granholm@digex.net, if you have a problem with unloading the attached c code file, e-mail me and i'll send it in the body of a message. -joe- (huddles@hasting.com) [[ CFUNC.C : 2398 in CFUNC.C ]] ---------- From: Morgan, Joseph To: Huddleston, Joe Subject: RE: Phonetic searching algorithms Date: Wednesday, January 25, 1995 9:23AM Joe ... I have a rather robust C library. In there is a Soundex function that I have been developing over the years. It is an improved Russellian soundex procedure. I wrote it, though, using other functions in the library. The file is: /u/morganj/4gl/lib/cfunc.c He would need to compile the library with: cc -c cfunc.c And then include that as an additional object library in his program module. Joe. ---------- From: ilist To: informix-list Subject: Phonetic searching algorithms Date: Wednesday, January 25, 1995 12:23AM Does anyone have experience writing phonetic search algorithms for I4GL (or ESQL/C) I am interested in any ideas / source code. Thanks in advance. granholm@digex.net #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> /* ======================= */ #define NIL(type) (type *)0 /* Points ANYTHING to NULL */ /* ======================= */ /* ========================= */ /* Local Function Prototypes */ /* ========================= */ #define MAXFNAME 144 typedef struct fglfileTAG { FILE *ptr; char name[MAXFNAME]; int open; struct fglfileTAG *nextfile; } FGLFILE; FGLFILE *FirstFGLFile = NIL(FGLFILE); FGLFILE *get_fglfile(char *); FGLFILE *make_fglfile(char *); int isvowel(int); char *strchgchar(char *, int, int); char *strchgstr(char *, char *, char *); int strnicmp(char *, char *, int); char *strremchar(char *, int, char *); char *strremchars(char *, char *, char *); char *strremcharsi(char *, char *, char *); char *strremstr(char *, char *, char *); char *strremstri(char *, char *, char *); char *strupr(char *); char *unlsetstr(char *); void errputs(char *); void protoerr(char *); /* ========================= */ /* 4GL Function Prototypes */ /* ========================= */ int file_delete(int); int file_exists(int); int fglfclose(int); int fglfeof(int); int fglfgets(int); int fglfopen(int); int fglfputs(int); int get_strtoken(int); int gettempfile(int); int getuname(int); int getwhoami(int); int runnoclear(int); int soundex(int); int string_char(int); int string_in_string(int); int string_ini_string(int); int string_rchar(int); int string_remove_chars(int); int string_remove_charsi(int); int string_set(int); int tempstropen(int); int tempstrwrite(int); int tempstrclose(int); /* ========= */ /* Functions */ /* ========= */ /* ========================================================== */ /* Deletes a system file. Returns 1 if successful, 0 if not. */ /* ========================================================== */ int file_delete(int n) { char fname[MAXFNAME]; int status_flag; if (n != 1) { errputs("\\nERROR (file_delete): invalid protocol"); return(0); } popquote(fname, MAXFNAME); unlsetstr(fname); status_flag = unlink(fname); retint(++status_flag); return(1); } /* ================================================================ */ /* Checks to see if a given file exists. Returns 1 if so, 0 if not */ /* or if there is an error. */ /* ================================================================ */ int file_exists(int n) { char fname[MAXFNAME]; int status_flag; FILE *file_ptr; if (n != 1) { errputs("\\nERROR (file_exists): invalid protocol"); return(0); } popquote(fname, MAXFNAME); unlsetstr(fname); if ((file_ptr = fopen(fname, "r")) == NULL) status_flag = 0; else { fclose(file_ptr); status_flag = 1; } retint(status_flag); return(1); } /* ======================================== */ /* Closes a 4gl accessible direct read file */ /* ======================================== */ int fglfclose(int n) { char fname[MAXFNAME]; FGLFILE *thisfile; if (n != 1) { puts("\\nERROR (fglfclose): Invalid Protocol."); return 0; } popquote(fname, MAXFNAME); unlsetstr(fname); if ((thisfile = get_fglfile(fname)) == NIL(FGLFILE)) return 0; fflush(thisfile->ptr); fclose(thisfile->ptr); thisfile->open = 0; return 0; } /* =============================================================== */ /* This function tests to see if a given file pointer has actually */ /* reached the end of a file for a 4gl direct read file. */ /* =============================================================== */ int fglfeof(int n) { char fname[MAXFNAME]; FGLFILE *thisfile; if (n != 1) { puts("\\nERROR (fglfeof): Invalid Protocol>"); return 0; } popquote(fname, MAXFNAME); unlsetstr(fname); if ((thisfile = get_fglfile(fname)) == NIL(FGLFILE)) { retint(0); return(1); } retint(feof(thisfile->ptr)); return(1); } /* ===================================================================== */ /* Gets and returns a string and stats from a 4gl direct accessible file */ /* ===================================================================== */ int fglfgets(int n) { char fname[MAXFNAME], *buffer; int len, status_flag; FGLFILE *thisfile; if (n != 2) { errputs("\\nERROR (fglfgets): Invalid Protocol."); return 0; } popquote(fname, MAXFNAME); unlsetstr(fname); popint(&len); if ((thisfile = get_fglfile(fname)) == NIL(FGLFILE)) { retquote(""); retint(0); return(2); } if (!thisfile->open) { retquote(""); retint(0); return(2); } buffer = (char *)malloc(++len); status_flag = (fgets(buffer, len, thisfile->ptr) == NIL(char)) ? 0 : 1; buffer[strlen(buffer) - 1] = '\\0'; retquote(buffer); free(buffer); retint(status_flag); return 2; } /* ===================================================== */ /* This function opens a 4gl accessible direct read file */ /* ===================================================== */ int fglfopen(int n) { FGLFILE *thisfile; char fname[MAXFNAME], fmode[5]; if (n != 2) { protoerr("fglfopen"); return 0; } popquote(fmode, 4); unlsetstr(fmode); popquote(fname, MAXFNAME); unlsetstr(fname); if ((thisfile = get_fglfile(fname)) == NIL(FGLFILE)) { if ((thisfile = make_fglfile(fname)) == NIL(F