2 * Copyright (c) 1985 Sun Microsystems, Inc.
3 * Copyright (c) 1980, 1993
4 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34static char sccsid[] =
"@(#)args.c 8.1 (Berkeley) 6/6/93";
41 * Argument scanning and profile reading code. Default parameters are set
54 #define INDENT_VERSION "2.1.2"
57 #define PRO_SPECIAL 1 /* special case */
58 #define PRO_BOOL 2 /* boolean */
59 #define PRO_INT 3 /* integer */
61/* profile specials for booleans */
62 #define ON 1 /* turn it on */
63 #define OFF 0 /* turn it off */
65/* profile specials for specials */
66 #define IGN 1 /* ignore it */
67 #define CLI 2 /* case label indent (float) */
68 #define STDIN 3 /* use stdin */
69 #define KEY 4 /* type (keyword) */
73 #define KEY_FILE 5 /* only used for args */
74 #define VERSION 6 /* only used for args */
81 * N.B.: because of the way the table here is scanned, options whose names are
82 * substrings of other options must occur later; that is, with -lp vs -l, -lp
83 * must be first. Also, while (most) booleans occur more than once, the last
84 * default value is the one actually assigned.
87 const char *
p_name;
/* name, e.g. -bl, -cli */
88 int p_type;
/* type (int, bool, special) */
91 int *
p_obj;
/* the associated variable */
172 * set_profile reads $HOME/.indent.pro and ./.indent.pro and handles arguments
173 * given in these files.
180 static char prof[] =
".indent.pro";
182 if (profile_name == NULL)
183 snprintf(fname,
sizeof(fname),
"%s/%s", getenv(
"HOME"), prof);
185 snprintf(fname,
sizeof(fname),
"%s", profile_name + 2);
207 while ((
i = getc(f)) != EOF) {
208 if (
i ==
'*' && !
comment && p >
buf && p[-1] ==
'/') {
211 }
else if (
i ==
'/' &&
comment && p >
buf && p[-1] ==
'*') {
214 }
else if (isspace((
unsigned char)
i)) {
251 * Because ps.case_indent is a float, we can't initialize it from the
264 const char *param_start;
266 arg++;
/* ignore leading "-" */
281 if (*param_start == 0)
294 if (*param_start == 0)
300 if (*param_start == 0)
310 errx(1,
"set_option: internal error: p_special %d", p->
p_special);
322 if (!isdigit((
unsigned char)*param_start)) {
326 *p->
p_obj = atoi(param_start);
330 errx(1,
"set_option: internal error: p_type %d", p->
p_type);
340 if ((file = fopen(
str,
"r")) == NULL) {
341 fprintf(stderr,
"indent: cannot open file %s\n",
str);
344 while ((fgets(line, BUFSIZ, file)) != NULL) {
345 /* Remove trailing whitespace */
346 line[strcspn(line,
" \t\n\r")] =
'0円';
static const char * eqin(const char *s1, const char *s2)
void add_typedefs_from_file(const char *str)
void set_profile(const char *profile_name)
static void scan_profile(FILE *f)
void set_option(char *arg)
const char * option_source
#define fprintf(file, fmt, msg)
void errx(int eval, const char *fmt,...)
void add_typename(const char *)
int blanklines_after_declarations
int block_comment_max_col
int blanklines_after_procs
int blanklines_before_blockcomments
int extra_expression_indent
int format_block_comments
int comment_delimiter_on_blankline
int blanklines_around_conditional_compilation
int swallow_optional_blanklines
int lineup_to_parens_always
int blanklines_after_declarations_at_proctop