#include <pwd.h>
#include <yajl/yajl_version.h>
#include <libgen.h>
+#include <ctype.h>
#define SN_API_NOT_YET_FROZEN 1
#include <libsn/sn-launcher.h>
a.height + b.height};
}
+/*
+ * Returns true if the name consists of only digits.
+ *
+ */
+__attribute__ ((pure)) bool name_is_digits(const char *name) {
+ /* positive integers and zero are interpreted as numbers */
+ for (int i = 0; i < strlen(name); i++)
+ if (!isdigit(name[i]))
+ return false;
+
+ return true;
+}
+
+/*
+ * Parses the workspace name as a number. Returns -1 if the workspace should be
+ * interpreted as a "named workspace".
+ *
+ */
+long ws_name_to_number(const char *name) {
+ /* positive integers and zero are interpreted as numbers */
+ char *endptr = NULL;
+ long parsed_num = strtol(name, &endptr, 10);
+ if (parsed_num == LONG_MIN ||
+ parsed_num == LONG_MAX ||
+ parsed_num < 0 ||
+ endptr == name) {
+ parsed_num = -1;
+ }
+
+ return parsed_num;
+}
+
/*
* Updates *destination with new_value and returns true if it was changed or false
* if it was the same
char *store_restart_layout(void) {
setlocale(LC_NUMERIC, "C");
-#if YAJL_MAJOR >= 2
yajl_gen gen = yajl_gen_alloc(NULL);
-#else
- yajl_gen gen = yajl_gen_alloc(NULL, NULL);
-#endif
dump_node(gen, croot, true);
setlocale(LC_NUMERIC, "");
const unsigned char *payload;
-#if YAJL_MAJOR >= 2
size_t length;
-#else
- unsigned int length;
-#endif
y(get_buf, &payload, &length);
/* create a temporary file if one hasn't been specified, or just
return NULL;
}
if (n == 0) {
- printf("write == 0?\n");
+ DLOG("write == 0?\n");
free(filename);
close(fd);
return NULL;
}
written += n;
-#if YAJL_MAJOR >= 2
DLOG("written: %zd of %zd\n", written, length);
-#else
- DLOG("written: %d of %d\n", written, length);
-#endif
}
close(fd);
if (length > 0) {
- printf("layout: %.*s\n", (int)length, payload);
+ DLOG("layout: %.*s\n", (int)length, payload);
}
y(free);