コード例 #1
0
ファイル: options_f.c プロジェクト: Alkzndr/freebsd
/*
 * PUBLIC: int f_lines __P((SCR *, OPTION *, char *, u_long *));
 */
int
f_lines(
	SCR *sp,
	OPTION *op,
	char *str,
	u_long *valp)
{
	/* Validate the number. */
	if (*valp < MINIMUM_SCREEN_ROWS) {
		msgq(sp, M_ERR, "042|Screen lines too small, less than %d",
		    MINIMUM_SCREEN_ROWS);
		return (1);
	}

	/*
	 * !!!
	 * It's not uncommon for allocation of huge chunks of memory to cause
	 * core dumps on various systems.  So, we prune out numbers that are
	 * "obviously" wrong.  Vi will not work correctly if it has the wrong
	 * number of lines/columns for the screen, but at least we don't drop
	 * core.
	 */
#define	MAXIMUM_SCREEN_ROWS	500
	if (*valp > MAXIMUM_SCREEN_ROWS) {
		msgq(sp, M_ERR, "043|Screen lines too large, greater than %d",
		    MAXIMUM_SCREEN_ROWS);
		return (1);
	}

	/*
	 * Set the value, and the related scroll value.  If no window
	 * value set, set a new default window.
	 */
	o_set(sp, O_LINES, 0, NULL, *valp);
	if (*valp == 1) {
		sp->defscroll = 1;

		if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
		    O_VAL(sp, O_WINDOW) > *valp) {
			o_set(sp, O_WINDOW, 0, NULL, 1);
			o_set(sp, O_WINDOW, OS_DEF, NULL, 1);
		}
	} else {
		sp->defscroll = (*valp - 1) / 2;

		if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
		    O_VAL(sp, O_WINDOW) > *valp) {
			o_set(sp, O_WINDOW, 0, NULL, *valp - 1);
			o_set(sp, O_WINDOW, OS_DEF, NULL, *valp - 1);
		}
	}
	return (0);
}
コード例 #2
0
Object Variant::toObjectHelper() const {
  switch (m_type) {
    case KindOfUninit:
    case KindOfNull:
      return SystemLib::AllocStdClassObject();

    case KindOfBoolean:
    case KindOfInt64:
    case KindOfDouble:
    case KindOfStaticString:
    case KindOfString:
    case KindOfResource: {
      auto obj = SystemLib::AllocStdClassObject();
      obj->o_set(s_scalar, *this, false);
      return obj;
    }

    case KindOfArray:
      return ObjectData::FromArray(m_data.parr);

    case KindOfObject:
      return m_data.pobj;

    case KindOfRef:
      return m_data.pref->var()->toObject();

    case KindOfClass:
      break;
  }
  not_reached();
}
コード例 #3
0
ファイル: options_f.c プロジェクト: Alkzndr/freebsd
/*
 * PUBLIC: int f_print __P((SCR *, OPTION *, char *, u_long *));
 */
