function_name
stringlengths
1
80
function
stringlengths
14
10.6k
comment
stringlengths
12
8.02k
normalized_comment
stringlengths
6
6.55k
CfgAddInt64
ITEM *CfgAddInt64(FOLDER *f, char *name, UINT64 i) { // Validate arguments if (f == NULL || name == NULL) { return NULL; } return CfgCreateItem(f, name, ITEM_TYPE_INT64, &i, sizeof(UINT64)); }
/* Add a 64-bit integer type*/
Add a 64-bit integer type
CfgGetIp
bool CfgGetIp(FOLDER *f, char *name, struct IP *ip) { char tmp[MAX_SIZE]; // Validate arguments if (f == NULL || name == NULL || ip == NULL) { return false; } Zero(ip, sizeof(IP)); if (CfgGetStr(f, name, tmp, sizeof(tmp)) == false) { return false; } if (StrToIP(ip, tmp) == false) { return false; } return true; }
/* Get an IP address type*/
Get an IP address type
CfgAddIp
ITEM *CfgAddIp(FOLDER *f, char *name, struct IP *ip) { char tmp[MAX_SIZE]; // Validate arguments if (f == NULL || name == NULL || ip == NULL) { return NULL; } IPToStr(tmp, sizeof(tmp), ip); return CfgAddStr(f, name, tmp); }
/* Add an IP address type*/
Add an IP address type
CfgAddInt
ITEM *CfgAddInt(FOLDER *f, char *name, UINT i) { // Validate arguments if (f == NULL || name == NULL) { return NULL; } return CfgCreateItem(f, name, ITEM_TYPE_INT, &i, sizeof(UINT)); }
/* Add an integer type*/
Add an integer type
CfgAddBool
ITEM *CfgAddBool(FOLDER *f, char *name, bool b) { // Validate arguments if (f == NULL || name == NULL) { return NULL; } return CfgCreateItem(f, name, ITEM_TYPE_BOOL, &b, sizeof(bool)); }
/* Adding a bool type*/
Adding a bool type
CmpItemName
int CmpItemName(void *p1, void *p2) { ITEM *f1, *f2; if (p1 == NULL || p2 == NULL) { return 0; } f1 = *(ITEM **)p1; f2 = *(ITEM **)p2; if (f1 == NULL || f2 == NULL) { return 0; } return StrCmpi(f1->Name, f2->Name); }
/* Comparison function of the item names*/
Comparison function of the item names
CmpFolderName
int CmpFolderName(void *p1, void *p2) { FOLDER *f1, *f2; if (p1 == NULL || p2 == NULL) { return 0; } f1 = *(FOLDER **)p1; f2 = *(FOLDER **)p2; if (f1 == NULL || f2 == NULL) { return 0; } return StrCmpi(f1->Name, f2->Name); }
/* Comparison function of the folder names*/
Comparison function of the folder names
CfgEnumItem
void CfgEnumItem(FOLDER *f, ENUM_ITEM proc, void *param) { UINT i; // Validate arguments if (f == NULL || proc == NULL) { return; } for (i = 0;i < LIST_NUM(f->Items);i++) { ITEM *tt = LIST_DATA(f->Items, i); if (proc(tt, param) == false) { break; } } }
/* Enumeration of items*/
Enumeration of items
CfgEnumFolderToTokenList
TOKEN_LIST *CfgEnumFolderToTokenList(FOLDER *f) { TOKEN_LIST *t, *ret; UINT i; // Validate arguments if (f == NULL) { return NULL; } t = ZeroMalloc(sizeof(TOKEN_LIST)); t->NumTokens = LIST_NUM(f->Folders); t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens); for (i = 0;i < t->NumTokens;i++) { FOLDER *ff = LIST_DATA(f->Folders, i); t->Token[i] = CopyStr(ff->Name); } ret = UniqueToken(t); FreeToken(t); return ret; }
/* Enumerate the folders and store it in the token list*/
Enumerate the folders and store it in the token list
CfgEnumItemToTokenList
TOKEN_LIST *CfgEnumItemToTokenList(FOLDER *f) { TOKEN_LIST *t, *ret; UINT i; // Validate arguments if (f == NULL) { return NULL; } t = ZeroMalloc(sizeof(TOKEN_LIST)); t->NumTokens = LIST_NUM(f->Items); t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens); for (i = 0;i < t->NumTokens;i++) { FOLDER *ff = LIST_DATA(f->Items, i); t->Token[i] = CopyStr(ff->Name); } ret = UniqueToken(t); FreeToken(t); return ret; }
/* Enumerate items and store these to the token list*/
Enumerate items and store these to the token list
CfgDeleteItem
void CfgDeleteItem(ITEM *t) { // Validate arguments if (t == NULL) { return; } // Remove from the parent list Delete(t->Parent->Items, t); // Memory release Free(t->Buf); Free(t->Name); Free(t); }
/* Delete the item*/
Delete the item
CfgCreateRoot
FOLDER *CfgCreateRoot() { return CfgCreateFolder(NULL, TAG_ROOT); }
/* Creating a root*/
Creating a root
SetStrCaseAccordingToBits
void SetStrCaseAccordingToBits(char *str, UINT bits) { UINT i, len; // Validate arguments if (str == NULL) { return; } len = StrLen(str); for (i = 0;i < len;i++) { char c = str[i]; if (bits & 0x01) { c = ToUpper(c); } else { c = ToLower(c); } str[i] = c; bits = bits / 2; } }
/* Change the case of the string by the bit array*/
Change the case of the string by the bit array
NormalizeIntListStr
void NormalizeIntListStr(char *dst, UINT dst_size, char *src, bool sorted, char *separate_str) { LIST *o; o = StrToIntList(src, sorted); IntListToStr(dst, dst_size, o, separate_str); ReleaseIntList(o); }
/* Normalize the integer list string*/
Normalize the integer list string
StrToIntList
LIST *StrToIntList(char *str, bool sorted) { LIST *o; TOKEN_LIST *t; o = NewIntList(sorted); t = ParseTokenWithoutNullStr(str, " ,/;\t"); if (t != NULL) { UINT i; for (i = 0;i < t->NumTokens;i++) { char *s = t->Token[i]; if (IsEmptyStr(s) == false) { if (IsNum(s)) { InsertIntDistinct(o, ToInt(s)); } } } FreeToken(t); } return o; }
/* Convert the string to an integer list*/
Convert the string to an integer list
IntListToStr
void IntListToStr(char *str, UINT str_size, LIST *o, char *separate_str) { UINT i; ClearStr(str, str_size); // Validate arguments if (o == NULL) { return; } if (IsEmptyStr(separate_str)) { separate_str = ", "; } for (i = 0;i < LIST_NUM(o);i++) { char tmp[MAX_SIZE]; UINT *v = LIST_DATA(o, i); ToStr(tmp, *v); StrCat(str, str_size, tmp); if (i != (LIST_NUM(o) - 1)) { StrCat(str, str_size, separate_str); } } }
/* Convert an integer list to a string*/
Convert an integer list to a string
ClearStr
void ClearStr(char *str, UINT str_size) { StrCpy(str, str_size, ""); }
/* Initialize the string*/
Initialize the string
SearchAsciiInBinary
UINT SearchAsciiInBinary(void *data, UINT size, char *str, bool case_sensitive) { UINT ret = INFINITE; char *tmp; // Validate arguments if (data == NULL || size == 0 || str == NULL) { return INFINITE; } tmp = ZeroMalloc(size + 1); Copy(tmp, data, size); ret = SearchStrEx(tmp, str, 0, case_sensitive); Free(tmp); return ret; }
/* Search for the ASCII string in the binary data sequence*/
Search for the ASCII string in the binary data sequence
FourBitToHex
char FourBitToHex(UINT value) { value = value % 16; if (value <= 9) { return '0' + value; } else { return 'a' + (value - 10); } }
/* Converts a 4 bit value to hexadecimal string*/
Converts a 4 bit value to hexadecimal string
HexTo4Bit
UINT HexTo4Bit(char c) { if ('0' <= c && c <= '9') { return c - '0'; } else if ('a' <= c && c <= 'f') { return c - 'a' + 10; } else if ('A' <= c && c <= 'F') { return c - 'A' + 10; } else { return 0; } }
/* Convert a hexadecimal string to a 4 bit integer*/
Convert a hexadecimal string to a 4 bit integer
DefaultTokenSplitChars
char *DefaultTokenSplitChars() { return " ,\t\r\n"; }
/* Get a standard token delimiter*/
Get a standard token delimiter
IsCharInStr
bool IsCharInStr(char *str, char c) { UINT i, len; // Validate arguments if (str == NULL) { return false; } len = StrLen(str); for (i = 0;i < len;i++) { if (str[i] == c) { return true; } } return false; }
/* Check whether the specified character is in the string*/
Check whether the specified character is in the string
InStrList
bool InStrList(char *target_str, char *tokens, char *splitter, bool case_sensitive) { TOKEN_LIST *t; bool ret = false; UINT i; // Validate arguments if (target_str == NULL || tokens == NULL || splitter == NULL) { return false; } t = ParseTokenWithoutNullStr(tokens, splitter); if (t != NULL) { for (i = 0;i < t->NumTokens;i++) { if (InStrEx(target_str, t->Token[i], case_sensitive)) { ret = true; // printf("%s\n", t->Token[i]); } if (ret) { break; } } FreeToken(t); } return ret; }
/* Check whether the string contains at least one of the specified tokens*/
Check whether the string contains at least one of the specified tokens
InStr
bool InStr(char *str, char *keyword) { return InStrEx(str, keyword, false); }
/* Check whether the string is included*/
Check whether the string is included
IniIntValue
UINT IniIntValue(LIST *o, char *key) { INI_ENTRY *e; // Validate arguments if (o == NULL || key == NULL) { return 0; } e = GetIniEntry(o, key); if (e == NULL) { return 0; } return ToInt(e->Value); }
/* Get a value from the INI*/
Get a value from the INI
FreeIni
void FreeIni(LIST *o) { UINT i; // Validate arguments if (o == NULL) { return; } for (i = 0;i < LIST_NUM(o);i++) { INI_ENTRY *e = LIST_DATA(o, i); Free(e->Key); Free(e->Value); Free(e->UnicodeValue); Free(e); } ReleaseList(o); }
/* Release the INI*/
Release the INI
GetIniEntry
INI_ENTRY *GetIniEntry(LIST *o, char *key) { UINT i; // Validate arguments if (o == NULL || key == NULL) { return NULL; } for (i = 0;i < LIST_NUM(o);i++) { INI_ENTRY *e = LIST_DATA(o, i); if (StrCmpi(e->Key, key) == 0) { return e; } } return NULL; }
/* Get an entry in the INI file*/
Get an entry in the INI file
IsSplitChar
bool IsSplitChar(char c, char *split_str) { UINT i, len; char c_upper = ToUpper(c); if (split_str == NULL) { split_str = default_spliter; } len = StrLen(split_str); for (i = 0;i < len;i++) { if (ToUpper(split_str[i]) == c_upper) { return true; } } return false; }
/* Check whether the specified character is a delimiter*/
Check whether the specified character is a delimiter
MakeCharArray
char *MakeCharArray(char c, UINT count) { UINT i; char *ret = Malloc(count + 1); for (i = 0;i < count;i++) { ret[i] = c; } ret[count] = 0; return ret; }
/* Generate a sequence of specified character*/
Generate a sequence of specified character
StrWidth
UINT StrWidth(char *str) { wchar_t *s; UINT ret; // Validate arguments if (str == NULL) { return 0; } s = CopyStrToUni(str); ret = UniStrWidth(s); Free(s); return ret; }
/* Get the width of the specified string*/
Get the width of the specified string
IsAllUpperStr
bool IsAllUpperStr(char *str) { UINT i, len; // Validate arguments if (str == NULL) { return false; } len = StrLen(str); for (i = 0;i < len;i++) { char c = str[i]; if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')) { } else { return false; } } return true; }
/* Check whether the specified string is all uppercase*/
Check whether the specified string is all uppercase
MacToStr
void MacToStr(char *str, UINT size, UCHAR *mac_address) { // Validate arguments if (str == NULL || mac_address == NULL) { return; } Format(str, size, "%02X-%02X-%02X-%02X-%02X-%02X", mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5]); }
/* Convert the MAC address to a string*/
Convert the MAC address to a string
IsEmptyStr
bool IsEmptyStr(char *str) { char *s; // Validate arguments if (str == NULL) { return true; } s = CopyStr(str); Trim(s); if (StrLen(s) == 0) { Free(s); return true; } else { Free(s); return false; } }
/* Examine whether the string is empty*/
Examine whether the string is empty
ListToTokenList
TOKEN_LIST *ListToTokenList(LIST *o) { UINT i; TOKEN_LIST *t; // Validate arguments if (o == NULL) { return NULL; } t = ZeroMalloc(sizeof(TOKEN_LIST)); t->NumTokens = LIST_NUM(o); t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens); for (i = 0;i < LIST_NUM(o);i++) { t->Token[i] = CopyStr(LIST_DATA(o, i)); } return t; }
/* Convert a string list to a token list*/
Convert a string list to a token list
FreeStrList
void FreeStrList(LIST *o) { UINT i; // Validate arguments if (o == NULL) { return; } for (i = 0;i < LIST_NUM(o);i++) { char *s = LIST_DATA(o, i); Free(s); } ReleaseList(o); }
/* Free the string list*/
Free the string list
StrToStrList
LIST *StrToStrList(char *str, UINT size) { LIST *o; char *tmp; UINT tmp_size; UINT i; // Validate arguments if (str == NULL) { return NULL; } o = NewListFast(NULL); i = 0; while (true) { if (i >= size) { break; } if (*str == 0) { break; } tmp_size = StrSize(str); tmp = ZeroMalloc(tmp_size); StrCpy(tmp, tmp_size, str); Add(o, tmp); str += StrLen(str) + 1; i++; } return o; }
/* Convert a (NULL delimited) string to a list*/
Convert a (NULL delimited) string to a list
NullToken
TOKEN_LIST *NullToken() { TOKEN_LIST *ret = ZeroMalloc(sizeof(TOKEN_LIST)); ret->Token = ZeroMalloc(0); return ret; }
/* Empty token list*/
Empty token list
CopyToken
TOKEN_LIST *CopyToken(TOKEN_LIST *src) { TOKEN_LIST *ret; UINT i; // Validate arguments if (src == NULL) { return NULL; } ret = ZeroMalloc(sizeof(TOKEN_LIST)); ret->NumTokens = src->NumTokens; ret->Token = ZeroMalloc(sizeof(char *) * ret->NumTokens); for (i = 0;i < ret->NumTokens;i++) { ret->Token[i] = CopyStr(src->Token[i]); } return ret; }
/* Copy the token list*/
Copy the token list
ToInt64
UINT64 ToInt64(char *str) { UINT len, i; UINT64 ret = 0; // Validate arguments if (str == NULL) { return 0; } len = StrLen(str); for (i = 0;i < len;i++) { char c = str[i]; if (c != ',') { if ('0' <= c && c <= '9') { ret = ret * (UINT64)10 + (UINT64)(c - '0'); } else { break; } } } return ret; }
/* Convert a string to a 64-bit integer*/
Convert a string to a 64-bit integer
EndWith
bool EndWith(char *str, char *key) { UINT str_len; UINT key_len; // Validate arguments if (str == NULL || key == NULL) { return false; } // Comparison str_len = StrLen(str); key_len = StrLen(key); if (str_len < key_len) { return false; } if (StrCmpi(str + (str_len - key_len), key) == 0) { return true; } else { return false; } }
/* Check whether the str ends with the key*/
Check whether the str ends with the key
StartWith
bool StartWith(char *str, char *key) { UINT str_len; UINT key_len; char *tmp; bool ret; // Validate arguments if (str == NULL || key == NULL) { return false; } // Comparison str_len = StrLen(str); key_len = StrLen(key); if (str_len < key_len) { return false; } if (str_len == 0 || key_len == 0) { return false; } tmp = CopyStr(str); tmp[key_len] = 0; if (StrCmpi(tmp, key) == 0) { ret = true; } else { ret = false; } Free(tmp); return ret; }
/* Check whether the str starts with the key*/
Check whether the str starts with the key
PrintBin
void PrintBin(void *data, UINT size) { char *tmp; UINT i; // Validate arguments if (data == NULL) { return; } i = size * 3 + 1; tmp = Malloc(i); BinToStrEx(tmp, i, data, size); Print("%s\n", tmp); Free(tmp); }
/* Display the binary data*/
Display the binary data
StrToMac
bool StrToMac(UCHAR *mac_address, char *str) { BUF *b; // Validate arguments if (mac_address == NULL || str == NULL) { return false; } b = StrToBin(str); if (b == NULL) { return false; } if (b->Size != 6) { FreeBuf(b); return false; } Copy(mac_address, b->Buf, 6); FreeBuf(b); return true; }
/* Convert the string to a MAC address*/
Convert the string to a MAC address
BinToStrEx
void BinToStrEx(char *str, UINT str_size, void *data, UINT data_size) { char *tmp; UCHAR *buf = (UCHAR *)data; UINT size; UINT i; // Validate arguments if (str == NULL || data == NULL) { return; } // Calculation of size size = data_size * 3 + 1; // Memory allocation tmp = ZeroMalloc(size); // Conversion for (i = 0;i < data_size;i++) { Format(&tmp[i * 3], 0, "%02X ", buf[i]); } Trim(tmp); // Copy StrCpy(str, str_size, tmp); // Memory release Free(tmp); }
/* Convert the binary data to a hexadecimal string (with space)*/
Convert the binary data to a hexadecimal string (with space)
CopyBinToStrEx
char *CopyBinToStrEx(void *data, UINT data_size) { char *ret; UINT size; // Validate arguments if (data == NULL) { return NULL; } size = data_size * 3 + 1; ret = ZeroMalloc(size); BinToStrEx(ret, size, data, data_size); return ret; }
/* Convert the binary data to a string, and copy it*/
Convert the binary data to a string, and copy it
BinToStr
void BinToStr(char *str, UINT str_size, void *data, UINT data_size) { char *tmp; UCHAR *buf = (UCHAR *)data; UINT size; UINT i; // Validate arguments if (str == NULL || data == NULL) { if (str != NULL) { str[0] = 0; } return; } // Calculation of size size = data_size * 2 + 1; // Memory allocation tmp = ZeroMalloc(size); // Conversion for (i = 0;i < data_size;i++) { sprintf(&tmp[i * 2], "%02X", buf[i]); } // Copy StrCpy(str, str_size, tmp); // Memory release Free(tmp); }
/* Convert the binary data to a hexadecimal string*/
Convert the binary data to a hexadecimal string
Bit160ToStr
void Bit160ToStr(char *str, UCHAR *data) { // Validate arguments if (str == NULL || data == NULL) { return; } Format(str, 0, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19]); }
/* Convert a 160-bit sequence into a string*/
Convert a 160-bit sequence into a string
CopyStr
char *CopyStr(char *str) { UINT len; char *dst; // Validate arguments if (str == NULL) { return NULL; } len = StrLen(str); dst = Malloc(len + 1); StrCpy(dst, len + 1, str); return dst; }
/* Copy a string*/
Copy a string
IsSafeStr
bool IsSafeStr(char *str) { UINT i, len; // Validate arguments if (str == NULL) { return false; } len = StrLen(str); for (i = 0;i < len;i++) { if (IsSafeChar(str[i]) == false) { return false; } } if (str[0] == ' ') { return false; } if (len != 0) { if (str[len - 1] == ' ') { return false; } } return true; }
/* Check whether the string is safe*/
Check whether the string is safe
IsPrintableAsciiChar
bool IsPrintableAsciiChar(char c) { UCHAR uc = (UCHAR)c; if (uc <= 31) { return false; } if (uc >= 127) { return false; } return true; }
/* Check whether the character can be displayed*/
Check whether the character can be displayed
EnPrintableAsciiStr
void EnPrintableAsciiStr(char *str, char replace) { UINT i, len; // Validate arguments if (str == NULL) { return; } len = StrLen(str); for (i = 0;i < len;i++) { char c = str[i]; if (IsPrintableAsciiChar(c) == false) { str[i] = replace; } } }
/* Convert a string to a displayable string*/
Convert a string to a displayable string
IsSafeChar
bool IsSafeChar(char c) { UINT i, len; char *check_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789" " ()-_#%&."; len = StrLen(check_str); for (i = 0;i < len;i++) { if (c == check_str[i]) { return true; } } return false; }
/* Check whether the character is safe*/
Check whether the character is safe
TruncateCharFromStr
void TruncateCharFromStr(char *str, char replace) { char *src,*dst; if (str == NULL) { return; } src = dst = str; while(*src != '\0') { if(*src != replace) { *dst = *src; dst++; } src++; } *dst = *src; //BUF *b = NewBuf(); //UINT i, len; //char zero = 0; //len = StrLen(str); //for (i = 0;i < len;i++) //{ // char c = str[i]; // if (c != replace) // { // WriteBuf(b, &c, 1); // } //} //if (b->Size == 0) //{ // char c = '_'; // WriteBuf(b, &c, 1); //} //WriteBuf(b, &zero, 1); //StrCpy(str, 0, b->Buf); //FreeBuf(b); }
/* Remove the specified character from a string*/
Remove the specified character from a string
EnSafeStr
void EnSafeStr(char *str, char replace) { if (str == NULL) { return; } while(*str != '\0') { if(IsSafeChar(*str) == false) { *str = replace; } str++; } }
/* Replace the unsafe characters*/
Replace the unsafe characters
CheckStringLibrary
bool CheckStringLibrary() { wchar_t *compare_str = L"TEST_TEST_123_123456789012345"; char *teststr = "TEST"; wchar_t *testunistr = L"TEST"; wchar_t tmp[64]; UINT i1 = 123; UINT64 i2 = 123456789012345ULL; UniFormat(tmp, sizeof(tmp), L"%S_%s_%u_%I64u", teststr, testunistr, i1, i2); if (UniStrCmpi(tmp, compare_str) != 0) { return false; } return true; }
/* Operation check of string library*/
Operation check of string library
InitStringLibrary
void InitStringLibrary() { // Create a lock for token token_lock = NewLock(); // Initialization of the International Library InitInternational(); // Operation check if (CheckStringLibrary() == false) { #ifdef OS_WIN32 Alert("String Library Init Failed.\r\nPlease check your locale settings.", NULL); #else // OS_WIN32 Alert("String Library Init Failed.\r\nPlease check your locale settings and iconv() libraries.", NULL); #endif // OS_WIN32 exit(0); } }
/* Initialize the string library*/
Initialize the string library
FreeStringLibrary
void FreeStringLibrary() { // Release of the International Library FreeInternational(); // Release of the lock for token DeleteLock(token_lock); token_lock = NULL; }
/* Release of the string library*/
Release of the string library
ReplaceStri
UINT ReplaceStri(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword) { return ReplaceStrEx(dst, size, string, old_keyword, new_keyword, false); }
/* String replaceing (case insensitive)*/
String replaceing (case insensitive)
ReplaceStr
UINT ReplaceStr(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword) { return ReplaceStrEx(dst, size, string, old_keyword, new_keyword, true); }
/* String replaceing (case sensitive)*/
String replaceing (case sensitive)
SearchStr
UINT SearchStr(char *string, char *keyword, UINT start) { return SearchStrEx(string, keyword, start, true); }
/* Search for a string (distinguish between upper / lower case)*/
Search for a string (distinguish between upper / lower case)
IsInToken
bool IsInToken(TOKEN_LIST *t, char *str) { UINT i; // Validate arguments if (t == NULL || str == NULL) { return false; } for (i = 0;i < t->NumTokens;i++) { if (StrCmpi(t->Token[i], str) == 0) { return true; } } return false; }
/* Determine whether the specified character is in the token list*/
Determine whether the specified character is in the token list
FreeToken
void FreeToken(TOKEN_LIST *tokens) { UINT i; if (tokens == NULL) { return; } for (i = 0;i < tokens->NumTokens;i++) { if (tokens->Token[i] != 0) { Free(tokens->Token[i]); } } Free(tokens->Token); Free(tokens); }
/* Release of the token list*/
Release of the token list
GetLine
bool GetLine(char *str, UINT size) { bool ret; wchar_t *unistr; UINT unistr_size = (size + 1) * sizeof(wchar_t); unistr = Malloc(unistr_size); ret = UniGetLine(unistr, unistr_size); UniToStr(str, size, unistr); Free(unistr); return ret; }
/* Get a line from standard input*/
Get a line from standard input
TrimCrlf
void TrimCrlf(char *str) { UINT len; // Validate arguments if (str == NULL) { return; } len = StrLen(str); if (len == 0) { return; } if (str[len - 1] == '\n') { if (len >= 2 && str[len - 2] == '\r') { str[len - 2] = 0; } str[len - 1] = 0; } else if (str[len - 1] == '\r') { str[len - 1] = 0; } }
/* Remove '\r' and '\n' at the end*/
Remove ' ' and ' ' at the end
TrimQuotes
void TrimQuotes(char *str) { UINT len = 0; // Validate arguments if (str == NULL) { return; } len = StrLen(str); if (len == 0) { return; } if (str[len - 1] == '\"') { str[len - 1] = 0; } if (str[0] == '\"') { Move(str, str + 1, len); } }
/* Remove quotes at the beginning and at the end of the string*/
Remove quotes at the beginning and at the end of the string
Trim
void Trim(char *str) { // Validate arguments if (str == NULL) { return; } // Trim on the left side TrimLeft(str); // Trim on the right side TrimRight(str); }
/* Remove white spaces of the both side of the string*/
Remove white spaces of the both side of the string
ToStr
void ToStr(char *str, UINT i) { sprintf(str, "%u", i); }
/* Convert an integer to a string*/
Convert an integer to a string
ToInti
int ToInti(char *str) { // Validate arguments if (str == NULL) { return 0; } return (int)ToInt(str); }
/* Convert the string to a signed integer*/
Convert the string to a signed integer
ToBool
bool ToBool(char *str) { char tmp[MAX_SIZE]; // Validate arguments if (str == NULL) { return false; } StrCpy(tmp, sizeof(tmp), str); Trim(tmp); if (IsEmptyStr(tmp)) { return false; } if (ToInt(tmp) != 0) { return true; } if (StartWith("true", tmp)) { return true; } if (StartWith("yes", tmp)) { return true; } if (StartWith(tmp, "true")) { return true; } if (StartWith(tmp, "yes")) { return true; } return false; }
/* Convert a string to a Boolean value*/
Convert a string to a Boolean value
ToInt
UINT ToInt(char *str) { // Validate arguments if (str == NULL) { return 0; } // Ignore the octal literal while (true) { if (*str != '0') { break; } if ((*(str + 1) == 'x') || (*(str + 1) == 'X')) { break; } str++; } return (UINT)strtoul(str, NULL, 0); }
/* Convert a string to an integer*/
Convert a string to an integer
PrintStr
void PrintStr(char *str) { wchar_t *unistr = NULL; // Validate arguments if (str == NULL) { return; } #ifdef OS_UNIX fputs(str, stdout); #else // OS_UNIX unistr = CopyStrToUni(str); UniPrintStr(unistr); Free(unistr); #endif // OS_UNIX }
/* Display the string on the screen*/
Display the string on the screen
PrintArgs
void PrintArgs(char *fmt, va_list args) { wchar_t *ret; wchar_t *fmt_wchar; char *tmp; // Validate arguments if (fmt == NULL) { return; } fmt_wchar = CopyStrToUni(fmt); ret = InternalFormatArgs(fmt_wchar, args, true); tmp = CopyUniToStr(ret); PrintStr(tmp); Free(tmp); Free(ret); Free(fmt_wchar); }
/* Display a string with arguments*/
Display a string with arguments
Print
void Print(char *fmt, ...) { va_list args; if (fmt == NULL) { return; } va_start(args, fmt); PrintArgs(fmt, args); va_end(args); }
/* Display a string*/
Display a string
DebugArgs
void DebugArgs(char *fmt, va_list args) { // Validate arguments if (fmt == NULL) { return; } if (g_debug == false) { return; } PrintArgs(fmt, args); }
/* Display a debug string with arguments*/
Display a debug string with arguments
Debug
void Debug(char *fmt, ...) { va_list args; // Validate arguments if (fmt == NULL) { return; } if (g_debug == false) { return; } va_start(args, fmt); DebugArgs(fmt, args); va_end(args); }
/* Display a debug string*/
Display a debug string
Format
void Format(char *buf, UINT size, char *fmt, ...) { va_list args; // Validate arguments if (buf == NULL || fmt == NULL) { return; } va_start(args, fmt); FormatArgs(buf, size, fmt, args); va_end(args); }
/* Format the string*/
Format the string
FormatArgs
void FormatArgs(char *buf, UINT size, char *fmt, va_list args) { wchar_t *tag; wchar_t *ret; // Validate arguments if (buf == NULL || fmt == NULL) { return; } tag = CopyStrToUni(fmt); ret = InternalFormatArgs(tag, args, true); UniToStr(buf, size, ret); Free(ret); Free(tag); }
/* Format the string (argument list)*/
Format the string (argument list)
StrCmpi
int StrCmpi(char *str1, char *str2) { UINT i; // Validate arguments if (str1 == NULL && str2 == NULL) { return 0; } if (str1 == NULL) { return 1; } if (str2 == NULL) { return -1; } // String comparison i = 0; while (true) { char c1, c2; c1 = ToUpper(str1[i]); c2 = ToUpper(str2[i]); if (c1 > c2) { return 1; } else if (c1 < c2) { return -1; } if (str1[i] == 0 || str2[i] == 0) { return 0; } i++; } }
/* Compare the strings in case-insensitive mode*/
Compare the strings in case-insensitive mode
StrCmp
int StrCmp(char *str1, char *str2) { // Validate arguments if (str1 == NULL && str2 == NULL) { return 0; } if (str1 == NULL) { return 1; } if (str2 == NULL) { return -1; } return strcmp(str1, str2); }
/* Compare the string*/
Compare the string
StrLower
void StrLower(char *str) { UINT len, i; // Validate arguments if (str == NULL) { return; } len = StrLen(str); for (i = 0;i < len;i++) { str[i] = ToLower(str[i]); } }
/* Uncapitalize the string*/
Uncapitalize the string
StrUpper
void StrUpper(char *str) { UINT len, i; // Validate arguments if (str == NULL) { return; } len = StrLen(str); for (i = 0;i < len;i++) { str[i] = ToUpper(str[i]); } }
/* Capitalize the string*/
Capitalize the string
ToLower
char ToLower(char c) { if ('A' <= c && c <= 'Z') { c += 'z' - 'Z'; } return c; }
/* Uncapitalize a character*/
Uncapitalize a character
ToUpper
char ToUpper(char c) { if ('a' <= c && c <= 'z') { c += 'Z' - 'z'; } return c; }
/* Capitalize a character*/
Capitalize a character
StrCat
UINT StrCat(char *dst, UINT size, char *src) { UINT len1, len2, len_test; // Validate arguments if (dst == NULL || src == NULL) { return 0; } // KS KS_INC(KS_STRCAT_COUNT); if (size == 0) { // Ignore the length size = 0x7fffffff; } len1 = StrLen(dst); len2 = StrLen(src); len_test = len1 + len2 + 1; if (len_test > size) { if (len2 <= (len_test - size)) { return 0; } len2 -= len_test - size; } Copy(dst + len1, src, len2); dst[len1 + len2] = 0; return len1 + len2; }
/* Combine the string*/
Combine the string
StrCheckLen
bool StrCheckLen(char *str, UINT len) { UINT count = 0; UINT i; // Validate arguments if (str == NULL) { return false; } // KS KS_INC(KS_STRCHECK_COUNT); for (i = 0;;i++) { if (str[i] == '\0') { return true; } count++; if (count > len) { return false; } } }
/* Make sure that the string is within the specified length*/
Make sure that the string is within the specified length
StrSize
UINT StrSize(char *str) { // Validate arguments if (str == NULL) { return 0; } return StrLen(str) + 1; }
/* Get the memory size needed to store the string*/
Get the memory size needed to store the string
StrLen
UINT StrLen(char *str) { // Validate arguments if (str == NULL) { return 0; } // KS KS_INC(KS_STRLEN_COUNT); return (UINT)strlen(str); }
/* Get the length of the string*/
Get the length of the string
get_quoted_string
static char * get_quoted_string(char **string) { char *string_start = *string; UINT string_len = 0; UINT status = skip_quotes(string); if (status != JSON_RET_OK) { return NULL; } string_len = (UINT)(*string - string_start - 2); /* length without quotes */ return process_string(string_start + 1, string_len); }
/* Return processed contents of a string between quotes and skips passed argument to a matching quote. */
Return processed contents of a string between quotes and skips passed argument to a matching quote.
JsonGet
JSON_VALUE * JsonGet(JSON_OBJECT *object, char *name) { if (object == NULL || name == NULL) { return NULL; } return json_object_nget_value(object, name, StrLen(name)); }
/* JSON Object API */
JSON Object API
JsonArrayGet
JSON_VALUE * JsonArrayGet(JSON_ARRAY *array, UINT index) { if (array == NULL || index >= JsonArrayGetCount(array)) { return NULL; } return array->items[index]; }
/* JSON Array API */
JSON Array API
JsonValueGetType
UINT JsonValueGetType(JSON_VALUE *value) { return value ? value->type : JSON_TYPE_ERROR; }
/* JSON Value API */
JSON Value API
SystemTimeToJsonStr
void SystemTimeToJsonStr(char *dst, UINT size, SYSTEMTIME *t) { if (dst == NULL) { return; } if (t == NULL) { ClearStr(dst, size); } else { GetDateTimeStrRFC3339(dst, size, t, 0); } }
/* SYSTEMTIME to JSON string*/
SYSTEMTIME to JSON string
SystemTime64ToJsonStr
void SystemTime64ToJsonStr(char *dst, UINT size, UINT64 t) { SYSTEMTIME st; if (dst == NULL) { return; } if (t == 0) { ClearStr(dst, size); } UINT64ToSystem(&st, t); SystemTimeToJsonStr(dst, size, &st); }
/* UINT64 System Time to JSON string*/
UINT64 System Time to JSON string
OSGetMemInfo
void OSGetMemInfo(MEMINFO *info) { // Validate arguments if (info == NULL) { return; } os->GetMemInfo(info); }
/* Get the memory information*/
Get the memory information
OSNewSingleInstance
void *OSNewSingleInstance(char *instance_name) { return os->NewSingleInstance(instance_name); }
/* Start a Single instance*/
Start a Single instance
OSSetHighPriority
void OSSetHighPriority() { os->SetHighPriority(); }
/* Raise the priority*/
Raise the priority
OSRestorePriority
void OSRestorePriority() { os->RestorePriority(); }
/* Restore the priority*/
Restore the priority
OSGetProductId
char* OSGetProductId() { return os->GetProductId(); }
/* Get the product ID*/
Get the product ID
OSIsSupportedOs
bool OSIsSupportedOs() { return os->IsSupportedOs(); }
/* Check whether the OS is supported*/
Check whether the OS is supported
OSGetOsInfo
void OSGetOsInfo(OS_INFO *info) { os->GetOsInfo(info); }
/* Getting OS information*/
Getting OS information