svn commit: r311138 - head/usr.bin/indent
Piotr Pawel Stefaniak
pstef at FreeBSD.org
Mon Jan 2 20:23:48 UTC 2017
Author: pstef
Date: Mon Jan 2 20:23:46 2017
New Revision: 311138
URL: https://svnweb.freebsd.org/changeset/base/311138
Log:
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
Modified:
head/usr.bin/indent/args.c
head/usr.bin/indent/indent.1
head/usr.bin/indent/indent.c
head/usr.bin/indent/indent.h
Modified: head/usr.bin/indent/args.c
==============================================================================
--- head/usr.bin/indent/args.c Mon Jan 2 20:14:06 2017 (r311137)
+++ head/usr.bin/indent/args.c Mon Jan 2 20:23:46 2017 (r311138)
@@ -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);
Modified: head/usr.bin/indent/indent.1
==============================================================================
--- head/usr.bin/indent/indent.1 Mon Jan 2 20:14:06 2017 (r311137)
+++ head/usr.bin/indent/indent.1 Mon Jan 2 20:23:46 2017 (r311138)
@@ -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
Modified: head/usr.bin/indent/indent.c
==============================================================================
--- head/usr.bin/indent/indent.c Mon Jan 2 20:14:06 2017 (r311137)
+++ head/usr.bin/indent/indent.c Mon Jan 2 20:23:46 2017 (r311138)
@@ -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) {
Modified: head/usr.bin/indent/indent.h
==============================================================================
--- head/usr.bin/indent/indent.h Mon Jan 2 20:14:06 2017 (r311137)
+++ head/usr.bin/indent/indent.h Mon Jan 2 20:23:46 2017 (r311138)
@@ -45,5 +45,5 @@ void parsefont(struct fstate *, const ch
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);
More information about the svn-src-all
mailing list