nazgul@alphalpha.com (Kee Hinckley) (08/10/90)
A friend sent me this code, saying it core-dumped on his machine. On mine it just doesn't work. I mucked with it a little to no avail. Note that if you take out the concat and just do it with the first Label it went into an infinite loop printing out null strings. Got me. #include <stdio.h> #include <Xm/Xm.h> void main(argc, argv) int argc; char *argv[]; { XmString Label, s1, s2; XmStringContext Context; char *LabelChars; XmStringCharSet CharSet; XmStringDirection Direction; Boolean Separator; Label = XmStringCreateLtoR("Death", XmSTRING_DEFAULT_CHARSET); s1 = XmStringCreateLtoR("and Taxes", XmSTRING_DEFAULT_CHARSET); Label = XmStringConcat(Label, s1); if (XmStringInitContext(&Context, Label) == False) { printf("XmStringInitContext Failed\n"); exit(0); } while (XmStringGetNextSegment(&Context, &LabelChars, &CharSet, &Direction, &Separator)) { printf("LabelChars='%s'\n", LabelChars); } } Alphalpha Software, Inc. | motif-request@alphalpha.com nazgul@alphalpha.com |----------------------------------- 617/646-7703 (voice/fax) | Proline BBS: 617/641-3722 I'm not sure which upsets me more; that people are so unwilling to accept responsibility for their own actions, or that they are so eager to regulate everyone else's. -------
neek@NEEK.FAC.CS.CMU.EDU (Craig Marcus) (08/10/90)
Keywords !> A friend sent me this code, saying it core-dumped on his machine. |> On mine it just doesn't work. I mucked with it a little to no avail. |> |> Note that if you take out the concat and just do it with the first |> Label it went into an infinite loop printing out null strings. .... 7 |> { 8 |> XmString Label, s1, s2; 9 |> XmStringContext Context; 10 |> char *LabelChars; 11 |> XmStringCharSet CharSet; 12 |> XmStringDirection Direction; 13 |> Boolean Separator; 14 |> 15 |> Label =XmStringCreateLtoR("Death",XmSTRING_DEFAULT_CHARSET); 16 |> s1 = XmStringCreateLtoR("andTaxes",XmSTRING_DEFAULT_CHARSET); 17 |> Label = XmStringConcat(Label, s1); 18 |> if (XmStringInitContext(&Context, Label) == False) 19 |> { 20 |> printf("XmStringInitContext Failed\n"); 21 |> exit(0); 22 |> } 23 |> 24 |> while (XmStringGetNextSegment(&Context, &LabelChars, &CharSet, &Dire ction, &Separator)) { 25 |> printf("LabelChars='%s'\n", LabelChars); 26 |> } The problem with this code is that the "Context" variable is one level of indirection off, ie Context is a pointer to a structure as populated by XmStringInitContext. Therefore, in line 24 above, change the first parameter from "&Context" to "Context" and the code should run fine. Neek Carnegie Mellon University Pittsburgh
rudolph@hri.com (Dave Rudolph) (08/15/90)
In article <9008100138.AA08292@alphalpha.com> nazgul@alphalpha.com (Kee Hinckley) writes: >A friend sent me this code, saying it core-dumped on his machine. >On mine it just doesn't work. I mucked with it a little to no avail. > >#include <stdio.h> >#include <Xm/Xm.h> > >void main(argc, argv) > int argc; > char *argv[]; >{ > XmString Label, s1, s2; > XmStringContext Context; > char *LabelChars; > XmStringCharSet CharSet; > XmStringDirection Direction; > Boolean Separator; > > Label = XmStringCreateLtoR("Death", XmSTRING_DEFAULT_CHARSET); > s1 = XmStringCreateLtoR("and Taxes", XmSTRING_DEFAULT_CHARSET); > Label = XmStringConcat(Label, s1); > if (XmStringInitContext(&Context, Label) == False) > { > printf("XmStringInitContext Failed\n"); > exit(0); > } > > while (XmStringGetNextSegment(&Context, &LabelChars, &CharSet, &Direction, &Separator)) { > printf("LabelChars='%s'\n", LabelChars); > } > >} I had problems with this sequence also, and I found that the documentation is screwed up. I don't have it in front of me, so I can't tell you exactly what the problem was, but it involved the first parameter to XmStringGetNextSegment (context) and whether or not it was a pointer. I think the doc said it should be a pointer, but it should not be. Anyway, the following code worked for me. Note that the init call uses "&context", while the get call uses just "context". char *getstring(str) XmString str; { caddr_t context; char *text; XmStringCharSet charset; XmStringDirection direction; Boolean separator; int res; XmStringInitContext (&context,str); XmStringGetNextSegment(context,&text,&charset,&direction,&separator); return text; } ---------------------------------------------------------------------------- David Rudolph | phone: (617) 466-8370 Horizon Research, Inc. | email: rudolph@hri.com ----------------------------------------------------------------------------