From demon!bnr.co.uk!bnrgate!bcars6a8!bcarh10d!markem Wed Apr 28 00:23:20 GMT 1993
Article: 1105 of alt.sources
Newsgroups: alt.sources
Path: demon!bnr.co.uk!bnrgate!bcars6a8!bcarh10d!markem
From: markem@bcarh10d.bnr.ca (Dave Mielke)
Subject: MAnagram 2.5
Message-ID: <1993Apr25.204810.20308@bcars6a8.bnr.ca>
Originator: markem@bcarh10d
Sender: usenet@bcars6a8.bnr.ca (Use Net)
Nntp-Posting-Host: bcarh10d
Organization: Bell Northern Research, Ottawa, Canada
Date: Sun, 25 Apr 1993 20:48:10 GMT
Lines: 454


Unpack this shell archive, and have fun!

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by Dave Mielke <markem@bcarh10d> on Sun Apr 25 16:47:30 1993
#
# This archive contains:
#	managram.c	version.c	Makefile	README		
#	managram.1	
#
# Modification/access file times will be preserved.
# Error checking via sum(1) will be performed.

LANG=""; export LANG
PATH=/bin:/usr/bin:$PATH; export PATH

if sum -r </dev/null >/dev/null 2>&1
then
	sumopt='-r'
else
	sumopt=''
fi

echo x - managram.c
cat >managram.c <<'@EOF'
/* managram.c
 *
 * Part of MAnagram, Mark Mielke's anagram finder.
 *
 * The actual anagram program.
 */


#include <stdio.h>

#ifdef BSD
#include <strings.h>
#else
#include <string.h>
#endif

static char rcsid[] = "$id$";

struct CompiledWord
     {
          char letter_usage[26];
          /* Counters for each letter of the alphabet */
          int length;/* Number of letters in WORD */
     };

struct CompiledWord origWord;
struct CompiledWord Word;

void CompileWord(w, word)
     struct CompiledWord *w;
     char *word;
{
     int i, length = 0;
     char *letter_usage = w->letter_usage;

#ifdef BSD
     bzero(letter_usage, 26);
#else
     memset(letter_usage, 0, 26);
#endif

     while (*word)
          {
               char ch = *word++;

               if (ch >= 'a' && ch <= 'z')
                    ch -= ('a' - 'A');

               if (ch < 'A' || ch > 'Z')
                    continue;
                                /* Skip non-alphabetic characters */

               letter_usage[ch - 'A']++, length++;
          }
     w->length = length;
}

int WordsEqual(w1, w2)
     struct CompiledWord *w1, *w2;
{
     char *letter_usage1 = w1->letter_usage;
     char *letter_usage2 = w2->letter_usage;
     int i;

     if (w1->length != w2->length)
          return 0;    /* Quick elimination of a possible */

     for (i = 0; i < 26; i++)
          if (letter_usage1[i] != letter_usage2[i])
               return 0;

     return 1;         /* Otherwise, they match */
}

int main(argc, argv)
     int argc;
     char **argv;
{
     char *progname = *argv;
     char buffer[0xFF];

     if (--argc != 1)
          {
               fprintf(stderr, "Usage: %s {word} <{wordfile}\n", progname);
fprintf(stderr, "   or, %s {--version | -v}\n", progname);
               exit(1);
          }

     if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0)
          {
               showVersion();
               exit(0);
          }

     CompileWord(&origWord, argv[1]);

     while (fgets(buffer, sizeof(buffer), stdin) != NULL)
          {
               CompileWord(&Word, buffer);
               if (WordsEqual(&origWord, &Word))
                    fputs(buffer, stdout);
          }

     return 0;
}
@EOF
set `sum $sumopt <managram.c`; if test $1 -ne 35613
then
	echo ERROR: managram.c checksum is $1 should be 35613
fi

touch -m 0425163393 managram.c
touch -a 0425163393 managram.c
chmod 444 managram.c

echo x - version.c
cat >version.c <<'@EOF'
/* version.c
 *
 * Part of MAnagram, Mark Mielke's anagram finder.
 *
 * Keeps track of the current version
 */


