+/*
+ * Parses the "align" module option (to validate input).
+ */
+static int parse_align(cfg_t *context, cfg_opt_t *option, const char *value, void *result) {
+ if (strcasecmp(value, "left") != 0 && strcasecmp(value,"right") != 0 && strcasecmp(value, "center") != 0)
+ die("Invalid alignment attribute found in section %s, line %d: \"%s\"\n"
+ "Valid attributes are: left, center, right\n", context->name, context->line, value);
+
+ const char **cresult = result;
+ *cresult = value;
+
+ return 0;
+}
+
+/*
+ * Parses the "min_width" module option whose value can either be a string or an integer.
+ */
+static int parse_min_width(cfg_t *context, cfg_opt_t *option, const char *value, void *result) {
+ char *end;
+ long num = strtol(value, &end, 10);
+
+ if (num < 0)
+ die("Invalid min_width attribute found in section %s, line %d: %d\n"
+ "Expected positive integer or string\n", context->name, context->line, num);
+ else if (num == LONG_MIN || num == LONG_MAX || (end && *end != '\0'))
+ num = 0;
+
+ if (strlen(value) == 0)
+ die("Empty min_width attribute found in section %s, line %d\n"
+ "Expected positive integer or non-empty string\n", context->name, context->line);
+
+ if (strcmp(value, "0") == 0)
+ die("Invalid min_width attribute found in section %s, line %d: \"%s\"\n"
+ "Expected positive integer or string\n", context->name, context->line, value);
+
+ struct min_width *parsed = scalloc(sizeof(struct min_width));
+ parsed->num = num;
+
+ /* num is preferred, but if it’s 0 (i.e. not valid), store and use
+ * the raw string value */
+ if (num == 0)
+ parsed->str = sstrdup(value);
+
+ struct min_width **cresult = result;
+ *cresult = parsed;
+
+ return 0;
+}