-
Notifications
You must be signed in to change notification settings - Fork 65
/
parameters.m
131 lines (97 loc) · 4.13 KB
/
parameters.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#import <Foundation/Foundation.h>
#include "pharovm/pharo.h"
#include "pharovm/parameters/parameters.h"
#include "pharovm/parameters/parameterVector.h"
#include "pharovm/debug.h"
#include "pharovm/pathUtilities.h"
#include <sys/stat.h>
static bool
fileExists(char *filename) {
struct stat buffer;
return (stat (filename, &buffer) == 0);
}
EXPORT(void) fillParametersFromPList(VMParameters* parameters){
char fileNameBuffer[FILENAME_MAX + 1];
char mainBundlePath[FILENAME_MAX + 1];
CFBundleRef mainBundle;
CFNumberRef logLevelRef;
int32_t logLevelValue;
CFStringRef imageFileName;
CFBooleanRef headlessRef;
CFBooleanRef workerRef;
CFNumberRef maxFramesToLogRef;
CFNumberRef maxOldSpaceSizeRef;
CFNumberRef edenSizeRef;
CFNumberRef codeSizeRef;
CFArrayRef argumentsRef;
mainBundle = CFBundleGetMainBundle();
CFStringGetCString((CFStringRef)[[NSBundle mainBundle] bundlePath], mainBundlePath, FILENAME_MAX + 1, kCFStringEncodingUTF8);
logLevelRef = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoLogLevel"));
if(logLevelRef != NULL){
CFNumberGetValue(logLevelRef, kCFNumberSInt32Type, &logLevelValue);
logLevel(logLevelValue);
}
imageFileName = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoImageFile"));
if(imageFileName != NULL){
CFStringGetCString(imageFileName, fileNameBuffer, FILENAME_MAX + 1, kCFStringEncodingUTF8);
parameters->imageFileName = strdup(fileNameBuffer);
parameters->isDefaultImage = false;
parameters->isInteractiveSession = true;
parameters->defaultImageFound = true;
//Check if the path passed exists, if not exists try with a location inside the main bundle.
if(fileExists(parameters->imageFileName)){
parameters->defaultImageFound = true;
}else{
snprintf(fileNameBuffer, FILENAME_MAX + 1, "%s/Contents/Resources/%s", mainBundlePath, parameters->imageFileName);
if(fileExists(fileNameBuffer)){
free(parameters->imageFileName);
parameters->imageFileName = strdup(fileNameBuffer);
parameters->defaultImageFound = true;
}else{
snprintf(fileNameBuffer, FILENAME_MAX + 1, "%s/Contents/MacOS/Resources/%s", mainBundlePath, parameters->imageFileName);
if(fileExists(fileNameBuffer)){
free(parameters->imageFileName);
parameters->imageFileName = strdup(fileNameBuffer);
parameters->defaultImageFound = true;
}
}
}
logDebug("Using Image File from PList: %s", parameters->imageFileName);
}
headlessRef = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoHeadless"));
if(headlessRef != NULL){
parameters->isInteractiveSession = !CFBooleanGetValue(headlessRef);
}
workerRef = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoWorker"));
if(workerRef != NULL){
parameters->isWorker = !CFBooleanGetValue(workerRef);
}
maxFramesToLogRef = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoMaxFramesToLog"));
if(maxFramesToLogRef != NULL){
CFNumberGetValue(maxFramesToLogRef, kCFNumberSInt32Type, ¶meters->maxStackFramesToPrint);
}
maxOldSpaceSizeRef = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoMaxOldSpaceSize"));
if(maxOldSpaceSizeRef != NULL){
CFNumberGetValue(maxOldSpaceSizeRef, kCFNumberSInt64Type, ¶meters->maxOldSpaceSize);
}
edenSizeRef = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoEdenSize"));
if(edenSizeRef != NULL){
CFNumberGetValue(edenSizeRef, kCFNumberSInt64Type, ¶meters->edenSize);
}
codeSizeRef = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoCodeSize"));
if(codeSizeRef != NULL){
CFNumberGetValue(codeSizeRef, kCFNumberSInt64Type, ¶meters->maxCodeSize);
}
argumentsRef = CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("PharoImageParameters"));
if(argumentsRef != NULL){
CFIndex count = CFArrayGetCount(argumentsRef);
for(CFIndex i=0; i < count; i++){
CFStringRef value = CFArrayGetValueAtIndex(argumentsRef, i);
if(value != NULL){
char* valueString = calloc(1, 255+1);
CFStringGetCString(value, valueString, 255 + 1, kCFStringEncodingUTF8);
vm_parameter_vector_insert_from(¶meters->imageParameters, 1, &valueString);
}
}
}
}