static TCHAR* getDBSetting(MCONTACT hContact, char* module, char* setting, TCHAR* defaultValue) { DBVARIANT dbv; if (db_get_s(hContact, module, setting, &dbv, 0)) return defaultValue; TCHAR *var = NULL; switch (dbv.type) { case DBVT_BYTE: var = itot(dbv.bVal); break; case DBVT_WORD: var = itot(dbv.wVal); break; case DBVT_DWORD: var = itot(dbv.dVal); break; case DBVT_ASCIIZ: var = mir_a2t(dbv.pszVal); break; case DBVT_WCHAR: var = mir_wstrdup(dbv.pwszVal); break; case DBVT_UTF8: Utf8Decode(dbv.pszVal, &var); break; } db_free(&dbv); return var; }
static TCHAR *parseNum(ARGUMENTSINFO *ai) { if (ai->argc != 3) return NULL; int val = ttoi(ai->targv[1]); int padding = ttoi(ai->targv[2]); TCHAR *szVal = itot(val); if (szVal == NULL) return NULL; unsigned zeros = max(padding - (signed int)mir_tstrlen(szVal), 0); TCHAR *res = (TCHAR*)mir_alloc((zeros + mir_tstrlen(szVal) + 1)*sizeof(TCHAR)); if (res == NULL) { mir_free(szVal); return NULL; } memset(res, 0, ((zeros + mir_tstrlen(szVal) + 1) * sizeof(TCHAR))); TCHAR *cur = res; for (unsigned i = 0; i < zeros; i++) *cur++ = '0'; mir_tstrcat(res, szVal); mir_free(szVal); return res; }
static TCHAR *parseMuldiv(ARGUMENTSINFO *ai) { if (ai->argc != 4) return NULL; if (ttoi(ai->targv[3]) == 0) return NULL; return itot((ttoi(ai->targv[1])*ttoi(ai->targv[2])) / ttoi(ai->targv[3])); }
static TCHAR *parseMul(ARGUMENTSINFO *ai) { if (ai->argc < 3) return NULL; int result = ttoi(ai->targv[1]); for (unsigned i = 2; i < ai->argc; i++) result *= ttoi(ai->targv[i]); return itot(result); }
static TCHAR *parseAdd(ARGUMENTSINFO *ai) { if (ai->argc < 3) return NULL; int result = 0; for (unsigned int i = 1; i < ai->argc; i++) result += ttoi(ai->targv[i]); return itot(result); }
static TCHAR *parseMax(ARGUMENTSINFO *ai) { if (ai->argc < 2) return NULL; int maxVal = ttoi(ai->targv[1]); for (unsigned i = 2; i < ai->argc; i++) maxVal = max(ttoi(ai->targv[i]), maxVal); return itot(maxVal); }
void turnOnLcdAndWriteTime(){//done LCD_TurnOnDisplay(); LCD_BL_State(1); RTC_GetValue(&dateTime); char time[time_len], date[date_len]; itot(time, dateTime.tm_hour, dateTime.tm_min); itod(date, dateTime.tm_mday, dateTime.tm_mon, dateTime.tm_year); LCD_Goto(3,1); LCD_WriteString(date); LCD_Goto(5,2); LCD_WriteString(time); LCD_Goto(5,3); //if(count>=0)LCD_WriteChar('*'); }
static TCHAR *parseMod(ARGUMENTSINFO *ai) { if (ai->argc != 3) return NULL; int val1 = ttoi(ai->targv[1]); int val2 = ttoi(ai->targv[2]); if (val2 == 0) return NULL; return itot(val1 % val2); }
static TCHAR* parseContactCount(ARGUMENTSINFO *ai) { if (ai->argc != 3) return NULL; CONTACTSINFO ci = { 0 }; ci.cbSize = sizeof(ci); ci.tszContact = ai->targv[1]; ci.flags = getContactInfoFlags(ai->targv[2]); int count = getContactFromString(&ci); if (count != 0 && ci.hContacts != NULL) mir_free(ci.hContacts); return itot(count); }
/* returns info about a contact as a string */ TCHAR* getContactInfoT(BYTE type, MCONTACT hContact) { /* returns dynamic allocated buffer with info, or NULL if failed */ TCHAR *res = NULL; char protoname[128], szVal[16]; PROTOACCOUNT *pa; if (hContact == NULL) return NULL; char *szProto = GetContactProto(hContact); if (szProto == NULL) return NULL; switch (type) { case CCNF_PROTOID: return mir_a2t(szProto); case CCNF_ACCOUNT: pa = ProtoGetAccount(szProto); return pa ? mir_tstrdup(pa->tszAccountName) : NULL; case CCNF_PROTOCOL: if (CallProtoService(szProto, PS_GETNAME, (WPARAM)sizeof(protoname), (LPARAM)protoname)) return NULL; return mir_a2t(protoname); case CCNF_STATUS: return mir_tstrdup((TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE), GSMDF_UNICODE)); case CCNF_INTERNALIP: case CCNF_EXTERNALIP: { DWORD ip = db_get_dw(hContact, szProto, (type == CCNF_INTERNALIP) ? "RealIP" : "IP", 0); if (ip == 0) return NULL; struct in_addr in; in.s_addr = htonl(ip); return mir_a2t( inet_ntoa(in)); } case CCNF_GROUP: if ((res = db_get_tsa(hContact, "CList", "Group")) != NULL) return res; break; case CNF_UNIQUEID: //UID for ChatRoom if (db_get_b(hContact, szProto, "ChatRoom", 0) == 1) if ((res = db_get_tsa(hContact, szProto, "ChatRoomID")) != NULL) return res; //UID for other contact break; } CONTACTINFO ci = { sizeof(ci) }; ci.hContact = hContact; ci.dwFlag = type | CNF_UNICODE; CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci); memset(szVal, '\0', sizeof(szVal)); switch(ci.type) { case CNFT_BYTE: if (type == CNF_GENDER) { szVal[0] = (char)ci.bVal; szVal[1] = 0; return mir_a2t(szVal); } return itot(ci.bVal); case CNFT_WORD: return itot(ci.wVal); case CNFT_DWORD: return itot(ci.dVal); case CNFT_ASCIIZ: return ci.pszVal; } return NULL; }
static TCHAR *parseRand(ARGUMENTSINFO *ai) { return itot(rand()); }