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-d3aeb78583b8
master
David Lawrence Ramsey 2004-08-04 18:24:53 +00:00
parent 4d44d2de0e
commit c53ab2a854
6 changed files with 17 additions and 14 deletions

View File

@ -32,7 +32,9 @@ CVS code -
- 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

View File

@ -3154,7 +3154,7 @@ int main(int argc, char *argv[])
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);
}
@ -3202,7 +3202,7 @@ int main(int argc, char *argv[])
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);
}

View File

@ -402,7 +402,7 @@ char *replace_line(const char *needle);
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);
@ -437,7 +437,7 @@ int is_blank_char(int c);
#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);

View File

@ -561,7 +561,7 @@ void parse_rcfile(FILE *rcstream)
#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;
}
@ -609,7 +609,7 @@ void parse_rcfile(FILE *rcstream)
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;
}

View File

@ -240,7 +240,7 @@ int search_init(int replacing)
#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;
@ -835,7 +835,7 @@ void do_replace(void)
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);
@ -856,7 +856,7 @@ void do_gotoline(int line, int save_pos)
}
/* 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;

View File

@ -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
* 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;
@ -94,10 +95,10 @@ int parse_num(const char *str, ssize_t *val)
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. */