Ejemplo n.º 1
0
 /* bo5-52.c 广义表的书写形式串为HString类型 */
 #include"c4-2.h" /* 定义HString类型 */
 #include"bo4-2.c" /* HString类型的基本操作 */
 Status sever(HString *str,HString *hstr)
 { /* 将非空串str分割成两部分:hstr为第一个','之前的子串,str为之后的子串 */
   int n,i=1,k=0; /* k记尚未配对的左括号个数 */
   HString ch,c1,c2,c3;
   InitString(&ch); /* 初始化HString类型的变量 */
   InitString(&c1);
   InitString(&c2);
   InitString(&c3);
   StrAssign(&c1,",");
   StrAssign(&c2,"(");
   StrAssign(&c3,")");
   n=StrLength(*str);
   do
   {
     SubString(&ch,*str,i,1);
     if(!StrCompare(ch,c2))
       ++k;
     else if(!StrCompare(ch,c3))
       --k;
     ++i;
   }while(i<=n&&StrCompare(ch,c1)||k!=0);
   if(i<=n)
   {
     StrCopy(&ch,*str);
     SubString(hstr,ch,1,i-2);
     SubString(str,ch,i,n-i+1);
   }
   else
   {
     StrCopy(hstr,*str);
     ClearString(str);
   }
   return OK;
 }
Ejemplo n.º 2
0
 /* bo5-51.c 广义表的书写形式串为SString类型 */
 #include "../ch4/c4-1.h" /* 定义SString类型 */
 #include "../ch4/bo4-1.c" /* SString类型的基本操作 */
 void sever(SString str,SString hstr) /* 算法5.8  SString是数组,不需引用类型 */
 { /* 将非空串str分割成两部分:hsub为第一个','之前的子串,str为之后的子串 */
   int n,k,i; /* k记尚未配对的左括号个数 */
   SString ch,c1,c2,c3;
   n=StrLength(str);
   StrAssign(c1,",");
   StrAssign(c2,"(");
   StrAssign(c3,")");
   SubString(ch,str,1,1);
   for(i=1,k=0;i<=n&&StrCompare(ch,c1)||k!=0;++i)
   { /* 搜索最外层的第一个逗号 */
     SubString(ch,str,i,1);
     if(!StrCompare(ch,c2))
       ++k;
     else if(!StrCompare(ch,c3))
       --k;
   }
   if(i<=n)
   {
     SubString(hstr,str,1,i-2);
     SubString(str,str,i,n-i+1);
   }
   else
   {
     StrCopy(hstr,str);
     ClearString(str);
   }
 }
