[template-glib] token: remove use of sscanf()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] token: remove use of sscanf()
- Date: Wed, 11 May 2022 22:04:26 +0000 (UTC)
commit 0fd40ba9ef390a913dc28ab32060d7fd331b8946
Author: Christian Hergert <christian hergert me>
Date: Wed May 11 14:59:05 2022 -0700
token: remove use of sscanf()
This fixes things to work where we don't have non-standard sscanf features
such as on macOS.
src/tmpl-token.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/src/tmpl-token.c b/src/tmpl-token.c
index 16ab375..9eae916 100644
--- a/src/tmpl-token.c
+++ b/src/tmpl-token.c
@@ -102,19 +102,32 @@ tmpl_token_type (TmplToken *self)
gchar *
tmpl_token_include_get_path (TmplToken *self)
{
+ const char *str;
char *path = NULL;
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->type == TMPL_TOKEN_INCLUDE, NULL);
- if (1 == sscanf (self->text, "include \"%m[^\"]", &path))
+ str = self->text;
+
+ if (!g_str_has_prefix (str, "include "))
+ return NULL;
+
+ str += strlen ("include ");
+ while (*str == ' ') str++;
+ if (str[0] != '"')
+ return NULL;
+ path = g_strdup (str+1);
+
+ if (path[0] == 0 || path[strlen(path)-1] != '"')
{
- gchar *tmp = g_strdup (path);
- free (path);
- return tmp;
+ g_free (path);
+ return NULL;
}
- return NULL;
+ path[strlen(path)-1] = 0;
+
+ return path;
}
TmplToken *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]