efn/c_print.c

51 lines
1016 B
C

void
print_with_fixed_tabs(Row *row) {
for (int i = 0; i < ROW_SIZE; i++) {
if(row->text[i] == 0) break;
if (row->text[i] == '\t') printf(" ");
else printf("%c", row->text[i]);
}
}
/*
void
c_print(char *c, char **argv) {
Row *row = buffer;
int line = 1;
if (atoi(c + 2) != 0) line = atoi(c + 2);
row = b_getline(buffer, line);
if (row == NULL) {puts("invalid line."); return;}
for (;; line++) {
printf("%3.i| ", line);
print_with_fixed_tabs(row);
puts("");
if (row->n == NULL) break;
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;
}
}