LJ Archive

Listing 4. Ttchmodd: ToolTalk Message Receiver

void ToolTalkCB (w, clientData, callData)
/*  widget id     */
Widget     w;
/*  data from application   */
xTpointer       clientData;
/*  data from widget class  */
XtPointer       callData;
{
Tt_message incoming;
Tt_status ttrc;
int ttmark, args;
char *filename;
char *mode;
char command[BUFSIZ];
XmString xmcmd;
ttmark = tt_mark();
incoming = tt_message_receive();
ToolTalkAbort("ToolTalkCB():
   tt_message_receive",
   tt_ptr_error(incoming));
if (incoming && (0 ==
   strcmp(tt_message_op(incoming), "Chmod")))
   {
   args = tt_message_args_count(incoming);
   ToolTalkAbort("ToolTalkCB():
      tt_message_args_count",
      tt_int_error(args));
   filename = tt_message_arg_val(incoming, 0);
   ToolTalkAbort("ToolTalkCB():
      tt_message_arg_val",
      tt_ptr_error(filename));
   mode = tt_message_arg_val(incoming, 1);
   ToolTalkAbort("ToolTalkCB():
      tt_message_arg_val",
      tt_ptr_error(mode));
   ttrc = tt_message_reply(incoming);
   ToolTalkAbort("ToolTalkCB():
      tt_message_destroy", ttrc);
   sprintf(command,
      "/bin/chmod %s %s\n",
      mode, filename);
   xmcmd = XmStringCreateLocalized(command);
   XmCommandSetValue(w, xmcmd);
   XmStringFree(xmcmd);
   }
else {
   printf("ToolTalkCB(): unknown message %s.\n",
      tt_message_op(incoming));
   }
ttrc = tt_message_destroy(incoming);
ToolTalkAbort("ToolTalkCB():
   tt_message_destroy", ttrc);
tt_release(ttmark);
}
ToolTalkAbort(char *procname, Tt_status errid)
{
if (tt_is_err(errid)) {
   fprintf(stderr,
      "%s returned ToolTalk error: %s\n",
      procname, tt_status_message(errid));
   exit(1);
   }
}
LJ Archive