Migrate more strings

FossilOrigin-Name: 5ef6284dcf38a9367998d964d81cf7cf8340d76c87d58efaa350c9d930ccb416
This commit is contained in:
Jonathan Schleifer 2025-03-07 19:55:34 +00:00
parent 2a2c5ee6ee
commit 570b9e3bb3
5 changed files with 76 additions and 68 deletions

View file

@ -166,7 +166,7 @@ trydisconnect()
string ctext; string ctext;
void void
toserver(char *text) toserver(const char *text)
{ {
conoutf(@"%s:\f %s", player1->name, text); conoutf(@"%s:\f %s", player1->name, text);
strn0cpy(ctext, text, 80); strn0cpy(ctext, text, 80);

View file

@ -511,33 +511,44 @@ resetcomplete()
} }
void void
complete(char *s) complete(OFString *s_)
{ {
@autoreleasepool {
std::unique_ptr<char> copy(strdup(s_.UTF8String));
char *s = copy.get();
if (*s != '/') { if (*s != '/') {
string t; string t;
strcpy_s(t, s); strcpy_s(t, s);
strcpy_s(s, "/"); strcpy_s(s, "/");
strcat_s(s, t); strcat_s(s, t);
} }
if (!s[1]) if (!s[1])
return; return;
if (!completesize) { if (!completesize) {
completesize = (int)strlen(s) - 1; completesize = strlen(s) - 1;
completeidx = 0; completeidx = 0;
} }
__block int idx = 0; __block int idx = 0;
[idents enumerateKeysAndObjectsUsingBlock:^( [idents enumerateKeysAndObjectsUsingBlock:^(
OFString *name, Ident *ident, bool *stop) { OFString *name, Ident *ident, bool *stop) {
if (strncmp(ident.name.UTF8String, s + 1, completesize) == 0 && if (strncmp(ident.name.UTF8String, s + 1,
completesize) == 0 &&
idx++ == completeidx) { idx++ == completeidx) {
strcpy_s(s, "/"); strcpy_s(s, "/");
strcat_s(s, ident.name.UTF8String); strcat_s(s, ident.name.UTF8String);
} }
}]; }];
completeidx++; completeidx++;
if (completeidx >= idx) if (completeidx >= idx)
completeidx = 0; completeidx = 0;
} }
}
bool bool
execfile(OFString *cfgfile) execfile(OFString *cfgfile)

View file

