more LINE,COLUMN-related work: fix problems parsing it, and allow it at

the (soon-to-be-renamed) "Go to Line" prompt


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2522 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2005-05-17 18:06:26 +00:00
parent 60a9bddcf6
commit 9245f97960
6 changed files with 41 additions and 38 deletions

View File

@ -16,7 +16,9 @@ CVS code -
- Add the ability to open a file on a specified column as well
as a specified line, by allowing an argument of the form
+LINE,COLUMN. New function parse_line_column(); changes to
main(), nano.1, and nano.texi. (DLR, suggested by PFTank)
main(), do_gotoline() (renamed do_gotolinecolumn()),
do_gotoline_void() (renamed do_gotolinecolumn_void()), nano.1,
and nano.texi. (DLR, suggested by PFTank)
- cut.c:
cut_line()
- Set placewewant properly after cutting a line, to avoid a

View File

@ -480,7 +480,8 @@ void shortcut_init(bool unjustify)
sc_init_one(&main_list, NANO_GOTOLINE_KEY, go_to_line_msg,
IFHELP(nano_gotoline_msg, NANO_GOTOLINE_ALTKEY),
NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW, do_gotoline_void);
NANO_GOTOLINE_FKEY, NANO_NO_KEY, VIEW,
do_gotolinecolumn_void);
sc_init_one(&main_list, NANO_REPLACE_KEY, replace_msg,
IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY),

View File

@ -4446,18 +4446,15 @@ int main(int argc, char **argv)
* followed by at least one other argument, the filename it
* applies to. */
if (i < argc - 1 && argv[i][0] == '+' && iline == 1 &&
icol == 1) {
icol == 1)
parse_line_column(&argv[i][1], &iline, &icol);
} else {
else {
load_buffer(argv[i]);
if (iline > 1) {
do_gotoline(iline, FALSE);
if (iline > 1 || icol > 1) {
do_gotolinecolumn(iline, icol - 1, FALSE, FALSE,
FALSE);
iline = 1;
}
if (icol > 1) {
current_x = actual_x(current->data, icol - 1);
icol = 1;
}
}
@ -4498,11 +4495,8 @@ int main(int argc, char **argv)
titlebar(NULL);
display_main_list();
if (startline > 1)
do_gotoline(startline, FALSE);
if (startcol > 1)
current_x = actual_x(current->data, startcol - 1);
if (startline > 1 || startcol > 1)
do_gotolinecolumn(startline, startcol, FALSE, FALSE, FALSE);
#ifndef NANO_SMALL
/* Return here after a SIGWINCH. */

View File

@ -516,8 +516,9 @@ ssize_t do_replace_loop(const char *needle, const filestruct
*real_current, size_t *real_current_x, bool wholewords, bool
*canceled);
void do_replace(void);
void do_gotoline(int line, bool save_pos);
void do_gotoline_void(void);
void do_gotolinecolumn(int line, ssize_t column, bool use_answer, bool
interactive, bool save_pos);
void do_gotolinecolumn_void(void);
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww);
#endif

View File

@ -255,9 +255,9 @@ int search_init(bool replacing, bool use_answer)
#ifndef NANO_SMALL
search_history.current = search_history.next;
#endif
do_gotoline(-1, FALSE); /* Put answer up on the
* statusbar and fall
* through. */
do_gotolinecolumn(1, 1, TRUE, TRUE, FALSE);
/* Put answer up on the statusbar and
* fall through. */
default:
return -1;
}
@ -969,11 +969,12 @@ void do_replace(void)
replace_abort();
}
void do_gotoline(int line, bool save_pos)
void do_gotolinecolumn(int line, ssize_t column, bool use_answer, bool
interactive, bool save_pos)
{
if (line <= 0) { /* Ask for it. */
if (interactive) { /* Ask for it. */
char *ans = mallocstrcpy(NULL, answer);
int i = statusq(FALSE, gotoline_list, line < 0 ? ans : "",
int i = statusq(FALSE, gotoline_list, use_answer ? ans : "",
#ifndef NANO_SMALL
NULL,
#endif
@ -998,12 +999,19 @@ void do_gotoline(int line, bool save_pos)
/* Do a bounds check. Display a warning on an out-of-bounds
* line number only if we hit Enter at the statusbar prompt. */
if (!parse_num(answer, &line) || line < 1) {
if (!parse_line_column(answer, &line, &column) || line < 1 ||
column < 1) {
if (i == 0)
statusbar(_("Come on, be reasonable"));
display_main_list();
return;
}
} else {
if (line < 1)
line = 1;
if (column < 1)
column = 1;
}
if (current->lineno > line) {
@ -1016,33 +1024,28 @@ void do_gotoline(int line, bool save_pos)
;
}
current_x = 0;
current_x = actual_x(current->data, column - 1);
/* If save_pos is TRUE, don't change the cursor position when
* updating the edit window. */
edit_update(save_pos ? NONE : CENTER);
placewewant = 0;
placewewant = xplustabs();
display_main_list();
}
void do_gotoline_void(void)
void do_gotolinecolumn_void(void)
{
do_gotoline(0, FALSE);
do_gotolinecolumn(1, 1, FALSE, TRUE, FALSE);
}
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww)
{
/* Since do_gotoline() resets the x-coordinate but not the
/* Since do_gotolinecolumn() resets the x-coordinate but not the
* y-coordinate, set the coordinates up this way. */
current_y = pos_y;
do_gotoline(line, TRUE);
/* Make sure that the x-coordinate is sane here. */
current_x = strlen(current->data);
if (pos_x < current_x)
current_x = pos_x;
do_gotolinecolumn(line, pos_x, FALSE, FALSE, TRUE);
/* Set the rest of the coordinates up. */
placewewant = pos_pww;

View File

@ -124,9 +124,10 @@ bool parse_line_column(const char *str, int *line, ssize_t *column)
if (line != NULL) {
if (comma != NULL) {
char *str_line = mallocstrncpy(NULL, str, comma - str);
char *str_line = mallocstrncpy(NULL, str, comma - str + 1);
str_line[comma - str] = '\0';
if (!parse_num(str_line, line))
if (str_line[0] != '\0' && !parse_num(str_line, line))
retval = FALSE;
free(str_line);
@ -358,7 +359,8 @@ char *mallocstrncpy(char *dest, const char *src, size_t n)
* "dest = mallocstrcpy(dest, src);". */
char *mallocstrcpy(char *dest, const char *src)
{
return mallocstrncpy(dest, src, src == NULL ? 1 : strlen(src) + 1);
return mallocstrncpy(dest, src, (src == NULL) ? 1 :
strlen(src) + 1);
}
/* Free the malloc()ed string at dest and return the malloc()ed string