Exemplo n.º 1
0
BOOL  InsertString_BeforeTag( const char* szSrc,      // [in]  Source string
                              const char* szTag,      // [in]  Insert new string BEFORE this tag
                              const char* szStr,      // [in]  New string to insert
                              char*       szDst,      // [out] Put it here
                              int         iDstSize)   // [in]  Size of buffer
{
   const char* szFound = NULL;
   int         iFoundOffset;
   int         iSrcSize;
   int         iTagSize;
   int         iStrSize;
   int         iNewSize;

   if(STRING_IS_EMPTY(szSrc)   ||
      STRING_IS_EMPTY(szTag)   ||
      STRING_IS_EMPTY(szStr)   ||
      !szDst || !iDstSize)
      return FALSE;   //   Invalid argument

   iSrcSize = strlen(szSrc);
   iTagSize = strlen(szTag);
   iStrSize = strlen(szStr);
   iNewSize = (iSrcSize + iStrSize);

   if( iDstSize <= iNewSize)
      return FALSE;
   szDst[iNewSize] = '\0';

   szFound = strstr( szSrc, szTag);
   if( !szFound)
      return FALSE;

   iFoundOffset = (int)(szFound - szSrc);

   if( szSrc == szDst)
   {
      //   Copy-1:   Prefix + tag
      //      Already done in this case...
      //   Copy-2:   Postfix
      memmove( (szDst+iFoundOffset+iStrSize), szFound, strlen(szFound));
      //   Copy-3:   Insertion
      strncpy( szDst+iFoundOffset, szStr, iStrSize);
   }
   else
   {
      //   Copy-1:   Prefix + tag
      strncpy( szDst, szSrc, iFoundOffset);
      //   Copy-2:   Postfix
      strcpy( (szDst+iFoundOffset+iStrSize), szFound);
      //   Copy-3:   Insertion
      strncpy( szDst+iFoundOffset, szStr, iStrSize);
   }
   

   return TRUE;
}
Exemplo n.º 2
0
static gchar *to_real_section(gchar * confSection, MkdgBackend * backend,
                              const gchar * section)
{

    if (!STRING_IS_EMPTY(backend->basePath)) {
        g_strlcpy(confSection, backend->basePath, KEY_BUFFER_SIZE);
    } else {
        g_strlcpy(confSection, "", KEY_BUFFER_SIZE);
    }

    if (!STRING_IS_EMPTY(section)) {
        g_strlcat(confSection, section, KEY_BUFFER_SIZE);
        g_strlcat(confSection, "/", KEY_BUFFER_SIZE);
    }
    return confSection;
}
gboolean ctx_write(PropertyContext * ctx, const gchar * schemasHome,
		   const gchar * owner, FILE * outF)

