V_const.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * \file V_const.c
  3. *
  4. * \brief Display constant functions.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. * \author GRASS GIS Development Team
  21. *
  22. * \date 1999-2006
  23. */
  24. #include <stdio.h>
  25. #include <grass/vask.h>
  26. /**
  27. * \fn int V_const (void *src, char var_type, int row, int col, int length)
  28. *
  29. * \brief Define screen constant.
  30. *
  31. * This routine allows a program to identify a constant, and where that
  32. * constant should be placed on the screen in the next call to
  33. * <i>V_call()</i>. <b>var_type</b> is one of <i>int</i>, <i>long</i>,
  34. * <i>float</i>, <i>double</i>, or <i>char</i>.
  35. *
  36. * \param[in] src
  37. * \param[in] var_type
  38. * \param[in] row
  39. * \param[in] col
  40. * \param[in] len
  41. * \return 0 on success
  42. * \return -1 on error
  43. */
  44. int V_const(void *src, int var_type, int row, int col, int length)
  45. {
  46. union target targetptr;
  47. targetptr.i = src;
  48. if (V__.NUM_CONST >= MAX_CONST) {
  49. V_error("Too many constants in call to V_const");
  50. return (-1);
  51. }
  52. if ((row < 0) || (row >= MAX_LINE)) {
  53. V_error("Illegal row (%d) in call to V_const", row);
  54. return (-1);
  55. }
  56. if ((col < 0) || (col > 80)) {
  57. V_error("Illegal column (%d) in call to V_const", col);
  58. return (-1);
  59. }
  60. if ((length < 0) || ((length + col) > 80)) {
  61. V_error("Length out of bounds in call to V_const");
  62. return (-1);
  63. }
  64. if ((var_type == 's') || (var_type == 'i') || (var_type == 'f')
  65. || (var_type == 'l') || (var_type == 'd')) {
  66. V__.constant[V__.NUM_CONST].targetptr = targetptr;
  67. V__.constant[V__.NUM_CONST].var_type = var_type;
  68. V__.constant[V__.NUM_CONST].row = row;
  69. V__.constant[V__.NUM_CONST].col = col;
  70. V__.constant[V__.NUM_CONST].length = length;
  71. V__.constant[V__.NUM_CONST].decimal_places = V__.decimal_places;
  72. V__.NUM_CONST++;
  73. return (0);
  74. }
  75. else {
  76. V_error("Illegal variable type in call to V_const");
  77. return (-1);
  78. }
  79. }