⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tkgen.c

📁 fsmlabs的real time linux的内核
💻 C
📖 第 1 页 / 共 3 页
字号:
    /*     * Now that the whole window is in place, we need to wait for an "update"     * so we can tell the canvas what its virtual size should be.     *     * Unfortunately, this causes some ugly screen-flashing because the whole     * window is drawn, and then it is immediately resized.  It seems     * unavoidable, though, since "frame" objects won't tell us their size     * until after an update, and "canvas" objects can't automatically pack     * around frames.  Sigh.     */    printf( "\tupdate idletasks\n" );    printf( "\t$w.config.canvas create window 0 0 -anchor nw -window $w.config.f\n\n" );    printf( "\t$w.config.canvas configure \\\n" );    printf( "\t\t-width [expr [winfo reqwidth $w.config.f] + 1]\\\n" );    printf( "\t\t-scrollregion \"-1 -1 [expr [winfo reqwidth $w.config.f] + 1] \\\n" );    printf( "\t\t\t [expr [winfo reqheight $w.config.f] + 1]\"\n\n" );	     /*     * If the whole canvas will fit in 3/4 of the screen height, do it;     * otherwise, resize to around 1/2 the screen and let us scroll.     */    printf( "\tset winy [expr [winfo reqh $w] - [winfo reqh $w.config.canvas]]\n" );    printf( "\tset scry [expr [winfo screenh $w] / 2]\n" );    printf( "\tset maxy [expr [winfo screenh $w] * 3 / 4]\n" );    printf( "\tset canvtotal [expr [winfo reqh $w.config.f] + 2]\n" );    printf( "\tif [expr $winy + $canvtotal < $maxy] {\n" );    printf( "\t\t$w.config.canvas configure -height $canvtotal\n" );    printf( "\t} else {\n" );    printf( "\t\t$w.config.canvas configure -height [expr $scry - $winy]\n" );    printf( "\t}\n" );    /*     * Limit the min/max window size.  Height can vary, but not width,     * because of the limitations of canvas and our laziness.     */    printf( "\tupdate idletasks\n" );    printf( "\twm maxsize $w [winfo width $w] [winfo screenheight $w]\n" );    printf( "\twm minsize $w [winfo width $w] 100\n\n" );    printf( "\twm deiconify $w\n" );    printf( "}\n\n\n" );    /*     * Now we generate the companion procedure for the menu we just     * generated.  This procedure contains all of the code to     * disable/enable widgets based upon the settings of the other     * widgets, and will be called first when the window is mapped,     * and each time one of the buttons in the window are clicked.     */    printf( "proc update_menu%d {} {\n", menu_num );    /*     * Clear all of the booleans that are defined in this menu.     */    clear_globalflags();    for ( cfg = scfg; cfg != NULL; cfg = cfg->next )    {	if ( cfg->menu_number == menu_num	&&   cfg->token != token_mainmenu_option	&&   cfg->token != token_choice_item )	{	    if ( cfg->cond != NULL )	    {		int i;		if ( (cfg->token == token_tristate || cfg->token == token_dep_tristate)		&& ! vartable[i = get_varnum( "CONFIG_MODULES" )].global_written )		{		    global( "CONFIG_MODULES" );		    vartable[i].global_written = 1;		}		generate_if( cfg, cfg->cond, cfg->menu_number, cfg->menu_line );	    }	    else	    {		if ( cfg->token == token_tristate )		{		    if ( ! vartable[cfg->nameindex].global_written )		    {			vartable[cfg->nameindex].global_written = 1;			printf( "\tglobal %s\n", vartable[cfg->nameindex].name );		    }		    if ( ! vartable[i = get_varnum( "CONFIG_MODULES" )].global_written )		    {			global( "CONFIG_MODULES" );			vartable[i].global_written = 1;		    }		    printf( "\n\tif {($CONFIG_MODULES == 1)} then {configure_entry .menu%d.config.f.x%d normal {m}} else {configure_entry .menu%d.config.f.x%d disabled {m}}\n",			menu_num, cfg->menu_line,			menu_num, cfg->menu_line );		}	    }	}	else if ( cfg->token == token_mainmenu_option	     &&   cfg->menu_number == menu_num	     &&   cfg->cond != NULL )	{	    generate_if( cfg, cfg->cond, menu_num, cfg->menu_line );	}    }    printf("}\n\n\n");    generate_update_var( scfg, menu_num );}/* * This is the top level function for generating the tk script. */void dump_tk_script( struct kconfig * scfg ){    int menu_depth;    int menu_num [64];    int imenu, i;    int top_level_num = 0;    struct kconfig * cfg;    struct kconfig * cfg1 = NULL;    const char * name = "No Name";    /*     * Mark begin and end of each menu so I can omit submenus when walking     * over a parent menu.     */    tot_menu_num = 0;    menu_depth   = 0;    menu_num [0] = 0;    for ( cfg = scfg; cfg != NULL; cfg = cfg->next )    {	switch ( cfg->token )	{	default:	    break;	case token_mainmenu_name:	    name = cfg->label;	    break;	case token_mainmenu_option:	    if ( ++menu_depth >= 64 )		{ fprintf( stderr, "menus too deep\n" ); exit( 1 ); }	    if ( ++tot_menu_num >= 100 )		{ fprintf( stderr, "too many menus\n" ); exit( 1 ); }	    menu_num   [menu_depth]   = tot_menu_num;	    menu_first [tot_menu_num] = cfg;	    menu_last  [tot_menu_num] = cfg;	    /*	     * Note, that menu_number is set to the number of parent 	     * (upper level) menu.	     */	    cfg->menu_number = menu_num[menu_depth - 1];	    if ( menu_depth == 1 )		++top_level_num;	    break;	case token_endmenu:	    menu_last [menu_num [menu_depth]] = cfg;	    /* flatten menus with proper scoping */	    if ( --menu_depth < 0 )		{ fprintf( stderr, "unmatched endmenu\n" ); exit( 1 ); }	    break;	case token_bool:	case token_choice_header:	case token_choice_item:	case token_dep_bool:	case token_dep_tristate:	case token_dep_mbool:	case token_hex:	case token_int:	case token_string:	case token_tristate:	    cfg->menu_number = menu_num[menu_depth];	    if ( menu_depth == 0 )		{ fprintf( stderr, "statement not in menu\n" ); exit( 1 ); }	    break;	case token_define_bool:	case token_define_hex:	case token_define_int:	case token_define_string:	case token_define_tristate:	case token_unset:	    cfg->menu_number = menu_num[menu_depth];	    break;	}    }    /*     * Generate menus per column setting.     * There are:     *   four extra buttons for save/quit/load/store;     *   one blank button     *   add two to round up for division     */    printf( "set menus_per_column %d\n", (top_level_num + 4 + 1 + 2) / 3 );    printf( "set total_menus %d\n\n", tot_menu_num );    printf( "proc toplevel_menu {num} {\n" );    for ( imenu = 1; imenu <= tot_menu_num; ++imenu )    {	int parent = 1;	if ( menu_first[imenu]->menu_number == 0 )	    parent = menu_first[imenu]->menu_number;	else	    printf( "\tif {$num == %d} then {return %d}\n",		imenu, menu_first[imenu]->menu_number );    }    printf( "\treturn $num\n}\n\n" );    /*     * Generate the menus.     */    printf( "mainmenu_name \"%s\"\n", name );    for ( imenu = 1; imenu <= tot_menu_num; ++imenu )    {	int menu_line = 0;	int nr_submenu = imenu;	clear_globalflags();	start_proc( menu_first[imenu]->label, imenu, 		!menu_first[imenu]->menu_number );	for ( cfg = menu_first[imenu]->next; cfg != NULL && cfg != menu_last[imenu]; cfg = cfg->next )	{	    switch ( cfg->token )	    {	    default:		break;	    case token_mainmenu_option:		while ( menu_first[++nr_submenu]->menu_number > imenu )		    ;		cfg->menu_line = menu_line++;		printf( "\tsubmenu $w.config.f %d %d \"%s\" %d\n",		    cfg->menu_number, cfg->menu_line, cfg->label, nr_submenu );		cfg = menu_last[nr_submenu];		break;	    case token_bool:		cfg->menu_line = menu_line++;		printf( "\tbool $w.config.f %d %d \"%s\" %s\n",		    cfg->menu_number, cfg->menu_line, cfg->label,		    vartable[cfg->nameindex].name );		break;	    case token_choice_header:		/*		 * I need the first token_choice_item to pick out the right		 * help text from doc/Configure.help.		 */		cfg->menu_line = menu_line++;		printf( "\tglobal tmpvar_%d\n", -(cfg->nameindex) );		printf( "\tminimenu $w.config.f %d %d \"%s\" tmpvar_%d %s\n",		    cfg->menu_number, cfg->menu_line, cfg->label,		    -(cfg->nameindex), vartable[cfg->next->nameindex].name );		printf( "\tmenu $w.config.f.x%d.x.menu\n", cfg->menu_line );		cfg1 = cfg;		break;	    case token_choice_item:		/* note: no menu line; uses choice header menu line */		printf( "\t$w.config.f.x%d.x.menu add radiobutton -label \"%s\" -variable tmpvar_%d -value \"%s\" -command \"update_active\"\n",		    cfg1->menu_line, cfg->label, -(cfg1->nameindex),		    cfg->label );		break;	    case token_dep_bool:	    case token_dep_mbool:		cfg->menu_line = menu_line++;		printf( "\tdep_bool $w.config.f %d %d \"%s\" %s\n",		    cfg->menu_number, cfg->menu_line, cfg->label,		    vartable[cfg->nameindex].name );		break;	    case token_dep_tristate:		cfg->menu_line = menu_line++;		printf( "\tdep_tristate $w.config.f %d %d \"%s\" %s\n",		    cfg->menu_number, cfg->menu_line, cfg->label,		    vartable[cfg->nameindex].name );		break;	    case token_hex:		cfg->menu_line = menu_line++;		printf( "\thex $w.config.f %d %d \"%s\" %s\n",		    cfg->menu_number, cfg->menu_line, cfg->label,		    vartable[cfg->nameindex].name );		break;	    case token_int:		cfg->menu_line = menu_line++;		printf( "\tint $w.config.f %d %d \"%s\" %s\n",		    cfg->menu_number, cfg->menu_line, cfg->label,		    vartable[cfg->nameindex].name );		break;	    case token_string:		cfg->menu_line = menu_line++;		printf( "\tistring $w.config.f %d %d \"%s\" %s\n",		    cfg->menu_number, cfg->menu_line, cfg->label,		    vartable[cfg->nameindex].name );		break;	    case token_tristate:		cfg->menu_line = menu_line++;		printf( "\ttristate $w.config.f %d %d \"%s\" %s\n",		    cfg->menu_number, cfg->menu_line, cfg->label,		    vartable[cfg->nameindex].name );		break;	    }	}	end_proc( scfg, imenu );    }    /*     * The top level menu also needs an update function.  When we update a     * submenu, we may need to disable one or more of the submenus on     * the top level menu, and this procedure will ensure that things are     * correct.     */    clear_globalflags();    printf( "proc update_mainmenu {}  {\n" );    for ( imenu = 1; imenu <= tot_menu_num; imenu++ )    {	if ( menu_first[imenu]->cond != NULL && menu_first[imenu]->menu_number == 0 )	    generate_if( menu_first[imenu], menu_first[imenu]->cond, imenu, -1 );    }    printf( "}\n\n\n" );    clear_globalflags();    /*     * Generate code to load the default settings into the variables.     * The script in tail.tk will attempt to load .config,     * which may override these settings, but that's OK.     */    for ( cfg = scfg; cfg != NULL; cfg = cfg->next )    {	switch ( cfg->token )	{	default:	    break;	case token_bool:	case token_choice_item:	case token_dep_bool:	case token_dep_tristate:	case token_dep_mbool:	case token_tristate:	    if ( ! vartable[cfg->nameindex].global_written )	    {		printf( "set %s 0\n", vartable[cfg->nameindex].name );		vartable[cfg->nameindex].global_written = 1;	    }	    break;	case token_choice_header:	    printf( "set tmpvar_%d \"(not set)\"\n", -(cfg->nameindex) );	    break;	case token_hex:	case token_int:	    if ( ! vartable[cfg->nameindex].global_written )	    {		printf( "set %s %s\n", vartable[cfg->nameindex].name, cfg->value ? cfg->value : "0" );		vartable[cfg->nameindex].global_written = 1;	    }	    break;	case token_string:	    if ( ! vartable[cfg->nameindex].global_written )	    {		printf( "set %s \"%s\"\n", vartable[cfg->nameindex].name, cfg->value );		vartable[cfg->nameindex].global_written = 1;	    }	    break;	}    }    /*     * Define to an empty value all other variables (which are never defined)     */    for ( i = 1; i <= max_varnum; i++ )    {	if ( ! vartable[i].global_written	&&   strncmp( vartable[i].name, "CONSTANT_", 9 ) )	    printf( "set %s 4\n", vartable[i].name );    }    /*     * Generate a function to write all of the variables to a file.     */    printf( "proc writeconfig {file1 file2} {\n" );    printf( "\tset cfg [open $file1 w]\n" );    printf( "\tset autocfg [open $file2 w]\n" );    printf( "\tset notmod 1\n" );    printf( "\tset notset 0\n" );    printf( "\tputs $cfg \"#\"\n");    printf( "\tputs $cfg \"# Automatically generated make config: don't edit\"\n");    printf( "\tputs $cfg \"#\"\n" );    printf( "\tputs $autocfg \"/*\"\n" );    printf( "\tputs $autocfg \" * Automatically generated C config: don't edit\"\n" );    printf( "\tputs $autocfg \" */\"\n" );    printf( "\tputs $autocfg \"#define RTL_AUTOCONF_INCLUDED\"\n" );    clear_globalflags();    for ( cfg = scfg; cfg != NULL; cfg = cfg->next )    {	switch ( cfg->token )	{	default:	    break;	case token_bool:	case token_choice_header:	case token_comment:	case token_define_bool:	case token_define_hex:	case token_define_int:	case token_define_string:	case token_define_tristate:	case token_dep_bool:	case token_dep_tristate:	case token_dep_mbool:	case token_hex:	case token_int:	case token_string:	case token_tristate:	    generate_writeconfig( cfg );	    break;	}    }    printf( "\tclose $cfg\n" );    printf( "\tclose $autocfg\n" );    printf( "}\n\n\n" );    /*     * Generate a simple function that updates the master choice     * variable depending upon what values were loaded from a .config     * file.       */    printf( "proc clear_choices { } {\n" );    for ( cfg = scfg; cfg != NULL; cfg = cfg->next )    {	if ( cfg->token == token_choice_header )	{	    for ( cfg1  = cfg->next; 		  cfg1 != NULL && cfg1->token == token_choice_item;		  cfg1  = cfg1->next )	    {		printf( "\tglobal %s; set %s 0\n",		    vartable[cfg1->nameindex].name,		    vartable[cfg1->nameindex].name );	    }	}    }    printf( "}\n\n\n" );    printf( "proc update_choices { } {\n" );    for ( cfg = scfg; cfg != NULL; cfg = cfg->next )    {	if ( cfg->token == token_choice_header )	{	    printf( "\tglobal tmpvar_%d\n", -(cfg->nameindex) );	    printf("\tset tmpvar_%d \"%s\"\n", -(cfg->nameindex), cfg->value);	    for ( cfg1  = cfg->next; 		  cfg1 != NULL && cfg1->token == token_choice_item;		  cfg1  = cfg1->next )	    {		printf( "\tglobal %s\n", vartable[cfg1->nameindex].name );		printf( "\tif { $%s == 1 } then { set tmpvar_%d \"%s\" }\n",		    vartable[cfg1->nameindex].name,		    -(cfg->nameindex), cfg1->label );	    }	}    }    printf( "}\n\n\n" );    generate_update_var( scfg, 0 );    /*     * That's it.  We are done.  The output of this file will have header.tk     * prepended and tail.tk appended to create an executable wish script.     */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -