/* get the workspace */
Con *output, *workspace = NULL;
- char *endptr = NULL;
- long parsed_num = strtol(which, &endptr, 10);
- if (parsed_num == LONG_MIN ||
- parsed_num == LONG_MAX ||
- parsed_num < 0 ||
- endptr == which) {
+ long parsed_num = ws_name_to_number(which);
+
+ if (parsed_num == -1) {
LOG("Could not parse initial part of \"%s\" as a number.\n", which);
// TODO: better error message
yerror("Could not parse number");
void cmd_workspace_number(I3_CMD, char *which) {
Con *output, *workspace = NULL;
- char *endptr = NULL;
- long parsed_num = strtol(which, &endptr, 10);
- if (parsed_num == LONG_MIN ||
- parsed_num == LONG_MAX ||
- parsed_num < 0 ||
- endptr == which) {
+ long parsed_num = ws_name_to_number(which);
+
+ if (parsed_num == -1) {
LOG("Could not parse initial part of \"%s\" as a number.\n", which);
// TODO: better error message
yerror("Could not parse number");
-
return;
}
/* Change the name and try to parse it as a number. */
FREE(workspace->name);
workspace->name = sstrdup(new_name);
- char *endptr = NULL;
- long parsed_num = strtol(new_name, &endptr, 10);
- if (parsed_num == LONG_MIN ||
- parsed_num == LONG_MAX ||
- parsed_num < 0 ||
- endptr == new_name)
- workspace->num = -1;
- else
- workspace->num = parsed_num;
+
+ workspace->num = ws_name_to_number(new_name);
LOG("num = %d\n", workspace->num);
/* By re-attaching, the sort order will be correct afterwards. */
if (!exists) {
/* Set ->num to the number of the workspace, if the name actually
* is a number or starts with a number */
- char *endptr = NULL;
- long parsed_num = strtol(ws->name, &endptr, 10);
- if (parsed_num == LONG_MIN ||
- parsed_num == LONG_MAX ||
- parsed_num < 0 ||
- endptr == ws->name)
- ws->num = -1;
- else
- ws->num = parsed_num;
+ ws->num = ws_name_to_number(ws->name);
LOG("Used number %d for workspace with name %s\n", ws->num, ws->name);
break;