Example #1
0
/*
 * doHookAssign - do an assignment for a hook variable
 */
static void doHookAssign( FILE *fp, hooktype num )
{
    vars        *v;

    v = GetHookVar( num );
    if( v == NULL ) {
        return;
    }
    MyFprintf( fp, "assign %%(%s) = %s\n", v->name, v->value );
    MyFprintf( fp, "load %s\n", v->value );

} /* doHookAssign */
Example #2
0
/*
 * writeHistory - write out history to a file
 */
static void writeHistory( FILE *f, history_data *hist )
{
    int i, j;

    MyFprintf( f, "%d\n", getHistCount( hist ) );
    j = hist->curr;
    for( i = 0; i < hist->max; i++ ) {
        if( hist->data[j % hist->max] != NULL ) {
            MyFprintf( f, "%s\n", hist->data[j % hist->max] );
            DeleteString( &hist->data[j % hist->max] );
        }
        j++;
    }

} /* writeHistory */
Example #3
0
/*
 * DoAutoSave - try to do autosave of current file
 */
void DoAutoSave( void )
{
    char        path[FILENAME_MAX];
    char        path2[FILENAME_MAX];
    char        tmp[FILENAME_MAX];
    bool        quiet;
    FILE        *f;
    vi_rc       rc;
    status_type lastst;

    if( EditVars.AutoSaveInterval == 0 ) {
        return;
    }
    if( clock() < NextAutoSave ) {
        return;
    }
    if( CurrentFile == NULL ) {
        return;
    }
    if( CurrentFile->is_stdio || CurrentFile->viewonly ||
                !CurrentFile->need_autosave ) {
        SetNextAutoSaveTime();
        return;
    }

    MakeTmpPath( path, "" );
    if( !CurrentFile->been_autosaved ) {
        getTmpName( path, CurrentFile->as_name );
    }
    strcat( path, CurrentFile->as_name );

    quiet = EditFlags.Quiet;
    EditFlags.Quiet = TRUE;
    lastst = UpdateCurrentStatus( CSTATUS_AUTOSAVE );
    rc = SaveFile( path, -1, -1, TRUE );
    EditFlags.Quiet = quiet;
    UpdateCurrentStatus( lastst );
    if( rc != ERR_NO_ERR ) {
        SetNextAutoSaveTime();
        return;
    }

    /*
     * update history file
     */
    CurrentFile->need_autosave = FALSE;
    if( !CurrentFile->been_autosaved ) {
        GetCurrentFilePath( path2 );
        CurrentFile->been_autosaved = TRUE;
        MakeTmpPath( tmp, checkFileName );
        f = fopen( tmp, "a" );
        if( f != NULL ) {
            MyFprintf( f, "%s %s\n", path, path2 );
            fclose( f );
        }
    }

    SetNextAutoSaveTime();

} /* DoAutoSave */
Example #4
0
/*
 * writeTitle - write a title for each section
 */
static void writeTitle( FILE *fp, const char *str )
{
    if( isCmdLine ) {
        MyFprintf( fp, "\n#\n# %s\n#\n", str );
    }

} /* writeTitle */
Example #5
0
/*
 * BarfToolBarData - output toolbar data to config file
 */
void BarfToolBarData( FILE *f )
{
    ss          *p;
    tool_item   *citem;

    p = toolBarHead;
    while( p != NULL ) {
        citem = (tool_item *)p;
        if( citem->dont_save ) {
            /* do nothing */
        } else if( citem->is_blank ) {
            MyFprintf( f, "addtoolbaritem\n" );
        } else {
            MyFprintf( f, "addtoolbaritem %s \"%s\" %s\n", citem->name, citem->help, citem->cmd );
        }
        p = p->next;
    }

} /* BarfToolBarData */
Example #6
0
/*
 * finiSourceErrFile - close up error file
 */
static void finiSourceErrFile( char *fn )
{
    char        drive[_MAX_DRIVE], directory[_MAX_DIR], name[_MAX_FNAME];
    char        path[FILENAME_MAX];
    char        tmp[MAX_SRC_LINE];

    if( !EditFlags.CompileScript ) {
        return;
    }
    _splitpath( fn, drive, directory, name, NULL );
    _makepath( path, drive, directory, name, ".err" );
    remove( path );
    if( srcErrFile != NULL ) {
        GetDateTimeString( tmp );
        MyFprintf( srcErrFile, "\nCompile of %s finished on %s\n", fn, tmp );
        MyFprintf( srcErrFile, "%d errors encountered\n", SourceErrCount );
        fclose( srcErrFile );
        srcErrFile = NULL;
        rename( srcErrFileName, path );
    }

} /* finiSourceErrFile */
Example #7
0
/*
 * SourceError - dump a source error
 */
