- Convert nano to use the new parse_num() function to read in
numeric values at the command line and in the rcfile, and
duplicate the messages used in the rcfile in the command line
- for consistency. (David Benbennick) DLR: Convert tabsize,
+ for consistency. (David Benbennick) DLR: Tweak parse_num() to
+ parse ssize_t values instead of ints and to return a bool
+ indicating whether parsing succeeded. Convert tabsize,
wrap_at, and fill to ssize_t in order to work with
parse_num() properly and also to increase their capacity
while keeping the ability to hold negative numbers in case of
break;
#endif
case 'T':
- if (parse_num(optarg, &tabsize) == -1 || tabsize <= 0) {
+ if (!parse_num(optarg, &tabsize) || tabsize <= 0) {
fprintf(stderr, _("Requested tab size %s invalid\n"), optarg);
exit(1);
}
break;
#ifndef DISABLE_WRAPJUSTIFY
case 'r':
- if (parse_num(optarg, &wrap_at) == -1) {
+ if (!parse_num(optarg, &wrap_at)) {
fprintf(stderr, _("Requested fill size %s invalid\n"), optarg);
exit(1);
}
int do_replace_loop(const char *needle, const filestruct *real_current,
size_t *real_current_x, int wholewords);
void do_replace(void);
-void do_gotoline(int line, int save_pos);
+void do_gotoline(int line, bool save_pos);
void do_gotoline_void(void);
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER)
void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww);
#endif
int is_cntrl_char(int c);
int num_of_digits(int n);
-int parse_num(const char *str, ssize_t *val);
+bool parse_num(const char *str, ssize_t *val);
void align(char **strp);
void null_at(char **data, size_t index);
void unsunder(char *str, size_t true_len);
#endif
#ifndef DISABLE_WRAPJUSTIFY
if (strcasecmp(rcopts[i].name, "fill") == 0) {
- if (parse_num(option, &wrap_at) == -1) {
+ if (!parse_num(option, &wrap_at)) {
rcfile_error(N_("Requested fill size %s invalid\n"), option);
wrap_at = -CHARS_FROM_EOL;
}
else
#endif
if (strcasecmp(rcopts[i].name, "tabsize") == 0) {
- if (parse_num(option, &tabsize) == -1 || tabsize <= 0)
+ if (!parse_num(option, &tabsize) || tabsize <= 0)
rcfile_error(N_("Requested tab size %s invalid\n"), option);
tabsize = -1;
}
#endif
/* If answer parses as an integer, put it up on the
* statusbar. */
- do_gotoline(parse_num(answer, NULL), FALSE);
+ do_gotoline(parse_num(answer, NULL) ? -1 : 0, FALSE);
/* Fall through. */
default:
return -1;
replace_abort();
}
-void do_gotoline(int line, int save_pos)
+void do_gotoline(int line, bool save_pos)
{
if (line <= 0) { /* Ask for it. */
char *ans = mallocstrcpy(NULL, answer);
}
/* Bounds check. */
- if (parse_num(answer, &line) == -1 || line < 0) {
+ if (!parse_num(answer, &line) || line < 0) {
statusbar(_("Come on, be reasonable"));
display_main_list();
return;
}
/* Read an int from str, and store it in *val (if val is not NULL). On
- * error, we return -1 and don't change *val. */
-int parse_num(const char *str, ssize_t *val)
+ * error, we return FALSE and don't change *val. Otherwise, we return
+ * TRUE. */
+bool parse_num(const char *str, ssize_t *val)
{
char *first_error;
ssize_t j;
assert(str != NULL);
j = (ssize_t)strtol(str, &first_error, 10);
if (errno == ERANGE || *str == '\0' || *first_error != '\0')
- return -1;
+ return FALSE;
if (val != NULL)
*val = j;
- return 0;
+ return TRUE;
}
/* Fix the memory allocation for a string. */