V_const.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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(
  45. void *src, int var_type,
  46. int row, int col, int length)
  47. {
  48. union target targetptr ;
  49. targetptr.i = src;
  50. if (V__.NUM_CONST >= MAX_CONST )
  51. {
  52. V_error("Too many constants in call to V_const") ;
  53. return(-1) ;
  54. }
  55. if ((row < 0) || (row >= MAX_LINE))
  56. {
  57. V_error("Illegal row (%d) in call to V_const", row) ;
  58. return(-1) ;
  59. }
  60. if ((col < 0) || (col > 80))
  61. {
  62. V_error("Illegal column (%d) in call to V_const", col) ;
  63. return(-1) ;
  64. }
  65. if ((length < 0) || ((length + col) > 80))
  66. {
  67. V_error("Length out of bounds in call to V_const") ;
  68. return(-1) ;
  69. }
  70. if ((var_type == 's') || (var_type == 'i') || (var_type == 'f')
  71. || (var_type == 'l') || (var_type == 'd'))
  72. {
  73. V__.constant[V__.NUM_CONST].targetptr = targetptr ;
  74. V__.constant[V__.NUM_CONST].var_type = var_type ;
  75. V__.constant[V__.NUM_CONST].row = row ;
  76. V__.constant[V__.NUM_CONST].col = col ;
  77. V__.constant[V__.NUM_CONST].length = length ;
  78. V__.constant[V__.NUM_CONST].decimal_places = V__.decimal_places ;
  79. V__.NUM_CONST++ ;
  80. return(0) ;
  81. }
  82. else
  83. {
  84. V_error("Illegal variable type in call to V_const") ;
  85. return(-1) ;
  86. }
  87. }