home *** CD-ROM | disk | FTP | other *** search
- /* colons.c
- *
- * Returns the number of substitution variables in an SQL query.
- */
- /* Copyright 1991 Kevin Stock.
- *
- * You may copy this under the terms of the GNU General Public License,
- * or the Artistic License, copies of which should have accompanied your
- * Perl kit.
- */
-
- int count_colons(s)
- register char *s;
- {
- register int n = 0, c;
-
- while (*s != '\0')
- {
- if (*s == ':')
- {
- /* numbers must be used in sequence,
- * but they may be repeated if a parameter is reused
- */
- if (((c = atoi(++s)) <= 0) || (c > n+1))
- {
- /* number too low or out of sequence */
- return(-1);
- }
- else if (c == n + 1)
- {
- ++n;
- }
- /* else repeating a previous parameter */
- }
- else if (*s == '\'')
- {
- while ((*++s != '\'') && (*s != '\0'))
- ;
- }
- if (*s != '\0')
- {
- ++s;
- }
- }
-
- return(n);
- }
-