Пример #1
0
	void SetData(int Type,const wchar_t *Str,const wchar_t *Eol,int StrNum,int StrPos,int Length=-1)
	{
		if (Length == -1 && Str)
			Length=(int)StrLength(Str);

		this->Type=Type;
		this->StrPos=StrPos;
		this->StrNum=StrNum;
		this->Length=Length;
		xwcsncpy(EOL,Eol?Eol:L"",ARRAYSIZE(EOL)-1);

		if (this->Str)
		{
			delete[] this->Str;
		}

		if (Str)
		{
			this->Str=new wchar_t[Length+1];

			if (this->Str)
				wmemmove(this->Str,Str,Length);
		}
		else
			this->Str=nullptr;
	}
Пример #2
0
 /* bo5-51.c 广义表的书写形式串为SString类型 */
 #include"c4-1.h" /* 定义SString类型 */
 #include"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);
   }
 }
Пример #3
0
// max - без учета символа конца строки!
wchar_t *Clipboard::PasteEx(int max)
{
	wchar_t *ClipText=nullptr;
	HANDLE hClipData=GetData(CF_UNICODETEXT);

	if (hClipData)
	{
		wchar_t *ClipAddr=(wchar_t *)GlobalLock(hClipData);

		if (ClipAddr)
		{
			int BufferSize;
			BufferSize=StrLength(ClipAddr);

			if (BufferSize>max)
				BufferSize=max;

			ClipText=(wchar_t *)xf_malloc((BufferSize+1)*sizeof(wchar_t));

			if (ClipText)
			{
				wmemset(ClipText,0,BufferSize+1);
				xwcsncpy(ClipText,ClipAddr,BufferSize+1);
			}

			GlobalUnlock(hClipData);
		}
	}

	return ClipText;
}
void TEST01_Sqstr_main()
{
	SqString s, s1, s2, s3, s4;

	printf("(1)建立串s和串s1\n");

	StrAssign(s, "abcdefghefghijklmn");
	StrAssign(s1, "xyz");

	printf("(2)输出串s:"); DispStr(s);
	printf("(3)串s的长度:%d\n", StrLength(s));

	printf("(4)在串s的第9个字符位置插入串s1而产生串s2\n");
	s2 = InsStr(s, 9, s1);
	printf("(5)输出串s2:"); DispStr(s2);

	printf("(6)删除串s第2个字符开始的5个字符而产生串s2\n");
	s2 = DelStr(s, 2, 5);
	printf("(7)输出串s2:"); DispStr(s2);

	printf("(8)将串s第2个字符开始的5个字符替换成串s1而产生串s2\n");
	s2 = RepStr(s, 2, 5, s1);
	printf("(9)输出串s2:"); DispStr(s2);

	printf("(10)提取串s的第2个字符开始的10个字符而产生串s3\n");
	s3 = SubStr(s, 2, 10);
	printf("(11)输出串s3:"); DispStr(s3);

	printf("(12)将串s1和串s2连接起来而产生串s4\n");
	s4 = Concat(s1, s2);
	printf("(13)输出串s4:"); DispStr(s4);
}
Пример #5
0
// вставка без очистки буфера - на добавление
bool Clipboard::CopyFormat(const wchar_t *Format, const wchar_t *Data)
{
	UINT FormatType=RegisterFormat(Format);

	if (!FormatType)
		return false;

	if (Data && *Data)
	{
		HGLOBAL hData;
		void *GData;

		size_t BufferSize=(StrLength(Data)+1)*sizeof(wchar_t);

		if ((hData=GlobalAlloc(GMEM_MOVEABLE,BufferSize)))
		{
			if ((GData=GlobalLock(hData)))
			{
				memcpy(GData,Data,BufferSize);
				GlobalUnlock(hData);

				if (!SetData(FormatType, hData))
					GlobalFree(hData);
			}
			else
			{
				GlobalFree(hData);
			}
		}
	}

	return true;
}
Пример #6
0
// Перед вставкой производится очистка буфера
bool Clipboard::Copy(const wchar_t *Data)
{
	Empty();
	if (Data && *Data)
	{
		HGLOBAL hData;
		void *GData;
		size_t BufferSize=(StrLength(Data)+1)*sizeof(wchar_t);

		if ((hData=GlobalAlloc(GMEM_MOVEABLE,BufferSize)))
		{
			if ((GData=GlobalLock(hData)))
			{
				memcpy(GData,Data,BufferSize);
				GlobalUnlock(hData);
				if (!SetData(CF_UNICODETEXT,(HANDLE)hData))
					GlobalFree(hData);
			}
			else
			{
				GlobalFree(hData);
			}
		}
	}

	return true;
}
Пример #7
0
int main()
{
    char cmd[MAXCMD]={0};     // Commande
    int ret;                  // Le retour de la fonctions
    String S[MAXLEN]={0},*p;  //S:String  p:Pointeur à String
    char tmp[MAXLEN]={0};
 
    printf("***********************************************\n");
    printf("------ Première implementaion du String ------\n");
    printf("La maxime longeur du string: %d\n",MAXLEN);
    printf("Options de commandes: \n");
    printf("0: StrAssign \n");
    printf("1: StrLength \n");
    printf("2: StrPrint \n");
    printf("#: Quit \n");
    printf("***********************************************\n");
 
    while (1)
    {
        scanf("%s",cmd);// Lire la commande
 
        if (cmd[0]=='#') break; // Quiter
       
                  
        if (!CharsCompare(cmd,"0\0"))
        {
            scanf("%s",tmp);    // La valeur initial
            p=&S[0];
            ret=StrAssign(p,tmp);
        }
       
        else if (!CharsCompare(cmd,"1\0"))
        {
            p=&S[0];
            ret=StrLength(*p);
           
            printf("length is %d.\n",ret);
            ret=OK;
        }
       
        else if (!CharsCompare(cmd,"2\0"))
        {
            p=&S[0];
            ret=StrPrint(*p);
        }
        else
        {
            printf("The Command is Error.\n");
        }
 
        if (ret==OK) 
            printf("This Command is Successful.\n\n");
        else if (ret==ERROR) 
            printf("The input data is Error.\n\n");
        else if (ret==OVERFLOW) 
            printf("OVERFLOW.\n\n");
    }
 
    return 0;
}
Пример #8
0
 char* StrDup(const char* str) {
     int length = StrLength(str);
     char* result = NewArray<char>(length + 1);
     OS::MemCopy(result, str, length);
     result[length] = '\0';
     return result;
 }
Пример #9
0
/* $ 01.09.2000 SVS
  + Новый метод, для получения параметров для .Options
   .Options <KeyName>=<Value>
*/
int GetOptionsParam(api::File& SrcFile,const wchar_t *KeyName,string &strValue, UINT nCodePage)
{
	int Length=StrLength(L".Options");
	auto CurFilePos = SrcFile.GetPointer();
	string ReadStr;
	GetFileString GetStr(SrcFile, nCodePage);
	while (GetStr.GetString(ReadStr))
	{
		if (!StrCmpNI(ReadStr.data(), L".Options", Length))
		{
			string strFullParamName = ReadStr.substr(Length);
			RemoveExternalSpaces(strFullParamName);
			size_t pos = strFullParamName.rfind(L'=');
			if (pos != string::npos)
			{
				strValue = strFullParamName;
				strValue.erase(0, pos+1);
				RemoveExternalSpaces(strValue);
				strFullParamName.resize(pos);
				RemoveExternalSpaces(strFullParamName);

				if (!StrCmpI(strFullParamName.data(),KeyName))
				{
					SrcFile.SetPointer(CurFilePos, nullptr, FILE_BEGIN);
					return TRUE;
				}
			}
		}
	}

	SrcFile.SetPointer(CurFilePos, nullptr, FILE_BEGIN);
	return FALSE;
}
Пример #10
0
/*
 * actually delete the node
 */
void delete_node(void)
{
	HashList *NodeConfig;
	const StrBuf *Index;
	NodeConf *Node;
	void *vNode;

	Index = sbstr("index");
	if (Index == NULL) {
		AppendImportantMessage(_("Invalid Parameter"), -1);
		url_do_template();
		return;
	}

	NodeConfig = load_netconf(NULL, &NoCtx);
	if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
	    (vNode == NULL)) {
		AppendImportantMessage(_("Invalid Parameter"), -1);
		url_do_template();
		DeleteHash(&NodeConfig);
		return;
	}
	Node = (NodeConf *) vNode;
	Node->DeleteMe = 1;
       	save_net_conf(NodeConfig);
	DeleteHash(&NodeConfig);
	
	url_do_template();

}
Пример #11
0
 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;
 }