void SourceError( char *msg )
{
    if( EditFlags.CompileScript ) {
        if( srcErrFile == NULL ) {
            srcErrFile = fopen( srcErrFileName, "w" );
            if( srcErrFile == NULL ) {
                return;
            }
        }
        MyFprintf( srcErrFile, "Error on line %d: \"%s\"\n", CurrentSrcLine, msg );
    }
    SourceErrCount++;

} /* SourceError */
Example #8
0
/*
 * doMaps - write map commands
 */
static void doMaps( FILE *f, key_map *maps, char *extra_str )
{
    char        *map;
    vi_key      *str;
    int         i;
    int         j;
    int         len;

    for( i = 0; i < MAX_EVENTS; i++ ) {
        if( maps[i].data != NULL ) {
            MyFprintf( f, "map%s ", extra_str );
            map = LookUpCharToken( i, FALSE );
            if( map == NULL ) {
                MyFprintf( f, "%c ", i );
            } else {
                MyFprintf( f, "%s ", map );
            }
            if( maps[i].no_input_window ) {
                MyFprintf( f, "\\x" );
            }
            str = maps[i].data;
            // len = strlen( str );
            for( len = 0; str[len] != 0; len++ );
            len--;

            for( j = 0; j < len; j++ ) {
                map = LookUpCharToken( str[j], TRUE );
                if( map == NULL ) {
                    MyFprintf( f, "%c", str[j] );
                } else {
                    if( map[1] == 0 ) {
                        MyFprintf( f, "\\%s", map );
                    } else {
                        MyFprintf( f, "\\<%s>", map );
                    }
                }
            }
            MyFprintf( f, "\n" );
        }
    }

} /* doMaps */
Example #9
0
void BarfFontData( FILE *file )
{
    font_type   i;
    font        *f;
    LOGFONT     *l;

    f = &Fonts[0];
    for( i = 0; i < MAX_FONTS; i++, f++ ) {
        if( f->used ) {
            l = &f->lf;
            /* ick... */
            MyFprintf( file,
                       "setfont %d %d %d %d %d %d %d %d %d %d %d %d %d %d \"%s\"\n", i,
                       l->lfHeight, l->lfWidth, l->lfEscapement, l->lfOrientation,
                       l->lfWeight, (int)l->lfItalic, (int)l->lfUnderline,
                       (int)l->lfStrikeOut, (int)l->lfCharSet, (int)l->lfOutPrecision,
                       (int)l->lfClipPrecision, (int)l->lfQuality,
                       (int)l->lfPitchAndFamily, &l->lfFaceName[0] );
        }
    }
}
Example #10
0
/*
 * doMaps - write map commands
 */
static void doMaps( FILE *fp, key_map *maps, const char *extra_str )
{
    char        *map;
    vi_key      *keymap;
    int         i;
    int         j;

    for( i = 0; i < MAX_EVENTS; i++ ) {
        if( maps[i].data != NULL ) {
            MyFprintf( fp, "map%s ", extra_str );
            map = LookUpCharToken( i, false );
            if( map == NULL ) {
                MyFprintf( fp, "%c ", i );
            } else {
                MyFprintf( fp, "%s ", map );
            }
            if( maps[i].no_input_window ) {
                MyFprintf( fp, "\\x" );
            }
            keymap = maps[i].data;
            for( j = 0; keymap[j] != VI_KEY( NULL ); j++ ) {
                map = LookUpCharToken( keymap[j], true );
                if( map == NULL ) {
                    MyFprintf( fp, "%c", (char)keymap[j] );
                } else {
                    if( map[1] == '\0' ) {
                        MyFprintf( fp, "\\%s", map );
                    } else {
                        MyFprintf( fp, "\\<%s>", map );
                    }
                }
            }
            MyFprintf( fp, "\n" );
        }
    }

} /* doMaps */
Example #11
0
/*
 * RemoveFromAutoSaveList - take a file that we are quitting out of the list
 */
