Mercurial > otakunoraifu
diff system/system_config.cc @ 52:15a18fbe6f21
* Known bugs added to the README
* Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author | thib |
---|---|
date | Sat, 18 Apr 2009 18:35:39 +0000 |
parents | 35ce1a30f3f9 |
children | ddbcbd000206 |
line wrap: on
line diff
--- a/system/system_config.cc +++ b/system/system_config.cc @@ -71,8 +71,10 @@ public: } }; HashStr::HashStr(const char* s ) { - if (s == 0 || s[0] == '\0') { - str = 0; hash = 0; return; /* invalid string */ + if (s == NULL || s[0] == '\0') { + str = NULL; + hash = 0; + return; /* invalid string */ } char* new_str = new char[strlen(s)+1]; strcpy(new_str, s); @@ -86,8 +88,9 @@ HashStr::HashStr(const char* s ) { hash = (unsigned int)h; } HashStr::HashStr(const HashStr& orig) { - if (orig.str == 0 || orig.str[0] == '\0') { - str = 0; hash = 0; return; /* invalid */ + if (orig.str == NULL || orig.str[0] == '\0') { + str = NULL; + hash = 0; return; /* invalid */ } char* new_str = new char[strlen(orig.str)+1]; strcpy(new_str, orig.str); @@ -130,9 +133,9 @@ class AyuSysConfigStringItem { char* new_data; public: AyuSysConfigStringItem(void) { - original_data = 0; - old_data = 0; - new_data = 0; + original_data = NULL; + old_data = NULL; + new_data = NULL; } ~AyuSysConfigStringItem(void) { if (original_data) delete[] original_data; @@ -140,7 +143,9 @@ public: if (new_data) delete[] new_data; } AyuSysConfigStringItem(const AyuSysConfigStringItem& o) { - original_data = 0; old_data = 0; new_data = 0; + original_data = NULL; + old_data = NULL; + new_data = NULL; if (o.original_data) { original_data = new char[strlen(o.original_data)+1]; strcpy(original_data, o.original_data); @@ -185,11 +190,11 @@ public: ** 変化を反映 */ int DiffOriginalLen(void) { - if (new_data == 0) return 0; + if (new_data == NULL) return 0; return strlen(new_data)+1; } void DiffOriginal(string& data) { - if (new_data == 0) { /* あり得ない */ + if (new_data == NULL) { /* あり得ない */ fprintf(stderr,"AyuSysConfigStringItem::DiffOriginal : this method must not called if not required!\n"); return; } @@ -218,9 +223,9 @@ public: } const char* PatchOriginal(const char* data) { static const char* table = "?\"',.:;=<>"; - if (new_data) delete[] new_data; - if (old_data) delete[] old_data; - new_data = 0; old_data = 0; + if (new_data != NULL) delete[] new_data; + if (old_data != NULL) delete[] old_data; + old_data = NULL; new_data = new char[1024]; int i,j = 0; for (i=0; i<1020; i++) { @@ -244,7 +249,8 @@ public: void SetOriginal(void) { if (new_data) delete[] new_data; if (old_data) delete[] old_data; - new_data = 0; old_data = 0; + new_data = NULL; + old_data = NULL; } void Dump(FILE* f) const { if (original_data) fprintf(f, "original %s ",original_data); @@ -266,9 +272,9 @@ class AyuSysConfigIntlistItem { public: AyuSysConfigIntlistItem(void) { item_deal = 0; - original_data = 0; - old_data = 0; - new_data = 0; + original_data = NULL; + old_data = NULL; + new_data = NULL; } ~AyuSysConfigIntlistItem(void) { if (original_data) delete[] original_data; @@ -277,7 +283,9 @@ public: } AyuSysConfigIntlistItem(const AyuSysConfigIntlistItem& o) { item_deal = o.item_deal; - original_data = 0; old_data = 0; new_data = 0; + original_data = NULL; + old_data = NULL; + new_data = NULL; if (o.original_data) { original_data = new int[item_deal]; memcpy(original_data, o.original_data, sizeof(int)*item_deal); @@ -294,7 +302,7 @@ public: /* 設定:Init で初期化、Set で変更、Get で変更を優先して取り出す */ void Init(int deal, const int* list) { /* deal は無視 */ if (original_data) delete[] original_data; - original_data = 0; + original_data = NULL; if (deal <= 0) { item_deal = 0; return; } @@ -309,20 +317,20 @@ public: memcpy(new_data, list, sizeof(int)*item_deal); } const int* Get(int deal) const {/* deal は無視 */ - if (item_deal == 0) return 0; + if (item_deal == 0) return NULL; if (deal > item_deal) { fprintf(stderr,"AyuSysConfigIntlistItem::Get : invalid items deal %d (correct: %d)\n",deal,item_deal); - return 0; + return NULL; } if (new_data) return new_data; else if (old_data) return old_data; return original_data; } const int* GetOriginal(int deal) const {/* deal は無視 */ - if (item_deal == 0) return 0; + if (item_deal == 0) return NULL; if (deal > item_deal) { fprintf(stderr,"AyuSysConfigIntlistItem::Get : invalid items deal %d (correct: %d)\n",deal,item_deal); - return 0; + return NULL; } return original_data; } @@ -334,11 +342,11 @@ public: ** 変化を反映 */ int DiffOriginalLen(void) { - if (new_data == 0) return 0; + if (new_data == NULL) return 0; return 12 * item_deal + 1; } void DiffOriginal(string& data) { - if (new_data == 0) { /* あり得ない */ + if (new_data == NULL) { /* あり得ない */ fprintf(stderr,"AyuSysConfigStringItem::DiffOriginal : this method must not called if not required!\n"); return; } @@ -352,12 +360,12 @@ public: const char* PatchOriginal(const char* data) { if (old_data) delete[] old_data; if (new_data) delete[] new_data; - old_data = 0; new_data = 0; + old_data = NULL; new_data = new int[item_deal]; int i; for (i=0; i<item_deal; i++) { new_data[i] = atoi(data); - if (strchr(data, ',') == 0) break; + if (strchr(data, ',') == NULL) break; data = strchr(data, ',') + 1; } return data; @@ -365,7 +373,8 @@ public: void SetOriginal(void) { if (new_data) delete[] new_data; if (old_data) delete[] old_data; - new_data = 0; old_data = 0; + new_data = NULL; + old_data = NULL; } void Dump(FILE* f) const { fprintf(f, "item deal %d, ",item_deal); @@ -410,11 +419,11 @@ template<class ItemType, class DataType> maptype data; public: void SetOrig(HashStr& name, int deal, const DataType* str) { - if (str == 0) return; /* 無効 */ + if (str == NULL) return; /* 無効 */ data[name].Init(deal, str); } void Set(HashStr& name, int deal, const DataType* new_data) { - if (new_data == 0) return; /* 無効 */ + if (new_data == NULL) return; /* 無効 */ /* 設定を検索 */ mapiterator it = data.find(name); /* 設定が元設定に見つからないなら失敗 */ @@ -428,17 +437,17 @@ public: /* 新しい設定を優先して返す */ const DataType* Get(int deal, HashStr& name) const { const_mapiterator it = data.find(name); - if (it == data.end()) return 0; + if (it == data.end()) return NULL; return it->second.Get(deal); } const DataType* GetOriginal(int deal, HashStr& name) const { const_mapiterator it = data.find(name); - if (it == data.end()) return 0; + if (it == data.end()) return NULL; return it->second.GetOriginal(deal); } int Deal(HashStr& name) const { const_mapiterator it = data.find(name); - if (it == data.end()) return 0; + if (it == data.end()) return NULL; return it->second.Deal(); } /* オリジナルからの変化の調査 : @@ -463,7 +472,7 @@ public: while(*diff_data != ';') { char name[1024]; const char* data_start = strchr(diff_data, '='); - if (data_start == 0) break; + if (data_start == NULL) break; strncpy(name, diff_data, data_start-diff_data); name[data_start-diff_data] = 0; data_start++; @@ -527,7 +536,7 @@ int AyuSysConfig::SearchParam(const char strncpy(name_copy, name, 1000); name_copy[1000] = 0; char* s; - for (s=name_copy; s != 0; s = strchr(s,'.')) { + for (s=name_copy; s != NULL; s = strchr(s,'.')) { if (isdigit(s[1]) && isdigit(s[2]) && isdigit(s[3])) { s[1] = '0'; s[2] = '0'; s[3] = '0'; } @@ -541,7 +550,7 @@ int AyuSysConfig::SearchParam(const char const char* AyuSysConfig::GetParaStr(const char* name) const{ HashStr str(name); const char* ret = str_config->orig.Get(1,str); - if (ret == 0) { + if (ret == NULL) { // fprintf(stderr,"Cannot find config name '%s'\n",name); } return ret; @@ -550,7 +559,7 @@ int AyuSysConfig::GetParam(const char* n HashStr str(name); va_list va; int i; const int* vars = int_config->orig.Get(deal, str); - if (vars == 0) { + if (vars == NULL) { // fprintf(stderr,"Cannot find config name '%s'\n",name); va_start(va, deal); for (i=0; i<deal; i++) { @@ -573,7 +582,7 @@ int AyuSysConfig::GetOriginalParam(const HashStr str(name); va_list va; int i; const int* vars = int_config->orig.GetOriginal(deal, str); - if (vars == 0) { + if (vars == NULL) { // fprintf(stderr,"Cannot find config name '%s'\n",name); va_start(va, deal); for (i=0; i<deal; i++) { @@ -594,10 +603,16 @@ int AyuSysConfig::GetOriginalParam(const } const int* AyuSysConfig::GetParamArray(const char* name, int& deal) const{ HashStr str(name); - if (int_config->orig.Deal(str) == 0) { deal = 0; return 0; } + if (int_config->orig.Deal(str) == 0) { + deal = 0; + return NULL; + } deal = int_config->orig.Deal(str); const int* vars = int_config->orig.Get(deal, str); - if (vars == 0) { deal = 0; return 0; } + if (vars == NULL) { + deal = 0; + return NULL; + } return vars; } void AyuSysConfig::SetParaStr(const char* name, const char* var) { @@ -882,7 +897,7 @@ bool AyuSysConfig::LoadInitFile(void) if (info == NULL) return false; int size = info->Size(); unsigned char* buf_orig = (unsigned char*)info->Read(); - if (size <= 0 || buf_orig == 0) { + if (size <= 0 || buf_orig == NULL) { delete info; return false; } unsigned char* buf_end = buf_orig + size; @@ -907,7 +922,9 @@ bool AyuSysConfig::LoadInitFile(void) continue; } /* 初期化 */ - token_deal = 1; tokens[0] = buf; buf_ptr = 0; + token_deal = 1; + tokens[0] = buf; + buf_ptr = NULL; int in_quote = 0; while(buf_orig < buf_end && buf_ptr < 1023) { @@ -930,7 +947,8 @@ bool AyuSysConfig::LoadInitFile(void) if (c == '\n' || c == '\r') break; /* = なら次の token */ if (c == '=') { - c = 0; tokens[token_deal++] = buf+buf_ptr+1; + c = 0; + tokens[token_deal++] = buf+buf_ptr+1; if (token_deal >= MAXTOKEN) break; } else if (c == '\"') { in_quote = 1; buf_orig++; continue; @@ -1069,7 +1087,7 @@ bool AyuSysConfig::LoadInitFile(void) /* 第二トークンの3つめのパラメータを得る(繰り返しの時の再生開始位置) */ int start_pt = 0; const char* tk1 = strchr(tokens[1], '-'); - const char* tk2 = 0; + const char* tk2 = NULL; if (tk1 && *tk1) tk2 = strchr(tk1+1, '-'); if (tk2 && *tk2) start_pt = atoi(tk2+1); if (token_deal == 3) { @@ -1224,15 +1242,15 @@ const char* TrackName::WaveTrack(char* n for (i=0; name[i]!=0; i++) buf[i]=tolower(name[i]); buf[i]=0; for (i=0; i<deal; i++) { - if (track[i] == 0) return 0; + if (track[i] == 0) return NULL; if (strcmp(track[i], buf) == 0) { return track_wave[i]; } } - return 0; + return NULL; } const char* TrackName::SETrack(int n) { - if (n < 0 || n >= se_deal) return 0; + if (n < 0 || n >= se_deal) return NULL; return se_track[n]; } void TrackName::AddSE(int n, char* file) {