Ejemplo n.º 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);
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 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;
}
Ejemplo n.º 5
0
Archivo: xmcvt.c Proyecto: juddy/edcde
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);
}
Ejemplo n.º 6
0
Archivo: xmcvt.c Proyecto: juddy/edcde
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);
}
Ejemplo n.º 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);
}
Ejemplo n.º 8
0
/*
 * 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);
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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
}
Ejemplo n.º 12
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);
}