コード例 #1
0
ファイル: comm.c プロジェクト: idunham/dtextra
/* ARGSUSED */
static void
GetClientValue(Widget w, XtPointer data, Atom *selection, Atom *type,
               XtPointer value, unsigned long *length,  int *format)
{
  Event          *event;
  ProtocolStream alloc_stream;
  ProtocolStream *stream;
  unsigned char  ident;
  unsigned char  error_code;
  char           *error_str;
  char           msg[BUFSIZ];


/* type should be checked if XT_CONVERT_FAIL */

  if (*length == 0)
    {
      return;
    }

  stream = &alloc_stream;	/* easier to think of it this way... */

  stream->current = stream->top = (unsigned char*)value;
  stream->size = HEADER_SIZE;		/* size of header. */

  /*
   * Retrieve the Header.
   */

  if (*length < HEADER_SIZE)
    {
      /* "Incorrectly formatted message from client" */
      SetMessage(global_screen_data.info_label,
		 res_labels[9],
		 "Incorrectly formatted message from client");
      return;
    }

  (void)_XEditResGet8(stream, &ident);
  if (global_client.ident != ident)
    {

#ifdef DEBUG
      if (global_resources.debug)
	{
	  printf("Incorrect ident from client.\n");
	}
#endif  /* DEBUG */

      if (!XtOwnSelection(w,
			  *selection,
			  CurrentTime,
			  ConvertCommand, 
			  LoseSelection,
			  SelectionDone))
	{
	  /* "Unable to own the Resource Editor Command Selection" */
	  SetMessage(global_screen_data.info_label,
		     res_labels[10],
		     "Unable to own the Resource Editor Command Selection");
	}

	return;

    }   /* if (global_client.ident != ident) */

    (void)_XEditResGet8(stream, &error_code);
    (void)_XEditResGet32(stream, &(stream->size));
    stream->top = stream->current;   /* reset stream to top of value.*/

    switch ((int)error_code)
      {
      case PartialSuccess:
        /*****
        if (global_client.command == LocalSendWidgetTree &&
	    global_effective_protocol_version < CURRENT_PROTOCOL_VERSION)
          {
	    ++global_effective_protocol_version;
          }
	*****/
	if ((event = BuildEvent(stream)) != NULL)
	  {
	    error_str = DispatchEvent(event);
	    FreeEvent(event);
	  }
	else
	  {
	    sprintf(msg,
		    "Unable to unpack protocol request.");
	    error_str = XtNewString(msg);
	  }
	break;   /* PartialSuccess */

      case Failure:
	error_str = GetFailureMessage(stream);
	break;   /* Failure */

      case ProtocolMismatch:
	error_str = ProtocolFailure(stream);
	--global_effective_protocol_version;
	/* normaly protocol version is reset to current during a SendWidgetTree
         * request, however, after a protocol failure this is skiped once for
         * a retry.
         */
	reset_protocol_level = False;
	SetCommand(w,
		   LocalSendWidgetTree,
		   NULL);
	break;   /* ProtocolMismatch */

	default:
		/* "Unknown Error code %s" */
		if (res_labels[11]) {
			sprintf(msg, res_labels[11], (int)error_code);
		} else {
			sprintf(msg, "Unknown Error code %i", (int)error_code);
		}
		SetMessage(global_screen_data.info_label, msg, "?res_labels[11]");
		break;    /* default */
	}   /* switch (error_code) */

    if (error_str == NULL)
      {
	WNode *top;


	if (global_tree_info == NULL)
	  {
	    return;
	  }
	
	top = global_tree_info->top_node;
	/* "Widget/Style tree for client %s (%s)" */
	if (res_labels[12])
	  {
	    sprintf(msg,
		    res_labels[12],
		    top->name,
		    top->class);
	  }
	else
	  {
コード例 #2
0
ファイル: comm.c プロジェクト: Bluerise/bitrig-xenocara
/* ARGSUSED */
static void
GetClientValue(Widget w, XtPointer data, Atom *selection, Atom *type,
	       XtPointer value, unsigned long *length, int *format)
{
    Event * event;
    ProtocolStream alloc_stream, *stream;
    unsigned char ident, error_code;
    char * error_str = NULL, msg[BUFSIZ];

    if (*length == 0)
	return;

    stream = &alloc_stream;	/* easier to think of it this way... */

    stream->current = stream->top = (unsigned char *) value;
    stream->size = HEADER_SIZE;		/* size of header. */

    /*
     * Retrieve the Header.
     */

    if (*length < HEADER_SIZE) {
	SetMessage(global_screen_data.info_label,
		   res_labels[9]);
	return;
    }

    (void) _XEditResGet8(stream, &ident);
    if (global_client.ident != ident) {
#ifdef DEBUG
	if (global_resources.debug)
	    printf("Incorrect ident from client.\n");
#endif 
	if (!XtOwnSelection(w, *selection, CurrentTime, ConvertCommand, 
			    LoseSelection, SelectionDone))
	    SetMessage(global_screen_data.info_label,
		       res_labels[10]);
	return;
    }

    (void) _XEditResGet8(stream, &error_code); 
    (void) _XEditResGet32(stream, &(stream->size));
    stream->top = stream->current; /* reset stream to top of value.*/

    switch ((int) error_code) {
    case PartialSuccess:
/*****
        if (global_client.command == LocalSendWidgetTree &&
	    global_effective_protocol_version < CURRENT_PROTOCOL_VERSION)
	  ++global_effective_protocol_version;
*****/
	if ((event = BuildEvent(stream)) != NULL) {
	    error_str = DispatchEvent(event);
	    FreeEvent(event);
	}
	else {
	    sprintf(msg, "Unable to unpack protocol request.");
	    error_str = XtNewString(msg);
	}
	break;
    case Failure:
	error_str = GetFailureMessage(stream);
	break;
    case ProtocolMismatch:
	error_str = ProtocolFailure(stream);
	--global_effective_protocol_version;
	/* normaly protocol version is reset to current during a SendWidgetTree
         * request, however, after a protocol failure this is skiped once for
         * a retry.
         */
	reset_protocol_level = False;
	SetCommand(w, LocalSendWidgetTree, NULL);
	break;
    default:
	sprintf(msg, res_labels[11], (int) error_code);
	SetMessage(global_screen_data.info_label, msg);
	break;
    }

    if (error_str == NULL) {
	WNode * top;
	
	if (global_tree_info == NULL)
	    return;
	
	top = global_tree_info->top_node;
	sprintf(msg, res_labels[12], top->name, top->class);
	SetMessage(global_screen_data.info_label, msg);
	return;
    }