home *** CD-ROM | disk | FTP | other *** search
- #ifdef RCSID
- static char *RCSid =
- "$Header: iaxpcc.pc,v 6.2 89/02/16 20:53:56 lchan Exp $ iaxpcc.c Copyr (c) 1986 Oracle";
- #endif /* RCSID */
-
- #include <stdio.h>
- #include "usrxit.h"
-
- extf int CHKVAL2();
-
- EXEC SQL BEGIN DECLARE SECTION;
- VARCHAR legval[15];
- /* contains legal value */
- VARCHAR sqlstmt[128];
- /* SQL stmt to fetch legal val */
- VARCHAR compvar[15];
- /* Fetch value from form into this var */
- char formfld[20]; /* Store block.field here */
- EXEC SQL END DECLARE SECTION;
- EXEC SQL INCLUDE SQLCA.H;
-
- /* *************************************************************************
-
- CHKVAL2 is called with the following syntax for the parameter string p:
-
- CHKVAL2 fieldname value1 value2 ... valueN
-
- Currently, only upper case, string values are able to be processed.
- CHKVAL2 will return IAPFAIL if the field matches one of the values in the list,
- otherwise it will return IAPSUCC.
-
- The User Exit Table, iapxtb[], is defined in iapxtb.c, which in turn is
- usually generated by pgm genxtb. See the "Installation and User's Guide"
- for details.
-
- *************************************************************************** */
-
- #define MAXARGS 128
- #define ARBUFSIZ 512
- char *wordb[MAXARGS]; /* Holds pointers to the blank separated */
- /* tokens in the string passed to CHKVAL2 */
-
- int CHKVAL2(p, paramlen, erm, ermlen, query)
- register char *p; /* Parameter string */
- int *paramlen; /* Ptr to param string length */
- char *erm; /* Error message if doesnt match */
- int *ermlen; /* Ptr to error message length */
- int *query; /* Ptr to query status flag */
- {
- extf int countwords(); /* Puts "words" into an array */
- extf char *cpystr(); /* Copies one string to another */
- extf char *upper(); /* Makes a string uppercase */
- extf char *rblank(); /* Get rid of extra whitespace */
- extf int strcmp(); /* Compares two strings */
- register int listsiz; /* Number of values */
- register int i; /* Temp counter */
- char arbuf[ARBUFSIZ]; /* To hold string that is passed */
-
- EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
-
- rblank( p ); /* Remove leading, trailing, and
- and double spaces */
-
- strncpy(arbuf, p, ARBUFSIZ-1 );
- listsiz = countargs( arbuf ); /* get fieldname and value list
- in wordb[] */
-
- if ( listsiz < 3 ) /* Check for minimum # of args */
- {
-
- char *ermsg1 = "CHKVAL2: Not enough arguments!";
-
- sqliem( ermsg1, strlen(ermsg1) );
- return IAPFTL;
- }
-
- if ( listsiz >= MAXARGS ) /* Check for maximum # of args */
- {
-
- char *ermsg1 = "CHKVAL2: Too many arguments!";
-
- sqliem( ermsg1, strlen(ermsg1) );
- return IAPFTL;
- }
-
-
- strcpy(formfld,wordb[1]); /* get fieldname string */
-
-
- /* This is the recommended way to read data from a field in a form. */
-
- EXEC IAF GET :formfld INTO :compvar; /* Get field value into compvar*/
- compvar.len= strlen(compvar.arr);
-
-
- listsiz -= 2;
- for ( i = 2; listsiz--; i++ ) /* Check field value against each
- value until we have a match
- or run out of values */
-
- if ( strcmp( wordb[i], compvar.arr ) == 0 ) /* Value matches? */
- return IAPSUCC; /* Yes, return success code */
-
- sqliem( erm, ermlen ); /* Display error message */
- return IAPFAIL; /* Return failure code */
-
- sqlerr:
- sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
- sqliem( sqlca.sqlerrm.sqlerrmc, sqlca.sqlerrm.sqlerrml );
- return IAPFAIL;
- }
-
-
- /* countargs - counts arguments in string and sets pointers in wordb[] */
- /* to point to individual, null-terminated tokens. Relies */
- /* on string having no leading, trailing or double blanks. */
-
- int countargs(textp)
- char *textp;
- {
- int numargs;
- char *sp;
- extf char *strchr();
-
- for ( numargs = 0, sp = textp; numargs < MAXARGS && sp; numargs++ ) {
-
- wordb[numargs] = sp;
- sp = strchr( textp, ' ');
-
- if ( sp ) {
- *sp = '\0';
- textp = ++sp;
- }
- }
- return(numargs);
- }
-
- /* End of example iaxpcc.pc */
-