home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cuj9301.zip / 1101090A < prev    next >
Text File  |  1992-11-10  |  1KB  |  63 lines

  1. /////////////////
  2. // catalog.cpp //
  3. /////////////////
  4.  
  5. #include "isam.h"
  6. #include <ctype.h>
  7.  
  8. static struct cat {
  9.     char *name;
  10.     t_func func;
  11. } Catalog[]    =    {    {    "descwrds",    descwrds    },
  12.                         {    NULL,            NULL        }    };
  13.  
  14. ///////////////////////
  15. // Catalog utilities //
  16. ///////////////////////
  17.  
  18. int catalog_number (char *name)
  19. {
  20.     int i = 0;
  21.     while (Catalog[i].name) {
  22.         if (!strcmp(nospace(name), Catalog[i].name))
  23.             return i;
  24.         i++;
  25.     }
  26.     return -1;
  27. }
  28.  
  29. t_func cataloged_func(int f)
  30. {
  31.     return Catalog[f].func;
  32. }
  33.  
  34. /////////////////////////
  35. // Cataloged functions //
  36. /////////////////////////
  37.  
  38. char     *    descwrds    (char *r);
  39.  
  40. char *descwrds (char *r)
  41. {    // Extracts up to 20 - 7 letter words from desc field.
  42.     // The description field starts at posn 37 and goes
  43.     // on for 120 characters.
  44.     static char keys[141];
  45.     int i = 37, j = 0, k = 0;
  46.  
  47.     memset (keys, ' ', 140);
  48.     while ((i < 157) && (k < 20)){
  49.         while ((ispunct(r[i]) || isspace(r[i])) && i < 157)
  50.             i++;
  51.         while (!ispunct(r[i]) && !isspace(r[i]) && i < 157
  52.                 && j < 7)
  53.             keys[(7 * k) + j++] = r[i++];
  54.         while (!ispunct(r[i]) && !isspace(r[i]) && i < 157)
  55.             i++;
  56.         k++;
  57.         j = 0;
  58.     }
  59.     keys[7 * k] = '\0';
  60.     return keys;
  61. }
  62.  
  63.