Develop and Download Open Source Software

Browse Subversion Repository

Contents of /old/edit.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 52 - (show annotations) (download)
Sat Apr 26 02:58:09 2008 UTC (15 years, 11 months ago) by tabasa
File MIME type: text/plain
File size: 7248 byte(s)
dir suggest test when dir doesnt exist
1 #include "defextern.h"
2
3 #ifndef STRICT
4 #define STRICT
5 #endif
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <iostream.h>
9 #include <fstream.h>
10 #include <windows.h>
11 #include "edit.h"
12 #include "mes.h"
13 #include "initial.h"
14 #include "file.h"
15 #include "status.h"
16 #include "mode.h"
17
18 #define MAX_EDIT 1024*30
19 #define editsize MAX_EDIT
20 char buff[editsize];
21 char backupbuff[editsize];
22 char editfile[MAX_PATH];
23
24 struct buffers
25 {
26 BOOL first;
27 char buff[editsize];
28 char backupbuff[editsize];
29 char updatebuff[editsize];
30 buffers(){
31 first =TRUE;
32 reset(buff);
33 reset(backupbuff);
34 reset(updatebuff);
35 }
36 void reset(char *buff) {memset(buff,0,editsize);}
37 BOOL update(ofstream &klog) {
38
39 BOOL ans = strcmp(buff,backupbuff)==0;
40 if(!ans && getnew()>0)
41 {
42 if(!first) klog<<updatebuff;
43 wsprintf(backupbuff,"%s",buff);
44 first =FALSE;
45 }
46 //Mes(buff);
47 return ans;
48 }
49 int getnew() {
50 char *p =buff;
51 int i;
52 for(i=0;i<strlen(buff);i++){
53 if(*p == backupbuff[i]) p++;
54 else break;
55 }
56 reset(updatebuff);
57 if(i<strlen(buff)-1){
58 strcpy(updatebuff,p);
59 for(int j=0;j<strlen(updatebuff);j++){
60 if(*p != backupbuff[i]) p++;
61 else if(strcmp(p,(char*)(&(backupbuff[i])))==0){
62 updatebuff[j]=0;
63 break;
64 }
65 }
66 }
67 //Mes(updatebuff);
68 return strlen(updatebuff);
69 }
70 };
71
72 buffers klogbuffer;
73
74
75 //������ ���������t�@�C�����`�F�b�N
76
77 BOOL checkoverwriteOK(char *file)
78 {
79 setstatusonly(1,"-");
80 if(checkExt(file,"exe")) return FALSE;
81 if(checkExt(file,"EXE")) return FALSE;
82 setstatusonly(1,"+");
83 return TRUE;
84 }
85
86 //������ ���������t�@�C�����\��
87
88 void overwriteStatus(char *st)
89 {
90 setstatusonly(1,st);
91 }
92
93 void cnvtoa(char *buf, int delim,long len,long denum)
94 {
95 strcpy(backupbuff,buf);
96 char *pfrom,*pto;
97 pfrom =backupbuff;
98 pto =buf;
99 long count=0;
100
101 for(long i=0; i+count<len; i++,pfrom++,pto++)
102 {
103 if(*pfrom!=delim) *pto=*pfrom;
104 else {
105 *pto=13;
106 pto++;
107 *pto=10;
108 count++;
109 }
110 }
111 }
112
113
114 char *cnvbuff(char *buf, long len)
115 {
116 int a=0;
117 int d=0;
118 int da=0;
119 for(int i=0; i<1000; i++)
120 {
121 if(buf[i]==13){
122 if( buf[i+1]==10) da++;
123 else d++;
124 }
125 else if(buf[i]==10) a++;
126 }
127 if(da==1 && a+d>0)
128 {
129 if(a>3){
130 cnvtoa(buf,10,len,a);
131 }
132 else if(d>3){
133 cnvtoa(buf,13,len,d);
134 }
135 }
136 return buf;
137 }
138
139 //edit window �\����
140 //�t�@�C���������A���e�\���A���e���o�b�N�A�b�v�o�b�t�@���R�s�[�i�������������j
141 //utf-8�ifirefox bookmark.htm�����j�I���������������������������H
142
143 void setfile(HWND hEdit,char *file,char *dir)
144 {
145 SetWindowText(hEdit,"loading..");
146 SetCurrentDirectory(dir);
147 _fullpath(editfile,file,MAX_PATH);
148 editflag=FALSE;
149 memset(buff,0,sizeof(buff));
150 memset(backupbuff,0,sizeof(backupbuff));
151 ifstream in(editfile,ios::binary | ios::nocreate);
152 sprintf(buff,"$.%s\r\n",file);
153 int headlen=strlen(buff);
154 long rsize =editsize-headlen-2;
155 editflag=FALSE;
156 if(in) {
157 in.read(buff+headlen,rsize);
158 cnvbuff(buff,rsize);
159 strcpy(backupbuff,buff);
160 SetWindowText(hEdit,buff);
161 checkoverwriteOK(editfile);
162 if(getfilesize(file)<editsize-1000)
163 {
164 editflag=TRUE;
165 overwriteStatus("");
166 }
167 else
168 {
169 overwriteStatus("big");
170 }
171 }
172 else
173 {
174 overwriteStatus("no");
175 }
176 }
177
178
179 char* getCurrentEditWinStr(HWND hEdit)
180 {
181 memset(buff,0,sizeof(buff));
182 GetWindowText(hEdit,buff,editsize-2);
183 return buff;
184 }
185
186 //������
187 //�o�b�N�A�b�v�o�b�t�@�����r�A�X�V�������������������B
188
189 void overwrite(HWND hEdit)
190 {
191 if(editflag)
192 {
193 memset(buff,0,sizeof(buff));
194 GetWindowText(hEdit,buff,editsize-2);
195 if(strcmp(backupbuff,buff)!=0 && checkoverwriteOK(editfile))
196 {
197 ofstream ou(editfile,ios::binary);
198 ou.write(buff,strlen(buff));
199 }
200 }
201 else
202 {
203 MessageBox(NULL, "�T�C�Y�����������������o�����t�@�C����������������", "Error", MB_OK);
204 }
205 }
206
207 //�����������A�t�@�C�����������O�������o�������A����������������������
208 void autooverwrite(HWND hEdit)
209 {
210 if(editflag)
211 {
212 overwrite(hEdit);
213 }
214 }
215
216
217 BOOL geteditflag()
218 {
219 return editflag;
220 }
221
222 void seteditflag(BOOL f)
223 {
224 editflag=f;
225 }
226
227 int readline(char *to,char *from,int len=0)
228 {
229 int i;
230 if(len==0) len=strlen(from);
231 strncpy(to,from,len);
232 for (i=0; i<strlen(to);i++)
233 {
234 if(to[i]==0x0d ||to[i]==0x0a){
235 to[i]=0;
236 break;
237 }
238 }
239 return i;
240 }
241
242 void cnvfname(char *to,char *from=NULL)
243 {
244 if(from==NULL) from=to;
245 char buff[MAX_PATH];
246 strcpy(buff,from);
247 char bad[]="\\ /:*?\"<>|";
248 for(int i=0;i<strlen(from);i++)
249 {
250 if(strchr(bad,buff[i])!=NULL) buff[i]='_';
251 }
252 strcpy(to,buff);
253 // Mes(buff);
254 }
255
256 int gettmpname(char *tmpfile, char *buff ,char *top=NULL)
257 {
258 int i=0;
259 int hlen;
260 if(top!=NULL) {
261 hlen=strlen(top);
262 if(strncmp(buff,top,hlen)==0) {
263 i=readline(tmpfile,buff+hlen,MAX_PATH-6);
264 if( strchr(tmpfile,'.') ==NULL ) strcat(tmpfile,".txt");
265 return i;
266 }
267 }
268 else {
269 i=readline(tmpfile,buff+2,MAX_PATH-2);
270 cnvfname(tmpfile);
271 if( strchr(tmpfile,'.') ==NULL ) strcat(tmpfile,".txt");
272 }
273 return i;
274 }
275
276
277 // �����s�����O���w����������������
278 // $.filename => current folder
279 // $>filename => memo folder
280
281 void saveTempo(HWND hEdit)
282 {
283 char mfile[MAX_PATH];
284 char tmpfile[MAX_PATH];
285
286 memset(buff,0,sizeof(buff));
287 memset(tmpfile,0,sizeof(tmpfile));
288 GetWindowText(hEdit,buff,editsize-2);
289 int pos = gettmpname( tmpfile, buff, "$>" );
290 if( pos!=0 ) {
291 GetFullName(mfile, tmpfile, memopath, MAX_PATH);
292 }
293 else {
294 pos = gettmpname( tmpfile, buff, "$." );
295 if( pos!=0 ) {
296 strcpy(mfile, tmpfile);
297 }
298 else {
299 wsprintf(mfile,"%s.txt", gettimestr());
300 // Mes(mfile);
301 ofstream ou(mfile,ios::binary);
302 if(ou) {
303 ou.write(buff,strlen(buff));
304 //Mes(mfile);
305 }
306 return;
307 }
308 }
309 ofstream ou(mfile,ios::binary);
310 if(ou && strlen(buff)-pos-4>0) {
311 ou.write(buff+pos+4,strlen(buff)-pos-4);
312 }
313 else Mes("can't save");
314 }
315
316 void saveMemo(HWND hEdit)
317 {
318 //Mes("save memo");
319 char mfile[MAX_PATH];
320 char buff[editsize];
321 GetFullName(mfile, memofile, memopath, MAX_PATH);
322
323 memset(buff,0,sizeof(buff));
324 if( MemoMode ==_OFF || hEdit == NULL ) return;
325 GetWindowText(hEdit,buff,editsize-2);
326 if(strcmp(backupbuff,buff)!=0 )
327 {
328 ofstream ou(mfile,ios::binary);
329 if(ou) {
330 ou.write(buff,strlen(buff));
331 SetWindowText(hEdit,"");
332 }
333 else Mes("can't save");
334 }
335 }
336
337 int renameMemo()
338 {
339 char newfile[MAX_PATH];
340 char ToFile[MAX_PATH], FromFile[MAX_PATH];
341
342 makenewfilenameEx(memofile,newfile);
343 //wsprintf(memofile,"%s",newfile);
344 GetFullName(ToFile, newfile, memopath, MAX_PATH);
345 GetFullName(FromFile, memofile, memopath, MAX_PATH);
346 return rename( FromFile, ToFile );
347 }
348
349 int changeMemo(HWND Edit)
350 {
351 if (Edit!=NULL) saveMemo(Edit);
352 int res=(renameMemo());
353 if(res) SetWindowText(Edit,"");
354 return res;
355 }
356
357 void askmemoname(char *path)
358 {
359 //
360 }
361
362 void loadMemo(HWND hEdit)
363 {
364 if(strlen(memopath)==0)
365 {
366 askmemoname(memopath);
367 }
368 if(strlen(memopath)==0)
369 {
370 strcpy(memopath,getCdir());
371 }
372
373 char mfile[MAX_PATH];
374 GetFullName(mfile, memofile, memopath, MAX_PATH);
375
376 memset(buff,0,sizeof(buff));
377 ifstream in(mfile,ios::binary | ios::nocreate);
378 if(in) in.read(buff,editsize-2);
379 cnvbuff(buff,editsize-2);
380 strcpy(backupbuff,buff);
381 SetWindowText(hEdit,buff);
382 //Mes(mfile);
383 }
384
385 void keylog( HWND hEdit, WORD key)
386 {
387 if(MemoMode == _OFF) return;
388 GetStream("key.log.txt", memopath, klog, ios::ate);
389 // Mes(klog? 1:-1);
390 GetWindowText(hEdit,klogbuffer.buff,editsize-2);
391 klogbuffer.update(klog);
392 klog.close();
393 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision
svn:mime-type text/plain

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26