Re: Mailme.4gl - Error routine
Posted in 1994
Net friends, This is a follow-up to Peter Botcherby's error routine mailing. The attached C function `fmt_err()' is callable from I-4GL. It will sub- stitute its second argument into the `%s' in its first argument. It is intended to be used to insert the contents of SQLCA.SQLERRM into the text returned by ERR_GET(), but I suppose it could be used to do any similar substitution. When used with your own 4GL character variable as the second argument, beware of trailing blanks. See the comments in the code for more info. This has been tested on a Sun under SunOS 4.1.3, using compiled I-4GL 1.10.03f and SQL 2.10.03f. Perhaps my good friend Jack Parker will try it on his HP system, which has broken some of my C-code in the past. Regards, Alan ___________________________ ______________________| R. Alan Popiel |__________________________ \\ Internet: | Martin Marietta, SLS | / \\ alan@den.mmc.com | P.O. Box 179, M/S 3810 | Std disclaimers apply. / )Voice: | Denver, CO 80201-0179 USA | ( / 303-977-9998 |___________________________| (But you knew that!) \\ /________________________) (____________________________\\ ------------------- Begin attached function --------------------- /* function: fmt_err.c - resolve %s in Informix error message text * author: R. Alan Popiel * date: 03 Mar 1994 * * fmt_err() returns a character string that is the result of substituting * its second argument into the `%s', if any, in the first argument * * usage: * CALL fmt_err ( err_text, err_name ) RETURNING err_text_2 * LET err_text_2 = fmt_err ( err_text, err_name ) * * CALL arguments: * err_text: 4GL character string, such as returned by ERR_GET() * err_name: 4GL character string, such as returned in SQLCA.SQLERRM * Note: Trailing blanks are not trimmed from err_name. It works best * to include an explicit '\\0' after the last character to be printed. * (This is already present in SQLCA.SQLERRM.) * * RETURNING argument: * err_text_2: 4GL character string with `%s', if any, resolved */ #include <stdio.h> int fmt_err ( nargs ) int nargs; { static char *fgl_modname = "fmt_err.c"; char err_name[72]; /* Defined size of SQLCA.SQLERRM */ char err_text[255]; /* Allow for long, but not ridiculous, */ char err_text_2[327]; /* error message text. */ if ( nargs != 2 ) { fgl_fatal ( fgl_modname, 0, -4501 ); /* Wrong number of args. */ } /* Pop calling arguments from the stack. */ popquote ( err_name, sizeof(err_name) ); popquote ( err_text, sizeof(err_text) ); if ( strstr ( err_text, "%s" ) == NULL ) /* No `%s' in err_text. */ retquote ( err_text ); /* Push original err_text to the stack. */ else { /* err_text has `%s', use as format, create err_text_2. */ sprintf ( err_text_2, err_text, err_name ); retquote ( err_text_2 ); /* Push formatted err_text_2 to the stack. */ } return (1); /* Number of return arguments pushed. */ } -------------------- End attached function ----------------------