forked from DmitriyKustov/texteditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshownonempty.c
More file actions
56 lines (49 loc) · 1.57 KB
/
shownonempty.c
File metadata and controls
56 lines (49 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* shownonempty.c -- реализует команду вывода содержимого непустых строк
*
* Copyright (c) 2018, Egor Ignatov <ignatov@petrsu.ru>
*
* This code is licensed under a MIT-style license.
*/
#include "common.h"
#include "text/text.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void shownonempty_line(int index, char *contents, int cursor,
void *data);
void shownonempty(text txt) { process_forward(txt, shownonempty_line, NULL); }
static void shownonempty_line(int index, char *contents, int cursor,
void *data) {
assert(contents != NULL);
UNUSED(cursor);
UNUSED(data);
UNUSED(index);
/* Вывод непустых строк*/
if (contents[0] != '\0') {
int i = 1;
while (contents[i] != '\0') {
/* Проверям является ли текущий символ пробельным */
if (isspace(contents[i])) {
i++;
continue;
}
/* Если нашли непробельный символ, то выводим строку*/
if (cursor >= 0) {
/* Есил в строке есть курсор выводим вместе с ним */
for (int j = 0; j < (int)strlen(contents) + 1; j++) {
if (j == cursor) {
printf("|");
}
printf("%c", contents[j]);
}
} else
printf("%s", contents);
break;
}
if (contents[strlen(contents) - 1] != '\n')
printf("\n");
}
}