Index: ObsoleteFiles.inc =================================================================== --- ObsoleteFiles.inc +++ ObsoleteFiles.inc @@ -38,6 +38,16 @@ # xargs -n1 | sort | uniq -d; # done +# 20171125: Remove fortune +OLD_FILES+=usr/bin/fortune +OLD_FILES+=usr/bin/strfile +OLD_FILES+=usr/bin/unstr +OLD_FILES+=usr/share/games/fortune/freebsd-tips +OLD_FILES+=usr/share/games/fortune/freebsd-tips.dat +OLD_FILES+=usr/share/man/man6/fortune.6.gz +OLD_FILES+=usr/share/man/man8/fortune.8.gz +OLD_DIRS+=usr/share/games/fortune +OLD_DIRS+=usr/share/games # 20171118: Remove old etc capser files OLD_FILES+=etc/casper/system.dns OLD_FILES+=etc/casper/system.grp Index: usr.bin/Makefile =================================================================== --- usr.bin/Makefile +++ usr.bin/Makefile @@ -211,7 +211,6 @@ SUBDIR.${MK_FTP}+= ftp SUBDIR.${MK_GAMES}+= caesar SUBDIR.${MK_GAMES}+= factor -SUBDIR.${MK_GAMES}+= fortune SUBDIR.${MK_GAMES}+= grdc SUBDIR.${MK_GAMES}+= morse SUBDIR.${MK_GAMES}+= number Index: usr.bin/fortune/Makefile =================================================================== --- usr.bin/fortune/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 5/31/93 -# -# $FreeBSD$ - -SUBDIR= fortune strfile datfiles unstr - -SUBDIR_DEPEND_datfiles= strfile - -SUBDIR_PARALLEL= - -.include Index: usr.bin/fortune/Makefile.inc =================================================================== --- usr.bin/fortune/Makefile.inc +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -FORTUNE_SRC= ${SRCTOP}/usr.bin/fortune -FORTUNE_OBJ= ${OBJTOP}/usr.bin/fortune - -.include "${SRCTOP}/usr.bin/Makefile.inc" Index: usr.bin/fortune/Notes =================================================================== --- usr.bin/fortune/Notes +++ /dev/null @@ -1,178 +0,0 @@ -# @(#)Notes 8.1 (Berkeley) 5/31/93 -# $FreeBSD$ - -Warning: - The fortunes contained in the fortune database have been collected - haphazardly from a cacophony of sources, in number so huge it - boggles the mind. It is impossible to do any meaningful quality - control on attributions, or lack thereof, or exactness of the quote. - Since this database is not used for profit, and since entire works - are not published, it falls under fair use, as we understand it. - However, if any half-assed idiot decides to make a profit off of - this, they will need to double check it all, and nobody not involved - of such an effort makes any warranty that anything in the database - bears any relation to the real world of literature, law, or other - bizzarrity. - -==> GENERAL INFORMATION - By default, fortune retrieves its fortune files from the directory -/usr/share/games/fortune. A fortune file has two parts: the source file -(which contains the fortunes themselves) and the data file which describes -the fortunes. The data file always has the same name as the fortune file -with the string ".dat" concatenated, i.e. "fortunes" is the standard fortune -database, and "fortunes.dat" is the data file which describes it. See -strfile(8) for more information on creating the data files. - Fortunes are split into potentially offensive and not potentially -offensive parts. The offensive version of a file has the same name as the -non-offensive version with "-o" concatenated, i.e. "fortunes" is the standard -fortune database, and "fortunes-o" is the standard offensive database. The -fortune program automatically assumes that any file with a name ending in -"-o" is potentially offensive, and should therefore only be displayed if -explicitly requested, either with the -o option or by specifying a file name -on the command line. - Potentially offensive fortune files should NEVER be maintained in -clear text on the system. They are rotated (see caesar(6)) 13 positions. -To create a new, potentially offensive database, use caesar to rotate it, -and then create its data file with the -x option to strfile(8). The fortune -program automatically decrypts the text when it prints entries from such -databases. - Anything which would not make it onto network prime time programming -(or which would only be broadcast if some discredited kind of guy said it) -MUST be in the potentially offensive database. Fortunes containing any -explicit language (see George Carlin's recent updated list) MUST be in the -potentially offensive database. Political and religious opinions are often -sequestered in the potentially offensive section as well. Anything which -assumes as a world view blatantly racist, misogynist (sexist), or homophobic -ideas should not be in either, since they are not really funny unless *you* -are racist, misogynist, or homophobic. - The point of this is that people should have a reasonable -expectation that, should they just run "fortune", they will not be offended. -We know that some people take offense at anything, but normal people do have -opinions, too, and have a right not to have their sensibilities offended by -a program which is supposed to be entertaining. People who run "fortune --o" or "fortune -a" are saying, in effect, that they are willing to have -their sensibilities tweaked. However, they should not have their personal -worth seriously (i.e., not in jest) assaulted. Jokes which depend for their -humor on racist, misogynist, or homophobic stereotypes *do* seriously -assault individual personal worth, and in a general entertainment medium -we should be able to get by without it. - -==> FORMATTING - This file describes the format for fortunes in the database. This -is done in detail to make it easier to keep track of things. Any rule given -here may be broken to make a better joke. - -[All examples are indented by one tab stop -- KCRCA] - -Numbers should be given in parentheses, e.g., - - (1) Everything depends. - (2) Nothing is always. - (3) Everything is sometimes. - -Attributions are two tab stops, followed by two hyphens, followed by a -space, followed by the attribution, and are *not* preceded by blank -lines. Book, journal, movie, and all other titles are in quotes, e.g., - - $100 invested at 7% interest for 100 years will become $100,000, at - which time it will be worth absolutely nothing. - -- Lazarus Long, "Time Enough for Love" - -Attributions which do not fit on one (72 char) line should be continued -on a line which lines up below the first text of the attribution, e.g., - - -- A very long attribution which might not fit on one - line, "Ken Arnold's Stupid Sayings" - -Single paragraph fortunes are in left justified (non-indented) paragraphs -unless they fall into another category listed below (see example above). -Longer fortunes should also be in left justified paragraphs, but if this -makes it too long, try indented paragraphs, with indentations of either one -tab stop or 5 chars. Indentations of less than 5 are too hard to read. - -Laws have the title left justified and capitalized, followed by a colon, -with all the text of the law itself indented one tab stop, initially -capitalized, e.g., - - A Law of Computer Programming: - Make it possible for programmers to write in English and - you will find the programmers cannot write in English. - -Limericks are indented as follows, all lines capitalized: - - A computer, to print out a fact, - Will divide, multiply, and subtract. - But this output can be - No more than debris, - If the input was short of exact. - -Accents precede the letter they are over, e.g., "`^He" for e with a grave -accent. Underlining is done on a word-by-word basis, with the underlines -preceding the word, e.g., "__^H^Hhi ____^H^H^H^Hthere". - -No fortune should run beyond 72 characters on a single line without good -justification (er, no pun intended). And no right margin justification, -either. Sorry. For BSD people, there is a program called "fmt" which can -make this kind of formatting easier. - -Definitions are given with the word or phrase left justified, followed by -the part of speech (if appropriate) and a colon. The definition starts -indented by one tab stop, with subsequent lines left justified, e.g., - - Afternoon, n.: - That part of the day we spend worrying about how we wasted - the morning. - -Quotes are sometimes put around statements which are funnier or make more -sense if they are understood as being spoken, rather than written, -communication, e.g., - - "All my friends and I are crazy. That's the only thing that - keeps us sane." - -Ellipses are always surrounded by spaces, except when next to punctuation, -and are three dots long. - - "... all the modern inconveniences ..." - -- Mark Twain - -Human initials always have spaces after the periods, e.g, "P. T. Barnum", -not "P.T. Barnum". However, "P.T.A.", not "P. T. A.". - -All fortunes should be attributed, but if and only if they are original with -somebody. Many people have said things that are folk sayings (i.e., are -common among the folk (i.e., us common slobs)). There is nothing wrong with -this, of course, but such statements should not be attributed to individuals -who did not invent them. - -Horoscopes should have the sign indented by one tab stop, followed by the -dates of the sign, with the text left justified below it, e.g., - - AQUARIUS (Jan 20 - Feb 18) - You have an inventive mind and are inclined to be progressive. You - lie a great deal. On the other hand, you are inclined to be - careless and impractical, causing you to make the same mistakes over - and over again. People think you are stupid. - -Single quotes should not be used except as quotes within quotes. Not even -single quotes masquerading as double quotes are to be used, e.g., don't say -``hi there'' or `hi there' or 'hi there', but "hi there". However, you -*can* say "I said, `hi there'". - -A long poem or song can be ordered as follows in order to make it fit on a -screen (fortunes should be 19 lines or less if at all possible) (numbers -here are stanza numbers): - - 11111111111111111111 - 11111111111111111111 - 11111111111111111111 22222222222222222222 - 11111111111111111111 22222222222222222222 - 22222222222222222222 - 33333333333333333333 22222222222222222222 - 33333333333333333333 - 33333333333333333333 44444444444444444444 - 33333333333333333333 44444444444444444444 - 44444444444444444444 - 44444444444444444444 - - Index: usr.bin/fortune/README =================================================================== --- usr.bin/fortune/README +++ /dev/null @@ -1,42 +0,0 @@ -# @(#)README 8.1 (Berkeley) 5/31/93 -# $FreeBSD$ - -The potentially offensive fortunes are installed by default on FreeBSD -systems. If you're absolutely, *positively*, without-a-shadow-of-a-doubt -sure that your user community goes berzerk/sues your pants off/drops dead -upon reading one of them, edit the Makefile in the subdirectory datfiles, -and do "make all install". - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - Some years ago, my neighbor Avery said to me: "There has not been an -adequate jokebook published since "Joe_Miller", which came out in 1739 and -which, incidentally, was the most miserable no-good ... jokebook in the -history of the printed word." - In a subsequent conversation, Avery said: "A funny story is a funny -story, no matter who is in it - whether it's about Catholics or Protestants, -Jews or Gentiles, blacks or whites, browns or yellows. If a story is genuinely -funny it makes no difference how dirty it is. Shout it from the rooftops. -Let the chips fall all over the prairie and let the bonehead wowsers yelp. -... on them." - It is a nice thing to have a neighbor of Avery's grain. He has -believed in the aforestated principles all his life. A great many other -people nowadays are casting aside the pietistic attitude that has led them -to plug up their ears against the facts of life. We of The Brotherhood -believe as Avery believes; we have never been intimidated by the pharisaical -meddlers who have been smelling up the American landscape since the time of -the bundling board. Neither has any one of our members ever been called a -racist. Still, we have been in unremitting revolt against the ignorant -propensity which ordains, in effect, that "The Green Pastures" should never -have been written; the idiot attitude which compelled Arthur Kober to abandon -his delightful Bella Gross, and Octavius Roy Cohen to quit writing about the -splendiferous Florian Slappey; the moronic frame of mind which, if carried -to its logical end, would have forbidden Ring Lardner from writing in the -language of the masses. - -- H. Allen Smith, "Rude Jokes" - - ... let us keep in mind the basic governing philosophy of The -Brotherhood, as handsomely summarized in these words: we believe in -healthy, hearty laughter -- at the expense of the whole human race, if -needs be. - Needs be. - -- H. Allen Smith, "Rude Jokes" Index: usr.bin/fortune/datfiles/Makefile =================================================================== --- usr.bin/fortune/datfiles/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# @(#)Makefile 8.2 (Berkeley) 4/19/94 -# $FreeBSD$ - -DB= freebsd-tips - -BLDS= ${DB:S/$/.dat/} -FILES= ${DB} ${BLDS} -CLEANFILES+=${BLDS} - -FILESDIR= ${SHAREDIR}/games/fortune - -.for f in ${DB} -$f.dat: $f - PATH=$$PATH:/usr/bin:${FORTUNE_OBJ}/strfile \ - strfile -Cs ${.ALLSRC} ${.TARGET} -.endfor - -.include Index: usr.bin/fortune/datfiles/Makefile.depend =================================================================== --- usr.bin/fortune/datfiles/Makefile.depend +++ /dev/null @@ -1,11 +0,0 @@ -# $FreeBSD$ -# Autogenerated - do NOT edit! - -DIRDEPS = \ - - -.include - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif Index: usr.bin/fortune/datfiles/freebsd-tips =================================================================== --- usr.bin/fortune/datfiles/freebsd-tips +++ /dev/null @@ -1,556 +0,0 @@ -This fortune brought to you by: -$FreeBSD$ -% -Any user that is a member of the wheel group can use "su -" to simulate -a root login. You can add a user to the wheel group by editing /etc/group. - -- Konstantinos Konstantinidis -% -By pressing "Scroll Lock" you can use the arrow keys to scroll backward -through the console output. Press "Scroll Lock" again to turn it off. -Don't have a "Scroll Lock" key? The "Pause / Break" key acts alike. -% -Can't remember if you've installed a certain port or not? Try "pkg info --x port_name". -% -Ever wonder what those numbers after command names were, as in cat(1)? It's -the section of the manual the man page is in. "man man" will tell you more. - -- David Scheidt -% -Forget how to spell a word or a variation of a word? Use - - look portion_of_word_you_know - -- Dru -% -Forget what directory you are in? Type "pwd". - -- Dru -% -Forget when Easter is? Try "ncal -e". If you need the date for Orthodox -Easter, use "ncal -o" instead. - -- Dru -% -FreeBSD is started up by the program 'init'. The first thing init does when -starting multiuser mode (ie, starting the computer up for normal use) is to -run the shell script /etc/rc. By reading /etc/rc and the /etc/rc.d/ scripts, -you can learn a lot about how the system is put together, which again will -make you more confident about what happens when you do something with it. -% -Handy bash(1) prompt: PS1="\u@\h \w \!$ " - -- David Scheidt -% -Having trouble using fetch through a firewall? Try setting the environment -variable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details. -% -If other operating systems have damaged your Master Boot Record, you can -reinstall it with gpart(8). See -"man gpart" for details. -% -If you accidentally end up inside vi, you can quit it by pressing Escape, colon -(:), q (q), bang (!) and pressing return. -% -If you do not want to get beeps in X11 (X Windows), you can turn them off with - - xset b off -% -If you have a CD-ROM drive in your machine, you can make the CD-ROM that is -presently inserted available by typing 'mount /cdrom' as root. The CD-ROM -will be available under /cdrom/. Remember to do 'umount /cdrom' before -removing the CD-ROM (it will usually not be possible to remove the CD-ROM -without doing this.) - -Note: This tip may not work in all configurations. -% -If you need a reminder to leave your terminal, type "leave +hhmm" where -"hhmm" represents in how many hours and minutes you need to leave. - -- Dru -% -If you need to ask a question on the FreeBSD-questions mailing list then - - https://www.FreeBSD.org/doc/en_US.ISO8859-1/articles/\ - freebsd-questions/index.html - -contains lots of useful advice to help you get the best results. -% -If you write part of a filename in tcsh, -pressing TAB will show you the available choices when there -is more than one, or complete the filename if there's only one match. -% -If you `set watch = (0 any any)' in tcsh, you will be notified when -someone logs in or out of your system. -% -If you use the C shell, add the following line to the .cshrc file in your -home directory to prevent core files from being written to disk: - - limit coredumpsize 0 - -- Dru -% -If you want df(1) and other commands to display disk sizes in -kilobytes instead of 512-byte blocks, set BLOCKSIZE in your -environment to 'K'. You can also use 'M' for Megabytes or 'G' for -Gigabytes. If you want df(1) to automatically select the best size -then use 'df -h'. -% -If you want to play CDs with FreeBSD, a utility for this is already included. -Type 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM -environment variable in order to make cdcontrol want to start.) -% -If you'd like to keep track of applications in the FreeBSD ports tree, take a -look at FreshPorts; - - https://www.freshports.org/ -% -In order to make fetch (the FreeBSD downloading tool) ask for -username/password when it encounters a password-protected web page, you can set -the environment variable HTTP_AUTH to 'basic:*'. -% -In order to search for a string in some files, use 'grep' like this: - - grep "string" filename1 [filename2 filename3 ...] - -This will print out the lines in the files that contain the string. grep can -also do a lot more advanced searches - type 'man grep' for details. -% -In order to support national characters for European languages in tools like -less without creating other nationalisation aspects, set the environment -variable LC_ALL to 'en_US.UTF-8'. -% -"man firewall" will give advice for building a FreeBSD firewall using ipfw(8). - -- David Scheidt -% -"man hier" will explain the way FreeBSD filesystems are normally laid out. - -- David Scheidt -% -Man pages are divided into section depending on topic. There are 9 different -sections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). -You can get an introduction to each topic by typing - - man intro - -In other words, to get the intro to general commands, type - - man 1 intro -% -"man ports" gives many useful hints about installing FreeBSD ports. -% -"man security" gives very good advice on how to tune the security of your -FreeBSD system. -% -"man tuning" gives some tips how to tune performance of your FreeBSD system. - -- David Scheidt -% -Need to do a search in a manpage or in a file you've sent to a pager? Use -"/search_word". To repeat the same search, type "n" for next or "p" for -previous. - -- Dru -% -Need to find the location of a program? Use "locate program_name". - -- Dru -% -Need to leave your terminal for a few minutes and don't want to logout? -Use "lock -p". When you return, use your password as the key to unlock the -terminal. - -- Dru -% -Need to quickly empty a file? Use ": > filename". - -- Dru -% -Need to quickly return to your home directory? Type "cd". - -- Dru -% -Need to remove all those ^M characters from a DOS file? Try - - tr -d \\r < dosfile > newfile - -- Originally by Dru -% -Need to see the calendar for this month? Simply type "cal". To see the -whole year, type "cal -y". - -- Dru -% -Need to see which daemons are listening for connection requests? Use -"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. - -- Dru -% -Need to see your routing table? Type "netstat -rn". The entry with the G -flag is your gateway. - -- Dru -% -Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' - -- Mathieu -% -Over quota? "du -sh * | sort -h " will give you a sorted list of your -directory sizes. - -- David Scheidt -% -nc(1) (or netcat) is useful not only for redirecting input/output to -TCP or UDP connections, but also for proxying them with inetd(8). -% -sh (the default Bourne shell in FreeBSD) supports command-line editing. Just -``set -o emacs'' or ``set -o vi'' to enable it. Use "" key to complete -paths. -% -Simple tcsh prompt: set prompt = '%# ' -% -The default editor in FreeBSD is vi, which is efficient to use when you have -learned it, but somewhat user-unfriendly. To use ee (an easier but less -powerful editor) instead, set the environment variable EDITOR to /usr/bin/ee -% -Time to change your password? Type "passwd" and follow the prompts. - -- Dru -% -To change an environment variable in /bin/sh use: - - $ VARIABLE="value" - $ export VARIABLE -% -To change an environment variable in tcsh you use: setenv NAME "value" -where NAME is the name of the variable and "value" its new value. -% -To clear the screen, use "clear". To re-display your screen buffer, press -the scroll lock key and use your page up button. When you're finished, -press the scroll lock key again to get your prompt back. - -- Dru -% -You can press Ctrl-L while in the shell to clear the screen. -% -To determine whether a file is a text file, executable, or some other type -of file, use - - file filename - -- Dru -% -To do a fast search for a file, try - - locate filename - -locate uses a database that is updated every Saturday (assuming your computer -is running FreeBSD at the time) to quickly find files based on name only. -% -To erase a line you've written at the command prompt, use "Ctrl-U". - -- Dru -% -To find out the hostname associated with an IP address, use - - drill -x IP_address - -- Dru -% -To obtain a neat PostScript rendering of a manual page, use ``-t'' switch -of the man(1) utility: ``man -t ''. For example: - - man -t grep > grep.ps # Save the PostScript version to a file -or - man -t printf | lp # Send the PostScript directly to printer -% -To quickly create an empty file, use "touch filename". - -- Dru -% -To read a compressed file without having to first uncompress it, use -"zcat" or "zless" to view it. There is also "bzcat", "bzless", "xzcat" -and "xzless". - -- Dru -% -To save disk space in your home directory, compress files you rarely -use with "gzip filename". - -- Dru -% -To search for files that match a particular name, use find(1); for example - - find / -name "*GENERIC*" -ls - -will search '/', and all subdirectories, for files with 'GENERIC' in the name. - -- Stephen Hilton -% -To see all of the directories on your FreeBSD system, type - - find / -type d | less - -All the files? - - find / -type f | less -% -To see how long it takes a command to run, type the word "time" before the -command name. - -- Dru -% -To see how much disk space is left on your partitions, use - - df -h - -- Dru -% -To see the 10 largest files on a directory or partition, use - - du -h /partition_or_directory_name | sort -rh | head - -- Dru -% -To see the IP addresses currently set on your active interfaces, type -"ifconfig -u". - -- Dru -% -To see the last 10 lines of a long file, use "tail filename". To see the -first 10 lines, use "head filename". To see new lines as they're appended -to a file, use "tail -f filename". - -- Dru -% -To see the last time that you logged in, use lastlogin(8). - -- Dru -% -To see the MAC addresses of the NICs on your system, type - - ifconfig -a - -- Dru -% -To see the output from when your computer started, run dmesg(8). If it has -been replaced with other messages, look at /var/run/dmesg.boot. - -- Francisco Reyes -% -Want colour in your directory listings? Use "ls -G". "ls -F" is also useful, -and they can be combined as "ls -FG". -% -Want to find a specific port, just type the following under /usr/ports -or one its subdirectories: - - make search name= - or - make search key= -% -Want to know how many words, lines, or bytes are contained in a file? Type -"wc filename". - -- Dru -% -Want to see how much virtual memory you're using? Just type "swapinfo" to -be shown information about the usage of your swap partitions. -% -Want to strip UTF-8 BOM(Byte Order Mark) from given files? - - sed -e '1s/^\xef\xbb\xbf//' < bomfile > newfile -% -Want to use sed(1) to edit a file in place? Well, to replace every 'e' with -an 'o', in a file named 'foo', you can do: - - sed -i.bak s/e/o/g foo - -And you'll get a backup of the original in a file named 'foo.bak', but if you -want no backup: - - sed -i '' s/e/o/g foo -% -When you've made modifications to a file in vi(1) and then find that -you can't write it, type ``!rm -f %'' then ``:w!'' to force the -write - -This won't work if you don't have write permissions to the directory -and probably won't be suitable if you're editing through a symbolic link. - -If you have sudo(8) installed and permissions to use it, type -``w ! sudo tee %'' to force a write. -% -You can adjust the volume of various parts of the sound system in your -computer by typing 'mixer '. To get a list of what you can -adjust, just type 'mixer'. -% -You can automatically download and install binary packages by doing - - pkg install - -This will also automatically install the packages that are dependencies -for the package you install (ie, the packages it needs in order to work.) -% -You can change the video mode on all consoles by adding something like -the following to /etc/rc.conf: - - allscreens="80x30" - -You can use "vidcontrol -i mode | grep T" for a list of supported text -modes. - -- Konstantinos Konstantinidis -% -You can disable tcsh's terminal beep if you `set nobeep'. -% -You can install extra packages for FreeBSD by using the ports system. -If you have installed it, you can download, compile, and install software by -just typing - - # cd /usr/ports// - # make install && make clean - -as root. The ports infrastructure will download the software, change it so -it works on FreeBSD, compile it, install it, register the installation so it -will be possible to automatically uninstall it, and clean out the temporary -working space it used. You can remove an installed port you decide you do not -want after all by typing - - # cd /usr/ports// - # make deinstall - -as root. -% -You can look through a file in a nice text-based interface by typing - - less filename -% -You can make a log of your terminal session with script(1). -% -You can often get answers to your questions about FreeBSD by searching in the -FreeBSD mailing list archives at - - http://freebsd.markmail.org -% -You can open up a new split-screen window in (n)vi with :N or :E and then -use ^w to switch between the two. -% -You can permanently set environment variables for your shell by putting them -in a startup file for the shell. The name of the startup file varies -depending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use -.profile. When using bash, sh, ksh or zsh, don't forget to export the -variable. -% -You can press Ctrl-D to quickly exit from a shell, or logout from a -login shell. - -- Konstantinos Konstantinidis -% -You can press up-arrow or down-arrow to walk through a list of -previous commands in tcsh. -% -You can search for documentation on a keyword by typing - - apropos keyword -% -You can `set autologout = 30' to have tcsh log you off automatically -if you leave the shell idle for more than 30 minutes. -% -You can use aliases to decrease the amount of typing you need to do to get -commands you commonly use. Examples of fairly popular aliases include (in -Bourne shell style, as in /bin/sh, bash, ksh, and zsh): - - alias lf="ls -FA" - alias ll="ls -lA" - alias su="su -m" - -In csh or tcsh, these would be - - alias lf ls -FA - alias ll ls -lA - alias su su -m - -To remove an alias, you can usually use 'unalias aliasname'. To list all -aliases, you can usually type just 'alias'. -% -You can use /etc/make.conf to control the options used to compile software -on this system. Example entries are in -/usr/share/examples/etc/make.conf and in make.conf(5). -For options that are set for building FreeBSD's kernel and its world, see -src.conf(5). -% -You can use "pkg info" to see a list of packages you have installed. -% -You can use the 'fetch' command to retrieve files over ftp, http or https. - - fetch https://www.FreeBSD.org/index.html - -will download the front page of the FreeBSD web site. -% -You can use "whereis" to search standard binary, manual page and source -directories for the specified programs. This can be particularly handy -when you are trying to find where in the ports tree an application is. - -Try "whereis firefox" and "whereis whereis". - -- Konstantinos Konstantinidis -% -Want to run the same command again? -In many shells (e.g., tcsh, zsh, bash) you can type "!!". -% -Want to go the directory you were just in? -Type "cd -" -% -Can't delete /usr/obj? Enter "chflags -R noschg /usr/obj" to remove the -system immutable flag for all files in /usr/obj. - - -- Lars Engels -% -Want to list all files of an installed package? Enter -"pkg info -l packagename". - - -- Lars Engels -% -Are you looking for a package? Search for it with -"pkg search part_of_package_name" - - -- Lars Engels -% -If you want to recursively copy a directory preserving file and directory -attributes use -"cp -a source target" - - -- Lars Engels -% -Do you wonder what a terminal program is doing at the moment? dd(1) does not -show any throughput? Hit "^T" (Control + t) to send SIGINFO to the process -and see what it is doing. - - -- Lars Engels -% -Do you want to know which version of FreeBSD you are running? Enter -"freebsd-version -ku" to display kernel and userland version. - - -- Lars Engels -% -If you want to end one or more processes at a time using a regular expression -enter "pkill regex". - - -- Lars Engels -% -Do you want to run a program directly after some other process has ended? Use -"pwait pid && new_program" - - -- Lars Engels -% -When you want your users to be able to reboot or shutdown FreeBSD, add them -to the group "operator" and they are allowed to use shutdown(8) and poweroff(8). - - -- Lars Engels -% -If you need to create a FAT32 formatted USB thumb drive, find out its devicename -running dmesg(8) after inserting it. Then create an MBR schema, a single slice and -format it: - -# gpart create -s MBR ${devicename} -# gpart add -t fat32 ${devicename} -# newfs_msdos -F 32 -L thumbdrive ${devicename}s1 - - -- Lars Engels -% -If you want to get a sorted list of all services that are started when FreeBSD boots, -enter "service -e". - - -- Lars Engels -% -To easily configure your installed FreeBSD use bsdconfig(8). - - -- Lars Engels -% -After you compiled and installed a new version of FreeBSD, use etcupdate(8) to merge -configuration updates. -Run "etcupdate extract" once when your sources match your running system, then run -"etcupdate" after every upgrade and "etcupdate resolve" to resolve any conflicts. - - -- Lars Engels -% -Do you want to do a binary upgrade of your running FreeBSD installation? Use freebsd-update(8). - -To install updates and patches for the running branch use -# freebsd-update fetch install - -To upgrade to a newer release use -# freebsd-update upgrade -r ${name_of_release} - - -- Lars Engels -% -To run rc scripts in /etc/rc.d and /usr/local/etc/rc.d use service(8). -Run "service ${name_of_rc_script} start" to start a daemon and -"service ${name_of_rc_script} stop" to stop it. - - -- Lars Engels -% -If you don't want to edit /etc/rc.conf directly, use sysrc(8) to add and remove entries. -Use "sysrc name=value" to add an entry and "sysrc -x name" to delete an entry. - - -- Lars Engels -% Index: usr.bin/fortune/datfiles/freebsd-tips.sp.ok =================================================================== --- usr.bin/fortune/datfiles/freebsd-tips.sp.ok +++ /dev/null @@ -1,87 +0,0 @@ -# $FreeBSD$ -aliasname -allscreens -AUTH -autolist -autologout -BLOCKSIZE -bomfile -cdcontrol -cdrom -CDs -cfg -conf -coredumpsize -csh -cshrc -Ctrl -deinstall -dmesg -dosfile -dscheidt -duth -ESC -filec -FreeBSD -grep -gzip -hiltonbsd -html -http -ifconfig -inetd -init -interactionvirtuelle -IPv -istar -kkonstan -Konstantinidis -ksh -lastlogin -lpr -manpage -mathieu -misc -natserv -ncal -netcat -netstat -newfile -NICs -nobeep -nospam -org -passwd -pkg -portname -PostScript -printf -proxying -PS -pwd -Reyes -sbin -Scheidt -setenv -sockstat -swapinfo -sysinstall -tcsh -tcsh's -tput -tumbolia -UDP -umount -unalias -uninstall -uniq -username -usr -UTF -vidcontrol -whereis -www -xset -zcat -zmore -zsh Index: usr.bin/fortune/fortune/Makefile =================================================================== --- usr.bin/fortune/fortune/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 5/31/93 -# $FreeBSD$ - -PROG= fortune -MAN= fortune.6 -CFLAGS+=-DDEBUG -I${FORTUNE_SRC}/strfile - -.include - -test: ${PROG} - ./${PROG} -m brass Index: usr.bin/fortune/fortune/Makefile.depend =================================================================== --- usr.bin/fortune/fortune/Makefile.depend +++ /dev/null @@ -1,17 +0,0 @@ -# $FreeBSD$ -# Autogenerated - do NOT edit! - -DIRDEPS = \ - gnu/lib/csu \ - include \ - include/xlocale \ - lib/${CSU_DIR} \ - lib/libc \ - lib/libcompiler_rt \ - - -.include - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif Index: usr.bin/fortune/fortune/fortune.6 =================================================================== --- usr.bin/fortune/fortune/fortune.6 +++ /dev/null @@ -1,190 +0,0 @@ -.\" Copyright (c) 1985, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Ken Arnold. -.\" -.\" 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. -.\" -.\" @(#)fortune.6 8.3 (Berkeley) 4/19/94 -.\" $FreeBSD$ -.\" -.Dd November 7, 2007 -.Dt FORTUNE 6 -.Os -.Sh NAME -.Nm fortune -.Nd "print a random, hopefully interesting, adage" -.Sh SYNOPSIS -.Nm -.Op Fl aDefilosw -.Op Fl m Ar pattern -.Oo -.Op Ar \&N% -.Ar file Ns / Ns Ar directory Ns / Ns Cm all -.Oc -.Sh DESCRIPTION -When -.Nm -is run with no arguments it prints out a random epigram. -Epigrams are divided into several categories, where each category -is subdivided into those which are potentially offensive and those -which are not. -The options are as follows: -.Bl -tag -width indent -.It Fl a -Choose from all lists of maxims, both offensive and not. -(See the -.Fl o -option for more information on offensive fortunes.) -.It Fl D -Enable additional debugging output. -Specify this option multiple times for more verbose output. -Only available if compiled with -.Li -DDEBUG . -.It Fl e -Consider all fortune files to be of equal size (see discussion below -on multiple files). -.It Fl f -Print out the list of files which would be searched, but do not -print a fortune. -.It Fl l -Long dictums only. -.It Fl m Ar pattern -Print out all fortunes which match the regular expression -.Ar pattern . -See -.Xr regex 3 -for a description of patterns. -.It Fl o -Choose only from potentially offensive aphorisms. -.Bf -symbolic -Please, please, please request a potentially offensive fortune if and -only if you believe, deep down in your heart, that you are willing -to be offended. -(And that if you are not willing, you will just quit using -.Fl o -rather than give us -grief about it, okay?) -.Ef -.Bd -unfilled -offset indent -\&... let us keep in mind the basic governing philosophy -of The Brotherhood, as handsomely summarized in these words: -we believe in healthy, hearty laughter -- at the expense of -the whole human race, if needs be. -Needs be. - --H. Allen Smith, "Rude Jokes" -.Ed -.It Fl s -Short apothegms only. -.It Fl i -Ignore case for -.Fl m -patterns. -.It Fl w -Wait before termination for an amount of time calculated from the -number of characters in the message. -This is useful if it is executed as part of the logout procedure -to guarantee that the message can be read before the screen is cleared. -.El -.Pp -The user may specify alternate sayings. -You can specify a specific file, a directory which contains one or -more files, or the special word -.Cm all -which says to use all the standard databases. -Any of these may be preceded by a percentage, which is a number -.Ar N -between 0 and 100 inclusive, followed by a -.Ql % . -If it is, there will be an -.Ar N -percent probability that an adage will be picked from that file -or directory. -If the percentages do not sum to 100, and there are specifications -without percentages, the remaining percent will apply to those files -and/or directories, in which case the probability of selecting from -one of them will be based on their relative sizes. -.Pp -As an example, given two databases -.Pa funny -and -.Pa not-funny , -with -.Pa funny -twice as big, saying -.Pp -.Dl "fortune funny not-funny" -.Pp -will get you fortunes out of -.Pa funny -two-thirds of the time. -The command -.Pp -.Dl "fortune 90% funny 10% not-funny" -.Pp -will pick out 90% of its fortunes from -.Pa funny -(the -.Dq Li "10% not-funny" -is unnecessary, since 10% is all that is left). -The -.Fl e -option says to consider all files equal; -thus -.Pp -.Dl "fortune -e funny not-funny" -.Pp -is equivalent to -.Pp -.Dl "fortune 50% funny 50% not-funny" -.Sh ENVIRONMENT -.Bl -tag -width ".Ev FORTUNE_PATH" -.It Ev FORTUNE_PATH -The search path for the data files. -It is a colon-separated list of directories in which -.Nm -looks for data files. -If not set it will default to -.Pa /usr/share/games/fortune . -If none of the directories specified exist, it will print a warning and exit. -.It Ev FORTUNE_SAVESTATE -If set, fortune will save some state about what fortune -it was up to on disk. -.El -.Sh FILES -.Bl -tag -width ".Pa /usr/share/games/fortune/*" -.It Pa /usr/share/games/fortune/* -the fortunes databases (those files ending -.Dq Pa -o -contain the -.Sy offensive -fortunes) -.El -.Sh SEE ALSO -.Xr arc4random_uniform 3 , -.Xr regcomp 3 , -.Xr regex 3 , -.Xr strfile 8 Index: usr.bin/fortune/fortune/fortune.c =================================================================== --- usr.bin/fortune/fortune/fortune.c +++ /dev/null @@ -1,1427 +0,0 @@ -/*- - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ken Arnold. - * - * 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. - */ - -#if 0 -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1986, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static const char sccsid[] = "@(#)fortune.c 8.1 (Berkeley) 5/31/93"; -#endif /* not lint */ -#endif -#include -__FBSDID("$FreeBSD$"); - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "strfile.h" -#include "pathnames.h" - -#define TRUE true -#define FALSE false - -#define MINW 6 /* minimum wait if desired */ -#define CPERS 20 /* # of chars for each sec */ -#define SLEN 160 /* # of chars in short fortune */ - -#define POS_UNKNOWN ((uint32_t) -1) /* pos for file unknown */ -#define NO_PROB (-1) /* no prob specified for file */ - -#ifdef DEBUG -#define DPRINTF(l,x) { if (Debug >= l) fprintf x; } -#undef NDEBUG -#else -#define DPRINTF(l,x) -#define NDEBUG 1 -#endif - -typedef struct fd { - int percent; - int fd, datfd; - uint32_t pos; - FILE *inf; - const char *name; - const char *path; - char *datfile, *posfile; - bool read_tbl; - bool was_pos_file; - STRFILE tbl; - int num_children; - struct fd *child, *parent; - struct fd *next, *prev; -} FILEDESC; - -static bool Found_one; /* did we find a match? */ -static bool Find_files = FALSE; /* just find a list of proper fortune files */ -static bool Fortunes_only = FALSE; /* check only "fortunes" files */ -static bool Wait = FALSE; /* wait desired after fortune */ -static bool Short_only = FALSE; /* short fortune desired */ -static bool Long_only = FALSE; /* long fortune desired */ -static bool Offend = FALSE; /* offensive fortunes only */ -static bool All_forts = FALSE; /* any fortune allowed */ -static bool Equal_probs = FALSE; /* scatter un-allocted prob equally */ -static bool Match = FALSE; /* dump fortunes matching a pattern */ -static bool WriteToDisk = false; /* use files on disk to save state */ -#ifdef DEBUG -static int Debug = 0; /* print debug messages */ -#endif - -static char *Fortbuf = NULL; /* fortune buffer for -m */ - -static int Fort_len = 0; - -static off_t Seekpts[2]; /* seek pointers to fortunes */ - -static FILEDESC *File_list = NULL, /* Head of file list */ - *File_tail = NULL; /* Tail of file list */ -static FILEDESC *Fortfile; /* Fortune file to use */ - -static STRFILE Noprob_tbl; /* sum of data for all no prob files */ - -static const char *Fortune_path; -static char **Fortune_path_arr; - -static int add_dir(FILEDESC *); -static int add_file(int, const char *, const char *, FILEDESC **, - FILEDESC **, FILEDESC *); -static void all_forts(FILEDESC *, char *); -static char *copy(const char *, u_int); -static void display(FILEDESC *); -static void do_free(void *); -static void *do_malloc(u_int); -static int form_file_list(char **, int); -static int fortlen(void); -static void get_fort(void); -static void get_pos(FILEDESC *); -static void get_tbl(FILEDESC *); -static void getargs(int, char *[]); -static void getpath(void); -static void init_prob(void); -static int is_dir(const char *); -static int is_fortfile(const char *, char **, char **, int); -static int is_off_name(const char *); -static int max(int, int); -static FILEDESC *new_fp(void); -static char *off_name(const char *); -static void open_dat(FILEDESC *); -static void open_fp(FILEDESC *); -static FILEDESC *pick_child(FILEDESC *); -static void print_file_list(void); -static void print_list(FILEDESC *, int); -static void sum_noprobs(FILEDESC *); -static void sum_tbl(STRFILE *, STRFILE *); -static void usage(void); -static void zero_tbl(STRFILE *); - -static char *conv_pat(char *); -static int find_matches(void); -static void matches_in_list(FILEDESC *); -static int maxlen_in_list(FILEDESC *); - -static regex_t Re_pat; - -int -main(int argc, char *argv[]) -{ - int fd; - - if (getenv("FORTUNE_SAVESTATE") != NULL) - WriteToDisk = true; - - (void) setlocale(LC_ALL, ""); - - getpath(); - getargs(argc, argv); - - if (Match) - exit(find_matches() != 0); - - init_prob(); - do { - get_fort(); - } while ((Short_only && fortlen() > SLEN) || - (Long_only && fortlen() <= SLEN)); - - display(Fortfile); - - if (WriteToDisk) { - if ((fd = creat(Fortfile->posfile, 0666)) < 0) { - perror(Fortfile->posfile); - exit(1); - } - /* - * if we can, we exclusive lock, but since it isn't very - * important, we just punt if we don't have easy locking - * available. - */ - flock(fd, LOCK_EX); - write(fd, (char *) &Fortfile->pos, sizeof Fortfile->pos); - if (!Fortfile->was_pos_file) - chmod(Fortfile->path, 0666); - flock(fd, LOCK_UN); - } - if (Wait) { - if (Fort_len == 0) - (void) fortlen(); - sleep((unsigned int) max(Fort_len / CPERS, MINW)); - } - - exit(0); -} - -static void -display(FILEDESC *fp) -{ - char *p; - unsigned char ch; - char line[BUFSIZ]; - - open_fp(fp); - fseeko(fp->inf, Seekpts[0], SEEK_SET); - for (Fort_len = 0; fgets(line, sizeof line, fp->inf) != NULL && - !STR_ENDSTRING(line, fp->tbl); Fort_len++) { - if (fp->tbl.str_flags & STR_ROTATED) - for (p = line; (ch = *p) != '\0'; ++p) { - if (isascii(ch)) { - if (isupper(ch)) - *p = 'A' + (ch - 'A' + 13) % 26; - else if (islower(ch)) - *p = 'a' + (ch - 'a' + 13) % 26; - } - } - if (fp->tbl.str_flags & STR_COMMENTS - && line[0] == fp->tbl.str_delim - && line[1] == fp->tbl.str_delim) - continue; - fputs(line, stdout); - } - (void) fflush(stdout); -} - -/* - * fortlen: - * Return the length of the fortune. - */ -static int -fortlen(void) -{ - int nchar; - char line[BUFSIZ]; - - if (!(Fortfile->tbl.str_flags & (STR_RANDOM | STR_ORDERED))) - nchar = (int)(Seekpts[1] - Seekpts[0]); - else { - open_fp(Fortfile); - fseeko(Fortfile->inf, Seekpts[0], SEEK_SET); - nchar = 0; - while (fgets(line, sizeof line, Fortfile->inf) != NULL && - !STR_ENDSTRING(line, Fortfile->tbl)) - nchar += strlen(line); - } - Fort_len = nchar; - - return (nchar); -} - -/* - * This routine evaluates the arguments on the command line - */ -static void -getargs(int argc, char *argv[]) -{ - int ignore_case; - char *pat; - int ch; - - ignore_case = FALSE; - pat = NULL; - -#ifdef DEBUG - while ((ch = getopt(argc, argv, "aDefilm:osw")) != -1) -#else - while ((ch = getopt(argc, argv, "aefilm:osw")) != -1) -#endif /* DEBUG */ - switch(ch) { - case 'a': /* any fortune */ - All_forts++; - break; -#ifdef DEBUG - case 'D': - Debug++; - break; -#endif /* DEBUG */ - case 'e': - Equal_probs++; /* scatter un-allocted prob equally */ - break; - case 'f': /* find fortune files */ - Find_files++; - break; - case 'l': /* long ones only */ - Long_only++; - Short_only = FALSE; - break; - case 'o': /* offensive ones only */ - Offend++; - break; - case 's': /* short ones only */ - Short_only++; - Long_only = FALSE; - break; - case 'w': /* give time to read */ - Wait++; - break; - case 'm': /* dump out the fortunes */ - Match++; - pat = optarg; - break; - case 'i': /* case-insensitive match */ - ignore_case++; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (!form_file_list(argv, argc)) - exit(1); /* errors printed through form_file_list() */ - if (Find_files) { - print_file_list(); - exit(0); - } -#ifdef DEBUG - else if (Debug >= 1) - print_file_list(); -#endif /* DEBUG */ - - if (pat != NULL) { - int error; - - if (ignore_case) - pat = conv_pat(pat); - error = regcomp(&Re_pat, pat, REG_BASIC); - if (error) { - fprintf(stderr, "regcomp(%s) fails\n", pat); - exit(1); - } - } -} - -/* - * form_file_list: - * Form the file list from the file specifications. - */ -static int -form_file_list(char **files, int file_cnt) -{ - int i, percent; - char *sp; - char **pstr; - - if (file_cnt == 0) { - if (Find_files) { - Fortunes_only = TRUE; - pstr = Fortune_path_arr; - i = 0; - while (*pstr) { - i += add_file(NO_PROB, *pstr++, NULL, - &File_list, &File_tail, NULL); - } - Fortunes_only = FALSE; - if (!i) { - fprintf(stderr, "No fortunes found in %s.\n", - Fortune_path); - } - return (i != 0); - } else { - pstr = Fortune_path_arr; - i = 0; - while (*pstr) { - i += add_file(NO_PROB, "fortunes", *pstr++, - &File_list, &File_tail, NULL); - } - if (!i) { - fprintf(stderr, "No fortunes found in %s.\n", - Fortune_path); - } - return (i != 0); - } - } - for (i = 0; i < file_cnt; i++) { - percent = NO_PROB; - if (!isdigit((unsigned char)files[i][0])) - sp = files[i]; - else { - percent = 0; - for (sp = files[i]; isdigit((unsigned char)*sp); sp++) - percent = percent * 10 + *sp - '0'; - if (percent > 100) { - fprintf(stderr, "percentages must be <= 100\n"); - return (FALSE); - } - if (*sp == '.') { - fprintf(stderr, "percentages must be integers\n"); - return (FALSE); - } - /* - * If the number isn't followed by a '%', then - * it was not a percentage, just the first part - * of a file name which starts with digits. - */ - if (*sp != '%') { - percent = NO_PROB; - sp = files[i]; - } - else if (*++sp == '\0') { - if (++i >= file_cnt) { - fprintf(stderr, "percentages must precede files\n"); - return (FALSE); - } - sp = files[i]; - } - } - if (strcmp(sp, "all") == 0) { - pstr = Fortune_path_arr; - i = 0; - while (*pstr) { - i += add_file(NO_PROB, *pstr++, NULL, - &File_list, &File_tail, NULL); - } - if (!i) { - fprintf(stderr, "No fortunes found in %s.\n", - Fortune_path); - return (FALSE); - } - } else if (!add_file(percent, sp, NULL, &File_list, - &File_tail, NULL)) { - return (FALSE); - } - } - - return (TRUE); -} - -/* - * add_file: - * Add a file to the file list. - */ -static int -add_file(int percent, const char *file, const char *dir, FILEDESC **head, - FILEDESC **tail, FILEDESC *parent) -{ - FILEDESC *fp; - int fd; - const char *path; - char *tpath, *offensive; - bool was_malloc; - bool isdir; - - if (dir == NULL) { - path = file; - tpath = NULL; - was_malloc = FALSE; - } - else { - tpath = do_malloc((unsigned int)(strlen(dir) + strlen(file) + 2)); - strcat(strcat(strcpy(tpath, dir), "/"), file); - path = tpath; - was_malloc = TRUE; - } - if ((isdir = is_dir(path)) && parent != NULL) { - if (was_malloc) - free(tpath); - return (FALSE); /* don't recurse */ - } - offensive = NULL; - if (!isdir && parent == NULL && (All_forts || Offend) && - !is_off_name(path)) { - offensive = off_name(path); - if (Offend) { - if (was_malloc) - free(tpath); - path = tpath = offensive; - offensive = NULL; - was_malloc = TRUE; - DPRINTF(1, (stderr, "\ttrying \"%s\"\n", path)); - file = off_name(file); - } - } - - DPRINTF(1, (stderr, "adding file \"%s\"\n", path)); -over: - if ((fd = open(path, O_RDONLY)) < 0) { - /* - * This is a sneak. If the user said -a, and if the - * file we're given isn't a file, we check to see if - * there is a -o version. If there is, we treat it as - * if *that* were the file given. We only do this for - * individual files -- if we're scanning a directory, - * we'll pick up the -o file anyway. - */ - if (All_forts && offensive != NULL) { - if (was_malloc) - free(tpath); - path = tpath = offensive; - offensive = NULL; - was_malloc = TRUE; - DPRINTF(1, (stderr, "\ttrying \"%s\"\n", path)); - file = off_name(file); - goto over; - } - if (dir == NULL && file[0] != '/') { - int i = 0; - char **pstr = Fortune_path_arr; - - while (*pstr) { - i += add_file(percent, file, *pstr++, - head, tail, parent); - } - if (!i) { - fprintf(stderr, "No '%s' found in %s.\n", - file, Fortune_path); - } - return (i != 0); - } - /* - if (parent == NULL) - perror(path); - */ - if (was_malloc) - free(tpath); - return (FALSE); - } - - DPRINTF(2, (stderr, "path = \"%s\"\n", path)); - - fp = new_fp(); - fp->fd = fd; - fp->percent = percent; - fp->name = file; - fp->path = path; - fp->parent = parent; - - if ((isdir && !add_dir(fp)) || - (!isdir && - !is_fortfile(path, &fp->datfile, &fp->posfile, (parent != NULL)))) - { - if (parent == NULL) - fprintf(stderr, - "fortune:%s not a fortune file or directory\n", - path); - if (was_malloc) - free(tpath); - do_free(fp->datfile); - do_free(fp->posfile); - free(fp); - do_free(offensive); - return (FALSE); - } - /* - * If the user said -a, we need to make this node a pointer to - * both files, if there are two. We don't need to do this if - * we are scanning a directory, since the scan will pick up the - * -o file anyway. - */ - if (All_forts && parent == NULL && !is_off_name(path)) - all_forts(fp, offensive); - if (*head == NULL) - *head = *tail = fp; - else if (fp->percent == NO_PROB) { - (*tail)->next = fp; - fp->prev = *tail; - *tail = fp; - } - else { - (*head)->prev = fp; - fp->next = *head; - *head = fp; - } - if (WriteToDisk) - fp->was_pos_file = (access(fp->posfile, W_OK) >= 0); - - return (TRUE); -} - -/* - * new_fp: - * Return a pointer to an initialized new FILEDESC. - */ -static FILEDESC * -new_fp(void) -{ - FILEDESC *fp; - - fp = do_malloc(sizeof(*fp)); - fp->datfd = -1; - fp->pos = POS_UNKNOWN; - fp->inf = NULL; - fp->fd = -1; - fp->percent = NO_PROB; - fp->read_tbl = FALSE; - fp->next = NULL; - fp->prev = NULL; - fp->child = NULL; - fp->parent = NULL; - fp->datfile = NULL; - fp->posfile = NULL; - - return (fp); -} - -/* - * off_name: - * Return a pointer to the offensive version of a file of this name. - */ -static char * -off_name(const char *file) -{ - char *new; - - new = copy(file, (unsigned int) (strlen(file) + 2)); - - return (strcat(new, "-o")); -} - -/* - * is_off_name: - * Is the file an offensive-style name? - */ -static int -is_off_name(const char *file) -{ - int len; - - len = strlen(file); - - return (len >= 3 && file[len - 2] == '-' && file[len - 1] == 'o'); -} - -/* - * all_forts: - * Modify a FILEDESC element to be the parent of two children if - * there are two children to be a parent of. - */ -static void -all_forts(FILEDESC *fp, char *offensive) -{ - char *sp; - FILEDESC *scene, *obscene; - int fd; - char *datfile, *posfile; - - if (fp->child != NULL) /* this is a directory, not a file */ - return; - if (!is_fortfile(offensive, &datfile, &posfile, FALSE)) - return; - if ((fd = open(offensive, O_RDONLY)) < 0) - return; - DPRINTF(1, (stderr, "adding \"%s\" because of -a\n", offensive)); - scene = new_fp(); - obscene = new_fp(); - *scene = *fp; - - fp->num_children = 2; - fp->child = scene; - scene->next = obscene; - obscene->next = NULL; - scene->child = obscene->child = NULL; - scene->parent = obscene->parent = fp; - - fp->fd = -1; - scene->percent = obscene->percent = NO_PROB; - - obscene->fd = fd; - obscene->inf = NULL; - obscene->path = offensive; - if ((sp = strrchr(offensive, '/')) == NULL) - obscene->name = offensive; - else - obscene->name = ++sp; - obscene->datfile = datfile; - obscene->posfile = posfile; - obscene->read_tbl = false; - if (WriteToDisk) - obscene->was_pos_file = (access(obscene->posfile, W_OK) >= 0); -} - -/* - * add_dir: - * Add the contents of an entire directory. - */ -static int -add_dir(FILEDESC *fp) -{ - DIR *dir; - struct dirent *dirent; - FILEDESC *tailp; - char *name; - - (void) close(fp->fd); - fp->fd = -1; - if ((dir = opendir(fp->path)) == NULL) { - perror(fp->path); - return (FALSE); - } - tailp = NULL; - DPRINTF(1, (stderr, "adding dir \"%s\"\n", fp->path)); - fp->num_children = 0; - while ((dirent = readdir(dir)) != NULL) { - if (dirent->d_namlen == 0) - continue; - name = copy(dirent->d_name, dirent->d_namlen); - if (add_file(NO_PROB, name, fp->path, &fp->child, &tailp, fp)) - fp->num_children++; - else - free(name); - } - if (fp->num_children == 0) { - (void) fprintf(stderr, - "fortune: %s: No fortune files in directory.\n", fp->path); - return (FALSE); - } - - return (TRUE); -} - -/* - * is_dir: - * Return TRUE if the file is a directory, FALSE otherwise. - */ -static int -is_dir(const char *file) -{ - struct stat sbuf; - - if (stat(file, &sbuf) < 0) - return (FALSE); - - return (sbuf.st_mode & S_IFDIR); -} - -/* - * is_fortfile: - * Return TRUE if the file is a fortune database file. We try and - * exclude files without reading them if possible to avoid - * overhead. Files which start with ".", or which have "illegal" - * suffixes, as contained in suflist[], are ruled out. - */ -/* ARGSUSED */ -static int -is_fortfile(const char *file, char **datp, char **posp, int check_for_offend) -{ - int i; - const char *sp; - char *datfile; - static const char *suflist[] = { - /* list of "illegal" suffixes" */ - "dat", "pos", "c", "h", "p", "i", "f", - "pas", "ftn", "ins.c", "ins,pas", - "ins.ftn", "sml", - NULL - }; - - DPRINTF(2, (stderr, "is_fortfile(%s) returns ", file)); - - /* - * Preclude any -o files for offendable people, and any non -o - * files for completely offensive people. - */ - if (check_for_offend && !All_forts) { - i = strlen(file); - if (Offend ^ (file[i - 2] == '-' && file[i - 1] == 'o')) { - DPRINTF(2, (stderr, "FALSE (offending file)\n")); - return (FALSE); - } - } - - if ((sp = strrchr(file, '/')) == NULL) - sp = file; - else - sp++; - if (*sp == '.') { - DPRINTF(2, (stderr, "FALSE (file starts with '.')\n")); - return (FALSE); - } - if (Fortunes_only && strncmp(sp, "fortunes", 8) != 0) { - DPRINTF(2, (stderr, "FALSE (check fortunes only)\n")); - return (FALSE); - } - if ((sp = strrchr(sp, '.')) != NULL) { - sp++; - for (i = 0; suflist[i] != NULL; i++) - if (strcmp(sp, suflist[i]) == 0) { - DPRINTF(2, (stderr, "FALSE (file has suffix \".%s\")\n", sp)); - return (FALSE); - } - } - - datfile = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for ".dat" */ - strcat(datfile, ".dat"); - if (access(datfile, R_OK) < 0) { - DPRINTF(2, (stderr, "FALSE (no readable \".dat\" file)\n")); - free(datfile); - return (FALSE); - } - if (datp != NULL) - *datp = datfile; - else - free(datfile); - if (posp != NULL) { - if (WriteToDisk) { - *posp = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for ".dat" */ - strcat(*posp, ".pos"); - } - else { - *posp = NULL; - } - } - DPRINTF(2, (stderr, "TRUE\n")); - - return (TRUE); -} - -/* - * copy: - * Return a malloc()'ed copy of the string - */ -static char * -copy(const char *str, unsigned int len) -{ - char *new, *sp; - - new = do_malloc(len + 1); - sp = new; - do { - *sp++ = *str; - } while (*str++); - - return (new); -} - -/* - * do_malloc: - * Do a malloc, checking for NULL return. - */ -static void * -do_malloc(unsigned int size) -{ - void *new; - - if ((new = malloc(size)) == NULL) { - (void) fprintf(stderr, "fortune: out of memory.\n"); - exit(1); - } - - return (new); -} - -/* - * do_free: - * Free malloc'ed space, if any. - */ -static void -do_free(void *ptr) -{ - if (ptr != NULL) - free(ptr); -} - -/* - * init_prob: - * Initialize the fortune probabilities. - */ -static void -init_prob(void) -{ - FILEDESC *fp, *last = NULL; - int percent, num_noprob, frac; - - /* - * Distribute the residual probability (if any) across all - * files with unspecified probability (i.e., probability of 0) - * (if any). - */ - - percent = 0; - num_noprob = 0; - for (fp = File_tail; fp != NULL; fp = fp->prev) - if (fp->percent == NO_PROB) { - num_noprob++; - if (Equal_probs) - last = fp; - } else - percent += fp->percent; - DPRINTF(1, (stderr, "summing probabilities:%d%% with %d NO_PROB's", - percent, num_noprob)); - if (percent > 100) { - (void) fprintf(stderr, - "fortune: probabilities sum to %d%% > 100%%!\n", percent); - exit(1); - } else if (percent < 100 && num_noprob == 0) { - (void) fprintf(stderr, - "fortune: no place to put residual probability (%d%% < 100%%)\n", - percent); - exit(1); - } else if (percent == 100 && num_noprob != 0) { - (void) fprintf(stderr, - "fortune: no probability left to put in residual files (100%%)\n"); - exit(1); - } - percent = 100 - percent; - if (Equal_probs) { - if (num_noprob != 0) { - if (num_noprob > 1) { - frac = percent / num_noprob; - DPRINTF(1, (stderr, ", frac = %d%%", frac)); - for (fp = File_tail; fp != last; fp = fp->prev) - if (fp->percent == NO_PROB) { - fp->percent = frac; - percent -= frac; - } - } - last->percent = percent; - DPRINTF(1, (stderr, ", residual = %d%%", percent)); - } - else - DPRINTF(1, (stderr, - ", %d%% distributed over remaining fortunes\n", - percent)); - } - DPRINTF(1, (stderr, "\n")); - -#ifdef DEBUG - if (Debug >= 1) - print_file_list(); -#endif -} - -/* - * get_fort: - * Get the fortune data file's seek pointer for the next fortune. - */ -static void -get_fort(void) -{ - FILEDESC *fp; - int choice; - - if (File_list->next == NULL || File_list->percent == NO_PROB) - fp = File_list; - else { - choice = arc4random_uniform(100); - DPRINTF(1, (stderr, "choice = %d\n", choice)); - for (fp = File_list; fp->percent != NO_PROB; fp = fp->next) - if (choice < fp->percent) - break; - else { - choice -= fp->percent; - DPRINTF(1, (stderr, - " skip \"%s\", %d%% (choice = %d)\n", - fp->name, fp->percent, choice)); - } - DPRINTF(1, (stderr, - "using \"%s\", %d%% (choice = %d)\n", - fp->name, fp->percent, choice)); - } - if (fp->percent != NO_PROB) - get_tbl(fp); - else { - if (fp->next != NULL) { - sum_noprobs(fp); - choice = arc4random_uniform(Noprob_tbl.str_numstr); - DPRINTF(1, (stderr, "choice = %d (of %u) \n", choice, - Noprob_tbl.str_numstr)); - while ((unsigned int)choice >= fp->tbl.str_numstr) { - choice -= fp->tbl.str_numstr; - fp = fp->next; - DPRINTF(1, (stderr, - " skip \"%s\", %u (choice = %d)\n", - fp->name, fp->tbl.str_numstr, - choice)); - } - DPRINTF(1, (stderr, "using \"%s\", %u\n", fp->name, - fp->tbl.str_numstr)); - } - get_tbl(fp); - } - if (fp->child != NULL) { - DPRINTF(1, (stderr, "picking child\n")); - fp = pick_child(fp); - } - Fortfile = fp; - get_pos(fp); - open_dat(fp); - lseek(fp->datfd, - (off_t) (sizeof fp->tbl + fp->pos * sizeof Seekpts[0]), SEEK_SET); - read(fp->datfd, Seekpts, sizeof Seekpts); - Seekpts[0] = be64toh(Seekpts[0]); - Seekpts[1] = be64toh(Seekpts[1]); -} - -/* - * pick_child - * Pick a child from a chosen parent. - */ -static FILEDESC * -pick_child(FILEDESC *parent) -{ - FILEDESC *fp; - int choice; - - if (Equal_probs) { - choice = arc4random_uniform(parent->num_children); - DPRINTF(1, (stderr, " choice = %d (of %d)\n", - choice, parent->num_children)); - for (fp = parent->child; choice--; fp = fp->next) - continue; - DPRINTF(1, (stderr, " using %s\n", fp->name)); - return (fp); - } - else { - get_tbl(parent); - choice = arc4random_uniform(parent->tbl.str_numstr); - DPRINTF(1, (stderr, " choice = %d (of %u)\n", - choice, parent->tbl.str_numstr)); - for (fp = parent->child; (unsigned)choice >= fp->tbl.str_numstr; - fp = fp->next) { - choice -= fp->tbl.str_numstr; - DPRINTF(1, (stderr, "\tskip %s, %u (choice = %d)\n", - fp->name, fp->tbl.str_numstr, choice)); - } - DPRINTF(1, (stderr, " using %s, %u\n", fp->name, - fp->tbl.str_numstr)); - return (fp); - } -} - -/* - * sum_noprobs: - * Sum up all the noprob probabilities, starting with fp. - */ -static void -sum_noprobs(FILEDESC *fp) -{ - static bool did_noprobs = FALSE; - - if (did_noprobs) - return; - zero_tbl(&Noprob_tbl); - while (fp != NULL) { - get_tbl(fp); - sum_tbl(&Noprob_tbl, &fp->tbl); - fp = fp->next; - } - did_noprobs = TRUE; -} - -static int -max(int i, int j) -{ - return (i >= j ? i : j); -} - -/* - * open_fp: - * Assocatiate a FILE * with the given FILEDESC. - */ -static void -open_fp(FILEDESC *fp) -{ - if (fp->inf == NULL && (fp->inf = fdopen(fp->fd, "r")) == NULL) { - perror(fp->path); - exit(1); - } -} - -/* - * open_dat: - * Open up the dat file if we need to. - */ -static void -open_dat(FILEDESC *fp) -{ - if (fp->datfd < 0 && (fp->datfd = open(fp->datfile, O_RDONLY)) < 0) { - perror(fp->datfile); - exit(1); - } -} - -/* - * get_pos: - * Get the position from the pos file, if there is one. If not, - * return a random number. - */ -static void -get_pos(FILEDESC *fp) -{ - int fd; - - assert(fp->read_tbl); - if (fp->pos == POS_UNKNOWN) { - if (WriteToDisk) { - if ((fd = open(fp->posfile, O_RDONLY)) < 0 || - read(fd, &fp->pos, sizeof fp->pos) != sizeof fp->pos) - fp->pos = arc4random_uniform(fp->tbl.str_numstr); - else if (fp->pos >= fp->tbl.str_numstr) - fp->pos %= fp->tbl.str_numstr; - if (fd >= 0) - close(fd); - } - else - fp->pos = arc4random_uniform(fp->tbl.str_numstr); - } - if (++(fp->pos) >= fp->tbl.str_numstr) - fp->pos -= fp->tbl.str_numstr; - DPRINTF(1, (stderr, "pos for %s is %ld\n", fp->name, (long)fp->pos)); -} - -/* - * get_tbl: - * Get the tbl data file the datfile. - */ -static void -get_tbl(FILEDESC *fp) -{ - int fd; - FILEDESC *child; - - if (fp->read_tbl) - return; - if (fp->child == NULL) { - if ((fd = open(fp->datfile, O_RDONLY)) < 0) { - perror(fp->datfile); - exit(1); - } - if (read(fd, (char *) &fp->tbl, sizeof fp->tbl) != sizeof fp->tbl) { - (void)fprintf(stderr, - "fortune: %s corrupted\n", fp->path); - exit(1); - } - /* fp->tbl.str_version = be32toh(fp->tbl.str_version); */ - fp->tbl.str_numstr = be32toh(fp->tbl.str_numstr); - fp->tbl.str_longlen = be32toh(fp->tbl.str_longlen); - fp->tbl.str_shortlen = be32toh(fp->tbl.str_shortlen); - fp->tbl.str_flags = be32toh(fp->tbl.str_flags); - (void) close(fd); - } - else { - zero_tbl(&fp->tbl); - for (child = fp->child; child != NULL; child = child->next) { - get_tbl(child); - sum_tbl(&fp->tbl, &child->tbl); - } - } - fp->read_tbl = TRUE; -} - -/* - * zero_tbl: - * Zero out the fields we care about in a tbl structure. - */ -static void -zero_tbl(STRFILE *tp) -{ - tp->str_numstr = 0; - tp->str_longlen = 0; - tp->str_shortlen = ~0; -} - -/* - * sum_tbl: - * Merge the tbl data of t2 into t1. - */ -static void -sum_tbl(STRFILE *t1, STRFILE *t2) -{ - t1->str_numstr += t2->str_numstr; - if (t1->str_longlen < t2->str_longlen) - t1->str_longlen = t2->str_longlen; - if (t1->str_shortlen > t2->str_shortlen) - t1->str_shortlen = t2->str_shortlen; -} - -#define STR(str) ((str) == NULL ? "NULL" : (str)) - -/* - * print_file_list: - * Print out the file list - */ -static void -print_file_list(void) -{ - print_list(File_list, 0); -} - -/* - * print_list: - * Print out the actual list, recursively. - */ -static void -print_list(FILEDESC *list, int lev) -{ - while (list != NULL) { - fprintf(stderr, "%*s", lev * 4, ""); - if (list->percent == NO_PROB) - fprintf(stderr, "___%%"); - else - fprintf(stderr, "%3d%%", list->percent); - fprintf(stderr, " %s", STR(list->name)); - DPRINTF(1, (stderr, " (%s, %s, %s)", STR(list->path), - STR(list->datfile), STR(list->posfile))); - fprintf(stderr, "\n"); - if (list->child != NULL) - print_list(list->child, lev + 1); - list = list->next; - } -} - -/* - * conv_pat: - * Convert the pattern to an ignore-case equivalent. - */ -static char * -conv_pat(char *orig) -{ - char *sp; - unsigned int cnt; - char *new; - - cnt = 1; /* allow for '\0' */ - for (sp = orig; *sp != '\0'; sp++) - if (isalpha((unsigned char)*sp)) - cnt += 4; - else - cnt++; - if ((new = malloc(cnt)) == NULL) { - fprintf(stderr, "pattern too long for ignoring case\n"); - exit(1); - } - - for (sp = new; *orig != '\0'; orig++) { - if (islower((unsigned char)*orig)) { - *sp++ = '['; - *sp++ = *orig; - *sp++ = toupper((unsigned char)*orig); - *sp++ = ']'; - } - else if (isupper((unsigned char)*orig)) { - *sp++ = '['; - *sp++ = *orig; - *sp++ = tolower((unsigned char)*orig); - *sp++ = ']'; - } - else - *sp++ = *orig; - } - *sp = '\0'; - - return (new); -} - -/* - * find_matches: - * Find all the fortunes which match the pattern we've been given. - */ -static int -find_matches(void) -{ - Fort_len = maxlen_in_list(File_list); - DPRINTF(2, (stderr, "Maximum length is %d\n", Fort_len)); - /* extra length, "%\n" is appended */ - Fortbuf = do_malloc((unsigned int) Fort_len + 10); - - Found_one = FALSE; - matches_in_list(File_list); - - return (Found_one); -} - -/* - * maxlen_in_list - * Return the maximum fortune len in the file list. - */ -static int -maxlen_in_list(FILEDESC *list) -{ - FILEDESC *fp; - int len, maxlen; - - maxlen = 0; - for (fp = list; fp != NULL; fp = fp->next) { - if (fp->child != NULL) { - if ((len = maxlen_in_list(fp->child)) > maxlen) - maxlen = len; - } - else { - get_tbl(fp); - if (fp->tbl.str_longlen > (unsigned int)maxlen) - maxlen = fp->tbl.str_longlen; - } - } - - return (maxlen); -} - -/* - * matches_in_list - * Print out the matches from the files in the list. - */ -static void -matches_in_list(FILEDESC *list) -{ - char *sp, *p; - FILEDESC *fp; - int in_file; - unsigned char ch; - - for (fp = list; fp != NULL; fp = fp->next) { - if (fp->child != NULL) { - matches_in_list(fp->child); - continue; - } - DPRINTF(1, (stderr, "searching in %s\n", fp->path)); - open_fp(fp); - sp = Fortbuf; - in_file = FALSE; - while (fgets(sp, Fort_len, fp->inf) != NULL) - if (fp->tbl.str_flags & STR_COMMENTS - && sp[0] == fp->tbl.str_delim - && sp[1] == fp->tbl.str_delim) - continue; - else if (!STR_ENDSTRING(sp, fp->tbl)) - sp += strlen(sp); - else { - *sp = '\0'; - if (fp->tbl.str_flags & STR_ROTATED) - for (p = Fortbuf; (ch = *p) != '\0'; ++p) { - if (isascii(ch)) { - if (isupper(ch)) - *p = 'A' + (ch - 'A' + 13) % 26; - else if (islower(ch)) - *p = 'a' + (ch - 'a' + 13) % 26; - } - } - if (regexec(&Re_pat, Fortbuf, 0, NULL, 0) != REG_NOMATCH) { - printf("%c%c", fp->tbl.str_delim, - fp->tbl.str_delim); - if (!in_file) { - printf(" (%s)", fp->name); - Found_one = TRUE; - in_file = TRUE; - } - putchar('\n'); - (void) fwrite(Fortbuf, 1, (sp - Fortbuf), stdout); - } - sp = Fortbuf; - } - } -} - -static void -usage(void) -{ - (void) fprintf(stderr, "fortune [-a"); -#ifdef DEBUG - (void) fprintf(stderr, "D"); -#endif /* DEBUG */ - (void) fprintf(stderr, "efilosw]"); - (void) fprintf(stderr, " [-m pattern]"); - (void) fprintf(stderr, " [[N%%] file/directory/all]\n"); - exit(1); -} - -/* - * getpath - * Set up file search patch from environment var FORTUNE_PATH; - * if not set, use the compiled in FORTDIR. - */ - -static void -getpath(void) -{ - int nstr, foundenv; - char *pch, **ppch, *str, *path; - - foundenv = 1; - Fortune_path = getenv("FORTUNE_PATH"); - if (Fortune_path == NULL) { - Fortune_path = FORTDIR; - foundenv = 0; - } - path = strdup(Fortune_path); - - for (nstr = 2, pch = path; *pch != '\0'; pch++) { - if (*pch == ':') - nstr++; - } - - ppch = Fortune_path_arr = (char **)calloc(nstr, sizeof(char *)); - - nstr = 0; - str = strtok(path, ":"); - while (str) { - if (is_dir(str)) { - nstr++; - *ppch++ = str; - } - str = strtok(NULL, ":"); - } - - if (nstr == 0) { - if (foundenv == 1) { - fprintf(stderr, - "fortune: FORTUNE_PATH: None of the specified " - "directories found.\n"); - exit(1); - } - free(path); - Fortune_path_arr[0] = strdup(FORTDIR); - } -} Index: usr.bin/fortune/fortune/pathnames.h =================================================================== --- usr.bin/fortune/fortune/pathnames.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 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. - * 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. - * - * @(#)pathnames.h 8.1 (Berkeley) 5/31/93 - * $FreeBSD$ - */ - -#define FORTDIR "/usr/share/games/fortune:" \ - "/usr/local/share/games/fortune" Index: usr.bin/fortune/strfile/Makefile =================================================================== --- usr.bin/fortune/strfile/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 5/31/93 -# $FreeBSD$ - -PROG= strfile -MAN= strfile.8 -MLINKS= strfile.8 unstr.8 - -.include Index: usr.bin/fortune/strfile/Makefile.depend =================================================================== --- usr.bin/fortune/strfile/Makefile.depend +++ /dev/null @@ -1,17 +0,0 @@ -# $FreeBSD$ -# Autogenerated - do NOT edit! - -DIRDEPS = \ - gnu/lib/csu \ - include \ - include/xlocale \ - lib/${CSU_DIR} \ - lib/libc \ - lib/libcompiler_rt \ - - -.include - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif Index: usr.bin/fortune/strfile/strfile.h =================================================================== --- usr.bin/fortune/strfile/strfile.h +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ken Arnold. - * - * 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. - * - * @(#)strfile.h 8.1 (Berkeley) 5/31/93 - */ -/* $FreeBSD$ */ - -#include - -#define STR_ENDSTRING(line,tbl) \ - (((unsigned char)(line)[0]) == (tbl).str_delim && (line)[1] == '\n') - -typedef struct { /* information table */ -#define VERSION 1 - uint32_t str_version; /* version number */ - uint32_t str_numstr; /* # of strings in the file */ - uint32_t str_longlen; /* length of longest string */ - uint32_t str_shortlen; /* length of shortest string */ -#define STR_RANDOM 0x1 /* randomized pointers */ -#define STR_ORDERED 0x2 /* ordered pointers */ -#define STR_ROTATED 0x4 /* rot-13'd text */ -#define STR_COMMENTS 0x8 /* embedded comments */ - uint32_t str_flags; /* bit field for flags */ - unsigned char stuff[4]; /* 64-bit aligned space */ -#define str_delim stuff[0] /* delimiting character */ -} STRFILE; Index: usr.bin/fortune/strfile/strfile.8 =================================================================== --- usr.bin/fortune/strfile/strfile.8 +++ /dev/null @@ -1,159 +0,0 @@ -.\" Copyright (c) 1989, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Ken Arnold. -.\" -.\" 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. -.\" -.\" @(#)strfile.8 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" -.Dd February 17, 2005 -.Dt STRFILE 8 -.Os -.Sh NAME -.Nm strfile , -.Nm unstr -.Nd "create a random access file for storing strings" -.Sh SYNOPSIS -.Nm -.Op Fl Ciorsx -.Op Fl c Ar char -.Ar source_file -.Op Ar output_file -.Nm unstr -.Ar source_file -.Sh DESCRIPTION -The -.Nm -utility -reads a file containing groups of lines separated by a line containing -a single percent -.Ql % -sign and creates a data file which contains -a header structure and a table of file offsets for each group of lines. -This allows random access of the strings. -.Pp -The output file, if not specified on the command line, is named -.Ar source_file Ns Pa .dat . -.Pp -The options are as follows: -.Bl -tag -width ".Fl c Ar char" -.It Fl C -Flag the file as containing comments. -This option cases the -.Dv STR_COMMENTS -bit in the header -.Va str_flags -field to be set. -Comments are designated by two delimiter characters at the -beginning of the line, though -.Nm -does not give any special -treatment to comment lines. -.It Fl c Ar char -Change the delimiting character from the percent sign to -.Ar char . -.It Fl i -Ignore case when ordering the strings. -.It Fl o -Order the strings in alphabetical order. -The offset table will be sorted in the alphabetical order of the -groups of lines referenced. -Any initial non-alphanumeric characters are ignored. -This option causes the -.Dv STR_ORDERED -bit in the header -.Va str_flags -field to be set. -.It Fl r -Randomize access to the strings. -Entries in the offset table will be randomly ordered. -This option causes the -.Dv STR_RANDOM -bit in the header -.Va str_flags -field to be set. -.It Fl s -Run silently; do not give a summary message when finished. -.It Fl x -Note that each alphabetic character in the groups of lines is rotated -13 positions in a simple caesar cypher. -This option causes the -.Dv STR_ROTATED -bit in the header -.Va str_flags -field to be set. -.El -.Pp -The format of the header is: -.Bd -literal -#define VERSION 1 -uint32_t str_version; /* version number */ -uint32_t str_numstr; /* # of strings in the file */ -uint32_t str_longlen; /* length of longest string */ -uint32_t str_shortlen; /* length of shortest string */ -#define STR_RANDOM 0x1 /* randomized pointers */ -#define STR_ORDERED 0x2 /* ordered pointers */ -#define STR_ROTATED 0x4 /* rot-13'd text */ -#define STR_COMMENTS 0x8 /* embedded comments */ -uint32_t str_flags; /* bit field for flags */ -char str_delim; /* delimiting character */ -.Ed -.Pp -All fields are written in network byte order. -.Pp -The purpose of -.Nm unstr -is to undo the work of -.Nm . -It prints out the strings contained in the file -.Ar source_file -in the order that they are listed in -the header file -.Ar source_file Ns Pa .dat -to standard output. -It is possible to create sorted versions of input files by using -.Fl o -when -.Nm -is run and then using -.Nm unstr -to dump them out in the table order. -.Sh FILES -.Bl -tag -width ".Pa strfile.dat" -compact -.It Pa strfile.dat -default output file. -.El -.Sh SEE ALSO -.Xr byteorder 3 , -.Xr fortune 6 -.Sh HISTORY -The -.Nm -utility first appeared in -.Bx 4.4 . Index: usr.bin/fortune/strfile/strfile.c =================================================================== --- usr.bin/fortune/strfile/strfile.c +++ /dev/null @@ -1,454 +0,0 @@ -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ken Arnold. - * - * 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. - */ - -#if 0 -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static const char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; -#endif /* not lint */ -#endif -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "strfile.h" - -/* - * This program takes a file composed of strings separated by - * lines starting with two consecutive delimiting character (default - * character is '%') and creates another file which consists of a table - * describing the file (structure from "strfile.h"), a table of seek - * pointers to the start of the strings, and the strings, each terminated - * by a null byte. Usage: - * - * % strfile [-iorsx] [ -cC ] sourcefile [ datafile ] - * - * C - Allow comments marked by a double delimiter at line's beginning - * c - Change delimiting character from '%' to 'C' - * s - Silent. Give no summary of data processed at the end of - * the run. - * o - order the strings in alphabetic order - * i - if ordering, ignore case - * r - randomize the order of the strings - * x - set rotated bit - * - * Ken Arnold Sept. 7, 1978 -- - * - * Added ordering options. - */ - -#define STORING_PTRS (Oflag || Rflag) -#define CHUNKSIZE 512 - -#define ALLOC(ptr, sz) do { \ - if (ptr == NULL) \ - ptr = malloc(CHUNKSIZE * sizeof(*ptr)); \ - else if (((sz) + 1) % CHUNKSIZE == 0) \ - ptr = realloc(ptr, ((sz) + CHUNKSIZE) * sizeof(*ptr)); \ - if (ptr == NULL) { \ - fprintf(stderr, "out of space\n"); \ - exit(1); \ - } \ - } while (0) - -typedef struct { - int first; - off_t pos; -} STR; - -static char *Infile = NULL, /* input file name */ - Outfile[MAXPATHLEN] = "", /* output file name */ - Delimch = '%'; /* delimiting character */ - -static int Cflag = false; /* embedded comments */ -static int Sflag = false; /* silent run flag */ -static int Oflag = false; /* ordering flag */ -static int Iflag = false; /* ignore case flag */ -static int Rflag = false; /* randomize order flag */ -static int Xflag = false; /* set rotated bit */ -static uint32_t Num_pts = 0; /* number of pointers/strings */ - -static off_t *Seekpts; - -static FILE *Sort_1, *Sort_2; /* pointers for sorting */ - -static STRFILE Tbl; /* statistics table */ - -static STR *Firstch; /* first chars of each string */ - -static void add_offset(FILE *, off_t); -static int cmp_str(const void *, const void *); -static int stable_collate_range_cmp(int, int); -static void do_order(void); -static void getargs(int, char **); -static void randomize(void); -static void usage(void); - -/* - * main: - * Drive the sucker. There are two main modes -- either we store - * the seek pointers, if the table is to be sorted or randomized, - * or we write the pointer directly to the file, if we are to stay - * in file order. If the former, we allocate and re-allocate in - * CHUNKSIZE blocks; if the latter, we just write each pointer, - * and then seek back to the beginning to write in the table. - */ -int -main(int ac, char *av[]) -{ - char *sp, *nsp, dc; - FILE *inf, *outf; - off_t last_off, pos, *p; - size_t length; - int first; - uint32_t cnt; - STR *fp; - static char string[257]; - - setlocale(LC_ALL, ""); - - getargs(ac, av); /* evalute arguments */ - dc = Delimch; - if ((inf = fopen(Infile, "r")) == NULL) { - perror(Infile); - exit(1); - } - - if ((outf = fopen(Outfile, "w")) == NULL) { - perror(Outfile); - exit(1); - } - if (!STORING_PTRS) - fseek(outf, (long)sizeof(Tbl), SEEK_SET); - - /* - * Write the strings onto the file - */ - - Tbl.str_longlen = 0; - Tbl.str_shortlen = 0xffffffff; - Tbl.str_delim = dc; - Tbl.str_version = VERSION; - first = Oflag; - add_offset(outf, ftello(inf)); - last_off = 0; - do { - sp = fgets(string, 256, inf); - if (sp == NULL || (sp[0] == dc && sp[1] == '\n')) { - pos = ftello(inf); - length = (size_t)(pos - last_off) - - (sp != NULL ? strlen(sp) : 0); - last_off = pos; - if (length == 0) - continue; - add_offset(outf, pos); - if ((size_t)Tbl.str_longlen < length) - Tbl.str_longlen = length; - if ((size_t)Tbl.str_shortlen > length) - Tbl.str_shortlen = length; - first = Oflag; - } - else if (first) { - for (nsp = sp; !isalnum((unsigned char)*nsp); nsp++) - continue; - ALLOC(Firstch, Num_pts); - fp = &Firstch[Num_pts - 1]; - if (Iflag && isupper((unsigned char)*nsp)) - fp->first = tolower((unsigned char)*nsp); - else - fp->first = *nsp; - fp->pos = Seekpts[Num_pts - 1]; - first = false; - } - } while (sp != NULL); - - /* - * write the tables in - */ - - fclose(inf); - Tbl.str_numstr = Num_pts - 1; - - if (Cflag) - Tbl.str_flags |= STR_COMMENTS; - - if (Oflag) - do_order(); - else if (Rflag) - randomize(); - - if (Xflag) - Tbl.str_flags |= STR_ROTATED; - - if (!Sflag) { - printf("\"%s\" created\n", Outfile); - if (Num_pts == 2) - puts("There was 1 string"); - else - printf("There were %u strings\n", Num_pts - 1); - printf("Longest string: %u byte%s\n", Tbl.str_longlen, - Tbl.str_longlen == 1 ? "" : "s"); - printf("Shortest string: %u byte%s\n", Tbl.str_shortlen, - Tbl.str_shortlen == 1 ? "" : "s"); - } - - rewind(outf); - Tbl.str_version = htobe32(Tbl.str_version); - Tbl.str_numstr = htobe32(Tbl.str_numstr); - Tbl.str_longlen = htobe32(Tbl.str_longlen); - Tbl.str_shortlen = htobe32(Tbl.str_shortlen); - Tbl.str_flags = htobe32(Tbl.str_flags); - fwrite((char *)&Tbl, sizeof(Tbl), 1, outf); - if (STORING_PTRS) { - for (p = Seekpts, cnt = Num_pts; cnt--; ++p) - *p = htobe64(*p); - fwrite(Seekpts, sizeof(*Seekpts), (size_t)Num_pts, outf); - } - fclose(outf); - exit(0); -} - -/* - * This routine evaluates arguments from the command line - */ -void -getargs(int argc, char **argv) -{ - int ch; - - while ((ch = getopt(argc, argv, "Cc:iorsx")) != -1) - switch(ch) { - case 'C': /* embedded comments */ - Cflag++; - break; - case 'c': /* new delimiting char */ - Delimch = *optarg; - if (!isascii(Delimch)) { - printf("bad delimiting character: '\\%o\n'", - (unsigned char)Delimch); - } - break; - case 'i': /* ignore case in ordering */ - Iflag++; - break; - case 'o': /* order strings */ - Oflag++; - break; - case 'r': /* randomize pointers */ - Rflag++; - break; - case 's': /* silent */ - Sflag++; - break; - case 'x': /* set the rotated bit */ - Xflag++; - break; - case '?': - default: - usage(); - } - argv += optind; - - if (*argv) { - Infile = *argv; - if (*++argv) - strcpy(Outfile, *argv); - } - if (!Infile) { - puts("No input file name"); - usage(); - } - if (*Outfile == '\0') { - strlcpy(Outfile, Infile, sizeof(Outfile)); - strlcat(Outfile, ".dat", sizeof(Outfile)); - } -} - -void -usage(void) -{ - fprintf(stderr, - "strfile [-Ciorsx] [-c char] source_file [output_file]\n"); - exit(1); -} - -/* - * add_offset: - * Add an offset to the list, or write it out, as appropriate. - */ -void -add_offset(FILE *fp, off_t off) -{ - off_t beoff; - - if (!STORING_PTRS) { - beoff = htobe64(off); - fwrite(&beoff, 1, sizeof(beoff), fp); - } else { - ALLOC(Seekpts, Num_pts + 1); - Seekpts[Num_pts] = off; - } - Num_pts++; -} - -/* - * do_order: - * Order the strings alphabetically (possibly ignoring case). - */ -void -do_order(void) -{ - uint32_t i; - off_t *lp; - STR *fp; - - Sort_1 = fopen(Infile, "r"); - Sort_2 = fopen(Infile, "r"); - qsort(Firstch, (size_t)Tbl.str_numstr, sizeof(*Firstch), cmp_str); - i = Tbl.str_numstr; - lp = Seekpts; - fp = Firstch; - while (i--) - *lp++ = fp++->pos; - fclose(Sort_1); - fclose(Sort_2); - Tbl.str_flags |= STR_ORDERED; -} - -static int -stable_collate_range_cmp(int c1, int c2) -{ - static char s1[2], s2[2]; - int ret; - - s1[0] = c1; - s2[0] = c2; - if ((ret = strcoll(s1, s2)) != 0) - return (ret); - return (c1 - c2); -} - -/* - * cmp_str: - * Compare two strings in the file - */ -int -cmp_str(const void *s1, const void *s2) -{ - const STR *p1, *p2; - int c1, c2, n1, n2, r; - -#define SET_N(nf,ch) (nf = (ch == '\n')) -#define IS_END(ch,nf) (ch == EOF || (ch == (unsigned char)Delimch && nf)) - - p1 = (const STR *)s1; - p2 = (const STR *)s2; - - c1 = (unsigned char)p1->first; - c2 = (unsigned char)p2->first; - if ((r = stable_collate_range_cmp(c1, c2)) != 0) - return (r); - - fseeko(Sort_1, p1->pos, SEEK_SET); - fseeko(Sort_2, p2->pos, SEEK_SET); - - n1 = false; - n2 = false; - while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0' && c1 != EOF) - SET_N(n1, c1); - while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0' && c2 != EOF) - SET_N(n2, c2); - - while (!IS_END(c1, n1) && !IS_END(c2, n2)) { - if (Iflag) { - if (isupper(c1)) - c1 = tolower(c1); - if (isupper(c2)) - c2 = tolower(c2); - } - if ((r = stable_collate_range_cmp(c1, c2)) != 0) - return (r); - SET_N(n1, c1); - SET_N(n2, c2); - c1 = getc(Sort_1); - c2 = getc(Sort_2); - } - if (IS_END(c1, n1)) - c1 = 0; - if (IS_END(c2, n2)) - c2 = 0; - - return (stable_collate_range_cmp(c1, c2)); -} - -/* - * randomize: - * Randomize the order of the string table. We must be careful - * not to randomize across delimiter boundaries. All - * randomization is done within each block. - */ -void -randomize(void) -{ - uint32_t cnt, i; - off_t tmp; - off_t *sp; - - Tbl.str_flags |= STR_RANDOM; - cnt = Tbl.str_numstr; - - /* - * move things around randomly - */ - - for (sp = Seekpts; cnt > 0; cnt--, sp++) { - i = arc4random_uniform(cnt); - tmp = sp[0]; - sp[0] = sp[i]; - sp[i] = tmp; - } -} Index: usr.bin/fortune/tools/Do_spell =================================================================== --- usr.bin/fortune/tools/Do_spell +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -# -# @(#)Do_spell 8.1 (Berkeley) 5/31/93 -# - -F=_spell.$$ -echo $1 -spell < $1 > $F -sort $F $1.sp.ok | uniq -u | column -rm -f $F Index: usr.bin/fortune/tools/Do_troff =================================================================== --- usr.bin/fortune/tools/Do_troff +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/csh -f -# -# @(#)Do_troff 8.1 (Berkeley) 5/31/93 -# - -set file=$1 -shift -( echo ".ds Se $file" ; cat Troff.mac ; sed -f Troff.sed $file ) | \ - $* -me >& $file.tr -echo troff output in $file.tr Index: usr.bin/fortune/tools/Troff.mac =================================================================== --- usr.bin/fortune/tools/Troff.mac +++ /dev/null @@ -1,26 +0,0 @@ -.nr tp 8 -.nr hm 3v -.nr fm 2v -.nr tm 5v -.nr bm 4v -.cs R -.sc -.sz 6 -.ll +10n -.lt \n(.l -.de $h -.tl 'Fortune Database'\\*(Se'\*(td' -.. -.de $f -.tl ''- % -'' -.. -.2c -.nf -.ta -.ta 8n 16n 24n 32n 40n 48n 56n 64n 72n 80n -.de %% -.sp .3 -.ce -\(sq\|\(sq\|\(sq\|\(sq\|\(sq\|\(sq\|\(sq\|\(sq\|\(sq -.sp .2 -.. Index: usr.bin/fortune/tools/Troff.sed =================================================================== --- usr.bin/fortune/tools/Troff.sed +++ /dev/null @@ -1,13 +0,0 @@ -/^['.]/s//\\\&&/ -/^%%/s//.&/ -/--/s//\\*-/g -/_a-squared cos 2(phi)/s//\\fIa\\fP\\u2\\d cos 2\\(*f/ -/__**\([a-zA-Z]*\)/s//\\fI\1\\fP/g -/"\(.\)/s//\1\\*:/g -/`\(.\)/s//\1\\*`/g -/'\(.\)/s//\1\\*'/g -/~\(.\)/s//\1\\*~/g -/\^\(.\)/s//\1\\*^/g -/,\(.\)/s//\1\\*,/g -/\(.\)\(.\)/s//\\o_\1\2_/g -/*/s//\\(bs/g Index: usr.bin/fortune/tools/do_sort =================================================================== --- usr.bin/fortune/tools/do_sort +++ /dev/null @@ -1,13 +0,0 @@ -#! /bin/sh -# -# @(#)do_sort 8.1 (Berkeley) 5/31/93 -# $FreeBSD$ -# -# an aggressive little script for sorting the fortune files -# depends on octal 02 and 03 not being anywhere in the files. - -sp="/usr/bin/sort -dfu -T /var/tmp" - -sed 's/^%$//' | tr '\12' '\3' | tr '\2' '\12' | - sed -e 's/^//' -e '/^$/d' -e 's/$/%/' | - $sp | tr '\3' '\12' Index: usr.bin/fortune/tools/do_uniq.py =================================================================== --- usr.bin/fortune/tools/do_uniq.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/local/bin/python -# -# $FreeBSD$ -# -# an aggressive little script for trimming duplicate cookies -from __future__ import print_function -import argparse -import re - -wordlist = [ - 'hadnot', - 'donot', 'hadnt', - 'dont', 'have', 'more', 'will', 'your', - 'and', 'are', 'had', 'the', 'you', - 'am', 'an', 'is', 'll', 've', 'we', - 'a', 'd', 'i', 'm', 's', -] - - -def hash(fortune): - f = fortune - f = f.lower() - f = re.sub('[\W_]', '', f) - for word in wordlist: - f = re.sub(word, '', f) -# f = re.sub('[aeiouy]', '', f) -# f = re.sub('[^aeiouy]', '', f) - f = f[:30] -# f = f[-30:] - return f - - -def edit(datfile): - dups = {} - fortunes = [] - fortune = "" - with open(datfile, "r") as datfiledf: - for line in datfiledf: - if line == "%\n": - key = hash(fortune) - if key not in dups: - dups[key] = [] - dups[key].append(fortune) - fortunes.append(fortune) - fortune = "" - else: - fortune += line - for key in list(dups.keys()): - if len(dups[key]) == 1: - del dups[key] - with open(datfile + "~", "w") as o: - for fortune in fortunes: - key = hash(fortune) - if key in dups: - print('\n' * 50) - for f in dups[key]: - if f != fortune: - print(f, '%') - print(fortune, '%') - if input("Remove last fortune? ") == 'y': - del dups[key] - continue - o.write(fortune + "%\n") - -parser = argparse.ArgumentParser(description="trimming duplicate cookies") -parser.add_argument("filename", type=str, nargs=1) -args = parser.parse_args() -edit(args.filename[0]) Index: usr.bin/fortune/unstr/Makefile =================================================================== --- usr.bin/fortune/unstr/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 5/31/93 -# $FreeBSD$ - -PROG= unstr -MAN= -CFLAGS+= -I${FORTUNE_SRC}/strfile - -.include Index: usr.bin/fortune/unstr/Makefile.depend =================================================================== --- usr.bin/fortune/unstr/Makefile.depend +++ /dev/null @@ -1,17 +0,0 @@ -# $FreeBSD$ -# Autogenerated - do NOT edit! - -DIRDEPS = \ - gnu/lib/csu \ - include \ - include/xlocale \ - lib/${CSU_DIR} \ - lib/libc \ - lib/libcompiler_rt \ - - -.include - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif Index: usr.bin/fortune/unstr/unstr.c =================================================================== --- usr.bin/fortune/unstr/unstr.c +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ken Arnold. - * - * 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. - */ - -#if 0 -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1991, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static const char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93"; -#endif /* not lint */ -#endif -#include -__FBSDID("$FreeBSD$"); - -/* - * This program un-does what "strfile" makes, thereby obtaining the - * original file again. This can be invoked with the name of the output - * file, the input file, or both. If invoked with only a single argument - * ending in ".dat", it is pressumed to be the input file and the output - * file will be the same stripped of the ".dat". If the single argument - * doesn't end in ".dat", then it is presumed to be the output file, and - * the input file is that name prepended by a ".dat". If both are given - * they are treated literally as the input and output files. - * - * Ken Arnold Aug 13, 1978 - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "strfile.h" - -static char *Infile, /* name of input file */ - Datafile[MAXPATHLEN], /* name of data file */ - Delimch; /* delimiter character */ - -static FILE *Inf, *Dataf; - -static void order_unstr(STRFILE *); - -/* ARGSUSED */ -int -main(int argc, char *argv[]) -{ - static STRFILE tbl; /* description table */ - - if (argc != 2) { - fprintf(stderr, "usage: unstr datafile\n"); - exit(1); - } - Infile = argv[1]; - if ((size_t)snprintf(Datafile, sizeof(Datafile), "%s.dat", Infile) >= - sizeof(Datafile)) - errx(1, "%s name too long", Infile); - if ((Inf = fopen(Infile, "r")) == NULL) - err(1, "%s", Infile); - if ((Dataf = fopen(Datafile, "r")) == NULL) - err(1, "%s", Datafile); - if (fread((char *)&tbl, sizeof(tbl), 1, Dataf) != 1) { - if (feof(Dataf)) - errx(1, "%s read EOF", Datafile); - else - err(1, "%s read", Datafile); - } - tbl.str_version = be32toh(tbl.str_version); - tbl.str_numstr = be32toh(tbl.str_numstr); - tbl.str_longlen = be32toh(tbl.str_longlen); - tbl.str_shortlen = be32toh(tbl.str_shortlen); - tbl.str_flags = be32toh(tbl.str_flags); - if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM))) - errx(1, "nothing to do -- table in file order"); - Delimch = tbl.str_delim; - order_unstr(&tbl); - fclose(Inf); - fclose(Dataf); - exit(0); -} - -static void -order_unstr(STRFILE *tbl) -{ - uint32_t i; - char *sp; - off_t pos; - char buf[BUFSIZ]; - - for (i = 0; i < tbl->str_numstr; i++) { - fread(&pos, 1, sizeof(pos), Dataf); - fseeko(Inf, be64toh(pos), SEEK_SET); - if (i != 0) - printf("%c\n", Delimch); - for (;;) { - sp = fgets(buf, sizeof(buf), Inf); - if (sp == NULL || STR_ENDSTRING(sp, *tbl)) - break; - else - fputs(sp, stdout); - } - } -}