home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume22 / oraperl / patch02 / colons.c next >
Encoding:
Text File  |  1991-08-25  |  830 b   |  48 lines

  1. /* colons.c
  2.  *
  3.  * Returns the number of substitution variables in an SQL query.
  4.  */
  5. /* Copyright 1991 Kevin Stock.
  6.  *
  7.  * You may copy this under the terms of the GNU General Public License,
  8.  * or the Artistic License, copies of which should have accompanied your
  9.  * Perl kit.
  10.  */
  11.  
  12. int count_colons(s)
  13. register char *s;
  14. {
  15.     register int n = 0, c;
  16.  
  17.     while (*s != '\0')
  18.     {
  19.         if (*s == ':')
  20.         {
  21.             /* numbers must be used in sequence,
  22.              * but they may be repeated if a parameter is reused
  23.              */
  24.             if (((c = atoi(++s)) <= 0) || (c > n+1))
  25.             {
  26.                 /* number too low or out of sequence */
  27.                 return(-1);
  28.             }
  29.             else if (c == n + 1)
  30.             {
  31.                 ++n;
  32.             }
  33.             /* else repeating a previous parameter */
  34.         }
  35.         else if (*s == '\'')
  36.         {
  37.             while ((*++s != '\'') && (*s != '\0'))
  38.                 ;
  39.         }
  40.         if (*s != '\0')
  41.         {
  42.             ++s;
  43.         }
  44.     }
  45.  
  46.     return(n);
  47. }
  48.