@ -18,7 +18,7 @@ const int WORDWRAP = 80;
int conskip = 0; int conskip = 0;
bool saycommandon = false; bool saycommandon = false;
string commandbuf; static OFMutableString *commandbuf;
void void
setconskip(int n) setconskip(int n)
@ -128,18 +128,21 @@ bindkey(OFString *key, OFString *action)
COMMANDN(bind, bindkey, ARG_2STR) COMMANDN(bind, bindkey, ARG_2STR)
void void
saycommand(char *init) // turns input to the command line on or off saycommand(const char *init) // turns input to the command line on or off
{ {
saycommandon = (init != NULL); saycommandon = (init != NULL);
if (saycommandon) if (saycommandon)
SDL_StartTextInput(); SDL_StartTextInput();
else else
SDL_StopTextInput(); SDL_StopTextInput();
if (!editmode) if (!editmode)
Cube.sharedInstance.repeatsKeys = saycommandon; Cube.sharedInstance.repeatsKeys = saycommandon;
if (!init) if (!init)
init = ""; init = "";
strcpy_s(commandbuf, init);
commandbuf = [[OFMutableString alloc] initWithUTF8String:init];
} }
COMMAND(saycommand, ARG_VARI) COMMAND(saycommand, ARG_VARI)
@ -155,12 +158,13 @@ COMMAND(mapmsg, ARG_1STR)
void void
pasteconsole() pasteconsole()
{ {
char *cb = SDL_GetClipboardText(); @autoreleasepool {
strcat_s(commandbuf, cb); [commandbuf appendString:@(SDL_GetClipboardText())];
}
} }
static OFMutableArray<OFString *> *vhistory; static OFMutableArray<OFString *> *vhistory;
int histpos = 0; static int histpos = 0;
void void
history(int n) history(int n)
@ -189,31 +193,24 @@ keypress(int code, bool isdown, int cooked)
case SDLK_BACKSPACE: case SDLK_BACKSPACE:
case SDLK_LEFT: { case SDLK_LEFT: {
for (int i = 0; commandbuf[i]; i++) [commandbuf
if (!commandbuf[i + 1]) deleteCharactersInRange:
commandbuf[i] = 0; OFMakeRange(commandbuf.length - 1, 1)];
resetcomplete(); resetcomplete();
break; break;
} }
case SDLK_UP: case SDLK_UP:
if (histpos) { if (histpos)
@autoreleasepool { commandbuf =
strcpy_s(commandbuf, [vhistory[--histpos] mutableCopy];
vhistory[--histpos]
.UTF8String);
}
}
break; break;
case SDLK_DOWN: case SDLK_DOWN:
if (histpos < vhistory.count) { if (histpos < vhistory.count)
@autoreleasepool { commandbuf =
strcpy_s(commandbuf, [vhistory[histpos++] mutableCopy];
vhistory[histpos++]
.UTF8String);
}
}
break; break;
case SDLK_TAB: case SDLK_TAB:
@ -225,22 +222,17 @@ keypress(int code, bool isdown, int cooked)
(KMOD_LCTRL | KMOD_RCTRL)) { (KMOD_LCTRL | KMOD_RCTRL)) {
pasteconsole(); pasteconsole();
return; return;
}; }
default: default:
resetcomplete(); resetcomplete();
if (cooked) { if (cooked)
char add[] = {(char)cooked, 0}; [commandbuf appendFormat:@"%c", cooked];
strcat_s(commandbuf, add);
}
} }
} else { } else {
if (code == SDLK_RETURN) { if (code == SDLK_RETURN) {
if (commandbuf[0]) { if (commandbuf.length > 0) {
@autoreleasepool { @autoreleasepool {
OFString *cmdbuf =
@(commandbuf);
if (vhistory == nil) if (vhistory == nil)
vhistory = vhistory =
[[OFMutableArray [[OFMutableArray
@ -248,17 +240,22 @@ keypress(int code, bool isdown, int cooked)
if (vhistory.count == 0 || if (vhistory.count == 0 ||
![vhistory.lastObject ![vhistory.lastObject
isEqual:cmdbuf]) { isEqual:commandbuf]) {
// cap this? // cap this?
[vhistory [vhistory
addObject:cmdbuf]; addObject:
[commandbuf
copy]];
} }
} }
histpos = vhistory.count; histpos = vhistory.count;
if (commandbuf[0] == '/') if ([commandbuf hasPrefix:@"/"]) {
execute(commandbuf, true); std::unique_ptr<char> copy(
else strdup(
toserver(commandbuf); commandbuf.UTF8String));
execute(copy.get(), true);
} else
toserver(commandbuf.UTF8String);
} }
saycommand(NULL); saycommand(NULL);
} else if (code == SDLK_ESCAPE) { } else if (code == SDLK_ESCAPE) {
@ -281,7 +278,7 @@ keypress(int code, bool isdown, int cooked)
} }
} }
char * OFString *
getcurcommand() getcurcommand()
{ {
return saycommandon ? commandbuf : NULL; return saycommandon ? commandbuf : NULL;

View file

@ -11,7 +11,7 @@ extern int execute(char *p, bool down = true);
extern void exec(OFString *cfgfile); extern void exec(OFString *cfgfile);
extern bool execfile(OFString *cfgfile); extern bool execfile(OFString *cfgfile);
extern void resetcomplete(); extern void resetcomplete();
extern void complete(char *s); extern void complete(OFString *s);
extern void alias(OFString *name, OFString *action); extern void alias(OFString *name, OFString *action);
extern OFString *getalias(OFString *name); extern OFString *getalias(OFString *name);
extern void writecfg(); extern void writecfg();
@ -20,7 +20,7 @@ extern void writecfg();
extern void keypress(int code, bool isdown, int cooked); extern void keypress(int code, bool isdown, int cooked);
extern void renderconsole(); extern void renderconsole();
extern void conoutf(OFConstantString *format, ...); extern void conoutf(OFConstantString *format, ...);
extern char *getcurcommand(); extern OFString *getcurcommand();
extern void writebinds(OFStream *stream); extern void writebinds(OFStream *stream);
// init // init
@ -71,7 +71,7 @@ extern void setarraypointers();
extern void localservertoclient(uchar *buf, int len); extern void localservertoclient(uchar *buf, int len);
extern void connects(OFString *servername); extern void connects(OFString *servername);
extern void disconnect(int onlyclean = 0, int async = 0); extern void disconnect(int onlyclean = 0, int async = 0);
extern void toserver(char *text); extern void toserver(const char *text);
extern void addmsg(int rel, int num, int type, ...); extern void addmsg(int rel, int num, int type, ...);
extern bool multiplayer(); extern bool multiplayer();
extern bool allowedittoggle(); extern bool allowedittoggle();

View file

@ -366,11 +366,11 @@ gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater)
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
@autoreleasepool { @autoreleasepool {
char *command = getcurcommand(); OFString *command = getcurcommand();
char *player = playerincrosshair(); char *player = playerincrosshair();
if (command) if (command)
draw_textf(@"> %s_", 20, 1570, 2, command); draw_textf(@"> %@_", 20, 1570, 2, command);
else if (closeent[0]) else if (closeent[0])
draw_text(@(closeent), 20, 1570, 2); draw_text(@(closeent), 20, 1570, 2);
else if (player) else if (player)