342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
countCmds( CMDFLAG_TEST ));
fossil_print("web-pages: %4d\n",
countCmds( CMDFLAG_WEBPAGE ));
fossil_print("settings: %4d\n",
countCmds( CMDFLAG_SETTING ));
fossil_print("total entries: %4d\n", MX_COMMAND);
}
/*
** Compute an estimate of the edit-distance between to input strings.
**
** The first string is the input. The second is the pattern. Only the
** first 100 characters of the pattern are considered.
*/
static int edit_distance(const char *zA, const char *zB){
int nA = (int)strlen(zA);
int nB = (int)strlen(zB);
int i, j, m;
int p0, p1, c0;
int a[100];
static const int incr = 4;
for(j=0; j<nB; j++) a[j] = 1;
for(i=0; i<nA; i++){
p0 = i==0 ? 0 : i*incr-1;
c0 = i*incr;
for(j=0; j<nB; j++){
int m = 999;
p1 = a[j];
if( zA[i]==zB[j] ){
m = p0;
}else{
m = c0+2;
if( m>p1+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<nB-1; j++){
if( a[j]+1<m ) m = a[j]+1;
}
return m;
}
/*
** Fill the pointer array with names of commands that approximately
** match the input. Return the number of approximate matches.
**
** Closest matches appear first.
*/
int dispatch_approx_match(const char *zIn, int nArray, const char **azArray){
int i;
int bestScore;
int m;
int n = 0;
int mnScore = 0;
int mxScore = 99999;
int iFirst, iLast;
if( zIn[0]=='/' ){
iFirst = 0;
iLast = FOSSIL_FIRST_CMD-1;
}else{
iFirst = FOSSIL_FIRST_CMD;
iLast = MX_COMMAND-1;
}
while( n<nArray ){
bestScore = mxScore;
for(i=iFirst; i<=iLast; i++){
m = edit_distance(zIn, aCommand[i].zName);
if( m<mnScore ) continue;
if( m==mnScore ){
azArray[n++] = aCommand[i].zName;
if( n>=nArray ) return n;
}else if( m<bestScore ){
bestScore = m;
}
}
if( bestScore>=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<g.argc; i++){
fossil_print("%s:\n", g.argv[i]);
n = dispatch_approx_match(g.argv[i], 20, az);
for(j=0; j<n; j++){
fossil_print(" %s\n", az[j]);
}
}
}
/*
** WEBPAGE: help
** URL: /help?name=CMD
**
** Show the built-in help text for CMD. CMD can be a command-line interface
** command or a page name from the web interface or a setting.
|
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
|
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
|
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
|
zCmdOrPage = "page";
zCmdOrPagePlural = "pages";
}else{
zCmdOrPage = "command or setting";
zCmdOrPagePlural = "commands and settings";
}
rc = dispatch_name_search(g.argv[2], CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd);
if( rc ){
int i, n;
const char *az[5];
if( rc==1 ){
fossil_print("unknown %s: %s\nConsider using:\n", zCmdOrPage, g.argv[2]);
if( rc==1 ){
fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]);
}else{
fossil_print("ambiguous %s prefix: %s\n",
zCmdOrPage, g.argv[2]);
}
fossil_print("Did you mean one of:\n");
n = dispatch_approx_match(g.argv[2], 5, az);
for(i=0; i<n; i++){
fossil_print(" * %s\n", az[i]);
}
fossil_print("Also consider using:\n");
fossil_print(" fossil help -a ;# show all commands\n");
fossil_print(" fossil help -w ;# show all web-pages\n");
fossil_print(" fossil help -s ;# show all settings\n");
fossil_exit(1);
}else if( rc==2 ){
fossil_print("ambiguous %s prefix: %s\nMatching %s:\n",
zCmdOrPage, g.argv[2], zCmdOrPagePlural);
command_list(g.argv[2], 0xff);
fossil_exit(1);
}
z = pCmd->zHelp;
if( z==0 ){
fossil_fatal("no help available for the %s %s",
pCmd->zName, zCmdOrPage);
}
if( pCmd->eCmdFlags & CMDFLAG_SETTING ){
|