示例#1
0
/*
 * tempFileSetup - set up a temp file with data in it
 */
static void tempFileSetup( file **cfile, char *list[], int maxlist, int indent,
                           bool makelower )
{
    int         j, boff, i, k;
    char        dd[FILENAME_MAX];

    /*
     * allocate temporary file structures
     */
    *cfile = FileAlloc( NULL );

    /*
     * copy data into buffer and create fcbs
     */
    j = boff = 0;
    while( j < maxlist ) {
        strcpy( dd, list[j] );
        if( makelower ) {
            FileLower( dd );
        }
        k = strlen( dd );
        if( k + 2 + indent + boff > MAX_IO_BUFFER ) {
            CreateFcbData( *cfile, boff );
            (*cfile)->fcbs.tail->non_swappable = TRUE;
            boff = 0;
        }
        if( indent ) {
            for( i = 0; i < indent; i++ ) {
                ReadBuffer[boff + i] = ' ';
            }
        }
        memcpy( &ReadBuffer[boff + indent], dd, k );
        /* Don't change the CRLF state of the current file */
        if( EditFlags.WriteCRLF ) {
            memcpy( &ReadBuffer[boff + k + indent], crlf, 2 );
            boff += 2;
        } else {
            memcpy( &ReadBuffer[boff + k + indent], &crlf[1], 1 );
            boff += 1;
        }
        boff += k + indent;
        j++;
    }

    CreateFcbData( *cfile, boff );
    (*cfile)->fcbs.tail->non_swappable = TRUE;

} /* tempFileSetup */
示例#2
0
/*
 * tempFileSetup - set up a temp file with data in it
 */
static void tempFileSetup( file **cfile, char *list[], int maxlist, int indent,
                           bool makelower )
{
    int         j, boff, i, k;
    char        dd[FILENAME_MAX];

    /*
     * allocate temporary file structures
     */
    *cfile = FileAlloc( NULL );

    /*
     * copy data into buffer and create fcbs
     */
    j = boff = 0;
    while( j < maxlist ) {
        strcpy( dd, list[j] );
        if( makelower ) {
            FileLower( dd );
        }
        k = strlen( dd );
        if( k + 2 + indent + boff > MAX_IO_BUFFER ) {
            CreateFcbData( *cfile, boff );
            (*cfile)->fcbs.tail->non_swappable = true;
            boff = 0;
        }
        if( indent ) {
            for( i = 0; i < indent; i++ ) {
                ReadBuffer[boff + i] = ' ';
            }
        }
        memcpy( &ReadBuffer[boff + indent], dd, k );
        ReadBuffer[boff + k + indent] = CR;
        ReadBuffer[boff + k + indent + 1] = LF;
        boff += k + indent + 2;
        j++;
    }

    CreateFcbData( *cfile, boff );
    (*cfile)->fcbs.tail->non_swappable = true;

} /* tempFileSetup */
示例#3
0
/*
 * SelectFileOpen - select file from specified directory
 */
vi_rc SelectFileOpen( char *dir, char **result_ptr, char *mask, bool want_all_dirs )
{
    char                dd[FILENAME_MAX], cdir[FILENAME_MAX];
    int                 j;
    file                *cfile;
    fcb                 *cfcb;
    line                *cline;
    selflinedata        sfd;
    bool                need_entire_path;
    char                *result = *result_ptr;
    vi_rc               rc;

    /*
     * get current directory
     */
    strcpy( dd, dir );
    strcpy( cdir, dir );
    SetCWD( dir );
    need_entire_path = FALSE;

    /*
     * work through all files
     */
    for( ;; ) {

        if( dd[strlen( dd ) - 1] != FILE_SEP ) {
            strcat( dd, FILE_SEP_STR );
        }
        strcat( dd, mask );
        rc = GetSortDir( dd, want_all_dirs );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }

        /*
         * allocate temporary file structure
         */
        cfile = FileAlloc( NULL );

        FormatDirToFile( cfile, TRUE );

        /*
         * go get selected line
         */
        memset( &sfd, 0, sizeof( sfd ) );
        sfd.f = cfile;
        sfd.wi = &dirw_info;
        sfd.title = CurrentDirectory;
        sfd.show_lineno = TRUE;
        sfd.cln = 1;
        sfd.eiw = NO_WINDOW;
        rc = SelectLineInFile( &sfd );
        if( rc != ERR_NO_ERR ) {
            break;
        }
        if( sfd.sl == -1 ) {
            result[0] = 0;
            break;
        }
        j = (int) sfd.sl - 1;
        if( j >= DirFileCount || DirFiles[j]->attr & _A_SUBDIR ) {
            if( j >= DirFileCount ) {
                GimmeLinePtr( j + 1, cfile, &cfcb, &cline );
                dd[0] = cline->data[3];
                dd[1] = ':';
                dd[2] = 0;
            } else {
                strcpy( dd, cdir );
                if( dd[strlen(dd) - 1] != FILE_SEP ) {
                    strcat( dd, FILE_SEP_STR );
                }
                strcat( dd, DirFiles[j]->name );
            }
            FreeEntireFile( cfile );
            rc = SetCWD( dd );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            need_entire_path = TRUE;
            strcpy( cdir, CurrentDirectory );
            strcpy( dd, CurrentDirectory );
            continue;
        }
        if( need_entire_path ) {
            strcpy( result, CurrentDirectory );
            if( result[strlen(result) - 1] != FILE_SEP ) {
                strcat( result, FILE_SEP_STR );
            }
        } else {
            result[0] = 0;
        }
        strcat( result, DirFiles[j]->name );
        break;

    }

    /*
     * done, free memory
     */
    FreeEntireFile( cfile );
    DCDisplayAllLines();
    return( rc );

} /* SelectFileOpen */
示例#4
0
/*
 * createNewFile - create new file entry
 */
static vi_rc createNewFile( char *name, bool same_file )
{
    int         height;
    window_id   cw;
    info        *tmp;
    vi_rc       rc;

    /*
     * test that we can create this file
     */
    tmp = NULL;
    if( !same_file ) {
        rc = FileExists( name );
        if( !(rc == ERR_READ_ONLY_FILE || rc == ERR_NO_ERR || rc == ERR_FILE_EXISTS) ) {
            return( rc );
        }
    } else {
        if( name != NULL ) {
            for( tmp = InfoHead; tmp != NULL; tmp = tmp->next ) {
                if( !strcmp( tmp->CurrentFile->name, name ) ) {
                    break;
                }
            }
        }
        if( tmp == NULL )  {
            return( ERR_FILE_NOT_FOUND );
        }
        if( tmp->CurrentFile->dup_count > MAX_DUPLICATE_FILES ) {
            return( ERR_WIND_NO_MORE_WINDOWS );
        }
    }

    /*
     * get new window
     */
    rc = NewWindow2( &cw, &editw_info );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
#ifdef __WIN__
    if( !strncmp( name, "untitled", 8 ) ) {
        // better yet, pass normal/maximize flag to NewWindow2...
        ShowWindow( cw, SW_SHOWMAXIMIZED );
    }
#endif
    SetBorderGadgets( cw, EditFlags.WindowGadgets );

    /*
     * get new file entry, and read the data
     */

    if( same_file ) {
        CurrentFile = tmp->CurrentFile;
        CurrentFile->dup_count++;
        SetFileWindowTitle( CurrentWindow, CurrentInfo, true );
        tmp = CurrentInfo;
        CurrentInfo = MemAlloc( sizeof( *CurrentInfo ) );
        FTSRunCmds( name );

        rc = ERR_NO_ERR;
    } else {
        bool crlf_reached;

        crlf_reached = false;
        tmp = CurrentInfo;
        CurrentInfo = MemAlloc( sizeof( *CurrentInfo ) );
        FTSRunCmds( name );
        height = editw_info.y2 - editw_info.y1 + 1;

        CurrentFile = FileAlloc( name );
        rc = OpenFcbData( CurrentFile );
        for( ; rc == ERR_NO_ERR; ) {
            rc = ReadFcbData( CurrentFile, &crlf_reached );
            if( rc == ERR_NO_ERR && !CurrentFile->is_stdio ) {
                if( EditFlags.BreakPressed || !EditFlags.ReadEntireFile ) {
                    if( CurrentFile->fcbs.tail->end_line > height ) {
                        break;
                    }
                }
            }
        }
        if( rc != ERR_NO_ERR && rc != ERR_FILE_NOT_FOUND && rc != END_OF_FILE ) {
            MemFree( CurrentInfo );
            CurrentInfo = tmp;
            FileFree( CurrentFile );
            CloseAWindow( cw );
            return( rc );
        }
        if( rc == ERR_FILE_NOT_FOUND ) {
            rc = NEW_FILE;
            EditFlags.NewFile = true;
            CurrentFile->write_crlf = FileSysNeedsCR( CurrentFile->handle );
#ifdef __UNIX__
            CurrentFile->attr = PMODE_RW;
#endif
        } else {
            rc = ERR_NO_ERR;
            CurrentFile->write_crlf = crlf_reached;
            EditFlags.NewFile = false;
#ifdef __UNIX__
            {
                struct stat     sb;
                stat( name, &sb );
                CurrentFile->attr = sb.st_mode & ~S_IFMT;
            }
#endif
        }
        CurrentFile->check_readonly = true;
    }

    /*
     * create info entry
     */
    CurrentPos.line = 0;
    CurrentPos.column = 1;
    VirtualColumnDesired = 1;
    LeftTopPos.line = 1;
    LeftTopPos.column = 0;
    if( !same_file ) {
        AllocateUndoStacks();
    }
    AllocateMarkList();
    CurrentWindow = cw;
    CurrentInfo->DuplicateID = CurrentFile->dup_count;
    CurrentInfo->CurrentWindow = cw;
    LangInit( CurrentInfo->fsi.Language );
#ifdef __WIN__
    {
        window_data     *wd;
        wd = DATA_FROM_ID( cw );
        wd->info = CurrentInfo;
    }
#endif
    DCCreate();
    SetFileWindowTitle( CurrentWindow, CurrentInfo, true );

    /*
     * set current file info
     */
    CurrentFcb = CurrentFile->fcbs.head;
    CurrentLine = CurrentFcb->lines.head;

    if( EditFlags.LineNumbers ) {
        LineNumbersSetup();
    }

    if( tmp != NULL ) {
        InsertLLItemAfter( (ss **)&InfoTail, (ss *)tmp, (ss *)CurrentInfo );
    } else {
        AddLLItemAtEnd( (ss **)&InfoHead, (ss **)&InfoTail, (ss *)CurrentInfo );
    }

    return( rc );

} /* createNewFile */