Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 954f932

Browse files
committed
[[libsystem]] Move MCFile* API into system library.
1 parent 6d4d14a commit 954f932

18 files changed

+718
-704
lines changed

libfoundation/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ SOURCES= \
1212
foundation-data.cpp \
1313
foundation-debug.cpp \
1414
foundation-error.cpp \
15-
foundation-file.cpp \
16-
foundation-file-posix.cpp \
1715
foundation-filters.cpp \
1816
foundation-foreign.cpp \
1917
foundation-handler.cpp \
@@ -29,15 +27,17 @@ SOURCES= \
2927
foundation-record.cpp \
3028
foundation-set.cpp \
3129
foundation-stream.cpp \
32-
foundation-stream-stdio.cpp \
3330
foundation-string.cpp \
3431
foundation-text.cpp \
3532
foundation-typeconvert.cpp \
3633
foundation-typeinfo.cpp \
3734
foundation-unicodechars.cpp \
3835
foundation-unicode.cpp \
3936
foundation-value.cpp \
40-
system-init.cpp
37+
system-file.cpp \
38+
system-file-posix.cpp \
39+
system-init.cpp \
40+
system-stream.cpp
4141

4242
CUSTOM_DEFINES=
4343

libfoundation/include/foundation-file.h

Lines changed: 0 additions & 91 deletions
This file was deleted.

libfoundation/include/foundation-system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2323

2424
extern "C" {
2525

26+
#include <system-file.h>
2627
#include <system-init.h>
28+
#include <system-stream.h>
2729

2830
}
2931

