Compare commits
2 Commits
b7a4fec162
...
1996e05ff6
Author | SHA1 | Date |
---|---|---|
bx | 1996e05ff6 | |
bx | 03d19d3169 |
6
buffer.c
6
buffer.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
4
c_file.c
4
c_file.c
|
@ -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) {
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
19
c_print.c
19
c_print.c
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue