r_header.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Function: hdrfile
  2. **
  3. ** Author: Paul W. Carlson April 1992
  4. */
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "header.h"
  8. #include "ps_info.h"
  9. #include "local_proto.h"
  10. #define KEY(x) (strcmp(key,x)==0)
  11. static char *help[] = {
  12. "file header file",
  13. "font fontname",
  14. "fontsize fontsize",
  15. "color color",
  16. ""
  17. };
  18. int read_header(void)
  19. {
  20. char buf[1024];
  21. char *key, *data;
  22. int color, fontsize;
  23. fontsize = 0;
  24. color = BLACK;
  25. while (input(2, buf, help)) {
  26. if (!key_data(buf, &key, &data))
  27. continue;
  28. if (KEY("none")) {
  29. PS.do_header = 0;
  30. continue;
  31. }
  32. if (KEY("file")) {
  33. G_strip(data);
  34. hdr.fp = fopen(data, "r");
  35. if (hdr.fp != NULL)
  36. hdr.file = G_store(data);
  37. continue;
  38. }
  39. if (KEY("fontsize")) {
  40. fontsize = atoi(data);
  41. if (fontsize < 4 || fontsize > 50)
  42. fontsize = 0;
  43. continue;
  44. }
  45. if (KEY("color")) {
  46. color = get_color_number(data);
  47. if (color < 0) {
  48. color = BLACK;
  49. error(key, data, "illegal color request");
  50. }
  51. continue;
  52. }
  53. if (KEY("font")) {
  54. get_font(data);
  55. hdr.font = G_store(data);
  56. continue;
  57. }
  58. error(key, data, "illegal header sub-request");
  59. }
  60. hdr.color = color;
  61. if (fontsize)
  62. hdr.fontsize = fontsize;
  63. return 0;
  64. }