Ejemplo n.º 3
0
static void AutoComplete(p_shell_context_t context)
{
    int32_t len;
    int32_t minLen;
    uint8_t i = 0;
    const shell_command_context_t *tmpCommand = NULL;
    const char *namePtr;
    const char *cmdName;

    minLen = 0;
    namePtr = NULL;

    if (!StrLen(context->line))
    {
        return;
    }
    context->printf_data_func("\r\n");
    /* Empty tab, list all commands */
    if (context->line[0] == '\0')
    {
        HelpCommand(context, 0, NULL);
        return;
    }
    /* Do auto complete */
    for (i = 0; i < g_RegisteredCommands.numberOfCommandInList; i++)
    {
        tmpCommand = g_RegisteredCommands.CommandList[i];
        cmdName = tmpCommand->pcCommand;
        if (StrCompare(context->line, cmdName, StrLen(context->line)) == 0)
        {
            if (minLen == 0)
            {
                namePtr = cmdName;
                minLen = StrLen(namePtr);
                /* Show possible matches */
                context->printf_data_func("%s\r\n", cmdName);
                continue;
            }
            len = StrCompare(namePtr, cmdName, StrLen(namePtr));
            if (len < 0)
            {
                len = len * (-1);
            }
            if (len < minLen)
            {
                minLen = len;
            }
        }
    }
    /* Auto complete string */
    if (namePtr)
    {
        StrCopy(context->line, namePtr, minLen);
    }
    context->printf_data_func("%s%s", context->prompt, context->line);
    return;
}
Ejemplo n.º 4
0
void test()
{
	char ch[2][255];
	int i=0,pos=1;
	SString S[2],T;

	for(i=0;i<2;i++)
	{
		printf("ÊäÈë×Ö·û´®%d:",i+1);
		scanf("%s",ch[i]);
		StrAssign(S[i],ch[i]);
	}

	for(i=0;i<2;i++)
	{
		printf("Êä³ö×Ö·û´®%d:",i+1);
		StrPrint(S[i]);
		printf("×Ö·ûÊÇ·ñΪ¿Õ%d(1-·Ç 0-¿Õ),×Ö·û´®³¤¶È:%d\n",!StrEmpty(S[i]),StrLength(S[i]));
	}

	printf("---Á¬½Ó´®--\n");
	Concat(T,S[0],S[1]);
	printf("Á¬½Óºó:");
	StrPrint(T);
	
	printf("---Çó×Ó´®---\n");
	printf("ÊäÈë×Ö´®:");
	scanf("%s",ch[0]);
	printf("ÊäÈë²éÕÒλÖÃ:");
	scanf("%d",&pos);
	StrAssign(S[0],ch[0]);
	i=Index(T,S[0],pos);
	printf("²éÕÒµ½µÄλÖÃ:%d\n",i);

	printf("---Ìæ´ú---\n");
	printf("ÊäÈëÌæ´úµÄ×Ó´®:");
	scanf("%s",ch[1]);
	printf("Ìæ»»%sºó:",ch[0]);
	StrAssign(S[1],ch[1]);
	Replace(T,S[0],S[1]);
	StrPrint(T);

	printf("±È½Ï×Ö·û´®:S%d%cS%d\n",1,StrCompare(S[0],S[1])>0?'>':StrCompare(S[0],S[1])<0?'<':'=',2);
	StrCopy(S[0],S[1]);
	printf("---¸´Öƺó---\n");
	for(i=0;i<2;i++)
	{
		printf("Êä³ö×Ö·û´®%d:",i+1);
		StrPrint(S[i]);
		printf("×Ö·ûÊÇ·ñΪ¿Õ%d(1-·Ç 0-¿Õ),×Ö·û´®³¤¶È:%d\n",!StrEmpty(S[i]),StrLength(S[i]));
	}
	printf("±È½Ï×Ö·û´®:S%d%cS%d\n",1,StrCompare(S[0],S[1])>0?'>':StrCompare(S[0],S[1])<0?'<':'=',2);
}
Ejemplo n.º 5
0
bool cConsole::cfAddPerlScript::operator()()
{
	string scriptfile, pathname, filename;
	bool number = false;
	int num = 0;
	GetParStr(1, scriptfile);
	vector<cPerlInterpreter *>::iterator it;
	cPerlInterpreter *pi;

	if (IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	}
	cServerDC *server= cServerDC::sCurrentServer;
	pathname = server->mConfigBaseDir;


	if(number) {
		DIR *dir = opendir(pathname.c_str());
		int i = 0;
		if(!dir) {
			(*mOS) << autosprintf(_("Failed loading directory %s."), pathname.c_str()) << " ";
			return false;
		}
		struct dirent *dent = NULL;

		while(NULL != (dent=readdir(dir))) {

			filename = dent->d_name;
			if((filename.size() > 4) && (StrCompare(filename,filename.size()-3,3,".pl")==0)) {
				if(i == num)
					scriptfile = pathname + "/" + filename;
				i++;
			}

		}
		closedir(dir);
	}
	char *argv[] = { (char*)"", (char*)scriptfile.c_str(), NULL };
	for(it = GetPI()->mPerl.mPerl.begin(); it != GetPI()->mPerl.mPerl.end(); ++it) {
		pi = *it;
		if (StrCompare(pi->mScriptName,0,pi->mScriptName.size(),scriptfile)==0) {
			(*mOS) << autosprintf(_("Script %s is already running."), scriptfile.c_str()) << " ";
			return false;
		}
	}
	GetPI()->mPerl.Parse(2, argv);
	(*mOS) << autosprintf(_("Script %s is now running."), scriptfile.c_str()) << " ";
	return true;
}
Ejemplo n.º 6
0
Long
CBLScriptParser::
Parse(
    PVoid          pScript,
    SizeT          ScriptSize,
    SBLScriptBase *pScriptInfo,
    SizeT          BufferSize
)
{
    Long      Result;
    SXmlInfo  XmlInfo;
    SXmlNode *pNode;

    if (pScript == NULL || pScriptInfo == NULL)
        return BL_ERROR_INVALID_PARAMETER;

    pScriptInfo->ScriptType = BL_SCRIPT_TYPE_UNKNOWN;

    if (!XmlParse(pScript, &XmlInfo))
        return BL_ERROR_INVALID_FORMAT;

    pNode = XmlInfo.pNode;
    if (pNode == NULL)
        return BL_ERROR_INVALID_FORMAT;

    if (!StrCompare(pNode->pszNodeName, BL_SCRIPT_CONFIG_ROOT_TAG))
    {
        Result = ParseScriptConfig(&XmlInfo, (SBLScriptConfig *)pScriptInfo, BufferSize);
    }
    else if (!StrCompare(pNode->pszNodeName, BL_SCRIPT_LIST_ROOT_TAG))
    {
        Result = ParseScriptGameList(&XmlInfo, (SBLScriptGameList *)pScriptInfo, BufferSize);
    }
    else if (!StrCompare(pNode->pszNodeName, BL_SCRIPT_PLUGIN_ROOT_TAG))
    {
        Result = ParseScriptPlugin(&XmlInfo, (SBLScriptPlugin *)pScriptInfo, BufferSize);
    }
    else
    {
        Result = BL_ERROR_INVALID_FORMAT;
    }

    XmlDestroy(&XmlInfo);
    if (BL_FAILED(Result))
        FreeScriptInfo(pScriptInfo);

    return Result;
}
Ejemplo n.º 7
0
bool cConsole::cfFilesPythonScript::operator()()
{
	DIR *dir = opendir(GetPI()->mScriptDir.c_str());
	if (!dir) {
		(*mOS) << autosprintf(_("Failed loading directory: %s"), GetPI()->mScriptDir.c_str());
		return false;
	}
	(*mOS) << autosprintf(_("Python scripts found in: %s"), GetPI()->mScriptDir.c_str()) << "\r\n\r\n";
	(*mOS) << "\t" << _("ID");
	(*mOS) << "\t" << _("Script") << "\r\n";
	(*mOS) << "\t" << string(40, '-') << "\r\n\r\n";
	string filename;
	struct dirent *dent = NULL;
	vector<string> filenames;

	while (NULL != (dent = readdir(dir))) {
		filename = dent->d_name;
		if ((filename.size() > 3) && (StrCompare(filename, filename.size() - 3, 3, ".py") == 0))
			filenames.push_back(filename);
	}
	sort(filenames.begin(), filenames.end());

	for (size_t i = 0; i < filenames.size(); i++)
		(*mOS) << "\t" << i << "\t" << filenames[i] << "\r\n";

	closedir(dir);
	return true;
}
Ejemplo n.º 8
0
void Create(GList1 &L, SString S)
{
	SString emp, sub, hsub;
	GList1 p;

	StrAssign(emp, "()");
	if (!(L = (GList1)malloc(sizeof(GLNode1))))
		exit(OVERFLOW);
	if (!StrCompare(S, emp)) {
		L->tag = LIST;
		L->hp = NULL;
	} else if (StrLength(S) == 1) {
		L->tag = ATOM;
		L->atom = S[1];
	} else { L->tag = LIST;
		 SubString(sub, S, 2, StrLength(S) - 2);

		 sever(sub, hsub);
		 Create(L->hp, hsub);
		 p = L->hp;
		 while (!StrEmpty(sub)) {
			 sever(sub, hsub);
			 Create(p->tp, hsub);
			 p = p->tp;
		 }
	}
	L->tp = NULL;
}
Ejemplo n.º 9
0
/* Compare names ( ascending ) */
static Int16 CompareDocumentNames
    (
    void*               rec1,           /* Pointer to the record to sort */
    void*               rec2,           /* Pointer to the record to sort */
    Int16               other,          /* Any other custom information you want 
                                           passed to the comparison function */
    SortRecordInfoPtr   rec1SortInfo,   /* Pointer to SortRecordInfoType
                                           structure that specify unique
                                           sorting information 
                                           for the record */
    SortRecordInfoPtr   rec2SortInfo,   /* Pointer to SortRecordInfoType
                                           structure that specify unique
                                           sorting information 
                                           for the record */
    MemHandle           appInfoH        /* A handle to the document's
                                           application info block */
    )
{
    Int16 result;

    /*   0 if rec1.name = rec2.name */
    /* < 0 if rec1.name < rec2.name */
    /* > 0 if rec1.name > rec2.name */
    result = StrCompare( ( (DocumentInfo*) rec1 )->name,
        ( (DocumentInfo*) rec2 )->name );

    return result;
}
Ejemplo n.º 10
0
/* Delete a bookmark for a given word in a bookmark database indicated by sortType */
static Err DeleteBookmarkInDB(AppContext* appContext, BookmarkSortType sortType, char *word)
{
    Err          err;
    UInt16       recsCount, i;
    MemHandle    recHandle;
    char *       wordInRecord;

    err = OpenBookmarksDB(appContext, sortType);
    if ( errNone != err )
        return err;

    recsCount = DmNumRecords(appContext->bookmarksDb);
    for (i = 0; i < recsCount; i++)
    {
        recHandle = DmQueryRecord(appContext->bookmarksDb, i);
        if (!recHandle)
        {
            err = DmGetLastErr();
            goto OnError;
        }

        wordInRecord = (char*)MemHandleLock(recHandle);
        Assert(wordInRecord);
        if (0 == StrCompare(wordInRecord, word))
        {
            MemHandleUnlock(recHandle);
            DmRemoveRecord(appContext->bookmarksDb, i);
            break;
        }
        MemHandleUnlock(recHandle);
    }
OnError:
    CloseBookmarksDB(appContext);
    return err;
}
Ejemplo n.º 11
0
static void MainFormFindButtonPressed(AppContext* appContext, FormType* form)
{
    const char* newWord=NULL;
    UInt16      index=FrmGetObjectIndex(form, fieldWordInput);

    Assert(frmInvalidObjectId!=index);

    FieldType* field=static_cast<FieldType*>(FrmGetObjectPtr(form, index));
    const char* prevWord=ebufGetDataPointer(&appContext->currentWordBuf);
    Assert(field);
    newWord=FldGetTextPtr(field);
    if (newWord && (StrLen(newWord)>0) && (!prevWord || 0!=StrCompare(newWord, prevWord)))
        StartWordLookup(appContext, newWord);
    else if (mainFormShowsDefinition!=appContext->mainFormContent)
    {
        const char* currentDefinition=ebufGetDataPointer(&appContext->currentDefinition);
        if ( NULL != currentDefinition )
        {
            // it can be NULL if we didn't have a definition and pressed "GO"
            // with no word in text field
            cbNoSelection(appContext);
            appContext->mainFormContent=mainFormShowsDefinition;

            diSetRawTxt(appContext->currDispInfo, const_cast<char*>(currentDefinition));
            FrmUpdateForm(formDictMain, redrawAll);
        }
    } 
}
Ejemplo n.º 12
0
void testStringWithFixedLen() {
	SString S;
	CreateString(S);
	PrintString(S);

	SString S2;
	CreateString(S2);
	PrintString(S2);

	SString T;
	StrConcat(T, S, S2);
	PrintString(T);


	SString Sub;
	SubString(Sub, T, 2, 3);
	PrintString(Sub);

	printf("compare two string:\n");
	SString s1;
	CreateString(s1);
	PrintString(s1);
	SString s2;
	CreateString(s2);
	PrintString(s2);
	int result = StrCompare(s1, s2);
	if (!result) printf("s1 == s2");
	else if (result > 0) printf("s1 > s2");
	else printf("s1 < s2");
	printf("\n");

}
Ejemplo n.º 13
0
int cPCRE::Compare(int index, const string &text, const char *text2)
{
	if(!this->PartFound(index))
		return -1;
	int start = mOffsetResults[index<<1];
	return StrCompare(text, start, mOffsetResults[(index<<1)+1]-start,text2);
}
Ejemplo n.º 14
0
bool cConsole::cfFilesLuaScript::operator()()
{
	DIR *dir = opendir(GetPI()->mScriptDir.c_str());

	if (!dir) {
		(*mOS) << autosprintf(_("Failed loading directory: %s"), GetPI()->mScriptDir.c_str());
		return false;
	}

	(*mOS) << autosprintf(_("Lua scripts found in: %s"), GetPI()->mScriptDir.c_str()) << "\r\n\r\n ";
	(*mOS) << setw(6) << setiosflags(ios::left) << _("ID");
	(*mOS) << toUpper(_("Script")) << "\r\n";
	(*mOS) << " " << string(6 + 20, '=') << "\r\n";
	string filename;
	struct dirent *dent = NULL;
	int i = 0;

	while (NULL != (dent = readdir(dir))) {
		filename = dent->d_name;

		if ((filename.size() > 4) && (StrCompare(filename, filename.size() - 4, 4, ".lua") == 0)) {
			(*mOS) << " " << setw(6) << setiosflags(ios::left) << i << filename << "\r\n";
			i++;
		}
	}

	closedir(dir);
	return true;
}
Ejemplo n.º 15
0
/**********************************************************************
 * Function: getDatabase
 * Description: pass the function the necessare database information,
 * and it will either open an existing database or create a new one if 
 * neccessary. "created" will be true if a new database was created
 * *******************************************************************/ 
