/* * Put character, possibly a rune, into read queue at interrupt time. * Performs translation for compose sequences * Called at interrupt time to process a character. */ int kbdputc(struct queue *q, int ch) { int n; char buf[3]; Rune r; static Rune kc[15]; static int nk, collecting = 0; r = ch; if (r == Latin) { collecting = 1; nk = 0; return 0; } if (collecting) { int c; nk += runetochar((char *unused_char_p_t)&kc[nk], &r); c = latin1(kc, nk); if (c < -1) /* need more keystrokes */ return 0; collecting = 0; if (c == -1) { /* invalid sequence */ echo(kc[0], (char *unused_char_p_t)kc, nk); qproduce(q, kc, nk); return 0; } r = (Rune) c; }
void gkbdputc(Queue *q, int ch) { int n; Rune r; static uchar kc[5*UTFmax]; static int nk, collecting = 0; char buf[UTFmax]; r = ch; if(r == Latin) { collecting = 1; nk = 0; return; } if(collecting) { int c; nk += runetochar((char*)&kc[nk], &r); c = latin1(kc, nk); if(c < -1) /* need more keystrokes */ return; collecting = 0; if(c == -1) { /* invalid sequence */ qproduce(q, kc, nk); return; } r = (Rune)c; } n = runetochar(buf, &r); if(n == 0) return; /* if(!isdbgkey(r)) */ qproduce(q, buf, n); }
vector <string> jdmRel(string mot1, string mot2){ //mot1.resize(mot1.size()-1); mot1=transformer(&mot1," ","%20"); mot2=transformer(&mot2," ","%20"); //http://www.jeuxdemots.org/intern_lexical_signature.php?affichrel_submit=Afficher&term_1=Pulp%20fiction&term_2=film vector <string> retour; string adresse = "http://www.jeuxdemots.org/intern_lexical_signature.php?affichrel_submit=Afficher&term_1="; adresse+=latin1(mot1); adresse+="&term_2="; adresse+=latin1(mot2); //cout<<"adresse : "<<adresse<<endl; //pause("adresse"); string page = ouvrirPage(adresse); string relTexte = decouperPage(&page,"div","relations"); int it=0; string rel; string score; while(lireMot(&it, &relTexte, "<br>")){ it++; lireMot(&it, &relTexte, " -- "); //mot1; it++; lireMot(&it, &relTexte, "_"); lireMot(&it, &relTexte, &rel , " : "); lireMot(&it, &relTexte, &score , " -->"); if(atoi(score.c_str())>20){ retour.push_back(rel); } //cout<<score<<endl; //cout<<atoi(score.c_str())<<endl; //cout<<rel<<endl; //pause("score"); score.clear(); rel.clear(); //pause("relation"); } return retour; //string = decouperPage(&c,"div","relations",&it); }
/* * Put character, possibly a rune, into read queue at interrupt time. * Performs translation for compose sequences * Called at interrupt time to process a character. */ int kbdputc(Queue *q, int ch) { int n; char buf[3]; Rune r; static Rune kc[15]; static int nk, collecting = 0; r = ch; if(r == Latin) { collecting = 1; nk = 0; return 0; } if(collecting) { int c; nk += runetochar((char*)&kc[nk], &r); c = latin1(kc, nk); if(c < -1) /* need more keystrokes */ return 0; collecting = 0; if(c == -1) { /* invalid sequence */ echo(kc[0], (char*)kc, nk); qproduce(q, kc, nk); return 0; } r = (Rune)c; } kbd.c = r; n = runetochar(buf, &r); if(n == 0) return 0; if(!isdbgkey(r)) { echo(r, buf, n); qproduce(q, buf, n); } return 0; }
string jdmExiste2(string s){ string url="http://www.jeuxdemots.org/autocompletion/autocompletion.php?completionarg=proposition&proposition="; url+=s; url = transformer(&url," ","%20"); string result=ouvrirPage(url); int i=0; string candidat; lireMot(&i, &result, "[\""); string maxs=""; int maxi=10; while(lireMot(&i, &result, &candidat, "\"")){ if((candidat==s || candidat==latin1(s) )&& poidJDM(s)>50){ return s; } else if( maxi<(poidJDM(candidat)/pow(LevenshteinDistance(s, candidat),3)) ){ maxi=poidJDM(candidat)/pow(LevenshteinDistance(s, candidat),3); maxs=s; } candidat.clear(); lireMot(&i, &result, "\""); } return maxs; }
/* * keyboard interrupt */ static void i8042intr(Ureg*, void*) { int s, c, i; static int esc1, esc2; static int alt, caps, ctl, num, shift; static int collecting, nk; static Rune kc[5]; int keyup; /* * get status */ lock(&i8042lock); s = inb(Status); if(!(s&Inready)){ unlock(&i8042lock); return; } /* * get the character */ c = inb(Data); unlock(&i8042lock); /* * if it's the aux port... */ if(s & Minready){ if(auxputc != nil) auxputc(c, shift); return; } /* * e0's is the first of a 2 character sequence */ if(c == 0xe0){ esc1 = 1; return; } else if(c == 0xe1){ esc2 = 2; return; } keyup = c&0x80; c &= 0x7f; if(c > sizeof kbtab){ c |= keyup; if(c != 0xFF) /* these come fairly often: CAPSLOCK U Y */ print("unknown key %ux\n", c); return; } if(esc1){ c = kbtabesc1[c]; esc1 = 0; } else if(esc2){ esc2--; return; } else if(shift) c = kbtabshift[c]; else c = kbtab[c]; if(caps && c<='z' && c>='a') c += 'A' - 'a'; /* * keyup only important for shifts */ if(keyup){ switch(c){ case Latin: alt = 0; break; case Shift: shift = 0; break; case Ctrl: ctl = 0; break; } return; } /* * normal character */ if(!(c & (Spec|KF))){ if(ctl){ if(alt && c == Del) exit(0); c &= 0x1f; } if(!collecting){ kbdputc(kbdq, c); return; } kc[nk++] = c; c = latin1(kc, nk); if(c < -1) /* need more keystrokes */ return; if(c != -1) /* valid sequence */ kbdputc(kbdq, c); else /* dump characters */ for(i=0; i<nk; i++) kbdputc(kbdq, kc[i]); nk = 0; collecting = 0; return; } else { switch(c){ case Caps: caps ^= 1; return; case Num: num ^= 1; return; case Shift: shift = 1; return; case Latin: alt = 1; collecting = 1; nk = 0; return; case Ctrl: ctl = 1; return; } } kbdputc(kbdq, c); }
static void Keyaction(Widget w, XEvent *e, String *p, Cardinal *np) { static unsigned char compose[5]; static int composing = -2; int kind = Kraw; int c, len, minmod; KeySym k, mk; Charfunc f; Modifiers md; char buf[100] = {0}; c = 0; len = 0; /* Translate the keycode into a key symbol. */ if(e->xany.type != KeyPress) return; XkbTranslateKeyCode(xkb, (KeyCode)e->xkey.keycode, e->xkey.state, &md, &k); XkbTranslateKeySym(e->xany.display, &k, e->xkey.state, buf, sizeof(buf) - 1, &len); /* Check to see if it's a specially-handled key first. */ for (Keymapping *m = keymappings; m; m = m->next){ KeySym u = NoSymbol; KeySym l = NoSymbol; XConvertCase(k, &l, &u); /* Note that magic bit manipulation here - we want to check that the * modifiers that are specified for the binding are all pressed, but * we allow other modifiers to be as well. This is because when NumLock * is on, it's always added to the modifier mask. */ if (l == m->s || m->s == XK_VoidSymbol){ if (m->m == 0 || (m->m & ~e->xkey.state) == 0){ switch (m->c){ case Cnone: return; case Cdefault: continue; default: f = ((GwinWidget)w)->gwin.gotchar; if (f) (*f)(m->c, m->k, Tcurrent, 0, 0, m->a); return; } } } } /* * The following song and dance is so we can have our chosen * modifier key behave like a compose key, i.e, press and release * and then type the compose sequence, like Plan 9. We have * to find out which key is the compose key first though. */ if (IsModifierKey(k) && ((GwinWidget)w)->gwin.compose && composing == -2 && modmap) { minmod = (((GwinWidget)w)->gwin.compose+2)*keypermod; for (c = minmod; c < minmod+keypermod; c++) { XtTranslateKeycode(e->xany.display, modmap->modifiermap[c], e->xkey.state, &md, &mk); if (k == mk) { composing = -1; break; } } return; } /* Handle Multi_key separately, since it isn't a modifier */ if(k == XK_Multi_key) { composing = -1; return; } if(k == NoSymbol || k > 0xff00) return; /* Check to see if we are in a composition sequence */ if (!((GwinWidget)w)->gwin.compose && (e->xkey.state & Mod1Mask) && composing == -2) composing = -1; if (composing > -2) { compose[++composing] = k; if ((*compose == 'X') && (composing > 0)) { if ((k < '0') || (k > 'f') || ((k > '9') && (k < 'a'))) { STUFFCOMPOSE(); c = (uint16_t)k; composing = -2; } else if (composing == 4) { c = unicode(compose); if (c == -1) { STUFFCOMPOSE(); c = (uint16_t)compose[4]; } composing = -2; } } else if (composing == 1) { c = (int)latin1(compose); if (c == -1) { STUFFCOMPOSE(); c = (uint16_t)compose[1]; } composing = -2; } } else { if (composing >= 0) { composing++; STUFFCOMPOSE(); } c = keysymtoshort(k); composing = -2; } if (composing >= -1) return; f = ((GwinWidget)w)->gwin.gotchar; if(f) (*f)(c, kind, Tcurrent, 0, 0, NULL); }
/* * The codes at 0x79 and 0x7b are produced by the PFU Happy Hacking keyboard. * A 'standard' keyboard doesn't produce anything above 0x58. */ Rune kbtab[Nscan] = { [0x00] No, 0x1b, '1', '2', '3', '4', '5', '6', [0x08] '7', '8', '9', '0', '-', '=', '\b', '\t', [0x10] 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', [0x18] 'o', 'p', '[', ']', '\n', Ctrl, 'a', 's', [0x20] 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', [0x28] '\'', '`', Shift, '\\', 'z', 'x', 'c', 'v', [0x30] 'b', 'n', 'm', ',', '.', '/', Shift, '*', [0x38] Latin, ' ', Ctrl, KF|1, KF|2, KF|3, KF|4, KF|5, [0x40] KF|6, KF|7, KF|8, KF|9, KF|10, Num, Scroll, '7', [0x48] '8', '9', '-', '4', '5', '6', '+', '1', [0x50] '2', '3', '0', '.', No, No, No, KF|11, [0x58] KF|12, No, No, No, No, No, No, No, [0x60] No, No, No, No, No, No, No, No, [0x68] No, No, No, No, No, No, No, No, [0x70] No, No, No, No, No, No, No, No, [0x78] No, View, No, Up, No, No, No, No, }; Rune kbtabshift[Nscan] = { [0x00] No, 0x1b, '!', '@', '#', '$', '%', '^', [0x08] '&', '*', '(', ')', '_', '+', '\b', '\t', [0x10] 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', [0x18] 'O', 'P', '{', '}', '\n', Ctrl, 'A', 'S', [0x20] 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', [0x28] '"', '~', Shift, '|', 'Z', 'X', 'C', 'V', [0x30] 'B', 'N', 'M', '<', '>', '?', Shift, '*', [0x38] Latin, ' ', Ctrl, KF|1, KF|2, KF|3, KF|4, KF|5, [0x40] KF|6, KF|7, KF|8, KF|9, KF|10, Num, Scroll, '7', [0x48] '8', '9', '-', '4', '5', '6', '+', '1', [0x50] '2', '3', '0', '.', No, No, No, KF|11, [0x58] KF|12, No, No, No, No, No, No, No, [0x60] No, No, No, No, No, No, No, No, [0x68] No, No, No, No, No, No, No, No, [0x70] No, No, No, No, No, No, No, No, [0x78] No, Up, No, Up, No, No, No, No, }; Rune kbtabesc1[Nscan] = { [0x00] No, No, No, No, No, No, No, No, [0x08] No, No, No, No, No, No, No, No, [0x10] No, No, No, No, No, No, No, No, [0x18] No, No, No, No, '\n', Ctrl, No, No, [0x20] No, No, No, No, No, No, No, No, [0x28] No, No, Shift, No, No, No, No, No, [0x30] No, No, No, No, No, '/', No, Print, [0x38] Altgr, No, No, No, No, No, No, No, [0x40] No, No, No, No, No, No, Break, Home, [0x48] Up, Pgup, No, Left, No, Right, No, End, [0x50] Down, Pgdown, Ins, Del, No, No, No, No, [0x58] No, No, No, No, No, No, No, No, [0x60] No, No, No, No, No, No, No, No, [0x68] No, No, No, No, No, No, No, No, [0x70] No, No, No, No, No, No, No, No, [0x78] No, Up, No, No, No, No, No, No, }; Rune kbtabshiftesc1[Nscan] = { [0x00] No, No, No, No, No, No, No, No, [0x08] No, No, No, No, No, No, No, No, [0x10] No, No, No, No, No, No, No, No, [0x18] No, No, No, No, No, No, No, No, [0x20] No, No, No, No, No, No, No, No, [0x28] No, No, No, No, No, No, No, No, [0x30] No, No, No, No, No, No, No, No, [0x38] No, No, No, No, No, No, No, No, [0x40] No, No, No, No, No, No, No, No, [0x48] Up, No, No, No, No, No, No, No, [0x50] No, No, No, No, No, No, No, No, [0x58] No, No, No, No, No, No, No, No, [0x60] No, No, No, No, No, No, No, No, [0x68] No, No, No, No, No, No, No, No, [0x70] No, No, No, No, No, No, No, No, [0x78] No, Up, No, No, No, No, No, No, }; Rune kbtabctrlesc1[Nscan] = { [0x00] No, No, No, No, No, No, No, No, [0x08] No, No, No, No, No, No, No, No, [0x10] No, No, No, No, No, No, No, No, [0x18] No, No, No, No, No, No, No, No, [0x20] No, No, No, No, No, No, No, No, [0x28] No, No, No, No, No, No, No, No, [0x30] No, No, No, No, No, No, No, No, [0x38] No, No, No, No, No, No, No, No, [0x40] No, No, No, No, No, No, No, No, [0x48] Up, No, No, No, No, No, No, No, [0x50] No, No, No, No, No, No, No, No, [0x58] No, No, No, No, No, No, No, No, [0x60] No, No, No, No, No, No, No, No, [0x68] No, No, No, No, No, No, No, No, [0x70] No, No, No, No, No, No, No, No, [0x78] No, Up, No, No, No, No, No, No, }; Rune kbtabaltgr[Nscan] = { [0x00] No, No, No, No, No, No, No, No, [0x08] No, No, No, No, No, No, No, No, [0x10] No, No, No, No, No, No, No, No, [0x18] No, No, No, No, '\n', Ctrl, No, No, [0x20] No, No, No, No, No, No, No, No, [0x28] No, No, Shift, No, No, No, No, No, [0x30] No, No, No, No, No, '/', No, Print, [0x38] Altgr, No, No, No, No, No, No, No, [0x40] No, No, No, No, No, No, Break, Home, [0x48] Up, Pgup, No, Left, No, Right, No, End, [0x50] Down, Pgdown, Ins, Del, No, No, No, No, [0x58] No, No, No, No, No, No, No, No, [0x60] No, No, No, No, No, No, No, No, [0x68] No, No, No, No, No, No, No, No, [0x70] No, No, No, No, No, No, No, No, [0x78] No, Up, No, No, No, No, No, No, }; Rune kbtabctrl[Nscan] = { [0x00] No, '', '', '', '', '', '', '', [0x08] '', '', '', '', ' ', '', '\b', '\t', [0x10] '', '', '', '', '', '', '', '\t', [0x18] '', '', '', '', '\n', Ctrl, '', '', [0x20] '', '', '', '\b', '\n', '', '', '', [0x28] '', No, Shift, '', '', '', '', '', [0x30] '', '', ' ', '', '', '', Shift, '\n', [0x38] Latin, No, Ctrl, '', '', '', '', '', [0x40] '', '', '', ' ', '', '', '', '', [0x48] '', '', ' ', '', '', '', '', '', [0x50] '', '', '', '', No, No, No, '', [0x58] '', No, No, No, No, No, No, No, [0x60] No, No, No, No, No, No, No, No, [0x68] No, No, No, No, No, No, No, No, [0x70] No, No, No, No, No, No, No, No, [0x78] No, '', No, '\b', No, No, No, No, }; int mouseshifted; void (*kbdmouse)(int); static int kdebug; typedef struct Kbscan Kbscan; struct Kbscan { int esc1; int esc2; int alt; int altgr; int caps; int ctl; int num; int shift; int collecting; int nk; Rune kc[5]; int buttons; }; Kbscan kbscans[Nscans]; /* kernel and external scan code state */ /* * Scan code processing */ void kbdputsc(int c, int external) { int i, keyup; Kbscan *kbscan; if(external) kbscan = &kbscans[Ext]; else kbscan = &kbscans[Int]; if(kdebug) print("sc %x ms %d\n", c, mouseshifted); /* * e0's is the first of a 2 character sequence, e1 the first * of a 3 character sequence (on the safari) */ if(c == 0xe0){ kbscan->esc1 = 1; return; } else if(c == 0xe1){ kbscan->esc2 = 2; return; } keyup = c & 0x80; c &= 0x7f; if(c > sizeof kbtab){ c |= keyup; if(c != 0xFF) /* these come fairly often: CAPSLOCK U Y */ print("unknown key %ux\n", c); return; } if(kbscan->esc1 && kbscan->shift){ c = kbtabshiftesc1[c]; kbscan->esc1 = 0; } else if(kbscan->esc1){ c = kbtabesc1[c]; kbscan->esc1 = 0; } else if(kbscan->esc2){ kbscan->esc2--; return; } else if(kbscan->shift) c = kbtabshift[c]; else if(kbscan->altgr) c = kbtabaltgr[c]; else if(kbscan->ctl) c = kbtabctrl[c]; else c = kbtab[c]; if(kbscan->caps && c<='z' && c>='a') c += 'A' - 'a'; /* * keyup only important for shifts */ if(keyup){ switch(c){ case Latin: kbscan->alt = 0; break; case Shift: kbscan->shift = 0; mouseshifted = 0; if(kdebug) print("shiftclr\n"); break; case Ctrl: kbscan->ctl = 0; break; case Altgr: kbscan->altgr = 0; break; case Kmouse|1: case Kmouse|2: case Kmouse|3: case Kmouse|4: case Kmouse|5: kbscan->buttons &= ~(1<<(c-Kmouse-1)); if(kbdmouse) kbdmouse(kbscan->buttons); break; } return; } /* * normal character */ if(!(c & (Spec|KF))){ if(kbscan->ctl) if(kbscan->alt && c == Del) exit(0); if(!kbscan->collecting){ kbdputc(kbdq, c); return; } kbscan->kc[kbscan->nk++] = c; c = latin1(kbscan->kc, kbscan->nk); if(c < -1) /* need more keystrokes */ return; if(c != -1) /* valid sequence */ kbdputc(kbdq, c); else /* dump characters */ for(i=0; i<kbscan->nk; i++) kbdputc(kbdq, kbscan->kc[i]); kbscan->nk = 0; kbscan->collecting = 0; return; } else { switch(c){ case Caps: kbscan->caps ^= 1; return; case Num: kbscan->num ^= 1; return; case Shift: kbscan->shift = 1; if(kdebug) print("shift\n"); mouseshifted = 1; return; case Latin: kbscan->alt = 1; /* * VMware and Qemu use Ctl-Alt as the key combination * to make the VM give up keyboard and mouse focus. * This has the unfortunate side effect that when you * come back into focus, Plan 9 thinks you want to type * a compose sequence (you just typed alt). * * As a clumsy hack around this, we look for ctl-alt and * don't treat it as the start of a compose sequence. */ if(!kbscan->ctl){ kbscan->collecting = 1; kbscan->nk = 0; } return; case Ctrl: kbscan->ctl = 1; return; case Altgr: kbscan->altgr = 1; return; case Kmouse|1: case Kmouse|2: case Kmouse|3: case Kmouse|4: case Kmouse|5: kbscan->buttons |= 1<<(c-Kmouse-1); if(kbdmouse) kbdmouse(kbscan->buttons); return; case KF|11: print("kbd debug on, F12 turns it off\n"); kdebug = 1; break; case KF|12: kdebug = 0; break;
TPtrC8 DeprecatedString::des8() const { TPtrC8 tstr((const TUint8*)latin1(), length()); return tstr; }
vector<relfind> getNeightboors(string mot, vector<string> relToFind){ vector<relfind> retour; string adresse = "http://www.jeuxdemots.org/rezo-xml.php?gotermsubmit=Chercher"; string stub = "&gotermrel="; string finAdresse = "&output=onlyxml"; string word = jdmExiste(mot); //mot orthographié jdm if(word != "") { string page = ouvrirPage(adresse+stub+latin1(word)+finAdresse); string ligne; string rel; string voisin; string poids; int i=0; int j=0; int w = 0; bool entrant = false; bool sortant = false; while(lireMot(&i, &page, &ligne, "<")) { j=0; if(lireMot(&ligne, "entrant>")) entrant = !entrant; if(lireMot(&ligne, "sortant>")) sortant = !sortant; if(lireMot(&j, &ligne, "type=\"")){ lireMot(&j, &ligne, &rel, "\""); lireMot(&j, &ligne, "poids=\""); lireMot(&j, &ligne, &poids, "\""); w = atoi(poids.c_str()); lireMot(&j, &ligne, ">"); lireMot(&j, &ligne, &voisin, "<"); vector<string>::iterator find_it; find_it = find (relToFind.begin(), relToFind.end(), rel); if (find_it != relToFind.end() && w > seuil) { // on ajoute à la structure relfind r; r.w = w; r.rel = rel; r.cible = voisin; r.sens = !entrant; retour.push_back(r); } // on rinit les variables rel = ""; voisin = ""; poids= ""; w = 0; } // fin de la récupération d'une relation ligne = ""; } // fin du parcours des lignes } return retour; }
/* * keyboard interrupt */ static void i8042intr(Ureg*, void*) { int s, c, i; static int esc1, esc2; static int alt, caps, ctl, num, shift; static int collecting, nk; static Rune kc[5]; int keyup; /* * get status */ lock(&i8042lock); s = inb(Status); if(!(s&Inready)){ unlock(&i8042lock); return; } /* * get the character */ c = inb(Data); unlock(&i8042lock); /* * if it's the aux port... */ if(s & Minready){ if(auxputc != nil) auxputc(c, shift); return; } /* * e0's is the first of a 2 character sequence */ if(c == 0xe0){ esc1 = 1; return; } else if(c == 0xe1){ esc2 = 2; return; } keyup = c&0x80; c &= 0x7f; if(c > sizeof kbtab){ c |= keyup; if(c != 0xFF) /* these come fairly often: CAPSLOCK U Y */ print("unknown key %ux\n", c); return; } if(esc1){ c = kbtabesc1[c]; esc1 = 0; } else if(esc2){ esc2--; return; } else if(shift) c = kbtabshift[c]; else c = kbtab[c]; if(caps && c<='z' && c>='a') c += 'A' - 'a'; /* * keyup only important for shifts */ if(keyup){ switch(c){ case Latin: alt = 0; break; case Shift: shift = 0; mouseshifted = 0; break; case Ctrl: ctl = 0; break; } return; } /* * normal character */ if(!(c & (Spec|KF))){ if(ctl){ if(alt && c == Del) exit(0); c &= 0x1f; } if(!collecting){ kbdputc(kbdq, c); return; } kc[nk++] = c; c = latin1(kc, nk); if(c < -1) /* need more keystrokes */ return; if(c != -1) /* valid sequence */ kbdputc(kbdq, c); else /* dump characters */ for(i=0; i<nk; i++) kbdputc(kbdq, kc[i]); nk = 0; collecting = 0; return; } else { switch(c){ case Caps: caps ^= 1; return; case Num: num ^= 1; return; case Shift: shift = 1; mouseshifted = 1; return; case Latin: alt = 1; /* * VMware uses Ctl-Alt as the key combination * to make the VM give up keyboard and mouse focus. * This has the unfortunate side effect that when you * come back into focus, Plan 9 thinks you want to type * a compose sequence (you just typed alt). * * As a clumsy hack around this, we look for ctl-alt * and don't treat it as the start of a compose sequence. */ if(!ctl){ collecting = 1; nk = 0; } return; case Ctrl: collecting = 0; nk = 0; ctl = 1; return; } } kbdputc(kbdq, c); }
static void Keyaction(Widget w, XEvent *e, String *p, Cardinal *np) { static unsigned char compose[5]; static int composing = -2; int composed = 0; int c, minmod; KeySym k, mk; Charfunc f; Modifiers md; /* * I tried using XtGetActionKeysym, but it didn't seem to * do case conversion properly * (at least, with Xterminal servers and R4 intrinsics) */ if(e->xany.type != KeyPress) return; XtTranslateKeycode(e->xany.display, (KeyCode)e->xkey.keycode, e->xkey.state, &md, &k); /* * The following song and dance is so we can have our chosen * modifier key behave like a compose key, i.e, press and release * and then type the compose sequence, like Plan 9. We have * to find out which key is the compose key first 'though. */ if (IsModifierKey(k) && ((GwinWidget)w)->gwin.compose && composing == -2 && modmap) { minmod = (((GwinWidget)w)->gwin.compose+2)*keypermod; for (c = minmod; c < minmod+keypermod; c++) { XtTranslateKeycode(e->xany.display, modmap->modifiermap[c], e->xkey.state, &md, &mk); if (k == mk) { composing = -1; break; } } return; } /* Handle Multi_key separately, since it isn't a modifier */ if(k == XK_Multi_key) { composing = -1; return; } if(k == NoSymbol) return; if(k&0xFF00){ switch(k){ case XK_BackSpace: case XK_Tab: case XK_Escape: case XK_Delete: case XK_KP_0: case XK_KP_1: case XK_KP_2: case XK_KP_3: case XK_KP_4: case XK_KP_5: case XK_KP_6: case XK_KP_7: case XK_KP_8: case XK_KP_9: case XK_KP_Divide: case XK_KP_Multiply: case XK_KP_Subtract: case XK_KP_Add: case XK_KP_Decimal: k &= 0x7F; break; case XK_Linefeed: k = '\r'; break; case XK_KP_Enter: case XK_Return: k = '\n'; break; case XK_Left: case XK_Down: case XK_Right: case XK_Next: k = 0x80; /* VIEW -- "Scroll" */ break; case XK_Up: case XK_Prior: k = 0x81; /* PREVIEW -- "Scroll back" */ break; default: return; /* not ISO-1 or tty control */ } } /* Compensate for servers that call a minus a hyphen */ if(k == XK_hyphen) k = XK_minus; /* Do control mapping ourselves if translator doesn't */ if((e->xkey.state&ControlMask) && !(md&ControlMask)) k &= 0x9f; if(k == NoSymbol) return; /* Check to see if we are in a composition sequence */ if (!((GwinWidget)w)->gwin.compose && (e->xkey.state & Mod1Mask) && composing == -2) composing = -1; if (composing > -2) { compose[++composing] = k; if ((*compose == 'X') && (composing > 0)) { if ((k < '0') || (k > 'f') || ((k > '9') && (k < 'a'))) { STUFFCOMPOSE(); c = (unsigned short)k; composing = -2; } else if (composing == 4) { c = unicode(compose); if (c == -1) { STUFFCOMPOSE(); c = (unsigned short)compose[4]; } else composed = 1; composing = -2; } } else if (composing == 1) { c = (int)latin1(compose); if (c == -1) { STUFFCOMPOSE(); c = (unsigned short)compose[1]; } else composed = 1; composing = -2; } } else { if (composing >= 0) { composing++; STUFFCOMPOSE(); } c = (unsigned short)k; composing = -2; } if (composing >= -1) return; f = ((GwinWidget)w)->gwin.gotchar; if(f) (*f)(c, composed); }