Module Name: src
Committed By: rillig
Date: Sun Oct 3 18:53:37 UTC 2021
Modified Files:
src/usr.bin/indent: args.c
Log Message:
indent: reduce duplicate code in load_profiles
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/indent/args.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.41 src/usr.bin/indent/args.c:1.42
--- src/usr.bin/indent/args.c:1.41 Sun Oct 3 18:44:51 2021
+++ src/usr.bin/indent/args.c Sun Oct 3 18:53:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: args.c,v 1.41 2021/10/03 18:44:51 rillig Exp $ */
+/* $NetBSD: args.c,v 1.42 2021/10/03 18:53:37 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c 8.1 (
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.41 2021/10/03 18:44:51 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.42 2021/10/03 18:53:37 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
#endif
@@ -140,12 +140,17 @@ static const struct pro {
};
static void
-load_profile(FILE *f)
+load_profile(const char *fname)
{
+ FILE *f;
int comment_index, i;
char *p;
char buf[BUFSIZ];
+ if ((f = fopen(fname, "r")) == NULL)
+ return;
+ option_source = fname;
+
for (;;) {
p = buf;
comment_index = 0;
@@ -168,30 +173,25 @@ load_profile(FILE *f)
if (opt.verbose)
printf("profile: %s\n", buf);
set_option(buf);
- } else if (i == EOF)
+ } else if (i == EOF) {
+ (void)fclose(f);
return;
+ }
}
}
void
load_profiles(const char *profile_name)
{
- FILE *f;
char fname[PATH_MAX];
- static char prof[] = ".indent.pro";
- if (profile_name == NULL)
- snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), prof);
- else
- snprintf(fname, sizeof(fname), "%s", profile_name);
- if ((f = fopen(option_source = fname, "r")) != NULL) {
- load_profile(f);
- (void)fclose(f);
- }
- if ((f = fopen(option_source = prof, "r")) != NULL) {
- load_profile(f);
- (void)fclose(f);
+ if (profile_name != NULL)
+ load_profile(profile_name);
+ else {
+ snprintf(fname, sizeof(fname), "%s/.indent.pro", getenv("HOME"));
+ load_profile(fname);
}
+ load_profile(".indent.pro");
option_source = "Command line";
}