BOOL boolean_isFalse(const char *value) { if (value == NULL) return FALSE; int len = strlen(value); if (len == 0) return FALSE; /* one character */ if (len == 1) { char tmp = tolower(value[0]); return tmp == 'f' || tmp == 'n' || tmp == '0'; } /* one word */ char *tmp = string_toLower(value); BOOL res = strcmp(tmp, "false") == 0 || strcmp(tmp, "no") == 0 || strcmp(tmp, "off") == 0; free(tmp); return res; }
BOOL boolean_isTrue(const char *value) { if (value == NULL) return FALSE; int len = strlen(value); if (len == 0) return FALSE; /* one character */ if (len == 1) { char tmp = tolower(value[0]); return tmp == 't' || tmp == 'y' || tmp == '1'; } /* one word */ char *tmp = string_toLower(value); BOOL res = strcmp(tmp, "true") == 0 || strcmp(tmp, "yes") == 0 || strcmp(tmp, "on") == 0; free(tmp); return res; }
bool ConfigFile::ReadBool( std::string sectionName,std::string entryName, bool defaultBool ) { std::string boolValue = string_toLower(_LRTrim(_ReadString(sectionName,entryName,"-"))); //没有适当的配置项 if(boolValue == "-") return defaultBool; //返回 true if(boolValue == "true" || boolValue == "y" || boolValue == "yes") return true; //返回false if(boolValue == "false" || boolValue == "n" || boolValue == "no") return false; return defaultBool; }
void initCommand(const char *str) { gCommand = COMMAND_ERROR; char *cmd; int idx = 0; /* pointer to remove "--" */ if (strlen(str) < 3) return; if (str[0] == '-' && str[1] == '-') idx += 2; cmd = string_toLower(str + idx); if (strcmp(cmd, "help") == 0) gCommand = COMMAND_HELP; else if (strcmp(cmd, "version") == 0) gCommand = COMMAND_VERSION; else if (strcmp(cmd, "install") == 0 || strcmp(cmd, "add") == 0) gCommand = COMMAND_INSTALL; else if (strcmp(cmd, "remove") == 0 || strcmp(cmd, "del") == 0) gCommand = COMMAND_REMOVE; else if (strcmp(cmd, "search") == 0) gCommand = COMMAND_SEARCH; else if (strcmp(cmd, "list") == 0) gCommand = COMMAND_LIST; else if (strcmp(cmd, "update") == 0) gCommand = COMMAND_UPDATE; else gCommand = COMMAND_ERROR; free(cmd); }
BOOL boolean_toBoolean(const char *value) { if (value == NULL) return FALSE; /* one character */ if (strlen(value) == 1) { return value[0] == 't' || value[0] == 'y' || value[0] == '1'; } /* one word */ char *tmp = string_toLower(value); BOOL res = strcmp(value, "true") == 0 || strcmp(value, "yes") == 0 || strcmp(value, "on") == 0; free (tmp); return res; }