Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.3 KiB

  1. /* $Header: /nw/tony/src/stevie/src/RCS/mark.c,v 1.3 89/03/11 22:42:39 tony Exp $
  2. *
  3. * Routines to save and retrieve marks.
  4. */
  5. #include "stevie.h"
  6. #define NMARKS 10 /* max. # of marks that can be saved */
  7. struct mark {
  8. char name;
  9. LNPTR pos;
  10. };
  11. static struct mark mlist[NMARKS];
  12. static struct mark pcmark; /* previous context mark */
  13. static bool_t pcvalid = FALSE; /* true if pcmark is valid */
  14. /*
  15. * setmark(c) - set mark 'c' at current cursor position
  16. *
  17. * Returns TRUE on success, FALSE if no room for mark or bad name given.
  18. */
  19. bool_t
  20. setmark(c)
  21. register char c;
  22. {
  23. register int i;
  24. if (!isalpha(c))
  25. return FALSE;
  26. /*
  27. * If there is already a mark of this name, then just use the
  28. * existing mark entry.
  29. */
  30. for (i=0; i < NMARKS ;i++) {
  31. if (mlist[i].name == c) {
  32. mlist[i].pos = *Curschar;
  33. return TRUE;
  34. }
  35. }
  36. /*
  37. * There wasn't a mark of the given name, so find a free slot
  38. */
  39. for (i=0; i < NMARKS ;i++) {
  40. if (mlist[i].name == NUL) { /* got a free one */
  41. mlist[i].name = c;
  42. mlist[i].pos = *Curschar;
  43. return TRUE;
  44. }
  45. }
  46. return FALSE;
  47. }
  48. /*
  49. * setpcmark() - set the previous context mark to the current position
  50. */
  51. void
  52. setpcmark()
  53. {
  54. pcmark.pos = *Curschar;
  55. pcvalid = TRUE;
  56. }
  57. /*
  58. * getmark(c) - find mark for char 'c'
  59. *
  60. * Return pointer to LNPTR or NULL if no such mark.
  61. */
  62. LNPTR *
  63. getmark(c)
  64. register char c;
  65. {
  66. register int i;
  67. if (c == '\'' || c == '`') /* previous context mark */
  68. return pcvalid ? &(pcmark.pos) : (LNPTR *) NULL;
  69. for (i=0; i < NMARKS ;i++) {
  70. if (mlist[i].name == c)
  71. return &(mlist[i].pos);
  72. }
  73. return (LNPTR *) NULL;
  74. }
  75. /*
  76. * clrall() - clear all marks
  77. *
  78. * Used mainly when trashing the entire buffer during ":e" type commands
  79. */
  80. void
  81. clrall()
  82. {
  83. register int i;
  84. for (i=0; i < NMARKS ;i++)
  85. mlist[i].name = NUL;
  86. pcvalid = FALSE;
  87. }
  88. /*
  89. * clrmark(line) - clear any marks for 'line'
  90. *
  91. * Used any time a line is deleted so we don't have marks pointing to
  92. * non-existent lines.
  93. */
  94. void
  95. clrmark(line)
  96. register LINE *line;
  97. {
  98. register int i;
  99. for (i=0; i < NMARKS ;i++) {
  100. if (mlist[i].pos.linep == line)
  101. mlist[i].name = NUL;
  102. }
  103. if (pcvalid && (pcmark.pos.linep == line))
  104. pcvalid = FALSE;
  105. }