Ok, here we go with an example. I'm not that C++ crack, so my code may have some smells, but it works at least. The uniface code reads as: ************************** cut here ************************************* entry do_gen_SQL params string p_DMLTEXT : IN ; SQL Statement string p_SQLPATH : IN ; Uniface Path string p_DUMPPATH: IN ; Path for dumpfile endparams sql/print p_DMLTEXT, p_sqlpath filedump $result,p_dumppath return(0) end ; do_gen_SQL entry do_split_SQL params string p_DUMPPATH: IN ; Path for dumpfile string p_Splitted: OUT ; Splitted result endparams variables string v_rec_header, v_rec_ruler, v_rec_data numeric v_loop endvariables p_splitted = "" ; open file, read the header and "ruler" line $30 = p_DUMPPATH $31 = "" perform "M4LS_OPEN" $30 = "" perform "M4LS_NEXT" v_rec_header = $30 $30 = "" perform "M4LS_NEXT" v_rec_ruler = $30 $30 = v_rec_header $31 = v_rec_header $32 = " " perform "M4LS_HEADER2LIST" p_splitted = $concat(p_splitted,v_rec_header,"%%^",$30,"%%^********%%^") ; read a couple of data lines; convert them to list according to ruler v_loop = 5 while (v_loop > 0) v_loop -= 1 $30 = "" perform "M4LS_NEXT" if ($status < 0) break endif v_rec_data = $30 $30 = v_rec_data $31 = v_rec_header $32 = " " perform "M4LS_HEADER2LIST" p_splitted = $concat(p_splitted,v_rec_data,"%%^",$30,"%%^********%%^") endwhile return(0) end ; do_split_SQL ************************** cut here ************************************* and the C code runs as ************************** cut here ************************************* /* ************** Special Global Variables */ char listsep; char nam_fpi[_MAX_PATH]; char workbuffer[8001]; long rec_cnt; FILE *fpi; /* ***************************** Exported functions */ XEXPORT(long) GETTICKS(void) { return(GetTickCount()); } XEXPORT(long) M4LS_INFO(void)/* returns name of file and record count */ { UPUTREGS(30,nam_fpi); return(rec_cnt); } XEXPORT(long) M4LS_OPEN(void) /* opens the file for reading and sets parameters*/ { UGETREGS(30,nam_fpi,sizeof(nam_fpi)-1); /* Input File */ UGETREGS(31,workbuffer,sizeof(workbuffer)-1); /* Separator */ listsep = workbuffer[0]; if (nam_fpi[0] == 0) { UPUTREGS(30,"M4LS_E0001 Input file has to be specified"); return(-11); }; if ((fpi = fopen(nam_fpi,"rt")) == NULL) { UPUTREGS(30,"M4LS_E0002 can't open input file"); rec_cnt = -11; return(-2); } rec_cnt = 0; return(rec_cnt); } XEXPORT(long) M4LS_CLOSE(void)/* closes the file and frees the buffers */ { if (fclose(fpi) == EOF) { UPUTREGS(30,"M4LS_E0003 can't close input file"); return(-5); }; rec_cnt = -2; return(0); } XEXPORT(long) M4LS_NEXT(void) /* copies next record to $30*/ { char *p; if (fgets(workbuffer,sizeof(workbuffer)-1,fpi) == NULL) /* read a record */ return(-3); for(p = workbuffer;*p != '';p++) if (*p=='\n') *p = ''; if (listsep != '') for(p = workbuffer;*p != '';p++) if (*p==listsep) *p = '\33'; UPUTREGS(30,workbuffer); return(++rec_cnt); } XEXPORT(long) M4LS_RULER2LIST(void) /* sets SEPARATORS in data where a LISTSEP character is encountered in RULER string */ { char L_DATA[8001]; char L_RULER[8001]; char L_LISTSEP[2]; char *p_data; char *p_ruler; UGETREGS(30,L_DATA,sizeof(L_DATA)-1); /* Data String */ UGETREGS(31,L_RULER,sizeof(L_RULER)-1); /* Ruler String */ UGETREGS(32,L_LISTSEP,sizeof(L_LISTSEP)-1); /* Separator Character in Ruler string */ if (L_LISTSEP[0] == 0) L_LISTSEP[0] = ' '; for(p_data = L_DATA, p_ruler = L_RULER;*p_data != '';p_data++, p_ruler++) if (*p_ruler==L_LISTSEP[0]) *p_data = '\33'; UPUTREGS(30,L_DATA); /* Data String */ return(0); } XEXPORT(long) M4LS_HEADER2LIST(void) /* sets SEPARATORS in data where SPACE changes to non-space in HEADER string */ { char L_DATA[8001]; char L_HEADER[8001]; char *p_data; char *p_header; char *p_header_prev; UGETREGS(30,L_DATA,sizeof(L_DATA)-1); /* Data String */ UGETREGS(31,L_HEADER,sizeof(L_HEADER)-1); /* Header String */ for(p_data = L_DATA, p_header_prev = L_HEADER, p_header = L_HEADER, p_header++;*p_header != '' && *p_data != '';p_data++, p_header_prev++, p_header++) if (*p_header_prev==' ' && *p_header != ' ') *p_data = '\33'; UPUTREGS(30,L_DATA); /* Data String */ return(0); } ************************** cut here ************************************* Don't forget to declare the DLL in your ASN File with ************************** cut here ************************************* [USER_3GL] ..\3GL\M4LSEQREAD_U8.dll /preload ************************** cut here ************************************* Because it's still the old dITo (do IT ourself) spirit, feel free to use it, copy it, modify it (even in commercial projects). Note: I just saw that the layout is lost in display, perhaps its worth to make it a downloadable text. (Unfortunately, I can not add a download file here, currently).
Author: ulrich-merkel (
ulrichmerkel@web.de)