• R/O
  • HTTP
  • SSH
  • HTTPS

CHNOSProject: Commit

CHNOSProjectのすべてのプロジェクトのソースのルート


Commit MetaInfo

Revisiónb9a126d23ac72b9f6cf365b584ba1bce3031997b (tree)
Tiempo2013-05-20 02:17:36
Autorhikarupsp <hikarupsp@user...>
Commiterhikarupsp

Log Message

データ保存関連を整備。

Cambiar Resumen

Diferencia incremental

--- a/CHNOSProject/AI003/AI003.xcodeproj/project.pbxproj
+++ b/CHNOSProject/AI003/AI003.xcodeproj/project.pbxproj
@@ -7,6 +7,9 @@
77 objects = {
88
99 /* Begin PBXBuildFile section */
10+ 170FE1E717493EFA0049FBBB /* memory.c in Sources */ = {isa = PBXBuildFile; fileRef = 170FE1E617493EFA0049FBBB /* memory.c */; };
11+ 170FE1EA17493FB10049FBBB /* wlfilter.c in Sources */ = {isa = PBXBuildFile; fileRef = 170FE1E917493FB10049FBBB /* wlfilter.c */; };
12+ 171C8B33174912D600E95F41 /* memory.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 171C8B3117490BAE00E95F41 /* memory.txt */; };
1013 17289436174406B600071834 /* AITestData_en.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 172894331744069100071834 /* AITestData_en.txt */; };
1114 17289437174406BB00071834 /* AITestData_ja.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 172894351744069800071834 /* AITestData_ja.txt */; };
1215 173BB42616C6600100126A00 /* config.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 173BB42316C65FBB00126A00 /* config.txt */; };
@@ -33,6 +36,7 @@
3336 dstPath = "";
3437 dstSubfolderSpec = 16;
3538 files = (
39+ 171C8B33174912D600E95F41 /* memory.txt in CopyFiles */,
3640 17289437174406BB00071834 /* AITestData_ja.txt in CopyFiles */,
3741 17289436174406B600071834 /* AITestData_en.txt in CopyFiles */,
3842 173BB42816C6618500126A00 /* words.txt in CopyFiles */,
@@ -53,6 +57,9 @@
5357 /* End PBXCopyFilesBuildPhase section */
5458
5559 /* Begin PBXFileReference section */
60+ 170FE1E617493EFA0049FBBB /* memory.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = memory.c; sourceTree = "<group>"; };
61+ 170FE1E917493FB10049FBBB /* wlfilter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = wlfilter.c; sourceTree = "<group>"; };
62+ 171C8B3117490BAE00E95F41 /* memory.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = memory.txt; path = ../memory.txt; sourceTree = "<group>"; };
5663 172894331744069100071834 /* AITestData_en.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = AITestData_en.txt; sourceTree = "<group>"; };
5764 172894351744069800071834 /* AITestData_ja.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = AITestData_ja.txt; sourceTree = "<group>"; };
5865 173BB42316C65FBB00126A00 /* config.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; lineEnding = 2; path = config.txt; sourceTree = "<group>"; };
@@ -98,6 +105,7 @@
98105 175A87A316B5827800F5166E /* AI003 */ = {
99106 isa = PBXGroup;
100107 children = (
108+ 171C8B3117490BAE00E95F41 /* memory.txt */,
101109 175A87A616B5827800F5166E /* AI003.1 */,
102110 173BB42316C65FBB00126A00 /* config.txt */,
103111 175A87AF16B5833500F5166E /* core.h */,
@@ -105,6 +113,8 @@
105113 173BB42716C660E000126A00 /* words.txt */,
106114 172894331744069100071834 /* AITestData_en.txt */,
107115 172894351744069800071834 /* AITestData_ja.txt */,
116+ 170FE1E617493EFA0049FBBB /* memory.c */,
117+ 170FE1E917493FB10049FBBB /* wlfilter.c */,
108118 );
109119 path = AI003;
110120 sourceTree = "<group>";
@@ -186,6 +196,8 @@
186196 buildActionMask = 2147483647;
187197 files = (
188198 175A87A516B5827800F5166E /* main.c in Sources */,
199+ 170FE1E717493EFA0049FBBB /* memory.c in Sources */,
200+ 170FE1EA17493FB10049FBBB /* wlfilter.c in Sources */,
189201 );
190202 runOnlyForDeploymentPostprocessing = 0;
191203 };
Binary files a/CHNOSProject/AI003/AI003.xcodeproj/project.xcworkspace/xcuserdata/hikaru.xcuserdatad/UserInterfaceState.xcuserstate and b/CHNOSProject/AI003/AI003.xcodeproj/project.xcworkspace/xcuserdata/hikaru.xcuserdatad/UserInterfaceState.xcuserstate differ
--- a/CHNOSProject/AI003/AI003.xcodeproj/xcuserdata/hikaru.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
+++ b/CHNOSProject/AI003/AI003.xcodeproj/xcuserdata/hikaru.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -85,19 +85,6 @@
8585 shouldBeEnabled = "No"
8686 ignoreCount = "0"
8787 continueAfterRunningActions = "No"
88- filePath = "AI003/main.c"
89- timestampString = "390602565.100723"
90- startingColumnNumber = "9223372036854775807"
91- endingColumnNumber = "9223372036854775807"
92- startingLineNumber = "280"
93- endingLineNumber = "280"
94- landmarkName = "AI_Memory_AddRootWordData()"
95- landmarkType = "7">
96- </FileBreakpoint>
97- <FileBreakpoint
98- shouldBeEnabled = "No"
99- ignoreCount = "0"
100- continueAfterRunningActions = "No"
10188 filePath = "AI003/chnlib.h"
10289 timestampString = "382105653.921843"
10390 startingColumnNumber = "9223372036854775807"
@@ -136,11 +123,11 @@
136123 ignoreCount = "0"
137124 continueAfterRunningActions = "No"
138125 filePath = "AI003/main.c"
139- timestampString = "390336991.21306"
126+ timestampString = "390676538.932936"
140127 startingColumnNumber = "9223372036854775807"
141128 endingColumnNumber = "9223372036854775807"
142- startingLineNumber = "58"
143- endingLineNumber = "58"
129+ startingLineNumber = "57"
130+ endingLineNumber = "57"
144131 landmarkName = "main()"
145132 landmarkType = "7">
146133 </FileBreakpoint>
@@ -175,11 +162,11 @@
175162 ignoreCount = "0"
176163 continueAfterRunningActions = "No"
177164 filePath = "AI003/main.c"
178- timestampString = "390602565.100723"
165+ timestampString = "390676538.932936"
179166 startingColumnNumber = "9223372036854775807"
180167 endingColumnNumber = "9223372036854775807"
181- startingLineNumber = "119"
182- endingLineNumber = "119"
168+ startingLineNumber = "145"
169+ endingLineNumber = "145"
183170 landmarkName = "AI_Think_LearnWordFromInputString()"
184171 landmarkType = "7">
185172 </FileBreakpoint>
@@ -188,11 +175,11 @@
188175 ignoreCount = "0"
189176 continueAfterRunningActions = "No"
190177 filePath = "AI003/main.c"
191- timestampString = "390602565.100723"
178+ timestampString = "390676538.932936"
192179 startingColumnNumber = "9223372036854775807"
193180 endingColumnNumber = "9223372036854775807"
194- startingLineNumber = "136"
195- endingLineNumber = "136"
181+ startingLineNumber = "161"
182+ endingLineNumber = "161"
196183 landmarkName = "AI_Think_LearnWordFromInputString()"
197184 landmarkType = "7">
198185 </FileBreakpoint>
@@ -201,11 +188,11 @@
201188 ignoreCount = "0"
202189 continueAfterRunningActions = "No"
203190 filePath = "AI003/main.c"
204- timestampString = "390602565.100723"
191+ timestampString = "390676538.932936"
205192 startingColumnNumber = "9223372036854775807"
206193 endingColumnNumber = "9223372036854775807"
207- startingLineNumber = "129"
208- endingLineNumber = "129"
194+ startingLineNumber = "154"
195+ endingLineNumber = "154"
209196 landmarkName = "AI_Think_LearnWordFromInputString()"
210197 landmarkType = "7">
211198 </FileBreakpoint>
@@ -214,11 +201,11 @@
214201 ignoreCount = "0"
215202 continueAfterRunningActions = "No"
216203 filePath = "AI003/main.c"
217- timestampString = "390602565.100723"
204+ timestampString = "390676538.932936"
218205 startingColumnNumber = "9223372036854775807"
219206 endingColumnNumber = "9223372036854775807"
220- startingLineNumber = "120"
221- endingLineNumber = "120"
207+ startingLineNumber = "146"
208+ endingLineNumber = "146"
222209 landmarkName = "AI_Think_LearnWordFromInputString()"
223210 landmarkType = "7">
224211 </FileBreakpoint>
@@ -227,11 +214,11 @@
227214 ignoreCount = "0"
228215 continueAfterRunningActions = "No"
229216 filePath = "AI003/main.c"
230- timestampString = "390602565.100723"
217+ timestampString = "390676538.932936"
231218 startingColumnNumber = "9223372036854775807"
232219 endingColumnNumber = "9223372036854775807"
233- startingLineNumber = "186"
234- endingLineNumber = "186"
220+ startingLineNumber = "211"
221+ endingLineNumber = "211"
235222 landmarkName = "AI_Think_SlideLookUpWordByHistory()"
236223 landmarkType = "7">
237224 </FileBreakpoint>
@@ -240,13 +227,39 @@
240227 ignoreCount = "0"
241228 continueAfterRunningActions = "No"
242229 filePath = "AI003/main.c"
243- timestampString = "390602565.100723"
230+ timestampString = "390676538.932936"
244231 startingColumnNumber = "9223372036854775807"
245232 endingColumnNumber = "9223372036854775807"
246- startingLineNumber = "192"
247- endingLineNumber = "192"
233+ startingLineNumber = "217"
234+ endingLineNumber = "217"
248235 landmarkName = "AI_Think_SlideLookUpWordByHistory()"
249236 landmarkType = "7">
250237 </FileBreakpoint>
238+ <FileBreakpoint
239+ shouldBeEnabled = "No"
240+ ignoreCount = "0"
241+ continueAfterRunningActions = "No"
242+ filePath = "../chn/chnlib04.c"
243+ timestampString = "390618368.792293"
244+ startingColumnNumber = "9223372036854775807"
245+ endingColumnNumber = "9223372036854775807"
246+ startingLineNumber = "226"
247+ endingLineNumber = "226"
248+ landmarkName = "CHNLIB_UTF8_GetByteSizeFromLengthByCharacter()"
249+ landmarkType = "7">
250+ </FileBreakpoint>
251+ <FileBreakpoint
252+ shouldBeEnabled = "Yes"
253+ ignoreCount = "0"
254+ continueAfterRunningActions = "No"
255+ filePath = "../chn/chnlib04.c"
256+ timestampString = "390618364.135592"
257+ startingColumnNumber = "9223372036854775807"
258+ endingColumnNumber = "9223372036854775807"
259+ startingLineNumber = "220"
260+ endingLineNumber = "220"
261+ landmarkName = "CHNLIB_UTF8_GetByteSizeFromLengthByCharacter()"
262+ landmarkType = "7">
263+ </FileBreakpoint>
251264 </FileBreakpoints>
252265 </Bucket>
--- a/CHNOSProject/AI003/AI003/config.txt
+++ b/CHNOSProject/AI003/AI003/config.txt
@@ -1 +1,2 @@
11 words.txt
2+memory.txt
\ No newline at end of file
--- a/CHNOSProject/AI003/AI003/core.h
+++ b/CHNOSProject/AI003/AI003/core.h
@@ -13,11 +13,21 @@
1313
1414 #define AI_CONFIG_FILE_NAME "config.txt"
1515 #define AI_INPUT_HISTORY_MAX 10
16+#define AI_EVENT_COUNT_0 10
17+
18+#define AI_SW_Delimiter_Colon 1
19+#define AI_SW_Delimiter_Comma 2
20+#define AI_SW_Delimiter_Plus 3
21+#define AI_SW_Bracket_Start 4
22+#define AI_SW_Bracket_End 5
1623
1724 typedef struct AI_WORKING_SET AI_WorkingSet;
1825 struct AI_WORKING_SET {
19- CHNLIB_UIPArray *SystemWordList0;
20- CHNLIB_UIPArray *RootWordList;
26+ CHNLIB_UIPArray *SystemWordList0; //データ解釈用区切り文字列を格納
27+ CHNLIB_UIPArray *SystemWordList1; //記憶単位のデータ種類を表す文字列を格納
28+ CHNLIB_UIPArray *SystemWordList2; //数字に使用する文字列を格納
29+ CHNLIB_UIPArray *RootWordList; //あらゆる文字列のStringを保持する。data32は単語カウント。
30+ CHNLIB_UIPArray *RootMemory; //記憶データを保持する。
2131 CHNLIB_UIPArray *InputHistory;
2232 };
2333
@@ -25,11 +35,22 @@ struct AI_WORKING_SET {
2535 extern AI_WorkingSet WorkingSet;
2636 void AI_Think_LearnWordFromInputString(CHNLIB_String *input);
2737 CHNLIB_UIPArray *AI_Think_SlideLookUpWordByHistory(CHNLIB_String *input);
28-int AI_Think_CandidateWordList_Filter00(CHNLIB_UIPArray **candidatewordlist);
29-int AI_Think_CandidateWordList_Filter01(CHNLIB_UIPArray **candidatewordlist, int length);
38+CHNLIB_UIPArray *AI_Think_WordList_GetSortedByLength(const CHNLIB_UIPArray *wordlist);
39+void AI_Think_WordList_SetLengthToData32(CHNLIB_UIPArray **wordlist);
40+void AI_System_InitializeSystemWorkingSet(void);
41+
42+//@memory.c
3043 int AI_Memory_AddRootWordData(CHNLIB_String *tag);
3144 int AI_Memory_AddRootWordData_IsDuplicated(const void *listtag, const void *newtag);
32-void AI_System_InitializeSystemWorkingSet(void);
45+int AI_Memory_AddRootMemoryData(CHNLIB_UIPArray *tag);
46+int AI_Memory_AddRootMemoryData_IsDuplicated(const void *listtag, const void *newtag);
3347 void AI_System_LoadMemory(const char configfilename[]);
48+void AI_System_SaveMemory_RootWordList(const char configfilename[]);
49+void AI_System_SaveMemory_RootMemory(const char memlistfilename[]);
50+
51+//@wlfilter.c
52+int AI_Think_CandidateWordList_Filter00(CHNLIB_UIPArray **candidatewordlist);
53+int AI_Think_CandidateWordList_Filter01(CHNLIB_UIPArray **candidatewordlist, int length);
54+int AI_Think_CandidateWordList_Filter02(CHNLIB_UIPArray **candidatewordlist, uint count);
3455
3556 #endif
--- a/CHNOSProject/AI003/AI003/main.c
+++ b/CHNOSProject/AI003/AI003/main.c
@@ -22,23 +22,22 @@ AI_WorkingSet WorkingSet;
2222 int main(int argc, const char * argv[])
2323 {
2424 //エントリポイント
25- int i, i_max;
25+ int i, i_max, j, count;
2626 CHNLIB_String *input, *temp;
2727 CHNLIB_UIPArray *separated, *sorted;
2828 int passthink;
29- FILE *readfp;
29+ FILE *readfp, *writefp;
3030
3131 CHNLIB_Environment_SetCurrentWorkingDirectory(argv[0]);
3232
33- CHNLIB_Debug("Hello, World.", CHNLIB_DEBUG_ARGUMENTS);
34-
3533 AI_System_InitializeSystemWorkingSet();
3634
3735 AI_System_LoadMemory(AI_CONFIG_FILE_NAME);
3836
3937 readfp = NULL;
38+ writefp = NULL;
4039
41- for(;;){
40+ for(count = 0; ; count++){
4241 passthink = False;
4342 if(readfp == NULL){
4443 input = CHNLIB_ReadLine(stdin);
@@ -64,26 +63,53 @@ int main(int argc, const char * argv[])
6463 } else if(CHNLIB_String_CompareStringWithCString(temp, "exit")){
6564 break;
6665 } else if(CHNLIB_String_CompareStringWithCString(temp, "wordlist")){
67- sorted = CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(WorkingSet.RootWordList);
66+ temp = CHNLIB_UIPArray_GetPointerByIndex(separated, 4);
67+ if(temp == NULL){
68+ //そのまま表示
69+ sorted = WorkingSet.RootWordList;
70+ retain(sorted);
71+ } else if(CHNLIB_String_CompareStringWithCString(temp, "count")){
72+ //回数カウント順
73+ sorted = CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(WorkingSet.RootWordList);
74+ } else if(CHNLIB_String_CompareStringWithCString(temp, "length")){
75+ //文字列長順
76+ sorted = AI_Think_WordList_GetSortedByLength(WorkingSet.RootWordList);
77+ } else{
78+ sorted = NULL;
79+ }
80+
6881 i_max = CHNLIB_UIPArray_GetNumberOfDatas(sorted);
82+ j = 0;
6983 for(i = 0; i < i_max; i++){
7084 printf("word%3d:%3d:%s\n", i, CHNLIB_UIPArray_GetData32ByIndex(sorted, i), CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(sorted, i)));
85+ j += CHNLIB_UIPArray_GetData32ByIndex(sorted, i);
86+ }
87+ if(i > 0){
88+ printf("Average:%d\n", j / i);
7189 }
7290 //CHNLIB_UIPArray_FreeOnlyArray(&sorted);
7391 release(sorted);
92+ } else if(CHNLIB_String_CompareStringWithCString(temp, "memlist")){
93+ CHNLIB_Debug_PrintStructureData(WorkingSet.RootMemory, 0);
7494 } else if(CHNLIB_String_CompareStringWithCString(temp, "readfile")){
7595 //::readfile:filename
76- readfp = fopen(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(separated, 4)), "rb");
7796 if(readfp == NULL){
78- puts("File open error.");
97+ readfp = fopen(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(separated, 4)), "rb");
98+ if(readfp == NULL){
99+ puts("File open error.");
100+ }
79101 }
102+ } else if(CHNLIB_String_CompareStringWithCString(temp, "savewordlist")){
103+ AI_System_SaveMemory_RootWordList(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(separated, 4)));
104+ } else if(CHNLIB_String_CompareStringWithCString(temp, "savememlist")){
105+ AI_System_SaveMemory_RootMemory(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(separated, 4)));
106+ } else if(CHNLIB_String_CompareStringWithCString(temp, "addmemtag")){
107+ //[not implemented]
80108 } else{
81109 passthink = False;
82110 }
83111 }
84112
85- ////WorkingSet.SystemWordList0を使っているので、解放しないように注意
86- //CHNLIB_UIPArray_FreeSelectedAll(&separated);
87113 release(separated);
88114 }
89115
@@ -113,13 +139,12 @@ void AI_Think_LearnWordFromInputString(CHNLIB_String *input)
113139 //入力文字列から単語を抽出して記憶する。
114140 CHNLIB_UIPArray *candidateWordList;
115141 int i, i_max;
116- int tagIndex, maxExistingWordIndex;
142+ int tagIndex;
117143
118144 candidateWordList = CHNLIB_UIPArray_Initialize();
119145 candidateWordList = AI_Think_SlideLookUpWordByHistory(input);
120146 i_max = CHNLIB_UIPArray_GetNumberOfDatas(candidateWordList);
121- maxExistingWordIndex = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.RootWordList) - 1;
122-
147+
123148 printf("Index(Decimal),CountOfContain(Decimal), String\n");
124149 for(i = 0; i < i_max; i++){
125150 printf("%d,%d,%s\n", i, CHNLIB_UIPArray_GetData32ByIndex(candidateWordList, i), CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(candidateWordList, i)));
@@ -201,134 +226,82 @@ CHNLIB_UIPArray *AI_Think_SlideLookUpWordByHistory(CHNLIB_String *input)
201226 }
202227
203228 //重複抽出フィルタリング
229+ AI_Think_CandidateWordList_Filter02(&candidatewordlist, 1);
204230 AI_Think_CandidateWordList_Filter01(&candidatewordlist, 1);
205231 AI_Think_CandidateWordList_Filter00(&candidatewordlist);
206232
207233 return candidatewordlist;
208234 }
209235
210-int AI_Think_CandidateWordList_Filter00(CHNLIB_UIPArray **candidatewordlist)
236+CHNLIB_UIPArray *AI_Think_WordList_GetSortedByLength(const CHNLIB_UIPArray *wordlist)
211237 {
212- //[Not implemented]
213- //[UTF-8]
214- //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。
215- //00:長い単語に含まれており、かつ出現頻度が長い単語と等しい単語を削除
216- int i, i_max;
217- CHNLIB_String *nowstr, *basestr;
218- int basestrCoC; //CountOfContainInHistoryStrings
238+ CHNLIB_UIPArray *temp, *sorted;
219239
220- i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist);
221- basestr = CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, 0);
222- basestrCoC = CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, 0);
223- for(i = 1; i < i_max; i++){
224- nowstr = CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, i);
225- if(CHNLIB_UTF8_GetCountOfContain(CHNLIB_String_GetReferencePointerOfCString(basestr), CHNLIB_String_GetReferencePointerOfCString(nowstr)) > 0){
226- //nowstrはbasestrに含まれている
227- if(basestrCoC == CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i)){
228- //かつ出現頻度が等しいので不要な単語
229- //出現頻度を0にして、後で削除する。
230- CHNLIB_UIPArray_SetData32ByIndex(*candidatewordlist, i, 0);
231- }
232- }
233-
234- if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) != 0){
235- //単語は削除されなかった、つまり異なる単語なので、basestrを更新
236- basestr = nowstr;
237- basestrCoC = CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i);
238- }
239- }
240+ temp = CHNLIB_UIPArray_CopyArray(wordlist);
240241
241- for(i = 1; i < i_max; i++){
242- if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) == 0){
243- //削除対象
244- CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i);
245- i--;
246- i_max--;
247- }
248- }
242+ AI_Think_WordList_SetLengthToData32(&temp);
243+ sorted = CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(temp);
249244
250- return 0;
245+ release(temp);
246+
247+ return sorted;
251248 }
252249
253-int AI_Think_CandidateWordList_Filter01(CHNLIB_UIPArray **candidatewordlist, int length)
250+void AI_Think_WordList_SetLengthToData32(CHNLIB_UIPArray **wordlist)
254251 {
255- //[Not implemented]
256- //[UTF-8]
257- //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。
258- //01:length以下の文字数の単語を削除
259-
260252 int i, i_max;
261253
262- i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist);
254+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(*wordlist);
255+
263256 for(i = 0; i < i_max; i++){
264- if(CHNLIB_UTF8_GetStringLengthByCharacter(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, i))) <= length){
265- CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i);
266- i--;
267- i_max--;
268- }
257+ CHNLIB_UIPArray_SetData32ByIndex(*wordlist, i, CHNLIB_UTF8_GetStringLengthByCharacter(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(*wordlist, i))));
269258 }
270259
271- return 0;
272-}
273-
274-int AI_Memory_AddRootWordData(CHNLIB_String *tag)
275-{
276- //WorkingSet.RootWordListに文字列を追加する。
277- //重複がある場合は警告を出し、追加しない。
278- //戻り値は追加されたまたは重複したタグのIndex.
279-
280- return CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&WorkingSet.RootWordList, 0, tag, &AI_Memory_AddRootWordData_IsDuplicated);
281-}
282-
283-int AI_Memory_AddRootWordData_IsDuplicated(const void *listtag, const void *newtag)
284-{
285- //CHNLIB_UIPArray_AppendLast_ProtectFromDuplicationに渡す関数ポインタ。
286- if(CHNLIB_StructureHeader_GetTypeID(listtag) != CHNLIB_STRUCT_ID_String){
287- return False;
288- }
289- if(CHNLIB_String_CompareString_Strict(listtag, newtag)){
290- CHNLIB_ReportError("Word[%s] has already existed.", CHNLIB_DEBUG_ARGUMENTS, CHNLIB_String_GetReferencePointerOfCString(newtag));
291- return True;
292- }
293- return False;
260+ return;
294261 }
295262
296263 void AI_System_InitializeSystemWorkingSet(void)
297264 {
298265 //WorkingSetを初期化する。
266+ int i, i_max;
267+
299268 WorkingSet.SystemWordList0 = CHNLIB_UIPArray_Initialize();
300- CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, True, autorelease(CHNLIB_String_Initialize(":")));
301- CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, True, autorelease(CHNLIB_String_Initialize(",")));
269+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Delimiter_Colon, autorelease(CHNLIB_String_Initialize(":")));
270+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Delimiter_Comma, autorelease(CHNLIB_String_Initialize(",")));
271+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Delimiter_Plus, autorelease(CHNLIB_String_Initialize("+")));
272+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Bracket_Start, autorelease(CHNLIB_String_Initialize("[")));
273+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList0, AI_SW_Bracket_End, autorelease(CHNLIB_String_Initialize("]")));
302274
303- WorkingSet.InputHistory = CHNLIB_UIPArray_Initialize();
275+ WorkingSet.SystemWordList1 = CHNLIB_UIPArray_Initialize();
276+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList1, True, autorelease(CHNLIB_String_Initialize("未定義")));
277+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList1, True, autorelease(CHNLIB_String_Initialize("真")));
278+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList1, True, autorelease(CHNLIB_String_Initialize("偽")));
279+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList1, True, autorelease(CHNLIB_String_Initialize("あいさつ")));
304280
305- return;
306-}
307-
308-void AI_System_LoadMemory(const char configfilename[])
309-{
310- //指定されたファイル名のテキストファイルから設定を読み出す。
311- FILE *fp;
312- CHNLIB_String *line, *currentfilename;
313- int i;
281+ WorkingSet.SystemWordList2 = CHNLIB_UIPArray_Initialize();
282+ for(i = 0; i < 10; i++){
283+ CHNLIB_UIPArray_AppendLast(&WorkingSet.SystemWordList2, True, autorelease(CHNLIB_String_InitializeWithFormat("%d", i)));
284+ }
285+
286+ WorkingSet.RootWordList = CHNLIB_UIPArray_Initialize();
287+ WorkingSet.RootMemory = CHNLIB_UIPArray_Initialize();
288+ WorkingSet.InputHistory = CHNLIB_UIPArray_Initialize();
314289
315- fp = fopen(configfilename, "rb");
316- currentfilename = CHNLIB_ReadLine(fp);
317- fclose(fp);
290+ //WordListへシステム文字列を追加
291+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.SystemWordList0);
292+ for(i = 0; i < i_max; i++){
293+ CHNLIB_UIPArray_AppendLast(&WorkingSet.RootWordList, 0, CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.SystemWordList0, i));
294+ }
318295
319- fp = fopen(CHNLIB_String_GetReferencePointerOfCString(currentfilename), "rb");
320- release(currentfilename);
296+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.SystemWordList1);
297+ for(i = 0; i < i_max; i++){
298+ CHNLIB_UIPArray_AppendLast(&WorkingSet.RootWordList, 0, CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.SystemWordList1, i));
299+ }
321300
322- WorkingSet.RootWordList = CHNLIB_UIPArray_Initialize();
323- for(i = 1; ;i++){
324- line = CHNLIB_ReadLine(fp);
325- if(line == NULL){
326- break;
327- }
328- CHNLIB_UIPArray_AppendLast(&WorkingSet.RootWordList, i, line);
329- release(line);
301+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.SystemWordList2);
302+ for(i = 0; i < i_max; i++){
303+ CHNLIB_UIPArray_AppendLast(&WorkingSet.RootWordList, 0, CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.SystemWordList2, i));
330304 }
331- fclose(fp);
332305
333306 return;
334307 }
--- /dev/null
+++ b/CHNOSProject/AI003/AI003/memory.c
@@ -0,0 +1,252 @@
1+//
2+// memory.c
3+// AI003
4+//
5+// Created by 西田 耀 on 13/05/20.
6+// Copyright (c) 2013年 Hikaru Nishida. All rights reserved.
7+//
8+
9+#include <stdio.h>
10+#include <stdlib.h>
11+#include "core.h"
12+
13+int AI_Memory_AddRootWordData(CHNLIB_String *tag)
14+{
15+ //WorkingSet.RootWordListに文字列を追加する。
16+ //重複がある場合は警告を出し、追加しない。
17+ //戻り値は追加されたまたは重複したタグのIndex.
18+
19+ return CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&WorkingSet.RootWordList, 0, tag, &AI_Memory_AddRootWordData_IsDuplicated);
20+}
21+
22+int AI_Memory_AddRootWordData_IsDuplicated(const void *listtag, const void *newtag)
23+{
24+ //CHNLIB_UIPArray_AppendLast_ProtectFromDuplicationに渡す関数ポインタ。
25+ if(CHNLIB_StructureHeader_GetTypeID(listtag) != CHNLIB_STRUCT_ID_String){
26+ return False;
27+ }
28+ if(CHNLIB_String_CompareString_Strict(listtag, newtag)){
29+ //CHNLIB_ReportError("Word[%s] has already existed.", CHNLIB_DEBUG_ARGUMENTS, CHNLIB_String_GetReferencePointerOfCString(newtag));
30+ return True;
31+ }
32+ return False;
33+}
34+
35+int AI_Memory_AddRootMemoryData(CHNLIB_UIPArray *tag)
36+{
37+ //WorkingSet.RootWordListに文字列を追加する。
38+ //重複がある場合は警告を出し、追加しない。
39+ //戻り値は追加されたまたは重複したタグのIndex.
40+
41+ return CHNLIB_UIPArray_AppendLast_ProtectFromDuplication(&WorkingSet.RootMemory, 0, tag, &AI_Memory_AddRootMemoryData_IsDuplicated);
42+}
43+
44+int AI_Memory_AddRootMemoryData_IsDuplicated(const void *listtag, const void *newtag)
45+{
46+ //CHNLIB_UIPArray_AppendLast_ProtectFromDuplicationに渡す関数ポインタ。
47+ CHNLIB_UIPArray *listtag_strArray, *newtag_strArray;
48+ int i, i_max;
49+
50+ if(CHNLIB_StructureHeader_GetTypeID(listtag) != CHNLIB_STRUCT_ID_UIPArray){
51+ return False;
52+ }
53+
54+ listtag_strArray = CHNLIB_UIPArray_GetPointerByIndex(listtag, 0);
55+ newtag_strArray = CHNLIB_UIPArray_GetPointerByIndex(newtag, 0);
56+
57+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(listtag_strArray);
58+ if(i_max == CHNLIB_UIPArray_GetNumberOfDatas(newtag_strArray)){
59+ //文字列配列の要素数が一致するので、内容も一致する可能性がある
60+ for(i = 0; i < i_max; i++){
61+ if(!CHNLIB_String_CompareString_Strict(CHNLIB_UIPArray_GetPointerByIndex(listtag_strArray, i), CHNLIB_UIPArray_GetPointerByIndex(newtag_strArray, i))){
62+ //一致しないタグがあったので、不一致
63+ return False;
64+ }
65+ }
66+ //すべて一致したので、重複している
67+ return True;
68+ }
69+ //文字列配列の要素数が一致しないので、不一致
70+ return False;
71+}
72+
73+//記憶ファイルの構成・書式
74+//-config.txt
75+// 一行目に単語リストファイル(words.txt)
76+// 二行目に記憶データファイル(memory.txt)
77+// のファイル名を記述する。
78+//
79+//-words.txt
80+//<単語カウント>:<単語文字列>
81+//
82+//-memory.txt
83+//[<文字列単語>+<文字列単語>+...][<属性値1>,<属性値2>,...][<属性値a>,<属性値b>,...]
84+//
85+//
86+void AI_System_LoadMemory(const char configfilename[])
87+{
88+ //指定されたファイル名のテキストファイルから設定を読み出す。
89+ FILE *configfp, *readfp;
90+ CHNLIB_String *line, *currentfilename;
91+ uint wordCount;
92+ char *invchar;
93+ int tagIndex, i, i_max;
94+ CHNLIB_UIPArray *separated, *dataArray, *subDataArray;
95+
96+ configfp = fopen(configfilename, "rb");
97+
98+ //単語リストの読み込み
99+ currentfilename = CHNLIB_ReadLine(configfp);
100+ readfp = fopen(CHNLIB_String_GetReferencePointerOfCString(currentfilename), "rb");
101+ release(currentfilename);
102+
103+ for(;;){
104+ line = CHNLIB_ReadLine(readfp);
105+ if(line == NULL){
106+ break;
107+ }
108+ wordCount = (uint)strtol(CHNLIB_String_GetReferencePointerOfCString(line), &invchar, 0);
109+ for(; *invchar != '\0'; invchar++){
110+ if(*invchar == ':'){
111+ invchar++;
112+ break;
113+ }
114+ }
115+ tagIndex = AI_Memory_AddRootWordData(autorelease(CHNLIB_String_Initialize(invchar)));
116+ CHNLIB_UIPArray_SetData32ByIndex(WorkingSet.RootWordList, tagIndex, CHNLIB_UIPArray_GetData32ByIndex(WorkingSet.RootWordList, tagIndex) + wordCount);
117+ release(line);
118+ }
119+ fclose(readfp);
120+
121+ //記憶データの読み込み
122+ currentfilename = CHNLIB_ReadLine(configfp);
123+ readfp = fopen(CHNLIB_String_GetReferencePointerOfCString(currentfilename), "rb");
124+ release(currentfilename);
125+
126+ for(;;){
127+ line = CHNLIB_ReadLine(readfp);
128+ if(line == NULL){
129+ break;
130+ }
131+ separated = CHNLIB_UIPArray_Initialize();
132+ CHNLIB_UIPArray_GetSeparatedStringByUIPArray(&separated, WorkingSet.SystemWordList0, line);
133+
134+ dataArray = CHNLIB_UIPArray_Initialize();
135+ subDataArray = CHNLIB_UIPArray_Initialize();
136+
137+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(separated);
138+ for(i = 0; i < i_max; i++){
139+ switch (CHNLIB_UIPArray_GetData32ByIndex(separated, i)) {
140+ case AI_SW_Delimiter_Colon:
141+ //:
142+ break;
143+
144+ case AI_SW_Delimiter_Comma:
145+ //,
146+ break;
147+
148+ case AI_SW_Delimiter_Plus:
149+ //+
150+ break;
151+
152+ case AI_SW_Bracket_Start:
153+ //[
154+ subDataArray = CHNLIB_UIPArray_Initialize();
155+ break;
156+
157+ case AI_SW_Bracket_End:
158+ //]
159+ CHNLIB_UIPArray_AppendLast(&dataArray, 0, subDataArray);
160+ release(subDataArray);
161+ break;
162+
163+ case 0:
164+ //文字列
165+ tagIndex = AI_Memory_AddRootWordData(CHNLIB_UIPArray_GetPointerByIndex(separated, i));
166+ CHNLIB_UIPArray_AppendLast(&subDataArray, 0, CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.RootWordList, tagIndex));
167+
168+ break;
169+ }
170+ }
171+ if(dataArray != NULL){
172+ AI_Memory_AddRootMemoryData(dataArray);
173+ release(dataArray);
174+ }
175+ release(separated);
176+ release(line);
177+ }
178+ fclose(readfp);
179+
180+ //終了処理
181+ fclose(configfp);
182+
183+ return;
184+}
185+
186+void AI_System_SaveMemory_RootWordList(const char wordlistfilename[])
187+{
188+ //指定されたファイル名へ単語リストを出力する。
189+ FILE *writefp;
190+ CHNLIB_UIPArray *sorted;
191+ int i, i_max;
192+
193+ writefp = fopen(wordlistfilename, "wb");
194+ if(writefp == NULL){
195+ puts("File open error.");
196+ } else{
197+ sorted = CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(WorkingSet.RootWordList);
198+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(sorted);
199+ for(i = 0; i < i_max; i++){
200+ fprintf(writefp, "%10d:%s\n", CHNLIB_UIPArray_GetData32ByIndex(sorted, i), CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(sorted, i)));
201+ }
202+ fclose(writefp);
203+ writefp = NULL;
204+ release(sorted);
205+ puts("Save RootWordList done.");
206+ }
207+
208+ return;
209+}
210+
211+void AI_System_SaveMemory_RootMemory(const char memlistfilename[])
212+{
213+ //指定されたファイル名へ記憶データを出力する。
214+ FILE *writefp;
215+ CHNLIB_UIPArray *subArray;
216+ int i, i_max;
217+ int j, j_max;
218+ int k, k_max;
219+
220+ writefp = fopen(memlistfilename, "wb");
221+ if(writefp == NULL){
222+ puts("File open error.");
223+ } else{
224+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(WorkingSet.RootMemory);
225+ for(i = 0; i < i_max; i++){
226+ subArray = CHNLIB_UIPArray_GetPointerByIndex(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.RootMemory, i), 0);
227+ j_max = CHNLIB_UIPArray_GetNumberOfDatas(subArray);
228+ fputc('[', writefp);
229+ for(j = 0; j < j_max - 1; j++){
230+ fprintf(writefp, "%s+", CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(subArray, j)));
231+ }
232+ fprintf(writefp, "%s]", CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(subArray, j)));
233+
234+ k_max = CHNLIB_UIPArray_GetNumberOfDatas(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.RootMemory, i));
235+ for(k = 1; k < k_max; k++){
236+ subArray = CHNLIB_UIPArray_GetPointerByIndex(CHNLIB_UIPArray_GetPointerByIndex(WorkingSet.RootMemory, i), k);
237+ j_max = CHNLIB_UIPArray_GetNumberOfDatas(subArray);
238+ fputc('[', writefp);
239+ for(j = 0; j < j_max - 1; j++){
240+ fprintf(writefp, "%s,", CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(subArray, j)));
241+ }
242+ fprintf(writefp, "%s]", CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(subArray, j)));
243+ }
244+ fputc('\n', writefp);
245+ }
246+ fclose(writefp);
247+ writefp = NULL;
248+ puts("Save RootMemory done.");
249+ }
250+
251+ return;
252+}
--- /dev/null
+++ b/CHNOSProject/AI003/AI003/wlfilter.c
@@ -0,0 +1,92 @@
1+//
2+// wlfilter.c
3+// AI003
4+//
5+// Created by 西田 耀 on 13/05/20.
6+// Copyright (c) 2013年 Hikaru Nishida. All rights reserved.
7+//
8+
9+#include <stdio.h>
10+#include "core.h"
11+
12+int AI_Think_CandidateWordList_Filter00(CHNLIB_UIPArray **candidatewordlist)
13+{
14+ //[UTF-8]
15+ //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。
16+ //00:長い単語に含まれており、かつ出現頻度が長い単語と等しい単語を削除
17+ int i, i_max;
18+ CHNLIB_String *nowstr, *basestr;
19+ int basestrCoC; //CountOfContainInHistoryStrings
20+
21+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist);
22+ basestr = CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, 0);
23+ basestrCoC = CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, 0);
24+ for(i = 1; i < i_max; i++){
25+ nowstr = CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, i);
26+ if(CHNLIB_UTF8_GetCountOfContain(CHNLIB_String_GetReferencePointerOfCString(basestr), CHNLIB_String_GetReferencePointerOfCString(nowstr)) > 0){
27+ //nowstrはbasestrに含まれている
28+ if(basestrCoC == CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i)){
29+ //かつ出現頻度が等しいので不要な単語
30+ //出現頻度を0にして、後で削除する。
31+ CHNLIB_UIPArray_SetData32ByIndex(*candidatewordlist, i, 0);
32+ }
33+ }
34+
35+ if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) != 0){
36+ //単語は削除されなかった、つまり異なる単語なので、basestrを更新
37+ basestr = nowstr;
38+ basestrCoC = CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i);
39+ }
40+ }
41+
42+ for(i = 1; i < i_max; i++){
43+ if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) == 0){
44+ //削除対象
45+ CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i);
46+ i--;
47+ i_max--;
48+ }
49+ }
50+
51+ return 0;
52+}
53+
54+int AI_Think_CandidateWordList_Filter01(CHNLIB_UIPArray **candidatewordlist, int length)
55+{
56+ //[UTF-8]
57+ //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。
58+ //01:length以下の文字数の単語を削除
59+
60+ int i, i_max;
61+
62+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist);
63+ for(i = 0; i < i_max; i++){
64+ if(CHNLIB_UTF8_GetStringLengthByCharacter(CHNLIB_String_GetReferencePointerOfCString(CHNLIB_UIPArray_GetPointerByIndex(*candidatewordlist, i))) <= length){
65+ CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i);
66+ i--;
67+ i_max--;
68+ }
69+ }
70+
71+ return 0;
72+}
73+
74+int AI_Think_CandidateWordList_Filter02(CHNLIB_UIPArray **candidatewordlist, uint count)
75+{
76+ //[UTF-8]
77+ //AI_Think_SlideLookUpWordByHistoryで返されたArray内の候補単語に対して、フィルターをかける。
78+ //02:count以下の出現回数の単語を削除
79+
80+ int i, i_max;
81+
82+ i_max = CHNLIB_UIPArray_GetNumberOfDatas(*candidatewordlist);
83+ for(i = 0; i < i_max; i++){
84+ if(CHNLIB_UIPArray_GetData32ByIndex(*candidatewordlist, i) <= count){
85+ CHNLIB_UIPArray_RemoveByIndex(candidatewordlist, i);
86+ i--;
87+ i_max--;
88+ }
89+ }
90+
91+ return 0;
92+}
--- /dev/null
+++ b/CHNOSProject/AI003/memory.txt
@@ -0,0 +1 @@
1+[こんにちは][単語,あいさつ]
--- a/CHNOSProject/chn/chnlib.h
+++ b/CHNOSProject/chn/chnlib.h
@@ -28,6 +28,7 @@
2828 #ifdef DEBUG
2929 //#define DEBUG_MEMORY_ALLOCATION
3030 //#define DEBUG_MEMORY_REFERENCE_COUNT
31+//#define DEBUG_STRING_STRICT
3132 #endif
3233
3334 //
@@ -117,6 +118,7 @@ CHNLIB_UIPArray *CHNLIB_UIPArray_GetSortedInDescendingOrderByData32(const CHNLIB
117118 typedef struct CHNLIB_STRING CHNLIB_String;
118119 struct CHNLIB_STRING;
119120 CHNLIB_String *CHNLIB_String_Initialize(const char str[]);
121+CHNLIB_String *CHNLIB_String_InitializeWithFormat(const char format[], ...);
120122 void CHNLIB_String_Free(CHNLIB_String *strtag);
121123 int CHNLIB_String_SetStringFromCString(CHNLIB_String *strtag, const char s[]);
122124 int CHNLIB_String_Print(CHNLIB_String *strtag);
--- a/CHNOSProject/chn/chnlib01.c
+++ b/CHNOSProject/chn/chnlib01.c
@@ -15,6 +15,7 @@
1515 #include <stdio.h>
1616 #include <stdlib.h>
1717 #include <string.h>
18+#include <stdarg.h>
1819 #include "chnlib.h"
1920
2021 //
@@ -62,6 +63,25 @@ CHNLIB_String *CHNLIB_String_Initialize(const char str[])
6263 return strtag;
6364 }
6465
66+CHNLIB_String *CHNLIB_String_InitializeWithFormat(const char format[], ...)
67+{
68+ CHNLIB_String *strtag;
69+ va_list ap;
70+ char str[CHNLIB_MAX_STRING_LENGTH];
71+
72+ va_start(ap, format);
73+ vsnprintf(str, sizeof(str), format, ap);
74+ va_end(ap);
75+
76+ strtag = CHNLIB_String_Internal_Allocate();
77+ strtag->header.destructor = &CHNLIB_String_Internal_Destruct;
78+
79+ if(str != NULL){
80+ CHNLIB_String_SetStringFromCString(strtag, str);
81+ }
82+ return strtag;
83+}
84+
6585 void CHNLIB_String_Free(CHNLIB_String *strtag)
6686 {
6787 //strtagを解放する。
@@ -289,10 +309,13 @@ int CHNLIB_CString_CompareString(const char s[], const char search[])
289309 //s[]の先頭からsearch[]と比較し、searchの終端まで一致したらTrue, 一致しなかったらFalseを返す。
290310 //終端文字'\0'はカウントしない。
291311 //search[]に含まれる文字(終端文字除く)がすべて入っていれば一致とみなす。
312+ //どちらかがNULLであった場合は、Falseを返す。
292313 int i;
293314
294315 if(s == NULL || search == NULL){
316+#ifdef DEBUG_STRING_STRICT
295317 CHNLIB_ReportError("Null str.\n", CHNLIB_DEBUG_ARGUMENTS);
318+#endif
296319 return False;
297320 }
298321
--- a/CHNOSProject/chn/chnlib03.c
+++ b/CHNOSProject/chn/chnlib03.c
@@ -54,10 +54,10 @@ void CHNLIB_Environment_SetCurrentWorkingDirectory(const char apppath[])
5454 }
5555 }
5656 path[last + 1] = '\0';
57- printf("%s\n", path);
57+ //printf("%s\n", path);
5858 chdir(path);
5959 getcwd(path, sizeof(path));
60- printf("%s\n", path);
60+ //printf("%s\n", path);
6161
6262 return;
6363 }
--- a/CHNOSProject/chn/chnlib04.c
+++ b/CHNOSProject/chn/chnlib04.c
@@ -216,11 +216,15 @@ int CHNLIB_UTF8_GetByteSizeFromLengthByCharacter(const char s[], int start, int
216216 const char *p;
217217
218218 if(s == NULL){
219+#ifdef DEBUG_STRING_STRICT
219220 CHNLIB_ReportError("Null str.\n", CHNLIB_DEBUG_ARGUMENTS);
221+#endif
220222 return 0;
221223 }
222224 if(end < start){
225+#ifdef DEBUG_STRING_STRICT
223226 CHNLIB_ReportError("Invalid index.\n", CHNLIB_DEBUG_ARGUMENTS);
227+#endif
224228 return 0;
225229 }
226230
Show on old repository browser