indent(1): add option -P for loading user-provided files as profiles
Without this change, indent(1) would only look to load options from ~/.indent.pro if it's there and -npro wasn't used on the command line. This option lets the user set their own path to the file. Approved by: pfg (mentor) Differential Revision: https://reviews.freebsd.org/D9010
This commit is contained in:
parent
0cd582c898
commit
86adac04b2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311138
@ -177,13 +177,16 @@ struct pro {
|
||||
* given in these files.
|
||||
*/
|
||||
void
|
||||
set_profile(void)
|
||||
set_profile(const char *profile_name)
|
||||
{
|
||||
FILE *f;
|
||||
char fname[PATH_MAX];
|
||||
static char prof[] = ".indent.pro";
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), prof);
|
||||
if (profile_name == NULL)
|
||||
snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), prof);
|
||||
else
|
||||
snprintf(fname, sizeof(fname), "%s", profile_name + 2);
|
||||
if ((f = fopen(option_source = fname, "r")) != NULL) {
|
||||
scan_profile(f);
|
||||
(void) fclose(f);
|
||||
|
@ -30,7 +30,7 @@
|
||||
.\" @(#)indent.1 8.1 (Berkeley) 7/1/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd December 2, 2016
|
||||
.Dd January 2, 2017
|
||||
.Dt INDENT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -74,6 +74,7 @@
|
||||
.Op Fl \&ldi Ns Ar n
|
||||
.Op Fl \&lp | Fl nlp
|
||||
.Op Fl npro
|
||||
.Op Fl P Ns Ar file
|
||||
.Op Fl pcs | Fl npcs
|
||||
.Op Fl psl | Fl npsl
|
||||
.Op Fl sac | Fl nsac
|
||||
@ -383,6 +384,9 @@ Causes the profile files,
|
||||
and
|
||||
.Sq Pa ~/.indent.pro ,
|
||||
to be ignored.
|
||||
.It Fl P Ns Ar file
|
||||
Read profile from
|
||||
.Ar file .
|
||||
.It Fl pcs , npcs
|
||||
If true
|
||||
.Pq Fl pcs
|
||||
|
@ -98,6 +98,7 @@ main(int argc, char **argv)
|
||||
int type_code; /* the type of token, returned by lexi */
|
||||
|
||||
int last_else = 0; /* true iff last keyword was an else */
|
||||
const char *profile_name = NULL;
|
||||
|
||||
|
||||
/*-----------------------------------------------*\
|
||||
@ -194,9 +195,11 @@ main(int argc, char **argv)
|
||||
for (i = 1; i < argc; ++i)
|
||||
if (strcmp(argv[i], "-npro") == 0)
|
||||
break;
|
||||
else if (argv[i][0] == '-' && argv[i][1] == 'P' && argv[i][2] != '\0')
|
||||
profile_name = argv[i]; /* non-empty -P (set profile) */
|
||||
set_defaults();
|
||||
if (i >= argc)
|
||||
set_profile();
|
||||
set_profile(profile_name);
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
|
||||
|
@ -45,5 +45,5 @@ void parsefont(struct fstate *, const char *);
|
||||
void pr_comment(void);
|
||||
void set_defaults(void);
|
||||
void set_option(char *);
|
||||
void set_profile(void);
|
||||
void set_profile(const char *);
|
||||
void writefdef(struct fstate *f, int);
|
||||
|
Loading…
Reference in New Issue
Block a user