summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/pango.c53
-rw-r--r--common/readline.c25
2 files changed, 16 insertions, 62 deletions
diff --git a/common/pango.c b/common/pango.c
index ea71ac4a..5afd72d8 100644
--- a/common/pango.c
+++ b/common/pango.c
@@ -7,66 +7,45 @@
7#include <stdlib.h> 7#include <stdlib.h>
8#include <string.h> 8#include <string.h>
9#include "log.h" 9#include "log.h"
10#include "stringop.h"
10 11
11int escape_markup_text(const char *src, char *dest, int dest_length) { 12size_t escape_markup_text(const char *src, char *dest) {
12 int length = 0; 13 size_t length = 0;
14 if (dest) {
15 dest[0] = '\0';
16 }
13 17
14 while (src[0]) { 18 while (src[0]) {
15 switch (src[0]) { 19 switch (src[0]) {
16 case '&': 20 case '&':
17 length += 5; 21 length += 5;
18 if (dest && dest_length - length >= 0) { 22 lenient_strcat(dest, "&amp;");
19 dest += sprintf(dest, "%s", "&amp;");
20 } else {
21 dest_length = -1;
22 }
23 break; 23 break;
24 case '<': 24 case '<':
25 length += 4; 25 length += 4;
26 if (dest && dest_length - length >= 0) { 26 lenient_strcat(dest, "&lt;");
27 dest += sprintf(dest, "%s", "&lt;");
28 } else {
29 dest_length = -1;
30 }
31 break; 27 break;
32 case '>': 28 case '>':
33 length += 4; 29 length += 4;
34 if (dest && dest_length - length >= 0) { 30 lenient_strcat(dest, "&gt;");
35 dest += sprintf(dest, "%s", "&gt;");
36 } else {
37 dest_length = -1;
38 }
39 break; 31 break;
40 case '\'': 32 case '\'':
41 length += 6; 33 length += 6;
42 if (dest && dest_length - length >= 0) { 34 lenient_strcat(dest, "&apos;");
43 dest += sprintf(dest, "%s", "&apos;");
44 } else {
45 dest_length = -1;
46 }
47 break; 35 break;
48 case '"': 36 case '"':
49 length += 6; 37 length += 6;
50 if (dest && dest_length - length >= 0) { 38 lenient_strcat(dest, "&quot;");
51 dest += sprintf(dest, "%s", "&quot;");
52 } else {
53 dest_length = -1;
54 }
55 break; 39 break;
56 default: 40 default:
57 length += 1; 41 if (dest) {
58 if (dest && dest_length - length >= 0) { 42 dest[length] = *src;
59 *(dest++) = *src; 43 dest[length + 1] = '\0';
60 } else {
61 dest_length = -1;
62 } 44 }
45 length += 1;
63 } 46 }
64 src++; 47 src++;
65 } 48 }
66 // if we could not fit the escaped string in dest, return -1
67 if (dest && dest_length == -1) {
68 return -1;
69 }
70 return length; 49 return length;
71} 50}
72 51
@@ -78,7 +57,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
78 char *buf; 57 char *buf;
79 GError *error = NULL; 58 GError *error = NULL;
80 if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { 59 if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) {
81 pango_layout_set_markup(layout, buf, -1); 60 pango_layout_set_text(layout, buf, -1);
82 free(buf); 61 free(buf);
83 } else { 62 } else {
84 wlr_log(WLR_ERROR, "pango_parse_markup '%s' -> error %s", text, 63 wlr_log(WLR_ERROR, "pango_parse_markup '%s' -> error %s", text,
diff --git a/common/readline.c b/common/readline.c
index a2c69018..58652429 100644
--- a/common/readline.c
+++ b/common/readline.c
@@ -70,28 +70,3 @@ char *peek_line(FILE *file, int line_offset, long *position) {
70 fseek(file, pos, SEEK_SET); 70 fseek(file, pos, SEEK_SET);
71 return line; 71 return line;
72} 72}
73
74char *read_line_buffer(FILE *file, char *string, size_t string_len) {
75 size_t length = 0;
76 if (!string) {
77 return NULL;
78 }
79 while (1) {
80 int c = getc(file);
81 if (c == EOF || c == '\n' || c == '\0') {
82 break;
83 }
84 if (c == '\r') {
85 continue;
86 }
87 string[length++] = c;
88 if (string_len <= length) {
89 return NULL;
90 }
91 }
92 if (length + 1 == string_len) {
93 return NULL;
94 }
95 string[length] = '\0';
96 return string;
97}