lsearch.c 943 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * This file lifted in toto from 'Dlibs' on the atari ST (RdeBath)
  3. *
  4. *
  5. * Dale Schumacher 399 Beacon Ave.
  6. * (alias: Dalnefre') St. Paul, MN 55104
  7. * dal@syntel.UUCP United States of America
  8. * "It's not reality that's important, but how you perceive things."
  9. */
  10. #include <stdio.h>
  11. char *lfind(key, base, num, size, cmp)
  12. register char *key, *base;
  13. unsigned int *num;
  14. register unsigned int size;
  15. register int (*cmp) ();
  16. {
  17. register int n = *num;
  18. while (n--) {
  19. if ((*cmp) (base, key) == 0)
  20. return (base);
  21. base += size;
  22. }
  23. return (NULL);
  24. }
  25. char *lsearch(key, base, num, size, cmp)
  26. char *key, *base;
  27. register unsigned int *num;
  28. register unsigned int size;
  29. int (*cmp) ();
  30. {
  31. register char *p;
  32. char *memcpy();
  33. if ((p = lfind(key, base, num, size, cmp)) == NULL) {
  34. p = memcpy((base + (size * (*num))), key, size);
  35. ++(*num);
  36. }
  37. return (p);
  38. }