diff -urN alterator-x11-0.13.7.orig/tools/xconf/Makefile alterator-x11-0.13.7/tools/xconf/Makefile --- alterator-x11-0.13.7.orig/tools/xconf/Makefile 2008-04-02 15:33:15 +0300 +++ alterator-x11-0.13.7/tools/xconf/Makefile 2008-04-07 20:18:53 +0300 @@ -1,4 +1,4 @@ -CFLAGS=$(RPM_OPT_FLAGS) -Wall -I/usr/X11R6/include/ -DVERSION=\"0.1\" -D_GNU_SOURCE=1 -g +CFLAGS=$(RPM_OPT_FLAGS) -Wall -I/usr/X11R6/include/ -DVERSION=\"0.2\" -D_GNU_SOURCE=1 LDLIBS=-lxf86config -lm -lXt all:xconf diff -urN alterator-x11-0.13.7.orig/tools/xconf/xconf.c alterator-x11-0.13.7/tools/xconf/xconf.c --- alterator-x11-0.13.7.orig/tools/xconf/xconf.c 2008-04-02 15:33:15 +0300 +++ alterator-x11-0.13.7/tools/xconf/xconf.c 2008-04-08 18:11:36 +0300 @@ -50,6 +50,110 @@ XtFree(p->x); \ p->x=XtNewString(""); +#define AddListItem(type, head, new) \ + head = (type) xf86addListItem((GenericListPtr) (head), (GenericListPtr) (new)); + +#define LoadList conf->conf_modules->mod_load_lst +#define DisableList conf->conf_modules->mod_disable_lst + +void get_loads(XF86ConfigPtr conf) +{ + XF86LoadPtr l; + + for (l = LoadList; l != NULL; l = l->list.next) + if (l->load_type == XF86_LOAD_MODULE) + printf("%s\n", l->load_name); +} + +void inline set_module(XF86ConfigPtr conf, const char *module, int in, int out) +{ + XF86LoadPtr l; + int f = 0; + + if (LoadList != DisableList) + AddListItem(XF86LoadPtr, LoadList, DisableList); + for (l = LoadList; l != NULL; l = l->list.next) + if ((l->load_opt == NULL) && (strcmp(l->load_name, module) == 0)) + { + if (l->load_type == in) + { + l->load_type = out; + l->load_comment = NULL; + l->ignore = 0; + } + f = 1; + } + if ((f == 0) && ((l = malloc(sizeof(XF86LoadRec))) != NULL)) + { + l->load_name = (char*) module; + l->load_opt = NULL; + l->list.next = NULL; + l->load_type = out; + l->load_comment = NULL; + l->ignore = 0; + AddListItem(XF86LoadPtr, LoadList, l); + } +} + +void set_loads(XF86ConfigPtr conf, const char *module) +{ + set_module(conf, module, XF86_DISABLE_MODULE, XF86_LOAD_MODULE); +} + +void get_disabled(XF86ConfigPtr conf) +{ + XF86LoadPtr l; + + for (l = DisableList; l != NULL; l = l->list.next) + if (l->load_type == XF86_DISABLE_MODULE) + printf("%s\n", l->load_name); +} + +void set_disable(XF86ConfigPtr conf, const char *module) +{ + set_module(conf, module, XF86_LOAD_MODULE, XF86_DISABLE_MODULE); +} + +#define ExtOptList conf->conf_extensions->ext_option_lst + +void get_extopts(XF86ConfigPtr conf) +{ + if (conf->conf_extensions != NULL) + { + XF86OptionPtr p; + for (p = ExtOptList; p != NULL; p = xf86nextOption(p)) + printf("%s=%s\n", xf86optionName(p), xf86optionValue(p)); + } +} + +void get_extopt(XF86ConfigPtr conf, const char *name) +{ + if (conf->conf_extensions != NULL) + { + XF86OptionPtr p; + if ((p = xf86findOption(ExtOptList, name)) != NULL) + printf("%s\n", xf86optionValue(p)); + } +} + +void set_extopt(XF86ConfigPtr conf, char *opt) +{ + char *c = strchr(opt, '='); + + if (c != NULL) + { + if (conf->conf_extensions == NULL) + { + conf->conf_extensions = malloc(sizeof(XF86ConfExtensionsRec)); + if (conf->conf_extensions == NULL) return; + ExtOptList = NULL; + conf->conf_extensions->extensions_comment = NULL; + } + *c = '\0'; + ExtOptList = xf86addNewOption(ExtOptList, opt, &(c[1])); + } +} + void setup_monitor(XF86ConfigPtr conf,const char *monitor_name) { char * line = NULL; @@ -335,7 +439,7 @@ usage (int retcode) { fprintf (stdout, - "Usage: %s old_config [new_config] \n" + "Usage: %s [...] old_config [new_config] \n" "\tnew_config is necessarily for all modifications", __progname); fputs ("\nTree - utility to read and modify some xorg config section\n", @@ -350,7 +454,14 @@ "\t-c, --get-color-depth get current default color depth value\n" "\t-C, --set-color-depth set new default color depth value\n" "\t-r, --get-resolution get current resolution list (mode list)\n" - "\t-R, --set-resolution set new resolution list (mode list)\n", + "\t-R, --set-resolution set new resolution list (mode list)\n" + "\t-l, --get-loads get current modules list to load\n" + "\t-L, --set-loads set new module to load\n" + "\t-a, --get-extopts get options from Section Extensions (=)\n" + "\t-E, --set-extopt set option in Section Extensions (=)\n" + "\t-e, --get-extopt get specified option from Section Extensions\n" + "\t-m, --get-disable get current modules list to disable\n" + "\t-M, --set-disable set module to disable\n", stdout); fputs ("\nReport bugs to \n", stdout); @@ -367,16 +478,48 @@ scolor, gres, sres, - gdriver} action_type; + gdriver, + gloads, + sloads, + gextopts, + sextopt, + gextopt, + gdisable, + sdisable} action_type; + +typedef struct ActionRec + { + GenericListRec list; + action_type type; + char *arg; + } ActionRec, *ActionPtr; + +ActionPtr add_action_to_list(ActionPtr actions, action_type a, const char *arg) +{ + ActionPtr action = malloc(sizeof(ActionRec)); + + if (action != NULL) + { + action->list.next = NULL; + action->type = a; + action->arg = (char*) arg; + return AddListItem(ActionPtr, actions, action); + } + else + return actions; +} + +#define add_action(a, arg) add_action_to_list(actions, (a), (arg)) +#define add_info(a) add_action((a), NULL) int main(int argc,char *argv[]) { - action_type action; const char *filename; XF86ConfigPtr conf; - char *name = 0; char *oldconfig = 0; char *newconfig = 0; + ActionPtr actions = NULL; + int write_config = 0; while (1) { @@ -392,11 +535,18 @@ {"set-color-depth", required_argument, 0, 'C'}, {"get-resolution", no_argument, 0, 'r'}, {"set-resolution", required_argument, 0, 'R'}, + {"get-loads", no_argument, 0, 'l'}, + {"set-loads", required_argument, 0, 'L'}, + {"get-extopts",no_argument, 0, 'a'}, + {"set-extopt", required_argument, 0, 'E'}, + {"get-extopt", required_argument, 0, 'e'}, + {"get-disable",no_argument, 0, 'm'}, + {"set-disable",required_argument, 0, 'M'}, {0, 0, 0, 0} }; char c; - c = getopt_long (argc, argv, "hvdD:nN:cC:rR:", long_options, NULL); + c = getopt_long (argc, argv, "hvdD:nN:cC:rR:lL:eE:a:mM:", long_options, NULL); if (c == -1) break; switch (c) @@ -405,37 +555,62 @@ usage (EXIT_SUCCESS); case 'v': fputs ("XConfig reader/changer " VERSION "\n" - "Written by Stanislav Ievlev\n\n" - "Copyright (C) 2005 ALT Linux Team\n", + "Written by Stanislav Ievlev\n" + "Completed by Led\n\n" + "Copyright (C) 2005,2008 ALT Linux Team\n", stdout); exit (EXIT_SUCCESS); case 'd': - action = gdevice; + actions = add_info(gdevice); break; case 'D': - action = sdevice; - name = strdup(optarg); + actions = add_action(sdevice, strdup(optarg)); + write_config++; break; case 'n': - action = gmon; + actions = add_info(gmon); break; case 'N': - action = smon; - name=strdup(optarg); + actions = add_action(smon, strdup(optarg)); + write_config++; break; case 'c': - action = gcolor; + actions = add_info(gcolor); break; case 'C': - action = scolor; - name=strdup(optarg); + actions = add_action(scolor, strdup(optarg)); + write_config++; break; case 'r': - action = gres; + actions = add_info(gres); break; case 'R': - action = sres; - name=strdup(optarg); + actions = add_action(sres, strdup(optarg)); + write_config++; + break; + case 'l': + actions = add_info(gloads); + break; + case 'L': + actions = add_action(sloads, strdup(optarg)); + write_config++; + break; + case 'e': + actions = add_info(gextopts); + break; + case 'E': + actions = add_action(sextopt, strdup(optarg)); + write_config++; + break; + case 'a': + actions = add_action(gextopt, strdup(optarg)); + break; + case 'm': + actions = add_info(gdisable); + break; + case 'M': + actions = add_action(sdisable, strdup(optarg)); + write_config++; break; default: usage (EXIT_FAILURE); @@ -448,11 +623,7 @@ if (((argc - optind) > 2) || ((argc - optind) == 0) || - ((action == sdevice || - action == scolor || - action == sres || - action == smon) && - ((argc - optind) == 1))) + (write_config && ((argc - optind) == 1))) usage(EXIT_FAILURE); oldconfig = argv[optind]; @@ -468,7 +639,8 @@ } xf86closeConfigFile (); - switch (action) + for (; actions != NULL; actions = actions->list.next) { + switch (actions->type) { case gdevice: { @@ -478,7 +650,7 @@ } break; case sdevice: - setup_device(conf,name); + setup_device(conf, actions->arg); break; case gmon: { @@ -489,7 +661,7 @@ } break; case smon: - setup_monitor(conf,name); + setup_monitor(conf, actions->arg); break; case gcolor: printf("%d\n",find_screen(conf)->scrn_defaultdepth); @@ -498,7 +670,7 @@ { XF86ConfScreenPtr screen; for (screen = find_screen(conf); screen; screen = screen->list.next) - screen->scrn_defaultdepth = atoi(name); + screen->scrn_defaultdepth = atoi(actions->arg); } break; case gres: @@ -516,17 +688,36 @@ break; } case sres: - setup_resolution(conf,name); + setup_resolution(conf, actions->arg); + break; + case gloads: + get_loads(conf); + break; + case sloads: + set_loads(conf, actions->arg); + break; + case gextopts: + get_extopts(conf); + break; + case sextopt: + set_extopt(conf, actions->arg); + break; + case gextopt: + get_extopt(conf, actions->arg); + break; + case gdisable: + get_disabled(conf); + break; + case sdisable: + set_disable(conf, actions->arg); break; default: fprintf(stderr,"fatal:unknown action type\n"); exit(EXIT_FAILURE); } - - if (action == sdevice || - action == smon || - action == sres || - action == scolor) + } + + if (write_config) xf86writeConfigFile (newconfig, conf); return EXIT_SUCCESS;