void RemoveFromAutoSaveList( void )
{
    FILE        *f, *f2;
    char        as_path[FILENAME_MAX];
    char        as2_path[FILENAME_MAX];
    char        path[FILENAME_MAX];
    char        path2[FILENAME_MAX];
    char        data[FILENAME_MAX];
//    bool        found;
    int         i;

    if( EditVars.AutoSaveInterval == 0 ) {
        return;
    }
    if( CurrentFile == NULL ) {
        return;
    }
    if( !CurrentFile->been_autosaved ) {
        return;
    }

    MakeTmpPath( as_path, checkFileName );
    MakeTmpPath( as2_path, checkFileTmpName );

    GetCurrentFilePath( path );

//    found = FALSE;
    f = fopen( as_path, "r" );
    if( f == NULL ) {
        return;
    }
    f2 = fopen( as2_path, "w" );
    if( f2 == NULL ) {
        fclose( f );
        return;
    }
    while( fgets( path2, FILENAME_MAX, f ) != NULL ) {
        for( i = strlen( path2 ); i && isWSorCtrlZ( path2[i - 1] ); --i ) {
            path2[i - 1] = '\0';
        }
        NextWord1( path2, data );
        RemoveLeadingSpaces( path2 );
        if( !strcmp( path, path2 ) ) {
            MakeTmpPath( path2, CurrentFile->as_name );
            if( !strcmp( data, path2 ) ) {
//                found = TRUE;
                remove( path2 );
                while( fgets( data, FILENAME_MAX, f ) != NULL ) {
                    for( i = strlen( data ); i && isWSorCtrlZ( data[i - 1] ); --i ) {
                        data[i - 1] = '\0';
                    }
                    MyFprintf( f2, "%s\n", data );
                }
                break;
            }
        }
        MyFprintf( f2, "%s %s\n", data, path2 );
    }
    fclose( f );
    fclose( f2 );
    remove( as_path );
    rename( as2_path, as_path );

} /* RemoveFromAutoSaveList */
Example #12
0
/*
 * barfScript - write a compiled script
 */
static vi_rc barfScript( char *fn, sfile *sf, vlist *vl, int *ln, char *vn )
{
    sfile       *curr;
    FILE        *foo;
    char        drive[_MAX_DRIVE], directory[_MAX_DIR], name[_MAX_FNAME];
    char        path[FILENAME_MAX];
    char        tmp[MAX_SRC_LINE], *tmp2;
    int         i, k;
    vi_rc       rc;

    /*
     * get compiled file name, and make error file
     */
    if( vn[0] == 0 ) {
        _splitpath( fn, drive, directory, name, NULL );
        _makepath( path, drive, directory, name, "._vi" );
    } else {
        strcpy( path, vn );
    }
    foo = fopen( path, "w" );
    if( foo == NULL ) {
        return( ERR_FILE_OPEN );
    }
    MyFprintf( foo, "VBJ__\n" );
    curr = sf;
    *ln = 1;

    /*
     * process all lines
     */
    while( TRUE ) {

        curr = curr->next;
        if( curr == NULL ) {
            break;
        }

        if( curr->data != NULL ) {
            strcpy( tmp, curr->data );
        } else {
            tmp[0] = 0;
        }

        /*
         * expand variables, if requested
         */
        if( EditFlags.CompileAssignments ) {
            /*
             * process the assign command
             */
            if( curr->token == SRC_T_ASSIGN ) {
                rc = SrcAssign( tmp, vl );
                if( rc != ERR_NO_ERR ) {
                    fclose( foo );
                    return( rc );
                }
                if( !EditFlags.CompileAssignments ) {
                    strcpy( tmp, curr->data );
                    EditFlags.CompileAssignments = TRUE;
                } else {
                    continue;
                }
            } else {
                if( curr->token != SRC_T_IF ) {
                    if( curr->hasvar ) {
                        Expand( tmp, vl );
                        curr->hasvar = FALSE;
                        k = strlen( curr->data );
                        for( i = 0; i < k; i++ ) {
                            if( curr->data[i] == '%' ) {
                                curr->hasvar = TRUE;
                                break;
                            }
                        }
                    }
                }
            }
        }

        /*
         * process any additional commands
         */
        switch( curr->token ) {
        /*
         * process the map command
         */
        case PCL_T_MAP + SRC_T_NULL + 1:
            if( tmp[0] == '!' ) {
                k = MAPFLAG_DAMMIT;
                tmp2 = &tmp[1];
            } else {
                k = 0;
                tmp2 = tmp;
            }
            rc = MapKey( k, tmp2 );
            if( rc != ERR_NO_ERR ) {
                fclose( foo );
                return( rc );
            }
            if( k ) {
                tmp[0] = '!';
            }
            strcpy( &tmp[k], WorkLine->data );
            break;
        }

        /*
         * spew out line
         */
        MyFprintf( foo, "%c%d %s", (char)((char)curr->hasvar + '0'), curr->token, tmp );
        if( curr->token == SRC_T_GOTO ) {
            MyFprintf( foo, " %d", curr->branchcond );
        }
        MyFprintf( foo, "\n" );
        *ln += 1;

    }
    fclose( foo );
    return( ERR_NO_ERR );

} /* barfScript */
Example #13
0
/*
 * 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 */
Example #14
0
/*
 * doWindow - output settings for a window
 */
