Beispiel #1
0
char *XmStringToText (XmString xmstring)
{
XmStringContext   context;
XmStringCharSet   charset;
XmStringDirection direction;
Boolean           separator;
char              *text_string = NULL, *temp = NULL;

text_string = (char *)calloc (1, sizeof (char));

if (xmstring) {
    if (!XmStringInitContext (&context, xmstring)) {
      printf("Can't convert compound string.\n");
      return (NULL);
    }
    while  (XmStringGetNextSegment (context, &temp, &charset,
                                    &direction, &separator)) {
      text_string = (char *)realloc (text_string, strlen (temp)+1);
      if (text_string == NULL) {
        printf("Can't allocate space for file name.\n");
        return (NULL);
      }
      text_string = strcpy(text_string, temp);
    }

    XmStringFreeContext(context);
    }

return (text_string);
}
Beispiel #2
0
int
main(int argc, char **argv)
{
#ifdef LESSTIF_VERSION
  Widget toplevel;
  XtAppContext app;
  XmFontList fontlist;
  XmString xmstr1 = XmStringCreate("Here is a ", "MY_FONT1");
  XmString xmstr2 = XmStringCreate("different font", "MY_FONT");
  char buf[] = { 0xdf, 0x80, 0x06, 0x00, 0x01, 0x00 };
  XmStringContext context;
  char *text;
  XmStringCharSet cs;
  XmStringDirection dir;
  Boolean sep;

  XmString xmstr = XmStringConcat(xmstr1, xmstr2);

  XtSetLanguageProc(NULL, NULL, NULL);

  toplevel = XtVaAppInitialize(&app, "Label", NULL, 0, &argc, argv, NULL, NULL);

  fontlist = XmFontListAppendEntry(NULL,
			   XmFontListEntryCreate("MY_FONT",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-o-normal--17-0-75-75-p-*-iso8859-1")));

  fontlist = XmFontListAppendEntry(fontlist,
			   XmFontListEntryCreate("MY_FONT1",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-r-normal--17-0-75-75-p-*-iso8859-1")));

  asn1_dump((unsigned char *)xmstr);

  printf("SINGLE SEGMENT\n");
  text = NULL;
  cs = "-adobe-helvetica-bold-r-normal--17-0-75-75-p-*-iso8859-1";
  _XmStringSingleSegment(xmstr, &text, &cs);
  printf("text: %s cs: %s\n", text ? text : "(empty)", cs ? cs : "(empty)");

  if (_XmStringIsXmString((XmString)buf))
	printf("IS STRING\n");
  else
	printf("ISN'T STRING\n");

  asn1_dump((unsigned char *)buf);

  XmStringInitContext(&context, xmstr);
  while (XmStringGetNextSegment(context, &text, &cs, &dir, &sep)) {
    printf("%s %s %d %d\n", text ? text : "(null)", cs ? cs : "(null)",
	   dir, sep);
  }
  XmStringFreeContext(context);

  printf("current charset: %s\n", _XmStringGetCurrentCharset());
#endif
  exit(0);
}
Beispiel #3
0
/******************************************************
  Static callback routine for logging a widget's messageString to opMod log file
******************************************************/
static void logMessageString(Widget w, XtPointer clientdata, XtPointer calldata)
{
	XmString cstring;
	XmStringContext context;
	char *lstring;
	XmStringCharSet tag;
	XmStringDirection direction;
	Boolean separator;

	XtVaGetValues(w, XmNmessageString, &cstring, NULL);
	if (!XmStringInitContext(&context,cstring)) {
		XmStringFree(cstring);
		return;
	}

	while (XmStringGetNextSegment(context,&lstring,&tag,&direction,&separator)){
		alLogOpModMessage(0,0,lstring);
		XtFree(lstring);
		lstring=0;
	}
	if (lstring) XtFree(lstring);
	XmStringFree(cstring);
	XmStringFreeContext(context);
    XtFree(tag);
}
Beispiel #4
0
/*
** Convert a compound string to a C style null terminated string.
** Returned string must be freed by the caller.
*/
char *GetXmStringText(XmString fromString)
{
    XmStringContext context;
    char *text, *toPtr, *toString, *fromPtr;
    XmStringCharSet charset;
    XmStringDirection direction;
    Boolean separator;
    
    /* Malloc a buffer large enough to hold the string.  XmStringLength
       should always be slightly longer than necessary, but won't be
       shorter than the equivalent null-terminated string */ 
    toString = XtMalloc(XmStringLength(fromString));
    
    /* loop over all of the segments in the string, copying each segment
       into the output string and converting separators into newlines */
    XmStringInitContext(&context, fromString);
    toPtr = toString;
    while (XmStringGetNextSegment(context, &text,
    	    &charset, &direction, &separator)) {
    	for (fromPtr=text; *fromPtr!='\0'; fromPtr++)
    	    *toPtr++ = *fromPtr;
    	if (separator)
    	    *toPtr++ = '\n';
    }
    
    /* terminate the string, free the context, and return the string */
    *toPtr++ = '\0';
    XmStringFreeContext(context);
    return toString;
}
Beispiel #5
0
char *
XmStringToString(
        XmString string )
{
	static char *buf = NULL;
	XmStringContext context;
	XmStringCharSet charset;
	XmStringDirection dir;
	char *text;
	Boolean separator = FALSE;

        if (string == NULL)
           return(NULL);

	XmStringInitContext(&context, string);
        XtFree(buf);
	buf = NULL;
	while (!separator) {
		if (XmStringGetNextSegment(context, &text, &charset, &dir,
			&separator)) {
			if (buf) {
				buf = XtRealloc(buf, strlen(buf) + strlen(text) + 2);
				strcat(buf, text);
			} else
				buf = strdup(text);
			XtFree(text);
		} else
			break;
	}
	XmStringFreeContext(context);
	return(buf);
}
Beispiel #6
0
char *
_CvtXmStringTableToString(
        XmStringTable stringtable,
        int itemCount )
{
   static char *buf = NULL;
   XmStringContext context;
   XmStringCharSet charset;
   XmStringDirection dir;
   char *text;
   Boolean separator = FALSE;
   XmString string;
   int i;
   char * ptr;
   char * nextComma;

   XtFree(buf);
   buf = XtMalloc(3);
   buf[0] = '\0';

   for (i = 0; i < itemCount; i++)
   {
      if (i > 0)
         strcat(buf, ",");

      XmStringInitContext(&context, stringtable[i]);
      while (!separator) 
      {
         if (XmStringGetNextSegment(context, &text, &charset, &dir, &separator))
         {
            /*
             * To be consistent with the Motif converter, which will take
             * a comma-separated string, and convert it to an XmStringTable,
             * we need to escape any ',' characters contained within a list
             * item.
             */
 
            ptr = text;
            while (nextComma = strchr(ptr, ','))
            {
               *nextComma = '\0';
               buf = XtRealloc(buf, strlen(buf) + strlen(ptr) + 5);
               strcat(buf, ptr);
               strcat(buf, "\\,");
               *nextComma = ',';
               ptr = nextComma + 1;
            }
            buf = XtRealloc(buf, strlen(buf) + strlen(ptr) + 3);
            strcat(buf, ptr);

            XtFree(text);
         } 
         else
            break;
      }
      XmStringFreeContext(context);
   }

   return(buf);
}
Beispiel #7
0
int
main(int argc, char **argv)
{
  Widget toplevel, one;
  XtAppContext app;
  XmFontList fontlist;
  XmString xmstr1 = XmStringCreateLtoR("Here is a\n", "MY_FONT1");
  XmString xmstr2 = XmStringCreate("different font", "MY_FONT");
  XmString xmstr3 = XmStringCreate("accelerator", "MY_FONT");
  XmStringContext context;
  char *text;
  XmStringCharSet tag;
  XmStringDirection dir;
  Boolean sep;

  XmString xmstr = XmStringConcat(xmstr1, xmstr2);

  XtSetLanguageProc(NULL, NULL, NULL);

  toplevel = XtVaAppInitialize(&app, "Label", NULL, 0, &argc, argv, FallBack, NULL);

  XmStringInitContext(&context, xmstr);
  while (XmStringGetNextSegment(context, &text, &tag, &dir, &sep)) {
	printf("Text: %s Tag: %s Dir: %d Sep: %d\n", text, tag, dir, sep);
	fflush(stdout);
  }

  fontlist = XmFontListAppendEntry(NULL,
			   XmFontListEntryCreate("MY_FONT",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-o-normal--17-0-75-75-p-*-iso8859-1")));

  fontlist = XmFontListAppendEntry(fontlist,
			   XmFontListEntryCreate("MY_FONT1",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-o-normal--30-*-*-*-*-*-iso8859-1")));

  one = XtVaCreateManagedWidget("One", xmLabelWidgetClass, toplevel, XmNfontList, fontlist, 
				XmNlabelString, xmstr,
				XmNacceleratorText, xmstr3, NULL);

  printf("xmstr: %p %p\n", xmstr, ((XmLabelRec*)one)->label._label);
  XtRealizeWidget(toplevel);
  {
  static XtWidgetGeometry Expected[] = {
  	CWWidth | CWHeight,		0,	0,	128,	55,	0,0,0,	/* Form */
};

  PrintDetails(toplevel, Expected);
  }
  LessTifTestMainLoop(toplevel);
  /*
  XtAppMainLoop(app);
  */

  exit(0);
}
Beispiel #8
0
// Return all characters in M
string MString::str() const
{
    XmString m = xmstring();
    if (m == 0)
	return "";

    string s;

    XmStringContext c;
    XmStringInitContext(&c, m);
    XmStringComponentType t = XmSTRING_COMPONENT_UNKNOWN;

    while (t != XmSTRING_COMPONENT_END)
    {
	char *s_text            = 0;
	XmStringCharSet s_cs    = 0;
	XmStringDirection d     = XmSTRING_DIRECTION_DEFAULT;
	XmStringComponentType u = XmSTRING_COMPONENT_UNKNOWN;
	unsigned short ul       = 0;
	unsigned char *s_uv     = 0;
	
	t = XmStringGetNextComponent(c, &s_text, &s_cs, &d, &u, &ul, &s_uv);

	// Upon EOF in LessTif 0.82, XmStringGetNextComponent()
	// returns XmSTRING_COMPONENT_UNKNOWN instead of
	// XmSTRING_COMPONENT_END.  Work around this.
	if (t == XmSTRING_COMPONENT_UNKNOWN && s_uv == 0)
	    t = XmSTRING_COMPONENT_END;

	switch (t)
	{
	case XmSTRING_COMPONENT_TEXT:
#if XmVersion >= 1002
	case XmSTRING_COMPONENT_LOCALE_TEXT:
#endif
#if XmVersion >= 2000
	case XmSTRING_COMPONENT_WIDECHAR_TEXT:
#endif
	    s += (s_text == 0 ? "" : s_text);
	    break;

	case XmSTRING_COMPONENT_SEPARATOR:
	    s += '\n';
	    break;

	default:
	    break;
	}

	// Free unused memory
	XtFree(s_text);
	XtFree(s_cs);
	XtFree((char *)s_uv);
    }

    XmStringFreeContext(c);

    return s;
}
/*
 * client_data is MFileDialogPeer instance pointer
 */
static void
FileDialog_OK(Widget w,
              void *client_data,
              XmFileSelectionBoxCallbackStruct * call_data)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    jobject this = (jobject) client_data;
    struct FrameData *fdata;
    char *file;
    jstring jstr;
    XmStringContext   stringContext;
    XmStringDirection direction;
    XmStringCharSet   charset;
    Boolean           separator;

    fdata = (struct FrameData *)JNU_GetLongFieldAsPtr(env,this,mComponentPeerIDs.pData);

    if ((*env)->EnsureLocalCapacity(env, 1) < 0)
        return;

    if (!XmStringInitContext(&stringContext, call_data->value))
	return;

    if (!XmStringGetNextSegment(stringContext, &file, &charset,
				&direction, &separator))
	file = NULL;

    if (file == NULL)
	jstr = NULL;
    else
	jstr = JNU_NewStringPlatform(env, (const char *) file);

    if (jstr != 0) {
	JNU_CallMethodByName(env, NULL, this, "handleSelected",
			     "(Ljava/lang/String;)V", jstr);
	(*env)->DeleteLocalRef(env, jstr);
    }
    if ((*env)->ExceptionOccurred(env)) {
        (*env)->ExceptionDescribe(env);
        (*env)->ExceptionClear(env);
    }

    XmStringFreeContext(stringContext);
    if (file != NULL)
	XtFree(file);
}
Beispiel #10
0
//-----------------------------------------------------------------------------
// Create a copy of a WXmString, substituting the current font with the
// supplied font
WXmString
WXmString::CopyUsingFont( char* newtag )
{
   XmStringContext context;
   if( XmStringInitContext(&context,*this)){
      char* text = NULL;
      XmStringCharSet tag;
      XmStringDirection direction;
      Boolean separator;

      if( XmStringGetNextSegment(context,&text,&tag,&direction,&separator) ){
	 WXmString NewString(text, newtag);
	 delete text;
         XmStringFreeContext(context);
	 return NewString;
      }
      XmStringFreeContext(context);
   }
   WXmString NullString;
   return NullString;
}
Beispiel #11
0
char* iupmotConvertString(XmString str)
{
  XmStringContext context;
  char *text, *p, *buf;
  unsigned int length;
  XmStringComponentType type;

  if (!XmStringInitContext (&context, str))
    return NULL;

  buf = iupStrGetMemory(XmStringLength(str));  /* always greatter than strlen */

  /* p keeps a running pointer through buf as text is read */
  p = buf;
  while ((type = XmStringGetNextTriple(context, &length, (XtPointer)&text)) != XmSTRING_COMPONENT_END) 
  {
    switch (type) 
    {
    case XmSTRING_COMPONENT_TEXT:
      memcpy(p, text, length);
      p += length;
      *p = 0;
      break;
    case XmSTRING_COMPONENT_TAB:
      *p++ = '\t';
      *p = 0;
      break;
    case XmSTRING_COMPONENT_SEPARATOR:
      *p++ = '\n';
      *p = 0;
      break;
    }
    XtFree(text);
  }

  XmStringFreeContext(context);

  return buf;
}
Beispiel #12
0
EIF_REFERENCE xm_string_to_eiffel (XmString motif_string)
{
	/*
	 * Convert `motif_string' in Eiffel string
	 * This function was written for Vision
	 */

	char * eiffel_string = (char*) NULL;
	char *result;
	char *text;
	char separator_place;
	XmStringCharSet charset;
	XmStringDirection direction;
	XmStringContext context;
	Boolean separator;

	result = (char *) malloc (sizeof (char));
	*result = (char) 0;
	if (XmStringInitContext (&context, motif_string))
		{
		for (; XmStringGetNextSegment (context, &text, &charset, &direction, &separator);)
			{
			separator_place = 1;
			if (separator) separator_place++;
			result = realloc (result, (strlen (result) + strlen (text) + separator_place));
			strcat (result, text);
			if (separator) strcat (result, "\n");
			XtFree (text);
			XtFree (charset);
			}
		XmStringFreeContext (context);
		eiffel_string = RTMS (result);
		free (result);
		}
	return (EIF_REFERENCE) eiffel_string;
}
Beispiel #13
0
Boolean
XmStringUngenerate(XmString string, XmStringCharSet tag, char** ret)
{

    *ret = (char *)_XmStringUngenerate(string, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT);
    if (*ret) {
	return True;
    }
    else {
	return False;
    }
    
#if 0
  XmStringContext context;

  if (! XmStringInitContext(&context, string)) {
    *ret = NULL;
    return False;
  }

  int bufsize, buflen;
  char* buf = XtMalloc(bufsize = 128);
  buf[0] = 0;
  buflen  = 1;

  char* text = NULL;
  XmStringDirection dir;
  Boolean sep;

  while (XmStringGetNextSegment(context, &text, &tag, &dir, &sep)) {
    if (text) {
      len = strlen(text);
      int textlen = len + (sep? 1 : 0);
      { // buffer size adjustment
	int bufsize_required = bufsize;
	while (buflen + textlen > bufsize_required)
	  bufsize_required += 128;
	if (bufsize_required > bufsize) {
	  buf = XtRealloc(buf, bufsize_required);
	  bufsize = bufsize_required;
	}
      }
      slen = strlen(buf);
      *((char *) memcpy(buf + slen, text, len) + len) = '\0';
      if (sep)
	*((char *) memcpy(buf + slen + 1, "\n", 1) + 1) = '\0';
      buflen += textlen;

      XtFree(text);
    }
    text = NULL;
  }

  XmStringFreeContext(context);

  *ret = buf;

  return True;

#endif
}
Beispiel #14
0
// Return true iff S1 is a prefix of S2
static bool is_prefix(const MString& m1, const MString& m2)
{
    XmString s1 = m1.xmstring();
    XmString s2 = m2.xmstring();

    XmStringContext c1;
    XmStringContext c2;

    XmStringInitContext(&c1, s1);
    XmStringInitContext(&c2, s2);

    XmStringComponentType t1 = XmSTRING_COMPONENT_UNKNOWN;
    XmStringComponentType t2 = XmSTRING_COMPONENT_UNKNOWN;

    while (t1 != XmSTRING_COMPONENT_END && t2 != XmSTRING_COMPONENT_END)
    {
	char *s_text1            = 0;
	XmStringCharSet s_cs1    = 0;
	XmStringDirection d1     = XmSTRING_DIRECTION_DEFAULT;
	XmStringComponentType u1 = XmSTRING_COMPONENT_UNKNOWN;
	unsigned short ul1       = 0;
	unsigned char *s_uv1     = 0;
	
	t1 = XmStringGetNextComponent(c1, &s_text1, &s_cs1, &d1, 
				      &u1, &ul1, &s_uv1);

	char *s_text2            = 0;
	XmStringCharSet s_cs2    = 0;
	XmStringDirection d2     = XmSTRING_DIRECTION_DEFAULT;
	XmStringComponentType u2 = XmSTRING_COMPONENT_UNKNOWN;
	unsigned short ul2       = 0;
	unsigned char *s_uv2     = 0;

	t2 = XmStringGetNextComponent(c2, &s_text2, &s_cs2, &d2,
				      &u2, &ul2, &s_uv2);

	// Upon EOF in LessTif 0.82, XmStringGetNextComponent()
	// returns XmSTRING_COMPONENT_UNKNOWN instead of
	// XmSTRING_COMPONENT_END.  Work around this.
	if (t1 == XmSTRING_COMPONENT_UNKNOWN && s_uv1 == 0)
	    t1 = XmSTRING_COMPONENT_END;
	if (t2 == XmSTRING_COMPONENT_UNKNOWN && s_uv2 == 0)
	    t2 = XmSTRING_COMPONENT_END;

	// Place string values in strings
	string text1(s_text1 == 0 ? "" : s_text1);
	string text2(s_text2 == 0 ? "" : s_text2);
	string cs1(s_cs1 == 0 ? "" : s_cs1);
	string cs2(s_cs2 == 0 ? "" : s_cs2);
	string uv1;
	string uv2;
	if (s_uv1 != 0)
	    uv1 = string((char *)s_uv1, ul1);
	if (s_uv2 != 0)
	    uv2 = string((char *)s_uv2, ul2);

	// Free unused memory
	XtFree(s_text1);
	XtFree(s_text2);
	XtFree(s_cs1);
	XtFree(s_cs2);
	XtFree((char *)s_uv1);
	XtFree((char *)s_uv2);

	if (t1 != t2)
	{
	    goto done;		// Differing tags
	}

	switch (t1)
	{
	case XmSTRING_COMPONENT_CHARSET:
	{
	    if (cs1.empty())	// In LessTif 0.82, XmStringGetNextComponent()
		cs1 = text1;	// swaps CS and TEXT.  Work around this.
	    if (cs2.empty())
		cs2 = text2;

	    if (cs1 != cs2)
		goto done;	// Differing character sets
	    break;
	}

	case XmSTRING_COMPONENT_TEXT:
#if XmVersion >= 1002
	case XmSTRING_COMPONENT_LOCALE_TEXT:
#endif
#if XmVersion >= 2000
	case XmSTRING_COMPONENT_WIDECHAR_TEXT:
#endif
	{
	    if (text1.empty())	// In LessTif 0.82, XmStringGetNextComponent()
		text1 = cs1;	// swaps CS and TEXT.  Work around this.
	    if (text2.empty())
		text2 = cs2;

	    if (!text2.contains(text1, 0))
		goto done;
	    XmStringComponentType next2 = XmStringPeekNextComponent(c2);

	    // In LessTif 0.82, XmStringPeekNextComponent() returns
	    // XmSTRING_COMPONENT_UNKNOWN instead of
	    // XmSTRING_COMPONENT_END.  Work around this.
	    if (next2 != XmSTRING_COMPONENT_END && 
		next2 != XmSTRING_COMPONENT_UNKNOWN)
		goto done;
	    break;
	}

	case XmSTRING_COMPONENT_DIRECTION:
	{
	    if (d1 != d2)
		goto done;
	    break;
	}

	case XmSTRING_COMPONENT_SEPARATOR:
	case XmSTRING_COMPONENT_END:
	{
	    // These are the same by definition
	    break;
	}

	case XmSTRING_COMPONENT_UNKNOWN:
	{
	    if (uv1 != uv2)
		goto done;	// Differing unknown tags
	    break;
	}

	default:
	{
	    break;		// Skip everything else
	}
	}
    }
 done:

    XmStringFreeContext(c2);
    XmStringFreeContext(c1);

    return t1 == XmSTRING_COMPONENT_END;
}
Beispiel #15
0
/*
 * fetch the first text 'segment' of the external TCS that matches the given
 * char set.
 */
Boolean 
XmStringGetLtoR(
  XmString string,
  XmStringTag tag,
  char **text )
{
  XmStringContext context;
  char * t;
  XmStringTag c, curtag = NULL; 
  XmStringDirection d;
  Boolean s, is_local = FALSE, done = FALSE, is_default = FALSE;
  
  _XmProcessLock();
  if (!string) {
	_XmProcessUnlock();
	return(FALSE);
  }
  if (!tag) {
	_XmProcessUnlock();
	return (FALSE);
  }
  
  if ((tag == XmFONTLIST_DEFAULT_TAG) || 
      (strcmp(tag, XmFONTLIST_DEFAULT_TAG) == 0))
    is_local = TRUE; 
  
  *text = NULL;				  /* pre-condition result */
  
  if (!is_local)
    {
      if ((strcmp(tag, XmSTRING_DEFAULT_CHARSET) == 0))
	{
	  curtag = _XmStringGetCurrentCharset();
	  is_default = TRUE;
	}
      else curtag = tag;
    }
  
  XmStringInitContext (&context, string);
  
  while ( ! done)
    {
      if (XmStringGetNextSegment (context, &t, &c, &d, &s))
	{
	  if (c && ((d == XmSTRING_DIRECTION_L_TO_R) ||
		    (d == XmSTRING_DIRECTION_UNSET)) &&
	      (((is_local || is_default) && 
		((c == XmFONTLIST_DEFAULT_TAG) || 
		 (strcmp(c, XmFONTLIST_DEFAULT_TAG) == 0) ||
		 (strcmp(c, _XmStringGetCurrentCharset()) == 0))) ||
	       (curtag && (strcmp (c, curtag) == 0))))
	    {
	      *text = t;		  /* OK, pass text to caller */
	      done = TRUE;
	    }
	  else
	    XtFree (t);			  /* not this text */
	  
	  if (c)
	    XtFree (c);			  /* always dump charset */
	}
      else
	done = TRUE;
    }
  
  XmStringFreeContext (context);
  _XmProcessUnlock();
  return (*text != NULL);
}