tweak parse_num() to return a bool, and fix backwards test of its value
so that numeric values will be preserved when switching to the "Go To Line" prompt again git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1881 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
4d44d2de0e
commit
c53ab2a854
|
@ -32,7 +32,9 @@ CVS code -
|
||||||
- Convert nano to use the new parse_num() function to read in
|
- Convert nano to use the new parse_num() function to read in
|
||||||
numeric values at the command line and in the rcfile, and
|
numeric values at the command line and in the rcfile, and
|
||||||
duplicate the messages used in the rcfile in the command line
|
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
|
wrap_at, and fill to ssize_t in order to work with
|
||||||
parse_num() properly and also to increase their capacity
|
parse_num() properly and also to increase their capacity
|
||||||
while keeping the ability to hold negative numbers in case of
|
while keeping the ability to hold negative numbers in case of
|
||||||
|
|
|
@ -3154,7 +3154,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'T':
|
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);
|
fprintf(stderr, _("Requested tab size %s invalid\n"), optarg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -3202,7 +3202,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
#ifndef DISABLE_WRAPJUSTIFY
|
#ifndef DISABLE_WRAPJUSTIFY
|
||||||
case 'r':
|
case 'r':
|
||||||
if (parse_num(optarg, &wrap_at) == -1) {
|
if (!parse_num(optarg, &wrap_at)) {
|
||||||
fprintf(stderr, _("Requested fill size %s invalid\n"), optarg);
|
fprintf(stderr, _("Requested fill size %s invalid\n"), optarg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,7 +402,7 @@ char *replace_line(const char *needle);
|
||||||
int do_replace_loop(const char *needle, const filestruct *real_current,
|
int do_replace_loop(const char *needle, const filestruct *real_current,
|
||||||
size_t *real_current_x, int wholewords);
|
size_t *real_current_x, int wholewords);
|
||||||
void do_replace(void);
|
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);
|
void do_gotoline_void(void);
|
||||||
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER)
|
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER)
|
||||||
void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww);
|
void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww);
|
||||||
|
@ -437,7 +437,7 @@ int is_blank_char(int c);
|
||||||
#endif
|
#endif
|
||||||
int is_cntrl_char(int c);
|
int is_cntrl_char(int c);
|
||||||
int num_of_digits(int n);
|
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 align(char **strp);
|
||||||
void null_at(char **data, size_t index);
|
void null_at(char **data, size_t index);
|
||||||
void unsunder(char *str, size_t true_len);
|
void unsunder(char *str, size_t true_len);
|
||||||
|
|
|
@ -561,7 +561,7 @@ void parse_rcfile(FILE *rcstream)
|
||||||
#endif
|
#endif
|
||||||
#ifndef DISABLE_WRAPJUSTIFY
|
#ifndef DISABLE_WRAPJUSTIFY
|
||||||
if (strcasecmp(rcopts[i].name, "fill") == 0) {
|
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);
|
rcfile_error(N_("Requested fill size %s invalid\n"), option);
|
||||||
wrap_at = -CHARS_FROM_EOL;
|
wrap_at = -CHARS_FROM_EOL;
|
||||||
}
|
}
|
||||||
|
@ -609,7 +609,7 @@ void parse_rcfile(FILE *rcstream)
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (strcasecmp(rcopts[i].name, "tabsize") == 0) {
|
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);
|
rcfile_error(N_("Requested tab size %s invalid\n"), option);
|
||||||
tabsize = -1;
|
tabsize = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,7 +240,7 @@ int search_init(int replacing)
|
||||||
#endif
|
#endif
|
||||||
/* If answer parses as an integer, put it up on the
|
/* If answer parses as an integer, put it up on the
|
||||||
* statusbar. */
|
* statusbar. */
|
||||||
do_gotoline(parse_num(answer, NULL), FALSE);
|
do_gotoline(parse_num(answer, NULL) ? -1 : 0, FALSE);
|
||||||
/* Fall through. */
|
/* Fall through. */
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -835,7 +835,7 @@ void do_replace(void)
|
||||||
replace_abort();
|
replace_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_gotoline(int line, int save_pos)
|
void do_gotoline(int line, bool save_pos)
|
||||||
{
|
{
|
||||||
if (line <= 0) { /* Ask for it. */
|
if (line <= 0) { /* Ask for it. */
|
||||||
char *ans = mallocstrcpy(NULL, answer);
|
char *ans = mallocstrcpy(NULL, answer);
|
||||||
|
@ -856,7 +856,7 @@ void do_gotoline(int line, int save_pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bounds check. */
|
/* Bounds check. */
|
||||||
if (parse_num(answer, &line) == -1 || line < 0) {
|
if (!parse_num(answer, &line) || line < 0) {
|
||||||
statusbar(_("Come on, be reasonable"));
|
statusbar(_("Come on, be reasonable"));
|
||||||
display_main_list();
|
display_main_list();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -85,8 +85,9 @@ int num_of_digits(int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read an int from str, and store it in *val (if val is not NULL). On
|
/* 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. */
|
* error, we return FALSE and don't change *val. Otherwise, we return
|
||||||
int parse_num(const char *str, ssize_t *val)
|
* TRUE. */
|
||||||
|
bool parse_num(const char *str, ssize_t *val)
|
||||||
{
|
{
|
||||||
char *first_error;
|
char *first_error;
|
||||||
ssize_t j;
|
ssize_t j;
|
||||||
|
@ -94,10 +95,10 @@ int parse_num(const char *str, ssize_t *val)
|
||||||
assert(str != NULL);
|
assert(str != NULL);
|
||||||
j = (ssize_t)strtol(str, &first_error, 10);
|
j = (ssize_t)strtol(str, &first_error, 10);
|
||||||
if (errno == ERANGE || *str == '\0' || *first_error != '\0')
|
if (errno == ERANGE || *str == '\0' || *first_error != '\0')
|
||||||
return -1;
|
return FALSE;
|
||||||
if (val != NULL)
|
if (val != NULL)
|
||||||
*val = j;
|
*val = j;
|
||||||
return 0;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fix the memory allocation for a string. */
|
/* Fix the memory allocation for a string. */
|
||||||
|
|
Loading…
Reference in New Issue