StrToOrnt.c revision 0cc2eac3
10cc2eac3Smrg/*
20cc2eac3Smrg
36c321187SmrgCopyright 1988, 1998  The Open Group
46c321187Smrg
56c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its
66c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that
76c321187Smrgthe above copyright notice appear in all copies and that both that
86c321187Smrgcopyright notice and this permission notice appear in supporting
96c321187Smrgdocumentation.
106c321187Smrg
116c321187SmrgThe above copyright notice and this permission notice shall be included in
126c321187Smrgall copies or substantial portions of the Software.
136c321187Smrg
146c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
156c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
166c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
176c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
186c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
196c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
206c321187Smrg
216c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be
226c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings
236c321187Smrgin this Software without prior written authorization from The Open Group.
246c321187Smrg
256c321187Smrg*/
266c321187Smrg
276c321187Smrg#ifdef HAVE_CONFIG_H
286c321187Smrg#include <config.h>
296c321187Smrg#endif
306c321187Smrg#include <X11/Intrinsic.h>
316c321187Smrg#include <X11/StringDefs.h>
326c321187Smrg#include "Converters.h"
336c321187Smrg#include "CharSet.h"
346c321187Smrg
356c321187Smrg/*
366c321187Smrg * Prototypes
376c321187Smrg */
386c321187Smrgstatic void InitializeQuarks(void);
396c321187Smrg
406c321187Smrg/*
416c321187Smrg * Initialization
426c321187Smrg */
436c321187Smrgstatic	XrmQuark Qhorizontal, Qvertical;
446c321187Smrgstatic Boolean haveQuarks;
456c321187Smrg
466c321187Smrg/*
476c321187Smrg * Implementation
486c321187Smrg */
496c321187Smrgstatic void
506c321187SmrgInitializeQuarks(void)
516c321187Smrg{
526c321187Smrg  if (!haveQuarks)
536c321187Smrg    {
546c321187Smrg      Qhorizontal = XrmPermStringToQuark(XtEhorizontal);
556c321187Smrg      Qvertical = XrmPermStringToQuark(XtEvertical);
566c321187Smrg      haveQuarks = True;
576c321187Smrg    }
586c321187Smrg}
596c321187Smrg
606c321187Smrg/*ARGSUSED*/
616c321187Smrgvoid
626c321187SmrgXmuCvtStringToOrientation(XrmValuePtr args, Cardinal *num_args,
636c321187Smrg			  XrmValuePtr fromVal, XrmValuePtr toVal)
646c321187Smrg{
656c321187Smrg    static XtOrientation orient;
666c321187Smrg    XrmQuark	q;
676c321187Smrg  char name[11];
686c321187Smrg
696c321187Smrg  InitializeQuarks();
706c321187Smrg  XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name));
716c321187Smrg  q = XrmStringToQuark(name);
726c321187Smrg
736c321187Smrg  toVal->size = sizeof(XtJustify);
746c321187Smrg  toVal->addr = (XPointer)&orient;
756c321187Smrg
766c321187Smrg  if (q == Qhorizontal)
776c321187Smrg    	orient = XtorientHorizontal;
786c321187Smrg  else if (q == Qvertical)
796c321187Smrg    	orient = XtorientVertical;
806c321187Smrg  else
816c321187Smrg    {
826c321187Smrg      toVal->addr = NULL;
836c321187Smrg      XtStringConversionWarning((char *)fromVal->addr, XtROrientation);
846c321187Smrg    }
856c321187Smrg}
866c321187Smrg
876c321187Smrg/*ARGSUSED*/
886c321187SmrgBoolean
896c321187SmrgXmuCvtOrientationToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
906c321187Smrg			  XrmValuePtr fromVal, XrmValuePtr toVal,
916c321187Smrg			  XtPointer *data)
926c321187Smrg{
936c321187Smrg  static String buffer;
946c321187Smrg  Cardinal size;
956c321187Smrg
966c321187Smrg  switch (*(XtOrientation *)fromVal->addr)
976c321187Smrg    {
986c321187Smrg    case XtorientVertical:
996c321187Smrg      buffer = XtEvertical;
1006c321187Smrg      break;
1016c321187Smrg    case XtorientHorizontal:
1026c321187Smrg      buffer = XtEhorizontal;
1036c321187Smrg      break;
1046c321187Smrg    default:
1056c321187Smrg      XtWarning("Cannot convert Orientation to String");
1066c321187Smrg      toVal->addr = NULL;
1076c321187Smrg      toVal->size = 0;
1086c321187Smrg      return (False);
1096c321187Smrg    }
1106c321187Smrg
1116c321187Smrg  size = strlen(buffer) + 1;
1126c321187Smrg  if (toVal->addr != NULL)
1136c321187Smrg    {
1146c321187Smrg      if (toVal->size < size)
1156c321187Smrg	{
1166c321187Smrg	  toVal->size = size;
1176c321187Smrg	  return (False);
1186c321187Smrg	}
1196c321187Smrg      strcpy((char *)toVal->addr, buffer);
1206c321187Smrg    }
1216c321187Smrg  else
1226c321187Smrg    toVal->addr = (XPointer)buffer;
1236c321187Smrg  toVal->size = sizeof(String);
1246c321187Smrg
1256c321187Smrg  return (True);
1266c321187Smrg}
127