41 lines
607 B
C
41 lines
607 B
C
|
|
#include "buffer.h"
|
||
|
|
#include "line-ed.h"
|
||
|
|
|
||
|
|
const char *line_start(struct line_ed *ed, unsigned int y)
|
||
|
|
{
|
||
|
|
const char *line = ed->l_buf;
|
||
|
|
|
||
|
|
for (unsigned int i = 0; i < y; i++) {
|
||
|
|
line += strcspn(line, "\n");
|
||
|
|
|
||
|
|
if (*line == '\n') {
|
||
|
|
line++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return line;
|
||
|
|
}
|
||
|
|
|
||
|
|
unsigned int line_length(struct line_ed *ed, unsigned int y)
|
||
|
|
{
|
||
|
|
const char *line = ed->l_buf;
|
||
|
|
|
||
|
|
for (unsigned int i = 0; i < y; i++) {
|
||
|
|
line += strcspn(line, "\n");
|
||
|
|
if (*line == '\n') {
|
||
|
|
line++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (*line == '\0') {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
unsigned int len = strcspn(line, "\n");
|
||
|
|
if (line[len] == '\n') {
|
||
|
|
len++;
|
||
|
|
}
|
||
|
|
|
||
|
|
return len;
|
||
|
|
}
|