Compare commits

..

2 Commits

Author SHA1 Message Date
bx 1996e05ff6 open uses new command format now 2022-04-03 09:35:05 +01:00
bx 03d19d3169 print command now accepts start + end lines 2022-04-03 09:28:24 +01:00
3 changed files with 28 additions and 1 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

@ -1,6 +1,7 @@
void
c_open(char *file, char **argv) {
FILE *f = fopen(file + 2, "r");
if(argv[1] == NULL) { puts("usage: O filename"); return;}
FILE *f = fopen(argv[1], "r");
if(f == NULL) { puts("couldnt open file."); return; }
b_truncate(buffer);
Row *row = buffer;
@ -38,3 +39,4 @@ c_save(char *file, char **argv) {

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;
}
}