/* * 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 */
/* * 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 */
/* * SaveFileAs - save data from current file */ vi_rc SaveFileAs( void ) { char fn[FILENAME_MAX]; char cmd[14 + FILENAME_MAX]; vi_rc rc; rc = SelectFileSave( fn ); if( rc != ERR_NO_ERR || fn[0] == '\0' ) { return( rc ); } // rename current file #ifndef __NT__ // this is stupid for all case-preserving systems like NT FileLower( fn ); #endif sprintf( cmd, "set filename \"%s\"", fn ); RunCommandLine( cmd ); UpdateLastFileList( fn ); // flag dammit as user must have already said overwrite ok return( SaveFile( fn, -1L, -1L, TRUE ) ); } /* SaveFileAs */
/* * getDir - get current directory list (no sorting) */ static vi_rc getDir( char *dname, bool want_all_dirs ) { DIR *d; struct dirent *nd; direct_ent *tmp; int i, j, len; char wild[FILENAME_MAX]; char path[FILENAME_MAX]; char ch; bool is_subdir; vi_rc rc; /* * initialize for file scan */ len = strlen( dname ); for( i = len - 1; i >= 0; i-- ) { if( dname[i] == '/' || dname[i] == '\\' || dname[i] == ':' ) { break; } } for( j = 0; j < i + 1; j++ ) { path[j] = dname[j]; } path[i + 1] = 0; if( i >= 0 ) { ch = path[i]; } else { ch = 0; } for( j = i + 1; j <= len; j++ ) { wild[j - i - 1] = dname[j]; } rc = FileMatchInit( wild ); if( rc != ERR_NO_ERR ) { return( rc ); } #ifndef __UNIX__ if( ch != '\\' && ch != '/' && ch != ':' && ch != 0 ) { strcat( path, FILE_SEP_STR ); } strcat( path, ALL_FILES_WILD_CARD ); #else if( ch == 0 ) { path[0] = '.'; path[1] = 0; } #endif for( i = 0; i < DirFileCount; i++ ) { MemFree2( &DirFiles[i] ); } DirFileCount = 0; d = opendir( path ); if( d == NULL ) { FileMatchFini(); return( ERR_FILE_NOT_FOUND ); } /* * loop through all directory entries */ while( (nd = readdir( d )) != NULL ) { if( DirFileCount >= MAX_FILES ) { break; } is_subdir = FALSE; #if defined( __QNX__ ) if( nd->d_stat.st_mode & S_IFDIR ) { is_subdir = TRUE; } #elif defined( __UNIX__ ) { struct stat st; stat( nd->d_name, &st ); if( st.st_mode & S_IFDIR ) { is_subdir = TRUE; } } #else if( nd->d_attr & _A_SUBDIR ) { is_subdir = TRUE; } #endif if( !(want_all_dirs && is_subdir) ) { if( !FileMatch( nd->d_name ) ) { continue; } } len = strlen( nd->d_name ); DirFiles[DirFileCount] = MemAlloc( sizeof( direct_ent ) + len ); tmp = DirFiles[DirFileCount]; GetFileInfo( tmp, nd, path ); memcpy( tmp->name, nd->d_name, len + 1 ); FileLower( tmp->name ); DirFileCount++; } FileMatchFini(); closedir( d ); return( ERR_NO_ERR ); } /* getDir */