/* * GenerateConfiguration - write out a config file */ vi_rc GenerateConfiguration( const char *fname, bool is_cmdline ) { FILE *fp; int i; char token[128]; const char *str; char *buff; int num; rgb c; const char *res; char tmpstr[MAX_STR]; if( fname == NULL ) { fname = CFG_NAME; } fp = fopen( fname, "w" ); if( fp == NULL ) { return( ERR_FILE_OPEN ); } isCmdLine = is_cmdline; buff = MemAllocUnsafe( VBUF_SIZE ); if( buff != NULL ) { setvbuf( fp, buff, _IOFBF, VBUF_SIZE ); } MyFprintf( fp, "#\n# %s configuration file\n# %s\n#\n", #if defined( __WIN__ ) banner1w1( "Text Editor for Windows" ), banner1w2( _VI_VERSION_ ) ); #else banner1w1( "Vi Text Editor" ), banner1w2( _VI_VERSION_ ) ); #endif if( is_cmdline ) { GetDateTimeString( token ); MyFprintf( fp, "# File generated on %s\n#\n", token ); } writeTitle( fp, "Hook script assignments" ); doHookAssign( fp, SRC_HOOK_WRITE ); doHookAssign( fp, SRC_HOOK_READ ); doHookAssign( fp, SRC_HOOK_BUFFIN ); doHookAssign( fp, SRC_HOOK_BUFFOUT ); doHookAssign( fp, SRC_HOOK_COMMAND ); doHookAssign( fp, SRC_HOOK_MODIFIED ); doHookAssign( fp, SRC_HOOK_MENU ); doHookAssign( fp, SRC_HOOK_MOUSE_LINESEL ); doHookAssign( fp, SRC_HOOK_MOUSE_CHARSEL ); writeTitle( fp, "General Settings" ); num = GetNumberOfTokens( SetVarTokens ); for( i = 0; i < num; i++ ) { if( i == SETVAR_T_TILECOLOR || i == SETVAR_T_FIGNORE || i == SETVAR_T_FILENAME ) { continue; } res = GetASetVal( GetTokenStringCVT( SetVarTokens, i, token, true ), tmpstr ); switch( i ) { case SETVAR_T_STATUSSTRING: case SETVAR_T_FILEENDSTRING: case SETVAR_T_HISTORYFILE: case SETVAR_T_TMPDIR: /* strings with possible spaces */ MyFprintf( fp, "set %s = \"%s\"\n", token, res ); break; case SETVAR_T_GADGETSTRING: if( !IsGadgetStringChanged( res ) ) break; // fall through default: MyFprintf( fp, "set %s = %s\n", token, res ); break; } } writeTitle( fp, "Boolean Settings" ); num = GetNumberOfTokens( SetFlagTokens ); for( i = 0; i < num; i++ ) { str = GetASetVal( GetTokenStringCVT( SetFlagTokens, i, token, true ), tmpstr ); MyFprintf( fp, "set %s%s\n", (*str == '0') ? "no" : "", token ); } writeTitle( fp, "Match pairs" ); for( i = INITIAL_MATCH_COUNT; i < MatchCount; i += 2 ) { MyFprintf( fp, "match /" ); outputMatchData( fp, MatchData[i] ); outputMatchData( fp, MatchData[i + 1] ); MyFprintf( fp, "\n" ); } writeTitle( fp, "Command Mode Mappings" ); doMaps( fp, KeyMaps, "" ); writeTitle( fp, "Insert Mode Mappings" ); doMaps( fp, InputKeyMaps, "!" ); writeTitle( fp, "Color Settings" ); for( i = 0; i < GetNumColors(); i++ ) { if( GetColorSetting( i, &c ) ) { MyFprintf( fp, "setcolor %d %d %d %d\n", i, c.red, c.green, c.blue ); } } #ifdef __WIN__ writeTitle( fp, "Font Settings" ); BarfFontData( fp ); #endif writeTitle( fp, "Window Configuration" ); doWindow( fp, PCL_T_COMMANDWINDOW, &cmdlinew_info, false ); doWindow( fp, PCL_T_STATUSWINDOW, &statusw_info, false ); doWindow( fp, PCL_T_COUNTWINDOW, &repcntw_info, false ); doWindow( fp, PCL_T_EDITWINDOW, &editw_info, false ); doWindow( fp, PCL_T_FILECWINDOW, &filecw_info, false ); doWindow( fp, PCL_T_DIRWINDOW, &dirw_info, false ); doWindow( fp, PCL_T_FILEWINDOW, &filelistw_info, false ); doWindow( fp, PCL_T_MESSAGEWINDOW, &messagew_info, false ); #ifndef __WIN__ doWindow( fp, PCL_T_SETWINDOW, &setw_info, false ); doWindow( fp, PCL_T_LINENUMBERWINDOW, &linenumw_info, false ); doWindow( fp, PCL_T_EXTRAINFOWINDOW, &extraw_info, false ); doWindow( fp, PCL_T_SETVALWINDOW, &setvalw_info, false ); doWindow( fp, PCL_T_MENUWINDOW, &menuw_info, false ); doWindow( fp, PCL_T_MENUBARWINDOW, &menubarw_info, true ); doWindow( fp, PCL_T_ACTIVEMENUWINDOW, &activemenu_info, true ); doWindow( fp, PCL_T_GREYEDMENUWINDOW, &greyedmenu_info, true ); doWindow( fp, PCL_T_ACTIVEGREYEDMENUWINDOW, &activegreyedmenu_info, true ); #endif writeTitle( fp, "Menu Configuration" ); BarfMenuData( fp ); #ifdef __WIN__ writeTitle( fp, "ToolBar Configuration" ); BarfToolBarData( fp ); #endif writeTitle( fp, "File Type Source" ); FTSBarfData( fp ); fclose( fp ); if( is_cmdline ) { Message1( "Configuration file \"%s\" generated", fname ); } MemFree( buff ); return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } /* GenerateConfiguration */
/* * GenerateConfiguration - write out a config file */ vi_rc GenerateConfiguration( char *fname, bool is_cmdline ) { FILE *f; int i; char token[128]; char *str; char boolstr[3]; char *buff; int num; rgb c; char *fmt; char *res; if( fname == NULL ) { fname = CFG_NAME; } f = fopen( fname, "w" ); if( f == NULL ) { return( ERR_FILE_OPEN ); } isCmdLine = is_cmdline; buff = MemAllocUnsafe( VBUF_SIZE ); if( buff != NULL ) { setvbuf( f, buff, _IOFBF, VBUF_SIZE ); } MyFprintf( f, "#\n# WATCOM %s %s configuration file\n# %s\n#\n", TITLE, VERSIONT, AUTHOR ); if( is_cmdline ) { GetDateTimeString( token ); MyFprintf( f, "# File generated on %s\n#\n", token ); } writeTitle( f, "Hook script assignments" ); doHookAssign( f, SRC_HOOK_WRITE ); doHookAssign( f, SRC_HOOK_READ ); doHookAssign( f, SRC_HOOK_BUFFIN ); doHookAssign( f, SRC_HOOK_BUFFOUT ); doHookAssign( f, SRC_HOOK_COMMAND ); doHookAssign( f, SRC_HOOK_MODIFIED ); doHookAssign( f, SRC_HOOK_MENU ); doHookAssign( f, SRC_HOOK_MOUSE_LINESEL ); doHookAssign( f, SRC_HOOK_MOUSE_CHARSEL ); writeTitle( f, "General Settings" ); num = GetNumberOfTokens( SetTokens1 ); for( i = 0; i < num; i++ ) { if( i == SET1_T_TILECOLOR || i == SET1_T_FIGNORE || i == SET1_T_FILENAME ) { continue; } strcpy( token, GetTokenString( SetTokens1, i ) ); strlwr( token ); res = GetASetVal( token ); if( i == SET1_T_STATUSSTRING || i == SET1_T_FILEENDSTRING || i == SET1_T_HISTORYFILE || i == SET1_T_TMPDIR ) { /* strings with possible spaces */ fmt = "set %s = \"%s\"\n"; } else { fmt = "set %s = %s\n"; } MyFprintf( f, fmt, token, res ); } writeTitle( f, "Boolean Settings" ); num = GetNumberOfTokens( SetTokens2 ); for( i = 0; i < num; i++ ) { strcpy( token, GetTokenString( SetTokens2, i ) ); strlwr( token ); str = GetASetVal( token ); boolstr[0] = 0; if( str[0] == '0' ) { boolstr[0] = 'n'; boolstr[1] = 'o'; boolstr[2] = 0; } MyFprintf( f, "set %s%s\n", boolstr, token ); } writeTitle( f, "Match pairs" ); for( i = INITIAL_MATCH_COUNT; i < MatchCount; i += 2 ) { MyFprintf( f, "match /" ); outputMatchData( f, MatchData[i] ); outputMatchData( f, MatchData[i + 1] ); MyFprintf( f, "\n" ); } writeTitle( f, "Command Mode Mappings" ); doMaps( f, KeyMaps, "" ); writeTitle( f, "Insert Mode Mappings" ); doMaps( f, InputKeyMaps, "!" ); writeTitle( f, "Color Settings" ); for( i = 0; i < GetNumColors(); i++ ) { if( GetColorSetting( i, &c ) ) { MyFprintf( f, "setcolor %d %d %d %d\n", i, c.red, c.green, c.blue ); } } #ifdef __WIN__ writeTitle( f, "Font Settings" ); BarfFontData( f ); #endif writeTitle( f, "Window Configuration" ); doWindow( f, PCL_T_COMMANDWINDOW, &cmdlinew_info, FALSE ); doWindow( f, PCL_T_STATUSWINDOW, &statusw_info, FALSE ); doWindow( f, PCL_T_COUNTWINDOW, &repcntw_info, FALSE ); doWindow( f, PCL_T_EDITWINDOW, &editw_info, FALSE ); doWindow( f, PCL_T_FILECWINDOW, &filecw_info, FALSE ); doWindow( f, PCL_T_DIRWINDOW, &dirw_info, FALSE ); doWindow( f, PCL_T_FILEWINDOW, &filelistw_info, FALSE ); doWindow( f, PCL_T_MESSAGEWINDOW, &messagew_info, FALSE ); #ifndef __WIN__ doWindow( f, PCL_T_SETWINDOW, &setw_info, FALSE ); doWindow( f, PCL_T_LINENUMBERWINDOW, &linenumw_info, FALSE ); doWindow( f, PCL_T_EXTRAINFOWINDOW, &extraw_info, FALSE ); doWindow( f, PCL_T_SETVALWINDOW, &setvalw_info, FALSE ); doWindow( f, PCL_T_MENUWINDOW, &menuw_info, FALSE ); doWindow( f, PCL_T_MENUBARWINDOW, &menubarw_info, TRUE ); doWindow( f, PCL_T_ACTIVEMENUWINDOW, &activemenu_info, TRUE ); doWindow( f, PCL_T_GREYEDMENUWINDOW, &greyedmenu_info, TRUE ); doWindow( f, PCL_T_ACTIVEGREYEDMENUWINDOW, &activegreyedmenu_info, TRUE ); #endif writeTitle( f, "Menu Configuration" ); BarfMenuData( f ); #ifdef __WIN__ writeTitle( f, "ToolBar Configuration" ); BarfToolBarData( f ); #endif writeTitle( f, "File Type Source" ); FTSBarfData( f ); fclose( f ); if( is_cmdline ) { Message1( "Configuration file \"%s\" generated", fname ); } MemFree( buff ); return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } /* GenerateConfiguration */