157691Sbostic /*-
2*60663Sbostic * Copyright (c) 1992, 1993
3*60663Sbostic * The Regents of the University of California. All rights reserved.
457691Sbostic *
557691Sbostic * This code is derived from software contributed to Berkeley by
657691Sbostic * Rodney Ruddock of the University of Guelph.
757691Sbostic *
857691Sbostic * %sccs.include.redist.c%
957691Sbostic */
1057691Sbostic
1157691Sbostic #ifndef lint
12*60663Sbostic static char sccsid[] = "@(#)k.c 8.1 (Berkeley) 05/31/93";
1357691Sbostic #endif /* not lint */
1457691Sbostic
1557710Sbostic #include <sys/types.h>
1657710Sbostic
1757710Sbostic #include <regex.h>
1857710Sbostic #include <setjmp.h>
1957710Sbostic #include <stdio.h>
2057710Sbostic #include <string.h>
2157710Sbostic
2258315Sbostic #ifdef DBI
2358315Sbostic #include <db.h>
2458315Sbostic #endif
2558315Sbostic
2657691Sbostic #include "ed.h"
2757710Sbostic #include "extern.h"
2857691Sbostic
2957691Sbostic /*
3057691Sbostic * This the mark command (k); see ed(1).
3157691Sbostic */
3257691Sbostic
3357691Sbostic void
set_mark(inputt,errnum)3457691Sbostic set_mark(inputt, errnum)
3557710Sbostic FILE *inputt;
3657710Sbostic int *errnum;
3757691Sbostic {
3857710Sbostic int l_mark;
3957691Sbostic
4057710Sbostic l_mark = getc(inputt);
4157710Sbostic if (End_default == 1)
4257710Sbostic End = current;
4357710Sbostic if (End == NULL) {
4457710Sbostic strcpy(help_msg, "bad address");
4557710Sbostic *errnum = -1;
4657710Sbostic ungetc('\n', inputt);
4757710Sbostic return;
4857710Sbostic }
4958564Sralph Start_default = End_default = 0;
5057691Sbostic
5157710Sbostic /*
5257710Sbostic * The marks have to be "a" to "z" (inclusive); that is, ye olde
5357710Sbostic * portable character set (ASCII) lower case alphabet.
5457710Sbostic */
5557710Sbostic if ((l_mark < 97) || (l_mark > 122) || (End == NULL)) {
5657710Sbostic strcpy(help_msg, "illegal mark character");
5757710Sbostic *errnum = -1;
5857710Sbostic return;
5957710Sbostic }
6057710Sbostic l_mark = l_mark - 97;
6157710Sbostic (mark_matrix[l_mark].address) = End;
6257691Sbostic
6357710Sbostic if (rol(inputt, errnum))
6457710Sbostic return;
6557691Sbostic
6657710Sbostic *errnum = 1;
6757710Sbostic }
6857691Sbostic
6957691Sbostic
7057691Sbostic /*
7157691Sbostic * This gets the address of a marked line.
7257691Sbostic */
7357710Sbostic LINE *
get_mark(inputt,errnum)7458315Sbostic get_mark(inputt, errnum)
7558315Sbostic FILE *inputt;
7657710Sbostic int *errnum;
7757691Sbostic {
7857710Sbostic int l_mark;
7957691Sbostic
8058315Sbostic l_mark = getc(inputt);
8157710Sbostic /* Ditto above comment. */
8257710Sbostic if ((l_mark < 97) || (l_mark > 122)) {
8357710Sbostic strcpy(help_msg, "illegal mark character");
8457710Sbostic *errnum = -1;
8557710Sbostic return (NULL);
8657710Sbostic }
8757710Sbostic l_mark = l_mark - 97;
8857710Sbostic *errnum = 0;
8957710Sbostic return (mark_matrix[l_mark].address);
9057710Sbostic }
9157691Sbostic
9257691Sbostic
9357691Sbostic /*
9457691Sbostic * This is for the restoration of marks during an undo.
9557691Sbostic */
9657691Sbostic void
ku_chk(begi,fini,val)9757691Sbostic ku_chk(begi, fini, val)
9857710Sbostic LINE *begi, *fini, *val;
9957691Sbostic {
10057710Sbostic register int l_cnt;
10157710Sbostic LINE *l_midd;
10257691Sbostic
10357710Sbostic l_midd = begi;
10457710Sbostic while (l_midd != NULL) {
10557710Sbostic for (l_cnt = 0; l_cnt < 26; l_cnt++)
10657710Sbostic if (mark_matrix[l_cnt].address == l_midd) {
10757710Sbostic u_add_stk(&(mark_matrix[l_cnt].address));
10857710Sbostic (mark_matrix[l_cnt].address) = val;
10957710Sbostic }
11057710Sbostic if (l_midd == fini)
11157710Sbostic break;
11257710Sbostic l_midd = l_midd->below;
11357710Sbostic }
11457710Sbostic }
115