Chameleon Applications

Chameleon Applications Commit Details

Date:2011-12-06 06:07:56 (6 years 5 days ago)
Author:Rekursor
Commit:453
Parents: 452
Message:Revisited KernelOptionsParser, factorized and fixed one case where autotrim of space between = flags would sometimes eat one more char.
Changes:
M/trunk/ChameleonPrefPane/Sources/KernOptionsParser.h
M/trunk/ChameleonPrefPane/Sources/CenterTextFieldCell.mm
M/trunk/ChameleonPrefPane/Sources/PropertyList.cpp
M/trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp
M/trunk/ChameleonPrefPane/Sources/string_util.h
M/trunk/ChameleonPrefPane/test_util/test_util.xcodeproj/project.pbxproj
M/trunk/ChameleonPrefPane/test_util/test_util.mm

File differences

trunk/ChameleonPrefPane/Sources/string_util.h
8686
8787
8888
89
89
9090
9191
9292
93
94
95
96
97
98
99
100
101
102
93103
94104
95105
{
std::string str = source;
std::string::size_type pos = source.find_first_of(substr);
return pos!=std::string::npos ? str.erase(source.find_first_of(substr) ) : str;
return pos!=std::string::npos ? str.erase(pos) : str;
}
/**
* return the right portion of the string until substr sep is found
*/
inline std::string string_right( const std::string& source, const std::string& substr = " ")
{
std::string str = source;
std::string::size_type pos = source.find_last_of(substr);
return pos!=std::string::npos ? str.erase(0, pos+1) : str;
}
/**
* return the left portion of the string until substr sep is found
*/
inline std::string string_dir_from(const std::string& source)
trunk/ChameleonPrefPane/Sources/PropertyList.cpp
2525
2626
2727
28
28
2929
3030
3131
char * buf = strdup(args);
char lastPriorityDelim=' ';
printf("Parsing <%s>\n", args);
// printf("Parsing <%s>\n", args);
int k=0;
for (int i=0; i< strlen(args); i++)
trunk/ChameleonPrefPane/Sources/CenterTextFieldCell.mm
2020
2121
2222
23
24
}
@end
trunk/ChameleonPrefPane/Sources/KernOptionsParser.h
66
77
88
9
910
1011
1112
......
1920
2021
2122
22
23
24
25
26
2327
2428
25
29
30
31
32
2633
2734
2835
*/
#include <string>
#include <list>
#include "string_util.h"
class KernOptionsParser
{
const std::string& stringFromKey(const std::string& key) const;
// get the left member of kern option "xxxx=yyyy"
const std::string& leftMember(const std::string& expression) const;
inline std::string leftMember(const std::string& expression) const
{
return string_left(expression, "=");
}
// get the right member of kern option "xxxx=yyyy"
const std::string& rightMember(const std::string& expression) const;
inline std::string rightMember(const std::string& expression) const
{
return string_right(expression, "=");
}
// add / remove a kernel Flags in the string
void addFlag(const std::string& flag);
trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp
1515
1616
1717
18
19
18
19
2020
2121
2222
......
3535
3636
3737
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
5938
6039
6140
6241
6342
6443
65
44
6645
6746
6847
......
8160
8261
8362
84
63
8564
8665
8766
// first remove spaces around '=' to simplify parsing
std::string::size_type found = std::string::npos;
while ((found=_options.find(" =")) != std::string::npos) _options.replace(found, 3,"=");
while ((found=_options.find("= ")) != std::string::npos) _options.replace(found, 3,"=");
while ((found=_options.find(" =")) != std::string::npos) _options.replace(found, 2,"=");
while ((found=_options.find("= ")) != std::string::npos) _options.replace(found, 2,"=");
// then tokenize the string
_optionsList = tokenize(_options);
return sEmpty;
}
// get the left member of kern option "xxxx=yyyy"
const std::string& KernOptionsParser::leftMember(const std::string& expression) const
{
static std::string sLeft;
std::string::size_type pos = expression.find('=');
if (pos!=std::string::npos)
return (sLeft = expression.substr(0, pos));
return expression;
}
// get the right member of kern option "xxxx=yyyy"
const std::string& KernOptionsParser::rightMember(const std::string& expression) const
{
static std::string sLeft;
std::string::size_type pos = expression.find('=');
if (pos!=std::string::npos)
return (sLeft = expression.substr(pos+1));
return expression;
}
// remove a flag in the string
void KernOptionsParser::removeFlag(const std::string& flag)
{
if (flag.length()==0) return; // not a flag, bye
std::string::size_type pos, l = _options.length();
if (l==0) return; // empty options nothing to do
std::string f = string_left(flag, "=");
std::string f = leftMember(flag);
std::string::size_type found = _options.find(f);
if (found==std::string::npos) return;
// find the end of the flag
std::string::size_type found = _options.find(key);
if (found!=std::string::npos)
removeFlag(key);
_options = " " + _options;
_options = " " + _options;
_options = flag + _options;
_options = trim(_options);
}
trunk/ChameleonPrefPane/test_util/test_util.mm
1111
1212
1313
14
15
16
1417
1518
1619
......
7376
7477
7578
76
77
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
7895
7996
#import "PartitionInfoManager.h"
#import "SmbiosExtractor.h"
#import "ShellProcess.h"
#include "string_util.h"
#include <string>
#include <iostream>
void testDiskInfoWith(NSString * bsd)
{
testDiskInfoWith(@"disk0s2");
testDiskInfoWith(@"disk0s3");
#endif
[pool drain];
fprintf(stderr, "String Test\n");
std::string options = "-v darkwake ab= a=0 =abc -f";
fprintf(stderr, "options = %s\n", options.c_str() );
std::list<std::string> l = tokenize(options, " ");
std::list<std::string>::const_iterator it = l.begin();
for (; it != l.end(); it++)
{
std::string s = *it;
std::cerr << "token: " << s
<< ", left: " << string_left(s, "=")
<< ", right: " << string_right(s, "=")
<< ", trim: " << trim(s)
<< std::endl;
}
[pool drain];
return 0;
}
trunk/ChameleonPrefPane/test_util/test_util.xcodeproj/project.pbxproj
33
44
55
6
6
77
88
99
......
199199
200200
201201
202
203
204
202205
203
206
204207
205208
206209
......
245248
246249
247250
248
249251
250252
251253
......
278280
279281
280282
281
282283
283284
284285
......
291292
292293
293294
294
295295
296296
297297
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
/* Begin PBXProject section */
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "test_util" */;
compatibilityVersion = "Xcode 3.1";
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
};
name = Debug;
GCC_ENABLE_OBJC_GC = supported;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
};
name = Release;

Archive Download the corresponding diff file

Revision: 453