X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;ds=sidebyside;f=git.c;h=5e7da74b6800a4256f9bcb0d0add7560213271e1;hb=e93ec6f9d8dd122557d54505129f7860b9301503;hp=c26cac6555e940e1ae5573a99350388f09118b87;hpb=5e80092f7e6db09a40a62e837ca3f74f0bc5ad73;p=git.git diff --git a/git.c b/git.c index c26cac65..5e7da74b 100644 --- a/git.c +++ b/git.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "git-compat-util.h" #ifndef PATH_MAX @@ -26,6 +27,16 @@ static int term_columns(void) if (col_string && (n_cols = atoi(col_string)) > 0) return n_cols; +#ifdef TIOCGWINSZ + { + struct winsize ws; + if (!ioctl(1, TIOCGWINSZ, &ws)) { + if (ws.ws_col) + return ws.ws_col; + } + } +#endif + return 80; } @@ -74,25 +85,28 @@ static int cmdname_compare(const void *a_, const void *b_) static void pretty_print_string_list(struct cmdname **cmdname, int longest) { - int cols = 1; + int cols = 1, rows; int space = longest + 1; /* min 1 SP between words */ int max_cols = term_columns() - 1; /* don't print *on* the edge */ - int i; + int i, j; if (space < max_cols) cols = max_cols / space; + rows = (cmdname_cnt + cols - 1) / cols; qsort(cmdname, cmdname_cnt, sizeof(*cmdname), cmdname_compare); - for (i = 0; i < cmdname_cnt; ) { - int c; + for (i = 0; i < rows; i++) { printf(" "); - for (c = cols; c && i < cmdname_cnt; i++) { - printf("%s", cmdname[i]->name); - - if (--c) - mput_char(' ', space - cmdname[i]->len); + for (j = 0; j < cols; j++) { + int n = j * rows + i; + int size = space; + if (n >= cmdname_cnt) + break; + if (j == cols-1 || n + rows >= cmdname_cnt) + size = 1; + printf("%-*s", size, cmdname[n]->name); } putchar('\n'); } @@ -230,6 +244,11 @@ int main(int argc, char **argv, char **envp) for (i = 1; i < argc; i++) { char *arg = argv[i]; + if (!strcmp(arg, "help")) { + show_help = 1; + continue; + } + if (strncmp(arg, "--", 2)) break; @@ -264,7 +283,7 @@ int main(int argc, char **argv, char **envp) if (*exec_path != '/') { if (!getcwd(git_command, sizeof(git_command))) { fprintf(stderr, - "git: cannot determine current directory"); + "git: cannot determine current directory\n"); exit(1); } len = strlen(git_command);