xref: /openbsd-src/gnu/usr.bin/gcc/protoize.1 (revision 699a035be169416a1a69f26d2eb35d7e6b678145)
1.\" Copyright (c) 1991, 1992, 1993, 1994 Free Software Foundation
2.\" See section COPYING for conditions for redistribution
3.\"
4.\" $OpenBSD: protoize.1,v 1.3 2014/01/18 22:06:02 schwarze Exp $
5.Dd $Mdocdate: January 18 2014 $
6.Dt PROTOIZE 1
7.Os
8.Sh NAME
9.Nm protoize ,
10.Nm unprotoize
11.Nd automatically add or remove function prototypes
12.Sh SYNOPSIS
13.Nm protoize
14.Bk -words
15.Op Fl CfgklNnqv
16.Op Fl B Ar directory
17.Op Fl c Ar COMPILATION-OPTIONS
18.Op Fl d Ar directory ...
19.Op Fl i Ar string
20.Op Fl p Ar program
21.Op Fl x Ar
22.Ar
23.Ek
24.Nm unprotoize
25.Bk -words
26.Op Fl fkNnqv
27.Op Fl c Ar COMPILATION-OPTIONS
28.Op Fl d Ar directory ...
29.Op Fl i Ar string
30.Op Fl p Ar program
31.Op Fl x Ar
32.Ar
33.Ek
34.Sh DESCRIPTION
35.Nm protoize
36is an optional part of GNU C.
37You can use it to add prototypes to a program,
38thus converting the program to ANSI C in one respect.
39The companion program
40.Nm unprotoize
41does the reverse: it removes argument types from any prototypes that are found.
42.Pp
43When you run these programs, you must specify a set of source files
44as command line arguments.
45The conversion programs start out by compiling these files
46to see what functions they define.
47The information gathered about a file
48.Ar FOO
49is saved in a file named
50.Ar FOO.X .
51.Pp
52After scanning comes the actual conversion.
53The specified files are all eligible to be converted;
54any files they include
55.Pq whether sources or just headers
56are eligible as well.
57.Pp
58But not all the eligible files are converted.
59By default,
60.Nm protoize
61and
62.Nm unprotoize
63convert only source and header files in the current directory.
64You can specify additional directories whose files
65should be converted with the
66.Sq Fl d Ar directory ...
67option.
68You can also specify particular files to exclude with the
69.Sq Fl x Ar
70option.
71A file is converted if it is eligible, its directory name matches one of the
72specified directory names, and its name within the directory has not
73been excluded.
74.Pp
75Basic conversion with
76.Nm protoize
77consists of rewriting most function definitions and function declarations
78to specify the types of the arguments.
79The only ones not rewritten are those for varargs functions.
80.Pp
81.Nm protoize
82optionally inserts prototype declarations at the beginning of the source file,
83to make them available for any calls that precede the function's definition.
84Or it can insert prototype declarations with block scope
85in the blocks where undeclared functions are called.
86.Pp
87Basic conversion with
88.Nm unprotoize
89consists of rewriting most function declarations to remove any argument types,
90and rewriting function definitions to the old-style pre-ANSI form.
91.Pp
92Both conversion programs print a warning for any function
93declaration or definition that they can't convert.
94You can suppress these warnings with the
95.Fl q
96option.
97.Pp
98The output from
99.Nm protoize
100or
101.Nm unprotoize
102replaces the original source file.
103The original file is renamed to a name ending with
104.Sq .save .
105If the
106.Sq .save
107file already exists, then the source file is simply discarded.
108.Pp
109.Nm protoize
110and
111.Nm unprotoize
112both depend on
113.Xr gcc 1
114to scan the program and collect information about the functions it uses.
115.Pp
116The options are as follows:
117.Bl -tag -width Ds
118.It Fl B Ar directory
119Look for the file
120.Sq SYSCALLS.c.X
121in
122.Ar directory ,
123instead of the usual directory
124.Pq normally Pa /usr/local/lib .
125This file contains prototype information about standard system functions.
126This option applies only to
127.Nm protoize .
128.It Fl C
129Rename files to end in
130.Sq .C
131instead of
132.Sq \&.c .
133This is convenient if you are converting a C program to C++.
134This option applies only to
135.Nm protoize .
136.It Fl c Ar COMPILATION-OPTIONS
137Use
138.Ar COMPILATION-OPTIONS
139as the options when running
140.Xr gcc 1
141to produce the
142.Sq .X
143files.
144The special option
145.Fl aux-info
146is always passed in addition, to tell gcc to write a
147.Sq .X
148file.
149.Pp
150Note that the compilation options must be given as a single argument to
151.Nm protoize
152or
153.Nm unprotoize .
154If you want to specify several gcc options, you must quote the entire set of
155compilation options to make them a single word in the shell.
156.Pp
157There are certain gcc arguments that you cannot use, because they
158would produce the wrong kind of output.
159These include
160.Fl g ,
161.Fl O ,
162.Fl c ,
163.Fl S ,
164and
165.Fl o .
166If you include these in the
167.Ar COMPILATION-OPTIONS ,
168they are ignored.
169.It Fl d Ar directory
170Specify additional directories whose files should be converted.
171.It Fl g
172Add explicit global declarations.
173This means inserting explicit declarations at the beginning of each
174source file for each function that is called in the file and was not declared.
175These declarations precede the first function definition that contains a
176call to an undeclared function.
177This option applies only to
178.Nm protoize .
179.It Fl i Ar string
180Indent old-style parameter declarations with the string
181.Ar string .
182This option applies only to
183.Nm protoize .
184.Pp
185.Nm unprotoize
186converts prototyped function definitions to old-style
187function definitions, where the arguments are declared between the
188argument list and the initial
189.Sq { .
190By default,
191.Nm unprotoize
192uses five spaces as the indentation.
193If you want to indent with just one space instead, use
194.Fl i
195.Sq \ \& .
196.It Fl k
197Keep the
198.Sq .X
199files.
200Normally, they are deleted after conversion is finished.
201.It Fl l
202Add explicit local declarations.
203.Nm protoize
204with
205.Fl l
206inserts a prototype declaration for each function in each block which calls
207the function without any declaration.
208This option applies only to
209.Nm protoize .
210.It Fl N
211Make no
212.Sq .save
213files.
214The original files are simply deleted.
215Use this option with caution.
216.It Fl n
217Make no real changes.
218This mode just prints information about the conversions
219that would have been done without
220.Fl n .
221.It Fl p Ar program
222Use the program
223.Ar program
224as the compiler.
225Normally, the name
226.Sq gcc
227is used.
228.It Fl q
229Work quietly.
230Most warnings are suppressed.
231.It Fl v
232Print the version number, just like
233.Fl v
234for gcc.
235.It Fl x Ar
236List of files to exclude from the conversion process.
237.El
238.Pp
239If you need special compiler options to compile one of your program's
240source files, then you should generate that file's
241.Sq .X
242file specially, by running gcc on that source file with
243the appropriate options and the option
244.Fl aux-info .
245Then run
246.Nm protoize
247on the entire set of files.
248.Nm protoize
249will use the existing
250.Sq .X
251file because it is newer than the source file.
252For example:
253.Pp
254.Dl $ gcc -Dfoo=bar file1.c -aux-info
255.Dl $ protoize *.c
256.Pp
257You need to include the special files along with the rest in the
258.Nm protoize
259command, even though their
260.Sq .X
261files already exist, because otherwise they won't get converted.
262.Pp
263.Bf -symbolic
264Note: most of this information is out of date and superseded by the
265EGCS install procedures.
266It is provided for historical reference only.
267.Ef
268.Sh SEE ALSO
269.Xr gcc 1 ,
270.Xr gcc-local 1
271.Sh HISTORY
272Ron Guilmette implemented the
273.Nm protoize
274and
275.Nm unprotoize
276tools.
277.Sh AUTHORS
278See the GNU CC manual for the contributors to GNU CC.
279.Sh CAVEATS
280The conversion programs
281.Nm protoize
282and
283.Nm unprotoize
284can sometimes change a source file in a way that won't work
285unless you rearrange it.
286.Pp
287.Nm protoize
288can insert references to a type name or type tag before
289the definition, or in a file where they are not defined.
290.Pp
291If this happens, compiler error messages should indicate where the
292new references are, so fixing the file by hand is straightforward.
293.Pp
294There are some C constructs which
295.Nm protoize
296cannot figure out.
297For example, it can't determine argument types for declaring a
298pointer-to-function variable; this must be done by hand.
299.Nm protoize
300inserts a comment containing
301.Sq ???
302each time it finds such a variable;
303all such variables can be found by searching for this string.
304ANSI C does not require declaring the argument types of
305pointer-to-function types.
306.Pp
307Using
308.Nm unprotoize
309can easily introduce bugs.
310If the program relied on prototypes to bring about conversion of arguments,
311these conversions will not take place in the program without prototypes.
312One case in which you can be sure
313.Nm unprotoize
314is safe is when you are removing prototypes that were made with
315.Nm protoize ;
316if the
317program worked before without any prototypes, it will work again
318without them.
319.Pp
320You can find all the places where this problem might occur by
321compiling the program with the
322.Fl Wconversion
323option.
324It prints a warning whenever an argument is converted.
325.Pp
326Both conversion programs can be confused if there are macro calls
327in and around the text to be converted.
328In other words, the standard syntax for a declaration or definition
329must not result from expanding a macro.
330This problem is inherent in the design of C and cannot be fixed.
331If only a few functions have confusing macro calls,
332you can easily convert them manually.
333.Pp
334.Nm protoize
335cannot get the argument types for a function whose definition was not
336actually compiled due to preprocessing conditionals.
337When this happens,
338.Nm protoize
339changes nothing in regard to such a function.
340.Nm protoize
341tries to detect such instances and warn about them.
342.Pp
343You can generally work around this problem by using
344.Nm protoize
345step by step, each time specifying a different set of
346.Fl D
347options for compilation, until all of the functions have been converted.
348There is no automatic way to verify that you have got them all, however.
349.Pp
350Confusion may result if there is an occasion to convert a function
351declaration or definition in a region of source code where there
352is more than one formal parameter list present.
353Thus, attempts to convert code containing multiple
354.Pq conditionally compiled
355versions of a single function header
356.Pq in the same vicinity
357may not produce the desired
358.Pq or expected
359results.
360.Pp
361If you plan on converting source files which contain such code,
362it is recommended that you first make sure that each conditionally
363compiled region of source code which contains an alternative
364function header also contains at least one additional follower
365token (past the final right parenthesis of the function header).
366This should circumvent the problem.
367.Pp
368.Nm unprotoize
369can become confused when trying to convert a function
370definition or declaration which contains a declaration for a
371pointer-to-function formal argument which has the same name as the
372function being defined or declared.
373We recommand you avoid such choices of formal parameter names.
374.Pp
375It might be necessary to correct some of the indentation by hand and
376break long lines.
377(The conversion programs don't write lines longer than eighty characters
378in any case.)
379.Sh BUGS
380For instructions on reporting bugs, see the GCC manual.
381.Sh COPYING
382Copyright 1991, 1992, 1993 Free Software Foundation, Inc.
383.Pp
384Permission is granted to make and distribute verbatim copies of
385this manual provided the copyright notice and this permission notice
386are preserved on all copies.
387.Pp
388Permission is granted to copy and distribute modified versions of this
389manual under the conditions for verbatim copying, provided that the
390entire resulting derived work is distributed under the terms of a
391permission notice identical to this one.
392.Pp
393Permission is granted to copy and distribute translations of this
394manual into another language, under the above conditions for modified
395versions, except that this permission notice may be included in
396translations approved by the Free Software Foundation instead of in
397the original English.
398