MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / showHelp

Function showHelp

modules/dasSQLITE/sqlite/shell.c:19960–20021  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

19958** Return the number of matches.
19959*/
19960static int showHelp(FILE *out, const char *zPattern){
19961 int i = 0;
19962 int j = 0;
19963 int n = 0;
19964 char *zPat;
19965 if( zPattern==0
19966 || zPattern[0]=='0'
19967 || cli_strcmp(zPattern,"-a")==0
19968 || cli_strcmp(zPattern,"-all")==0
19969 || cli_strcmp(zPattern,"--all")==0
19970 ){
19971 /* Show all commands, but only one line per command */
19972 if( zPattern==0 ) zPattern = "";
19973 for(i=0; i<ArraySize(azHelp); i++){
19974 if( azHelp[i][0]=='.' || zPattern[0] ){
19975 utf8_printf(out, "%s\n", azHelp[i]);
19976 n++;
19977 }
19978 }
19979 }else{
19980 /* Look for commands that for which zPattern is an exact prefix */
19981 zPat = sqlite3_mprintf(".%s*", zPattern);
19982 shell_check_oom(zPat);
19983 for(i=0; i<ArraySize(azHelp); i++){
19984 if( sqlite3_strglob(zPat, azHelp[i])==0 ){
19985 utf8_printf(out, "%s\n", azHelp[i]);
19986 j = i+1;
19987 n++;
19988 }
19989 }
19990 sqlite3_free(zPat);
19991 if( n ){
19992 if( n==1 ){
19993 /* when zPattern is a prefix of exactly one command, then include the
19994 ** details of that command, which should begin at offset j */
19995 while( j<ArraySize(azHelp)-1 && azHelp[j][0]!='.' ){
19996 utf8_printf(out, "%s\n", azHelp[j]);
19997 j++;
19998 }
19999 }
20000 return n;
20001 }
20002 /* Look for commands that contain zPattern anywhere. Show the complete
20003 ** text of all commands that match. */
20004 zPat = sqlite3_mprintf("%%%s%%", zPattern);
20005 shell_check_oom(zPat);
20006 for(i=0; i<ArraySize(azHelp); i++){
20007 if( azHelp[i][0]=='.' ) j = i;
20008 if( sqlite3_strlike(zPat, azHelp[i], 0)==0 ){
20009 utf8_printf(out, "%s\n", azHelp[j]);
20010 while( j<ArraySize(azHelp)-1 && azHelp[j+1][0]!='.' ){
20011 j++;
20012 utf8_printf(out, "%s\n", azHelp[j]);
20013 }
20014 i = j;
20015 n++;
20016 }
20017 }

Callers 3

arUsageFunction · 0.85
recoverDatabaseCmdFunction · 0.85
do_meta_commandFunction · 0.85

Calls 3

cli_strcmpFunction · 0.85
utf8_printfFunction · 0.85
shell_check_oomFunction · 0.85

Tested by

no test coverage detected