Пример #12
0
/*
 * modify an existing node
 */
void display_edit_node(void)
{
	WCTemplputParams SubTP;
	HashList *NodeConfig;
	const StrBuf *Index;
	void *vNode;
	const StrBuf *Tmpl;

	Index = sbstr("index");
	if (Index == NULL) {
		AppendImportantMessage(_("Invalid Parameter"), -1);
		url_do_template();
		return;
	}

	NodeConfig = load_netconf(NULL, &NoCtx);
	if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
	    (vNode == NULL)) {
		AppendImportantMessage(_("Invalid Parameter"), -1);
		url_do_template();
		DeleteHash(&NodeConfig);
		return;
	}
	StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL);
	{
		begin_burst();
		Tmpl = sbstr("template");
		output_headers(1, 0, 0, 0, 1, 0);
		DoTemplate(SKEY(Tmpl), NULL, &SubTP);
		end_burst();
	}
	UnStackContext(&SubTP);
	DeleteHash(&NodeConfig);
	
}
Пример #13
0
wchar_t* TruncStrFromCenter(wchar_t *Str, int MaxLength)
{
	assert(MaxLength >= 0);

	MaxLength=Max(0, MaxLength);

	if (Str)
	{
		int Length = StrLength(Str);

		if (MaxLength < 0)
			MaxLength=0;

		if (Length > MaxLength)
		{
			const int DotsLen = 3;

			if (MaxLength > DotsLen)
			{
				int Len1 = (MaxLength - DotsLen) / 2;
				int Len2 = MaxLength - DotsLen - Len1;
				wmemcpy(Str + Len1, L"...", DotsLen);
				wmemmove(Str + Len1 + DotsLen, Str + Length - Len2, Len2);
			}

			Str[MaxLength] = 0;
		}
	}

	return Str;
}
Пример #14
0
unsigned __int64 ConvertFileSizeString(const wchar_t *FileSizeStr)
{
	if (!CheckFileSizeStringFormat(FileSizeStr))
		return 0;

	unsigned __int64 n = _wtoi64(FileSizeStr);
	wchar_t c = Upper(FileSizeStr[StrLength(FileSizeStr)-1]);

	// http://en.wikipedia.org/wiki/SI_prefix
	switch (c)
	{
		case L'K':		// kilo 10x3
			n <<= 10;
			break;
		case L'M':		// mega 10x6
			n <<= 20;
			break;
		case L'G':		// giga 10x9
			n <<= 30;
			break;
		case L'T':		// tera 10x12
			n <<= 40;
			break;
		case L'P':		// peta 10x15
			n <<= 50;
			break;
		case L'E':		// exa  10x18
			n <<= 60;
			break;
			// Z - zetta 10x21
			// Y - yotta 10x24
	}

	return n;
}
Пример #15
0
// Заменить в строке Str Count вхождений подстроки FindStr на подстроку ReplStr
// Если Count < 0 - заменять "до полной победы"
// Return - количество замен
int ReplaceStrings(string &strStr,const wchar_t *FindStr,const wchar_t *ReplStr,int Count,BOOL IgnoreCase)
{
	const int LenFindStr=StrLength(FindStr);
	if ( !LenFindStr || !Count )
		return 0;
	const int LenReplStr=StrLength(ReplStr);
	size_t L=strStr.GetLength();

	const int Delta = LenReplStr-LenFindStr;
	const int AllocDelta = Delta > 0 ? Delta*10 : 0;

	size_t I=0;
	int J=0;
	while (I+LenFindStr <= L)
	{
		int Res=IgnoreCase?StrCmpNI(&strStr[I], FindStr, LenFindStr):StrCmpN(&strStr[I], FindStr, LenFindStr);

		if (!Res)
		{
			wchar_t *Str;
			if (L+Delta+1 > strStr.GetSize())
				Str = strStr.GetBuffer(L+AllocDelta);
			else
				Str = strStr.GetBuffer();

			if (Delta > 0)
				wmemmove(Str+I+Delta,Str+I,L-I+1);
			else if (Delta < 0)
				wmemmove(Str+I,Str+I-Delta,L-I+Delta+1);

			wmemcpy(Str+I,ReplStr,LenReplStr);
			I += LenReplStr;

			L+=Delta;
			strStr.ReleaseBuffer(L);

			if (++J == Count && Count > 0)
				break;
		}
		else
		{
			I++;
		}
	}

	return J;
}
Пример #16
0
	static PGPError
