示例#1
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 */
示例#2
0
/*
 * fileGrep - search a single dir and build list of files
 */
static void fileGrep( char *dir, char **list, int *clist, window_id wn )
{
    char        fn[FILENAME_MAX], data[FILENAME_MAX], ts[FILENAME_MAX];
    char        path[FILENAME_MAX];
    char        drive[_MAX_DRIVE], directory[_MAX_DIR], name[_MAX_FNAME];
    char        ext[_MAX_EXT];
    int         i;
#if defined( __WIN__ ) && defined( __NT__ )
    LVITEM      lvi;
#endif
    vi_rc       rc;

    /*
     * get file path prefix
     */
    _splitpath( dir, drive, directory, name, ext );
    strcpy( path, drive );
    strcat( path, directory );
//    _makepath( path, drive, directory, NULL,NULL );

    /*
     * run through each entry and search it; building a list of matches
     */
    rc = GetSortDir( dir, FALSE );
    if( rc != ERR_NO_ERR ) {
        return;
    }
    for( i = 0; i < DirFileCount; i++ ) {
        if( !(DirFiles[i]->attr & _A_SUBDIR ) ) {

            strcpy( fn, path );
            strcat( fn, DirFiles[i]->name );
#ifdef __WIN__
            EditFlags.BreakPressed = SetGrepDialogFile( fn );
#else
            DisplayLineInWindow( wn, 1, fn );
#endif
            if( EditFlags.BreakPressed ) {
                return;
            }
            if( isFgrep ) {
                rc = fSearch( fn, ts );
            } else {
                rc = eSearch( fn, ts );
            }
            if( rc == FGREP_FOUND_STRING ) {

                ExpandTabsInABuffer( ts, strlen( ts ), data, MAX_DISP );
                strcpy( ts, data );
                MySprintf( data, "%X \"%s\"", fn, ts );
#ifdef __WIN__
                /*
                 * for windows - the handle passed in is the list box
                 * and the entire string is added to it but only the file
                 * name is added to the list
                 */
#ifdef __NT__
                if( IsCommCtrlLoaded() ) {
                    lvi.mask = LVIF_TEXT;
                    lvi.iItem = SendMessage( wn, LVM_GETITEMCOUNT, 0, 0L );
                    lvi.iSubItem = 0;
                    lvi.pszText = fn;
                    SendMessage( wn, LVM_INSERTITEM, 0, (LPARAM)&lvi );
                    lvi.iSubItem = 1;
                    lvi.pszText = ts;
                    SendMessage( wn, LVM_SETITEM, 0, (LPARAM)&lvi );
                } else {
#endif
                    SendMessage( wn, LB_ADDSTRING, 0, (LPARAM)data );
                    MySprintf( data, "%X", fn );
#ifdef __NT__
                }
#endif
#endif
                AddString( &(list[*clist]), data );
                (*clist)++;

            } else if( rc != ERR_NO_ERR ) {
                return;
            }
        }
    }

} /* fileGrep */