C/Motif on unix: how to pause app while waiting for user response?

I'm trying to implement a reusable function which asks the user for a response, then performs tasks based on the response. The app needs to pause and wait until the response is received, but I can't figure out how to do this without locking up the entire app. In the following example, the Response at line 48 always comes back blank because the run_b routine keeps processing instead of waiting for user_response to complete. Uncommenting the lines at 46.47 causes the entire app to lockup. How can I do this?

You are trying to use the wrong programming model. X/Motif is an event driven system. Therefore the action takes place in an event handler. The event handler for your response is "question_cb() " and that's where youi have to deal with the response. If you are planning to create a kind of "GUI library" you have to use the callback function as input paramater for "user_response()"

There is no reason for you to wait for the reply, since X is already taking care of that wait. You provided X with a way to handle the reply by installing the event handler "question_cb() ". This function is only called when (!) the user presses one of the buttons.

=====
Werner

0

jimdgarAuthor Commented: 2004-09-07

Conceptually I understand what you're saying but I still can't see how to implement this. The legacy C code I have is "flow-driven" and depends on getting inputs from the user to make decisions. These inputs cannot be predetermined, they must happen in realtime. In a command-line mode it's easy since the entire app simply waits until the user enters a response to an xterm. Now I want to get the same response from a popup text entry window.

Anyone know of any guidelines on how to do this? I cannot find similar cases in my Motif manuals or online.

In a console application every input operation creates its own wait until the user starts typing. X takes that responsibility for you. With " XtAppMainLoop (app) " you create a loop that will check events for you and your task is to provide handlers for these events.
It is almost impossible to mix these completely different models. If you want to apply a Motif UI to your app you have to make the app work with X/Motif I'm afraid.

>>Now I want to get the same response from a popup text entry window
And that's what you get from X/Motif. You provided a handler for that input event and have to deal with the data. The main() function is there to create widgets and to instantiate the main X event loop. Every action in the system is triggered by some type of event.