home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / shellforms / part02 / keyword.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-09  |  1.2 KB  |  50 lines

  1. /* Last update: 01/13/88  10:43 AM  (Edition: 5) */
  2. #include    <stdio.h>
  3. #include    "basic.h"
  4. /*----------------------------------------------------------------------+
  5. |                                    |
  6. |    fill_keyword : fill the field with possible matched keyword    |
  7. |                                    |
  8. +----------------------------------------------------------------------*/
  9. fill_keyword (buf, len, list)
  10. char        *buf;
  11. unsigned    len;            /* size of input field */
  12. char        **list;
  13.     {
  14.     int        i, j;
  15.     unsigned    flen;        /* field length */
  16.     unsigned char    match[80];
  17.  
  18.     ENTER (fill_keyword);
  19.     flen = fldlen (buf, len);
  20.  
  21.     for (i=j=0; list[i] != NULL; i++) {
  22.         if (kwcmp (buf, list[i], flen) == 0) {
  23.             /* find a match */
  24.             match[j++] = i;
  25.             }
  26.         }
  27.     if (j == 1) bcopy (buf, list[match[0]], len);
  28.     else if (j > 1)     bcopy (buf, list[match[0]], flen);
  29.  
  30.     RETURN (j);
  31.     }
  32.  
  33. /*----------------------------------------------------------------------+
  34. |                                    |
  35. |    kwcmp : compare a word with keyword (case insensitive)        |
  36. |                                    |
  37. +----------------------------------------------------------------------*/
  38. kwcmp (src, dest, len)
  39. char        *src;
  40. char        *dest;
  41. unsigned    len;
  42.     {
  43.     ENTER (kwcmp);
  44.     while (len-- != 0) {
  45.         if ((*src++ | 0x20) != (*dest++ | 0x20))
  46.              RETURN (1);            /* no match */
  47.         }
  48.     RETURN (0);        /* match found */
  49.     }
  50.