Index: head/misc/Makefile =================================================================== --- head/misc/Makefile (revision 422085) +++ head/misc/Makefile (revision 422086) @@ -1,510 +1,511 @@ # $FreeBSD$ # COMMENT = Miscellaneous utilities SUBDIR += R-cran-mime SUBDIR += achievo SUBDIR += aclgen SUBDIR += amanda-client SUBDIR += amanda-perl-wrapper SUBDIR += amanda-server SUBDIR += amfm SUBDIR += ansiweather SUBDIR += apparix SUBDIR += artikulate SUBDIR += asbutton SUBDIR += asr-manpages SUBDIR += astrolog SUBDIR += auto-multiple-choice SUBDIR += bb SUBDIR += bbjd SUBDIR += bdelta SUBDIR += bestfit SUBDIR += bibletime SUBDIR += biblical-curse SUBDIR += binclock SUBDIR += biosfont-demos SUBDIR += birthday SUBDIR += bogosort SUBDIR += bottlerocket SUBDIR += boxes SUBDIR += brs SUBDIR += buffer SUBDIR += cave SUBDIR += cdcollect SUBDIR += chef SUBDIR += chmlib SUBDIR += chord2html SUBDIR += cinnamon-translations SUBDIR += clex SUBDIR += cloc SUBDIR += clpbar SUBDIR += cmatrix SUBDIR += colortail SUBDIR += colwide SUBDIR += compat10x SUBDIR += compat4x SUBDIR += compat5x SUBDIR += compat6x SUBDIR += compat7x SUBDIR += compat8x SUBDIR += compat9x SUBDIR += countrycodes SUBDIR += cpuid SUBDIR += crosspad SUBDIR += cs SUBDIR += cstream SUBDIR += dahdi SUBDIR += dahdi-kmod SUBDIR += dahdi-kmod26 SUBDIR += ddate SUBDIR += deco SUBDIR += dejagnu SUBDIR += delay SUBDIR += detachtty SUBDIR += diction SUBDIR += digitemp SUBDIR += display SUBDIR += dnetc SUBDIR += dphys-config SUBDIR += dtach SUBDIR += dvorak7min SUBDIR += dvorakng SUBDIR += e2fsprogs-libblkid SUBDIR += e2fsprogs-libuuid SUBDIR += elixir-mime SUBDIR += elixir-uuid SUBDIR += elscreen SUBDIR += erlang-mimerl SUBDIR += erlang-mimetypes SUBDIR += esniper SUBDIR += estic SUBDIR += excel-writer SUBDIR += exercism SUBDIR += explosions SUBDIR += fbless SUBDIR += felis SUBDIR += figlet SUBDIR += figlet-fonts SUBDIR += findutils SUBDIR += firestring SUBDIR += flag SUBDIR += floatator SUBDIR += fortune-mod-bible SUBDIR += fortune-mod-bofh SUBDIR += fortune-mod-culmea-culmilor SUBDIR += fortune-mod-epictetus SUBDIR += fortune-mod-ferengi_rules_of_acquisition SUBDIR += fortune-mod-futurama SUBDIR += fortune-mod-psalms + SUBDIR += fortune_strfile SUBDIR += fortuneit SUBDIR += fpc-chm SUBDIR += freebsd-doc-all SUBDIR += freebsd-doc-bn SUBDIR += freebsd-doc-da SUBDIR += freebsd-doc-de SUBDIR += freebsd-doc-el SUBDIR += freebsd-doc-en SUBDIR += freebsd-doc-es SUBDIR += freebsd-doc-fr SUBDIR += freebsd-doc-hu SUBDIR += freebsd-doc-it SUBDIR += freebsd-doc-ja SUBDIR += freebsd-doc-ko SUBDIR += freebsd-doc-mn SUBDIR += freebsd-doc-nl SUBDIR += freebsd-doc-pl SUBDIR += freebsd-doc-pt SUBDIR += freebsd-doc-ru SUBDIR += freebsd-doc-sr SUBDIR += freebsd-doc-tr SUBDIR += freebsd-doc-zh_cn SUBDIR += freebsd-doc-zh_tw SUBDIR += freebsd-release-manifests SUBDIR += freeguide SUBDIR += ftdi-eeprom SUBDIR += fxload SUBDIR += gcstar SUBDIR += gctpc SUBDIR += geekcode SUBDIR += getopt SUBDIR += gimp-help-ca SUBDIR += gimp-help-da SUBDIR += gimp-help-el SUBDIR += gimp-help-en SUBDIR += gimp-help-en_GB SUBDIR += gimp-help-es SUBDIR += gimp-help-it SUBDIR += gimp-help-nl SUBDIR += gimp-help-nn SUBDIR += gimp-help-sl SUBDIR += gimp-help-sv SUBDIR += gkrellm-gamma SUBDIR += gkrellm-helium SUBDIR += gkrellm-xkb SUBDIR += gkrellmbgchg2 SUBDIR += gkrellmlaunch2 SUBDIR += gkrellshoot2 SUBDIR += gkrellweather2 SUBDIR += gkx86info2 SUBDIR += gnome-devel-docs SUBDIR += gnome-icon-theme SUBDIR += gnome-icon-theme-extras SUBDIR += gnome-mime-data SUBDIR += gnome-osd SUBDIR += gnome-user-docs SUBDIR += gnu-watch SUBDIR += gnuit SUBDIR += gnuls SUBDIR += gnustep-examples SUBDIR += gone SUBDIR += gonvert SUBDIR += gplink SUBDIR += granulate SUBDIR += grc SUBDIR += gregexp SUBDIR += grun SUBDIR += gtkfind SUBDIR += gwhich SUBDIR += hb SUBDIR += hello SUBDIR += help2man SUBDIR += heyu2 SUBDIR += hicolor-icon-theme SUBDIR += histring SUBDIR += hotkeys SUBDIR += hulgalugha SUBDIR += imerge SUBDIR += ini_file_manager SUBDIR += inplace SUBDIR += ipa_conv SUBDIR += ipbt SUBDIR += iselect SUBDIR += iso-codes SUBDIR += jargon SUBDIR += jbidwatcher SUBDIR += jive SUBDIR += kbdscan SUBDIR += kcd SUBDIR += kde-thumbnailer-chm SUBDIR += kde-thumbnailer-epub SUBDIR += kde-thumbnailer-fb2 SUBDIR += kde4-l10n SUBDIR += kde4-l10n-bg SUBDIR += kde4-l10n-bs SUBDIR += kde4-l10n-ca SUBDIR += kde4-l10n-ca_valencia SUBDIR += kde4-l10n-cs SUBDIR += kde4-l10n-da SUBDIR += kde4-l10n-el SUBDIR += kde4-l10n-en_GB SUBDIR += kde4-l10n-es SUBDIR += kde4-l10n-et SUBDIR += kde4-l10n-eu SUBDIR += kde4-l10n-fa SUBDIR += kde4-l10n-fi SUBDIR += kde4-l10n-ga SUBDIR += kde4-l10n-gl SUBDIR += kde4-l10n-hi SUBDIR += kde4-l10n-hr SUBDIR += kde4-l10n-ia SUBDIR += kde4-l10n-id SUBDIR += kde4-l10n-is SUBDIR += kde4-l10n-it SUBDIR += kde4-l10n-kk SUBDIR += kde4-l10n-km SUBDIR += kde4-l10n-lt SUBDIR += kde4-l10n-lv SUBDIR += kde4-l10n-mr SUBDIR += kde4-l10n-nb SUBDIR += kde4-l10n-nds SUBDIR += kde4-l10n-nl SUBDIR += kde4-l10n-nn SUBDIR += kde4-l10n-pa SUBDIR += kde4-l10n-ro SUBDIR += kde4-l10n-sk SUBDIR += kde4-l10n-sl SUBDIR += kde4-l10n-sr SUBDIR += kde4-l10n-sv SUBDIR += kde4-l10n-tr SUBDIR += kde4-l10n-ug SUBDIR += kde4-l10n-wa SUBDIR += kde4-xdg-env SUBDIR += kdeedu4 SUBDIR += kdeutils4 SUBDIR += kenny SUBDIR += kgeography SUBDIR += klettres SUBDIR += krecipes-kde4 SUBDIR += ktouch SUBDIR += kwordquiz SUBDIR += latex-mk SUBDIR += lc SUBDIR += lesspipe SUBDIR += libeatmydata SUBDIR += libisocodes SUBDIR += libkdeedu SUBDIR += libmetalink SUBDIR += libpri SUBDIR += libsupertone SUBDIR += libutf SUBDIR += lifelines SUBDIR += lingoteach SUBDIR += linm SUBDIR += localedata SUBDIR += logsurfer SUBDIR += loop SUBDIR += lr SUBDIR += lv SUBDIR += lxde-common SUBDIR += magicpoint SUBDIR += man.el SUBDIR += mbuffer SUBDIR += mc SUBDIR += mc-light SUBDIR += mdp SUBDIR += metalink-checker SUBDIR += metalink-editor SUBDIR += metalink-tools SUBDIR += metromap SUBDIR += mime-support SUBDIR += mirmon SUBDIR += mmv SUBDIR += mtail SUBDIR += mtx SUBDIR += najitool SUBDIR += newer SUBDIR += nms SUBDIR += nsf SUBDIR += numchar SUBDIR += nut SUBDIR += ondir SUBDIR += opencyc SUBDIR += openr2 SUBDIR += orville-write SUBDIR += ossp-uuid SUBDIR += otter SUBDIR += p5-Acme-ButFirst SUBDIR += p5-Array-Compare SUBDIR += p5-Array-Diff SUBDIR += p5-Array-FileReader SUBDIR += p5-Array-IntSpan SUBDIR += p5-Array-LineReader SUBDIR += p5-Array-PrintCols SUBDIR += p5-Array-RefElem SUBDIR += p5-Asterisk SUBDIR += p5-Asterisk-FastAGI SUBDIR += p5-Bot-Training SUBDIR += p5-Bot-Training-MegaHAL SUBDIR += p5-Bot-Training-StarCraft SUBDIR += p5-Business-EDI SUBDIR += p5-Business-Hours SUBDIR += p5-Business-ISBN SUBDIR += p5-Business-ISBN-Data SUBDIR += p5-Business-ISIN SUBDIR += p5-Business-ISMN SUBDIR += p5-Business-ISSN SUBDIR += p5-Business-UPS SUBDIR += p5-Chatbot-Eliza SUBDIR += p5-Data-Buffer SUBDIR += p5-File-CounterFile SUBDIR += p5-File-Sort SUBDIR += p5-Geo-Cache SUBDIR += p5-Geo-Coder-Bing SUBDIR += p5-Geo-Coder-Geocoder-US SUBDIR += p5-Geo-Coder-Google SUBDIR += p5-Geo-Coder-Googlev3 SUBDIR += p5-Geo-Coder-Many SUBDIR += p5-Geo-Coder-Mapquest SUBDIR += p5-Geo-Coder-Multimap SUBDIR += p5-Geo-Coder-Multiple SUBDIR += p5-Geo-Coder-Navteq SUBDIR += p5-Geo-Coder-OSM SUBDIR += p5-Geo-Coder-OpenCage SUBDIR += p5-Geo-Coder-Ovi SUBDIR += p5-Geo-Coder-PlaceFinder SUBDIR += p5-Geo-Coder-TomTom SUBDIR += p5-Geo-GeoNames SUBDIR += p5-Geo-Postcodes SUBDIR += p5-Geo-Postcodes-DK SUBDIR += p5-Geo-Postcodes-NO SUBDIR += p5-Geo-Weather SUBDIR += p5-Geography-Countries SUBDIR += p5-I18N-Charset SUBDIR += p5-I18N-LangTags SUBDIR += p5-LEGO-RCX SUBDIR += p5-List-Compare SUBDIR += p5-List-Util-WeightedRoundRobin SUBDIR += p5-Locale-Codes SUBDIR += p5-Locale-Geocode SUBDIR += p5-Locale-Msgcat SUBDIR += p5-Locale-SubCountry SUBDIR += p5-Locale-US SUBDIR += p5-Net-vCard SUBDIR += p5-Norge SUBDIR += p5-OSSP-uuid SUBDIR += p5-Software-License SUBDIR += p5-Software-License-CCpack SUBDIR += p5-Test-Dir SUBDIR += p5-Text-FIGlet SUBDIR += p5-Tie-DxHash SUBDIR += p5-Zen-Koans SUBDIR += pantry SUBDIR += parley SUBDIR += pastebinit SUBDIR += patchutils SUBDIR += pauker SUBDIR += pciids SUBDIR += pdmenu SUBDIR += pear-Services_Weather SUBDIR += pear-Text_Figlet SUBDIR += pecl-timezonedb SUBDIR += pfm SUBDIR += php55-calendar SUBDIR += php56-calendar SUBDIR += php70-calendar SUBDIR += phraze SUBDIR += pinfo SUBDIR += pipe SUBDIR += podsleuth SUBDIR += posixtestsuite SUBDIR += proxyper SUBDIR += pspresent SUBDIR += py-YABT SUBDIR += py-osd SUBDIR += py-pexpect SUBDIR += py-powerline-status SUBDIR += py-progressbar SUBDIR += py-progressbar231 SUBDIR += py-pyfiglet SUBDIR += py-pyprind SUBDIR += py-qt4-demo SUBDIR += py-qt4-doc SUBDIR += py-qt5-demo SUBDIR += py-qt5-doc SUBDIR += py-socli SUBDIR += py-spdx SUBDIR += py-spdx-lookup SUBDIR += py-tqdm SUBDIR += py-yolk SUBDIR += pylize SUBDIR += qbrew SUBDIR += qlas SUBDIR += qmetro SUBDIR += qt4-doc SUBDIR += qt4-l10n SUBDIR += qt4-qtconfig SUBDIR += qt4-qtdemo SUBDIR += qt5-doc SUBDIR += qt5-examples SUBDIR += qt5-l10n SUBDIR += qt5ct SUBDIR += raspberrypi-userland SUBDIR += raspbsd-led SUBDIR += ree SUBDIR += rfc SUBDIR += ringtonetools SUBDIR += rname SUBDIR += rpl SUBDIR += rtfm SUBDIR += rubygem-dotenv SUBDIR += rubygem-iesd SUBDIR += rubygem-mime-types SUBDIR += rubygem-mime-types-data SUBDIR += rubygem-mime-types1 SUBDIR += rubygem-mime-types29 SUBDIR += rubygem-mimemagic SUBDIR += rubygem-rabbit SUBDIR += rubygem-vpim SUBDIR += rump SUBDIR += saaghar SUBDIR += seabios SUBDIR += sent SUBDIR += seq2 SUBDIR += shared-mime-info SUBDIR += shc SUBDIR += shuffle SUBDIR += shuffle-db SUBDIR += since SUBDIR += skyutils SUBDIR += sloccount SUBDIR += sls SUBDIR += smssend SUBDIR += solarized SUBDIR += spamcalc SUBDIR += sshbuddy SUBDIR += sssnips SUBDIR += susv2 SUBDIR += susv3 SUBDIR += susv4 SUBDIR += sword SUBDIR += table.el SUBDIR += talkfilters SUBDIR += tcb SUBDIR += team SUBDIR += telbook SUBDIR += tellico-kde4 SUBDIR += tempcontrol SUBDIR += termatrix SUBDIR += terraform SUBDIR += teseq SUBDIR += teslams SUBDIR += timediff SUBDIR += tkcron SUBDIR += tkinfo SUBDIR += tkregexp SUBDIR += tkrunit SUBDIR += toilet SUBDIR += tpp SUBDIR += translate SUBDIR += ttyrec SUBDIR += tudu SUBDIR += tvbrowser SUBDIR += typetrainer SUBDIR += uk-phone SUBDIR += uk-postcodes SUBDIR += umodunpack SUBDIR += unclutter SUBDIR += upclient SUBDIR += us-zipcodes SUBDIR += usbids SUBDIR += usbrh-libusb SUBDIR += utftools SUBDIR += valspeak SUBDIR += vdmfec SUBDIR += vera SUBDIR += vifm SUBDIR += viz SUBDIR += whichman SUBDIR += window SUBDIR += wmScoreBoard SUBDIR += wmcalendar SUBDIR += wmjulia SUBDIR += wmpal SUBDIR += wmtunlo SUBDIR += wmweather+ SUBDIR += wmwork SUBDIR += wotsap SUBDIR += xd SUBDIR += xdelta SUBDIR += xdelta3 SUBDIR += xdg-menu SUBDIR += xfce4-appfinder SUBDIR += xfce4-weather-plugin SUBDIR += xfce4-wm-themes SUBDIR += xgas SUBDIR += xiphos SUBDIR += xless SUBDIR += xosd SUBDIR += xpns SUBDIR += xsw SUBDIR += xtail SUBDIR += xtar SUBDIR += xtypo SUBDIR += xyzcmd SUBDIR += yaunc SUBDIR += ytree SUBDIR += zoneinfo .include Index: head/misc/fortune_strfile/Makefile =================================================================== --- head/misc/fortune_strfile/Makefile (nonexistent) +++ head/misc/fortune_strfile/Makefile (revision 422086) @@ -0,0 +1,24 @@ +# Created by: marino@FreeBSD.org +# $FreeBSD$ + +PORTNAME= fortune_strfile +PORTVERSION= 1.0 +CATEGORIES= misc +MASTER_SITES= # none +DISTFILES= # none + +MAINTAINER= marino@FreeBSD.org +COMMENT= Duplicate of strfile(8) + +PROGRAM= fortune_strfile +PLIST_FILES= bin/${PROGRAM} + +do-build: + ${MKDIR} ${WRKSRC} + ${CC} ${CFLAGS} -o ${WRKSRC}/${PROGRAM} ${FILESDIR}/strfile.c + +do-install: + ${MKDIR} ${STAGEDIR}${PREFIX}/bin + ${INSTALL_PROGRAM} ${WRKSRC}/${PROGRAM} ${STAGEDIR}${PREFIX}/bin + +.include Property changes on: head/misc/fortune_strfile/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/misc/fortune_strfile/files/strfile.c =================================================================== --- head/misc/fortune_strfile/files/strfile.c (nonexistent) +++ head/misc/fortune_strfile/files/strfile.c (revision 422086) @@ -0,0 +1,441 @@ +/*- + * 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. + * + * @(#) Copyright (c) 1989, 1993 The Regents of the University of California. All rights reserved. + * @(#)strfile.c 8.1 (Berkeley) 5/31/93 + * $FreeBSD: src/games/fortune/strfile/strfile.c,v 1.15.2.2 2001/03/05 11:52:37 kris Exp $ + */ + +#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((unsigned int)(CHUNKSIZE * sizeof(*ptr))); \ + else if (((sz) + 1) % CHUNKSIZE == 0) \ + ptr = realloc(ptr, ((unsigned int)((sz) + CHUNKSIZE) * sizeof(*ptr))); \ + if (ptr == NULL) { \ + fprintf(stderr, "out of space\n"); \ + exit(1); \ + } \ + } while (0) + +typedef struct { + char first; + long pos; +} STR; + +static char *Infile = NULL; /* input file name */ +static char Outfile[MAXPATHLEN] = ""; /* output file name */ +static char 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 long Num_pts = 0; /* number of pointers/strings */ + +static long *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 *, long); +static int cmp_str(const void *, const void *); +static int 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 argc, char *argv[]) +{ + char *sp, *nsp, dc; + FILE *inf, *outf; + long last_off, length, pos, *p; + int first, cnt; + STR *fp; + static char string[257]; + + setlocale(LC_ALL, ""); + + getargs(argc, argv); /* 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, sizeof(Tbl), SEEK_SET); + + /* + * Write the strings onto the file + */ + + Tbl.str_longlen = 0; + Tbl.str_shortlen = ~((unsigned long)0); + Tbl.str_delim = dc; + Tbl.str_version = VERSION; + first = Oflag; + add_offset(outf, ftell(inf)); + last_off = 0; + do { + sp = fgets(string, 256, inf); + if (sp == NULL || (sp[0] == dc && sp[1] == '\n')) { + pos = ftell(inf); + length = pos - last_off - (sp ? strlen(sp) : 0); + last_off = pos; + if (!length) + continue; + add_offset(outf, pos); + if (Tbl.str_longlen < (unsigned long)length) + Tbl.str_longlen = length; + if (Tbl.str_shortlen > (unsigned long)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 %ld strings\n", Num_pts - 1); + printf("Longest string: %lu byte%s\n", Tbl.str_longlen, + Tbl.str_longlen == 1 ? "" : "s"); + printf("Shortest string: %lu byte%s\n", Tbl.str_shortlen, + Tbl.str_shortlen == 1 ? "" : "s"); + } + + rewind(outf); + Tbl.str_version = htonl(Tbl.str_version); + Tbl.str_numstr = htonl(Tbl.str_numstr); + Tbl.str_longlen = htonl(Tbl.str_longlen); + Tbl.str_shortlen = htonl(Tbl.str_shortlen); + Tbl.str_flags = htonl(Tbl.str_flags); + fwrite((char *)&Tbl, sizeof(Tbl), 1, outf); + if (STORING_PTRS) { + for (p = Seekpts, cnt = Num_pts; cnt--; ++p) + *p = htonl(*p); + fwrite((char *)Seekpts, sizeof(*Seekpts), (int)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') { + strcpy(Outfile, Infile); + strcat(Outfile, ".dat"); + } +} + +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, long off) +{ + long net; + + if (!STORING_PTRS) { + net = htonl(off); + fwrite(&net, 1, sizeof(net), 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) +{ + int i; + long *lp; + STR *fp; + + Sort_1 = fopen(Infile, "r"); + Sort_2 = fopen(Infile, "r"); + qsort((char *)Firstch, (int)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 +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 = collate_range_cmp(c1, c2)) != 0) + return r; + + fseek(Sort_1, p1->pos, SEEK_SET); + fseek(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 = 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 (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; + long tmp; + long *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; + } +} Property changes on: head/misc/fortune_strfile/files/strfile.c ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/misc/fortune_strfile/files/strfile.h =================================================================== --- head/misc/fortune_strfile/files/strfile.h (nonexistent) +++ head/misc/fortune_strfile/files/strfile.h (revision 422086) @@ -0,0 +1,52 @@ +/*- + * 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: src/games/fortune/strfile/strfile.h,v 1.3 1999/10/02 12:33:37 dcs Exp $ */ + +#define STR_ENDSTRING(line,tbl) \ + (((unsigned char)(line)[0]) == (tbl).str_delim && (line)[1] == '\n') + +typedef struct { /* information table */ +#define VERSION 1 + unsigned long str_version; /* version number */ + unsigned long str_numstr; /* # of strings in the file */ + unsigned long str_longlen; /* length of longest string */ + unsigned long 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 */ + unsigned long str_flags; /* bit field for flags */ + unsigned char stuff[4]; /* long aligned space */ +#define str_delim stuff[0] /* delimiting character */ +} STRFILE; Property changes on: head/misc/fortune_strfile/files/strfile.h ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/misc/fortune_strfile/pkg-descr =================================================================== --- head/misc/fortune_strfile/pkg-descr (nonexistent) +++ head/misc/fortune_strfile/pkg-descr (revision 422086) @@ -0,0 +1,4 @@ +This is a duplicate of strfile(8). + +It exists to make it possible to have fortune ports without first having +to install the games distribution. Property changes on: head/misc/fortune_strfile/pkg-descr ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property