cookietool-2.5/0040700000175000017500000000000007301470172012452 5ustar baranbarancookietool-2.5/doc/0040700000175000017500000000000007301455432013221 5ustar baranbarancookietool-2.5/doc/cdbsplit.60100600000175000017500000000510507301505167015115 0ustar baranbaran.\" Hey, EMACS: -*- nroff -*- .\" $Jubal::Debian::Packages$ .TH COOKIETOOL 6 "May 19, 2001" .SH NAME cdbsplit \- program to operate cookie (fortune) database .SH SYNOPSIS .B cdbsplit .RI [ options ] " " .SH DESCRIPTION This manual page documents briefly the \fBcdbsplit\fP command. This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. Instead, it has some plain text documentation, see below. .PP \fBcdbsplit\fP is a program that can be used to operate cookie database in various formats, the default is standard fortune(6) format, i.e. list of 'cookies' delimited with line containing a single percent ('\fB%\fP') char . With 'cdbsplit' you can split cookie database, or extract parts of it depending on various criteria. .SH OPTIONS A summary of options is included below. For a complete description, see the documentation in \fI/usr/share/doc/cookietool\fP directory. \fBNOTE\fP, that default behaviour is to overwrite existing database with its reduced version, so the cookies are MOVED to hitfile. The hitfile is never overwritten, but may be appended to. .TP .B [nothing] Shows summary of options. .TP .B \-c case-sensitive comparisons (for both keywords and groups) .TP .B \-d[0-3] how fuzzy about word delimiters? (default: 2) .TP .B \-k optional keyword .TP .B \-K mandatory keyword (use both of them to form boolean expressions) .TP .B \-l minimal cookie length (in lines) .TP .B \-L maximal cookie length (in lines) .TP .B \-w minimal line width (in chars) .TP .B \-W maximal line width (in chars) .TP .B \-n start at cookie .TP .B \-N stop after cookie .TP .B \-m find groups of cookies starting with matching characters (database must be sorted for this to make sense!) .TP .B \-x extract only, don't modify .TP .B \-a append, don't overwrite if such a filename exists .TP .B \-f[0-3] input file format \- \-f3: cookies are separated by '%%' lines; \-f2: cookies are separated by '%' lines (DEFAULT); \-f1: each line is a cookie; \-f0: each word is a cookie. .SH SEE ALSO \fBcookietool(6)\fP, \fBcdbdiff(6)\fP .SH BUGS None known. .SH AUTHOR Upstream author and Aminet cookietool.lha package with AmigaOS binaries uploader is Wilhelm Nöker, . Unix manpages (including this one) and makefile are maintained by Miros/law L. Baran . This manual page uses many excerpts from the original README file. cookietool-2.5/doc/cookietool.60100600000175000017500000000417707301505224015462 0ustar baranbaran.\" Hey, EMACS: -*- nroff -*- .\" $Jubal::Debian::Packages$ .TH COOKIETOOL 6 "May 19, 2001" .SH NAME cookietool \- program to operate cookie (fortune) database .SH SYNOPSIS .B cookietool .RI [ options ] " " .SH DESCRIPTION This manual page documents briefly the \fBcookietool\fP command. This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. Instead, it has some plaintext documentation, see below. .PP \fBcookietool\fP is a program that should be used to sort, clear and maintain cookie database in standard fortune(6) format, i.e. list of \fBcookies\fP delimited with line containing a single percent ('\fB%\fP') char. \fBcookietool\fP can now understand another formats and convert cookie database between them. .SH OPTIONS A summary of options is included below. For a complete description, see the documentation in \fI/usr/share/doc/cookietool\fP directory .TP .B [nothing] Shows summary of options. .TP .B \-c case sensitive comparisons. .TP .B \-d[0-3] how fuzzy about word delimiters? (default: 2) .TP .B \-b delete cookies that are 'abbreviations' of another, too. .TP .B \-p passive, don't delete anything. .TP .B \-s[l|w||s] sort cookies; looking after last line only; looking after last word only; starting after the last , e.g. '-s--'; by size. .TP .B \-a treat 'abbreviations' as doubles (i.e. delete them from the database, too). .TP .B \-f[0-3] input file format \- \-f3: cookies are separated by '%%' lines; \-f2: cookies are separated by '%' lines (DEFAULT); \-f1: each line is a cookie; \-f0: each word is a cookie. .TP .B \-F[0-3] force output in a different file format, see \-f. .TP .B \-o overwrite directly without temporary file. CAUTION NEEDED. .SH SEE ALSO \fBcdbdiff(6)\fP, \fBcdbsplit(6)\fP .SH BUGS None known. .SH AUTHOR Upstream author and Aminet cookietool.lha package with AmigaOS binaries uploader is Wilhelm Nöker, . Unix manpages (including this one) and makefile are maintained by Miros/law L. Baran . This manual page uses many excerpts from the original README file. cookietool-2.5/doc/cdbdiff.60100600000175000017500000000320207301505260014660 0ustar baranbaran.\" Hey, EMACS: -*- nroff -*- .\" $Jubal::Debian::Packages$ .TH COOKIETOOL 6 "May 19, 2001" .SH NAME cdbdiff \- program to operate cookie (fortune) database .SH SYNOPSIS .B cdbdiff .RI [ options ] " " .SH DESCRIPTION This manual page documents briefly the \fBcdbdiff\fP command. This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. Instead, it has some plaintext documentation, see below. .PP \fBcdbdiff\fP is a program that compares two cookie databases and builds a list of those cookies that are only present in second, but not in the first of them. The input files are not modified in any way. .SH OPTIONS A summary of options is included below. For a complete description, see the documentation in \fI/usr/share/doc/cookietool\fP directory .TP .B [nothing] Shows summary of options. .TP .B \-c case sensitive comparisons. .TP .B \-d[0-3] how fuzzy about word delimiters? (default: 2) .TP .B \-f[0-3] input file format \- \-f3: cookies are separated by '%%' lines; \-f2: cookies are separated by '%' lines (DEFAULT); \-f1: each line is a cookie; \-f0: each word is a cookie. .TP .B \-a append if exists (instead of failing). .SH SEE ALSO \fBcookietool(6)\fP, \fBcdbsplit(6)\fP .SH BUGS None known. .SH AUTHOR Upstream author and Aminet cookietool.lha package with AmigaOS binaries uploader is Wilhelm Nöker, . Unix manpages (including this one) and makefile are maintained by Miros/law L. Baran . This manual page uses many excerpts from the original README file. cookietool-2.5/cdbdiff.c0100600000175000017500000001222407256442600014203 0ustar baranbaran/* cdbdiff is (c) 2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: cdbdiff.c Date: 22 Mar 2001 | *------------------------------------------------------------------------* | Compare two fortune cookie files 'A' and 'B', | | extracting all cookies which are present in 'B' but not in 'A'. | | See help() for usage notes. | | | \*========================================================================*/ #include #include #include #include #include "strstuff.h" #include "cookio.h" #include "compress.h" char version[] = "$VER: cdbdiff 2.5 (22.03.2001)"; #define FBUFSIZE 16384 /* we'll use larger file buffers */ /* * Print a help text and nag about illegal parameter */ void help( UBYTE *s ) { if( s ) printf( "illegal option '%s'\n", s ); printf( "usage: cdbdiff [options] \n" ); printf( "where options are:\n" ); printf( " -f[0-3] cookie format: words, lines, %%, %%%% (default: %d)\n", DEF_FMT ); printf( " -d[0-3] how fussy about word delimiters? (default: 2)\n" ); printf( " -c case sensitive comparisons\n" ); printf( " -a if exists, append to it\n" ); } int main( int argc, char *argv[] ) { UBYTE *s; int append = 0; int case_sense = 0, bordermode = 2; int fmt = DEF_FMT; long count1; UBYTE name1[ 100 ], name2[ 100 ], name3[ 100 ]; UBYTE hooktarget[ 16 ]; FILE *infile, *infile2, *logfile; name1[ 0 ] = name2[ 0 ] = name3[ 0 ] = '\0'; while( --argc ) { s = *++argv; if( *s != '-' ) { if( name1[ 0 ] == '\0' ) strcpy( name1, s ); else if( name2[ 0 ] == '\0' ) strcpy( name2, s ); else strcpy( name3, s ); } else { s++; switch( *s++ ) { case 'd': if( isdigit( *s ) ) bordermode = atoi( s ); else goto bad_parm; break; case 'f': if( isdigit( *s ) ) fmt = atoi( s ); else goto bad_parm; break; case 'c': case_sense = 1; break; case 'a': append = 1; break; default: goto bad_parm; } } } /* important, before calling anything from strstuff: */ str_setup( bordermode, case_sense ); if( *name3 == '\0' ) { help( NULL ); return 5; } printf( "CdbDiff " ); print_strstat(); printf( "File format: " ); print_fmtinfo( fmt ); /* Open all three files. */ if( !(infile = fopen( name1, "r" ) ) ) { printf( "Can't open %s for input!\n", name1 ); return 10; } if( !(infile2 = fopen( name2, "r" ) ) ) { printf( "Can't open %s for input!\n", name2 ); return 10; } if( !append && (logfile = fopen( name3, "r" )) ) { printf( "Error: '%s' exists! Use -a to append.\n", name3 ); return 10; } if( !(logfile = fopen( name3, "a" ) ) ) { printf( "Can't open %s for output!\n", name3 ); return 10; } setvbuf( infile, NULL, _IOFBF, FBUFSIZE ); setvbuf( infile2, NULL, _IOFBF, FBUFSIZE ); setvbuf( logfile, NULL, _IOFBF, FBUFSIZE ); /* Read the first cookie file and compress it. */ read_cookies( infile, fmt ); fclose( infile ); one_cookie( DUPDEL_MATCH, SORT_RESTORE, hooktarget, NULL, fmt ); count1 = listed; /* Add the second file and once more delete any duplicates. */ read_cookies( infile2, fmt ); fclose( infile2 ); one_cookie( DUPDEL_MATCH, SORT_RESTORE, hooktarget, NULL, fmt ); /* Write the remaining cookies, skipping those from the first file. */ write_cookies( logfile, fmt, count1 ); fclose( logfile ); return 0; bad_parm: help( argv[ 0 ] ); return 5; } cookietool-2.5/Makefile0100600000175000017500000000254207301466357014126 0ustar baranbaran# $Id: Makefile,v 1.6 2000/06/17 18:49:22 baran Exp $ # slightly rewritten original Wilhelm Noeker's Makefile targets = cookietool cdbsplit cdbdiff objects = cookietool.o cdbsplit.o cdbdiff.o strstuff.o \ cookio.o compress.o prefix = usr binprefix = $(prefix)/games manprefix = $(prefix)/share/man/man6 CC = gcc RM = rm -v INSTALL = install CFLAGS = -O2 -Wall build : $(targets) strstuff.o : strstuff.c strstuff.h cookio.o : cookio.c cookio.h compress.o : compress.c compress.h cookietool : cookietool.o strstuff.o compress.o cookio.o cookietool.o : cookietool.c strstuff.h compress.h cookio.h cdbdiff : cdbdiff.o strstuff.o compress.o cookio.o cdbdiff.o : cdbdiff.c strstuff.h compress.h cookio.h cdbsplit : cdbsplit.o strstuff.o cookio.o cdbsplit.o : cdbsplit.c strstuff.h cookio.h clean : @-$(RM) $(targets) $(objects) # for AmigaOS installation change install-binary-unix to # install-binary-amiga; for non-debian-installation, use `make all' install : install-binary # install-manpages install-binary : @for file in $(targets); do \ $(INSTALL) -m 0755 $$file $(DESTDIR)/$(binprefix)/$$file; \ done; install-manpages : @for file in doc/*.6; do \ $(INSTALL) -m 0644 $$file $(DESTDIR)/$(manprefix)/$$file; \ done; all : build install install-manpages cookietool-2.5/cdbsplit.c0100600000175000017500000002723607255076526014450 0ustar baranbaran/* cookietool is (c) 1995-2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: cdbsplit.c Date: 25 Oct 1997 | *------------------------------------------------------------------------* | Split parts off your cookie database, by keyword, by line length, | | by number of lines, or as groups of "similar" cookies. | | Expected file format is plain text with a "%%" line ending each cookie.| | See help() for usage notes. | | | \*========================================================================*/ #include #include #include #include #include #include "strstuff.h" #include "cookio.h" char version[] = "$VER: cdbsplit 2.5 (18.03.2001)"; #define FBUFSIZE 16384 /* we'll use larger file buffers */ int l_min = 1, l_max = 0, w_min = 1, w_max = 0; long n_min = 1, n_max = 0; int matchlen = 0; int c_fmt = DEF_FMT; #define NTARGET 10 /* max. number of keywords to search for */ char *rtarget[NTARGET]; /* required keywords */ char *otarget[NTARGET]; /* optional keywords */ int required = 0, optional = 0; /* * print a help text and nag about illegal parameter */ void help( char *s ) { if( s ) printf( "illegal option '%s'\n", s ); printf( "usage: cdbsplit [options] \n" ); printf( "where options are:\n" ); printf( " -k / -K search for optional / required keyword\n" ); printf( " -l / -L range for number of lines in a cookie\n" ); printf( " -w / -W range for cookie line width\n" ); printf( " -n / -N range of cookie numbers\n" ); printf( " -m extract groups of cookies with matching chars\n" ); printf( " -f[0-3] cookie format: words, lines, %%, %%%% (default: %d)\n", DEF_FMT ); printf( " -d[0-3] how fussy about word delimiters? (default: 2)\n" ); printf( " -c case sensitive comparisons\n" ); printf( " -x extract only, do not modify the input file\n" ); printf( " -a append to an existing output file\n" ); } /* * Write a cookie to one of two files. Returns the number of cookies * written to the hit-file (which of course is either 1 or 0). */ int dispatch( char *cookie, int good, FILE *fp2, FILE *fp3 ) { int success = 1; if( good ) success = write_cookie( cookie, fp2, c_fmt ); else if( fp3 != NULL ) success = write_cookie( cookie, fp3, c_fmt ); if( !success ) { printf( "\nfile error, aborted !!!\n" ); exit( 20 ); } return good ? 1 : 0; } /* * Scatter contents of across (hitfile) and (dumpfile), * return value is the number of cookies in the dumpfile */ long filter_cookies( FILE *fp1, FILE *fp2, FILE *fp3 ) { static char cbak[ CBUFSIZE ]; /* backup of the last cookie, to find groups */ char *cptr; long count = 0, hits = 0, lines, width; int ok = 0, ok2, i; time_t checkpt; strcpy( cbak, "" ); time( &checkpt ); while( (cptr = read_cookie( fp1, c_fmt, NULL, &lines, &width )) != NULL ) { count++; /* perform the checks: */ if( matchlen ) /* "similar cookies" mode */ { ok2 = ok; ok = (str_ncmp( cbak, cptr, matchlen ) == 0); if( *cbak ) /* skip the first loop */ hits += dispatch( cbak, ok || ok2, fp2, fp3 ); strcpy( cbak, cptr ); } else /* standard mode */ { ok = (lines >= l_min && width >= w_min && count >= n_min); if( l_max ) ok = ok && ( lines <= l_max ); if( w_max ) ok = ok && ( width <= w_max ); if( n_max ) ok = ok && ( count <= n_max ); if( ok ) /* string checks still necessary? */ { if( required == 0 && optional > 0 ) ok = 0; for( i = 0; i < required; i++ ) ok = ok && (str_str( cptr, rtarget[i] ) != NULL); for( i = 0; i < optional; i++ ) ok = ok || (str_str( cptr, otarget[i] ) != NULL); } hits += dispatch( cptr, ok, fp2, fp3 ); } if( difftime( time( NULL ), checkpt ) >= 1 ) { time( &checkpt ); printf( "%ld hits/%ld misses.\r", hits, count - hits ); fflush( stdout ); } } if( matchlen ) /* one cookie still pending in this mode */ hits += dispatch( cbak, ok, fp2, fp3 ); printf( "Done, %ld hits out of %ld\n", hits, count ); return (count - hits); } void confirm_options() /* tell the user what his options will do */ { int flags, i; if( matchlen ) printf( " searching for groups of cookies with " "%d matching characters.\n", matchlen ); else { flags = 0xf; /* what restrictions do apply? */ if( optional + required > 0 ) { printf( " search string%s: ", (optional + required > 1) ? "s" : ""); if( required > 1 && optional > 0 ) printf("("); if( required > 0 ) { printf( "\"%s\"", rtarget[0] ); for( i = 1; i < required; i++ ) printf( " && \"%s\"", rtarget[i] ); } if( required > 1 && optional > 0 ) printf(")"); if( required > 0 && optional > 0 ) printf(" || "); if( optional > 0 ) { printf( "\"%s\"", otarget[0] ); for( i = 1; i < optional; i++ ) printf( " || \"%s\"", otarget[i] ); } printf( "\n" ); } else flags ^= 1; if( l_max ) printf( " looking for cookies %d - %d lines long.\n", l_min, l_max ); else if( l_min > 1 ) printf( " looking for cookies at least %d lines long.\n", l_min ); else flags ^= 2; if( w_max ) printf( " looking for cookies %d - %d columns wide.\n", w_min, w_max ); else if( w_min > 1 ) printf( " looking for cookies at least %d columns wide.\n", w_min ); else flags ^= 4; if( n_max ) printf( " considering cookies #%ld - #%ld only.\n", n_min, n_max); else if( n_min > 1 ) printf( " starting at cookie #%ld.\n", n_min ); else flags ^= 8; if( flags == 0 ) printf( " no restrictions.\n" ); } } int main( int argc, char *argv[] ) { char *s; char *name1 = NULL, *name2 = NULL, *name3 = "cdb_temp_kickme"; int append = 0, move = 1; int case_sense = 0, bordermode = 2; long dumped; FILE *infile, *hitfile, *dumpfile; if( argc < 3 ) { help( NULL ); return 5; } while( --argc ) { s = *++argv; if( *s != '-' ) { if( name1 == NULL ) name1 = s; else name2 = s; } else { s++; switch( *s++ ) { case 'k': if( optional < NTARGET ) otarget[ optional++ ] = s; break; case 'K': if( required < NTARGET ) rtarget[ required++ ] = s; break; case 'm': matchlen = atoi( s ); break; case 'l': l_min = atoi( s ); break; case 'L': l_max = atoi( s ); break; case 'w': w_min = atoi( s ); break; case 'W': w_max = atoi( s ); break; case 'n': n_min = atol( s ); break; case 'N': n_max = atol( s ); break; case 'a': append = 1; break; case 'x': move = 0; break; case 'c': case_sense = 1; break; case 'd': if( isdigit( *s ) ) bordermode = atoi( s ); else goto bad_parm; break; case 'f': if( isdigit( *s ) ) c_fmt = atoi( s ); else goto bad_parm; break; default: goto bad_parm; } } } str_setup( bordermode, case_sense ); /* !!! */ if( name1 == NULL || name2 == NULL ) { help( NULL ); return 5; } if( !(infile = fopen( name1, "r" ) ) ) { printf( "Can't open '%s' for input!\n", name1 ); return 10; } setvbuf( infile, NULL, _IOFBF, FBUFSIZE ); if( !append && (hitfile = fopen( name2, "r" )) ) { printf( "Error: '%s' exists! Use -a to append.\n", name2 ); return 10; } if( !(hitfile = fopen( name2, "a" )) ) { printf( "Can't open '%s' for output!\n", name2 ); return 10; } setvbuf( hitfile, NULL, _IOFBF, FBUFSIZE ); if( move ) { if( !(dumpfile = fopen( name3, "w" ) ) ) { printf( "Can't open '%s' for output!\n", name3 ); return 10; } setvbuf( dumpfile, NULL, _IOFBF, FBUFSIZE ); } else dumpfile = NULL; printf( "CdbSplit " ); print_strstat(); printf( "File format: " ); print_fmtinfo( c_fmt ); printf( "%s from '%s' to '%s',\n", move ? "Moving" : "Copying", name1, name2 ); confirm_options(); /* OK, here we go: */ dumped = filter_cookies( infile, hitfile, dumpfile ); fclose( infile ); fclose( hitfile ); if( move ) { fclose( dumpfile ); if( remove( name1 ) != 0 || rename( name3, name1 ) != 0 ) { printf( "Couldn't overwrite the input file! Your cookies are in '%s'.\n", name3 ); return 5; } if( dumped == 0 ) { remove( name1 ); printf( "'%s' is now empty and has been deleted.\n", name1 ); } } return 0; bad_parm: help( argv[ 0 ] ); return 5; } cookietool-2.5/compress.c0100600000175000017500000002261607256442472014472 0ustar baranbaran/* cookietool is (c) 1995-2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: compress.c Date: 22 Mar 2001 | *------------------------------------------------------------------------* | Read cookies, remove duplicates, sort, and write back to file. | | These routines are common to both cookietool and cdbdiff. | | | \*========================================================================*/ #include #include #include #include #include "cookio.h" #include "compress.h" struct cookie { UBYTE *text; UBYTE *sorthook; long size; long number; }; struct cookie *clist = NULL; long listsize = 0; /* will be adjusted dynamically */ long listed = 0; /* * Assign ascending numbers to all cookies in the list and reset each sort * hook to the start of its body text. */ void rebuild_listinfo() { long l; for( l = 0; l < listed; l++ ) { clist[ l ].number = l; clist[ l ].sorthook = clist[ l ].text; } } /* * Build cookie list from file. * The list may or may not be empty before this call. */ void read_cookies( FILE *fp, int fmt ) { long lines, cbuflen, offset, ignored = 0; char *cptr; offset = listed; /* may or may not be 0 */ printf( "Reading cookies..." ); fflush( stdout ); while( (cptr = read_cookie( fp, fmt, &cbuflen, &lines, NULL )) != NULL ) { if( lines > 0 ) { /* store the cookie */ if( listed == listsize ) { /* we start with listsize==0, clist==NULL ! */ listsize = 3 * listsize / 2 + 1000; clist = realloc( clist, listsize * sizeof( struct cookie ) ); if( !clist ) { printf( "\nList reallocation failed\n" ); exit( 20 ); } } clist[ listed ].text = malloc( cbuflen + 1 ); /* mind the '\0'! */ if( clist[ listed ].text != NULL ) { clist[ listed ].size = cbuflen; strcpy( clist[ listed ].text, cptr ); } else { printf( "\nOut of memory\n" ); exit( 20 ); } listed++; } else ignored++; /* or ignore it */ } rebuild_listinfo(); printf( " done. (%ld read, %ld empty)\n", listed-offset, ignored ); } /* * Write cookies to file, optionally skipping some at the start of the * list. */ void write_cookies( FILE *fp, int fmt, long offset ) { long l; printf( "Writing cookies..." ); fflush( stdout ); for( l = offset; l < listed; l++ ) if( !write_cookie( clist[ l ].text, fp, fmt ) ) { printf( "\nFile error, aborted !!!\n" ); exit( 20 ); } printf( " done. (%ld written)\n", listed-offset ); } /* * Cookie comparison, for sorting. */ int cookie_cmp( struct cookie *a, struct cookie *b, int mode ) { int c = 0; switch( mode ) { case SORT_BODY: /* by name */ c = str_cmp( a->sorthook, b->sorthook ); break; case SORT_REVERSE: /* descending, by name */ c = str_cmp( b->sorthook, a->sorthook ); break; case SORT_SIZE: /* by size */ c = a->size - b->size; break; } if( c == 0 ) /* when in doubt, the number decides */ c = a->number - b->number; return c; } /* * sift(): does the main work for my_heapsort() */ void sift( struct cookie v[], long i, long m, int mode ) { long j; struct cookie temp; while( (j = 2 * (i + 1) - 1) <= m ) { if( j < m && cookie_cmp( &v[ j ], &v[ j + 1 ], mode ) < 0 ) j++; if( cookie_cmp( &v[ i ], &v[ j ], mode ) < 0 ) { temp = v[ i ]; v[ i ] = v[ j ]; v[ j ] = temp; i = j; } else i = m; /* done */ } } /* * Note the side effect: Will print three "."s to stdout: one on entry, * one when the sort is halfway through, and another one when it's all done. */ void my_heapsort( struct cookie v[], long n, int mode ) { long i; struct cookie temp; putchar( '.' ); fflush( stdout ); if( n < 2 ) /* no sorting necessary */ return; for( i = n/2 - 1; i >= 0; i-- ) sift( v, i, n - 1, mode ); putchar( '.' ); fflush( stdout ); for( i = n - 1; i >= 1; i-- ) { temp = v[ 0 ]; v[ 0 ] = v[ i ]; v[ i ] = temp; sift( v, 0, i - 1, mode ); } putchar( '.' ); fflush( stdout ); } /* * Adjust sorthooks for the final sort, according to the desired mode. */ void set_hooks( int mode, UBYTE *hooktarget ) { long l; int hot; UBYTE *s; printf( "Adjusting sort hooks..." ); fflush( stdout ); for( l = 0; l < listed; l++ ) { s = clist[ l ].text; switch( mode ) { case SORT_LASTLINE: /* start of last line */ hot = 1; while( *s ) { if( *s == '\n' ) hot = 1; else if( hot ) { clist[ l ].sorthook = s; hot = 0; } s++; } break; case SORT_LASTWORD: /* start of last word */ hot = 1; while( *s ) { if( isspace( *s ) ) hot = 1; else if( hot ) { clist[ l ].sorthook = s; hot = 0; } s++; } break; case SORT_HOOKTARGET: while( s ) /* at last occurence of */ { clist[ l ].sorthook = s++; s = strstr( s, hooktarget ); } break; default: } } printf( " done.\n" ); } /* * Delete cookies and (optionally) log them to a file. For values of delmode * and sortmode, see "compress.h". * Note that the routine expects the sorthooks to point at the body texts * on entry, but may modify and not restore them itself. There are many * reasons why this does *not* hurt with the current implementations of both * cookietool and cdbdiff, but it might be a pitfall in the future. */ void one_cookie( int delmode, int sortmode, UBYTE *hooktarget, FILE *fp, int fmt ) { long i, j, dbl = 0, abr = 0; int cmp; if( delmode != DUPDEL_NONE ) { printf( "Removing double entries" ); if( delmode == DUPDEL_ABBREVS ) printf( " + 'abbreviations'" ); /* sort descending by string */ my_heapsort( clist, listed, SORT_REVERSE ); for( i = listed - 1; i > 0; i = j ) { for( j = i - 1; j >= 0 && ( (cmp = str_cmp( clist[ j ].text, clist[ i ].text )) == 0 || (delmode == DUPDEL_ABBREVS && cmp == STR_LONGER) ); j-- ) { if( fp ) if( !write_cookie( clist[ i ].text, fp, fmt ) ) { printf( "\nFile error, aborted !!!\n" ); exit( 20 ); } free( clist[ i ].text ); clist[ i-- ] = clist[ --listed ]; if( cmp == 0 ) dbl++; else abr++; } } printf( " done. (%ld ", dbl ); if( delmode == DUPDEL_ABBREVS ) printf( "+ %ld ", abr ); printf( "found)\n" ); } if( sortmode == SORT_RESTORE ) { printf( "Restoring order" ); my_heapsort( clist, listed, SORT_RESTORE ); } else { if( sortmode > SORT_BODY ) set_hooks( sortmode, hooktarget ); printf( "Sorting" ); if( sortmode == SORT_SIZE ) my_heapsort( clist, listed, SORT_SIZE ); else my_heapsort( clist, listed, SORT_BODY ); } printf( " done.\n" ); } cookietool-2.5/compress.h0100600000175000017500000000430607256355156014475 0ustar baranbaran/* cookietool is (c) 1995-2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: compress.h Date: 22 Mar 2001 | *------------------------------------------------------------------------* | Read cookies, remove duplicates, sort, and write back to file. | | These routines are common to both cookietool and cdbdiff. | | | \*========================================================================*/ #include "strstuff.h" extern long listed; /* number of cookies in memory */ void read_cookies ( FILE *fp, int fmt ); void write_cookies ( FILE *fp, int fmt, long offset ); void one_cookie ( int delmode, int sortmode, UBYTE *hooktarget, FILE *fp, int fmt ); /* values for delmode */ enum { DUPDEL_NONE, /* don't delete anything */ DUPDEL_MATCH, /* delete duplicates */ DUPDEL_ABBREVS /* delete duplicates and abbreviations */ }; /* values for sortmode */ enum { SORT_REVERSE, /* (only for use inside this module) */ SORT_RESTORE, /* restore original order */ SORT_SIZE, /* sort by size */ SORT_BODY, /* sort by body text */ SORT_LASTLINE, /* sort by last line */ SORT_LASTWORD, /* sort by last word */ SORT_HOOKTARGET /* sort by last occurence of special hook target */ }; cookietool-2.5/README.unix0100600000175000017500000000055307301506021014307 0ustar baranbarancookietool v2.5 --------------- This is basically the same version as the cookietool.lha from Aminet, with another Makefile, added manpages and changed code defaults (cookie delimiter changed to '%\n'). The cookietool-x.x.tar.gz tarball is maintained by Miros/law L. Baran -- any comments regarding man pages (not code) should be sent to him. cookietool-2.5/cookietool.c0100600000175000017500000001765307256354752015016 0ustar baranbaran/* cookietool is (c) 1995-2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: cookietool.c Date: 25 Oct 1997 | *------------------------------------------------------------------------* | Remove duplicate entries from a cookie file, | | various options for sorting the output. | | Expected file format is plain text with a "%%" line ending each cookie.| | See help() for usage notes. | | | \*========================================================================*/ #include #include #include #include #include "strstuff.h" #include "cookio.h" #include "compress.h" char version[] = "$VER: cookietool 2.5 (22.03.2001)"; #define FBUFSIZE 16384 /* we'll use larger file buffers */ /* * Print a help text and nag about illegal parameter */ void help( UBYTE *s ) { if( s ) printf( "illegal option '%s'\n", s ); printf( "usage: cookietool [options] [logfile]\n" ); printf( "where options are:\n" ); printf( " -p passive, don't delete anything\n" ); printf( " -b treat 'abbreviations' as doubles (i.e. delete them, too)\n" ); printf( " -s sort cookies\n" ); printf( " -sl \" , looking at the last line only\n" ); printf( " -sw \" , looking at the last word only\n" ); printf( " -s \" , starting after the last , e.g. '-s--'\n" ); printf( " -ss \" , by size\n" ); printf( " -f[0-3] cookie format: words, lines, %%, %%%% (default: %d)\n", DEF_FMT ); printf( " -F[0-3] force output in a different format\n" ); printf( " -d[0-3] how fussy about word delimiters? (default: 2)\n" ); printf( " -c case sensitive comparisons\n" ); printf( " -a if exists, append to it\n" ); printf( " -o overwrite directly, no tempfile (caution!)\n" ); } int main( int argc, char *argv[] ) { UBYTE *s; int dirty = 0, append = 0, action = DUPDEL_MATCH, finalsort = SORT_RESTORE; int case_sense = 0, bordermode = 2; int i_fmt = DEF_FMT, o_fmt = DEF_FMT; int force_fmt = -1; UBYTE name1[ 100 ], name2[ 100 ], name3[ 100 ]; UBYTE hooktarget[ 16 ]; FILE *infile, *outfile, *logfile; name1[ 0 ] = name2[ 0 ] = name3[ 0 ] = '\0'; if( argc < 2 ) { help( NULL ); return 5; } while( --argc ) { s = *++argv; if( *s != '-' ) { if( name1[ 0 ] == '\0' ) strcpy( name1, s ); else strcpy( name3, s ); } else { s++; switch( *s++ ) { case 's': switch( *s ) { case '\0': finalsort = SORT_BODY; break; case 's': finalsort = SORT_SIZE; break; case 'l': finalsort = SORT_LASTLINE; break; case 'w': finalsort = SORT_LASTWORD; break; default: if( ispunct( *s ) ) { finalsort = SORT_HOOKTARGET; str_ncpy( hooktarget, s, sizeof( hooktarget ) ); } else goto bad_parm; } break; case 'd': if( isdigit( *s ) ) bordermode = atoi( s ); else goto bad_parm; break; case 'f': if( isdigit( *s ) ) i_fmt = atoi( s ); else goto bad_parm; break; case 'F': if( isdigit( *s ) ) force_fmt = atoi( s ); else goto bad_parm; break; case 'c': case_sense = 1; break; case 'a': append = 1; break; case 'b': action = DUPDEL_ABBREVS; break; case 'p': action = DUPDEL_NONE; break; case 'o': dirty = 1; break; default: goto bad_parm; } } } o_fmt = (force_fmt >= 0) ? force_fmt : i_fmt; /* important, before calling anything from strstuff: */ str_setup( bordermode, case_sense ); if( *name1 == '\0' ) { help( NULL ); return 5; } if( dirty ) { strcpy( name2, name1 ); printf( "Warning! You have enabled direct writeback mode!\n" ); printf( "\e[2mDon't break (or crash) cookietool now, " ); printf( "or you will inevitably lose data!\e[0m\n" ); } else strcpy( name2, "ct_temp_crunchfile" ); printf( "CookieTool " ); print_strstat(); if( i_fmt == o_fmt ) { printf( "File format: " ); print_fmtinfo( i_fmt ); } else { printf( "Input format: " ); print_fmtinfo( i_fmt ); printf( "Output format: " ); print_fmtinfo( o_fmt ); } if( !(infile = fopen( name1, "r" ) ) ) { printf( "Can't open %s for input!\n", name1 ); return 10; } setvbuf( infile, NULL, _IOFBF, FBUFSIZE ); if( *name3 ) { if( !append && (logfile = fopen( name3, "r" )) ) { printf( "Error: '%s' exists! Use -a to append.\n", name3 ); return 10; } if( !(logfile = fopen( name3, "a" ) ) ) { printf( "Can't open %s for output!\n", name3 ); return 10; } } else logfile = NULL; read_cookies( infile, i_fmt ); fclose( infile ); one_cookie( action, finalsort, hooktarget, logfile, o_fmt ); if( logfile ) fclose( logfile ); if( !(outfile = fopen( name2, "w" ) ) ) { printf( "Can't open %s for output!\n", name2 ); return 10; } setvbuf( outfile, NULL, _IOFBF, FBUFSIZE ); write_cookies( outfile, o_fmt, 0 ); fclose( outfile ); if( !dirty ) { /* replace the input file */ if( remove( name1 ) != 0 || rename( name2, name1 ) != 0 ) { printf( "Couldn't overwrite the input file! Your cookies are in '%s'.\n", name2 ); return 5; } } return 0; bad_parm: help( argv[ 0 ] ); return 5; } cookietool-2.5/cookio.c0100600000175000017500000001142707301467014014106 0ustar baranbaran/* (c) 1995-2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: cookio.c Date: 17 Feb 2001 | *------------------------------------------------------------------------* | Generalised I/O for cookies, supporting various file formats. | | | \*========================================================================*/ #include #include #include #include "cookio.h" #define LBUFSIZE 4000 char line[LBUFSIZE]; /* large enough to hold the longest line */ char cbuf[CBUFSIZE]; /* large enough to hold one complete cookie */ /* * Read a cookie from the given input file, store it in a static * buffer and return a pointer to it, or NULL at end of file. * The size information variables (about strlen, lines, longest line) * are optional, passing NULL is allowed. * Note: No matter what mode we are in, the string result *never* has * a trailing EOL character. */ char *read_cookie( FILE *fp, int fmt, long *psize, long *plines, long *pmaxline ) { long cbuflen, lines, w, width; int delimlen; char *delim = "%%"; switch( fmt ) { case FMT_WORDS: if( fscanf( fp, "%s", cbuf ) != 1 ) return NULL; cbuflen = strlen( cbuf ); width = cbuflen; lines = 1; goto done; case FMT_LINES: if( fgets( cbuf, sizeof( cbuf ), fp ) == NULL ) return NULL; cbuflen = strlen( cbuf ); width = cbuflen - 1; lines = 1; goto done; case FMT_PERCENT: delim = "%"; break; } delimlen = strlen( delim ); strcpy( cbuf, "" ); cbuflen = lines = width = 0; while( fgets( line, sizeof( line ), fp ) ) { if( strncmp( line, delim, delimlen ) == 0 ) goto done; /* "end of cookie"-marker */ else /* add a line to the current cookie */ { w = strlen( line ); if( (cbuflen += w) >= sizeof( cbuf ) ) { printf( "\ncookie too big (>%ld chars) \n", (long) sizeof( cbuf ) ); exit( 20 ); } strcat( cbuf, line ); lines++; if( w-1 > width ) width = w-1; /* "\n" doesn't count for width */ } } /* Found EOF. */ if( cbuflen == 0 ) return NULL; done: if( cbuf[ cbuflen-1 ] == '\n' ) cbuf[ --cbuflen ] = '\0'; if( psize != NULL ) *psize = cbuflen; if( plines != NULL ) *plines = lines; if( pmaxline != NULL ) *pmaxline = width; return cbuf; } /* * Write a cookie to the output file. Returns non-zero if successful. */ int write_cookie( char *cookie, FILE *fp, int fmt ) { char *fmts = "%s\n%%%%\n"; int len; static int linew = 0; switch( fmt ) { case FMT_WORDS: fmts = "%s "; len = strlen( cookie ); if( len + linew > 75 ) { fmts = "\n%s "; linew = 0; } linew += len + 1; break; case FMT_LINES: fmts = "%s\n"; break; case FMT_PERCENT: fmts = "%s\n%%\n"; break; } return (fprintf( fp, fmts, cookie ) > 0) ? 1 : 0; } /* * Print a short plaintext description of a cookie format. */ void print_fmtinfo( int fmt ) { switch( fmt ) { case FMT_WORDS: printf( "each word is a cookie\n" ); break; case FMT_LINES: printf( "each line is a cookie\n" ); break; case FMT_PERCENT: printf( "cookies are separated by lines of '%%'\n" ); break; default: printf( "cookies are separated by lines of '%%%%'\n" ); } } cookietool-2.5/cookio.h0100600000175000017500000000360707301442745014120 0ustar baranbaran/* cookietool is (c) 1995-2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: cookio.h Date: 17 Feb 2001 | *------------------------------------------------------------------------* | Generalised I/O for cookies, supporting various file formats. | | | \*========================================================================*/ /* Cookie file formats: */ #define FMT_WORDS 0 /* cookies separated by arbitrary white space */ #define FMT_LINES 1 /* each line is a cookie */ #define FMT_PERCENT 2 /* cookies separated by "%" lines */ #define FMT_DBLPERCENT 3 /* cookies separated by "%%" lines */ #define DEF_FMT 2 /* default cookie format */ /* The static input buffer size, */ /* read_cookie() will never return a cookie larger than this. */ #define CBUFSIZE 64000L char *read_cookie( FILE *fp, int fmt, long *psize, long *plines, long *pmaxline ); int write_cookie( char *cookie, FILE *fp, int fmt ); void print_fmtinfo( int fmt ); cookietool-2.5/COPYING0100600000175000017500000004311007125231500013475 0ustar baranbaran GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. cookietool-2.5/README0100600000175000017500000004133407301467547013352 0ustar baranbaran CookieTool V2.5 =============== A team of programs to help you maintain your cookie database: "CookieTool" itself eliminates duplicate entries, sorts cookies alphabetically or by size if you wish. "CdbSplit" extracts parts of the database to a separate file, by keyword, by size, by number, or as groups of 'similar' cookies. "CdbDiff" compares two cookie databases and builds a list of those cookies only present in B, but not in A. 0. Who needs it? ---------------- These tools are intended for users of "Cookie", "IntuiCookie" (both available on Aminet, util/misc/), or generally for any plain text cookie database with entries separated by "%%" lines. They are nice for crunching your cookie collection by a few KByte of duplicate stuff, but also for splitting it into seperate files, for example extracting quotations or dumping those cookies too big to be fun to read. Note that "CookieTool" and its companions know how to handle the database itself, but not how to update the corresponding index file (also called 'hash file'). That means you still need "cookhash" (or whatever the utility is called that came with your cookie display program). With the introduction of the -f option (selectable file format at run time), the cookie-tools have also become useful for managing arbitrary word lists. 1. CookieTool command summary ----------------------------- cookietool [options] [logfile] The crunched cookie database will be WRITTEN BACK to the input file (quite different from cookietool V1.x behaviour). The deleted cookies will be written to , if one is specified. (Thus one could restore the original database by appending the logfile to the cookiefile again.) options: meaning: -c case-sensitive comparisons (for both deleting and sorting) -d[0-3] how fussy about word delimiters? -d3: strict, compare character by character -d2: ignore number and kind of spaces between words (DEFAULT) -d1: treat punctuation signs as spaces, too -d0: completely ignore punctuation signs and spaces -b delete cookies that are "abbreviations" of another, too -p passive, don't delete anything -s sort output -sl " , looking at the last line only \ intended to -sw " , looking at the last word only }- sort quotations -s " , starting at the last occurence / by source of , e.g. '-s--' or '-s...' -ss sort by size -o overwrite the input file directly (no tempfile), risky! Use this *only* if your disk is so full that cookietool couldn't create its tempfile. -a append, if exists (instead of failing) -f[0-3] input file format: -f3: cookies are separated by "%%" lines (DEFAULT) -f2: cookies are separated by "%" lines -f1: each line is a cookie -f0: each word is a cookie -F[0-3] force output in a different file format Please don't play with the -f/-F options "just to see what they do". They can easily damage your database beyond repair. 2. CdbSplit command summary --------------------------- cdbsplit [options] By default, the input file will always be OVERWRITTEN by a reduced version of the database, so that cookies are moved (not copied) to the hit file. An existing hit file will never be overwritten, but may be appended to. options: meaning: -c case-sensitive comparisons (for both keywords and groups) -d[0-3] how fussy about word delimiters? (see details above) -k optional keyword \_combine these to form simple -K mandatory keyword / boolean expressions -l accept only cookies with lines or more -L " " " " lines or less -w accept only cookies chars wide or more -W " " " chars wide or less -n start at cookie number -N stop after " " -m find groups of cookies starting with matching characters (database must have been sorted for this to make sense!) -x extract only, don't modify -a append, if exists (instead of failing) -f[0-3] cookie file format (see details above) Note that CdbSplit cannot *change* the file format, only CookieTool itself has a -F option. 3. CdbDiff command summary --------------------------- cdbdiff [options] The result file will receive those cookies that are only present in but not in . Neither of the input files will be modified. options: meaning: -c case-sensitive comparisons -d[0-3] how fussy about word delimiters? (see details above) -f[0-3] cookie file format (see details above) -a append, if exists (instead of failing) From reading the above description, you may have noticed that CdbDiff only does "half a diff" . To really find all differences between two files you might type something like "cdbdiff file0 file1 diff01" and "cdbdiff file1 file0 diff10". Another hint: CdbDiff can also tell you which cookies two files have in common. To do so, execute "cdbdiff file0 file1 diff", then "cdbdiff file1 file0 diff -a" (which creates a list of all cookies which are only present in one of the input files, but not in both), and finally "cdbdiff diff file0 common" (or "cdbdiff diff file1 common", which would give the same result). 4. Examples ----------- These examples assume that your cookie database is in a single file called "cookies" and that your favourite text editor is called "Ed". And of course I'd strongly suggest that you backup your files before trying any of this. 4.1. Do what "onecookie" used to do ----------------------------------- The classic "onecookie" could only delete verbatim copies of a cookie, where even two spaces instead of one would make a difference. CookieTool can be told to behave like this, too: cookietool cookies -c -d3 The default settings are a bit more generous: cookietool cookies might delete a few cookies more. Upper- and lowercase letters are now considered the same, and it doesn't matter if two words are seperated by one or several spaces, by a tab sign, by a line break, etc. So two copies of the same text, but formatted in different ways, will still be recognized as identical. The question is: Do you really want such copies deleted automatically, or would you rather decide yourself which one of such *almost* identical cookies should be deleted? This question arises even more with the real liberal settings like cookietool cookies -d0 which for example recognizes "Kill ugly radio. -- Frank Zappa" and "Kill ugly radio... Frank Zappa" as identical. (Both of these two styles of supplying sources to quotations are frequently used.) More on that question later. 4.2. Deleting abbreviations --------------------------- It occurs rather frequently that one cookie seems to be an "abbreviation" of another. Sayings may consist of more than one sentence, but the first sentence is sometimes quoted by itself. And quotations are sometimes written down with, sometimes without their author. In both cases the shorter cookie may be deleted, and cookietool can do that, too (-b). However, one should not ignore puctuation signs with this option (don't use -d1 or -d0), because that would consider "A penny saved is a penny." as an abbreviation of "A penny saved is a penny earned.", which is not desireable. It might be a good idea to create a log file of the deleted cookies and look at least at the shortest ones among them. cookietool -b cookies log ; extract to "log" rather than just deleting cookietool log -ss ; sort the extracted cookies by size Ed log ; check if some are worth keeping and delete the rest cdbsplit log cookies -a ; put the survivors back Using 'cdbsplit -a' without any search options is a nice way of moving cookies back into your main database. (Note that "Type log >>cookies", "Delete log" would essentially do the same, but is risky: If you accidentally type '>' instead of '>>', that would overwrite your main database instead of appending to it! Such a thing can't happen with cdbsplit -a.) 4.3. Move cookies between files ------------------------------- Let's say you want to keep cookies which are quotations in a seperate file. That's easy, they should be recognized by the "--" which precedes the source of the saying: cdbsplit cookies quotes -k-- Another example: You might want to move all Bart Simpson quotes to a separate "simpsons" file. That's a little trickier, as "Bart" is a rather short keyword, which might appear as part of other words as well. Try three passes, cautious at first, then more generous to make sure you get them all: cdbsplit cookies simpsons -KBart -KSimpson This collects cookies with both "Bart" and "Simpson" in them (note the capital -K!). I can't imagine anything going wrong here. cdbsplit cookies simps2 "-kBart " -d1 -c Note how the -d1 in this second command will make "Bart!" but not "Barton" be identified as "Bart ". But as this keyword fails if "Bart" appears at the very end of a cookie, you still have to collect the rest: cdbsplit cookies simps3 -kBart Now look at the "simps2" and "simps3" files and check if anything went wrong with them. In my case, I found a quotation by a guy named "Barth". It's easy to put it back: cdbsplit simps3 cookies -kBarth -a Finally, put the three hit files together: cdbsplit simps2 simpsons -a cdbsplit simps3 simpsons -a 4.4. Support for editing manually --------------------------------- CdbSplit can help you collect all cookies that need reformatting (because they are too wide) in an extra file, and put them back later: cdbsplit -w76 cookies wide Ed wide ; add some line breaks cdbsplit wide cookies -a Now this was easy. But cdbsplit can even help you to find groups of "similar" cookies! That's helpful to eliminate cookies that differ only by some typing error (e.g. 'seperate'/'separate'), something that cookietool will *never* handle automatically. To do this, you must sort your database first, then tell cdbsplit how many agreeing characters make "similar" cookies (I think 10 - 20 characters is usually a good choice): cookietool cookies -s -d0 -p cdbsplit cookies temp -d0 -m20 Ed temp ; delete some manually cdbsplit temp cookies -a When editing the "temp" file, you should find groups of two or more cookies with identical beginnings. If you think they are really the same, you can delete all but one (!) of each group. Of course, this is tedious work, but still far easier than just sorting the database and looking for similar cookies with your eyes only! Here's a more sophisticated procedure that will extract groups of cookies starting and ending with the same word (well, almost): cookietool cookies -s -d1 -p ; regular sorting first cookietool cookies -sw -d1 -p ; *then* sort by last word cdbsplit cookies temp -d1 -m3 ; yes, 3 matching characters will do! Ed temp ; delete all but one from each group cdbsplit temp cookies -a ; put the others back Applying -s-- instead of -sw in the second pass could help you find similar sayings that are attributed to the same person. 4.5. Joining "good" and "bad" cookie files ------------------------------------------ Suppose you have a well maintained cookie database, without double entries, all the cookies are formatted the way you want them, and all the authors of quotations are written down in your preferred style. Now you find an archive with new cookies somewhere and you want to add them to your database. You could simply join the files and let CookieTool remove the duplicates, but I'd suggest a slightly more sophisticated procedure using CdbDiff: cdbdiff cookies visitors diff -d0 Now you can look at the "diff" file (which will usually be much smaller than "visitors") to see what new cookies you've got, edit and reformat where needed, and then finally append the result to your main database. Ed diff cdbsplit diff cookies -a 4.6. Extract poems ------------------ Would you agree that a poem is something that has at least four lines, but doesn't use the full line width? So let's try this: cdbsplit -l4 -W60 cookies poems You should check the contents of "poems" manually now, and maybe you will want to move some of the wider cookies back. Not a problem: cdbsplit poems cookies -w51 -a 4.7. File format options ------------------------ First of all, some things to avoid: - Don't specify a -f option that doesn't match the actual format of your database. This will usually do some serious damage, rather than just fail. For example, running "cookietool -f1" on a database of "%%"- separated cookies will delete all but one of the "%%" lines! - Think twice before changing file format with the -F option: Converting between format 2 and 3 is always safe, but converting to a "lower" format usually isn't. For example, "cookietool -f3 -F1" more or less only removes the "%%" lines, it *does not* check for multi-line cookies, unwrapping them to a single line or whatever would seem reasonable. Now let's assume you have a cookie database in "%%" format and want to export all one-liners into a plain text file: cdbsplit -x -L1 cookies short cookietool short -f3 -F1 Or, for a weird reading experience, try the following, which removes all duplicate words from this doc file: copy README temp cookietool temp -f0 -d0 more temp delete temp More seriously, CookieTool can be used to create a list of words from an arbitrary text file. You only need to change the last example slightly: copy README words cookietool words -f0 -F1 -d0 -s 5. Background information ------------------------- Just like "onecookie", "cookietool" has to load the complete database into memory first, so it may fail on very large databases. But unlike "onecookie" does, the cookies aren't compared each against all others (O(n*n) operation) but sorted first and then compared against their neighbours only (O(n*log n) operation). For a database of 1000 cookies, that's about 100 times faster! Overwriting input files is done by creating a tempfile and renaming it when all else is done. So breaking (or crashing) the programs won't lead to data loss. Unless, of course, you use cookietool in '-o' mode, which is why that option is deprecated. Note that breaking "cdbsplit" while it is appending to another file is no good idea. All cookies that were already copied are then present in both files, and most likely the output file even ends with an incomplete cookie! The same can happen without your fault, if cdbsplit encounters a "Disk Full" error. In both cases, don't append any further data to this output file, or the first of the new cookies will be merged with that incomplete cookie, due to the missing %% separator! You might run "cookietool" once on the output file, to ensure a valid file format again. 6. History ---------- V1.0 - V1.3 forget them, they were all crap, too hard to use V2.0 no more reformatting of cookies, sorry for those who miss it :'( V2.1 fixed a bug that would unnecessarily lose data after "Disk Full" errors V2.2 added search for combinations of keywords and the -x option for CdbSplit, CookieTool can now sort by size V2.3 changed licensing to GPL, minor bugfix in CdbSplit (the -w option was off by one from its designed behaviour), cookie separator can be redefined as something other that "%%" at compile time, added short manpages for cookietool and cdbsplit V2.4 fixed some bugs (the -b option in CookieTool and the -d option in CdbSplit were broken, and some kinds of buffer overflow weren't properly intercepted), the cookie file format can now be set at run time, CookieTool can now append to its dumpfile. V2.5 added the CdbDiff tool 7. Credits ---------- CookieTool, CdbSplit and CdbDiff are distributed under GNU General Public License version 2 or later. The author is: Wilhelm Nöker Hertastr. 8, D-44388 Dortmund Drop me an e-mail if you like these programs, or if you have some suggestions. The man pages, the Linux makefile and the "GPL paperwork" for V2.3 were done by Miroslaw 'Jubal' Baran . Greetings to Christian Kemp (author of IntuiCookie and of the Amiga port of SmartAss, and, last not least: maintainer of the great Amiga Network News web pages at www.ann.lu). CookieTool, CdbSplit and CdbDiff were written using CygnusEd V4.2 and the GNU C compiler (with libnix). cookietool-2.5/strstuff.c0100600000175000017500000001472507250371732014513 0ustar baranbaran/* (c) 1995-2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: strstuff.c Date: 20 Sep 1997 | *------------------------------------------------------------------------* | Some string functions, similar to those from the standard library | | in , but more flexible. | | You must call str_setup() before using any of these functions !!! | | | \*========================================================================*/ #include #include #include #include "strstuff.h" UBYTE to_upper[ 256 ]; /* conversion table */ int is_space[ 256 ]; /* lookup table */ int bordermode, case_sense; /* * Like strncpy(), but guarantees a null delimiter. */ UBYTE *str_ncpy( UBYTE *t, UBYTE *s, size_t n ) { strncpy( t, s, n ); t[ n-1 ] = '\0'; return t; } /* * Set up a to_upper[] table that can convert all national characters from * the ISO Latin-1 charset to uppercase, not only 'a'-'z'. * Depending on the global variable this table may just as * well do nothing at all. * Similarly, the is_space[] table which is built here may call anything * but alphanumerics a 'space', depending on the setting of . */ void str_setup( int bm, int cs ) { int c, d; bordermode = bm; case_sense = cs; /* set global variables */ for( c = 0; c < 256; c++ ) { to_upper[ c ] = c; is_space[ c ] = ( bordermode < 2 || (c & 0x7f) <= ' ' ); } for( c = 'a'; c <= 'z'; c++ ) { d = c + 'A' - 'a'; to_upper[ c ] = d; is_space[ c ] = 0; is_space[ d ] = 0; } for( c = '0'; c <= '9'; c++ ) { is_space[ c ] = 0; } for( c = 224; c < 256; c++ ) if( c != 247 ) { /* 247 is the division sign -:- */ d = c - 32; is_space[ c ] = 0; is_space[ d ] = 0; if( c != 255 ) /* and don't convert '"y' to 'sz' : ) */ to_upper[ c ] = d; } if( case_sense ) /* destroy the to_upper[] table again */ for( c = 0; c < 256; c++ ) to_upper[ c ] = c; is_space[ 0 ] = 0; /* important, we'll take advantage of this! */ } /* * str_cmp() will work like strcmp() if( case_sense && bordermode == 3 ), * but can change its behaviour depending on those variables. * Will also indicate by special (but legal) return values if was an * abbreviation of or vice versa. */ int str_cmp( UBYTE *s, UBYTE *t ) { if( bordermode < 3 ) { /* modes where number of 'spaces' doesn't count */ while( is_space[ *s ] ) s++; /* advance to first word */ while( is_space[ *t ] ) t++; while( to_upper[ *s ] == to_upper[ *t ] ) { if( *s == '\0' ) return 0; s++; t++; if( !bordermode || (is_space[ *s ] && is_space[ *t ]) ) { /* both at the end of a word OR in sloppy bordermode */ while( is_space[ *s ] ) s++; /* skip the spaces */ while( is_space[ *t ] ) t++; } } } else { while( to_upper[ *s ] == to_upper[ *t ] ) { if( *s == '\0' ) return 0; s++; t++; } } if( *s == '\0' ) return STR_SHORTER; else if( *t == '\0' ) return STR_LONGER; else return( to_upper[ *s ] - to_upper[ *t ] ); } /* * The same as str_cmp(), but will only compare up to characters. * (Only two lines of code are different.) */ int str_ncmp( UBYTE *s, UBYTE *t, size_t n ) { if( bordermode < 3 ) { while( is_space[ *s ] ) s++; while( is_space[ *t ] ) t++; while( to_upper[ *s ] == to_upper[ *t ] ) { if( --n == 0 || *s == '\0' ) return 0; /* that's the difference */ s++; t++; if( !bordermode || (is_space[ *s ] && is_space[ *t ]) ) { while( is_space[ *s ] ) s++; while( is_space[ *t ] ) t++; } } } else { while( to_upper[ *s ] == to_upper[ *t ] ) { if( --n == 0 || *s == '\0' ) return 0; /* and here once more */ s++; t++; } } if( *s == '\0' ) return STR_SHORTER; else if( *t == '\0' ) return STR_LONGER; else return( to_upper[ *s ] - to_upper[ *t ] ); } /* * Find a copy of t in s, like strstr( )does. * Note that bordermode has NO effect here! */ UBYTE *str_str( UBYTE *s, UBYTE *t ) { int c; while( *s ) { c = str_cmp( s, t ); if( c == 0 || c == STR_LONGER ) return s; s++; } return NULL; } /* * Some user info printed to . */ void print_strstat( void ) { printf( "string processing:\n" ); printf( " upper-/lowercase: " ); if( case_sense ) printf( "strict\n" ); else printf( "'ABC'='abc'\n" ); printf( " word delimiters: " ); switch( bordermode ) { case 0: printf( "'a,b c'='abc'\n" ); break; case 1: printf( "'a, b, c'='a,b c'\n" ); break; case 2: printf( "'a b c'='a b c'\n" ); break; case 3: printf( "strict\n" ); break; } } cookietool-2.5/strstuff.h0100600000175000017500000000426607256355312014521 0ustar baranbaran/* cookietool is (c) 1995-2001 by Wilhelm Noeker (wnoeker@t-online.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*========================================================================*\ | File: strstuff.h Date: 20 Sep 1997 | *------------------------------------------------------------------------* | Some string functions, similar to those from the standard library | | in , but more flexible. | | You must call str_setup() before using any of these functions !!! | | | \*========================================================================*/ #ifndef _STRSTUFF_H_ #define _STRSTUFF_H_ typedef unsigned char UBYTE; /* special return values for str_cmp() and strn_cmp() */ #define STR_LONGER 256 #define STR_SHORTER -256 /* possible values for bordermode (treatment of word delimiters): */ #define BM_FUSSY 3 /* compare char by char */ #define BM_DONTCOUNT 2 /* number (and kind) of spaces doesn't matter */ #define BM_SPACEPUNCTS 1 /* treat punctuation like spaces */ #define BM_MERGE 0 /* merge all alphanumerics into one single word */ void str_setup ( int bordermode, int case_sense ); void print_strstat( void ); int str_cmp ( UBYTE *s, UBYTE *t ); int str_ncmp ( UBYTE *s, UBYTE *t, size_t n ); UBYTE *str_str ( UBYTE *s, UBYTE *t ); UBYTE *str_ncpy ( UBYTE *t, UBYTE *s, size_t n ); #endif