Skein::Node* TranscriptWindow::FindRelevantNode(FindAction action, bool next, bool selected)
{
    // Get all the nodes in the transcript or skein
    CArray<Skein::Node*,Skein::Node*> nodes;
    if (action == SkeinDifferent)
    {
        ASSERT(next);
        m_skein->GetAllNodes(nodes);
    }
    else
    {
        Skein::Node* node = m_skeinEndThread;
        while (node != NULL)
        {
            if (next)
                nodes.InsertAt(0,node);
            else
                nodes.Add(node);
            node = node->GetParent();
        }
    }
    if (next)
        nodes.InsertAt(0,(Skein::Node*)NULL);

    // Return the next relevant node after the selected node (which may be NULL)
    bool afterSelected = false;
    for (int i = 0; i < nodes.GetSize(); i++)
    {
        if (afterSelected == false)
        {
            if (nodes.GetAt(i) == (selected ? m_skeinSelected : NULL))
                afterSelected = true;
        }
        else
        {
            switch (action)
            {
            case TranscriptDifferent:
            case SkeinDifferent:
                if (nodes.GetAt(i)->GetDiffers() != Skein::Node::ExpectedSame)
                    return nodes.GetAt(i);
                break;
            case TranscriptChanged:
                if (nodes.GetAt(i)->GetChanged())
                    return nodes.GetAt(i);
                break;
            default:
                ASSERT(FALSE);
                break;
            }
        }
    }

    // If nothing found, then if searching the whole skein, start from the beginning
    if ((action == SkeinDifferent) && selected)
        return FindRelevantNode(action,next,false);
    return NULL;
}
Example #2
0
void  CFileSelectList::DelSelItems()
{
	POSITION pos = GetFirstSelectedItemPosition();
	CArray<int> aryIndex;
	while(pos != NULL)
	{
		aryIndex.InsertAt(0,GetNextSelectedItem(pos));
	}

	for(int i= 0;i<aryIndex.GetCount();++i)
	{
		ItemDataType* pItemData = (ItemDataType*)GetItemData(aryIndex[i]);
		SAFE_DELETE(pItemData)
		DeleteItem(aryIndex[i]);
	}
}
Example #3
0
void main()
{
	CArray arr;
	arr.Add(1234);
	arr.Add(23);
	arr.Add(44);
	arr.Add(21);
	arr.Add(5);
	arr.RemoveAt(2,20000000); //从第二个位置起,删除2个数据
	arr.InsertAt(3,10,2);
	int i = 0;
	int nSize = arr.GetSize();
	cout << "共有 " << nSize << " 条数据" << endl;
	
	TYPE *p = arr.GetData();
	
	qsort(p,nSize,sizeof(TYPE),compar);

	while(i < nSize)
	{
		cout << arr[i] << endl;
		++i;
	}
}
Example #4
0
void CItemData::InsertColumn(int nColumn)
{
	aTextColors.InsertAt(nColumn, ::GetSysColor(COLOR_WINDOWTEXT));
	aBkColors.InsertAt(nColumn, ::GetSysColor(COLOR_WINDOW));
}
Example #5
0
int CProxy::SubstituteTags(CString *buf, int skAccept, int searchflag, char *searchstring, int startswithflag, char *startswithstring, char *errorcode, int adminFlag)
{
	int ret = 0;
	int	iError = 0;
	char	*pszSongTitle = (char *)1;
	char	szArtist[255] = "";
	int		playlistpos = 0;
	CString	substituted;
	char	tmpbuf[1024] = "";
	int		replaceflag = 0;
	CString tempArtist;
	int		foundit = 0;
	int		loop = 1;
	int		errorCode = 0;

	errorCode = atoi(errorcode);

	ret = buf->Find("%%ARTISTSELECT%%");

	if (ret != -1) {
		while(loop) {
			memset(szArtist, '\000', sizeof(szArtist));
			loop = getArtist(playlistpos, szArtist);
			if(loop) {
				tempArtist = szArtist;
				foundit = 0;
				for(int i=0;i <= ArtistList.GetUpperBound();i++) {
					if (ArtistList.GetAt(i) == tempArtist) {
						foundit = 1;
					}
				}
				if (!foundit) {
					if (strlen(tempArtist) > 0) {	
						ArtistList.Add(tempArtist);
					}
				}
			}
			playlistpos++;
		}

		CArray<CString, CString &> ArtistListSorted;

		for(int j=0;j <= ArtistList.GetUpperBound();j++) {
			int added = 0;
			for (int k=0;k <= ArtistListSorted.GetUpperBound();k++) {
				if (ArtistList.GetAt(j) < ArtistListSorted.GetAt(k)) {
					ArtistListSorted.InsertAt(k, ArtistList.GetAt(j));
					added = 1;
					break;
				}
			}
			if (!added) {
				ArtistListSorted.Add(ArtistList.GetAt(j));
			}
		}

		for(int i=0;i <= ArtistListSorted.GetUpperBound();i++) {
			substituted = *buf;
			substituted.Replace("%%ARTISTSELECT%%", ArtistListSorted.GetAt(i));
			iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
			iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		}
		return 1;
	}

	ret = buf->Find("%%ADMINWINAMPCONTROL%%");

	if (ret != -1) {
		substituted = *buf;
		if (adminFlag) {
			char	hiddenfield[1024] = "";
			sprintf(hiddenfield, "<table bordercolor=white border=1><tr><td colspan=5>Winamp Admin Control</td></tr><tr><td><a href=\"admin.cgi?pass=%s&action=prev\">Prev</td><td><a href=\"admin.cgi?pass=%s&action=play\">Play</td><td><a href=\"admin.cgi?pass=%s&action=pause\">Pause</td><td><a href=\"admin.cgi?pass=%s&action=stop\">Stop</td><td><a href=\"admin.cgi?pass=%s&action=next\">Next</td><tr><td colspan=5><a href=\"admin.cgi?pass=%s&action=refreshcache\">Refresh Playlist Cache</td></tr></table>", g_AdminPassword, g_AdminPassword, g_AdminPassword, g_AdminPassword, g_AdminPassword, g_AdminPassword);
			substituted.Replace("%%ADMINWINAMPCONTROL%%", hiddenfield);
		}
		else {
			substituted.Replace("%%ADMINWINAMPCONTROL%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	ret = buf->Find("%%ADMINHIDDENFIELD%%");

	if (ret != -1) {
		substituted = *buf;
		if (adminFlag) {
			char	hiddenfield[1024] = "";
			sprintf(hiddenfield, "<input type=hidden name=pass value=\"%s\">", g_AdminPassword);
			substituted.Replace("%%ADMINHIDDENFIELD%%", hiddenfield);
		}
		else {
			substituted.Replace("%%ADMINHIDDENFIELD%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}
	ret = buf->Find("%%ADMINPASSWORD%%");

	if (ret != -1) {
		substituted = *buf;
		if (adminFlag) {
			char	hiddenfield[1024] = "";
			sprintf(hiddenfield, "&pass=%s", g_AdminPassword);
			substituted.Replace("%%ADMINPASSWORD%%", hiddenfield);
		}
		else {
			substituted.Replace("%%ADMINPASSWORD%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	ret = buf->Find("%%ERROR%%");

	if (ret != -1) {
		substituted = *buf;
		if (errorCode != 0) {
			substituted.Replace("%%ERROR%%", errorTable[errorCode]);
		}
		else {
			substituted.Replace("%%ERROR%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	ret = buf->Find("%%HTTP_REFERRER%%");

	if (ret != -1) {
		substituted = *buf;
		if (errorCode != 0) {
			substituted.Replace("%%HTTP_REFERRER%%", m_Referrer);
		}
		else {
			substituted.Replace("URL=%%HTTP_REFERRER%%", "");
			substituted.Replace("%%HTTP_REFERRER%%", "");
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		return 1;
	}


	playlistpos = 0;
	ret = buf->Find("%%PLAYLISTENTRY%%");

	if (ret != -1) {
		int startingPos = 0;
		if (strlen(m_Current) > 0) {
			startingPos = atoi(m_Current);
		}

		int currentPos = 0;
		numDisplayed = 0;
		maxEntries = atoi(g_MaxEntries);
		while(pszSongTitle) {
			pszSongTitle = getSongTitle(playlistpos);
			if(pszSongTitle) {
				replaceflag = 1;
				if (searchflag) {
					if (CompareNonCase(pszSongTitle, searchstring, strlen(searchstring))) {
						replaceflag = 1;
					}
					else {
						replaceflag = 0;
					}
				}
				if (startswithflag) {
					if (CompareNonCaseBeginning(pszSongTitle, startswithstring, strlen(startswithstring))) {
						replaceflag = 1;
					}
					else {
						replaceflag = 0;
					}
				}

				if (replaceflag) {
					if ((currentPos >= startingPos) && (numDisplayed < maxEntries)) {
						substituted = *buf;
						substituted.Replace("%%PLAYLISTENTRY%%", pszSongTitle);
						memset(tmpbuf, '\000', sizeof(tmpbuf));
						if (adminFlag) {
							sprintf(tmpbuf, "%d&pass=%s", playlistpos, g_AdminPassword);
						}
						else {
							sprintf(tmpbuf, "%d", playlistpos);
						}

						substituted.Replace("%%PLAYLISTPOS%%", tmpbuf);
						iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
						iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
						numDisplayed++;
					}
					currentPos++;
				}
			}
			playlistpos++;
		}
		return 1;
	}
	ret = buf->Find("%%QUEUELISTENTRY%%");

	pszSongTitle = (char *)1;
	
	playlistpos = RequestQueue.GetUpperBound();

	int	queuepos = 1;
	if (ret != -1) {
		while(pszSongTitle) {
			pszSongTitle = GetQueueTitle(playlistpos);
			if(pszSongTitle) {
				substituted = *buf;
				substituted.Replace("%%QUEUELISTENTRY%%", pszSongTitle);
				memset(tmpbuf, '\000', sizeof(tmpbuf));
				if (adminFlag) {
					sprintf(tmpbuf, "<a href=\"admin.cgi?pass=%s&action=delete&listpos=%d\">Delete</a>&nbsp;%d", g_AdminPassword, queuepos, queuepos);
				}
				else {
					sprintf(tmpbuf, "%d", queuepos);
				}
				substituted.Replace("%%QUEUELISTPOS%%", tmpbuf);
				iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
				iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

			}
			playlistpos--;
			queuepos++;
		}
		return 1;
	}

	ret = buf->Find("%%NAV_NEXT%%");

	if (ret != -1) {
		substituted = *buf;
		char	buff[255] = "";
		if (strchr(g_choppedrequest, '?')) {
			sprintf(buff, "<a href=\"%s&current=%d\">Next..></a>", g_choppedrequest, atoi(m_Current) + atoi(g_MaxEntries));
		}
		else {
			char	params[255] = "";

			if (startswithflag) {
				sprintf(params, "startswith=%s&current=%d", startswithstring, atoi(m_Current) + atoi(g_MaxEntries));
			}
			if (searchflag) {
				sprintf(params, "psearch=%s&current=%d", searchstring, atoi(m_Current) + atoi(g_MaxEntries));
			}
			if (strlen(params) == 0) {
				sprintf(params, "current=%d", atoi(m_Current) + atoi(g_MaxEntries));
			}
			if (adminFlag) {
				sprintf(buff, "<a href=\"admin.cgi?pass=%s&%s\">Next..></a>", g_AdminPassword, params);
			}
			else {
				sprintf(buff, "<a href=\"playlist.cgi?%s\">Next..></a>", params);
			}
		}
		if (numDisplayed < maxEntries) {
			substituted.Replace("%%NAV_NEXT%%", "");
		}
		else {
			substituted.Replace("%%NAV_NEXT%%", buff);
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		return 1;
	}
	ret = buf->Find("%%NAV_PREV%%");

	if (ret != -1) {
		substituted = *buf;
		char	buff[255] = "";
		if (strchr(g_choppedrequest, '?')) {
			sprintf(buff, "<a href=\"%s&current=%d\"><..Prev</a>", g_choppedrequest, atoi(m_Current) - atoi(g_MaxEntries));
		}
		else {
			char	params[255] = "";

			if (startswithflag) {
				sprintf(params, "startswith=%s&current=%d", startswithstring, atoi(m_Current) - atoi(g_MaxEntries));
			}
			if (searchflag) {
				sprintf(params, "psearch=%s&current=%d", searchstring, atoi(m_Current) - atoi(g_MaxEntries));
			}
			if (strlen(params) == 0) {
				sprintf(params, "current=%d",  atoi(m_Current) - atoi(g_MaxEntries));
			}
			if (adminFlag) {
				sprintf(buff, "<a href=\"admin.cgi?pass=%s&%s\"><...Prev</a>", g_AdminPassword, params);
			}
			else {
				sprintf(buff, "<a href=\"playlist.cgi?%s\"><...Prev</a>", params);
			}
		}
		if ((atoi(m_Current) - atoi(g_MaxEntries)) < 0) {
			substituted.Replace("%%NAV_PREV%%", "");
		}
		else {
			substituted.Replace("%%NAV_PREV%%", buff);
		}
		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		return 1;
	}

	ret = buf->Find("%%CURRENTSONG%%");

	if (ret != -1) {
		pszSongTitle = getCurrentSong();
		if(pszSongTitle) {
			substituted = *buf;
			substituted.Replace("%%CURRENTSONG%%", pszSongTitle);
			iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
			iError = send(skAccept, "\r\n", strlen("\r\n"), 0);

		}
		return 1;
	}

	ret = buf->Find("%%CONTENT_REFRESH%%");
	if (ret != -1) {
		substituted = *buf;
		GetSecondsLeft();
		char tmp[25] = "";
		sprintf(tmp, "%d", g_CurrentSongLeft + 5);
		
		substituted.Replace("%%CONTENT_REFRESH%%", tmp);

		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}
	ret = buf->Find("%%PCT_LEFT%%");
	if (ret != -1) {
		substituted = *buf;
		GetSecondsLeft();
		char tmp[25] = "";
		sprintf(tmp, "%d", g_CurrentPctLeft);
		
		substituted.Replace("%%PCT_LEFT%%", tmp);

		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	ret = buf->Find("%%SONG_LENGTH%%");
	if (ret != -1) {
		substituted = *buf;
		GetSecondsLeft();
		char tmp[25] = "";
		sprintf(tmp, "%d", g_CurrentSongLength);
		
		substituted.Replace("%%SONG_LENGTH%%", tmp);

		iError = send(skAccept, substituted.GetBuffer(substituted.GetLength()), substituted.GetLength(), 0);
		iError = send(skAccept, "\r\n", strlen("\r\n"), 0);
		return 1;
	}

	return 0;		
}
Example #6
0
void CProxy::RequestHandler(char *request)
{
	int	playlistpos = 0;
	char	suppliedPass[255] = "";

	char	variable[255] = "";
	char	value[255] = "";
	int		action = 0;
	int		adminFlag = 0;

	char	msg[255] = "";
	int		valid = 0;
	int		errorCode = 0;

	int	requestFlag = 0;
	if (!strncmp(request, "/request.cgi", strlen("/request.cgi"))) {
		char	*p1;
		p1 = strchr(request, '?');
		if (p1) {
			p1++;
			char	*token;
			token = strtok(p1, "&");
			while (token != NULL) {
				char	*p2;
				p2 = strchr(token, '=');
				if (p2) {
					memset(variable, '\000', sizeof(variable));
					memset(value, '\000', sizeof(value));

					int lengthtocopy = 0;
					if ((p2-token) > (sizeof(variable)-1)) {
						lengthtocopy = sizeof(variable)-1;
					}
					else {
						lengthtocopy = p2-token;
					}
					strncpy(variable, token, lengthtocopy);
					p2++;
					strncpy(value, p2, sizeof(value)-1);
					if (!strcmp(variable, "pass")) {
						strncpy(suppliedPass, value, sizeof(suppliedPass)-1);
					}
					if (!strcmp(variable, "listpos")) {
						playlistpos = atoi(value);
					}
				}
				token = strtok(NULL, "&");
			}
		}
		if (strlen(g_AdminPassword) > 0) {
			if (!strcmp(suppliedPass, g_AdminPassword)) {
					adminFlag = 1;
			}
			else {
				adminFlag = 0;
			}
		}
		requestFlag = 1;
	}

//    if (sscanf(request, "/request.cgi?listpos=%d", &playlistpos) == 1) {
	if (requestFlag) {
		if (adminFlag) {
			errorCode = REQUEST_ACCEPTED;
		}
		else {
			errorCode = ValidateRequest(playlistpos);
		}

		if (errorCode == REQUEST_ACCEPTED) {
				EnterCriticalSection(&GlobalCriticalSection_QueueList); 
				Req_Queue newQueueItem;
				newQueueItem.playlistpos = playlistpos;
				newQueueItem.requestingIP = connectedTo;

				RequestQueue.InsertAt(0, newQueueItem, 1);
				LeaveCriticalSection(&GlobalCriticalSection_QueueList);
		}
	} 

	char	location[1024] = "";
	if (strlen(m_Referrer) > 0) {
		CString  tS = m_Referrer;
		tS.Replace("action=", "actionx=");
		strcpy(m_Referrer, LPCSTR(tS));
		if (errorCode == 0) {
			_snprintf(location, sizeof(location)-1, "Location: %s", m_Referrer);
		}
		else {
			_snprintf(location, sizeof(location)-1,  "Location: %s&errorCode=%d", m_Referrer, errorCode);
		}
	}
	else {
		if (errorCode == 0) {
			_snprintf(location, sizeof(location)-1,  "Location: /playlist.cgi");
		}
		else {
			_snprintf(location, sizeof(location)-1,  "Location: /playlist.cgi?errorCode=%d", errorCode);
		}
	}
	send_headers(302, "Moved Temporarily", (char*) location, 0, -1, -1 );

}
Example #7
0
SSHANDLE* CSSolid::CreateNewVertexList(CSSFace *pFace, CSSEdge *pEdge1, 
									   CSSEdge *pEdge2, int& nv1index, int& nv2index,
									   CSSVertex *pNewVertex1, CSSVertex *pNewVertex2)
{
	// get original vertex list
	CArray<SSHANDLE, SSHANDLE&> hVertexList;
	hVertexList.SetSize(pFace->nEdges+4);
	CreatePointHandleList(*pFace, hVertexList.GetData());

	// add vertex1 and vertex2.
	nv1index = -1;
	nv2index = -1;

	int nVertices = pFace->nEdges;
	int iPass = 0;
DoAgain:
	for(int i = 0; i < nVertices; i++)
	{
		int iPrevIndex = GetNext(i, -1, nVertices);
		int iNextIndex = GetNext(i, 1, nVertices);

		if(nv1index == -1 && (hVertexList[i] == pEdge1->hvEnd || 
			hVertexList[i] == pEdge1->hvStart))
		{
			// find pEdge1->hvStart
			if(hVertexList[iPrevIndex] == pEdge1->hvStart || 
				hVertexList[iPrevIndex] == pEdge1->hvEnd)
			{
				// add at i.
				nv1index = i;
			}
			if(hVertexList[iNextIndex] == pEdge1->hvStart || 
				hVertexList[iNextIndex] == pEdge1->hvEnd)
			{
				// add at iNextIndex
				nv1index = iNextIndex;
			}

			if(nv1index != -1)
			{
				hVertexList.InsertAt(nv1index, pNewVertex1->id);
				++nVertices;
				break;
			}
		}

		if(nv2index == -1 && (hVertexList[i] == pEdge2->hvEnd || 
			hVertexList[i] == pEdge2->hvStart))
		{
			// find pEdge1->hvStart
			if(hVertexList[iPrevIndex] == pEdge2->hvStart || 
				hVertexList[iPrevIndex] == pEdge2->hvEnd)
			{
				// add at i.
				nv2index = i;
			}
			if(hVertexList[iNextIndex] == pEdge2->hvStart || 
				hVertexList[iNextIndex] == pEdge2->hvEnd)
			{
				// add at iNextIndex
				nv2index = iNextIndex;
			}

			if(nv2index != -1)
			{
				hVertexList.InsertAt(nv2index, pNewVertex2->id);
				++nVertices;
				break;
			}
		}
	}

	SSHANDLE hTmp[64];
	memcpy(hTmp, hVertexList.GetData(), sizeof(SSHANDLE) * nVertices);

	if(nv1index == -1 && nv2index == -1)
		return NULL;	// not used here.

	if(nv1index == -1 || nv2index == -1)
	{
		if(++iPass != 2)
			goto DoAgain;
	}

	SSHANDLE *rvl = new SSHANDLE[nVertices];
	memcpy(rvl, hVertexList.GetData(), sizeof(SSHANDLE) * nVertices);

	return rvl;
}
Example #8
0
BOOL MPCStatusBar::AddIndicator( int position, UINT paneID )
{
 CArray<MPCStatusBarPane,MPCStatusBarPane> arPanes;

 MPCStatusBarPane statusPane;
 int i;

 i = 0;
 while( GetStatusPane(i,statusPane) )
 {
  arPanes.Add( statusPane );
  i++;
 }
 if( position < 0 )
  position = 0;
 if( position > arPanes.GetSize() )
  position = arPanes.GetSize()-1;

 for(i = 0; i < arPanes.GetSize(); i ++ )
 {
  if( paneID == arPanes[i].nID )
  {
   TRACE(_T("XFXStatusBar::AddIndicator(): Pane ID already exists \n"));
   return FALSE;
  }
 }

 MPCStatusBarPane new_statusPane;
 new_statusPane.nID = paneID;
 if( arPanes.GetSize() )
  arPanes.InsertAt(position,new_statusPane);
 else
  arPanes.Add(new_statusPane);

 UINT * pIndicators = new UINT[arPanes.GetSize()];
 for(i=0;i<arPanes.GetSize();i++)
  pIndicators[i]=arPanes[i].nID;

 SetRedraw(FALSE);
 SetIndicators(pIndicators,arPanes.GetSize());

 // Replace infos of indicators ..
 for(i = 0; i < arPanes.GetSize(); i++ )
 {
  if( arPanes[i].nID != paneID )
  {
   SetPaneInfo(i,arPanes[i].nID,arPanes[i].nStyle,arPanes[i].cxText);
   SetPaneText(i,arPanes[i].strText);
  }
  else
  {
   SetPaneWidth(i,50);
   SetPaneText(i,arPanes[i].strText);
  }

 }
 delete pIndicators;
 SetRedraw(TRUE);
 PositionControls();
 Invalidate(TRUE);
 return TRUE;
}