--- /dev/null
+#ifndef __LABWC_STRING_HELPERs_H
+#define __LABWC_STRING_HELPERS_H
+
+/**
+ * string_strip - strip white space left and right
+ * Note: this function does a left skip, so the returning pointer cannot be
+ * used to free any allocated memory
+ */
+char *string_strip(char *s);
+
+#endif /* __LABWC_STRING_HELPERs_H */
* session_environment_init - set enrivonment variables
* Note: Same as `. ~/.config/labwc/environment` (or equivalent XDG config dir)
*/
-session_environment_init(void);
+void session_environment_init(void);
/**
* session_autostart_init - run autostart file as shell script
* Note: Same as `sh ~/.config/labwc/autostart` (or equivalent XDG config dir)
*/
-session_autostart_init(void);
+void session_autostart_init(void);
#endif /* __LABWC_SESSION_H */
'grab-file.c',
'log.c',
'spawn.c',
+ 'string-helpers.c',
)
--- /dev/null
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+static void
+rtrim(char **s)
+{
+ size_t len = strlen(*s);
+ if (!len) {
+ return;
+ }
+ char *end = *s + len - 1;
+ while (end >= *s && isspace(*end)) {
+ end--;
+ }
+ *(end + 1) = '\0';
+}
+
+char *
+string_strip(char *s)
+{
+ rtrim(&s);
+ while (isspace(*s)) {
+ s++;
+ }
+ return s;
+}
#include "common/dir.h"
#include "common/log.h"
#include "common/spawn.h"
+#include "common/string-helpers.h"
static bool
isfile(const char *path)
return !s || !*s;
}
-static void
-rtrim(char **s)
-{
- size_t len = strlen(*s);
- if (!len) {
- return;
- }
- char *end = *s + len - 1;
- while (end >= *s && isspace(*end)) {
- end--;
- }
- *(end + 1) = '\0';
-}
-
-static char *
-strstrip(char *s)
-{
- rtrim(&s);
- while (isspace(*s)) {
- s++;
- }
- return s;
-}
-
static void
process_line(char *line)
{
return;
}
*p = '\0';
- key = strstrip(line);
- value = strstrip(++p);
+ key = string_strip(line);
+ value = string_strip(++p);
if (string_empty(key) || string_empty(value)) {
return;
}
#include "common/dir.h"
#include "common/log.h"
+#include "common/string-helpers.h"
#include "theme/theme.h"
static int
}
/* clang-format on */
-static void
-rtrim(char **s)
-{
- size_t len = strlen(*s);
- if (!len) {
- return;
- }
- char *end = *s + len - 1;
- while (end >= *s && isspace(*end)) {
- end--;
- }
- *(end + 1) = '\0';
-}
-
-static char *
-strstrip(char *s)
-{
- rtrim(&s);
- while (isspace(*s)) {
- s++;
- }
- return s;
-}
-
static void
parse_config_line(char *line, char **key, char **value)
{
return;
}
*p = '\0';
- *key = strstrip(line);
- *value = strstrip(++p);
+ *key = string_strip(line);
+ *value = string_strip(++p);
}
static void