common.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* common.c -- Common functions.
  2. *
  3. * Copyright (C) 2013 Artyom V. Poptsov <poptsov.artyom@gmail.com>
  4. *
  5. * This file is part of Guile-SSH.
  6. *
  7. * Guile-SSH is free software: you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * Guile-SSH is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Guile-SSH. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <libguile.h>
  22. #include <libssh/libssh.h>
  23. #include "common.h"
  24. /* Convert the SSH constant VALUE to a Scheme symbol */
  25. SCM
  26. _ssh_const_to_scm (const struct symbol_mapping *types, int value)
  27. {
  28. const struct symbol_mapping *t;
  29. for (t = types; t->symbol; ++t)
  30. {
  31. if (t->value == value)
  32. return scm_from_locale_symbol (t->symbol);
  33. }
  34. return SCM_BOOL_F;
  35. }
  36. /* Convert the Scheme symbol VALUE to a SSH constant.
  37. Return the apropriate structure that contains the needed
  38. constant. */
  39. const struct symbol_mapping *
  40. _scm_to_ssh_const (const struct symbol_mapping *types, SCM value)
  41. {
  42. const struct symbol_mapping *t;
  43. char *sym = scm_to_locale_string (scm_symbol_to_string (value));
  44. for (t = types; t->symbol; ++t)
  45. {
  46. if (! strcmp (t->symbol, sym))
  47. return t;
  48. }
  49. return NULL;
  50. }
  51. /* Return an address of the object OBJ as an hexadecimal number represented as
  52. a string. */
  53. SCM
  54. _scm_object_hex_address (SCM obj)
  55. {
  56. return scm_number_to_string (scm_object_address (obj), scm_from_uint (16U));
  57. }
  58. /* common.c ends here. */