void ui_cmdline_show_help(unsigned int num_options, cmdline_option_ram_t *opt, void *arg) { int chars; // maximum area could be shown char format[13]; unsigned int i; HWND hwnd; // // calculate maximum width of text // size_t jmax = 0; for (i = 0; i < num_options; i++) { size_t j = strlen(opt[i].name) + 1; j += strlen((opt[i].need_arg && cmdline_options_get_param(i) != NULL) ? cmdline_options_get_param(i) : "") + 1; jmax = j > jmax ? j : jmax; j += strlen(cmdline_options_get_description(i)) + 1; chars = j > chars ? j : chars; } sprintf(format, "%%-%ds%%s", jmax); // // open dialog // hwnd = cmdopt_dialog((HWND)arg); if (!hwnd) { return; } // // fill dialog with text // for (i = 0; i < num_options; i++) { char *textopt = lib_msprintf("%s %s", opt[i].name, (opt[i].need_arg && cmdline_options_get_param(i) != NULL) ? cmdline_options_get_param(i) : ""); char *text = lib_msprintf(format, textopt, cmdline_options_get_description(i)); lib_free(textopt); WinSendMsg(hwnd, WM_INSERT, text, (void*)TRUE); lib_free(text); } // // MAINLOOP // WinProcessDlg(hwnd); // // WinProcessDlg() does NOT destroy the window on return! Do it here, // otherwise the window procedure won't ever get a WM_DESTROY, // which we may want :-) // WinDestroyWindow(hwnd); }
char *cmdline_options_string(void) { unsigned int i; char *cmdline_string, *new_cmdline_string; char *add_to_options1, *add_to_options2, *add_to_options3; cmdline_string = lib_stralloc("\n"); for (i = 0; i < num_options; i++) { add_to_options1 = lib_msprintf("%s", options[i].name); add_to_options3 = lib_msprintf("\n\t%s\n", cmdline_options_get_description(i)); if (options[i].need_arg && cmdline_options_get_param(i) != NULL) { if (options[i].need_arg == -1) { add_to_options2 = lib_msprintf(" <%s>", cmdline_options_get_param(i)); } else { add_to_options2 = lib_msprintf(" %s", cmdline_options_get_param(i)); } new_cmdline_string = util_concat(cmdline_string, add_to_options1, add_to_options2, add_to_options3, NULL); lib_free(add_to_options2); } else { new_cmdline_string = util_concat(cmdline_string, add_to_options1, add_to_options3, NULL); } lib_free(add_to_options1); lib_free(add_to_options3); lib_free(cmdline_string); cmdline_string = new_cmdline_string; } return cmdline_string; }
void ui_cmdline_show_help(unsigned int num_options, cmdline_option_ram_t *options, void *userparam) { unsigned int i; printf(translate_text(IDS_AVAILABLE_CMDLINE_OPTIONS)); for (i = 0; i < num_options; i++) { fputs(options[i].name, stdout); if (options[i].need_arg && cmdline_options_get_param(i) != NULL) { printf(" %s", cmdline_options_get_param(i)); } printf("\n\t%s\n", cmdline_options_get_description(i)); } putchar('\n'); }
void ui_cmdline_show_help(unsigned int num_options, cmdline_option_ram_t *options, void *userparam) { unsigned int i; printf("\nAvailable command-line options:\n\n"); for (i = 0; i < num_options; i++) { fputs(options[i].name, stdout); if (options[i].need_arg && cmdline_options_get_param(i) != NULL) { printf(" %s", cmdline_options_get_param(i)); } printf("\n\t%s\n", cmdline_options_get_description(i)); } putchar('\n'); }
static UI_CALLBACK(ui_about_cmdline) { unsigned int i, num_options; char *name, *param, *desc; char *text; num_options = cmdline_get_num_options(); text = lib_malloc(num_options * 0x100); text[0] = 0; for (i = 0; i < num_options; i++) { name = cmdline_options_get_name(i); if (name == NULL) { log_error(LOG_ERR, "ui_about_cmdline: name is NULL."); break; } strcat(text, name); param = cmdline_options_get_param(i); if (param != NULL) { strcat(text, " "); strcat(text, param); } desc = cmdline_options_get_description(i); if (desc != NULL) { strcat(text, "\n\t"); strcat(text, desc); } else { log_error(LOG_ERR, "ui_about_cmdline: description for '%s' is NULL.", name); } strcat(text, "\n"); if (strlen(text) > ((num_options - 1) * 0x100)) { log_error(LOG_ERR, "ui_about_cmdline: string buffer not big enough!"); break; } } ui_show_text(_("Available command-line options:"), text, 600, 400); lib_free(text); }
/** \brief Create textview with scrollbars * * \return GtkScrolledWindow */ static GtkWidget *create_content_widget(void) { GtkWidget *view; GtkWidget *scrolled; GtkTextBuffer *buffer; GtkTextIter iter; GtkTextTag *name_tag; GtkTextTag *inv_tag; GtkTextTag *desc_tag; int num_options = cmdline_get_num_options(); int i; view = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE); gtk_text_view_set_monospace(GTK_TEXT_VIEW(view), TRUE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD_CHAR); gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view),16); gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view),16); buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)); /* name: bold (for -option) */ name_tag = gtk_text_buffer_create_tag(buffer, "name_tag", "weight", PANGO_WEIGHT_BOLD, NULL); /* name: bold and red (for +option) */ inv_tag = gtk_text_buffer_create_tag(buffer, "inv_tag", "weight", PANGO_WEIGHT_BOLD, "foreground", "red", NULL); /* description: indented and sans-serif */ desc_tag = gtk_text_buffer_create_tag(buffer, "desc_tag", "left-margin", 48, "family", "sans-serif", NULL); scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_widget_set_size_request(scrolled, 800, 600); gtk_container_add(GTK_CONTAINER(scrolled), view); gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0); for (i = 0; i < num_options; i++) { char *name; char *param; char *desc; name = cmdline_options_get_name(i); param = cmdline_options_get_param(i); desc = cmdline_options_get_description(i); if (name[0] == '-') { gtk_text_buffer_insert_with_tags(buffer, &iter, name, -1, name_tag, NULL); } else { gtk_text_buffer_insert_with_tags(buffer, &iter, name, -1, inv_tag, NULL); } if (param != NULL) { gtk_text_buffer_insert(buffer, &iter, " ", -1); gtk_text_buffer_insert(buffer, &iter, param, -1); } gtk_text_buffer_insert(buffer, &iter, "\n", -1); if (desc == NULL) { fprintf(stderr, "no desc for '%s'\n", name); desc = "[DESCRIPTION MISSING]"; } gtk_text_buffer_insert_with_tags(buffer, &iter, desc, -1, desc_tag, NULL); gtk_text_buffer_insert(buffer, &iter, "\n\n", -1); } gtk_widget_show_all(scrolled); return scrolled; }