SAMPLE FIX: The following patch changes these files: lib/Xmu/EditresCom.c lib/Xt/Display.c lib/Xt/Imakefile lib/Xt/StringConverters.c (new file) programs/editres/handler.c ============ lib/Xmu/EditresCom.c =============== *** /usr/sde/osf1/build/xexternal/src/xc/lib/Xmu/EditresCom.c Sun Apr 17 20:16:05 1994 --- lib/Xmu/EditresCom.c Tue Feb 07 14:35:40 1995 *************** *** 1,3 **** --- 1,4 ---- + /* $XConsortium: EditresCom.c,v 1.33 94/04/17 20:16:05 rws Exp $ */ /* *************** *** 142,147 **** --- 143,150 ---- static char *DumpWidgets(), *DoSetValues(), *DoFindChild(); static char *DoGetGeometry(), *DoGetResources(), *DumpValues(); + static void _XEditresGetStringValues(Widget, Arg *, int); + /************************************************************ * * Resource Editor Communication Code *************** *** 1388,1394 **** --- 1391,1401 ---- Arg warg[1]; String res_value = NULL; GetValuesEvent * gv_event = (GetValuesEvent *)event; + char buffer[64]; + char * str; + res_value = buffer; + /* put the count in the stream. */ _XEditResPut16(stream, (unsigned int) 1); *************** *** 1397,1404 **** /* resource editor and insert it into the stream */ XtSetArg(warg[0], gv_event->name, &res_value); /*_XtGetStringValues(gv_event->widgets[0].ids[0], warg, 1);*/ ! if (!res_value) res_value = "NoValue"; ! _XEditResPutString8(stream, res_value); return(NULL); } --- 1404,1419 ---- /* resource editor and insert it into the stream */ XtSetArg(warg[0], gv_event->name, &res_value); /*_XtGetStringValues(gv_event->widgets[0].ids[0], warg, 1);*/ ! ! if ((str = VerifyWidget(w, &(gv_event->widgets[0]))) != NULL) { ! _XEditResPutString8(stream, str); ! XtFree(str); ! } ! else { ! _XEditresGetStringValues(gv_event->widgets[0].real_widget, warg, 1); ! if (!res_value) res_value = "NoValue"; ! _XEditResPutString8(stream, res_value); ! } return(NULL); } *************** *** 1836,1838 **** --- 1851,2049 ---- } + + static void _XEditResCvtWarningHandler(name, type, class, def, params, num_params) + String name; + String type; + String class; + String def; + String *params; + Cardinal *num_params; + { + /* just ignore the warning */ + return; + } + + + static void + _XEditresGetStringValues(Widget w, Arg *warg, int numargs) + + { + XtResourceList res_list; + Cardinal num_res; + XtResource * res = NULL; + long value; + int size, i; + char * string = ""; + char *buffer; + Arg args[1]; + XrmValue to, from, to_color; + + + /* + * Look for the resource. + */ + XtGetResourceList(XtClass(w), &res_list, &num_res); + for (i=0; i<(int)num_res && res==NULL; i++) + { + if (0 == strcmp(res_list[i].resource_name, warg->name)) + res = &res_list[i]; + } + if (res == NULL && XtParent(w) != NULL) + { + XtFree((char *)res_list); + XtGetConstraintResourceList(XtClass(XtParent(w)), &res_list, &num_res); + } + for (i=0; i<(int)num_res && res==NULL; i++) + { + if (0 == strcmp(res_list[i].resource_name, warg->name)) + res = &res_list[i]; + } + + if (res == NULL) + { + /* Couldn't find resource */ + + XtFree((char *)res_list); + *(XtPointer *)(warg->value) = NULL; + return; + } + + size = res->resource_size; + buffer = *(char **)(warg->value); + + + /* try to get the value in the proper size */ + switch (res->resource_size) { + #if (LONG_BIT == 64) + long v8; + #endif + int v4; + short v2; + char v1; + + case 1 : + XtSetArg( args[0], res->resource_name, &v1); + XtGetValues(w, args, 1); + value = (int) v1; + break; + case 2 : + XtSetArg( args[0], res->resource_name, &v2); + XtGetValues(w, args, 1); + value = (int) v2; + break; + case 4 : + XtSetArg( args[0], res->resource_name, &v4); + XtGetValues(w, args, 1); + value = (int) v4; + break; + #if (LONG_BIT == 64) + case 8 : + XtSetArg( args[0], res->resource_name, &v8); + XtGetValues(w, args, 1); + value = (long) v8; + break; + #endif + default: + fprintf(stderr, "_XEditresGetStringValues: bad size %d\n", + res->resource_size); + string = "bad size"; + goto done; + } + + + /* + * If the resource is already String, no conversion needed. + */ + if (strcmp(XtRString, res->resource_type) == 0) + { + if (value == NULL) + string = "(null)"; + else + string = (char *) value; + } + else + { + XtErrorMsgHandler old_handler; + + /* + * Ignore conversion warnings. + */ + old_handler = XtAppSetWarningMsgHandler(XtWidgetToApplicationContext(w), + _XEditResCvtWarningHandler); + from.size = res->resource_size; + from.addr = (caddr_t) &value; + to.addr = NULL; + to.size = 0; + to_color.addr = NULL; + to_color.size = 0; + /* + * Special case for type Pixel. + */ + if (0 == strcmp(res->resource_type, XtRPixel) + && XtConvertAndStore(w, XtRPixel, &from, XtRColor, &to) + && XtConvertAndStore(w, XtRColor, &to, XtRString, &to_color)) + { + string = to_color.addr; + } + else if (XtConvertAndStore(w,res->resource_type, &from, XtRString, &to)) + { + string = to.addr; + } + else + { + /* + * Conversion failed, fall back to representing it as integer. + */ + switch (res->resource_size) + { + case sizeof(char): + sprintf(buffer, "%d", (unsigned char)value); + string = buffer; + break; + case sizeof(short): + sprintf(buffer, "%d", (short)value); + string = buffer; + break; + case sizeof(int): + sprintf(buffer, "%d", (int)value); + string = buffer; + break; + #if (LONG_BIT == 64) + case sizeof(long): + sprintf(buffer, "%ld", value); + string = buffer; + break; + #endif + default: + break; + } + strcat(buffer, " (integer fallback conversion)"); + } + /* + * Restore original warning handler. + */ + XtAppSetWarningMsgHandler(XtWidgetToApplicationContext(w), old_handler); + } + + + if (string == NULL) + { + /* can't happen */ + #ifdef DEBUG + fprintf(stderr, "_XEditResPutValueString8: couldn't convert to string\n"); + fprintf(stderr, "Class = %s Type = %s Name = %s\n", res->resource_type, + res->resource_name,res->resource_class); + #endif + string = ""; + } + done: + *(char **)(warg->value) = string; + #ifdef DEBUG + fprintf(stderr, "put %s at %#x\n", string, stream->current); + #endif + + XtFree((char *)res_list); + + } + ============ lib/Xt/Display.c =============== *** /usr/sde/osf1/build/xexternal/src/xc/lib/Xt/Display.c Thu Sep 08 13:58:19 1994 --- lib/Xt/Display.c Tue Feb 07 14:35:46 1995 *************** *** 1,3 **** --- 1,4 ---- + /* $XConsortium: Display.c,v 1.116 94/06/01 15:34:15 converse Exp $ */ /*********************************************************** *************** *** 412,417 **** --- 413,419 ---- app->action_table = NULL; _XtSetDefaultSelectionTimeout(&app->selectionTimeout); _XtSetDefaultConverterTable(&app->converterTable); + _XtInitStringConverters(); app->sync = app->being_destroyed = app->error_inited = FALSE; app->in_phase2_destroy = NULL; #ifndef USE_POLL ============ lib/Xt/Imakefile =============== *** /usr/sde/osf1/build/xexternal/src/xc/lib/Xt/Imakefile Mon Apr 04 21:54:26 1994 --- lib/Xt/Imakefile Tue Feb 07 14:35:53 1995 *************** *** 1,3 **** --- 1,5 ---- + + XCOMM $XConsortium: Imakefile,v 1.110 94/04/04 21:54:23 gildea Exp $ #define DoNormalLib NormalLibXt #define DoSharedLib SharedLibXt *************** *** 63,68 **** --- 65,73 ---- LINTLIBS = $(LINTXLIB) + EDITRES_SRCS = EditresCom.c Lower.c StringConverters.c + EDITRES_OBJS = EditresCom.o Lower.o StringConverters.o + HEADERS = \ Composite.h \ CompositeP.h \ *************** *** 136,142 **** VarGet.c \ Varargs.c \ Vendor.c \ ! sharedlib.c OBJS = \ ActionHook.o \ --- 141,148 ---- VarGet.c \ Varargs.c \ Vendor.c \ ! sharedlib.c \ ! $(EDITRES_SRCS) OBJS = \ ActionHook.o \ *************** *** 191,197 **** VarCreate.o \ VarGet.o \ Varargs.o \ ! Vendor.o #if SharedDataSeparation UNSHAREDOBJS = StringDefs.o sharedlib.o --- 197,204 ---- VarCreate.o \ VarGet.o \ Varargs.o \ ! Vendor.o \ ! $(EDITRES_OBJS) #if SharedDataSeparation UNSHAREDOBJS = StringDefs.o sharedlib.o *************** *** 210,214 **** --- 217,224 ---- #if DoSharedLib SpecialCObjectRule(sharedlib,$(_NOOP_),$(SHLIBDEF)) #endif + + LinkSourceFile(EditresCom.c,$(XMUSRC)) + LinkSourceFile(Lower.c,$(XMUSRC)) DependTarget() ============ lib/Xt/StringConverters.c =============== ============ programs/editres/handler.c =============== *** /usr/sde/osf1/build/xexternal/src/xc/programs/editres/handler.c Sun Apr 17 20:38:56 1994 --- programs/editres/handler.c Tue Feb 07 14:36:12 1995 *************** *** 1,3 **** --- 1,4 ---- + /* * $XConsortium: handler.c,v 1.29 94/04/17 20:38:56 dave Exp $ * *************** *** 813,820 **** /*CreateGetValuesCommand(node, (XtPointer)&info); Inserts widget */ /* Insert widget */ ! _XEditResPut16(stream, 1); ! _XEditResPut32(stream, node->id); SetCommand(node->tree_info->tree_widget, LocalGetValues, NULL); } --- 814,820 ---- /*CreateGetValuesCommand(node, (XtPointer)&info); Inserts widget */ /* Insert widget */ ! InsertWidgetFromNode(stream, node); SetCommand(node->tree_info->tree_widget, LocalGetValues, NULL); } ============ lib/Xt/StringConverters.c =============== *** lib/Xt/StringConverters.c Tue Feb 07 14:40:46 1995 --- lib/Xt/StringConverters.c Tue Feb 07 14:31:23 1995 *************** *** 0 **** --- 1,383 ---- + + /* + * Copyright (c) 1995 Digital Equipment Corportation + * + * The X Consortium, and any party obtaining a copy of these files from + * the X Consortium, directly or indirectly, is granted, free of charge, a + * full and unrestricted irrevocable, world-wide, paid up, royalty-free, + * nonexclusive right and license to deal in this software and + * documentation files (the "Software"), including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons who receive + * copies from any such party to do so. This license includes without + * limitation a license to do the foregoing actions under any patents of + * the party supplying this software to the X Consortium. + */ + + #pragma ident "@(#)$RCSfile: StringConverters.c,v $ $Revision: 1.1.2.2 $ (DEC) $Date: 1995/01/25 22:13:17 $" + #include + #include "../Xt/IntrinsicI.h" + #include + #include + + #include + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + void XtDisplayConversionWarning(); + + static String XtNwrongParameters = "wrongParameters"; + static String XtNconversionError = "conversionError"; + static String XtNmissingCharsetList = "missingCharsetList"; + + typedef struct { + int value; + char * name; + int size; + } ConversionMap; + + static ConversionMap boolean_map[] = { + { True, XtEtrue, sizeof(XtEtrue) }, + { False, XtEfalse, sizeof(XtEfalse) }, + { True, XtEon, sizeof(XtEon) }, + { False, XtEoff, sizeof(XtEoff) }, + { True, XtEyes, sizeof(XtEyes) }, + { False, XtEno, sizeof(XtEno) }, + }; + + static ConversionMap shape_style_map[] = { + { XmuShapeRectangle, XtERectangle, sizeof(XtERectangle) }, + { XmuShapeRectangle, "ShapeRectangle", sizeof("ShapeRectangle") }, + { XmuShapeOval, XtEOval, sizeof(XtEOval) }, + { XmuShapeOval, "ShapeOval", sizeof("ShapeOval") }, + { XmuShapeEllipse, "ShapeEllipse", sizeof("ShapeEllipse") }, + { XmuShapeEllipse, XtEEllipse, sizeof(XtEEllipse) }, + { XmuShapeRoundedRectangle, "ShapeRoundedRectangle", + sizeof("ShapeRoundedRectangle") }, + { XmuShapeRoundedRectangle, XtERoundedRectangle, + sizeof( XtERoundedRectangle) }, + }; + + + #define string_convert_done(value) \ + { \ + if (toVal->addr != NULL) { \ + if (toVal->size < size) { \ + toVal->size = size; \ + return False; \ + } \ + strcpy((char *) toVal->addr, value); \ + } \ + else { \ + toVal->addr = (XtPointer)value; \ + } \ + toVal->size = size; \ + return True; \ + } + + #define map_convert_done(value) \ + { \ + if (toVal->addr != NULL) { \ + if (toVal->size < value.size) { \ + toVal->size = value.size; \ + return False; \ + } \ + strcpy((char *) toVal->addr, value.name); \ + } \ + else { \ + toVal->addr = value.name; \ + } \ + toVal->size = value.size; \ + return True; \ + } + + + + Boolean XtCvtShapeStyleToString (); + Boolean XtCvtBooleanToString (); + Boolean XtCvtBoolToString (); + + + void + XtDisplayConversionWarning(type, from, to) + String type; + int from; + String to; + { + String params[2]; + Cardinal num_params = 2; + + params[0] = (String)from; + params[1] = (String)to; + XtWarningMsg("conversionError", type, XtCXtToolkitError, + "Cannot convert value %d to type %s", + params,&num_params); + } + + + + Boolean XtCvtShapeStyleToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + int * i = (int *) (fromVal->addr); + int index; + + + for (index = 0; XtNumber(shape_style_map); index++) + if (*i == shape_style_map[index].value) + map_convert_done(shape_style_map[index]); + + XtDisplayConversionWarning(XtRShapeStyle, *i, XtRString); + return False; + } + + + + + + Boolean XtCvtBooleanToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + Boolean * i = (Boolean *) (fromVal->addr); + int index; + + + for (index = 0; XtNumber(boolean_map); index++) + if (*i == boolean_map[index].value) + map_convert_done(boolean_map[index]); + + XtDisplayConversionWarning(XtRBoolean, *i, XtRString); + return False; + } + + + Boolean XtCvtBoolToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + Boolean * i = (Boolean *) (fromVal->addr); + int index; + + + for (index = 0; XtNumber(boolean_map); index++) + if (*i == boolean_map[index].value) + map_convert_done(boolean_map[index]); + + XtDisplayConversionWarning(XtRBool, *i, XtRString); + return False; + } + + + Boolean XtCvtPositionToString (dpy, args, numArgs, fromVal, toVal, data) + Display* dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + int size; + static char buffer[32]; + + if (*numArgs != 0) + XtAppWarningMsg(XtDisplayToApplicationContext(dpy), + XtNwrongParameters,"cvtPositionToString",XtCXtToolkitError, + "Position to String conversion needs no extra arguments", + (String *)NULL, (Cardinal *)NULL); + + sprintf(buffer, "%d", * (Position *) fromVal->addr); + size = strlen(buffer); + string_convert_done(buffer); + } + + Boolean XtCvtIntToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + int size; + static char buffer[32]; + + if (*numArgs != 0) + XtAppWarningMsg(XtDisplayToApplicationContext(dpy), + XtNwrongParameters,"cvtIntToString",XtCXtToolkitError, + "Int to String conversion needs no extra arguments", + (String *)NULL, (Cardinal *)NULL); + + sprintf(buffer, "%d", * (int *) fromVal->addr); + size = strlen(buffer); + string_convert_done(buffer); + } + + Boolean XtCvtCardinalToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + int size; + static char buffer[32]; + + if (*numArgs != 0) + XtAppWarningMsg(XtDisplayToApplicationContext(dpy), + XtNwrongParameters,"cvtCardinalToString",XtCXtToolkitError, + "Cardinal to String conversion needs no extra arguments", + (String *)NULL, (Cardinal *)NULL); + + sprintf(buffer, "%d", * (Cardinal *) fromVal->addr); + size = strlen(buffer); + string_convert_done(buffer); + } + + + Boolean XtCvtPixelToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + int size; + static char buffer[32]; + + if (*numArgs != 0) + XtAppWarningMsg(XtDisplayToApplicationContext(dpy), + XtNwrongParameters,"cvtPixelToString",XtCXtToolkitError, + "Pixel to String conversion needs no extra arguments", + (String *)NULL, (Cardinal *)NULL); + + sprintf(buffer, "%d", * (Pixel *) fromVal->addr); + size = strlen(buffer); + string_convert_done(buffer); + } + + Boolean XtCvtColorToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + int size; + static char buffer[32]; + + if (*numArgs != 0) + XtAppWarningMsg(XtDisplayToApplicationContext(dpy), + XtNwrongParameters,"cvtColorToString",XtCXtToolkitError, + "Color to String conversion needs no extra arguments", + (String *)NULL, (Cardinal *)NULL); + + sprintf(buffer, "rgb:%04hx/%04hx/%04hx", ((XColor *)fromVal->addr)->red, + ((XColor *)fromVal->addr)->green, ((XColor *)fromVal->addr)->blue); + size = strlen(buffer); + string_convert_done(buffer); + } + + + Boolean XtCvtUnsignedCharToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + int size; + static char buffer[32]; + + if (*numArgs != 0) + XtAppWarningMsg(XtDisplayToApplicationContext(dpy), + XtNwrongParameters,"cvtUnsignedCharToString", + XtCXtToolkitError, + "UnsignedChar to String conversion needs no extra arguments", + (String *)NULL, (Cardinal *)NULL); + + sprintf(buffer, "%d", * (unsigned char *) fromVal->addr); + size = strlen(buffer); + string_convert_done(buffer); + } + + Boolean XtCvtDimensionToString (dpy, args, numArgs, fromVal, toVal, data) + Display * dpy; + XrmValue * args; + Cardinal * numArgs; + XrmValue * fromVal; + XrmValue * toVal; + XtPointer * data; + { + int size; + static char buffer[32]; + + if (*numArgs != 0) + XtAppWarningMsg(XtDisplayToApplicationContext(dpy), + XtNwrongParameters,"cvtDimensionToString",XtCXtToolkitError, + "Dimension to String conversion needs no extra arguments", + (String *)NULL, (Cardinal *)NULL); + + sprintf(buffer, "%d", * (Dimension *) fromVal->addr); + size = strlen(buffer); + string_convert_done(buffer); + } + + + void + _XtInitStringConverters() + { + XtSetTypeConverter(XtRShapeStyle, XtRString, XtCvtShapeStyleToString, + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRBoolean, XtRString, XtCvtBooleanToString, + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRBool, XtRString, XtCvtBoolToString, + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRShapeStyle, XtRString , XtCvtShapeStyleToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRBoolean, XtRString , XtCvtBooleanToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRBool, XtRString , XtCvtBoolToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRPosition, XtRString , XtCvtPositionToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRInt, XtRString , XtCvtIntToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRCardinal, XtRString , XtCvtCardinalToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRPixel, XtRString , XtCvtPixelToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRColor, XtRString , XtCvtColorToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRUnsignedChar, XtRString , XtCvtUnsignedCharToString , + NULL, 0, XtCacheNone, NULL); + XtSetTypeConverter(XtRDimension, XtRString , XtCvtDimensionToString , + NULL, 0, XtCacheNone, NULL); + } +