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