#include <stdio.h>

static char rcsid[] = "$Id: version.c,v 2.5 1993/04/25 20:26:31 markem Exp $";

void showVersion()
{
     /* Print out Version. */

#ifdef VERSION
     fprintf(stderr, "Managram v%s\n", VERSION);
#else
     fprintf(stderr, "Managram, Version unknown.\n");
#endif

     /** Figure out the following, and **/
     /** you're a genius. :-)          **/

#if defined(COMPILER) || defined(CFLAGS) || defined(LDFLAGS) || defined(BSD)

     /* Show Compiler information. (How it was compiled) */

     fprintf(stderr, "Compiled with:");

#ifdef COMPILER
     fprintf(stderr, " %s", COMPILER);
#else
#ifdef __GNUC__
     fprintf(stderr, " gcc", COMPILER);
                                        /* Good guess */
#endif /*__GNUC__*/
#endif /*COMPILER*/

#ifdef CFLAGS
     fprintf(stderr, " %s", CFLAGS);
#else
#ifdef BSD
     fprintf(stderr, " -DBSD", CFLAGS);
#endif /*BSD*/
#endif /*CFLAGS*/

#ifdef LDFLAGS
     fprintf(stderr, " %s", LDFLAGS);
#endif /*LDFLAGS*/

     fprintf(stderr, "\n");

#endif /*COMPILER||CFLAGS||LDFLAGS||BSD*/

     /* Show compiler Date & Time */

#if defined(__DATE__) || defined(__TIME__)
     fprintf(stderr, "Compiled");
#ifdef __DATE__
     fprintf(stderr, " on %s", __DATE__);
#endif /*__DATE__*/
#ifdef __TIME__
     fprintf(stderr, " at %s", __TIME__);
#endif /*__TIME__*/
     fprintf(stderr, ".\n");
#endif /*__DATE__||__TIME__*/
}
@EOF
set `sum $sumopt <version.c`; if test $1 -ne 26601
then
	echo ERROR: version.c checksum is $1 should be 26601
fi

touch -m 0425163393 version.c
touch -a 0425163393 version.c
chmod 444 version.c

echo x - Makefile
cat >Makefile <<'@EOF'
###
### Makefile for MAnagram 2.5
###
### Part of MAnagram, Mark Mielke's anagram finder.
###


## Current version (leave alone)
VERSION = 2.5

## Uncomment for BSD platforms.
BSD = #-DBSD

CFLAGS = -O # or +O3 if you have it.
CC = cc

## for GCC
CFLAGS = -O2 -pipe -traditional
CC = gcc

LDFLAGS = -s # Strip the executable. (Makes it a bit smaller)

OTHER= Makefile README managram.1
LIBS =
OBJS = managram.o version.o
SRCS = managram.c version.c
TARG = managram

${TARG}: ${OBJS}
	$(CC) $(LDFLAGS) -o ${@} ${OBJS} ${LIBS}

managram.o: managram.c
	$(CC) $(CFLAGS) ${BSD}	-c $<

version.o: version.c
	$(CC) $(CFLAGS) ${BSD} -DVERSION='"${VERSION}"' -DCOMPILER='"$(CC)"' -DCFLAGS='"$(CFLAGS) ${BSD}"' -DLDFLAGS='"$(LDFLAGS)"'	-c $<

${TARG}${VERSION}.shar: ${SRCS} ${OTHER}
	shar -ms ${SRCS} ${OTHER} >${TARG}${VERSION}.shar

${TARG}${VERSION}.tar: ${SRCS} ${OTHER}
	tar cf ${TARG}${VERSION}.tar ${SRCS} ${OTHER}

clean:
	rm -f ${OBJS}

clobber:
	rm -f ${OBJS} ${TARG} core

shar: ${TARG}${VERSION}.shar

tar: ${TARG}${VERSION}.tar

@EOF
set `sum $sumopt <Makefile`; if test $1 -ne 43889
then
	echo ERROR: Makefile checksum is $1 should be 43889
