Fun_People Archive
5 Apr
tdf.c -- Telecom Decency Filter


Date: Fri, 5 Apr 96 19:17:38 -0800
From: Peter Langston <psl>
To: Fun_People
Subject: tdf.c -- Telecom Decency Filter

Forwarded-by: larryy@apple.com (Larry Yaeger)

/* This simple C program, tdf.c, is the new Telecommunications Decency Filter,
 *  brought to you by someone.
 *
 * Need to clean up your web page?  News posts?  Email?  Tdf is just what
 *  you need!  Tdf is a simple filter which copies stdin to stdout, swapping
 *  _decent_ words in for any _indecent_ ones it finds.  Don't think you
 *  write indecently?  Better safe than in jail!  Use tdf on everything!
 *  You never know when speaking of the flapping muscles of a chicken might
 *  get your favorite discussion group banned!
 *
 * "How can I be sure the words tdf uses will be considered decent?"
 *
 * Not to fear!  Tdf selects its stand-ins from amongst the names of the
 *  politicians who brought you this lovely bill.  If _their_ names aren't
 *  decent, what are!?
 *
 * "Is there a reverse filter, to make tdf files read normally again?"
 *
 * No!  That would defeat the purpose!  With a little exposure, you'll learn
 *  the new words by heart!  Then you can use them in your everyday speech,
 *  and you wont have to worry about offending _anyone_, _ever_.  Wouldn't
 *  that be great!?
 *
 * Typical usage:
 *
 *    tdf < myLetter | Mail president@gov.gov
 * or:
 *    tdf < dirtyLetter > cleanLetter
 *
 * or, as a vi macro:
 *    :map #t :%!tdf^M
 *
 * etc..
 *
 * If you find indecent words slipping through, please add them to the
 *  list.  I've appended (what I beleive to be) a list of all yea-sayers
 *  after the existing mappings, so you'll have plenty of stand-ins to choose
 *  from.  Don't change existing mappings -- consistency is important if
 *  we're all to learn these names by heart.  If you get two versions with
 *  different mappings, do you best to merge them in a consistent manner
 *  before passing them on.  Keep an eye on the nets to see where the trends
 *  are taking it.  Hopefully we can eventually settle on a single consistent
 *  mapping which catches all the indecent words, and uses all the yea-sayers
 *  names.  If someone starts a newsgroup to coordinate this process, be sure
 *  to ascii shift the indecent words in your discussions!  (I know, it's
 *  a pain, but that's the one news group where tdf couldn't help you!)
 *
 * Tdf automatically matches the case of the first letter when making
 *  substitutions.
 *
 * Feel free to port this to other machines -- a plug-in for Eudora would
 *  be great!  Standalone Mac and PC versions would be handy too!  But
 *  please, whatever you do, keep the format of the names the same, so
 *  people can copy-paste update the name lists between ports; and keep
 *  this header.
 *
 * The _indecent_ words have been ascii shifted by one so you can email
 *  or post this file without morally corrupting the nets.
 *
 * You can always run tdf interactively if you want to see if it knows
 *  particular words.
 */

#include <stdio.h>

    typedef char *string;

    string mapping[][2] = {
        /*
         * Keep the key players at the top!
         */
        { "fydsfnfou"      , "exon"           },
        { "tiju"           , "exon"           },
        { "uvse"           , "exon"           },
        { "uvseejoh"       , "exoning"        },
        { "ejdl"           , "pressler"       },
        { "dpdl"           , "pressler"       },
        { "ejdlt"          , "presslers"      },
        { "dpdlt"          , "presslers"      },
        { "qfojt"          , "pressler"       },
        { "qfojtft"        , "presslers"      },
        { "ejmep"          , "pressler"       },
        { "ejmept"         , "presslers"      },
        { "btt"            , "grassley"       },
        { "bttft"          , "grasslies"      },
        { "wbhjob"         , "fields"         },
        { "wbhjobt"        , "fields"         },
        { "dvou"           , "fields"         },
        { "uxbu"           , "fields"         },
        { "tfy"            , "hyde"           },
        { "gvdl"           , "mack"           },
        { "gvdljoh"        , "macking"        },
        { "gvdlfe"         , "macked"         },
        { "gvdlfs"         , "macker"         },
        { "gbh"            , "bennett"        },
        { "ipnp"           , "helms"          },
        { "fspujd"         , "d'Amato"        },
        { "ipnptfyvbm"     , "helms-hyde"     },
        { "mftcjbo"        , "lautenberg"     },
        { "qfepqijmf"      , "levin"          },
        { "qfepqijmjb"     , "levina"         },
        { "dpoepn"         , "cochran"        },
        { "dpoepnt"        , "cochrans"       },
        { "qvttz"          , "shelby"         },
        { "qvttjft"        , "shelbies"       },
        { "dspudi"         , "craig"          },
        { "dspudift"       , "craigs"         },
        { "csfbtu"         , "breaux"         },
        { "csfbtut"        , "breaux"         },
        { "uisvtu"         , "frist"          },
        { "ovef"           , "faircloth"      },
        { "bovt"           , "ashcroft"       },
        { "hspjo"          , "gorton"         },
        { "tdspuvn"        , "santorum"       },
        { "ojqqmf"         , "nunn"           },
        { "ojqqmft"        , "nunns"          },
        { "ebno"           , "doll"           },
        { "qjtt"           , "mikulski"       },
        { "qjttfe"         , "mikulskied"     },
        { "dvn"            , "snowe"          },
        { "tqfsn"          , "snowe"          },
        { "tfnfo"          , "snowe"          },
        { "pshbtn"         , "inouye"         },
        { "pshbtnjoh"      , "inouying"       },
        { "pshbtnjd"       , "inouyic"        },
        { "dmjupsjt"       , "coverdell"      },
        { "dmju"           , "coverdell"      },
        { "dmjut"          , "coverdells"     },
        { "mvtu"           , "lugar"          },
        { "cvuu"           , "bingaman"       },
        { "cvuut"          , "bingamans"      },
        { "cvuupdl"        , "bingaman"       },
        { "cvuupdlt"       , "bingamans"      },
        { "bcpsujpo"       , "abraham"        },
        { "bcpsujpot"      , "abrahams"       },
        { NULL, NULL },
    };

