about summary refs log tree commit diff stats
path: root/src/LYEdit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/LYEdit.c')
-rw-r--r--src/LYEdit.c181
1 files changed, 109 insertions, 72 deletions
diff --git a/src/LYEdit.c b/src/LYEdit.c
index 98940c4e..38346c90 100644
--- a/src/LYEdit.c
+++ b/src/LYEdit.c
@@ -23,46 +23,50 @@
 #define FREE(x) if (x) {free(x); x = NULL;}
 
 /*
- *  in edit mode invoke either emacs, vi, pico, jove, jed or the default
- *  editor to display and edit the current file
- *  emacs, vi, pico, jove and jed will open the file to the same line that
- *  the screen cursor is on when editing is invoked
- *  returns FALSE if file uneditable
+ *  In edit mode invoke either emacs, vi, pico, jove, jed sedt or the
+ *  default editor to display and edit the current file.
+ *  For emacs, vi, pico, jove and jed, Lynx will open the file to the
+ *  same line that the screen cursor is on when editing is invoked.
+ *  Returns FALSE if file is uneditable.
  */
-
-PUBLIC int edit_current_file ARGS3(char *,newfile, int,cur, int,lineno)
+PUBLIC int edit_current_file ARGS3(
+	char *,		newfile,
+	int,		cur,
+	int,		lineno)
 {
+    char command[512];
+    char *filename = NULL;
+    char *colon, *number_sign;
+    FILE *fp;
 
-	char command[512];
-        char *filename = NULL;
-	char *colon, *number_sign;
-	FILE *fp;
+    /*
+     *  If its a remote file then we can't edit it.
+     */
+    if (!LYisLocalFile(newfile)) {
+	_statusline(CANNOT_EDIT_REMOTE_FILES);
+	sleep(MessageSecs);
+	return FALSE;
+    }
 
-	/*
-	 * If its a remote file then we can't edit it.
-	 */
-	if(!LYisLocalFile(newfile)) {
-	    _statusline(CANNOT_EDIT_REMOTE_FILES);
-	    sleep(MessageSecs);
-	    return FALSE;
-	}
+    /*
+     *  If there's a fragment, trim it. - FM
+     */
+    number_sign = strchr(newfile, '#');
+    if (number_sign)
+	*number_sign = '\0';
 
-	number_sign = strchr(newfile,'#');
-	if(number_sign)
-	    *number_sign = '\0';
-	   
-	 /*
-	  * On Unix, first try to open it as a completely referenced file,
-	  * then via the path alone.
-	  *
-	  * On VMS, only try the path.
-	  */
+    /*
+     *  On Unix, first try to open it as a completely referenced file,
+     *  then via the path alone.
+     *
+     * On VMS, only try the path.
+     */
 #if !defined (VMS) && !defined (DOSPATH)
-	colon = strchr(newfile,':');
-	StrAllocCopy(filename, colon+1);
-	HTUnEscape(filename);
-	if((fp = fopen(filename,"r")) == NULL) {
-	    FREE(filename);
+    colon = strchr(newfile, ':');
+    StrAllocCopy(filename, (colon + 1));
+    HTUnEscape(filename);
+    if ((fp = fopen(filename, "r")) == NULL) {
+	FREE(filename);
 #endif /* !VMS */
 	    filename = HTParse(newfile,"",PARSE_PATH+PARSE_PUNCTUATION);
 	    HTUnEscape(filename);
@@ -73,20 +77,20 @@ PUBLIC int edit_current_file ARGS3(char *,newfile, int,cur, int,lineno)
 		 if ((fp = fopen(HTDOS_name(filename),"r")) == NULL) {
 #else
 #ifdef VMS
-	    if ((fp = fopen(HTVMS_name("",filename),"r")) == NULL) {
+	if ((fp = fopen(HTVMS_name("", filename), "r")) == NULL) {
 #else
-	    if ((fp = fopen(filename,"r")) == NULL) {
+	if ((fp = fopen(filename, "r")) == NULL) {
 #endif /* VMS */
 #endif /* DOSPATH */
-	        HTAlert(COULD_NOT_ACCESS_FILE);
-		FREE(filename);
-		goto failure;
-	    }
-#if !defined (VMS) && !defined (DOSPATH)
+	    HTAlert(COULD_NOT_ACCESS_FILE);
+	    FREE(filename);
+	    goto failure;
 	}
+#if !defined (VMS) && !defined (DOSPATH)
+    }
 #endif /* !VMS */
-	fclose(fp);
-		
+    fclose(fp);
+
 #if defined(VMS) || defined(CANT_EDIT_UNWRITABLE_FILES)
         /*
 	 * Don't allow editing if user lacks append access.
@@ -95,54 +99,87 @@ PUBLIC int edit_current_file ARGS3(char *,newfile, int,cur, int,lineno)
 	if ((fp = fopen(HTDOS_name("",filename),"a")) == NULL) {
 #else
 #ifdef VMS
-	if ((fp = fopen(HTVMS_name("",filename),"a")) == NULL) {
+    if ((fp = fopen(HTVMS_name("", filename), "a")) == NULL) {
 #else
-	if ((fp = fopen(filename,"a")) == NULL) {
+    if ((fp = fopen(filename, "a")) == NULL) {
 #endif /* VMS */
 #endif /* DOSPATH */
-		_statusline(NOAUTH_TO_EDIT_FILE);
-		sleep(MessageSecs);
-		goto failure;
-	}
-	fclose(fp);
+	_statusline(NOAUTH_TO_EDIT_FILE);
+	sleep(MessageSecs);
+	goto failure;
+    }
+    fclose(fp);
 #endif /* VMS || CANT_EDIT_UNWRITABLE_FILES */
 
+    /*
+     *  Make sure cur is at least zero. - FM
+     */
+    if (cur < 0) {
+	cur = 0;
+    }
+
+    /*
+     *  Set up the command for the editor. - FM
+     */
 #ifdef VMS
-        sprintf(command,"%s %s",editor, HTVMS_name("",filename));
+    if ((strstr(editor, "sedt") || strstr(editor, "SEDT")) &&
+	((lineno - 1) + (nlinks ? links[cur].ly : 0)) > 0) {
+	sprintf(command, "%s %s -%d",
+			 editor,
+			 HTVMS_name("", filename),
+			 ((lineno - 1) + (nlinks ? links[cur].ly : 0)));
+    } else {
+	sprintf(command, "%s %s", editor, HTVMS_name("", filename));
+    }
 #else
-	if (strstr(editor,"emacs") || strstr(editor,"vi") ||
-	    strstr(editor, "pico") || strstr(editor,"jove") ||
-	    strstr(editor, "jed"))
-	    sprintf(command,"%s +%d \"%s\"",editor, lineno+links[cur].ly, 
+    if (strstr(editor, "emacs") || strstr(editor, "vi") ||
+	strstr(editor, "pico") || strstr(editor, "jove") ||
+	strstr(editor, "jed"))
+	sprintf(command, "%s +%d \"%s\"",
+			 editor,
+			 (lineno + (nlinks ? links[cur].ly : 0)),
 #ifdef DOSPATH
-																	 HTDOS_name(filename));
+		HTDOS_name(filename));
 #else
                                                                 filename);
 #endif /* DOSPATH */
-	else
-		 sprintf(command,"%s \"%s\"",editor,
+    else
+	sprintf(command, "%s \"%s\"", editor,
 #ifdef DOSPATH
 				 HTDOS_name(filename));
 #else
 				 filename);
 #endif /* DOSPATH */
 #endif /* VMS */
-	if (TRACE) {
-	    fprintf(stderr, "LYEdit: %s\n",command);
-	    sleep(MessageSecs);
-	}
-	FREE(filename);
+    if (TRACE) {
+	fprintf(stderr, "LYEdit: %s\n", command);
+	sleep(MessageSecs);
+    }
+    FREE(filename);
 
-	stop_curses();
-	system(command);
-	start_curses();
+    /*
+     *  Invoke the editor. - FM
+     */
+    fflush(stderr);
+    fflush(stdout);
+    stop_curses();
+    system(command);
+    fflush(stdout);
+    fflush(stderr);
+    start_curses();
 
-	if(number_sign)
-	    *number_sign = '#';
-	return TRUE;
+    /*
+     *  Restore the fragment if there was one. - FM
+     */
+    if (number_sign)
+	*number_sign = '#';
+    return TRUE;
 
 failure:
-	if(number_sign)
-	    *number_sign = '#';
-	return FALSE;
+    /*
+     *  Restore the fragment if there was one. - FM
+     */
+    if (number_sign)
+	*number_sign = '#';
+    return FALSE;
 }