cpr_get.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* $MirOS: contrib/hosted/fwcf/cpr_get.c,v 1.4 2007/03/09 22:35:13 tg Exp $ */
  2. /*-
  3. * Copyright (c) 2006, 2007
  4. * Thorsten Glaser <tg@mirbsd.de>
  5. *
  6. * Licensee is hereby permitted to deal in this work without restric-
  7. * tion, including unlimited rights to use, publicly perform, modify,
  8. * merge, distribute, sell, give away or sublicence, provided all co-
  9. * pyright notices above, these terms and the disclaimer are retained
  10. * in all redistributions or reproduced in accompanying documentation
  11. * or other materials provided with binary redistributions.
  12. *
  13. * Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
  14. * express, or implied, to the maximum extent permitted by applicable
  15. * law, without malicious intent or gross negligence; in no event may
  16. * licensor, an author or contributor be held liable for any indirect
  17. * or other damage, or direct damage except proven a consequence of a
  18. * direct error of said person and intended use of this work, loss or
  19. * other issues arising in any way out of its use, even if advised of
  20. * the possibility of such damage or existence of a defect.
  21. */
  22. #include <sys/param.h>
  23. #include <err.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include "defs.h"
  27. #include "compress.h"
  28. __RCSID("$MirOS: contrib/hosted/fwcf/cpr_get.c,v 1.4 2007/03/09 22:35:13 tg Exp $");
  29. fwcf_compressor *
  30. compressor_get(uint8_t algo)
  31. {
  32. fwcf_compressor *list;
  33. if ((list = compress_enumerate()) == NULL)
  34. errx(1, "compress_enumerate");
  35. if (list[algo].name == NULL)
  36. errx(1, "compression algorithm %02Xh not loaded", algo);
  37. if (list[algo].init())
  38. errx(1, "cannot initialise %s compression", list[algo].name);
  39. return (&(list[algo]));
  40. }
  41. int
  42. compressor_getbyname(const char *s)
  43. {
  44. fwcf_compressor *cl;
  45. int i;
  46. if ((cl = compress_enumerate()) == NULL)
  47. errx(1, "no compression algorithms found");
  48. for (i = 1; i < 256; ++i)
  49. if (cl[i].name != NULL)
  50. if (!strcasecmp(cl[i].name, s))
  51. return (i);
  52. return (0);
  53. }