Exemple #1
0
static status
callCv(CObj host, CPointer function, int argc, Any *argv)
{ status rval;
  SendFunc f = (SendFunc) function->pointer;
  int n;

  for(n=0; n<argc; n++)
    if ( isObject(argv[n]) )
      addCodeReference(argv[n]);

  switch(argc)
  { case 0: rval = (*f)(); break;
    case 1: rval = (*f)(argv[0]); break;
    case 2: rval = (*f)(argv[0], argv[1]); break;
    case 3: rval = (*f)(argv[0], argv[1], argv[2]); break;
    case 4: rval = (*f)(argv[0], argv[1], argv[2], argv[3]); break;
    case 5: rval = (*f)(argv[0], argv[1], argv[2], argv[3], argv[4]); break;
    case 6: rval = (*f)(argv[0], argv[1], argv[2], argv[3], argv[4],
		        argv[5]); break;
    case 7: rval = (*f)(argv[0], argv[1], argv[2], argv[3], argv[4],
		        argv[5], argv[6]); break;
    case 8: rval = (*f)(argv[0], argv[1], argv[2], argv[3], argv[4],
		        argv[5], argv[6], argv[7]); break;
    case 9: rval = (*f)(argv[0], argv[1], argv[2], argv[3], argv[4],
		        argv[5], argv[6], argv[7], argv[8]); break;
    default:
      rval = errorPce(host, NAME_tooManyArguments, argc);
  }

  for(n=0; n<argc; n++)
    if ( isObject(argv[n]) && !isFreedObj(argv[n]) )
      delCodeReference(argv[n]);

  return rval ? SUCCEED : FAIL;
}
Exemple #2
0
static ssize_t
Swrite_object(void *handle, char *buf, size_t size)
{ OpenObject h = handle;
  string s;
  CharArray ca;
  status rval;
  Int where = toInt(h->point);
  size_t advance;

  if ( isFreedObj(h->object) )
  { errno = EIO;
    return -1;
  }

  if ( h->encoding == ENC_WCHAR )
  { const wchar_t *wbuf = (const wchar_t*)buf;
    const wchar_t *end = (const wchar_t*)&buf[size];
    const wchar_t *f;

    assert(size%sizeof(wchar_t) == 0);
    advance = size/sizeof(wchar_t);

    for(f=wbuf; f<end; f++)
    { if ( *f > 0xff )
	break;
    }

    if ( f == end )
    { charA *asc = alloca(size);
      charA *t = asc;

      for(f=wbuf; f<end; )
	*t++ = (charA)*f++;

      str_set_n_ascii(&s, advance, (char*)asc);
    } else
    { str_set_n_wchar(&s, advance, (wchar_t*)wbuf);
    }
  } else if ( h->encoding == ENC_OCTET )
  { advance = size;
    str_set_n_ascii(&s, size, buf);
  } else
  { assert(0);
    errno = EIO;
    return -1;
  }

  ca = StringToScratchCharArray(&s);

  if ( (rval = send(h->object, NAME_writeAsFile, where, ca, EAV)) )
    h->point += (long)advance;
  doneScratchCharArray(ca);

  if ( rval )
    return size;

  errno = EIO;
  return -1;
}
Exemple #3
0
int
pceExistsReference(uintptr_t ref)
{ Any addr = longToPointer(ref);

  if ( !isProperObject(addr) || isFreedObj(addr) )
    return PCE_FAIL;

  return PCE_SUCCEED;
}
Exemple #4
0
int
pceExistsAssoc(PceName assoc)
{ Any addr;

  if ( !(addr = getObjectAssoc(assoc)) )
    return PCE_FAIL;
  if ( !isProperObject(addr) || isFreedObj(addr) )
    return PCE_FAIL;

  return PCE_SUCCEED;
}
Exemple #5
0
status
unlinkLayoutInterface(Any obj)
{ LayoutInterface itf = obj;

  if ( notNil(itf->image) && !isFreedObj(itf->image) )
  { Any nil = NIL;

    return qadSendv(itf->image, NAME_layoutInterface, 1, &nil);
  }

  succeed;
}
Exemple #6
0
static status
executeLabel(Label lb)
{ if ( notNil(lb->message) && notDefault(lb->message) )
  { statusLabel(lb, NAME_execute);
    flushGraphical(lb);
    forwardReceiverCode(lb->message, lb, EAV);
    if ( !isFreedObj(lb) )
    { statusLabel(lb, NAME_inactive);
      flushGraphical(lb);
    }
  }

  succeed;
}
Exemple #7
0
static int
Sclose_object(void *handle)
{ OpenObject h = handle;

  if ( isFreedObj(h->object) )
  { errno = EIO;
    return -1;
  }

  delCodeReference(h->object);
  freeableObj(h->object);

  unalloc(sizeof(*h), h);

  return 0;
}
Exemple #8
0
static Any
getCallHostv(Host host, Name selector, int argc, Any *argv)
{ Any rval;
  int n;

  for(n=0; n<argc; n++)
    if ( isObject(argv[n]) )
      addCodeReference(argv[n]);

  rval = hostGet(host, selector, argc, argv);

  for(n=0; n<argc; n++)
    if ( isObject(argv[n]) && !isFreedObj(argv[n]) )
      delCodeReference(argv[n]);

  return rval;
}
Exemple #9
0
static void
event_window(Widget w, XtPointer xsw, XtPointer xevent)
{ PceWindow sw = (PceWindow) xsw;
  XEvent *event = (XEvent *)xevent;

  pceMTLock(LOCK_PCE);
  DEBUG(NAME_event, Cprintf("event_window(): X-event %d on %s\n",
			    event->xany.type, pp(sw)));

  if ( isFreeingObj(sw) || isFreedObj(sw) || sw->sensitive == OFF )
  { pceMTUnlock(LOCK_PCE);
    return;
  }

  ServiceMode(is_service_window(sw),
	      { AnswerMark mark;
		markAnswerStack(mark);

		x_event_window(sw, event);

		rewindAnswerStack(mark, NIL);
	      });
Exemple #10
0
static long
Sseek_object(void *handle, long pos, int whence)
{ OpenObject h = handle;
  Int size;
  int usize = (h->encoding == ENC_WCHAR ? sizeof(wchar_t) : 1);

  pos /= usize;

  if ( isFreedObj(h->object) )
  { errno = EIO;
    return -1;
  }

  switch(whence)
  { case SIO_SEEK_SET:
      h->point = pos;
      break;
    case SIO_SEEK_CUR:
      h->point += pos;			/* check for end!? */
      break;
    case SIO_SEEK_END:
    { if ( hasGetMethodObject(h->object, NAME_sizeAsFile) &&
	   (size = get(h->object, NAME_sizeAsFile, EAV)) )
      { h->point = valInt(size) - pos;
	break;
      } else
      { errno = EPIPE;			/* better idea? */
	return -1;
      }
    }
    default:
    { errno = EINVAL;
      return -1;
    }
  }

  return h->point * usize;
}
Exemple #11
0
static ssize_t
Sread_object(void *handle, char *buf, size_t size)
{ OpenObject h = handle;
  Any argv[2];
  CharArray sub;
  int chread;
  size_t advance;

  if ( isFreedObj(h->object) )
  { errno = EIO;
    return -1;
  }

  if ( h->encoding == ENC_WCHAR )
  { advance = size/sizeof(wchar_t);
  } else if ( h->encoding == ENC_OCTET )
  { advance = size;
  } else
  { assert(0);
    errno = EIO;
    return -1;
  }

  argv[0] = toInt(h->point);
  argv[1] = toInt(advance);

  if ( (sub = getv(h->object, NAME_readAsFile, 2, argv)) &&
       instanceOfObject(sub, ClassCharArray) )
  { String s = &sub->data;

    assert(s->size <= advance);

    if ( h->encoding == ENC_WCHAR )
    { if ( isstrA(s) )
      { charW *dest = (charW*)buf;
	const charA *f = s->s_textA;
	const charA *e = &f[s->size];

	while(f<e)
	  *dest++ = *f++;
      } else
      { memcpy(buf, s->s_textW, s->size*sizeof(charW));
      }
      chread = s->size * sizeof(wchar_t);
    } else
    { if ( isstrA(s) )
      { memcpy(buf, s->s_textA, s->size);
      } else
      { errno = EIO;
	chread = -1;
      }
      chread = s->size;
    }

    h->point += s->size;
  } else
  { errno = EIO;
    chread = -1;
  }

  return chread;
}