/* misc.c Misc. functions 1985 Mark E. Mallett Included are nccmp Compare 2 strings with no case sensitivity newstr Allocate a new copy of a string. chkfor Check that an event is for the current user */ #include "minder.h" #include "mem.h" /* External routines */ /* External data */ extern char *Usrnam; /* Name of current user */ /* Internal routines */ /* Internal data */ /* *//* nccmp(s1,s2) Compare strings without case sensitivity Accepts : s1 Addr of first string s2 Addr of second string Returns : -1 if s1 < s2 0 if s1 = s2 1 if s1 > s2 */ nccmp (s1,s2) char *s1; /* String 1 */ char *s2; /* String 2 */ { IND int c1,c2; /* Chars */ while (TRUE) { c1 = *s1++; c1 = toupper(c1); c2 = *s2++; c2 = toupper(c2); if (c1 < c2) return (-1); if (c1 > c2) return (1); if (c1 == NUL) return(0); } } /* *//* newstr (str) Makes a copy of a string Accepts : str Addr of string to copy Returns : Address of copy */ char *newstr (str) char *str; /* String to copy */ { IND char *sptr; /* Points to new string */ sptr = calloc (1, strlen(str)+1); /* Make space for new string */ strcpy (sptr, str); /* Copy it */ return (sptr); /* Return it */ } /* *//* chkfor (EVTptr) Check that an event is for the current user, by user name. Accepts : EVTptr Address of event block Returns : TRUE if it is for the user FALSE if not */ int chkfor (EVTptr) EVT *EVTptr; /* Points to event thing */ { if (EVTptr -> EVT_FOR == NULL) /* If for nobody */ return (TRUE); /* then it is for everybody */ if (Usrnam == NULL) /* If no username */ return (FALSE); /* then not for me. */ return (nccmp(Usrnam, EVTptr -> EVT_FOR) == 0); /* Do no-case comparison */ }