mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
add some string builtins (only the basics for now, but enough to deal with
temporary strings) and fix the game load/save menus.
This commit is contained in:
parent
bdd5c8aa96
commit
b3f76e1e48
8 changed files with 113 additions and 5 deletions
|
@ -59,6 +59,8 @@ void Key_Progs_Init (struct progs_s *pr);
|
|||
|
||||
void Plist_Progs_Init (struct progs_s *pr);
|
||||
|
||||
void String_Progs_Init (struct progs_s *pr);
|
||||
|
||||
#include "QF/quakeio.h"
|
||||
#define QFILE_MAX_HANDLES 20
|
||||
typedef struct {
|
||||
|
|
|
@ -463,6 +463,7 @@ Menu_Init (void)
|
|||
QFS_Progs_Init (&menu_pr_state);
|
||||
PR_Cmds_Init (&menu_pr_state);
|
||||
R_Progs_Init (&menu_pr_state);
|
||||
String_Progs_Init (&menu_pr_state);
|
||||
|
||||
PR_AddLoadFunc (&menu_pr_state, menu_resolve_globals);
|
||||
|
||||
|
|
|
@ -11,5 +11,4 @@ libQFgamecode_builtins_la_SOURCES= pr_cmds.c
|
|||
libQFcsqc_la_LDFLAGS= -version-info 1:0:0
|
||||
libQFcsqc_la_SOURCES=\
|
||||
bi_cbuf.c bi_cmd.c bi_cvar.c bi_file.c bi_gib.c bi_hash.c bi_init.c \
|
||||
bi_inputline.c bi_plist.c \
|
||||
bi_qfile.c bi_qfs.c
|
||||
bi_inputline.c bi_plist.c bi_qfile.c bi_qfs.c bi_string.c
|
||||
|
|
|
@ -45,6 +45,7 @@ static U void (*const inputline_progs_init)(progs_t *) = InputLine_Progs_Init;
|
|||
static U void (*const plist_progs_init)(progs_t *) = Plist_Progs_Init;
|
||||
static U void (*const qfile_progs_init)(progs_t *, int) = QFile_Progs_Init;
|
||||
static U void (*const qfs_progs_init)(progs_t *) = QFS_Progs_Init;
|
||||
static U void (*const string_progs_init)(progs_t *) = String_Progs_Init;
|
||||
#undef U
|
||||
|
||||
void
|
||||
|
|
92
libs/gamecode/builtins/bi_string.c
Normal file
92
libs/gamecode/builtins/bi_string.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
bi_string.c
|
||||
|
||||
QuakeC string api
|
||||
|
||||
Copyright (C) 2004 Bill Currie
|
||||
|
||||
Author: Bill Currie <bill@taniwha.org>
|
||||
Date: 2004/1/6
|
||||
|
||||
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
|
||||
|
||||
static __attribute__ ((unused)) const char rcsid[] =
|
||||
"$Id$";
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "QF/csqc.h"
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/progs.h"
|
||||
|
||||
static void
|
||||
bi_str_new (progs_t *pr)
|
||||
{
|
||||
R_STRING (pr) = PR_NewString (pr);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_str_free (progs_t *pr)
|
||||
{
|
||||
PR_FreeString (pr, P_STRING (pr, 0));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_str_copy (progs_t *pr)
|
||||
{
|
||||
dstring_t *dst = P_DSTRING (pr, 0);
|
||||
const char *src = P_GSTRING (pr, 1);
|
||||
|
||||
dstring_copystr (dst, src);
|
||||
R_STRING (pr) = P_STRING (pr, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_str_clear (progs_t *pr)
|
||||
{
|
||||
dstring_t *str = P_DSTRING (pr, 0);
|
||||
|
||||
dstring_clearstr (str);
|
||||
R_STRING (pr) = P_STRING (pr, 0);
|
||||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"str_new", bi_str_new, -1},
|
||||
{"str_free", bi_str_free, -1},
|
||||
{"str_copy", bi_str_copy, -1},
|
||||
{"str_clear", bi_str_clear, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
String_Progs_Init (progs_t *pr)
|
||||
{
|
||||
PR_RegisterBuiltins (pr, builtins);
|
||||
}
|
|
@ -98,13 +98,16 @@ void () scan_saves =
|
|||
local integer i;
|
||||
local QFile f;
|
||||
for (i = 0; i < MAX_SAVEGAMES; i++) {
|
||||
if (!filenames[i])
|
||||
filenames[i] = str_new ();
|
||||
loadable[i] = 0;
|
||||
filenames[i] = "--- UNUSED SLOT ---";
|
||||
f = File_Open (sprintf ("s%i.sav", i), "rz");
|
||||
if (!f)
|
||||
if (!f) {
|
||||
str_copy (filenames[i], "--- UNUSED SLOT ---");
|
||||
continue;
|
||||
}
|
||||
Qgetline (f);
|
||||
filenames[i] = Qgetline (f);
|
||||
str_copy (filenames[i], Qgetline (f));
|
||||
loadable[i] = 1;
|
||||
Qclose (f);
|
||||
}
|
||||
|
|
|
@ -11,4 +11,9 @@
|
|||
@extern integer (string s) stoi;
|
||||
@extern vector (string s) stov;
|
||||
|
||||
@extern string (void) str_new;
|
||||
@extern string (string str) str_free;
|
||||
@extern string (string dst, string src) str_copy;
|
||||
@extern string (string str) str_clear;
|
||||
|
||||
#endif//__ruamoko_string_h
|
||||
|
|
|
@ -9,3 +9,8 @@ string (...) sprintf = #0x000f0000 + 109;
|
|||
string (integer i) itos = #0x000f0000 + 112;
|
||||
integer (string s) stoi = #0x000f0000 + 113;
|
||||
vector (string s) stov = #0x000f0000 + 114;
|
||||
|
||||
string (void) str_new = #0;
|
||||
string (string str) str_free = #0;
|
||||
string (string dst, string src) str_copy = #0;
|
||||
string (string str) str_clear = #0;
|
||||
|
|
Loading…
Reference in a new issue