libfoundation/include/foundation.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,10 +2533,6 @@ MC_DLLEXPORT bool MCForeignValueExport(MCTypeInfoRef typeinfo, MCValueRef value,
25332533
// STREAM DEFINITIONS
25342534
//
25352535

2536-
MC_DLLEXPORT extern MCStreamRef kMCStdinStream;
2537-
MC_DLLEXPORT extern MCStreamRef kMCStdoutStream;
2538-
MC_DLLEXPORT extern MCStreamRef kMCStderrStream;
2539-
25402536
// Basic stream creation.
25412537

25422538
struct MCStreamCallbacks
@@ -2705,11 +2701,6 @@ MC_DLLEXPORT bool MCStreamReadSet(MCStreamRef stream, MCSetRef& r_set);
27052701
// easy encoding/decoding of any value type (that supports serialization).
27062702
MC_DLLEXPORT bool MCStreamReadValue(MCStreamRef stream, MCValueRef& r_value);
27072703

2708-
// Standard streams
2709-
MC_DLLEXPORT bool MCStreamGetStandardOutput(MCStreamRef & r_stdout);
2710-
MC_DLLEXPORT bool MCStreamGetStandardInput(MCStreamRef & r_stdin);
2711-
MC_DLLEXPORT bool MCStreamGetStandardError(MCStreamRef & r_stderr);
2712-
27132704
////////////////////////////////////////////////////////////////////////////////
27142705
//
27152706
// PROPER LIST DEFINITIONS
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/* -*-c++-*-
2+
Copyright (C) 2015 Runtime Revolution Ltd.
3+
4+
This file is part of LiveCode.
5+
6+
LiveCode is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License v3 as published by the Free
8+
Software Foundation.
9+
10+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
17+
18+
#if !defined(__MCS_SYSTEM_H_INSIDE__)
19+
# error "Only <foundation-system.h> can be included directly"
20+
#endif
21+
22+
/* ================================================================
23+
* Errors
24+
* ================================================================ */
25+
26+
MC_DLLEXPORT extern MCTypeInfoRef kMCSFileIOErrorTypeInfo;
27+
MC_DLLEXPORT extern MCTypeInfoRef kMCSFileEndOfFileErrorTypeInfo;
28+
MC_DLLEXPORT extern MCTypeInfoRef kMCSFileInvalidPathErrorTypeInfo;
29+
30+
#ifdef __MCS_INTERNAL_API__
31+
32+
bool __MCSFileThrowIOErrorWithErrno (MCStringRef p_native_path, MCStringRef p_message, int p_errno);
33+
bool __MCSFileThrowReadErrorWithErrno (MCStringRef p_native_path, int p_errno);
34+
bool __MCSFileThrowWriteErrorWithErrno (MCStringRef p_native_path, int p_errno);
35+
bool __MCSFileThrowOpenErrorWithErrno (MCStringRef p_native_path, int p_errno);
36+
bool __MCSFileThrowInvalidPathError (MCStringRef p_path);
37+
38+
#endif
39+
40+
/* ================================================================
41+
* Path manipulation
42+
* ================================================================ */
43+
44+
#ifdef __MCS_INTERNAL_API__
45+
46+
bool __MCSFilePathToNative (MCStringRef p_path, MCStringRef & r_native_path);
47+
bool __MCSFilePathFromNative (MCStringRef p_native_path, MCStringRef & r_path);
48+
49+
#endif
50+
51+
/* ================================================================
52+
* Whole-file IO
53+
* ================================================================ */
54+
55+
/* Read an entire file into allocated memory, with good error checking. */
56+
MC_DLLEXPORT bool MCSFileGetContents(MCStringRef p_filename, MCDataRef & r_data);
57+
58+
/* Write all of p_data to a file called p_filename, with good error
59+
* checking. If a file called p_filename already exists it will be
60+
* overwritten.
61+
*
62+
* The data is first written to a temporary file which is then renamed
63+
* to the final name. On some systems, the write will therefore be
64+
* atomic in some sense. Note that:
65+
*
66+
* 1) On POSIX systems, if p_filename already exists hard links to
67+
* p_filename will break. Also, existing permissions, access
68+
* control lists, metadata etc. may be lost. If p_filename is a
69+
* symbolic link, the link itself will be replaced, not the linked
70+
* file.
71+
*
72+
* 2) On Windows it isn't possible to rename over an existing file.
73+
* There will therefore be a race condition between the existing
74+
* file being removed and the temporary file being moved into
75+
* place.
76+
*
77+
* 3) On Windows, this function will fail if p_filename already exists
78+
* and is open.
79+
*/
80+
MC_DLLEXPORT bool MCSFileSetContents(MCStringRef p_filename, MCDataRef p_data);
81+
82+
#ifdef __MCS_INTERNAL_API__
83+
84+
bool __MCSFileGetContents (MCStringRef p_native_path, MCDataRef & r_data);
85+
bool __MCSFileSetContents (MCStringRef p_native_path, MCDataRef p_data);
86+
87+
#endif
88+
89+
/* ================================================================
90+
* File streams
91+
* ================================================================ */
92+
93+
enum MCSFileOpenMode
94+
{
95+
kMCSFileOpenModeRead = (1 << 0),
96+
kMCSFileOpenModeWrite = (1 << 1),
97+
kMCSFileOpenModeAppend = (1 << 2),
98+
kMCSFileOpenModeCreate = (1 << 3), /* Force creation of file */
99+
100+
kMCSFileOpenModeUpdate = (kMCSFileOpenModeRead | kMCSFileOpenModeWrite),
101+
};
102+
103+
MC_DLLEXPORT bool MCSFileCreateStream(MCStringRef p_filename, intenum_t p_mode, MCStreamRef& r_stream);
104+
105+
#ifdef __MCS_INTERNAL_API__
106+
107+
bool __MCSFileCreateStream (MCStringRef p_native_path, intenum_t p_mode, MCStreamRef & r_stream);
108+
109+
#endif
110+
111+
/* ================================================================
112+
* Filesystem operations
113+
* ================================================================ */
114+
115+
/* Delete the file at path. */
116+
MC_DLLEXPORT bool MCSFileDelete (MCStringRef p_path);
117+
118+
/* Create a directory at p_path. Does not recursively create
119+
* directories. */
120+
MC_DLLEXPORT bool MCSFileCreateDirectory (MCStringRef p_path);
121+
122+
/* Delete a directory at p_path. The directory must be empty. */
123+
MC_DLLEXPORT bool MCSFileDeleteDirectory (MCStringRef p_path);
124+
125+
/* Return a list of the entries in the directory at p_path. The
126+
* returned list never includes "." and "..". */
127+
MC_DLLEXPORT bool MCSFileGetDirectoryEntries (MCStringRef p_path, MCProperListRef & r_entries);
128+
129+
#ifdef __MCS_INTERNAL_API__
130+
131+
bool __MCSFileDelete (MCStringRef p_native_path);
132+
bool __MCSFileCreateDirectory (MCStringRef p_native_path);
133+
bool __MCSFileDeleteDirectory (MCStringRef p_native_path);
134+
bool __MCSFileGetDirectoryEntries (MCStringRef p_native_path, MCProperListRef & r_entries);
135+
136+
#endif
137+
138+
/* ================================================================
139+
* File API initialization
140+
* ================================================================ */
141+
142+
#ifdef __MCS_INTERNAL_API__
143+
144+
bool __MCSFileInitialize (void);
145+
void __MCSFileFinalize (void);
146+
147+
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* -*-c++-*-
2+
Copyright (C) 2015 Runtime Revolution Ltd.
3+
4+
This file is part of LiveCode.
5+
6+
LiveCode is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License v3 as published by the Free
8+
Software Foundation.
9+
10+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
17+
18+
#if !defined(__MCS_SYSTEM_H_INSIDE__)
19+
# error "Only <foundation-system.h> can be included directly"
20+
#endif
21+
22+
/* ================================================================
23+
* C stdio-based streams
24+
* ================================================================ */
25+
26+
// Standard streams
27+
MC_DLLEXPORT bool MCSStreamGetStandardOutput(MCStreamRef & r_stdout);
28+
MC_DLLEXPORT bool MCSStreamGetStandardInput(MCStreamRef & r_stdin);
29+
MC_DLLEXPORT bool MCSStreamGetStandardError(MCStreamRef & r_stderr);
30+
31+
#ifdef __MCS_INTERNAL_API__
32+
33+
bool __MCSStreamCreateWithStdio (FILE *, MCStreamRef & r_stream);
34+
35+
#endif
36+
37+
/* ================================================================
38+
* Initialization
39+
* ================================================================ */
40+
41+
#ifdef __MCS_INTERNAL_API__
42+
43+
bool __MCSStreamInitialize (void);
44+
void __MCSStreamFinalize (void);
45+
46+
#endif

libfoundation/src/foundation-core.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,11 @@ bool MCInitialize(void)
7777
if (!__MCStreamInitialize())
7878
return false;
7979

80-
if (!__MCStdioStreamInitialize())
81-
return false;
82-
83-
if (!__MCFileInitialize())
84-
return false;
85-
8680
return true;
8781
}
8882

8983
void MCFinalize(void)
9084
{
91-
__MCFileFinalize();
92-
__MCStdioStreamFinalize();
9385
__MCStreamFinalize();
9486
__MCProperListFinalize();
9587
__MCLocaleFinalize();

0 commit comments

Comments
 (0)