# Modi fr die generierung

static doGUI;		# TRUE: generiere GUI Map
static doFRM;		# TRUE: generiere FRM Struktur (Excel Datei)
static doLIB;		# TRUE: generiere LIB Skript (eien Funktion pro Window)
static doDRV;		# TRUE: generiere DRV Skript (Elemente der switch-Statement)

# Dateinamen

static homedir = getvar( "tempdir" );
static GUIfile = join_path( homedir, "wiz.gui" );
static FRMfile = join_path( homedir, "wizcsv.wri" );
static LIBfile = join_path( homedir, "wizlib.wri" );
static DRVfile = join_path( homedir, "wizdrv.wri" );

# Flagge, die zeigt ob ein TSL_hdr geschriebe wurde (d.h. TS_trl ist ntig)
static flag_LIBhdr = 0;

static selName;
static stepName;
static funcName;

static flag_noObj;  # indictes whether to record the object or not

# Patch oe Simens light-weight objects
static const PARENT_NAME_SUFFIX = "_label";
static has_parent, parent_name, parent_desc;
# end patch

#------------------------------------------------------------------------------------
# callbacks 
#------------------------------------------------------------------------------------
 
public function wizard_mode_callback ( in guif, in frmf, in libf, in drvf, in dir, in gui, in frm, in lib, in drv, in clear )
{
	if ( !gui && !frm && !lib && !drv && !clear )
		return "?";
		
	if ( dir != "" )	homedir = dir;
	if ( guif != "" )	GUIfile = join_path( homedir, strip_trail( guif, ".gui") & ".gui" );
	if ( frmf != "" )	FRMfile =  join_path( homedir, strip_trail( frmf, ".csv") & ".csv" );
	if ( libf != "" )	LIBfile =  join_path( homedir, strip_trail( libf, ".tsl") & ".tsl" );
	if ( drvf != "" )	DRVfile =  join_path( homedir, strip_trail( drvf, ".tsl") & ".tsl" );
	doGUI = gui;
	doFRM = frm;
	doLIB = lib;
	doDRV = drv;
	if ( doGUI && clear )
	{
		clear_file( GUIfile );
#		GUI_buf_new( GUIfile );
		GUI_load( GUIfile );
	}
	if ( doFRM && clear )
	{
		clear_file( FRMfile );
		generate_frm_titles();
	}
	if ( doLIB && clear )
	{
		clear_file( LIBfile );
	}
	if ( doDRV && clear )
	{
		clear_file( DRVfile );
	}
	return 0;
}

public function select_callback ( in name, in pick, in select )
{
	selName = name;
	if ( pick )	return 1;
	if ( select ) return 2;
	if ( name != "" ) return 3;
	return "?";
} 

public function select_callback2 ( in name, in obj, in win )
{
	if ( obj ) return 1;
	if ( win ) return 2;
	return (name=="" ? "?" : name);
} 

public function win_callback ( in name, in stp, in func, in other )
{
	stepName = stp;
	funcName = func;
	if ( other )	return -1;
	return (name=="" ? "?" : name);
}

public function obj_callback ( in name, in other, in noObj )
{
	flag_noObj = noObj;
	if ( other )	return -1;
	return (name=="" ? "?" : name);
}

#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------

static function minimizeWR ()
{
	auto hWnd;
	load( "win32api", 1, 1 );
	hWnd = GetForegroundWindow();
	ShowWindow( hWnd, SW_MINIMIZE );
	return hWnd;
}

static function restoreWR ( in hWnd )
{
	ShowWindow( hWnd, SW_RESTORE );
}

#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------

public function clear_file( in file )
{
	auto rc = E_OK;
	rc+= file_open( file, FO_MODE_WRITE );
	rc+= file_close( file );
	return rc;
}

public function a( in file, in str )
{
	auto rc;
	rc = file_open( file, FO_MODE_APPEND );
	rc+= file_printf( file, str );
	rc+= file_close( file );
	return rc;
}

#------------------------------------------------------------------------------------
# select-Funktionen
#------------------------------------------------------------------------------------

