move duplicate code from the +LINE,COLUMN feature into a separate
function, parse_line_column() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2517 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
50995bd024
commit
b68c01b753
|
@ -15,8 +15,8 @@ CVS code -
|
||||||
various comments. (DLR)
|
various comments. (DLR)
|
||||||
- Add the ability to open a file on a specified column as well
|
- Add the ability to open a file on a specified column as well
|
||||||
as a specified line, by allowing an argument of the form
|
as a specified line, by allowing an argument of the form
|
||||||
+LINE,COLUMN. Changes to main(), nano.1, and nano.texi. (DLR,
|
+LINE,COLUMN. New function parse_line_column(); changes to
|
||||||
suggested by PFTank)
|
main(), nano.1, and nano.texi. (DLR, suggested by PFTank)
|
||||||
- cut.c:
|
- cut.c:
|
||||||
cut_line()
|
cut_line()
|
||||||
- Set placewewant properly after cutting a line, to avoid a
|
- Set placewewant properly after cutting a line, to avoid a
|
||||||
|
|
15
src/nano.c
15
src/nano.c
|
@ -4427,13 +4427,7 @@ int main(int argc, char **argv)
|
||||||
* non-option argument, and it is followed by at least one other
|
* non-option argument, and it is followed by at least one other
|
||||||
* argument, the filename it applies to. */
|
* argument, the filename it applies to. */
|
||||||
if (0 < optind && optind < argc - 1 && argv[optind][0] == '+') {
|
if (0 < optind && optind < argc - 1 && argv[optind][0] == '+') {
|
||||||
char *comma = strchr(&argv[optind][1], ',');
|
parse_line_column(&argv[optind][1], &startline, &startcol);
|
||||||
|
|
||||||
if (comma != NULL)
|
|
||||||
parse_num(&argv[optind][comma - argv[optind] + 1],
|
|
||||||
&startcol);
|
|
||||||
|
|
||||||
startline = atoi(&argv[optind][1]);
|
|
||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4453,12 +4447,7 @@ int main(int argc, char **argv)
|
||||||
* applies to. */
|
* applies to. */
|
||||||
if (i < argc - 1 && argv[i][0] == '+' && iline == 1 &&
|
if (i < argc - 1 && argv[i][0] == '+' && iline == 1 &&
|
||||||
icol == 1) {
|
icol == 1) {
|
||||||
char *comma = strchr(&argv[i][1], ',');
|
parse_line_column(&argv[i][1], &iline, &icol);
|
||||||
|
|
||||||
if (comma != NULL)
|
|
||||||
parse_num(&argv[i][comma - argv[i] + 1], &icol);
|
|
||||||
|
|
||||||
iline = atoi(&argv[i][1]);
|
|
||||||
} else {
|
} else {
|
||||||
load_buffer(argv[i]);
|
load_buffer(argv[i]);
|
||||||
|
|
||||||
|
|
|
@ -547,6 +547,7 @@ int regexp_bol_or_eol(const regex_t *preg, const char *string);
|
||||||
int digits(size_t n);
|
int digits(size_t n);
|
||||||
void get_homedir(void);
|
void get_homedir(void);
|
||||||
bool parse_num(const char *str, ssize_t *val);
|
bool parse_num(const char *str, ssize_t *val);
|
||||||
|
void parse_line_column(const char *str, int *line, ssize_t *column);
|
||||||
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);
|
||||||
|
|
15
src/utils.c
15
src/utils.c
|
@ -105,6 +105,21 @@ bool parse_num(const char *str, ssize_t *val)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parse_line_column(const char *str, int *line, ssize_t *column)
|
||||||
|
{
|
||||||
|
char *comma;
|
||||||
|
|
||||||
|
assert(str != NULL);
|
||||||
|
|
||||||
|
comma = strchr(str, ',');
|
||||||
|
|
||||||
|
if (comma != NULL && column != NULL)
|
||||||
|
parse_num(&str[comma - str + 1], column);
|
||||||
|
|
||||||
|
if (line != NULL)
|
||||||
|
*line = atoi(str);
|
||||||
|
}
|
||||||
|
|
||||||
/* Fix the memory allocation for a string. */
|
/* Fix the memory allocation for a string. */
|
||||||
void align(char **strp)
|
void align(char **strp)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue