Beispiel #1
0
int is_prime(char InpStr[37]){
    int len,i,numb;

    len=strlen(InpStr)-1;
    for(i=0;i<len;i++){
        if(InpStr[i]<'0'||InpStr[i]>'9')
            return -1;
    }

    numb=ConvertStrToInt(InpStr,len);

    if(numb==0||numb==1)
        return 0;

    for(i=2;i<numb;i++){
        if(numb%i==0)
            return 0;
    }

    return 1;
}
void CCallback::ProcessCallbacks() {
	CMySQLQuery *Query = NULL;
	while( (Query = GetNextQuery()) != NULL) {
		CCallback *Callback = Query->Callback;
		 
		if(Callback != NULL && (Callback->Name.length() > 0 || Query->OrmObject != NULL) ) { 

			bool PassByReference = Query->Callback->IsInline;

			if(Query->OrmObject != NULL) { //orm, update the variables with the given result
				switch(Query->OrmQueryType) {
				case ORM_QUERYTYPE_SELECT:
					Query->OrmObject->ApplySelectResult(Query->Result);
					break;

				case ORM_QUERYTYPE_INSERT:
					Query->OrmObject->ApplyInsertResult(Query->Result);
					break;
				}
			}

			for (list<AMX *>::iterator a = m_AmxList.begin(), end = m_AmxList.end(); a != end; ++a) { 
				AMX *amx = (*a);
				cell amx_Ret;
				int amx_Index;
				cell amx_MemoryAddress = -1;

				if (amx_FindPublic(amx, Callback->Name.c_str(), &amx_Index) == AMX_ERR_NONE) { 
					
					CLog::Get()->StartCallback(Callback->Name.c_str());

					int StringIndex = Callback->ParamFormat.length()-1; 
					while(!Callback->Parameters.empty() && StringIndex >= 0) {
						switch(Callback->ParamFormat.at(StringIndex)) {
							case 'i':
							case 'd': {
								int val = 0;
								ConvertStrToInt(Callback->Parameters.top().c_str(), val);

								if(PassByReference == false)
									amx_Push(amx, (cell)val);
								else {
									cell tmpAddress;
									amx_PushArray(amx, &tmpAddress, NULL, (cell*)&val, 1);
									if(amx_MemoryAddress < NULL)
										amx_MemoryAddress = tmpAddress;
								}
							} break;

							case 'f': {
								float float_val = 0.0f;
								ConvertStrToFloat(Callback->Parameters.top().c_str(), float_val);
								cell FParam = amx_ftoc(float_val);
								
								if(PassByReference == false)
									amx_Push(amx, FParam);
								else {
									cell tmpAddress;
									amx_PushArray(amx, &tmpAddress, NULL, (cell*)&FParam, 1);
									if(amx_MemoryAddress < NULL)
										amx_MemoryAddress = tmpAddress;
								}

							} break;
							
							default: {
								cell tmpAddress;
								amx_PushString(amx, &tmpAddress, NULL, Callback->Parameters.top().c_str(), 0, 0);
								if(amx_MemoryAddress < NULL)
									amx_MemoryAddress = tmpAddress;
							}
						}

						StringIndex--;
						Callback->Parameters.pop();
					}


					Query->ConnHandle->SetActiveResult(Query->Result);
					Query->Result = NULL;

					amx_Exec(amx, &amx_Ret, amx_Index);
					if (amx_MemoryAddress >= NULL)
						amx_Release(amx, amx_MemoryAddress);

					if(Query->ConnHandle->IsActiveResultSaved() == false)
						delete Query->ConnHandle->GetActiveResult();

					Query->ConnHandle->SetActiveResult((CMySQLResult *)NULL);

					CLog::Get()->EndCallback();
					
					break; //we have found our callback, exit loop
				}
			}
		}
		Query->Destroy();
	}
}