public function select_win ( out buf, out win, out desc, out name )
{
	auto rc, arr1[], arr2[], arr3[], count, list, i, dummy;
	rc = GUI_list_map_buffers( arr1, count );
	if ( rc != E_OK ) return rc;
	for( i=1; i<=count; i++ )
	{
		split_path( arr1[i], dummy, arr2[i] );
		arr3[arr2[i]] = arr1[i];
	}
	list = arr2str( arr2, ",", count, 1 );
	rc = create_list_dialog( "Buffers",
		"Bitte whlen Sie ein GUI-Buffer aus",
		list );
	if ( rc == "" ) return rc;
	buf = arr3[rc];
	rc = GUI_list_buf_windows( buf, arr1, count );
	if ( rc != E_OK ) return rc;
	list = arr2str( arr1, ",", count, 1 );
	rc = create_list_dialog( "Windows",
		"Bitte whlen Sie ein WINDOW aus",
		list );
	if ( rc == "" ) return rc;
	win = rc;
	rc = GUI_buf_get_desc( buf, win, "", desc );
	rc = GUI_buf_get_logical_name( buf, desc, "", name );
	return rc; 
}

public function select_obj ( in buf, in win, out obj, out desc, out name )
{
	auto rc, arr[], count, list, i;
	rc = GUI_list_win_objects( buf, win, arr, count );
	if ( rc != E_OK ) return rc;
	list = arr2str( arr, ",", count, 1 );
	rc = create_list_dialog( "Objects",
		"Bitte whlen Sie ein OBJEKT aus",
		list );
	if ( rc == "" ) return rc;
	obj = rc;
	rc = GUI_buf_get_desc( buf, win, obj, desc );
	rc = GUI_buf_get_logical_name( buf, desc, win, name );
	return rc; 
}

#------------------------------------------------------------------------------------
# point2-Funktionen
#------------------------------------------------------------------------------------

static win, obj;
static const WIN = "TmpWin";
static const OBJ = "TmpObj";

public function win_get_name ( in desc )
{
	auto val;
	if ( GUI_desc_get_attr ( desc, "label", val ) == E_OK )	
		if ( val != "" ) return val;
	if ( GUI_desc_get_attr ( desc, "html_name", val ) == E_OK )	
		if ( val != "" ) return val;
	if ( GUI_desc_get_attr ( desc, "owner", val ) == E_OK )
		if ( val != "" ) return val;
	return "";
}

public function obj_get_name ( in desc )
{
	auto val;
	if ( GUI_desc_get_attr ( desc, "label", val ) == E_OK )
		if ( val != "" ) return val;
	if ( GUI_desc_get_attr ( desc, "attached_text", val ) == E_OK )
		if ( val != "" ) return val;
	if ( GUI_desc_get_attr ( desc, "html_name", val ) == E_OK )
		if ( val != "" ) return val;
	if ( GUI_desc_get_attr ( desc, "delphi_name", val ) == E_OK )
		if ( val != "" ) return val;
	if ( GUI_desc_get_attr ( desc, "pb_name", val ) == E_OK )
		if ( val != "" ) return val;
	if ( GUI_desc_get_attr ( desc, "vpms_name", val ) == E_OK )
		if ( val != "" ) return val;
	if ( GUI_desc_get_attr ( desc, "parent", val ) == E_OK )
		if ( val != "" ) return val;
	return "";
}

public function point2win ( out buf, out win, out desc, out name )
{
	auto rc, dummy;
	rc = GUI_point_to( WIN, "", 1 );
	if ( rc == 0 )
	{
		rc = GUI_map_get_desc( WIN, "", desc, dummy );
		name = win_get_name( desc );
		rc = GUI_delete( "", WIN, "" );
		rc = GUI_map_get_logical_name( desc, "", win, buf );
	}
	return rc;
}

public function point2obj ( in buf, in win, out obj, out desc, out name )
{
	auto rc, file;
	auto obj_name, obj_desc;
		
	rc = GUI_point_to( WIN, OBJ, 0 );
	if ( rc == 0 )
	{
		rc = GUI_map_get_desc( WIN, OBJ, desc, file );
		# patch for Siemens light-weight objects
		# has_parent, parent_name and parent_desc are kept outside this function
		rc = parse_desc ( desc, obj_name, obj_desc, has_parent, parent_name, parent_desc );
		if ( has_parent )
		{
			name = obj_name;
			desc = obj_desc;
		}
		else
		# end patch
			name = obj_get_name( desc );
		delete_all_obj( "", WIN );
		rc = GUI_buf_get_logical_name( buf, desc, win, obj );
	}
	return rc;
}

