@@ -688,41 +688,48 @@ namespace Cvar {
688688 CvarMap& cvars = GetCvarMap ();
689689
690690 bool raw = false ;
691- std::string match = " " ;
691+ std::string pattern = " " ;
692692
693693 // Read parameters
694694 if (args.Argc () > 1 ) {
695- match = args.Argv (1 );
696- if (Cmd::IsSwitch (match , " -raw" )) {
695+ pattern = args.Argv (1 );
696+ if (Cmd::IsSwitch (pattern , " -raw" )) {
697697 raw = true ;
698- match = (args.Argc () > 2 ) ? args.Argv (2 ) : " " ;
698+ pattern = (args.Argc () > 2 ) ? args.Argv (2 ) : " " ;
699699 }
700700 }
701701
702- std::vector<cvarRecord_t*> matches;
702+ struct CvarMatch_t {
703+ std::string name;
704+ cvarRecord_t* record;
705+ };
703706
704- std::vector<std::string> matchesNames;
705- size_t maxNameLength = 0 ;
707+ std::vector<CvarMatch_t> matches;
706708
707- std::vector<std::string> matchesValues ;
709+ size_t maxNameLength = 0 ;
708710
709711 // Find all the matching cvars
710712 for (auto & entry : cvars) {
711- if (Com_Filter (match .c_str (), entry.first .c_str (), false )) {
712- matchesNames. push_back (entry. first ) ;
713+ if (Com_Filter (pattern .c_str (), entry.first .c_str (), false )) {
714+ CvarMatch_t match ;
713715
714- matches.push_back (entry.second );
715- matchesValues.push_back (entry.second ->value );
716+ match.name = entry.first ;
717+ match.record = entry.second ;
718+ matches.push_back (match);
716719
717720 // TODO: the raw parameter is not handled, need a function to escape carets
718- maxNameLength = std::max (maxNameLength, entry. first .length ());
721+ maxNameLength = std::max (maxNameLength, match. name .length ());
719722 }
720723 }
721724
725+ // TODO: case insensitive compare function?
726+ std::sort (matches.begin (), matches.end (),
727+ [](CvarMatch_t &a, CvarMatch_t &b) { return a.name < b.name ; });
728+
722729 // Print the matches, keeping the flags and descriptions aligned
723730 for (size_t i = 0 ; i < matches.size (); i++) {
724- const std::string& name = matchesNames [i];
725- cvarRecord_t* var = matches[i];
731+ const std::string& name = matches [i]. name ;
732+ cvarRecord_t* var = matches[i]. record ;
726733
727734 std::string cvarFlags = " " ;
728735 cvarFlags += (var->flags & SERVERINFO) ? " S" : " _" ;
0 commit comments