/* * 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 */
/* * SrcAssign - assign a value to a variable */ vi_rc SrcAssign( const char *data, vlist *vl ) { int i, j, k, l; long val; bool rxflag = false; bool envflag = false; bool setflag = false; bool expflag = false; bool timeflag = false; bool lnumflag = false; char tmp[MAX_SRC_LINE], tmp1[MAX_SRC_LINE], name[MAX_SRC_LINE]; const char *v1; char *t; vars *v; jmp_buf jmpaddr; time_t tod; bool check_end; char tmpstr[MAX_STR]; /* * get assign syntax : * ASSIGN %v = /v1/(r)($)(@)(x)(l)(t) * possible v1: * strlen %a * strchr %a ch * substr %a n1 n2 */ data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } if( !VarName( name, tmp, vl ) ) { return( ERR_SRC_INVALID_ASSIGN ); } data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } if( stricmp( tmp, "=" ) != 0 ) { return( ERR_SRC_INVALID_ASSIGN ); } data = SkipLeadingSpaces( data ); if( data[0] == '/' || data[0] == '"' ) { check_end = false; if( data[0] == '"' ) { data = GetNextWord( data, tmp, SingleQuote ); if( data[0] == '"' ) { check_end = true; } } else { data = GetNextWord( data, tmp, SingleSlash ); if( data[0] == '/' ) { check_end = true; } } if( check_end ) { for( ++data; data[0] != '\0'; data++ ) { switch( data[0] ) { case 't': timeflag = true; break; case 'r': rxflag = true; break; case '$': envflag = true; break; case '@': setflag = true; break; case 'x': expflag = true; break; case 'l': lnumflag = true; break; } } } Expand( tmp1, tmp, vl ); } else { data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } j = Tokenize( StrTokens, tmp, false ); if( j != TOK_INVALID ) { data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } if( !VarName( tmp1, tmp, vl ) ) { return( ERR_SRC_INVALID_ASSIGN ); } v = VarFind( tmp1, vl ); switch( j ) { case STR_T_STRLEN: if( v != NULL ) { sprintf( tmp1, "%d", v->len ); } else { strcpy( tmp1, "0" ); } break; case STR_T_SUBSTR: data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } Expand( tmp1, tmp, vl ); i = atoi( tmp1 ) - 1; data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } Expand( tmp1, tmp, vl ); j = atoi( tmp1 ) - 1; if( v == NULL ) { tmp1[0] = '\0'; break; } if( j >= v->len || i < 0 ) { tmp1[0] = '\0'; } else { l = 0; for( k = i; k <= j; k++ ) { tmp1[l++] = v->value[k]; } tmp1[l] = '\0'; } break; case STR_T_STRCHR: data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } Expand( tmp1, tmp, vl ); if( v == NULL ) { j = -1; } else { t = strchr( v->value, tmp1[0] ); if( t != NULL ) { j = t - v->value; } else { j = -1; } j++; } sprintf( tmp1, "%d", j ); break; } } else { Expand( tmp1, tmp, vl ); } } /* * regular expression subs. */ if( rxflag && CurrentRegularExpression != NULL ) { RegSub( CurrentRegularExpression, tmp1, tmp, CurrentPos.line ); strcpy( tmp1, tmp ); } /* * special processing */ if( envflag ) { v1 = getenv( tmp1 ); if( v1 == NULL ) { v1 = ""; } } else if( setflag ) { v1 = GetASetVal( tmp1, tmpstr ); } else if( timeflag ) { tod = time( NULL ); strftime( tmp, sizeof( tmp ), tmp1, localtime( &tod ) ); v1 = tmp; } else if( expflag || lnumflag ) { i = setjmp( jmpaddr ); if( i != 0 ) { return( (vi_rc)i ); } StartExprParse( tmp1, jmpaddr ); val = GetConstExpr(); if( lnumflag ) { fcb *cfcb; line *cline; vi_rc rc; rc = CGimmeLinePtr( val, &cfcb, &cline ); v1 = cline->data; if( rc != ERR_NO_ERR ) { v1 = ""; } } else { v1 = ltoa( val, tmp1, EditVars.Radix ); } } else { v1 = tmp1; } VarAddStr( name, v1, vl ); return( ERR_NO_ERR ); } /* SrcAssign */
/* * nextToken - fetch the next real token from the buffer */ static token nextToken( void ) { int j; char *endptr; currToken = _nextToken(); if( currToken == T_UNKNOWN ) { currToken = T_CONSTANT; if( isdigit( tokenBuff[0] ) ) { constantVal = strtol( tokenBuff, &endptr, 10 ); if( (endptr - tokenBuff) != tokenBuffCnt ) { constantVal = strtol( tokenBuff, &endptr, 16 ); if( (endptr - tokenBuff) != tokenBuffCnt ) { abortExpr( ERR_INVALID_VALUE ); } } } else { if( tokenBuff[0] == '.' ) { strcpy( tokenBuff, GetASetVal( &tokenBuff[1] ) ); constantVal = strtol( tokenBuff, NULL, 0 ); j = tokenBuffCnt - 1; while( j >= 0 ) { if( !isdigit( tokenBuff[j] ) ) { currToken = T_STRING; break; } j--; } } else if( !strcmp( tokenBuff, "config" ) ) { constantVal = EditFlags.Color * 100 + EditFlags.BlackAndWhite * 10 + EditFlags.Monocolor; } else if( !strcmp( tokenBuff, "rdonly" ) ) { constantVal = CFileReadOnly(); } else if( !strcmp( tokenBuff, "lastrc" ) ) { constantVal = (long)LastRC; } else if( !strcmp( tokenBuff, "pagelen" ) ) { constantVal = EditVars.WindMaxHeight; } else if( !strcmp( tokenBuff, "endcolumn" ) ) { constantVal = EditVars.WindMaxWidth; } else if( !strcmp( tokenBuff, "numundos" ) ) { if( UndoStack == NULL ) { constantVal = 0; } else { constantVal = UndoStack->current + 1; } } else if( !strcmp( tokenBuff, "numredos" ) ) { if( UndoUndoStack == NULL ) { constantVal = 0; } else { constantVal = UndoUndoStack->current + 1; } } else if( !strcmp( tokenBuff, "hassel" ) ) { constantVal = SelRgn.selected; } else if( !strcmp( tokenBuff, "hasfile" ) ) { constantVal = (CurrentFile != NULL); } else if( !strncmp( tokenBuff, "emptybuf", 8 ) ) { j = tokenBuff[8]; constantVal = IsEmptySavebuf( j ); } else if( (j = Tokenize( colorTokens, tokenBuff, true )) != TOK_INVALID ) { constantVal = j; #ifdef __WIN__ } else if( (j = Tokenize( ddeTokens, tokenBuff, true )) != TOK_INVALID ) { constantVal = ddeNums[j]; #endif } else { ReadErrorTokens(); j = Tokenize( ErrorTokens, tokenBuff, true ); if( j != TOK_INVALID ) { constantVal = ErrorValues[j]; } else { currToken = T_STRING; } } } } return( currToken ); } /* nextToken */
/* * 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 */