-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.c
163 lines (141 loc) · 2.23 KB
/
file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <stdlib.h>
#include <fcntl.h>
#include <io.h>
#include <sys\stat.h>
#include <sys\types.h>
#include "default.h"
#include "draw.h"
#include "file.h"
static char gbPath[DIALOG_PATH_W-2];
void Get_File_Path(char * caDialog_Path)
{
unsigned int uiCnt = 0;
for(uiCnt = 0; gbPath[uiCnt] != 0; uiCnt++)
{
caDialog_Path[uiCnt] = gbPath[uiCnt];
}
caDialog_Path[uiCnt] = 0;
return;
}
void Set_File_Path(char * caDialog_Path)
{
unsigned int uiCnt = 0;
for(uiCnt = 0; caDialog_Path[uiCnt] != 0; uiCnt++)
{
gbPath[uiCnt] = caDialog_Path[uiCnt];
}
gbPath[uiCnt] = 0;
return;
}
void Test_Ext(char * path)
{
unsigned int uiCnt;
unsigned int uiExt;
char cExt[] = ".txt";
for(uiCnt = 1; path[uiCnt] != 0; uiCnt++)
{
if(path[uiCnt] == '.')
{
break;
}
if( uiCnt == 13)
{
break;
}
}
for(uiExt = 0; cExt[uiExt] != 0; uiExt++)
{
path[uiCnt+uiExt] = cExt[uiExt];
}
path[uiCnt+uiExt] = 0;
return;
}
int Save_File(char * path)
{
int fd;
stLine * TmpL = gbHead;
stChar * TmpC;
int x = 0;
int y = 0;
Test_Ext(path);
fd = creat(path, S_IREAD|S_IWRITE);
if(fd == -1)
{
return FAIL;
}
while( 0 != TmpL )
{
TmpC = TmpL->char_point;
while(TmpC != 0)
{
write(fd, &(TmpC->character), 1);
TmpC = TmpC->next;
x++;
}
y++;
TmpL = TmpL->down;
}
Set_File_Path(path);
close(fd);
return GOOD;
}
int Load_File(char * path)
{
int fd;
char ch;
volatile int ret = 1;
stLine * tmpL;
fd = open(path, O_RDWR|O_TEXT);
if(fd == -1)
{
return FAIL;
}
FreeAll();
Init();
lseek(fd, 0, SEEK_SET);
while( ret != 0)
{
ret = read(fd, &ch, 1);
if(ret == 0) break;
if(ch == '\n' )
{
if(FAIL == Insert_Enter())
{
FreeAll();
Init();
Dialog_Error("[ Enter Fail ]");
return ERROR;
}
}
else if(ch == TAB)
{
for(ret = 0; ret<TAB_CNT; ret++)
{
if(FAIL == Insert(' '))
{
FreeAll();
Init();
Dialog_Error("[ Insert Fail ]");
return ERROR;
}
}
}
else if((ch >= ' ')&&(ch <= '~'))
{
if(FAIL == Insert(ch))
{
FreeAll();
Init();
Dialog_Error("[ Insert Fail ]");
return ERROR;
}
}
}
gbCurL = gbHead;
gbCurC = 0;
gbTopL = gbHead;
gbTopCharNum= 0;
Set_File_Path(path);
close(fd);
return GOOD;
}