void output_options(FILE *pfile) { int idx; const option_map_value *ptr; fprintf(pfile, "-== Options ==-\n"); for (idx = 0; idx < UO_option_count; idx++) { ptr = get_option_name(idx); if (ptr != NULL) { if (ptr->type == AT_STRING) { fprintf(pfile, "%3d) %32s = \"%s\"\n", ptr->id, ptr->name, op_val_to_string(ptr->type, cpd.settings[ptr->id]).c_str()); } else { fprintf(pfile, "%3d) %32s = %s\n", ptr->id, ptr->name, op_val_to_string(ptr->type, cpd.settings[ptr->id]).c_str()); } } } }
/* library list options get put in object list, * so order w.r.t. libraries is preserved. */ extern void add_object (int flag, string arg) { /* cxx_prelinker_object_list contains real objects, -objectlist flags. */ switch (flag) { case O_l: /* xpg fort77 has weird rule about putting all libs after objects */ if (xpg_flag && invoked_lang == L_f77) { add_string(lib_objects, concat_strings("-l",arg)); } else { add_string(objects, concat_strings("-l",arg)); add_string(ld_args_objs, concat_strings("-l",arg)); } if (invoked_lang == L_CC) { add_string(cxx_prelinker_objects,concat_strings("-l",arg)); } break; case O_none: add_string(objects, get_option_name(flag)); add_string(ld_args_objs, get_option_name(flag)); break; case O_objectlist: add_multi_strings(objects, concat_strings("-objectlist ",arg)); add_multi_strings(ld_args_objs, concat_strings("-objectlist ",arg)); if (invoked_lang == L_CC) { add_string(cxx_prelinker_objects, concat_strings("-YO=",arg)); } break; case O_object: if (dashdash_flag && arg[0] == '-') { add_string(objects,"--"); add_string(ld_args_objs,"--"); dashdash_flag = 1; } add_string(objects, arg); add_string(ld_args_objs, arg); if (invoked_lang == L_CC) { add_string(cxx_prelinker_objects, arg); } break; default: internal_error("add_object called with not-an-object"); } }
void output_options(FILE *pfile) { int idx; const option_map_value *ptr; fprintf(pfile, "-== Options ==-\n"); for (idx = 0; idx < UO_option_count; idx++) { ptr = get_option_name(idx); if (ptr != NULL) { if (ptr->type == AT_BOOL) { fprintf(pfile, "%3d) %32s = %s\n", ptr->id, ptr->name, cpd.settings[ptr->id].b ? "True" : "False"); } else if (ptr->type == AT_IARF) { fprintf(pfile, "%3d) %32s = %s\n", ptr->id, ptr->name, (cpd.settings[ptr->id].a == AV_ADD) ? "Add" : (cpd.settings[ptr->id].a == AV_REMOVE) ? "Remove" : (cpd.settings[ptr->id].a == AV_FORCE) ? "Force" : "Ignore"); } else if (ptr->type == AT_LINE) { fprintf(pfile, "%3d) %32s = %s\n", ptr->id, ptr->name, (cpd.settings[ptr->id].le == LE_AUTO) ? "Auto" : (cpd.settings[ptr->id].le == LE_LF) ? "LF" : (cpd.settings[ptr->id].le == LE_CRLF) ? "CRLF" : (cpd.settings[ptr->id].le == LE_CR) ? "CR" : "???"); } else /* AT_NUM */ { fprintf(pfile, "%3d) %32s = %d\n", ptr->id, ptr->name, cpd.settings[ptr->id].n); } } } }
static void dump_error(struct cliopts_priv *ctx) { fprintf(stderr, "Couldn't parse options: %s\n", ctx->errstr); if (ctx->errnum == CLIOPTS_ERR_BADOPT) { fprintf(stderr, "Bad option: %s", ctx->current_key); } else if (ctx->errnum == CLIOPTS_ERR_BAD_VALUE) { fprintf(stderr, "Bad value '%s' for %s", ctx->current_value, ctx->current_key); } else if (ctx->errnum == CLIOPTS_ERR_UNRECOGNIZED) { fprintf(stderr, "No such option: %s", ctx->current_key); } else if (ctx->errnum == CLIOPTS_ERR_ISSWITCH) { char optbuf[64] = { 0 }; fprintf(stderr, "Option %s takes no arguments", get_option_name(ctx->prev, optbuf)); } fprintf(stderr, "\n"); }
static void EnableTree(xmlNodePtr node, OptionsBox *box) { if(strcmp(node->name, "option") == 0) { //GtkWidget *button = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(window), // get_option_name(cur_info, node, NULL, 0)); OptionsButton *button = carbon_GetButtonByName(box, get_option_name(cur_info, node, NULL, 0)); if(button) //gtk_widget_set_sensitive(button, TRUE); EnableControl(button->Control); } node = node->childs; while(node) { EnableTree(node, box); node = node->next; } }
void print_universal_indent_cfg(FILE *pfile) { const group_map_value *p_grp; const char *p_name; /* Dump the header and the categories */ fprintf(pfile, "[header]\n"); /* Add all the categories */ char ch = '='; int idx; fprintf(pfile, "categories"); for (idx = 0; idx < UG_group_count; idx++) { p_grp = get_group_name(idx); if (p_grp != NULL) { fprintf(pfile, "%c%s", ch, p_grp->short_desc); ch = '|'; } } fprintf(pfile, "\n"); fprintf(pfile, "cfgFileParameterEnding=cr\n" "configFilename=TechPlayers.cfg\n"); /* Add all the recognized file extensions */ ch = '='; idx = 0; fprintf(pfile, "fileTypes"); while ((p_name = get_file_extension(idx)) != NULL) { fprintf(pfile, "%c*%s", ch, p_name); ch = '|'; } fprintf(pfile, "\n"); /* Add the rest of the constant file header */ fprintf(pfile, "indenterFileName=TechPlayers\n" "indenterName=TechPlayers (C, C++, C#, ObjectiveC, D, Java, Pawn, VALA)\n" "inputFileName=indentinput\n" "inputFileParameter=\"-f \"\n" "manual=http://TechPlayers.sourceforge.net/config.txt\n" "outputFileName=indentoutput\n" "outputFileParameter=\"-o \"\n" "stringparaminquotes=false\n" "parameterOrder=ipo\n" "showHelpParameter=-h\n" "stringparaminquotes=false\n" "useCfgFileParameter=\"-c \"\n" "version=%s\n", TechPlayers_VERSION); /* Now add each option */ for (idx = 0; idx < UG_group_count; idx++) { p_grp = get_group_name(idx); if (p_grp == NULL) { continue; } for (option_list_cit it = p_grp->options.begin(); it != p_grp->options.end(); it++) { const option_map_value *option = get_option_name(*it); // Create a better readable name from the options name // by replacing '_' by a space and use some upper case characters. char *optionNameReadable = new char[strlen(option->name) + 1]; strcpy(optionNameReadable, option->name); bool was_space = true; for (char *character = optionNameReadable; *character != 0; character++) { if (*character == '_') { *character = ' '; was_space = true; } else if (was_space) { *character = unc_toupper(*character); was_space = false; } } fprintf(pfile, "\n[%s]\n", optionNameReadable); fprintf(pfile, "Category=%d\n", idx); fprintf(pfile, "Description=\"<html>"); const char *tmp = option->short_desc; ch = 0; /* Output the decription which may contain forbidden chars */ while (*tmp != 0) { switch (*tmp) { case '<': fprintf(pfile, "<"); break; case '>': fprintf(pfile, ">"); break; case '&': fprintf(pfile, "&"); break; case '\n': fprintf(pfile, "<BR>"); break; default: fputc(*tmp, pfile); } tmp++; } fprintf(pfile, "</html>\"\n"); // Handle some options independent of their type and most by their type. switch (option->id) { // Indenting with tabs selector becomes a multiple selector and not only a number. Also its default enabled. case UO_indent_with_tabs: fprintf(pfile, "Enabled=true\n"); fprintf(pfile, "EditorType=multiple\n"); fprintf(pfile, "Choices=\"%s=0|%s=1|%s=2\"\n", option->name, option->name, option->name); fprintf(pfile, "ChoicesReadable=\"Spaces only|Indent with tabs, align with spaces|Indent and align with tabs\"\n"); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; // All not specially handled options are created only dependent by their type. default: fprintf(pfile, "Enabled=false\n"); switch (option->type) { case AT_BOOL: // [align_keep_tabs] // Category=3 // Description=<html>Whether to keep non-indenting tabs</html> // Value=0 // ValueDefault=0 // EditorType=boolean // TrueFalse="align_keep_tabs=true|align_keep_tabs=false" fprintf(pfile, "EditorType=boolean\n"); fprintf(pfile, "TrueFalse=%s=true|%s=false\n", option->name, option->name); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; case AT_IARF: fprintf(pfile, "EditorType=multiple\n"); fprintf(pfile, "Choices=\"%s=ignore|%s=add|%s=remove|%s=force\"\n", option->name, option->name, option->name, option->name); fprintf(pfile, "ChoicesReadable=\"Ignore %s|Add %s|Remove %s|Force %s\"\n", optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); // [nl_after_switch] // Category=4 // Description=<html>Add or remove newline after 'switch'</html> // Value=3 // ValueDefault=-1 // Enabled=true // EditorType=multiple // Choices="nl_after_switch=ignore|nl_after_switch=add|nl_after_switch=remove|nl_after_switch=force" break; case AT_NUM: // [align_assign_span] // CallName="align_assign_span=" // Category=3 // Description="<html>The span for aligning on '=' in assignments (0=don't align)</html>" // EditorType=numeric // Enabled=false // MaxVal=300 // MinVal=0 // Value=0 // ValueDefault=0 fprintf(pfile, "EditorType=numeric\n"); fprintf(pfile, "CallName=\"%s=\"\n", option->name); fprintf(pfile, "MinVal=%d\n", option->min_val); fprintf(pfile, "MaxVal=%d\n", option->max_val); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; case AT_LINE: // [newlines] // Category=0 // Description=<html>The type of line endings</html> // Value=0 // ValueDefault=-1 // Enabled=true // EditorType=multiple // Choices="newlines=auto|newlines=lf|newlines=crlf|newlines=cr" fprintf(pfile, "EditorType=multiple\n"); fprintf(pfile, "Choices=\"%s=lf|%s=crlf|%s=cr|%s=auto\"\n", option->name, option->name, option->name, option->name); fprintf(pfile, "ChoicesReadable=\"Newlines Unix|Newlines Win|Newlines Mac|Newlines Auto\"\n"); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; case AT_POS: // [pos_bool] // Category=5 // Description=<html>The position of boolean operators in wrapped expressions</html> // Enabled=false // Value=0 // ValueDefault=-1 // EditorType=multiple // Choices="pos_bool=ignore|pos_bool=lead|pos_bool=trail" fprintf(pfile, "EditorType=multiple\n"); fprintf(pfile, "Choices=\"%s=ignore|%s=lead|%s=lead_break|%s=lead_force|%s=trail|%s=trail_break|%s=trail_force\"\n", option->name, option->name, option->name, option->name, option->name, option->name, option->name); fprintf(pfile, "ChoicesReadable=\"Ignore %s|Lead %s|Lead Break %s|Lead Force %s|Trail %s|Trail Break %s|Trail Force %s\"\n", optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable); fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n); break; case AT_STRING: { fprintf(pfile, "CallName=%s=\n", option->name); fprintf(pfile, "EditorType=string\n"); string val_string; const char *val_str; val_string = op_val_to_string(option->type, cpd.settings[option->id]); val_str = val_string.c_str(); fprintf(pfile, "ValueDefault=%s\n", val_str); } break; default: break; } } delete [] optionNameReadable; } } }
CLIOPTS_API int cliopts_parse_options(cliopts_entry *entries, int argc, char **argv, int *lastidx, struct cliopts_extra_settings *settings) { /** * Now let's build ourselves a */ int curmode; int ii, ret = 0, lastidx_s = 0; struct cliopts_priv ctx = { 0 }; struct cliopts_extra_settings default_settings = { 0 }; if (!lastidx) { lastidx = &lastidx_s; } ctx.entries = entries; if (!settings) { settings = &default_settings; settings->show_defaults = 1; } if (!settings->progname) { settings->progname = argv[0]; } if (!settings->argstring) { settings->argstring = "[OPTIONS...]"; } settings->nrestargs = 0; if (!settings->line_max) { settings->line_max = get_terminal_width() - 3; } ii = (settings->argv_noskip) ? 0 : 1; if (ii >= argc) { *lastidx = 0; ret = 0; goto GT_CHECK_REQ; return 0; } curmode = WANT_OPTION; ctx.wanted = curmode; ctx.settings = settings; for (; ii < argc; ii++) { if (curmode == WANT_OPTION) { curmode = parse_option(&ctx, argv[ii]); } else if (curmode == WANT_VALUE) { curmode = parse_value(&ctx, argv[ii]); } if (curmode == MODE_ERROR) { if (settings->error_nohelp == 0) { dump_error(&ctx); } ret = -1; break; } else if (curmode == MODE_HELP) { if (settings->help_noflag) { /* ignore it ? */ continue; } print_help(&ctx, settings); exit(0); } else if (curmode == MODE_RESTARGS) { ii++; break; } else { ctx.wanted = curmode; } } *lastidx = ii; if (curmode == WANT_VALUE) { ret = -1; if (settings->error_nohelp == 0) { fprintf(stderr, "Option %s requires argument\n", ctx.current_key); } goto GT_RET; } GT_CHECK_REQ: { cliopts_entry *cur_ent; for (cur_ent = entries; cur_ent->dest; cur_ent++) { char entbuf[128] = { 0 }; if (cur_ent->found || cur_ent->required == 0) { continue; } ret = -1; if (settings->error_nohelp) { goto GT_RET; } fprintf(stderr, "Required option %s missing\n", get_option_name(cur_ent, entbuf)); } } GT_RET: if (ret == -1) { if (settings->error_nohelp == 0) { print_help(&ctx, settings); } if (settings->error_noexit == 0) { exit(EXIT_FAILURE); } } return ret; }
static void parse_option(install_info *info, const char *component, xmlNodePtr node, OptionsBox *box, int level, OptionsButton *parent, int exclusive, RadioGroup **radio) { xmlNodePtr child; char text[1024] = ""; const char *help; const char *wanted; char *name; int i; OptionsButton *button = NULL; /* See if this node matches the current architecture */ wanted = xmlGetProp(node, "arch"); if ( ! match_arch(info, wanted) ) { return; } wanted = xmlGetProp(node, "libc"); if ( ! match_libc(info, wanted) ) { return; } wanted = xmlGetProp(node, "distro"); if ( ! match_distro(info, wanted) ) { return; } if ( ! get_option_displayed(info, node) ) { return; } /* See if the user wants this option */ if ( node->type == XML_TEXT_NODE ) { //name = g_strdup(node->content); name = strdup(node->content); //!!!TODO - Strip name //g_strstrip(name); if( *name ) { //button = gtk_label_new(name); //gtk_widget_show(button); //gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(button), FALSE, FALSE, 0); button = carbon_OptionsNewLabel(box, name); } //!!!TODO - Free name //g_free(name); return; } else { name = get_option_name(info, node, NULL, 0); for(i=0; i < (level*5); i++) text[i] = ' '; text[i] = '\0'; strncat(text, name, sizeof(text)-strlen(text)); } if ( GetProductIsMeta(info) ) { //button = gtk_radio_button_new_with_label(radio_list, text); //radio_list = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = carbon_OptionsNewRadioButton(box, text, &radio_list); } else if ( exclusive ) { //button = gtk_radio_button_new_with_label(*radio, text); //*radio = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = carbon_OptionsNewRadioButton(box, text, radio); } else { //button = gtk_check_button_new_with_label(text); button = carbon_OptionsNewCheckButton(box, text); } /* Add tooltip help, if available */ help = get_option_help(info, node); if ( help ) { //GtkTooltipsData* group; //group = gtk_tooltips_data_get(window); //if ( group ) { //gtk_tooltips_set_tip( group->tooltips, button, help, 0); //} else { //gtk_tooltips_set_tip( gtk_tooltips_new(), button, help, 0); //} carbon_OptionsSetTooltip(button, help); } /* Set the data associated with the button */ if ( button ) { //gtk_object_set_data(GTK_OBJECT(button), "data", (gpointer)node); button->Data = (void *)node; /* Register the button in the window's private data */ //window = glade_xml_get_widget(setup_glade, "setup_window"); //gtk_object_set_data(GTK_OBJECT(window), name, (gpointer)button); if(strlen(name) >= MAX_BUTTON_NAME) carbon_debug("parse_option() - Button name exceeeded length! This will cause problems with selecting options!\n"); else strcpy(button->Name, name); } /* Check for required option */ if ( xmlGetProp(node, "required") ) { xmlSetProp(node, "install", "true"); //gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE); DisableControl(button->Control); } /* If this is a sub-option and parent is not active, then disable option */ wanted = xmlGetProp(node, "install"); //if( level>0 && GTK_IS_TOGGLE_BUTTON(parent) && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(parent)) ) { if( level>0 && parent->Type == ButtonType_Radio && !carbon_OptionsGetValue(parent)) { wanted = "false"; //gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE); DisableControl(button->Control); } //***This functionality is implemented automatically when creating no option*** // buttons and labels //if ( button ) { // gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(button), FALSE, FALSE, 0); // gtk_signal_connect(GTK_OBJECT(button), "toggled", // GTK_SIGNAL_FUNC(setup_checkbox_option_slot), (gpointer)node); // gtk_widget_show(button); //} if ( wanted && (strcmp(wanted, "true") == 0) ) { //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); carbon_OptionsSetValue(button, true); } else { /* Unmark this option for installation */ mark_option(info, node, "false", 1); } /* Recurse down any other options */ child = node->childs; while ( child ) { if ( !strcmp(child->name, "option") ) { //parse_option(info, component, child, window, box, level+1, button, 0, NULL); parse_option(info, component, child, box, level+1, button, 0, NULL); } else if ( !strcmp(child->name, "exclusive") ) { xmlNodePtr exchild; //GSList *list = NULL; RadioGroup *list = NULL; for ( exchild = child->childs; exchild; exchild = exchild->next) { //parse_option(info, component, exchild, window, box, level+1, button, 1, &list); parse_option(info, component, exchild, box, level+1, button, 1, &list); } } child = child->next; } /* Disable any options that are already installed */ if ( info->product && ! GetProductReinstall(info) ) { product_component_t *comp; if ( component ) { comp = loki_find_component(info->product, component); } else { comp = loki_getdefault_component(info->product); } if ( comp && loki_find_option(comp, name) ) { /* Unmark this option for installation */ //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); //gtk_widget_set_sensitive(button, FALSE); carbon_OptionsSetValue(button, FALSE); DisableControl(button->Control); mark_option(info, node, "false", 1); } } }
//void setup_checkbox_option_slot( GtkWidget* widget, gpointer func_data) int OnOptionClickEvent(OptionsButton *ButtonWithEventClick) { //GtkWidget *window; xmlNodePtr node; //xmlNodePtr data_node = (xmlNodePtr) func_data; //gtk_object_get_data(GTK_OBJECT(widget),"data"); xmlNodePtr data_node = (xmlNodePtr)ButtonWithEventClick->Data; carbon_debug("OnOptionClickEvent()\n"); if(!data_node) return true; //window = glade_xml_get_widget(setup_glade, "setup_window"); //if(GTK_TOGGLE_BUTTON(widget)->active) if(carbon_OptionsGetValue(ButtonWithEventClick)) { carbon_debug("OnOptionClickEvent() - Button toggle to true\n"); const char *warn = get_option_warn(cur_info, data_node); // does this option require a seperate EULA? xmlNodePtr child; child = data_node->childs; while(child) { if (!strcmp(child->name, "eula")) { const char* name = GetProductEULANode(cur_info, data_node, NULL); if(name) { char buffer[MAX_README_SIZE]; load_file(name, buffer, MAX_README_SIZE); if(!carbon_ReadmeOrLicense(MyRes, false, buffer)) { carbon_OptionsSetValue(ButtonWithEventClick, false); return true; } // Else, license was accepted...get out of loop break; } else { log_warning("option-specific EULA not found, can't set option on\n"); // EULA not found or not accepted carbon_OptionsSetValue(ButtonWithEventClick, false); return true; } } child = child->next; } if ( warn && !in_setup ) { // Display a warning message to the user carbonui_prompt(warn, RESPONSE_OK); } /* Mark this option for installation */ mark_option(cur_info, data_node, "true", 0); /* Recurse down any other options to re-enable grayed out options */ node = data_node->childs; while ( node ) { //enable_tree(node, window); EnableTree(node, (OptionsBox *)ButtonWithEventClick->Box); node = node->next; } } else { carbon_debug("OnOptionClickEvent() - Button toggle to false\n"); /* Unmark this option for installation */ mark_option(cur_info, data_node, "false", 1); /* Recurse down any other options */ node = data_node->childs; while ( node ) { if ( !strcmp(node->name, "option") ) { //GtkWidget *button; //button = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(window), // get_option_name(cur_info, node, NULL, 0)); OptionsButton *button; button = carbon_GetButtonByName((OptionsBox *)ButtonWithEventClick->Box, get_option_name(cur_info, node, NULL, 0)); if(button){ /* This recursively calls this function */ //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); //gtk_widget_set_sensitive(button, FALSE); carbon_OptionsSetValue(button, false); DisableControl(button->Control); } } else if ( !strcmp(node->name, "exclusive") ) { xmlNodePtr child; for ( child = node->childs; child; child = child->next) { //GtkWidget *button; //button = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(window), // get_option_name(cur_info, child, NULL, 0)); OptionsButton *button; button = carbon_GetButtonByName((OptionsBox *)ButtonWithEventClick->Box, get_option_name(cur_info, node, NULL, 0)); if(button){ /* This recursively calls this function */ //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); //gtk_widget_set_sensitive(button, FALSE); carbon_OptionsSetValue(button, false); DisableControl(button->Control); } } } node = node->next; } } cur_info->install_size = size_tree(cur_info, cur_info->config->root->childs); update_size(); return true; }