static function parse_desc ( in desc, out oname, out odesc, out has_parent, out pname, out pdesc )
{
	auto oattrs[], pattrs[];
	auto rc, i;
	
	rc = GUI_list_desc_attrs( desc, oattrs );
	if ( rc != E_OK )
		return rc;

	oname = "";
	has_parent = FALSE;
	for ( i in oattrs )
	{
		if ( i == "parent" )
		{
			if ( is_embeded_parent( oattrs[i] ) )
			{
				has_parent = TRUE;
				oname = strip_both( get_label( oattrs[i] ), "\"" );
				GUI_list_desc_attrs( oattrs[i], pattrs );
				pname = oname & PARENT_NAME_SUFFIX;
				pdesc = get_desc_from_attrs( pattrs );
				oattrs[i] = "\"" & pname & "\"";
			}
		}
	}
	if ( oname == "" )
		oname = obj_get_name( odesc );
	odesc = get_desc_from_attrs( oattrs );
	return E_OK;
}

static function get_label ( in obj_desc )
{
	auto rc, i;
	auto obj_attrs[];
	
	rc = GUI_list_desc_attrs( obj_desc, obj_attrs );
	if ( rc != E_OK )
		return rc;
	for ( i in obj_attrs )
	{
		if ( i == "label" )
			return obj_attrs[i];
	}
	return "";
}

static function get_desc_from_attrs ( inout attrs[] )
{
	auto i;
	auto desc = "";
	
	for ( i in attrs )
	{
		if ( desc == "" )
			desc = "{";
		else
			desc = desc & ",";
		desc = sprintf( "%s %s: \"%s\"", desc, i, strip_both( attrs[i], "\"" ) );
	}
	desc = desc & " }";
	return desc;
}

static function is_embeded_parent ( in desc )
{
	return match( desc, "{.*}" );
}

static function delete_all_obj ( in file, in win )
{
	auto i, rc;
	auto obj_num, obj_arr[];
	
	rc = GUI_list_win_objects ( file, win, obj_arr, obj_num );
	for ( i=0; rc == E_OK && i < obj_num; i++ )
	{
		GUI_delete( file, win, obj_arr[i+1] );
	}
}

#------------------------------------------------------------------------------------
# pick-Funktionen
#------------------------------------------------------------------------------------

static function pick_windows()
{
	auto rc, win, buf, desc, name;
	while ( 1 )
	{
		rc = create_custom_dialog( "select_callback", 
			"WINDOW whlen", 
			"OK", 
			"Name:", 
			"auf der AUT zeigen,aus der GUI-Map" );
		switch ( rc )
		{
		case "?":	# OK pressed, nothing selected
		case 1:	rc = point2win( buf, win, desc, name ); break;	# auf AUT zeigen
		case 2:	rc = select_win( buf, win, desc, name ); break;	# aus GUI whlen
		case 3:	win = selName; rc = GUI_map_get_desc( win, "", desc, buf ); break;
		default:	return;	# Cancel
		}
		switch ( rc )
		{
		case E_OK:
		case E_ITEM_NOT_FOUND:
			rc = process_win( buf, win, desc, name );
			if ( rc != E_OK ) continue;
			break;
		case 3:		# rechte Maustaste
			return;
		case "":
			continue;
		default:
			rc = pause_test( "Unbekanntes Fehler" &
				"\nRC=" & rc & " desc=" & desc &
				"\nWollen Sie fortfahren?"
				, "&Ja", "&Nein" );
			if ( rc != 0 ) return;
			continue;
		}
		while ( 1 )
		{
			rc = create_custom_dialog( "select_callback2", 
				"Aktion whlen", 
				"OK", 
				"Dummy step:", 
				"OBJEKT erfassen,WINDOW erfassen" );
			if ( rc == "" )	# Cancel
			{
				if ( flag_LIBhdr > 0 ) generate_lib_trl();
				return;
			}
			if ( rc == "?" || rc == 1 )	# Object
			{
				pick_objects( buf, win, name );
				continue;
			}
			if ( rc == 2 )	# Window
			{
				if ( flag_LIBhdr > 0 ) generate_lib_trl();
				break;
			}
			generate_frm_dummy( rc );
			generate_lib_dummy( rc );
		}
	}
}

#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------

static function pick_objects( in buf, in win, in name )
{
	auto rc, obj, desc, ask = FALSE;
	while ( 1 )
	{
		switch ( ask )
		{
		case -1:
			rc = create_custom_dialog( "select_callback", 
				"OBJEKT whlen", 
				"OK", 
				"Name:", 
				"auf der AUT zeigen,aus der GUI-Map" );
			switch ( rc )
			{
			case "?":
			case 1:	rc = point2obj( buf, win, obj, desc, name );	break;
			case 2:	rc = select_obj( buf, win, obj, desc, name );	break;
			case 3:	obj = selName; rc = GUI_map_get_desc( win, obj, desc, buf ); break;
#			case "?":	continue;
			default:	return;
			}
			break;
		case -2:
			rc = create_custom_dialog( "select_callback", 
				"WINDOW whlen", 
				"OK", 
				"Name:", 
				"auf der AUT zeigen,aus der GUI-Map" );
			switch ( rc )
			{
			case "?":
			case 1:	rc = point2win( buf, win, desc, name ); break;
			case 2:	rc = select_win( buf, win, desc, name ); break;
			case 3:	win = selName; rc = GUI_map_get_desc( win, "", desc, buf ); break;
#			case "?":	continue;
			default:	return;
			}
			break;
		default:
			rc = point2obj( buf, win, obj, desc, name );
		}
		ask = FALSE;
		switch ( rc )
		{
		case 3:		# rechte Maustaste
			return;
		case E_OK:
		case E_NOT_FOUND:
			rc = process_obj( buf, win, obj, desc, name );
			switch ( rc )
			{
			case E_OK:
				break;
			case -1:
			case -2:
				ask = rc;
				continue;
			default:
				break;
			}
			break;
		default:
			rc = pause_test( "Unbekanntes Fehler beim GUI aufzeichnen." &
				"\nRC=" & rc & " desc=" & desc &
				"\nWollen Sie fortfahren?"
				, "&Ja", "&Nein" );
			if ( rc != 0 ) return;
			continue;
		}
	}
}

#------------------------------------------------------------------------------------
# process-Funktionen
#------------------------------------------------------------------------------------

static function process_win ( inout buf, inout win, inout desc, inout name )
{
	auto rc;
	while (1)
	{
		rc = create_custom_dialog( "win_callback", 
			(win=="" ? "<unbekannt> [" & name & "]" : win) , 
			"OK", 
			"Window:,Step:,Function:", 
			"anderes WINDOW" );
		switch ( rc ) 
		{
		case "":	# Cancel
		case -1:	# anderes Window
			return rc;
		case "?":	# dieser Name (ohne den neuen Namen)
			if ( win=="" && name == "" )
				continue;
			if ( win=="" && name != "" )
				win = name;
			buf = ((buf=="") ? GUIfile : buf);
			break;
		default:	# dieser name (neuer Name definiert)
			buf = ((buf=="") ? GUIfile : buf);
			win = rc;
			break;
		}
		break;
	}
	generate_gui_win( buf, win, desc );
	generate_frm_hdr( win );
	generate_lib_hdr( win );
	generate_drv_hdr( win );
	return E_OK;
}	

static function process_obj ( inout buf, inout win, inout obj, inout desc, inout name )
{
	auto rc;
	while (1)
	{
		if ( obj == "" )
		{
			flag_noObj = FALSE;
			rc = create_custom_dialog( "obj_callback", 
				(obj=="" ? "<unbekannt> [" & name & "]" : obj),
				"OK", 
				"Objekt:", 
				"anderes OBJEKT,kein object" );
			switch ( rc ) 
			{
			case "":	return "";
			case "?":
				if ( name == "" )
					continue;
				else
					obj = name;
				break;
			case -1:	return -1;
			default:
				obj = rc;
				break;
			}
		}
		if ( win == "" )
		{
			rc = create_custom_dialog( "win_callback", 
				(win=="" ? "<unbekannt> [" & name & "]" : win) , 
				"OK", 
				"Window:,Step:,Function:", 
				"anderes WINDOW" );
			switch ( rc ) 
			{
			case "":	return "";
			case "?":
				if ( name == "" )
					continue;
				else
					obj = name;
				break;
			case -1:	return -2;
			default:
				buf = ((buf=="") ? GUIfile : buf);
				win = rc;
				break;
			}
		}
		break;
	}
	generate_gui_obj( buf, win, obj, desc );
	generate_frm_det( buf, win, obj, desc );
	generate_lib_det( buf, win, obj, desc );
	return E_OK;
}

#------------------------------------------------------------------------------------
# generate_gui-Funktionen
#------------------------------------------------------------------------------------

static function generate_gui_win ( in buf, in win, in desc )
{
	if ( !doGUI )
		return;
	GUI_add( buf,  win, "", desc );
}

