home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / AZTEC-C / MINDER.ARK / MNDMSC.C < prev    next >
C/C++ Source or Header  |  1986-06-19  |  2KB  |  135 lines

  1. /* misc.c    Misc. functions
  2.  
  3.     1985    Mark E. Mallett
  4.  
  5.  
  6. Included are
  7.  
  8.     nccmp        Compare 2 strings with no case sensitivity
  9.     newstr        Allocate a new copy of a string.
  10.     chkfor        Check that an event is for the current user
  11.  
  12. */
  13.  
  14. #include "minder.h"
  15. #include "mem.h"
  16.  
  17. /* External routines */
  18.  
  19.  
  20. /* External data */
  21.  
  22. extern    char    *Usrnam;        /* Name of current user */
  23.  
  24.  
  25. /* Internal routines */
  26.  
  27.  
  28. /* Internal data */
  29.  
  30.  
  31.  
  32. /*
  33.  
  34. *//* nccmp(s1,s2)
  35.  
  36.     Compare strings without case sensitivity
  37.  
  38. Accepts :
  39.  
  40.     s1        Addr of first string
  41.     s2        Addr of second string
  42.  
  43. Returns :
  44.  
  45.     <value>        -1 if s1 < s2
  46.              0 if s1 = s2
  47.              1 if s1 > s2
  48.  
  49. */
  50.  
  51. nccmp (s1,s2)
  52.  
  53. char        *s1;            /* String 1 */
  54. char        *s2;            /* String 2 */
  55.  
  56. {
  57. IND    int    c1,c2;            /* Chars */
  58.  
  59. while (TRUE)
  60.     {
  61.     c1 = *s1++;
  62.     c1 = toupper(c1);
  63.     c2 = *s2++;
  64.     c2 = toupper(c2);
  65.     if (c1 < c2)
  66.     return (-1);
  67.     if (c1 > c2)
  68.     return (1);
  69.     if (c1 == NUL)
  70.     return(0);
  71.     }
  72. }
  73. /*
  74.  
  75. *//* newstr (str)
  76.  
  77.     Makes a copy of a string
  78.  
  79.  
  80. Accepts :
  81.  
  82.     str        Addr of string to copy
  83.  
  84.  
  85. Returns :
  86.  
  87.     <value>        Address of copy
  88.  
  89.  
  90. */
  91.  
  92. char *newstr (str)
  93.  
  94. char        *str;            /* String to copy */
  95.  
  96. {
  97. IND    char    *sptr;            /* Points to new string */
  98.  
  99. sptr = calloc (1, strlen(str)+1);    /* Make space for new string */
  100. strcpy (sptr, str);            /* Copy it */
  101. return (sptr);                /* Return it */
  102. }
  103. /*
  104.  
  105. *//* chkfor (EVTptr)
  106.  
  107.     Check that an event is for the current user, by user name.
  108.  
  109.  
  110. Accepts :
  111.  
  112.     EVTptr        Address of event block
  113.  
  114.  
  115. Returns :
  116.  
  117.     <value>        TRUE if it is for the user
  118.             FALSE if not
  119.  
  120.  
  121. */
  122.  
  123. int chkfor (EVTptr)
  124.  
  125. EVT        *EVTptr;        /* Points to event thing */
  126.  
  127. {
  128. if (EVTptr -> EVT_FOR == NULL)        /* If for nobody */
  129.     return (TRUE);            /*  then it is for everybody */
  130. if (Usrnam == NULL)            /* If no username */
  131.     return (FALSE);            /*  then not for me. */
  132. return (nccmp(Usrnam, EVTptr -> EVT_FOR) == 0);
  133.                     /* Do no-case comparison */
  134. }
  135.