r_header.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Function: hdrfile
  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 "header.h"
  10. #include "clr.h"
  11. #include "local_proto.h"
  12. #define KEY(x) (strcmp(key,x)==0)
  13. static char *help[] = {
  14. "file header file",
  15. "font fontname",
  16. "fontsize fontsize",
  17. "color color",
  18. ""
  19. };
  20. int read_header(void)
  21. {
  22. char buf[1024];
  23. char *key, *data;
  24. int fontsize;
  25. PSCOLOR color;
  26. int ret, r, g, b;
  27. fontsize = 0;
  28. set_color(&color, 0, 0, 0);
  29. while (input(2, buf, help)) {
  30. if (!key_data(buf, &key, &data))
  31. continue;
  32. if (KEY("none")) {
  33. PS.do_header = 0;
  34. continue;
  35. }
  36. if (KEY("file")) {
  37. G_strip(data);
  38. hdr.fp = fopen(data, "r");
  39. if (hdr.fp != NULL)
  40. hdr.file = G_store(data);
  41. continue;
  42. }
  43. if (KEY("fontsize")) {
  44. fontsize = atoi(data);
  45. if (fontsize < 4 || fontsize > 50)
  46. fontsize = 0;
  47. continue;
  48. }
  49. if (KEY("color")) {
  50. ret = G_str_to_color(data, &r, &g, &b);
  51. if (ret == 1)
  52. set_color(&color, r, g, b);
  53. else if (ret == 2) /* i.e. "none" */
  54. /* unset_color(&color); */
  55. error(key, data, _("Unsupported color request"));
  56. else
  57. error(key, data, _("illegal color request"));
  58. continue;
  59. }
  60. if (KEY("font")) {
  61. get_font(data);
  62. hdr.font = G_store(data);
  63. continue;
  64. }
  65. error(key, data, _("illegal header sub-request"));
  66. }
  67. hdr.color = color;
  68. if (fontsize)
  69. hdr.fontsize = fontsize;
  70. return 0;
  71. }