mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
C client: command line args read on linux, dropping map onto client works too
This commit is contained in:
parent
53475ce993
commit
d298f3ff57
@ -4,6 +4,7 @@
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
#define PROGRAM_MAX_CMDARGS 5
|
||||
#define PROGRAM_APP_NAME "ClassiCube 0.99.9.2"
|
||||
|
||||
#define USE16_BIT FALSE
|
||||
|
@ -42,7 +42,7 @@ Int32 Game_ComponentsCount;
|
||||
struct ScheduledTask Game_Tasks[6];
|
||||
Int32 Game_TasksCount, entTaskI;
|
||||
|
||||
char Game_UsernameBuffer[STRING_SIZE];
|
||||
char Game_UsernameBuffer[FILENAME_SIZE];
|
||||
String Game_Username = String_FromArray(Game_UsernameBuffer);
|
||||
char Game_MppassBuffer[STRING_SIZE];
|
||||
String Game_Mppass = String_FromArray(Game_MppassBuffer);
|
||||
|
@ -1283,25 +1283,43 @@ ReturnCode Platform_StartShell(STRING_PURE String* args) {
|
||||
return instance > 32 ? 0 : (ReturnCode)instance;
|
||||
}
|
||||
|
||||
STRING_PURE String Platform_GetCommandLineArgs(void) {
|
||||
String args = String_FromReadonly(GetCommandLineA());
|
||||
static String Platform_NextArg(STRING_REF String* args) {
|
||||
/* get rid of leading spaces before arg */
|
||||
while (args->length && args->buffer[0] == ' ') {
|
||||
*args = String_UNSAFE_SubstringAt(args, 1);
|
||||
}
|
||||
|
||||
Int32 argsStart;
|
||||
if (args.buffer[0] == '"') {
|
||||
/* Handle path argument in full "path" form, which can include spaces */
|
||||
argsStart = String_IndexOf(&args, '"', 1) + 1;
|
||||
Int32 end;
|
||||
if (args->length && args->buffer[0] == '"') {
|
||||
/* "xy za" is used for arg with spaces */
|
||||
*args = String_UNSAFE_SubstringAt(args, 1);
|
||||
end = String_IndexOf(args, '"', 0);
|
||||
} else {
|
||||
argsStart = String_IndexOf(&args, ' ', 0) + 1;
|
||||
end = String_IndexOf(args, ' ', 0);
|
||||
}
|
||||
|
||||
if (argsStart == 0) argsStart = args.length;
|
||||
args = String_UNSAFE_SubstringAt(&args, argsStart);
|
||||
|
||||
/* get rid of duplicate leading spaces before first arg */
|
||||
while (args.length && args.buffer[0] == ' ') {
|
||||
args = String_UNSAFE_SubstringAt(&args, 1);
|
||||
String arg;
|
||||
if (end == -1) {
|
||||
arg = *args;
|
||||
args->length = 0;
|
||||
} else {
|
||||
arg = String_UNSAFE_Substring(args, 0, end);
|
||||
*args = String_UNSAFE_SubstringAt(args, end + 1);
|
||||
}
|
||||
return args;
|
||||
return arg;
|
||||
}
|
||||
|
||||
Int32 Platform_GetCommandLineArgs(int argc, char** argv, STRING_TRANSIENT String* args) {
|
||||
String cmdArgs = String_FromReadonly(GetCommandLineA());
|
||||
Platform_NextArg(&cmdArgs); /* skip exe path */
|
||||
|
||||
Int32 count;
|
||||
for (count = 0; count < PROGRAM_MAX_CMDARGS; count++) {
|
||||
args[count] = Platform_NextArg(&cmdArgs);
|
||||
|
||||
if (!args[count].length) break;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
#elif CC_BUILD_NIX
|
||||
void Platform_ConvertString(void* dstPtr, STRING_PURE String* src) {
|
||||
@ -1326,9 +1344,9 @@ static void Platform_InitDisplay(void) {
|
||||
|
||||
/* TODO: Use Xinerama and XRandR for querying these */
|
||||
struct DisplayDevice device = { 0 };
|
||||
device.Bounds.Width = DisplayWidth(display, screen);
|
||||
device.Bounds.Width = DisplayWidth(display, screen);
|
||||
device.Bounds.Height = DisplayHeight(display, screen);
|
||||
device.BitsPerPixel = DefaultDepth(display, screen);
|
||||
device.BitsPerPixel = DefaultDepth(display, screen);
|
||||
DisplayDevice_Default = device;
|
||||
|
||||
DisplayDevice_Meta[0] = display;
|
||||
@ -1370,4 +1388,14 @@ ReturnCode Platform_StartShell(STRING_PURE String* args) {
|
||||
if (!fp) return errno;
|
||||
return Nix_Return(pclose(fp));
|
||||
}
|
||||
|
||||
Int32 Platform_GetCommandLineArgs(int argc, char** argv, STRING_TRANSIENT String* args) {
|
||||
argc--; /* skip path argument*/
|
||||
Int32 i, count = min(argc, PROGRAM_MAX_CMDARGS);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
args[i] = String_FromReadonly(argv[i]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
#endif
|
||||
|
@ -32,7 +32,7 @@ void Platform_Init(void);
|
||||
void Platform_Free(void);
|
||||
void Platform_SetWorkingDir(void);
|
||||
void Platform_Exit(ReturnCode code);
|
||||
STRING_PURE String Platform_GetCommandLineArgs(void);
|
||||
Int32 Platform_GetCommandLineArgs(int argc, char** argv, STRING_TRANSIENT String* args);
|
||||
ReturnCode Platform_StartShell(STRING_PURE String* args);
|
||||
|
||||
NOINLINE_ void* Mem_Alloc(UInt32 numElems, UInt32 elemsSize, const char* place);
|
||||
|
@ -39,7 +39,7 @@ int main_imdct() {
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
int main(int argc, char** argv) {
|
||||
Platform_SetWorkingDir();
|
||||
ErrorHandler_Init("client.log");
|
||||
Platform_Init();
|
||||
@ -61,13 +61,13 @@ int main(void) {
|
||||
Platform_Exit(1); return 1;
|
||||
}
|
||||
|
||||
String title = String_FromConst(PROGRAM_APP_NAME);
|
||||
String rawArgs = Platform_GetCommandLineArgs();
|
||||
/* NOTE: Make sure to comment this out before pushing a commit */
|
||||
//rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25565");
|
||||
String args[PROGRAM_MAX_CMDARGS];
|
||||
String title = String_FromConst(PROGRAM_APP_NAME);
|
||||
Int32 argsCount = Platform_GetCommandLineArgs(argc, argv, args);
|
||||
|
||||
String args[5]; Int32 argsCount = Array_Elems(args);
|
||||
String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);
|
||||
/* NOTE: Make sure to comment this out before pushing a commit */
|
||||
// String rawArgs = String_FromConst("UnknownShadow200 fff 127.0.0.1 25565");
|
||||
// argsCount = 4; String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);
|
||||
|
||||
if (argsCount == 1) {
|
||||
String name = args[0];
|
||||
|
Loading…
x
Reference in New Issue
Block a user