From owner-svn-src-head@freebsd.org Mon Jan 2 20:23:48 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 65D4BC9C9BB; Mon, 2 Jan 2017 20:23:48 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 333A8155B; Mon, 2 Jan 2017 20:23:48 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v02KNleY081458; Mon, 2 Jan 2017 20:23:47 GMT (envelope-from pstef@FreeBSD.org) Received: (from pstef@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v02KNlEO081454; Mon, 2 Jan 2017 20:23:47 GMT (envelope-from pstef@FreeBSD.org) Message-Id: <201701022023.v02KNlEO081454@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pstef set sender to pstef@FreeBSD.org using -f From: Piotr Pawel Stefaniak Date: Mon, 2 Jan 2017 20:23:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r311138 - head/usr.bin/indent X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jan 2017 20:23:48 -0000 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);