static void doWindow( FILE *fp, int id, window_info *wi, bool colour_only )
{
    char        token[64];

    MyFprintf( fp, "%s\n", GetTokenStringCVT( CmdLineTokens, id, token, true ) );
    if( !colour_only ) {
        MyFprintf( fp, "    dimension %d %d %d %d\n", wi->area.x1, wi->area.y1, wi->area.x2, wi->area.y2 );
        if( wi->has_border ) {
            MyFprintf( fp, "    border 1 %d %d\n", wi->border_color1, wi->border_color2 );
        } else {
            MyFprintf( fp, "    border -1\n" );
        }
    }
    MyFprintf( fp, "    text %d %d %d\n", wi->text_style.foreground, wi->text_style.background,
               wi->text_style.font );
    MyFprintf( fp, "    hilight %d %d %d\n", wi->hilight_style.foreground,
               wi->hilight_style.background, wi->hilight_style.font );
    if( wi == &editw_info ) {
        MyFprintf( fp, "    whitespace %d %d %d\n", SEType[SE_WHITESPACE].foreground,
                   SEType[SE_WHITESPACE].background, SEType[SE_WHITESPACE].font );
        MyFprintf( fp, "    selection %d %d %d\n", SEType[SE_SELECTION].foreground,
                   SEType[SE_SELECTION].background, SEType[SE_SELECTION].font );
        MyFprintf( fp, "    eoftext %d %d %d\n", SEType[SE_EOFTEXT].foreground,
                   SEType[SE_EOFTEXT].background, SEType[SE_EOFTEXT].font );
        MyFprintf( fp, "    keyword %d %d %d\n", SEType[SE_KEYWORD].foreground,
                   SEType[SE_KEYWORD].background, SEType[SE_KEYWORD].font );
        MyFprintf( fp, "    octal %d %d %d\n", SEType[SE_OCTAL].foreground,
                   SEType[SE_OCTAL].background, SEType[SE_OCTAL].font );
        MyFprintf( fp, "    hex %d %d %d\n", SEType[SE_HEX].foreground,
                   SEType[SE_HEX].background, SEType[SE_HEX].font );
        MyFprintf( fp, "    integer %d %d %d\n", SEType[SE_INTEGER].foreground,
                   SEType[SE_INTEGER].background, SEType[SE_INTEGER].font );
        MyFprintf( fp, "    char %d %d %d\n", SEType[SE_CHAR].foreground,
                   SEType[SE_CHAR].background, SEType[SE_CHAR].font );
        MyFprintf( fp, "    preprocessor %d %d %d\n", SEType[SE_PREPROCESSOR].foreground,
                   SEType[SE_PREPROCESSOR].background, SEType[SE_PREPROCESSOR].font );
        MyFprintf( fp, "    symbol %d %d %d\n", SEType[SE_SYMBOL].foreground,
                   SEType[SE_SYMBOL].background, SEType[SE_SYMBOL].font );
        MyFprintf( fp, "    invalidtext %d %d %d\n", SEType[SE_INVALIDTEXT].foreground,
                   SEType[SE_INVALIDTEXT].background, SEType[SE_INVALIDTEXT].font );
        MyFprintf( fp, "    identifier %d %d %d\n", SEType[SE_IDENTIFIER].foreground,
                   SEType[SE_IDENTIFIER].background, SEType[SE_IDENTIFIER].font );
        MyFprintf( fp, "    jumplabel %d %d %d\n", SEType[SE_JUMPLABEL].foreground,
                   SEType[SE_JUMPLABEL].background, SEType[SE_JUMPLABEL].font );
        MyFprintf( fp, "    comment %d %d %d\n", SEType[SE_COMMENT].foreground,
                   SEType[SE_COMMENT].background, SEType[SE_COMMENT].font );
        MyFprintf( fp, "    float %d %d %d\n", SEType[SE_FLOAT].foreground,
                   SEType[SE_FLOAT].background, SEType[SE_FLOAT].font );
        MyFprintf( fp, "    string %d %d %d\n", SEType[SE_STRING].foreground,
                   SEType[SE_STRING].background, SEType[SE_STRING].font );
        MyFprintf( fp, "    variable %d %d %d\n", SEType[SE_VARIABLE].foreground,
                   SEType[SE_VARIABLE].background, SEType[SE_VARIABLE].font );
        MyFprintf( fp, "    regexp %d %d %d\n", SEType[SE_REGEXP].foreground,
                   SEType[SE_VARIABLE].background, SEType[SE_VARIABLE].font );
    }
    MyFprintf( fp, "endwindow\n" );

} /* doWindow */
Example #15
0
/*
 * 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 */