コード例 #1
0
ファイル: exmpp_xml.c プロジェクト: ASalimov/exmpp
int
make_attribute(struct exmpp_xml_ctx *ctx,
    const char *ns, int ns_len,
    const char *attr, int attr_len,
    const char *value, int value_len)
{
	ei_x_buff *tree;

	tree = ctx->current_tree;

	/* Start #xmlattr record. */
	ei_x_encode_list_header(tree, 1);
	ei_x_encode_tuple_header(tree, 4);
	ei_x_encode_atom(tree, "xmlattr");

	/* Check if the namespace is known and encode it. */
	encode_ns(ctx, tree, ns, ns_len);

	/* Check if the attribute is known and encode it. */
	encode_attr(ctx, tree, attr, attr_len);

	/* Encode the value. */
	if (value_len == -1)
		ei_x_encode_binary(tree, value, strlen(value));
	else
		ei_x_encode_binary(tree, value, value_len);

	return (0);
}
コード例 #2
0
ファイル: codec.c プロジェクト: tidatida/alarmd
void
encode_event(DBusMessageIter *iter, int *err, const alarm_event_t *eve,
             const char **def_args)
{
  encode_cookie   (iter, err, &eve->ALARMD_PRIVATE(cookie));
  encode_time     (iter, err, &eve->ALARMD_PRIVATE(trigger));
  encode_string   (iter, err, &eve->title);
  encode_string   (iter, err, &eve->message);
  encode_string   (iter, err, &eve->sound);
  encode_string   (iter, err, &eve->icon);
  encode_unsigned (iter, err, &eve->flags);
  encode_string   (iter, err, &eve->alarm_appid);
  encode_time     (iter, err, &eve->alarm_time);
  encode_tm       (iter, err, &eve->alarm_tm);
  encode_string   (iter, err, &eve->alarm_tz);
  encode_time     (iter, err, &eve->recur_secs);
  encode_int      (iter, err, &eve->recur_count);
  encode_time     (iter, err, &eve->snooze_secs);
  encode_time     (iter, err, &eve->snooze_total);

  encode_size     (iter, err, &eve->action_cnt);
  encode_int      (iter, err, &eve->response);

  for( size_t i = 0; i < eve->action_cnt; ++i )
  {
    encode_action(iter, err, &eve->action_tab[i], def_args);
  }

  encode_size     (iter, err, &eve->recurrence_cnt);
  for( size_t i = 0; i < eve->recurrence_cnt; ++i )
  {
    encode_recur(iter, err, &eve->recurrence_tab[i]);
  }

  encode_size     (iter, err, &eve->attr_cnt);
  for( size_t i = 0; i < eve->attr_cnt; ++i )
  {
    encode_attr(iter, err, eve->attr_tab[i]);
  }
}
コード例 #3
0
ファイル: exmpp_xml.c プロジェクト: ASalimov/exmpp
int
make_attribute_legacy(struct exmpp_xml_ctx *ctx,
    const char *attr, int attr_len,
    const char *value, int value_len)
{
	ei_x_buff *tree;

	tree = ctx->current_tree;

	/* Start a simple tuple. */
	ei_x_encode_list_header(tree, 1);
	ei_x_encode_tuple_header(tree, 2);

	/* Check if the attribute is known and encode it. */
	encode_attr(ctx, tree, attr, attr_len);

	/* Encode the value. */
	if (value_len == -1)
		ei_x_encode_string(tree, value);
	else
		ei_x_encode_string_len(tree, value, value_len);

	return (0);
}
コード例 #4
0
ファイル: lib_screen.c プロジェクト: kleopatra999/ncurses-1
putwin(WINDOW *win, FILE *filep)
{
    int code = ERR;
    int y;

    T((T_CALLED("putwin(%p,%p)"), (void *) win, (void *) filep));

#if NCURSES_EXT_PUTWIN
    if (win != 0) {
	const char *version = curses_version();
	char buffer[1024];
	NCURSES_CH_T last_cell;

	memset(&last_cell, 0, sizeof(last_cell));

	clearerr(filep);

	/*
	 * Our magic number is technically nonprinting, but aside from that,
	 * all of the file is printable ASCII.
	 */
#define PUTS(s) if (fputs(s, filep) == EOF || ferror(filep)) returnCode(code)
	PUTS(my_magic);
	PUTS(version);
	PUTS("\n");
	for (y = 0; y < (int) SIZEOF(scr_params); ++y) {
	    const char *name = scr_params[y].name;
	    const char *data = (char *) win + scr_params[y].offset;
	    const void *dp = (const void *) data;

	    *buffer = '\0';
	    if (!strncmp(name, "_pad.", 5) && !(win->_flags & _ISPAD)) {
		continue;
	    }
	    switch (scr_params[y].type) {
	    case pATTR:
		encode_attr(buffer, (*(const attr_t *) dp) & ~A_CHARTEXT, A_NORMAL);
		break;
	    case pBOOL:
		if (!(*(const bool *) data)) {
		    continue;
		}
		strcpy(buffer, name);
		name = "flag";
		break;
	    case pCHAR:
		encode_attr(buffer, *(const attr_t *) dp, A_NORMAL);
		break;
	    case pINT:
		if (!(*(const int *) dp))
		    continue;
		sprintf(buffer, "%d", *(const int *) dp);
		break;
	    case pSHORT:
		if (!(*(const short *) dp))
		    continue;
		sprintf(buffer, "%d", *(const short *) dp);
		break;
	    case pSIZE:
		if (!(*(const NCURSES_SIZE_T *) dp))
		    continue;
		sprintf(buffer, "%d", *(const NCURSES_SIZE_T *) dp);
		break;
#if NCURSES_WIDECHAR
	    case pCCHAR:
		encode_cell(buffer, (CARG_CH_T) dp, CHREF(last_cell));
		break;
#endif
	    }
	    /*
	     * Only write non-default data.
	     */
	    if (*buffer != '\0') {
		if (fprintf(filep, "%s=%s\n", name, buffer) <= 0
		    || ferror(filep))
		    returnCode(code);
	    }
	}
	/* Write row-data */
	fprintf(filep, "rows:\n");
	for (y = 0; y <= win->_maxy; y++) {
	    NCURSES_CH_T *data = win->_line[y].text;
	    int x;
	    if (fprintf(filep, "%d:", y + 1) <= 0
		|| ferror(filep))
		returnCode(code);
	    for (x = 0; x <= win->_maxx; x++) {
#if NCURSES_WIDECHAR
		int len = wcwidth(data[x].chars[0]);
		encode_cell(buffer, CHREF(data[x]), CHREF(last_cell));
		last_cell = data[x];
		PUTS(buffer);
		if (len > 1)
		    x += (len - 1);
#else
		encode_cell(buffer, CHREF(data[x]), CHREF(last_cell));
		last_cell = data[x];
		PUTS(buffer);
#endif
	    }
	    PUTS("\n");
	}
	code = OK;
    }
#else
    /*
     * This is the original putwin():
     * A straight binary dump is simple, but its format can depend on whether
     * ncurses is compiled with wide-character support, and also may depend
     * on the version of ncurses, e.g., if the WINDOW structure is extended.
     */
    if (win != 0) {
	size_t len = (size_t) (win->_maxx + 1);

	clearerr(filep);
	if (fwrite(win, sizeof(WINDOW), (size_t) 1, filep) != 1
	    || ferror(filep))
	      returnCode(code);

	for (y = 0; y <= win->_maxy; y++) {
	    if (fwrite(win->_line[y].text,
		       sizeof(NCURSES_CH_T), len, filep) != len
		|| ferror(filep)) {
		returnCode(code);
	    }
	}
	code = OK;
    }
#endif
    returnCode(code);
}
コード例 #5
0
ファイル: lib_screen.c プロジェクト: kleopatra999/ncurses-1
static void
encode_cell(char *target, CARG_CH_T source, CARG_CH_T previous)
{
#if NCURSES_WIDECHAR
    size_t n;

    *target = '\0';
    if (previous->attr != source->attr) {
	encode_attr(target, source->attr, previous->attr);
    }
    target += strlen(target);
#if NCURSES_EXT_COLORS
    if (previous->ext_color != source->ext_color) {
	sprintf(target, "%c%cC%d%c", MARKER, L_CURL, source->ext_color, R_CURL);
    }
#endif
    for (n = 0; n < SIZEOF(source->chars); ++n) {
	unsigned uch = (unsigned) source->chars[n];
	if (uch == 0)
	    continue;
	if (n) {
	    *target++ = MARKER;
	    *target++ = APPEND;
	}
	*target++ = MARKER;
	if (uch > 0xffff) {
	    sprintf(target, "U%08x", uch);
	} else if (uch > 0xff) {
	    sprintf(target, "u%04x", uch);
	} else if (uch < 32 || uch >= 127) {
	    sprintf(target, "%03o", uch & 0xff);
	} else {
	    switch (uch) {
	    case ' ':
		strcpy(target, "s");
		break;
	    case MARKER:
		*target++ = MARKER;
		*target = '\0';
		break;
	    default:
		sprintf(--target, "%c", uch);
		break;
	    }
	}
	target += strlen(target);
    }
#else
    chtype ch = CharOfD(source);

    *target = '\0';
    if (AttrOfD(previous) != AttrOfD(source)) {
	encode_attr(target, AttrOfD(source), AttrOfD(previous));
    }
    target += strlen(target);
    *target++ = MARKER;
    if (ch < 32 || ch >= 127) {
	sprintf(target, "%03o", UChar(ch));
    } else {
	switch (ch) {
	case ' ':
	    strcpy(target, "s");
	    break;
	case MARKER:
	    *target++ = MARKER;
	    *target = '\0';
	    break;
	default:
	    sprintf(--target, "%c", UChar(ch));
	    break;
	}
    }
#endif
}