home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / DSHJ2 / HYCOD.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  7.8 KB  |  295 lines

  1. #define        hibit        0x1b
  2. #define        nibit        0x1d
  3. #define        samec        0x1f
  4. #define        ENGLISH        0
  5.  
  6. extern char    SAV_RULE, RULE_LD, hyphens[];
  7. extern unsigned    hyph_index;
  8.  
  9. char *hyprul[]= { "Engrul.rul","Frerul.rul","Itlrul.rul","Sparul.rul",
  10.           "Prtrul.rul","Gerrul.rul","Dutrul.rul","Norrul.rul",
  11.           "Finrul.rul","Swerul.rul","Danrul.rul" };
  12.  
  13. unsigned lang_size[11]= { 531,467,493,389,431,1037,1015,747,369,703,1081 };
  14.  
  15. unsigned char    ttlngth, inlngth, unitbuf[100], cnvrtbuf[100], rulbuf[1100];
  16. unsigned char    *wrdptr, *codptr, *maptr, *clasptr, hyphct, unitofs, *affx;
  17. char        rulnum;
  18. unsigned    *rulptr, fsize;
  19.  
  20. rule_hyph(bgnptr,endptr)
  21. unsigned char *bgnptr, *endptr;
  22. {
  23.     unsigned char c, c1, ct, nohyph, *tmptr, *savptr, *jmptr;
  24.  
  25.     rulnum = hyphct = 0;
  26.     maptr = rulptr = rulbuf;
  27.     clasptr = (maptr + 256);
  28.  
  29.     for (codptr = bgnptr,ct = 0;codptr <= endptr;++codptr,++ct) {
  30.       c = *codptr; cnvrtbuf[ct] = *(maptr + c);    /* convert to numbers*/
  31.     }
  32.     cnvrtbuf[ct] = 0;
  33.     if (*(clasptr + 61)) {                /* check for units   */
  34.       strcpy(unitbuf,cnvrtbuf);
  35.       jmptr = (clasptr + 61);
  36.       maptr = wrdptr = unitbuf;
  37.       ct = 0;
  38.       while (*wrdptr) {           /* look for vowel and consonant units */
  39.         while (*jmptr) {
  40.           tmptr = (jmptr + 1);
  41.           while (*tmptr == *wrdptr) {
  42.             ++tmptr; ++wrdptr;
  43.           }
  44.           if (!(*tmptr)) {
  45.             *maptr++ = *(tmptr + 1);
  46.         while (maptr < wrdptr) {
  47.           *maptr = 0xff; ++maptr;
  48.         }
  49.         --wrdptr; break;
  50.           }
  51.           else {
  52.             wrdptr = maptr;
  53.             tmptr = jmptr;
  54.             jmptr += *tmptr;
  55.           }
  56.         }
  57.         maptr = ++wrdptr;
  58.         jmptr = (clasptr + 61);
  59.       }
  60.     }
  61.     maptr = rulbuf;
  62.     maptr += fsize;                /* get beginning of ptr list */
  63.     rulptr = maptr;
  64.     rulptr -= 9;                    /* get first pointer */
  65.     affx = maptr = wrdptr = cnvrtbuf;
  66.     for (;;) {
  67.       ++rulnum;
  68.       while (!(*rulptr) && rulptr <= (rulbuf + fsize)) {
  69.         ++rulptr; ++rulnum;
  70.       }                        /* find rule offsets */
  71.       if (!(*rulptr)) break;            /* no more rules     */
  72.       if (rulnum == 3 && *(clasptr + 61)) {
  73.         strcpy(cnvrtbuf,unitbuf); maptr = wrdptr = affx;
  74.       }
  75.       else if (rulnum == 2) {
  76.         maptr = wrdptr = affx;    /* point to end of word for suffix   */
  77.         while (*wrdptr) ++wrdptr;
  78.         maptr = --wrdptr;
  79.       }
  80.       codptr = (rulbuf + *rulptr);
  81.       savptr = codptr;
  82.       while (*wrdptr) {
  83.         if (*wrdptr == 0xff) { ++wrdptr; continue; }
  84.         nohyph = 1;
  85.         codptr = savptr;
  86.         while (*codptr) {
  87.           tmptr = codptr;
  88.            ttlngth = *tmptr++;            /* get total length  */
  89.           inlngth = *tmptr++;            /* get input length  */
  90. nxtpass:      if (!(*wrdptr)) {
  91.         if (*tmptr == hibit)
  92.           goto tst_hibit;
  93.         else break;
  94.           }
  95.           if (rulnum == 2 && (wrdptr == cnvrtbuf)) break;
  96.           if (*wrdptr == 0xff) {            /* character in unit */
  97.              ++wrdptr; goto nxtpass;
  98.           }
  99.           if (*tmptr == samec && *wrdptr == *(wrdptr - 1)) {
  100.             if (rulnum == 2) --wrdptr;
  101.         else         ++wrdptr;
  102.             if (++tmptr == (codptr + inlngth)) {
  103. /*printf("\n\nrule number : %d",nohyph);*/
  104.           if (sethyph(tmptr) || rulnum < 3) {
  105.             if (rulnum == 2) {
  106.               maptr = ++wrdptr; *wrdptr = 0;
  107.               unitbuf[(wrdptr - cnvrtbuf)] = 0;
  108.             }
  109.             else  maptr = --wrdptr;
  110.             break;
  111.           }
  112.           goto nodo;
  113.             }
  114.         else goto nxtpass;
  115.           }
  116.           else if (*tmptr & 0x80) {                /* if V, K   */
  117.             c = *tmptr;
  118.             c1 = *(clasptr + *wrdptr);
  119.             if ((c & c1) == c) {
  120.               if (rulnum == 2) --wrdptr;
  121.           else           ++wrdptr;
  122.           if (++tmptr == (codptr + inlngth)) {
  123. /*printf("\n\nrule number : %d",nohyph);*/
  124.             if (sethyph(tmptr) || rulnum < 3) {
  125.               if (rulnum == 2) {
  126.                 maptr = ++wrdptr; *wrdptr = 0;
  127.                 unitbuf[(wrdptr - cnvrtbuf)] = 0;
  128.               }
  129.               else  maptr = --wrdptr;
  130.               break;
  131.             }
  132.             goto nodo;
  133.           }
  134.           else goto nxtpass;
  135.         }
  136.         else goto nodo;
  137.           }
  138.           else if (*tmptr == hibit) {    /* invoke exception test     */
  139. tst_hibit:      c = *(tmptr + 1);
  140.             if (rulnum == 2) ++wrdptr;    /* increment for suffix         */
  141.         else         --wrdptr;
  142.             jmptr = wrdptr;
  143.             while (*jmptr == 0xff) --jmptr;
  144.         if ((c & 0x80))
  145.               c1 = *(clasptr + *jmptr);
  146.             else {
  147.               c1 = *jmptr;
  148.               if (c1 != c)  c = 0x55;        /* force mismatch    */
  149.             }
  150.             if ((c & c1) != c) {
  151.               if (rulnum == 2) --wrdptr;    /* decrement for suffix      */
  152.           else           ++wrdptr;
  153.               if ((tmptr += 2) == (codptr + inlngth)) {
  154. /*printf("\n\nrule number : %d",nohyph);*/
  155.             if (sethyph(tmptr) || rulnum < 3) {
  156.               if (rulnum == 2) {
  157.                 maptr = ++wrdptr; *wrdptr = 0;
  158.                 unitbuf[(wrdptr - cnvrtbuf)] = 0;
  159.               }
  160.               else  maptr = --wrdptr;
  161.               break;
  162.             }
  163.             goto nodo;
  164.           }
  165.               else goto nxtpass;
  166.         }
  167.         else goto nodo;
  168.           }
  169.           else if (*tmptr == nibit) {    /* invoke exception test     */
  170.             c = *(tmptr + 1);
  171.             c1 = *wrdptr;
  172.             if (c1 != c) {
  173.               if (rulnum == 2 && (wrdptr > cnvrtbuf))
  174.                    --wrdptr;        /* decrement for suffix      */
  175.           else ++wrdptr;
  176.               if ((tmptr += 2) == (codptr + inlngth)) {
  177. /*printf("\n\nrule number : %d",nohyph);*/
  178.             if (sethyph(tmptr) || rulnum < 3) {
  179.               if (rulnum == 2) {
  180.                 maptr = ++wrdptr; *wrdptr = 0;
  181.                 unitbuf[(wrdptr - cnvrtbuf)] = 0;
  182.               }
  183.               else  maptr = --wrdptr;
  184.               break;
  185.             }
  186.             goto nodo;
  187.           }
  188.               else goto nxtpass;
  189.         }
  190.         else goto nodo;
  191.           }
  192.           else if (*tmptr == *wrdptr) {
  193.             if (rulnum == 2) --wrdptr;    /* decrement for suffix      */
  194.         else         ++wrdptr;
  195.             if (++tmptr == (codptr + inlngth)) {
  196. /*printf("\n\nrule number : %d",nohyph);*/
  197.           if (sethyph(tmptr) || rulnum < 3) {
  198.             if (rulnum == 2) {
  199.               maptr = ++wrdptr; *wrdptr = 0;
  200.               unitbuf[(wrdptr - cnvrtbuf)] = 0;
  201.             }
  202.             else  maptr = --wrdptr;
  203.             break;
  204.           }
  205.           goto nodo;
  206.             }
  207.         else goto nxtpass;
  208.           }
  209.           else {
  210. nodo:            wrdptr = maptr;
  211.             codptr += ttlngth;
  212.             ++nohyph;
  213.           }
  214.         }                    /* end of while (*codptr)    */
  215.         if (rulnum < 3) break;
  216.         wrdptr = ++maptr;
  217.       }                    /* end of while (*wrdptr)    */
  218.       ++rulptr;
  219.     }                        /* end of for (;;)   */
  220.     if (hyph_index > 1) seqhyph();
  221. }
  222.  
  223. sethyph(tmptr)
  224. unsigned char *tmptr;
  225. {
  226.     unsigned char rc, ct, *savptr;
  227.  
  228.     savptr = wrdptr;
  229.     if (rulnum != 2) { 
  230.       --savptr; affx = wrdptr;
  231.     }
  232.     rc = 0;
  233.     if (*tmptr & 0x10) rc = 1;
  234.     if (*tmptr & 0x80)
  235.       ct = (savptr - cnvrtbuf) - (*tmptr & 0x07);
  236.     else
  237.       ct = (savptr - cnvrtbuf) + *tmptr;
  238.     while (cnvrtbuf[ct + 1] == 0xff) --ct;    /* this is a band aid */
  239.     hyphens[hyphct++] = ct;
  240.     ++hyph_index;
  241.     return(rc);
  242. }
  243.  
  244. llang(rule_number)
  245. unsigned char rule_number;
  246. {
  247.     unsigned char path[100];
  248.     unsigned tab_ID;
  249.  
  250.     RULE_LD = rule_number;
  251.     if (!findfile(hyprul[(RULE_LD-1)],path)) {
  252.       RULE_LD = SAV_RULE; return(1);
  253.     }
  254.     if ((tab_ID = open(path,0)) == -1) {
  255.       RULE_LD = SAV_RULE; return(1);
  256.     }
  257.     if ((read(tab_ID,rulbuf,1100)) == -1) {
  258.       close(tab_ID); SAV_RULE = RULE_LD = 1; return(1);
  259.     }
  260.     fsize = lang_size[RULE_LD-1]; fsize += 1;
  261.     close(tab_ID);
  262.     SAV_RULE = RULE_LD;
  263.     return(0);
  264. }
  265.  
  266. seqhyph()
  267. {
  268.     char tmphyp[120], wrkct, ct, hyct;
  269.  
  270.     for (ct = 0;ct < hyph_index;++ct)
  271.       tmphyp[ct] = hyphens[ct];
  272.     for (ct = 0,hyct = 0;ct < hyph_index && hyct < 64;++hyct) {
  273.       wrkct = 0;
  274.       while (wrkct < hyph_index) {
  275.         if (tmphyp[wrkct] == hyct) {
  276.           hyphens[ct++] = hyct; break;
  277.         }
  278.         ++wrkct;
  279.       }
  280.     }
  281.     hyph_index = ct;
  282. }
  283.  
  284. /*
  285.     Routine to check if character "c" is a hyphenation alphabet.
  286.     True returns 1 else 0.
  287. */
  288. halpha(c)
  289. unsigned char    c;
  290. {
  291.     return(    (c >= 'A' && c <= 'Z')||(c >= 'a' && c <= 'z')||
  292.         (c >= 128 && c <= 154)||(c >= 160 && c <= 167)||
  293.         (c >= 176 && c <= 184)||(c == 158) );
  294. }
  295.