From c543fc25b270d0afc582a3f77ef0b77f7d5a0c31 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sat, 9 May 2015 13:25:08 +0200 Subject: [PATCH 1/3] Allow the line number to be passed along with the file name E.g. path/to/file.c:123 --- src/loadsave.cc | 12 +++++- src/user.cc | 106 ++++++++++++++++++++++++++---------------------- 2 files changed, 68 insertions(+), 50 deletions(-) diff --git a/src/loadsave.cc b/src/loadsave.cc index 548caac..079a8a5 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; char open_name1[256]; unsigned n; if(buffer_mmapped) { @@ -227,6 +228,13 @@ int LoadFile(char *name) else mmap_begin=mmap_len=0; } + if (!buffer_mmapped) { + if (sscanf(name,"%[^:]:%lu",open_name1,&flineno)==2) { + open_name=open_name1; + // internally the lineno is 0-based: + flineno--; + } + } if(stat(open_name,&st)!=-1) { @@ -377,8 +385,10 @@ int LoadFile(char *name) strcpy(FileName,name); CurrentPos=TextBegin; - if(SavePos) + if(flineno >= 0) { + MoveLineCol(flineno,0); + } else if(SavePos) { old=PositionHistory.FindInode(FileInfo); if(old) { diff --git a/src/user.cc b/src/user.cc index c4a488b..457121a 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; + if (sscanf(fn,"%[^:]:%li",open_name1,&flineno)==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() From 4a9a0040f6429d44e7c0f1057d092af5a744c3a9 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sat, 9 May 2015 13:39:15 +0200 Subject: [PATCH 2/3] Use the file we opened as the actual, internal, file name --- src/loadsave.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loadsave.cc b/src/loadsave.cc index 079a8a5..c012fec 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -382,7 +382,7 @@ int LoadFile(char *name) fstat(file,&st); FileInfo=InodeInfo(&st); - strcpy(FileName,name); + strcpy(FileName,open_name); CurrentPos=TextBegin; if(flineno >= 0) From 926468dbfe66c2ab4576b908f6cd43176055d492 Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sat, 9 May 2015 13:45:23 +0200 Subject: [PATCH 3/3] Also allow the column number to be passed --- src/loadsave.cc | 10 ++++++---- src/user.cc | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/loadsave.cc b/src/loadsave.cc index c012fec..ed69eb6 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -218,7 +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; + long flineno=-1,fcol=-1; char open_name1[256]; unsigned n; if(buffer_mmapped) { @@ -229,10 +229,11 @@ int LoadFile(char *name) mmap_begin=mmap_len=0; } if (!buffer_mmapped) { - if (sscanf(name,"%[^:]:%lu",open_name1,&flineno)==2) { + if (sscanf(name,"%[^:]:%lu:%lu",open_name1,&flineno,&fcol)>=2) { open_name=open_name1; - // internally the lineno is 0-based: + // internally the lineno and col are 0-based: flineno--; + fcol--; } } @@ -387,7 +388,8 @@ int LoadFile(char *name) CurrentPos=TextBegin; if(flineno >= 0) { - MoveLineCol(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 457121a..b8cd84d 100644 --- a/src/user.cc +++ b/src/user.cc @@ -968,8 +968,8 @@ int file_check(const char *fn) if (!buffer_mmapped) { char *open_name1=(char*)alloca(strlen(fn)+1); - long flineno=0; - if (sscanf(fn,"%[^:]:%li",open_name1,&flineno)==2) + 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;