aboutsummaryrefslogtreecommitdiff
path: root/generic/MapInfo.c
diff options
context:
space:
mode:
authorlecoanet2003-10-02 07:50:57 +0000
committerlecoanet2003-10-02 07:50:57 +0000
commitd1c619094efe5c3bc9d7ce1570fb95eb93e6a9bb (patch)
treea725695cac5a2ed96efdb2a1e2f7c695d0b98aff /generic/MapInfo.c
parent269ffa44b4897a143e0fc7c5e58ab174be459edd (diff)
downloadtkzinc-d1c619094efe5c3bc9d7ce1570fb95eb93e6a9bb.zip
tkzinc-d1c619094efe5c3bc9d7ce1570fb95eb93e6a9bb.tar.gz
tkzinc-d1c619094efe5c3bc9d7ce1570fb95eb93e6a9bb.tar.bz2
tkzinc-d1c619094efe5c3bc9d7ce1570fb95eb93e6a9bb.tar.xz
Replaced the fopen/fclose/fread api by the corresponding Tcl_Channel
api for reading videomaps. This enable using zinc and data right from starkits.
Diffstat (limited to 'generic/MapInfo.c')
-rw-r--r--generic/MapInfo.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/generic/MapInfo.c b/generic/MapInfo.c
index f050898..c843c48 100644
--- a/generic/MapInfo.c
+++ b/generic/MapInfo.c
@@ -27,8 +27,6 @@
*/
-#include <stdlib.h>
-#include <stdio.h>
#ifndef _WIN32
#include <sys/param.h>
#include <netinet/in.h>
@@ -1185,20 +1183,20 @@ FillMap(ZnMapInfoId map, VideoMap *vm)
*/
static int
ZnMapInfoGetVideomap(ZnMapInfoId map,
- char *filename,
- unsigned int index)
+ char *filename,
+ unsigned int index)
{
VideoMap current_vm;
- FILE *file;
+ Tcl_Channel chan;
unsigned int cur_index, cur_id;
/* Open the specified map file. */
-#ifdef _WIN32
- file = fopen(filename, "rb");
-#else
- file = fopen(filename, "r");
-#endif
- if (file == NULL) {
+ chan = Tcl_OpenFileChannel(NULL, filename, "r", 0);
+ if (chan == NULL) {
+ return TCL_ERROR;
+ }
+ if (Tcl_SetChannelOption(NULL, chan,
+ "-translation", "binary") == TCL_ERROR) {
return TCL_ERROR;
}
@@ -1206,12 +1204,14 @@ ZnMapInfoGetVideomap(ZnMapInfoId map,
/* First skip the leading maps up to index. */
cur_index = 0;
- if (fread(&current_vm, sizeof(VideoMap), 1, file) != 1) {
+ if (Tcl_Read(chan, (char *) &current_vm,
+ sizeof(VideoMap)) != sizeof(VideoMap)) {
goto error;
}
cur_id = ntohi((unsigned int) current_vm.id);
while (cur_index != index) {
- if (fread(&current_vm, sizeof(VideoMap), 1, file) != 1) {
+ if (Tcl_Read(chan, (char *) &current_vm,
+ sizeof(VideoMap)) != sizeof(VideoMap)) {
goto error;
}
if (cur_id != ntohi((unsigned int) current_vm.id)) {
@@ -1224,17 +1224,20 @@ ZnMapInfoGetVideomap(ZnMapInfoId map,
do {
ReorderVidomap(&current_vm);
FillMap(map, &current_vm);
- if ((fread(&current_vm, sizeof(VideoMap), 1, file) != 1) && !feof(file)) {
+ if ((Tcl_Read(chan, (char *) &current_vm,
+ sizeof(VideoMap)) != sizeof(VideoMap)) &&
+ !Tcl_Eof(chan)) {
goto error;
}
}
- while ((cur_id == ntohi((unsigned int) current_vm.id)) && !feof(file));
+ while ((cur_id == ntohi((unsigned int) current_vm.id)) &&
+ !Tcl_Eof(chan));
- fclose(file);
+ Tcl_Close(NULL, chan);
return TCL_OK;
error:
- fclose(file);
+ Tcl_Close(NULL, chan);
return TCL_ERROR;
}
@@ -1252,24 +1255,25 @@ ZnMapInfoGetVideomap(ZnMapInfoId map,
static ZnList
ZnMapInfoVideomapIds(char *filename)
{
- FILE *file;
+ Tcl_Channel chan;
VideoMap current_vm;
unsigned int cur_id;
ZnList ids;
/* Open the specified map file. */
-#ifdef _WIN32
- file = fopen(filename, "rb");
-#else
- file = fopen(filename, "r");
-#endif
- if (file == NULL) {
+ chan = Tcl_OpenFileChannel(NULL, filename, "r", 0);
+ if (chan == NULL) {
+ return NULL;
+ }
+ if (Tcl_SetChannelOption(NULL, chan,
+ "-translation", "binary") == TCL_ERROR) {
return NULL;
}
- if (fread(&current_vm, sizeof(VideoMap), 1, file) != 1) {
+ if (Tcl_Read(chan, (char *) &current_vm,
+ sizeof(VideoMap)) != sizeof(VideoMap)) {
error:
- fclose(file);
+ Tcl_Close(NULL, chan);
return NULL;
}
cur_id = ntohi((unsigned int) current_vm.id);
@@ -1278,7 +1282,8 @@ ZnMapInfoVideomapIds(char *filename)
ZnListAdd(ids, &cur_id, ZnListTail);
do {
- if (fread(&current_vm, sizeof(VideoMap), 1, file) != 1) {
+ if (Tcl_Read(chan, (char *) &current_vm,
+ sizeof(VideoMap)) != sizeof(VideoMap)) {
ZnListFree(ids);
goto error;
}
@@ -1288,9 +1293,9 @@ ZnMapInfoVideomapIds(char *filename)
ZnListAdd(ids, &cur_id, ZnListTail);
}
}
- while (!feof(file));
+ while (!Tcl_Eof(chan));
- fclose(file);
+ Tcl_Close(NULL, chan);
return ids;
}