-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile1.cpp
103 lines (85 loc) · 2.15 KB
/
file1.cpp
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
//
// AYA version 5
//
// 1つのファイルを扱うクラス CFile1
// written by umeici. 2004
//
#ifndef POSIX
# include "stdafx.h"
#else
# include "manifest.h"
#endif
#include "file.h"
#include "misc.h"
#include "ccct.h"
#include "wsex.h"
/* -----------------------------------------------------------------------
* 関数名 : CFile1::Open
* 機能概要: ファイルをオープンします
*
* 返値 : 0/1=失敗/成功(既にロードされている含む)
* -----------------------------------------------------------------------
*/
int CFile1::Open(void)
{
if (fp != NULL)
return 1;
char *filepath = Ccct::Ucs2ToMbcs(name, CHARSET_DEFAULT);
if (filepath == NULL)
return 0;
fp = w_fopen((wchar_t *)name.c_str(), (wchar_t *)mode.c_str());
free(filepath);
return (fp != NULL) ? 1 : 0;
}
/* -----------------------------------------------------------------------
* 関数名 : CFile1::Close
* 機能概要: ファイルをクローズします
*
* 返値 : 1/2=成功/ロードされていない、もしくは既にunloadされている
* -----------------------------------------------------------------------
*/
int CFile1::Close(void)
{
if (fp == NULL)
return 2;
fclose(fp);
return 1;
}
/* -----------------------------------------------------------------------
* 関数名 : CFile1::Write
* 機能概要: ファイルに文字列を書き込みます
*
* 返値 : 0/1=失敗/成功
* -----------------------------------------------------------------------
*/
int CFile1::Write(const wstring &istr)
{
if (fp == NULL)
return 0;
// 文字列をマルチバイト文字コードに変換
char *t_istr = Ccct::Ucs2ToMbcs(istr, charset);
if (t_istr == NULL)
return 0;
long len = (long)strlen(t_istr);
// 書き込み
fwrite(t_istr, sizeof(char), len, fp);
free(t_istr);
return 1;
}
/* -----------------------------------------------------------------------
* 関数名 : CFile1::Read
* 機能概要: ファイルから文字列を1行読み取ります
*
* 返値 : -1/0/1=EOF/失敗/成功
* -----------------------------------------------------------------------
*/
int CFile1::Read(wstring &ostr)
{
ostr = L"";
if (fp == NULL)
return 0;
if (ws_fgets(ostr, fp, charset, 0, bomcheck) == WS_EOF)
return -1;
bomcheck++;
return 1;
}