deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / Files / File.sc
blobf63e5aa8a81201ae5854af7aad65eb4c001fe621
1 File : UnixFILE {
3         classvar <openDialogs;
5         *new { arg pathName, mode;
6                 ^super.new.open(pathName, mode);
7         }
8         *open { arg pathName, mode;
9                 ^super.new.open(pathName, mode);
10         }
11         *use { arg pathName, mode, function;
12                 var file;
13                 file = this.new(pathName, mode);
14                 ^{ function.value(file) }.protect({ file.close });
15         }
16         *delete { arg pathName;
17                 _FileDelete
18                 ^this.primitiveFailed
19         }
20         *mtime { arg pathName;
21                 _FileMTime
22                 ^this.primitiveFailed
23         }
24         *exists { arg pathName;
25                 _FileExists
26                 ^this.primitiveFailed
27         }
28         *realpath { arg pathName;
29                 _FileRealPath
30                 ^this.primitiveFailed
31         }
32         *mkdir { arg pathName;
33                 _FileMkDir
34                 ^this.primitiveFailed
35         }
36         *copy { arg pathNameFrom, pathNameTo;
37                 _FileCopy
38                 ^this.primitiveFailed
39         }
40         *type { arg pathName;
41                 var sym = #[error, not_found, regular, directory, symlink, block, character, fifo, socket, unknown];
42                 ^sym.clipAt(this.prType(pathName))
43         }
44         *prType { arg pathName;
45                 _FileType
46                 ^this.primitiveFailed
47         }
48         *fileSize { arg pathName;
49                 _FileSize
50                 ^this.primitiveFailed
51         }
53         *getcwd {
54                 var string;
55                 this.prGetcwd(string = String.new(256));
56                 ^string
57         }
58         open { arg pathName, mode;
59                 /* open the file. mode is a string passed
60                         to fopen, so should be one of:
61                         "r","w","a","rb","wb","ab","r+","w+","a+",
62                         "rb+","wb+","ab+"
63                 */
64                 if (this.prOpen(pathName, mode), {
65                         this.addOpenFile;
66                 });
67         }
68         close { // close the file
69                 // the GC will not call this for you
70                 this.prClose;
71                 fileptr = nil;
72                 openFiles.remove(this);
73         }
74         length { // returns the length of the file
75                 _FileLength;
76                 ^this.primitiveFailed;
77         }
78         pos { // current file position
79                 _FilePos
80                 ^this.primitiveFailed;
81         }
82         pos_ { arg toPos;
83                 toPos = toPos.clip(0, this.length - 1);
84                 this.seek(toPos, 0);
85         }
86         seek { arg offset = 0, origin = 0;
87                 // origin is an integer, one of:
88                 // 0 - from beginning of file
89                 // 1 - from current position
90                 // 2 - from end of file
92                 _FileSeek
93                 ^this.primitiveFailed;
94         }
96         readAllString {
97                 var string;
98                 string = String.newClear(this.length);
99                 this.read(string);
100                 ^string
101         }
102         readAllStringRTF {
103                 ^this.readAllString.stripRTF;
104         }
105         readAllStringHTML {
106                 ^this.readAllString.stripHTML;
107         }
108         readAllSignal {
109                 var signal;
110                 signal = Signal.newClear(this.length);
111                 this.read(signal);
112                 ^signal
113         }
115         // PRIVATE
116         prOpen { arg pathName, mode;
117                 /* open the file. mode is a string passed
118                         to fopen, so should be one of:
119                         "r","w","a","rb","wb","ab","r+","w+","a+",
120                         "rb+","wb+","ab+"
121                 */
122                 _FileOpen
123                 ^this.primitiveFailed;
124         }
125         prClose {
126                 _FileClose
127                 ^this.primitiveFailed;
128         }
130         *prGetcwd { arg string;
131                 _File_getcwd
132                 ^this.primitiveFailed;
133         }
137 Pipe : UnixFILE {
138         // pipe stdin to, or stdout from, a unix shell command.
139         *new { arg commandLine, mode;
140                 ^super.new.open(commandLine, mode);
141         }
142         open { arg commandLine, mode;
143                 /* open the file. mode is a string passed
144                         to popen, so should be one of:
145                         "r","w"
146                 */
147                 if (this.prOpen(commandLine, mode), {
148                         this.addOpenFile;
149                 });
150         }
152         close {
153                 var res = this.prClose;
154                 fileptr = nil;
155                 openFiles.remove(this);
156                 ^res;
157         }
159         prClose { // close the file
160                 // the GC will not call this for you
161                 _PipeClose
162                 ^this.primitiveFailed;
163         }
166         // PRIVATE
167         prOpen { arg pathName, mode;
168                 /* open the file. mode is a string passed
169                         to popen, so should be one of:
170                         "r","w"
171                 */
172                 _PipeOpen
173                 ^this.primitiveFailed;
174         }