lsearch.c 946 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 <string.h>
  11. #include <stdio.h>
  12. char *lfind(key, base, num, size, cmp)
  13. register char *key, *base;
  14. unsigned int *num;
  15. register unsigned int size;
  16. register int (*cmp) ();
  17. {
  18. register int n = *num;
  19. while (n--) {
  20. if ((*cmp) (base, key) == 0)
  21. return (base);
  22. base += size;
  23. }
  24. return (NULL);
  25. }
  26. char *lsearch(key, base, num, size, cmp)
  27. char *key, *base;
  28. register unsigned int *num;
  29. register unsigned int size;
  30. int (*cmp) ();
  31. {
  32. register char *p;
  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. }