static void ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out) { if (pool && out) { struct gc_arena gc = gc_new(); int i; for (i = 0; i < pool->size; ++i) { const struct ifconfig_pool_entry *e = &pool->list[i]; if (e->common_name) { const in_addr_t ip = ifconfig_pool_handle_to_ip_base(pool, i); if (pool->ipv6) { struct in6_addr ip6 = ifconfig_pool_handle_to_ipv6_base(pool, i); status_printf(out, "%s,%s,%s", e->common_name, print_in_addr_t(ip, 0, &gc), print_in6_addr(ip6, 0, &gc)); } else { status_printf(out, "%s,%s", e->common_name, print_in_addr_t(ip, 0, &gc)); } } } gc_free(&gc); } }
void comp_print_stats (const struct compress_context *compctx, struct status_output *so) { if (compctx) { status_printf (so, "pre-compress bytes," counter_format, compctx->pre_compress); status_printf (so, "post-compress bytes," counter_format, compctx->post_compress); status_printf (so, "pre-decompress bytes," counter_format, compctx->pre_decompress); status_printf (so, "post-decompress bytes," counter_format, compctx->post_decompress); } }
static void do_wait(struct excrate *e) { int status; assert(e->pid != 0); debug("waiting on pid %d", e->pid); if (close(e->fd) == -1) abort(); if (waitpid(e->pid, &status, 0) == -1) abort(); debug("wait for pid %d returned %d", e->pid, status); if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) { fprintf(stderr, "Scan completed\n"); } else { fprintf(stderr, "Scan completed with status %d\n", status); if (!e->terminated) status_printf(STATUS_ALERT, "Error scanning %s", e->search); } e->pid = 0; }
static void wt_status_print_unmerged_data(struct wt_status *s, struct string_list_item *it) { const char *c = color(WT_STATUS_UNMERGED, s); struct wt_status_change_data *d = it->util; struct strbuf onebuf = STRBUF_INIT; static char *padding; static int label_width; const char *one, *how; int len; if (!padding) { label_width = maxwidth(wt_status_unmerged_status_string, 1, 7); label_width += strlen(" "); padding = xmallocz(label_width); memset(padding, ' ', label_width); } one = quote_path(it->string, s->prefix, &onebuf); status_printf(s, color(WT_STATUS_HEADER, s), "\t"); how = wt_status_unmerged_status_string(d->stagemask); len = label_width - utf8_strwidth(how); status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one); strbuf_release(&onebuf); }
static void ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel) { struct status_output *so = status_open(NULL, 0, msglevel, NULL, 0); ASSERT(so); status_printf(so, "IFCONFIG POOL LIST"); ifconfig_pool_list(pool, so); status_close(so); }
void WinProcessRenderOptions::WriteError(const char *format, ...) { va_list marker; char error_buffer[1024]; va_start(marker, format); vsnprintf(error_buffer, 1023, format, marker); va_end(marker); buffer_message (mFatal, error_buffer) ; buffer_message (mFatal, "\n") ; status_printf (StatusMessage, error_buffer) ; }
static void wt_status_print_other(struct wt_status *s, struct string_list *l, const char *what, const char *how) { int i; struct strbuf buf = STRBUF_INIT; static struct string_list output = STRING_LIST_INIT_DUP; struct column_options copts; if (!l->nr) return; wt_status_print_other_header(s, what, how); for (i = 0; i < l->nr; i++) { struct string_list_item *it; const char *path; it = &(l->items[i]); path = quote_path(it->string, s->prefix, &buf); if (column_active(s->colopts)) { string_list_append(&output, path); continue; } status_printf(s, color(WT_STATUS_HEADER, s), "\t"); status_printf_more(s, color(WT_STATUS_UNTRACKED, s), "%s\n", path); } strbuf_release(&buf); if (!column_active(s->colopts)) goto conclude; strbuf_addf(&buf, "%s%s\t%s", color(WT_STATUS_HEADER, s), s->display_comment_prefix ? "#" : "", color(WT_STATUS_UNTRACKED, s)); memset(&copts, 0, sizeof(copts)); copts.padding = 1; copts.indent = buf.buf; if (want_color(s->use_color)) copts.nl = GIT_COLOR_RESET "\n"; print_columns(&output, s->colopts, &copts); string_list_clear(&output, 0); strbuf_release(&buf); conclude: status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); }
static void wt_status_print_unmerged_data(struct wt_status *s, struct string_list_item *it) { const char *c = color(WT_STATUS_UNMERGED, s); struct wt_status_change_data *d = it->util; struct strbuf onebuf = STRBUF_INIT; const char *one, *how = _("bug"); one = quote_path(it->string, s->prefix, &onebuf); status_printf(s, color(WT_STATUS_HEADER, s), "\t"); switch (d->stagemask) { case 1: how = _("both deleted:"); break; case 2: how = _("added by us:"); break; case 3: how = _("deleted by them:"); break; case 4: how = _("added by them:"); break; case 5: how = _("deleted by us:"); break; case 6: how = _("both added:"); break; case 7: how = _("both modified:"); break; } status_printf_more(s, c, "%-20s%s\n", how, one); strbuf_release(&onebuf); }
static void wt_status_print_other(struct wt_status *s, struct string_list *l, const char *what, const char *how) { int i; struct strbuf buf = STRBUF_INIT; if (!s->untracked.nr) return; wt_status_print_other_header(s, what, how); for (i = 0; i < l->nr; i++) { struct string_list_item *it; it = &(l->items[i]); status_printf(s, color(WT_STATUS_HEADER, s), "\t"); status_printf_more(s, color(WT_STATUS_UNTRACKED, s), "%s\n", quote_path(it->string, strlen(it->string), &buf, s->prefix)); } strbuf_release(&buf); }
static void wt_status_print_change_data(struct wt_status *s, int change_type, struct string_list_item *it) { struct wt_status_change_data *d = it->util; const char *c = color(change_type, s); int status; char *one_name; char *two_name; const char *one, *two; struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT; struct strbuf extra = STRBUF_INIT; one_name = two_name = it->string; switch (change_type) { case WT_STATUS_UPDATED: status = d->index_status; if (d->head_path) one_name = d->head_path; break; case WT_STATUS_CHANGED: if (d->new_submodule_commits || d->dirty_submodule) { strbuf_addstr(&extra, " ("); if (d->new_submodule_commits) strbuf_addf(&extra, _("new commits, ")); if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED) strbuf_addf(&extra, _("modified content, ")); if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) strbuf_addf(&extra, _("untracked content, ")); strbuf_setlen(&extra, extra.len - 2); strbuf_addch(&extra, ')'); } status = d->worktree_status; break; default: die("BUG: unhandled change_type %d in wt_status_print_change_data", change_type); } one = quote_path(one_name, s->prefix, &onebuf); two = quote_path(two_name, s->prefix, &twobuf); status_printf(s, color(WT_STATUS_HEADER, s), "\t"); switch (status) { case DIFF_STATUS_ADDED: status_printf_more(s, c, _("new file: %s"), one); break; case DIFF_STATUS_COPIED: status_printf_more(s, c, _("copied: %s -> %s"), one, two); break; case DIFF_STATUS_DELETED: status_printf_more(s, c, _("deleted: %s"), one); break; case DIFF_STATUS_MODIFIED: status_printf_more(s, c, _("modified: %s"), one); break; case DIFF_STATUS_RENAMED: status_printf_more(s, c, _("renamed: %s -> %s"), one, two); break; case DIFF_STATUS_TYPE_CHANGED: status_printf_more(s, c, _("typechange: %s"), one); break; case DIFF_STATUS_UNKNOWN: status_printf_more(s, c, _("unknown: %s"), one); break; case DIFF_STATUS_UNMERGED: status_printf_more(s, c, _("unmerged: %s"), one); break; default: die(_("bug: unhandled diff status %c"), status); } if (extra.len) { status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf); strbuf_release(&extra); } status_printf_more(s, GIT_COLOR_NORMAL, "\n"); strbuf_release(&onebuf); strbuf_release(&twobuf); }
void wt_status_print(struct wt_status *s) { const char *branch_color = color(WT_STATUS_ONBRANCH, s); const char *branch_status_color = color(WT_STATUS_HEADER, s); struct wt_status_state state; memset(&state, 0, sizeof(state)); wt_status_get_state(&state, s->branch && !strcmp(s->branch, "HEAD")); if (s->branch) { const char *on_what = _("On branch "); const char *branch_name = s->branch; if (!prefixcmp(branch_name, "refs/heads/")) branch_name += 11; else if (!strcmp(branch_name, "HEAD")) { branch_status_color = color(WT_STATUS_NOBRANCH, s); if (state.rebase_in_progress || state.rebase_interactive_in_progress) { on_what = _("rebase in progress; onto "); branch_name = state.onto; } else if (state.detached_from) { unsigned char sha1[20]; branch_name = state.detached_from; if (!get_sha1("HEAD", sha1) && !hashcmp(sha1, state.detached_sha1)) on_what = _("HEAD detached at "); else on_what = _("HEAD detached from "); } else { branch_name = ""; on_what = _("Not currently on any branch."); } } status_printf(s, color(WT_STATUS_HEADER, s), ""); status_printf_more(s, branch_status_color, "%s", on_what); status_printf_more(s, branch_color, "%s\n", branch_name); if (!s->is_initial) wt_status_print_tracking(s); } wt_status_print_state(s, &state); free(state.branch); free(state.onto); free(state.detached_from); if (s->is_initial) { status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit")); status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); } wt_status_print_updated(s); wt_status_print_unmerged(s); wt_status_print_changed(s); if (s->submodule_summary && (!s->ignore_submodule_arg || strcmp(s->ignore_submodule_arg, "all"))) { wt_status_print_submodule_summary(s, 0); /* staged */ wt_status_print_submodule_summary(s, 1); /* unstaged */ } if (s->show_untracked_files) { wt_status_print_other(s, &s->untracked, _("Untracked files"), "add"); if (s->show_ignored_files) wt_status_print_other(s, &s->ignored, _("Ignored files"), "add -f"); if (advice_status_u_option && 2000 < s->untracked_in_ms) { status_printf_ln(s, GIT_COLOR_NORMAL, ""); status_printf_ln(s, GIT_COLOR_NORMAL, _("It took %.2f seconds to enumerate untracked files. 'status -uno'\n" "may speed it up, but you have to be careful not to forget to add\n" "new files yourself (see 'git help status')."), s->untracked_in_ms / 1000.0); } } else if (s->commitable) status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"), advice_status_hints ? _(" (use -u option to show untracked files)") : ""); if (s->verbose) wt_status_print_verbose(s); if (!s->commitable) { if (s->amend) status_printf_ln(s, GIT_COLOR_NORMAL, _("No changes")); else if (s->nowarn) ; /* nothing */ else if (s->workdir_dirty) { if (advice_status_hints) printf(_("no changes added to commit " "(use \"git add\" and/or \"git commit -a\")\n")); else printf(_("no changes added to commit\n")); } else if (s->untracked.nr) { if (advice_status_hints) printf(_("nothing added to commit but untracked files " "present (use \"git add\" to track)\n")); else printf(_("nothing added to commit but untracked files present\n")); } else if (s->is_initial) { if (advice_status_hints) printf(_("nothing to commit (create/copy files " "and use \"git add\" to track)\n")); else printf(_("nothing to commit\n")); } else if (!s->show_untracked_files) { if (advice_status_hints) printf(_("nothing to commit (use -u to show untracked files)\n")); else printf(_("nothing to commit\n")); } else printf(_("nothing to commit, working directory clean\n")); } }
/* * Takes a pointer to a dpv_config structure containing layout details and * pointer to initial element in a linked-list of dpv_file_node structures, * each presenting a file to process. Executes the `action' function passed-in * as a member to the `config' structure argument. */ int dpv(struct dpv_config *config, struct dpv_file_node *file_list) { char c; uint8_t keep_going; uint8_t nls = FALSE; /* See dialog_prompt_nlstate() */ uint8_t no_overrun = FALSE; uint8_t pprompt_nls = FALSE; /* See dialog_prompt_nlstate() */ uint8_t shrink_label_size = FALSE; mode_t mask; uint16_t options; char *cp; char *fc; char *last; char *name; char *output; const char *status_fmt; const char *path_fmt; enum dpv_display display_type; enum dpv_output output_type; enum dpv_status status; int (*action)(struct dpv_file_node *file, int out); int backslash; int dialog_last_update = 0; int dialog_old_nthfile = 0; int dialog_old_seconds = -1; int dialog_out = STDOUT_FILENO; int dialog_update_usec = 0; int dialog_updates_per_second; int files_left; int max_cols; int nthfile = 0; int output_out; int overall = 0; int pct; int res; int seconds; int status_last_update = 0; int status_old_nthfile = 0; int status_old_seconds = -1; int status_update_usec = 0; int status_updates_per_second; pid_t output_pid; pid_t pid; size_t len; struct dpv_file_node *curfile; struct dpv_file_node *first_file; struct dpv_file_node *list_head; struct timeval now; struct timeval start; char init_prompt[PROMPT_MAX + 1] = ""; /* Initialize globals to default values */ aprompt = NULL; pprompt = NULL; options = 0; action = NULL; backtitle = NULL; debug = FALSE; dialog_test = FALSE; dialog_updates_per_second = DIALOG_UPDATES_PER_SEC; display_limit = DISPLAY_LIMIT_DEFAULT; display_type = DPV_DISPLAY_LIBDIALOG; label_size = LABEL_SIZE_DEFAULT; msg_done = NULL; msg_fail = NULL; msg_pending = NULL; no_labels = FALSE; output = NULL; output_type = DPV_OUTPUT_NONE; pbar_size = PBAR_SIZE_DEFAULT; status_format_custom = NULL; status_updates_per_second = STATUS_UPDATES_PER_SEC; title = NULL; wide = FALSE; /* Process config options (overriding defaults) */ if (config != NULL) { if (config->aprompt != NULL) { if (aprompt == NULL) { aprompt = malloc(DPV_APROMPT_MAX); if (aprompt == NULL) return (-1); } snprintf(aprompt, DPV_APROMPT_MAX, "%s", config->aprompt); } if (config->pprompt != NULL) { if (pprompt == NULL) { pprompt = malloc(DPV_PPROMPT_MAX + 2); /* +2 is for implicit "\n" appended later */ if (pprompt == NULL) return (-1); } snprintf(pprompt, DPV_APROMPT_MAX, "%s", config->pprompt); } options = config->options; action = config->action; backtitle = config->backtitle; debug = config->debug; dialog_test = ((options & DPV_TEST_MODE) != 0); dialog_updates_per_second = config->dialog_updates_per_second; display_limit = config->display_limit; display_type = config->display_type; label_size = config->label_size; msg_done = (char *)config->msg_done; msg_fail = (char *)config->msg_fail; msg_pending = (char *)config->msg_pending; no_labels = ((options & DPV_NO_LABELS) != 0); no_overrun = ((options & DPV_NO_OVERRUN) != 0); output = config->output; output_type = config->output_type; pbar_size = config->pbar_size; status_updates_per_second = config->status_updates_per_second; title = config->title; wide = ((options & DPV_WIDE_MODE) != 0); /* Enforce some minimums (pedantic) */ if (display_limit < -1) display_limit = -1; if (label_size < -1) label_size = -1; if (pbar_size < -1) pbar_size = -1; /* For the mini-pbar, -1 means hide, zero is invalid unless * only one file is given */ if (pbar_size == 0) { if (file_list == NULL || file_list->next == NULL) pbar_size = -1; else pbar_size = PBAR_SIZE_DEFAULT; } /* For the label, -1 means auto-size, zero is invalid unless * specifically requested through the use of options flag */ if (label_size == 0 && no_labels == FALSE) label_size = LABEL_SIZE_DEFAULT; /* Status update should not be zero */ if (status_updates_per_second == 0) status_updates_per_second = STATUS_UPDATES_PER_SEC; } /* config != NULL */ /* Process the type of display we've been requested to produce */ switch (display_type) { case DPV_DISPLAY_STDOUT: debug = TRUE; use_color = FALSE; use_dialog = FALSE; use_libdialog = FALSE; use_xdialog = FALSE; break; case DPV_DISPLAY_DIALOG: use_color = TRUE; use_dialog = TRUE; use_libdialog = FALSE; use_xdialog = FALSE; break; case DPV_DISPLAY_XDIALOG: snprintf(dialog, PATH_MAX, XDIALOG); use_color = FALSE; use_dialog = FALSE; use_libdialog = FALSE; use_xdialog = TRUE; break; default: use_color = TRUE; use_dialog = FALSE; use_libdialog = TRUE; use_xdialog = FALSE; break; } /* display_type */ /* Enforce additional minimums that require knowing our display type */ if (dialog_updates_per_second == 0) dialog_updates_per_second = use_xdialog ? XDIALOG_UPDATES_PER_SEC : DIALOG_UPDATES_PER_SEC; /* Allow forceful override of use_color */ if (config != NULL && (config->options & DPV_USE_COLOR) != 0) use_color = TRUE; /* Count the number of files in provided list of dpv_file_node's */ if (use_dialog && pprompt != NULL && *pprompt != '\0') pprompt_nls = dialog_prompt_nlstate(pprompt); max_cols = dialog_maxcols(); if (label_size == -1) shrink_label_size = TRUE; /* Process file arguments */ for (curfile = file_list; curfile != NULL; curfile = curfile->next) { dpv_nfiles++; /* dialog(3) only expands literal newlines */ if (use_libdialog) strexpandnl(curfile->name); /* Optionally calculate label size for file */ if (shrink_label_size) { nls = FALSE; name = curfile->name; if (curfile == file_list) nls = pprompt_nls; last = (char *)dialog_prompt_lastline(name, nls); if (use_dialog) { c = *last; *last = '\0'; nls = dialog_prompt_nlstate(name); *last = c; } len = dialog_prompt_longestline(last, nls); if ((int)len > (label_size - 3)) { if (label_size > 0) label_size += 3; label_size = len; /* Room for ellipsis (unless NULL) */ if (label_size > 0) label_size += 3; } if (max_cols > 0 && label_size > (max_cols - pbar_size - 9)) label_size = max_cols - pbar_size - 9; } if (debug) warnx("label=[%s] path=[%s] size=%lli", curfile->name, curfile->path, curfile->length); } /* file_list */ /* Optionally process the contents of DIALOGRC (~/.dialogrc) */ if (use_dialog) { res = parse_dialogrc(); if (debug && res == 0) { warnx("Successfully read `%s' config file", DIALOGRC); warnx("use_shadow = %i (Boolean)", use_shadow); warnx("use_colors = %i (Boolean)", use_colors); warnx("gauge_color=[%s] (FBH)", gauge_color); } } else if (use_libdialog) { init_dialog(stdin, stdout); use_shadow = dialog_state.use_shadow; use_colors = dialog_state.use_colors; gauge_color[0] = 48 + dlg_color_table[GAUGE_ATTR].fg; gauge_color[1] = 48 + dlg_color_table[GAUGE_ATTR].bg; gauge_color[2] = dlg_color_table[GAUGE_ATTR].hilite ? 'b' : 'B'; gauge_color[3] = '\0'; end_dialog(); if (debug) { warnx("Finished initializing dialog(3) library"); warnx("use_shadow = %i (Boolean)", use_shadow); warnx("use_colors = %i (Boolean)", use_colors); warnx("gauge_color=[%s] (FBH)", gauge_color); } } /* Enable mini progress bar automatically for stdin streams if unable * to calculate progress (missing `lines:' syntax). */ if (dpv_nfiles <= 1 && file_list != NULL && file_list->length < 0 && !dialog_test) pbar_size = PBAR_SIZE_DEFAULT; /* If $USE_COLOR is set and non-NULL enable color; otherwise disable */ if ((cp = getenv(ENV_USE_COLOR)) != 0) use_color = *cp != '\0' ? 1 : 0; /* Print error and return `-1' if not given at least one name */ if (dpv_nfiles == 0) { warnx("%s: no labels provided", __func__); return (-1); } else if (debug) warnx("%s: %u label%s provided", __func__, dpv_nfiles, dpv_nfiles == 1 ? "" : "s"); /* If only one file and pbar size is zero, default to `-1' */ if (dpv_nfiles <= 1 && pbar_size == 0) pbar_size = -1; /* Print some debugging information */ if (debug) { warnx("%s: %s(%i) max rows x cols = %i x %i", __func__, use_xdialog ? XDIALOG : DIALOG, use_libdialog ? 3 : 1, dialog_maxrows(), dialog_maxcols()); } /* Xdialog(1) updates a lot slower than dialog(1) */ if (dialog_test && use_xdialog) increment = XDIALOG_INCREMENT; /* Always add implicit newline to pprompt (when specified) */ if (pprompt != NULL && *pprompt != '\0') { len = strlen(pprompt); /* * NOTE: pprompt = malloc(PPROMPT_MAX + 2) * NOTE: (see getopt(2) section above for pprompt allocation) */ pprompt[len++] = '\\'; pprompt[len++] = 'n'; pprompt[len++] = '\0'; } /* Xdialog(1) requires newlines (a) escaped and (b) in triplicate */ if (use_xdialog && pprompt != NULL) { /* Replace `\n' with `\n\\n\n' in pprompt */ len = strlen(pprompt); len += strcount(pprompt, "\\n") * 2; if (len > DPV_PPROMPT_MAX) errx(EXIT_FAILURE, "%s: Oops, pprompt buffer overflow " "(%zu > %i)", __func__, len, DPV_PPROMPT_MAX); if (replaceall(pprompt, "\\n", "\n\\n\n") < 0) err(EXIT_FAILURE, "%s: replaceall()", __func__); } /* libdialog requires literal newlines */ else if (use_libdialog && pprompt != NULL) strexpandnl(pprompt); /* Xdialog(1) requires newlines (a) escaped and (b) in triplicate */ if (use_xdialog && aprompt != NULL) { /* Replace `\n' with `\n\\n\n' in aprompt */ len = strlen(aprompt); len += strcount(aprompt, "\\n") * 2; if (len > DPV_APROMPT_MAX) errx(EXIT_FAILURE, "%s: Oops, aprompt buffer overflow " " (%zu > %i)", __func__, len, DPV_APROMPT_MAX); if (replaceall(aprompt, "\\n", "\n\\n\n") < 0) err(EXIT_FAILURE, "%s: replaceall()", __func__); } /* libdialog requires literal newlines */ else if (use_libdialog && aprompt != NULL) strexpandnl(aprompt); /* * Warn user about an obscure dialog(1) bug (neither Xdialog(1) nor * libdialog are affected) in the `--gauge' widget. If the first non- * whitespace letter of "{new_prompt}" in "XXX\n{new_prompt}\nXXX\n" * is a number, the number can sometimes be mistaken for a percentage * to the overall progressbar. Other nasty side-effects such as the * entire prompt not displaying or displaying improperly are caused by * this bug too. * * NOTE: When we can use color, we have a work-around... prefix the * output with `\Zn' (used to terminate ANSI and reset to normal). */ if (use_dialog && !use_color) { backslash = 0; /* First, check pprompt (falls through if NULL) */ fc = pprompt; while (fc != NULL && *fc != '\0') { if (*fc == '\n') /* leading literal newline OK */ break; if (!isspace(*fc) && *fc != '\\' && backslash == 0) break; else if (backslash > 0 && *fc != 'n') break; else if (*fc == '\\') { backslash++; if (backslash > 2) break; /* we're safe */ } fc++; } /* First non-whitespace character that dialog(1) will see */ if (fc != NULL && *fc >= '0' && *fc <= '9') warnx("%s: WARNING! text argument to `-p' begins with " "a number (not recommended)", __func__); else if (fc > pprompt) warnx("%s: WARNING! text argument to `-p' begins with " "whitespace (not recommended)", __func__); /* * If no pprompt or pprompt is all whitespace, check the first * file name provided to make sure it is alright too. */ if ((pprompt == NULL || *fc == '\0') && file_list != NULL) { first_file = file_list; fc = first_file->name; while (fc != NULL && *fc != '\0' && isspace(*fc)) fc++; /* First non-whitespace char that dialog(1) will see */ if (fc != NULL && *fc >= '0' && *fc <= '9') warnx("%s: WARNING! File name `%s' begins " "with a number (use `-p text' for safety)", __func__, first_file->name); } } dprompt_init(file_list); /* Reads: label_size pbar_size pprompt aprompt dpv_nfiles */ /* Inits: dheight and dwidth */ if (!debug) { /* Internally create the initial `--gauge' prompt text */ dprompt_recreate(file_list, (struct dpv_file_node *)NULL, 0); /* Spawn [X]dialog(1) `--gauge', returning pipe descriptor */ if (use_libdialog) { status_printf(""); dprompt_libprint(pprompt, aprompt, 0); } else { dprompt_sprint(init_prompt, pprompt, aprompt); dialog_out = dialog_spawn_gauge(init_prompt, &pid); dprompt_dprint(dialog_out, pprompt, aprompt, 0); } } /* !debug */ /* Seed the random(3) generator */ if (dialog_test) srandom(0xf1eeface); /* Set default/custom status line format */ if (dpv_nfiles > 1) { snprintf(status_format_default, DPV_STATUS_FORMAT_MAX, "%s", DPV_STATUS_MANY); status_format_custom = config->status_many; } else { snprintf(status_format_default, DPV_STATUS_FORMAT_MAX, "%s", DPV_STATUS_SOLO); status_format_custom = config->status_solo; } /* Add test mode identifier to default status line if enabled */ if (dialog_test && (strlen(status_format_default) + 12) < DPV_STATUS_FORMAT_MAX) strcat(status_format_default, " [TEST MODE]"); /* Verify custom status format */ status_fmt = fmtcheck(status_format_custom, status_format_default); if (status_format_custom != NULL && status_fmt == status_format_default) { warnx("WARNING! Invalid status_format configuration `%s'", status_format_custom); warnx("Default status_format `%s'", status_format_default); } /* Record when we started (used to prevent updating too quickly) */ (void)gettimeofday(&start, (struct timezone *)NULL); /* Calculate number of microseconds in-between sub-second updates */ if (status_updates_per_second != 0) status_update_usec = 1000000 / status_updates_per_second; if (dialog_updates_per_second != 0) dialog_update_usec = 1000000 / dialog_updates_per_second; /* * Process the file list [serially] (one for each argument passed) */ files_left = dpv_nfiles; list_head = file_list; for (curfile = file_list; curfile != NULL; curfile = curfile->next) { keep_going = TRUE; output_out = -1; pct = 0; nthfile++; files_left--; if (dpv_interrupt) break; if (dialog_test) pct = 0 - increment; /* Attempt to spawn output program for this file */ if (!dialog_test && output != NULL) { mask = umask(0022); (void)umask(mask); switch (output_type) { case DPV_OUTPUT_SHELL: output_out = shell_spawn_pipecmd(output, curfile->name, &output_pid); break; case DPV_OUTPUT_FILE: path_fmt = fmtcheck(output, "%s"); if (path_fmt == output) len = snprintf(pathbuf, PATH_MAX, output, curfile->name); else len = snprintf(pathbuf, PATH_MAX, "%s", output); if (len >= PATH_MAX) { warnx("%s:%d:%s: pathbuf[%u] too small" "to hold output argument", __FILE__, __LINE__, __func__, PATH_MAX); return (-1); } if ((output_out = open(pathbuf, O_CREAT|O_WRONLY, DEFFILEMODE & ~mask)) < 0) { warn("%s", pathbuf); return (-1); } break; default: break; } } while (!dpv_interrupt && keep_going) { if (dialog_test) { usleep(50000); pct += increment; dpv_overall_read += (int)(random() / 512 / dpv_nfiles); /* 512 limits fake readout to Megabytes */ } else if (action != NULL) pct = action(curfile, output_out); if (no_overrun || dialog_test) keep_going = (pct < 100); else { status = curfile->status; keep_going = (status == DPV_STATUS_RUNNING); } /* Get current time and calculate seconds elapsed */ gettimeofday(&now, (struct timezone *)NULL); now.tv_sec = now.tv_sec - start.tv_sec; now.tv_usec = now.tv_usec - start.tv_usec; if (now.tv_usec < 0) now.tv_sec--, now.tv_usec += 1000000; seconds = now.tv_sec + (now.tv_usec / 1000000.0); /* Update dialog (be it dialog(3), dialog(1), etc.) */ if ((dialog_updates_per_second != 0 && ( seconds != dialog_old_seconds || now.tv_usec - dialog_last_update >= dialog_update_usec || nthfile != dialog_old_nthfile )) || pct == 100 ) { /* Calculate overall progress (rounding up) */ overall = (100 * nthfile - 100 + pct) / dpv_nfiles; if (((100 * nthfile - 100 + pct) * 10 / dpv_nfiles % 100) > 50) overall++; dprompt_recreate(list_head, curfile, pct); if (use_libdialog && !debug) { /* Update dialog(3) widget */ dprompt_libprint(pprompt, aprompt, overall); } else { /* stdout, dialog(1), or Xdialog(1) */ dprompt_dprint(dialog_out, pprompt, aprompt, overall); fsync(dialog_out); } dialog_old_seconds = seconds; dialog_old_nthfile = nthfile; dialog_last_update = now.tv_usec; } /* Update the status line */ if ((use_libdialog && !debug) && status_updates_per_second != 0 && ( keep_going != TRUE || seconds != status_old_seconds || now.tv_usec - status_last_update >= status_update_usec || nthfile != status_old_nthfile ) ) { status_printf(status_fmt, dpv_overall_read, (dpv_overall_read / (seconds == 0 ? 1 : seconds) * 1.0), 1, /* XXX until we add parallelism XXX */ files_left); status_old_seconds = seconds; status_old_nthfile = nthfile; status_last_update = now.tv_usec; } } if (!dialog_test && output_out >= 0) { close(output_out); waitpid(output_pid, (int *)NULL, 0); } if (dpv_abort) break; /* Advance head of list when we hit the max display lines */ if (display_limit > 0 && nthfile % display_limit == 0) list_head = curfile->next; } if (!debug) { if (use_libdialog) end_dialog(); else { close(dialog_out); waitpid(pid, (int *)NULL, 0); } if (!dpv_interrupt) printf("\n"); } else warnx("%s: %lli overall read", __func__, dpv_overall_read); if (dpv_interrupt || dpv_abort) return (-1); else return (0); }
void wt_status_print(struct wt_status *s) { const char *branch_color = color(WT_STATUS_ONBRANCH, s); const char *branch_status_color = color(WT_STATUS_HEADER, s); if (s->branch) { const char *on_what = "On branch "; const char *branch_name = s->branch; if (!prefixcmp(branch_name, "refs/heads/")) branch_name += 11; else if (!strcmp(branch_name, "HEAD")) { branch_name = ""; branch_status_color = color(WT_STATUS_NOBRANCH, s); on_what = "Not currently on any branch."; } status_printf(s, color(WT_STATUS_HEADER, s), ""); status_printf_more(s, branch_status_color, "%s", on_what); status_printf_more(s, branch_color, "%s\n", branch_name); if (!s->is_initial) wt_status_print_tracking(s); } if (s->is_initial) { status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); status_printf_ln(s, color(WT_STATUS_HEADER, s), "Initial commit"); status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); } wt_status_print_updated(s); wt_status_print_unmerged(s); wt_status_print_changed(s); if (s->submodule_summary && (!s->ignore_submodule_arg || strcmp(s->ignore_submodule_arg, "all"))) { wt_status_print_submodule_summary(s, 0); /* staged */ wt_status_print_submodule_summary(s, 1); /* unstaged */ } if (s->show_untracked_files) { wt_status_print_other(s, &s->untracked, "Untracked", "add"); if (s->show_ignored_files) wt_status_print_other(s, &s->ignored, "Ignored", "add -f"); } else if (s->commitable) status_printf_ln(s, GIT_COLOR_NORMAL, "Untracked files not listed%s", advice_status_hints ? " (use -u option to show untracked files)" : ""); if (s->verbose) wt_status_print_verbose(s); if (!s->commitable) { if (s->amend) status_printf_ln(s, GIT_COLOR_NORMAL, "No changes"); else if (s->nowarn) ; /* nothing */ else if (s->workdir_dirty) printf("no changes added to commit%s\n", advice_status_hints ? " (use \"git add\" and/or \"git commit -a\")" : ""); else if (s->untracked.nr) printf("nothing added to commit but untracked files present%s\n", advice_status_hints ? " (use \"git add\" to track)" : ""); else if (s->is_initial) printf("nothing to commit%s\n", advice_status_hints ? " (create/copy files and use \"git add\" to track)" : ""); else if (!s->show_untracked_files) printf("nothing to commit%s\n", advice_status_hints ? " (use -u to show untracked files)" : ""); else printf("nothing to commit%s\n", advice_status_hints ? " (working directory clean)" : ""); } }
/* * Print statistics. * * Triggered by SIGUSR2 or F2 on Windows. */ void print_status(const struct context *c, struct status_output *so) { struct gc_arena gc = gc_new(); status_reset(so); status_printf(so, "OpenVPN STATISTICS"); status_printf(so, "Updated,%s", time_string(0, 0, false, &gc)); status_printf(so, "TUN/TAP read bytes," counter_format, c->c2.tun_read_bytes); status_printf(so, "TUN/TAP write bytes," counter_format, c->c2.tun_write_bytes); status_printf(so, "TCP/UDP read bytes," counter_format, c->c2.link_read_bytes); status_printf(so, "TCP/UDP write bytes," counter_format, c->c2.link_write_bytes); status_printf(so, "Auth read bytes," counter_format, c->c2.link_read_bytes_auth); #ifdef USE_COMP if (c->c2.comp_context) { comp_print_stats(c->c2.comp_context, so); } #endif #ifdef PACKET_TRUNCATION_CHECK status_printf(so, "TUN read truncations," counter_format, c->c2.n_trunc_tun_read); status_printf(so, "TUN write truncations," counter_format, c->c2.n_trunc_tun_write); status_printf(so, "Pre-encrypt truncations," counter_format, c->c2.n_trunc_pre_encrypt); status_printf(so, "Post-decrypt truncations," counter_format, c->c2.n_trunc_post_decrypt); #endif #ifdef _WIN32 if (tuntap_defined(c->c1.tuntap)) { status_printf(so, "TAP-WIN32 driver status,\"%s\"", tap_win_getinfo(c->c1.tuntap, &gc)); } #endif status_printf(so, "END"); status_flush(so); gc_free(&gc); }
void WinRenderFrontend::RenderProgress (POVMSObjectPtr msg, POVMSObjectPtr, int) { int ret = kNoErr ; int n = 0 ; int l = 0 ; int s = 0 ; char str [512] ; char *p = str ; POVMSLong ll = 0 ; if (no_status_output) return ; if (delay_next_status) return ; // animation frame progress if (POVMSUtil_GetInt (msg, kPOVAttrib_FrameCount, &l) == kNoErr) { if (POVMSUtil_GetInt (msg, kPOVAttrib_AbsoluteCurFrame, &s) == kNoErr) { status_printf (StatusMessage, "Rendering frame %d of %d", s, l) ; delay_next_status = 1000 ; } } // parsing progress else if ((POVMSUtil_GetLong (msg, kPOVAttrib_CurrentToken, &ll) == kNoErr) && (ll > 0)) { status_printf (StatusMessage, "Parsed %I64u tokens", ll) ; } // rendering progress else if (POVMSUtil_GetInt (msg, kPOVAttrib_CurrentLine, &l) == kNoErr) { if (POVMSUtil_GetInt (msg, kPOVAttrib_LineCount, &s) == kNoErr) { if (POVMSUtil_GetInt(msg, kPOVAttrib_MosaicPreviewSize, &n) == kNoErr) p += sprintf (str, "Pre-rendering line %d of %d (mosaic %dx%d)", l, s, n, n) ; else p += sprintf (str, "Rendering line %d of %d", l, s) ; if (POVMSUtil_GetInt (msg, kPOVAttrib_SuperSampleCount, &l) == kNoErr) p += sprintf (p, " (%d supersamples)", l) ; if (POVMSUtil_GetInt (msg, kPOVAttrib_RadGatherCount, &l) == kNoErr) { if (*(p - 1) == ')') p += sprintf (--p, ", %d radiosity samples)", l) ; else p += sprintf (p, " (%d radiosity samples)", l) ; } if (seconds_for_last_line > 9) sprintf (p, " [last line %d PPS]", render_width / seconds_for_last_line) ; say_status_message (StatusMessage, str) ; } } // photon progress else if (POVMSUtil_GetInt (msg, kPOVAttrib_TotalPhotonCount, &n) == kNoErr) { // sorting if (POVMSUtil_GetInt (msg, kPOVAttrib_CurrentPhotonCount, &s) == kNoErr) status_printf (StatusMessage, "Sorting photon %d of %d", s, n) ; // shooting else { l = s = 0 ; POVMSUtil_GetInt (msg, kPOVAttrib_PhotonXSamples, &l) ; POVMSUtil_GetInt (msg, kPOVAttrib_PhotonYSamples, &s) ; status_printf (StatusMessage, "Photons %d (sampling %dx%d)", n, s, l) ; } } }
static int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, struct strbuf *author_ident) { struct stat statbuf; struct strbuf committer_ident = STRBUF_INIT; int commitable; struct strbuf sb = STRBUF_INIT; const char *hook_arg1 = NULL; const char *hook_arg2 = NULL; int clean_message_contents = (cleanup_mode != CLEANUP_NONE); int old_display_comment_prefix; /* This checks and barfs if author is badly specified */ determine_author_info(author_ident); if (!no_verify && run_hook(index_file, "pre-commit", NULL)) return 0; if (squash_message) { /* * Insert the proper subject line before other commit * message options add their content. */ if (use_message && !strcmp(use_message, squash_message)) strbuf_addstr(&sb, "squash! "); else { struct pretty_print_context ctx = {0}; struct commit *c; c = lookup_commit_reference_by_name(squash_message); if (!c) die(_("could not lookup commit %s"), squash_message); ctx.output_encoding = get_commit_output_encoding(); format_commit_message(c, "squash! %s\n\n", &sb, &ctx); } } if (message.len) { strbuf_addbuf(&sb, &message); hook_arg1 = "message"; } else if (logfile && !strcmp(logfile, "-")) { if (isatty(0)) fprintf(stderr, _("(reading log message from standard input)\n")); if (strbuf_read(&sb, 0, 0) < 0) die_errno(_("could not read log from standard input")); hook_arg1 = "message"; } else if (logfile) { if (strbuf_read_file(&sb, logfile, 0) < 0) die_errno(_("could not read log file '%s'"), logfile); hook_arg1 = "message"; } else if (use_message) { char *buffer; buffer = strstr(use_message_buffer, "\n\n"); if (!use_editor && (!buffer || buffer[2] == '\0')) die(_("commit has empty message")); strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); hook_arg1 = "commit"; hook_arg2 = use_message; } else if (fixup_message) { struct pretty_print_context ctx = {0}; struct commit *commit; commit = lookup_commit_reference_by_name(fixup_message); if (!commit) die(_("could not lookup commit %s"), fixup_message); ctx.output_encoding = get_commit_output_encoding(); format_commit_message(commit, "fixup! %s\n\n", &sb, &ctx); hook_arg1 = "message"; } else if (!stat(git_path("MERGE_MSG"), &statbuf)) { if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0) die_errno(_("could not read MERGE_MSG")); hook_arg1 = "merge"; } else if (!stat(git_path("SQUASH_MSG"), &statbuf)) { if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0) die_errno(_("could not read SQUASH_MSG")); hook_arg1 = "squash"; } else if (template_file) { if (strbuf_read_file(&sb, template_file, 0) < 0) die_errno(_("could not read '%s'"), template_file); hook_arg1 = "template"; clean_message_contents = 0; } /* * The remaining cases don't modify the template message, but * just set the argument(s) to the prepare-commit-msg hook. */ else if (whence == FROM_MERGE) hook_arg1 = "merge"; else if (whence == FROM_CHERRY_PICK) { hook_arg1 = "commit"; hook_arg2 = "CHERRY_PICK_HEAD"; } if (squash_message) { /* * If squash_commit was used for the commit subject, * then we're possibly hijacking other commit log options. * Reset the hook args to tell the real story. */ hook_arg1 = "message"; hook_arg2 = ""; } s->fp = fopen(git_path(commit_editmsg), "w"); if (s->fp == NULL) die_errno(_("could not open '%s'"), git_path(commit_editmsg)); /* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */ old_display_comment_prefix = s->display_comment_prefix; s->display_comment_prefix = 1; /* * Most hints are counter-productive when the commit has * already started. */ s->hints = 0; if (clean_message_contents) stripspace(&sb, 0); if (signoff) { /* * See if we have a Conflicts: block at the end. If yes, count * its size, so we can ignore it. */ int ignore_footer = 0; int i, eol, previous = 0; const char *nl; for (i = 0; i < sb.len; i++) { nl = memchr(sb.buf + i, '\n', sb.len - i); if (nl) eol = nl - sb.buf; else eol = sb.len; if (starts_with(sb.buf + previous, "\nConflicts:\n")) { ignore_footer = sb.len - previous; break; } while (i < eol) i++; previous = eol; } append_signoff(&sb, ignore_footer, 0); } if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len) die_errno(_("could not write commit template")); strbuf_release(&sb); /* This checks if committer ident is explicitly given */ strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT)); if (use_editor && include_status) { int ident_shown = 0; int saved_color_setting; char *ai_tmp, *ci_tmp; if (whence != FROM_COMMIT) status_printf_ln(s, GIT_COLOR_NORMAL, whence == FROM_MERGE ? _("\n" "It looks like you may be committing a merge.\n" "If this is not correct, please remove the file\n" " %s\n" "and try again.\n") : _("\n" "It looks like you may be committing a cherry-pick.\n" "If this is not correct, please remove the file\n" " %s\n" "and try again.\n"), git_path(whence == FROM_MERGE ? "MERGE_HEAD" : "CHERRY_PICK_HEAD")); fprintf(s->fp, "\n"); if (cleanup_mode == CLEANUP_ALL) status_printf(s, GIT_COLOR_NORMAL, _("Please enter the commit message for your changes." " Lines starting\nwith '%c' will be ignored, and an empty" " message aborts the commit.\n"), comment_line_char); else /* CLEANUP_SPACE, that is. */ status_printf(s, GIT_COLOR_NORMAL, _("Please enter the commit message for your changes." " Lines starting\n" "with '%c' will be kept; you may remove them" " yourself if you want to.\n" "An empty message aborts the commit.\n"), comment_line_char); if (only_include_assumed) status_printf_ln(s, GIT_COLOR_NORMAL, "%s", only_include_assumed); ai_tmp = cut_ident_timestamp_part(author_ident->buf); ci_tmp = cut_ident_timestamp_part(committer_ident.buf); if (strcmp(author_ident->buf, committer_ident.buf)) status_printf_ln(s, GIT_COLOR_NORMAL, _("%s" "Author: %s"), ident_shown++ ? "" : "\n", author_ident->buf); if (!committer_ident_sufficiently_given()) status_printf_ln(s, GIT_COLOR_NORMAL, _("%s" "Committer: %s"), ident_shown++ ? "" : "\n", committer_ident.buf); if (ident_shown) status_printf_ln(s, GIT_COLOR_NORMAL, ""); saved_color_setting = s->use_color; s->use_color = 0; commitable = run_status(s->fp, index_file, prefix, 1, s); s->use_color = saved_color_setting; *ai_tmp = ' '; *ci_tmp = ' '; } else { unsigned char sha1[20]; const char *parent = "HEAD"; if (!active_nr && read_cache() < 0) die(_("Cannot read index")); if (amend) parent = "HEAD^1"; if (get_sha1(parent, sha1)) commitable = !!active_nr; else commitable = index_differs_from(parent, 0); } strbuf_release(&committer_ident); fclose(s->fp); /* * Reject an attempt to record a non-merge empty commit without * explicit --allow-empty. In the cherry-pick case, it may be * empty due to conflict resolution, which the user should okay. */ if (!commitable && whence != FROM_MERGE && !allow_empty && !(amend && is_a_merge(current_head))) { s->display_comment_prefix = old_display_comment_prefix; run_status(stdout, index_file, prefix, 0, s); if (amend) fputs(_(empty_amend_advice), stderr); else if (whence == FROM_CHERRY_PICK) { fputs(_(empty_cherry_pick_advice), stderr); if (!sequencer_in_use) fputs(_(empty_cherry_pick_advice_single), stderr); else fputs(_(empty_cherry_pick_advice_multi), stderr); } return 0; } /* * Re-read the index as pre-commit hook could have updated it, * and write it out as a tree. We must do this before we invoke * the editor and after we invoke run_status above. */ discard_cache(); read_cache_from(index_file); if (update_main_cache_tree(0)) { error(_("Error building trees")); return 0; } if (run_hook(index_file, "prepare-commit-msg", git_path(commit_editmsg), hook_arg1, hook_arg2, NULL)) return 0; if (use_editor) { char index[PATH_MAX]; const char *env[2] = { NULL }; env[0] = index; snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); if (launch_editor(git_path(commit_editmsg), NULL, env)) { fprintf(stderr, _("Please supply the message using either -m or -F option.\n")); exit(1); } } if (!no_verify && run_hook(index_file, "commit-msg", git_path(commit_editmsg), NULL)) { return 0; } return 1; }
static void wt_status_print_change_data(struct wt_status *s, int change_type, struct string_list_item *it) { struct wt_status_change_data *d = it->util; const char *c = color(change_type, s); int status; char *one_name; char *two_name; const char *one, *two; struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT; struct strbuf extra = STRBUF_INIT; static char *padding; static int label_width; const char *what; int len; if (!padding) { /* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */ label_width = maxwidth(wt_status_diff_status_string, 'A', 'Z'); label_width += strlen(" "); padding = xmallocz(label_width); memset(padding, ' ', label_width); } one_name = two_name = it->string; switch (change_type) { case WT_STATUS_UPDATED: status = d->index_status; if (d->head_path) one_name = d->head_path; break; case WT_STATUS_CHANGED: if (d->new_submodule_commits || d->dirty_submodule) { strbuf_addstr(&extra, " ("); if (d->new_submodule_commits) strbuf_addf(&extra, _("new commits, ")); if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED) strbuf_addf(&extra, _("modified content, ")); if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) strbuf_addf(&extra, _("untracked content, ")); strbuf_setlen(&extra, extra.len - 2); strbuf_addch(&extra, ')'); } status = d->worktree_status; break; default: die("BUG: unhandled change_type %d in wt_status_print_change_data", change_type); } one = quote_path(one_name, s->prefix, &onebuf); two = quote_path(two_name, s->prefix, &twobuf); status_printf(s, color(WT_STATUS_HEADER, s), "\t"); what = wt_status_diff_status_string(status); if (!what) die(_("bug: unhandled diff status %c"), status); len = label_width - utf8_strwidth(what); assert(len >= 0); if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED) status_printf_more(s, c, "%s%.*s%s -> %s", what, len, padding, one, two); else status_printf_more(s, c, "%s%.*s%s", what, len, padding, one); if (extra.len) { status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf); strbuf_release(&extra); } status_printf_more(s, GIT_COLOR_NORMAL, "\n"); strbuf_release(&onebuf); strbuf_release(&twobuf); }