Err getDatabaseByTypeCreatorName (DmOpenRef * DBptr, UInt32 type, 
	UInt32 creator, UInt32 mode, char *name) {
	 
    Err errors;
    LocalID id;
    UInt16 cardNum, attr;
    DmSearchStateType srch;
    Char db_name[32];
 
	errors = DmGetNextDatabaseByTypeCreator(true, &srch, type, creator,  false, 
		&cardNum, &id);

    while(!errors && id) {
		*DBptr =  DmOpenDatabase (cardNum, id, mode);
        DmDatabaseInfo (cardNum, id, db_name, &attr, NULL, NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL);
		if(StrCompare(name, db_name) == 0) {
            attr |= dmHdrAttrBackup;
            DmSetDatabaseInfo (cardNum, id, NULL, &attr, NULL, NULL, NULL, NULL,
                    NULL, NULL, NULL, NULL, NULL);
            return 0;
		}
		if(*DBptr) DmCloseDatabase(*DBptr);
		errors = DmGetNextDatabaseByTypeCreator(false, &srch, type, creator,  false, 
			&cardNum, &id);
    } 
	return 1; 
} 
Ejemplo n.º 16
0
// null fields are considered less than others
//
static Int16 HDComparePackedRecords(PackedHappyDays *rec1,
                                     PackedHappyDays *rec2,
                                     Int16 unusedInt,
                                     SortRecordInfoPtr unused1,
                                     SortRecordInfoPtr unused2,
                                     MemHandle appInfoH)
{
    Int16 result;
    Int16 whichKey1 = 1, whichKey2 = 1;
    char *key1, *key2;

    do {
        HDFindKey(rec1, &key1, &whichKey1);
        HDFindKey(rec2, &key2, &whichKey2);

        if (!key1 || *key1 == 0) {
            if (!key2 || *key2 == 0) {
                result = 0;
                return result;
            }
            else result = -1;
        }
        else if (!key2 || *key2 == 0) result = 1;
        else {
            result = StrCaselessCompare(key1, key2);
            if (result == 0)
                result = StrCompare(key1, key2);
        }
    } while (!result);

    return result;
}
Ejemplo n.º 17
0
void Search (struct nodo ** list)
{
	/* this function searches for either a number of a client or for
	its name. We present a menu until the user exits the loop */
	struct nodo * act = NULL;
	int	choice, number, foundit = 0;
	char	name[40];
	if (! *list)
		return;
	do
	{
		act = *list;
		puts("\n\n0 - Exit");
		puts("1 - Search By Name");
		puts("2 - Search By Number");
		CHOICE(choice);
		switch (choice)
		{
			case 1:
				printf("\Name: "); scanf("%s", name);
				while (act)
				{
					if (StrCompare(name, act->name))
					{
						foundit = 1;
						break;
					}
					act = act->next;
				}
				if (foundit)
				{
					printf("\n\tFound it!");
					ShowData(act);
				}
				break;
			case 2:
				printf("\nSearch Number: "); scanf("%i", &number);
				while (act)
				{
					if (act->nclient == number)
					{
						foundit = 1;
						break;
					}
					act = act->next;
				}
				if (foundit)
				{
					printf("\n\tFound it!");
					ShowData(act);
				}
				else
					printf("\n\n\tNo Data was found");
				break;
			default:
				break;
		}
	} while (choice != 0);
}
Ejemplo n.º 18
0
static int
try_db_name(void)
{int i,n;struct database_handle**db=get_database_list(&n);
 if(*db_name)for(i=0;i<n;i++)if(!StrCompare(db[i]->name,db_name))
  if(!load_database(i))return 0;
 *db_name=0;if(n>0)return load_database(0);
 FrmAlert(No_Dictionary_Alert_id);return!0;
}enum aux_flags_bits{list_mode_bit=0};
Ejemplo n.º 19
0
/* Finds and opens database,
 * calls plugin specific code to create new item,
 * then fills in GoTo parameters.
 */