fi

touch -m 0425163393 Makefile
touch -a 0425164793 Makefile
chmod 444 Makefile

echo x - README
cat >README <<'@EOF'
MAnagram - Mark Mielke's anagram finder - Version 2.5
-----------------------------------------------------

Edit the Makefile to taste, run 'make', and you should get an
executable called 'managram'.

Use this program like:
	managram someword < wordfile

Wordfile:
   Is a file full of words, one per line.
Someword:
   Is any string of characters, non-alphabetic charcters are ignored, search
   is case-insensitive.

See the manpage for further details.

If you have any improvements, enhancements, or bug(s|fixes), to donate, e-mail to:
   davem@bnr.ca         -On the Internet
   markem@bnr.ca        -Within BNR
   mem@bcarh10d.bnr.ca  -Within BNR

@EOF
set `sum $sumopt <README`; if test $1 -ne 60461
then
	echo ERROR: README checksum is $1 should be 60461
fi

touch -m 0425164793 README
touch -a 0425164793 README
chmod 444 README

echo x - managram.1
sed 's/^@//' >managram.1 <<'@EOF'
@.TH managram 1 "Contributed by Mark Mielke" "Local Software"
@.Id $Id: managram.1,v 2.5 1993/04/25 20:25:18 markem Exp $
@.SH NAME
managram - Mark's anagram finder - Version 2.5
@.SH SYNOPSIS
managram -version

managram
@.I "somestring < wordfile"

zcat
@.I wordfile
| managram
@.I somestring
  # For
@.I compress(1)ed
files.

gzcat
@.I wordfile
| managram
@.I somestring
  # For
@.I gzip(1)ped
files.
@.I (GNU)
@.SH "DESCRIPTION"
This is a program to find anagrams given a string of characters
and a list of words.
@.SS "Program Usage"
This program ignores non-alphabetic characters, and is not
case-sensitive. The list of search words is taken on stdin.
The anagram string is the only argument.
@.SS "Word File"
The word file is a list of words, one per line. For example:

cab
@.br
car
@.br
cat
@.br
@.SH OPTIONS
This program presently has no options.
@.SH EXAMPLES
@.I Wordfile
contains:
@.br
   cab
@.br
   car
@.br
   cat
@.sp
If your run:
@.br
   managram abc <
@.I Wordfile
@.br
you get:
@.br
   cab
@.sp
If you run:
@.br
   managram act <
@.I wordfile
@.br
you get:
@.br
   cat
@.SH FILES
A wordfile used as the anagram search source
@.SH NOTES
You may distribute, modify, or erase this program, as long as
the author's name's in it, and you don't get any money for it. :-)
@.SH BUGS
Please report bugs or enhancements to:

   davem@bnr.ca    -On the Internet
@.br
   markem@bnr.ca   -Within BNR
@.br
   mem@bcarh10d.bnr.ca -Within BNR
@.SH AUTHOR
Mark Mielke
@.SH HISTORY
@.TP
@.B "Mar ??"
-managram (then anagram) created.
@.br
-Latest Version: 1.0
@.TP
@.B "Mar 28"
-managram completely re-written, source easier to comprehend now.
@.br
-Makefile & README files created.
@.br
-Latest Version: 2.0
@.TP
@.B "Apr  6"
-Manpage donated by Bryan Miller <grey@bnr.ca>, Thanks Bryan.
@.br
-anagram.c renamed managram.c
@.br
-Makefile & READE files modified.
@.br
-Latest Version: 2.1
@.TP
@.B "Apr 22"
-Manpage, anagram.c modified
@.br
-version.c added.
@.br
-Latest Version: 2.5
@.SH "SEE ALSO"
compress(1), gzip(1).
@EOF
set `sum $sumopt <managram.1`; if test $1 -ne 15972
then
	echo ERROR: managram.1 checksum is $1 should be 15972
fi

touch -m 0425164793 managram.1
touch -a 0425164793 managram.1
chmod 400 managram.1

exit 0
-- 
markem@bnr.ca


