print command now accepts start + end lines

master
bx 2022-04-03 09:28:24 +01:00
parent b7a4fec162
commit 03d19d3169
2 changed files with 25 additions and 0 deletions

View File

@ -24,4 +24,10 @@ b_truncate(Row *row) {
}
}
int
b_countlines(Row *row) {
int lines = 1;
for(; row->n != NULL; row = row->n) lines++;
return lines;
}

View File

@ -7,6 +7,7 @@ else printf("%c", row->text[i]);
}
}
/*
void
c_print(char *c, char **argv) {
Row *row = buffer;
@ -22,6 +23,24 @@ c_print(char *c, char **argv) {
row = row -> n;
}
}
*/
void
c_print(char *c, char **argv) {
int start = argv[1] != NULL ? atoi(argv[1]) : 1;
int end = argv[2] != NULL ? atoi(argv[2]) : b_countlines(buffer);
start = start > 1 ? start : 1;
end = end < b_countlines(buffer) ? end : b_countlines(buffer);
Row *row = b_getline(buffer, start);
for(int line = start; line <= end; line++) {
printf("%3.i| ", line);
print_with_fixed_tabs(row);
puts("");
row = row->n;
}
}