Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. #ifndef TEXTBUFFER_H
  2. #define TEXTBUFFER_H
  3.  
  4. #include <stdbool.h>
  5.  
  6. typedef struct textbuffer *TB;
  7.  
  8. typedef struct _matchNode {
  9. int lineNumber;
  10. int columnNumber;
  11. struct _matchNode* next;
  12. } matchNode;
  13.  
  14. typedef matchNode *Match;
  15.  
  16. /* Allocate a new textbuffer whose contents is initialised with the text given
  17. * in the array.
  18. */
  19. TB newTB (char text[]);
  20.  
  21. /* Free the memory occupied by the given textbuffer. It is an error to access
  22. * the buffer afterwards.
  23. */
  24. void releaseTB (TB tb);
  25.  
  26. /* Allocate and return an array containing the text in the given textbuffer.
  27. * add a prefix corrosponding to line number iff showLineNumbers == TRUE
  28. */
  29. char *dumpTB (TB tb, bool showLineNumbers);
  30.  
  31. /* Return the number of lines of the given textbuffer.
  32. */
  33. int linesTB (TB tb);
  34.  
  35. /* Add a given prefix to all lines between pos1 and pos2
  36. *
  37. * - The program is to abort() with an error message if line 'pos1' or line
  38. * 'pos2' is out of range. The first line of a textbuffer is at position 0.
  39. */
  40. void addPrefixTB (TB tb, int pos1, int pos2, char* prefix);
  41.  
  42. /* Merge 'tb2' into 'tb1' at line 'pos'.
  43. *
  44. * - Afterwards line 0 of 'tb2' will be line 'pos' of 'tb1'.
  45. * - The old line 'pos' of 'tb1' will follow after the last line of 'tb2'.
  46. * - After this operation 'tb2' can not be used anymore (as if we had used
  47. * releaseTB() on it).
  48. * - The program is to abort() with an error message if 'pos' is out of range.
  49. */
  50. void mergeTB (TB tb1, int pos, TB tb2);
  51.  
  52. /* Copy 'tb2' into 'tb1' at line 'pos'.
  53. *
  54. * - Afterwards line 0 of 'tb2' will be line 'pos' of 'tb1'.
  55. * - The old line 'pos' of 'tb1' will follow after the last line of 'tb2'.
  56. * - After this operation 'tb2' is unmodified and remains usable independent
  57. * of 'tb1'.
  58. * - The program is to abort() with an error message if 'pos' is out of range.
  59. */
  60. void pasteTB (TB tb1, int pos, TB tb2);
  61.  
  62. /* Cut the lines between and including 'from' and 'to' out of the textbuffer
  63. * 'tb'.
  64. *
  65. * - The result is a new textbuffer (much as one created with newTB()).
  66. * - The cut lines will be deleted from 'tb'.
  67. * - The program is to abort() with an error message if 'from' or 'to' is out
  68. * of range.
  69. */
  70. TB cutTB (TB tb, int from, int to);
  71.  
  72. /* Return a linked list of Match nodes of all the matches of string search
  73. * in tb
  74. *
  75. * - The textbuffer 'tb' will remain unmodified.
  76. * - The user is responsible of freeing the returned list
  77. */
  78. Match searchTB (TB tb, char* search);
  79.  
  80. /* Remove the lines between and including 'from' and 'to' from the textbuffer
  81. * 'tb'.
  82. *
  83. * - The program is to abort() with an error message if 'from' or 'to' is out
  84. * of range.
  85. */
  86. void deleteTB (TB tb, int from, int to);
  87.  
  88.  
  89. /* Search every line of tb for each occurrence of a set of specified subsitituions
  90. * and alter them accordingly
  91. *
  92. * refer to spec for table.
  93. */
  94. void formRichText (TB tb);
  95.  
  96.  
  97. /* Your whitebox tests
  98. */
  99. void whiteBoxTests();
  100.  
  101. /* Bonus Challenges
  102. */
  103.  
  104. char* diffTB (TB tb1, TB tb2) ;
  105.  
  106. void undoTB (TB tb) ;
  107.  
  108. void redoTB (TB tb) ;
  109.  
  110. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement