1
0
Fork 0

Modified Files:

options.cxx: Olaf Flebbe: Fix some problems with --help --verbose
	caused by the usage of snprintf. Elimate snprintf usage in favour
	plain std::string manipulations.
This commit is contained in:
frohlich 2007-01-02 08:32:32 +00:00
parent 82d4fc6583
commit f63c96bf0e

View file

@ -1673,7 +1673,16 @@ fgUsage (bool verbose)
tmp.append(", -"); tmp.append(", -");
tmp.append(short_name->getStringValue()); tmp.append(short_name->getStringValue());
} }
if (tmp.size() <= 25) {
msg+= " --";
msg += tmp;
msg.append( 27-tmp.size(), ' ');
} else {
msg += "\n --";
msg += tmp + '\n';
msg.append(32, ' ');
}
char cstr[96]; char cstr[96];
if (tmp.size() <= 25) { if (tmp.size() <= 25) {
snprintf(cstr, 96, " --%-27s", tmp.c_str()); snprintf(cstr, 96, " --%-27s", tmp.c_str());
@ -1684,10 +1693,8 @@ fgUsage (bool verbose)
// There may be more than one <description> tag assosiated // There may be more than one <description> tag assosiated
// with one option // with one option
msg += cstr; vector<SGPropertyNode_ptr> desc;
vector<SGPropertyNode_ptr>desc = desc = option[k]->getChildren("description");
option[k]->getChildren("description");
if (desc.size() > 0) { if (desc.size() > 0) {
for ( unsigned int l = 0; l < desc.size(); l++) { for ( unsigned int l = 0; l < desc.size(); l++) {
@ -1702,9 +1709,7 @@ fgUsage (bool verbose)
string t_str = trans_desc[m]->getStringValue(); string t_str = trans_desc[m]->getStringValue();
if ((m > 0) || ((l > 0) && m == 0)) { if ((m > 0) || ((l > 0) && m == 0)) {
snprintf(cstr, 96, "%32c", ' '); msg.append( 32, ' ');
msg += cstr;
} }
// If the string is too large to fit on the screen, // If the string is too large to fit on the screen,
@ -1713,9 +1718,8 @@ fgUsage (bool verbose)
while ( t_str.size() > 47 ) { while ( t_str.size() > 47 ) {
unsigned int m = t_str.rfind(' ', 47); unsigned int m = t_str.rfind(' ', 47);
msg += t_str.substr(0, m); msg += t_str.substr(0, m) + '\n';
snprintf(cstr, 96, "\n%32c", ' '); msg.append( 32, ' ');
msg += cstr;
t_str.erase(t_str.begin(), t_str.begin() + m + 1); t_str.erase(t_str.begin(), t_str.begin() + m + 1);
} }
@ -1726,8 +1730,8 @@ fgUsage (bool verbose)
} }
} }
SGPropertyNode *name = SGPropertyNode *name;
locale->getNode(section[j]->getStringValue("name")); name = locale->getNode(section[j]->getStringValue("name"));
if (!msg.empty() && name) { if (!msg.empty() && name) {
cout << endl << name->getStringValue() << ":" << endl; cout << endl << name->getStringValue() << ":" << endl;
@ -1810,25 +1814,27 @@ static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
status = node->getNode("status"); status = node->getNode("status");
} }
char cstr[96]; //additionally display status information where it is available
//additionally display status information where it is available
if (strlen(dire->d_name) <= 27) {
snprintf(cstr, 96, " %-27s %s", dire->d_name,
(desc) ? desc->getStringValue() : "");
} else { string descStr(" ");
snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ', descStr += dire->d_name;
(desc) ? desc->getStringValue() : ""); if (desc) {
if (descStr.size() <= 27+3) {
descStr.append(29+3-descStr.size(), ' ');
} else {
descStr += '\n';
descStr.append( 32, ' ');
}
descStr += desc->getStringValue();
} }
SGPropertyNode * required_status SGPropertyNode * required_status
= fgGetNode ("/sim/aircraft-min-status", true); = fgGetNode ("/sim/aircraft-min-status", true);
// If the node holds the value "all", then there wasn't any status // If the node holds the value "all", then there wasn't any status
// level specified, so we simply go ahead and output ALL aircraft // level specified, so we simply go ahead and output ALL aircraft
if (strcmp(required_status->getStringValue(),"all")==0) { if (strcmp(required_status->getStringValue(),"all")==0) {
aircraft.push_back(cstr); aircraft.push_back(descStr);
} }
else else
{ {
@ -1840,7 +1846,7 @@ static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
//Compare (minimally) required status level with actual aircraft status: //Compare (minimally) required status level with actual aircraft status:
if ( getNumMaturity(status->getStringValue() ) >= if ( getNumMaturity(status->getStringValue() ) >=
getNumMaturity(required_status->getStringValue() ) ) getNumMaturity(required_status->getStringValue() ) )
aircraft.push_back(cstr); } aircraft.push_back(descStr); }
} }