vi_rc OpenFcbData( file *f ) { int handle; vi_rc rc; fcb *cfcb; /* * open file handle if we need to */ rc = ERR_NO_ERR; if( !f->is_stdio ) { handle = -1; ConditionalChangeDirectory( f->home ); rc = FileOpen( f->name, false, O_BINARY | O_RDONLY, 0, &handle ); if( rc != ERR_NO_ERR ) { return( ERR_FILE_OPEN ); } if( handle == -1 ) { rc = ERR_FILE_NOT_FOUND; } else if( f->size == 0 ) { close( handle ); rc = END_OF_FILE; } else { f->handle = handle; } if( rc != ERR_NO_ERR ) { cfcb = FcbAlloc( f ); AddLLItemAtEnd( (ss **)&(f->fcbs.head), (ss **)&(f->fcbs.tail), (ss *)cfcb ); CreateNullLine( cfcb ); } } return( rc ); }
/* * FileSPVAR - build file special variables */ void FileSPVAR( void ) { char path[FILENAME_MAX]; char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; int i; /* * build path */ if( CurrentFile == NULL ) { VarAddGlobalStr( "F", "" ); VarAddGlobalStr( "H", "" ); drive[0] = dir[0] = fname[0] = ext[0] = 0; } else { VarAddGlobalStr( "F", CurrentFile->name ); VarAddGlobalStr( "H", CurrentFile->home ); ConditionalChangeDirectory( CurrentFile->home ); _splitpath( CurrentFile->name, drive, dir, fname, ext ); } VarAddGlobalStr( "P1", dir ); VarAddGlobalStr( "D1", drive ); strcpy( path, drive ); strcat( path, dir ); i = strlen( path ) - 1; if( path[i] == FILE_SEP && i > 0 ) { path[i] = 0; } if( CurrentFile != NULL ) { PushDirectory( path ); ChangeDirectory( path ); GetCWD2( path, FILENAME_MAX ); PopDirectory(); } else { path[0] = 0; } if( path[strlen(path) - 1] == FILE_SEP ) { StrMerge( 2, path, fname, ext ); } else { StrMerge( 3, path,FILE_SEP_STR, fname, ext ); } _splitpath( path, drive, dir, fname, ext ); VarAddGlobalStr( "D", drive ); VarAddGlobalStr( "P", dir ); VarAddGlobalStr( "N", fname ); VarAddGlobalStr( "E", ext ); } /* FileSPVAR */