diff --git a/src/loadsave.cc b/src/loadsave.cc index 548caac..ed69eb6 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -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) { @@ -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) { @@ -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) { diff --git a/src/user.cc b/src/user.cc index c4a488b..b8cd84d 100644 --- a/src/user.cc +++ b/src/user.cc @@ -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()