Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/loadsave.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ int LoadFile(char *name)
const char *open_name=name;
unsigned long long mmap_begin=0;
unsigned long mmap_len=0;
long flineno=-1,fcol=-1;
char open_name1[256];
unsigned n;
if(buffer_mmapped) {
Expand All @@ -227,6 +228,14 @@ int LoadFile(char *name)
else
mmap_begin=mmap_len=0;
}
if (!buffer_mmapped) {
if (sscanf(name,"%[^:]:%lu:%lu",open_name1,&flineno,&fcol)>=2) {
open_name=open_name1;
// internally the lineno and col are 0-based:
flineno--;
fcol--;
}
}

if(stat(open_name,&st)!=-1)
{
Expand Down Expand Up @@ -374,11 +383,14 @@ int LoadFile(char *name)

fstat(file,&st);
FileInfo=InodeInfo(&st);
strcpy(FileName,name);
strcpy(FileName,open_name);

CurrentPos=TextBegin;
if(SavePos)
if(flineno >= 0)
{
fcol = (fcol >= 0)? fcol : 0;
MoveLineCol(flineno,fcol);
} else if(SavePos) {
old=PositionHistory.FindInode(FileInfo);
if(old)
{
Expand Down
106 changes: 57 additions & 49 deletions src/user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -963,58 +963,66 @@ int file_check(const char *fn)
fn=open_name1;
}

if(access(fn,R_OK)==-1)
{
if(access(fn,F_OK)==0)
{
sprintf(msg,"File: %s\nThe specified file is not readable",fn);
ErrMsg(msg);
return ERR;
}
if((View&RO_MODE) || buffer_mmapped) // view mode or mmap mode
{
sprintf(msg,"File: %s\nThe specified file does not exist",fn);
ErrMsg(msg);
return ERR;
}
strcpy(dir,fn);
slash=dir+strlen(dir);
while(slash>dir && !isslash(*--slash));
if(slash>dir)
*slash=0;
else
strcpy(dir,".");
if(access(dir,F_OK)==-1)
{
sprintf(msg,"File: %s\nThe specified directory does not exist",fn);
ErrMsg(msg);
return ERR;
}
if(access(dir,W_OK|X_OK)==-1)
{
sprintf(msg,"File: %s\nThe specified file does not exist\n"
"and the directory does not permit creating",fn);
ErrMsg(msg);
return ERR;
}
if(access(fn,R_OK)==0)
return OK;

struct menu CreateOrNot[]=
{
{" C&reate ",MIDDLE-6,4},
{" &Cancel ",MIDDLE+6,4},
{NULL}
};
sprintf(msg,"The file `%s' does not exist. Create?",fn);
switch(ReadMenuBox(CreateOrNot,HORIZ,msg,
" Verify ",VERIFY_WIN_ATTR,CURR_BUTTON_ATTR))
{
case('R'):
if (!buffer_mmapped) {
char *open_name1=(char*)alloca(strlen(fn)+1);
long flineno=0,fcol=0;
if (sscanf(fn,"%[^:]:%li:%li",open_name1,&flineno,&fcol)>=2)
fn=open_name1;
if (access(fn,R_OK)==0)
return OK;
default:
return ERR;
}
}
return OK;

if(access(fn,F_OK)==0)
{
sprintf(msg,"File: %s\nThe specified file is not readable",fn);
ErrMsg(msg);
return ERR;
}
if((View&RO_MODE) || buffer_mmapped) // view mode or mmap mode
{
sprintf(msg,"File: %s\nThe specified file does not exist",fn);
ErrMsg(msg);
return ERR;
}
strcpy(dir,fn);
slash=dir+strlen(dir);
while(slash>dir && !isslash(*--slash));
if(slash>dir)
*slash=0;
else
strcpy(dir,".");
if(access(dir,F_OK)==-1)
{
sprintf(msg,"File: %s\nThe specified directory does not exist",fn);
ErrMsg(msg);
return ERR;
}
if(access(dir,W_OK|X_OK)==-1)
{
sprintf(msg,"File: %s\nThe specified file does not exist\n"
"and the directory does not permit creating",fn);
ErrMsg(msg);
return ERR;
}

struct menu CreateOrNot[]=
{
{" C&reate ",MIDDLE-6,4},
{" &Cancel ",MIDDLE+6,4},
{NULL}
};
sprintf(msg,"The file `%s' does not exist. Create?",fn);
switch(ReadMenuBox(CreateOrNot,HORIZ,msg,
" Verify ",VERIFY_WIN_ATTR,CURR_BUTTON_ATTR))
{
case('R'):
return OK;
default:
return ERR;
}
}

void UserLoad()
Expand Down