コード例 #1
0
ファイル: Site.cpp プロジェクト: dblock/alkaline
CString CSite::Map(const CString& String, const CVector<CString>& Vector) {
    CString Result;
    int DPos = String.Pos('$');
    int i, PPos=0;
    CString MidValue;
    while (DPos >= 0) {
        String.Mid(PPos, DPos - PPos, &MidValue);
        Result += MidValue;
        i = ++DPos;
        while ((i < (int) String.GetLength()) && isdigit(String[i])) 
            i++;
        PPos = i;
        if (i != DPos) {
            i = String.GetInt(DPos, i - DPos);
            if (i>=0) {
                if ((int) Vector.GetSize() > i) 
                    Result+=Vector[i];
            }
        }
        DPos = String.Pos('$', DPos);
    }
    String.Mid(PPos, String.GetLength(), &MidValue);
    Result+=MidValue;
    return Result;
    
}
コード例 #2
0
ファイル: recent_class.cpp プロジェクト: dblock/agnes
struct tm recent_manager::encode_date(const CString& date_string){
	int day;
	int month;
	int year;
	struct tm when; time_t now;	time( &now ); when = *localtime( &now );	
	
	char sep = 0;
	if (date_string.Pos('.') >=0 ) sep = '.';
	else if (date_string.Pos('/') >= 0) sep = '/';
	else if (date_string.Pos('-') >= 0) sep = '-';  
  
	CVector<CString> Tokens; date_string.Tokenizer(sep, Tokens);
	assert(Tokens.Count()==3);
	year = Tokens[2].Val();
	month = Tokens[1].Val();
	day = Tokens[0].Val();
	
	if ((year>0)&&(year < 100)&&(year >= when.tm_year)) year = year + 1900;
	else if ((year>0)&&(year < 100)&&(year<when.tm_year)) year = year + 2000;	
	else assert((year>=0)&&(year<=100));  

	assert((month<=12)&&(month>=1));  
	day = date_string.Val();
	assert((day <= 31)&&(day >= 1));
  	