sGetNameProc(
	PFLConstFileSpecRef	ref,
	char				name[ 256 ] )
{
	const MyData *	myData	= GetMyData( ref );
	const FSSpec *	spec;
	
	PGPValidatePtr( myData );
	spec	= &myData->spec;
	PGPValidateParam( StrLength( spec->name ) <= 31 );
	
	pgpCopyMemory( &spec->name[ 1 ], name, StrLength( spec->name ) );
	name[ StrLength( spec->name ) ]	= '\0';
	
	return( kPGPError_NoErr );
}
Пример #17
0
XString::XString(const char *cstr) {
	stringLength = StrLength(cstr);
	capacity = stringLength + 1;
	string = DBG_NEW char[capacity];
	// Will include '\0' since cstr must be null-terminated, or StrLength would already have crashed.
	memcpy(string, cstr, stringLength + 1); 
	string[stringLength] = '\0';
}
Пример #18
0
Status Concat(HString *T, HString S1, HString S2){
  if(T->ch){
    free(T->ch);
  }
  int len_s1, len_s2, i;
  len_s1 = StrLength(S1);
  len_s2 = StrLength(S2);
  T->ch = (char *)malloc((len_s1 + len_s2) * sizeof(char));
  for(i = 0; i < len_s1; i++){
    (T->ch)[i] = S1.ch[i];
  }
  for(i = len_s1; i < len_s1 + len_s2; i++){
    T->ch[i] = S2.ch[i - len_s1];
  }
  T->length = len_s1 + len_s2;
  return OK;
}
Пример #19
0
int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
{
	wcsession *WCC = WC;
	if (WCC != NULL)
		return (StrLength(WCC->ImportantMsg) > 0);
	else
		return 0;
}
Пример #20
0
Status Replace(HString *S, HString T, HString V){
  int i = 1, len_t, len_v;
  if(StrEmpty(*S)){
    return ERROR;
  }
  len_t = StrLength(T);
  len_v = StrLength(V);
  do{
    i = Index(*S, T, i);
    if(i){
      StrDelete(S, i, len_t);
      StrInsert(S, i, V);
      i += len_v;
    }
  }while(i);
  return OK;
}
/*  操作结果: 用V替换主串S中出现的所有与T相等的不重叠的子串 */
Status Replace(String S,String T,String V)
{
    int i=1; /*  从串S的第一个字符起查找串T */
    if(StrEmpty(T)) /*  T是空串 */
        return ERROR;
    do
    {
        i=Index(S,T,i); /*  结果i为从上一个i之后找到的子串T的位置 */
        if(i) /*  串S中存在串T */
        {
            StrDelete(S,i,StrLength(T)); /*  删除该串T */
            StrInsert(S,i,V); /*  在原串T的位置插入串V */
            i+=StrLength(V); /*  在插入的串V后面继续查找串T */
        }
    } while(i);
    return OK;
}
Пример #22
0
/*
 * Attach an OpenID to a Citadel account
 */
