This source file includes following definitions.
- CurrentFile
- Load
- At
- BF_Dict_Load
- BF_DictAt
- BF_DictCurrentFile
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "BF_Dict.h"
4 #include "BL_File.h"
5
6
7
8 class BF_Dict:public BL_Object{
9 public:
10 BF_Dict();
11 const char* At(uint32 i_Index);
12 void Load(const char *pc_Name);
13 const char* CurrentFile() const {return sFile.String();};
14 private:
15 BL_List lsData;
16 BL_String sFile;
17 };
18
19 BF_Dict *poDict=NULL;
20
21
22
23 BF_Dict::BF_Dict()
24 {
25 }
26
27 #include <Roster.h>
28 #include <Application.h>
29 #include <Path.h>
30
31 void
32 BF_Dict::Load(const char *pc_Name)
33 {
34 ASSERT(pc_Name);
35
36 sFile = pc_Name;
37
38 BL_String s;
39 {
40 app_info uInfo;
41 be_app->GetAppInfo(&uInfo);
42 BEntry oEntry(&uInfo.ref);
43
44 BPath oPath;
45 oEntry.GetPath(&oPath);
46 BPath oPath1;
47 oPath.GetParent(&oPath1);
48 s<<oPath1.Path();
49 }
50
51 s<<"/";
52 s<<pc_Name;
53 printf(s.String());
54 printf("-------\n");
55
56 BL_File oFile(s.String(),B_READ_ONLY);
57 if(B_OK!=oFile.InitCheck()){
58 BL_String sError("Can`t open ");
59 sError<<s.String();
60 Debug_Error(sError.String(),oFile.InitCheck());
61 exit(-1);
62 }
63
64 lsData.DeleteItems();
65
66 for(int i=0;i<BF_DICT_COUNT;i++) lsData.AddItem(new BL_String());
67
68 s="";
69 BL_String s1;
70 BL_String *ps;
71 int32 i1,i2;
72 uint32 iCode;
73
74 while(B_OK==oFile.ReadString(&s)){
75 if(s.FindFirst("//")==0) continue;
76 if(s.FindFirst("`")==0) continue;
77 if(s=="") continue;
78
79 i2=s.FindFirst("|");
80 if(i2<=0) continue;
81
82 s1= "";
83 s1.Insert(s,0,i2,0);
84
85 iCode = s1.Int32();
86
87 i1=s.FindFirst("|",i2+1);
88 if(i1<0) continue;
89
90 s1 = "";
91 s1.Insert(s,i1+1,s.Length()-i1,0);
92
93 ps = lsData.StringAt(iCode);
94 if(!ps) continue;
95 ps->SetTo(s1);
96 }
97 }
98
99 const char*
100 BF_Dict::At(uint32 i_Index)
101 {
102 const BL_String *ps = lsData.StringAt(i_Index);
103 if(!ps){
104 BL_String s("Can`t find dictionary frase #");
105 s<<i_Index;
106 ASSERT(FALSE,s.String());
107 }
108 return ps->String();
109 }
110
111
112 void BF_Dict_Load(const char *pc_DictName)
113 {
114 if(poDict) delete poDict;
115 poDict = new BF_Dict();
116 poDict->Load(pc_DictName);
117 }
118
119 const char* BF_DictAt(uint32 i_Index)
120 {
121 ASSERT(poDict);
122 return poDict->At(i_Index);
123 }
124
125
126 const char* BF_DictCurrentFile()
127 {
128 ASSERT(poDict);
129 return poDict->CurrentFile();
130 }
131