From f8d792e82d94cccb48f03da1acae5c7c93cc3b8f Mon Sep 17 00:00:00 2001 From: mfranz Date: Sat, 27 Oct 2007 21:28:56 +0000 Subject: [PATCH] sort entries alphabetically (consistent with property browser) --- src/Network/httpd.cxx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Network/httpd.cxx b/src/Network/httpd.cxx index cdc4dc3dc..700a8c0fb 100644 --- a/src/Network/httpd.cxx +++ b/src/Network/httpd.cxx @@ -31,6 +31,7 @@ #include +#include // sort() #include // atoi() atof() #include STL_STRING @@ -83,6 +84,15 @@ bool FGHttpd::close() { } +class CompareNodes { +public: + bool operator() (const SGPropertyNode_ptr a, const SGPropertyNode_ptr b) const { + int r = strcmp(a->getName(), b->getName()); + return r ? r < 0 : a->getIndex() < b->getIndex(); + } +}; + + // Handle http GET requests void HttpdChannel::foundTerminator (void) { @@ -193,8 +203,15 @@ void HttpdChannel::foundTerminator (void) { response += "\""; response += getTerminator(); - for (int i = 0; i < node->nChildren(); i++) { - SGPropertyNode *child = node->getChild(i); + + vector children; + for (int i = 0; i < node->nChildren(); i++) + children.push_back(node->getChild(i)); + std::sort(children.begin(), children.end(), CompareNodes()); + + vector::iterator it, end = children.end(); + for (it = children.begin(); it != end; ++it) { + SGPropertyNode *child = *it; string name = child->getDisplayName(true); string line = ""; if ( child->nChildren() > 0 ) { -- 2.39.5