{
    if (ctx->spec->propertyFlags & MKDG_PROPERTY_FLAG_NO_BACKEND){
	return TRUE;
    }
    mkdg_xml_tags_write(outF, "schema", MKDG_XML_TAG_TYPE_BEGIN_ONLY, NULL,
			NULL);
    gchar buf[XML_BUFFER_SIZE];
    gchar *camalCasedKey=mkdg_str_dash_to_camel(ctx->spec->key);
    g_snprintf(buf, XML_BUFFER_SIZE, "/schemas%s",schemasHome);

    if (! STRING_IS_EMPTY(ctx->spec->subSection)) {
	g_strlcat(buf, "/", XML_BUFFER_SIZE);
	g_strlcat(buf, ctx->spec->subSection, XML_BUFFER_SIZE);
    } 
    g_strlcat(buf, "/", XML_BUFFER_SIZE);
    g_strlcat(buf, camalCasedKey, XML_BUFFER_SIZE);

    mkdg_xml_tags_write(outF, "key", MKDG_XML_TAG_TYPE_SHORT, NULL, buf);
    mkdg_xml_tags_write(outF, "applyto", MKDG_XML_TAG_TYPE_SHORT, NULL,
			buf + strlen("/schemas"));
    mkdg_xml_tags_write(outF, "owner", MKDG_XML_TAG_TYPE_SHORT, NULL,
			owner);
    switch (ctx->spec->valueType) {
    case G_TYPE_BOOLEAN:
	mkdg_xml_tags_write(outF, "type", MKDG_XML_TAG_TYPE_SHORT, NULL,
			    "bool");
	break;
    case G_TYPE_INT:
    case G_TYPE_UINT:
	mkdg_xml_tags_write(outF, "type", MKDG_XML_TAG_TYPE_SHORT, NULL,
			    "int");
	break;
    case G_TYPE_STRING:
	mkdg_xml_tags_write(outF, "type", MKDG_XML_TAG_TYPE_SHORT, NULL,
			    "string");
	break;
    default:
	break;
    }
    if (ctx->spec->defaultValue) {
	mkdg_xml_tags_write(outF, "default", MKDG_XML_TAG_TYPE_SHORT, NULL,
			    ctx->spec->defaultValue);
    }
    int i;
    for (i = 0; localeArray[i] != NULL; i++) {
	ctx_write_locale(ctx, outF, localeArray[i]);
    }

    setlocale(LC_ALL, NULL);
    mkdg_xml_tags_write(outF, "schema", MKDG_XML_TAG_TYPE_END_ONLY, NULL,
			NULL);
    return TRUE;
}
Exemplo n.º 4
0
static gchar *to_real_key(gchar * confKey, MkdgBackend * backend,
                          const gchar * section, const gchar * key)
{
    gchar *camalCasedKey = gconf2_backend_get_key(backend, section, key, NULL);

    if (!STRING_IS_EMPTY(backend->basePath)) {
        g_strlcpy(confKey, backend->basePath, KEY_BUFFER_SIZE);
        g_strlcat(confKey, "/", KEY_BUFFER_SIZE);
    } else {
        g_strlcpy(confKey, "/", KEY_BUFFER_SIZE);
    }

    if (!STRING_IS_EMPTY(section)) {
        g_strlcat(confKey, section, KEY_BUFFER_SIZE);
        g_strlcat(confKey, "/", KEY_BUFFER_SIZE);
    }
    g_strlcat(confKey, camalCasedKey, KEY_BUFFER_SIZE);
    return confKey;
}
Exemplo n.º 5
0
void CMsnContactManager::AddUsers(const CMembership* memberShip)
{
	const std::list<Member*>& members = memberShip->GetMembers();
	std::list<Member*>::const_iterator cit = members.begin();
	for (; cit != members.end(); cit++)
	{
		const char* passport = (*cit)->PassportName;
		if (STRING_IS_EMPTY(passport))
			continue;
		Member* member = FindUser(passport);
		if (member != NULL)
			continue;

		// 如果显示名为空,则先用 Passport 帐号代替
		if (STRING_IS_EMPTY((*cit)->DisplayName))
			(*cit)->DisplayName = acl_mystrdup(passport);
		users_[passport] = (*cit);
	}
}
Exemplo n.º 6
0
void CMsnContactManager::CreateUsers()
{
	// 遍历所有成员列表,创建用户列表

	const std::list<CMembership*>& memberShips =
		memberShips_->GetMemberShips();
	std::list<CMembership*>::const_iterator cit1 = memberShips.begin();
	for (; cit1 != memberShips.end(); cit1++)
	{
		const char* role = (*cit1)->GetMemberRole();
		if (STRING_IS_EMPTY(role))
			continue;
		if (strcmp(role, "Allow") == 0)
			AddUsers(*cit1);
		else if (strcmp(role, "Block") == 0)
			AddUsers(*cit1);
		else if (strcmp(role, "Reverse") == 0)
			AddUsers(*cit1);
	}

	// 遍历所有联系人列表,补充用户列表的信息

	const std::list<CMsnContact*>& contacts = contacts_->GetContacts();
	std::list<CMsnContact*>::const_iterator cit2 = contacts.begin();
	for (; cit2 != contacts.end(); cit2++)
	{
		// 必要性检查
		if (STRING_IS_EMPTY((*cit2)->passportName))
			continue;
		if (STRING_IS_EMPTY((*cit2)->contactType))
			continue;
		if (strcasecmp((*cit2)->contactType, "Regular") != 0)
			continue;
		Member* member = FindUser((*cit2)->passportName);
		if (member == NULL)
			continue;

		// 设置该成员的联系人对象
		member->SetContact(*cit2);
	}
}
void update_pre_edit_text(IBusChewingEngine * self)
{
    refresh_pre_edit_text(self);
    gboolean visible = TRUE;

    IBusPreeditFocusMode mode;
    if (STRING_IS_EMPTY(self->preEditText->text)) {
	mode = IBUS_ENGINE_PREEDIT_CLEAR;
	visible = FALSE;
    } else {
	mode = IBUS_ENGINE_PREEDIT_COMMIT;
    }

    parent_update_pre_edit_text_with_mode(IBUS_ENGINE(self),
					  self->preEditText,
					  cursor_current, visible, mode);
}
Exemplo n.º 8
0
// 设置联系人列表中的成员的在线状态
Member* CMsnContactManager::SetUserStatus(const char* passportName,
	const char* status, const char* displayName)
{
	acl_assert(passportName && status && displayName);

	std::map<acl::string, Member*>::iterator it = users_.find(passportName);
	if (it == users_.end())
		return (NULL);

	Member* member = it->second;
	if (strcasecmp(status, "NLN") == 0)
		member->online_ = member_s_online;
	else if (strcasecmp(status, "IDL") == 0)
		member->online_ = member_s_idle;
	else if (strcasecmp(status, "BSY") == 0)
		member->online_ = member_s_busy;
	else if (strcasecmp(status, "AWY"))
		member->online_ = member_s_away;
	else
		logger_warn("unkown status: %s", status);

	acl::string buf;

	// 字符集转换成 GB18030
	bool ret = conv_.convert("UTF-8", "GB18030", displayName,
		strlen(displayName), &buf);
	if (ret == false)
	{
		logger_warn("convert from utf-8 to GB18030 error");
		return (member);
	}

	if (!STRING_IS_EMPTY(member->DisplayName))
		acl_myfree(member->DisplayName);
	member->DisplayName = acl_mystrdup(buf.c_str());

	return (member);
}
Exemplo n.º 9
0
void
parrot_init_library_paths(PARROT_INTERP)
{
    ASSERT_ARGS(parrot_init_library_paths)
    PMC    *paths;
    STRING *entry;
    PMC * const iglobals    = interp->iglobals;

    /* create the lib_paths array */
    PMC * const lib_paths   = Parrot_pmc_new_init_int(interp,
            enum_class_FixedPMCArray, PARROT_LIB_PATH_SIZE);
    VTABLE_set_pmc_keyed_int(interp, iglobals,
            IGLOBALS_LIB_PATHS, lib_paths);

    /* each is an array of strings */
    /* define include paths */
    paths = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
    VTABLE_set_pmc_keyed_int(interp, lib_paths,
            PARROT_LIB_PATH_INCLUDE, paths);
    { /* EXPERIMENTAL: add include path from environment */
        STRING *envvar = Parrot_getenv(interp, CONST_STRING(interp, "PARROT_INCLUDE"));
        Parrot_warn_experimental(interp, "PARROT_INCLUDE environment variable is experimental");
        if (!STRING_IS_NULL(envvar) && !STRING_IS_EMPTY(envvar))
            VTABLE_push_string(interp, paths, envvar);
    }
    entry = CONST_STRING(interp, "./");
    VTABLE_push_string(interp, paths, entry);

    /* define library paths */
    paths = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
    VTABLE_set_pmc_keyed_int(interp, lib_paths,
            PARROT_LIB_PATH_LIBRARY, paths);
    { /* EXPERIMENTAL: add library path from environment */
        STRING *envvar = Parrot_getenv(interp, CONST_STRING(interp, "PARROT_LIBRARY"));
        Parrot_warn_experimental(interp, "PARROT_LIBRARY environment variable is experimental");
        if (!STRING_IS_NULL(envvar) && !STRING_IS_EMPTY(envvar))
            VTABLE_push_string(interp, paths, envvar);
    }
    entry = CONST_STRING(interp, "./");
    VTABLE_push_string(interp, paths, entry);

    /* define languages paths */
    paths = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
    VTABLE_set_pmc_keyed_int(interp, lib_paths,
            PARROT_LIB_PATH_LANG, paths);
    entry = CONST_STRING(interp, "./");
    VTABLE_push_string(interp, paths, entry);

    /* define dynext paths */
    paths = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
    VTABLE_set_pmc_keyed_int(interp, lib_paths,
            PARROT_LIB_PATH_DYNEXT, paths);
    entry = CONST_STRING(interp, "dynext/");
    VTABLE_push_string(interp, paths, entry);

    /* shared exts */
    paths = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
    VTABLE_set_pmc_keyed_int(interp, lib_paths,
            PARROT_LIB_DYN_EXTS, paths);
    /* no CONST_STRING here - the c2str.pl preprocessor needs "real strs" */
    entry = Parrot_str_new_constant(interp, PARROT_LOAD_EXT);
    VTABLE_push_string(interp, paths, entry);
    /* OS/X has .dylib and .bundle */
    if (!STREQ(PARROT_LOAD_EXT, PARROT_SHARE_EXT)) {
        entry = Parrot_str_new_constant(interp, PARROT_SHARE_EXT);
        VTABLE_push_string(interp, paths, entry);
    }

#ifdef PARROT_PLATFORM_LIB_PATH_INIT_HOOK
    PARROT_PLATFORM_LIB_PATH_INIT_HOOK(interp, lib_paths);
#endif
}