Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
3-manifolds
GitHub Repository: 3-manifolds/Sage_macOS
Path: blob/main/main_ex/SageMath.c
170 views
1
#include <stdio.h>
2
#include <unistd.h>
3
#include <sys/param.h>
4
#include <libgen.h>
5
#include <CoreFoundation/CoreFoundation.h>
6
7
/*
8
* We expect the bundle to contain a symlink MacOS/Python to the python
9
* executable within the bundle and a python script Resources/main.py
10
* which will be run using the python executable.
11
*/
12
13
static void debugMessage(char *msg) {
14
FILE *logfile = fopen("/tmp/sagemath.log", "a");
15
fprintf(logfile, "%s\n", msg);
16
fclose(logfile);
17
}
18
19
int main(int argc, char **argv, char **envp) {
20
char executablePath[PATH_MAX];
21
char pythonPath[PATH_MAX];
22
char mainPath[PATH_MAX];
23
char *exec_argv[3] = {pythonPath, mainPath, NULL};
24
CFBundleRef bundle = CFBundleGetMainBundle();
25
CFURLRef URL;
26
CFStringRef string;
27
/* debugMessage("Starting SageMath"); */
28
URL = CFBundleCopyExecutableURL(bundle);
29
string = CFURLCopyFileSystemPath(URL, kCFURLPOSIXPathStyle);
30
CFRelease(URL);
31
CFStringGetCString(string, executablePath, PATH_MAX, kCFStringEncodingUTF8);
32
CFRelease(string);
33
CFRelease(bundle);
34
dirname_r(executablePath, pythonPath);
35
dirname_r(pythonPath, mainPath);
36
strlcat(pythonPath, "/Python", PATH_MAX);
37
strlcat(mainPath, "/Resources/main.py", PATH_MAX);
38
/*
39
debugMessage(pythonPath);
40
debugMessage(mainPath);
41
for (char **p = envp; *p != NULL; p++) {
42
debugMessage(*p);
43
}
44
*/
45
execve(pythonPath, exec_argv, envp);
46
return 0;
47
}
48
49