Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "History.h"
- #include <string.h>
- #include <unistd.h>
- #include <stdio.h>
- History::History()
- {
- hist = {0};
- index = 0;
- r_index = 0;
- }
- History::~History()
- {
- for (int i = 0; i < 20; i++)
- {
- if (hist[i] != 0)
- {
- delete[] (hist[i]);
- }
- }
- }
- void History::addEntry(char* str)
- {
- if (hist[index] != NULL)
- {
- delete[] (hist[index]);
- }
- hist[index] = new char[65];
- strcpy(hist[index], str);
- index = (index + 1) % 20;
- }
- void History::printEntry()
- {
- printf( "%s", hist[r_index] );
- fflush(stdout);
- }
- void History::printAll()
- {
- r_index = index;
- if (hist[0] == NULL)
- {
- }
- else if (hist[(index + 1) % 20] == NULL)
- {
- r_index = 0;
- while(r_index < index)
- {
- printEntry();
- printf("%c", '\n');
- fflush(stdout);
- r_index++;
- }
- }
- else
- {
- for(int i = 0; i < 20; i++)
- {
- printEntry();
- r_index = (r_index - 1) % 20;
- }
- }
- }
Add Comment
Please, Sign In to add comment