1*0a6a1f1dSLionel Sambuc /* $NetBSD: args.c,v 1.11 2014/09/04 04:06:07 mrg Exp $ */
297c7d358SVivek Prakash
397c7d358SVivek Prakash /*
497c7d358SVivek Prakash * Copyright (c) 1980, 1993
597c7d358SVivek Prakash * The Regents of the University of California. All rights reserved.
697c7d358SVivek Prakash *
797c7d358SVivek Prakash * Redistribution and use in source and binary forms, with or without
897c7d358SVivek Prakash * modification, are permitted provided that the following conditions
997c7d358SVivek Prakash * are met:
1097c7d358SVivek Prakash * 1. Redistributions of source code must retain the above copyright
1197c7d358SVivek Prakash * notice, this list of conditions and the following disclaimer.
1297c7d358SVivek Prakash * 2. Redistributions in binary form must reproduce the above copyright
1397c7d358SVivek Prakash * notice, this list of conditions and the following disclaimer in the
1497c7d358SVivek Prakash * documentation and/or other materials provided with the distribution.
1597c7d358SVivek Prakash * 3. Neither the name of the University nor the names of its contributors
1697c7d358SVivek Prakash * may be used to endorse or promote products derived from this software
1797c7d358SVivek Prakash * without specific prior written permission.
1897c7d358SVivek Prakash *
1997c7d358SVivek Prakash * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2097c7d358SVivek Prakash * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2197c7d358SVivek Prakash * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2297c7d358SVivek Prakash * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2397c7d358SVivek Prakash * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2497c7d358SVivek Prakash * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2597c7d358SVivek Prakash * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2697c7d358SVivek Prakash * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2797c7d358SVivek Prakash * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2897c7d358SVivek Prakash * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2997c7d358SVivek Prakash * SUCH DAMAGE.
3097c7d358SVivek Prakash */
3197c7d358SVivek Prakash
3297c7d358SVivek Prakash /*
3397c7d358SVivek Prakash * Copyright (c) 1976 Board of Trustees of the University of Illinois.
3497c7d358SVivek Prakash * Copyright (c) 1985 Sun Microsystems, Inc.
3597c7d358SVivek Prakash * All rights reserved.
3697c7d358SVivek Prakash *
3797c7d358SVivek Prakash * Redistribution and use in source and binary forms, with or without
3897c7d358SVivek Prakash * modification, are permitted provided that the following conditions
3997c7d358SVivek Prakash * are met:
4097c7d358SVivek Prakash * 1. Redistributions of source code must retain the above copyright
4197c7d358SVivek Prakash * notice, this list of conditions and the following disclaimer.
4297c7d358SVivek Prakash * 2. Redistributions in binary form must reproduce the above copyright
4397c7d358SVivek Prakash * notice, this list of conditions and the following disclaimer in the
4497c7d358SVivek Prakash * documentation and/or other materials provided with the distribution.
4597c7d358SVivek Prakash * 3. All advertising materials mentioning features or use of this software
4697c7d358SVivek Prakash * must display the following acknowledgement:
4797c7d358SVivek Prakash * This product includes software developed by the University of
4897c7d358SVivek Prakash * California, Berkeley and its contributors.
4997c7d358SVivek Prakash * 4. Neither the name of the University nor the names of its contributors
5097c7d358SVivek Prakash * may be used to endorse or promote products derived from this software
5197c7d358SVivek Prakash * without specific prior written permission.
5297c7d358SVivek Prakash *
5397c7d358SVivek Prakash * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5497c7d358SVivek Prakash * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5597c7d358SVivek Prakash * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5697c7d358SVivek Prakash * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5797c7d358SVivek Prakash * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5897c7d358SVivek Prakash * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5997c7d358SVivek Prakash * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6097c7d358SVivek Prakash * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6197c7d358SVivek Prakash * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6297c7d358SVivek Prakash * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6397c7d358SVivek Prakash * SUCH DAMAGE.
6497c7d358SVivek Prakash */
6597c7d358SVivek Prakash
6697c7d358SVivek Prakash #include <sys/cdefs.h>
6797c7d358SVivek Prakash #ifndef lint
6897c7d358SVivek Prakash #if 0
6997c7d358SVivek Prakash static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";
7097c7d358SVivek Prakash #else
71*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: args.c,v 1.11 2014/09/04 04:06:07 mrg Exp $");
7297c7d358SVivek Prakash #endif
7397c7d358SVivek Prakash #endif /* not lint */
7497c7d358SVivek Prakash
7597c7d358SVivek Prakash /*
7697c7d358SVivek Prakash * Argument scanning and profile reading code. Default parameters are set
7797c7d358SVivek Prakash * here as well.
7897c7d358SVivek Prakash */
7997c7d358SVivek Prakash
8097c7d358SVivek Prakash #include <ctype.h>
8197c7d358SVivek Prakash #include <stdio.h>
8297c7d358SVivek Prakash #include <stdlib.h>
8397c7d358SVivek Prakash #include <string.h>
8497c7d358SVivek Prakash #include "indent_globs.h"
8597c7d358SVivek Prakash
8697c7d358SVivek Prakash /* profile types */
8797c7d358SVivek Prakash #define PRO_SPECIAL 1 /* special case */
8897c7d358SVivek Prakash #define PRO_BOOL 2 /* boolean */
8997c7d358SVivek Prakash #define PRO_INT 3 /* integer */
9097c7d358SVivek Prakash #define PRO_FONT 4 /* troff font */
9197c7d358SVivek Prakash
9297c7d358SVivek Prakash /* profile specials for booleans */
9397c7d358SVivek Prakash #define ON 1 /* turn it on */
9497c7d358SVivek Prakash #define OFF 0 /* turn it off */
9597c7d358SVivek Prakash
9697c7d358SVivek Prakash /* profile specials for specials */
9797c7d358SVivek Prakash #define IGN 1 /* ignore it */
9897c7d358SVivek Prakash #define CLI 2 /* case label indent (float) */
9997c7d358SVivek Prakash #define STDIN 3 /* use stdin */
10097c7d358SVivek Prakash #define KEY 4 /* type (keyword) */
10197c7d358SVivek Prakash
10297c7d358SVivek Prakash const char *option_source = "?";
10397c7d358SVivek Prakash
10497c7d358SVivek Prakash /*
10597c7d358SVivek Prakash * N.B.: because of the way the table here is scanned, options whose names are
10697c7d358SVivek Prakash * substrings of other options must occur later; that is, with -lp vs -l, -lp
10797c7d358SVivek Prakash * must be first. Also, while (most) booleans occur more than once, the last
10897c7d358SVivek Prakash * default value is the one actually assigned.
10997c7d358SVivek Prakash */
11097c7d358SVivek Prakash struct pro {
11197c7d358SVivek Prakash const char *p_name; /* name, eg -bl, -cli */
11297c7d358SVivek Prakash int p_type; /* type (int, bool, special) */
11397c7d358SVivek Prakash int p_default; /* the default value (if int) */
11497c7d358SVivek Prakash int p_special; /* depends on type */
11597c7d358SVivek Prakash int *p_obj; /* the associated variable */
11697c7d358SVivek Prakash } pro[] = {
11797c7d358SVivek Prakash {
11897c7d358SVivek Prakash "T", PRO_SPECIAL, 0, KEY, 0
11997c7d358SVivek Prakash },
12097c7d358SVivek Prakash {
12197c7d358SVivek Prakash "bacc", PRO_BOOL, false, ON, &blanklines_around_conditional_compilation
12297c7d358SVivek Prakash },
12397c7d358SVivek Prakash {
12497c7d358SVivek Prakash "badp", PRO_BOOL, false, ON, &blanklines_after_declarations_at_proctop
12597c7d358SVivek Prakash },
12697c7d358SVivek Prakash {
12797c7d358SVivek Prakash "bad", PRO_BOOL, false, ON, &blanklines_after_declarations
12897c7d358SVivek Prakash },
12997c7d358SVivek Prakash {
13097c7d358SVivek Prakash "bap", PRO_BOOL, false, ON, &blanklines_after_procs
13197c7d358SVivek Prakash },
13297c7d358SVivek Prakash {
13397c7d358SVivek Prakash "bbb", PRO_BOOL, false, ON, &blanklines_before_blockcomments
13497c7d358SVivek Prakash },
13597c7d358SVivek Prakash {
13697c7d358SVivek Prakash "bc", PRO_BOOL, true, OFF, &ps.leave_comma
13797c7d358SVivek Prakash },
13897c7d358SVivek Prakash {
13997c7d358SVivek Prakash "bl", PRO_BOOL, true, OFF, &btype_2
14097c7d358SVivek Prakash },
14197c7d358SVivek Prakash {
14297c7d358SVivek Prakash "br", PRO_BOOL, true, ON, &btype_2
14397c7d358SVivek Prakash },
14497c7d358SVivek Prakash {
14597c7d358SVivek Prakash "bs", PRO_BOOL, false, ON, &Bill_Shannon
14697c7d358SVivek Prakash },
14797c7d358SVivek Prakash {
14897c7d358SVivek Prakash "cdb", PRO_BOOL, true, ON, &comment_delimiter_on_blankline
14997c7d358SVivek Prakash },
15097c7d358SVivek Prakash {
15197c7d358SVivek Prakash "cd", PRO_INT, 0, 0, &ps.decl_com_ind
15297c7d358SVivek Prakash },
15397c7d358SVivek Prakash {
15497c7d358SVivek Prakash "ce", PRO_BOOL, true, ON, &cuddle_else
15597c7d358SVivek Prakash },
15697c7d358SVivek Prakash {
15797c7d358SVivek Prakash "ci", PRO_INT, 0, 0, &continuation_indent
15897c7d358SVivek Prakash },
15997c7d358SVivek Prakash {
16097c7d358SVivek Prakash "cli", PRO_SPECIAL, 0, CLI, 0
16197c7d358SVivek Prakash },
16297c7d358SVivek Prakash {
16397c7d358SVivek Prakash "c", PRO_INT, 33, 0, &ps.com_ind
16497c7d358SVivek Prakash },
16597c7d358SVivek Prakash {
16697c7d358SVivek Prakash "di", PRO_INT, 16, 0, &ps.decl_indent
16797c7d358SVivek Prakash },
16897c7d358SVivek Prakash {
16997c7d358SVivek Prakash "dj", PRO_BOOL, false, ON, &ps.ljust_decl
17097c7d358SVivek Prakash },
17197c7d358SVivek Prakash {
17297c7d358SVivek Prakash "d", PRO_INT, 0, 0, &ps.unindent_displace
17397c7d358SVivek Prakash },
17497c7d358SVivek Prakash {
17597c7d358SVivek Prakash "eei", PRO_BOOL, false, ON, &extra_expression_indent
17697c7d358SVivek Prakash },
17797c7d358SVivek Prakash {
17897c7d358SVivek Prakash "ei", PRO_BOOL, true, ON, &ps.else_if
17997c7d358SVivek Prakash },
18097c7d358SVivek Prakash {
18197c7d358SVivek Prakash "fbc", PRO_FONT, 0, 0, (int *) &blkcomf
18297c7d358SVivek Prakash },
18397c7d358SVivek Prakash {
18497c7d358SVivek Prakash "fbx", PRO_FONT, 0, 0, (int *) &boxcomf
18597c7d358SVivek Prakash },
18697c7d358SVivek Prakash {
18797c7d358SVivek Prakash "fb", PRO_FONT, 0, 0, (int *) &bodyf
18897c7d358SVivek Prakash },
18997c7d358SVivek Prakash {
19097c7d358SVivek Prakash "fc1", PRO_BOOL, true, ON, &format_col1_comments
19197c7d358SVivek Prakash },
19297c7d358SVivek Prakash {
19397c7d358SVivek Prakash "fc", PRO_FONT, 0, 0, (int *) &scomf
19497c7d358SVivek Prakash },
19597c7d358SVivek Prakash {
19697c7d358SVivek Prakash "fk", PRO_FONT, 0, 0, (int *) &keywordf
19797c7d358SVivek Prakash },
19897c7d358SVivek Prakash {
19997c7d358SVivek Prakash "fs", PRO_FONT, 0, 0, (int *) &stringf
20097c7d358SVivek Prakash },
20197c7d358SVivek Prakash {
20297c7d358SVivek Prakash "ip", PRO_BOOL, true, ON, &ps.indent_parameters
20397c7d358SVivek Prakash },
20497c7d358SVivek Prakash {
20597c7d358SVivek Prakash "i", PRO_INT, 8, 0, &ps.ind_size
20697c7d358SVivek Prakash },
20797c7d358SVivek Prakash {
20897c7d358SVivek Prakash "lc", PRO_INT, 0, 0, &block_comment_max_col
20997c7d358SVivek Prakash },
21097c7d358SVivek Prakash {
21197c7d358SVivek Prakash "lp", PRO_BOOL, true, ON, &lineup_to_parens
21297c7d358SVivek Prakash },
21397c7d358SVivek Prakash {
21497c7d358SVivek Prakash "l", PRO_INT, 78, 0, &max_col
21597c7d358SVivek Prakash },
21697c7d358SVivek Prakash {
21797c7d358SVivek Prakash "nbacc", PRO_BOOL, false, OFF, &blanklines_around_conditional_compilation
21897c7d358SVivek Prakash },
21997c7d358SVivek Prakash {
22097c7d358SVivek Prakash "nbadp", PRO_BOOL, false, OFF, &blanklines_after_declarations_at_proctop
22197c7d358SVivek Prakash },
22297c7d358SVivek Prakash {
22397c7d358SVivek Prakash "nbad", PRO_BOOL, false, OFF, &blanklines_after_declarations
22497c7d358SVivek Prakash },
22597c7d358SVivek Prakash {
22697c7d358SVivek Prakash "nbap", PRO_BOOL, false, OFF, &blanklines_after_procs
22797c7d358SVivek Prakash },
22897c7d358SVivek Prakash {
22997c7d358SVivek Prakash "nbbb", PRO_BOOL, false, OFF, &blanklines_before_blockcomments
23097c7d358SVivek Prakash },
23197c7d358SVivek Prakash {
23297c7d358SVivek Prakash "nbc", PRO_BOOL, true, ON, &ps.leave_comma
23397c7d358SVivek Prakash },
23497c7d358SVivek Prakash {
23597c7d358SVivek Prakash "nbs", PRO_BOOL, false, OFF, &Bill_Shannon
23697c7d358SVivek Prakash },
23797c7d358SVivek Prakash {
23897c7d358SVivek Prakash "ncdb", PRO_BOOL, true, OFF, &comment_delimiter_on_blankline
23997c7d358SVivek Prakash },
24097c7d358SVivek Prakash {
24197c7d358SVivek Prakash "nce", PRO_BOOL, true, OFF, &cuddle_else
24297c7d358SVivek Prakash },
24397c7d358SVivek Prakash {
24497c7d358SVivek Prakash "ndj", PRO_BOOL, false, OFF, &ps.ljust_decl
24597c7d358SVivek Prakash },
24697c7d358SVivek Prakash {
24797c7d358SVivek Prakash "neei", PRO_BOOL, false, OFF, &extra_expression_indent
24897c7d358SVivek Prakash },
24997c7d358SVivek Prakash {
25097c7d358SVivek Prakash "nei", PRO_BOOL, true, OFF, &ps.else_if
25197c7d358SVivek Prakash },
25297c7d358SVivek Prakash {
25397c7d358SVivek Prakash "nfc1", PRO_BOOL, true, OFF, &format_col1_comments
25497c7d358SVivek Prakash },
25597c7d358SVivek Prakash {
25697c7d358SVivek Prakash "nip", PRO_BOOL, true, OFF, &ps.indent_parameters
25797c7d358SVivek Prakash },
25897c7d358SVivek Prakash {
25997c7d358SVivek Prakash "nlp", PRO_BOOL, true, OFF, &lineup_to_parens
26097c7d358SVivek Prakash },
26197c7d358SVivek Prakash {
26297c7d358SVivek Prakash "npcs", PRO_BOOL, false, OFF, &proc_calls_space
26397c7d358SVivek Prakash },
26497c7d358SVivek Prakash {
26597c7d358SVivek Prakash "npro", PRO_SPECIAL, 0, IGN, 0
26697c7d358SVivek Prakash },
26797c7d358SVivek Prakash {
26897c7d358SVivek Prakash "npsl", PRO_BOOL, true, OFF, &procnames_start_line
26997c7d358SVivek Prakash },
27097c7d358SVivek Prakash {
27197c7d358SVivek Prakash "nps", PRO_BOOL, false, OFF, &pointer_as_binop
27297c7d358SVivek Prakash },
27397c7d358SVivek Prakash {
27497c7d358SVivek Prakash "nsc", PRO_BOOL, true, OFF, &star_comment_cont
27597c7d358SVivek Prakash },
27697c7d358SVivek Prakash {
277*0a6a1f1dSLionel Sambuc "nut", PRO_BOOL, true, OFF, &use_tabs
278*0a6a1f1dSLionel Sambuc },
279*0a6a1f1dSLionel Sambuc {
28097c7d358SVivek Prakash "nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines
28197c7d358SVivek Prakash },
28297c7d358SVivek Prakash {
28397c7d358SVivek Prakash "nv", PRO_BOOL, false, OFF, &verbose
28497c7d358SVivek Prakash },
28597c7d358SVivek Prakash {
28697c7d358SVivek Prakash "pcs", PRO_BOOL, false, ON, &proc_calls_space
28797c7d358SVivek Prakash },
28897c7d358SVivek Prakash {
28997c7d358SVivek Prakash "psl", PRO_BOOL, true, ON, &procnames_start_line
29097c7d358SVivek Prakash },
29197c7d358SVivek Prakash {
29297c7d358SVivek Prakash "ps", PRO_BOOL, false, ON, &pointer_as_binop
29397c7d358SVivek Prakash },
29497c7d358SVivek Prakash {
29597c7d358SVivek Prakash "sc", PRO_BOOL, true, ON, &star_comment_cont
29697c7d358SVivek Prakash },
29797c7d358SVivek Prakash {
29897c7d358SVivek Prakash "sob", PRO_BOOL, false, ON, &swallow_optional_blanklines
29997c7d358SVivek Prakash },
30097c7d358SVivek Prakash {
30197c7d358SVivek Prakash "st", PRO_SPECIAL, 0, STDIN, 0
30297c7d358SVivek Prakash },
30397c7d358SVivek Prakash {
30497c7d358SVivek Prakash "troff", PRO_BOOL, false, ON, &troff
30597c7d358SVivek Prakash },
30697c7d358SVivek Prakash {
307*0a6a1f1dSLionel Sambuc "ut", PRO_BOOL, true, ON, &use_tabs
308*0a6a1f1dSLionel Sambuc },
309*0a6a1f1dSLionel Sambuc {
31097c7d358SVivek Prakash "v", PRO_BOOL, false, ON, &verbose
31197c7d358SVivek Prakash },
31297c7d358SVivek Prakash /* whew! */
31397c7d358SVivek Prakash {
31497c7d358SVivek Prakash 0, 0, 0, 0, 0
31597c7d358SVivek Prakash }
31697c7d358SVivek Prakash };
31797c7d358SVivek Prakash /*
31897c7d358SVivek Prakash * set_profile reads $HOME/.indent.pro and ./.indent.pro and handles arguments
31997c7d358SVivek Prakash * given in these files.
32097c7d358SVivek Prakash */
32197c7d358SVivek Prakash void
set_profile(void)32297c7d358SVivek Prakash set_profile(void)
32397c7d358SVivek Prakash {
32497c7d358SVivek Prakash FILE *f;
32597c7d358SVivek Prakash char fname[BUFSIZ];
32697c7d358SVivek Prakash static char prof[] = ".indent.pro";
32797c7d358SVivek Prakash
32897c7d358SVivek Prakash snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), prof);
32997c7d358SVivek Prakash if ((f = fopen(option_source = fname, "r")) != NULL) {
33097c7d358SVivek Prakash scan_profile(f);
33197c7d358SVivek Prakash (void) fclose(f);
33297c7d358SVivek Prakash }
33397c7d358SVivek Prakash if ((f = fopen(option_source = prof, "r")) != NULL) {
33497c7d358SVivek Prakash scan_profile(f);
33597c7d358SVivek Prakash (void) fclose(f);
33697c7d358SVivek Prakash }
33797c7d358SVivek Prakash option_source = "Command line";
33897c7d358SVivek Prakash }
33997c7d358SVivek Prakash
34097c7d358SVivek Prakash void
scan_profile(FILE * f)34197c7d358SVivek Prakash scan_profile(FILE *f)
34297c7d358SVivek Prakash {
34397c7d358SVivek Prakash int i;
34497c7d358SVivek Prakash char *p;
34597c7d358SVivek Prakash char buf[BUFSIZ];
34697c7d358SVivek Prakash
34797c7d358SVivek Prakash while (1) {
34897c7d358SVivek Prakash for (p = buf; (i = getc(f)) != EOF && (*p = i) > ' '; ++p);
34997c7d358SVivek Prakash if (p != buf) {
35097c7d358SVivek Prakash *p++ = 0;
35197c7d358SVivek Prakash if (verbose)
35297c7d358SVivek Prakash printf("profile: %s\n", buf);
35397c7d358SVivek Prakash set_option(buf);
35497c7d358SVivek Prakash } else
35597c7d358SVivek Prakash if (i == EOF)
35697c7d358SVivek Prakash return;
35797c7d358SVivek Prakash }
35897c7d358SVivek Prakash }
35997c7d358SVivek Prakash
36097c7d358SVivek Prakash const char *param_start;
36197c7d358SVivek Prakash
36297c7d358SVivek Prakash int
eqin(const char * s1,const char * s2)36397c7d358SVivek Prakash eqin(const char *s1, const char *s2)
36497c7d358SVivek Prakash {
36597c7d358SVivek Prakash while (*s1) {
36697c7d358SVivek Prakash if (*s1++ != *s2++)
36797c7d358SVivek Prakash return (false);
36897c7d358SVivek Prakash }
36997c7d358SVivek Prakash param_start = s2;
37097c7d358SVivek Prakash return (true);
37197c7d358SVivek Prakash }
37297c7d358SVivek Prakash /*
37397c7d358SVivek Prakash * Set the defaults.
37497c7d358SVivek Prakash */
37597c7d358SVivek Prakash void
set_defaults(void)37697c7d358SVivek Prakash set_defaults(void)
37797c7d358SVivek Prakash {
37897c7d358SVivek Prakash struct pro *p;
37997c7d358SVivek Prakash
38097c7d358SVivek Prakash /*
38197c7d358SVivek Prakash * Because ps.case_indent is a float, we can't initialize it from the
38297c7d358SVivek Prakash * table:
38397c7d358SVivek Prakash */
38497c7d358SVivek Prakash ps.case_indent = 0.0; /* -cli0.0 */
38597c7d358SVivek Prakash for (p = pro; p->p_name; p++)
38697c7d358SVivek Prakash if (p->p_type != PRO_SPECIAL && p->p_type != PRO_FONT)
38797c7d358SVivek Prakash *p->p_obj = p->p_default;
38897c7d358SVivek Prakash }
38997c7d358SVivek Prakash
39097c7d358SVivek Prakash void
set_option(char * arg)39197c7d358SVivek Prakash set_option(char *arg)
39297c7d358SVivek Prakash {
39397c7d358SVivek Prakash struct pro *p;
39497c7d358SVivek Prakash
39597c7d358SVivek Prakash arg++; /* ignore leading "-" */
39697c7d358SVivek Prakash for (p = pro; p->p_name; p++)
39797c7d358SVivek Prakash if (*p->p_name == *arg && eqin(p->p_name, arg))
39897c7d358SVivek Prakash goto found;
39997c7d358SVivek Prakash fprintf(stderr, "indent: %s: unknown parameter \"%s\"\n", option_source, arg - 1);
40097c7d358SVivek Prakash exit(1);
40197c7d358SVivek Prakash found:
40297c7d358SVivek Prakash switch (p->p_type) {
40397c7d358SVivek Prakash
40497c7d358SVivek Prakash case PRO_SPECIAL:
40597c7d358SVivek Prakash switch (p->p_special) {
40697c7d358SVivek Prakash
40797c7d358SVivek Prakash case IGN:
40897c7d358SVivek Prakash break;
40997c7d358SVivek Prakash
41097c7d358SVivek Prakash case CLI:
41197c7d358SVivek Prakash if (*param_start == 0)
41297c7d358SVivek Prakash goto need_param;
41397c7d358SVivek Prakash ps.case_indent = atof(param_start);
41497c7d358SVivek Prakash break;
41597c7d358SVivek Prakash
41697c7d358SVivek Prakash case STDIN:
41797c7d358SVivek Prakash if (input == 0)
41897c7d358SVivek Prakash input = stdin;
41997c7d358SVivek Prakash if (output == 0)
42097c7d358SVivek Prakash output = stdout;
42197c7d358SVivek Prakash break;
42297c7d358SVivek Prakash
42397c7d358SVivek Prakash case KEY:
42497c7d358SVivek Prakash if (*param_start == 0)
42597c7d358SVivek Prakash goto need_param;
42697c7d358SVivek Prakash {
42797c7d358SVivek Prakash char *str;
42897c7d358SVivek Prakash
42997c7d358SVivek Prakash str = strdup(param_start);
43097c7d358SVivek Prakash addkey(str, 4);
43197c7d358SVivek Prakash }
43297c7d358SVivek Prakash break;
43397c7d358SVivek Prakash
43497c7d358SVivek Prakash default:
43597c7d358SVivek Prakash fprintf(stderr, "\
43697c7d358SVivek Prakash indent: set_option: internal error: p_special %d\n", p->p_special);
43797c7d358SVivek Prakash exit(1);
43897c7d358SVivek Prakash }
43997c7d358SVivek Prakash break;
44097c7d358SVivek Prakash
44197c7d358SVivek Prakash case PRO_BOOL:
44297c7d358SVivek Prakash if (p->p_special == OFF)
44397c7d358SVivek Prakash *p->p_obj = false;
44497c7d358SVivek Prakash else
44597c7d358SVivek Prakash *p->p_obj = true;
44697c7d358SVivek Prakash break;
44797c7d358SVivek Prakash
44897c7d358SVivek Prakash case PRO_INT:
44997c7d358SVivek Prakash if (!isdigit((unsigned char)*param_start)) {
45097c7d358SVivek Prakash need_param:
45197c7d358SVivek Prakash fprintf(stderr, "indent: %s: ``%s'' requires a parameter\n",
45297c7d358SVivek Prakash option_source, arg - 1);
45397c7d358SVivek Prakash exit(1);
45497c7d358SVivek Prakash }
45597c7d358SVivek Prakash *p->p_obj = atoi(param_start);
45697c7d358SVivek Prakash break;
45797c7d358SVivek Prakash
45897c7d358SVivek Prakash case PRO_FONT:
45997c7d358SVivek Prakash parsefont((struct fstate *) p->p_obj, param_start);
46097c7d358SVivek Prakash break;
46197c7d358SVivek Prakash
46297c7d358SVivek Prakash default:
46397c7d358SVivek Prakash fprintf(stderr, "indent: set_option: internal error: p_type %d\n",
46497c7d358SVivek Prakash p->p_type);
46597c7d358SVivek Prakash exit(1);
46697c7d358SVivek Prakash }
46797c7d358SVivek Prakash }
468