static function generate_gui_obj ( in buf, in win, in obj, in desc )
{
	auto pname, rc;
	
	if ( !doGUI || flag_noObj)
		return;

	# patch for Siemens light-weight objects
	if ( has_parent )
	{
		# object name be overriden so we allocate
		# the parent name again
		pname = obj & PARENT_NAME_SUFFIX;
		rc = GUI_add( buf, win, pname, parent_desc );
	}
	# end patch
	rc = GUI_add( buf, win, obj, desc );
}

#------------------------------------------------------------------------------------
# generate_frm-Funktionen
#------------------------------------------------------------------------------------

static function generate_frm_titles ( )
{
	static fmt = "\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\n";
	if ( !doFRM )
		return;
	a( FRMfile, sprintf( fmt, "IDX", "Name", "Inhalt", "test" ) );
	a( FRMfile, sprintf( fmt, "x", "Kommentar", "", "???" ) );
	a( FRMfile, sprintf( fmt, "x", "Testvorgang", "", "???" ) );
}

static function generate_frm_hdr ( in name )
{
	static fmt = "\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\n";
	if ( !doFRM )
		return;
	a( FRMfile, sprintf( fmt, "x", (stepName!="" ? stepName : name), "", "" ) );
}

static function generate_frm_det ( in buf, in win, in obj, in desc )
{
	static fmt = "\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\n";
	auto rc, class, msw_class, text, num;
	if ( !doFRM )
		return;
	rc = set_window( win, 1 );
	if ( rc != E_OK ) return;
	
	if ( flag_noObj )
		rc = GUI_desc_get_attr ( desc, "class", class );
	else
		rc = GUI_buf_get_desc_attr( buf, win, obj, "class", class );
	if ( rc != E_OK ) return rc;
	switch ( class )
	{
	case "edit":
		rc = edit_get_text( obj, text );
		if ( rc != E_OK ) text = "???";
		break;
	case "list":
		rc = list_get_selected( obj, text, num ); 
		if ( rc != E_OK ) text = "???";
		if ( text == "" ) text = num;
		if ( text == -1 ) text = "";
		break;
	case "push_button":
		text = "";
		break;
	case "radio_button":
	case "check_button":
		rc = button_get_state( obj, text );
		if ( rc != E_OK ) text = "???";
		switch ( text )
		{
		case ON:	text = "ON"; break;
		case OFF:	text = "OFF"; break;
		default:	text = "???"; break;
		}
		break;
	case "object":
		if ( flag_noObj )
			rc = GUI_desc_get_attr ( desc, "MSW_class", msw_class );
		else
			rc = GUI_buf_get_desc_attr( buf, win, obj, "MSW_class", msw_class );
		if ( rc == E_OK ) 
			class = msw_class;
		text = "";
		break;
	default:
		rc = obj_get_text( obj, text );
		if ( rc != E_OK ) text = "???";
	}
	if ( flag_noObj )
		a( FRMfile, sprintf( fmt, "", "???", class, obj ) );
	else
		a( FRMfile, sprintf( fmt, "", obj, class, text ) );
}

static function generate_frm_dummy ( in name )
{
	static fmt = "\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\n";
	if ( !doFRM )
		return;
	a( FRMfile, sprintf( fmt, "", name, "", "" ) );
}

#------------------------------------------------------------------------------------
# generate_lib-Funktionen
#------------------------------------------------------------------------------------

static function generate_lib_hdr ( in name )
{
	if ( !doLIB )
		return;
	a( LIBfile, sprintf( "\npublic function FRM_%s ( in table, in test, in idx, in mode )\n", (funcName!="" ? funcName : name ) ) );
	a( LIBfile, sprintf( "{\n\tauto rc;\n" ) );
	a( LIBfile, sprintf( "\trc = FRM_init_block( table, test, idx, mode );\n" ) );
	a( LIBfile, sprintf( "\tif ( rc != E_OK )\n" ) );
	a( LIBfile, sprintf( "\t\treturn rc;\n" ) );
	a( LIBfile, sprintf( "\trc+=set_window( \"%s\", 5 );\n", name ) );
	flag_LIBhdr++;
}

