** Output help text. ** ** zPattern describes the set of commands for which help text is provided. ** If zPattern is NULL, then show all commands, but only give a one-line ** description of each. ** ** Return the number of matches. */
| 14265 | ** Return the number of matches. |
| 14266 | */ |
| 14267 | static int showHelp(FILE *out, const char *zPattern){ |
| 14268 | int i = 0; |
| 14269 | int j = 0; |
| 14270 | int n = 0; |
| 14271 | char *zPat; |
| 14272 | if( zPattern==0 |
| 14273 | || zPattern[0]=='0' |
| 14274 | || strcmp(zPattern,"-a")==0 |
| 14275 | || strcmp(zPattern,"-all")==0 |
| 14276 | || strcmp(zPattern,"--all")==0 |
| 14277 | ){ |
| 14278 | /* Show all commands, but only one line per command */ |
| 14279 | if( zPattern==0 ) zPattern = ""; |
| 14280 | for(i=0; i<ArraySize(azHelp); i++){ |
| 14281 | if( azHelp[i][0]=='.' || zPattern[0] ){ |
| 14282 | utf8_printf(out, "%s\n", azHelp[i]); |
| 14283 | n++; |
| 14284 | } |
| 14285 | } |
| 14286 | }else{ |
| 14287 | /* Look for commands that for which zPattern is an exact prefix */ |
| 14288 | zPat = sqlite3_mprintf(".%s*", zPattern); |
| 14289 | for(i=0; i<ArraySize(azHelp); i++){ |
| 14290 | if( sqlite3_strglob(zPat, azHelp[i])==0 ){ |
| 14291 | utf8_printf(out, "%s\n", azHelp[i]); |
| 14292 | j = i+1; |
| 14293 | n++; |
| 14294 | } |
| 14295 | } |
| 14296 | sqlite3_free(zPat); |
| 14297 | if( n ){ |
| 14298 | if( n==1 ){ |
| 14299 | /* when zPattern is a prefix of exactly one command, then include the |
| 14300 | ** details of that command, which should begin at offset j */ |
| 14301 | while( j<ArraySize(azHelp)-1 && azHelp[j][0]!='.' ){ |
| 14302 | utf8_printf(out, "%s\n", azHelp[j]); |
| 14303 | j++; |
| 14304 | } |
| 14305 | } |
| 14306 | return n; |
| 14307 | } |
| 14308 | /* Look for commands that contain zPattern anywhere. Show the complete |
| 14309 | ** text of all commands that match. */ |
| 14310 | zPat = sqlite3_mprintf("%%%s%%", zPattern); |
| 14311 | for(i=0; i<ArraySize(azHelp); i++){ |
| 14312 | if( azHelp[i][0]=='.' ) j = i; |
| 14313 | if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){ |
| 14314 | utf8_printf(out, "%s\n", azHelp[j]); |
| 14315 | while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]!='.' ){ |
| 14316 | j++; |
| 14317 | utf8_printf(out, "%s\n", azHelp[j]); |
| 14318 | } |
| 14319 | i = j; |
| 14320 | n++; |
| 14321 | } |
| 14322 | } |
| 14323 | sqlite3_free(zPat); |
| 14324 | } |
no test coverage detected