added indent and unindent commmands

master
bx 2022-04-02 16:12:22 +00:00
parent 5ed3ab8aa6
commit 054e0b02e8
5 changed files with 36 additions and 2 deletions

23
c_indent.c 100644
View File

@ -0,0 +1,23 @@
void
c_indent(char *c) {
Row *row = b_getline(buffer, atoi(c + 2));
if (row == NULL) { puts ("invalid line"); return; }
for(int i = ROW_SIZE - 1; i >= 1; i--) {
row->text[i] = row->text[i - 1];
}
row->text[0] = '\t';
}
void
c_unindent(char *c) {
Row *row = b_getline(buffer, atoi(c + 2));
if (row == NULL) { puts ("invalid line"); return; }
for(int i = 0; i < ROW_SIZE - 1; i++) {
row->text[i] = row->text[i + 1];
}
row->text[ROW_SIZE] = 0;
}

View File

@ -11,3 +11,7 @@ NULL,
['p'] = NULL, ['p'] = NULL,
['p'] = c_print, ['p'] = c_print,
['P'] = NULL, ['P'] = NULL,
[']'] = c_indent,
['['] = c_unindent,

2
efn.c
View File

@ -22,3 +22,5 @@
#include "c_save.c" #include "c_save.c"
#include "c_insertline.c" #include "c_insertline.c"
#include "c_indent.c"

4
efn.h
View File

@ -14,3 +14,7 @@ Row *b_getline(Row *, int);
void c_writeline(char *); void c_writeline(char *);
void c_save(char*); void c_save(char*);
void c_insertline(char *); void c_insertline(char *);
void c_indent(char *);
void c_unindent(char *);

1
main.c
View File

@ -18,3 +18,4 @@ char *com = fgets(buf, sizeof(buf), stdin);