int attach_openid(struct ctdluser *who, StrBuf *claimed_id)
{
	struct cdbdata *cdboi;
	long fetched_usernum;
	char *data;
	int data_len;
	char buf[2048];

	if (!who) return(1);
	if (StrLength(claimed_id)==0) return(1);

	/* Check to see if this OpenID is already in the database */

	cdboi = cdb_fetch(CDB_OPENID, ChrPtr(claimed_id), StrLength(claimed_id));
	if (cdboi != NULL) {
		memcpy(&fetched_usernum, cdboi->ptr, sizeof(long));
		cdb_free(cdboi);

		if (fetched_usernum == who->usernum) {
			syslog(LOG_INFO, "%s already associated; no action is taken", ChrPtr(claimed_id));
			return(0);
		}
		else {
			syslog(LOG_INFO, "%s already belongs to another user", ChrPtr(claimed_id));
			return(3);
		}
	}

	/* Not already in the database, so attach it now */

	data_len = sizeof(long) + StrLength(claimed_id) + 1;
	data = malloc(data_len);

	memcpy(data, &who->usernum, sizeof(long));
	memcpy(&data[sizeof(long)], ChrPtr(claimed_id), StrLength(claimed_id) + 1);

	cdb_store(CDB_OPENID, ChrPtr(claimed_id), StrLength(claimed_id), data, data_len);
	free(data);

	snprintf(buf, sizeof buf, "User <%s> (#%ld) has claimed the OpenID URL %s\n",
		 who->fullname, who->usernum, ChrPtr(claimed_id));
	CtdlAideMessage(buf, "OpenID claim");
	syslog(LOG_INFO, "%s", buf);
	return(0);
}
Пример #23
0
 void Replace()
 { // 替换字符串
   int i,k,f=1; // f为继续替换标志
   char b[2];
   HString s,t;
   printf("请输入待替换的字符串: ");
   scanf("%s%*c",str);
   InitString(s);
   StrAssign(s,str);
   printf("替换为: ");
   scanf("%s%*c",str);
   InitString(t);
   StrAssign(t,str);
   for(i=0;i<n&&f;i++) // 逐行查找、替换
   {
     k=1; // 由每行第1个字符起查找
     while(k)
     {
       k=Index(T[i],s,k); // 由本行的第k个字符开始查找
       if(k) // 找到
       {
         printf("第%d行: ",i+1);
         StrPrint(T[i]);
         printf("第%d个字符处找到。是否替换(Y/N)? ",k);
         gets(b);
         if(b[0]=='Y'||b[0]=='y')
         {
           StrDelete(T[i],k,StrLength(s));
           StrInsert(T[i],k,t);
         }
         printf("继续替换吗(Y/N)?");
         gets(b);
         if(b[0]!='Y'&&b[0]!='y') // 中断查找、替换
         {
           f=0;
           break;
         }
         else
           k+=StrLength(t);
       }
     }
   }
   if(f)
     printf("没找到\n");
 }
Пример #24
0
OneQueItem *DeserializeQueueItem(StrBuf *RawQItem, long QueMsgID)
{
	OneQueItem *Item;
	const char *pLine = NULL;
	StrBuf *Line;
	StrBuf *Token;
	void *v;

	Item = (OneQueItem*)malloc(sizeof(OneQueItem));
	memset(Item, 0, sizeof(OneQueItem));
	Item->Retry = SMTP_RETRY_INTERVAL;
	Item->MessageID = -1;
	Item->QueMsgID = QueMsgID;

	Token = NewStrBuf();
	Line = NewStrBufPlain(NULL, 128);
	while (pLine != StrBufNOTNULL) {
		const char *pItemPart = NULL;
		void *vHandler;

		StrBufExtract_NextToken(Line, RawQItem, &pLine, '\n');
		if (StrLength(Line) == 0) continue;
		StrBufExtract_NextToken(Token, Line, &pItemPart, '|');
		if (GetHash(QItemHandlers, SKEY(Token), &vHandler))
		{
			QItemHandlerStruct *HS;
			HS = (QItemHandlerStruct*) vHandler;
			HS->H(Item, Line, &pItemPart);
		}
	}
	FreeStrBuf(&Line);
	FreeStrBuf(&Token);

	if (Item->Retry >= MaxRetry)
		Item->FailNow = 1;

	pthread_mutex_lock(&ActiveQItemsLock);
	if (GetHash(ActiveQItems,
		    LKEY(Item->MessageID),
		    &v))
	{
		/* WHOOPS. somebody else is already working on this. */
		pthread_mutex_unlock(&ActiveQItemsLock);
		FreeQueItem(&Item);
		return NULL;
	}
	else {
		/* mark our claim on this. */
		Put(ActiveQItems,
		    LKEY(Item->MessageID),
		    Item,
		    HFreeQueItem);
		pthread_mutex_unlock(&ActiveQItemsLock);
	}

	return Item;
}
Пример #25
0
 static Status Replace(LString &S,LString T,LString V)
 { // 初始条件: 串S,T和V存在,T是非空串(此函数与串的存储结构无关)
   // 操作结果: 用V替换主串S中出现的所有与T相等的不重叠的子串
   int i=1; // 从串S的第一个字符起查找串T
   if(StrEmpty(T)) // T是空串
     return ERROR;
   do
   {
     i=Index(S,T,i); // 结果i为从上一个i之后找到的子串T的位置
     if(i) // 串S中存在串T
     {
       StrDelete(S,i,StrLength(T)); // 删除该串T
       StrInsert(S,i,V); // 在原串T的位置插入串V
       i+=StrLength(V); // 在插入的串V后面继续查找串T
     }
   }while(i);
   return OK;
 }
