1CPROTO(1) USER COMMANDS CPROTO(1)
2
3
4
6 cproto - generate C function prototypes and convert function defini‐
7 tions
8
10 cproto [ option ... ] [ file ... ]
11
13 Cproto generates function prototypes for functions defined in the spec‐
14 ified C source files to the standard output. The function definitions
15 may be in the old style or ANSI C style. Optionally, cproto also out‐
16 puts declarations for variables defined in the files. If no file argu‐
17 ment is given, cproto reads its input from the standard input.
18
19 By giving a command line option, cproto will also convert function def‐
20 initions in the specified files from the old style to the ANSI C style.
21 The original source files along with files specified by
22
23 #include "file"
24
25 directives appearing in the source code will be overwritten with the
26 converted code. If no file names are given on the command line, then
27 the program reads the source code from the standard input and outputs
28 the converted source to the standard output.
29
30 If any comments appear in the parameter declarations for a function
31 definition, such as in the example,
32
33 main (argc, argv)
34 int argc; /* number of arguments */
35 char *argv[]; /* arguments */
36 {
37 }
38
39 then the converted function definition will have the form
40
41 int
42 main (
43 int argc, /* number of arguments */
44 char *argv[] /* arguments */
45 )
46 {
47 }
48
49 Otherwise, the converted function definition will look like
50
51 int
52 main (int argc, char *argv[])
53 {
54 }
55
56 Cproto can optionally convert function definitions from the ANSI style
57 to the old style. In this mode, the program also converts function
58 declarators and prototypes that appear outside function bodies. This
59 is not a complete ANSI C to old C conversion. The program does not
60 change anything within function bodies.
61
62 Cproto can optionally generate source in lint-library format. This is
63 useful in environments where the lint utility is used to supplement
64 prototype checking of your program.
65
67 -e Output the keyword extern in front of every generated prototype
68 or declaration that has global scope.
69
70 -f n Set the style of generated function prototypes where n is a num‐
71 ber from 0 to 3. For example, consider the function definition
72
73 main (argc, argv)
74 int argc;
75 char *argv[];
76 {
77 }
78
79 If the value is 0, then no prototypes are generated. When set
80 to 1, the output is:
81
82 int main(/*int argc, char *argv[]*/);
83
84 For a value of 2, the output has the form:
85
86 int main(int /*argc*/, char */*argv*/[]);
87
88 The default value is 3. It produces the full function proto‐
89 type:
90
91 int main(int argc, char *argv[]);
92
93 -l Generate text for a lint-library (overrides the “-f” option).
94 The output includes the comment
95
96 /* LINTLIBRARY */
97
98 Special comments LINT_EXTERN and LINT_PREPRO (a la “VARARGS”)
99 respectively turn on the “-x” option and copy comment-text to
100 the output (for preprocessing in lint). Use the comment
101
102 /* LINT_EXTERN2 */
103
104 to include externs defined in the first level of include-files.
105 Use the comment
106
107 /* LINT_SHADOWED */
108
109 to cause cproto to put “#undef” directives before each lint li‐
110 brary declaration (i.e., to avoid conflicts with macros that
111 happen to have to have the same name as the functions, thus
112 causing syntax errors).
113
114 Note that these special comments are not supported under
115 VAX/VMS, since there is no equivalent for the “-C” option of cpp
116 with VAX-C.
117
118 -c The parameter comments in the prototypes generated by the -f1
119 and -f2 options are omitted by default. Use this option to en‐
120 able the output of these comments.
121
122 -m Put a macro around the parameter list of every generated proto‐
123 type. For example:
124
125 int main P_((int argc, char *argv[]));
126
127 -M name
128 Set the name of the macro used to surround prototype parameter
129 lists when option -m is selected. The default is “P_”.
130
131 -n Rather than filling in “void” for functions without parameters,
132 use a comment “/*empty*/”.
133
134 -N name
135 Rather than filling in “void” for functions without parameters,
136 use the given name.
137
138 -d Omit the definition of the prototype macro used by the -m op‐
139 tion.
140
141 -o file
142 Specify the name of the output file (default: standard output).
143
144 -O file
145 Specify the name of the error file (default: standard error).
146
147 -p Disable promotion of formal parameters in old style function
148 definitions. By default, parameters of type char or short in
149 old style function definitions are promoted to type int in the
150 function prototype or converted ANSI C function definition. Pa‐
151 rameters of type float get promoted to double as well.
152
153 -q Do not output any error messages when the program cannot read
154 the file specified in an #include directive.
155
156 -s By default, cproto only generates declarations for functions and
157 variables having global scope. This option will output static
158 declarations as well.
159
160 -S Output only static declarations.
161
162 -i By default, cproto only generates declarations for functions and
163 variables having global scope. This option will output inline
164 declarations as well.
165
166 -T Copy type definitions from each file. (Definitions in in‐
167 cluded-files are copied, unlike the “-l” option).
168
169 -v Also output declarations for variables defined in the source.
170
171 -x This option causes procedures and variables which are declared
172 “extern” to be included in the output.
173
174 -X level
175 This option limits the include-file level from which declara‐
176 tions are extracted by examining the preprocessor output.
177
178 -a Convert function definitions from the old style to the ANSI C
179 style.
180
181 -t Convert function definitions from the ANSI C style to the tradi‐
182 tional style.
183
184 -b Rewrite function definition heads to include both old style and
185 new style declarations separated by a conditional compilation
186 directive. For example, the program can generate this function
187 definition:
188
189 #ifdef ANSI_FUNC
190
191 int
192 main (int argc, char *argv[])
193 #else
194
195 int
196 main (argc, argv)
197 int argc;
198 char *argv[]
199 #endif
200 {
201 }
202
203 -B directive
204 Set the conditional compilation directive to output at the be‐
205 ginning of function definitions generated by the -b option. The
206 default is
207
208 #ifdef ANSI_FUNC
209
210 -P template
211 -F template
212 -C template
213 Set the output format for generated prototypes, function defini‐
214 tions, and function definitions with parameter comments respec‐
215 tively. The format is specified by a template in the form
216
217 " int f ( a, b )"
218
219 but you may replace each space in this string with any number of
220 whitespace characters. For example, the option
221
222 -F"int f(\n\ta,\n\tb\n\t)"
223
224 will produce
225
226 int main(
227 int argc,
228 char *argv[]
229 )
230
231 -D name[=value]
232 This option is passed through to the preprocessor and is used to
233 define symbols for use with conditionals such as #ifdef.
234
235 -U name
236 This option is passed through to the preprocessor and is used to
237 remove any definitions of this symbol.
238
239 -I directory
240 This option is passed through to the preprocessor and is used to
241 specify a directory to search for files that are referenced with
242 #include.
243
244 -E cpp Pipe the input files through the specified C preprocessor com‐
245 mand when generating prototypes. By default, the program uses
246 /lib/cpp.
247
248 -E 0 Do not run the C preprocessor.
249
250 -V Print version information.
251
253 The environment variable CPROTO is scanned for a list of options in the
254 same format as the command line options. Options given on the command
255 line override any corresponding environment option.
256
258 If an un-tagged struct, union or enum declaration appears in a gener‐
259 ated function prototype or converted function definition, the content
260 of the declaration between the braces is empty.
261
262 The program does not pipe the source files through the C preprocessor
263 when it is converting function definitions. Instead, it tries to han‐
264 dle preprocessor directives and macros itself and can be confused by
265 tricky macro expansions. The conversion also discards some comments in
266 the function definition head.
267
268 The -v option does not generate declarations for variables defined with
269 the extern specifier. This doesn't strictly conform to the C language
270 standard but this rule was implemented because include files commonly
271 declare variables this way.
272
273 When the program encounters an error, it usually outputs the not very
274 descriptive message “syntax error”. (Your configuration may allow the
275 extended error reporting in yyerror.c).
276
277 Options that take string arguments only interpret the following charac‐
278 ter escape sequences:
279
280 \n newline
281 \s space
282 \t tab
283
284 VARARGS comments don't get passed through on systems whose C preproces‐
285 sors don't support this (e.g., VAX/VMS, MS-DOS).
286
288 Chin Huang
289 cthuang@vex.net
290 cthuang@interlog.com
291
292 Thomas E. Dickey
293 dickey@invisible-island.net
294 modifications to support lint library, type-copying, and port to VAX/VMS.
295
297 cc(1), cpp(1)
298
299
300
301Version 4.7v 2023-02-05 CPROTO(1)