Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!rochester!bbn.com!nic!hri!rudolph From: rudolph@hri.com (Dave Rudolph) Newsgroups: comp.windows.x.motif Subject: Re: Has anyone used XmStringGetSegment? Message-ID: <1990Aug15.133409.23403@hri.com> Date: 15 Aug 90 13:34:09 GMT References: <9008100138.AA08292@alphalpha.com> Distribution: inet Organization: Horizon Research Inc. Lines: 62 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 >#include > >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 ----------------------------------------------------------------------------