2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 Primitives for File i/o.
28 #include "PyrKernel.h"
29 #include "PyrPrimitive.h"
30 #include "PyrSymbol.h"
31 #include "PyrFilePrim.h"
32 #include "PyrFileUtils.h"
33 #include "ReadWriteMacros.h"
35 #include "SC_DirUtils.h"
42 #include <TextUtils.h>
43 #include <Navigation.h>
51 # define strcasecmp stricmp
56 #include "SC_Win32Utils.h"
57 #include "SC_DirUtils.h"
63 #include <boost/filesystem.hpp>
65 #if defined(__APPLE__) || defined(SC_IPHONE)
66 #ifndef _SC_StandAloneInfo_
67 # include "SC_StandAloneInfo_Darwin.h"
69 # include <CoreFoundation/CFString.h>
70 # include <CoreFoundation/CFBundle.h>
72 # include <CoreServices/CoreServices.h>
78 bool filelen(FILE *file
, size_t *length
);
80 int prFileDelete(struct VMGlobals
*g
, int numArgsPushed
)
82 PyrSlot
*a
= g
->sp
- 1, *b
= g
->sp
;
83 char filename
[PATH_MAX
];
85 int error
= slotStrVal(b
, filename
, PATH_MAX
);
89 int err
= unlink(filename
);
95 int prFileMTime(struct VMGlobals
* g
, int numArgsPushed
)
97 PyrSlot
*a
= g
->sp
- 1, *b
= g
->sp
;
98 char filename
[PATH_MAX
];
100 int error
= slotStrVal(b
, filename
, PATH_MAX
);
101 if (error
!= errNone
)
104 time_t mtime
= boost::filesystem::last_write_time(filename
);
109 int prFileExists(struct VMGlobals
* g
, int numArgsPushed
)
111 PyrSlot
*a
= g
->sp
- 1, *b
= g
->sp
;
112 char filename
[PATH_MAX
];
114 int error
= slotStrVal(b
, filename
, PATH_MAX
);
115 if (error
!= errNone
)
118 bool res
= boost::filesystem::exists(filename
);
123 int prFileRealPath(struct VMGlobals
* g
, int numArgsPushed
)
125 PyrSlot
*a
= g
->sp
- 1, *b
= g
->sp
;
126 char ipath
[PATH_MAX
];
127 char opath
[PATH_MAX
];
130 err
= slotStrVal(b
, ipath
, PATH_MAX
);
133 bool isAlias
= false;
134 if(sc_ResolveIfAlias(ipath
, opath
, isAlias
, PATH_MAX
)!=0) {
138 boost::system::error_code error_code
;
139 boost::filesystem::path p
= boost::filesystem::canonical(opath
,error_code
);
144 strcpy(opath
,p
.string().c_str());
147 CFStringRef cfstring
=
148 CFStringCreateWithCString(NULL
,
150 kCFStringEncodingUTF8
);
151 err
= !CFStringGetFileSystemRepresentation(cfstring
, opath
, PATH_MAX
);
153 if (err
) return errFailed
;
156 PyrString
* pyrString
= newPyrString(g
->gc
, opath
, 0, true);
157 SetObject(a
, pyrString
);
162 int prFileMkDir(struct VMGlobals
* g
, int numArgsPushed
)
164 PyrSlot
*a
= g
->sp
- 1, *b
= g
->sp
;
165 char filename
[PATH_MAX
];
167 int error
= slotStrVal(b
, filename
, PATH_MAX
);
168 if (error
!= errNone
)
171 boost::system::error_code error_code
;
172 boost::filesystem::create_directories(filename
, error_code
);
174 postfl("Warning: %s (\"%s\")\n", error_code
.message().c_str(), filename
);
179 int prFileCopy(struct VMGlobals
* g
, int numArgsPushed
)
181 PyrSlot
*a
= g
->sp
- 2, *b
= g
->sp
- 1, *c
= g
->sp
;
182 char filename1
[PATH_MAX
];
183 char filename2
[PATH_MAX
];
185 error
= slotStrVal(b
, filename1
, PATH_MAX
);
186 if (error
!= errNone
)
188 error
= slotStrVal(c
, filename2
, PATH_MAX
);
189 if (error
!= errNone
)
192 boost::filesystem3::copy(filename1
, filename2
);
196 int prFileType(struct VMGlobals
* g
, int numArgsPushed
)
198 PyrSlot
*a
= g
->sp
- 1, *b
= g
->sp
;
199 char filename
[PATH_MAX
];
201 int error
= slotStrVal(b
, filename
, PATH_MAX
);
202 if (error
!= errNone
)
205 boost::filesystem::file_status
s(boost::filesystem::symlink_status(filename
));
210 int prFileSize(struct VMGlobals
* g
, int numArgsPushed
)
212 PyrSlot
*a
= g
->sp
- 1, *b
= g
->sp
;
213 char filename
[PATH_MAX
];
215 int error
= slotStrVal(b
, filename
, PATH_MAX
);
216 if (error
!= errNone
)
219 uintmax_t sz
= boost::filesystem::file_size(filename
);
225 int prFileOpen(struct VMGlobals
*g
, int numArgsPushed
)
228 char filename
[PATH_MAX
];
236 if (NotObj(c
) || !isKindOf(slotRawObject(c
), class_string
)
237 || NotObj(b
) || !isKindOf(slotRawObject(b
), class_string
))
239 if (slotRawObject(b
)->size
> PATH_MAX
- 1) return errFailed
;
240 if (slotRawObject(c
)->size
> 11) return errFailed
;
241 pfile
= (PyrFile
*)slotRawObject(a
);
243 memcpy(filename
, slotRawString(b
)->s
, slotRawObject(b
)->size
);
244 filename
[slotRawString(b
)->size
] = 0;
246 memcpy(mode
, slotRawString(c
)->s
, slotRawObject(c
)->size
);
247 mode
[slotRawString(c
)->size
] = 0;
250 win32_ReplaceCharInString(filename
,PATH_MAX
,'/','\\');
251 if(strcmp(mode
,"w") == 0)
253 if(strcmp(mode
,"r") == 0)
257 file
= fopen(filename
, mode
);
259 SetPtr(&pfile
->fileptr
, file
);
263 // check if directory exisits
264 // create a temporary file (somewhere) for a handle
265 // the file is deleted automatically when closed
266 if (sc_DirectoryExists(filename
)) {
269 err
= tmpfile_s(&file
);
271 SetPtr(&pfile
->fileptr
, file
);
275 #elif defined(__MINGW32__)
278 SetPtr(&pfile
->fileptr
, file
);
283 #error compiler unsupported
293 int prFileClose(struct VMGlobals
*g
, int numArgsPushed
)
300 pfile
= (PyrFile
*)slotRawObject(a
);
301 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
302 if (file
== NULL
) return errNone
;
303 SetPtr(&pfile
->fileptr
, NULL
);
304 if (fclose(file
)) return errFailed
;
308 int prFileFlush(struct VMGlobals
*g
, int numArgsPushed
)
315 pfile
= (PyrFile
*)slotRawObject(a
);
316 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
317 if (file
!= NULL
) fflush(file
);
321 int prFilePos(struct VMGlobals
*g
, int numArgsPushed
)
330 pfile
= (PyrFile
*)slotRawObject(a
);
331 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
332 if (file
== NULL
) return errFailed
;
333 if (fgetpos(file
, &pos
)) return errFailed
;
346 int prFileLength(struct VMGlobals
*g
, int numArgsPushed
)
355 pfile
= (PyrFile
*)slotRawObject(a
);
356 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
357 if (file
== NULL
) return errFailed
;
358 // preserve file position
359 if (fgetpos(file
, &pos
)) return errFailed
;
360 if (filelen(file
, &length
)) return errFailed
;
361 if (fsetpos(file
, &pos
)) return errFailed
;
367 int prFileSeek(struct VMGlobals
*g
, int numArgsPushed
)
374 static int originTable
[3] = { SEEK_SET
, SEEK_CUR
, SEEK_END
};
379 if (NotInt(b
)) return errWrongType
;
380 if (NotInt(c
)) return errWrongType
;
381 pfile
= (PyrFile
*)slotRawObject(a
);
382 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
383 if (file
== NULL
) return errFailed
;
384 offset
= slotRawInt(b
);
385 origin
= slotRawInt(c
);
386 if (origin
< 0 || origin
> 2) return errIndexOutOfRange
;
387 origin
= originTable
[origin
]; // translate in case ANSI constants ever change..
388 if (fseek(file
, offset
, origin
)) return errFailed
;
393 int prFileWrite(struct VMGlobals
*g
, int numArgsPushed
)
395 PyrSlot
*a
, *b
, *ptr
;
403 pfile
= (PyrFile
*)slotRawObject(a
);
404 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
405 if (file
== NULL
) return errFailed
;
409 SC_IOStream
<FILE*> scio(file
);
410 scio
.writeInt32_be(slotRawInt(b
));
414 fwrite(slotRawSymbol(b
)->name
, sizeof(char), slotRawSymbol(b
)->length
, file
);
417 chr
= slotRawChar(b
);
418 fwrite(&chr
, sizeof(char), 1, file
);
427 // writes the indexable part of any non obj_slot format object
428 obj
= slotRawObject(b
);
429 if (!isKindOf(obj
, class_rawarray
)
430 || isKindOf(obj
, class_symbolarray
)) return errWrongType
;
433 int elemSize
= gFormatElemSize
[obj
->obj_format
];
434 int numElems
= obj
->size
;
435 #if BYTE_ORDER != BIG_ENDIAN
438 fwrite(ptr
, elemSize
, numElems
, file
);
442 char *ptr
= slotRawString(b
)->s
;
443 char *ptrend
= ptr
+ numElems
*2;
444 for (; ptr
< ptrend
; ptr
+=2) {
452 char *ptr
= slotRawString(b
)->s
;
453 char *ptrend
= ptr
+ numElems
*4;
454 for (; ptr
< ptrend
; ptr
+=4) {
464 char *ptr
= slotRawString(b
)->s
;
465 char *ptrend
= ptr
+ numElems
*8;
466 for (; ptr
< ptrend
; ptr
+=8) {
480 fwrite(ptr
, elemSize
, numElems
, file
);
487 SC_IOStream
<FILE*> scio(file
);
488 scio
.writeDouble_be(slotRawFloat(b
));
496 int prFileWriteLE(struct VMGlobals
*g
, int numArgsPushed
)
498 PyrSlot
*a
, *b
, *ptr
;
506 pfile
= (PyrFile
*)slotRawObject(a
);
507 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
508 if (file
== NULL
) return errFailed
;
512 SC_IOStream
<FILE*> scio(file
);
513 scio
.writeInt32_le(slotRawInt(b
));
517 fwrite(slotRawSymbol(b
)->name
, sizeof(char), slotRawSymbol(b
)->length
, file
);
521 fwrite(&chr
, sizeof(char), 1, file
);
530 // writes the indexable part of any non obj_slot format object
531 obj
= slotRawObject(b
);
532 if (!isKindOf(obj
, class_rawarray
)
533 || isKindOf(obj
, class_symbolarray
)) return errWrongType
;
536 int elemSize
= gFormatElemSize
[obj
->obj_format
];
537 int numElems
= obj
->size
;
538 #if BYTE_ORDER == BIG_ENDIAN
541 fwrite(ptr
, elemSize
, numElems
, file
);
545 char *ptr
= slotRawString(b
)->s
;
546 char *ptrend
= ptr
+ numElems
*2;
547 for (; ptr
< ptrend
; ptr
+=2) {
555 char *ptr
= slotRawString(b
)->s
;
556 char *ptrend
= ptr
+ numElems
*4;
557 for (; ptr
< ptrend
; ptr
+=4) {
567 char *ptr
= slotRawString(b
)->s
;
568 char *ptrend
= ptr
+ numElems
*8;
569 for (; ptr
< ptrend
; ptr
+=8) {
583 fwrite(ptr
, elemSize
, numElems
, file
);
590 SC_IOStream
<FILE*> scio(file
);
591 scio
.writeDouble_le(slotRawFloat(b
));
598 int prFileReadLine(struct VMGlobals
*g
, int numArgsPushed
)
600 PyrSlot
*a
, *b
; // receiver(a File), string
607 pfile
= (PyrFile
*)slotRawObject(a
);
608 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
609 if (file
== NULL
) return errFailed
;
611 char* result
= fgets(slotRawString(b
)->s
, MAXINDEXSIZE(slotRawObject(b
)) - 1, file
);
615 slotRawString(b
)->size
= strlen(slotRawString(b
)->s
);
616 if (slotRawString(b
)->s
[slotRawString(b
)->size
-1] == '\n') slotRawString(b
)->size
--;
622 int prFilePutInt32(struct VMGlobals
*g
, int numArgsPushed
)
631 pfile
= (PyrFile
*)slotRawObject(a
);
632 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
633 if (file
== NULL
) return errFailed
;
636 int err
= slotIntVal(b
, &val
);
639 SC_IOStream
<FILE*> scio(file
);
640 scio
.writeInt32_be(val
);
645 int prFilePutInt16(struct VMGlobals
*g
, int numArgsPushed
)
654 pfile
= (PyrFile
*)slotRawObject(a
);
655 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
656 if (file
== NULL
) return errFailed
;
659 int err
= slotIntVal(b
, &val
);
663 SC_IOStream
<FILE*> scio(file
);
664 scio
.writeInt16_be(val
);
670 int prFilePutInt32LE(struct VMGlobals
*g
, int numArgsPushed
)
679 pfile
= (PyrFile
*)slotRawObject(a
);
680 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
681 if (file
== NULL
) return errFailed
;
684 int err
= slotIntVal(b
, &val
);
687 SC_IOStream
<FILE*> scio(file
);
688 scio
.writeInt32_le(val
);
693 int prFilePutInt16LE(struct VMGlobals
*g
, int numArgsPushed
)
702 pfile
= (PyrFile
*)slotRawObject(a
);
703 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
704 if (file
== NULL
) return errFailed
;
707 int err
= slotIntVal(b
, &val
);
711 SC_IOStream
<FILE*> scio(file
);
712 scio
.writeInt16_le(val
);
717 int prFilePutInt8(struct VMGlobals
*g
, int numArgsPushed
)
726 pfile
= (PyrFile
*)slotRawObject(a
);
727 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
728 if (file
== NULL
) return errFailed
;
731 int err
= slotIntVal(b
, &val
);
735 SC_IOStream
<FILE*> scio(file
);
741 int prFilePutChar(struct VMGlobals
*g
, int numArgsPushed
)
751 pfile
= (PyrFile
*)slotRawObject(a
);
752 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
753 if (file
== NULL
) return errFailed
;
754 if (NotChar(b
)) return errWrongType
;
758 SC_IOStream
<FILE*> scio(file
);
764 int prFilePutFloat(struct VMGlobals
*g
, int numArgsPushed
)
773 pfile
= (PyrFile
*)slotRawObject(a
);
774 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
781 int err
= slotFloatVal(b
, &val
);
784 SC_IOStream
<FILE*> scio(file
);
785 scio
.writeFloat_be(val
);
790 int prFilePutDouble(struct VMGlobals
*g
, int numArgsPushed
)
799 pfile
= (PyrFile
*)slotRawObject(a
);
800 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
801 if (file
== NULL
) return errFailed
;
805 int err
= slotDoubleVal(b
, &val
);
808 SC_IOStream
<FILE*> scio(file
);
809 scio
.writeDouble_be(val
);
815 int prFilePutFloatLE(struct VMGlobals
*g
, int numArgsPushed
)
824 pfile
= (PyrFile
*)slotRawObject(a
);
825 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
832 int err
= slotFloatVal(b
, &val
);
835 SC_IOStream
<FILE*> scio(file
);
836 scio
.writeFloat_le(val
);
841 int prFilePutDoubleLE(struct VMGlobals
*g
, int numArgsPushed
)
850 pfile
= (PyrFile
*)slotRawObject(a
);
851 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
852 if (file
== NULL
) return errFailed
;
856 int err
= slotDoubleVal(b
, &val
);
859 SC_IOStream
<FILE*> scio(file
);
860 scio
.writeDouble_le(val
);
865 int prFilePutString(struct VMGlobals
*g
, int numArgsPushed
)
874 pfile
= (PyrFile
*)slotRawObject(a
);
875 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
876 if (file
== NULL
) return errFailed
;
877 if (NotObj(b
) || slotRawObject(b
)->classptr
!= class_string
) return errWrongType
;
878 string
= slotRawString(b
);
880 fwrite(string
->s
, 1, string
->size
, file
);
886 int prFileGetDouble(struct VMGlobals
*g
, int numArgsPushed
)
894 pfile
= (PyrFile
*)slotRawObject(a
);
895 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
896 if (file
== NULL
) return errFailed
;
898 if (feof(file
)) SetNil(a
);
900 SC_IOStream
<FILE*> scio(file
);
901 SetFloat(a
, scio
.readDouble_be());
906 int prFileGetFloat(struct VMGlobals
*g
, int numArgsPushed
)
914 pfile
= (PyrFile
*)slotRawObject(a
);
915 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
916 if (file
== NULL
) return errFailed
;
918 if (feof(file
)) SetNil(a
);
920 SC_IOStream
<FILE*> scio(file
);
921 SetFloat(a
, scio
.readFloat_be());
927 int prFileGetDoubleLE(struct VMGlobals
*g
, int numArgsPushed
)
935 pfile
= (PyrFile
*)slotRawObject(a
);
936 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
937 if (file
== NULL
) return errFailed
;
939 if (feof(file
)) SetNil(a
);
941 SC_IOStream
<FILE*> scio(file
);
942 SetFloat(a
, scio
.readDouble_le());
947 int prFileGetFloatLE(struct VMGlobals
*g
, int numArgsPushed
)
955 pfile
= (PyrFile
*)slotRawObject(a
);
956 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
957 if (file
== NULL
) return errFailed
;
959 if (feof(file
)) SetNil(a
);
961 SC_IOStream
<FILE*> scio(file
);
962 SetFloat(a
, scio
.readFloat_le());
967 int prFileGetChar(struct VMGlobals
*g
, int numArgsPushed
)
976 pfile
= (PyrFile
*)slotRawObject(a
);
977 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
978 if (file
== NULL
) return errFailed
;
980 int count
= fread(&z
, sizeof(char), 1, file
);
981 if (count
==0) SetNil(a
);
986 int prFileGetInt8(struct VMGlobals
*g
, int numArgsPushed
)
995 pfile
= (PyrFile
*)slotRawObject(a
);
996 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
997 if (file
== NULL
) return errFailed
;
999 int count
= fread(&z
, sizeof(char), 1, file
);
1000 if (count
==0) SetNil(a
);
1005 int prFileGetInt16(struct VMGlobals
*g
, int numArgsPushed
)
1013 pfile
= (PyrFile
*)slotRawObject(a
);
1014 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
1015 if (file
== NULL
) return errFailed
;
1017 if (feof(file
)) SetNil(a
);
1019 SC_IOStream
<FILE*> scio(file
);
1020 SetInt(a
, scio
.readInt16_be());
1025 int prFileGetInt32(struct VMGlobals
*g
, int numArgsPushed
)
1033 pfile
= (PyrFile
*)slotRawObject(a
);
1034 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
1038 if (feof(file
)) SetNil(a
);
1040 SC_IOStream
<FILE*> scio(file
);
1041 SetInt(a
, scio
.readInt32_be());
1047 int prFileGetInt16LE(struct VMGlobals
*g
, int numArgsPushed
)
1055 pfile
= (PyrFile
*)slotRawObject(a
);
1056 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
1057 if (file
== NULL
) return errFailed
;
1059 if (feof(file
)) SetNil(a
);
1061 SC_IOStream
<FILE*> scio(file
);
1062 SetInt(a
, scio
.readInt16_le());
1067 int prFileGetInt32LE(struct VMGlobals
*g
, int numArgsPushed
)
1075 pfile
= (PyrFile
*)slotRawObject(a
);
1076 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
1077 if (file
== NULL
) return errFailed
;
1079 if (feof(file
)) SetNil(a
);
1081 SC_IOStream
<FILE*> scio(file
);
1082 SetInt(a
, scio
.readInt32_le());
1087 int prFileReadRaw(struct VMGlobals
*g
, int numArgsPushed
)
1092 PyrSlot
* a
= g
->sp
- 1;
1095 if (!isKindOfSlot(b
, class_rawarray
)
1096 || isKindOfSlot(b
, class_symbolarray
)) return errWrongType
;
1098 pfile
= (PyrFile
*)slotRawObject(a
);
1099 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
1100 if (file
== NULL
) return errFailed
;
1102 int elemSize
= gFormatElemSize
[slotRawObject(b
)->obj_format
];
1103 int numElems
= slotRawObject(b
)->size
;
1104 numElems
= fread(slotRawString(b
)->s
, elemSize
, numElems
, file
);
1105 slotRawObject(b
)->size
= numElems
;
1107 #if BYTE_ORDER != BIG_ENDIAN
1113 char *ptr
= slotRawString(b
)->s
;
1114 char *ptrend
= ptr
+ numElems
*2;
1115 for (; ptr
< ptrend
; ptr
+=2) {
1124 char *ptr
= slotRawString(b
)->s
;
1125 char *ptrend
= ptr
+ numElems
*4;
1126 for (; ptr
< ptrend
; ptr
+=4) {
1139 char *ptr
= slotRawString(b
)->s
;
1140 char *ptrend
= ptr
+ numElems
*8;
1141 for (; ptr
< ptrend
; ptr
+=8) {
1163 if (slotRawObject(b
)->size
==0) SetNil(a
);
1168 int prFileReadRawLE(struct VMGlobals
*g
, int numArgsPushed
)
1173 PyrSlot
* a
= g
->sp
- 1;
1176 if (!isKindOfSlot(b
, class_rawarray
)
1177 || isKindOfSlot(b
, class_symbolarray
)) return errWrongType
;
1179 pfile
= (PyrFile
*)slotRawObject(a
);
1180 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
1181 if (file
== NULL
) return errFailed
;
1183 int elemSize
= gFormatElemSize
[slotRawObject(b
)->obj_format
];
1184 int numElems
= slotRawObject(b
)->size
;
1185 numElems
= fread(slotRawString(b
)->s
, elemSize
, numElems
, file
);
1186 slotRawObject(b
)->size
= numElems
;
1188 #if BYTE_ORDER == BIG_ENDIAN
1194 char *ptr
= slotRawString(b
)->s
;
1195 char *ptrend
= ptr
+ numElems
*2;
1196 for (; ptr
< ptrend
; ptr
+=2) {
1205 char *ptr
= slotRawString(b
)->s
;
1206 char *ptrend
= ptr
+ numElems
*4;
1207 for (; ptr
< ptrend
; ptr
+=4) {
1220 char *ptr
= slotRawString(b
)->s
;
1221 char *ptrend
= ptr
+ numElems
*8;
1222 for (; ptr
< ptrend
; ptr
+=8) {
1244 if (slotRawObject(b
)->size
==0) SetNil(a
);
1249 int prFileGetcwd(struct VMGlobals
*g
, int numArgsPushed
)
1251 //PyrSlot* a = g->sp - 1; // File
1252 PyrSlot
* string
= g
->sp
;
1254 if (!isKindOfSlot(string
, class_string
)) return errWrongType
;
1256 char * cwd
= getcwd(slotRawString(string
)->s
,255);
1258 error(strerror(errno
));
1261 slotRawString(string
)->size
= strlen(slotRawString(string
)->s
);
1269 int prPipeOpen(struct VMGlobals
*g
, int numArgsPushed
)
1280 if (NotObj(c
) || !isKindOf(slotRawObject(c
), class_string
)
1281 || NotObj(b
) || !isKindOf(slotRawObject(b
), class_string
))
1282 return errWrongType
;
1283 if (slotRawObject(c
)->size
> 11) return errFailed
;
1284 pfile
= (PyrFile
*)slotRawObject(a
);
1286 char *commandLine
= (char*)malloc(slotRawObject(b
)->size
+ 1);
1287 memcpy(commandLine
, slotRawString(b
)->s
, slotRawObject(b
)->size
);
1288 commandLine
[slotRawString(b
)->size
] = 0;
1290 memcpy(mode
, slotRawString(c
)->s
, slotRawObject(c
)->size
);
1291 mode
[slotRawString(c
)->size
] = 0;
1293 file
= popen(commandLine
, mode
);
1296 SetPtr(&pfile
->fileptr
, file
);
1305 int prPipeClose(struct VMGlobals
*g
, int numArgsPushed
)
1312 pfile
= (PyrFile
*)slotRawObject(a
);
1313 file
= (FILE*)slotRawPtr(&pfile
->fileptr
);
1314 if (file
== NULL
) return errNone
;
1315 SetPtr(&pfile
->fileptr
, NULL
);
1316 int perr
= pclose(file
);
1326 #ifndef NO_LIBSNDFILE
1329 #include <sndfile-win.h>
1331 #include <sndfile.h>
1335 int sampleFormatToString(struct SF_INFO
*info
, const char **string
);
1336 int sampleFormatToString(struct SF_INFO
*info
, const char **string
)
1338 unsigned int format
= info
->format
& SF_FORMAT_SUBMASK
;
1341 case SF_FORMAT_DPCM_8
:
1342 case SF_FORMAT_PCM_S8
:
1345 case SF_FORMAT_DPCM_16
:
1346 case SF_FORMAT_PCM_16
:
1347 case SF_FORMAT_DWVW_16
:
1350 case SF_FORMAT_PCM_24
:
1351 case SF_FORMAT_DWVW_24
:
1354 case SF_FORMAT_PCM_32
:
1357 case SF_FORMAT_FLOAT
:
1360 case SF_FORMAT_DOUBLE
:
1363 case SF_FORMAT_ULAW
:
1366 case SF_FORMAT_ALAW
:
1377 int headerFormatToString(struct SF_INFO
*info
, const char **string
);
1378 int headerFormatToString(struct SF_INFO
*info
, const char **string
){
1379 switch (info
->format
& SF_FORMAT_TYPEMASK
)
1381 case SF_FORMAT_WAV
:
1384 case SF_FORMAT_AIFF
:
1390 case SF_FORMAT_IRCAM
:
1393 case SF_FORMAT_RAW
:
1396 case SF_FORMAT_W64
:
1399 case SF_FORMAT_FLAC
:
1402 // TODO allow other platforms to know vorbis once libsndfile 1.0.18 is established
1403 #if SC_DARWIN || SC_WIN32 || LIBSNDFILE_1018
1404 case SF_FORMAT_VORBIS
:
1409 case SF_FORMAT_PAF :
1413 case SF_FORMAT_SVX :
1417 case SF_FORMAT_NIST :
1421 case SF_FORMAT_VOC :
1425 case SF_FORMAT_MAT4 :
1429 case SF_FORMAT_MAT5 :
1433 case SF_FORMAT_PVF :
1441 case SF_FORMAT_HTK :
1445 case SF_FORMAT_SDS :
1456 int sndfileFormatInfoToStrings(struct SF_INFO
*info
, const char **stringHead
, const char **stringSample
);
1457 int sndfileFormatInfoToStrings(struct SF_INFO
*info
, const char **stringHead
, const char **stringSample
)
1460 error
= headerFormatToString(info
, stringHead
);
1461 error
= sampleFormatToString(info
, stringSample
);
1465 int prSFOpenRead(struct VMGlobals
*g
, int numArgsPushed
);
1466 int prSFOpenRead(struct VMGlobals
*g
, int numArgsPushed
)
1469 char filename
[PATH_MAX
];
1472 const char *headerstr
;
1473 const char *sampleformatstr
;
1478 if (!isKindOfSlot(b
, class_string
)) return errWrongType
;
1479 if (slotRawObject(b
)->size
> PATH_MAX
- 1) return errFailed
;
1481 memcpy(filename
, slotRawString(b
)->s
, slotRawObject(b
)->size
);
1482 filename
[slotRawString(b
)->size
] = 0;
1485 file
= sf_open(filename
, SFM_READ
, &info
);
1489 SetPtr(slotRawObject(a
)->slots
+ 0, file
);
1490 sndfileFormatInfoToStrings(&info
, &headerstr
, &sampleformatstr
);
1491 //headerFormatToString(&info, &headerstr);
1492 PyrString
*hpstr
= newPyrString(g
->gc
, headerstr
, 0, true);
1493 SetObject(slotRawObject(a
)->slots
+1, hpstr
);
1494 PyrString
*smpstr
= newPyrString(g
->gc
, sampleformatstr
, 0, true);
1495 SetObject(slotRawObject(a
)->slots
+2, smpstr
);
1496 SetInt(slotRawObject(a
)->slots
+ 3, info
.frames
);
1497 SetInt(slotRawObject(a
)->slots
+ 4, info
.channels
);
1498 SetInt(slotRawObject(a
)->slots
+ 5, info
.samplerate
);
1507 /// copied from SC_World.cpp:
1509 int sampleFormatFromString(const char* name
);
1510 int sampleFormatFromString(const char* name
)
1512 if (!name
) return SF_FORMAT_PCM_16
;
1514 size_t len
= strlen(name
);
1515 if (len
< 1) return 0;
1517 if (name
[0] == 'u') {
1518 if (len
< 5) return 0;
1519 if (name
[4] == '8') return SF_FORMAT_PCM_U8
; // uint8
1521 } else if (name
[0] == 'i') {
1522 if (len
< 4) return 0;
1523 if (name
[3] == '8') return SF_FORMAT_PCM_S8
; // int8
1524 else if (name
[3] == '1') return SF_FORMAT_PCM_16
; // int16
1525 else if (name
[3] == '2') return SF_FORMAT_PCM_24
; // int24
1526 else if (name
[3] == '3') return SF_FORMAT_PCM_32
; // int32
1527 } else if (name
[0] == 'f') {
1528 return SF_FORMAT_FLOAT
; // float
1529 } else if (name
[0] == 'd') {
1530 return SF_FORMAT_DOUBLE
; // double
1531 } else if (name
[0] == 'm' || name
[0] == 'u') {
1532 return SF_FORMAT_ULAW
; // mulaw ulaw
1533 } else if (name
[0] == 'a') {
1534 return SF_FORMAT_ALAW
; // alaw
1539 int headerFormatFromString(const char *name
);
1540 int headerFormatFromString(const char *name
)
1542 if (!name
) return SF_FORMAT_AIFF
;
1543 if (strcasecmp(name
, "AIFF")==0) return SF_FORMAT_AIFF
;
1544 if (strcasecmp(name
, "AIFC")==0) return SF_FORMAT_AIFF
;
1545 if (strcasecmp(name
, "RIFF")==0) return SF_FORMAT_WAV
;
1546 if (strcasecmp(name
, "WAVEX")==0) return SF_FORMAT_WAVEX
;
1547 if (strcasecmp(name
, "WAVE")==0) return SF_FORMAT_WAV
;
1548 if (strcasecmp(name
, "WAV" )==0) return SF_FORMAT_WAV
;
1549 if (strcasecmp(name
, "Sun" )==0) return SF_FORMAT_AU
;
1550 if (strcasecmp(name
, "IRCAM")==0) return SF_FORMAT_IRCAM
;
1551 if (strcasecmp(name
, "NeXT")==0) return SF_FORMAT_AU
;
1552 if (strcasecmp(name
, "raw")==0) return SF_FORMAT_RAW
;
1553 if (strcasecmp(name
, "MAT4")==0) return SF_FORMAT_MAT4
;
1554 if (strcasecmp(name
, "MAT5")==0) return SF_FORMAT_MAT5
;
1555 if (strcasecmp(name
, "PAF")==0) return SF_FORMAT_PAF
;
1556 if (strcasecmp(name
, "SVX")==0) return SF_FORMAT_SVX
;
1557 if (strcasecmp(name
, "NIST")==0) return SF_FORMAT_NIST
;
1558 if (strcasecmp(name
, "VOC")==0) return SF_FORMAT_VOC
;
1559 if (strcasecmp(name
, "W64")==0) return SF_FORMAT_W64
;
1560 if (strcasecmp(name
, "PVF")==0) return SF_FORMAT_PVF
;
1561 if (strcasecmp(name
, "XI")==0) return SF_FORMAT_XI
;
1562 if (strcasecmp(name
, "HTK")==0) return SF_FORMAT_HTK
;
1563 if (strcasecmp(name
, "SDS")==0) return SF_FORMAT_SDS
;
1564 if (strcasecmp(name
, "AVR")==0) return SF_FORMAT_AVR
;
1565 if (strcasecmp(name
, "SD2")==0) return SF_FORMAT_SD2
;
1566 if (strcasecmp(name
, "FLAC")==0) return SF_FORMAT_FLAC
;
1567 if (strcasecmp(name
, "CAF")==0) return SF_FORMAT_CAF
;
1568 // TODO allow other platforms to know vorbis once libsndfile 1.0.18 is established
1569 #if SC_DARWIN || SC_WIN32
1570 if (strcasecmp(name
, "VORBIS")==0) return SF_FORMAT_VORBIS
;
1572 if (strcasecmp(name
, "RF64")==0) return SF_FORMAT_RF64
;
1577 int sndfileFormatInfoFromStrings(struct SF_INFO
*info
, const char *headerFormatString
, const char *sampleFormatString
)
1579 int headerFormat
= headerFormatFromString(headerFormatString
);
1580 if (!headerFormat
) return errWrongType
;
1582 int sampleFormat
= sampleFormatFromString(sampleFormatString
);
1583 if (!sampleFormat
) return errWrongType
;
1585 info
->format
= (unsigned int)(headerFormat
| sampleFormat
);
1590 int prSFOpenWrite(struct VMGlobals
*g
, int numArgsPushed
);
1591 int prSFOpenWrite(struct VMGlobals
*g
, int numArgsPushed
)
1594 char filename
[PATH_MAX
];
1597 PyrSlot
*headerSlot
;
1598 PyrSlot
*formatSlot
;
1605 headerSlot
= (slotRawObject(a
)->slots
+ 1);
1606 formatSlot
= (slotRawObject(a
)->slots
+ 2);
1609 if (!isKindOfSlot(headerSlot
, class_string
)) return errWrongType
;
1610 if (!isKindOfSlot(formatSlot
, class_string
)) return errWrongType
;
1612 if (!isKindOfSlot(b
, class_string
)) return errWrongType
;
1613 if (slotRawObject(b
)->size
> PATH_MAX
- 1) return errFailed
;
1615 memcpy(filename
, slotRawString(b
)->s
, slotRawObject(b
)->size
);
1616 filename
[slotRawString(b
)->size
] = 0;
1619 char* headerFormat
= (char *)malloc(slotRawObject(headerSlot
)->size
);
1621 char headerFormat
[slotRawString(headerSlot
)->size
];
1623 memcpy(headerFormat
, slotRawString(headerSlot
)->s
, slotRawObject(headerSlot
)->size
);
1624 headerFormat
[slotRawString(headerSlot
)->size
] = 0;
1627 char* sampleFormat
= (char *)malloc(slotRawString(formatSlot
)->size
);
1629 char sampleFormat
[slotRawString(formatSlot
)->size
];
1631 memcpy(sampleFormat
, slotRawString(formatSlot
)->s
, slotRawObject(formatSlot
)->size
);
1632 sampleFormat
[slotRawString(formatSlot
)->size
] = 0;
1634 error
= sndfileFormatInfoFromStrings(&info
, headerFormat
, sampleFormat
);
1643 if(error
) return errFailed
;
1644 //slotIntVal(slotRawObject(a)->slots + 3, &info.frames);
1645 slotIntVal(slotRawObject(a
)->slots
+ 4, &info
.channels
);
1646 slotIntVal(slotRawObject(a
)->slots
+ 5, &info
.samplerate
);
1648 file
= sf_open(filename
, SFM_WRITE
, &info
);
1650 SetPtr(slotRawObject(a
)->slots
+0, file
);
1660 int prSFClose(struct VMGlobals
*g
, int numArgsPushed
);
1661 int prSFClose(struct VMGlobals
*g
, int numArgsPushed
)
1667 SNDFILE
*file
= (SNDFILE
*)slotRawPtr(&slotRawObject(a
)->slots
[0]);
1670 SetNil(slotRawObject(a
)->slots
+ 0);
1676 int prSFRead(struct VMGlobals
*g
, int numArgsPushed
);
1677 int prSFRead(struct VMGlobals
*g
, int numArgsPushed
)
1684 SNDFILE
*file
= (SNDFILE
*)slotRawPtr(&slotRawObject(a
)->slots
[0]);
1686 if (!isKindOfSlot(b
, class_rawarray
)) return errWrongType
;
1688 switch (slotRawObject(b
)->obj_format
) {
1690 slotRawObject(b
)->size
= sf_read_short(file
, (short*)slotRawInt8Array(b
)->b
, slotRawObject(b
)->size
);
1693 slotRawObject(b
)->size
= sf_read_int(file
, (int*)slotRawInt8Array(b
)->b
, slotRawObject(b
)->size
);
1696 slotRawObject(b
)->size
= sf_read_float(file
, (float*)slotRawInt8Array(b
)->b
, slotRawObject(b
)->size
);
1699 slotRawObject(b
)->size
= sf_read_double(file
, (double*)slotRawInt8Array(b
)->b
, slotRawObject(b
)->size
);
1702 error("sample format not supported.\n");
1709 int prSFWrite(struct VMGlobals
*g
, int numArgsPushed
);
1710 int prSFWrite(struct VMGlobals
*g
, int numArgsPushed
)
1717 SNDFILE
*file
= (SNDFILE
*)slotRawPtr(&slotRawObject(a
)->slots
[0]);
1719 if (!isKindOfSlot(b
, class_rawarray
)) return errWrongType
;
1721 switch (slotRawObject(b
)->obj_format
) {
1723 sf_write_short(file
, (short*)slotRawInt8Array(b
)->b
, slotRawObject(b
)->size
);
1726 sf_write_int(file
, (int*)slotRawInt8Array(b
)->b
, slotRawObject(b
)->size
);
1729 sf_write_float(file
, (float*)slotRawInt8Array(b
)->b
, slotRawObject(b
)->size
);
1732 sf_write_double(file
, (double*)slotRawInt8Array(b
)->b
, slotRawObject(b
)->size
);
1735 error("sample format not supported.\n");
1742 int prSFSeek(struct VMGlobals
*g
, int numArgsPushed
);
1743 int prSFSeek(struct VMGlobals
*g
, int numArgsPushed
)
1751 SNDFILE
*file
= (SNDFILE
*)slotRawPtr(&slotRawObject(a
)->slots
[0]);
1754 int err
= slotIntVal(b
, &offset
);
1755 if (err
) return err
;
1757 err
= slotIntVal(c
, &origin
);
1758 if (err
) return err
;
1760 sf_seek(file
, offset
, origin
);
1765 int prSFHeaderInfoString(struct VMGlobals
*g
, int numArgsPushed
);
1766 int prSFHeaderInfoString(struct VMGlobals
*g
, int numArgsPushed
)
1771 SNDFILE
*file
= (SNDFILE
*)slotRawPtr(&slotRawObject(a
)->slots
[0]);
1773 static char strbuffer
[(1 << 16)] ;
1774 sf_command (file
, SFC_GET_LOG_INFO
, strbuffer
, (1 << 16)) ;
1775 PyrString
*pstring
= newPyrString(g
->gc
, strbuffer
, 0, true);
1777 SetObject(a
, pstring
);
1783 #else // !NO_LIBSNDFILE
1785 int prSFOpenRead(struct VMGlobals
*g
, int numArgsPushed
)
1790 int prSFOpenWrite(struct VMGlobals
*g
, int numArgsPushed
)
1795 int prSFClose(struct VMGlobals
*g
, int numArgsPushed
)
1800 int prSFWrite(struct VMGlobals
*g
, int numArgsPushed
)
1805 int prSFRead(struct VMGlobals
*g
, int numArgsPushed
)
1810 int prSFSeek(struct VMGlobals
*g
, int numArgsPushed
)
1815 int prSFHeaderInfoString(struct VMGlobals
*g
, int numArgsPushed
)
1820 #endif // !NO_LIBSNDFILE
1826 int dir_Lookup(char *pathString
, int pathStringLength
, int index
,
1828 char *name
, int *nameLength
, int *creationDate
, int *modificationDate
,
1829 int *isDirectory
, int *isVisible
, int *sizeIfFile
);
1831 int prDirectory_At(struct VMGlobals
*g
, int numArgsPushed
);
1832 int prDirectory_At(struct VMGlobals
*g
, int numArgsPushed
)
1834 PyrSlot
*a
= g
->sp
- 2;
1835 PyrSlot
*b
= g
->sp
- 1;
1838 PyrSlot
*dirPathSlot
= slotRawObject(a
)->slots
+ 0;
1840 err
= slotIntVal(c
, &index
);
1846 char name
[256], fullPathName
[256];
1847 int nameLength
, creationDate
, modificationDate
, isDirectory
, isVisible
, sizeIfFile
;
1848 int dirPathLength
= slotRawObject(dirPathSlot
)->size
;
1850 err
= dir_Lookup(slotRawObject(dirPathSlot
)s
->s
, dirPathLength
, index
+1,
1851 name
, &nameLength
, &creationDate
, &modificationDate
, &isDirectory
, &isVisible
, &sizeIfFile
);
1857 error("Invalid path\n");
1862 if (dirPathLength
+ nameLength
+ 1 > 255) {
1863 error("Full path name too long.\n");
1868 PyrSlot
*entryName
= slotRawObject(b
)->slots
+ 0;
1869 PyrSlot
*entryPath
= slotRawObject(b
)->slots
+ 1;
1870 PyrSlot
*entryIsDir
= slotRawObject(b
)->slots
+ 2;
1871 PyrSlot
*entryIsVisible
= slotRawObject(b
)->slots
+ 3;
1873 PyrString
*nameString
= newPyrString(g
->gc
, name
, 0, true);
1874 SetObject(entryName
, nameString
);
1875 g
->gc
->GCWrite(slotRawObject(b
), (PyrObject
*)nameString
);
1877 memcpy(fullPathName
, slotRawObject(dirPathSlot
)s
->s
, dirPathLength
);
1878 fullPathName
[dirPathLength
] = DELIMITOR
;
1879 strcpy(fullPathName
+ dirPathLength
+ 1, name
);
1881 PyrString
*pathString
= newPyrString(g
->gc
, fullPathName
, 0, true);
1882 SetObject(entryPath
, pathString
);
1883 g
->gc
->GCWrite(slotRawObject(b
), (PyrObject
*)pathString
);
1885 if (isDirectory
) { SetTrue(entryIsDir
); } else { SetFalse(entryIsDir
); }
1886 if (isVisible
) { SetTrue(entryIsVisible
); } else { SetFalse(entryIsVisible
); }
1893 Boolean
GetFullPathname(const FSSpec
* aSpec
, Str255 pathname
);
1894 void pstrncpy(unsigned char *s1
, unsigned char *s2
, int n
);
1896 int prFile_GetFile(struct VMGlobals
*g
, int numArgsPushed
);
1897 int prFile_GetFile(struct VMGlobals
*g
, int numArgsPushed
)
1900 PyrSlot
*a
= g
->sp
- 1;
1903 NavDialogOptions options
;
1905 int err
= NavGetDefaultDialogOptions(&options
);
1906 if (err
) return errFailed
;
1908 options
.dialogOptionFlags
|= kNavNoTypePopup
;
1909 options
.dialogOptionFlags
|= kNavDontAutoTranslate
;
1910 options
.dialogOptionFlags
|= kNavDontAddTranslateItems
;
1911 options
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
1912 options
.dialogOptionFlags
&= ~kNavAllowPreviews
;
1913 options
.dialogOptionFlags
&= ~kNavAllowMultipleFiles
;
1915 if (isKindOfSlot(b
, class_string
)) {
1916 pstringFromPyrString((PyrString
*)slotRawObject(b
), options
.message
, 256);
1919 NavReplyRecord reply
;
1920 err
= NavGetFile(0, &reply
, &options
, 0, 0, 0, 0, 0);
1922 if (err
== noErr
&& reply
.validRecord
) {
1924 DescType actualType
;
1928 err
= AEGetNthPtr(&reply
.selection
, 1, typeFSS
, &keyword
, &actualType
,
1929 &fsspec
, sizeof(FSSpec
), &actualSize
);
1933 GetFullPathname(&fsspec
, pathname
);
1935 PyrString
*string
= newPyrString(g
->gc
, (char*)pathname
, 0, true);
1936 SetObject(a
, string
);
1940 err
= NavDisposeReply(&reply
);
1949 int prFile_PutFile(struct VMGlobals
*g
, int numArgsPushed
);
1950 int prFile_PutFile(struct VMGlobals
*g
, int numArgsPushed
)
1953 PyrSlot
*a
= g
->sp
- 2;
1954 PyrSlot
*b
= g
->sp
- 1;
1957 NavDialogOptions options
;
1959 int err
= NavGetDefaultDialogOptions(&options
);
1960 if (err
) return errFailed
;
1962 options
.dialogOptionFlags
|= kNavNoTypePopup
;
1963 options
.dialogOptionFlags
|= kNavDontAutoTranslate
;
1964 options
.dialogOptionFlags
|= kNavDontAddTranslateItems
;
1965 options
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
1966 options
.dialogOptionFlags
&= ~kNavAllowPreviews
;
1967 options
.dialogOptionFlags
&= ~kNavAllowMultipleFiles
;
1969 if (isKindOfSlot(b
, class_string
)) {
1970 pstringFromPyrString((PyrString
*)slotRawObject(b
), options
.message
, 256);
1973 if (isKindOfSlot(c
, class_string
)) {
1974 pstringFromPyrString((PyrString
*)slotRawObject(c
), options
.savedFileName
, 256);
1976 //pstrncpy(options.savedFileName, "\pUntitled", 255);
1979 NavReplyRecord reply
;
1980 err
= NavPutFile(0, &reply
, &options
, 0, 'TEXT', 'SCjm', 0);
1982 if (err
== noErr
&& reply
.validRecord
) {
1984 DescType actualType
;
1988 err
= AEGetNthPtr(&reply
.selection
, 1, typeFSS
, &keyword
, &actualType
,
1989 &fsspec
, sizeof(FSSpec
), &actualSize
);
1993 GetFullPathname(&fsspec
, pathname
);
1995 PyrString
*string
= newPyrString(g
->gc
, (char*)pathname
, 0, true);
1996 SetObject(a
, string
);
1998 err
= NavCompleteSave(&reply
, kNavTranslateInPlace
);
2002 err
= NavDisposeReply(&reply
);
2013 void initFilePrimitives()
2017 base
= nextPrimitiveIndex();
2020 definePrimitive(base
, index
++, "_SFOpenRead", prSFOpenRead
, 2, 0);
2021 definePrimitive(base
, index
++, "_SFOpenWrite", prSFOpenWrite
, 2, 0);
2022 definePrimitive(base
, index
++, "_SFClose", prSFClose
, 1, 0);
2023 definePrimitive(base
, index
++, "_SFWrite", prSFWrite
, 2, 0);
2024 definePrimitive(base
, index
++, "_SFRead", prSFRead
, 2, 0);
2025 definePrimitive(base
, index
++, "_SFSeek", prSFSeek
, 3, 0);
2026 definePrimitive(base
, index
++, "_SFHeaderInfoString", prSFHeaderInfoString
, 1, 0);
2029 definePrimitive(base
, index
++, "_PipeOpen", prPipeOpen
, 3, 0);
2030 definePrimitive(base
, index
++, "_PipeClose", prPipeClose
, 1, 0);
2033 definePrimitive(base
, index
++, "_FileDelete", prFileDelete
, 2, 0);
2034 definePrimitive(base
, index
++, "_FileMTime", prFileMTime
, 2, 0);
2035 definePrimitive(base
, index
++, "_FileExists", prFileExists
, 2, 0);
2036 definePrimitive(base
, index
++, "_FileRealPath", prFileRealPath
, 2, 0);
2037 definePrimitive(base
, index
++, "_FileMkDir", prFileMkDir
, 2, 0);
2038 definePrimitive(base
, index
++, "_FileCopy", prFileCopy
, 3, 0);
2039 definePrimitive(base
, index
++, "_FileType", prFileType
, 2, 0);
2040 definePrimitive(base
, index
++, "_FileSize", prFileSize
, 2, 0);
2042 definePrimitive(base
, index
++, "_FileOpen", prFileOpen
, 3, 0);
2043 definePrimitive(base
, index
++, "_FileClose", prFileClose
, 1, 0);
2044 definePrimitive(base
, index
++, "_FileFlush", prFileFlush
, 1, 0);
2045 definePrimitive(base
, index
++, "_FileSeek", prFileSeek
, 3, 0);
2046 definePrimitive(base
, index
++, "_FilePos", prFilePos
, 1, 0);
2047 definePrimitive(base
, index
++, "_FileLength", prFileLength
, 1, 0);
2048 definePrimitive(base
, index
++, "_FileWrite", prFileWrite
, 2, 0);
2049 definePrimitive(base
, index
++, "_FileWriteLE", prFileWriteLE
, 2, 0);
2050 definePrimitive(base
, index
++, "_FileReadLine", prFileReadLine
, 2, 0);
2051 definePrimitive(base
, index
++, "_File_getcwd", prFileGetcwd
, 2, 0);
2053 definePrimitive(base
, index
++, "_FilePutChar", prFilePutChar
, 2, 0);
2054 definePrimitive(base
, index
++, "_FilePutInt8", prFilePutInt8
, 2, 0);
2055 definePrimitive(base
, index
++, "_FilePutInt16", prFilePutInt16
, 2, 0);
2056 definePrimitive(base
, index
++, "_FilePutInt32", prFilePutInt32
, 2, 0);
2057 definePrimitive(base
, index
++, "_FilePutFloat", prFilePutFloat
, 2, 0);
2058 definePrimitive(base
, index
++, "_FilePutDouble", prFilePutDouble
, 2, 0);
2059 definePrimitive(base
, index
++, "_FilePutInt16LE", prFilePutInt16LE
, 2, 0);
2060 definePrimitive(base
, index
++, "_FilePutInt32LE", prFilePutInt32LE
, 2, 0);
2061 definePrimitive(base
, index
++, "_FilePutFloatLE", prFilePutFloatLE
, 2, 0);
2062 definePrimitive(base
, index
++, "_FilePutDoubleLE", prFilePutDoubleLE
, 2, 0);
2064 definePrimitive(base
, index
++, "_FileGetChar", prFileGetChar
, 1, 0);
2065 definePrimitive(base
, index
++, "_FileGetInt8", prFileGetInt8
, 1, 0);
2066 definePrimitive(base
, index
++, "_FileGetInt16", prFileGetInt16
, 1, 0);
2067 definePrimitive(base
, index
++, "_FileGetInt32", prFileGetInt32
, 1, 0);
2068 definePrimitive(base
, index
++, "_FileGetFloat", prFileGetFloat
, 1, 0);
2069 definePrimitive(base
, index
++, "_FileGetDouble", prFileGetDouble
, 1, 0);
2070 definePrimitive(base
, index
++, "_FileGetInt16LE", prFileGetInt16LE
, 1, 0);
2071 definePrimitive(base
, index
++, "_FileGetInt32LE", prFileGetInt32LE
, 1, 0);
2072 definePrimitive(base
, index
++, "_FileGetFloatLE", prFileGetFloatLE
, 1, 0);
2073 definePrimitive(base
, index
++, "_FileGetDoubleLE", prFileGetDoubleLE
, 1, 0);
2075 definePrimitive(base
, index
++, "_FilePutString", prFilePutString
, 2, 0);
2077 definePrimitive(base
, index
++, "_FileReadRaw", prFileReadRaw
, 2, 0);
2078 definePrimitive(base
, index
++, "_FileReadRawLE", prFileReadRawLE
, 2, 0);
2081 definePrimitive(base
, index
++, "_Directory_At", prDirectory_At
, 3, 0);
2082 definePrimitive(base
, index
++, "_File_GetFile", prFile_GetFile
, 2, 0);
2083 definePrimitive(base
, index
++, "_File_PutFile", prFile_PutFile
, 3, 0);