Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch against libcli 1 10 0 rel2 #49

Conversation

RobSanders
Copy link
Collaborator

Several bug fixes, but major work on how 'help' messages are display. Biggest change for 'legacy' is that the help messages for commands are now wrapped (default 80 cols), and my contain embedded cr/lf

RobSanders and others added 9 commits July 31, 2019 13:21
All help lines consist of the name and helpstr.  This treats allows each
line to be 'wrapped' and collimated so each partial piece of helpstr will
be left aligned with each other.  Wrapping is done assuming an 80 col width,
and if a line is wrapped it will attempt to split it at the last white
space in that segment.  If none found, then it prints what it can.  Then it
also breaks at the first '\n' or '\r'.

Additionally, for optarg help, we can have 'specific' help messages in
addition to the general help for the optarg.  Look at the clitest program
for an example (both 'triangle' and 'rectangle' have specific help msgs
for the 'shape' optarg.  These specific help messages are tab ('\t')
separated and occur after the general help message.  A specific message
will only be shown if 'could' be a match.
libcli.c Outdated
@@ -166,6 +166,7 @@ static int cli_int_execute_pipeline(struct cli_def *cli, struct cli_pipeline *pi
inline void cli_int_show_pipeline(struct cli_def *cli, struct cli_pipeline *pipeline);
static void cli_int_free_pipeline(struct cli_pipeline *pipeline);
static void cli_register_command_core(struct cli_def *cli, struct cli_command *parent, struct cli_command *c);
static void cli_int_wrap_help_line (char *nameptr, char *helpptr, struct cli_comphelp *comphelp) ;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra spaces around ( and )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

libcli.c Outdated Show resolved Hide resolved
libcli.c Outdated
* Attemp quick dirty wrapping of helptext taking into account the offset from name, embedded
* cr/lf in helptext, and trying to split on last white-text before the margin
*/
void cli_int_wrap_help_line (char *nameptr, char *helpptr, struct cli_comphelp *comphelp) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra space before (

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

libcli.c Outdated
if (toprint > availwidth) {
toprint = availwidth;
while ((toprint>=0) && !isspace(helpptr[toprint])) toprint--;
if ( toprint < 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra space after (.

BTW, even old versions of clang-format would do this for you. In fact, clang-format makes quite a lot of changes to this file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, one of these days when I (re)discover that mythical thing called 'free time' I need to spin up a machine that has a more recent version of clang than CentOS7. Right now our primary development platform is specific to RHEL7.5 - and our dev builds tend to be CentOS7 based. Our product is currently aimed as an appliance where we supply both H/W and S/W.

libcli.c Outdated

if (asprintf(&line, "%*.*s%.*s", namewidth, namewidth, nameptr, toprint, helpptr) < 0) break;
cli_add_comphelp_entry(comphelp, line);
if (nameptr != emptystring) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny little nitpick, but I don't think this if statement should be here. Just setting nameptr = emptystring every time is potentially more efficient.

  1. It's shorter code
  2. nameptr will equal emptystring after the first loop so this if statement will always run after the first loop. If there are more than 2 lines in the output then it's more efficient not to have the if.

Yes it's a pedantic request. I think i thought about this too much just now and I feel silly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This from code creep. Originally this routine was tucked inside another routine where I'd've done a 'free_z(nameptr)' just before setting nameptr back to emptystring. When I moved this code to the new cli_int_wrap_help_line() I no longer needed the free (parent handled that), so I just popped the line. At any rate - fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juggled order of code here also so the calls to asprintf, cli_add_comphelp_entry, and the free of said asprintf are consecutive.

libcli.c Outdated Show resolved Hide resolved
libcli.c Show resolved Hide resolved
libcli.c Outdated Show resolved Hide resolved
libcli.c Show resolved Hide resolved
Copy link
Collaborator Author

@RobSanders RobSanders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated patch w/above changes coming momentarily.....

@dparrish dparrish merged commit 2c132dd into dparrish:patch_against_libcli_1_10_0_rel2 Aug 8, 2019
@dparrish
Copy link
Owner

dparrish commented Aug 8, 2019 via email

@RobSanders
Copy link
Collaborator Author

RobSanders commented Aug 8, 2019 via email

@RobSanders
Copy link
Collaborator Author

RobSanders commented Aug 9, 2019 via email

@RobSanders
Copy link
Collaborator Author

RobSanders commented Aug 9, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants