less/backport-Create-only-one-ifile-when-a-file-is-opened-under-di.patch

71 lines
2.1 KiB
Diff
Raw Normal View History

From 815ed449e5fa61b17879d8095a9a505e404f21a5 Mon Sep 17 00:00:00 2001
From: Mark Nudelman <markn@greenwoodsoftware.com>
Date: Sun, 14 Jun 2020 10:20:08 -0700
Subject: [PATCH] Create only one ifile when a file is opened under different
names.
---
ifile.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/ifile.c b/ifile.c
index 0175fcf..6ab1a2c 100644
--- a/ifile.c
+++ b/ifile.c
@@ -20,6 +20,7 @@ struct ifile {
struct ifile *h_next; /* Links for command line list */
struct ifile *h_prev;
char *h_filename; /* Name of the file */
+ char *h_rfilename; /* Canonical name of the file */
void *h_filestate; /* File state (used in ch.c) */
int h_index; /* Index within command line list */
int h_hold; /* Hold count */
@@ -39,7 +40,7 @@ struct ifile {
/*
* Anchor for linked list.
*/
-static struct ifile anchor = { &anchor, &anchor, NULL, NULL, 0, 0, '\0',
+static struct ifile anchor = { &anchor, &anchor, NULL, NULL, NULL, 0, 0, '\0',
{ NULL_POSITION, 0 } };
static int ifiles = 0;
@@ -109,6 +110,7 @@ new_ifile(filename, prev)
*/
p = (struct ifile *) ecalloc(1, sizeof(struct ifile));
p->h_filename = save(filename);
+ p->h_rfilename = lrealpath(filename);
p->h_scrpos.pos = NULL_POSITION;
p->h_opened = 0;
p->h_hold = 0;
@@ -143,6 +145,7 @@ del_ifile(h)
curr_ifile = getoff_ifile(curr_ifile);
p = int_ifile(h);
unlink_ifile(p);
+ free(p->h_rfilename);
free(p->h_filename);
free(p);
}
@@ -214,15 +217,17 @@ find_ifile(filename)
for (p = anchor.h_next; p != &anchor; p = p->h_next)
{
- if (strcmp(filename, p->h_filename) == 0 ||
- strcmp(rfilename, p->h_filename) == 0)
+ if (strcmp(rfilename, p->h_rfilename) == 0)
{
/*
* If given name is shorter than the name we were
* previously using for this file, adopt shorter name.
*/
if (strlen(filename) < strlen(p->h_filename))
- strcpy(p->h_filename, filename);
+ {
+ free(p->h_filename);
+ p->h_filename = save(filename);
+ }
break;
}
}
--
1.8.3.1