r_info.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Function: infofile
  2. **
  3. ** Author: Paul W. Carlson April 1992
  4. */
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <grass/colors.h>
  8. #include <grass/glocale.h>
  9. #include "map_info.h"
  10. #include "clr.h"
  11. #include "local_proto.h"
  12. #define KEY(x) (strcmp(key,x)==0)
  13. static char *help[] = {
  14. "where x y",
  15. "font fontname",
  16. "fontsize fontsize",
  17. "color color",
  18. "background color|none",
  19. "border color|none",
  20. ""
  21. };
  22. int read_info(void)
  23. {
  24. char buf[1024];
  25. char *key, *data;
  26. int fontsize;
  27. double x, y;
  28. int r, g, b, ret;
  29. PSCOLOR color, bgcolor, border;
  30. fontsize = 0;
  31. set_color(&color, 0, 0, 0);
  32. set_color(&bgcolor, 255, 255, 255);
  33. unset_color(&border);
  34. x = y = 0.0;
  35. while (input(2, buf, help)) {
  36. if (!key_data(buf, &key, &data))
  37. continue;
  38. if (KEY("where")) {
  39. if (sscanf(data, "%lf %lf", &x, &y) != 2) {
  40. x = y = 0.0;
  41. error(key, data, _("illegal where request"));
  42. }
  43. else
  44. continue;
  45. }
  46. if (KEY("fontsize")) {
  47. fontsize = atoi(data);
  48. if (fontsize < 4 || fontsize > 50)
  49. fontsize = 0;
  50. continue;
  51. }
  52. if (KEY("color")) {
  53. ret = G_str_to_color(data, &r, &g, &b);
  54. if (ret == 1)
  55. set_color(&color, r, g, b);
  56. else if (ret == 2) /* i.e. "none" */
  57. /* unset_color(&color); */
  58. error(key, data, _("Unsupported color request"));
  59. else
  60. error(key, data, _("illegal color request"));
  61. continue;
  62. }
  63. if (KEY("background")) {
  64. ret = G_str_to_color(data, &r, &g, &b);
  65. if (ret == 1)
  66. set_color(&bgcolor, r, g, b);
  67. else if (ret == 2) /* i.e. "none" */
  68. unset_color(&bgcolor);
  69. else
  70. error(key, data, _("illegal bgcolor request"));
  71. continue;
  72. }
  73. if (KEY("border")) {
  74. ret = G_str_to_color(data, &r, &g, &b);
  75. if (ret == 1)
  76. set_color(&border, r, g, b);
  77. else if (ret == 2) /* i.e. "none" */
  78. unset_color(&border);
  79. else
  80. error(key, data, _("illegal border color request"));
  81. continue;
  82. }
  83. if (KEY("font")) {
  84. get_font(data);
  85. m_info.font = G_store(data);
  86. continue;
  87. }
  88. error(key, data, _("illegal mapinfo sub-request"));
  89. }
  90. m_info.x = x;
  91. m_info.y = y;
  92. m_info.color = color;
  93. m_info.bgcolor = bgcolor;
  94. m_info.border = border;
  95. if (fontsize)
  96. m_info.fontsize = fontsize;
  97. return 0;
  98. }