1.\" Copyright (c) 1985, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" Copyright (c) 2002 - 2005 Tony Finch <dot@dotat.at>. All rights reserved. 4.\" 5.\" This code is derived from software contributed to Berkeley by 6.\" Dave Yost. It was rewritten to support ANSI C by Tony Finch. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)unifdef.1 8.2 (Berkeley) 4/1/94 33.\" $dotat: things/unifdef.1,v 1.51 2005/03/08 12:39:01 fanf2 Exp $ 34.\" $DragonFly: src/usr.bin/unifdef/unifdef.1,v 1.5 2007/05/17 08:19:02 swildner Exp $ 35.\" $FreeBSD: src/usr.bin/unifdef/unifdef.1,v 1.24 2005/05/21 09:55:09 ru Exp $ 36.\" 37.Dd September 24, 2002 38.Dt UNIFDEF 1 39.Os 40.Sh NAME 41.Nm unifdef , 42.Nm unifdefall 43.Nd remove preprocessor conditionals from code 44.Sh SYNOPSIS 45.Nm 46.Op Fl cdeklnst 47.Op Fl I Ns Ar path 48.Op Fl D Ns Ar sym Ns Op = Ns Ar val 49.Op Fl U Ns Ar sym 50.Op Fl iD Ns Ar sym Ns Op = Ns Ar val 51.Op Fl iU Ns Ar sym 52.Ar ... 53.Op Ar file 54.Nm unifdefall 55.Op Fl I Ns Ar path 56.Ar ... 57.Ar file 58.Sh DESCRIPTION 59The 60.Nm 61utility selectively processes conditional 62.Xr cpp 1 63directives. 64It removes from a file 65both the directives 66and any additional text that they specify should be removed, 67while otherwise leaving the file alone. 68.Pp 69The 70.Nm 71utility acts on 72.Ic #if , #ifdef , #ifndef , #elif , #else , 73and 74.Ic #endif 75lines, 76and it understands only the commonly-used subset 77of the expression syntax for 78.Ic #if 79and 80.Ic #elif 81lines. 82It handles 83integer values of symbols defined on the command line, 84the 85.Fn defined 86operator applied to symbols defined or undefined on the command line, 87the operators 88.Ic \&! , < , > , <= , >= , == , != , && , || , 89and parenthesized expressions. 90Anything that it does not understand is passed through unharmed. 91It only processes 92.Ic #ifdef 93and 94.Ic #ifndef 95directives if the symbol is specified on the command line, 96otherwise they are also passed through unchanged. 97By default, it ignores 98.Ic #if 99and 100.Ic #elif 101lines with constant expressions, 102or they may be processed by specifying the 103.Fl k 104flag on the command line. 105.Pp 106The 107.Nm 108utility also understands just enough about C 109to know when one of the directives is inactive 110because it is inside 111a comment, 112or affected by a backslash-continued line. 113It spots unusually-formatted preprocessor directives 114and knows when the layout is too odd to handle. 115.Pp 116A script called 117.Nm unifdefall 118can be used to remove all conditional 119.Xr cpp 1 120directives from a file. 121It uses 122.Nm Fl s 123and 124.Nm cpp Fl dM 125to get lists of all the controlling symbols 126and their definitions (or lack thereof), 127then invokes 128.Nm 129with appropriate arguments to process the file. 130.Pp 131Available options: 132.Pp 133.Bl -tag -width indent -compact 134.It Fl D Ns Ar sym Ns Op = Ns Ar val 135Specify that a symbol is defined, 136and optionally specify what value to give it 137for the purpose of handling 138.Ic #if 139and 140.Ic #elif 141directives. 142.Pp 143.It Fl U Ns Ar sym 144Specify that a symbol is undefined. 145If the same symbol appears in more than one argument, 146the last occurrence dominates. 147.Pp 148.It Fl c 149If the 150.Fl c 151flag is specified, 152then the operation of 153.Nm 154is complemented, 155i.e., the lines that would have been removed or blanked 156are retained and vice versa. 157.Pp 158.It Fl d 159Turn on printing of debugging messages. 160.Pp 161.It Fl e 162Because 163.Nm 164processes its input one line at a time, 165it cannot remove preprocessor directives that span more than one line. 166The most common example of this is a directive with a multi-line 167comment hanging off its right hand end. 168By default, 169if 170.Nm 171has to process such a directive, 172it will complain that the line is too obfuscated. 173The 174.Fl e 175option changes the behaviour so that, 176where possible, 177such lines are left unprocessed instead of reporting an error. 178.Pp 179.It Fl k 180Process 181.Ic #if 182and 183.Ic #elif 184lines with constant expressions. 185By default, sections controlled by such lines are passed through unchanged 186because they typically start 187.Dq Li "#if 0" 188and are used as a kind of comment to sketch out future or past development. 189It would be rude to strip them out, just as it would be for normal comments. 190.Pp 191.It Fl l 192Replace removed lines with blank lines 193instead of deleting them. 194.Pp 195.It Fl n 196Add 197.Li #line 198directives to the output following any deleted lines, 199so that errors produced when compiling the output file correspond to 200line numbers in the input file. 201.Pp 202.It Fl s 203Instead of processing the input file as usual, 204this option causes 205.Nm 206to produce a list of symbols that appear in expressions 207that 208.Nm 209understands. 210It is useful in conjunction with the 211.Fl dM 212option of 213.Xr cpp 1 214for creating 215.Nm 216command lines. 217.Pp 218.It Fl t 219Disables parsing for C comments 220and line continuations, 221which is useful 222for plain text. 223.Pp 224.It Fl iD Ns Ar sym Ns Op = Ns Ar val 225.It Fl iU Ns Ar sym 226Ignore 227.Ic #ifdef Ns s . 228If your C code uses 229.Ic #ifdef Ns s 230to delimit non-C lines, 231such as comments 232or code which is under construction, 233then you must tell 234.Nm 235which symbols are used for that purpose so that it will not try to parse 236comments 237and line continuations 238inside those 239.Ic #ifdef Ns s . 240One specifies ignored symbols with 241.Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc 242and 243.Fl iU Ns Ar sym 244similar to 245.Fl D Ns Ar sym Ns Op = Ns Ar val 246and 247.Fl U Ns Ar sym 248above. 249.Pp 250.It Fl I Ns Ar path 251Specifies to 252.Nm unifdefall 253an additional place to look for 254.Ic #include 255files. 256This option is ignored by 257.Nm 258for compatibility with 259.Xr cpp 1 260and to simplify the implementation of 261.Nm unifdefall . 262.El 263.Pp 264The 265.Nm 266utility copies its output to 267.Em stdout 268and will take its input from 269.Em stdin 270if no 271.Ar file 272argument is given. 273.Pp 274The 275.Nm 276utility works nicely with the 277.Fl D Ns Ar sym 278option of 279.Xr diff 1 . 280.Sh EXIT STATUS 281The 282.Nm 283utility exits 0 if the output is an exact copy of the input, 2841 if not, and 2 if in trouble. 285.Sh DIAGNOSTICS 286.Bl -item 287.It 288Too many levels of nesting. 289.It 290Inappropriate 291.Ic #elif , 292.Ic #else 293or 294.Ic #endif . 295.It 296Obfuscated preprocessor control line. 297.It 298Premature 299.Tn EOF 300(with the line number of the most recent unterminated 301.Ic #if ) . 302.It 303.Tn EOF 304in comment. 305.El 306.Sh SEE ALSO 307.Xr cpp 1 , 308.Xr diff 1 309.Sh HISTORY 310The 311.Nm 312command appeared in 313.Bx 4.3 . 314.Tn ANSI\~C 315support was added in 316.Fx 4.7 . 317.Sh BUGS 318Expression evaluation is very limited. 319.Pp 320Preprocessor control lines split across more than one physical line 321(because of comments or backslash-newline) 322cannot be handled in every situation. 323.Pp 324Trigraphs are not recognized. 325.Pp 326There is no support for symbols with different definitions at 327different points in the source file. 328.Pp 329The text-mode and ignore functionality does not correspond to modern 330.Xr cpp 1 331behaviour. 332