unctrl.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * \file unctrl.c
  3. *
  4. * \brief GIS Library - Handles control characters.
  5. *
  6. * (C) 2001-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author GRASS GIS Development Team
  12. *
  13. * \date 1999-2006
  14. */
  15. #include <stdio.h>
  16. #include <grass/gis.h>
  17. /**
  18. * \brief Printable version of control character.
  19. *
  20. * This routine returns a pointer to a string which contains an
  21. * English-like representation for the character <b>c</b>. This is useful for
  22. * nonprinting characters, such as control characters. Control characters are
  23. * represented by ctrl-C, e.g., control A is represented by ctrl-A. 0177 is
  24. * represented by DEL/RUB. Normal characters remain unchanged.
  25. *
  26. * \param[in] int c
  27. * \return char * pointer to string containing English-like representation for character <b>c</b>
  28. */
  29. char *G_unctrl(int c)
  30. {
  31. static char buf[20];
  32. if (c < ' ')
  33. sprintf(buf, "ctrl-%c", c | 0100);
  34. else if (c < 0177)
  35. sprintf(buf, "%c", c);
  36. else if (c == 0177)
  37. sprintf(buf, "DEL/RUB");
  38. else
  39. sprintf(buf, "Mctrl-%c", (c & 77) | 0100);
  40. return buf;
  41. }