/* ** Copyright (c) 2016 D. Richard Hipp ** ** This program is free software; you can redistribute it and/or ** modify it under the terms of the Simplified BSD License (also ** known as the "2-Clause License" or "FreeBSD License".) ** ** This program is distributed in the hope that it will be useful, ** but without any warranty; without even the implied warranty of ** merchantability or fitness for a particular purpose. ** ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ******************************************************************************* ** ** This file contains code used to map command names (ex: "help", "commit", ** "diff") or webpage names (ex: "/timeline", "/search") into the functions ** that implement those commands and web pages and their associated help ** text. */ #include "config.h" #include #include "dispatch.h" #if INTERFACE /* ** An instance of this object defines everything we need to know about an ** individual command, webpage, or setting. */ struct CmdOrPage { const char *zName; /* Name. Webpages start with "/". Commands do not */ void (*xFunc)(void); /* Implementation function, or NULL for settings */ const char *zHelp; /* Raw help text */ unsigned int eCmdFlags; /* Flags */ }; /*************************************************************************** ** These macros must match similar macros in mkindex.c ** Allowed values for CmdOrPage.eCmdFlags. */ #define CMDFLAG_1ST_TIER 0x0001 /* Most important commands */ #define CMDFLAG_2ND_TIER 0x0002 /* Obscure and seldom used commands */ #define CMDFLAG_TEST 0x0004 /* Commands for testing only */ #define CMDFLAG_WEBPAGE 0x0008 /* Web pages */ #define CMDFLAG_COMMAND 0x0010 /* A command */ #define CMDFLAG_SETTING 0x0020 /* A setting */ #define CMDFLAG_VERSIONABLE 0x0040 /* A versionable setting */ #define CMDFLAG_BLOCKTEXT 0x0080 /* Multi-line text setting */ #define CMDFLAG_BOOLEAN 0x0100 /* A boolean setting */ #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret POST content */ /**************************************************************************/ /* Values for the 2nd parameter to dispatch_name_search() */ #define CMDFLAG_ANY 0x0038 /* Match anything */ #define CMDFLAG_PREFIX 0x0200 /* Prefix match is ok */ #endif /* INTERFACE */ /* ** The page_index.h file contains the definition for aCommand[] - an array ** of CmdOrPage objects that defines all available commands and webpages ** known to Fossil. ** ** The entries in aCommand[] are in sorted order by name. Since webpage names ** always begin with "/", all webpage names occur first. The page_index.h file ** also sets the FOSSIL_FIRST_CMD macro to be the *approximate* index ** in aCommand[] of the first command entry. FOSSIL_FIRST_CMD might be ** slightly too low, and so the range FOSSIL_FIRST_CMD...MX_COMMAND might ** contain a few webpage entries at the beginning. ** ** The page_index.h file is generated by the mkindex program which scans all ** source code files looking for header comments on the functions that ** implement command and webpages. */ #include "page_index.h" #define MX_COMMAND count(aCommand) /* ** Given a command, webpage, or setting name in zName, find the corresponding ** CmdOrPage object and return a pointer to that object in *ppCmd. ** ** The eType field is CMDFLAG_COMMAND to look up commands, CMDFLAG_WEBPAGE to ** look up webpages, CMDFLAG_SETTING to look up settings, or CMDFLAG_ANY to look ** for any. If the CMDFLAG_PREFIX bit is set, then a prefix match is allowed. ** ** Return values: ** 0: Success. *ppCmd is set to the appropriate CmdOrPage ** 1: Not found. ** 2: Ambiguous. Two or more entries match. */ int dispatch_name_search( const char *zName, /* Look for this name */ unsigned eType, /* CMDFLAGS_* bits */ const CmdOrPage **ppCmd /* Write the matching CmdOrPage object here */ ){ int upr, lwr, mid; int nName = strlen(zName); lwr = 0; upr = MX_COMMAND - 1; while( lwr<=upr ){ int c; mid = (upr+lwr)/2; c = strcmp(zName, aCommand[mid].zName); if( c==0 ){ if( (aCommand[mid].eCmdFlags & eType)==0 ) return 1; *ppCmd = &aCommand[mid]; return 0; /* An exact match */ }else if( c<0 ){ upr = mid - 1; }else{ lwr = mid + 1; } } if( (eType & CMDFLAG_PREFIX)!=0 && lwr=0 ){ *ppCmd = &aCommand[mid]; return 0; /* Prefix match */ } } return 1; /* Not found */ } /* ** zName is the name of a webpage (eType==CMDFLAGS_WEBPAGE) that does not ** exist in the dispatch table. Check to see if this webpage name exists ** as an alias in the CONFIG table of the repository. If it is, then make ** appropriate changes to the CGI environment and set *ppCmd to point to the ** aliased command. ** ** Return 0 if the command is successfully aliased. Return 1 if there ** is not alias for zName. Any kind of error in the alias value causes a ** error to be thrown. ** ** Alias entries in the CONFIG table have a "name" value of "walias:NAME" ** where NAME is the input page name. The value is a string of the form ** "NEWNAME?QUERYPARAMS". The ?QUERYPARAMS is optional. If present (and it ** usually is), then all query parameters are added to the CGI environment. ** Except, query parameters of the form "X!" cause any CGI X variable to be ** removed. */ int dispatch_alias(const char *zName, const CmdOrPage **ppCmd){ char *z; char *zQ; int i; z = db_text(0, "SELECT value FROM config WHERE name='walias:%q'",zName); if( z==0 ) return 1; for(i=0; z[i] && z[i]!='?'; i++){} if( z[i]=='?' ){ z[i] = 0; zQ = &z[i+1]; }else{ zQ = &z[i]; } if( dispatch_name_search(z, CMDFLAG_WEBPAGE, ppCmd) ){ fossil_fatal("\"%s\" aliased to \"%s\" but \"%s\" does not exist", zName, z, z); } z = zQ; while( *z ){ char *zName = z; char *zValue = 0; while( *z && *z!='=' && *z!='&' && *z!='!' ){ z++; } if( *z=='=' ){ *z = 0; z++; zValue = z; while( *z && *z!='&' ){ z++; } if( *z ){ *z = 0; z++; } dehttpize(zValue); }else if( *z=='!' ){ *(z++) = 0; cgi_delete_query_parameter(zName); zName = ""; }else{ if( *z ){ *z++ = 0; } zValue = ""; } if( fossil_islower(zName[0]) ){ cgi_replace_query_parameter(zName, zValue); }else if( fossil_isupper(zName[0]) ){ cgi_replace_query_parameter_tolower(zName, zValue); } } return 0; } /* ** Fill Blob with a space-separated list of all command names that ** match the prefix zPrefix. */ void dispatch_matching_names(const char *zPrefix, Blob *pList){ int i; int nPrefix = (int)strlen(zPrefix); for(i=FOSSIL_FIRST_CMD; i & and " ** * Change "%fossil" to just "fossil" */ static void appendLinked(Blob *pOut, const char *z, int n){ int i = 0; int j; while( i0 ){ if( i ) blob_append(pOut, z, i); z += i+2; n -= i+2; blob_appendf(pOut, "%.*s", j-3, z, j-3, z); z += j-1; n -= j-1; i = 0; }else if( c=='%' && n-i>=7 && strncmp(z+i,"%fossil",7)==0 ){ if( i ) blob_append(pOut, z, i); z += i+7; n -= i+7; blob_append(pOut, "fossil", 6); i = 0; }else if( c=='<' ){ if( i ) blob_append(pOut, z, i); blob_append(pOut, "<", 4); z += i+1; n -= i+1; i = 0; }else if( c=='>' ){ if( i ) blob_append(pOut, z, i); blob_append(pOut, ">", 4); z += i+1; n -= i+1; i = 0; }else if( c=='&' ){ if( i ) blob_append(pOut, z, i); blob_append(pOut, "&", 5); z += i+1; n -= i+1; i = 0; }else{ i++; } } blob_append(pOut, z, i); } /* ** Append text to pOut, adding formatting markup. Terms that ** have all lower-case letters are within ... Terms ** that have all upper-case letters are within ... */ static void appendMixedFont(Blob *pOut, const char *z, int n){ const char *zEnd = ""; int i = 0; int j; while( i=n || z[j]==' ' || z[j]=='=' ){ zEnd = ""; }else{ if( fossil_isupper(z[j]) && z[i]!='-' ){ blob_append(pOut, "",3); zEnd = ""; }else{ blob_append(pOut, "", 4); zEnd = ""; } } while( j elements can begin ** on the same line as long as they are separated by at least ** two spaces. ** ** * Indented text is show verbatim (
...
) */ static void help_to_html(const char *zHelp, Blob *pHtml){ int i; char c; int nIndent = 0; int wantP = 0; int wantBR = 0; int aIndent[10]; const char *azEnd[10]; int iLevel = 0; int isLI = 0; int isDT = 0; static const char *zEndDL = ""; static const char *zEndPRE = ""; static const char *zEndUL = ""; static const char *zEndDD = ""; aIndent[0] = 0; azEnd[0] = ""; while( zHelp[0] ){ i = 0; while( (c = zHelp[i])!=0 && c!='\n' ){ if( c=='%' && i>2 && zHelp[i-2]==':' && strncmp(zHelp+i,"%fossil",7)==0 ){ appendLinked(pHtml, zHelp, i); zHelp += i+1; i = 0; wantBR = 1; continue; } i++; } if( i>2 && zHelp[0]=='>' && zHelp[1]==' ' ){ isDT = 1; for(nIndent=1; nIndent */ }else{ blob_append_char(pHtml, '\n'); } wantP = 1; wantBR = 0; zHelp += i+1; continue; } if( nIndent+20 && aIndent[iLevel]>nIndent ){ blob_append(pHtml, azEnd[iLevel--], -1); } if( nIndent>aIndent[iLevel] ){ assert( iLevel\n", 5); }else if( isDT || zHelp[nIndent]=='-' || hasGap(zHelp+nIndent,i-nIndent) ){ iLevel++; aIndent[iLevel] = nIndent; azEnd[iLevel] = zEndDL; blob_append(pHtml, "
\n", -1); }else if( azEnd[iLevel]==zEndDL ){ iLevel++; aIndent[iLevel] = nIndent; azEnd[iLevel] = zEndDD; blob_append(pHtml, "
", 4); }else if( wantP ){ iLevel++; aIndent[iLevel] = nIndent; azEnd[iLevel] = zEndPRE; blob_append(pHtml, "
", -1);
        wantP = 0;
      }
    }
    if( isLI ){
      blob_append(pHtml, "
  • ", 5); } if( wantP ){ blob_append(pHtml, "

    ", 4); wantP = 0; } if( azEnd[iLevel]==zEndDL ){ int iDD; blob_append(pHtml, "

    ", 5); iDD = hasGap(zHelp+nIndent, i-nIndent); if( iDD ){ int x; assert( iLevel
    ",9); appendLinked(pHtml, zHelp+x, i-x); }else{ appendMixedFont(pHtml, zHelp+nIndent, i-nIndent); } blob_append(pHtml, "\n", 6); }else if( wantBR ){ appendMixedFont(pHtml, zHelp+nIndent, i-nIndent); blob_append(pHtml, "
    \n", 5); wantBR = 0; }else{ appendLinked(pHtml, zHelp+nIndent, i-nIndent); blob_append_char(pHtml, '\n'); } zHelp += i+1; i = 0; if( c==0 ) break; } while( iLevel>0 ){ blob_appendf(pHtml, "%s\n", azEnd[iLevel--]); } } /* ** Format help text for TTY display. */ static void help_to_text(const char *zHelp, Blob *pText){ int i, x; char c; for(i=0; (c = zHelp[i])!=0; i++){ if( c=='%' && strncmp(zHelp+i,"%fossil",7)==0 ){ if( i>0 ) blob_append(pText, zHelp, i); blob_append(pText, "fossil", 6); zHelp += i+7; i = -1; continue; } if( c=='\n' && strncmp(zHelp+i+1,"> ",2)==0 ){ blob_append(pText, zHelp, i+1); blob_append(pText, " ", 1); zHelp += i+2; i = -1; continue; } if( c=='[' && (x = help_is_link(zHelp+i, 100000))!=0 ){ if( i>0 ) blob_append(pText, zHelp, i); zHelp += i+2; blob_append(pText, zHelp, x-3); zHelp += x-1; i = -1; continue; } } if( i>0 ){ blob_append(pText, zHelp, i); } } /* ** COMMAND: test-all-help ** ** Usage: %fossil test-all-help ?OPTIONS? ** ** Show help text for commands and pages. Useful for proof-reading. ** Defaults to just the CLI commands. Specify --www to see only the ** web pages, or --everything to see both commands and pages. ** ** Options: ** -e|--everything Show all commands and pages. ** -t|--test Include test- commands ** -w|--www Show WWW pages. ** -s|--settings Show settings. ** -h|--html Transform output to HTML. ** -r|--raw No output formatting. */ void test_all_help_cmd(void){ int i; int mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER; int useHtml = find_option("html","h",0)!=0; int rawOut = find_option("raw","r",0)!=0; if( find_option("www","w",0) ){ mask = CMDFLAG_WEBPAGE; } if( find_option("everything","e",0) ){ mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE | CMDFLAG_SETTING | CMDFLAG_TEST; } if( find_option("settings","s",0) ){ mask = CMDFLAG_SETTING; } if( find_option("test","t",0) ){ mask |= CMDFLAG_TEST; } if( useHtml ) fossil_print("\n"); fossil_print("\n"); }else{ fossil_print("---\n"); } for(i=0; i%h\n", aCommand[i].zName); fossil_print("%s\n
    \n", blob_str(&html)); blob_reset(&html); }else if( rawOut ){ fossil_print("# %s\n", aCommand[i].zName); fossil_print("%s\n\n", aCommand[i].zHelp); }else{ Blob txt; blob_init(&txt, 0, 0); help_to_text(aCommand[i].zHelp, &txt); fossil_print("# %s\n", aCommand[i].zName); fossil_print("%s\n\n", blob_str(&txt)); blob_reset(&txt); } } if( useHtml ){ fossil_print("\n"); }else{ fossil_print("---\n"); } version_cmd(); } /* ** Count the number of entries in the aCommand[] table that match ** the given flag. */ static int countCmds(unsigned int eFlg){ int n = 0; int i; for(i=0; ip1+2 ) m = p1+2; if( m>p0+3 ) m = p0+3; } c0 = a[j]; a[j] = m; p0 = p1; } } m = a[nB-1]; for(j=0; j=nArray ) return n; }else if( m=mxScore ) break; mnScore = bestScore; } return n; } /* ** COMMAND: test-approx-match ** ** Test the approximate match algorithm */ void test_approx_match_command(void){ int i, j, n; const char *az[20]; for(i=2; i...
  • , as if it were ** displayed using the "fossil help" command. ** ** raw Show the raw help text without any formatting. ** (Used for debugging.) */ void help_page(void){ const char *zCmd = P("cmd"); if( zCmd==0 ) zCmd = P("name"); if( zCmd && *zCmd ){ int rc; const CmdOrPage *pCmd = 0; style_header("Help: %s", zCmd); style_submenu_element("Command-List", "%s/help", g.zTop); rc = dispatch_name_search(zCmd, CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd); if( *zCmd=='/' ){ /* Some of the webpages require query parameters in order to work. ** @

    The "%s(zCmd)" page:

    */ @

    The "%h(zCmd)" page:

    }else if( rc==0 && (pCmd->eCmdFlags & CMDFLAG_SETTING)!=0 ){ @

    The "%h(pCmd->zName)" setting:

    }else{ @

    The "%h(zCmd)" command:

    } if( rc==1 ){ @ unknown command: %h(zCmd) }else if( rc==2 ){ @ ambiguous command prefix: %h(zCmd) }else{ if( pCmd->zHelp[0]==0 ){ @ No help available for "%h(pCmd->zName)" }else if( P("plaintext") ){ Blob txt; blob_init(&txt, 0, 0); help_to_text(pCmd->zHelp, &txt); @
            @ %h(blob_str(&txt))
            @ 
    blob_reset(&txt); }else if( P("raw") ){ @
            @ %h(pCmd->zHelp)
            @ 
    }else{ @
    help_to_html(pCmd->zHelp, cgi_output_blob()); @
    } } }else{ int i; style_header("Help"); @ @

    Available commands:

    @
    @
      for(i=0; i" :""; const char *zBoldOff = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"":""; if( '/'==*z || strncmp(z,"test",4)==0 ) continue; if( (aCommand[i].eCmdFlags & CMDFLAG_SETTING)!=0 ) continue; @
    • %s(zBoldOn)%s(z)%s(zBoldOff)
    • } @
    @ @

    Available web UI pages:

    @
    @
      for(i=0; i%s(z+1) }else{ @
    • %s(z+1)
    • } } @
    @ @

    Unsupported commands:

    @
    @
      for(i=0; i%s(z) }else{ @
    • %s(z)
    • } } @
    @ @

    Settings:

    @
    @
      for(i=0; i%s(z) }else{ @
    • %s(z)
    • } } @
    } style_footer(); } /* ** WEBPAGE: test-all-help ** ** Show all help text on a single page. Useful for proof-reading. */ void test_all_help_page(void){ int i; Blob buf; blob_init(&buf,0,0); style_header("All Help Text"); @
    for(i=0; i%s(aCommand[i].zName) (%s(zDesc)) @
    help_to_html(aCommand[i].zHelp, cgi_output_blob()); @
    } @
    blob_reset(&buf); style_footer(); } static void multi_column_list(const char **azWord, int nWord){ int i, j, len; int mxLen = 0; int nCol; int nRow; for(i=0; imxLen ) mxLen = len; } nCol = 80/(mxLen+2); if( nCol==0 ) nCol = 1; nRow = (nWord + nCol - 1)/nCol; for(i=0; izHelp; if( z==0 ){ fossil_fatal("no help available for the %s %s", pCmd->zName, zCmdOrPage); } if( pCmd->eCmdFlags & CMDFLAG_SETTING ){ fossil_print("Setting: \"%s\"%s\n\n", pCmd->zName, (pCmd->eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ? " (versionable)" : "" ); } blob_init(&txt, 0, 0); if( useHtml ){ help_to_html(z, &txt); }else{ help_to_text(z, &txt); } fossil_print("%s\n", blob_str(&txt)); blob_reset(&txt); } /* ** Return a pointer to the setting information array. ** ** This routine provides access to the aSetting2[] array which is created ** by the mkindex utility program and included with . */ const Setting *setting_info(int *pnCount){ if( pnCount ) *pnCount = (int)(sizeof(aSetting)/sizeof(aSetting[0])) - 1; return aSetting; } /***************************************************************************** ** A virtual table for accessing the information in aCommand[], and ** especially the help-text */ /* helptextVtab_vtab is a subclass of sqlite3_vtab which is ** underlying representation of the virtual table */ typedef struct helptextVtab_vtab helptextVtab_vtab; struct helptextVtab_vtab { sqlite3_vtab base; /* Base class - must be first */ /* Add new fields here, as necessary */ }; /* helptextVtab_cursor is a subclass of sqlite3_vtab_cursor which will ** serve as the underlying representation of a cursor that scans ** over rows of the result */ typedef struct helptextVtab_cursor helptextVtab_cursor; struct helptextVtab_cursor { sqlite3_vtab_cursor base; /* Base class - must be first */ /* Insert new fields here. For this helptextVtab we only keep track ** of the rowid */ sqlite3_int64 iRowid; /* The rowid */ }; /* ** The helptextVtabConnect() method is invoked to create a new ** helptext virtual table. ** ** Think of this routine as the constructor for helptextVtab_vtab objects. ** ** All this routine needs to do is: ** ** (1) Allocate the helptextVtab_vtab object and initialize all fields. ** ** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the ** result set of queries against the virtual table will look like. */ static int helptextVtabConnect( sqlite3 *db, void *pAux, int argc, const char *const*argv, sqlite3_vtab **ppVtab, char **pzErr ){ helptextVtab_vtab *pNew; int rc; rc = sqlite3_declare_vtab(db, "CREATE TABLE x(name,type,flags,helptext,formatted,html)" ); if( rc==SQLITE_OK ){ pNew = sqlite3_malloc( sizeof(*pNew) ); *ppVtab = (sqlite3_vtab*)pNew; if( pNew==0 ) return SQLITE_NOMEM; memset(pNew, 0, sizeof(*pNew)); } return rc; } /* ** This method is the destructor for helptextVtab_vtab objects. */ static int helptextVtabDisconnect(sqlite3_vtab *pVtab){ helptextVtab_vtab *p = (helptextVtab_vtab*)pVtab; sqlite3_free(p); return SQLITE_OK; } /* ** Constructor for a new helptextVtab_cursor object. */ static int helptextVtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ helptextVtab_cursor *pCur; pCur = sqlite3_malloc( sizeof(*pCur) ); if( pCur==0 ) return SQLITE_NOMEM; memset(pCur, 0, sizeof(*pCur)); *ppCursor = &pCur->base; return SQLITE_OK; } /* ** Destructor for a helptextVtab_cursor. */ static int helptextVtabClose(sqlite3_vtab_cursor *cur){ helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; sqlite3_free(pCur); return SQLITE_OK; } /* ** Advance a helptextVtab_cursor to its next row of output. */ static int helptextVtabNext(sqlite3_vtab_cursor *cur){ helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; pCur->iRowid++; return SQLITE_OK; } /* ** Return values of columns for the row at which the helptextVtab_cursor ** is currently pointing. */ static int helptextVtabColumn( sqlite3_vtab_cursor *cur, /* The cursor */ sqlite3_context *ctx, /* First argument to sqlite3_result_...() */ int i /* Which column to return */ ){ helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; const CmdOrPage *pPage = aCommand + pCur->iRowid; switch( i ){ case 0: /* name */ sqlite3_result_text(ctx, pPage->zName, -1, SQLITE_STATIC); break; case 1: { /* type */ const char *zType = 0; if( pPage->eCmdFlags & CMDFLAG_COMMAND ){ zType = "command"; }else if( pPage->eCmdFlags & CMDFLAG_WEBPAGE ){ zType = "webpage"; }else if( pPage->eCmdFlags & CMDFLAG_SETTING ){ zType = "setting"; } sqlite3_result_text(ctx, zType, -1, SQLITE_STATIC); break; } case 2: /* flags */ sqlite3_result_int(ctx, pPage->eCmdFlags); break; case 3: /* helptext */ sqlite3_result_text(ctx, pPage->zHelp, -1, SQLITE_STATIC); break; case 4: { /* formatted */ Blob txt; blob_init(&txt, 0, 0); help_to_text(pPage->zHelp, &txt); sqlite3_result_text(ctx, blob_str(&txt), -1, fossil_free); break; } case 5: { /* formatted */ Blob txt; blob_init(&txt, 0, 0); help_to_html(pPage->zHelp, &txt); sqlite3_result_text(ctx, blob_str(&txt), -1, fossil_free); break; } } return SQLITE_OK; } /* ** Return the rowid for the current row. In this implementation, the ** rowid is the same as the output value. */ static int helptextVtabRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){ helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; *pRowid = pCur->iRowid; return SQLITE_OK; } /* ** Return TRUE if the cursor has been moved off of the last ** row of output. */ static int helptextVtabEof(sqlite3_vtab_cursor *cur){ helptextVtab_cursor *pCur = (helptextVtab_cursor*)cur; return pCur->iRowid>=MX_COMMAND; } /* ** This method is called to "rewind" the helptextVtab_cursor object back ** to the first row of output. This method is always called at least ** once prior to any call to helptextVtabColumn() or helptextVtabRowid() or ** helptextVtabEof(). */ static int helptextVtabFilter( sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv ){ helptextVtab_cursor *pCur = (helptextVtab_cursor *)pVtabCursor; pCur->iRowid = 1; return SQLITE_OK; } /* ** SQLite will invoke this method one or more times while planning a query ** that uses the virtual table. This routine needs to create ** a query plan for each invocation and compute an estimated cost for that ** plan. */ static int helptextVtabBestIndex( sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo ){ pIdxInfo->estimatedCost = (double)MX_COMMAND; pIdxInfo->estimatedRows = MX_COMMAND; return SQLITE_OK; } /* ** This following structure defines all the methods for the ** virtual table. */ static sqlite3_module helptextVtabModule = { /* iVersion */ 0, /* xCreate */ 0, /* Helptext is eponymous and read-only */ /* xConnect */ helptextVtabConnect, /* xBestIndex */ helptextVtabBestIndex, /* xDisconnect */ helptextVtabDisconnect, /* xDestroy */ 0, /* xOpen */ helptextVtabOpen, /* xClose */ helptextVtabClose, /* xFilter */ helptextVtabFilter, /* xNext */ helptextVtabNext, /* xEof */ helptextVtabEof, /* xColumn */ helptextVtabColumn, /* xRowid */ helptextVtabRowid, /* xUpdate */ 0, /* xBegin */ 0, /* xSync */ 0, /* xCommit */ 0, /* xRollback */ 0, /* xFindMethod */ 0, /* xRename */ 0, /* xSavepoint */ 0, /* xRelease */ 0, /* xRollbackTo */ 0, /* xShadowName */ 0 }; /* ** Register the helptext virtual table */ int helptext_vtab_register(sqlite3 *db){ int rc = sqlite3_create_module(db, "helptext", &helptextVtabModule, 0); return rc; } /* End of the helptext virtual table ******************************************************************************/