Changeset 41583 in vbox
- Timestamp:
- Jun 5, 2012 3:08:25 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGCCommands.cpp
r41575 r41583 415 415 416 416 /** 417 * Outputs a command or function summary line. 418 * 419 * @returns Output status code 420 * @param pCmdHlp The command helpers. 421 * @param pszName The name of the function or command. 422 * @param fExternal Whether it's external. 423 * @param pszSyntax The syntax. 424 * @param pszDescription The description. 425 */ 426 static int dbgcCmdHelpCmdOrFunc(PDBGCCMDHLP pCmdHlp, const char *pszName, bool fExternal, 427 const char *pszSyntax, const char *pszDescription) 428 { 429 /* 430 * Aiming for "%-11s %-30s %s". Need to adjust when any of the two 431 * columns are two wide as well as break the last column up if its 432 * too wide. 433 */ 434 size_t const cchMaxWidth = 100; 435 size_t const cchCol1 = 11; 436 size_t const cchCol2 = 30; 437 size_t const cchCol3 = cchMaxWidth - cchCol1 - cchCol2 - 2; 438 439 size_t const cchName = strlen(pszName) + fExternal; 440 size_t const cchSyntax = strlen(pszSyntax); 441 size_t cchDesc = strlen(pszDescription); 442 443 /* Can we do it the simple + fast way? */ 444 if ( cchName <= cchCol1 445 && ( cchSyntax <= cchCol2 446 || cchSyntax + cchDesc <= cchCol2 + cchCol3)) 447 return DBGCCmdHlpPrintf(pCmdHlp, 448 !fExternal ? "%-*s %-*s %s\n" : ".%-*s %-*s %s\n", 449 cchCol1, pszName, 450 cchCol2, pszSyntax, 451 pszDescription); 452 453 /* Column 1. */ 454 size_t off = 0; 455 DBGCCmdHlpPrintf(pCmdHlp, !fExternal ? "%s" : ".%s", pszName); 456 off += cchName; 457 if (off < cchCol1) 458 DBGCCmdHlpPrintf(pCmdHlp, "%*s", cchCol1 - off, ""); 459 460 /* Column 2. */ 461 DBGCCmdHlpPrintf(pCmdHlp, " %s", pszSyntax); 462 off += 1 + cchSyntax; 463 if (off < cchCol1 + 1 + cchCol2) 464 DBGCCmdHlpPrintf(pCmdHlp, "%*s", cchCol1 + 1 + cchCol2 - off, ""); 465 466 /* Column 3. */ 467 for (;;) 468 { 469 if (off + 1 + cchDesc < cchMaxWidth) 470 return DBGCCmdHlpPrintf(pCmdHlp, " %s\n", pszDescription); 471 472 /** @todo fix this code! */ 473 /* Split on preceeding blank. */ 474 const char *pszNext = &pszDescription[cchCol3]; 475 const char *pszEnd = pszNext; 476 if (!RT_C_IS_BLANK(*pszEnd)) 477 while (pszEnd != pszDescription && !RT_C_IS_BLANK(pszEnd[-1])) 478 pszEnd--; 479 while (pszEnd != pszDescription && RT_C_IS_BLANK(pszEnd[-1])) 480 pszEnd--; 481 if (pszEnd == pszDescription) 482 { 483 while (*pszEnd && !RT_C_IS_BLANK(*pszEnd)) 484 pszEnd++; 485 pszNext = pszEnd; 486 } 487 488 while (RT_C_IS_BLANK(*pszNext)) 489 pszNext++; 490 491 /* Output it and advance to the next line. */ 492 if (!*pszNext) 493 return DBGCCmdHlpPrintf(pCmdHlp, " %.*s\n", pszEnd - pszDescription, pszDescription); 494 off = cchCol1 + 1 + cchCol2; 495 DBGCCmdHlpPrintf(pCmdHlp, " %.*s\n%*s", pszEnd - pszDescription, pszDescription, off, ""); 496 497 /* next */ 498 cchDesc -= pszNext - pszDescription; 499 pszDescription = pszNext; 500 } 501 } 502 503 504 /** 417 505 * Prints full command help. 418 506 */ … … 468 556 { 469 557 int rc = VINF_SUCCESS; 558 470 559 if (pszDescFmt) 471 560 { … … 477 566 478 567 for (unsigned i = 0; i < cCmds && RT_SUCCESS(rc); i++) 479 rc = DBGCCmdHlpPrintf(pCmdHlp, 480 !fExternal ? "%-11s %-30s %s\n" : ".%-10s %-30s %s\n", 481 paCmds[i].pszCmd, 482 paCmds[i].pszSyntax, 483 paCmds[i].pszDescription); 484 return VINF_SUCCESS; 568 rc = dbgcCmdHelpCmdOrFunc(pCmdHlp, paCmds[i].pszCmd, fExternal, paCmds[i].pszSyntax, paCmds[i].pszDescription); 569 570 return rc; 485 571 } 486 572 … … 553 639 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <%u+>\n", pFunc->paArgDescs[i].cTimesMin); 554 640 else 555 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <%u-%u>\n", pFunc->paArgDescs[i].cTimesMin, pFunc->paArgDescs[i].cTimesMax); 641 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " <%u-%u>\n", pFunc->paArgDescs[i].cTimesMin, 642 pFunc->paArgDescs[i].cTimesMax); 556 643 } 557 644 } … … 573 660 574 661 for (unsigned i = 0; i < cFuncs && RT_SUCCESS(rc); i++) 575 rc = DBGCCmdHlpPrintf(pCmdHlp, 576 !fExternal ? "%-11s %-30s %s\n" : ".%-10s %-30s %s\n", 577 paFuncs[i].pszFuncNm, 578 paFuncs[i].pszSyntax, 579 paFuncs[i].pszDescription); 662 rc = dbgcCmdHelpCmdOrFunc(pCmdHlp, paFuncs[i].pszFuncNm, fExternal, paFuncs[i].pszSyntax, paFuncs[i].pszDescription); 580 663 return VINF_SUCCESS; 581 664 } … … 658 741 "help functions Show help on all functions.\n" 659 742 "help operators Show help on all operators.\n" 743 "help all All the above.\n" 660 744 "help <cmd-pattern> [...]\n" 661 745 " Show details help on individual commands, simple\n" … … 694 778 else if (!strcmp(pszPattern, "all")) 695 779 { 696 rc = dbgcCmdHelpFunctions(pDbgc, pCmdHlp);697 780 rc = DBGCCmdHlpPrintf(pCmdHlp, 698 781 "VirtualBox Debugger Help\n"
Note:
See TracChangeset
for help on using the changeset viewer.