int
f_print(
	SCR *sp,
	OPTION *op,
	char *str,
	u_long *valp)
{
	int offset = op - sp->opts;

	/* Preset the value, needed for reinitialization of lookup table. */
	if (offset == O_OCTAL) {
		if (*valp)
			O_SET(sp, offset);
		else
			O_CLR(sp, offset);
	} else if (o_set(sp, offset, OS_STRDUP, str, 0))
		return(1);

	/* Reinitialize the key fast lookup table. */
	v_key_ilookup(sp);

	/* Reformat the screen. */
	F_SET(sp, SC_SCR_REFORMAT);
	return (0);
}
コード例 #4
0
ファイル: ext_imap.cpp プロジェクト: bd808/hhvm
static Variant HHVM_FUNCTION(imap_check, const Resource& imap_stream) {
  auto obj = cast<ImapStream>(imap_stream);
  if (mail_ping(obj->m_stream) == NIL) {
    return false;
  }
  if (obj->m_stream && obj->m_stream->mailbox) {
    auto ret = SystemLib::AllocStdClassObject();
    char date[100];
    rfc822_date(date);
    ret.o_set("Date", String(date, CopyString));
    ret.o_set("Driver", String(obj->m_stream->dtb->name, CopyString));
    ret.o_set("Mailbox", String(obj->m_stream->mailbox, CopyString));
    ret.o_set("Nmsgs", (int64_t)obj->m_stream->nmsgs);
    ret.o_set("Recent", (int64_t)obj->m_stream->recent);
    return ret;
  }
  return false;
}
コード例 #5
0
ファイル: conv.c プロジェクト: VargMon/netbsd-cvs-mirror
void
conv_init (SCR *orig, SCR *sp)
{
    if (orig != NULL)
	MEMCPY(&sp->conv, &orig->conv, 1);
    else {
	setlocale(LC_ALL, "");
#ifdef USE_WIDECHAR
	sp->conv.sys2int = cs_char2int;
	sp->conv.int2sys = cs_int2char;
	sp->conv.file2int = fe_char2int;
	sp->conv.int2file = fe_int2char;
	sp->conv.input2int = ie_char2int;
#endif
#ifdef USE_ICONV
	o_set(sp, O_FILEENCODING, OS_STRDUP, nl_langinfo(CODESET), 0);
	o_set(sp, O_INPUTENCODING, OS_STRDUP, nl_langinfo(CODESET), 0);
#endif
    }
}
コード例 #6
0
void Mapping::sort_as(const Mapping & map)
{
    object_list_type n;
    std::set<Object> t_set(this->_lst.begin(), this->_lst.end());
    for(object_list_type::const_iterator i = map._lst.begin(); i != map._lst.end(); ++i)
    {
        if(t_set.find(*i) != t_set.end())
        {
            n.push_back(*i);
        }
    }
    std::set<Object> o_set(n.begin(), n.end());
    for(object_list_type::const_iterator i = this->_lst.begin(); i != this->_lst.end(); ++i)
    {
        if(o_set.find(*i) == o_set.end())
        {
            n.push_back(*i);
        }
        else
        {
            // key is also in "map"
            Object & tv = this->at(*i);
            const Object & ov = map.at(*i);
            if(tv.is<Mapping>() && ov.is<Mapping>())
            {
                Mapping & tm = reinterpret_cast<Mapping &>(tv.get_object());
                const Mapping & om = reinterpret_cast<const Mapping &>(ov.get_object());
                tm.sort_as(om);
            }
        }
    }
    if(this->_lst.size() != n.size())
    {
        std::cerr << "internal error" << std::endl;
        std::cerr << "this->_lst: " << this->_lst.size() << std::endl;
        for(object_list_type::const_iterator i = this->_lst.begin(); i != this->_lst.end(); ++i)
        {
            std::cerr << "   " << i->repr() << std::endl;
        }
        std::cerr << "n: " << n.size() << std::endl;
        for(object_list_type::const_iterator i = n.begin(); i != n.end(); ++i)
        {
            std::cerr << "   " << i->repr() << std::endl;
        }
        std::cout << this->_lst.size() << " " << n.size() << std::endl;
        throw InternalError(DEBUG_INFO, "key sorting was not successful");
        assert(false);
    }
    this->_lst = n;
}
コード例 #7
0
ファイル: ext_datetime.cpp プロジェクト: Kofel/hhvm
Array c_DateTime::t___sleep() {
  o_set(s__date_time, t_format(s_c));
  return make_packed_array(s__date_time);
}
コード例 #8
0
ファイル: options.c プロジェクト: Hooman3/minix
/*
 * opts_set --
 *	Change the values of one or more options.
 *
 * PUBLIC: int opts_set __P((SCR *, ARGS *[], const char *));
 */
int
opts_set(SCR *sp, ARGS **argv, const char *usage)
{
	enum optdisp disp;
	enum nresult nret;
	OPTLIST const *op;
	OPTION *spo;
	u_long isset, turnoff, value;
	int ch, equals, nf, nf2, offset, qmark, rval;
	CHAR_T *endp, *name, *p, *sep;
	char *p2, *t2;
	const char *np;
	size_t nlen;

	disp = NO_DISPLAY;
	for (rval = 0; argv[0]->len != 0; ++argv) {
		/*
		 * The historic vi dumped the options for each occurrence of
		 * "all" in the set list.  Puhleeze.
		 */
		if (!STRCMP(argv[0]->bp, L("all"))) {
			disp = ALL_DISPLAY;
			continue;
		}

		/* Find equals sign or question mark. */
		for (sep = NULL, equals = qmark = 0,
		    p = name = argv[0]->bp; (ch = *p) != '\0'; ++p)
			if (ch == '=' || ch == '?') {
				if (p == name) {
					if (usage != NULL)
						msgq(sp, M_ERR,
						    "032|Usage: %s", usage);
					return (1);
				}
				sep = p;
				if (ch == '=')
					equals = 1;
				else
					qmark = 1;
				break;
			}

		turnoff = 0;
		op = NULL;
		if (sep != NULL)
			*sep++ = '\0';

		/* Search for the name, then name without any leading "no". */
		if ((op = opts_search(name)) == NULL &&
		    name[0] == L('n') && name[1] == L('o')) {
			turnoff = 1;
			name += 2;
			op = opts_search(name);
		}
		if (op == NULL) {
			opts_nomatch(sp, name);
			rval = 1;
			continue;
		}

		/* Find current option values. */
		offset = op - optlist;
		spo = sp->opts + offset;

		/*
		 * !!!
		 * Historically, the question mark could be a separate
		 * argument.
		 */
		if (!equals && !qmark &&
		    argv[1]->len == 1 && argv[1]->bp[0] == '?') {
			++argv;
			qmark = 1;
		}

		/* Set name, value. */
		switch (op->type) {
		case OPT_0BOOL:
		case OPT_1BOOL:
			/* Some options may not be reset. */
			if (F_ISSET(op, OPT_NOUNSET) && turnoff) {
				msgq_wstr(sp, M_ERR, name,
			    "291|set: the %s option may not be turned off");
				rval = 1;
				break;
			}

			/* Some options may not be set. */
			if (F_ISSET(op, OPT_NOSET) && !turnoff) {
				msgq_wstr(sp, M_ERR, name,
			    "313|set: the %s option may never be turned on");
				rval = 1;
				break;
			}

			if (equals) {
				msgq_wstr(sp, M_ERR, name,
			    "034|set: [no]%s option doesn't take a value");
				rval = 1;
				break;
			}
			if (qmark) {
				if (!disp)
					disp = SELECT_DISPLAY;
				F_SET(spo, OPT_SELECTED);
				break;
			}

			/*
			 * Do nothing if the value is unchanged, the underlying
			 * functions can be expensive.
			 */
			isset = !turnoff;
			if (!F_ISSET(op, OPT_ALWAYS)) {
				if (isset) {
					if (O_ISSET(sp, offset))
						break;
				} else
					if (!O_ISSET(sp, offset))
						break;
			}

			/* Report to subsystems. */
			if ((op->func != NULL &&
			    op->func(sp, spo, NULL, &isset)) ||
			    ex_optchange(sp, offset, NULL, &isset) ||
			    v_optchange(sp, offset, NULL, &isset) ||
			    sp->gp->scr_optchange(sp, offset, NULL, &isset)) {
				rval = 1;
				break;
			}

			/* Set the value. */
			if (isset)
				O_SET(sp, offset);
			else
				O_CLR(sp, offset);
			break;
		case OPT_NUM:
			if (turnoff) {
				msgq_wstr(sp, M_ERR, name,
				    "035|set: %s option isn't a boolean");
				rval = 1;
				break;
			}
			if (qmark || !equals) {
				if (!disp)
					disp = SELECT_DISPLAY;
				F_SET(spo, OPT_SELECTED);
				break;
			}

			if (!ISDIGIT((UCHAR_T)sep[0]))
				goto badnum;
			if ((nret =
			    nget_uslong(sp, &value, sep, &endp, 10)) != NUM_OK) {
				INT2CHAR(sp, name, STRLEN(name) + 1, 
					     np, nlen);
				p2 = msg_print(sp, np, &nf);
				INT2CHAR(sp, sep, STRLEN(sep) + 1, 
					     np, nlen);
				t2 = msg_print(sp, np, &nf2);
				switch (nret) {
				case NUM_ERR:
					msgq(sp, M_SYSERR,
					    "036|set: %s option: %s", p2, t2);
					break;
				case NUM_OVER:
					msgq(sp, M_ERR,
			    "037|set: %s option: %s: value overflow", p2, t2);
					break;
				case NUM_OK:
				case NUM_UNDER:
					abort();
				}
				if (nf)
					FREE_SPACE(sp, p2, 0);
				if (nf2)
					FREE_SPACE(sp, t2, 0);
				rval = 1;
				break;
			}
			if (*endp && !ISBLANK(*endp)) {
badnum:				INT2CHAR(sp, name, STRLEN(name) + 1, 
					     np, nlen);
				p2 = msg_print(sp, np, &nf);
				INT2CHAR(sp, sep, STRLEN(sep) + 1, 
					     np, nlen);
				t2 = msg_print(sp, np, &nf2);
				msgq(sp, M_ERR,
		    "038|set: %s option: %s is an illegal number", p2, t2);
				if (nf)
					FREE_SPACE(sp, p2, 0);
				if (nf2)
					FREE_SPACE(sp, t2, 0);
				rval = 1;
				break;
			}

			/* Some options may never be set to zero. */
			if (F_ISSET(op, OPT_NOZERO) && value == 0) {
				msgq_wstr(sp, M_ERR, name,
			    "314|set: the %s option may never be set to 0");
				rval = 1;
				break;
			}

			/*
			 * Do nothing if the value is unchanged, the underlying
			 * functions can be expensive.
			 */
			if (!F_ISSET(op, OPT_ALWAYS) &&
			    O_VAL(sp, offset) == value)
				break;

			/* Report to subsystems. */
			INT2CHAR(sp, sep, STRLEN(sep) + 1, np, nlen);
			if ((op->func != NULL &&
			    op->func(sp, spo, np, &value)) ||
			    ex_optchange(sp, offset, np, &value) ||
			    v_optchange(sp, offset, np, &value) ||
			    sp->gp->scr_optchange(sp, offset, np, &value)) {
				rval = 1;
				break;
			}

			/* Set the value. */
			if (o_set(sp, offset, 0, NULL, value))
				rval = 1;
			break;
		case OPT_STR:
			if (turnoff) {
				msgq_wstr(sp, M_ERR, name,
				    "039|set: %s option isn't a boolean");
				rval = 1;
				break;
			}
			if (qmark || !equals) {
				if (!disp)
					disp = SELECT_DISPLAY;
				F_SET(spo, OPT_SELECTED);
				break;
			}

			/* Check for strings that must have even length */
			if (F_ISSET(op, OPT_PAIRS) && STRLEN(sep) & 1) {
				msgq_wstr(sp, M_ERR, name,
				    "047|set: the %s option must be in two character groups");
				rval = 1;
				break;
			}

			/*
			 * Do nothing if the value is unchanged, the underlying
			 * functions can be expensive.
			 */
			INT2CHAR(sp, sep, STRLEN(sep) + 1, np, nlen);
			if (!F_ISSET(op, OPT_ALWAYS) &&
			    O_STR(sp, offset) != NULL &&
			    !strcmp(O_STR(sp, offset), np))
				break;

			/* Report to subsystems. */
			if ((op->func != NULL &&
			    op->func(sp, spo, np, NULL)) ||
			    ex_optchange(sp, offset, np, NULL) ||
			    v_optchange(sp, offset, np, NULL) ||
			    sp->gp->scr_optchange(sp, offset, np, NULL)) {
				rval = 1;
				break;
			}

			/* Set the value. */
			if (o_set(sp, offset, OS_STRDUP, np, 0))
				rval = 1;
			break;
		default:
			abort();
		}
	}
	if (disp != NO_DISPLAY)
		opts_dump(sp, disp);
	return (rval);
}
コード例 #9
0
ファイル: options.c プロジェクト: Hooman3/minix
/*
 * opts_init --
 *	Initialize some of the options.
 *
 * PUBLIC: int opts_init __P((SCR *, int *));
 */
