using namespace std;
-void build_display(char **choices, char *regexp) {
+const int buffer_size = 1024;
+const int nb_lines_max = 1000;
+
+void build_display(int nb_lines, char **lines, char *regexp) {
+ char buffer[buffer_size];
clear(); // Cleaning the window
refresh(); // After doing something on the display, we refresh it
- for(int y = 0; y < 10; y++) {
- printw("y = %d\n", y);
+ int maxx = getmaxx(stdscr);
+ int maxy = getmaxy(stdscr);
+ printw("maxx %d maxy %d\n", maxx, maxy);
+ printw("nb_lines %d\n", nb_lines);
+ int nb_printed_lines = 2;
+ for(int y = 0; nb_printed_lines < maxy && y < nb_lines; y++) {
+ int k = 0;
+ while(lines[y][k] && k < buffer_size - 2 && k < maxx) {
+ buffer[k] = lines[y][k];
+ k++;
+ }
+ buffer[k++] = '\n';
+ buffer[k++] = '\0';
+ printw(buffer);
+ nb_printed_lines++;
}
- printw("regexp = \"%s\"", regexp);
}
int main(int argc, char **argv) {
int dummy, xpos, ypos;
- const int buffer_size = 1024;
- const int nb_lines_max = 1000;
char buffer[buffer_size];
char *lines[nb_lines_max];
file.getline(buffer, buffer_size);
lines[nb_lines] = new char[strlen(buffer) + 1];
strcpy(lines[nb_lines], buffer);
+ nb_lines++;
}
char regexp[buffer_size]="";
int key;
do {
- build_display(0, regexp);
+ build_display(nb_lines, lines, regexp);
key = getch();
- regexp[regexp_point++] = key;
- regexp[regexp_point] = '\0';
+ if(key >= 'a' && key <= 'z') {
+ regexp[regexp_point++] = key;
+ regexp[regexp_point] = '\0';
+ }
} while(key != 'q');
echo(); // We want to have echo