Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add the "help" command and the "clean" command. More work is needed on the text for various help messages. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
c9fdb846fb169e3789256688942b56e5 |
| User & Date: | drh 2007-08-18 02:45:47.000 |
Context
|
2007-08-18
| ||
| 11:42 | Added options to the "timeline" CLI command. Additional help comments. check-in: 6607844a01 user: drh tags: trunk | |
| 02:45 | Add the "help" command and the "clean" command. More work is needed on the text for various help messages. check-in: c9fdb846fb user: drh tags: trunk | |
|
2007-08-17
| ||
| 19:53 | Omit the -static option from the default Makefile. check-in: e5b74951d9 user: drh tags: trunk | |
Changes
Changes to src/add.c.
| ︙ | ︙ | |||
28 29 30 31 32 33 34 35 | #include "add.h" #include <assert.h> /* ** COMMAND: add ** ** Add one or more files to the current checkout such that these files | > | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include "add.h"
#include <assert.h>
/*
** COMMAND: add
**
** Usage: %fossil add FILE...
** Add one or more files to the current checkout such that these files
** will be inserted into the repository at the next commit.
*/
void add_cmd(void){
int i;
int vid;
db_must_be_within_tree();
vid = db_lget_int("checkout",0);
|
| ︙ | ︙ | |||
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
db_end_transaction(0);
}
/*
** COMMAND: rm
** COMMAND: del
**
** Remove one or more files from the tree.
*/
void del_cmd(void){
int i;
int vid;
db_must_be_within_tree();
| > > | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
db_end_transaction(0);
}
/*
** COMMAND: rm
** COMMAND: del
**
** Usage: %fossil rm FILE...
** or: %fossil del FILE...
** Remove one or more files from the tree.
*/
void del_cmd(void){
int i;
int vid;
db_must_be_within_tree();
|
| ︙ | ︙ |
Changes to src/checkin.c.
| ︙ | ︙ | |||
68 69 70 71 72 73 74 | } db_finalize(&q); } /* ** COMMAND: changes ** | > | > > > | | | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
}
db_finalize(&q);
}
/*
** COMMAND: changes
**
** Usage: %fossil changes
** Report on the edit status of all files in the current checkout.
** See also the "status" and "extra" commands.
*/
void changes_cmd(void){
Blob report;
int vid;
db_must_be_within_tree();
blob_zero(&report);
vid = db_lget_int("checkout", 0);
vfile_check_signature(vid);
status_report(&report, "");
blob_write_to_file(&report, "-");
}
/*
** COMMAND: status
** Usage: %fossil status
** Report on the status of the current checkout.
*/
void status_cmd(void){
int vid;
db_must_be_within_tree();
/* 012345678901234 */
printf("repository: %s\n", db_lget("repository",""));
printf("local-root: %s\n", g.zLocalRoot);
printf("server-code: %s\n", db_get("server-code", ""));
vid = db_lget_int("checkout", 0);
if( vid ){
show_common_info(vid, "checkout:", 0);
}
changes_cmd();
}
/*
** COMMAND: ls
** Usage: %fossil ls
** Show the names of all files in the current checkout
*/
void ls_cmd(void){
int vid;
Stmt q;
db_must_be_within_tree();
vid = db_lget_int("checkout", 0);
|
| ︙ | ︙ | |||
132 133 134 135 136 137 138 |
}
}
db_finalize(&q);
}
/*
** COMMAND: extra
| | | < > > > > > > > > > > > > > > > > > > > > > > > > > | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
}
}
db_finalize(&q);
}
/*
** COMMAND: extra
** Usage: %fossil extra
** Print a list of all files in the source tree that are not part of
** the current checkout. See also the "clean" command.
*/
void extra_cmd(void){
Blob path;
Stmt q;
db_must_be_within_tree();
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
chdir(g.zLocalRoot);
blob_zero(&path);
vfile_scan(0, &path);
db_prepare(&q,
"SELECT x FROM sfile"
" WHERE x NOT IN ('manifest','_FOSSIL_')"
" ORDER BY 1");
while( db_step(&q)==SQLITE_ROW ){
printf("%s\n", db_column_text(&q, 0));
}
db_finalize(&q);
}
/*
** COMMAND: clean
** Usage: %fossil clean
** Delete all "extra" files in the source tree. "Extra" files are
** files that are not officially part of the checkout. See also
** the "extra" command.
*/
void clean_cmd(void){
Blob path;
Stmt q;
db_must_be_within_tree();
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
chdir(g.zLocalRoot);
blob_zero(&path);
vfile_scan(0, &path);
db_prepare(&q,
"SELECT %Q || x FROM sfile"
" WHERE x NOT IN ('manifest','_FOSSIL_')"
" ORDER BY 1", g.zLocalRoot);
while( db_step(&q)==SQLITE_ROW ){
unlink(db_column_text(&q, 0));
}
db_finalize(&q);
}
/*
** Prepare a commit comment. Let the user modify it using the
** editor specified in the global_config table or either
** the VISUAL or EDITOR environment variable.
**
** Store the final commit comment in pComment. pComment is assumed
|
| ︙ | ︙ | |||
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
if( zEditor==0 ){
zEditor = "ed";
}
zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
g.zLocalRoot);
blob_write_to_file(&text, zFile);
zCmd = mprintf("%s %s", zEditor, zFile);
if( system(zCmd) ){
fossil_panic("editor aborted");
}
blob_reset(&text);
blob_read_from_file(&text, zFile);
unlink(zFile);
free(zFile);
| > | 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
if( zEditor==0 ){
zEditor = "ed";
}
zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
g.zLocalRoot);
blob_write_to_file(&text, zFile);
zCmd = mprintf("%s %s", zEditor, zFile);
printf("%s\n", zCmd);
if( system(zCmd) ){
fossil_panic("editor aborted");
}
blob_reset(&text);
blob_read_from_file(&text, zFile);
unlink(zFile);
free(zFile);
|
| ︙ | ︙ | |||
253 254 255 256 257 258 259 260 |
g.aCommitFile[ii-2] = 0;
}
}
/*
** COMMAND: commit
**
** Create a new version containing all of the changes in the current
| > > | < < > | > > | < | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
g.aCommitFile[ii-2] = 0;
}
}
/*
** COMMAND: commit
**
** Usage: %fossil commit ?-m COMMENT? ?--nosign? ?FILE...?
**
** Create a new version containing all of the changes in the current
** checkout. You will be prompted to enter a check-in comment unless
** the "-m" option is used to specify a command line. You will be
** prompted for your GPG passphrase in order to sign the new manifest
** unless the "--nosign" options is used. All files that have
** changed will be committed unless some subset of files is specified
** on the command line.
*/
void commit_cmd(void){
int rc;
int vid, nrid, nvid;
Blob comment;
const char *zComment;
Stmt q;
|
| ︙ | ︙ |
Changes to src/checkout.c.
| ︙ | ︙ | |||
107 108 109 110 111 112 113 | free(zManFile); blob_reset(&manifest); } /* ** COMMAND: checkout ** | > | > > > > | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
free(zManFile);
blob_reset(&manifest);
}
/*
** COMMAND: checkout
**
** Usage: %fossil checkout VERSION ?-f|--force?
** Check out a version specified on the command-line. This command
** will not overwrite edited files in the current checkout unless
** the --force option appears on the command-line.
**
** See also the "update" command.
*/
void checkout_cmd(void){
int forceFlag;
int noWrite;
int vid, prior;
Blob cksum1, cksum1b, cksum2;
|
| ︙ | ︙ | |||
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
}
db_end_transaction(0);
}
/*
** COMMAND: close
**
** The opposite of "open". Close the current database connection.
** Require a -f or --force flag if there are unsaved changed in the
** current check-out.
*/
void close_cmd(void){
int forceFlag = find_option("force","f",0)!=0;
db_must_be_within_tree();
| > | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
}
db_end_transaction(0);
}
/*
** COMMAND: close
**
** Usage: %fossil close ?-f|--force?
** The opposite of "open". Close the current database connection.
** Require a -f or --force flag if there are unsaved changed in the
** current check-out.
*/
void close_cmd(void){
int forceFlag = find_option("force","f",0)!=0;
db_must_be_within_tree();
|
| ︙ | ︙ |
Changes to src/clone.c.
| ︙ | ︙ | |||
28 29 30 31 32 33 34 | #include <assert.h> /* ** COMMAND: clone ** | | | > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <assert.h>
/*
** COMMAND: clone
**
** Usage: %fossil clone URL FILENAME
**
** Make a clone of a repository specified by URL in the local
** file named FILENAME.
*/
void clone_cmd(void){
if( g.argc!=4 ){
usage("FILE-OR-URL NEW-REPOSITORY");
}
if( file_size(g.argv[3])>0 ){
fossil_panic("file already exists: %s", g.argv[3]);
|
| ︙ | ︙ |
Changes to src/db.c.
| ︙ | ︙ | |||
101 102 103 104 105 106 107 |
}
/*
** Prepare or reprepare the sqlite3 statement from the raw SQL text.
*/
static void reprepare(Stmt *pStmt){
sqlite3_stmt *pNew;
| < | | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
}
/*
** Prepare or reprepare the sqlite3 statement from the raw SQL text.
*/
static void reprepare(Stmt *pStmt){
sqlite3_stmt *pNew;
if( sqlite3_prepare(g.db, blob_buffer(&pStmt->sql), -1, &pNew, 0)!=0 ){
db_err("%s\n%s", blob_str(&pStmt->sql), sqlite3_errmsg(g.db));
}
if( pStmt->pStmt ){
sqlite3_transfer_bindings(pStmt->pStmt, pNew);
sqlite3_finalize(pStmt->pStmt);
}
pStmt->pStmt = pNew;
|
| ︙ | ︙ | |||
189 190 191 192 193 194 195 |
}
/*
** Step the SQL statement. Return either SQLITE_ROW or an error code
** or SQLITE_OK if the statement finishes successfully.
*/
int db_step(Stmt *pStmt){
| | | 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
}
/*
** Step the SQL statement. Return either SQLITE_ROW or an error code
** or SQLITE_OK if the statement finishes successfully.
*/
int db_step(Stmt *pStmt){
int rc = SQLITE_OK;
int limit = 3;
while( limit-- ){
rc = sqlite3_step(pStmt->pStmt);
if( rc==SQLITE_ERROR ){
rc = sqlite3_reset(pStmt->pStmt);
}
if( rc==SQLITE_SCHEMA ){
|
| ︙ | ︙ | |||
645 646 647 648 649 650 651 | ); } /* ** COMMAND: new ** | > | > > | 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
);
}
/*
** COMMAND: new
**
** Usage: %fossil new FILENAME
** Create a repository for a new project in the file named FILENAME.
** This command is distinct from "clone". The "clone" command makes
** a copy of an existing project. This command starts a new project.
*/
void create_repository_cmd(void){
char *zDate;
char *zUser;
Blob hash;
Blob manifest;
|
| ︙ | ︙ | |||
819 820 821 822 823 824 825 |
void db_lset_int(const char *zName, int value){
db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
}
/*
** COMMAND: open
**
| > | > > | 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
void db_lset_int(const char *zName, int value){
db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
}
/*
** COMMAND: open
**
** Usage: open FILENAME
** Open a connection to the local repository in FILENAME. A checkout
** for the repository is created with its root at the working directory.
** See also the "close" command.
*/
void cmd_open(void){
Blob path;
if( g.argc!=3 ){
usage("REPOSITORY-FILENAME");
}
if( db_open_local() ){
|
| ︙ | ︙ |
Changes to src/descendents.c.
| ︙ | ︙ | |||
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
" WHERE EXISTS(SELECT 1 FROM plink WHERE pid=rid)"
);
}
/*
** COMMAND: leaves
**
** Find all leaf descendents of the current version or of the
** specified version.
*/
void leaves_cmd(void){
Stmt q;
int base;
| > | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
" WHERE EXISTS(SELECT 1 FROM plink WHERE pid=rid)"
);
}
/*
** COMMAND: leaves
**
** Usage: %fossil leaves ?UUID?
** Find all leaf descendents of the current version or of the
** specified version.
*/
void leaves_cmd(void){
Stmt q;
int base;
|
| ︙ | ︙ | |||
92 93 94 95 96 97 98 99 100 101 102 |
print_timeline(&q, 20);
db_finalize(&q);
}
/*
** COMMAND: branches
**
** Find leaves of all branches.
*/
void branches_cmd(void){
Stmt q;
| > < < < < < < < | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
print_timeline(&q, 20);
db_finalize(&q);
}
/*
** COMMAND: branches
**
** Usage: %fossil branches
** Find leaves of all branches.
*/
void branches_cmd(void){
Stmt q;
db_must_be_within_tree();
db_prepare(&q,
"SELECT blob.uuid, datetime(event.mtime,'localtime'), event.comment"
" FROM blob, event"
" WHERE blob.rid IN"
" (SELECT cid FROM plink EXCEPT SELECT pid FROM plink)"
" AND event.objid=blob.rid"
" ORDER BY event.mtime DESC"
|
| ︙ | ︙ |
Changes to src/diffcmd.c.
| ︙ | ︙ | |||
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
}
/*
** COMMAND: diff
** COMMAND: tkdiff
*/
void diff_cmd(void){
const char *zFile;
Blob cmd;
Blob fname;
int i;
char *zV1 = 0;
| > > > > > | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
}
/*
** COMMAND: diff
** COMMAND: tkdiff
**
** Usage: %fossil diff|tkdiff FILE...
** Show the difference between the current version of a file (as it
** exists on disk) and that same file as it was checked out. Use
** either "diff -u" or "tkdiff".
*/
void diff_cmd(void){
const char *zFile;
Blob cmd;
Blob fname;
int i;
char *zV1 = 0;
|
| ︙ | ︙ |
Changes to src/main.c.
| ︙ | ︙ | |||
133 134 135 136 137 138 139 | ** defined in the page_index.h header file which is automatically ** generated by mkindex.c program. */ static int name_search( const char *zName, /* The name we are looking for */ const NameMap *aMap, /* Search in this array */ int nMap, /* Number of slots in aMap[] */ | | | | | | | | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
** defined in the page_index.h header file which is automatically
** generated by mkindex.c program.
*/
static int name_search(
const char *zName, /* The name we are looking for */
const NameMap *aMap, /* Search in this array */
int nMap, /* Number of slots in aMap[] */
int *pIndex /* OUT: The index in aMap[] of the match */
){
int upr, lwr, cnt, m, i;
int n = strlen(zName);
lwr = 0;
upr = nMap-1;
while( lwr<=upr ){
int mid, c;
mid = (upr+lwr)/2;
c = strcmp(zName, aMap[mid].zName);
if( c==0 ){
*pIndex = mid;
return 0;
}else if( c<0 ){
upr = mid - 1;
}else{
lwr = mid + 1;
}
}
for(m=cnt=0, i=upr-2; i<=upr+3 && i<nMap; i++){
if( i<0 ) continue;
if( strncmp(zName, aMap[i].zName, n)==0 ){
m = i;
cnt++;
}
}
if( cnt==1 ){
*pIndex = m;
return 0;
}
return 1+(cnt>1);
}
/*
** This procedure runs first.
*/
int main(int argc, char **argv){
const char *zCmdName;
int idx;
int rc;
g.now = time(0);
g.argc = argc;
g.argv = argv;
if( getenv("GATEWAY_INTERFACE")!=0 ){
zCmdName = "cgi";
}else if( argc<2 ){
fprintf(stderr, "Usage: %s COMMAND ...\n", argv[0]);
exit(1);
}else{
g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
g.zLogin = find_option("user", "U", 1);
zCmdName = argv[1];
}
rc = name_search(zCmdName, aCommand, count(aCommand), &idx);
if( rc==1 ){
fprintf(stderr,"%s: unknown command: %s\n"
"%s: use \"commands\" or \"test-commands\" for help\n",
argv[0], zCmdName, argv[0]);
return 1;
}else if( rc==2 ){
fprintf(stderr,"%s: ambiguous command prefix: %s\n"
"%s: use \"commands\" or \"test-commands\" for help\n",
argv[0], zCmdName, argv[0]);
return 1;
}
aCommand[idx].xFunc();
return 0;
}
/*
** Print an error message, rollback all databases, and quit.
*/
void fossil_panic(const char *zFormat, ...){
|
| ︙ | ︙ | |||
338 339 340 341 342 343 344 |
printf("\n");
}
}
/*
** COMMAND: commands
**
| > | | > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
printf("\n");
}
}
/*
** COMMAND: commands
**
** Usage: %fossil commands
** List all supported commands.
*/
void cmd_cmd_list(void){
int i, nCmd;
const char *aCmd[count(aCommand)];
for(i=nCmd=0; i<count(aCommand); i++){
if( strncmp(aCommand[i].zName,"test",4)==0 ) continue;
/* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */
aCmd[nCmd++] = aCommand[i].zName;
}
multi_column_list(aCmd, nCmd);
}
/*
** COMMAND: test-commands
**
** Usage: %fossil test-commands
** List all commands used for testing and debugging.
*/
void cmd_test_cmd_list(void){
int i, nCmd;
const char *aCmd[count(aCommand)];
for(i=nCmd=0; i<count(aCommand); i++){
if( strncmp(aCommand[i].zName,"test",4)!=0 ) continue;
/* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */
aCmd[nCmd++] = aCommand[i].zName;
}
multi_column_list(aCmd, nCmd);
}
/*
** COMMAND: help
**
** Usage: %fossil help COMMAND
** Display information on how to use COMMAND
*/
void help_cmd(void){
int rc, idx;
const char *z;
if( g.argc!=3 ){
printf("Usage: %s help <command>.\nAvailable commands:\n", g.argv[0]);
cmd_cmd_list();
return;
}
rc = name_search(g.argv[2], aCommand, count(aCommand), &idx);
if( rc==1 ){
fossil_fatal("unknown command: %s", g.argv[2]);
}else if( rc==2 ){
fossil_fatal("ambiguous command prefix: %s", g.argv[2]);
}
z = aCmdHelp[idx];
if( z==0 ){
fossil_fatal("no help available for the %s command",
aCommand[idx].zName);
}
while( *z ){
if( *z=='%' && strncmp(z, "%fossil", 7)==0 ){
printf("%s", g.argv[0]);
z += 7;
}else{
putchar(*z);
z++;
}
}
putchar('\n');
}
/*
** RSS feeds need to reference absolute URLs so we need to calculate
** the base URL onto which we add components. This is basically
** cgi_redirect() stripped down and always returning an absolute URL.
*/
static char *get_base_url(void){
|
| ︙ | ︙ | |||
410 411 412 413 414 415 416 |
**
** Process the webpage specified by the PATH_INFO or REQUEST_URI
** environment variable.
*/
static void process_one_web_page(void){
const char *zPathInfo;
char *zPath;
| | | 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
**
** Process the webpage specified by the PATH_INFO or REQUEST_URI
** environment variable.
*/
static void process_one_web_page(void){
const char *zPathInfo;
char *zPath;
int idx;
int i, j;
/* Find the page that the user has requested, construct and deliver that
** page.
*/
zPathInfo = P("PATH_INFO");
if( zPathInfo==0 || zPathInfo[0]==0 ){
|
| ︙ | ︙ | |||
461 462 463 464 465 466 467 |
cgi_reply();
exit(0);
}
/* Locate the method specified by the path and execute the function
** that implements that method.
*/
| | | | | 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
cgi_reply();
exit(0);
}
/* Locate the method specified by the path and execute the function
** that implements that method.
*/
if( name_search(g.zPath, aWebpage, count(aWebpage), &idx) &&
name_search("not_found", aWebpage, count(aWebpage), &idx) ){
cgi_set_status(404,"Not Found");
@ <h1>Not Found</h1>
@ <p>Page not found: %h(g.zPath)</p>
}else{
aWebpage[idx].xFunc();
}
/* Return the result.
*/
cgi_reply();
}
|
| ︙ | ︙ |
Changes to src/mkindex.c.
| ︙ | ︙ | |||
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
/*
** Each entry looks like this:
*/
typedef struct Entry {
int eType;
char *zFunc;
char *zPath;
} Entry;
/*
** Maximum number of entries
*/
#define N_ENTRY 500
/*
** Table of entries
*/
Entry aEntry[N_ENTRY];
/*
** How many entries are used
*/
int nUsed;
int nFixed;
/*
| > > > > > > > > > > > > | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
/*
** Each entry looks like this:
*/
typedef struct Entry {
int eType;
char *zFunc;
char *zPath;
char *zHelp;
} Entry;
/*
** Maximum number of entries
*/
#define N_ENTRY 500
/*
** Maximum size of a help message
*/
#define MX_HELP 10000
/*
** Table of entries
*/
Entry aEntry[N_ENTRY];
/*
** Current help message accumulator
*/
char zHelp[MX_HELP];
int nHelp;
/*
** How many entries are used
*/
int nUsed;
int nFixed;
/*
|
| ︙ | ︙ | |||
118 119 120 121 122 123 124 |
nUsed++;
}
/*
** Scan a line for a function that implements a web page or command.
*/
void scan_for_func(char *zLine){
| | > > > > > > > > > > > > > > > > > > > > > > > | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
nUsed++;
}
/*
** Scan a line for a function that implements a web page or command.
*/
void scan_for_func(char *zLine){
int i,j,k;
char *z;
if( nUsed<=nFixed ) return;
if( strncmp(zLine, "**", 2)==0 && isspace(zLine[2])
&& strlen(zLine)<sizeof(zHelp)-nHelp-1 && nUsed>nFixed ){
if( zLine[2]=='\n' ){
zHelp[nHelp++] = '\n';
}else{
if( strncmp(&zLine[3], "Usage: ", 6)==0 ) nHelp = 0;
strcpy(&zHelp[nHelp], &zLine[3]);
nHelp += strlen(&zHelp[nHelp]);
}
return;
}
for(i=0; isspace(zLine[i]); i++){}
if( zLine[i]==0 ) return;
if( strncmp(&zLine[i],"void",4)!=0 ){
if( zLine[i]!='*' ) goto page_skip;
return;
}
i += 4;
if( !isspace(zLine[i]) ) goto page_skip;
while( isspace(zLine[i]) ){ i++; }
for(j=0; isalnum(zLine[i+j]) || zLine[i+j]=='_'; j++){}
if( j==0 ) goto page_skip;
for(k=nHelp-1; k>=0 && isspace(zHelp[k]); k--){}
nHelp = k+1;
zHelp[nHelp] = 0;
for(k=0; k<nHelp && isspace(zHelp[k]); k++){}
if( k<nHelp ){
z = string_dup(&zHelp[k], nHelp-k);
}else{
z = 0;
}
for(k=nFixed; k<nUsed; k++){
aEntry[k].zFunc = string_dup(&zLine[i], j);
aEntry[k].zHelp = z;
}
i+=j;
while( isspace(zLine[i]) ){ i++; }
if( zLine[i]!='(' ) goto page_skip;
nFixed = nUsed;
nHelp = 0;
return;
page_skip:
for(i=nFixed; i<nUsed; i++){
fprintf(stderr,"%s:%d: skipping page \"%s\"\n",
zFile, nLine, aEntry[i].zPath);
}
|
| ︙ | ︙ | |||
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
}
/*
** Build the binary search table.
*/
void build_table(void){
int i;
qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare);
for(i=0; i<nFixed; i++){
printf("extern void %s(void);\n", aEntry[i].zFunc);
}
printf(
"typedef struct NameMap NameMap;\n"
"struct NameMap {\n"
" const char *zName;\n"
" void (*xFunc)(void);\n"
"};\n"
"static const NameMap aWebpage[] = {\n"
);
for(i=0; i<nFixed && aEntry[i].eType==0; i++){
printf(" { \"%s\",%*s %s },\n",
aEntry[i].zPath, (int)(25-strlen(aEntry[i].zPath)), "",
aEntry[i].zFunc
);
}
printf("};\n");
printf(
"static const NameMap aCommand[] = {\n"
);
| > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
}
/*
** Build the binary search table.
*/
void build_table(void){
int i;
int nType0;
qsort(aEntry, nFixed, sizeof(aEntry[0]), e_compare);
for(i=0; i<nFixed; i++){
printf("extern void %s(void);\n", aEntry[i].zFunc);
}
printf(
"typedef struct NameMap NameMap;\n"
"struct NameMap {\n"
" const char *zName;\n"
" void (*xFunc)(void);\n"
"};\n"
"static const NameMap aWebpage[] = {\n"
);
for(i=0; i<nFixed && aEntry[i].eType==0; i++){
printf(" { \"%s\",%*s %s },\n",
aEntry[i].zPath, (int)(25-strlen(aEntry[i].zPath)), "",
aEntry[i].zFunc
);
}
printf("};\n");
nType0 = i;
printf(
"static const NameMap aCommand[] = {\n"
);
for(i=nType0; i<nFixed && aEntry[i].eType==1; i++){
printf(" { \"%s\",%*s %s },\n",
aEntry[i].zPath, (int)(25-strlen(aEntry[i].zPath)), "",
aEntry[i].zFunc
);
}
printf("};\n");
for(i=nType0; i<nFixed; i++){
char *z = aEntry[i].zHelp;
if( z && z[0] ){
printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc);
printf(" \"");
while( *z ){
if( *z=='\n' ){
printf("\\n\"\n \"");
}else if( *z=='"' ){
printf("\\\"");
}else{
putchar(*z);
}
z++;
}
printf("\";\n");
aEntry[i].zHelp[0] = 0;
}
}
printf(
"static const char * const aCmdHelp[] = {\n"
);
for(i=nType0; i<nFixed; i++){
if( aEntry[i].zHelp==0 ){
printf(" 0,\n");
}else{
printf(" zHelp_%s,\n", aEntry[i].zFunc);
}
}
printf("};\n");
}
/*
** Process a single file of input
*/
|
| ︙ | ︙ |