scan_ref.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* This stuff is taken from the p.map/cmd files text.h, scan_ref.c and case.c
  2. **
  3. ** Paul W. Carlson March 1992
  4. */
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include "local_proto.h"
  8. #define LEFT 0
  9. #define RIGHT 1
  10. #define LOWER 0
  11. #define UPPER 1
  12. #define CENTER 2
  13. static int xok, yok;
  14. static int ymatch(char *, int *);
  15. static int xmatch(char *, int *);
  16. int scan_ref(char *buf, int *xref, int *yref)
  17. {
  18. char word1[50], word2[50];
  19. xok = yok = 0;
  20. *xref = *yref = CENTER;
  21. switch (sscanf(buf, "%s%s", word1, word2)) {
  22. case 2:
  23. lowercase(word2);
  24. if (!(xmatch(word2, xref) || ymatch(word2, yref)))
  25. return 0;
  26. case 1:
  27. lowercase(word1);
  28. if (xmatch(word1, xref) || ymatch(word1, yref))
  29. return 1;
  30. default:
  31. return 0;
  32. }
  33. }
  34. static int xmatch(char *word, int *xref)
  35. {
  36. if (strcmp(word, "center") == 0)
  37. return 1;
  38. if (strcmp(word, "middle") == 0)
  39. return 1;
  40. if (xok)
  41. return 0;
  42. if (strcmp(word, "left") == 0)
  43. *xref = LEFT;
  44. else if (strcmp(word, "right") == 0)
  45. *xref = RIGHT;
  46. else
  47. return 0;
  48. xok = 1;
  49. return 1;
  50. }
  51. static int ymatch(char *word, int *yref)
  52. {
  53. if (strcmp(word, "center") == 0)
  54. return 1;
  55. if (strcmp(word, "middle") == 0)
  56. return 1;
  57. if (yok)
  58. return 0;
  59. if (strcmp(word, "upper") == 0)
  60. *yref = UPPER;
  61. else if (strcmp(word, "top") == 0)
  62. *yref = UPPER;
  63. else if (strcmp(word, "lower") == 0)
  64. *yref = LOWER;
  65. else if (strcmp(word, "bottom") == 0)
  66. *yref = LOWER;
  67. else
  68. return 0;
  69. yok = 1;
  70. return 1;
  71. }
  72. int lowercase(register char *s)
  73. {
  74. for (; *s; s++)
  75. if (*s >= 'A' && *s <= 'Z')
  76. *s += 'a' - 'A';
  77. return 0;
  78. }