int
opts_init(SCR *sp, int *oargs)
{
	ARGS *argv[2], a, b;
	OPTLIST const *op;
	u_long isset, v;
	int cnt, optindx = 0;
	char *s;
	CHAR_T b2[1024];

	if (sizeof optlist / sizeof optlist[0] - 1 != O_OPTIONCOUNT) {
		fprintf(stderr, "vi: option table size error (%d != %d)\n",
		    (int)(sizeof optlist / sizeof optlist[0] - 1),
		    O_OPTIONCOUNT);
		exit(1);
	}

	a.bp = b2;
	b.bp = NULL;
	a.len = b.len = 0;
	argv[0] = &a;
	argv[1] = &b;

	/* Set numeric and string default values. */
#define	OI(indx, str) {							\
	a.len = STRLEN(str);						\
	if ((const CHAR_T*)str != b2)/* GCC puts strings in text-space. */\
		(void)MEMCPY(b2, str, a.len+1);				\
	if (opts_set(sp, argv, NULL)) {					\
		 optindx = indx;					\
		goto err;						\
	}								\
}
	/*
	 * Indirect global options to global space.  Specifically, set up
	 * terminal, lines, columns first, they're used by other options.
	 * Note, don't set the flags until we've set up the indirection.
	 */
	if (o_set(sp, O_TERM, 0, NULL, GO_TERM))
		goto err;
	F_SET(&sp->opts[O_TERM], OPT_GLOBAL);
	if (o_set(sp, O_LINES, 0, NULL, GO_LINES))
		goto err;
	F_SET(&sp->opts[O_LINES], OPT_GLOBAL);
	if (o_set(sp, O_COLUMNS, 0, NULL, GO_COLUMNS))
		goto err;
	F_SET(&sp->opts[O_COLUMNS], OPT_GLOBAL);
	if (o_set(sp, O_SECURE, 0, NULL, GO_SECURE))
		goto err;
	F_SET(&sp->opts[O_SECURE], OPT_GLOBAL);

	/* Initialize string values. */
	(void)SPRINTF(b2, SIZE(b2),
	    L("cdpath=%s"), (s = getenv("CDPATH")) == NULL ? ":" : s);
	OI(O_CDPATH, b2);

	/*
	 * !!!
	 * Vi historically stored temporary files in /var/tmp.  We store them
	 * in /tmp by default, hoping it's a memory based file system.  There
	 * are two ways to change this -- the user can set either the directory
	 * option or the TMPDIR environmental variable.
	 */
	(void)SPRINTF(b2, SIZE(b2),
	    L("directory=%s"), (s = getenv("TMPDIR")) == NULL ? _PATH_TMP : s);
	OI(O_TMP_DIRECTORY, b2);
	OI(O_ESCAPETIME, L("escapetime=1"));
	OI(O_KEYTIME, L("keytime=6"));
	OI(O_MATCHCHARS, L("matchchars=()[]{}<>"));
	OI(O_MATCHTIME, L("matchtime=7"));
	(void)SPRINTF(b2, SIZE(b2), L("msgcat=%s"), _PATH_MSGCAT);
	OI(O_MSGCAT, b2);
	OI(O_REPORT, L("report=5"));
	OI(O_PARAGRAPHS, L("paragraphs=IPLPPPQPP LIpplpipbp"));
	(void)SPRINTF(b2, SIZE(b2), L("path=%s"), "");
	OI(O_PATH, b2);
	(void)SPRINTF(b2, SIZE(b2), L("recdir=%s"), _PATH_PRESERVE);
	OI(O_RECDIR, b2);
	OI(O_SECTIONS, L("sections=NHSHH HUnhsh"));
	(void)SPRINTF(b2, SIZE(b2),
	    L("shell=%s"), (s = getenv("SHELL")) == NULL ? _PATH_BSHELL : s);
	OI(O_SHELL, b2);
	OI(O_SHELLMETA, L("shellmeta=~{[*?$`'\"\\"));
	OI(O_SHIFTWIDTH, L("shiftwidth=8"));
	OI(O_SIDESCROLL, L("sidescroll=16"));
	OI(O_TABSTOP, L("tabstop=8"));
	(void)SPRINTF(b2, SIZE(b2), L("tags=%s"), _PATH_TAGS);
	OI(O_TAGS, b2);

	/*
	 * XXX
	 * Initialize O_SCROLL here, after term; initializing term should
	 * have created a LINES/COLUMNS value.
	 */
	if ((v = (O_VAL(sp, O_LINES) - 1) / 2) == 0)
		v = 1;
	(void)SPRINTF(b2, SIZE(b2), L("scroll=%ld"), v);
	OI(O_SCROLL, b2);

	/*
	 * The default window option values are:
	 *		8 if baud rate <=  600
	 *	       16 if baud rate <= 1200
	 *	LINES - 1 if baud rate  > 1200
	 *
	 * Note, the windows option code will correct any too-large value
	 * or when the O_LINES value is 1.
	 */
	if (sp->gp->scr_baud(sp, &v))
		return (1);
	if (v <= 600)
		v = 8;
	else if (v <= 1200)
		v = 16;
	else if ((v = O_VAL(sp, O_LINES) - 1) == 0)
		v = 1;

	(void)SPRINTF(b2, SIZE(b2), L("window=%lu"), v);
	OI(O_WINDOW, b2);

	/*
	 * Set boolean default values, and copy all settings into the default
	 * information.  OS_NOFREE is set, we're copying, not replacing.
	 */
	for (op = optlist, cnt = 0; op->name != NULL; ++op, ++cnt)
		switch (op->type) {
		case OPT_0BOOL:
			break;
		case OPT_1BOOL:
			O_SET(sp, cnt);
			O_D_SET(sp, cnt);
			break;
		case OPT_NUM:
			o_set(sp, cnt, OS_DEF, NULL, O_VAL(sp, cnt));
			break;
		case OPT_STR:
			if (O_STR(sp, cnt) != NULL && o_set(sp, cnt,
			    OS_DEF | OS_NOFREE | OS_STRDUP, O_STR(sp, cnt), 0))
				goto err;
			break;
		default:
			abort();
		}

	/*
	 * !!!
	 * Some options can be initialized by the command name or the
	 * command-line arguments.  They don't set the default values,
	 * it's historic practice.
	 */
	for (; *oargs != -1; ++oargs)
		OI(*oargs, optlist[*oargs].name);