static function generate_lib_det ( in buf, in win, in obj, in desc )
{
	auto rc, class, msw_class, num, choices, cmd;
	if ( !doLIB )
		return;
	if ( flag_noObj )
		rc = GUI_desc_get_attr ( desc, "class", class );
	else
		rc = GUI_buf_get_desc_attr( buf, win, obj, "class", class );
	if ( rc != E_OK ) return rc;
	switch ( class )
	{
	case "edit":
		choices = "edit_set,obj_type,IRONMAN_list";
		break;
	case "list":
		choices = "list_select_item,list_select_multi_items,list_activate_item";
		break;
	case "push_button":
		choices = "button_press";
		break;
	case "radio_button":
	case "check_button":
		choices = "button_set";
		break;
	case "static_text":
		choices = "static_get";
		break;
	case "window":
		choices = "set_window";
		break;
	case "object":
		if ( flag_noObj )
			rc = GUI_desc_get_attr ( desc, "MSW_class", msw_class );
		else
			rc = GUI_buf_get_desc_attr( buf, win, obj, "MSW_class", msw_class );
		if ( rc != E_OK ) 
		{
			choices = "win_type,obj_type,button_press,IRONMAN_check_button,IRONMAN_date_field";
			break;
		}
		if ( match( msw_class, "html" ) )
			switch ( msw_class )
			{
				case "html_text_link":
					choices="web_link_click";
					break;
				case "html_rect":
					choices="web_image_click,web_label_click,web_obj_get_text";
					break;
				case "html_table":
					choices="web_obj_get_text";
					break;
				default:
					choices="web_image_click,web_label_click,web_obj_get_text";
					break;
			}
		else
			choices = "win_type,obj_type,button_press,IRONMAN_check_button,IRONMAN_date_field";
		break;
	default:
		choices = "win_type,obj_type,button_press";
	}
	rc = create_list_dialog( "Operation",
		"Bitte whlen Sie die gewnschte Operation:",
		choices );
	if ( rc == "" ) return;
	cmd = rc;
	switch ( cmd )
	{
	case "set_window":
		a( LIBfile, sprintf( "\trc+=%s( \"%s\" );\n", cmd, obj ) );
		break;
	case "obj_type":
	case "win_type":
		a( LIBfile, sprintf( "\trc+=FRM_%s( table, test, \"%s\", \"%s\" );\n", cmd, obj, "<kTab>" ) );
		break;
	case "IRONMAN_list":
		a( LIBfile, sprintf( "\trc+=AUT_FRM_list_select_item( table, test, \"%s\", \"%s\" );\n", obj, "ComboBox" ) );
		break;
	case "IRONMAN_check_button":
		a( LIBfile, sprintf( "\trc+=AUT_FRM_check_button_press( table, test, \"%s\" );\n", obj ) );
		break;
	case "IRONMAN_date_field":
		a( LIBfile, sprintf( "\trc+=AUT_FRM_date_obj_type( table, test, \"%s\", \"<kTab>\" );\n", obj ) );
		break;
	default:
		if ( flag_noObj )
			a( LIBfile, sprintf( "\trc+=FRM_%s( table, test );\n", cmd ) );
		else
			a( LIBfile, sprintf( "\trc+=FRM_%s( table, test, \"%s\" );\n", cmd, obj ) );
		break;
	}
}

static function generate_lib_trl ( in name )
{
	if ( !doLIB )
		return;
	a( LIBfile, sprintf( "\treturn rc;\n" ) );
	a( LIBfile, sprintf( "}\n" ) );
	flag_LIBhdr--;
}

static function generate_lib_dummy ( in name )
{
	if ( !doLIB )
		return;
	a( LIBfile, sprintf( "\trc+=FRM_skip( table ); # %s\n", name ) );
}

#------------------------------------------------------------------------------------
# generate_drv-Funktionen
#------------------------------------------------------------------------------------

static function generate_drv_hdr ( in win )
{
	if ( !doDRV )
		return;
	a( DRVfile, sprintf( "\tcase \"%s\":\n", tolower( (stepName!="" ? stepName : win) ) ) );	
	a( DRVfile, sprintf( "\t\trc = FRM_%s( table, test, step, mode ); break;\n", (funcName!="" ? funcName : win) ) );
}

#------------------------------------------------------------------------------------
# Hauptprogramm
#------------------------------------------------------------------------------------

hWnd = minimizeWR();
while ( 1 )
{
	rc = create_custom_dialog( "wizard_mode_callback", 
		"Bitte whlen Sie was generiert werden soll", 
		"OK", 
		"GUImap (.gui):,FRMfile (.csv):,LIBscript (.tsl):,DRVscript (.tsl):,Verzeichnis:", 
		"generieren,generieren,generieren,generieren,Dateien lschen" );
	if ( rc == "?" )
		continue;
	if ( rc != 0 ) 
		break;
	pick_windows();
}
restoreWR( hWnd );

