From f91cfd14bede9cf3213d390eb2b97404e94897a1 Mon Sep 17 00:00:00 2001 From: John Kohl Date: Tue, 5 Jul 1988 11:58:48 +0000 Subject: varline was horribly broken. Cleaned up. --- lib/ZVariables.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'lib/ZVariables.c') diff --git a/lib/ZVariables.c b/lib/ZVariables.c index 67869c2..017c398 100644 --- a/lib/ZVariables.c +++ b/lib/ZVariables.c @@ -21,10 +21,8 @@ static char rcsid_ZVariables_c[] = "$Header$"; #include -#include #include -#define _toupper(c) (islower(c)?toupper(c):c) extern char *getenv(); extern uid_t getuid(); @@ -159,26 +157,34 @@ static char *get_varval(fn, var) return ((char *)0); } +/* If the variable in the line bfr[] is the same as var, return index to + the variable value, else return 0. */ static int varline(bfr, var) char *bfr; char *var; { - int i; + register char *cp; - if (!bfr[0] || bfr[0] == '#') + + if (!bfr[0] || bfr[0] == '#') /* comment or null line */ return (0); - for (i = 0; bfr[i] && !isspace(bfr[i]) && - bfr[i] != '='; i++) - if (_toupper(bfr[i]) != _toupper(var[i])) - break; - if ((!bfr[i] || !isspace(bfr[i])) && bfr[i] != '=') - return (0); - while (bfr[i] && isspace(bfr[i])) - i++; - if (bfr[i++] != '=') - return (0); - while (bfr[i] && isspace(bfr[i])) - i++; - return (i); + cp = bfr; + while (*cp && !isspace(*cp) && (*cp != '=')) + cp++; + +#define max(a,b) ((a > b) ? (a) : (b)) + + if (strncasecmp(bfr, var, max(strlen(var),cp - bfr))) + return(0); /* var is not the var in + bfr ==> no match */ + + cp = index(bfr, '='); + if (!cp) + return(0); + cp++; + while (*cp && isspace(*cp)) /* space up to variable value */ + cp++; + + return (cp - bfr); /* return index */ } -- cgit v1.2.3