home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xt / Converters.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-23  |  46.1 KB  |  1,533 lines

  1. /* $XConsortium: Converters.c,v 1.85 91/07/23 15:38:18 converse Exp $ */
  2. /*LINTLIBRARY*/
  3.  
  4. /***********************************************************
  5. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  6. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  7.  
  8.                         All Rights Reserved
  9.  
  10. Permission to use, copy, modify, and distribute this software and its 
  11. documentation for any purpose and without fee is hereby granted, 
  12. provided that the above copyright notice appear in all copies and that
  13. both that copyright notice and this permission notice appear in 
  14. supporting documentation, and that the names of Digital or MIT not be
  15. used in advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.  
  17.  
  18. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  20. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  21. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  23. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  24. SOFTWARE.
  25.  
  26. ******************************************************************/
  27.  
  28. /* Conversion.c - implementations of resource type conversion procs */
  29.  
  30. #include    "IntrinsicI.h"
  31. #include    "StringDefs.h"
  32. #include    <stdio.h>
  33. #include        <X11/cursorfont.h>
  34. #include    <X11/keysym.h>
  35. #include    <X11/Xlocale.h>
  36.  
  37. #if __STDC__
  38. #define Const const
  39. #else
  40. #define Const /**/
  41. #endif
  42.  
  43. static Const String XtNwrongParameters = "wrongParameters";
  44. static Const String XtNconversionError = "conversionError";
  45. static Const String XtNmissingCharsetList = "missingCharsetList";
  46.  
  47. /* Representation types */
  48.  
  49. #define XtQAtom        XrmPermStringToQuark(XtRAtom)
  50. #define XtQCursor    XrmPermStringToQuark(XtRCursor)
  51. #define XtQDisplay    XrmPermStringToQuark(XtRDisplay)
  52. #define XtQFile        XrmPermStringToQuark(XtRFile)
  53. #define XtQFloat    XrmPermStringToQuark(XtRFloat)
  54. #ifdef STRING_TO_GEOMETRY
  55. #define XtQGeometry    XrmPermStringToQuark(XtRGeometry)
  56. #endif
  57. #define XtQInitialState    XrmPermStringToQuark(XtRInitialState)
  58. #define XtQPixmap    XrmPermStringToQuark(XtRPixmap)
  59. #define XtQShort    XrmPermStringToQuark(XtRShort)
  60. #define XtQUnsignedChar    XrmPermStringToQuark(XtRUnsignedChar)
  61. #define XtQVisual    XrmPermStringToQuark(XtRVisual)
  62.  
  63. static XrmQuark  XtQBool;
  64. static XrmQuark  XtQBoolean;
  65. static XrmQuark  XtQColor;
  66. static XrmQuark  XtQDimension;
  67. static XrmQuark  XtQFont;
  68. static XrmQuark  XtQFontSet;
  69. static XrmQuark  XtQFontStruct;
  70. static XrmQuark  XtQInt;
  71. static XrmQuark  XtQPixel;
  72. static XrmQuark  XtQPosition;
  73. XrmQuark  _XtQString;
  74.  
  75. void _XtConvertInitialize()
  76. {
  77.     XtQBool        = XrmPermStringToQuark(XtRBool);
  78.     XtQBoolean        = XrmPermStringToQuark(XtRBoolean);
  79.     XtQColor        = XrmPermStringToQuark(XtRColor);
  80.     XtQDimension    = XrmPermStringToQuark(XtRDimension);
  81.     XtQFont        = XrmPermStringToQuark(XtRFont);
  82.     XtQFontSet        = XrmPermStringToQuark(XtRFontSet);
  83.     XtQFontStruct    = XrmPermStringToQuark(XtRFontStruct);
  84.     XtQInt        = XrmPermStringToQuark(XtRInt);
  85.     XtQPixel        = XrmPermStringToQuark(XtRPixel);
  86.     XtQPosition        = XrmPermStringToQuark(XtRPosition);
  87.     _XtQString        = XrmPermStringToQuark(XtRString);
  88. }
  89.  
  90. #define    done(type, value) \
  91.     {                            \
  92.         if (toVal->addr != NULL) {                \
  93.         if (toVal->size < sizeof(type)) {        \
  94.             toVal->size = sizeof(type);            \
  95.             return False;                \
  96.         }                        \
  97.         *(type*)(toVal->addr) = (value);        \
  98.         }                            \
  99.         else {                        \
  100.         static type static_val;                \
  101.         static_val = (value);                \
  102.         toVal->addr = (XPointer)&static_val;        \
  103.         }                            \
  104.         toVal->size = sizeof(type);                \
  105.         return True;                    \
  106.     }
  107.  
  108.  
  109. #if NeedFunctionPrototypes
  110. void XtDisplayStringConversionWarning(
  111.     Display* dpy,
  112.     _Xconst char* from,
  113.     _Xconst char* toType
  114.     )
  115. #else
  116. void XtDisplayStringConversionWarning(dpy, from, toType)
  117.     Display* dpy;
  118.     String from, toType;
  119. #endif
  120. {
  121. #ifndef NO_MIT_HACKS    
  122.     /* Allow suppression of conversion warnings. %%%  Not specified. */
  123.  
  124.     static enum {Check, Report, Ignore} report_it = Check;
  125.  
  126.     if (report_it == Check) {
  127.     XrmDatabase rdb = XtDatabase(dpy);
  128.     XrmName xrm_name[2];
  129.     XrmClass xrm_class[2];
  130.     XrmRepresentation rep_type;
  131.     XrmValue value;
  132.     xrm_name[0] = XrmPermStringToQuark( "stringConversionWarnings" );
  133.     xrm_name[1] = 0;
  134.     xrm_class[0] = XrmPermStringToQuark( "StringConversionWarnings" );
  135.     xrm_class[1] = 0;
  136.     if (XrmQGetResource( rdb, xrm_name, xrm_class,
  137.                  &rep_type, &value ))
  138.     {
  139.         if (rep_type == XtQBoolean)
  140.         report_it = *(Boolean*)value.addr ? Report : Ignore;
  141.         else if (rep_type == _XtQString) {
  142.         XrmValue toVal;
  143.         Boolean report;
  144.         toVal.addr = (XPointer)&report;
  145.         toVal.size = sizeof(Boolean);
  146.         if (XtCallConverter(dpy, XtCvtStringToBoolean, (XrmValuePtr)NULL,
  147.                     (Cardinal)0, &value, &toVal,
  148.                     (XtCacheRef*)NULL))
  149.             report_it = report ? Report : Ignore;
  150.         }
  151.         else report_it = Report;
  152.     }
  153.     else report_it = Report;
  154.     }
  155.  
  156.     if (report_it == Report) {
  157. #endif /* ifndef NO_MIT_HACKS */
  158.     String params[2];
  159.     Cardinal num_params = 2;
  160.     params[0] = (String)from;
  161.     params[1] = (String)toType;
  162.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  163.            XtNconversionError,"string",XtCXtToolkitError,
  164.            "Cannot convert string \"%s\" to type %s",
  165.             params,&num_params);
  166. #ifndef NO_MIT_HACKS    
  167.     }
  168. #endif /* ifndef NO_MIT_HACKS */
  169. }
  170.  
  171. #if NeedFunctionPrototypes
  172. void XtStringConversionWarning(
  173.     _Xconst char* from,
  174.     _Xconst char* toType
  175.     )
  176. #else
  177. void XtStringConversionWarning(from, toType)
  178.     String from, toType;
  179. #endif
  180. {
  181.     String params[2];
  182.     Cardinal num_params = 2;
  183.     params[0] = (String)from;
  184.     params[1] = (String)toType;
  185.     XtWarningMsg(XtNconversionError,"string",XtCXtToolkitError,
  186.            "Cannot convert string \"%s\" to type %s",
  187.             params,&num_params);
  188. }
  189.  
  190. static int CompareISOLatin1();
  191.  
  192.  
  193. static Boolean IsInteger(string, value)
  194.     String string;
  195.     int *value;
  196. {
  197.     Boolean foundDigit = False;
  198.     Boolean isNegative = False;
  199.     Boolean isPositive = False;
  200.     int val = 0;
  201.     char ch;
  202.     /* skip leading whitespace */
  203.     while ((ch = *string) == ' ' || ch == '\t') string++;
  204.     while (ch = *string++) {
  205.     if (ch >= '0' && ch <= '9') {
  206.         val *= 10;
  207.         val += ch - '0';
  208.         foundDigit = True;
  209.         continue;
  210.     }
  211.     if (ch == ' ' || ch == '\t') {
  212.         if (!foundDigit) return False;
  213.         /* make sure only trailing whitespace */
  214.         while (ch = *string++) {
  215.         if (ch != ' ' && ch != '\t')
  216.             return False;
  217.         }
  218.         break;
  219.     }
  220.     if (ch == '-' && !foundDigit && !isNegative && !isPositive) {
  221.         isNegative = True;
  222.         continue;
  223.     }
  224.     if (ch == '+' && !foundDigit && !isNegative && !isPositive) {
  225.         isPositive = True;
  226.         continue;
  227.     }
  228.     return False;
  229.     }
  230.     if (ch == '\0') {
  231.     if (isNegative)
  232.         *value = -val;
  233.     else
  234.         *value = val;
  235.     return True;
  236.     }
  237.     return False;
  238. }
  239.  
  240.  
  241. /*ARGSUSED*/
  242. Boolean XtCvtIntToBoolean(dpy, args, num_args, fromVal, toVal, closure_ret)
  243.     Display*    dpy;
  244.     XrmValuePtr args;
  245.     Cardinal    *num_args;
  246.     XrmValuePtr    fromVal;
  247.     XrmValuePtr    toVal;
  248.     XtPointer    *closure_ret;
  249. {
  250.     if (*num_args != 0)
  251.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  252.           XtNwrongParameters,"cvtIntToBoolean",XtCXtToolkitError,
  253.                   "Integer to Boolean conversion needs no extra arguments",
  254.                    (String *)NULL, (Cardinal *)NULL);
  255.     done(Boolean, (*(int *)fromVal->addr != 0));
  256. }
  257.  
  258.  
  259. /*ARGSUSED*/
  260. Boolean XtCvtIntToShort(dpy, args, num_args, fromVal, toVal, closure_ret)
  261.     Display*    dpy;
  262.     XrmValuePtr args;
  263.     Cardinal    *num_args;
  264.     XrmValuePtr    fromVal;
  265.     XrmValuePtr    toVal;
  266.     XtPointer    *closure_ret;
  267. {
  268.     if (*num_args != 0)
  269.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  270.           XtNwrongParameters,"cvtIntToShort",XtCXtToolkitError,
  271.                   "Integer to Short conversion needs no extra arguments",
  272.                    (String *)NULL, (Cardinal *)NULL);
  273.     done(short, (*(int *)fromVal->addr));
  274. }
  275.  
  276.  
  277. /*ARGSUSED*/
  278. Boolean XtCvtStringToBoolean(dpy, args, num_args, fromVal, toVal, closure_ret)
  279.     Display*    dpy;
  280.     XrmValuePtr args;
  281.     Cardinal    *num_args;
  282.     XrmValuePtr    fromVal;
  283.     XrmValuePtr    toVal;
  284.     XtPointer    *closure_ret;
  285. {
  286.     String str = (String)fromVal->addr;
  287.     if (*num_args != 0)
  288.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  289.           XtNwrongParameters,"cvtStringToBoolean",XtCXtToolkitError,
  290.                   "String to Boolean conversion needs no extra arguments",
  291.                    (String *)NULL, (Cardinal *)NULL);
  292.  
  293.     if (   (CompareISOLatin1(str, "true") == 0)
  294.     || (CompareISOLatin1(str, "yes") == 0)
  295.     || (CompareISOLatin1(str, "on") == 0)
  296.     || (CompareISOLatin1(str, "1") == 0))    done( Boolean, True );
  297.  
  298.     if (   (CompareISOLatin1(str, "false") == 0)
  299.     || (CompareISOLatin1(str, "no") == 0)
  300.     || (CompareISOLatin1(str, "off") == 0)
  301.     || (CompareISOLatin1(str, "0") == 0))    done( Boolean, False );
  302.  
  303.     XtDisplayStringConversionWarning(dpy, str, XtRBoolean);
  304.     return False;
  305. }
  306.  
  307.  
  308. /*ARGSUSED*/
  309. Boolean XtCvtIntToBool(dpy, args, num_args, fromVal, toVal, closure_ret)
  310.     Display*    dpy;
  311.     XrmValuePtr args;
  312.     Cardinal    *num_args;
  313.     XrmValuePtr    fromVal;
  314.     XrmValuePtr    toVal;
  315.     XtPointer    *closure_ret;
  316. {
  317.     if (*num_args != 0)
  318.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  319.           XtNwrongParameters,"cvtIntToBool",XtCXtToolkitError,
  320.                   "Integer to Bool conversion needs no extra arguments",
  321.                    (String *)NULL, (Cardinal *)NULL);
  322.     done(Bool, (*(int *)fromVal->addr != 0));
  323. }
  324.  
  325.  
  326. /*ARGSUSED*/
  327. Boolean XtCvtStringToBool(dpy, args, num_args, fromVal, toVal, closure_ret)
  328.     Display*    dpy;
  329.     XrmValuePtr args;
  330.     Cardinal    *num_args;
  331.     XrmValuePtr    fromVal;
  332.     XrmValuePtr    toVal;
  333.     XtPointer    *closure_ret;
  334. {
  335.     String str = (String)fromVal->addr;
  336.     if (*num_args != 0)
  337.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  338.         XtNwrongParameters,"cvtStringToBool",
  339.         XtCXtToolkitError,
  340.                  "String to Bool conversion needs no extra arguments",
  341.                   (String *)NULL, (Cardinal *)NULL);
  342.  
  343.     if (   (CompareISOLatin1(str, "true") == 0)
  344.     || (CompareISOLatin1(str, "yes") == 0)
  345.     || (CompareISOLatin1(str, "on") == 0)
  346.     || (CompareISOLatin1(str, "1") == 0))    done( Bool, True );
  347.  
  348.     if (   (CompareISOLatin1(str, "false") == 0)
  349.     || (CompareISOLatin1(str, "no") == 0)
  350.     || (CompareISOLatin1(str, "off") == 0)
  351.     || (CompareISOLatin1(str, "0") == 0))    done( Bool, False );
  352.  
  353.     XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRBool);
  354.     return False;
  355. }
  356.  
  357. XtConvertArgRec Const colorConvertArgs[] = {
  358.     {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
  359.      sizeof(Screen *)},
  360.     {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
  361.      sizeof(Colormap)}
  362. };
  363.  
  364.  
  365. /* ARGSUSED */
  366. Boolean XtCvtIntToColor(dpy, args, num_args, fromVal, toVal, closure_ret)
  367.     Display*    dpy;
  368.     XrmValuePtr args;
  369.     Cardinal    *num_args;
  370.     XrmValuePtr    fromVal;
  371.     XrmValuePtr    toVal;
  372.     XtPointer    *closure_ret;
  373. {    
  374.     XColor    c;
  375.     Screen    *screen;
  376.     Colormap    colormap;
  377.  
  378.     if (*num_args != 2) {
  379.       XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  380.      XtNwrongParameters,"cvtIntOrPixelToXColor",XtCXtToolkitError,
  381.          "Pixel to color conversion needs screen and colormap arguments",
  382.           (String *)NULL, (Cardinal *)NULL);
  383.       return False;
  384.     }
  385.     screen = *((Screen **) args[0].addr);
  386.     colormap = *((Colormap *) args[1].addr);
  387.     c.pixel = *(int *)fromVal->addr;
  388.  
  389.     XQueryColor(DisplayOfScreen(screen), colormap, &c);
  390.     done(XColor, c);
  391. }
  392.  
  393.  
  394. Boolean XtCvtStringToPixel(dpy, args, num_args, fromVal, toVal, closure_ret)
  395.     Display*    dpy;
  396.     XrmValuePtr args;
  397.     Cardinal    *num_args;
  398.     XrmValuePtr    fromVal;
  399.     XrmValuePtr    toVal;
  400.     XtPointer    *closure_ret;
  401. {
  402.     String        str = (String)fromVal->addr;
  403.     XColor        screenColor;
  404.     XColor        exactColor;
  405.     Screen        *screen;
  406.     XtPerDisplay    pd = _XtGetPerDisplay(dpy);
  407.     Colormap        colormap;
  408.     Status        status;
  409.     String          params[1];
  410.     Cardinal        num_params=1;
  411.  
  412.     if (*num_args != 2) {
  413.      XtAppWarningMsg(pd->appContext, XtNwrongParameters, "cvtStringToPixel",
  414.              XtCXtToolkitError,
  415.     "String to pixel conversion needs screen and colormap arguments",
  416.         (String *)NULL, (Cardinal *)NULL);
  417.      return False;
  418.     }
  419.  
  420.     screen = *((Screen **) args[0].addr);
  421.     colormap = *((Colormap *) args[1].addr);
  422.  
  423.     if (CompareISOLatin1(str, XtDefaultBackground) == 0) {
  424.     *closure_ret = False;
  425.     if (pd->rv) done(Pixel, BlackPixelOfScreen(screen))
  426.     else        done(Pixel, WhitePixelOfScreen(screen));
  427.     }
  428.     if (CompareISOLatin1(str, XtDefaultForeground) == 0) {
  429.     *closure_ret = False;
  430.     if (pd->rv) done(Pixel, WhitePixelOfScreen(screen))
  431.         else        done(Pixel, BlackPixelOfScreen(screen));
  432.     }
  433.  
  434.     status = XAllocNamedColor(DisplayOfScreen(screen), colormap,
  435.                   (char*)str, &screenColor, &exactColor);
  436.     if (status == 0) {
  437.     String msg, type;
  438.     params[0] = str;
  439.     /* Server returns a specific error code but Xlib discards it.  Ugh */
  440.     if (XLookupColor(DisplayOfScreen(screen), colormap, (char*)str,
  441.              &exactColor, &screenColor)) {
  442.         type = "noColormap";
  443.         msg = "Cannot allocate colormap entry for \"%s\"";
  444.     }
  445.     else {
  446.         type = "badValue";
  447.         msg = "Color name \"%s\" is not defined";
  448.     }
  449.  
  450.     XtAppWarningMsg(pd->appContext, type, "cvtStringToPixel",
  451.             XtCXtToolkitError, msg, params, &num_params);
  452.     *closure_ret = False;
  453.     return False;
  454.     } else {
  455.     *closure_ret = (char*)True;
  456.         done(Pixel, screenColor.pixel);
  457.     }
  458. }
  459.  
  460. /* ARGSUSED */
  461. static void FreePixel(app, toVal, closure, args, num_args)
  462.     XtAppContext app;
  463.     XrmValuePtr    toVal;
  464.     XtPointer    closure;
  465.     XrmValuePtr    args;
  466.     Cardinal    *num_args;
  467. {
  468.     Screen        *screen;
  469.     Colormap        colormap;
  470.  
  471.     if (*num_args != 2) {
  472.      XtAppWarningMsg(app, XtNwrongParameters,"freePixel",XtCXtToolkitError,
  473.     "Freeing a pixel requires screen and colormap arguments",
  474.         (String *)NULL, (Cardinal *)NULL);
  475.      return;
  476.     }
  477.  
  478.     screen = *((Screen **) args[0].addr);
  479.     colormap = *((Colormap *) args[1].addr);
  480.  
  481.     if (closure) {
  482.     XFreeColors( DisplayOfScreen(screen), colormap,
  483.              (unsigned long*)toVal->addr, 1, (unsigned long)0
  484.             );
  485.     }
  486. }
  487.  
  488.  
  489. /* no longer used by Xt, but it's in the spec */
  490. XtConvertArgRec Const screenConvertArg[] = {
  491.     {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
  492.      sizeof(Screen *)}
  493. };
  494.  
  495. /*ARGSUSED*/
  496. static void FetchDisplayArg(widget, size, value)
  497.     Widget widget;
  498.     Cardinal *size;
  499.     XrmValue* value;
  500. {
  501.     if (widget == NULL)
  502.     XtErrorMsg("missingWidget", "fetchDisplayArg", XtCXtToolkitError,
  503.            "FetchDisplayArg called without a widget to reference",
  504.            (String*)NULL, (Cardinal*)NULL);
  505.         /* can't return any useful Display and caller will de-ref NULL,
  506.        so aborting is the only useful option */
  507.  
  508.     value->size = sizeof(Display*);
  509.     value->addr = (XPointer)&DisplayOfScreen(XtScreenOfObject(widget));
  510. }
  511.  
  512. static XtConvertArgRec Const displayConvertArg[] = {
  513.     {XtProcedureArg, (XtPointer)FetchDisplayArg, 0},
  514. };
  515.  
  516. /*ARGSUSED*/
  517. Boolean XtCvtStringToCursor(dpy, args, num_args, fromVal, toVal, closure_ret)
  518.     Display*    dpy;
  519.     XrmValuePtr args;
  520.     Cardinal    *num_args;
  521.     XrmValuePtr    fromVal;
  522.     XrmValuePtr    toVal;
  523.  
  524.     XtPointer    *closure_ret;
  525. {
  526.     static Const struct _CursorName {
  527.     Const char    *name;
  528.     unsigned int    shape;
  529.     } cursor_names[] = {
  530.             {"X_cursor",        XC_X_cursor},
  531.             {"arrow",        XC_arrow},
  532.             {"based_arrow_down",    XC_based_arrow_down},
  533.             {"based_arrow_up",    XC_based_arrow_up},
  534.             {"boat",        XC_boat},
  535.             {"bogosity",        XC_bogosity},
  536.             {"bottom_left_corner",    XC_bottom_left_corner},
  537.             {"bottom_right_corner",    XC_bottom_right_corner},
  538.             {"bottom_side",        XC_bottom_side},
  539.             {"bottom_tee",        XC_bottom_tee},
  540.             {"box_spiral",        XC_box_spiral},
  541.             {"center_ptr",        XC_center_ptr},
  542.             {"circle",        XC_circle},
  543.             {"clock",        XC_clock},
  544.             {"coffee_mug",        XC_coffee_mug},
  545.             {"cross",        XC_cross},
  546.             {"cross_reverse",    XC_cross_reverse},
  547.             {"crosshair",        XC_crosshair},
  548.             {"diamond_cross",    XC_diamond_cross},
  549.             {"dot",            XC_dot},
  550.             {"dotbox",        XC_dotbox},
  551.             {"double_arrow",    XC_double_arrow},
  552.             {"draft_large",        XC_draft_large},
  553.             {"draft_small",        XC_draft_small},
  554.             {"draped_box",        XC_draped_box},
  555.             {"exchange",        XC_exchange},
  556.             {"fleur",        XC_fleur},
  557.             {"gobbler",        XC_gobbler},
  558.             {"gumby",        XC_gumby},
  559.             {"hand1",        XC_hand1},
  560.             {"hand2",        XC_hand2},
  561.             {"heart",        XC_heart},
  562.             {"icon",        XC_icon},
  563.             {"iron_cross",        XC_iron_cross},
  564.             {"left_ptr",        XC_left_ptr},
  565.             {"left_side",        XC_left_side},
  566.             {"left_tee",        XC_left_tee},
  567.             {"leftbutton",        XC_leftbutton},
  568.             {"ll_angle",        XC_ll_angle},
  569.             {"lr_angle",        XC_lr_angle},
  570.             {"man",            XC_man},
  571.             {"middlebutton",    XC_middlebutton},
  572.             {"mouse",        XC_mouse},
  573.             {"pencil",        XC_pencil},
  574.             {"pirate",        XC_pirate},
  575.             {"plus",        XC_plus},
  576.             {"question_arrow",    XC_question_arrow},
  577.             {"right_ptr",        XC_right_ptr},
  578.             {"right_side",        XC_right_side},
  579.             {"right_tee",        XC_right_tee},
  580.             {"rightbutton",        XC_rightbutton},
  581.             {"rtl_logo",        XC_rtl_logo},
  582.             {"sailboat",        XC_sailboat},
  583.             {"sb_down_arrow",    XC_sb_down_arrow},
  584.             {"sb_h_double_arrow",    XC_sb_h_double_arrow},
  585.             {"sb_left_arrow",    XC_sb_left_arrow},
  586.             {"sb_right_arrow",    XC_sb_right_arrow},
  587.             {"sb_up_arrow",        XC_sb_up_arrow},
  588.             {"sb_v_double_arrow",    XC_sb_v_double_arrow},
  589.             {"shuttle",        XC_shuttle},
  590.             {"sizing",        XC_sizing},
  591.             {"spider",        XC_spider},
  592.             {"spraycan",        XC_spraycan},
  593.             {"star",        XC_star},
  594.             {"target",        XC_target},
  595.             {"tcross",        XC_tcross},
  596.             {"top_left_arrow",    XC_top_left_arrow},
  597.             {"top_left_corner",    XC_top_left_corner},
  598.             {"top_right_corner",    XC_top_right_corner},
  599.             {"top_side",        XC_top_side},
  600.             {"top_tee",        XC_top_tee},
  601.             {"trek",        XC_trek},
  602.             {"ul_angle",        XC_ul_angle},
  603.             {"umbrella",        XC_umbrella},
  604.             {"ur_angle",        XC_ur_angle},
  605.             {"watch",        XC_watch},
  606.             {"xterm",        XC_xterm},
  607.     };
  608.     Const struct _CursorName *nP;
  609.     char *name = (char *)fromVal->addr;
  610.     register int i;
  611.  
  612.     if (*num_args != 1) {
  613.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  614.          XtNwrongParameters,"cvtStringToCursor",XtCXtToolkitError,
  615.              "String to cursor conversion needs display argument",
  616.               (String *)NULL, (Cardinal *)NULL);
  617.     return False;
  618.     }
  619.  
  620.     for (i=0, nP=cursor_names; i < XtNumber(cursor_names); i++, nP++ ) {
  621.     if (strcmp(name, nP->name) == 0) {
  622.         Display *display = *(Display**)args[0].addr;
  623.         Cursor cursor = XCreateFontCursor(display, nP->shape );
  624.         done(Cursor, cursor);
  625.     }
  626.     }
  627.     XtDisplayStringConversionWarning(dpy, name, XtRCursor);
  628.     return False;
  629. }
  630.  
  631. /* ARGSUSED */
  632. static void FreeCursor(app, toVal, closure, args, num_args)
  633.     XtAppContext app;
  634.     XrmValuePtr    toVal;
  635.     XtPointer    closure;    /* unused */
  636.     XrmValuePtr    args;
  637.     Cardinal    *num_args;
  638. {
  639.     Display*    display;
  640.  
  641.     if (*num_args != 1) {
  642.      XtAppWarningMsg(app,
  643.          XtNwrongParameters,"freeCursor",XtCXtToolkitError,
  644.              "Free Cursor requires display argument",
  645.               (String *)NULL, (Cardinal *)NULL);
  646.      return;
  647.     }
  648.  
  649.     display = *(Display**)args[0].addr;
  650.     XFreeCursor( display, *(Cursor*)toVal->addr );
  651. }
  652.  
  653. /*ARGSUSED*/
  654. Boolean XtCvtStringToDisplay(dpy, args, num_args, fromVal, toVal, closure_ret)
  655.     Display*    dpy;
  656.     XrmValuePtr args;
  657.     Cardinal    *num_args;
  658.     XrmValuePtr    fromVal;
  659.     XrmValuePtr    toVal;
  660.     XtPointer    *closure_ret;
  661. {
  662.     Display    *d;
  663.  
  664.     if (*num_args != 0)
  665.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  666.           XtNwrongParameters,"cvtStringToDisplay",XtCXtToolkitError,
  667.                   "String to Display conversion needs no extra arguments",
  668.                    (String *)NULL, (Cardinal *)NULL);
  669.  
  670.     d = XOpenDisplay((char *)fromVal->addr);
  671.     if (d != NULL)
  672.     done(Display*, d);
  673.  
  674.     XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRDisplay);
  675.     return False;
  676. }
  677.  
  678.  
  679. /*ARGSUSED*/
  680. Boolean XtCvtStringToFile(dpy, args, num_args, fromVal, toVal, closure_ret)
  681.     Display*    dpy;
  682.     XrmValuePtr args;
  683.     Cardinal    *num_args;
  684.     XrmValuePtr    fromVal;
  685.     XrmValuePtr    toVal;
  686.     XtPointer    *closure_ret;
  687. {
  688.     FILE *f;
  689.  
  690.     if (*num_args != 0)
  691.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  692.          XtNwrongParameters,"cvtStringToFile",XtCXtToolkitError,
  693.                  "String to File conversion needs no extra arguments",
  694.                  (String *) NULL, (Cardinal *)NULL);
  695.  
  696.     f = fopen((char *)fromVal->addr, "r");
  697.     if (f != NULL)
  698.     done(FILE*, f);
  699.  
  700.     XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRFile);
  701.     return False;
  702. }
  703.  
  704. /* ARGSUSED */
  705. static void FreeFile(app, toVal, closure, args, num_args)
  706.     XtAppContext app;
  707.     XrmValuePtr    toVal;
  708.     XtPointer    closure;    /* unused */
  709.     XrmValuePtr    args;        /* unused */
  710.     Cardinal    *num_args;
  711. {
  712.     if (*num_args != 0)
  713.     XtAppWarningMsg(app,
  714.          XtNwrongParameters,"freeFile",XtCXtToolkitError,
  715.                  "Free File requires no extra arguments",
  716.                  (String *) NULL, (Cardinal *)NULL);
  717.  
  718.     fclose( *(FILE**)toVal->addr );
  719. }
  720.  
  721. /*ARGSUSED*/
  722. Boolean XtCvtIntToFloat(dpy, args, num_args, fromVal, toVal, closure_ret)
  723.     Display*    dpy;
  724.     XrmValuePtr args;
  725.     Cardinal    *num_args;
  726.     XrmValuePtr    fromVal;
  727.     XrmValuePtr    toVal;
  728.     XtPointer    *closure_ret;
  729. {
  730.     if (*num_args != 0)
  731.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  732.           XtNwrongParameters,"cvtIntToFloat",XtCXtToolkitError,
  733.                   "Integer to Float conversion needs no extra arguments",
  734.                    (String *)NULL, (Cardinal *)NULL);
  735.     done(float, (*(int *)fromVal->addr));
  736. }
  737.  
  738. /*ARGSUSED*/
  739. Boolean XtCvtStringToFloat(dpy, args, num_args, fromVal, toVal, closure_ret)
  740.     Display*    dpy;
  741.     XrmValuePtr args;
  742.     Cardinal    *num_args;
  743.     XrmValuePtr    fromVal;
  744.     XrmValuePtr    toVal;
  745.     XtPointer    *closure_ret;
  746. {
  747.     float f;
  748.     extern double atof();
  749.  
  750.     if (*num_args != 0)
  751.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  752.          XtNwrongParameters,"cvtStringToFloat",XtCXtToolkitError,
  753.                  "String to Float conversion needs no extra arguments",
  754.                  (String *) NULL, (Cardinal *)NULL);
  755.  
  756.     f = atof(fromVal->addr);
  757.     done(float, f);
  758. }
  759.  
  760. /*ARGSUSED*/
  761. Boolean XtCvtStringToFont(dpy, args, num_args, fromVal, toVal, closure_ret)
  762.     Display*    dpy;
  763.     XrmValuePtr args;
  764.     Cardinal    *num_args;
  765.     XrmValuePtr    fromVal;
  766.     XrmValuePtr    toVal;
  767.     XtPointer    *closure_ret;
  768. {
  769.     Font    f;
  770.     Display*    display;
  771.  
  772.     if (*num_args != 1) {
  773.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  774.          XtNwrongParameters,"cvtStringToFont",XtCXtToolkitError,
  775.              "String to font conversion needs display argument",
  776.               (String *) NULL, (Cardinal *)NULL);
  777.     return False;
  778.     }
  779.  
  780.     display = *(Display**)args[0].addr;
  781.  
  782.     if (CompareISOLatin1((String)fromVal->addr, XtDefaultFont) != 0) {
  783.     f = XLoadFont(display, (char *)fromVal->addr);
  784.     if (f != 0) {
  785.   Done:        done( Font, f );
  786.     }
  787.     XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRFont);
  788.     }
  789.     /* try and get the default font */
  790.  
  791.     {
  792.     XrmName xrm_name[2];
  793.     XrmClass xrm_class[2];
  794.     XrmRepresentation rep_type;
  795.     XrmValue value;
  796.  
  797.     xrm_name[0] = XrmPermStringToQuark ("xtDefaultFont");
  798.     xrm_name[1] = 0;
  799.     xrm_class[0] = XrmPermStringToQuark ("XtDefaultFont");
  800.     xrm_class[1] = 0;
  801.     if (XrmQGetResource(XtDatabase(display), xrm_name, xrm_class, 
  802.                 &rep_type, &value)) {
  803.         if (rep_type == _XtQString) {
  804.         f = XLoadFont(display, (char *)value.addr);
  805.         if (f != 0)
  806.             goto Done;
  807.         else
  808.             XtDisplayStringConversionWarning(dpy, (char *)value.addr,
  809.                              XtRFont);
  810.         } else if (rep_type == XtQFont) {
  811.         f = *(Font*)value.addr;
  812.         goto Done;
  813.         } else if (rep_type == XtQFontStruct) {
  814.         f = ((XFontStruct*)value.addr)->fid;
  815.         goto Done;
  816.         }
  817.     }
  818.     }
  819.     /* Should really do XListFonts, but most servers support this */
  820.     f = XLoadFont(display, "-*-*-*-R-*-*-*-120-*-*-*-*-ISO8859-1");
  821.     if (f != 0)
  822.     goto Done;
  823.  
  824.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  825.             "noFont","cvtStringToFont",XtCXtToolkitError,
  826.             "Unable to load any useable ISO8859-1 font",
  827.             (String *) NULL, (Cardinal *)NULL);
  828.  
  829.     return False;
  830. }
  831.  
  832. /* ARGSUSED */
  833. static void FreeFont(app, toVal, closure, args, num_args)
  834.     XtAppContext app;
  835.     XrmValuePtr    toVal;
  836.     XtPointer    closure;    /* unused */
  837.     XrmValuePtr    args;
  838.     Cardinal    *num_args;
  839. {
  840.     Display *display;
  841.     if (*num_args != 1) {
  842.     XtAppWarningMsg(app,
  843.          XtNwrongParameters,"freeFont",XtCXtToolkitError,
  844.              "Free Font needs display argument",
  845.               (String *) NULL, (Cardinal *)NULL);
  846.     return;
  847.     }
  848.  
  849.     display = *(Display**)args[0].addr;
  850.     XUnloadFont( display, *(Font*)toVal->addr );
  851. }
  852.  
  853. /*ARGSUSED*/
  854. Boolean XtCvtIntToFont(dpy, args, num_args, fromVal, toVal, closure_ret)
  855.     Display*    dpy;
  856.     XrmValuePtr args;
  857.     Cardinal    *num_args;
  858.     XrmValuePtr    fromVal;
  859.     XrmValuePtr    toVal;
  860.     XtPointer    *closure_ret;
  861. {
  862.     if (*num_args != 0)
  863.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  864.        XtNwrongParameters,"cvtIntToFont",XtCXtToolkitError,
  865.            "Integer to Font conversion needs no extra arguments",
  866.             (String *) NULL, (Cardinal *)NULL);
  867.     done(Font, *(int*)fromVal->addr);
  868. }
  869.  
  870. /*ARGSUSED*/
  871. Boolean XtCvtStringToFontSet(dpy, args, num_args, fromVal, toVal, closure_ret)
  872.     Display*    dpy;
  873.     XrmValuePtr args;
  874.     Cardinal    *num_args;
  875.     XrmValuePtr fromVal;
  876.     XrmValuePtr toVal;
  877.     XtPointer   *closure_ret;
  878. {
  879.     XFontSet  f;
  880.     Display*  display;
  881.     char**    missing_charset_list;
  882.     int       missing_charset_count;
  883.     char*     def_string;
  884.  
  885.     if (*num_args != 2) {
  886.       XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  887.            XtNwrongParameters,"cvtStringToFontSet",XtCXtToolkitError,
  888.              "String to FontSet conversion needs display and locale arguments",
  889.               (String *) NULL, (Cardinal *)NULL);
  890.       return False;
  891.     }
  892.  
  893.     display = *(Display**)args[0].addr;
  894.  
  895.     if (CompareISOLatin1((String)fromVal->addr, XtDefaultFontSet) != 0) {
  896.       f = XCreateFontSet(display, (char *)fromVal->addr,
  897.               &missing_charset_list, &missing_charset_count, &def_string);
  898.         /* Free any returned missing charset list */
  899.       if (missing_charset_count) {
  900.           XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  901.                  XtNmissingCharsetList,"cvtStringToFontSet",XtCXtToolkitError,
  902.                  "Missing charsets in String to FontSet conversion",
  903.                  (String *) NULL, (Cardinal *)NULL);
  904.             XFreeStringList(missing_charset_list);
  905.       }
  906.       if (f != NULL) {
  907.   Done:           done( XFontSet, f );
  908.       }
  909.       XtDisplayStringConversionWarning(dpy, (char *)fromVal->addr, XtRFontSet);
  910.     }
  911.     /* try and get the default fontset */
  912.  
  913.     {
  914.       XrmName xrm_name[2];
  915.       XrmClass xrm_class[2];
  916.       XrmRepresentation rep_type;
  917.       XrmValue value;
  918.  
  919.       xrm_name[0] = XrmPermStringToQuark ("xtDefaultFontSet");
  920.       xrm_name[1] = 0;
  921.       xrm_class[0] = XrmPermStringToQuark ("XtDefaultFontSet");
  922.       xrm_class[1] = 0;
  923.       if (XrmQGetResource(XtDatabase(display), xrm_name, xrm_class, 
  924.                           &rep_type, &value)) {
  925.           if (rep_type == _XtQString) {
  926.               f = XCreateFontSet(display, (char *)value.addr,
  927.                  &missing_charset_list, &missing_charset_count,
  928.                  &def_string);
  929.                 /* Free any returned missing charset list */
  930.               if (missing_charset_count) {
  931.                   XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  932.              XtNmissingCharsetList,"cvtStringToFontSet",
  933.              XtCXtToolkitError,
  934.              "Missing charsets in String to FontSet conversion",
  935.                          (String *) NULL, (Cardinal *)NULL);
  936.           XFreeStringList(missing_charset_list);
  937.               }
  938.               if (f != NULL)
  939.                   goto Done;
  940.               else
  941.                   XtDisplayStringConversionWarning(dpy, (char *)value.addr,
  942.                                                    XtRFontSet);
  943.           } else if (rep_type == XtQFontSet) {
  944.               f = *(XFontSet*)value.addr;
  945.               goto Done;
  946.           }
  947.       }
  948.   }
  949.  
  950.     /* Should really do XListFonts, but most servers support this */
  951.     f = XCreateFontSet(display, "-*-*-*-R-*-*-*-120-*-*-*-*",
  952.           &missing_charset_list, &missing_charset_count, &def_string);
  953.     /* Free any returned missing charset list */
  954.     if (missing_charset_count) {
  955.       XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  956.              XtNmissingCharsetList,"cvtStringToFontSet",XtCXtToolkitError,
  957.              "Missing charsets in String to FontSet conversion",
  958.              (String *) NULL, (Cardinal *)NULL);
  959.         XFreeStringList(missing_charset_list);
  960.     }
  961.     if (f != NULL)
  962.       goto Done;
  963.  
  964.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  965.            "noFont","cvtStringToFontSet",XtCXtToolkitError,
  966.              "Unable to load any useable fontset",
  967.               (String *) NULL, (Cardinal *)NULL);
  968.     
  969.     return False;
  970. }
  971.  
  972. /*ARGSUSED*/
  973. static void FreeFontSet(app, toVal, closure, args, num_args)
  974.     XtAppContext    app;
  975.     XrmValuePtr        toVal;
  976.     XtPointer        closure;        /* unused */
  977.     XrmValuePtr        args;
  978.     Cardinal        *num_args;
  979. {
  980.     Display *display;
  981.     if (*num_args != 2) {
  982.       XtAppWarningMsg(app,
  983.            XtNwrongParameters,"freeFontSet",XtCXtToolkitError,
  984.              "FreeFontSet needs display and locale arguments",
  985.               (String *) NULL, (Cardinal *)NULL);
  986.       return;
  987.     }
  988.  
  989.     display = *(Display**)args[0].addr;
  990.     XFreeFontSet( display, *(XFontSet*)toVal->addr );
  991. }
  992.  
  993. /*ARGSUSED*/
  994. static void FetchLocaleArg(widget, size, value )
  995.     Widget widget;    /* unused */
  996.     Cardinal *size;    /* unused */
  997.     XrmValue *value;
  998. {
  999.     static XrmString locale;
  1000.  
  1001.     locale = XrmQuarkToString(XrmStringToQuark
  1002.                   (setlocale(LC_CTYPE, (char*)NULL)));
  1003.     value->size = sizeof(XrmString);
  1004.     value->addr = (XPointer)&locale;
  1005. }
  1006.  
  1007. static XtConvertArgRec Const localeDisplayConvertArgs[] = {
  1008.     {XtProcedureArg, (XtPointer)FetchDisplayArg, 0},
  1009.     {XtProcedureArg, (XtPointer)FetchLocaleArg, 0},
  1010. };
  1011.  
  1012.  
  1013. /*ARGSUSED*/
  1014. Boolean
  1015. XtCvtStringToFontStruct(dpy, args, num_args, fromVal, toVal, closure_ret)
  1016.     Display*    dpy;
  1017.     XrmValuePtr args;
  1018.     Cardinal    *num_args;
  1019.     XrmValuePtr    fromVal;
  1020.     XrmValuePtr    toVal;
  1021.     XtPointer    *closure_ret;
  1022. {
  1023.     XFontStruct        *f;
  1024.     Display*    display;
  1025.  
  1026.     if (*num_args != 1) {
  1027.      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1028.          XtNwrongParameters,"cvtStringToFontStruct",XtCXtToolkitError,
  1029.              "String to font conversion needs display argument",
  1030.               (String *) NULL, (Cardinal *)NULL);
  1031.      return False;
  1032.     }
  1033.  
  1034.     display = *(Display**)args[0].addr;
  1035.  
  1036.     if (CompareISOLatin1((String)fromVal->addr, XtDefaultFont) != 0) {
  1037.     f = XLoadQueryFont(display, (char *)fromVal->addr);
  1038.     if (f != NULL) {
  1039.   Done:        done( XFontStruct*, f);
  1040.     }
  1041.  
  1042.     XtDisplayStringConversionWarning(dpy, (char*)fromVal->addr,
  1043.                      XtRFontStruct);
  1044.     }
  1045.  
  1046.     /* try and get the default font */
  1047.  
  1048.     {
  1049.     XrmName xrm_name[2];
  1050.     XrmClass xrm_class[2];
  1051.     XrmRepresentation rep_type;
  1052.     XrmValue value;
  1053.  
  1054.     xrm_name[0] = XrmPermStringToQuark ("xtDefaultFont");
  1055.     xrm_name[1] = 0;
  1056.     xrm_class[0] = XrmPermStringToQuark ("XtDefaultFont");
  1057.     xrm_class[1] = 0;
  1058.     if (XrmQGetResource(XtDatabase(display), xrm_name, xrm_class, 
  1059.                 &rep_type, &value)) {
  1060.         if (rep_type == _XtQString) {
  1061.         f = XLoadQueryFont(display, (char*)value.addr);
  1062.         if (f != NULL)
  1063.             goto Done;
  1064.         else
  1065.             XtDisplayStringConversionWarning(dpy, (char*)value.addr,
  1066.                              XtRFontStruct);
  1067.         } else if (rep_type == XtQFont) {
  1068.         f = XQueryFont(display, *(Font*)value.addr );
  1069.         if (f != NULL) goto Done;
  1070.         } else if (rep_type == XtQFontStruct) {
  1071.         f = (XFontStruct*)value.addr;
  1072.         goto Done;
  1073.         }
  1074.     }
  1075.     }
  1076.     /* Should really do XListFonts, but most servers support this */
  1077.     f = XLoadQueryFont(display, "-*-*-*-R-*-*-*-120-*-*-*-*-ISO8859-1");
  1078.     if (f != NULL)
  1079.     goto Done;
  1080.  
  1081.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1082.          "noFont","cvtStringToFontStruct",XtCXtToolkitError,
  1083.              "Unable to load any useable ISO8859-1 font",
  1084.               (String *) NULL, (Cardinal *)NULL);
  1085.     
  1086.     return False;
  1087. }
  1088.  
  1089. /* ARGSUSED */
  1090. static void FreeFontStruct(app, toVal, closure, args, num_args)
  1091.     XtAppContext app;
  1092.     XrmValuePtr    toVal;
  1093.     XtPointer    closure;    /* unused */
  1094.     XrmValuePtr    args;
  1095.     Cardinal    *num_args;
  1096. {
  1097.     Display *display;
  1098.     if (*num_args != 1) {
  1099.      XtAppWarningMsg(app,
  1100.          XtNwrongParameters,"freeFontStruct",XtCXtToolkitError,
  1101.              "Free FontStruct requires display argument",
  1102.               (String *) NULL, (Cardinal *)NULL);
  1103.      return;
  1104.     }
  1105.  
  1106.     display = *(Display**)args[0].addr;
  1107.     XFreeFont( display, *(XFontStruct**)toVal->addr );
  1108. }
  1109.  
  1110. /*ARGSUSED*/
  1111. Boolean XtCvtStringToInt(dpy, args, num_args, fromVal, toVal, closure_ret)
  1112.     Display*    dpy;
  1113.     XrmValuePtr args;
  1114.     Cardinal    *num_args;
  1115.     XrmValuePtr    fromVal;
  1116.     XrmValuePtr    toVal;
  1117.     XtPointer    *closure_ret;
  1118. {
  1119.     int    i;
  1120.  
  1121.     if (*num_args != 0)
  1122.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1123.           XtNwrongParameters,"cvtStringToInt",XtCXtToolkitError,
  1124.                   "String to Integer conversion needs no extra arguments",
  1125.                   (String *) NULL, (Cardinal *)NULL);
  1126.     if (IsInteger((String)fromVal->addr, &i))
  1127.     done(int, i);
  1128.  
  1129.     XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRInt);
  1130.     return False;
  1131. }
  1132.  
  1133. /*ARGSUSED*/
  1134. Boolean XtCvtStringToShort(dpy, args, num_args, fromVal, toVal, closure_ret)
  1135.     Display*    dpy;
  1136.     XrmValuePtr args;
  1137.     Cardinal    *num_args;
  1138.     XrmValuePtr fromVal;
  1139.     XrmValuePtr toVal;
  1140.     XtPointer    *closure_ret;
  1141. {
  1142.     int i;
  1143.  
  1144.     if (*num_args != 0)
  1145.         XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1146.       XtNwrongParameters,"cvtStringToShort",XtCXtToolkitError,
  1147.           "String to Integer conversion needs no extra arguments",
  1148.            (String *) NULL, (Cardinal *)NULL);
  1149.     if (IsInteger((String)fromVal->addr, &i))
  1150.         done(short, (short)i);
  1151.  
  1152.     XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRShort);
  1153.     return False;
  1154. }
  1155.  
  1156. /*ARGSUSED*/
  1157. Boolean XtCvtStringToDimension(dpy, args, num_args, fromVal, toVal, closure_ret)
  1158.     Display*    dpy;
  1159.     XrmValuePtr args;
  1160.     Cardinal    *num_args;
  1161.     XrmValuePtr fromVal;
  1162.     XrmValuePtr toVal;
  1163.     XtPointer    *closure_ret;
  1164. {
  1165.     int i;
  1166.  
  1167.     if (*num_args != 0)
  1168.         XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1169.       XtNwrongParameters,"cvtStringToDimension",XtCXtToolkitError,
  1170.           "String to Dimension conversion needs no extra arguments",
  1171.            (String *) NULL, (Cardinal *)NULL);
  1172.     if (IsInteger((String)fromVal->addr, &i)) {
  1173.         if ( i < 0 )
  1174.             XtDisplayStringConversionWarning(dpy, (char*)fromVal->addr,
  1175.                          XtRDimension);
  1176.         done(Dimension, (Dimension)i);
  1177.     }
  1178.     XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRDimension);
  1179.     return False;
  1180. }
  1181.  
  1182. /*ARGSUSED*/
  1183. Boolean XtCvtIntToUnsignedChar(dpy, args, num_args, fromVal, toVal, closure_ret)
  1184.     Display*    dpy;
  1185.     XrmValuePtr args;
  1186.     Cardinal    *num_args;
  1187.     XrmValuePtr    fromVal;
  1188.     XrmValuePtr    toVal;
  1189.     XtPointer    *closure_ret;
  1190. {
  1191.     if (*num_args != 0)
  1192.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1193.           XtNwrongParameters,"cvtIntToUnsignedChar",XtCXtToolkitError,
  1194.                   "Integer to UnsignedChar conversion needs no extra arguments",
  1195.                    (String *)NULL, (Cardinal *)NULL);
  1196.     done(unsigned char, (*(int *)fromVal->addr));
  1197. }
  1198.  
  1199.  
  1200. /*ARGSUSED*/
  1201. Boolean XtCvtStringToUnsignedChar(dpy, args, num_args, fromVal, toVal, closure_ret)
  1202.     Display*    dpy;
  1203.     XrmValuePtr args;
  1204.     Cardinal    *num_args;
  1205.     XrmValuePtr fromVal;
  1206.     XrmValuePtr toVal;
  1207.     XtPointer    *closure_ret;
  1208. {
  1209.     int i;
  1210.  
  1211.     if (*num_args != 0)
  1212.         XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1213.           XtNwrongParameters,"cvtStringToUnsignedChar",XtCXtToolkitError,
  1214.                   "String to Integer conversion needs no extra arguments",
  1215.                    (String *) NULL, (Cardinal *)NULL);
  1216.     if (IsInteger((String)fromVal->addr, &i)) {
  1217.         if ( i < 0 || i > 255 )
  1218.             XtDisplayStringConversionWarning(dpy, (char*)fromVal->addr,
  1219.                          XtRUnsignedChar);
  1220.         done(unsigned char, i);
  1221.     }
  1222.     XtDisplayStringConversionWarning(dpy, (char*)fromVal->addr,
  1223.                      XtRUnsignedChar);
  1224.     return False;
  1225. }
  1226.  
  1227.  
  1228. /*ARGSUSED*/
  1229. Boolean XtCvtColorToPixel(dpy, args, num_args, fromVal, toVal, closure_ret)
  1230.     Display*    dpy;
  1231.     XrmValuePtr args;
  1232.     Cardinal    *num_args;
  1233.     XrmValuePtr    fromVal;
  1234.     XrmValuePtr    toVal;
  1235.     XtPointer    *closure_ret;
  1236. {
  1237.     if (*num_args != 0)
  1238.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1239.           XtNwrongParameters,"cvtXColorToPixel",XtCXtToolkitError,
  1240.                   "Color to Pixel conversion needs no extra arguments",
  1241.                    (String *) NULL, (Cardinal *)NULL);
  1242.     done(Pixel, ((XColor *)fromVal->addr)->pixel);
  1243. }
  1244.  
  1245. /*ARGSUSED*/
  1246. Boolean XtCvtIntToPixel(dpy, args, num_args, fromVal, toVal, closure_ret)
  1247.     Display*    dpy;
  1248.     XrmValuePtr args;
  1249.     Cardinal    *num_args;
  1250.     XrmValuePtr    fromVal;
  1251.     XrmValuePtr    toVal;
  1252.     XtPointer    *closure_ret;
  1253. {
  1254.     if (*num_args != 0)
  1255.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1256.           XtNwrongParameters,"cvtIntToPixel",XtCXtToolkitError,
  1257.                   "Integer to Pixel conversion needs no extra arguments",
  1258.                    (String *) NULL, (Cardinal *)NULL);
  1259.     done(Pixel, *(int*)fromVal->addr);
  1260. }
  1261.  
  1262. /*ARGSUSED*/
  1263. Boolean XtCvtIntToPixmap(dpy, args, num_args, fromVal, toVal, closure_ret)
  1264.     Display*    dpy;
  1265.     XrmValuePtr args;
  1266.     Cardinal    *num_args;
  1267.     XrmValuePtr fromVal;
  1268.     XrmValuePtr toVal;
  1269.     XtPointer    *closure_ret;
  1270. {
  1271.     if (*num_args != 0)
  1272.         XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1273.           XtNwrongParameters,"cvtIntToPixmap",XtCXtToolkitError,
  1274.                   "Integer to Pixmap conversion needs no extra arguments",
  1275.                    (String *) NULL, (Cardinal *)NULL);
  1276.     done(Pixmap, *(Pixmap*)fromVal->addr);
  1277. }
  1278.  
  1279. #ifdef STRING_TO_GEOMETRY    /* not in the specification */
  1280. /*ARGSUSED*/
  1281. static Boolean
  1282. CvtStringToGeometry(dpy, args, num_args, fromVal, toVal, closure_ret)
  1283.     Display*    dpy;
  1284.     XrmValuePtr args;
  1285.     Cardinal    *num_args;
  1286.     XrmValuePtr    fromVal;
  1287.     XrmValuePtr    toVal;
  1288.     XtPointer    *closure_ret;
  1289. {
  1290.     if (*num_args != 0)
  1291.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1292.           XtNwrongParameters,"cvtStringToGeometry",XtCXtToolkitError,
  1293.                   "String to Geometry conversion needs no extra arguments",
  1294.                    (String *) NULL, (Cardinal *)NULL);
  1295.     done(String, *(String*)fromVal->addr);
  1296. }
  1297. #endif
  1298.  
  1299. #ifdef MOTIFBC
  1300. void LowerCase(source, dest)
  1301.     register char  *source, *dest;
  1302. {
  1303.     register char ch;
  1304.     int i;
  1305.  
  1306.     for (i = 0; (ch = *source) != 0 && i < 999; source++, dest++, i++) {
  1307.         if ('A' <= ch && ch <= 'Z')
  1308.         *dest = ch - 'A' + 'a';
  1309.     else
  1310.         *dest = ch;
  1311.     }
  1312.     *dest = 0;
  1313. }
  1314. #endif
  1315.  
  1316. static int CompareISOLatin1 (first, second)
  1317.     char *first, *second;
  1318. {
  1319.     register unsigned char *ap, *bp;
  1320.  
  1321.     for (ap = (unsigned char *) first, bp = (unsigned char *) second;
  1322.      *ap && *bp; ap++, bp++) {
  1323.     register unsigned char a, b;
  1324.  
  1325.     if ((a = *ap) != (b = *bp)) {
  1326.         /* try lowercasing and try again */
  1327.  
  1328.         if ((a >= XK_A) && (a <= XK_Z))
  1329.           a += (XK_a - XK_A);
  1330.         else if ((a >= XK_Agrave) && (a <= XK_Odiaeresis))
  1331.           a += (XK_agrave - XK_Agrave);
  1332.         else if ((a >= XK_Ooblique) && (a <= XK_Thorn))
  1333.           a += (XK_oslash - XK_Ooblique);
  1334.  
  1335.         if ((b >= XK_A) && (b <= XK_Z))
  1336.           b += (XK_a - XK_A);
  1337.         else if ((b >= XK_Agrave) && (b <= XK_Odiaeresis))
  1338.           b += (XK_agrave - XK_Agrave);
  1339.         else if ((b >= XK_Ooblique) && (b <= XK_Thorn))
  1340.           b += (XK_oslash - XK_Ooblique);
  1341.  
  1342.         if (a != b) break;
  1343.     }
  1344.     }
  1345.     return (((int) *bp) - ((int) *ap));
  1346. }
  1347.  
  1348.  
  1349. /*ARGSUSED*/
  1350. Boolean 
  1351. XtCvtStringToInitialState(dpy, args, num_args, fromVal, toVal, closure_ret)
  1352.     Display*    dpy;
  1353.     XrmValuePtr args;
  1354.     Cardinal    *num_args;
  1355.     XrmValuePtr    fromVal;
  1356.     XrmValuePtr    toVal;
  1357.     XtPointer    *closure_ret;
  1358. {
  1359.     String str = (String)fromVal->addr;
  1360.     if (*num_args != 0)
  1361.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1362.           XtNwrongParameters,"cvtStringToInitialState",XtCXtToolkitError,
  1363.                   "String to InitialState conversion needs no extra arguments",
  1364.                    (String *) NULL, (Cardinal *)NULL);
  1365.  
  1366.     if (CompareISOLatin1(str, "NormalState") == 0) done(int, NormalState);
  1367.     if (CompareISOLatin1(str, "IconicState") == 0) done(int, IconicState);
  1368.     {
  1369.     int val;
  1370.     if (IsInteger(str, &val)) done( int, val );
  1371.     }
  1372.     XtDisplayStringConversionWarning(dpy, str, XtRInitialState);
  1373.     return False;
  1374. }
  1375.  
  1376. static XtConvertArgRec Const visualConvertArgs[] = {
  1377.     {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
  1378.      sizeof(Screen *)},
  1379.     {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.depth),
  1380.      sizeof(Cardinal)}
  1381. };
  1382.  
  1383. /*ARGSUSED*/
  1384. Boolean XtCvtStringToVisual(dpy, args, num_args, fromVal, toVal, closure_ret)
  1385.     Display*    dpy;
  1386.     XrmValuePtr args;        /* Screen, depth */
  1387.     Cardinal    *num_args;    /* 2 */
  1388.     XrmValuePtr    fromVal;
  1389.     XrmValuePtr    toVal;
  1390.     XtPointer    *closure_ret;    /* unused */
  1391. {
  1392.     String str = (String)fromVal->addr;
  1393.     int vc;
  1394.     XVisualInfo vinfo;
  1395.     if (*num_args != 2) {
  1396.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1397.           XtNwrongParameters,"cvtStringToVisual",XtCXtToolkitError,
  1398.                   "String to Visual conversion needs screen and depth arguments",
  1399.                    (String *) NULL, (Cardinal *)NULL);
  1400.     return False;
  1401.     }
  1402.  
  1403.          if (CompareISOLatin1(str, "StaticGray") == 0)    vc = StaticGray;
  1404.     else if (CompareISOLatin1(str, "StaticColor") == 0)    vc = StaticColor;
  1405.     else if (CompareISOLatin1(str, "TrueColor") == 0)    vc = TrueColor;
  1406.     else if (CompareISOLatin1(str, "GrayScale") == 0)    vc = GrayScale;
  1407.     else if (CompareISOLatin1(str, "PseudoColor") == 0)    vc = PseudoColor;
  1408.     else if (CompareISOLatin1(str, "DirectColor") == 0)    vc = DirectColor;
  1409.     else if (!IsInteger(str, &vc)) {
  1410.     XtDisplayStringConversionWarning(dpy, str, "Visual class name");
  1411.     return False;
  1412.     }
  1413.  
  1414.     if (XMatchVisualInfo( XDisplayOfScreen((Screen*)*(Screen**)args[0].addr),
  1415.              XScreenNumberOfScreen((Screen*)*(Screen**)args[0].addr),
  1416.              (int)*(int*)args[1].addr,
  1417.              vc,
  1418.              &vinfo) ) {
  1419.     done( Visual*, vinfo.visual );
  1420.     }
  1421.     else {
  1422.     String params[2];
  1423.     Cardinal num_params = 2;
  1424.     params[0] = str;
  1425.     params[1] = 
  1426.         DisplayString(XDisplayOfScreen((Screen*)*(Screen**)args[0].addr));
  1427.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1428.           XtNconversionError, "stringToVisual", XtCXtToolkitError,
  1429.                   "Cannot find Visual of class %s for display %s",
  1430.           params, &num_params );
  1431.     return False;
  1432.     }
  1433. }
  1434.  
  1435.  
  1436. /*ARGSUSED*/
  1437. Boolean XtCvtStringToAtom(dpy, args, num_args, fromVal, toVal, closure_ret)
  1438.     Display*    dpy;
  1439.     XrmValuePtr args;
  1440.     Cardinal    *num_args;
  1441.     XrmValuePtr    fromVal;
  1442.     XrmValuePtr    toVal;
  1443.     XtPointer    *closure_ret;
  1444. {
  1445.     Atom atom;
  1446.     if (*num_args != 1) {
  1447.     XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
  1448.           XtNwrongParameters,"cvtStringToAtom",XtCXtToolkitError,
  1449.                   "String to Atom conversion needs Display argument",
  1450.                    (String *) NULL, (Cardinal *)NULL);
  1451.     return False;
  1452.     }
  1453.     
  1454.     atom =  XInternAtom( *(Display**)args->addr, (char*)fromVal->addr, False );
  1455.     done(Atom, atom);
  1456. }
  1457.  
  1458.  
  1459. _XtAddDefaultConverters(table)
  1460.     ConverterTable table;
  1461. {
  1462. #define Add(from, to, proc, convert_args, num_args, cache) \
  1463.     _XtTableAddConverter(table, from, to, proc, \
  1464.         (XtConvertArgList) convert_args, (Cardinal)num_args, \
  1465.         True, cache, (XtDestructor)NULL)
  1466.  
  1467. #define Add2(from, to, proc, convert_args, num_args, cache, destructor) \
  1468.     _XtTableAddConverter(table, from, to, proc, \
  1469.         (XtConvertArgList) convert_args, (Cardinal)num_args, \
  1470.         True, cache, destructor)
  1471.  
  1472.     Add(XtQColor, XtQPixel,       XtCvtColorToPixel,   NULL, 0, XtCacheNone);
  1473.  
  1474.     Add(XtQInt,   XtQBool,      XtCvtIntToBool,      NULL, 0, XtCacheNone);
  1475.     Add(XtQInt,   XtQBoolean,     XtCvtIntToBoolean,   NULL, 0, XtCacheNone);
  1476.     Add(XtQInt,   XtQColor,      XtCvtIntToColor,
  1477.     colorConvertArgs, XtNumber(colorConvertArgs), XtCacheByDisplay);
  1478.     Add(XtQInt,   XtQDimension,   XtCvtIntToShort,     NULL, 0, XtCacheNone);
  1479.     Add(XtQInt,   XtQFloat,       XtCvtIntToFloat,     NULL, 0, XtCacheNone);
  1480.     Add(XtQInt,   XtQFont,        XtCvtIntToFont,      NULL, 0, XtCacheNone);
  1481.     Add(XtQInt,   XtQPixel,       XtCvtIntToPixel,     NULL, 0, XtCacheNone);
  1482.     Add(XtQInt,   XtQPixmap,      XtCvtIntToPixmap,    NULL, 0, XtCacheNone);
  1483.     Add(XtQInt,   XtQPosition,    XtCvtIntToShort,     NULL, 0, XtCacheNone);
  1484.     Add(XtQInt,   XtQShort,       XtCvtIntToShort,     NULL, 0, XtCacheNone);
  1485.     Add(XtQInt,   XtQUnsignedChar,XtCvtIntToUnsignedChar,NULL, 0, XtCacheNone);
  1486.  
  1487.     Add(XtQPixel, XtQColor,      XtCvtIntToColor,
  1488.     colorConvertArgs, XtNumber(colorConvertArgs), XtCacheByDisplay);
  1489.  
  1490.     Add(_XtQString, XtQAtom,      XtCvtStringToAtom,
  1491.     displayConvertArg, XtNumber(displayConvertArg), XtCacheNone);
  1492.     Add(_XtQString, XtQBool,      XtCvtStringToBool,    NULL, 0, XtCacheNone);
  1493.     Add(_XtQString, XtQBoolean,   XtCvtStringToBoolean, NULL, 0, XtCacheNone);
  1494.    Add2(_XtQString, XtQCursor,    XtCvtStringToCursor,
  1495.     displayConvertArg, XtNumber(displayConvertArg),
  1496.     XtCacheByDisplay, FreeCursor);
  1497.     Add(_XtQString, XtQDimension, XtCvtStringToDimension,NULL, 0, XtCacheNone);
  1498.     Add(_XtQString, XtQDisplay,   XtCvtStringToDisplay, NULL, 0, XtCacheAll);
  1499.    Add2(_XtQString, XtQFile,      XtCvtStringToFile,    NULL, 0,
  1500.     XtCacheAll | XtCacheRefCount, FreeFile);
  1501.     Add(_XtQString, XtQFloat,     XtCvtStringToFloat,   NULL, 0, XtCacheNone);
  1502.  
  1503.    Add2(_XtQString, XtQFont,      XtCvtStringToFont,
  1504.     displayConvertArg, XtNumber(displayConvertArg),
  1505.     XtCacheByDisplay, FreeFont);
  1506.    Add2(_XtQString, XtQFontSet,   XtCvtStringToFontSet,
  1507.     localeDisplayConvertArgs, XtNumber(localeDisplayConvertArgs),
  1508.     XtCacheByDisplay, FreeFontSet);
  1509.    Add2(_XtQString, XtQFontStruct,XtCvtStringToFontStruct,
  1510.     displayConvertArg, XtNumber(displayConvertArg),
  1511.     XtCacheByDisplay, FreeFontStruct);
  1512.  
  1513. #ifdef STRING_TO_GEOMETRY /* Not in the specification */
  1514.     Add(_XtQString, XtQGeometry,  CvtStringToGeometry, NULL, 0, XtCacheNone);
  1515. #endif
  1516.  
  1517.     Add(_XtQString, XtQInitialState, XtCvtStringToInitialState, NULL, 0,
  1518.     XtCacheNone);
  1519.     Add(_XtQString, XtQInt,         XtCvtStringToInt,    NULL, 0, XtCacheAll);
  1520.    Add2(_XtQString, XtQPixel,        XtCvtStringToPixel,
  1521.     colorConvertArgs, XtNumber(colorConvertArgs),
  1522.     XtCacheByDisplay, FreePixel);
  1523.     Add(_XtQString, XtQPosition,     XtCvtStringToShort,  NULL, 0, XtCacheAll);
  1524.     Add(_XtQString, XtQShort,        XtCvtStringToShort,  NULL, 0, XtCacheAll);
  1525.     Add(_XtQString, XtQUnsignedChar, XtCvtStringToUnsignedChar,
  1526.     NULL, 0, XtCacheAll);
  1527.    Add2(_XtQString, XtQVisual,       XtCvtStringToVisual,
  1528.     visualConvertArgs, XtNumber(visualConvertArgs),
  1529.     XtCacheByDisplay, NULL);
  1530.  
  1531.    _XtAddTMConverters(table);
  1532. }
  1533.