* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)ex_digraph.c 8.6 (Berkeley) 3/25/94";
static void do_digraph
__P((SCR
*, EXF
*, int, u_char
*));
/* This stuff is used to build the default digraphs table. */
static u_char digtable
[][4] = {
"C,\200", "u\"\1", "e'\2", "a^\3",
"a\"\4", "a`\5", "a@\6", "c,\7",
"e^\10", "e\"\211", "e`\12", "i\"\13",
"i^\14", "i`\15", "A\"\16", "A@\17",
"E'\20", "ae\21", "AE\22", "o^\23",
"o\"\24", "o`\25", "u^\26", "u`\27",
"y\"\30", "O\"\31", "U\"\32", "a'\240",
"i'!", "o'\"", "u'#", "n~$",
"N~%", "a-&", "o-'", "~?(",
"2/+", "4/,", "^+;", "^q<",
"^c=", "^r>", "^t?", "pp]",
"^^^", "oo_", "*a`", "*ba",
"*pc", "*Sd", "*se", "*uf",
"*tg", "*Ph", "*Ti", "*Oj",
"*dk", "*Hl", "*hm", "*En",
"*No", "eqp", "pmq", "ger",
"les", "*It", "*iu", "*/v",
"*=w", "sq{", "^n|", "^2}",
"~!!", "a-*", "\">+", "o-:",
"A`@", "A'A", "A^B", "A~C",
"A\"D", "A@E", "AEF", "C,G",
"E`H", "E'I", "E^J", "E\"K",
"I`L", "I'M", "I^N", "I\"O",
"-DP", "N~Q", "O`R", "O'S",
"O^T", "O~U", "O\"V", "O/X",
"U`Y", "U'Z", "U^[", "U\"\\",
"a``", "a'a", "a^b", "a~c",
"a\"d", "a@e", "aef", "c,g",
"e`h", "e'i", "e^j", "e\"k",
"i`l", "i'm", "i^n", "i\"o",
"-dp", "n~q", "o`r", "o's",
"o^t", "o~u", "o\"v", "o/x",
"u`y", "u'z", "u^{", "u\"|",
for (i
= 0; *digtable
[i
]; i
++)
do_digraph(sp
, NULL
, 0, digtable
[i
]);
do_digraph(sp
, NULL
, 0, NULL
);
do_digraph(sp
, ep
, F_ISSET(cmdp
, E_FORCE
), cmdp
->argv
[0]->bp
);
char key1
; /* the underlying character */
char key2
; /* the second character */
register struct _DIG
*dp
;
/* if digraphs are disabled, then just return the new char */
if (O_ISSET(sp
, O_DIGRAPH
))
/* remember the new key, so we can return it if this isn't a digraph */
/* sort key1 and key2, so that their original order won't matter */
/* scan through the digraph chart */
dp
&& (dp
->key1
!= key1
|| dp
->key2
!= key2
);
/* if this combination isn't in there, just use the new key */
/* else use the digraph key */
/* this function lists or defines digraphs */
do_digraph(sp
, ep
, bang
, extra
)
register struct _DIG
*dp
;
static int user_defined
= 0; /* boolean: are all later digraphs user-defined? */
/* if "extra" is NULL, then we've reached the end of the built-ins */
/* if no args, then display the existing digraphs */
listbuf
[0] = listbuf
[1] = listbuf
[2] = listbuf
[5] = ' ';
for (dig
= 0, dp
= digs
; dp
; dp
= dp
->next
)
/* make sure we have at least two characters */
"Digraphs must be composed of two characters");
/* sort key1 and key2, so that their original order won't matter */
/* locate the new digraph character */
for (dig
= 2; extra
[dig
] == ' ' || extra
[dig
] == '\t'; dig
++)
/* search for the digraph */
for (prev
= (struct _DIG
*)0, dp
= digs
;
dp
&& (dp
->key1
!= extra
[0] || dp
->key2
!= extra
[1]);
prev
= dp
, dp
= dp
->next
)
/* deleting the digraph? */
"%c%c not a digraph", extra
[0], extra
[1]);
/* if necessary, create a new digraph struct for the new digraph */
MALLOC(sp
, dp
, struct _DIG
*, sizeof(struct _DIG
));
dp
->next
= (struct _DIG
*)0;
/* assign it the new digraph value */
static char buf
[] = "digraph! XX Y\n";
register struct _DIG
*dp
;
for (dp
= digs
; dp
; dp
= dp
->next
)
write(fd
, buf
, (unsigned)14);