home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume30 / oraperl-v2 / part05 / colons.c next >
Encoding:
C/C++ Source or Header  |  1992-07-06  |  1.1 KB  |  59 lines

  1. /* colons.c
  2.  *
  3.  * Returns the number of substitution variables in an SQL query.
  4.  */
  5. /* Copyright 1991, 1992 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. #include <stdio.h>
  13. #include "EXTERN.h"
  14. #include "orafns.h"
  15.  
  16.  
  17. int count_colons(s)
  18. register char *s;
  19. {
  20.     register int n = 0, c;
  21.  
  22.     DBUG_ENTER("count_colons");
  23.     DBUG_PRINT("entry", ("count_colons(\"%s\")", s));
  24.  
  25.     while (*s != '\0')
  26.     {
  27.         if (*s == ':')
  28.         {
  29.             /* numbers must be used in sequence,
  30.              * but they may be repeated if a parameter is reused
  31.              */
  32.             if (((c = atoi(++s)) <= 0) || (c > n+1))
  33.             {
  34.                 /* number too low or out of sequence */
  35.                 DBUG_PRINT("exit",
  36.                 ("count_colons: got %d, expected %d", c, n+1));
  37.                 DBUG_RETURN(-1);
  38.             }
  39.             else if (c == n + 1)
  40.             {
  41.                 ++n;
  42.             }
  43.             /* else repeating a previous parameter */
  44.         }
  45.         else if (*s == '\'')
  46.         {
  47.             while ((*++s != '\'') && (*s != '\0'))
  48.                 ;
  49.         }
  50.         if (*s != '\0')
  51.         {
  52.             ++s;
  53.         }
  54.     }
  55.  
  56.     DBUG_PRINT("exit", ("count_colons: returning %d", n));
  57.     DBUG_RETURN(n);
  58. }
  59.