Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "ITI.h"
  4. #define right 77
  5. #define left 75
  6. #define Enter 13
  7. #define del 83
  8. #define ins 82
  9.  
  10. #define moveR 1
  11. #define moveL 2
  12. #define delete 3
  13. #define ent 4
  14. #define insert 5
  15. int main()
  16. {
  17. char* line = (char*)malloc(10 * sizeof(char));
  18. char* start, * cur, * end;
  19. start = cur = end = line;
  20. char key = ' ';
  21. int linesize=0;
  22. int command = 0;
  23. char* i = line;
  24. int replacemet = 0;
  25.  
  26. while (1) {
  27. key = _getch();
  28. if (key == -32 || key == NULL) {
  29. key = _getch();
  30. }
  31.  
  32. switch (key) {
  33. case right:
  34. command = moveR;
  35. break;
  36. case left:
  37. command = moveL;
  38. break;
  39. case del:
  40. command = delete;
  41. break;
  42. case ins:
  43. command = insert;
  44. break;
  45. case Enter:
  46. command = ent;
  47. default:
  48. command = 0;
  49.  
  50. }
  51.  
  52. switch (command)
  53. {
  54. case moveR:
  55. if (cur != end) {
  56. cur++;
  57. }
  58. break;
  59. case moveL:
  60. if (cur != start) {
  61. cur--;
  62. }
  63. break;
  64. case delete:
  65. if (linesize != 0) {
  66. for (char* y = cur; y < end - 1; y++) {
  67. *y = *(y + 1);
  68. }
  69. end--;
  70. linesize--;
  71. }
  72. break;
  73. case insert:
  74. if (replacemet == 0) {
  75. replacemet = 1;
  76. }
  77. else
  78. if (replacemet == 1) {
  79. replacemet == 0;
  80. }
  81. break;
  82. default:
  83. if (replacemet == 0) {
  84. if (linesize < 10) {
  85. end++;
  86. linesize++;
  87. for (char* k = end - 2; k >= cur; k--) {
  88. *(k + 1) = *k;
  89. }
  90. *cur = key;
  91. cur++;
  92. }
  93. }
  94. else
  95. if (linesize != 0) {
  96. *cur = key;
  97. }
  98. else
  99. end++;
  100. linesize++;
  101.  
  102. break;
  103. }
  104. system("cls");
  105. for (i = line; i < end; i++)
  106. {
  107. if (i == cur)
  108. {
  109. printHighlighted(*i);
  110. }
  111. else
  112. {
  113. printf("%c", *i);
  114. }
  115. }
  116. if (cur == end) {
  117. printHighlighted(" ");
  118. }
  119. }
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement