home *** CD-ROM | disk | FTP | other *** search
- /*
- * 78code.h - definitions for trigram encodings
- *
- * Copyright 1989 Howard Lee Gayle
- *
- * $Header: 78code.h,v 1.2 89/08/25 11:16:02 howard Exp $
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 1,
- * as published by the Free Software Foundation.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Prerequisites: howard/port.h howard/a2.h 78.h
- */
-
- PRIVATE byteT byte2t[256]; /* Map each byte to a trigram code.*/
- PRIVATE byteT t2byte[TRINONE]; /* Map trigram code to printable character.*/
-
- /* rdcode - read in a trigram encoding file and initialize byte2t and t2byte */
-
- PRIVATE void rdcode (fn)
- R4 bStrT fn; /* Name of trigram encoding file.*/
-
- /* Function:
- * Initialize byte2t[] and t2byte[] by reading the given encoding file.
- * Algorithm:
- * Initialize each element of byte2t[] to TRINONE.
- * Read each line in the encoding file.
- * Store the primary representation in t2byte[] and byte2t[].
- * Store any secondary representations in byte2t[].
- * Returns:
- *
- * Notes:
- *
- */
- {
- R2 int i; /* Trigram code for current letter.*/
- R3 streamT is; /* Input stream.*/
- unsigned ln = 0; /* Line number.*/
- R1 bStrT p; /* Steps through lb[].*/
- bStrT p0; /* mra2i() stores end of number here.*/
- byteT lb[MLINE]; /* Line buffer.*/
-
- is = mfopen (fn, "r");
- for (p = byte2t; p != &byte2t[256];)
- *p++ = TRINONE;
- t2byte[TRIBEG] = '(';
- t2byte[TRIEND] = ')';
- while (NULBSTR != getlic (lb, MLINE, is, fn, &ln, 1, COMMENT))
- {
- i = mra2i (lb, NULBSTR, TRUE, S("Trigram code"), TRILO, TRIHI, &p0);
- if (EOS != t2byte[i]) malf1 ("%s %u: code %d already used", fn, ln, i);
- for (p = p0; ' ' == B(*p); ++p)
- ;
- if (('\'' != B(*p)) || (EOS == B(p[1])) || ('\'' != B(p[2])))
- malf1 ("%s %u: bad letter: %s", fn, ln, p);
- ++p;
- t2byte[i] = B(*p);
- byte2t[B(*p)] = i;
- for (p += 2; EOS != B(*p);)
- {
- for (; ' ' == B(*p); ++p)
- ;
- if (EOS != B(*p))
- {
- if (('\'' == B(*p)) && (EOS != B(p[1])) && ('\'' == B(p[2])))
- {
- ++p;
- byte2t[B(*p)] = i;
- p += 2;
- }
- else
- {
- byte2t[mra2i (p, NULBSTR, TRUE, S("Byte"), 0, 255, &p0)] = i;
- p = p0;
- }
- }
- }
- }
- mfclose (is, fn);
- }
-