aboutsummaryrefslogtreecommitdiff
path: root/contrib/less/mark.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/less/mark.c')
-rw-r--r--contrib/less/mark.c87
1 files changed, 28 insertions, 59 deletions
diff --git a/contrib/less/mark.c b/contrib/less/mark.c
index cbb316f276e6..1749e01b3651 100644
--- a/contrib/less/mark.c
+++ b/contrib/less/mark.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2021 Mark Nudelman
+ * Copyright (C) 1984-2023 Mark Nudelman
*
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
@@ -49,24 +49,21 @@ public int marks_modified = 0;
/*
* Initialize a mark struct.
*/
- static void
-cmark(m, ifile, pos, ln)
- struct mark *m;
- IFILE ifile;
- POSITION pos;
- int ln;
+static void cmark(struct mark *m, IFILE ifile, POSITION pos, int ln)
{
m->m_ifile = ifile;
m->m_scrpos.pos = pos;
m->m_scrpos.ln = ln;
+ if (m->m_filename != NULL)
+ /* Normally should not happen but a corrupt lesshst file can do it. */
+ free(m->m_filename);
m->m_filename = NULL;
}
/*
* Initialize the mark table to show no marks are set.
*/
- public void
-init_mark(VOID_PARAM)
+public void init_mark(void)
{
int i;
@@ -86,10 +83,7 @@ init_mark(VOID_PARAM)
/*
* Set m_ifile and clear m_filename.
*/
- static void
-mark_set_ifile(m, ifile)
- struct mark *m;
- IFILE ifile;
+static void mark_set_ifile(struct mark *m, IFILE ifile)
{
m->m_ifile = ifile;
/* With m_ifile set, m_filename is no longer needed. */
@@ -100,9 +94,7 @@ mark_set_ifile(m, ifile)
/*
* Populate the m_ifile member of a mark struct from m_filename.
*/
- static void
-mark_get_ifile(m)
- struct mark *m;
+static void mark_get_ifile(struct mark *m)
{
if (m->m_ifile != NULL_IFILE)
return; /* m_ifile is already set */
@@ -112,9 +104,7 @@ mark_get_ifile(m)
/*
* Return the user mark struct identified by a character.
*/
- static struct mark *
-getumark(c)
- int c;
+static struct mark * getumark(LWCHAR c)
{
PARG parg;
if (c >= 'a' && c <= 'z')
@@ -135,9 +125,7 @@ getumark(c)
* The mark struct may either be in the mark table (user mark)
* or may be constructed on the fly for certain characters like ^, $.
*/
- static struct mark *
-getmark(c)
- int c;
+static struct mark * getmark(LWCHAR c)
{
struct mark *m;
static struct mark sm;
@@ -197,9 +185,7 @@ getmark(c)
/*
* Is a mark letter invalid?
*/
- public int
-badmark(c)
- int c;
+public int badmark(LWCHAR c)
{
return (getmark(c) == NULL);
}
@@ -207,10 +193,7 @@ badmark(c)
/*
* Set a user-defined mark.
*/
- public void
-setmark(c, where)
- int c;
- int where;
+public void setmark(LWCHAR c, int where)
{
struct mark *m;
struct scrpos scrpos;
@@ -231,9 +214,7 @@ setmark(c, where)
/*
* Clear a user-defined mark.
*/
- public void
-clrmark(c)
- int c;
+public void clrmark(LWCHAR c)
{
struct mark *m;
@@ -252,8 +233,7 @@ clrmark(c)
/*
* Set lmark (the mark named by the apostrophe).
*/
- public void
-lastmark(VOID_PARAM)
+public void lastmark(void)
{
struct scrpos scrpos;
@@ -269,9 +249,7 @@ lastmark(VOID_PARAM)
/*
* Go to a mark.
*/
- public void
-gomark(c)
- int c;
+public void gomark(LWCHAR c)
{
struct mark *m;
struct scrpos scrpos;
@@ -312,9 +290,7 @@ gomark(c)
* is associated with, but this doesn't matter much,
* because it's always the first non-blank line on the screen.
*/
- public POSITION
-markpos(c)
- int c;
+public POSITION markpos(LWCHAR c)
{
struct mark *m;
@@ -333,9 +309,7 @@ markpos(c)
/*
* Return the mark associated with a given position, if any.
*/
- public char
-posmark(pos)
- POSITION pos;
+public char posmark(POSITION pos)
{
int i;
@@ -355,9 +329,7 @@ posmark(pos)
/*
* Clear the marks associated with a specified ifile.
*/
- public void
-unmark(ifile)
- IFILE ifile;
+public void unmark(IFILE ifile)
{
int i;
@@ -370,9 +342,7 @@ unmark(ifile)
* Check if any marks refer to a specified ifile vi m_filename
* rather than m_ifile.
*/
- public void
-mark_check_ifile(ifile)
- IFILE ifile;
+public void mark_check_ifile(IFILE ifile)
{
int i;
char *filename = get_real_filename(ifile);
@@ -396,10 +366,7 @@ mark_check_ifile(ifile)
/*
* Save marks to history file.
*/
- public void
-save_marks(fout, hdr)
- FILE *fout;
- char *hdr;
+public void save_marks(FILE *fout, char *hdr)
{
int i;
@@ -414,7 +381,7 @@ save_marks(fout, hdr)
char pos_str[INT_STRLEN_BOUND(m->m_scrpos.pos) + 2];
if (m->m_scrpos.pos == NULL_POSITION)
continue;
- postoa(m->m_scrpos.pos, pos_str);
+ postoa(m->m_scrpos.pos, pos_str, 10);
filename = m->m_filename;
if (filename == NULL)
filename = get_real_filename(m->m_ifile);
@@ -427,9 +394,7 @@ save_marks(fout, hdr)
/*
* Restore one mark from the history file.
*/
- public void
-restore_mark(line)
- char *line;
+public void restore_mark(char *line)
{
struct mark *m;
int ln;
@@ -443,13 +408,17 @@ restore_mark(line)
if (m == NULL)
return;
skip_whitespace;
- ln = lstrtoi(line, &line);
+ ln = lstrtoi(line, &line, 10);
+ if (ln < 0)
+ return;
if (ln < 1)
ln = 1;
if (ln > sc_height)
ln = sc_height;
skip_whitespace;
- pos = lstrtopos(line, &line);
+ pos = lstrtopos(line, &line, 10);
+ if (pos < 0)
+ return;
skip_whitespace;
cmark(m, NULL_IFILE, pos, ln);
m->m_filename = save(line);