	struct tm this_day;
	this_day.tm_mday = day;
	this_day.tm_year = year;
	this_day.tm_mon = month;
	return(this_day);
}
コード例 #3
0
ファイル: EquivManager.cpp プロジェクト: dblock/alkaline
void CEquivManager::Read(void) {
    struct_stat NewStat;
    base_stat((const char *) m_Filename.GetBuffer(), &NewStat);
    if (GetSize() && (m_Stat.st_mtime == NewStat.st_mtime))
        return;

    m_LoadMutex.Lock();
    m_Stat = NewStat;
    RemoveAll();
    (* (CTSStringTable *) this) = m_PersistentTable;
    CLocalFile File(m_Filename);
    if (File.OpenReadBinary()) {
        CVector<CString> Lines;
        File.ReadLines(&Lines);
        CString Line;
        for (register int i=0; i<(int) Lines.GetSize(); i++) {
            Line = Lines[i];
            //// _L_DEBUG(6, cout << "CEquivManager::Read() - parsing " << Line << endl);
            if (!Line.GetLength()) continue;
            if (Line[0] == '#') {
                Line.Delete(0, 1);
                if ((Line.Pos('<')>=0)&&(Line.Pos('>')> Line.Pos('<'))) m_EmailVector += Line;
            } else {
                CVector<CString> Tokens;
                CString::StrToVector(Line, ',', &Tokens);
                if ((Tokens.GetSize() == 2)&&(Tokens[0].GetLength())&&(Tokens[1].GetLength())) {
                    // complex equivalences
                    CVector<CString> TokensLeft;
                    CString::StrToVector(Tokens[0], '+', &TokensLeft);
                    CVector<CString> TokensRight;
                    CString::StrToVector(Tokens[1], '+', &TokensRight);
                    if ((int) TokensLeft.GetSize() > 1) {
                        if (TokensLeft.GetSize() > TokensRight.GetSize()) {
                            cout << "Dropping malformed equivalence at " << Tokens[0] << "=" << Tokens[1] << endl;
                        } else {
                            for (int ii=1; ii<(int)TokensLeft.GetSize(); ii++) {
                                CString TL(TokensLeft[0]);
                                TL+=TokensLeft[ii];
                                CString TR(TokensRight[0]);
                                TR+=TokensRight[ii];
                                CTSStringTable::Set(TL, TR);
                            }
                        }
                    } else {
                        CTSStringTable::Set(Tokens[0], Tokens[1]);
                    }
                }
            }
        }
    }
    m_LoadMutex.UnLock();
}
コード例 #4
0
ファイル: windows.cpp プロジェクト: henryfung01/GameCode4
//-----------------------------------------------------------
//send f keys to onkey handler
bool ProcessFuncKey(CString k)
{
	//talke a copy
	CString temp=k;

	//get count value & strip out count characters
	//from temporary value
	int count=GetFunctionKeyCount(k);

	//is it a function key?
	if (IsAFunctionKey(k) || k.Pos("\\")==1)
	{
		//pass it count times to handler
		for(int i=0;i<count;i++)
		{
			OnKeyHandler(true,k);
		}
		return true;
	}
	else
	{
		//restore original if not an F key
		k=temp;
	}

	return false;
}
コード例 #5
0
ファイル: MimeParser.cpp プロジェクト: dblock/baseclasses
bool CMimeParser::ProcessMultipart(CString RawData, const CString& Boundary, CVectorTable<CStringTable>& Fields) {
  //cout << "expected boundary: [" << "--" + Boundary << "]" << endl;	
  CString OneLine; RawData.ExtractLine(&OneLine);
  //cout << "   found boundary: [" << OneLine << "]" << endl;
  CString PrefixedBoundary;
  while (OneLine.GetLength()) {
    //cout << OneLine << endl;
    PrefixedBoundary = g_strDashDash;
    PrefixedBoundary.Append(Boundary);
    if (OneLine == PrefixedBoundary) {
      CStringTable Table;
      CString Name, Value;
      RawData.ExtractLine(&OneLine);
      while (OneLine.GetLength()) {
        if (ParseLine(OneLine, Name, Value, Table)) {
          //Fields.Add(Name, Table);
          // _L_DEBUG(3, cout << "---------------------" << endl);
          // _L_DEBUG(3, cout << "Content disposition: " << Table.GetValue("Content-Disposition") << endl);
          // _L_DEBUG(3, cout << "               Name: " << Table.GetValue("name") << endl);
          // _L_DEBUG(3, cout << "       Content type: " << Table.GetValue("Content-type") << endl);
          // _L_DEBUG(3, cout << "           Filename: " << Table.GetValue("Filename") << endl);
        } else return false;
        RawData.ExtractLine(&OneLine);
      }            
      int NextBoundaryPosition = RawData.Pos(PrefixedBoundary);
      if (NextBoundaryPosition == -1) NextBoundaryPosition = RawData.GetLength();
      Table.Add(g_strValue, CString(RawData.GetBuffer(), NextBoundaryPosition-2));
      Fields.Add(Table.GetValue(g_strName), Table);
      RawData.Delete(0, NextBoundaryPosition);
      // _L_DEBUG(3, cout << "              Value: " << Table.GetValue(g_strValue) << endl);
      RawData.ExtractLine(&OneLine);
    } else return false;
  }
  return true;
}
コード例 #6
0
ファイル: chttprequest.cpp プロジェクト: dblock/agnes
void CHttpRequest::ProcessOneLine(const CString& Line){
  int sPos = Line.Pos(':');
  if (sPos > 0) {
    RHeaderResponse.set_value(Line.Copy(0, sPos), Line.Copy(sPos+1, Line.StrLength()).StrTrim());
#ifdef _U_DEBUG
    cout << "CHTTPREQUEST::Header:[" << Line.Copy(0, sPos) << "]:[" << Line.Copy(sPos+1, Line.StrLength()).StrTrim() << "]" << endl;
#endif
  } else {
#ifdef _U_DEBUG
    cout << "CHTTPREQUEST::Header (???):[" << Line << "]" << endl;
#endif
  }
}
コード例 #7
0
ファイル: windows.cpp プロジェクト: henryfung01/GameCode4
//-----------------------------------------------------------
//function keys
void PushFnKey(CString KeyCode)
{

	// Outputs function key. KeyCode may have a number of times to be output
	LONG NumPushes;
	INT index;
	CString FnKey;
	CString OrigCode;
	bool isfnkey=false;

	// Work out which function key to push and how many times

	//get key press count & strip out count characters
	NumPushes=GetFunctionKeyCount(KeyCode);

	//keep a copy
	OrigCode=KeyCode;

	FnKey=KeyCode.UpperCase();

	//direct code entry
	if (FnKey.Pos("\\")==1)
	{
		ProcessFuncKey(FnKey);
		return;
	}

	//braces
	if (FnKey=="LEFTBRACE" || FnKey=="RIGHTBRACE")
	{
		char pc=FnKey.Pos("LEFT")<1 ? '}' : '{';
		for (index=1;index<=NumPushes;index++)
		{
			PushAKey(pc);
		}
		return;
	}

	//search for F key
	byte fnkey=GetFunctionKey(FnKey);

	if (fnkey==(byte)-1)
		fnkey=GetControlKey(FnKey);

	if (fnkey!=(byte)-1)
	{
		isfnkey=true;
	}

	//press f key
	if (isfnkey)
	{
		bool dodos=false;

		//do DOS conversion?
		if (DOSKey)
		{
			byte vk[]={VK_BELL,VK_BREAK,VK_RETURN,VK_ESCAPE,VK_CLEAR,VK_LINEFEED,VK_TAB};
			char dk[]={'G','C','M','[','L','J','I'};

			//search for key equivalent
			for (int i=0;i<sizeof(vk)/sizeof(vk[0]);i++)
			{
				if (fnkey==vk[i])
				{
					//match found
					dodos=true;

					for (index=1;index<=NumPushes;index++)
					{
						//do key press
						PushCTRLKey(dk[i]);
					}
					break;
				}
			}
		}
		if (!dodos)//normal fkey
		{
			for (index=1;index<=NumPushes;index++)
			{
				//reserved characters
				if (GetControlKey(fnkey)!=(byte)-1)
				{
					PushAKey(fnkey);
				}
				else
				{
					//full printscreen
					if (fnkey==VK_SNAPSHOT && !AltOn)
					{
						PressKey(fnkey,1);
					}
					else
					{
						PressKey(fnkey,MapVirtualKey(fnkey,0));
					}
				}
			}
		}
	}
	//sleeep or NL or clear clipboard or run
	else if(FnKey!="SLEEP" && FnKey!="NEWLINE" && FnKey!="NL"  && FnKey !="EMPTYCLIP"
		&& FnKey.Pos("RUN ")!=1)
	{
		// Ordinary keys
		for (index=1; index<=NumPushes; index++)
		{
			for (int i=0;i<OrigCode.GetLength();i++)
			{
				char ss=OrigCode[i+1];

				//watch for {~ 2}
				if(ss!='~' || OrigCode=="~")
				{
					OnKeyHandler(false,ss);
				}
				else
				{
					//{hello world~ 3}
					OnKeyHandler(true,"ENTER");
				}
			}
		}
	}
}
コード例 #8
0
ファイル: MimeParser.cpp プロジェクト: dblock/baseclasses
bool CMimeParser::ParseLine(const CString& CommandLine, CString& Name, CString& Value, CStringTable& Result) {
  int sPos = CommandLine.Pos(':');
  if (sPos > 0) {
    CommandLine.Mid(0, sPos, &Name);
    Name.Trim();    
    CommandLine.Mid(sPos+1, CommandLine.GetLength(), &Value); 
    Value.Trim();

    if (Name.Same("Authorization") || 
	Name.Same("Location")) {
      Result.Add(Name, Value);
      return true;
    }
 
    int CurPos = 0;
    int PrevPos = 0;
    CString ParameterName = Name;
    CString ParameterValue;
    bool Comment = false;
    while (CurPos < (int) Value.GetLength()) {
      switch(Value[CurPos]) {
      case '(':
        if (!Comment) Comment = true;
        break;
      case ')':
        Comment = false;
        break;
      case '=':
        // double ==, Base64 encoded for example
        if ((CurPos + 1) < (int) Value.GetLength()) {
          if (Value[CurPos + 1] == '=') {
            CurPos++;
            break;
          }
        }
        if (!Comment) {
          Value.Mid(PrevPos, CurPos - PrevPos, &ParameterName);
          ParameterName.Trim();
          PrevPos = CurPos+1;
        }
        break;
      case ';':
        if (!Comment) {
          Value.Mid(PrevPos, CurPos - PrevPos, &ParameterValue);
          ParameterValue.Trim();
          PrevPos = CurPos+1;
          ParameterName.Dequote();
          ParameterValue.Dequote();
          Result.Add(ParameterName, ParameterValue);
          /*
            CVector<CString> ParameterValueVector = CString::StrToVector(ParameterValue, ',');
            for (register int i=0;i<(int)ParameterValueVector.GetSize();i++) {
            _L_DEBUG(3, cout << "adding [" << ParameterName << "][" << ParameterValueVector[i].Trim() << "]" << endl);
            Result.Add(ParameterName, ParameterValueVector[i].Trim().Dequote());
            }
          */
        }
        break;
      default:
        break;
      };
      CurPos++;
    }
    if (PrevPos != (int) Value.GetLength()) {
      Value.Mid(PrevPos, Value.GetLength(), &ParameterValue);
      ParameterValue.Trim();
      /*
        CVector<CString> ParameterValueVector = CString::StrToVector(ParameterValue, ',');
        for (register int i=0;i<(int)ParameterValueVector.GetSize();i++) {
        _L_DEBUG(3, cout << "adding [" << ParameterName << "][" << ParameterValueVector[i].Trim() << "]" << endl);
        Result.Add(ParameterName, ParameterValueVector[i].Trim().Dequote());
        }
      */
      ParameterName.Dequote();
      ParameterValue.Dequote();
      Result.Add(ParameterName, ParameterValue);
    }

    return true;
  } else return false;
}