Quelltext /~heha/j/japextra.zip/ROMA2KAN.C

/* Roma zu Kana Konvertierung fr JAP.EXE
 * zu bersetzen mit: Borland C++ 3.1
 */
#include <windows.h>

char pascal lower(char c) {
 if (c>='A' && c<='Z' ||
    (unsigned char)c>=0xC0 && (unsigned char)c<=0xDE) return c+0x20;
 return c;
}

BOOL pascal alpha(char c) {
 if (c>='A' && c<='Z') return TRUE;
 if (c>='a' && c<='z') return TRUE;
 if ((unsigned char)c>=0xC0 && (unsigned char)c<=0xFE) return TRUE;
 return FALSE;
}

#define RK_KEEPSPACE	1
#define RK_HIRAGANA	2
#define RK_KATAKANA	4

BOOL pascal roma2kana(LPCSTR src, LPSTR dst, WORD dstlen, WORD flags) {
 char c,c2;
 unsigned char z,z2,zlast,prev,nigori,choku,i,kanatype;
 prev=choku=zlast=0;
 kanatype=flags&RK_KATAKANA;

 while (*src && dstlen>1) {
  c=*src++;
  c2=lower(c);
  if (c2!=c) {
   c=c2;
   kanatype|=flags&RK_KATAKANA;
  }else{
   if (alpha(c) && flags&RK_HIRAGANA) kanatype=0;
  }
  z2=0;
nochmal:
  i=z=0;
  switch (c) {
   case '': c='a'; z2=0x42; goto nochmal;
   case '': c='i'; z2=0x44; goto nochmal;
   case '': c='u'; z2=0x46; goto nochmal;
   case '': c='e'; z2=0x48; goto nochmal;
   case '': c='o'; z2=0x46; goto nochmal;
   case '': c='a'; z2='-'; goto nochmal;
   case '': c='i'; z2='-'; goto nochmal;
   case '': c='u'; z2='-'; goto nochmal;
   case '': c='e'; z2='-'; goto nochmal;
   case '': c='o'; z2='-'; goto nochmal;
   case 'o': i++;
   case 'e': i++;
   case 'u': i++;
   case 'y':				// aus der I-Zeile
   case 'i': i++;
   case 'a': //a=0, i=1 usw.
   nigori=0;
   switch (prev) {
    case '+': z=0x41+i+i; break;	// kleine Kana
    case 'g': nigori++;
    case 'k': z=0x4B+i+i+nigori; break;
    case 'z': {
     if (c=='i' && zlast==0x61) goto make_d;
     if (c=='u' && zlast==0x64) goto make_d;
     nigori++;
    }
    case 's': z=0x55+i+i+nigori; break;
make_d:
    case 'd': nigori++;
    case 't': z=0x5F+i+i+nigori; if (z>=0x63) z++; break;
					// kleines tsu berspringen
    case 'n': z=0x6A+i; break;
    case 'p': nigori++;
    case 'b': nigori++;
    case 'f':				// nur fr's fu
    case 'h': z=0x6F+i+i+i+nigori; break;
    case 'm': z=0x7E+i; break;
    case 'y': if (c!='i' && c!='e') z=0x84+i-choku; break; // ya, yu, yo
    case 'l':
    case 'r': z=0x89+i; break;
    case 'w': z=0x8F+i; if (i>=2) z--; break;	// wu fehlt
    default: if (c=='y') {
     prev=0;		// groes ya/yu/yo vorbereiten
    }else{
     z=0x42+i+i;	// reine Vokale
    }break;
   }
   choku=0;
   if (c=='y') {
    if (prev) choku=1;	// kleines ya/yu/yo vorbereiten
    prev=c;
   }else prev=0;
   break;

   default:{			//alle Konsonanten
    if (prev=='n' || prev=='m') {
     z=0x93;	// silbisches n
     if (c=='\'') {
      c='\0';	// Fluchtzeichen tten
     }
    }else if (prev==c || prev=='t' && c=='c') {
     z=0x63;	// kleines TSU bei Doppelkonsonant oder (ma)tch(a)=mattya
    }
    if (c=='h') switch (prev) {      
     case 'c': z=0x61; c='y'; choku=1; break;	//ch-->ty
     case 's': z=0x57; c='y'; choku=1; break;	//sh-->sy
    }
    if (prev=='t' && c=='s') c='t';			//ts(u)-->t(u)
    if (c=='j') { z=0x58; c='y'; choku=1; }		//j-->zy	 
    prev=c;
    if (c==' '){
     if (flags&RK_KEEPSPACE) {
      z2=' ';
     }
    }else if (c && c<0x41 && c!='+') {
     z2=c;
    }
   }
  }

  if (z) {
   *dst++=z + (z>=0x41&&kanatype?0x60:0);
   zlast=z;
  };

  if (z2) *dst++=z2 + (z2>=0x41&&kanatype?0x60:0);

 }
 if (prev=='n') {
  *dst++=0x93+(kanatype?0x60:0);	// silbisches n am Ende
 }
 *dst='\0';
 return TRUE;
}

Vorgefundene Kodierung: UTF-80