コード例 #1
0
ファイル: request.c プロジェクト: cnh/kurma
// Processing after data for a STRING_LEN state has been read.
static int string_len(struct request *r)
{
	char *p;

	p = (char *) allocate(r, r->string_len + 1, sizeof(char));
	if (p == NULL) {
		// Allocate internally logs and disconnects the client which makes r no
		// longer valid.
		return 1;
	}
	DEBUG("[%d] outer_index=%d inner_len=%d string_len=%d\n", r->fd,
			r->outer_index, r->inner_len, r->string_len);

	// If the string length we are about to read is zero then we need to
	// transition into the done state right away.
	if (r->string_len == 0) {
		return string_done(r);
	} else {
		DEBUG("[%d] Switching to the STRING state.\n", r->fd);
		r->buffer = r->data[r->outer_index][r->inner_index] = p;
		r->buffer_len = r->string_len;
		r->state = STRING;
		return 0;
	}
}
コード例 #2
0
ファイル: Converters.c プロジェクト: aosm/X11
/*ARGSUSED*/
static Boolean
_XawCvtPixelToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		     XrmValue *fromVal, XrmValue *toVal,
		     XtPointer *converter_data)
{
  static char buffer[19];
  Cardinal size;
  Colormap colormap;
  XColor color;

  if (*num_args != 1)
    {
      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		      XtNwrongParameters, "cvtPixelToString",
		      XtCToolkitError,
		      "Pixel to String conversion needs colormap argument",
		      NULL, NULL);
      return (False);
    }

  colormap = *(Colormap *)args[0].addr;
  color.pixel = *(Pixel *)fromVal->addr;

  /* Note:
   * If we know the visual type, we can calculate the xcolor
   * without asking Xlib.
   */
  XQueryColor(dpy, colormap, &color);
  XmuSnprintf(buffer, sizeof(buffer), "rgb:%04hx/%04hx/%04hx",
	      color.red, color.green, color.blue);
  size = strlen(buffer) + 1;

  string_done(buffer);
}
コード例 #3
0
ファイル: Converters.c プロジェクト: aosm/X11
/*ARGSUSED*/
static Boolean
_XawCvtAtomToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		    XrmValue *fromVal, XrmValue *toVal,
		    XtPointer *converter_data)
{
  static char *buffer = NULL;
  static char *nullatom = "NULL";
  Cardinal size;
  Atom atom;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRAtom);

  if (buffer && buffer != nullatom)
    XFree(buffer);

  atom = *(Atom *)fromVal[0].addr;
  if (atom == 0)
    buffer = nullatom;
  else if ((buffer = XGetAtomName(dpy, *(Atom *)fromVal[0].addr)) == NULL)
    {
      XawTypeToStringWarning(dpy, XtRAtom);
      toVal->addr = NULL;
      toVal->size = sizeof(String);
      return (False);
    }

  size = strlen(buffer) + 1;

  string_done(buffer);
}
コード例 #4
0
ファイル: Converters.c プロジェクト: aosm/X11
/*ARGSUSED*/
static Boolean
_XawCvtPixmapToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		      XrmValue *fromVal, XrmValue *toVal,
		      XtPointer *converter_data)
{
  XawPixmap *xaw_pixmap;
  Pixmap pixmap;
  Screen *screen;
  Colormap colormap;
  int depth;
  String buffer = NULL;
  Cardinal size;

  if (*num_args != 3)
    {
      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		      XtNwrongParameters, "cvtPixmapToString",
		      XtCToolkitError,
		      "Pixmap to String conversion needs screen, "
		      "colormap, and depth arguments",
		      NULL, NULL);
      return (False);
    }

  screen     = *(Screen **)args[0].addr;
  colormap   = *(Colormap *)args[1].addr;
  depth      = *(int *)args[2].addr;

  pixmap = *(Pixmap *)(fromVal[0].addr);

  switch (pixmap)
    {
    case None:
      buffer = "None";
      break;
    case ParentRelative:
      buffer = "ParentRelative";
      break;
    case XtUnspecifiedPixmap:
      buffer = "XtUnspecifiedPixmap";
      break;
    default:
      xaw_pixmap = XawPixmapFromXPixmap(pixmap, screen, colormap, depth);
      if (xaw_pixmap)
	buffer = xaw_pixmap->name;
      break;
    }

  if (!buffer)
    /* Bad Pixmap or Pixmap was not loaded by XawLoadPixmap() */
    return (_XawCvtCARD32ToString(dpy, args, num_args, fromVal, toVal,
				  converter_data));

  size = strlen(buffer) + 1;

  string_done(buffer);
}
コード例 #5
0
ファイル: Converters.c プロジェクト: aosm/X11
/*ARGSUSED*/
static Boolean
_XawCvtDisplayListToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			   XrmValue *fromVal, XrmValue *toVal,
			   XtPointer *converter_data)
{
  String buffer;
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XawRDisplayList);

  buffer = XawDisplayListString(*(XawDisplayList **)(fromVal[0].addr));
  size = strlen(buffer) + 1;

  string_done(buffer);
}
コード例 #6
0
ファイル: Converters.c プロジェクト: aosm/X11
/*ARGSUSED*/
static Boolean
_XawCvtCardinalToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			XrmValue *fromVal, XrmValue *toVal,
			XtPointer *converter_data)
{
  static char buffer[11];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRCardinal);

  XmuSnprintf(buffer, sizeof(buffer), "%u", *(Cardinal *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}
コード例 #7
0
ファイル: Converters.c プロジェクト: aosm/X11
/*ARGSUSED*/
static Boolean
_XawCvtBooleanToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		       XrmValue *fromVal, XrmValue *toVal,
		       XtPointer *converter_data)
{
  static char buffer[6];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRBoolean);

  XmuSnprintf(buffer, sizeof(buffer), "%s",
	      *(Boolean *)fromVal->addr ? XtEtrue : XtEfalse);
  size = strlen(buffer) + 1;

  string_done(buffer);
}
コード例 #8
0
ファイル: symboltable.cpp プロジェクト: kewlgrapes/kestrel
symbol_handle symbol_lookup() {
  string_done();
  symbol_handle place = _symbol_hash;

  for (;;) {
    if (_symbol_table[place] == STRING_NULL) {
      // add symbol to table
      _symbol_table[place] = _symbol_string;
      string_accept();
      return place;
    }
    if (!string_eq(_symbol_table[place], _symbol_string)) {
      // symbol is already in the table
      string_reject();
      return place;
    }
    place += 1;
    if (place == SYMBOL_SIZE) place = 0;
    if (place == _symbol_hash) error_fatal(ER_HASHFULL, "Symbol table");
  }
}
コード例 #9
0
ファイル: Converters.c プロジェクト: aosm/X11
/*ARGSUSED*/
static Boolean
_XawCvtFontStructToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			  XrmValue *fromVal, XrmValue *toVal,
			  XtPointer *converter_data)
{
  static char buffer[128];
  Cardinal size;
  Atom atom;
  unsigned long value;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRFontStruct);

  if ((atom = XInternAtom(dpy, "FONT", True)) == None)
    return (False);

  size = 0;

  if (XGetFontProperty(*(XFontStruct **)fromVal->addr, atom, &value))
    {
      char *tmp = XGetAtomName(dpy, value);

      if (tmp)
	{
	  XmuSnprintf(buffer, sizeof(buffer), "%s", tmp);
	  size = strlen(tmp);
	  XFree(tmp);
	}
    }

  if (size)
    {
      ++size;
    string_done(buffer);
    }

  XawTypeToStringWarning(dpy, XtRFontStruct);

  return (False);
}
コード例 #10
0
ファイル: request.c プロジェクト: cnh/kurma
// Documented in cinitd.h
void initd_request_read(struct request *r)
{
	ssize_t bytes;
	int total = r->buffer_len;

	while (true) {
		// Attempt to read into the string that we are reading from. This can be the
		// size buffer or a real string but either way the call is the same.
		bytes = read(r->fd, r->buffer, r->buffer_len);
		if (bytes == -1) {
			if (errno == EAGAIN || errno == EWOULDBLOCK) {
				// Reading from this file descriptor would have blocked so we return and
				// wait for data to become available later.
				return;
			} else if (errno == EINTR) {
				// We got interrupted by a signal. Retry.
				continue;
			}

			// This is an unknown error.
			ERROR("[%d] Error in read(): %s\n", r->fd, strerror(errno));
			initd_request_remove(r);
			return;
		}
		r->buffer += (int)(bytes);
		r->buffer_len -= (int)(bytes);

		// Check to see if this was the last of the string that needed to be
		// read. If not then we need to bail out since the request is not ready to
		// be processed anyway.
		if (r->buffer_len > 0) {
			DEBUG("Only read %d of %d, looping back\n", (int)bytes, total);
			continue;
		}

		// See what action should be taken based on the state of the request.
		switch (r->state) {
		case PROTO:
			if (read_int(r, &r->protocol, proto)) {
				// read_int logs errors internally.
				return;
			}
			break;
		case OUTER_LEN:
			if (read_int(r, &r->outer_len, outer_len)) {
				// read_int logs errors internally.
				return;
			}
			break;
		case INNER_LEN:
			if (read_int(r, &r->inner_len, inner_len)) {
				// read_int logs errors internally.
				return;
			}
			break;
		case STRING_LEN:
			if (read_int(r, &r->string_len, string_len)) {
				// read_int logs errors internally.
				return;
			}
			break;
		case STRING:
			if (string_done(r)) {
				// string() logs error internally.
				return;
			}
			break;
		default:
			ERROR("[%d] Request is in an unknown state: %d\n", r->fd, r->state);
			initd_response_internal_error(r);
			return;
		}
	}
}