home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c023 / 1.img / PROGRAMS / BLDKEY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-05  |  1.5 KB  |  50 lines

  1. /* (C) Copyright 1984,85,86,87 Walter L. Peacock    All Rights Reserved    */
  2.  
  3. /*---------------------------------------------------------------------------- 
  4.  * bldkey() is an example of a routine that builds a concatenated key 
  5.  * that is to be stored in the B+tree index.  USERBTR.EXE calls this function 
  6.  * to build the name key.
  7.  *---------------------------------------------------------------------------*/
  8.  
  9. /*    patrec - structure for the patient record file        */
  10.  
  11. #include "cbtree.h"
  12. #include "patrec.str"
  13.  
  14. char to_upper(c)   /* need non-#define'd version */
  15. char c;
  16. {
  17.     return((char)toupper(c));
  18. }
  19.  
  20. /* build the search key and return length of key    */
  21. int bldkey(keyfield, maxlen, pr)
  22. char    *keyfield;
  23. uint    maxlen;
  24. PATREC *pr;
  25. {
  26.     extern char to_upper();
  27.     register int i;
  28.     char *prlnme, *prfnme, *prmint;
  29.  
  30.     i = 0;                  /* needs to be here for EC */
  31.     prlnme = pr->lname;
  32.     prfnme = pr->fname;
  33.     prmint = pr->minit;
  34.  
  35.     while (i < maxlen  &&  (keyfield[i] = to_upper(*prlnme++)) != NUL)
  36.         ++i;
  37.     if (i < maxlen)   /* need space between names for proper ordering */
  38.         keyfield[i++] = ' ';
  39.     while (i < maxlen  &&  (keyfield[i] = to_upper(*prfnme++)) != NUL)
  40.         ++i;
  41.     if (i < maxlen && keyfield[i-1] != ' ')   /* only 1 space ! */
  42.         keyfield[i++] = ' ';
  43.     if (i < maxlen    &&  (keyfield[i] = to_upper(*prmint)) != NUL)
  44.         ++i;
  45.     if (keyfield[i-1] == ' ')   /* don't end in space ! */
  46.         --i;
  47.     keyfield[i] = '\0';
  48.     return(i);                    /* return strlen of keyfield  */
  49. }
  50.