1CPROTO(1) General Commands Manual 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 -d Omit the definition of the prototype macro used by the -m op‐
132 tion.
133
134 -o file
135 Specify the name of the output file (default: standard output).
136
137 -O file
138 Specify the name of the error file (default: standard error).
139
140 -p Disable promotion of formal parameters in old style function
141 definitions. By default, parameters of type char or short in
142 old style function definitions are promoted to type int in the
143 function prototype or converted ANSI C function definition. Pa‐
144 rameters of type float get promoted to double as well.
145
146 -q Do not output any error messages when the program cannot read
147 the file specified in an #include directive.
148
149 -s By default, cproto only generates declarations for functions and
150 variables having global scope. This option will output static
151 declarations as well.
152
153 -S Output only static declarations.
154
155 -i By default, cproto only generates declarations for functions and
156 variables having global scope. This option will output inline
157 declarations as well.
158
159 -T Copy type definitions from each file. (Definitions in in‐
160 cluded-files are copied, unlike the "-l" option).
161
162 -v Also output declarations for variables defined in the source.
163
164 -x This option causes procedures and variables which are declared
165 "extern" to be included in the output.
166
167 -X level
168 This option limits the include-file level from which declara‐
169 tions are extracted by examining the preprocessor output.
170
171 -a Convert function definitions from the old style to the ANSI C
172 style.
173
174 -t Convert function definitions from the ANSI C style to the tradi‐
175 tional style.
176
177 -b Rewrite function definition heads to include both old style and
178 new style declarations separated by a conditional compilation
179 directive. For example, the program can generate this function
180 definition:
181
182 #ifdef ANSI_FUNC
183
184 int
185 main (int argc, char *argv[])
186 #else
187
188 int
189 main (argc, argv)
190 int argc;
191 char *argv[]
192 #endif
193 {
194 }
195
196 -B directive
197 Set the conditional compilation directive to output at the be‐
198 ginning of function definitions generated by the -b option. The
199 default is
200
201 #ifdef ANSI_FUNC
202
203 -P template
204 -F template
205 -C template
206 Set the output format for generated prototypes, function defini‐
207 tions, and function definitions with parameter comments respec‐
208 tively. The format is specified by a template in the form
209
210 " int f ( a, b )"
211
212 but you may replace each space in this string with any number of
213 whitespace characters. For example, the option
214
215 -F"int f(\n\ta,\n\tb\n\t)"
216
217 will produce
218
219 int main(
220 int argc,
221 char *argv[]
222 )
223
224 -D name[=value]
225 This option is passed through to the preprocessor and is used to
226 define symbols for use with conditionals such as #ifdef.
227
228 -U name
229 This option is passed through to the preprocessor and is used to
230 remove any definitions of this symbol.
231
232 -I directory
233 This option is passed through to the preprocessor and is used to
234 specify a directory to search for files that are referenced with
235 #include.
236
237 -E cpp Pipe the input files through the specified C preprocessor com‐
238 mand when generating prototypes. By default, the program uses
239 /lib/cpp.
240
241 -E 0 Do not run the C preprocessor.
242
243 -V Print version information.
244
246 The environment variable CPROTO is scanned for a list of options in the
247 same format as the command line options. Options given on the command
248 line override any corresponding environment option.
249
251 If an un-tagged struct, union or enum declaration appears in a gener‐
252 ated function prototype or converted function definition, the content
253 of the declaration between the braces is empty.
254
255 The program does not pipe the source files through the C preprocessor
256 when it is converting function definitions. Instead, it tries to han‐
257 dle preprocessor directives and macros itself and can be confused by
258 tricky macro expansions. The conversion also discards some comments in
259 the function definition head.
260
261 The -v option does not generate declarations for variables defined with
262 the extern specifier. This doesn't strictly conform to the C language
263 standard but this rule was implemented because include files commonly
264 declare variables this way.
265
266 When the program encounters an error, it usually outputs the not very
267 descriptive message "syntax error". (Your configuration may allow the
268 extended error reporting in yyerror.c).
269
270 Options that take string arguments only interpret the following charac‐
271 ter escape sequences:
272
273 \n newline
274 \s space
275 \t tab
276
277 VARARGS comments don't get passed through on systems whose C preproces‐
278 sors don't support this (e.g., VAX/VMS, MS-DOS).
279
281 Chin Huang
282 cthuang@vex.net
283 cthuang@interlog.com
284
285 Thomas E. Dickey
286 dickey@invisible-island.net
287 modifications to support lint library, type-copying, and port to VAX/VMS.
288
290 cc(1), cpp(1)
291
292
293
294 October 2020 CPROTO(1)