static UInt16
PickBooger(KleenexPtr kleenexP)
{
    DmOpenRef dbR;
    UInt32 creatorID;
    UInt16 cardNo;
    LocalID dbID;
    Boolean closedb = false;
    UInt16 err, index;
    Char name[dmDBNameLength];

    /* Check for the correct version */
    if (!((kleenexP->version) & IBVERSION_PICTURE))
        return (boogerErrorVersionMismatch);

    /* Open the database */
    cardNo = 0;
    if (!(dbID = DmFindDatabase(cardNo, "DiddleIDB")))
        return 1;

    if ((dbR = DmOpenDatabase(cardNo, dbID, dmModeReadWrite))) {
        closedb = true;

    } else if (DmGetLastErr() == dmErrAlreadyOpenForWrites) {
        dbR = NULL;
        while ((dbR = DmNextOpenDatabase(dbR))) {
            DmOpenDatabaseInfo(dbR, &dbID, NULL, NULL, &cardNo, NULL);
            DmDatabaseInfo(cardNo, dbID, name, NULL, NULL, NULL, NULL, NULL,
                           NULL, NULL, NULL, NULL, &creatorID);
            if (!StrCompare(name, "DiddleIDB") && (creatorID == DB_CREATOR))
                break;
        }
        if (!dbR)
            return 1;
    }

    /* Call plugin specific routine to create item in database */
    err = DoTheBoogie(kleenexP, dbR, &index);

    /* Close the database */
    if (closedb)
        DmCloseDatabase(dbR);

    /* Did it work? */
    if (err)
        return (1);

    /* Load the GoTo parameters */
    if (!(kleenexP->booger.cmdPBP = MemPtrNew(sizeof(GoToParamsType))))
        return (1);
    MemSet(kleenexP->booger.cmdPBP, sizeof(GoToParamsType), 0);
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->dbCardNo = cardNo;
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->dbID = dbID;
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->recordNum = index;
    MemPtrSetOwner(kleenexP->booger.cmdPBP, 0);

    return (errNone);
}
Ejemplo n.º 20
0
tVAL_NICK cServerDC::ValidateNick(const string &nick, bool registered)
{
	cTime now;
	string ProhibitedChars("$| ");
	//ProhibitedChars.append("\0",1);

	if (!registered) {
		if(nick.size() > mC.max_nick ) return eVN_LONG;
		if(nick.size() < mC.min_nick ) return eVN_SHORT;
		if(nick.npos != nick.find_first_of(ProhibitedChars)) return eVN_CHARS;
		if((mC.nick_chars.size()>0) && (nick.npos != nick.find_first_not_of(mC.nick_chars.c_str()))) return eVN_CHARS;
		if(StrCompare(nick,0,mC.nick_prefix.length(),mC.nick_prefix) != 0) return eVN_PREFIX;
		if(StrCompare(nick,0,4,"[OP]") == 0) return eVN_NOT_REGED_OP;
	}
	if(mBanList->IsNickTempBanned(nick) > now.Sec())
		return eVN_BANNED;
	return eVN_OK;
}
Ejemplo n.º 21
0
bool cConsole::cfReloadLuaScript::operator()()
{
	string scriptfile;
	GetParStr(1, scriptfile);
	bool number = false;
	int num = 0;

	if (GetPI()->IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	} else if (scriptfile.find_first_of('/') == string::npos) {
		scriptfile = GetPI()->mScriptDir + scriptfile;
	}

	vector<cLuaInterpreter *>::iterator it;
	cLuaInterpreter *li;
	bool found = false;
	int i = 0;

	for (it = GetPI()->mLua.begin(); it != GetPI()->mLua.end(); ++it, ++i) {
		li = *it;

		if ((number && (num == i)) || (!number && (StrCompare(li->mScriptName, 0, li->mScriptName.size(), scriptfile) == 0))) {
			found = true;
			(*mOS) << autosprintf(_("Script stopped: %s"), li->mScriptName.c_str());
			scriptfile = li->mScriptName;
			delete li;
			GetPI()->mLua.erase(it);
			break;
		}
	}

	if (!found) {
		if (number)
			(*mOS) << autosprintf(_("Script not stopped because it's not loaded: #%d"), num);
		else
			(*mOS) << autosprintf(_("Script not stopped because it's not loaded: %s"), scriptfile.c_str());
	}

	cLuaInterpreter *ip = new cLuaInterpreter(scriptfile);

	if (!ip) {
		(*mOS) << " " << _("Failed to allocate new Lua interpreter.");
		return false;
	}

	if (ip->Init()) {
		(*mOS) << " " << autosprintf(_("Script is now loaded: %s"), scriptfile.c_str());
		GetPI()->AddData(ip);
		ip->Load();
		return true;
	} else {
		(*mOS) << " " << autosprintf(_("Script not found or couldn't be parsed: %s"), scriptfile.c_str());
		delete ip;
		return false;
	}
}
Ejemplo n.º 22
0
/* Save a given word in bookmarks database. */
Err AddBookmark(AppContext* appContext, char * word)
{
    Err                 err;
    UInt16              pos;
    Boolean             fWordAlreadyBookmarked;
    MemHandle           recHandle;
    char *              wordInRec;
    BookmarkSortType    currDbOpen;

    currDbOpen = appContext->currBookmarkDbType;

    // 1. See if we already have the record in bookmarks.
    //    We assume that if the record wasn't found in sorted-by-name database, it doesn't exist in the other.
    //    The sorted-by-name database is quicker to scan, because we can use binary search.

    err = OpenBookmarksDB(appContext, bkmSortByName);
    if (errNone != err)
        goto Exit;

    pos = DmFindSortPosition(appContext->bookmarksDb, word, NULL, (DmComparF *) BookmarksByNameCompare, 0);
    
    fWordAlreadyBookmarked = false;
    // DmFindSortPosition returns the position there the new record should be placed
    // so if the record exist its position is (pos - 1)
    recHandle = DmQueryRecord(appContext->bookmarksDb, pos>0 ? pos-1 : pos);
    // it's ok if we don't get handle - this might be an empty database
    if (recHandle)
    {
        wordInRec = (char*)MemHandleLock(recHandle);
        if (0 == StrCompare(word, wordInRec))
            fWordAlreadyBookmarked = true;
        MemHandleUnlock(recHandle);
    }
    
    if (fWordAlreadyBookmarked)
    {
        err = errNone;
        goto Exit;
    }

    // 2. If we haven't found the record, we add it to databases

    WriteWordInRecord(appContext->bookmarksDb, pos, word);
    CloseBookmarksDB(appContext);

    err = OpenBookmarksDB(appContext, bkmSortByTime);
    if (errNone != err)
        goto Exit;
    // the record must be put chronogically, so we add it at the beginning of the database
    WriteWordInRecord(appContext->bookmarksDb, 0, word);
    CloseBookmarksDB(appContext);

Exit:
    if (bkmInvalid != currDbOpen)
        OpenBookmarksDB(appContext, currDbOpen);
    return err;
}
Ejemplo n.º 23
0
static Int16 DBEntryCompare
    (
    void*  a,
    void*  b,
    Int32  other
    )
{
    return StrCompare( ( *( DBEntryType** )a )->name,
                       ( *( DBEntryType** )b )->name );
}
Ejemplo n.º 24
0
static Int16 XlitCompare
    (
    void*   a,
    void*   b,
    Int32   other
    )
{
    return StrCompare( ( ( XlitEntry* )a )->header->name,
                       ( ( XlitEntry* )b )->header->name );
}
Ejemplo n.º 25
0
static U32 DirTraverse(const PFAT_FileHandle_t pDir, PFAT_DIR_DOS_Entry_t pEntry, const PBYTE pFileName)
{
    U32 r;

    while(FAT_ERR_CODE_NONE == (r = FAT_DirGetNextEntry(pDir, pEntry, NULL)))
    {
        if(0 == StrCompare((char *)pFileName, pEntry->m_cName)) return(FAT_ERR_CODE_FOUND);
    }

    return(r);
}
Ejemplo n.º 26
0
void main()
{
	int i;
	char c, *p = "God bye!", *q = "God luck!";
	HString t, s, r;

	InitString(t);
	InitString(s);
	InitString(r);
	StrAssign(t, p);
	printf("串t为");
	StrPrint(t);
	printf("串长为%d,串空否?%d(1:空 0:否)\n", StrLength(t), StrEmpty(t));
	StrAssign(s, q);
	printf("串s为");
	StrPrint(s);
	i = StrCompare(s, t);
	if (i < 0)
		c = '<';
	else if (i == 0)
		c = '=';
	else
		c = '>';
	printf("串s%c串t\n", c);
	Concat(r, t, s);
	printf("串t连接串s产生的串r为");
	StrPrint(r);
	StrAssign(s, "oo");
	printf("串s为");
	StrPrint(s);
	StrAssign(t, "o");
	printf("串t为");
	StrPrint(t);
	Replace(r, t, s);
	printf("把串r中和串t相同的子串用串s代替后,串r为");
	StrPrint(r);
	ClearString(s);
	printf("串s清空后,串长为%d,空否?%d(1:空 0:否)\n", StrLength(s), StrEmpty(s));
	SubString(s, r, 6, 4);
	printf("串s为从串r的第6个字符起的4个字符,长度为%d,串s为", s.length);
	StrPrint(s);
	StrCopy(t, r);
	printf("由串r复制得串t,串t为");
	StrPrint(t);
	StrInsert(t, 6, s);
	printf("在串t的第6个字符前插入串s后,串t为");
	StrPrint(t);
	StrDelete(t, 1, 5);
	printf("从串t的第1个字符起删除5个字符后,串t为");
	StrPrint(t);
	printf("%d是从串t的第1个字符起,和串s相同的第1个子串的位置\n", Index(t, s, 1));
	printf("%d是从串t的第2个字符起,和串s相同的第1个子串的位置\n", Index(t, s, 2));
	DestroyString(t);
}
Ejemplo n.º 27
0
void main()
{
  int i;
  char c,*p="God bye!",*q="God luck!";
  HString t,s,r;
  InitString(&t); /* HString类型必需初始化 */
  InitString(&s);
  InitString(&r);
  StrAssign(&t,p);
  printf("串t为: ");
  StrPrint(t);
  printf("串长为%d 串空否?%d(1:空 0:否)\n",StrLength(t),StrEmpty(t));
  StrAssign(&s,q);
  printf("串s为: ");
  StrPrint(s);
  i=StrCompare(s,t);
  if(i<0)
    c='<';
  else if(i==0)
    c='=';
  else
    c='>';
  printf("串s%c串t\n",c);
  Concat(&r,t,s);
  printf("串t联接串s产生的串r为: ");
  StrPrint(r);
  StrAssign(&s,"oo");
  printf("串s为: ");
  StrPrint(s);
  StrAssign(&t,"o");
  printf("串t为: ");
  StrPrint(t);
  Replace(&r,t,s);
  printf("把串r中和串t相同的子串用串s代替后,串r为:\n");
  StrPrint(r);
  ClearString(&s);
  printf("串s清空后,串长为%d 空否?%d(1:空 0:否)\n",StrLength(s),StrEmpty(s));
  SubString(&s,r,6,4);
  printf("串s为从串r的第6个字符起的4个字符,长度为%d 串s为: ",s.length);
  StrPrint(s);
  StrCopy(&t,r);
  printf("复制串t为串r,串t为: ");
  StrPrint(t);
  StrInsert(&t,6,s);
  printf("在串t的第6个字符前插入串s后,串t为: ");
  StrPrint(t);
  StrDelete(&t,1,5);
  printf("从串t的第1个字符起删除5个字符后,串t为: ");
  StrPrint(t);
  printf("%d是从串t的第1个字符起,和串s相同的第1个子串的位置\n",Index(t,s,1));
  printf("%d是从串t的第2个字符起,和串s相同的第1个子串的位置\n",Index(t,s,2));
}
Ejemplo n.º 28
0
/***********************************************************************
 *
 * FUNCTION:    PrvCompareTimeZoneEntries
 *
 * DESCRIPTION: Compare two time zone entries using the time zone name
 *		(if the countries don't match), otherwise the offset from GMT.
 *
 * PARAMETERS:
 *		entryA		 ->	Ptr to time zone entry.
 *		entryB		 ->	Ptr to time zone entry.
 *		other			 ->	Unused argument.
 *
 * RETURNED:
 *		0 if two entries are equal
 *		<0 if entryA sorts before entryB
 *		>0 if entryA sorts after entryB
 *
 * HISTORY:
 *		07/31/00	kwk	Created by Ken Krugler.
 *		08/23/00	kwk	Use GMT offset to compare two entries in the same
 *							country, so that all US entries (for example) are
 *							sorted west-to-east.
 *
 ***********************************************************************/