Пример #26
0
 Status Replace(LString *S,LString T,LString V)
 { /* 初始条件: 串S,T和V存在,T是非空串(此函数与串的存储结构无关) */
   /* 操作结果: 用V替换主串S中出现的所有与T相等的不重叠的子串 */
   int i=1; /* 从串S的第一个字符起查找串T */
   if(StrEmpty(T)) /* T是空串 */
     return ERROR;
   do
   {
     i=Index(*S,T,i); /* 结果i为从上一个i之后找到的子串T的位置 */
     if(i) /* 串S中存在串T */
     {
       StrDelete(S,i,StrLength(T)); /* 删除该串T */
       StrInsert(S,i,V); /* 在原串T的位置插入串V */
       i+=StrLength(V); /* 在插入的串V后面继续查找串T */
     }
   }while(i);
   return OK;
 }
Пример #27
0
/*************************************************************************
 * StrAppendMax
 */
char *StrAppendMax(char *target, size_t max, const char *source)
{
  assert(VALID(target));
  assert(VALID(source));
  assert(max > 0);

  max -= StrLength(target) + 1;
  return (max > 0) ? strncat(target, source, max) : target;
}
Пример #28
0
 Status CreateGList(GList *L,HString S)
 { /* 采用头尾链表存储结构,由广义表的书写形式串S创建广义表L。设emp="()" */
   HString emp,sub,hsub;
   GList p,q;
   InitString(&emp);
   InitString(&sub);
   InitString(&hsub);
   StrAssign(&emp,"()");
   if(!StrCompare(S,emp)) /* 创建空表 */
     *L=NULL;
   else
   {
     *L=(GList)malloc(sizeof(GLNode));
     if(!*L) /* 建表结点不成功 */
       exit(OVERFLOW);
     if(StrLength(S)==1) /* 创建单原子广义表 */
     {
       (*L)->tag=ATOM;
       (*L)->a.atom=S.ch[0];
     }
     else
     {
       (*L)->tag=LIST;
       p=*L;
       SubString(&sub,S,2,StrLength(S)-2); /* 脱外层括号 */
       do /* 重复建n个子表 */
       {
         sever(&sub,&hsub); /* 从sub中分离出表头串hsub */
         CreateGList(&p->a.ptr.hp,hsub);
         q=p;
         if(!StrEmpty(sub)) /* 表尾不空 */
         {
           p=(GList)malloc(sizeof(GLNode));
           if(!p)
             exit(OVERFLOW);
           p->tag=LIST;
           q->a.ptr.tp=p;
         }
       }while(!StrEmpty(sub));
       q->a.ptr.tp=NULL;
     }
   }
   return OK;
 }
Пример #29
0
Status Index(HString S, HString T, int pos){
  int len_s, len_t, i;
  HString Sub;
  len_s = StrLength(S);
  len_t = StrLength(T);
  InitString(&Sub);
  if(pos > 0){
    i = pos;
    while(i <= len_s - len_t + 1){
      SubString(&Sub, S, i, len_t);
      if(StrCompare(Sub, T) != 0){
        i++;
      }else{
        return i;
      }
    }
  }
  return 0;
}
Пример #30
0
void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
{
	wcsession *WCC = WC;
	
	if (WCC != NULL) {
		if (StrLength(WCC->ImportantMsg) > 0) {
			StrEscAppend(Target, WCC->ImportantMsg, NULL, 0, 0);
		}
	}
}