home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a524 / 33.ddi / lib / iaxpcc.pc < prev    next >
Encoding:
Text File  |  1991-03-04  |  4.1 KB  |  139 lines

  1. #ifdef RCSID
  2. static char *RCSid = 
  3.    "$Header: iaxpcc.pc,v 6.2 89/02/16 20:53:56 lchan Exp $ iaxpcc.c Copyr (c) 1986 Oracle";
  4. #endif /* RCSID */
  5.  
  6. #include <stdio.h>
  7. #include "usrxit.h"
  8.  
  9. extf    int    CHKVAL2();
  10.  
  11. EXEC SQL BEGIN DECLARE SECTION;
  12.     VARCHAR legval[15];
  13.                     /* contains legal value    */
  14.     VARCHAR sqlstmt[128];
  15.                     /* SQL stmt to fetch legal val  */
  16.     VARCHAR compvar[15];
  17.                 /* Fetch value from form into this var  */
  18.     char formfld[20];    /* Store block.field here         */
  19. EXEC SQL END DECLARE SECTION;
  20. EXEC SQL INCLUDE SQLCA.H;
  21.  
  22. /* *************************************************************************
  23.  
  24. CHKVAL2 is called with the following syntax for the parameter string p:
  25.  
  26. CHKVAL2 fieldname  value1  value2  ...  valueN
  27.  
  28. Currently, only upper case, string values are able to be processed.
  29. CHKVAL2 will return IAPFAIL if the field matches one of the values in the list,
  30. otherwise it will return IAPSUCC.
  31.  
  32. The User Exit Table, iapxtb[], is defined in iapxtb.c, which in turn is
  33. usually generated by pgm genxtb. See the "Installation and User's Guide"
  34. for details.
  35.  
  36. *************************************************************************** */
  37.  
  38. #define    MAXARGS    128
  39. #define ARBUFSIZ    512
  40. char       *wordb[MAXARGS];       /* Holds pointers to the blank separated  */
  41.                    /* tokens in the string passed to CHKVAL2 */
  42.  
  43. int     CHKVAL2(p, paramlen, erm, ermlen, query)
  44. register    char       *p;             /* Parameter string */
  45.         int           *paramlen;         /* Ptr to param string length */
  46.         char       *erm;             /* Error message if doesnt match */
  47.         int           *ermlen;                  /* Ptr to error message length */
  48.         int           *query;                 /* Ptr to query status flag */
  49. {
  50. extf        int     countwords();         /* Puts "words" into an array */
  51. extf        char       *cpystr();         /* Copies one string to another */
  52. extf        char       *upper();         /* Makes a string uppercase */
  53. extf        char       *rblank();         /* Get rid of extra whitespace */
  54. extf        int     strcmp();         /* Compares two strings */
  55. register    int     listsiz;         /* Number of values */
  56. register    int     i;             /* Temp counter */
  57.         char    arbuf[ARBUFSIZ];    /* To hold string that is passed */
  58.  
  59. EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
  60.  
  61.    rblank( p );                     /* Remove leading, trailing, and
  62.                         and double spaces */
  63.  
  64.    strncpy(arbuf, p, ARBUFSIZ-1 );
  65.    listsiz = countargs( arbuf );             /* get fieldname and value list
  66.                         in wordb[] */
  67.  
  68.    if ( listsiz < 3 )                 /* Check for minimum # of args */
  69.    {
  70.  
  71.       char        *ermsg1 = "CHKVAL2: Not enough arguments!";
  72.  
  73.       sqliem( ermsg1, strlen(ermsg1) );
  74.       return IAPFTL;
  75.    }
  76.  
  77.    if ( listsiz >= MAXARGS )             /* Check for maximum # of args */
  78.    {
  79.  
  80.       char        *ermsg1 = "CHKVAL2: Too many arguments!";
  81.  
  82.       sqliem( ermsg1, strlen(ermsg1) );
  83.       return IAPFTL;
  84.    }
  85.  
  86.  
  87.     strcpy(formfld,wordb[1]);             /* get fieldname string   */
  88.    
  89.  
  90. /* This is the recommended way to read data from a field in a form.     */
  91.  
  92.     EXEC IAF GET :formfld INTO :compvar;  /* Get field value into compvar*/
  93.     compvar.len= strlen(compvar.arr);
  94.  
  95.  
  96.    listsiz -= 2;
  97.    for ( i = 2; listsiz--; i++ )         /* Check field value against each
  98.                         value until we have a match
  99.                         or run out of values */
  100.  
  101.       if ( strcmp( wordb[i], compvar.arr ) == 0 )    /* Value matches? */
  102.      return IAPSUCC;             /* Yes, return success code */
  103.  
  104.    sqliem( erm, ermlen );             /* Display error message */
  105.    return IAPFAIL;                 /* Return failure code */
  106.  
  107.    sqlerr:
  108.    sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
  109.    sqliem( sqlca.sqlerrm.sqlerrmc, sqlca.sqlerrm.sqlerrml );
  110.    return IAPFAIL;
  111. }
  112.  
  113.  
  114. /* countargs - counts arguments in string and sets pointers in wordb[] */
  115. /*             to point to individual, null-terminated tokens.  Relies */
  116. /*             on string having no leading, trailing or double blanks. */
  117.  
  118. int countargs(textp)
  119. char *textp;
  120. {
  121.      int numargs;
  122.      char *sp;
  123. extf char *strchr();
  124.  
  125.     for ( numargs = 0, sp = textp; numargs < MAXARGS && sp; numargs++ ) {
  126.  
  127.         wordb[numargs] = sp;
  128.         sp = strchr( textp, ' ');
  129.  
  130.         if ( sp ) {
  131.             *sp = '\0';
  132.             textp = ++sp;
  133.         }
  134.     }
  135.     return(numargs);
  136. }
  137.  
  138. /* End of example iaxpcc.pc */
  139.