Debian Codegraph @

drivers/apple_embedded/main_utilities.mm

raw
1 /**************************************************************************/
2 /* main_utilities.mm */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "core/string/ustring.h"
32
33 #import <UIKit/UIKit.h>
34
35 #include <unistd.h>
36 #include <cstdio>
37
38 void change_to_launch_dir(char **p_args) {
39 size_t len = strlen(p_args[0]);
40
41 while (len--) {
42 if (p_args[0][len] == '/') {
43 break;
44 }
45 }
46
47 if (len >= 0) {
48 char path[512];
49 memcpy(path, p_args[0], len > sizeof(path) ? sizeof(path) : len);
50 path[len] = 0;
51 chdir(path);
52 }
53 }
54
55 int add_cmdline(int p_argc, char **p_args) {
56 NSArray *arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_cmdline"];
57 if (!arr) {
58 return p_argc;
59 }
60
61 for (NSUInteger i = 0; i < [arr count]; i++) {
62 NSString *str = [arr objectAtIndex:i];
63 if (!str) {
64 continue;
65 }
66 p_args[p_argc++] = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding];
67 }
68
69 p_args[p_argc] = nullptr;
70
71 return p_argc;
72 }
73
74 int process_args(int p_argc, char **p_args, char **r_args) {
75 for (int i = 0; i < p_argc; i++) {
76 r_args[i] = p_args[i];
77 }
78 r_args[p_argc] = nullptr;
79 p_argc = add_cmdline(p_argc, r_args);
80 return p_argc;
81 }