home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / cz / part01 / 78code.h < prev    next >
Encoding:
Text File  |  1989-10-01  |  2.8 KB  |  90 lines

  1. /*
  2.  * 78code.h - definitions for trigram encodings
  3.  *
  4.  * Copyright 1989 Howard Lee Gayle
  5.  *
  6.  * $Header: 78code.h,v 1.2 89/08/25 11:16:02 howard Exp $
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License version 1,
  10.  * as published by the Free Software Foundation.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  * Prerequisites: howard/port.h howard/a2.h 78.h
  22.  */
  23.  
  24. PRIVATE byteT byte2t[256];     /* Map each byte to a trigram code.*/
  25. PRIVATE byteT t2byte[TRINONE]; /* Map trigram code to printable character.*/
  26.  
  27. /* rdcode - read in a trigram encoding file and initialize byte2t and t2byte */
  28.  
  29. PRIVATE void rdcode (fn)
  30. R4 bStrT fn; /* Name of trigram encoding file.*/
  31.  
  32. /* Function:
  33.  *    Initialize byte2t[] and t2byte[] by reading the given encoding file.
  34.  * Algorithm:
  35.  *    Initialize each element of byte2t[] to TRINONE.
  36.  *    Read each line in the encoding file.
  37.  *    Store the primary representation in t2byte[] and byte2t[].
  38.  *    Store any secondary representations in byte2t[].
  39.  * Returns:
  40.  *    
  41.  * Notes:
  42.  *    
  43.  */
  44. {
  45. R2 int      i;         /* Trigram code for current letter.*/
  46. R3 streamT  is;        /* Input stream.*/
  47.    unsigned ln = 0;    /* Line number.*/
  48. R1 bStrT    p;         /* Steps through lb[].*/
  49.    bStrT    p0;        /* mra2i() stores end of number here.*/
  50.    byteT    lb[MLINE]; /* Line buffer.*/
  51.  
  52. is = mfopen (fn, "r");
  53. for (p = byte2t; p != &byte2t[256];)
  54.    *p++ = TRINONE;
  55. t2byte[TRIBEG] = '(';
  56. t2byte[TRIEND] = ')';
  57. while (NULBSTR != getlic (lb, MLINE, is, fn, &ln, 1, COMMENT))
  58.    {
  59.    i = mra2i (lb, NULBSTR, TRUE, S("Trigram code"), TRILO, TRIHI, &p0);
  60.    if (EOS != t2byte[i]) malf1 ("%s %u: code %d already used", fn, ln, i);
  61.    for (p = p0; ' ' == B(*p); ++p)
  62.       ;
  63.    if (('\'' != B(*p)) || (EOS == B(p[1])) || ('\'' != B(p[2])))
  64.       malf1 ("%s %u: bad letter: %s", fn, ln, p);
  65.    ++p;
  66.    t2byte[i] = B(*p);
  67.    byte2t[B(*p)] = i;
  68.    for (p += 2; EOS != B(*p);)
  69.       {
  70.       for (; ' ' == B(*p); ++p)
  71.          ;
  72.       if (EOS != B(*p))
  73.          {
  74.          if (('\'' == B(*p)) && (EOS != B(p[1])) && ('\'' == B(p[2])))
  75.             {
  76.             ++p;
  77.             byte2t[B(*p)] = i;
  78.             p += 2;
  79.             }
  80.          else
  81.             {
  82.             byte2t[mra2i (p, NULBSTR, TRUE, S("Byte"), 0, 255, &p0)] = i;
  83.             p = p0;
  84.             }
  85.          }
  86.       }
  87.    }
  88. mfclose (is, fn);
  89. }
  90.