From demon!bnr.co.uk!bnrgate!bcars6a8!bcarh10d!markem Fri Apr  9 04:07:58 GMT 1993
Article: 990 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.1 part 1/1
Message-ID: <1993Apr8.021300.27302@bcars6a8.bnr.ca>
Originator: markem@bcarh10d
Sender: usenet@bcars6a8.bnr.ca (Use Net)
Nntp-Posting-Host: bcarh10d
Organization: Bell Northern Research, Ottawa, Canada
Date: Thu, 8 Apr 1993 02:13:00 GMT
Lines: 352


This is MANAGRAM Version 2.1, use it to find find anagrams of a word
from a wordlist.

--------------------> CUT HERE <---------------------------------------------

# 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 Tue Apr  6 19:43:51 1993
#
# This archive contains:
#	managram.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'
#include <stdio.h>
#ifdef BSD
#include <strings.h>
#else
#include <string.h>
#endif

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);
         exit(1);
      }

   if (strcmp(argv[1], "-version") == 0)
      {
         fprintf(stdout, "MAnagram Version %s by Mark Mielke\n", VERSION);
         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 28852
then
	echo ERROR: managram.c checksum is $1 should be 28852
fi

touch -m 0402203193 managram.c
touch -a 0406193993 managram.c
chmod 644 managram.c

echo x - Makefile
sed 's/^@//' >Makefile <<'@EOF'
###
### Makefile for MAnagram
###



VERSION = 2.1

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

## for GCC
#CFLAGS = -O2
#CC = gcc -pipe # -pipe speeds up compiling time, if you have it.

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

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

LIBS =
OBJS = managram.o
SRCS = managram.c
TARG = managram

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

@.c.o:
	$(CC) $(CFLAGS) ${BSD} -DVERSION='"${VERSION}"' -c ${<}

${TARG}${VERSION}.shar:
	shar -ms ${SRCS} Makefile README managram.1 >${TARG}${VERSION}.shar

${TARG}${VERSION}.tar:
	tar cf ${TARG}${VERSION}.tar ${SRCS} Makefile README managram.1

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

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

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

touch -m 0406193993 Makefile
touch -a 0406194393 Makefile
chmod 644 Makefile

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

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 47557
then
	echo ERROR: README checksum is $1 should be 47557
fi

touch -m 0406191393 README
touch -a 0406185993 README
chmod 644 README

echo x - managram.1
sed 's/^@//' >managram.1 <<'@EOF'
@.TH managram 1
@.SH NAME
managram - Mark's anagram finder - Version 2.1
@.SH SYNOPSIS
managram
@.ul
somestring
<
@.ul
wordfile

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

gzcat
@.ul
wordfile
| managram
@.ul
somestring
  # For
@.ul
gzip(1)ped
files.
@.ul
(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
@.ul
Wordfile
contains:
@.br
   cab
@.br
   car
@.br
   cat
@.sp
If your run:
@.br
   managram abc <
@.ul
Wordfile
@.br
you get:
@.br
   cab
@.sp
If you run:
@.br
   managram act <
@.ul
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
@.SS "Mar ??"
-managram (then anagram) created.
@.br
-Latest Version: 1.0
@.SS "Mar 28"
-managram completely re-written, source easier to comprehend now.
@.br
-Makefile & README files created.
@.br
-Latest Version: 2.0
@.SS "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
@EOF
set `sum $sumopt <managram.1`; if test $1 -ne 36319
then
	echo ERROR: managram.1 checksum is $1 should be 36319
fi

touch -m 0406194293 managram.1
touch -a 0406194293 managram.1
chmod 600 managram.1

exit 0


-- 
markem@bnr.ca


