diff options
Diffstat (limited to 'lib/libXt/src/TMparse.c')
-rw-r--r-- | lib/libXt/src/TMparse.c | 241 |
1 files changed, 126 insertions, 115 deletions
diff --git a/lib/libXt/src/TMparse.c b/lib/libXt/src/TMparse.c index df94181b4..9582b0cdc 100644 --- a/lib/libXt/src/TMparse.c +++ b/lib/libXt/src/TMparse.c @@ -99,10 +99,12 @@ in this Software without prior written authorization from The Open Group. #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -static String XtNtranslationParseError = "translationParseError"; +static _Xconst char *XtNtranslationParseError = "translationParseError"; typedef int EventType; +#define PARSE_PROC_DECL String, Opaque, EventPtr, Boolean* + typedef String (*ParseProc)( String /* str; */, Opaque /* closure; */, @@ -228,13 +230,13 @@ static NameValueRec mappingNotify[] = { {NULL, NULLQUARK, 0}, }; -static String ParseKeySym(String, Opaque, EventPtr, Boolean*); -static String ParseKeyAndModifiers(String, Opaque, EventPtr, Boolean*); -static String ParseTable(String, Opaque, EventPtr, Boolean*); -static String ParseImmed(String, Opaque, EventPtr, Boolean*); -static String ParseAddModifier(String, Opaque, EventPtr, Boolean*); -static String ParseNone(String, Opaque, EventPtr, Boolean*); -static String ParseAtom(String, Opaque, EventPtr, Boolean*); +static String ParseKeySym(PARSE_PROC_DECL); +static String ParseKeyAndModifiers(PARSE_PROC_DECL); +static String ParseTable(PARSE_PROC_DECL); +static String ParseImmed(PARSE_PROC_DECL); +static String ParseAddModifier(PARSE_PROC_DECL); +static String ParseNone(PARSE_PROC_DECL); +static String ParseAtom(PARSE_PROC_DECL); static EventKey events[] = { @@ -445,7 +447,7 @@ static void Compile_XtEventTable( register int i; register EventKeys entry = table; - for (i=count; --i >= 0; entry++) + for (i= (int)count; --i >= 0; entry++) entry->signature = XrmPermStringToQuark(entry->event); qsort(table, count, sizeof(EventKey), OrderEvents); } @@ -463,7 +465,7 @@ static void Compile_XtModifierTable( register int i; register ModifierKeys entry = table; - for (i=count; --i >= 0; entry++) + for (i= (int)count; --i >= 0; entry++) entry->signature = XrmPermStringToQuark(entry->name); qsort(table, count, sizeof(ModifierRec), OrderModifiers); } @@ -479,13 +481,13 @@ static String PanicModeRecovery( static void Syntax( - String str0,String str1) + _Xconst char *str0, _Xconst char *str1) { Cardinal num_params = 2; String params[2]; - params[0] = str0; - params[1] = str1; + params[0] = (String) str0; + params[1] = (String) str1; XtWarningMsg(XtNtranslationParseError,"parseError",XtCXtToolkitError, "translation table syntax error: %s %s",params,&num_params); } @@ -535,9 +537,12 @@ static void StoreLateBindings( LateBindingsPtr* lateBindings) { LateBindingsPtr temp; - Boolean pair = FALSE; - unsigned long count,number; + if (lateBindings != NULL){ + Boolean pair = FALSE; + unsigned long count; + unsigned long number; + temp = *lateBindings; if (temp != NULL) { for (count = 0; temp[count].keysym; count++){/*EMPTY*/} @@ -552,13 +557,13 @@ static void StoreLateBindings( temp = (LateBindingsPtr)XtRealloc((char *)temp, (unsigned)((count+number+1) * sizeof(LateBindings)) ); *lateBindings = temp; - temp[count].knot = notL; - temp[count].pair = pair; + XtSetBit(temp[count].knot, notL); + XtSetBit(temp[count].pair, pair); if (count == 0) temp[count].ref_count = 1; temp[count++].keysym = keysymL; if (keysymR){ - temp[count].knot = notR; + XtSetBit(temp[count].knot, notR); temp[count].pair = FALSE; temp[count].ref_count = 0; temp[count++].keysym = keysymR; @@ -591,7 +596,7 @@ static Boolean _XtLookupModifier( Value *valueP, Bool constMask) { - register int i, left, right; + int left, right; static int previous = 0; LOCK_PROCESS; @@ -607,7 +612,7 @@ static Boolean _XtLookupModifier( left = 0; right = XtNumber(modifiers) - 1; while (left <= right) { - i = (left + right) >> 1; + int i = (left + right) >> 1; if (signature < modifiers[i].signature) right = i - 1; else if (signature > modifiers[i].signature) @@ -651,25 +656,22 @@ static String FetchModifierToken( if (*str == '$') { *token_return = QMeta; str++; - return str; - } - if (*str == '^') { + } else if (*str == '^') { *token_return = QCtrl; str++; - return str; - } - str = ScanIdent(str); - if (start != str) { - char modStrbuf[100]; - char* modStr; - - modStr = XtStackAlloc ((size_t)(str - start + 1), modStrbuf); - if (modStr == NULL) _XtAllocError (NULL); - (void) memmove(modStr, start, str-start); - modStr[str-start] = '\0'; - *token_return = XrmStringToQuark(modStr); - XtStackFree (modStr, modStrbuf); - return str; + } else { + str = ScanIdent(str); + if (start != str) { + char modStrbuf[100]; + char* modStr; + + modStr = XtStackAlloc ((size_t)(str - start + 1), modStrbuf); + if (modStr == NULL) _XtAllocError (NULL); + (void) memmove(modStr, start, (size_t) (str - start)); + modStr[str-start] = '\0'; + *token_return = XrmStringToQuark(modStr); + XtStackFree (modStr, modStrbuf); + } } return str; } @@ -682,7 +684,7 @@ static String ParseModifiers( register String start; Boolean notFlag, exclusive, keysymAsMod; Value maskBit; - XrmQuark Qmod; + XrmQuark Qmod = QNone; ScanWhitespace(str); start = str; @@ -690,7 +692,7 @@ static String ParseModifiers( exclusive = FALSE; if (start != str) { if (Qmod == QNone) { - event->event.modifierMask = ~0; + event->event.modifierMask = (unsigned long) (~0); event->event.modifiers = 0; ScanWhitespace(str); return str; @@ -748,11 +750,11 @@ static String ParseModifiers( return PanicModeRecovery(str); } event->event.modifierMask |= maskBit; - if (notFlag) event->event.modifiers &= ~maskBit; + if (notFlag) event->event.modifiers = (event->event.modifiers & (TMLongCard) (~maskBit)); else event->event.modifiers |= maskBit; ScanWhitespace(str); } - if (exclusive) event->event.modifierMask = ~0; + if (exclusive) event->event.modifierMask = (unsigned long) (~0); return str; } @@ -769,13 +771,13 @@ static String ParseXtEventType( ScanAlphanumeric(str); eventTypeStr = XtStackAlloc ((size_t)(str - start + 1), eventTypeStrbuf); if (eventTypeStr == NULL) _XtAllocError (NULL); - (void) memmove(eventTypeStr, start, str-start); + (void) memmove(eventTypeStr, start, (size_t)(str-start)); eventTypeStr[str-start] = '\0'; *tmEventP = LookupTMEventType(eventTypeStr,error); XtStackFree (eventTypeStr, eventTypeStrbuf); if (*error) return PanicModeRecovery(str); - event->event.eventType = events[*tmEventP].eventType; + event->event.eventType = (TMLongCard) events[*tmEventP].eventType; return str; } @@ -786,9 +788,9 @@ static unsigned long StrToHex( register unsigned long val = 0; while ((c = *str)) { - if ('0' <= c && c <= '9') val = val*16+c-'0'; - else if ('a' <= c && c <= 'z') val = val*16+c-'a'+10; - else if ('A' <= c && c <= 'Z') val = val*16+c-'A'+10; + if ('0' <= c && c <= '9') val = (unsigned long) (val * 16 + (unsigned long)c - '0'); + else if ('a' <= c && c <= 'z') val = (unsigned long) (val*16+(unsigned long)c-'a'+10); + else if ('A' <= c && c <= 'Z') val = (unsigned long) (val*16+(unsigned long)c-'A'+10); else return 0; str++; } @@ -803,7 +805,7 @@ static unsigned long StrToOct( register unsigned long val = 0; while ((c = *str)) { - if ('0' <= c && c <= '7') val = val*8+c-'0'; else return 0; + if ('0' <= c && c <= '7') val = val*8+(unsigned long)c-'0'; else return 0; str++; } @@ -823,7 +825,7 @@ static unsigned long StrToNum( } while ((c = *str)) { - if ('0' <= c && c <= '9') val = val*10+c-'0'; + if ('0' <= c && c <= '9') val = val*10+(unsigned long)c-'0'; else return 0; str++; } @@ -842,7 +844,7 @@ static KeySym StringToKeySym( #ifndef NOTASCII /* special case single character ASCII, for speed */ if (*(str+1) == '\0') { - if (' ' <= *str && *str <= '~') return XK_space + (*str - ' '); + if (' ' <= *str && *str <= '~') return (KeySym) (XK_space + (*str - ' ')); } #endif @@ -906,7 +908,7 @@ static String ParseImmed( Boolean* error) { event->event.eventCode = (unsigned long)closure; - event->event.eventCodeMask = ~0UL; + event->event.eventCodeMask = (unsigned long) (~0UL); return BROKEN_OPTIMIZER_HACK(str); } @@ -952,9 +954,9 @@ static String ParseKeySym( EventPtr event, Boolean* error) { - char *start; + String start; char keySymNamebuf[100]; - char* keySymName; + char* keySymName = NULL; ScanWhitespace(str); @@ -965,7 +967,7 @@ static String ParseKeySym( if (*str != '\0' && !IsNewline(*str)) str++; keySymName[1] = '\0'; event->event.eventCode = StringToKeySym(keySymName, error); - event->event.eventCodeMask = ~0L; + event->event.eventCodeMask = (unsigned long) (~0L); } else if (*str == ',' || *str == ':' || /* allow leftparen to be single char symbol, * for backwards compatibility @@ -986,12 +988,12 @@ static String ParseKeySym( && (*str != '(' || *(str+1) <= '0' || *(str+1) >= '9') && *str != '\0') str++; keySymName = XtStackAlloc ((size_t)(str - start + 1), keySymNamebuf); - (void) memmove(keySymName, start, str-start); + (void) memmove(keySymName, start, (size_t) (str-start)); keySymName[str-start] = '\0'; event->event.eventCode = StringToKeySym(keySymName, error); - event->event.eventCodeMask = ~0L; + event->event.eventCodeMask = (unsigned long) (~0L); } - if (*error) { + if (*error && keySymName) { /* We never get here when keySymName hasn't been allocated */ if (keySymName[0] == '<') { /* special case for common error */ @@ -1032,13 +1034,13 @@ static String ParseTable( *error = TRUE; return str; } - (void) memmove(tableSymName, start, str-start); + (void) memmove(tableSymName, start, (size_t) (str-start)); tableSymName[str-start] = '\0'; signature = StringToQuark(tableSymName); for (; table->signature != NULLQUARK; table++) if (table->signature == signature) { event->event.eventCode = table->value; - event->event.eventCodeMask = ~0L; + event->event.eventCodeMask = (unsigned long) (~0L); return str; } @@ -1074,7 +1076,8 @@ static String ParseAtom( event->event.eventCode = 0L; event->event.eventCodeMask = 0L; } else { - char *start, atomName[1000]; + String start; + char atomName[1000]; start = str; while ( *str != ',' @@ -1088,9 +1091,9 @@ static String ParseAtom( *error = TRUE; return str; } - (void) memmove(atomName, start, str-start); + (void) memmove(atomName, start, (size_t) (str-start)); atomName[str-start] = '\0'; - event->event.eventCode = XrmStringToQuark(atomName); + event->event.eventCode = (TMLongCard) XrmStringToQuark(atomName); event->event.matchEvent = _XtMatchAtom; } return str; @@ -1141,8 +1144,8 @@ static String ParseEvent( && (event->event.modifiers | event->event.modifierMask) /* any */ && (event->event.modifiers != AnyModifier)) { - event->event.modifiers - |= buttonModifierMasks[event->event.eventCode]; + event->event.modifiers = (event->event.modifiers + | (TMLongCard) buttonModifierMasks[event->event.eventCode]); /* the button that is going up will always be in the modifiers... */ } @@ -1173,7 +1176,7 @@ static String ParseQuotedStringEvent( event->event.eventType = KeyPress; event->event.eventCode = StringToKeySym(s, error); if (*error) return PanicModeRecovery(str); - event->event.eventCodeMask = ~0L; + event->event.eventCodeMask = (unsigned long) (~0L); event->event.matchEvent = _XtMatchUsingStandardMods; event->event.standard = TRUE; @@ -1205,11 +1208,11 @@ static void RepeatDown( if ((upEvent->event.eventType == ButtonRelease) && (upEvent->event.modifiers != AnyModifier) && (upEvent->event.modifiers | upEvent->event.modifierMask)) - upEvent->event.modifiers - |= buttonModifierMasks[event->event.eventCode]; + upEvent->event.modifiers = (upEvent->event.modifiers + | (TMLongCard) buttonModifierMasks[event->event.eventCode]); if (event->event.lateModifiers) - event->event.lateModifiers->ref_count += (reps - 1) * 2; + event->event.lateModifiers->ref_count = (unsigned short) (event->event.lateModifiers->ref_count + (reps - 1) * 2); for (i=1; i<reps; i++) { @@ -1252,11 +1255,11 @@ static void RepeatDownPlus( if ((upEvent->event.eventType == ButtonRelease) && (upEvent->event.modifiers != AnyModifier) && (upEvent->event.modifiers | upEvent->event.modifierMask)) - upEvent->event.modifiers - |= buttonModifierMasks[event->event.eventCode]; + upEvent->event.modifiers = (upEvent->event.modifiers + | (TMLongCard) buttonModifierMasks[event->event.eventCode]); if (event->event.lateModifiers) - event->event.lateModifiers->ref_count += reps * 2 - 1; + event->event.lateModifiers->ref_count = (unsigned short) (event->event.lateModifiers->ref_count + reps * 2 - 1); for (i=0; i<reps; i++) { @@ -1306,11 +1309,11 @@ static void RepeatUp( if ((downEvent->event.eventType == ButtonPress) && (downEvent->event.modifiers != AnyModifier) && (downEvent->event.modifiers | downEvent->event.modifierMask)) - downEvent->event.modifiers - &= ~buttonModifierMasks[event->event.eventCode]; + downEvent->event.modifiers = (downEvent->event.modifiers + & (TMLongCard) (~buttonModifierMasks[event->event.eventCode])); if (event->event.lateModifiers) - event->event.lateModifiers->ref_count += reps * 2 - 1; + event->event.lateModifiers->ref_count = (unsigned short) (event->event.lateModifiers->ref_count + reps * 2 - 1); /* up */ event->next = XtNew(EventSeqRec); @@ -1362,11 +1365,11 @@ static void RepeatUpPlus( if ((downEvent->event.eventType == ButtonPress) && (downEvent->event.modifiers != AnyModifier) && (downEvent->event.modifiers | downEvent->event.modifierMask)) - downEvent->event.modifiers - &= ~buttonModifierMasks[event->event.eventCode]; + downEvent->event.modifiers = (downEvent->event.modifiers + & (TMLongCard) (~buttonModifierMasks[event->event.eventCode])); if (event->event.lateModifiers) - event->event.lateModifiers->ref_count += reps * 2; + event->event.lateModifiers->ref_count = (unsigned short) (event->event.lateModifiers->ref_count + reps * 2); for (i=0; i<reps; i++) { @@ -1403,7 +1406,7 @@ static void RepeatOther( tempEvent = event = *eventP; if (event->event.lateModifiers) - event->event.lateModifiers->ref_count += reps - 1; + event->event.lateModifiers->ref_count = (unsigned short) (event->event.lateModifiers->ref_count + reps - 1); for (i=1; i<reps; i++) { event->next = XtNew(EventSeqRec); @@ -1426,7 +1429,7 @@ static void RepeatOtherPlus( tempEvent = event = *eventP; if (event->event.lateModifiers) - event->event.lateModifiers->ref_count += reps - 1; + event->event.lateModifiers->ref_count = (unsigned short) (event->event.lateModifiers->ref_count + reps - 1); for (i=1; i<reps; i++) { event->next = XtNew(EventSeqRec); @@ -1481,11 +1484,11 @@ static String ParseRepeat( size_t len; ScanNumeric(str); - len = (str - start); + len = (size_t) (str - start); if (len < sizeof repStr) { (void) memmove(repStr, start, len); repStr[len] = '\0'; - *reps = StrToNum(repStr); + *reps = (int) StrToNum(repStr); } else { Syntax("Repeat count too large.", ""); *error = TRUE; @@ -1551,6 +1554,7 @@ static String ParseEventSeq( XtCXtToolkitError, "... probably due to non-Latin1 character in quoted string", (String*)NULL, (Cardinal*)NULL); + XtFree((char *)event); return PanicModeRecovery(str); } *nextEvent = event; @@ -1616,7 +1620,7 @@ static String ParseActionProc( *error = TRUE; return str; } - (void) memmove(procName, start, str-start); + (void) memmove(procName, start, (size_t) (str-start)); procName[str-start] = '\0'; *actionProcNameP = XrmStringToQuark( procName ); return str; @@ -1625,7 +1629,7 @@ static String ParseActionProc( static String ParseString( register String str, - String *strP) + _XtString *strP) { register String start; @@ -1642,9 +1646,9 @@ static String ParseString( */ if (*str == '\\' && (*(str+1) == '"' || (*(str+1) == '\\' && *(str+2) == '"'))) { - len = prev_len + (str-start+2); + len = (unsigned) (prev_len + (str-start+2)); *strP = XtRealloc(*strP, len); - (void) memmove(*strP + prev_len, start, str-start); + (void) memmove(*strP + prev_len, start, (size_t) (str-start)); prev_len = len-1; str++; (*strP)[prev_len-1] = *str; @@ -1653,9 +1657,9 @@ static String ParseString( } str++; } - len = prev_len + (str-start+1); + len = (unsigned) (prev_len + (str-start+1)); *strP = XtRealloc(*strP, len); - (void) memmove( *strP + prev_len, start, str-start); + (void) memmove( *strP + prev_len, start, (size_t) (str-start)); (*strP)[len-1] = '\0'; if (*str == '"') str++; else XtWarningMsg(XtNtranslationParseError,"parseString", @@ -1671,7 +1675,7 @@ static String ParseString( && !IsNewline(*str) && *str != '\0') str++; *strP = __XtMalloc((unsigned)(str-start+1)); - (void) memmove(*strP, start, str-start); + (void) memmove(*strP, start, (size_t) (str-start)); (*strP)[str-start] = '\0'; } return str; @@ -1690,12 +1694,11 @@ static String ParseParamSeq( } ParamRec; ParamPtr params = NULL; - register Cardinal num_params = 0; - register Cardinal i; + Cardinal num_params = 0; ScanWhitespace(str); while (*str != ')' && *str != '\0' && !IsNewline(*str)) { - String newStr; + _XtString newStr; str = ParseString(str, &newStr); if (newStr != NULL) { ParamPtr temp = (ParamRec*) @@ -1716,7 +1719,9 @@ static String ParseParamSeq( if (num_params != 0) { String *paramP = (String *) - __XtMalloc( (unsigned)(num_params+1) * sizeof(String) ); + __XtMalloc( (Cardinal)((num_params+1) * sizeof(String)) ); + Cardinal i; + *paramSeqP = paramP; *paramNumP = num_params; paramP += num_params; /* list is LIFO right now */ @@ -1768,9 +1773,11 @@ static String ParseActionSeq( ActionPtr *actionsP, Boolean *error) { - ActionPtr *nextActionP = actionsP; + ActionPtr *nextActionP; + + if ((nextActionP = actionsP) != NULL) + *actionsP = NULL; - *actionsP = NULL; while (*str != '\0' && !IsNewline(*str)) { register ActionPtr action; XrmQuark quark; @@ -1781,12 +1788,17 @@ static String ParseActionSeq( action->next = NULL; str = ParseAction(str, action, &quark, error); - if (*error) return PanicModeRecovery(str); + if (*error) { + XtFree((char *)action); + return PanicModeRecovery(str); + } action->idx = _XtGetQuarkIndex(parseTree, quark); ScanWhitespace(str); - *nextActionP = action; - nextActionP = &action->next; + if (nextActionP) { + *nextActionP = action; + nextActionP = &action->next; + } } if (IsNewline(*str)) str++; ScanWhitespace(str); @@ -1803,7 +1815,7 @@ static void ShowProduction( char *eol, *production, productionbuf[500]; eol = strchr(currentProduction, '\n'); - if (eol) len = eol - currentProduction; + if (eol) len = (size_t) (eol - currentProduction); else len = strlen (currentProduction); production = XtStackAlloc (len + 1, productionbuf); if (production == NULL) _XtAllocError (NULL); @@ -1832,21 +1844,18 @@ static String ParseTranslationTableProduction( String production = str; actionsP = NULL; - str = ParseEventSeq(str, &eventSeq, &actionsP,error); - if (*error == TRUE) { - ShowProduction(production); - FreeEventSeq(eventSeq); - return (str); - } - ScanWhitespace(str); - str = ParseActionSeq(parseTree, str, actionsP, error); + str = ParseEventSeq(str, &eventSeq, &actionsP, error); if (*error == TRUE) { ShowProduction(production); - FreeEventSeq(eventSeq); - return (str); + } else { + ScanWhitespace(str); + str = ParseActionSeq(parseTree, str, actionsP, error); + if (*error == TRUE) { + ShowProduction(production); + } else { + _XtAddEventSeqToStateTree(eventSeq, parseTree); + } } - - _XtAddEventSeqToStateTree(eventSeq, parseTree); FreeEventSeq(eventSeq); return (str); } @@ -1856,19 +1865,21 @@ static String CheckForPoundSign( _XtTranslateOp defaultOp, _XtTranslateOp *actualOpRtn) { - String start; - char operation[20]; _XtTranslateOp opType; opType = defaultOp; ScanWhitespace(str); + if (*str == '#') { + String start; + char operation[20]; int len; + str++; start = str; str = ScanIdent(str); - len = MIN(19, str-start); - (void) memmove(operation, start, len); + len = MIN(19, (int)(str - start)); + (void) memmove(operation, start, (size_t) len); operation[len] = '\0'; if (!strcmp(operation,"replace")) opType = XtTableReplace; @@ -1909,7 +1920,7 @@ static XtTranslations ParseTranslationTable( parseTree->isSimple = TRUE; parseTree->mappingNotifyInterest = FALSE; - parseTree->isAccelerator = isAccelerator; + XtSetBit(parseTree->isAccelerator, isAccelerator); parseTree->isStackBranchHeads = parseTree->isStackQuarks = parseTree->isStackComplexBranchHeads = TRUE; @@ -1940,7 +1951,7 @@ static XtTranslations ParseTranslationTable( XtFree((char *)parseTree->complexBranchHeadTbl); xlations = _XtCreateXlations(stateTrees, 1, NULL, NULL); - xlations->operation = actualOp; + xlations->operation = (unsigned char) actualOp; #ifdef notdef XtFree(stateTrees); |