#undef OI

	/*
	 * Inform the underlying screen of the initial values of the
	 * edit options.
	 */
	for (op = optlist, cnt = 0; op->name != NULL; ++op, ++cnt) {
		isset = O_ISSET(sp, cnt);
		(void)sp->gp->scr_optchange(sp, cnt, O_STR(sp, cnt), &isset);
	}
	return (0);

err:	msgq_wstr(sp, M_ERR, optlist[optindx].name,
	    "031|Unable to set default %s option");
	return (1);
}
コード例 #10
0
Object hippo_write_result_init(bson_t *reply, bson_error_t *error, mongoc_client_t *client, int server_id, int success, const mongoc_write_concern_t *write_concern)
{
	static Class* c_writeResult;

	c_writeResult = Unit::lookupClass(s_MongoDriverWriteResult_className.get());
	assert(c_writeResult);
	Object obj = Object{c_writeResult};

	MongoDBDriverWriteResultData* wr_data = Native::data<MongoDBDriverWriteResultData>(obj.get());
	wr_data->m_client = client;
	wr_data->m_server_id = server_id;
	wr_data->m_write_concern = mongoc_write_concern_copy(write_concern);

	/* Convert the whole BSON reply into a Variant */
	Variant v;
	Array a;
	hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_DEBUG_INITIALIZER;

	BsonToVariantConverter convertor(bson_get_data(reply), reply->len, options);
	convertor.convert(&v);
	a = v.toArray();

	obj->o_set(s_nUpserted, Variant(a[s_nUpserted]), s_MongoDriverWriteResult_className);
	obj->o_set(s_nMatched, Variant(a[s_nMatched]), s_MongoDriverWriteResult_className);
	obj->o_set(s_nRemoved, Variant(a[s_nRemoved]), s_MongoDriverWriteResult_className);
	obj->o_set(s_nInserted, Variant(a[s_nInserted]), s_MongoDriverWriteResult_className);
	obj->o_set(s_nModified, Variant(a[s_nModified]), s_MongoDriverWriteResult_className);

	if (write_concern) {
		Array debugInfoResult = Array::Create();
		mongodb_driver_add_write_concern_debug((mongoc_write_concern_t*) write_concern, &debugInfoResult);

		obj->o_set(s_writeConcern, debugInfoResult, s_MongoDriverWriteConcern_className);
	} else {
		obj->o_set(s_writeConcern, Variant(), s_MongoDriverWriteConcern_className);
	}

	if (a.exists(s_upserted)) {
		obj->o_set(s_upsertedIds, a[s_upserted], s_MongoDriverWriteResult_className);
	} else {
		Array a = Array::Create();
		obj->o_set(s_upsertedIds, a, s_MongoDriverWriteResult_className);
	}

	if (a.exists(s_writeErrors)) {
		Array writeErrors = Array::Create();

		for (ArrayIter iter(a[s_writeErrors].toArray()); iter; ++iter) {
			const Variant& value = iter.second();
			static Class* c_writeError;

			Array a_we = value.toArray();

			c_writeError = Unit::lookupClass(s_MongoDriverWriteError_className.get());
			assert(c_writeError);
			Object we_obj = Object{c_writeError};

			if (a_we.exists(s_errmsg)) {
				we_obj->o_set(s_message, a_we[s_errmsg], s_MongoDriverWriteError_className);
			}
			if (a_we.exists(s_code)) {
				we_obj->o_set(s_code, a_we[s_code], s_MongoDriverWriteError_className);
			}
			if (a_we.exists(s_index)) {
				we_obj->o_set(s_index, a_we[s_index], s_MongoDriverWriteError_className);
			}
			if (a_we.exists(s_info)) {
				we_obj->o_set(s_info, a_we[s_info], s_MongoDriverWriteError_className);
			}

			writeErrors.append(we_obj);
		}

		obj->o_set(s_writeErrors, writeErrors, s_MongoDriverWriteResult_className);
	}

	if (a.exists(s_writeConcernErrors)) {
		Array a_v;

		a_v = a[s_writeConcernErrors].toArray();
	
		static Class* c_writeConcernError;

		c_writeConcernError = Unit::lookupClass(s_MongoDriverWriteConcernError_className.get());
		assert(c_writeConcernError);
		Object wce_obj = Object{c_writeConcernError};

		if (a_v.exists(0) && a_v[0].isArray()) {
			Array first_item = a_v[0].toArray();

			if (first_item.exists(s_errmsg)) {
				wce_obj->o_set(s_message, first_item[s_errmsg], s_MongoDriverWriteConcernError_className);
			}
			if (first_item.exists(s_code)) {
				wce_obj->o_set(s_code, first_item[s_code], s_MongoDriverWriteConcernError_className);
			}
			if (first_item.exists(s_info)) {
				wce_obj->o_set(s_info, first_item[s_info], s_MongoDriverWriteConcernError_className);
			} else {
				wce_obj->o_set(s_info, Variant(), s_MongoDriverWriteConcernError_className);
			}

			obj->o_set(s_writeConcernError, Variant(wce_obj), s_MongoDriverWriteResult_className);
		}
	}

	if (success == 0) {
		if ((error->domain == MONGOC_ERROR_COMMAND && error->code != MONGOC_ERROR_COMMAND_INVALID_ARG) || error->domain == MONGOC_ERROR_WRITE_CONCERN) {
			auto bw_exception = MongoDriver::Utils::throwBulkWriteException(error->message);
			bw_exception->o_set(s_MongoDriverExceptionBulkWriteException_writeResult, obj, MongoDriver::s_MongoDriverExceptionBulkWriteException_className);

			throw bw_exception;
		} else {
			throw MongoDriver::Utils::throwExceptionFromBsonError(error);
		}
	}

	return obj;
}
コード例 #11
0
ファイル: ext_imap.cpp プロジェクト: bd808/hhvm
static void _php_imap_add_body(Object &ret, BODY *body, bool do_multipart) {

  if (body->type <= TYPEMAX) {
   ret.o_set("type", body->type);
  }

  if (body->encoding <= ENCMAX) {
    ret.o_set("encoding", body->encoding);
  }

  if (body->subtype) {
    ret.o_set("ifsubtype", 1);
    ret.o_set("subtype", String((const char*)body->subtype, CopyString));
  } else {
    ret.o_set("ifsubtype", 0);
  }

  if (body->description) {
    ret.o_set("ifdescription", 1);
    ret.o_set("description",
      String((const char*)body->description, CopyString));
  } else {
    ret.o_set("ifdescription", 0);
  }

  if (body->id) {
    ret.o_set("ifid", 1);
    ret.o_set("id", String((const char*)body->id, CopyString));
  } else {
    ret.o_set("ifid", 0);
  }


  if (body->size.lines) {
    ret.o_set("lines", (int64_t)body->size.lines);
  }

  if (body->size.bytes) {
    ret.o_set("bytes", (int64_t)body->size.bytes);
  }

  if (body->disposition.type) {
    ret.o_set("ifdisposition", 1);
    ret.o_set("disposition",
      String((const char*)body->disposition.type, CopyString));
  } else {
    ret.o_set("ifdisposition", 0);
  }

  if (body->disposition.parameter) {
    PARAMETER *dpar;
    dpar = body->disposition.parameter;
    ret.o_set("ifdparameters", 1);

    Array dparametres(Array::Create());
    do {
      auto dparam = SystemLib::AllocStdClassObject();
      dparam.o_set("attribute",
        String((const char*)dpar->attribute, CopyString));
      dparam.o_set("value", String((const char*)dpar->value, CopyString));
      dparametres.append(std::move(dparam));
    } while ((dpar = dpar->next));
    ret.o_set("dparameters", dparametres);
  } else {
    ret.o_set("ifdparameters", 0);
  }

  PARAMETER *par;
  Array parametres(Array::Create());

  if ((par = body->parameter)) {
    ret.o_set("ifparameters", 1);
    do {
      auto param = SystemLib::AllocStdClassObject();
      OBJ_SET_ENTRY(param, par, "attribute", attribute);
      OBJ_SET_ENTRY(param, par, "value", value);
      parametres.append(std::move(param));
    } while ((par = par->next));
    ret.o_set("parameters", parametres);
  } else {
    ret.o_set("ifparameters", 0);
  }

  if (do_multipart) {
    /* multipart message ? */
    if (body->type == TYPEMULTIPART) {
      parametres.clear();
      PART *part;
      for (part = body->nested.part; part; part = part->next) {
        auto param = SystemLib::AllocStdClassObject();
        _php_imap_add_body(param, &part->body, do_multipart);
        parametres.append(std::move(param));
      }
      ret.o_set("parts", parametres);
    }

    /* encapsulated message ? */
    if ((body->type == TYPEMESSAGE) && (!strcasecmp(body->subtype, "rfc822"))) {
      body = body->nested.msg->body;
      parametres.clear();
      auto param = SystemLib::AllocStdClassObject();
      _php_imap_add_body(param, body, do_multipart);
      parametres.append(std::move(param));
      ret.o_set("parts", parametres);
    }
  }
}