Index: stable/9/usr.bin/calendar =================================================================== --- stable/9/usr.bin/calendar (revision 279642) +++ stable/9/usr.bin/calendar (revision 279643) Property changes on: stable/9/usr.bin/calendar ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/usr.bin/calendar:r233456,248258,248849,279297 Index: stable/9/usr.bin/find/find.1 =================================================================== --- stable/9/usr.bin/find/find.1 (revision 279642) +++ stable/9/usr.bin/find/find.1 (revision 279643) @@ -1,1081 +1,1080 @@ .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" the Institute of Electrical and Electronics Engineers, Inc. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)find.1 8.7 (Berkeley) 5/9/95 .\" $FreeBSD$ .\" .Dd January 5, 2014 .Dt FIND 1 .Os .Sh NAME .Nm find .Nd walk a file hierarchy .Sh SYNOPSIS .Nm .Op Fl H | Fl L | Fl P .Op Fl EXdsx .Op Fl f Ar path .Ar path ... .Op Ar expression .Nm .Op Fl H | Fl L | Fl P .Op Fl EXdsx .Fl f Ar path .Op Ar path ... .Op Ar expression .Sh DESCRIPTION The .Nm utility recursively descends the directory tree for each .Ar path listed, evaluating an .Ar expression (composed of the .Dq primaries and .Dq operands listed below) in terms of each file in the tree. .Pp The options are as follows: .Bl -tag -width indent .It Fl E Interpret regular expressions followed by .Ic -regex and .Ic -iregex primaries as extended (modern) regular expressions rather than basic regular expressions (BRE's). The .Xr re_format 7 manual page fully describes both formats. .It Fl H Cause the file information and file type (see .Xr stat 2 ) returned for each symbolic link specified on the command line to be those of the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will be for the link itself. File information of all symbolic links not on the command line is that of the link itself. .It Fl L Cause the file information and file type (see .Xr stat 2 ) returned for each symbolic link to be those of the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will be for the link itself. .Pp This option is equivalent to the deprecated .Ic -follow primary. .It Fl P Cause the file information and file type (see .Xr stat 2 ) returned for each symbolic link to be those of the link itself. This is the default. .It Fl X Permit .Nm to be safely used in conjunction with .Xr xargs 1 . If a file name contains any of the delimiting characters used by .Xr xargs 1 , a diagnostic message is displayed on standard error, and the file is skipped. The delimiting characters include single .Pq Dq Li " ' " and double .Pq Dq Li " \*q " quotes, backslash .Pq Dq Li \e , space, tab and newline characters. .Pp However, you may wish to consider the .Fl print0 primary in conjunction with .Dq Nm xargs Fl 0 as an effective alternative. .It Fl d Cause .Nm to perform a depth-first traversal. .Pp This option is a BSD-specific equivalent of the .Ic -depth primary specified by .St -p1003.1-2001 . Refer to its description under .Sx PRIMARIES for more information. .It Fl s Cause .Nm to traverse the file hierarchies in lexicographical order, i.e., alphabetical order within each directory. Note: .Ql find -s and .Ql "find | sort" may give different results. .It Fl x Prevent .Nm from descending into directories that have a device number different than that of the file from which the descent began. .Pp This option is equivalent to the deprecated .Ic -xdev primary. .El .Sh PRIMARIES -.Pp All primaries which take a numeric argument allow the number to be preceded by a plus sign .Pq Dq Li + or a minus sign .Pq Dq Li - . A preceding plus sign means .Dq more than n , a preceding minus sign means .Dq less than n and neither means .Dq exactly n . .Bl -tag -width indent .It Ic -Bmin Ar n True if the difference between the time of a file's inode creation and the time .Nm was started, rounded up to the next full minute, is .Ar n minutes. .It Ic -Bnewer Ar file Same as .Ic -newerBm . .It Ic -Btime Ar n Ns Op Cm smhdw If no units are specified, this primary evaluates to true if the difference between the time of a file's inode creation and the time .Nm was started, rounded up to the next full 24-hour period, is .Ar n 24-hour periods. .Pp If units are specified, this primary evaluates to true if the difference between the time of a file's inode creation and the time .Nm was started is exactly .Ar n units. Please refer to the .Ic -atime primary description for information on supported time units. .It Ic -acl May be used in conjunction with other primaries to locate files with extended ACLs. See .Xr acl 3 for more information. .It Ic -amin Ar n True if the difference between the file last access time and the time .Nm was started, rounded up to the next full minute, is .Ar n minutes. .It Ic -anewer Ar file Same as .Ic -neweram . .It Ic -atime Ar n Ns Op Cm smhdw If no units are specified, this primary evaluates to true if the difference between the file last access time and the time .Nm was started, rounded up to the next full 24-hour period, is .Ar n 24-hour periods. .Pp If units are specified, this primary evaluates to true if the difference between the file last access time and the time .Nm was started is exactly .Ar n units. Possible time units are as follows: .Pp .Bl -tag -width indent -compact .It Cm s second .It Cm m minute (60 seconds) .It Cm h hour (60 minutes) .It Cm d day (24 hours) .It Cm w week (7 days) .El .Pp Any number of units may be combined in one .Ic -atime argument, for example, .Dq Li "-atime -1h30m" . Units are probably only useful when used in conjunction with the .Cm + or .Cm - modifier. .It Ic -cmin Ar n True if the difference between the time of last change of file status information and the time .Nm was started, rounded up to the next full minute, is .Ar n minutes. .It Ic -cnewer Ar file Same as .Ic -newercm . .It Ic -ctime Ar n Ns Op Cm smhdw If no units are specified, this primary evaluates to true if the difference between the time of last change of file status information and the time .Nm was started, rounded up to the next full 24-hour period, is .Ar n 24-hour periods. .Pp If units are specified, this primary evaluates to true if the difference between the time of last change of file status information and the time .Nm was started is exactly .Ar n units. Please refer to the .Ic -atime primary description for information on supported time units. .It Ic -d Non-portable, BSD-specific version of .Ic depth . GNU find implements this as a primary in mistaken emulation of .Fx .Nm . .It Ic -delete Delete found files and/or directories. Always returns true. This executes from the current working directory as .Nm recurses down the tree. It will not attempt to delete a filename with a .Dq Pa / character in its pathname relative to .Dq Pa \&. for security reasons. Depth-first traversal processing is implied by this option. Following symlinks is incompatible with this option. .It Ic -depth Always true; same as the non-portable .Fl d option. Cause .Nm to perform a depth-first traversal, i.e., directories are visited in post-order and all entries in a directory will be acted on before the directory itself. By default, .Nm visits directories in pre-order, i.e., before their contents. Note, the default is .Em not a breadth-first traversal. .Pp The .Ic -depth primary can be useful when .Nm is used with .Xr cpio 1 to process files that are contained in directories with unusual permissions. It ensures that you have write permission while you are placing files in a directory, then sets the directory's permissions as the last thing. .It Ic -depth Ar n True if the depth of the file relative to the starting point of the traversal is .Ar n . .It Ic -empty True if the current file or directory is empty. .It Ic -exec Ar utility Oo Ar argument ... Oc Li \&; True if the program named .Ar utility returns a zero value as its exit status. Optional .Ar arguments may be passed to the utility. The expression must be terminated by a semicolon .Pq Dq Li \&; . If you invoke .Nm from a shell you may need to quote the semicolon if the shell would otherwise treat it as a control operator. If the string .Dq Li {} appears anywhere in the utility name or the arguments it is replaced by the pathname of the current file. .Ar Utility will be executed from the directory from which .Nm was executed. .Ar Utility and .Ar arguments are not subject to the further expansion of shell patterns and constructs. .It Ic -exec Ar utility Oo Ar argument ... Oc Li {} + Same as .Ic -exec , except that .Dq Li {} is replaced with as many pathnames as possible for each invocation of .Ar utility . This behaviour is similar to that of .Xr xargs 1 . .It Ic -execdir Ar utility Oo Ar argument ... Oc Li \&; The .Ic -execdir primary is identical to the .Ic -exec primary with the exception that .Ar utility will be executed from the directory that holds the current file. The filename substituted for the string .Dq Li {} is not qualified. .It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} + Same as .Ic -execdir , except that .Dq Li {} is replaced with as many pathnames as possible for each invocation of .Ar utility . This behaviour is similar to that of .Xr xargs 1 . .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags The flags are specified using symbolic names (see .Xr chflags 1 ) . Those with the .Qq Li no prefix (except .Qq Li nodump ) are said to be .Ar notflags . Flags in .Ar flags are checked to be set, and flags in .Ar notflags are checked to be not set. Note that this is different from .Ic -perm , which only allows the user to specify mode bits that are set. .Pp If flags are preceded by a dash .Pq Dq Li - , this primary evaluates to true if at least all of the bits in .Ar flags and none of the bits in .Ar notflags are set in the file's flags bits. If flags are preceded by a plus .Pq Dq Li + , this primary evaluates to true if any of the bits in .Ar flags is set in the file's flags bits, or any of the bits in .Ar notflags is not set in the file's flags bits. Otherwise, this primary evaluates to true if the bits in .Ar flags exactly match the file's flags bits, and none of the .Ar flags bits match those of .Ar notflags . .It Ic -fstype Ar type True if the file is contained in a file system of type .Ar type . The .Xr lsvfs 1 command can be used to find out the types of file systems that are available on the system. In addition, there are two pseudo-types, .Dq Li local and .Dq Li rdonly . The former matches any file system physically mounted on the system where the .Nm is being executed and the latter matches any file system which is mounted read-only. .It Ic -gid Ar gname The same thing as .Ar -group Ar gname for compatibility with GNU find. GNU find imposes a restriction that .Ar gname is numeric, while .Nm does not. .It Ic -group Ar gname True if the file belongs to the group .Ar gname . If .Ar gname is numeric and there is no such group name, then .Ar gname is treated as a group ID. .It Ic -ignore_readdir_race Ignore errors because a file or a directory is deleted after reading the name from a directory. This option does not affect errors occurring on starting points. .It Ic -ilname Ar pattern Like .Ic -lname , but the match is case insensitive. This is a GNU find extension. .It Ic -iname Ar pattern Like .Ic -name , but the match is case insensitive. .It Ic -inum Ar n True if the file has inode number .Ar n . .It Ic -ipath Ar pattern Like .Ic -path , but the match is case insensitive. .It Ic -iregex Ar pattern Like .Ic -regex , but the match is case insensitive. .It Ic -iwholename Ar pattern The same thing as .Ic -ipath , for GNU find compatibility. .It Ic -links Ar n True if the file has .Ar n links. .It Ic -lname Ar pattern Like .Ic -name , but the contents of the symbolic link are matched instead of the file name. Note that this only matches broken symbolic links if symbolic links are being followed. This is a GNU find extension. .It Ic -ls This primary always evaluates to true. The following information for the current file is written to standard output: its inode number, size in 512-byte blocks, file permissions, number of hard links, owner, group, size in bytes, last modification time, and pathname. If the file is a block or character special file, the major and minor numbers will be displayed instead of the size in bytes. If the file is a symbolic link, the pathname of the linked-to file will be displayed preceded by .Dq Li -> . The format is identical to that produced by .Bk -words .Dq Nm ls Fl dgils . .Ek .It Ic -maxdepth Ar n Always true; descend at most .Ar n directory levels below the command line arguments. If any .Ic -maxdepth primary is specified, it applies to the entire expression even if it would not normally be evaluated. .Dq Ic -maxdepth Li 0 limits the whole search to the command line arguments. .It Ic -mindepth Ar n Always true; do not apply any tests or actions at levels less than .Ar n . If any .Ic -mindepth primary is specified, it applies to the entire expression even if it would not normally be evaluated. .Dq Ic -mindepth Li 1 processes all but the command line arguments. .It Ic -mmin Ar n True if the difference between the file last modification time and the time .Nm was started, rounded up to the next full minute, is .Ar n minutes. .It Ic -mnewer Ar file Same as .Ic -newer . .It Ic -mount The same thing as .Ic -xdev , for GNU find compatibility. .It Ic -mtime Ar n Ns Op Cm smhdw If no units are specified, this primary evaluates to true if the difference between the file last modification time and the time .Nm was started, rounded up to the next full 24-hour period, is .Ar n 24-hour periods. .Pp If units are specified, this primary evaluates to true if the difference between the file last modification time and the time .Nm was started is exactly .Ar n units. Please refer to the .Ic -atime primary description for information on supported time units. .It Ic -name Ar pattern True if the last component of the pathname being examined matches .Ar pattern . Special shell pattern matching characters .Dq ( Li \&[ , .Dq Li \&] , .Dq Li * , and .Dq Li \&? ) may be used as part of .Ar pattern . These characters may be matched explicitly by escaping them with a backslash .Pq Dq Li \e . .It Ic -newer Ar file True if the current file has a more recent last modification time than .Ar file . .It Ic -newer Ns Ar X Ns Ar Y Ar file True if the current file has a more recent last access time .Pq Ar X Ns = Ns Cm a , inode creation time .Pq Ar X Ns = Ns Cm B , change time .Pq Ar X Ns = Ns Cm c , or modification time .Pq Ar X Ns = Ns Cm m than the last access time .Pq Ar Y Ns = Ns Cm a , inode creation time .Pq Ar Y Ns = Ns Cm B , change time .Pq Ar Y Ns = Ns Cm c , or modification time .Pq Ar Y Ns = Ns Cm m of .Ar file . In addition, if .Ar Y Ns = Ns Cm t , then .Ar file is instead interpreted as a direct date specification of the form understood by .Xr cvs 1 . Note that .Ic -newermm is equivalent to .Ic -newer . .It Ic -nogroup True if the file belongs to an unknown group. .It Ic -noignore_readdir_race Turn off the effect of .Ic -ignore_readdir_race . This is default behaviour. .It Ic -noleaf This option is for GNU find compatibility. In GNU find it disables an optimization not relevant to .Nm , so it is ignored. .It Ic -nouser True if the file belongs to an unknown user. .It Ic -ok Ar utility Oo Ar argument ... Oc Li \&; The .Ic -ok primary is identical to the .Ic -exec primary with the exception that .Nm requests user affirmation for the execution of the .Ar utility by printing a message to the terminal and reading a response. If the response is not affirmative .Ql ( y in the .Dq Li POSIX locale), the command is not executed and the value of the .Ic -ok expression is false. .It Ic -okdir Ar utility Oo Ar argument ... Oc Li \&; The .Ic -okdir primary is identical to the .Ic -execdir primary with the same exception as described for the .Ic -ok primary. .It Ic -path Ar pattern True if the pathname being examined matches .Ar pattern . Special shell pattern matching characters .Dq ( Li \&[ , .Dq Li \&] , .Dq Li * , and .Dq Li \&? ) may be used as part of .Ar pattern . These characters may be matched explicitly by escaping them with a backslash .Pq Dq Li \e . Slashes .Pq Dq Li / are treated as normal characters and do not have to be matched explicitly. .It Ic -perm Oo Cm - Ns | Ns Cm + Oc Ns Ar mode The .Ar mode may be either symbolic (see .Xr chmod 1 ) or an octal number. If the .Ar mode is symbolic, a starting value of zero is assumed and the .Ar mode sets or clears permissions without regard to the process' file mode creation mask. If the .Ar mode is octal, only bits 07777 .Pq Dv S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO of the file's mode bits participate in the comparison. If the .Ar mode is preceded by a dash .Pq Dq Li - , this primary evaluates to true if at least all of the bits in the .Ar mode are set in the file's mode bits. If the .Ar mode is preceded by a plus .Pq Dq Li + , this primary evaluates to true if any of the bits in the .Ar mode are set in the file's mode bits. Otherwise, this primary evaluates to true if the bits in the .Ar mode exactly match the file's mode bits. Note, the first character of a symbolic mode may not be a dash .Pq Dq Li - . .It Ic -print This primary always evaluates to true. It prints the pathname of the current file to standard output. If none of .Ic -exec , -ls , -print0 , or .Ic -ok is specified, the given expression shall be effectively replaced by .Cm \&( Ar "given expression" Cm \&) Ic -print . .It Ic -print0 This primary always evaluates to true. It prints the pathname of the current file to standard output, followed by an .Tn ASCII .Dv NUL character (character code 0). .It Ic -prune This primary always evaluates to true. It causes .Nm to not descend into the current file. Note, the .Ic -prune primary has no effect if the .Fl d option was specified. .It Ic -quit Causes .Nm to immediately terminate. .It Ic -regex Ar pattern True if the whole path of the file matches .Ar pattern using regular expression. To match a file named .Dq Pa ./foo/xyzzy , you can use the regular expression .Dq Li ".*/[xyz]*" or .Dq Li ".*/foo/.*" , but not .Dq Li xyzzy or .Dq Li /foo/ . .It Ic -samefile Ar name True if the file is a hard link to .Ar name . If the command option .Ic -L is specified, it is also true if the file is a symbolic link and points to .Ar name . .It Ic -size Ar n Ns Op Cm ckMGTP True if the file's size, rounded up, in 512-byte blocks is .Ar n . If .Ar n is followed by a .Cm c , then the primary is true if the file's size is .Ar n bytes (characters). Similarly if .Ar n is followed by a scale indicator then the file's size is compared to .Ar n scaled as: .Pp .Bl -tag -width indent -compact .It Cm k kilobytes (1024 bytes) .It Cm M megabytes (1024 kilobytes) .It Cm G gigabytes (1024 megabytes) .It Cm T terabytes (1024 gigabytes) .It Cm P petabytes (1024 terabytes) .El .It Ic -type Ar t True if the file is of the specified type. Possible file types are as follows: .Pp .Bl -tag -width indent -compact .It Cm b block special .It Cm c character special .It Cm d directory .It Cm f regular file .It Cm l symbolic link .It Cm p FIFO .It Cm s socket .El .It Ic -uid Ar uname The same thing as .Ar -user Ar uname for compatibility with GNU find. GNU find imposes a restriction that .Ar uname is numeric, while .Nm does not. .It Ic -user Ar uname True if the file belongs to the user .Ar uname . If .Ar uname is numeric and there is no such user name, then .Ar uname is treated as a user ID. .It Ic -wholename Ar pattern The same thing as .Ic -path , for GNU find compatibility. .El .Sh OPERATORS The primaries may be combined using the following operators. The operators are listed in order of decreasing precedence. .Pp .Bl -tag -width indent -compact .It Cm \&( Ar expression Cm \&) This evaluates to true if the parenthesized expression evaluates to true. .Pp .It Cm \&! Ar expression .It Cm -not Ar expression This is the unary .Tn NOT operator. It evaluates to true if the expression is false. .Pp .It Cm -false Always false. .It Cm -true Always true. .Pp .It Ar expression Cm -and Ar expression .It Ar expression expression The .Cm -and operator is the logical .Tn AND operator. As it is implied by the juxtaposition of two expressions it does not have to be specified. The expression evaluates to true if both expressions are true. The second expression is not evaluated if the first expression is false. .Pp .It Ar expression Cm -or Ar expression The .Cm -or operator is the logical .Tn OR operator. The expression evaluates to true if either the first or the second expression is true. The second expression is not evaluated if the first expression is true. .El .Pp All operands and primaries must be separate arguments to .Nm . Primaries which themselves take arguments expect each argument to be a separate argument to .Nm . .Sh ENVIRONMENT The .Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES and .Ev LC_TIME environment variables affect the execution of the .Nm utility as described in .Xr environ 7 . .Sh EXAMPLES The following examples are shown as given to the shell: .Bl -tag -width indent .It Li "find / \e! -name \*q*.c\*q -print" Print out a list of all the files whose names do not end in .Pa .c . .It Li "find / -newer ttt -user wnj -print" Print out a list of all the files owned by user .Dq wnj that are newer than the file .Pa ttt . .It Li "find / \e! \e( -newer ttt -user wnj \e) -print" Print out a list of all the files which are not both newer than .Pa ttt and owned by .Dq wnj . .It Li "find / \e( -newer ttt -or -user wnj \e) -print" Print out a list of all the files that are either owned by .Dq wnj or that are newer than .Pa ttt . .It Li "find / -newerct '1 minute ago' -print" Print out a list of all the files whose inode change time is more recent than the current time minus one minute. .It Li "find / -type f -exec echo {} \e;" Use the .Xr echo 1 command to print out a list of all the files. .It Li "find -L /usr/ports/packages -type l -exec rm -- {} +" Delete all broken symbolic links in .Pa /usr/ports/packages . .It Li "find /usr/src -name CVS -prune -o -depth +6 -print" Find files and directories that are at least seven levels deep in the working directory .Pa /usr/src . .It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print" Is not equivalent to the previous example, since .Ic -prune is not evaluated below level seven. .El .Sh COMPATIBILITY The .Ic -follow primary is deprecated; the .Fl L option should be used instead. See the .Sx STANDARDS section below for details. .Sh SEE ALSO .Xr chflags 1 , .Xr chmod 1 , .Xr cvs 1 , .Xr locate 1 , .Xr lsvfs 1 , .Xr whereis 1 , .Xr which 1 , .Xr xargs 1 , .Xr stat 2 , .Xr acl 3 , .Xr fts 3 , .Xr getgrent 3 , .Xr getpwent 3 , .Xr strmode 3 , .Xr re_format 7 , .Xr symlink 7 .Sh STANDARDS The .Nm utility syntax is a superset of the syntax specified by the .St -p1003.1-2001 standard. .Pp All the single character options except .Fl H and .Fl L as well as .Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype , .Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin , .Ic -path , -print0 , -regex and all of the .Ic -B* birthtime related primaries are extensions to .St -p1003.1-2001 . .Pp Historically, the .Fl d , L and .Fl x options were implemented using the primaries .Ic -depth , -follow , and .Ic -xdev . These primaries always evaluated to true. As they were really global variables that took effect before the traversal began, some legal expressions could have unexpected results. An example is the expression .Ic -print Cm -o Ic -depth . As .Ic -print always evaluates to true, the standard order of evaluation implies that .Ic -depth would never be evaluated. This is not the case. .Pp The operator .Cm -or was implemented as .Cm -o , and the operator .Cm -and was implemented as .Cm -a . .Pp Historic implementations of the .Ic -exec and .Ic -ok primaries did not replace the string .Dq Li {} in the utility name or the utility arguments if it had preceding or following non-whitespace characters. This version replaces it no matter where in the utility name or arguments it appears. .Pp The .Fl E option was inspired by the equivalent .Xr grep 1 and .Xr sed 1 options. .Sh HISTORY A .Nm command appeared in .At v1 . .Sh BUGS The special characters used by .Nm are also special characters to many shell programs. In particular, the characters .Dq Li * , .Dq Li \&[ , .Dq Li \&] , .Dq Li \&? , .Dq Li \&( , .Dq Li \&) , .Dq Li \&! , .Dq Li \e and .Dq Li \&; may have to be escaped from the shell. .Pp As there is no delimiter separating options and file names or file names and the .Ar expression , it is difficult to specify files named .Pa -xdev or .Pa \&! . These problems are handled by the .Fl f option and the .Xr getopt 3 .Dq Fl Fl construct. .Pp The .Ic -delete primary does not interact well with other options that cause the file system tree traversal options to be changed. .Pp The .Ic -mindepth and .Ic -maxdepth primaries are actually global options (as documented above). They should probably be replaced by options which look like options. Index: stable/9/usr.bin/find =================================================================== --- stable/9/usr.bin/find (revision 279642) +++ stable/9/usr.bin/find (revision 279643) Property changes on: stable/9/usr.bin/find ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/usr.bin/find:r233456,248258,248849,279297 Index: stable/9/usr.bin/indent/indent.1 =================================================================== --- stable/9/usr.bin/indent/indent.1 (revision 279642) +++ stable/9/usr.bin/indent/indent.1 (revision 279643) @@ -1,565 +1,562 @@ .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" Copyright (c) 1976 Board of Trustees of the University of Illinois. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)indent.1 8.1 (Berkeley) 7/1/93 .\" $FreeBSD$ .\" .Dd March 3, 2012 .Dt INDENT 1 .Os .Sh NAME .Nm indent .Nd indent and format C program source .Sh SYNOPSIS .Nm .Op Ar input-file Op Ar output-file .Op Fl bacc | Fl nbacc .Op Fl bad | Fl nbad .Op Fl bap | Fl nbap .Bk -words .Op Fl ei | Fl ei .Op Fl eei | Fl eei .Op Fl bbb | Fl nbbb .Ek .Op Fl \&bc | Fl nbc .Op Fl \&bl .Op Fl \&br .Op Fl c Ns Ar n .Op Fl \&cd Ns Ar n .Bk -words .Op Fl cdb | Fl ncdb .Ek .Op Fl \&ce | Fl nce .Op Fl \&ci Ns Ar n .Op Fl cli Ns Ar n .Op Fl d Ns Ar n .Op Fl \&di Ns Ar n .Bk -words .Op Fl fbs | Fl nfbs .Op Fl fc1 | Fl nfc1 .Op Fl fcb | Fl nfcb .Ek .Op Fl i Ns Ar n .Op Fl \&ip | Fl nip .Op Fl l Ns Ar n .Op Fl \&lc Ns Ar n .Op Fl \&ldi Ns Ar n .Op Fl \&lp | Fl nlp .Op Fl npro .Op Fl pcs | Fl npcs .Op Fl psl | Fl npsl .Op Fl \&sc | Fl nsc .Bk -words .Op Fl sob | Fl nsob .Ek .Op Fl \&st .Op Fl \&ta .Op Fl troff .Op Fl ut | Fl nut .Op Fl v | Fl \&nv .Sh DESCRIPTION The .Nm utility is a .Em C program formatter. It reformats the .Em C program in the .Ar input-file according to the switches. The switches which can be specified are described below. They may appear before or after the file names. .Pp .Sy NOTE : If you only specify an .Ar input-file , the formatting is done `in-place', that is, the formatted file is written back into .Ar input-file and a backup copy of .Ar input-file is written in the current directory. If .Ar input-file is named .Sq Pa /blah/blah/file , the backup file is named .Sq Pa file.BAK . .Pp If .Ar output-file is specified, .Nm checks to make sure that it is different from .Ar input-file . .Pp The options listed below control the formatting style imposed by .Nm . .Bl -tag -width Op .It Fl bacc , nbacc If .Fl bacc is specified, a blank line is forced around every conditional compilation block. For example, in front of every #ifdef and after every #endif. Other blank lines surrounding such blocks will be swallowed. Default: .Fl nbacc . .It Fl bad , nbad If .Fl bad is specified, a blank line is forced after every block of declarations. Default: .Fl nbad . .It Fl bap , nbap If .Fl bap is specified, a blank line is forced after every procedure body. Default: .Fl nbap . .It Fl bbb , nbbb If .Fl bbb is specified, a blank line is forced before every block comment. Default: .Fl nbbb . .It Fl \&bc , nbc If .Fl \&bc is specified, then a newline is forced after each comma in a declaration. .Fl nbc turns off this option. Default: .Fl \&nbc . .It Fl \&br , \&bl Specifying .Fl \&bl lines-up compound statements like this: .Bd -literal -offset indent if (...) { code } .Ed .Pp Specifying .Fl \&br (the default) makes them look like this: .Bd -literal -offset indent if (...) { code } .Ed .Pp .It Fl c Ns Ar n The column in which comments on code start. The default is 33. .It Fl cd Ns Ar n The column in which comments on declarations start. The default is for these comments to start in the same column as those on code. .It Fl cdb , ncdb Enables (disables) the placement of comment delimiters on blank lines. With this option enabled, comments look like this: .Bd -literal -offset indent /* * this is a comment */ .Ed .Pp Rather than like this: .Bd -literal -offset indent /* this is a comment */ .Ed .Pp This only affects block comments, not comments to the right of code. The default is .Fl cdb . .It Fl ce , nce Enables (disables) forcing of `else's to cuddle up to the immediately preceding `}'. The default is .Fl \&ce . .It Fl \&ci Ns Ar n Sets the continuation indent to be .Ar n . Continuation lines will be indented that far from the beginning of the first line of the statement. Parenthesized expressions have extra indentation added to indicate the nesting, unless .Fl \&lp is in effect or the continuation indent is exactly half of the main indent. .Fl \&ci defaults to the same value as .Fl i . .It Fl cli Ns Ar n Causes case labels to be indented .Ar n tab stops to the right of the containing .Ic switch statement. .Fl cli0.5 causes case labels to be indented half a tab stop. The default is .Fl cli0 . .It Fl d Ns Ar n Controls the placement of comments which are not to the right of code. For example, .Fl \&d\&1 means that such comments are placed one indentation level to the left of code. Specifying the default .Fl \&d\&0 lines-up these comments with the code. See the section on comment indentation below. .It Fl \&di Ns Ar n Specifies the indentation, in character positions, of global variable names and all struct/union member names relative to the beginning of their type declaration. The default is .Fl di16 . .It Fl dj , ndj .Fl \&dj left justifies declarations. .Fl ndj indents declarations the same as code. The default is .Fl ndj . .It Fl \&ei , nei Enables (disables) special .Ic else-if processing. If it is enabled, an .Ic if following an .Ic else will have the same indentation as the preceding .Ic \&if statement. The default is .Fl ei . .It Fl eei , neei Enables (disables) extra indentation on continuation lines of the expression part of .Ic if and .Ic while statements. These continuation lines will be indented one extra level. The default is .Fl neei . .It Fl fbs , nfbs Enables (disables) splitting the function declaration and opening brace across two lines. The default is .Fl fbs . .It Fl fc1 , nfc1 Enables (disables) the formatting of comments that start in column 1. Often, comments whose leading `/' is in column 1 have been carefully hand formatted by the programmer. In such cases, .Fl nfc1 should be used. The default is .Fl fc1 . .It Fl fcb , nfcb Enables (disables) the formatting of block comments (ones that begin with `/*\\n'). Often, block comments have been not so carefully hand formatted by the programmer, but reformatting that would just change the line breaks is not wanted. In such cases, .Fl nfcb should be used. Block comments are then handled like box comments. The default is .Fl fcb . .It Fl i Ns Ar n The number of spaces for one indentation level. The default is 8. .It Fl \&ip , nip Enables (disables) the indentation of parameter declarations from the left margin. The default is .Fl \&ip . .It Fl l Ns Ar n Maximum length of an output line. The default is 78. .It Fl \&ldi Ns Ar n Specifies the indentation, in character positions, of local variable names relative to the beginning of their type declaration. The default is for local variable names to be indented by the same amount as global ones. .It Fl \&lp , nlp Lines-up code surrounded by parenthesis in continuation lines. If a line has a left paren which is not closed on that line, then continuation lines will be lined up to start at the character position just after the left paren. For example, here is how a piece of continued code looks with .Fl nlp in effect: .Bd -literal -offset indent p1 = first_procedure(second_procedure(p2, p3), \ \ third_procedure(p4, p5)); .Ed .Pp With .Fl lp in effect (the default) the code looks somewhat clearer: .Bd -literal -offset indent p1\ =\ first_procedure(second_procedure(p2,\ p3), \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5)); .Ed .Pp Inserting two more newlines we get: .Bd -literal -offset indent p1\ =\ first_procedure(second_procedure(p2, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3), \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5)); .Ed .It Fl npro Causes the profile files, .Sq Pa ./.indent.pro and .Sq Pa ~/.indent.pro , to be ignored. .It Fl pcs , npcs If true .Pq Fl pcs all procedure calls will have a space inserted between the name and the `('. The default is .Fl npcs . .It Fl psl , npsl If true .Pq Fl psl the names of procedures being defined are placed in column 1 \- their types, if any, will be left on the previous lines. The default is .Fl psl . .It Fl \&sc , nsc Enables (disables) the placement of asterisks (`*'s) at the left edge of all comments. The default is .Fl sc . .It Fl sob , nsob If .Fl sob is specified, indent will swallow optional blank lines. You can use this to get rid of blank lines after declarations. Default: .Fl nsob . .It Fl \&st Causes .Nm to take its input from stdin and put its output to stdout. .It Fl ta Automatically add all identifiers ending in "_t" to the list of type keywords. .It Fl T Ns Ar typename Adds .Ar typename to the list of type keywords. Names accumulate: .Fl T can be specified more than once. You need to specify all the typenames that appear in your program that are defined by .Ic typedef \- nothing will be harmed if you miss a few, but the program will not be formatted as nicely as it should. This sounds like a painful thing to have to do, but it is really a symptom of a problem in C: .Ic typedef causes a syntactic change in the language and .Nm cannot find all instances of .Ic typedef . .It Fl troff Causes .Nm to format the program for processing by .Xr troff 1 . It will produce a fancy listing in much the same spirit as .Xr vgrind 1 . If the output file is not specified, the default is standard output, rather than formatting in place. .It Fl ut , nut Enables (disables) the use of tab characters in the output. Tabs are assumed to be aligned on columns divisible by 8. The default is .Fl ut . .It Fl v , \&nv .Fl v turns on `verbose' mode; .Fl \&nv turns it off. When in verbose mode, .Nm reports when it splits one line of input into two or more lines of output, and gives some size statistics at completion. The default is .Fl \&nv . .El .Pp You may set up your own `profile' of defaults to .Nm by creating a file called .Pa .indent.pro in your login directory and/or the current directory and including whatever switches you like. A `.indent.pro' in the current directory takes precedence over the one in your login directory. If .Nm is run and a profile file exists, then it is read to set up the program's defaults. Switches on the command line, though, always override profile switches. The switches should be separated by spaces, tabs or newlines. .Pp .Ss Comments .Sq Em Box .Em comments . The .Nm utility assumes that any comment with a dash or star immediately after the start of comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars. Each line of such a comment is left unchanged, except that its indentation may be adjusted to account for the change in indentation of the first line of the comment. .Pp .Em Straight text . All other comments are treated as straight text. The .Nm utility fits as many words (separated by blanks, tabs, or newlines) on a line as possible. Blank lines break paragraphs. -.Pp .Ss Comment indentation If a comment is on a line with code it is started in the `comment column', which is set by the .Fl c Ns Ns Ar n command line parameter. Otherwise, the comment is started at .Ar n indentation levels less than where code is currently being placed, where .Ar n is specified by the .Fl d Ns Ns Ar n command line parameter. If the code on a line extends past the comment column, the comment starts further to the right, and the right margin may be automatically extended in extreme cases. -.Pp .Ss Preprocessor lines In general, .Nm leaves preprocessor lines alone. The only reformatting that it will do is to straighten up trailing comments. It leaves embedded comments alone. Conditional compilation .Pq Ic #ifdef...#endif is recognized and .Nm attempts to correctly compensate for the syntactic peculiarities introduced. -.Pp .Ss C syntax The .Nm utility understands a substantial amount about the syntax of C, but it has a `forgiving' parser. It attempts to cope with the usual sorts of incomplete and misformed syntax. In particular, the use of macros like: .Pp .Dl #define forever for(;;) .Pp is handled properly. .Sh ENVIRONMENT The .Nm utility uses the .Ev HOME environment variable. .Sh FILES .Bl -tag -width "./.indent.pro" -compact .It Pa ./.indent.pro profile file .It Pa ~/.indent.pro profile file .El .Sh HISTORY The .Nm command appeared in .Bx 4.2 . .Sh BUGS The .Nm utility has even more switches than .Xr ls 1 . .Pp A common mistake is to try to indent all the .Em C programs in a directory by typing: .Pp .Dl indent *.c .Pp This is probably a bug, not a feature. Index: stable/9/usr.bin/indent =================================================================== --- stable/9/usr.bin/indent (revision 279642) +++ stable/9/usr.bin/indent (revision 279643) Property changes on: stable/9/usr.bin/indent ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/usr.bin/indent:r233456,248258,248849,279297 Index: stable/9/usr.bin/jot/jot.1 =================================================================== --- stable/9/usr.bin/jot/jot.1 (revision 279642) +++ stable/9/usr.bin/jot/jot.1 (revision 279643) @@ -1,327 +1,326 @@ .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)jot.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" .Dd June 2, 2010 .Dt JOT 1 .Os .Sh NAME .Nm jot .Nd print sequential or random data .Sh SYNOPSIS .Nm .Op Fl cnr .Op Fl b Ar word .Op Fl w Ar word .Op Fl s Ar string .Op Fl p Ar precision .Op Ar reps Op Ar begin Op Ar end Op Ar s .Sh DESCRIPTION The .Nm utility is used to print out increasing, decreasing, random, or redundant data, usually numbers, one per line. .Pp The following options are available: .Bl -tag -width indent .It Fl r Generate random data instead of the default sequential data. .It Fl b Ar word Just print .Ar word repetitively. .It Fl w Ar word Print .Ar word with the generated data appended to it. Octal, hexadecimal, exponential, .Tn ASCII , zero padded, and right-adjusted representations are possible by using the appropriate .Xr printf 3 conversion specification inside .Ar word , in which case the data are inserted rather than appended. .It Fl c This is an abbreviation for .Fl w Ar %c . .It Fl s Ar string Print data separated by .Ar string . Normally, newlines separate data. .It Fl n Do not print the final newline normally appended to the output. .It Fl p Ar precision Print only as many digits or characters of the data as indicated by the integer .Ar precision . In the absence of .Fl p , the precision is the greater of the precisions of .Ar begin and .Ar end . The .Fl p option is overridden by whatever appears in a .Xr printf 3 conversion following .Fl w . .El .Pp The last four arguments indicate, respectively, the number of data, the lower bound, the upper bound, and the step size or, for random data, the seed. While at least one of them must appear, any of the other three may be omitted, and will be considered as such if given as .Fl "" or as an empty string. Any three of these arguments determines the fourth. If four are specified and the given and computed values of .Ar reps conflict, the lower value is used. If fewer than three are specified, defaults are assigned left to right, except for .Ar s , which assumes a default of 1 or -1 if both .Ar begin and .Ar end are given. .Pp Defaults for the four arguments are, respectively, 100, 1, 100, and 1, except that when random data are requested, the seed, .Ar s , is picked randomly. The .Ar reps argument is expected to be an unsigned integer, and if given as zero is taken to be infinite. The .Ar begin and .Ar end arguments may be given as real numbers or as characters representing the corresponding value in .Tn ASCII . The last argument must be a real number. .Pp Random numbers are obtained through .Xr arc4random 3 when no seed is specified, and through .Xr random 3 when a seed is given. When .Nm is asked to generate random integers or characters with begin and end values in the range of the random number generator function and no format is specified with one of the .Fl w , .Fl b , or .Fl p options, .Nm will arrange for all the values in the range to appear in the output with an equal probability. In all other cases be careful to ensure that the output format's rounding or truncation will not skew the distribution of output values in an unintended way. .Pp The name .Nm derives in part from .Nm iota , a function in APL. .Ss Rounding and truncation The .Nm utility uses double precision floating point arithmetic internally. Before printing a number, it is converted depending on the output format used. .Pp If no output format is specified or the output format is a floating point format .Po .Sq E , .Sq G , .Sq e , .Sq f , or .Sq g .Pc , the value is rounded using the .Xr printf 3 function, taking into account the requested precision. .Pp If the output format is an integer format .Po .Sq D , .Sq O , .Sq U , .Sq X , .Sq c , .Sq d , .Sq i , .Sq o , .Sq u , or .Sq x .Pc , the value is converted to an integer value by truncation. .Pp As an illustration, consider the following command: .Bd -literal -offset indent $ jot 6 1 10 0.5 1 2 2 2 3 4 .Ed .Pp By requesting an explicit precision of 1, the values generated before rounding can be seen. The .5 values are rounded down if the integer part is even, up otherwise. .Bd -literal -offset indent $ jot -p 1 6 1 10 0.5 1.0 1.5 2.0 2.5 3.0 3.5 .Ed .Pp By offsetting the values slightly, the values generated by the following command are always rounded down: .Bd -literal -offset indent $ jot -p 0 6 .9999999999 10 0.5 1 1 2 2 3 3 .Ed .Pp Another way of achieving the same result is to force truncation by specifying an integer format: .Bd -literal -offset indent $ jot -w %d 6 1 10 0.5 .Ed -.Pp .Sh EXIT STATUS .Ex -std .Sh EXAMPLES The command .Dl jot - 1 10 .Pp prints the integers from 1 to 10, while the command .Dl jot 21 -1 1.00 .Pp prints 21 evenly spaced numbers increasing from -1 to 1. The .Tn ASCII character set is generated with .Dl jot -c 128 0 .Pp and the strings xaa through xaz with .Dl jot -w xa%c 26 a .Pp while 20 random 8-letter strings are produced with .Dl "jot -r -c 160 a z | rs -g 0 8" .Pp Infinitely many .Em yes Ns 's may be obtained through .Dl jot -b yes 0 .Pp and thirty .Xr ed 1 substitution commands applying to lines 2, 7, 12, etc.\& is the result of .Dl jot -w %ds/old/new/ 30 2 - 5 .Pp The stuttering sequence 9, 9, 8, 8, 7, etc.\& can be produced by truncating the output precision and a suitable choice of step size, as in .Dl jot -w %d - 9.5 0 -.5 .Pp and a file containing exactly 1024 bytes is created with .Dl jot -b x 512 > block .Pp Finally, to set tabs four spaces apart starting from column 10 and ending in column 132, use .Dl expand -`jot -s, - 10 132 4` .Pp and to print all lines 80 characters or longer, .Dl grep `jot -s \&"\&" -b \&. 80` .Sh DIAGNOSTICS The following diagnostic messages deserve special explanation: .Bl -diag .It "illegal or unsupported format '%s'" The requested conversion format specifier for .Xr printf 3 was not of the form .Dl %[#][ ][{+,-}][0-9]*[.[0-9]*]? where .Dq ?\& must be one of .Dl [l]{d,i,o,u,x} or .Dl {c,e,f,g,D,E,G,O,U,X} .It "range error in conversion" A value to be printed fell outside the range of the data type associated with the requested output format. .It "too many conversions" More than one conversion format specifier has been supplied, but only one is allowed. .El .Sh SEE ALSO .Xr ed 1 , .Xr expand 1 , .Xr rs 1 , .Xr seq 1 , .Xr yes 1 , .Xr arc4random 3 , .Xr printf 3 , .Xr random 3 .Sh HISTORY The .Nm utility first appeared in .Bx 4.2 . Index: stable/9/usr.bin/setchannel/setchannel.1 =================================================================== --- stable/9/usr.bin/setchannel/setchannel.1 (revision 279642) +++ stable/9/usr.bin/setchannel/setchannel.1 (revision 279643) @@ -1,104 +1,103 @@ .\"- .\" Copyright (C) 2004-2006 The FreeBSD Project. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $Id: cxm.4,v 1.1 2004/10/16 00:12:35 mavetju Exp $ .\" $FreeBSD$ .\" .Dd November 30, 2006 .Dt PVR250-SETCHANNEL 1 .Os .Sh NAME .Nm pvr250-setchannel .Nd Hauppage PVR250/350 channel selector .Sh SYNOPSIS .Cd pvr250-setchannel [-a {on | off}] [-c | -r | -s | -t] [-g geom] [-m channel_set] [channel | freq] -.Pp .Sh DESCRIPTION .Nm provides support for selecting channels on Hauppauge WinTV cards, including the PVR 150, PVR 250, PVR 350 and PVR 500. .Pp The following options are available: .Bl -tag -width indent .It Fl a Cm on Enable AFC. .It Fl a Cm off Disable AFC. .It Fl c Select composite input. .It Fl d Select the tuner unit number. This is appended to the base device file name .Pa /dev/cxm to form a device name such as .Pa /dev/cxm0 or .Pa /dev/cxm1 . .It Fl r Select radio input. .It Fl s Select svideo input. .It Fl t Select tuner. .It Fl g Cm geom Select geometry. The first resolution is for NTSC, the second for PAL. .Pp VCD: 352x240 or 352x288 SVCD: 480x480 or 480x576 DVD (half D1): 352x480 or 352x576 DVD (full D1): 720x480 or 720x576 .It Fl m Cm channel-set Select channel set and system. .Pp 0 = Tuner Default 1 = US Broadcast (NTSC) 2 = US Cable (NTSC) 4 = Western Europe (PAL) 5 = Japan Broadcast (NTSC) 6 = Japan Cable (NTSC) 8 = Australia (PAL) 9 = France (SECAM) .It Cm channel Channel number to set. .It Cm freq Frequency in MHz (must include decimal point). .El .Sh SEE ALSO .Xr cxm 4 , .Xr bktr 4 , .Xr meteor 4 .Sh HISTORY The .Nm program first appeared in the -multimedia mailing-list in January 2004. The .Nm program first appeared in the FreeBSD Ports collection in October 2004. .Sh AUTHORS .An -nosplit This program is made by .An John Wehle .Pp This man page is made by .An Edwin Groothuis Index: stable/9/usr.bin/tr/tr.1 =================================================================== --- stable/9/usr.bin/tr/tr.1 (revision 279642) +++ stable/9/usr.bin/tr/tr.1 (revision 279643) @@ -1,423 +1,421 @@ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" the Institute of Electrical and Electronics Engineers, Inc. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)tr.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" .Dd October 13, 2006 .Dt TR 1 .Os .Sh NAME .Nm tr .Nd translate characters .Sh SYNOPSIS .Nm .Op Fl Ccsu .Ar string1 string2 .Nm .Op Fl Ccu .Fl d .Ar string1 .Nm .Op Fl Ccu .Fl s .Ar string1 .Nm .Op Fl Ccu .Fl ds .Ar string1 string2 .Sh DESCRIPTION The .Nm utility copies the standard input to the standard output with substitution or deletion of selected characters. .Pp The following options are available: .Bl -tag -width Ds .It Fl C Complement the set of characters in .Ar string1 , that is .Dq Fl C Li ab includes every character except for .Ql a and .Ql b . .It Fl c Same as .Fl C but complement the set of values in .Ar string1 . .It Fl d Delete characters in .Ar string1 from the input. .It Fl s Squeeze multiple occurrences of the characters listed in the last operand (either .Ar string1 or .Ar string2 ) in the input into a single instance of the character. This occurs after all deletion and translation is completed. .It Fl u Guarantee that any output is unbuffered. .El .Pp In the first synopsis form, the characters in .Ar string1 are translated into the characters in .Ar string2 where the first character in .Ar string1 is translated into the first character in .Ar string2 and so on. If .Ar string1 is longer than .Ar string2 , the last character found in .Ar string2 is duplicated until .Ar string1 is exhausted. .Pp In the second synopsis form, the characters in .Ar string1 are deleted from the input. .Pp In the third synopsis form, the characters in .Ar string1 are compressed as described for the .Fl s option. .Pp In the fourth synopsis form, the characters in .Ar string1 are deleted from the input, and the characters in .Ar string2 are compressed as described for the .Fl s option. .Pp The following conventions can be used in .Ar string1 and .Ar string2 to specify sets of characters: .Bl -tag -width [:equiv:] .It character Any character not described by one of the following conventions represents itself. .It \eoctal A backslash followed by 1, 2 or 3 octal digits represents a character with that encoded value. To follow an octal sequence with a digit as a character, left zero-pad the octal sequence to the full 3 octal digits. .It \echaracter A backslash followed by certain special characters maps to special values. -.Pp .Bl -column "\ea" .It "\ea .It "\eb .It "\ef .It "\en .It "\er .It "\et .It "\ev .El .Pp A backslash followed by any other character maps to that character. .It c-c For non-octal range endpoints represents the range of characters between the range endpoints, inclusive, in ascending order, as defined by the collation sequence. If either or both of the range endpoints are octal sequences, it represents the range of specific coded values between the range endpoints, inclusive. .Pp .Bf Em See the .Sx COMPATIBILITY section below for an important note regarding differences in the way the current implementation interprets range expressions differently from previous implementations. .Ef .It [:class:] Represents all characters belonging to the defined character class. Class names are: -.Pp .Bl -column "phonogram" .It "alnum .It "alpha .It "blank .It "cntrl .It "digit .It "graph .It "ideogram .It "lower .It "phonogram .It "print .It "punct .It "rune .It "space .It "special .It "upper .It "xdigit .El .Pp .\" All classes may be used in .\" .Ar string1 , .\" and in .\" .Ar string2 .\" when both the .\" .Fl d .\" and .\" .Fl s .\" options are specified. .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in .\" .Ar string2 .\" and then only when the corresponding class (``upper'' for ``lower'' .\" and vice-versa) is specified in the same relative position in .\" .Ar string1 . .\" .Pp When .Dq Li [:lower:] appears in .Ar string1 and .Dq Li [:upper:] appears in the same relative position in .Ar string2 , it represents the characters pairs from the .Dv toupper mapping in the .Ev LC_CTYPE category of the current locale. When .Dq Li [:upper:] appears in .Ar string1 and .Dq Li [:lower:] appears in the same relative position in .Ar string2 , it represents the characters pairs from the .Dv tolower mapping in the .Ev LC_CTYPE category of the current locale. .Pp With the exception of case conversion, characters in the classes are in unspecified order. .Pp For specific information as to which .Tn ASCII characters are included in these classes, see .Xr ctype 3 and related manual pages. .It [=equiv=] Represents all characters belonging to the same equivalence class as .Ar equiv , ordered by their encoded values. .It [#*n] Represents .Ar n repeated occurrences of the character represented by .Ar # . This expression is only valid when it occurs in .Ar string2 . If .Ar n is omitted or is zero, it is be interpreted as large enough to extend .Ar string2 sequence to the length of .Ar string1 . If .Ar n has a leading zero, it is interpreted as an octal value, otherwise, it is interpreted as a decimal value. .El .Sh ENVIRONMENT The .Ev LANG , LC_ALL , LC_CTYPE and .Ev LC_COLLATE environment variables affect the execution of .Nm as described in .Xr environ 7 . .Sh EXIT STATUS .Ex -std .Sh EXAMPLES The following examples are shown as given to the shell: .Pp Create a list of the words in file1, one per line, where a word is taken to be a maximal string of letters. .Pp .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1" .Pp Translate the contents of file1 to upper-case. .Pp .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1" .Pp (This should be preferred over the traditional .Ux idiom of .Dq Li "tr a-z A-Z" , since it works correctly in all locales.) .Pp Strip out non-printable characters from file1. .Pp .D1 Li "tr -cd \*q[:print:]\*q < file1" .Pp Remove diacritical marks from all accented variants of the letter .Ql e : .Pp .Dl "tr \*q[=e=]\*q \*qe\*q" .Sh COMPATIBILITY Previous .Fx implementations of .Nm did not order characters in range expressions according to the current locale's collation order, making it possible to convert unaccented Latin characters (esp.\& as found in English text) from upper to lower case using the traditional .Ux idiom of .Dq Li "tr A-Z a-z" . Since .Nm now obeys the locale's collation order, this idiom may not produce correct results when there is not a 1:1 mapping between lower and upper case, or when the order of characters within the two cases differs. As noted in the .Sx EXAMPLES section above, the character class expressions .Dq Li [:lower:] and .Dq Li [:upper:] should be used instead of explicit character ranges like .Dq Li a-z and .Dq Li A-Z . .Pp System V has historically implemented character ranges using the syntax .Dq Li [c-c] instead of the .Dq Li c-c used by historic .Bx implementations and standardized by POSIX. System V shell scripts should work under this implementation as long as the range is intended to map in another range, i.e., the command .Dq Li "tr [a-z] [A-Z]" will work as it will map the .Ql \&[ character in .Ar string1 to the .Ql \&[ character in .Ar string2 . However, if the shell script is deleting or squeezing characters as in the command .Dq Li "tr -d [a-z]" , the characters .Ql \&[ and .Ql \&] will be included in the deletion or compression list which would not have happened under a historic System V implementation. Additionally, any scripts that depended on the sequence .Dq Li a-z to represent the three characters .Ql a , .Ql \- and .Ql z will have to be rewritten as .Dq Li a\e-z . .Pp The .Nm utility has historically not permitted the manipulation of NUL bytes in its input and, additionally, stripped NUL's from its input stream. This implementation has removed this behavior as a bug. .Pp The .Nm utility has historically been extremely forgiving of syntax errors, for example, the .Fl c and .Fl s options were ignored unless two strings were specified. This implementation will not permit illegal syntax. .Sh STANDARDS The .Nm utility conforms to .St -p1003.1-2001 . The .Dq ideogram , .Dq phonogram , .Dq rune , and .Dq special character classes are extensions. .Pp It should be noted that the feature wherein the last character of .Ar string2 is duplicated if .Ar string2 has less characters than .Ar string1 is permitted by POSIX but is not required. Shell scripts attempting to be portable to other POSIX systems should use the .Dq Li [#*] convention instead of relying on this behavior. The .Fl u option is an extension to the .St -p1003.1-2001 standard. Index: stable/9/usr.bin/unifdef/unifdef.1 =================================================================== --- stable/9/usr.bin/unifdef/unifdef.1 (revision 279642) +++ stable/9/usr.bin/unifdef/unifdef.1 (revision 279643) @@ -1,415 +1,489 @@ .\" Copyright (c) 1985, 1991, 1993 .\" The Regents of the University of California. All rights reserved. -.\" Copyright (c) 2002 - 2010 Tony Finch . All rights reserved. +.\" Copyright (c) 2002 - 2013 Tony Finch . All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Dave Yost. It was rewritten to support ANSI C by Tony Finch. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd March 11, 2010 -.Dt UNIFDEF 1 -.Os +.Dd January 7, 2014 +.Dt UNIFDEF 1 PRM +.Os " " .Sh NAME .Nm unifdef , unifdefall .Nd remove preprocessor conditionals from code .Sh SYNOPSIS .Nm -.Op Fl bBcdeKknsStV +.Op Fl bBcdehKkmnsStV .Op Fl I Ns Ar path -.Op Fl D Ns Ar sym Ns Op = Ns Ar val -.Op Fl U Ns Ar sym -.Op Fl iD Ns Ar sym Ns Op = Ns Ar val -.Op Fl iU Ns Ar sym +.Op Fl [i]D Ns Ar sym Ns Op = Ns Ar val +.Op Fl [i]U Ns Ar sym .Ar ... +.Op Fl f Ar defile +.Op Fl x Bro Ar 012 Brc +.Op Fl M Ar backext .Op Fl o Ar outfile -.Op Ar infile +.Op Ar infile ... .Nm unifdefall .Op Fl I Ns Ar path .Ar ... .Ar file .Sh DESCRIPTION The .Nm utility selectively processes conditional .Xr cpp 1 directives. It removes from a file both the directives and any additional text that they specify should be removed, while otherwise leaving the file alone. .Pp The .Nm utility acts on -.Ic #if , #ifdef , #ifndef , #elif , #else , +.Ic #if , #ifdef , #ifndef , +.Ic #elif , #else , and .Ic #endif -lines. -A directive is only processed -if the symbols specified on the command line are sufficient to allow -.Nm -to get a definite value for its control expression. +lines, +using macros specified in +.Fl D +and +.Fl U +command line options or in +.Fl f +definitions files. +A directive is processed +if the macro specifications are sufficient to provide +a definite value for its control expression. If the result is false, the directive and the following lines under its control are removed. If the result is true, only the directive is removed. An .Ic #ifdef or .Ic #ifndef directive is passed through unchanged -if its controlling symbol is not specified on the command line. +if its controlling macro is not specified. Any .Ic #if or .Ic #elif control expression that has an unknown value or that .Nm cannot parse is passed through unchanged. By default, .Nm ignores .Ic #if and .Ic #elif lines with constant expressions; it can be told to process them by specifying the .Fl k flag on the command line. .Pp It understands a commonly-used subset of the expression syntax for .Ic #if and .Ic #elif lines: integer constants, -integer values of symbols defined on the command line, +integer values of macros defined on the command line, the .Fn defined operator, the operators -.Ic \&! , < , > , <= , >= , == , != , && , || , +.Ic \&! , < , > , +.Ic <= , >= , == , != , +.Ic && , || , and parenthesized expressions. A kind of .Dq "short circuit" evaluation is used for the .Ic && operator: if either operand is definitely false then the result is false, even if the value of the other operand is unknown. Similarly, if either operand of .Ic || is definitely true then the result is true. .Pp -In most cases, the +When evaluating an expression, .Nm -utility does not distinguish between object-like macros -(without arguments) and function-like arguments (with arguments). -If a macro is not explicitly defined, or is defined with the +does not expand macros first. +The value of a macro must be a simple number, +not an expression. +A limited form of indirection is allowed, +where one macro's value is the name of another. +.Pp +In most cases, +.Nm +does not distinguish between object-like macros +(without arguments) and function-like macros (with arguments). +A function-like macro invocation can appear in +.Ic #if +and +.Ic #elif +control expressions. +If the macro is not explicitly defined, +or is defined with the .Fl D -flag on the command-line, its arguments are ignored. +flag on the command-line, +or with +.Ic #define +in a +.Fl f +definitions file, +its arguments are ignored. If a macro is explicitly undefined on the command line with the .Fl U -flag, it may not have any arguments since this leads to a syntax error. +flag, +or with +.Ic #undef +in a +.Fl f +definitions file, +it may not have any arguments since this leads to a syntax error. .Pp The .Nm utility understands just enough about C to know when one of the directives is inactive because it is inside a comment, or affected by a backslash-continued line. It spots unusually-formatted preprocessor directives and knows when the layout is too odd for it to handle. .Pp A script called .Nm unifdefall can be used to remove all conditional .Xr cpp 1 directives from a file. It uses .Nm Fl s and .Nm cpp Fl dM -to get lists of all the controlling symbols +to get lists of all the controlling macros and their definitions (or lack thereof), then invokes .Nm with appropriate arguments to process the file. .Sh OPTIONS -.Pp .Bl -tag -width indent -compact .It Fl D Ns Ar sym Ns = Ns Ar val -Specify that a symbol is defined to a given value -which is used when evaluating -.Ic #if -and -.Ic #elif -control expressions. +Specify that a macro is defined to a given value. .Pp .It Fl D Ns Ar sym -Specify that a symbol is defined to the value 1. +Specify that a macro is defined to the value 1. .Pp .It Fl U Ns Ar sym -Specify that a symbol is undefined. -If the same symbol appears in more than one argument, +Specify that a macro is undefined. +.Pp +If the same macro appears in more than one argument, the last occurrence dominates. .Pp +.It Fl iD Ns Ar sym Ns Op = Ns Ar val +.It Fl iU Ns Ar sym +C strings, comments, +and line continuations +are ignored within +.Ic #ifdef +and +.Ic #ifndef +blocks +controlled by macros +specified with these options. +.Pp +.It Fl f Ar defile +The file +.Ar defile +contains +.Ic #define +and +.Ic #undef +preprocessor directives, +which have the same effect as the corresponding +.Fl D +and +.Fl U +command-line arguments. +You can have multiple +.Fl f +arguments and mix them with +.Fl D +and +.Fl U +arguments; +later options override earlier ones. +.Pp +Each directive must be on a single line. +Object-like macro definitions (without arguments) +are set to the given value. +Function-like macro definitions (with arguments) +are treated as if they are set to 1. +.Pp .It Fl b Replace removed lines with blank lines instead of deleting them. Mutually exclusive with the .Fl B option. .Pp .It Fl B Compress blank lines around a deleted section. Mutually exclusive with the .Fl b option. .Pp .It Fl c -If the -.Fl c -flag is specified, -then the operation of -.Nm -is complemented, -i.e., the lines that would have been removed or blanked +Complement, +i.e., lines that would have been removed or blanked are retained and vice versa. .Pp .It Fl d Turn on printing of debugging messages. .Pp .It Fl e -Because -.Nm -processes its input one line at a time, -it cannot remove preprocessor directives that span more than one line. -The most common example of this is a directive with a multi-line -comment hanging off its right hand end. By default, -if .Nm -has to process such a directive, -it will complain that the line is too obfuscated. +will report an error if it needs to remove +a preprocessor directive that spans more than one line, +for example, if it has a multi-line +comment hanging off its right hand end. The .Fl e -option changes the behaviour so that, -where possible, -such lines are left unprocessed instead of reporting an error. +flag makes it ignore the line instead. .Pp +.It Fl h +Print help. +.Pp +.It Fl I Ns Ar path +Specifies to +.Nm unifdefall +an additional place to look for +.Ic #include +files. +This option is ignored by +.Nm +for compatibility with +.Xr cpp 1 +and to simplify the implementation of +.Nm unifdefall . +.Pp .It Fl K Always treat the result of .Ic && and .Ic || operators as unknown if either operand is unknown, instead of short-circuiting when unknown operands can't affect the result. This option is for compatibility with older versions of .Nm . .Pp .It Fl k Process .Ic #if and .Ic #elif lines with constant expressions. By default, sections controlled by such lines are passed through unchanged because they typically start .Dq Li "#if 0" and are used as a kind of comment to sketch out future or past development. It would be rude to strip them out, just as it would be for normal comments. .Pp +.It Fl m +Modify one or more input files in place. +.Pp +.It Fl M Ar backext +Modify input files in place, and keep backups of the original files by +appending the +.Ar backext +to the input filenames. +.Pp .It Fl n Add .Li #line directives to the output following any deleted lines, so that errors produced when compiling the output file correspond to line numbers in the input file. .Pp .It Fl o Ar outfile Write output to the file .Ar outfile -instead of the standard output. -If -.Ar outfile -is the same as the input file, -the output is written to a temporary file -which is renamed into place when -.Nm -completes successfully. +instead of the standard output when processing a single file. .Pp .It Fl s -Instead of processing the input file as usual, +Instead of processing an input file as usual, this option causes .Nm -to produce a list of symbols that appear in expressions -that -.Nm -understands. -It is useful in conjunction with the -.Fl dM -option of -.Xr cpp 1 -for creating -.Nm -command lines. +to produce a list of macros that are used in +preprocessor directive controlling expressions. .Pp .It Fl S Like the .Fl s -option, but the nesting depth of each symbol is also printed. +option, but the nesting depth of each macro is also printed. This is useful for working out the number of possible combinations -of interdependent defined/undefined symbols. +of interdependent defined/undefined macros. .Pp .It Fl t -Disables parsing for C comments +Disables parsing for C strings, comments, and line continuations, which is useful for plain text. -.Pp -.It Fl iD Ns Ar sym Ns Op = Ns Ar val -.It Fl iU Ns Ar sym -Ignore -.Ic #ifdef Ns s . -If your C code uses -.Ic #ifdef Ns s -to delimit non-C lines, -such as comments -or code which is under construction, -then you must tell -.Nm -which symbols are used for that purpose so that it will not try to parse -comments -and line continuations -inside those -.Ic #ifdef Ns s . -You can specify ignored symbols with -.Fl iD Ns Ar sym Ns Oo = Ns Ar val Oc +This is a blanket version of the +.Fl iD and -.Fl iU Ns Ar sym -similar to -.Fl D Ns Ar sym Ns Op = Ns Ar val -and -.Fl U Ns Ar sym -above. +.Fl iU +flags. .Pp -.It Fl I Ns Ar path -Specifies to -.Nm unifdefall -an additional place to look for -.Ic #include -files. -This option is ignored by -.Nm -for compatibility with -.Xr cpp 1 -and to simplify the implementation of -.Nm unifdefall . -.Pp .It Fl V Print version details. +.Pp +.It Fl x Bro Ar 012 Brc +Set exit status mode to zero, one, or two. +See the +.Sx EXIT STATUS +section below for details. .El .Pp The .Nm -utility copies its output to -.Em stdout -and will take its input from +utility takes its input from .Em stdin -if no +if there are no .Ar file -argument is given. +arguments. +You must use the +.Fl m +or +.Fl M +options if there are multiple input files. +You can specify inut from stdin or output to stdout with +.Ql - . .Pp The .Nm utility works nicely with the .Fl D Ns Ar sym option of .Xr diff 1 . .Sh EXIT STATUS -The +In normal usage the .Nm -utility exits 0 if the output is an exact copy of the input, -1 if not, and 2 if in trouble. +utility's exit status depends on the mode set using the +.Fl x +option. +.Pp +If the exit mode is zero (the default) then +.Nm +exits with status 0 if the output is an exact copy of the input, +or with status 1 if the output differs. +.Pp +If the exit mode is one, +.Nm +exits with status 1 if the output is unmodified +or 0 if it differs. +.Pp +If the exit mode is two, +.Nm +exits with status zero in both cases. +.Pp +In all exit modes, +.Nm +exits with status 2 if there is an error. +.Pp +The exit status is 0 if the +.Fl h +or +.Fl V +command line options are given. .Sh DIAGNOSTICS .Bl -item .It Too many levels of nesting. .It Inappropriate .Ic #elif , .Ic #else or .Ic #endif . .It Obfuscated preprocessor control line. .It Premature .Tn EOF (with the line number of the most recent unterminated .Ic #if ) . .It .Tn EOF in comment. .El .Sh SEE ALSO .Xr cpp 1 , .Xr diff 1 +.Pp +The unifdef home page is +.Pa http://dotat.at/prog/unifdef .Sh HISTORY The .Nm command appeared in .Bx 2.9 . .Tn ANSI\~C support was added in .Fx 4.7 . .Sh AUTHORS The original implementation was written by .An Dave Yost Aq Dave@Yost.com . .An Tony Finch Aq dot@dotat.at rewrote it to support .Tn ANSI\~C . .Sh BUGS Expression evaluation is very limited. .Pp -Preprocessor control lines split across more than one physical line +Handling one line at a time means +preprocessor directives split across more than one physical line (because of comments or backslash-newline) cannot be handled in every situation. .Pp Trigraphs are not recognized. .Pp -There is no support for symbols with different definitions at +There is no support for macros with different definitions at different points in the source file. .Pp The text-mode and ignore functionality does not correspond to modern .Xr cpp 1 behaviour. Index: stable/9/usr.bin/unifdef/unifdef.c =================================================================== --- stable/9/usr.bin/unifdef/unifdef.c (revision 279642) +++ stable/9/usr.bin/unifdef/unifdef.c (revision 279643) @@ -1,1235 +1,1571 @@ /* - * Copyright (c) 2002 - 2011 Tony Finch + * Copyright (c) 2002 - 2014 Tony Finch * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * unifdef - remove ifdef'ed lines * * This code was derived from software contributed to Berkeley by Dave Yost. * It was rewritten to support ANSI C by Tony Finch. The original version * of unifdef carried the 4-clause BSD copyright licence. None of its code * remains in this version (though some of the names remain) so it now * carries a more liberal licence. * * Wishlist: * provide an option which will append the name of the * appropriate symbol after #else's and #endif's * provide an option which will check symbols after * #else's and #endif's to see that they match their * corresponding #ifdef or #ifndef * * These require better buffer handling, which would also make * it possible to handle all "dodgy" directives correctly. */ -#include -#include +#include "unifdef.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const char copyright[] = - "@(#) $Version: unifdef-2.5.6.21f1388 $\n" +static const char copyright[] = + "@(#) $Version: unifdef-2.10 $\n" "@(#) $FreeBSD$\n" "@(#) $Author: Tony Finch (dot@dotat.at) $\n" "@(#) $URL: http://dotat.at/prog/unifdef $\n" ; /* types of input lines: */ typedef enum { LT_TRUEI, /* a true #if with ignore flag */ LT_FALSEI, /* a false #if with ignore flag */ LT_IF, /* an unknown #if */ LT_TRUE, /* a true #if */ LT_FALSE, /* a false #if */ LT_ELIF, /* an unknown #elif */ LT_ELTRUE, /* a true #elif */ LT_ELFALSE, /* a false #elif */ LT_ELSE, /* #else */ LT_ENDIF, /* #endif */ LT_DODGY, /* flag: directive is not on one line */ LT_DODGY_LAST = LT_DODGY + LT_ENDIF, LT_PLAIN, /* ordinary line */ LT_EOF, /* end of file */ LT_ERROR, /* unevaluable #if */ LT_COUNT } Linetype; static char const * const linetype_name[] = { "TRUEI", "FALSEI", "IF", "TRUE", "FALSE", "ELIF", "ELTRUE", "ELFALSE", "ELSE", "ENDIF", "DODGY TRUEI", "DODGY FALSEI", "DODGY IF", "DODGY TRUE", "DODGY FALSE", "DODGY ELIF", "DODGY ELTRUE", "DODGY ELFALSE", "DODGY ELSE", "DODGY ENDIF", "PLAIN", "EOF", "ERROR" }; +#define linetype_if2elif(lt) ((Linetype)(lt - LT_IF + LT_ELIF)) +#define linetype_2dodgy(lt) ((Linetype)(lt + LT_DODGY)) + /* state of #if processing */ typedef enum { IS_OUTSIDE, IS_FALSE_PREFIX, /* false #if followed by false #elifs */ IS_TRUE_PREFIX, /* first non-false #(el)if is true */ IS_PASS_MIDDLE, /* first non-false #(el)if is unknown */ IS_FALSE_MIDDLE, /* a false #elif after a pass state */ IS_TRUE_MIDDLE, /* a true #elif after a pass state */ IS_PASS_ELSE, /* an else after a pass state */ IS_FALSE_ELSE, /* an else after a true state */ IS_TRUE_ELSE, /* an else after only false states */ IS_FALSE_TRAILER, /* #elifs after a true are false */ IS_COUNT } Ifstate; static char const * const ifstate_name[] = { "OUTSIDE", "FALSE_PREFIX", "TRUE_PREFIX", "PASS_MIDDLE", "FALSE_MIDDLE", "TRUE_MIDDLE", "PASS_ELSE", "FALSE_ELSE", "TRUE_ELSE", "FALSE_TRAILER" }; /* state of comment parser */ typedef enum { NO_COMMENT = false, /* outside a comment */ C_COMMENT, /* in a comment like this one */ CXX_COMMENT, /* between // and end of line */ STARTING_COMMENT, /* just after slash-backslash-newline */ FINISHING_COMMENT, /* star-backslash-newline in a C comment */ CHAR_LITERAL, /* inside '' */ STRING_LITERAL /* inside "" */ } Comment_state; static char const * const comment_name[] = { "NO", "C", "CXX", "STARTING", "FINISHING", "CHAR", "STRING" }; /* state of preprocessor line parser */ typedef enum { LS_START, /* only space and comments on this line */ LS_HASH, /* only space, comments, and a hash */ LS_DIRTY /* this line can't be a preprocessor line */ } Line_state; static char const * const linestate_name[] = { "START", "HASH", "DIRTY" }; /* * Minimum translation limits from ISO/IEC 9899:1999 5.2.4.1 */ #define MAXDEPTH 64 /* maximum #if nesting */ #define MAXLINE 4096 /* maximum length of line */ -#define MAXSYMS 4096 /* maximum number of symbols */ +#define MAXSYMS 16384 /* maximum number of symbols */ /* * Sometimes when editing a keyword the replacement text is longer, so * we leave some space at the end of the tline buffer to accommodate this. */ #define EDITSLOP 10 /* - * For temporary filenames - */ -#define TEMPLATE "unifdef.XXXXXX" - -/* * Globals. */ static bool compblank; /* -B: compress blank lines */ static bool lnblank; /* -b: blank deleted lines */ static bool complement; /* -c: do the complement */ static bool debugging; /* -d: debugging reports */ +static bool inplace; /* -m: modify in place */ static bool iocccok; /* -e: fewer IOCCC errors */ static bool strictlogic; /* -K: keep ambiguous #ifs */ static bool killconsts; /* -k: eval constant #ifs */ static bool lnnum; /* -n: add #line directives */ static bool symlist; /* -s: output symbol list */ static bool symdepth; /* -S: output symbol depth */ static bool text; /* -t: this is a text file */ static const char *symname[MAXSYMS]; /* symbol name */ static const char *value[MAXSYMS]; /* -Dsym=value */ static bool ignore[MAXSYMS]; /* -iDsym or -iUsym */ static int nsyms; /* number of symbols */ static FILE *input; /* input file pointer */ static const char *filename; /* input file name */ static int linenum; /* current line number */ +static const char *linefile; /* file name for #line */ static FILE *output; /* output file pointer */ static const char *ofilename; /* output file name */ -static bool overwriting; /* output overwrites input */ -static char tempname[FILENAME_MAX]; /* used when overwriting */ +static const char *backext; /* backup extension */ +static char *tempname; /* avoid splatting input */ static char tline[MAXLINE+EDITSLOP];/* input buffer plus space */ static char *keyword; /* used for editing #elif's */ +/* + * When processing a file, the output's newline style will match the + * input's, and unifdef correctly handles CRLF or LF endings whatever + * the platform's native style. The stdio streams are opened in binary + * mode to accommodate platforms whose native newline style is CRLF. + * When the output isn't a processed input file (when it is error / + * debug / diagnostic messages) then unifdef uses native line endings. + */ + static const char *newline; /* input file format */ static const char newline_unix[] = "\n"; static const char newline_crlf[] = "\r\n"; static Comment_state incomment; /* comment parser state */ static Line_state linestate; /* #if line parser state */ static Ifstate ifstate[MAXDEPTH]; /* #if processor state */ static bool ignoring[MAXDEPTH]; /* ignore comments state */ static int stifline[MAXDEPTH]; /* start of current #if */ static int depth; /* current #if nesting */ static int delcount; /* count of deleted lines */ static unsigned blankcount; /* count of blank lines */ static unsigned blankmax; /* maximum recent blankcount */ static bool constexpr; /* constant #if expression */ -static bool zerosyms = true; /* to format symdepth output */ +static bool zerosyms; /* to format symdepth output */ static bool firstsym; /* ditto */ +static int exitmode; /* exit status mode */ static int exitstat; /* program exit status */ -static void addsym(bool, bool, char *); -static void closeout(void); +static void addsym1(bool, bool, char *); +static void addsym2(bool, const char *, const char *); +static char *astrcat(const char *, const char *); +static void cleantemp(void); +static void closeio(void); static void debug(const char *, ...); +static void debugsym(const char *, int); +static bool defundef(void); +static void defundefile(const char *); static void done(void); static void error(const char *); -static int findsym(const char *); +static int findsym(const char **); static void flushline(bool); -static Linetype parseline(void); +static void hashline(void); +static void help(void); static Linetype ifeval(const char **); static void ignoreoff(void); static void ignoreon(void); +static void indirectsym(void); static void keywordedit(const char *); +static const char *matchsym(const char *, const char *); static void nest(void); +static Linetype parseline(void); static void process(void); +static void processinout(const char *, const char *); static const char *skipargs(const char *); static const char *skipcomment(const char *); +static const char *skiphash(void); +static const char *skipline(const char *); static const char *skipsym(const char *); static void state(Ifstate); -static int strlcmp(const char *, const char *, size_t); static void unnest(void); static void usage(void); static void version(void); +static const char *xstrdup(const char *, const char *); #define endsym(c) (!isalnum((unsigned char)c) && c != '_') /* * The main program. */ int main(int argc, char *argv[]) { int opt; - while ((opt = getopt(argc, argv, "i:D:U:I:o:bBcdeKklnsStV")) != -1) + while ((opt = getopt(argc, argv, "i:D:U:f:I:M:o:x:bBcdehKklmnsStV")) != -1) switch (opt) { case 'i': /* treat stuff controlled by these symbols as text */ /* * For strict backwards-compatibility the U or D * should be immediately after the -i but it doesn't * matter much if we relax that requirement. */ opt = *optarg++; if (opt == 'D') - addsym(true, true, optarg); + addsym1(true, true, optarg); else if (opt == 'U') - addsym(true, false, optarg); + addsym1(true, false, optarg); else usage(); break; case 'D': /* define a symbol */ - addsym(false, true, optarg); + addsym1(false, true, optarg); break; case 'U': /* undef a symbol */ - addsym(false, false, optarg); + addsym1(false, false, optarg); break; case 'I': /* no-op for compatibility with cpp */ break; case 'b': /* blank deleted lines instead of omitting them */ case 'l': /* backwards compatibility */ lnblank = true; break; case 'B': /* compress blank lines around removed section */ compblank = true; break; case 'c': /* treat -D as -U and vice versa */ complement = true; break; case 'd': debugging = true; break; case 'e': /* fewer errors from dodgy lines */ iocccok = true; break; + case 'f': /* definitions file */ + defundefile(optarg); + break; + case 'h': + help(); + break; case 'K': /* keep ambiguous #ifs */ strictlogic = true; break; case 'k': /* process constant #ifs */ killconsts = true; break; + case 'm': /* modify in place */ + inplace = true; + break; + case 'M': /* modify in place and keep backup */ + inplace = true; + backext = optarg; + break; case 'n': /* add #line directive after deleted lines */ lnnum = true; break; case 'o': /* output to a file */ ofilename = optarg; break; case 's': /* only output list of symbols that control #ifs */ symlist = true; break; case 'S': /* list symbols with their nesting depth */ symlist = symdepth = true; break; case 't': /* don't parse C comments */ text = true; break; - case 'V': /* print version */ + case 'V': version(); + break; + case 'x': + exitmode = atoi(optarg); + if(exitmode < 0 || exitmode > 2) + usage(); + break; default: usage(); } argc -= optind; argv += optind; if (compblank && lnblank) errx(2, "-B and -b are mutually exclusive"); - if (argc > 1) { - errx(2, "can only do one file"); - } else if (argc == 1 && strcmp(*argv, "-") != 0) { - filename = *argv; - input = fopen(filename, "rb"); - if (input == NULL) - err(2, "can't open %s", filename); - } else { - filename = "[stdin]"; - input = stdin; + if (symlist && (ofilename != NULL || inplace || argc > 1)) + errx(2, "-s only works with one input file"); + if (argc > 1 && ofilename != NULL) + errx(2, "-o cannot be used with multiple input files"); + if (argc > 1 && !inplace) + errx(2, "multiple input files require -m or -M"); + if (argc == 0) + argc = 1; + if (argc == 1 && !inplace && ofilename == NULL) + ofilename = "-"; + indirectsym(); + + atexit(cleantemp); + if (ofilename != NULL) + processinout(*argv, ofilename); + else while (argc-- > 0) { + processinout(*argv, *argv); + argv++; } - if (ofilename == NULL) { - ofilename = "[stdout]"; - output = stdout; - } else { - struct stat ist, ost; - if (stat(ofilename, &ost) == 0 && - fstat(fileno(input), &ist) == 0) - overwriting = (ist.st_dev == ost.st_dev - && ist.st_ino == ost.st_ino); - if (overwriting) { - const char *dirsep; - int ofd; + switch(exitmode) { + case(0): exit(exitstat); + case(1): exit(!exitstat); + case(2): exit(0); + default: abort(); /* bug */ + } +} - dirsep = strrchr(ofilename, '/'); - if (dirsep != NULL) - snprintf(tempname, sizeof(tempname), - "%.*s/" TEMPLATE, - (int)(dirsep - ofilename), ofilename); - else - snprintf(tempname, sizeof(tempname), - TEMPLATE); - ofd = mkstemp(tempname); - if (ofd != -1) - output = fdopen(ofd, "wb+"); - if (output == NULL) - err(2, "can't create temporary file"); - fchmod(ofd, ist.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)); - } else { - output = fopen(ofilename, "wb"); - if (output == NULL) - err(2, "can't open %s", ofilename); - } +/* + * File logistics. + */ +static void +processinout(const char *ifn, const char *ofn) +{ + struct stat st; + + if (ifn == NULL || strcmp(ifn, "-") == 0) { + filename = "[stdin]"; + linefile = NULL; + input = fbinmode(stdin); + } else { + filename = ifn; + linefile = ifn; + input = fopen(ifn, "rb"); + if (input == NULL) + err(2, "can't open %s", ifn); } + if (strcmp(ofn, "-") == 0) { + output = fbinmode(stdout); + process(); + return; + } + if (stat(ofn, &st) < 0) { + output = fopen(ofn, "wb"); + if (output == NULL) + err(2, "can't create %s", ofn); + process(); + return; + } + + tempname = astrcat(ofn, ".XXXXXX"); + output = mktempmode(tempname, st.st_mode); + if (output == NULL) + err(2, "can't create %s", tempname); + process(); - abort(); /* bug */ + + if (backext != NULL) { + char *backname = astrcat(ofn, backext); + if (rename(ofn, backname) < 0) + err(2, "can't rename \"%s\" to \"%s\"", ofn, backname); + free(backname); + } + if (replace(tempname, ofn) < 0) + err(2, "can't rename \"%s\" to \"%s\"", tempname, ofn); + free(tempname); + tempname = NULL; } +/* + * For cleaning up if there is an error. + */ static void +cleantemp(void) +{ + if (tempname != NULL) + remove(tempname); +} + +/* + * Self-identification functions. + */ + +static void version(void) { const char *c = copyright; for (;;) { while (*++c != '$') if (*c == '\0') exit(0); while (*++c != '$') putc(*c, stderr); putc('\n', stderr); } } static void +synopsis(FILE *fp) +{ + fprintf(fp, + "usage: unifdef [-bBcdehKkmnsStV] [-x{012}] [-Mext] [-opath] \\\n" + " [-[i]Dsym[=val]] [-[i]Usym] [-fpath] ... [file] ...\n"); +} + +static void usage(void) { - fprintf(stderr, "usage: unifdef [-bBcdeKknsStV] [-Ipath]" - " [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [file]\n"); + synopsis(stderr); exit(2); } +static void +help(void) +{ + synopsis(stdout); + printf( + " -Dsym=val define preprocessor symbol with given value\n" + " -Dsym define preprocessor symbol with value 1\n" + " -Usym preprocessor symbol is undefined\n" + " -iDsym=val \\ ignore C strings and comments\n" + " -iDsym ) in sections controlled by these\n" + " -iUsym / preprocessor symbols\n" + " -fpath file containing #define and #undef directives\n" + " -b blank lines instead of deleting them\n" + " -B compress blank lines around deleted section\n" + " -c complement (invert) keep vs. delete\n" + " -d debugging mode\n" + " -e ignore multiline preprocessor directives\n" + " -h print help\n" + " -Ipath extra include file path (ignored)\n" + " -K disable && and || short-circuiting\n" + " -k process constant #if expressions\n" + " -Mext modify in place and keep backups\n" + " -m modify input files in place\n" + " -n add #line directives to output\n" + " -opath output file name\n" + " -S list #if control symbols with nesting\n" + " -s list #if control symbols\n" + " -t ignore C strings and comments\n" + " -V print version\n" + " -x{012} exit status mode\n" + ); + exit(0); +} + /* * A state transition function alters the global #if processing state * in a particular way. The table below is indexed by the current * processing state and the type of the current line. * * Nesting is handled by keeping a stack of states; some transition * functions increase or decrease the depth. They also maintain the * ignore state on a stack. In some complicated cases they have to * alter the preprocessor directive, as follows. * * When we have processed a group that starts off with a known-false * #if/#elif sequence (which has therefore been deleted) followed by a * #elif that we don't understand and therefore must keep, we edit the - * latter into a #if to keep the nesting correct. We use strncpy() to + * latter into a #if to keep the nesting correct. We use memcpy() to * overwrite the 4 byte token "elif" with "if " without a '\0' byte. * * When we find a true #elif in a group, the following block will * always be kept and the rest of the sequence after the next #elif or * #else will be discarded. We edit the #elif into a #else and the * following directive to #endif since this has the desired behaviour. * * "Dodgy" directives are split across multiple lines, the most common * example being a multi-line comment hanging off the right of the * directive. We can handle them correctly only if there is no change * from printing to dropping (or vice versa) caused by that directive. * If the directive is the first of a group we have a choice between * failing with an error, or passing it through unchanged instead of * evaluating it. The latter is not the default to avoid questions from * users about unifdef unexpectedly leaving behind preprocessor directives. */ typedef void state_fn(void); /* report an error */ static void Eelif (void) { error("Inappropriate #elif"); } static void Eelse (void) { error("Inappropriate #else"); } static void Eendif(void) { error("Inappropriate #endif"); } static void Eeof (void) { error("Premature EOF"); } static void Eioccc(void) { error("Obfuscated preprocessor control line"); } /* plain line handling */ static void print (void) { flushline(true); } static void drop (void) { flushline(false); } /* output lacks group's start line */ static void Strue (void) { drop(); ignoreoff(); state(IS_TRUE_PREFIX); } static void Sfalse(void) { drop(); ignoreoff(); state(IS_FALSE_PREFIX); } static void Selse (void) { drop(); state(IS_TRUE_ELSE); } /* print/pass this block */ static void Pelif (void) { print(); ignoreoff(); state(IS_PASS_MIDDLE); } static void Pelse (void) { print(); state(IS_PASS_ELSE); } static void Pendif(void) { print(); unnest(); } /* discard this block */ static void Dfalse(void) { drop(); ignoreoff(); state(IS_FALSE_TRAILER); } static void Delif (void) { drop(); ignoreoff(); state(IS_FALSE_MIDDLE); } static void Delse (void) { drop(); state(IS_FALSE_ELSE); } static void Dendif(void) { drop(); unnest(); } /* first line of group */ static void Fdrop (void) { nest(); Dfalse(); } static void Fpass (void) { nest(); Pelif(); } static void Ftrue (void) { nest(); Strue(); } static void Ffalse(void) { nest(); Sfalse(); } /* variable pedantry for obfuscated lines */ static void Oiffy (void) { if (!iocccok) Eioccc(); Fpass(); ignoreon(); } static void Oif (void) { if (!iocccok) Eioccc(); Fpass(); } static void Oelif (void) { if (!iocccok) Eioccc(); Pelif(); } /* ignore comments in this block */ static void Idrop (void) { Fdrop(); ignoreon(); } static void Itrue (void) { Ftrue(); ignoreon(); } static void Ifalse(void) { Ffalse(); ignoreon(); } /* modify this line */ -static void Mpass (void) { strncpy(keyword, "if ", 4); Pelif(); } +static void Mpass (void) { memcpy(keyword, "if ", 4); Pelif(); } static void Mtrue (void) { keywordedit("else"); state(IS_TRUE_MIDDLE); } static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); } static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); } static state_fn * const trans_table[IS_COUNT][LT_COUNT] = { /* IS_OUTSIDE */ { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Eendif, Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eendif, print, done, abort }, /* IS_FALSE_PREFIX */ { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Strue, Sfalse,Selse, Dendif, Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Eioccc,Eioccc,Eioccc,Eioccc, drop, Eeof, abort }, /* IS_TRUE_PREFIX */ { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Dfalse,Dfalse,Dfalse,Delse, Dendif, Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, print, Eeof, abort }, /* IS_PASS_MIDDLE */ { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Pelif, Mtrue, Delif, Pelse, Pendif, Oiffy, Oiffy, Fpass, Oif, Oif, Pelif, Oelif, Oelif, Pelse, Pendif, print, Eeof, abort }, /* IS_FALSE_MIDDLE */ { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Pelif, Mtrue, Delif, Pelse, Pendif, Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, drop, Eeof, abort }, /* IS_TRUE_MIDDLE */ { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Melif, Melif, Melif, Melse, Pendif, Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Pendif, print, Eeof, abort }, /* IS_PASS_ELSE */ { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Pendif, Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Pendif, print, Eeof, abort }, /* IS_FALSE_ELSE */ { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Dendif, Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Eioccc, drop, Eeof, abort }, /* IS_TRUE_ELSE */ { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Dendif, Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eioccc, print, Eeof, abort }, /* IS_FALSE_TRAILER */ { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Dendif, Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Eioccc, drop, Eeof, abort } /*TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF (DODGY) PLAIN EOF ERROR */ }; /* * State machine utility functions */ static void ignoreoff(void) { if (depth == 0) abort(); /* bug */ ignoring[depth] = ignoring[depth-1]; } static void ignoreon(void) { ignoring[depth] = true; } static void keywordedit(const char *replacement) { snprintf(keyword, tline + sizeof(tline) - keyword, "%s%s", replacement, newline); print(); } static void nest(void) { if (depth > MAXDEPTH-1) abort(); /* bug */ if (depth == MAXDEPTH-1) error("Too many levels of nesting"); depth += 1; stifline[depth] = linenum; } static void unnest(void) { if (depth == 0) abort(); /* bug */ depth -= 1; } static void state(Ifstate is) { ifstate[depth] = is; } /* + * The last state transition function. When this is called, + * lineval == LT_EOF, so the process() loop will terminate. + */ +static void +done(void) +{ + if (incomment) + error("EOF in comment"); + closeio(); +} + +/* * Write a line to the output or not, according to command line options. - * If writing fails, closeout() will print the error and exit. + * If writing fails, closeio() will print the error and exit. */ static void flushline(bool keep) { if (symlist) return; if (keep ^ complement) { bool blankline = tline[strspn(tline, " \t\r\n")] == '\0'; if (blankline && compblank && blankcount != blankmax) { delcount += 1; blankcount += 1; } else { - if (lnnum && delcount > 0 && - fprintf(output, "#line %d%s", linenum, newline) < 0) - closeout(); + if (lnnum && delcount > 0) + hashline(); if (fputs(tline, output) == EOF) - closeout(); + closeio(); delcount = 0; blankmax = blankcount = blankline ? blankcount + 1 : 0; } } else { if (lnblank && fputs(newline, output) == EOF) - closeout(); + closeio(); exitstat = 1; delcount += 1; blankcount = 0; } if (debugging && fflush(output) == EOF) - closeout(); + closeio(); } /* - * The driver for the state machine. + * Format of #line directives depends on whether we know the input filename. */ static void -process(void) +hashline(void) { - /* When compressing blank lines, act as if the file - is preceded by a large number of blank lines. */ - blankmax = blankcount = 1000; - for (;;) { - Linetype lineval = parseline(); - trans_table[ifstate[depth]][lineval](); - debug("process line %d %s -> %s depth %d", - linenum, linetype_name[lineval], - ifstate_name[ifstate[depth]], depth); - } + int e; + + if (linefile == NULL) + e = fprintf(output, "#line %d%s", linenum, newline); + else + e = fprintf(output, "#line %d \"%s\"%s", + linenum, linefile, newline); + if (e < 0) + closeio(); } /* * Flush the output and handle errors. */ static void -closeout(void) +closeio(void) { + /* Tidy up after findsym(). */ if (symdepth && !zerosyms) printf("\n"); - if (ferror(output) || fclose(output) == EOF) { - if (overwriting) { - warn("couldn't write to temporary file"); - unlink(tempname); - errx(2, "%s unchanged", ofilename); - } else { - err(2, "couldn't write to %s", ofilename); - } - } + if (output != NULL && (ferror(output) || fclose(output) == EOF)) + err(2, "%s: can't write to output", filename); + fclose(input); } /* - * Clean up and exit. + * The driver for the state machine. */ static void -done(void) +process(void) { - if (incomment) - error("EOF in comment"); - closeout(); - if (overwriting && rename(tempname, ofilename) == -1) { - warn("couldn't rename temporary file"); - unlink(tempname); - errx(2, "%s unchanged", ofilename); + Linetype lineval = LT_PLAIN; + /* When compressing blank lines, act as if the file + is preceded by a large number of blank lines. */ + blankmax = blankcount = 1000; + zerosyms = true; + newline = NULL; + linenum = 0; + while (lineval != LT_EOF) { + lineval = parseline(); + trans_table[ifstate[depth]][lineval](); + debug("process line %d %s -> %s depth %d", + linenum, linetype_name[lineval], + ifstate_name[ifstate[depth]], depth); } - exit(exitstat); } /* * Parse a line and determine its type. We keep the preprocessor line * parser state between calls in the global variable linestate, with * help from skipcomment(). */ static Linetype parseline(void) { const char *cp; int cursym; - int kwlen; Linetype retval; Comment_state wascomment; - linenum++; - if (fgets(tline, MAXLINE, input) == NULL) { - if (ferror(input)) - error(strerror(errno)); - else - return (LT_EOF); - } + wascomment = incomment; + cp = skiphash(); + if (cp == NULL) + return (LT_EOF); if (newline == NULL) { if (strrchr(tline, '\n') == strrchr(tline, '\r') + 1) newline = newline_crlf; else newline = newline_unix; } - retval = LT_PLAIN; - wascomment = incomment; - cp = skipcomment(tline); - if (linestate == LS_START) { - if (*cp == '#') { - linestate = LS_HASH; - firstsym = true; - cp = skipcomment(cp + 1); - } else if (*cp != '\0') - linestate = LS_DIRTY; + if (*cp == '\0') { + retval = LT_PLAIN; + goto done; } - if (!incomment && linestate == LS_HASH) { - keyword = tline + (cp - tline); - cp = skipsym(cp); - kwlen = cp - keyword; + keyword = tline + (cp - tline); + if ((cp = matchsym("ifdef", keyword)) != NULL || + (cp = matchsym("ifndef", keyword)) != NULL) { + cp = skipcomment(cp); + if ((cursym = findsym(&cp)) < 0) + retval = LT_IF; + else { + retval = (keyword[2] == 'n') + ? LT_FALSE : LT_TRUE; + if (value[cursym] == NULL) + retval = (retval == LT_TRUE) + ? LT_FALSE : LT_TRUE; + if (ignore[cursym]) + retval = (retval == LT_TRUE) + ? LT_TRUEI : LT_FALSEI; + } + } else if ((cp = matchsym("if", keyword)) != NULL) + retval = ifeval(&cp); + else if ((cp = matchsym("elif", keyword)) != NULL) + retval = linetype_if2elif(ifeval(&cp)); + else if ((cp = matchsym("else", keyword)) != NULL) + retval = LT_ELSE; + else if ((cp = matchsym("endif", keyword)) != NULL) + retval = LT_ENDIF; + else { + cp = skipsym(keyword); /* no way can we deal with a continuation inside a keyword */ if (strncmp(cp, "\\\r\n", 3) == 0 || strncmp(cp, "\\\n", 2) == 0) Eioccc(); - if (strlcmp("ifdef", keyword, kwlen) == 0 || - strlcmp("ifndef", keyword, kwlen) == 0) { - cp = skipcomment(cp); - if ((cursym = findsym(cp)) < 0) - retval = LT_IF; - else { - retval = (keyword[2] == 'n') - ? LT_FALSE : LT_TRUE; - if (value[cursym] == NULL) - retval = (retval == LT_TRUE) - ? LT_FALSE : LT_TRUE; - if (ignore[cursym]) - retval = (retval == LT_TRUE) - ? LT_TRUEI : LT_FALSEI; - } - cp = skipsym(cp); - } else if (strlcmp("if", keyword, kwlen) == 0) - retval = ifeval(&cp); - else if (strlcmp("elif", keyword, kwlen) == 0) - retval = ifeval(&cp) - LT_IF + LT_ELIF; - else if (strlcmp("else", keyword, kwlen) == 0) - retval = LT_ELSE; - else if (strlcmp("endif", keyword, kwlen) == 0) - retval = LT_ENDIF; - else { + cp = skipline(cp); + retval = LT_PLAIN; + goto done; + } + cp = skipcomment(cp); + if (*cp != '\0') { + cp = skipline(cp); + if (retval == LT_TRUE || retval == LT_FALSE || + retval == LT_TRUEI || retval == LT_FALSEI) + retval = LT_IF; + if (retval == LT_ELTRUE || retval == LT_ELFALSE) + retval = LT_ELIF; + } + /* the following can happen if the last line of the file lacks a + newline or if there is too much whitespace in a directive */ + if (linestate == LS_HASH) { + long len = cp - tline; + if (fgets(tline + len, MAXLINE - len, input) == NULL) { + if (ferror(input)) + err(2, "can't read %s", filename); + /* append the missing newline at eof */ + strcpy(tline + len, newline); + cp += strlen(newline); + linestate = LS_START; + } else { linestate = LS_DIRTY; - retval = LT_PLAIN; } - cp = skipcomment(cp); - if (*cp != '\0') { - linestate = LS_DIRTY; - if (retval == LT_TRUE || retval == LT_FALSE || - retval == LT_TRUEI || retval == LT_FALSEI) - retval = LT_IF; - if (retval == LT_ELTRUE || retval == LT_ELFALSE) - retval = LT_ELIF; - } - if (retval != LT_PLAIN && (wascomment || incomment)) { - retval += LT_DODGY; - if (incomment) - linestate = LS_DIRTY; - } - /* skipcomment normally changes the state, except - if the last line of the file lacks a newline, or - if there is too much whitespace in a directive */ - if (linestate == LS_HASH) { - size_t len = cp - tline; - if (fgets(tline + len, MAXLINE - len, input) == NULL) { - if (ferror(input)) - error(strerror(errno)); - /* append the missing newline at eof */ - strcpy(tline + len, newline); - cp += strlen(newline); - linestate = LS_START; - } else { - linestate = LS_DIRTY; - } - } } - if (linestate == LS_DIRTY) { - while (*cp != '\0') - cp = skipcomment(cp + 1); + if (retval != LT_PLAIN && (wascomment || linestate != LS_START)) { + retval = linetype_2dodgy(retval); + linestate = LS_DIRTY; } +done: debug("parser line %d state %s comment %s line", linenum, comment_name[incomment], linestate_name[linestate]); return (retval); } /* * These are the binary operators that are supported by the expression * evaluator. */ -static Linetype op_strict(int *p, int v, Linetype at, Linetype bt) { +static Linetype op_strict(long *p, long v, Linetype at, Linetype bt) { if(at == LT_IF || bt == LT_IF) return (LT_IF); return (*p = v, v ? LT_TRUE : LT_FALSE); } -static Linetype op_lt(int *p, Linetype at, int a, Linetype bt, int b) { +static Linetype op_lt(long *p, Linetype at, long a, Linetype bt, long b) { return op_strict(p, a < b, at, bt); } -static Linetype op_gt(int *p, Linetype at, int a, Linetype bt, int b) { +static Linetype op_gt(long *p, Linetype at, long a, Linetype bt, long b) { return op_strict(p, a > b, at, bt); } -static Linetype op_le(int *p, Linetype at, int a, Linetype bt, int b) { +static Linetype op_le(long *p, Linetype at, long a, Linetype bt, long b) { return op_strict(p, a <= b, at, bt); } -static Linetype op_ge(int *p, Linetype at, int a, Linetype bt, int b) { +static Linetype op_ge(long *p, Linetype at, long a, Linetype bt, long b) { return op_strict(p, a >= b, at, bt); } -static Linetype op_eq(int *p, Linetype at, int a, Linetype bt, int b) { +static Linetype op_eq(long *p, Linetype at, long a, Linetype bt, long b) { return op_strict(p, a == b, at, bt); } -static Linetype op_ne(int *p, Linetype at, int a, Linetype bt, int b) { +static Linetype op_ne(long *p, Linetype at, long a, Linetype bt, long b) { return op_strict(p, a != b, at, bt); } -static Linetype op_or(int *p, Linetype at, int a, Linetype bt, int b) { +static Linetype op_or(long *p, Linetype at, long a, Linetype bt, long b) { if (!strictlogic && (at == LT_TRUE || bt == LT_TRUE)) return (*p = 1, LT_TRUE); return op_strict(p, a || b, at, bt); } -static Linetype op_and(int *p, Linetype at, int a, Linetype bt, int b) { +static Linetype op_and(long *p, Linetype at, long a, Linetype bt, long b) { if (!strictlogic && (at == LT_FALSE || bt == LT_FALSE)) return (*p = 0, LT_FALSE); return op_strict(p, a && b, at, bt); } /* * An evaluation function takes three arguments, as follows: (1) a pointer to * an element of the precedence table which lists the operators at the current * level of precedence; (2) a pointer to an integer which will receive the * value of the expression; and (3) a pointer to a char* that points to the * expression to be evaluated and that is updated to the end of the expression * when evaluation is complete. The function returns LT_FALSE if the value of * the expression is zero, LT_TRUE if it is non-zero, LT_IF if the expression * depends on an unknown symbol, or LT_ERROR if there is a parse failure. */ struct ops; -typedef Linetype eval_fn(const struct ops *, int *, const char **); +typedef Linetype eval_fn(const struct ops *, long *, const char **); static eval_fn eval_table, eval_unary; /* * The precedence table. Expressions involving binary operators are evaluated * in a table-driven way by eval_table. When it evaluates a subexpression it * calls the inner function with its first argument pointing to the next * element of the table. Innermost expressions have special non-table-driven * handling. */ -static const struct ops { +struct op { + const char *str; + Linetype (*fn)(long *, Linetype, long, Linetype, long); +}; +struct ops { eval_fn *inner; - struct op { - const char *str; - Linetype (*fn)(int *, Linetype, int, Linetype, int); - } op[5]; -} eval_ops[] = { + struct op op[5]; +}; +static const struct ops eval_ops[] = { { eval_table, { { "||", op_or } } }, { eval_table, { { "&&", op_and } } }, { eval_table, { { "==", op_eq }, { "!=", op_ne } } }, { eval_unary, { { "<=", op_le }, { ">=", op_ge }, { "<", op_lt }, { ">", op_gt } } } }; +/* Current operator precedence level */ +static long prec(const struct ops *ops) +{ + return (ops - eval_ops); +} + /* * Function for evaluating the innermost parts of expressions, * viz. !expr (expr) number defined(symbol) symbol * We reset the constexpr flag in the last two cases. */ static Linetype -eval_unary(const struct ops *ops, int *valp, const char **cpp) +eval_unary(const struct ops *ops, long *valp, const char **cpp) { const char *cp; char *ep; int sym; bool defparen; Linetype lt; cp = skipcomment(*cpp); if (*cp == '!') { - debug("eval%d !", ops - eval_ops); + debug("eval%d !", prec(ops)); cp++; lt = eval_unary(ops, valp, &cp); if (lt == LT_ERROR) return (LT_ERROR); if (lt != LT_IF) { *valp = !*valp; lt = *valp ? LT_TRUE : LT_FALSE; } } else if (*cp == '(') { cp++; - debug("eval%d (", ops - eval_ops); + debug("eval%d (", prec(ops)); lt = eval_table(eval_ops, valp, &cp); if (lt == LT_ERROR) return (LT_ERROR); cp = skipcomment(cp); if (*cp++ != ')') return (LT_ERROR); } else if (isdigit((unsigned char)*cp)) { - debug("eval%d number", ops - eval_ops); + debug("eval%d number", prec(ops)); *valp = strtol(cp, &ep, 0); if (ep == cp) return (LT_ERROR); lt = *valp ? LT_TRUE : LT_FALSE; - cp = skipsym(cp); - } else if (strncmp(cp, "defined", 7) == 0 && endsym(cp[7])) { + cp = ep; + } else if (matchsym("defined", cp) != NULL) { cp = skipcomment(cp+7); - debug("eval%d defined", ops - eval_ops); if (*cp == '(') { cp = skipcomment(cp+1); defparen = true; } else { defparen = false; } - sym = findsym(cp); + sym = findsym(&cp); + cp = skipcomment(cp); + if (defparen && *cp++ != ')') { + debug("eval%d defined missing ')'", prec(ops)); + return (LT_ERROR); + } if (sym < 0) { + debug("eval%d defined unknown", prec(ops)); lt = LT_IF; } else { + debug("eval%d defined %s", prec(ops), symname[sym]); *valp = (value[sym] != NULL); lt = *valp ? LT_TRUE : LT_FALSE; } - cp = skipsym(cp); - cp = skipcomment(cp); - if (defparen && *cp++ != ')') - return (LT_ERROR); constexpr = false; } else if (!endsym(*cp)) { - debug("eval%d symbol", ops - eval_ops); - sym = findsym(cp); - cp = skipsym(cp); + debug("eval%d symbol", prec(ops)); + sym = findsym(&cp); if (sym < 0) { lt = LT_IF; cp = skipargs(cp); } else if (value[sym] == NULL) { *valp = 0; lt = LT_FALSE; } else { *valp = strtol(value[sym], &ep, 0); if (*ep != '\0' || ep == value[sym]) return (LT_ERROR); lt = *valp ? LT_TRUE : LT_FALSE; cp = skipargs(cp); } constexpr = false; } else { - debug("eval%d bad expr", ops - eval_ops); + debug("eval%d bad expr", prec(ops)); return (LT_ERROR); } *cpp = cp; - debug("eval%d = %d", ops - eval_ops, *valp); + debug("eval%d = %d", prec(ops), *valp); return (lt); } /* * Table-driven evaluation of binary operators. */ static Linetype -eval_table(const struct ops *ops, int *valp, const char **cpp) +eval_table(const struct ops *ops, long *valp, const char **cpp) { const struct op *op; const char *cp; - int val; + long val; Linetype lt, rt; - debug("eval%d", ops - eval_ops); + debug("eval%d", prec(ops)); cp = *cpp; lt = ops->inner(ops+1, valp, &cp); if (lt == LT_ERROR) return (LT_ERROR); for (;;) { cp = skipcomment(cp); for (op = ops->op; op->str != NULL; op++) if (strncmp(cp, op->str, strlen(op->str)) == 0) break; if (op->str == NULL) break; cp += strlen(op->str); - debug("eval%d %s", ops - eval_ops, op->str); + debug("eval%d %s", prec(ops), op->str); rt = ops->inner(ops+1, &val, &cp); if (rt == LT_ERROR) return (LT_ERROR); lt = op->fn(valp, lt, *valp, rt, val); } *cpp = cp; - debug("eval%d = %d", ops - eval_ops, *valp); - debug("eval%d lt = %s", ops - eval_ops, linetype_name[lt]); + debug("eval%d = %d", prec(ops), *valp); + debug("eval%d lt = %s", prec(ops), linetype_name[lt]); return (lt); } /* * Evaluate the expression on a #if or #elif line. If we can work out * the result we return LT_TRUE or LT_FALSE accordingly, otherwise we * return just a generic LT_IF. */ static Linetype ifeval(const char **cpp) { - int ret; - int val = 0; + Linetype ret; + long val = 0; debug("eval %s", *cpp); constexpr = killconsts ? false : true; ret = eval_table(eval_ops, &val, cpp); debug("eval = %d", val); return (constexpr ? LT_IF : ret == LT_ERROR ? LT_IF : ret); } /* + * Read a line and examine its initial part to determine if it is a + * preprocessor directive. Returns NULL on EOF, or a pointer to a + * preprocessor directive name, or a pointer to the zero byte at the + * end of the line. + */ +static const char * +skiphash(void) +{ + const char *cp; + + linenum++; + if (fgets(tline, MAXLINE, input) == NULL) { + if (ferror(input)) + err(2, "can't read %s", filename); + else + return (NULL); + } + cp = skipcomment(tline); + if (linestate == LS_START && *cp == '#') { + linestate = LS_HASH; + return (skipcomment(cp + 1)); + } else if (*cp == '\0') { + return (cp); + } else { + return (skipline(cp)); + } +} + +/* + * Mark a line dirty and consume the rest of it, keeping track of the + * lexical state. + */ +static const char * +skipline(const char *cp) +{ + if (*cp != '\0') + linestate = LS_DIRTY; + while (*cp != '\0') + cp = skipcomment(cp + 1); + return (cp); +} + +/* * Skip over comments, strings, and character literals and stop at the * next character position that is not whitespace. Between calls we keep * the comment state in the global variable incomment, and we also adjust * the global variable linestate when we see a newline. * XXX: doesn't cope with the buffer splitting inside a state transition. */ static const char * skipcomment(const char *cp) { if (text || ignoring[depth]) { for (; isspace((unsigned char)*cp); cp++) if (*cp == '\n') linestate = LS_START; return (cp); } while (*cp != '\0') /* don't reset to LS_START after a line continuation */ if (strncmp(cp, "\\\r\n", 3) == 0) cp += 3; else if (strncmp(cp, "\\\n", 2) == 0) cp += 2; else switch (incomment) { case NO_COMMENT: if (strncmp(cp, "/\\\r\n", 4) == 0) { incomment = STARTING_COMMENT; cp += 4; } else if (strncmp(cp, "/\\\n", 3) == 0) { incomment = STARTING_COMMENT; cp += 3; } else if (strncmp(cp, "/*", 2) == 0) { incomment = C_COMMENT; cp += 2; } else if (strncmp(cp, "//", 2) == 0) { incomment = CXX_COMMENT; cp += 2; } else if (strncmp(cp, "\'", 1) == 0) { incomment = CHAR_LITERAL; linestate = LS_DIRTY; cp += 1; } else if (strncmp(cp, "\"", 1) == 0) { incomment = STRING_LITERAL; linestate = LS_DIRTY; cp += 1; } else if (strncmp(cp, "\n", 1) == 0) { linestate = LS_START; cp += 1; } else if (strchr(" \r\t", *cp) != NULL) { cp += 1; } else return (cp); continue; case CXX_COMMENT: if (strncmp(cp, "\n", 1) == 0) { incomment = NO_COMMENT; linestate = LS_START; } cp += 1; continue; case CHAR_LITERAL: case STRING_LITERAL: if ((incomment == CHAR_LITERAL && cp[0] == '\'') || (incomment == STRING_LITERAL && cp[0] == '\"')) { incomment = NO_COMMENT; cp += 1; } else if (cp[0] == '\\') { if (cp[1] == '\0') cp += 1; else cp += 2; } else if (strncmp(cp, "\n", 1) == 0) { if (incomment == CHAR_LITERAL) error("unterminated char literal"); else error("unterminated string literal"); } else cp += 1; continue; case C_COMMENT: if (strncmp(cp, "*\\\r\n", 4) == 0) { incomment = FINISHING_COMMENT; cp += 4; } else if (strncmp(cp, "*\\\n", 3) == 0) { incomment = FINISHING_COMMENT; cp += 3; } else if (strncmp(cp, "*/", 2) == 0) { incomment = NO_COMMENT; cp += 2; } else cp += 1; continue; case STARTING_COMMENT: if (*cp == '*') { incomment = C_COMMENT; cp += 1; } else if (*cp == '/') { incomment = CXX_COMMENT; cp += 1; } else { incomment = NO_COMMENT; linestate = LS_DIRTY; } continue; case FINISHING_COMMENT: if (*cp == '/') { incomment = NO_COMMENT; cp += 1; } else incomment = C_COMMENT; continue; default: abort(); /* bug */ } return (cp); } /* * Skip macro arguments. */ static const char * skipargs(const char *cp) { const char *ocp = cp; int level = 0; cp = skipcomment(cp); if (*cp != '(') return (cp); do { if (*cp == '(') level++; if (*cp == ')') level--; cp = skipcomment(cp+1); } while (level != 0 && *cp != '\0'); if (level == 0) return (cp); else /* Rewind and re-detect the syntax error later. */ return (ocp); } /* * Skip over an identifier. */ static const char * skipsym(const char *cp) { while (!endsym(*cp)) ++cp; return (cp); } /* + * Skip whitespace and take a copy of any following identifier. + */ +static const char * +getsym(const char **cpp) +{ + const char *cp = *cpp, *sym; + + cp = skipcomment(cp); + cp = skipsym(sym = cp); + if (cp == sym) + return NULL; + *cpp = cp; + return (xstrdup(sym, cp)); +} + +/* + * Check that s (a symbol) matches the start of t, and that the + * following character in t is not a symbol character. Returns a + * pointer to the following character in t if there is a match, + * otherwise NULL. + */ +static const char * +matchsym(const char *s, const char *t) +{ + while (*s != '\0' && *t != '\0') + if (*s != *t) + return (NULL); + else + ++s, ++t; + if (*s == '\0' && endsym(*t)) + return(t); + else + return(NULL); +} + +/* * Look for the symbol in the symbol table. If it is found, we return * the symbol table index, else we return -1. */ static int -findsym(const char *str) +findsym(const char **strp) { - const char *cp; + const char *str; int symind; - cp = skipsym(str); - if (cp == str) - return (-1); + str = *strp; + *strp = skipsym(str); if (symlist) { + if (*strp == str) + return (-1); if (symdepth && firstsym) printf("%s%3d", zerosyms ? "" : "\n", depth); firstsym = zerosyms = false; printf("%s%.*s%s", - symdepth ? " " : "", - (int)(cp-str), str, - symdepth ? "" : "\n"); + symdepth ? " " : "", + (int)(*strp-str), str, + symdepth ? "" : "\n"); /* we don't care about the value of the symbol */ return (0); } for (symind = 0; symind < nsyms; ++symind) { - if (strlcmp(symname[symind], str, cp-str) == 0) { - debug("findsym %s %s", symname[symind], - value[symind] ? value[symind] : ""); + if (matchsym(symname[symind], str) != NULL) { + debugsym("findsym", symind); return (symind); } } return (-1); } /* + * Resolve indirect symbol values to their final definitions. + */ +static void +indirectsym(void) +{ + const char *cp; + int changed, sym, ind; + + do { + changed = 0; + for (sym = 0; sym < nsyms; ++sym) { + if (value[sym] == NULL) + continue; + cp = value[sym]; + ind = findsym(&cp); + if (ind == -1 || ind == sym || + *cp != '\0' || + value[ind] == NULL || + value[ind] == value[sym]) + continue; + debugsym("indir...", sym); + value[sym] = value[ind]; + debugsym("...ectsym", sym); + changed++; + } + } while (changed); +} + +/* + * Add a symbol to the symbol table, specified with the format sym=val + */ +static void +addsym1(bool ignorethis, bool definethis, char *symval) +{ + const char *sym, *val; + + sym = symval; + val = skipsym(sym); + if (definethis && *val == '=') { + symval[val - sym] = '\0'; + val = val + 1; + } else if (*val == '\0') { + val = definethis ? "1" : NULL; + } else { + usage(); + } + addsym2(ignorethis, sym, val); +} + +/* * Add a symbol to the symbol table. */ static void -addsym(bool ignorethis, bool definethis, char *sym) +addsym2(bool ignorethis, const char *sym, const char *val) { + const char *cp = sym; int symind; - char *val; - symind = findsym(sym); + symind = findsym(&cp); if (symind < 0) { if (nsyms >= MAXSYMS) errx(2, "too many symbols"); symind = nsyms++; } - symname[symind] = sym; ignore[symind] = ignorethis; - val = sym + (skipsym(sym) - sym); - if (definethis) { - if (*val == '=') { - value[symind] = val+1; - *val = '\0'; - } else if (*val == '\0') - value[symind] = "1"; - else - usage(); + symname[symind] = sym; + value[symind] = val; + debugsym("addsym", symind); +} + +static void +debugsym(const char *why, int symind) +{ + debug("%s %s%c%s", why, symname[symind], + value[symind] ? '=' : ' ', + value[symind] ? value[symind] : "undef"); +} + +/* + * Add symbols to the symbol table from a file containing + * #define and #undef preprocessor directives. + */ +static void +defundefile(const char *fn) +{ + filename = fn; + input = fopen(fn, "rb"); + if (input == NULL) + err(2, "can't open %s", fn); + linenum = 0; + while (defundef()) + ; + if (ferror(input)) + err(2, "can't read %s", filename); + else + fclose(input); + if (incomment) + error("EOF in comment"); +} + +/* + * Read and process one #define or #undef directive + */ +static bool +defundef(void) +{ + const char *cp, *kw, *sym, *val, *end; + + cp = skiphash(); + if (cp == NULL) + return (false); + if (*cp == '\0') + goto done; + /* strip trailing whitespace, and do a fairly rough check to + avoid unsupported multi-line preprocessor directives */ + end = cp + strlen(cp); + while (end > tline && strchr(" \t\n\r", end[-1]) != NULL) + --end; + if (end > tline && end[-1] == '\\') + Eioccc(); + + kw = cp; + if ((cp = matchsym("define", kw)) != NULL) { + sym = getsym(&cp); + if (sym == NULL) + error("missing macro name in #define"); + if (*cp == '(') { + val = "1"; + } else { + cp = skipcomment(cp); + val = (cp < end) ? xstrdup(cp, end) : ""; + } + debug("#define"); + addsym2(false, sym, val); + } else if ((cp = matchsym("undef", kw)) != NULL) { + sym = getsym(&cp); + if (sym == NULL) + error("missing macro name in #undef"); + cp = skipcomment(cp); + debug("#undef"); + addsym2(false, sym, NULL); } else { - if (*val != '\0') - usage(); - value[symind] = NULL; + error("unrecognized preprocessor directive"); } - debug("addsym %s=%s", symname[symind], - value[symind] ? value[symind] : "undef"); + skipline(cp); +done: + debug("parser line %d state %s comment %s line", linenum, + comment_name[incomment], linestate_name[linestate]); + return (true); } /* - * Compare s with n characters of t. - * The same as strncmp() except that it checks that s[n] == '\0'. + * Concatenate two strings into new memory, checking for failure. */ -static int -strlcmp(const char *s, const char *t, size_t n) +static char * +astrcat(const char *s1, const char *s2) { - while (n-- && *t != '\0') - if (*s != *t) - return ((unsigned char)*s - (unsigned char)*t); - else - ++s, ++t; - return ((unsigned char)*s); + char *s; + int len; + size_t size; + + len = snprintf(NULL, 0, "%s%s", s1, s2); + if (len < 0) + err(2, "snprintf"); + size = (size_t)len + 1; + s = (char *)malloc(size); + if (s == NULL) + err(2, "malloc"); + snprintf(s, size, "%s%s", s1, s2); + return (s); } /* + * Duplicate a segment of a string, checking for failure. + */ +static const char * +xstrdup(const char *start, const char *end) +{ + size_t n; + char *s; + + if (end < start) abort(); /* bug */ + n = (size_t)(end - start) + 1; + s = malloc(n); + if (s == NULL) + err(2, "malloc"); + snprintf(s, n, "%s", start); + return (s); +} + +/* * Diagnostics. */ static void debug(const char *msg, ...) { va_list ap; if (debugging) { va_start(ap, msg); vwarnx(msg, ap); va_end(ap); } } static void error(const char *msg) { if (depth == 0) warnx("%s: %d: %s", filename, linenum, msg); else warnx("%s: %d: %s (#if line %d depth %d)", filename, linenum, msg, stifline[depth], depth); - closeout(); + closeio(); errx(2, "output may be truncated"); } Index: stable/9/usr.bin/unifdef/unifdef.h =================================================================== --- stable/9/usr.bin/unifdef/unifdef.h (nonexistent) +++ stable/9/usr.bin/unifdef/unifdef.h (revision 279643) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012 - 2013 Tony Finch + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +/* portabiity stubs */ + +#define fbinmode(fp) (fp) + +#define replace(old,new) rename(old,new) + +static FILE * +mktempmode(char *tmp, int mode) +{ + int fd = mkstemp(tmp); + if (fd < 0) return (NULL); + fchmod(fd, mode & (S_IRWXU|S_IRWXG|S_IRWXO)); + return (fdopen(fd, "wb")); +} Property changes on: stable/9/usr.bin/unifdef/unifdef.h ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: stable/9/usr.bin/unifdef/unifdefall.sh =================================================================== --- stable/9/usr.bin/unifdef/unifdefall.sh (revision 279642) +++ stable/9/usr.bin/unifdef/unifdefall.sh (revision 279643) @@ -1,79 +1,60 @@ #!/bin/sh # # unifdefall: remove all the #if's from a source file # -# Copyright (c) 2002 - 2010 Tony Finch +# Copyright (c) 2002 - 2013 Tony Finch # Copyright (c) 2009 - 2010 Jonathan Nieder # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ set -e unifdef="$(dirname "$0")/unifdef" if [ ! -e "$unifdef" ] then unifdef=unifdef fi case "$@" in "-d "*) echo DEBUGGING 1>&2 debug=-d shift esac -basename=$(basename "$0") -tmp=$(mktemp -d "${TMPDIR:-/tmp}/$basename.XXXXXXXXXX") || exit 2 +tmp=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXXXXXX") || exit 2 trap 'rm -r "$tmp" || exit 2' EXIT export LC_ALL=C -# list of all controlling macros -"$unifdef" $debug -s "$@" | sort | uniq >"$tmp/ctrl" +# list of all controlling macros; assume these are undefined +"$unifdef" $debug -s "$@" | sort -u | sed 's/^/#undef /' >"$tmp/undefs" # list of all macro definitions -cpp -dM "$@" | sort | sed 's/^#define //' >"$tmp/hashdefs" -# list of defined macro names -sed 's/[^A-Za-z0-9_].*$//' <"$tmp/hashdefs" >"$tmp/alldef" -# list of undefined and defined controlling macros -comm -23 "$tmp/ctrl" "$tmp/alldef" >"$tmp/undef" -comm -12 "$tmp/ctrl" "$tmp/alldef" >"$tmp/def" -# create a sed script that extracts the controlling macro definitions -# and converts them to unifdef command-line arguments -sed 's|.*|s/^&\\(([^)]*)\\)\\{0,1\\} /-D&=/p|' <"$tmp/def" >"$tmp/script" -# create the final unifdef command -{ echo "$unifdef" $debug -k '\' - # convert the controlling undefined macros to -U arguments - sed 's/.*/-U& \\/' <"$tmp/undef" - # convert the controlling defined macros to quoted -D arguments - sed -nf "$tmp/script" <"$tmp/hashdefs" | - sed "s/'/'\\\\''/g;s/.*/'&' \\\\/" - echo '"$@"' -} >"$tmp/cmd" +cc -E -dM "$@" | sort >"$tmp/defs" + case $debug in --d) for i in ctrl hashdefs alldef undef def script cmd - do echo ==== $i - cat "$tmp/$i" - done 1>&2 +-d) cat "$tmp/undefs" "$tmp/defs" 1>&2 esac -# run the command we just created -sh "$tmp/cmd" "$@" + +# order of -f arguments means definitions override undefs +"$unifdef" $debug -k -f "$tmp/undefs" -f "$tmp/defs" "$@" Index: stable/9/usr.bin/vgrind/vgrindefs.5 =================================================================== --- stable/9/usr.bin/vgrind/vgrindefs.5 (revision 279642) +++ stable/9/usr.bin/vgrind/vgrindefs.5 (revision 279643) @@ -1,171 +1,170 @@ .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)vgrindefs.5 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" .Dd June 6, 1993 .Dt VGRINDEFS 5 .Os .Sh NAME .Nm vgrindefs .Nd language definition data base for .Xr vgrind 1 .Sh SYNOPSIS .Nm .Sh DESCRIPTION The .Nm file contains all language definitions for .Xr vgrind 1 . The data base is very similar to .Xr termcap 5 . .Sh FIELDS The following table names and describes each field. -.Pp .Bl -column Namexxx Tpexxx .It Sy "Name Type Description .It "ab str regular expression for the start of an alternate comment" .It "ae str regular expression for the end of an alternate comment" .It "pb str regular expression for start of a procedure" .It "bb str regular expression for start of a lexical block" .It "be str regular expression for the end of a lexical block" .It "cb str regular expression for the start of a comment" .It "ce str regular expression for the end of a comment" .It "sb str regular expression for the start of a string" .It "se str regular expression for the end of a string" .It "lb str regular expression for the start of a character constant" .It "le str regular expression for the end of a character constant" .It "nc str regular expression for a non-comment (see below)" .It "tl bool present means procedures are only defined at the top lexical level" .It "oc bool present means upper and lower case are equivalent" .It "kw str a list of keywords separated by spaces" .El .Pp Non-comments are required to describe a certain context where a sequence that would normally start a comment loses its special meaning. A typical example for this can be found in Perl, where comments are normally starting with .Ql # , while the string .Ql $# is an operator on an array. .Sh REGULAR EXPRESSIONS .Nm Vgrindefs uses regular expression which are very similar to those of .Xr ex 1 and .Xr lex 1 . The characters `^', `$', `:' and `\e' are reserved characters and must be "quoted" with a preceding .Ql \e if they are to be included as normal characters. The metasymbols and their meanings are: .Bl -tag -width indent .It $ the end of a line .It \&^ the beginning of a line .It \ed a delimiter (space, tab, newline, start of line) .It \ea matches any string of symbols (like .* in lex) .It \ep matches any alphanumeric name. In a procedure definition (pb) the string that matches this symbol is used as the procedure name. .It () grouping .It \&| alternation .It ? last item is optional .It \ee preceding any string means that the string will not match an input string if the input string is preceded by an escape character (\e). This is typically used for languages (like C) which can include the string delimiter in a string by escaping it. .El .Pp Unlike other regular expressions in the system, these match words and not characters. Hence something like "(tramp|steamer)flies?" would match "tramp", "steamer", "trampflies", or "steamerflies". .Sh KEYWORD LIST The keyword list is just a list of keywords in the language separated by spaces. If the "oc" boolean is specified, indicating that upper and lower case are equivalent, then all the keywords should be specified in lower case. .Sh FILES .Bl -tag -width /usr/share/misc/vgrindefs -compact .It Pa /usr/share/misc/vgrindefs File containing terminal descriptions. .El .Sh EXAMPLES The following entry, which describes the C language, is typical of a language entry. .Bd -literal C|c:\ :pb=^\ed?*?\ed?\ep\ed?\e(\ea?\e):bb={:be=}:cb=/*:ce=*/:sb=":se=\ee":\e :lb=':le=\ee':tl:\e :kw=asm auto break case char continue default do double else enum\e extern float for fortran goto if int long register return short\e sizeof static struct switch typedef union unsigned while #define\e #else #endif #if #ifdef #ifndef #include #undef # define else endif\e if ifdef ifndef include undef: .Ed .Pp Note that the first field is just the language name (and any variants of it). Thus the C language could be specified to .Xr vgrind 1 as "c" or "C". .Pp Entries may continue onto multiple lines by giving a \e as the last character of a line. Capabilities in .Nm are of two types: Boolean capabilities which indicate that the language has some particular feature and string capabilities which give a regular expression or keyword list. .Sh SEE ALSO .Xr troff 1 , .Xr vgrind 1 .Sh HISTORY The .Nm file format appeared in .Bx 4.2 . Index: stable/9/usr.bin =================================================================== --- stable/9/usr.bin (revision 279642) +++ stable/9/usr.bin (revision 279643) Property changes on: stable/9/usr.bin ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/usr.bin:r227243,233456,248258,248849,279297