2003-02-14 18:17:17 +00:00
|
|
|
/*
|
|
|
|
bi_file.c
|
|
|
|
|
|
|
|
CSQC file builtins
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2007-05-13 03:56:08 +00:00
|
|
|
#include "QF/dstring.h"
|
2003-02-14 18:17:17 +00:00
|
|
|
#include "QF/progs.h"
|
2020-02-26 00:46:59 +00:00
|
|
|
#include "QF/quakeio.h"
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-01-16 07:03:58 +00:00
|
|
|
#include "rua_internal.h"
|
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
typedef struct qfile_s {
|
|
|
|
struct qfile_s *next;
|
|
|
|
struct qfile_s **prev;
|
|
|
|
QFile *file;
|
|
|
|
} qfile_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PR_RESMAP (qfile_t) handle_map;
|
|
|
|
qfile_t *handles;
|
|
|
|
} qfile_resources_t;
|
|
|
|
|
|
|
|
static qfile_t *
|
|
|
|
handle_new (qfile_resources_t *res)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESNEW (res->handle_map);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_free (qfile_resources_t *res, qfile_t *handle)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
PR_RESFREE (res->handle_map, handle);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_reset (qfile_resources_t *res)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
PR_RESRESET (res->handle_map);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline qfile_t *
|
|
|
|
handle_get (qfile_resources_t *res, int index)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESGET(res->handle_map, index);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 17:12:51 +00:00
|
|
|
static inline int __attribute__((pure))
|
2004-11-11 07:57:00 +00:00
|
|
|
handle_index (qfile_resources_t *res, qfile_t *handle)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESINDEX(res->handle_map, handle);
|
2004-11-11 07:57:00 +00:00
|
|
|
}
|
|
|
|
|
2003-02-28 05:35:27 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_qfile_clear (progs_t *pr, void *_res)
|
2003-02-28 05:35:27 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_resources_t *res = (qfile_resources_t *) _res;
|
2004-11-11 07:57:00 +00:00
|
|
|
qfile_t *handle;
|
|
|
|
|
|
|
|
for (handle = res->handles; handle; handle = handle->next)
|
|
|
|
Qclose (handle->file);
|
|
|
|
res->handles = 0;
|
|
|
|
handle_reset (res);
|
2003-02-28 05:35:27 +00:00
|
|
|
}
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
static void
|
|
|
|
bi_qfile_destroy (progs_t *pr, void *_res)
|
|
|
|
{
|
2023-03-03 10:36:28 +00:00
|
|
|
free (_res);
|
2022-05-12 09:23:32 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
static int
|
|
|
|
alloc_handle (qfile_resources_t *res, QFile *file)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2004-11-11 07:57:00 +00:00
|
|
|
qfile_t *handle = handle_new (res);
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
handle->next = res->handles;
|
|
|
|
handle->prev = &res->handles;
|
|
|
|
if (res->handles)
|
|
|
|
res->handles->prev = &handle->next;
|
|
|
|
res->handles = handle;
|
|
|
|
handle->file = file;
|
|
|
|
return handle_index (res, handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QFile_AllocHandle (progs_t *pr, QFile *file)
|
|
|
|
{
|
|
|
|
qfile_resources_t *res = PR_Resources_Find (pr, "QFile");
|
|
|
|
|
|
|
|
return alloc_handle (res, file);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
secured (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
|
|
|
PR_RunError (pr, "Secured function called");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qrename (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *old = P_GSTRING (pr, 0);
|
|
|
|
const char *new = P_GSTRING (pr, 1);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
|
|
|
R_INT (pr) = Qrename (old, new);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qremove (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *path = P_GSTRING (pr, 0);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
|
|
|
R_INT (pr) = Qremove (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qopen (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *path = P_GSTRING (pr, 0);
|
|
|
|
const char *mode = P_GSTRING (pr, 1);
|
2004-11-11 07:57:00 +00:00
|
|
|
QFile *file;
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = 0;
|
|
|
|
if (!(file = Qopen (path, mode)))
|
2003-02-28 05:35:27 +00:00
|
|
|
return;
|
2004-11-11 07:57:00 +00:00
|
|
|
if (!(R_INT (pr) = alloc_handle (res, file)))
|
|
|
|
Qclose (file);
|
2003-02-28 05:35:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 10:30:50 +00:00
|
|
|
static qfile_t * __attribute__((pure))
|
2022-02-14 03:28:38 +00:00
|
|
|
get_handle (progs_t *pr, qfile_resources_t *res, const char *name, int handle)
|
2003-02-28 05:35:27 +00:00
|
|
|
{
|
2004-11-11 07:57:00 +00:00
|
|
|
qfile_t *h = handle_get (res, handle);
|
2003-02-28 05:35:27 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
if (!h)
|
|
|
|
PR_RunError (pr, "invalid file handle passed to %s", name + 3);
|
|
|
|
return h;
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 04:10:25 +00:00
|
|
|
QFile *
|
|
|
|
QFile_GetFile (progs_t *pr, int handle)
|
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_resources_t *res = PR_Resources_Find (pr, "QFile");
|
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2010-11-24 04:10:25 +00:00
|
|
|
|
|
|
|
return h->file;
|
|
|
|
}
|
|
|
|
|
2003-02-14 18:17:17 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qclose (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2004-11-11 07:57:00 +00:00
|
|
|
qfile_t *h = handle_get (res, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
if (!h)
|
2010-11-18 15:06:53 +00:00
|
|
|
PR_RunError (pr, "invalid file handle passed to Qclose");
|
2004-11-11 07:57:00 +00:00
|
|
|
Qclose (h->file);
|
|
|
|
*h->prev = h->next;
|
2011-07-09 00:42:11 +00:00
|
|
|
if (h->next)
|
|
|
|
h->next->prev = h->prev;
|
2004-11-11 07:57:00 +00:00
|
|
|
handle_free (res, h);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qgetline (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
const char *s;
|
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
s = Qgetline (h->file);
|
2003-04-24 04:57:30 +00:00
|
|
|
if (s)
|
|
|
|
RETURN_STRING (pr, s);
|
|
|
|
else
|
|
|
|
R_STRING (pr) = 0;
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
2007-05-13 03:56:08 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qreadstring (progs_t *pr, void *_res)
|
2007-05-13 03:56:08 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2007-05-13 03:56:08 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
|
|
|
int len = P_INT (pr, 1);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t str = PR_NewMutableString (pr);
|
2007-05-13 03:56:08 +00:00
|
|
|
dstring_t *dstr = PR_GetMutableString (pr, str);
|
|
|
|
|
|
|
|
dstr->size = len + 1;
|
|
|
|
dstring_adjust (dstr);
|
|
|
|
len = Qread (h->file, dstr->str, len);
|
|
|
|
dstr->size = len + 1;
|
|
|
|
dstr->str[len] = 0;
|
|
|
|
R_STRING (pr) = str;
|
|
|
|
}
|
|
|
|
|
2003-02-14 18:17:17 +00:00
|
|
|
static void
|
|
|
|
check_buffer (progs_t *pr, pr_type_t *buf, int count, const char *name)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = (count + sizeof (pr_type_t) - 1) / sizeof (pr_type_t);
|
|
|
|
if (buf < pr->pr_globals || buf + len > pr->pr_globals + pr->globals_size)
|
|
|
|
PR_RunError (pr, "%s: bad buffer", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qread (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-04-22 18:20:15 +00:00
|
|
|
pr_type_t *buf = P_GPOINTER (pr, 1);
|
2003-02-14 18:17:17 +00:00
|
|
|
int count = P_INT (pr, 2);
|
|
|
|
|
|
|
|
check_buffer (pr, buf, count, "Qread");
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qread (h->file, buf, count);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qwrite (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-04-22 18:20:15 +00:00
|
|
|
pr_type_t *buf = P_GPOINTER (pr, 1);
|
2003-02-14 18:17:17 +00:00
|
|
|
int count = P_INT (pr, 2);
|
|
|
|
|
|
|
|
check_buffer (pr, buf, count, "Qwrite");
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qwrite (h->file, buf, count);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qputs (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-04-22 18:20:15 +00:00
|
|
|
const char *str = P_GSTRING (pr, 1);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qputs (h->file, str);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qgets (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-04-22 18:20:15 +00:00
|
|
|
pr_type_t *buf = P_GPOINTER (pr, 1);
|
2003-02-14 18:17:17 +00:00
|
|
|
int count = P_INT (pr, 2);
|
|
|
|
|
|
|
|
check_buffer (pr, buf, count, "Qgets");
|
2004-11-11 07:57:00 +00:00
|
|
|
RETURN_POINTER (pr, Qgets (h->file, (char *) buf, count));
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qgetc (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qgetc (h->file);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qputc (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
int c = P_INT (pr, 1);
|
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qputc (h->file, c);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qseek (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
int offset = P_INT (pr, 1);
|
|
|
|
int whence = P_INT (pr, 2);
|
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qseek (h->file, offset, whence);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qtell (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qtell (h->file);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qflush (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qflush (h->file);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qeof (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qeof (h->file);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_Qfilesize (progs_t *pr, void *_res)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
__auto_type res = (qfile_resources_t *) _res;
|
2003-02-28 05:35:27 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
qfile_t *h = get_handle (pr, res, __FUNCTION__, handle);
|
2003-02-14 18:17:17 +00:00
|
|
|
|
2004-11-11 07:57:00 +00:00
|
|
|
R_INT (pr) = Qfilesize (h->file);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define bi(x,np,params...) {#x, secured, -1, np, {params}}
|
|
|
|
#define p(type) PR_PARAM(type)
|
|
|
|
#define P(a, s) { .size = (s), .alignment = BITOP_LOG2 (a), }
|
2004-01-06 05:51:09 +00:00
|
|
|
static builtin_t secure_builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(Qrename, 2, p(string), p(string)),
|
|
|
|
bi(Qremove, 1, p(string)),
|
|
|
|
bi(Qopen, 2, p(string), p(string)),
|
2004-01-06 05:51:09 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#undef bi
|
|
|
|
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
2004-01-06 05:51:09 +00:00
|
|
|
static builtin_t insecure_builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(Qrename, 2, p(string), p(string)),
|
|
|
|
bi(Qremove, 1, p(string)),
|
|
|
|
bi(Qopen, 2, p(string), p(string)),
|
2004-01-06 05:51:09 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static builtin_t builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(Qclose, 1, p(ptr)),
|
|
|
|
bi(Qgetline, 1, p(ptr)),
|
|
|
|
bi(Qreadstring, 2, p(ptr), p(int)),
|
|
|
|
bi(Qread, 3, p(ptr), p(ptr), p(int)),
|
|
|
|
bi(Qwrite, 3, p(ptr), p(ptr), p(int)),
|
|
|
|
bi(Qputs, 2, p(ptr), p(string)),
|
|
|
|
// bi(Qgets, _, _),
|
|
|
|
bi(Qgetc, 1, p(ptr)),
|
|
|
|
bi(Qputc, 2, p(ptr), p(int)),
|
|
|
|
bi(Qseek, 3, p(ptr), p(int), p(int)),
|
|
|
|
bi(Qtell, 1, p(ptr)),
|
|
|
|
bi(Qflush, 1, p(ptr)),
|
|
|
|
bi(Qeof, 1, p(ptr)),
|
|
|
|
bi(Qfilesize, 1, p(ptr)),
|
2004-01-06 05:51:09 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2003-02-14 18:17:17 +00:00
|
|
|
void
|
2004-01-16 05:46:19 +00:00
|
|
|
RUA_QFile_Init (progs_t *pr, int secure)
|
2003-02-14 18:17:17 +00:00
|
|
|
{
|
2003-02-28 05:35:27 +00:00
|
|
|
qfile_resources_t *res = calloc (sizeof (qfile_resources_t), 1);
|
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
PR_Resources_Register (pr, "QFile", res, bi_qfile_clear, bi_qfile_destroy);
|
2003-02-14 18:17:17 +00:00
|
|
|
if (secure) {
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, secure_builtins, res);
|
2003-02-14 18:17:17 +00:00
|
|
|
} else {
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, insecure_builtins, res);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, builtins, res);
|
2003-02-14 18:17:17 +00:00
|
|
|
}
|