Changeset View
Changeset View
Standalone View
Standalone View
contrib/less/mark.c
Show All 21 Lines | |||||
#define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */ | #define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */ | ||||
#define LASTMARK (NMARKS-1) | #define LASTMARK (NMARKS-1) | ||||
static struct mark marks[NMARKS]; | static struct mark marks[NMARKS]; | ||||
/* | /* | ||||
* Initialize the mark table to show no marks are set. | * Initialize the mark table to show no marks are set. | ||||
*/ | */ | ||||
public void | public void | ||||
init_mark() | init_mark(void) | ||||
{ | { | ||||
int i; | int i; | ||||
for (i = 0; i < NMARKS; i++) | for (i = 0; i < NMARKS; i++) | ||||
marks[i].m_scrpos.pos = NULL_POSITION; | marks[i].m_scrpos.pos = NULL_POSITION; | ||||
} | } | ||||
/* | /* | ||||
* See if a mark letter is valid (between a and z). | * See if a mark letter is valid (between a and z). | ||||
*/ | */ | ||||
static struct mark * | static struct mark * | ||||
getumark(c) | getumark(int c) | ||||
int c; | |||||
{ | { | ||||
if (c >= 'a' && c <= 'z') | if (c >= 'a' && c <= 'z') | ||||
return (&marks[c-'a']); | return (&marks[c-'a']); | ||||
if (c >= 'A' && c <= 'Z') | if (c >= 'A' && c <= 'Z') | ||||
return (&marks[c-'A'+26]); | return (&marks[c-'A'+26]); | ||||
error("Invalid mark letter", NULL_PARG); | error("Invalid mark letter", NULL_PARG); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* | /* | ||||
* Get the mark structure identified by a character. | * Get the mark structure identified by a character. | ||||
* The mark struct may come either from the mark table | * The mark struct may come either from the mark table | ||||
* or may be constructed on the fly for certain characters like ^, $. | * or may be constructed on the fly for certain characters like ^, $. | ||||
*/ | */ | ||||
static struct mark * | static struct mark * | ||||
getmark(c) | getmark(int c) | ||||
int c; | |||||
{ | { | ||||
register struct mark *m; | struct mark *m; | ||||
static struct mark sm; | static struct mark sm; | ||||
switch (c) | switch (c) | ||||
{ | { | ||||
case '^': | case '^': | ||||
/* | /* | ||||
* Beginning of the current file. | * Beginning of the current file. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | getmark(int c) | ||||
} | } | ||||
return (m); | return (m); | ||||
} | } | ||||
/* | /* | ||||
* Is a mark letter is invalid? | * Is a mark letter is invalid? | ||||
*/ | */ | ||||
public int | public int | ||||
badmark(c) | badmark(int c) | ||||
int c; | |||||
{ | { | ||||
return (getmark(c) == NULL); | return (getmark(c) == NULL); | ||||
} | } | ||||
/* | /* | ||||
* Set a user-defined mark. | * Set a user-defined mark. | ||||
*/ | */ | ||||
public void | public void | ||||
setmark(c) | setmark(int c) | ||||
int c; | |||||
{ | { | ||||
register struct mark *m; | struct mark *m; | ||||
struct scrpos scrpos; | struct scrpos scrpos; | ||||
m = getumark(c); | m = getumark(c); | ||||
if (m == NULL) | if (m == NULL) | ||||
return; | return; | ||||
get_scrpos(&scrpos); | get_scrpos(&scrpos); | ||||
m->m_scrpos = scrpos; | m->m_scrpos = scrpos; | ||||
m->m_ifile = curr_ifile; | m->m_ifile = curr_ifile; | ||||
} | } | ||||
/* | /* | ||||
* Set lmark (the mark named by the apostrophe). | * Set lmark (the mark named by the apostrophe). | ||||
*/ | */ | ||||
public void | public void | ||||
lastmark() | lastmark(void) | ||||
{ | { | ||||
struct scrpos scrpos; | struct scrpos scrpos; | ||||
if (ch_getflags() & CH_HELPFILE) | if (ch_getflags() & CH_HELPFILE) | ||||
return; | return; | ||||
get_scrpos(&scrpos); | get_scrpos(&scrpos); | ||||
if (scrpos.pos == NULL_POSITION) | if (scrpos.pos == NULL_POSITION) | ||||
return; | return; | ||||
marks[LASTMARK].m_scrpos = scrpos; | marks[LASTMARK].m_scrpos = scrpos; | ||||
marks[LASTMARK].m_ifile = curr_ifile; | marks[LASTMARK].m_ifile = curr_ifile; | ||||
} | } | ||||
/* | /* | ||||
* Go to a mark. | * Go to a mark. | ||||
*/ | */ | ||||
public void | public void | ||||
gomark(c) | gomark(int c) | ||||
int c; | |||||
{ | { | ||||
register struct mark *m; | struct mark *m; | ||||
struct scrpos scrpos; | struct scrpos scrpos; | ||||
m = getmark(c); | m = getmark(c); | ||||
if (m == NULL) | if (m == NULL) | ||||
return; | return; | ||||
/* | /* | ||||
* If we're trying to go to the lastmark and | * If we're trying to go to the lastmark and | ||||
Show All 28 Lines | |||||
/* | /* | ||||
* Return the position associated with a given mark letter. | * Return the position associated with a given mark letter. | ||||
* | * | ||||
* We don't return which screen line the position | * We don't return which screen line the position | ||||
* is associated with, but this doesn't matter much, | * is associated with, but this doesn't matter much, | ||||
* because it's always the first non-blank line on the screen. | * because it's always the first non-blank line on the screen. | ||||
*/ | */ | ||||
public POSITION | public POSITION | ||||
markpos(c) | markpos(int c) | ||||
int c; | |||||
{ | { | ||||
register struct mark *m; | struct mark *m; | ||||
m = getmark(c); | m = getmark(c); | ||||
if (m == NULL) | if (m == NULL) | ||||
return (NULL_POSITION); | return (NULL_POSITION); | ||||
if (m->m_ifile != curr_ifile) | if (m->m_ifile != curr_ifile) | ||||
{ | { | ||||
error("Mark not in current file", NULL_PARG); | error("Mark not in current file", NULL_PARG); | ||||
return (NULL_POSITION); | return (NULL_POSITION); | ||||
} | } | ||||
return (m->m_scrpos.pos); | return (m->m_scrpos.pos); | ||||
} | } | ||||
/* | /* | ||||
* Clear the marks associated with a specified ifile. | * Clear the marks associated with a specified ifile. | ||||
*/ | */ | ||||
public void | public void | ||||
unmark(ifile) | unmark(IFILE ifile) | ||||
IFILE ifile; | |||||
{ | { | ||||
int i; | int i; | ||||
for (i = 0; i < NMARKS; i++) | for (i = 0; i < NMARKS; i++) | ||||
if (marks[i].m_ifile == ifile) | if (marks[i].m_ifile == ifile) | ||||
marks[i].m_scrpos.pos = NULL_POSITION; | marks[i].m_scrpos.pos = NULL_POSITION; | ||||
} | } |