aboutsummaryrefslogtreecommitdiff
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 @@
#include <stdlib.h>
#include <string.h>
#include "log.h"
+#include "stringop.h"
-int escape_markup_text(const char *src, char *dest, int dest_length) {
- int length = 0;
+size_t escape_markup_text(const char *src, char *dest) {
+ size_t length = 0;
+ if (dest) {
+ dest[0] = '\0';
+ }
while (src[0]) {
switch (src[0]) {
case '&':
length += 5;
- if (dest && dest_length - length >= 0) {
- dest += sprintf(dest, "%s", "&amp;");
- } else {
- dest_length = -1;
- }
+ lenient_strcat(dest, "&amp;");
break;
case '<':
length += 4;
- if (dest && dest_length - length >= 0) {
- dest += sprintf(dest, "%s", "&lt;");
- } else {
- dest_length = -1;
- }
+ lenient_strcat(dest, "&lt;");
break;
case '>':
length += 4;
- if (dest && dest_length - length >= 0) {
- dest += sprintf(dest, "%s", "&gt;");
- } else {
- dest_length = -1;
- }
+ lenient_strcat(dest, "&gt;");
break;
case '\'':
length += 6;
- if (dest && dest_length - length >= 0) {
- dest += sprintf(dest, "%s", "&apos;");
- } else {
- dest_length = -1;
- }
+ lenient_strcat(dest, "&apos;");
break;
case '"':
length += 6;
- if (dest && dest_length - length >= 0) {
- dest += sprintf(dest, "%s", "&quot;");
- } else {
- dest_length = -1;
- }
+ lenient_strcat(dest, "&quot;");
break;
default:
- length += 1;
- if (dest && dest_length - length >= 0) {
- *(dest++) = *src;
- } else {
- dest_length = -1;
+ if (dest) {
+ dest[length] = *src;
+ dest[length + 1] = '\0';
}
+ length += 1;
}
src++;
}
- // if we could not fit the escaped string in dest, return -1
- if (dest && dest_length == -1) {
- return -1;
- }
return length;
}
@@ -78,7 +57,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
char *buf;
GError *error = NULL;
if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) {
- pango_layout_set_markup(layout, buf, -1);
+ pango_layout_set_text(layout, buf, -1);
free(buf);
} else {
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) {
fseek(file, pos, SEEK_SET);
return line;
}
-
-char *read_line_buffer(FILE *file, char *string, size_t string_len) {
- size_t length = 0;
- if (!string) {
- return NULL;
- }
- while (1) {
- int c = getc(file);
- if (c == EOF || c == '\n' || c == '\0') {
- break;
- }
- if (c == '\r') {
- continue;
- }
- string[length++] = c;
- if (string_len <= length) {
- return NULL;
- }
- }
- if (length + 1 == string_len) {
- return NULL;
- }
- string[length] = '\0';
- return string;
-}