/*
 * Here are the yea-sayers to the Telecommunications bill:
       Abraham
       Akaka
       Ashcroft
       Baucus
       Bennett
       Biden
       Bingaman
       Bond
       Boxer
       Bradley
       Breaux
       Brown
       Bryan
       Bumpers
       Burns
       Byrd
       Campbell
       Chafee
       Coats
       Cochran
       Cohen
       Conrad
       Coverdell
       Craig
       D'Amato
       Daschle
       DeWine
       Dole
       Domenici
       Dorgan
       Exon
       Faircloth
       Feinstein
       Ford
       Frist
       Glenn
       Gorton
       Graham
       Grams
       Grassley
       Gregg
       Harkin
       Hatch
       Hatfield
       Heflin
       Helms
       Hollings
       Hutchison
       Inhofe
       Inouye
       Jeffords
       Johnston
       Kassebaum
       Kempthorne
       Kennedy
       Kerrey
       Kerry
       Kohl
       Kyl
       Lautenberg
       Levin
       Lieberman
       Lott
       Lugar
       Mack
       McConnell
       Mikulski
       Moseley-Braun
       Moynihan
       Murkowski
       Murray
       Nickles
       Nunn
       Pell
       Pressler
       Pryor
       Reid
       Robb
       Roth
       Santorum
       Sarbanes
       Shelby
       Simpson
       Smith
       Snowe
       Specter
       Stevens
       Thomas
       Thompson
       Thurmond
       Warner

 */

    typedef struct NodeStruct *Node;
    struct NodeStruct {
        Node   next[26];
        string mapto;
    };

#define NodeAllocate() ((Node)(malloc(sizeof(struct NodeStruct))))

    Node root = NULL;

#define misalpha(c) (((c)>='a'&&(c)<='z')||((c)>='A'&&(c)<='Z'))
#define mlower(c) (((c)<'a')?((c)+('a'-'A')):(c))

Node NodeNew();
Node NodeAdd();

main()
{
    int i;
    root = NodeNew();

    for (i=0; mapping[i][0]; i++)
        AddMapping(mapping[i][0],mapping[i][1]);

    docopy(stdin,stdout);
    exit(0);
}


docopy(in,out)
FILE *in, *out;
{
    int c;
    Node node;
    char hold[50];
    int  holdlen;

    holdlen = 0;
    node    = root;

    while ((c = getc(in)) != EOF) {

        if (!misalpha(c)) {
            if (node->mapto) {
                if (hold[0]<'a')
                    putc(node->mapto[0]-('a'-'A'),out);
                else
                    putc(node->mapto[0],out);
                fprintf(out,"%s",node->mapto+1);
            } else {
                if (holdlen)
                    fwrite(hold,1,holdlen,out);
            }
            holdlen = 0;
            node    = root;
            putc(c,out);
            continue;
        }

        hold[holdlen++] = c;
        if (!(node = node->next[mlower(c)-'a'])) {
            fwrite(hold,1,holdlen,out);
            holdlen = 0;
            node    = root;
        }
    }
}


AddMapping(from, to)
string from,to;
{
    NodeAdd(root,from)->mapto = to;
}

Node NodeAdd(from, s)
Node from;
string s;
{
    int c;

    c = *(s++);

    if (!c)
        return(from);

    c--;    /* Undo the encryption shift */

    if (c < 'a' || c > 'z')
        return(NodeAdd(from,s));

    c -= 'a';

    if (!from->next[c])
        from->next[c] = NodeNew();

    return(NodeAdd(from->next[c],s));
}

Node NodeNew()
{
    int i;
    Node n;

    n = NodeAllocate();

    n->mapto = NULL;

    for (i=0; i<26; i++)
        n->next[i] = NULL;

    return(n);
}


prev [=] prev © 1996 Peter Langston []