2 * Copyright (c) 1985 Sun Microsystems, Inc.
3 * Copyright (c) 1980 The Regents of the University of California.
4 * Copyright (c) 1976 Board of Trustees of the University of Illinois.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by the University of California, Berkeley, the University of Illinois,
13 * Urbana, and Sun Microsystems, Inc. The name of either University
14 * or Sun Microsystems may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 * Argument scanning and profile reading code. Default parameters are set
27 #include <sys/types.h>
35 #define PRO_SPECIAL 1 /* special case */
36 #define PRO_BOOL 2 /* boolean */
37 #define PRO_INT 3 /* integer */
38 #define PRO_FONT 4 /* troff font */
40 /* profile specials for booleans */
41 #define ON 1 /* turn it on */
42 #define OFF 0 /* turn it off */
44 /* profile specials for specials */
45 #define IGN 1 /* ignore it */
46 #define CLI 2 /* case label indent (float) */
47 #define STDIN 3 /* use stdin */
48 #define KEY 4 /* type (keyword) */
51 * N.B.: because of the way the table here is scanned, options whose names
52 * are substrings of other options must occur later; that is, with -lp vs -l,
53 * -lp must be first. Also, while (most) booleans occur more than once, the
54 * last default value is the one actually assigned.
58 char *p_name
; /* name, eg -bl, -cli */
59 int p_type
; /* type (int, bool, special) */
60 int p_default
; /* the default value (if int) */
61 int p_special
; /* depends on type */
62 int *p_obj
; /* the associated variable */
67 "T", PRO_SPECIAL
, 0, KEY
, 0,
68 "bacc", PRO_BOOL
, false, ON
, &bl_around
,
69 "badp", PRO_BOOL
, false, ON
, &bl_at_proctop
,
70 "bad", PRO_BOOL
, false, ON
, &bl_aft_decl
,
71 "bap", PRO_BOOL
, false, ON
, &bl_a_procs
,
72 "bbb", PRO_BOOL
, false, ON
, &bl_bef_bk
,
73 "bc", PRO_BOOL
, true, OFF
, &ps
.leave_comma
,
74 "bl", PRO_BOOL
, true, OFF
, &btype_2
,
75 "br", PRO_BOOL
, true, ON
, &btype_2
,
76 "bs", PRO_BOOL
, false, ON
, &Bill_Shannon
,
77 "cdb", PRO_BOOL
, true, ON
, &del_on_bl
,
78 "cd", PRO_INT
, 0, 0, &ps
.decl_com_ind
,
79 "ce", PRO_BOOL
, true, ON
, &cuddle_else
,
80 "ci", PRO_INT
, 0, 0, &continuation_indent
,
81 "cli", PRO_SPECIAL
, 0, CLI
, 0,
82 "c", PRO_INT
, 33, 0, &ps
.com_ind
,
83 "di", PRO_INT
, 16, 0, &ps
.decl_indent
,
84 "dj", PRO_BOOL
, false, ON
, &ps
.ljust_decl
,
85 "d", PRO_INT
, 0, 0, &ps
.unindent_displace
,
86 "eei", PRO_BOOL
, false, ON
, &ex_expr_indent
,
87 "ei", PRO_BOOL
, true, ON
, &ps
.else_if
,
88 "fbc", PRO_FONT
, 0, 0, (int *) &blkcomf
,
89 "fbx", PRO_FONT
, 0, 0, (int *) &boxcomf
,
90 "fb", PRO_FONT
, 0, 0, (int *) &bodyf
,
91 "fc1", PRO_BOOL
, true, ON
, &format_col1_comments
,
92 "fc", PRO_FONT
, 0, 0, (int *) &scomf
,
93 "fk", PRO_FONT
, 0, 0, (int *) &keywordf
,
94 "fs", PRO_FONT
, 0, 0, (int *) &stringf
,
95 "ip", PRO_BOOL
, true, ON
, &ps
.indent_parameters
,
96 "i", PRO_INT
, 8, 0, &ps
.ind_size
,
97 "lc", PRO_INT
, 0, 0, &bk_max_col
,
98 "lp", PRO_BOOL
, true, ON
, &lineup_to_parens
,
99 "l", PRO_INT
, 78, 0, &max_col
,
100 "nbacc", PRO_BOOL
, false, OFF
, &bl_around
,
101 "nbadp", PRO_BOOL
, false, OFF
, &bl_at_proctop
,
102 "nbad", PRO_BOOL
, false, OFF
, &bl_aft_decl
,
103 "nbap", PRO_BOOL
, false, OFF
, &bl_a_procs
,
104 "nbbb", PRO_BOOL
, false, OFF
, &bl_bef_bk
,
105 "nbc", PRO_BOOL
, true, ON
, &ps
.leave_comma
,
106 "nbs", PRO_BOOL
, false, OFF
, &Bill_Shannon
,
107 "ncdb", PRO_BOOL
, true, OFF
, &del_on_bl
,
108 "nce", PRO_BOOL
, true, OFF
, &cuddle_else
,
109 "ndj", PRO_BOOL
, false, OFF
, &ps
.ljust_decl
,
110 "neei", PRO_BOOL
, false, OFF
, &ex_expr_indent
,
111 "nei", PRO_BOOL
, true, OFF
, &ps
.else_if
,
112 "nfc1", PRO_BOOL
, true, OFF
, &format_col1_comments
,
113 "nip", PRO_BOOL
, true, OFF
, &ps
.indent_parameters
,
114 "nlp", PRO_BOOL
, true, OFF
, &lineup_to_parens
,
115 "npcs", PRO_BOOL
, false, OFF
, &proc_calls_space
,
116 "npro", PRO_SPECIAL
, 0, IGN
, 0,
117 "npsl", PRO_BOOL
, true, OFF
, &proc_str_line
,
118 "nps", PRO_BOOL
, false, OFF
, &ptr_binop
,
119 "nsc", PRO_BOOL
, true, OFF
, &star_comment_cont
,
120 "nsob", PRO_BOOL
, false, OFF
, &swallow_opt_bl
,
121 "nv", PRO_BOOL
, false, OFF
, &verbose
,
122 "pcs", PRO_BOOL
, false, ON
, &proc_calls_space
,
123 "psl", PRO_BOOL
, true, ON
, &proc_str_line
,
124 "ps", PRO_BOOL
, false, ON
, &ptr_binop
,
125 "sc", PRO_BOOL
, true, ON
, &star_comment_cont
,
126 "sob", PRO_BOOL
, false, ON
, &swallow_opt_bl
,
127 "st", PRO_SPECIAL
, 0, STDIN
, 0,
128 "troff", PRO_BOOL
, false, ON
, &troff
,
129 "v", PRO_BOOL
, false, ON
, &verbose
,
135 * set_profile reads $HOME/.indent.pro and ./.indent.pro and handles
136 * arguments given in these files.
142 static char prof
[] = ".indent.pro";
144 sprintf(fname
, "%s/%s", getenv("HOME"), prof
);
145 if ((f
= fopen(fname
, "r")) != NULL
)
150 if ((f
= fopen(prof
, "r")) != NULL
)
166 for (p
= buf
; (i
= getc(f
)) != EOF
&& (*p
= (char)i
) > ' '; ++p
);
171 printf("profile: %s\n", buf
);
198 register struct pro
*p
;
200 /* Because ps.case_indent is a float, we can't initialize it from
202 ps
.case_indent
= 0; /* -cli0.0 */
203 for (p
= pro
; p
->p_name
; p
++)
204 if (p
->p_type
!= PRO_SPECIAL
&& p
->p_type
!= PRO_FONT
)
205 *p
->p_obj
= p
->p_default
;
211 register struct pro
*p
;
213 arg
++; /* ignore leading "-" */
214 for (p
= pro
; p
->p_name
; p
++)
215 if (*p
->p_name
== *arg
&& eqin(p
->p_name
, arg
))
217 fprintf(stderr
, "indent: unknown parameter \"%s\"\n", arg
- 1);
224 switch (p
->p_special
)
231 if (*param_start
== 0)
233 ps
.case_indent
= atoi(param_start
);
244 if (*param_start
== 0)
247 register char *str
= (char *) malloc(strlen(param_start
) + 1);
248 strcpy(str
, param_start
);
255 indent: set_option: internal error: p_special %d\n", p
->p_special
);
261 if (p
->p_special
== OFF
)
268 if (*param_start
== 0)
271 fprintf(stderr
, "indent: ``%s'' requires a parameter\n",
275 *p
->p_obj
= atoi(param_start
);
279 parsefont((struct fstate
*) p
->p_obj
, param_start
);
283 fprintf(stderr
, "indent: set_option: internal error: p_type %d\n",