Re: Text->String conversion
Posted in 1993
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
In article <27nn6o$1ff6@mtecv2.mty.itesm.mx> (comp.databases.informix - 21 Sep 1993 20:12:08 GMT) Ing. Maximo Maldonado Boyso wrote: : Is it possible to assign a text var to : a string var?, I need to perform some : operations with the string var. : Do you have any idea?, Thank You for : any advice or suggestion. : INFORMIX-4GL Version 4.10.UD3 : -- : Maximo Maldonado B. : Information Services : ITESM-Campus Monterrey : Mexico : mmaldona@mtecv2.mty.itesm.mx I wrote some subroutines in C for transferring TEXT-Blobs into strings and vice versa. TEXT-blobs must be located in memory. Documentation is in german, but it's very easy: str2txt --> string to text-blob txt2str --> text-blob to string Perhaps You can use these functions: /* Funktionen zum Umwandeln von Strings (char) in TEXT-Blobs und umgekehrt str2txt: call str2txt(string, textblob) Wandelt den String string in den BLOB textblob um strcattxt: call strcattxt(string, textblob) Haengt den String string an den BLOB textblob an txt2str: call txt2str(textblob) returning string Wandelt den Textblob text in den String string um Alle Blobs muessen im Speicher liegen locate textblob in memory */ #include <stdio.h> #include <string.h> #include <memory.h> #include "/usr/lib/informix/incl/locator.h" #undef DEBUG txt2str(nargs) int nargs; { loc_t *bltext; /*Blob, der verarbeitet werden soll*/ #ifdef DEBUG printf ("Aufruf txt2str\\n"); fflush (stdout); #endif poplocator(&bltext); if (bltext->loc_loctype != LOCMEMORY) { retint(0); return(1); } retquote(bltext->lc_union.lc_mem.lc_buffer); return(1); } strcattxt(nargs) int nargs; { loc_t *bltext; /*Blob, der verarbeitet werden soll*/ char *s, *rs; char str[1030]; int nlen, slen, blen; popquote(str,1025); poplocator(&bltext); if (bltext->loc_loctype != LOCMEMORY) return(0); s = str + 1023; while (*s == ' ' && s>str) { *s = '\\0'; s--; } slen = s - str + 1; s = bltext->lc_union.lc_mem.lc_buffer; blen = bltext->lc_union.lc_mem.lc_bufsize; nlen = slen + blen + 10; if ( (rs = malloc( (unsigned)nlen) ) == NULL ) return(0); strcpy(rs, s); strcat (rs, str); free(s); bltext->lc_union.lc_mem.lc_buffer = rs; bltext->lc_union.lc_mem.lc_bufsize = nlen; bltext->loc_size = nlen-10; bltext->loc_indicator = 0; return(0); } str2txt(nargs) int nargs; { loc_t *bltext; /*Blob, der verarbeitet werden soll*/ char *s, *rs; char str[1030]; int nlen, slen, blen; popquote(str,1025); poplocator(&bltext); #ifdef DEBUG printf ("str2txt: String:\\n%s\\n", str); fflush (stdout); #endif if (bltext->loc_loctype != LOCMEMORY) return(0); s = str + 1023; while (*s == ' ' && s>str) { *s = '\\0'; s--; } slen = s - str + 1; #ifdef DEBUG printf ("str2txt: Laenge: %d\\n\\n", slen); fflush (stdout); #endif nlen = slen + 10; if ( (rs = malloc( (unsigned)nlen) ) == NULL ) return(0); #ifdef DEBUG printf ("str2txt: Memorybereich: %x, Laenge: %d, Stringlaenge: %d\\n", rs, nlen, slen); printf("%s\\n", str); fflush (stdout); #endif strcpy(rs, str); #ifdef DEBUG printf ("str2txt: Kopie in TEXT:\\n%s\\n", rs); fflush (stdout); #endif bltext->lc_union.lc_mem.lc_buffer = rs; bltext->lc_union.lc_mem.lc_bufsize = nlen; bltext->loc_size = slen; bltext->loc_indicator = 0; return(0); } -- Dr. med. dipl.-math Dieter Becker Tel.: (0 / +49) 6841 - 16 3046 Medizinische Universitaets- und Poliklinik Fax.: (0 / +49) 6841 - 16 3369 Innere Medizin III D - 66421 Homburg / Saar Email: becker@med-in.uni-sb.de