@@ -27,14 +27,17 @@ const Command* getCommandByName(const char *s) {
2727 const char *prefix = " base:" ;
2828 const char *check = strncmp (s, prefix, strlen (prefix)) == 0 ? s + strlen (prefix) : s;
2929
30- for (size_t i = 0 ; i < commands.size (); i++ ) {
30+ for (size_t i = commands.size () - 1 ; true ; i-- ) {
3131 for (size_t j = 0 ; j < commands[i]->size (); j++) {
3232 const Command &p = (*commands[i])[j];
3333 if (!strcmp (s, p.cmd ))
3434 return &p;
3535 if (i == 0 && !strcmp (check, p.cmd ))
3636 return &p;
3737 }
38+ if (i == 0 ) {
39+ break ;
40+ }
3841 }
3942 return NULL ;
4043}
@@ -60,14 +63,17 @@ void printUsage(bool showExtended) {
6063 if (hide_base_commands) {
6164 start = commands.size () - 1 ;
6265 }
63- for (size_t j = start; j < commands.size (); j++ ) {
66+ for (size_t j = commands.size () - 1 ; j >= start; j-- ) {
6467 for (size_t k = 0 ; k < commands[j]->size (); k++) {
6568 const Command &p = (*commands[j])[k];
6669 if (p.mode & categories[i].mode ) {
6770 showCategoryHeader[i] = 1 ;
6871 break ;
6972 }
7073 }
74+ if (j == 0 ) {
75+ break ;
76+ }
7177 }
7278 }
7379
@@ -87,12 +93,12 @@ void printUsage(bool showExtended) {
8793 }
8894
8995 usage << " \n " << std::setw (20 ) << categories[i].title << " \n " ;
90- for ( size_t j = 0 ; j < commands. size (); j++) {
91- size_t start = 0 ;
92- if (hide_base_commands) {
93- start = commands. size () - 1 ;
94- }
95- for (size_t k = start ; k < commands[j]->size (); k++) {
96+ size_t start = 0 ;
97+ if (hide_base_commands) {
98+ start = commands. size () - 1 ;
99+ }
100+ for ( size_t j = commands. size () - 1 ; j >= start; j--) {
101+ for (size_t k = 0 ; k < commands[j]->size (); k++) {
96102 const Command &p = (*commands[j])[k];
97103 if (showExtended == false && (p.mode & COMMAND_EXPERT) != 0 ) {
98104 continue ;
@@ -101,6 +107,9 @@ void printUsage(bool showExtended) {
101107 usage << std::left << std::setw (20 ) << " " + std::string (p.cmd ) << " \t " << p.description << " \n " ;
102108 }
103109 }
110+ if (j == 0 ) {
111+ break ;
112+ }
104113 }
105114 }
106115
@@ -118,29 +127,32 @@ void printUsage(bool showExtended) {
118127int shellcompletion (int argc, const char **argv) {
119128 // mmseqs programs
120129 if (argc == 0 ) {
121- for ( size_t i = 0 ; i < commands. size (); i++) {
122- size_t start = 0 ;
123- if (hide_base_commands) {
124- start = commands. size () - 1 ;
125- }
126- for (size_t j = start ; j < commands[i]->size (); j++) {
130+ size_t start = 0 ;
131+ if (hide_base_commands) {
132+ start = commands. size () - 1 ;
133+ }
134+ for ( size_t i = commands. size () - 1 ; i >= start; i--) {
135+ for (size_t j = 0 ; j < commands[i]->size (); j++) {
127136 const Command &p = (*commands[i])[j];
128137 if (p.mode & COMMAND_HIDDEN)
129138 continue ;
130139 Debug (Debug::INFO) << p.cmd << " " ;
131140 }
141+ if (i == 0 ) {
142+ break ;
143+ }
132144 }
133145 Debug (Debug::INFO) << " \n " ;
134146 }
135147
136148 // mmseqs parameters for given program
137149 if (argc == 1 ) {
138- for ( size_t i = 0 ; i < commands. size (); i++) {
139- size_t start = 0 ;
140- if (hide_base_commands) {
141- start = commands. size () - 1 ;
142- }
143- for (size_t j = start ; j < commands[i]->size (); j++) {
150+ size_t start = 0 ;
151+ if (hide_base_commands) {
152+ start = commands. size () - 1 ;
153+ }
154+ for ( size_t i = commands. size () - 1 ; i >= start; i--) {
155+ for (size_t j = 0 ; j < commands[i]->size (); j++) {
144156 const Command &p = (*commands[i])[j];
145157 if (strcmp (p.cmd , argv[0 ]) != 0 ) {
146158 continue ;
@@ -154,6 +166,9 @@ int shellcompletion(int argc, const char **argv) {
154166 Debug (Debug::INFO) << " \n " ;
155167 break ;
156168 }
169+ if (i == 0 ) {
170+ break ;
171+ }
157172 }
158173 Debug (Debug::INFO) << " \n " ;
159174 }
@@ -194,12 +209,12 @@ int main(int argc, const char **argv) {
194209 size_t indexI = SIZE_MAX;
195210 size_t indexJ = SIZE_MAX;
196211 int maxDistance = 0 ;
197- for ( size_t i = 0 ; i < commands. size (); i++) {
198- size_t start = 0 ;
199- if (hide_base_commands) {
200- start = commands. size () - 1 ;
201- }
202- for (size_t j = start ; j < commands[i]->size (); j++) {
212+ size_t start = 0 ;
213+ if (hide_base_commands) {
214+ start = commands. size () - 1 ;
215+ }
216+ for ( size_t i = commands. size () - 1 ; i >= start; i--) {
217+ for (size_t j = 0 ; j < commands[i]->size (); j++) {
203218 const Command &p = (*commands[i])[j];
204219 if (p.mode & COMMAND_HIDDEN) {
205220 continue ;
@@ -212,6 +227,9 @@ int main(int argc, const char **argv) {
212227 indexJ = j;
213228 }
214229 }
230+ if (i == 0 ) {
231+ break ;
232+ }
215233 }
216234
217235 if (indexI != SIZE_MAX && indexJ != SIZE_MAX) {
0 commit comments