diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2014-05-25 13:50:29 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2014-05-25 14:06:26 -0700 |
commit | 33fd917bcd564a5526216a286867a528018f425d (patch) | |
tree | 0b791884036c12075dfbeb841a4276bec34336d5 | |
parent | bd55f70b8740a630fa42d17e4f3345b3601542e2 (diff) |
Convert sources to X.Org standard coding style
Via util/modular/x-indent-all.sh
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | cfgscan.c | 628 | ||||
-rw-r--r-- | evargs.c | 193 | ||||
-rw-r--r-- | printev.c | 498 | ||||
-rw-r--r-- | utils.c | 86 | ||||
-rw-r--r-- | utils.h | 40 | ||||
-rw-r--r-- | xkbevd.c | 839 | ||||
-rw-r--r-- | xkbevd.h | 84 |
7 files changed, 1273 insertions, 1095 deletions
@@ -34,72 +34,137 @@ #include "tokens.h" #include "xkbevd.h" -FILE *yyin = NULL; +FILE *yyin = NULL; static char scanFileBuf[1024]; -char * scanFile= scanFileBuf; -int lineNum= 0; +char *scanFile = scanFileBuf; +int lineNum = 0; -int scanInt; -char *scanIntStr; -int scanIntClass; +int scanInt; +char *scanIntStr; +int scanIntClass; -char *scanStr = NULL; -int scanStrLine= 0; +char *scanStr = NULL; +int scanStrLine = 0; -#define BUFSIZE 512 -static int nInBuf = 0; -static char buf[BUFSIZE]; +#define BUFSIZE 512 +static int nInBuf = 0; +static char buf[BUFSIZE]; #ifdef DEBUG -extern unsigned debugFlags; +extern unsigned debugFlags; static char * tokText(int tok) { -static char buf[32]; + static char buf[32]; switch (tok) { - case END_OF_FILE: snprintf(buf, sizeof(buf), "END_OF_FILE");break; - case ERROR: snprintf(buf, sizeof(buf), "ERROR"); break; - - case BELL: snprintf(buf, sizeof(buf), "BELL"); break; - case ACCESSX: snprintf(buf, sizeof(buf), "ACCESSX"); break; - case MESSAGE: snprintf(buf, sizeof(buf), "MESSAGE"); break; - - case NONE: snprintf(buf, sizeof(buf), "NONE"); break; - case IGNORE: snprintf(buf, sizeof(buf), "IGNORE"); break; - case ECHO: snprintf(buf, sizeof(buf), "ECHO"); break; - case PRINT_EV: snprintf(buf, sizeof(buf), "PRINT_EV"); break; - case SHELL: snprintf(buf, sizeof(buf), "SHELL"); break; - case SOUND: snprintf(buf, sizeof(buf), "SOUND"); break; - - case EQUALS: snprintf(buf, sizeof(buf), "EQUALS"); break; - case PLUS: snprintf(buf, sizeof(buf), "PLUS"); break; - case MINUS: snprintf(buf, sizeof(buf), "MINUS"); break; - case DIVIDE: snprintf(buf, sizeof(buf), "DIVIDE"); break; - case TIMES: snprintf(buf, sizeof(buf), "TIMES"); break; - case OBRACE: snprintf(buf, sizeof(buf), "OBRACE"); break; - case CBRACE: snprintf(buf, sizeof(buf), "CBRACE"); break; - case OPAREN: snprintf(buf, sizeof(buf), "OPAREN"); break; - case CPAREN: snprintf(buf, sizeof(buf), "CPAREN"); break; - case OBRACKET: snprintf(buf, sizeof(buf), "OBRACKET"); break; - case CBRACKET: snprintf(buf, sizeof(buf), "CBRACKET"); break; - case DOT: snprintf(buf, sizeof(buf), "DOT"); break; - case COMMA: snprintf(buf, sizeof(buf), "COMMA"); break; - case SEMI: snprintf(buf, sizeof(buf), "SEMI"); break; - case EXCLAM: snprintf(buf, sizeof(buf), "EXCLAM"); break; - case INVERT: snprintf(buf, sizeof(buf), "INVERT"); break; - - case STRING: snprintf(buf, sizeof(buf), "STRING (%s)",scanStr); break; - case INTEGER: snprintf(buf, sizeof(buf), "INTEGER (0x%x)",scanInt); break; - case FLOAT: snprintf(buf, sizeof(buf), "FLOAT (%d.%d)", - scanInt/XkbGeomPtsPerMM, - scanInt%XkbGeomPtsPerMM); break; - case IDENT: snprintf(buf, sizeof(buf), "IDENT (%s)",scanStr); break; - case KEYNAME: snprintf(buf, sizeof(buf), "KEYNAME (%s)",scanStr); break; - default: snprintf(buf, sizeof(buf), "UNKNOWN"); break; + case END_OF_FILE: + snprintf(buf, sizeof(buf), "END_OF_FILE"); + break; + case ERROR: + snprintf(buf, sizeof(buf), "ERROR"); + break; + + case BELL: + snprintf(buf, sizeof(buf), "BELL"); + break; + case ACCESSX: + snprintf(buf, sizeof(buf), "ACCESSX"); + break; + case MESSAGE: + snprintf(buf, sizeof(buf), "MESSAGE"); + break; + + case NONE: + snprintf(buf, sizeof(buf), "NONE"); + break; + case IGNORE: + snprintf(buf, sizeof(buf), "IGNORE"); + break; + case ECHO: + snprintf(buf, sizeof(buf), "ECHO"); + break; + case PRINT_EV: + snprintf(buf, sizeof(buf), "PRINT_EV"); + break; + case SHELL: + snprintf(buf, sizeof(buf), "SHELL"); + break; + case SOUND: + snprintf(buf, sizeof(buf), "SOUND"); + break; + + case EQUALS: + snprintf(buf, sizeof(buf), "EQUALS"); + break; + case PLUS: + snprintf(buf, sizeof(buf), "PLUS"); + break; + case MINUS: + snprintf(buf, sizeof(buf), "MINUS"); + break; + case DIVIDE: + snprintf(buf, sizeof(buf), "DIVIDE"); + break; + case TIMES: + snprintf(buf, sizeof(buf), "TIMES"); + break; + case OBRACE: + snprintf(buf, sizeof(buf), "OBRACE"); + break; + case CBRACE: + snprintf(buf, sizeof(buf), "CBRACE"); + break; + case OPAREN: + snprintf(buf, sizeof(buf), "OPAREN"); + break; + case CPAREN: + snprintf(buf, sizeof(buf), "CPAREN"); + break; + case OBRACKET: + snprintf(buf, sizeof(buf), "OBRACKET"); + break; + case CBRACKET: + snprintf(buf, sizeof(buf), "CBRACKET"); + break; + case DOT: + snprintf(buf, sizeof(buf), "DOT"); + break; + case COMMA: + snprintf(buf, sizeof(buf), "COMMA"); + break; + case SEMI: + snprintf(buf, sizeof(buf), "SEMI"); + break; + case EXCLAM: + snprintf(buf, sizeof(buf), "EXCLAM"); + break; + case INVERT: + snprintf(buf, sizeof(buf), "INVERT"); + break; + + case STRING: + snprintf(buf, sizeof(buf), "STRING (%s)", scanStr); + break; + case INTEGER: + snprintf(buf, sizeof(buf), "INTEGER (0x%x)", scanInt); + break; + case FLOAT: + snprintf(buf, sizeof(buf), "FLOAT (%d.%d)", + scanInt / XkbGeomPtsPerMM, scanInt % XkbGeomPtsPerMM); + break; + case IDENT: + snprintf(buf, sizeof(buf), "IDENT (%s)", scanStr); + break; + case KEYNAME: + snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanStr); + break; + default: + snprintf(buf, sizeof(buf), "UNKNOWN"); + break; } return buf; } @@ -108,71 +173,80 @@ static char buf[32]; int setScanState(const char *file, int line) { - if (file!=NULL) - strncpy(scanFile,file,1024); - if (line>=0) - lineNum= line; + if (file != NULL) + strncpy(scanFile, file, 1024); + if (line >= 0) + lineNum = line; return 1; } static int yyGetString(void) { -int ch; + int ch; nInBuf = 0; - while ( ((ch=getc(yyin))!=EOF) && (ch!='"') ) { - if ( ch == '\\' ) { - if ((ch = getc(yyin))!=EOF) { - if ( ch=='n' ) ch = '\n'; - else if ( ch == 't' ) ch = '\t'; - else if ( ch == 'v' ) ch = '\v'; - else if ( ch == 'b' ) ch = '\b'; - else if ( ch == 'r' ) ch = '\r'; - else if ( ch == 'f' ) ch = '\f'; - else if ( ch == 'e' ) ch = '\033'; - else if ( ch == '0' ) { - int tmp,stop; - ch = stop = 0; - if (((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) && - (tmp!='8') && (tmp!='9')) { - ch= (ch*8)+(tmp-'0'); - } - else { - stop= 1; - ungetc(tmp,yyin); - } - if ((!stop) && ((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) && - (tmp!='8') && (tmp!='9')) { - ch= (ch*8)+(tmp-'0'); - } - else { - stop= 1; - ungetc(tmp,yyin); - } - if ((!stop) && ((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) && - (tmp!='8') && (tmp!='9')) { - ch= (ch*8)+(tmp-'0'); - } - else { - stop= 1; - ungetc(tmp,yyin); - } - } - } - else return ERROR; - } - - if ( nInBuf < BUFSIZE-1 ) - buf[nInBuf++] = ch; + while (((ch = getc(yyin)) != EOF) && (ch != '"')) { + if (ch == '\\') { + if ((ch = getc(yyin)) != EOF) { + if (ch == 'n') + ch = '\n'; + else if (ch == 't') + ch = '\t'; + else if (ch == 'v') + ch = '\v'; + else if (ch == 'b') + ch = '\b'; + else if (ch == 'r') + ch = '\r'; + else if (ch == 'f') + ch = '\f'; + else if (ch == 'e') + ch = '\033'; + else if (ch == '0') { + int tmp, stop; + + ch = stop = 0; + if (((tmp = getc(yyin)) != EOF) && (isdigit(tmp)) && + (tmp != '8') && (tmp != '9')) { + ch = (ch * 8) + (tmp - '0'); + } + else { + stop = 1; + ungetc(tmp, yyin); + } + if ((!stop) && ((tmp = getc(yyin)) != EOF) && (isdigit(tmp)) + && (tmp != '8') && (tmp != '9')) { + ch = (ch * 8) + (tmp - '0'); + } + else { + stop = 1; + ungetc(tmp, yyin); + } + if ((!stop) && ((tmp = getc(yyin)) != EOF) && (isdigit(tmp)) + && (tmp != '8') && (tmp != '9')) { + ch = (ch * 8) + (tmp - '0'); + } + else { + stop = 1; + ungetc(tmp, yyin); + } + } + } + else + return ERROR; + } + + if (nInBuf < BUFSIZE - 1) + buf[nInBuf++] = ch; } - if ( ch == '"' ) { - buf[nInBuf++] = '\0'; - if ( scanStr ) - free( scanStr ); - scanStr = uStringDup(buf); - scanStrLine = lineNum; - return STRING; + if (ch == '"') { + buf[nInBuf++] = '\0'; + if (scanStr) + free(scanStr); + scanStr = uStringDup(buf); + scanStrLine = lineNum; + return STRING; } return ERROR; } @@ -180,113 +254,124 @@ int ch; static int yyGetKeyName(void) { -int ch; + int ch; nInBuf = 0; - while ( ((ch=getc(yyin))!=EOF) && (ch!='>') ) { - if ( ch == '\\' ) { - if ((ch = getc(yyin))!=EOF) { - if ( ch=='n' ) ch = '\n'; - else if ( ch == 't' ) ch = '\t'; - else if ( ch == 'v' ) ch = '\v'; - else if ( ch == 'b' ) ch = '\b'; - else if ( ch == 'r' ) ch = '\r'; - else if ( ch == 'f' ) ch = '\f'; - else if ( ch == 'e' ) ch = '\033'; - else if ( ch == '0' ) { - int tmp,stop; - ch = stop = 0; - if (((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) && - (tmp!='8') && (tmp!='9')) { - ch= (ch*8)+(tmp-'0'); - } - else { - stop= 1; - ungetc(tmp,yyin); - } - if ((!stop) && ((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) && - (tmp!='8') && (tmp!='9')) { - ch= (ch*8)+(tmp-'0'); - } - else { - stop= 1; - ungetc(tmp,yyin); - } - if ((!stop) && ((tmp=getc(yyin))!=EOF) && (isdigit(tmp)) && - (tmp!='8') && (tmp!='9')) { - ch= (ch*8)+(tmp-'0'); - } - else { - stop= 1; - ungetc(tmp,yyin); - } - } - } - else return ERROR; - } - - if ( nInBuf < BUFSIZE-1 ) - buf[nInBuf++] = ch; + while (((ch = getc(yyin)) != EOF) && (ch != '>')) { + if (ch == '\\') { + if ((ch = getc(yyin)) != EOF) { + if (ch == 'n') + ch = '\n'; + else if (ch == 't') + ch = '\t'; + else if (ch == 'v') + ch = '\v'; + else if (ch == 'b') + ch = '\b'; + else if (ch == 'r') + ch = '\r'; + else if (ch == 'f') + ch = '\f'; + else if (ch == 'e') + ch = '\033'; + else if (ch == '0') { + int tmp, stop; + + ch = stop = 0; + if (((tmp = getc(yyin)) != EOF) && (isdigit(tmp)) && + (tmp != '8') && (tmp != '9')) { + ch = (ch * 8) + (tmp - '0'); + } + else { + stop = 1; + ungetc(tmp, yyin); + } + if ((!stop) && ((tmp = getc(yyin)) != EOF) && (isdigit(tmp)) + && (tmp != '8') && (tmp != '9')) { + ch = (ch * 8) + (tmp - '0'); + } + else { + stop = 1; + ungetc(tmp, yyin); + } + if ((!stop) && ((tmp = getc(yyin)) != EOF) && (isdigit(tmp)) + && (tmp != '8') && (tmp != '9')) { + ch = (ch * 8) + (tmp - '0'); + } + else { + stop = 1; + ungetc(tmp, yyin); + } + } + } + else + return ERROR; + } + + if (nInBuf < BUFSIZE - 1) + buf[nInBuf++] = ch; } - if (( ch == '>' )&&(nInBuf<5)) { - buf[nInBuf++] = '\0'; - if ( scanStr ) - free( scanStr ); - scanStr = uStringDup(buf); - scanStrLine = lineNum; - return KEYNAME; + if ((ch == '>') && (nInBuf < 5)) { + buf[nInBuf++] = '\0'; + if (scanStr) + free(scanStr); + scanStr = uStringDup(buf); + scanStrLine = lineNum; + return KEYNAME; } return ERROR; } static struct _Keyword { - const char *keyword; - int token; + const char *keyword; + int token; } keywords[] = { - { "bell", BELL }, - { "accessx", ACCESSX }, - { "message", MESSAGE }, - { "none", NONE }, - { "ignore", IGNORE }, - { "echo", ECHO }, - { "printevent", PRINT_EV }, - { "shell", SHELL }, - { "sound", SOUND } + { "bell", BELL }, + { "accessx", ACCESSX }, + { "message", MESSAGE }, + { "none", NONE }, + { "ignore", IGNORE }, + { "echo", ECHO }, + { "printevent", PRINT_EV }, + { "shell", SHELL }, + { "sound", SOUND } }; -static int numKeywords = sizeof(keywords)/sizeof(struct _Keyword); +static int numKeywords = sizeof(keywords) / sizeof(struct _Keyword); static int yyGetIdent(int first) { -int ch,i,found; -int rtrn = -1; + int ch, i, found; - buf[0] = first; nInBuf = 1; - while ( ((ch=getc(yyin))!=EOF) && (isalnum(ch)||(ch=='_')) ) { - if ( nInBuf < BUFSIZE - 1 ) - buf[nInBuf++] = ch; + int rtrn = -1; + + buf[0] = first; + nInBuf = 1; + while (((ch = getc(yyin)) != EOF) && (isalnum(ch) || (ch == '_'))) { + if (nInBuf < BUFSIZE - 1) + buf[nInBuf++] = ch; } buf[nInBuf++] = '\0'; - found= 0; + found = 0; - for (i=0;(!found)&&(i<numKeywords);i++) { - if (uStrCaseCmp(buf,keywords[i].keyword)==0) { - rtrn= keywords[i].token; - found= 1; - } + for (i = 0; (!found) && (i < numKeywords); i++) { + if (uStrCaseCmp(buf, keywords[i].keyword) == 0) { + rtrn = keywords[i].token; + found = 1; + } } if (!found) { - if ( scanStr ) - free( scanStr ); - scanStr = uStringDup(buf); - scanStrLine = lineNum; - rtrn = IDENT; + if (scanStr) + free(scanStr); + scanStr = uStringDup(buf); + scanStrLine = lineNum; + rtrn = IDENT; } - if ( (ch!=EOF) && (!isspace(ch)) ) - ungetc( ch, yyin ); - else if ( ch=='\n' ) - lineNum++; + if ((ch != EOF) && (!isspace(ch))) + ungetc(ch, yyin); + else if (ch == '\n') + lineNum++; return rtrn; } @@ -294,89 +379,114 @@ int rtrn = -1; static int yyGetNumber(int ch) { -int isFloat= 0; + int isFloat = 0; - buf[0]= ch; - nInBuf= 1; - while (((ch=getc(yyin))!=EOF)&&(isxdigit(ch)||((nInBuf==1)&&(ch=='x')))) { - buf[nInBuf++]= ch; + buf[0] = ch; + nInBuf = 1; + while (((ch = getc(yyin)) != EOF) && + (isxdigit(ch) || ((nInBuf == 1) && (ch == 'x')))) { + buf[nInBuf++] = ch; } - if (ch=='.') { - isFloat= 1; - buf[nInBuf++]= ch; - while (((ch=getc(yyin))!=EOF)&&(isxdigit(ch))) { - buf[nInBuf++]= ch; - } + if (ch == '.') { + isFloat = 1; + buf[nInBuf++] = ch; + while (((ch = getc(yyin)) != EOF) && (isxdigit(ch))) { + buf[nInBuf++] = ch; + } } - buf[nInBuf++]= '\0'; - if ((ch!=EOF)&&(!isspace(ch))) - ungetc( ch, yyin ); + buf[nInBuf++] = '\0'; + if ((ch != EOF) && (!isspace(ch))) + ungetc(ch, yyin); if (isFloat) { - float tmp; - if (sscanf(buf,"%g",&tmp)==1) { - scanInt= tmp*XkbGeomPtsPerMM; - return FLOAT; - } + float tmp; + + if (sscanf(buf, "%g", &tmp) == 1) { + scanInt = tmp * XkbGeomPtsPerMM; + return FLOAT; + } } - else if ( sscanf(buf,"%i",&scanInt)==1 ) - return INTEGER; - fprintf(stderr,"Malformed number %s\n",buf); + else if (sscanf(buf, "%i", &scanInt) == 1) + return INTEGER; + fprintf(stderr, "Malformed number %s\n", buf); return ERROR; } int yylex(void) { -int ch; -int rtrn; + int ch; + int rtrn; do { - ch = getc(yyin); - if ( ch == '\n' ) { - lineNum++; - } - else if ( ch=='/' ) { /* handle C++ style double-/ comments */ - int newch= getc(yyin); - if (newch=='/') { - do { - ch= getc(yyin); - } while ((ch!='\n')&&(ch!=EOF)); - lineNum++; - } - else if (newch!=EOF) { - ungetc(newch,yyin); - } - } - } while ((ch!=EOF)&&(isspace(ch))); - if ( ch == '=' ) rtrn = EQUALS; - else if ( ch == '+' ) rtrn = PLUS; - else if ( ch == '-' ) rtrn = MINUS; - else if ( ch == '/' ) rtrn = DIVIDE; - else if ( ch == '*' ) rtrn = TIMES; - else if ( ch == '{' ) rtrn = OBRACE; - else if ( ch == '}' ) rtrn = CBRACE; - else if ( ch == '(' ) rtrn = OPAREN; - else if ( ch == ')' ) rtrn = CPAREN; - else if ( ch == '[' ) rtrn = OBRACKET; - else if ( ch == ']' ) rtrn = CBRACKET; - else if ( ch == '.' ) rtrn = DOT; - else if ( ch == ',' ) rtrn = COMMA; - else if ( ch == ';' ) rtrn = SEMI; - else if ( ch == '!' ) rtrn = EXCLAM; - else if ( ch == '~' ) rtrn = INVERT; - else if ( ch == '"' ) rtrn = yyGetString(); - else if ( ch == '<' ) rtrn = yyGetKeyName(); - else if ( isalpha(ch) || (ch=='_')) rtrn = yyGetIdent(ch); - else if ( isdigit(ch) ) rtrn = yyGetNumber(ch); - else if ( ch == EOF ) rtrn = END_OF_FILE; + ch = getc(yyin); + if (ch == '\n') { + lineNum++; + } + else if (ch == '/') { /* handle C++ style double-/ comments */ + int newch = getc(yyin); + + if (newch == '/') { + do { + ch = getc(yyin); + } while ((ch != '\n') && (ch != EOF)); + lineNum++; + } + else if (newch != EOF) { + ungetc(newch, yyin); + } + } + } while ((ch != EOF) && (isspace(ch))); + if (ch == '=') + rtrn = EQUALS; + else if (ch == '+') + rtrn = PLUS; + else if (ch == '-') + rtrn = MINUS; + else if (ch == '/') + rtrn = DIVIDE; + else if (ch == '*') + rtrn = TIMES; + else if (ch == '{') + rtrn = OBRACE; + else if (ch == '}') + rtrn = CBRACE; + else if (ch == '(') + rtrn = OPAREN; + else if (ch == ')') + rtrn = CPAREN; + else if (ch == '[') + rtrn = OBRACKET; + else if (ch == ']') + rtrn = CBRACKET; + else if (ch == '.') + rtrn = DOT; + else if (ch == ',') + rtrn = COMMA; + else if (ch == ';') + rtrn = SEMI; + else if (ch == '!') + rtrn = EXCLAM; + else if (ch == '~') + rtrn = INVERT; + else if (ch == '"') + rtrn = yyGetString(); + else if (ch == '<') + rtrn = yyGetKeyName(); + else if (isalpha(ch) || (ch == '_')) + rtrn = yyGetIdent(ch); + else if (isdigit(ch)) + rtrn = yyGetNumber(ch); + else if (ch == EOF) + rtrn = END_OF_FILE; else { - fprintf(stderr,"Unexpected character %c (%d) in input stream\n",ch,ch); - rtrn = ERROR; + fprintf(stderr, "Unexpected character %c (%d) in input stream\n", + ch, ch); + rtrn = ERROR; } #ifdef DEBUG - if (debugFlags&0x2) - fprintf(stderr,"scan: %s\n",tokText(rtrn)); + if (debugFlags & 0x2) + fprintf(stderr, "scan: %s\n", tokText(rtrn)); #endif return rtrn; } @@ -31,57 +31,59 @@ static char * AppendBellNotifyArg(char *sink, char *arg, XkbEvent *ev) { - if (uStringEqual(arg,"device")||uStringEqual(arg,"D")) - sprintf(sink,"%d",ev->bell.device); - else if (uStringEqual(arg,"volume")||uStringEqual(arg,"v")) - sprintf(sink,"%d",ev->bell.percent); - else if (uStringEqual(arg,"pitch")||uStringEqual(arg,"p")) - sprintf(sink,"%d",ev->bell.pitch); - else if (uStringEqual(arg,"duration")||uStringEqual(arg,"d")) - sprintf(sink,"%d",ev->bell.duration); - else if (uStringEqual(arg,"class")||uStringEqual(arg,"c")) - sprintf(sink,"%d",ev->bell.bell_class); - else if (uStringEqual(arg,"id")||uStringEqual(arg,"i")) - sprintf(sink,"%d",ev->bell.bell_id); - else if (uStringEqual(arg,"window")||uStringEqual(arg,"w")) - sprintf(sink,"0x%x",(unsigned int)ev->bell.window); - else if (uStringEqual(arg,"name")||uStringEqual(arg,"n")) - sprintf(sink,"%s",XkbAtomText(dpy,ev->bell.name,XkbMessage)); + if (uStringEqual(arg, "device") || uStringEqual(arg, "D")) + sprintf(sink, "%d", ev->bell.device); + else if (uStringEqual(arg, "volume") || uStringEqual(arg, "v")) + sprintf(sink, "%d", ev->bell.percent); + else if (uStringEqual(arg, "pitch") || uStringEqual(arg, "p")) + sprintf(sink, "%d", ev->bell.pitch); + else if (uStringEqual(arg, "duration") || uStringEqual(arg, "d")) + sprintf(sink, "%d", ev->bell.duration); + else if (uStringEqual(arg, "class") || uStringEqual(arg, "c")) + sprintf(sink, "%d", ev->bell.bell_class); + else if (uStringEqual(arg, "id") || uStringEqual(arg, "i")) + sprintf(sink, "%d", ev->bell.bell_id); + else if (uStringEqual(arg, "window") || uStringEqual(arg, "w")) + sprintf(sink, "0x%x", (unsigned int) ev->bell.window); + else if (uStringEqual(arg, "name") || uStringEqual(arg, "n")) + sprintf(sink, "%s", XkbAtomText(dpy, ev->bell.name, XkbMessage)); return sink; } static char * AppendAccessXNotifyArg(char *sink, char *arg, XkbEvent *ev) { - if (uStringEqual(arg,"device")||uStringEqual(arg,"D")) - sprintf(sink,"%d",ev->accessx.device); - else if (uStringEqual(arg,"detail")||uStringEqual(arg,"d")) { - sprintf(sink,"%s",XkbAccessXDetailText(ev->accessx.detail,XkbMessage)); + if (uStringEqual(arg, "device") || uStringEqual(arg, "D")) + sprintf(sink, "%d", ev->accessx.device); + else if (uStringEqual(arg, "detail") || uStringEqual(arg, "d")) { + sprintf(sink, "%s", + XkbAccessXDetailText(ev->accessx.detail, XkbMessage)); } - else if (uStringEqual(arg,"keycode")||uStringEqual(arg,"key")|| - uStringEqual(arg,"k")) - sprintf(sink,"%d",ev->accessx.keycode); - else if (uStringEqual(arg,"skdelay")||uStringEqual(arg,"s")) - sprintf(sink,"%d",ev->accessx.sk_delay); - else if (uStringEqual(arg,"bkdelay")||uStringEqual(arg,"b")) - sprintf(sink,"%d",ev->accessx.debounce_delay); + else if (uStringEqual(arg, "keycode") || uStringEqual(arg, "key") || + uStringEqual(arg, "k")) + sprintf(sink, "%d", ev->accessx.keycode); + else if (uStringEqual(arg, "skdelay") || uStringEqual(arg, "s")) + sprintf(sink, "%d", ev->accessx.sk_delay); + else if (uStringEqual(arg, "bkdelay") || uStringEqual(arg, "b")) + sprintf(sink, "%d", ev->accessx.debounce_delay); return sink; } static char * AppendActionMessageArg(char *sink, char *arg, XkbEvent *ev) { - if (uStringEqual(arg,"device")||uStringEqual(arg,"D")) - sprintf(sink,"%d",ev->message.device); - else if (uStringEqual(arg,"message")||uStringEqual(arg,"m")) - sprintf(sink,"%s",ev->message.message); - else if (uStringEqual(arg,"keycode")||uStringEqual(arg,"key")|| - uStringEqual(arg,"k")) - sprintf(sink,"%d",ev->message.keycode); - else if (uStringEqual(arg,"press")||uStringEqual(arg,"p")) - sprintf(sink,"%s",(ev->message.press?"press":"release")); - else if (uStringEqual(arg,"event")||uStringEqual(arg,"e")) - sprintf(sink,"%s",(ev->message.key_event_follows?"event":"no_event")); + if (uStringEqual(arg, "device") || uStringEqual(arg, "D")) + sprintf(sink, "%d", ev->message.device); + else if (uStringEqual(arg, "message") || uStringEqual(arg, "m")) + sprintf(sink, "%s", ev->message.message); + else if (uStringEqual(arg, "keycode") || uStringEqual(arg, "key") || + uStringEqual(arg, "k")) + sprintf(sink, "%d", ev->message.keycode); + else if (uStringEqual(arg, "press") || uStringEqual(arg, "p")) + sprintf(sink, "%s", (ev->message.press ? "press" : "release")); + else if (uStringEqual(arg, "event") || uStringEqual(arg, "e")) + sprintf(sink, "%s", + (ev->message.key_event_follows ? "event" : "no_event")); return sink; } @@ -89,83 +91,82 @@ static char * AppendEventArg(char *sink, char *arg, XkbEvent *ev) { switch (ev->any.xkb_type) { - case XkbBellNotify: - sink= AppendBellNotifyArg(sink,arg,ev); - break; - case XkbAccessXNotify: - sink= AppendAccessXNotifyArg(sink,arg,ev); - break; - case XkbActionMessage: - sink= AppendActionMessageArg(sink,arg,ev); - break; - default: - return sink; + case XkbBellNotify: + sink = AppendBellNotifyArg(sink, arg, ev); + break; + case XkbAccessXNotify: + sink = AppendAccessXNotifyArg(sink, arg, ev); + break; + case XkbActionMessage: + sink = AppendActionMessageArg(sink, arg, ev); + break; + default: + return sink; } - sink+= strlen(sink); + sink += strlen(sink); return sink; } static void CopyEventArg(char **sink_inout, char **source_inout, XkbEvent *ev) { -char buf[1024]; -char *source,*sink; -char *arg; + char buf[1024]; + char *source, *sink; + char *arg; - arg= buf; - source= *source_inout; - sink= *sink_inout; - if (*source=='$') { - *sink++= '$'; - source++; - *sink++= '\0'; - *sink_inout= sink; - *source_inout= source; - return; + arg = buf; + source = *source_inout; + sink = *sink_inout; + if (*source == '$') { + *sink++ = '$'; + source++; + *sink++ = '\0'; + *sink_inout = sink; + *source_inout = source; + return; } - else if (*source=='(') { - source++; - while ((*source!=')')&&(*source!='\0')) { - *arg++= *source++; - } - if (*source=='\0') { - *sink++= '$'; - *sink++= '\0'; - *sink_inout= sink; - return; - } - source++; - *arg++= '\0'; - arg= buf; + else if (*source == '(') { + source++; + while ((*source != ')') && (*source != '\0')) { + *arg++ = *source++; + } + if (*source == '\0') { + *sink++ = '$'; + *sink++ = '\0'; + *sink_inout = sink; + return; + } + source++; + *arg++ = '\0'; + arg = buf; } else { - arg[0]= *source++; - arg[1]= '\0'; + arg[0] = *source++; + arg[1] = '\0'; } - sink= AppendEventArg(sink,arg,ev); - *sink_inout= sink; - *source_inout= source; + sink = AppendEventArg(sink, arg, ev); + *sink_inout = sink; + *source_inout = source; return; } char * SubstituteEventArgs(char *cmd, XkbEvent *ev) { -static char buf[1024]; -char *source,*sink; + static char buf[1024]; + char *source, *sink; - if (index(cmd,'$')==NULL) - return cmd; - buf[0]= '\0'; - sink= buf; - source= cmd; - while (*source!='\0') { - if (*source=='$') { - source++; - CopyEventArg(&sink,&source,ev); - } - *sink++= *source++; + if (index(cmd, '$') == NULL) + return cmd; + buf[0] = '\0'; + sink = buf; + source = cmd; + while (*source != '\0') { + if (*source == '$') { + source++; + CopyEventArg(&sink, &source, ev); + } + *sink++ = *source++; } return buf; } - @@ -35,97 +35,114 @@ static char * eventTypeToString(int evType) { -static char name[20]; + static char name[20]; + switch (evType) { - case KeyPress: strcpy(name,"KeyPress"); break; - case KeyRelease:strcpy(name,"KeyRelease"); break; - default: strcpy(name,"unknown"); break; + case KeyPress: + strcpy(name, "KeyPress"); + break; + case KeyRelease: + strcpy(name, "KeyRelease"); + break; + default: + strcpy(name, "unknown"); + break; } return name; } static void -xkb_prologue (FILE *file, XkbEvent *ev, const char *name) +xkb_prologue(FILE *file, XkbEvent *ev, const char *name) { XkbAnyEvent *e = &ev->any; - fprintf(file,"\n%s event, serial %ld, synthetic %s, device %d, time %ld,\n", - name, e->serial, ynText(e->send_event), e->device,e->time); + fprintf(file, + "\n%s event, serial %ld, synthetic %s, device %d, time %ld,\n", + name, e->serial, ynText(e->send_event), e->device, e->time); return; } static void do_XkbStateNotify(FILE *file, XkbEvent *xkbev) { - XkbStateNotifyEvent *state= &xkbev->state; - - if (state->keycode!=0) - fprintf(file," keycode %d, eventType %s,\n", - state->keycode,eventTypeToString(state->event_type)); - else fprintf(file," request %d/%d,\n",state->req_minor,state->req_minor); - fprintf(file," group= %d%s, base= %d%s, latched= %d%s, locked= %d%s,\n", - state->group, (state->changed&XkbGroupStateMask?"*":""), - state->base_group,(state->changed&XkbGroupBaseMask?"*":""), - state->latched_group,(state->changed&XkbGroupLatchMask?"*":""), - state->locked_group,(state->changed&XkbGroupLockMask?"*":"")); + XkbStateNotifyEvent *state = &xkbev->state; + + if (state->keycode != 0) + fprintf(file, " keycode %d, eventType %s,\n", + state->keycode, eventTypeToString(state->event_type)); + else + fprintf(file, " request %d/%d,\n", state->req_minor, + state->req_minor); + fprintf(file, " group= %d%s, base= %d%s, latched= %d%s, locked= %d%s,\n", + state->group, (state->changed & XkbGroupStateMask ? "*" : ""), + state->base_group, (state->changed & XkbGroupBaseMask ? "*" : ""), + state->latched_group, + (state->changed & XkbGroupLatchMask ? "*" : ""), + state->locked_group, + (state->changed & XkbGroupLockMask ? "*" : "")); fprintf(file, " mods= 0x%02x%s, base= 0x%02x%s, latched= 0x%02x%s, locked= 0x%02x%s\n", - state->mods, (state->changed&XkbModifierStateMask?"*":""), - state->base_mods,(state->changed&XkbModifierBaseMask?"*":""), - state->latched_mods,(state->changed&XkbModifierLatchMask?"*":""), - state->locked_mods,(state->changed&XkbModifierLockMask?"*":"")); - fprintf(file," grab mods= 0x%02x%s, compat grab mods= 0x%02x%s\n", - state->grab_mods, (state->changed&XkbGrabModsMask?"*":""), - state->compat_grab_mods, - (state->changed&XkbCompatGrabModsMask?"*":"")); - fprintf(file," lookup mods= 0x%02x%s, compat lookup mods= 0x%02x%s\n", - state->lookup_mods, (state->changed&XkbLookupModsMask?"*":""), - state->compat_lookup_mods, - (state->changed&XkbCompatLookupModsMask?"*":"")); - fprintf(file," compatState = 0x%02x%s, ", - state->compat_state,(state->changed&XkbCompatStateMask?"*":"")); - fprintf(file,"ptr_buttons= 0x%04x%s\n",state->ptr_buttons, - (state->changed&XkbPointerButtonMask?"*":"")); + state->mods, (state->changed & XkbModifierStateMask ? "*" : ""), + state->base_mods, (state->changed & XkbModifierBaseMask ? "*" : ""), + state->latched_mods, + (state->changed & XkbModifierLatchMask ? "*" : ""), + state->locked_mods, + (state->changed & XkbModifierLockMask ? "*" : "")); + fprintf(file, " grab mods= 0x%02x%s, compat grab mods= 0x%02x%s\n", + state->grab_mods, (state->changed & XkbGrabModsMask ? "*" : ""), + state->compat_grab_mods, + (state->changed & XkbCompatGrabModsMask ? "*" : "")); + fprintf(file, " lookup mods= 0x%02x%s, compat lookup mods= 0x%02x%s\n", + state->lookup_mods, (state->changed & XkbLookupModsMask ? "*" : ""), + state->compat_lookup_mods, + (state->changed & XkbCompatLookupModsMask ? "*" : "")); + fprintf(file, " compatState = 0x%02x%s, ", state->compat_state, + (state->changed & XkbCompatStateMask ? "*" : "")); + fprintf(file, "ptr_buttons= 0x%04x%s\n", state->ptr_buttons, + (state->changed & XkbPointerButtonMask ? "*" : "")); return; } static void do_map_message(const char *what, int first, int num, int eol) { - if (num>1) - printf("%ss %d..%d changed%s",what,first,first+num-1,(eol?"\n":"")); - else printf("%s %d changed%s",what,first,(eol?"\n":"")); + if (num > 1) + printf("%ss %d..%d changed%s", what, first, first + num - 1, + (eol ? "\n" : "")); + else + printf("%s %d changed%s", what, first, (eol ? "\n" : "")); } static void -do_XkbMapNotify(FILE *file,XkbEvent *xkbev) +do_XkbMapNotify(FILE *file, XkbEvent *xkbev) { XkbMapNotifyEvent *map = &xkbev->map; - if (map->changed&XkbKeyTypesMask) { - do_map_message("key type",map->first_type,map->num_types,0); + + if (map->changed & XkbKeyTypesMask) { + do_map_message("key type", map->first_type, map->num_types, 0); } - if (map->changed&XkbKeySymsMask) { - do_map_message("symbols for key",map->first_key_sym,map->num_key_syms, - 1); + if (map->changed & XkbKeySymsMask) { + do_map_message("symbols for key", map->first_key_sym, map->num_key_syms, + 1); } - if (map->changed&XkbKeyActionsMask) { - do_map_message("acts for key",map->first_key_act, - map->num_key_acts,1); + if (map->changed & XkbKeyActionsMask) { + do_map_message("acts for key", map->first_key_act, + map->num_key_acts, 1); } - if (map->changed&XkbKeyBehaviorsMask) { - do_map_message("behavior for key",map->first_key_behavior, - map->num_key_behaviors,1); + if (map->changed & XkbKeyBehaviorsMask) { + do_map_message("behavior for key", map->first_key_behavior, + map->num_key_behaviors, 1); } - if (map->changed&XkbVirtualModsMask) { - fprintf(file," virtual modifiers changed (0x%04x)\n",map->vmods); + if (map->changed & XkbVirtualModsMask) { + fprintf(file, " virtual modifiers changed (0x%04x)\n", map->vmods); } - if (map->changed&XkbExplicitComponentsMask) { - do_map_message("explicit components for key",map->first_key_explicit, - map->num_key_explicit,1); + if (map->changed & XkbExplicitComponentsMask) { + do_map_message("explicit components for key", map->first_key_explicit, + map->num_key_explicit, 1); } - if (map->changed&XkbModifierMapMask) { - do_map_message("modifier map for key",map->first_modmap_key, - map->num_modmap_keys,1); + if (map->changed & XkbModifierMapMask) { + do_map_message("modifier map for key", map->first_modmap_key, + map->num_modmap_keys, 1); } return; } @@ -134,15 +151,18 @@ static void do_XkbControlsNotify(FILE *file, XkbEvent *xkbev) { XkbControlsNotifyEvent *ctrls = &xkbev->ctrls; - fprintf(file," changed= 0x%x, enabled= 0x%x, enabledChanges= 0x%x\n", - ctrls->changed_ctrls,ctrls->enabled_ctrls, - ctrls->enabled_ctrl_changes); - fprintf(file," num_groups= %d\n",ctrls->num_groups); - if (ctrls->keycode!=0) - fprintf(file," keycode %d, eventType %s,", - ctrls->keycode,eventTypeToString(ctrls->event_type)); - else fprintf(file," request %d/%d%s\n",ctrls->req_major,ctrls->req_minor, - (ctrls->req_major!=xkbOpcode?" (NON-XKB)":"")); + + fprintf(file, " changed= 0x%x, enabled= 0x%x, enabledChanges= 0x%x\n", + ctrls->changed_ctrls, ctrls->enabled_ctrls, + ctrls->enabled_ctrl_changes); + fprintf(file, " num_groups= %d\n", ctrls->num_groups); + if (ctrls->keycode != 0) + fprintf(file, " keycode %d, eventType %s,", + ctrls->keycode, eventTypeToString(ctrls->event_type)); + else + fprintf(file, " request %d/%d%s\n", ctrls->req_major, + ctrls->req_minor, + (ctrls->req_major != xkbOpcode ? " (NON-XKB)" : "")); return; } @@ -150,11 +170,13 @@ static void do_XkbIndicatorNotify(FILE *file, XkbEvent *xkbev) { XkbIndicatorNotifyEvent *leds = &xkbev->indicators; - if (leds->xkb_type==XkbIndicatorStateNotify) - fprintf(file," state changes= 0x%08x, new state= 0x%08x\n", - leds->changed,leds->state); - else fprintf(file," map changes= 0x%08x, state= 0x%08x\n", - leds->changed,leds->state); + + if (leds->xkb_type == XkbIndicatorStateNotify) + fprintf(file, " state changes= 0x%08x, new state= 0x%08x\n", + leds->changed, leds->state); + else + fprintf(file, " map changes= 0x%08x, state= 0x%08x\n", + leds->changed, leds->state); return; } @@ -162,18 +184,22 @@ static void do_XkbBellNotify(FILE *file, XkbEvent *xkbev) { XkbBellNotifyEvent *bell = &xkbev->bell; - fprintf(file," bell class= %d, id= %d\n",bell->bell_class,bell->bell_id); - fprintf(file," percent= %d, pitch= %d, duration= %d", - bell->percent,bell->pitch,bell->duration); - if (bell->name!=None) { - char *name = XGetAtomName (dpy, bell->name); - fprintf(file,"\n name= \"%s\"\n",(name?name:"")); - if (name) - XFree(name); + + fprintf(file, " bell class= %d, id= %d\n", bell->bell_class, + bell->bell_id); + fprintf(file, " percent= %d, pitch= %d, duration= %d", bell->percent, + bell->pitch, bell->duration); + if (bell->name != None) { + char *name = XGetAtomName(dpy, bell->name); + + fprintf(file, "\n name= \"%s\"\n", (name ? name : "")); + if (name) + XFree(name); } - else fprintf(file,", no name\n"); - fprintf(file," window= 0x%x, %sevent_only\n",(unsigned int)bell->window, - (bell->event_only?"":"!")); + else + fprintf(file, ", no name\n"); + fprintf(file, " window= 0x%x, %sevent_only\n", + (unsigned int) bell->window, (bell->event_only ? "" : "!")); return; } @@ -182,24 +208,40 @@ do_XkbAccessXNotify(FILE *file, XkbEvent *xkbev) { XkbAccessXNotifyEvent *sk = &xkbev->accessx; const char *detail; + switch (sk->detail) { - case XkbAXN_SKPress: detail= "skpress"; break; - case XkbAXN_SKAccept: detail= "skaccept"; break; - case XkbAXN_SKReject: detail= "skreject"; break; - case XkbAXN_SKRelease: detail= "skrelease"; break; - case XkbAXN_BKAccept: detail= "bkaccept"; break; - case XkbAXN_BKReject: detail= "bkreject"; break; - case XkbAXN_AXKWarning: detail= "warning"; break; - default: { - static char buf[20]; - snprintf(buf, sizeof(buf), "unknown(%d)", sk->detail); - detail= buf; - break; - } + case XkbAXN_SKPress: + detail = "skpress"; + break; + case XkbAXN_SKAccept: + detail = "skaccept"; + break; + case XkbAXN_SKReject: + detail = "skreject"; + break; + case XkbAXN_SKRelease: + detail = "skrelease"; + break; + case XkbAXN_BKAccept: + detail = "bkaccept"; + break; + case XkbAXN_BKReject: + detail = "bkreject"; + break; + case XkbAXN_AXKWarning: + detail = "warning"; + break; + default:{ + static char buf[20]; + + snprintf(buf, sizeof(buf), "unknown(%d)", sk->detail); + detail = buf; + break; + } } fprintf(file, - " keycode= %d,detail= %s,slow keys delay= %d,debounce delay= %d\n", - sk->keycode,detail,sk->sk_delay,sk->debounce_delay); + " keycode= %d,detail= %s,slow keys delay= %d,debounce delay= %d\n", + sk->keycode, detail, sk->sk_delay, sk->debounce_delay); return; } @@ -208,57 +250,58 @@ do_XkbNamesNotify(FILE *file, XkbEvent *xkbev) { XkbNamesNotifyEvent *names = &xkbev->names; - if (names->changed& - (XkbKeycodesNameMask|XkbGeometryNameMask|XkbSymbolsNameMask)) { - int needComma= 0; - fprintf(file," "); - if (names->changed&XkbKeycodesNameMask) { - fprintf(file,"keycodes"); - needComma++; - } - if (names->changed&XkbGeometryNameMask) { - fprintf(file,"%sgeometry",(needComma?", ":"")); - needComma++; - } - if (names->changed&XkbSymbolsNameMask) { - fprintf(file,"%ssymbols",(needComma?", ":"")); - needComma++; - } - if (names->changed&XkbPhysSymbolsNameMask) { - fprintf(file,"%sphysical symbols",(needComma?", ":"")); - needComma++; - } - fprintf(file," name%s changed\n",(needComma>1?"s":"")); + if (names->changed & + (XkbKeycodesNameMask | XkbGeometryNameMask | XkbSymbolsNameMask)) { + int needComma = 0; + + fprintf(file, " "); + if (names->changed & XkbKeycodesNameMask) { + fprintf(file, "keycodes"); + needComma++; + } + if (names->changed & XkbGeometryNameMask) { + fprintf(file, "%sgeometry", (needComma ? ", " : "")); + needComma++; + } + if (names->changed & XkbSymbolsNameMask) { + fprintf(file, "%ssymbols", (needComma ? ", " : "")); + needComma++; + } + if (names->changed & XkbPhysSymbolsNameMask) { + fprintf(file, "%sphysical symbols", (needComma ? ", " : "")); + needComma++; + } + fprintf(file, " name%s changed\n", (needComma > 1 ? "s" : "")); } - if (names->changed&XkbKeyTypeNamesMask) { - do_map_message("key type name",names->first_type,names->num_types,1); + if (names->changed & XkbKeyTypeNamesMask) { + do_map_message("key type name", names->first_type, names->num_types, 1); } - if (names->changed&XkbKTLevelNamesMask) { - do_map_message("level names for key type", - names->first_lvl,names->num_lvls,1); + if (names->changed & XkbKTLevelNamesMask) { + do_map_message("level names for key type", + names->first_lvl, names->num_lvls, 1); } - if (names->changed&XkbIndicatorNamesMask) { - fprintf(file," names of indicators in 0x%08x changed\n", - names->changed_indicators); + if (names->changed & XkbIndicatorNamesMask) { + fprintf(file, " names of indicators in 0x%08x changed\n", + names->changed_indicators); } - if (names->changed&XkbVirtualModNamesMask) { - fprintf(file," names of virtual modifiers in 0x%04x changed\n", - names->changed_vmods); + if (names->changed & XkbVirtualModNamesMask) { + fprintf(file, " names of virtual modifiers in 0x%04x changed\n", + names->changed_vmods); } - if (names->changed&XkbGroupNamesMask) { - fprintf(file," names of groups in 0x%x changed\n", - names->changed_groups); + if (names->changed & XkbGroupNamesMask) { + fprintf(file, " names of groups in 0x%x changed\n", + names->changed_groups); } - if (names->changed&XkbKeyNamesMask) { - do_map_message("names for key",names->first_key,names->num_keys,1); + if (names->changed & XkbKeyNamesMask) { + do_map_message("names for key", names->first_key, names->num_keys, 1); } - if (names->changed&XkbKeyAliasesMask) { - fprintf(file,"key aliases changed (%d aliases total)\n", - names->num_aliases); + if (names->changed & XkbKeyAliasesMask) { + fprintf(file, "key aliases changed (%d aliases total)\n", + names->num_aliases); } - if (names->changed&XkbRGNamesMask) { - fprintf(file,"radio group names changed (%d radio groups total)\n", - names->num_radio_groups); + if (names->changed & XkbRGNamesMask) { + fprintf(file, "radio group names changed (%d radio groups total)\n", + names->num_radio_groups); } return; } @@ -269,118 +312,119 @@ do_XkbCompatMapNotify(FILE *file, XkbEvent *xkbev) XkbCompatMapNotifyEvent *map = &xkbev->compat; if (map->changed_groups) - fprintf(file," compat maps for groups in 0x%02x changed\n", - map->changed_groups); - if (map->num_si>0) { - fprintf(file," symbol interpretations %d..%d (of %d) changed\n", - map->first_si,map->first_si+map->num_si-1, - map->num_total_si); + fprintf(file, " compat maps for groups in 0x%02x changed\n", + map->changed_groups); + if (map->num_si > 0) { + fprintf(file, " symbol interpretations %d..%d (of %d) changed\n", + map->first_si, map->first_si + map->num_si - 1, + map->num_total_si); } - else fprintf(file," keyboard has %d symbol interpretations\n", - map->num_total_si); + else + fprintf(file, " keyboard has %d symbol interpretations\n", + map->num_total_si); return; } static void do_XkbActionMessage(FILE *file, XkbEvent *xkbev) { - XkbActionMessageEvent *msg= &xkbev->message; - fprintf(file," message: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", - msg->message[0],msg->message[1], - msg->message[2],msg->message[3], - msg->message[4],msg->message[5]); - fprintf(file," key %d, event: %s, follows: %s\n",msg->keycode, - (msg->press?"press":"release"), - (msg->key_event_follows?"yes":"no")); + XkbActionMessageEvent *msg = &xkbev->message; + + fprintf(file, " message: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", + msg->message[0], msg->message[1], + msg->message[2], msg->message[3], msg->message[4], msg->message[5]); + fprintf(file, " key %d, event: %s, follows: %s\n", msg->keycode, + (msg->press ? "press" : "release"), + (msg->key_event_follows ? "yes" : "no")); return; } static void do_XkbNewKeyboardNotify(FILE *file, XkbEvent *xkbev) { - XkbNewKeyboardNotifyEvent *nk= &xkbev->new_kbd; - fprintf(file," new device: %d min_keycode: %d, max_keycode %d\n", - nk->device,nk->min_key_code,nk->max_key_code); - fprintf(file," old device: %d min_keycode: %d, max_keycode %d\n", - nk->old_device, - nk->old_min_key_code,nk->old_max_key_code); + XkbNewKeyboardNotifyEvent *nk = &xkbev->new_kbd; + + fprintf(file, " new device: %d min_keycode: %d, max_keycode %d\n", + nk->device, nk->min_key_code, nk->max_key_code); + fprintf(file, " old device: %d min_keycode: %d, max_keycode %d\n", + nk->old_device, nk->old_min_key_code, nk->old_max_key_code); return; } static void do_XkbExtensionDeviceNotify(FILE *file, XkbEvent *xkbev) { - XkbExtensionDeviceNotifyEvent *edn= &xkbev->device; - fprintf(file," device= %d, class= %d, id= %d\n",edn->device, - edn->led_class,edn->led_id); - fprintf(file," reason= 0x%0x\n",edn->reason); - fprintf(file," supported= 0x%0x, unsupported= 0x%0x\n",edn->supported, - edn->unsupported); - fprintf(file," first button= %d, num buttons= %d\n",edn->first_btn, - edn->num_btns); - fprintf(file," leds defined= 0x%08x, led state= 0x%08x\n", - edn->leds_defined,edn->led_state); + XkbExtensionDeviceNotifyEvent *edn = &xkbev->device; + + fprintf(file, " device= %d, class= %d, id= %d\n", edn->device, + edn->led_class, edn->led_id); + fprintf(file, " reason= 0x%0x\n", edn->reason); + fprintf(file, " supported= 0x%0x, unsupported= 0x%0x\n", edn->supported, + edn->unsupported); + fprintf(file, " first button= %d, num buttons= %d\n", edn->first_btn, + edn->num_btns); + fprintf(file, " leds defined= 0x%08x, led state= 0x%08x\n", + edn->leds_defined, edn->led_state); return; } - void PrintXkbEvent(FILE *file, XkbEvent *ev) { - if (ev->type==xkbEventCode) { - switch (ev->any.xkb_type) { - case XkbStateNotify: - xkb_prologue(file, ev, "XkbStateNotify" ); - do_XkbStateNotify(file,ev); - break; - case XkbMapNotify: - xkb_prologue(file, ev, "XkbMapNotify" ); - do_XkbMapNotify(file,ev); - break; - case XkbControlsNotify: - xkb_prologue(file, ev, "XkbControlsNotify" ); - do_XkbControlsNotify(file,ev); - break; - case XkbIndicatorMapNotify: - xkb_prologue(file, ev, "XkbIndicatorMapNotify" ); - do_XkbIndicatorNotify(file,ev); - break; - case XkbIndicatorStateNotify: - xkb_prologue(file, ev, "XkbIndicatorStateNotify" ); - do_XkbIndicatorNotify(file,ev); - break; - case XkbBellNotify: - xkb_prologue(file, ev, "XkbBellNotify" ); - do_XkbBellNotify(file,ev); - break; - case XkbAccessXNotify: - xkb_prologue(file, ev, "XkbAccessXNotify" ); - do_XkbAccessXNotify(file,ev); - break; - case XkbNamesNotify: - xkb_prologue(file, ev, "XkbNamesNotify" ); - do_XkbNamesNotify(file,ev); - break; - case XkbCompatMapNotify: - xkb_prologue(file, ev, "XkbCompatMapNotify" ); - do_XkbCompatMapNotify(file,ev); - break; - case XkbActionMessage: - xkb_prologue(file, ev, "XkbActionMessage" ); - do_XkbActionMessage(file,ev); - break; - case XkbNewKeyboardNotify: - xkb_prologue(file, ev, "XkbNewKeyboard" ); - do_XkbNewKeyboardNotify(file,ev); - break; - case XkbExtensionDeviceNotify: - xkb_prologue(file, ev, "XkbExtensionDeviceNotify" ); - do_XkbExtensionDeviceNotify(file,ev); - break; - default: - xkb_prologue(file, ev, "XKB_UNKNOWN!!!" ); - break; - } + if (ev->type == xkbEventCode) { + switch (ev->any.xkb_type) { + case XkbStateNotify: + xkb_prologue(file, ev, "XkbStateNotify"); + do_XkbStateNotify(file, ev); + break; + case XkbMapNotify: + xkb_prologue(file, ev, "XkbMapNotify"); + do_XkbMapNotify(file, ev); + break; + case XkbControlsNotify: + xkb_prologue(file, ev, "XkbControlsNotify"); + do_XkbControlsNotify(file, ev); + break; + case XkbIndicatorMapNotify: + xkb_prologue(file, ev, "XkbIndicatorMapNotify"); + do_XkbIndicatorNotify(file, ev); + break; + case XkbIndicatorStateNotify: + xkb_prologue(file, ev, "XkbIndicatorStateNotify"); + do_XkbIndicatorNotify(file, ev); + break; + case XkbBellNotify: + xkb_prologue(file, ev, "XkbBellNotify"); + do_XkbBellNotify(file, ev); + break; + case XkbAccessXNotify: + xkb_prologue(file, ev, "XkbAccessXNotify"); + do_XkbAccessXNotify(file, ev); + break; + case XkbNamesNotify: + xkb_prologue(file, ev, "XkbNamesNotify"); + do_XkbNamesNotify(file, ev); + break; + case XkbCompatMapNotify: + xkb_prologue(file, ev, "XkbCompatMapNotify"); + do_XkbCompatMapNotify(file, ev); + break; + case XkbActionMessage: + xkb_prologue(file, ev, "XkbActionMessage"); + do_XkbActionMessage(file, ev); + break; + case XkbNewKeyboardNotify: + xkb_prologue(file, ev, "XkbNewKeyboard"); + do_XkbNewKeyboardNotify(file, ev); + break; + case XkbExtensionDeviceNotify: + xkb_prologue(file, ev, "XkbExtensionDeviceNotify"); + do_XkbExtensionDeviceNotify(file, ev); + break; + default: + xkb_prologue(file, ev, "XKB_UNKNOWN!!!"); + break; + } } return; } @@ -1,10 +1,10 @@ /*\ * - * COPYRIGHT 1990 - * DIGITAL EQUIPMENT CORPORATION - * MAYNARD, MASSACHUSETTS - * ALL RIGHTS RESERVED. + * COPYRIGHT 1990 + * DIGITAL EQUIPMENT CORPORATION + * MAYNARD, MASSACHUSETTS + * ALL RIGHTS RESERVED. * * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. @@ -31,31 +31,33 @@ /***====================================================================***/ -static FILE *errorFile= NULL; +static FILE *errorFile = NULL; Boolean uSetErrorFile(const char *name) { - if ((errorFile!=NULL)&&(errorFile!=stderr)) { - fprintf(errorFile,"switching to %s\n",name?name:"stderr"); - fclose(errorFile); + if ((errorFile != NULL) && (errorFile != stderr)) { + fprintf(errorFile, "switching to %s\n", name ? name : "stderr"); + fclose(errorFile); } - if (name!=NullString) errorFile= fopen(name,"w"); - else errorFile= stderr; - if (errorFile==NULL) { - errorFile= stderr; - return(False); + if (name != NullString) + errorFile = fopen(name, "w"); + else + errorFile = stderr; + if (errorFile == NULL) { + errorFile = stderr; + return (False); } - return(True); + return (True); } void -uInformation(const char *s,...) +uInformation(const char *s, ...) { va_list ap; va_start(ap, s); - vfprintf(errorFile,s,ap); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -64,13 +66,13 @@ uInformation(const char *s,...) /***====================================================================***/ void -uAction(const char *s,...) +uAction(const char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile," "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, " "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -79,13 +81,13 @@ uAction(const char *s,...) /***====================================================================***/ void -uWarning(const char *s,...) +uWarning(const char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Warning: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Warning: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -94,13 +96,13 @@ uWarning(const char *s,...) /***====================================================================***/ void -uError(const char *s,...) +uError(const char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Error: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Error: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -109,13 +111,13 @@ uError(const char *s,...) /***====================================================================***/ void -uInternalError(const char *s,...) +uInternalError(const char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Internal error: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Internal error: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -127,24 +129,26 @@ uInternalError(const char *s,...) int uStrCaseCmp(const char *str1, const char *str2) { - char buf1[512],buf2[512]; + char buf1[512], buf2[512]; + char c, *s; + register int n; - for (n=0, s = buf1; (c = *str1++); n++) { - if (isupper(c)) - c = tolower(c); - if (n>510) - break; - *s++ = c; + for (n = 0, s = buf1; (c = *str1++); n++) { + if (isupper(c)) + c = tolower(c); + if (n > 510) + break; + *s++ = c; } *s = '\0'; - for (n=0, s = buf2; (c = *str2++); n++) { - if (isupper(c)) - c = tolower(c); - if (n>510) - break; - *s++ = c; + for (n = 0, s = buf2; (c = *str2++); n++) { + if (isupper(c)) + c = tolower(c); + if (n > 510) + break; + *s++ = c; } *s = '\0'; return (strcmp(buf1, buf2)); @@ -3,10 +3,10 @@ /*\ * - * COPYRIGHT 1990 - * DIGITAL EQUIPMENT CORPORATION - * MAYNARD, MASSACHUSETTS - * ALL RIGHTS RESERVED. + * COPYRIGHT 1990 + * DIGITAL EQUIPMENT CORPORATION + * MAYNARD, MASSACHUSETTS + * ALL RIGHTS RESERVED. * * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. @@ -42,7 +42,6 @@ _XFUNCPROTOBEGIN - #ifndef NUL #define NUL '\0' #endif @@ -50,24 +49,24 @@ _XFUNCPROTOBEGIN /***====================================================================***/ #ifndef OPAQUE_DEFINED -typedef void *Opaque; +typedef void *Opaque; #endif #ifndef NullOpaque #define NullOpaque ((Opaque)NULL) #endif #ifndef BOOLEAN_DEFINED -typedef char Boolean; +typedef char Boolean; #endif #ifndef True #define True ((Boolean)1) #define False ((Boolean)0) -#endif /* ndef True */ +#endif /* ndef True */ #define booleanText(b) ((b)?"True":"False") #ifndef COMPARISON_DEFINED -typedef int Comparison; +typedef int Comparison; #define Greater ((Comparison)1) #define Equal ((Comparison)0) @@ -76,15 +75,15 @@ typedef int Comparison; #define comparisonText(c) ((c)?((c)<0?"Less":"Greater"):"Equal") #endif - /***====================================================================***/ -extern Boolean uSetErrorFile ( const char *name ); -extern void uInformation ( const char *s, ...) _X_ATTRIBUTE_PRINTF(1,2); -extern void uAction ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2); -extern void uWarning ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2); -extern void uError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2); -extern void uInternalError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2); +extern Boolean uSetErrorFile(const char *name); + +extern void uInformation(const char *s, ...)_X_ATTRIBUTE_PRINTF(1, 2); +extern void uAction(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2); +extern void uWarning(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2); +extern void uError(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2); +extern void uInternalError(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2); /***====================================================================***/ @@ -98,10 +97,7 @@ extern void uInternalError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2); #ifdef HAVE_STRCASECMP #define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2)) #else -extern int uStrCaseCmp( - const char * /* s1 */, - const char * /* s2 */ -); +extern int uStrCaseCmp(const char *s1, const char *s2); #endif #define uStringDup(s1) (strdup(s1)) @@ -109,6 +105,4 @@ extern int uStrCaseCmp( _XFUNCPROTOEND -#endif /* UTILS_H */ - - +#endif /* UTILS_H */ @@ -55,26 +55,24 @@ /***====================================================================***/ -static char * dpyName= NULL; -Display * dpy= NULL; -static const char * cfgFileName= NULL; -int xkbOpcode= 0; -int xkbEventCode= 0; -Bool detectableRepeat= False; +static char * dpyName = NULL; +Display * dpy = NULL; +static const char *cfgFileName = NULL; +int xkbOpcode = 0; +int xkbEventCode = 0; +Bool detectableRepeat = False; -static -CfgEntryPtr config= NULL; -static -unsigned long eventMask= 0; +static CfgEntryPtr config = NULL; +static unsigned long eventMask = 0; -static Bool synch= False; -static int verbose= 0; -static Bool background= False; +static Bool synch = False; +static int verbose = 0; +static Bool background = False; -static const char * soundCmd= NULL; -static const char * soundDir= NULL; +static const char *soundCmd = NULL; +static const char *soundDir = NULL; -XkbDescPtr xkb= NULL; +XkbDescPtr xkb = NULL; /***====================================================================***/ @@ -82,15 +80,16 @@ static void Usage(int argc, char *argv[]) { fprintf(stderr, "Usage: %s [options]...\n%s", argv[0], - "Legal options:\n" - "-?, -help Print this message\n" - "-cfg <file> Specify a config file\n" - "-sc <cmd> Specify the command to play sounds\n" - "-sd <dir> Specify the root directory for sound files\n" - "-d[isplay] <dpy> Specify the display to watch\n" - "-bg Run in background\n" - "-synch Force synchronization\n" - "-v Print verbose messages\n"); + "Legal options:\n" + "-?, -help Print this message\n" + "-cfg <file> Specify a config file\n" + "-sc <cmd> Specify the command to play sounds\n" + "-sd <dir> Specify the root directory for sound files\n" + "-d[isplay] <dpy> Specify the display to watch\n" + "-bg Run in background\n" + "-synch Force synchronization\n" + "-v Print verbose messages\n" + ); return; } @@ -99,111 +98,116 @@ Usage(int argc, char *argv[]) static Bool parseArgs(int argc, char *argv[]) { -register int i; - - for (i=1;i<argc;i++) { - if (strcmp(argv[i],"-bg")==0) { - background= True; - } - else if (strcmp(argv[i],"-cfg")==0) { - if (i>=(argc-1)) { - uError("No configuration file specified on command line\n"); - uAction("Trailing %s argument ignored\n",argv[i]); - } - else { - char *name= argv[++i]; - if (cfgFileName!=NULL) { - if (uStringEqual(cfgFileName,name)) - uWarning("Config file \"%s\" specified twice!\n", - name); - else { - uWarning("Multiple config files on command line\n"); - uAction("Using \"%s\", ignoring \"%s\"\n",name, - cfgFileName); - } - } - cfgFileName= name; - } - } - else if ((strcmp(argv[i],"-d")==0)||(strcmp(argv[i],"-display")==0)) { - if (i>=(argc-1)) { - uError("No display specified on command line\n"); - uAction("Trailing %s argument ignored\n",argv[i]); - } - else { - char *name= argv[++i]; - if (dpyName!=NULL) { - if (uStringEqual(dpyName,name)) - uWarning("Display \"%s\" specified twice!\n", - name); - else { - uWarning("Multiple displays on command line\n"); - uAction("Using \"%s\", ignoring \"%s\"\n",name, - dpyName); - } - } - dpyName= name; - } - } - else if (strcmp(argv[i],"-sc")==0) { - if (i>=(argc-1)) { - uError("No sound command specified on command line\n"); - uAction("Trailing %s argument ignored\n",argv[i]); - } - else { - char *name= argv[++i]; - if (soundCmd!=NULL) { - if (uStringEqual(soundCmd,name)) - uWarning("Sound command \"%s\" specified twice!\n", - name); - else { - uWarning("Multiple sound commands on command line\n"); - uAction("Using \"%s\", ignoring \"%s\"\n",name, - soundCmd); - } - } - soundCmd= name; - } - } - else if (strcmp(argv[i],"-sd")==0) { - if (i>=(argc-1)) { - uError("No sound directory specified on command line\n"); - uAction("Trailing %s argument ignored\n",argv[i]); - } - else { - char *name= argv[++i]; - if (soundDir!=NULL) { - if (uStringEqual(soundDir,name)) - uWarning("Sound directory \"%s\" specified twice!\n", - name); - else { - uWarning("Multiple sound dirs on command line\n"); - uAction("Using \"%s\", ignoring \"%s\"\n",name, - soundDir); - } - } - soundDir= name; - } - } - else if ((strcmp(argv[i],"-synch")==0)||(strcmp(argv[i],"-s")==0)) { - synch= True; - } - else if (strcmp(argv[i],"-v")==0) { - verbose++; - } - else if ((strcmp(argv[i],"-?")==0)||(strcmp(argv[i],"-help")==0)) { - Usage(argc,argv); - exit(0); - } - else { - uError("Unknown flag \"%s\" on command line\n",argv[i]); - Usage(argc,argv); - return False; - } + register int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-bg") == 0) { + background = True; + } + else if (strcmp(argv[i], "-cfg") == 0) { + if (i >= (argc - 1)) { + uError("No configuration file specified on command line\n"); + uAction("Trailing %s argument ignored\n", argv[i]); + } + else { + char *name = argv[++i]; + + if (cfgFileName != NULL) { + if (uStringEqual(cfgFileName, name)) + uWarning("Config file \"%s\" specified twice!\n", name); + else { + uWarning("Multiple config files on command line\n"); + uAction("Using \"%s\", ignoring \"%s\"\n", name, + cfgFileName); + } + } + cfgFileName = name; + } + } + else if ((strcmp(argv[i], "-d") == 0) || + (strcmp(argv[i], "-display") == 0)) { + if (i >= (argc - 1)) { + uError("No display specified on command line\n"); + uAction("Trailing %s argument ignored\n", argv[i]); + } + else { + char *name = argv[++i]; + + if (dpyName != NULL) { + if (uStringEqual(dpyName, name)) + uWarning("Display \"%s\" specified twice!\n", name); + else { + uWarning("Multiple displays on command line\n"); + uAction("Using \"%s\", ignoring \"%s\"\n", name, + dpyName); + } + } + dpyName = name; + } + } + else if (strcmp(argv[i], "-sc") == 0) { + if (i >= (argc - 1)) { + uError("No sound command specified on command line\n"); + uAction("Trailing %s argument ignored\n", argv[i]); + } + else { + char *name = argv[++i]; + + if (soundCmd != NULL) { + if (uStringEqual(soundCmd, name)) + uWarning("Sound command \"%s\" specified twice!\n", + name); + else { + uWarning("Multiple sound commands on command line\n"); + uAction("Using \"%s\", ignoring \"%s\"\n", name, + soundCmd); + } + } + soundCmd = name; + } + } + else if (strcmp(argv[i], "-sd") == 0) { + if (i >= (argc - 1)) { + uError("No sound directory specified on command line\n"); + uAction("Trailing %s argument ignored\n", argv[i]); + } + else { + char *name = argv[++i]; + + if (soundDir != NULL) { + if (uStringEqual(soundDir, name)) + uWarning("Sound directory \"%s\" specified twice!\n", + name); + else { + uWarning("Multiple sound dirs on command line\n"); + uAction("Using \"%s\", ignoring \"%s\"\n", name, + soundDir); + } + } + soundDir = name; + } + } + else if ((strcmp(argv[i], "-synch") == 0) || + (strcmp(argv[i], "-s") == 0)) { + synch = True; + } + else if (strcmp(argv[i], "-v") == 0) { + verbose++; + } + else if ((strcmp(argv[i], "-?") == 0) || + (strcmp(argv[i], "-help") == 0)) { + Usage(argc, argv); + exit(0); + } + else { + uError("Unknown flag \"%s\" on command line\n", argv[i]); + Usage(argc, argv); + return False; + } } if (background == False) { - eventMask = XkbAllEventsMask; - verbose++; + eventMask = XkbAllEventsMask; + verbose++; } return True; @@ -212,40 +216,40 @@ register int i; static Display * GetDisplay(char *program, char *dpyName, int *opcodeRtrn, int *evBaseRtrn) { -int mjr,mnr,error; -Display *dpy; - - mjr= XkbMajorVersion; - mnr= XkbMinorVersion; - dpy= XkbOpenDisplay(dpyName,evBaseRtrn,NULL,&mjr,&mnr,&error); - if (dpy==NULL) { - switch (error) { - case XkbOD_BadLibraryVersion: - uInformation("%s was compiled with XKB version %d.%02d\n", - program,XkbMajorVersion,XkbMinorVersion); - uError("X library supports incompatible version %d.%02d\n", - mjr,mnr); - break; - case XkbOD_ConnectionRefused: - uError("Cannot open display \"%s\"\n",dpyName); - break; - case XkbOD_NonXkbServer: - uError("XKB extension not present on %s\n",dpyName); - break; - case XkbOD_BadServerVersion: - uInformation("%s was compiled with XKB version %d.%02d\n", - program,XkbMajorVersion,XkbMinorVersion); - uError("Server %s uses incompatible version %d.%02d\n", - dpyName,mjr,mnr); - break; - default: - uInternalError("Unknown error %d from XkbOpenDisplay\n",error); - } + int mjr, mnr, error; + Display *dpy; + + mjr = XkbMajorVersion; + mnr = XkbMinorVersion; + dpy = XkbOpenDisplay(dpyName, evBaseRtrn, NULL, &mjr, &mnr, &error); + if (dpy == NULL) { + switch (error) { + case XkbOD_BadLibraryVersion: + uInformation("%s was compiled with XKB version %d.%02d\n", + program, XkbMajorVersion, XkbMinorVersion); + uError("X library supports incompatible version %d.%02d\n", + mjr, mnr); + break; + case XkbOD_ConnectionRefused: + uError("Cannot open display \"%s\"\n", dpyName); + break; + case XkbOD_NonXkbServer: + uError("XKB extension not present on %s\n", dpyName); + break; + case XkbOD_BadServerVersion: + uInformation("%s was compiled with XKB version %d.%02d\n", + program, XkbMajorVersion, XkbMinorVersion); + uError("Server %s uses incompatible version %d.%02d\n", + dpyName, mjr, mnr); + break; + default: + uInternalError("Unknown error %d from XkbOpenDisplay\n", error); + } } else if (synch) - XSynchronize(dpy,True); + XSynchronize(dpy, True); if (opcodeRtrn) - XkbQueryExtension(dpy,opcodeRtrn,evBaseRtrn,NULL,&mjr,&mnr); + XkbQueryExtension(dpy, opcodeRtrn, evBaseRtrn, NULL, &mjr, &mnr); return dpy; } @@ -254,195 +258,210 @@ Display *dpy; void InterpretConfigs(CfgEntryPtr cfg) { -char * name; -unsigned priv= 0; - - config= cfg; - while (cfg!=NULL) { - name= cfg->name.str; - if (cfg->entry_type==VariableDef) { - if (uStrCaseEqual(name,"sounddirectory")|| - uStrCaseEqual(name,"sounddir")) { - if (soundDir==NULL) { - soundDir= cfg->action.text; - cfg->name.str= NULL; - cfg->action.text= NULL; - } - } - else if (uStrCaseEqual(name,"soundcommand")|| - uStrCaseEqual(name,"soundcmd")) { - if (soundCmd==NULL) { - soundCmd= cfg->action.text; - cfg->name.str= NULL; - cfg->action.text= NULL; - } - } - else { - uWarning("Assignment to unknown variable \"%s\"\n", name); - uAction("Ignored\n"); - } - } - else if (cfg->entry_type==EventDef) switch (cfg->event_type) { - case XkbBellNotify: - if (name!=NULL) cfg->name.atom= XInternAtom(dpy,name,False); - else cfg->name.atom= None; - if (name) free(name); - break; - case XkbAccessXNotify: - priv= 0; - if (name==NULL) - priv= XkbAllNewKeyboardEventsMask; - else if (uStrCaseEqual(name,"skpress")) - priv= XkbAXN_SKPressMask; - else if (uStrCaseEqual(name,"skaccept")) - priv= XkbAXN_SKAcceptMask; - else if (uStrCaseEqual(name,"skreject")) - priv= XkbAXN_SKRejectMask; - else if (uStrCaseEqual(name,"skrelease")) - priv= XkbAXN_SKReleaseMask; - else if (uStrCaseEqual(name,"bkaccept")) - priv= XkbAXN_BKAcceptMask; - else if (uStrCaseEqual(name,"bkreject")) - priv= XkbAXN_BKRejectMask; - else if (uStrCaseEqual(name,"warning")) - priv= XkbAXN_AXKWarningMask; - if (name) free(name); - cfg->name.priv= priv; - break; - case XkbActionMessage: - /* nothing to do */ - break; - } - eventMask|= (1L<<cfg->event_type); - cfg= cfg->next; + char *name; + unsigned priv = 0; + + config = cfg; + while (cfg != NULL) { + name = cfg->name.str; + if (cfg->entry_type == VariableDef) { + if (uStrCaseEqual(name, "sounddirectory") || + uStrCaseEqual(name, "sounddir")) { + if (soundDir == NULL) { + soundDir = cfg->action.text; + cfg->name.str = NULL; + cfg->action.text = NULL; + } + } + else if (uStrCaseEqual(name, "soundcommand") || + uStrCaseEqual(name, "soundcmd")) { + if (soundCmd == NULL) { + soundCmd = cfg->action.text; + cfg->name.str = NULL; + cfg->action.text = NULL; + } + } + else { + uWarning("Assignment to unknown variable \"%s\"\n", name); + uAction("Ignored\n"); + } + } + else if (cfg->entry_type == EventDef) + switch (cfg->event_type) { + case XkbBellNotify: + if (name != NULL) + cfg->name.atom = XInternAtom(dpy, name, False); + else + cfg->name.atom = None; + if (name) + free(name); + break; + case XkbAccessXNotify: + priv = 0; + if (name == NULL) + priv = XkbAllNewKeyboardEventsMask; + else if (uStrCaseEqual(name, "skpress")) + priv = XkbAXN_SKPressMask; + else if (uStrCaseEqual(name, "skaccept")) + priv = XkbAXN_SKAcceptMask; + else if (uStrCaseEqual(name, "skreject")) + priv = XkbAXN_SKRejectMask; + else if (uStrCaseEqual(name, "skrelease")) + priv = XkbAXN_SKReleaseMask; + else if (uStrCaseEqual(name, "bkaccept")) + priv = XkbAXN_BKAcceptMask; + else if (uStrCaseEqual(name, "bkreject")) + priv = XkbAXN_BKRejectMask; + else if (uStrCaseEqual(name, "warning")) + priv = XkbAXN_AXKWarningMask; + if (name) + free(name); + cfg->name.priv = priv; + break; + case XkbActionMessage: + /* nothing to do */ + break; + } + eventMask |= (1L << cfg->event_type); + cfg = cfg->next; } - while ((config)&&(config->entry_type!=EventDef)) { - CfgEntryPtr next; - if (config->name.str) free(config->name.str); - if (config->action.text) free(config->action.text); - config->name.str= NULL; - config->action.text= NULL; - next= config->next; - free(config); - config= next; + while ((config) && (config->entry_type != EventDef)) { + CfgEntryPtr next; + + if (config->name.str) + free(config->name.str); + if (config->action.text) + free(config->action.text); + config->name.str = NULL; + config->action.text = NULL; + next = config->next; + free(config); + config = next; } - cfg= config; - while ((cfg!=NULL)&&(cfg->next!=NULL)) { - CfgEntryPtr next; - next= cfg->next; - if (next->entry_type!=EventDef) { - if (next->name.str) free(config->name.str); - if (next->action.text) free(config->action.text); - next->name.str= NULL; - next->action.text= NULL; - cfg->next= next->next; - next->next= NULL; - free(next); - } - else cfg= next; + cfg = config; + while ((cfg != NULL) && (cfg->next != NULL)) { + CfgEntryPtr next; + + next = cfg->next; + if (next->entry_type != EventDef) { + if (next->name.str) + free(config->name.str); + if (next->action.text) + free(config->action.text); + next->name.str = NULL; + next->action.text = NULL; + cfg->next = next->next; + next->next = NULL; + free(next); + } + else + cfg = next; } return; } static CfgEntryPtr -FindMatchingConfig(XkbEvent *ev) +FindMatchingConfig(XkbEvent * ev) { -CfgEntryPtr cfg,dflt; - - dflt= NULL; - for (cfg= config;(cfg!=NULL);cfg=cfg->next) { - if ((ev->type!=xkbEventCode)||(cfg->event_type!=ev->any.xkb_type)) - continue; - switch (ev->any.xkb_type) { - case XkbBellNotify: - if (ev->bell.name==cfg->name.atom) - return cfg; - else if ((cfg->name.atom==None)&&(dflt==NULL)) - dflt= cfg; - break; - case XkbAccessXNotify: - if (cfg->name.priv&(1L<<ev->accessx.detail)) - return cfg; - break; - case XkbActionMessage: - if (cfg->name.str==NULL) - dflt= cfg; - else if (strncmp(cfg->name.str,ev->message.message, - XkbActionMessageLength)==0) - return cfg; - break; - default: - uInternalError("Can't handle type %d XKB events yet, Sorry.\n", - ev->any.xkb_type); - break; - } + CfgEntryPtr cfg, dflt; + + dflt = NULL; + for (cfg = config; (cfg != NULL); cfg = cfg->next) { + if ((ev->type != xkbEventCode) || (cfg->event_type != ev->any.xkb_type)) + continue; + switch (ev->any.xkb_type) { + case XkbBellNotify: + if (ev->bell.name == cfg->name.atom) + return cfg; + else if ((cfg->name.atom == None) && (dflt == NULL)) + dflt = cfg; + break; + case XkbAccessXNotify: + if (cfg->name.priv & (1L << ev->accessx.detail)) + return cfg; + break; + case XkbActionMessage: + if (cfg->name.str == NULL) + dflt = cfg; + else if (strncmp(cfg->name.str, ev->message.message, + XkbActionMessageLength) == 0) + return cfg; + break; + default: + uInternalError("Can't handle type %d XKB events yet, Sorry.\n", + ev->any.xkb_type); + break; + } } return dflt; } static Bool -ProcessMatchingConfig(XkbEvent *ev) +ProcessMatchingConfig(XkbEvent * ev) { -CfgEntryPtr cfg; -char buf[1024],*cmd; -int ok; + CfgEntryPtr cfg; + char buf[1024], *cmd; + int ok; - cfg= FindMatchingConfig(ev); + cfg = FindMatchingConfig(ev); if (!cfg) { - if (verbose) - PrintXkbEvent(stdout,ev); - return False; + if (verbose) + PrintXkbEvent(stdout, ev); + return False; } - if (cfg->action.type==UnknownAction) { - if (cfg->action.text==NULL) - cfg->action.type= NoAction; - else if (cfg->action.text[0]=='!') { - char *tmp; - cfg->action.type= ShellAction; - tmp= uStringDup(&cfg->action.text[1]); - free(cfg->action.text); - cfg->action.text= tmp; - } - else cfg->action.type= SoundAction; + if (cfg->action.type == UnknownAction) { + if (cfg->action.text == NULL) + cfg->action.type = NoAction; + else if (cfg->action.text[0] == '!') { + char *tmp; + + cfg->action.type = ShellAction; + tmp = uStringDup(&cfg->action.text[1]); + free(cfg->action.text); + cfg->action.text = tmp; + } + else + cfg->action.type = SoundAction; } switch (cfg->action.type) { - case NoAction: - return True; - case EchoAction: - if (cfg->action.text!=NULL) { - snprintf(buf,sizeof(buf),"%s",cfg->action.text); - cmd= SubstituteEventArgs(buf,ev); - printf("%s",cmd); - } - return True; - case PrintEvAction: - PrintXkbEvent(stdout,ev); - return True; - case ShellAction: - if (cfg->action.text==NULL) { - uWarning("Empty shell command!\n"); - uAction("Ignored\n"); - return True; - } - cmd= cfg->action.text; - break; - case SoundAction: - if (cfg->action.text==NULL) { - uWarning("Empty sound command!\n"); - uAction("Ignored\n"); - return True; - } - snprintf(buf,sizeof(buf),"%s %s%s",soundCmd,soundDir,cfg->action.text); - cmd= buf; - break; - default: - uInternalError("Unknown error action type %d\n",cfg->action.type); - return False; + case NoAction: + return True; + case EchoAction: + if (cfg->action.text != NULL) { + snprintf(buf, sizeof(buf), "%s", cfg->action.text); + cmd = SubstituteEventArgs(buf, ev); + printf("%s", cmd); + } + return True; + case PrintEvAction: + PrintXkbEvent(stdout, ev); + return True; + case ShellAction: + if (cfg->action.text == NULL) { + uWarning("Empty shell command!\n"); + uAction("Ignored\n"); + return True; + } + cmd = cfg->action.text; + break; + case SoundAction: + if (cfg->action.text == NULL) { + uWarning("Empty sound command!\n"); + uAction("Ignored\n"); + return True; + } + snprintf(buf, sizeof(buf), "%s %s%s", soundCmd, soundDir, + cfg->action.text); + cmd = buf; + break; + default: + uInternalError("Unknown error action type %d\n", cfg->action.type); + return False; } - cmd= SubstituteEventArgs(cmd,ev); + cmd = SubstituteEventArgs(cmd, ev); if (verbose) - uInformation("Executing shell command \"%s\"\n",cmd); - ok= (system(cmd)==0); + uInformation("Executing shell command \"%s\"\n", cmd); + ok = (system(cmd) == 0); return ok; } @@ -451,109 +470,115 @@ int ok; int main(int argc, char *argv[]) { -FILE * file; -static char buf[1024]; -XkbEvent ev; -Bool ok; - + FILE * file; + static char buf[1024]; + XkbEvent ev; + Bool ok; yyin = stdin; uSetErrorFile(NullString); - if (!parseArgs(argc,argv)) - exit(1); - file= NULL; + if (!parseArgs(argc, argv)) + exit(1); + file = NULL; XkbInitAtoms(NULL); - if (cfgFileName==NULL) { - char *home; - home= (char *)getenv("HOME"); - snprintf(buf,sizeof(buf),DFLT_XKBEVD_CONFIG,(home?home:"")); - cfgFileName= buf; + if (cfgFileName == NULL) { + char *home; + + home = (char *) getenv("HOME"); + snprintf(buf, sizeof(buf), DFLT_XKBEVD_CONFIG, (home ? home : "")); + cfgFileName = buf; } - if (uStringEqual(cfgFileName,"-")) { - static const char *in= "stdin"; - file= stdin; - cfgFileName= in; + if (uStringEqual(cfgFileName, "-")) { + static const char *in = "stdin"; + + file = stdin; + cfgFileName = in; } else { - file= fopen(cfgFileName,"r"); - if (file==NULL) { /* no personal config, try for a system one */ - if (cfgFileName!=buf) { /* user specified a file. bail */ - uError("Can't open config file \"%s\n",cfgFileName); - uAction("Exiting\n"); - exit(1); - } - snprintf(buf,sizeof(buf),DFLT_SYS_XKBEVD_CONFIG,DFLT_XKB_CONFIG_ROOT); - file= fopen(cfgFileName,"r"); - if (file==NULL && !eventMask) { - if (verbose) { - uError("Couldn't find a config file anywhere\n"); - uAction("Exiting\n"); - exit(1); - } - exit(0); - } - } + file = fopen(cfgFileName, "r"); + if (file == NULL) { /* no personal config, try for a system one */ + if (cfgFileName != buf) { /* user specified a file. bail */ + uError("Can't open config file \"%s\n", cfgFileName); + uAction("Exiting\n"); + exit(1); + } + snprintf(buf, sizeof(buf), DFLT_SYS_XKBEVD_CONFIG, + DFLT_XKB_CONFIG_ROOT); + file = fopen(cfgFileName, "r"); + if (file == NULL && !eventMask) { + if (verbose) { + uError("Couldn't find a config file anywhere\n"); + uAction("Exiting\n"); + exit(1); + } + exit(0); + } + } } if (background) { - if (fork()!=0) { - if (verbose) - uInformation("Running in the background\n"); - exit(0); - } + if (fork() != 0) { + if (verbose) + uInformation("Running in the background\n"); + exit(0); + } } - dpy= GetDisplay(argv[0],dpyName,&xkbOpcode,&xkbEventCode); + dpy = GetDisplay(argv[0], dpyName, &xkbOpcode, &xkbEventCode); if (!dpy) - goto BAILOUT; - ok= True; - setScanState(cfgFileName,1); + goto BAILOUT; + ok = True; + setScanState(cfgFileName, 1); CFGParseFile(file); if (!config && !eventMask) { - uError("No configuration specified in \"%s\"\n",cfgFileName); - goto BAILOUT; + uError("No configuration specified in \"%s\"\n", cfgFileName); + goto BAILOUT; } - if (eventMask==0) { - uError("No events to watch in \"%s\"\n",cfgFileName); - goto BAILOUT; + if (eventMask == 0) { + uError("No events to watch in \"%s\"\n", cfgFileName); + goto BAILOUT; } - if (!XkbSelectEvents(dpy,XkbUseCoreKbd,eventMask,eventMask)) { - uError("Couldn't select desired XKB events\n"); - goto BAILOUT; + if (!XkbSelectEvents(dpy, XkbUseCoreKbd, eventMask, eventMask)) { + uError("Couldn't select desired XKB events\n"); + goto BAILOUT; } - xkb= XkbGetKeyboard(dpy,XkbGBN_AllComponentsMask,XkbUseCoreKbd); - if (eventMask&XkbBellNotifyMask) { - unsigned ctrls,vals; - if (verbose) - uInformation("Temporarily disabling the audible bell\n"); - if (!XkbChangeEnabledControls(dpy,XkbUseCoreKbd,XkbAudibleBellMask,0)) { - uError("Couldn't disable audible bell\n"); - goto BAILOUT; - } - ctrls= vals= XkbAudibleBellMask; - if (!XkbSetAutoResetControls(dpy,XkbAudibleBellMask,&ctrls,&vals)) { - uWarning("Couldn't configure audible bell to reset on exit\n"); - uAction("Audible bell might remain off\n"); - } + xkb = XkbGetKeyboard(dpy, XkbGBN_AllComponentsMask, XkbUseCoreKbd); + if (eventMask & XkbBellNotifyMask) { + unsigned ctrls, vals; + + if (verbose) + uInformation("Temporarily disabling the audible bell\n"); + if (!XkbChangeEnabledControls + (dpy, XkbUseCoreKbd, XkbAudibleBellMask, 0)) { + uError("Couldn't disable audible bell\n"); + goto BAILOUT; + } + ctrls = vals = XkbAudibleBellMask; + if (!XkbSetAutoResetControls(dpy, XkbAudibleBellMask, &ctrls, &vals)) { + uWarning("Couldn't configure audible bell to reset on exit\n"); + uAction("Audible bell might remain off\n"); + } } - if (soundCmd==NULL) soundCmd= DFLT_SOUND_CMD; - if (soundDir==NULL) soundDir= DFLT_SOUND_DIR; - XkbStdBellEvent(dpy,None,0,XkbBI_ImAlive); + if (soundCmd == NULL) + soundCmd = DFLT_SOUND_CMD; + if (soundDir == NULL) + soundDir = DFLT_SOUND_DIR; + XkbStdBellEvent(dpy, None, 0, XkbBI_ImAlive); while (1) { - XNextEvent(dpy,&ev.core); - if ((!ProcessMatchingConfig(&ev))&&(ev.type==xkbEventCode)&& - (ev.any.xkb_type==XkbBellNotify)) { - XkbForceDeviceBell(dpy,ev.bell.device, - ev.bell.bell_class,ev.bell.bell_id, - ev.bell.percent); - } + XNextEvent(dpy, &ev.core); + if ((!ProcessMatchingConfig(&ev)) && (ev.type == xkbEventCode) && + (ev.any.xkb_type == XkbBellNotify)) { + XkbForceDeviceBell(dpy, ev.bell.device, + ev.bell.bell_class, ev.bell.bell_id, + ev.bell.percent); + } } XCloseDisplay(dpy); - return (ok==0); -BAILOUT: + return (ok == 0); + BAILOUT: uAction("Exiting\n"); - if (dpy!=NULL) - XCloseDisplay(dpy); + if (dpy != NULL) + XCloseDisplay(dpy); exit(1); } @@ -25,7 +25,7 @@ ********************************************************/ #ifndef XKBEVD_H -#define XKBEVD_H 1 +#define XKBEVD_H 1 #include <stdio.h> #include <X11/Xlib.h> @@ -35,62 +35,62 @@ #include "utils.h" -extern FILE * yyin; -extern char * scanFile; -extern int lineNum; -extern int scanInt; -extern char * scanIntStr; -extern int scanIntClass; -extern char * scanStr; -extern int scanStrLine; - -extern Display * dpy; -extern int xkbOpcode; -extern int xkbEventCode; -extern Bool detectableRepeat; - -extern XkbDescPtr xkb; - -#define UnknownAction 0 -#define NoAction 1 -#define EchoAction 2 -#define PrintEvAction 3 -#define ShellAction 4 -#define SoundAction 5 +extern FILE * yyin; +extern char * scanFile; +extern int lineNum; +extern int scanInt; +extern char * scanIntStr; +extern int scanIntClass; +extern char * scanStr; +extern int scanStrLine; + +extern Display * dpy; +extern int xkbOpcode; +extern int xkbEventCode; +extern Bool detectableRepeat; + +extern XkbDescPtr xkb; + +#define UnknownAction 0 +#define NoAction 1 +#define EchoAction 2 +#define PrintEvAction 3 +#define ShellAction 4 +#define SoundAction 5 typedef struct _ActDef { - int type; - char * text; - unsigned priv; + int type; + char * text; + unsigned priv; } ActDefRec,*ActDefPtr; -#define EventDef 0 -#define VariableDef 1 +#define EventDef 0 +#define VariableDef 1 typedef struct _CfgEntry { - unsigned char entry_type; - unsigned char event_type; - union { - char * str; - Atom atom; - unsigned priv; - } name; - ActDefRec action; - struct _CfgEntry * next; + unsigned char entry_type; + unsigned char event_type; + union { + char * str; + Atom atom; + unsigned priv; + } name; + ActDefRec action; + struct _CfgEntry * next; } CfgEntryRec,*CfgEntryPtr; extern void InterpretConfigs( - CfgEntryPtr /* cfgs */ + CfgEntryPtr /* cfgs */ ); extern char *SubstituteEventArgs( - char * /* cmd */, - XkbEvent * /* ev */ + char * /* cmd */, + XkbEvent * /* ev */ ); extern void PrintXkbEvent( - FILE * /* file */, - XkbEvent * /* ev */ + FILE * /* file */, + XkbEvent * /* ev */ ); extern int setScanState ( const char * file, int line ); |