- int len, doneLen = 0;
- unsigned int ksym, mod;
-
- /* -------> Print each of the slots into buf. */
- for( ; (tabPt->code & 0xffff) != NoSymbol; tabPt++) {
- if ( maxLen <= 0 ) break;
-
- ksym = tabPt->code;
- mod = tabPt->mod & 0xffff;
-
- len = printKeysym( ksym, mod, buf, maxLen );
- if ( len <= 0 ) break;
- buf += len;
- maxLen -= len;
- doneLen += len;
-
- /* -------> Add space when possible. */
- if ( maxLen > 0 ) {
- *buf++ = ' ';
- *buf = '\0';
- maxLen--;
- doneLen++;
- }
- }
- return doneLen;
-}
-
-
-
-// === kb_sequence methods ================================================
-
-
-
-/* ---F+------------------------------------------------------------------ *\
- Function : kb_sequence::addkey
- Called by : [user]
- Purpose : add a key to the sequence, look up in map and return action
- Parameters: key - keysym of key
- mod - modifier mask
- nmod - modifier veto mask (unused now)
- Returns : action or -1 if error (no map defined or key not found)
-\* ---F------------------------------------------------------------------- */
-
-int kb_sequence::addkey(KeySym key, unsigned int mod, unsigned int nmod /*=0*/)
-{
- if(length<0) length=0;
-
- if(length+1 >= size) {
- unsigned int *nseq = new unsigned int[size+KB_PREALLOC];
- size += KB_PREALLOC;
- memcpy(nseq, sequence, length*sizeof(unsigned int));
- if(sequence != staticseq) delete sequence;
- sequence = nseq;
- nseq = new unsigned int[size];
- memcpy(nseq, modifiers, length*sizeof(unsigned int));
- if(modifiers != staticmod) delete modifiers;
- modifiers = nseq;
- }
-
- modifiers[length] = mod + (nmod<<16);
- sequence[length++] = key;
-
- if(curmap)
- return curmap->lookup(key, mod, this);
-
- return -1;
-}
-
-
-/* ---F+------------------------------------------------------------------ *\
- Function : kb_sequence::parse
- Called by : [user]
- Purpose : parse a string that holds a key sequence and add the keys
- Parameters: s - string holding the key sequence
- Returns : 0 - if ok, error pos if error
- Note : Keys must be separated with whitespace;
- Use the keysym names used by XStringToKeysym
- Prefixes are S-, C-, M- for shift, control, meta
-\* ---F------------------------------------------------------------------- */
-
-int kb_sequence::parse(char const*s)
-{
- int i = 0;
- unsigned int mod = 0, nmod = 0;
- KeySym key = 0;
- char tbuf[100];
-
- if(!s[0]) return 1;
-
- while(s[i]) {
- if(s[i] && (s[i]) <= ' ') i++;
- if(!s[i]) break;
-
- if(s[i+1]=='-') { // is implicit that s[i]==true
- switch(s[i]) {
- case 's': case 'S':
- mod |= ShiftMask;
- i+=2;
- continue;
- case 'c': case 'C':
- mod |= ControlMask;
- i+=2;
- continue;
- case 'm': case 'M':
- mod |= Mod1Mask;
- i+=2;
- continue;
- default:
- return i+1;
- }
- } else if(s[i]=='~' && s[i+1] && s[i+2]=='-') {
- switch(s[i+1]) {
- case 's': case 'S':
- nmod |= ShiftMask;
- i+=3;
- continue;
- case 'c': case 'C':
- nmod |= ControlMask;
- i+=3;
- continue;
- case 'm': case 'M':
- nmod |= Mod1Mask;
- i+=3;
- continue;
- default:
- return i+2;
- }
- } else {
- int j = 0;
- for(j = i; s[j] && (s[j])>' '; j++)
- tbuf[j-i] = s[j]; // (!!!check bounds :-)
-
- tbuf[j-i] = '\0';
-
- key = XStringToKeysym(tbuf);
- if(key == NoSymbol) {
- lyxerr[Debug::KBMAP]
- << "kbmap.C: No such keysym: "
- << tbuf << endl;
- return j;
- }
- i = j;
-
- addkey(key, mod, nmod);
- mod = 0;
- nmod = 0;
- }
- }
- return 0;