static Int16 PrvCompareTimeZoneEntries(void* entryA, void* entryB, Int32 /* other */)
{
	const TimeZoneEntryType* tzEntryA = (const TimeZoneEntryType*)entryA;
	const TimeZoneEntryType* tzEntryB = (const TimeZoneEntryType*)entryB;
	
	if (tzEntryA->tzCountry != tzEntryB->tzCountry)
	{
		return(StrCompare(tzEntryA->tzName, tzEntryB->tzName));
	}
	else
	{
		return(tzEntryA->tzOffset - tzEntryB->tzOffset);
	}
} // PrvCompareTimeZoneEntries
Ejemplo n.º 29
0
Status CreateGList(GList &L, SString S) {  // 算法5.7
  // 采用头尾链表存储结构,由广义表的书写形式串S创建广义表L。
  // 设emp="()"。
  char s[3]="()";
  SString emp;
  crt_SString(emp,s);
  SString sub,hsub;
  GList p,q;
  if (StrCompare(S, emp)) L = NULL;  // 创建空表
  else {
    if (!(L=(GList)malloc(sizeof(GLNode)))) return ERROR;  // 建表结点
    if (StrLength(S)==1) {  // 创建单原子广义表
       L->tag = ATOM;  L->atom =S[1]; }  
    } else { 
Ejemplo n.º 30
0
/********************************
Units must match or one be empty.
********************************/
STATIC_ROUTINE either(struct descriptor_xd uni[2]) {

	if (uni[0].pointer == 0) {
		uni[0] = uni[1];
		uni[1] = EMPTY_XD;
	}
	else if (uni[1].pointer) {
		if (StrCompare(uni[0].pointer, uni[1].pointer)) {
			MdsFree1Dx(&uni[0],NULL);
			uni[0] = BAD;
		}
	}
	return 1;
}